@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.
Files changed (100) hide show
  1. package/components/controls/phi-collection-reorder-context.d.ts +21 -0
  2. package/components/controls/phi-collection-reorder-context.js +6 -0
  3. package/components/controls/phi-collection-sortable-layout-control.d.ts +17 -0
  4. package/components/controls/phi-collection-sortable-layout-control.js +72 -0
  5. package/components/controls/phi-collection-view-control.d.ts +1 -1
  6. package/components/controls/phi-collection-view-control.js +15 -1
  7. package/components/controls/phi-media-asset-tile-control.d.ts +14 -6
  8. package/components/controls/phi-media-picker-control.d.ts +13 -2
  9. package/components/controls/phi-media-picker-control.js +9 -2
  10. package/components/forms/compound-form-controls.d.ts +1 -1
  11. package/components/forms/compound-form-controls.js +6 -4
  12. package/components/forms/form-field-labels.d.ts +4 -2
  13. package/components/forms/form-field-labels.js +30 -9
  14. package/components/forms/form-provider-contract.js +2 -1
  15. package/components/forms/media-asset-field-keys.d.ts +13 -2
  16. package/components/forms/media-asset-field-keys.js +17 -2
  17. package/components/forms/table-field-keys.d.ts +8 -0
  18. package/components/forms/table-field-keys.js +8 -0
  19. package/components/forms/table-field-labels.d.ts +16 -0
  20. package/components/forms/table-field-labels.js +16 -0
  21. package/components/forms/table-field-text.d.ts +9 -0
  22. package/components/forms/table-field-text.js +20 -0
  23. package/components/forms/upload-field-refusal-labels.d.ts +10 -0
  24. package/components/forms/upload-field-refusal-labels.js +24 -0
  25. package/components/forms/upload-form-control.js +3 -16
  26. package/components/media/label-sets/media.js +4 -0
  27. package/components/media/media-folder-name-path.d.ts +14 -0
  28. package/components/media/media-folder-name-path.js +40 -2
  29. package/components/media/media-library-resource.d.ts +70 -0
  30. package/components/media/media-library-resource.js +41 -0
  31. package/components/media/media-upload-flow.d.ts +13 -1
  32. package/components/media/media-upload-flow.js +16 -0
  33. package/components/media/media-widget-labels.d.ts +13 -0
  34. package/components/media/media-widget-labels.js +2 -0
  35. package/components/media/phi-area-upload-widget.d.ts +31 -1
  36. package/components/media/phi-area-upload-widget.js +33 -7
  37. package/components/media/phi-image-preview-data.d.ts +8 -1
  38. package/components/media/phi-image-preview-data.js +29 -0
  39. package/components/media/phi-media-picker-binding.d.ts +50 -1
  40. package/components/media/phi-media-picker-binding.js +86 -6
  41. package/components/media/phi-media-upload.d.ts +7 -1
  42. package/components/media/phi-media-upload.js +17 -5
  43. package/components/media/use-media-library-add-picker.d.ts +94 -0
  44. package/components/media/use-media-library-add-picker.js +40 -0
  45. package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
  46. package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
  47. package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
  48. package/components/widgets/label-sets/collection-view.d.ts +4 -0
  49. package/components/widgets/label-sets/collection-view.js +16 -0
  50. package/components/widgets/label-sets/table.d.ts +6 -0
  51. package/components/widgets/label-sets/table.js +10 -0
  52. package/components/widgets/label-types/collection-view.d.ts +8 -0
  53. package/components/widgets/label-types/collection-view.js +4 -0
  54. package/constants/media-library-provider-keys.d.ts +7 -0
  55. package/constants/media-library-provider-keys.js +7 -0
  56. package/constants/runtime-module-ownership.js +1 -0
  57. package/controls.d.ts +1 -1
  58. package/helpers/preset-tree-contract-check.d.ts +35 -0
  59. package/helpers/preset-tree-contract-check.js +211 -0
  60. package/module-page-check.d.ts +6 -0
  61. package/module-page-check.js +6 -0
  62. package/package.json +1 -1
  63. package/plugins/runtime-modules/asset/data-providers.d.ts +56 -38
  64. package/plugins/runtime-modules/asset/data-providers.js +4 -32
  65. package/plugins/runtime-modules/asset/definition.d.ts +123 -38
  66. package/plugins/runtime-modules/asset/definition.js +2 -1
  67. package/plugins/runtime-modules/asset/form-providers.d.ts +93 -2
  68. package/plugins/runtime-modules/asset/form-providers.js +76 -11
  69. package/plugins/runtime-modules/asset/form-ui-provider.js +7 -1
  70. package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
  71. package/plugins/runtime-modules/asset/media-asset-field.js +30 -5
  72. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +14 -0
  73. package/plugins/runtime-modules/asset/media-asset-form-control.js +72 -37
  74. package/plugins/runtime-modules/asset/media-assets-field.d.ts +37 -0
  75. package/plugins/runtime-modules/asset/media-assets-field.js +81 -0
  76. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +27 -0
  77. package/plugins/runtime-modules/asset/media-assets-form-control.js +182 -0
  78. package/plugins/runtime-modules/asset/media-field-picker-labels.d.ts +9 -0
  79. package/plugins/runtime-modules/asset/media-field-picker-labels.js +49 -0
  80. package/plugins/runtime-modules/asset/services/collection.js +12 -0
  81. package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
  82. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.d.ts +24 -0
  83. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding-tools.js +55 -0
  84. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +26 -2
  85. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +125 -32
  86. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +10 -0
  87. package/plugins/runtime-modules/core/widgets/collection-view/client.js +59 -5
  88. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +53 -2
  89. package/plugins/runtime-modules/core/widgets/collection-view/config.js +47 -0
  90. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +4 -1
  91. package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
  92. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +5 -1
  93. package/plugins/runtime-modules/core/widgets/collection-view/server.js +26 -9
  94. package/plugins/runtime-modules/descriptor-compiler.d.ts +4 -0
  95. package/plugins/runtime-modules/descriptor-compiler.js +9 -204
  96. package/plugins/runtime-modules/resolver.js +31 -5
  97. package/types/collection-provider.d.ts +7 -0
  98. package/types/collection-view-widget.d.ts +30 -0
  99. package/types/core-widget-placements.d.ts +14 -0
  100. package/types/media.d.ts +16 -0
@@ -0,0 +1,20 @@
1
+ import { isPhiRecord } from "../../helpers/is-record";
2
+ import { resolvePhiFormText } from "@phis/contracts/forms";
3
+ import { PHI_FORM_TABLE_DEFAULT_LABELS, PHI_FORM_TABLE_LABEL_KEYS } from "./table-field-labels";
4
+ /**
5
+ * One of the table field's words: the text its `config` names -- a label reference (`{ kind: "label",
6
+ * key, fallback }`) read from the Form's labels, or a literal (`{ kind: "literal", value }`), as a field's
7
+ * own label is written -- or else the Form's word under `PHI_FORM_TABLE_LABEL_KEYS`, which the Form Widget
8
+ * fills from Core's `widget:table` set, or else the English source. A plain string is not a text: it would
9
+ * be English in every language.
10
+ */
11
+ export function readPhiFormTableFieldText(value, labels, key) {
12
+ if (isPhiRecord(value)) {
13
+ if (value.kind === "label" && typeof value.key === "string" && typeof value.fallback === "string") {
14
+ return resolvePhiFormText({ kind: "label", key: value.key, fallback: value.fallback }, labels);
15
+ }
16
+ if (value.kind === "literal" && typeof value.value === "string")
17
+ return value.value;
18
+ }
19
+ return labels?.[PHI_FORM_TABLE_LABEL_KEYS[key]]?.trim() || PHI_FORM_TABLE_DEFAULT_LABELS[key];
20
+ }
@@ -0,0 +1,10 @@
1
+ import { type PhiMediaUploadLabels } from "../media/media-upload-labels";
2
+ /**
3
+ * The upload's refusals as a field control reads them from its labels: under `PHI_FORM_UPLOAD_LABEL_KEYS`,
4
+ * where the Form Widget put Core's `widget:upload` words for every Form with an upload field or a
5
+ * `media-asset` field (`form-field-labels.ts`), and the source wording where it put none.
6
+ *
7
+ * Beside the keys rather than in their file: the keys are on the Server graph of every Page
8
+ * (`form-field-labels.ts`, `form-provider-contract.ts`), and only the field controls read the words back.
9
+ */
10
+ export declare function readPhiFormUploadRefusalLabels(labels: Readonly<Record<string, string>> | undefined): PhiMediaUploadLabels;
@@ -0,0 +1,24 @@
1
+ import { PHI_MEDIA_UPLOAD_DEFAULT_LABELS } from "../media/media-upload-labels";
2
+ import { PHI_FORM_UPLOAD_LABEL_KEYS } from "./upload-field-keys";
3
+ /**
4
+ * The upload's refusals as a field control reads them from its labels: under `PHI_FORM_UPLOAD_LABEL_KEYS`,
5
+ * where the Form Widget put Core's `widget:upload` words for every Form with an upload field or a
6
+ * `media-asset` field (`form-field-labels.ts`), and the source wording where it put none.
7
+ *
8
+ * Beside the keys rather than in their file: the keys are on the Server graph of every Page
9
+ * (`form-field-labels.ts`, `form-provider-contract.ts`), and only the field controls read the words back.
10
+ */
11
+ export function readPhiFormUploadRefusalLabels(labels) {
12
+ const read = (key) => labels?.[PHI_FORM_UPLOAD_LABEL_KEYS[key]]?.trim() || PHI_MEDIA_UPLOAD_DEFAULT_LABELS[key];
13
+ return {
14
+ errorGeneric: read("errorGeneric"),
15
+ errorNetwork: read("errorNetwork"),
16
+ errorTooLarge: read("errorTooLarge"),
17
+ errorDuplicate: read("errorDuplicate"),
18
+ errorTypeNotAllowed: read("errorTypeNotAllowed"),
19
+ errorQuotaExceeded: read("errorQuotaExceeded"),
20
+ errorSpaceUnavailable: read("errorSpaceUnavailable"),
21
+ errorStorageUnreachable: read("errorStorageUnreachable"),
22
+ errorFolderLocked: read("errorFolderLocked"),
23
+ };
24
+ }
@@ -9,9 +9,10 @@ import { PhiProgressControl } from "../controls/phi-progress-control";
9
9
  import { PhiTagControl } from "../controls/phi-tag-control";
10
10
  import { PhiTypographyControl } from "../controls/phi-typography-control";
11
11
  import { PhiIcon } from "../shell/phi-icon";
12
- import { PHI_MEDIA_UPLOAD_DEFAULT_LABELS, PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS, } from "../media/media-upload-labels";
12
+ import { PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS } from "../media/media-upload-labels";
13
13
  import { usePhiMediaUpload } from "../media/phi-media-upload";
14
14
  import { PHI_FORM_UPLOAD_LABEL_KEYS } from "./form-provider-contract";
15
+ import { readPhiFormUploadRefusalLabels } from "./upload-field-refusal-labels";
15
16
  /*
16
17
  * The texts arrive in the Form's labels under `PHI_FORM_UPLOAD_LABEL_KEYS`, put there by the Form
17
18
  * Widget from Core's `widget:upload` set for every Form with an upload field. The defaults are that
@@ -60,20 +61,6 @@ function readUploadSettings(config) {
60
61
  area: config?.presentation === "area",
61
62
  };
62
63
  }
63
- function resolveUploadLabels(labels) {
64
- const read = (key, fallback) => labels?.[key]?.trim() || fallback;
65
- return {
66
- errorGeneric: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorGeneric, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorGeneric),
67
- errorNetwork: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorNetwork, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorNetwork),
68
- errorTooLarge: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorTooLarge, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorTooLarge),
69
- errorDuplicate: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorDuplicate, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorDuplicate),
70
- errorTypeNotAllowed: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorTypeNotAllowed, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorTypeNotAllowed),
71
- errorQuotaExceeded: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorQuotaExceeded, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorQuotaExceeded),
72
- errorSpaceUnavailable: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorSpaceUnavailable, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorSpaceUnavailable),
73
- errorStorageUnreachable: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorStorageUnreachable, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorStorageUnreachable),
74
- errorFolderLocked: read(PHI_FORM_UPLOAD_LABEL_KEYS.errorFolderLocked, PHI_MEDIA_UPLOAD_DEFAULT_LABELS.errorFolderLocked),
75
- };
76
- }
77
64
  /**
78
65
  * The shared upload field Control: attach a file, watch it arrive, take it back out again.
79
66
  *
@@ -96,7 +83,7 @@ function resolveUploadLabels(labels) {
96
83
  */
97
84
  export function PhiUploadFormControl({ field, value, onChange, placeholder, labels, disabled, readOnly, formContext, }) {
98
85
  const settings = useMemo(() => readUploadSettings(field.config), [field.config]);
99
- const uploadLabels = useMemo(() => resolveUploadLabels(labels), [labels]);
86
+ const uploadLabels = useMemo(() => readPhiFormUploadRefusalLabels(labels), [labels]);
100
87
  const [refusal, setRefusal] = useState(null);
101
88
  const assetIds = readPhiFormUploadAssetIds(value);
102
89
  const inFlight = useRef(0);
@@ -27,6 +27,7 @@ const PHI_MEDIA_WIDGET_LABEL_SET = definePhiLabelSet({
27
27
  tool_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.kindLabel,
28
28
  tool_reset_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.resetLabel,
29
29
  tool_reload_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.reloadLabel,
30
+ tool_choose_from_library_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.chooseFromLibraryLabel,
30
31
  tool_image_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.imageKindLabel,
31
32
  tool_video_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.videoKindLabel,
32
33
  tool_audio_kind_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.tool.audioKindLabel,
@@ -45,6 +46,7 @@ const PHI_MEDIA_WIDGET_LABEL_SET = definePhiLabelSet({
45
46
  grid_delete_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteLabel,
46
47
  grid_delete_success_template: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteSuccessTemplate),
47
48
  grid_delete_failed_text: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.deleteFailedText),
49
+ grid_add_failed_text: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.grid.addFailedText),
48
50
  picker_trigger_label: PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.triggerLabel,
49
51
  picker_popover_title: PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.popoverTitle,
50
52
  picker_empty_description: definePhiMessageLabel(PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker.emptyDescription),
@@ -82,6 +84,7 @@ export async function getPhiMediaWidgetLabels(options) {
82
84
  kindLabel: labels.tool_kind_label,
83
85
  resetLabel: labels.tool_reset_label,
84
86
  reloadLabel: labels.tool_reload_label,
87
+ chooseFromLibraryLabel: labels.tool_choose_from_library_label,
85
88
  imageKindLabel: labels.tool_image_kind_label,
86
89
  videoKindLabel: labels.tool_video_kind_label,
87
90
  audioKindLabel: labels.tool_audio_kind_label,
@@ -103,6 +106,7 @@ export async function getPhiMediaWidgetLabels(options) {
103
106
  deleteLabel: labels.grid_delete_label,
104
107
  deleteSuccessTemplate: labels.grid_delete_success_template,
105
108
  deleteFailedText: labels.grid_delete_failed_text,
109
+ addFailedText: labels.grid_add_failed_text,
106
110
  },
107
111
  picker: {
108
112
  triggerLabel: labels.picker_trigger_label,
@@ -15,3 +15,17 @@ export declare function findPhiMediaFolderByNamePath(folders: readonly Pick<PhiM
15
15
  folderId: number | null;
16
16
  depth: number;
17
17
  };
18
+ /**
19
+ * Whether a Folder path setting is one whose placeholders read `{key}`: every brace opens or closes one
20
+ * (`{}`, `{a`, `a}`, `{a{b}}` do not). What the `media-asset` field's `folderPath` and the Media
21
+ * renderer's `features.media.folderPath` are held to.
22
+ */
23
+ export declare function isPhiMediaFolderPathTemplate(value: string): boolean;
24
+ /**
25
+ * The Folder path a template of names (`splitPhiMediaFolderNamePath` of a setting) names for these
26
+ * values: each `{key}` the value under `key` -- the `media-asset` field's Form values, the Collection
27
+ * View's binding params for the Media renderer. A name whose placeholder has no value is left out whole
28
+ * -- "Shop Images / {category} / {product}" without a category is "Shop Images / <product>" -- and a name
29
+ * that comes out empty is left out too.
30
+ */
31
+ export declare function resolvePhiMediaFolderPathTemplate(folderPath: readonly string[], values: Readonly<Record<string, unknown>>): string[];
@@ -1,8 +1,9 @@
1
+ import { readPhiDotPath } from "../../helpers/dot-path";
1
2
  /*
2
3
  * A Folder named by its path of names rather than its id: what a setting states that a preset writes for
3
4
  * every Site (the `area-upload` Widget's `folderPath`) and what the Asset Controller's `path` signal may
4
- * carry. Pure and without runtime imports, because the upload transport reads it and every upload surface carries
5
- * the transport.
5
+ * carry -- with the `{key}` placeholders a path setting may hold. Pure and without runtime imports beyond
6
+ * the dot-path reader, because the upload transport reads it and every upload surface carries the transport.
6
7
  */
7
8
  /**
8
9
  * A Folder named by its path, written the way a person types it and Core reads it: names from the root
@@ -34,3 +35,40 @@ export function findPhiMediaFolderByNamePath(folders, path) {
34
35
  }
35
36
  return { folderId, depth };
36
37
  }
38
+ /* `{key}`: a value's key, a dotted path into it for a value that is a record. */
39
+ const PHI_MEDIA_FOLDER_PATH_PLACEHOLDER = /\{([A-Za-z0-9_.-]+)\}/gu;
40
+ /**
41
+ * Whether a Folder path setting is one whose placeholders read `{key}`: every brace opens or closes one
42
+ * (`{}`, `{a`, `a}`, `{a{b}}` do not). What the `media-asset` field's `folderPath` and the Media
43
+ * renderer's `features.media.folderPath` are held to.
44
+ */
45
+ export function isPhiMediaFolderPathTemplate(value) {
46
+ return !/[{}]/u.test(value.replace(PHI_MEDIA_FOLDER_PATH_PLACEHOLDER, ""));
47
+ }
48
+ /*
49
+ * A value as a Folder name: a text or a number, trimmed, and a `/` in it a `-`, so a value can name a
50
+ * Folder but never add a level of them. Anything else -- empty, absent, a list, a record -- is no name.
51
+ */
52
+ function readPhiMediaFolderPathValue(value) {
53
+ const text = typeof value === "string" ? value : typeof value === "number" && Number.isFinite(value) ? String(value) : "";
54
+ return text.replace(/\//gu, "-").replace(/\s+/gu, " ").trim();
55
+ }
56
+ /**
57
+ * The Folder path a template of names (`splitPhiMediaFolderNamePath` of a setting) names for these
58
+ * values: each `{key}` the value under `key` -- the `media-asset` field's Form values, the Collection
59
+ * View's binding params for the Media renderer. A name whose placeholder has no value is left out whole
60
+ * -- "Shop Images / {category} / {product}" without a category is "Shop Images / <product>" -- and a name
61
+ * that comes out empty is left out too.
62
+ */
63
+ export function resolvePhiMediaFolderPathTemplate(folderPath, values) {
64
+ return folderPath.flatMap((segment) => {
65
+ let missing = false;
66
+ const resolved = segment.replace(PHI_MEDIA_FOLDER_PATH_PLACEHOLDER, (_placeholder, key) => {
67
+ const value = readPhiMediaFolderPathValue(readPhiDotPath(values, key));
68
+ if (!value)
69
+ missing = true;
70
+ return value;
71
+ }).replace(/\s+/gu, " ").trim();
72
+ return missing || !resolved ? [] : [resolved];
73
+ });
74
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The Media library's own Collection resource, `assets` of `PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection`,
3
+ * as the Asset Module declares it (`plugins/runtime-modules/asset/data-providers.ts` names this object):
4
+ * its filters, its Folder, lock, upload and delete actions, and its upload panel -- what the Media
5
+ * renderer offers for it (COLLECTIONS.md, "The Media renderer").
6
+ *
7
+ * The Foundation's, like the keys beside it, because a Foundation surface binds that resource without a
8
+ * page's registry and still has to hand the renderer its declaration: the Media preview grid
9
+ * (`PhiAssetPreviewGridWidget`). One object, so the declaration the Area's registry holds and the one the
10
+ * grid hands over cannot say different things.
11
+ */
12
+ export declare const PHI_MEDIA_LIBRARY_ASSET_RESOURCE: {
13
+ readonly resourceKey: "assets";
14
+ readonly title: "Assets";
15
+ readonly itemIdentityPath: "id";
16
+ readonly itemRendererKey: `${string}/${string}`;
17
+ readonly selectionValueSchema: `${string}/signals/${string}`;
18
+ readonly defaultForWidget: true;
19
+ readonly query: {
20
+ readonly search: true;
21
+ readonly pagination: true;
22
+ readonly filterFields: readonly [{
23
+ readonly key: "kind";
24
+ readonly title: "Kind";
25
+ readonly type: "enum[]";
26
+ }, {
27
+ readonly key: "presentationFlags";
28
+ readonly title: "Flags";
29
+ readonly type: "enum[]";
30
+ }, {
31
+ readonly key: "folderId";
32
+ readonly title: "Folder";
33
+ readonly type: "path";
34
+ }];
35
+ };
36
+ readonly actions: readonly [{
37
+ readonly key: "createFolder";
38
+ readonly title: "Create folder";
39
+ readonly scope: "resource";
40
+ }, {
41
+ readonly key: "lockFolder";
42
+ readonly title: "Lock folder";
43
+ readonly scope: "resource";
44
+ }, {
45
+ readonly key: "unlockFolder";
46
+ readonly title: "Unlock folder";
47
+ readonly scope: "resource";
48
+ }, {
49
+ readonly key: "upload";
50
+ readonly title: "Upload";
51
+ readonly scope: "resource";
52
+ readonly panelKey: "upload";
53
+ }, {
54
+ readonly key: "refresh";
55
+ readonly title: "Reload";
56
+ readonly scope: "resource";
57
+ }, {
58
+ readonly key: "update";
59
+ readonly title: "Update";
60
+ readonly scope: "item";
61
+ }, {
62
+ readonly key: "delete";
63
+ readonly title: "Delete";
64
+ readonly scope: "item";
65
+ }];
66
+ readonly panels: readonly [{
67
+ readonly key: "upload";
68
+ readonly title: "Upload assets";
69
+ }];
70
+ };
@@ -0,0 +1,41 @@
1
+ import { PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY } from "../../constants/media-library-provider-keys";
2
+ import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../types/signals";
3
+ /**
4
+ * The Media library's own Collection resource, `assets` of `PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection`,
5
+ * as the Asset Module declares it (`plugins/runtime-modules/asset/data-providers.ts` names this object):
6
+ * its filters, its Folder, lock, upload and delete actions, and its upload panel -- what the Media
7
+ * renderer offers for it (COLLECTIONS.md, "The Media renderer").
8
+ *
9
+ * The Foundation's, like the keys beside it, because a Foundation surface binds that resource without a
10
+ * page's registry and still has to hand the renderer its declaration: the Media preview grid
11
+ * (`PhiAssetPreviewGridWidget`). One object, so the declaration the Area's registry holds and the one the
12
+ * grid hands over cannot say different things.
13
+ */
14
+ export const PHI_MEDIA_LIBRARY_ASSET_RESOURCE = {
15
+ resourceKey: "assets",
16
+ title: "Assets",
17
+ itemIdentityPath: "id",
18
+ itemRendererKey: PHI_MEDIA_LIBRARY_ITEM_RENDERER_KEY,
19
+ selectionValueSchema: PHI_SIGNAL_VALUE_SCHEMAS.mediaAssetSelection,
20
+ defaultForWidget: true,
21
+ query: {
22
+ search: true,
23
+ pagination: true,
24
+ filterFields: [
25
+ { key: "kind", title: "Kind", type: "enum[]" },
26
+ { key: "presentationFlags", title: "Flags", type: "enum[]" },
27
+ { key: "folderId", title: "Folder", type: "path" },
28
+ ],
29
+ },
30
+ actions: [
31
+ { key: "createFolder", title: "Create folder", scope: "resource" },
32
+ // The Folder the listing is filtered to; Core refuses every change to what a locked one holds.
33
+ { key: "lockFolder", title: "Lock folder", scope: "resource" },
34
+ { key: "unlockFolder", title: "Unlock folder", scope: "resource" },
35
+ { key: "upload", title: "Upload", scope: "resource", panelKey: "upload" },
36
+ { key: "refresh", title: "Reload", scope: "resource" },
37
+ { key: "update", title: "Update", scope: "item" },
38
+ { key: "delete", title: "Delete", scope: "item" },
39
+ ],
40
+ panels: [{ key: "upload", title: "Upload assets" }],
41
+ };
@@ -195,7 +195,8 @@ export type PhiMediaUploadInitOptions = {
195
195
  folderId?: number | null;
196
196
  /**
197
197
  * A Folder of the Site Space named by its path of names from the root, for a surface whose setting
198
- * names one -- the `area-upload` Widget's `folderPath`. A setting holds the path and not an id, because
198
+ * names one -- the `area-upload` Widget's `folderPath`, and the `media-asset` field's picker while it
199
+ * stands on its start Folder whose path is not all there yet. A setting holds the path and not an id, because
199
200
  * a preset states the same path on every Site, and it is resolved to the Folder's id each time a session
200
201
  * is begun, never kept resolved (`resolvePhiMediaUploadFolderPathId`). Where it is given it stands in
201
202
  * for `folderId` and for `spaceAddress`: a path is read in the Site Space, whatever Space is in view.
@@ -255,6 +256,17 @@ export declare function resolvePhiMediaUploadInitOptions(input: {
255
256
  * needs it. Each caller stops waiting for itself.
256
257
  */
257
258
  export declare function resolvePhiMediaUploadFolderPathId(folderPath: readonly string[], signal?: AbortSignal): Promise<number>;
259
+ /**
260
+ * How far a path of names leads through the Site Space's Folders as they are now, read and nothing
261
+ * written (`GET /api/site/media/folders`): the deepest Folder it reaches, `null` for the root, and whether
262
+ * that is the whole path. For a surface that opens on a path before anything is uploaded -- the
263
+ * `media-asset` field's picker -- and which a reader without Media write authority may open as well; the
264
+ * missing Folders are created by the upload (`resolvePhiMediaUploadFolderPathId`).
265
+ */
266
+ export declare function readPhiMediaUploadFolderPathReach(folderPath: readonly string[], signal?: AbortSignal): Promise<{
267
+ folderId: number | null;
268
+ complete: boolean;
269
+ }>;
258
270
  export declare function initPhiMediaUploadSession(file: File, options?: PhiMediaUploadInitOptions, signal?: AbortSignal): Promise<PhiMediaUploadInitSession>;
259
271
  export declare function uploadPhiMediaUploadBody(plan: PhiMediaUploadPlan, file: File, onProgress?: PhiMediaUploadProgressHandler,
260
272
  /** Parts an earlier attempt delivered, where this session was taken over rather than opened. */
@@ -384,6 +384,22 @@ function readPhiMediaUploadFolderPathFolders(value) {
384
384
  return { id, parentId, name };
385
385
  });
386
386
  }
387
+ /**
388
+ * How far a path of names leads through the Site Space's Folders as they are now, read and nothing
389
+ * written (`GET /api/site/media/folders`): the deepest Folder it reaches, `null` for the root, and whether
390
+ * that is the whole path. For a surface that opens on a path before anything is uploaded -- the
391
+ * `media-asset` field's picker -- and which a reader without Media write authority may open as well; the
392
+ * missing Folders are created by the upload (`resolvePhiMediaUploadFolderPathId`).
393
+ */
394
+ export async function readPhiMediaUploadFolderPathReach(folderPath, signal) {
395
+ const listing = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
396
+ headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
397
+ cache: "no-store",
398
+ ...(signal ? { signal } : {}),
399
+ }));
400
+ const reached = findPhiMediaFolderByNamePath(readPhiMediaUploadFolderPathFolders(listing.folders), folderPath);
401
+ return { folderId: reached.folderId, complete: reached.depth === folderPath.length };
402
+ }
387
403
  async function createPhiMediaUploadFolderPath(folderPath) {
388
404
  const listing = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
389
405
  headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
@@ -15,6 +15,12 @@ export type PhiAssetPreviewToolWidgetLabels = {
15
15
  kindLabel: string;
16
16
  resetLabel: string;
17
17
  reloadLabel: string;
18
+ /**
19
+ * The Media renderer's toolbar action `add`: the Media library's picker, whose pick goes to the bound
20
+ * resource's `add` action. A Collection of references to Assets offers it (a gallery); the Media
21
+ * library's own does not.
22
+ */
23
+ chooseFromLibraryLabel: string;
18
24
  imageKindLabel: string;
19
25
  videoKindLabel: string;
20
26
  audioKindLabel: string;
@@ -50,9 +56,16 @@ export type PhiAreaUploadWidgetLabels = {
50
56
  };
51
57
  export type PhiAssetPreviewGridWidgetLabels = {
52
58
  emptyDescription: string;
59
+ /**
60
+ * A tile's delete, the bound resource's `delete` action: the Media library deletes the file, a
61
+ * Collection of references takes it out -- whose placement says so in its own words
62
+ * (`presentation.labels.grid`).
63
+ */
53
64
  deleteLabel: string;
54
65
  deleteSuccessTemplate: string;
55
66
  deleteFailedText: string;
67
+ /** Said where the resource's `add` action refused an Asset picked or uploaded, without words of its own. */
68
+ addFailedText: string;
56
69
  };
57
70
  export type PhiAssetInspectorWidgetLabels = {
58
71
  inspectorTitle: string;
@@ -14,6 +14,7 @@ export const PHI_MEDIA_WIDGET_DEFAULT_LABELS = {
14
14
  kindLabel: "Kind",
15
15
  resetLabel: "Reset",
16
16
  reloadLabel: "Reload",
17
+ chooseFromLibraryLabel: "Choose from Media library",
17
18
  imageKindLabel: "image",
18
19
  videoKindLabel: "video",
19
20
  audioKindLabel: "audio",
@@ -47,6 +48,7 @@ export const PHI_MEDIA_WIDGET_DEFAULT_LABELS = {
47
48
  deleteLabel: "Delete asset",
48
49
  deleteSuccessTemplate: "Asset %1 deleted.",
49
50
  deleteFailedText: "Delete failed.",
51
+ addFailedText: "The file could not be added.",
50
52
  },
51
53
  picker: {
52
54
  triggerLabel: "Mediathek",
@@ -1,11 +1,41 @@
1
1
  import type { PhiCmsAreaUploadWidgetConfig } from "../../types/media";
2
+ import type { PhiMediaAssetTile } from "../../types/media";
2
3
  import type { PhiCollectionProviderQuery } from "../../types/collection-provider";
3
4
  import type { PhiAreaUploadWidgetLabels } from "./media-widget-labels";
5
+ import { type PhiMediaUploadAcceptance } from "./phi-media-upload";
4
6
  import { type PhiImagePreviewStoreState } from "./phi-image-preview-store";
5
7
  export type PhiAreaUploadWidgetProps = {
6
8
  config?: PhiCmsAreaUploadWidgetConfig | null;
7
9
  labels: PhiAreaUploadWidgetLabels;
8
10
  onUploadComplete?: () => void;
11
+ /**
12
+ * What the surface takes (`usePhiMediaUpload`'s acceptance): a file of another kind is refused before
13
+ * it is sent, and the file dialog offers these kinds. Absent: `config.accept`, every file by default.
14
+ */
15
+ acceptance?: PhiMediaUploadAcceptance;
16
+ /**
17
+ * Whether an Asset that arrived stays in the wall as a tile, with its delete -- the Media library's own
18
+ * upload panel. `false` for a surface whose Collection shows what arrived itself (a Collection View of
19
+ * another Provider that adds it, the picker that chooses it): only the files on their way and the
20
+ * failed ones stand here, so nothing shows twice. Default `true`.
21
+ */
22
+ showFinished?: boolean;
23
+ /** The Asset that arrived, for a host that does something with it (adds it, chooses it). */
24
+ onAssetUploaded?: (asset: PhiMediaAssetTile) => void;
25
+ /** Whether a file is on its way, for a host that holds something back meanwhile (a Form's submit). */
26
+ onUploadingChange?: (uploading: boolean) => void;
27
+ /**
28
+ * The host's own refusal of a file before it is sent, asked of each file dropped or chosen with the
29
+ * number of files this surface has on their way (the ones let through in the same selection included):
30
+ * the sentence, said as the upload's refusals are (an application message), or `null` to send it. For a
31
+ * host whose list has room for so many (the `media-assets` field's `max`).
32
+ */
33
+ refuseFile?: (file: File, sending: number) => string | null;
34
+ /**
35
+ * Uploads into the Site Space, whatever Space the Media library's listing last showed: for a host that
36
+ * stores a reference everybody follows. A `config.folderPath` is read in the Site Space either way.
37
+ */
38
+ siteSpaceOnly?: boolean;
9
39
  collectionContext?: {
10
40
  folders: PhiImagePreviewStoreState["folders"];
11
41
  folderId: number | null;
@@ -14,5 +44,5 @@ export type PhiAreaUploadWidgetProps = {
14
44
  query: PhiCollectionProviderQuery;
15
45
  };
16
46
  };
17
- export declare function PhiAreaUploadBinding({ config, labels, onUploadComplete, collectionContext }: PhiAreaUploadWidgetProps): import("react").JSX.Element;
47
+ export declare function PhiAreaUploadBinding({ config, labels, onUploadComplete, acceptance, showFinished, onAssetUploaded, onUploadingChange, refuseFile, siteSpaceOnly, collectionContext, }: PhiAreaUploadWidgetProps): import("react").JSX.Element;
18
48
  export declare function PhiAreaUploadWidget(props: PhiAreaUploadWidgetProps): import("react").JSX.Element;
@@ -4,7 +4,7 @@ import { resolvePhiMediaAssetTypeLabel } from "./asset-type-label";
4
4
  import { PhiTagControl } from "../controls/phi-tag-control";
5
5
  import { PhiButtonControl } from "../controls/phi-button-control";
6
6
  import NextImage from "next/image";
7
- import { useMemo, useState } from "react";
7
+ import { useEffect, useMemo, useRef, useState } from "react";
8
8
  import { PhiCollectionLayoutControl } from "../controls/phi-collection-layout-control";
9
9
  import { resolvePhiMediaKindFromContentType, } from "../../constants/media";
10
10
  import { normalizePhiImagePreviewTile, resolvePhiMediaAssetDisplayDimensions, } from "./phi-image-preview-data";
@@ -68,7 +68,7 @@ function buildPendingWallItem(item, presentationFlags) {
68
68
  function resolveUploadWallDisplayDimensions(item) {
69
69
  return resolvePhiMediaAssetDisplayDimensions(item);
70
70
  }
71
- export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collectionContext }) {
71
+ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, acceptance, showFinished = true, onAssetUploaded, onUploadingChange, refuseFile, siteSpaceOnly = false, collectionContext, }) {
72
72
  const { token } = usePhiConfig();
73
73
  const { showMessage } = usePhiApplicationFeedback();
74
74
  const uploadTileFrameSize = token.controlHeight * 3;
@@ -77,7 +77,7 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
77
77
  const activateCollectionAction = usePhiCollectionProviderAction(PHI_ASSET_COLLECTION_DATA_SOURCE);
78
78
  const [uploadWall, setUploadWall] = useState([]);
79
79
  const allowDelete = config?.allowDelete ?? true;
80
- const accept = config?.accept?.trim() || "*/*";
80
+ const configAccept = config?.accept?.trim() || "*/*";
81
81
  const multiple = config?.multiple ?? true;
82
82
  const collectionFolderId = collectionContext?.folderId ?? null;
83
83
  const collectionPresentationFlags = collectionContext?.presentationFlags ?? null;
@@ -94,8 +94,9 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
94
94
  configPresentationFlags: config?.presentationFlags,
95
95
  // A Folder this Widget names is where it uploads, whichever one the Controller has open.
96
96
  configFolderPath,
97
- // Whatever Space the listing last answered with -- an upload follows the eye, not a separate choice.
98
- activeSpaceAddress: previewState.activeSpace?.address ?? null,
97
+ // Whatever Space the listing last answered with -- an upload follows the eye, not a separate choice --
98
+ // unless the host stores what arrives for everybody, which only the Site Space can stand behind.
99
+ activeSpaceAddress: siteSpaceOnly ? null : previewState.activeSpace?.address ?? null,
99
100
  }), [
100
101
  collectionFolderId,
101
102
  collectionPresentationFlags,
@@ -105,6 +106,7 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
105
106
  previewState.activeSpace?.address,
106
107
  previewState.presentationFlags,
107
108
  previewState.folderId,
109
+ siteSpaceOnly,
108
110
  ]);
109
111
  function showUploadMessage(type, content) {
110
112
  showMessage({
@@ -150,15 +152,28 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
150
152
  */
151
153
  const upload = usePhiMediaUpload({
152
154
  labels: labels.refusals,
155
+ ...(acceptance ? { acceptance } : {}),
153
156
  initOptions: uploadInitOptions,
154
157
  onUploaded: (asset, file) => {
155
158
  const uploadedTile = normalizePhiImagePreviewTile(asset, []);
156
- setUploadWall((current) => [buildUploadWallItem(uploadedTile, `asset-${uploadedTile.id}`), ...current]);
159
+ if (showFinished) {
160
+ setUploadWall((current) => [buildUploadWallItem(uploadedTile, `asset-${uploadedTile.id}`), ...current]);
161
+ }
157
162
  onUploadComplete?.();
158
163
  showUploadMessage("success", labels.uploadSuccessTemplate.replace("%1", file.name));
164
+ onAssetUploaded?.(uploadedTile);
159
165
  },
160
166
  onRejected: (message) => showUploadMessage("error", message),
161
167
  });
168
+ const accept = acceptance ? upload.accept : configAccept;
169
+ const sendingRef = useRef(0);
170
+ const uploading = upload.uploading;
171
+ useEffect(() => {
172
+ if (!onUploadingChange)
173
+ return;
174
+ onUploadingChange(uploading);
175
+ }, [onUploadingChange, uploading]);
176
+ useEffect(() => () => onUploadingChange?.(false), [onUploadingChange]);
162
177
  // The shared items are on their way or failed; an arrived one is a tile in the wall instead.
163
178
  const wallItems = [
164
179
  ...upload.items
@@ -166,7 +181,18 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
166
181
  .map((item) => buildPendingWallItem(item, uploadInitOptions.presentationFlags ?? 0)),
167
182
  ...uploadWall,
168
183
  ];
169
- return (_jsxs(PhiFlexControl, { vertical: true, gap: 12, style: { width: "100%" }, children: [_jsx(PhiUploadDropArea, { multiple: multiple, accept: accept, title: labels.dropTitle, hint: labels.dropHint, onFile: (file) => void upload.upload(file) }), _jsx(PhiCollectionLayoutControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: uploadTileFrameSize, items: wallItems.map((item) => {
184
+ return (_jsxs(PhiFlexControl, { vertical: true, gap: 12, style: { width: "100%" }, children: [_jsx(PhiUploadDropArea, { multiple: multiple, accept: accept, title: labels.dropTitle, hint: labels.dropHint, onFile: (file) => {
185
+ const refusal = refuseFile?.(file, sendingRef.current) ?? null;
186
+ if (refusal) {
187
+ showUploadMessage("error", refusal);
188
+ return;
189
+ }
190
+ // Counted rather than read off the items: a selection of several arrives file by file in one tick.
191
+ sendingRef.current += 1;
192
+ void upload.upload(file).finally(() => {
193
+ sendingRef.current -= 1;
194
+ });
195
+ } }), _jsx(PhiCollectionLayoutControl, { mode: "grid", gap: token.paddingSM, minColumnWidth: uploadTileFrameSize, items: wallItems.map((item) => {
170
196
  const displayDimensions = resolveUploadWallDisplayDimensions(item);
171
197
  return (_jsxs("div", { style: {
172
198
  border: resolvePhiThemeBorderLine(token.colorBorderSecondary),
@@ -1,4 +1,4 @@
1
- import type { PhiMediaAsset, PhiMediaAssetFolder, PhiMediaAssetTile, PhiMediaPickerPagination, PhiMediaSpaceOption } from "../../types/media";
1
+ import type { PhiMediaAsset, PhiMediaAssetFolder, PhiMediaAssetTile, PhiMediaCollectionItem, PhiMediaPickerPagination, PhiMediaSpaceOption } from "../../types/media";
2
2
  export type PhiImagePreviewApiRecord = Omit<PhiMediaAsset, "kind"> & {
3
3
  thumbnailUrl?: string | null;
4
4
  previewUrl?: string | null;
@@ -16,6 +16,13 @@ export declare function readPhiMediaPagination(value: unknown, source?: string):
16
16
  * holds items of no particular type, so whoever takes them out reads them again instead of casting.
17
17
  */
18
18
  export declare function readPhiMediaAssetTiles(value: unknown, source?: string): PhiMediaAssetTile[];
19
+ /**
20
+ * The items of a Collection the Media renderer draws, from any Provider (`PhiMediaCollectionItem`): read
21
+ * field by field as the Media library's own tiles are, so an item without its id, name, type, kind or
22
+ * delivery state, or with a field of the wrong type, is an error naming the field. `deliveryUrl` is a
23
+ * text, empty for a reference whose Asset the library no longer answers. `source` names the Collection.
24
+ */
25
+ export declare function readPhiMediaCollectionItems(value: unknown, source: string): PhiMediaCollectionItem[];
19
26
  export declare function resolvePhiMediaAssetDisplayDimensions(asset: Pick<PhiMediaAssetTile, "contentType" | "width" | "height">): {
20
27
  width: number;
21
28
  height: number;
@@ -171,6 +171,35 @@ export function readPhiMediaAssetTiles(value, source = PHI_MEDIA_LISTING) {
171
171
  };
172
172
  }) ?? [];
173
173
  }
174
+ /**
175
+ * The items of a Collection the Media renderer draws, from any Provider (`PhiMediaCollectionItem`): read
176
+ * field by field as the Media library's own tiles are, so an item without its id, name, type, kind or
177
+ * delivery state, or with a field of the wrong type, is an error naming the field. `deliveryUrl` is a
178
+ * text, empty for a reference whose Asset the library no longer answers. `source` names the Collection.
179
+ */
180
+ export function readPhiMediaCollectionItems(value, source) {
181
+ return createPhiResponseReader({ items: value }, source).list("items", (reader) => {
182
+ const folderId = reader.integer("folderId");
183
+ return {
184
+ id: requiredInteger(reader, "id"),
185
+ originalName: requiredString(reader, "originalName"),
186
+ title: nullableString(reader, "title"),
187
+ altText: nullableString(reader, "altText"),
188
+ // Empty for a reference whose Asset the library no longer answers: the tile shows the kind's icon.
189
+ deliveryUrl: typeof reader.record.deliveryUrl === "string" ? reader.record.deliveryUrl : reader.fail("deliveryUrl", "a text"),
190
+ thumbnailUrl: nullableString(reader, "thumbnailUrl"),
191
+ previewUrl: nullableString(reader, "previewUrl"),
192
+ blurDataUrl: nullableString(reader, "blurDataUrl"),
193
+ contentType: requiredString(reader, "contentType"),
194
+ kind: requirePhiField(reader, "kind", "a media kind", (key) => reader.oneOf(key, PHI_MEDIA_KINDS)),
195
+ width: nullableNumber(reader, "width"),
196
+ height: nullableNumber(reader, "height"),
197
+ lifecycleStatus: requiredInteger(reader, "lifecycleStatus"),
198
+ deliveryPolicy: requiredInteger(reader, "deliveryPolicy"),
199
+ ...(folderId === undefined ? {} : { folderId }),
200
+ };
201
+ }) ?? [];
202
+ }
174
203
  const PHI_SVG_MEDIA_MIN_DISPLAY_DIMENSION = 48;
175
204
  function normalizePhiImagePreviewAsset(asset) {
176
205
  return {