@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
@@ -70,8 +70,7 @@ export const SolidFormSearch = {
70
70
  });
71
71
  return values;
72
72
  },
73
- getWidget(field) {
74
- let isSet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
73
+ getWidget(field, isSet = false) {
75
74
  let tagName = '';
76
75
  // If auto-range-[field] exists, create range-[field] and sets its value
77
76
  if (this.element.hasAttribute('auto-range-' + field) && !this.element.hasAttribute('range-' + field)) {
@@ -87,8 +87,7 @@ export const SolidForm = {
87
87
  }
88
88
  return transformArrayToContainer(value);
89
89
  },
90
- getWidget(field) {
91
- let isSet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
90
+ getWidget(field, isSet = false) {
92
91
  let tagName = '';
93
92
  const widgetAttribute = this.element.getAttribute('widget-' + field);
94
93
 
@@ -163,8 +162,7 @@ export const SolidForm = {
163
162
  if (!this.isCreationForm(formValue) && this.isSavingAutomatically) this.submitForm(); // if autosave, submitForm
164
163
  },
165
164
 
166
- findErrorMessage(errors) {
167
- let errorFullName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
165
+ findErrorMessage(errors, errorFullName = '') {
168
166
  let errorsArray = [];
169
167
  errors.forEach(member => {
170
168
  let errorNextName = Object.values(member)[0];
@@ -131,10 +131,7 @@ export class ComponentFactory {
131
131
  static bindMethods(componentConstructor, methods) {
132
132
  methods.forEach((method, methodName) => {
133
133
  Reflect.defineProperty(componentConstructor.prototype, methodName, {
134
- value: function () {
135
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
136
- args[_key] = arguments[_key];
137
- }
134
+ value: function (...args) {
138
135
  return Reflect.apply(method, this, args);
139
136
  }
140
137
  });
@@ -116,7 +116,7 @@ const cacheFieldsProps = (cacheKey, filter, fields, searchForm) => {
116
116
  * @param resource - resource to test
117
117
  * @param filter - name of the property tested
118
118
  * @param query - query object to know how to compare values
119
- * @param fields - fields attribute of the element
119
+ * @param fieldsAttr - fields attribute of the element
120
120
  * @param searchForm - searchForm component
121
121
  * @param filterId - uniqId used to fill the cache
122
122
  * @param throwOn - should function throw error on True or False
@@ -7,8 +7,7 @@ function stringToDom(html) {
7
7
  template.innerHTML = html;
8
8
  return template.content;
9
9
  }
10
- async function evalTemplateString(str) {
11
- let variables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
+ async function evalTemplateString(str, variables = {}) {
12
11
  const keys = Object.keys(variables);
13
12
  const values = keys.map(key => variables[key]);
14
13
  try {
@@ -20,11 +19,8 @@ async function evalTemplateString(str) {
20
19
  throw new SyntaxError('`' + str + '`');
21
20
  }
22
21
  }
23
- function importCSS() {
22
+ function importCSS(...stylesheets) {
24
23
  const linksElements = [];
25
- for (var _len = arguments.length, stylesheets = new Array(_len), _key = 0; _key < _len; _key++) {
26
- stylesheets[_key] = arguments[_key];
27
- }
28
24
  for (let url of stylesheets) {
29
25
  url = relativeSource(url);
30
26
  let link = Array.from(document.head.querySelectorAll('link')).find(link => link.href === url);
@@ -38,10 +34,7 @@ function importCSS() {
38
34
  ;
39
35
  return linksElements;
40
36
  }
41
- function importJS() {
42
- for (var _len2 = arguments.length, plugins = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
43
- plugins[_key2] = arguments[_key2];
44
- }
37
+ function importJS(...plugins) {
45
38
  return plugins.map(url => {
46
39
  url = new URL(url, document.baseURI).href;
47
40
  let script = Array.from(document.querySelectorAll('script')).find(script => script.src === url);
@@ -169,6 +162,7 @@ function transformArrayToContainer(resource) {
169
162
  // iterate over all properties
170
163
  const predicateValue = newValue[predicate];
171
164
  if (!predicateValue || typeof predicateValue !== 'object') continue; // undefined or literal, do nothing
165
+ if (['permissions', '@context'].includes(predicate)) continue; // do not transform permissions and context
172
166
 
173
167
  // check all keys of nested resource
174
168
  if (!Array.isArray(predicateValue) && predicateValue['@id']) {
@@ -93,12 +93,9 @@ const templateStringsCache = new WeakMap();
93
93
 
94
94
  // Convert dynamic tags to template strings
95
95
  // example: <${'div'}>${'this is example'}</${'div'}> => <div>${'this is example'}</div>
96
- export function preHTML(strings) {
96
+ export function preHTML(strings, ...values) {
97
97
  // check cache !important return equal link at first argument
98
98
  let cachedStrings = templateStringsCache.get(strings);
99
- for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
100
- values[_key - 1] = arguments[_key];
101
- }
102
99
  if (cachedStrings) {
103
100
  for (let i = 0, n = cachedStrings.length; i < n; ++i) {
104
101
  const needlessValues = cachedStrings[i].needlessValues;
@@ -2,8 +2,7 @@
2
2
  if (!('flat' in Array.prototype)) {
3
3
  Object.defineProperty(Array.prototype, 'flat', {
4
4
  configurable: true,
5
- value: function flat() {
6
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
5
+ value: function flat(depth = 1) {
7
6
  depth = isNaN(depth) ? 1 : Number(depth);
8
7
  if (depth === 0) return Array.prototype.slice.call(this);
9
8
  return Array.prototype.reduce.call(this, function (acc, cur) {
@@ -21,8 +20,7 @@ if (!('flat' in Array.prototype)) {
21
20
 
22
21
  // Element.prototype.toggleAttribute
23
22
  if (!Element.prototype.toggleAttribute) {
24
- Element.prototype.toggleAttribute = function (name) {
25
- let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
23
+ Element.prototype.toggleAttribute = function (name, force = undefined) {
26
24
  if (force !== undefined) force = !!force;
27
25
  if (this.hasAttribute(name)) {
28
26
  if (force) return true;
@@ -0,0 +1,313 @@
1
+ let _Symbol$toPrimitive;
2
+ 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
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4
+ 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
+ import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js';
6
+ import { store } from './store.js';
7
+ const ContextParser = JSONLDContextParser.ContextParser;
8
+ _Symbol$toPrimitive = Symbol.toPrimitive;
9
+ export class CustomGetter {
10
+ // search attributes to give to server
11
+
12
+ constructor(resourceId, resource, clientContext, serverContext, parentId = "", serverPagination = {}, serverSearch = {}) {
13
+ _defineProperty(this, "resource", void 0);
14
+ // content of the requested resource
15
+ _defineProperty(this, "resourceId", void 0);
16
+ _defineProperty(this, "clientContext", void 0);
17
+ // context given by the app
18
+ _defineProperty(this, "serverContext", void 0);
19
+ // context given by the server
20
+ _defineProperty(this, "parentId", void 0);
21
+ // id of the parent resource, used to get the absolute url of the current resource
22
+ _defineProperty(this, "containerTypes", void 0);
23
+ // types of resources interpreted as containers
24
+ _defineProperty(this, "serverPagination", void 0);
25
+ // pagination attributes to give to server
26
+ _defineProperty(this, "serverSearch", void 0);
27
+ this.clientContext = clientContext;
28
+ this.serverContext = serverContext;
29
+ this.parentId = parentId;
30
+ this.resource = resource;
31
+ this.resourceId = resourceId;
32
+ this.serverPagination = serverPagination;
33
+ this.serverSearch = serverSearch;
34
+ this.containerTypes = [this.getExpandedPredicate("ldp:Container"), this.getExpandedPredicate("ldp:BasicContainer"), this.getExpandedPredicate("ldp:DirectContainer"), this.getExpandedPredicate("ldp:IndirectContainer"), "sib:federatedContainer"];
35
+ }
36
+
37
+ /**
38
+ * Get the property of a resource for a given path
39
+ * Which means that if the resource is not complete, it will fetch it
40
+ * And that we handle the `.` notation, traversing the path recursively
41
+ * @param path: string
42
+ */
43
+ async get(path) {
44
+ if (!path) return;
45
+
46
+ // Specific case where the predicates is a full IRI, avoid splitting it on the dot notation
47
+ try {
48
+ let isUrl = new URL(path);
49
+ // If the path is an absolute url, we need to fetch the resource
50
+ if (isUrl) {
51
+ let value = this.resource[this.getExpandedPredicate(path)];
52
+ return value ? value : undefined;
53
+ }
54
+ } catch (e) {
55
+ // Split the path on each dots
56
+ const path1 = path.split('.');
57
+
58
+ // Intermediate path var to request each resource individually until the path traversal is completed
59
+ const path2 = [];
60
+
61
+ // Actual value found from the store, if any
62
+ let value;
63
+ if (!this.isFullResource()) {
64
+ // if resource is not complete, fetch it first
65
+ await this.getResource(this.resourceId, {
66
+ ...this.clientContext,
67
+ ...this.serverContext
68
+ }, this.parentId);
69
+ }
70
+
71
+ // If the path contains dot, we need to traverse the path recursively
72
+ // We do that by poping one element from path1 at each step and affecting it to path2
73
+ // Trying to get the value from it
74
+ while (true) {
75
+ try {
76
+ value = this.resource[this.getExpandedPredicate(path1[0])];
77
+ } catch (e) {
78
+ break;
79
+ }
80
+ if (path1.length <= 1) break; // no dot path
81
+ const lastPath1El = path1.pop();
82
+ if (lastPath1El) path2.unshift(lastPath1El);
83
+ }
84
+ if (path2.length === 0) {
85
+ // end of the path
86
+ if (!value || !value['@id']) return this.getLiteralValue(value); // no value or not a resource
87
+ return await this.getResource(value['@id'], {
88
+ ...this.clientContext,
89
+ ...this.serverContext
90
+ }, this.parentId || this.resourceId); // return complete resource
91
+ }
92
+
93
+ if (!value) return undefined;
94
+ let resource = await this.getResource(value['@id'], {
95
+ ...this.clientContext,
96
+ ...this.serverContext
97
+ }, this.parentId || this.resourceId);
98
+ store.subscribeResourceTo(this.resourceId, value['@id']);
99
+ return resource ? await resource[path2.join('.')] : undefined; // return value
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Return value depending of the current language
105
+ * @param value
106
+ * @returns
107
+ */
108
+ getLiteralValue(value) {
109
+ if (typeof value === "object") {
110
+ // value object: https://www.w3.org/TR/json-ld11/#value-objects
111
+ if (value['@value']) {
112
+ // 1 language
113
+ return value['@value'];
114
+ } else if (Array.isArray(value)) {
115
+ // multiple languages
116
+ if (value.length === 0) return null;
117
+ const ln = store._getLanguage();
118
+ let translatedValue = value.find(v => v['@language'] && v['@language'] === ln); // find current language
119
+ if (!translatedValue) translatedValue = value.find(v => v['@language'] && v['@language'] === 'en'); // default to en
120
+ return translatedValue ? translatedValue['@value'] || null : null;
121
+ }
122
+ }
123
+ return value; // simple value
124
+ }
125
+
126
+ /**
127
+ * Cache resource in the store, and return the created proxy
128
+ * @param id
129
+ * @param context
130
+ * @param iriParent
131
+ */
132
+ async getResource(id, context, iriParent, forceFetch = false) {
133
+ if (id.startsWith('_:b')) return store.get(id + iriParent); // anonymous node = get from cache
134
+ return store.getData(id, context, iriParent, undefined, forceFetch);
135
+ }
136
+
137
+ /**
138
+ * Return true if the resource is a container
139
+ */
140
+ isContainer() {
141
+ if (this.resource["@type"]) {
142
+ // @type is an array
143
+ if (Array.isArray(this.resource["@type"])) return this.containerTypes.some(type => this.resource["@type"].includes(type));
144
+ return this.containerTypes.includes(this.resource["@type"]);
145
+ } else if (this.resource["type"]) {
146
+ if (Array.isArray(this.resource["type"])) return this.containerTypes.some(type => this.resource["type"].includes(type));
147
+ return this.containerTypes.includes(this.resource["type"]);
148
+ }
149
+ return false;
150
+ }
151
+
152
+ /**
153
+ * Return true if the given key in the current resource in an array
154
+ */
155
+ isArray() {
156
+ if (Array.isArray(this.resource)) return true;
157
+ return false;
158
+ }
159
+
160
+ /**
161
+ * Get all properties of a resource
162
+ */
163
+ getProperties() {
164
+ return Object.keys(this.resource).map(prop => this.getCompactedPredicate(prop));
165
+ }
166
+
167
+ /**
168
+ * Get children of container as objects
169
+ */
170
+ getChildren(predicateName) {
171
+ return this.resource[this.getExpandedPredicate(predicateName)] || [];
172
+ }
173
+
174
+ /**
175
+ * Get children of container as Proxys
176
+ */
177
+ getLdpContains() {
178
+ let children = this.resource[this.getExpandedPredicate("ldp:contains")];
179
+ if (!children) return null;
180
+ if (!Array.isArray(children)) children = [children]; // convert to array if compacted to 1 resource
181
+
182
+ let result = children ? children.map(res => {
183
+ let resource = store.get(res['@id']);
184
+ if (resource) return resource;
185
+
186
+ // if not in cache, generate the basic resource
187
+ resource = new CustomGetter(res['@id'], {
188
+ '@id': res['@id']
189
+ }, this.clientContext, this.serverContext, this.parentId).getProxy();
190
+ store.cacheResource(res['@id'], resource); // put it in cache
191
+ return resource; // and return it
192
+ }) : [];
193
+ return result;
194
+ }
195
+ merge(resource) {
196
+ this.resource = {
197
+ ...this.getResourceData(),
198
+ ...resource.getResourceData()
199
+ };
200
+ }
201
+ getResourceData() {
202
+ return this.resource;
203
+ }
204
+
205
+ /**
206
+ * return true resource seems complete
207
+ * @param prop
208
+ */
209
+ isFullResource() {
210
+ return Object.keys(this.resource).filter(p => !p.startsWith('@')).length > 0 // has some properties
211
+ || this.resource['@id'].startsWith('_:b'); // anonymous node = always full resource
212
+ }
213
+
214
+ /**
215
+ * Get permissions of a resource
216
+ * @param resourceId
217
+ * @returns
218
+ */
219
+ async getPermissions() {
220
+ let permissionsIds = this.resource[this.getExpandedPredicate("permissions")];
221
+ if (!permissionsIds) {
222
+ // if no permission, re-fetch data from store
223
+ await this.getResource(this.resourceId, {
224
+ ...this.clientContext,
225
+ ...this.serverContext
226
+ }, this.parentId, true);
227
+ permissionsIds = this.resource[this.getExpandedPredicate("permissions")];
228
+ }
229
+ if (!permissionsIds) return [];
230
+ if (!Array.isArray(permissionsIds)) permissionsIds = [permissionsIds]; // convert to array if compacted to 1 resource
231
+ const permissions = await Promise.all(permissionsIds.map(p => store.get(p['@id'] + this.parentId)) // get anonymous node from store
232
+ .map(p => p ? p['mode.@type'] : ''));
233
+ return permissions ? permissions.map(perm => ContextParser.expandTerm(perm, this.serverContext, true)) : [];
234
+ }
235
+
236
+ /**
237
+ * returns compacted @type of resource
238
+ */
239
+ getType() {
240
+ return this.resource['@type'] ? this.getCompactedIri(this.resource['@type']) : '';
241
+ }
242
+
243
+ /**
244
+ * Remove the resource from the cache
245
+ */
246
+ clearCache() {
247
+ store.clearCache(this.resourceId);
248
+ }
249
+ getExpandedPredicate(property) {
250
+ return ContextParser.expandTerm(property, {
251
+ ...this.clientContext,
252
+ ...this.serverContext
253
+ }, true);
254
+ }
255
+ getCompactedPredicate(property) {
256
+ return ContextParser.compactIri(property, {
257
+ ...this.clientContext,
258
+ ...this.serverContext
259
+ }, true);
260
+ }
261
+ getCompactedIri(id) {
262
+ return ContextParser.compactIri(id, {
263
+ ...this.clientContext,
264
+ ...this.serverContext
265
+ });
266
+ }
267
+ toString() {
268
+ return this.getCompactedIri(this.resource['@id']);
269
+ }
270
+ [_Symbol$toPrimitive]() {
271
+ return this.getCompactedIri(this.resource['@id']);
272
+ }
273
+
274
+ /**
275
+ * Returns a Proxy which handles the different get requests
276
+ */
277
+ getProxy() {
278
+ return new Proxy(this, {
279
+ get: (resource, property) => {
280
+ if (!this.resource) return undefined;
281
+ if (typeof resource[property] === 'function') return resource[property].bind(resource);
282
+ switch (property) {
283
+ case '@id':
284
+ if (this.resource['@id']) return this.getCompactedIri(this.resource['@id']); // Compact @id if possible
285
+ else console.log(this.resource, this.resource['@id']);
286
+ return;
287
+ case '@type':
288
+ return this.resource['@type'];
289
+ // return synchronously
290
+ case 'properties':
291
+ return this.getProperties();
292
+ case 'ldp:contains':
293
+ return this.getLdpContains();
294
+ // returns standard arrays synchronously
295
+ case 'permissions':
296
+ return this.getPermissions();
297
+ // get expanded permissions
298
+ case 'clientContext':
299
+ return this.clientContext;
300
+ // get saved client context to re-fetch easily a resource
301
+ case 'serverContext':
302
+ return this.serverContext;
303
+ // get saved client context to re-fetch easily a resource
304
+ case 'then':
305
+ return;
306
+ default:
307
+ // FIXME: missing 'await'
308
+ return resource.get(property);
309
+ }
310
+ }
311
+ });
312
+ }
313
+ }
@@ -1,11 +1,8 @@
1
1
  export function formatAttributesToServerPaginationOptions(elementAttributes) {
2
- const attributes = new Map(Array.from(elementAttributes).map(_ref => {
3
- let {
4
- name,
5
- value
6
- } = _ref;
7
- return [name, value];
8
- }));
2
+ const attributes = new Map(Array.from(elementAttributes).map(({
3
+ name,
4
+ value
5
+ }) => [name, value]));
9
6
  const limit = attributes.get('limit');
10
7
  const offset = attributes.get('offset');
11
8
  if (!offset || !limit) return;
@@ -1,11 +1,8 @@
1
1
  export function formatAttributesToServerSearchOptions(elementAttributes) {
2
- const attributes = new Map(Array.from(elementAttributes).map(_ref => {
3
- let {
4
- name,
5
- value
6
- } = _ref;
7
- return [name, value];
8
- }));
2
+ const attributes = new Map(Array.from(elementAttributes).map(({
3
+ name,
4
+ value
5
+ }) => [name, value]));
9
6
  const fields = attributes.get('server-search-fields')?.split(",").map(field => field.trim());
10
7
  const value = attributes.get('server-search-value')?.trim();
11
8
  const method = attributes.get('server-search-method')?.trim();