solid-ui 2.4.22-34c116c1 → 2.4.22-39d66c72

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/README.md CHANGED
@@ -7,13 +7,26 @@ User Interface widgets and utilities for Solid (solid-ui)
7
7
  These are HTML5 widgets which connect to a solid store. Building blocks for solid-based apps.
8
8
  Vanilla JS. Includes large widgets like chat, table, matrix, form fields, and small widgets.
9
9
 
10
+ See [Solid-Ui Storybook](http://solidos.github.io/solid-ui/examples/storybook/) for SolidUI widgets.
11
+ See [Solid-UI API](https://solidos.github.io/solid-ui/Documentation/api/) for SolidUI functions.
12
+ See [Forms introduction](./Documentation/FormsReadme.md) for UI vocabulary implementation.
13
+
14
+ Table of content:
15
+ - Getting started(#getting-started)
16
+ - Further documentation(#further-ocumentation)
17
+
18
+
10
19
  ## Getting started
20
+
21
+ Contributions of bug fixes and new functionality, documentation, and tests are
22
+ always appreciated.
23
+
11
24
  ### In npm-based projects
12
25
  When including solid-ui in an npm-based project, you can use it with:
13
26
 
14
27
  ```js
15
- import { ns, rdf, acl, aclControl, authn, create, dom, icons, log, matrix, media,
16
- messageArea, infiniteMessageArea, pad, preferences, store, style, table, tabs, utils, widgets, versionInfo
28
+ import { ns, rdf, acl, aclControl, create, dom, icons, log, matrix, media,
29
+ messageArea, infiniteMessageArea, pad, preferences, style, table, tabs, utils, widgets, versionInfo
17
30
  } from 'solid-ui'
18
31
 
19
32
  ```
@@ -23,10 +36,8 @@ Clone this repo, and in the repo root run:
23
36
  * `npm install`
24
37
  * `npm run build`
25
38
 
26
- This will generate a `lib/` folder containing, among other artifacts, `lib/webpack-bundle.js`.
27
- Now run `npx serve` and go to http://localhost:5000/examples/ with your browser to see some examples.
28
- See the ['examples' folder](https://github.com/solidos/solid-ui/tree/examples/examples) for the
29
- source code of those examples.
39
+ This will generate a `dist/` folder containing, among other artifacts, `dist/main.js`.
40
+ Now run `npx serve` and go to http://localhost:3000/Documentation/ with your browser to see some examples.
30
41
 
31
42
  While viewing one of those examples, you can open the web console in your browser and for instance
32
43
  try how you can create a button:
@@ -44,56 +55,7 @@ const chat = UI.infiniteMessageArea(document, store, UI.rdf.namedNode(chatChanne
44
55
  document.body.appendChild(chat)
45
56
  ```
46
57
 
47
- Or a full ACL Control Box:
48
- ```js
49
- const exampleFolder = 'https://example-user.inrupt.net/public/public-control/'
50
- const aclControlBox = UI.aclControl.ACLControlBox5(UI.rdf.namedNode(exampleFolder), { dom: document }, '', store)
51
- document.body.appendChild(aclControlBox)
52
- ```
53
-
54
-
55
- ## Documentation
56
- - [talk presentation](https://solidos.github.io/solid-ui/Documentation/talks/FormsTalk.html)
57
- - API https://solidos.github.io/solid-ui/Documentation/api/ for the API documentation.
58
- - The UI components are presented in a [storybook](http://solidos.github.io/solid-ui/examples/storybook/).
59
-
60
- ## Overview
61
- This has been a place to put any functionality from solid views which has been generalized to be usable in other views.
62
-
63
- - Authentication UI: manage the user's logged in/out state.
64
- - Discovery: finding the user's stuff, and leaving records of new things
65
- - Preferences: UI for managing a user's preferences with two axes of defaults
66
- - An Access Control List widget for Solid ACL system
67
- - Acess Control Logic
68
- - Create a new object from modules/extensions which have registered their ability to create things
69
-
70
- - A [form system](https://solidos.github.io/solid-ui/Documentation/forms-intro.html): Forms are defined in RDF, and create/edit RDF data, including form definitions
71
- - A collection of shortcut namespace objects for a selection of relevant RDF vocabularies.
72
- - Small atomic widgets (buttons etc) of which the others are constructed.
73
- - An error message panel
74
-
75
- Some of the larger controls include:
76
-
77
- - A chat widget: add discussion to any object. Infinite scroll, embedded images, social reactions, etc etc
78
- - A people picker widget for choosing a set of people or an existing group
79
- - A general purpose table display with built-in faceted browsing
80
- - A two-dimentional matrix of editable live data that extends in both dimensions.
81
- - A notepad of shared notes for real-time collaboration
82
- - Drag and drop code for linking things and uploading files
83
- - A set of tabs for holding other widgets and arbitrary UI elements
84
-
85
- The typical style of the widgets is to know what data it has been derived from,
86
- allow users to edit it, and to automatically sync with data as it changes in the future.
87
- To see how these are used, see the panes which use them within the data browser.
88
-
89
- The level of support for this varies.
90
-
91
- See also: [A short introduction to the Form system](https://solidos.github.io/solid-ui/Documentation/forms-intro.html)
92
-
93
- Contributions of bug fixes and new functionality, documentation, and tests are
94
- always appreciated.
95
-
96
- ## Development
58
+ ### Development new components
97
59
 
98
60
  When developing a component in solid-ui you can test it in isolation using storybook
99
61
 
@@ -104,5 +66,8 @@ npm run storybook
104
66
 
105
67
  If there is no story for the component yet, add a new one to `./src/stories`.
106
68
 
107
- When you want to test the component within a solid-pane, you can use the [development mode of solid-panes](https://github.com/solidos/solid-panes#development) or
108
- [mashlib-dev](https://github.com/solidos/mashlib-dev).
69
+ When you want to test the component within a solid-pane, you can use the [development mode of solid-panes](https://github.com/solidos/solid-panes#development).
70
+
71
+ ## Further documentation
72
+
73
+ - [Some code know-how](https://github.com/SolidOS/solidos/wiki/2.-Solid-UI-know-how)
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-12T08:42:06Z',
15196
- commit: '34c116c1c296d02641c2225bc113a041a920e806',
15195
+ buildTime: '2022-05-20T06:55:49Z',
15196
+ commit: '39d66c72c1c4f433317f3a8f6e3df4d0db35fd6e',
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
  };
@@ -17149,6 +17149,7 @@ exports.findClosest = findClosest;
17149
17149
  exports.formsFor = formsFor;
17150
17150
  exports.makeDescription = makeDescription;
17151
17151
  exports.makeSelectForCategory = makeSelectForCategory;
17152
+ exports.makeSelectForChoice = makeSelectForChoice;
17152
17153
  exports.makeSelectForNestedCategory = makeSelectForNestedCategory;
17153
17154
  exports.makeSelectForOptions = makeSelectForOptions;
17154
17155
  exports.newButton = newButton;
@@ -17260,6 +17261,7 @@ _fieldFunction.field[ns.ui('Form').uri] = _fieldFunction.field[ns.ui('Group').ur
17260
17261
  var ui = ns.ui;
17261
17262
  if (container) container.appendChild(box); // Prevent loops
17262
17263
 
17264
+ if (!form) return;
17263
17265
  var key = subject.toNT() + '|' + form.toNT();
17264
17266
 
17265
17267
  if (already[key]) {
@@ -18147,8 +18149,6 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
18147
18149
  var kb = _solidLogic.store;
18148
18150
  var formDoc = form.doc ? form.doc() : null; // @@ if blank no way to know
18149
18151
 
18150
- var uiMultipleInUse = false; // this signals to ui:choice that it is part of a ui:multiple
18151
-
18152
18152
  var multiSelect = false;
18153
18153
  var p;
18154
18154
  var box = dom.createElement('div');
@@ -18178,91 +18178,77 @@ _fieldFunction.field[ns.ui('Choice').uri] = function (dom, container, already, s
18178
18178
 
18179
18179
  var follow = kb.anyJS(form, ui('follow'), null, formDoc); // data doc moves to new subject?
18180
18180
 
18181
- var possible = [];
18182
- var possibleProperties;
18183
- var firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *'; // if we do NOT have a container it means it is a ui:Multiple
18184
- // only important for the first option text in select
18185
-
18186
- if (!container) {
18187
- uiMultipleInUse = true;
18188
- firstSelectOptionText = utils.label(subject, true);
18189
- }
18190
-
18191
- if (subject.termType === 'BlankNode') {
18192
- firstSelectOptionText = '* Select for ' + utils.label(property) + ' *';
18193
- }
18194
-
18195
18181
  var opts = {
18196
18182
  form: form,
18197
18183
  subForm: subForm,
18198
18184
  multiSelect: multiSelect,
18199
- firstSelectOptionText: firstSelectOptionText,
18200
- uiMultipleInUse: uiMultipleInUse,
18201
18185
  disambiguate: false
18202
18186
  };
18203
- possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
18204
18187
 
18205
- for (var x in kb.findMembersNT(uiFrom)) {
18206
- possible.push(kb.fromNT(x));
18207
- } // Use rdfs
18188
+ function getSelectorOptions() {
18189
+ var possible = [];
18190
+ var possibleProperties;
18191
+ possible = kb.each(undefined, ns.rdf('type'), uiFrom, formDoc);
18208
18192
 
18193
+ for (var x in kb.findMembersNT(uiFrom)) {
18194
+ possible.push(kb.fromNT(x));
18195
+ } // Use rdfs
18209
18196
 
18210
- if (uiFrom.sameTerm(ns.rdfs('Class'))) {
18211
- for (p in buttons.allClassURIs()) {
18212
- possible.push(kb.sym(p));
18213
- } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
18214
18197
 
18215
- } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
18216
- possibleProperties = buttons.propertyTriage(kb);
18198
+ if (uiFrom.sameTerm(ns.rdfs('Class'))) {
18199
+ for (p in buttons.allClassURIs()) {
18200
+ possible.push(kb.sym(p));
18201
+ } // log.debug("%%% Choice field: possible.length 2 = "+possible.length)
18217
18202
 
18218
- for (p in possibleProperties.op) {
18219
- possible.push(kb.fromNT(p));
18220
- }
18203
+ } else if (uiFrom.sameTerm(ns.rdf('Property'))) {
18204
+ possibleProperties = buttons.propertyTriage(kb);
18221
18205
 
18222
- for (p in possibleProperties.dp) {
18223
- possible.push(kb.fromNT(p));
18224
- }
18206
+ for (p in possibleProperties.op) {
18207
+ possible.push(kb.fromNT(p));
18208
+ }
18209
+
18210
+ for (p in possibleProperties.dp) {
18211
+ possible.push(kb.fromNT(p));
18212
+ }
18225
18213
 
18226
- opts.disambiguate = true; // This is a big class, and the labels won't be enough.
18227
- } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
18228
- possibleProperties = buttons.propertyTriage(kb);
18214
+ opts.disambiguate = true; // This is a big class, and the labels won't be enough.
18215
+ } else if (uiFrom.sameTerm(ns.owl('ObjectProperty'))) {
18216
+ possibleProperties = buttons.propertyTriage(kb);
18229
18217
 
18230
- for (p in possibleProperties.op) {
18231
- possible.push(kb.fromNT(p));
18232
- }
18218
+ for (p in possibleProperties.op) {
18219
+ possible.push(kb.fromNT(p));
18220
+ }
18233
18221
 
18234
- opts.disambiguate = true;
18235
- } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
18236
- possibleProperties = buttons.propertyTriage(kb);
18222
+ opts.disambiguate = true;
18223
+ } else if (uiFrom.sameTerm(ns.owl('DatatypeProperty'))) {
18224
+ possibleProperties = buttons.propertyTriage(kb);
18237
18225
 
18238
- for (p in possibleProperties.dp) {
18239
- possible.push(kb.fromNT(p));
18226
+ for (p in possibleProperties.dp) {
18227
+ possible.push(kb.fromNT(p));
18228
+ }
18229
+
18230
+ opts.disambiguate = true;
18240
18231
  }
18241
18232
 
18242
- opts.disambiguate = true;
18243
- }
18233
+ return sortByLabel(possible);
18234
+ } // TODO: this checks for any occurrence, regardless of true or false setting
18244
18235
 
18245
- var sortedPossible = sortByLabel(possible); // TODO: this checks for any occurrence, regardless of true or false setting
18246
18236
 
18247
18237
  if (kb.any(form, ui('canMintNew'))) {
18248
18238
  opts.mint = '* Create new *'; // @@ could be better
18249
18239
  }
18250
18240
 
18251
- var selector = makeSelectForOptions(dom, kb, subject, property, sortedPossible, uiFrom, opts, dataDoc, callbackFunction);
18252
- rhs.appendChild(selector);
18253
- var object;
18241
+ var selector;
18254
18242
 
18255
- if (selector.currentURI) {
18256
- object = $rdf.sym(selector.currentURI);
18257
- } else {
18258
- object = kb.any(subject, property);
18259
- }
18260
-
18261
- if (object && subForm) {
18262
- removeNextSiblingsAfterElement(selector);
18263
- addSubFormChoice(dom, rhs, already, object, subForm, follow ? object.doc() : dataDoc, callbackFunction);
18264
- }
18243
+ rhs.refresh = function () {
18244
+ var selectorOptions = getSelectorOptions();
18245
+ selector = makeSelectForChoice(dom, rhs, kb, subject, property, selectorOptions, uiFrom, opts, dataDoc, callbackFunction);
18246
+ rhs.innerHTML = '';
18247
+ rhs.appendChild(selector);
18248
+ };
18265
18249
 
18250
+ rhs.refresh();
18251
+ if (selector && selector.refresh) selector.refresh();
18266
18252
  return box;
18267
18253
  };
18268
18254
  /**
@@ -18619,10 +18605,9 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
18619
18605
  // @param subject - a term, the subject of the statement(s) being edited.
18620
18606
  // @param predicate - a term, the predicate of the statement(s) being edited
18621
18607
  // @param possible - a list of terms, the possible value the object can take
18622
- // @param options.multiSelect - Boolean - Whether more than one at a time is allowed
18623
- // @param options.firstSelectOptionText - a string to be displayed as the
18624
- // option for none selected (for non multiSelect)
18625
- // @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
18608
+ // @param options.multiple - Boolean - Whether more than one at a time is allowed
18609
+ // @param options.nullLabel - a string to be displayed as the
18610
+ // option for none selected (for non multiple)
18626
18611
  // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
18627
18612
  // @param options.subForm - If mint, then the form to be used for minting the new thing
18628
18613
  // @param dataDoc - The web document being edited
@@ -18630,7 +18615,7 @@ function makeDescription(dom, kb, subject, predicate, dataDoc, callbackFunction)
18630
18615
  */
18631
18616
 
18632
18617
 
18633
- function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
18618
+ function makeSelectForOptions(dom, kb, subject, predicate, possible, options, dataDoc, callbackFunction) {
18634
18619
  log.debug('Select list length now ' + possible.length);
18635
18620
  var n = 0;
18636
18621
  var uris = {}; // Count them
@@ -18673,6 +18658,8 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18673
18658
  actual = getActual();
18674
18659
 
18675
18660
  var onChange = function onChange(_e) {
18661
+ select.disabled = true; // until data written back - gives user feedback too
18662
+
18676
18663
  var ds = [];
18677
18664
  var is = [];
18678
18665
 
@@ -18703,14 +18690,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18703
18690
  newObject = newThing(dataDoc);
18704
18691
  }
18705
18692
 
18706
- is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
18707
- 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
18693
+ is.push($rdf.st(subject, predicate, newObject, dataDoc)); // not sure if this 'if' is used because I cannot find mintStatementsFun
18708
18694
 
18709
18695
  if (options.mintStatementsFun) {
18710
18696
  is = is.concat(options.mintStatementsFun(newObject));
18711
18697
  }
18712
-
18713
- select.currentURI = newObject;
18714
18698
  }
18715
18699
 
18716
18700
  if (!opt.AJAR_uri) continue; // a prompt or mint
@@ -18718,7 +18702,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18718
18702
  if (opt.selected && !(opt.AJAR_uri in actual)) {
18719
18703
  // new class
18720
18704
  is.push($rdf.st(subject, predicate, kb.sym(opt.AJAR_uri), dataDoc));
18721
- select.currentURI = opt.AJAR_uri;
18705
+ }
18706
+
18707
+ if (!opt.selected && opt.AJAR_uri in actual) {
18708
+ // old class
18709
+ removeValue(kb.sym(opt.AJAR_uri));
18722
18710
  }
18723
18711
 
18724
18712
  if (opt.selected) select.currentURI = opt.AJAR_uri;
@@ -18738,29 +18726,38 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18738
18726
  sel = sel.superSelect;
18739
18727
  }
18740
18728
 
18741
- log.info('selectForOptions: data doc = ' + dataDoc); // refresh subForm
18729
+ function doneNew(ok, _body) {
18730
+ callbackFunction(ok, {
18731
+ widget: 'select',
18732
+ event: 'new'
18733
+ });
18734
+ }
18735
+
18736
+ log.info('selectForOptions: data doc = ' + dataDoc);
18737
+ kb.updater.update(ds, is, function (uri, ok, body) {
18738
+ actual = getActual(); // refresh
18742
18739
 
18743
- removeNextSiblingsAfterElement(select);
18744
- addSubFormChoice(dom, select.parentNode, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
18745
18740
  if (ok) {
18746
- kb.updater.update(ds, is, function (uri, success, errorBody) {
18747
- actual = getActual(); // refresh
18741
+ select.disabled = false; // data written back
18748
18742
 
18749
- if (!success) select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
18750
- });
18751
- if (callbackFunction) callbackFunction(ok, {
18752
- widget: 'select',
18753
- event: 'new'
18754
- });
18743
+ if (newObject) {
18744
+ var fn = (0, _fieldFunction.fieldFunction)(dom, options.subForm);
18745
+ fn(dom, select.parentNode, {}, newObject, options.subForm, dataDoc, doneNew);
18746
+ }
18755
18747
  } else {
18756
- select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
18748
+ return select.parentNode.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in select: ' + body));
18757
18749
  }
18750
+
18751
+ if (callbackFunction) callbackFunction(ok, {
18752
+ widget: 'select',
18753
+ event: 'change'
18754
+ });
18758
18755
  });
18759
18756
  };
18760
18757
 
18761
18758
  var select = dom.createElement('select');
18762
18759
  select.setAttribute('style', style.formSelectSTyle);
18763
- if (options.multiSelect) select.setAttribute('multiSelect', 'true');
18760
+ if (options.multiple) select.setAttribute('multiple', 'true');
18764
18761
  select.currentURI = null;
18765
18762
 
18766
18763
  select.refresh = function () {
@@ -18811,14 +18808,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18811
18808
  select.insertBefore(mint, select.firstChild);
18812
18809
  }
18813
18810
 
18814
- if (!select.currentURI && options.uiMultipleInUse) {
18811
+ if (select.currentURI == null && !options.multiple) {
18815
18812
  var prompt = dom.createElement('option');
18816
- prompt.appendChild(dom.createTextNode(options.firstSelectOptionText));
18817
- prompt.disabled = true;
18818
- prompt.value = true;
18819
- prompt.hidden = true;
18820
- prompt.selected = true;
18813
+ prompt.appendChild(dom.createTextNode(options.nullLabel));
18821
18814
  select.insertBefore(prompt, select.firstChild);
18815
+ prompt.selected = true;
18822
18816
  }
18823
18817
 
18824
18818
  if (editable) {
@@ -18837,11 +18831,11 @@ function makeSelectForOptions(dom, kb, subject, predicate, possible, uiFrom, opt
18837
18831
  function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunction) {
18838
18832
  var du = kb.any(category, ns.owl('disjointUnionOf'));
18839
18833
  var subs;
18840
- var multiSelect = false;
18834
+ var multiple = false;
18841
18835
 
18842
18836
  if (!du) {
18843
18837
  subs = kb.each(undefined, ns.rdfs('subClassOf'), category);
18844
- multiSelect = true;
18838
+ multiple = true;
18845
18839
  } else {
18846
18840
  subs = du.elements;
18847
18841
  }
@@ -18849,15 +18843,16 @@ function makeSelectForCategory(dom, kb, subject, category, dataDoc, callbackFunc
18849
18843
  log.debug('Select list length ' + subs.length);
18850
18844
 
18851
18845
  if (subs.length === 0) {
18852
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
18846
+ return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with no subclasses of category: ' + category);
18853
18847
  }
18854
18848
 
18855
18849
  if (subs.length === 1) {
18856
- return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiSelect ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
18850
+ return (0, _error.errorMessageBlock)(dom, "Can't do " + (multiple ? 'multiple ' : '') + 'selector with only 1 subclass of category: ' + category + ':' + subs[1]);
18857
18851
  }
18858
18852
 
18859
- return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, null, {
18860
- multiSelect: multiSelect
18853
+ return makeSelectForOptions(dom, kb, subject, ns.rdf('type'), subs, {
18854
+ multiple: multiple,
18855
+ nullPrompt: '--classify--'
18861
18856
  }, dataDoc, callbackFunction);
18862
18857
  }
18863
18858
  /** Make SELECT element to select subclasses recurively
@@ -19047,6 +19042,199 @@ function newThing(doc) {
19047
19042
  var now = new Date();
19048
19043
  return $rdf.sym(doc.uri + '#' + 'id' + ('' + now.getTime()));
19049
19044
  }
19045
+ /** Make SELECT element to select options
19046
+ //
19047
+ // @param subject - a term, the subject of the statement(s) being edited.
19048
+ // @param predicate - a term, the predicate of the statement(s) being edited
19049
+ // @param possible - a list of terms, the possible value the object can take
19050
+ // @param options.multiSelect - Boolean - Whether more than one at a time is allowed
19051
+ // @param options.uiMultipleInUse - signals that the ui:choise is used with a ui:multiple
19052
+ // @param options.mint - User may create thing if this sent to the prompt string eg "New foo"
19053
+ // @param options.subForm - If mint, then the form to be used for minting the new thing
19054
+ // @param dataDoc - The web document being edited
19055
+ // @param callbackFunction - takes (boolean ok, string errorBody)
19056
+ */
19057
+
19058
+
19059
+ function makeSelectForChoice(dom, container, kb, subject, predicate, possible, uiFrom, options, dataDoc, callbackFunction) {
19060
+ var n = 0;
19061
+ var uris = {}; // Count them
19062
+
19063
+ var editable = kb.updater.editable(dataDoc.uri);
19064
+
19065
+ for (var i = 0; i < possible.length; i++) {
19066
+ var sub = possible[i]; // @@ Maybe; make this so it works with blank nodes too
19067
+
19068
+ if (!sub.uri) debug.warn("makeSelectForOptions: option does not have an uri: ".concat(sub, ", with predicate: ").concat(predicate));
19069
+ if (!sub.uri || sub.uri in uris) continue;
19070
+ uris[sub.uri] = true;
19071
+ n++;
19072
+ } // uris is now the set of possible options
19073
+
19074
+
19075
+ if (n === 0 && !options.mint) {
19076
+ return (0, _error.errorMessageBlock)(dom, "Can't do selector with no options, subject= " + subject + ' property = ' + predicate + '.');
19077
+ }
19078
+
19079
+ log.debug('makeSelectForOptions: dataDoc=' + dataDoc);
19080
+
19081
+ function determinFirstSelectOption() {
19082
+ var firstSelectOptionText = '--- classify ---';
19083
+ var option = dom.createElement('option');
19084
+
19085
+ if (predicate && !(predicate.termType === 'BlankNode')) {
19086
+ firstSelectOptionText = '* Select for property: ' + utils.label(predicate) + ' *';
19087
+ }
19088
+
19089
+ if (subject && !(subject.termType === 'BlankNode')) {
19090
+ firstSelectOptionText = '* Select for ' + utils.label(subject, true) + ' *';
19091
+ }
19092
+
19093
+ option.appendChild(dom.createTextNode(firstSelectOptionText));
19094
+ option.disabled = true;
19095
+ option.value = true;
19096
+ option.hidden = true;
19097
+ option.selected = true;
19098
+ return option;
19099
+ }
19100
+
19101
+ var onChange = function onChange(_e) {
19102
+ select.refresh();
19103
+ };
19104
+
19105
+ var select = dom.createElement('select');
19106
+ select.setAttribute('style', style.formSelectSTyle);
19107
+ if (options.multiSelect) select.setAttribute('multiSelect', 'true');
19108
+ select.currentURI = null;
19109
+ var object = kb.any(subject, predicate);
19110
+ if (object) select.currentURI = object;
19111
+
19112
+ for (var uri in uris) {
19113
+ select.appendChild(createOption(uri));
19114
+ }
19115
+
19116
+ if (editable && options.mint) {
19117
+ var mint = dom.createElement('option');
19118
+ mint.appendChild(dom.createTextNode(options.mint));
19119
+ mint.AJAR_mint = true; // Flag it
19120
+
19121
+ select.insertBefore(mint, select.firstChild);
19122
+ }
19123
+
19124
+ if (select.children.length === 0) select.insertBefore(determinFirstSelectOption(), select.firstChild);
19125
+
19126
+ select.refresh = function () {
19127
+ select.disabled = true; // unlocked any conflict we had got into
19128
+
19129
+ var ds = [];
19130
+ var is = [];
19131
+
19132
+ var removeValue = function removeValue(t) {
19133
+ if (kb.holds(subject, predicate, t, dataDoc)) {
19134
+ ds.push($rdf.st(subject, predicate, t, dataDoc));
19135
+ }
19136
+ };
19137
+
19138
+ var newObject;
19139
+
19140
+ for (var _i3 = 0; _i3 < select.options.length; _i3++) {
19141
+ var opt = select.options[_i3];
19142
+
19143
+ if (opt.selected && opt.AJAR_mint) {
19144
+ // not sure if this 'if' is used because I cannot find mintClass
19145
+ if (options.mintClass) {
19146
+ var thisForm = promptForNew(dom, kb, subject, predicate, options.mintClass, null, dataDoc, function (ok, body) {
19147
+ if (!ok) {
19148
+ callbackFunction(ok, body, {
19149
+ change: 'new'
19150
+ }); // @@ if ok, need some form of refresh of the select for the new thing
19151
+ }
19152
+ });
19153
+ select.parentNode.appendChild(thisForm);
19154
+ newObject = thisForm.AJAR_subject;
19155
+ } else {
19156
+ newObject = newThing(dataDoc);
19157
+ }
19158
+
19159
+ is.push($rdf.st(subject, predicate, kb.sym(newObject), dataDoc));
19160
+ 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
19161
+
19162
+ if (options.mintStatementsFun) {
19163
+ is = is.concat(options.mintStatementsFun(newObject));
19164
+ }
19165
+
19166
+ select.currentURI = newObject;
19167
+ }
19168
+
19169
+ if (!opt.AJAR_uri) continue; // a prompt or mint
19170
+
19171
+ if (opt.selected) select.currentURI = opt.AJAR_uri;
19172
+ }
19173
+
19174
+ var sel = select.subSelect; // All subclasses must also go
19175
+
19176
+ while (sel && sel.currentURI) {
19177
+ removeValue(kb.sym(sel.currentURI));
19178
+ sel = sel.subSelect;
19179
+ }
19180
+
19181
+ sel = select.superSelect; // All superclasses are redundant
19182
+
19183
+ while (sel && sel.currentURI) {
19184
+ removeValue(kb.sym(sel.currentURI));
19185
+ sel = sel.superSelect;
19186
+ }
19187
+
19188
+ log.info('selectForOptions: data doc = ' + dataDoc);
19189
+
19190
+ if (select.currentURI) {
19191
+ removeNextSiblingsAfterElement(select);
19192
+ addSubFormChoice(dom, container, {}, $rdf.sym(select.currentURI), options.subForm, dataDoc, function (ok, body) {
19193
+ if (ok) {
19194
+ kb.updater.update(ds, is, function (uri, success, errorBody) {
19195
+ if (!success) container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating select: ' + errorBody));
19196
+ });
19197
+ if (callbackFunction) callbackFunction(ok, {
19198
+ widget: 'select',
19199
+ event: 'new'
19200
+ }); // widgets.refreshTree(container)
19201
+ } else {
19202
+ container.appendChild((0, _error.errorMessageBlock)(dom, 'Error updating data in field of select: ' + body));
19203
+ }
19204
+ });
19205
+ }
19206
+
19207
+ select.disabled = false;
19208
+ };
19209
+
19210
+ function createOption(uri) {
19211
+ var option = dom.createElement('option');
19212
+ var c = kb.sym(uri);
19213
+
19214
+ if (options.disambiguate) {
19215
+ option.appendChild(dom.createTextNode(utils.labelWithOntology(c, true))); // Init. cap
19216
+ } else {
19217
+ option.appendChild(dom.createTextNode(utils.label(c, true))); // Init.
19218
+ }
19219
+
19220
+ var backgroundColor = kb.any(c, kb.sym('http://www.w3.org/ns/ui#backgroundColor'));
19221
+
19222
+ if (backgroundColor) {
19223
+ option.setAttribute('style', 'background-color: ' + backgroundColor.value + '; ');
19224
+ }
19225
+
19226
+ option.AJAR_uri = uri;
19227
+ if (c.toString() === '' + select.currentURI) option.selected = true;
19228
+ return option;
19229
+ }
19230
+
19231
+ if (editable) {
19232
+ select.addEventListener('change', onChange, false);
19233
+ }
19234
+
19235
+ select.refresh();
19236
+ return select;
19237
+ } // makeSelectForChoice
19050
19238
  //# sourceMappingURL=forms.js.map
19051
19239
 
19052
19240
  /***/ }),