@foxy.io/elements 1.32.0 → 1.33.0-beta.2
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-address-form.js +1 -1
- package/dist/cdn/foxy-admin-subscription-form.js +1 -1
- package/dist/cdn/foxy-api-browser.js +1 -1
- package/dist/cdn/foxy-applied-coupon-code-form.js +1 -1
- package/dist/cdn/foxy-attribute-form.js +1 -1
- package/dist/cdn/foxy-cart-form.js +2 -2
- package/dist/cdn/foxy-client-form.js +1 -1
- package/dist/cdn/foxy-coupon-code-form.js +1 -1
- package/dist/cdn/foxy-coupon-codes-form.js +1 -1
- package/dist/cdn/foxy-coupon-form.js +1 -1
- package/dist/cdn/foxy-custom-field-form.js +1 -1
- package/dist/cdn/foxy-customer-form.js +1 -1
- package/dist/cdn/foxy-customer-portal-settings-form.js +1 -1
- package/dist/cdn/foxy-customer-portal.js +1 -1
- package/dist/cdn/foxy-customer.js +1 -1
- package/dist/cdn/foxy-downloadable-form.js +1 -1
- package/dist/cdn/foxy-email-template-form.js +1 -1
- package/dist/cdn/foxy-filter-attribute-form.js +1 -1
- package/dist/cdn/foxy-generate-codes-form.js +1 -1
- package/dist/cdn/foxy-gift-card-code-form.js +1 -1
- package/dist/cdn/foxy-gift-card-codes-form.js +1 -1
- package/dist/cdn/foxy-gift-card-form.js +1 -1
- package/dist/cdn/foxy-integration-form.js +1 -1
- package/dist/cdn/foxy-item-category-form.js +1 -1
- package/dist/cdn/foxy-item-form.js +1 -1
- package/dist/cdn/foxy-item-option-form.js +1 -1
- package/dist/cdn/foxy-native-integration-form.js +1 -1
- package/dist/cdn/foxy-passkey-form.js +1 -1
- package/dist/cdn/foxy-payment-method-card.js +1 -1
- package/dist/cdn/foxy-payments-api-fraud-protection-form.js +1 -1
- package/dist/cdn/foxy-payments-api-payment-method-form.js +1 -1
- package/dist/cdn/foxy-payments-api-payment-preset-form.js +1 -1
- package/dist/cdn/foxy-store-form.js +1 -1
- package/dist/cdn/foxy-store-shipping-method-form.js +1 -1
- package/dist/cdn/foxy-subscription-form.js +1 -1
- package/dist/cdn/foxy-subscription-settings-form.js +1 -1
- package/dist/cdn/foxy-template-config-form.js +1 -1
- package/dist/cdn/foxy-template-form.js +1 -1
- package/dist/cdn/foxy-template-set-form.js +1 -1
- package/dist/cdn/foxy-transaction.js +1 -1
- package/dist/cdn/foxy-update-payment-method-form.js +1 -1
- package/dist/cdn/foxy-user-form.js +1 -1
- package/dist/cdn/foxy-user-invitation-form.js +1 -1
- package/dist/cdn/foxy-users-table.js +1 -1
- package/dist/cdn/foxy-webhook-form.js +1 -1
- package/dist/cdn/shared-0203d3da.js +1 -0
- package/dist/cdn/shared-14179b23.js +1 -0
- package/dist/cdn/shared-529f2b48.js +2 -0
- package/dist/cdn/shared-d367ea04.js +1 -0
- package/dist/cdn/translations/email-template-form/en.json +99 -27
- package/dist/cdn/translations/item-category-form/en.json +1 -1
- package/dist/cdn/translations/store-form/en.json +1 -1
- package/dist/cdn/translations/subscription-settings-form/en.json +6 -6
- package/dist/cdn/translations/template-form/en.json +67 -19
- package/dist/elements/internal/InternalResourcePickerControl/InternalResourcePickerControlForm.d.ts +1 -2
- package/dist/elements/internal/InternalResourcePickerControl/InternalResourcePickerControlForm.js +0 -3
- package/dist/elements/internal/InternalResourcePickerControl/InternalResourcePickerControlForm.js.map +1 -1
- package/dist/elements/internal/InternalSourceControl/InternalSourceControl.js +6 -26
- package/dist/elements/internal/InternalSourceControl/InternalSourceControl.js.map +1 -1
- package/dist/elements/internal/InternalSummaryControl/InternalSummaryControl.js +1 -1
- package/dist/elements/internal/InternalSummaryControl/InternalSummaryControl.js.map +1 -1
- package/dist/elements/internal/InternalTimestampsControl/InternalTimestampsControl.js +1 -1
- package/dist/elements/internal/InternalTimestampsControl/InternalTimestampsControl.js.map +1 -1
- package/dist/elements/public/CartForm/internal/InternalCartFormCreateSessionAction/InternalCartFormCreateSessionAction.js +0 -1
- package/dist/elements/public/CartForm/internal/InternalCartFormCreateSessionAction/InternalCartFormCreateSessionAction.js.map +1 -1
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.d.ts +12 -20
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.js +100 -333
- package/dist/elements/public/EmailTemplateForm/EmailTemplateForm.js.map +1 -1
- package/dist/elements/public/EmailTemplateForm/index.d.ts +5 -7
- package/dist/elements/public/EmailTemplateForm/index.js +5 -7
- package/dist/elements/public/EmailTemplateForm/index.js.map +1 -1
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/InternalEmailTemplateFormAsyncAction.d.ts +10 -0
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/InternalEmailTemplateFormAsyncAction.js +49 -0
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/InternalEmailTemplateFormAsyncAction.js.map +1 -0
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/index.d.ts +5 -0
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/index.js +7 -0
- package/dist/elements/public/EmailTemplateForm/internal/InternalEmailTemplateFormAsyncAction/index.js.map +1 -0
- package/dist/elements/public/EmailTemplateForm/types.d.ts +3 -1
- package/dist/elements/public/EmailTemplateForm/types.js.map +1 -1
- package/dist/elements/public/StoreShippingMethodForm/StoreShippingMethodForm.js +3 -3
- package/dist/elements/public/StoreShippingMethodForm/StoreShippingMethodForm.js.map +1 -1
- package/dist/elements/public/SubscriptionSettingsForm/SubscriptionSettingsForm.js +6 -6
- package/dist/elements/public/SubscriptionSettingsForm/SubscriptionSettingsForm.js.map +1 -1
- package/dist/elements/public/TemplateForm/TemplateForm.d.ts +10 -18
- package/dist/elements/public/TemplateForm/TemplateForm.js +54 -305
- package/dist/elements/public/TemplateForm/TemplateForm.js.map +1 -1
- package/dist/elements/public/TemplateForm/index.d.ts +4 -6
- package/dist/elements/public/TemplateForm/index.js +4 -6
- package/dist/elements/public/TemplateForm/index.js.map +1 -1
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/InternalTemplateFormAsyncAction.d.ts +10 -0
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/InternalTemplateFormAsyncAction.js +49 -0
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/InternalTemplateFormAsyncAction.js.map +1 -0
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/index.d.ts +5 -0
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/index.js +7 -0
- package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/index.js.map +1 -0
- package/package.json +1 -1
- package/dist/cdn/shared-015da8ca.js +0 -1
- package/dist/cdn/shared-a84befbf.js +0 -1
- package/dist/cdn/shared-d0e0f8a1.js +0 -2
- package/dist/cdn/shared-fb18400f.js +0 -1
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { html } from 'lit-element';
|
|
2
|
-
import { Choice, Group, Metadata } 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
1
|
import { TranslatableMixin } from "../../../mixins/translatable.js";
|
|
9
|
-
import {
|
|
2
|
+
import { BooleanSelector } from '@foxy.io/sdk/core';
|
|
3
|
+
import { InternalForm } from "../../internal/InternalForm/InternalForm.js";
|
|
4
|
+
import { ifDefined } from 'lit-html/directives/if-defined';
|
|
5
|
+
import { html } from 'lit-element';
|
|
10
6
|
const NS = 'template-form';
|
|
11
|
-
const Base =
|
|
7
|
+
const Base = TranslatableMixin(InternalForm, NS);
|
|
12
8
|
/**
|
|
13
9
|
* Form element for creating or editing templates (`fx:cart_include_template`, `fx:checkout_template`, `fx:cart_template`).
|
|
14
10
|
*
|
|
@@ -16,321 +12,74 @@ const Base = ScopedElementsMixin(ThemeableMixin(ConfigurableMixin(TranslatableMi
|
|
|
16
12
|
* @since 1.14.0
|
|
17
13
|
*/
|
|
18
14
|
export class TemplateForm extends Base {
|
|
19
|
-
|
|
20
|
-
super(
|
|
21
|
-
this.
|
|
22
|
-
|
|
15
|
+
get readonlySelector() {
|
|
16
|
+
const alwaysMatch = [super.readonlySelector.toString()];
|
|
17
|
+
if (this.form.content_url)
|
|
18
|
+
alwaysMatch.unshift('content');
|
|
19
|
+
return new BooleanSelector(alwaysMatch.join(' ').trim());
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
get disabledSelector() {
|
|
22
|
+
const alwaysMatch = [super.disabledSelector.toString()];
|
|
23
|
+
if (!this.in({ idle: { snapshot: 'clean' } }) || !this.data.content_url) {
|
|
24
|
+
alwaysMatch.unshift('source:cache');
|
|
25
|
+
}
|
|
26
|
+
return new BooleanSelector(alwaysMatch.join(' ').trim());
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'foxy-i18n': customElements.get('foxy-i18n'),
|
|
38
|
-
'vaadin-text-field': customElements.get('vaadin-text-field'),
|
|
39
|
-
'vaadin-button': customElements.get('vaadin-button'),
|
|
40
|
-
'x-metadata': Metadata,
|
|
41
|
-
'x-choice': Choice,
|
|
42
|
-
'x-group': Group,
|
|
43
|
-
};
|
|
28
|
+
get hiddenSelector() {
|
|
29
|
+
var _a;
|
|
30
|
+
const alwaysMatch = [super.hiddenSelector.toString()];
|
|
31
|
+
if (!((_a = this.data) === null || _a === void 0 ? void 0 : _a.content_url))
|
|
32
|
+
alwaysMatch.unshift('source:cache');
|
|
33
|
+
return new BooleanSelector(alwaysMatch.join(' ').trim());
|
|
44
34
|
}
|
|
45
|
-
|
|
46
|
-
var _a
|
|
47
|
-
const { hiddenSelector, href, lang, ns } = this;
|
|
48
|
-
const action = href ? 'delete' : 'create';
|
|
49
|
-
const isBusy = this.in('busy');
|
|
50
|
-
const isFail = this.in('fail');
|
|
35
|
+
renderBody() {
|
|
36
|
+
var _a;
|
|
51
37
|
return html `
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
${this.renderHeader()}
|
|
39
|
+
|
|
40
|
+
<foxy-internal-summary-control infer="general">
|
|
41
|
+
<foxy-internal-text-control layout="summary-item" infer="description">
|
|
42
|
+
</foxy-internal-text-control>
|
|
43
|
+
</foxy-internal-summary-control>
|
|
44
|
+
|
|
45
|
+
${this.renderTemplateOrSlot()}
|
|
46
|
+
|
|
47
|
+
<foxy-internal-source-control infer="content"></foxy-internal-source-control>
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
<foxy-internal-summary-control infer="source">
|
|
50
|
+
<foxy-internal-text-control layout="summary-item" infer="content-url">
|
|
51
|
+
</foxy-internal-text-control>
|
|
52
|
+
|
|
53
|
+
<foxy-internal-template-form-async-action
|
|
54
|
+
theme="tertiary-inline"
|
|
55
|
+
infer="cache"
|
|
56
|
+
href=${ifDefined((_a = this.data) === null || _a === void 0 ? void 0 : _a._links['fx:cache'].href)}
|
|
64
57
|
>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
lang=${lang}
|
|
70
|
-
ns="${ns} ${(_b = (_a = customElements.get('foxy-spinner')) === null || _a === void 0 ? void 0 : _a.defaultNS) !== null && _b !== void 0 ? _b : ''}"
|
|
71
|
-
>
|
|
72
|
-
</foxy-spinner>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
58
|
+
</foxy-internal-template-form-async-action>
|
|
59
|
+
</foxy-internal-summary-control>
|
|
60
|
+
|
|
61
|
+
${super.renderBody()}
|
|
75
62
|
`;
|
|
76
63
|
}
|
|
77
64
|
async _sendPost(edits) {
|
|
78
65
|
const data = await super._sendPost(edits);
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
if (edits.content_url) {
|
|
67
|
+
const url = data._links['fx:cache'].href;
|
|
68
|
+
const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });
|
|
69
|
+
if (!response.ok)
|
|
70
|
+
throw ['error:failed_to_cache'];
|
|
71
|
+
}
|
|
85
72
|
return await this._fetch(data._links.self.href);
|
|
86
73
|
}
|
|
87
74
|
async _sendPatch(edits) {
|
|
88
75
|
const data = await super._sendPatch(edits);
|
|
89
76
|
if (!edits.content_url)
|
|
90
77
|
return data;
|
|
91
|
-
this.__cacheState = 'busy';
|
|
92
78
|
const url = data._links['fx:cache'].href;
|
|
93
79
|
const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });
|
|
94
|
-
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw ['error:failed_to_cache'];
|
|
95
82
|
return await this._fetch(data._links.self.href);
|
|
96
83
|
}
|
|
97
|
-
__renderDescription() {
|
|
98
|
-
var _a, _b;
|
|
99
|
-
const scope = 'description';
|
|
100
|
-
return html `
|
|
101
|
-
<div>
|
|
102
|
-
${this.renderTemplateOrSlot(`${scope}:before`)}
|
|
103
|
-
|
|
104
|
-
<vaadin-text-field
|
|
105
|
-
data-testid=${scope}
|
|
106
|
-
class="w-full mb-s"
|
|
107
|
-
label=${this.t(scope)}
|
|
108
|
-
?disabled=${!this.in('idle') || this.disabledSelector.matches(scope)}
|
|
109
|
-
?readonly=${this.readonlySelector.matches(scope)}
|
|
110
|
-
.value=${(_b = (_a = this.form) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : ''}
|
|
111
|
-
@keydown=${(evt) => evt.key === 'Enter' && this.submit()}
|
|
112
|
-
@input=${(evt) => {
|
|
113
|
-
this.edit({ description: evt.currentTarget.value });
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
</vaadin-text-field>
|
|
117
|
-
|
|
118
|
-
${this.renderTemplateOrSlot(`${scope}:after`)}
|
|
119
|
-
</div>
|
|
120
|
-
`;
|
|
121
|
-
}
|
|
122
|
-
__renderContent() {
|
|
123
|
-
var _a, _b;
|
|
124
|
-
const scope = 'content';
|
|
125
|
-
const url = this.form.content_url;
|
|
126
|
-
const source = this.form.content;
|
|
127
|
-
const contentChoice = url ? 'url' : source ? 'clipboard' : this.__contentChoice;
|
|
128
|
-
const isDisabled = !this.in('idle') || this.disabledSelector.matches(scope);
|
|
129
|
-
const isReadonly = this.readonlySelector.matches(scope);
|
|
130
|
-
const isSyncProhibited = isReadonly || !((_a = this.data) === null || _a === void 0 ? void 0 : _a.content_url) || url !== this.data.content_url;
|
|
131
|
-
return html `
|
|
132
|
-
<div data-testid="content">
|
|
133
|
-
<x-group frame>
|
|
134
|
-
<foxy-i18n
|
|
135
|
-
class=${classMap({ 'transition-colors': true, 'text-disabled': isDisabled })}
|
|
136
|
-
lang=${this.lang}
|
|
137
|
-
slot="header"
|
|
138
|
-
key="template"
|
|
139
|
-
ns=${this.ns}
|
|
140
|
-
>
|
|
141
|
-
</foxy-i18n>
|
|
142
|
-
|
|
143
|
-
<x-choice
|
|
144
|
-
data-testid="content-type"
|
|
145
|
-
.value=${contentChoice}
|
|
146
|
-
.items=${['default', 'url', 'clipboard']}
|
|
147
|
-
?readonly=${isReadonly}
|
|
148
|
-
?disabled=${isDisabled}
|
|
149
|
-
@change=${(evt) => {
|
|
150
|
-
if (evt instanceof ChoiceChangeEvent) {
|
|
151
|
-
this.edit({ content: '', content_url: '' });
|
|
152
|
-
this.__contentChoice = evt.detail;
|
|
153
|
-
}
|
|
154
|
-
}}
|
|
155
|
-
>
|
|
156
|
-
${['default', 'url', 'clipboard'].map(value => {
|
|
157
|
-
return html `
|
|
158
|
-
<div slot="${value}-label" class="py-s leading-s">
|
|
159
|
-
<foxy-i18n class="block" lang=${this.lang} key="template_${value}" ns=${this.ns}>
|
|
160
|
-
</foxy-i18n>
|
|
161
|
-
</div>
|
|
162
|
-
`;
|
|
163
|
-
})}
|
|
164
|
-
|
|
165
|
-
<div
|
|
166
|
-
style="--lumo-border-radius: var(--lumo-border-radius-s)"
|
|
167
|
-
class="mb-m"
|
|
168
|
-
slot="url"
|
|
169
|
-
?hidden=${contentChoice !== 'url'}
|
|
170
|
-
>
|
|
171
|
-
<div class="flex items-end mt-0">
|
|
172
|
-
<vaadin-text-field
|
|
173
|
-
data-testid="content-url"
|
|
174
|
-
placeholder="https://example.com/my-template"
|
|
175
|
-
label=${this.t('url')}
|
|
176
|
-
class="flex-1 min-w-0"
|
|
177
|
-
?readonly=${isReadonly}
|
|
178
|
-
?disabled=${isDisabled}
|
|
179
|
-
.value=${this.form.content_url}
|
|
180
|
-
@keydown=${(evt) => evt.key === 'Enter' && this.submit()}
|
|
181
|
-
@input=${(evt) => {
|
|
182
|
-
const value = evt.currentTarget.value;
|
|
183
|
-
this.edit({ content: '', content_url: value });
|
|
184
|
-
}}
|
|
185
|
-
>
|
|
186
|
-
</vaadin-text-field>
|
|
187
|
-
|
|
188
|
-
<vaadin-button
|
|
189
|
-
data-testid="cache"
|
|
190
|
-
class="relative flex-shrink-0 ml-s"
|
|
191
|
-
?hidden=${isSyncProhibited}
|
|
192
|
-
?disabled=${isDisabled || this.__cacheState === 'busy'}
|
|
193
|
-
@click=${this.__cache}
|
|
194
|
-
>
|
|
195
|
-
<foxy-i18n
|
|
196
|
-
class=${classMap({
|
|
197
|
-
'relative transition-opacity': true,
|
|
198
|
-
'opacity-0': this.__cacheState !== 'idle',
|
|
199
|
-
})}
|
|
200
|
-
lang=${this.lang}
|
|
201
|
-
key="cache"
|
|
202
|
-
ns=${this.ns}
|
|
203
|
-
>
|
|
204
|
-
</foxy-i18n>
|
|
205
|
-
|
|
206
|
-
<div
|
|
207
|
-
class=${classMap({
|
|
208
|
-
'absolute inset-0 flex transition-opacity': true,
|
|
209
|
-
'opacity-0': this.__cacheState === 'idle',
|
|
210
|
-
})}
|
|
211
|
-
>
|
|
212
|
-
<foxy-spinner
|
|
213
|
-
layout="no-label"
|
|
214
|
-
class="m-auto"
|
|
215
|
-
state=${this.__cacheState === 'fail' ? 'error' : 'busy'}
|
|
216
|
-
lang=${this.lang}
|
|
217
|
-
ns=${this.ns}
|
|
218
|
-
>
|
|
219
|
-
</foxy-spinner>
|
|
220
|
-
</div>
|
|
221
|
-
</vaadin-button>
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
|
-
<foxy-internal-source-control
|
|
225
|
-
placeholder=${this.t('url_source_placeholder')}
|
|
226
|
-
helper-text=""
|
|
227
|
-
label=${this.t('url_source_label')}
|
|
228
|
-
infer="content"
|
|
229
|
-
class="mt-m${((_b = this.data) === null || _b === void 0 ? void 0 : _b.content) ? '' : ' hidden'}"
|
|
230
|
-
>
|
|
231
|
-
</foxy-internal-source-control>
|
|
232
|
-
</div>
|
|
233
|
-
|
|
234
|
-
<foxy-internal-source-control
|
|
235
|
-
placeholder=${this.t('clipboard_source_placeholder')}
|
|
236
|
-
helper-text=""
|
|
237
|
-
label=${this.t('clipboard_source_label')}
|
|
238
|
-
infer="content"
|
|
239
|
-
class="mb-m${contentChoice === 'clipboard' ? '' : ' hidden'}"
|
|
240
|
-
style="--lumo-border-radius: var(--lumo-border-radius-s)"
|
|
241
|
-
slot="clipboard"
|
|
242
|
-
>
|
|
243
|
-
</foxy-internal-source-control>
|
|
244
|
-
</x-choice>
|
|
245
|
-
</x-group>
|
|
246
|
-
</div>
|
|
247
|
-
`;
|
|
248
|
-
}
|
|
249
|
-
__renderTimestamps() {
|
|
250
|
-
const scope = 'timestamps';
|
|
251
|
-
return html `
|
|
252
|
-
<div>
|
|
253
|
-
${this.renderTemplateOrSlot(`${scope}:before`)}
|
|
254
|
-
|
|
255
|
-
<x-metadata
|
|
256
|
-
data-testid="timestamps"
|
|
257
|
-
.items=${['date_modified', 'date_created'].map(field => {
|
|
258
|
-
var _a;
|
|
259
|
-
return ({
|
|
260
|
-
name: this.t(field),
|
|
261
|
-
value: ((_a = this.data) === null || _a === void 0 ? void 0 : _a[field]) ? this.t('date', { value: new Date(this.data[field]) })
|
|
262
|
-
: '',
|
|
263
|
-
});
|
|
264
|
-
})}
|
|
265
|
-
>
|
|
266
|
-
</x-metadata>
|
|
267
|
-
|
|
268
|
-
${this.renderTemplateOrSlot(`${scope}:after`)}
|
|
269
|
-
</div>
|
|
270
|
-
`;
|
|
271
|
-
}
|
|
272
|
-
__renderAction(action) {
|
|
273
|
-
const { disabledSelector, href, lang, ns } = this;
|
|
274
|
-
const isTemplateValid = this.in({ idle: { template: { dirty: 'valid' } } });
|
|
275
|
-
const isSnapshotValid = this.in({ idle: { snapshot: { dirty: 'valid' } } });
|
|
276
|
-
const isDisabled = !this.in('idle') || disabledSelector.matches(action, true);
|
|
277
|
-
const isValid = isTemplateValid || isSnapshotValid;
|
|
278
|
-
const handleClick = (evt) => {
|
|
279
|
-
if (action === 'delete') {
|
|
280
|
-
const confirm = this.renderRoot.querySelector('#confirm');
|
|
281
|
-
confirm.show(evt.currentTarget);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.submit();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
return html `
|
|
288
|
-
<div>
|
|
289
|
-
${this.renderTemplateOrSlot(`${action}:before`)}
|
|
290
|
-
|
|
291
|
-
<foxy-internal-confirm-dialog
|
|
292
|
-
message="delete_prompt"
|
|
293
|
-
confirm="delete"
|
|
294
|
-
cancel="cancel"
|
|
295
|
-
header="delete"
|
|
296
|
-
theme="primary error"
|
|
297
|
-
lang=${lang}
|
|
298
|
-
ns=${ns}
|
|
299
|
-
id="confirm"
|
|
300
|
-
data-testid="confirm"
|
|
301
|
-
@hide=${(evt) => {
|
|
302
|
-
if (!evt.detail.cancelled)
|
|
303
|
-
this.delete();
|
|
304
|
-
}}
|
|
305
|
-
>
|
|
306
|
-
</foxy-internal-confirm-dialog>
|
|
307
|
-
|
|
308
|
-
<vaadin-button
|
|
309
|
-
class="w-full"
|
|
310
|
-
theme=${this.in('idle') ? (href ? 'error' : 'primary success') : ''}
|
|
311
|
-
data-testid=${action}
|
|
312
|
-
?disabled=${(this.in({ idle: 'template' }) && !isValid) || isDisabled}
|
|
313
|
-
@click=${handleClick}
|
|
314
|
-
>
|
|
315
|
-
<foxy-i18n ns=${ns} key=${action} lang=${lang}></foxy-i18n>
|
|
316
|
-
</vaadin-button>
|
|
317
|
-
|
|
318
|
-
${this.renderTemplateOrSlot(`${action}:after`)}
|
|
319
|
-
</div>
|
|
320
|
-
`;
|
|
321
|
-
}
|
|
322
|
-
async __cache() {
|
|
323
|
-
var _a, _b;
|
|
324
|
-
this.__cacheState = 'busy';
|
|
325
|
-
try {
|
|
326
|
-
const url = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a._links['fx:cache'].href) !== null && _b !== void 0 ? _b : '';
|
|
327
|
-
const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });
|
|
328
|
-
this.__cacheState = response.ok ? 'idle' : 'fail';
|
|
329
|
-
this.refresh();
|
|
330
|
-
}
|
|
331
|
-
catch (_c) {
|
|
332
|
-
this.__cacheState = 'fail';
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
84
|
}
|
|
336
85
|
//# sourceMappingURL=TemplateForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateForm.js","sourceRoot":"","sources":["../../../../src/elements/public/TemplateForm/TemplateForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,IAAI,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,+BAA4B;AAE9D,OAAO,EAAqB,mBAAmB,EAAE,MAAM,0BAA0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,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;YAClD,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;QAAC,WAAM;YACN,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;SAC5B;IACH,CAAC;CACF","sourcesContent":["import { PropertyDeclarations, TemplateResult, html } from 'lit-element';\nimport { Choice, Group, Metadata } from '../../private/index';\nimport { Data } from './types';\nimport { ScopedElementsMap, ScopedElementsMixin } from '@open-wc/scoped-elements';\n\nimport { ChoiceChangeEvent } from '../../private/events';\nimport { ConfigurableMixin } from '../../../mixins/configurable';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/NucleonElement';\nimport { TextFieldElement } from '@vaadin/vaadin-text-field';\nimport { ThemeableMixin } from '../../../mixins/themeable';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { classMap } from '../../../utils/class-map';\n\nconst NS = 'template-form';\nconst Base = ScopedElementsMixin(\n ThemeableMixin(ConfigurableMixin(TranslatableMixin(NucleonElement, NS)))\n);\n\n/**\n * Form element for creating or editing templates (`fx:cart_include_template`, `fx:checkout_template`, `fx:cart_template`).\n *\n * @element foxy-template-form\n * @since 1.14.0\n */\nexport class TemplateForm 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 scopedElements(): ScopedElementsMap {\n return {\n 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),\n 'foxy-internal-source-control': customElements.get('foxy-internal-source-control'),\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-button': customElements.get('vaadin-button'),\n 'x-metadata': Metadata,\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 relative\">\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 protected async _sendPost(edits: Partial<Data>): Promise<Data> {\n const data = await super._sendPost(edits);\n if (!data.content_url) return data;\n\n this.__cacheState = 'busy';\n const url = data._links['fx:cache'].href;\n const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });\n this.__cacheState = response.ok ? 'idle' : 'fail';\n\n return await this._fetch(data._links.self.href);\n }\n\n protected async _sendPatch(edits: Partial<Data>): Promise<Data> {\n const data = await super._sendPatch(edits);\n if (!edits.content_url) return data;\n\n this.__cacheState = 'busy';\n const url = data._links['fx:cache'].href;\n const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });\n this.__cacheState = response.ok ? 'idle' : 'fail';\n\n return await this._fetch(data._links.self.href);\n }\n\n private __renderDescription() {\n const scope = 'description';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${scope}:before`)}\n\n <vaadin-text-field\n data-testid=${scope}\n class=\"w-full mb-s\"\n label=${this.t(scope)}\n ?disabled=${!this.in('idle') || this.disabledSelector.matches(scope)}\n ?readonly=${this.readonlySelector.matches(scope)}\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(`${scope}:after`)}\n </div>\n `;\n }\n\n private __renderContent() {\n const scope = 'content';\n const url = this.form.content_url;\n const source = this.form.content;\n const contentChoice = url ? 'url' : source ? 'clipboard' : this.__contentChoice;\n\n const isDisabled = !this.in('idle') || this.disabledSelector.matches(scope);\n const isReadonly = this.readonlySelector.matches(scope);\n const isSyncProhibited = isReadonly || !this.data?.content_url || url !== this.data.content_url;\n\n return html`\n <div data-testid=\"content\">\n <x-group frame>\n <foxy-i18n\n class=${classMap({ 'transition-colors': true, 'text-disabled': isDisabled })}\n lang=${this.lang}\n slot=\"header\"\n key=\"template\"\n ns=${this.ns}\n >\n </foxy-i18n>\n\n <x-choice\n data-testid=\"content-type\"\n .value=${contentChoice}\n .items=${['default', 'url', 'clipboard']}\n ?readonly=${isReadonly}\n ?disabled=${isDisabled}\n @change=${(evt: Event) => {\n if (evt instanceof ChoiceChangeEvent) {\n this.edit({ content: '', content_url: '' });\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 leading-s\">\n <foxy-i18n class=\"block\" lang=${this.lang} key=\"template_${value}\" ns=${this.ns}>\n </foxy-i18n>\n </div>\n `;\n })}\n\n <div\n style=\"--lumo-border-radius: var(--lumo-border-radius-s)\"\n class=\"mb-m\"\n slot=\"url\"\n ?hidden=${contentChoice !== 'url'}\n >\n <div class=\"flex items-end mt-0\">\n <vaadin-text-field\n data-testid=\"content-url\"\n placeholder=\"https://example.com/my-template\"\n label=${this.t('url')}\n class=\"flex-1 min-w-0\"\n ?readonly=${isReadonly}\n ?disabled=${isDisabled}\n .value=${this.form.content_url}\n @keydown=${(evt: KeyboardEvent) => evt.key === 'Enter' && this.submit()}\n @input=${(evt: CustomEvent) => {\n const value = (evt.currentTarget as TextFieldElement).value;\n this.edit({ content: '', content_url: value });\n }}\n >\n </vaadin-text-field>\n\n <vaadin-button\n data-testid=\"cache\"\n class=\"relative flex-shrink-0 ml-s\"\n ?hidden=${isSyncProhibited}\n ?disabled=${isDisabled || 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 </div>\n\n <foxy-internal-source-control\n placeholder=${this.t('url_source_placeholder')}\n helper-text=\"\"\n label=${this.t('url_source_label')}\n infer=\"content\"\n class=\"mt-m${this.data?.content ? '' : ' hidden'}\"\n >\n </foxy-internal-source-control>\n </div>\n\n <foxy-internal-source-control\n placeholder=${this.t('clipboard_source_placeholder')}\n helper-text=\"\"\n label=${this.t('clipboard_source_label')}\n infer=\"content\"\n class=\"mb-m${contentChoice === 'clipboard' ? '' : ' hidden'}\"\n style=\"--lumo-border-radius: var(--lumo-border-radius-s)\"\n slot=\"clipboard\"\n >\n </foxy-internal-source-control>\n </x-choice>\n </x-group>\n </div>\n `;\n }\n\n private __renderTimestamps() {\n const scope = 'timestamps';\n\n return html`\n <div>\n ${this.renderTemplateOrSlot(`${scope}:before`)}\n\n <x-metadata\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-metadata>\n\n ${this.renderTemplateOrSlot(`${scope}: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') ? (href ? 'error' : 'primary 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 TemplateForm.API(this).fetch(url, { method: 'POST' });\n this.__cacheState = response.ok ? 'idle' : 'fail';\n this.refresh();\n } catch {\n this.__cacheState = 'fail';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TemplateForm.js","sourceRoot":"","sources":["../../../../src/elements/public/TemplateForm/TemplateForm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,oDAAiD;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,EAAE,GAAG,eAAe,CAAC;AAC3B,MAAM,IAAI,GAAG,iBAAiB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,IAAU;IAC1C,IAAI,gBAAgB;QAClB,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC1D,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,gBAAgB;QAClB,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC;QAExD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACvE,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;SACrC;QAED,OAAO,IAAI,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAA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AAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,CAAC,uBAAuB,CAAC,CAAC;QAElD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import type { TemplateResult } from 'lit-element';\nimport type { Data } from './types';\n\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { BooleanSelector } from '@foxy.io/sdk/core';\nimport { InternalForm } from '../../internal/InternalForm/InternalForm';\nimport { ifDefined } from 'lit-html/directives/if-defined';\nimport { html } from 'lit-element';\n\nconst NS = 'template-form';\nconst Base = TranslatableMixin(InternalForm, NS);\n\n/**\n * Form element for creating or editing templates (`fx:cart_include_template`, `fx:checkout_template`, `fx:cart_template`).\n *\n * @element foxy-template-form\n * @since 1.14.0\n */\nexport class TemplateForm extends Base<Data> {\n get readonlySelector(): BooleanSelector {\n const alwaysMatch = [super.readonlySelector.toString()];\n if (this.form.content_url) alwaysMatch.unshift('content');\n return new BooleanSelector(alwaysMatch.join(' ').trim());\n }\n\n get disabledSelector(): BooleanSelector {\n const alwaysMatch = [super.disabledSelector.toString()];\n\n if (!this.in({ idle: { snapshot: 'clean' } }) || !this.data.content_url) {\n alwaysMatch.unshift('source:cache');\n }\n\n return new BooleanSelector(alwaysMatch.join(' ').trim());\n }\n\n get hiddenSelector(): BooleanSelector {\n const alwaysMatch = [super.hiddenSelector.toString()];\n if (!this.data?.content_url) alwaysMatch.unshift('source:cache');\n return new BooleanSelector(alwaysMatch.join(' ').trim());\n }\n\n renderBody(): TemplateResult {\n return html`\n ${this.renderHeader()}\n\n <foxy-internal-summary-control infer=\"general\">\n <foxy-internal-text-control layout=\"summary-item\" infer=\"description\">\n </foxy-internal-text-control>\n </foxy-internal-summary-control>\n\n ${this.renderTemplateOrSlot()}\n\n <foxy-internal-source-control infer=\"content\"></foxy-internal-source-control>\n\n <foxy-internal-summary-control infer=\"source\">\n <foxy-internal-text-control layout=\"summary-item\" infer=\"content-url\">\n </foxy-internal-text-control>\n\n <foxy-internal-template-form-async-action\n theme=\"tertiary-inline\"\n infer=\"cache\"\n href=${ifDefined(this.data?._links['fx:cache'].href)}\n >\n </foxy-internal-template-form-async-action>\n </foxy-internal-summary-control>\n\n ${super.renderBody()}\n `;\n }\n\n protected async _sendPost(edits: Partial<Data>): Promise<Data> {\n const data = await super._sendPost(edits);\n\n if (edits.content_url) {\n const url = data._links['fx:cache'].href;\n const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });\n if (!response.ok) throw ['error:failed_to_cache'];\n }\n\n return await this._fetch(data._links.self.href);\n }\n\n protected async _sendPatch(edits: Partial<Data>): Promise<Data> {\n const data = await super._sendPatch(edits);\n if (!edits.content_url) return data;\n\n const url = data._links['fx:cache'].href;\n const response = await new TemplateForm.API(this).fetch(url, { method: 'POST' });\n if (!response.ok) throw ['error:failed_to_cache'];\n\n return await this._fetch(data._links.self.href);\n }\n}\n"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import '@vaadin/vaadin-button';
|
|
3
|
-
import '../../internal/InternalConfirmDialog/index';
|
|
1
|
+
import '../../internal/InternalSummaryControl/index';
|
|
4
2
|
import '../../internal/InternalSourceControl/index';
|
|
5
|
-
import '../../internal/
|
|
6
|
-
import '
|
|
7
|
-
import '
|
|
3
|
+
import '../../internal/InternalTextControl/index';
|
|
4
|
+
import '../../internal/InternalForm/index';
|
|
5
|
+
import './internal/InternalTemplateFormAsyncAction/index';
|
|
8
6
|
import { TemplateForm } from './TemplateForm';
|
|
9
7
|
export { TemplateForm };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '@vaadin/vaadin-button';
|
|
3
|
-
import "../../internal/InternalConfirmDialog/index.js";
|
|
1
|
+
import "../../internal/InternalSummaryControl/index.js";
|
|
4
2
|
import "../../internal/InternalSourceControl/index.js";
|
|
5
|
-
import "../../internal/
|
|
6
|
-
import "
|
|
7
|
-
import "
|
|
3
|
+
import "../../internal/InternalTextControl/index.js";
|
|
4
|
+
import "../../internal/InternalForm/index.js";
|
|
5
|
+
import "./internal/InternalTemplateFormAsyncAction/index.js";
|
|
8
6
|
import { TemplateForm } from "./TemplateForm.js";
|
|
9
7
|
customElements.define('foxy-template-form', TemplateForm);
|
|
10
8
|
export { TemplateForm };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/elements/public/TemplateForm/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/elements/public/TemplateForm/index.ts"],"names":[],"mappings":"AAAA,wDAAqD;AACrD,uDAAoD;AACpD,qDAAkD;AAClD,8CAA2C;AAE3C,6DAA0D;AAE1D,OAAO,EAAE,YAAY,EAAE,0BAAuB;AAE9C,cAAc,CAAC,MAAM,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import '../../internal/InternalSummaryControl/index';\nimport '../../internal/InternalSourceControl/index';\nimport '../../internal/InternalTextControl/index';\nimport '../../internal/InternalForm/index';\n\nimport './internal/InternalTemplateFormAsyncAction/index';\n\nimport { TemplateForm } from './TemplateForm';\n\ncustomElements.define('foxy-template-form', TemplateForm);\n\nexport { TemplateForm };\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropertyDeclarations, TemplateResult } from 'lit-element';
|
|
2
|
+
import { InternalControl } from '../../../../internal/InternalControl/InternalControl';
|
|
3
|
+
export declare class InternalTemplateFormAsyncAction extends InternalControl {
|
|
4
|
+
static get properties(): PropertyDeclarations;
|
|
5
|
+
theme: string | null;
|
|
6
|
+
href: string | null;
|
|
7
|
+
private __state;
|
|
8
|
+
renderControl(): TemplateResult;
|
|
9
|
+
private __submit;
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { InternalControl } from "../../../../internal/InternalControl/InternalControl.js";
|
|
2
|
+
import { NucleonElement } from "../../../NucleonElement/NucleonElement.js";
|
|
3
|
+
import { html } from 'lit-element';
|
|
4
|
+
export class InternalTemplateFormAsyncAction extends InternalControl {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.theme = null;
|
|
8
|
+
this.href = null;
|
|
9
|
+
this.__state = 'idle';
|
|
10
|
+
}
|
|
11
|
+
static get properties() {
|
|
12
|
+
return {
|
|
13
|
+
...super.properties,
|
|
14
|
+
__state: { type: String },
|
|
15
|
+
theme: { type: String },
|
|
16
|
+
href: { type: String },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
renderControl() {
|
|
20
|
+
const state = this.__state;
|
|
21
|
+
const theme = state === 'fail' ? 'error' : state === 'idle' ? '' : '';
|
|
22
|
+
return html `
|
|
23
|
+
<vaadin-button
|
|
24
|
+
theme=${`${this.theme} ${theme !== null && theme !== void 0 ? theme : ''}`.trim()}
|
|
25
|
+
?disabled=${state === 'busy' || this.disabled}
|
|
26
|
+
@click=${this.__submit}
|
|
27
|
+
>
|
|
28
|
+
<foxy-i18n key=${state} infer=""></foxy-i18n>
|
|
29
|
+
</vaadin-button>
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
async __submit() {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if (this.__state === 'busy')
|
|
35
|
+
return;
|
|
36
|
+
try {
|
|
37
|
+
this.__state = 'busy';
|
|
38
|
+
const api = new NucleonElement.API(this);
|
|
39
|
+
const response = await api.fetch((_a = this.href) !== null && _a !== void 0 ? _a : '', { method: 'POST' });
|
|
40
|
+
this.__state = response.ok ? 'idle' : 'fail';
|
|
41
|
+
if (response.ok)
|
|
42
|
+
(_b = this.nucleon) === null || _b === void 0 ? void 0 : _b.refresh();
|
|
43
|
+
}
|
|
44
|
+
catch (_c) {
|
|
45
|
+
this.__state = 'fail';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=InternalTemplateFormAsyncAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalTemplateFormAsyncAction.js","sourceRoot":"","sources":["../../../../../../src/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/InternalTemplateFormAsyncAction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,gEAA6D;AACvF,OAAO,EAAE,cAAc,EAAE,kDAA+C;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,OAAO,+BAAgC,SAAQ,eAAe;IAApE;;QAUE,UAAK,GAAkB,IAAI,CAAC;QAE5B,SAAI,GAAkB,IAAI,CAAC;QAEnB,YAAO,GAAG,MAAM,CAAC;IAgC3B,CAAC;IA7CC,MAAM,KAAK,UAAU;QACnB,OAAO;YACL,GAAG,KAAK,CAAC,UAAU;YACnB,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACzB,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACvB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;SACvB,CAAC;IACJ,CAAC;IAQD,aAAa;QACX,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,MAAM,KAAK,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtE,OAAO,IAAI,CAAA;;gBAEC,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,EAAE,CAAC,IAAI,EAAE;oBACjC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,QAAQ;iBACpC,IAAI,CAAC,QAAQ;;yBAEL,KAAK;;KAEzB,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,QAAQ;;QACpB,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM;YAAE,OAAO;QAEpC,IAAI;YACF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YAEtB,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,KAAK,OAAC,IAAI,CAAC,IAAI,mCAAI,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAEtE,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7C,IAAI,QAAQ,CAAC,EAAE;gBAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,GAAG;SAC1C;QAAC,WAAM;YACN,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;SACvB;IACH,CAAC;CACF","sourcesContent":["import type { PropertyDeclarations, TemplateResult } from 'lit-element';\n\nimport { InternalControl } from '../../../../internal/InternalControl/InternalControl';\nimport { NucleonElement } from '../../../NucleonElement/NucleonElement';\nimport { html } from 'lit-element';\n\nexport class InternalTemplateFormAsyncAction extends InternalControl {\n static get properties(): PropertyDeclarations {\n return {\n ...super.properties,\n __state: { type: String },\n theme: { type: String },\n href: { type: String },\n };\n }\n\n theme: string | null = null;\n\n href: string | null = null;\n\n private __state = 'idle';\n\n renderControl(): TemplateResult {\n const state = this.__state;\n const theme = state === 'fail' ? 'error' : state === 'idle' ? '' : '';\n\n return html`\n <vaadin-button\n theme=${`${this.theme} ${theme ?? ''}`.trim()}\n ?disabled=${state === 'busy' || this.disabled}\n @click=${this.__submit}\n >\n <foxy-i18n key=${state} infer=\"\"></foxy-i18n>\n </vaadin-button>\n `;\n }\n\n private async __submit(): Promise<void> {\n if (this.__state === 'busy') return;\n\n try {\n this.__state = 'busy';\n\n const api = new NucleonElement.API(this);\n const response = await api.fetch(this.href ?? '', { method: 'POST' });\n\n this.__state = response.ok ? 'idle' : 'fail';\n if (response.ok) this.nucleon?.refresh();\n } catch {\n this.__state = 'fail';\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import '@vaadin/vaadin-button';
|
|
2
|
+
import '../../../../internal/InternalControl/index';
|
|
3
|
+
import '../../../I18n/index';
|
|
4
|
+
import { InternalTemplateFormAsyncAction as Control } from './InternalTemplateFormAsyncAction';
|
|
5
|
+
export { Control as InternalTemplateFormAsyncAction };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import '@vaadin/vaadin-button';
|
|
2
|
+
import "../../../../internal/InternalControl/index.js";
|
|
3
|
+
import "../../../I18n/index.js";
|
|
4
|
+
import { InternalTemplateFormAsyncAction as Control } from "./InternalTemplateFormAsyncAction.js";
|
|
5
|
+
customElements.define('foxy-internal-template-form-async-action', Control);
|
|
6
|
+
export { Control as InternalTemplateFormAsyncAction };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/dist/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/elements/public/TemplateForm/internal/InternalTemplateFormAsyncAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,uDAAoD;AACpD,gCAA6B;AAE7B,OAAO,EAAE,+BAA+B,IAAI,OAAO,EAAE,6CAA0C;AAE/F,cAAc,CAAC,MAAM,CAAC,0CAA0C,EAAE,OAAO,CAAC,CAAC;AAE3E,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,CAAC","sourcesContent":["import '@vaadin/vaadin-button';\nimport '../../../../internal/InternalControl/index';\nimport '../../../I18n/index';\n\nimport { InternalTemplateFormAsyncAction as Control } from './InternalTemplateFormAsyncAction';\n\ncustomElements.define('foxy-internal-template-form-async-action', Control);\n\nexport { Control as InternalTemplateFormAsyncAction };\n"]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./shared-935adc3b.js";import"./shared-3bfbd5af.js";import{a as e}from"./shared-2dd497e5.js";import{h as t}from"./shared-dc73b9a5.js";import{l as r,_ as i,B as n}from"./shared-d1195c27.js";import"./shared-c86db2c0.js";import"./foxy-copy-to-clipboard.js";import"./foxy-spinner.js";import{g as s}from"./shared-bab2ea2c.js";import{C as o}from"./shared-d1cb97c6.js";import{T as a}from"./shared-6d7c1a2f.js";import{N as d}from"./shared-e8b8c8d0.js";import{c as l}from"./shared-4e709717.js";let c,h=e=>e;customElements.define("foxy-internal-timestamps-control",class extends e{renderControl(){return t(c||(c=h` <p class="font-lumo text-xs leading-s text-secondary"> <foxy-i18n infer="" key="date_created"></foxy-i18n> <foxy-i18n .options="${0}" infer="" key="date"> </foxy-i18n> <span>•<span> <foxy-i18n infer="" key="date_modified"></foxy-i18n> <foxy-i18n .options="${0}" infer="" key="date"> </foxy-i18n> </span></span></p> `),{value:r(this,"nucleon.data.date_created")},{value:r(this,"nucleon.data.date_modified")})}});let f,u=e=>e;customElements.define("foxy-internal-submit-control",class extends e{constructor(){super(...arguments),this.theme="primary"}static get properties(){return i(i({},super.properties),{},{theme:{type:String}})}renderControl(){return t(f||(f=u` <vaadin-button theme="${0}" ?disabled="${0}" @click="${0}"> <foxy-i18n infer="" key="caption"></foxy-i18n> </vaadin-button> `),this.theme,this.disabled,(()=>{var e;return null===(e=this.nucleon)||void 0===e?void 0:e.submit()}))}});let p,y=e=>e;customElements.define("foxy-internal-delete-control",class extends e{constructor(){super(...arguments),this.theme="error"}static get properties(){return i(i({},super.properties),{},{theme:{type:String}})}renderControl(){return t(p||(p=y` <foxy-internal-confirm-dialog message="delete_prompt" confirm="delete" cancel="cancel" header="delete" theme="primary error" infer="" id="confirm" @hide="${0}"> </foxy-internal-confirm-dialog> <vaadin-button data-testid="delete" theme="${0}" class="w-full" ?disabled="${0}" @click="${0}"> <foxy-i18n infer="" key="delete"></foxy-i18n> </vaadin-button> `),(e=>{var t;return!e.detail.cancelled&&(null===(t=this.nucleon)||void 0===t?void 0:t.delete())}),this.theme,this.disabled||this.readonly,(e=>{this.renderRoot.querySelector("#confirm").show(e.currentTarget)}))}});let m,x=e=>e;customElements.define("foxy-internal-undo-control",class extends e{constructor(){super(...arguments),this.theme="secondary"}static get properties(){return i(i({},super.properties),{},{theme:{type:String}})}renderControl(){return t(m||(m=x` <vaadin-button theme="${0}" ?disabled="${0}" @click="${0}"> <foxy-i18n infer="" key="caption"></foxy-i18n> </vaadin-button> `),this.theme,this.disabled,(()=>{var e;return null===(e=this.nucleon)||void 0===e?void 0:e.undo()}))}});let b,v,g,$,k,S,_,j,E,O,T,C,w=e=>e;const K=o(a(d));class B extends K{constructor(){super(...arguments),this.status=null}static get properties(){return i(i({},super.properties),{},{status:{type:Object}})}renderHeaderActions(e){return null}get headerTitleKey(){return"title"}get headerTitleOptions(){return i(i({},this.data),{},{context:this.data?"existing":"new",id:this.data?s(this.data._links.self.href):null})}get headerSubtitleKey(){return"subtitle"}get headerSubtitleOptions(){var e;return null!==(e=this.data)&&void 0!==e?e:{}}get headerCopyIdValue(){var e;return this.data&&null!==(e=s(this.data._links.self.href))&&void 0!==e?e:""}get hiddenSelector(){const e=[super.hiddenSelector.toString()];return this.href&&e.unshift("create"),this.href||e.unshift("delete","timestamps","submit"),this.in({idle:{snapshot:"dirty"}})||e.unshift("undo","submit"),new n(e.join(" ").trim())}renderHeader(){if(this.hiddenSelector.matches("header",!0))return t(b||(b=w``));const e=this.data,r=e?this.renderHeaderActions(e):null;return t(v||(v=w` <div> ${0} <h2> <span class="flex items-center gap-s leading-xs text-xl font-medium break-all"> <foxy-i18n options="${0}" infer="header" key="${0}"> </foxy-i18n> ${0} </span> ${0} </h2> ${0} </div> `),this.renderTemplateOrSlot("header:before"),JSON.stringify(this.headerTitleOptions),this.headerTitleKey,e?t(g||(g=w` ${0} ${0} `),this.hiddenSelector.matches("header:copy-id",!0)?"":t($||($=w` <foxy-copy-to-clipboard infer="header copy-id" class="text-m" text="${0}"> </foxy-copy-to-clipboard> `),this.headerCopyIdValue),this.hiddenSelector.matches("header:copy-json",!0)?"":t(k||(k=w` <foxy-copy-to-clipboard infer="header copy-json" class="text-m" icon="icons:code" text="${0}"> </foxy-copy-to-clipboard> `),JSON.stringify(e,null,2))):"",e?t(S||(S=w` <foxy-i18n infer="header" class="text-m text-secondary" key="${0}" .options="${0}"> </foxy-i18n> ${0} `),this.headerSubtitleKey,this.headerSubtitleOptions,r?t(_||(_=w`<div class="mt-xs flex gap-m">${0}</div>`),r):""):"",this.renderTemplateOrSlot("header:after"))}renderBody(){return t(j||(j=w` <foxy-internal-timestamps-control infer="timestamps"></foxy-internal-timestamps-control> <div class="flex gap-m" ?hidden="${0}"> <foxy-internal-delete-control infer="delete"></foxy-internal-delete-control> <div class="w-full"></div> <foxy-internal-undo-control infer="undo"> </foxy-internal-undo-control> <foxy-internal-submit-control infer="submit"> </foxy-internal-submit-control> <foxy-internal-submit-control infer="create" theme="primary success"> </foxy-internal-submit-control> </div> `),["delete","undo","submit","create"].every((e=>this.hiddenSelector.matches(e,!0))))}render(){const e=!(this.in("idle")||this.in({busy:"fetching"})&&this.data);return t(E||(E=w` <div aria-busy="${0}" aria-live="polite" class="relative"> <div class="${0}"> ${0} ${0} ${0} </div> <div data-testid="spinner" class="${0}"> <foxy-spinner layout="${0}" state="${0}" infer="spinner"> </foxy-spinner> ${0} </div> </div> `),this.in("busy"),l({"space-y-m":!0,"transition-opacity":!0,"opacity-0 pointer-events-none":e}),this.__generalErrors.map((e=>this.__renderGeneralError(e))),this.status?this.__renderStatus(this.status):"",this.renderBody(),l({"flex flex-col items-center justify-center gap-m":!0,"transition-opacity absolute inset-0":!0,"opacity-0 pointer-events-none":!e}),this.in("fail")?"vertical":"no-label",this.in("fail")?"error":"busy",this.href&&this.in("fail")?t(O||(O=w` <vaadin-button theme="small contrast" @click="${0}"> <foxy-i18n infer="spinner" key="refresh"></foxy-i18n> </vaadin-button> `),(()=>this.refresh())):"")}get __generalErrors(){const e=this.constructor.generalErrorPrefix;return this.errors.filter((t=>t.startsWith(e)))}__renderGeneralError(e){return t(T||(T=w` <foxy-i18n class="leading-xs text-body rounded bg-error-10 block" style="padding:calc(.625em + (var(--lumo-border-radius)/ 4) - 1px)" infer="error" key="${0}"> </foxy-i18n> `),e.replace("error:",""))}__renderStatus({key:e,options:r}){if(!this.hiddenSelector.matches("status",!0))return t(C||(C=w` <p data-testid="status" class="leading-xs text-body rounded bg-success-10 flex items-start gap-m" style="padding:calc(.625em + (var(--lumo-border-radius)/ 4) - 1px)"> <foxy-i18n class="flex-1" infer="status" key="${0}" .options="${0}"></foxy-i18n> <vaadin-button class="flex-shrink-0" theme="success tertiary-inline" @click="${0}"> <foxy-i18n class="flex-1" infer="status" key="close"></foxy-i18n> </vaadin-button> </p> `),e,r,(()=>this.status=null))}}B.generalErrorPrefix="error:",customElements.define("foxy-internal-form",B);export{B as I};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e}from"./shared-2dd497e5.js";import"./shared-3bfbd5af.js";import{c as s,h as t}from"./shared-dc73b9a5.js";let r,d,l=e=>e;customElements.define("foxy-internal-summary-control",class extends e{static get styles(){return[...super.styles,s(r||(r=l`::slotted(*){background-color:var(--lumo-contrast-5pct);padding:calc(.625em + (var(--lumo-border-radius)/ 4) - 1px)}`))]}renderLightDom(){}renderControl(){return t(d||(d=l` <div class="leading-s mb-s"> <p class="font-medium text-body text-l" ?hidden="${0}">${0}</p> <p class="text-s text-secondary" ?hidden="${0}">${0}</p> </div> <div class="rounded overflow-hidden grid" style="gap:1px"> <slot></slot> </div> `),!this.label,this.label,!this.helperText,this.helperText)}});
|