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

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-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 +54606 -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,257 +0,0 @@
1
- import { Sib } from '../libs/Sib.js';
2
- import { WidgetMixin } from '../mixins/widgetMixin.js';
3
- import { StoreMixin } from '../mixins/storeMixin.js';
4
- import { NextMixin } from '../mixins/nextMixin.js';
5
- import { ValidationMixin } from '../mixins/validationMixin.js';
6
- import { store } from '../libs/store/store.js';
7
- import { setDeepProperty, transformArrayToContainer } from '../libs/helpers.js';
8
- import { html, render } from '../_snowpack/pkg/lit-html.js';
9
- import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
10
- export const SolidForm = {
11
- name: 'solid-form',
12
- use: [WidgetMixin, StoreMixin, NextMixin, ValidationMixin],
13
- attributes: {
14
- defaultWidget: {
15
- type: String,
16
- default: 'solid-form-label-text'
17
- },
18
- naked: {
19
- type: String,
20
- default: null
21
- },
22
- submitButton: {
23
- type: String,
24
- default: undefined,
25
- callback: function (newValue, oldValue) {
26
- if (this.noRender == null && newValue !== oldValue) this.populate();
27
- }
28
- },
29
- submitWidget: {
30
- type: String,
31
- default: null
32
- },
33
- classSubmitButton: {
34
- type: String,
35
- default: undefined
36
- },
37
- partial: {
38
- type: Boolean,
39
- default: null
40
- },
41
- autosave: {
42
- type: Boolean,
43
- default: null
44
- }
45
- },
46
- initialState: {
47
- error: ''
48
- },
49
- get defaultMultipleWidget() {
50
- return 'solid-multiple-form';
51
- },
52
- get defaultSetWidget() {
53
- return 'solid-set-default';
54
- },
55
- get value() {
56
- const values = {};
57
- this.widgets.forEach(widget => {
58
- const name = (widget.component || widget).name;
59
- if (name == null) return;
60
- let value = widget.component ? widget.component.getValue() : widget.value;
61
- try {
62
- value = JSON.parse(value);
63
- } catch (e) {}
64
- setDeepProperty(values, name.split('.'), value);
65
- });
66
- // add @id if edition
67
- if (this.resource && !this.resource.isContainer?.()) values['@id'] = this.resourceId;
68
- return values;
69
- },
70
- get isNaked() {
71
- return this.element.hasAttribute('naked');
72
- },
73
- get isSavingAutomatically() {
74
- return this.autosave !== null;
75
- },
76
- isCreationForm(formValue) {
77
- return !('@id' in formValue);
78
- },
79
- async getFormValue() {
80
- let value = this.value;
81
- if (this.resource && !this.resource.isContainer?.()) {
82
- for (let predicate of Object.keys(this.value)) {
83
- // add @id for nested resources
84
- const object = await this.resource[predicate];
85
- if (object && object['@id'] && !value[predicate]['@id']) value[predicate]['@id'] = object['@id'];
86
- }
87
- }
88
- return transformArrayToContainer(value);
89
- },
90
- getWidget(field, isSet = false) {
91
- let tagName = '';
92
- const widgetAttribute = this.element.getAttribute('widget-' + field);
93
-
94
- // Choose widget
95
- if (!widgetAttribute && this.element.hasAttribute('upload-url-' + field)) {
96
- tagName = 'solid-form-file';
97
- } else if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {
98
- tagName = 'solid-form-dropdown';
99
- } else {
100
- tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);
101
- }
102
- // Create widget
103
- return this.widgetFromTagName(tagName);
104
- },
105
- change(resource) {
106
- this.element.dispatchEvent(new CustomEvent('formChange', {
107
- bubbles: true,
108
- detail: {
109
- resource
110
- }
111
- }));
112
- },
113
- async save() {
114
- this.toggleLoaderHidden(false);
115
- this.hideError();
116
- const resource = await this.getFormValue();
117
- resource['@context'] = this.context;
118
- let saved;
119
- try {
120
- if (this.partial == null) {
121
- saved = resource['@id'] ? await store.put(resource, this.resourceId) : await store.post(resource, this.resourceId);
122
- } else {
123
- saved = await store.patch(resource, this.resourceId);
124
- }
125
- } catch (e) {
126
- this.toggleLoaderHidden(true);
127
- if (e) {
128
- // if server error
129
- e.json().then(error => this.showError(error));
130
- throw e;
131
- } // else, ldpframework error, we continue
132
- }
133
-
134
- this.element.dispatchEvent(new CustomEvent('save', {
135
- bubbles: true,
136
- detail: {
137
- resource: resource,
138
- id: saved || null
139
- }
140
- }));
141
- this.toggleLoaderHidden(true);
142
- return saved;
143
- },
144
- async submitForm() {
145
- let id;
146
- try {
147
- id = (await this.save()) || this.getFormValue()['@id'];
148
- } catch (e) {
149
- return;
150
- }
151
- this.reset();
152
- this.goToNext({
153
- '@id': id
154
- });
155
- },
156
- async onInput() {
157
- const formValue = await this.getFormValue();
158
- this.change(formValue);
159
- },
160
- async onChange() {
161
- const formValue = await this.getFormValue();
162
- if (!this.isCreationForm(formValue) && this.isSavingAutomatically) this.submitForm(); // if autosave, submitForm
163
- },
164
-
165
- findErrorMessage(errors, errorFullName = '') {
166
- let errorsArray = [];
167
- errors.forEach(member => {
168
- let errorNextName = Object.values(member)[0];
169
- let errorAddName = errorFullName === "" ? errorNextName : errorFullName.concat(' - ', errorNextName);
170
- if (Array.isArray(Object.values(member)[1]) === true) {
171
- let errorMessage = Object.values(member)[1];
172
- let errorGlobal = errorAddName.concat(': ', errorMessage.join(', '));
173
- errorsArray.push(errorGlobal);
174
- } else {
175
- let objectErrors = Object.values(member)[1];
176
- let subErrors = Object.entries(objectErrors);
177
- errorsArray = [...errorsArray, ...this.findErrorMessage(subErrors, errorAddName)];
178
- }
179
- });
180
- return errorsArray;
181
- },
182
- empty() {},
183
- showError(e) {
184
- let errors = Object.entries(e).filter(field => !field[0].startsWith('@context'));
185
- const errorTemplate = html`
186
- <p>A validation error occurred.</p>
187
- <ul>
188
- ${this.findErrorMessage(errors).map(field => html`
189
- <li>${field}</li>
190
- `)}
191
- </ul>
192
- `;
193
- // If field exists pick its label (unsure if that's easily possible)
194
- // In this.getFields() map with each field and get label
195
- // If it does not just add a notice as we do that it's missing that field
196
-
197
- // Validation message in english ?
198
- const parentElement = this.element.querySelector('[data-id=error]');
199
- if (parentElement) render(errorTemplate, parentElement);
200
- },
201
- hideError() {
202
- const parentElement = this.element.querySelector('[data-id=error]');
203
- if (parentElement) render('', parentElement);
204
- },
205
- reset() {
206
- if (!this.isNaked) this.element.querySelector('form').reset();
207
- },
208
- onSubmit(event) {
209
- if (!this.isNaked) {
210
- event.preventDefault();
211
- this.performAction(); // In validationMixin, method defining what to do according to the present attributes
212
- }
213
- },
214
-
215
- validateModal() {
216
- //send method to validationMixin, used by the dialog modal and performAction method
217
- return this.submitForm();
218
- },
219
- onReset() {
220
- if (!this.isNaked) setTimeout(() => this.onInput());
221
- },
222
- getSubmitTemplate() {
223
- return html`
224
- <div class=${ifDefined(this.classSubmitButton)}>
225
- ${this.submitWidget === 'button' ? html`
226
- <button type="submit">${this.submitButton || this.t("solid-form.submit-button")}</button>
227
- ` : html`
228
- <input type="submit" value=${this.submitButton || this.t("solid-form.submit-button")}>
229
- `}
230
- </div>
231
- `;
232
- },
233
- async populate() {
234
- this.element.oninput = () => this.onInput(); // prevent from firing change multiple times
235
- this.element.onchange = () => this.onChange();
236
- const fields = await this.getFields();
237
- const widgetTemplates = await Promise.all(fields.map(field => this.createWidgetTemplate(field)));
238
- const template = html`
239
- <div data-id="error"></div>
240
- ${!this.isNaked ? html`
241
- <form
242
- @submit=${this.onSubmit.bind(this)}
243
- @reset=${this.onReset.bind(this)}
244
- >
245
- ${widgetTemplates}
246
- ${!this.isSavingAutomatically ? this.getSubmitTemplate() : ''}
247
- ${this.element.hasAttribute('reset') ? html`<input type="reset" />` : ''}
248
- </form>
249
- ` : html`
250
- ${widgetTemplates}
251
- `}
252
- ${this.getModalDialog()}
253
- `;
254
- render(template, this.element);
255
- }
256
- };
257
- Sib.register(SolidForm);
@@ -1,35 +0,0 @@
1
- import { Sib } from '../libs/Sib.js';
2
- import { store } from '../libs/store/store.js';
3
- import { html, render } from '../_snowpack/pkg/lit-html.js';
4
- export const SolidLang = {
5
- name: 'solid-lang',
6
- use: [],
7
- attributes: {
8
- lang: {
9
- type: String,
10
- default: null
11
- },
12
- dataLabel: {
13
- type: String,
14
- default: null
15
- }
16
- },
17
- created() {
18
- this.render();
19
- },
20
- languageLoader() {
21
- store.selectLanguage(this.lang);
22
- location.reload();
23
- },
24
- render() {
25
- let template = html`
26
- <button
27
- @click=${this.languageLoader.bind(this)}
28
- >
29
- ${this.dataLabel}
30
- </button>
31
- `;
32
- render(template, this.element);
33
- }
34
- };
35
- Sib.register(SolidLang);
@@ -1,204 +0,0 @@
1
- import { Sib } from '../libs/Sib.js';
2
- import { ListMixin } from '../mixins/listMixin.js';
3
- import { StoreMixin } from '../mixins/storeMixin.js';
4
- import { WidgetMixin } from '../mixins/widgetMixin.js';
5
- import { CounterMixin } from '../mixins/counterMixin.js';
6
- import { FilterMixin } from '../mixins/filterMixin.js';
7
- import { FederationMixin } from '../mixins/federationMixin.js';
8
- import { GrouperMixin } from '../mixins/grouperMixin.js';
9
- import { NextMixin } from '../mixins/nextMixin.js';
10
- import { store } from '../libs/store/store.js';
11
- import { uniqID } from '../libs/helpers.js';
12
- import { spread } from '../libs/lit-helpers.js';
13
-
14
- //@ts-ignore
15
- import L from 'https://cdn.skypack.dev/leaflet'; // TODO : revert to "leaflet" when apps up to date
16
- import 'https://cdn.skypack.dev/leaflet.markercluster'; // TODO : revert to "leaflet.markercluster" when apps up to date
17
-
18
- import { html, render } from '../_snowpack/pkg/lit-html.js';
19
- import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
20
- export const SolidMap = {
21
- name: 'solid-map',
22
- use: [WidgetMixin, ListMixin, StoreMixin, GrouperMixin, CounterMixin, FilterMixin, FederationMixin, NextMixin],
23
- attributes: {
24
- clustering: {
25
- type: Boolean,
26
- default: null
27
- }
28
- },
29
- initialState: {
30
- markers: {
31
- default: null
32
- },
33
- subscriptions: null,
34
- resetPlanned: false,
35
- hasBeenResetOnce: false
36
- },
37
- created() {
38
- //@ts-ignore
39
- import("../_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js");
40
- //@ts-ignore
41
- import("../style/default-theme.css.proxy.js");
42
- //@ts-ignore
43
- import("../_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js");
44
- //@ts-ignore
45
- import("../_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js");
46
-
47
- // reset when it becomes visible to prevent bug https://git.startinblox.com/framework/sib-core/issues/661
48
- document.body.addEventListener('navigate', () => setTimeout(() => this.isVisible && !this.hasBeenResetOnce && this.reset()));
49
- this.markers = [];
50
- this.subscriptions = new Map();
51
- },
52
- get isVisible() {
53
- return this.element.offsetParent !== null;
54
- },
55
- attached() {
56
- const id = uniqID();
57
- const template = html`
58
- <div id=${id} style="width:100%;height:100%;"></div>
59
- `;
60
- render(template, this.element);
61
- const div = this.element.querySelector(`#${id}`);
62
- this.map = L.map(div);
63
- L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png').addTo(this.map);
64
- if (this.clustering !== null) {
65
- this.markersCluster = L.markerClusterGroup();
66
- this.map.addLayer(this.markersCluster);
67
- }
68
- },
69
- reset() {
70
- if (this.isVisible) {
71
- // reset only if visible
72
- this.map.invalidateSize();
73
- if (this.markers.length) {
74
- this.map.fitBounds(L.featureGroup(this.markers).getBounds()); // Center map on markers if some available
75
- } else {
76
- this.map.fitWorld(); // ... or on the world if not
77
- }
78
-
79
- this.hasBeenResetOnce = true;
80
- }
81
- },
82
- /**
83
- * Execute a reset only if none is planned already
84
- */
85
- planReset() {
86
- if (!this.resetPlanned) {
87
- this.resetPlanned = true;
88
- setTimeout(() => {
89
- this.reset();
90
- this.resetPlanned = false;
91
- });
92
- }
93
- },
94
- dispatchSelect(event) {
95
- const target = event.target;
96
- const resource = target['options'].resource;
97
- this.element.dispatchEvent(new CustomEvent('resourceSelect', {
98
- detail: {
99
- resource: resource
100
- }
101
- }));
102
- this.goToNext(resource);
103
- },
104
- /**
105
- * Override listMixin method: initialize a marker on the map
106
- * @param resourceId: id of the resource to display
107
- * @param groupClass: class of the group of markers
108
- */
109
- async appendChildElt(resourceId, groupClass) {
110
- const resource = await store.getData(resourceId, this.context);
111
- if (!this.subscriptions.get(resourceId)) {
112
- this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()));
113
- }
114
- if (!resource) return;
115
- const lat = await resource['lat'];
116
- const lng = await resource['lng'];
117
- if (lat && lng) {
118
- const icon = L.divIcon({
119
- // create the icon, doc here: https://leafletjs.com/reference-1.6.0.html#icon
120
- className: 'sib-custom-marker ' + groupClass,
121
- // default class used for styling
122
- iconSize: [8, 8],
123
- iconAnchor: [12, 34],
124
- popupAnchor: [0, -34]
125
- });
126
-
127
- // create a marker, doc here: https://leafletjs.com/reference-1.6.0.html#marker
128
- const marker = L.marker([lat.toString(), lng.toString()], {
129
- resource,
130
- icon
131
- });
132
- if (this.clustering === null) marker.addTo(this.map);else this.markersCluster.addLayer(marker);
133
- marker.on('click', this.dispatchSelect.bind(this));
134
- if (this.fields !== null) {
135
- // show popups only if fields attribute
136
- marker.bindPopup(() => this.getPopupContent(resourceId), {
137
- minWidth: 150
138
- }); // re-generate popup solid-display
139
- }
140
-
141
- this.markers.push(marker);
142
- }
143
- },
144
- /**
145
- * Generate the solid-display of the popup
146
- * @param resourceId: id of the popup clicked
147
- */
148
- getPopupContent(resourceId) {
149
- const attributes = {};
150
- for (let attr of this.element.attributes) {
151
- //copy widget and value attributes
152
- if (attr.name.startsWith('value-') || attr.name.startsWith('label-') || attr.name.startsWith('widget-') || attr.name.startsWith('class-') || attr.name.startsWith('multiple-') || attr.name.startsWith('editable-') || attr.name.startsWith('action-') || attr.name.startsWith('default-') || attr.name == 'extra-context') attributes[attr.name] = attr.value;
153
- if (attr.name.startsWith('child-')) attributes[attr.name.replace(/^child-/, '')] = attr.value;
154
- }
155
- const div = document.createElement('div');
156
- const template = html`
157
- <solid-display
158
- fields="${ifDefined(this.fields)}"
159
- data-src="${resourceId}"
160
- ...=${spread(attributes)}
161
- ></solid-display>
162
- `;
163
- render(template, div);
164
- return div.querySelector('solid-display');
165
- },
166
- /**
167
- * Override widgetMixin method: empty the map
168
- */
169
- empty() {
170
- if (!this.map) return;
171
- if (this.markersCluster) this.map.removeLayer(this.markersCluster);
172
- for (let marker of this.markers) this.map.removeLayer(marker);
173
- if (this.clustering !== null) {
174
- this.markersCluster = L.markerClusterGroup();
175
- this.map.addLayer(this.markersCluster);
176
- }
177
- this.markers = [];
178
- },
179
- /**
180
- * Override groupMixin method
181
- * @param groupName: value of the group
182
- */
183
- renderGroup(groupName) {
184
- const sanitizedGroupName = encodeURIComponent(groupName.toLowerCase()).replace(/%[0-9A-F]{2}/gi, '');
185
- const div = document.createElement('div'); // used to pass group info to renderDOM
186
- div.dataset.groupClass = 'group-' + sanitizedGroupName;
187
- return div;
188
- },
189
- /**
190
- * Override listMixin method: display all the resources
191
- * @param resources
192
- * @param listPostProcessors
193
- * @param div
194
- * @param context
195
- */
196
- async renderDOM(resources, listPostProcessors, div, context) {
197
- const groupClass = div.dataset.groupClass || ''; // get the group class from the useless div element
198
- await Promise.all(resources.map(resource => this.appendChildElt(resource['@id'], groupClass)));
199
- this.planReset();
200
- const nextProcessor = listPostProcessors.shift();
201
- if (nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);
202
- }
203
- };
204
- Sib.register(SolidMap);
@@ -1,181 +0,0 @@
1
- import { Sib } from '../libs/Sib.js';
2
- import { store } from '../libs/store/store.js';
3
- import { WidgetMixin } from '../mixins/widgetMixin.js';
4
- import { ListMixin } from '../mixins/listMixin.js';
5
- import { StoreMixin } from '../mixins/storeMixin.js';
6
- import { PaginateMixin } from '../mixins/paginateMixin.js';
7
- import { FilterMixin } from '../mixins/filterMixin.js';
8
- import { CounterMixin } from '../mixins/counterMixin.js';
9
- import { SorterMixin } from '../mixins/sorterMixin.js';
10
- import { GrouperMixin } from '../mixins/grouperMixin.js';
11
- import { FederationMixin } from '../mixins/federationMixin.js';
12
- import { HighlighterMixin } from '../mixins/highlighterMixin.js';
13
- import { RequiredMixin } from '../mixins/requiredMixin.js';
14
- import { html, render } from '../_snowpack/pkg/lit-html.js';
15
- import { until } from '../_snowpack/pkg/lit-html/directives/until.js';
16
- import { spread } from '../libs/lit-helpers.js';
17
- export const SolidTable = {
18
- name: 'solid-table',
19
- use: [WidgetMixin, ListMixin, StoreMixin, PaginateMixin, GrouperMixin, CounterMixin, HighlighterMixin, FilterMixin, SorterMixin, RequiredMixin, FederationMixin],
20
- attributes: {
21
- defaultWidget: {
22
- type: String,
23
- default: 'solid-display-value'
24
- },
25
- selectable: {
26
- type: String,
27
- default: null
28
- },
29
- header: {
30
- type: String,
31
- default: null
32
- }
33
- },
34
- get parentElement() {
35
- return 'table';
36
- },
37
- get defaultMultipleWidget() {
38
- return 'solid-multiple';
39
- },
40
- get defaultSetWidget() {
41
- return 'solid-set-default';
42
- },
43
- get selectedLines() {
44
- if (this.selectable === null) return [];
45
- return Array.from(this.element.querySelectorAll('input[data-selection]:checked')).map(e => e?.closest('[data-resource]')?.getAttribute('data-resource'));
46
- },
47
- /**
48
- * Select all lines
49
- * @param e - event
50
- */
51
- selectAll(e) {
52
- if (this.selectable === null) return;
53
- for (const checkbox of Array.from(this.element.querySelectorAll('input[data-selection]'))) {
54
- checkbox.checked = e.target.checked;
55
- }
56
- },
57
- /**
58
- * Unselect all lines
59
- */
60
- unselectAll() {
61
- if (this.selectable === null) return;
62
- for (const checkbox of Array.from(this.element.querySelectorAll('input[data-selection]'))) {
63
- checkbox.checked = false;
64
- }
65
- },
66
- /**
67
- * Select specific lines
68
- * @param lines - array of selected lines
69
- */
70
- selectLines(lines) {
71
- if (this.selectable === null || lines.length === 0) return;
72
- for (const line of lines) {
73
- const checkbox = this.element.querySelector(`[data-resource="${line}"] input[data-selection]`);
74
- if (checkbox) checkbox.checked = true;
75
- }
76
- },
77
- /**
78
- * Create a widget for the field or a form if it's editable
79
- * @param field
80
- * @param resource
81
- */
82
- async createCellWidget(field, resource) {
83
- // if regular widget
84
- if (!this.element.hasAttribute('editable-' + field)) return this.createWidgetTemplate(field, resource, true);
85
-
86
- // if editable widget
87
- const attributes = {};
88
- const formWidgetAttributes = [
89
- // attributes to give to the form widget
90
- 'range', 'enum', 'placeholder', 'required', 'autocomplete', 'option-label', 'option-value', 'min', 'max', 'pattern', 'title', 'widget'];
91
- for (let attr of formWidgetAttributes) this.addToAttributes(`${attr}-${field}`, `${attr}-${field}`, attributes);
92
- const formAttributes = [
93
- // attributes to give to the form
94
- 'class', 'submit-button', 'next'];
95
- for (let attr of formAttributes) this.addToAttributes(`${attr}-${field}`, attr, attributes);
96
- return html`
97
- <solid-form
98
- data-src="${resource['@id']}"
99
- fields="${field}"
100
- partial
101
- autosave
102
- ...=${spread(attributes)}
103
- ></solid-form>
104
- `;
105
- },
106
- /**
107
- * Creates a header line for the table
108
- * @param fields
109
- */
110
- getHeader(fields) {
111
- let template = html`
112
- <tr>
113
- ${this.selectable !== null ? html`
114
- <th>
115
- <input type="checkbox" @change="${this.selectAll.bind(this)}" />
116
- </th>` : ''}
117
- ${fields.map(field => html`
118
- <th>
119
- ${this.element.hasAttribute('label-' + field) ? this.element.getAttribute('label-' + field) : field}
120
- </th>`)}
121
- </tr>
122
- `;
123
- return template;
124
- },
125
- /**
126
- * Returns template of a child element (resource)
127
- * @param resourceId
128
- * @param attributes
129
- */
130
- async getChildTemplate(resourceId, fields) {
131
- const resource = await store.getData(resourceId, this.context);
132
- let template = html`
133
- <tr data-resource="${resourceId}">
134
- ${this.selectable !== null ? html`
135
- <td>
136
- <input type="checkbox" data-selection />
137
- </td>` : ''}
138
- ${fields.map(field => html`<td>${until(this.createCellWidget(field, resource))}</td>`)}
139
- </tr>
140
- `;
141
- return template;
142
- },
143
- /**
144
- * Creates and render the content of a single element (resource)
145
- * @param parent
146
- */
147
- async appendSingleElt(parent) {
148
- const fields = await this.getFields();
149
- const template = html`
150
- ${this.header !== null ? this.getHeader(fields) : ''}
151
- ${until(this.getChildTemplate(this.resource['@id'], fields))}
152
- `;
153
- render(template, parent);
154
- },
155
- /**
156
- * @override listMixin method to use litHtml
157
- *
158
- * Render resources from a container
159
- * @param resources
160
- * @param listPostProcessors
161
- * @param div
162
- * @param context
163
- */
164
- async renderDOM(resources, listPostProcessors, div, context) {
165
- const selectedLines = [...this.selectedLines]; // save selected lines before moving them
166
- const fields = await this.getFields();
167
- const childTemplates = await Promise.all(resources.map(r => r ? this.getChildTemplate(r['@id'], fields) : null));
168
- const template = html`
169
- ${this.header !== null ? this.getHeader(fields) : ''}
170
- ${childTemplates}
171
- `; // create a child template for each resource
172
- render(template, div);
173
-
174
- // Re-select the right lines
175
- this.unselectAll();
176
- this.selectLines(selectedLines);
177
- const nextProcessor = listPostProcessors.shift();
178
- if (nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);
179
- }
180
- };
181
- Sib.register(SolidTable);