@startinblox/core 0.17.21-beta.10 → 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/components/solid-form.js +6 -2
- package/dist/components/solid-form.js.map +1 -1
- package/dist/components/solid-map.js +2 -2
- package/dist/components/solid-map.js.map +1 -1
- 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 +46 -30
- package/dist/libs/store/store.js.map +1 -1
- package/dist/mixins/attributeBinderMixin.js +3 -1
- package/dist/mixins/attributeBinderMixin.js.map +1 -1
- package/dist/mixins/federationMixin.js +3 -1
- package/dist/mixins/federationMixin.js.map +1 -1
- package/dist/mixins/interfaces.js.map +1 -1
- package/dist/mixins/listMixin.js +3 -1
- package/dist/mixins/listMixin.js.map +1 -1
- package/dist/mixins/paginateMixin.js.map +1 -1
- package/dist/mixins/serverPaginationMixin.js +130 -0
- package/dist/mixins/serverPaginationMixin.js.map +1 -0
- package/dist/mixins/storeMixin.js +12 -3
- package/dist/mixins/storeMixin.js.map +1 -1
- package/dist/mixins/widgetMixin.js +6 -2
- package/dist/mixins/widgetMixin.js.map +1 -1
- package/dist/widgets/baseWidget.js +3 -1
- package/dist/widgets/baseWidget.js.map +1 -1
- package/package.json +1 -1
|
@@ -148,6 +148,8 @@ export const SolidForm = {
|
|
|
148
148
|
},
|
|
149
149
|
|
|
150
150
|
get value() {
|
|
151
|
+
var _this$resource$isCont, _this$resource;
|
|
152
|
+
|
|
151
153
|
const values = {};
|
|
152
154
|
this.widgets.forEach(widget => {
|
|
153
155
|
const name = (widget.component || widget).name;
|
|
@@ -161,7 +163,7 @@ export const SolidForm = {
|
|
|
161
163
|
setDeepProperty(values, name.split('.'), value);
|
|
162
164
|
}); // add @id if edition
|
|
163
165
|
|
|
164
|
-
if (this.resource && !this.resource.isContainer()) values['@id'] = this.resourceId;
|
|
166
|
+
if (this.resource && !((_this$resource$isCont = (_this$resource = this.resource).isContainer) !== null && _this$resource$isCont !== void 0 && _this$resource$isCont.call(_this$resource))) values['@id'] = this.resourceId;
|
|
165
167
|
return values;
|
|
166
168
|
},
|
|
167
169
|
|
|
@@ -178,9 +180,11 @@ export const SolidForm = {
|
|
|
178
180
|
},
|
|
179
181
|
|
|
180
182
|
async getFormValue() {
|
|
183
|
+
var _this$resource$isCont2, _this$resource2;
|
|
184
|
+
|
|
181
185
|
let value = this.value;
|
|
182
186
|
|
|
183
|
-
if (this.resource && !this.resource.isContainer()) {
|
|
187
|
+
if (this.resource && !((_this$resource$isCont2 = (_this$resource2 = this.resource).isContainer) !== null && _this$resource$isCont2 !== void 0 && _this$resource$isCont2.call(_this$resource2))) {
|
|
184
188
|
for (let predicate of Object.keys(this.value)) {
|
|
185
189
|
// add @id for nested resources
|
|
186
190
|
const object = await this.resource[predicate];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["solid-form.ts"],"names":["Sib","WidgetMixin","StoreMixin","NextMixin","ValidationMixin","store","setDeepProperty","transformArrayToContainer","html","render","ifDefined","SolidForm","name","use","attributes","defaultWidget","type","String","default","naked","submitButton","undefined","callback","newValue","oldValue","noRender","populate","submitWidget","classSubmitButton","partial","Boolean","autosave","initialState","error","defaultMultipleWidget","defaultSetWidget","value","values","widgets","forEach","widget","component","getValue","JSON","parse","e","split","resource","isContainer","resourceId","isNaked","element","hasAttribute","isSavingAutomatically","isCreationForm","formValue","getFormValue","predicate","Object","keys","object","getWidget","field","isSet","tagName","widgetAttribute","getAttribute","widgetFromTagName","change","dispatchEvent","CustomEvent","bubbles","detail","save","toggleLoaderHidden","hideError","context","saved","put","post","patch","json","then","showError","id","submitForm","reset","goToNext","onInput","onChange","findErrorMessage","errors","errorFullName","errorsArray","member","errorNextName","errorAddName","concat","Array","isArray","errorMessage","errorGlobal","join","push","objectErrors","subErrors","entries","empty","filter","startsWith","errorTemplate","map","parentElement","querySelector","onSubmit","event","preventDefault","performAction","validateModal","onReset","setTimeout","getSubmitTemplate","t","oninput","onchange","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","bind","getModalDialog","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,eAAT,QAAgC,2BAAhC;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,eAAT,EAA0BC,yBAA1B,QAA2D,iBAA3D;AAGA,SAASC,IAAT,EAAeC,MAAf,QAA6B,UAA7B;AACA,SAASC,SAAT,QAA0B,gCAA1B;AAEA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,YADiB;AAEvBC,EAAAA,GAAG,EAAE,CAACZ,WAAD,EAAcC,UAAd,EAA0BC,SAA1B,EAAqCC,eAArC,CAFkB;AAGvBU,EAAAA,UAAU,EAAE;AACVC,IAAAA,aAAa,EAAE;AACbC,MAAAA,IAAI,EAAEC,MADO;AAEbC,MAAAA,OAAO,EAAE;AAFI,KADL;AAKVC,IAAAA,KAAK,EAAE;AACLH,MAAAA,IAAI,EAAEC,MADD;AAELC,MAAAA,OAAO,EAAE;AAFJ,KALG;AASVE,IAAAA,YAAY,EAAE;AACZJ,MAAAA,IAAI,EAAEC,MADM;AAEZC,MAAAA,OAAO,EAAEG,SAFG;AAGZC,MAAAA,QAAQ,EAAE,UAAUC,QAAV,EAA4BC,QAA5B,EAA8C;AACtD,YAAI,KAAKC,QAAL,IAAiB,IAAjB,IAAyBF,QAAQ,KAAKC,QAA1C,EAAoD,KAAKE,QAAL;AACrD;AALW,KATJ;AAgBVC,IAAAA,YAAY,EAAE;AACZX,MAAAA,IAAI,EAAEC,MADM;AAEZC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sB,QAAtB,GAAiCnB,IAAjC,qBACwB,KAAKY,YAAL,IAAqB,KAAKsG,CAAL,CAAO,0BAAP,CAD7C,IAEElH,IAFF,qBAG6B,KAAKY,YAAL,IAAqB,KAAKsG,CAAL,CAAO,0BAAP,CAHlD,CAFN;AASD,GA1NsB;;AA2NvB,QAAMhG,QAAN,GAAgC;AAC9B,SAAKyB,OAAL,CAAawE,OAAb,GAAuB,MAAM,KAAKnC,OAAL,EAA7B,CAD8B,CACe;;;AAC7C,SAAKrC,OAAL,CAAayE,QAAb,GAAwB,MAAM,KAAKnC,QAAL,EAA9B;;AACA,UAAMoC,MAAM,GAAG,MAAM,KAAKC,SAAL,EAArB;AACA,UAAMC,eAAe,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYJ,MAAM,CAACd,GAAP,CAAYjD,KAAD,IAAmB,KAAKoE,oBAAL,CAA0BpE,KAA1B,CAA9B,CAAZ,CAA9B;AACA,UAAMqE,QAAQ,GAAG3H,IAAH,qBAEV,CAAC,KAAK0C,OAAN,GAAgB1C,IAAhB,qBAEY,KAAK0G,QAAL,CAAckB,IAAd,CAAmB,IAAnB,CAFZ,EAGW,KAAKb,OAAL,CAAaa,IAAb,CAAkB,IAAlB,CAHX,EAKIL,eALJ,EAMI,CAAC,KAAK1E,qBAAN,GAA8B,KAAKoE,iBAAL,EAA9B,GAAyD,EAN7D,EAOI,KAAKtE,OAAL,CAAaC,YAAb,CAA0B,OAA1B,IACE5C,IADF,uBACiC,EARrC,IAUEA,IAVF,qBAWEuH,eAXF,CAFU,EAgBV,KAAKM,cAAL,EAhBU,CAAd;AAkBA5H,IAAAA,MAAM,CAAC0H,QAAD,EAAW,KAAKhF,OAAhB,CAAN;AACD;;AAnPsB,CAAlB;AAsPPnD,GAAG,CAACsI,QAAJ,CAAa3H,SAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { ValidationMixin } from '../mixins/validationMixin';\nimport { store } from '../libs/store/store';\nimport { setDeepProperty, transformArrayToContainer } from '../libs/helpers';\nimport type { WidgetInterface } from '../mixins/interfaces';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidForm = {\n name: 'solid-form',\n use: [WidgetMixin, StoreMixin, NextMixin, ValidationMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text'\n },\n naked: {\n type: String,\n default: null\n },\n submitButton: {\n type: String,\n default: undefined,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: null\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n partial: {\n type: Boolean,\n default: null\n },\n autosave: {\n type: Boolean,\n default: null\n },\n },\n initialState: {\n error: ''\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n get value(): object {\n const values = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch (e) {}\n setDeepProperty(values, name.split('.'), value);\n });\n // add @id if edition\n if (this.resource && !this.resource.isContainer()) values['@id'] = this.resourceId;\n return values;\n },\n get isNaked(): boolean {\n return this.element.hasAttribute('naked');\n },\n get isSavingAutomatically(): boolean {\n return this.autosave !== null;\n },\n isCreationForm(formValue: object): boolean {\n return !('@id' in formValue);\n },\n async getFormValue() {\n let value = this.value;\n if (this.resource && !this.resource.isContainer()) {\n for (let predicate of Object.keys(this.value)) { // add @id for nested resources\n const object = await this.resource[predicate];\n if (object && object['@id'] && !value[predicate]['@id']) value[predicate]['@id'] = object['@id'];\n }\n }\n return transformArrayToContainer(value);\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n const widgetAttribute = this.element.getAttribute('widget-' + field);\n\n // Choose widget\n if (!widgetAttribute && this.element.hasAttribute('upload-url-' + field)) {\n tagName = 'solid-form-file'\n } else if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n return this.widgetFromTagName(tagName);\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async save(): Promise<object> {\n this.toggleLoaderHidden(false);\n this.hideError();\n const resource = await this.getFormValue();\n resource['@context'] = this.context;\n let saved;\n try {\n if (this.partial == null) {\n saved = resource['@id'] ?\n await store.put(resource, this.resourceId) :\n await store.post(resource, this.resourceId);\n } else {\n saved = await store.patch(resource, this.resourceId);\n }\n } catch (e) {\n this.toggleLoaderHidden(true);\n if (e) { // if server error\n e.json().then(error => this.showError(error));\n throw e;\n } // else, ldpframework error, we continue\n }\n this.element.dispatchEvent(\n new CustomEvent('save', {\n bubbles: true,\n detail: {\n resource: resource,\n id: saved || null\n },\n }),\n );\n this.toggleLoaderHidden(true);\n return saved;\n },\n async submitForm(): Promise<void> {\n let id: string;\n try {\n id = await this.save() || this.getFormValue()['@id'];\n } catch (e) { return; }\n this.reset();\n this.goToNext({'@id': id})\n },\n async onInput(): Promise<void> {\n const formValue = await this.getFormValue();\n this.change(formValue);\n },\n async onChange(): Promise<void> {\n const formValue = await this.getFormValue();\n if (!this.isCreationForm(formValue) && this.isSavingAutomatically)\n this.submitForm(); // if autosave, submitForm\n },\n findErrorMessage(errors: [string, any][], errorFullName: string = '') {\n let errorsArray: string[] = [];\n errors.forEach((member: [string, any]) => {\n let errorNextName: string = Object.values(member)[0];\n let errorAddName = (errorFullName === \"\" ? errorNextName : errorFullName.concat(' - ', errorNextName));\n if (Array.isArray(Object.values(member)[1]) === true) {\n let errorMessage: string[] = Object.values(member)[1];\n let errorGlobal = errorAddName.concat(': ', errorMessage.join(', '));\n errorsArray.push(errorGlobal);\n } else {\n let objectErrors = Object.values(member)[1];\n let subErrors = Object.entries(objectErrors);\n errorsArray = [...errorsArray, ...this.findErrorMessage(subErrors, errorAddName)];\n }\n });\n return errorsArray;\n },\n empty(): void {},\n showError(e: object) {\n let errors = Object.entries(e).filter(field => !field[0].startsWith('@context'));\n\n const errorTemplate = html`\n <p>A validation error occurred.</p>\n <ul>\n ${this.findErrorMessage(errors).map(field => html`\n <li>${field}</li>\n `)}\n </ul>\n `;\n // If field exists pick its label (unsure if that's easily possible)\n // In this.getFields() map with each field and get label\n // If it does not just add a notice as we do that it's missing that field\n\n // Validation message in english ?\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render(errorTemplate, parentElement);\n },\n hideError() {\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render('', parentElement);\n },\n reset() {\n if (!this.isNaked) this.element.querySelector('form').reset();\n },\n onSubmit(event: Event) {\n if (!this.isNaked) {\n event.preventDefault();\n this.performAction(); // In validationMixin, method defining what to do according to the present attributes\n }\n },\n validateModal() { //send method to validationMixin, used by the dialog modal and performAction method\n return this.submitForm();\n },\n onReset() {\n if (!this.isNaked) setTimeout(() => this.onInput())\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || this.t(\"solid-form.submit-button\")}</button>\n ` : html`\n <input type=\"submit\" value=${this.submitButton || this.t(\"solid-form.submit-button\")}>\n `}\n </div>\n `\n },\n async populate(): Promise<void> {\n this.element.oninput = () => this.onInput(); // prevent from firing change multiple times\n this.element.onchange = () => this.onChange();\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <div data-id=\"error\"></div>\n ${!this.isNaked ? html`\n <form\n @submit=${this.onSubmit.bind(this)}\n @reset=${this.onReset.bind(this)}\n >\n ${widgetTemplates}\n ${!this.isSavingAutomatically ? this.getSubmitTemplate() : ''}\n ${this.element.hasAttribute('reset')\n ? html`<input type=\"reset\" />` : ''}\n </form>\n ` : html`\n ${widgetTemplates}\n `\n }\n ${this.getModalDialog()}\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidForm);"]}
|
|
1
|
+
{"version":3,"sources":["solid-form.ts"],"names":["Sib","WidgetMixin","StoreMixin","NextMixin","ValidationMixin","store","setDeepProperty","transformArrayToContainer","html","render","ifDefined","SolidForm","name","use","attributes","defaultWidget","type","String","default","naked","submitButton","undefined","callback","newValue","oldValue","noRender","populate","submitWidget","classSubmitButton","partial","Boolean","autosave","initialState","error","defaultMultipleWidget","defaultSetWidget","value","values","widgets","forEach","widget","component","getValue","JSON","parse","e","split","resource","isContainer","resourceId","isNaked","element","hasAttribute","isSavingAutomatically","isCreationForm","formValue","getFormValue","predicate","Object","keys","object","getWidget","field","isSet","tagName","widgetAttribute","getAttribute","widgetFromTagName","change","dispatchEvent","CustomEvent","bubbles","detail","save","toggleLoaderHidden","hideError","context","saved","put","post","patch","json","then","showError","id","submitForm","reset","goToNext","onInput","onChange","findErrorMessage","errors","errorFullName","errorsArray","member","errorNextName","errorAddName","concat","Array","isArray","errorMessage","errorGlobal","join","push","objectErrors","subErrors","entries","empty","filter","startsWith","errorTemplate","map","parentElement","querySelector","onSubmit","event","preventDefault","performAction","validateModal","onReset","setTimeout","getSubmitTemplate","t","oninput","onchange","fields","getFields","widgetTemplates","Promise","all","createWidgetTemplate","template","bind","getModalDialog","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC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C7C,SAAKrC,OAAL,CAAayE,QAAb,GAAwB,MAAM,KAAKnC,QAAL,EAA9B;;AACA,UAAMoC,MAAM,GAAG,MAAM,KAAKC,SAAL,EAArB;AACA,UAAMC,eAAe,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYJ,MAAM,CAACd,GAAP,CAAYjD,KAAD,IAAmB,KAAKoE,oBAAL,CAA0BpE,KAA1B,CAA9B,CAAZ,CAA9B;AACA,UAAMqE,QAAQ,GAAG3H,IAAH,qBAEV,CAAC,KAAK0C,OAAN,GAAgB1C,IAAhB,qBAEY,KAAK0G,QAAL,CAAckB,IAAd,CAAmB,IAAnB,CAFZ,EAGW,KAAKb,OAAL,CAAaa,IAAb,CAAkB,IAAlB,CAHX,EAKIL,eALJ,EAMI,CAAC,KAAK1E,qBAAN,GAA8B,KAAKoE,iBAAL,EAA9B,GAAyD,EAN7D,EAOI,KAAKtE,OAAL,CAAaC,YAAb,CAA0B,OAA1B,IACE5C,IADF,uBACiC,EARrC,IAUEA,IAVF,qBAWEuH,eAXF,CAFU,EAgBV,KAAKM,cAAL,EAhBU,CAAd;AAkBA5H,IAAAA,MAAM,CAAC0H,QAAD,EAAW,KAAKhF,OAAhB,CAAN;AACD;;AAnPsB,CAAlB;AAsPPnD,GAAG,CAACsI,QAAJ,CAAa3H,SAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { ValidationMixin } from '../mixins/validationMixin';\nimport { store } from '../libs/store/store';\nimport { setDeepProperty, transformArrayToContainer } from '../libs/helpers';\nimport type { WidgetInterface } from '../mixins/interfaces';\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidForm = {\n name: 'solid-form',\n use: [WidgetMixin, StoreMixin, NextMixin, ValidationMixin],\n attributes: {\n defaultWidget: {\n type: String,\n default: 'solid-form-label-text'\n },\n naked: {\n type: String,\n default: null\n },\n submitButton: {\n type: String,\n default: undefined,\n callback: function (newValue: string, oldValue: string) {\n if (this.noRender == null && newValue !== oldValue) this.populate();\n },\n },\n submitWidget: {\n type: String,\n default: null\n },\n classSubmitButton: {\n type: String,\n default: undefined,\n },\n partial: {\n type: Boolean,\n default: null\n },\n autosave: {\n type: Boolean,\n default: null\n },\n },\n initialState: {\n error: ''\n },\n get defaultMultipleWidget(): string {\n return 'solid-multiple-form';\n },\n get defaultSetWidget(): string {\n return 'solid-set-default';\n },\n get value(): object {\n const values = {};\n this.widgets.forEach((widget) => {\n const name = (widget.component || widget).name;\n if (name == null) return;\n let value = widget.component ? widget.component.getValue() : widget.value;\n try {\n value = JSON.parse(value);\n } catch (e) {}\n setDeepProperty(values, name.split('.'), value);\n });\n // add @id if edition\n if (this.resource && !this.resource.isContainer?.()) values['@id'] = this.resourceId;\n return values;\n },\n get isNaked(): boolean {\n return this.element.hasAttribute('naked');\n },\n get isSavingAutomatically(): boolean {\n return this.autosave !== null;\n },\n isCreationForm(formValue: object): boolean {\n return !('@id' in formValue);\n },\n async getFormValue() {\n let value = this.value;\n if (this.resource && !this.resource.isContainer?.()) {\n for (let predicate of Object.keys(this.value)) { // add @id for nested resources\n const object = await this.resource[predicate];\n if (object && object['@id'] && !value[predicate]['@id']) value[predicate]['@id'] = object['@id'];\n }\n }\n return transformArrayToContainer(value);\n },\n getWidget(field: string, isSet: boolean = false): WidgetInterface {\n let tagName = '';\n const widgetAttribute = this.element.getAttribute('widget-' + field);\n\n // Choose widget\n if (!widgetAttribute && this.element.hasAttribute('upload-url-' + field)) {\n tagName = 'solid-form-file'\n } else if (!widgetAttribute && (this.element.hasAttribute('range-' + field) || this.element.hasAttribute('enum-' + field))) {\n tagName = 'solid-form-dropdown'\n } else {\n tagName = widgetAttribute || (!isSet ? this.defaultWidget : this.defaultSetWidget);\n }\n // Create widget\n return this.widgetFromTagName(tagName);\n },\n change(resource: object): void {\n this.element.dispatchEvent(\n new CustomEvent('formChange', {\n bubbles: true,\n detail: { resource },\n }),\n );\n },\n async save(): Promise<object> {\n this.toggleLoaderHidden(false);\n this.hideError();\n const resource = await this.getFormValue();\n resource['@context'] = this.context;\n let saved;\n try {\n if (this.partial == null) {\n saved = resource['@id'] ?\n await store.put(resource, this.resourceId) :\n await store.post(resource, this.resourceId);\n } else {\n saved = await store.patch(resource, this.resourceId);\n }\n } catch (e) {\n this.toggleLoaderHidden(true);\n if (e) { // if server error\n e.json().then(error => this.showError(error));\n throw e;\n } // else, ldpframework error, we continue\n }\n this.element.dispatchEvent(\n new CustomEvent('save', {\n bubbles: true,\n detail: {\n resource: resource,\n id: saved || null\n },\n }),\n );\n this.toggleLoaderHidden(true);\n return saved;\n },\n async submitForm(): Promise<void> {\n let id: string;\n try {\n id = await this.save() || this.getFormValue()['@id'];\n } catch (e) { return; }\n this.reset();\n this.goToNext({'@id': id})\n },\n async onInput(): Promise<void> {\n const formValue = await this.getFormValue();\n this.change(formValue);\n },\n async onChange(): Promise<void> {\n const formValue = await this.getFormValue();\n if (!this.isCreationForm(formValue) && this.isSavingAutomatically)\n this.submitForm(); // if autosave, submitForm\n },\n findErrorMessage(errors: [string, any][], errorFullName: string = '') {\n let errorsArray: string[] = [];\n errors.forEach((member: [string, any]) => {\n let errorNextName: string = Object.values(member)[0];\n let errorAddName = (errorFullName === \"\" ? errorNextName : errorFullName.concat(' - ', errorNextName));\n if (Array.isArray(Object.values(member)[1]) === true) {\n let errorMessage: string[] = Object.values(member)[1];\n let errorGlobal = errorAddName.concat(': ', errorMessage.join(', '));\n errorsArray.push(errorGlobal);\n } else {\n let objectErrors = Object.values(member)[1];\n let subErrors = Object.entries(objectErrors);\n errorsArray = [...errorsArray, ...this.findErrorMessage(subErrors, errorAddName)];\n }\n });\n return errorsArray;\n },\n empty(): void {},\n showError(e: object) {\n let errors = Object.entries(e).filter(field => !field[0].startsWith('@context'));\n\n const errorTemplate = html`\n <p>A validation error occurred.</p>\n <ul>\n ${this.findErrorMessage(errors).map(field => html`\n <li>${field}</li>\n `)}\n </ul>\n `;\n // If field exists pick its label (unsure if that's easily possible)\n // In this.getFields() map with each field and get label\n // If it does not just add a notice as we do that it's missing that field\n\n // Validation message in english ?\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render(errorTemplate, parentElement);\n },\n hideError() {\n const parentElement = this.element.querySelector('[data-id=error]');\n if (parentElement) render('', parentElement);\n },\n reset() {\n if (!this.isNaked) this.element.querySelector('form').reset();\n },\n onSubmit(event: Event) {\n if (!this.isNaked) {\n event.preventDefault();\n this.performAction(); // In validationMixin, method defining what to do according to the present attributes\n }\n },\n validateModal() { //send method to validationMixin, used by the dialog modal and performAction method\n return this.submitForm();\n },\n onReset() {\n if (!this.isNaked) setTimeout(() => this.onInput())\n },\n getSubmitTemplate() {\n return html`\n <div class=${ifDefined(this.classSubmitButton)}>\n ${this.submitWidget === 'button' ? html`\n <button type=\"submit\">${this.submitButton || this.t(\"solid-form.submit-button\")}</button>\n ` : html`\n <input type=\"submit\" value=${this.submitButton || this.t(\"solid-form.submit-button\")}>\n `}\n </div>\n `\n },\n async populate(): Promise<void> {\n this.element.oninput = () => this.onInput(); // prevent from firing change multiple times\n this.element.onchange = () => this.onChange();\n const fields = await this.getFields();\n const widgetTemplates = await Promise.all(fields.map((field: string) => this.createWidgetTemplate(field)));\n const template = html`\n <div data-id=\"error\"></div>\n ${!this.isNaked ? html`\n <form\n @submit=${this.onSubmit.bind(this)}\n @reset=${this.onReset.bind(this)}\n >\n ${widgetTemplates}\n ${!this.isSavingAutomatically ? this.getSubmitTemplate() : ''}\n ${this.element.hasAttribute('reset')\n ? html`<input type=\"reset\" />` : ''}\n </form>\n ` : html`\n ${widgetTemplates}\n `\n }\n ${this.getModalDialog()}\n `;\n render(template, this.element);\n }\n};\n\nSib.register(SolidForm);"]}
|
|
@@ -33,9 +33,9 @@ import { store } from '../libs/store/store.js';
|
|
|
33
33
|
import { uniqID } from '../libs/helpers.js';
|
|
34
34
|
import { spread } from '../libs/lit-helpers.js'; //@ts-ignore
|
|
35
35
|
|
|
36
|
-
import L from 'https://cdn.skypack.dev/leaflet'; // TODO : revert to "leaflet" when apps up to date
|
|
36
|
+
import L from 'https://cdn.skypack.dev/leaflet@1.7.1'; // TODO : revert to "leaflet" when apps up to date
|
|
37
37
|
|
|
38
|
-
import 'https://cdn.skypack.dev/leaflet.markercluster'; // TODO : revert to "leaflet.markercluster" when apps up to date
|
|
38
|
+
import 'https://cdn.skypack.dev/leaflet.markercluster@1.4.1'; // TODO : revert to "leaflet.markercluster" when apps up to date
|
|
39
39
|
|
|
40
40
|
import { html, render } from '../_snowpack/pkg/lit-html.js';
|
|
41
41
|
import { ifDefined } from '../_snowpack/pkg/lit-html/directives/if-defined.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["solid-map.ts"],"names":["Sib","ListMixin","StoreMixin","WidgetMixin","CounterMixin","FilterMixin","FederationMixin","GrouperMixin","NextMixin","store","uniqID","spread","L","html","render","ifDefined","SolidMap","name","use","attributes","clustering","type","Boolean","default","initialState","markers","subscriptions","resetPlanned","hasBeenResetOnce","created","document","body","addEventListener","setTimeout","isVisible","reset","Map","element","offsetParent","attached","id","template","div","querySelector","map","tileLayer","addTo","markersCluster","markerClusterGroup","addLayer","invalidateSize","length","fitBounds","featureGroup","getBounds","fitWorld","planReset","dispatchSelect","event","target","resource","dispatchEvent","CustomEvent","detail","goToNext","appendChildElt","resourceId","groupClass","getData","context","get","set","PubSub","subscribe","updateDOM","lat","lng","icon","divIcon","className","iconSize","iconAnchor","popupAnchor","marker","toString","on","bind","fields","bindPopup","getPopupContent","minWidth","push","attr","startsWith","value","replace","createElement","empty","removeLayer","renderGroup","groupName","sanitizedGroupName","encodeURIComponent","toLowerCase","dataset","renderDOM","resources","listPostProcessors","Promise","all","nextProcessor","shift","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,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kBAAZ,EAAgCjE,GAAhC,EAAqC2B,OAArC,CAAnB;AACnB;;AAjNqB,CAAjB;AAoNPrE,GAAG,CAACgH,QAAJ,CAAahG,QAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { ListMixin } from '../mixins/listMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { CounterMixin } from '../mixins/counterMixin';\nimport { FilterMixin } from '../mixins/filterMixin';\nimport { FederationMixin } from '../mixins/federationMixin';\nimport { GrouperMixin } from '../mixins/grouperMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { store } from '../libs/store/store';\nimport { uniqID } from '../libs/helpers';\nimport { spread } from '../libs/lit-helpers';\n\n//@ts-ignore\nimport L, { MarkerOptions } from 'https://cdn.skypack.dev/leaflet'; // TODO : revert to \"leaflet\" when apps up to date\nimport 'https://cdn.skypack.dev/leaflet.markercluster'; // TODO : revert to \"leaflet.markercluster\" when apps up to date\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidMap = {\n name: 'solid-map',\n use: [\n WidgetMixin,\n ListMixin,\n StoreMixin,\n GrouperMixin,\n CounterMixin,\n FilterMixin,\n FederationMixin,\n NextMixin,\n ],\n attributes: {\n clustering: {\n type: Boolean,\n default: null\n }\n },\n initialState: {\n markers: {\n default: null\n },\n subscriptions: null,\n resetPlanned: false,\n hasBeenResetOnce: false\n },\n created(): void {\n //@ts-ignore\n import('leaflet/dist/leaflet.css');\n //@ts-ignore\n import('../style/default-theme.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.Default.css');\n\n // reset when it becomes visible to prevent bug https://git.startinblox.com/framework/sib-core/issues/661\n document.body.addEventListener('navigate', () =>\n setTimeout(() => this.isVisible && !this.hasBeenResetOnce && this.reset())\n );\n this.markers = [];\n this.subscriptions = new Map();\n },\n get isVisible() {\n return this.element.offsetParent !== null\n },\n attached(): void {\n const id = uniqID();\n const template = html`\n <div id=${id} style=\"width:100%;height:100%;\"></div>\n `;\n render(template, this.element);\n\n const div = this.element.querySelector(`#${id}`);\n this.map = L.map(div);\n\n L.tileLayer(\n 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png'\n ).addTo(this.map);\n\n if (this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n },\n reset() {\n if (this.isVisible) { // reset only if visible\n this.map.invalidateSize();\n\n if (this.markers.length) {\n this.map.fitBounds(L.featureGroup(this.markers).getBounds()); // Center map on markers if some available\n } else {\n this.map.fitWorld(); // ... or on the world if not\n }\n this.hasBeenResetOnce = true;\n }\n },\n /**\n * Execute a reset only if none is planned already\n */\n planReset() {\n if (!this.resetPlanned) {\n this.resetPlanned = true;\n setTimeout(() => {\n this.reset();\n this.resetPlanned = false;\n })\n }\n },\n dispatchSelect(event: CustomEvent): void {\n const target = event.target as Element;\n const resource = target['options'].resource;\n this.element.dispatchEvent(\n new CustomEvent('resourceSelect', { detail: { resource: resource } })\n );\n this.goToNext(resource);\n },\n\n /**\n * Override listMixin method: initialize a marker on the map\n * @param resourceId: id of the resource to display\n * @param groupClass: class of the group of markers\n */\n async appendChildElt(resourceId: string, groupClass: string) {\n const resource = await store.getData(resourceId, this.context);\n if (!this.subscriptions.get(resourceId)) {\n this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()))\n }\n if (!resource) return;\n const lat = await resource['lat'];\n const lng = await resource['lng'];\n\n if (lat && lng) {\n const icon = L.divIcon({ // create the icon, doc here: https://leafletjs.com/reference-1.6.0.html#icon\n className: 'sib-custom-marker ' + groupClass, // default class used for styling\n iconSize: [8, 8],\n iconAnchor: [12, 34],\n popupAnchor: [0,-34]\n });\n\n // create a marker, doc here: https://leafletjs.com/reference-1.6.0.html#marker\n const marker = L.marker(\n [lat.toString(), lng.toString()], \n {resource, icon} as MarkerOptions\n );\n if(this.clustering === null) marker.addTo(this.map);\n else this.markersCluster.addLayer(marker);\n marker.on('click', this.dispatchSelect.bind(this));\n\n if (this.fields !== null) { // show popups only if fields attribute\n marker.bindPopup(() => this.getPopupContent(resourceId), { minWidth: 150 }) // re-generate popup solid-display\n }\n\n this.markers.push(marker);\n }\n },\n /**\n * Generate the solid-display of the popup\n * @param resourceId: id of the popup clicked\n */\n getPopupContent(resourceId: string) {\n const attributes:{[key:string]: string} = {};\n\n for (let attr of this.element.attributes) {\n //copy widget and value attributes\n if (\n attr.name.startsWith('value-') ||\n attr.name.startsWith('label-') ||\n attr.name.startsWith('widget-') ||\n attr.name.startsWith('class-') ||\n attr.name.startsWith('multiple-') ||\n attr.name.startsWith('editable-') ||\n attr.name.startsWith('action-') ||\n attr.name.startsWith('default-') ||\n attr.name == 'extra-context'\n )\n attributes[attr.name] = attr.value;\n if (attr.name.startsWith('child-'))\n attributes[attr.name.replace(/^child-/, '')] = attr.value;\n }\n\n const div = document.createElement('div');\n const template = html`\n <solid-display\n fields=\"${ifDefined(this.fields)}\"\n data-src=\"${resourceId}\"\n ...=${spread(attributes)}\n ></solid-display>\n `;\n render(template, div);\n return div.querySelector('solid-display');\n },\n /**\n * Override widgetMixin method: empty the map\n */\n empty(): void {\n if (!this.map) return;\n if (this.markersCluster) this.map.removeLayer(this.markersCluster);\n for (let marker of this.markers) this.map.removeLayer(marker);\n if(this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n this.markers = [];\n },\n /**\n * Override groupMixin method\n * @param groupName: value of the group\n */\n renderGroup(groupName: string) {\n const sanitizedGroupName = encodeURIComponent(groupName.toLowerCase()).replace(/%[0-9A-F]{2}/gi, '');\n const div = document.createElement('div'); // used to pass group info to renderDOM\n div.dataset.groupClass = 'group-' + sanitizedGroupName;\n return div;\n },\n /**\n * Override listMixin method: display all the resources\n * @param resources\n * @param listPostProcessors\n * @param div\n * @param context\n */\n async renderDOM(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string) {\n const groupClass = div.dataset.groupClass || ''; // get the group class from the useless div element\n await Promise.all(resources.map(resource => this.appendChildElt(resource['@id'], groupClass)))\n this.planReset();\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);\n }\n};\n\nSib.register(SolidMap);"]}
|
|
1
|
+
{"version":3,"sources":["solid-map.ts"],"names":["Sib","ListMixin","StoreMixin","WidgetMixin","CounterMixin","FilterMixin","FederationMixin","GrouperMixin","NextMixin","store","uniqID","spread","L","html","render","ifDefined","SolidMap","name","use","attributes","clustering","type","Boolean","default","initialState","markers","subscriptions","resetPlanned","hasBeenResetOnce","created","document","body","addEventListener","setTimeout","isVisible","reset","Map","element","offsetParent","attached","id","template","div","querySelector","map","tileLayer","addTo","markersCluster","markerClusterGroup","addLayer","invalidateSize","length","fitBounds","featureGroup","getBounds","fitWorld","planReset","dispatchSelect","event","target","resource","dispatchEvent","CustomEvent","detail","goToNext","appendChildElt","resourceId","groupClass","getData","context","get","set","PubSub","subscribe","updateDOM","lat","lng","icon","divIcon","className","iconSize","iconAnchor","popupAnchor","marker","toString","on","bind","fields","bindPopup","getPopupContent","minWidth","push","attr","startsWith","value","replace","createElement","empty","removeLayer","renderGroup","groupName","sanitizedGroupName","encodeURIComponent","toLowerCase","dataset","renderDOM","resources","listPostProcessors","Promise","all","nextProcessor","shift","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,GAAT,QAAoB,aAApB;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,YAAT,QAA6B,wBAA7B;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,eAAT,QAAgC,2BAAhC;AACA,SAASC,YAAT,QAA6B,wBAA7B;AACA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SA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,CAAkB,KAAKF,cAAvB;AACD;;AACD,SAAKtB,OAAL,GAAe,EAAf;AACD,GAxLqB;;AAyLtB;AACF;AACA;AACA;AACE0E,EAAAA,WAAW,CAACC,SAAD,EAAoB;AAC7B,UAAMC,kBAAkB,GAAGC,kBAAkB,CAACF,SAAS,CAACG,WAAV,EAAD,CAAlB,CAA4CR,OAA5C,CAAoD,gBAApD,EAAsE,EAAtE,CAA3B;AACA,UAAMrD,GAAG,GAAGZ,QAAQ,CAACkE,aAAT,CAAuB,KAAvB,CAAZ,CAF6B,CAEc;;AAC3CtD,IAAAA,GAAG,CAAC8D,OAAJ,CAAYrC,UAAZ,GAAyB,WAAWkC,kBAApC;AACA,WAAO3D,GAAP;AACD,GAlMqB;;AAmMtB;AACF;AACA;AACA;AACA;AACA;AACA;AACE,QAAM+D,SAAN,CAAgBC,SAAhB,EAAqCC,kBAArC,EAAqEjE,GAArE,EAAuF2B,OAAvF,EAAwG;AACtG,UAAMF,UAAU,GAAGzB,GAAG,CAAC8D,OAAJ,CAAYrC,UAAZ,IAA0B,EAA7C,CADsG,CACrD;;AACjD,UAAMyC,OAAO,CAACC,GAAR,CAAYH,SAAS,CAAC9D,GAAV,CAAcgB,QAAQ,IAAI,KAAKK,cAAL,CAAoBL,QAAQ,CAAC,KAAD,CAA5B,EAAqCO,UAArC,CAA1B,CAAZ,CAAN;AACA,SAAKX,SAAL;AAEA,UAAMsD,aAAa,GAAGH,kBAAkB,CAACI,KAAnB,EAAtB;AACA,QAAGD,aAAH,EAAkB,MAAMA,aAAa,CAACJ,SAAD,EAAYC,kBAAZ,EAAgCjE,GAAhC,EAAqC2B,OAArC,CAAnB;AACnB;;AAjNqB,CAAjB;AAoNPrE,GAAG,CAACgH,QAAJ,CAAahG,QAAb","sourcesContent":["import { Sib } from '../libs/Sib';\nimport { ListMixin } from '../mixins/listMixin';\nimport { StoreMixin } from '../mixins/storeMixin';\nimport { WidgetMixin } from '../mixins/widgetMixin';\nimport { CounterMixin } from '../mixins/counterMixin';\nimport { FilterMixin } from '../mixins/filterMixin';\nimport { FederationMixin } from '../mixins/federationMixin';\nimport { GrouperMixin } from '../mixins/grouperMixin';\nimport { NextMixin } from '../mixins/nextMixin';\nimport { store } from '../libs/store/store';\nimport { uniqID } from '../libs/helpers';\nimport { spread } from '../libs/lit-helpers';\n\n//@ts-ignore\nimport L, { MarkerOptions } from 'https://cdn.skypack.dev/leaflet@1.7.1'; // TODO : revert to \"leaflet\" when apps up to date\nimport 'https://cdn.skypack.dev/leaflet.markercluster@1.4.1'; // TODO : revert to \"leaflet.markercluster\" when apps up to date\n\nimport { html, render } from 'lit-html';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nexport const SolidMap = {\n name: 'solid-map',\n use: [\n WidgetMixin,\n ListMixin,\n StoreMixin,\n GrouperMixin,\n CounterMixin,\n FilterMixin,\n FederationMixin,\n NextMixin,\n ],\n attributes: {\n clustering: {\n type: Boolean,\n default: null\n }\n },\n initialState: {\n markers: {\n default: null\n },\n subscriptions: null,\n resetPlanned: false,\n hasBeenResetOnce: false\n },\n created(): void {\n //@ts-ignore\n import('leaflet/dist/leaflet.css');\n //@ts-ignore\n import('../style/default-theme.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.css');\n //@ts-ignore\n import('leaflet.markercluster/dist/MarkerCluster.Default.css');\n\n // reset when it becomes visible to prevent bug https://git.startinblox.com/framework/sib-core/issues/661\n document.body.addEventListener('navigate', () =>\n setTimeout(() => this.isVisible && !this.hasBeenResetOnce && this.reset())\n );\n this.markers = [];\n this.subscriptions = new Map();\n },\n get isVisible() {\n return this.element.offsetParent !== null\n },\n attached(): void {\n const id = uniqID();\n const template = html`\n <div id=${id} style=\"width:100%;height:100%;\"></div>\n `;\n render(template, this.element);\n\n const div = this.element.querySelector(`#${id}`);\n this.map = L.map(div);\n\n L.tileLayer(\n 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png'\n ).addTo(this.map);\n\n if (this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n },\n reset() {\n if (this.isVisible) { // reset only if visible\n this.map.invalidateSize();\n\n if (this.markers.length) {\n this.map.fitBounds(L.featureGroup(this.markers).getBounds()); // Center map on markers if some available\n } else {\n this.map.fitWorld(); // ... or on the world if not\n }\n this.hasBeenResetOnce = true;\n }\n },\n /**\n * Execute a reset only if none is planned already\n */\n planReset() {\n if (!this.resetPlanned) {\n this.resetPlanned = true;\n setTimeout(() => {\n this.reset();\n this.resetPlanned = false;\n })\n }\n },\n dispatchSelect(event: CustomEvent): void {\n const target = event.target as Element;\n const resource = target['options'].resource;\n this.element.dispatchEvent(\n new CustomEvent('resourceSelect', { detail: { resource: resource } })\n );\n this.goToNext(resource);\n },\n\n /**\n * Override listMixin method: initialize a marker on the map\n * @param resourceId: id of the resource to display\n * @param groupClass: class of the group of markers\n */\n async appendChildElt(resourceId: string, groupClass: string) {\n const resource = await store.getData(resourceId, this.context);\n if (!this.subscriptions.get(resourceId)) {\n this.subscriptions.set(resourceId, PubSub.subscribe(resourceId, () => this.updateDOM()))\n }\n if (!resource) return;\n const lat = await resource['lat'];\n const lng = await resource['lng'];\n\n if (lat && lng) {\n const icon = L.divIcon({ // create the icon, doc here: https://leafletjs.com/reference-1.6.0.html#icon\n className: 'sib-custom-marker ' + groupClass, // default class used for styling\n iconSize: [8, 8],\n iconAnchor: [12, 34],\n popupAnchor: [0,-34]\n });\n\n // create a marker, doc here: https://leafletjs.com/reference-1.6.0.html#marker\n const marker = L.marker(\n [lat.toString(), lng.toString()], \n {resource, icon} as MarkerOptions\n );\n if(this.clustering === null) marker.addTo(this.map);\n else this.markersCluster.addLayer(marker);\n marker.on('click', this.dispatchSelect.bind(this));\n\n if (this.fields !== null) { // show popups only if fields attribute\n marker.bindPopup(() => this.getPopupContent(resourceId), { minWidth: 150 }) // re-generate popup solid-display\n }\n\n this.markers.push(marker);\n }\n },\n /**\n * Generate the solid-display of the popup\n * @param resourceId: id of the popup clicked\n */\n getPopupContent(resourceId: string) {\n const attributes:{[key:string]: string} = {};\n\n for (let attr of this.element.attributes) {\n //copy widget and value attributes\n if (\n attr.name.startsWith('value-') ||\n attr.name.startsWith('label-') ||\n attr.name.startsWith('widget-') ||\n attr.name.startsWith('class-') ||\n attr.name.startsWith('multiple-') ||\n attr.name.startsWith('editable-') ||\n attr.name.startsWith('action-') ||\n attr.name.startsWith('default-') ||\n attr.name == 'extra-context'\n )\n attributes[attr.name] = attr.value;\n if (attr.name.startsWith('child-'))\n attributes[attr.name.replace(/^child-/, '')] = attr.value;\n }\n\n const div = document.createElement('div');\n const template = html`\n <solid-display\n fields=\"${ifDefined(this.fields)}\"\n data-src=\"${resourceId}\"\n ...=${spread(attributes)}\n ></solid-display>\n `;\n render(template, div);\n return div.querySelector('solid-display');\n },\n /**\n * Override widgetMixin method: empty the map\n */\n empty(): void {\n if (!this.map) return;\n if (this.markersCluster) this.map.removeLayer(this.markersCluster);\n for (let marker of this.markers) this.map.removeLayer(marker);\n if(this.clustering !== null) {\n this.markersCluster = L.markerClusterGroup();\n this.map.addLayer(this.markersCluster);\n }\n this.markers = [];\n },\n /**\n * Override groupMixin method\n * @param groupName: value of the group\n */\n renderGroup(groupName: string) {\n const sanitizedGroupName = encodeURIComponent(groupName.toLowerCase()).replace(/%[0-9A-F]{2}/gi, '');\n const div = document.createElement('div'); // used to pass group info to renderDOM\n div.dataset.groupClass = 'group-' + sanitizedGroupName;\n return div;\n },\n /**\n * Override listMixin method: display all the resources\n * @param resources\n * @param listPostProcessors\n * @param div\n * @param context\n */\n async renderDOM(resources: object[], listPostProcessors: Function[], div: HTMLElement, context: string) {\n const groupClass = div.dataset.groupClass || ''; // get the group class from the useless div element\n await Promise.all(resources.map(resource => this.appendChildElt(resource['@id'], groupClass)))\n this.planReset();\n\n const nextProcessor = listPostProcessors.shift();\n if(nextProcessor) await nextProcessor(resources, listPostProcessors, div, context);\n }\n};\n\nSib.register(SolidMap);"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function formatAttributesToServerPaginationOptions(elementAttributes) {
|
|
2
|
+
const attributes = new Map(Array.from(elementAttributes).map(({
|
|
3
|
+
name,
|
|
4
|
+
value
|
|
5
|
+
}) => [name, value]));
|
|
6
|
+
const limit = attributes.get('limit');
|
|
7
|
+
const offset = attributes.get('offset');
|
|
8
|
+
if (!offset || !limit) return;
|
|
9
|
+
return {
|
|
10
|
+
limit: limit,
|
|
11
|
+
offset: offset
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function appendServerPaginationToIri(iri, options) {
|
|
15
|
+
const first = iri.includes('?') ? '&' : '?';
|
|
16
|
+
const limit = options.limit;
|
|
17
|
+
const offset = options.offset;
|
|
18
|
+
return "".concat(iri).concat(first, "limit=").concat(limit, "&offset=").concat(offset);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=server-pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["server-pagination.ts"],"names":["formatAttributesToServerPaginationOptions","elementAttributes","attributes","Map","Array","from","map","name","value","limit","get","offset","appendServerPaginationToIri","iri","options","first","includes"],"mappings":"AAKA,OAAO,SAASA,yCAAT,CACHC,iBADG,EAEgC;AACnC,QAAMC,UAAU,GAAG,IAAIC,GAAJ,CAAQC,KAAK,CAACC,IAAN,CAAWJ,iBAAX,EAA8BK,GAA9B,CAAkC,CAAC;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAAD,KAAqB,CAACD,IAAD,EAAOC,KAAP,CAAvD,CAAR,CAAnB;AACA,QAAMC,KAAK,GAAGP,UAAU,CAACQ,GAAX,CAAe,OAAf,CAAd;AACA,QAAMC,MAAM,GAAGT,UAAU,CAACQ,GAAX,CAAe,QAAf,CAAf;AACA,MAAI,CAACC,MAAD,IAAW,CAACF,KAAhB,EAAuB;AACvB,SAAO;AACHA,IAAAA,KAAK,EAAEA,KADJ;AAEHE,IAAAA,MAAM,EAAEA;AAFL,GAAP;AAIH;AAED,OAAO,SAASC,2BAAT,CAAqCC,GAArC,EAAkDC,OAAlD,EAA4F;AAC/F,QAAMC,KAAK,GAAGF,GAAG,CAACG,QAAJ,CAAa,GAAb,IAAoB,GAApB,GAA0B,GAAxC;AACA,QAAMP,KAAK,GAAGK,OAAO,CAACL,KAAtB;AACA,QAAME,MAAM,GAAGG,OAAO,CAACH,MAAvB;AACA,mBAAUE,GAAV,SAAgBE,KAAhB,mBAA8BN,KAA9B,qBAA8CE,MAA9C;AACH","sourcesContent":["export interface ServerPaginationOptions {\n offset: number;\n limit: number;\n}\n\nexport function formatAttributesToServerPaginationOptions(\n elementAttributes: { name: string, value: number }[]\n): ServerPaginationOptions | undefined {\n const attributes = new Map(Array.from(elementAttributes).map(({ name, value }) => [name, value]))\n const limit = attributes.get('limit');\n const offset = attributes.get('offset');\n if (!offset || !limit) return;\n return {\n limit: limit,\n offset: offset,\n }\n}\n\nexport function appendServerPaginationToIri(iri: string, options: ServerPaginationOptions): string {\n const first = iri.includes('?') ? '&' : '?';\n const limit = options.limit;\n const offset = options.offset;\n return `${iri}${first}limit=${limit}&offset=${offset}`;\n}"]}
|
package/dist/libs/store/store.js
CHANGED
|
@@ -5,6 +5,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
5
5
|
import JSONLDContextParser from '../../_snowpack/pkg/jsonld-context-parser.js'; //@ts-ignore
|
|
6
6
|
|
|
7
7
|
import PubSub from 'https://cdn.skypack.dev/pubsub-js';
|
|
8
|
+
import { appendServerPaginationToIri } from './server-pagination.js';
|
|
8
9
|
const ContextParser = JSONLDContextParser.ContextParser;
|
|
9
10
|
const myParser = new ContextParser();
|
|
10
11
|
export const base_context = {
|
|
@@ -69,7 +70,7 @@ class Store {
|
|
|
69
70
|
* Fetch data and cache it
|
|
70
71
|
* @param id - uri of the resource to fetch
|
|
71
72
|
* @param context - context used to expand id and predicates when accessing the resource
|
|
72
|
-
* @param
|
|
73
|
+
* @param parentId - uri of the parent caller used to expand uri for local files
|
|
73
74
|
* @param localData - data to put in cache
|
|
74
75
|
* @param forceFetch - force the fetch of data
|
|
75
76
|
*
|
|
@@ -79,16 +80,24 @@ class Store {
|
|
|
79
80
|
*/
|
|
80
81
|
|
|
81
82
|
|
|
82
|
-
async getData(id, context = {},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
async getData(id, context = {}, parentId = "", localData, forceFetch = false, serverPagination) {
|
|
84
|
+
let key = id;
|
|
85
|
+
|
|
86
|
+
if (serverPagination) {
|
|
87
|
+
key = id + "#p" + serverPagination.limit + "?o" + serverPagination.offset;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (localData == null && this.cache.has(key) && !this.loadingList.has(key)) {
|
|
91
|
+
var _resource$isFullResou;
|
|
92
|
+
|
|
93
|
+
const resource = this.get(key);
|
|
94
|
+
if (resource && (_resource$isFullResou = resource.isFullResource) !== null && _resource$isFullResou !== void 0 && _resource$isFullResou.call(resource) && !forceFetch) return resource; // if resource is not complete, re-fetch it
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
return new Promise(async resolve => {
|
|
89
|
-
document.addEventListener('resourceReady', this.resolveResource(
|
|
90
|
-
if (this.loadingList.has(
|
|
91
|
-
this.loadingList.add(
|
|
98
|
+
document.addEventListener('resourceReady', this.resolveResource(key, resolve));
|
|
99
|
+
if (this.loadingList.has(key)) return;
|
|
100
|
+
this.loadingList.add(key); // Generate proxy
|
|
92
101
|
|
|
93
102
|
const clientContext = await myParser.parse(context);
|
|
94
103
|
let resource = null;
|
|
@@ -98,26 +107,26 @@ class Store {
|
|
|
98
107
|
localData["@id"] = id;
|
|
99
108
|
resource = localData;
|
|
100
109
|
} else try {
|
|
101
|
-
resource = localData || (await this.fetchData(id, clientContext,
|
|
110
|
+
resource = localData || (await this.fetchData(id, clientContext, parentId, serverPagination));
|
|
102
111
|
} catch (error) {
|
|
103
112
|
console.error(error);
|
|
104
113
|
}
|
|
105
114
|
|
|
106
115
|
if (!resource) {
|
|
107
|
-
this.loadingList.delete(
|
|
116
|
+
this.loadingList.delete(key);
|
|
108
117
|
resolve(null);
|
|
109
118
|
return;
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
const serverContext = await myParser.parse([resource['@context'] || {}]);
|
|
113
|
-
const resourceProxy = new CustomGetter(
|
|
122
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, serverContext, parentId ? parentId : key, serverPagination).getProxy(); // Cache proxy
|
|
114
123
|
|
|
115
|
-
await this.cacheGraph(
|
|
116
|
-
this.loadingList.delete(
|
|
124
|
+
await this.cacheGraph(key, resourceProxy, clientContext, serverContext, parentId ? parentId : key, serverPagination);
|
|
125
|
+
this.loadingList.delete(key);
|
|
117
126
|
document.dispatchEvent(new CustomEvent('resourceReady', {
|
|
118
127
|
detail: {
|
|
119
|
-
id:
|
|
120
|
-
resource: this.get(
|
|
128
|
+
id: key,
|
|
129
|
+
resource: this.get(key)
|
|
121
130
|
}
|
|
122
131
|
}));
|
|
123
132
|
});
|
|
@@ -144,13 +153,14 @@ class Store {
|
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
155
|
|
|
147
|
-
async fetchData(id, context = {},
|
|
148
|
-
|
|
156
|
+
async fetchData(id, context = {}, parentId = "", serverPagination) {
|
|
157
|
+
let iri = this._getAbsoluteIri(id, context, parentId);
|
|
149
158
|
|
|
159
|
+
if (serverPagination) iri = appendServerPaginationToIri(iri, serverPagination);
|
|
150
160
|
const headers = { ...this.headers,
|
|
151
|
-
'accept-language': this._getLanguage()
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
'accept-language': this._getLanguage(),
|
|
162
|
+
'Prefer': 'return=representation; max-triple-count="500"'
|
|
163
|
+
};
|
|
154
164
|
return this.fetchAuthn(iri, {
|
|
155
165
|
method: 'GET',
|
|
156
166
|
headers: headers,
|
|
@@ -161,12 +171,13 @@ class Store {
|
|
|
161
171
|
});
|
|
162
172
|
}
|
|
163
173
|
|
|
164
|
-
async cacheGraph(key, resource, clientContext, parentContext, parentId) {
|
|
174
|
+
async cacheGraph(key, resource, clientContext, parentContext, parentId, serverPagination) {
|
|
165
175
|
if (resource.properties) {
|
|
166
176
|
// if proxy, cache it
|
|
167
|
-
if (this.get(key)) {
|
|
177
|
+
if (this.get(key) && this.cache.get(key).merge) {
|
|
168
178
|
// if already cached, merge data
|
|
169
179
|
this.cache.get(key).merge(resource);
|
|
180
|
+
;
|
|
170
181
|
} else {
|
|
171
182
|
// else, put in cache
|
|
172
183
|
this.cache.set(key, resource);
|
|
@@ -183,17 +194,17 @@ class Store {
|
|
|
183
194
|
});
|
|
184
195
|
const resourceProxy = new CustomGetter(res['@id'], res, clientContext, newParentContext, parentId).getProxy(); // this.subscribeResourceTo(resource['@id'], res['@id']); // removed to prevent useless updates
|
|
185
196
|
|
|
186
|
-
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId);
|
|
197
|
+
await this.cacheGraph(res['@id'], resourceProxy, clientContext, parentContext, parentId, serverPagination);
|
|
187
198
|
}
|
|
188
199
|
} // Cache children of container
|
|
189
200
|
|
|
190
201
|
|
|
191
202
|
if (resource['@type'] == "ldp:Container" && resource.getChildren) {
|
|
192
|
-
const cacheChildrenPromises = [];
|
|
203
|
+
const cacheChildrenPromises = []; //TODO: return complete object without the need for the fetch data from the cacheGraph
|
|
193
204
|
|
|
194
|
-
for (let res of resource.getChildren()) {
|
|
205
|
+
for (let res of await resource.getChildren()) {
|
|
195
206
|
this.subscribeResourceTo(resource['@id'], res['@id']);
|
|
196
|
-
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId));
|
|
207
|
+
cacheChildrenPromises.push(this.cacheGraph(res['@id'], res, clientContext, parentContext, parentId, serverPagination));
|
|
197
208
|
}
|
|
198
209
|
|
|
199
210
|
await Promise.all(cacheChildrenPromises);
|
|
@@ -212,7 +223,7 @@ class Store {
|
|
|
212
223
|
return;
|
|
213
224
|
}
|
|
214
225
|
|
|
215
|
-
const resourceProxy = new CustomGetter(
|
|
226
|
+
const resourceProxy = new CustomGetter(key, resource, clientContext, parentContext, parentId).getProxy();
|
|
216
227
|
await this.cacheGraph(key, resourceProxy, clientContext, parentContext, parentId);
|
|
217
228
|
}
|
|
218
229
|
}
|
|
@@ -319,8 +330,10 @@ class Store {
|
|
|
319
330
|
|
|
320
331
|
|
|
321
332
|
async getNestedResources(resource, id) {
|
|
333
|
+
var _cachedResource$isCon;
|
|
334
|
+
|
|
322
335
|
const cachedResource = store.get(id);
|
|
323
|
-
if (!cachedResource || cachedResource.isContainer()) return [];
|
|
336
|
+
if (!cachedResource || (_cachedResource$isCon = cachedResource.isContainer) !== null && _cachedResource$isCon !== void 0 && _cachedResource$isCon.call(cachedResource)) return [];
|
|
324
337
|
let nestedProperties = [];
|
|
325
338
|
const excludeKeys = ['@context'];
|
|
326
339
|
|
|
@@ -420,7 +433,6 @@ class Store {
|
|
|
420
433
|
|
|
421
434
|
|
|
422
435
|
async purge(id) {
|
|
423
|
-
// console.log('Purging resource ' + id);
|
|
424
436
|
await this.fetchAuthn(id, {
|
|
425
437
|
method: "PURGE",
|
|
426
438
|
headers: this.headers
|
|
@@ -591,7 +603,8 @@ class CustomGetter {
|
|
|
591
603
|
// context given by the app
|
|
592
604
|
// context given by the server
|
|
593
605
|
// id of the parent resource, used to get the absolute url of the current resource
|
|
594
|
-
|
|
606
|
+
// pagination attributes to give to server
|
|
607
|
+
constructor(resourceId, resource, clientContext, serverContext = {}, parentId = "", serverPagination = {}) {
|
|
595
608
|
_defineProperty(this, "resource", void 0);
|
|
596
609
|
|
|
597
610
|
_defineProperty(this, "resourceId", void 0);
|
|
@@ -602,12 +615,15 @@ class CustomGetter {
|
|
|
602
615
|
|
|
603
616
|
_defineProperty(this, "parentId", void 0);
|
|
604
617
|
|
|
618
|
+
_defineProperty(this, "serverPagination", void 0);
|
|
619
|
+
|
|
605
620
|
this.clientContext = clientContext;
|
|
606
621
|
this.serverContext = serverContext;
|
|
607
622
|
this.parentId = parentId;
|
|
608
623
|
this.resource = this.expandProperties({ ...resource
|
|
609
624
|
}, serverContext);
|
|
610
625
|
this.resourceId = resourceId;
|
|
626
|
+
this.serverPagination = serverPagination;
|
|
611
627
|
}
|
|
612
628
|
/**
|
|
613
629
|
* Expand all predicates of a resource with a given context
|