solid-ui 2.4.22-0030d5e1 → 2.4.22-027fc53e

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() {
@@ -1017,28 +1032,38 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
1017
1032
  **
1018
1033
  ** Not nested. Generates a link to something from a given class.
1019
1034
  ** Optional subform for the thing selected.
1035
+ ** Generates a subForm based on a ui:use form
1036
+ ** Will look like:
1037
+ ** <div id=dropDownDiv>
1038
+ ** <div id=labelOfDropDown>
1039
+ ** <div id=selectDiv>
1040
+ ** <select id=dropDownSelect>
1041
+ ** <option> ....
1042
+ ** <subForm>
1020
1043
  ** Alternative implementatons caould be:
1021
1044
  ** -- pop-up menu (as here)
1022
1045
  ** -- radio buttons
1023
1046
  ** -- auto-complete typing
1024
1047
  **
1025
- ** 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
1026
1049
  */
1027
1050
 
1028
1051
 
1029
1052
  _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, subject, form, dataDoc, callbackFunction) {
1030
1053
  var ui = ns.ui;
1031
1054
  var kb = _solidLogic.store;
1032
- var multiple = false;
1033
1055
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
1034
1056
 
1035
1057
  var p;
1036
- var box = dom.createElement('div'); // Set flexDirection column?
1058
+ var box = dom.createElement('div');
1059
+ box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
1037
1060
 
1038
1061
  if (container) container.appendChild(box);
1039
1062
  var lhs = dom.createElement('div');
1063
+ lhs.setAttribute('class', 'formFieldName choiceBox-label');
1040
1064
  box.appendChild(lhs);
1041
1065
  var rhs = dom.createElement('div');
1066
+ rhs.setAttribute('class', 'formFieldValue choiceBox-selectBox');
1042
1067
  box.appendChild(rhs);
1043
1068
  var property = kb.any(form, ui('property'));
1044
1069
 
@@ -1047,87 +1072,128 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1047
1072
  }
1048
1073
 
1049
1074
  lhs.appendChild((0, _basic.fieldLabel)(dom, property, form));
1050
- var from = kb.any(form, ui('from'));
1075
+ var uiFrom = kb.any(form, ui('from'));
1051
1076
 
1052
- if (!from) {
1077
+ if (!uiFrom) {
1053
1078
  return (0, _error.errorMessageBlock)(dom, "No 'from' for Choice: " + form);
1054
1079
  }
1055
1080
 
1056
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?
1057
1083
 
1058
- var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
1059
-
1060
- var possible = [];
1061
- var possibleProperties;
1062
- var nullLabel = '--' + utils.label(property) + '-?';
1063
1084
  var opts = {
1064
1085
  form: form,
1065
- multiple: multiple,
1066
- nullLabel: nullLabel,
1086
+ subForm: subForm,
1067
1087
  disambiguate: false
1068
1088
  };
1069
- possible = kb.each(undefined, ns.rdf('type'), from, formDoc);
1070
1089
 
1071
- for (var x in kb.findMembersNT(from)) {
1072
- possible.push(kb.fromNT(x));
1073
- } // Use rdfs
1090
+ function getSelectorOptions() {
1091
+ var possible = [];
1092
+ var possibleProperties;
1093
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1074
1094
 
1095
+ for (var x in kb.findMembersNT(uiFrom)) {
1096
+ possible.push(kb.fromNT(x));
1097
+ } // Use rdfs
1075
1098
 
1076
- if (from.sameTerm(ns.rdfs('Class'))) {
1077
- for (p in buttons.allClassURIs()) {
1078
- possible.push(kb.sym(p));
1079
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1080
1099
 
1081
- } else if (from.sameTerm(ns.rdf('Property'))) {
1082
- 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)
1083
1104
 
1084
- for (p in possibleProperties.op) {
1085
- possible.push(kb.fromNT(p));
1086
- }
1105
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1106
+ possibleProperties = buttons.propertyTriage(kb);
1087
1107
 
1088
- for (p in possibleProperties.dp) {
1089
- possible.push(kb.fromNT(p));
1090
- }
1108
+ for (p in possibleProperties.op) {
1109
+ possible.push(kb.fromNT(p));
1110
+ }
1091
1111
 
1092
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1093
- } else if (from.sameTerm(ns.owl('ObjectProperty'))) {
1094
- possibleProperties = buttons.propertyTriage(kb);
1112
+ for (p in possibleProperties.dp) {
1113
+ possible.push(kb.fromNT(p));
1114
+ }
1095
1115
 
1096
- for (p in possibleProperties.op) {
1097
- possible.push(kb.fromNT(p));
1098
- }
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
+ }
1099
1123
 
1100
- opts.disambiguate = true;
1101
- } else if (from.sameTerm(ns.owl('DatatypeProperty'))) {
1102
- possibleProperties = buttons.propertyTriage(kb);
1124
+ opts.disambiguate = true;
1125
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1126
+ possibleProperties = buttons.propertyTriage(kb);
1103
1127
 
1104
- for (p in possibleProperties.dp) {
1105
- possible.push(kb.fromNT(p));
1128
+ for (p in possibleProperties.dp) {
1129
+ possible.push(kb.fromNT(p));
1130
+ }
1131
+
1132
+ opts.disambiguate = true;
1106
1133
  }
1107
1134
 
1108
- opts.disambiguate = true;
1109
- }
1135
+ return possible; // return sortByLabel(possible)
1136
+ } // TODO: this checks for any occurrence, regardless of true or false setting
1110
1137
 
1111
- var object = kb.any(subject, property);
1112
1138
 
1113
- function addSubForm() {
1114
- object = kb.any(subject, property);
1115
- (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
1139
+ if (kb.any(form, ui('canMintNew'))) {
1140
+ opts.mint = '* Create new *'; // @@ could be better
1116
1141
  }
1117
1142
 
1118
- var possible2 = sortByLabel(possible);
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
+ }
1119
1175
 
1120
- if (kb.any(form, ui('canMintNew'))) {
1121
- opts.mint = '* New *'; // @@ could be better
1176
+ if (event.action === 'CLEAR_ALL_OPTIONS') {
1177
+ selectedOptions = [];
1178
+ }
1122
1179
 
1123
- opts.subForm = subForm;
1124
- }
1180
+ if (event.action === 'ADD_OPTION') {
1181
+ selectedOptions.push(event.value);
1182
+ }
1183
+
1184
+ selector.update(selectedOptions);
1185
+ });
1186
+ }
1187
+ };
1125
1188
 
1126
- var selector = makeSelectForOptions(dom, kb, subject, property, possible2, opts, dataDoc, callbackFunction);
1127
- rhs.appendChild(selector);
1128
- if (object && subForm) addSubForm();
1189
+ rhs.refresh();
1190
+ if (selector && selector.refresh) selector.refresh();
1129
1191
  return box;
1130
- }; // Documentation - non-interactive fields
1192
+ };
1193
+
1194
+ function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1195
+ (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
1196
+ } // Documentation - non-interactive fields
1131
1197
  //
1132
1198
 
1133
1199
 
@@ -1330,7 +1396,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
1330
1396
  b.setAttribute('type', 'button');
1331
1397
  b.setAttribute('style', 'float: right;');
1332
1398
  b.innerHTML = 'Goto ' + utils.label(theClass);
1333
- b.addEventListener('click', function (_e) {
1399
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
1400
+ function (_e) {
1334
1401
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
1335
1402
  }, false);
1336
1403
  return box;
@@ -1465,10 +1532,8 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1465
1532
  // @param subject - a term, the subject of the statement(s) being edited.
1466
1533
  // @param predicate - a term, the predicate of the statement(s) being edited
1467
1534
  // @param possible - a list of terms, the possible value the object can take
1468
- // @param options.multiple - Boolean - Whether more than one at a time is allowed
1469
1535
  // @param options.nullLabel - a string to be displayed as the
1470
1536
  // option for none selected (for non multiple)
1471
- // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1472
1537
  // @param options.subForm - If mint, then the form to be used for minting the new thing
1473
1538
  // @param dataDoc - The web document being edited
1474
1539
  // @param callbackFunction - takes (boolean ok, string errorBody)
@@ -1492,7 +1557,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1492
1557
  } // uris is now the set of possible options
1493
1558
 
1494
1559
 
1495
- if (n === 0 && !options.mint) {
1560
+ if (n === 0) {
1496
1561
  return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
1497
1562
  }
1498
1563
 
@@ -1506,7 +1571,9 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1506
1571
  actual = kb.findTypeURIs(subject);
1507
1572
  } else {
1508
1573
  kb.each(subject, predicate, null, dataDoc).forEach(function (x) {
1509
- actual[x.uri] = true;
1574
+ if (x.uri) {
1575
+ actual[x.uri] = true;
1576
+ }
1510
1577
  });
1511
1578
  }
1512
1579
 
@@ -1527,33 +1594,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1527
1594
  }
1528
1595
  };
1529
1596
 
1530
- var newObject;
1531
-
1532
1597
  for (var _i = 0; _i < select.options.length; _i++) {
1533
1598
  var opt = select.options[_i];
1534
-
1535
- if (opt.selected && opt.AJAR_mint) {
1536
- if (options.mintClass) {
1537
- var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
1538
- if (!ok) {
1539
- callbackFunction(ok, body, {
1540
- change: 'new'
1541
- }); // @@ if ok, need some form of refresh of the select for the new thing
1542
- }
1543
- });
1544
- select.parentNode.appendChild(thisForm);
1545
- newObject = thisForm.AJAR_subject;
1546
- } else {
1547
- newObject = newThing(dataDoc);
1548
- }
1549
-
1550
- is.push($rdf.st(subject, predicate, newObject, dataDoc));
1551
-
1552
- if (options.mintStatementsFun) {
1553
- is = is.concat(options.mintStatementsFun(newObject));
1554
- }
1555
- }
1556
-
1557
1599
  if (!opt.AJAR_uri) continue; // a prompt or mint
1558
1600
 
1559
1601
  if (opt.selected && !(opt.AJAR_uri in actual)) {
@@ -1583,24 +1625,12 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1583
1625
  sel = sel.superSelect;
1584
1626
  }
1585
1627
 
1586
- function doneNew(ok, _body) {
1587
- callbackFunction(ok, {
1588
- widget: 'select',
1589
- event: 'new'
1590
- });
1591
- }
1592
-
1593
1628
  log.info('selectForOptions: data doc = ' + dataDoc);
1594
1629
  kb.updater.update(ds, is, function (uri, ok, body) {
1595
1630
  actual = getActual(); // refresh
1596
1631
 
1597
1632
  if (ok) {
1598
1633
  select.disabled = false; // data written back
1599
-
1600
- if (newObject) {
1601
- var fn = (0, _fieldFunction.fieldFunction)(dom, options.subForm);
1602
- fn(dom, select.parentNode, {}, newObject, options.subForm, dataDoc, doneNew);
1603
- }
1604
1634
  } else {
1605
1635
  return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
1606
1636
  }
@@ -1614,7 +1644,6 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1614
1644
 
1615
1645
  var select = dom.createElement('select');
1616
1646
  select.setAttribute('style', style.formSelectSTyle);
1617
- if (options.multiple) select.setAttribute('multiple', 'true');
1618
1647
  select.currentURI = null;
1619
1648
 
1620
1649
  select.refresh = function () {
@@ -1657,15 +1686,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1657
1686
  select.appendChild(option);
1658
1687
  }
1659
1688
 
1660
- if (editable && options.mint) {
1661
- var mint = dom.createElement('option');
1662
- mint.appendChild(dom.createTextNode(options.mint));
1663
- mint.AJAR_mint = true; // Flag it
1664
-
1665
- select.insertBefore(mint, select.firstChild);
1666
- }
1667
-
1668
- if (select.currentURI == null && !options.multiple) {
1689
+ if (!select.currentURI) {
1669
1690
  var prompt = dom.createElement('option');
1670
1691
  prompt.appendChild(dom.createTextNode(options.nullLabel));
1671
1692
  select.insertBefore(prompt, select.firstChild);
@@ -1688,28 +1709,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1688
1709
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
1689
1710
  var du = kb.any(category, ns.owl('disjointUnionOf'));
1690
1711
  var subs;
1691
- var multiple = false;
1692
1712
 
1693
1713
  if (!du) {
1694
1714
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
1695
- multiple = true;
1696
1715
  } else {
1697
1716
  subs = du.elements;
1698
1717
  }
1699
1718
 
1700
1719
  log.debug('Select list length ' + subs.length);
1701
-
1702
- if (subs.length === 0) {
1703
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1704
- }
1705
-
1706
- if (subs.length === 1) {
1707
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
1708
- }
1709
-
1710
1720
  return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
1711
- multiple: multiple,
1712
- nullPrompt: '--classify--'
1721
+ nullLabel: '* Select type *'
1713
1722
  }, dataDoc, callbackFunction);
1714
1723
  }
1715
1724
  /** Make SELECT element to select subclasses recurively
@@ -1743,8 +1752,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
1743
1752
  function onChange(ok, body) {
1744
1753
  if (ok) update();
1745
1754
  callbackFunction(ok, body);
1746
- } // eslint-disable-next-line prefer-const
1747
-
1755
+ }
1748
1756
 
1749
1757
  var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
1750
1758
  container.appendChild(select);
@@ -1899,4 +1907,262 @@ function newThing(doc) {
1899
1907
  var now = new Date();
1900
1908
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
1901
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
+ }
1902
2168
  //# sourceMappingURL=forms.js.map