solid-ui 2.4.22-72c4afee → 2.4.22-805cc91c

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.
Files changed (97) hide show
  1. package/README.md +23 -58
  2. package/dist/main.js +7230 -6603
  3. package/dist/main.js.map +1 -1
  4. package/lib/acl/access-controller.js.map +1 -1
  5. package/lib/acl/access-groups.js.map +1 -1
  6. package/lib/acl/acl-control.js.map +1 -1
  7. package/lib/acl/acl.js.map +1 -1
  8. package/lib/acl/add-agent-buttons.js +0 -1
  9. package/lib/acl/add-agent-buttons.js.map +1 -1
  10. package/lib/acl/index.js.map +1 -1
  11. package/lib/acl/styles.js.map +1 -1
  12. package/lib/acl/types.js.map +1 -1
  13. package/lib/chat/bookmarks.js +2 -4
  14. package/lib/chat/bookmarks.js.map +1 -1
  15. package/lib/chat/chatLogic.js.map +1 -1
  16. package/lib/chat/dateFolder.js.map +1 -1
  17. package/lib/chat/infinite.js.map +1 -1
  18. package/lib/chat/message.js.map +1 -1
  19. package/lib/chat/messageTools.js.map +1 -1
  20. package/lib/chat/thread.js.map +1 -1
  21. package/lib/create/create.js.map +1 -1
  22. package/lib/create/index.js.map +1 -1
  23. package/lib/create/types.js.map +1 -1
  24. package/lib/debug.js.map +1 -1
  25. package/lib/folders.js.map +1 -1
  26. package/lib/footer/index.js.map +1 -1
  27. package/lib/footer/styleMap.js.map +1 -1
  28. package/lib/header/empty-profile.js.map +1 -1
  29. package/lib/header/index.js.map +1 -1
  30. package/lib/header/styleMap.js.map +1 -1
  31. package/lib/iconBase.js +3 -2
  32. package/lib/iconBase.js.map +1 -1
  33. package/lib/icons/solid_logo.js.map +1 -1
  34. package/lib/index.js.map +1 -1
  35. package/lib/jss/index.js.map +1 -1
  36. package/lib/log.js.map +1 -1
  37. package/lib/login/login.d.ts +9 -8
  38. package/lib/login/login.d.ts.map +1 -1
  39. package/lib/login/login.js +290 -342
  40. package/lib/login/login.js.map +1 -1
  41. package/lib/matrix/index.js.map +1 -1
  42. package/lib/matrix/matrix.js.map +1 -1
  43. package/lib/matrix/types.js.map +1 -1
  44. package/lib/media/index.js.map +1 -1
  45. package/lib/media/media-capture.js.map +1 -1
  46. package/lib/messageArea.js.map +1 -1
  47. package/lib/noun_Camera_1618446_000000.js.map +1 -1
  48. package/lib/ns.js.map +1 -1
  49. package/lib/pad.js.map +1 -1
  50. package/lib/participation.js.map +1 -1
  51. package/lib/preferences.js.map +1 -1
  52. package/lib/signup/config-default.js.map +1 -1
  53. package/lib/signup/signup.js.map +1 -1
  54. package/lib/stories/decorators.js.map +1 -1
  55. package/lib/style.js.map +1 -1
  56. package/lib/style_multiSelect.js +67 -0
  57. package/lib/style_multiSelect.js.map +1 -0
  58. package/lib/table.js.map +1 -1
  59. package/lib/tabs.d.ts +1 -1
  60. package/lib/tabs.d.ts.map +1 -1
  61. package/lib/tabs.js +34 -21
  62. package/lib/tabs.js.map +1 -1
  63. package/lib/typings.d.js.map +1 -1
  64. package/lib/utils/headerFooterHelpers.js.map +1 -1
  65. package/lib/utils/index.js.map +1 -1
  66. package/lib/utils/label.js +1 -1
  67. package/lib/utils/label.js.map +1 -1
  68. package/lib/versionInfo.d.ts +9 -9
  69. package/lib/versionInfo.js +14 -14
  70. package/lib/versionInfo.js.map +1 -1
  71. package/lib/widgets/buttons/iconLinks.js.map +1 -1
  72. package/lib/widgets/buttons.d.ts.map +1 -1
  73. package/lib/widgets/buttons.js +2 -0
  74. package/lib/widgets/buttons.js.map +1 -1
  75. package/lib/widgets/dragAndDrop.js.map +1 -1
  76. package/lib/widgets/error.d.ts +0 -12
  77. package/lib/widgets/error.d.ts.map +1 -1
  78. package/lib/widgets/error.js +5 -0
  79. package/lib/widgets/error.js.map +1 -1
  80. package/lib/widgets/forms/autocomplete/autocompleteBar.js.map +1 -1
  81. package/lib/widgets/forms/autocomplete/autocompleteField.js.map +1 -1
  82. package/lib/widgets/forms/autocomplete/autocompletePicker.js.map +1 -1
  83. package/lib/widgets/forms/autocomplete/language.js.map +1 -1
  84. package/lib/widgets/forms/autocomplete/publicData.js.map +1 -1
  85. package/lib/widgets/forms/basic.js.map +1 -1
  86. package/lib/widgets/forms/comment.js.map +1 -1
  87. package/lib/widgets/forms/fieldFunction.js.map +1 -1
  88. package/lib/widgets/forms/fieldParams.js.map +1 -1
  89. package/lib/widgets/forms/formStyle.js.map +1 -1
  90. package/lib/widgets/forms.js +443 -189
  91. package/lib/widgets/forms.js.map +1 -1
  92. package/lib/widgets/index.js.map +1 -1
  93. package/lib/widgets/multiSelect.js +784 -0
  94. package/lib/widgets/multiSelect.js.map +1 -0
  95. package/lib/widgets/peoplePicker.js.map +1 -1
  96. package/lib/widgets/widgetHelpers.js.map +1 -1
  97. package/package.json +11 -7
@@ -22,6 +22,12 @@ Object.defineProperty(exports, "field", {
22
22
  return _fieldFunction.field;
23
23
  }
24
24
  });
25
+ Object.defineProperty(exports, "fieldFunction", {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _fieldFunction.fieldFunction;
29
+ }
30
+ });
25
31
  Object.defineProperty(exports, "fieldLabel", {
26
32
  enumerable: true,
27
33
  get: function get() {
@@ -44,8 +50,15 @@ exports.findClosest = findClosest;
44
50
  exports.formsFor = formsFor;
45
51
  exports.makeDescription = makeDescription;
46
52
  exports.makeSelectForCategory = makeSelectForCategory;
53
+ exports.makeSelectForChoice = makeSelectForChoice;
47
54
  exports.makeSelectForNestedCategory = makeSelectForNestedCategory;
48
55
  exports.makeSelectForOptions = makeSelectForOptions;
56
+ Object.defineProperty(exports, "mostSpecificClassURI", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _fieldFunction.mostSpecificClassURI;
60
+ }
61
+ });
49
62
  exports.newButton = newButton;
50
63
  exports.newThing = newThing;
51
64
  exports.promptForNew = promptForNew;
@@ -93,6 +106,8 @@ var _solidLogic = require("solid-logic");
93
106
 
94
107
  var utils = _interopRequireWildcard(require("../utils"));
95
108
 
109
+ var _multiSelect = require("./multiSelect");
110
+
96
111
  var widgets = _interopRequireWildcard(require("../widgets"));
97
112
 
98
113
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -155,14 +170,16 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
155
170
  var ui = ns.ui;
156
171
  if (container) container.appendChild(box); // Prevent loops
157
172
 
173
+ if (!form) return;
158
174
  var key = subject.toNT() + '|' + form.toNT();
159
175
 
160
176
  if (already[key]) {
161
177
  // been there done that
162
- box.appendChild(dom.createTextNode('Group: see above ' + key));
163
- var plist = [$rdf.st(subject, ns.owl('sameAs'), subject)]; // @@ need prev subject
178
+ box.appendChild(dom.createTextNode('Group: see above ' + key)); // TODO fix dependency cycle to solid-panes by calling outlineManager
179
+ // const plist = [$rdf.st(subject, ns.owl('sameAs'), subject)] // @@ need prev subject
180
+ // dom.outlineManager.appendPropertyTRs(box, plist)
181
+ // dom.appendChild(plist)
164
182
 
165
- dom.outlineManager.appendPropertyTRs(box, plist);
166
183
  return box;
167
184
  }
168
185
 
@@ -263,47 +280,43 @@ _fieldFunction.field[ns.ui('Options').uri] = function (dom, container, already,
263
280
  values = kb.each(subject, dependingOn);
264
281
  }
265
282
 
266
- if (values.length === 0) {
267
- box.appendChild((0, _error.errorMessageBlock)(dom, "Can't select subform as no value of: " + dependingOn));
268
- } else {
269
- for (var i = 0; i < cases.length; i++) {
270
- var c = cases[i];
271
- var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
283
+ for (var i = 0; i < cases.length; i++) {
284
+ var c = cases[i];
285
+ var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
272
286
 
273
- var match = false;
287
+ var match = false;
274
288
 
275
- for (var j = 0; j < tests.length; j++) {
276
- var _iterator = _createForOfIteratorHelper(values),
277
- _step;
289
+ for (var j = 0; j < tests.length; j++) {
290
+ var _iterator = _createForOfIteratorHelper(values),
291
+ _step;
278
292
 
279
- try {
280
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
281
- var value = _step.value;
282
- var test = tests[j];
293
+ try {
294
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
295
+ var value = _step.value;
296
+ var test = tests[j];
283
297
 
284
- if (value.sameTerm(tests) || value.termType === test.termType && value.value === test.value) {
285
- match = true;
286
- }
298
+ if (value.sameTerm(tests) || value.termType === test.termType && value.value === test.value) {
299
+ match = true;
287
300
  }
288
- } catch (err) {
289
- _iterator.e(err);
290
- } finally {
291
- _iterator.f();
292
301
  }
302
+ } catch (err) {
303
+ _iterator.e(err);
304
+ } finally {
305
+ _iterator.f();
293
306
  }
307
+ }
294
308
 
295
- if (match) {
296
- var _field3 = kb.the(c, ui('use'));
297
-
298
- if (!_field3) {
299
- box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
300
- return box;
301
- } else {
302
- appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
303
- }
309
+ if (match) {
310
+ var _field3 = kb.the(c, ui('use'));
304
311
 
305
- break;
312
+ if (!_field3) {
313
+ box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
314
+ return box;
315
+ } else {
316
+ appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
306
317
  }
318
+
319
+ break;
307
320
  }
308
321
  } // @@ Add box.refresh() to sync fields with values
309
322
 
@@ -692,8 +705,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
692
705
  }
693
706
 
694
707
  var multipleUIlabel = kb.any(form, ui('label'));
695
- if (!multipleUIlabel) multipleUIlabel = utils.label(property, true); // Init capital
696
-
708
+ if (!multipleUIlabel) multipleUIlabel = utils.label(property);
697
709
  var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
698
710
 
699
711
  min = min ? 0 + min.value : 0;
@@ -1033,6 +1045,7 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
1033
1045
  ** -- radio buttons
1034
1046
  ** -- auto-complete typing
1035
1047
  **
1048
+ ** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
1036
1049
  */
1037
1050
 
1038
1051
 
@@ -1041,9 +1054,6 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1041
1054
  var kb = _solidLogic.store;
1042
1055
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
1043
1056
 
1044
- var uiMultipleInUse = false; // this signals to ui:choice that it is part of a ui:multiple
1045
-
1046
- var multiSelect = false;
1047
1057
  var p;
1048
1058
  var box = dom.createElement('div');
1049
1059
  box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
@@ -1069,104 +1079,142 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1069
1079
  }
1070
1080
 
1071
1081
  var subForm = kb.any(form, ui('use')); // Optional
1072
-
1073
- var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
1074
-
1075
- var possible = [];
1076
- var possibleProperties;
1077
- var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
1078
- // only important for the first option text in select
1079
-
1080
- if (!container) {
1081
- uiMultipleInUse = true;
1082
- firstSelectOptionText = utils.label(subject, true);
1083
- }
1082
+ // const follow = kb.anyJS(form, ui('follow'), null, formDoc) // data doc moves to new subject?
1084
1083
 
1085
1084
  var opts = {
1086
1085
  form: form,
1087
1086
  subForm: subForm,
1088
- multiSelect: multiSelect,
1089
- firstSelectOptionText: firstSelectOptionText,
1090
- uiMultipleInUse: uiMultipleInUse,
1091
1087
  disambiguate: false
1092
1088
  };
1093
- possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1094
1089
 
1095
- for (var x in kb.findMembersNT(uiFrom)) {
1096
- possible.push(kb.fromNT(x));
1097
- } // Use rdfs
1090
+ function getSelectorOptions() {
1091
+ var possible = [];
1092
+ var possibleProperties;
1093
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1098
1094
 
1095
+ for (var x in kb.findMembersNT(uiFrom)) {
1096
+ possible.push(kb.fromNT(x));
1097
+ } // Use rdfs
1099
1098
 
1100
- if (uiFrom.sameTerm(ns.rdfs('Class'))) {
1101
- for (p in buttons.allClassURIs()) {
1102
- possible.push(kb.sym(p));
1103
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1104
1099
 
1105
- } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1106
- possibleProperties = buttons.propertyTriage(kb);
1100
+ if (uiFrom.sameTerm(ns.rdfs('Class'))) {
1101
+ for (p in buttons.allClassURIs()) {
1102
+ possible.push(kb.sym(p));
1103
+ } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1107
1104
 
1108
- for (p in possibleProperties.op) {
1109
- possible.push(kb.fromNT(p));
1110
- }
1105
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1106
+ possibleProperties = buttons.propertyTriage(kb);
1111
1107
 
1112
- for (p in possibleProperties.dp) {
1113
- possible.push(kb.fromNT(p));
1114
- }
1108
+ for (p in possibleProperties.op) {
1109
+ possible.push(kb.fromNT(p));
1110
+ }
1111
+
1112
+ for (p in possibleProperties.dp) {
1113
+ possible.push(kb.fromNT(p));
1114
+ }
1115
1115
 
1116
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1117
- } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
1118
- possibleProperties = buttons.propertyTriage(kb);
1116
+ opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1117
+ } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
1118
+ possibleProperties = buttons.propertyTriage(kb);
1119
1119
 
1120
- for (p in possibleProperties.op) {
1121
- possible.push(kb.fromNT(p));
1122
- }
1120
+ for (p in possibleProperties.op) {
1121
+ possible.push(kb.fromNT(p));
1122
+ }
1123
+
1124
+ opts.disambiguate = true;
1125
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1126
+ possibleProperties = buttons.propertyTriage(kb);
1123
1127
 
1124
- opts.disambiguate = true;
1125
- } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1126
- possibleProperties = buttons.propertyTriage(kb);
1128
+ for (p in possibleProperties.dp) {
1129
+ possible.push(kb.fromNT(p));
1130
+ }
1127
1131
 
1128
- for (p in possibleProperties.dp) {
1129
- possible.push(kb.fromNT(p));
1132
+ opts.disambiguate = true;
1130
1133
  }
1131
1134
 
1132
- opts.disambiguate = true;
1133
- }
1135
+ return possible; // return sortByLabel(possible)
1136
+ } // TODO: this checks for any occurrence, regardless of true or false setting
1134
1137
 
1135
- var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
1136
1138
 
1137
1139
  if (kb.any(form, ui('canMintNew'))) {
1138
1140
  opts.mint = '* Create new *'; // @@ could be better
1139
1141
  }
1140
1142
 
1141
- var selector = makeSelectForOptions(dom, kb, subject, property, sortedPossible, uiFrom, opts, dataDoc, callbackFunction);
1142
- rhs.appendChild(selector);
1143
- var object;
1143
+ var multiSelect = kb.any(form, ui('multiselect')); // Optional
1144
+
1145
+ if (multiSelect) opts.multiSelect = true;
1146
+ var selector;
1147
+
1148
+ rhs.refresh = function () {
1149
+ // from ui:property
1150
+ var selectedOptions = kb.each(subject, property, null, dataDoc).map(function (object) {
1151
+ return object.value;
1152
+ }); // from ui:from + ui:property
1153
+
1154
+ var possibleOptions = getSelectorOptions();
1155
+ possibleOptions.push(selectedOptions);
1156
+ possibleOptions = sortByLabel(possibleOptions);
1157
+ selector = makeSelectForChoice(dom, rhs, kb, subject, property, possibleOptions, selectedOptions, uiFrom, opts, dataDoc, callbackFunction);
1158
+ rhs.innerHTML = '';
1159
+ rhs.appendChild(selector);
1160
+
1161
+ if (multiSelect) {
1162
+ var multiSelectDiv = new _multiSelect.IconicMultiSelect({
1163
+ placeholder: selector.selected,
1164
+ select: selector,
1165
+ container: rhs,
1166
+ textField: 'textField',
1167
+ valueField: 'valueField'
1168
+ });
1169
+ multiSelectDiv.init();
1170
+ multiSelectDiv.subscribe(function (event) {
1171
+ if (event.action === 'REMOVE_OPTION') {
1172
+ selectedOptions = selectedOptions.filter(function (value) {
1173
+ return value !== event.value;
1174
+ });
1175
+ }
1144
1176
 
1145
- if (selector.currentURI) {
1146
- object = $rdf.sym(selector.currentURI);
1147
- } else {
1148
- object = kb.any(subject, property);
1149
- }
1177
+ if (event.action === 'CLEAR_ALL_OPTIONS') {
1178
+ selectedOptions = [];
1179
+ }
1150
1180
 
1151
- if (object && subForm) {
1152
- removeNextSiblingsAfterElement(selector);
1153
- addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
1154
- }
1181
+ if (event.action === 'ADD_OPTION') {
1182
+ var stringValue = event.value + '';
1155
1183
 
1156
- return box;
1157
- };
1158
- /**
1159
- * Removes all sibling elements after specified
1160
- * @param {HTMLElement} currentElement
1161
- * @private
1162
- */
1184
+ if (stringValue.includes('Create new')) {
1185
+ var newObject = newThing(dataDoc);
1186
+ var is = [];
1187
+ is.push($rdf.st(subject, property, kb.sym(newObject), dataDoc));
1188
+ if (uiFrom) is.push($rdf.st(newObject, ns.rdf('type'), kb.sym(uiFrom), dataDoc));
1163
1189
 
1190
+ if (subForm) {
1191
+ addSubFormChoice(dom, rhs, {}, $rdf.sym(newObject), subForm, dataDoc, function (ok, body) {
1192
+ if (ok) {
1193
+ kb.updater.update([], is, function (uri, success, errorBody) {
1194
+ if (!success) rhs.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
1195
+ });
1196
+ selectedOptions.push(newObject);
1197
+ if (callbackFunction) callbackFunction(ok, {
1198
+ widget: 'select',
1199
+ event: 'new'
1200
+ });
1201
+ } else {
1202
+ rhs.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
1203
+ }
1204
+ });
1205
+ }
1206
+ } else selectedOptions.push(event.value);
1207
+ }
1164
1208
 
1165
- function removeNextSiblingsAfterElement(currentElement) {
1166
- while (currentElement.nextElementSibling) {
1167
- currentElement.nextElementSibling.remove();
1168
- }
1169
- }
1209
+ selector.update(selectedOptions);
1210
+ });
1211
+ }
1212
+ };
1213
+
1214
+ rhs.refresh();
1215
+ if (selector && selector.refresh) selector.refresh();
1216
+ return box;
1217
+ };
1170
1218
 
1171
1219
  function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1172
1220
  (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
@@ -1373,7 +1421,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
1373
1421
  b.setAttribute('type', 'button');
1374
1422
  b.setAttribute('style', 'float: right;');
1375
1423
  b.innerHTML = 'Goto ' + utils.label(theClass);
1376
- b.addEventListener('click', function (_e) {
1424
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
1425
+ function (_e) {
1377
1426
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
1378
1427
  }, false);
1379
1428
  return box;
@@ -1508,18 +1557,15 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1508
1557
  // @param subject - a term, the subject of the statement(s) being edited.
1509
1558
  // @param predicate - a term, the predicate of the statement(s) being edited
1510
1559
  // @param possible - a list of terms, the possible value the object can take
1511
- // @param options.multiSelect - Boolean - Whether more than one at a time is allowed
1512
- // @param options.firstSelectOptionText - a string to be displayed as the
1513
- // option for none selected (for non multiSelect)
1514
- // @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
1515
- // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1560
+ // @param options.nullLabel - a string to be displayed as the
1561
+ // option for none selected (for non multiple)
1516
1562
  // @param options.subForm - If mint, then the form to be used for minting the new thing
1517
1563
  // @param dataDoc - The web document being edited
1518
1564
  // @param callbackFunction - takes (boolean ok, string errorBody)
1519
1565
  */
1520
1566
 
1521
1567
 
1522
- function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
1568
+ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
1523
1569
  log.debug('Select list length now ' + possible.length);
1524
1570
  var n = 0;
1525
1571
  var uris = {}; // Count them
@@ -1536,7 +1582,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1536
1582
  } // uris is now the set of possible options
1537
1583
 
1538
1584
 
1539
- if (n === 0 && !options.mint) {
1585
+ if (n === 0) {
1540
1586
  return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1541
1587
  }
1542
1588
 
@@ -1562,6 +1608,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1562
1608
  actual = getActual();
1563
1609
 
1564
1610
  var onChange = function onChange(_e) {
1611
+ select.disabled = true; // until data written back - gives user feedback too
1612
+
1565
1613
  var ds = [];
1566
1614
  var is = [];
1567
1615
 
@@ -1571,43 +1619,18 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1571
1619
  }
1572
1620
  };
1573
1621
 
1574
- var newObject;
1575
-
1576
1622
  for (var _i = 0; _i < select.options.length; _i++) {
1577
1623
  var opt = select.options[_i];
1578
-
1579
- if (opt.selected && opt.AJAR_mint) {
1580
- // not sure if this 'if' is used because I cannot find mintClass
1581
- if (options.mintClass) {
1582
- var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
1583
- if (!ok) {
1584
- callbackFunction(ok, body, {
1585
- change: 'new'
1586
- }); // @@ if ok, need some form of refresh of the select for the new thing
1587
- }
1588
- });
1589
- select.parentNode.appendChild(thisForm);
1590
- newObject = thisForm.AJAR_subject;
1591
- } else {
1592
- newObject = newThing(dataDoc);
1593
- }
1594
-
1595
- is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
1596
- if (uiFrom) is.push($rdf.st(newObject, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
1597
-
1598
- if (options.mintStatementsFun) {
1599
- is = is.concat(options.mintStatementsFun(newObject));
1600
- }
1601
-
1602
- select.currentURI = newObject;
1603
- }
1604
-
1605
1624
  if (!opt.AJAR_uri) continue; // a prompt or mint
1606
1625
 
1607
1626
  if (opt.selected && !(opt.AJAR_uri in actual)) {
1608
1627
  // new class
1609
1628
  is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
1610
- select.currentURI = opt.AJAR_uri;
1629
+ }
1630
+
1631
+ if (!opt.selected && opt.AJAR_uri in actual) {
1632
+ // old class
1633
+ removeValue(kb.sym(opt.AJAR_uri));
1611
1634
  }
1612
1635
 
1613
1636
  if (opt.selected) select.currentURI = opt.AJAR_uri;
@@ -1627,29 +1650,25 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1627
1650
  sel = sel.superSelect;
1628
1651
  }
1629
1652
 
1630
- log.info('selectForOptions: data doc = ' + dataDoc); // refresh subForm
1653
+ log.info('selectForOptions: data doc = ' + dataDoc);
1654
+ kb.updater.update(ds, is, function (uri, ok, body) {
1655
+ actual = getActual(); // refresh
1631
1656
 
1632
- removeNextSiblingsAfterElement(select);
1633
- addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
1634
1657
  if (ok) {
1635
- kb.updater.update(ds, is, function (uri, success, errorBody) {
1636
- actual = getActual(); // refresh
1637
-
1638
- if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
1639
- });
1640
- if (callbackFunction) callbackFunction(ok, {
1641
- widget: 'select',
1642
- event: 'new'
1643
- });
1658
+ select.disabled = false; // data written back
1644
1659
  } else {
1645
- select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
1660
+ return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
1646
1661
  }
1662
+
1663
+ if (callbackFunction) callbackFunction(ok, {
1664
+ widget: 'select',
1665
+ event: 'change'
1666
+ });
1647
1667
  });
1648
1668
  };
1649
1669
 
1650
1670
  var select = dom.createElement('select');
1651
1671
  select.setAttribute('style', style.formSelectSTyle);
1652
- if (options.multiSelect) select.setAttribute('multiSelect', 'true');
1653
1672
  select.currentURI = null;
1654
1673
 
1655
1674
  select.refresh = function () {
@@ -1692,22 +1711,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1692
1711
  select.appendChild(option);
1693
1712
  }
1694
1713
 
1695
- if (editable && options.mint) {
1696
- var mint = dom.createElement('option');
1697
- mint.appendChild(dom.createTextNode(options.mint));
1698
- mint.AJAR_mint = true; // Flag it
1699
-
1700
- select.insertBefore(mint, select.firstChild);
1701
- }
1702
-
1703
- if (!select.currentURI && options.uiMultipleInUse) {
1714
+ if (!select.currentURI) {
1704
1715
  var prompt = dom.createElement('option');
1705
- prompt.appendChild(dom.createTextNode(options.firstSelectOptionText));
1706
- prompt.disabled = true;
1707
- prompt.value = true;
1708
- prompt.hidden = true;
1709
- prompt.selected = true;
1716
+ prompt.appendChild(dom.createTextNode(options.nullLabel));
1710
1717
  select.insertBefore(prompt, select.firstChild);
1718
+ prompt.selected = true;
1711
1719
  }
1712
1720
 
1713
1721
  if (editable) {
@@ -1726,27 +1734,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1726
1734
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
1727
1735
  var du = kb.any(category, ns.owl('disjointUnionOf'));
1728
1736
  var subs;
1729
- var multiSelect = false;
1730
1737
 
1731
1738
  if (!du) {
1732
1739
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
1733
- multiSelect = true;
1734
1740
  } else {
1735
1741
  subs = du.elements;
1736
1742
  }
1737
1743
 
1738
1744
  log.debug('Select list length ' + subs.length);
1739
-
1740
- if (subs.length === 0) {
1741
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1742
- }
1743
-
1744
- if (subs.length === 1) {
1745
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
1746
- }
1747
-
1748
- return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
1749
- multiSelect: multiSelect
1745
+ return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
1746
+ nullLabel: '* Select type *'
1750
1747
  }, dataDoc, callbackFunction);
1751
1748
  }
1752
1749
  /** Make SELECT element to select subclasses recurively
@@ -1780,8 +1777,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
1780
1777
  function onChange(ok, body) {
1781
1778
  if (ok) update();
1782
1779
  callbackFunction(ok, body);
1783
- } // eslint-disable-next-line prefer-const
1784
-
1780
+ }
1785
1781
 
1786
1782
  var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
1787
1783
  container.appendChild(select);
@@ -1936,4 +1932,262 @@ function newThing(doc) {
1936
1932
  var now = new Date();
1937
1933
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
1938
1934
  }
1935
+ /** Make SELECT element to select options
1936
+ //
1937
+ // @param subject - a term, the subject of the statement(s) being edited.
1938
+ // @param predicate - a term, the predicate of the statement(s) being edited
1939
+ // @param possible - a list of terms, the possible value the object can take
1940
+ // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1941
+ // @param options.subForm - If mint, then the form to be used for minting the new thing
1942
+ // @param dataDoc - The web document being edited
1943
+ // @param callbackFunction - takes (boolean ok, string errorBody)
1944
+ */
1945
+
1946
+
1947
+ function makeSelectForChoice(dom, container, kb, subject, predicate, inputPossibleOptions, selectedOptions, uiFrom, options, dataDoc, callbackFunction) {
1948
+ var optionsFromClassUIfrom = {}; // Count them
1949
+
1950
+ var editable = kb.updater.editable(dataDoc.uri);
1951
+
1952
+ for (var i = 0; i < inputPossibleOptions.length; i++) {
1953
+ var sub = inputPossibleOptions[i]; // @@ Maybe; make this so it works with blank nodes too
1954
+ // if (!sub.uri) debug.warn(`makeSelectForChoice: option does not have an uri: ${sub}, with predicate: ${predicate}`)
1955
+
1956
+ if (!sub.uri || sub.uri in optionsFromClassUIfrom) continue;
1957
+ optionsFromClassUIfrom[sub.uri] = true;
1958
+ }
1959
+
1960
+ var isEmpty = Object.keys(optionsFromClassUIfrom).length === 0;
1961
+
1962
+ if (isEmpty && !options.mint) {
1963
+ return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1964
+ }
1965
+
1966
+ log.debug('makeSelectForChoice: dataDoc=' + dataDoc);
1967
+
1968
+ function createDefaultSelectOptionText() {
1969
+ var firstSelectOptionText = '--- choice ---';
1970
+
1971
+ if (predicate && !(predicate.termType === 'BlankNode')) {
1972
+ firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
1973
+ }
1974
+
1975
+ if (subject && !(subject.termType === 'BlankNode')) {
1976
+ firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
1977
+ }
1978
+
1979
+ return firstSelectOptionText;
1980
+ }
1981
+
1982
+ function createDefaultSelectOption() {
1983
+ var option = dom.createElement('option');
1984
+ option.appendChild(dom.createTextNode(createDefaultSelectOptionText()));
1985
+ option.disabled = true;
1986
+ option.value = true;
1987
+ option.hidden = true;
1988
+ option.selected = true;
1989
+ return option;
1990
+ }
1991
+
1992
+ var onChange = function onChange(_e) {
1993
+ container.removeChild(container.lastChild);
1994
+ select.refresh();
1995
+ };
1996
+
1997
+ var select = dom.createElement('select');
1998
+ select.setAttribute('style', style.formSelectSTyle);
1999
+ select.setAttribute('id', 'formSelect');
2000
+ select.currentURI = null;
2001
+
2002
+ for (var uri in optionsFromClassUIfrom) {
2003
+ select.appendChild(createOption(uri));
2004
+ }
2005
+
2006
+ if (editable && options.mint) {
2007
+ var mint = dom.createElement('option');
2008
+ mint.appendChild(dom.createTextNode(options.mint));
2009
+ mint.AJAR_mint = true; // Flag it
2010
+
2011
+ select.insertBefore(mint, select.firstChild);
2012
+ }
2013
+
2014
+ if (select.children.length === 0) select.insertBefore(createDefaultSelectOption(), select.firstChild);
2015
+
2016
+ select.update = function (newSelectedOptions) {
2017
+ selectedOptions = newSelectedOptions;
2018
+ var ds = [];
2019
+ var is = [];
2020
+
2021
+ var removeValue = function removeValue(t) {
2022
+ if (kb.holds(subject, predicate, t, dataDoc)) {
2023
+ ds.push($rdf.st(subject, predicate, t, dataDoc));
2024
+ }
2025
+ };
2026
+
2027
+ var addValue = function addValue(t) {
2028
+ if (!kb.holds(subject, predicate, t, dataDoc)) {
2029
+ is.push($rdf.st(subject, predicate, t, dataDoc)); // console.log("----value added " + t)
2030
+ }
2031
+
2032
+ if (uiFrom && !kb.holds(t, ns.rdf('type'), kb.sym(uiFrom), dataDoc)) {
2033
+ is.push($rdf.st(t, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // console.log("----added type to value " + uiFrom)
2034
+ }
2035
+ };
2036
+
2037
+ var existingValues = kb.each(subject, predicate, null, dataDoc).map(function (object) {
2038
+ return object.value;
2039
+ });
2040
+
2041
+ var _iterator2 = _createForOfIteratorHelper(existingValues),
2042
+ _step2;
2043
+
2044
+ try {
2045
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2046
+ var value = _step2.value;
2047
+ if (!containsObject(value, selectedOptions)) removeValue($rdf.sym(value));
2048
+ }
2049
+ } catch (err) {
2050
+ _iterator2.e(err);
2051
+ } finally {
2052
+ _iterator2.f();
2053
+ }
2054
+
2055
+ var _iterator3 = _createForOfIteratorHelper(selectedOptions),
2056
+ _step3;
2057
+
2058
+ try {
2059
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2060
+ var _value = _step3.value;
2061
+ if (!(_value in existingValues)) addValue($rdf.sym(_value));
2062
+ }
2063
+ } catch (err) {
2064
+ _iterator3.e(err);
2065
+ } finally {
2066
+ _iterator3.f();
2067
+ }
2068
+
2069
+ kb.updater.update(ds, is, function (uri, ok, body) {
2070
+ if (!ok) return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
2071
+ select.refresh();
2072
+ if (callbackFunction) callbackFunction(ok, {
2073
+ widget: 'select',
2074
+ event: 'change'
2075
+ });
2076
+ });
2077
+ };
2078
+
2079
+ select.refresh = function () {
2080
+ select.disabled = true; // unlocked any conflict we had got into
2081
+
2082
+ var is = [];
2083
+ var newObject;
2084
+
2085
+ for (var _i3 = 0; _i3 < select.options.length; _i3++) {
2086
+ var opt = select.options[_i3];
2087
+
2088
+ if (opt.selected && opt.AJAR_mint) {
2089
+ // not sure if this 'if' is used because I cannot find mintClass
2090
+ if (options.mintClass) {
2091
+ var thisForm = promptForNew(dom, kb, subject, predicate, uiFrom, options.subForm, dataDoc, function (ok, body) {
2092
+ if (!ok) {
2093
+ callbackFunction(ok, body, {
2094
+ change: 'new'
2095
+ }); // @@ if ok, need some form of refresh of the select for the new thing
2096
+ }
2097
+ });
2098
+ select.parentNode.appendChild(thisForm);
2099
+ newObject = thisForm.AJAR_subject;
2100
+ } else {
2101
+ newObject = newThing(dataDoc);
2102
+ }
2103
+
2104
+ is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
2105
+ if (uiFrom) is.push($rdf.st(newObject, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
2106
+
2107
+ if (options.mintStatementsFun) {
2108
+ is = is.concat(options.mintStatementsFun(newObject));
2109
+ }
2110
+
2111
+ select.currentURI = newObject;
2112
+ }
2113
+
2114
+ if (!opt.AJAR_uri) continue; // a prompt or mint
2115
+
2116
+ if (opt.selected && containsObject(opt.AJAR_uri, selectedOptions)) {
2117
+ select.currentURI = opt.AJAR_uri;
2118
+ }
2119
+
2120
+ if (!containsObject(opt.AJAR_uri, selectedOptions)) opt.removeAttribute('selected');
2121
+ if (containsObject(opt.AJAR_uri, selectedOptions)) opt.setAttribute('selected', 'true');
2122
+ }
2123
+
2124
+ log.info('selectForOptions: data doc = ' + dataDoc);
2125
+
2126
+ if (select.currentURI && options.subForm && !options.multiSelect) {
2127
+ addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
2128
+ if (ok) {
2129
+ kb.updater.update([], is, function (uri, success, errorBody) {
2130
+ if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
2131
+ });
2132
+ if (callbackFunction) callbackFunction(ok, {
2133
+ widget: 'select',
2134
+ event: 'new'
2135
+ });
2136
+ } else {
2137
+ container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
2138
+ }
2139
+ });
2140
+ }
2141
+
2142
+ select.disabled = false;
2143
+ };
2144
+
2145
+ function createOption(uri) {
2146
+ var option = dom.createElement('option');
2147
+ var c = kb.sym(uri);
2148
+ var label;
2149
+
2150
+ if (options.disambiguate) {
2151
+ label = utils.labelWithOntology(c, true); // Init. cap
2152
+ } else {
2153
+ label = utils.label(c, true);
2154
+ }
2155
+
2156
+ option.appendChild(dom.createTextNode(label)); // Init.
2157
+
2158
+ option.setAttribute('value', uri);
2159
+ var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
2160
+
2161
+ if (backgroundColor) {
2162
+ option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
2163
+ }
2164
+
2165
+ option.AJAR_uri = uri;
2166
+
2167
+ if (containsObject(c.value, selectedOptions)) {
2168
+ option.setAttribute('selected', 'true');
2169
+ }
2170
+
2171
+ return option;
2172
+ }
2173
+
2174
+ if (editable) {
2175
+ select.addEventListener('change', onChange, false);
2176
+ }
2177
+
2178
+ return select;
2179
+ } // makeSelectForChoice
2180
+
2181
+
2182
+ function containsObject(obj, list) {
2183
+ var i;
2184
+
2185
+ for (i = 0; i < list.length; i++) {
2186
+ if (list[i] === obj) {
2187
+ return true;
2188
+ }
2189
+ }
2190
+
2191
+ return false;
2192
+ }
1939
2193
  //# sourceMappingURL=forms.js.map