solid-ui 2.4.22-0a43b5fb → 2.4.22-0b2c6704

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -15172,7 +15172,7 @@ function slice(s, suffix) {
15172
15172
 
15173
15173
  function getWellKnownLabel(thing) {
15174
15174
  return _solidLogic.store.any(thing, UI.ns.ui('label')) || // Prioritize ui:label
15175
- _solidLogic.store.any(thing, UI.ns.link('message')) || _solidLogic.store.any(thing, UI.ns.vcard('fn')) || _solidLogic.store.any(thing, UI.ns.foaf('name')) || _solidLogic.store.any(thing, UI.ns.dct('title')) || _solidLogic.store.any(thing, UI.ns.dc('title')) || _solidLogic.store.any(thing, UI.ns.rss('title')) || _solidLogic.store.any(thing, UI.ns.contact('fullName')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2001/04/roadmap/org#name')) || _solidLogic.store.any(thing, UI.ns.cal('summary')) || _solidLogic.store.any(thing, UI.ns.foaf('nick')) || _solidLogic.store.any(thing, UI.ns.as('name')) || _solidLogic.store.any(thing, UI.ns.schema('name')) || _solidLogic.store.any(thing, UI.ns.rdfs('label'));
15175
+ _solidLogic.store.any(thing, UI.ns.link('message')) || _solidLogic.store.any(thing, UI.ns.vcard('fn')) || _solidLogic.store.any(thing, UI.ns.foaf('name')) || _solidLogic.store.any(thing, UI.ns.dct('title')) || _solidLogic.store.any(thing, UI.ns.dc('title')) || _solidLogic.store.any(thing, UI.ns.rss('title')) || _solidLogic.store.any(thing, UI.ns.contact('fullName')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2001/04/roadmap/org#name')) || _solidLogic.store.any(thing, UI.ns.cal('summary')) || _solidLogic.store.any(thing, UI.ns.foaf('nick')) || _solidLogic.store.any(thing, UI.ns.as('name')) || _solidLogic.store.any(thing, UI.ns.schema('name')) || _solidLogic.store.any(thing, UI.ns.rdfs('label')) || _solidLogic.store.any(thing, _solidLogic.store.sym('http://www.w3.org/2004/02/skos/core#prefLabel'));
15176
15176
  }
15177
15177
  //# sourceMappingURL=label.js.map
15178
15178
 
@@ -15192,11 +15192,11 @@ Object.defineProperty(exports, "__esModule", ({
15192
15192
  }));
15193
15193
  exports.versionInfo = void 0;
15194
15194
  var versionInfo = {
15195
- buildTime: '2022-05-09T08:09:58Z',
15196
- commit: '0a43b5fb3622a6d3bab53b0f33fc5b2e57144b9d',
15195
+ buildTime: '2022-05-20T07:49:44Z',
15196
+ commit: '0b2c67046f504374a65ff9f4995cbb1f5fa17556',
15197
15197
  npmInfo: {
15198
15198
  'solid-ui': '2.4.22',
15199
- npm: '6.14.16',
15199
+ npm: '6.14.17',
15200
15200
  ares: '1.18.1',
15201
15201
  brotli: '1.0.9',
15202
15202
  cldr: '40.0',
@@ -15205,12 +15205,12 @@ var versionInfo = {
15205
15205
  modules: '83',
15206
15206
  napi: '8',
15207
15207
  nghttp2: '1.42.0',
15208
- node: '14.19.1',
15208
+ node: '14.19.2',
15209
15209
  openssl: '1.1.1n',
15210
15210
  tz: '2021a3',
15211
15211
  unicode: '14.0',
15212
15212
  uv: '1.42.0',
15213
- v8: '8.4.371.23-node.85',
15213
+ v8: '8.4.371.23-node.87',
15214
15214
  zlib: '1.2.11'
15215
15215
  }
15216
15216
  };
@@ -16280,6 +16280,7 @@ function openHrefInOutlineMode(e) {
16280
16280
 
16281
16281
  if (dom.outlineManager) {
16282
16282
  // @@ TODO Remove the use of document as a global object
16283
+ // TODO fix dependency cycle to solid-panes by calling outlineManager
16283
16284
  ;
16284
16285
  dom.outlineManager.GotoSubject(_solidLogic.store.sym(uri), true, undefined, true, undefined);
16285
16286
  } else if (window && window.panes && window.panes.getOutliner) {
@@ -16407,6 +16408,7 @@ function linkButton(dom, object) {
16407
16408
  b.textContent = 'Goto ' + utils.label(object);
16408
16409
  b.addEventListener('click', function (_event) {
16409
16410
  // b.parentNode.removeChild(b)
16411
+ // TODO fix dependency cycle to solid-panes by calling outlineManager
16410
16412
  ;
16411
16413
  dom.outlineManager.GotoSubject(object, true, undefined, true, undefined);
16412
16414
  }, true);
@@ -17147,6 +17149,7 @@ exports.findClosest = findClosest;
17147
17149
  exports.formsFor = formsFor;
17148
17150
  exports.makeDescription = makeDescription;
17149
17151
  exports.makeSelectForCategory = makeSelectForCategory;
17152
+ exports.makeSelectForChoice = makeSelectForChoice;
17150
17153
  exports.makeSelectForNestedCategory = makeSelectForNestedCategory;
17151
17154
  exports.makeSelectForOptions = makeSelectForOptions;
17152
17155
  exports.newButton = newButton;
@@ -17258,14 +17261,16 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
17258
17261
  var ui = ns.ui;
17259
17262
  if (container) container.appendChild(box); // Prevent loops
17260
17263
 
17264
+ if (!form) return;
17261
17265
  var key = subject.toNT() + '|' + form.toNT();
17262
17266
 
17263
17267
  if (already[key]) {
17264
17268
  // been there done that
17265
- box.appendChild(dom.createTextNode('Group: see above ' + key));
17266
- var plist = [$rdf.st(subject, ns.owl('sameAs'), subject)]; // @@ need prev subject
17269
+ box.appendChild(dom.createTextNode('Group: see above ' + key)); // TODO fix dependency cycle to solid-panes by calling outlineManager
17270
+ // const plist = [$rdf.st(subject, ns.owl('sameAs'), subject)] // @@ need prev subject
17271
+ // dom.outlineManager.appendPropertyTRs(box, plist)
17272
+ // dom.appendChild(plist)
17267
17273
 
17268
- dom.outlineManager.appendPropertyTRs(box, plist);
17269
17274
  return box;
17270
17275
  }
17271
17276
 
@@ -17366,47 +17371,43 @@ _fieldFunction.field[ns.ui('Options').uri] = function (dom, container, already,
17366
17371
  values = kb.each(subject, dependingOn);
17367
17372
  }
17368
17373
 
17369
- if (values.length === 0) {
17370
- box.appendChild((0, _error.errorMessageBlock)(dom, "Can't select subform as no value of: " + dependingOn));
17371
- } else {
17372
- for (var i = 0; i < cases.length; i++) {
17373
- var c = cases[i];
17374
- var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
17374
+ for (var i = 0; i < cases.length; i++) {
17375
+ var c = cases[i];
17376
+ var tests = kb.each(c, ui('for'), null, formDoc); // There can be multiple 'for'
17375
17377
 
17376
- var match = false;
17378
+ var match = false;
17377
17379
 
17378
- for (var j = 0; j < tests.length; j++) {
17379
- var _iterator = _createForOfIteratorHelper(values),
17380
- _step;
17380
+ for (var j = 0; j < tests.length; j++) {
17381
+ var _iterator = _createForOfIteratorHelper(values),
17382
+ _step;
17381
17383
 
17382
- try {
17383
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
17384
- var value = _step.value;
17385
- var test = tests[j];
17384
+ try {
17385
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
17386
+ var value = _step.value;
17387
+ var test = tests[j];
17386
17388
 
17387
- if (value.sameTerm(tests) || value.termType === test.termType && value.value === test.value) {
17388
- match = true;
17389
- }
17389
+ if (value.sameTerm(tests) || value.termType === test.termType && value.value === test.value) {
17390
+ match = true;
17390
17391
  }
17391
- } catch (err) {
17392
- _iterator.e(err);
17393
- } finally {
17394
- _iterator.f();
17395
17392
  }
17393
+ } catch (err) {
17394
+ _iterator.e(err);
17395
+ } finally {
17396
+ _iterator.f();
17396
17397
  }
17398
+ }
17397
17399
 
17398
- if (match) {
17399
- var _field3 = kb.the(c, ui('use'));
17400
-
17401
- if (!_field3) {
17402
- box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
17403
- return box;
17404
- } else {
17405
- appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
17406
- }
17400
+ if (match) {
17401
+ var _field3 = kb.the(c, ui('use'));
17407
17402
 
17408
- break;
17403
+ if (!_field3) {
17404
+ box.appendChild((0, _error.errorMessageBlock)(dom, 'No "use" part for case in form ' + form));
17405
+ return box;
17406
+ } else {
17407
+ appendForm(dom, box, already, subject, _field3, dataDoc, callbackFunction);
17409
17408
  }
17409
+
17410
+ break;
17410
17411
  }
17411
17412
  } // @@ Add box.refresh() to sync fields with values
17412
17413
 
@@ -17694,7 +17695,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
17694
17695
  // delete button and move buttons
17695
17696
 
17696
17697
  if (kb.updater.editable(dataDoc.uri)) {
17697
- buttons.deleteButtonWithCheck(dom, subField, utils.label(property), deleteThisItem);
17698
+ buttons.deleteButtonWithCheck(dom, subField, multipleUIlabel, deleteThisItem);
17698
17699
 
17699
17700
  if (ordered) {
17700
17701
  // Add controsl in a frame
@@ -17745,7 +17746,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
17745
17746
 
17746
17747
  var _shim = dom.createElement('div');
17747
17748
 
17748
- _shim.appendChild(subField); // Subfield has its own laytout
17749
+ _shim.appendChild(subField); // Subfield has its own layout
17749
17750
 
17750
17751
 
17751
17752
  frame.appendChild(_shim);
@@ -17794,6 +17795,8 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
17794
17795
  return shim;
17795
17796
  }
17796
17797
 
17798
+ var multipleUIlabel = kb.any(form, ui('label'));
17799
+ if (!multipleUIlabel) multipleUIlabel = utils.label(property);
17797
17800
  var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
17798
17801
 
17799
17802
  min = min ? 0 + min.value : 0;
@@ -17834,10 +17837,9 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
17834
17837
  img.setAttribute('src', plusIconURI); // plus sign
17835
17838
 
17836
17839
  img.setAttribute('style', 'margin: 0.2em; width: 1.5em; height:1.5em');
17837
- img.title = 'Click to add one or more ' + utils.predicateLabel(property, reverse);
17838
- var prompt = tail.appendChild(dom.createElement('span'));
17839
- prompt.textContent = (values.length === 0 ? 'Add one or more ' : 'Add more ') + utils.predicateLabel(property, reverse); // utils.label(property)
17840
-
17840
+ img.title = 'Click to add another ' + multipleUIlabel;
17841
+ var prompt = dom.createElement('span');
17842
+ prompt.textContent = (values.length === 0 ? 'Add another ' : 'Add ') + multipleUIlabel;
17841
17843
  tail.addEventListener('click', /*#__PURE__*/function () {
17842
17844
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_eventNotUsed) {
17843
17845
  return _regenerator["default"].wrap(function _callee5$(_context5) {
@@ -17859,6 +17861,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
17859
17861
  return _ref3.apply(this, arguments);
17860
17862
  };
17861
17863
  }(), true);
17864
+ tail.appendChild(prompt);
17862
17865
  }
17863
17866
 
17864
17867
  function createListIfNecessary() {
@@ -18120,28 +18123,39 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
18120
18123
  **
18121
18124
  ** Not nested. Generates a link to something from a given class.
18122
18125
  ** Optional subform for the thing selected.
18126
+ ** Generates a subForm based on a ui:use form
18127
+ ** Will look like:
18128
+ ** <div id=dropDownDiv>
18129
+ ** <div id=labelOfDropDown>
18130
+ ** <div id=selectDiv>
18131
+ ** <select id=dropDownSelect>
18132
+ ** <option> ....
18133
+ ** <subForm>
18123
18134
  ** Alternative implementatons caould be:
18124
18135
  ** -- pop-up menu (as here)
18125
18136
  ** -- radio buttons
18126
18137
  ** -- auto-complete typing
18127
18138
  **
18128
- ** Todo: Deal with multiple. Maybe merge with multiple code.
18139
+ ** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
18129
18140
  */
18130
18141
 
18131
18142
 
18132
18143
  _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, subject, form, dataDoc, callbackFunction) {
18133
18144
  var ui = ns.ui;
18134
18145
  var kb = _solidLogic.store;
18135
- var multiple = false;
18136
18146
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
18137
18147
 
18148
+ var multiSelect = false;
18138
18149
  var p;
18139
- var box = dom.createElement('div'); // Set flexDirection column?
18150
+ var box = dom.createElement('div');
18151
+ box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
18140
18152
 
18141
18153
  if (container) container.appendChild(box);
18142
18154
  var lhs = dom.createElement('div');
18155
+ lhs.setAttribute('class', 'formFieldName choiceBox-label');
18143
18156
  box.appendChild(lhs);
18144
18157
  var rhs = dom.createElement('div');
18158
+ rhs.setAttribute('class', 'formFieldValue choiceBox-selectBox');
18145
18159
  box.appendChild(rhs);
18146
18160
  var property = kb.any(form, ui('property'));
18147
18161
 
@@ -18150,9 +18164,9 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
18150
18164
  }
18151
18165
 
18152
18166
  lhs.appendChild((0, _basic.fieldLabel)(dom, property, form));
18153
- var from = kb.any(form, ui('from'));
18167
+ var uiFrom = kb.any(form, ui('from'));
18154
18168
 
18155
- if (!from) {
18169
+ if (!uiFrom) {
18156
18170
  return (0, _error.errorMessageBlock)(dom, "No 'from' for Choice: " + form);
18157
18171
  }
18158
18172
 
@@ -18160,77 +18174,95 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
18160
18174
 
18161
18175
  var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
18162
18176
 
18163
- var possible = [];
18164
- var possibleProperties;
18165
- var nullLabel = '--' + utils.label(property) + '-?';
18166
18177
  var opts = {
18167
18178
  form: form,
18168
- multiple: multiple,
18169
- nullLabel: nullLabel,
18179
+ subForm: subForm,
18180
+ multiSelect: multiSelect,
18170
18181
  disambiguate: false
18171
18182
  };
18172
- possible = kb.each(undefined, ns.rdf('type'), from, formDoc);
18173
18183
 
18174
- for (var x in kb.findMembersNT(from)) {
18175
- possible.push(kb.fromNT(x));
18176
- } // Use rdfs
18184
+ function getSelectorOptions() {
18185
+ var possible = [];
18186
+ var possibleProperties;
18187
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
18177
18188
 
18189
+ for (var x in kb.findMembersNT(uiFrom)) {
18190
+ possible.push(kb.fromNT(x));
18191
+ } // Use rdfs
18178
18192
 
18179
- if (from.sameTerm(ns.rdfs('Class'))) {
18180
- for (p in buttons.allClassURIs()) {
18181
- possible.push(kb.sym(p));
18182
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
18183
18193
 
18184
- } else if (from.sameTerm(ns.rdf('Property'))) {
18185
- possibleProperties = buttons.propertyTriage(kb);
18194
+ if (uiFrom.sameTerm(ns.rdfs('Class'))) {
18195
+ for (p in buttons.allClassURIs()) {
18196
+ possible.push(kb.sym(p));
18197
+ } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
18186
18198
 
18187
- for (p in possibleProperties.op) {
18188
- possible.push(kb.fromNT(p));
18189
- }
18199
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
18200
+ possibleProperties = buttons.propertyTriage(kb);
18190
18201
 
18191
- for (p in possibleProperties.dp) {
18192
- possible.push(kb.fromNT(p));
18193
- }
18202
+ for (p in possibleProperties.op) {
18203
+ possible.push(kb.fromNT(p));
18204
+ }
18194
18205
 
18195
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
18196
- } else if (from.sameTerm(ns.owl('ObjectProperty'))) {
18197
- possibleProperties = buttons.propertyTriage(kb);
18206
+ for (p in possibleProperties.dp) {
18207
+ possible.push(kb.fromNT(p));
18208
+ }
18198
18209
 
18199
- for (p in possibleProperties.op) {
18200
- possible.push(kb.fromNT(p));
18201
- }
18210
+ opts.disambiguate = true; // This is a big class, and the labels won't be enough.
18211
+ } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
18212
+ possibleProperties = buttons.propertyTriage(kb);
18213
+
18214
+ for (p in possibleProperties.op) {
18215
+ possible.push(kb.fromNT(p));
18216
+ }
18202
18217
 
18203
- opts.disambiguate = true;
18204
- } else if (from.sameTerm(ns.owl('DatatypeProperty'))) {
18205
- possibleProperties = buttons.propertyTriage(kb);
18218
+ opts.disambiguate = true;
18219
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
18220
+ possibleProperties = buttons.propertyTriage(kb);
18206
18221
 
18207
- for (p in possibleProperties.dp) {
18208
- possible.push(kb.fromNT(p));
18222
+ for (p in possibleProperties.dp) {
18223
+ possible.push(kb.fromNT(p));
18224
+ }
18225
+
18226
+ opts.disambiguate = true;
18209
18227
  }
18210
18228
 
18211
- opts.disambiguate = true;
18212
- }
18229
+ return sortByLabel(possible);
18230
+ } // TODO: this checks for any occurrence, regardless of true or false setting
18213
18231
 
18214
- var object = kb.any(subject, property);
18215
18232
 
18216
- function addSubForm() {
18217
- object = kb.any(subject, property);
18218
- (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
18233
+ if (kb.any(form, ui('canMintNew'))) {
18234
+ opts.mint = '* Create new *'; // @@ could be better
18219
18235
  }
18220
18236
 
18221
- var possible2 = sortByLabel(possible);
18237
+ var selector;
18222
18238
 
18223
- if (kb.any(form, ui('canMintNew'))) {
18224
- opts.mint = '* New *'; // @@ could be better
18239
+ rhs.refresh = function () {
18240
+ var selectorOptions = getSelectorOptions();
18241
+ selector = makeSelectForChoice(dom, rhs, kb, subject, property, selectorOptions, uiFrom, opts, dataDoc, callbackFunction);
18242
+ rhs.innerHTML = '';
18243
+ rhs.appendChild(selector);
18244
+ };
18225
18245
 
18226
- opts.subForm = subForm;
18246
+ rhs.refresh();
18247
+ if (selector && selector.refresh) selector.refresh();
18248
+ return box;
18249
+ };
18250
+ /**
18251
+ * Removes all sibling elements after specified
18252
+ * @param {HTMLElement} currentElement
18253
+ * @private
18254
+ */
18255
+
18256
+
18257
+ function removeNextSiblingsAfterElement(currentElement) {
18258
+ while (currentElement.nextElementSibling) {
18259
+ currentElement.nextElementSibling.remove();
18227
18260
  }
18261
+ }
18228
18262
 
18229
- var selector = makeSelectForOptions(dom, kb, subject, property, possible2, opts, dataDoc, callbackFunction);
18230
- rhs.appendChild(selector);
18231
- if (object && subForm) addSubForm();
18232
- return box;
18233
- }; // Documentation - non-interactive fields
18263
+ function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
18264
+ (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
18265
+ } // Documentation - non-interactive fields
18234
18266
  //
18235
18267
 
18236
18268
 
@@ -18433,7 +18465,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
18433
18465
  b.setAttribute('type', 'button');
18434
18466
  b.setAttribute('style', 'float: right;');
18435
18467
  b.innerHTML = 'Goto ' + utils.label(theClass);
18436
- b.addEventListener('click', function (_e) {
18468
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
18469
+ function (_e) {
18437
18470
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
18438
18471
  }, false);
18439
18472
  return box;
@@ -18568,10 +18601,8 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
18568
18601
  // @param subject - a term, the subject of the statement(s) being edited.
18569
18602
  // @param predicate - a term, the predicate of the statement(s) being edited
18570
18603
  // @param possible - a list of terms, the possible value the object can take
18571
- // @param options.multiple - Boolean - Whether more than one at a time is allowed
18572
18604
  // @param options.nullLabel - a string to be displayed as the
18573
18605
  // option for none selected (for non multiple)
18574
- // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
18575
18606
  // @param options.subForm - If mint, then the form to be used for minting the new thing
18576
18607
  // @param dataDoc - The web document being edited
18577
18608
  // @param callbackFunction - takes (boolean ok, string errorBody)
@@ -18595,7 +18626,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18595
18626
  } // uris is now the set of possible options
18596
18627
 
18597
18628
 
18598
- if (n === 0 && !options.mint) {
18629
+ if (n === 0) {
18599
18630
  return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
18600
18631
  }
18601
18632
 
@@ -18609,7 +18640,9 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18609
18640
  actual = kb.findTypeURIs(subject);
18610
18641
  } else {
18611
18642
  kb.each(subject, predicate, null, dataDoc).forEach(function (x) {
18612
- actual[x.uri] = true;
18643
+ if (x.uri) {
18644
+ actual[x.uri] = true;
18645
+ }
18613
18646
  });
18614
18647
  }
18615
18648
 
@@ -18630,33 +18663,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18630
18663
  }
18631
18664
  };
18632
18665
 
18633
- var newObject;
18634
-
18635
18666
  for (var _i = 0; _i < select.options.length; _i++) {
18636
18667
  var opt = select.options[_i];
18637
-
18638
- if (opt.selected && opt.AJAR_mint) {
18639
- if (options.mintClass) {
18640
- var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
18641
- if (!ok) {
18642
- callbackFunction(ok, body, {
18643
- change: 'new'
18644
- }); // @@ if ok, need some form of refresh of the select for the new thing
18645
- }
18646
- });
18647
- select.parentNode.appendChild(thisForm);
18648
- newObject = thisForm.AJAR_subject;
18649
- } else {
18650
- newObject = newThing(dataDoc);
18651
- }
18652
-
18653
- is.push($rdf.st(subject, predicate, newObject, dataDoc));
18654
-
18655
- if (options.mintStatementsFun) {
18656
- is = is.concat(options.mintStatementsFun(newObject));
18657
- }
18658
- }
18659
-
18660
18668
  if (!opt.AJAR_uri) continue; // a prompt or mint
18661
18669
 
18662
18670
  if (opt.selected && !(opt.AJAR_uri in actual)) {
@@ -18686,24 +18694,12 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18686
18694
  sel = sel.superSelect;
18687
18695
  }
18688
18696
 
18689
- function doneNew(ok, _body) {
18690
- callbackFunction(ok, {
18691
- widget: 'select',
18692
- event: 'new'
18693
- });
18694
- }
18695
-
18696
18697
  log.info('selectForOptions: data doc = ' + dataDoc);
18697
18698
  kb.updater.update(ds, is, function (uri, ok, body) {
18698
18699
  actual = getActual(); // refresh
18699
18700
 
18700
18701
  if (ok) {
18701
18702
  select.disabled = false; // data written back
18702
-
18703
- if (newObject) {
18704
- var fn = (0, _fieldFunction.fieldFunction)(dom, options.subForm);
18705
- fn(dom, select.parentNode, {}, newObject, options.subForm, dataDoc, doneNew);
18706
- }
18707
18703
  } else {
18708
18704
  return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
18709
18705
  }
@@ -18717,7 +18713,6 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18717
18713
 
18718
18714
  var select = dom.createElement('select');
18719
18715
  select.setAttribute('style', style.formSelectSTyle);
18720
- if (options.multiple) select.setAttribute('multiple', 'true');
18721
18716
  select.currentURI = null;
18722
18717
 
18723
18718
  select.refresh = function () {
@@ -18760,15 +18755,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18760
18755
  select.appendChild(option);
18761
18756
  }
18762
18757
 
18763
- if (editable && options.mint) {
18764
- var mint = dom.createElement('option');
18765
- mint.appendChild(dom.createTextNode(options.mint));
18766
- mint.AJAR_mint = true; // Flag it
18767
-
18768
- select.insertBefore(mint, select.firstChild);
18769
- }
18770
-
18771
- if (select.currentURI == null && !options.multiple) {
18758
+ if (!select.currentURI) {
18772
18759
  var prompt = dom.createElement('option');
18773
18760
  prompt.appendChild(dom.createTextNode(options.nullLabel));
18774
18761
  select.insertBefore(prompt, select.firstChild);
@@ -18791,28 +18778,16 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
18791
18778
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
18792
18779
  var du = kb.any(category, ns.owl('disjointUnionOf'));
18793
18780
  var subs;
18794
- var multiple = false;
18795
18781
 
18796
18782
  if (!du) {
18797
18783
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
18798
- multiple = true;
18799
18784
  } else {
18800
18785
  subs = du.elements;
18801
18786
  }
18802
18787
 
18803
18788
  log.debug('Select list length ' + subs.length);
18804
-
18805
- if (subs.length === 0) {
18806
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
18807
- }
18808
-
18809
- if (subs.length === 1) {
18810
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
18811
- }
18812
-
18813
18789
  return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
18814
- multiple: multiple,
18815
- nullPrompt: '--classify--'
18790
+ nullLabel: '* Select type *'
18816
18791
  }, dataDoc, callbackFunction);
18817
18792
  }
18818
18793
  /** Make SELECT element to select subclasses recurively
@@ -18846,8 +18821,7 @@ function makeSelectForNestedCategory(dom, kb, subject, category, dataDoc, callba
18846
18821
  function onChange(ok, body) {
18847
18822
  if (ok) update();
18848
18823
  callbackFunction(ok, body);
18849
- } // eslint-disable-next-line prefer-const
18850
-
18824
+ }
18851
18825
 
18852
18826
  var select = makeSelectForCategory(dom, kb, subject, category, dataDoc, onChange);
18853
18827
  container.appendChild(select);
@@ -19002,6 +18976,199 @@ function newThing(doc) {
19002
18976
  var now = new Date();
19003
18977
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
19004
18978
  }
18979
+ /** Make SELECT element to select options
18980
+ //
18981
+ // @param subject - a term, the subject of the statement(s) being edited.
18982
+ // @param predicate - a term, the predicate of the statement(s) being edited
18983
+ // @param possible - a list of terms, the possible value the object can take
18984
+ // @param options.multiSelect - Boolean - Whether more than one at a time is allowed
18985
+ // @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
18986
+ // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
18987
+ // @param options.subForm - If mint, then the form to be used for minting the new thing
18988
+ // @param dataDoc - The web document being edited
18989
+ // @param callbackFunction - takes (boolean ok, string errorBody)
18990
+ */
18991
+
18992
+
18993
+ function makeSelectForChoice(dom, container, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
18994
+ var n = 0;
18995
+ var uris = {}; // Count them
18996
+
18997
+ var editable = kb.updater.editable(dataDoc.uri);
18998
+
18999
+ for (var i = 0; i < possible.length; i++) {
19000
+ var sub = possible[i]; // @@ Maybe; make this so it works with blank nodes too
19001
+
19002
+ if (!sub.uri) debug.warn("makeSelectForOptions: option does not have an uri: ".concat(sub, ", with predicate: ").concat(predicate));
19003
+ if (!sub.uri || sub.uri in uris) continue;
19004
+ uris[sub.uri] = true;
19005
+ n++;
19006
+ } // uris is now the set of possible options
19007
+
19008
+
19009
+ if (n === 0 && !options.mint) {
19010
+ return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
19011
+ }
19012
+
19013
+ log.debug('makeSelectForOptions: dataDoc=' + dataDoc);
19014
+
19015
+ function determinFirstSelectOption() {
19016
+ var firstSelectOptionText = '--- classify ---';
19017
+ var option = dom.createElement('option');
19018
+
19019
+ if (predicate && !(predicate.termType === 'BlankNode')) {
19020
+ firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
19021
+ }
19022
+
19023
+ if (subject && !(subject.termType === 'BlankNode')) {
19024
+ firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
19025
+ }
19026
+
19027
+ option.appendChild(dom.createTextNode(firstSelectOptionText));
19028
+ option.disabled = true;
19029
+ option.value = true;
19030
+ option.hidden = true;
19031
+ option.selected = true;
19032
+ return option;
19033
+ }
19034
+
19035
+ var onChange = function onChange(_e) {
19036
+ select.refresh();
19037
+ };
19038
+
19039
+ var select = dom.createElement('select');
19040
+ select.setAttribute('style', style.formSelectSTyle);
19041
+ if (options.multiSelect) select.setAttribute('multiSelect', 'true');
19042
+ select.currentURI = null;
19043
+ var object = kb.any(subject, predicate);
19044
+ if (object) select.currentURI = object;
19045
+
19046
+ for (var uri in uris) {
19047
+ select.appendChild(createOption(uri));
19048
+ }
19049
+
19050
+ if (editable && options.mint) {
19051
+ var mint = dom.createElement('option');
19052
+ mint.appendChild(dom.createTextNode(options.mint));
19053
+ mint.AJAR_mint = true; // Flag it
19054
+
19055
+ select.insertBefore(mint, select.firstChild);
19056
+ }
19057
+
19058
+ if (select.children.length === 0) select.insertBefore(determinFirstSelectOption(), select.firstChild);
19059
+
19060
+ select.refresh = function () {
19061
+ select.disabled = true; // unlocked any conflict we had got into
19062
+
19063
+ var ds = [];
19064
+ var is = [];
19065
+
19066
+ var removeValue = function removeValue(t) {
19067
+ if (kb.holds(subject, predicate, t, dataDoc)) {
19068
+ ds.push($rdf.st(subject, predicate, t, dataDoc));
19069
+ }
19070
+ };
19071
+
19072
+ var newObject;
19073
+
19074
+ for (var _i3 = 0; _i3 < select.options.length; _i3++) {
19075
+ var opt = select.options[_i3];
19076
+
19077
+ if (opt.selected && opt.AJAR_mint) {
19078
+ // not sure if this 'if' is used because I cannot find mintClass
19079
+ if (options.mintClass) {
19080
+ var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
19081
+ if (!ok) {
19082
+ callbackFunction(ok, body, {
19083
+ change: 'new'
19084
+ }); // @@ if ok, need some form of refresh of the select for the new thing
19085
+ }
19086
+ });
19087
+ select.parentNode.appendChild(thisForm);
19088
+ newObject = thisForm.AJAR_subject;
19089
+ } else {
19090
+ newObject = newThing(dataDoc);
19091
+ }
19092
+
19093
+ is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
19094
+ 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
19095
+
19096
+ if (options.mintStatementsFun) {
19097
+ is = is.concat(options.mintStatementsFun(newObject));
19098
+ }
19099
+
19100
+ select.currentURI = newObject;
19101
+ }
19102
+
19103
+ if (!opt.AJAR_uri) continue; // a prompt or mint
19104
+
19105
+ if (opt.selected) select.currentURI = opt.AJAR_uri;
19106
+ }
19107
+
19108
+ var sel = select.subSelect; // All subclasses must also go
19109
+
19110
+ while (sel && sel.currentURI) {
19111
+ removeValue(kb.sym(sel.currentURI));
19112
+ sel = sel.subSelect;
19113
+ }
19114
+
19115
+ sel = select.superSelect; // All superclasses are redundant
19116
+
19117
+ while (sel && sel.currentURI) {
19118
+ removeValue(kb.sym(sel.currentURI));
19119
+ sel = sel.superSelect;
19120
+ }
19121
+
19122
+ log.info('selectForOptions: data doc = ' + dataDoc);
19123
+
19124
+ if (select.currentURI) {
19125
+ removeNextSiblingsAfterElement(select);
19126
+ addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
19127
+ if (ok) {
19128
+ kb.updater.update(ds, is, function (uri, success, errorBody) {
19129
+ if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
19130
+ });
19131
+ if (callbackFunction) callbackFunction(ok, {
19132
+ widget: 'select',
19133
+ event: 'new'
19134
+ }); // widgets.refreshTree(container)
19135
+ } else {
19136
+ container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
19137
+ }
19138
+ });
19139
+ }
19140
+
19141
+ select.disabled = false;
19142
+ };
19143
+
19144
+ function createOption(uri) {
19145
+ var option = dom.createElement('option');
19146
+ var c = kb.sym(uri);
19147
+
19148
+ if (options.disambiguate) {
19149
+ option.appendChild(dom.createTextNode(utils.labelWithOntology(c, true))); // Init. cap
19150
+ } else {
19151
+ option.appendChild(dom.createTextNode(utils.label(c, true))); // Init.
19152
+ }
19153
+
19154
+ var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
19155
+
19156
+ if (backgroundColor) {
19157
+ option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
19158
+ }
19159
+
19160
+ option.AJAR_uri = uri;
19161
+ if (c.toString() === '' + select.currentURI) option.selected = true;
19162
+ return option;
19163
+ }
19164
+
19165
+ if (editable) {
19166
+ select.addEventListener('change', onChange, false);
19167
+ }
19168
+
19169
+ select.refresh();
19170
+ return select;
19171
+ } // makeSelectForChoice
19005
19172
  //# sourceMappingURL=forms.js.map
19006
19173
 
19007
19174
  /***/ }),