@phis/ui 0.7.3 → 0.7.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.
Files changed (73) hide show
  1. package/components/controls/phi-form-control.js +1 -0
  2. package/components/controls/phi-media-asset-tile-control.d.ts +4 -3
  3. package/components/controls/phi-media-picker-control.d.ts +9 -11
  4. package/components/controls/phi-media-picker-control.js +9 -11
  5. package/components/controls/phi-options-provider.d.ts +14 -1
  6. package/components/controls/phi-options-provider.js +73 -2
  7. package/components/forms/form-field-labels.d.ts +3 -3
  8. package/components/forms/form-field-labels.js +13 -5
  9. package/components/forms/media-asset-field-keys.d.ts +9 -1
  10. package/components/forms/media-asset-field-keys.js +13 -1
  11. package/components/media/label-sets/media.js +4 -0
  12. package/components/media/media-folder-name-path.d.ts +14 -0
  13. package/components/media/media-folder-name-path.js +40 -2
  14. package/components/media/media-library-resource.d.ts +70 -0
  15. package/components/media/media-library-resource.js +41 -0
  16. package/components/media/media-widget-labels.d.ts +13 -0
  17. package/components/media/media-widget-labels.js +2 -0
  18. package/components/media/phi-area-upload-widget.d.ts +31 -1
  19. package/components/media/phi-area-upload-widget.js +33 -7
  20. package/components/media/phi-image-preview-data.d.ts +8 -1
  21. package/components/media/phi-image-preview-data.js +29 -0
  22. package/components/media/phi-media-picker-binding.d.ts +22 -20
  23. package/components/media/phi-media-picker-binding.js +20 -33
  24. package/components/media/use-media-library-add-picker.d.ts +94 -0
  25. package/components/media/use-media-library-add-picker.js +40 -0
  26. package/components/widgets/client/shared/phi-choice-controller.js +22 -15
  27. package/constants/media-library-provider-keys.d.ts +7 -0
  28. package/constants/media-library-provider-keys.js +7 -0
  29. package/constants/runtime-module-ownership.js +1 -0
  30. package/helpers/preset-tree-contract-check.d.ts +35 -0
  31. package/helpers/preset-tree-contract-check.js +211 -0
  32. package/module-page-check.d.ts +6 -0
  33. package/module-page-check.js +6 -0
  34. package/package.json +1 -1
  35. package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
  36. package/plugins/runtime-modules/asset/data-providers.js +4 -32
  37. package/plugins/runtime-modules/asset/definition.d.ts +115 -38
  38. package/plugins/runtime-modules/asset/definition.js +2 -1
  39. package/plugins/runtime-modules/asset/form-providers.d.ts +85 -2
  40. package/plugins/runtime-modules/asset/form-providers.js +70 -11
  41. package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
  42. package/plugins/runtime-modules/asset/media-asset-field.d.ts +7 -7
  43. package/plugins/runtime-modules/asset/media-asset-field.js +11 -33
  44. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +8 -7
  45. package/plugins/runtime-modules/asset/media-asset-form-control.js +42 -83
  46. package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
  47. package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
  48. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
  49. package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
  50. package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
  51. package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
  52. package/plugins/runtime-modules/asset/services/collection.js +12 -0
  53. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +11 -6
  54. package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
  55. package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
  56. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
  57. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
  58. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
  59. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
  60. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +7 -2
  61. package/plugins/runtime-modules/core/widgets/collection-view/client.js +12 -4
  62. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +25 -0
  63. package/plugins/runtime-modules/core/widgets/collection-view/config.js +34 -0
  64. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
  65. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +3 -2
  66. package/plugins/runtime-modules/core/widgets/collection-view/server.js +20 -18
  67. package/plugins/runtime-modules/core/widgets/multi-select/client.js +6 -4
  68. package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
  69. package/plugins/runtime-modules/descriptor-compiler.js +9 -204
  70. package/plugins/runtime-modules/resolver.js +31 -5
  71. package/types/collection-view-widget.d.ts +19 -0
  72. package/types/core-widget-placements.d.ts +9 -0
  73. package/types/media.d.ts +16 -0
@@ -101,6 +101,7 @@ function PhiResolvedFormFieldControl({ id, provider, field, label, description,
101
101
  sourceConfig,
102
102
  searchDraft,
103
103
  formValues,
104
+ selectedValues: value,
104
105
  });
105
106
  /*
106
107
  * A required parent changed, so what this field holds was chosen from a list that no longer applies.
@@ -1,12 +1,13 @@
1
1
  import type { PhiControlSize } from "../../types/control";
2
- import type { PhiMediaAssetTile } from "../../types/media";
2
+ import type { PhiMediaCollectionItem } from "../../types/media";
3
3
  import { type PhiCollectionLayoutControlProps } from "./phi-collection-layout-control";
4
4
  /**
5
5
  * What a tile reads of an Asset, and nothing more: a whole `PhiMediaAssetTile` fits, and so does an
6
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).
7
+ * label, `deliveryPolicy`/`lifecycleStatus` for whether the picture is public and may be optimised). The
8
+ * item a Collection hands the Media renderer is this and its Folder (`PhiMediaCollectionItem`).
8
9
  */
9
- export type PhiMediaAssetTileControlAsset = Pick<PhiMediaAssetTile, "id" | "kind" | "originalName" | "title" | "altText" | "contentType" | "deliveryUrl" | "thumbnailUrl" | "previewUrl" | "deliveryPolicy" | "lifecycleStatus" | "width" | "height" | "blurDataUrl">;
10
+ export type PhiMediaAssetTileControlAsset = Omit<PhiMediaCollectionItem, "folderId">;
10
11
  /** `onSelect` and `onDelete` hand back the Asset as it was passed in, in its own type. */
11
12
  export type PhiMediaAssetTileControlProps<TAsset extends PhiMediaAssetTileControlAsset = PhiMediaAssetTileControlAsset> = {
12
13
  asset: TAsset;
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from "react";
1
+ import { type ReactNode } from "react";
2
2
  import type { PhisMediaSourceItem } from "@phis/contracts/media-source";
3
3
  import type { PhiMediaAssetTile } from "../../types/media";
4
4
  import type { PhiControlOption } from "./phi-control-options";
@@ -30,16 +30,14 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
30
30
  /** Why the last import did not work, said above the tiles. */
31
31
  sourceNotice?: string | null;
32
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.
33
+ * The upload surface, where the picker offers one: the Upload button beside Reload shows it above the
34
+ * library's tiles -- the Media library's own upload surface (`PhiAreaUploadBinding`, one file), which
35
+ * the host draws, so a picker without upload carries no transport. It is drawn only while the picker is
36
+ * open and the panel shown, so closing either stops what is on its way. `choose` chooses an Asset that
37
+ * arrived as if it had been picked in the library, and closes the picker. Absent, no upload is offered.
36
38
  */
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. */
39
+ uploadPanel?: (choose: (assetId: number) => void) => ReactNode;
40
+ /** Why the last upload did not work, or the Folder could not be opened, said above the library's tiles. */
43
41
  uploadNotice?: string | null;
44
42
  folders?: readonly PhiControlOption[];
45
43
  folderValue?: string;
@@ -91,4 +89,4 @@ export type PhiMediaPickerControlProps = PhiPickerTransactionCallbacks<number |
91
89
  onMinColumnWidthChange?: (minColumnWidth: number) => void;
92
90
  onReload?: () => void;
93
91
  };
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;
92
+ export declare function PhiMediaPickerControl({ open, value, assets, spaces, spaceValue, sources, sourceValue, sourceItems, sourceHasMore, importingItemId, sourceNotice, uploadPanel, 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;
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
3
4
  import { Flex, Typography } from "antd";
4
5
  import { usePhiConfig } from "../root/phi-config-provider";
5
6
  import { PhiButtonControl } from "./phi-button-control";
6
7
  import { PhiCascaderControl } from "./phi-cascader-control";
7
8
  import { PhiEmptyControl } from "./phi-empty-control";
8
- import { PhiFileDropControl } from "./phi-file-drop-control";
9
9
  import { PhiSelectControl } from "./phi-select-control";
10
10
  import { PhiCollectionLayoutControl } from "./phi-collection-layout-control";
11
11
  import { PhiMediaAssetCollectionSkeletonControl, PhiMediaAssetTileControl, } from "./phi-media-asset-tile-control";
@@ -17,7 +17,7 @@ import { PhiSliderControl } from "./phi-slider-control";
17
17
  import { PhiTextControl } from "./phi-text-control";
18
18
  import { usePhiImmediatePicker } from "./use-phi-immediate-picker";
19
19
  import { PhiIcon } from "../shell/phi-icon";
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
+ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [], spaceValue = null, sources = [], sourceValue = "", sourceItems = [], sourceHasMore = false, importingItemId = null, sourceNotice = null, uploadPanel, 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, }) {
21
21
  const { token } = usePhiConfig();
22
22
  const locked = disabled || readOnly;
23
23
  const resolvedMinColumnWidth = normalizePhiMediaPickerMinColumnWidth(minColumnWidth);
@@ -34,7 +34,8 @@ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [],
34
34
  // A source is shown while one other than the library is named; its items stand where the tiles do.
35
35
  const sourceActive = sources.length > 1 && sourceValue !== "";
36
36
  const importing = importingItemId != null;
37
- const uploading = uploadProgress != null;
37
+ const [uploadShown, setUploadShown] = useState(false);
38
+ const uploadOffered = uploadPanel != null && !sourceActive;
38
39
  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: () => {
39
40
  void onSourceItemSelect?.(item).then((asset) => {
40
41
  if (!asset)
@@ -53,13 +54,10 @@ export function PhiMediaPickerControl({ open, value = null, assets, spaces = [],
53
54
  minHeight: 0,
54
55
  }, 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)
55
56
  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")
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] })] }));
57
+ 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 }), uploadOffered ? (_jsx(PhiButtonControl, { icon: _jsx(PhiIcon, { name: "upload", size: "inherit" }), ariaLabel: labels?.upload ?? "Upload", tooltip: labels?.upload ?? "Upload", type: uploadShown ? "primary" : "default", size: "small", disabled: locked, onClick: () => setUploadShown((current) => !current) })) : null] }), uploadOffered && uploadShown && picker.open && !locked ? uploadPanel((assetId) => {
58
+ setUploadShown(false);
59
+ picker.changeValue(assetId);
60
+ picker.closePicker("commit");
61
+ }) : 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] })] }));
64
62
  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 }) })) }));
65
63
  }
@@ -44,6 +44,17 @@ export type PhiControlOptionsProviderContext<TValue extends string | number = st
44
44
  * knowing which field supplies it or where that field lives.
45
45
  */
46
46
  dependencies: Record<string, unknown>;
47
+ /**
48
+ * The values the control holds right now: one for a single choice, every one for a multiple choice,
49
+ * none while nothing is chosen.
50
+ *
51
+ * For a provider that answers with one page of a longer list. What the field holds need not be on
52
+ * that page, and a control that cannot find a value among its options shows the raw value -- an id
53
+ * instead of a name. Such a provider loads the names of these values alongside the page. Not part of
54
+ * the default load key: a provider that answers with everything it has would ask again on every
55
+ * choice for nothing, so one that needs them takes them into `resolveLoadKey` itself.
56
+ */
57
+ selected: readonly TValue[];
47
58
  /**
48
59
  * The reader's language and the Site's time zone (`usePhiIntlLocale`, `usePhiIntlTimeZone`), for a
49
60
  * provider whose option labels are words, amounts or dates. The hook puts both into every load key,
@@ -109,7 +120,7 @@ export declare function createPhiStaticControlOptionsProviderClient<TValue exten
109
120
  export declare function PhiControlOptionsProviderIsolationBoundary({ children }: {
110
121
  children: ReactNode;
111
122
  }): import("react").FunctionComponentElement<import("react").ProviderProps<ReadonlyMap<`${string}/${string}`, AnyOptionsProviderRegistration>>>;
112
- export declare function usePhiControlOptionsProvider<TValue extends string | number = string>({ options, optionsProvider, sourceConfig, searchDraft, formValues, }: {
123
+ export declare function usePhiControlOptionsProvider<TValue extends string | number = string>({ options, optionsProvider, sourceConfig, searchDraft, formValues, selectedValues, }: {
113
124
  options?: readonly {
114
125
  value: TValue;
115
126
  label?: string;
@@ -130,6 +141,8 @@ export declare function usePhiControlOptionsProvider<TValue extends string | num
130
141
  * passes none, and a `form` dependency simply has no value there.
131
142
  */
132
143
  formValues?: Record<string, unknown> | null;
144
+ /** What the control holds -- one value, a list, or nothing -- as it holds it; read into `selected`. */
145
+ selectedValues?: unknown;
133
146
  }): PhiResolvedControlOptions<TValue> & {
134
147
  search: PhiControlOptionsSearchState;
135
148
  };
@@ -8,6 +8,9 @@ const PhiControlOptionsProviderRegistryContext = createContext(EMPTY_OPTIONS_PRO
8
8
  const EMPTY_PROVIDER_SNAPSHOT = null;
9
9
  /** Shared, so a provider without dependencies keeps the same object across renders. */
10
10
  const EMPTY_DEPENDENCY_VALUES = Object.freeze({});
11
+ /** Shared for the same reason: a control that holds nothing hands every provider the same list. */
12
+ const EMPTY_SELECTED_VALUES = Object.freeze([]);
13
+ const EMPTY_REMEMBERED_OPTIONS = new Map();
11
14
  /** One pause, not one request per keystroke. */
12
15
  const PHI_OPTIONS_SEARCH_DEBOUNCE_MS = 250;
13
16
  const IN_FLIGHT_PROVIDER_LOADS = new WeakMap();
@@ -45,6 +48,41 @@ function normalizeStaticOptions(options) {
45
48
  parentValue: option.parentValue,
46
49
  }));
47
50
  }
51
+ /**
52
+ * What a control holds, as `selected`: read here once, like the search policy. `null` and the `""` a
53
+ * cleared select reports are no value, and only a string or a number can be an option's value.
54
+ */
55
+ function readSelectedValues(value) {
56
+ const entries = Array.isArray(value) ? value : [value];
57
+ return entries.filter((entry) => (typeof entry === "string" && entry !== "") || (typeof entry === "number" && Number.isFinite(entry)));
58
+ }
59
+ function areSameControlOptions(left, right) {
60
+ const leftEntries = Object.entries(left);
61
+ return leftEntries.length === Object.keys(right).length
62
+ && leftEntries.every(([key, entry]) => Object.is(entry, right[key]));
63
+ }
64
+ /**
65
+ * The last option seen for each chosen value; a value no longer chosen is forgotten. Answers with
66
+ * `remembered` itself while nothing changed -- by content, as a resolver may build options afresh -- so
67
+ * storing it during the render does not render again.
68
+ */
69
+ function rememberSelectedOptions(remembered, selected, options) {
70
+ if (selected.length === 0) {
71
+ return remembered.size === 0 ? remembered : EMPTY_REMEMBERED_OPTIONS;
72
+ }
73
+ const next = new Map();
74
+ for (const value of selected) {
75
+ const known = options.find((option) => option.value === value) ?? remembered.get(value);
76
+ if (known)
77
+ next.set(value, known);
78
+ }
79
+ const unchanged = next.size === remembered.size
80
+ && [...next].every(([value, option]) => {
81
+ const previous = remembered.get(value);
82
+ return previous !== undefined && (previous === option || areSameControlOptions(previous, option));
83
+ });
84
+ return unchanged ? remembered : next;
85
+ }
48
86
  export function readPhiControlOptionsProviderParam(provider, key) {
49
87
  const value = provider?.params?.[key];
50
88
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
@@ -130,9 +168,14 @@ export function createPhiStaticControlOptionsProviderClient(registration) {
130
168
  export function PhiControlOptionsProviderIsolationBoundary({ children }) {
131
169
  return createElement(PhiControlOptionsProviderRegistryContext.Provider, { value: EMPTY_OPTIONS_PROVIDER_REGISTRY }, children);
132
170
  }
133
- export function usePhiControlOptionsProvider({ options, optionsProvider, sourceConfig, searchDraft = "", formValues, }) {
171
+ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceConfig, searchDraft = "", formValues, selectedValues, }) {
134
172
  const registry = useContext(PhiControlOptionsProviderRegistryContext);
135
173
  const staticOptions = useMemo(() => normalizeStaticOptions(options), [options]);
174
+ // Keyed by content, so a value list built afresh on every render is still the same `selected`.
175
+ const selectedKey = JSON.stringify(readSelectedValues(selectedValues));
176
+ const selected = useMemo(() => selectedKey === "[]"
177
+ ? EMPTY_SELECTED_VALUES
178
+ : Object.freeze(JSON.parse(selectedKey)), [selectedKey]);
136
179
  /*
137
180
  * The declared search policy, applied in one place. A field states whether its provider can be
138
181
  * searched and from how many characters; the load mode states who narrows the list. Debouncing lives
@@ -188,6 +231,8 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
188
231
  // keystroke, so taking the search into account is the searching provider's own decision.
189
232
  search,
190
233
  dependencies: dependencyValues,
234
+ // Not in the default load key either: a provider that answers with all it has must not reload per choice.
235
+ selected,
191
236
  locale,
192
237
  timeZone,
193
238
  snapshot: providerSnapshot,
@@ -241,7 +286,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
241
286
  providerLoadKey,
242
287
  registeredProvider,
243
288
  ]);
244
- return useMemo(() => {
289
+ const resolved = useMemo(() => {
245
290
  if (!optionsProvider?.providerKey) {
246
291
  return { options: staticOptions, search: searchState };
247
292
  }
@@ -278,6 +323,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
278
323
  sourceConfig,
279
324
  search,
280
325
  dependencies: dependencyValues,
326
+ selected,
281
327
  locale,
282
328
  timeZone,
283
329
  snapshot: providerSnapshot,
@@ -290,6 +336,7 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
290
336
  searchState,
291
337
  dependenciesSatisfied,
292
338
  dependencyValues,
339
+ selected,
293
340
  locale,
294
341
  timeZone,
295
342
  asyncData,
@@ -301,4 +348,28 @@ export function usePhiControlOptionsProvider({ options, optionsProvider, sourceC
301
348
  sourceConfig,
302
349
  staticOptions,
303
350
  ]);
351
+ /*
352
+ * A chosen value keeps the option it was last seen with, for every provider: any answer can leave it
353
+ * out -- the empty list while a new search loads, the next page -- and the control would show the raw
354
+ * value. Added to the list, because the Select finds a chosen value's label among `options`. Filtering
355
+ * locally, the Select hides it like any option that does not match; where the provider answered the
356
+ * search (`filterLocally: false`) it stays at the end, marked as chosen -- the price of keeping its
357
+ * name, and a multiple choice shows its tags while the person types. Stored during the render, so the
358
+ * label survives the very render that drops it; empty until an option resolved, on the server as on
359
+ * the client, so hydration matches.
360
+ */
361
+ const [rememberedOptions, setRememberedOptions] = useState(EMPTY_REMEMBERED_OPTIONS);
362
+ const nextRememberedOptions = rememberSelectedOptions(rememberedOptions, selected, resolved.options);
363
+ if (nextRememberedOptions !== rememberedOptions) {
364
+ setRememberedOptions(nextRememberedOptions);
365
+ }
366
+ return useMemo(() => {
367
+ const missing = selected
368
+ .filter((value) => !resolved.options.some((option) => option.value === value))
369
+ .flatMap((value) => {
370
+ const option = nextRememberedOptions.get(value);
371
+ return option ? [option] : [];
372
+ });
373
+ return missing.length === 0 ? resolved : { ...resolved, options: [...resolved.options, ...missing] };
374
+ }, [nextRememberedOptions, resolved, selected]);
304
375
  }
@@ -4,9 +4,9 @@ import type { PhiFormRenderContext } from "./form-resolution";
4
4
  /**
5
5
  * What a Form's field types say for themselves, under the keys their controls read.
6
6
  *
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`), 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
7
+ * The `media-asset` and `media-assets` fields are the same: the picker they open and the upload surface
8
+ * say the Media Label Set's words, read here for every Form that has such a field
9
+ * (`media-asset-field-keys.ts`), and the upload says its refusals and its hold under the upload field's keys. The `table` field says its add, remove and
10
10
  * empty words from Core's `widget:table` set (`table-field-labels.ts`) where its config names none.
11
11
  *
12
12
  * A field type whose control speaks -- the upload field's trigger, its drop hint, its holds and the
@@ -1,7 +1,7 @@
1
1
  import "server-only";
2
2
  import { getPhiMediaWidgetLabels } from "../media/label-sets/media";
3
3
  import { getPhiMediaUploadLabels } from "../media/label-sets/media-upload";
4
- import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY } from "../../constants/media-library-provider-keys";
4
+ import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY, PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY, } from "../../constants/media-library-provider-keys";
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";
@@ -11,9 +11,9 @@ import { PHI_FORM_TABLE_LABEL_KEYS } from "./table-field-labels";
11
11
  /**
12
12
  * What a Form's field types say for themselves, under the keys their controls read.
13
13
  *
14
- * The `media-asset` field is the same: the picker it opens says the Media Label Set's words, read here
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
14
+ * The `media-asset` and `media-assets` fields are the same: the picker they open and the upload surface
15
+ * say the Media Label Set's words, read here for every Form that has such a field
16
+ * (`media-asset-field-keys.ts`), and the upload says its refusals and its hold under the upload field's keys. The `table` field says its add, remove and
17
17
  * empty words from Core's `widget:table` set (`table-field-labels.ts`) where its config names none.
18
18
  *
19
19
  * A field type whose control speaks -- the upload field's trigger, its drop hint, its holds and the
@@ -27,7 +27,8 @@ import { PHI_FORM_TABLE_LABEL_KEYS } from "./table-field-labels";
27
27
  */
28
28
  export async function resolvePhiFormFieldLabels(context, descriptor) {
29
29
  const hasUpload = descriptor.fields.some((field) => field.fieldProviderKey === PHI_FORM_UPLOAD_FIELD_PROVIDER_KEY);
30
- const hasMediaAsset = descriptor.fields.some((field) => field.fieldProviderKey === PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY);
30
+ const hasMediaAsset = descriptor.fields.some((field) => field.fieldProviderKey === PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY ||
31
+ field.fieldProviderKey === PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY);
31
32
  const hasTable = descriptor.fields.some((field) => field.fieldProviderKey === PHI_FORM_TABLE_FIELD_PROVIDER_KEY);
32
33
  if (!hasUpload && !hasMediaAsset && !hasTable)
33
34
  return {};
@@ -86,6 +87,13 @@ async function readMediaAssetFieldLabels(options) {
86
87
  [keys.importingLabel]: picker.importingLabel,
87
88
  [keys.importFailedText]: picker.importFailedText,
88
89
  [keys.loadMoreLabel]: picker.loadMoreLabel,
90
+ [keys.chooseFromLibraryLabel]: tool.chooseFromLibraryLabel,
89
91
  [keys.uploadLabel]: upload.uploadToggleLabel,
92
+ [keys.uploadDropTitle]: upload.dropTitle,
93
+ [keys.uploadDropHint]: upload.dropHint,
94
+ [keys.uploadRetryLabel]: upload.retryLabel,
95
+ [keys.uploadDoneLabel]: upload.doneLabel,
96
+ [keys.uploadFailedLabel]: upload.failedLabel,
97
+ [keys.uploadSuccessTemplate]: upload.uploadSuccessTemplate,
90
98
  };
91
99
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The `media-asset` field's picker words, under the keys its control reads them from.
2
+ * The `media-asset` and `media-assets` fields' picker words, under the keys their controls read them from.
3
3
  *
4
4
  * The field opens the Media library's own picker, and the picker's words are the Media Label Set's
5
5
  * (`getPhiMediaWidgetLabels`). The Form Widget reads that set on the Server for every Form that has a
@@ -25,6 +25,14 @@ export declare const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS: {
25
25
  readonly importingLabel: "mediaAssetPickerImporting";
26
26
  readonly importFailedText: "mediaAssetPickerImportFailed";
27
27
  readonly loadMoreLabel: "mediaAssetPickerLoadMore";
28
+ /** The `media-assets` field's button that opens the picker (the Media Label Set's "Choose from Media library"). */
29
+ readonly chooseFromLibraryLabel: "mediaAssetPickerChooseFromLibrary";
28
30
  /** The picker's upload button (the Media Label Set's upload toggle). */
29
31
  readonly uploadLabel: "mediaAssetPickerUpload";
32
+ readonly uploadDropTitle: "mediaAssetPickerUploadDropTitle";
33
+ readonly uploadDropHint: "mediaAssetPickerUploadDropHint";
34
+ readonly uploadRetryLabel: "mediaAssetPickerUploadRetry";
35
+ readonly uploadDoneLabel: "mediaAssetPickerUploadDone";
36
+ readonly uploadFailedLabel: "mediaAssetPickerUploadFailed";
37
+ readonly uploadSuccessTemplate: "mediaAssetPickerUploadSuccess";
30
38
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The `media-asset` field's picker words, under the keys its control reads them from.
2
+ * The `media-asset` and `media-assets` fields' picker words, under the keys their controls read them from.
3
3
  *
4
4
  * The field opens the Media library's own picker, and the picker's words are the Media Label Set's
5
5
  * (`getPhiMediaWidgetLabels`). The Form Widget reads that set on the Server for every Form that has a
@@ -25,6 +25,18 @@ export const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS = {
25
25
  importingLabel: "mediaAssetPickerImporting",
26
26
  importFailedText: "mediaAssetPickerImportFailed",
27
27
  loadMoreLabel: "mediaAssetPickerLoadMore",
28
+ /** The `media-assets` field's button that opens the picker (the Media Label Set's "Choose from Media library"). */
29
+ chooseFromLibraryLabel: "mediaAssetPickerChooseFromLibrary",
28
30
  /** The picker's upload button (the Media Label Set's upload toggle). */
29
31
  uploadLabel: "mediaAssetPickerUpload",
32
+ /*
33
+ * The upload surface the button shows, the Media library's own (`PhiAreaUploadBinding`): its drop area,
34
+ * the state of the file on its way, and the message once it arrived (`widget:upload`'s `area_*`).
35
+ */
36
+ uploadDropTitle: "mediaAssetPickerUploadDropTitle",
37
+ uploadDropHint: "mediaAssetPickerUploadDropHint",
38
+ uploadRetryLabel: "mediaAssetPickerUploadRetry",
39
+ uploadDoneLabel: "mediaAssetPickerUploadDone",
40
+ uploadFailedLabel: "mediaAssetPickerUploadFailed",
41
+ uploadSuccessTemplate: "mediaAssetPickerUploadSuccess",
30
42
  };
@@ -27,6 +27,7 @@ const PHI_MEDIA_WIDGET_LABEL_SET = definePhiLabelSet({
27
27
  tool_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.kindLabel,
28
28
  tool_reset_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.resetLabel,
29
29
  tool_reload_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.reloadLabel,
30
+ tool_choose_from_library_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.chooseFromLibraryLabel,
30
31
  tool_image_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.imageKindLabel,
31
32
  tool_video_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.videoKindLabel,
32
33
  tool_audio_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.audioKindLabel,
@@ -45,6 +46,7 @@ const PHI_MEDIA_WIDGET_LABEL_SET = definePhiLabelSet({
45
46
  grid_delete_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteLabel,
46
47
  grid_delete_success_template: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteSuccessTemplate),
47
48
  grid_delete_failed_text: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteFailedText),
49
+ grid_add_failed_text: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.addFailedText),
48
50
  picker_trigger_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.triggerLabel,
49
51
  picker_popover_title: PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.popoverTitle,
50
52
  picker_empty_description: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.emptyDescription),
@@ -82,6 +84,7 @@ export async function getPhiMediaWidgetLabels(options) {
82
84
  kindLabel: labels.tool_kind_label,
83
85
  resetLabel: labels.tool_reset_label,
84
86
  reloadLabel: labels.tool_reload_label,
87
+ chooseFromLibraryLabel: labels.tool_choose_from_library_label,
85
88
  imageKindLabel: labels.tool_image_kind_label,
86
89
  videoKindLabel: labels.tool_video_kind_label,
87
90
  audioKindLabel: labels.tool_audio_kind_label,
@@ -103,6 +106,7 @@ export async function getPhiMediaWidgetLabels(options) {
103
106
  deleteLabel: labels.grid_delete_label,
104
107
  deleteSuccessTemplate: labels.grid_delete_success_template,
105
108
  deleteFailedText: labels.grid_delete_failed_text,
109
+ addFailedText: labels.grid_add_failed_text,
106
110
  },
107
111
  picker: {
108
112
  triggerLabel: labels.picker_trigger_label,
@@ -15,3 +15,17 @@ export declare function findPhiMediaFolderByNamePath(folders: readonly Pick<PhiM
15
15
  folderId: number | null;
16
16
  depth: number;
17
17
  };
18
+ /**
19
+ * Whether a Folder path setting is one whose placeholders read `{key}`: every brace opens or closes one
20
+ * (`{}`, `{a`, `a}`, `{a{b}}` do not). What the `media-asset` field's `folderPath` and the Media
21
+ * renderer's `features.media.folderPath` are held to.
22
+ */
23
+ export declare function isPhiMediaFolderPathTemplate(value: string): boolean;
24
+ /**
25
+ * The Folder path a template of names (`splitPhiMediaFolderNamePath` of a setting) names for these
26
+ * values: each `{key}` the value under `key` -- the `media-asset` field's Form values, the Collection
27
+ * View's binding params for the Media renderer. A name whose placeholder has no value is left out whole
28
+ * -- "Shop Images / {category} / {product}" without a category is "Shop Images / <product>" -- and a name
29
+ * that comes out empty is left out too.
30
+ */
31
+ export declare function resolvePhiMediaFolderPathTemplate(folderPath: readonly string[], values: Readonly<Record<string, unknown>>): string[];
@@ -1,8 +1,9 @@
1
+ import { readPhiDotPath } from "../../helpers/dot-path";
1
2
  /*
2
3
  * A Folder named by its path of names rather than its id: what a setting states that a preset writes for
3
4
  * every Site (the `area-upload` Widget's `folderPath`) and what the Asset Controller's `path` signal may
4
- * carry. Pure and without runtime imports, because the upload transport reads it and every upload surface carries
5
- * the transport.
5
+ * carry -- with the `{key}` placeholders a path setting may hold. Pure and without runtime imports beyond
6
+ * the dot-path reader, because the upload transport reads it and every upload surface carries the transport.
6
7
  */
7
8
  /**
8
9
  * A Folder named by its path, written the way a person types it and Core reads it: names from the root
@@ -34,3 +35,40 @@ export function findPhiMediaFolderByNamePath(folders, path) {
34
35
  }
35
36
  return { folderId, depth };
36
37
  }
38
+ /* `{key}`: a value's key, a dotted path into it for a value that is a record. */
39
+ const PHI_MEDIA_FOLDER_PATH_PLACEHOLDER = /\{([A-Za-z0-9_.-]+)\}/gu;
40
+ /**
41
+ * Whether a Folder path setting is one whose placeholders read `{key}`: every brace opens or closes one
42
+ * (`{}`, `{a`, `a}`, `{a{b}}` do not). What the `media-asset` field's `folderPath` and the Media
43
+ * renderer's `features.media.folderPath` are held to.
44
+ */
45
+ export function isPhiMediaFolderPathTemplate(value) {
46
+ return !/[{}]/u.test(value.replace(PHI_MEDIA_FOLDER_PATH_PLACEHOLDER, ""));
47
+ }
48
+ /*
49
+ * A value as a Folder name: a text or a number, trimmed, and a `/` in it a `-`, so a value can name a
50
+ * Folder but never add a level of them. Anything else -- empty, absent, a list, a record -- is no name.
51
+ */
52
+ function readPhiMediaFolderPathValue(value) {
53
+ const text = typeof value === "string" ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : "";
54
+ return text.replace(/\//gu, "-").replace(/\s+/gu, " ").trim();
55
+ }
56
+ /**
57
+ * The Folder path a template of names (`splitPhiMediaFolderNamePath` of a setting) names for these
58
+ * values: each `{key}` the value under `key` -- the `media-asset` field's Form values, the Collection
59
+ * View's binding params for the Media renderer. A name whose placeholder has no value is left out whole
60
+ * -- "Shop Images / {category} / {product}" without a category is "Shop Images / <product>" -- and a name
61
+ * that comes out empty is left out too.
62
+ */
63
+ export function resolvePhiMediaFolderPathTemplate(folderPath, values) {
64
+ return folderPath.flatMap((segment) => {
65
+ let missing = false;
66
+ const resolved = segment.replace(PHI_MEDIA_FOLDER_PATH_PLACEHOLDER, (_placeholder, key) => {
67
+ const value = readPhiMediaFolderPathValue(readPhiDotPath(values, key));
68
+ if (!value)
69
+ missing = true;
70
+ return value;
71
+ }).replace(/\s+/gu, " ").trim();
72
+ return missing || !resolved ? [] : [resolved];
73
+ });
74
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The Media library's own Collection resource, `assets` of `PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection`,
3
+ * as the Asset Module declares it (`plugins/runtime-modules/asset/data-providers.ts` names this object):
4
+ * its filters, its Folder, lock, upload and delete actions, and its upload panel -- what the Media
5
+ * renderer offers for it (COLLECTIONS.md, "The Media renderer").
6
+ *
7
+ * The Foundation's, like the keys beside it, because a Foundation surface binds that resource without a
8
+ * page's registry and still has to hand the renderer its declaration: the Media preview grid
9
+ * (`PhiAssetPreviewGridWidget`). One object, so the declaration the Area's registry holds and the one the
10
+ * grid hands over cannot say different things.
11
+ */
12
+ export declare const PHI_MEDIA_LIBRARY_ASSET_RESOURCE: {
13
+ readonly resourceKey: "assets";
14
+ readonly title: "Assets";
15
+ readonly itemIdentityPath: "id";
16
+ readonly itemRendererKey: `${string}/${string}`;
17
+ readonly selectionValueSchema: `${string}/signals/${string}`;
18
+ readonly defaultForWidget: true;
19
+ readonly query: {
20
+ readonly search: true;
21
+ readonly pagination: true;
22
+ readonly filterFields: readonly [{
23
+ readonly key: "kind";
24
+ readonly title: "Kind";
25
+ readonly type: "enum[]";
26
+ }, {
27
+ readonly key: "presentationFlags";
28
+ readonly title: "Flags";
29
+ readonly type: "enum[]";
30
+ }, {
31
+ readonly key: "folderId";
32
+ readonly title: "Folder";
33
+ readonly type: "path";
34
+ }];
35
+ };
36
+ readonly actions: readonly [{
37
+ readonly key: "createFolder";
38
+ readonly title: "Create folder";
39
+ readonly scope: "resource";
40
+ }, {
41
+ readonly key: "lockFolder";
42
+ readonly title: "Lock folder";
43
+ readonly scope: "resource";
44
+ }, {
45
+ readonly key: "unlockFolder";
46
+ readonly title: "Unlock folder";
47
+ readonly scope: "resource";
48
+ }, {
49
+ readonly key: "upload";
50
+ readonly title: "Upload";
51
+ readonly scope: "resource";
52
+ readonly panelKey: "upload";
53
+ }, {
54
+ readonly key: "refresh";
55
+ readonly title: "Reload";
56
+ readonly scope: "resource";
57
+ }, {
58
+ readonly key: "update";
59
+ readonly title: "Update";
60
+ readonly scope: "item";
61
+ }, {
62
+ readonly key: "delete";
63
+ readonly title: "Delete";
64
+ readonly scope: "item";
65
+ }];
66
+ readonly panels: readonly [{
67
+ readonly key: "upload";
68
+ readonly title: "Upload assets";
69
+ }];
70
+ };