@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.
- package/components/controls/phi-media-asset-tile-control.d.ts +4 -3
- package/components/controls/phi-media-picker-control.d.ts +9 -11
- package/components/controls/phi-media-picker-control.js +9 -11
- package/components/forms/form-field-labels.d.ts +3 -3
- package/components/forms/form-field-labels.js +13 -5
- package/components/forms/media-asset-field-keys.d.ts +9 -1
- package/components/forms/media-asset-field-keys.js +13 -1
- 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-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 +22 -20
- package/components/media/phi-media-picker-binding.js +20 -33
- package/components/media/use-media-library-add-picker.d.ts +94 -0
- package/components/media/use-media-library-add-picker.js +40 -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/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 +115 -38
- package/plugins/runtime-modules/asset/definition.js +2 -1
- package/plugins/runtime-modules/asset/form-providers.d.ts +85 -2
- package/plugins/runtime-modules/asset/form-providers.js +70 -11
- package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +7 -7
- package/plugins/runtime-modules/asset/media-asset-field.js +11 -33
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +8 -7
- package/plugins/runtime-modules/asset/media-asset-form-control.js +42 -83
- 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/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 +7 -2
- package/plugins/runtime-modules/core/widgets/collection-view/client.js +12 -4
- package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +25 -0
- package/plugins/runtime-modules/core/widgets/collection-view/config.js +34 -0
- package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +3 -2
- package/plugins/runtime-modules/core/widgets/collection-view/server.js +20 -18
- 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-view-widget.d.ts +19 -0
- package/types/core-widget-placements.d.ts +9 -0
- package/types/media.d.ts +16 -0
|
@@ -4,7 +4,7 @@ import { resolvePhiMediaAssetTypeLabel } from "./asset-type-label";
|
|
|
4
4
|
import { PhiTagControl } from "../controls/phi-tag-control";
|
|
5
5
|
import { PhiButtonControl } from "../controls/phi-button-control";
|
|
6
6
|
import NextImage from "next/image";
|
|
7
|
-
import { useMemo, useState } from "react";
|
|
7
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { PhiCollectionLayoutControl } from "../controls/phi-collection-layout-control";
|
|
9
9
|
import { resolvePhiMediaKindFromContentType, } from "../../constants/media";
|
|
10
10
|
import { normalizePhiImagePreviewTile, resolvePhiMediaAssetDisplayDimensions, } from "./phi-image-preview-data";
|
|
@@ -68,7 +68,7 @@ function buildPendingWallItem(item, presentationFlags) {
|
|
|
68
68
|
function resolveUploadWallDisplayDimensions(item) {
|
|
69
69
|
return resolvePhiMediaAssetDisplayDimensions(item);
|
|
70
70
|
}
|
|
71
|
-
export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collectionContext }) {
|
|
71
|
+
export function PhiAreaUploadBinding({ config, labels, onUploadComplete, acceptance, showFinished = true, onAssetUploaded, onUploadingChange, refuseFile, siteSpaceOnly = false, collectionContext, }) {
|
|
72
72
|
const { token } = usePhiConfig();
|
|
73
73
|
const { showMessage } = usePhiApplicationFeedback();
|
|
74
74
|
const uploadTileFrameSize = token.controlHeight * 3;
|
|
@@ -77,7 +77,7 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
|
|
|
77
77
|
const activateCollectionAction = usePhiCollectionProviderAction(PHI_ASSET_COLLECTION_DATA_SOURCE);
|
|
78
78
|
const [uploadWall, setUploadWall] = useState([]);
|
|
79
79
|
const allowDelete = config?.allowDelete ?? true;
|
|
80
|
-
const
|
|
80
|
+
const configAccept = config?.accept?.trim() || "*/*";
|
|
81
81
|
const multiple = config?.multiple ?? true;
|
|
82
82
|
const collectionFolderId = collectionContext?.folderId ?? null;
|
|
83
83
|
const collectionPresentationFlags = collectionContext?.presentationFlags ?? null;
|
|
@@ -94,8 +94,9 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
|
|
|
94
94
|
configPresentationFlags: config?.presentationFlags,
|
|
95
95
|
// A Folder this Widget names is where it uploads, whichever one the Controller has open.
|
|
96
96
|
configFolderPath,
|
|
97
|
-
// Whatever Space the listing last answered with -- an upload follows the eye, not a separate choice
|
|
98
|
-
|
|
97
|
+
// Whatever Space the listing last answered with -- an upload follows the eye, not a separate choice --
|
|
98
|
+
// unless the host stores what arrives for everybody, which only the Site Space can stand behind.
|
|
99
|
+
activeSpaceAddress: siteSpaceOnly ? null : previewState.activeSpace?.address ?? null,
|
|
99
100
|
}), [
|
|
100
101
|
collectionFolderId,
|
|
101
102
|
collectionPresentationFlags,
|
|
@@ -105,6 +106,7 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
|
|
|
105
106
|
previewState.activeSpace?.address,
|
|
106
107
|
previewState.presentationFlags,
|
|
107
108
|
previewState.folderId,
|
|
109
|
+
siteSpaceOnly,
|
|
108
110
|
]);
|
|
109
111
|
function showUploadMessage(type, content) {
|
|
110
112
|
showMessage({
|
|
@@ -150,15 +152,28 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
|
|
|
150
152
|
*/
|
|
151
153
|
const upload = usePhiMediaUpload({
|
|
152
154
|
labels: labels.refusals,
|
|
155
|
+
...(acceptance ? { acceptance } : {}),
|
|
153
156
|
initOptions: uploadInitOptions,
|
|
154
157
|
onUploaded: (asset, file) => {
|
|
155
158
|
const uploadedTile = normalizePhiImagePreviewTile(asset, []);
|
|
156
|
-
|
|
159
|
+
if (showFinished) {
|
|
160
|
+
setUploadWall((current) => [buildUploadWallItem(uploadedTile, `asset-${uploadedTile.id}`), ...current]);
|
|
161
|
+
}
|
|
157
162
|
onUploadComplete?.();
|
|
158
163
|
showUploadMessage("success", labels.uploadSuccessTemplate.replace("%1", file.name));
|
|
164
|
+
onAssetUploaded?.(uploadedTile);
|
|
159
165
|
},
|
|
160
166
|
onRejected: (message) => showUploadMessage("error", message),
|
|
161
167
|
});
|
|
168
|
+
const accept = acceptance ? upload.accept : configAccept;
|
|
169
|
+
const sendingRef = useRef(0);
|
|
170
|
+
const uploading = upload.uploading;
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (!onUploadingChange)
|
|
173
|
+
return;
|
|
174
|
+
onUploadingChange(uploading);
|
|
175
|
+
}, [onUploadingChange, uploading]);
|
|
176
|
+
useEffect(() => () => onUploadingChange?.(false), [onUploadingChange]);
|
|
162
177
|
// The shared items are on their way or failed; an arrived one is a tile in the wall instead.
|
|
163
178
|
const wallItems = [
|
|
164
179
|
...upload.items
|
|
@@ -166,7 +181,18 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
|
|
|
166
181
|
.map((item) => buildPendingWallItem(item, uploadInitOptions.presentationFlags ?? 0)),
|
|
167
182
|
...uploadWall,
|
|
168
183
|
];
|
|
169
|
-
return (_jsxs(PhiFlexControl, { vertical: true, gap: 12, style: { width: "100%" }, children: [_jsx(PhiUploadDropArea, { multiple: multiple, accept: accept, title: labels.dropTitle, hint: labels.dropHint, onFile: (file) =>
|
|
184
|
+
return (_jsxs(PhiFlexControl, { vertical: true, gap: 12, style: { width: "100%" }, children: [_jsx(PhiUploadDropArea, { multiple: multiple, accept: accept, title: labels.dropTitle, hint: labels.dropHint, onFile: (file) => {
|
|
185
|
+
const refusal = refuseFile?.(file, sendingRef.current) ?? null;
|
|
186
|
+
if (refusal) {
|
|
187
|
+
showUploadMessage("error", refusal);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
// Counted rather than read off the items: a selection of several arrives file by file in one tick.
|
|
191
|
+
sendingRef.current += 1;
|
|
192
|
+
void upload.upload(file).finally(() => {
|
|
193
|
+
sendingRef.current -= 1;
|
|
194
|
+
});
|
|
195
|
+
} }), _jsx(PhiCollectionLayoutControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: uploadTileFrameSize, items: wallItems.map((item) => {
|
|
170
196
|
const displayDimensions = resolveUploadWallDisplayDimensions(item);
|
|
171
197
|
return (_jsxs("div", { style: {
|
|
172
198
|
border: resolvePhiThemeBorderLine(token.colorBorderSecondary),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PhiMediaAsset, PhiMediaAssetFolder, PhiMediaAssetTile, PhiMediaPickerPagination, PhiMediaSpaceOption } from "../../types/media";
|
|
1
|
+
import type { PhiMediaAsset, PhiMediaAssetFolder, PhiMediaAssetTile, PhiMediaCollectionItem, PhiMediaPickerPagination, PhiMediaSpaceOption } from "../../types/media";
|
|
2
2
|
export type PhiImagePreviewApiRecord = Omit<PhiMediaAsset, "kind"> & {
|
|
3
3
|
thumbnailUrl?: string | null;
|
|
4
4
|
previewUrl?: string | null;
|
|
@@ -16,6 +16,13 @@ export declare function readPhiMediaPagination(value: unknown, source?: string):
|
|
|
16
16
|
* holds items of no particular type, so whoever takes them out reads them again instead of casting.
|
|
17
17
|
*/
|
|
18
18
|
export declare function readPhiMediaAssetTiles(value: unknown, source?: string): PhiMediaAssetTile[];
|
|
19
|
+
/**
|
|
20
|
+
* The items of a Collection the Media renderer draws, from any Provider (`PhiMediaCollectionItem`): read
|
|
21
|
+
* field by field as the Media library's own tiles are, so an item without its id, name, type, kind or
|
|
22
|
+
* delivery state, or with a field of the wrong type, is an error naming the field. `deliveryUrl` is a
|
|
23
|
+
* text, empty for a reference whose Asset the library no longer answers. `source` names the Collection.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readPhiMediaCollectionItems(value: unknown, source: string): PhiMediaCollectionItem[];
|
|
19
26
|
export declare function resolvePhiMediaAssetDisplayDimensions(asset: Pick<PhiMediaAssetTile, "contentType" | "width" | "height">): {
|
|
20
27
|
width: number;
|
|
21
28
|
height: number;
|
|
@@ -171,6 +171,35 @@ export function readPhiMediaAssetTiles(value, source = PHI_MEDIA_LISTING) {
|
|
|
171
171
|
};
|
|
172
172
|
}) ?? [];
|
|
173
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* The items of a Collection the Media renderer draws, from any Provider (`PhiMediaCollectionItem`): read
|
|
176
|
+
* field by field as the Media library's own tiles are, so an item without its id, name, type, kind or
|
|
177
|
+
* delivery state, or with a field of the wrong type, is an error naming the field. `deliveryUrl` is a
|
|
178
|
+
* text, empty for a reference whose Asset the library no longer answers. `source` names the Collection.
|
|
179
|
+
*/
|
|
180
|
+
export function readPhiMediaCollectionItems(value, source) {
|
|
181
|
+
return createPhiResponseReader({ items: value }, source).list("items", (reader) => {
|
|
182
|
+
const folderId = reader.integer("folderId");
|
|
183
|
+
return {
|
|
184
|
+
id: requiredInteger(reader, "id"),
|
|
185
|
+
originalName: requiredString(reader, "originalName"),
|
|
186
|
+
title: nullableString(reader, "title"),
|
|
187
|
+
altText: nullableString(reader, "altText"),
|
|
188
|
+
// Empty for a reference whose Asset the library no longer answers: the tile shows the kind's icon.
|
|
189
|
+
deliveryUrl: typeof reader.record.deliveryUrl === "string" ? reader.record.deliveryUrl : reader.fail("deliveryUrl", "a text"),
|
|
190
|
+
thumbnailUrl: nullableString(reader, "thumbnailUrl"),
|
|
191
|
+
previewUrl: nullableString(reader, "previewUrl"),
|
|
192
|
+
blurDataUrl: nullableString(reader, "blurDataUrl"),
|
|
193
|
+
contentType: requiredString(reader, "contentType"),
|
|
194
|
+
kind: requirePhiField(reader, "kind", "a media kind", (key) => reader.oneOf(key, PHI_MEDIA_KINDS)),
|
|
195
|
+
width: nullableNumber(reader, "width"),
|
|
196
|
+
height: nullableNumber(reader, "height"),
|
|
197
|
+
lifecycleStatus: requiredInteger(reader, "lifecycleStatus"),
|
|
198
|
+
deliveryPolicy: requiredInteger(reader, "deliveryPolicy"),
|
|
199
|
+
...(folderId === undefined ? {} : { folderId }),
|
|
200
|
+
};
|
|
201
|
+
}) ?? [];
|
|
202
|
+
}
|
|
174
203
|
const PHI_SVG_MEDIA_MIN_DISPLAY_DIMENSION = 48;
|
|
175
204
|
function normalizePhiImagePreviewAsset(asset) {
|
|
176
205
|
return {
|
|
@@ -4,32 +4,36 @@ import type { PhiMediaAssetTile } from "../../types/media";
|
|
|
4
4
|
import type { PhiCmsMediaPickerWidgetConfig } from "../../types/media";
|
|
5
5
|
import type { PhiSearchWidgetLabels } from "../widgets/label-types/search";
|
|
6
6
|
import type { PhiAssetWidgetLabels } from "./media-widget-labels";
|
|
7
|
+
/**
|
|
8
|
+
* Where a file uploaded in the picker goes, as the binding hands it to the host's upload surface
|
|
9
|
+
* (`PhiMediaPickerUploadBinding.renderPanel`): the Folder in view of the Site Space (`null`, its root),
|
|
10
|
+
* and `intoStartFolder` while the picker stands where `openOnFolder` put it and that Folder's path is
|
|
11
|
+
* not all there yet -- the host then sends the file into the whole path, creating what is missing, as
|
|
12
|
+
* `area-upload` does. `onUploaded` takes the Asset that arrived, or `null` where the host does not let it
|
|
13
|
+
* be chosen: the picker reads its list again, follows the file into its Folder, and chooses it.
|
|
14
|
+
*/
|
|
15
|
+
export type PhiMediaPickerUploadTarget = {
|
|
16
|
+
folderId: number | null;
|
|
17
|
+
intoStartFolder: boolean;
|
|
18
|
+
onUploaded: (asset: PhiMediaAssetTile | null) => void;
|
|
19
|
+
};
|
|
7
20
|
/**
|
|
8
21
|
* An upload of a file from the reader's machine, offered inside the picker by a host that brings the
|
|
9
|
-
*
|
|
22
|
+
* upload surface -- the Media library's own (`PhiAreaUploadBinding`, one file, its wall showing only
|
|
23
|
+
* what is on its way), so there is one upload interface in the house and a picker without one does not
|
|
24
|
+
* carry the transport.
|
|
10
25
|
*
|
|
11
|
-
* The binding says where the file goes
|
|
12
|
-
*
|
|
13
|
-
*
|
|
26
|
+
* The binding says where the file goes and chooses what came back; the host draws the surface for that
|
|
27
|
+
* target, words what went wrong and decides whether the Asset is one to choose. The surface is drawn
|
|
28
|
+
* only while the picker is open, so closing it stops what is on its way.
|
|
14
29
|
*
|
|
15
30
|
* Offered on the Site Space only, as an import is: the file goes without a Space named, which Core
|
|
16
31
|
* answers with the Site Space, so a picker standing on another Space shows no upload.
|
|
17
32
|
*/
|
|
18
33
|
export type PhiMediaPickerUploadBinding = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/** How far the upload on its way is, in per cent; null while none is. */
|
|
22
|
-
progress: number | null;
|
|
23
|
-
/** Why the last upload did not work, or the Asset it made cannot be chosen. */
|
|
34
|
+
renderPanel: (target: PhiMediaPickerUploadTarget) => ReactNode;
|
|
35
|
+
/** Why the Asset the last upload made cannot be chosen, said above the tiles. */
|
|
24
36
|
notice: string | null;
|
|
25
|
-
/**
|
|
26
|
-
* One file into this Folder of the Site Space (null: its root). `intoStartFolder` is true while the
|
|
27
|
-
* picker stands where `openOnFolder` put it and that Folder's path is not all there yet: the host sends
|
|
28
|
-
* the file into the whole path, creating what is missing, as `area-upload` does.
|
|
29
|
-
*/
|
|
30
|
-
send: (file: File, folderId: number | null, intoStartFolder: boolean) => Promise<PhiMediaAssetTile | null>;
|
|
31
|
-
/** Stops what is on its way; the picker was closed. */
|
|
32
|
-
cancel: () => void;
|
|
33
37
|
};
|
|
34
38
|
export type PhiMediaPickerBindingProps = {
|
|
35
39
|
config?: PhiCmsMediaPickerWidgetConfig | null;
|
|
@@ -94,9 +98,7 @@ export declare function usePhiMediaPickerBinding({ config, labels, searchLabels,
|
|
|
94
98
|
sourceHasMore: boolean;
|
|
95
99
|
importingItemId: string | null;
|
|
96
100
|
sourceNotice: string | null;
|
|
97
|
-
|
|
98
|
-
uploadAccept: string | undefined;
|
|
99
|
-
uploadProgress: number | null;
|
|
101
|
+
uploadPanel: ((choose: (assetId: number) => void) => ReactNode) | undefined;
|
|
100
102
|
uploadNotice: string | null;
|
|
101
103
|
folders: ({
|
|
102
104
|
value: string;
|
|
@@ -55,11 +55,6 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
|
|
|
55
55
|
// The picker stands where `openOnFolder` put it, and the path it was asked for goes further.
|
|
56
56
|
const [onIncompleteStartFolder, setOnIncompleteStartFolder] = useState(false);
|
|
57
57
|
const startFolderRequestRef = useRef(null);
|
|
58
|
-
// The host's upload as of the last render, for the close below, which must not run again per render.
|
|
59
|
-
const uploadRef = useRef(upload);
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
uploadRef.current = upload;
|
|
62
|
-
}, [upload]);
|
|
63
58
|
const sourceRequestRef = useRef(null);
|
|
64
59
|
const importRequestRef = useRef(null);
|
|
65
60
|
const [total, setTotal] = useState(0);
|
|
@@ -225,13 +220,13 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
|
|
|
225
220
|
};
|
|
226
221
|
}, [activeSourceId, isOpen, readSourcePage]);
|
|
227
222
|
/*
|
|
228
|
-
* A closed picker stops what it asked: the listing, an import
|
|
229
|
-
*
|
|
223
|
+
* A closed picker stops what it asked: the listing, an import -- nothing is to choose for it
|
|
224
|
+
* afterwards -- and the Folder it opens on. An upload on its way stops with its surface, which the
|
|
225
|
+
* Control draws only while the picker is open.
|
|
230
226
|
*/
|
|
231
227
|
useEffect(() => {
|
|
232
228
|
if (isOpen)
|
|
233
229
|
return;
|
|
234
|
-
uploadRef.current?.cancel();
|
|
235
230
|
sourceRequestRef.current?.abort();
|
|
236
231
|
importRequestRef.current?.abort();
|
|
237
232
|
importRequestRef.current = null;
|
|
@@ -371,28 +366,22 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
|
|
|
371
366
|
* what comes back is chosen like a picked tile.
|
|
372
367
|
*/
|
|
373
368
|
const uploadOffered = upload != null && onSiteSpace;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
setRefreshToken((current) => current + 1);
|
|
391
|
-
if (!tile)
|
|
392
|
-
return null;
|
|
393
|
-
assetCacheRef.current.set(tile.id, tile);
|
|
394
|
-
return tile;
|
|
395
|
-
};
|
|
369
|
+
const uploadPanel = (choose) => upload?.renderPanel({
|
|
370
|
+
folderId,
|
|
371
|
+
intoStartFolder: onIncompleteStartFolder,
|
|
372
|
+
onUploaded: (tile) => {
|
|
373
|
+
if (tile && onIncompleteStartFolder) {
|
|
374
|
+
setFolderId(tile.folderId);
|
|
375
|
+
setOnIncompleteStartFolder(false);
|
|
376
|
+
setPage(1);
|
|
377
|
+
}
|
|
378
|
+
setRefreshToken((current) => current + 1);
|
|
379
|
+
if (!tile)
|
|
380
|
+
return;
|
|
381
|
+
assetCacheRef.current.set(tile.id, tile);
|
|
382
|
+
choose(tile.id);
|
|
383
|
+
},
|
|
384
|
+
});
|
|
396
385
|
const updateOpen = (next) => {
|
|
397
386
|
if (controlledOpen == null)
|
|
398
387
|
setLocalOpen(next);
|
|
@@ -442,9 +431,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
|
|
|
442
431
|
sourceHasMore: activeSource != null && sourceCursor != null,
|
|
443
432
|
importingItemId,
|
|
444
433
|
sourceNotice: importFailure,
|
|
445
|
-
|
|
446
|
-
uploadAccept: uploadOffered ? upload.accept : undefined,
|
|
447
|
-
uploadProgress: uploadOffered ? upload.progress : null,
|
|
434
|
+
uploadPanel: uploadOffered ? uploadPanel : undefined,
|
|
448
435
|
uploadNotice: uploadOffered ? startFolderFailure ?? upload.notice : startFolderFailure,
|
|
449
436
|
folders: provider && source ? folderOptions : [],
|
|
450
437
|
folderValue,
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { PhiMediaAssetTile, PhiMediaKindValue } from "../../types/media";
|
|
2
|
+
import type { PhiAssetWidgetLabels } from "./media-widget-labels";
|
|
3
|
+
/**
|
|
4
|
+
* The Media library's picker for a host that adds what is picked to a list of its own -- the Media
|
|
5
|
+
* renderer's "Choose from Media library" (a Collection of references) and the `media-assets` Form field:
|
|
6
|
+
* the Site Space only, twelve tiles a page with search and paging, the kind `mediaType` names (images where
|
|
7
|
+
* none), and no value of its own, since each pick is added rather than chosen.
|
|
8
|
+
*
|
|
9
|
+
* `folderPath` is the Folder it opens on, by its path of names, asked each time it opens: the host
|
|
10
|
+
* resolves its placeholders then (from the binding params, from the Form's values; a stable function),
|
|
11
|
+
* and the path is read without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader who
|
|
12
|
+
* may only choose opens it as well. `null` where the host names no Folder: the picker opens where it
|
|
13
|
+
* stood last.
|
|
14
|
+
* `isAssetSelectable` greys out what the host will not take (an Asset its list holds already).
|
|
15
|
+
*/
|
|
16
|
+
export declare function usePhiMediaLibraryAddPicker({ mediaType, labels, folderPath, isAssetSelectable, onAssetSelect, }: {
|
|
17
|
+
mediaType: PhiMediaKindValue | null;
|
|
18
|
+
labels: PhiAssetWidgetLabels;
|
|
19
|
+
folderPath: (() => readonly string[]) | null;
|
|
20
|
+
isAssetSelectable?: (asset: PhiMediaAssetTile) => boolean;
|
|
21
|
+
onAssetSelect: (asset: PhiMediaAssetTile) => void;
|
|
22
|
+
}): {
|
|
23
|
+
open: boolean;
|
|
24
|
+
value: number | null;
|
|
25
|
+
assets: PhiMediaAssetTile[];
|
|
26
|
+
spaces: {
|
|
27
|
+
value: string;
|
|
28
|
+
label: string;
|
|
29
|
+
}[];
|
|
30
|
+
spaceValue: string | null;
|
|
31
|
+
sources: {
|
|
32
|
+
value: string;
|
|
33
|
+
label: string;
|
|
34
|
+
}[];
|
|
35
|
+
sourceValue: string;
|
|
36
|
+
sourceItems: readonly import("@phis/contracts/media-source").PhisMediaSourceItem[];
|
|
37
|
+
sourceHasMore: boolean;
|
|
38
|
+
importingItemId: string | null;
|
|
39
|
+
sourceNotice: string | null;
|
|
40
|
+
uploadPanel: ((choose: (assetId: number) => void) => import("react").ReactNode) | undefined;
|
|
41
|
+
uploadNotice: string | null;
|
|
42
|
+
folders: ({
|
|
43
|
+
value: string;
|
|
44
|
+
label: string;
|
|
45
|
+
} | {
|
|
46
|
+
description?: string | undefined;
|
|
47
|
+
icon: string;
|
|
48
|
+
value: string;
|
|
49
|
+
label: string;
|
|
50
|
+
})[];
|
|
51
|
+
folderValue: string;
|
|
52
|
+
query: string;
|
|
53
|
+
page: number;
|
|
54
|
+
pageSize: number;
|
|
55
|
+
minColumnWidth: number;
|
|
56
|
+
total: number;
|
|
57
|
+
loading: boolean;
|
|
58
|
+
showSearchBar: boolean;
|
|
59
|
+
showFolderFilter: boolean;
|
|
60
|
+
showPagination: boolean;
|
|
61
|
+
trigger: import("react").ReactNode;
|
|
62
|
+
labels: {
|
|
63
|
+
trigger: string;
|
|
64
|
+
title: string;
|
|
65
|
+
search: string;
|
|
66
|
+
folder: string;
|
|
67
|
+
space: string;
|
|
68
|
+
empty: string;
|
|
69
|
+
sourceEmpty: string;
|
|
70
|
+
clear: string;
|
|
71
|
+
reload: string;
|
|
72
|
+
tileSize: string;
|
|
73
|
+
source: string;
|
|
74
|
+
importing: string;
|
|
75
|
+
loadMore: string;
|
|
76
|
+
upload: string;
|
|
77
|
+
};
|
|
78
|
+
getPopupContainer: ((triggerNode: HTMLElement) => HTMLElement) | undefined;
|
|
79
|
+
popupRootClassName: string | undefined;
|
|
80
|
+
isAssetSelectable: ((asset: PhiMediaAssetTile) => boolean) | undefined;
|
|
81
|
+
onOpenChange: (next: boolean) => void;
|
|
82
|
+
onCommit: ((assetId: number | null, originalAssetId: number | null) => void) | undefined;
|
|
83
|
+
onDiscard: ((originalAssetId: number | null) => void) | undefined;
|
|
84
|
+
onQueryChange: (nextQuery: string) => void;
|
|
85
|
+
onSpaceChange: (nextSpace: string) => void;
|
|
86
|
+
onSourceChange: (nextSource: string) => void;
|
|
87
|
+
onSourceItemSelect: (item: import("@phis/contracts/media-source").PhisMediaSourceItem) => Promise<PhiMediaAssetTile | null>;
|
|
88
|
+
onSourceLoadMore: () => void;
|
|
89
|
+
onFolderChange: (nextFolder: string) => void;
|
|
90
|
+
onPageChange: (nextPage: number, nextPageSize: number) => void;
|
|
91
|
+
onMinColumnWidthChange: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
92
|
+
onReload: () => void;
|
|
93
|
+
onChange: (assetId: number | null) => void;
|
|
94
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { PhiMediaKind } from "../../constants/media";
|
|
4
|
+
import { PHI_SEARCH_WIDGET_DEFAULT_LABELS } from "../widgets/label-types/search";
|
|
5
|
+
import { readPhiMediaUploadFolderPathReach } from "./media-upload-flow";
|
|
6
|
+
import { usePhiMediaPickerBinding } from "./phi-media-picker-binding";
|
|
7
|
+
/**
|
|
8
|
+
* The Media library's picker for a host that adds what is picked to a list of its own -- the Media
|
|
9
|
+
* renderer's "Choose from Media library" (a Collection of references) and the `media-assets` Form field:
|
|
10
|
+
* the Site Space only, twelve tiles a page with search and paging, the kind `mediaType` names (images where
|
|
11
|
+
* none), and no value of its own, since each pick is added rather than chosen.
|
|
12
|
+
*
|
|
13
|
+
* `folderPath` is the Folder it opens on, by its path of names, asked each time it opens: the host
|
|
14
|
+
* resolves its placeholders then (from the binding params, from the Form's values; a stable function),
|
|
15
|
+
* and the path is read without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader who
|
|
16
|
+
* may only choose opens it as well. `null` where the host names no Folder: the picker opens where it
|
|
17
|
+
* stood last.
|
|
18
|
+
* `isAssetSelectable` greys out what the host will not take (an Asset its list holds already).
|
|
19
|
+
*/
|
|
20
|
+
export function usePhiMediaLibraryAddPicker({ mediaType, labels, folderPath, isAssetSelectable, onAssetSelect, }) {
|
|
21
|
+
const openOnFolder = useCallback(async (signal) => {
|
|
22
|
+
const path = folderPath?.() ?? [];
|
|
23
|
+
return path.length > 0 ? readPhiMediaUploadFolderPathReach(path, signal) : { folderId: null, complete: true };
|
|
24
|
+
}, [folderPath]);
|
|
25
|
+
return usePhiMediaPickerBinding({
|
|
26
|
+
config: {
|
|
27
|
+
mediaType: mediaType ?? PhiMediaKind.Image,
|
|
28
|
+
pageSize: 12,
|
|
29
|
+
showPagination: true,
|
|
30
|
+
showSearchBar: true,
|
|
31
|
+
},
|
|
32
|
+
labels,
|
|
33
|
+
searchLabels: PHI_SEARCH_WIDGET_DEFAULT_LABELS,
|
|
34
|
+
value: null,
|
|
35
|
+
siteSpaceOnly: true,
|
|
36
|
+
isAssetSelectable,
|
|
37
|
+
onAssetSelect,
|
|
38
|
+
openOnFolder: folderPath ? openOnFolder : null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -50,3 +50,10 @@ export declare const PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY: `${string}/${string}`;
|
|
|
50
50
|
* holds no reference to the Module -- the resolver reads it to mount the library Provider the picker needs.
|
|
51
51
|
*/
|
|
52
52
|
export declare const PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY: PhiFormProviderKey;
|
|
53
|
+
/**
|
|
54
|
+
* The `media-assets` Form field type: several Assets of the Site's Media library, as an ordered list of
|
|
55
|
+
* their ids -- the many-picture counterpart of `media-asset`, for a record that has several (a product's
|
|
56
|
+
* gallery). Named on the same terms: the Asset Module owns, declares and serves it (FORMS.md), and the
|
|
57
|
+
* resolver reads this key to mount the library Provider its picker and tiles read.
|
|
58
|
+
*/
|
|
59
|
+
export declare const PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY: PhiFormProviderKey;
|
|
@@ -51,3 +51,10 @@ export const PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY = createPhiSharedRuntimeItemRen
|
|
|
51
51
|
* holds no reference to the Module -- the resolver reads it to mount the library Provider the picker needs.
|
|
52
52
|
*/
|
|
53
53
|
export const PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY = createPhiModuleScopedKey("form-field", "media-asset");
|
|
54
|
+
/**
|
|
55
|
+
* The `media-assets` Form field type: several Assets of the Site's Media library, as an ordered list of
|
|
56
|
+
* their ids -- the many-picture counterpart of `media-asset`, for a record that has several (a product's
|
|
57
|
+
* gallery). Named on the same terms: the Asset Module owns, declares and serves it (FORMS.md), and the
|
|
58
|
+
* resolver reads this key to mount the library Provider its picker and tiles read.
|
|
59
|
+
*/
|
|
60
|
+
export const PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY = createPhiModuleScopedKey("form-field", "media-assets");
|
|
@@ -48,6 +48,7 @@ const PHI_RUNTIME_MODULE_OWNERSHIP = {
|
|
|
48
48
|
"form-field/hidden": ["core", "hidden"],
|
|
49
49
|
"form-field/honeypot": ["core", "honeypot"],
|
|
50
50
|
"form-field/media-asset": ["asset", "media-asset"],
|
|
51
|
+
"form-field/media-assets": ["asset", "media-assets"],
|
|
51
52
|
"form-field/money": ["core", "money"],
|
|
52
53
|
"form-field/multi-select": ["core", "multi-select"],
|
|
53
54
|
"form-field/number": ["core", "number"],
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PhiFormDescriptor } from "@phis/contracts/forms";
|
|
2
|
+
import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../types/cms";
|
|
3
|
+
/**
|
|
4
|
+
* The rules every preset tree is held to (THIRD_PARTY_MODULES.md, "Checking a Page preset"), as findings.
|
|
5
|
+
*
|
|
6
|
+
* One source for two callers. The descriptor compiler runs it on every tree a preset loads while a Site
|
|
7
|
+
* serves the Page and throws the first finding (`assertPhiCmsPresetTreeContract`): the Page answers 500. A
|
|
8
|
+
* Module package runs it, from `@phis/ui/module/page-check`, over every tree its presets build in its own
|
|
9
|
+
* tests, with its own Forms, so the same tree fails there before it ships.
|
|
10
|
+
*
|
|
11
|
+
* The rules: every node a preset instance id, none twice, every parent, Region root, Overlay root and Page
|
|
12
|
+
* root resolved; the base page layout node only as the canonical scaffold; an actions Footer the canonical
|
|
13
|
+
* Flex preset; a modal's body and actions the dialog's (`helpers/cms-dialog.ts`), and a modal at the default
|
|
14
|
+
* `PHI_DIALOG_WIDTH` not holding only Forms of one column. The findings come in the order the compiler used
|
|
15
|
+
* to throw them, so its first is the error it always gave.
|
|
16
|
+
*
|
|
17
|
+
* `page` is the Page the tree was asked for: a tree whose Page or Regions belong to another is refused.
|
|
18
|
+
* `forms` are the Forms the caller can see, by id or as definitions; a Form not among them -- one stored on
|
|
19
|
+
* the Site, one of another Module -- is not judged, and without `forms` the dialog width is not checked.
|
|
20
|
+
*/
|
|
21
|
+
export type PhiPresetTreeContractFinding = {
|
|
22
|
+
/** The node's id, or "page" for the Page itself. */
|
|
23
|
+
node: string;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
type PresetTreeForm = {
|
|
27
|
+
descriptor: PhiFormDescriptor;
|
|
28
|
+
};
|
|
29
|
+
export declare function checkPhiPresetTreeContract(tree: PhiResolvedCmsPageTree, options?: {
|
|
30
|
+
page?: PhiCmsPageNode;
|
|
31
|
+
forms?: ReadonlyMap<string, PresetTreeForm> | Iterable<PresetTreeForm & {
|
|
32
|
+
formId: string;
|
|
33
|
+
}>;
|
|
34
|
+
}): PhiPresetTreeContractFinding[];
|
|
35
|
+
export {};
|