@startinblox/core 0.19.0-beta.2 → 0.19.0-beta.21

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 (166) hide show
  1. package/dist/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css → assets/MarkerCluster-614dea0a.css} +0 -0
  2. package/dist/{_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css → assets/MarkerCluster.Default-61258232.css} +0 -0
  3. package/dist/assets/en-e53105c5.js +14 -0
  4. package/dist/assets/en-e53105c5.js.map +1 -0
  5. package/dist/assets/fr-a7fcdb64.js +14 -0
  6. package/dist/assets/fr-a7fcdb64.js.map +1 -0
  7. package/dist/{_snowpack/pkg/fusejs.js → assets/helpers-411e08e4.js} +499 -454
  8. package/dist/assets/helpers-411e08e4.js.map +1 -0
  9. package/dist/{_snowpack/pkg/leaflet/dist/leaflet.css → assets/leaflet-3c081932.css} +3 -3
  10. package/dist/helpers.js +22 -0
  11. package/dist/helpers.js.map +1 -0
  12. package/dist/index.js +54873 -48
  13. package/dist/index.js.map +1 -0
  14. package/package.json +7 -22
  15. package/dist/_snowpack/pkg/autolinker.js +0 -4429
  16. package/dist/_snowpack/pkg/autolinker.js.map +0 -1
  17. package/dist/_snowpack/pkg/common/_baseUnary-d2677655.js +0 -353
  18. package/dist/_snowpack/pkg/common/_baseUnary-d2677655.js.map +0 -1
  19. package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js +0 -26
  20. package/dist/_snowpack/pkg/common/_commonjsHelpers-0597c316.js.map +0 -1
  21. package/dist/_snowpack/pkg/common/decode-26fbf385.js +0 -185
  22. package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +0 -1
  23. package/dist/_snowpack/pkg/common/lit-html-3647afce.js +0 -1104
  24. package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +0 -1
  25. package/dist/_snowpack/pkg/delta-markdown-for-quill.js +0 -26198
  26. package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +0 -1
  27. package/dist/_snowpack/pkg/dialog-polyfill.js +0 -826
  28. package/dist/_snowpack/pkg/dialog-polyfill.js.map +0 -1
  29. package/dist/_snowpack/pkg/fusejs.js.map +0 -1
  30. package/dist/_snowpack/pkg/import-map.json +0 -25
  31. package/dist/_snowpack/pkg/jsonld-context-parser.js +0 -836
  32. package/dist/_snowpack/pkg/jsonld-context-parser.js.map +0 -1
  33. package/dist/_snowpack/pkg/jsonld.js +0 -11760
  34. package/dist/_snowpack/pkg/jsonld.js.map +0 -1
  35. package/dist/_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js +0 -10
  36. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +0 -10
  37. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +0 -10
  38. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +0 -39
  39. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +0 -1
  40. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +0 -48
  41. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +0 -1
  42. package/dist/_snowpack/pkg/lit-html/directives/until.js +0 -87
  43. package/dist/_snowpack/pkg/lit-html/directives/until.js.map +0 -1
  44. package/dist/_snowpack/pkg/lit-html.js +0 -94
  45. package/dist/_snowpack/pkg/lit-html.js.map +0 -1
  46. package/dist/_snowpack/pkg/markdown-it-link-attributes.js +0 -68
  47. package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +0 -1
  48. package/dist/_snowpack/pkg/markdown-it.js +0 -11307
  49. package/dist/_snowpack/pkg/markdown-it.js.map +0 -1
  50. package/dist/_snowpack/pkg/quill/dist/quill.snow.css.proxy.js +0 -10
  51. package/dist/_snowpack/pkg/quill-delta-to-markdown.js +0 -971
  52. package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +0 -1
  53. package/dist/_snowpack/pkg/quill.js +0 -14441
  54. package/dist/_snowpack/pkg/quill.js.map +0 -1
  55. package/dist/_snowpack/pkg/slim-select.js +0 -714
  56. package/dist/_snowpack/pkg/slim-select.js.map +0 -1
  57. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +0 -1149
  58. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +0 -10
  59. package/dist/_snowpack/pkg/tui-calendar.js +0 -46503
  60. package/dist/_snowpack/pkg/tui-calendar.js.map +0 -1
  61. package/dist/components/solid-ac-checker.js +0 -45
  62. package/dist/components/solid-calendar.js +0 -66
  63. package/dist/components/solid-delete.js +0 -96
  64. package/dist/components/solid-display.js +0 -150
  65. package/dist/components/solid-form-search.js +0 -173
  66. package/dist/components/solid-form.js +0 -257
  67. package/dist/components/solid-lang.js +0 -35
  68. package/dist/components/solid-map.js +0 -204
  69. package/dist/components/solid-table.js +0 -181
  70. package/dist/components/solid-widget.js +0 -72
  71. package/dist/import.css +0 -4
  72. package/dist/libs/Component.js +0 -13
  73. package/dist/libs/ComponentFactory.js +0 -165
  74. package/dist/libs/Compositor.js +0 -96
  75. package/dist/libs/Sib.js +0 -44
  76. package/dist/libs/filter.js +0 -184
  77. package/dist/libs/helpers.js +0 -185
  78. package/dist/libs/interfaces.js +0 -6
  79. package/dist/libs/lit-helpers.js +0 -139
  80. package/dist/libs/polyfills.js +0 -35
  81. package/dist/libs/store/custom-getter.js +0 -313
  82. package/dist/libs/store/server-pagination.js +0 -19
  83. package/dist/libs/store/server-search.js +0 -32
  84. package/dist/libs/store/store.js +0 -560
  85. package/dist/locales/en.json +0 -10
  86. package/dist/locales/en.json.proxy.js +0 -2
  87. package/dist/locales/fr.json +0 -10
  88. package/dist/locales/fr.json.proxy.js +0 -2
  89. package/dist/mixins/attributeBinderMixin.js +0 -113
  90. package/dist/mixins/contextMixin.js +0 -26
  91. package/dist/mixins/counterMixin.js +0 -54
  92. package/dist/mixins/federationMixin.js +0 -57
  93. package/dist/mixins/filterMixin.js +0 -152
  94. package/dist/mixins/grouperMixin.js +0 -73
  95. package/dist/mixins/highlighterMixin.js +0 -36
  96. package/dist/mixins/interfaces.js +0 -6
  97. package/dist/mixins/listMixin.js +0 -116
  98. package/dist/mixins/nextMixin.js +0 -23
  99. package/dist/mixins/paginateMixin.js +0 -97
  100. package/dist/mixins/requiredMixin.js +0 -38
  101. package/dist/mixins/serverPaginationMixin.js +0 -122
  102. package/dist/mixins/sorterMixin.js +0 -131
  103. package/dist/mixins/storeMixin.js +0 -139
  104. package/dist/mixins/translationMixin.js +0 -58
  105. package/dist/mixins/validationMixin.js +0 -95
  106. package/dist/mixins/widgetMixin.js +0 -364
  107. package/dist/new-widgets/attributeMixins/actionMixin.js +0 -13
  108. package/dist/new-widgets/attributeMixins/blankMixin.js +0 -7
  109. package/dist/new-widgets/attributeMixins/booleanMixin.js +0 -7
  110. package/dist/new-widgets/attributeMixins/index.js +0 -19
  111. package/dist/new-widgets/attributeMixins/mailtoMixin.js +0 -7
  112. package/dist/new-widgets/attributeMixins/multipleMixin.js +0 -27
  113. package/dist/new-widgets/attributeMixins/numberMixin.js +0 -7
  114. package/dist/new-widgets/attributeMixins/placeholderMixin.js +0 -16
  115. package/dist/new-widgets/attributeMixins/telMixin.js +0 -7
  116. package/dist/new-widgets/baseWidgetMixin.js +0 -109
  117. package/dist/new-widgets/callbackMixins/autocompletionMixin.js +0 -96
  118. package/dist/new-widgets/callbackMixins/index.js +0 -7
  119. package/dist/new-widgets/callbackMixins/richtextMixin.js +0 -37
  120. package/dist/new-widgets/callbackMixins/slimselect.css.proxy.js +0 -10
  121. package/dist/new-widgets/interfaces.js +0 -1
  122. package/dist/new-widgets/new-widget-factory.js +0 -91
  123. package/dist/new-widgets/templateAdditionMixins/addableMixin.js +0 -26
  124. package/dist/new-widgets/templateAdditionMixins/index.js +0 -13
  125. package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +0 -16
  126. package/dist/new-widgets/templateAdditionMixins/labelMixin.js +0 -18
  127. package/dist/new-widgets/templates/defaultTemplatesDirectory.js +0 -29
  128. package/dist/new-widgets/templates/displayTemplatesDirectory.js +0 -54
  129. package/dist/new-widgets/templates/formTemplatesDirectory.js +0 -423
  130. package/dist/new-widgets/templates/groupTemplatesDirectory.js +0 -11
  131. package/dist/new-widgets/templates/index.js +0 -6
  132. package/dist/new-widgets/templates/setTemplatesDirectory.js +0 -16
  133. package/dist/new-widgets/templatesDependencies/altMixin.js +0 -12
  134. package/dist/new-widgets/templatesDependencies/editableMixin.js +0 -60
  135. package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +0 -34
  136. package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +0 -10
  137. package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +0 -41
  138. package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +0 -59
  139. package/dist/new-widgets/templatesDependencies/formFileMixin.js +0 -82
  140. package/dist/new-widgets/templatesDependencies/formLengthMixin.js +0 -18
  141. package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +0 -18
  142. package/dist/new-widgets/templatesDependencies/formMixin.js +0 -56
  143. package/dist/new-widgets/templatesDependencies/formNumberMixin.js +0 -10
  144. package/dist/new-widgets/templatesDependencies/formRadioMixin.js +0 -12
  145. package/dist/new-widgets/templatesDependencies/formStepMixin.js +0 -12
  146. package/dist/new-widgets/templatesDependencies/linkTextMixin.js +0 -13
  147. package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +0 -125
  148. package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +0 -74
  149. package/dist/new-widgets/templatesDependencies/patternMixin.js +0 -18
  150. package/dist/new-widgets/templatesDependencies/rangeMixin.js +0 -100
  151. package/dist/new-widgets/templatesDependencies/setMixin.js +0 -9
  152. package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +0 -9
  153. package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +0 -14
  154. package/dist/new-widgets/valueTransformationMixins/dateMixin.js +0 -29
  155. package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +0 -12
  156. package/dist/new-widgets/valueTransformationMixins/index.js +0 -15
  157. package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +0 -30
  158. package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +0 -13
  159. package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +0 -21
  160. package/dist/solid-template-element.js +0 -144
  161. package/dist/style/default-theme.css.proxy.js +0 -10
  162. package/dist/widgets/baseWidget.js +0 -267
  163. package/dist/widgets/widget-factory.js +0 -20
  164. /package/dist/{style/default-theme.css → assets/default-theme-d0f20a8a.css} +0 -0
  165. /package/dist/{_snowpack/pkg/quill/dist/quill.snow.css → assets/quill.snow-8f222e44.css} +0 -0
  166. /package/dist/{new-widgets/callbackMixins/slimselect.css → assets/slimselect-43e3ebc8.css} +0 -0
@@ -1,364 +0,0 @@
1
- import { spread, preHTML } from '../libs/lit-helpers.js';
2
- import { parseFieldsString, findClosingBracketMatchIndex } from '../libs/helpers.js';
3
- import { newWidgetFactory } from '../new-widgets/new-widget-factory.js';
4
- import { WidgetType } from './interfaces.js';
5
- import { html, render } from '../_snowpack/pkg/lit-html.js';
6
- import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
7
- const WidgetMixin = {
8
- name: 'widget-mixin',
9
- use: [],
10
- attributes: {
11
- fields: {
12
- type: String,
13
- default: undefined
14
- }
15
- },
16
- initialState: {
17
- nameWidgets: null,
18
- _div: null
19
- },
20
- created() {
21
- this.nameWidgets = [];
22
- },
23
- attached() {
24
- if (!this.dataSrc && !this.resource && this.noRender === null) this.populate();
25
- },
26
- get parentElement() {
27
- return 'div';
28
- },
29
- get div() {
30
- if (this._div) return this._div;
31
- this._div = document.createElement(this.parentElement);
32
- this.element.appendChild(this._div);
33
- return this._div;
34
- },
35
- set div(value) {
36
- this._div = value;
37
- },
38
- get widgets() {
39
- return this.nameWidgets.map(name => this.element.querySelector(`[name="${name}"]`));
40
- },
41
- /**
42
- * Return field list of the component
43
- */
44
- async getFields() {
45
- // TODO : improve code
46
- const attr = this.fields;
47
- if (attr === '') return [];
48
- if (attr) return parseFieldsString(attr);
49
- let resource = this.resource;
50
- if (resource && resource.isContainer?.()) {
51
- // If container, keep the 1rst resource
52
- for (let res of resource['ldp:contains']) {
53
- resource = res;
54
- break;
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
- }
62
- }
63
- if (!this.dataSrc) console.error(new Error('You must provide a "fields" attribute'));
64
- if (!resource) return [];
65
- let fields = [];
66
- for (const prop of resource.properties) {
67
- if (!prop.startsWith('@') && !(prop === "permissions") && (await resource[prop])) fields.push(prop);
68
- }
69
- return fields;
70
- },
71
- /**
72
- * return attribute if "field" is an action
73
- * @param field - string
74
- */
75
- getAction(field) {
76
- const action = this.element.getAttribute('action-' + field);
77
- return action;
78
- },
79
- /**
80
- * return true if "field" is editable
81
- * @param field - string
82
- */
83
- editable(field) {
84
- return this.element.hasAttribute('editable-' + field);
85
- },
86
- /**
87
- * Return regexp to check if "field" is a set
88
- * @param field - string
89
- */
90
- getSetRegexp(field) {
91
- return new RegExp(`(^|\\,|\\(|\\s)\\s*${field}\\s*\\(`, 'g');
92
- },
93
- /**
94
- * Return fields contained in set "field"
95
- * @param field - string
96
- */
97
- getSet(field) {
98
- const setString = this.fields.match(this.getSetRegexp(field));
99
- if (!setString) return [];
100
- const firstSetBracket = this.fields.indexOf(setString[0]) + setString[0].length - 1;
101
- const lastSetBracket = findClosingBracketMatchIndex(this.fields, firstSetBracket);
102
- const set = this.fields.substring(firstSetBracket + 1, lastSetBracket);
103
- return parseFieldsString(set);
104
- },
105
- /**
106
- * Return true if "field" is a set
107
- * @param field - string
108
- */
109
- isSet(field) {
110
- if (!this.fields) return false;
111
- let foundSets = this.fields.match(this.getSetRegexp(field));
112
- return foundSets ? foundSets.length > 0 : false;
113
- },
114
- isString(field) {
115
- return field.startsWith('\'') || field.startsWith('\"');
116
- },
117
- /**
118
- * Return the value of "resource" for predicate "field"
119
- * @param field - string
120
- * @param resource - Resource
121
- */
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
- }
133
- return resource && !resource.isContainer?.() ? await resource[field] : undefined;
134
- },
135
- /**
136
- * Return the value of the field
137
- * @param field - field
138
- */
139
- async getValue(field, resource) {
140
- const escapedField = this.getEscapedField(field);
141
- if (this.getAction(escapedField)) {
142
- return this.getAction(escapedField);
143
- }
144
- if (this.element.hasAttribute('value-' + field)) {
145
- return this.element.getAttribute('value-' + field);
146
- }
147
- let resourceValue = await this.fetchValue(field, resource);
148
-
149
- // Empty value
150
- if (resourceValue === undefined || resourceValue === '' || resourceValue === null)
151
- // If null or empty, return field default value
152
- return this.element.hasAttribute('default-' + field) ? this.element.getAttribute('default-' + field) : '';
153
- return resourceValue;
154
- },
155
- empty() {},
156
- /**
157
- * Return a widget from a tagName, and create it if necessary
158
- * @param tagName - string
159
- */
160
- widgetFromTagName(tagName) {
161
- let type = tagName.startsWith('solid') ? WidgetType.CUSTOM : WidgetType.USER;
162
- if (!customElements.get(tagName)) {
163
- // component does not exist
164
- if (tagName.startsWith('solid')) newWidgetFactory(tagName); // solid- -> create it
165
- else type = WidgetType.NATIVE; // or use a native tag
166
- }
167
-
168
- return {
169
- tagName,
170
- type
171
- }; // return tagName
172
- },
173
-
174
- /**
175
- * Return widget for field "field"
176
- * @param field - string
177
- * @param isSet - boolean
178
- */
179
- getWidget(field, isSet = false) {
180
- const widget = this.element.getAttribute('widget-' + field);
181
- if (widget) return this.widgetFromTagName(widget);
182
- if (this.getAction(field)) return this.widgetFromTagName('solid-action');
183
- return !isSet ? this.widgetFromTagName(this.defaultWidget) : this.widgetFromTagName(this.defaultSetWidget);
184
- },
185
- /**
186
- * Return multiple widget if "field" is a multiple, false if it's not
187
- * @param field - string
188
- */
189
- multiple(field) {
190
- const attribute = 'multiple-' + field;
191
- if (!this.element.hasAttribute(attribute)) return null;
192
- const widget = this.element.getAttribute(attribute) || this.defaultMultipleWidget;
193
- return this.widgetFromTagName(widget);
194
- },
195
- /**
196
- * If attribute "lookForAttr" is set on element, add "attrKey" to the "attributes" list
197
- * @param lookForAttr - string
198
- * @param setAttrKey - string
199
- * @param attributes - object
200
- */
201
- addToAttributes(lookForAttr, setAttrKey, attributes) {
202
- const attribute = this.element.getAttribute(lookForAttr);
203
- if (attribute == null) return;
204
- attributes[setAttrKey] = attribute;
205
- },
206
- /**
207
- * Return all the attributes of widget "field"
208
- * @param field - string
209
- * @param resource - Resource
210
- */
211
- widgetAttributes(field, resource) {
212
- const attrs = {
213
- name: field
214
- };
215
- const escapedField = this.getEscapedField(field);
216
-
217
- // transfer all multiple-[field]-[attr] attributes as [attr] for multiple widget [field]
218
- const multipleAttributes = ['fields', 'label', 'widget', 'add-label', 'remove-label', 'next', 'empty-widget', 'add-class', 'remove-class'];
219
- for (let attr of multipleAttributes) this.addToAttributes(`multiple-${escapedField}-${attr}`, attr, attrs);
220
-
221
- // transfer all [attr]-[field] attributes as [attr] attribute for widget [field]
222
- const defaultAttributes = ['range', 'enum', 'label', 'placeholder', 'class',
223
-
224
- /* 'widget', */
225
- , 'required', 'editable', 'autocomplete', 'upload-url', 'option-label', 'option-value', 'order-by',
226
- // deprecated. Remove in 0.15
227
- 'each-label', 'order-asc', 'order-desc', 'min', 'max', 'pattern', 'title', 'start-value', 'end-value', 'alt', 'step', 'maxlength', 'minlength', 'search-text', 'search-placeholder', 'link-text'];
228
- for (let attr of defaultAttributes) this.addToAttributes(`${attr}-${escapedField}`, attr, attrs);
229
- const addableAttributes = Array.from(this.element.attributes).filter(a => a.name.startsWith(`addable-${escapedField}`));
230
- for (let attr of addableAttributes) this.addToAttributes(attr.name, attr.name.replace(`addable-${escapedField}`, 'addable'), attrs);
231
- const resourceId = resource ? resource['@id'] : null;
232
- if (this.multiple(escapedField)) attrs['widget'] = this.getWidget(escapedField).tagName;
233
- if (this.getAction(escapedField) && resourceId) attrs['src'] = this.element.getAttribute('src-' + escapedField) || resourceId;
234
- if (this.editable(escapedField) && resourceId) attrs['value-id'] = resourceId;
235
- return attrs;
236
- },
237
- /**
238
- * Creates and return a widget for field + add it to the widget list
239
- * @param field - string
240
- */
241
- async createWidgetTemplate(field, resource = null, transformAttributes = false) {
242
- if (this.isString(field)) return this.createString(field); // field is a static string
243
- if (this.isSet(field)) return await this.createSet(field);
244
- const currentResource = resource || this.resource;
245
- let attributes = this.widgetAttributes(field, currentResource);
246
- const escapedField = this.getEscapedField(field);
247
- const widgetMeta = this.multiple(escapedField) || this.getWidget(escapedField);
248
- let tagName = widgetMeta.tagName;
249
- let widgetTemplate = html``;
250
-
251
- // Set attributes
252
- let value = await this.getValue(field, currentResource);
253
- if (widgetMeta.type === WidgetType.NATIVE) {
254
- // native widget (ie: h1)
255
- widgetTemplate = preHTML`
256
- <${tagName}
257
- name="${ifDefined(attributes.name)}"
258
- class="${ifDefined(attributes.class)}"
259
- >${value}</${tagName}>
260
- `;
261
- } else {
262
- // custom widget (ie: solid-display-value)
263
- // Check if value is defined, and if the default widget is needed
264
- if ((value === null || value === '') && this.element.hasAttribute('default-widget-' + field)) {
265
- tagName = this.element.getAttribute('default-widget-' + field);
266
- }
267
- // Set attributes to the widget
268
- // setAttribute set a string. Make sure null values are empty
269
- if (value === null || value === undefined) attributes.value = '';
270
- if (widgetMeta.type === WidgetType.USER && value['@id']) {
271
- // if value is a resource and solid-widget used, set data-src
272
- attributes['data-src'] = value['@id'];
273
- } else {
274
- // otherwise, set value attribute
275
- attributes['value'] = value;
276
- }
277
-
278
- // Subscribe widgets if they show a resource
279
- if (value && value['@id']) attributes['auto-subscribe'] = value['@id'];
280
-
281
- // Transform store://XXX attributes
282
- if (transformAttributes) attributes = await this.transformAttributes(attributes, currentResource);
283
- widgetTemplate = preHTML`<${tagName} ...=${spread(attributes)}></${tagName}>`;
284
- }
285
- this.nameWidgets.push(field);
286
- return widgetTemplate;
287
- },
288
- defineAttribute(widget, attribute, value) {
289
- if (widget.getAttribute(attribute) !== value) {
290
- // if attribute is different than previous one
291
- widget.setAttribute(attribute, value); // set it
292
- }
293
- },
294
-
295
- /**
296
- * Create a set and add fields to it
297
- * @param field - string
298
- */
299
- async createSet(field) {
300
- const setWidget = this.getWidget(field, true);
301
-
302
- // Get set attributes
303
- const attrs = {
304
- name: field
305
- };
306
- const setAttributes = ['class', 'label'];
307
- for (let attr of setAttributes) this.addToAttributes(`${attr}-${field}`, attr, attrs);
308
-
309
- // Create widget if not already existing
310
- let widget = this.element.querySelector(`${setWidget.tagName}[name="${field}"]`);
311
- let initializing = false; // used to render widget only first time
312
- if (!widget) {
313
- widget = document.createElement(setWidget.tagName);
314
- initializing = true;
315
- }
316
- for (let name of Object.keys(attrs)) {
317
- this.defineAttribute(widget, name, attrs[name], setWidget.type);
318
- }
319
- if (widget.component && initializing) widget.component.render();
320
- let setFields = this.getSet(field);
321
- // Catch widget for the set if all these fields are empty
322
- if (this.element.hasAttribute('empty-' + field)) {
323
- let hasOnlyEmpty = true;
324
- for (let field of setFields) {
325
- let value = await this.getValue(field, this.resource);
326
- if (value !== '') {
327
- // if one not empty
328
- hasOnlyEmpty = false;
329
- continue; // break loop
330
- }
331
- }
332
-
333
- ;
334
- if (hasOnlyEmpty) {
335
- // if only empty values, return empty-widget
336
- const attributes = this.widgetAttributes(field, this.resource);
337
- const tagName = this.element.getAttribute(`empty-${field}`);
338
- const valueSet = this.element.getAttribute(`empty-${field}-value`);
339
- if (valueSet) attributes.value = valueSet;
340
- return preHTML`<${tagName} ...=${spread(attributes)}></${tagName}>`;
341
- }
342
- ;
343
- }
344
-
345
- // Render template
346
- const widgetsTemplate = await Promise.all(setFields.map(field => this.createWidgetTemplate(field)));
347
- const template = html`${widgetsTemplate}`;
348
- render(template, widget.querySelector('[data-content]') || widget);
349
- return widget;
350
- },
351
- createString(value) {
352
- return html`
353
- <span>${value.slice(1, -1).replace(/\\(['"])/g, '$1')}</span>
354
- `;
355
- },
356
- /**
357
- * Returns field name without starting "@"
358
- * @param field
359
- */
360
- getEscapedField(field) {
361
- return field.startsWith('@') ? field.slice(1, field.length) : field;
362
- }
363
- };
364
- export { WidgetMixin };
@@ -1,13 +0,0 @@
1
- const ActionMixin = {
2
- name: 'action-mixin',
3
- attributes: {
4
- src: {
5
- type: String,
6
- default: '',
7
- callback: function (newValue) {
8
- this.addToAttributes(newValue, 'src');
9
- }
10
- }
11
- }
12
- };
13
- export { ActionMixin };
@@ -1,7 +0,0 @@
1
- const BlankMixin = {
2
- name: 'blank-mixin',
3
- created() {
4
- this.listAttributes['target'] = '_blank';
5
- }
6
- };
7
- export { BlankMixin };
@@ -1,7 +0,0 @@
1
- const BooleanMixin = {
2
- name: 'boolean-mixin',
3
- get type() {
4
- return 'boolean';
5
- }
6
- };
7
- export { BooleanMixin };
@@ -1,19 +0,0 @@
1
- import { MultipleMixin } from './multipleMixin.js';
2
- import { ActionMixin } from './actionMixin.js';
3
- import { BlankMixin } from './blankMixin.js';
4
- import { MailtoMixin } from './mailtoMixin.js';
5
- import { TelMixin } from './telMixin.js';
6
- import { PlaceholderMixin } from './placeholderMixin.js';
7
- import { BooleanMixin } from './booleanMixin.js';
8
- import { NumberMixin } from './numberMixin.js';
9
- const attributeDirectory = {
10
- multiple: MultipleMixin,
11
- action: ActionMixin,
12
- blank: BlankMixin,
13
- mailto: MailtoMixin,
14
- tel: TelMixin,
15
- placeholder: PlaceholderMixin,
16
- bool: BooleanMixin,
17
- num: NumberMixin
18
- };
19
- export { attributeDirectory, MultipleMixin, ActionMixin, BlankMixin, MailtoMixin, TelMixin, PlaceholderMixin };
@@ -1,7 +0,0 @@
1
- const MailtoMixin = {
2
- name: 'mailto-mixin',
3
- created() {
4
- this.listAttributes['mailto'] = 'mailto:';
5
- }
6
- };
7
- export { MailtoMixin };
@@ -1,27 +0,0 @@
1
- const MultipleMixin = {
2
- name: 'multiple-mixin',
3
- attributes: {
4
- fields: {
5
- type: String,
6
- default: '',
7
- callback: function (newValue) {
8
- this.addToAttributes(newValue, 'fields');
9
- }
10
- },
11
- next: {
12
- type: String,
13
- default: '',
14
- callback: function (newValue) {
15
- this.addToAttributes(newValue, 'next');
16
- }
17
- },
18
- emptyWidget: {
19
- type: String,
20
- default: '',
21
- callback: function (newValue) {
22
- this.addToAttributes(newValue, 'emptyWidget');
23
- }
24
- }
25
- }
26
- };
27
- export { MultipleMixin };
@@ -1,7 +0,0 @@
1
- const NumberMixin = {
2
- name: 'number-mixin',
3
- get type() {
4
- return 'number';
5
- }
6
- };
7
- export { NumberMixin };
@@ -1,16 +0,0 @@
1
- const PlaceholderMixin = {
2
- name: 'placeholder-mixin',
3
- attributes: {
4
- placeholder: {
5
- type: String,
6
- default: '',
7
- callback: function (newValue) {
8
- this.addToAttributes(newValue, 'placeholder');
9
- }
10
- }
11
- },
12
- attached() {
13
- this.listAttributes['placeholder'] = this.placeholder || this.label || this.name || '';
14
- }
15
- };
16
- export { PlaceholderMixin };
@@ -1,7 +0,0 @@
1
- const TelMixin = {
2
- name: 'tel-mixin',
3
- created() {
4
- this.listAttributes['tel'] = 'tel:';
5
- }
6
- };
7
- export { TelMixin };
@@ -1,109 +0,0 @@
1
- import { render } from '../_snowpack/pkg/lit-html.js';
2
- const BaseWidgetMixin = {
3
- name: 'widget-mixin',
4
- use: [],
5
- attributes: {
6
- value: {
7
- type: String,
8
- default: '',
9
- callback: function () {
10
- this.planRender();
11
- }
12
- },
13
- name: {
14
- type: String,
15
- default: '',
16
- callback: function (newValue) {
17
- this.addToAttributes(newValue, 'name');
18
- }
19
- },
20
- label: {
21
- type: String,
22
- default: null,
23
- callback: function (newValue) {
24
- this.addToAttributes(newValue, 'label');
25
- }
26
- },
27
- autoSubscribe: {
28
- type: String,
29
- default: null,
30
- callback: function (newValue) {
31
- if (this.subscription) PubSub.unsubscribe(this.subscription);
32
- this.subscribe(newValue);
33
- }
34
- }
35
- },
36
- initialState: {
37
- listValueTransformations: [],
38
- listTemplateAdditions: [],
39
- listAttributes: {},
40
- listCallbacks: [],
41
- renderPlanned: false
42
- },
43
- get template() {
44
- return null;
45
- },
46
- created() {
47
- this.listValueTransformations = [];
48
- this.listAttributes = {};
49
- this.listTemplateAdditions = [];
50
- this.listCallbacks = [];
51
- this.subscription = null;
52
- },
53
- attached() {
54
- this.planRender();
55
- },
56
- detached() {
57
- if (this.subscription) PubSub.unsubscribe(this.subscription);
58
- },
59
- planRender() {
60
- if (!this.renderPlanned && document.body.contains(this.element)) {
61
- this.renderPlanned = true;
62
- setTimeout(() => {
63
- this.render();
64
- this.renderPlanned = false;
65
- });
66
- }
67
- },
68
- render() {
69
- const listValueTransformations = [...this.listValueTransformations];
70
- listValueTransformations.push(this.renderTemplate.bind(this));
71
- const nextProcessor = listValueTransformations.shift();
72
- nextProcessor(this.value, listValueTransformations);
73
-
74
- // Callbacks
75
- const listCallbacks = [...this.listCallbacks];
76
- if (listCallbacks.length) {
77
- const nextCallback = listCallbacks.shift();
78
- nextCallback(this.value, listCallbacks);
79
- }
80
- this.element.dispatchEvent(new CustomEvent('widgetRendered', {
81
- bubbles: true
82
- }));
83
- },
84
- renderTemplate(value) {
85
- const template = this.template(value, {
86
- ...this.listAttributes
87
- });
88
- const listTemplateAdditions = [...this.listTemplateAdditions];
89
- listTemplateAdditions.push(this.templateToDOM.bind(this));
90
- const nextProcessor = listTemplateAdditions.shift();
91
- nextProcessor(template, listTemplateAdditions);
92
- },
93
- templateToDOM(template) {
94
- render(template, this.element);
95
- },
96
- addToAttributes(value, attrKey) {
97
- if (value !== null && value !== this.listAttributes[attrKey]) {
98
- this.listAttributes[attrKey] = value;
99
- this.planRender();
100
- }
101
- },
102
- subscribe(event) {
103
- this.subscription = PubSub.subscribe(event, () => this.planRender());
104
- },
105
- update() {
106
- this.planRender();
107
- }
108
- };
109
- export { BaseWidgetMixin };
@@ -1,96 +0,0 @@
1
- import { fuzzyCompare } from '../../libs/helpers.js';
2
- import SlimSelect from '../../_snowpack/pkg/slim-select.js';
3
- import { TranslationMixin } from '../../mixins/translationMixin.js';
4
- const AutocompletionMixin = {
5
- name: 'autocompletion-mixin',
6
- use: [TranslationMixin],
7
- attributes: {
8
- searchText: {
9
- type: String,
10
- default: null,
11
- callback: function (newValue) {
12
- this.addToAttributes(newValue, 'searchText');
13
- }
14
- },
15
- searchPlaceholder: {
16
- type: String,
17
- default: null,
18
- callback: function (newValue) {
19
- this.addToAttributes(newValue, 'searchPlaceholder');
20
- }
21
- }
22
- },
23
- initialState: {
24
- slimSelect: null,
25
- mutationObserver: null
26
- },
27
- created() {
28
- //@ts-ignore
29
- import("./slimselect.css.proxy.js");
30
- this.slimSelect = null;
31
- this.addToAttributes(true, 'autocomplete');
32
- this.listCallbacks.push(this.addCallback.bind(this));
33
- },
34
- detached() {
35
- if (this.slimSelect) this.slimSelect.destroy();
36
- if (this.mutationObserver) this.mutationObserver.disconnect();
37
- },
38
- addCallback(value, listCallbacks) {
39
- if (this.slimSelect) return;
40
- let select = this.element.querySelector('select');
41
- if (select) {
42
- this.initSlimSelect(select);
43
- } else {
44
- // if no select available, wait for one and init slimSelect
45
- new MutationObserver((_m, observer) => {
46
- const select = this.element.querySelector('select');
47
- if (select) {
48
- this.initSlimSelect(select);
49
- observer.disconnect(); // then disconnect mutationObserver
50
- }
51
- }).observe(this.element, {
52
- childList: true,
53
- characterData: true,
54
- subtree: true
55
- });
56
- }
57
- const nextProcessor = listCallbacks.shift();
58
- if (nextProcessor) nextProcessor(value, listCallbacks);
59
- },
60
- initSlimSelect(select) {
61
- const slimSelect = new SlimSelect({
62
- select
63
- });
64
- this.slimSelect = slimSelect;
65
- select.addEventListener('change', () => {
66
- this.slimSelect.render();
67
- this.element.dispatchEvent(new Event('input', {
68
- bubbles: true
69
- }));
70
- });
71
- this.element.addEventListener('input', e => {
72
- if (e.target !== this.element) {
73
- // avoid update search result when search in slimSelect suggestions
74
- e.stopPropagation();
75
- }
76
- });
77
-
78
- // when data changes, re-build slimSelect
79
- if (this.mutationObserver) this.mutationObserver.disconnect();
80
- this.mutationObserver = new MutationObserver(() => {
81
- this.slimSelect.destroy();
82
- this.slimSelect = new SlimSelect({
83
- select,
84
- placeholder: this.placeholder || this.t("autocompletion.placeholder"),
85
- searchText: this.searchText || this.t("autocompletion.searchText"),
86
- searchPlaceholder: this.searchPlaceholder || this.t("autocompletion.searchPlaceholder"),
87
- searchFilter: (option, filterValue) => fuzzyCompare(option.text, filterValue)
88
- });
89
- }).observe(select, {
90
- childList: true,
91
- characterData: true,
92
- subtree: true
93
- });
94
- }
95
- };
96
- export { AutocompletionMixin };