@startinblox/core 0.18.1 → 0.19.0-beta.2

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.
Files changed (43) hide show
  1. package/dist/_snowpack/pkg/common/{_baseUnary-c1edb653.js → _baseUnary-d2677655.js} +2 -2
  2. package/dist/_snowpack/pkg/common/{_baseUnary-c1edb653.js.map → _baseUnary-d2677655.js.map} +1 -1
  3. package/dist/_snowpack/pkg/common/{_commonjsHelpers-37fa8da4.js → _commonjsHelpers-0597c316.js} +2 -2
  4. package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js.map +1 -0
  5. package/dist/_snowpack/pkg/delta-markdown-for-quill.js +2 -2
  6. package/dist/_snowpack/pkg/dialog-polyfill.js +1 -2
  7. package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -1
  8. package/dist/_snowpack/pkg/import-map.json +1 -0
  9. package/dist/_snowpack/pkg/jsonld-context-parser.js +1 -1
  10. package/dist/_snowpack/pkg/jsonld.js +11760 -0
  11. package/dist/_snowpack/pkg/jsonld.js.map +1 -0
  12. package/dist/_snowpack/pkg/markdown-it.js +1 -1
  13. package/dist/_snowpack/pkg/quill-delta-to-markdown.js +2 -2
  14. package/dist/_snowpack/pkg/quill.js +11626 -11627
  15. package/dist/_snowpack/pkg/quill.js.map +1 -1
  16. package/dist/_snowpack/pkg/tui-calendar.js +43101 -43105
  17. package/dist/_snowpack/pkg/tui-calendar.js.map +1 -1
  18. package/dist/components/solid-form-search.js +1 -2
  19. package/dist/components/solid-form.js +2 -4
  20. package/dist/libs/ComponentFactory.js +1 -4
  21. package/dist/libs/filter.js +1 -1
  22. package/dist/libs/helpers.js +4 -10
  23. package/dist/libs/lit-helpers.js +1 -4
  24. package/dist/libs/polyfills.js +2 -4
  25. package/dist/libs/store/custom-getter.js +313 -0
  26. package/dist/libs/store/server-pagination.js +4 -7
  27. package/dist/libs/store/server-search.js +4 -7
  28. package/dist/libs/store/store.js +92 -346
  29. package/dist/mixins/attributeBinderMixin.js +3 -6
  30. package/dist/mixins/federationMixin.js +6 -0
  31. package/dist/mixins/filterMixin.js +13 -16
  32. package/dist/mixins/listMixin.js +20 -9
  33. package/dist/mixins/requiredMixin.js +15 -3
  34. package/dist/mixins/storeMixin.js +30 -0
  35. package/dist/mixins/widgetMixin.js +18 -5
  36. package/dist/new-widgets/templates/formTemplatesDirectory.js +6 -15
  37. package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +3 -0
  38. package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +17 -4
  39. package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +11 -2
  40. package/dist/widgets/baseWidget.js +4 -5
  41. package/dist/widgets/widget-factory.js +1 -3
  42. package/package.json +5 -4
  43. package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { store } from '../libs/store/store.js';
1
2
  const RequiredMixin = {
2
3
  name: 'required-mixin',
3
4
  use: [],
@@ -11,9 +12,20 @@ const RequiredMixin = {
11
12
  for (let resource of resources) {
12
13
  let hasProps = true;
13
14
  for (let field of requiredFields) {
14
- if ((await resource[field]) == null || (await resource[field]) == "") {
15
- hasProps = false;
16
- continue;
15
+ // Retrieve resource from store
16
+ let res = store.get(resource['@id']);
17
+ if (!res && !resource[field] && !(await resource[field])) {
18
+ //TODO: refactor to better handle this edge case where res is either the direct resource or a proxy
19
+ res = await store.getData(resource['@id'], this.context);
20
+ if (!res || res[field] == null || res[field] == "") {
21
+ hasProps = false;
22
+ continue;
23
+ }
24
+ } else if (res) {
25
+ if ((await res[field]) == null || (await res[field]) == "") {
26
+ hasProps = false;
27
+ continue;
28
+ }
17
29
  }
18
30
  }
19
31
  if (hasProps) displays.push(resource);
@@ -35,6 +35,17 @@ const StoreMixin = {
35
35
  nestedField: {
36
36
  type: String,
37
37
  default: null
38
+ },
39
+ arrayField: {
40
+ type: String,
41
+ default: null,
42
+ callback: function (value) {
43
+ if (value) this.predicateName = store.getExpandedPredicate(this.arrayField, this.context);
44
+ }
45
+ },
46
+ predicateName: {
47
+ type: String,
48
+ default: null
38
49
  }
39
50
  },
40
51
  initialState: {
@@ -67,7 +78,26 @@ const StoreMixin = {
67
78
  if (!value || value == "undefined") return;
68
79
  this.resourceId = value;
69
80
  if (this.nestedField) {
81
+ // First step: store.getData
70
82
  const resource = await store.getData(value, this.context);
83
+
84
+ // Which internally triggers store.fetchData -> Fine
85
+
86
+ // Which triggers store.fetchAuthn -> Fine
87
+
88
+ // Once done it calls store.cacheGraph
89
+
90
+ // And the issue seems to reside in the caching ?
91
+
92
+ // How is computed the key to cache the nested resource with proper id like
93
+ // http:///localhost:3000/examples/data/list/group-3.jsonld#foaf:member ?
94
+ // Should it be:
95
+ // - http:///localhost:3000/examples/data/list/group-3.jsonld#foaf:member
96
+ // - _:b1/examples/data/list/group-3.jsonld#foaf:member
97
+ // - _:b9/examples/data/list/group-3.jsonld
98
+ // - examples/data/list/group-3.jsonld#foaf:member
99
+
100
+ // So the work is in cacheGraph ?
71
101
  const nestedResource = resource ? await resource[this.nestedField] : null;
72
102
  this.resourceId = nestedResource ? nestedResource['@id'] : null;
73
103
  if (!this.resourceId) throw `Error: the key "${this.nestedField}" does not exist on the resource`;
@@ -53,6 +53,12 @@ const WidgetMixin = {
53
53
  resource = res;
54
54
  break;
55
55
  }
56
+ } else if (resource && this.arrayField && this.predicateName) {
57
+ // if array, keep the 1rst resource
58
+ for (let res of resource[this.predicateName]) {
59
+ resource = res;
60
+ break;
61
+ }
56
62
  }
57
63
  if (!this.dataSrc) console.error(new Error('You must provide a "fields" attribute'));
58
64
  if (!resource) return [];
@@ -114,6 +120,16 @@ const WidgetMixin = {
114
120
  * @param resource - Resource
115
121
  */
116
122
  async fetchValue(field, resource) {
123
+ if (resource && !resource.isContainer?.()) {
124
+ let fieldValue = await resource[field];
125
+ if (fieldValue === null || fieldValue === undefined || fieldValue === '') return undefined;
126
+ if (Array.isArray(fieldValue) && !fieldValue['ldp:contains']) {
127
+ return JSON.stringify(fieldValue);
128
+ // Dumb edge case because if it bears only one item, when compacted the array translates into one object
129
+ } else if (typeof fieldValue === 'object' && fieldValue['@id'] && 1 === Object.keys(fieldValue).length) {
130
+ return JSON.stringify([fieldValue]);
131
+ }
132
+ }
117
133
  return resource && !resource.isContainer?.() ? await resource[field] : undefined;
118
134
  },
119
135
  /**
@@ -160,8 +176,7 @@ const WidgetMixin = {
160
176
  * @param field - string
161
177
  * @param isSet - boolean
162
178
  */
163
- getWidget(field) {
164
- let isSet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
179
+ getWidget(field, isSet = false) {
165
180
  const widget = this.element.getAttribute('widget-' + field);
166
181
  if (widget) return this.widgetFromTagName(widget);
167
182
  if (this.getAction(field)) return this.widgetFromTagName('solid-action');
@@ -223,9 +238,7 @@ const WidgetMixin = {
223
238
  * Creates and return a widget for field + add it to the widget list
224
239
  * @param field - string
225
240
  */
226
- async createWidgetTemplate(field) {
227
- let resource = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
228
- let transformAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
241
+ async createWidgetTemplate(field, resource = null, transformAttributes = false) {
229
242
  if (this.isString(field)) return this.createString(field); // field is a static string
230
243
  if (this.isSet(field)) return await this.createSet(field);
231
244
  const currentResource = resource || this.resource;
@@ -176,17 +176,14 @@ export const formTemplates = {
176
176
  ${el.label}
177
177
  </option>
178
178
  `)}
179
- ${Object.entries(attributes.enum || []).map(_ref => {
180
- let [key, val] = _ref;
181
- return html`
179
+ ${Object.entries(attributes.enum || []).map(([key, val]) => html`
182
180
  <option
183
181
  value="${key}"
184
182
  ?selected=${!attributes.multiple ? value === key : attributes.values.includes(key)}
185
183
  >
186
184
  ${val}
187
185
  </option>
188
- `;
189
- })}
186
+ `)}
190
187
  </select>
191
188
  `,
192
189
  dependencies: [FormDropdownMixin, FormMixin, RangeMixin]
@@ -207,9 +204,7 @@ export const formTemplates = {
207
204
  > <span>${el.label}</span>
208
205
  </label>
209
206
  `)}
210
- ${Object.entries(attributes.enum || []).map(_ref2 => {
211
- let [key, val] = _ref2;
212
- return html`
207
+ ${Object.entries(attributes.enum || []).map(([key, val]) => html`
213
208
  <label>
214
209
  <input
215
210
  type="radio"
@@ -219,8 +214,7 @@ export const formTemplates = {
219
214
  ?checked=${value === key}
220
215
  > <span>${val}</span>
221
216
  </label>
222
- `;
223
- })}
217
+ `)}
224
218
  `,
225
219
  dependencies: [FormRadioMixin, FormMixin, RangeMixin]
226
220
  },
@@ -238,16 +232,13 @@ export const formTemplates = {
238
232
  /> <span>${el.label}</span>
239
233
  </label>
240
234
  `)}
241
- ${Object.entries(attributes.enum || []).map(_ref3 => {
242
- let [key, val] = _ref3;
243
- return html`
235
+ ${Object.entries(attributes.enum || []).map(([key, val]) => html`
244
236
  <label>
245
237
  <input type="checkbox"
246
238
  value="${key}"
247
239
  /> <span>${val}</span>
248
240
  </label>
249
- `;
250
- })}
241
+ `)}
251
242
  </select>
252
243
  `,
253
244
  dependencies: [FormCheckboxesMixin, FormMixin, RangeMixin]
@@ -28,6 +28,9 @@ const FormDropdownMixin = {
28
28
  },
29
29
  created() {
30
30
  this.listAttributes['values'] = [];
31
+ if (this.listAttributes['value'] && !JSON.parse(this.listAttributes['value']['@id']) && Array.isArray(JSON.parse(this.listAttributes['value']))) {
32
+ this.listAttributes['values'] = this.listAttributes['value'];
33
+ }
31
34
  if (this.multiple) this.listAttributes['multiple'] = true;
32
35
  },
33
36
  dispatchChange() {
@@ -63,7 +63,16 @@ const MultipleFormMixin = {
63
63
  };
64
64
  },
65
65
  setDataSrc(value, listValueTransformations) {
66
- if (value && value !== this.dataSrc) this.dataSrc = value;
66
+ if (value && value !== this.dataSrc) {
67
+ try {
68
+ if (Array.isArray(JSON.parse(value))) {
69
+ this.setValue(JSON.parse(value));
70
+ }
71
+ } catch (ex) {
72
+ this.dataSrc = value;
73
+ console.log('Not an array', ex);
74
+ }
75
+ }
67
76
  const nextProcessor = listValueTransformations.shift();
68
77
  if (nextProcessor) nextProcessor(value, listValueTransformations);
69
78
  },
@@ -79,8 +88,7 @@ const MultipleFormMixin = {
79
88
 
80
89
  this.planRender();
81
90
  },
82
- insertWidget() {
83
- let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
91
+ insertWidget(value = '') {
84
92
  if (!this.widget) return;
85
93
  const widget = document.createElement(this.widget);
86
94
  const attributes = {
@@ -100,7 +108,12 @@ const MultipleFormMixin = {
100
108
  },
101
109
  getValue() {
102
110
  if (!this.dataHolder) return [];
103
- return Array.from(this.dataHolder).map(element => this.getValueFromElement(element));
111
+ // Was returning an array of functions, now returns an array of values.
112
+ // Not sure about the tests results in that context
113
+ return Array.from(this.dataHolder).map(element => {
114
+ let elValue = this.getValueFromElement(element);
115
+ return elValue;
116
+ });
104
117
  },
105
118
  get type() {
106
119
  return 'resource';
@@ -38,12 +38,21 @@ const MultipleselectFormMixin = {
38
38
  this.listValueTransformations.push(this.setDataSrc.bind(this));
39
39
  },
40
40
  setDataSrc(value, listValueTransformations) {
41
- if (value && value !== this.dataSrc) this.dataSrc = value;
41
+ if (value && value !== this.dataSrc) {
42
+ try {
43
+ if (Array.isArray(JSON.parse(value))) {
44
+ this.setValue(JSON.parse(value));
45
+ }
46
+ } catch (ex) {
47
+ this.dataSrc = value;
48
+ console.log('Not an array', ex);
49
+ }
50
+ }
42
51
  const nextProcessor = listValueTransformations.shift();
43
52
  if (nextProcessor) nextProcessor(value, listValueTransformations);
44
53
  },
45
54
  populate() {
46
- if (!this.resource || !this.resource['ldp:contains']) return;
55
+ if (!this.resource || !this.resource['ldp:contains'] && !Array.isArray(this.resource)) return;
47
56
  this.setValue(this.resource['ldp:contains']);
48
57
  this.planRender();
49
58
  },
@@ -4,8 +4,8 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
4
4
  import { evalTemplateString } from '../libs/helpers.js';
5
5
  import { store } from '../libs/store/store.js';
6
6
  export class BaseWidget extends HTMLElement {
7
- constructor() {
8
- super(...arguments);
7
+ constructor(...args) {
8
+ super(...args);
9
9
  _defineProperty(this, "src", void 0);
10
10
  _defineProperty(this, "multiple", void 0);
11
11
  _defineProperty(this, "editable", void 0);
@@ -155,7 +155,7 @@ export class BaseWidget extends HTMLElement {
155
155
  if (!res) {
156
156
  // child not in cache yet
157
157
  try {
158
- const resourceId = resource.getChildren()[index]['@id'];
158
+ const resourceId = resource.getChildren('ldp:contains')[index]['@id'];
159
159
  res = await store.getData(resourceId, this.context);
160
160
  } catch (e) {
161
161
  continue;
@@ -210,8 +210,7 @@ export class BaseWidget extends HTMLElement {
210
210
  subscribe(event) {
211
211
  this._listen(event);
212
212
  }
213
- _listen(id) {
214
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
213
+ _listen(id, callback = () => {}) {
215
214
  if (!this._subscriptions.get(id)) {
216
215
  this._subscriptions.set(id, PubSub.subscribe(id, async () => {
217
216
  await callback();
@@ -1,8 +1,6 @@
1
1
  import { BaseWidget } from './baseWidget.js';
2
2
  import { defineComponent } from '../libs/helpers.js';
3
- export const widgetFactory = function (tagName, customTemplate) {
4
- let childTemplate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
5
- let callback = arguments.length > 3 ? arguments[3] : undefined;
3
+ export const widgetFactory = (tagName, customTemplate, childTemplate = '', callback) => {
6
4
  const registered = customElements.get(tagName);
7
5
  if (registered) return registered;
8
6
  const cls = class extends BaseWidget {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startinblox/core",
3
- "version": "0.18.1",
3
+ "version": "0.19.0-beta.2",
4
4
  "description": "This is a series of web component respecting both the web components standards and the Linked Data Platform convention.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "snowpack build --polyfill-node",
16
- "watch": "npm run build -- --watch",
16
+ "watch": "snowpack build --polyfill-node --watch",
17
17
  "serve": "node --watch server.js",
18
18
  "dev": "concurrently -n 'WATCH,SERVE' -c 'yellow.bold,magenta.bold' 'npm run watch' 'npm run serve'",
19
19
  "check-types": "tsc",
@@ -93,6 +93,8 @@
93
93
  "express": "^4.17.1",
94
94
  "find-free-port": "^2.0.0",
95
95
  "fuse.js": "^6.4.6",
96
+ "semver": "^7.4.0",
97
+ "jsonld": "^8.3.1",
96
98
  "jsonld-context-parser": "^1.3.4",
97
99
  "leaflet": "1.7.1",
98
100
  "leaflet.markercluster": "1.5.3",
@@ -108,8 +110,7 @@
108
110
  "ts-node": "^9.1.1",
109
111
  "tui-calendar": "^1.13.0",
110
112
  "typescript": "^4.1.3",
111
- "wait-on": "^5.2.1",
112
- "semver": "^7.4.0"
113
+ "wait-on": "^5.2.1"
113
114
  },
114
115
  "dependencies": {
115
116
  "cors": "^2.8.5"
@@ -1 +0,0 @@
1
- {"version":3,"file":"_commonjsHelpers-37fa8da4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}