@foxy.io/elements 1.11.0-beta.2 → 1.11.0-beta.6
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 +4 -4
- package/dist/cdn/foxy-address-form.js +1 -1
- package/dist/cdn/foxy-applied-tax-card.js +1 -0
- 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 -0
- package/dist/cdn/foxy-custom-field-form.js +1 -0
- package/dist/cdn/foxy-customer-api.js +1 -1
- package/dist/cdn/foxy-customer-form.js +1 -1
- package/dist/cdn/foxy-customer-portal-settings.js +1 -1
- package/dist/cdn/foxy-customer-portal.js +2 -2
- 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 -0
- package/dist/cdn/foxy-donation.js +1 -1
- 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 -0
- package/dist/cdn/foxy-payment-method-card.js +1 -1
- package/dist/cdn/foxy-sign-in-form.js +1 -230
- package/dist/cdn/foxy-spinner.js +2 -2
- package/dist/cdn/foxy-subscription-card.js +1 -1
- package/dist/cdn/foxy-subscription-form.js +1 -1
- package/dist/cdn/foxy-subscriptions-table.js +1 -1
- package/dist/cdn/foxy-table.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-00355097.js +1 -0
- package/dist/cdn/shared-050576d4.js +15 -0
- package/dist/cdn/{shared-96de56d4.js → shared-0f4c8011.js} +1 -1
- package/dist/cdn/shared-2de00e0b.js +1 -0
- package/dist/cdn/{shared-497fd63c.js → shared-30016bf0.js} +1 -1
- package/dist/cdn/{shared-851b97ef.js → shared-3b229cce.js} +1 -1
- package/dist/cdn/shared-3d3d419e.js +1 -0
- package/dist/cdn/{shared-bf28ab5e.js → shared-3f710b92.js} +1 -1
- package/dist/cdn/{shared-aac9fed8.js → shared-5873e293.js} +1 -1
- package/dist/cdn/{shared-43316b66.js → shared-6a9e83d7.js} +1 -1
- package/dist/cdn/{shared-bba615b8.js → shared-73252961.js} +19 -19
- package/dist/cdn/{shared-84203d52.js → shared-73401142.js} +1 -1
- package/dist/cdn/shared-75c86771.js +1 -0
- package/dist/cdn/{shared-a5fbfdc7.js → shared-7dbbc98e.js} +1 -1
- package/dist/cdn/shared-7dda002f.js +1 -0
- package/dist/cdn/{shared-090432b4.js → shared-7f726bf5.js} +1 -1
- package/dist/cdn/{shared-525dd8c8.js → shared-8953096d.js} +1 -1
- package/dist/cdn/{shared-1e8cda7a.js → shared-897c8104.js} +1 -1
- package/dist/cdn/{shared-b0c39c37.js → shared-8caad813.js} +1 -1
- package/dist/cdn/{shared-23966eed.js → shared-8d210ad5.js} +1 -1
- package/dist/cdn/{shared-5ad54678.js → shared-9248217c.js} +1 -1
- package/dist/cdn/{shared-f06d08d5.js → shared-997e696f.js} +1 -1
- package/dist/cdn/{shared-a7709d26.js → shared-9bbb65af.js} +1 -1
- package/dist/cdn/shared-9fd917e7.js +1 -0
- package/dist/cdn/{shared-69d0ca61.js → shared-aa607c54.js} +1 -1
- package/dist/cdn/shared-bfba2bef.js +1 -0
- package/dist/cdn/{shared-9f78e096.js → shared-c5659975.js} +1 -1
- package/dist/cdn/{shared-e058cb87.js → shared-deb50049.js} +1 -1
- package/dist/cdn/shared-e762082b.js +1 -0
- package/dist/cdn/shared-f4119f12.js +230 -0
- package/dist/cdn/translations/shared/de.json +2 -0
- package/dist/cdn/translations/shared/en.json +3 -0
- package/dist/cdn/translations/shared/es.json +2 -0
- package/dist/elements/public/AddressCard/AddressCard.js +2 -2
- package/dist/elements/public/AddressCard/AddressCard.js.map +1 -1
- package/dist/elements/public/AppliedTaxCard/AppliedTaxCard.d.ts +25 -0
- package/dist/elements/public/AppliedTaxCard/AppliedTaxCard.js +62 -0
- package/dist/elements/public/AppliedTaxCard/AppliedTaxCard.js.map +1 -0
- package/dist/elements/public/AppliedTaxCard/index.d.ts +5 -0
- package/dist/elements/public/AppliedTaxCard/index.js +7 -0
- package/dist/elements/public/AppliedTaxCard/index.js.map +1 -0
- package/dist/elements/public/AppliedTaxCard/types.d.ts +3 -0
- package/dist/elements/public/AppliedTaxCard/types.js +2 -0
- package/dist/elements/public/AppliedTaxCard/types.js.map +1 -0
- package/dist/elements/public/AttributeCard/AttributeCard.js +4 -8
- package/dist/elements/public/AttributeCard/AttributeCard.js.map +1 -1
- package/dist/elements/public/CollectionPage/CollectionPage.d.ts +2 -0
- package/dist/elements/public/CollectionPage/CollectionPage.js +7 -0
- package/dist/elements/public/CollectionPage/CollectionPage.js.map +1 -1
- package/dist/elements/public/CollectionPage/types.d.ts +3 -0
- package/dist/elements/public/CollectionPage/types.js.map +1 -1
- package/dist/elements/public/CollectionPages/CollectionPages.d.ts +2 -0
- package/dist/elements/public/CollectionPages/CollectionPages.js +7 -0
- package/dist/elements/public/CollectionPages/CollectionPages.js.map +1 -1
- package/dist/elements/public/CollectionPages/types.d.ts +3 -0
- package/dist/elements/public/CollectionPages/types.js.map +1 -1
- package/dist/elements/public/CustomFieldCard/CustomFieldCard.d.ts +22 -0
- package/dist/elements/public/CustomFieldCard/CustomFieldCard.js +24 -0
- package/dist/elements/public/CustomFieldCard/CustomFieldCard.js.map +1 -0
- package/dist/elements/public/CustomFieldCard/TwoLineCard.d.ts +29 -0
- package/dist/elements/public/CustomFieldCard/TwoLineCard.js +70 -0
- package/dist/elements/public/CustomFieldCard/TwoLineCard.js.map +1 -0
- package/dist/elements/public/CustomFieldCard/index.d.ts +4 -0
- package/dist/elements/public/CustomFieldCard/index.js +6 -0
- package/dist/elements/public/CustomFieldCard/index.js.map +1 -0
- package/dist/elements/public/CustomFieldCard/types.d.ts +3 -0
- package/dist/elements/public/CustomFieldCard/types.js +2 -0
- package/dist/elements/public/CustomFieldCard/types.js.map +1 -0
- package/dist/elements/public/CustomFieldForm/CustomFieldForm.d.ts +49 -0
- package/dist/elements/public/CustomFieldForm/CustomFieldForm.js +235 -0
- package/dist/elements/public/CustomFieldForm/CustomFieldForm.js.map +1 -0
- package/dist/elements/public/CustomFieldForm/index.d.ts +9 -0
- package/dist/elements/public/CustomFieldForm/index.js +11 -0
- package/dist/elements/public/CustomFieldForm/index.js.map +1 -0
- package/dist/elements/public/CustomFieldForm/types.d.ts +22 -0
- package/dist/elements/public/CustomFieldForm/types.js +2 -0
- package/dist/elements/public/CustomFieldForm/types.js.map +1 -0
- package/dist/elements/public/DiscountCard/DiscountCard.d.ts +25 -0
- package/dist/elements/public/DiscountCard/DiscountCard.js +50 -0
- package/dist/elements/public/DiscountCard/DiscountCard.js.map +1 -0
- package/dist/elements/public/DiscountCard/index.d.ts +5 -0
- package/dist/elements/public/DiscountCard/index.js +7 -0
- package/dist/elements/public/DiscountCard/index.js.map +1 -0
- package/dist/elements/public/DiscountCard/types.d.ts +3 -0
- package/dist/elements/public/DiscountCard/types.js +2 -0
- package/dist/elements/public/DiscountCard/types.js.map +1 -0
- package/dist/elements/public/FormDialog/FormDialog.d.ts +2 -0
- package/dist/elements/public/FormDialog/FormDialog.js +4 -0
- package/dist/elements/public/FormDialog/FormDialog.js.map +1 -1
- package/dist/elements/public/I18n/I18n.d.ts +10 -0
- package/dist/elements/public/I18n/I18n.js +13 -0
- package/dist/elements/public/I18n/I18n.js.map +1 -1
- package/dist/elements/public/I18n/format/index.js +14 -14
- package/dist/elements/public/I18n/format/index.js.map +1 -1
- package/dist/elements/public/I18n/format/percent.d.ts +6 -0
- package/dist/elements/public/I18n/format/percent.js +16 -0
- package/dist/elements/public/I18n/format/percent.js.map +1 -0
- package/dist/elements/public/I18n/format/price.js +4 -2
- package/dist/elements/public/I18n/format/price.js.map +1 -1
- package/dist/elements/public/I18n/types.d.ts +7 -0
- package/dist/elements/public/I18n/types.js +2 -0
- package/dist/elements/public/I18n/types.js.map +1 -0
- package/dist/elements/public/NucleonElement/NucleonElement.d.ts +14 -1
- package/dist/elements/public/NucleonElement/NucleonElement.js +52 -8
- package/dist/elements/public/NucleonElement/NucleonElement.js.map +1 -1
- package/dist/elements/public/NucleonElement/serveFromCache.js +11 -6
- package/dist/elements/public/NucleonElement/serveFromCache.js.map +1 -1
- package/dist/elements/public/PaymentCard/PaymentCard.d.ts +46 -0
- package/dist/elements/public/PaymentCard/PaymentCard.js +185 -0
- package/dist/elements/public/PaymentCard/PaymentCard.js.map +1 -0
- package/dist/elements/public/PaymentCard/index.d.ts +5 -0
- package/dist/elements/public/PaymentCard/index.js +7 -0
- package/dist/elements/public/PaymentCard/index.js.map +1 -0
- package/dist/elements/public/PaymentCard/types.d.ts +17 -0
- package/dist/elements/public/PaymentCard/types.js +2 -0
- package/dist/elements/public/PaymentCard/types.js.map +1 -0
- package/dist/elements/public/SignInForm/SignInForm.d.ts +1 -1
- package/dist/elements/public/SignInForm/SignInForm.js.map +1 -1
- package/dist/elements/public/Spinner/Spinner.js +1 -1
- package/dist/elements/public/Spinner/Spinner.js.map +1 -1
- package/dist/elements/public/index.d.ts +5 -0
- package/dist/elements/public/index.defined.d.ts +5 -0
- package/dist/elements/public/index.defined.js +5 -0
- package/dist/elements/public/index.defined.js.map +1 -1
- package/dist/elements/public/index.js +5 -0
- package/dist/elements/public/index.js.map +1 -1
- package/dist/mixins/themeable.js +9 -0
- package/dist/mixins/themeable.js.map +1 -1
- package/package.json +2 -2
- package/dist/cdn/shared-6872bf5c.js +0 -1
- package/dist/cdn/shared-750035db.js +0 -15
- package/dist/cdn/shared-8057ee9c.js +0 -1
- package/dist/cdn/shared-9ba229fb.js +0 -1
- package/dist/cdn/shared-a110de43.js +0 -1
- package/dist/cdn/shared-c70d9713.js +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { html } from 'lit-html';
|
|
2
|
+
import { TranslatableMixin } from "../../../mixins/translatable.js";
|
|
3
|
+
import { TwoLineCard } from "../CustomFieldCard/TwoLineCard.js";
|
|
4
|
+
/**
|
|
5
|
+
* Basic card displaying a discount.
|
|
6
|
+
*
|
|
7
|
+
* @slot title:before
|
|
8
|
+
* @slot title:after
|
|
9
|
+
*
|
|
10
|
+
* @slot subtitle:before
|
|
11
|
+
* @slot subtitle:after
|
|
12
|
+
*
|
|
13
|
+
* @element foxy-discount-card
|
|
14
|
+
* @since 1.11.0
|
|
15
|
+
*/
|
|
16
|
+
export class DiscountCard extends TranslatableMixin(TwoLineCard, 'discount-card') {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.__currencyDisplay = '';
|
|
20
|
+
this.__currency = '';
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
return super.render({
|
|
24
|
+
title: data => html `${data.name} • ${data.code}`,
|
|
25
|
+
subtitle: data => html `
|
|
26
|
+
<foxy-i18n
|
|
27
|
+
options=${JSON.stringify({
|
|
28
|
+
currencyDisplay: this.__currencyDisplay,
|
|
29
|
+
amount: `${Math.abs(data.amount)} ${this.__currency}`,
|
|
30
|
+
})}
|
|
31
|
+
lang=${this.lang}
|
|
32
|
+
key="price"
|
|
33
|
+
ns=${this.ns}
|
|
34
|
+
>
|
|
35
|
+
</foxy-i18n>
|
|
36
|
+
`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async _sendGet() {
|
|
40
|
+
const discount = await super._sendGet();
|
|
41
|
+
const [transaction, store] = await Promise.all([
|
|
42
|
+
super._fetch(discount._links['fx:transaction'].href),
|
|
43
|
+
super._fetch(discount._links['fx:store'].href),
|
|
44
|
+
]);
|
|
45
|
+
this.__currency = transaction.currency_code;
|
|
46
|
+
this.__currencyDisplay = store.use_international_currency_symbol ? 'code' : 'symbol';
|
|
47
|
+
return discount;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=DiscountCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiscountCard.js","sourceRoot":"","sources":["../../../../src/elements/public/DiscountCard/DiscountCard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhD,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AACjE,OAAO,EAAE,WAAW,EAAE,0CAAuC;AAE7D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,YAAa,SAAQ,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAO;IAAvF;;QACU,sBAAiB,GAAG,EAAE,CAAC;QAEvB,eAAU,GAAG,EAAE,CAAC;IAmC1B,CAAC;IAjCC,MAAM;QACJ,OAAO,KAAK,CAAC,MAAM,CAAC;YAClB,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAA,GAAG,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,EAAE;YACrD,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAA;;oBAER,IAAI,CAAC,SAAS,CAAC;gBACvB,eAAe,EAAE,IAAI,CAAC,iBAAiB;gBACvC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;aACtD,CAAC;iBACK,IAAI,CAAC,IAAI;;eAEX,IAAI,CAAC,EAAE;;;OAGf;SACF,CAAC,CAAC;IACL,CAAC;IAES,KAAK,CAAC,QAAQ;QAItB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC7C,KAAK,CAAC,MAAM,CAAc,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;YACjE,KAAK,CAAC,MAAM,CAAQ,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;SACtD,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,aAAa,CAAC;QAC5C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iCAAiC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;QAErF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { TemplateResult, html } from 'lit-html';\n\nimport { Data } from './types';\nimport { Rels } from '@foxy.io/sdk/backend';\nimport { Resource } from '@foxy.io/sdk/core';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { TwoLineCard } from '../CustomFieldCard/TwoLineCard';\n\n/**\n * Basic card displaying a discount.\n *\n * @slot title:before\n * @slot title:after\n *\n * @slot subtitle:before\n * @slot subtitle:after\n *\n * @element foxy-discount-card\n * @since 1.11.0\n */\nexport class DiscountCard extends TranslatableMixin(TwoLineCard, 'discount-card')<Data> {\n private __currencyDisplay = '';\n\n private __currency = '';\n\n render(): TemplateResult {\n return super.render({\n title: data => html`${data.name} • ${data.code}`,\n subtitle: data => html`\n <foxy-i18n\n options=${JSON.stringify({\n currencyDisplay: this.__currencyDisplay,\n amount: `${Math.abs(data.amount)} ${this.__currency}`,\n })}\n lang=${this.lang}\n key=\"price\"\n ns=${this.ns}\n >\n </foxy-i18n>\n `,\n });\n }\n\n protected async _sendGet(): Promise<Data> {\n type Transaction = Resource<Rels.Transaction>;\n type Store = Resource<Rels.Store>;\n\n const discount = await super._sendGet();\n const [transaction, store] = await Promise.all([\n super._fetch<Transaction>(discount._links['fx:transaction'].href),\n super._fetch<Store>(discount._links['fx:store'].href),\n ]);\n\n this.__currency = transaction.currency_code;\n this.__currencyDisplay = store.use_international_currency_symbol ? 'code' : 'symbol';\n\n return discount;\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "../../internal/InternalSandbox/index.js";
|
|
2
|
+
import "../Spinner/index.js";
|
|
3
|
+
import "../I18n/index.js";
|
|
4
|
+
import { DiscountCard } from "./DiscountCard.js";
|
|
5
|
+
customElements.define('foxy-discount-card', DiscountCard);
|
|
6
|
+
export { DiscountCard };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/elements/public/DiscountCard/index.ts"],"names":[],"mappings":"AAAA,iDAA8C;AAC9C,6BAA0B;AAC1B,0BAAuB;AAEvB,OAAO,EAAE,YAAY,EAAE,0BAAuB;AAE9C,cAAc,CAAC,MAAM,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import '../../internal/InternalSandbox/index';\nimport '../Spinner/index';\nimport '../I18n/index';\n\nimport { DiscountCard } from './DiscountCard';\n\ncustomElements.define('foxy-discount-card', DiscountCard);\n\nexport { DiscountCard };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/elements/public/DiscountCard/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.Discount>;\n"]}
|
|
@@ -13,6 +13,8 @@ import { FormRenderer } from './types';
|
|
|
13
13
|
export declare class FormDialog extends Dialog {
|
|
14
14
|
/** @readonly */
|
|
15
15
|
static get properties(): PropertyDeclarations;
|
|
16
|
+
/** Optional URI list of the related resources (passed to form). */
|
|
17
|
+
related: string[];
|
|
16
18
|
/** Optional URL of the collection this resource belongs to (passed to form). */
|
|
17
19
|
parent: string;
|
|
18
20
|
group: string;
|
|
@@ -15,6 +15,8 @@ import { UpdateEvent } from "../NucleonElement/UpdateEvent.js";
|
|
|
15
15
|
export class FormDialog extends Dialog {
|
|
16
16
|
constructor() {
|
|
17
17
|
super(...arguments);
|
|
18
|
+
/** Optional URI list of the related resources (passed to form). */
|
|
19
|
+
this.related = [];
|
|
18
20
|
/** Optional URL of the collection this resource belongs to (passed to form). */
|
|
19
21
|
this.parent = '';
|
|
20
22
|
this.group = '';
|
|
@@ -54,6 +56,7 @@ export class FormDialog extends Dialog {
|
|
|
54
56
|
form: { type: String, noAccessor: true },
|
|
55
57
|
group: { type: String },
|
|
56
58
|
parent: { type: String },
|
|
59
|
+
related: { type: Array },
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
@@ -84,6 +87,7 @@ export class FormDialog extends Dialog {
|
|
|
84
87
|
?readonly=\${options.dialog.readonly}
|
|
85
88
|
?hidden=\${options.dialog.hidden}
|
|
86
89
|
.templates=\${options.dialog.templates}
|
|
90
|
+
.related=\${options.dialog.related}
|
|
87
91
|
@fetch=\${options.handleFetch}
|
|
88
92
|
@update=\${options.handleUpdate}
|
|
89
93
|
>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormDialog.js","sourceRoot":"","sources":["../../../../src/elements/public/FormDialog/FormDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,IAAI,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,iCAA8B;AAC5C,OAAO,EAAE,MAAM,EAAE,uCAAoC;AAErD,OAAO,EAAE,UAAU,EAAE,wCAAqC;AAI1D,OAAO,EAAE,WAAW,EAAE,yCAAsC;AAE5D;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAW,SAAQ,MAAM;IAAtC;;
|
|
1
|
+
{"version":3,"file":"FormDialog.js","sourceRoot":"","sources":["../../../../src/elements/public/FormDial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;CACF","sourcesContent":["import { PropertyDeclarations, TemplateResult, html } from 'lit-element';\n\nimport { API } from '../NucleonElement/API';\nimport { Dialog } from '../../private/Dialog/Dialog';\nimport { DialogHideEvent } from '../../private/Dialog/DialogHideEvent';\nimport { FetchEvent } from '../NucleonElement/FetchEvent';\nimport { FormRenderer } from './types';\nimport { InternalConfirmDialog } from '../../internal/InternalConfirmDialog/InternalConfirmDialog';\nimport { NucleonElement } from '../NucleonElement/NucleonElement';\nimport { UpdateEvent } from '../NucleonElement/UpdateEvent';\n\n/**\n * Dialog wrapper for the forms made with NucleonElement.\n *\n * @fires FormDialog#show - Instance of `FormDialog.ShowEvent`. Dispatched after dialog finishes entry transition.\n * @fires FormDialog#hide - Instance of `FormDialog.HideEvent`. Dispatched after dialog finishes exit transition.\n *\n * @element foxy-form-dialog\n * @since 1.1.0\n */\nexport class FormDialog extends Dialog {\n /** @readonly */\n static get properties(): PropertyDeclarations {\n return {\n ...super.properties,\n href: { type: String },\n form: { type: String, noAccessor: true },\n group: { type: String },\n parent: { type: String },\n related: { type: Array },\n };\n }\n\n /** Optional URI list of the related resources (passed to form). */\n related: string[] = [];\n\n /** Optional URL of the collection this resource belongs to (passed to form). */\n parent = '';\n\n group = '';\n\n /** Optional URL of the resource to load (passed to form). */\n href = '';\n\n private __form: string | null | FormRenderer = null;\n\n private __renderForm: FormRenderer | null = null;\n\n private __handleFetch = (evt: Event) => {\n if (!(evt instanceof FetchEvent)) return;\n\n evt.stopImmediatePropagation();\n evt.preventDefault();\n evt.respondWith(\n new API(this).fetch(evt.request).then(response => {\n const wasDeleting = evt.request.url === this.href && evt.request.method === 'DELETE';\n const wasAdding = evt.request.url === this.parent && evt.request.method === 'POST';\n\n if (response.ok && (wasDeleting || wasAdding)) this.open = false;\n return response;\n })\n );\n };\n\n private __handleUpdate = (evt: Event) => {\n if (!(evt instanceof UpdateEvent)) return;\n const target = evt.target as NucleonElement<never>;\n\n this.closable = !target.in('busy');\n this.editable =\n target.in({ idle: { template: { clean: 'valid' } } }) ||\n target.in({ idle: { template: { dirty: 'valid' } } }) ||\n target.in({ idle: { snapshot: { dirty: 'valid' } } });\n };\n\n /**\n * Form's custom element tag. Generated custom element will have the following attributes:\n *\n * - `parent` – same as `foxy-form-dialog[parent]`;\n * - `href` – same as `foxy-form-dialog[href]`;\n * - `lang` – same as `foxy-form-dialog[lang]`;\n */\n get form(): string | null | FormRenderer {\n return this.__form;\n }\n\n set form(value: string | null | FormRenderer) {\n this.__form = value;\n\n if (typeof value === 'string') {\n this.__renderForm = new Function(\n 'options',\n `return options.html\\`\n <${value}\n id=\"form\"\n ns=\"$\\{options.dialog.ns} $\\{customElements.get('${value}')?.defaultNS ?? ''}\"\n href=\\${options.dialog.href}\n lang=\\${options.dialog.lang}\n group=\\${options.dialog.group}\n parent=\\${options.dialog.parent}\n disabledcontrols=\\${options.dialog.disabledControls.toString()}\n readonlycontrols=\\${options.dialog.readonlyControls.toString()}\n hiddencontrols=\\${options.dialog.hiddenControls.toString()}\n ?disabled=\\${options.dialog.disabled}\n ?readonly=\\${options.dialog.readonly}\n ?hidden=\\${options.dialog.hidden}\n .templates=\\${options.dialog.templates}\n .related=\\${options.dialog.related}\n @fetch=\\${options.handleFetch}\n @update=\\${options.handleUpdate}\n >\n </${value}>\\``\n ) as FormRenderer;\n } else {\n this.__renderForm = value;\n }\n\n this.requestUpdate();\n }\n\n /** @readonly */\n render(): TemplateResult {\n return html`\n <foxy-internal-confirm-dialog\n message=\"undo_message\"\n confirm=\"undo_confirm\"\n cancel=\"undo_cancel\"\n header=\"undo_header\"\n theme=\"error\"\n lang=${this.lang}\n ns=${this.ns}\n id=\"confirm\"\n @hide=${(evt: DialogHideEvent) => !evt.detail.cancelled && super.hide(true)}\n >\n </foxy-internal-confirm-dialog>\n\n ${super.render(() => {\n return html`${this.__renderForm?.({\n handleUpdate: this.__handleUpdate,\n handleFetch: this.__handleFetch,\n dialog: this,\n html,\n })}`;\n })}\n `;\n }\n\n async hide(cancelled = false): Promise<void> {\n if (cancelled) {\n const confirm = this.renderRoot.querySelector('#confirm') as InternalConfirmDialog;\n confirm.show();\n } else {\n return super.hide(cancelled);\n }\n }\n\n /** Submits the form. */\n async save(): Promise<void> {\n (this.renderRoot.querySelector('#form') as NucleonElement<never>).submit();\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LitElement, PropertyDeclarations, TemplateResult } from 'lit-element';
|
|
2
2
|
import { StringMap, TOptions } from 'i18next';
|
|
3
3
|
import { FetchEvent } from '../NucleonElement/FetchEvent';
|
|
4
|
+
import { Gateways } from './types';
|
|
4
5
|
declare const I18n_base: typeof LitElement & import("lit-element").Constructor<import("../../../mixins/translatable").TranslatableMixinHost> & {
|
|
5
6
|
defaultNS: string;
|
|
6
7
|
};
|
|
@@ -35,6 +36,15 @@ export declare class I18n extends I18n_base {
|
|
|
35
36
|
* @example const unsubscribe = I18n.onResourceFetch((ns, lang) => fetch(`path/to/${ns}/${lang}`));
|
|
36
37
|
*/
|
|
37
38
|
static onResourceFetch(handler: (ns: string, lang: string) => Promise<Response>): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Adds payment gateway names to the i18next store. Fetch `fx:hosted_payment_gateways`
|
|
41
|
+
* and `fx:payment_gateways` and call this method to make gateway names available to
|
|
42
|
+
* elements like `foxy-payment-card`.
|
|
43
|
+
*
|
|
44
|
+
* @param param0 `fx:hosted_payment_gateways` or `fx:payment_gateways`
|
|
45
|
+
* @example I18n.setGateways({ values: { authorize: { name: 'Authorize.Net' }}})
|
|
46
|
+
*/
|
|
47
|
+
static setGateways({ values }: Gateways): void;
|
|
38
48
|
/** @readonly */
|
|
39
49
|
static get properties(): PropertyDeclarations;
|
|
40
50
|
/**
|
|
@@ -62,6 +62,19 @@ export class I18n extends TranslatableMixin(LitElement, '') {
|
|
|
62
62
|
addEventListener('fetch', handleFetch);
|
|
63
63
|
return () => removeEventListener('fetch', handleFetch);
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Adds payment gateway names to the i18next store. Fetch `fx:hosted_payment_gateways`
|
|
67
|
+
* and `fx:payment_gateways` and call this method to make gateway names available to
|
|
68
|
+
* elements like `foxy-payment-card`.
|
|
69
|
+
*
|
|
70
|
+
* @param param0 `fx:hosted_payment_gateways` or `fx:payment_gateways`
|
|
71
|
+
* @example I18n.setGateways({ values: { authorize: { name: 'Authorize.Net' }}})
|
|
72
|
+
*/
|
|
73
|
+
static setGateways({ values }) {
|
|
74
|
+
for (const id in values) {
|
|
75
|
+
this.i18next.addResource('en', 'gateways', `gateways.${id}`, values[id].name);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
65
78
|
/** @readonly */
|
|
66
79
|
static get properties() {
|
|
67
80
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../../../src/elements/public/I18n/I18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwC,IAAI,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,OAAgC,MAAM,SAAS,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,wCAAqC;
|
|
1
|
+
{"version":3,"file":"I18n.js","sourceRoot":"","sources":["../../../../src/elements/public/I18n/I18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwC,IAAI,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,OAAgC,MAAM,SAAS,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,wCAAqC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,wCAAqC;AACjE,OAAO,EAAE,OAAO,EAAE,qBAAkB;AACpC,OAAO,EAAE,MAAM,EAAE,0BAAuB;AAExC;;;;;;;GAOG;AACH,MAAM,OAAO,IAAK,SAAQ,iBAAiB,CAAC,UAAU,EAAE,EAAE,CAAC;IAA3D;;QAuEE;;;WAGG;QACH,YAAO,GAAwB,EAAE,CAAC;QAElC;;;WAGG;QACH,QAAG,GAAG,EAAE,CA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C,GAAG,CAAC,OAAO,CAAC,CAAC;AAkGlE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAChB,aAAa,EAAE,EAAE,MAAM,EAAE;IACzB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,QAAQ;IACpB,SAAS,EAAE,QAAQ;IACnB,EAAE,EAAE,CAAC,QAAQ,CAAC;CACf,CAAC,CAAC","sourcesContent":["import { LitElement, PropertyDeclarations, TemplateResult, html } from 'lit-element';\nimport i18next, { StringMap, TOptions } from 'i18next';\n\nimport { FetchEvent } from '../NucleonElement/FetchEvent';\nimport { Gateways } from './types';\nimport { TranslatableMixin } from '../../../mixins/translatable';\nimport { backend } from './backend';\nimport { format } from './format/index';\n\n/**\n * Custom element for effortless localization with i18next.\n *\n * @fires I18n#fetch - Instance of `I18n.FetchEvent`. Emitted before each translation request.\n *\n * @element foxy-i18n\n * @since 1.1.0\n */\nexport class I18n extends TranslatableMixin(LitElement, '') {\n /** Instances of this event are dispatched on an element before each translation request. */\n static readonly FetchEvent = FetchEvent;\n\n /** Shared [i18next](https://www.i18next.com) instance for all I18n elements. */\n static readonly i18next = i18next.createInstance().use(backend);\n\n /**\n * Registers a joint event listener for all i18next events that indicate\n * the availability of new translations. If you're using `I18n.i18next` to localize\n * your components, this function will call the provided handler every time an update is needed.\n *\n * @param handler Callback to invoke when translation changes.\n * @example const unsubscribe = I18n.onTranslationChange(triggerUpdate);\n */\n static onTranslationChange(handler: () => void): () => void {\n const i18nextEvents = ['initialized', 'loaded'] as const;\n const storeEvents = ['removed', 'added'] as const;\n\n i18nextEvents.forEach(type => I18n.i18next.on(type, handler));\n storeEvents.forEach(type => I18n.i18next.store.on(type, handler));\n\n return () => {\n i18nextEvents.forEach(type => I18n.i18next.off(type, handler));\n storeEvents.forEach(type => I18n.i18next.store.off(type, handler));\n };\n }\n\n /**\n * Registers a global event listener that calls `handler` every time an i18next resource\n * is downloaded by `foxy-i18n`. Allows devs to specify resource location and/or fetch it\n * via a different channel (e.g. web sockets or using a localization SaaS).\n *\n * @param handler Callback to invoke on resource fetch.\n * @example const unsubscribe = I18n.onResourceFetch((ns, lang) => fetch(`path/to/${ns}/${lang}`));\n */\n static onResourceFetch(handler: (ns: string, lang: string) => Promise<Response>): () => void {\n const handleFetch = (evt: unknown) => {\n if (evt instanceof FetchEvent && evt.request.url.startsWith('foxy://i18n/')) {\n const [lang, ns] = evt.request.url.split('/').reverse();\n evt.respondWith(handler(ns, lang));\n }\n };\n\n addEventListener('fetch', handleFetch);\n return () => removeEventListener('fetch', handleFetch);\n }\n\n /**\n * Adds payment gateway names to the i18next store. Fetch `fx:hosted_payment_gateways`\n * and `fx:payment_gateways` and call this method to make gateway names available to\n * elements like `foxy-payment-card`.\n *\n * @param param0 `fx:hosted_payment_gateways` or `fx:payment_gateways`\n * @example I18n.setGateways({ values: { authorize: { name: 'Authorize.Net' }}})\n */\n static setGateways({ values }: Gateways): void {\n for (const id in values) {\n this.i18next.addResource('en', 'gateways', `gateways.${id}`, values[id].name);\n }\n }\n\n /** @readonly */\n static get properties(): PropertyDeclarations {\n return {\n ...super.properties,\n options: { type: Object },\n key: { type: String },\n };\n }\n\n /**\n * Optional i18next translation function\n * [options](https://www.i18next.com/translation-function/essentials#overview-options).\n */\n options: TOptions<StringMap> = {};\n\n /**\n * Optional key to translate. Empty by default (renders nothing).\n * See [i18next docs](https://www.i18next.com/translation-function/essentials#accessing-keys) for more info.\n */\n key = '';\n\n private __unsubscribe?: () => void;\n\n /** @readonly */\n connectedCallback(): void {\n super.connectedCallback();\n this.__unsubscribe = I18n.onTranslationChange(() => this.requestUpdate());\n }\n\n /** @readonly */\n render(): TemplateResult {\n return html`${this.t(this.key, { ...this.options, lng: this.lang })}`;\n }\n\n /** @readonly */\n disconnectedCallback(): void {\n super.disconnectedCallback();\n this.__unsubscribe?.();\n }\n}\n\nI18n.i18next.init({\n interpolation: { format },\n fallbackLng: 'en',\n fallbackNS: 'shared',\n defaultNS: 'shared',\n ns: ['shared'],\n});\n"]}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { date } from "./date.js";
|
|
2
|
+
import { percent } from "./percent.js";
|
|
2
3
|
import { price } from "./price.js";
|
|
3
4
|
import { time } from "./time.js";
|
|
5
|
+
const formatters = {
|
|
6
|
+
percent,
|
|
7
|
+
price,
|
|
8
|
+
date,
|
|
9
|
+
time,
|
|
10
|
+
};
|
|
4
11
|
/**
|
|
5
12
|
* Chooses the right i18next formatter for the given template.
|
|
6
13
|
* @see https://www.i18next.com/translation-function/formatting
|
|
7
14
|
*/
|
|
8
|
-
export const format = (
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return price(result, format, language);
|
|
16
|
-
if (format === 'date')
|
|
17
|
-
return date(result, format, language);
|
|
18
|
-
if (format === 'time')
|
|
19
|
-
return time(result, format, language);
|
|
20
|
-
return result;
|
|
21
|
-
}, value);
|
|
15
|
+
export const format = (value, names = '', lang = 'en', opts = {}) => {
|
|
16
|
+
const parsedNames = names.split(' ').filter(v => !!v.trim());
|
|
17
|
+
const applyFormat = (result, name) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return (_b = (_a = formatters[name]) === null || _a === void 0 ? void 0 : _a.call(formatters, result, name, lang, opts)) !== null && _b !== void 0 ? _b : result;
|
|
20
|
+
};
|
|
21
|
+
return parsedNames.reduce(applyFormat, value);
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/elements/public/I18n/format/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,kBAAe;AAC9B,OAAO,EAAE,KAAK,EAAE,mBAAgB;AAChC,OAAO,EAAE,IAAI,EAAE,kBAAe;AAE9B;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/elements/public/I18n/format/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,kBAAe;AAC9B,OAAO,EAAE,OAAO,EAAE,qBAAkB;AACpC,OAAO,EAAE,KAAK,EAAE,mBAAgB;AAChC,OAAO,EAAE,IAAI,EAAE,kBAAe;AAE9B,MAAM,UAAU,GAAmC;IACjD,OAAO;IACP,KAAK;IACL,IAAI;IACJ,IAAI;CACL,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,EAAE,EAAU,EAAE;IAC1F,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE;;QACnD,mBAAO,UAAU,CAAC,IAAI,CAAC,+CAAhB,UAAU,EAAS,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,oCAAK,MAAM,CAAC;IAChE,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import { FormatFunction } from 'i18next';\nimport { date } from './date';\nimport { percent } from './percent';\nimport { price } from './price';\nimport { time } from './time';\n\nconst formatters: Record<string, FormatFunction> = {\n percent,\n price,\n date,\n time,\n};\n\n/**\n * Chooses the right i18next formatter for the given template.\n * @see https://www.i18next.com/translation-function/formatting\n */\nexport const format: FormatFunction = (value, names = '', lang = 'en', opts = {}): string => {\n const parsedNames = names.split(' ').filter(v => !!v.trim());\n const applyFormat = (result: string, name: string) => {\n return formatters[name]?.(result, name, lang, opts) ?? result;\n };\n\n return parsedNames.reduce(applyFormat, value);\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18next formatter that presents a fraction as percentage.
|
|
3
|
+
* @see https://www.i18next.com/translation-function/formatting
|
|
4
|
+
*/
|
|
5
|
+
export const percent = (value, format, lang) => {
|
|
6
|
+
let result = null;
|
|
7
|
+
try {
|
|
8
|
+
if (typeof value === 'number')
|
|
9
|
+
result = value.toLocaleString(lang, { style: 'percent' });
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
console.warn(`i18next formatter error: ${err.message}`);
|
|
13
|
+
}
|
|
14
|
+
return result || String(value);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=percent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percent.js","sourceRoot":"","sources":["../../../../../src/elements/public/I18n/format/percent.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAU,EAAE;IACrE,IAAI,MAAM,GAAkB,IAAI,CAAC;IAEjC,IAAI;QACF,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;KAC1F;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,IAAI,CAAC,4BAA4B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;KACzD;IAED,OAAO,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC","sourcesContent":["import { FormatFunction } from 'i18next';\n\n/**\n * i18next formatter that presents a fraction as percentage.\n * @see https://www.i18next.com/translation-function/formatting\n */\nexport const percent: FormatFunction = (value, format, lang): string => {\n let result: string | null = null;\n\n try {\n if (typeof value === 'number') result = value.toLocaleString(lang, { style: 'percent' });\n } catch (err) {\n console.warn(`i18next formatter error: ${err.message}`);\n }\n\n return result || String(value);\n};\n"]}
|
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
* i18next formatter that formats given value as price + currency code (e.g. 9.99 USD) for current locale (e.g. $9,99).
|
|
3
3
|
* @see https://www.i18next.com/translation-function/formatting
|
|
4
4
|
*/
|
|
5
|
-
export const price = (value, format, lang) => {
|
|
5
|
+
export const price = (value, format, lang, options) => {
|
|
6
|
+
var _a;
|
|
6
7
|
try {
|
|
7
8
|
const [amount, currency] = value.split(' ');
|
|
8
9
|
return parseFloat(amount).toLocaleString(lang, {
|
|
9
10
|
maximumFractionDigits: 2,
|
|
10
11
|
minimumFractionDigits: 2,
|
|
12
|
+
currencyDisplay: (_a = options === null || options === void 0 ? void 0 : options.currencyDisplay) !== null && _a !== void 0 ? _a : 'symbol',
|
|
11
13
|
style: 'currency',
|
|
12
14
|
currency,
|
|
13
15
|
});
|
|
14
16
|
}
|
|
15
|
-
catch (
|
|
17
|
+
catch (_b) {
|
|
16
18
|
return value;
|
|
17
19
|
}
|
|
18
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../../src/elements/public/I18n/format/price.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAU,EAAE
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../../src/elements/public/I18n/format/price.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAU,EAAE;;IAC5E,IAAI;QACF,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE;YAC7C,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,EAAE,CAAC;YACxB,eAAe,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,QAAQ;YACrD,KAAK,EAAE,UAAU;YACjB,QAAQ;SACT,CAAC,CAAC;KACJ;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC","sourcesContent":["import { FormatFunction } from 'i18next';\n\n/**\n * i18next formatter that formats given value as price + currency code (e.g. 9.99 USD) for current locale (e.g. $9,99).\n * @see https://www.i18next.com/translation-function/formatting\n */\nexport const price: FormatFunction = (value, format, lang, options): string => {\n try {\n const [amount, currency] = value.split(' ');\n return parseFloat(amount).toLocaleString(lang, {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n currencyDisplay: options?.currencyDisplay ?? 'symbol',\n style: 'currency',\n currency,\n });\n } catch {\n return value;\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/elements/public/I18n/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Gateways = {\n values: {\n [key: string]: { name: string };\n };\n};\n"]}
|
|
@@ -52,10 +52,16 @@ export declare class NucleonElement<TData extends HALJSONResource> extends LitEl
|
|
|
52
52
|
* Changing the `parent` attribute will update the value of this property.
|
|
53
53
|
*/
|
|
54
54
|
parent: string;
|
|
55
|
+
/**
|
|
56
|
+
* Optional URI list of the related resources. If Rumour encounters a related
|
|
57
|
+
* resource on creation or deletion, it will be reloaded from source.
|
|
58
|
+
*/
|
|
59
|
+
related: string[];
|
|
55
60
|
private __href;
|
|
56
61
|
private __group;
|
|
57
62
|
private __unsubscribeFromRumour;
|
|
58
63
|
private __fetchEventHandler;
|
|
64
|
+
private __fetchEventQueue;
|
|
59
65
|
private readonly __service;
|
|
60
66
|
/**
|
|
61
67
|
* If network request returns non-2XX code, the entire error response
|
|
@@ -130,12 +136,17 @@ export declare class NucleonElement<TData extends HALJSONResource> extends LitEl
|
|
|
130
136
|
* @example element.delete()
|
|
131
137
|
*/
|
|
132
138
|
delete(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Fetches data from `element.href` in background, keeping the edits and v8n errors.
|
|
141
|
+
* @example element.refresh()
|
|
142
|
+
*/
|
|
143
|
+
refresh(): void;
|
|
133
144
|
/** @readonly */
|
|
134
145
|
connectedCallback(): void;
|
|
135
146
|
/** @readonly */
|
|
136
147
|
disconnectedCallback(): void;
|
|
137
148
|
/** Sends API request. Throws an error on non-2XX response. */
|
|
138
|
-
protected _fetch(...args: Parameters<Window['fetch']>): Promise<
|
|
149
|
+
protected _fetch<TResult = TData>(...args: Parameters<Window['fetch']>): Promise<TResult>;
|
|
139
150
|
/** POSTs to `element.parent`, shares response with the Rumour group and returns parsed JSON. */
|
|
140
151
|
protected _sendPost(edits: Partial<TData>): Promise<TData>;
|
|
141
152
|
/** GETs `element.href`, shares response with the Rumour group and returns parsed JSON. */
|
|
@@ -151,5 +162,7 @@ export declare class NucleonElement<TData extends HALJSONResource> extends LitEl
|
|
|
151
162
|
private __createServer;
|
|
152
163
|
private __destroyServer;
|
|
153
164
|
private __handleRumourUpdate;
|
|
165
|
+
private __processFetchEventQueue;
|
|
166
|
+
private __flushFetchEventQueue;
|
|
154
167
|
private __handleFetchEvent;
|
|
155
168
|
}
|
|
@@ -28,8 +28,14 @@ export class NucleonElement extends LitElement {
|
|
|
28
28
|
* Changing the `parent` attribute will update the value of this property.
|
|
29
29
|
*/
|
|
30
30
|
this.parent = '';
|
|
31
|
+
/**
|
|
32
|
+
* Optional URI list of the related resources. If Rumour encounters a related
|
|
33
|
+
* resource on creation or deletion, it will be reloaded from source.
|
|
34
|
+
*/
|
|
35
|
+
this.related = [];
|
|
31
36
|
this.__href = '';
|
|
32
37
|
this.__group = '';
|
|
38
|
+
this.__fetchEventQueue = [];
|
|
33
39
|
this.__service = interpret(Nucleon.machine.withConfig({
|
|
34
40
|
services: {
|
|
35
41
|
sendDelete: () => this._sendDelete(),
|
|
@@ -54,6 +60,7 @@ export class NucleonElement extends LitElement {
|
|
|
54
60
|
/** @readonly */
|
|
55
61
|
static get properties() {
|
|
56
62
|
return {
|
|
63
|
+
related: { type: Array },
|
|
57
64
|
parent: { type: String },
|
|
58
65
|
group: { type: String, noAccessor: true },
|
|
59
66
|
href: { type: String, noAccessor: true },
|
|
@@ -180,12 +187,20 @@ export class NucleonElement extends LitElement {
|
|
|
180
187
|
delete() {
|
|
181
188
|
this.__service.send({ type: 'DELETE' });
|
|
182
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Fetches data from `element.href` in background, keeping the edits and v8n errors.
|
|
192
|
+
* @example element.refresh()
|
|
193
|
+
*/
|
|
194
|
+
refresh() {
|
|
195
|
+
this.__service.send({ type: 'REFRESH' });
|
|
196
|
+
}
|
|
183
197
|
/** @readonly */
|
|
184
198
|
connectedCallback() {
|
|
185
199
|
super.connectedCallback();
|
|
186
200
|
this.__createService();
|
|
187
201
|
this.__createRumour();
|
|
188
202
|
this.__createServer();
|
|
203
|
+
this.__processFetchEventQueue();
|
|
189
204
|
}
|
|
190
205
|
/** @readonly */
|
|
191
206
|
disconnectedCallback() {
|
|
@@ -193,6 +208,7 @@ export class NucleonElement extends LitElement {
|
|
|
193
208
|
this.__destroyService();
|
|
194
209
|
this.__destroyRumour();
|
|
195
210
|
this.__destroyServer();
|
|
211
|
+
this.__flushFetchEventQueue('parent element was disconnected');
|
|
196
212
|
}
|
|
197
213
|
/** Sends API request. Throws an error on non-2XX response. */
|
|
198
214
|
async _fetch(...args) {
|
|
@@ -206,8 +222,9 @@ export class NucleonElement extends LitElement {
|
|
|
206
222
|
const body = JSON.stringify(edits);
|
|
207
223
|
const data = await this._fetch(this.parent, { body, method: 'POST' });
|
|
208
224
|
const rumour = NucleonElement.Rumour(this.group);
|
|
225
|
+
const related = [...this.related, this.parent];
|
|
209
226
|
this.__destroyRumour();
|
|
210
|
-
rumour.share({ data, related
|
|
227
|
+
rumour.share({ data, related, source: data._links.self.href });
|
|
211
228
|
this.__createRumour();
|
|
212
229
|
return data;
|
|
213
230
|
}
|
|
@@ -226,7 +243,7 @@ export class NucleonElement extends LitElement {
|
|
|
226
243
|
const data = await this._fetch(this.href, { body, method: 'PATCH' });
|
|
227
244
|
const rumour = NucleonElement.Rumour(this.group);
|
|
228
245
|
this.__destroyRumour();
|
|
229
|
-
rumour.share({ data, source: this.href });
|
|
246
|
+
rumour.share({ data, source: this.href, related: this.related });
|
|
230
247
|
this.__createRumour();
|
|
231
248
|
return data;
|
|
232
249
|
}
|
|
@@ -234,8 +251,9 @@ export class NucleonElement extends LitElement {
|
|
|
234
251
|
async _sendDelete() {
|
|
235
252
|
const data = await this._fetch(this.href, { method: 'DELETE' });
|
|
236
253
|
const rumour = NucleonElement.Rumour(this.group);
|
|
254
|
+
const related = [...this.related, this.parent];
|
|
237
255
|
this.__destroyRumour();
|
|
238
|
-
rumour.share({ data: null, source: this.href, related
|
|
256
|
+
rumour.share({ data: null, source: this.href, related });
|
|
239
257
|
this.__createRumour();
|
|
240
258
|
return data;
|
|
241
259
|
}
|
|
@@ -247,6 +265,8 @@ export class NucleonElement extends LitElement {
|
|
|
247
265
|
this.setAttribute('state', [...new Set(flags)].join(' '));
|
|
248
266
|
this.requestUpdate();
|
|
249
267
|
this.dispatchEvent(new UpdateEvent());
|
|
268
|
+
if (!state.matches('busy'))
|
|
269
|
+
this.__processFetchEventQueue();
|
|
250
270
|
});
|
|
251
271
|
this.__service.onChange(() => {
|
|
252
272
|
this.requestUpdate();
|
|
@@ -284,23 +304,47 @@ export class NucleonElement extends LitElement {
|
|
|
284
304
|
}
|
|
285
305
|
catch (err) {
|
|
286
306
|
if (err instanceof Rumour.UpdateError) {
|
|
287
|
-
this.__service.send({ type: '
|
|
307
|
+
this.__service.send({ type: 'REFRESH' });
|
|
288
308
|
}
|
|
289
309
|
else {
|
|
290
310
|
throw err;
|
|
291
311
|
}
|
|
292
312
|
}
|
|
293
313
|
}
|
|
314
|
+
__processFetchEventQueue() {
|
|
315
|
+
const api = new NucleonElement.API(this);
|
|
316
|
+
this.__fetchEventQueue.forEach(event => {
|
|
317
|
+
const request = event.request;
|
|
318
|
+
const cacheResponse = serveFromCache(request.url, this.data);
|
|
319
|
+
const whenResponseReady = cacheResponse.ok ? cacheResponse : api.fetch(request);
|
|
320
|
+
event.respondWith(Promise.resolve(whenResponseReady));
|
|
321
|
+
if (cacheResponse.ok) {
|
|
322
|
+
console.debug(`%c@foxy.io/elements::${this.localName}\n%c200%c GET ${request.url}`, 'color: gray', `background: gray; padding: 0 .2em; border-radius: .2em; color: white;`, '');
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
this.__fetchEventQueue = [];
|
|
326
|
+
}
|
|
327
|
+
__flushFetchEventQueue(errorMessage) {
|
|
328
|
+
this.__fetchEventQueue.forEach(event => {
|
|
329
|
+
event.respondWith(Promise.reject(new Error(errorMessage)));
|
|
330
|
+
});
|
|
331
|
+
this.__fetchEventQueue = [];
|
|
332
|
+
}
|
|
294
333
|
__handleFetchEvent(event) {
|
|
295
334
|
if (!(event instanceof FetchEvent))
|
|
296
335
|
return;
|
|
336
|
+
if (event.defaultPrevented)
|
|
337
|
+
return;
|
|
297
338
|
if (event.request.method !== 'GET')
|
|
298
339
|
return;
|
|
299
|
-
|
|
300
|
-
|
|
340
|
+
if (event.request.url.startsWith('foxy://'))
|
|
341
|
+
return;
|
|
342
|
+
if (event.composedPath()[0] === this)
|
|
301
343
|
return;
|
|
302
|
-
event.
|
|
303
|
-
|
|
344
|
+
event.preventDefault();
|
|
345
|
+
this.__fetchEventQueue.push(event);
|
|
346
|
+
if (!this.in('busy'))
|
|
347
|
+
this.__processFetchEventQueue();
|
|
304
348
|
}
|
|
305
349
|
}
|
|
306
350
|
/**
|