@foxy.io/elements 1.13.0-beta.3 → 1.14.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/foxy-access-recovery-form.js +1 -1
- package/dist/cdn/foxy-address-card.js +1 -1
- package/dist/cdn/foxy-address-form.js +1 -1
- package/dist/cdn/foxy-applied-tax-card.js +1 -1
- package/dist/cdn/foxy-attribute-card.js +1 -1
- package/dist/cdn/foxy-attribute-form.js +1 -1
- package/dist/cdn/foxy-cancellation-form.js +1 -1
- package/dist/cdn/foxy-collection-page.js +1 -1
- package/dist/cdn/foxy-collection-pages.js +1 -1
- package/dist/cdn/foxy-custom-field-card.js +1 -1
- package/dist/cdn/foxy-custom-field-form.js +1 -1
- package/dist/cdn/foxy-customer-api.js +1 -1
- package/dist/cdn/foxy-customer-card.js +1 -1
- package/dist/cdn/foxy-customer-form.js +1 -1
- package/dist/cdn/foxy-customer-portal-settings.js +2 -2
- package/dist/cdn/foxy-customer-portal.js +1 -1
- package/dist/cdn/foxy-customer.js +1 -1
- package/dist/cdn/foxy-customers-table.js +1 -1
- package/dist/cdn/foxy-discount-card.js +1 -1
- package/dist/cdn/foxy-donation.js +1 -1
- package/dist/cdn/foxy-email-template-form.js +1 -0
- package/dist/cdn/foxy-error-entry-card.js +1 -1
- package/dist/cdn/foxy-form-dialog.js +1 -1
- package/dist/cdn/foxy-i18n.js +1 -1
- package/dist/cdn/foxy-items-form.js +1 -1
- package/dist/cdn/foxy-nucleon-element.js +1 -1
- package/dist/cdn/foxy-payment-card.js +1 -1
- package/dist/cdn/foxy-payment-method-card.js +1 -1
- package/dist/cdn/foxy-query-builder.js +2 -2
- package/dist/cdn/foxy-sign-in-form.js +1 -1
- package/dist/cdn/foxy-spinner.js +2 -2
- package/dist/cdn/foxy-subscription-card.js +1 -1
- package/dist/cdn/foxy-subscription-form.js +24 -7
- package/dist/cdn/foxy-subscriptions-table.js +1 -1
- package/dist/cdn/foxy-table.js +1 -1
- package/dist/cdn/foxy-tax-card.js +1 -1
- package/dist/cdn/foxy-tax-form.js +1 -1
- package/dist/cdn/foxy-template-form.js +1 -0
- package/dist/cdn/foxy-transaction-card.js +1 -1
- package/dist/cdn/foxy-transactions-table.js +1 -1
- package/dist/cdn/foxy-user-form.js +1 -1
- package/dist/cdn/foxy-users-table.js +1 -1
- package/dist/cdn/{shared-b98f88c9.js → shared-04b77f79.js} +1 -1
- package/dist/cdn/{shared-bf09e011.js → shared-1108653b.js} +23 -18
- package/dist/cdn/{shared-d4dad105.js → shared-14788132.js} +1 -1
- package/dist/cdn/{shared-54702b33.js → shared-27d93838.js} +1 -1
- package/dist/cdn/shared-2b2b56f6.js +1 -0
- package/dist/cdn/{shared-91a9e922.js → shared-2d99835c.js} +4 -4
- package/dist/cdn/{shared-f47647ac.js → shared-302d8a7b.js} +1 -1
- package/dist/cdn/{shared-5fedf5e4.js → shared-3534b284.js} +2 -2
- package/dist/cdn/shared-3553ff4d.js +1 -0
- package/dist/cdn/{shared-4059f633.js → shared-3e14c0d2.js} +1 -1
- package/dist/cdn/{shared-45d647e4.js → shared-46ee137f.js} +1 -1
- package/dist/cdn/{shared-296637c5.js → shared-4ee97558.js} +1 -1
- package/dist/cdn/{shared-d9159fe1.js → shared-57522229.js} +1 -1
- package/dist/cdn/{shared-2860a3d3.js → shared-59a0cb0f.js} +2 -2
- package/dist/cdn/{shared-cd700eac.js → shared-60126eee.js} +1 -1
- package/dist/cdn/{shared-84fa75d9.js → shared-652ef7fe.js} +1 -1
- package/dist/cdn/{shared-036a8b21.js → shared-72678c5d.js} +1 -1
- package/dist/cdn/shared-7fd12533.js +1 -0
- package/dist/cdn/shared-82dd0556.js +15 -0
- package/dist/cdn/{shared-67157a25.js → shared-84df58e1.js} +1 -1
- package/dist/cdn/{shared-ed4ed7a5.js → shared-8e38d64f.js} +2 -2
- package/dist/cdn/{shared-54c485d2.js → shared-92442eb1.js} +21 -21
- package/dist/cdn/{shared-98ee7fad.js → shared-94c83b2b.js} +1 -1
- package/dist/cdn/{shared-4a990126.js → shared-a0c2bbe0.js} +1 -1
- package/dist/cdn/{shared-e55b6bb7.js → shared-a21a7562.js} +1 -1
- package/dist/cdn/{shared-f0199313.js → shared-a4410f22.js} +1 -1
- package/dist/cdn/{shared-e0248713.js → shared-a71bd9f0.js} +1 -1
- package/dist/cdn/{shared-e9920617.js → shared-acf49ecc.js} +1 -1
- package/dist/cdn/{shared-cf248335.js → shared-b8349f79.js} +1 -1
- package/dist/cdn/{shared-f2cf6cfb.js → shared-bbc97ae0.js} +1 -1
- package/dist/cdn/shared-bec929ac.js +1 -0
- package/dist/cdn/{shared-145cc9eb.js → shared-c7f352fa.js} +5 -5
- package/dist/cdn/{shared-f4119f12.js → shared-d196432b.js} +1 -1
- package/dist/cdn/shared-d19e2399.js +1 -0
- package/dist/cdn/{shared-17968c53.js → shared-d97a6ee5.js} +0 -0
- package/dist/cdn/{shared-3ae39e52.js → shared-dce03b47.js} +3 -3
- package/dist/cdn/{shared-a99dea97.js → shared-dd66b354.js} +1 -1
- package/dist/cdn/{shared-b77179fd.js → shared-e969772e.js} +1 -1
- package/dist/cdn/{shared-e5de8675.js → shared-fda14a3d.js} +1 -1
- package/dist/cdn/{shared-747b0842.js → shared-ff79f3f9.js} +1 -1
- package/dist/cdn/translations/shared/en.json +11 -0
- package/dist/elements/private/Choice/Choice.js +0 -2
- package/dist/elements/private/Choice/Choice.js.map +1 -1
- package/dist/elements/private/I18N/I18N.js +1 -1
- package/dist/elements/private/I18N/I18N.js.map +1 -1
- package/dist/elements/public/AddressForm/AddressForm.js +8 -4
- package/dist/elements/public/AddressForm/AddressForm.js.map +1 -1
- package/dist/elements/public/AttributeForm/AttributeForm.js +8 -4
- package/dist/elements/public/AttributeForm/AttributeForm.js.map +1 -1
- package/dist/elements/public/CustomFieldForm/CustomFieldForm.js +8 -4
- package/dist/elements/public/CustomFieldForm/CustomFieldForm.js.map +1 -1
- package/dist/elements/public/CustomerForm/CustomerForm.js +8 -4
- package/dist/elements/public/CustomerForm/CustomerForm.js.map +1 -1
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.d.ts +24 -0
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.js +311 -0
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.js.map +1 -0
- package/dist/elements/public/EmailTemplateForm/index.d.ts +9 -0
- package/dist/elements/public/EmailTemplateForm/index.js +11 -0
- package/dist/elements/public/EmailTemplateForm/index.js.map +1 -0
- package/dist/elements/public/EmailTemplateForm/types.d.ts +3 -0
- package/dist/elements/public/EmailTemplateForm/types.js +2 -0
- package/dist/elements/public/EmailTemplateForm/types.js.map +1 -0
- package/dist/elements/public/ItemsForm/ItemsForm.js +2 -2
- package/dist/elements/public/ItemsForm/ItemsForm.js.map +1 -1
- package/dist/elements/public/NucleonElement/serveFromCache.js +1 -0
- package/dist/elements/public/NucleonElement/serveFromCache.js.map +1 -1
- package/dist/elements/public/TaxForm/TaxForm.js +8 -4
- package/dist/elements/public/TaxForm/TaxForm.js.map +1 -1
- package/dist/elements/public/TemplateForm/TemplateForm.d.ts +23 -0
- package/dist/elements/public/TemplateForm/TemplateForm.js +303 -0
- package/dist/elements/public/TemplateForm/TemplateForm.js.map +1 -0
- package/dist/elements/public/TemplateForm/index.d.ts +9 -0
- package/dist/elements/public/TemplateForm/index.js +11 -0
- package/dist/elements/public/TemplateForm/index.js.map +1 -0
- package/dist/elements/public/TemplateForm/types.d.ts +3 -0
- package/dist/elements/public/TemplateForm/types.js +2 -0
- package/dist/elements/public/TemplateForm/types.js.map +1 -0
- package/dist/elements/public/index.d.ts +2 -0
- package/dist/elements/public/index.defined.d.ts +2 -0
- package/dist/elements/public/index.defined.js +2 -0
- package/dist/elements/public/index.defined.js.map +1 -1
- package/dist/elements/public/index.js +2 -0
- package/dist/elements/public/index.js.map +1 -1
- package/dist/mixins/themeable.js +43 -12
- package/dist/mixins/themeable.js.map +1 -1
- package/package.json +2 -7
- package/dist/cdn/shared-50744508.js +0 -15
- package/dist/cdn/shared-b0b1d248.js +0 -1
- package/dist/cdn/shared-c0161e6a.js +0 -1
- package/dist/cdn/shared-c1e0e11f.js +0 -1
- package/dist/cdn/shared-dbcffd8e.js +0 -1
- package/dist/cdn/shared-e21a2aac.js +0 -1
|
@@ -92,10 +92,14 @@ export class CustomFieldForm extends Base {
|
|
|
92
92
|
`;
|
|
93
93
|
};
|
|
94
94
|
this.__renderTimestamps = () => {
|
|
95
|
-
const items = ['date_modified', 'date_created'].map(field =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
const items = ['date_modified', 'date_created'].map(field => {
|
|
96
|
+
var _a;
|
|
97
|
+
return ({
|
|
98
|
+
name: this.t(field),
|
|
99
|
+
value: ((_a = this.data) === null || _a === void 0 ? void 0 : _a[field]) ? this.t('date', { value: new Date(this.data[field]) })
|
|
100
|
+
: '',
|
|
101
|
+
});
|
|
102
|
+
});
|
|
99
103
|
return html `
|
|
100
104
|
<div>
|
|
101
105
|
${this.renderTemplateOrSlot('timestamps:before')}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomFieldForm.js","sourceRoot":"","sources":["../../../../src/elements/public/CustomFieldForm/CustomFieldForm.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAkB,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AAGjE,OAAO,EAAE,cAAc,EAAE,4CAAyC;AAElE,OAAO,EAAE,aAAa,EAAE,+BAA4B;AACpD,OAAO,EAAE,cAAc,EAAE,qCAAkC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AACjE,OAAO,EAAE,QAAQ,EAAE,oCAAiC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAEx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opedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\nimport { TemplateResult, html } from 'lit-html';\n\nimport { CheckboxElement } from '@vaadin/vaadin-checkbox';\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/NucleonElement';\nimport { NucleonV8N } from '../NucleonElement/types';\nimport { PropertyTable } from '../../private/index';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport memoize from 'lodash-es/memoize';\n\nconst NS = 'custom-field-form';\nconst Base = TranslatableMixin(\n ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(NucleonElement))),\n NS\n);\n\n/**\n * Form element for creating or editing custom fields.\n *\n * @slot name:before\n * @slot name:after\n * @slot value:before\n * @slot value:after\n * @slot visibility:before\n * @slot visibility:after\n * @slot timestamps:before\n * @slot timestamps:after\n * @slot create:before\n * @slot create:after\n * @slot delete:before\n * @slot delete:after\n *\n * @element foxy-custom-field-form\n * @since 1.11.0\n */\nexport class CustomFieldForm extends Base<Data> {\n static get scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),\n 'vaadin-text-field': customElements.get('vaadin-text-field'),\n 'vaadin-checkbox': customElements.get('vaadin-checkbox'),\n 'x-property-table': PropertyTable,\n 'vaadin-button': customElements.get('vaadin-button'),\n 'foxy-i18n': customElements.get('foxy-i18n'),\n 'foxy-spinner': customElements.get('foxy-spinner'),\n };\n }\n\n static get v8n(): NucleonV8N<Data> {\n return [\n ({ value }) => (value && value.length > 0) || 'value_required',\n ({ value }) => (value && value.length <= 1000) || 'value_too_long',\n ({ name }) => (name && name.length > 0) || 'name_required',\n ({ name }) => (name && name.length <= 500) || 'name_too_long',\n ];\n }\n\n templates: Templates = {};\n\n private readonly __getValidator = memoize((prefix: string) => () => {\n return !this.errors.some(err => err.startsWith(prefix));\n });\n\n private readonly __bindField = memoize((key: keyof Data) => {\n return (evt: CustomEvent) => {\n const target = evt.target as HTMLInputElement;\n this.edit({ [key]: target.value });\n };\n });\n\n private readonly __maybeRenderTextField = ({ field }: TextFieldParams) => {\n const bsid = field.replace(/_/, '-');\n if (this.hiddenSelector.matches(bsid)) return '';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${bsid}:before`)}\n\n <vaadin-text-field\n class=\"w-full\"\n label=${this.t(field).toString()}\n value=${ifDefined(this.form?.[field]?.toString())}\n error-message=${this.__getErrorMessage(field)}\n data-testid=${field}\n .checkValidity=${this.__getValidator(field)}\n ?disabled=${!this.in('idle') || this.disabledSelector.matches(bsid)}\n ?readonly=${this.readonlySelector.matches(bsid)}\n @input=${this.__bindField(field)}\n @keydown=${this.__handleKeyDown}\n >\n </vaadin-text-field>\n\n ${this.renderTemplateOrSlot(`${bsid}:after`)}\n </div>\n `;\n };\n\n private readonly __renderVisibility = () => {\n const { disabledSelector, form, lang, ns } = this;\n const isDisabled = !this.in('idle') || disabledSelector.matches('visibility', true);\n\n return html`\n <div data-testid=\"visibility\">\n ${this.renderTemplateOrSlot('visibility:before')}\n\n <vaadin-checkbox\n ?disabled=${isDisabled}\n ?checked=${!form.is_hidden}\n @change=${(evt: CustomEvent) => {\n const checkbox = evt.currentTarget as CheckboxElement;\n this.edit({ is_hidden: !checkbox.checked });\n }}\n >\n <foxy-i18n lang=${lang} key=\"show_on_receipt\" ns=${ns}></foxy-i18n>\n </vaadin-checkbox>\n\n ${this.renderTemplateOrSlot('visibility:after')}\n </div>\n `;\n };\n\n private readonly __renderTimestamps = () => {\n const items = (['date_modified', 'date_created'] as const).map(field => ({\n name: this.t(field),\n value: this.t('date', { value: new Date(this.data![field]) }),\n }));\n\n return html`\n <div>\n ${this.renderTemplateOrSlot('timestamps:before')}\n <x-property-table .items=${items} data-testid=\"timestamps\"></x-property-table>\n ${this.renderTemplateOrSlot('timestamps:after')}\n </div>\n `;\n };\n\n private readonly __renderDelete = () => {\n return html`\n <div>\n ${this.renderTemplateOrSlot('delete:before')}\n\n <vaadin-button\n class=\"w-full\"\n data-testid=\"delete\"\n theme=\"error primary\"\n ?disabled=${!this.in('idle') || this.disabledSelector.matches('delete', true)}\n @click=${this.__handleDeleteClick}\n >\n <foxy-i18n ns=${this.ns} lang=${this.lang} key=\"delete\"></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot('delete:after')}\n </div>\n `;\n };\n\n private readonly __renderCreate = () => {\n const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });\n const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });\n const isValid = isTemplateValid || isSnapshotValid;\n\n return html`\n <div>\n ${this.renderTemplateOrSlot('create:before')}\n\n <vaadin-button\n data-testid=\"create\"\n class=\"w-full\"\n theme=\"success primary\"\n ?disabled=${!this.in('idle') || !isValid || this.disabledSelector.matches('create', true)}\n @click=${() => this.submit()}\n >\n <foxy-i18n ns=${this.ns} lang=${this.lang} key=\"create\"></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot('create:after')}\n </div>\n `;\n };\n\n render(): TemplateResult {\n const { hiddenSelector, data, lang, ns } = this;\n const isBusy = this.in('busy');\n const isFail = this.in('fail');\n\n return html`\n <foxy-internal-confirm-dialog\n data-testid=\"confirm\"\n message=\"delete_prompt\"\n confirm=\"delete\"\n cancel=\"cancel\"\n header=\"delete\"\n theme=\"primary error\"\n lang=${lang}\n ns=${ns}\n id=\"confirm\"\n @hide=${this.__handleConfirmHide}\n >\n </foxy-internal-confirm-dialog>\n\n <div class=\"relative\" aria-busy=${this.in('busy')} aria-live=\"polite\">\n <div class=\"grid grid-cols-1 gap-l\">\n ${this.__maybeRenderTextField({ field: 'name' })}\n ${this.__maybeRenderTextField({ field: 'value' })}\n ${hiddenSelector.matches('visibility', true) ? '' : this.__renderVisibility()}\n ${hiddenSelector.matches('timestamps', true) || !data ? '' : this.__renderTimestamps()}\n ${hiddenSelector.matches('delete', true) || !data ? '' : this.__renderDelete()}\n ${hiddenSelector.matches('create', true) || data ? '' : this.__renderCreate()}\n </div>\n\n <div\n data-testid=\"spinner\"\n class=${classMap({\n 'transition duration-500 ease-in-out absolute inset-0 flex': true,\n 'opacity-0 pointer-events-none': !isBusy && !isFail,\n })}\n >\n <foxy-spinner\n layout=\"vertical\"\n class=\"m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l\"\n state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}\n lang=${lang}\n ns=${ns}\n >\n </foxy-spinner>\n </div>\n </div>\n `;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.__bindField.cache.clear?.();\n this.__getValidator.cache.clear?.();\n }\n\n private get __confirmDialog(): InternalConfirmDialog {\n return this.renderRoot.querySelector('#confirm') as InternalConfirmDialog;\n }\n\n private __getErrorMessage(prefix: string) {\n const error = this.errors.find(err => err.startsWith(prefix));\n return error ? this.t(error.replace(prefix, 'v8n')).toString() : '';\n }\n\n private __handleKeyDown(evt: KeyboardEvent) {\n if (evt.key === 'Enter') this.submit();\n }\n\n private __handleDeleteClick(evt: Event) {\n this.__confirmDialog.show(evt.currentTarget as HTMLElement);\n }\n\n private __handleConfirmHide(evt: DialogHideEvent) {\n if (!evt.detail.cancelled) this.delete();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CustomFieldForm.js","sourceRoot":"","sources":["../../../../src/elements/public/CustomFieldForm/CustomFieldForm.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAkB,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AAGjE,OAAO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B;QACxC,IAAI,GAAG,CAAC,GAAG,KAAK,OAAO;YAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IACzC,CAAC;IAEO,mBAAmB,CAAC,GAAU;QACpC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,aAA4B,CAAC,CAAC;IAC9D,CAAC;IAEO,mBAAmB,CAAC,GAAoB;QAC9C,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS;YAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { Data, Templates, TextFieldParams } from './types';\nimport { ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\nimport { TemplateResult, html } from 'lit-html';\n\nimport { CheckboxElement } from '@vaadin/vaadin-checkbox';\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/NucleonElement';\nimport { NucleonV8N } from '../NucleonElement/types';\nimport { PropertyTable } from '../../private/index';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport memoize from 'lodash-es/memoize';\n\nconst NS = 'custom-field-form';\nconst Base = TranslatableMixin(\n ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(NucleonElement))),\n NS\n);\n\n/**\n * Form element for creating or editing custom fields.\n *\n * @slot name:before\n * @slot name:after\n * @slot value:before\n * @slot value:after\n * @slot visibility:before\n * @slot visibility:after\n * @slot timestamps:before\n * @slot timestamps:after\n * @slot create:before\n * @slot create:after\n * @slot delete:before\n * @slot delete:after\n *\n * @element foxy-custom-field-form\n * @since 1.11.0\n */\nexport class CustomFieldForm extends Base<Data> {\n static get scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),\n 'vaadin-text-field': customElements.get('vaadin-text-field'),\n 'vaadin-checkbox': customElements.get('vaadin-checkbox'),\n 'x-property-table': PropertyTable,\n 'vaadin-button': customElements.get('vaadin-button'),\n 'foxy-i18n': customElements.get('foxy-i18n'),\n 'foxy-spinner': customElements.get('foxy-spinner'),\n };\n }\n\n static get v8n(): NucleonV8N<Data> {\n return [\n ({ value }) => (value && value.length > 0) || 'value_required',\n ({ value }) => (value && value.length <= 1000) || 'value_too_long',\n ({ name }) => (name && name.length > 0) || 'name_required',\n ({ name }) => (name && name.length <= 500) || 'name_too_long',\n ];\n }\n\n templates: Templates = {};\n\n private readonly __getValidator = memoize((prefix: string) => () => {\n return !this.errors.some(err => err.startsWith(prefix));\n });\n\n private readonly __bindField = memoize((key: keyof Data) => {\n return (evt: CustomEvent) => {\n const target = evt.target as HTMLInputElement;\n this.edit({ [key]: target.value });\n };\n });\n\n private readonly __maybeRenderTextField = ({ field }: TextFieldParams) => {\n const bsid = field.replace(/_/, '-');\n if (this.hiddenSelector.matches(bsid)) return '';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${bsid}:before`)}\n\n <vaadin-text-field\n class=\"w-full\"\n label=${this.t(field).toString()}\n value=${ifDefined(this.form?.[field]?.toString())}\n error-message=${this.__getErrorMessage(field)}\n data-testid=${field}\n .checkValidity=${this.__getValidator(field)}\n ?disabled=${!this.in('idle') || this.disabledSelector.matches(bsid)}\n ?readonly=${this.readonlySelector.matches(bsid)}\n @input=${this.__bindField(field)}\n @keydown=${this.__handleKeyDown}\n >\n </vaadin-text-field>\n\n ${this.renderTemplateOrSlot(`${bsid}:after`)}\n </div>\n `;\n };\n\n private readonly __renderVisibility = () => {\n const { disabledSelector, form, lang, ns } = this;\n const isDisabled = !this.in('idle') || disabledSelector.matches('visibility', true);\n\n return html`\n <div data-testid=\"visibility\">\n ${this.renderTemplateOrSlot('visibility:before')}\n\n <vaadin-checkbox\n ?disabled=${isDisabled}\n ?checked=${!form.is_hidden}\n @change=${(evt: CustomEvent) => {\n const checkbox = evt.currentTarget as CheckboxElement;\n this.edit({ is_hidden: !checkbox.checked });\n }}\n >\n <foxy-i18n lang=${lang} key=\"show_on_receipt\" ns=${ns}></foxy-i18n>\n </vaadin-checkbox>\n\n ${this.renderTemplateOrSlot('visibility:after')}\n </div>\n `;\n };\n\n private readonly __renderTimestamps = () => {\n const items = (['date_modified', 'date_created'] as const).map(field => ({\n name: this.t(field),\n value: this.data?.[field]\n ? this.t('date', { value: new Date(this.data[field] as string) })\n : '',\n }));\n\n return html`\n <div>\n ${this.renderTemplateOrSlot('timestamps:before')}\n <x-property-table .items=${items} data-testid=\"timestamps\"></x-property-table>\n ${this.renderTemplateOrSlot('timestamps:after')}\n </div>\n `;\n };\n\n private readonly __renderDelete = () => {\n return html`\n <div>\n ${this.renderTemplateOrSlot('delete:before')}\n\n <vaadin-button\n class=\"w-full\"\n data-testid=\"delete\"\n theme=\"error primary\"\n ?disabled=${!this.in('idle') || this.disabledSelector.matches('delete', true)}\n @click=${this.__handleDeleteClick}\n >\n <foxy-i18n ns=${this.ns} lang=${this.lang} key=\"delete\"></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot('delete:after')}\n </div>\n `;\n };\n\n private readonly __renderCreate = () => {\n const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });\n const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });\n const isValid = isTemplateValid || isSnapshotValid;\n\n return html`\n <div>\n ${this.renderTemplateOrSlot('create:before')}\n\n <vaadin-button\n data-testid=\"create\"\n class=\"w-full\"\n theme=\"success primary\"\n ?disabled=${!this.in('idle') || !isValid || this.disabledSelector.matches('create', true)}\n @click=${() => this.submit()}\n >\n <foxy-i18n ns=${this.ns} lang=${this.lang} key=\"create\"></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot('create:after')}\n </div>\n `;\n };\n\n render(): TemplateResult {\n const { hiddenSelector, data, lang, ns } = this;\n const isBusy = this.in('busy');\n const isFail = this.in('fail');\n\n return html`\n <foxy-internal-confirm-dialog\n data-testid=\"confirm\"\n message=\"delete_prompt\"\n confirm=\"delete\"\n cancel=\"cancel\"\n header=\"delete\"\n theme=\"primary error\"\n lang=${lang}\n ns=${ns}\n id=\"confirm\"\n @hide=${this.__handleConfirmHide}\n >\n </foxy-internal-confirm-dialog>\n\n <div class=\"relative\" aria-busy=${this.in('busy')} aria-live=\"polite\">\n <div class=\"grid grid-cols-1 gap-l\">\n ${this.__maybeRenderTextField({ field: 'name' })}\n ${this.__maybeRenderTextField({ field: 'value' })}\n ${hiddenSelector.matches('visibility', true) ? '' : this.__renderVisibility()}\n ${hiddenSelector.matches('timestamps', true) || !data ? '' : this.__renderTimestamps()}\n ${hiddenSelector.matches('delete', true) || !data ? '' : this.__renderDelete()}\n ${hiddenSelector.matches('create', true) || data ? '' : this.__renderCreate()}\n </div>\n\n <div\n data-testid=\"spinner\"\n class=${classMap({\n 'transition duration-500 ease-in-out absolute inset-0 flex': true,\n 'opacity-0 pointer-events-none': !isBusy && !isFail,\n })}\n >\n <foxy-spinner\n layout=\"vertical\"\n class=\"m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l\"\n state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}\n lang=${lang}\n ns=${ns}\n >\n </foxy-spinner>\n </div>\n </div>\n `;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.__bindField.cache.clear?.();\n this.__getValidator.cache.clear?.();\n }\n\n private get __confirmDialog(): InternalConfirmDialog {\n return this.renderRoot.querySelector('#confirm') as InternalConfirmDialog;\n }\n\n private __getErrorMessage(prefix: string) {\n const error = this.errors.find(err => err.startsWith(prefix));\n return error ? this.t(error.replace(prefix, 'v8n')).toString() : '';\n }\n\n private __handleKeyDown(evt: KeyboardEvent) {\n if (evt.key === 'Enter') this.submit();\n }\n\n private __handleDeleteClick(evt: Event) {\n this.__confirmDialog.show(evt.currentTarget as HTMLElement);\n }\n\n private __handleConfirmHide(evt: DialogHideEvent) {\n if (!evt.detail.cancelled) this.delete();\n }\n}\n"]}
|
|
@@ -81,10 +81,14 @@ export class CustomerForm extends Base {
|
|
|
81
81
|
|
|
82
82
|
<x-property-table
|
|
83
83
|
data-testid="timestamps"
|
|
84
|
-
.items=${['date_modified', 'date_created'].map(field =>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
.items=${['date_modified', 'date_created'].map(field => {
|
|
85
|
+
var _a;
|
|
86
|
+
return ({
|
|
87
|
+
name: this.t(field),
|
|
88
|
+
value: ((_a = this.data) === null || _a === void 0 ? void 0 : _a[field]) ? this.t('date', { value: new Date(this.data[field]) })
|
|
89
|
+
: '',
|
|
90
|
+
});
|
|
91
|
+
})}
|
|
88
92
|
>
|
|
89
93
|
</x-property-table>
|
|
90
94
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomerForm.js","sourceRoot":"","sources":["../../../../src/elements/public/CustomerForm/CustomerForm.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAAkB,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AAGjE,OAAO,EAAE,cAAc,EAAE,mCAAgC;AAEzD,OAAO,EAAE,aAAa,EAAE,+BAA4B;AACpD,OAAO,EAAE,eAAe,EAAE,sCAAmC;AAC7D,OAAO,EAAE,cAAc,EAAE,qCAAkC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AACjE,OAAO,EAAE,QAAQ,EAAE,oCAAiC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,OAAO,MAA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IzD,QAAQ,CAAC;YACf,2DAA2D,EAAE,IAAI;YACjE,+BAA+B,EAAE,CAAC,MAAM,IAAI,CAAC,MAAM;SACpD,CAAC;;;;;oBAKQ,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;mBAC7C,IAAI;kBACL,EAAE,IAAI,YAAA,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,0CAAE,SAAS,mCAAI,EAAE;;;;;KAKtE,CAAC;IACJ,CAAC;IAED,oBAAoB;;QAClB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,MAAA,MAAA,IAAI,CAAC,cAAc,CAAC,KAAK,EAAC,KAAK,mDAAK;IACtC,CAAC;CACF","sourcesContent":["import { Data, Templates, TextFieldParams } from './types';\nimport { ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\nimport { TemplateResult, html } from 'lit-html';\n\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/index';\nimport { NucleonV8N } from '../NucleonElement/types';\nimport { PropertyTable } from '../../private/index';\nimport { ResponsiveMixin } from '../../../mixins/responsive';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { validate as isEmail } from 'email-validator';\nimport memoize from 'lodash-es/memoize';\n\nconst NS = 'customer-form';\nconst Base = ResponsiveMixin(\n ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(TranslatableMixin(NucleonElement, NS))))\n);\n\n/**\n * Form element for creating or editing customers.\n *\n * @slot first-name:before - **new in v1.4.0**\n * @slot first-name:after - **new in v1.4.0**\n *\n * @slot last-name:before - **new in v1.4.0**\n * @slot last-name:after - **new in v1.4.0**\n *\n * @slot email:before - **new in v1.4.0**\n * @slot email:after - **new in v1.4.0**\n *\n * @slot tax-id:before - **new in v1.4.0**\n * @slot tax-id:after - **new in v1.4.0**\n *\n * @slot timestamps:before - **new in v1.4.0**\n * @slot timestamps:after - **new in v1.4.0**\n *\n * @slot create:before - **new in v1.4.0**\n * @slot create:after - **new in v1.4.0**\n *\n * @slot delete:before - **new in v1.4.0**\n * @slot delete:after - **new in v1.4.0**\n *\n * @element foxy-customer-form\n * @since 1.2.0\n */\nexport class CustomerForm extends Base<Data> {\n static get scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),\n 'vaadin-text-field': customElements.get('vaadin-text-field'),\n 'x-property-table': PropertyTable,\n 'vaadin-button': customElements.get('vaadin-button'),\n 'foxy-spinner': customElements.get('foxy-spinner'),\n 'foxy-i18n': customElements.get('foxy-i18n'),\n };\n }\n\n static get v8n(): NucleonV8N<Data> {\n return [\n ({ first_name: v }) => !v || v.length <= 50 || 'first_name_too_long',\n ({ last_name: v }) => !v || v.length <= 50 || 'last_name_too_long',\n ({ tax_id: v }) => !v || v.length <= 50 || 'tax_id_too_long',\n ({ email: v }) => (v && v.length > 0) || 'email_required',\n ({ email: v }) => (v && v.length <= 100) || 'email_too_long',\n ({ email: v }) => (v && isEmail(v)) || 'email_invalid_email',\n ];\n }\n\n templates: Templates = {};\n\n private __getValidator = memoize((prefix: string) => () => {\n return !this.errors.some(err => err.startsWith(prefix));\n });\n\n private __maybeRenderTextField = ({ field }: TextFieldParams) => {\n const bsid = field.replace(/_/, '-');\n const error = this.errors.find(err => err.startsWith(field));\n\n if (this.hiddenSelector.matches(bsid, true)) return '';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${bsid}:before`)}\n\n <vaadin-text-field\n class=\"w-full\"\n label=${this.t(field).toString()}\n value=${ifDefined(this.form?.[field]?.toString())}\n error-message=${error ? this.t(error.replace(field, 'v8n')).toString() : ''}\n data-testid=${bsid}\n .checkValidity=${this.__getValidator(field)}\n ?disabled=${!this.in('idle') || this.disabledSelector.matches(bsid, true)}\n ?readonly=${this.readonlySelector.matches(bsid, true)}\n @input=${(evt: Event) => this.edit({ [field]: (evt.target as HTMLInputElement).value })}\n @keydown=${(evt: KeyboardEvent) => evt.key === 'Enter' && this.submit()}\n >\n </vaadin-text-field>\n\n ${this.renderTemplateOrSlot(`${bsid}:after`)}\n </div>\n `;\n };\n\n private __renderTimestamps = () => {\n return html`\n <div>\n ${this.renderTemplateOrSlot('timestamps:before')}\n\n <x-property-table\n data-testid=\"timestamps\"\n .items=${(['date_modified', 'date_created'] as const).map(field => ({\n name: this.t(field),\n value: this.data ? this.t('date', { value: new Date(this.data[field]) }) : '',\n }))}\n >\n </x-property-table>\n\n ${this.renderTemplateOrSlot('timestamps:after')}\n </div>\n `;\n };\n\n private __renderAction = (action: string) => {\n const { disabledSelector, href, lang, ns } = this;\n\n const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });\n const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });\n const isDisabled = !this.in('idle') || disabledSelector.matches(action, true);\n const isValid = isTemplateValid || isSnapshotValid;\n\n const handleClick = (evt: Event) => {\n if (action === 'delete') {\n const confirm = this.renderRoot.querySelector('#confirm');\n (confirm as InternalConfirmDialog).show(evt.currentTarget as HTMLElement);\n } else {\n this.submit();\n }\n };\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${action}:before`)}\n\n <vaadin-button\n class=\"w-full\"\n theme=${this.in('idle') ? `primary ${href ? 'error' : 'success'}` : ''}\n data-testid=${action}\n ?disabled=${(this.in({ idle: 'template' }) && !isValid) || isDisabled}\n @click=${handleClick}\n >\n <foxy-i18n ns=${ns} key=${action} lang=${lang}></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot(`${action}:after`)}\n </div>\n `;\n };\n\n render(): TemplateResult {\n const { hiddenSelector, href, lang, ns } = this;\n const action = href ? 'delete' : 'create';\n const isBusy = this.in('busy');\n const isFail = this.in('fail');\n\n return html`\n <foxy-internal-confirm-dialog\n message=\"delete_prompt\"\n confirm=\"delete\"\n cancel=\"cancel\"\n header=\"delete\"\n theme=\"primary error\"\n lang=${lang}\n ns=${ns}\n id=\"confirm\"\n data-testid=\"confirm\"\n @hide=${(evt: DialogHideEvent) => {\n if (!evt.detail.cancelled) this.delete();\n }}\n >\n </foxy-internal-confirm-dialog>\n\n <div data-testid=\"wrapper\" aria-busy=${isBusy} aria-live=\"polite\" class=\"space-y-l relative\">\n <div class=\"grid grid-cols-1 sm-grid-cols-2 gap-m\">\n ${this.__maybeRenderTextField({ field: 'first_name' })}\n ${this.__maybeRenderTextField({ field: 'last_name' })}\n ${this.__maybeRenderTextField({ field: 'email' })}\n ${this.__maybeRenderTextField({ field: 'tax_id' })}\n </div>\n\n ${hiddenSelector.matches('timestamps', true) || !href ? '' : this.__renderTimestamps()}\n ${hiddenSelector.matches(action) ? '' : this.__renderAction(action)}\n\n <div\n data-testid=\"spinner\"\n class=${classMap({\n 'transition duration-500 ease-in-out absolute inset-0 flex': true,\n 'opacity-0 pointer-events-none': !isBusy && !isFail,\n })}\n >\n <foxy-spinner\n layout=\"vertical\"\n class=\"m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l\"\n state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}\n lang=${lang}\n ns=\"${ns} ${customElements.get('foxy-spinner')?.defaultNS ?? ''}\"\n >\n </foxy-spinner>\n </div>\n </div>\n `;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.__getValidator.cache.clear?.();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CustomerForm.js","sourceRoot":"","sources":["../../../../src/elements/public/CustomerForm/CustomerForm.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,0BAA0B,C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E,KAAK,EAAE,YAAY,EAAE,CAAC;YACpD,IAAI,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;YACnD,IAAI,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;YAC/C,IAAI,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;;;UAGlD,cAAc,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE;UACpF,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;;;;kBAIzD,QAAQ,CAAC;YACf,2DAA2D,EAAE,IAAI;YACjE,+BAA+B,EAAE,CAAC,MAAM,IAAI,CAAC,MAAM;SACpD,CAAC;;;;;oBAKQ,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;mBAC7C,IAAI;kBACL,EAAE,IAAI,YAAA,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,0CAAE,SAAS,mCAAI,EAAE;;;;;KAKtE,CAAC;IACJ,CAAC;IAED,oBAAoB;;QAClB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,MAAA,MAAA,IAAI,CAAC,cAAc,CAAC,KAAK,EAAC,KAAK,mDAAK;IACtC,CAAC;CACF","sourcesContent":["import { Data, Templates, TextFieldParams } from './types';\nimport { ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\nimport { TemplateResult, html } from 'lit-html';\n\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/index';\nimport { NucleonV8N } from '../NucleonElement/types';\nimport { PropertyTable } from '../../private/index';\nimport { ResponsiveMixin } from '../../../mixins/responsive';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { validate as isEmail } from 'email-validator';\nimport memoize from 'lodash-es/memoize';\n\nconst NS = 'customer-form';\nconst Base = ResponsiveMixin(\n ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(TranslatableMixin(NucleonElement, NS))))\n);\n\n/**\n * Form element for creating or editing customers.\n *\n * @slot first-name:before - **new in v1.4.0**\n * @slot first-name:after - **new in v1.4.0**\n *\n * @slot last-name:before - **new in v1.4.0**\n * @slot last-name:after - **new in v1.4.0**\n *\n * @slot email:before - **new in v1.4.0**\n * @slot email:after - **new in v1.4.0**\n *\n * @slot tax-id:before - **new in v1.4.0**\n * @slot tax-id:after - **new in v1.4.0**\n *\n * @slot timestamps:before - **new in v1.4.0**\n * @slot timestamps:after - **new in v1.4.0**\n *\n * @slot create:before - **new in v1.4.0**\n * @slot create:after - **new in v1.4.0**\n *\n * @slot delete:before - **new in v1.4.0**\n * @slot delete:after - **new in v1.4.0**\n *\n * @element foxy-customer-form\n * @since 1.2.0\n */\nexport class CustomerForm extends Base<Data> {\n static get scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),\n 'vaadin-text-field': customElements.get('vaadin-text-field'),\n 'x-property-table': PropertyTable,\n 'vaadin-button': customElements.get('vaadin-button'),\n 'foxy-spinner': customElements.get('foxy-spinner'),\n 'foxy-i18n': customElements.get('foxy-i18n'),\n };\n }\n\n static get v8n(): NucleonV8N<Data> {\n return [\n ({ first_name: v }) => !v || v.length <= 50 || 'first_name_too_long',\n ({ last_name: v }) => !v || v.length <= 50 || 'last_name_too_long',\n ({ tax_id: v }) => !v || v.length <= 50 || 'tax_id_too_long',\n ({ email: v }) => (v && v.length > 0) || 'email_required',\n ({ email: v }) => (v && v.length <= 100) || 'email_too_long',\n ({ email: v }) => (v && isEmail(v)) || 'email_invalid_email',\n ];\n }\n\n templates: Templates = {};\n\n private __getValidator = memoize((prefix: string) => () => {\n return !this.errors.some(err => err.startsWith(prefix));\n });\n\n private __maybeRenderTextField = ({ field }: TextFieldParams) => {\n const bsid = field.replace(/_/, '-');\n const error = this.errors.find(err => err.startsWith(field));\n\n if (this.hiddenSelector.matches(bsid, true)) return '';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${bsid}:before`)}\n\n <vaadin-text-field\n class=\"w-full\"\n label=${this.t(field).toString()}\n value=${ifDefined(this.form?.[field]?.toString())}\n error-message=${error ? this.t(error.replace(field, 'v8n')).toString() : ''}\n data-testid=${bsid}\n .checkValidity=${this.__getValidator(field)}\n ?disabled=${!this.in('idle') || this.disabledSelector.matches(bsid, true)}\n ?readonly=${this.readonlySelector.matches(bsid, true)}\n @input=${(evt: Event) => this.edit({ [field]: (evt.target as HTMLInputElement).value })}\n @keydown=${(evt: KeyboardEvent) => evt.key === 'Enter' && this.submit()}\n >\n </vaadin-text-field>\n\n ${this.renderTemplateOrSlot(`${bsid}:after`)}\n </div>\n `;\n };\n\n private __renderTimestamps = () => {\n return html`\n <div>\n ${this.renderTemplateOrSlot('timestamps:before')}\n\n <x-property-table\n data-testid=\"timestamps\"\n .items=${(['date_modified', 'date_created'] as const).map(field => ({\n name: this.t(field),\n value: this.data?.[field]\n ? this.t('date', { value: new Date(this.data[field] as string) })\n : '',\n }))}\n >\n </x-property-table>\n\n ${this.renderTemplateOrSlot('timestamps:after')}\n </div>\n `;\n };\n\n private __renderAction = (action: string) => {\n const { disabledSelector, href, lang, ns } = this;\n\n const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });\n const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });\n const isDisabled = !this.in('idle') || disabledSelector.matches(action, true);\n const isValid = isTemplateValid || isSnapshotValid;\n\n const handleClick = (evt: Event) => {\n if (action === 'delete') {\n const confirm = this.renderRoot.querySelector('#confirm');\n (confirm as InternalConfirmDialog).show(evt.currentTarget as HTMLElement);\n } else {\n this.submit();\n }\n };\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${action}:before`)}\n\n <vaadin-button\n class=\"w-full\"\n theme=${this.in('idle') ? `primary ${href ? 'error' : 'success'}` : ''}\n data-testid=${action}\n ?disabled=${(this.in({ idle: 'template' }) && !isValid) || isDisabled}\n @click=${handleClick}\n >\n <foxy-i18n ns=${ns} key=${action} lang=${lang}></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot(`${action}:after`)}\n </div>\n `;\n };\n\n render(): TemplateResult {\n const { hiddenSelector, href, lang, ns } = this;\n const action = href ? 'delete' : 'create';\n const isBusy = this.in('busy');\n const isFail = this.in('fail');\n\n return html`\n <foxy-internal-confirm-dialog\n message=\"delete_prompt\"\n confirm=\"delete\"\n cancel=\"cancel\"\n header=\"delete\"\n theme=\"primary error\"\n lang=${lang}\n ns=${ns}\n id=\"confirm\"\n data-testid=\"confirm\"\n @hide=${(evt: DialogHideEvent) => {\n if (!evt.detail.cancelled) this.delete();\n }}\n >\n </foxy-internal-confirm-dialog>\n\n <div data-testid=\"wrapper\" aria-busy=${isBusy} aria-live=\"polite\" class=\"space-y-l relative\">\n <div class=\"grid grid-cols-1 sm-grid-cols-2 gap-m\">\n ${this.__maybeRenderTextField({ field: 'first_name' })}\n ${this.__maybeRenderTextField({ field: 'last_name' })}\n ${this.__maybeRenderTextField({ field: 'email' })}\n ${this.__maybeRenderTextField({ field: 'tax_id' })}\n </div>\n\n ${hiddenSelector.matches('timestamps', true) || !href ? '' : this.__renderTimestamps()}\n ${hiddenSelector.matches(action) ? '' : this.__renderAction(action)}\n\n <div\n data-testid=\"spinner\"\n class=${classMap({\n 'transition duration-500 ease-in-out absolute inset-0 flex': true,\n 'opacity-0 pointer-events-none': !isBusy && !isFail,\n })}\n >\n <foxy-spinner\n layout=\"vertical\"\n class=\"m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l\"\n state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}\n lang=${lang}\n ns=\"${ns} ${customElements.get('foxy-spinner')?.defaultNS ?? ''}\"\n >\n </foxy-spinner>\n </div>\n </div>\n `;\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.__getValidator.cache.clear?.();\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyDeclarations, TemplateResult } from 'lit-element';
|
|
2
|
+
import { ScopedElementsMap } from '@open-wc/scoped-elements';
|
|
3
|
+
import { Data } from './types';
|
|
4
|
+
import { NucleonElement } from '../NucleonElement/NucleonElement';
|
|
5
|
+
declare const Base: typeof NucleonElement & import("lit-element").Constructor<import("../../../mixins/translatable").TranslatableMixinHost> & {
|
|
6
|
+
defaultNS: string;
|
|
7
|
+
} & import("lit-element").Constructor<import("../../../mixins/configurable").ConfigurableMixinHost> & {
|
|
8
|
+
styles: CSSResultArray;
|
|
9
|
+
} & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/src/types").ScopedElementsHost>;
|
|
10
|
+
export declare class EmailTemplateForm extends Base<Data> {
|
|
11
|
+
static get properties(): PropertyDeclarations;
|
|
12
|
+
static get styles(): CSSResultArray;
|
|
13
|
+
static get scopedElements(): ScopedElementsMap;
|
|
14
|
+
private __cacheState;
|
|
15
|
+
private __contentChoice;
|
|
16
|
+
render(): TemplateResult;
|
|
17
|
+
private __renderDescription;
|
|
18
|
+
private __renderContent;
|
|
19
|
+
private __renderTabContent;
|
|
20
|
+
private __renderTimestamps;
|
|
21
|
+
private __renderAction;
|
|
22
|
+
private __cache;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { css, html } from 'lit-element';
|
|
2
|
+
import { Choice, Group, PropertyTable } from "../../private/index.js";
|
|
3
|
+
import { ScopedElementsMixin } from '@open-wc/scoped-elements';
|
|
4
|
+
import { ChoiceChangeEvent } from "../../private/events.js";
|
|
5
|
+
import { ConfigurableMixin } from "../../../mixins/configurable.js";
|
|
6
|
+
import { NucleonElement } from "../NucleonElement/NucleonElement.js";
|
|
7
|
+
import { ThemeableMixin } from "../../../mixins/themeable.js";
|
|
8
|
+
import { TranslatableMixin } from "../../../mixins/translatable.js";
|
|
9
|
+
import { classMap } from "../../../utils/class-map.js";
|
|
10
|
+
import { ifDefined } from 'lit-html/directives/if-defined';
|
|
11
|
+
const NS = 'email-template-form';
|
|
12
|
+
const Base = ScopedElementsMixin(ThemeableMixin(ConfigurableMixin(TranslatableMixin(NucleonElement, NS))));
|
|
13
|
+
export class EmailTemplateForm extends Base {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.__cacheState = 'idle';
|
|
17
|
+
this.__contentChoice = 'default';
|
|
18
|
+
}
|
|
19
|
+
static get properties() {
|
|
20
|
+
return {
|
|
21
|
+
...super.properties,
|
|
22
|
+
__cacheState: { attribute: false },
|
|
23
|
+
__contentChoice: { attribute: false },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static get styles() {
|
|
27
|
+
return [
|
|
28
|
+
...super.styles,
|
|
29
|
+
css `#cached-content::part(input-field){
|
|
30
|
+
max-height:15em;
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
static get scopedElements() {
|
|
36
|
+
return {
|
|
37
|
+
'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),
|
|
38
|
+
'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),
|
|
39
|
+
'foxy-spinner': customElements.get('foxy-spinner'),
|
|
40
|
+
'foxy-i18n': customElements.get('foxy-i18n'),
|
|
41
|
+
'vaadin-text-field': customElements.get('vaadin-text-field'),
|
|
42
|
+
'vaadin-text-area': customElements.get('vaadin-text-area'),
|
|
43
|
+
'vaadin-button': customElements.get('vaadin-button'),
|
|
44
|
+
'x-property-table': PropertyTable,
|
|
45
|
+
'x-choice': Choice,
|
|
46
|
+
'x-group': Group,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
render() {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const { hiddenSelector, href, lang, ns } = this;
|
|
52
|
+
const action = href ? 'delete' : 'create';
|
|
53
|
+
const isBusy = this.in('busy');
|
|
54
|
+
const isFail = this.in('fail');
|
|
55
|
+
return html `
|
|
56
|
+
<div class="space-y-m">
|
|
57
|
+
${hiddenSelector.matches('description', true) ? '' : this.__renderDescription()}
|
|
58
|
+
${hiddenSelector.matches('content', true) ? '' : this.__renderContent()}
|
|
59
|
+
${hiddenSelector.matches('timestamps', true) || !href ? '' : this.__renderTimestamps()}
|
|
60
|
+
${hiddenSelector.matches(action) ? '' : this.__renderAction(action)}
|
|
61
|
+
|
|
62
|
+
<div
|
|
63
|
+
data-testid="spinner"
|
|
64
|
+
class=${classMap({
|
|
65
|
+
'transition duration-500 ease-in-out absolute inset-0 flex': true,
|
|
66
|
+
'opacity-0 pointer-events-none': !isBusy && !isFail,
|
|
67
|
+
})}
|
|
68
|
+
>
|
|
69
|
+
<foxy-spinner
|
|
70
|
+
layout="vertical"
|
|
71
|
+
class="m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l"
|
|
72
|
+
state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}
|
|
73
|
+
lang=${lang}
|
|
74
|
+
ns="${ns} ${(_b = (_a = customElements.get('foxy-spinner')) === null || _a === void 0 ? void 0 : _a.defaultNS) !== null && _b !== void 0 ? _b : ''}"
|
|
75
|
+
>
|
|
76
|
+
</foxy-spinner>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
__renderDescription() {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
return html `
|
|
84
|
+
<div>
|
|
85
|
+
${this.renderTemplateOrSlot('description:before')}
|
|
86
|
+
|
|
87
|
+
<vaadin-text-field
|
|
88
|
+
class="w-full mb-s"
|
|
89
|
+
label=${this.t('description')}
|
|
90
|
+
.value=${(_b = (_a = this.form) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : ''}
|
|
91
|
+
@keydown=${(evt) => evt.key === 'Enter' && this.submit()}
|
|
92
|
+
@input=${(evt) => {
|
|
93
|
+
this.edit({ description: evt.currentTarget.value });
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
</vaadin-text-field>
|
|
97
|
+
|
|
98
|
+
${this.renderTemplateOrSlot('description:after')}
|
|
99
|
+
</div>
|
|
100
|
+
`;
|
|
101
|
+
}
|
|
102
|
+
__renderContent() {
|
|
103
|
+
return html `
|
|
104
|
+
<div>
|
|
105
|
+
${this.renderTemplateOrSlot('content:before')}
|
|
106
|
+
|
|
107
|
+
<div class="space-y-l">
|
|
108
|
+
${this.__renderTabContent('content_text_url', 'content_text', 'text_template')}
|
|
109
|
+
${this.__renderTabContent('content_html_url', 'content_html', 'html_template')}
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
${this.renderTemplateOrSlot('content:after')}
|
|
113
|
+
</div>
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
__renderTabContent(urlPath, textPath, header) {
|
|
117
|
+
var _a;
|
|
118
|
+
const contentChoice = this.form[urlPath]
|
|
119
|
+
? 'url'
|
|
120
|
+
: this.form[textPath]
|
|
121
|
+
? 'clipboard'
|
|
122
|
+
: this.__contentChoice;
|
|
123
|
+
return html `
|
|
124
|
+
<x-group frame>
|
|
125
|
+
<foxy-i18n lang=${this.lang} slot="header" key=${header} ns=${this.ns}></foxy-i18n>
|
|
126
|
+
|
|
127
|
+
<x-choice
|
|
128
|
+
data-testid="template-type"
|
|
129
|
+
.value=${contentChoice}
|
|
130
|
+
.items=${['default', 'url', 'clipboard']}
|
|
131
|
+
?readonly=${this.readonlySelector.matches('content', true)}
|
|
132
|
+
?disabled=${this.in('busy') || this.disabledSelector.matches('content', true)}
|
|
133
|
+
@change=${(evt) => {
|
|
134
|
+
if (evt instanceof ChoiceChangeEvent) {
|
|
135
|
+
this.edit({ [textPath]: '', [urlPath]: '' });
|
|
136
|
+
this.__contentChoice = evt.detail;
|
|
137
|
+
}
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
${['default', 'url', 'clipboard'].map(value => {
|
|
141
|
+
return html `
|
|
142
|
+
<div slot="${value}-label" class="py-s">
|
|
143
|
+
<foxy-i18n class="block" lang=${this.lang} key="template_${value}" ns=${this.ns}>
|
|
144
|
+
</foxy-i18n>
|
|
145
|
+
|
|
146
|
+
<foxy-i18n
|
|
147
|
+
class="block text-s opacity-70"
|
|
148
|
+
lang=${this.lang}
|
|
149
|
+
key="template_${value}_explainer"
|
|
150
|
+
ns=${this.ns}
|
|
151
|
+
>
|
|
152
|
+
</foxy-i18n>
|
|
153
|
+
</div>
|
|
154
|
+
`;
|
|
155
|
+
})}
|
|
156
|
+
|
|
157
|
+
<div slot="url" ?hidden=${contentChoice !== 'url'}>
|
|
158
|
+
<div class="flex items-center mt-0 mb-m">
|
|
159
|
+
<vaadin-text-field
|
|
160
|
+
data-testid="content_url"
|
|
161
|
+
value=${ifDefined(this.form[urlPath])}
|
|
162
|
+
class="mr-s flex-grow"
|
|
163
|
+
@input=${(evt) => {
|
|
164
|
+
const value = evt.currentTarget.value;
|
|
165
|
+
this.edit({ [textPath]: '', [urlPath]: value });
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
</vaadin-text-field>
|
|
169
|
+
|
|
170
|
+
${this.form[urlPath] === ((_a = this.data) === null || _a === void 0 ? void 0 : _a[urlPath])
|
|
171
|
+
? html `
|
|
172
|
+
<vaadin-button
|
|
173
|
+
class="relative"
|
|
174
|
+
?disabled=${this.__cacheState === 'busy'}
|
|
175
|
+
@click=${this.__cache}
|
|
176
|
+
>
|
|
177
|
+
<foxy-i18n
|
|
178
|
+
class=${classMap({
|
|
179
|
+
'relative transition-opacity': true,
|
|
180
|
+
'opacity-0': this.__cacheState !== 'idle',
|
|
181
|
+
})}
|
|
182
|
+
lang=${this.lang}
|
|
183
|
+
key="cache"
|
|
184
|
+
ns=${this.ns}
|
|
185
|
+
>
|
|
186
|
+
</foxy-i18n>
|
|
187
|
+
|
|
188
|
+
<div
|
|
189
|
+
class=${classMap({
|
|
190
|
+
'absolute inset-0 flex transition-opacity': true,
|
|
191
|
+
'opacity-0': this.__cacheState === 'idle',
|
|
192
|
+
})}
|
|
193
|
+
>
|
|
194
|
+
<foxy-spinner
|
|
195
|
+
layout="no-label"
|
|
196
|
+
class="m-auto"
|
|
197
|
+
state=${this.__cacheState === 'fail' ? 'error' : 'busy'}
|
|
198
|
+
lang=${this.lang}
|
|
199
|
+
ns=${this.ns}
|
|
200
|
+
>
|
|
201
|
+
</foxy-spinner>
|
|
202
|
+
</div>
|
|
203
|
+
</vaadin-button>
|
|
204
|
+
`
|
|
205
|
+
: ''}
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<div slot="clipboard" ?hidden=${contentChoice !== 'clipboard'}>
|
|
210
|
+
<vaadin-text-area
|
|
211
|
+
id="cached-content"
|
|
212
|
+
data-testid="content"
|
|
213
|
+
class="w-full mb-m"
|
|
214
|
+
.value=${this.form[textPath]}
|
|
215
|
+
@input=${(evt) => {
|
|
216
|
+
const value = evt.currentTarget.value;
|
|
217
|
+
this.edit({ [textPath]: value, [urlPath]: '' });
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
</vaadin-text-area>
|
|
221
|
+
</div>
|
|
222
|
+
</x-choice>
|
|
223
|
+
</x-group>
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
__renderTimestamps() {
|
|
227
|
+
return html `
|
|
228
|
+
<div>
|
|
229
|
+
${this.renderTemplateOrSlot('timestamps:before')}
|
|
230
|
+
|
|
231
|
+
<x-property-table
|
|
232
|
+
data-testid="timestamps"
|
|
233
|
+
.items=${['date_modified', 'date_created'].map(field => {
|
|
234
|
+
var _a;
|
|
235
|
+
return ({
|
|
236
|
+
name: this.t(field),
|
|
237
|
+
value: ((_a = this.data) === null || _a === void 0 ? void 0 : _a[field]) ? this.t('date', { value: new Date(this.data[field]) })
|
|
238
|
+
: '',
|
|
239
|
+
});
|
|
240
|
+
})}
|
|
241
|
+
>
|
|
242
|
+
</x-property-table>
|
|
243
|
+
|
|
244
|
+
${this.renderTemplateOrSlot('timestamps:after')}
|
|
245
|
+
</div>
|
|
246
|
+
`;
|
|
247
|
+
}
|
|
248
|
+
__renderAction(action) {
|
|
249
|
+
const { disabledSelector, href, lang, ns } = this;
|
|
250
|
+
const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });
|
|
251
|
+
const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });
|
|
252
|
+
const isDisabled = !this.in('idle') || disabledSelector.matches(action, true);
|
|
253
|
+
const isValid = isTemplateValid || isSnapshotValid;
|
|
254
|
+
const handleClick = (evt) => {
|
|
255
|
+
if (action === 'delete') {
|
|
256
|
+
const confirm = this.renderRoot.querySelector('#confirm');
|
|
257
|
+
confirm.show(evt.currentTarget);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this.submit();
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return html `
|
|
264
|
+
<div>
|
|
265
|
+
${this.renderTemplateOrSlot(`${action}:before`)}
|
|
266
|
+
|
|
267
|
+
<foxy-internal-confirm-dialog
|
|
268
|
+
message="delete_prompt"
|
|
269
|
+
confirm="delete"
|
|
270
|
+
cancel="cancel"
|
|
271
|
+
header="delete"
|
|
272
|
+
theme="primary error"
|
|
273
|
+
lang=${lang}
|
|
274
|
+
ns=${ns}
|
|
275
|
+
id="confirm"
|
|
276
|
+
data-testid="confirm"
|
|
277
|
+
@hide=${(evt) => {
|
|
278
|
+
if (!evt.detail.cancelled)
|
|
279
|
+
this.delete();
|
|
280
|
+
}}
|
|
281
|
+
>
|
|
282
|
+
</foxy-internal-confirm-dialog>
|
|
283
|
+
|
|
284
|
+
<vaadin-button
|
|
285
|
+
class="w-full"
|
|
286
|
+
theme=${this.in('idle') ? `primary ${href ? 'error' : 'success'}` : ''}
|
|
287
|
+
data-testid=${action}
|
|
288
|
+
?disabled=${(this.in({ idle: 'template' }) && !isValid) || isDisabled}
|
|
289
|
+
@click=${handleClick}
|
|
290
|
+
>
|
|
291
|
+
<foxy-i18n ns=${ns} key=${action} lang=${lang}></foxy-i18n>
|
|
292
|
+
</vaadin-button>
|
|
293
|
+
|
|
294
|
+
${this.renderTemplateOrSlot(`${action}:after`)}
|
|
295
|
+
</div>
|
|
296
|
+
`;
|
|
297
|
+
}
|
|
298
|
+
async __cache() {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
this.__cacheState = 'busy';
|
|
301
|
+
try {
|
|
302
|
+
const url = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a._links['fx:cache'].href) !== null && _b !== void 0 ? _b : '';
|
|
303
|
+
const response = await new EmailTemplateForm.API(this).fetch(url, { method: 'POST' });
|
|
304
|
+
this.__cacheState = response.ok ? 'idle' : 'fail';
|
|
305
|
+
}
|
|
306
|
+
catch (_c) {
|
|
307
|
+
this.__cacheState = 'fail';
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=EmailTemplateForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailTemplateForm.js","sourceRoot":"","sources":["../../../../src/elements/public/EmailTemplateForm/EmailTemplateForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwD,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,a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import { CSSResultArray, PropertyDeclarations, TemplateResult, css, html } from 'lit-element';\nimport { Choice, Group, PropertyTable } from '../../private/index';\nimport { ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\n\nimport { ChoiceChangeEvent } from '../../private/events';\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { Data } from './types';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/NucleonElement';\nimport { TextAreaElement } from '@vaadin/vaadin-text-field/vaadin-text-area';\nimport { TextFieldElement } from '@vaadin/vaadin-text-field';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\nimport { ifDefined } from 'lit-html/directives/if-defined';\n\nconst NS = 'email-template-form';\nconst Base = ScopedElementsMixin(\n ThemeableMixin(ConfigurableMixin(TranslatableMixin(NucleonElement, NS)))\n);\n\nexport class EmailTemplateForm extends Base<Data> {\n static get properties(): PropertyDeclarations {\n return {\n ...super.properties,\n __cacheState: { attribute: false },\n __contentChoice: { attribute: false },\n };\n }\n\n static get styles(): CSSResultArray {\n return [\n ...super.styles,\n css`\n #cached-content::part(input-field) {\n max-height: 15em;\n }\n `,\n ];\n }\n\n static get scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),\n 'foxy-spinner': customElements.get('foxy-spinner'),\n 'foxy-i18n': customElements.get('foxy-i18n'),\n 'vaadin-text-field': customElements.get('vaadin-text-field'),\n 'vaadin-text-area': customElements.get('vaadin-text-area'),\n 'vaadin-button': customElements.get('vaadin-button'),\n 'x-property-table': PropertyTable,\n 'x-choice': Choice,\n 'x-group': Group,\n };\n }\n\n private __cacheState: 'idle' | 'busy' | 'fail' = 'idle';\n\n private __contentChoice: 'default' | 'url' | 'clipboard' = 'default';\n\n render(): TemplateResult {\n const { hiddenSelector, href, lang, ns } = this;\n const action = href ? 'delete' : 'create';\n const isBusy = this.in('busy');\n const isFail = this.in('fail');\n\n return html`\n <div class=\"space-y-m\">\n ${hiddenSelector.matches('description', true) ? '' : this.__renderDescription()}\n ${hiddenSelector.matches('content', true) ? '' : this.__renderContent()}\n ${hiddenSelector.matches('timestamps', true) || !href ? '' : this.__renderTimestamps()}\n ${hiddenSelector.matches(action) ? '' : this.__renderAction(action)}\n\n <div\n data-testid=\"spinner\"\n class=${classMap({\n 'transition duration-500 ease-in-out absolute inset-0 flex': true,\n 'opacity-0 pointer-events-none': !isBusy && !isFail,\n })}\n >\n <foxy-spinner\n layout=\"vertical\"\n class=\"m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l\"\n state=${isFail ? 'error' : isBusy ? 'busy' : 'empty'}\n lang=${lang}\n ns=\"${ns} ${customElements.get('foxy-spinner')?.defaultNS ?? ''}\"\n >\n </foxy-spinner>\n </div>\n </div>\n `;\n }\n\n private __renderDescription() {\n return html`\n <div>\n ${this.renderTemplateOrSlot('description:before')}\n\n <vaadin-text-field\n class=\"w-full mb-s\"\n label=${this.t('description')}\n .value=${this.form?.description ?? ''}\n @keydown=${(evt: KeyboardEvent) => evt.key === 'Enter' && this.submit()}\n @input=${(evt: CustomEvent) => {\n this.edit({ description: (evt.currentTarget as TextFieldElement).value });\n }}\n >\n </vaadin-text-field>\n\n ${this.renderTemplateOrSlot('description:after')}\n </div>\n `;\n }\n\n private __renderContent() {\n return html`\n <div>\n ${this.renderTemplateOrSlot('content:before')}\n\n <div class=\"space-y-l\">\n ${this.__renderTabContent('content_text_url', 'content_text', 'text_template')}\n ${this.__renderTabContent('content_html_url', 'content_html', 'html_template')}\n </div>\n\n ${this.renderTemplateOrSlot('content:after')}\n </div>\n `;\n }\n\n private __renderTabContent(\n urlPath: 'content_text_url' | 'content_html_url',\n textPath: 'content_text' | 'content_html',\n header: string\n ) {\n const contentChoice = this.form[urlPath]\n ? 'url'\n : this.form[textPath]\n ? 'clipboard'\n : this.__contentChoice;\n\n return html`\n <x-group frame>\n <foxy-i18n lang=${this.lang} slot=\"header\" key=${header} ns=${this.ns}></foxy-i18n>\n\n <x-choice\n data-testid=\"template-type\"\n .value=${contentChoice}\n .items=${['default', 'url', 'clipboard']}\n ?readonly=${this.readonlySelector.matches('content', true)}\n ?disabled=${this.in('busy') || this.disabledSelector.matches('content', true)}\n @change=${(evt: Event) => {\n if (evt instanceof ChoiceChangeEvent) {\n this.edit({ [textPath]: '', [urlPath]: '' });\n this.__contentChoice = evt.detail as 'url' | 'clipboard' | 'default';\n }\n }}\n >\n ${['default', 'url', 'clipboard'].map(value => {\n return html`\n <div slot=\"${value}-label\" class=\"py-s\">\n <foxy-i18n class=\"block\" lang=${this.lang} key=\"template_${value}\" ns=${this.ns}>\n </foxy-i18n>\n\n <foxy-i18n\n class=\"block text-s opacity-70\"\n lang=${this.lang}\n key=\"template_${value}_explainer\"\n ns=${this.ns}\n >\n </foxy-i18n>\n </div>\n `;\n })}\n\n <div slot=\"url\" ?hidden=${contentChoice !== 'url'}>\n <div class=\"flex items-center mt-0 mb-m\">\n <vaadin-text-field\n data-testid=\"content_url\"\n value=${ifDefined(this.form[urlPath])}\n class=\"mr-s flex-grow\"\n @input=${(evt: CustomEvent) => {\n const value = (evt.currentTarget as TextFieldElement).value;\n this.edit({ [textPath]: '', [urlPath]: value });\n }}\n >\n </vaadin-text-field>\n\n ${this.form[urlPath] === this.data?.[urlPath]\n ? html`\n <vaadin-button\n class=\"relative\"\n ?disabled=${this.__cacheState === 'busy'}\n @click=${this.__cache}\n >\n <foxy-i18n\n class=${classMap({\n 'relative transition-opacity': true,\n 'opacity-0': this.__cacheState !== 'idle',\n })}\n lang=${this.lang}\n key=\"cache\"\n ns=${this.ns}\n >\n </foxy-i18n>\n\n <div\n class=${classMap({\n 'absolute inset-0 flex transition-opacity': true,\n 'opacity-0': this.__cacheState === 'idle',\n })}\n >\n <foxy-spinner\n layout=\"no-label\"\n class=\"m-auto\"\n state=${this.__cacheState === 'fail' ? 'error' : 'busy'}\n lang=${this.lang}\n ns=${this.ns}\n >\n </foxy-spinner>\n </div>\n </vaadin-button>\n `\n : ''}\n </div>\n </div>\n\n <div slot=\"clipboard\" ?hidden=${contentChoice !== 'clipboard'}>\n <vaadin-text-area\n id=\"cached-content\"\n data-testid=\"content\"\n class=\"w-full mb-m\"\n .value=${this.form[textPath]}\n @input=${(evt: CustomEvent) => {\n const value = (evt.currentTarget as TextAreaElement).value;\n this.edit({ [textPath]: value, [urlPath]: '' });\n }}\n >\n </vaadin-text-area>\n </div>\n </x-choice>\n </x-group>\n `;\n }\n\n private __renderTimestamps() {\n return html`\n <div>\n ${this.renderTemplateOrSlot('timestamps:before')}\n\n <x-property-table\n data-testid=\"timestamps\"\n .items=${(['date_modified', 'date_created'] as const).map(field => ({\n name: this.t(field),\n value: this.data?.[field]\n ? this.t('date', { value: new Date(this.data[field] as string) })\n : '',\n }))}\n >\n </x-property-table>\n\n ${this.renderTemplateOrSlot('timestamps:after')}\n </div>\n `;\n }\n\n private __renderAction(action: string) {\n const { disabledSelector, href, lang, ns } = this;\n\n const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });\n const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });\n const isDisabled = !this.in('idle') || disabledSelector.matches(action, true);\n const isValid = isTemplateValid || isSnapshotValid;\n\n const handleClick = (evt: Event) => {\n if (action === 'delete') {\n const confirm = this.renderRoot.querySelector('#confirm');\n (confirm as InternalConfirmDialog).show(evt.currentTarget as HTMLElement);\n } else {\n this.submit();\n }\n };\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${action}:before`)}\n\n <foxy-internal-confirm-dialog\n message=\"delete_prompt\"\n confirm=\"delete\"\n cancel=\"cancel\"\n header=\"delete\"\n theme=\"primary error\"\n lang=${lang}\n ns=${ns}\n id=\"confirm\"\n data-testid=\"confirm\"\n @hide=${(evt: DialogHideEvent) => {\n if (!evt.detail.cancelled) this.delete();\n }}\n >\n </foxy-internal-confirm-dialog>\n\n <vaadin-button\n class=\"w-full\"\n theme=${this.in('idle') ? `primary ${href ? 'error' : 'success'}` : ''}\n data-testid=${action}\n ?disabled=${(this.in({ idle: 'template' }) && !isValid) || isDisabled}\n @click=${handleClick}\n >\n <foxy-i18n ns=${ns} key=${action} lang=${lang}></foxy-i18n>\n </vaadin-button>\n\n ${this.renderTemplateOrSlot(`${action}:after`)}\n </div>\n `;\n }\n\n private async __cache(): Promise<void> {\n this.__cacheState = 'busy';\n\n try {\n const url = this.data?._links['fx:cache'].href ?? '';\n const response = await new EmailTemplateForm.API(this).fetch(url, { method: 'POST' });\n\n this.__cacheState = response.ok ? 'idle' : 'fail';\n } catch {\n this.__cacheState = 'fail';\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import '@vaadin/vaadin-text-field/vaadin-text-field';
|
|
2
|
+
import '@vaadin/vaadin-text-field/vaadin-text-area';
|
|
3
|
+
import '@vaadin/vaadin-button';
|
|
4
|
+
import '../../internal/InternalConfirmDialog/index';
|
|
5
|
+
import '../../internal/InternalSandbox/index';
|
|
6
|
+
import '../Spinner/index';
|
|
7
|
+
import '../I18n/index';
|
|
8
|
+
import { EmailTemplateForm } from './EmailTemplateForm';
|
|
9
|
+
export { EmailTemplateForm };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '@vaadin/vaadin-text-field/vaadin-text-field';
|
|
2
|
+
import '@vaadin/vaadin-text-field/vaadin-text-area';
|
|
3
|
+
import '@vaadin/vaadin-button';
|
|
4
|
+
import "../../internal/InternalConfirmDialog/index.js";
|
|
5
|
+
import "../../internal/InternalSandbox/index.js";
|
|
6
|
+
import "../Spinner/index.js";
|
|
7
|
+
import "../I18n/index.js";
|
|
8
|
+
import { EmailTemplateForm } from "./EmailTemplateForm.js";
|
|
9
|
+
customElements.define('foxy-email-template-form', EmailTemplateForm);
|
|
10
|
+
export { EmailTemplateForm };
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/elements/public/EmailTemplateForm/index.ts"],"names":[],"mappings":"AAAA,OAAO,6CAA6C,CAAC;AACrD,OAAO,4CAA4C,CAAC;AACpD,OAAO,uBAAuB,CAAC;AAC/B,uDAAoD;AACpD,iDAA8C;AAC9C,6BAA0B;AAC1B,0BAAuB;AAEvB,OAAO,EAAE,iBAAiB,EAAE,+BAA4B;AAExD,cAAc,CAAC,MAAM,CAAC,0BAA0B,EAAE,iBAAiB,CAAC,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import '@vaadin/vaadin-text-field/vaadin-text-field';\nimport '@vaadin/vaadin-text-field/vaadin-text-area';\nimport '@vaadin/vaadin-button';\nimport '../../internal/InternalConfirmDialog/index';\nimport '../../internal/InternalSandbox/index';\nimport '../Spinner/index';\nimport '../I18n/index';\n\nimport { EmailTemplateForm } from './EmailTemplateForm';\n\ncustomElements.define('foxy-email-template-form', EmailTemplateForm);\n\nexport { EmailTemplateForm };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/elements/public/EmailTemplateForm/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Rels } from '@foxy.io/sdk/backend';\nimport { Resource } from '@foxy.io/sdk/core';\n\nexport type Data = Resource<Rels.EmailTemplate>;\n"]}
|