solid-ui 2.4.22-4af9be21 → 2.4.22-4f620aea

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.
@@ -159,10 +159,11 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
159
159
 
160
160
  if (already[key]) {
161
161
  // 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
162
+ box.appendChild(dom.createTextNode('Group: see above ' + key)); // TODO fix dependency cycle to solid-panes by calling outlineManager
163
+ // const plist = [$rdf.st(subject, ns.owl('sameAs'), subject)] // @@ need prev subject
164
+ // dom.outlineManager.appendPropertyTRs(box, plist)
165
+ // dom.appendChild(plist)
164
166
 
165
- dom.outlineManager.appendPropertyTRs(box, plist);
166
167
  return box;
167
168
  }
168
169
 
@@ -591,7 +592,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
591
592
  // delete button and move buttons
592
593
 
593
594
  if (kb.updater.editable(dataDoc.uri)) {
594
- buttons.deleteButtonWithCheck(dom, subField, utils.label(property), deleteThisItem);
595
+ buttons.deleteButtonWithCheck(dom, subField, multipleUIlabel, deleteThisItem);
595
596
 
596
597
  if (ordered) {
597
598
  // Add controsl in a frame
@@ -642,7 +643,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
642
643
 
643
644
  var _shim = dom.createElement('div');
644
645
 
645
- _shim.appendChild(subField); // Subfield has its own laytout
646
+ _shim.appendChild(subField); // Subfield has its own layout
646
647
 
647
648
 
648
649
  frame.appendChild(_shim);
@@ -691,6 +692,8 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
691
692
  return shim;
692
693
  }
693
694
 
695
+ var multipleUIlabel = kb.any(form, ui('label'));
696
+ if (!multipleUIlabel) multipleUIlabel = utils.label(property);
694
697
  var min = kb.any(form, ui('min')); // This is the minimum number -- default 0
695
698
 
696
699
  min = min ? 0 + min.value : 0;
@@ -731,10 +734,9 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
731
734
  img.setAttribute('src', plusIconURI); // plus sign
732
735
 
733
736
  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
-
737
+ img.title = 'Click to add another ' + multipleUIlabel;
738
+ var prompt = dom.createElement('span');
739
+ prompt.textContent = (values.length === 0 ? 'Add another ' : 'Add ') + multipleUIlabel;
738
740
  tail.addEventListener('click', /*#__PURE__*/function () {
739
741
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(_eventNotUsed) {
740
742
  return _regenerator["default"].wrap(function _callee5$(_context5) {
@@ -756,6 +758,7 @@ _fieldFunction.field[ns.ui('Multiple').uri] = function (dom, container, already,
756
758
  return _ref3.apply(this, arguments);
757
759
  };
758
760
  }(), true);
761
+ tail.appendChild(prompt);
759
762
  }
760
763
 
761
764
  function createListIfNecessary() {
@@ -1017,28 +1020,41 @@ _fieldFunction.field[ns.ui('Classifier').uri] = function (dom, container, alread
1017
1020
  **
1018
1021
  ** Not nested. Generates a link to something from a given class.
1019
1022
  ** Optional subform for the thing selected.
1023
+ ** Generates a subForm based on a ui:use form
1024
+ ** Will look like:
1025
+ ** <div id=dropDownDiv>
1026
+ ** <div id=labelOfDropDown>
1027
+ ** <div id=selectDiv>
1028
+ ** <select id=dropDownSelect>
1029
+ ** <option> ....
1030
+ ** <subForm>
1020
1031
  ** Alternative implementatons caould be:
1021
1032
  ** -- pop-up menu (as here)
1022
1033
  ** -- radio buttons
1023
1034
  ** -- auto-complete typing
1024
1035
  **
1025
- ** Todo: Deal with multiple. Maybe merge with multiple code.
1036
+ ** TODO: according to ontology ui:choice can also have ns.ui('default') - this is not implemented yet
1026
1037
  */
1027
1038
 
1028
1039
 
1029
1040
  _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, subject, form, dataDoc, callbackFunction) {
1030
1041
  var ui = ns.ui;
1031
1042
  var kb = _solidLogic.store;
1032
- var multiple = false;
1033
1043
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
1034
1044
 
1045
+ var uiMultipleInUse = false; // this signals to ui:choice that it is part of a ui:multiple
1046
+
1047
+ var multiSelect = false;
1035
1048
  var p;
1036
- var box = dom.createElement('div'); // Set flexDirection column?
1049
+ var box = dom.createElement('div');
1050
+ box.setAttribute('class', 'choiceBox'); // Set flexDirection column?
1037
1051
 
1038
1052
  if (container) container.appendChild(box);
1039
1053
  var lhs = dom.createElement('div');
1054
+ lhs.setAttribute('class', 'formFieldName choiceBox-label');
1040
1055
  box.appendChild(lhs);
1041
1056
  var rhs = dom.createElement('div');
1057
+ rhs.setAttribute('class', 'formFieldValue choiceBox-selectBox');
1042
1058
  box.appendChild(rhs);
1043
1059
  var property = kb.any(form, ui('property'));
1044
1060
 
@@ -1047,9 +1063,9 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1047
1063
  }
1048
1064
 
1049
1065
  lhs.appendChild((0, _basic.fieldLabel)(dom, property, form));
1050
- var from = kb.any(form, ui('from'));
1066
+ var uiFrom = kb.any(form, ui('from'));
1051
1067
 
1052
- if (!from) {
1068
+ if (!uiFrom) {
1053
1069
  return (0, _error.errorMessageBlock)(dom, "No 'from' for Choice: " + form);
1054
1070
  }
1055
1071
 
@@ -1059,26 +1075,39 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1059
1075
 
1060
1076
  var possible = [];
1061
1077
  var possibleProperties;
1062
- var nullLabel = '--' + utils.label(property) + '-?';
1078
+ var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
1079
+ // only important for the first option text in select
1080
+
1081
+ if (!container) {
1082
+ uiMultipleInUse = true;
1083
+ firstSelectOptionText = utils.label(subject, true);
1084
+ }
1085
+
1086
+ if (subject.termType === 'BlankNode') {
1087
+ firstSelectOptionText = '* Select for ' + utils.label(property) + ' *';
1088
+ }
1089
+
1063
1090
  var opts = {
1064
1091
  form: form,
1065
- multiple: multiple,
1066
- nullLabel: nullLabel,
1092
+ subForm: subForm,
1093
+ multiSelect: multiSelect,
1094
+ firstSelectOptionText: firstSelectOptionText,
1095
+ uiMultipleInUse: uiMultipleInUse,
1067
1096
  disambiguate: false
1068
1097
  };
1069
- possible = kb.each(undefined, ns.rdf('type'), from, formDoc);
1098
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
1070
1099
 
1071
- for (var x in kb.findMembersNT(from)) {
1100
+ for (var x in kb.findMembersNT(uiFrom)) {
1072
1101
  possible.push(kb.fromNT(x));
1073
1102
  } // Use rdfs
1074
1103
 
1075
1104
 
1076
- if (from.sameTerm(ns.rdfs('Class'))) {
1105
+ if (uiFrom.sameTerm(ns.rdfs('Class'))) {
1077
1106
  for (p in buttons.allClassURIs()) {
1078
1107
  possible.push(kb.sym(p));
1079
1108
  } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
1080
1109
 
1081
- } else if (from.sameTerm(ns.rdf('Property'))) {
1110
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
1082
1111
  possibleProperties = buttons.propertyTriage(kb);
1083
1112
 
1084
1113
  for (p in possibleProperties.op) {
@@ -1090,7 +1119,7 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1090
1119
  }
1091
1120
 
1092
1121
  opts.disambiguate = true; // This is a big class, and the labels won't be enough.
1093
- } else if (from.sameTerm(ns.owl('ObjectProperty'))) {
1122
+ } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
1094
1123
  possibleProperties = buttons.propertyTriage(kb);
1095
1124
 
1096
1125
  for (p in possibleProperties.op) {
@@ -1098,7 +1127,7 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1098
1127
  }
1099
1128
 
1100
1129
  opts.disambiguate = true;
1101
- } else if (from.sameTerm(ns.owl('DatatypeProperty'))) {
1130
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
1102
1131
  possibleProperties = buttons.propertyTriage(kb);
1103
1132
 
1104
1133
  for (p in possibleProperties.dp) {
@@ -1108,26 +1137,45 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
1108
1137
  opts.disambiguate = true;
1109
1138
  }
1110
1139
 
1111
- var object = kb.any(subject, property);
1140
+ var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
1112
1141
 
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);
1142
+ if (kb.any(form, ui('canMintNew'))) {
1143
+ opts.mint = '* Create new *'; // @@ could be better
1116
1144
  }
1117
1145
 
1118
- var possible2 = sortByLabel(possible);
1146
+ var selector = makeSelectForOptions(dom, kb, subject, property, sortedPossible, uiFrom, opts, dataDoc, callbackFunction);
1147
+ rhs.appendChild(selector);
1148
+ var object;
1119
1149
 
1120
- if (kb.any(form, ui('canMintNew'))) {
1121
- opts.mint = '* New *'; // @@ could be better
1150
+ if (selector.currentURI) {
1151
+ object = $rdf.sym(selector.currentURI);
1152
+ } else {
1153
+ object = kb.any(subject, property);
1154
+ }
1122
1155
 
1123
- opts.subForm = subForm;
1156
+ if (object && subForm) {
1157
+ removeNextSiblingsAfterElement(selector);
1158
+ addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
1124
1159
  }
1125
1160
 
1126
- var selector = makeSelectForOptions(dom, kb, subject, property, possible2, opts, dataDoc, callbackFunction);
1127
- rhs.appendChild(selector);
1128
- if (object && subForm) addSubForm();
1129
1161
  return box;
1130
- }; // Documentation - non-interactive fields
1162
+ };
1163
+ /**
1164
+ * Removes all sibling elements after specified
1165
+ * @param {HTMLElement} currentElement
1166
+ * @private
1167
+ */
1168
+
1169
+
1170
+ function removeNextSiblingsAfterElement(currentElement) {
1171
+ while (currentElement.nextElementSibling) {
1172
+ currentElement.nextElementSibling.remove();
1173
+ }
1174
+ }
1175
+
1176
+ function addSubFormChoice(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction) {
1177
+ (0, _fieldFunction.fieldFunction)(dom, subForm)(dom, selectDiv, already, subject, subForm, dataDoc, callbackFunction);
1178
+ } // Documentation - non-interactive fields
1131
1179
  //
1132
1180
 
1133
1181
 
@@ -1330,7 +1378,8 @@ function promptForNew(dom, kb, subject, predicate, theClass, form, dataDoc, call
1330
1378
  b.setAttribute('type', 'button');
1331
1379
  b.setAttribute('style', 'float: right;');
1332
1380
  b.innerHTML = 'Goto ' + utils.label(theClass);
1333
- b.addEventListener('click', function (_e) {
1381
+ b.addEventListener('click', // TODO fix dependency cycle to solid-panes by calling outlineManager
1382
+ function (_e) {
1334
1383
  dom.outlineManager.GotoSubject(theClass, true, undefined, true, undefined);
1335
1384
  }, false);
1336
1385
  return box;
@@ -1465,9 +1514,10 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1465
1514
  // @param subject - a term, the subject of the statement(s) being edited.
1466
1515
  // @param predicate - a term, the predicate of the statement(s) being edited
1467
1516
  // @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
- // @param options.nullLabel - a string to be displayed as the
1470
- // option for none selected (for non multiple)
1517
+ // @param options.multiSelect - Boolean - Whether more than one at a time is allowed
1518
+ // @param options.firstSelectOptionText - a string to be displayed as the
1519
+ // option for none selected (for non multiSelect)
1520
+ // @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
1471
1521
  // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
1472
1522
  // @param options.subForm - If mint, then the form to be used for minting the new thing
1473
1523
  // @param dataDoc - The web document being edited
@@ -1475,7 +1525,7 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
1475
1525
  */
1476
1526
 
1477
1527
 
1478
- function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
1528
+ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
1479
1529
  log.debug('Select list length now ' + possible.length);
1480
1530
  var n = 0;
1481
1531
  var uris = {}; // Count them
@@ -1506,7 +1556,9 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1506
1556
  actual = kb.findTypeURIs(subject);
1507
1557
  } else {
1508
1558
  kb.each(subject, predicate, null, dataDoc).forEach(function (x) {
1509
- actual[x.uri] = true;
1559
+ if (x.uri) {
1560
+ actual[x.uri] = true;
1561
+ }
1510
1562
  });
1511
1563
  }
1512
1564
 
@@ -1516,8 +1568,6 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1516
1568
  actual = getActual();
1517
1569
 
1518
1570
  var onChange = function onChange(_e) {
1519
- select.disabled = true; // until data written back - gives user feedback too
1520
-
1521
1571
  var ds = [];
1522
1572
  var is = [];
1523
1573
 
@@ -1533,6 +1583,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1533
1583
  var opt = select.options[_i];
1534
1584
 
1535
1585
  if (opt.selected && opt.AJAR_mint) {
1586
+ // not sure if this 'if' is used because I cannot find mintClass
1536
1587
  if (options.mintClass) {
1537
1588
  var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
1538
1589
  if (!ok) {
@@ -1547,11 +1598,14 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1547
1598
  newObject = newThing(dataDoc);
1548
1599
  }
1549
1600
 
1550
- is.push($rdf.st(subject, predicate, newObject, dataDoc));
1601
+ is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
1602
+ 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
1551
1603
 
1552
1604
  if (options.mintStatementsFun) {
1553
1605
  is = is.concat(options.mintStatementsFun(newObject));
1554
1606
  }
1607
+
1608
+ select.currentURI = newObject;
1555
1609
  }
1556
1610
 
1557
1611
  if (!opt.AJAR_uri) continue; // a prompt or mint
@@ -1559,11 +1613,7 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1559
1613
  if (opt.selected && !(opt.AJAR_uri in actual)) {
1560
1614
  // new class
1561
1615
  is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
1562
- }
1563
-
1564
- if (!opt.selected && opt.AJAR_uri in actual) {
1565
- // old class
1566
- removeValue(kb.sym(opt.AJAR_uri));
1616
+ select.currentURI = opt.AJAR_uri;
1567
1617
  }
1568
1618
 
1569
1619
  if (opt.selected) select.currentURI = opt.AJAR_uri;
@@ -1583,38 +1633,29 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1583
1633
  sel = sel.superSelect;
1584
1634
  }
1585
1635
 
1586
- function doneNew(ok, _body) {
1587
- callbackFunction(ok, {
1588
- widget: 'select',
1589
- event: 'new'
1590
- });
1591
- }
1592
-
1593
- log.info('selectForOptions: data doc = ' + dataDoc);
1594
- kb.updater.update(ds, is, function (uri, ok, body) {
1595
- actual = getActual(); // refresh
1636
+ log.info('selectForOptions: data doc = ' + dataDoc); // refresh subForm
1596
1637
 
1638
+ removeNextSiblingsAfterElement(select);
1639
+ addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
1597
1640
  if (ok) {
1598
- 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
- }
1641
+ kb.updater.update(ds, is, function (uri, success, errorBody) {
1642
+ actual = getActual(); // refresh
1643
+
1644
+ if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
1645
+ });
1646
+ if (callbackFunction) callbackFunction(ok, {
1647
+ widget: 'select',
1648
+ event: 'new'
1649
+ });
1604
1650
  } else {
1605
- return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
1651
+ select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
1606
1652
  }
1607
-
1608
- if (callbackFunction) callbackFunction(ok, {
1609
- widget: 'select',
1610
- event: 'change'
1611
- });
1612
1653
  });
1613
1654
  };
1614
1655
 
1615
1656
  var select = dom.createElement('select');
1616
1657
  select.setAttribute('style', style.formSelectSTyle);
1617
- if (options.multiple) select.setAttribute('multiple', 'true');
1658
+ if (options.multiSelect) select.setAttribute('multiSelect', 'true');
1618
1659
  select.currentURI = null;
1619
1660
 
1620
1661
  select.refresh = function () {
@@ -1665,11 +1706,14 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1665
1706
  select.insertBefore(mint, select.firstChild);
1666
1707
  }
1667
1708
 
1668
- if (select.currentURI == null && !options.multiple) {
1709
+ if (!select.currentURI && options.uiMultipleInUse) {
1669
1710
  var prompt = dom.createElement('option');
1670
- prompt.appendChild(dom.createTextNode(options.nullLabel));
1671
- select.insertBefore(prompt, select.firstChild);
1711
+ prompt.appendChild(dom.createTextNode(options.firstSelectOptionText));
1712
+ prompt.disabled = true;
1713
+ prompt.value = true;
1714
+ prompt.hidden = true;
1672
1715
  prompt.selected = true;
1716
+ select.insertBefore(prompt, select.firstChild);
1673
1717
  }
1674
1718
 
1675
1719
  if (editable) {
@@ -1688,11 +1732,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, da
1688
1732
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
1689
1733
  var du = kb.any(category, ns.owl('disjointUnionOf'));
1690
1734
  var subs;
1691
- var multiple = false;
1735
+ var multiSelect = false;
1692
1736
 
1693
1737
  if (!du) {
1694
1738
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
1695
- multiple = true;
1739
+ multiSelect = true;
1696
1740
  } else {
1697
1741
  subs = du.elements;
1698
1742
  }
@@ -1700,16 +1744,15 @@ function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunc
1700
1744
  log.debug('Select list length ' + subs.length);
1701
1745
 
1702
1746
  if (subs.length === 0) {
1703
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1747
+ return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
1704
1748
  }
1705
1749
 
1706
1750
  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]);
1751
+ return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
1708
1752
  }
1709
1753
 
1710
- return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
1711
- multiple: multiple,
1712
- nullPrompt: '--classify--'
1754
+ return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
1755
+ multiSelect: multiSelect
1713
1756
  }, dataDoc, callbackFunction);
1714
1757
  }
1715
1758
  /** Make SELECT element to select subclasses recurively