@startinblox/core 0.19.0-beta.1 → 0.19.0-beta.3

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 +54523 -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 -344
  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 -358
  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 -116
  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,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,267 +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(...args) {
8
- super(...args);
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('ldp:contains')[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, callback = () => {}) {
214
- if (!this._subscriptions.get(id)) {
215
- this._subscriptions.set(id, PubSub.subscribe(id, async () => {
216
- await callback();
217
- this.render();
218
- }));
219
- }
220
- }
221
-
222
- // Editable widgets
223
- addEditButtons() {
224
- const editableField = this.querySelector('[data-editable]');
225
- if (editableField) {
226
- // Add edit button
227
- const editButton = document.createElement('button');
228
- editButton.innerText = "Modifier";
229
- editButton.onclick = () => this.activateEditableField(editableField, editButton);
230
- editableField.insertAdjacentElement('afterend', editButton);
231
-
232
- // Save on focusout
233
- editableField.addEventListener('focusout', () => this.save(editableField, editButton));
234
- }
235
- }
236
- activateEditableField(editableField, editButton) {
237
- editableField.setAttribute('contenteditable', 'true');
238
- editableField.focus();
239
- editButton.setAttribute("disabled", "disabled");
240
- }
241
- /**
242
- * Dispatch change events of data holders from the current widget
243
- */
244
- initChangeEvents() {
245
- if (this.dataHolder) {
246
- const event = new Event('change', {
247
- bubbles: true
248
- });
249
- this.dataHolder.forEach(element => {
250
- element.addEventListener('change', e => {
251
- e.preventDefault();
252
- e.stopPropagation();
253
- this.dispatchEvent(event);
254
- });
255
- });
256
- }
257
- }
258
- save(editableField, editButton) {
259
- editableField.setAttribute('contenteditable', 'false');
260
- editButton.removeAttribute("disabled");
261
- if (!this.name) return;
262
- const resource = {};
263
- resource[this.name] = editableField.innerText;
264
- resource['@context'] = this.context;
265
- if (this.resourceId && resource) store.patch(resource, this.resourceId);
266
- }
267
- }
@@ -1,20 +0,0 @@
1
- import { BaseWidget } from './baseWidget.js';
2
- import { defineComponent } from '../libs/helpers.js';
3
- export const widgetFactory = (tagName, customTemplate, childTemplate = '', callback) => {
4
- const registered = customElements.get(tagName);
5
- if (registered) return registered;
6
- const cls = class extends BaseWidget {
7
- async render() {
8
- await super.render();
9
- if (callback) callback(this);
10
- }
11
- get template() {
12
- return customTemplate;
13
- }
14
- get childTemplate() {
15
- return childTemplate;
16
- }
17
- };
18
- defineComponent(tagName, cls);
19
- return cls;
20
- };