@phis/ui 0.5.3 → 0.5.5
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/components/cms/phi-cms-layout-renderer.js +17 -7
- package/components/controls/phi-cascader-control.d.ts +9 -1
- package/components/controls/phi-cascader-control.js +25 -3
- package/components/controls/phi-money-control.d.ts +39 -0
- package/components/controls/phi-money-control.js +34 -0
- package/components/controls/phi-number-control.d.ts +6 -1
- package/components/controls/phi-number-control.js +3 -3
- package/components/controls/phi-options-provider.d.ts +7 -0
- package/components/controls/phi-options-provider.js +11 -0
- package/components/forms/extended-form-field-controls.d.ts +1 -0
- package/components/forms/extended-form-field-controls.js +23 -1
- package/components/forms/form-descriptor-runtime-client.js +13 -0
- package/components/forms/form-provider-contract.d.ts +43 -0
- package/components/forms/form-provider-contract.js +40 -0
- package/components/forms/money-field.d.ts +27 -0
- package/components/forms/money-field.js +78 -0
- package/components/forms/shared-form-provider-registry.js +4 -0
- package/components/layouts/clients/phi-flex-layout-client.js +17 -2
- package/components/layouts/clients/phi-layout-anchored-overlay.d.ts +2 -0
- package/components/layouts/clients/phi-layout-anchored-overlay.js +2 -0
- package/components/media/phi-media-picker-binding.js +6 -1
- package/components/media/phi-site-font-assets.js +6 -1
- package/components/motion/phi-sequence-run.d.ts +14 -1
- package/components/motion/phi-sequence-run.js +22 -3
- package/components/motion/phi-sequence-viewport.js +3 -1
- package/components/regions/presets/content-entry-editor-page-tree.js +5 -1
- package/components/regions/presets/content-entry-public-page-trees.js +2 -0
- package/components/tables/client/phi-table-binding.js +16 -3
- package/components/trees/client/phi-tree-binding.js +6 -2
- package/components/widgets/builder/stack-tabs.d.ts +2 -1
- package/components/widgets/builder/stack-tabs.js +18 -2
- package/components/widgets/client/shared/phi-collection-view-binding.js +10 -2
- package/components/widgets/client/shared/phi-rendered-value.d.ts +9 -1
- package/components/widgets/client/shared/phi-rendered-value.js +20 -1
- package/components/widgets/config/choice-shared.d.ts +1 -49
- package/components/widgets/config/choice-shared.js +0 -1
- package/components/widgets/config/stack-tabs.js +4 -3
- package/components/widgets/label-sets/gallery.js +6 -0
- package/components/widgets/label-sets/interval.d.ts +4 -0
- package/components/widgets/label-sets/interval.js +31 -0
- package/components/widgets/label-sets/record.js +6 -1
- package/components/widgets/label-sets/slot-upload.d.ts +4 -0
- package/components/widgets/label-sets/slot-upload.js +36 -0
- package/components/widgets/label-sets/table.js +6 -1
- package/components/widgets/label-types/gallery.d.ts +7 -0
- package/components/widgets/label-types/gallery.js +6 -0
- package/components/widgets/label-types/interval.d.ts +16 -0
- package/components/widgets/label-types/interval.js +21 -0
- package/components/widgets/label-types/record.d.ts +3 -0
- package/components/widgets/label-types/record.js +2 -0
- package/components/widgets/label-types/slot-upload.d.ts +24 -0
- package/components/widgets/label-types/slot-upload.js +16 -0
- package/components/widgets/label-types/table.d.ts +3 -0
- package/components/widgets/label-types/table.js +2 -0
- package/constants/record-field-kinds.d.ts +1 -1
- package/constants/record-field-kinds.js +1 -1
- package/constants/runtime-module-ownership.js +1 -0
- package/controls.d.ts +7 -0
- package/controls.js +4 -0
- package/helpers/cms-dialog.d.ts +39 -3
- package/helpers/cms-dialog.js +46 -4
- package/helpers/cms-page-catalog.d.ts +8 -0
- package/helpers/cms-page-catalog.js +18 -2
- package/helpers/cms-preset-nodes.d.ts +13 -3
- package/helpers/cms-preset-nodes.js +3 -2
- package/helpers/config-text-fields.d.ts +49 -0
- package/helpers/config-text-fields.js +122 -0
- package/helpers/money-amount.d.ts +48 -0
- package/helpers/money-amount.js +131 -0
- package/helpers/page-layout-check.js +15 -2
- package/helpers/preset-text-source-check.d.ts +22 -0
- package/helpers/preset-text-source-check.js +45 -0
- package/helpers/record-fields.d.ts +18 -5
- package/helpers/record-fields.js +38 -13
- package/helpers/text-source.d.ts +14 -5
- package/helpers/text-source.js +16 -3
- package/module-page-check.d.ts +1 -0
- package/module-page-check.js +1 -0
- package/module-records.d.ts +6 -3
- package/module-records.js +4 -2
- package/package.json +2 -2
- package/plugins/runtime/phi-slot-child-frame-view.js +1 -1
- package/plugins/runtime/slot-size-policy.d.ts +8 -2
- package/plugins/runtime/slot-size-policy.js +51 -16
- package/plugins/runtime-modules/accounting/module.d.ts +1 -1
- package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.js +2 -0
- package/plugins/runtime-modules/app/module.d.ts +1 -1
- package/plugins/runtime-modules/asset/services/collection.js +1 -0
- package/plugins/runtime-modules/asset/trees/phi-default-builder-media-page-tree.js +2 -2
- package/plugins/runtime-modules/auth/trees/phi-default-admin-auth-settings-page-tree.js +3 -0
- package/plugins/runtime-modules/builder/clients/widget-inspector.js +2 -2
- package/plugins/runtime-modules/builder/offered-page-catalog.js +3 -3
- package/plugins/runtime-modules/builder/options-providers.js +7 -0
- package/plugins/runtime-modules/builder/trees/phi-builder-inspector-area-overlay-tree.server.js +3 -0
- package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +17 -3
- package/plugins/runtime-modules/contracts.d.ts +1 -1
- package/plugins/runtime-modules/core/definition.d.ts +43 -0
- package/plugins/runtime-modules/core/form-providers.d.ts +43 -0
- package/plugins/runtime-modules/core/widgets/breadcrumb/client.d.ts +6 -3
- package/plugins/runtime-modules/core/widgets/breadcrumb/client.js +6 -5
- package/plugins/runtime-modules/core/widgets/breadcrumb/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/breadcrumb/server.d.ts +9 -1
- package/plugins/runtime-modules/core/widgets/breadcrumb/server.js +29 -3
- package/plugins/runtime-modules/core/widgets/button/config.d.ts +0 -1
- package/plugins/runtime-modules/core/widgets/button/config.js +0 -1
- package/plugins/runtime-modules/core/widgets/button/plugin.js +6 -25
- package/plugins/runtime-modules/core/widgets/card/config.d.ts +18 -2
- package/plugins/runtime-modules/core/widgets/card/config.js +16 -1
- package/plugins/runtime-modules/core/widgets/card/plugin.js +8 -10
- package/plugins/runtime-modules/core/widgets/card/server.d.ts +1 -2
- package/plugins/runtime-modules/core/widgets/card/server.js +16 -28
- package/plugins/runtime-modules/core/widgets/cascader/authoring.d.ts +4 -3
- package/plugins/runtime-modules/core/widgets/cascader/client.js +1 -1
- package/plugins/runtime-modules/core/widgets/cascader/config.d.ts +8 -2
- package/plugins/runtime-modules/core/widgets/cascader/config.js +22 -0
- package/plugins/runtime-modules/core/widgets/checkbox-group/config.d.ts +8 -2
- package/plugins/runtime-modules/core/widgets/checkbox-group/config.js +1 -1
- package/plugins/runtime-modules/core/widgets/description/config.d.ts +2 -1
- package/plugins/runtime-modules/core/widgets/entry-list/config.d.ts +2 -2
- package/plugins/runtime-modules/core/widgets/entry-list/config.js +0 -1
- package/plugins/runtime-modules/core/widgets/entry-list/plugin.js +1 -3
- package/plugins/runtime-modules/core/widgets/entry-list/server.d.ts +1 -3
- package/plugins/runtime-modules/core/widgets/entry-list/server.js +3 -3
- package/plugins/runtime-modules/core/widgets/gallery/authoring.js +12 -3
- package/plugins/runtime-modules/core/widgets/gallery/client.js +10 -1
- package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +4 -1
- package/plugins/runtime-modules/core/widgets/gallery/config.js +8 -0
- package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/image/server.js +5 -9
- package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +2 -1
- package/plugins/runtime-modules/core/widgets/markdown-toc/server.js +3 -5
- package/plugins/runtime-modules/core/widgets/multi-select/config.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/quick-links/plugin.js +2 -4
- package/plugins/runtime-modules/core/widgets/quick-links/server.d.ts +2 -5
- package/plugins/runtime-modules/core/widgets/quick-links/server.js +2 -6
- package/plugins/runtime-modules/core/widgets/record/client.js +8 -2
- package/plugins/runtime-modules/core/widgets/record/config.js +4 -0
- package/plugins/runtime-modules/core/widgets/result/config.d.ts +2 -2
- package/plugins/runtime-modules/core/widgets/result/config.js +0 -1
- package/plugins/runtime-modules/core/widgets/result/plugin.js +2 -4
- package/plugins/runtime-modules/core/widgets/result/server.d.ts +2 -3
- package/plugins/runtime-modules/core/widgets/result/server.js +11 -33
- package/plugins/runtime-modules/core/widgets/segmented/config.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/select-box/config.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +2 -1
- package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/slider/config.d.ts +11 -0
- package/plugins/runtime-modules/core/widgets/slider/config.js +1 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/authoring.js +2 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/client.d.ts +3 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/client.js +45 -24
- package/plugins/runtime-modules/core/widgets/slot-upload/config.d.ts +11 -4
- package/plugins/runtime-modules/core/widgets/slot-upload/config.js +16 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/plugin.js +2 -2
- package/plugins/runtime-modules/core/widgets/slot-upload/server.d.ts +8 -3
- package/plugins/runtime-modules/core/widgets/slot-upload/server.js +9 -3
- package/plugins/runtime-modules/core/widgets/spacer/config.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/spacer/config.js +1 -1
- package/plugins/runtime-modules/core/widgets/steps/config.d.ts +8 -3
- package/plugins/runtime-modules/core/widgets/steps/config.js +1 -2
- package/plugins/runtime-modules/core/widgets/steps/plugin.js +6 -30
- package/plugins/runtime-modules/core/widgets/table/client.js +4 -4
- package/plugins/runtime-modules/core/widgets/table/config.d.ts +6 -3
- package/plugins/runtime-modules/core/widgets/table/config.js +4 -1
- package/plugins/runtime-modules/core/widgets/timeline/config.d.ts +8 -1
- package/plugins/runtime-modules/core/widgets/timeline/config.js +1 -2
- package/plugins/runtime-modules/core/widgets/timeline/plugin.js +6 -37
- package/plugins/runtime-modules/descriptor-compiler.d.ts +11 -1
- package/plugins/runtime-modules/descriptor-compiler.js +49 -8
- package/plugins/runtime-modules/groups/definition.d.ts +1 -1
- package/plugins/runtime-modules/groups/forms.d.ts +18 -0
- package/plugins/runtime-modules/groups/forms.js +2 -2
- package/plugins/runtime-modules/groups/trees/phi-default-admin-groups-page-tree.js +8 -4
- package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -0
- package/plugins/runtime-modules/localization/trees/phi-default-editor-translations-page-tree.js +3 -0
- package/plugins/runtime-modules/page-preset-overlays.d.ts +18 -0
- package/plugins/runtime-modules/page-preset-overlays.js +70 -0
- package/plugins/runtime-modules/public/module.d.ts +1 -1
- package/plugins/runtime-modules/public/trees/phi-default-pub-welcome-page-tree.js +1 -0
- package/plugins/runtime-modules/resolver.js +5 -0
- package/plugins/runtime-modules/revisions/trees/phi-default-builder-revisions-page-tree.js +5 -2
- package/plugins/runtime-modules/search/widgets/search-box/server.js +3 -5
- package/plugins/runtime-modules/search/widgets/search-results/server.js +3 -5
- package/plugins/runtime-modules/theme/trees/phi-default-builder-theme-page-tree.js +4 -0
- package/plugins/runtime-modules/threads/trees/phi-default-threads-page-tree.js +6 -2
- package/plugins/runtime-modules/user-management/controller/client.js +6 -1
- package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +5 -3
- package/runtime-render-client.d.ts +1 -1
- package/runtime-render-client.js +2 -1
- package/server-helpers/cms-page-record.d.ts +2 -2
- package/server-helpers/cms-page-record.js +15 -5
- package/server-helpers/cms-request.js +34 -12
- package/server-helpers/cms-widget-texts.d.ts +14 -0
- package/server-helpers/cms-widget-texts.js +117 -0
- package/server-helpers/record-fields.d.ts +1 -1
- package/server-helpers/record-fields.js +1 -2
- package/server-helpers/record-samples.d.ts +4 -4
- package/server-helpers/record-samples.js +10 -2
- package/server-helpers/search-index.js +12 -3
- package/styles/root.css +6 -2
- package/types/cms-module-descriptors.d.ts +3 -0
- package/types/cms-plugins.d.ts +38 -5
- package/types/collection-provider.d.ts +7 -0
- package/types/core-widget-placements.d.ts +37 -0
- package/types/record-provider.d.ts +19 -3
- package/types/slot-size-policy.d.ts +19 -2
- package/types/table-widget.d.ts +33 -1
- package/types/table-widget.js +1 -0
- package/types/tree-widget.d.ts +7 -0
- package/types/widget-runtime.d.ts +1 -1
- package/types.d.ts +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PhiCmsConfigField, PhiCmsWidgetConfigText } from "../types/cms-plugins";
|
|
2
|
+
/**
|
|
3
|
+
* Which of a Widget's config fields are words a reader reads, and so are translated.
|
|
4
|
+
*
|
|
5
|
+
* The name answers it: a field called `label`, `title` or `placeholder` -- or one that ends in `Label`,
|
|
6
|
+
* `Title`, `Placeholder` or `Description` -- holds text, and nothing else does. `key`, `value`, `format`
|
|
7
|
+
* or `timeZone` are what the Widget works with, and translating them would break it. A Widget does not
|
|
8
|
+
* declare its texts one by one, so a new Widget whose label is called `label` is translated without
|
|
9
|
+
* anybody remembering to say so; the few fields the name gets wrong say otherwise on the field (`text`).
|
|
10
|
+
*
|
|
11
|
+
* The register is the translator's context: a label is a noun phrase on a control (`Web UI label`), a
|
|
12
|
+
* description a sentence (`Web UI message`), so a translator neither clips the one nor pads the other.
|
|
13
|
+
*/
|
|
14
|
+
export type PhiConfigTextRegister = "label" | "message";
|
|
15
|
+
/** The register a field's name gives it, or null where the name says it is not text. */
|
|
16
|
+
export declare function readPhiConfigTextRegisterByName(key: string): PhiConfigTextRegister | null;
|
|
17
|
+
/**
|
|
18
|
+
* The register of one config field, or null where it is not translated: a `string` field by its name
|
|
19
|
+
* unless the field states `text`, every other type never -- a link, an icon or a choice stores what it
|
|
20
|
+
* means, not what it says.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readPhiConfigFieldTextRegister(field: PhiCmsConfigField): PhiConfigTextRegister | null;
|
|
23
|
+
/** One text a config holds: where it stands, and how a translator is told to read it. */
|
|
24
|
+
export type PhiConfigTextLocation = {
|
|
25
|
+
/** Keys and list positions from the config's root, ending at the text. */
|
|
26
|
+
path: readonly (string | number)[];
|
|
27
|
+
register: PhiConfigTextRegister;
|
|
28
|
+
text: string;
|
|
29
|
+
/** What stands in the text as `%1` onwards, filled after the translation. */
|
|
30
|
+
values?: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Every non-empty text a config holds, in field order: the fields themselves and, inside a
|
|
34
|
+
* `collection`, each entry's -- a select's options are its `options[].label`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function collectPhiConfigTexts(fields: readonly PhiCmsConfigField[], config: Readonly<Record<string, unknown>>, prefix?: readonly (string | number)[]): PhiConfigTextLocation[];
|
|
37
|
+
/**
|
|
38
|
+
* The texts a Widget declares beyond its fields (`configTexts`): a key's text, or each list entry's, with
|
|
39
|
+
* the entry's values beside it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function collectPhiDeclaredConfigTexts(declarations: readonly PhiCmsWidgetConfigText[], config: Readonly<Record<string, unknown>>): PhiConfigTextLocation[];
|
|
42
|
+
/**
|
|
43
|
+
* The config with each located text replaced by its answer, copied only along the paths written; an
|
|
44
|
+
* empty answer keeps the text as written.
|
|
45
|
+
*/
|
|
46
|
+
export declare function writePhiConfigTexts(config: Readonly<Record<string, unknown>>, answers: ReadonlyArray<{
|
|
47
|
+
path: readonly (string | number)[];
|
|
48
|
+
text: string;
|
|
49
|
+
}>): Record<string, unknown>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isPhiRecord } from "./is-record";
|
|
2
|
+
const TEXT_FIELD_NAMES = {
|
|
3
|
+
label: "label",
|
|
4
|
+
title: "label",
|
|
5
|
+
subtitle: "label",
|
|
6
|
+
placeholder: "label",
|
|
7
|
+
tooltip: "label",
|
|
8
|
+
eyebrow: "label",
|
|
9
|
+
footer: "label",
|
|
10
|
+
alt: "label",
|
|
11
|
+
description: "message",
|
|
12
|
+
};
|
|
13
|
+
const TEXT_FIELD_SUFFIXES = [
|
|
14
|
+
["Label", "label"],
|
|
15
|
+
["Title", "label"],
|
|
16
|
+
["Placeholder", "label"],
|
|
17
|
+
["Description", "message"],
|
|
18
|
+
];
|
|
19
|
+
/** The register a field's name gives it, or null where the name says it is not text. */
|
|
20
|
+
export function readPhiConfigTextRegisterByName(key) {
|
|
21
|
+
const exact = TEXT_FIELD_NAMES[key];
|
|
22
|
+
if (exact)
|
|
23
|
+
return exact;
|
|
24
|
+
for (const [suffix, register] of TEXT_FIELD_SUFFIXES) {
|
|
25
|
+
if (key.length > suffix.length && key.endsWith(suffix))
|
|
26
|
+
return register;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The register of one config field, or null where it is not translated: a `string` field by its name
|
|
32
|
+
* unless the field states `text`, every other type never -- a link, an icon or a choice stores what it
|
|
33
|
+
* means, not what it says.
|
|
34
|
+
*/
|
|
35
|
+
export function readPhiConfigFieldTextRegister(field) {
|
|
36
|
+
if (field.type !== "string")
|
|
37
|
+
return null;
|
|
38
|
+
if (field.text !== undefined)
|
|
39
|
+
return field.text === false ? null : field.text;
|
|
40
|
+
return readPhiConfigTextRegisterByName(field.key);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Every non-empty text a config holds, in field order: the fields themselves and, inside a
|
|
44
|
+
* `collection`, each entry's -- a select's options are its `options[].label`.
|
|
45
|
+
*/
|
|
46
|
+
export function collectPhiConfigTexts(fields, config, prefix = []) {
|
|
47
|
+
const found = [];
|
|
48
|
+
for (const field of fields) {
|
|
49
|
+
const value = config[field.key];
|
|
50
|
+
if (field.type === "collection") {
|
|
51
|
+
if (!Array.isArray(value))
|
|
52
|
+
continue;
|
|
53
|
+
value.forEach((item, index) => {
|
|
54
|
+
if (isPhiRecord(item)) {
|
|
55
|
+
found.push(...collectPhiConfigTexts(field.itemFields, item, [...prefix, field.key, index]));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const register = readPhiConfigFieldTextRegister(field);
|
|
61
|
+
if (register && typeof value === "string" && value.trim()) {
|
|
62
|
+
found.push({ path: [...prefix, field.key], register, text: value });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The texts a Widget declares beyond its fields (`configTexts`): a key's text, or each list entry's, with
|
|
69
|
+
* the entry's values beside it.
|
|
70
|
+
*/
|
|
71
|
+
export function collectPhiDeclaredConfigTexts(declarations, config) {
|
|
72
|
+
const found = [];
|
|
73
|
+
for (const declaration of declarations) {
|
|
74
|
+
const value = config[declaration.key];
|
|
75
|
+
if (declaration.item === undefined) {
|
|
76
|
+
if (typeof value === "string" && value.trim()) {
|
|
77
|
+
found.push({ path: [declaration.key], register: declaration.register, text: value });
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!Array.isArray(value))
|
|
82
|
+
continue;
|
|
83
|
+
value.forEach((entry, index) => {
|
|
84
|
+
if (!isPhiRecord(entry))
|
|
85
|
+
return;
|
|
86
|
+
const text = entry[declaration.item];
|
|
87
|
+
if (typeof text !== "string" || !text.trim())
|
|
88
|
+
return;
|
|
89
|
+
const values = declaration.values ? entry[declaration.values] : undefined;
|
|
90
|
+
found.push({
|
|
91
|
+
path: [declaration.key, index, declaration.item],
|
|
92
|
+
register: declaration.register,
|
|
93
|
+
text,
|
|
94
|
+
...(Array.isArray(values) ? { values: values.map((entry) => String(entry)) } : {}),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return found;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The config with each located text replaced by its answer, copied only along the paths written; an
|
|
102
|
+
* empty answer keeps the text as written.
|
|
103
|
+
*/
|
|
104
|
+
export function writePhiConfigTexts(config, answers) {
|
|
105
|
+
const root = { ...config };
|
|
106
|
+
for (const { path, text } of answers) {
|
|
107
|
+
if (!text.trim())
|
|
108
|
+
continue;
|
|
109
|
+
let target = root;
|
|
110
|
+
for (let index = 0; index < path.length - 1; index += 1) {
|
|
111
|
+
const step = path[index];
|
|
112
|
+
const current = target[step];
|
|
113
|
+
const copy = Array.isArray(current)
|
|
114
|
+
? [...current]
|
|
115
|
+
: { ...current };
|
|
116
|
+
target[step] = copy;
|
|
117
|
+
target = copy;
|
|
118
|
+
}
|
|
119
|
+
target[path[path.length - 1]] = text;
|
|
120
|
+
}
|
|
121
|
+
return root;
|
|
122
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type PhisPaymentMoney } from "@phis/contracts/payments";
|
|
2
|
+
/** The largest minor amount the contract carries. */
|
|
3
|
+
export declare const PHI_MINOR_AMOUNT_MAX = "9999999999999999";
|
|
4
|
+
/** The currency's exponent, or `undefined` for a code that is not an ISO 4217 currency a payment accepts. */
|
|
5
|
+
export declare function readPhiCurrencyExponent(currency: string): number | undefined;
|
|
6
|
+
export declare function isPhiMinorAmount(value: unknown): value is string;
|
|
7
|
+
/**
|
|
8
|
+
* A value a Provider handed over as an amount of money, or `null` where it is none: `{ currency, minor }`
|
|
9
|
+
* with a currency a payment accepts and `minor` as the contract writes it or as a safe non-negative
|
|
10
|
+
* integer, which is how a row out of JSON often carries it. The answer is always the contract's shape.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readPhiMoneyValue(value: unknown): PhisPaymentMoney | null;
|
|
13
|
+
/** `-1`, `0` or `1` as `left` is less than, equal to or more than `right`; both minor amounts. */
|
|
14
|
+
export declare function comparePhiMinorAmounts(left: string, right: string): number;
|
|
15
|
+
/**
|
|
16
|
+
* A major amount written with a point (`"19.9"`, `"19."`, `".5"`) as the minor amount it states, or
|
|
17
|
+
* `null` where it states none or one the contract cannot carry.
|
|
18
|
+
*
|
|
19
|
+
* A fraction longer than the currency has is rounded half up on its digits, the way the Control rounds
|
|
20
|
+
* it when the field is left: `"12.345"` francs are `"1235"` Rappen.
|
|
21
|
+
*/
|
|
22
|
+
export declare function phiMajorToMinorAmount(major: string, exponent: number): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* A major amount (`"1234.5"`) written the way the locale writes it, with as many places as the currency
|
|
25
|
+
* has: `1’234.50` in de-CH, `1.234,50` in de-DE, `1,234.50` in en.
|
|
26
|
+
*
|
|
27
|
+
* The whole part is formatted as a `bigint`, so no digit passes through a float; the fraction is the
|
|
28
|
+
* amount's own digits behind the locale's separator. What is not a major amount is returned as it came.
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatPhiMajorAmount(major: string, locale: string, exponent: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* What somebody typed, in the locale's way of writing numbers, as a major amount with a point.
|
|
33
|
+
*
|
|
34
|
+
* Group separators and spaces are dropped. The decimal separator is the locale's, and the point or the
|
|
35
|
+
* comma is read as one too wherever the locale does not group with it: somebody in fr-CH who types
|
|
36
|
+
* `12.50` means twelve and a half, while in de-DE `1.250` is one thousand two hundred and fifty, as it
|
|
37
|
+
* would be written there. The result may still not be a number -- `"1.2.3"` -- and the Control then
|
|
38
|
+
* keeps the last amount it could read.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parsePhiLocaleAmount(text: string, locale: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Where the currency stands beside the number in the locale, and as what: its ISO code, which no
|
|
43
|
+
* reader confuses with another currency's the way `$` is confused, and which nobody translates.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolvePhiCurrencyAffix(locale: string, currency: string): {
|
|
46
|
+
placement: "prefix" | "suffix";
|
|
47
|
+
text: string;
|
|
48
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { PHIS_PAYMENT_CURRENCY_EXPONENTS, phisMinorToMajorAmount } from "@phis/contracts/payments";
|
|
2
|
+
/*
|
|
3
|
+
* An amount of money as the contract keeps it and as a person reads it.
|
|
4
|
+
*
|
|
5
|
+
* The contract keeps minor units as a canonical integer string (`PhisPaymentMoney.minor`: `"1990"` for
|
|
6
|
+
* 19.90 francs), and a person reads major units written the way their language writes numbers. Between
|
|
7
|
+
* the two lies a power of ten that is the currency's (`PHIS_PAYMENT_CURRENCY_EXPONENTS`: two for the
|
|
8
|
+
* franc, none for the yen, three for the dinar) -- never a fixed hundred.
|
|
9
|
+
*
|
|
10
|
+
* Every conversion here is done on the digits. `12.35 * 100` is `1234.9999999999998` in a float, and a
|
|
11
|
+
* price rounded down by one Rappen on every save is not a rounding error anybody notices until the
|
|
12
|
+
* books do not add up. So a major amount is split at its point, the fraction padded to the exponent,
|
|
13
|
+
* and the digits joined; nothing is multiplied. The way back, and showing an amount as money, are the
|
|
14
|
+
* contract's (`phisMinorToMajorAmount`, `formatPhisMoney` in `@phis/contracts/payments`), so that a
|
|
15
|
+
* Table, a record and a shop write the same amount the same way.
|
|
16
|
+
*/
|
|
17
|
+
/** A minor amount as phis-server accepts one (`requirePhisPaymentMinor`): no sign, no leading zero, 16 digits at most. */
|
|
18
|
+
const PHI_MINOR_AMOUNT_PATTERN = /^(0|[1-9][0-9]{0,15})$/u;
|
|
19
|
+
/** The largest minor amount the contract carries. */
|
|
20
|
+
export const PHI_MINOR_AMOUNT_MAX = "9999999999999999";
|
|
21
|
+
const PHI_MAJOR_AMOUNT_PATTERN = /^([0-9]*)(?:\.([0-9]*))?$/u;
|
|
22
|
+
/** The currency's exponent, or `undefined` for a code that is not an ISO 4217 currency a payment accepts. */
|
|
23
|
+
export function readPhiCurrencyExponent(currency) {
|
|
24
|
+
return Object.hasOwn(PHIS_PAYMENT_CURRENCY_EXPONENTS, currency) ? PHIS_PAYMENT_CURRENCY_EXPONENTS[currency] : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function isPhiMinorAmount(value) {
|
|
27
|
+
return typeof value === "string" && PHI_MINOR_AMOUNT_PATTERN.test(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A value a Provider handed over as an amount of money, or `null` where it is none: `{ currency, minor }`
|
|
31
|
+
* with a currency a payment accepts and `minor` as the contract writes it or as a safe non-negative
|
|
32
|
+
* integer, which is how a row out of JSON often carries it. The answer is always the contract's shape.
|
|
33
|
+
*/
|
|
34
|
+
export function readPhiMoneyValue(value) {
|
|
35
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
36
|
+
return null;
|
|
37
|
+
const { currency, minor } = value;
|
|
38
|
+
if (typeof currency !== "string" || readPhiCurrencyExponent(currency) === undefined)
|
|
39
|
+
return null;
|
|
40
|
+
const text = typeof minor === "number" && Number.isSafeInteger(minor) && minor >= 0 ? String(minor) : minor;
|
|
41
|
+
return isPhiMinorAmount(text) ? { currency, minor: text } : null;
|
|
42
|
+
}
|
|
43
|
+
/** `-1`, `0` or `1` as `left` is less than, equal to or more than `right`; both minor amounts. */
|
|
44
|
+
export function comparePhiMinorAmounts(left, right) {
|
|
45
|
+
const difference = BigInt(left) - BigInt(right);
|
|
46
|
+
return difference < 0n ? -1 : difference > 0n ? 1 : 0;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A major amount written with a point (`"19.9"`, `"19."`, `".5"`) as the minor amount it states, or
|
|
50
|
+
* `null` where it states none or one the contract cannot carry.
|
|
51
|
+
*
|
|
52
|
+
* A fraction longer than the currency has is rounded half up on its digits, the way the Control rounds
|
|
53
|
+
* it when the field is left: `"12.345"` francs are `"1235"` Rappen.
|
|
54
|
+
*/
|
|
55
|
+
export function phiMajorToMinorAmount(major, exponent) {
|
|
56
|
+
const match = PHI_MAJOR_AMOUNT_PATTERN.exec(major.trim());
|
|
57
|
+
if (!match)
|
|
58
|
+
return null;
|
|
59
|
+
const whole = match[1] ?? "";
|
|
60
|
+
const fraction = match[2] ?? "";
|
|
61
|
+
if (whole === "" && fraction === "")
|
|
62
|
+
return null;
|
|
63
|
+
const kept = fraction.slice(0, exponent).padEnd(exponent, "0");
|
|
64
|
+
const roundsUp = fraction.length > exponent && fraction.charCodeAt(exponent) >= "5".charCodeAt(0);
|
|
65
|
+
const minor = (BigInt(`${whole}${kept}` || "0") + (roundsUp ? 1n : 0n)).toString();
|
|
66
|
+
return PHI_MINOR_AMOUNT_PATTERN.test(minor) ? minor : null;
|
|
67
|
+
}
|
|
68
|
+
const symbolsByLocale = new Map();
|
|
69
|
+
/** The locale's decimal and group separators, in Latin digits so that what is typed can be read back. */
|
|
70
|
+
function readPhiAmountSymbols(locale) {
|
|
71
|
+
const cached = symbolsByLocale.get(locale);
|
|
72
|
+
if (cached)
|
|
73
|
+
return cached;
|
|
74
|
+
const parts = new Intl.NumberFormat(locale, { numberingSystem: "latn" }).formatToParts(1234567.5);
|
|
75
|
+
const symbols = {
|
|
76
|
+
decimal: parts.find((part) => part.type === "decimal")?.value ?? ".",
|
|
77
|
+
group: parts.find((part) => part.type === "group")?.value ?? "",
|
|
78
|
+
};
|
|
79
|
+
symbolsByLocale.set(locale, symbols);
|
|
80
|
+
return symbols;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A major amount (`"1234.5"`) written the way the locale writes it, with as many places as the currency
|
|
84
|
+
* has: `1’234.50` in de-CH, `1.234,50` in de-DE, `1,234.50` in en.
|
|
85
|
+
*
|
|
86
|
+
* The whole part is formatted as a `bigint`, so no digit passes through a float; the fraction is the
|
|
87
|
+
* amount's own digits behind the locale's separator. What is not a major amount is returned as it came.
|
|
88
|
+
*/
|
|
89
|
+
export function formatPhiMajorAmount(major, locale, exponent) {
|
|
90
|
+
const minor = phiMajorToMinorAmount(major, exponent);
|
|
91
|
+
if (minor === null)
|
|
92
|
+
return major;
|
|
93
|
+
const [whole = "0", fraction = ""] = phisMinorToMajorAmount(minor, exponent).split(".");
|
|
94
|
+
const formattedWhole = new Intl.NumberFormat(locale, { numberingSystem: "latn", maximumFractionDigits: 0 }).format(BigInt(whole));
|
|
95
|
+
return exponent === 0 ? formattedWhole : `${formattedWhole}${readPhiAmountSymbols(locale).decimal}${fraction}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* What somebody typed, in the locale's way of writing numbers, as a major amount with a point.
|
|
99
|
+
*
|
|
100
|
+
* Group separators and spaces are dropped. The decimal separator is the locale's, and the point or the
|
|
101
|
+
* comma is read as one too wherever the locale does not group with it: somebody in fr-CH who types
|
|
102
|
+
* `12.50` means twelve and a half, while in de-DE `1.250` is one thousand two hundred and fifty, as it
|
|
103
|
+
* would be written there. The result may still not be a number -- `"1.2.3"` -- and the Control then
|
|
104
|
+
* keeps the last amount it could read.
|
|
105
|
+
*/
|
|
106
|
+
export function parsePhiLocaleAmount(text, locale) {
|
|
107
|
+
const { decimal, group } = readPhiAmountSymbols(locale);
|
|
108
|
+
let result = "";
|
|
109
|
+
for (const character of text) {
|
|
110
|
+
if (character >= "0" && character <= "9") {
|
|
111
|
+
result += character;
|
|
112
|
+
}
|
|
113
|
+
else if (character === decimal || ((character === "." || character === ",") && character !== group)) {
|
|
114
|
+
result += ".";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Where the currency stands beside the number in the locale, and as what: its ISO code, which no
|
|
121
|
+
* reader confuses with another currency's the way `$` is confused, and which nobody translates.
|
|
122
|
+
*/
|
|
123
|
+
export function resolvePhiCurrencyAffix(locale, currency) {
|
|
124
|
+
const parts = new Intl.NumberFormat(locale, { style: "currency", currency, currencyDisplay: "code" }).formatToParts(1);
|
|
125
|
+
const currencyIndex = parts.findIndex((part) => part.type === "currency");
|
|
126
|
+
const numberIndex = parts.findIndex((part) => part.type === "integer");
|
|
127
|
+
return {
|
|
128
|
+
placement: currencyIndex !== -1 && numberIndex !== -1 && currencyIndex > numberIndex ? "suffix" : "prefix",
|
|
129
|
+
text: parts[currencyIndex]?.value.trim() || currency,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PhiCmsRegionType } from "../constants/phi-cms";
|
|
2
|
-
import { PHI_SPACE } from "../theme/antd-css-var-contract";
|
|
2
|
+
import { PHI_PAGE, PHI_SPACE } from "../theme/antd-css-var-contract";
|
|
3
3
|
import { parsePhiCmsCarouselLayoutConfig, parsePhiCmsCollapsibleLayoutConfig, parsePhiCmsContentLayoutConfig, parsePhiCmsFlexLayoutConfig, parsePhiCmsFlexVerticalLayoutConfig, parsePhiCmsGridLayoutConfig, parsePhiCmsMasonryLayoutConfig, parsePhiCmsSplitCardLayoutConfig, parsePhiCmsStackLayoutConfig, parsePhiCmsThreeColumnLayoutConfig, } from "../types/cms-config";
|
|
4
4
|
import { readPhiSurface } from "../types/surface";
|
|
5
5
|
const SPACING_KEYS = ["padding", "paddingTop", "paddingRight", "paddingBottom", "paddingLeft", "gap"];
|
|
@@ -22,9 +22,16 @@ const LAYOUT_CONFIG_PARSERS = {
|
|
|
22
22
|
"three-column": parsePhiCmsThreeColumnLayoutConfig,
|
|
23
23
|
"split-card": parsePhiCmsSplitCardLayoutConfig,
|
|
24
24
|
};
|
|
25
|
+
/*
|
|
26
|
+
* The Theme's Page inset (`PHI_PAGE.padding`, THEME.md "Page padding") is a step of the spacing scale per
|
|
27
|
+
* side and screen, chosen by the Theme: a distance like any other, at the preset level.
|
|
28
|
+
*/
|
|
29
|
+
const PAGE_INSET_REFERENCES = new Set(Object.values(PHI_PAGE.padding));
|
|
25
30
|
function stepOf(value) {
|
|
26
31
|
if (value === 0 || value === "0")
|
|
27
32
|
return "none";
|
|
33
|
+
if (PAGE_INSET_REFERENCES.has(value))
|
|
34
|
+
return "page";
|
|
28
35
|
for (const [step, reference] of Object.entries(PHI_SPACE)) {
|
|
29
36
|
if (value === reference)
|
|
30
37
|
return step;
|
|
@@ -78,6 +85,12 @@ export function checkPhiPagePresetLayout(tree) {
|
|
|
78
85
|
// A band under the Header keeps its sides on the small step without a Surface; nothing above or below.
|
|
79
86
|
const headerBottomRootId = tree.regions
|
|
80
87
|
.find((region) => region.regionType === PhiCmsRegionType.HeaderBottom)?.rootLayoutNodeId;
|
|
88
|
+
/*
|
|
89
|
+
* An Overlay's footer is the dialog's action row, built by `dialog` on `createPhiCmsPresetNodes` and held
|
|
90
|
+
* to its own contract by the descriptor compiler (OVERLAYS.md, "Structured dialogs"): its inset is the
|
|
91
|
+
* dialog's, not a Page Layout's, so the Surface rule below does not apply to it.
|
|
92
|
+
*/
|
|
93
|
+
const overlayFooterIds = new Set(tree.overlays.flatMap((overlay) => overlay.footerLayoutNodeId == null ? [] : [overlay.footerLayoutNodeId]));
|
|
81
94
|
for (const node of tree.layoutNodes) {
|
|
82
95
|
const config = (node.config ?? {});
|
|
83
96
|
const typeKey = typeKeyOf(node);
|
|
@@ -128,7 +141,7 @@ export function checkPhiPagePresetLayout(tree) {
|
|
|
128
141
|
}
|
|
129
142
|
continue;
|
|
130
143
|
}
|
|
131
|
-
if (!surface && typeKey !== "content") {
|
|
144
|
+
if (!surface && typeKey !== "content" && !overlayFooterIds.has(node.id)) {
|
|
132
145
|
if (hasPadding(config)) {
|
|
133
146
|
findings.push({
|
|
134
147
|
node: nameOf(node),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PhiResolvedCmsPageTree } from "../types/cms";
|
|
2
|
+
/**
|
|
3
|
+
* Whose words a Module's Preset writes, as a check (`helpers/text-source.ts`).
|
|
4
|
+
*
|
|
5
|
+
* A Module's Preset says, of every Widget it fills with text, whose words they are: `textSource:
|
|
6
|
+
* "preset"` for the Module's own -- translated once, in the platform's store, on every installation --
|
|
7
|
+
* or `"site"` for what the Site configured and the Preset only places, such as its contact address.
|
|
8
|
+
* Left unsaid, the words would be translated per Site as if an author had written them, and nobody would
|
|
9
|
+
* notice; that is how the Builder's own Area select came to read "Accounting" in German.
|
|
10
|
+
*
|
|
11
|
+
* Run by a Module over the trees its presets build, in its own verify step, beside the Page rule. A Site's
|
|
12
|
+
* own package does not run it: every word in its Pages is the Site's, which is what no marker means.
|
|
13
|
+
*
|
|
14
|
+
* It reads the config as stated, by the field names alone (`helpers/config-text-fields.ts`), so it needs
|
|
15
|
+
* no Widget definition: a text under a text's name, at the top or inside a list's entries.
|
|
16
|
+
*/
|
|
17
|
+
export type PhiPresetTextSourceFinding = {
|
|
18
|
+
/** The node's label, or its id where it has none. */
|
|
19
|
+
node: string;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function checkPhiPresetTextSources(tree: Pick<PhiResolvedCmsPageTree, "contentWidgets">): PhiPresetTextSourceFinding[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readPhiConfigTextRegisterByName } from "./config-text-fields";
|
|
2
|
+
import { readPhiTextSource } from "./text-source";
|
|
3
|
+
import { PhiCmsFlags } from "../constants/phi-cms";
|
|
4
|
+
import { hasPhiFlag } from "./flags";
|
|
5
|
+
function findTextKey(value, depth = 0) {
|
|
6
|
+
if (depth > 4 || value == null || typeof value !== "object")
|
|
7
|
+
return null;
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
for (const item of value) {
|
|
10
|
+
const found = findTextKey(item, depth + 1);
|
|
11
|
+
if (found)
|
|
12
|
+
return found;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
17
|
+
if (typeof entry === "string" && entry.trim() && readPhiConfigTextRegisterByName(key))
|
|
18
|
+
return key;
|
|
19
|
+
if (Array.isArray(entry)) {
|
|
20
|
+
const found = findTextKey(entry, depth + 1);
|
|
21
|
+
if (found)
|
|
22
|
+
return `${key}[].${found}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export function checkPhiPresetTextSources(tree) {
|
|
28
|
+
const findings = [];
|
|
29
|
+
for (const widget of tree.contentWidgets) {
|
|
30
|
+
if (readPhiTextSource(widget.config.textSource))
|
|
31
|
+
continue;
|
|
32
|
+
// Already in the reader's language, read from a Label Set: nobody translates it.
|
|
33
|
+
if (hasPhiFlag(widget.flags, PhiCmsFlags.NoTranslate))
|
|
34
|
+
continue;
|
|
35
|
+
const key = findTextKey(widget.config);
|
|
36
|
+
if (!key)
|
|
37
|
+
continue;
|
|
38
|
+
findings.push({
|
|
39
|
+
node: widget.label?.trim() || String(widget.id),
|
|
40
|
+
message: `writes text ("${key}") without saying whose words it is: state textSource "preset" for the ` +
|
|
41
|
+
`Module's own words or "site" for what the Site configured.`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return findings;
|
|
45
|
+
}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PhiRuntimeModuleCatalogEntry } from "../types/cms-plugins";
|
|
2
|
+
import type { PhiRuntimeDataProviderKey } from "../types/runtime-data-provider";
|
|
3
|
+
import type { PhiRecordDeclaration, PhiRecordField, PhiRecordFieldKind, PhiRecordFieldValueByKind } from "../types/record-provider";
|
|
2
4
|
/** `value` as a field of `kind`, or `undefined` where it is not one. */
|
|
3
5
|
export declare function readPhiRecordFieldValue<K extends PhiRecordFieldKind>(kind: K, value: unknown): PhiRecordFieldValueByKind[K] | undefined;
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The kinds a line of text can show: a text as it is, a number, a date and an amount of money in the
|
|
8
|
+
* page's language.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PHI_RECORD_TEXT_FIELD_KINDS: readonly ["text", "number", "date", "money"];
|
|
11
|
+
/**
|
|
12
|
+
* A text, number, date or money field as the words a page shows, written for `locale`; a date on the
|
|
13
|
+
* calendar of the Site's `timeZone`, as every other date the page shows (`formatPhiDate`).
|
|
14
|
+
*/
|
|
7
15
|
export declare function formatPhiRecordFieldText(field: Extract<PhiRecordField, {
|
|
8
16
|
kind: (typeof PHI_RECORD_TEXT_FIELD_KINDS)[number];
|
|
9
|
-
}>, locale: string): string;
|
|
17
|
+
}>, locale: string, timeZone: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* The declarations of the `record` Providers these Modules describe, by key: what a render's registry
|
|
20
|
+
* answers a record's fields from (`recordDeclarationsByKey`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildPhiRecordDeclarationsByKey(entries: readonly Pick<PhiRuntimeModuleCatalogEntry, "definition">[]): ReadonlyMap<PhiRuntimeDataProviderKey, PhiRecordDeclaration>;
|
package/helpers/record-fields.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { formatPhisMoney } from "@phis/contracts/payments";
|
|
2
|
+
import { formatPhiDate } from "./format-date-time";
|
|
3
|
+
import { isPhiMinorAmount, readPhiCurrencyExponent } from "./money-amount";
|
|
1
4
|
/*
|
|
2
5
|
* A record field's value, checked against its declared kind (`types/record-provider.ts`).
|
|
3
6
|
*
|
|
@@ -40,6 +43,13 @@ function readLink(value) {
|
|
|
40
43
|
return undefined;
|
|
41
44
|
return typeof value.label === "string" && value.label ? { href, label: value.label } : { href };
|
|
42
45
|
}
|
|
46
|
+
/** The contract's money exactly: a currency a payment accepts and `minor` as an integer string. */
|
|
47
|
+
function readMoney(value) {
|
|
48
|
+
if (!isRecord(value) || typeof value.currency !== "string" || readPhiCurrencyExponent(value.currency) === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return isPhiMinorAmount(value.minor) ? { currency: value.currency, minor: value.minor } : undefined;
|
|
52
|
+
}
|
|
43
53
|
function readAll(value, read) {
|
|
44
54
|
if (!Array.isArray(value))
|
|
45
55
|
return undefined;
|
|
@@ -63,22 +73,37 @@ export function readPhiRecordFieldValue(kind, value) {
|
|
|
63
73
|
return typeof value === "string" && !Number.isNaN(Date.parse(value)) ? value : undefined;
|
|
64
74
|
case "number":
|
|
65
75
|
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
76
|
+
case "money":
|
|
77
|
+
return readMoney(value);
|
|
66
78
|
case "link":
|
|
67
79
|
return readLink(value);
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
/**
|
|
83
|
+
* The kinds a line of text can show: a text as it is, a number, a date and an amount of money in the
|
|
84
|
+
* page's language.
|
|
85
|
+
*/
|
|
86
|
+
export const PHI_RECORD_TEXT_FIELD_KINDS = ["text", "number", "date", "money"];
|
|
87
|
+
/**
|
|
88
|
+
* A text, number, date or money field as the words a page shows, written for `locale`; a date on the
|
|
89
|
+
* calendar of the Site's `timeZone`, as every other date the page shows (`formatPhiDate`).
|
|
90
|
+
*/
|
|
91
|
+
export function formatPhiRecordFieldText(field, locale, timeZone) {
|
|
92
|
+
switch (field.kind) {
|
|
93
|
+
case "text":
|
|
94
|
+
return field.value;
|
|
95
|
+
case "number":
|
|
96
|
+
return new Intl.NumberFormat(locale).format(field.value);
|
|
97
|
+
case "date":
|
|
98
|
+
return formatPhiDate(field.value, locale, timeZone);
|
|
99
|
+
case "money":
|
|
100
|
+
return formatPhisMoney(field.value, locale);
|
|
83
101
|
}
|
|
84
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* The declarations of the `record` Providers these Modules describe, by key: what a render's registry
|
|
105
|
+
* answers a record's fields from (`recordDeclarationsByKey`).
|
|
106
|
+
*/
|
|
107
|
+
export function buildPhiRecordDeclarationsByKey(entries) {
|
|
108
|
+
return new Map(entries.flatMap((entry) => (entry.definition.dataProviders ?? []).flatMap((provider) => provider.kind === "record" && provider.record ? [[provider.key, provider.record]] : [])));
|
|
109
|
+
}
|
package/helpers/text-source.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PhiCmsConfigField } from "../types/cms-plugins";
|
|
1
2
|
/**
|
|
2
3
|
* Whose words a text Widget holds, which decides the store that translates them.
|
|
3
4
|
*
|
|
@@ -11,9 +12,17 @@
|
|
|
11
12
|
* built, so a Preset that translated its words would freeze one locale into the Site's copy.
|
|
12
13
|
*/
|
|
13
14
|
export declare const PHI_TEXT_SOURCE_PRESET: "preset";
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The Site's words written by a Preset: what the Site configured -- its contact address, its name --
|
|
17
|
+
* placed into a Widget by a Module's Preset. Stated, not left out, so that a Module's Preset says of
|
|
18
|
+
* every Widget with text whose words it holds (`helpers/preset-text-source-check.ts`); it is read like
|
|
19
|
+
* no marker at all, and the Site's store translates them.
|
|
20
|
+
*/
|
|
21
|
+
export declare const PHI_TEXT_SOURCE_SITE: "site";
|
|
22
|
+
export type PhiTextSource = typeof PHI_TEXT_SOURCE_PRESET | typeof PHI_TEXT_SOURCE_SITE;
|
|
15
23
|
export declare function readPhiTextSource(value: unknown): PhiTextSource | undefined;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Whether a Builder edit of this field ends the Preset's ownership of the Widget's words: a text
|
|
26
|
+
* field's, or a list's whose entries hold text -- a select's options.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isPhiAuthoredTextField(field: PhiCmsConfigField): boolean;
|
package/helpers/text-source.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readPhiConfigFieldTextRegister } from "./config-text-fields";
|
|
1
2
|
/**
|
|
2
3
|
* Whose words a text Widget holds, which decides the store that translates them.
|
|
3
4
|
*
|
|
@@ -11,10 +12,22 @@
|
|
|
11
12
|
* built, so a Preset that translated its words would freeze one locale into the Site's copy.
|
|
12
13
|
*/
|
|
13
14
|
export const PHI_TEXT_SOURCE_PRESET = "preset";
|
|
15
|
+
/**
|
|
16
|
+
* The Site's words written by a Preset: what the Site configured -- its contact address, its name --
|
|
17
|
+
* placed into a Widget by a Module's Preset. Stated, not left out, so that a Module's Preset says of
|
|
18
|
+
* every Widget with text whose words it holds (`helpers/preset-text-source-check.ts`); it is read like
|
|
19
|
+
* no marker at all, and the Site's store translates them.
|
|
20
|
+
*/
|
|
21
|
+
export const PHI_TEXT_SOURCE_SITE = "site";
|
|
14
22
|
export function readPhiTextSource(value) {
|
|
15
|
-
return value === PHI_TEXT_SOURCE_PRESET ? value : undefined;
|
|
23
|
+
return value === PHI_TEXT_SOURCE_PRESET || value === PHI_TEXT_SOURCE_SITE ? value : undefined;
|
|
16
24
|
}
|
|
17
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Whether a Builder edit of this field ends the Preset's ownership of the Widget's words: a text
|
|
27
|
+
* field's, or a list's whose entries hold text -- a select's options.
|
|
28
|
+
*/
|
|
18
29
|
export function isPhiAuthoredTextField(field) {
|
|
19
|
-
|
|
30
|
+
if (field.type === "collection")
|
|
31
|
+
return field.itemFields.some(isPhiAuthoredTextField);
|
|
32
|
+
return readPhiConfigFieldTextRegister(field) != null;
|
|
20
33
|
}
|
package/module-page-check.d.ts
CHANGED
|
@@ -10,3 +10,4 @@
|
|
|
10
10
|
* No `server-only` here, on purpose: a test in a package loads this door without a mock.
|
|
11
11
|
*/
|
|
12
12
|
export { checkPhiPagePresetLayout, type PhiPageLayoutFinding } from "./helpers/page-layout-check";
|
|
13
|
+
export { checkPhiPresetTextSources, type PhiPresetTextSourceFinding } from "./helpers/preset-text-source-check";
|
package/module-page-check.js
CHANGED