@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,10 +1,11 @@
1
- let _Symbol$toPrimitive;
2
1
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
2
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4
3
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
4
  import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
6
5
  //@ts-ignore
7
6
  import PubSub from 'https://cdn.skypack.dev/pubsub-js';
7
+ import jsonld from '../../_snowpack/pkg/jsonld.js';
8
+ import { CustomGetter } from './custom-getter.js';
8
9
  import { appendServerSearchToIri } from './server-search.js';
9
10
  import { appendServerPaginationToIri } from './server-pagination.js';
10
11
  const ContextParser = JSONLDContextParser.ContextParser;
@@ -67,18 +68,13 @@ class Store {
67
68
  * @param forceFetch - force the fetch of data
68
69
  * @param serverPagination - Server pagination options
69
70
  * @param serverSearch - Server search options
70
- *
71
+ * @param predicateName - predicate name if we target a specific predicate from the resource, useful for arrays
72
+ *
71
73
  * @returns The fetched resource
72
74
  *
73
75
  * @async
74
76
  */
75
- async getData(id) {
76
- let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
77
- let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
78
- let localData = arguments.length > 3 ? arguments[3] : undefined;
79
- let forceFetch = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
80
- let serverPagination = arguments.length > 5 ? arguments[5] : undefined;
81
- let serverSearch = arguments.length > 6 ? arguments[6] : undefined;
77
+ async getData(id, context = {}, parentId = "", localData, forceFetch = false, serverPagination, serverSearch) {
82
78
  let key = id;
83
79
  if (serverPagination) {
84
80
  key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
@@ -114,9 +110,9 @@ class Store {
114
110
  return;
115
111
  }
116
112
  const serverContext = await myParser.parse([resource['@context'] || {}]);
117
- const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
113
+ // const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch).getProxy();
118
114
  // Cache proxy
119
- await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
115
+ await this.cacheGraph(resource, clientContext, serverContext, parentId ? parentId : key, serverPagination, serverSearch);
120
116
  this.loadingList.delete(key);
121
117
  document.dispatchEvent(new CustomEvent('resourceReady', {
122
118
  detail: {
@@ -144,11 +140,17 @@ class Store {
144
140
  });
145
141
  }
146
142
  }
147
- async fetchData(id) {
148
- let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
149
- let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
150
- let serverPagination = arguments.length > 3 ? arguments[3] : undefined;
151
- let serverSearch = arguments.length > 4 ? arguments[4] : undefined;
143
+
144
+ /**
145
+ * Fetch resource
146
+ * @param id - id of the resource
147
+ * @param context - context used to expand id
148
+ * @param idParent - id of the caller resource. Needed to expand id
149
+ * @param serverPagination - Server pagination query params
150
+ * @param serverSearch - Server search query params
151
+ * @returns data in json
152
+ */
153
+ async fetchData(id, context = {}, parentId = "", serverPagination, serverSearch) {
152
154
  let iri = this._getAbsoluteIri(id, context, parentId);
153
155
  if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
154
156
  if (serverSearch) iri = appendServerSearchToIri(iri, serverSearch);
@@ -158,6 +160,12 @@ class Store {
158
160
  // 'Prefer' : 'return=representation; max-triple-count="100"' // Commenting out for now as it raises CORS errors
159
161
  };
160
162
 
163
+ /**
164
+ * Fetch data with authentication if available (sib-auth)
165
+ * @param iri - iri to call
166
+ * @param options - options of the request
167
+ * @returns - response
168
+ */
161
169
  return this.fetchAuthn(iri, {
162
170
  method: 'GET',
163
171
  headers: headers,
@@ -167,59 +175,51 @@ class Store {
167
175
  return response.json();
168
176
  });
169
177
  }
170
- async cacheGraph(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
171
- if (resource.properties) {
172
- // if proxy, cache it
173
- if (this.get(key) && this.cache.get(key).merge) {
178
+
179
+ /**
180
+ * Cache the whole graph
181
+ * @param resource - graph fetched
182
+ * @param clientContext - context of the client app
183
+ * @param parentContext - context of the server
184
+ * @param parentId - id of the parent caller
185
+ * @param serverPagination - Server pagination query params
186
+ * @param serverSearch - Server search query params
187
+ */
188
+ async cacheGraph(resource, clientContext, parentContext, parentId, serverPagination, serverSearch) {
189
+ const flattenedResources = await jsonld.flatten(resource);
190
+ const compactedResources = await Promise.all(flattenedResources.map(r => jsonld.compact(r, {})));
191
+ for (let resource of compactedResources) {
192
+ let id = resource['@id'] || resource['id'];
193
+ let key = resource['@id'] || resource['id'];
194
+ if (!key) console.log('No key or id for resource:', resource);
195
+ if (key === '/') key = parentId;
196
+ if (key.startsWith('_:b')) key = key + parentId; // anonymous node -> change key before saving in cache
197
+
198
+ // We have to add the server search and pagination attributes again here to the resource cache key
199
+ if (key === id && resource['@type'] == this.getExpandedPredicate("ldp:Container", clientContext)) {
200
+ // Add only pagination and search params to the original resource
201
+ if (serverPagination) key = key + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
202
+ if (serverSearch) key = appendServerSearchToIri(key, serverSearch);
203
+ }
204
+ const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId, serverPagination, serverSearch).getProxy();
205
+ if (resourceProxy.isContainer()) this.subscribeChildren(resourceProxy, id);
206
+ if (this.get(key)) {
174
207
  // if already cached, merge data
175
- this.cache.get(key).merge(resource);
176
- ;
208
+ this.cache.get(key).merge(resourceProxy);
177
209
  } else {
178
210
  // else, put in cache
179
- this.cache.set(key, resource);
211
+ this.cacheResource(key, resourceProxy);
180
212
  }
181
213
  }
214
+ }
182
215
 
183
- // Cache nested resources
184
- if (resource.getSubObjects) {
185
- for (let res of resource.getSubObjects()) {
186
- let newParentContext = parentContext;
187
- // If additional context in resource, use it to expand properties
188
- if (res['@context']) newParentContext = await myParser.parse({
189
- ...parentContext,
190
- ...res['@context']
191
- });
192
- const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy();
193
- // this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates
194
- await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId, serverPagination, serverSearch);
195
- }
196
- }
197
-
198
- // Cache children of container
199
- if (resource['@type'] == "ldp:Container" && resource.getChildren) {
200
- const cacheChildrenPromises = [];
201
-
202
- //TODO: return complete object without the need for the fetch data from the cacheGraph
203
- for (let res of await resource.getChildren()) {
204
- this.subscribeResourceTo(resource['@id'], res['@id']);
205
- cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId, serverPagination, serverSearch));
206
- }
207
- await Promise.all(cacheChildrenPromises);
208
- return;
209
- }
210
-
211
- // Create proxy, (fetch data) and cache resource
212
- if (resource['@id'] && !resource.properties) {
213
- if (resource['@id'].match(/^b\d+$/)) return; // not anonymous node
214
- // Fetch data if
215
- if (resource['@type'] === "sib:federatedContainer" && resource['@cache'] !== 'false') {
216
- // if object is federated container
217
- await this.getData(resource['@id'], clientContext, parentId); // then init graph
218
- return;
219
- }
220
- const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId).getProxy();
221
- await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);
222
- }
216
+ /**
217
+ * Put proxy in cache
218
+ * @param key
219
+ * @param resourceProxy
220
+ */
221
+ cacheResource(key, resourceProxy) {
222
+ this.cache.set(key, resourceProxy);
223
223
  }
224
224
 
225
225
  /**
@@ -247,6 +247,25 @@ class Store {
247
247
  ok: true
248
248
  };
249
249
  }
250
+
251
+ /**
252
+ * Subscribe all the children of a container to its parent
253
+ * @param container
254
+ */
255
+ subscribeChildren(container, containerId) {
256
+ if (!container['ldp:contains']) return;
257
+ for (let res of container['ldp:contains']) {
258
+ this.subscribeResourceTo(containerId, res['@id'] || res['id']);
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Update a resource
264
+ * @param method - can be POST, PUT or PATCH
265
+ * @param resource - content of the updated resource
266
+ * @param id - id of the resource to update
267
+ * @returns void
268
+ */
250
269
  async _updateResource(method, resource, id) {
251
270
  if (!['POST', 'PUT', 'PATCH', '_LOCAL'].includes(method)) throw new Error('Error: method not allowed');
252
271
  const context = await myParser.parse([resource['@context'] || {}]); // parse context before expandTerm
@@ -287,13 +306,10 @@ class Store {
287
306
  for (const resource of resourceWithContexts) {
288
307
  if (!this._isLocalId(resource.id)) this.clearCache(resource.id);
289
308
  }
290
- await Promise.all(resourceWithContexts.map(_ref => {
291
- let {
292
- id,
293
- context
294
- } = _ref;
295
- return this.getData(id, context || base_context);
296
- }));
309
+ await Promise.all(resourceWithContexts.map(({
310
+ id,
311
+ context
312
+ }) => this.getData(id, context || base_context)));
297
313
  return resourceIds;
298
314
  }
299
315
  /**
@@ -437,8 +453,7 @@ class Store {
437
453
  *
438
454
  * @returns id of the deleted resource
439
455
  */
440
- async delete(id) {
441
- let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
456
+ async delete(id, context = {}) {
442
457
  const expandedId = this._getExpandedId(id, context);
443
458
  const deleted = await this.fetchAuthn(expandedId, {
444
459
  method: 'DELETE',
@@ -468,6 +483,9 @@ class Store {
468
483
  _getExpandedId(id, context) {
469
484
  return context && Object.keys(context) ? ContextParser.expandTerm(id, context) : id;
470
485
  }
486
+ getExpandedPredicate(property, context) {
487
+ return ContextParser.expandTerm(property, context, true);
488
+ }
471
489
  _isLocalId(id) {
472
490
  return id.startsWith('store://local.');
473
491
  }
@@ -500,7 +518,7 @@ class Store {
500
518
  */
501
519
  _getAbsoluteIri(id, context, parentId) {
502
520
  let iri = ContextParser.expandTerm(id, context); // expand if reduced ids
503
- if (parentId) {
521
+ if (parentId && !parentId.startsWith('store://local')) {
504
522
  // and get full URL from parent caller for local files
505
523
  let parentIri = new URL(parentId, document.location.href).href;
506
524
  iri = new URL(iri, parentIri).href;
@@ -510,14 +528,6 @@ class Store {
510
528
  return iri;
511
529
  }
512
530
 
513
- /**
514
- * Check if object is a full resource
515
- * @param resource
516
- */
517
- _resourceIsComplete(resource) {
518
- return !!(Object.keys(resource).filter(p => !p.startsWith('@')).length > 0 && resource['@id']);
519
- }
520
-
521
531
  /**
522
532
  * Return language of the users
523
533
  */
@@ -547,265 +557,4 @@ if (window.sibStore) {
547
557
  store = new Store(storeOptions);
548
558
  window.sibStore = store;
549
559
  }
550
- export { store };
551
- _Symbol$toPrimitive = Symbol.toPrimitive;
552
- class CustomGetter {
553
- // search attributes to give to server
554
-
555
- constructor(resourceId, resource, clientContext, serverContext) {
556
- let parentId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
557
- let serverPagination = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
558
- let serverSearch = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
559
- _defineProperty(this, "resource", void 0);
560
- // content of the requested resource
561
- _defineProperty(this, "resourceId", void 0);
562
- _defineProperty(this, "clientContext", void 0);
563
- // context given by the app
564
- _defineProperty(this, "serverContext", void 0);
565
- // context given by the server
566
- _defineProperty(this, "parentId", void 0);
567
- // id of the parent resource, used to get the absolute url of the current resource
568
- _defineProperty(this, "serverPagination", void 0);
569
- // pagination attributes to give to server
570
- _defineProperty(this, "serverSearch", void 0);
571
- this.clientContext = clientContext;
572
- this.serverContext = serverContext;
573
- this.parentId = parentId;
574
- this.resource = this.expandProperties({
575
- ...resource
576
- }, serverContext);
577
- this.resourceId = resourceId;
578
- this.serverPagination = serverPagination;
579
- this.serverSearch = serverSearch;
580
- }
581
-
582
- /**
583
- * Expand all predicates of a resource with a given context
584
- * @param resource: object
585
- * @param context: object
586
- */
587
- expandProperties(resource, context) {
588
- for (let prop of Object.keys(resource)) {
589
- if (!prop) continue;
590
- this.objectReplaceProperty(resource, prop, ContextParser.expandTerm(prop, context, true));
591
- }
592
- return resource;
593
- }
594
-
595
- /**
596
- * Change the key of an object
597
- * @param object: object
598
- * @param oldProp: string - current key
599
- * @param newProp: string - new key to set
600
- */
601
- objectReplaceProperty(object, oldProp, newProp) {
602
- if (newProp !== oldProp) {
603
- Object.defineProperty(object, newProp, Object.getOwnPropertyDescriptor(object, oldProp) || '');
604
- delete object[oldProp];
605
- }
606
- }
607
-
608
- /**
609
- * Get the property of a resource for a given path
610
- * @param path: string
611
- */
612
- async get(path) {
613
- if (!path) return;
614
- const path1 = path.split('.');
615
- const path2 = [];
616
- let value;
617
- if (!this.isFullResource()) {
618
- // if resource is not complete, fetch it first
619
- await this.getResource(this.resourceId, {
620
- ...this.clientContext,
621
- ...this.serverContext
622
- }, this.parentId);
623
- }
624
- while (true) {
625
- try {
626
- value = this.resource[this.getExpandedPredicate(path1[0])];
627
- } catch (e) {
628
- break;
629
- }
630
- if (path1.length <= 1) break; // no dot path
631
- const lastPath1El = path1.pop();
632
- if (lastPath1El) path2.unshift(lastPath1El);
633
- }
634
- if (path2.length === 0) {
635
- // end of the path
636
- if (!value || !value['@id']) return value; // no value or not a resource
637
- return await this.getResource(value['@id'], {
638
- ...this.clientContext,
639
- ...this.serverContext
640
- }, this.parentId || this.resourceId); // return complete resource
641
- }
642
-
643
- if (!value) return undefined;
644
- let resource = await this.getResource(value['@id'], {
645
- ...this.clientContext,
646
- ...this.serverContext
647
- }, this.parentId || this.resourceId);
648
- store.subscribeResourceTo(this.resourceId, value['@id']);
649
- return resource ? await resource[path2.join('.')] : undefined; // return value
650
- }
651
-
652
- /**
653
- * Cache resource in the store, and return the created proxy
654
- * @param id
655
- * @param context
656
- * @param iriParent
657
- * @param forceFetch
658
- */
659
- async getResource(id, context, iriParent) {
660
- let forceFetch = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
661
- return store.getData(id, context, iriParent, undefined, forceFetch);
662
- }
663
-
664
- /**
665
- * Return true if the resource is a container
666
- */
667
- isContainer() {
668
- return this.resource["@type"] == "ldp:Container" || this.resource["@type"] == "sib:federatedContainer";
669
- }
670
-
671
- /**
672
- * Get all properties of a resource
673
- */
674
- getProperties() {
675
- return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));
676
- }
677
-
678
- /**
679
- * Get children of container as objects
680
- */
681
- getChildren() {
682
- return this.resource[this.getExpandedPredicate("ldp:contains")] || [];
683
- }
684
-
685
- /**
686
- * Get children of container as Proxys
687
- */
688
- getLdpContains() {
689
- const children = this.resource[this.getExpandedPredicate("ldp:contains")];
690
- return children ? children.map(res => store.get(res['@id'])) : [];
691
- }
692
-
693
- /**
694
- * Get all nested resource or containers which contains datas
695
- */
696
- getSubObjects() {
697
- let subObjects = [];
698
- for (let p of Object.keys(this.resource)) {
699
- let property = this.resource[p];
700
- if (!this.isFullNestedResource(property)) continue; // if not a resource, stop
701
- if (property['@type'] == "ldp:Container" && (property['ldp:contains'] == undefined || property['ldp:contains'].length >= 1 && !this.isFullNestedResource(property['ldp:contains'][0]))) continue; // if not a full container
702
- subObjects.push(property);
703
- }
704
- return subObjects;
705
- }
706
- merge(resource) {
707
- this.resource = {
708
- ...this.getResourceData(),
709
- ...resource.getResourceData()
710
- };
711
- }
712
- getResourceData() {
713
- return this.resource;
714
- }
715
-
716
- /**
717
- * return true if prop is a resource with an @id and some properties
718
- * @param prop
719
- */
720
- isFullNestedResource(prop) {
721
- return prop && typeof prop == "object" && prop['@id'] != undefined && Object.keys(prop).filter(p => !p.startsWith('@')).length > 0;
722
- }
723
- /**
724
- * return true resource seems complete
725
- * @param prop
726
- */
727
- isFullResource() {
728
- return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0;
729
- }
730
- async getPermissions() {
731
- const permissionPredicate = this.getExpandedPredicate("permissions");
732
- let permissions = this.resource[permissionPredicate];
733
- if (!permissions) {
734
- // if no permission, re-fetch data
735
- await this.getResource(this.resourceId, {
736
- ...this.clientContext,
737
- ...this.serverContext
738
- }, this.parentId, true);
739
- permissions = this.resource[permissionPredicate];
740
- }
741
- return permissions ? permissions.map(perm => ContextParser.expandTerm(perm.mode['@type'], this.serverContext, true)) : [];
742
- }
743
-
744
- /**
745
- * Remove the resource from the cache
746
- */
747
- clearCache() {
748
- store.clearCache(this.resourceId);
749
- }
750
- getExpandedPredicate(property) {
751
- return ContextParser.expandTerm(property, {
752
- ...this.clientContext,
753
- ...this.serverContext
754
- }, true);
755
- }
756
- getCompactedPredicate(property) {
757
- return ContextParser.compactIri(property, {
758
- ...this.clientContext,
759
- ...this.serverContext
760
- }, true);
761
- }
762
- getCompactedIri(id) {
763
- return ContextParser.compactIri(id, {
764
- ...this.clientContext,
765
- ...this.serverContext
766
- });
767
- }
768
- toString() {
769
- return this.getCompactedIri(this.resource['@id']);
770
- }
771
- [_Symbol$toPrimitive]() {
772
- return this.getCompactedIri(this.resource['@id']);
773
- }
774
-
775
- /**
776
- * Returns a Proxy which handles the different get requests
777
- */
778
- getProxy() {
779
- return new Proxy(this, {
780
- get: (resource, property) => {
781
- if (!this.resource) return undefined;
782
- if (typeof resource[property] === 'function') return resource[property].bind(resource);
783
- switch (property) {
784
- case '@id':
785
- if (this.resource['@id']) return this.getCompactedIri(this.resource['@id']); // Compact @id if possible
786
- else console.log(this.resource, this.resource['@id']);
787
- return;
788
- case '@type':
789
- return this.resource['@type'];
790
- // return synchronously
791
- case 'properties':
792
- return this.getProperties();
793
- case 'ldp:contains':
794
- return this.getLdpContains();
795
- // returns standard arrays synchronously
796
- case 'permissions':
797
- return this.getPermissions();
798
- // get expanded permissions
799
- case 'clientContext':
800
- return this.clientContext;
801
- // get saved client context to re-fetch easily a resource
802
- case 'then':
803
- return;
804
- default:
805
- // FIXME: missing 'await'
806
- return resource.get(property);
807
- }
808
- }
809
- });
810
- }
811
- }
560
+ export { store };
@@ -20,8 +20,7 @@ const AttributeBinderMixin = {
20
20
  * Replace store://XXX attributes by corresponding data
21
21
  * @param reset - set to false if no need to reset data
22
22
  */
23
- async replaceAttributesData() {
24
- let reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23
+ async replaceAttributesData(reset = true) {
25
24
  if (reset) this.resetAttributesData();
26
25
  const oldAttributes = Array.from(this.element.attributes) // transform NamedNodeMap in object
27
26
  .reduce((obj, attr) => {
@@ -59,7 +58,7 @@ const AttributeBinderMixin = {
59
58
  const value = attributes[attr];
60
59
  // Avoid error if value is a number
61
60
  if (typeof value === 'string') {
62
- // Replace attribute value
61
+ // Replace attribute value
63
62
  if (!isContainer && resource && value.startsWith('store://resource')) {
64
63
  // RESOURCE
65
64
  let path = value.replace('store://resource.', '');
@@ -98,9 +97,7 @@ const AttributeBinderMixin = {
98
97
  * @param maxRetries
99
98
  * @returns
100
99
  */
101
- async retry(fn) {
102
- let ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
103
- let maxRetries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5;
100
+ async retry(fn, ms = 200, maxRetries = 5) {
104
101
  return new Promise((resolve, reject) => {
105
102
  let retries = 0;
106
103
  fn().then(resolve).catch(() => {
@@ -17,6 +17,7 @@ const FederationMixin = {
17
17
  if (nextProcessor) await nextProcessor(newResources, listPostProcessors, div, context);
18
18
  },
19
19
  async getResources(resources) {
20
+ if (!resources) return [];
20
21
  const newResources = [];
21
22
  const getChildResources = async res => {
22
23
  if (!res) return;
@@ -29,11 +30,16 @@ const FederationMixin = {
29
30
  const resourcesFetched = await this.fetchSource(containerId); // fetch the resources of this container
30
31
  if (resourcesFetched) newResources.push(...(await this.getResources(resourcesFetched))); // Add content of source to array...
31
32
  }
33
+ } else if (!res.isArray?.()) {
34
+ const resource = await store.getData(res['@id'], this.context);
35
+ if (resource) newResources.push(resource);
32
36
  } else {
33
37
  newResources.push(res); // Or resource directly if not a container
34
38
  }
35
39
  };
36
40
 
41
+ // Special case for list support, if there is only one item it is serialized as an object, not an array
42
+ if (!Array.isArray(resources)) resources = [resources];
37
43
  await Promise.all(resources.map(res => getChildResources(res)));
38
44
  return newResources;
39
45
  },
@@ -67,12 +67,9 @@ const FilterMixin = {
67
67
  const filters = this.filters;
68
68
  if (this.isFilteredOnServer() && filters) {
69
69
  const fields = Object.keys(filters);
70
- const value = Object.values(filters).map(_ref => {
71
- let {
72
- value
73
- } = _ref;
74
- return value;
75
- }).filter(value => !!value).join(' ').trim();
70
+ const value = Object.values(filters).map(({
71
+ value
72
+ }) => value).filter(value => !!value).join(' ').trim();
76
73
  if (fields.length > 0 && value) {
77
74
  return {
78
75
  fields,
@@ -109,14 +106,15 @@ const FilterMixin = {
109
106
  console.warn(`The format value of ${field} is not suitable with auto-range-[field] attribute`);
110
107
  continue;
111
108
  }
112
- const nextArrayOfIds = nextArrayOfObjects['ldp:contains'];
113
- for (const obj of nextArrayOfIds) {
114
- // catch each element id
115
- arrayOfDataIds.push(obj['@id']);
116
- }
117
109
  if (nextArrayOfObjects['@type'] !== 'ldp:Container') {
118
110
  // if no element in 'ldp:contains', catch object id
119
111
  arrayOfDataIds.push(nextArrayOfObjects['@id']);
112
+ } else {
113
+ if (!nextArrayOfObjects['ldp:contains']) continue;
114
+ for (const obj of nextArrayOfObjects['ldp:contains']) {
115
+ // catch each element id
116
+ arrayOfDataIds.push(obj['@id']);
117
+ }
120
118
  }
121
119
  }
122
120
  return arrayOfDataIds;
@@ -141,11 +139,10 @@ const FilterMixin = {
141
139
  name: attr['name'].replace('search-', ''),
142
140
  value: attr['value']
143
141
  }));
144
- searchAttributes.forEach(_ref2 => {
145
- let {
146
- name,
147
- value
148
- } = _ref2;
142
+ searchAttributes.forEach(({
143
+ name,
144
+ value
145
+ }) => {
149
146
  this.searchForm.setAttribute(name, value);
150
147
  });
151
148
  this.element.insertBefore(this.searchForm, this.element.firstChild);
@@ -43,21 +43,32 @@ const ListMixin = {
43
43
  if (!this.resource) return;
44
44
 
45
45
  // Not a container but a single resource
46
- if (!this.resource.isContainer?.()) {
46
+ if (!this.resource.isContainer?.() && !this.arrayField && !this.predicateName) {
47
47
  this.setElementAttribute("resource");
48
48
  this.appendSingleElt(div);
49
49
  return;
50
50
  }
51
- this.setElementAttribute("container");
52
- const listPostProcessors = [...this.listPostProcessors];
53
- this.renderCallbacks = [];
54
- listPostProcessors.push(this.renderDOM.bind(this));
55
- listPostProcessors.push(this.handleEmptyWidget.bind(this));
51
+ if (this.resource.isContainer?.()) {
52
+ this.setElementAttribute("container");
53
+ const listPostProcessors = [...this.listPostProcessors];
54
+ this.renderCallbacks = [];
55
+ listPostProcessors.push(this.renderDOM.bind(this));
56
+ listPostProcessors.push(this.handleEmptyWidget.bind(this));
56
57
 
57
- // Execute the first post-processor of the list
58
- const nextProcessor = listPostProcessors.shift();
59
- await nextProcessor(this.resource['ldp:contains'], listPostProcessors, div, this.dataSrc);
58
+ // Execute the first post-processor of the list
59
+ const nextProcessor = listPostProcessors.shift();
60
+ await nextProcessor(this.resource['ldp:contains'], listPostProcessors, div, this.dataSrc);
61
+ } else if (this.arrayField && this.predicateName && this.resource[this.predicateName]) {
62
+ this.setElementAttribute("container");
63
+ const listPostProcessors = [...this.listPostProcessors];
64
+ this.renderCallbacks = [];
65
+ listPostProcessors.push(this.renderDOM.bind(this));
66
+ listPostProcessors.push(this.handleEmptyWidget.bind(this));
60
67
 
68
+ // Execute the first post-processor of the list
69
+ const nextProcessor = listPostProcessors.shift();
70
+ await nextProcessor(await this.resource[this.predicateName], listPostProcessors, div, this.dataSrc);
71
+ }
61
72
  // Execute the render callbacks
62
73
  for (const renderCallback of this.renderCallbacks) {
63
74
  // Render the template in the given parent element