@phis/ui 0.7.2 → 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 (60) 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 +12 -5
  8. package/components/controls/phi-media-picker-control.d.ts +14 -1
  9. package/components/controls/phi-media-picker-control.js +11 -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 +3 -1
  13. package/components/forms/form-field-labels.js +19 -6
  14. package/components/forms/form-provider-contract.js +2 -1
  15. package/components/forms/media-asset-field-keys.d.ts +4 -1
  16. package/components/forms/media-asset-field-keys.js +4 -1
  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/media-upload-flow.d.ts +13 -1
  27. package/components/media/media-upload-flow.js +16 -0
  28. package/components/media/phi-media-picker-binding.d.ts +48 -1
  29. package/components/media/phi-media-picker-binding.js +99 -6
  30. package/components/media/phi-media-upload.d.ts +7 -1
  31. package/components/media/phi-media-upload.js +17 -5
  32. package/components/widgets/client/shared/phi-collection-reorder.d.ts +45 -0
  33. package/components/widgets/client/shared/phi-collection-reorder.js +110 -0
  34. package/components/widgets/client/shared/phi-collection-view-binding.js +2 -1
  35. package/components/widgets/label-sets/collection-view.d.ts +4 -0
  36. package/components/widgets/label-sets/collection-view.js +16 -0
  37. package/components/widgets/label-sets/table.d.ts +6 -0
  38. package/components/widgets/label-sets/table.js +10 -0
  39. package/components/widgets/label-types/collection-view.d.ts +8 -0
  40. package/components/widgets/label-types/collection-view.js +4 -0
  41. package/controls.d.ts +1 -1
  42. package/package.json +1 -1
  43. package/plugins/runtime-modules/asset/definition.d.ts +8 -0
  44. package/plugins/runtime-modules/asset/form-providers.d.ts +8 -0
  45. package/plugins/runtime-modules/asset/form-providers.js +6 -0
  46. package/plugins/runtime-modules/asset/media-asset-field.d.ts +34 -4
  47. package/plugins/runtime-modules/asset/media-asset-field.js +50 -3
  48. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +13 -0
  49. package/plugins/runtime-modules/asset/media-asset-form-control.js +81 -5
  50. package/plugins/runtime-modules/builder/page-meta-form.js +6 -6
  51. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +5 -0
  52. package/plugins/runtime-modules/core/widgets/collection-view/client.js +50 -4
  53. package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +28 -2
  54. package/plugins/runtime-modules/core/widgets/collection-view/config.js +13 -0
  55. package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +1 -1
  56. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +4 -1
  57. package/plugins/runtime-modules/core/widgets/collection-view/server.js +19 -4
  58. package/types/collection-provider.d.ts +7 -0
  59. package/types/collection-view-widget.d.ts +11 -0
  60. package/types/core-widget-placements.d.ts +5 -0
@@ -0,0 +1,16 @@
1
+ import "server-only";
2
+ import { PHI_TR_CTX_WEB_UI_LABEL } from "../../../gateway/tr";
3
+ import { definePhiLabelSet, definePhiMessageLabel, getPhiLabelSet } from "../../../gateway/label-set";
4
+ import { PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS, } from "../label-types/collection-view";
5
+ const PHI_COLLECTION_VIEW_WIDGET_LABEL_SET = definePhiLabelSet({
6
+ key: "widget:collection-view",
7
+ ctx: PHI_TR_CTX_WEB_UI_LABEL,
8
+ labels: {
9
+ reorder_handle: PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS.reorderHandle,
10
+ reorder_failed: definePhiMessageLabel(PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS.reorderFailed),
11
+ },
12
+ });
13
+ export async function getPhiCollectionViewWidgetLabels(options) {
14
+ const labels = await getPhiLabelSet(options, PHI_COLLECTION_VIEW_WIDGET_LABEL_SET);
15
+ return { reorderHandle: labels.reorder_handle, reorderFailed: labels.reorder_failed };
16
+ }
@@ -2,3 +2,9 @@ import "server-only";
2
2
  import { type PhiGlobalTranslatorOptions } from "../../../gateway/tr";
3
3
  import type { PhiTableWidgetLabels } from "../label-types/table";
4
4
  export declare function getPhiTableWidgetLabels(options: PhiGlobalTranslatorOptions): Promise<PhiTableWidgetLabels>;
5
+ /** The Core `table` form field's add, remove and empty words, which the Form Widget hands to the field. */
6
+ export declare function getPhiTableFormFieldLabels(options: PhiGlobalTranslatorOptions): Promise<{
7
+ add: string;
8
+ remove: string;
9
+ empty: string;
10
+ }>;
@@ -2,6 +2,7 @@ import "server-only";
2
2
  import { PHI_TR_CTX_WEB_UI_LABEL } from "../../../gateway/tr";
3
3
  import { definePhiLabelSet, definePhiMessageLabel, getPhiLabelSet } from "../../../gateway/label-set";
4
4
  import { getPhiIntervalLabels } from "./interval";
5
+ import { PHI_FORM_TABLE_DEFAULT_LABELS } from "../../forms/table-field-labels";
5
6
  const PHI_TABLE_WIDGET_LABEL_SET = definePhiLabelSet({
6
7
  key: "widget:table",
7
8
  ctx: PHI_TR_CTX_WEB_UI_LABEL,
@@ -25,6 +26,10 @@ const PHI_TABLE_WIDGET_LABEL_SET = definePhiLabelSet({
25
26
  drag_row: "Drag row",
26
27
  move_row_up: "Move row up",
27
28
  move_row_down: "Move row down",
29
+ // The Core `table` form field's words where its config names none (`table-field-labels.ts`).
30
+ form_add: PHI_FORM_TABLE_DEFAULT_LABELS.add,
31
+ form_remove: PHI_FORM_TABLE_DEFAULT_LABELS.remove,
32
+ form_empty: definePhiMessageLabel(PHI_FORM_TABLE_DEFAULT_LABELS.empty),
28
33
  },
29
34
  });
30
35
  export async function getPhiTableWidgetLabels(options) {
@@ -54,3 +59,8 @@ export async function getPhiTableWidgetLabels(options) {
54
59
  interval,
55
60
  };
56
61
  }
62
+ /** The Core `table` form field's add, remove and empty words, which the Form Widget hands to the field. */
63
+ export async function getPhiTableFormFieldLabels(options) {
64
+ const labels = await getPhiLabelSet(options, PHI_TABLE_WIDGET_LABEL_SET);
65
+ return { add: labels.form_add, remove: labels.form_remove, empty: labels.form_empty };
66
+ }
@@ -0,0 +1,8 @@
1
+ /** What the `collection-view` Widget says of its own, apart from whatever its renderer says. */
2
+ export type PhiCollectionViewWidgetLabels = {
3
+ /** The drag handle on each item while reordering is offered (`features.reorder`). */
4
+ reorderHandle: string;
5
+ /** Said when the Provider refused the new order and gave no words of its own. */
6
+ reorderFailed: string;
7
+ };
8
+ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS: PhiCollectionViewWidgetLabels;
@@ -0,0 +1,4 @@
1
+ export const PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS = {
2
+ reorderHandle: "Drag to reorder",
3
+ reorderFailed: "The new order could not be saved.",
4
+ };
package/controls.d.ts CHANGED
@@ -39,7 +39,7 @@ export type { PhiCollectionHeaderControlProps } from "./components/controls/phi-
39
39
  export { PhiCollectionViewControl } from "./components/controls/phi-collection-view-control";
40
40
  export type { PhiCollectionViewControlProps } from "./components/controls/phi-collection-view-control";
41
41
  export { PhiMediaAssetCollectionSkeletonControl, PhiMediaAssetTileControl, } from "./components/controls/phi-media-asset-tile-control";
42
- export type { PhiMediaAssetCollectionSkeletonControlProps, PhiMediaAssetTileControlProps, } from "./components/controls/phi-media-asset-tile-control";
42
+ export type { PhiMediaAssetCollectionSkeletonControlProps, PhiMediaAssetTileControlAsset, PhiMediaAssetTileControlProps, } from "./components/controls/phi-media-asset-tile-control";
43
43
  export { PhiMediaSourceItemTileControl } from "./components/controls/phi-media-source-item-tile-control";
44
44
  export type { PhiMediaSourceItemTileControlProps } from "./components/controls/phi-media-source-item-tile-control";
45
45
  export { PhiVideoEmbedControl } from "./components/controls/phi-video-embed-control";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -146,6 +146,14 @@ export declare const PHI_ASSET_RUNTIME_MODULE_DEFINITION: {
146
146
  mode?: undefined;
147
147
  valueType?: undefined;
148
148
  options?: undefined;
149
+ } | {
150
+ key: string;
151
+ type: "string";
152
+ label: string;
153
+ description: string;
154
+ mode?: undefined;
155
+ valueType?: undefined;
156
+ options?: undefined;
149
157
  })[];
150
158
  })[];
151
159
  handlers: ({
@@ -68,5 +68,13 @@ export declare const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR: {
68
68
  mode?: undefined;
69
69
  valueType?: undefined;
70
70
  options?: undefined;
71
+ } | {
72
+ key: string;
73
+ type: "string";
74
+ label: string;
75
+ description: string;
76
+ mode?: undefined;
77
+ valueType?: undefined;
78
+ options?: undefined;
71
79
  })[];
72
80
  };
@@ -61,5 +61,11 @@ export const PHI_ASSET_MEDIA_ASSET_FORM_PROVIDER_DESCRIPTOR = {
61
61
  label: "Public only",
62
62
  description: "Offer only Assets that are delivered publicly. The picker greys out the others; the Server that takes the value decides.",
63
63
  },
64
+ {
65
+ key: "folderPath",
66
+ type: "string",
67
+ label: "Folder path",
68
+ description: "The Site Folder the picker opens on and uploads 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.",
69
+ },
64
70
  ],
65
71
  };
@@ -2,15 +2,38 @@ import type { PhiMediaAssetTile, PhiMediaKindValue } from "../../../types/media"
2
2
  export type PhiMediaAssetFieldConfig = {
3
3
  /** Which kind of Asset the picker lists. */
4
4
  mediaType: PhiMediaKindValue;
5
- /** Whether Assets that are not delivered publicly are greyed out in the picker. */
5
+ /**
6
+ * Whether Assets that are not delivered publicly are greyed out in the picker -- and an uploaded one
7
+ * that is not is left unchosen. Core delivers what goes into the Site Space publicly by default.
8
+ */
6
9
  publicOnly: boolean;
10
+ /**
11
+ * The Folder of the Site Space the picker opens on, by its path of names from the root ("Shop Images /
12
+ * Products"): it opens on the deepest of them that is there, and an upload from there creates the
13
+ * missing ones and goes into the whole path. Empty: the Folder the picker last showed, at first the
14
+ * root. A path and not an id, so a Module's Form states it for every Site.
15
+ *
16
+ * A name may hold placeholders, `{key}`, read from the Form's values when the picker opens
17
+ * (`resolvePhiMediaAssetFieldFolderPath`): "Shop Images / {category} / {product}". These are the names
18
+ * as written, placeholders unresolved.
19
+ */
20
+ folderPath: readonly string[];
7
21
  };
8
22
  /**
9
- * The field's config, read strictly (`strict-config-reader.ts`): a kind the picker does not list, or a
10
- * `publicOnly` that is not a boolean, is a `PhiConfigError` naming the field, never a default put in its
11
- * place -- a typo in `mediaType` would otherwise quietly offer another kind of file.
23
+ * The field's config, read strictly (`strict-config-reader.ts`): a kind the picker does not list, a
24
+ * `publicOnly` that is not a boolean, or a `folderPath` that is not a text or holds a brace that opens no
25
+ * placeholder (`{}`, `{a`, `a}`, `{a{b}}`) is a `PhiConfigError` naming the field, never a default put in
26
+ * its place -- a typo in `mediaType` would otherwise quietly offer another kind of file, and a broken
27
+ * placeholder would become a Folder named after it.
12
28
  */
13
29
  export declare function readPhiMediaAssetFieldConfig(config: Readonly<Record<string, unknown>> | undefined): PhiMediaAssetFieldConfig;
30
+ /**
31
+ * The Folder path a `folderPath` names for the Form's values as they are now: each `{key}` the value
32
+ * under `key` (the Form's current values, those loaded from its record included). A name whose
33
+ * placeholder has no value is left out whole -- "Shop Images / {category} / {product}" without a
34
+ * category is "Shop Images / <product>" -- and a name that comes out empty is left out too.
35
+ */
36
+ export declare function resolvePhiMediaAssetFieldFolderPath(folderPath: readonly string[], values: Readonly<Record<string, unknown>>): string[];
14
37
  /**
15
38
  * The Asset id a Form value holds, or `null`. A value that is not a positive whole number is not an id,
16
39
  * and showing it as one would put a request for Asset `NaN` on the wire.
@@ -18,3 +41,10 @@ export declare function readPhiMediaAssetFieldConfig(config: Readonly<Record<str
18
41
  export declare function readPhiMediaAssetFieldValue(value: unknown): number | null;
19
42
  /** Whether the picker lets one Asset be chosen: always, unless the field offers public Assets only. */
20
43
  export declare function isPhiMediaAssetFieldSelectable(config: PhiMediaAssetFieldConfig, asset: Pick<PhiMediaAssetTile, "deliveryPolicy" | "lifecycleStatus">): boolean;
44
+ /**
45
+ * Whether an Asset uploaded in the field's picker is one it lets be chosen, and if not, why: of the kind
46
+ * the picker lists, and public where the field offers public Assets only. The same question a pick
47
+ * answers, asked of what the upload made -- Core does not know the field's kind, and a file the browser
48
+ * could not name reaches it unrefused.
49
+ */
50
+ export declare function readPhiMediaAssetFieldUploadRefusal(config: PhiMediaAssetFieldConfig, asset: Pick<PhiMediaAssetTile, "kind" | "deliveryPolicy" | "lifecycleStatus">): "kind" | "notPublic" | null;
@@ -1,5 +1,7 @@
1
1
  import { PhiMediaKind, isPhiMediaAssetPublic } from "../../../constants/media";
2
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";
3
5
  const MEDIA_ASSET_FIELD_KINDS = [
4
6
  PhiMediaKind.Image,
5
7
  PhiMediaKind.Video,
@@ -9,17 +11,51 @@ const MEDIA_ASSET_FIELD_KINDS = [
9
11
  PhiMediaKind.Font,
10
12
  ];
11
13
  /**
12
- * The field's config, read strictly (`strict-config-reader.ts`): a kind the picker does not list, or a
13
- * `publicOnly` that is not a boolean, is a `PhiConfigError` naming the field, never a default put in its
14
- * place -- a typo in `mediaType` would otherwise quietly offer another kind of file.
14
+ * The field's config, read strictly (`strict-config-reader.ts`): a kind the picker does not list, a
15
+ * `publicOnly` that is not a boolean, or a `folderPath` that is not a text or holds a brace that opens no
16
+ * placeholder (`{}`, `{a`, `a}`, `{a{b}}`) is a `PhiConfigError` naming the field, never a default put in
17
+ * its place -- a typo in `mediaType` would otherwise quietly offer another kind of file, and a broken
18
+ * placeholder would become a Folder named after it.
15
19
  */
16
20
  export function readPhiMediaAssetFieldConfig(config) {
17
21
  const reader = createPhiConfigReader(config ?? {}, "config");
18
22
  return {
19
23
  mediaType: reader.oneOf("mediaType", MEDIA_ASSET_FIELD_KINDS) ?? PhiMediaKind.Image,
20
24
  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)),
21
26
  };
22
27
  }
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
+ /**
42
+ * The Folder path a `folderPath` names for the Form's values as they are now: each `{key}` the value
43
+ * under `key` (the Form's current values, those loaded from its record included). A name whose
44
+ * placeholder has no value is left out whole -- "Shop Images / {category} / {product}" without a
45
+ * category is "Shop Images / <product>" -- and a name that comes out empty is left out too.
46
+ */
47
+ export function resolvePhiMediaAssetFieldFolderPath(folderPath, values) {
48
+ return folderPath.flatMap((segment) => {
49
+ let missing = false;
50
+ const resolved = segment.replace(PHI_MEDIA_ASSET_FOLDER_PATH_PLACEHOLDER, (_placeholder, key) => {
51
+ const value = readPhiMediaAssetFolderPathValue(readPhiDotPath(values, key));
52
+ if (!value)
53
+ missing = true;
54
+ return value;
55
+ }).replace(/\s+/gu, " ").trim();
56
+ return missing || !resolved ? [] : [resolved];
57
+ });
58
+ }
23
59
  /**
24
60
  * The Asset id a Form value holds, or `null`. A value that is not a positive whole number is not an id,
25
61
  * and showing it as one would put a request for Asset `NaN` on the wire.
@@ -31,3 +67,14 @@ export function readPhiMediaAssetFieldValue(value) {
31
67
  export function isPhiMediaAssetFieldSelectable(config, asset) {
32
68
  return !config.publicOnly || isPhiMediaAssetPublic(asset.deliveryPolicy, asset.lifecycleStatus);
33
69
  }
70
+ /**
71
+ * Whether an Asset uploaded in the field's picker is one it lets be chosen, and if not, why: of the kind
72
+ * the picker lists, and public where the field offers public Assets only. The same question a pick
73
+ * answers, asked of what the upload made -- Core does not know the field's kind, and a file the browser
74
+ * could not name reaches it unrefused.
75
+ */
76
+ export function readPhiMediaAssetFieldUploadRefusal(config, asset) {
77
+ if (asset.kind !== config.mediaType)
78
+ return "kind";
79
+ return isPhiMediaAssetFieldSelectable(config, asset) ? null : "notPublic";
80
+ }
@@ -8,6 +8,19 @@ 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, by
12
+ * the upload every surface sends with (`usePhiMediaUpload`, Core's upload session); what it made is
13
+ * chosen as a picked tile would be. It goes into the Site Space, like everything the field offers, and
14
+ * Core delivers what goes there publicly. What comes back is asked what a pick is asked: an Asset of
15
+ * another kind (a file the browser could not name reaches Core unrefused) or, for a `publicOnly` field,
16
+ * one that is not public is left in the list unchosen, and the field says why. While the file is on its
17
+ * way the Form's submit is held, as the upload field holds it, and closing the picker stops it.
18
+ * `config.folderPath` names the Folder the picker opens on ("Shop Images / Products"): read in the Site
19
+ * Space each time it opens, without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader
20
+ * who may only choose opens and picks without a refusal; the picker opens on the deepest Folder of the
21
+ * path that is there. An upload from there goes into the whole path, the missing Folders created the way
22
+ * `area-upload` creates them (`resolvePhiMediaUploadFolderPathId`).
23
+ *
11
24
  * Only the Site Space is offered, in every Area (`siteSpaceOnly`): a Form stores a reference everybody
12
25
  * who reads the stored value will follow, and a personal or a group Space cannot honestly stand behind
13
26
  * that. `config.publicOnly` greys out the Assets that are not delivered publicly, from the delivery
@@ -1,19 +1,25 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useMemo } from "react";
3
+ import { useCallback, useEffect, useMemo, useRef, 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
7
  import { PHI_FORM_MEDIA_ASSET_PICKER_LABEL_KEYS } from "../../../components/forms/media-asset-field-keys";
8
+ import { PHI_FORM_UPLOAD_LABEL_KEYS } from "../../../components/forms/upload-field-keys";
9
+ import { readPhiFormUploadRefusalLabels } from "../../../components/forms/upload-field-refusal-labels";
8
10
  import { PhiMediaPickerControl } from "../../../components/controls/phi-media-picker-control";
9
11
  import { PhiTypographyControl } from "../../../components/controls/phi-typography-control";
10
12
  import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../components/media/media-widget-labels";
11
- import { usePhiMediaPickerBinding } from "../../../components/media/phi-media-picker-binding";
13
+ import { usePhiMediaPickerBinding, } from "../../../components/media/phi-media-picker-binding";
14
+ import { normalizePhiImagePreviewTile } from "../../../components/media/phi-image-preview-data";
15
+ import { usePhiMediaUpload } from "../../../components/media/phi-media-upload";
16
+ import { readPhiMediaUploadFolderPathReach, } from "../../../components/media/media-upload-flow";
17
+ import { PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS } from "../../../components/media/media-upload-labels";
12
18
  import { usePhiAuthoringAssetDetails } from "../../../components/media/use-authoring-asset-details";
13
19
  import { PHI_SEARCH_WIDGET_DEFAULT_LABELS } from "../../../components/widgets/label-types/search";
14
20
  import { isPhiMediaAssetPublic } from "../../../constants/media";
15
21
  import { PHI_FORM_MEDIA_ASSET_LABEL_KEYS } from "./form-providers";
16
- import { isPhiMediaAssetFieldSelectable, readPhiMediaAssetFieldConfig, readPhiMediaAssetFieldValue, } from "./media-asset-field";
22
+ import { isPhiMediaAssetFieldSelectable, readPhiMediaAssetFieldConfig, readPhiMediaAssetFieldUploadRefusal, readPhiMediaAssetFieldValue, resolvePhiMediaAssetFieldFolderPath, } from "./media-asset-field";
17
23
  const DEFAULT_LABELS = {
18
24
  choose: "Choose",
19
25
  change: "Change",
@@ -31,6 +37,19 @@ const PREVIEW_SIZE = 72;
31
37
  * value is the Asset id as a number, `null` for none, and the field keeps no copy of it: what it keeps is
32
38
  * the picker's open state.
33
39
  *
40
+ * Inside the picker a file from the reader's machine can go up too, into the Folder the picker shows, by
41
+ * the upload every surface sends with (`usePhiMediaUpload`, Core's upload session); what it made is
42
+ * chosen as a picked tile would be. It goes into the Site Space, like everything the field offers, and
43
+ * Core delivers what goes there publicly. What comes back is asked what a pick is asked: an Asset of
44
+ * another kind (a file the browser could not name reaches Core unrefused) or, for a `publicOnly` field,
45
+ * one that is not public is left in the list unchosen, and the field says why. While the file is on its
46
+ * way the Form's submit is held, as the upload field holds it, and closing the picker stops it.
47
+ * `config.folderPath` names the Folder the picker opens on ("Shop Images / Products"): read in the Site
48
+ * Space each time it opens, without writing anything (`readPhiMediaUploadFolderPathReach`), so a reader
49
+ * who may only choose opens and picks without a refusal; the picker opens on the deepest Folder of the
50
+ * path that is there. An upload from there goes into the whole path, the missing Folders created the way
51
+ * `area-upload` creates them (`resolvePhiMediaUploadFolderPathId`).
52
+ *
34
53
  * Only the Site Space is offered, in every Area (`siteSpaceOnly`): a Form stores a reference everybody
35
54
  * who reads the stored value will follow, and a personal or a group Space cannot honestly stand behind
36
55
  * that. `config.publicOnly` greys out the Assets that are not delivered publicly, from the delivery
@@ -41,13 +60,63 @@ const PREVIEW_SIZE = 72;
41
60
  * field reads (`usePhiAuthoringAssetDetails`), so the preview shows what is stored. Where that read is
42
61
  * refused, the field says so and still lets the value be changed or removed.
43
62
  */
44
- export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readOnly, onChange, }) => {
63
+ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readOnly, onChange, formContext, }) => {
45
64
  const config = useMemo(() => readPhiMediaAssetFieldConfig(field.config), [field.config]);
46
65
  const assetId = readPhiMediaAssetFieldValue(value);
47
66
  const asset = usePhiAuthoringAssetDetails(assetId);
48
67
  const read = (key) => labels?.[PHI_FORM_MEDIA_ASSET_LABEL_KEYS[key]]?.trim() || DEFAULT_LABELS[key];
49
68
  const choose = read("choose");
50
69
  const change = read("change");
70
+ const notPublic = read("notPublic");
71
+ // The upload's refusals and its hold are the upload field's words, read for this field too.
72
+ const refusals = useMemo(() => readPhiFormUploadRefusalLabels(labels), [labels]);
73
+ const pendingLabel = labels?.[PHI_FORM_UPLOAD_LABEL_KEYS.pending]?.trim() || PHI_MEDIA_UPLOAD_FIELD_DEFAULT_LABELS.pending;
74
+ const [uploadNotice, setUploadNotice] = useState(null);
75
+ const acceptance = useMemo(() => ({ kinds: [config.mediaType], multiple: false }), [config.mediaType]);
76
+ const transfer = usePhiMediaUpload({
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;
83
+ useEffect(() => {
84
+ if (!formContext || !uploading)
85
+ return;
86
+ formContext.holdSubmit(field.key, pendingLabel);
87
+ return () => formContext.holdSubmit(field.key, null);
88
+ }, [field.key, formContext, pendingLabel, uploading]);
89
+ /*
90
+ * The start Folder as the Form's values name it when the picker opens (`{key}` placeholders), kept for
91
+ * the upload into it: the path the picker opened on is the path the file goes to.
92
+ */
93
+ const startFolderPath = config.folderPath;
94
+ const startFolderPathRef = useRef([]);
95
+ const openOnFolder = useCallback(async (signal) => {
96
+ const path = resolvePhiMediaAssetFieldFolderPath(startFolderPath, formContext?.getValues() ?? {});
97
+ startFolderPathRef.current = path;
98
+ return path.length > 0 ? readPhiMediaUploadFolderPathReach(path, signal) : { folderId: null, complete: true };
99
+ }, [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]);
51
120
  // The picker's words come from the Media Label Set, which the Form Widget read for this Form
52
121
  // (`resolvePhiFormFieldLabels`); outside a Form that read them, the English defaults stand.
53
122
  const pickerLabels = useMemo(() => {
@@ -76,9 +145,14 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
76
145
  importFailedText: readPicker("importFailedText", base.picker.importFailedText),
77
146
  loadMoreLabel: readPicker("loadMoreLabel", base.picker.loadMoreLabel),
78
147
  },
148
+ upload: {
149
+ ...base.upload,
150
+ uploadToggleLabel: readPicker("uploadLabel", base.upload.uploadToggleLabel),
151
+ refusals,
152
+ },
79
153
  space: { ...base.space, label: readPicker("spaceLabel", base.space.label) },
80
154
  };
81
- }, [assetId, change, choose, labels]);
155
+ }, [assetId, change, choose, labels, refusals]);
82
156
  const picker = usePhiMediaPickerBinding({
83
157
  config: {
84
158
  mediaType: config.mediaType,
@@ -93,6 +167,8 @@ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readO
93
167
  isAssetSelectable: config.publicOnly ? (candidate) => isPhiMediaAssetFieldSelectable(config, candidate) : undefined,
94
168
  onAssetSelect: (picked) => onChange?.(picked.id),
95
169
  onAssetClear: () => onChange?.(null),
170
+ upload,
171
+ openOnFolder: startFolderPath.length > 0 ? openOnFolder : null,
96
172
  });
97
173
  const locked = disabled || readOnly;
98
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) }))] })), config.publicOnly && !readOnly ? (_jsx(PhiTypographyControl, { type: "secondary", children: read("publicOnlyHint") })) : null] }));
@@ -272,7 +272,7 @@ const effectsDescriptors = {
272
272
  columns: transitionColumns,
273
273
  add: {
274
274
  enabled: true,
275
- label: "Add",
275
+ label: label("add", "Add"),
276
276
  defaultRow: {
277
277
  type: "fade",
278
278
  mode: "in",
@@ -316,10 +316,10 @@ const effectsDescriptors = {
316
316
  transitionEasing: "ease-out",
317
317
  },
318
318
  },
319
- remove: { enabled: true, label: "Remove transition" },
319
+ remove: { enabled: true, label: label("removeTransition", "Remove transition") },
320
320
  reorder: true,
321
321
  bordered: true,
322
- emptyText: "No transitions configured.",
322
+ emptyText: label("table.emptyTransitions", "No transitions configured."),
323
323
  layout: { mode: "auto", overflowX: "auto" },
324
324
  },
325
325
  },
@@ -410,7 +410,7 @@ const effectsDescriptors = {
410
410
  columns: viewportColumns,
411
411
  add: {
412
412
  enabled: true,
413
- label: "Add",
413
+ label: label("add", "Add"),
414
414
  defaultRow: {
415
415
  property: "translate",
416
416
  axis: "y",
@@ -448,10 +448,10 @@ const effectsDescriptors = {
448
448
  viewportPerspectivePx: 800,
449
449
  },
450
450
  },
451
- remove: { enabled: true, label: "Remove viewport effect" },
451
+ remove: { enabled: true, label: label("removeViewportEffect", "Remove viewport effect") },
452
452
  reorder: true,
453
453
  bordered: true,
454
- emptyText: "No viewport effects configured.",
454
+ emptyText: label("table.emptyViewportEffects", "No viewport effects configured."),
455
455
  layout: { mode: "auto", overflowX: "auto" },
456
456
  },
457
457
  },
@@ -1,10 +1,15 @@
1
1
  import type { PhiCmsInstanceId } from "../../../../../types/cms-instance-id";
2
+ import { type PhiCollectionViewWidgetLabels } from "../../../../../components/widgets/label-types/collection-view";
2
3
  import type { PhiCmsCollectionViewWidgetConfig } from "../../../../../types/collection-view-widget";
3
4
  import type { PhiRenderableBlockRenderMode } from "../../../../../types/renderable-block";
4
5
  export type PhiCollectionViewWidgetProps = {
5
6
  config?: PhiCmsCollectionViewWidgetConfig | null;
6
7
  widgetId?: PhiCmsInstanceId | null;
7
8
  labels?: unknown;
9
+ /** The Widget's own words (the reorder handle and refusal), loaded where `features.reorder` is on. */
10
+ reorderLabels?: PhiCollectionViewWidgetLabels;
11
+ /** The bound resource's item key path, from its declaration; only where `features.reorder` is on. */
12
+ itemIdentityPath?: string | null;
8
13
  /** Where this draws; the parsed config does not carry it, so the plugin reads it off the node. */
9
14
  renderMode: PhiRenderableBlockRenderMode;
10
15
  preview?: boolean;
@@ -1,7 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createElement } from "react";
3
+ import { createElement, useCallback, useMemo, useState } from "react";
4
4
  import { PhiCollectionViewSkeletonControl } from "../../../../../components/controls/phi-collection-view-control";
5
+ import { PhiCollectionReorderContext } from "../../../../../components/controls/phi-collection-reorder-context";
6
+ import { usePhiCollectionReorderBinding } from "../../../../../components/widgets/client/shared/phi-collection-reorder";
7
+ import { usePhiApplicationFeedback } from "../../../../../components/runtime/use-phi-application-feedback";
8
+ import { PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS, } from "../../../../../components/widgets/label-types/collection-view";
5
9
  import { normalizePhiCssSize } from "../../../../../components/layouts/phi-layout-contract";
6
10
  import { usePhiConfig } from "../../../../../components/root/phi-config-provider";
7
11
  import { usePhiRuntimeModuleState } from "../../../../../components/runtime/runtime-module-context";
@@ -14,6 +18,10 @@ import { usePhiCollectionViewBinding } from "../../../../../components/widgets/c
14
18
  import { PhiCollectionSourceFailureText, readPhiCollectionViewDeclaredFailure, } from "../../../../../components/widgets/shared/collection-source-failure";
15
19
  import { PhiWidgetFailure } from "../../../../../components/widgets/shared/widget-failure-client";
16
20
  import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
21
+ import { usePhiSignalListener } from "../../../../../components/runtime/runtime-signal-bus";
22
+ import { findPhiSignalListenRoute, resolvePhiSignalListenFilter } from "../../../../../helpers/signal-listen-routes";
23
+ import { readPhiTableBindingParamsSignalValue } from "../../../../../types/table-signal-values";
24
+ import { isPhiRecord } from "../../../../../helpers/is-record";
17
25
  /**
18
26
  * The parts of a Collection View a Tour can point at, as `cms:<instanceId>:<part>` (design/TOURS.md): the
19
27
  * filters and search, the toolbar, the items and the pagination. A part the view does not draw is simply
@@ -50,10 +58,35 @@ function PhiCollectionViewWidgetPreview({ config, widgetId, renderMode, skeleton
50
58
  }
51
59
  return (_jsx(PhiCollectionViewSkeletonControl, { mode: presentation?.mode ?? "grid", gap: normalizePhiCssSize(presentation?.gap) ?? token.paddingSM, minColumnWidth: normalizePhiCssSize(presentation?.minColumnWidth) ?? 102, active: skeletonActive }));
52
60
  }
53
- function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, }) {
61
+ function PhiCollectionViewWidgetLive({ config, labels, reorderLabels, itemIdentityPath, widgetId, renderMode, }) {
54
62
  const signalIdentity = usePhiSignalIdentity();
55
63
  usePhiVisualAnchorParts(signalIdentity.receiver?.startsWith("cms:") ? signalIdentity.receiver : null, PHI_COLLECTION_VIEW_VISUAL_ANCHOR_PARTS);
56
- const source = config?.source ?? null;
64
+ /*
65
+ * The binding params, as the Table takes them (`bindingParamsChange`): the configured `source.params`
66
+ * until a received `{ params }` is laid over them, and handed to the Provider as `source.params`. A
67
+ * new set starts the list over -- first page, the initial query, nothing of the old answer shown
68
+ * (`usePhiCollectionViewBinding`). The chosen set is tagged with the configuration it was laid over, so
69
+ * a Builder edit of the configured params is a new starting point.
70
+ */
71
+ const configuredSource = config?.source ?? null;
72
+ const configuredBindingParams = useMemo(() => isPhiRecord(configuredSource?.params) ? configuredSource.params : {}, [configuredSource]);
73
+ const bindingParamsSeed = JSON.stringify(configuredBindingParams);
74
+ const [chosenBindingParams, setChosenBindingParams] = useState(null);
75
+ const bindingParams = chosenBindingParams?.seed === bindingParamsSeed
76
+ ? chosenBindingParams.params
77
+ : configuredBindingParams;
78
+ const source = useMemo(() => configuredSource ? { ...configuredSource, params: bindingParams } : null, [bindingParams, configuredSource]);
79
+ // What the renderer reads of the binding is the source the Provider is asked with.
80
+ const resolvedConfig = useMemo(() => config ? { ...config, source } : config, [config, source]);
81
+ const listenRoutes = useMemo(() => config?.signalRoutes?.listens ?? [], [config?.signalRoutes?.listens]);
82
+ usePhiSignalListener(useCallback((signal) => {
83
+ const route = findPhiSignalListenRoute(listenRoutes, signal, signalIdentity.receiver);
84
+ if (route?.capabilityId !== "bindingParamsChange")
85
+ return;
86
+ const next = readPhiTableBindingParamsSignalValue(signal.value);
87
+ if (next)
88
+ setChosenBindingParams({ seed: bindingParamsSeed, params: { ...bindingParams, ...next.params } });
89
+ }, [bindingParams, bindingParamsSeed, listenRoutes, signalIdentity.receiver]), useMemo(() => resolvePhiSignalListenFilter(listenRoutes), [listenRoutes]), signalIdentity.receiver);
57
90
  const { resource, bindingError, queryError, binding } = usePhiCollectionViewBinding({
58
91
  source,
59
92
  initialQuery: config?.initialQuery,
@@ -62,6 +95,19 @@ function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, })
62
95
  // The provider ships a renderer with its resource; a Site may name another Module's instead. Both are
63
96
  // ordinary Render Clients, so neither side has to know the other exists.
64
97
  const rendererKey = config?.itemRendererKey ?? resource?.itemRendererKey ?? null;
98
+ /*
99
+ * Drag reordering (`features.reorder`) goes around whatever the renderer draws: the renderer gets the
100
+ * binding with the items in the dropped order while the Provider writes it, and its Collection Control
101
+ * puts the handles on (`PhiCollectionReorderContext`). The Widget keeps no order of its own.
102
+ */
103
+ const { showMessage } = usePhiApplicationFeedback();
104
+ const { binding: presentedBinding, reorder } = usePhiCollectionReorderBinding({
105
+ config: resolvedConfig,
106
+ binding,
107
+ itemIdentityPath: itemIdentityPath ?? null,
108
+ labels: reorderLabels ?? PHI_COLLECTION_VIEW_WIDGET_DEFAULT_LABELS,
109
+ showMessage,
110
+ });
65
111
  const ItemRenderer = usePhiRuntimeModuleRenderClient(rendererKey);
66
112
  usePhiControlSignalController({
67
113
  key: "collectionReload",
@@ -92,7 +138,7 @@ function PhiCollectionViewWidgetLive({ config, labels, widgetId, renderMode, })
92
138
  // component in tag position reads to React -- and to `react-hooks/static-components` -- as a new
93
139
  // component per render. This is the same call `PhiRuntimeModuleRenderClientHost` makes for a Widget.
94
140
  // `renderMode` goes along so a renderer's own configuration failures are said the same way.
95
- return createElement(ItemRenderer, { config, binding, labels, widgetId, renderMode });
141
+ return (_jsx(PhiCollectionReorderContext.Provider, { value: reorder, children: createElement(ItemRenderer, { config: resolvedConfig ?? config, binding: presentedBinding, labels, widgetId, renderMode }) }));
96
142
  }
97
143
  export function PhiCollectionViewWidget(props) {
98
144
  return props.preview
@@ -28,12 +28,19 @@ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFINITION: {
28
28
  valueSchema: `${string}/signals/${string}`;
29
29
  valueSchemaFrom?: undefined;
30
30
  })[];
31
- listens: {
31
+ listens: ({
32
32
  id: string;
33
33
  channel: string;
34
34
  action: "activate";
35
35
  valueType: "none";
36
- }[];
36
+ valueSchema?: undefined;
37
+ } | {
38
+ id: string;
39
+ channel: string;
40
+ action: "change";
41
+ valueType: "json";
42
+ valueSchema: `${string}/signals/${string}`;
43
+ })[];
37
44
  };
38
45
  fields: ({
39
46
  key: string;
@@ -338,6 +345,25 @@ export declare const PHI_COLLECTION_VIEW_WIDGET_DEFINITION: {
338
345
  options?: undefined;
339
346
  min?: undefined;
340
347
  precision?: undefined;
348
+ } | {
349
+ key: string;
350
+ type: "string";
351
+ label: string;
352
+ placeholder: string;
353
+ providerKind?: undefined;
354
+ presentation?: undefined;
355
+ optionsProvider?: undefined;
356
+ emptyOption?: undefined;
357
+ emptyValue?: undefined;
358
+ options?: undefined;
359
+ min?: undefined;
360
+ itemKeyField?: undefined;
361
+ itemLabelField?: undefined;
362
+ addLabel?: undefined;
363
+ emptyLabel?: undefined;
364
+ defaultItem?: undefined;
365
+ itemFields?: undefined;
366
+ precision?: undefined;
341
367
  } | {
342
368
  key: string;
343
369
  type: "number";