Skip to content

Commit 8e499cc

Browse files
author
Tim Berners-Lee
committed
bug fixes eg in imports
1 parent 20a6728 commit 8e499cc

7 files changed

Lines changed: 57 additions & 43 deletions

File tree

src/chat/dateFolder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as debug from '../debug'
7-
import store from '../logic'
7+
import { store } from '../logic'
88

99
import ns from '../ns'
1010
import * as $rdf from 'rdflib' // pull in first avoid cross-refs

src/chat/infinite.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import ns from '../ns'
1111
import * as pad from '../pad'
1212
import DateFolder from './dateFolder'
1313
import { renderMessage, creatorAndDate } from './message'
14-
import bookmarks from './bookmarks'
14+
import { findBookmarkDocument } from './bookmarks'
1515

1616
import * as $rdf from 'rdflib' // pull in first avoid cross-refs
17+
import style from '../style'
1718
import * as utils from '../utils'
1819
import widgets from '../widgets'
1920

20-
const UI = { authn, icons, ns, media, pad, $rdf, store, utils, widgets }
21+
const UI = { authn, icons, ns, media, pad, $rdf, store, style, utils, widgets }
2122

2223
/* global alert */
2324

@@ -326,7 +327,7 @@ export async function infiniteMessageArea (dom, kb, chatChannel, options) {
326327
me = context.me
327328
turnOnInput()
328329
Object.assign(context, userContext)
329-
bookmarks.findBookmarkDocument(context).then(context => {
330+
findBookmarkDocument(context).then(context => {
330331
debug.log('Bookmark file: ' + context.bookmarkDocument)
331332
})
332333
})
@@ -835,9 +836,9 @@ export async function infiniteMessageArea (dom, kb, chatChannel, options) {
835836
}
836837
}
837838

838-
let live
839+
let live, selectedDocument
839840
if (options.selectedMessage) {
840-
var selectedDocument = options.selectedMessage.doc()
841+
selectedDocument = options.selectedMessage.doc()
841842
const now = new Date()
842843
const todayDocument = dateFolder.leafDocumentFromDate(now)
843844
live = todayDocument.sameTerm(selectedDocument)

src/chat/messageTools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as rdf from 'rdflib' // pull in first avoid cross-refs
1919
import style from '../style'
2020
import * as utils from '../utils'
2121
import widgets from '../widgets'
22-
import * as bookmarks from './bookmarks'
22+
import { renderBookmarksButton } from './bookmarks'
2323

2424
const UI = { authn, icons, ns, media, pad, rdf, store, style, utils, widgets }
2525

@@ -146,7 +146,7 @@ export function messageToolbar (message, messageRow, userContext) {
146146
*/
147147
// Things anyone can do if they have a bookmark list
148148

149-
bookmarks.renderBookmarksButton(userContext).then(bookmarkButton => {
149+
renderBookmarksButton(userContext).then(bookmarkButton => {
150150
if (bookmarkButton) div.appendChild(bookmarkButton)
151151
})
152152

src/logic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const solidLogicSingleton = new SolidLogic({ fetch: auth.fetch }, auth)
99

1010
// Make this directly accessible as it is what you need most of the time
1111
export const store = solidLogicSingleton.store
12+
export const kb = store // Very commonly used synonym of store - Knowledge Base
1213

1314
debug.log('Unique quadstore initialized.')
1415

src/widgets/forms/autocomplete/autocompleteBar.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import widgets from '../../../widgets'
1111
import { renderAutoComplete, AutocompleteDecoration } from './autocompletePicker' // dbpediaParameters
1212

1313
import { NamedNode } from 'rdflib'
14-
import { wikidataParameters } from './publicData'
14+
// import { wikidataParameters } from './publicData'
1515

1616
const WEBID_NOUN = 'Solid ID'
1717

@@ -43,23 +43,29 @@ export async function renderAutocompleteControl (dom:HTMLDocument,
4343
}
4444
return addOneIdAndRefresh(person, webid)
4545
}
46+
4647
function removeDecorated () {
4748
if (decoratedAutocomplete) {
4849
creationArea.removeChild(decoratedAutocomplete)
4950
decoratedAutocomplete = undefined
5051
}
5152
}
53+
54+
async function displayAutocomplete () {
55+
decoratedAutocomplete = dom.createElement('div') as HTMLElement
56+
decoratedAutocomplete.setAttribute('style', 'display: flex; flex-flow: wrap;')
57+
decoratedAutocomplete.appendChild(await renderAutoComplete(dom, acOptions, decoration, autoCompleteDone))
58+
decoratedAutocomplete.appendChild(acceptButton)
59+
decoratedAutocomplete.appendChild(cancelButton)
60+
creationArea.appendChild(decoratedAutocomplete)
61+
}
62+
5263
async function searchButtonHandler (_event) {
5364
if (decoratedAutocomplete) {
5465
creationArea.removeChild(decoratedAutocomplete)
5566
decoratedAutocomplete = undefined
5667
} else {
57-
decoratedAutocomplete = dom.createElement('div') as HTMLElement
58-
decoratedAutocomplete.setAttribute('style', 'display: flex; flex-flow: wrap;')
59-
decoratedAutocomplete.appendChild(await renderAutoComplete(dom, acOptions, decoration, autoCompleteDone))
60-
decoratedAutocomplete.appendChild(acceptButton)
61-
decoratedAutocomplete.appendChild(cancelButton)
62-
creationArea.appendChild(decoratedAutocomplete)
68+
displayAutocomplete()
6369
}
6470
}
6571

@@ -72,8 +78,8 @@ export async function renderAutocompleteControl (dom:HTMLDocument,
7278
// const queryParams = barOptions.queryParameters || wikidataParameters
7379
const acceptButton = widgets.continueButton(dom)
7480
const cancelButton = widgets.cancelButton(dom, removeDecorated) // @@ not in edit case only in temporary case
75-
var editButton
76-
var editing = true
81+
let editButton
82+
let editing = true
7783

7884
function setVisible (element:HTMLElement, visible:boolean) {
7985
element.style.visibility = visible ? 'visible' : 'collapse'
@@ -95,7 +101,7 @@ export async function renderAutocompleteControl (dom:HTMLDocument,
95101
acceptButton, cancelButton, editButton
96102
}
97103

98-
var decoratedAutocomplete = undefined as HTMLElement | undefined
104+
let decoratedAutocomplete = undefined as HTMLElement | undefined
99105
// const { dom } = dataBrowserContext
100106
// barOptions = barOptions || {}
101107

@@ -109,17 +115,20 @@ export async function renderAutocompleteControl (dom:HTMLDocument,
109115
const plus = creationArea.appendChild(widgets.button(dom, GREEN_PLUS, barOptions.idNoun, greenButtonHandler))
110116
widgets.makeDropTarget(plus, droppedURIHandler, undefined)
111117
}
112-
if (barOptions.dbLookup) {
118+
if (barOptions.dbLookup && !acOptions.currentObject) {
113119
creationArea.appendChild(widgets.button(dom, SEARCH_ICON, barOptions.idNoun, searchButtonHandler))
114120
}
115121
if (barOptions.permanent && barOptions.editable) {
116-
editButton = widgets.button(dom, icons.iconBase + 'noun_253504.svg', 'Edit', _event => {
122+
editButton = widgets.button(dom, EDIT_ICON, 'Edit', _event => {
117123
editing = !editing
118124
syncEditingStatus()
119125
})
120126
creationArea.appendChild(editButton)
121127
}
122128
}
129+
if (acOptions.currentObject) {
130+
displayAutocomplete()
131+
}
123132
syncEditingStatus()
124133
return creationArea
125134
} // renderAutocompleteControl

src/widgets/forms/autocomplete/autocompleteField.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@ export function autocompleteField (
3939
subject: NamedNode | BlankNode | Variable,
4040
form: NamedNode,
4141
doc: NamedNode | undefined,
42-
callbackFunction: (ok: boolean, errorMessage: string) => void
42+
callbackFunction: (_ok: boolean, _errorMessage: string) => void
4343
): HTMLElement {
44-
async function addOneIdAndRefresh (result, _name) {
45-
const deletables = kb.statementsMatching(subject, property as any, null, null) // remove any multiple values in any doc
46-
47-
let insertables = deletables.map(statement => st(statement.subject, statement.predicate, result, statement.why)) // can include >1 doc
48-
if (insertables.length === 0) {
49-
// or none
50-
insertables = [st(subject, property as any, result, doc)]
51-
}
44+
async function addOneIdAndRefresh (result, name) {
45+
const originals = kb.each(subject, property as any, null, doc)
46+
const deletables = []
47+
originals.forEach(x => { // Clean up multiple if there were any
48+
deletables.concat(kb.statementsMatching(subject, property as any, x, doc)) // @@ concat does right
49+
deletables.concat(kb.statementsMatching(x, labelProperty as any, null, doc))
50+
})
51+
const insertables = [st(subject, property as any, result, doc),
52+
st(result, labelProperty as any, name, doc)] // @@ track the language of the name too!
5253
try {
5354
await kb.updater.updateMany(deletables, insertables)
5455
} catch (err) {
5556
callbackFunction(false, err)
56-
box.appendChild(widgets.errorMessageBlock(dom, 'Autocomplete form data write error:' + err))
57+
box.appendChild(widgets.errorMessageBlock(dom, 'Autocomplete form data update error:' + err))
5758
return
5859
}
5960
callbackFunction(true, '')
@@ -82,7 +83,7 @@ export function autocompleteField (
8283
)
8384
}
8485
const labelProperty = kb.any(form, ns.ui('labelProperty')) || ns.schema('name')
85-
const size = kb.any(form, ns.ui('size')) // may be undefined, let the widget decide
86+
// const size = kb.any(form, ns.ui('size')) // may be undefined, let the widget decide
8687

8788
// Parse the data source into query options
8889

@@ -149,7 +150,7 @@ export function autocompleteField (
149150
obj = kb.any(form, ns.ui('default'))
150151
if (obj) {
151152
autocompleteOptions.currentObject = obj as NamedNode
152-
autocompleteOptions.currentName = kb.anyJS(autocompleteOptions.currentObject, labelProperty, null, form.doc())
153+
autocompleteOptions.currentName = kb.anyJS(autocompleteOptions.currentObject, labelProperty, null, doc)
153154
} else { // No data or default. Should we suprress the whole field?
154155
if (suppressEmptyUneditable && !editable) {
155156
box.style.display = 'none' // clutter removal
@@ -158,7 +159,7 @@ export function autocompleteField (
158159
}
159160
} else { // get object and name from target data:
160161
autocompleteOptions.currentObject = obj as NamedNode
161-
autocompleteOptions.currentName = kb.anyJS(autocompleteOptions.currentObject, labelProperty, null, (subject as NamedNode).doc())
162+
autocompleteOptions.currentName = kb.anyJS(autocompleteOptions.currentObject, labelProperty, null, doc)
162163
}
163164

164165
lhs.appendChild(widgets.fieldLabel(dom, property as any, form))

src/widgets/forms/autocomplete/autocompletePicker.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type AutocompleteOptions = {
4949
}
5050

5151
interface Callback1 {
52-
(subject: NamedNode, name: string): void;
52+
(_subject: NamedNode, _name: string): void;
5353
}
5454

5555
function assertString (x):string {
@@ -79,11 +79,13 @@ export async function renderAutoComplete (dom: HTMLDocument,
7979
style.setStyle(errorRow, 'autocompleteRowStyle')
8080
errorRow.style.padding = '1em'
8181
}
82+
/*
8283
function remove (ele?: HTMLElement) {
8384
if (ele && ele.parentNode) {
8485
ele.parentNode.removeChild(ele)
8586
}
8687
}
88+
*/
8789
function finish (object, name) {
8890
debug.log('Auto complete: finish! ' + object)
8991
// remove(decoration.cancelButton)
@@ -113,11 +115,12 @@ export async function renderAutoComplete (dom: HTMLDocument,
113115
}
114116
}
115117

118+
/*
116119
async function cancelButtonHandler (_event) {
117120
debug.log('Auto complete: Canceled by user! ')
118121
div.innerHTML = '' // Clear out the table
119122
}
120-
123+
*/
121124
function nameMatch (filter:string, candidate: string):boolean {
122125
const parts = filter.split(' ') // Each name part must be somewhere
123126
for (let j = 0; j < parts.length; j++) {
@@ -126,15 +129,15 @@ export async function renderAutoComplete (dom: HTMLDocument,
126129
}
127130
return true
128131
}
129-
132+
/*
130133
function cancelText (_event) {
131134
searchInput.value = ''
132135
if (decoration.acceptButton) {
133136
(decoration.acceptButton as any).disabled = true // start again
134137
}
135-
candidatesLoaded = false
138+
// candidatesLoaded = false
136139
}
137-
140+
*/
138141
function thinOut (filter) {
139142
let hits = 0
140143
let pick = undefined as NamedNode | undefined
@@ -177,11 +180,10 @@ export async function renderAutoComplete (dom: HTMLDocument,
177180
}
178181
inputEventHandlerLock = true
179182
const languagePrefs = await getPreferredLanguages()
180-
const language = languagePrefs[0] // if have to pick one
181183
const filter = searchInput.value.trim().toLowerCase()
182184
if (filter.length < AUTOCOMPLETE_THRESHOLD) { // too small
183185
clearList()
184-
candidatesLoaded = false
186+
// candidatesLoaded = false
185187
numberOfRows = AUTOCOMPLETE_ROWS
186188
} else {
187189
if (allDisplayed && lastFilter && filter.startsWith(lastFilter)) {
@@ -198,7 +200,7 @@ export async function renderAutoComplete (dom: HTMLDocument,
198200
inputEventHandlerLock = false
199201
return
200202
}
201-
candidatesLoaded = true
203+
// candidatesLoaded = true
202204
const loadedEnough = bindings.length < AUTOCOMPLETE_LIMIT
203205
if (loadedEnough) {
204206
lastFilter = filter
@@ -234,7 +236,7 @@ export async function renderAutoComplete (dom: HTMLDocument,
234236
inputEventHandlerLock = false
235237
} // refreshList
236238

237-
const queryParams: QueryParameters = options.queryParams
239+
// const queryParams: QueryParameters = options.queryParams
238240
const OrgClass = options.targetClass // kb.sym('http://umbel.org/umbel/rc/EducationalOrganization') // @@@ other
239241
if (decoration.acceptButton) {
240242
decoration.acceptButton.addEventListener('click', acceptButtonHandler, false)
@@ -243,7 +245,7 @@ export async function renderAutoComplete (dom: HTMLDocument,
243245
// decoration.cancelButton.addEventListener('click', cancelButtonHandler, false)
244246
}
245247

246-
var candidatesLoaded = false
248+
// var candidatesLoaded = false
247249
const runningTimeout = undefined as any
248250
let inputEventHandlerLock = false
249251
let allDisplayed = false

0 commit comments

Comments
 (0)