@phis/ui 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/controls/phi-form-control.js +1 -0
- 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/controls/phi-options-provider.d.ts +14 -1
- package/components/controls/phi-options-provider.js +73 -2
- 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/components/widgets/client/shared/phi-choice-controller.js +22 -15
- 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/builder/clients/inspector-config-field.js +11 -6
- package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
- package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
- 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/core/widgets/multi-select/client.js +6 -4
- 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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY } from "../../constants/media-library-provider-keys";
|
|
2
|
+
import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../types/signals";
|
|
3
|
+
/**
|
|
4
|
+
* The Media library's own Collection resource, `assets` of `PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection`,
|
|
5
|
+
* as the Asset Module declares it (`plugins/runtime-modules/asset/data-providers.ts` names this object):
|
|
6
|
+
* its filters, its Folder, lock, upload and delete actions, and its upload panel -- what the Media
|
|
7
|
+
* renderer offers for it (COLLECTIONS.md, "The Media renderer").
|
|
8
|
+
*
|
|
9
|
+
* The Foundation's, like the keys beside it, because a Foundation surface binds that resource without a
|
|
10
|
+
* page's registry and still has to hand the renderer its declaration: the Media preview grid
|
|
11
|
+
* (`PhiAssetPreviewGridWidget`). One object, so the declaration the Area's registry holds and the one the
|
|
12
|
+
* grid hands over cannot say different things.
|
|
13
|
+
*/
|
|
14
|
+
export const PHI_MEDIA_LIBRARY_ASSET_RESOURCE = {
|
|
15
|
+
resourceKey: "assets",
|
|
16
|
+
title: "Assets",
|
|
17
|
+
itemIdentityPath: "id",
|
|
18
|
+
itemRendererKey: PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY,
|
|
19
|
+
selectionValueSchema: PHI_SIGNAL_VALUE_SCHEMAS.mediaAssetSelection,
|
|
20
|
+
defaultForWidget: true,
|
|
21
|
+
query: {
|
|
22
|
+
search: true,
|
|
23
|
+
pagination: true,
|
|
24
|
+
filterFields: [
|
|
25
|
+
{ key: "kind", title: "Kind", type: "enum[]" },
|
|
26
|
+
{ key: "presentationFlags", title: "Flags", type: "enum[]" },
|
|
27
|
+
{ key: "folderId", title: "Folder", type: "path" },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
actions: [
|
|
31
|
+
{ key: "createFolder", title: "Create folder", scope: "resource" },
|
|
32
|
+
// The Folder the listing is filtered to; Core refuses every change to what a locked one holds.
|
|
33
|
+
{ key: "lockFolder", title: "Lock folder", scope: "resource" },
|
|
34
|
+
{ key: "unlockFolder", title: "Unlock folder", scope: "resource" },
|
|
35
|
+
{ key: "upload", title: "Upload", scope: "resource", panelKey: "upload" },
|
|
36
|
+
{ key: "refresh", title: "Reload", scope: "resource" },
|
|
37
|
+
{ key: "update", title: "Update", scope: "item" },
|
|
38
|
+
{ key: "delete", title: "Delete", scope: "item" },
|
|
39
|
+
],
|
|
40
|
+
panels: [{ key: "upload", title: "Upload assets" }],
|
|
41
|
+
};
|
|
@@ -15,6 +15,12 @@ export type PhiAssetPreviewToolWidgetLabels = {
|
|
|
15
15
|
kindLabel: string;
|
|
16
16
|
resetLabel: string;
|
|
17
17
|
reloadLabel: string;
|
|
18
|
+
/**
|
|
19
|
+
* The Media renderer's toolbar action `add`: the Media library's picker, whose pick goes to the bound
|
|
20
|
+
* resource's `add` action. A Collection of references to Assets offers it (a gallery); the Media
|
|
21
|
+
* library's own does not.
|
|
22
|
+
*/
|
|
23
|
+
chooseFromLibraryLabel: string;
|
|
18
24
|
imageKindLabel: string;
|
|
19
25
|
videoKindLabel: string;
|
|
20
26
|
audioKindLabel: string;
|
|
@@ -50,9 +56,16 @@ export type PhiAreaUploadWidgetLabels = {
|
|
|
50
56
|
};
|
|
51
57
|
export type PhiAssetPreviewGridWidgetLabels = {
|
|
52
58
|
emptyDescription: string;
|
|
59
|
+
/**
|
|
60
|
+
* A tile's delete, the bound resource's `delete` action: the Media library deletes the file, a
|
|
61
|
+
* Collection of references takes it out -- whose placement says so in its own words
|
|
62
|
+
* (`presentation.labels.grid`).
|
|
63
|
+
*/
|
|
53
64
|
deleteLabel: string;
|
|
54
65
|
deleteSuccessTemplate: string;
|
|
55
66
|
deleteFailedText: string;
|
|
67
|
+
/** Said where the resource's `add` action refused an Asset picked or uploaded, without words of its own. */
|
|
68
|
+
addFailedText: string;
|
|
56
69
|
};
|
|
57
70
|
export type PhiAssetInspectorWidgetLabels = {
|
|
58
71
|
inspectorTitle: string;
|
|
@@ -14,6 +14,7 @@ export const PHI_MEDIA_WIDGET_DEFAULT_LABELS = {
|
|
|
14
14
|
kindLabel: "Kind",
|
|
15
15
|
resetLabel: "Reset",
|
|
16
16
|
reloadLabel: "Reload",
|
|
17
|
+
chooseFromLibraryLabel: "Choose from Media library",
|
|
17
18
|
imageKindLabel: "image",
|
|
18
19
|
videoKindLabel: "video",
|
|
19
20
|
audioKindLabel: "audio",
|
|
@@ -47,6 +48,7 @@ export const PHI_MEDIA_WIDGET_DEFAULT_LABELS = {
|
|
|
47
48
|
deleteLabel: "Delete asset",
|
|
48
49
|
deleteSuccessTemplate: "Asset %1 deleted.",
|
|
49
50
|
deleteFailedText: "Delete failed.",
|
|
51
|
+
addFailedText: "The file could not be added.",
|
|
50
52
|
},
|
|
51
53
|
picker: {
|
|
52
54
|
triggerLabel: "Mediathek",
|
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
import type { PhiCmsAreaUploadWidgetConfig } from "../../types/media";
|
|
2
|
+
import type { PhiMediaAssetTile } from "../../types/media";
|
|
2
3
|
import type { PhiCollectionProviderQuery } from "../../types/collection-provider";
|
|
3
4
|
import type { PhiAreaUploadWidgetLabels } from "./media-widget-labels";
|
|
5
|
+
import { type PhiMediaUploadAcceptance } from "./phi-media-upload";
|
|
4
6
|
import { type PhiImagePreviewStoreState } from "./phi-image-preview-store";
|
|
5
7
|
export type PhiAreaUploadWidgetProps = {
|
|
6
8
|
config?: PhiCmsAreaUploadWidgetConfig | null;
|
|
7
9
|
labels: PhiAreaUploadWidgetLabels;
|
|
8
10
|
onUploadComplete?: () => void;
|
|
11
|
+
/**
|
|
12
|
+
* What the surface takes (`usePhiMediaUpload`'s acceptance): a file of another kind is refused before
|
|
13
|
+
* it is sent, and the file dialog offers these kinds. Absent: `config.accept`, every file by default.
|
|
14
|
+
*/
|
|
15
|
+
acceptance?: PhiMediaUploadAcceptance;
|
|
16
|
+
/**
|
|
17
|
+
* Whether an Asset that arrived stays in the wall as a tile, with its delete -- the Media library's own
|
|
18
|
+
* upload panel. `false` for a surface whose Collection shows what arrived itself (a Collection View of
|
|
19
|
+
* another Provider that adds it, the picker that chooses it): only the files on their way and the
|
|
20
|
+
* failed ones stand here, so nothing shows twice. Default `true`.
|
|
21
|
+
*/
|
|
22
|
+
showFinished?: boolean;
|
|
23
|
+
/** The Asset that arrived, for a host that does something with it (adds it, chooses it). */
|
|
24
|
+
onAssetUploaded?: (asset: PhiMediaAssetTile) => void;
|
|
25
|
+
/** Whether a file is on its way, for a host that holds something back meanwhile (a Form's submit). */
|
|
26
|
+
onUploadingChange?: (uploading: boolean) => void;
|
|
27
|
+
/**
|
|
28
|
+
* The host's own refusal of a file before it is sent, asked of each file dropped or chosen with the
|
|
29
|
+
* number of files this surface has on their way (the ones let through in the same selection included):
|
|
30
|
+
* the sentence, said as the upload's refusals are (an application message), or `null` to send it. For a
|
|
31
|
+
* host whose list has room for so many (the `media-assets` field's `max`).
|
|
32
|
+
*/
|
|
33
|
+
refuseFile?: (file: File, sending: number) => string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Uploads into the Site Space, whatever Space the Media library's listing last showed: for a host that
|
|
36
|
+
* stores a reference everybody follows. A `config.folderPath` is read in the Site Space either way.
|
|
37
|
+
*/
|
|
38
|
+
siteSpaceOnly?: boolean;
|
|
9
39
|
collectionContext?: {
|
|
10
40
|
folders: PhiImagePreviewStoreState["folders"];
|
|
11
41
|
folderId: number | null;
|
|
@@ -14,5 +44,5 @@ export type PhiAreaUploadWidgetProps = {
|
|
|
14
44
|
query: PhiCollectionProviderQuery;
|
|
15
45
|
};
|
|
16
46
|
};
|
|
17
|
-
export declare function PhiAreaUploadBinding({ config, labels, onUploadComplete, collectionContext }: PhiAreaUploadWidgetProps): import("react").JSX.Element;
|
|
47
|
+
export declare function PhiAreaUploadBinding({ config, labels, onUploadComplete, acceptance, showFinished, onAssetUploaded, onUploadingChange, refuseFile, siteSpaceOnly, collectionContext, }: PhiAreaUploadWidgetProps): import("react").JSX.Element;
|
|
18
48
|
export declare function PhiAreaUploadWidget(props: PhiAreaUploadWidgetProps): import("react").JSX.Element;
|
|
@@ -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
|
+
}
|