@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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { PhiMediaDeliveryPolicy, PhiMediaKind, PhiMediaLifecycleStatus } from "../../../constants/media";
|
|
2
|
+
import { createPhiConfigReader } from "../../../components/widgets/config/strict-config-reader";
|
|
3
|
+
import { PHI_MEDIA_ASSETS_FIELD_MOST } from "./form-providers";
|
|
4
|
+
import { readPhiMediaAssetFieldValue, readPhiMediaFieldTarget } from "./media-asset-field";
|
|
5
|
+
/**
|
|
6
|
+
* The field's config, read strictly as `media-asset`'s is (`readPhiMediaFieldTarget`): a kind the picker
|
|
7
|
+
* does not list, a broken placeholder in `folderPath`, or a `max` that is not a whole number from 1 to
|
|
8
|
+
* `PHI_MEDIA_ASSETS_FIELD_MOST` is a `PhiConfigError` naming the field, never a default in its place.
|
|
9
|
+
*/
|
|
10
|
+
export function readPhiMediaAssetsFieldConfig(config) {
|
|
11
|
+
const reader = createPhiConfigReader(config ?? {}, "config");
|
|
12
|
+
return {
|
|
13
|
+
...readPhiMediaFieldTarget(reader),
|
|
14
|
+
max: reader.value("max", `a whole number from 1 to ${PHI_MEDIA_ASSETS_FIELD_MOST}`, (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= PHI_MEDIA_ASSETS_FIELD_MOST
|
|
15
|
+
? value
|
|
16
|
+
: undefined) ?? PHI_MEDIA_ASSETS_FIELD_MOST,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The Asset ids a Form value holds, in its order: a list's entries that are Asset ids (positive whole
|
|
21
|
+
* numbers, as `media-asset` reads its one), each once; anything that is not a list holds none.
|
|
22
|
+
*/
|
|
23
|
+
export function readPhiMediaAssetsFieldValue(value) {
|
|
24
|
+
if (!Array.isArray(value))
|
|
25
|
+
return [];
|
|
26
|
+
const ids = [];
|
|
27
|
+
for (const entry of value) {
|
|
28
|
+
const id = readPhiMediaAssetFieldValue(entry);
|
|
29
|
+
if (id != null && !ids.includes(id))
|
|
30
|
+
ids.push(id);
|
|
31
|
+
}
|
|
32
|
+
return ids;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The value with Assets added at its end: the ones it does not hold yet, while there is room under `max`.
|
|
36
|
+
* Which ones did not fit is said apart, so the field can say why they are missing.
|
|
37
|
+
*/
|
|
38
|
+
export function addPhiMediaAssetsFieldIds(ids, added, max) {
|
|
39
|
+
const next = [...ids];
|
|
40
|
+
const refused = [];
|
|
41
|
+
for (const id of added) {
|
|
42
|
+
if (next.includes(id))
|
|
43
|
+
continue;
|
|
44
|
+
if (next.length >= max)
|
|
45
|
+
refused.push(id);
|
|
46
|
+
else
|
|
47
|
+
next.push(id);
|
|
48
|
+
}
|
|
49
|
+
return { ids: next, refused };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The tiles for the value, in the value's order and not the answer's: each id as the library answered
|
|
53
|
+
* it, and an id it did not answer (released, or out of the reader's reach) as an unavailable tile --
|
|
54
|
+
* named `unavailableName`, of no kind the tile would load a picture for -- which can still be removed.
|
|
55
|
+
*/
|
|
56
|
+
export function orderPhiMediaAssetsFieldTiles(ids, answered, unavailableName) {
|
|
57
|
+
return ids.map((id) => {
|
|
58
|
+
const tile = answered.get(id);
|
|
59
|
+
return tile ? { tile, available: true } : { tile: buildUnavailableTile(id, unavailableName), available: false };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function buildUnavailableTile(id, name) {
|
|
63
|
+
return {
|
|
64
|
+
id,
|
|
65
|
+
// `other` draws the kind's icon: an image tile would ask the optimiser for a picture that is not there.
|
|
66
|
+
kind: PhiMediaKind.Other,
|
|
67
|
+
originalName: name,
|
|
68
|
+
title: null,
|
|
69
|
+
altText: null,
|
|
70
|
+
contentType: "application/octet-stream",
|
|
71
|
+
deliveryUrl: "",
|
|
72
|
+
thumbnailUrl: null,
|
|
73
|
+
previewUrl: null,
|
|
74
|
+
blurDataUrl: null,
|
|
75
|
+
// Public and ready, so the tile shows the kind's icon rather than the restricted one.
|
|
76
|
+
deliveryPolicy: PhiMediaDeliveryPolicy.Public,
|
|
77
|
+
lifecycleStatus: PhiMediaLifecycleStatus.Ready,
|
|
78
|
+
width: null,
|
|
79
|
+
height: null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
|
+
import type { PhiFormFieldProviderProps } from "../../../components/forms/form-provider-registry";
|
|
3
|
+
/**
|
|
4
|
+
* The `media-assets` field: several Assets of the Site's Media library, as an ordered list of their ids
|
|
5
|
+
* (`FORMS.md`). The Form holds the value -- the draft, its dirty state, Save and Cancel, its validation --
|
|
6
|
+
* and the handler receives the ids on save; the field writes nothing anywhere itself.
|
|
7
|
+
*
|
|
8
|
+
* Composed of what the Collection View's Media renderer draws: the Media tiles in a
|
|
9
|
+
* `PhiCollectionViewControl`, each with its remove (the tile's delete, which only takes the id out of the
|
|
10
|
+
* value -- no confirm, no request, nothing released), drag reordering through the Collection's own handles
|
|
11
|
+
* (`PhiCollectionReorderContext`, the order dropped is the value's new order), the Media library's
|
|
12
|
+
* multi-upload wall (`PhiAreaUploadBinding`, what arrived leaves the wall and joins the value at its end)
|
|
13
|
+
* and its picker on the same Folder (`usePhiMediaLibraryAddPicker`, a pick joins the value at its end, an
|
|
14
|
+
* Asset the value holds already is greyed out). Both offer the Site Space only, and Core delivers every
|
|
15
|
+
* Asset there publicly from the start.
|
|
16
|
+
*
|
|
17
|
+
* `config.folderPath` names the Folder both open on and upload into, its `{key}` placeholders read from the
|
|
18
|
+
* Form's values when the picker or the upload opens (`resolvePhiMediaFolderPathTemplate`), as `media-asset`
|
|
19
|
+
* reads them. `config.max` is the most the value holds: once full the picker and the upload are not
|
|
20
|
+
* offered, a file beyond it is refused before it is sent, and a value beyond it -- one that came in --
|
|
21
|
+
* holds the Form's submit with the sentence the field shows.
|
|
22
|
+
*
|
|
23
|
+
* The tiles are read in one request for the ids the field has no tile for yet (the Media list with `id`
|
|
24
|
+
* repeated, through the Media library's collection Provider), shown in the value's order; an id the list
|
|
25
|
+
* does not answer is an unavailable tile that can still be removed. A pick or an upload brings its tile.
|
|
26
|
+
*/
|
|
27
|
+
export declare const PhiMediaAssetsFormControl: ComponentType<PhiFormFieldProviderProps>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { PhiButtonControl } from "../../../components/controls/phi-button-control";
|
|
5
|
+
import { PhiCollectionReorderContext } from "../../../components/controls/phi-collection-reorder-context";
|
|
6
|
+
import { PhiCollectionViewControl } from "../../../components/controls/phi-collection-view-control";
|
|
7
|
+
import { PhiMediaAssetCollectionSkeletonControl, PhiMediaAssetTileControl, } from "../../../components/controls/phi-media-asset-tile-control";
|
|
8
|
+
import { PhiMediaPickerControl } from "../../../components/controls/phi-media-picker-control";
|
|
9
|
+
import { PhiToolbarControl } from "../../../components/controls/phi-toolbar-control";
|
|
10
|
+
import { PhiTypographyControl } from "../../../components/controls/phi-typography-control";
|
|
11
|
+
import { PHI_FORM_UPLOAD_LABEL_KEYS } from "../../../components/forms/upload-field-keys";
|
|
12
|
+
import { PHI_ASSET_COLLECTION_DATA_SOURCE } from "../../../components/media/asset-collection-runtime";
|
|
13
|
+
import { resolvePhiMediaFolderPathTemplate } from "../../../components/media/media-folder-name-path";
|
|
14
|
+
import { PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS } from "../../../components/media/media-upload-labels";
|
|
15
|
+
import { PhiAreaUploadBinding } from "../../../components/media/phi-area-upload-widget";
|
|
16
|
+
import { readPhiMediaCollectionItems } from "../../../components/media/phi-image-preview-data";
|
|
17
|
+
import { usePhiMediaLibraryAddPicker } from "../../../components/media/use-media-library-add-picker";
|
|
18
|
+
import { usePhiCollectionProvider } from "../../../components/widgets/client/shared/phi-collection-provider";
|
|
19
|
+
import { usePhiIntlLocale, usePhiIntlTimeZone } from "../../../components/root/phi-intl-locale";
|
|
20
|
+
import { usePhiConfig } from "../../../components/root/phi-config-provider";
|
|
21
|
+
import { PHI_FORM_MEDIA_ASSETS_LABEL_KEYS, PHI_MEDIA_ASSETS_FIELD_MOST } from "./form-providers";
|
|
22
|
+
import { readPhiMediaFieldPickerLabels } from "./media-field-picker-labels";
|
|
23
|
+
import { addPhiMediaAssetsFieldIds, orderPhiMediaAssetsFieldTiles, readPhiMediaAssetsFieldConfig, readPhiMediaAssetsFieldValue, } from "./media-assets-field";
|
|
24
|
+
const DEFAULT_LABELS = {
|
|
25
|
+
remove: "Remove",
|
|
26
|
+
reorder: "Drag to reorder",
|
|
27
|
+
unavailable: "The file could not be read.",
|
|
28
|
+
tooMany: "At most %1 files.",
|
|
29
|
+
};
|
|
30
|
+
// The Media renderer's tile width, so the field's tiles are the ones its Collection draws.
|
|
31
|
+
const TILE_MIN_WIDTH = 102;
|
|
32
|
+
/**
|
|
33
|
+
* The `media-assets` field: several Assets of the Site's Media library, as an ordered list of their ids
|
|
34
|
+
* (`FORMS.md`). The Form holds the value -- the draft, its dirty state, Save and Cancel, its validation --
|
|
35
|
+
* and the handler receives the ids on save; the field writes nothing anywhere itself.
|
|
36
|
+
*
|
|
37
|
+
* Composed of what the Collection View's Media renderer draws: the Media tiles in a
|
|
38
|
+
* `PhiCollectionViewControl`, each with its remove (the tile's delete, which only takes the id out of the
|
|
39
|
+
* value -- no confirm, no request, nothing released), drag reordering through the Collection's own handles
|
|
40
|
+
* (`PhiCollectionReorderContext`, the order dropped is the value's new order), the Media library's
|
|
41
|
+
* multi-upload wall (`PhiAreaUploadBinding`, what arrived leaves the wall and joins the value at its end)
|
|
42
|
+
* and its picker on the same Folder (`usePhiMediaLibraryAddPicker`, a pick joins the value at its end, an
|
|
43
|
+
* Asset the value holds already is greyed out). Both offer the Site Space only, and Core delivers every
|
|
44
|
+
* Asset there publicly from the start.
|
|
45
|
+
*
|
|
46
|
+
* `config.folderPath` names the Folder both open on and upload into, its `{key}` placeholders read from the
|
|
47
|
+
* Form's values when the picker or the upload opens (`resolvePhiMediaFolderPathTemplate`), as `media-asset`
|
|
48
|
+
* reads them. `config.max` is the most the value holds: once full the picker and the upload are not
|
|
49
|
+
* offered, a file beyond it is refused before it is sent, and a value beyond it -- one that came in --
|
|
50
|
+
* holds the Form's submit with the sentence the field shows.
|
|
51
|
+
*
|
|
52
|
+
* The tiles are read in one request for the ids the field has no tile for yet (the Media list with `id`
|
|
53
|
+
* repeated, through the Media library's collection Provider), shown in the value's order; an id the list
|
|
54
|
+
* does not answer is an unavailable tile that can still be removed. A pick or an upload brings its tile.
|
|
55
|
+
*/
|
|
56
|
+
export const PhiMediaAssetsFormControl = ({ field, value, labels, disabled, readOnly, onChange, formContext, }) => {
|
|
57
|
+
const { token } = usePhiConfig();
|
|
58
|
+
const config = useMemo(() => readPhiMediaAssetsFieldConfig(field.config), [field.config]);
|
|
59
|
+
const ids = readPhiMediaAssetsFieldValue(value);
|
|
60
|
+
const locked = disabled === true || readOnly === true;
|
|
61
|
+
const full = ids.length >= config.max;
|
|
62
|
+
const read = (key) => labels?.[PHI_FORM_MEDIA_ASSETS_LABEL_KEYS[key]]?.trim() || DEFAULT_LABELS[key];
|
|
63
|
+
const tooMany = read("tooMany").replace("%1", String(config.max));
|
|
64
|
+
const unavailableName = read("unavailable");
|
|
65
|
+
const mediaLabels = useMemo(() => {
|
|
66
|
+
const base = readPhiMediaFieldPickerLabels(labels);
|
|
67
|
+
return { ...base, picker: { ...base.picker, triggerLabel: base.tool.chooseFromLibraryLabel } };
|
|
68
|
+
}, [labels]);
|
|
69
|
+
const pendingLabel = labels?.[PHI_FORM_UPLOAD_LABEL_KEYS.pending]?.trim() || PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS.pending;
|
|
70
|
+
/*
|
|
71
|
+
* The value as the Form holds it this instant: two uploads that finish in one tick each add to what the
|
|
72
|
+
* other left, not to the value this render received. Outside a Form there is only the render's value.
|
|
73
|
+
*/
|
|
74
|
+
const readIdsNow = () => formContext ? readPhiMediaAssetsFieldValue(formContext.getValues()[field.key]) : ids;
|
|
75
|
+
const commit = (next) => onChange?.([...next]);
|
|
76
|
+
const [notice, setNotice] = useState(null);
|
|
77
|
+
// The tiles the field knows, by Asset id: read from the list, or brought by a pick or an upload.
|
|
78
|
+
const [tiles, setTiles] = useState(() => new Map());
|
|
79
|
+
const [unreadable, setUnreadable] = useState(() => new Set());
|
|
80
|
+
const knowTiles = useCallback((known) => {
|
|
81
|
+
if (known.length === 0)
|
|
82
|
+
return;
|
|
83
|
+
setTiles((current) => new Map([...current, ...known.map((tile) => [tile.id, tile])]));
|
|
84
|
+
}, []);
|
|
85
|
+
const add = (assets) => {
|
|
86
|
+
knowTiles(assets);
|
|
87
|
+
const { ids: next, refused } = addPhiMediaAssetsFieldIds(readIdsNow(), assets.map((asset) => asset.id), config.max);
|
|
88
|
+
setNotice(refused.length > 0 ? tooMany : null);
|
|
89
|
+
commit(next);
|
|
90
|
+
};
|
|
91
|
+
// One read for the ids the field has no tile for: the Media list answers them by `id`, at most 100 a read.
|
|
92
|
+
const { provider } = usePhiCollectionProvider(PHI_ASSET_COLLECTION_DATA_SOURCE);
|
|
93
|
+
const locale = usePhiIntlLocale();
|
|
94
|
+
const timeZone = usePhiIntlTimeZone();
|
|
95
|
+
const missingKey = ids.filter((id) => !tiles.has(id) && !unreadable.has(id)).join(",");
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const missing = missingKey ? missingKey.split(",").map(Number).slice(0, PHI_MEDIA_ASSETS_FIELD_MOST) : [];
|
|
98
|
+
if (missing.length === 0 || !provider)
|
|
99
|
+
return;
|
|
100
|
+
const controller = new AbortController();
|
|
101
|
+
void (async () => {
|
|
102
|
+
let answered = [];
|
|
103
|
+
try {
|
|
104
|
+
const data = await provider.query({
|
|
105
|
+
resourceKey: PHI_ASSET_COLLECTION_DATA_SOURCE.resourceKey,
|
|
106
|
+
query: { page: 1, pageSize: missing.length, filters: { id: missing } },
|
|
107
|
+
locale,
|
|
108
|
+
timeZone,
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
});
|
|
111
|
+
if (data.error)
|
|
112
|
+
throw new Error(data.error);
|
|
113
|
+
// Only the ids asked for: a Server that does not filter by `id` answers some page of the library.
|
|
114
|
+
answered = readPhiMediaCollectionItems(data.items, "The Media library").filter((tile) => missing.includes(tile.id));
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (controller.signal.aborted)
|
|
118
|
+
return;
|
|
119
|
+
console.error("The media-assets field could not read its Assets.", error);
|
|
120
|
+
}
|
|
121
|
+
if (controller.signal.aborted)
|
|
122
|
+
return;
|
|
123
|
+
knowTiles(answered);
|
|
124
|
+
// What the list did not answer is unavailable, and not asked for again.
|
|
125
|
+
const answeredIds = new Set(answered.map((tile) => tile.id));
|
|
126
|
+
setUnreadable((current) => new Set([...current, ...missing.filter((id) => !answeredIds.has(id))]));
|
|
127
|
+
})();
|
|
128
|
+
return () => controller.abort();
|
|
129
|
+
}, [knowTiles, locale, missingKey, provider, timeZone]);
|
|
130
|
+
/*
|
|
131
|
+
* The submit is held while the value is beyond `max` (one that came in) -- said on the field the way a
|
|
132
|
+
* rule is -- and while a file is on its way, with the upload field's sentence.
|
|
133
|
+
*/
|
|
134
|
+
const overMax = ids.length > config.max;
|
|
135
|
+
const [uploading, setUploading] = useState(false);
|
|
136
|
+
const holdReason = overMax ? tooMany : uploading ? pendingLabel : null;
|
|
137
|
+
useEffect(() => {
|
|
138
|
+
if (!formContext || holdReason == null)
|
|
139
|
+
return;
|
|
140
|
+
formContext.holdSubmit(field.key, holdReason);
|
|
141
|
+
return () => formContext.holdSubmit(field.key, null);
|
|
142
|
+
}, [field.key, formContext, holdReason]);
|
|
143
|
+
// The Folder path as the Form's values name it, read when the picker or the upload opens.
|
|
144
|
+
const folderPathTemplate = config.folderPath;
|
|
145
|
+
const resolveFolderPath = useCallback(() => resolvePhiMediaFolderPathTemplate(folderPathTemplate, formContext?.getValues() ?? {}), [folderPathTemplate, formContext]);
|
|
146
|
+
const picker = usePhiMediaLibraryAddPicker({
|
|
147
|
+
mediaType: config.mediaType,
|
|
148
|
+
labels: mediaLabels,
|
|
149
|
+
folderPath: folderPathTemplate.length > 0 ? resolveFolderPath : null,
|
|
150
|
+
isAssetSelectable: (candidate) => !ids.includes(candidate.id),
|
|
151
|
+
onAssetSelect: (picked) => add([picked]),
|
|
152
|
+
});
|
|
153
|
+
/*
|
|
154
|
+
* The upload wall, into the Folder path as it was when the wall opened. A file the value has no room for
|
|
155
|
+
* -- counting the ones on their way -- is refused before it is sent, so a selection of several that
|
|
156
|
+
* would overfill it sends only what fits.
|
|
157
|
+
*/
|
|
158
|
+
const [uploadFolderPath, setUploadFolderPath] = useState(null);
|
|
159
|
+
const acceptance = useMemo(() => ({ kinds: [config.mediaType], multiple: config.max > 1 }), [config.mediaType, config.max]);
|
|
160
|
+
const uploadPanel = uploadFolderPath && !locked ? (_jsx(PhiAreaUploadBinding, { labels: mediaLabels.upload, config: uploadFolderPath.length > 0 ? { folderPath: uploadFolderPath.join(" / ") } : null, acceptance: acceptance, showFinished: false, siteSpaceOnly: true, collectionContext: { folders: [], folderId: null, folderPath: null, presentationFlags: null, query: {} }, onUploadingChange: setUploading, refuseFile: (_file, sending) => readIdsNow().length + sending >= config.max ? tooMany : null, onAssetUploaded: (asset) => {
|
|
161
|
+
// Core does not know the field's kind, and a file the browser could not name reaches it unrefused.
|
|
162
|
+
if (asset.kind !== config.mediaType) {
|
|
163
|
+
setNotice(mediaLabels.upload.refusals.errorTypeNotAllowed);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
add([asset]);
|
|
167
|
+
} })) : null;
|
|
168
|
+
const shown = orderPhiMediaAssetsFieldTiles(ids, tiles, unavailableName);
|
|
169
|
+
const toolbar = locked ? null : (_jsxs(PhiToolbarControl, { compact: true, size: "small", children: [_jsx(PhiButtonControl, { label: mediaLabels.upload.uploadToggleLabel, size: "small", type: uploadFolderPath ? "primary" : "default", disabled: full && !uploadFolderPath, onClick: () => setUploadFolderPath((current) => current ? null : resolveFolderPath()) }), _jsx(PhiMediaPickerControl, { ...picker, disabled: full })] }));
|
|
170
|
+
// The Collection's own drag handles; the order dropped is the value's new order.
|
|
171
|
+
const reorder = locked || ids.length < 2 ? null : {
|
|
172
|
+
itemKeys: ids,
|
|
173
|
+
onReorder: (keys) => commit(readPhiMediaAssetsFieldValue(keys)),
|
|
174
|
+
handleLabel: read("reorder"),
|
|
175
|
+
};
|
|
176
|
+
// While the first tiles are read, the Media renderer's skeleton stands where they will be.
|
|
177
|
+
const reading = missingKey !== "" && provider != null;
|
|
178
|
+
return (_jsx(PhiCollectionReorderContext.Provider, { value: reorder, children: _jsx(PhiCollectionViewControl, { toolbar: toolbar, panel: uploadPanel, diagnostics: overMax || notice ? (_jsx(PhiTypographyControl, { type: "danger", children: overMax ? tooMany : notice })) : null, body: reading ? (_jsx(PhiMediaAssetCollectionSkeletonControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: TILE_MIN_WIDTH, count: Math.min(ids.length, 6) })) : undefined, items: shown.map(({ tile, available }) => (_jsx(PhiMediaAssetTileControl, { asset: tile, minColumnWidth: TILE_MIN_WIDTH, onDelete: (removed) => {
|
|
179
|
+
setNotice(null);
|
|
180
|
+
commit(readIdsNow().filter((id) => id !== removed.id));
|
|
181
|
+
}, deleteLabel: read("remove"), showDeleteAction: !locked, showTypeLabel: available, showDimensions: true, showIdLabel: true }, tile.id))), mode: "grid", minColumnWidth: TILE_MIN_WIDTH }) }));
|
|
182
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PhiAssetWidgetLabels } from "../../../components/media/media-widget-labels";
|
|
2
|
+
/**
|
|
3
|
+
* The Media picker's and the upload surface's words for a Media field of a Form (`media-asset`,
|
|
4
|
+
* `media-assets`), read from the field's labels -- where the Form Widget put the Media Label Set's words
|
|
5
|
+
* for the Form (`form-field-labels.ts`, `PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS`), with the upload's
|
|
6
|
+
* refusals under the upload field's keys -- and the English defaults beneath. Outside a Form that read
|
|
7
|
+
* them, the defaults stand. The trigger's words are each field's own and laid over by it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readPhiMediaFieldPickerLabels(labels: Readonly<Record<string, string>> | undefined): PhiAssetWidgetLabels;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS } from "../../../components/forms/media-asset-field-keys";
|
|
2
|
+
import { readPhiFormUploadRefusalLabels } from "../../../components/forms/upload-field-refusal-labels";
|
|
3
|
+
import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../components/media/media-widget-labels";
|
|
4
|
+
/**
|
|
5
|
+
* The Media picker's and the upload surface's words for a Media field of a Form (`media-asset`,
|
|
6
|
+
* `media-assets`), read from the field's labels -- where the Form Widget put the Media Label Set's words
|
|
7
|
+
* for the Form (`form-field-labels.ts`, `PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS`), with the upload's
|
|
8
|
+
* refusals under the upload field's keys -- and the English defaults beneath. Outside a Form that read
|
|
9
|
+
* them, the defaults stand. The trigger's words are each field's own and laid over by it.
|
|
10
|
+
*/
|
|
11
|
+
export function readPhiMediaFieldPickerLabels(labels) {
|
|
12
|
+
const read = (key, fallback) => labels?.[PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS[key]]?.trim() || fallback;
|
|
13
|
+
const base = PHI_MEDIA_WIDGET_DEFAULT_LABELS;
|
|
14
|
+
return {
|
|
15
|
+
...base,
|
|
16
|
+
tool: {
|
|
17
|
+
...base.tool,
|
|
18
|
+
searchPlaceholder: read("searchPlaceholder", base.tool.searchPlaceholder),
|
|
19
|
+
folderLabel: read("folderLabel", base.tool.folderLabel),
|
|
20
|
+
reloadLabel: read("reloadLabel", base.tool.reloadLabel),
|
|
21
|
+
chooseFromLibraryLabel: read("chooseFromLibraryLabel", base.tool.chooseFromLibraryLabel),
|
|
22
|
+
},
|
|
23
|
+
picker: {
|
|
24
|
+
...base.picker,
|
|
25
|
+
popoverTitle: read("popoverTitle", base.picker.popoverTitle),
|
|
26
|
+
emptyDescription: read("emptyDescription", base.picker.emptyDescription),
|
|
27
|
+
loadFailedDescription: read("loadFailedDescription", base.picker.loadFailedDescription),
|
|
28
|
+
clearLabel: read("clearLabel", base.picker.clearLabel),
|
|
29
|
+
tileSizeLabel: read("tileSizeLabel", base.picker.tileSizeLabel),
|
|
30
|
+
sourceLabel: read("sourceLabel", base.picker.sourceLabel),
|
|
31
|
+
sourceFailedText: read("sourceFailedText", base.picker.sourceFailedText),
|
|
32
|
+
importingLabel: read("importingLabel", base.picker.importingLabel),
|
|
33
|
+
importFailedText: read("importFailedText", base.picker.importFailedText),
|
|
34
|
+
loadMoreLabel: read("loadMoreLabel", base.picker.loadMoreLabel),
|
|
35
|
+
},
|
|
36
|
+
upload: {
|
|
37
|
+
...base.upload,
|
|
38
|
+
uploadToggleLabel: read("uploadLabel", base.upload.uploadToggleLabel),
|
|
39
|
+
dropTitle: read("uploadDropTitle", base.upload.dropTitle),
|
|
40
|
+
dropHint: read("uploadDropHint", base.upload.dropHint),
|
|
41
|
+
retryLabel: read("uploadRetryLabel", base.upload.retryLabel),
|
|
42
|
+
doneLabel: read("uploadDoneLabel", base.upload.doneLabel),
|
|
43
|
+
failedLabel: read("uploadFailedLabel", base.upload.failedLabel),
|
|
44
|
+
uploadSuccessTemplate: read("uploadSuccessTemplate", base.upload.uploadSuccessTemplate),
|
|
45
|
+
refusals: readPhiFormUploadRefusalLabels(labels),
|
|
46
|
+
},
|
|
47
|
+
space: { ...base.space, label: read("spaceLabel", base.space.label) },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -46,6 +46,18 @@ function buildMediaQuery(query) {
|
|
|
46
46
|
search.set("since", since);
|
|
47
47
|
if (typeof until === "string" && until)
|
|
48
48
|
search.set("until", until);
|
|
49
|
+
/*
|
|
50
|
+
* Named Assets (`filters.id`, the ids as a list): the list answers those, in its usual shape, at most
|
|
51
|
+
* 100 of them -- the read a `media-assets` field draws its tiles from. A program's filter and not an
|
|
52
|
+
* author's, so the resource does not declare it among its `filterFields`.
|
|
53
|
+
*/
|
|
54
|
+
const id = readFilter(query, "id");
|
|
55
|
+
if (Array.isArray(id)) {
|
|
56
|
+
id.forEach((entry) => {
|
|
57
|
+
if (typeof entry === "number" && Number.isSafeInteger(entry) && entry > 0)
|
|
58
|
+
search.append("id", String(entry));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
49
61
|
return search;
|
|
50
62
|
}
|
|
51
63
|
/** The Media library answers file names and sizes, nothing in a language, so it reads neither `locale` nor `timeZone`. */
|
|
@@ -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;
|