@startinblox/core 0.18.0-beta.3 → 0.18.0-beta.4

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 +344 -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 -343
  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 +12 -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 +7 -3
  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 +4 -2
  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,10 @@ 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 (Array.isArray(fieldValue) && !fieldValue['ldp:contains']) return JSON.stringify(fieldValue);
126
+ }
117
127
  return resource && !resource.isContainer?.() ? await resource[field] : undefined;
118
128
  },
119
129
  /**
@@ -160,8 +170,7 @@ const WidgetMixin = {
160
170
  * @param field - string
161
171
  * @param isSet - boolean
162
172
  */
163
- getWidget(field) {
164
- let isSet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
173
+ getWidget(field, isSet = false) {
165
174
  const widget = this.element.getAttribute('widget-' + field);
166
175
  if (widget) return this.widgetFromTagName(widget);
167
176
  if (this.getAction(field)) return this.widgetFromTagName('solid-action');
@@ -223,9 +232,7 @@ const WidgetMixin = {
223
232
  * Creates and return a widget for field + add it to the widget list
224
233
  * @param field - string
225
234
  */
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;
235
+ async createWidgetTemplate(field, resource = null, transformAttributes = false) {
229
236
  if (this.isString(field)) return this.createString(field); // field is a static string
230
237
  if (this.isSet(field)) return await this.createSet(field);
231
238
  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() {
@@ -79,8 +79,7 @@ const MultipleFormMixin = {
79
79
 
80
80
  this.planRender();
81
81
  },
82
- insertWidget() {
83
- let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
82
+ insertWidget(value = '') {
84
83
  if (!this.widget) return;
85
84
  const widget = document.createElement(this.widget);
86
85
  const attributes = {
@@ -100,7 +99,12 @@ const MultipleFormMixin = {
100
99
  },
101
100
  getValue() {
102
101
  if (!this.dataHolder) return [];
103
- return Array.from(this.dataHolder).map(element => this.getValueFromElement(element));
102
+ // Was returning an array of functions, now returns an array of values.
103
+ // Not sure about the tests results in that context
104
+ return Array.from(this.dataHolder).map(element => {
105
+ let elValue = this.getValueFromElement(element);
106
+ return elValue;
107
+ });
104
108
  },
105
109
  get type() {
106
110
  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.0-beta.3",
3
+ "version": "0.18.0-beta.4",
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.5.4",
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",
@@ -1 +0,0 @@
1
- {"version":3,"file":"_commonjsHelpers-37fa8da4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}