solid-ui 2.4.22-8fef4f19 → 2.4.22-90ab4764

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.
@@ -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
 
@@ -591,7 +604,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
591
604
  // delete button and move buttons
592
605
 
593
606
  if (kb.updater.editable(dataDoc.uri)) {
594
- buttons.deleteButtonWithCheck(dom, subField, utils.label(property), deleteThisItem);
607
+ buttons.deleteButtonWithCheck(dom, subField, multipleUIlabel, deleteThisItem);
595
608
 
596
609
  if (ordered) {
597
610
  // Add controsl in a frame
@@ -691,6 +704,8 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
691
704
  return shim;
692
705
  }
693
706
 
707
+ var multipleUIlabel = kb.any(form, ui('label'));
708
+ if (!multipleUIlabel) multipleUIlabel = utils.label(property);
694
709
  var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
695
710
 
696
711
  min = min ? 0 + min.value : 0;
@@ -727,16 +742,13 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
727
742
  if (kb.updater.editable(dataDoc.uri)) {
728
743
  var tail = box.appendChild(dom.createElement('div'));
729
744
  tail.style.padding = '0.5em';
730
- var label = kb.any(form, ui('label'));
731
- if (!label) label = utils.label(property, true); // Init capital
732
-
733
745
  var img = tail.appendChild(dom.createElement('img'));
734
746
  img.setAttribute('src', plusIconURI); // plus sign
735
747
 
736
748
  img.setAttribute('style', 'margin: 0.2em; width: 1.5em; height:1.5em');
737
- img.title = 'Click to add one or more ' + label;
749
+ img.title = 'Click to add another ' + multipleUIlabel;
738
750
  var prompt = dom.createElement('span');
739
- prompt.textContent = (values.length === 0 ? 'Add one or more ' : 'Add more ') + utils.predicateLabel(property, reverse);
751
+ prompt.textContent = (values.length === 0 ? 'Add another ' : 'Add ') + multipleUIlabel;
740
752
  tail.addEventListener('click', /*#__PURE__*/function () {
741
753
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_eventNotUsed) {
742
754
  return _regenerator["default"].wrap(function _callee5$(_context5) {
@@ -1033,7 +1045,7 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
1033
1045
  ** -- radio buttons
1034
1046
  ** -- auto-complete typing
1035
1047
  **
1036
- ** Todo: Deal with multiple. Maybe merge with multiple code.
1048
+ ** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
1037
1049
  */
1038
1050
 
1039
1051
 
@@ -1067,104 +1079,117 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1067
1079
  }
1068
1080
 
1069
1081
  var subForm = kb.any(form, ui('use')); // Optional
1070
-
1071
- var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
1072
-
1073
- var possible = [];
1074
- var possibleProperties;
1075
- var multiple = false;
1076
- var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
1077
- // only important for the first option text in select
1078
-
1079
- if (!container) {
1080
- multiple = true;
1081
- firstSelectOptionText = utils.label(subject, true);
1082
- }
1082
+ // const follow = kb.anyJS(form, ui('follow'), null, formDoc) // data doc moves to new subject?
1083
1083
 
1084
1084
  var opts = {
1085
1085
  form: form,
1086
1086
  subForm: subForm,
1087
- multiple: multiple,
1088
- firstSelectOptionText: firstSelectOptionText,
1089
1087
  disambiguate: false
1090
1088
  };
1091
- possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1092
1089
 
1093
- for (var x in kb.findMembersNT(uiFrom)) {
1094
- possible.push(kb.fromNT(x));
1095
- } // Use rdfs
1090
+ function getSelectorOptions() {
1091
+ var possible = [];
1092
+ var possibleProperties;
1093
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1096
1094
 
1095
+ for (var x in kb.findMembersNT(uiFrom)) {
1096
+ possible.push(kb.fromNT(x));
1097
+ } // Use rdfs
1097
1098
 
1098
- if (uiFrom.sameTerm(ns.rdfs('Class'))) {
1099
- for (p in buttons.allClassURIs()) {
1100
- possible.push(kb.sym(p));
1101
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1102
1099
 
1103
- } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1104
- 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)
1105
1104
 
1106
- for (p in possibleProperties.op) {
1107
- possible.push(kb.fromNT(p));
1108
- }
1105
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1106
+ possibleProperties = buttons.propertyTriage(kb);
1109
1107
 
1110
- for (p in possibleProperties.dp) {
1111
- possible.push(kb.fromNT(p));
1112
- }
1108
+ for (p in possibleProperties.op) {
1109
+ possible.push(kb.fromNT(p));
1110
+ }
1113
1111
 
1114
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1115
- } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
1116
- possibleProperties = buttons.propertyTriage(kb);
1112
+ for (p in possibleProperties.dp) {
1113
+ possible.push(kb.fromNT(p));
1114
+ }
1117
1115
 
1118
- for (p in possibleProperties.op) {
1119
- possible.push(kb.fromNT(p));
1120
- }
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
+
1120
+ for (p in possibleProperties.op) {
1121
+ possible.push(kb.fromNT(p));
1122
+ }
1121
1123
 
1122
- opts.disambiguate = true;
1123
- } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1124
- possibleProperties = buttons.propertyTriage(kb);
1124
+ opts.disambiguate = true;
1125
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1126
+ possibleProperties = buttons.propertyTriage(kb);
1125
1127
 
1126
- for (p in possibleProperties.dp) {
1127
- possible.push(kb.fromNT(p));
1128
+ for (p in possibleProperties.dp) {
1129
+ possible.push(kb.fromNT(p));
1130
+ }
1131
+
1132
+ opts.disambiguate = true;
1128
1133
  }
1129
1134
 
1130
- opts.disambiguate = true;
1131
- }
1135
+ return possible; // return sortByLabel(possible)
1136
+ } // TODO: this checks for any occurrence, regardless of true or false setting
1132
1137
 
1133
- var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
1134
1138
 
1135
1139
  if (kb.any(form, ui('canMintNew'))) {
1136
1140
  opts.mint = '* Create new *'; // @@ could be better
1137
1141
  }
1138
1142
 
1139
- var selector = makeSelectForOptions(dom, kb, subject, property, sortedPossible, uiFrom, opts, dataDoc, callbackFunction);
1140
- rhs.appendChild(selector);
1141
- var object;
1143
+ var multiSelect = kb.any(form, ui('multiselect')); // Optional
1144
+
1145
+ var selector;
1146
+
1147
+ rhs.refresh = function () {
1148
+ // from ui:property
1149
+ var selectedOptions = kb.each(subject, property, null, dataDoc).map(function (object) {
1150
+ return object.value;
1151
+ }); // from ui:from + ui:property
1152
+
1153
+ var possibleOptions = getSelectorOptions();
1154
+ possibleOptions.push(selectedOptions);
1155
+ possibleOptions = sortByLabel(possibleOptions);
1156
+ selector = makeSelectForChoice(dom, rhs, kb, subject, property, possibleOptions, selectedOptions, uiFrom, opts, dataDoc, callbackFunction);
1157
+ rhs.innerHTML = '';
1158
+ rhs.appendChild(selector);
1159
+
1160
+ if (multiSelect) {
1161
+ var multiSelectDiv = new _multiSelect.IconicMultiSelect({
1162
+ placeholder: selector.selected,
1163
+ select: selector,
1164
+ container: rhs,
1165
+ textField: 'textField',
1166
+ valueField: 'valueField'
1167
+ });
1168
+ multiSelectDiv.init();
1169
+ multiSelectDiv.subscribe(function (event) {
1170
+ if (event.action === 'REMOVE_OPTION') {
1171
+ selectedOptions = selectedOptions.filter(function (value) {
1172
+ return value !== event.value;
1173
+ });
1174
+ }
1142
1175
 
1143
- if (selector.currentURI) {
1144
- object = $rdf.sym(selector.currentURI);
1145
- } else {
1146
- object = kb.any(subject, property);
1147
- }
1176
+ if (event.action === 'CLEAR_ALL_OPTIONS') {
1177
+ selectedOptions = [];
1178
+ }
1148
1179
 
1149
- if (object && subForm) {
1150
- removeNextSiblingsAfterElement(selector);
1151
- addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
1152
- }
1180
+ if (event.action === 'ADD_OPTION') {
1181
+ selectedOptions.push(event.value);
1182
+ }
1153
1183
 
1184
+ selector.update(selectedOptions);
1185
+ });
1186
+ }
1187
+ };
1188
+
1189
+ rhs.refresh();
1190
+ if (selector && selector.refresh) selector.refresh();
1154
1191
  return box;
1155
1192
  };
1156
- /**
1157
- * Removes all sibling elements after specified
1158
- * @param {HTMLElement} currentElement
1159
- * @private
1160
- */
1161
-
1162
-
1163
- function removeNextSiblingsAfterElement(currentElement) {
1164
- while (currentElement.nextElementSibling) {
1165
- currentElement.nextElementSibling.remove();
1166
- }
1167
- }
1168
1193
 
1169
1194
  function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1170
1195
  (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
@@ -1371,7 +1396,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
1371
1396
  b.setAttribute('type', 'button');
1372
1397
  b.setAttribute('style', 'float: right;');
1373
1398
  b.innerHTML = 'Goto ' + utils.label(theClass);
1374
- b.addEventListener('click', function (_e) {
1399
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
1400
+ function (_e) {
1375
1401
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
1376
1402
  }, false);
1377
1403
  return box;
@@ -1506,17 +1532,15 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1506
1532
  // @param subject - a term, the subject of the statement(s) being edited.
1507
1533
  // @param predicate - a term, the predicate of the statement(s) being edited
1508
1534
  // @param possible - a list of terms, the possible value the object can take
1509
- // @param options.multiple - Boolean - Whether more than one at a time is allowed
1510
- // @param options.firstSelectOptionText - a string to be displayed as the
1535
+ // @param options.nullLabel - a string to be displayed as the
1511
1536
  // option for none selected (for non multiple)
1512
- // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1513
1537
  // @param options.subForm - If mint, then the form to be used for minting the new thing
1514
1538
  // @param dataDoc - The web document being edited
1515
1539
  // @param callbackFunction - takes (boolean ok, string errorBody)
1516
1540
  */
1517
1541
 
1518
1542
 
1519
- function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
1543
+ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
1520
1544
  log.debug('Select list length now ' + possible.length);
1521
1545
  var n = 0;
1522
1546
  var uris = {}; // Count them
@@ -1533,7 +1557,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1533
1557
  } // uris is now the set of possible options
1534
1558
 
1535
1559
 
1536
- if (n === 0 && !options.mint) {
1560
+ if (n === 0) {
1537
1561
  return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1538
1562
  }
1539
1563
 
@@ -1559,6 +1583,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1559
1583
  actual = getActual();
1560
1584
 
1561
1585
  var onChange = function onChange(_e) {
1586
+ select.disabled = true; // until data written back - gives user feedback too
1587
+
1562
1588
  var ds = [];
1563
1589
  var is = [];
1564
1590
 
@@ -1568,43 +1594,18 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1568
1594
  }
1569
1595
  };
1570
1596
 
1571
- var newObject;
1572
-
1573
1597
  for (var _i = 0; _i < select.options.length; _i++) {
1574
1598
  var opt = select.options[_i];
1575
-
1576
- if (opt.selected && opt.AJAR_mint) {
1577
- // not sure if this 'if' is used because I cannot find mintClass
1578
- if (options.mintClass) {
1579
- var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
1580
- if (!ok) {
1581
- callbackFunction(ok, body, {
1582
- change: 'new'
1583
- }); // @@ if ok, need some form of refresh of the select for the new thing
1584
- }
1585
- });
1586
- select.parentNode.appendChild(thisForm);
1587
- newObject = thisForm.AJAR_subject;
1588
- } else {
1589
- newObject = newThing(dataDoc);
1590
- }
1591
-
1592
- is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
1593
- 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
1594
-
1595
- if (options.mintStatementsFun) {
1596
- is = is.concat(options.mintStatementsFun(newObject));
1597
- }
1598
-
1599
- select.currentURI = newObject;
1600
- }
1601
-
1602
1599
  if (!opt.AJAR_uri) continue; // a prompt or mint
1603
1600
 
1604
1601
  if (opt.selected && !(opt.AJAR_uri in actual)) {
1605
1602
  // new class
1606
1603
  is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
1607
- select.currentURI = opt.AJAR_uri;
1604
+ }
1605
+
1606
+ if (!opt.selected && opt.AJAR_uri in actual) {
1607
+ // old class
1608
+ removeValue(kb.sym(opt.AJAR_uri));
1608
1609
  }
1609
1610
 
1610
1611
  if (opt.selected) select.currentURI = opt.AJAR_uri;
@@ -1624,29 +1625,25 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1624
1625
  sel = sel.superSelect;
1625
1626
  }
1626
1627
 
1627
- log.info('selectForOptions: data doc = ' + dataDoc); // refresh subForm
1628
+ log.info('selectForOptions: data doc = ' + dataDoc);
1629
+ kb.updater.update(ds, is, function (uri, ok, body) {
1630
+ actual = getActual(); // refresh
1628
1631
 
1629
- removeNextSiblingsAfterElement(select);
1630
- addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
1631
1632
  if (ok) {
1632
- kb.updater.update(ds, is, function (uri, success, errorBody) {
1633
- actual = getActual(); // refresh
1634
-
1635
- if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
1636
- });
1637
- if (callbackFunction) callbackFunction(ok, {
1638
- widget: 'select',
1639
- event: 'new'
1640
- });
1633
+ select.disabled = false; // data written back
1641
1634
  } else {
1642
- select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
1635
+ return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
1643
1636
  }
1637
+
1638
+ if (callbackFunction) callbackFunction(ok, {
1639
+ widget: 'select',
1640
+ event: 'change'
1641
+ });
1644
1642
  });
1645
1643
  };
1646
1644
 
1647
1645
  var select = dom.createElement('select');
1648
- select.setAttribute('style', style.formSelectSTyle); // if (options.multiple) select.setAttribute('multiple', 'true') // use case merged with ui:Multiple
1649
-
1646
+ select.setAttribute('style', style.formSelectSTyle);
1650
1647
  select.currentURI = null;
1651
1648
 
1652
1649
  select.refresh = function () {
@@ -1689,22 +1686,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1689
1686
  select.appendChild(option);
1690
1687
  }
1691
1688
 
1692
- if (editable && options.mint) {
1693
- var mint = dom.createElement('option');
1694
- mint.appendChild(dom.createTextNode(options.mint));
1695
- mint.AJAR_mint = true; // Flag it
1696
-
1697
- select.insertBefore(mint, select.firstChild);
1698
- }
1699
-
1700
- if (!select.currentURI && options.multiple) {
1689
+ if (!select.currentURI) {
1701
1690
  var prompt = dom.createElement('option');
1702
- prompt.appendChild(dom.createTextNode(options.firstSelectOptionText));
1703
- prompt.disabled = true;
1704
- prompt.value = true;
1705
- prompt.hidden = true;
1706
- prompt.selected = true;
1691
+ prompt.appendChild(dom.createTextNode(options.nullLabel));
1707
1692
  select.insertBefore(prompt, select.firstChild);
1693
+ prompt.selected = true;
1708
1694
  }
1709
1695
 
1710
1696
  if (editable) {
@@ -1723,27 +1709,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
1723
1709
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
1724
1710
  var du = kb.any(category, ns.owl('disjointUnionOf'));
1725
1711
  var subs;
1726
- var multiple = false;
1727
1712
 
1728
1713
  if (!du) {
1729
1714
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
1730
- multiple = true;
1731
1715
  } else {
1732
1716
  subs = du.elements;
1733
1717
  }
1734
1718
 
1735
1719
  log.debug('Select list length ' + subs.length);
1736
-
1737
- if (subs.length === 0) {
1738
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1739
- }
1740
-
1741
- if (subs.length === 1) {
1742
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
1743
- }
1744
-
1745
- return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
1746
- multiple: multiple
1720
+ return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
1721
+ nullLabel: '* Select type *'
1747
1722
  }, dataDoc, callbackFunction);
1748
1723
  }
1749
1724
  /** Make SELECT element to select subclasses recurively
@@ -1777,8 +1752,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
1777
1752
  function onChange(ok, body) {
1778
1753
  if (ok) update();
1779
1754
  callbackFunction(ok, body);
1780
- } // eslint-disable-next-line prefer-const
1781
-
1755
+ }
1782
1756
 
1783
1757
  var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
1784
1758
  container.appendChild(select);
@@ -1933,4 +1907,262 @@ function newThing(doc) {
1933
1907
  var now = new Date();
1934
1908
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
1935
1909
  }
1910
+ /** Make SELECT element to select options
1911
+ //
1912
+ // @param subject - a term, the subject of the statement(s) being edited.
1913
+ // @param predicate - a term, the predicate of the statement(s) being edited
1914
+ // @param possible - a list of terms, the possible value the object can take
1915
+ // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1916
+ // @param options.subForm - If mint, then the form to be used for minting the new thing
1917
+ // @param dataDoc - The web document being edited
1918
+ // @param callbackFunction - takes (boolean ok, string errorBody)
1919
+ */
1920
+
1921
+
1922
+ function makeSelectForChoice(dom, container, kb, subject, predicate, inputPossibleOptions, selectedOptions, uiFrom, options, dataDoc, callbackFunction) {
1923
+ var optionsFromClassUIfrom = {}; // Count them
1924
+
1925
+ var editable = kb.updater.editable(dataDoc.uri);
1926
+
1927
+ for (var i = 0; i < inputPossibleOptions.length; i++) {
1928
+ var sub = inputPossibleOptions[i]; // @@ Maybe; make this so it works with blank nodes too
1929
+ // if (!sub.uri) debug.warn(`makeSelectForChoice: option does not have an uri: ${sub}, with predicate: ${predicate}`)
1930
+
1931
+ if (!sub.uri || sub.uri in optionsFromClassUIfrom) continue;
1932
+ optionsFromClassUIfrom[sub.uri] = true;
1933
+ }
1934
+
1935
+ var isEmpty = Object.keys(optionsFromClassUIfrom).length === 0;
1936
+
1937
+ if (isEmpty && !options.mint) {
1938
+ return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1939
+ }
1940
+
1941
+ log.debug('makeSelectForChoice: dataDoc=' + dataDoc);
1942
+
1943
+ function createDefaultSelectOptionText() {
1944
+ var firstSelectOptionText = '--- choice ---';
1945
+
1946
+ if (predicate && !(predicate.termType === 'BlankNode')) {
1947
+ firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
1948
+ }
1949
+
1950
+ if (subject && !(subject.termType === 'BlankNode')) {
1951
+ firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
1952
+ }
1953
+
1954
+ return firstSelectOptionText;
1955
+ }
1956
+
1957
+ function createDefaultSelectOption() {
1958
+ var option = dom.createElement('option');
1959
+ option.appendChild(dom.createTextNode(createDefaultSelectOptionText()));
1960
+ option.disabled = true;
1961
+ option.value = true;
1962
+ option.hidden = true;
1963
+ option.selected = true;
1964
+ return option;
1965
+ }
1966
+
1967
+ var onChange = function onChange(_e) {
1968
+ container.removeChild(container.lastChild);
1969
+ select.refresh();
1970
+ };
1971
+
1972
+ var select = dom.createElement('select');
1973
+ select.setAttribute('style', style.formSelectSTyle);
1974
+ select.setAttribute('id', 'formSelect');
1975
+ select.currentURI = null;
1976
+
1977
+ for (var uri in optionsFromClassUIfrom) {
1978
+ select.appendChild(createOption(uri));
1979
+ }
1980
+
1981
+ if (editable && options.mint) {
1982
+ var mint = dom.createElement('option');
1983
+ mint.appendChild(dom.createTextNode(options.mint));
1984
+ mint.AJAR_mint = true; // Flag it
1985
+
1986
+ select.insertBefore(mint, select.firstChild);
1987
+ }
1988
+
1989
+ if (select.children.length === 0) select.insertBefore(createDefaultSelectOption(), select.firstChild);
1990
+
1991
+ select.update = function (newSelectedOptions) {
1992
+ selectedOptions = newSelectedOptions;
1993
+ var ds = [];
1994
+ var is = [];
1995
+
1996
+ var removeValue = function removeValue(t) {
1997
+ if (kb.holds(subject, predicate, t, dataDoc)) {
1998
+ ds.push($rdf.st(subject, predicate, t, dataDoc));
1999
+ }
2000
+ };
2001
+
2002
+ var addValue = function addValue(t) {
2003
+ if (!kb.holds(subject, predicate, t, dataDoc)) {
2004
+ is.push($rdf.st(subject, predicate, t, dataDoc)); // console.log("----value added " + t)
2005
+ }
2006
+
2007
+ if (uiFrom && !kb.holds(t, ns.rdf('type'), kb.sym(uiFrom), dataDoc)) {
2008
+ is.push($rdf.st(t, ns.rdf('type'), kb.sym(uiFrom), dataDoc)); // console.log("----added type to value " + uiFrom)
2009
+ }
2010
+ };
2011
+
2012
+ var existingValues = kb.each(subject, predicate, null, dataDoc).map(function (object) {
2013
+ return object.value;
2014
+ });
2015
+
2016
+ var _iterator2 = _createForOfIteratorHelper(existingValues),
2017
+ _step2;
2018
+
2019
+ try {
2020
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2021
+ var value = _step2.value;
2022
+ if (!containsObject(value, selectedOptions)) removeValue($rdf.sym(value));
2023
+ }
2024
+ } catch (err) {
2025
+ _iterator2.e(err);
2026
+ } finally {
2027
+ _iterator2.f();
2028
+ }
2029
+
2030
+ var _iterator3 = _createForOfIteratorHelper(selectedOptions),
2031
+ _step3;
2032
+
2033
+ try {
2034
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2035
+ var _value = _step3.value;
2036
+ if (!(_value in existingValues)) addValue($rdf.sym(_value));
2037
+ }
2038
+ } catch (err) {
2039
+ _iterator3.e(err);
2040
+ } finally {
2041
+ _iterator3.f();
2042
+ }
2043
+
2044
+ kb.updater.update(ds, is, function (uri, ok, body) {
2045
+ if (!ok) return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
2046
+ select.refresh();
2047
+ if (callbackFunction) callbackFunction(ok, {
2048
+ widget: 'select',
2049
+ event: 'change'
2050
+ });
2051
+ });
2052
+ };
2053
+
2054
+ select.refresh = function () {
2055
+ select.disabled = true; // unlocked any conflict we had got into
2056
+
2057
+ var is = [];
2058
+ var newObject;
2059
+
2060
+ for (var _i3 = 0; _i3 < select.options.length; _i3++) {
2061
+ var opt = select.options[_i3];
2062
+
2063
+ if (opt.selected && opt.AJAR_mint) {
2064
+ // not sure if this 'if' is used because I cannot find mintClass
2065
+ if (options.mintClass) {
2066
+ var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
2067
+ if (!ok) {
2068
+ callbackFunction(ok, body, {
2069
+ change: 'new'
2070
+ }); // @@ if ok, need some form of refresh of the select for the new thing
2071
+ }
2072
+ });
2073
+ select.parentNode.appendChild(thisForm);
2074
+ newObject = thisForm.AJAR_subject;
2075
+ } else {
2076
+ newObject = newThing(dataDoc);
2077
+ }
2078
+
2079
+ is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
2080
+ 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
2081
+
2082
+ if (options.mintStatementsFun) {
2083
+ is = is.concat(options.mintStatementsFun(newObject));
2084
+ }
2085
+
2086
+ select.currentURI = newObject;
2087
+ }
2088
+
2089
+ if (!opt.AJAR_uri) continue; // a prompt or mint
2090
+
2091
+ if (opt.selected && containsObject(opt.AJAR_uri, selectedOptions)) {
2092
+ select.currentURI = opt.AJAR_uri;
2093
+ }
2094
+
2095
+ if (!containsObject(opt.AJAR_uri, selectedOptions)) opt.removeAttribute('selected');
2096
+ if (containsObject(opt.AJAR_uri, selectedOptions)) opt.setAttribute('selected', 'true');
2097
+ }
2098
+
2099
+ log.info('selectForOptions: data doc = ' + dataDoc);
2100
+
2101
+ if (select.currentURI && options.subForm) {
2102
+ addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
2103
+ if (ok) {
2104
+ kb.updater.update([], is, function (uri, success, errorBody) {
2105
+ if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
2106
+ });
2107
+ if (callbackFunction) callbackFunction(ok, {
2108
+ widget: 'select',
2109
+ event: 'new'
2110
+ });
2111
+ } else {
2112
+ container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
2113
+ }
2114
+ });
2115
+ }
2116
+
2117
+ select.disabled = false;
2118
+ };
2119
+
2120
+ function createOption(uri) {
2121
+ var option = dom.createElement('option');
2122
+ var c = kb.sym(uri);
2123
+ var label;
2124
+
2125
+ if (options.disambiguate) {
2126
+ label = utils.labelWithOntology(c, true); // Init. cap
2127
+ } else {
2128
+ label = utils.label(c, true);
2129
+ }
2130
+
2131
+ option.appendChild(dom.createTextNode(label)); // Init.
2132
+
2133
+ option.setAttribute('value', uri);
2134
+ var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
2135
+
2136
+ if (backgroundColor) {
2137
+ option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
2138
+ }
2139
+
2140
+ option.AJAR_uri = uri;
2141
+
2142
+ if (containsObject(c.value, selectedOptions)) {
2143
+ option.setAttribute('selected', 'true');
2144
+ }
2145
+
2146
+ return option;
2147
+ }
2148
+
2149
+ if (editable) {
2150
+ select.addEventListener('change', onChange, false);
2151
+ }
2152
+
2153
+ return select;
2154
+ } // makeSelectForChoice
2155
+
2156
+
2157
+ function containsObject(obj, list) {
2158
+ var i;
2159
+
2160
+ for (i = 0; i < list.length; i++) {
2161
+ if (list[i] === obj) {
2162
+ return true;
2163
+ }
2164
+ }
2165
+
2166
+ return false;
2167
+ }
1936
2168
  //# sourceMappingURL=forms.js.map