@phis/ui 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/controls/phi-collection-reorder-context.d.ts +21 -0
- package/components/controls/phi-collection-reorder-context.js +6 -0
- package/components/controls/phi-collection-sortable-layout-control.d.ts +17 -0
- package/components/controls/phi-collection-sortable-layout-control.js +72 -0
- package/components/controls/phi-collection-view-control.d.ts +1 -1
- package/components/controls/phi-collection-view-control.js +15 -1
- package/components/controls/phi-media-asset-tile-control.d.ts +14 -6
- package/components/controls/phi-media-picker-control.d.ts +13 -2
- package/components/controls/phi-media-picker-control.js +9 -2
- package/components/forms/compound-form-controls.d.ts +1 -1
- package/components/forms/compound-form-controls.js +6 -4
- package/components/forms/form-field-labels.d.ts +4 -2
- package/components/forms/form-field-labels.js +30 -9
- package/components/forms/form-provider-contract.js +2 -1
- package/components/forms/media-asset-field-keys.d.ts +13 -2
- package/components/forms/media-asset-field-keys.js +17 -2
- package/components/forms/table-field-keys.d.ts +8 -0
- package/components/forms/table-field-keys.js +8 -0
- package/components/forms/table-field-labels.d.ts +16 -0
- package/components/forms/table-field-labels.js +16 -0
- package/components/forms/table-field-text.d.ts +9 -0
- package/components/forms/table-field-text.js +20 -0
- package/components/forms/upload-field-refusal-labels.d.ts +10 -0
- package/components/forms/upload-field-refusal-labels.js +24 -0
- package/components/forms/upload-form-control.js +3 -16
- package/components/media/label-sets/media.js +4 -0
- package/components/media/media-folder-name-path.d.ts +14 -0
- package/components/media/media-folder-name-path.js +40 -2
- package/components/media/media-library-resource.d.ts +70 -0
- package/components/media/media-library-resource.js +41 -0
- package/components/media/media-upload-flow.d.ts +13 -1
- package/components/media/media-upload-flow.js +16 -0
- package/components/media/media-widget-labels.d.ts +13 -0
- package/components/media/media-widget-labels.js +2 -0
- package/components/media/phi-area-upload-widget.d.ts +31 -1
- package/components/media/phi-area-upload-widget.js +33 -7
- package/components/media/phi-image-preview-data.d.ts +8 -1
- package/components/media/phi-image-preview-data.js +29 -0
- package/components/media/phi-media-picker-binding.d.ts +50 -1
- package/components/media/phi-media-picker-binding.js +86 -6
- package/components/media/phi-media-upload.d.ts +7 -1
- package/components/media/phi-media-upload.js +17 -5
- package/components/media/use-media-library-add-picker.d.ts +94 -0
- package/components/media/use-media-library-add-picker.js +40 -0
- package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
- package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
- package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
- package/components/widgets/label-sets/collection-view.d.ts +4 -0
- package/components/widgets/label-sets/collection-view.js +16 -0
- package/components/widgets/label-sets/table.d.ts +6 -0
- package/components/widgets/label-sets/table.js +10 -0
- package/components/widgets/label-types/collection-view.d.ts +8 -0
- package/components/widgets/label-types/collection-view.js +4 -0
- package/constants/media-library-provider-keys.d.ts +7 -0
- package/constants/media-library-provider-keys.js +7 -0
- package/constants/runtime-module-ownership.js +1 -0
- package/controls.d.ts +1 -1
- package/helpers/preset-tree-contract-check.d.ts +35 -0
- package/helpers/preset-tree-contract-check.js +211 -0
- package/module-page-check.d.ts +6 -0
- package/module-page-check.js +6 -0
- package/package.json +1 -1
- package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
- package/plugins/runtime-modules/asset/data-providers.js +4 -32
- package/plugins/runtime-modules/asset/definition.d.ts +123 -38
- package/plugins/runtime-modules/asset/definition.js +2 -1
- package/plugins/runtime-modules/asset/form-providers.d.ts +93 -2
- package/plugins/runtime-modules/asset/form-providers.js +76 -11
- package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
- package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
- package/plugins/runtime-modules/asset/media-asset-field.js +30 -5
- package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +14 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +72 -37
- package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
- package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
- package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
- package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
- package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
- package/plugins/runtime-modules/asset/services/collection.js +12 -0
- package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
- package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +10 -0
- package/plugins/runtime-modules/core/widgets/collection-view/client.js +59 -5
- package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +53 -2
- package/plugins/runtime-modules/core/widgets/collection-view/config.js +47 -0
- package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
- package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +5 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.js +26 -9
- package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
- package/plugins/runtime-modules/descriptor-compiler.js +9 -204
- package/plugins/runtime-modules/resolver.js +31 -5
- package/types/collection-provider.d.ts +7 -0
- package/types/collection-view-widget.d.ts +30 -0
- package/types/core-widget-placements.d.ts +14 -0
- package/types/media.d.ts +16 -0
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo } from "react";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { PhiButtonControl } from "../../../components/controls/phi-button-control";
|
|
5
5
|
import { PhiFlexControl } from "../../../components/controls/phi-flex-control";
|
|
6
6
|
import { PhiMediaAssetTileControl } from "../../../components/controls/phi-media-asset-tile-control";
|
|
7
|
-
import {
|
|
7
|
+
import { PHI_FORM_UPLOAD_LABEL_KEYS } from "../../../components/forms/upload-field-keys";
|
|
8
8
|
import { PhiMediaPickerControl } from "../../../components/controls/phi-media-picker-control";
|
|
9
9
|
import { PhiTypographyControl } from "../../../components/controls/phi-typography-control";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { usePhiMediaPickerBinding, } from "../../../components/media/phi-media-picker-binding";
|
|
11
|
+
import { PhiAreaUploadBinding } from "../../../components/media/phi-area-upload-widget";
|
|
12
|
+
import { readPhiMediaUploadFolderPathReach } from "../../../components/media/media-upload-flow";
|
|
13
|
+
import { resolvePhiMediaFolderPathTemplate } from "../../../components/media/media-folder-name-path";
|
|
14
|
+
import { PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS } from "../../../components/media/media-upload-labels";
|
|
12
15
|
import { usePhiAuthoringAssetDetails } from "../../../components/media/use-authoring-asset-details";
|
|
13
16
|
import { PHI_SEARCH_WIDGET_DEFAULT_LABELS } from "../../../components/widgets/label-types/search";
|
|
14
17
|
import { isPhiMediaAssetPublic } from "../../../constants/media";
|
|
15
18
|
import { PHI_FORM_MEDIA_ASSET_LABEL_KEYS } from "./form-providers";
|
|
16
|
-
import {
|
|
19
|
+
import { readPhiMediaFieldPickerLabels } from "./media-field-picker-labels";
|
|
20
|
+
import { isPhiMediaAssetFieldSelectable, readPhiMediaAssetFieldConfig, readPhiMediaAssetFieldUploadRefusal, readPhiMediaAssetFieldValue, } from "./media-asset-field";
|
|
17
21
|
const DEFAULT_LABELS = {
|
|
18
22
|
choose: "Choose",
|
|
19
23
|
change: "Change",
|
|
20
24
|
remove: "Remove",
|
|
21
|
-
publicOnlyHint: "Only publicly delivered files can be chosen.",
|
|
22
25
|
notPublic: "This file is not delivered publicly.",
|
|
23
26
|
unavailable: "The file could not be read.",
|
|
24
27
|
};
|
|
@@ -31,6 +34,20 @@ const PREVIEW_SIZE = 72;
|
|
|
31
34
|
* value is the Asset id as a number, `null` for none, and the field keeps no copy of it: what it keeps is
|
|
32
35
|
* the picker's open state.
|
|
33
36
|
*
|
|
37
|
+
* Inside the picker a file from the reader's machine can go up too, into the Folder the picker shows,
|
|
38
|
+
* through the Media library's own upload surface (`PhiAreaUploadBinding`, one file, Core's upload
|
|
39
|
+
* session); what it made is chosen as a picked tile would be. It goes into the Site Space, like
|
|
40
|
+
* everything the field offers, and Core delivers what goes there publicly. What comes back is asked what
|
|
41
|
+
* a pick is asked: an Asset of another kind (a file the browser could not name reaches Core unrefused)
|
|
42
|
+
* or, for a `publicOnly` field, one that is not public is left in the list unchosen, and the field says
|
|
43
|
+
* why. While the file is on its way the Form's submit is held, as the upload field holds it, and closing
|
|
44
|
+
* the picker stops it.
|
|
45
|
+
* `config.folderPath` names the Folder the picker opens on ("Shop Images / Products"): read in the Site
|
|
46
|
+
* Space each time it opens, without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader
|
|
47
|
+
* who may only choose opens and picks without a refusal; the picker opens on the deepest Folder of the
|
|
48
|
+
* path that is there. An upload from there goes into the whole path, the missing Folders created the way
|
|
49
|
+
* `area-upload` creates them (`resolvePhiMediaUploadFolderPathId`).
|
|
50
|
+
*
|
|
34
51
|
* Only the Site Space is offered, in every Area (`siteSpaceOnly`): a Form stores a reference everybody
|
|
35
52
|
* who reads the stored value will follow, and a personal or a group Space cannot honestly stand behind
|
|
36
53
|
* that. `config.publicOnly` greys out the Assets that are not delivered publicly, from the delivery
|
|
@@ -41,44 +58,60 @@ const PREVIEW_SIZE = 72;
|
|
|
41
58
|
* field reads (`usePhiAuthoringAssetDetails`), so the preview shows what is stored. Where that read is
|
|
42
59
|
* refused, the field says so and still lets the value be changed or removed.
|
|
43
60
|
*/
|
|
44
|
-
export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readOnly, onChange, }) => {
|
|
61
|
+
export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readOnly, onChange, formContext, }) => {
|
|
45
62
|
const config = useMemo(() => readPhiMediaAssetFieldConfig(field.config), [field.config]);
|
|
46
63
|
const assetId = readPhiMediaAssetFieldValue(value);
|
|
47
64
|
const asset = usePhiAuthoringAssetDetails(assetId);
|
|
48
65
|
const read = (key) => labels?.[PHI_FORM_MEDIA_ASSET_LABEL_KEYS[key]]?.trim() || DEFAULT_LABELS[key];
|
|
49
66
|
const choose = read("choose");
|
|
50
67
|
const change = read("change");
|
|
68
|
+
const notPublic = read("notPublic");
|
|
69
|
+
// The upload's hold is the upload field's sentence, read for this field too; its refusals are in the
|
|
70
|
+
// picker's upload words (`readPhiMediaFieldPickerLabels`).
|
|
71
|
+
const pendingLabel = labels?.[PHI_FORM_UPLOAD_LABEL_KEYS.pending]?.trim() || PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS.pending;
|
|
72
|
+
const [uploadNotice, setUploadNotice] = useState(null);
|
|
73
|
+
const acceptance = useMemo(() => ({ kinds: [config.mediaType], multiple: false }), [config.mediaType]);
|
|
74
|
+
const [uploading, setUploading] = useState(false);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!formContext || !uploading)
|
|
77
|
+
return;
|
|
78
|
+
formContext.holdSubmit(field.key, pendingLabel);
|
|
79
|
+
return () => formContext.holdSubmit(field.key, null);
|
|
80
|
+
}, [field.key, formContext, pendingLabel, uploading]);
|
|
81
|
+
/*
|
|
82
|
+
* The start Folder as the Form's values name it when the picker opens (`{key}` placeholders), kept for
|
|
83
|
+
* the upload into it: the path the picker opened on is the path the file goes to.
|
|
84
|
+
*/
|
|
85
|
+
const startFolderPath = config.folderPath;
|
|
86
|
+
const [openedFolderPath, setOpenedFolderPath] = useState([]);
|
|
87
|
+
const openOnFolder = useCallback(async (signal) => {
|
|
88
|
+
const path = resolvePhiMediaFolderPathTemplate(startFolderPath, formContext?.getValues() ?? {});
|
|
89
|
+
setOpenedFolderPath(path);
|
|
90
|
+
return path.length > 0 ? readPhiMediaUploadFolderPathReach(path, signal) : { folderId: null, complete: true };
|
|
91
|
+
}, [formContext, startFolderPath]);
|
|
51
92
|
// The picker's words come from the Media Label Set, which the Form Widget read for this Form
|
|
52
93
|
// (`resolvePhiFormFieldLabels`); outside a Form that read them, the English defaults stand.
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
...
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
sourceFailedText: readPicker("sourceFailedText", base.picker.sourceFailedText),
|
|
75
|
-
importingLabel: readPicker("importingLabel", base.picker.importingLabel),
|
|
76
|
-
importFailedText: readPicker("importFailedText", base.picker.importFailedText),
|
|
77
|
-
loadMoreLabel: readPicker("loadMoreLabel", base.picker.loadMoreLabel),
|
|
78
|
-
},
|
|
79
|
-
space: { ...base.space, label: readPicker("spaceLabel", base.space.label) },
|
|
80
|
-
};
|
|
81
|
-
}, [assetId, change, choose, labels]);
|
|
94
|
+
const mediaLabels = useMemo(() => readPhiMediaFieldPickerLabels(labels), [labels]);
|
|
95
|
+
const pickerUploadLabels = mediaLabels.upload;
|
|
96
|
+
/*
|
|
97
|
+
* The upload is the Media library's own surface (`PhiAreaUploadBinding`), one file: the drop area and
|
|
98
|
+
* the file on its way, no finished tiles -- what arrived is chosen, or stays in the picker's list
|
|
99
|
+
* greyed out. No Space is named, which Core answers with the Site Space -- the only one the field
|
|
100
|
+
* offers. What comes back is asked what a pick is asked (`readPhiMediaAssetFieldUploadRefusal`).
|
|
101
|
+
*/
|
|
102
|
+
const upload = useMemo(() => ({
|
|
103
|
+
notice: uploadNotice,
|
|
104
|
+
renderPanel: ({ folderId, intoStartFolder, onUploaded }) => (_jsx(PhiAreaUploadBinding, { config: {
|
|
105
|
+
multiple: false,
|
|
106
|
+
allowDelete: false,
|
|
107
|
+
...(intoStartFolder ? { folderPath: openedFolderPath.join(" / ") } : {}),
|
|
108
|
+
}, labels: pickerUploadLabels, acceptance: acceptance, showFinished: false, siteSpaceOnly: true, collectionContext: { folders: [], folderId, presentationFlags: null, query: {} }, onUploadingChange: setUploading, onAssetUploaded: (tile) => {
|
|
109
|
+
const refusal = readPhiMediaAssetFieldUploadRefusal(config, tile);
|
|
110
|
+
setUploadNotice(refusal === "kind" ? pickerUploadLabels.refusals.errorTypeNotAllowed : refusal ? notPublic : null);
|
|
111
|
+
onUploaded(refusal ? null : tile);
|
|
112
|
+
} })),
|
|
113
|
+
}), [acceptance, config, notPublic, openedFolderPath, pickerUploadLabels, uploadNotice]);
|
|
114
|
+
const pickerLabels = useMemo(() => ({ ...mediaLabels, picker: { ...mediaLabels.picker, triggerLabel: assetId == null ? choose : change } }), [assetId, change, choose, mediaLabels]);
|
|
82
115
|
const picker = usePhiMediaPickerBinding({
|
|
83
116
|
config: {
|
|
84
117
|
mediaType: config.mediaType,
|
|
@@ -93,7 +126,9 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
|
|
|
93
126
|
isAssetSelectable: config.publicOnly ? (candidate) => isPhiMediaAssetFieldSelectable(config, candidate) : undefined,
|
|
94
127
|
onAssetSelect: (picked) => onChange?.(picked.id),
|
|
95
128
|
onAssetClear: () => onChange?.(null),
|
|
129
|
+
upload,
|
|
130
|
+
openOnFolder: startFolderPath.length > 0 ? openOnFolder : null,
|
|
96
131
|
});
|
|
97
132
|
const locked = disabled || readOnly;
|
|
98
|
-
return (_jsxs(PhiFlexControl, { vertical: true, gap: "small", children: [assetId == null ? null : (_jsxs(PhiFlexControl, { align: "center", gap: "small", children: [asset ? (_jsx(PhiFlexControl, { style: { width: PREVIEW_SIZE, flex: "none" }, children: _jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: PREVIEW_SIZE, size: "small", showTypeLabel: false, showDimensions: false }) })) : null, _jsx(PhiFlexControl, { vertical: true, children: asset == null ? (_jsxs(_Fragment, { children: [_jsx(PhiTypographyControl, { ellipsis: true, children: `#${assetId}` }), _jsx(PhiTypographyControl, { type: "secondary", children: read("unavailable") })] })) : config.publicOnly && !isPhiMediaAssetPublic(asset.deliveryPolicy, asset.lifecycleStatus) ? (_jsx(PhiTypographyControl, { type: "danger", children: read("notPublic") })) : null })] })), readOnly ? null : (_jsxs(PhiFlexControl, { gap: "small", children: [_jsx(PhiMediaPickerControl, { ...picker, disabled: locked }), assetId == null ? null : (_jsx(PhiButtonControl, { label: read("remove"), disabled: locked, onClick: () => onChange?.(null) }))] }))
|
|
133
|
+
return (_jsxs(PhiFlexControl, { vertical: true, gap: "small", children: [assetId == null ? null : (_jsxs(PhiFlexControl, { align: "center", gap: "small", children: [asset ? (_jsx(PhiFlexControl, { style: { width: PREVIEW_SIZE, flex: "none" }, children: _jsx(PhiMediaAssetTileControl, { asset: asset, minColumnWidth: PREVIEW_SIZE, size: "small", showTypeLabel: false, showDimensions: false }) })) : null, _jsx(PhiFlexControl, { vertical: true, children: asset == null ? (_jsxs(_Fragment, { children: [_jsx(PhiTypographyControl, { ellipsis: true, children: `#${assetId}` }), _jsx(PhiTypographyControl, { type: "secondary", children: read("unavailable") })] })) : config.publicOnly && !isPhiMediaAssetPublic(asset.deliveryPolicy, asset.lifecycleStatus) ? (_jsx(PhiTypographyControl, { type: "danger", children: read("notPublic") })) : null })] })), readOnly ? null : (_jsxs(PhiFlexControl, { gap: "small", children: [_jsx(PhiMediaPickerControl, { ...picker, disabled: locked }), assetId == null ? null : (_jsx(PhiButtonControl, { label: read("remove"), disabled: locked, onClick: () => onChange?.(null) }))] }))] }));
|
|
99
134
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PhiMediaCollectionItem } from "../../../types/media";
|
|
2
|
+
import { type PhiMediaAssetFieldConfig } from "./media-asset-field";
|
|
3
|
+
export type PhiMediaAssetsFieldConfig = Pick<PhiMediaAssetFieldConfig, "mediaType" | "folderPath"> & {
|
|
4
|
+
/**
|
|
5
|
+
* The most Assets the value may hold, from 1 to `PHI_MEDIA_ASSETS_FIELD_MOST` (the default): the field
|
|
6
|
+
* offers no more choosing or uploading once it is full, and a value beyond it holds the Form's submit.
|
|
7
|
+
*/
|
|
8
|
+
max: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The field's config, read strictly as `media-asset`'s is (`readPhiMediaFieldTarget`): a kind the picker
|
|
12
|
+
* does not list, a broken placeholder in `folderPath`, or a `max` that is not a whole number from 1 to
|
|
13
|
+
* `PHI_MEDIA_ASSETS_FIELD_MOST` is a `PhiConfigError` naming the field, never a default in its place.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readPhiMediaAssetsFieldConfig(config: Readonly<Record<string, unknown>> | undefined): PhiMediaAssetsFieldConfig;
|
|
16
|
+
/**
|
|
17
|
+
* The Asset ids a Form value holds, in its order: a list's entries that are Asset ids (positive whole
|
|
18
|
+
* numbers, as `media-asset` reads its one), each once; anything that is not a list holds none.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readPhiMediaAssetsFieldValue(value: unknown): number[];
|
|
21
|
+
/**
|
|
22
|
+
* The value with Assets added at its end: the ones it does not hold yet, while there is room under `max`.
|
|
23
|
+
* Which ones did not fit is said apart, so the field can say why they are missing.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addPhiMediaAssetsFieldIds(ids: readonly number[], added: readonly number[], max: number): {
|
|
26
|
+
ids: number[];
|
|
27
|
+
refused: number[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The tiles for the value, in the value's order and not the answer's: each id as the library answered
|
|
31
|
+
* it, and an id it did not answer (released, or out of the reader's reach) as an unavailable tile --
|
|
32
|
+
* named `unavailableName`, of no kind the tile would load a picture for -- which can still be removed.
|
|
33
|
+
*/
|
|
34
|
+
export declare function orderPhiMediaAssetsFieldTiles(ids: readonly number[], answered: ReadonlyMap<number, PhiMediaCollectionItem>, unavailableName: string): {
|
|
35
|
+
tile: PhiMediaCollectionItem;
|
|
36
|
+
available: boolean;
|
|
37
|
+
}[];
|
|
@@ -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`. */
|
|
@@ -272,7 +272,7 @@ const effectsDescriptors = {
|
|
|
272
272
|
columns: transitionColumns,
|
|
273
273
|
add: {
|
|
274
274
|
enabled: true,
|
|
275
|
-
label: "Add",
|
|
275
|
+
label: label("add", "Add"),
|
|
276
276
|
defaultRow: {
|
|
277
277
|
type: "fade",
|
|
278
278
|
mode: "in",
|
|
@@ -316,10 +316,10 @@ const effectsDescriptors = {
|
|
|
316
316
|
transitionEasing: "ease-out",
|
|
317
317
|
},
|
|
318
318
|
},
|
|
319
|
-
remove: { enabled: true, label: "Remove transition" },
|
|
319
|
+
remove: { enabled: true, label: label("removeTransition", "Remove transition") },
|
|
320
320
|
reorder: true,
|
|
321
321
|
bordered: true,
|
|
322
|
-
emptyText: "No transitions configured.",
|
|
322
|
+
emptyText: label("table.emptyTransitions", "No transitions configured."),
|
|
323
323
|
layout: { mode: "auto", overflowX: "auto" },
|
|
324
324
|
},
|
|
325
325
|
},
|
|
@@ -410,7 +410,7 @@ const effectsDescriptors = {
|
|
|
410
410
|
columns: viewportColumns,
|
|
411
411
|
add: {
|
|
412
412
|
enabled: true,
|
|
413
|
-
label: "Add",
|
|
413
|
+
label: label("add", "Add"),
|
|
414
414
|
defaultRow: {
|
|
415
415
|
property: "translate",
|
|
416
416
|
axis: "y",
|
|
@@ -448,10 +448,10 @@ const effectsDescriptors = {
|
|
|
448
448
|
viewportPerspectivePx: 800,
|
|
449
449
|
},
|
|
450
450
|
},
|
|
451
|
-
remove: { enabled: true, label: "Remove viewport effect" },
|
|
451
|
+
remove: { enabled: true, label: label("removeViewportEffect", "Remove viewport effect") },
|
|
452
452
|
reorder: true,
|
|
453
453
|
bordered: true,
|
|
454
|
-
emptyText: "No viewport effects configured.",
|
|
454
|
+
emptyText: label("table.emptyViewportEffects", "No viewport effects configured."),
|
|
455
455
|
layout: { mode: "auto", overflowX: "auto" },
|
|
456
456
|
},
|
|
457
457
|
},
|