Resolved label, showName, and infinite complexity errors
MODIFY
package.json
package.json
"build": "npm run clean && npm run build-version && npm run build-lib && npm run build-types",
"build-lib": "babel src -d lib --source-maps --extensions '.ts,.js'",
"build-types": "tsc --emitDeclarationOnly",
- "build-version": "./timestamp.sh > src/versionInfo.ts && eslint 'src/versionInfo.ts' --fix",
+ "build-version": "sh ./timestamp.sh > src/versionInfo.ts && eslint \"src/versionInfo.ts\" --fix",
"watch": "npm run build-version && babel src --out-dir lib --watch --source-maps --extensions '.ts,.js'",
"clean": "rm -rf lib",
- "lint": "eslint 'src/**/*.js' 'src/**/*.ts'",
- "lint-fix": "eslint 'src/**/*.js' 'src/**/*.ts' --fix",
+ "lint": "eslint \"src/**/*.js\" \"src/**/*.ts\"",
+ "lint-fix": "eslint \"src/**/*.js\" \"src/**/*.ts\" --fix",
"test": "npm run lint",
"prepublishOnly": "npm test && npm run build",
"postpublish": "git push origin master --follow-tags"

MODIFY
src/chat/infinite.js
src/chat/infinite.js
// Common code for a discussion are a of messages about something
// This version runs over a series of files for different time periods
//
-// Parameters for the whole chat like its title are stred on
+// Parameters for the whole chat like its title are stored on
// index.ttl#this and the chats messages are stored in YYYY/MM/DD/chat.ttl
//
/* global alert $rdf */
@@ -165,7 +165,12 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
// if (text) field.value = text No - don't destroy half-finsihed user input
sts.push(
- new $rdf.Statement(chatChannel, ns.wf('message'), message, chatDocument)
+ new $rdf.Statement(
+ chatChannel,
+ ns.wf('message'),
+ message,
+ chatDocument
+ )
)
sts.push(
new $rdf.Statement(message, ns.sioc('content'), content, chatDocument)
@@ -748,6 +753,20 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
var latest = { messageTable: null }
var lock = false
+
+ function loadBackwardsMessages (magicZone) {
+ return (div.scrollTop < magicZone &&
+ earliest.messageTable &&
+ !earliest.messageTable.initial &&
+ earliest.messageTable.extendBackwards)
+ }
+ function loadForwardMessages (magicZone) {
+ return (options.selectedMessage && // we started in the middle not at the bottom
+ div.scrollHeight - div.scrollTop - div.clientHeight < magicZone && // we are scrolled right to the bottom
+ latest.messageTable &&
+ !latest.messageTable.final && // there is more data to come
+ latest.messageTable.extendForwards)
+ }
async function loadMoreWhereNeeded (event, fixScroll) {
if (lock) return
lock = true
@@ -758,10 +777,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
var done
while (
- div.scrollTop < magicZone &&
- earliest.messageTable &&
- !earliest.messageTable.initial &&
- earliest.messageTable.extendBackwards
+ loadBackwardsMessages(magicZone)
) {
const scrollBottom = div.scrollHeight - div.scrollTop
console.log('infinite scroll: adding above: top ' + div.scrollTop)
@@ -773,11 +789,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
if (done) break
}
while (
- options.selectedMessage && // we started in the middle not at the bottom
- div.scrollHeight - div.scrollTop - div.clientHeight < magicZone && // we are scrolled right to the bottom
- latest.messageTable &&
- !latest.messageTable.final && // there is more data to come
- latest.messageTable.extendForwards
+ loadForwardMessages(magicZone)
) {
const scrollTop = div.scrollTop
console.log(

MODIFY
src/chat/message.js
src/chat/message.js
@@ -93,7 +93,23 @@ export function creatorAndDateHorizontal (td1, creator, date, message) {
}
// BODY of renderMessage
-
+function shouldInsertBefore (dateString, ele, newestFirst) {
+ return (
+ (dateString > ele.AJAR_date && newestFirst) ||
+ (dateString < ele.AJAR_date && !newestFirst)
+ )
+}
+// not sure about this one...
+function processAuthorAboveContent (td1, creator) {
+ const img = dom.createElement('img')
+ img.setAttribute(
+ 'style',
+ 'max-height: 2.5em; max-width: 2.5em; border-radius: 0.5em; margin: auto;'
+ )
+ UI.widgets.setImage(img, creator)
+ td1.appendChild(img)
+}
+function renderMessageContent () {}
export function renderMessage (
messageTable,
bindings,
@@ -127,10 +143,7 @@ export function renderMessage (
break
}
var newestFirst = options.newestfirst === true
- if (
- (dateString > ele.AJAR_date && newestFirst) ||
- (dateString < ele.AJAR_date && !newestFirst)
- ) {
+ if (shouldInsertBefore(dateString, ele, newestFirst)) {
messageTable.insertBefore(messageRow, ele)
done = true
break
@@ -143,13 +156,7 @@ export function renderMessage (
var td1 = dom.createElement('td')
messageRow.appendChild(td1)
if (options.authorAboveContent) {
- const img = dom.createElement('img')
- img.setAttribute(
- 'style',
- 'max-height: 2.5em; max-width: 2.5em; border-radius: 0.5em; margin: auto;'
- )
- UI.widgets.setImage(img, creator)
- td1.appendChild(img)
+ processAuthorAboveContent(td1, creator)
} else {
creatorAndDate(td1, creator, UI.widgets.shortDate(dateString), message)
}

ADD
src/playground.js
+function decodeAsciiPoints (s) {
+ for (var i = s.length - 3; i > 0; i--) {
+ const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
+ while (
+ s[i] === '%' &&
+ hex.indexOf(s[i + 1]) >= 0 &&
+ hex.indexOf(s[i + 2]) >= 0
+ ) {
+ s =
+ s.slice(0, i) +
+ String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) +
+ s.slice(i + 3)
+ }
+ }
+ return s
+}
+
+function trimS (s) {
+ if (s.slice(-5) === '#this') s = s.slice(0, -5)
+ else if (s.slice(-3) === '#me') s = s.slice(0, -3)
+ // these were below the hash check. not sure if this makes a difference
+ // but something to test to make sure
+ if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
+ else if (s.slice(-5) === '/foaf') s = s.slice(0, -5)
+ return s
+}
+function label (x, initialCap) {
+ // x is an object
+ function doCap (s) {
+ // s = s.toString()
+ return initialCap ? s.slice(0, 1).toUpperCase() + s.slice(1) : s
+ }
+ function cleanUp (s1) {
+ var s2 = ''
+ if (s1.slice(-1) === '/') s1 = s1.slice(0, -1) // chop trailing slash
+ for (var i = 0; i < s1.length; i++) {
+ if (s1[i] === '_' || s1[i] === '-') {
+ s2 += ' '
+ }
+ s2 += s1[i]
+ if (
+ i + 1 < s1.length &&
+ s1[i].toUpperCase() !== s1[i] &&
+ s1[i + 1].toLowerCase() !== s1[i + 1]
+ ) {
+ s2 += ' '
+ }
+ }
+ if (s2.slice(0, 4) === 'has ') s2 = s2.slice(4)
+ return doCap(s2)
+ }
+
+ // The tabulator labeler is more sophisticated if it exists
+ // Todo: move it to a solid-ui option.
+ /*
+ var lab
+ if (typeof tabulator !== 'undefined' && tabulator.lb) {
+ lab = tabulator.lb.label(x)
+ if (lab) {
+ return doCap(lab.value)
+ }
+ }
+ */
+ // Hard coded known label predicates
+ // @@ TBD: Add subproperties of rdfs:label
+
+ var kb = UI.store
+ var lab1 =
+ kb.any(x, UI.ns.link('message')) ||
+ kb.any(x, UI.ns.vcard('fn')) ||
+ kb.any(x, UI.ns.foaf('name')) ||
+ kb.any(x, UI.ns.dct('title')) ||
+ kb.any(x, UI.ns.dc('title')) ||
+ kb.any(x, UI.ns.rss('title')) ||
+ kb.any(x, UI.ns.contact('fullName')) ||
+ kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) ||
+ kb.any(x, UI.ns.cal('summary')) ||
+ kb.any(x, UI.ns.foaf('nick')) ||
+ kb.any(x, UI.ns.rdfs('label'))
+
+ if (lab1) {
+ return doCap(lab1.value)
+ }
+
+ // Default to label just generated from the URI
+
+ if (x.termType === 'BlankNode') {
+ return '...'
+ }
+ if (x.termType === 'Collection') {
+ return '(' + x.elements.length + ')'
+ }
+ var s = x.uri
+ if (typeof s === 'undefined') return x.toString() // can't be a symbol
+ // s = decodeURI(s) // This can crash is random valid @ signs are presentation
+ // The idea was to clean up eg URIs encoded in query strings
+ // Also encoded character in what was filenames like @ [] {}
+ try {
+ s = s
+ .split('/')
+ .map(decodeURIComponent)
+ .join('/') // If it is properly encoded
+ } catch (e) {
+ // try individual decoding of ASCII code points
+ s = decodeAsciiPoints(s)
+ }
+
+ s = trimS(s)
+ var hash = s.indexOf('#')
+ if (hash >= 0) return cleanUp(s.slice(hash + 1))
+
+ // Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
+ var slash = s.lastIndexOf('/', s.length - 2) // (len-2) excludes trailing slash
+ if (slash >= 0 && slash < x.uri.length) return cleanUp(s.slice(slash + 1))
+
+ return doCap(decodeURIComponent(x.uri))
+}

MODIFY
src/utils.js
src/utils.js
@@ -186,7 +186,8 @@ function syncTableToArrayReOrdered (table, things, createNewRow) {
for (let g = 0; g < things.length; g++) {
var thing = things[g]
- if (g >= table.children.length) { // table needs extending
+ if (g >= table.children.length) {
+ // table needs extending
const newRow = createNewRow(thing)
newRow.subject = thing
table.appendChild(newRow)
@@ -412,15 +413,13 @@ function shortName (uri) {
for (const ns in this.prefixes) {
namespaces[this.prefixes[ns]] = ns // reverse index
}
- let pok
+
const canUse = function canUse (pp) {
// if (!__Serializer.prototype.validPrefix.test(pp)) return false; // bad format
- if (pp === 'ns') return false // boring
+ return pp === 'ns'
// if (pp in this.namespaces) return false; // already used
// this.prefixes[uri] = pp;
// this.namespaces[pp] = uri;
- pok = pp
- return true
}
let i
@@ -435,13 +434,14 @@ function shortName (uri) {
else break
}
p = p.slice(0, i)
- if (p.length < 6 && canUse(p)) return pok // exact i sbest
- if (canUse(p.slice(0, 3))) return pok
- if (canUse(p.slice(0, 2))) return pok
- if (canUse(p.slice(0, 4))) return pok
- if (canUse(p.slice(0, 1))) return pok
- if (canUse(p.slice(0, 5))) return pok
- for (i = 0; ; i++) if (canUse(p.slice(0, 3) + i)) return pok
+ if (p.length < 6 && canUse(p)) {
+ return p
+ } else {
+ for (let j = 0; j < 6; j++) {
+ if (canUse(p.slice(0, j))) return p.slice(0, j)
+ }
+ }
+ for (i = 0; ; i++) if (canUse(p.slice(0, 3) + i)) return p.slice(0, 3) + i
}
}
@@ -499,12 +499,52 @@ function labelWithOntology (x, initialCap) {
//
// @returns string
//
+
+function decodeAsciiPoints (s) {
+ for (var i = s.length - 3; i > 0; i--) {
+ const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
+ while (
+ s[i] === '%' &&
+ hex.indexOf(s[i + 1]) >= 0 &&
+ hex.indexOf(s[i + 2]) >= 0
+ ) {
+ s =
+ s.slice(0, i) +
+ String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) +
+ s.slice(i + 3)
+ }
+ }
+ return s
+}
+function trimS (s) {
+ if (s.slice(-5) === '#this') s = s.slice(0, -5)
+ else if (s.slice(-3) === '#me') s = s.slice(0, -3)
+ // these were below the hash check. not sure if this makes a difference
+ // but something to test to make sure
+ if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
+ else if (s.slice(-5) === '/foaf') s = s.slice(0, -5)
+ return s
+}
+function getLab1 (x, kb) {
+ return (
+ kb.any(x, UI.ns.link('message')) ||
+ kb.any(x, UI.ns.vcard('fn')) ||
+ kb.any(x, UI.ns.foaf('name')) ||
+ kb.any(x, UI.ns.dct('title')) ||
+ kb.any(x, UI.ns.dc('title')) ||
+ kb.any(x, UI.ns.rss('title')) ||
+ kb.any(x, UI.ns.contact('fullName')) ||
+ kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) ||
+ kb.any(x, UI.ns.cal('summary')) ||
+ kb.any(x, UI.ns.foaf('nick')) ||
+ kb.any(x, UI.ns.rdfs('label'))
+ )
+}
function label (x, initialCap) {
// x is an object
function doCap (s) {
// s = s.toString()
- if (initialCap) return s.slice(0, 1).toUpperCase() + s.slice(1)
- return s
+ return initialCap ? s.slice(0, 1).toUpperCase() + s.slice(1) : s
}
function cleanUp (s1) {
var s2 = ''
@@ -512,7 +552,6 @@ function label (x, initialCap) {
for (var i = 0; i < s1.length; i++) {
if (s1[i] === '_' || s1[i] === '-') {
s2 += ' '
- continue
}
s2 += s1[i]
if (
@@ -542,18 +581,7 @@ function label (x, initialCap) {
// @@ TBD: Add subproperties of rdfs:label
var kb = UI.store
- var lab1 =
- kb.any(x, UI.ns.link('message')) ||
- kb.any(x, UI.ns.vcard('fn')) ||
- kb.any(x, UI.ns.foaf('name')) ||
- kb.any(x, UI.ns.dct('title')) ||
- kb.any(x, UI.ns.dc('title')) ||
- kb.any(x, UI.ns.rss('title')) ||
- kb.any(x, UI.ns.contact('fullName')) ||
- kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) ||
- kb.any(x, UI.ns.cal('summary')) ||
- kb.any(x, UI.ns.foaf('nick')) ||
- kb.any(x, UI.ns.rdfs('label'))
+ var lab1 = getLab1(x, kb)
if (lab1) {
return doCap(lab1.value)
@@ -579,28 +607,15 @@ function label (x, initialCap) {
.join('/') // If it is properly encoded
} catch (e) {
// try individual decoding of ASCII code points
- for (var i = s.length - 3; i > 0; i--) {
- const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
- while (
- s[i] === '%' &&
- hex.indexOf(s[i + 1]) >= 0 &&
- hex.indexOf(s[i + 2]) >= 0
- ) {
- s =
- s.slice(0, i) +
- String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) +
- s.slice(i + 3)
- }
- }
+ s = decodeAsciiPoints(s)
}
- if (s.slice(-5) === '#this') s = s.slice(0, -5)
- else if (s.slice(-3) === '#me') s = s.slice(0, -3)
+ s = trimS()
var hash = s.indexOf('#')
if (hash >= 0) return cleanUp(s.slice(hash + 1))
- if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
- else if (s.slice(-5) === '/foaf') s = s.slice(0, -5)
+ /* put this in trimS function if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9)
+ else if (s.slice(-5) === '/foaf') s = s.slice(0, -5) */
// Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
var slash = s.lastIndexOf('/', s.length - 2) // (len-2) excludes trailing slash

Resolved label, showName, and infinite complexity errors