@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
|
@@ -20,8 +20,6 @@ export declare const PHI_FORM_MEDIA_ASSET_LABEL_KEYS: {
|
|
|
20
20
|
readonly choose: "mediaAssetChoose";
|
|
21
21
|
readonly change: "mediaAssetChange";
|
|
22
22
|
readonly remove: "mediaAssetRemove";
|
|
23
|
-
/** Beneath the field when it offers public Assets only (`config.publicOnly`). */
|
|
24
|
-
readonly publicOnlyHint: "mediaAssetPublicOnlyHint";
|
|
25
23
|
/** Beside a chosen Asset that is not public, where the field offers public ones only. */
|
|
26
24
|
readonly notPublic: "mediaAssetNotPublic";
|
|
27
25
|
/** Where the preview would be, when the Asset could not be read. */
|
|
@@ -78,3 +76,88 @@ export declare const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR: {
|
|
|
78
76
|
options?: undefined;
|
|
79
77
|
})[];
|
|
80
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* The most Assets a `media-assets` field holds whatever its config says: the most the Media list answers
|
|
81
|
+
* by id in one read (`GET /api/site/media?id=…`), which is how the field reads its tiles.
|
|
82
|
+
*/
|
|
83
|
+
export declare const PHI_MEDIA_ASSETS_FIELD_MOST = 100;
|
|
84
|
+
/**
|
|
85
|
+
* The `media-assets` field's own wording, read from the Form's Label Set and falling back to English. Its
|
|
86
|
+
* buttons and the picker and upload surface they open say the Media Label Set's words
|
|
87
|
+
* (`PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS`, "Choose from Media library" and the upload toggle among them).
|
|
88
|
+
*/
|
|
89
|
+
export declare const PHI_FORM_MEDIA_ASSETS_LABEL_KEYS: {
|
|
90
|
+
/** A tile's button that takes the Asset out of the value. */
|
|
91
|
+
readonly remove: "mediaAssetsRemove";
|
|
92
|
+
/** The drag handle's name for assistive technology. */
|
|
93
|
+
readonly reorder: "mediaAssetsReorder";
|
|
94
|
+
/** The name on a tile whose Asset the library did not answer. */
|
|
95
|
+
readonly unavailable: "mediaAssetsUnavailable";
|
|
96
|
+
/** Said where the value holds more than `max`, or more were offered than fit; `%1` is `max`. */
|
|
97
|
+
readonly tooMany: "mediaAssetsTooMany";
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `media-assets` field type: several Assets of the Site's Media library, as an ordered list of their
|
|
101
|
+
* ids. The Asset Module owns it as it owns `media-asset`. `json`, as the `upload` field's list of Asset
|
|
102
|
+
* ids is: the Form contract's value types have no list of numbers.
|
|
103
|
+
*/
|
|
104
|
+
export declare const PHI_ASSET_MEDIA_ASSETS_FORM_PROVIDER_DESCRIPTOR: {
|
|
105
|
+
key: `${string}/${string}`;
|
|
106
|
+
ownerModuleId: "@phis/ui/modules/asset";
|
|
107
|
+
title: string;
|
|
108
|
+
description: string;
|
|
109
|
+
valueType: "json";
|
|
110
|
+
presentation: "control";
|
|
111
|
+
settingsFields: ({
|
|
112
|
+
key: string;
|
|
113
|
+
type: "choice";
|
|
114
|
+
mode: "single";
|
|
115
|
+
valueType: "string";
|
|
116
|
+
label: string;
|
|
117
|
+
description: string;
|
|
118
|
+
options: ({
|
|
119
|
+
value: "image";
|
|
120
|
+
label: string;
|
|
121
|
+
} | {
|
|
122
|
+
value: "video";
|
|
123
|
+
label: string;
|
|
124
|
+
} | {
|
|
125
|
+
value: "audio";
|
|
126
|
+
label: string;
|
|
127
|
+
} | {
|
|
128
|
+
value: "pdf";
|
|
129
|
+
label: string;
|
|
130
|
+
} | {
|
|
131
|
+
value: "markdown";
|
|
132
|
+
label: string;
|
|
133
|
+
} | {
|
|
134
|
+
value: "font";
|
|
135
|
+
label: string;
|
|
136
|
+
})[];
|
|
137
|
+
min?: undefined;
|
|
138
|
+
max?: undefined;
|
|
139
|
+
precision?: undefined;
|
|
140
|
+
} | {
|
|
141
|
+
key: string;
|
|
142
|
+
type: "string";
|
|
143
|
+
label: string;
|
|
144
|
+
description: string;
|
|
145
|
+
mode?: undefined;
|
|
146
|
+
valueType?: undefined;
|
|
147
|
+
options?: undefined;
|
|
148
|
+
min?: undefined;
|
|
149
|
+
max?: undefined;
|
|
150
|
+
precision?: undefined;
|
|
151
|
+
} | {
|
|
152
|
+
key: string;
|
|
153
|
+
type: "number";
|
|
154
|
+
label: string;
|
|
155
|
+
description: string;
|
|
156
|
+
min: number;
|
|
157
|
+
max: number;
|
|
158
|
+
precision: number;
|
|
159
|
+
mode?: undefined;
|
|
160
|
+
valueType?: undefined;
|
|
161
|
+
options?: undefined;
|
|
162
|
+
})[];
|
|
163
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PHI_ASSET_RUNTIME_MODULE_ID } from "./ids";
|
|
2
2
|
import { PhiMediaKind } from "../../../constants/media";
|
|
3
|
-
import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY } from "../../../constants/media-library-provider-keys";
|
|
3
|
+
import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY, PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY, } from "../../../constants/media-library-provider-keys";
|
|
4
4
|
import { createPhiSharedFormProviderKey } from "../../../components/forms/form-provider-contract";
|
|
5
5
|
export const PHI_ASSET_FOCAL_RECT_FORM_PROVIDER_KEY = createPhiSharedFormProviderKey("field", "asset-focal-rect");
|
|
6
6
|
export const PHI_ASSET_FOCAL_RECT_FORM_PROVIDER_DESCRIPTOR = {
|
|
@@ -24,13 +24,20 @@ export const PHI_FORM_MEDIA_ASSET_LABEL_KEYS = {
|
|
|
24
24
|
choose: "mediaAssetChoose",
|
|
25
25
|
change: "mediaAssetChange",
|
|
26
26
|
remove: "mediaAssetRemove",
|
|
27
|
-
/** Beneath the field when it offers public Assets only (`config.publicOnly`). */
|
|
28
|
-
publicOnlyHint: "mediaAssetPublicOnlyHint",
|
|
29
27
|
/** Beside a chosen Asset that is not public, where the field offers public ones only. */
|
|
30
28
|
notPublic: "mediaAssetNotPublic",
|
|
31
29
|
/** Where the preview would be, when the Asset could not be read. */
|
|
32
30
|
unavailable: "mediaAssetUnavailable",
|
|
33
31
|
};
|
|
32
|
+
// The kinds a Media field's picker lists, offered alike by `media-asset` and `media-assets`.
|
|
33
|
+
const MEDIA_FIELD_KIND_OPTIONS = [
|
|
34
|
+
{ value: PhiMediaKind.Image, label: "Image" },
|
|
35
|
+
{ value: PhiMediaKind.Video, label: "Video" },
|
|
36
|
+
{ value: PhiMediaKind.Audio, label: "Audio" },
|
|
37
|
+
{ value: PhiMediaKind.Pdf, label: "PDF" },
|
|
38
|
+
{ value: PhiMediaKind.Markdown, label: "Markdown" },
|
|
39
|
+
{ value: PhiMediaKind.Font, label: "Font" },
|
|
40
|
+
];
|
|
34
41
|
export const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR = {
|
|
35
42
|
key: PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY,
|
|
36
43
|
ownerModuleId: PHI_ASSET_RUNTIME_MODULE_ID,
|
|
@@ -46,14 +53,7 @@ export const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR = {
|
|
|
46
53
|
valueType: "string",
|
|
47
54
|
label: "Kind",
|
|
48
55
|
description: "Image when nothing is named.",
|
|
49
|
-
options:
|
|
50
|
-
{ value: PhiMediaKind.Image, label: "Image" },
|
|
51
|
-
{ value: PhiMediaKind.Video, label: "Video" },
|
|
52
|
-
{ value: PhiMediaKind.Audio, label: "Audio" },
|
|
53
|
-
{ value: PhiMediaKind.Pdf, label: "PDF" },
|
|
54
|
-
{ value: PhiMediaKind.Markdown, label: "Markdown" },
|
|
55
|
-
{ value: PhiMediaKind.Font, label: "Font" },
|
|
56
|
-
],
|
|
56
|
+
options: MEDIA_FIELD_KIND_OPTIONS,
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
key: "publicOnly",
|
|
@@ -69,3 +69,62 @@ export const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR = {
|
|
|
69
69
|
},
|
|
70
70
|
],
|
|
71
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* The most Assets a `media-assets` field holds whatever its config says: the most the Media list answers
|
|
74
|
+
* by id in one read (`GET /api/site/media?id=…`), which is how the field reads its tiles.
|
|
75
|
+
*/
|
|
76
|
+
export const PHI_MEDIA_ASSETS_FIELD_MOST = 100;
|
|
77
|
+
/**
|
|
78
|
+
* The `media-assets` field's own wording, read from the Form's Label Set and falling back to English. Its
|
|
79
|
+
* buttons and the picker and upload surface they open say the Media Label Set's words
|
|
80
|
+
* (`PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS`, "Choose from Media library" and the upload toggle among them).
|
|
81
|
+
*/
|
|
82
|
+
export const PHI_FORM_MEDIA_ASSETS_LABEL_KEYS = {
|
|
83
|
+
/** A tile's button that takes the Asset out of the value. */
|
|
84
|
+
remove: "mediaAssetsRemove",
|
|
85
|
+
/** The drag handle's name for assistive technology. */
|
|
86
|
+
reorder: "mediaAssetsReorder",
|
|
87
|
+
/** The name on a tile whose Asset the library did not answer. */
|
|
88
|
+
unavailable: "mediaAssetsUnavailable",
|
|
89
|
+
/** Said where the value holds more than `max`, or more were offered than fit; `%1` is `max`. */
|
|
90
|
+
tooMany: "mediaAssetsTooMany",
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The `media-assets` field type: several Assets of the Site's Media library, as an ordered list of their
|
|
94
|
+
* ids. The Asset Module owns it as it owns `media-asset`. `json`, as the `upload` field's list of Asset
|
|
95
|
+
* ids is: the Form contract's value types have no list of numbers.
|
|
96
|
+
*/
|
|
97
|
+
export const PHI_ASSET_MEDIA_ASSETS_FORM_PROVIDER_DESCRIPTOR = {
|
|
98
|
+
key: PHI_MEDIA_ASSETS_FORM_FIELD_PROVIDER_KEY,
|
|
99
|
+
ownerModuleId: PHI_ASSET_RUNTIME_MODULE_ID,
|
|
100
|
+
title: "Media assets",
|
|
101
|
+
description: "Several Assets of the Site's Media library, as their ids in order.",
|
|
102
|
+
valueType: "json",
|
|
103
|
+
presentation: "control",
|
|
104
|
+
settingsFields: [
|
|
105
|
+
{
|
|
106
|
+
key: "mediaType",
|
|
107
|
+
type: "choice",
|
|
108
|
+
mode: "single",
|
|
109
|
+
valueType: "string",
|
|
110
|
+
label: "Kind",
|
|
111
|
+
description: "Image when nothing is named.",
|
|
112
|
+
options: MEDIA_FIELD_KIND_OPTIONS,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
key: "folderPath",
|
|
116
|
+
type: "string",
|
|
117
|
+
label: "Folder path",
|
|
118
|
+
description: "The Site Folder the picker opens on and uploads go into, by its path (\"Shop Images / Products\"); missing Folders are created on the first upload. {key} puts in a value of the Form; a name whose value is empty is left out. Empty: the root.",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
key: "max",
|
|
122
|
+
type: "number",
|
|
123
|
+
label: "Most Assets",
|
|
124
|
+
description: `The most Assets the field holds, from 1 to ${PHI_MEDIA_ASSETS_FIELD_MOST} (the default).`,
|
|
125
|
+
min: 1,
|
|
126
|
+
max: PHI_MEDIA_ASSETS_FIELD_MOST,
|
|
127
|
+
precision: 0,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
};
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { lazyPhiFormFieldControl } from "../../../components/forms/lazy-form-field-control";
|
|
4
4
|
import { createPhiFormProviderRegistry, PhiFormProviderRegistryProvider } from "../../../components/forms/form-provider-registry";
|
|
5
|
-
import { PHI_ASSET_FOCAL_RECT_FORM_PROVIDER_DESCRIPTOR, PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR, } from "./form-providers";
|
|
5
|
+
import { PHI_ASSET_FOCAL_RECT_FORM_PROVIDER_DESCRIPTOR, PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR, PHI_ASSET_MEDIA_ASSETS_FORM_PROVIDER_DESCRIPTOR, } from "./form-providers";
|
|
6
6
|
// Loaded when a `media-asset` field first renders: the picker and the Media library binding stay out of
|
|
7
7
|
// every other Form.
|
|
8
8
|
const PhiLazyMediaAssetFormControl = lazyPhiFormFieldControl(() => import("./media-asset-form-control").then((module) => module.PhiMediaAssetFormControl));
|
|
9
|
+
// Loaded when a `media-assets` field first renders, on the same terms.
|
|
10
|
+
const PhiLazyMediaAssetsFormControl = lazyPhiFormFieldControl(() => import("./media-assets-form-control").then((module) => module.PhiMediaAssetsFormControl));
|
|
9
11
|
const PHI_ASSET_FORM_PROVIDER_REGISTRY = createPhiFormProviderRegistry({
|
|
10
12
|
fieldTypes: [
|
|
11
13
|
{
|
|
@@ -16,6 +18,10 @@ const PHI_ASSET_FORM_PROVIDER_REGISTRY = createPhiFormProviderRegistry({
|
|
|
16
18
|
...PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR,
|
|
17
19
|
Control: PhiLazyMediaAssetFormControl,
|
|
18
20
|
},
|
|
21
|
+
{
|
|
22
|
+
...PHI_ASSET_MEDIA_ASSETS_FORM_PROVIDER_DESCRIPTOR,
|
|
23
|
+
Control: PhiLazyMediaAssetsFormControl,
|
|
24
|
+
},
|
|
19
25
|
],
|
|
20
26
|
});
|
|
21
27
|
export function PhiAssetFormUiProvider({ children }) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PhiMediaAssetTile, PhiMediaKindValue } from "../../../types/media";
|
|
2
|
+
import { type PhiConfigReader } from "../../../components/widgets/config/strict-config-reader";
|
|
2
3
|
export type PhiMediaAssetFieldConfig = {
|
|
3
4
|
/** Which kind of Asset the picker lists. */
|
|
4
5
|
mediaType: PhiMediaKindValue;
|
|
@@ -14,8 +15,8 @@ export type PhiMediaAssetFieldConfig = {
|
|
|
14
15
|
* root. A path and not an id, so a Module's Form states it for every Site.
|
|
15
16
|
*
|
|
16
17
|
* A name may hold placeholders, `{key}`, read from the Form's values when the picker opens
|
|
17
|
-
* (`
|
|
18
|
-
* as written, placeholders unresolved.
|
|
18
|
+
* (`resolvePhiMediaFolderPathTemplate`, `components/media/media-folder-name-path.ts`): "Shop Images /
|
|
19
|
+
* {category} / {product}". These are the names as written, placeholders unresolved.
|
|
19
20
|
*/
|
|
20
21
|
folderPath: readonly string[];
|
|
21
22
|
};
|
|
@@ -28,12 +29,11 @@ export type PhiMediaAssetFieldConfig = {
|
|
|
28
29
|
*/
|
|
29
30
|
export declare function readPhiMediaAssetFieldConfig(config: Readonly<Record<string, unknown>> | undefined): PhiMediaAssetFieldConfig;
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* category is "Shop Images / <product>" -- and a name that comes out empty is left out too.
|
|
32
|
+
* What the `media-asset` and the `media-assets` field read alike: the kind the picker lists and the
|
|
33
|
+
* upload takes (images where none is named), and the Folder path it opens on and uploads into, with its
|
|
34
|
+
* placeholders unresolved -- by the same strict rules, so the two fields cannot read one setting two ways.
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
36
|
+
export declare function readPhiMediaFieldTarget(reader: PhiConfigReader): Pick<PhiMediaAssetFieldConfig, "mediaType" | "folderPath">;
|
|
37
37
|
/**
|
|
38
38
|
* The Asset id a Form value holds, or `null`. A value that is not a positive whole number is not an id,
|
|
39
39
|
* and showing it as one would put a request for Asset `NaN` on the wire.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PhiMediaKind, isPhiMediaAssetPublic } from "../../../constants/media";
|
|
2
|
-
import { createPhiConfigReader } from "../../../components/widgets/config/strict-config-reader";
|
|
3
|
-
import { splitPhiMediaFolderNamePath } from "../../../components/media/media-folder-name-path";
|
|
4
|
-
import { readPhiDotPath } from "../../../helpers/dot-path";
|
|
2
|
+
import { createPhiConfigReader, } from "../../../components/widgets/config/strict-config-reader";
|
|
3
|
+
import { isPhiMediaFolderPathTemplate, splitPhiMediaFolderNamePath, } from "../../../components/media/media-folder-name-path";
|
|
5
4
|
const MEDIA_ASSET_FIELD_KINDS = [
|
|
6
5
|
PhiMediaKind.Image,
|
|
7
6
|
PhiMediaKind.Video,
|
|
@@ -20,41 +19,20 @@ const MEDIA_ASSET_FIELD_KINDS = [
|
|
|
20
19
|
export function readPhiMediaAssetFieldConfig(config) {
|
|
21
20
|
const reader = createPhiConfigReader(config ?? {}, "config");
|
|
22
21
|
return {
|
|
23
|
-
|
|
22
|
+
...readPhiMediaFieldTarget(reader),
|
|
24
23
|
publicOnly: reader.boolean("publicOnly") ?? false,
|
|
25
|
-
folderPath: splitPhiMediaFolderNamePath(reader.value("folderPath", "a Folder path whose placeholders read {key}", (value) => typeof value === "string" && isPhiMediaAssetFolderPathTemplate(value) ? value : undefined)),
|
|
26
24
|
};
|
|
27
25
|
}
|
|
28
|
-
/* `{key}`: a Form value's key, a dotted path into it for a value that is a record. */
|
|
29
|
-
const PHI_MEDIA_ASSET_FOLDER_PATH_PLACEHOLDER = /\{([A-Za-z0-9_.-]+)\}/gu;
|
|
30
|
-
function isPhiMediaAssetFolderPathTemplate(value) {
|
|
31
|
-
return !/[{}]/u.test(value.replace(PHI_MEDIA_ASSET_FOLDER_PATH_PLACEHOLDER, ""));
|
|
32
|
-
}
|
|
33
|
-
/*
|
|
34
|
-
* A Form value as a Folder name: a text or a number, trimmed, and a `/` in it a `-`, so a value can name
|
|
35
|
-
* a Folder but never add a level of them. Anything else -- empty, absent, a list, a record -- is no name.
|
|
36
|
-
*/
|
|
37
|
-
function readPhiMediaAssetFolderPathValue(value) {
|
|
38
|
-
const text = typeof value === "string" ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : "";
|
|
39
|
-
return text.replace(/\//gu, "-").replace(/\s+/gu, " ").trim();
|
|
40
|
-
}
|
|
41
26
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* category is "Shop Images / <product>" -- and a name that comes out empty is left out too.
|
|
27
|
+
* What the `media-asset` and the `media-assets` field read alike: the kind the picker lists and the
|
|
28
|
+
* upload takes (images where none is named), and the Folder path it opens on and uploads into, with its
|
|
29
|
+
* placeholders unresolved -- by the same strict rules, so the two fields cannot read one setting two ways.
|
|
46
30
|
*/
|
|
47
|
-
export function
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!value)
|
|
53
|
-
missing = true;
|
|
54
|
-
return value;
|
|
55
|
-
}).replace(/\s+/gu, " ").trim();
|
|
56
|
-
return missing || !resolved ? [] : [resolved];
|
|
57
|
-
});
|
|
31
|
+
export function readPhiMediaFieldTarget(reader) {
|
|
32
|
+
return {
|
|
33
|
+
mediaType: reader.oneOf("mediaType", MEDIA_ASSET_FIELD_KINDS) ?? PhiMediaKind.Image,
|
|
34
|
+
folderPath: splitPhiMediaFolderNamePath(reader.value("folderPath", "a Folder path whose placeholders read {key}", (value) => typeof value === "string" && isPhiMediaFolderPathTemplate(value) ? value : undefined)),
|
|
35
|
+
};
|
|
58
36
|
}
|
|
59
37
|
/**
|
|
60
38
|
* The Asset id a Form value holds, or `null`. A value that is not a positive whole number is not an id,
|
|
@@ -8,13 +8,14 @@ import type { PhiFormFieldProviderProps } from "../../../components/forms/form-p
|
|
|
8
8
|
* value is the Asset id as a number, `null` for none, and the field keeps no copy of it: what it keeps is
|
|
9
9
|
* the picker's open state.
|
|
10
10
|
*
|
|
11
|
-
* Inside the picker a file from the reader's machine can go up too, into the Folder the picker shows,
|
|
12
|
-
* the
|
|
13
|
-
* chosen as a picked tile would be. It goes into the Site Space, like
|
|
14
|
-
* Core delivers what goes there publicly. What comes back is asked what
|
|
15
|
-
* another kind (a file the browser could not name reaches Core unrefused)
|
|
16
|
-
* one that is not public is left in the list unchosen, and the field says
|
|
17
|
-
* way the Form's submit is held, as the upload field holds it, and closing
|
|
11
|
+
* Inside the picker a file from the reader's machine can go up too, into the Folder the picker shows,
|
|
12
|
+
* through the Media library's own upload surface (`PhiAreaUploadBinding`, one file, Core's upload
|
|
13
|
+
* session); what it made is chosen as a picked tile would be. It goes into the Site Space, like
|
|
14
|
+
* everything the field offers, and Core delivers what goes there publicly. What comes back is asked what
|
|
15
|
+
* a pick is asked: an Asset of another kind (a file the browser could not name reaches Core unrefused)
|
|
16
|
+
* or, for a `publicOnly` field, one that is not public is left in the list unchosen, and the field says
|
|
17
|
+
* why. While the file is on its way the Form's submit is held, as the upload field holds it, and closing
|
|
18
|
+
* the picker stops it.
|
|
18
19
|
* `config.folderPath` names the Folder the picker opens on ("Shop Images / Products"): read in the Site
|
|
19
20
|
* Space each time it opens, without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader
|
|
20
21
|
* who may only choose opens and picks without a refusal; the picker opens on the deepest Folder of the
|
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useMemo,
|
|
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 { PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS } from "../../../components/forms/media-asset-field-keys";
|
|
8
7
|
import { PHI_FORM_UPLOAD_LABEL_KEYS } from "../../../components/forms/upload-field-keys";
|
|
9
|
-
import { readPhiFormUploadRefusalLabels } from "../../../components/forms/upload-field-refusal-labels";
|
|
10
8
|
import { PhiMediaPickerControl } from "../../../components/controls/phi-media-picker-control";
|
|
11
9
|
import { PhiTypographyControl } from "../../../components/controls/phi-typography-control";
|
|
12
|
-
import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../components/media/media-widget-labels";
|
|
13
10
|
import { usePhiMediaPickerBinding, } from "../../../components/media/phi-media-picker-binding";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
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";
|
|
17
14
|
import { PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS } from "../../../components/media/media-upload-labels";
|
|
18
15
|
import { usePhiAuthoringAssetDetails } from "../../../components/media/use-authoring-asset-details";
|
|
19
16
|
import { PHI_SEARCH_WIDGET_DEFAULT_LABELS } from "../../../components/widgets/label-types/search";
|
|
20
17
|
import { isPhiMediaAssetPublic } from "../../../constants/media";
|
|
21
18
|
import { PHI_FORM_MEDIA_ASSET_LABEL_KEYS } from "./form-providers";
|
|
22
|
-
import {
|
|
19
|
+
import { readPhiMediaFieldPickerLabels } from "./media-field-picker-labels";
|
|
20
|
+
import { isPhiMediaAssetFieldSelectable, readPhiMediaAssetFieldConfig, readPhiMediaAssetFieldUploadRefusal, readPhiMediaAssetFieldValue, } from "./media-asset-field";
|
|
23
21
|
const DEFAULT_LABELS = {
|
|
24
22
|
choose: "Choose",
|
|
25
23
|
change: "Change",
|
|
26
24
|
remove: "Remove",
|
|
27
|
-
publicOnlyHint: "Only publicly delivered files can be chosen.",
|
|
28
25
|
notPublic: "This file is not delivered publicly.",
|
|
29
26
|
unavailable: "The file could not be read.",
|
|
30
27
|
};
|
|
@@ -37,13 +34,14 @@ const PREVIEW_SIZE = 72;
|
|
|
37
34
|
* value is the Asset id as a number, `null` for none, and the field keeps no copy of it: what it keeps is
|
|
38
35
|
* the picker's open state.
|
|
39
36
|
*
|
|
40
|
-
* Inside the picker a file from the reader's machine can go up too, into the Folder the picker shows,
|
|
41
|
-
* the
|
|
42
|
-
* chosen as a picked tile would be. It goes into the Site Space, like
|
|
43
|
-
* Core delivers what goes there publicly. What comes back is asked what
|
|
44
|
-
* another kind (a file the browser could not name reaches Core unrefused)
|
|
45
|
-
* one that is not public is left in the list unchosen, and the field says
|
|
46
|
-
* way the Form's submit is held, as the upload field holds it, and closing
|
|
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.
|
|
47
45
|
* `config.folderPath` names the Folder the picker opens on ("Shop Images / Products"): read in the Site
|
|
48
46
|
* Space each time it opens, without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader
|
|
49
47
|
* who may only choose opens and picks without a refusal; the picker opens on the deepest Folder of the
|
|
@@ -68,18 +66,12 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
|
|
|
68
66
|
const choose = read("choose");
|
|
69
67
|
const change = read("change");
|
|
70
68
|
const notPublic = read("notPublic");
|
|
71
|
-
// The upload's
|
|
72
|
-
|
|
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`).
|
|
73
71
|
const pendingLabel = labels?.[PHI_FORM_UPLOAD_LABEL_KEYS.pending]?.trim() || PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS.pending;
|
|
74
72
|
const [uploadNotice, setUploadNotice] = useState(null);
|
|
75
73
|
const acceptance = useMemo(() => ({ kinds: [config.mediaType], multiple: false }), [config.mediaType]);
|
|
76
|
-
const
|
|
77
|
-
labels: refusals,
|
|
78
|
-
acceptance,
|
|
79
|
-
onRejected: (message) => setUploadNotice(message),
|
|
80
|
-
});
|
|
81
|
-
const { upload: sendFile, cancel: cancelUpload, uploading } = transfer;
|
|
82
|
-
const uploadProgress = transfer.items.find((item) => item.status === "uploading")?.progress ?? null;
|
|
74
|
+
const [uploading, setUploading] = useState(false);
|
|
83
75
|
useEffect(() => {
|
|
84
76
|
if (!formContext || !uploading)
|
|
85
77
|
return;
|
|
@@ -91,68 +83,35 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
|
|
|
91
83
|
* the upload into it: the path the picker opened on is the path the file goes to.
|
|
92
84
|
*/
|
|
93
85
|
const startFolderPath = config.folderPath;
|
|
94
|
-
const
|
|
86
|
+
const [openedFolderPath, setOpenedFolderPath] = useState([]);
|
|
95
87
|
const openOnFolder = useCallback(async (signal) => {
|
|
96
|
-
const path =
|
|
97
|
-
|
|
88
|
+
const path = resolvePhiMediaFolderPathTemplate(startFolderPath, formContext?.getValues() ?? {});
|
|
89
|
+
setOpenedFolderPath(path);
|
|
98
90
|
return path.length > 0 ? readPhiMediaUploadFolderPathReach(path, signal) : { folderId: null, complete: true };
|
|
99
91
|
}, [formContext, startFolderPath]);
|
|
100
|
-
const upload = useMemo(() => ({
|
|
101
|
-
accept: transfer.accept,
|
|
102
|
-
progress: uploadProgress,
|
|
103
|
-
notice: uploadNotice,
|
|
104
|
-
send: async (file, folderId, intoStartFolder) => {
|
|
105
|
-
setUploadNotice(null);
|
|
106
|
-
// No Space is named, which Core answers with the Site Space -- the only one the field offers.
|
|
107
|
-
const asset = await sendFile(file, intoStartFolder ? { folderPath: startFolderPathRef.current } : { folderId });
|
|
108
|
-
if (!asset)
|
|
109
|
-
return null;
|
|
110
|
-
const tile = normalizePhiImagePreviewTile(asset, []);
|
|
111
|
-
const refusal = readPhiMediaAssetFieldUploadRefusal(config, tile);
|
|
112
|
-
if (refusal) {
|
|
113
|
-
setUploadNotice(refusal === "kind" ? refusals.errorTypeNotAllowed : notPublic);
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
return tile;
|
|
117
|
-
},
|
|
118
|
-
cancel: cancelUpload,
|
|
119
|
-
}), [cancelUpload, config, notPublic, refusals, sendFile, transfer.accept, uploadNotice, uploadProgress]);
|
|
120
92
|
// The picker's words come from the Media Label Set, which the Form Widget read for this Form
|
|
121
93
|
// (`resolvePhiFormFieldLabels`); outside a Form that read them, the English defaults stand.
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
...
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
sourceFailedText: readPicker("sourceFailedText", base.picker.sourceFailedText),
|
|
144
|
-
importingLabel: readPicker("importingLabel", base.picker.importingLabel),
|
|
145
|
-
importFailedText: readPicker("importFailedText", base.picker.importFailedText),
|
|
146
|
-
loadMoreLabel: readPicker("loadMoreLabel", base.picker.loadMoreLabel),
|
|
147
|
-
},
|
|
148
|
-
upload: {
|
|
149
|
-
...base.upload,
|
|
150
|
-
uploadToggleLabel: readPicker("uploadLabel", base.upload.uploadToggleLabel),
|
|
151
|
-
refusals,
|
|
152
|
-
},
|
|
153
|
-
space: { ...base.space, label: readPicker("spaceLabel", base.space.label) },
|
|
154
|
-
};
|
|
155
|
-
}, [assetId, change, choose, labels, refusals]);
|
|
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]);
|
|
156
115
|
const picker = usePhiMediaPickerBinding({
|
|
157
116
|
config: {
|
|
158
117
|
mediaType: config.mediaType,
|
|
@@ -171,5 +130,5 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
|
|
|
171
130
|
openOnFolder: startFolderPath.length > 0 ? openOnFolder : null,
|
|
172
131
|
});
|
|
173
132
|
const locked = disabled || readOnly;
|
|
174
|
-
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) }))] }))] }));
|
|
175
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
|
+
}[];
|