@phis/ui 0.7.3 → 0.7.4

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 (65) hide show
  1. package/components/controls/phi-media-asset-tile-control.d.ts +4 -3
  2. package/components/controls/phi-media-picker-control.d.ts +9 -11
  3. package/components/controls/phi-media-picker-control.js +9 -11
  4. package/components/forms/form-field-labels.d.ts +3 -3
  5. package/components/forms/form-field-labels.js +13 -5
  6. package/components/forms/media-asset-field-keys.d.ts +9 -1
  7. package/components/forms/media-asset-field-keys.js +13 -1
  8. package/components/media/label-sets/media.js +4 -0
  9. package/components/media/media-folder-name-path.d.ts +14 -0
  10. package/components/media/media-folder-name-path.js +40 -2
  11. package/components/media/media-library-resource.d.ts +70 -0
  12. package/components/media/media-library-resource.js +41 -0
  13. package/components/media/media-widget-labels.d.ts +13 -0
  14. package/components/media/media-widget-labels.js +2 -0
  15. package/components/media/phi-area-upload-widget.d.ts +31 -1
  16. package/components/media/phi-area-upload-widget.js +33 -7
  17. package/components/media/phi-image-preview-data.d.ts +8 -1
  18. package/components/media/phi-image-preview-data.js +29 -0
  19. package/components/media/phi-media-picker-binding.d.ts +22 -20
  20. package/components/media/phi-media-picker-binding.js +20 -33
  21. package/components/media/use-media-library-add-picker.d.ts +94 -0
  22. package/components/media/use-media-library-add-picker.js +40 -0
  23. package/constants/media-library-provider-keys.d.ts +7 -0
  24. package/constants/media-library-provider-keys.js +7 -0
  25. package/constants/runtime-module-ownership.js +1 -0
  26. package/helpers/preset-tree-contract-check.d.ts +35 -0
  27. package/helpers/preset-tree-contract-check.js +211 -0
  28. package/module-page-check.d.ts +6 -0
  29. package/module-page-check.js +6 -0
  30. package/package.json +1 -1
  31. package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
  32. package/plugins/runtime-modules/asset/data-providers.js +4 -32
  33. package/plugins/runtime-modules/asset/definition.d.ts +115 -38
  34. package/plugins/runtime-modules/asset/definition.js +2 -1
  35. package/plugins/runtime-modules/asset/form-providers.d.ts +85 -2
  36. package/plugins/runtime-modules/asset/form-providers.js +70 -11
  37. package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
  38. package/plugins/runtime-modules/asset/media-asset-field.d.ts +7 -7
  39. package/plugins/runtime-modules/asset/media-asset-field.js +11 -33
  40. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +8 -7
  41. package/plugins/runtime-modules/asset/media-asset-form-control.js +42 -83
  42. package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
  43. package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
  44. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
  45. package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
  46. package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
  47. package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
  48. package/plugins/runtime-modules/asset/services/collection.js +12 -0
  49. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
  50. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
  51. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
  52. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
  53. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +7 -2
  54. package/plugins/runtime-modules/core/widgets/collection-view/client.js +12 -4
  55. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +25 -0
  56. package/plugins/runtime-modules/core/widgets/collection-view/config.js +34 -0
  57. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
  58. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +3 -2
  59. package/plugins/runtime-modules/core/widgets/collection-view/server.js +20 -18
  60. package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
  61. package/plugins/runtime-modules/descriptor-compiler.js +9 -204
  62. package/plugins/runtime-modules/resolver.js +31 -5
  63. package/types/collection-view-widget.d.ts +19 -0
  64. package/types/core-widget-placements.d.ts +9 -0
  65. package/types/media.d.ts +16 -0
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { isPhiRecord } from "../../../../../helpers/is-record";
4
4
  import { useCallback, useEffect, useMemo, useState } from "react";
5
5
  import { PhiMediaAssetFlags, PhiMediaKind } from "../../../../../constants/media";
6
+ import { PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS } from "../../../../../constants/media-library-provider-keys";
6
7
  import { createPhiSignalSubcontrolAddress } from "../../../../../types/signals";
7
8
  import { normalizePhiCssSize } from "../../../../../components/layouts/phi-layout-contract";
8
9
  import { PhiAlertControl } from "../../../../../components/controls/phi-alert-control";
@@ -25,10 +26,14 @@ import { PhiWidgetFailure } from "../../../../../components/widgets/shared/widge
25
26
  import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
26
27
  import { PHI_ASSET_CONTROLLER_STORE_KEY } from "../../../../../components/media/asset-controller-signals";
27
28
  import { applyPhiAssetCollectionData } from "../../../../../components/media/asset-collection-runtime";
28
- import { readPhiMediaAssetTiles, readPhiMediaFolders } from "../../../../../components/media/phi-image-preview-data";
29
+ import { readPhiMediaAssetTiles, readPhiMediaCollectionItems, readPhiMediaFolders, } from "../../../../../components/media/phi-image-preview-data";
29
30
  import { PhiAssetFolderControl } from "../../../../../components/media/phi-asset-folder-control";
30
31
  import { isPhiMediaFolderIdLocked, isPhiMediaFolderLockedError, } from "../../../../../components/media/media-folder-lock";
31
32
  import { PhiAreaUploadBinding } from "../../../../../components/media/phi-area-upload-widget";
33
+ import { PhiMediaPickerControl } from "../../../../../components/controls/phi-media-picker-control";
34
+ import { usePhiMediaLibraryAddPicker } from "../../../../../components/media/use-media-library-add-picker";
35
+ import { resolvePhiMediaFolderPathTemplate, splitPhiMediaFolderNamePath, } from "../../../../../components/media/media-folder-name-path";
36
+ import { PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY, readPhiMediaRendererResourceActions, readPhiMediaRendererToolFailure, } from "./asset-binding-tools";
32
37
  import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../../../components/media/media-widget-labels";
33
38
  import { setPhiImagePreviewSelection, usePhiImagePreviewStore } from "../../../../../components/media/phi-image-preview-store";
34
39
  const ASSET_FLAG_VALUES = [
@@ -62,7 +67,29 @@ function overlayPhiAssetLabels(base, override) {
62
67
  }
63
68
  return result;
64
69
  }
65
- export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabels, widgetId, renderMode, }) {
70
+ /**
71
+ * The Media renderer (`PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY`): the items of a Collection as Media tiles,
72
+ * for whichever Provider names it -- the Media library's own Collection, and any Collection of Assets
73
+ * (a gallery of references) whose resource names it as its `itemRendererKey`, or whose placement does.
74
+ *
75
+ * - **Items** are read in the Media tile shape (`PhiMediaCollectionItem`, `readPhiMediaCollectionItems`);
76
+ * the Media library's own as its whole tiles.
77
+ * - **Tools** follow what the resource declares (`readPhiMediaRendererToolFailure`): a Folder, lock,
78
+ * new-Folder or flag tool the placement names but the resource does not declare is a failure, not a
79
+ * control that does nothing. A tile's delete is the resource's `delete`, in the words the placement's
80
+ * `presentation.labels.grid` gives (a gallery's "Remove from gallery").
81
+ * - **Upload** is the resource's `upload` panel, the Media library's multi-upload wall, into
82
+ * `features.media.folderPath` with `{param}` filled from the binding params. Where the resource
83
+ * declares `add`, what arrived is added to it (`itemKeys`, the Asset ids) -- the Provider's answer shows
84
+ * it at once, then the Collection is read again -- and leaves the wall, so it is not shown twice.
85
+ * - **Choose from Media library** (toolbar action `add`) opens the library's picker on the same Folder;
86
+ * the pick goes to the same `add` action.
87
+ * - **The Asset Controller's store** (the selection, the Space selector) is fed by the Media library's
88
+ * own Collection only; a tile of another Collection is not selected.
89
+ *
90
+ * Drag reordering (`features.reorder`) is the Collection View's, around these tiles.
91
+ */
92
+ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabels, widgetId, renderMode, resource, }) {
66
93
  /*
67
94
  * The English defaults, under what the server half loaded for this Widget (`rawLabels`, the Media Label
68
95
  * Set in the reader's language), under what the Widget's own configuration says.
@@ -70,17 +97,24 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
70
97
  const labels = useMemo(() => overlayPhiAssetLabels(overlayPhiAssetLabels(PHI_MEDIA_WIDGET_DEFAULT_LABELS, rawLabels), config.presentation.labels), [config.presentation.labels, rawLabels]);
71
98
  const { token } = usePhiConfig();
72
99
  const { showMessage } = usePhiApplicationFeedback();
73
- const selectionState = usePhiImagePreviewStore(PHI_ASSET_CONTROLLER_STORE_KEY);
100
+ // The Media library's own Collection, the one whose answer is the Asset Controller's store.
101
+ const isMediaLibrary = config.source?.providerKey === PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection;
102
+ const resourceActions = readPhiMediaRendererResourceActions(resource);
103
+ const toolFailure = readPhiMediaRendererToolFailure({ config, resource });
104
+ const storeState = usePhiImagePreviewStore(PHI_ASSET_CONTROLLER_STORE_KEY);
74
105
  const query = binding.query;
75
106
  const setQuery = binding.setQuery;
107
+ const sourceName = `The collection "${config.source?.resourceKey ?? "unknown"}"`;
76
108
  // A Collection carries items of no particular type; they are read as tiles, not cast to them.
77
- const assets = useMemo(() => readPhiMediaAssetTiles(binding.data?.items ?? []), [binding.data?.items]);
109
+ const mediaTiles = useMemo(() => isMediaLibrary ? readPhiMediaAssetTiles(binding.data?.items ?? []) : null, [binding.data?.items, isMediaLibrary]);
110
+ const assets = useMemo(() => mediaTiles ?? readPhiMediaCollectionItems(binding.data?.items ?? [], sourceName), [binding.data?.items, mediaTiles, sourceName]);
78
111
  const folders = useMemo(() => readPhiMediaFolders(binding.data?.meta?.folders), [binding.data?.meta?.folders]);
79
112
  const queryKind = query.filters?.kind;
80
113
  const queryFlags = query.filters?.presentationFlags;
81
114
  const queryFolderId = query.filters?.folderId;
82
115
  const state = {
83
- ...selectionState,
116
+ selectedAssetId: isMediaLibrary ? storeState.selectedAssetId : null,
117
+ selectedVariantKey: storeState.selectedVariantKey,
84
118
  searchQuery: query.search ?? "",
85
119
  folderId: typeof queryFolderId === "number" ? queryFolderId : null,
86
120
  kinds: readAssetKinds(queryKind),
@@ -93,13 +127,13 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
93
127
  pagination: { total: binding.data?.total ?? 0 },
94
128
  loading: binding.loading,
95
129
  error: binding.error,
96
- uploadPanelOpen: binding.openPanelKey === "upload",
130
+ uploadPanelOpen: binding.openPanelKey === PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY,
97
131
  };
98
132
  useEffect(() => {
99
- if (binding.data) {
133
+ if (isMediaLibrary && binding.data) {
100
134
  applyPhiAssetCollectionData(binding.data);
101
135
  }
102
- }, [binding.data]);
136
+ }, [binding.data, isMediaLibrary]);
103
137
  const onSearchChange = useCallback((search) => setQuery((current) => ({ ...current, page: 1, search })), [setQuery]);
104
138
  const { draft: searchDraft, setDraft: setSearchDraft } = usePhiSearchDraft({
105
139
  query: state.searchQuery,
@@ -118,8 +152,9 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
118
152
  const spaceSelectionAllowed = usePhiMediaSpaceSelectionAllowed();
119
153
  const activeSpaceAddress = typeof query.filters?.spaceId === "string" && query.filters.spaceId
120
154
  ? query.filters.spaceId
121
- : selectionState.activeSpace?.address ?? null;
122
- const spaceOptions = useMemo(() => buildPhiMediaSpaceOptions(selectionState.spaces, labels.space), [labels.space, selectionState.spaces]);
155
+ : storeState.activeSpace?.address ?? null;
156
+ // The Spaces are the Media library's to answer; another Collection's items are of the Site Space.
157
+ const spaceOptions = useMemo(() => buildPhiMediaSpaceOptions(isMediaLibrary ? storeState.spaces : [], labels.space), [isMediaLibrary, labels.space, storeState.spaces]);
123
158
  const presentation = config.presentation;
124
159
  const features = config.features;
125
160
  const controlSize = presentation.controlSize ?? "small";
@@ -127,12 +162,15 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
127
162
  const gap = normalizePhiCssSize(presentation.gap) ?? token.paddingSM;
128
163
  const minColumnWidth = normalizePhiCssSize(presentation.minColumnWidth) ?? 102;
129
164
  const selfContained = features.tools.mode === "self-contained";
130
- const unsupportedFilter = features.filters?.find((filter) => !["kind", "presentationFlags", "folderId"].includes(filter.key));
131
- const configuredActions = [
132
- ...(features.actions?.toolbar ?? []),
133
- ...(features.filters ?? []).flatMap((filter) => filter.actions ?? []),
134
- ];
135
- const unsupportedAction = configuredActions.find((action) => action.key !== "upload" && action.key !== "createFolder" && action.key !== "lockFolder");
165
+ /*
166
+ * Where an upload goes and the picker opens (`features.media.folderPath`), its `{param}` names filled
167
+ * from the binding params the Provider is asked with -- what a Controller told this Collection about the
168
+ * record it shows. Resolved per render, so a new set of params moves both.
169
+ */
170
+ const bindingParams = config.source?.params;
171
+ const folderPath = useMemo(() => resolvePhiMediaFolderPathTemplate(splitPhiMediaFolderNamePath(features.media?.folderPath), isPhiRecord(bindingParams) ? bindingParams : {}), [bindingParams, features.media?.folderPath]);
172
+ const mediaType = features.media?.mediaType ?? null;
173
+ const uploadAcceptance = useMemo(() => mediaType ? { kinds: [mediaType] } : undefined, [mediaType]);
136
174
  const folderOptions = useMemo(() => buildPhiMediaFolderCascaderOptions(state.folders, { lockedLabel: labels.tool.folderLockedLabel }), [labels.tool.folderLockedLabel, state.folders]);
137
175
  /*
138
176
  * The Folder the listing is filtered to, locked: Core refuses a new Folder in it, an upload into it and
@@ -159,10 +197,42 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
159
197
  valueType: "json",
160
198
  typeKey: "collection-action",
161
199
  });
162
- if (unsupportedFilter || unsupportedAction) {
163
- return (_jsx(PhiWidgetFailure, { renderMode: renderMode, widgetType: PhiCmsWidgetType.CollectionView, widgetId: widgetId, title: unsupportedFilter
164
- ? `Asset collection filter "${unsupportedFilter.key}" is not supported.`
165
- : `Asset collection action "${unsupportedAction?.key ?? "unknown"}" is not supported.` }));
200
+ /*
201
+ * Adds Assets of the Media library to the bound resource (its `add` action, `itemKeys` the Asset ids):
202
+ * what an upload made, or what was picked. The Provider answers the Collection as it now stands, which
203
+ * the binding shows at once; then it is read again.
204
+ */
205
+ const addAssets = useCallback(async (assetIds) => {
206
+ try {
207
+ const data = await binding.activate({ actionKey: "add", itemKeys: [...assetIds], query });
208
+ if (data.error)
209
+ throw new Error(data.error);
210
+ binding.reload();
211
+ }
212
+ catch (error) {
213
+ showMessage({
214
+ level: "error",
215
+ content: error instanceof Error && error.message ? error.message : labels.grid.addFailedText,
216
+ durationSeconds: 2.8,
217
+ });
218
+ }
219
+ }, [binding, labels.grid.addFailedText, query, showMessage]);
220
+ /*
221
+ * The Media library's picker, for the toolbar action `add`: the Site Space only, opening on the
222
+ * resolved Folder path (read, nothing written), the kind `features.media.mediaType` names (images where
223
+ * none). Every Asset of the Site Space is delivered publicly from the start (`defaultMediaDeliveryPolicy`
224
+ * in phis-server), so there is nothing to grey out; what the resource's `add` takes, it decides. A pick
225
+ * is added; the picker has no upload of its own here -- the Collection's upload panel is that.
226
+ */
227
+ const readFolderPath = useCallback(() => folderPath, [folderPath]);
228
+ const libraryPicker = usePhiMediaLibraryAddPicker({
229
+ mediaType,
230
+ labels,
231
+ folderPath: folderPath.length > 0 ? readFolderPath : null,
232
+ onAssetSelect: (picked) => { void addAssets([picked.id]); },
233
+ });
234
+ if (toolFailure) {
235
+ return (_jsx(PhiWidgetFailure, { renderMode: renderMode, widgetType: PhiCmsWidgetType.CollectionView, widgetId: widgetId, title: toolFailure }));
166
236
  }
167
237
  function readActionFailure(error, fallback) {
168
238
  if (isPhiMediaFolderLockedError(error))
@@ -217,9 +287,13 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
217
287
  setDeletingAssetIds((current) => current.filter((id) => id !== asset.id));
218
288
  }
219
289
  }
290
+ // The Media library's own tiles only: a selection is the Asset Controller's, which reads that library.
220
291
  function selectAsset(asset) {
221
- setPhiImagePreviewSelection(PHI_ASSET_CONTROLLER_STORE_KEY, asset.id, state.selectedVariantKey ?? null, asset);
222
- selectionSignals.emitCapability("selection", { area: PHI_ASSET_CONTROLLER_STORE_KEY, assetId: asset.id });
292
+ const tile = mediaTiles?.find((entry) => entry.id === asset.id);
293
+ if (!tile)
294
+ return;
295
+ setPhiImagePreviewSelection(PHI_ASSET_CONTROLLER_STORE_KEY, tile.id, state.selectedVariantKey ?? null, tile);
296
+ selectionSignals.emitCapability("selection", { area: PHI_ASSET_CONTROLLER_STORE_KEY, assetId: tile.id });
223
297
  }
224
298
  const filters = selfContained ? (_jsxs(_Fragment, { children: [spaceSelectionAllowed && spaceOptions.length > 1 ? (_jsx(PhiSelectControl, { value: activeSpaceAddress ?? undefined, options: spaceOptions, placeholder: labels.space.label, size: controlSize, style: { minWidth: 140 }, onChange: (value) => {
225
299
  if (typeof value !== "string" || !value)
@@ -293,8 +367,14 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
293
367
  }), features.search?.enabled ? (_jsx(PhiTextControl, { inputType: "search", value: searchDraft, placeholder: features.search.placeholder ?? labels.tool.searchPlaceholder, ariaLabel: features.search.placeholder ?? labels.tool.searchPlaceholder, size: controlSize, style: { flex: "1 1 12rem", minWidth: normalizePhiCssSize(features.search.minWidth) ?? "10rem" }, onChange: (value) => setSearchDraft(value ?? "") })) : null] })) : null;
294
368
  const toolbar = selfContained && ((features.actions?.toolbar?.length ?? 0) > 0 || features.tools.reset || features.tools.reload) ? (_jsxs(PhiToolbarControl, { compact: true, size: controlSize, children: [(features.actions?.toolbar ?? []).map((action) => {
295
369
  const display = action.display ?? "icon";
296
- const label = action.label ?? (action.key === "upload" ? labels.upload.uploadToggleLabel : action.key);
297
- return (_jsx(PhiButtonControl, { label: display === "icon" ? undefined : label, ariaLabel: label, tooltip: action.description, icon: display === "label" || !action.icon ? undefined : resolvePhiButtonIcon(action.icon), type: action.mode === "primary" ? "primary" : "default", danger: action.mode === "danger", size: controlSize, disabled: action.key === "upload" && currentFolderLocked, onClick: action.key === "upload" ? () => binding.setOpenPanelKey(state.uploadPanelOpen ? null : "upload") : undefined }, action.key));
370
+ const label = action.label ?? (action.key === "upload" ? labels.upload.uploadToggleLabel
371
+ : action.key === "add" ? labels.tool.chooseFromLibraryLabel
372
+ : action.key);
373
+ const button = (_jsx(PhiButtonControl, { label: display === "icon" ? undefined : label, ariaLabel: label, tooltip: action.description, icon: display === "label" || !action.icon ? undefined : resolvePhiButtonIcon(action.icon), type: action.mode === "primary" ? "primary" : "default", danger: action.mode === "danger", size: controlSize, disabled: action.key === "upload" && currentFolderLocked, onClick: action.key === "upload" ? () => binding.setOpenPanelKey(state.uploadPanelOpen ? null : PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY) : undefined }, action.key));
374
+ // The picker opens from its own button: the popover's trigger.
375
+ return action.key === "add"
376
+ ? _jsx(PhiMediaPickerControl, { ...libraryPicker, trigger: _jsx("span", { children: button }) }, action.key)
377
+ : button;
298
378
  }), features.tools.reset ? (_jsx(PhiButtonControl, { ariaLabel: labels.tool.resetLabel, tooltip: labels.tool.resetLabel, icon: resolvePhiButtonIcon("antd:rollback-outlined"), size: controlSize, onClick: () => binding.setQuery({
299
379
  ...(config.initialQuery ?? {}),
300
380
  page: config.initialQuery?.page ?? 1,
@@ -303,18 +383,31 @@ export function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabe
303
383
  }) })) : null, features.tools.reload ? (_jsx(PhiButtonControl, { ariaLabel: labels.tool.reloadLabel, tooltip: labels.tool.reloadLabel, icon: resolvePhiButtonIcon("reload"), size: controlSize, onClick: binding.reload })) : null] })) : null;
304
384
  const awaitingInitialPayload = binding.data == null && !state.error;
305
385
  const body = state.error ? null : awaitingInitialPayload ? (_jsx(PhiMediaAssetCollectionSkeletonControl, { mode: mode, gap: gap, minColumnWidth: minColumnWidth })) : state.assets.length === 0 ? (_jsx(PhiEmptyControl, { description: presentation.emptyDescription ?? labels.grid.emptyDescription })) : undefined;
306
- return (_jsx(PhiCollectionViewControl, { title: presentation.title, description: presentation.description, filters: filters, toolbar: toolbar, panel: state.uploadPanelOpen ? (_jsx(PhiAreaUploadBinding, { labels: labels.upload, onUploadComplete: binding.reload, collectionContext: {
307
- folders: state.folders,
308
- folderId: state.folderId,
309
- folderPath: null,
310
- presentationFlags: state.presentationFlags,
311
- query,
312
- } })) : null,
386
+ /*
387
+ * The upload panel: the Media library's wall, into the resolved Folder path where the placement names
388
+ * one. For the Media library's own Collection what arrived stays in the wall, with its delete, and the
389
+ * listing is read again; for a resource that adds, what arrived is added and leaves the wall; for any
390
+ * other the Collection is read again, in case its Provider lists what arrived itself.
391
+ */
392
+ const uploadPanel = state.uploadPanelOpen ? (_jsx(PhiAreaUploadBinding, { labels: labels.upload, config: folderPath.length > 0 ? { folderPath: folderPath.join(" / ") } : null, acceptance: uploadAcceptance, showFinished: isMediaLibrary, siteSpaceOnly: !isMediaLibrary, onUploadComplete: resourceActions.add ? undefined : binding.reload, onAssetUploaded: resourceActions.add ? (asset) => { void addAssets([asset.id]); } : undefined, collectionContext: isMediaLibrary ? {
393
+ folders: state.folders,
394
+ folderId: state.folderId,
395
+ folderPath: null,
396
+ presentationFlags: state.presentationFlags,
397
+ query,
398
+ } : {
399
+ folders: [],
400
+ folderId: null,
401
+ folderPath: null,
402
+ presentationFlags: null,
403
+ query,
404
+ } })) : null;
405
+ return (_jsx(PhiCollectionViewControl, { title: presentation.title, description: presentation.description, filters: filters, toolbar: toolbar, panel: uploadPanel,
313
406
  /*
314
407
  * Only what an action left behind reaches this: a failed read of the source ends the Collection
315
408
  * View before this renderer is drawn. A refusal is the acting person's to read, live or not.
316
409
  */
317
- diagnostics: state.error ? (_jsx(PhiAlertControl, { level: "error", showIcon: true, title: state.error })) : currentFolderLocked ? (_jsx(PhiAlertControl, { level: "info", showIcon: true, title: labels.tool.folderLockedText })) : null, body: body, items: state.assets.map((asset) => (_jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: minColumnWidth, selected: state.selectedAssetId === asset.id, mode: mode, deleting: deletingAssetIds.includes(asset.id), onSelect: selectAsset, onDelete: (nextAsset) => { void deleteAsset(nextAsset); }, deleteLabel: labels.grid.deleteLabel, showTypeLabel: true, showDeleteAction: !isPhiMediaFolderIdLocked(state.folders, asset.folderId), showDimensions: true, showIdLabel: true }, asset.id))), mode: mode, gap: gap, minColumnWidth: minColumnWidth, pagination: features.pagination?.enabled === false ? null : {
410
+ diagnostics: state.error ? (_jsx(PhiAlertControl, { level: "error", showIcon: true, title: state.error })) : currentFolderLocked ? (_jsx(PhiAlertControl, { level: "info", showIcon: true, title: labels.tool.folderLockedText })) : null, body: body, items: state.assets.map((asset) => (_jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: minColumnWidth, selected: state.selectedAssetId === asset.id, mode: mode, deleting: deletingAssetIds.includes(asset.id), ...(isMediaLibrary ? { onSelect: selectAsset } : {}), onDelete: (nextAsset) => { void deleteAsset(nextAsset); }, deleteLabel: labels.grid.deleteLabel, showTypeLabel: true, showDeleteAction: resourceActions.delete && !isPhiMediaFolderIdLocked(state.folders, asset.folderId), showDimensions: true, showIdLabel: true }, asset.id))), mode: mode, gap: gap, minColumnWidth: minColumnWidth, pagination: features.pagination?.enabled === false ? null : {
318
411
  page: state.page,
319
412
  pageSize: state.pageSize,
320
413
  total: state.pagination?.total ?? 0,
@@ -1,6 +1,7 @@
1
1
  import type { PhiCmsInstanceId } from "../../../../../types/cms-instance-id";
2
2
  import { type PhiCollectionViewWidgetLabels } from "../../../../../components/widgets/label-types/collection-view";
3
3
  import type { PhiCmsCollectionViewWidgetConfig } from "../../../../../types/collection-view-widget";
4
+ import type { PhiCollectionProviderResourceDescriptor } from "../../../../../types/collection-provider";
4
5
  import type { PhiRenderableBlockRenderMode } from "../../../../../types/renderable-block";
5
6
  export type PhiCollectionViewWidgetProps = {
6
7
  config?: PhiCmsCollectionViewWidgetConfig | null;
@@ -8,8 +9,12 @@ export type PhiCollectionViewWidgetProps = {
8
9
  labels?: unknown;
9
10
  /** The Widget's own words (the reorder handle and refusal), loaded where `features.reorder` is on. */
10
11
  reorderLabels?: PhiCollectionViewWidgetLabels;
11
- /** The bound resource's item key path, from its declaration; only where `features.reorder` is on. */
12
- itemIdentityPath?: string | null;
12
+ /**
13
+ * The bound resource as the Area's Modules declare it, read by the Server from the Area's registry:
14
+ * its item key path (what a reorder sends) and the actions, filters and panels its renderer's tools may
15
+ * offer. Handed on to the renderer as `resource`. `null` where the Area declares no such resource.
16
+ */
17
+ resourceDescriptor?: PhiCollectionProviderResourceDescriptor | null;
13
18
  /** Where this draws; the parsed config does not carry it, so the plugin reads it off the node. */
14
19
  renderMode: PhiRenderableBlockRenderMode;
15
20
  preview?: boolean;
@@ -58,7 +58,7 @@ function PhiCollectionViewWidgetPreview({ config, widgetId, renderMode, skeleton
58
58
  }
59
59
  return (_jsx(PhiCollectionViewSkeletonControl, { mode: presentation?.mode ?? "grid", gap: normalizePhiCssSize(presentation?.gap) ?? token.paddingSM, minColumnWidth: normalizePhiCssSize(presentation?.minColumnWidth) ?? 102, active: skeletonActive }));
60
60
  }
61
- function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, itemIdentityPath, widgetId, renderMode, }) {
61
+ function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, resourceDescriptor, widgetId, renderMode, }) {
62
62
  const signalIdentity = usePhiSignalIdentity();
63
63
  usePhiVisualAnchorParts(signalIdentity.receiver?.startsWith("cms:") ? signalIdentity.receiver : null, PHI_COLLECTION_VIEW_VISUAL_ANCHOR_PARTS);
64
64
  /*
@@ -104,7 +104,7 @@ function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, itemIdenti
104
104
  const { binding: presentedBinding, reorder } = usePhiCollectionReorderBinding({
105
105
  config: resolvedConfig,
106
106
  binding,
107
- itemIdentityPath: itemIdentityPath ?? null,
107
+ itemIdentityPath: resourceDescriptor?.itemIdentityPath ?? null,
108
108
  labels: reorderLabels ?? PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS,
109
109
  showMessage,
110
110
  });
@@ -137,8 +137,16 @@ function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, itemIdenti
137
137
  // `createElement` rather than a JSX tag: the renderer is looked up, not written down, and a looked-up
138
138
  // component in tag position reads to React -- and to `react-hooks/static-components` -- as a new
139
139
  // component per render. This is the same call `PhiRuntimeModuleRenderClientHost` makes for a Widget.
140
- // `renderMode` goes along so a renderer's own configuration failures are said the same way.
141
- return (_jsx(PhiCollectionReorderContext.Provider, { value: reorder, children: createElement(ItemRenderer, { config: resolvedConfig ?? config, binding: presentedBinding, labels, widgetId, renderMode }) }));
140
+ // `renderMode` goes along so a renderer's own configuration failures are said the same way, and the
141
+ // resource's declaration so its tools follow what the resource offers (`resource`, null where none).
142
+ return (_jsx(PhiCollectionReorderContext.Provider, { value: reorder, children: createElement(ItemRenderer, {
143
+ config: resolvedConfig ?? config,
144
+ binding: presentedBinding,
145
+ labels,
146
+ widgetId,
147
+ renderMode,
148
+ resource: resourceDescriptor ?? null,
149
+ }) }));
142
150
  }
143
151
  export function PhiCollectionViewWidget(props) {
144
152
  return props.preview
@@ -364,6 +364,31 @@ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFINITION: {
364
364
  defaultItem?: undefined;
365
365
  itemFields?: undefined;
366
366
  precision?: undefined;
367
+ } | {
368
+ key: string;
369
+ type: "choice";
370
+ label: string;
371
+ presentation: "select";
372
+ options: {
373
+ value: "image" | "video" | "markdown" | "other" | "document" | "audio" | "pdf" | "archive" | "font" | "binary";
374
+ label: "image" | "video" | "markdown" | "other" | "document" | "audio" | "pdf" | "archive" | "font" | "binary";
375
+ }[];
376
+ emptyOption: {
377
+ value: string;
378
+ label: string;
379
+ };
380
+ emptyValue: null;
381
+ providerKind?: undefined;
382
+ optionsProvider?: undefined;
383
+ placeholder?: undefined;
384
+ min?: undefined;
385
+ itemKeyField?: undefined;
386
+ itemLabelField?: undefined;
387
+ addLabel?: undefined;
388
+ emptyLabel?: undefined;
389
+ defaultItem?: undefined;
390
+ itemFields?: undefined;
391
+ precision?: undefined;
367
392
  } | {
368
393
  key: string;
369
394
  type: "number";
@@ -9,6 +9,9 @@ import { PHI_AUTHORING_OPTION_PROVIDER_KEYS } from "../../../../../constants/aut
9
9
  import { readPhiLengthValue } from "../../../../../types/length";
10
10
  import { readBoolean, readNumber, readNumberList, readString } from "../../../../../components/widgets/config/parser-primitives";
11
11
  import { isPhiRecord } from "../../../../../helpers/is-record";
12
+ import { PhiMediaKind } from "../../../../../constants/media";
13
+ import { isPhiMediaFolderPathTemplate } from "../../../../../components/media/media-folder-name-path";
14
+ import { createPhiConfigReader } from "../../../../../components/widgets/config/strict-config-reader";
12
15
  function readCardPresentation(value) {
13
16
  if (!isPhiRecord(value)) {
14
17
  return undefined;
@@ -80,6 +83,21 @@ function readToolbarActions(value) {
80
83
  }];
81
84
  });
82
85
  }
86
+ const MEDIA_KINDS = Object.values(PhiMediaKind);
87
+ /*
88
+ * The Media renderer's settings (`features.media`), read strictly: a path whose braces open no
89
+ * placeholder or a kind the Media library does not know is a `PhiConfigError` naming the key, never a default put in its place -- a broken placeholder would
90
+ * become a Folder named after it.
91
+ */
92
+ function readMediaFeatures(value) {
93
+ const reader = createPhiConfigReader(value, "features.media");
94
+ const folderPath = reader.value("folderPath", "a Folder path whose placeholders read {key}", (entry) => typeof entry === "string" && isPhiMediaFolderPathTemplate(entry) ? entry.trim() : undefined);
95
+ const mediaType = reader.oneOf("mediaType", MEDIA_KINDS);
96
+ return {
97
+ ...(folderPath ? { folderPath } : {}),
98
+ ...(mediaType ? { mediaType } : {}),
99
+ };
100
+ }
83
101
  function readInitialQuery(value) {
84
102
  if (!isPhiRecord(value))
85
103
  return undefined;
@@ -110,6 +128,7 @@ function normalizePhiCmsCollectionViewWidgetConfig(config) {
110
128
  const actions = isPhiRecord(features.actions) ? features.actions : {};
111
129
  const pagination = isPhiRecord(features.pagination) ? features.pagination : null;
112
130
  const reorder = isPhiRecord(features.reorder) ? features.reorder : null;
131
+ const media = isPhiRecord(features.media) ? features.media : null;
113
132
  return {
114
133
  presentation: {
115
134
  title: readString(presentation.title),
@@ -139,6 +158,7 @@ function normalizePhiCmsCollectionViewWidgetConfig(config) {
139
158
  enabled: readBoolean(reorder.enabled) ?? false,
140
159
  actionKey: readString(reorder.actionKey)?.trim() || undefined,
141
160
  } : undefined,
161
+ media: media ? readMediaFeatures(media) : undefined,
142
162
  pagination: pagination ? {
143
163
  enabled: readBoolean(pagination.enabled) ?? true,
144
164
  pageSize: readNumber(pagination.pageSize),
@@ -347,6 +367,20 @@ export const PHI_COLLECTION_VIEW_WIDGET_DEFINITION = {
347
367
  */
348
368
  { key: "features.reorder.enabled", type: "boolean", label: "Drag Reordering" },
349
369
  { key: "features.reorder.actionKey", type: "string", label: "Reorder Action Key", placeholder: "reorder" },
370
+ /*
371
+ * The Media renderer's: where its upload goes and its picker opens (placeholders from the binding
372
+ * params), the kind both offer, and whether only public Assets may be added. Other renderers ignore them.
373
+ */
374
+ { key: "features.media.folderPath", type: "string", label: "Media Folder Path", placeholder: "Shop Images / {category}" },
375
+ {
376
+ key: "features.media.mediaType",
377
+ type: "choice",
378
+ label: "Media Kind",
379
+ presentation: "select",
380
+ options: MEDIA_KINDS.map((kind) => ({ value: kind, label: kind })),
381
+ emptyOption: { value: "", label: "Every kind" },
382
+ emptyValue: null,
383
+ },
350
384
  { key: "features.pagination.enabled", type: "boolean", label: "Pagination" },
351
385
  { key: "features.pagination.pageSize", type: "number", label: "Page Size", min: 1, precision: 0 },
352
386
  { key: "features.pagination.compact", type: "boolean", label: "Compact Pagination" },
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../../../components/media/media-widget-labels";
3
3
  import { PHI_ASSET_COLLECTION_DATA_SOURCE } from "../../../../../components/media/asset-collection-runtime";
4
+ import { PHI_MEDIA_LIBRARY_ASSET_RESOURCE } from "../../../../../components/media/media-library-resource";
4
5
  import { PhiCollectionViewWidget } from "./client";
5
6
  export function PhiAssetPreviewGridWidget({ config, labels, mediaLabels, renderMode }) {
6
7
  return (_jsx(PhiCollectionViewWidget, { config: {
@@ -12,5 +13,7 @@ export function PhiAssetPreviewGridWidget({ config, labels, mediaLabels, renderM
12
13
  },
13
14
  features: { tools: { mode: "external" }, pagination: { enabled: false } },
14
15
  source: PHI_ASSET_COLLECTION_DATA_SOURCE,
15
- }, labels: { ...(mediaLabels ?? PHI_MEDIA_WIDGET_DEFAULT_LABELS), grid: labels }, renderMode: renderMode }));
16
+ }, labels: { ...(mediaLabels ?? PHI_MEDIA_WIDGET_DEFAULT_LABELS), grid: labels },
17
+ // No page registry reaches this: the resource's declaration is handed over, so its tiles keep their delete.
18
+ resourceDescriptor: PHI_MEDIA_LIBRARY_ASSET_RESOURCE, renderMode: renderMode }));
16
19
  }
@@ -6,8 +6,9 @@ import type { PhiRenderableBlockRenderMode } from "../../../../../types/renderab
6
6
  export type PhiCollectionViewWidgetServerProps = {
7
7
  runtime: Pick<PhiBlockRuntime, "locale">;
8
8
  /**
9
- * The Area's declarations: the preview judges the binding against them, and a Widget that offers
10
- * reordering reads the bound resource's `itemIdentityPath` there. Absent outside a page render.
9
+ * The Area's declarations: the preview judges the binding against them, and the live Widget reads the
10
+ * bound resource's declaration there -- its renderer, `itemIdentityPath` and tools. Absent outside a
11
+ * page render.
11
12
  */
12
13
  registry?: Pick<PhiCmsRuntimeRenderRegistry, "dataProviderDescriptorsByKey">;
13
14
  config?: PhiCmsCollectionViewWidgetConfig | null;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
3
- import { PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS } from "../../../../../constants/media-library-provider-keys";
3
+ import { PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY } from "../../../../../constants/media-library-provider-keys";
4
4
  import { getPhiMediaWidgetLabels } from "../../../../../components/media/label-sets/media";
5
5
  import { getPhiCollectionViewWidgetLabels } from "../../../../../components/widgets/label-sets/collection-view";
6
6
  import { buildPhiWidgetLabelTranslatorOptions } from "../../../../../components/widgets/label-sets/runtime-options";
@@ -28,27 +28,29 @@ export async function PhiCollectionViewWidgetServer({ runtime, config, widgetId,
28
28
  return (_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiCmsWidgetType.CollectionView, componentProps: { config, widgetId, renderMode, preview: true } }));
29
29
  }
30
30
  /*
31
- * The Media collection's renderer says the Media Label Set's words (the toolbar, the flag filter, the
32
- * grid, the upload surface) and Core may not import the Asset Module to get them, so they are the
33
- * Foundation's and loaded here -- only for a Widget bound to that collection, so no other source pays.
34
- * `config.presentation.labels` still lays over them.
31
+ * The bound resource as the Area's Modules declare it: the renderer it names, the key path of its
32
+ * items (what a reorder sends as `itemKeys`) and the actions, filters and panels its tools may offer.
33
+ * The Provider's Client registration does not carry them, the declaration does, so the Server hands
34
+ * it on and the renderer offers what the resource declares (`PhiCollectionProviderResourceDescriptor`).
35
+ */
36
+ const source = config?.source;
37
+ const providerDescriptor = source ? registry?.dataProviderDescriptorsByKey.get(source.providerKey) : undefined;
38
+ const resourceDescriptor = providerDescriptor?.kind === "collection"
39
+ ? providerDescriptor.resources.find((resource) => resource.resourceKey === source?.resourceKey) ?? null
40
+ : null;
41
+ const rendererKey = config?.itemRendererKey ?? resourceDescriptor?.itemRendererKey ?? null;
42
+ /*
43
+ * The Media renderer says the Media Label Set's words (the toolbar, the flag filter, the grid, the
44
+ * upload surface) and Core may not import the Asset Module to get them, so they are the Foundation's
45
+ * and loaded here -- for a Widget whose items that renderer draws, whichever Provider it is bound to
46
+ * (the Media library, a gallery of references), and for no other. `config.presentation.labels` still
47
+ * lays over them.
35
48
  */
36
49
  const translatorOptions = buildPhiWidgetLabelTranslatorOptions(runtime);
37
50
  const [labels, reorderLabels] = await Promise.all([
38
- config?.source?.providerKey === PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection
39
- ? getPhiMediaWidgetLabels(translatorOptions)
40
- : undefined,
51
+ rendererKey === PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY ? getPhiMediaWidgetLabels(translatorOptions) : undefined,
41
52
  // The Widget's own words, only for one that offers reordering.
42
53
  config?.features.reorder?.enabled ? getPhiCollectionViewWidgetLabels(translatorOptions) : undefined,
43
54
  ]);
44
- /*
45
- * Which field of an item is its key, as the bound resource declares it: what a reorder sends as
46
- * `itemKeys`. The Provider's Client registration does not carry it, the declaration does.
47
- */
48
- const source = config?.source;
49
- const providerDescriptor = source ? registry?.dataProviderDescriptorsByKey.get(source.providerKey) : undefined;
50
- const itemIdentityPath = config?.features.reorder?.enabled && providerDescriptor?.kind === "collection"
51
- ? providerDescriptor.resources.find((resource) => resource.resourceKey === source?.resourceKey)?.itemIdentityPath ?? null
52
- : null;
53
- return (_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiCmsWidgetType.CollectionView, componentProps: { config, widgetId, renderMode, preview: false, labels, reorderLabels, itemIdentityPath } }));
55
+ return (_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiCmsWidgetType.CollectionView, componentProps: { config, widgetId, renderMode, preview: false, labels, reorderLabels, resourceDescriptor } }));
54
56
  }
@@ -115,6 +115,10 @@ type PhiCmsPresetTreeForm = {
115
115
  descriptor: PhiFormDescriptor;
116
116
  };
117
117
  /**
118
+ * The preset tree contract, enforced: the first of `checkPhiPresetTreeContract`'s findings
119
+ * (`helpers/preset-tree-contract-check.ts`, which a Module runs in its own tests from
120
+ * `@phis/ui/module/page-check`) is thrown, and the Page answers 500.
121
+ *
118
122
  * `forms` are the Forms the compiler can see -- the ones the catalog's Modules ship, by id. A Form it
119
123
  * cannot see (one stored on the Site, one of a Module outside the catalog) is not judged.
120
124
  */