@phis/ui 0.7.1 → 0.7.3

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 (102) hide show
  1. package/components/cms/phi-cms-layout-renderer.d.ts +1 -0
  2. package/components/cms/phi-cms-layout-renderer.js +35 -6
  3. package/components/controls/phi-collection-reorder-context.d.ts +21 -0
  4. package/components/controls/phi-collection-reorder-context.js +6 -0
  5. package/components/controls/phi-collection-sortable-layout-control.d.ts +17 -0
  6. package/components/controls/phi-collection-sortable-layout-control.js +72 -0
  7. package/components/controls/phi-collection-view-control.d.ts +1 -1
  8. package/components/controls/phi-collection-view-control.js +15 -1
  9. package/components/controls/phi-media-asset-tile-control.d.ts +12 -5
  10. package/components/controls/phi-media-picker-control.d.ts +14 -1
  11. package/components/controls/phi-media-picker-control.js +11 -2
  12. package/components/controls/use-phi-color-control-presets.d.ts +2 -2
  13. package/components/controls/use-phi-color-control-presets.js +16 -2
  14. package/components/forms/compound-form-controls.d.ts +1 -1
  15. package/components/forms/compound-form-controls.js +6 -4
  16. package/components/forms/form-field-labels.d.ts +3 -1
  17. package/components/forms/form-field-labels.js +19 -6
  18. package/components/forms/form-provider-contract.js +2 -1
  19. package/components/forms/media-asset-field-keys.d.ts +4 -1
  20. package/components/forms/media-asset-field-keys.js +4 -1
  21. package/components/forms/table-field-keys.d.ts +8 -0
  22. package/components/forms/table-field-keys.js +8 -0
  23. package/components/forms/table-field-labels.d.ts +16 -0
  24. package/components/forms/table-field-labels.js +16 -0
  25. package/components/forms/table-field-text.d.ts +9 -0
  26. package/components/forms/table-field-text.js +20 -0
  27. package/components/forms/upload-field-refusal-labels.d.ts +10 -0
  28. package/components/forms/upload-field-refusal-labels.js +24 -0
  29. package/components/forms/upload-form-control.js +3 -16
  30. package/components/layouts/clients/phi-flex-layout-client.js +12 -2
  31. package/components/media/media-folder-name-path.d.ts +17 -0
  32. package/components/media/media-folder-name-path.js +36 -0
  33. package/components/media/media-upload-flow.d.ts +42 -0
  34. package/components/media/media-upload-flow.js +120 -4
  35. package/components/media/media-upload-refusals.js +5 -2
  36. package/components/media/phi-area-upload-widget.js +4 -0
  37. package/components/media/phi-media-picker-binding.d.ts +48 -1
  38. package/components/media/phi-media-picker-binding.js +99 -6
  39. package/components/media/phi-media-upload.d.ts +7 -1
  40. package/components/media/phi-media-upload.js +17 -5
  41. package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
  42. package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
  43. package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
  44. package/components/widgets/client/shared/phi-command-buttons.d.ts +12 -0
  45. package/components/widgets/client/shared/phi-command-buttons.js +23 -3
  46. package/components/widgets/config/command-buttons.js +3 -0
  47. package/components/widgets/label-sets/collection-view.d.ts +4 -0
  48. package/components/widgets/label-sets/collection-view.js +16 -0
  49. package/components/widgets/label-sets/color-picker.js +2 -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/components/widgets/label-types/color-picker.d.ts +1 -0
  55. package/components/widgets/label-types/color-picker.js +1 -0
  56. package/controls.d.ts +1 -1
  57. package/helpers/cms-content-binding.d.ts +7 -1
  58. package/helpers/cms-content-binding.js +10 -2
  59. package/helpers/cms-node-visibility.d.ts +25 -0
  60. package/helpers/cms-node-visibility.js +35 -1
  61. package/package.json +2 -2
  62. package/plugins/runtime-modules/accounting/definition.js +1 -1
  63. package/plugins/runtime-modules/accounting/presets.js +5 -12
  64. package/plugins/runtime-modules/area-definitions.d.ts +9 -39
  65. package/plugins/runtime-modules/area-definitions.js +8 -8
  66. package/plugins/runtime-modules/asset/controller/runtime.js +1 -6
  67. package/plugins/runtime-modules/asset/definition.d.ts +8 -0
  68. package/plugins/runtime-modules/asset/form-providers.d.ts +8 -0
  69. package/plugins/runtime-modules/asset/form-providers.js +6 -0
  70. package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
  71. package/plugins/runtime-modules/asset/media-asset-field.js +50 -3
  72. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +13 -0
  73. package/plugins/runtime-modules/asset/media-asset-form-control.js +81 -5
  74. package/plugins/runtime-modules/asset/widgets/area-upload/config.js +7 -1
  75. package/plugins/runtime-modules/builder/data-providers.js +1 -0
  76. package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
  77. package/plugins/runtime-modules/builder/services/runtime-modules-table.d.ts +1 -0
  78. package/plugins/runtime-modules/builder/services/runtime-modules-table.js +4 -0
  79. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +6 -5
  80. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +5 -0
  81. package/plugins/runtime-modules/core/widgets/collection-view/client.js +50 -4
  82. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +28 -2
  83. package/plugins/runtime-modules/core/widgets/collection-view/config.js +13 -0
  84. package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
  85. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +4 -1
  86. package/plugins/runtime-modules/core/widgets/collection-view/server.js +19 -4
  87. package/plugins/runtime-modules/core/widgets/image/config.d.ts +1 -0
  88. package/plugins/runtime-modules/core/widgets/image/config.js +1 -0
  89. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +1 -1
  90. package/plugins/runtime-modules/core/widgets/markdown/config.js +1 -0
  91. package/plugins/runtime-modules/core/widgets/markdown/plugin.js +0 -1
  92. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +1 -0
  93. package/plugins/runtime-modules/core/widgets/simple-text/config.js +1 -0
  94. package/plugins/runtime-modules/core/widgets/table/client.js +8 -1
  95. package/server-helpers/cms-node-record.d.ts +18 -0
  96. package/server-helpers/cms-node-record.js +28 -0
  97. package/types/cms-plugins.d.ts +6 -0
  98. package/types/collection-provider.d.ts +7 -0
  99. package/types/collection-view-widget.d.ts +11 -0
  100. package/types/core-widget-placements.d.ts +11 -0
  101. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.d.ts +0 -6
  102. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.js +0 -49
@@ -7,7 +7,8 @@
7
7
  * Module that places the field translates none of them. A Foundation file for the same reason
8
8
  * `upload-field-keys.ts` is: the Server reads it without the Asset Module, and the Module's control reads
9
9
  * it without the Server. Where the field's own wording is the Form's -- Choose, Change, Remove -- the keys
10
- * are the Module's (`PHI_FORM_MEDIA_ASSET_LABEL_KEYS`).
10
+ * are the Module's (`PHI_FORM_MEDIA_ASSET_LABEL_KEYS`). The upload inside the picker says its refusals and
11
+ * its hold under the upload field's keys (`PHI_FORM_UPLOAD_LABEL_KEYS`), read for this field as well.
11
12
  */
12
13
  export declare const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS: {
13
14
  readonly popoverTitle: "mediaAssetPickerTitle";
@@ -24,4 +25,6 @@ export declare const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS: {
24
25
  readonly importingLabel: "mediaAssetPickerImporting";
25
26
  readonly importFailedText: "mediaAssetPickerImportFailed";
26
27
  readonly loadMoreLabel: "mediaAssetPickerLoadMore";
28
+ /** The picker's upload button (the Media Label Set's upload toggle). */
29
+ readonly uploadLabel: "mediaAssetPickerUpload";
27
30
  };
@@ -7,7 +7,8 @@
7
7
  * Module that places the field translates none of them. A Foundation file for the same reason
8
8
  * `upload-field-keys.ts` is: the Server reads it without the Asset Module, and the Module's control reads
9
9
  * it without the Server. Where the field's own wording is the Form's -- Choose, Change, Remove -- the keys
10
- * are the Module's (`PHI_FORM_MEDIA_ASSET_LABEL_KEYS`).
10
+ * are the Module's (`PHI_FORM_MEDIA_ASSET_LABEL_KEYS`). The upload inside the picker says its refusals and
11
+ * its hold under the upload field's keys (`PHI_FORM_UPLOAD_LABEL_KEYS`), read for this field as well.
11
12
  */
12
13
  export const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS = {
13
14
  popoverTitle: "mediaAssetPickerTitle",
@@ -24,4 +25,6 @@ export const PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS = {
24
25
  importingLabel: "mediaAssetPickerImporting",
25
26
  importFailedText: "mediaAssetPickerImportFailed",
26
27
  loadMoreLabel: "mediaAssetPickerLoadMore",
28
+ /** The picker's upload button (the Media Label Set's upload toggle). */
29
+ uploadLabel: "mediaAssetPickerUpload",
27
30
  };
@@ -0,0 +1,8 @@
1
+ import type { PhiFormProviderKey } from "../../types/form-descriptor";
2
+ /**
3
+ * The Core `table` field's own names, apart from the rest of the Form contract, for the reason
4
+ * `upload-field-keys.ts` is: the Form Widget reads the field's words on the Server (`form-field-labels.ts`)
5
+ * and needs only which field type is the table field; the keys its control reads the words under are in
6
+ * `table-field-labels.ts`, without imports, because Core's `widget:table` set reads its defaults there.
7
+ */
8
+ export declare const PHI_FORM_TABLE_FIELD_PROVIDER_KEY: PhiFormProviderKey;
@@ -0,0 +1,8 @@
1
+ import { createPhiModuleScopedKey } from "../../constants/runtime-module-ownership";
2
+ /**
3
+ * The Core `table` field's own names, apart from the rest of the Form contract, for the reason
4
+ * `upload-field-keys.ts` is: the Form Widget reads the field's words on the Server (`form-field-labels.ts`)
5
+ * and needs only which field type is the table field; the keys its control reads the words under are in
6
+ * `table-field-labels.ts`, without imports, because Core's `widget:table` set reads its defaults there.
7
+ */
8
+ export const PHI_FORM_TABLE_FIELD_PROVIDER_KEY = createPhiModuleScopedKey("form-field", "table");
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The words the table field says where its `config` names none: the add action, the remove action and
3
+ * the empty table. The Form Widget puts Core's `widget:table` words here for every Form with a table
4
+ * field, and the Form's own Label Set may say them differently under the same keys.
5
+ */
6
+ export declare const PHI_FORM_TABLE_LABEL_KEYS: {
7
+ readonly add: "tableAdd";
8
+ readonly remove: "tableRemove";
9
+ readonly empty: "tableEmpty";
10
+ };
11
+ /** The source wording of those words, for a Form rendered without a resolution behind it. */
12
+ export declare const PHI_FORM_TABLE_DEFAULT_LABELS: {
13
+ readonly add: "Add";
14
+ readonly remove: "Remove";
15
+ readonly empty: "No rows yet.";
16
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The words the table field says where its `config` names none: the add action, the remove action and
3
+ * the empty table. The Form Widget puts Core's `widget:table` words here for every Form with a table
4
+ * field, and the Form's own Label Set may say them differently under the same keys.
5
+ */
6
+ export const PHI_FORM_TABLE_LABEL_KEYS = {
7
+ add: "tableAdd",
8
+ remove: "tableRemove",
9
+ empty: "tableEmpty",
10
+ };
11
+ /** The source wording of those words, for a Form rendered without a resolution behind it. */
12
+ export const PHI_FORM_TABLE_DEFAULT_LABELS = {
13
+ add: "Add",
14
+ remove: "Remove",
15
+ empty: "No rows yet.",
16
+ };
@@ -0,0 +1,9 @@
1
+ import { PHI_FORM_TABLE_LABEL_KEYS } from "./table-field-labels";
2
+ /**
3
+ * One of the table field's words: the text its `config` names -- a label reference (`{ kind: "label",
4
+ * key, fallback }`) read from the Form's labels, or a literal (`{ kind: "literal", value }`), as a field's
5
+ * own label is written -- or else the Form's word under `PHI_FORM_TABLE_LABEL_KEYS`, which the Form Widget
6
+ * fills from Core's `widget:table` set, or else the English source. A plain string is not a text: it would
7
+ * be English in every language.
8
+ */
9
+ export declare function readPhiFormTableFieldText(value: unknown, labels: Readonly<Record<string, string>> | undefined, key: keyof typeof PHI_FORM_TABLE_LABEL_KEYS): string;
@@ -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);
@@ -189,6 +189,16 @@ export function PhiFlexLayout({ slots, ...layoutProps }) {
189
189
  const shouldWrap = resolvedWrap != null && resolvedWrap !== "nowrap";
190
190
  const usesMinMainBasis = shouldWrap && minMainSize != null;
191
191
  const canShrinkWithinMax = shouldWrap && maxMainSize != null;
192
+ /*
193
+ * A child that is its own content on the main axis gives way in a row that does not wrap, but no
194
+ * further than its content can go (`min-width: auto`, or the minimum it states): a text wraps inside
195
+ * the room the row has left, while a picture of a set width or a label kept on one line has nothing
196
+ * to give and stays as it is. Held at its content size it ran past the row's edge instead -- a page
197
+ * title beside an icon, on a phone. A child with a width of its own keeps it, and in a row that wraps
198
+ * a child moves to the next line rather than giving way. A collapsed slot is as narrow as nothing.
199
+ */
200
+ const givesWayToContent = slotState === "expanded" && !shouldWrap &&
201
+ !slotSizing.stretchesInline && !slotSizing.hasExplicitWidth;
192
202
  const flexBasis = usesMinMainBasis
193
203
  ? minMainSize
194
204
  : shouldFillMainAxis
@@ -204,11 +214,11 @@ export function PhiFlexLayout({ slots, ...layoutProps }) {
204
214
  });
205
215
  return (_jsx("div", { className: phiLayoutSlotClassName(isAuthoringRender), "data-phi-layout-has-content": phiLayoutSlotContentMarker(isAuthoringRender, true), style: {
206
216
  flexGrow: shouldFillMainAxis ? 1 : 0,
207
- flexShrink: shouldFillMainAxis || usesMinMainBasis || canShrinkWithinMax ? 1 : 0,
217
+ flexShrink: shouldFillMainAxis || usesMinMainBasis || canShrinkWithinMax || givesWayToContent ? 1 : 0,
208
218
  flexBasis,
209
219
  ...collapsedStyle,
210
220
  height: shouldFillCrossAxis ? "100%" : undefined,
211
- minWidth: minMainSize ?? 0,
221
+ minWidth: minMainSize ?? (givesWayToContent ? "auto" : 0),
212
222
  minHeight: minCrossSize ?? 0,
213
223
  maxWidth: maxMainSize,
214
224
  /*
@@ -0,0 +1,17 @@
1
+ import type { PhiMediaAssetFolder } from "../../types/media";
2
+ /**
3
+ * A Folder named by its path, written the way a person types it and Core reads it: names from the root
4
+ * down, separated by `/` ("Summer 2024 / Costa Rica"). Each name is trimmed and its whitespace folded the
5
+ * way Core stores a Folder's name, and empty names -- a leading or doubled `/` -- are dropped.
6
+ */
7
+ export declare function splitPhiMediaFolderNamePath(value: string | null | undefined): string[];
8
+ /**
9
+ * How far a path of names leads through these Folders: the deepest Folder it reaches and how many of its
10
+ * names that took. Names are matched without regard to case, as Core matches them. `depth` equal to the
11
+ * path's length means the whole path is there; otherwise the names from `depth` on are missing below
12
+ * `folderId` (`null`, the root, when not even the first is there).
13
+ */
14
+ export declare function findPhiMediaFolderByNamePath(folders: readonly Pick<PhiMediaAssetFolder, "id" | "parentId" | "name">[], path: readonly string[]): {
15
+ folderId: number | null;
16
+ depth: number;
17
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ * A Folder named by its path of names rather than its id: what a setting states that a preset writes for
3
+ * 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.
6
+ */
7
+ /**
8
+ * A Folder named by its path, written the way a person types it and Core reads it: names from the root
9
+ * down, separated by `/` ("Summer 2024 / Costa Rica"). Each name is trimmed and its whitespace folded the
10
+ * way Core stores a Folder's name, and empty names -- a leading or doubled `/` -- are dropped.
11
+ */
12
+ export function splitPhiMediaFolderNamePath(value) {
13
+ return (value ?? "")
14
+ .split("/")
15
+ .map((segment) => segment.replace(/\s+/gu, " ").trim())
16
+ .filter(Boolean);
17
+ }
18
+ /**
19
+ * How far a path of names leads through these Folders: the deepest Folder it reaches and how many of its
20
+ * names that took. Names are matched without regard to case, as Core matches them. `depth` equal to the
21
+ * path's length means the whole path is there; otherwise the names from `depth` on are missing below
22
+ * `folderId` (`null`, the root, when not even the first is there).
23
+ */
24
+ export function findPhiMediaFolderByNamePath(folders, path) {
25
+ let folderId = null;
26
+ let depth = 0;
27
+ for (const name of path) {
28
+ const wanted = name.toLowerCase();
29
+ const next = folders.find((folder) => folder.parentId === folderId && folder.name.toLowerCase() === wanted);
30
+ if (!next)
31
+ break;
32
+ folderId = next.id;
33
+ depth += 1;
34
+ }
35
+ return { folderId, depth };
36
+ }
@@ -193,6 +193,15 @@ export type PhiMediaUploadFailureReason = (typeof PHI_MEDIA_UPLOAD_FAILURE_REASO
193
193
  export declare function isUsablePhiMediaUploadPlan(plan: PhiMediaUploadPlan | undefined, storedParts?: number): plan is PhiMediaUploadPlan;
194
194
  export type PhiMediaUploadInitOptions = {
195
195
  folderId?: number | null;
196
+ /**
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`, 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
200
+ * a preset states the same path on every Site, and it is resolved to the Folder's id each time a session
201
+ * is begun, never kept resolved (`resolvePhiMediaUploadFolderPathId`). Where it is given it stands in
202
+ * for `folderId` and for `spaceAddress`: a path is read in the Site Space, whatever Space is in view.
203
+ */
204
+ folderPath?: readonly string[] | null;
196
205
  presentationFlags?: number | null;
197
206
  /**
198
207
  * The Space the surface is currently reading, as the control plane named it.
@@ -218,13 +227,46 @@ export type PhiMediaUploadContext = {
218
227
  * The Space is inherited whole and separately, because it is not a filter a panel owns: it is the Space
219
228
  * the control plane said it served. An upload started while looking at a group's library therefore goes
220
229
  * to that group instead of silently to the Site Space.
230
+ *
231
+ * A Folder the Widget's own setting names (`configFolderPath`, "Shop Images / Products") is the one
232
+ * exception to inheriting: it is where this Widget puts what it takes, whichever Folder the panel or the
233
+ * Controller has open, and it is a Folder of the Site Space. It travels as the path; the session resolves
234
+ * it. The flags are inherited as before. A blank setting is no setting.
221
235
  */
222
236
  export declare function resolvePhiMediaUploadInitOptions(input: {
223
237
  collectionContext?: PhiMediaUploadContext | null;
224
238
  previewState: PhiMediaUploadContext;
225
239
  configPresentationFlags?: number | null;
240
+ configFolderPath?: string | null;
226
241
  activeSpaceAddress?: string | null;
227
242
  }): PhiMediaUploadInitOptions;
243
+ /**
244
+ * The id of the Site Space's Folder a path of names leads to, the Folders it names that are not there yet
245
+ * created on the way, below the deepest one that is.
246
+ *
247
+ * Read afresh for every session rather than kept, because a Folder is renamed, moved or deleted between
248
+ * two uploads and the path is what the setting means. Creating is what makes a preset's Folder work on a
249
+ * Site that has never had it: the first upload brings it into being, with the same authority the upload
250
+ * itself needs, since writing into the Site Space is Media administration either way. A locked Folder on
251
+ * the way is not written into: Core refuses the new Folder (`media_folder_locked`) or the upload
252
+ * (`folder_locked`), and both read as the lock refusal.
253
+ *
254
+ * Two files dropped at once ask for the same path at once. They share one resolution, which is not
255
+ * stopped by either of them: a Folder half created is not worth stopping for, and the other file still
256
+ * needs it. Each caller stops waiting for itself.
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
+ }>;
228
270
  export declare function initPhiMediaUploadSession(file: File, options?: PhiMediaUploadInitOptions, signal?: AbortSignal): Promise<PhiMediaUploadInitSession>;
229
271
  export declare function uploadPhiMediaUploadBody(plan: PhiMediaUploadPlan, file: File, onProgress?: PhiMediaUploadProgressHandler,
230
272
  /** Parts an earlier attempt delivered, where this session was taken over rather than opened. */
@@ -1,4 +1,5 @@
1
1
  import { isPhiRecord } from "../../helpers/is-record";
2
+ import { findPhiMediaFolderByNamePath, splitPhiMediaFolderNamePath } from "./media-folder-name-path";
2
3
  import { buildPhiMediaClientDigest } from "./media-upload-digest";
3
4
  import { PHIS_AREA_HEADER, buildPhiMediaRequestHeaders } from "./phi-media-request-headers";
4
5
  /** How many parts travel at once. Enough to fill a high-latency link, few enough to stay polite. */
@@ -293,8 +294,24 @@ function readPlanTarget(plan) {
293
294
  * The Space is inherited whole and separately, because it is not a filter a panel owns: it is the Space
294
295
  * the control plane said it served. An upload started while looking at a group's library therefore goes
295
296
  * to that group instead of silently to the Site Space.
297
+ *
298
+ * A Folder the Widget's own setting names (`configFolderPath`, "Shop Images / Products") is the one
299
+ * exception to inheriting: it is where this Widget puts what it takes, whichever Folder the panel or the
300
+ * Controller has open, and it is a Folder of the Site Space. It travels as the path; the session resolves
301
+ * it. The flags are inherited as before. A blank setting is no setting.
296
302
  */
297
303
  export function resolvePhiMediaUploadInitOptions(input) {
304
+ const folderPath = splitPhiMediaFolderNamePath(input.configFolderPath);
305
+ if (folderPath.length > 0) {
306
+ return {
307
+ folderId: null,
308
+ folderPath,
309
+ presentationFlags: input.collectionContext
310
+ ? input.collectionContext.presentationFlags ?? 0
311
+ : input.previewState.presentationFlags ?? input.configPresentationFlags ?? 0,
312
+ spaceAddress: null,
313
+ };
314
+ }
298
315
  const spaceAddress = input.activeSpaceAddress?.trim() || null;
299
316
  if (input.collectionContext) {
300
317
  return {
@@ -316,17 +333,116 @@ async function readJsonResponse(response) {
316
333
  }
317
334
  return payload;
318
335
  }
336
+ const PHI_MEDIA_FOLDERS_PATH = "/api/site/media/folders";
337
+ /** Paths being resolved right now, so files dropped together create a missing Folder once, not once each. */
338
+ const pendingPhiMediaUploadFolderPaths = new Map();
339
+ /**
340
+ * The id of the Site Space's Folder a path of names leads to, the Folders it names that are not there yet
341
+ * created on the way, below the deepest one that is.
342
+ *
343
+ * Read afresh for every session rather than kept, because a Folder is renamed, moved or deleted between
344
+ * two uploads and the path is what the setting means. Creating is what makes a preset's Folder work on a
345
+ * Site that has never had it: the first upload brings it into being, with the same authority the upload
346
+ * itself needs, since writing into the Site Space is Media administration either way. A locked Folder on
347
+ * the way is not written into: Core refuses the new Folder (`media_folder_locked`) or the upload
348
+ * (`folder_locked`), and both read as the lock refusal.
349
+ *
350
+ * Two files dropped at once ask for the same path at once. They share one resolution, which is not
351
+ * stopped by either of them: a Folder half created is not worth stopping for, and the other file still
352
+ * needs it. Each caller stops waiting for itself.
353
+ */
354
+ export async function resolvePhiMediaUploadFolderPathId(folderPath, signal) {
355
+ const key = folderPath.map((name) => name.toLowerCase()).join("/");
356
+ let pending = pendingPhiMediaUploadFolderPaths.get(key);
357
+ if (!pending) {
358
+ pending = createPhiMediaUploadFolderPath(folderPath).finally(() => {
359
+ pendingPhiMediaUploadFolderPaths.delete(key);
360
+ });
361
+ pendingPhiMediaUploadFolderPaths.set(key, pending);
362
+ }
363
+ const folderId = await pending;
364
+ throwIfPhiMediaUploadAborted(signal);
365
+ return folderId;
366
+ }
367
+ /**
368
+ * The three things of a listed Folder a path is walked by, read strictly: a listing that does not carry
369
+ * them is refused rather than walked, since a guess here creates a Folder twice. Not the library's full
370
+ * Folder reader, which every upload surface would then carry for the one that names a path.
371
+ */
372
+ function readPhiMediaUploadFolderPathFolders(value) {
373
+ if (!Array.isArray(value)) {
374
+ throw new PhiMediaUploadError("The media folders route answered without its Folders.", null, 500);
375
+ }
376
+ return value.map((entry) => {
377
+ const folder = isPhiRecord(entry) ? entry : {};
378
+ const { id, parentId, name } = folder;
379
+ if (typeof id !== "number" || !Number.isInteger(id)
380
+ || (parentId !== null && (typeof parentId !== "number" || !Number.isInteger(parentId)))
381
+ || typeof name !== "string") {
382
+ throw new PhiMediaUploadError("The media folders route answered a Folder without its id, parent or name.", null, 500);
383
+ }
384
+ return { id, parentId, name };
385
+ });
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
+ }
403
+ async function createPhiMediaUploadFolderPath(folderPath) {
404
+ const listing = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
405
+ headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
406
+ cache: "no-store",
407
+ }));
408
+ const reached = findPhiMediaFolderByNamePath(readPhiMediaUploadFolderPathFolders(listing.folders), folderPath);
409
+ let folderId = reached.folderId;
410
+ for (const name of folderPath.slice(reached.depth)) {
411
+ const body = new FormData();
412
+ body.set("name", name);
413
+ if (folderId != null)
414
+ body.set("parentId", String(folderId));
415
+ const created = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
416
+ method: "POST",
417
+ headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
418
+ cache: "no-store",
419
+ body,
420
+ }));
421
+ const createdId = created.folder?.id;
422
+ if (typeof createdId !== "number" || !Number.isInteger(createdId) || createdId <= 0) {
423
+ throw new PhiMediaUploadError("The media folders route answered a created Folder without its id.", null, 500);
424
+ }
425
+ folderId = createdId;
426
+ }
427
+ if (folderId == null) {
428
+ throw new PhiMediaUploadError("An empty Folder path names no Folder.", null, 400);
429
+ }
430
+ return folderId;
431
+ }
319
432
  export async function initPhiMediaUploadSession(file, options, signal) {
320
- const folderId = Number.isInteger(options?.folderId) && (options?.folderId ?? 0) > 0
321
- ? options?.folderId
322
- : null;
433
+ const folderPath = options?.folderPath?.length ? options.folderPath : null;
434
+ const folderId = folderPath
435
+ ? await resolvePhiMediaUploadFolderPathId(folderPath, signal)
436
+ : Number.isInteger(options?.folderId) && (options?.folderId ?? 0) > 0
437
+ ? options?.folderId
438
+ : null;
323
439
  const presentationFlags = Number.isInteger(options?.presentationFlags) && (options?.presentationFlags ?? 0) >= 0 ? options?.presentationFlags : null;
324
440
  const meta = isPhiRecord(options?.meta)
325
441
  ? options.meta
326
442
  : null;
327
443
  // The Space is named the way every Media route names one -- as a query parameter -- while the Folder
328
444
  // and the flags travel in the body, because those describe the Asset rather than the Space it lands in.
329
- const spaceAddress = options?.spaceAddress?.trim() || null;
445
+ const spaceAddress = folderPath ? null : options?.spaceAddress?.trim() || null;
330
446
  /*
331
447
  * Hashed before the session is asked for, because the Server signs the digest into the upload request
332
448
  * and cannot do that after it has issued one. Null where the browser cannot hash -- an upload without a
@@ -1,4 +1,4 @@
1
- import { PHI_MEDIA_UPLOAD_FOLDER_LOCKED_CODE } from "./media-folder-lock";
1
+ import { PHI_MEDIA_FOLDER_LOCKED_CODE, PHI_MEDIA_UPLOAD_FOLDER_LOCKED_CODE } from "./media-folder-lock";
2
2
  /**
3
3
  * The words for a refusal code the upload path has words for, or `null` for any other code.
4
4
  *
@@ -22,7 +22,10 @@ export function readPhiMediaUploadRefusalMessage(code, labels) {
22
22
  // Provider, so this is deliberately not the same reading as a network failure.
23
23
  case "storage_unreachable":
24
24
  case "storage_rejected": return labels.errorStorageUnreachable;
25
- case PHI_MEDIA_UPLOAD_FOLDER_LOCKED_CODE: return labels.errorFolderLocked;
25
+ // The second is Core's word for a Folder that is not created below a locked one, which an upload
26
+ // into a Folder named by its path meets on the way (`resolvePhiMediaUploadFolderPathId`).
27
+ case PHI_MEDIA_UPLOAD_FOLDER_LOCKED_CODE:
28
+ case PHI_MEDIA_FOLDER_LOCKED_CODE: return labels.errorFolderLocked;
26
29
  default: return null;
27
30
  }
28
31
  }
@@ -82,6 +82,7 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
82
82
  const collectionFolderId = collectionContext?.folderId ?? null;
83
83
  const collectionPresentationFlags = collectionContext?.presentationFlags ?? null;
84
84
  const hasCollectionContext = collectionContext != null;
85
+ const configFolderPath = config?.folderPath ?? null;
85
86
  const uploadInitOptions = useMemo(() => resolvePhiMediaUploadInitOptions({
86
87
  collectionContext: hasCollectionContext
87
88
  ? { folderId: collectionFolderId, presentationFlags: collectionPresentationFlags }
@@ -91,12 +92,15 @@ export function PhiAreaUploadBinding({ config, labels, onUploadComplete, collect
91
92
  presentationFlags: previewState.presentationFlags,
92
93
  },
93
94
  configPresentationFlags: config?.presentationFlags,
95
+ // A Folder this Widget names is where it uploads, whichever one the Controller has open.
96
+ configFolderPath,
94
97
  // Whatever Space the listing last answered with -- an upload follows the eye, not a separate choice.
95
98
  activeSpaceAddress: previewState.activeSpace?.address ?? null,
96
99
  }), [
97
100
  collectionFolderId,
98
101
  collectionPresentationFlags,
99
102
  config?.presentationFlags,
103
+ configFolderPath,
100
104
  hasCollectionContext,
101
105
  previewState.activeSpace?.address,
102
106
  previewState.presentationFlags,
@@ -4,6 +4,33 @@ import type { PhiMediaAssetTile } from "../../types/media";
4
4
  import type { PhiCmsMediaPickerWidgetConfig } from "../../types/media";
5
5
  import type { PhiSearchWidgetLabels } from "../widgets/label-types/search";
6
6
  import type { PhiAssetWidgetLabels } from "./media-widget-labels";
7
+ /**
8
+ * An upload of a file from the reader's machine, offered inside the picker by a host that brings the
9
+ * transport (`usePhiMediaUpload`), so that a picker without one does not carry it.
10
+ *
11
+ * The binding says where the file goes -- the Folder in view -- and chooses what came back; the host
12
+ * sends it, words what went wrong and decides whether the Asset is one to choose (`send` answers null
13
+ * for a refusal, a stopped upload, and an Asset the host does not let be chosen).
14
+ *
15
+ * Offered on the Site Space only, as an import is: the file goes without a Space named, which Core
16
+ * answers with the Site Space, so a picker standing on another Space shows no upload.
17
+ */
18
+ export type PhiMediaPickerUploadBinding = {
19
+ /** What the file dialog offers (`usePhiMediaUpload`'s `accept`). */
20
+ accept: string;
21
+ /** How far the upload on its way is, in per cent; null while none is. */
22
+ progress: number | null;
23
+ /** Why the last upload did not work, or the Asset it made cannot be chosen. */
24
+ notice: string | null;
25
+ /**
26
+ * One file into this Folder of the Site Space (null: its root). `intoStartFolder` is true while the
27
+ * picker stands where `openOnFolder` put it and that Folder's path is not all there yet: the host sends
28
+ * the file into the whole path, creating what is missing, as `area-upload` does.
29
+ */
30
+ send: (file: File, folderId: number | null, intoStartFolder: boolean) => Promise<PhiMediaAssetTile | null>;
31
+ /** Stops what is on its way; the picker was closed. */
32
+ cancel: () => void;
33
+ };
7
34
  export type PhiMediaPickerBindingProps = {
8
35
  config?: PhiCmsMediaPickerWidgetConfig | null;
9
36
  labels: PhiAssetWidgetLabels;
@@ -33,8 +60,23 @@ export type PhiMediaPickerBindingProps = {
33
60
  * reader can see exists.
34
61
  */
35
62
  isAssetSelectable?: (asset: PhiMediaAssetTile) => boolean;
63
+ /** An upload inside the picker, into the Folder it shows (`PhiMediaPickerUploadBinding`). */
64
+ upload?: PhiMediaPickerUploadBinding | null;
65
+ /**
66
+ * The Folder the picker opens on, asked for each time it opens: the listing waits for the answer, and
67
+ * the reader may leave it for another Folder as from any. For a `siteSpaceOnly` host whose setting
68
+ * names a Folder by its path (the `media-asset` field's `folderPath`); the host reads it without
69
+ * writing anything, so a reader who may only choose opens it as well, and answers the deepest Folder of
70
+ * the path that is there (`null`, the root) and whether that is the whole path -- if not, an upload from
71
+ * there goes into the whole path (`PhiMediaPickerUploadBinding.send`). A failed read is said where an
72
+ * upload's refusal would be, and the picker opens on the root.
73
+ */
74
+ openOnFolder?: ((signal: AbortSignal) => Promise<{
75
+ folderId: number | null;
76
+ complete: boolean;
77
+ }>) | null;
36
78
  };
37
- export declare function usePhiMediaPickerBinding({ config, labels, searchLabels, value: controlledValue, onAssetSelect, onAssetClear, open: controlledOpen, onOpenChange, onCommit, onDiscard, onPopupOpenChange, trigger, getPopupContainer, popupRootClassName, siteSpaceOnly, isAssetSelectable, }: PhiMediaPickerBindingProps): {
79
+ export declare function usePhiMediaPickerBinding({ config, labels, searchLabels, value: controlledValue, onAssetSelect, onAssetClear, open: controlledOpen, onOpenChange, onCommit, onDiscard, onPopupOpenChange, trigger, getPopupContainer, popupRootClassName, siteSpaceOnly, isAssetSelectable, upload, openOnFolder, }: PhiMediaPickerBindingProps): {
38
80
  open: boolean;
39
81
  value: number | null;
40
82
  assets: PhiMediaAssetTile[];
@@ -52,6 +94,10 @@ export declare function usePhiMediaPickerBinding({ config, labels, searchLabels,
52
94
  sourceHasMore: boolean;
53
95
  importingItemId: string | null;
54
96
  sourceNotice: string | null;
97
+ onUpload: ((file: File) => Promise<PhiMediaAssetTile | null>) | undefined;
98
+ uploadAccept: string | undefined;
99
+ uploadProgress: number | null;
100
+ uploadNotice: string | null;
55
101
  folders: ({
56
102
  value: string;
57
103
  label: string;
@@ -86,6 +132,7 @@ export declare function usePhiMediaPickerBinding({ config, labels, searchLabels,
86
132
  source: string;
87
133
  importing: string;
88
134
  loadMore: string;
135
+ upload: string;
89
136
  };
90
137
  getPopupContainer: ((triggerNode: HTMLElement) => HTMLElement) | undefined;
91
138
  popupRootClassName: string | undefined;