@startinblox/core 0.0.0
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/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/_snowpack/pkg/autolinker.js +4429 -0
- package/dist/_snowpack/pkg/autolinker.js.map +1 -0
- package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js +353 -0
- package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js.map +1 -0
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js +26 -0
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +1 -0
- package/dist/_snowpack/pkg/common/decode-26fbf385.js +185 -0
- package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +1 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js +1104 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +26198 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +1 -0
- package/dist/_snowpack/pkg/dialog-polyfill.js +827 -0
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -0
- package/dist/_snowpack/pkg/fusejs.js +1593 -0
- package/dist/_snowpack/pkg/fusejs.js.map +1 -0
- package/dist/_snowpack/pkg/import-map.json +24 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js +836 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map +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 +39 -0
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +48 -0
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html/directives/until.js +87 -0
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map +1 -0
- package/dist/_snowpack/pkg/lit-html.js +94 -0
- package/dist/_snowpack/pkg/lit-html.js.map +1 -0
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js +68 -0
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +1 -0
- package/dist/_snowpack/pkg/markdown-it.js +11307 -0
- package/dist/_snowpack/pkg/markdown-it.js.map +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 +971 -0
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +1 -0
- package/dist/_snowpack/pkg/quill.js +14442 -0
- package/dist/_snowpack/pkg/quill.js.map +1 -0
- package/dist/_snowpack/pkg/slim-select.js +714 -0
- package/dist/_snowpack/pkg/slim-select.js.map +1 -0
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +1149 -0
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +10 -0
- package/dist/_snowpack/pkg/tui-calendar.js +46507 -0
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -0
- package/dist/components/solid-ac-checker.js +45 -0
- package/dist/components/solid-calendar.js +66 -0
- package/dist/components/solid-delete.js +96 -0
- package/dist/components/solid-display.js +150 -0
- package/dist/components/solid-form-search.js +177 -0
- package/dist/components/solid-form.js +259 -0
- package/dist/components/solid-lang.js +35 -0
- package/dist/components/solid-map.js +204 -0
- package/dist/components/solid-table.js +181 -0
- package/dist/components/solid-widget.js +72 -0
- package/dist/import.css +4 -0
- package/dist/index.js +49 -0
- package/dist/libs/Component.js +13 -0
- package/dist/libs/ComponentFactory.js +168 -0
- package/dist/libs/Compositor.js +96 -0
- package/dist/libs/Sib.js +44 -0
- package/dist/libs/filter.js +184 -0
- package/dist/libs/helpers.js +194 -0
- package/dist/libs/interfaces.js +6 -0
- package/dist/libs/lit-helpers.js +142 -0
- package/dist/libs/polyfills.js +37 -0
- package/dist/libs/store/server-pagination.js +22 -0
- package/dist/libs/store/server-search.js +35 -0
- package/dist/libs/store/store.js +814 -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 +116 -0
- package/dist/mixins/contextMixin.js +26 -0
- package/dist/mixins/counterMixin.js +54 -0
- package/dist/mixins/federationMixin.js +51 -0
- package/dist/mixins/filterMixin.js +155 -0
- package/dist/mixins/grouperMixin.js +73 -0
- package/dist/mixins/highlighterMixin.js +36 -0
- package/dist/mixins/interfaces.js +6 -0
- package/dist/mixins/listMixin.js +105 -0
- package/dist/mixins/nextMixin.js +23 -0
- package/dist/mixins/paginateMixin.js +97 -0
- package/dist/mixins/requiredMixin.js +26 -0
- package/dist/mixins/serverPaginationMixin.js +122 -0
- package/dist/mixins/sorterMixin.js +131 -0
- package/dist/mixins/storeMixin.js +109 -0
- package/dist/mixins/translationMixin.js +58 -0
- package/dist/mixins/validationMixin.js +95 -0
- package/dist/mixins/widgetMixin.js +351 -0
- package/dist/new-widgets/attributeMixins/actionMixin.js +13 -0
- package/dist/new-widgets/attributeMixins/blankMixin.js +7 -0
- package/dist/new-widgets/attributeMixins/booleanMixin.js +7 -0
- package/dist/new-widgets/attributeMixins/index.js +19 -0
- package/dist/new-widgets/attributeMixins/mailtoMixin.js +7 -0
- package/dist/new-widgets/attributeMixins/multipleMixin.js +27 -0
- package/dist/new-widgets/attributeMixins/numberMixin.js +7 -0
- package/dist/new-widgets/attributeMixins/placeholderMixin.js +16 -0
- package/dist/new-widgets/attributeMixins/telMixin.js +7 -0
- package/dist/new-widgets/baseWidgetMixin.js +109 -0
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js +96 -0
- package/dist/new-widgets/callbackMixins/index.js +7 -0
- package/dist/new-widgets/callbackMixins/richtextMixin.js +37 -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/interfaces.js +1 -0
- package/dist/new-widgets/new-widget-factory.js +91 -0
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js +26 -0
- package/dist/new-widgets/templateAdditionMixins/index.js +13 -0
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +16 -0
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js +18 -0
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js +29 -0
- package/dist/new-widgets/templates/displayTemplatesDirectory.js +54 -0
- package/dist/new-widgets/templates/formTemplatesDirectory.js +432 -0
- package/dist/new-widgets/templates/groupTemplatesDirectory.js +11 -0
- package/dist/new-widgets/templates/index.js +6 -0
- package/dist/new-widgets/templates/setTemplatesDirectory.js +16 -0
- package/dist/new-widgets/templatesDependencies/altMixin.js +12 -0
- package/dist/new-widgets/templatesDependencies/editableMixin.js +60 -0
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +34 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +10 -0
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +41 -0
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +56 -0
- package/dist/new-widgets/templatesDependencies/formFileMixin.js +82 -0
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js +18 -0
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +18 -0
- package/dist/new-widgets/templatesDependencies/formMixin.js +56 -0
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js +10 -0
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js +12 -0
- package/dist/new-widgets/templatesDependencies/formStepMixin.js +12 -0
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js +13 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +112 -0
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +65 -0
- package/dist/new-widgets/templatesDependencies/patternMixin.js +18 -0
- package/dist/new-widgets/templatesDependencies/rangeMixin.js +100 -0
- package/dist/new-widgets/templatesDependencies/setMixin.js +9 -0
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +9 -0
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +14 -0
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js +29 -0
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +12 -0
- package/dist/new-widgets/valueTransformationMixins/index.js +15 -0
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +30 -0
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +13 -0
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +21 -0
- package/dist/solid-template-element.js +144 -0
- package/dist/style/default-theme.css +24 -0
- package/dist/style/default-theme.css.proxy.js +10 -0
- package/dist/widgets/baseWidget.js +268 -0
- package/dist/widgets/widget-factory.js +22 -0
- package/package.json +117 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import JSONLDContextParser from '../_snowpack/pkg/jsonld-context-parser.js';
|
|
2
|
+
import { Sib } from '../libs/Sib.js';
|
|
3
|
+
import { StoreMixin } from '../mixins/storeMixin.js';
|
|
4
|
+
export const SolidAcChecker = {
|
|
5
|
+
name: 'solid-ac-checker',
|
|
6
|
+
use: [StoreMixin],
|
|
7
|
+
attributes: {
|
|
8
|
+
permission: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: ''
|
|
11
|
+
},
|
|
12
|
+
noPermission: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: ''
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async populate() {
|
|
18
|
+
if (!this.resource) return;
|
|
19
|
+
let displayElement;
|
|
20
|
+
const ContextParser = JSONLDContextParser.ContextParser;
|
|
21
|
+
const myParser = new ContextParser();
|
|
22
|
+
const context = await myParser.parse(this.context);
|
|
23
|
+
const permissions = await this.resource.permissions;
|
|
24
|
+
if (this.permission) {
|
|
25
|
+
// User has permission of ...
|
|
26
|
+
displayElement = permissions.some(p => {
|
|
27
|
+
return ContextParser.compactIri(p, context) === this.permission;
|
|
28
|
+
});
|
|
29
|
+
} else if (this.noPermission) {
|
|
30
|
+
// User has no permission of ...
|
|
31
|
+
displayElement = permissions.every(p => {
|
|
32
|
+
return ContextParser.compactIri(p, context) !== this.noPermission;
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
// No parameter provided
|
|
36
|
+
console.warn('solid-ac-checker: you should define at least one of "permission" or "no-permission" attribute.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (displayElement) this.element.removeAttribute('hidden');
|
|
40
|
+
},
|
|
41
|
+
empty() {
|
|
42
|
+
this.element.setAttribute('hidden', '');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
Sib.register(SolidAcChecker);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Sib } from '../libs/Sib.js';
|
|
2
|
+
import { ListMixin } from '../mixins/listMixin.js';
|
|
3
|
+
import { StoreMixin } from '../mixins/storeMixin.js';
|
|
4
|
+
import { NextMixin } from '../mixins/nextMixin.js';
|
|
5
|
+
import { store } from '../libs/store/store.js';
|
|
6
|
+
import { uniqID } from '../libs/helpers.js';
|
|
7
|
+
import Calendar from '../_snowpack/pkg/tui-calendar.js';
|
|
8
|
+
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
9
|
+
export const SolidCalendar = {
|
|
10
|
+
name: 'solid-calendar',
|
|
11
|
+
use: [ListMixin, StoreMixin, NextMixin],
|
|
12
|
+
initialState: {
|
|
13
|
+
subscriptions: null
|
|
14
|
+
},
|
|
15
|
+
created() {
|
|
16
|
+
//@ts-ignore
|
|
17
|
+
import("../_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js");
|
|
18
|
+
const id = uniqID();
|
|
19
|
+
const template = html`
|
|
20
|
+
<div id=${id} style="width:100%;height:100%;"></div>
|
|
21
|
+
`;
|
|
22
|
+
render(template, this.element);
|
|
23
|
+
this.calendar = new Calendar(this.element.querySelector(`#${id}`), {
|
|
24
|
+
defaultView: 'month'
|
|
25
|
+
});
|
|
26
|
+
this.calendar.on('clickSchedule', this.dispatchSelect.bind(this));
|
|
27
|
+
this.subscriptions = new Map();
|
|
28
|
+
},
|
|
29
|
+
get extra_context() {
|
|
30
|
+
return {
|
|
31
|
+
date: "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
dispatchSelect(event) {
|
|
35
|
+
const resource = {
|
|
36
|
+
'@id': event['schedule'].id
|
|
37
|
+
};
|
|
38
|
+
this.element.dispatchEvent(new CustomEvent('resourceSelect', {
|
|
39
|
+
detail: {
|
|
40
|
+
resource: resource
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
this.goToNext(resource);
|
|
44
|
+
},
|
|
45
|
+
async appendChildElt(resourceId) {
|
|
46
|
+
const resource = await store.getData(resourceId, this.context);
|
|
47
|
+
if (!resource) return;
|
|
48
|
+
if (!this.subscriptions.get(resourceId)) {
|
|
49
|
+
this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()));
|
|
50
|
+
} // TODO : mixin gestion des enfants
|
|
51
|
+
const date = await resource['date'];
|
|
52
|
+
const name = await resource['name'];
|
|
53
|
+
if (name && date) {
|
|
54
|
+
this.calendar.createSchedules([{
|
|
55
|
+
id: resource['@id'],
|
|
56
|
+
title: name.toString(),
|
|
57
|
+
category: 'time',
|
|
58
|
+
start: date.toString()
|
|
59
|
+
}]);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
empty() {
|
|
63
|
+
this.calendar.clear();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
Sib.register(SolidCalendar);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Sib } from '../libs/Sib.js';
|
|
2
|
+
import { base_context, store } from '../libs/store/store.js';
|
|
3
|
+
import { NextMixin } from '../mixins/nextMixin.js';
|
|
4
|
+
import { ValidationMixin } from '../mixins/validationMixin.js';
|
|
5
|
+
import { AttributeBinderMixin } from '../mixins/attributeBinderMixin.js';
|
|
6
|
+
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
7
|
+
export const SolidDelete = {
|
|
8
|
+
name: 'solid-delete',
|
|
9
|
+
use: [NextMixin, ValidationMixin, AttributeBinderMixin],
|
|
10
|
+
attributes: {
|
|
11
|
+
dataSrc: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: null,
|
|
14
|
+
callback: function () {
|
|
15
|
+
this.resourceId = this.dataSrc;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
dataLabel: {
|
|
19
|
+
type: String,
|
|
20
|
+
default: null,
|
|
21
|
+
callback: function (newValue, oldValue) {
|
|
22
|
+
if (newValue !== oldValue) this.planRender();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
extraContext: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: null
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
initialState: {
|
|
31
|
+
renderPlanned: false
|
|
32
|
+
},
|
|
33
|
+
created() {
|
|
34
|
+
this.planRender();
|
|
35
|
+
},
|
|
36
|
+
planRender() {
|
|
37
|
+
if (!this.renderPlanned) {
|
|
38
|
+
this.renderPlanned = true;
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
this.render();
|
|
41
|
+
this.renderPlanned = false;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
get context() {
|
|
46
|
+
let extraContextElement = this.extraContext ? document.getElementById(this.extraContext) :
|
|
47
|
+
// take element extra context first
|
|
48
|
+
document.querySelector('[data-default-context]'); // ... or look for a default extra context
|
|
49
|
+
|
|
50
|
+
let extraContext = {};
|
|
51
|
+
if (extraContextElement) extraContext = JSON.parse(extraContextElement.textContent || "{}");
|
|
52
|
+
return {
|
|
53
|
+
...base_context,
|
|
54
|
+
...extraContext
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
async delete(e) {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
if (!this.dataSrc) return;
|
|
60
|
+
this.performAction(); // In validationMixin, method defining what to do according to the present attributes
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
deletion() {
|
|
64
|
+
return store.delete(this.dataSrc, this.context).then(response => {
|
|
65
|
+
if (!response.ok) return;
|
|
66
|
+
this.goToNext(null);
|
|
67
|
+
const eventData = {
|
|
68
|
+
detail: {
|
|
69
|
+
resource: {
|
|
70
|
+
"@id": this.dataSrc
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
bubbles: true
|
|
74
|
+
};
|
|
75
|
+
this.element.dispatchEvent(new CustomEvent('save', eventData));
|
|
76
|
+
this.element.dispatchEvent(new CustomEvent('resourceDeleted', eventData)); // Deprecated. To remove in 0.15
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
validateModal() {
|
|
81
|
+
// Send method to validationMixin, used by the dialog modal and performAction method
|
|
82
|
+
return this.deletion();
|
|
83
|
+
},
|
|
84
|
+
update() {
|
|
85
|
+
this.render();
|
|
86
|
+
},
|
|
87
|
+
async render() {
|
|
88
|
+
await this.replaceAttributesData(false);
|
|
89
|
+
const button = html`
|
|
90
|
+
<button @click=${this.delete.bind(this)}>${this.dataLabel || this.t("solid-delete.button")}</button>
|
|
91
|
+
${this.getModalDialog()}
|
|
92
|
+
`;
|
|
93
|
+
render(button, this.element);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
Sib.register(SolidDelete);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Sib } from '../libs/Sib.js';
|
|
2
|
+
import { WidgetMixin } from '../mixins/widgetMixin.js';
|
|
3
|
+
import { ListMixin } from '../mixins/listMixin.js';
|
|
4
|
+
import { StoreMixin } from '../mixins/storeMixin.js';
|
|
5
|
+
import { PaginateMixin } from '../mixins/paginateMixin.js';
|
|
6
|
+
import { FilterMixin } from '../mixins/filterMixin.js';
|
|
7
|
+
import { CounterMixin } from '../mixins/counterMixin.js';
|
|
8
|
+
import { SorterMixin } from '../mixins/sorterMixin.js';
|
|
9
|
+
import { GrouperMixin } from '../mixins/grouperMixin.js';
|
|
10
|
+
import { FederationMixin } from '../mixins/federationMixin.js';
|
|
11
|
+
import { HighlighterMixin } from '../mixins/highlighterMixin.js';
|
|
12
|
+
import { NextMixin } from '../mixins/nextMixin.js';
|
|
13
|
+
import { RequiredMixin } from '../mixins/requiredMixin.js';
|
|
14
|
+
import { spread } from '../libs/lit-helpers.js';
|
|
15
|
+
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
16
|
+
import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
|
|
17
|
+
export const SolidDisplay = {
|
|
18
|
+
name: 'solid-display',
|
|
19
|
+
use: [WidgetMixin, ListMixin, StoreMixin, PaginateMixin, GrouperMixin, CounterMixin, HighlighterMixin, FilterMixin, SorterMixin, RequiredMixin, FederationMixin, NextMixin],
|
|
20
|
+
attributes: {
|
|
21
|
+
defaultWidget: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: 'solid-display-value'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
initialState: {
|
|
27
|
+
activeSubscription: null,
|
|
28
|
+
removeActiveSubscription: null
|
|
29
|
+
},
|
|
30
|
+
created() {
|
|
31
|
+
// Set route active at initialization
|
|
32
|
+
const route = document.querySelector('solid-route[active]');
|
|
33
|
+
if (!route) return;
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
if (route['resourceId'] === this.resourceId) this.addActiveCallback();
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
detached() {
|
|
39
|
+
if (this.activeSubscription) PubSub.unsubscribe(this.activeSubscription);
|
|
40
|
+
if (this.removeActiveSubscription) PubSub.unsubscribe(this.removeActiveSubscription);
|
|
41
|
+
},
|
|
42
|
+
// Update subscription when id changes
|
|
43
|
+
updateNavigateSubscription() {
|
|
44
|
+
if (this.activeSubscription) PubSub.unsubscribe(this.activeSubscription);
|
|
45
|
+
if (this.resourceId) {
|
|
46
|
+
this.activeSubscription = PubSub.subscribe('enterRoute.' + this.resourceId, this.addActiveCallback.bind(this));
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
addActiveCallback() {
|
|
50
|
+
this.element.setAttribute('active', '');
|
|
51
|
+
this.removeActiveSubscription = PubSub.subscribe('leaveRoute', this.removeActiveCallback.bind(this));
|
|
52
|
+
},
|
|
53
|
+
removeActiveCallback() {
|
|
54
|
+
this.element.removeAttribute('active');
|
|
55
|
+
PubSub.unsubscribe(this.removeActiveSubscription);
|
|
56
|
+
},
|
|
57
|
+
get childTag() {
|
|
58
|
+
return this.element.dataset.child || this.element.tagName;
|
|
59
|
+
},
|
|
60
|
+
get defaultMultipleWidget() {
|
|
61
|
+
return 'solid-multiple';
|
|
62
|
+
},
|
|
63
|
+
get defaultSetWidget() {
|
|
64
|
+
return 'solid-set-default';
|
|
65
|
+
},
|
|
66
|
+
// Here "even.target" points to the content of the widgets of the children of solid-display
|
|
67
|
+
dispatchSelect(event, resourceId) {
|
|
68
|
+
const linkTarget = event.target.closest('a');
|
|
69
|
+
if (linkTarget && linkTarget.hasAttribute('href')) return;
|
|
70
|
+
const resource = {
|
|
71
|
+
"@id": resourceId
|
|
72
|
+
};
|
|
73
|
+
this.element.dispatchEvent(new CustomEvent('resourceSelect', {
|
|
74
|
+
detail: {
|
|
75
|
+
resource: resource
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
this.goToNext(resource);
|
|
79
|
+
},
|
|
80
|
+
enterKeydownAction(event, resourceId) {
|
|
81
|
+
if (event.keyCode === 13) {
|
|
82
|
+
const resource = {
|
|
83
|
+
"@id": resourceId
|
|
84
|
+
};
|
|
85
|
+
this.goToNext(resource);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Returns template of a child element (resource)
|
|
90
|
+
* @param resourceId
|
|
91
|
+
* @param attributes
|
|
92
|
+
*/
|
|
93
|
+
getChildTemplate(resourceId, attributes) {
|
|
94
|
+
let template = html`
|
|
95
|
+
<solid-display
|
|
96
|
+
data-src=${resourceId}
|
|
97
|
+
@click=${event => this.dispatchSelect(event, resourceId)}
|
|
98
|
+
@keydown=${event => this.enterKeydownAction(event, resourceId)}
|
|
99
|
+
fields=${ifDefined(this.fields)}
|
|
100
|
+
...=${spread(attributes)}
|
|
101
|
+
></solid-display>
|
|
102
|
+
`;
|
|
103
|
+
return template;
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Creates and render the content of a single element (resource)
|
|
107
|
+
* @param parent
|
|
108
|
+
*/
|
|
109
|
+
async appendSingleElt(parent) {
|
|
110
|
+
const fields = await this.getFields();
|
|
111
|
+
const widgetTemplates = await Promise.all(
|
|
112
|
+
// generate all widget templates
|
|
113
|
+
fields.map(field => this.createWidgetTemplate(field)));
|
|
114
|
+
render(html`${widgetTemplates}`, parent);
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* @override listMixin method to use litHtml
|
|
118
|
+
*
|
|
119
|
+
* Render resources from a container
|
|
120
|
+
* @param resources
|
|
121
|
+
* @param listPostProcessors
|
|
122
|
+
* @param div
|
|
123
|
+
* @param context
|
|
124
|
+
*/
|
|
125
|
+
async renderDOM(resources, listPostProcessors, div, context) {
|
|
126
|
+
const attributes = this.getChildAttributes(); // get attributes of children only once
|
|
127
|
+
// and create a child template for each resource
|
|
128
|
+
const template = html`${resources.map(r => r ? this.getChildTemplate(r['@id'], attributes) : null)}`;
|
|
129
|
+
render(template, div);
|
|
130
|
+
const nextProcessor = listPostProcessors.shift();
|
|
131
|
+
if (nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* Get attributes to dispatch to children from current element
|
|
135
|
+
*/
|
|
136
|
+
getChildAttributes() {
|
|
137
|
+
const attributes = {};
|
|
138
|
+
for (let attr of this.element.attributes) {
|
|
139
|
+
//copy widget and value attributes
|
|
140
|
+
if (attr.name.startsWith('value-') || attr.name.startsWith('label-') || attr.name.startsWith('placeholder-') || attr.name.startsWith('widget-') || attr.name.startsWith('class-') || attr.name.startsWith('multiple-') || attr.name.startsWith('editable-') || attr.name.startsWith('action-') || attr.name.startsWith('default-') || attr.name.startsWith('link-text-') || attr.name == 'extra-context') attributes[attr.name] = attr.value;
|
|
141
|
+
if (attr.name.startsWith('child-')) attributes[attr.name.replace(/^child-/, '')] = attr.value;
|
|
142
|
+
if (attr.name == 'next') {
|
|
143
|
+
attributes['role'] = 'button';
|
|
144
|
+
attributes['tabindex'] = '0';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return attributes;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
Sib.register(SolidDisplay);
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Sib } from '../libs/Sib.js';
|
|
2
|
+
import { WidgetMixin } from '../mixins/widgetMixin.js';
|
|
3
|
+
import { AttributeBinderMixin } from '../mixins/attributeBinderMixin.js';
|
|
4
|
+
import { ContextMixin } from '../mixins/contextMixin.js';
|
|
5
|
+
import { newWidgetFactory } from '../new-widgets/new-widget-factory.js';
|
|
6
|
+
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
7
|
+
import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
|
|
8
|
+
import { uniqID } from '../libs/helpers.js';
|
|
9
|
+
export const SolidFormSearch = {
|
|
10
|
+
name: 'solid-form-search',
|
|
11
|
+
use: [WidgetMixin, AttributeBinderMixin, ContextMixin],
|
|
12
|
+
attributes: {
|
|
13
|
+
defaultWidget: {
|
|
14
|
+
type: String,
|
|
15
|
+
default: 'solid-form-label-text'
|
|
16
|
+
},
|
|
17
|
+
submitButton: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: null,
|
|
20
|
+
callback: function (newValue, oldValue) {
|
|
21
|
+
if (this.noRender == null && newValue !== oldValue) this.populate();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
submitWidget: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: undefined
|
|
27
|
+
},
|
|
28
|
+
classSubmitButton: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: undefined
|
|
31
|
+
},
|
|
32
|
+
noRender: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: null,
|
|
35
|
+
callback: function (value) {
|
|
36
|
+
if (value === null) this.populate();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
initialState: {
|
|
41
|
+
error: ''
|
|
42
|
+
},
|
|
43
|
+
created() {
|
|
44
|
+
if (this.element.closest('[no-render]')) this.noRender = ''; // if embedded in no-render, apply no-render to himself
|
|
45
|
+
this.autoRangeValues = {};
|
|
46
|
+
this.rangeId = uniqID();
|
|
47
|
+
this.attachedElements = new Set();
|
|
48
|
+
},
|
|
49
|
+
get defaultMultipleWidget() {
|
|
50
|
+
return 'solid-multiple-form';
|
|
51
|
+
},
|
|
52
|
+
get defaultSetWidget() {
|
|
53
|
+
return 'solid-set-default';
|
|
54
|
+
},
|
|
55
|
+
// Returns the current value of the search from
|
|
56
|
+
// As a search query object
|
|
57
|
+
get value() {
|
|
58
|
+
const values = {};
|
|
59
|
+
this.widgets.forEach(widget => {
|
|
60
|
+
const name = (widget.component || widget).name;
|
|
61
|
+
if (name == null) return;
|
|
62
|
+
let value = widget.component ? widget.component.getValue() : widget.value;
|
|
63
|
+
try {
|
|
64
|
+
value = JSON.parse(value);
|
|
65
|
+
} catch {}
|
|
66
|
+
// Add another filter value in the values array
|
|
67
|
+
value = {
|
|
68
|
+
type: widget.component.type,
|
|
69
|
+
list: !!widget.component.multiple,
|
|
70
|
+
value: value
|
|
71
|
+
};
|
|
72
|
+
values[name] = value;
|
|
73
|
+
});
|
|
74
|
+
return values;
|
|
75
|
+
},
|
|
76
|
+
getWidget(field) {
|
|
77
|
+
let isSet = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
78
|
+
let tagName = '';
|
|
79
|
+
// If auto-range-[field] exists, create range-[field] and sets its value
|
|
80
|
+
if (this.element.hasAttribute('auto-range-' + field) && !this.element.hasAttribute('range-' + field)) {
|
|
81
|
+
const idField = `${this.rangeId}_${field}`;
|
|
82
|
+
this.element.setAttribute('range-' + field, 'store://local.' + idField);
|
|
83
|
+
this.populate();
|
|
84
|
+
}
|
|
85
|
+
const widgetAttribute = this.element.getAttribute('widget-' + field);
|
|
86
|
+
// Choose widget
|
|
87
|
+
if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {
|
|
88
|
+
tagName = 'solid-form-dropdown';
|
|
89
|
+
} else {
|
|
90
|
+
tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);
|
|
91
|
+
}
|
|
92
|
+
// Create widget
|
|
93
|
+
if (!customElements.get(tagName)) {
|
|
94
|
+
// component does not exist
|
|
95
|
+
if (tagName.startsWith('solid')) newWidgetFactory(tagName); // solid- -> create it
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.widgetFromTagName(tagName);
|
|
99
|
+
},
|
|
100
|
+
async attach(elm) {
|
|
101
|
+
if (this.attachedElements.has(elm)) return;
|
|
102
|
+
this.attachedElements.add(elm);
|
|
103
|
+
await this.updateAutoRanges();
|
|
104
|
+
},
|
|
105
|
+
async detach(elm) {
|
|
106
|
+
if (!this.attachedElements.has(elm)) return;
|
|
107
|
+
this.attachedElements.delete(elm);
|
|
108
|
+
await this.updateAutoRanges();
|
|
109
|
+
},
|
|
110
|
+
async updateAutoRanges() {
|
|
111
|
+
for (const attr of this.element.attributes) {
|
|
112
|
+
if (!attr['name'].startsWith('auto-range-')) continue;
|
|
113
|
+
const field = attr['name'].replace('auto-range-', '');
|
|
114
|
+
const autoRangeValues = new Set();
|
|
115
|
+
for (const elm of this.attachedElements) {
|
|
116
|
+
for (const value of await elm.getValuesOfField(field)) {
|
|
117
|
+
autoRangeValues.add(value);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const idField = `${this.rangeId}_${field}`;
|
|
121
|
+
const id = `store://local.${idField}`;
|
|
122
|
+
const ldpContains = Array.from(autoRangeValues).map(id => ({
|
|
123
|
+
'@id': id
|
|
124
|
+
}));
|
|
125
|
+
const data = {
|
|
126
|
+
"@type": "ldp:Container",
|
|
127
|
+
"@context": this.context,
|
|
128
|
+
"ldp:contains": ldpContains
|
|
129
|
+
};
|
|
130
|
+
sibStore.setLocalData(data, id);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
change(resource) {
|
|
134
|
+
this.element.dispatchEvent(new CustomEvent('formChange', {
|
|
135
|
+
bubbles: true,
|
|
136
|
+
detail: {
|
|
137
|
+
resource
|
|
138
|
+
}
|
|
139
|
+
}));
|
|
140
|
+
},
|
|
141
|
+
async inputChange() {
|
|
142
|
+
this.change(this.value);
|
|
143
|
+
},
|
|
144
|
+
getSubmitTemplate() {
|
|
145
|
+
return html`
|
|
146
|
+
<div class=${ifDefined(this.classSubmitButton)}>
|
|
147
|
+
${this.submitWidget === 'button' ? html`
|
|
148
|
+
<button type="submit">${this.submitButton || ''}</button>
|
|
149
|
+
` : html`
|
|
150
|
+
<input type="submit" value=${ifDefined(this.submitButton || undefined)}>
|
|
151
|
+
`}
|
|
152
|
+
</div>
|
|
153
|
+
`;
|
|
154
|
+
},
|
|
155
|
+
empty() {},
|
|
156
|
+
async populate() {
|
|
157
|
+
await this.replaceAttributesData();
|
|
158
|
+
if (this.submitButton == null) {
|
|
159
|
+
this.element.addEventListener('input', () => this.inputChange());
|
|
160
|
+
} else {
|
|
161
|
+
this.element.addEventListener('submit', e => {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
this.inputChange();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const fields = await this.getFields();
|
|
167
|
+
const widgetTemplates = await Promise.all(fields.map(field => this.createWidgetTemplate(field)));
|
|
168
|
+
const template = html`
|
|
169
|
+
<form>
|
|
170
|
+
${widgetTemplates}
|
|
171
|
+
${this.submitButton == null ? '' : this.getSubmitTemplate()}
|
|
172
|
+
</form>
|
|
173
|
+
`;
|
|
174
|
+
render(template, this.element);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
Sib.register(SolidFormSearch);
|