@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,21 +0,0 @@
1
- import { unsafeHTML } from '../../_snowpack/pkg/lit-html/directives/unsafe-html.js';
2
- const OembedMixin = {
3
- name: 'oembed-mixin',
4
- initialState: {
5
- existingOembed: null
6
- },
7
- created() {
8
- this.listValueTransformations.push(this.transformValue.bind(this));
9
- },
10
- async transformValue(value, listValueTransformations) {
11
- if (!value) return;
12
- if (this.existingOembed == null) {
13
- const response = await fetch(this.value);
14
- this.existingOembed = await response.json();
15
- }
16
- const newValue = unsafeHTML(this.existingOembed.html);
17
- const nextProcessor = listValueTransformations.shift();
18
- if (nextProcessor) nextProcessor(newValue, listValueTransformations);
19
- }
20
- };
21
- export { OembedMixin };
@@ -1,144 +0,0 @@
1
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
- ///@ts-nocheck
5
-
6
- export default class SolidTemplateElement extends HTMLElement {
7
- constructor() {
8
- super();
9
- _defineProperty(this, "renderPlanned", false);
10
- _defineProperty(this, "strings", {});
11
- _defineProperty(this, "translationsPath", null);
12
- _defineProperty(this, "translationsFetched", false);
13
- _defineProperty(this, "props", {});
14
- this.initProps();
15
- }
16
- static get observedAttributes() {
17
- return Object.values(this.propsDefinition);
18
- }
19
- static get propsDefinition() {
20
- return {};
21
- }
22
- initProps() {
23
- this.props = {};
24
- for (let key in this.constructor.propsDefinition) {
25
- this.props[key] = undefined;
26
- }
27
- }
28
- updateProps() {
29
- const declaredAttributes = [];
30
-
31
- // Get props values
32
- for (let key in this.constructor.propsDefinition) {
33
- const def = this.constructor.propsDefinition[key];
34
- if (typeof def === "string") {
35
- this.props[key] = this.hasAttribute(def) ? this.getAttribute(def) : undefined;
36
- declaredAttributes.push(def);
37
- } else if (typeof def === "object" && def.attribute && typeof def.attribute === "string") {
38
- this.props[key] = this.hasAttribute(def.attribute) ? this.getAttribute(def.attribute) : def.default || undefined;
39
- declaredAttributes.push(def.attribute);
40
- }
41
- }
42
-
43
- // Add attributes to props
44
- for (let attr of this.attributes) {
45
- if (!declaredAttributes.includes(attr.name)) {
46
- // if attribute not in propsDefinition
47
- this.props[this._camelize(attr.name)] = attr.value || undefined; // add it to props
48
- }
49
- }
50
- }
51
-
52
- /**
53
- * Define the path folder of translations files
54
- * @param path
55
- */
56
- setTranslationsPath(path) {
57
- this.translationsPath = path;
58
- }
59
-
60
- /**
61
- * Fetch all localized strings
62
- */
63
- async fetchLocaleStrings() {
64
- if (this.translationsFetched) return;
65
- const filesToFetch = [];
66
- if (this.translationsPath)
67
- // fetch component translations
68
- filesToFetch.push(this.fetchTranslationFile(this.translationsPath));
69
- const extraTranslationsPath = this.getAttribute('extra-translations-path');
70
- if (extraTranslationsPath)
71
- // fetch developer translations
72
- filesToFetch.push(this.fetchTranslationFile(extraTranslationsPath));
73
-
74
- // merge all translations
75
- return Promise.all(filesToFetch).then(res => {
76
- this.translationsFetched = true;
77
- this.strings = Object.assign({}, ...res);
78
- });
79
- }
80
-
81
- /**
82
- * Fetch the translation file from [path]
83
- */
84
- async fetchTranslationFile(path) {
85
- const ln = this.getLocale();
86
- const fullPath = `${path}/${ln}.json`;
87
- return fetch(fullPath).then(result => {
88
- if (result.ok) {
89
- return result.json() // parse content
90
- .catch(e => console.error(`Error while parsing the translation file: ${fullPath}`));
91
- }
92
- }).catch(e => console.error(`Error while retrieving the translation file: ${fullPath}`));
93
- }
94
-
95
- /**
96
- * Returns current locale of app
97
- */
98
- getLocale() {
99
- return localStorage.getItem('language') || window.navigator.language.slice(0, 2);
100
- }
101
-
102
- /**
103
- * Return localized string for [key]
104
- * @param key
105
- */
106
- localize(key) {
107
- return this.strings[key] || key;
108
- }
109
- attributeChangedCallback() {
110
- this.updateProps();
111
- this.planRender();
112
- }
113
- connectedCallback() {
114
- this.updateProps();
115
- this.planRender();
116
- }
117
-
118
- /**
119
- * Plan a render if none is already waiting to prevent multi re-renders
120
- */
121
- planRender() {
122
- if (!this.renderPlanned) {
123
- this.renderPlanned = true;
124
- setTimeout(() => {
125
- this.render();
126
- this.renderPlanned = false;
127
- });
128
- }
129
- }
130
- renderCallback() {}
131
- render() {
132
- this.fetchLocaleStrings().finally(() => {
133
- // render even if some errors occurred
134
- this.innerHTML = this.template(this.props);
135
- this.renderCallback();
136
- });
137
- }
138
- template() {
139
- return '';
140
- }
141
- _camelize(str) {
142
- return str.replace(/\W+(.)/g, (match, chr) => chr.toUpperCase());
143
- }
144
- }
@@ -1,10 +0,0 @@
1
- // [snowpack] add styles to the page (skip if no document exists)
2
- if (typeof document !== 'undefined') {
3
- const code = "/*==== SOLID-MAP ====*/\n/* map custom marker */\n.sib-custom-marker {\n position: absolute;\n top: 40%;\n left: 50%;\n margin-left: 115px;\n border-radius: 50%;\n border: 8px solid #1c78c9;\n width: 8px;\n height: 8px;\n}\n.sib-custom-marker::after {\n position: absolute;\n content: '';\n width: 0px;\n height: 0px;\n bottom: -30px;\n left: -6px;\n border: 10px solid transparent;\n border-top-width: 17px;\n border-top-style: solid;\n border-top-color: inherit;\n}";
4
-
5
- const styleEl = document.createElement("style");
6
- const codeEl = document.createTextNode(code);
7
- styleEl.type = 'text/css';
8
- styleEl.appendChild(codeEl);
9
- document.head.appendChild(styleEl);
10
- }
@@ -1,268 +0,0 @@
1
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
- import { evalTemplateString } from '../libs/helpers.js';
5
- import { store } from '../libs/store/store.js';
6
- export class BaseWidget extends HTMLElement {
7
- constructor() {
8
- super(...arguments);
9
- _defineProperty(this, "src", void 0);
10
- _defineProperty(this, "multiple", void 0);
11
- _defineProperty(this, "editable", void 0);
12
- _defineProperty(this, "required", void 0);
13
- _defineProperty(this, "resourceId", void 0);
14
- _defineProperty(this, "_value", void 0);
15
- _defineProperty(this, "_range", void 0);
16
- _defineProperty(this, "_context", void 0);
17
- _defineProperty(this, "_subscriptions", new Map());
18
- }
19
- connectedCallback() {
20
- this.render();
21
- }
22
- disconnectedCallback() {
23
- this._subscriptions.forEach(subscription => {
24
- PubSub.unsubscribe(subscription);
25
- });
26
- }
27
- async render() {
28
- this.innerHTML = await evalTemplateString(this.template, {
29
- src: this.src,
30
- name: this.name,
31
- label: this.label,
32
- placeholder: this.placeholder,
33
- value: this.value,
34
- id: this._value && this._value['@id'] || '',
35
- escapedValue: this.escapedValue,
36
- range: await this.htmlRange,
37
- multiple: this.multiple,
38
- editable: this.editable === '' ? true : false,
39
- required: this.required === '' ? true : false
40
- });
41
- this.addEditButtons();
42
- this.initChangeEvents();
43
- }
44
- get label() {
45
- return this.hasAttribute('label') ? this.getAttribute('label') : this.name;
46
- }
47
- set label(label) {
48
- if (label != null) this.setAttribute('label', label);
49
- this.render();
50
- }
51
- get placeholder() {
52
- return this.hasAttribute('placeholder') ? this.getAttribute('placeholder') : this.label;
53
- }
54
- set placeholder(placeholder) {
55
- if (placeholder != null) this.setAttribute('placeholder', placeholder);
56
- this.render();
57
- }
58
- get name() {
59
- return this.getAttribute('name');
60
- }
61
- set name(name) {
62
- if (name) this.setAttribute('name', name);
63
- this.render();
64
- }
65
- get value() {
66
- if (this.dataHolder) {
67
- let values = this.dataHolder.map(element => {
68
- if (element instanceof HTMLInputElement && element.type == "checkbox") return element.checked;
69
- // if value is defined, push it in the array
70
- return this.getValueHolder(element).value;
71
- });
72
- // If only one value, do not return an array
73
- return values.length === 1 ? values[0] : values;
74
- }
75
- return this._value || '';
76
- }
77
- set value(value) {
78
- this._value = value; // ... store `value` in the widget
79
- if (this._value == null || this._value == undefined) return;
80
- if (this.dataHolder && this.dataHolder.length === 1) {
81
- // if one dataHolder in the widget...
82
- const element = this.getValueHolder(this.dataHolder[0]);
83
- if (element.type == "checkbox") {
84
- element.checked = value;
85
- } else {
86
- element.value = value; // ... set `value` to the dataHolder element
87
- }
88
- // remove when https://git.happy-dev.fr/startinblox/framework/sib-core/issues/426 fixed
89
- if (element.dispatchEvent) element.dispatchEvent(new Event('change')); // trigger change manually
90
- } else if (this.dataHolder && this.dataHolder.length > 1) {
91
- // if multiple dataHolder in the widget ...
92
- this.dataHolder.forEach((el, index) => {
93
- const element = this.getValueHolder(el);
94
- if (element.type == "checkbox") {
95
- element.checked = value ? value[index] : '';
96
- } else {
97
- element.value = value ? value[index] : '';
98
- }
99
- element.dispatchEvent(new Event('change')); // trigger change manually
100
- }); // ... set each `value` to each dataHolder element
101
- }
102
-
103
- this.render();
104
- }
105
- get ['each-label']() {
106
- return this.getAttribute('each-label') || '';
107
- }
108
- set ['each-label'](label) {
109
- this.setAttribute('each-label', label);
110
- }
111
- set ['add-label'](label) {
112
- this.setAttribute('add-label', label);
113
- }
114
- set ['remove-label'](label) {
115
- this.setAttribute('remove-label', label);
116
- }
117
- get dataHolder() {
118
- const widgetDataHolders = Array.from(this.querySelectorAll('[data-holder]')).filter(element => {
119
- const dataHolderAncestor = element.parentElement ? element.parentElement.closest('[data-holder]') : null;
120
- // get the dataHolder of the widget only if no dataHolder ancestor in the current widget
121
- return dataHolderAncestor === this || !dataHolderAncestor || !this.contains(dataHolderAncestor);
122
- });
123
- return widgetDataHolders.length ? widgetDataHolders : null;
124
- }
125
- get template() {
126
- return '';
127
- }
128
- get childTemplate() {
129
- return '';
130
- }
131
- get escapedValue() {
132
- return ('' + this.value).replace(/&/g, '&').replace(/'/g, ''').replace(/"/g, '"');
133
- }
134
- set context(value) {
135
- this._context = value;
136
- }
137
- get context() {
138
- return this._context || {};
139
- }
140
- get range() {
141
- return this.fetchSources(this._range);
142
- }
143
- set range(range) {
144
- (async () => {
145
- this._listen(range, async () => this._range = await store.getData(range, this.context));
146
- this._range = await store.getData(range, this.context);
147
- this.render();
148
- })();
149
- }
150
- async fetchSources(resource) {
151
- if (!resource || !resource['ldp:contains']) return null;
152
- let resources = [];
153
- let index = 0;
154
- for (let res of resource['ldp:contains']) {
155
- if (!res) {
156
- // child not in cache yet
157
- try {
158
- const resourceId = resource.getChildren()[index]['@id'];
159
- res = await store.getData(resourceId, this.context);
160
- } catch (e) {
161
- continue;
162
- }
163
- }
164
- if (res.isContainer?.()) {
165
- // if nested container
166
- let resourcesFromContainer = await store.getData(res['@id'], this.context); // fetch the datas
167
- this._listen(res['@id']);
168
- if (resourcesFromContainer) resources.push(...resourcesFromContainer['ldp:contains']);
169
- } else {
170
- resources.push(res);
171
- }
172
- index++;
173
- }
174
- return resources;
175
- }
176
- get htmlRange() {
177
- return (async () => {
178
- let htmlRange = '';
179
- const rangeResources = await this.range;
180
- if (!rangeResources) return;
181
- for await (let element of rangeResources) {
182
- element = await store.getData(element['@id'], this.context); // fetch the resource to display the name
183
- this._listen(element['@id']);
184
- let selected;
185
- if (this._value && this._value.isContainer && this._value.isContainer()) {
186
- // selected options for multiple select
187
- selected = false;
188
- for await (let value of this._value["ldp:contains"]) {
189
- if (value['@id'] == element['@id']) {
190
- selected = true;
191
- break;
192
- }
193
- }
194
- } else {
195
- // selected options for simple dropdowns
196
- selected = this._value ? this._value['@id'] == element['@id'] : false;
197
- }
198
- htmlRange += await evalTemplateString(this.childTemplate, {
199
- name: await element.name,
200
- id: element['@id'],
201
- selected: selected
202
- });
203
- }
204
- return htmlRange || '';
205
- })();
206
- }
207
- getValueHolder(element) {
208
- return element.component ? element.component : element;
209
- }
210
- subscribe(event) {
211
- this._listen(event);
212
- }
213
- _listen(id) {
214
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
215
- if (!this._subscriptions.get(id)) {
216
- this._subscriptions.set(id, PubSub.subscribe(id, async () => {
217
- await callback();
218
- this.render();
219
- }));
220
- }
221
- }
222
-
223
- // Editable widgets
224
- addEditButtons() {
225
- const editableField = this.querySelector('[data-editable]');
226
- if (editableField) {
227
- // Add edit button
228
- const editButton = document.createElement('button');
229
- editButton.innerText = "Modifier";
230
- editButton.onclick = () => this.activateEditableField(editableField, editButton);
231
- editableField.insertAdjacentElement('afterend', editButton);
232
-
233
- // Save on focusout
234
- editableField.addEventListener('focusout', () => this.save(editableField, editButton));
235
- }
236
- }
237
- activateEditableField(editableField, editButton) {
238
- editableField.setAttribute('contenteditable', 'true');
239
- editableField.focus();
240
- editButton.setAttribute("disabled", "disabled");
241
- }
242
- /**
243
- * Dispatch change events of data holders from the current widget
244
- */
245
- initChangeEvents() {
246
- if (this.dataHolder) {
247
- const event = new Event('change', {
248
- bubbles: true
249
- });
250
- this.dataHolder.forEach(element => {
251
- element.addEventListener('change', e => {
252
- e.preventDefault();
253
- e.stopPropagation();
254
- this.dispatchEvent(event);
255
- });
256
- });
257
- }
258
- }
259
- save(editableField, editButton) {
260
- editableField.setAttribute('contenteditable', 'false');
261
- editButton.removeAttribute("disabled");
262
- if (!this.name) return;
263
- const resource = {};
264
- resource[this.name] = editableField.innerText;
265
- resource['@context'] = this.context;
266
- if (this.resourceId && resource) store.patch(resource, this.resourceId);
267
- }
268
- }
@@ -1,22 +0,0 @@
1
- import { BaseWidget } from './baseWidget.js';
2
- import { defineComponent } from '../libs/helpers.js';
3
- export const widgetFactory = function (tagName, customTemplate) {
4
- let childTemplate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
5
- let callback = arguments.length > 3 ? arguments[3] : undefined;
6
- const registered = customElements.get(tagName);
7
- if (registered) return registered;
8
- const cls = class extends BaseWidget {
9
- async render() {
10
- await super.render();
11
- if (callback) callback(this);
12
- }
13
- get template() {
14
- return customTemplate;
15
- }
16
- get childTemplate() {
17
- return childTemplate;
18
- }
19
- };
20
- defineComponent(tagName, cls);
21
- return cls;
22
- };