@startinblox/core 0.18.1 → 0.19.0-beta.10

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