@phis/ui 0.5.4 → 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/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/regions/presets/content-entry-editor-page-tree.js +2 -0
- package/components/regions/presets/content-entry-public-page-trees.js +2 -0
- package/components/widgets/builder/stack-tabs.d.ts +2 -1
- package/components/widgets/builder/stack-tabs.js +18 -2
- package/components/widgets/config/choice-shared.d.ts +0 -48
- package/components/widgets/config/choice-shared.js +0 -1
- package/components/widgets/config/stack-tabs.js +4 -3
- package/helpers/config-text-fields.d.ts +49 -0
- package/helpers/config-text-fields.js +122 -0
- package/helpers/preset-text-source-check.d.ts +22 -0
- package/helpers/preset-text-source-check.js +45 -0
- 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/package.json +1 -1
- 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/trees/phi-default-accounting-page-tree.js +2 -0
- package/plugins/runtime-modules/builder/clients/widget-inspector.js +2 -2
- 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 +11 -0
- 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 +17 -1
- 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 +1 -0
- package/plugins/runtime-modules/core/widgets/checkbox-group/config.d.ts +7 -1
- package/plugins/runtime-modules/core/widgets/checkbox-group/config.js +1 -1
- package/plugins/runtime-modules/core/widgets/description/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/entry-list/config.d.ts +1 -1
- 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/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/image/server.js +5 -9
- package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/markdown-toc/server.js +3 -5
- 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/result/config.d.ts +1 -1
- 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/simple-text/config.d.ts +1 -0
- 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/config.d.ts +0 -1
- package/plugins/runtime-modules/core/widgets/slot-upload/config.js +0 -2
- package/plugins/runtime-modules/core/widgets/slot-upload/plugin.js +2 -4
- package/plugins/runtime-modules/core/widgets/slot-upload/server.d.ts +3 -4
- package/plugins/runtime-modules/core/widgets/slot-upload/server.js +5 -13
- 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 +7 -2
- 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/config.d.ts +3 -0
- package/plugins/runtime-modules/core/widgets/table/config.js +1 -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/groups/trees/phi-default-admin-groups-page-tree.js +2 -0
- 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/trees/phi-default-pub-welcome-page-tree.js +1 -0
- package/plugins/runtime-modules/revisions/trees/phi-default-builder-revisions-page-tree.js +3 -0
- 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 +2 -0
- package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +2 -0
- 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/search-index.js +12 -3
- package/styles/root.css +6 -2
- package/types/cms-plugins.d.ts +30 -5
- package/types/core-widget-placements.d.ts +5 -0
- package/types/slot-size-policy.d.ts +19 -2
|
@@ -58,6 +58,14 @@ export function createPhiLayoutOwnTextTranslator(plugin, node, runtime) {
|
|
|
58
58
|
return texts.map((text, index) => (text.trim() ? translated[index]?.trim() || text : text));
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The tree with its Widgets' words in the reader's language (`server-helpers/cms-widget-texts.ts`),
|
|
63
|
+
* imported lazily as the passes beside it are.
|
|
64
|
+
*/
|
|
65
|
+
async function translatePhiCmsTreeWidgetTexts(tree, registry, runtime) {
|
|
66
|
+
const { translatePhiCmsTreeWidgetTexts: translate } = await import("../../server-helpers/cms-widget-texts");
|
|
67
|
+
return translate(tree, registry, runtime);
|
|
68
|
+
}
|
|
61
69
|
/** Lazily imported for the reason above: the pass is `server-only`, the helpers beside it are not. */
|
|
62
70
|
async function resolvePhiCmsTreeLinkTargets(...args) {
|
|
63
71
|
const { resolvePhiCmsTreeLinkTargets: resolve } = await import("../../server-helpers/cms-link-targets");
|
|
@@ -268,16 +276,17 @@ function buildLayoutTree(tree, blockDefaultsByType) {
|
|
|
268
276
|
});
|
|
269
277
|
}
|
|
270
278
|
export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }) {
|
|
271
|
-
const [featureResolution, links] = await Promise.all([
|
|
279
|
+
const [featureResolution, links, translatedTree] = await Promise.all([
|
|
272
280
|
resolvePhiCmsTreeFeatures(tree, registry, runtime),
|
|
273
281
|
resolvePhiCmsTreeLinkTargets(tree, runtime),
|
|
282
|
+
translatePhiCmsTreeWidgetTexts(tree, registry, runtime),
|
|
274
283
|
]);
|
|
275
284
|
return {
|
|
276
|
-
tree,
|
|
285
|
+
tree: translatedTree,
|
|
277
286
|
runtime,
|
|
278
287
|
registry,
|
|
279
288
|
signalScope,
|
|
280
|
-
createNode: buildLayoutNodeResolver(
|
|
289
|
+
createNode: buildLayoutNodeResolver(translatedTree, registry.widgetBlockDefaultsByType),
|
|
281
290
|
// From the whole tree, not the Overlay alone: a block is a participant when anything in the tree
|
|
282
291
|
// addresses it, and that is the same answer whether the zones render with the page or on demand.
|
|
283
292
|
signalParticipants: resolvePhiTreeSignalParticipants(tree),
|
|
@@ -739,14 +748,15 @@ function renderLayoutNode(node, context) {
|
|
|
739
748
|
return (_jsxs("div", { "data-phi-cms-orphaned-layout": node.widgetType, style: { display: "flex", flexDirection: "column", gap: 21, width: "100%", minWidth: 0 }, children: [diagnostic, orphanedChildren] }));
|
|
740
749
|
}
|
|
741
750
|
export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, regionTypes, stackGap = 21, registry, }) {
|
|
742
|
-
const
|
|
751
|
+
const viewerTree = filterPhiCmsRenderableTreeForViewer({
|
|
743
752
|
tree,
|
|
744
753
|
viewer: runtime.viewer,
|
|
745
754
|
registry,
|
|
746
755
|
});
|
|
747
|
-
const [{ features, failures: featureFailures }, links] = await Promise.all([
|
|
748
|
-
resolvePhiCmsTreeFeatures(
|
|
749
|
-
resolvePhiCmsTreeLinkTargets(
|
|
756
|
+
const [{ features, failures: featureFailures }, links, filteredTree] = await Promise.all([
|
|
757
|
+
resolvePhiCmsTreeFeatures(viewerTree, registry, runtime),
|
|
758
|
+
resolvePhiCmsTreeLinkTargets(viewerTree, runtime),
|
|
759
|
+
translatePhiCmsTreeWidgetTexts(viewerTree, registry, runtime),
|
|
750
760
|
]);
|
|
751
761
|
const signalParticipants = resolvePhiTreeSignalParticipants(filteredTree);
|
|
752
762
|
const allowedRegionTypes = regionTypes ? new Set(regionTypes) : null;
|
|
@@ -96,6 +96,21 @@ export function PhiFlexLayout({ slots, ...layoutProps }) {
|
|
|
96
96
|
function isRenderableSlotChild(child) {
|
|
97
97
|
return child !== null && child !== undefined && child !== false;
|
|
98
98
|
}
|
|
99
|
+
/*
|
|
100
|
+
* Whether a content child takes the rest of the main axis. A child does when it states `rest` and still
|
|
101
|
+
* fills that axis (a stated size makes the axis `fixed`). Where any does, the others that fill the main
|
|
102
|
+
* axis keep their content size on it, so the rest is shared among those that took it and nobody else.
|
|
103
|
+
*/
|
|
104
|
+
const mainAxisHasRestTaker = slots.some((child, index) => {
|
|
105
|
+
if (!isRenderableSlotChild(child) || isFlexSeparatorChild(child)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if ((resolvedSlotStates[index] ?? "expanded") !== "expanded") {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const sizing = resolvePhiLayoutSlotChildSizing(child);
|
|
112
|
+
return sizing.takesRest && (resolvedVertical ? sizing.stretchesBlock : sizing.stretchesInline);
|
|
113
|
+
});
|
|
99
114
|
const renderSlotChild = (child, index) => {
|
|
100
115
|
if (isFlexSeparatorChild(child)) {
|
|
101
116
|
return child;
|
|
@@ -122,7 +137,7 @@ export function PhiFlexLayout({ slots, ...layoutProps }) {
|
|
|
122
137
|
}
|
|
123
138
|
: {};
|
|
124
139
|
if (resolvedVertical) {
|
|
125
|
-
const shouldFillMainAxis = slotSizing.stretchesBlock;
|
|
140
|
+
const shouldFillMainAxis = slotSizing.stretchesBlock && (!mainAxisHasRestTaker || slotSizing.takesRest);
|
|
126
141
|
const shouldFillCrossAxis = slotSizing.stretchesInline;
|
|
127
142
|
return (_jsx("div", { className: phiLayoutSlotClassName(isAuthoringRender), "data-phi-layout-has-content": phiLayoutSlotContentMarker(isAuthoringRender, true), style: {
|
|
128
143
|
flexGrow: shouldFillMainAxis ? 1 : 0,
|
|
@@ -166,7 +181,7 @@ export function PhiFlexLayout({ slots, ...layoutProps }) {
|
|
|
166
181
|
}),
|
|
167
182
|
}, children: child }, `content-${index}`));
|
|
168
183
|
}
|
|
169
|
-
const shouldFillMainAxis = slotSizing.stretchesInline;
|
|
184
|
+
const shouldFillMainAxis = slotSizing.stretchesInline && (!mainAxisHasRestTaker || slotSizing.takesRest);
|
|
170
185
|
const shouldFillCrossAxis = slotSizing.stretchesBlock;
|
|
171
186
|
const minMainSize = slotSizing.minInlineSize;
|
|
172
187
|
const maxMainSize = slotSizing.maxInlineSize;
|
|
@@ -17,6 +17,8 @@ export type PhiLayoutSlotChildSizing = {
|
|
|
17
17
|
*/
|
|
18
18
|
stretchesInline: boolean;
|
|
19
19
|
stretchesBlock: boolean;
|
|
20
|
+
/** The child states `rest`; a Flex Layout also asks whether it still fills its main axis. */
|
|
21
|
+
takesRest: boolean;
|
|
20
22
|
minInlineSize: CSSProperties["minWidth"];
|
|
21
23
|
minBlockSize: CSSProperties["minHeight"];
|
|
22
24
|
maxInlineSize: CSSProperties["maxWidth"];
|
|
@@ -22,6 +22,7 @@ export function resolvePhiLayoutSlotChildSizing(child) {
|
|
|
22
22
|
hasExplicitHeight: slotSizing.explicitBlockSize,
|
|
23
23
|
stretchesInline: slotSizing.policy.inline === "fill",
|
|
24
24
|
stretchesBlock: slotSizing.policy.block === "fill",
|
|
25
|
+
takesRest: slotSizing.policy.takesRest === true,
|
|
25
26
|
minInlineSize: slotSizing.minInlineSize,
|
|
26
27
|
minBlockSize: slotSizing.minBlockSize,
|
|
27
28
|
maxInlineSize: slotSizing.maxInlineSize,
|
|
@@ -90,6 +91,7 @@ export function PhiLayoutAnchoredOverlay({ anchor, slotRole, positionMode = "abs
|
|
|
90
91
|
}, ...buildPhiSlotChildDataAttributes({
|
|
91
92
|
inline: slotSizing.fillInline ? "fill" : "intrinsic",
|
|
92
93
|
block: slotSizing.fillBlock ? "fill" : "intrinsic",
|
|
94
|
+
...(slotSizing.takesRest ? { takesRest: true } : {}),
|
|
93
95
|
}, {
|
|
94
96
|
explicitInlineSize: slotSizing.hasExplicitWidth,
|
|
95
97
|
explicitBlockSize: slotSizing.hasExplicitHeight,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PHI_TEXT_SOURCE_PRESET } from "../../../helpers/text-source";
|
|
1
2
|
import { PHI_CMS_DEFAULT_SLOT_INDEX, PHI_CMS_SEQUENTIAL_LAYOUT_SLOTS, } from "../../../constants/cms-layout-types";
|
|
2
3
|
import { PHI_CORE_RUNTIME_DATA_PROVIDER_KEYS } from "../../../constants/core-data-provider-keys";
|
|
3
4
|
import { canPhiViewerAccess, PHI_VIEWER_ACCESS_PUBLISHING } from "../../../types/access";
|
|
@@ -182,6 +183,7 @@ function buildEntryDialogNodes(nodes, input) {
|
|
|
182
183
|
label: `${input.routePrefix} ${input.key} commands`,
|
|
183
184
|
config: {
|
|
184
185
|
key: `${prefix}-commands`,
|
|
186
|
+
textSource: PHI_TEXT_SOURCE_PRESET,
|
|
185
187
|
...PHI_DIALOG_COMMANDS_CONFIG,
|
|
186
188
|
/*
|
|
187
189
|
* The two buttons as one group, the way every other overlay footer states it: they are the two
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PHI_TEXT_SOURCE_PRESET } from "../../../helpers/text-source";
|
|
1
2
|
import "server-only";
|
|
2
3
|
import { notFound } from "next/navigation";
|
|
3
4
|
import { createPhiPresetCmsInstanceIdMap } from "../../../types/cms-instance-id";
|
|
@@ -129,6 +130,7 @@ export async function buildPhiContentEntryDetailPageTree({ page, runtime, params
|
|
|
129
130
|
config: {
|
|
130
131
|
kind,
|
|
131
132
|
source: "related",
|
|
133
|
+
textSource: PHI_TEXT_SOURCE_PRESET,
|
|
132
134
|
relatedTo: entry,
|
|
133
135
|
presentation: related.presentation,
|
|
134
136
|
...listPartsFor(related.presentation),
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { PhiCmsBuilderWidgetPlugin } from "../../../types";
|
|
1
2
|
import { type PhiCmsTabBarWidgetConfig } from "../config/stack-tabs";
|
|
2
|
-
export declare const PHI_TAB_BAR_WIDGET_BUILDER_PLUGIN:
|
|
3
|
+
export declare const PHI_TAB_BAR_WIDGET_BUILDER_PLUGIN: PhiCmsBuilderWidgetPlugin<PhiCmsTabBarWidgetConfig>;
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createPhiCmsBuilderWidgetPlugin } from "../../../plugins/factories/widget-builder-plugin";
|
|
4
3
|
import { PHI_TAB_BAR_WIDGET_DEFINITION, } from "../config/stack-tabs";
|
|
5
4
|
import { PhiTabBarWidgetClient } from "../client/stack-tabs";
|
|
6
|
-
|
|
5
|
+
import { PhiStaticOptionsToolButton } from "./phi-static-options-picker";
|
|
6
|
+
export const PHI_TAB_BAR_WIDGET_BUILDER_PLUGIN = {
|
|
7
|
+
...PHI_TAB_BAR_WIDGET_DEFINITION,
|
|
8
|
+
renderEditor: ({ config }) => _jsx(PhiTabBarWidgetClient, { config: config }),
|
|
9
|
+
/*
|
|
10
|
+
* Static options only where they are what is drawn: not while a provider answers for them, and not
|
|
11
|
+
* while the tabs are the followed Stack's slots.
|
|
12
|
+
*/
|
|
13
|
+
renderEditorTools: ({ config, authoring }) => authoring?.updateConfig && !config.optionsProvider && config.valueMode !== "stack-slot-index" ? (_jsx(PhiStaticOptionsToolButton, { options: config.options, onApply: (options) => {
|
|
14
|
+
const selectedValue = config.value?.trim();
|
|
15
|
+
authoring.updateConfig?.({
|
|
16
|
+
options,
|
|
17
|
+
...(!selectedValue || options.some((option) => option.value === selectedValue)
|
|
18
|
+
? {}
|
|
19
|
+
: { value: options[0]?.value }),
|
|
20
|
+
});
|
|
21
|
+
} })) : null,
|
|
22
|
+
};
|
|
@@ -64,54 +64,6 @@ export declare function buildPhiChoiceControlOptionFields(editorPlacement?: "ins
|
|
|
64
64
|
emptyLabel?: undefined;
|
|
65
65
|
itemFields?: undefined;
|
|
66
66
|
})[];
|
|
67
|
-
export declare const PHI_CHOICE_CONTROL_OPTION_FIELDS: ({
|
|
68
|
-
key: string;
|
|
69
|
-
type: "collection";
|
|
70
|
-
label: string;
|
|
71
|
-
editorPlacement: "inspector" | "toolbar";
|
|
72
|
-
itemKeyField: string;
|
|
73
|
-
itemLabelField: string;
|
|
74
|
-
defaultItem: {
|
|
75
|
-
value: string;
|
|
76
|
-
label: string;
|
|
77
|
-
};
|
|
78
|
-
addLabel: string;
|
|
79
|
-
emptyLabel: string;
|
|
80
|
-
itemFields: ({
|
|
81
|
-
key: string;
|
|
82
|
-
type: "icon";
|
|
83
|
-
label: string;
|
|
84
|
-
required?: undefined;
|
|
85
|
-
} | {
|
|
86
|
-
key: string;
|
|
87
|
-
type: "string";
|
|
88
|
-
label: string;
|
|
89
|
-
required: true;
|
|
90
|
-
} | {
|
|
91
|
-
key: string;
|
|
92
|
-
type: "string";
|
|
93
|
-
label: string;
|
|
94
|
-
required?: undefined;
|
|
95
|
-
} | {
|
|
96
|
-
key: string;
|
|
97
|
-
type: "boolean";
|
|
98
|
-
label: string;
|
|
99
|
-
required?: undefined;
|
|
100
|
-
})[];
|
|
101
|
-
providerKind?: undefined;
|
|
102
|
-
} | {
|
|
103
|
-
key: string;
|
|
104
|
-
type: "data-provider";
|
|
105
|
-
providerKind: "options";
|
|
106
|
-
label: string;
|
|
107
|
-
editorPlacement?: undefined;
|
|
108
|
-
itemKeyField?: undefined;
|
|
109
|
-
itemLabelField?: undefined;
|
|
110
|
-
defaultItem?: undefined;
|
|
111
|
-
addLabel?: undefined;
|
|
112
|
-
emptyLabel?: undefined;
|
|
113
|
-
itemFields?: undefined;
|
|
114
|
-
})[];
|
|
115
67
|
export declare function parsePhiChoiceOptionsConfig(config: Record<string, unknown>): PhiChoiceOptionsConfig;
|
|
116
68
|
export declare const PHI_CHOICE_CONTROL_CONFIG_FIELDS: ({
|
|
117
69
|
key: string;
|
|
@@ -26,7 +26,6 @@ export function buildPhiChoiceControlOptionFields(editorPlacement = "inspector")
|
|
|
26
26
|
label: "Options Source",
|
|
27
27
|
}];
|
|
28
28
|
}
|
|
29
|
-
export const PHI_CHOICE_CONTROL_OPTION_FIELDS = buildPhiChoiceControlOptionFields();
|
|
30
29
|
export function parsePhiChoiceOptionsConfig(config) {
|
|
31
30
|
const reader = createPhiConfigReader(config);
|
|
32
31
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPhiConfigReader } from "./strict-config-reader";
|
|
2
|
-
import {
|
|
2
|
+
import { buildPhiChoiceControlOptionFields, PHI_CHOICE_CONTROL_CONFIG_FIELDS, PHI_CHOICE_CONTROL_VALUE_MODE_FIELD, parsePhiStackChoiceControlConfig, } from "./choice-shared";
|
|
3
3
|
import { createPhiCmsWidgetDefinition } from "./helpers";
|
|
4
4
|
import { PHI_SELECT_CONTROL_SIGNALS } from "../signals/control-signal-capabilities";
|
|
5
5
|
function parsePhiCmsTabBarWidgetConfig(config) {
|
|
@@ -14,7 +14,7 @@ export const PHI_TAB_BAR_WIDGET_DEFINITION = createPhiCmsWidgetDefinition({
|
|
|
14
14
|
description: "Reusable tab control that emits runtime state signals and can optionally control stack slots.",
|
|
15
15
|
category: "navigation",
|
|
16
16
|
iconFamily: "basic",
|
|
17
|
-
slotSizePolicy: "fill-block",
|
|
17
|
+
slotSizePolicy: { configField: "placement", byValue: { left: "fill-block", right: "fill-block" }, otherwise: "fill-inline" },
|
|
18
18
|
runtimeSignals: {
|
|
19
19
|
...PHI_SELECT_CONTROL_SIGNALS,
|
|
20
20
|
},
|
|
@@ -39,7 +39,8 @@ export const PHI_TAB_BAR_WIDGET_DEFINITION = createPhiCmsWidgetDefinition({
|
|
|
39
39
|
{ value: "right", label: "Right" },
|
|
40
40
|
],
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
/* Edited in the scaffold's dialog, as every choice Widget's static options are. */
|
|
43
|
+
...buildPhiChoiceControlOptionFields("toolbar"),
|
|
43
44
|
...PHI_CHOICE_CONTROL_CONFIG_FIELDS,
|
|
44
45
|
],
|
|
45
46
|
parseConfig: parsePhiCmsTabBarWidgetConfig,
|
|
@@ -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,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
|
+
}
|
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
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@ export function PhiSlotChildFrameView({ kind, slotSizePolicy, surfacePolicy, blo
|
|
|
31
31
|
* whatever reads its attributes, and a frame carrying a width of its own while announcing "fill"
|
|
32
32
|
* makes every reader below it wrong in the same way at once.
|
|
33
33
|
*/
|
|
34
|
-
const policy = resolvePhiEffectiveSlotSizePolicy(resolvePhiSlotSizePolicy(slotSizePolicy, kind), {
|
|
34
|
+
const policy = resolvePhiEffectiveSlotSizePolicy(resolvePhiSlotSizePolicy(slotSizePolicy, kind, config), {
|
|
35
35
|
explicitInlineSize: resolvedExplicitInlineSize,
|
|
36
36
|
explicitBlockSize: resolvedExplicitBlockSize,
|
|
37
37
|
});
|
|
@@ -17,7 +17,11 @@ export type PhiSlotChildSizing = {
|
|
|
17
17
|
*/
|
|
18
18
|
queriesRoom: boolean;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* `config` is the config of the block whose policy this is; a by-config policy reads its field there.
|
|
22
|
+
* A caller without the block's config passes `null` and gets `otherwise`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolvePhiSlotSizePolicy(policy: PhiSlotSizePolicy | null | undefined, kind: PhiSlotChildKind, config: Record<string, unknown> | null | undefined): PhiNormalizedSlotSizePolicy;
|
|
21
25
|
export declare function resolvePhiSlotChildExplicitAxes(geometry: PhiResolvedBlockGeometry): {
|
|
22
26
|
explicitInlineSize: boolean;
|
|
23
27
|
explicitBlockSize: boolean;
|
|
@@ -61,7 +65,8 @@ export declare function resolvePhiSlotChildSizeConstraints(geometry: PhiResolved
|
|
|
61
65
|
* `Cannot assign to read only property 'config'` and take the Widget's whole render with it. The account
|
|
62
66
|
* menu was lost to exactly that shape, from a different source; see the Account Widget plugin.
|
|
63
67
|
*
|
|
64
|
-
*
|
|
68
|
+
* Resolved values carry the same information and share nothing, so there is no reference to fill in.
|
|
69
|
+
* The policy is built here as a plain object, `takesRest` included.
|
|
65
70
|
*/
|
|
66
71
|
export declare function resolvePhiSlotChildSizingForConfig(kind: PhiSlotChildKind, slotSizePolicy: PhiSlotSizePolicy | null | undefined, config: PhiRenderableBlockGeometryInput | null | undefined): PhiSlotChildSizing;
|
|
67
72
|
export declare function buildPhiSlotChildClassName(policy: PhiNormalizedSlotSizePolicy): string;
|
|
@@ -75,6 +80,7 @@ export declare function buildPhiSlotChildDataAttributes(policy: PhiNormalizedSlo
|
|
|
75
80
|
}): {
|
|
76
81
|
"data-phi-slot-size-inline": PhiSlotAxisSizePolicy;
|
|
77
82
|
"data-phi-slot-size-block": PhiSlotAxisSizePolicy;
|
|
83
|
+
"data-phi-slot-rest": string | undefined;
|
|
78
84
|
"data-phi-layout-fill-slot": string | undefined;
|
|
79
85
|
"data-phi-layout-explicit-width": string | undefined;
|
|
80
86
|
"data-phi-layout-explicit-height": string | undefined;
|