solid-ui 2.4.22-c53976d9 → 2.4.22-c7419dec

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
@@ -642,7 +655,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
642
655
 
643
656
  var _shim = dom.createElement('div');
644
657
 
645
- _shim.appendChild(subField); // Subfield has its own laytout
658
+ _shim.appendChild(subField); // Subfield has its own layout
646
659
 
647
660
 
648
661
  frame.appendChild(_shim);
@@ -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;
@@ -731,10 +746,9 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
731
746
  img.setAttribute('src', plusIconURI); // plus sign
732
747
 
733
748
  img.setAttribute('style', 'margin: 0.2em; width: 1.5em; height:1.5em');
734
- img.title = 'Click to add one or more ' + utils.predicateLabel(property, reverse);
735
- var prompt = tail.appendChild(dom.createElement('span'));
736
- prompt.textContent = (values.length === 0 ? 'Add one or more ' : 'Add more ') + utils.predicateLabel(property, reverse); // utils.label(property)
737
-
749
+ img.title = 'Click to add another ' + multipleUIlabel;
750
+ var prompt = dom.createElement('span');
751
+ prompt.textContent = (values.length === 0 ? 'Add another ' : 'Add ') + multipleUIlabel;
738
752
  tail.addEventListener('click', /*#__PURE__*/function () {
739
753
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_eventNotUsed) {
740
754
  return _regenerator["default"].wrap(function _callee5$(_context5) {
@@ -756,6 +770,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
756
770
  return _ref3.apply(this, arguments);
757
771
  };
758
772
  }(), true);
773
+ tail.appendChild(prompt);
759
774
  }
760
775
 
761
776
  function createListIfNecessary() {
@@ -1030,23 +1045,25 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
1030
1045
  ** -- radio buttons
1031
1046
  ** -- auto-complete typing
1032
1047
  **
1033
- ** 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
1034
1049
  */
1035
1050
 
1036
1051
 
1037
1052
  _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, subject, form, dataDoc, callbackFunction) {
1038
1053
  var ui = ns.ui;
1039
1054
  var kb = _solidLogic.store;
1040
- var multiple = false;
1041
1055
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
1042
1056
 
1043
1057
  var p;
1044
- var box = dom.createElement('div'); // Set flexDirection column?
1058
+ var box = dom.createElement('div');
1059
+ box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
1045
1060
 
1046
1061
  if (container) container.appendChild(box);
1047
1062
  var lhs = dom.createElement('div');
1063
+ lhs.setAttribute('class', 'formFieldName choiceBox-label');
1048
1064
  box.appendChild(lhs);
1049
1065
  var rhs = dom.createElement('div');
1066
+ rhs.setAttribute('class', 'formFieldValue choiceBox-selectBox');
1050
1067
  box.appendChild(rhs);
1051
1068
  var property = kb.any(form, ui('property'));
1052
1069
 
@@ -1055,105 +1072,126 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1055
1072
  }
1056
1073
 
1057
1074
  lhs.appendChild((0, _basic.fieldLabel)(dom, property, form));
1058
- var from = kb.any(form, ui('from'));
1075
+ var uiFrom = kb.any(form, ui('from'));
1059
1076
 
1060
- if (!from) {
1077
+ if (!uiFrom) {
1061
1078
  return (0, _error.errorMessageBlock)(dom, "No 'from' for Choice: " + form);
1062
1079
  }
1063
1080
 
1064
1081
  var subForm = kb.any(form, ui('use')); // Optional
1082
+ // const follow = kb.anyJS(form, ui('follow'), null, formDoc) // data doc moves to new subject?
1065
1083
 
1066
- var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
1067
-
1068
- var possible = [];
1069
- var possibleProperties;
1070
- var firstSelectOptionText = '* Select from ' + utils.label(subject, true) + ' *';
1071
1084
  var opts = {
1072
1085
  form: form,
1073
1086
  subForm: subForm,
1074
- multiple: multiple,
1075
- firstSelectOptionText: firstSelectOptionText,
1076
1087
  disambiguate: false
1077
1088
  };
1078
- possible = kb.each(undefined, ns.rdf('type'), from, formDoc);
1079
1089
 
1080
- for (var x in kb.findMembersNT(from)) {
1081
- possible.push(kb.fromNT(x));
1082
- } // Use rdfs
1090
+ function getSelectorOptions() {
1091
+ var possible = [];
1092
+ var possibleProperties;
1093
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1083
1094
 
1095
+ for (var x in kb.findMembersNT(uiFrom)) {
1096
+ possible.push(kb.fromNT(x));
1097
+ } // Use rdfs
1084
1098
 
1085
- if (from.sameTerm(ns.rdfs('Class'))) {
1086
- for (p in buttons.allClassURIs()) {
1087
- possible.push(kb.sym(p));
1088
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1089
1099
 
1090
- } else if (from.sameTerm(ns.rdf('Property'))) {
1091
- 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)
1092
1104
 
1093
- for (p in possibleProperties.op) {
1094
- possible.push(kb.fromNT(p));
1095
- }
1105
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1106
+ possibleProperties = buttons.propertyTriage(kb);
1096
1107
 
1097
- for (p in possibleProperties.dp) {
1098
- possible.push(kb.fromNT(p));
1099
- }
1108
+ for (p in possibleProperties.op) {
1109
+ possible.push(kb.fromNT(p));
1110
+ }
1100
1111
 
1101
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1102
- } else if (from.sameTerm(ns.owl('ObjectProperty'))) {
1103
- possibleProperties = buttons.propertyTriage(kb);
1112
+ for (p in possibleProperties.dp) {
1113
+ possible.push(kb.fromNT(p));
1114
+ }
1104
1115
 
1105
- for (p in possibleProperties.op) {
1106
- possible.push(kb.fromNT(p));
1107
- }
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);
1108
1119
 
1109
- opts.disambiguate = true;
1110
- } else if (from.sameTerm(ns.owl('DatatypeProperty'))) {
1111
- possibleProperties = buttons.propertyTriage(kb);
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);
1112
1127
 
1113
- for (p in possibleProperties.dp) {
1114
- possible.push(kb.fromNT(p));
1128
+ for (p in possibleProperties.dp) {
1129
+ possible.push(kb.fromNT(p));
1130
+ }
1131
+
1132
+ opts.disambiguate = true;
1115
1133
  }
1116
1134
 
1117
- opts.disambiguate = true;
1118
- }
1135
+ return possible; // return sortByLabel(possible)
1136
+ } // TODO: this checks for any occurrence, regardless of true or false setting
1119
1137
 
1120
- var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurance regardles if it is set to true or false
1121
1138
 
1122
1139
  if (kb.any(form, ui('canMintNew'))) {
1123
1140
  opts.mint = '* Create new *'; // @@ could be better
1124
1141
  }
1125
1142
 
1126
- var selector = makeSelectForOptions(dom, kb, subject, property, sortedPossible, opts, dataDoc, callbackFunction);
1127
- rhs.appendChild(selector);
1128
- 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
+ }
1129
1175
 
1130
- if (selector.currentURI) {
1131
- object = $rdf.sym(selector.currentURI);
1132
- } else {
1133
- object = kb.any(subject, property);
1134
- }
1176
+ if (event.action === 'CLEAR_ALL_OPTIONS') {
1177
+ selectedOptions = [];
1178
+ }
1135
1179
 
1136
- if (object && subForm) {
1137
- removeNextSiblingsAfterElement(selector);
1138
- addSubFormDropDown(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
1139
- }
1180
+ if (event.action === 'ADD_OPTION') {
1181
+ selectedOptions.push(event.value);
1182
+ }
1140
1183
 
1184
+ selector.update(selectedOptions);
1185
+ });
1186
+ }
1187
+ };
1188
+
1189
+ rhs.refresh();
1190
+ if (selector && selector.refresh) selector.refresh();
1141
1191
  return box;
1142
1192
  };
1143
- /**
1144
- * Removes all sibling elements after specified
1145
- * @param {HTMLElement} currentElement
1146
- * @private
1147
- */
1148
1193
 
1149
-
1150
- function removeNextSiblingsAfterElement(currentElement) {
1151
- while (currentElement.nextElementSibling) {
1152
- currentElement.nextElementSibling.remove();
1153
- }
1154
- }
1155
-
1156
- function addSubFormDropDown(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1194
+ function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1157
1195
  (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
1158
1196
  } // Documentation - non-interactive fields
1159
1197
  //
@@ -1358,7 +1396,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
1358
1396
  b.setAttribute('type', 'button');
1359
1397
  b.setAttribute('style', 'float: right;');
1360
1398
  b.innerHTML = 'Goto ' + utils.label(theClass);
1361
- b.addEventListener('click', function (_e) {
1399
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
1400
+ function (_e) {
1362
1401
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
1363
1402
  }, false);
1364
1403
  return box;
@@ -1493,10 +1532,8 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1493
1532
  // @param subject - a term, the subject of the statement(s) being edited.
1494
1533
  // @param predicate - a term, the predicate of the statement(s) being edited
1495
1534
  // @param possible - a list of terms, the possible value the object can take
1496
- // @param options.multiple - Boolean - Whether more than one at a time is allowed
1497
- // @param options.firstSelectOptionText - a string to be displayed as the
1535
+ // @param options.nullLabel - a string to be displayed as the
1498
1536
  // option for none selected (for non multiple)
1499
- // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1500
1537
  // @param options.subForm - If mint, then the form to be used for minting the new thing
1501
1538
  // @param dataDoc - The web document being edited
1502
1539
  // @param callbackFunction - takes (boolean ok, string errorBody)
@@ -1520,7 +1557,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1520
1557
  } // uris is now the set of possible options
1521
1558
 
1522
1559
 
1523
- if (n === 0 && !options.mint) {
1560
+ if (n === 0) {
1524
1561
  return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1525
1562
  }
1526
1563
 
@@ -1557,17 +1594,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1557
1594
  }
1558
1595
  };
1559
1596
 
1560
- var newObject;
1561
-
1562
1597
  for (var _i = 0; _i < select.options.length; _i++) {
1563
1598
  var opt = select.options[_i];
1564
-
1565
- if (opt.selected && opt.AJAR_mint) {
1566
- newObject = newThing(dataDoc);
1567
- removeNextSiblingsAfterElement(select);
1568
- addSubFormDropDown(dom, select.parentNode, {}, $rdf.sym(newObject), options.subForm, dataDoc, callbackFunction);
1569
- }
1570
-
1571
1599
  if (!opt.AJAR_uri) continue; // a prompt or mint
1572
1600
 
1573
1601
  if (opt.selected && !(opt.AJAR_uri in actual)) {
@@ -1575,6 +1603,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1575
1603
  is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
1576
1604
  }
1577
1605
 
1606
+ if (!opt.selected && opt.AJAR_uri in actual) {
1607
+ // old class
1608
+ removeValue(kb.sym(opt.AJAR_uri));
1609
+ }
1610
+
1578
1611
  if (opt.selected) select.currentURI = opt.AJAR_uri;
1579
1612
  }
1580
1613
 
@@ -1592,25 +1625,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1592
1625
  sel = sel.superSelect;
1593
1626
  }
1594
1627
 
1595
- function doneNew(ok, _body) {
1596
- callbackFunction(ok, {
1597
- widget: 'select',
1598
- event: 'new'
1599
- });
1600
- }
1601
-
1602
1628
  log.info('selectForOptions: data doc = ' + dataDoc);
1603
- removeNextSiblingsAfterElement(select);
1604
- addSubFormDropDown(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, callbackFunction);
1605
1629
  kb.updater.update(ds, is, function (uri, ok, body) {
1606
1630
  actual = getActual(); // refresh
1607
1631
 
1608
1632
  if (ok) {
1609
- if (newObject) {
1610
- removeNextSiblingsAfterElement(select);
1611
- addSubFormDropDown(dom, select.parentNode, {}, newObject, options.subForm, dataDoc, doneNew);
1612
- }
1613
-
1614
1633
  select.disabled = false; // data written back
1615
1634
  } else {
1616
1635
  return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
@@ -1625,7 +1644,6 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1625
1644
 
1626
1645
  var select = dom.createElement('select');
1627
1646
  select.setAttribute('style', style.formSelectSTyle);
1628
- if (options.multiple) select.setAttribute('multiple', 'true');
1629
1647
  select.currentURI = null;
1630
1648
 
1631
1649
  select.refresh = function () {
@@ -1668,22 +1686,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1668
1686
  select.appendChild(option);
1669
1687
  }
1670
1688
 
1671
- if (editable && options.mint) {
1672
- var mint = dom.createElement('option');
1673
- mint.appendChild(dom.createTextNode(options.mint));
1674
- mint.AJAR_mint = true; // Flag it
1675
-
1676
- select.insertBefore(mint, select.firstChild);
1677
- }
1678
-
1679
- if (!select.currentURI && !options.multiple) {
1689
+ if (!select.currentURI) {
1680
1690
  var prompt = dom.createElement('option');
1681
- prompt.appendChild(dom.createTextNode(options.firstSelectOptionText));
1682
- prompt.selected = true;
1683
- prompt.disabled = true;
1684
- prompt.value = true;
1685
- prompt.hidden = true;
1691
+ prompt.appendChild(dom.createTextNode(options.nullLabel));
1686
1692
  select.insertBefore(prompt, select.firstChild);
1693
+ prompt.selected = true;
1687
1694
  }
1688
1695
 
1689
1696
  if (editable) {
@@ -1702,27 +1709,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1702
1709
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
1703
1710
  var du = kb.any(category, ns.owl('disjointUnionOf'));
1704
1711
  var subs;
1705
- var multiple = false;
1706
1712
 
1707
1713
  if (!du) {
1708
1714
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
1709
- multiple = true;
1710
1715
  } else {
1711
1716
  subs = du.elements;
1712
1717
  }
1713
1718
 
1714
1719
  log.debug('Select list length ' + subs.length);
1715
-
1716
- if (subs.length === 0) {
1717
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1718
- }
1719
-
1720
- if (subs.length === 1) {
1721
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
1722
- }
1723
-
1724
1720
  return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
1725
- multiple: multiple
1721
+ nullLabel: '* Select type *'
1726
1722
  }, dataDoc, callbackFunction);
1727
1723
  }
1728
1724
  /** Make SELECT element to select subclasses recurively
@@ -1756,8 +1752,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
1756
1752
  function onChange(ok, body) {
1757
1753
  if (ok) update();
1758
1754
  callbackFunction(ok, body);
1759
- } // eslint-disable-next-line prefer-const
1760
-
1755
+ }
1761
1756
 
1762
1757
  var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
1763
1758
  container.appendChild(select);
@@ -1912,4 +1907,262 @@ function newThing(doc) {
1912
1907
  var now = new Date();
1913
1908
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
1914
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
+ }
1915
2168
  //# sourceMappingURL=forms.js.map