@phis/ui 0.7.2 → 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.
- package/components/controls/phi-collection-reorder-context.d.ts +21 -0
- package/components/controls/phi-collection-reorder-context.js +6 -0
- package/components/controls/phi-collection-sortable-layout-control.d.ts +17 -0
- package/components/controls/phi-collection-sortable-layout-control.js +72 -0
- package/components/controls/phi-collection-view-control.d.ts +1 -1
- package/components/controls/phi-collection-view-control.js +15 -1
- package/components/controls/phi-media-asset-tile-control.d.ts +14 -6
- package/components/controls/phi-media-picker-control.d.ts +13 -2
- package/components/controls/phi-media-picker-control.js +9 -2
- package/components/forms/compound-form-controls.d.ts +1 -1
- package/components/forms/compound-form-controls.js +6 -4
- package/components/forms/form-field-labels.d.ts +4 -2
- package/components/forms/form-field-labels.js +30 -9
- package/components/forms/form-provider-contract.js +2 -1
- package/components/forms/media-asset-field-keys.d.ts +13 -2
- package/components/forms/media-asset-field-keys.js +17 -2
- package/components/forms/table-field-keys.d.ts +8 -0
- package/components/forms/table-field-keys.js +8 -0
- package/components/forms/table-field-labels.d.ts +16 -0
- package/components/forms/table-field-labels.js +16 -0
- package/components/forms/table-field-text.d.ts +9 -0
- package/components/forms/table-field-text.js +20 -0
- package/components/forms/upload-field-refusal-labels.d.ts +10 -0
- package/components/forms/upload-field-refusal-labels.js +24 -0
- package/components/forms/upload-form-control.js +3 -16
- package/components/media/label-sets/media.js +4 -0
- package/components/media/media-folder-name-path.d.ts +14 -0
- package/components/media/media-folder-name-path.js +40 -2
- package/components/media/media-library-resource.d.ts +70 -0
- package/components/media/media-library-resource.js +41 -0
- package/components/media/media-upload-flow.d.ts +13 -1
- package/components/media/media-upload-flow.js +16 -0
- package/components/media/media-widget-labels.d.ts +13 -0
- package/components/media/media-widget-labels.js +2 -0
- package/components/media/phi-area-upload-widget.d.ts +31 -1
- package/components/media/phi-area-upload-widget.js +33 -7
- package/components/media/phi-image-preview-data.d.ts +8 -1
- package/components/media/phi-image-preview-data.js +29 -0
- package/components/media/phi-media-picker-binding.d.ts +50 -1
- package/components/media/phi-media-picker-binding.js +86 -6
- package/components/media/phi-media-upload.d.ts +7 -1
- package/components/media/phi-media-upload.js +17 -5
- package/components/media/use-media-library-add-picker.d.ts +94 -0
- package/components/media/use-media-library-add-picker.js +40 -0
- package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
- package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
- package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
- package/components/widgets/label-sets/collection-view.d.ts +4 -0
- package/components/widgets/label-sets/collection-view.js +16 -0
- package/components/widgets/label-sets/table.d.ts +6 -0
- package/components/widgets/label-sets/table.js +10 -0
- package/components/widgets/label-types/collection-view.d.ts +8 -0
- package/components/widgets/label-types/collection-view.js +4 -0
- package/constants/media-library-provider-keys.d.ts +7 -0
- package/constants/media-library-provider-keys.js +7 -0
- package/constants/runtime-module-ownership.js +1 -0
- package/controls.d.ts +1 -1
- package/helpers/preset-tree-contract-check.d.ts +35 -0
- package/helpers/preset-tree-contract-check.js +211 -0
- package/module-page-check.d.ts +6 -0
- package/module-page-check.js +6 -0
- package/package.json +1 -1
- package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
- package/plugins/runtime-modules/asset/data-providers.js +4 -32
- package/plugins/runtime-modules/asset/definition.d.ts +123 -38
- package/plugins/runtime-modules/asset/definition.js +2 -1
- package/plugins/runtime-modules/asset/form-providers.d.ts +93 -2
- package/plugins/runtime-modules/asset/form-providers.js +76 -11
- package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
- package/plugins/runtime-modules/asset/media-asset-field.js +30 -5
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +14 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +72 -37
- package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
- package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
- package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
- package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
- package/plugins/runtime-modules/asset/services/collection.js +12 -0
- package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
- package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +10 -0
- package/plugins/runtime-modules/core/widgets/collection-view/client.js +59 -5
- package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +53 -2
- package/plugins/runtime-modules/core/widgets/collection-view/config.js +47 -0
- package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
- package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +5 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.js +26 -9
- package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
- package/plugins/runtime-modules/descriptor-compiler.js +9 -204
- package/plugins/runtime-modules/resolver.js +31 -5
- package/types/collection-provider.d.ts +7 -0
- package/types/collection-view-widget.d.ts +30 -0
- package/types/core-widget-placements.d.ts +14 -0
- package/types/media.d.ts +16 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PhiCollectionProviderResourceDescriptor } from "../../../../../types/collection-provider";
|
|
2
|
+
import type { PhiCmsCollectionViewWidgetConfig } from "../../../../../types/collection-view-widget";
|
|
3
|
+
/** The panel the `upload` action opens, by the resource's declaration (`panelKey`). */
|
|
4
|
+
export declare const PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY = "upload";
|
|
5
|
+
/**
|
|
6
|
+
* What the resource lets the renderer offer on its own, without a tool in the placement: a tile's
|
|
7
|
+
* delete (`delete`, scope `item`) and adding what an upload made (`add`, which takes `itemKeys`, the
|
|
8
|
+
* Asset ids).
|
|
9
|
+
*/
|
|
10
|
+
export type PhiMediaRendererResourceActions = {
|
|
11
|
+
delete: boolean;
|
|
12
|
+
add: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function readPhiMediaRendererResourceActions(resource: Pick<PhiCollectionProviderResourceDescriptor, "actions"> | null | undefined): PhiMediaRendererResourceActions;
|
|
15
|
+
/**
|
|
16
|
+
* Why the placement's tools cannot be drawn for this resource, or `null`: a filter or an action the
|
|
17
|
+
* renderer has no control for, or one the bound resource does not declare -- a Folder filter on a
|
|
18
|
+
* gallery of references, a lock on a resource that cannot lock. The resource is the one the Server read
|
|
19
|
+
* from the Area's registry; where the Area declares none, nothing is declared and every tool is refused.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readPhiMediaRendererToolFailure(input: {
|
|
22
|
+
config: Pick<PhiCmsCollectionViewWidgetConfig, "features">;
|
|
23
|
+
resource: Pick<PhiCollectionProviderResourceDescriptor, "actions" | "query"> | null | undefined;
|
|
24
|
+
}): string | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What the Media renderer's tools are, apart from the drawing (`asset-binding.tsx`): which a placement
|
|
3
|
+
* may name, and which of them the bound resource declares. Pure, so the rules are tested without a
|
|
4
|
+
* render.
|
|
5
|
+
*/
|
|
6
|
+
/** The filters the Media renderer draws a control for. */
|
|
7
|
+
const PHI_MEDIA_RENDERER_FILTER_KEYS = ["kind", "presentationFlags", "folderId"];
|
|
8
|
+
/**
|
|
9
|
+
* The tool actions the Media renderer draws: `upload` opens the resource's upload panel, `add` the Media
|
|
10
|
+
* library's picker whose pick goes to the resource's `add` action, `createFolder` and `lockFolder`
|
|
11
|
+
* (with `unlockFolder`) sit beside the Folder filter.
|
|
12
|
+
*/
|
|
13
|
+
const PHI_MEDIA_RENDERER_ACTION_KEYS = ["upload", "add", "createFolder", "lockFolder"];
|
|
14
|
+
/** The panel the `upload` action opens, by the resource's declaration (`panelKey`). */
|
|
15
|
+
export const PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY = "upload";
|
|
16
|
+
export function readPhiMediaRendererResourceActions(resource) {
|
|
17
|
+
const keys = new Set((resource?.actions ?? []).map((action) => action.key));
|
|
18
|
+
return { delete: keys.has("delete"), add: keys.has("add") };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Why the placement's tools cannot be drawn for this resource, or `null`: a filter or an action the
|
|
22
|
+
* renderer has no control for, or one the bound resource does not declare -- a Folder filter on a
|
|
23
|
+
* gallery of references, a lock on a resource that cannot lock. The resource is the one the Server read
|
|
24
|
+
* from the Area's registry; where the Area declares none, nothing is declared and every tool is refused.
|
|
25
|
+
*/
|
|
26
|
+
export function readPhiMediaRendererToolFailure(input) {
|
|
27
|
+
const { features } = input.config;
|
|
28
|
+
const declaredFilters = new Set((input.resource?.query.filterFields ?? []).map((filter) => filter.key));
|
|
29
|
+
const declaredActions = new Map((input.resource?.actions ?? []).map((action) => [action.key, action]));
|
|
30
|
+
for (const filter of features.filters ?? []) {
|
|
31
|
+
if (!PHI_MEDIA_RENDERER_FILTER_KEYS.includes(filter.key)) {
|
|
32
|
+
return `Asset collection filter "${filter.key}" is not supported.`;
|
|
33
|
+
}
|
|
34
|
+
if (!declaredFilters.has(filter.key)) {
|
|
35
|
+
return `The bound resource declares no filter "${filter.key}".`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const configuredActions = [
|
|
39
|
+
...(features.actions?.toolbar ?? []),
|
|
40
|
+
...(features.filters ?? []).flatMap((filter) => filter.actions ?? []),
|
|
41
|
+
];
|
|
42
|
+
for (const action of configuredActions) {
|
|
43
|
+
if (!PHI_MEDIA_RENDERER_ACTION_KEYS.includes(action.key)) {
|
|
44
|
+
return `Asset collection action "${action.key}" is not supported.`;
|
|
45
|
+
}
|
|
46
|
+
const needed = action.key === "lockFolder" ? ["lockFolder", "unlockFolder"] : [action.key];
|
|
47
|
+
const missing = needed.find((key) => !declaredActions.has(key));
|
|
48
|
+
if (missing)
|
|
49
|
+
return `The bound resource declares no action "${missing}".`;
|
|
50
|
+
if (action.key === "upload" && declaredActions.get("upload")?.panelKey !== PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY) {
|
|
51
|
+
return `The bound resource's "upload" action opens no "${PHI_MEDIA_RENDERER_UPLOAD_PANEL_KEY}" panel.`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import type { PhiCmsInstanceId } from "../../../../../types/cms-instance-id";
|
|
2
|
-
import type { PhiCollectionViewBindingModel } from "../../../../../types/collection-provider";
|
|
2
|
+
import type { PhiCollectionProviderResourceDescriptor, PhiCollectionViewBindingModel } from "../../../../../types/collection-provider";
|
|
3
3
|
import type { PhiCmsCollectionViewWidgetConfig } from "../../../../../types/collection-view-widget";
|
|
4
4
|
import type { PhiRenderableBlockRenderMode } from "../../../../../types/renderable-block";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The Media renderer (`PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY`): the items of a Collection as Media tiles,
|
|
7
|
+
* for whichever Provider names it -- the Media library's own Collection, and any Collection of Assets
|
|
8
|
+
* (a gallery of references) whose resource names it as its `itemRendererKey`, or whose placement does.
|
|
9
|
+
*
|
|
10
|
+
* - **Items** are read in the Media tile shape (`PhiMediaCollectionItem`, `readPhiMediaCollectionItems`);
|
|
11
|
+
* the Media library's own as its whole tiles.
|
|
12
|
+
* - **Tools** follow what the resource declares (`readPhiMediaRendererToolFailure`): a Folder, lock,
|
|
13
|
+
* new-Folder or flag tool the placement names but the resource does not declare is a failure, not a
|
|
14
|
+
* control that does nothing. A tile's delete is the resource's `delete`, in the words the placement's
|
|
15
|
+
* `presentation.labels.grid` gives (a gallery's "Remove from gallery").
|
|
16
|
+
* - **Upload** is the resource's `upload` panel, the Media library's multi-upload wall, into
|
|
17
|
+
* `features.media.folderPath` with `{param}` filled from the binding params. Where the resource
|
|
18
|
+
* declares `add`, what arrived is added to it (`itemKeys`, the Asset ids) -- the Provider's answer shows
|
|
19
|
+
* it at once, then the Collection is read again -- and leaves the wall, so it is not shown twice.
|
|
20
|
+
* - **Choose from Media library** (toolbar action `add`) opens the library's picker on the same Folder;
|
|
21
|
+
* the pick goes to the same `add` action.
|
|
22
|
+
* - **The Asset Controller's store** (the selection, the Space selector) is fed by the Media library's
|
|
23
|
+
* own Collection only; a tile of another Collection is not selected.
|
|
24
|
+
*
|
|
25
|
+
* Drag reordering (`features.reorder`) is the Collection View's, around these tiles.
|
|
26
|
+
*/
|
|
27
|
+
export declare function PhiAssetCollectionViewBinding({ config, binding, labels: rawLabels, widgetId, renderMode, resource, }: {
|
|
6
28
|
config: PhiCmsCollectionViewWidgetConfig;
|
|
7
29
|
binding: PhiCollectionViewBindingModel;
|
|
8
30
|
labels?: unknown;
|
|
9
31
|
widgetId?: PhiCmsInstanceId | null;
|
|
10
32
|
/** Handed on by the Collection View, so a configuration this renderer cannot serve is said its way. */
|
|
11
33
|
renderMode: PhiRenderableBlockRenderMode;
|
|
34
|
+
/** The bound resource as the Area declares it (the Collection View's Server half read it); `null`: none. */
|
|
35
|
+
resource?: PhiCollectionProviderResourceDescriptor | null;
|
|
12
36
|
}): import("react").JSX.Element;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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 ===
|
|
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
|
-
:
|
|
122
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
222
|
-
|
|
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
|
|
297
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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,10 +1,20 @@
|
|
|
1
1
|
import type { PhiCmsInstanceId } from "../../../../../types/cms-instance-id";
|
|
2
|
+
import { type PhiCollectionViewWidgetLabels } from "../../../../../components/widgets/label-types/collection-view";
|
|
2
3
|
import type { PhiCmsCollectionViewWidgetConfig } from "../../../../../types/collection-view-widget";
|
|
4
|
+
import type { PhiCollectionProviderResourceDescriptor } from "../../../../../types/collection-provider";
|
|
3
5
|
import type { PhiRenderableBlockRenderMode } from "../../../../../types/renderable-block";
|
|
4
6
|
export type PhiCollectionViewWidgetProps = {
|
|
5
7
|
config?: PhiCmsCollectionViewWidgetConfig | null;
|
|
6
8
|
widgetId?: PhiCmsInstanceId | null;
|
|
7
9
|
labels?: unknown;
|
|
10
|
+
/** The Widget's own words (the reorder handle and refusal), loaded where `features.reorder` is on. */
|
|
11
|
+
reorderLabels?: PhiCollectionViewWidgetLabels;
|
|
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;
|
|
8
18
|
/** Where this draws; the parsed config does not carry it, so the plugin reads it off the node. */
|
|
9
19
|
renderMode: PhiRenderableBlockRenderMode;
|
|
10
20
|
preview?: boolean;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createElement } from "react";
|
|
3
|
+
import { createElement, useCallback, useMemo, useState } from "react";
|
|
4
4
|
import { PhiCollectionViewSkeletonControl } from "../../../../../components/controls/phi-collection-view-control";
|
|
5
|
+
import { PhiCollectionReorderContext } from "../../../../../components/controls/phi-collection-reorder-context";
|
|
6
|
+
import { usePhiCollectionReorderBinding } from "../../../../../components/widgets/client/shared/phi-collection-reorder";
|
|
7
|
+
import { usePhiApplicationFeedback } from "../../../../../components/runtime/use-phi-application-feedback";
|
|
8
|
+
import { PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS, } from "../../../../../components/widgets/label-types/collection-view";
|
|
5
9
|
import { normalizePhiCssSize } from "../../../../../components/layouts/phi-layout-contract";
|
|
6
10
|
import { usePhiConfig } from "../../../../../components/root/phi-config-provider";
|
|
7
11
|
import { usePhiRuntimeModuleState } from "../../../../../components/runtime/runtime-module-context";
|
|
@@ -14,6 +18,10 @@ import { usePhiCollectionViewBinding } from "../../../../../components/widgets/c
|
|
|
14
18
|
import { PhiCollectionSourceFailureText, readPhiCollectionViewDeclaredFailure, } from "../../../../../components/widgets/shared/collection-source-failure";
|
|
15
19
|
import { PhiWidgetFailure } from "../../../../../components/widgets/shared/widget-failure-client";
|
|
16
20
|
import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
|
|
21
|
+
import { usePhiSignalListener } from "../../../../../components/runtime/runtime-signal-bus";
|
|
22
|
+
import { findPhiSignalListenRoute, resolvePhiSignalListenFilter } from "../../../../../helpers/signal-listen-routes";
|
|
23
|
+
import { readPhiTableBindingParamsSignalValue } from "../../../../../types/table-signal-values";
|
|
24
|
+
import { isPhiRecord } from "../../../../../helpers/is-record";
|
|
17
25
|
/**
|
|
18
26
|
* The parts of a Collection View a Tour can point at, as `cms:<instanceId>:<part>` (design/TOURS.md): the
|
|
19
27
|
* filters and search, the toolbar, the items and the pagination. A part the view does not draw is simply
|
|
@@ -50,10 +58,35 @@ function PhiCollectionViewWidgetPreview({ config, widgetId, renderMode, skeleton
|
|
|
50
58
|
}
|
|
51
59
|
return (_jsx(PhiCollectionViewSkeletonControl, { mode: presentation?.mode ?? "grid", gap: normalizePhiCssSize(presentation?.gap) ?? token.paddingSM, minColumnWidth: normalizePhiCssSize(presentation?.minColumnWidth) ?? 102, active: skeletonActive }));
|
|
52
60
|
}
|
|
53
|
-
function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, }) {
|
|
61
|
+
function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, resourceDescriptor, widgetId, renderMode, }) {
|
|
54
62
|
const signalIdentity = usePhiSignalIdentity();
|
|
55
63
|
usePhiVisualAnchorParts(signalIdentity.receiver?.startsWith("cms:") ? signalIdentity.receiver : null, PHI_COLLECTION_VIEW_VISUAL_ANCHOR_PARTS);
|
|
56
|
-
|
|
64
|
+
/*
|
|
65
|
+
* The binding params, as the Table takes them (`bindingParamsChange`): the configured `source.params`
|
|
66
|
+
* until a received `{ params }` is laid over them, and handed to the Provider as `source.params`. A
|
|
67
|
+
* new set starts the list over -- first page, the initial query, nothing of the old answer shown
|
|
68
|
+
* (`usePhiCollectionViewBinding`). The chosen set is tagged with the configuration it was laid over, so
|
|
69
|
+
* a Builder edit of the configured params is a new starting point.
|
|
70
|
+
*/
|
|
71
|
+
const configuredSource = config?.source ?? null;
|
|
72
|
+
const configuredBindingParams = useMemo(() => isPhiRecord(configuredSource?.params) ? configuredSource.params : {}, [configuredSource]);
|
|
73
|
+
const bindingParamsSeed = JSON.stringify(configuredBindingParams);
|
|
74
|
+
const [chosenBindingParams, setChosenBindingParams] = useState(null);
|
|
75
|
+
const bindingParams = chosenBindingParams?.seed === bindingParamsSeed
|
|
76
|
+
? chosenBindingParams.params
|
|
77
|
+
: configuredBindingParams;
|
|
78
|
+
const source = useMemo(() => configuredSource ? { ...configuredSource, params: bindingParams } : null, [bindingParams, configuredSource]);
|
|
79
|
+
// What the renderer reads of the binding is the source the Provider is asked with.
|
|
80
|
+
const resolvedConfig = useMemo(() => config ? { ...config, source } : config, [config, source]);
|
|
81
|
+
const listenRoutes = useMemo(() => config?.signalRoutes?.listens ?? [], [config?.signalRoutes?.listens]);
|
|
82
|
+
usePhiSignalListener(useCallback((signal) => {
|
|
83
|
+
const route = findPhiSignalListenRoute(listenRoutes, signal, signalIdentity.receiver);
|
|
84
|
+
if (route?.capabilityId !== "bindingParamsChange")
|
|
85
|
+
return;
|
|
86
|
+
const next = readPhiTableBindingParamsSignalValue(signal.value);
|
|
87
|
+
if (next)
|
|
88
|
+
setChosenBindingParams({ seed: bindingParamsSeed, params: { ...bindingParams, ...next.params } });
|
|
89
|
+
}, [bindingParams, bindingParamsSeed, listenRoutes, signalIdentity.receiver]), useMemo(() => resolvePhiSignalListenFilter(listenRoutes), [listenRoutes]), signalIdentity.receiver);
|
|
57
90
|
const { resource, bindingError, queryError, binding } = usePhiCollectionViewBinding({
|
|
58
91
|
source,
|
|
59
92
|
initialQuery: config?.initialQuery,
|
|
@@ -62,6 +95,19 @@ function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, })
|
|
|
62
95
|
// The provider ships a renderer with its resource; a Site may name another Module's instead. Both are
|
|
63
96
|
// ordinary Render Clients, so neither side has to know the other exists.
|
|
64
97
|
const rendererKey = config?.itemRendererKey ?? resource?.itemRendererKey ?? null;
|
|
98
|
+
/*
|
|
99
|
+
* Drag reordering (`features.reorder`) goes around whatever the renderer draws: the renderer gets the
|
|
100
|
+
* binding with the items in the dropped order while the Provider writes it, and its Collection Control
|
|
101
|
+
* puts the handles on (`PhiCollectionReorderContext`). The Widget keeps no order of its own.
|
|
102
|
+
*/
|
|
103
|
+
const { showMessage } = usePhiApplicationFeedback();
|
|
104
|
+
const { binding: presentedBinding, reorder } = usePhiCollectionReorderBinding({
|
|
105
|
+
config: resolvedConfig,
|
|
106
|
+
binding,
|
|
107
|
+
itemIdentityPath: resourceDescriptor?.itemIdentityPath ?? null,
|
|
108
|
+
labels: reorderLabels ?? PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS,
|
|
109
|
+
showMessage,
|
|
110
|
+
});
|
|
65
111
|
const ItemRenderer = usePhiRuntimeModuleRenderClient(rendererKey);
|
|
66
112
|
usePhiControlSignalController({
|
|
67
113
|
key: "collectionReload",
|
|
@@ -91,8 +137,16 @@ function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, })
|
|
|
91
137
|
// `createElement` rather than a JSX tag: the renderer is looked up, not written down, and a looked-up
|
|
92
138
|
// component in tag position reads to React -- and to `react-hooks/static-components` -- as a new
|
|
93
139
|
// component per render. This is the same call `PhiRuntimeModuleRenderClientHost` makes for a Widget.
|
|
94
|
-
// `renderMode` goes along so a renderer's own configuration failures are said the same way
|
|
95
|
-
|
|
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
|
+
}) }));
|
|
96
150
|
}
|
|
97
151
|
export function PhiCollectionViewWidget(props) {
|
|
98
152
|
return props.preview
|
|
@@ -28,12 +28,19 @@ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFINITION: {
|
|
|
28
28
|
valueSchema: `${string}/signals/${string}`;
|
|
29
29
|
valueSchemaFrom?: undefined;
|
|
30
30
|
})[];
|
|
31
|
-
listens: {
|
|
31
|
+
listens: ({
|
|
32
32
|
id: string;
|
|
33
33
|
channel: string;
|
|
34
34
|
action: "activate";
|
|
35
35
|
valueType: "none";
|
|
36
|
-
|
|
36
|
+
valueSchema?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
id: string;
|
|
39
|
+
channel: string;
|
|
40
|
+
action: "change";
|
|
41
|
+
valueType: "json";
|
|
42
|
+
valueSchema: `${string}/signals/${string}`;
|
|
43
|
+
})[];
|
|
37
44
|
};
|
|
38
45
|
fields: ({
|
|
39
46
|
key: string;
|
|
@@ -338,6 +345,50 @@ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFINITION: {
|
|
|
338
345
|
options?: undefined;
|
|
339
346
|
min?: undefined;
|
|
340
347
|
precision?: undefined;
|
|
348
|
+
} | {
|
|
349
|
+
key: string;
|
|
350
|
+
type: "string";
|
|
351
|
+
label: string;
|
|
352
|
+
placeholder: string;
|
|
353
|
+
providerKind?: undefined;
|
|
354
|
+
presentation?: undefined;
|
|
355
|
+
optionsProvider?: undefined;
|
|
356
|
+
emptyOption?: undefined;
|
|
357
|
+
emptyValue?: undefined;
|
|
358
|
+
options?: undefined;
|
|
359
|
+
min?: undefined;
|
|
360
|
+
itemKeyField?: undefined;
|
|
361
|
+
itemLabelField?: undefined;
|
|
362
|
+
addLabel?: undefined;
|
|
363
|
+
emptyLabel?: undefined;
|
|
364
|
+
defaultItem?: undefined;
|
|
365
|
+
itemFields?: undefined;
|
|
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;
|
|
341
392
|
} | {
|
|
342
393
|
key: string;
|
|
343
394
|
type: "number";
|