solid-ui 2.6.1-e5ad2945 → 2.6.1-e78cbe5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -1
- package/README.md +85 -26
- package/dist/acl/access-controller.js +238 -0
- package/dist/acl/access-controller.js.map +1 -0
- package/{lib → dist}/acl/access-groups.d.ts +2 -2
- package/{lib → dist}/acl/access-groups.d.ts.map +1 -1
- package/dist/acl/access-groups.js +323 -0
- package/dist/acl/access-groups.js.map +1 -0
- package/dist/acl/acl-control.js +173 -0
- package/dist/acl/acl-control.js.map +1 -0
- package/dist/acl/acl.js +495 -0
- package/dist/acl/acl.js.map +1 -0
- package/dist/acl/add-agent-buttons.js +217 -0
- package/dist/acl/add-agent-buttons.js.map +1 -0
- package/dist/acl/index.js +32 -0
- package/dist/acl/index.js.map +1 -0
- package/dist/acl/types.js +6 -0
- package/dist/acl/types.js.map +1 -0
- package/dist/chat/keys.js +106 -0
- package/dist/chat/keys.js.map +1 -0
- package/dist/chat/signature.js +63 -0
- package/dist/chat/signature.js.map +1 -0
- package/dist/create/create.js +249 -0
- package/dist/create/create.js.map +1 -0
- package/dist/create/index.js +5 -0
- package/dist/create/index.js.map +1 -0
- package/dist/create/types.js +2 -0
- package/dist/create/types.js.map +1 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +13 -0
- package/dist/debug.js.map +1 -0
- package/dist/footer/index.js +67 -0
- package/dist/footer/index.js.map +1 -0
- package/dist/header/empty-profile.js +11 -0
- package/dist/header/empty-profile.js.map +1 -0
- package/dist/header/index.js +260 -0
- package/dist/header/index.js.map +1 -0
- package/dist/iconBase.js +37 -0
- package/dist/iconBase.js.map +1 -0
- package/dist/icons/solid_logo.js.map +1 -0
- package/{lib → dist}/index.d.ts +7 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/{lib → dist}/log.d.ts.map +1 -1
- package/dist/log.js +182 -0
- package/dist/log.js.map +1 -0
- package/dist/login/login.js +858 -0
- package/dist/login/login.js.map +1 -0
- package/dist/matrix/index.js +5 -0
- package/dist/matrix/index.js.map +1 -0
- package/dist/matrix/matrix.js +217 -0
- package/dist/matrix/matrix.js.map +1 -0
- package/dist/matrix/types.js +2 -0
- package/dist/matrix/types.js.map +1 -0
- package/dist/media/index.js +6 -0
- package/dist/media/index.js.map +1 -0
- package/dist/media/media-capture.js +161 -0
- package/dist/media/media-capture.js.map +1 -0
- package/dist/pad.js +775 -0
- package/dist/pad.js.map +1 -0
- package/{lib → dist}/participation.d.ts.map +1 -1
- package/dist/participation.js +184 -0
- package/dist/participation.js.map +1 -0
- package/dist/solid-ui.esm.js +25531 -0
- package/dist/solid-ui.esm.js.map +1 -0
- package/dist/solid-ui.esm.min.js +43 -0
- package/dist/solid-ui.esm.min.js.map +1 -0
- package/dist/solid-ui.js +23479 -68931
- package/dist/solid-ui.js.map +1 -1
- package/dist/solid-ui.min.js +40 -2
- package/dist/solid-ui.min.js.map +1 -1
- package/dist/tabs.js +388 -0
- package/dist/tabs.js.map +1 -0
- package/{lib → dist}/utils/headerFooterHelpers.d.ts.map +1 -1
- package/dist/utils/headerFooterHelpers.js +114 -0
- package/dist/utils/headerFooterHelpers.js.map +1 -0
- package/dist/utils/keyHelpers/accessData.js +64 -0
- package/dist/utils/keyHelpers/accessData.js.map +1 -0
- package/dist/utils/keyHelpers/acl.js +74 -0
- package/dist/utils/keyHelpers/acl.js.map +1 -0
- package/dist/utils/keyHelpers/otherHelpers.js +13 -0
- package/dist/utils/keyHelpers/otherHelpers.js.map +1 -0
- package/dist/utils/label.js +111 -0
- package/dist/utils/label.js.map +1 -0
- package/dist/versionInfo.js +31 -0
- package/dist/versionInfo.js.map +1 -0
- package/dist/widgets/buttons/iconLinks.js +44 -0
- package/dist/widgets/buttons/iconLinks.js.map +1 -0
- package/dist/widgets/buttons.js +1280 -0
- package/dist/widgets/buttons.js.map +1 -0
- package/dist/widgets/error.d.ts +14 -0
- package/dist/widgets/error.d.ts.map +1 -0
- package/dist/widgets/error.js +35 -0
- package/dist/widgets/error.js.map +1 -0
- package/dist/widgets/forms/autocomplete/autocompleteBar.js +123 -0
- package/dist/widgets/forms/autocomplete/autocompleteBar.js.map +1 -0
- package/dist/widgets/forms/autocomplete/autocompleteField.js +199 -0
- package/dist/widgets/forms/autocomplete/autocompleteField.js.map +1 -0
- package/dist/widgets/forms/autocomplete/autocompletePicker.js +256 -0
- package/dist/widgets/forms/autocomplete/autocompletePicker.js.map +1 -0
- package/dist/widgets/forms/autocomplete/language.js +104 -0
- package/dist/widgets/forms/autocomplete/language.js.map +1 -0
- package/dist/widgets/forms/autocomplete/publicData.js +460 -0
- package/dist/widgets/forms/autocomplete/publicData.js.map +1 -0
- package/dist/widgets/forms/basic.js +241 -0
- package/dist/widgets/forms/basic.js.map +1 -0
- package/dist/widgets/forms/comment.js +46 -0
- package/dist/widgets/forms/comment.js.map +1 -0
- package/dist/widgets/forms/fieldFunction.js +44 -0
- package/dist/widgets/forms/fieldFunction.js.map +1 -0
- package/dist/widgets/forms/fieldParams.js +89 -0
- package/dist/widgets/forms/fieldParams.js.map +1 -0
- package/{lib → dist}/widgets/forms/formStyle.d.ts.map +1 -1
- package/dist/widgets/forms/formStyle.js +36 -0
- package/dist/widgets/forms/formStyle.js.map +1 -0
- package/{lib → dist}/widgets/widgetHelpers.d.ts.map +1 -1
- package/{lib → dist}/widgets/widgetHelpers.js +14 -25
- package/dist/widgets/widgetHelpers.js.map +1 -0
- package/package.json +48 -52
- package/dist/789.solid-ui.min.js +0 -1
- package/dist/841.solid-ui.min.js +0 -3
- package/dist/841.solid-ui.min.js.LICENSE.txt +0 -58
- package/dist/841.solid-ui.min.js.map +0 -1
- package/dist/_2b19.solid-ui.js +0 -14
- package/dist/_2b19.solid-ui.js.map +0 -1
- package/dist/index.html +0 -1
- package/dist/solid-ui.min.js.LICENSE.txt +0 -57
- package/dist/vendors-node_modules_jsonld_lib_jsonld_js.solid-ui.js +0 -12247
- package/dist/vendors-node_modules_jsonld_lib_jsonld_js.solid-ui.js.map +0 -1
- package/lib/acl/access-controller.js +0 -391
- package/lib/acl/access-controller.js.map +0 -1
- package/lib/acl/access-groups.js +0 -507
- package/lib/acl/access-groups.js.map +0 -1
- package/lib/acl/acl-control.js +0 -237
- package/lib/acl/acl-control.js.map +0 -1
- package/lib/acl/acl.js +0 -517
- package/lib/acl/acl.js.map +0 -1
- package/lib/acl/add-agent-buttons.js +0 -434
- package/lib/acl/add-agent-buttons.js.map +0 -1
- package/lib/acl/index.js +0 -39
- package/lib/acl/index.js.map +0 -1
- package/lib/acl/types.js +0 -6
- package/lib/acl/types.js.map +0 -1
- package/lib/chat/bookmarks.js +0 -303
- package/lib/chat/bookmarks.js.map +0 -1
- package/lib/chat/chatLogic.js +0 -420
- package/lib/chat/chatLogic.js.map +0 -1
- package/lib/chat/dateFolder.js +0 -328
- package/lib/chat/dateFolder.js.map +0 -1
- package/lib/chat/infinite.js +0 -994
- package/lib/chat/infinite.js.map +0 -1
- package/lib/chat/keys.js +0 -232
- package/lib/chat/keys.js.map +0 -1
- package/lib/chat/message.js +0 -715
- package/lib/chat/message.js.map +0 -1
- package/lib/chat/messageTools.js +0 -538
- package/lib/chat/messageTools.js.map +0 -1
- package/lib/chat/signature.js +0 -109
- package/lib/chat/signature.js.map +0 -1
- package/lib/chat/thread.js +0 -535
- package/lib/chat/thread.js.map +0 -1
- package/lib/create/create.js +0 -242
- package/lib/create/create.js.map +0 -1
- package/lib/create/index.js +0 -11
- package/lib/create/index.js.map +0 -1
- package/lib/create/types.js +0 -6
- package/lib/create/types.js.map +0 -1
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js +0 -30
- package/lib/debug.js.map +0 -1
- package/lib/folders.js +0 -132
- package/lib/folders.js.map +0 -1
- package/lib/footer/index.js +0 -123
- package/lib/footer/index.js.map +0 -1
- package/lib/header/empty-profile.js +0 -8
- package/lib/header/empty-profile.js.map +0 -1
- package/lib/header/index.js +0 -375
- package/lib/header/index.js.map +0 -1
- package/lib/iconBase.js +0 -44
- package/lib/iconBase.js.map +0 -1
- package/lib/icons/solid_logo.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -223
- package/lib/index.js.map +0 -1
- package/lib/log.js +0 -213
- package/lib/log.js.map +0 -1
- package/lib/login/login.js +0 -1241
- package/lib/login/login.js.map +0 -1
- package/lib/matrix/index.js +0 -11
- package/lib/matrix/index.js.map +0 -1
- package/lib/matrix/matrix.js +0 -216
- package/lib/matrix/matrix.js.map +0 -1
- package/lib/matrix/types.js +0 -6
- package/lib/matrix/types.js.map +0 -1
- package/lib/media/index.js +0 -12
- package/lib/media/index.js.map +0 -1
- package/lib/media/media-capture.js +0 -194
- package/lib/media/media-capture.js.map +0 -1
- package/lib/messageArea.js +0 -319
- package/lib/messageArea.js.map +0 -1
- package/lib/noun_Camera_1618446_000000.js +0 -8
- package/lib/noun_Camera_1618446_000000.js.map +0 -1
- package/lib/ns.js +0 -17
- package/lib/ns.js.map +0 -1
- package/lib/pad.js +0 -805
- package/lib/pad.js.map +0 -1
- package/lib/participation.js +0 -219
- package/lib/participation.js.map +0 -1
- package/lib/preferences.js +0 -215
- package/lib/preferences.js.map +0 -1
- package/lib/signup/config-default.js +0 -43
- package/lib/signup/config-default.js.map +0 -1
- package/lib/signup/signup.js +0 -74
- package/lib/signup/signup.js.map +0 -1
- package/lib/stories/decorators.js +0 -10
- package/lib/stories/decorators.js.map +0 -1
- package/lib/style.js +0 -158
- package/lib/style.js.map +0 -1
- package/lib/styleConstants.js +0 -35
- package/lib/styleConstants.js.map +0 -1
- package/lib/style_multiSelect.js +0 -62
- package/lib/style_multiSelect.js.map +0 -1
- package/lib/table.js +0 -1573
- package/lib/table.js.map +0 -1
- package/lib/tabs.js +0 -448
- package/lib/tabs.js.map +0 -1
- package/lib/typings.d.js +0 -2
- package/lib/typings.d.js.map +0 -1
- package/lib/utils/headerFooterHelpers.js +0 -165
- package/lib/utils/headerFooterHelpers.js.map +0 -1
- package/lib/utils/index.js +0 -527
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/keyHelpers/accessData.js +0 -131
- package/lib/utils/keyHelpers/accessData.js.map +0 -1
- package/lib/utils/keyHelpers/acl.js +0 -90
- package/lib/utils/keyHelpers/acl.js.map +0 -1
- package/lib/utils/keyHelpers/otherHelpers.js +0 -21
- package/lib/utils/keyHelpers/otherHelpers.js.map +0 -1
- package/lib/utils/label.js +0 -103
- package/lib/utils/label.js.map +0 -1
- package/lib/versionInfo.d.ts +0 -32
- package/lib/versionInfo.d.ts.map +0 -1
- package/lib/versionInfo.js +0 -37
- package/lib/versionInfo.js.map +0 -1
- package/lib/widgets/buttons/iconLinks.js +0 -53
- package/lib/widgets/buttons/iconLinks.js.map +0 -1
- package/lib/widgets/buttons.js +0 -1306
- package/lib/widgets/buttons.js.map +0 -1
- package/lib/widgets/dragAndDrop.js +0 -194
- package/lib/widgets/dragAndDrop.js.map +0 -1
- package/lib/widgets/error.d.ts +0 -2
- package/lib/widgets/error.d.ts.map +0 -1
- package/lib/widgets/error.js +0 -46
- package/lib/widgets/error.js.map +0 -1
- package/lib/widgets/forms/autocomplete/autocompleteBar.js +0 -271
- package/lib/widgets/forms/autocomplete/autocompleteBar.js.map +0 -1
- package/lib/widgets/forms/autocomplete/autocompleteField.js +0 -258
- package/lib/widgets/forms/autocomplete/autocompleteField.js.map +0 -1
- package/lib/widgets/forms/autocomplete/autocompletePicker.js +0 -436
- package/lib/widgets/forms/autocomplete/autocompletePicker.js.map +0 -1
- package/lib/widgets/forms/autocomplete/language.js +0 -189
- package/lib/widgets/forms/autocomplete/language.js.map +0 -1
- package/lib/widgets/forms/autocomplete/publicData.js +0 -636
- package/lib/widgets/forms/autocomplete/publicData.js.map +0 -1
- package/lib/widgets/forms/basic.js +0 -254
- package/lib/widgets/forms/basic.js.map +0 -1
- package/lib/widgets/forms/comment.js +0 -54
- package/lib/widgets/forms/comment.js.map +0 -1
- package/lib/widgets/forms/fieldFunction.js +0 -52
- package/lib/widgets/forms/fieldFunction.js.map +0 -1
- package/lib/widgets/forms/fieldParams.js +0 -77
- package/lib/widgets/forms/fieldParams.js.map +0 -1
- package/lib/widgets/forms/formStyle.js +0 -44
- package/lib/widgets/forms/formStyle.js.map +0 -1
- package/lib/widgets/forms.js +0 -2045
- package/lib/widgets/forms.js.map +0 -1
- package/lib/widgets/index.js +0 -110
- package/lib/widgets/index.js.map +0 -1
- package/lib/widgets/multiSelect.js +0 -658
- package/lib/widgets/multiSelect.js.map +0 -1
- package/lib/widgets/peoplePicker.js +0 -467
- package/lib/widgets/peoplePicker.js.map +0 -1
- package/lib/widgets/widgetHelpers.js.map +0 -1
- /package/{lib → dist}/acl/access-controller.d.ts +0 -0
- /package/{lib → dist}/acl/access-controller.d.ts.map +0 -0
- /package/{lib → dist}/acl/acl-control.d.ts +0 -0
- /package/{lib → dist}/acl/acl-control.d.ts.map +0 -0
- /package/{lib → dist}/acl/acl.d.ts +0 -0
- /package/{lib → dist}/acl/acl.d.ts.map +0 -0
- /package/{lib → dist}/acl/add-agent-buttons.d.ts +0 -0
- /package/{lib → dist}/acl/add-agent-buttons.d.ts.map +0 -0
- /package/{lib → dist}/acl/index.d.ts +0 -0
- /package/{lib → dist}/acl/index.d.ts.map +0 -0
- /package/{lib → dist}/acl/types.d.ts +0 -0
- /package/{lib → dist}/acl/types.d.ts.map +0 -0
- /package/{lib → dist}/chat/keys.d.ts +0 -0
- /package/{lib → dist}/chat/keys.d.ts.map +0 -0
- /package/{lib → dist}/chat/signature.d.ts +0 -0
- /package/{lib → dist}/chat/signature.d.ts.map +0 -0
- /package/{lib → dist}/create/create.d.ts +0 -0
- /package/{lib → dist}/create/create.d.ts.map +0 -0
- /package/{lib → dist}/create/index.d.ts +0 -0
- /package/{lib → dist}/create/index.d.ts.map +0 -0
- /package/{lib → dist}/create/types.d.ts +0 -0
- /package/{lib → dist}/create/types.d.ts.map +0 -0
- /package/{lib → dist}/debug.d.ts +0 -0
- /package/{lib → dist}/footer/index.d.ts +0 -0
- /package/{lib → dist}/footer/index.d.ts.map +0 -0
- /package/{lib → dist}/header/empty-profile.d.ts +0 -0
- /package/{lib → dist}/header/empty-profile.d.ts.map +0 -0
- /package/{lib → dist}/header/index.d.ts +0 -0
- /package/{lib → dist}/header/index.d.ts.map +0 -0
- /package/{lib → dist}/iconBase.d.ts +0 -0
- /package/{lib → dist}/iconBase.d.ts.map +0 -0
- /package/{lib → dist}/icons/solid_logo.d.ts +0 -0
- /package/{lib → dist}/icons/solid_logo.d.ts.map +0 -0
- /package/{lib → dist}/icons/solid_logo.js +0 -0
- /package/{lib → dist}/log.d.ts +0 -0
- /package/{lib → dist}/login/login.d.ts +0 -0
- /package/{lib → dist}/login/login.d.ts.map +0 -0
- /package/{lib → dist}/matrix/index.d.ts +0 -0
- /package/{lib → dist}/matrix/index.d.ts.map +0 -0
- /package/{lib → dist}/matrix/matrix.d.ts +0 -0
- /package/{lib → dist}/matrix/matrix.d.ts.map +0 -0
- /package/{lib → dist}/matrix/types.d.ts +0 -0
- /package/{lib → dist}/matrix/types.d.ts.map +0 -0
- /package/{lib → dist}/media/index.d.ts +0 -0
- /package/{lib → dist}/media/index.d.ts.map +0 -0
- /package/{lib → dist}/media/media-capture.d.ts +0 -0
- /package/{lib → dist}/media/media-capture.d.ts.map +0 -0
- /package/{lib → dist}/pad.d.ts +0 -0
- /package/{lib → dist}/pad.d.ts.map +0 -0
- /package/{lib → dist}/participation.d.ts +0 -0
- /package/{lib → dist}/tabs.d.ts +0 -0
- /package/{lib → dist}/tabs.d.ts.map +0 -0
- /package/{lib → dist}/utils/headerFooterHelpers.d.ts +0 -0
- /package/{lib → dist}/utils/keyHelpers/accessData.d.ts +0 -0
- /package/{lib → dist}/utils/keyHelpers/accessData.d.ts.map +0 -0
- /package/{lib → dist}/utils/keyHelpers/acl.d.ts +0 -0
- /package/{lib → dist}/utils/keyHelpers/acl.d.ts.map +0 -0
- /package/{lib → dist}/utils/keyHelpers/otherHelpers.d.ts +0 -0
- /package/{lib → dist}/utils/keyHelpers/otherHelpers.d.ts.map +0 -0
- /package/{lib → dist}/utils/label.d.ts +0 -0
- /package/{lib → dist}/utils/label.d.ts.map +0 -0
- /package/{lib → dist}/widgets/buttons/iconLinks.d.ts +0 -0
- /package/{lib → dist}/widgets/buttons/iconLinks.d.ts.map +0 -0
- /package/{lib → dist}/widgets/buttons.d.ts +0 -0
- /package/{lib → dist}/widgets/buttons.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompleteBar.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompleteBar.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompleteField.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompleteField.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompletePicker.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/autocompletePicker.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/language.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/language.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/publicData.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/autocomplete/publicData.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/basic.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/basic.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/comment.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/comment.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/fieldFunction.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/fieldFunction.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/fieldParams.d.ts +0 -0
- /package/{lib → dist}/widgets/forms/fieldParams.d.ts.map +0 -0
- /package/{lib → dist}/widgets/forms/formStyle.d.ts +0 -0
- /package/{lib → dist}/widgets/widgetHelpers.d.ts +0 -0
package/dist/pad.js
ADDED
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
/** **************
|
|
2
|
+
* Notepad Widget
|
|
3
|
+
*/
|
|
4
|
+
/** @module pad
|
|
5
|
+
*/
|
|
6
|
+
import ns from './ns';
|
|
7
|
+
import { Namespace, NamedNode, st } from 'rdflib';
|
|
8
|
+
import { newThing, errorMessageBlock } from './widgets';
|
|
9
|
+
import { beep } from './utils';
|
|
10
|
+
import { log } from './debug';
|
|
11
|
+
import { solidLogicSingleton } from 'solid-logic';
|
|
12
|
+
import { style } from './style';
|
|
13
|
+
export { renderParticipants, participationObject, manageParticipation, recordParticipation } from './participation';
|
|
14
|
+
const store = solidLogicSingleton.store;
|
|
15
|
+
const PAD = Namespace('http://www.w3.org/ns/pim/pad#');
|
|
16
|
+
/**
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
|
+
class NotepadElement extends HTMLElement {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
class NotepadPart extends HTMLElement {
|
|
25
|
+
}
|
|
26
|
+
/** Figure out a random color from my webid
|
|
27
|
+
*
|
|
28
|
+
* @param {NamedNode} author - The author of text being displayed
|
|
29
|
+
* @returns {String} The CSS color generated, constrained to be light for a background color
|
|
30
|
+
*/
|
|
31
|
+
export function lightColorHash(author) {
|
|
32
|
+
const hash = function (x) {
|
|
33
|
+
return x.split('').reduce(function (a, b) {
|
|
34
|
+
a = (a << 5) - a + b.charCodeAt(0);
|
|
35
|
+
return a & a;
|
|
36
|
+
}, 0);
|
|
37
|
+
};
|
|
38
|
+
return author && author.uri
|
|
39
|
+
? '#' + ((hash(author.uri) & 0xffffff) | 0xc0c0c0).toString(16)
|
|
40
|
+
: '#ffffff'; // c0c0c0 forces pale
|
|
41
|
+
} // no id -> white
|
|
42
|
+
/** notepad
|
|
43
|
+
*
|
|
44
|
+
* @param {HTMLDocument} dom - the web page of the browser
|
|
45
|
+
* @param {NamedNode} padDoc - the document in which the participation should be shown
|
|
46
|
+
* @param {NamedNode} subject - the thing in which participation is happening
|
|
47
|
+
* @param {NamedNode} me - person who is logged into the pod
|
|
48
|
+
* @param {notepadOptions} options - the options that can be passed in consist of statusArea, exists
|
|
49
|
+
*/
|
|
50
|
+
export function notepad(dom, padDoc, subject, me, options) {
|
|
51
|
+
options = options || {};
|
|
52
|
+
const exists = options.exists;
|
|
53
|
+
const table = dom.createElement('table');
|
|
54
|
+
const kb = store;
|
|
55
|
+
if (me && !me.uri)
|
|
56
|
+
throw new Error('UI.pad.notepad: Invalid userid');
|
|
57
|
+
const updater = store.updater;
|
|
58
|
+
const PAD = Namespace('http://www.w3.org/ns/pim/pad#');
|
|
59
|
+
table.setAttribute('style', style.notepadStyle);
|
|
60
|
+
let upstreamStatus = null;
|
|
61
|
+
let downstreamStatus = null;
|
|
62
|
+
if (options.statusArea) {
|
|
63
|
+
const t = options.statusArea.appendChild(dom.createElement('table'));
|
|
64
|
+
const tr = t.appendChild(dom.createElement('tr'));
|
|
65
|
+
upstreamStatus = tr.appendChild(dom.createElement('td'));
|
|
66
|
+
downstreamStatus = tr.appendChild(dom.createElement('td'));
|
|
67
|
+
if (upstreamStatus) {
|
|
68
|
+
upstreamStatus.setAttribute('style', style.upstreamStatus);
|
|
69
|
+
}
|
|
70
|
+
if (downstreamStatus) {
|
|
71
|
+
downstreamStatus.setAttribute('style', style.downstreamStatus);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/* @@ TODO want to look into this, it seems upstream should be a boolean and default to false ?
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
const complain = function (message, upstream = false) {
|
|
78
|
+
log(message);
|
|
79
|
+
if (options.statusArea) {
|
|
80
|
+
;
|
|
81
|
+
(upstream ? upstreamStatus : downstreamStatus).appendChild(errorMessageBlock(dom, message, 'pink'));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// @@ TODO need to refactor so that we don't have to type cast
|
|
85
|
+
const clearStatus = function (_upsteam) {
|
|
86
|
+
if (options.statusArea) {
|
|
87
|
+
options.statusArea.innerHTML = '';
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const setPartStyle = function (part, colors, pending) {
|
|
91
|
+
const chunk = part.subject;
|
|
92
|
+
colors = colors || '';
|
|
93
|
+
const baseStyle = style.baseStyle;
|
|
94
|
+
const headingCore = style.headingCore;
|
|
95
|
+
const headingStyle = style.headingStyle;
|
|
96
|
+
const author = kb.any(chunk, ns.dc('author'));
|
|
97
|
+
if (!colors && author) {
|
|
98
|
+
// Hash the user webid for now -- later allow user selection!
|
|
99
|
+
const bgcolor = lightColorHash(author);
|
|
100
|
+
colors =
|
|
101
|
+
'color: ' +
|
|
102
|
+
(pending ? '#888' : 'black') +
|
|
103
|
+
'; background-color: ' +
|
|
104
|
+
bgcolor +
|
|
105
|
+
';';
|
|
106
|
+
}
|
|
107
|
+
// @@ TODO Need to research when this can be an object with the indent stored in value
|
|
108
|
+
// and when the indent is stored as a Number itself, not in an object.
|
|
109
|
+
let indent = kb.any(chunk, PAD('indent'));
|
|
110
|
+
indent = indent ? indent.value : 0;
|
|
111
|
+
const localStyle = indent >= 0
|
|
112
|
+
? baseStyle + 'text-indent: ' + indent * 3 + 'em;'
|
|
113
|
+
: headingCore + headingStyle[-1 - indent];
|
|
114
|
+
// ? baseStyle + 'padding-left: ' + (indent * 3) + 'em;'
|
|
115
|
+
part.setAttribute('style', localStyle + colors);
|
|
116
|
+
};
|
|
117
|
+
const removePart = function (part) {
|
|
118
|
+
const chunk = part.subject;
|
|
119
|
+
if (!chunk)
|
|
120
|
+
throw new Error('No chunk for line to be deleted!'); // just in case
|
|
121
|
+
const prev = kb.any(undefined, PAD('next'), chunk);
|
|
122
|
+
const next = kb.any(chunk, PAD('next'));
|
|
123
|
+
if (prev.sameTerm(subject) && next.sameTerm(subject)) {
|
|
124
|
+
// Last one
|
|
125
|
+
log('You can\'t delete the only line.');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const del = kb
|
|
129
|
+
.statementsMatching(chunk, undefined, undefined, padDoc)
|
|
130
|
+
.concat(kb.statementsMatching(undefined, undefined, chunk, padDoc));
|
|
131
|
+
const ins = [st(prev, PAD('next'), next, padDoc)];
|
|
132
|
+
// @@ TODO what should we do if chunk is not a NamedNode should we
|
|
133
|
+
// assume then it is a string?
|
|
134
|
+
if (chunk instanceof NamedNode) {
|
|
135
|
+
const label = chunk.uri.slice(-4);
|
|
136
|
+
log('Deleting line ' + label);
|
|
137
|
+
}
|
|
138
|
+
if (!updater) {
|
|
139
|
+
throw new Error('have no updater');
|
|
140
|
+
}
|
|
141
|
+
// @@ TODO below you can see that before is redefined and not a boolean
|
|
142
|
+
updater.update(del, ins, function (uri, ok, errorMessage, response) {
|
|
143
|
+
if (ok) {
|
|
144
|
+
const row = part.parentNode;
|
|
145
|
+
if (row) {
|
|
146
|
+
const before = row.previousSibling;
|
|
147
|
+
if (row.parentNode) {
|
|
148
|
+
row.parentNode.removeChild(row);
|
|
149
|
+
}
|
|
150
|
+
// console.log(' deleted line ' + label + ' ok ' + part.value)
|
|
151
|
+
if (before && before.firstChild) {
|
|
152
|
+
// @@ TODO IMPORTANT FOCUS ISN'T A PROPERTY ON A CHILDNODE
|
|
153
|
+
before.firstChild.focus();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (response && response.status === 409) {
|
|
158
|
+
// Conflict
|
|
159
|
+
setPartStyle(part, 'color: black; background-color: #ffd;'); // yellow
|
|
160
|
+
part.state = 0; // Needs downstream refresh
|
|
161
|
+
beep(0.5, 512); // Ooops clash with other person
|
|
162
|
+
setTimeout(function () {
|
|
163
|
+
// Ideally, beep! @@
|
|
164
|
+
reloadAndSync(); // Throw away our changes and
|
|
165
|
+
// updater.requestDownstreamAction(padDoc, reloadAndSync)
|
|
166
|
+
}, 1000);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
log(' removePart FAILED ' + chunk + ': ' + errorMessage);
|
|
170
|
+
log(' removePart was deleteing :\'' + del);
|
|
171
|
+
setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
|
|
172
|
+
const res = response ? response.status : ' [no response field] ';
|
|
173
|
+
complain('Error ' + res + ' saving changes: ' + errorMessage.true); // upstream,
|
|
174
|
+
// updater.requestDownstreamAction(padDoc, reloadAndSync);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}; // removePart
|
|
178
|
+
const changeIndent = function (part, chunk, delta) {
|
|
179
|
+
const del = kb.statementsMatching(chunk, PAD('indent'));
|
|
180
|
+
const current = del.length ? Number(del[0].object.value) : 0;
|
|
181
|
+
if (current + delta < -3)
|
|
182
|
+
return; // limit negative indent
|
|
183
|
+
const newIndent = current + delta;
|
|
184
|
+
const ins = st(chunk, PAD('indent'), newIndent, padDoc);
|
|
185
|
+
if (!updater) {
|
|
186
|
+
throw new Error('no updater');
|
|
187
|
+
}
|
|
188
|
+
updater.update(del, ins, function (uri, ok, errorBody) {
|
|
189
|
+
if (!ok) {
|
|
190
|
+
log('Indent change FAILED \'' +
|
|
191
|
+
newIndent +
|
|
192
|
+
'\' for ' +
|
|
193
|
+
padDoc +
|
|
194
|
+
': ' +
|
|
195
|
+
errorBody);
|
|
196
|
+
setPartStyle(part, 'color: black; background-color: #fdd;'); // failed
|
|
197
|
+
updater.requestDownstreamAction(padDoc, reloadAndSync);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
setPartStyle(part); // Implement the indent
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const addListeners = function (part, chunk) {
|
|
205
|
+
part.addEventListener('keydown', function (event) {
|
|
206
|
+
if (!updater) {
|
|
207
|
+
throw new Error('no updater');
|
|
208
|
+
}
|
|
209
|
+
let queueProperty, queue;
|
|
210
|
+
// up 38; down 40; left 37; right 39 tab 9; shift 16; escape 27
|
|
211
|
+
switch (event.keyCode) {
|
|
212
|
+
case 13: // Return
|
|
213
|
+
{
|
|
214
|
+
const before = event.shiftKey;
|
|
215
|
+
log('enter'); // Shift-return inserts before -- only way to add to top of pad.
|
|
216
|
+
if (before) {
|
|
217
|
+
queue = kb.any(undefined, PAD('next'), chunk);
|
|
218
|
+
queueProperty = 'newlinesAfter';
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
queue = kb.any(chunk, PAD('next'));
|
|
222
|
+
queueProperty = 'newlinesBefore';
|
|
223
|
+
}
|
|
224
|
+
queue[queueProperty] = queue[queueProperty] || 0;
|
|
225
|
+
queue[queueProperty] += 1;
|
|
226
|
+
if (queue[queueProperty] > 1) {
|
|
227
|
+
log(' queueing newline queue = ' + queue[queueProperty]);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
log(' go ahead line before ' + queue[queueProperty]);
|
|
231
|
+
newChunk(part, before); // was document.activeElement
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case 8: // Delete
|
|
235
|
+
if (part.value.length === 0) {
|
|
236
|
+
log('Delete key line ' + chunk.uri.slice(-4) + ' state ' + part.state);
|
|
237
|
+
switch (part.state) {
|
|
238
|
+
case 1: // contents being sent
|
|
239
|
+
case 2: // contents need to be sent again
|
|
240
|
+
part.state = 4; // delete me
|
|
241
|
+
return;
|
|
242
|
+
case 3: // already being deleted
|
|
243
|
+
case 4: // already deleted state
|
|
244
|
+
return;
|
|
245
|
+
case undefined:
|
|
246
|
+
case 0:
|
|
247
|
+
part.state = 3; // being deleted
|
|
248
|
+
removePart(part);
|
|
249
|
+
event.preventDefault();
|
|
250
|
+
break; // continue
|
|
251
|
+
default:
|
|
252
|
+
throw new Error('pad: Unexpected state ' + part);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
case 9: // Tab
|
|
257
|
+
{
|
|
258
|
+
const delta = event.shiftKey ? -1 : 1;
|
|
259
|
+
changeIndent(part, chunk, delta);
|
|
260
|
+
event.preventDefault(); // default is to highlight next field
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 27: // ESC
|
|
264
|
+
log('escape');
|
|
265
|
+
updater.requestDownstreamAction(padDoc, reloadAndSync);
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
break;
|
|
268
|
+
case 38: // Up
|
|
269
|
+
if (part.parentNode.previousSibling) {
|
|
270
|
+
part.parentNode.previousSibling.firstChild.focus();
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
}
|
|
273
|
+
break;
|
|
274
|
+
case 40: // Down
|
|
275
|
+
if (part.parentNode.nextSibling) {
|
|
276
|
+
part.parentNode.nextSibling.firstChild.focus();
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
280
|
+
default:
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
const updateStore = function (part) {
|
|
284
|
+
const chunk = part.subject;
|
|
285
|
+
setPartStyle(part, undefined, true);
|
|
286
|
+
const old = kb.any(chunk, ns.sioc('content')).value;
|
|
287
|
+
const del = [st(chunk, ns.sioc('content'), old, padDoc)];
|
|
288
|
+
let ins;
|
|
289
|
+
if (part.value) {
|
|
290
|
+
ins = [st(chunk, ns.sioc('content'), part.value, padDoc)];
|
|
291
|
+
}
|
|
292
|
+
const newOne = part.value;
|
|
293
|
+
// DEBUGGING ONLY
|
|
294
|
+
if (part.lastSent) {
|
|
295
|
+
if (old !== part.lastSent) {
|
|
296
|
+
throw new Error('Out of order, last sent expected \'' +
|
|
297
|
+
old +
|
|
298
|
+
'\' but found \'' +
|
|
299
|
+
part.lastSent +
|
|
300
|
+
'\'');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
part.lastSent = newOne;
|
|
304
|
+
/* console.log(
|
|
305
|
+
' Patch proposed to ' +
|
|
306
|
+
chunk.uri.slice(-4) +
|
|
307
|
+
" '" +
|
|
308
|
+
old +
|
|
309
|
+
"' -> '" +
|
|
310
|
+
newOne +
|
|
311
|
+
"' "
|
|
312
|
+
) */
|
|
313
|
+
if (!updater) {
|
|
314
|
+
throw new Error('no updater');
|
|
315
|
+
}
|
|
316
|
+
updater.update(del, ins, function (uri, ok, errorBody, xhr) {
|
|
317
|
+
if (!ok) {
|
|
318
|
+
// alert("clash " + errorBody);
|
|
319
|
+
log(' patch FAILED ' +
|
|
320
|
+
xhr.status +
|
|
321
|
+
' for \'' +
|
|
322
|
+
old +
|
|
323
|
+
'\' -> \'' +
|
|
324
|
+
newOne +
|
|
325
|
+
'\': ' +
|
|
326
|
+
errorBody);
|
|
327
|
+
if (xhr.status === 409) {
|
|
328
|
+
// Conflict - @@ we assume someone else
|
|
329
|
+
setPartStyle(part, 'color: black; background-color: #fdd;');
|
|
330
|
+
part.state = 0; // Needs downstream refresh
|
|
331
|
+
beep(0.5, 512); // Ooops clash with other person
|
|
332
|
+
setTimeout(function () {
|
|
333
|
+
updater.requestDownstreamAction(padDoc, reloadAndSync);
|
|
334
|
+
}, 1000);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
setPartStyle(part, 'color: black; background-color: #fdd;'); // failed pink
|
|
338
|
+
part.state = 0;
|
|
339
|
+
complain(' Error ' + xhr.status + ' sending data: ' + errorBody, true);
|
|
340
|
+
beep(1.0, 128); // Other
|
|
341
|
+
// @@@ Do soemthing more serious with other errors eg auth, etc
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
clearStatus(true); // upstream
|
|
346
|
+
setPartStyle(part); // synced
|
|
347
|
+
log(' Patch ok \'' + old + '\' -> \'' + newOne + '\' ');
|
|
348
|
+
if (part.state === 4) {
|
|
349
|
+
// delete me
|
|
350
|
+
part.state = 3;
|
|
351
|
+
removePart(part);
|
|
352
|
+
}
|
|
353
|
+
else if (part.state === 3) {
|
|
354
|
+
// being deleted
|
|
355
|
+
// pass
|
|
356
|
+
}
|
|
357
|
+
else if (part.state === 2) {
|
|
358
|
+
part.state = 1; // pending: lock
|
|
359
|
+
updateStore(part);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
part.state = 0; // clear lock
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
part.addEventListener('input', function inputChangeListener(_event) {
|
|
368
|
+
// debug.log("input changed "+part.value);
|
|
369
|
+
setPartStyle(part, undefined, true); // grey out - not synced
|
|
370
|
+
log('Input event state ' + part.state + ' value \'' + part.value + '\'');
|
|
371
|
+
switch (part.state) {
|
|
372
|
+
case 3: // being deleted
|
|
373
|
+
return;
|
|
374
|
+
case 4: // needs to be deleted
|
|
375
|
+
return;
|
|
376
|
+
case 2: // needs content updating, we know
|
|
377
|
+
return;
|
|
378
|
+
case 1:
|
|
379
|
+
part.state = 2; // lag we need another patch
|
|
380
|
+
return;
|
|
381
|
+
case 0:
|
|
382
|
+
case undefined:
|
|
383
|
+
part.state = 1; // being upadted
|
|
384
|
+
updateStore(part);
|
|
385
|
+
}
|
|
386
|
+
}); // listener
|
|
387
|
+
}; // addlisteners
|
|
388
|
+
// @@ TODO Need to research before as it appears to be used as an Element and a boolean
|
|
389
|
+
const newPartAfter = function (tr1, chunk, before) {
|
|
390
|
+
// @@ take chunk and add listeners
|
|
391
|
+
let text = kb.any(chunk, ns.sioc('content'));
|
|
392
|
+
text = text ? text.value : '';
|
|
393
|
+
const tr = dom.createElement('tr');
|
|
394
|
+
if (before) {
|
|
395
|
+
table.insertBefore(tr, tr1);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
// after
|
|
399
|
+
if (tr1 && tr1.nextSibling) {
|
|
400
|
+
table.insertBefore(tr, tr1.nextSibling);
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
table.appendChild(tr);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const part = tr.appendChild(dom.createElement('input'));
|
|
407
|
+
part.subject = chunk;
|
|
408
|
+
part.setAttribute('type', 'text');
|
|
409
|
+
part.value = text;
|
|
410
|
+
if (me) {
|
|
411
|
+
setPartStyle(part, '');
|
|
412
|
+
addListeners(part, chunk);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
setPartStyle(part, 'color: #222; background-color: #fff');
|
|
416
|
+
log('Note can\'t add listeners - not logged in');
|
|
417
|
+
}
|
|
418
|
+
return part;
|
|
419
|
+
};
|
|
420
|
+
/* @@ TODO we need to look at indent, it can be a Number or an Object this doesn't seem correct.
|
|
421
|
+
*/
|
|
422
|
+
const newChunk = function (ele, before) {
|
|
423
|
+
// element of chunk being split
|
|
424
|
+
const kb = store;
|
|
425
|
+
let indent = 0;
|
|
426
|
+
let queueProperty = null;
|
|
427
|
+
let here, prev, next, queue, tr1;
|
|
428
|
+
if (ele) {
|
|
429
|
+
if (ele.tagName.toLowerCase() !== 'input') {
|
|
430
|
+
log('return pressed when current document is: ' + ele.tagName);
|
|
431
|
+
}
|
|
432
|
+
here = ele.subject;
|
|
433
|
+
indent = kb.any(here, PAD('indent'));
|
|
434
|
+
indent = indent ? Number(indent.value) : 0;
|
|
435
|
+
if (before) {
|
|
436
|
+
prev = kb.any(undefined, PAD('next'), here);
|
|
437
|
+
next = here;
|
|
438
|
+
queue = prev;
|
|
439
|
+
queueProperty = 'newlinesAfter';
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
prev = here;
|
|
443
|
+
next = kb.any(here, PAD('next'));
|
|
444
|
+
queue = next;
|
|
445
|
+
queueProperty = 'newlinesBefore';
|
|
446
|
+
}
|
|
447
|
+
tr1 = ele.parentNode;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
prev = subject;
|
|
451
|
+
next = subject;
|
|
452
|
+
tr1 = undefined;
|
|
453
|
+
}
|
|
454
|
+
const chunk = newThing(padDoc);
|
|
455
|
+
const label = chunk.uri.slice(-4);
|
|
456
|
+
const del = [st(prev, PAD('next'), next, padDoc)];
|
|
457
|
+
const ins = [
|
|
458
|
+
st(prev, PAD('next'), chunk, padDoc),
|
|
459
|
+
st(chunk, PAD('next'), next, padDoc),
|
|
460
|
+
st(chunk, ns.dc('author'), me, padDoc),
|
|
461
|
+
st(chunk, ns.sioc('content'), '', padDoc)
|
|
462
|
+
];
|
|
463
|
+
if (indent > 0) {
|
|
464
|
+
// Do not inherit
|
|
465
|
+
ins.push(st(chunk, PAD('indent'), indent, padDoc));
|
|
466
|
+
}
|
|
467
|
+
log(' Fresh chunk ' + label + ' proposed');
|
|
468
|
+
if (!updater) {
|
|
469
|
+
throw new Error('no updater');
|
|
470
|
+
}
|
|
471
|
+
updater.update(del, ins, function (uri, ok, errorBody, _xhr) {
|
|
472
|
+
if (!ok) {
|
|
473
|
+
// alert("Error writing new line " + label + ": " + errorBody);
|
|
474
|
+
log(' ERROR writing new line ' + label + ': ' + errorBody);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
const newPart = newPartAfter(tr1, chunk, before);
|
|
478
|
+
setPartStyle(newPart);
|
|
479
|
+
newPart.focus(); // Note this is delayed
|
|
480
|
+
if (queueProperty) {
|
|
481
|
+
log(' Fresh chunk ' +
|
|
482
|
+
label +
|
|
483
|
+
' updated, queue = ' +
|
|
484
|
+
queue[queueProperty]);
|
|
485
|
+
queue[queueProperty] -= 1;
|
|
486
|
+
if (queue[queueProperty] > 0) {
|
|
487
|
+
log(' Implementing queued newlines = ' + next.newLinesBefore);
|
|
488
|
+
newChunk(newPart, before);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
const consistencyCheck = function () {
|
|
495
|
+
const found = {};
|
|
496
|
+
let failed = 0;
|
|
497
|
+
function complain2(msg) {
|
|
498
|
+
complain(msg);
|
|
499
|
+
failed++;
|
|
500
|
+
}
|
|
501
|
+
if (!kb.the(subject, PAD('next'))) {
|
|
502
|
+
complain2('No initial next pointer');
|
|
503
|
+
return false; // can't do linked list
|
|
504
|
+
}
|
|
505
|
+
// var chunk = kb.the(subject, PAD('next'))
|
|
506
|
+
let prev = subject;
|
|
507
|
+
let chunk;
|
|
508
|
+
for (;;) {
|
|
509
|
+
chunk = kb.the(prev, PAD('next'));
|
|
510
|
+
if (!chunk) {
|
|
511
|
+
complain2('No next pointer from ' + prev);
|
|
512
|
+
}
|
|
513
|
+
if (chunk.sameTerm(subject)) {
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
prev = chunk;
|
|
517
|
+
const label = chunk.uri.split('#')[1];
|
|
518
|
+
if (found[chunk.uri]) {
|
|
519
|
+
complain2('Loop!');
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
found[chunk.uri] = true;
|
|
523
|
+
let k = kb.each(chunk, PAD('next')).length;
|
|
524
|
+
if (k !== 1) {
|
|
525
|
+
complain2('Should be 1 not ' + k + ' next pointer for ' + label);
|
|
526
|
+
}
|
|
527
|
+
k = kb.each(chunk, PAD('indent')).length;
|
|
528
|
+
if (k > 1) {
|
|
529
|
+
complain2('Should be 0 or 1 not ' + k + ' indent for ' + label);
|
|
530
|
+
}
|
|
531
|
+
k = kb.each(chunk, ns.sioc('content')).length;
|
|
532
|
+
if (k !== 1) {
|
|
533
|
+
complain2('Should be 1 not ' + k + ' contents for ' + label);
|
|
534
|
+
}
|
|
535
|
+
k = kb.each(chunk, ns.dc('author')).length;
|
|
536
|
+
if (k !== 1) {
|
|
537
|
+
complain2('Should be 1 not ' + k + ' author for ' + label);
|
|
538
|
+
}
|
|
539
|
+
const sts = kb.statementsMatching(undefined, ns.sioc('contents'));
|
|
540
|
+
sts.forEach(function (st) {
|
|
541
|
+
if (!found[st.subject.value]) {
|
|
542
|
+
complain2('Loose chunk! ' + st.subject.value);
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return !failed;
|
|
547
|
+
};
|
|
548
|
+
// Ensure that the display matches the current state of the
|
|
549
|
+
// @@ TODO really need to refactor this so that we don't need to cast types
|
|
550
|
+
const sync = function () {
|
|
551
|
+
// var first = kb.the(subject, PAD('next'))
|
|
552
|
+
if (kb.each(subject, PAD('next')).length !== 1) {
|
|
553
|
+
const msg = 'Pad: Inconsistent data - NEXT pointers: ' +
|
|
554
|
+
kb.each(subject, PAD('next')).length;
|
|
555
|
+
log(msg);
|
|
556
|
+
if (options.statusArea) {
|
|
557
|
+
options.statusArea.textContent += msg;
|
|
558
|
+
}
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
let row;
|
|
562
|
+
// First see which of the logical chunks have existing physical manifestations
|
|
563
|
+
const manif = [];
|
|
564
|
+
// Find which lines correspond to existing chunks
|
|
565
|
+
for (let chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
|
|
566
|
+
for (let i = 0; i < table.children.length; i++) {
|
|
567
|
+
const tr = table.children[i];
|
|
568
|
+
if (tr.firstChild) {
|
|
569
|
+
if (tr.firstChild.subject.sameTerm(chunk)) {
|
|
570
|
+
manif[chunk.uri] = tr.firstChild;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
// Remove any deleted lines
|
|
576
|
+
for (let i = table.children.length - 1; i >= 0; i--) {
|
|
577
|
+
row = table.children[i];
|
|
578
|
+
if (!manif[row.firstChild.subject.uri]) {
|
|
579
|
+
table.removeChild(row);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
// Insert any new lines and update old ones
|
|
583
|
+
row = table.firstChild; // might be null
|
|
584
|
+
for (let chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
|
|
585
|
+
const text = kb.any(chunk, ns.sioc('content')).value;
|
|
586
|
+
// superstitious -- don't mess with unchanged input fields
|
|
587
|
+
// which may be selected by the user
|
|
588
|
+
if (row && manif[chunk.uri]) {
|
|
589
|
+
const part = row.firstChild;
|
|
590
|
+
if (text !== part.value) {
|
|
591
|
+
part.value = text;
|
|
592
|
+
}
|
|
593
|
+
setPartStyle(part);
|
|
594
|
+
part.state = 0; // Clear the state machine
|
|
595
|
+
delete part.lastSent; // DEBUG ONLY
|
|
596
|
+
row = row.nextSibling;
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
newPartAfter(row, chunk, true); // actually before
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
// Refresh the DOM tree
|
|
604
|
+
const refreshTree = function (root) {
|
|
605
|
+
if (root.refresh) {
|
|
606
|
+
root.refresh();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
610
|
+
refreshTree(root.children[i]);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
let reloading = false;
|
|
614
|
+
const checkAndSync = function () {
|
|
615
|
+
log(' reloaded OK');
|
|
616
|
+
clearStatus();
|
|
617
|
+
if (!consistencyCheck()) {
|
|
618
|
+
complain('CONSISTENCY CHECK FAILED');
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
refreshTree(table);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
const reloadAndSync = function () {
|
|
625
|
+
if (reloading) {
|
|
626
|
+
log(' Already reloading - stop');
|
|
627
|
+
return; // once only needed
|
|
628
|
+
}
|
|
629
|
+
reloading = true;
|
|
630
|
+
let retryTimeout = 1000; // ms
|
|
631
|
+
const tryReload = function () {
|
|
632
|
+
log('try reload - timeout = ' + retryTimeout);
|
|
633
|
+
if (!updater) {
|
|
634
|
+
throw new Error('no updater');
|
|
635
|
+
}
|
|
636
|
+
updater.reload(updater.store, padDoc, function (ok, message, xhr) {
|
|
637
|
+
reloading = false;
|
|
638
|
+
if (ok) {
|
|
639
|
+
checkAndSync();
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
if (xhr.status === 0) {
|
|
643
|
+
complain('Network error refreshing the pad. Retrying in ' +
|
|
644
|
+
retryTimeout / 1000);
|
|
645
|
+
reloading = true;
|
|
646
|
+
retryTimeout = retryTimeout * 2;
|
|
647
|
+
setTimeout(tryReload, retryTimeout);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
complain('Error ' +
|
|
651
|
+
xhr.status +
|
|
652
|
+
'refreshing the pad:' +
|
|
653
|
+
message +
|
|
654
|
+
'. Stopped. ' +
|
|
655
|
+
padDoc);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
tryReload();
|
|
661
|
+
};
|
|
662
|
+
table.refresh = sync; // Catch downward propagating refresh events
|
|
663
|
+
table.reloadAndSync = reloadAndSync;
|
|
664
|
+
if (!me)
|
|
665
|
+
log('Warning: must be logged in for pad to be edited');
|
|
666
|
+
if (exists) {
|
|
667
|
+
log('Existing pad.');
|
|
668
|
+
if (consistencyCheck()) {
|
|
669
|
+
sync();
|
|
670
|
+
if (kb.holds(subject, PAD('next'), subject)) {
|
|
671
|
+
// Empty list untenable
|
|
672
|
+
newChunk(); // require at least one line
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
log((table.textContent = 'Inconsistent data. Abort'));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
// Make new pad
|
|
681
|
+
log('No pad exists - making new one.');
|
|
682
|
+
const insertables = [
|
|
683
|
+
st(subject, ns.rdf('type'), PAD('Notepad'), padDoc),
|
|
684
|
+
st(subject, ns.dc('author'), me, padDoc),
|
|
685
|
+
st(subject, ns.dc('created'), new Date(), padDoc),
|
|
686
|
+
st(subject, PAD('next'), subject, padDoc)
|
|
687
|
+
];
|
|
688
|
+
if (!updater) {
|
|
689
|
+
throw new Error('no updater');
|
|
690
|
+
}
|
|
691
|
+
updater.update([], insertables, function (uri, ok, errorBody) {
|
|
692
|
+
if (!ok) {
|
|
693
|
+
complain(errorBody || '');
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
log('Initial pad created');
|
|
697
|
+
newChunk(); // Add a first chunck
|
|
698
|
+
// getResults();
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
return table;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Get the chunks of the notepad
|
|
706
|
+
* They are stored in a RDF linked list
|
|
707
|
+
*/
|
|
708
|
+
// @ignore exporting this only for the unit test
|
|
709
|
+
export function getChunks(subject, kb) {
|
|
710
|
+
const chunks = [];
|
|
711
|
+
for (let chunk = kb.the(subject, PAD('next')); !chunk.sameTerm(subject); chunk = kb.the(chunk, PAD('next'))) {
|
|
712
|
+
chunks.push(chunk);
|
|
713
|
+
}
|
|
714
|
+
return chunks;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Encode content to be put in XML or HTML elements
|
|
718
|
+
*/
|
|
719
|
+
// @ignore exporting this only for the unit test
|
|
720
|
+
export function xmlEncode(str) {
|
|
721
|
+
return str.replace('&', '&').replace('<', '<').replace('>', '>');
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Convert a notepad to HTML
|
|
725
|
+
* @param { } pad - the notepad
|
|
726
|
+
* @param {store} pad - the data store
|
|
727
|
+
*/
|
|
728
|
+
export function notepadToHTML(pad, kb) {
|
|
729
|
+
const chunks = getChunks(pad, kb);
|
|
730
|
+
let html = '<html>\n <head>\n';
|
|
731
|
+
const title = kb.anyValue(pad, ns.dct('title'));
|
|
732
|
+
if (title) {
|
|
733
|
+
html += ` <title>${xmlEncode(title)}</title>\n`;
|
|
734
|
+
}
|
|
735
|
+
html += ' </head>\n <body>\n';
|
|
736
|
+
let level = 0;
|
|
737
|
+
function increaseLevel(indent) {
|
|
738
|
+
for (; level < indent; level++) {
|
|
739
|
+
html += '<ul>\n';
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function decreaseLevel(indent) {
|
|
743
|
+
for (; level > indent; level--) {
|
|
744
|
+
html += '</ul>\n';
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
chunks.forEach(chunk => {
|
|
748
|
+
const indent = kb.anyJS(chunk, PAD('indent'));
|
|
749
|
+
const rawContent = kb.anyJS(chunk, ns.sioc('content'));
|
|
750
|
+
if (!rawContent)
|
|
751
|
+
return; // seed chunk is dummy
|
|
752
|
+
const content = xmlEncode(rawContent);
|
|
753
|
+
if (indent < 0) { // negative indent levels represent heading levels
|
|
754
|
+
decreaseLevel(0);
|
|
755
|
+
const h = indent >= -3 ? 4 + indent : 1; // -1 -> h4, -2 -> h3
|
|
756
|
+
html += `\n<h${h}>${content}</h${h}>\n`;
|
|
757
|
+
}
|
|
758
|
+
else { // >= 0
|
|
759
|
+
if (indent > 0) { // Lists
|
|
760
|
+
decreaseLevel(indent);
|
|
761
|
+
increaseLevel(indent);
|
|
762
|
+
html += `<li>${content}</li>\n`;
|
|
763
|
+
}
|
|
764
|
+
else { // indent 0
|
|
765
|
+
decreaseLevel(indent);
|
|
766
|
+
html += `<p>${content}</p>\n`;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}); // foreach chunk
|
|
770
|
+
// At the end decreaseLevel any open ULs
|
|
771
|
+
decreaseLevel(0);
|
|
772
|
+
html += ' </body>\n</html>\n';
|
|
773
|
+
return html;
|
|
774
|
+
}
|
|
775
|
+
//# sourceMappingURL=pad.js.map
|