UNPKG

@digital-blueprint/formalize-app

Version:

[GitHub Repository](https://github.com/digital-blueprint/formalize-app) | [npmjs package](https://www.npmjs.com/package/@digital-blueprint/formalize-app) | [Unpkg CDN](https://unpkg.com/browse/@digital-blueprint/formalize-app/) | [Formalize Bundle](https:

100 lines (96 loc) 10.5 kB
let t,e,s,i,o=t=>t;function n(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function r(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?n(Object(s),!0).forEach((function(e){a(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):n(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}function a(t,e,s){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)} /*! * License: LGPL-2.1-or-later * Dependencies: * * @webcomponents/scoped-custom-element-registry: BSD-3-Clause * @dbp-toolkit/app-shell: LGPL-2.1-or-later * @dbp-toolkit/language-select: LGPL-2.1-or-later * @dbp-toolkit/auth: LGPL-2.1-or-later * @dbp-toolkit/theme-switcher: LGPL-2.1-or-later * universal-router: MIT * @dbp-toolkit/matomo: LGPL-2.1-or-later * @dbp-toolkit/tabulator-table: LGPL-2.1-or-later * xlsx: Apache-2.0 * jspdf-autotable: MIT * xss: MIT * cssfilter: MIT * @dbp-toolkit/common: LGPL-2.1-or-later * lit-html: BSD-3-Clause * @dbp-toolkit/file-handling: LGPL-2.1-or-later * webdav: MIT * jose: MIT * file-saver: MIT * @dbp-toolkit/grant-permission-dialog: LGPL-2.1-or-later * @dbp-toolkit/pdf-viewer: LGPL-2.1-or-later * pdfjs-dist: Apache-2.0 * html2pdf.js: MIT * jspdf: MIT * @dbp-toolkit/notification: LGPL-2.1-or-later * tabulator-tables: MIT * @babel/runtime: MIT * fflate: MIT * jquery: MIT * @dbp-toolkit/person-select: LGPL-2.1-or-later * select2: MIT * @dbp-toolkit/form-elements: LGPL-2.1-or-later */(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}import{i as l,S as u,D as d,d as c,e as h,f as b,x as m,P as p,Q as f,O as v,R as g}from"./notification.DekX2Yn_.es.js";import{c as y,g as S}from"./i18n.sFs-myza.es.js";const w=()=>l(t||(t=o` fieldset { border: none; margin: 15px 0; padding: 0; } fieldset label { font-weight: bold; display: block; margin-bottom: 0.5em; } fieldset input:not([type='radio']):not([type='checkbox']), fieldset select, fieldset textarea { width: calc(100% - 12px); padding: 2px 5px; border: var(--dbp-border); } `)),$=t=>Array.from(t.getElementsByTagName("*")).filter((t=>t.tagName.toLowerCase().match(/^dbp-.*-element$/))),A=t=>JSON.stringify(t).replace(/"/g,"&quot;"),O=t=>{let e={};const s=$(t);console.log("gatherFormDataFromElement elementWebComponents",s),s.forEach((t=>{const s=t.getAttribute("name")||t.id;e[s]=t.value}));const i=t.querySelectorAll("[data-value]");let o={};i.forEach((t=>{const e=t.getAttribute("name")||t.id,s=t.getAttribute("data-value"),i=s.replace(/&quot;/g,'"');try{o[e]=JSON.parse(i)}catch(t){o[e]=s}})),console.log("gatherFormDataFromElement dataValues",o);const n={};for(let[t,s]of Object.entries(e))_(n,t,s);const r=new FormData(t);for(let[t,e]of r.entries())_(n,t,e);for(let[t,e]of Object.entries(o))_(n,t,e);return console.log("gatherFormDataFromElement data",n),n},_=(t,e,s)=>{const i=e.replace(/\]/g,"").split("[");let o=t;for(let t=0;t<i.length;t++){const e=i[t];t===i.length-1?o[e]=s:(o[e]&&"object"==typeof o[e]||(o[e]={}),o=o[e])}};class E{getUrlSlug(){return"url-slug"}getFormComponent(){return D}getFormIdentifier(){return"uuid"}}class D extends(u(d)){constructor(){super(),this._i18n=y(),this.lang=this._i18n.language,this.formData={},this.entryPointUrl="",this.auth={},this.saveButtonEnabled=!0,this.formIdentifier="",this.formUrlSlug="",this.formProperties={},this.userAllSubmissions=[],this.allowedSubmissionStates=4,this.maxNumberOfSubmissionsPerUser=10,this.readOnly=!1,this.submissionId=""}async validateAndSendSubmission(t){t.preventDefault();const e=this.shadowRoot.querySelector("form"),s=await(async t=>{const e=$(t),s=O(t),i=e.map((t=>new Promise((e=>{const i=new CustomEvent("evaluate",{detail:{data:s,respond:e}});t.dispatchEvent(i)}))));return!(await Promise.all(i)).includes(!1)})(e);console.log("validateAndSendSubmission validationResult",s),s?this.sendSubmission(t):this.scrollToFirstInvalidField(e)}scrollToFirstInvalidField(t){const e=$(t);for(const t of e){const e=t.shadowRoot.querySelector(".validation-errors");if(e){const t=e.closest("fieldset").querySelector("label");t.style.scrollMarginTop="70px",t.scrollIntoView({behavior:"smooth"});break}}}sendSubmission(t){this.saveButtonEnabled=!1;const e=this.shadowRoot.querySelector("form"),s={formData:O(e)};console.log("sendSubmission data",s);const i=new CustomEvent("DbpFormalizeFormSubmission",{detail:s,bubbles:!0,composed:!0});this.dispatchEvent(i)}sendDraft(t){this.draftButtonEnabled=!1;const e=this.shadowRoot.querySelector("form"),s={formData:O(e)},i=new CustomEvent("DbpFormalizeFormSaveDraft",{bubbles:!0,composed:!0,detail:s});this.dispatchEvent(i)}sendDeleteSubmission(t){if(!this.submissionId)return;this.deleteButtonEnabled=!1;const e={submissionId:this.submissionId},s=new CustomEvent("DbpFormalizeFormDeleteSubmission",{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}acceptSubmission(t){if(!this.submissionId)return;this.acceptButtonEnabled=!1;const e={submissionId:this.submissionId},s=new CustomEvent("DbpFormalizeFormAcceptSubmission",{bubbles:!0,composed:!0,detail:e});this.dispatchEvent(s)}static get properties(){return r(r({},super.properties),{},{lang:{type:String},person:{type:Object},additionalType:{type:String,attribute:"additional-type"},formData:{type:Object,attribute:!1},data:{type:Object},auth:{type:Object},entryPointUrl:{type:String,attribute:"entry-point-url"},formIdentifier:{type:String,attribute:"form-identifier"},formUrlSlug:{type:String,attribute:"form-url-slug"},readOnly:{type:Boolean,attribute:"read-only"},allowedSubmissionStates:{type:Number,attribute:"allowed-submission-states"},maxNumberOfSubmissionsPerUser:{type:String,attribute:"max-number-of-submissions"},formProperties:{type:Object},userAllSubmissions:{type:Array},saveButtonEnabled:{type:Boolean,attribute:!1}})}static get styles(){return l(e||(e=o` ${0} ${0} ${0} .button-row { margin-top: 1em; text-align: right; } `),c(!1),h(),S())}resetForm(t){t.preventDefault(),this.saveButtonEnabled=!0,this.formData={};const e=new CustomEvent("DbpFormalizeFormReset",{bubbles:!0,composed:!0});this.dispatchEvent(e)}getButtonRowHtml(){const t=this._i18n;return m(s||(s=o` <div class="button-row"> <button class="button is-secondary" type="button" @click=${0} hidden> ${0} </button> <button class="button is-primary" type="submit" ?disabled=${0} @click=${0}> ${0} <dbp-mini-spinner class="${0}"></dbp-mini-spinner> </button> </div> `),this.resetForm,t.t("render-form.button-row.reset"),!this.saveButtonEnabled,this.validateAndSendSubmission,t.t("render-form.button-row.submit"),b({hidden:this.saveButtonEnabled}))}update(t){t.forEach(((t,e)=>{if("lang"===e)this._i18n.changeLanguage(this.lang)})),super.update(t)}render(){return console.log("-- Render BaseFormElement --"),m(i||(i=o` <form>Please implement render() in your subclass! ${0}</form> `),this.getButtonRowHtml())}} /** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const F=t=>void 0===t.strings,j={},P=(t,e=j)=>t._$AH=e,C=(t,e)=>{const s=t._$AN;if(void 0===s)return!1;for(const t of s){var i;null!==(i=t._$AO)&&void 0!==i&&i.call(t,e,!1),C(t,e)}return!0},B=t=>{let e,s;do{var i;if(void 0===(e=t._$AM))break;s=e._$AN,s.delete(t),t=e}while(0===(null===(i=s)||void 0===i?void 0:i.size))},I=t=>{for(let e;e=t._$AM;t=e){let s=e._$AN;if(void 0===s)e._$AN=s=new Set;else if(s.has(t))break;s.add(t),G(e)}}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function x(t){void 0!==this._$AN?(B(this),this._$AM=t,I(this)):this._$AM=t}function N(t,e=!1,s=0){const i=this._$AH,o=this._$AN;if(void 0!==o&&0!==o.size)if(e)if(Array.isArray(i))for(let t=s;t<i.length;t++)C(i[t],!1),B(i[t]);else null!=i&&(C(i,!1),B(i));else C(this,t)}const G=t=>{var e,s;t.type==f.CHILD&&(null!==(e=t._$AP)&&void 0!==e||(t._$AP=N),null!==(s=t._$AQ)&&void 0!==s||(t._$AQ=x))};class k extends p{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,s){super._$AT(t,e,s),I(this),this.isConnected=t._$AU}_$AO(t,e=!0){var s,i;t!==this.isConnected&&(this.isConnected=t,t?null===(s=this.reconnected)||void 0===s||s.call(this):null===(i=this.disconnected)||void 0===i||i.call(this)),e&&(C(this,t),B(this))}setValue(t){if(F(this._$Ct))this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}} /** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const R=()=>new T;class T{}const q=new WeakMap,U=v(class extends k{render(t){return g}update(t,[e]){var s;const i=e!==this.G;return i&&void 0!==this.G&&this.rt(void 0),(i||this.lt!==this.ct)&&(this.G=e,this.ht=null===(s=t.options)||void 0===s?void 0:s.host,this.rt(this.ct=t.element)),g}rt(t){if(this.isConnected||(t=void 0),"function"==typeof this.G){var e;const s=null!==(e=this.ht)&&void 0!==e?e:globalThis;let i=q.get(s);void 0===i&&(i=new WeakMap,q.set(s,i)),void 0!==i.get(this.G)&&this.G.call(this.ht,void 0),i.set(this.G,t),void 0!==t&&this.G.call(this.ht,t)}else this.G.value=t}get lt(){var t,e,s;return"function"==typeof this.G?null===(t=q.get(null!==(e=this.ht)&&void 0!==e?e:globalThis))||void 0===t?void 0:t.get(this.G):null===(s=this.G)||void 0===s?void 0:s.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});export{E as B,D as a,w as b,R as e,F as f,O as g,P as m,U as n,A as s}; //# sourceMappingURL=ref.Ds46LGIc.es.js.map