@phis/ui 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/cms/phi-cms-layout-renderer.d.ts +1 -0
- package/components/cms/phi-cms-layout-renderer.js +35 -6
- package/components/controls/phi-collection-reorder-context.d.ts +21 -0
- package/components/controls/phi-collection-reorder-context.js +6 -0
- package/components/controls/phi-collection-sortable-layout-control.d.ts +17 -0
- package/components/controls/phi-collection-sortable-layout-control.js +72 -0
- package/components/controls/phi-collection-view-control.d.ts +1 -1
- package/components/controls/phi-collection-view-control.js +15 -1
- package/components/controls/phi-media-asset-tile-control.d.ts +12 -5
- package/components/controls/phi-media-picker-control.d.ts +14 -1
- package/components/controls/phi-media-picker-control.js +11 -2
- package/components/controls/use-phi-color-control-presets.d.ts +2 -2
- package/components/controls/use-phi-color-control-presets.js +16 -2
- package/components/forms/compound-form-controls.d.ts +1 -1
- package/components/forms/compound-form-controls.js +6 -4
- package/components/forms/form-field-labels.d.ts +3 -1
- package/components/forms/form-field-labels.js +19 -6
- package/components/forms/form-provider-contract.js +2 -1
- package/components/forms/media-asset-field-keys.d.ts +4 -1
- package/components/forms/media-asset-field-keys.js +4 -1
- package/components/forms/table-field-keys.d.ts +8 -0
- package/components/forms/table-field-keys.js +8 -0
- package/components/forms/table-field-labels.d.ts +16 -0
- package/components/forms/table-field-labels.js +16 -0
- package/components/forms/table-field-text.d.ts +9 -0
- package/components/forms/table-field-text.js +20 -0
- package/components/forms/upload-field-refusal-labels.d.ts +10 -0
- package/components/forms/upload-field-refusal-labels.js +24 -0
- package/components/forms/upload-form-control.js +3 -16
- package/components/layouts/clients/phi-flex-layout-client.js +12 -2
- package/components/media/media-folder-name-path.d.ts +17 -0
- package/components/media/media-folder-name-path.js +36 -0
- package/components/media/media-upload-flow.d.ts +42 -0
- package/components/media/media-upload-flow.js +120 -4
- package/components/media/media-upload-refusals.js +5 -2
- package/components/media/phi-area-upload-widget.js +4 -0
- package/components/media/phi-media-picker-binding.d.ts +48 -1
- package/components/media/phi-media-picker-binding.js +99 -6
- package/components/media/phi-media-upload.d.ts +7 -1
- package/components/media/phi-media-upload.js +17 -5
- package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
- package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
- package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
- package/components/widgets/client/shared/phi-command-buttons.d.ts +12 -0
- package/components/widgets/client/shared/phi-command-buttons.js +23 -3
- package/components/widgets/config/command-buttons.js +3 -0
- package/components/widgets/label-sets/collection-view.d.ts +4 -0
- package/components/widgets/label-sets/collection-view.js +16 -0
- package/components/widgets/label-sets/color-picker.js +2 -0
- package/components/widgets/label-sets/table.d.ts +6 -0
- package/components/widgets/label-sets/table.js +10 -0
- package/components/widgets/label-types/collection-view.d.ts +8 -0
- package/components/widgets/label-types/collection-view.js +4 -0
- package/components/widgets/label-types/color-picker.d.ts +1 -0
- package/components/widgets/label-types/color-picker.js +1 -0
- package/controls.d.ts +1 -1
- package/helpers/cms-content-binding.d.ts +7 -1
- package/helpers/cms-content-binding.js +10 -2
- package/helpers/cms-node-visibility.d.ts +25 -0
- package/helpers/cms-node-visibility.js +35 -1
- package/package.json +2 -2
- package/plugins/runtime-modules/accounting/definition.js +1 -1
- package/plugins/runtime-modules/accounting/presets.js +5 -12
- package/plugins/runtime-modules/area-definitions.d.ts +9 -39
- package/plugins/runtime-modules/area-definitions.js +8 -8
- package/plugins/runtime-modules/asset/controller/runtime.js +1 -6
- package/plugins/runtime-modules/asset/definition.d.ts +8 -0
- package/plugins/runtime-modules/asset/form-providers.d.ts +8 -0
- package/plugins/runtime-modules/asset/form-providers.js +6 -0
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
- package/plugins/runtime-modules/asset/media-asset-field.js +50 -3
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +13 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +81 -5
- package/plugins/runtime-modules/asset/widgets/area-upload/config.js +7 -1
- package/plugins/runtime-modules/builder/data-providers.js +1 -0
- package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
- package/plugins/runtime-modules/builder/services/runtime-modules-table.d.ts +1 -0
- package/plugins/runtime-modules/builder/services/runtime-modules-table.js +4 -0
- package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +6 -5
- package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +5 -0
- package/plugins/runtime-modules/core/widgets/collection-view/client.js +50 -4
- package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +28 -2
- package/plugins/runtime-modules/core/widgets/collection-view/config.js +13 -0
- package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +4 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.js +19 -4
- package/plugins/runtime-modules/core/widgets/image/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/image/config.js +1 -0
- package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/markdown/config.js +1 -0
- package/plugins/runtime-modules/core/widgets/markdown/plugin.js +0 -1
- package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/simple-text/config.js +1 -0
- package/plugins/runtime-modules/core/widgets/table/client.js +8 -1
- package/server-helpers/cms-node-record.d.ts +18 -0
- package/server-helpers/cms-node-record.js +28 -0
- package/types/cms-plugins.d.ts +6 -0
- package/types/collection-provider.d.ts +7 -0
- package/types/collection-view-widget.d.ts +11 -0
- package/types/core-widget-placements.d.ts +11 -0
- package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.d.ts +0 -6
- package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.js +0 -49
|
@@ -51,6 +51,7 @@ export type PhiCmsOverlayRenderContext = {
|
|
|
51
51
|
signalRuntime: PhiRenderableBlockRuntime;
|
|
52
52
|
features: PhiRuntimeFeatureState | null;
|
|
53
53
|
featureFailures: ReadonlyMap<string, string>;
|
|
54
|
+
recordFields: Readonly<Record<string, unknown>> | null;
|
|
54
55
|
links: Awaited<ReturnType<typeof resolvePhiCmsTreeLinkTargets>>;
|
|
55
56
|
};
|
|
56
57
|
export declare function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }: {
|
|
@@ -20,7 +20,7 @@ import { splitPhiCmsLayoutNamespacedTypeKey } from "../../constants/cms-layout-t
|
|
|
20
20
|
import { createPhiSignalAddress, readPhiSignalRouteSet, } from "../../types/signals";
|
|
21
21
|
import { readPhiRuntimeTreeRenderMode, resolvePhiRuntimeWidgetImplementationMode, } from "../../plugins/runtime-modules/render-mode";
|
|
22
22
|
import { filterPhiCmsRenderableTreeForViewer } from "../../helpers/cms-access-policy";
|
|
23
|
-
import { collectPhiCmsNodeFeatureNamespaces, readPhiCmsNodeVisibleWhen, readPhiCmsServerPageConditionState, resolvePhiCmsNodeVisibility, } from "../../helpers/cms-node-visibility";
|
|
23
|
+
import { collectPhiCmsNodeFeatureNamespaces, readPhiCmsNodeVisibleWhen, readPhiCmsServerPageConditionState, resolvePhiCmsNodeVisibility, settlePhiCmsNodeRecordConditions, } from "../../helpers/cms-node-visibility";
|
|
24
24
|
import { logRuntimeEvent } from "../../net/log";
|
|
25
25
|
import { PhiCmsNodeVisibilityGate } from "./clients/phi-cms-node-visibility-gate";
|
|
26
26
|
import { PhiRuntimeModuleRenderClientHost } from "../runtime/runtime-module-render-client-manifest";
|
|
@@ -39,6 +39,11 @@ async function resolvePhiCmsTreeFeatures(...args) {
|
|
|
39
39
|
const { resolvePhiCmsTreeFeatures: resolve } = await import("../../server-helpers/cms-node-features");
|
|
40
40
|
return resolve(...args);
|
|
41
41
|
}
|
|
42
|
+
/* The fields a `record` condition reads, loaded the same way and for the same reason. */
|
|
43
|
+
async function resolvePhiCmsTreeRecordConditionFields(...args) {
|
|
44
|
+
const { resolvePhiCmsTreeRecordConditionFields: resolve } = await import("../../server-helpers/cms-node-record");
|
|
45
|
+
return resolve(...args);
|
|
46
|
+
}
|
|
42
47
|
/**
|
|
43
48
|
* What a Layout that `translatesOwnText` is handed to translate the text in its config with -- the
|
|
44
49
|
* Collapsible's panel titles. The node's `NoTranslate` flag is the switch, as for a Widget, and the
|
|
@@ -285,8 +290,9 @@ function buildLayoutTree(tree, blockDefaultsByType) {
|
|
|
285
290
|
});
|
|
286
291
|
}
|
|
287
292
|
export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }) {
|
|
288
|
-
const [featureResolution, links, translatedTree] = await Promise.all([
|
|
293
|
+
const [featureResolution, recordFields, links, translatedTree] = await Promise.all([
|
|
289
294
|
resolvePhiCmsTreeFeatures(tree, registry, runtime),
|
|
295
|
+
resolvePhiCmsTreeRecordConditionFields(tree, registry, runtime),
|
|
290
296
|
resolvePhiCmsTreeLinkTargets(tree, runtime),
|
|
291
297
|
translatePhiCmsTreeWidgetTexts(tree, registry, runtime),
|
|
292
298
|
]);
|
|
@@ -308,6 +314,7 @@ export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registr
|
|
|
308
314
|
},
|
|
309
315
|
features: featureResolution.features,
|
|
310
316
|
featureFailures: featureResolution.failures,
|
|
317
|
+
recordFields,
|
|
311
318
|
links,
|
|
312
319
|
};
|
|
313
320
|
}
|
|
@@ -340,6 +347,7 @@ export function renderPhiCmsOverlayZones(context, overlay) {
|
|
|
340
347
|
signalParticipants,
|
|
341
348
|
features: context.features,
|
|
342
349
|
featureFailures: context.featureFailures,
|
|
350
|
+
recordFields: context.recordFields,
|
|
343
351
|
links: context.links,
|
|
344
352
|
}), {
|
|
345
353
|
kind: "layout",
|
|
@@ -418,7 +426,11 @@ function renderContentWidget(widget, context) {
|
|
|
418
426
|
: null;
|
|
419
427
|
const widgetPlugin = runtimePlugin ?? previewPlugin;
|
|
420
428
|
// Bound content that was never published is not on the live Site, and neither is its Widget.
|
|
421
|
-
if (renderMode === "live" &&
|
|
429
|
+
if (renderMode === "live" &&
|
|
430
|
+
widgetPlugin &&
|
|
431
|
+
isPhiCmsWidgetContentUnpublished(widgetPlugin.contentBinding, widget, {
|
|
432
|
+
aboutRecord: context.runtime.page?.record != null,
|
|
433
|
+
})) {
|
|
422
434
|
return null;
|
|
423
435
|
}
|
|
424
436
|
if (widgetPlugin) {
|
|
@@ -568,13 +580,26 @@ function wrapPhiRenderedSlotChild(node, options) {
|
|
|
568
580
|
slotChildSizing: resolvePhiSlotChildSizingForConfig(options.kind, options.slotSizePolicy, options.config), visibleWhen: options.visibleWhen, receiver: options.blockId != null ? createPhiSignalAddress("cms", options.blockId) : null, page: options.page ?? null, features: options.features ?? null, children: framed }, options.key))
|
|
569
581
|
: framed;
|
|
570
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* A child's condition with its `record` parts answered here (`settlePhiCmsNodeRecordConditions`), or
|
|
585
|
+
* `false` where they already rule the child out. The live Site leaves out a node that asks about a record
|
|
586
|
+
* the Page is not about; a Preview or the canvas draws it.
|
|
587
|
+
*/
|
|
588
|
+
function readRenderedChildVisibleWhen(child, context) {
|
|
589
|
+
return settlePhiCmsNodeRecordConditions(readPhiCmsNodeVisibleWhen(child.config), {
|
|
590
|
+
fields: context.recordFields,
|
|
591
|
+
live: readPhiRuntimeTreeRenderMode(child.config) === "live",
|
|
592
|
+
});
|
|
593
|
+
}
|
|
571
594
|
function buildRenderedChildEntries(node, context) {
|
|
572
595
|
const page = readPhiCmsServerPageConditionState(context.runtime);
|
|
573
596
|
const features = context.features;
|
|
574
597
|
const failures = context.featureFailures;
|
|
575
598
|
return [
|
|
576
599
|
...node.childLayouts.flatMap((child) => {
|
|
577
|
-
const visibleWhen =
|
|
600
|
+
const visibleWhen = readRenderedChildVisibleWhen(child, context);
|
|
601
|
+
if (visibleWhen === false)
|
|
602
|
+
return [];
|
|
578
603
|
const visibility = resolvePhiCmsNodeVisibility(visibleWhen, page, features);
|
|
579
604
|
if (visibility === "omit")
|
|
580
605
|
return [];
|
|
@@ -614,7 +639,9 @@ function buildRenderedChildEntries(node, context) {
|
|
|
614
639
|
}];
|
|
615
640
|
}),
|
|
616
641
|
...node.childWidgets.flatMap((child) => {
|
|
617
|
-
const visibleWhen =
|
|
642
|
+
const visibleWhen = readRenderedChildVisibleWhen(child, context);
|
|
643
|
+
if (visibleWhen === false)
|
|
644
|
+
return [];
|
|
618
645
|
const visibility = resolvePhiCmsNodeVisibility(visibleWhen, page, features);
|
|
619
646
|
if (visibility === "omit")
|
|
620
647
|
return [];
|
|
@@ -762,8 +789,9 @@ export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, reg
|
|
|
762
789
|
viewer: runtime.viewer,
|
|
763
790
|
registry,
|
|
764
791
|
});
|
|
765
|
-
const [{ features, failures: featureFailures }, links, filteredTree] = await Promise.all([
|
|
792
|
+
const [{ features, failures: featureFailures }, recordFields, links, filteredTree] = await Promise.all([
|
|
766
793
|
resolvePhiCmsTreeFeatures(viewerTree, registry, runtime),
|
|
794
|
+
resolvePhiCmsTreeRecordConditionFields(viewerTree, registry, runtime),
|
|
767
795
|
resolvePhiCmsTreeLinkTargets(viewerTree, runtime),
|
|
768
796
|
translatePhiCmsTreeWidgetTexts(viewerTree, registry, runtime),
|
|
769
797
|
]);
|
|
@@ -798,6 +826,7 @@ export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, reg
|
|
|
798
826
|
signalParticipants,
|
|
799
827
|
features,
|
|
800
828
|
featureFailures,
|
|
829
|
+
recordFields,
|
|
801
830
|
links,
|
|
802
831
|
}), {
|
|
803
832
|
kind: "layout",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag reordering of the items a Collection draws, offered by the `collection-view` Widget around
|
|
3
|
+
* whatever renderer draws them.
|
|
4
|
+
*
|
|
5
|
+
* The renderer -- the Provider's Render Client or one a Site chose (`itemRendererKey`) -- lays its items
|
|
6
|
+
* out through `PhiCollectionViewControl`, and that is where each of them gets a drag handle: the
|
|
7
|
+
* renderer is not touched and does not know. `itemKeys` are the keys of the items in the order the
|
|
8
|
+
* renderer draws them, one per item; where the renderer draws another number of items than there are
|
|
9
|
+
* keys, the Control cannot tell which is which and offers no reordering.
|
|
10
|
+
*/
|
|
11
|
+
export type PhiCollectionReorderContextValue = {
|
|
12
|
+
itemKeys: readonly (string | number)[];
|
|
13
|
+
/** Every key in the new order, once an item was dropped somewhere else. */
|
|
14
|
+
onReorder: (itemKeys: (string | number)[]) => void;
|
|
15
|
+
/** True while an order is being written; nothing is dragged meanwhile. */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** The drag handle's name for assistive technology. */
|
|
18
|
+
handleLabel: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const PhiCollectionReorderContext: import("react").Context<PhiCollectionReorderContextValue | null>;
|
|
21
|
+
export declare function usePhiCollectionReorder(): PhiCollectionReorderContextValue | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type PhiCollectionReorderContextValue } from "./phi-collection-reorder-context";
|
|
3
|
+
export type PhiCollectionSortableLayoutControlProps = {
|
|
4
|
+
mode: "grid" | "stack";
|
|
5
|
+
gap: string | number;
|
|
6
|
+
minColumnWidth: string | number;
|
|
7
|
+
/** Drawn by the renderer, one per key of `reorder.itemKeys`, in that order. */
|
|
8
|
+
items: readonly ReactNode[];
|
|
9
|
+
reorder: PhiCollectionReorderContextValue;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A Collection's items in `grid` or `stack` with a drag handle on each, for `PhiCollectionViewControl`
|
|
13
|
+
* while a `PhiCollectionReorderContext` offers reordering. Pointer and keyboard (`@dnd-kit`, as the Table
|
|
14
|
+
* Control sorts its rows); a drop answers every key in the new order and changes nothing itself -- the
|
|
15
|
+
* order shown is the one the items come in.
|
|
16
|
+
*/
|
|
17
|
+
export declare function PhiCollectionSortableLayoutControl({ mode, gap, minColumnWidth, items, reorder, }: PhiCollectionSortableLayoutControlProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors, } from "@dnd-kit/core";
|
|
5
|
+
import { arrayMove, rectSortingStrategy, SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy, } from "@dnd-kit/sortable";
|
|
6
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
7
|
+
import { PhiIcon } from "../shell/phi-icon";
|
|
8
|
+
import { usePhiConfig } from "../root/phi-config-provider";
|
|
9
|
+
import { PhiCollectionReorderContext } from "./phi-collection-reorder-context";
|
|
10
|
+
function buildGridColumns(minColumnWidth) {
|
|
11
|
+
const width = typeof minColumnWidth === "number" ? `${minColumnWidth}px` : minColumnWidth;
|
|
12
|
+
return `repeat(auto-fill, minmax(${width}, 1fr))`;
|
|
13
|
+
}
|
|
14
|
+
/*
|
|
15
|
+
* One item and its handle. Only the handle starts a drag -- by pointer or, focused, by Space or Enter --
|
|
16
|
+
* so the item's own links, buttons and its click stay its own: a keyboard press on the item's delete
|
|
17
|
+
* button never reaches the drag sensor, which listens on the handle alone.
|
|
18
|
+
*/
|
|
19
|
+
function PhiCollectionSortableItem({ id, disabled, handleLabel, children, }) {
|
|
20
|
+
const { token } = usePhiConfig();
|
|
21
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id, disabled });
|
|
22
|
+
const style = {
|
|
23
|
+
position: "relative",
|
|
24
|
+
minWidth: 0,
|
|
25
|
+
transform: CSS.Translate.toString(transform),
|
|
26
|
+
transition,
|
|
27
|
+
zIndex: isDragging ? 10 : undefined,
|
|
28
|
+
opacity: isDragging ? 0.72 : undefined,
|
|
29
|
+
};
|
|
30
|
+
return (_jsxs("div", { ref: setNodeRef, style: style, "data-phi-collection-sortable-item": "", children: [_jsx(PhiCollectionReorderContext.Provider, { value: null, children: children }), _jsx("span", { ...attributes, ...listeners, ref: setActivatorNodeRef, "aria-label": handleLabel, title: handleLabel, style: {
|
|
31
|
+
position: "absolute",
|
|
32
|
+
top: token.paddingXXS,
|
|
33
|
+
insetInlineStart: token.paddingXXS,
|
|
34
|
+
display: "inline-flex",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
width: token.controlHeightSM,
|
|
38
|
+
height: token.controlHeightSM,
|
|
39
|
+
borderRadius: token.borderRadiusSM,
|
|
40
|
+
background: token.colorBgElevated,
|
|
41
|
+
color: token.colorTextSecondary,
|
|
42
|
+
boxShadow: token.boxShadowTertiary,
|
|
43
|
+
cursor: disabled ? "default" : isDragging ? "grabbing" : "grab",
|
|
44
|
+
opacity: disabled ? 0.5 : 0.9,
|
|
45
|
+
touchAction: "none",
|
|
46
|
+
}, children: _jsx(PhiIcon, { name: "holder", size: "inherit" }) })] }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A Collection's items in `grid` or `stack` with a drag handle on each, for `PhiCollectionViewControl`
|
|
50
|
+
* while a `PhiCollectionReorderContext` offers reordering. Pointer and keyboard (`@dnd-kit`, as the Table
|
|
51
|
+
* Control sorts its rows); a drop answers every key in the new order and changes nothing itself -- the
|
|
52
|
+
* order shown is the one the items come in.
|
|
53
|
+
*/
|
|
54
|
+
export function PhiCollectionSortableLayoutControl({ mode, gap, minColumnWidth, items, reorder, }) {
|
|
55
|
+
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
|
|
56
|
+
// dnd-kit names items by string; the keys go back out as the Provider gave them.
|
|
57
|
+
const ids = useMemo(() => reorder.itemKeys.map((key) => String(key)), [reorder.itemKeys]);
|
|
58
|
+
const disabled = reorder.disabled === true;
|
|
59
|
+
const onDragEnd = ({ active, over }) => {
|
|
60
|
+
if (!over || active.id === over.id)
|
|
61
|
+
return;
|
|
62
|
+
const from = ids.indexOf(String(active.id));
|
|
63
|
+
const to = ids.indexOf(String(over.id));
|
|
64
|
+
if (from < 0 || to < 0)
|
|
65
|
+
return;
|
|
66
|
+
reorder.onReorder(arrayMove([...reorder.itemKeys], from, to));
|
|
67
|
+
};
|
|
68
|
+
const style = mode === "stack"
|
|
69
|
+
? { display: "flex", flexDirection: "column", gap, width: "100%" }
|
|
70
|
+
: { display: "grid", gridTemplateColumns: buildGridColumns(minColumnWidth), gap, width: "100%" };
|
|
71
|
+
return (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: onDragEnd, children: _jsx(SortableContext, { items: ids, strategy: mode === "stack" ? verticalListSortingStrategy : rectSortingStrategy, children: _jsx("div", { style: style, children: items.map((item, index) => (_jsx(PhiCollectionSortableItem, { id: ids[index], disabled: disabled, handleLabel: reorder.handleLabel, children: item }, ids[index]))) }) }) }));
|
|
72
|
+
}
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense } from "react";
|
|
3
4
|
import { PHI_VISUAL_ANCHOR_PART_ATTRIBUTE } from "../../types/visual-anchors";
|
|
4
5
|
import { usePhiConfig } from "../root/phi-config-provider";
|
|
5
6
|
import { PhiCollectionHeaderControl } from "./phi-collection-header-control";
|
|
6
7
|
import { PhiCollectionLayoutControl } from "./phi-collection-layout-control";
|
|
7
8
|
import { PhiPaginationControl } from "./phi-pagination-control";
|
|
8
9
|
import { PhiSkeletonControl } from "./phi-skeleton-control";
|
|
10
|
+
import { usePhiCollectionReorder } from "./phi-collection-reorder-context";
|
|
11
|
+
// Loaded where a Collection offers reordering, so a Collection that does not carries no drag code.
|
|
12
|
+
const PhiCollectionSortableLayoutControl = lazy(() => import("./phi-collection-sortable-layout-control").then((module) => ({ default: module.PhiCollectionSortableLayoutControl })));
|
|
9
13
|
export function PhiCollectionViewControl({ title, description, filters, toolbar, panel, diagnostics, body, items, mode = "grid", gap, minColumnWidth, pagination, }) {
|
|
10
14
|
const { token } = usePhiConfig();
|
|
11
15
|
const resolvedGap = gap ?? token.paddingSM;
|
|
12
|
-
|
|
16
|
+
/*
|
|
17
|
+
* Reordering offered around this Collection (`PhiCollectionReorderContext`, the `collection-view`
|
|
18
|
+
* Widget's `features.reorder`) puts a handle on each item, in grid and stack. Only where the items are
|
|
19
|
+
* the ones the keys name -- one each, the renderer's own `body` not in their place.
|
|
20
|
+
*/
|
|
21
|
+
const reorder = usePhiCollectionReorder();
|
|
22
|
+
const itemList = [...(items ?? [])];
|
|
23
|
+
const sortable = reorder != null && body == null && mode !== "masonry" && itemList.length > 0 &&
|
|
24
|
+
itemList.length === reorder.itemKeys.length;
|
|
25
|
+
const layout = (_jsx(PhiCollectionLayoutControl, { mode: mode, gap: resolvedGap, minColumnWidth: minColumnWidth ?? 102, items: itemList }));
|
|
26
|
+
return (_jsxs("div", { style: { display: "flex", flexDirection: "column", gap: token.paddingSM, width: "100%", minWidth: 0 }, children: [_jsx(PhiCollectionHeaderControl, { title: title, description: description, filters: filters, toolbar: toolbar }), panel, diagnostics, _jsx("div", { [PHI_VISUAL_ANCHOR_PART_ATTRIBUTE]: "items", style: { width: "100%", minWidth: 0 }, children: body ?? (sortable ? (_jsx(Suspense, { fallback: layout, children: _jsx(PhiCollectionSortableLayoutControl, { mode: mode === "stack" ? "stack" : "grid", gap: resolvedGap, minColumnWidth: minColumnWidth ?? 102, items: itemList, reorder: reorder }) })) : layout) }), pagination ? (_jsx("div", { [PHI_VISUAL_ANCHOR_PART_ATTRIBUTE]: "pagination", style: { display: "flex", justifyContent: "flex-end", width: "100%", minWidth: 0 }, children: _jsx(PhiPaginationControl, { page: pagination.page, pageSize: pagination.pageSize, total: pagination.total, simple: pagination.simple, showSizeChanger: pagination.showSizeChanger, pageSizeOptions: pagination.pageSizeOptions, size: pagination.size, onChange: (value) => pagination.onChange(value.page, value.pageSize) }) })) : null] }));
|
|
13
27
|
}
|
|
14
28
|
export function PhiCollectionViewSkeletonControl({ mode = "grid", gap, minColumnWidth, active = true, count = 8, }) {
|
|
15
29
|
const { token } = usePhiConfig();
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { PhiControlSize } from "../../types/control";
|
|
2
2
|
import type { PhiMediaAssetTile } from "../../types/media";
|
|
3
3
|
import { type PhiCollectionLayoutControlProps } from "./phi-collection-layout-control";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* What a tile reads of an Asset, and nothing more: a whole `PhiMediaAssetTile` fits, and so does an
|
|
6
|
+
* Asset a Module holds in a shape of its own with these fields (`width`/`height` for the dimensions
|
|
7
|
+
* label, `deliveryPolicy`/`lifecycleStatus` for whether the picture is public and may be optimised).
|
|
8
|
+
*/
|
|
9
|
+
export type PhiMediaAssetTileControlAsset = Pick<PhiMediaAssetTile, "id" | "kind" | "originalName" | "title" | "altText" | "contentType" | "deliveryUrl" | "thumbnailUrl" | "previewUrl" | "deliveryPolicy" | "lifecycleStatus" | "width" | "height" | "blurDataUrl">;
|
|
10
|
+
/** `onSelect` and `onDelete` hand back the Asset as it was passed in, in its own type. */
|
|
11
|
+
export type PhiMediaAssetTileControlProps<TAsset extends PhiMediaAssetTileControlAsset = PhiMediaAssetTileControlAsset> = {
|
|
12
|
+
asset: TAsset;
|
|
6
13
|
minColumnWidth: string | number;
|
|
7
14
|
selected?: boolean;
|
|
8
15
|
mode?: "grid" | "masonry" | "stack";
|
|
@@ -15,15 +22,15 @@ export type PhiMediaAssetTileControlProps = {
|
|
|
15
22
|
* where it was started. The button reports it and refuses a second press while it stands.
|
|
16
23
|
*/
|
|
17
24
|
deleting?: boolean;
|
|
18
|
-
onSelect?: (asset:
|
|
19
|
-
onDelete?: (asset:
|
|
25
|
+
onSelect?: (asset: TAsset) => void;
|
|
26
|
+
onDelete?: (asset: TAsset) => void;
|
|
20
27
|
deleteLabel?: string;
|
|
21
28
|
showTypeLabel?: boolean;
|
|
22
29
|
showDeleteAction?: boolean;
|
|
23
30
|
showDimensions?: boolean;
|
|
24
31
|
showIdLabel?: boolean;
|
|
25
32
|
};
|
|
26
|
-
export declare function PhiMediaAssetTileControl({ asset, minColumnWidth, selected, mode, size, disabled, deleting, onSelect, onDelete, deleteLabel, showTypeLabel, showDeleteAction, showDimensions, showIdLabel, }: PhiMediaAssetTileControlProps): import("react").JSX.Element;
|
|
33
|
+
export declare function PhiMediaAssetTileControl<TAsset extends PhiMediaAssetTileControlAsset = PhiMediaAssetTileControlAsset>({ asset, minColumnWidth, selected, mode, size, disabled, deleting, onSelect, onDelete, deleteLabel, showTypeLabel, showDeleteAction, showDimensions, showIdLabel, }: PhiMediaAssetTileControlProps<TAsset>): import("react").JSX.Element;
|
|
27
34
|
export type PhiMediaAssetCollectionSkeletonControlProps = Pick<PhiCollectionLayoutControlProps, "mode" | "gap" | "minColumnWidth"> & {
|
|
28
35
|
active?: boolean;
|
|
29
36
|
count?: number;
|
|
@@ -29,6 +29,18 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
|
|
|
29
29
|
importingItemId?: string | null;
|
|
30
30
|
/** Why the last import did not work, said above the tiles. */
|
|
31
31
|
sourceNotice?: string | null;
|
|
32
|
+
/**
|
|
33
|
+
* A file from the reader's machine was chosen to go into the library, where the picker offers that.
|
|
34
|
+
* Answers the Asset it became -- chosen then as if it had been picked in the library -- or null where
|
|
35
|
+
* nothing is to be chosen and the picker stays as it is. Absent, the picker offers no upload.
|
|
36
|
+
*/
|
|
37
|
+
onUpload?: (file: File) => Promise<PhiMediaAssetTile | null>;
|
|
38
|
+
/** What the file dialog offers, as a MIME or extension list. */
|
|
39
|
+
uploadAccept?: string;
|
|
40
|
+
/** How far the upload on its way is, in per cent; null while none is. */
|
|
41
|
+
uploadProgress?: number | null;
|
|
42
|
+
/** Why the last upload did not work, said above the library's tiles. */
|
|
43
|
+
uploadNotice?: string | null;
|
|
32
44
|
folders?: readonly PhiControlOption[];
|
|
33
45
|
folderValue?: string;
|
|
34
46
|
query?: string;
|
|
@@ -61,6 +73,7 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
|
|
|
61
73
|
source: string;
|
|
62
74
|
importing: string;
|
|
63
75
|
loadMore: string;
|
|
76
|
+
upload: string;
|
|
64
77
|
}>;
|
|
65
78
|
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
66
79
|
popupRootClassName?: string;
|
|
@@ -78,4 +91,4 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
|
|
|
78
91
|
onMinColumnWidthChange?: (minColumnWidth: number) => void;
|
|
79
92
|
onReload?: () => void;
|
|
80
93
|
};
|
|
81
|
-
export declare function PhiMediaPickerControl({ open, value, assets, spaces, spaceValue, sources, sourceValue, sourceItems, sourceHasMore, importingItemId, sourceNotice, folders, folderValue, query, page, pageSize, total, minColumnWidth, loading, disabled, readOnly, placement, showSearchBar, showFolderFilter, showPagination, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onSourceChange, onSourceItemSelect, onSourceLoadMore, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }: PhiMediaPickerControlProps): import("react").JSX.Element;
|
|
94
|
+
export declare function PhiMediaPickerControl({ open, value, assets, spaces, spaceValue, sources, sourceValue, sourceItems, sourceHasMore, importingItemId, sourceNotice, onUpload, uploadAccept, uploadProgress, uploadNotice, folders, folderValue, query, page, pageSize, total, minColumnWidth, loading, disabled, readOnly, placement, showSearchBar, showFolderFilter, showPagination, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onSourceChange, onSourceItemSelect, onSourceLoadMore, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }: PhiMediaPickerControlProps): import("react").JSX.Element;
|
|
@@ -5,6 +5,7 @@ import { usePhiConfig } from "../root/phi-config-provider";
|
|
|
5
5
|
import { PhiButtonControl } from "./phi-button-control";
|
|
6
6
|
import { PhiCascaderControl } from "./phi-cascader-control";
|
|
7
7
|
import { PhiEmptyControl } from "./phi-empty-control";
|
|
8
|
+
import { PhiFileDropControl } from "./phi-file-drop-control";
|
|
8
9
|
import { PhiSelectControl } from "./phi-select-control";
|
|
9
10
|
import { PhiCollectionLayoutControl } from "./phi-collection-layout-control";
|
|
10
11
|
import { PhiMediaAssetCollectionSkeletonControl, PhiMediaAssetTileControl, } from "./phi-media-asset-tile-control";
|
|
@@ -16,7 +17,7 @@ import { PhiSliderControl } from "./phi-slider-control";
|
|
|
16
17
|
import { PhiTextControl } from "./phi-text-control";
|
|
17
18
|
import { usePhiImmediatePicker } from "./use-phi-immediate-picker";
|
|
18
19
|
import { PhiIcon } from "../shell/phi-icon";
|
|
19
|
-
export function PhiMediaPickerControl({ open, value = null, assets, spaces = [], spaceValue = null, sources = [], sourceValue = "", sourceItems = [], sourceHasMore = false, importingItemId = null, sourceNotice = null, folders = [], folderValue = "/", query = "", page = 1, pageSize = 20, total = assets.length, minColumnWidth = PHI_MEDIA_PICKER_DEFAULT_COLUMN_WIDTH, loading, disabled, readOnly, placement = "left", showSearchBar = true, showFolderFilter = true, showPagination = true, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onSourceChange, onSourceItemSelect, onSourceLoadMore, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }) {
|
|
20
|
+
export function PhiMediaPickerControl({ open, value = null, assets, spaces = [], spaceValue = null, sources = [], sourceValue = "", sourceItems = [], sourceHasMore = false, importingItemId = null, sourceNotice = null, onUpload, uploadAccept, uploadProgress = null, uploadNotice = null, folders = [], folderValue = "/", query = "", page = 1, pageSize = 20, total = assets.length, minColumnWidth = PHI_MEDIA_PICKER_DEFAULT_COLUMN_WIDTH, loading, disabled, readOnly, placement = "left", showSearchBar = true, showFolderFilter = true, showPagination = true, trigger, isAssetSelectable, labels, getPopupContainer, popupRootClassName, onOpenChange, onQueryChange, onSpaceChange, onSourceChange, onSourceItemSelect, onSourceLoadMore, onFolderChange, onPageChange, onMinColumnWidthChange, onReload, onChange, onCommit, onDiscard, }) {
|
|
20
21
|
const { token } = usePhiConfig();
|
|
21
22
|
const locked = disabled || readOnly;
|
|
22
23
|
const resolvedMinColumnWidth = normalizePhiMediaPickerMinColumnWidth(minColumnWidth);
|
|
@@ -33,6 +34,7 @@ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [],
|
|
|
33
34
|
// A source is shown while one other than the library is named; its items stand where the tiles do.
|
|
34
35
|
const sourceActive = sources.length > 1 && sourceValue !== "";
|
|
35
36
|
const importing = importingItemId != null;
|
|
37
|
+
const uploading = uploadProgress != null;
|
|
36
38
|
const sourceTileItems = sourceItems.map((item) => (_jsx(PhiMediaSourceItemTileControl, { title: item.title, thumbnailUrl: item.thumbnailUrl, credit: item.credit, minColumnWidth: resolvedMinColumnWidth, busy: importingItemId === item.id, busyLabel: labels?.importing, disabled: locked || importing, onSelect: () => {
|
|
37
39
|
void onSourceItemSelect?.(item).then((asset) => {
|
|
38
40
|
if (!asset)
|
|
@@ -51,6 +53,13 @@ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [],
|
|
|
51
53
|
minHeight: 0,
|
|
52
54
|
}, children: [_jsx(Typography.Text, { strong: true, children: labels?.title ?? "Select media" }), _jsxs(Flex, { gap: token.paddingSM, align: "center", wrap: true, children: [showSearchBar ? (_jsx("div", { style: { flex: "1 1 220px" }, children: _jsx(PhiTextControl, { inputType: "search", value: query, size: "small", placeholder: labels?.search ?? "Search", disabled: locked, onChange: (next) => onQueryChange?.(next ?? "") }) })) : null, spaces.length > 1 ? (_jsx("div", { style: { flex: "0 1 160px" }, children: _jsx(PhiSelectControl, { value: spaceValue ?? undefined, options: spaces, size: "small", placeholder: labels?.space ?? "Space", disabled: locked, getPopupContainer: getPopupContainer, popupRootClassName: popupRootClassName, onChange: (next) => { if (typeof next === "string" && next)
|
|
53
55
|
onSpaceChange?.(next); } }) })) : null, sources.length > 1 ? (_jsx("div", { style: { flex: "0 1 160px" }, children: _jsx(PhiSelectControl, { value: sourceValue, options: sources, size: "small", ariaLabel: labels?.source ?? "Source", placeholder: labels?.source ?? "Source", disabled: locked || importing, getPopupContainer: getPopupContainer, popupRootClassName: popupRootClassName, onChange: (next) => { if (typeof next === "string")
|
|
54
|
-
onSourceChange?.(next); } }) })) : null, showFolderFilter ? (_jsx("div", { style: { flex: "1 1 180px" }, children: _jsx(PhiCascaderControl, { value: folderValue, options: folders, allowRoot: true, rootValue: "/", separator: "/", size: "small", placeholder: labels?.folder ?? "Folder", disabled: locked, getPopupContainer: getPopupContainer, classNames: popupRootClassName ? { popup: { root: popupRootClassName } } : undefined, onChange: (next) => onFolderChange?.(next ?? "/") }) })) : null, _jsx(PhiButtonControl, { ariaLabel: labels?.reload ?? "Reload", tooltip: labels?.reload ?? "Reload", icon: _jsx(PhiIcon, { name: "reload", size: "inherit" }), size: "small", disabled: locked, onClick: onReload })
|
|
56
|
+
onSourceChange?.(next); } }) })) : null, showFolderFilter ? (_jsx("div", { style: { flex: "1 1 180px" }, children: _jsx(PhiCascaderControl, { value: folderValue, options: folders, allowRoot: true, rootValue: "/", separator: "/", size: "small", placeholder: labels?.folder ?? "Folder", disabled: locked, getPopupContainer: getPopupContainer, classNames: popupRootClassName ? { popup: { root: popupRootClassName } } : undefined, onChange: (next) => onFolderChange?.(next ?? "/") }) })) : null, _jsx(PhiButtonControl, { ariaLabel: labels?.reload ?? "Reload", tooltip: labels?.reload ?? "Reload", icon: _jsx(PhiIcon, { name: "reload", size: "inherit" }), size: "small", disabled: locked, onClick: onReload }), onUpload && !sourceActive ? (_jsx(PhiFileDropControl, { accept: uploadAccept, disabled: locked || uploading, onFile: (file) => {
|
|
57
|
+
void onUpload(file).then((asset) => {
|
|
58
|
+
if (!asset)
|
|
59
|
+
return;
|
|
60
|
+
picker.changeValue(asset.id);
|
|
61
|
+
picker.closePicker("commit");
|
|
62
|
+
});
|
|
63
|
+
}, children: _jsx(PhiButtonControl, { icon: _jsx(PhiIcon, { name: "upload", size: "inherit" }), label: uploading ? `${uploadProgress}%` : labels?.upload ?? "Upload", ariaLabel: labels?.upload ?? "Upload", size: "small", loading: uploading, disabled: locked || uploading }) })) : null] }), sourceActive && sourceNotice ? (_jsx(Typography.Text, { type: "danger", role: "alert", children: sourceNotice })) : null, !sourceActive && uploadNotice ? (_jsx(Typography.Text, { type: "danger", role: "alert", children: uploadNotice })) : null, _jsx("div", { style: { flex: "1 1 auto", minHeight: 0, overflow: "auto" }, children: sourceActive ? (loading && sourceItems.length === 0 ? (_jsx(PhiMediaAssetCollectionSkeletonControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: resolvedMinColumnWidth, count: Math.min(pageSize, 12), size: "small" })) : sourceItems.length === 0 ? (_jsx(PhiEmptyControl, { description: labels?.sourceEmpty ?? labels?.empty ?? "No media" })) : (_jsx(PhiCollectionLayoutControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: resolvedMinColumnWidth, items: sourceTileItems }))) : loading && assets.length === 0 ? (_jsx(PhiMediaAssetCollectionSkeletonControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: resolvedMinColumnWidth, count: Math.min(pageSize, 12), size: "small" })) : assets.length === 0 ? (_jsx(PhiEmptyControl, { description: labels?.empty ?? "No media" })) : (_jsx(PhiCollectionLayoutControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: resolvedMinColumnWidth, items: tileItems })) }), _jsxs(Flex, { align: "center", gap: token.paddingSM, style: { flex: "0 0 auto", minWidth: 0 }, children: [_jsx(Typography.Text, { type: "secondary", ellipsis: true, style: { flex: "0 1 180px", minWidth: 0 }, children: selected?.title || selected?.originalName || "" }), _jsxs(Flex, { align: "center", gap: token.paddingXS, style: { flex: "1 1 160px", minWidth: 120 }, children: [_jsx(PhiSliderControl, { ariaLabel: labels?.tileSize ?? "Tile size", value: resolvedMinColumnWidth, min: PHI_MEDIA_PICKER_MIN_COLUMN_WIDTH, max: PHI_MEDIA_PICKER_MAX_COLUMN_WIDTH, step: PHI_MEDIA_PICKER_COLUMN_WIDTH_STEP, tooltipSuffix: " px", disabled: locked, style: { flex: "1 1 auto", minWidth: 0 }, onChange: onMinColumnWidthChange }), _jsxs(Typography.Text, { type: "secondary", style: { fontSize: token.fontSizeSM, whiteSpace: "nowrap" }, children: [resolvedMinColumnWidth, "px"] })] }), _jsx(PhiButtonControl, { label: labels?.clear ?? "Clear", size: "small", disabled: locked || picker.value == null, onClick: () => picker.changeValue(null) }), sourceActive ? (sourceHasMore ? (_jsx(PhiButtonControl, { label: labels?.loadMore ?? "Load more", size: "small", loading: loading, disabled: locked || importing, onClick: onSourceLoadMore })) : null) : showPagination ? (_jsx(PhiPaginationControl, { page: page, pageSize: pageSize, total: total, size: "small", disabled: locked, showSizeChanger: true, getPopupContainer: getPopupContainer, popupRootClassName: popupRootClassName, onChange: (next) => onPageChange?.(next.page, next.pageSize) })) : null] })] }));
|
|
55
64
|
return (_jsx(PhiPopoverControl, { open: picker.open, content: content, placement: placement, disabled: locked, getPopupContainer: getPopupContainer, rootClassName: popupRootClassName, onOpenChange: picker.handleOpenChange, children: trigger ?? (_jsx("span", { children: _jsx(PhiButtonControl, { block: true, icon: _jsx(PhiIcon, { name: "picture", size: "inherit" }), label: labels?.trigger ?? "Select media", disabled: locked, onClick: picker.openPicker }) })) }));
|
|
56
65
|
}
|
|
@@ -6,8 +6,8 @@ export type PhiColorControlCustomColor = {
|
|
|
6
6
|
value: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* The colour picker's swatches: the Theme's custom colours, its primary
|
|
10
|
-
* palettes.
|
|
9
|
+
* The colour picker's swatches: the Theme's custom colours, its primary ladder, its status colours and its
|
|
10
|
+
* text ladder, then the fixed palettes.
|
|
11
11
|
*
|
|
12
12
|
* With `storeThemeRoles`, a Theme swatch stores the role it shows (`PHI_COLOR.custom3`,
|
|
13
13
|
* `PHI_COLOR.primaryBg`) rather than its colour, so what an author picks follows the Theme and the mode.
|
|
@@ -16,6 +16,13 @@ const PHI_PRIMARY_COLOR_TOKEN_KEYS = [
|
|
|
16
16
|
"colorPrimaryText",
|
|
17
17
|
"colorPrimaryTextActive",
|
|
18
18
|
];
|
|
19
|
+
/* What a colour says rather than what it looks like: done, careful, wrong, of note -- as Alerts and Tags say it. */
|
|
20
|
+
const PHI_STATUS_COLOR_TOKEN_KEYS = [
|
|
21
|
+
"colorSuccess",
|
|
22
|
+
"colorWarning",
|
|
23
|
+
"colorError",
|
|
24
|
+
"colorInfo",
|
|
25
|
+
];
|
|
19
26
|
const PHI_TEXT_COLOR_TOKEN_KEYS = [
|
|
20
27
|
"colorTextBase",
|
|
21
28
|
"colorText",
|
|
@@ -33,8 +40,8 @@ function resolvePhiColorTokenReference(tokenKey) {
|
|
|
33
40
|
return `var(--phi-${tokenKey.replace(/[A-Z]/gu, (letter) => `-${letter.toLowerCase()}`)})`;
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
|
-
* The colour picker's swatches: the Theme's custom colours, its primary
|
|
37
|
-
* palettes.
|
|
43
|
+
* The colour picker's swatches: the Theme's custom colours, its primary ladder, its status colours and its
|
|
44
|
+
* text ladder, then the fixed palettes.
|
|
38
45
|
*
|
|
39
46
|
* With `storeThemeRoles`, a Theme swatch stores the role it shows (`PHI_COLOR.custom3`,
|
|
40
47
|
* `PHI_COLOR.primaryBg`) rather than its colour, so what an author picks follows the Theme and the mode.
|
|
@@ -70,6 +77,13 @@ export function usePhiColorControlPresets({ labels = PHI_COLOR_PICKER_DEFAULT_LA
|
|
|
70
77
|
colorLabels: [...PHI_PRIMARY_COLOR_TOKEN_KEYS],
|
|
71
78
|
...(storeThemeRoles ? { colorReferences: PHI_PRIMARY_COLOR_TOKEN_KEYS.map(resolvePhiColorTokenReference) } : {}),
|
|
72
79
|
},
|
|
80
|
+
{
|
|
81
|
+
key: "phi-status",
|
|
82
|
+
label: labels.colors.status,
|
|
83
|
+
colors: PHI_STATUS_COLOR_TOKEN_KEYS.map((key) => token[key]),
|
|
84
|
+
colorLabels: [...PHI_STATUS_COLOR_TOKEN_KEYS],
|
|
85
|
+
...(storeThemeRoles ? { colorReferences: PHI_STATUS_COLOR_TOKEN_KEYS.map(resolvePhiColorTokenReference) } : {}),
|
|
86
|
+
},
|
|
73
87
|
{
|
|
74
88
|
key: "phi-text",
|
|
75
89
|
label: labels.colors.text,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PhiFormFieldProviderProps } from "./form-provider-registry";
|
|
2
|
-
export declare function PhiCompoundTableFormControl({ field, label, description, value, onChange, disabled, readOnly, formContext, }: PhiFormFieldProviderProps): import("react").JSX.Element;
|
|
2
|
+
export declare function PhiCompoundTableFormControl({ field, label, description, value, onChange, disabled, readOnly, formContext, labels, }: PhiFormFieldProviderProps): import("react").JSX.Element;
|
|
3
3
|
export declare function PhiCompoundTreeFormControl({ field, label, description, value, onChange, disabled, readOnly }: PhiFormFieldProviderProps): import("react").JSX.Element;
|
|
@@ -10,6 +10,7 @@ import { PhiToolbarControl } from "../controls/phi-toolbar-control";
|
|
|
10
10
|
import { readPhiDotPath as readPath } from "../../helpers/dot-path";
|
|
11
11
|
import { movePhiTableBindingRows } from "../../helpers/table-binding";
|
|
12
12
|
import { PhiIcon } from "../shell/phi-icon";
|
|
13
|
+
import { readPhiFormTableFieldText as readTableFieldText } from "./table-field-text";
|
|
13
14
|
function readRecords(value) {
|
|
14
15
|
return Array.isArray(value)
|
|
15
16
|
? value.filter((entry) => isPhiRecord(entry)).map((entry) => ({ ...entry }))
|
|
@@ -110,7 +111,7 @@ function applyMove(rows, identityPath, parentPath, move) {
|
|
|
110
111
|
? setPath(row, parentPath, parentIdentity)
|
|
111
112
|
: row);
|
|
112
113
|
}
|
|
113
|
-
export function PhiCompoundTableFormControl({ field, label, description, value, onChange, disabled, readOnly, formContext, }) {
|
|
114
|
+
export function PhiCompoundTableFormControl({ field, label, description, value, onChange, disabled, readOnly, formContext, labels, }) {
|
|
114
115
|
const rows = useMemo(() => readRecords(value), [value]);
|
|
115
116
|
const nextRowSequenceRef = useRef(0);
|
|
116
117
|
const config = field.config ?? {};
|
|
@@ -124,8 +125,9 @@ export function PhiCompoundTableFormControl({ field, label, description, value,
|
|
|
124
125
|
: null;
|
|
125
126
|
const addEnabled = addConfig?.enabled === true;
|
|
126
127
|
const removeEnabled = removeConfig?.enabled === true;
|
|
127
|
-
const addLabel =
|
|
128
|
-
const removeLabel =
|
|
128
|
+
const addLabel = readTableFieldText(addConfig?.label, labels, "add");
|
|
129
|
+
const removeLabel = readTableFieldText(removeConfig?.label, labels, "remove");
|
|
130
|
+
const emptyText = readTableFieldText(config.emptyText, labels, "empty");
|
|
129
131
|
const addSourceFields = isPhiRecord(addConfig?.sourceFields)
|
|
130
132
|
? addConfig.sourceFields
|
|
131
133
|
: null;
|
|
@@ -195,7 +197,7 @@ export function PhiCompoundTableFormControl({ field, label, description, value,
|
|
|
195
197
|
icon: _jsx(PhiIcon, { name: "plus", size: "inherit" }),
|
|
196
198
|
type: "primary",
|
|
197
199
|
}], compact: true, showLabels: true, size: "small", disabled: locked, onActivate: (key) => { if (key === "add")
|
|
198
|
-
appendRow(); } })) : null }), _jsx(PhiTableControl, { rows: rows, rowIdentityPath: identityPath, columns: renderedColumns, columnOrder: columnOrder, sortingMode: "none", sorts: [], bordered: config.bordered === true, striped: config.striped === true, size: "small", emptyText:
|
|
200
|
+
appendRow(); } })) : null }), _jsx(PhiTableControl, { rows: rows, rowIdentityPath: identityPath, columns: renderedColumns, columnOrder: columnOrder, sortingMode: "none", sorts: [], bordered: config.bordered === true, striped: config.striped === true, size: "small", emptyText: emptyText, layout: layout, rowReordering: config.reorder === true && !locked ? {
|
|
199
201
|
enabled: true,
|
|
200
202
|
onMove: (move) => onChange?.(applyMove(rows, identityPath, typeof config.parentRowIdentityPath === "string" ? config.parentRowIdentityPath : null, move)),
|
|
201
203
|
} : undefined })] }));
|
|
@@ -5,7 +5,9 @@ import type { PhiFormRenderContext } from "./form-resolution";
|
|
|
5
5
|
* What a Form's field types say for themselves, under the keys their controls read.
|
|
6
6
|
*
|
|
7
7
|
* The `media-asset` field is the same: the picker it opens says the Media Label Set's words, read here
|
|
8
|
-
* for every Form that has such a field (`media-asset-field-keys.ts`)
|
|
8
|
+
* for every Form that has such a field (`media-asset-field-keys.ts`), and the upload inside it says the
|
|
9
|
+
* upload's refusals and its hold under the upload field's keys. The `table` field says its add, remove and
|
|
10
|
+
* empty words from Core's `widget:table` set (`table-field-labels.ts`) where its config names none.
|
|
9
11
|
*
|
|
10
12
|
* A field type whose control speaks -- the upload field's trigger, its drop hint, its holds and the
|
|
11
13
|
* refusals of the upload -- says it from Core's `widget:upload` Label Set, read here for every Form that
|
|
@@ -5,11 +5,16 @@ import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY } from "../../constants/media-l
|
|
|
5
5
|
import { phiRuntime } from "../../server-helpers/phi-runtime";
|
|
6
6
|
import { PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS } from "./media-asset-field-keys";
|
|
7
7
|
import { PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY, PHI_FORM_UPLOAD_LABEL_KEYS } from "./upload-field-keys";
|
|
8
|
+
import { getPhiTableFormFieldLabels } from "../widgets/label-sets/table";
|
|
9
|
+
import { PHI_FORM_TABLE_FIELD_PROVIDER_KEY } from "./table-field-keys";
|
|
10
|
+
import { PHI_FORM_TABLE_LABEL_KEYS } from "./table-field-labels";
|
|
8
11
|
/**
|
|
9
12
|
* What a Form's field types say for themselves, under the keys their controls read.
|
|
10
13
|
*
|
|
11
14
|
* The `media-asset` field is the same: the picker it opens says the Media Label Set's words, read here
|
|
12
|
-
* for every Form that has such a field (`media-asset-field-keys.ts`)
|
|
15
|
+
* for every Form that has such a field (`media-asset-field-keys.ts`), and the upload inside it says the
|
|
16
|
+
* upload's refusals and its hold under the upload field's keys. The `table` field says its add, remove and
|
|
17
|
+
* empty words from Core's `widget:table` set (`table-field-labels.ts`) where its config names none.
|
|
13
18
|
*
|
|
14
19
|
* A field type whose control speaks -- the upload field's trigger, its drop hint, its holds and the
|
|
15
20
|
* refusals of the upload -- says it from Core's `widget:upload` Label Set, read here for every Form that
|
|
@@ -23,7 +28,8 @@ import { PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY, PHI_FORM_UPLOAD_LABEL_KEYS } from "
|
|
|
23
28
|
export async function resolvePhiFormFieldLabels(context, descriptor) {
|
|
24
29
|
const hasUpload = descriptor.fields.some((field) => field.fieldProviderKey === PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY);
|
|
25
30
|
const hasMediaAsset = descriptor.fields.some((field) => field.fieldProviderKey === PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY);
|
|
26
|
-
|
|
31
|
+
const hasTable = descriptor.fields.some((field) => field.fieldProviderKey === PHI_FORM_TABLE_FIELD_PROVIDER_KEY);
|
|
32
|
+
if (!hasUpload && !hasMediaAsset && !hasTable)
|
|
27
33
|
return {};
|
|
28
34
|
const rt = phiRuntime(context.runtime);
|
|
29
35
|
const options = {
|
|
@@ -31,11 +37,12 @@ export async function resolvePhiFormFieldLabels(context, descriptor) {
|
|
|
31
37
|
internalToken: rt.internalToken,
|
|
32
38
|
locale: context.runtime.locale.current,
|
|
33
39
|
};
|
|
34
|
-
const [upload, media] = await Promise.all([
|
|
35
|
-
hasUpload ? readUploadFieldLabels(options) : {},
|
|
40
|
+
const [upload, media, table] = await Promise.all([
|
|
41
|
+
hasUpload || hasMediaAsset ? readUploadFieldLabels(options) : {},
|
|
36
42
|
hasMediaAsset ? readMediaAssetFieldLabels(options) : {},
|
|
43
|
+
hasTable ? readTableFieldLabels(options) : {},
|
|
37
44
|
]);
|
|
38
|
-
return { ...upload, ...media };
|
|
45
|
+
return { ...upload, ...media, ...table };
|
|
39
46
|
}
|
|
40
47
|
async function readUploadFieldLabels(options) {
|
|
41
48
|
const { field, refusals } = await getPhiMediaUploadLabels(options);
|
|
@@ -56,8 +63,13 @@ async function readUploadFieldLabels(options) {
|
|
|
56
63
|
[keys.errorFolderLocked]: refusals.errorFolderLocked,
|
|
57
64
|
};
|
|
58
65
|
}
|
|
66
|
+
async function readTableFieldLabels(options) {
|
|
67
|
+
const { add, remove, empty } = await getPhiTableFormFieldLabels(options);
|
|
68
|
+
const keys = PHI_FORM_TABLE_LABEL_KEYS;
|
|
69
|
+
return { [keys.add]: add, [keys.remove]: remove, [keys.empty]: empty };
|
|
70
|
+
}
|
|
59
71
|
async function readMediaAssetFieldLabels(options) {
|
|
60
|
-
const { tool, picker, space } = await getPhiMediaWidgetLabels(options);
|
|
72
|
+
const { tool, picker, space, upload } = await getPhiMediaWidgetLabels(options);
|
|
61
73
|
const keys = PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS;
|
|
62
74
|
return {
|
|
63
75
|
[keys.popoverTitle]: picker.popoverTitle,
|
|
@@ -74,5 +86,6 @@ async function readMediaAssetFieldLabels(options) {
|
|
|
74
86
|
[keys.importingLabel]: picker.importingLabel,
|
|
75
87
|
[keys.importFailedText]: picker.importFailedText,
|
|
76
88
|
[keys.loadMoreLabel]: picker.loadMoreLabel,
|
|
89
|
+
[keys.uploadLabel]: upload.uploadToggleLabel,
|
|
77
90
|
};
|
|
78
91
|
}
|
|
@@ -2,6 +2,7 @@ import { createPhiModuleScopedKey } from "../../constants/runtime-module-ownersh
|
|
|
2
2
|
import { PhiMediaKind } from "../../constants/media";
|
|
3
3
|
import { PHIS_PAYMENT_CURRENCY_EXPONENTS } from "@phis/contracts/payments";
|
|
4
4
|
import { PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY } from "./upload-field-keys";
|
|
5
|
+
import { PHI_FORM_TABLE_FIELD_PROVIDER_KEY } from "./table-field-keys";
|
|
5
6
|
export function createPhiSharedFormProviderKey(kind, key) {
|
|
6
7
|
const normalizedKey = key.trim();
|
|
7
8
|
if (!normalizedKey || normalizedKey.includes("/") || normalizedKey.includes(":")) {
|
|
@@ -29,7 +30,7 @@ export const PHI_FORM_FIELD_PROVIDER_KEYS = {
|
|
|
29
30
|
switch: createPhiSharedFormProviderKey("field", "switch"),
|
|
30
31
|
segmented: createPhiSharedFormProviderKey("field", "segmented"),
|
|
31
32
|
cascader: createPhiSharedFormProviderKey("field", "cascader"),
|
|
32
|
-
table:
|
|
33
|
+
table: PHI_FORM_TABLE_FIELD_PROVIDER_KEY,
|
|
33
34
|
tree: createPhiSharedFormProviderKey("field", "tree"),
|
|
34
35
|
// Spelled beside its label keys, which the Form Widget reads on the Server without this whole file.
|
|
35
36
|
upload: PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY,
|