@startinblox/core 0.17.21-beta.1 → 0.17.21-beta.11
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.
- package/dist/_snowpack/env.js +3 -0
- package/dist/_snowpack/pkg/autolinker.js +4281 -0
- package/dist/_snowpack/pkg/autolinker.js.map +1 -0
- package/dist/_snowpack/pkg/autolinker.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/common/_baseUnary-217dffb2.js +377 -0
- package/dist/_snowpack/pkg/common/_baseUnary-217dffb2.js.map +1 -0
- package/dist/_snowpack/pkg/common/_baseUnary-217dffb2.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js +22 -0
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map +1 -0
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js +216 -0
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map +1 -0
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js +1119 -0
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map +1 -0
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +25677 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/dialog-polyfill.js +859 -0
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -0
- package/dist/_snowpack/pkg/dialog-polyfill.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/fusejs.js +1783 -0
- package/dist/_snowpack/pkg/fusejs.js.map +1 -0
- package/dist/_snowpack/pkg/fusejs.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/import-map.json +23 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js +804 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map +1 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/leaflet/dist/leaflet.css +640 -0
- package/dist/_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css +60 -0
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css +14 -0
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +40 -0
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +46 -0
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/until.js +88 -0
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/lit-html.js +92 -0
- package/dist/_snowpack/pkg/lit-html.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/markdown-it.js +11860 -0
- package/dist/_snowpack/pkg/markdown-it.js.map +1 -0
- package/dist/_snowpack/pkg/markdown-it.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/quill/dist/quill.snow.css +945 -0
- package/dist/_snowpack/pkg/quill/dist/quill.snow.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js +1029 -0
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +1 -0
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/quill.js +13382 -0
- package/dist/_snowpack/pkg/quill.js.map +1 -0
- package/dist/_snowpack/pkg/quill.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/slim-select.js +4 -0
- package/dist/_snowpack/pkg/slim-select.js.map +1 -0
- package/dist/_snowpack/pkg/slim-select.js.map.proxy.js +1 -0
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +1164 -0
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/tui-calendar.js +42285 -0
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -0
- package/dist/_snowpack/pkg/tui-calendar.js.map.proxy.js +1 -0
- package/dist/components/solid-ac-checker.js +51 -0
- package/dist/components/solid-ac-checker.js.map +1 -0
- package/dist/components/solid-calendar.js +87 -0
- package/dist/components/solid-calendar.js.map +1 -0
- package/dist/components/solid-delete.js +111 -0
- package/dist/components/solid-delete.js.map +1 -0
- package/dist/components/solid-display.js +194 -0
- package/dist/components/solid-display.js.map +1 -0
- package/dist/components/solid-form-search.js +226 -0
- package/dist/components/solid-form-search.js.map +1 -0
- package/dist/components/solid-form.js +358 -0
- package/dist/components/solid-form.js.map +1 -0
- package/dist/components/solid-lang.js +46 -0
- package/dist/components/solid-lang.js.map +1 -0
- package/dist/components/solid-map.js +242 -0
- package/dist/components/solid-map.js.map +1 -0
- package/dist/components/solid-table.js +263 -0
- package/dist/components/solid-table.js.map +1 -0
- package/dist/components/solid-widget.js +94 -0
- package/dist/components/solid-widget.js.map +1 -0
- package/dist/import.css +4 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/libs/Component.js +19 -0
- package/dist/libs/Component.js.map +1 -0
- package/dist/libs/ComponentFactory.js +196 -0
- package/dist/libs/ComponentFactory.js.map +1 -0
- package/dist/libs/Compositor.js +103 -0
- package/dist/libs/Compositor.js.map +1 -0
- package/dist/libs/Sib.js +58 -0
- package/dist/libs/Sib.js.map +1 -0
- package/dist/libs/filter.js +214 -0
- package/dist/libs/filter.js.map +1 -0
- package/dist/libs/helpers.js +219 -0
- package/dist/libs/helpers.js.map +1 -0
- package/dist/libs/interfaces.js +6 -0
- package/dist/libs/interfaces.js.map +1 -0
- package/dist/libs/lit-helpers.js +169 -0
- package/dist/libs/lit-helpers.js.map +1 -0
- package/dist/libs/polyfills.js +40 -0
- package/dist/libs/polyfills.js.map +1 -0
- package/dist/libs/store/server-pagination.js +20 -0
- package/dist/libs/store/server-pagination.js.map +1 -0
- package/dist/libs/store/store.js +879 -0
- package/dist/libs/store/store.js.map +1 -0
- package/dist/locales/en.json +10 -0
- package/dist/locales/en.json.proxy.js +2 -0
- package/dist/locales/fr.json +10 -0
- package/dist/locales/fr.json.proxy.js +2 -0
- package/dist/mixins/attributeBinderMixin.js +126 -0
- package/dist/mixins/attributeBinderMixin.js.map +1 -0
- package/dist/mixins/contextMixin.js +28 -0
- package/dist/mixins/contextMixin.js.map +1 -0
- package/dist/mixins/counterMixin.js +75 -0
- package/dist/mixins/counterMixin.js.map +1 -0
- package/dist/mixins/federationMixin.js +65 -0
- package/dist/mixins/federationMixin.js.map +1 -0
- package/dist/mixins/filterMixin.js +136 -0
- package/dist/mixins/filterMixin.js.map +1 -0
- package/dist/mixins/grouperMixin.js +80 -0
- package/dist/mixins/grouperMixin.js.map +1 -0
- package/dist/mixins/highlighterMixin.js +42 -0
- package/dist/mixins/highlighterMixin.js.map +1 -0
- package/dist/mixins/interfaces.js +8 -0
- package/dist/mixins/interfaces.js.map +1 -0
- package/dist/mixins/listMixin.js +138 -0
- package/dist/mixins/listMixin.js.map +1 -0
- package/dist/mixins/nextMixin.js +26 -0
- package/dist/mixins/nextMixin.js.map +1 -0
- package/dist/mixins/paginateMixin.js +110 -0
- package/dist/mixins/paginateMixin.js.map +1 -0
- package/dist/mixins/requiredMixin.js +34 -0
- package/dist/mixins/requiredMixin.js.map +1 -0
- package/dist/mixins/serverPaginationMixin.js +130 -0
- package/dist/mixins/serverPaginationMixin.js.map +1 -0
- package/dist/mixins/sorterMixin.js +149 -0
- package/dist/mixins/sorterMixin.js.map +1 -0
- package/dist/mixins/storeMixin.js +111 -0
- package/dist/mixins/storeMixin.js.map +1 -0
- package/dist/mixins/translationMixin.js +68 -0
- package/dist/mixins/translationMixin.js.map +1 -0
- package/dist/mixins/validationMixin.js +113 -0
- package/dist/mixins/validationMixin.js.map +1 -0
- package/dist/mixins/widgetMixin.js +451 -0
- package/dist/mixins/widgetMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/actionMixin.js +14 -0
- package/dist/new-widgets/attributeMixins/actionMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/blankMixin.js +10 -0
- package/dist/new-widgets/attributeMixins/blankMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/booleanMixin.js +10 -0
- package/dist/new-widgets/attributeMixins/booleanMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/index.js +20 -0
- package/dist/new-widgets/attributeMixins/index.js.map +1 -0
- package/dist/new-widgets/attributeMixins/mailtoMixin.js +10 -0
- package/dist/new-widgets/attributeMixins/mailtoMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/multipleMixin.js +28 -0
- package/dist/new-widgets/attributeMixins/multipleMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/numberMixin.js +10 -0
- package/dist/new-widgets/attributeMixins/numberMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/placeholderMixin.js +19 -0
- package/dist/new-widgets/attributeMixins/placeholderMixin.js.map +1 -0
- package/dist/new-widgets/attributeMixins/telMixin.js +10 -0
- package/dist/new-widgets/attributeMixins/telMixin.js.map +1 -0
- package/dist/new-widgets/baseWidgetMixin.js +122 -0
- package/dist/new-widgets/baseWidgetMixin.js.map +1 -0
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js +104 -0
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js.map +1 -0
- package/dist/new-widgets/callbackMixins/index.js +8 -0
- package/dist/new-widgets/callbackMixins/index.js.map +1 -0
- package/dist/new-widgets/callbackMixins/richtextMixin.js +42 -0
- package/dist/new-widgets/callbackMixins/richtextMixin.js.map +1 -0
- package/dist/new-widgets/callbackMixins/slimselect.css +2 -0
- package/dist/new-widgets/callbackMixins/slimselect.css.proxy.js +10 -0
- package/dist/new-widgets/new-widget-factory.js +96 -0
- package/dist/new-widgets/new-widget-factory.js.map +1 -0
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js +41 -0
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js.map +1 -0
- package/dist/new-widgets/templateAdditionMixins/index.js +14 -0
- package/dist/new-widgets/templateAdditionMixins/index.js.map +1 -0
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +29 -0
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js.map +1 -0
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js +31 -0
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js.map +1 -0
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js +36 -0
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js.map +1 -0
- package/dist/new-widgets/templates/displayTemplatesDirectory.js +90 -0
- package/dist/new-widgets/templates/displayTemplatesDirectory.js.map +1 -0
- package/dist/new-widgets/templates/formTemplatesDirectory.js +397 -0
- package/dist/new-widgets/templates/formTemplatesDirectory.js.map +1 -0
- package/dist/new-widgets/templates/groupTemplatesDirectory.js +21 -0
- package/dist/new-widgets/templates/groupTemplatesDirectory.js.map +1 -0
- package/dist/new-widgets/templates/index.js +7 -0
- package/dist/new-widgets/templates/index.js.map +1 -0
- package/dist/new-widgets/templates/setTemplatesDirectory.js +49 -0
- package/dist/new-widgets/templates/setTemplatesDirectory.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/altMixin.js +13 -0
- package/dist/new-widgets/templatesDependencies/altMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/editableMixin.js +77 -0
- package/dist/new-widgets/templatesDependencies/editableMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +38 -0
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +14 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +51 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +66 -0
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formFileMixin.js +81 -0
- package/dist/new-widgets/templatesDependencies/formFileMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js +19 -0
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +19 -0
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formMixin.js +66 -0
- package/dist/new-widgets/templatesDependencies/formMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js +14 -0
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js +16 -0
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/formStepMixin.js +13 -0
- package/dist/new-widgets/templatesDependencies/formStepMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js +14 -0
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +125 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +74 -0
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/patternMixin.js +19 -0
- package/dist/new-widgets/templatesDependencies/patternMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/rangeMixin.js +110 -0
- package/dist/new-widgets/templatesDependencies/rangeMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/setMixin.js +12 -0
- package/dist/new-widgets/templatesDependencies/setMixin.js.map +1 -0
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +12 -0
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +18 -0
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js +35 -0
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +16 -0
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/index.js +16 -0
- package/dist/new-widgets/valueTransformationMixins/index.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +25 -0
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +17 -0
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js.map +1 -0
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +27 -0
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js.map +1 -0
- package/dist/solid-template-element.js +164 -0
- package/dist/solid-template-element.js.map +1 -0
- package/dist/style/default-theme.css +24 -0
- package/dist/style/default-theme.css.proxy.js +10 -0
- package/dist/widgets/baseWidget.js +334 -0
- package/dist/widgets/baseWidget.js.map +1 -0
- package/dist/widgets/widget-factory.js +24 -0
- package/dist/widgets/widget-factory.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
function _templateObject() {
|
|
2
|
+
const data = _taggedTemplateLiteral(["\n <button\n data-id=\"prev\"\n ?disabled=", "\n @click=", "\n >\u2190</button>\n <button\n data-id=\"next\"\n ?disabled=", "\n @click=", "\n >\u2192</button>\n <span>\n <span data-id=\"current\">\n ", "\n </span> / \n <span data-id=\"count\">\n ", "\n </span>\n </span>\n "]);
|
|
3
|
+
|
|
4
|
+
_templateObject = function () {
|
|
5
|
+
return data;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
12
|
+
|
|
13
|
+
import { html, render } from "../_snowpack/pkg/lit-html.js";
|
|
14
|
+
const ServerPaginationMixin = {
|
|
15
|
+
name: 'server-pagination-mixin',
|
|
16
|
+
use: [],
|
|
17
|
+
attributes: {
|
|
18
|
+
limit: {
|
|
19
|
+
type: Number,
|
|
20
|
+
default: undefined
|
|
21
|
+
},
|
|
22
|
+
offset: {
|
|
23
|
+
type: Number,
|
|
24
|
+
default: undefined
|
|
25
|
+
},
|
|
26
|
+
pageCount: {
|
|
27
|
+
type: Number,
|
|
28
|
+
default: 1000
|
|
29
|
+
},
|
|
30
|
+
pageNumber: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 0
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
initialState: {
|
|
36
|
+
currentOffset: []
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
attached() {
|
|
40
|
+
if (this.limit) {
|
|
41
|
+
this.setCurrentOffset(this.resourceId, 0);
|
|
42
|
+
const parentDiv = this.initServerPaginationDiv(this.div);
|
|
43
|
+
this.renderCallbacks.push({
|
|
44
|
+
template: this.renderServerPaginationNav(this.resourceId, parentDiv),
|
|
45
|
+
parent: parentDiv
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getCurrentOffset(resourceId, limit) {
|
|
51
|
+
return this.currentOffset[resourceId + "#p" + limit];
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async setCurrentOffset(resourceId, offset) {
|
|
55
|
+
let index = resourceId + "#p" + this.limit;
|
|
56
|
+
this.currentOffset[index] = this.offset = offset;
|
|
57
|
+
this.pageNumber = Number(this.offset / this.limit);
|
|
58
|
+
this.currentPage[resourceId] = this.pageNumber;
|
|
59
|
+
await this.fetchData(this.dataSrc);
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
async decreaseCurrentOffset(resourceId) {
|
|
63
|
+
let index = resourceId + "#p" + this.limit;
|
|
64
|
+
this.currentOffset[index] = this.offset = this.offset - this.limit;
|
|
65
|
+
this.currentPage[index] = this.offset / this.limit;
|
|
66
|
+
this.pageNumber = this.offset / this.limit;
|
|
67
|
+
this.updateNavButtons(resourceId, index, -1);
|
|
68
|
+
await this.fetchData(this.dataSrc);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
async increaseCurrentOffset(resourceId) {
|
|
72
|
+
let index = resourceId + "#p" + this.limit;
|
|
73
|
+
this.currentOffset[index] = this.offset = this.offset + this.limit;
|
|
74
|
+
this.currentPage[index] = this.offset / this.limit;
|
|
75
|
+
this.updateNavButtons(resourceId, index, 1);
|
|
76
|
+
await this.fetchData(this.dataSrc);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
updateNavButtons(resourceId, index, variance) {
|
|
80
|
+
this.element.querySelector("[data-id='prev']").disabled = this.currentOffset[index] <= 0;
|
|
81
|
+
this.element.querySelector("[data-id='next']").disabled = this.currentOffset[index] * this.limit >= this.pageCount;
|
|
82
|
+
this.element.querySelector("[data-id='current']").innerText = this.getCurrentServedPage(resourceId, variance);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
getServerNavElement(div) {
|
|
86
|
+
if (div) {
|
|
87
|
+
const insertNode = div.parentNode || div;
|
|
88
|
+
return insertNode.querySelector("nav[data-id=\"nav\"]");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return null;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
getCurrentServedPage(context, variance) {
|
|
95
|
+
this.currentPage[context] = Number(this.currentPage[context]) + variance;
|
|
96
|
+
return this.currentPage[context];
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Find nav element or create it if not existing
|
|
101
|
+
* @param div - insert nav next to this div
|
|
102
|
+
*/
|
|
103
|
+
initServerPaginationDiv(div) {
|
|
104
|
+
let nav = this.getServerNavElement(div);
|
|
105
|
+
|
|
106
|
+
if (!nav) {
|
|
107
|
+
nav = document.createElement('nav');
|
|
108
|
+
nav.setAttribute('data-id', 'nav');
|
|
109
|
+
const insertNode = div.parentNode || div;
|
|
110
|
+
insertNode.appendChild(nav);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return nav;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create pagination template
|
|
118
|
+
*/
|
|
119
|
+
renderServerPaginationNav(resourceId, div) {
|
|
120
|
+
if (this.limit) {
|
|
121
|
+
const currentOffset = this.getCurrentOffset(resourceId, this.limit);
|
|
122
|
+
var currentPageNumber = this.getCurrentServedPage(resourceId, 1);
|
|
123
|
+
const pageCount = Math.ceil(this.pageCount / this.limit);
|
|
124
|
+
render(html(_templateObject(), currentOffset <= 0, () => this.decreaseCurrentOffset(resourceId), currentOffset >= (pageCount - 1) * this.limit, () => this.increaseCurrentOffset(resourceId), currentPageNumber, this.pageCount), div);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
};
|
|
129
|
+
export { ServerPaginationMixin };
|
|
130
|
+
//# sourceMappingURL=serverPaginationMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["serverPaginationMixin.ts"],"names":["html","render","ServerPaginationMixin","name","use","attributes","limit","type","Number","default","undefined","offset","pageCount","pageNumber","initialState","currentOffset","attached","setCurrentOffset","resourceId","parentDiv","initServerPaginationDiv","div","renderCallbacks","push","template","renderServerPaginationNav","parent","getCurrentOffset","index","currentPage","fetchData","dataSrc","decreaseCurrentOffset","updateNavButtons","increaseCurrentOffset","variance","element","querySelector","disabled","innerText","getCurrentServedPage","getServerNavElement","insertNode","parentNode","context","nav","document","createElement","setAttribute","appendChild","currentPageNumber","Math","ceil"],"mappings":";;;;;;;;;;;;AAAA,SAASA,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AAEA,MAAMC,qBAAqB,GAAG;AAC5BC,EAAAA,IAAI,EAAE,yBADsB;AAE5BC,EAAAA,GAAG,EAAE,EAFuB;AAG5BC,EAAAA,UAAU,EAAE;AACVC,IAAAA,KAAK,EAAE;AACLC,MAAAA,IAAI,EAAEC,MADD;AAELC,MAAAA,OAAO,EAAEC;AAFJ,KADG;AAKVC,IAAAA,MAAM,EAAE;AACNJ,MAAAA,IAAI,EAAEC,MADA;AAENC,MAAAA,OAAO,EAAEC;AAFH,KALE;AASVE,IAAAA,SAAS,EAAE;AACTL,MAAAA,IAAI,EAAEC,MADG;AAETC,MAAAA,OAAO,EAAE;AAFA,KATD;AAaVI,IAAAA,UAAU,EAAE;AACVN,MAAAA,IAAI,EAAEC,MADI;AAEVC,MAAAA,OAAO,EAAE;AAFC;AAbF,GAHgB;AAqB5BK,EAAAA,YAAY,EAAE;AACZC,IAAAA,aAAa,EAAE;AADH,GArBc;;AAyB5BC,EAAAA,QAAQ,GAAS;AACf,QAAI,KAAKV,KAAT,EAAgB;AACd,WAAKW,gBAAL,CAAsB,KAAKC,UAA3B,EAAuC,CAAvC;AACA,YAAMC,SAAS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oBD;AACF;;AAtI2B,CAA9B;AAyIA,SACEnB,qBADF","sourcesContent":["import { html, render } from \"lit-html\";\n\nconst ServerPaginationMixin = {\n name: 'server-pagination-mixin',\n use: [],\n attributes: {\n limit: {\n type: Number,\n default: undefined\n },\n offset: {\n type: Number,\n default: undefined\n },\n pageCount: {\n type: Number,\n default: 1000\n },\n pageNumber: {\n type: Number,\n default: 0\n }\n },\n initialState: {\n currentOffset: [],\n },\n\n attached(): void {\n if (this.limit) {\n this.setCurrentOffset(this.resourceId, 0);\n const parentDiv = this.initServerPaginationDiv(this.div);\n \n this.renderCallbacks.push({\n template: this.renderServerPaginationNav(this.resourceId, parentDiv),\n parent: parentDiv\n });\n }\n },\n\n getCurrentOffset(resourceId: string, limit: number) {\n return this.currentOffset[resourceId + \"#p\" + limit];\n },\n\n async setCurrentOffset(resourceId: string, offset: number): Promise<void> {\n let index = resourceId + \"#p\" + this.limit;\n this.currentOffset[index] = this.offset = offset;\n this.pageNumber = Number(this.offset / this.limit);\n this.currentPage[resourceId] = this.pageNumber;\n\n await this.fetchData(this.dataSrc);\n },\n\n async decreaseCurrentOffset(resourceId: string): Promise<void> {\n let index = resourceId + \"#p\" + this.limit;\n this.currentOffset[index] = this.offset = this.offset - this.limit;\n this.currentPage[index] = this.offset / this.limit;\n this.pageNumber = this.offset / this.limit;\n\n this.updateNavButtons(resourceId, index, -1);\n await this.fetchData(this.dataSrc);\n },\n\n async increaseCurrentOffset(resourceId: string): Promise<void> {\n let index = resourceId + \"#p\" + this.limit;\n this.currentOffset[index] = this.offset = this.offset + this.limit;\n this.currentPage[index] = this.offset / this.limit;\n\n this.updateNavButtons(resourceId, index, 1);\n await this.fetchData(this.dataSrc);\n },\n\n updateNavButtons(resourceId: string, index: string, variance: number) {\n this.element.querySelector(\"[data-id='prev']\").disabled = this.currentOffset[index] <= 0;\n this.element.querySelector(\"[data-id='next']\").disabled = this.currentOffset[index] * this.limit >= this.pageCount;\n this.element.querySelector(\"[data-id='current']\").innerText = this.getCurrentServedPage(resourceId, variance);\n },\n\n getServerNavElement(div: HTMLElement) {\n if(div) {\n const insertNode = div.parentNode || div;\n return insertNode.querySelector(`nav[data-id=\"nav\"]`);\n }\n\n return null;\n },\n\n getCurrentServedPage(context: string, variance: number): Promise<void> {\n this.currentPage[context] = Number(this.currentPage[context]) + variance;\n return this.currentPage[context];\n },\n\n /**\n * Find nav element or create it if not existing\n * @param div - insert nav next to this div\n */\n initServerPaginationDiv(div: HTMLElement) {\n let nav = this.getServerNavElement(div);\n if (!nav) {\n nav = document.createElement('nav');\n nav.setAttribute('data-id', 'nav');\n const insertNode = div.parentNode || div;\n insertNode.appendChild(nav);\n }\n return nav;\n },\n\n /**\n * Create pagination template\n */\n renderServerPaginationNav(resourceId: string, div: HTMLElement): void {\n if (this.limit) {\n const currentOffset = this.getCurrentOffset(resourceId, this.limit);\n var currentPageNumber = this.getCurrentServedPage(resourceId, 1);\n const pageCount = Math.ceil(this.pageCount / this.limit);\n\n render(html`\n <button\n data-id=\"prev\"\n ?disabled=${currentOffset <= 0}\n @click=${() => this.decreaseCurrentOffset(resourceId)}\n >←</button>\n <button\n data-id=\"next\"\n ?disabled=${currentOffset >= (pageCount - 1) * this.limit}\n @click=${ () => this.increaseCurrentOffset(resourceId)}\n >→</button>\n <span>\n <span data-id=\"current\">\n ${currentPageNumber}\n </span> / \n <span data-id=\"count\">\n ${this.pageCount}\n </span>\n </span>\n `, div);\n }\n },\n}\n\nexport {\n ServerPaginationMixin\n}"]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const SorterMixin = {
|
|
2
|
+
name: 'sorter-mixin',
|
|
3
|
+
use: [],
|
|
4
|
+
attributes: {
|
|
5
|
+
orderBy: {
|
|
6
|
+
type: String,
|
|
7
|
+
default: null
|
|
8
|
+
},
|
|
9
|
+
orderAsc: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: null
|
|
12
|
+
},
|
|
13
|
+
orderDesc: {
|
|
14
|
+
type: String,
|
|
15
|
+
default: null
|
|
16
|
+
},
|
|
17
|
+
orderByRandom: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: null
|
|
20
|
+
},
|
|
21
|
+
sortedBy: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: null,
|
|
24
|
+
|
|
25
|
+
callback(newValue) {
|
|
26
|
+
// if we change search form, re-populate
|
|
27
|
+
if (newValue && this.sortForm && newValue !== this.sortForm.getAttribute('id')) {
|
|
28
|
+
this.sortForm = null;
|
|
29
|
+
this.populate();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
initialState: {
|
|
36
|
+
randomOrder: null
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
attached() {
|
|
40
|
+
this.listPostProcessors.push(this.orderCallback.bind(this));
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
created() {
|
|
44
|
+
this.randomOrder = [];
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
async sorterList() {
|
|
48
|
+
if (!this.resource) return;
|
|
49
|
+
this.empty();
|
|
50
|
+
await this.populate();
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
linkSorterForm() {
|
|
54
|
+
this.sortForm.addEventListener('formChange', () => {
|
|
55
|
+
this.sorterList();
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async orderCallback(resources, listPostProcessors, div, context) {
|
|
60
|
+
if (this.orderBy) this.orderAsc = this.orderBy; // retrocompatibility. remove in 0.15
|
|
61
|
+
|
|
62
|
+
let sortingKey = '';
|
|
63
|
+
let orderValueToSort = ''; // if order-asc or order-desc attribute
|
|
64
|
+
|
|
65
|
+
if (this.orderAsc || this.orderDesc) {
|
|
66
|
+
sortingKey = this.orderAsc || this.orderDesc;
|
|
67
|
+
} // if sorted-by attribute (solid-form-search data used)
|
|
68
|
+
else if (this.sortedBy) {
|
|
69
|
+
const sortedBy = this.sortedBy;
|
|
70
|
+
|
|
71
|
+
if (sortedBy != null) {
|
|
72
|
+
if (!this.sortForm) {
|
|
73
|
+
this.sortForm = document.getElementById(sortedBy);
|
|
74
|
+
if (!this.sortForm) throw "#".concat(sortedBy, " is not in DOM");
|
|
75
|
+
this.linkSorterForm();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!this.sortForm.component.value.field) {
|
|
79
|
+
console.warn('The attribute field does not exist');
|
|
80
|
+
} else {
|
|
81
|
+
sortingKey = this.sortForm.component.value.field['value'];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const orderField = this.sortForm.component.value.order;
|
|
85
|
+
orderValueToSort = orderField && orderField.value ? orderField.value : 'asc';
|
|
86
|
+
}
|
|
87
|
+
} // sorting data according to the defined value of sortingKey
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (sortingKey) {
|
|
91
|
+
let orderToSort = true; // set 'asc' by default
|
|
92
|
+
|
|
93
|
+
if (this.orderDesc || orderValueToSort == "desc") orderToSort = false;
|
|
94
|
+
resources = (await Promise.all(resources.map(async resource => ({
|
|
95
|
+
sortingKey: await resource[sortingKey],
|
|
96
|
+
// fetch sorting value
|
|
97
|
+
proxy: resource // and keep proxy
|
|
98
|
+
|
|
99
|
+
})))).sort(this.sortValuesByKey("sortingKey", orderToSort)) // sort this array
|
|
100
|
+
.map(r => r.proxy); // re-create array
|
|
101
|
+
} // if order-by-random attribute
|
|
102
|
+
else if (this.isRandomSorted()) {
|
|
103
|
+
resources = this.shuffleResources(resources); // shuffle resources
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const nextProcessor = listPostProcessors.shift();
|
|
107
|
+
if (nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
isRandomSorted() {
|
|
111
|
+
return this.orderByRandom !== null;
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
sortValuesByKey(key, asc) {
|
|
115
|
+
return function (a, b) {
|
|
116
|
+
if (!a[key]) return 1;
|
|
117
|
+
if (!b[key]) return -1;
|
|
118
|
+
const varA = typeof a[key] === 'string' ? a[key].toUpperCase() : a[key];
|
|
119
|
+
const varB = typeof b[key] === 'string' ? b[key].toUpperCase() : b[key];
|
|
120
|
+
let comparison = 0;
|
|
121
|
+
if (varA > varB) comparison = asc ? 1 : -1;else if (varA < varB) comparison = asc ? -1 : 1;
|
|
122
|
+
return comparison;
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
shuffleResources(array) {
|
|
127
|
+
let currentIndex = array.length;
|
|
128
|
+
let temporaryValue;
|
|
129
|
+
let randomIndex;
|
|
130
|
+
|
|
131
|
+
if (this.randomOrder.length !== array.length) {
|
|
132
|
+
// if no random order existing
|
|
133
|
+
this.randomOrder = [...Array(array.length).keys()]; // generate array of indexes
|
|
134
|
+
|
|
135
|
+
while (0 !== currentIndex) {
|
|
136
|
+
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
137
|
+
currentIndex -= 1;
|
|
138
|
+
temporaryValue = this.randomOrder[currentIndex];
|
|
139
|
+
this.randomOrder[currentIndex] = this.randomOrder[randomIndex];
|
|
140
|
+
this.randomOrder[randomIndex] = temporaryValue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return this.randomOrder.map(i => array[i]); // rebuild array with random order
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
};
|
|
148
|
+
export { SorterMixin };
|
|
149
|
+
//# sourceMappingURL=sorterMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["sorterMixin.ts"],"names":["SorterMixin","name","use","attributes","orderBy","type","String","default","orderAsc","orderDesc","orderByRandom","sortedBy","callback","newValue","sortForm","getAttribute","populate","initialState","randomOrder","attached","listPostProcessors","push","orderCallback","bind","created","sorterList","resource","empty","linkSorterForm","addEventListener","resources","div","context","sortingKey","orderValueToSort","document","getElementById","component","value","field","console","warn","orderField","order","orderToSort","Promise","all","map","proxy","sort","sortValuesByKey","r","isRandomSorted","shuffleResources","nextProcessor","shift","key","asc","a","b","varA","toUpperCase","varB","comparison","array","currentIndex","length","temporaryValue","randomIndex","Array","keys","Math","floor","random","i"],"mappings":"AAAA,MAAMA,WAAW,GAAG;AAClBC,EAAAA,IAAI,EAAE,cADY;AAElBC,EAAAA,GAAG,EAAE,EAFa;AAGlBC,EAAAA,UAAU,EAAE;AACVC,IAAAA,OAAO,EAAE;AACPC,MAAAA,IAAI,EAAEC,MADC;AAEPC,MAAAA,OAAO,EAAE;AAFF,KADC;AAKVC,IAAAA,QAAQ,EAAE;AACRH,MAAAA,IAAI,EAAEC,MADE;AAERC,MAAAA,OAAO,EAAE;AAFD,KALA;AASVE,IAAAA,SAAS,EAAE;AACTJ,MAAAA,IAAI,EAAEC,MADG;AAETC,MAAAA,OAAO,EAAE;AAFA,KATD;AAaVG,IAAAA,aAAa,EAAE;AACbL,MAAAA,IAAI,EAAEC,MADO;AAEbC,MAAAA,OAAO,EAAE;AAFI,KAbL;AAiBVI,IAAAA,QAAQ,EAAE;AACRN,MAAAA,IAAI,EAACC,MADG;AAERC,MAAAA,OAAO,EAAE,IAFD;;AAGRK,MAAAA,QAAQ,CAACC,QAAD,EAAmB;AACzB;AACA,YAAIA,QAAQ,IAAI,KAAKC,QAAjB,IAA6BD,QAAQ,KAAK,KAAKC,QAAL,CAAcC,YAAd,CAA2B,IAA3B,CAA9C,EAAgF;AAC9E,eAAKD,QAAL,GAAgB,IAAhB;AACA,eAAKE,QAAL;AACD;AACF;;AATO;AAjBA,GAHM;AAgClBC,EAAAA,YAAY,EAAE;AACZC,IAAAA,WAAW,EAAE;AADD,GAhCI;;AAmClBC,EAAAA,QAAQ,GAAS;AACf,SAAKC,kBAAL,CAAwBC,IAAxB,CAA6B,KAAKC,aAAL,CAAmBC,IAAnB,CAAwB,IAAxB,CAA7B;AACD,GArCiB;;AAsClBC,EAAAA,OAAO,GAAS;AACd,SAAKN,WAAL,GAAmB,EAAnB;AACD,GA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CAAd;AACAA,QAAAA,YAAY,IAAI,CAAhB;AACAE,QAAAA,cAAc,GAAG,KAAKjD,WAAL,CAAiB+C,YAAjB,CAAjB;AACA,aAAK/C,WAAL,CAAiB+C,YAAjB,IAAiC,KAAK/C,WAAL,CAAiBkD,WAAjB,CAAjC;AACA,aAAKlD,WAAL,CAAiBkD,WAAjB,IAAgCD,cAAhC;AACD;AACF;;AACD,WAAO,KAAKjD,WAAL,CAAiB6B,GAAjB,CAAsB2B,CAAD,IAAeV,KAAK,CAACU,CAAD,CAAzC,CAAP,CAd0C,CAcY;AACvD;;AAlIiB,CAApB;AAqIA,SACE1E,WADF","sourcesContent":["const SorterMixin = {\n name: 'sorter-mixin',\n use: [],\n attributes: {\n orderBy: {\n type: String,\n default: null\n },\n orderAsc: {\n type: String,\n default: null\n },\n orderDesc: {\n type: String,\n default: null\n },\n orderByRandom: {\n type: String,\n default: null\n },\n sortedBy: {\n type:String,\n default: null,\n callback(newValue: string) {\n // if we change search form, re-populate\n if (newValue && this.sortForm && newValue !== this.sortForm.getAttribute('id')) {\n this.sortForm = null;\n this.populate();\n }\n }\n }\n },\n initialState: {\n randomOrder: null\n },\n attached(): void {\n this.listPostProcessors.push(this.orderCallback.bind(this));\n },\n created(): void {\n this.randomOrder = [];\n },\n async sorterList(): Promise<void> {\n if (!this.resource) return;\n this.empty();\n await this.populate();\n },\n linkSorterForm() {\n this.sortForm.addEventListener('formChange', () => {\n this.sorterList();\n });\n },\n\n async orderCallback(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string) { \n if (this.orderBy) this.orderAsc = this.orderBy; // retrocompatibility. remove in 0.15\n let sortingKey = '';\n let orderValueToSort = '';\n\n // if order-asc or order-desc attribute\n if (this.orderAsc || this.orderDesc) {\n sortingKey = this.orderAsc || this.orderDesc;\n }\n // if sorted-by attribute (solid-form-search data used)\n else if (this.sortedBy) {\n const sortedBy = this.sortedBy;\n if (sortedBy != null) {\n if (!this.sortForm) {\n this.sortForm = document.getElementById(sortedBy);\n if (!this.sortForm) throw `#${sortedBy} is not in DOM`; \n this.linkSorterForm();\n }\n if (!this.sortForm.component.value.field) {\n console.warn('The attribute field does not exist')\n } else { \n sortingKey = this.sortForm.component.value.field['value'];\n }\n const orderField = this.sortForm.component.value.order;\n orderValueToSort = orderField && orderField.value ? orderField.value : 'asc';\n }\n }\n // sorting data according to the defined value of sortingKey\n if (sortingKey) {\n let orderToSort = true; // set 'asc' by default\n if (this.orderDesc || orderValueToSort == \"desc\") orderToSort = false;\n resources = (await Promise.all(resources.map(async (resource) => ({\n sortingKey: await resource[sortingKey], // fetch sorting value\n proxy: resource // and keep proxy\n }))))\n .sort(this.sortValuesByKey(\"sortingKey\", orderToSort)) // sort this array\n .map(r => r.proxy) // re-create array\n }\n // if order-by-random attribute\n else if (this.isRandomSorted()) {\n resources = this.shuffleResources(resources); // shuffle resources\n }\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);\n },\n isRandomSorted(): boolean {\n return this.orderByRandom !== null;\n },\n sortValuesByKey(key: string, asc: boolean): Function {\n return function (a: object, b: object): number {\n if (!a[key]) return 1;\n if (!b[key]) return -1;\n\n const varA = typeof a[key] === 'string' ? a[key].toUpperCase() : a[key];\n const varB = typeof b[key] === 'string' ? b[key].toUpperCase() : b[key];\n let comparison = 0;\n if (varA > varB) comparison = asc ? 1 : -1;\n else if (varA < varB) comparison = asc ? -1 : 1;\n\n return comparison;\n }\n },\n shuffleResources(array: object[]): object[] {\n let currentIndex = array.length;\n let temporaryValue: object;\n let randomIndex: number;\n if (this.randomOrder.length !== array.length) { // if no random order existing\n this.randomOrder = [ ...Array(array.length).keys() ]; // generate array of indexes\n while (0 !== currentIndex) {\n randomIndex = Math.floor(Math.random() * currentIndex);\n currentIndex -= 1;\n temporaryValue = this.randomOrder[currentIndex];\n this.randomOrder[currentIndex] = this.randomOrder[randomIndex];\n this.randomOrder[randomIndex] = temporaryValue;\n }\n }\n return this.randomOrder.map((i: number) => array[i]); // rebuild array with random order\n }\n}\n\nexport {\n SorterMixin\n}"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { store } from '../libs/store/store.js';
|
|
2
|
+
import { AttributeBinderMixin } from './attributeBinderMixin.js';
|
|
3
|
+
import { ContextMixin } from './contextMixin.js';
|
|
4
|
+
import { ServerPaginationMixin } from './serverPaginationMixin.js';
|
|
5
|
+
import { formatAttributesToServerPaginationOptions } from '../libs/store/server-pagination.js';
|
|
6
|
+
const StoreMixin = {
|
|
7
|
+
name: 'store-mixin',
|
|
8
|
+
use: [AttributeBinderMixin, ContextMixin, ServerPaginationMixin],
|
|
9
|
+
attributes: {
|
|
10
|
+
noRender: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: null,
|
|
13
|
+
callback: function (value) {
|
|
14
|
+
if (value === null) this.fetchData(this.dataSrc);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
dataSrc: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: null,
|
|
20
|
+
callback: async function (value) {
|
|
21
|
+
if (this.noRender === null) await this.fetchData(value);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
loaderId: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: ''
|
|
27
|
+
},
|
|
28
|
+
nestedField: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: null
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
initialState: {
|
|
34
|
+
resourceId: null,
|
|
35
|
+
subscription: null
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
created() {
|
|
39
|
+
if (this.element.closest('[no-render]')) this.noRender = ''; // if embedded in no-render, apply no-render to himself
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
detached() {
|
|
43
|
+
if (this.subscription) PubSub.unsubscribe(this.subscription);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
get resource() {
|
|
47
|
+
let id = this.resourceId;
|
|
48
|
+
|
|
49
|
+
if (this.limit) {
|
|
50
|
+
id = this.resourceId + "#p" + this.limit + "?o" + this.offset;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return id ? store.get(id) : null;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
get loader() {
|
|
57
|
+
return this.loaderId ? document.getElementById(this.loaderId) : null;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
async fetchData(value) {
|
|
61
|
+
this.empty();
|
|
62
|
+
if (this.subscription) PubSub.unsubscribe(this.subscription);
|
|
63
|
+
if (!value || value == "undefined") return;
|
|
64
|
+
this.resourceId = value;
|
|
65
|
+
|
|
66
|
+
if (this.nestedField) {
|
|
67
|
+
const resource = await store.getData(value, this.context);
|
|
68
|
+
const nestedResource = resource ? await resource[this.nestedField] : null;
|
|
69
|
+
this.resourceId = nestedResource ? nestedResource['@id'] : null;
|
|
70
|
+
if (!this.resourceId) throw "Error: the key \"".concat(this.nestedField, "\" does not exist on the resource");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.updateNavigateSubscription();
|
|
74
|
+
this.subscription = PubSub.subscribe(this.resourceId, this.updateDOM.bind(this));
|
|
75
|
+
const serverPagination = formatAttributesToServerPaginationOptions(this.element.attributes);
|
|
76
|
+
await store.getData(this.resourceId, this.context, undefined, undefined, false, serverPagination);
|
|
77
|
+
this.updateDOM();
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
toggleLoaderHidden(toggle) {
|
|
81
|
+
if (this.loader) this.loader.toggleAttribute('hidden', toggle);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
updateNavigateSubscription() {},
|
|
85
|
+
|
|
86
|
+
async updateDOM() {
|
|
87
|
+
this.toggleLoaderHidden(false); // brings a loader out if the attribute is set
|
|
88
|
+
|
|
89
|
+
this.empty();
|
|
90
|
+
await this.replaceAttributesData();
|
|
91
|
+
await this.populate();
|
|
92
|
+
setTimeout(() => // Brings the dispatchEvent at the end of the queue
|
|
93
|
+
this.element.dispatchEvent(new CustomEvent('populate', {
|
|
94
|
+
detail: {
|
|
95
|
+
resource: {
|
|
96
|
+
"@id": this.dataSrc
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
})));
|
|
100
|
+
this.toggleLoaderHidden(true);
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
empty() {},
|
|
104
|
+
|
|
105
|
+
update() {
|
|
106
|
+
if (this.noRender === null) this.updateDOM();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
};
|
|
110
|
+
export { StoreMixin };
|
|
111
|
+
//# sourceMappingURL=storeMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["storeMixin.ts"],"names":["store","AttributeBinderMixin","ContextMixin","ServerPaginationMixin","formatAttributesToServerPaginationOptions","StoreMixin","name","use","attributes","noRender","type","String","default","callback","value","fetchData","dataSrc","loaderId","nestedField","initialState","resourceId","subscription","created","element","closest","detached","PubSub","unsubscribe","resource","id","limit","offset","get","loader","document","getElementById","empty","getData","context","nestedResource","updateNavigateSubscription","subscribe","updateDOM","bind","serverPagination","undefined","toggleLoaderHidden","toggle","toggleAttribute","replaceAttributesData","populate","setTimeout","dispatchEvent","CustomEvent","detail","update"],"mappings":"AAAA,SAASA,KAAT,QAAsB,qBAAtB;AACA,SAASC,oBAAT,QAAqC,wBAArC;AAEA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AACA,SAASC,yCAAT,QAA0D,iCAA1D;AAEA,MAAMC,UAAU,GAAG;AACjBC,EAAAA,IAAI,EAAE,aADW;AAEjBC,EAAAA,GAAG,EAAE,CAACN,oBAAD,EAAuBC,YAAvB,EAAqCC,qBAArC,CAFY;AAGjBK,EAAAA,UAAU,EAAE;AACVC,IAAAA,QAAQ,EAAE;AACRC,MAAAA,IAAI,EAAEC,MADE;AAERC,MAAAA,OAAO,EAAE,IAFD;AAGRC,MAAAA,QAAQ,EAAE,UAAUC,KAAV,EAA0B;AAClC,YAAIA,K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4B,QAA5B,EAAsCD,MAAtC;AAClB,GAvEgB;;AAwEjBP,EAAAA,0BAA0B,GAAG,CAAG,CAxEf;;AAyEjB,QAAME,SAAN,GAAiC;AAC/B,SAAKI,kBAAL,CAAwB,KAAxB,EAD+B,CACC;;AAChC,SAAKV,KAAL;AACA,UAAM,KAAKa,qBAAL,EAAN;AACA,UAAM,KAAKC,QAAL,EAAN;AACAC,IAAAA,UAAU,CAAC,MAAQ;AACjB,SAAK5B,OAAL,CAAa6B,aAAb,CAA2B,IAAIC,WAAJ,CAAgB,UAAhB,EAA4B;AAAEC,MAAAA,MAAM,EAAE;AAAE1B,QAAAA,QAAQ,EAAE;AAAC,iBAAO,KAAKZ;AAAb;AAAZ;AAAV,KAA5B,CAA3B,CADQ,CAAV;AAGA,SAAK8B,kBAAL,CAAwB,IAAxB;AACD,GAlFgB;;AAmFjBV,EAAAA,KAAK,GAAQ,CACZ,CApFgB;;AAqFjBmB,EAAAA,MAAM,GAAG;AACP,QAAI,KAAK9C,QAAL,KAAkB,IAAtB,EAA4B,KAAKiC,SAAL;AAC7B;;AAvFgB,CAAnB;AA0FA,SACErC,UADF","sourcesContent":["import { store } from '../libs/store/store';\nimport { AttributeBinderMixin } from './attributeBinderMixin';\nimport type { Resource } from './interfaces';\nimport { ContextMixin } from './contextMixin';\nimport { ServerPaginationMixin } from './serverPaginationMixin';\nimport { formatAttributesToServerPaginationOptions } from '../libs/store/server-pagination';\n\nconst StoreMixin = {\n name: 'store-mixin',\n use: [AttributeBinderMixin, ContextMixin, ServerPaginationMixin],\n attributes: {\n noRender: {\n type: String,\n default: null,\n callback: function (value: boolean) {\n if (value === null) this.fetchData(this.dataSrc);\n }\n },\n dataSrc: {\n type: String,\n default: null,\n callback: async function (value: string) {\n if (this.noRender === null) await this.fetchData(value);\n },\n },\n loaderId: {\n type: String,\n default: ''\n },\n nestedField: {\n type: String,\n default: null\n },\n },\n initialState: {\n resourceId: null,\n subscription: null,\n },\n created() {\n if (this.element.closest('[no-render]')) this.noRender = ''; // if embedded in no-render, apply no-render to himself\n },\n detached() {\n if (this.subscription) PubSub.unsubscribe(this.subscription);\n },\n get resource(): Resource|null{\n let id = this.resourceId;\n if (this.limit) {\n id = this.resourceId + \"#p\" + this.limit + \"?o\" + this.offset;\n }\n return id ? store.get(id) : null;\n },\n get loader(): HTMLElement | null {\n return this.loaderId ? document.getElementById(this.loaderId) : null;\n },\n \n async fetchData(value: string) {\n this.empty();\n if (this.subscription) PubSub.unsubscribe(this.subscription);\n if (!value || value == \"undefined\") return;\n\n this.resourceId = value;\n if (this.nestedField) {\n const resource = await store.getData(value, this.context);\n const nestedResource = resource ? await resource[this.nestedField] : null;\n this.resourceId = nestedResource ? nestedResource['@id'] : null;\n if (!this.resourceId) throw `Error: the key \"${this.nestedField}\" does not exist on the resource`\n }\n this.updateNavigateSubscription();\n\n this.subscription = PubSub.subscribe(this.resourceId, this.updateDOM.bind(this));\n const serverPagination = formatAttributesToServerPaginationOptions(this.element.attributes);\n await store.getData(this.resourceId, this.context, undefined, undefined, false, serverPagination);\n\n this.updateDOM();\n },\n\n toggleLoaderHidden(toggle: boolean): void {\n if (this.loader) this.loader.toggleAttribute('hidden', toggle);\n },\n updateNavigateSubscription() { },\n async updateDOM(): Promise<void> {\n this.toggleLoaderHidden(false); // brings a loader out if the attribute is set\n this.empty();\n await this.replaceAttributesData();\n await this.populate();\n setTimeout(() => ( // Brings the dispatchEvent at the end of the queue\n this.element.dispatchEvent(new CustomEvent('populate', { detail: { resource: {\"@id\": this.dataSrc} } })))\n );\n this.toggleLoaderHidden(true);\n },\n empty():void {\n },\n update() {\n if (this.noRender === null) this.updateDOM();\n }\n};\n\nexport {\n StoreMixin\n}"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { store } from "../libs/store/store.js";
|
|
2
|
+
const TranslationMixin = {
|
|
3
|
+
name: 'translation-mixin',
|
|
4
|
+
use: [],
|
|
5
|
+
initialState: {
|
|
6
|
+
translationData: {}
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
created() {
|
|
10
|
+
this.getLang();
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the translation module
|
|
15
|
+
* @param langCode - string: language needed in 2 char
|
|
16
|
+
* @returns - object: {key: translation}
|
|
17
|
+
*/
|
|
18
|
+
async getTranslationModule(langCode) {
|
|
19
|
+
const translationsModules = {
|
|
20
|
+
// define modules in a static way, snowpack does not support dynamic strings here
|
|
21
|
+
en: () => import("../locales/en.json.proxy.js"),
|
|
22
|
+
fr: () => import("../locales/fr.json.proxy.js")
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (!translationsModules[langCode]) {
|
|
26
|
+
// set default to EN if the file does not exist
|
|
27
|
+
console.warn("".concat(langCode, ".json translation file may not exist, English is setted by default"));
|
|
28
|
+
langCode = 'en';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const module = await translationsModules[langCode]();
|
|
32
|
+
return module.default;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Loads the right translation file and reload the component
|
|
37
|
+
*/
|
|
38
|
+
getLang() {
|
|
39
|
+
const languageStorage = store._getLanguage();
|
|
40
|
+
|
|
41
|
+
if (languageStorage) {
|
|
42
|
+
if (window.fetchTranslationPromise === undefined) {
|
|
43
|
+
// if translation data are not already fetched
|
|
44
|
+
window.fetchTranslationPromise = this.getTranslationModule(languageStorage);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
window.fetchTranslationPromise.then(res => {
|
|
48
|
+
if (res) {
|
|
49
|
+
this.translationData = res; // stock data in object passed to traduction method below
|
|
50
|
+
|
|
51
|
+
this.update(); // update the rendering in components and widgets
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns translation for a given key
|
|
59
|
+
* @param tradKey - string: key
|
|
60
|
+
* @returns - string: translation
|
|
61
|
+
*/
|
|
62
|
+
t(tradKey) {
|
|
63
|
+
return this.translationData[tradKey] || '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
};
|
|
67
|
+
export { TranslationMixin };
|
|
68
|
+
//# sourceMappingURL=translationMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["translationMixin.ts"],"names":["store","TranslationMixin","name","use","initialState","translationData","created","getLang","getTranslationModule","langCode","translationsModules","en","fr","console","warn","module","default","languageStorage","_getLanguage","window","fetchTranslationPromise","undefined","then","res","update","t","tradKey"],"mappings":"AAAA,SAASA,KAAT,QAAsB,qBAAtB;AAEA,MAAMC,gBAAgB,GAAG;AACvBC,EAAAA,IAAI,EAAE,mBADiB;AAEvBC,EAAAA,GAAG,EAAE,EAFkB;AAGvBC,EAAAA,YAAY,EAAE;AACZC,IAAAA,eAAe,EAAC;AADJ,GAHS;;AAMvBC,EAAAA,OAAO,GAAG;AACR,SAAKC,OAAL;AACD,GARsB;;AASvB;AACF;AACA;AACA;AACA;AACE,QAAMC,oBAAN,CAA2BC,QAA3B,EAA6C;AAC3C,UAAMC,mBAAmB,GAAG;AAAE;AAC5BC,MAAAA,EAAE,EAAE,MAAM,OAAO,oBAAP,CADgB;AAE1BC,MAAAA,EAAE,EAAE,MAAM,OAAO,oBAAP;AAFgB,KAA5B;;AAIA,QAAI,CAACF,mBAAmB,CAACD,QAAD,CAAxB,EAAoC;AAAE;AACpCI,MAAAA,OAAO,CAACC,IAAR,WAAgBL,QAAhB;AACAA,MAAAA,QAAQ,GAAG,IAAX;AACD;;AACD,UAAMM,MAAM,GAAG,MAAML,mBAAmB,CAACD,QAAD,CAAnB,EAArB;AACA,WAAOM,MAAM,CAACC,OAAd;AACD,GAzBsB;;AA0BvB;AACF;AACA;AACET,EAAAA,OAAO,GAAG;AACR,UAAMU,eAAe,GAAGjB,KAAK,CAACkB,YAAN,EAAxB;;AACA,QAAGD,eAAH,EAAoB;AAClB,UAAIE,MAAM,CAACC,uBAAP,KAAmCC,SAAvC,EAAkD;AAAE;AAClDF,QAAAA,MAAM,CAACC,uBAAP,GAAiC,KAAKZ,oBAAL,CAA0BS,eAA1B,CAAjC;AACD;;AACDE,MAAAA,MAAM,CAACC,uBAAP,CAA+BE,IAA/B,CAAoCC,GAAG,IAAI;AACzC,YAAIA,GAAJ,EAAS;AACP,eAAKlB,eAAL,GAAuBkB,GAAvB,CADO,CACqB;;AAC5B,eAAKC,MAAL,GAFO,CAEQ;AAChB;AACF,OALD;AAMD;AACF,GA1CsB;;AA2CvB;AACF;AACA;AACA;AACA;AACEC,EAAAA,CAAC,CAACC,OAAD,EAAkB;AACjB,WAAO,KAAKrB,eAAL,CAAqBqB,OAArB,KAAiC,EAAxC;AACD;;AAlDsB,CAAzB;AAqDA,SACEzB,gBADF","sourcesContent":["import { store } from \"../libs/store/store\";\n\nconst TranslationMixin = {\n name: 'translation-mixin',\n use: [],\n initialState: {\n translationData:{}\n },\n created() {\n this.getLang();\n },\n /**\n * Returns the translation module\n * @param langCode - string: language needed in 2 char\n * @returns - object: {key: translation}\n */\n async getTranslationModule(langCode: string) {\n const translationsModules = { // define modules in a static way, snowpack does not support dynamic strings here\n en: () => import('../locales/en.json'),\n fr: () => import('../locales/fr.json'),\n };\n if (!translationsModules[langCode]) { // set default to EN if the file does not exist\n console.warn(`${langCode}.json translation file may not exist, English is setted by default`);\n langCode = 'en';\n }\n const module = await translationsModules[langCode]();\n return module.default;\n },\n /**\n * Loads the right translation file and reload the component\n */\n getLang() {\n const languageStorage = store._getLanguage();\n if(languageStorage) {\n if (window.fetchTranslationPromise === undefined) { // if translation data are not already fetched\n window.fetchTranslationPromise = this.getTranslationModule(languageStorage);\n }\n window.fetchTranslationPromise.then(res => {\n if (res) {\n this.translationData = res; // stock data in object passed to traduction method below\n this.update(); // update the rendering in components and widgets\n }\n })\n }\n },\n /**\n * Returns translation for a given key\n * @param tradKey - string: key\n * @returns - string: translation\n */\n t(tradKey: string) {\n return this.translationData[tradKey] || '';\n }\n}\n\nexport {\n TranslationMixin\n}"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
function _templateObject3() {
|
|
2
|
+
const data = _taggedTemplateLiteral(["\n <p>", "</p>\n "]);
|
|
3
|
+
|
|
4
|
+
_templateObject3 = function () {
|
|
5
|
+
return data;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _templateObject2() {
|
|
12
|
+
const data = _taggedTemplateLiteral(["\n <", " value=", "></", ">\n "]);
|
|
13
|
+
|
|
14
|
+
_templateObject2 = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _templateObject() {
|
|
22
|
+
const data = _taggedTemplateLiteral(["\n <dialog id=\"", "\">\n ", "\n <div>\n <button\n @click=", " \n class=", "\n >\n ", "\n </button>\n <button\n @click=", "\n class=", "\n >\n ", "\n </button>\n </div>\n </dialog>\n "]);
|
|
23
|
+
|
|
24
|
+
_templateObject = function () {
|
|
25
|
+
return data;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
32
|
+
|
|
33
|
+
import dialogPolyfill from '../_snowpack/pkg/dialog-polyfill.js';
|
|
34
|
+
import { html } from '../_snowpack/pkg/lit-html.js';
|
|
35
|
+
import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
|
|
36
|
+
import { uniqID } from '../libs/helpers.js';
|
|
37
|
+
import { TranslationMixin } from './translationMixin.js';
|
|
38
|
+
import { preHTML } from '../libs/lit-helpers.js';
|
|
39
|
+
const ValidationMixin = {
|
|
40
|
+
name: 'validation-mixin',
|
|
41
|
+
use: [TranslationMixin],
|
|
42
|
+
attributes: {
|
|
43
|
+
confirmationMessage: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: null
|
|
46
|
+
},
|
|
47
|
+
confirmationType: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: null
|
|
50
|
+
},
|
|
51
|
+
confirmationSubmitText: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: null
|
|
54
|
+
},
|
|
55
|
+
confirmationCancelText: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: null
|
|
58
|
+
},
|
|
59
|
+
confirmationSubmitClass: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: undefined
|
|
62
|
+
},
|
|
63
|
+
confirmationCancelClass: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: undefined
|
|
66
|
+
},
|
|
67
|
+
confirmationWidget: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: undefined
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
created() {
|
|
74
|
+
this.dialogID = uniqID();
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
showModal() {
|
|
78
|
+
var dialog = document.getElementById(this.dialogID);
|
|
79
|
+
dialogPolyfill.registerDialog(dialog);
|
|
80
|
+
return dialog.showModal();
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
performAction() {
|
|
84
|
+
// Console warning if conf-type attr not filled AND conf-message filled
|
|
85
|
+
if (this.element.hasAttribute('confirmation-message') && !this.confirmationType) console.warn('confirmation-type attribute is missing.'); // Data directly submitted OR confirm dialog modal displayed
|
|
86
|
+
|
|
87
|
+
if (!this.confirmationType || this.confirmationType == "confirm" && confirm(this.confirmationMessage || this.t("validation.message"))) this.validateModal(); // Customisable dialog modal opened
|
|
88
|
+
|
|
89
|
+
if (this.confirmationType == "dialog") {
|
|
90
|
+
this.showModal();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
getModalDialog() {
|
|
95
|
+
if (this.confirmationType == 'dialog') {
|
|
96
|
+
const quitDialog = () => {
|
|
97
|
+
var dialog = document.getElementById(this.dialogID);
|
|
98
|
+
if (dialog == null) return;
|
|
99
|
+
dialog.close();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const confirmChoice = () => {
|
|
103
|
+
this.validateModal();
|
|
104
|
+
quitDialog();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return html(_templateObject(), this.dialogID, this.confirmationWidget ? preHTML(_templateObject2(), this.confirmationWidget, this.resourceId, this.confirmationWidget) : html(_templateObject3(), this.confirmationMessage || this.t("validation.message")), confirmChoice, ifDefined(this.confirmationSubmitClass), this.confirmationSubmitText || this.t("validation.submit-text"), quitDialog, ifDefined(this.confirmationCancelClass), this.confirmationCancelText || this.t("validation.cancel-text"));
|
|
108
|
+
} else return '';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
export { ValidationMixin };
|
|
113
|
+
//# sourceMappingURL=validationMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["validationMixin.ts"],"names":["dialogPolyfill","html","ifDefined","uniqID","TranslationMixin","preHTML","ValidationMixin","name","use","attributes","confirmationMessage","type","String","default","confirmationType","confirmationSubmitText","confirmationCancelText","confirmationSubmitClass","undefined","confirmationCancelClass","confirmationWidget","created","dialogID","showModal","dialog","document","getElementById","registerDialog","performAction","element","hasAttribute","console","warn","confirm","t","validateModal","getModalDialog","quitDialog","close","confirmChoice","resourceId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,cAAP,MAA2B,iBAA3B;AACA,SAASC,IAAT,QAAqB,UAArB;AACA,SAASC,SAAT,QAA0B,gCAA1B;AACA,SAASC,MAAT,QAAuB,iBAAvB;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,OAAT,QAAwB,qBAAxB;AAEA,MAAMC,eAAe,GAAG;AACtBC,EAAAA,IAAI,EAAE,kBADgB;AAEtBC,EAAAA,GA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{ html } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { uniqID } from '../libs/helpers';\nimport { TranslationMixin } from './translationMixin';\nimport { preHTML } from '../libs/lit-helpers';\n\nconst ValidationMixin = {\n name: 'validation-mixin',\n use: [TranslationMixin],\n attributes: {\n confirmationMessage: {\n type: String,\n default: null\n },\n confirmationType: {\n type: String,\n default: null\n },\n confirmationSubmitText: {\n type: String,\n default: null\n },\n confirmationCancelText: {\n type: String,\n default: null\n },\n confirmationSubmitClass: {\n type: String,\n default: undefined\n },\n confirmationCancelClass: {\n type: String,\n default: undefined\n },\n confirmationWidget: {\n type: String,\n default: undefined\n }\n },\n created() {\n this.dialogID = uniqID();\n },\n showModal() {\n var dialog: any = document.getElementById(this.dialogID);\n dialogPolyfill.registerDialog(dialog);\n return dialog.showModal();\n },\n performAction() {\n // Console warning if conf-type attr not filled AND conf-message filled\n if (this.element.hasAttribute('confirmation-message') && !this.confirmationType) console.warn('confirmation-type attribute is missing.');\n // Data directly submitted OR confirm dialog modal displayed\n if ((!this.confirmationType) || (this.confirmationType == \"confirm\" && confirm(this.confirmationMessage || this.t(\"validation.message\")))) this.validateModal();\n // Customisable dialog modal opened\n if (this.confirmationType == \"dialog\") {\n this.showModal();\n }\n },\n getModalDialog() {\n if (this.confirmationType == 'dialog') {\n const quitDialog = () => {\n var dialog: any = document.getElementById(this.dialogID);\n if (dialog == null) return;\n dialog.close();\n }\n const confirmChoice = () => {\n this.validateModal();\n quitDialog();\n }\n return html`\n <dialog id=\"${this.dialogID}\">\n ${this.confirmationWidget ? preHTML`\n <${this.confirmationWidget} value=${this.resourceId}></${this.confirmationWidget}>\n ` : html`\n <p>${this.confirmationMessage || this.t(\"validation.message\")}</p>\n `}\n <div>\n <button\n @click=${confirmChoice} \n class=${ifDefined(this.confirmationSubmitClass)}\n >\n ${this.confirmationSubmitText || this.t(\"validation.submit-text\")}\n </button>\n <button\n @click=${quitDialog}\n class=${ifDefined(this.confirmationCancelClass)}\n >\n ${this.confirmationCancelText || this.t(\"validation.cancel-text\")}\n </button>\n </div>\n </dialog>\n `\n } else return '';\n },\n}\n\nexport {\n ValidationMixin\n}"]}
|