@phis/ui 0.7.1 → 0.7.2

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 (46) 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/use-phi-color-control-presets.d.ts +2 -2
  4. package/components/controls/use-phi-color-control-presets.js +16 -2
  5. package/components/layouts/clients/phi-flex-layout-client.js +12 -2
  6. package/components/media/media-folder-name-path.d.ts +17 -0
  7. package/components/media/media-folder-name-path.js +36 -0
  8. package/components/media/media-upload-flow.d.ts +30 -0
  9. package/components/media/media-upload-flow.js +104 -4
  10. package/components/media/media-upload-refusals.js +5 -2
  11. package/components/media/phi-area-upload-widget.js +4 -0
  12. package/components/widgets/client/shared/phi-command-buttons.d.ts +12 -0
  13. package/components/widgets/client/shared/phi-command-buttons.js +23 -3
  14. package/components/widgets/config/command-buttons.js +3 -0
  15. package/components/widgets/label-sets/color-picker.js +2 -0
  16. package/components/widgets/label-types/color-picker.d.ts +1 -0
  17. package/components/widgets/label-types/color-picker.js +1 -0
  18. package/helpers/cms-content-binding.d.ts +7 -1
  19. package/helpers/cms-content-binding.js +10 -2
  20. package/helpers/cms-node-visibility.d.ts +25 -0
  21. package/helpers/cms-node-visibility.js +35 -1
  22. package/package.json +2 -2
  23. package/plugins/runtime-modules/accounting/definition.js +1 -1
  24. package/plugins/runtime-modules/accounting/presets.js +5 -12
  25. package/plugins/runtime-modules/area-definitions.d.ts +9 -39
  26. package/plugins/runtime-modules/area-definitions.js +8 -8
  27. package/plugins/runtime-modules/asset/controller/runtime.js +1 -6
  28. package/plugins/runtime-modules/asset/widgets/area-upload/config.js +7 -1
  29. package/plugins/runtime-modules/builder/data-providers.js +1 -0
  30. package/plugins/runtime-modules/builder/services/runtime-modules-table.d.ts +1 -0
  31. package/plugins/runtime-modules/builder/services/runtime-modules-table.js +4 -0
  32. package/plugins/runtime-modules/builder/trees/phi-default-builder-area-preset-tree.js +6 -5
  33. package/plugins/runtime-modules/core/widgets/image/config.d.ts +1 -0
  34. package/plugins/runtime-modules/core/widgets/image/config.js +1 -0
  35. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +1 -1
  36. package/plugins/runtime-modules/core/widgets/markdown/config.js +1 -0
  37. package/plugins/runtime-modules/core/widgets/markdown/plugin.js +0 -1
  38. package/plugins/runtime-modules/core/widgets/simple-text/config.d.ts +1 -0
  39. package/plugins/runtime-modules/core/widgets/simple-text/config.js +1 -0
  40. package/plugins/runtime-modules/core/widgets/table/client.js +8 -1
  41. package/server-helpers/cms-node-record.d.ts +18 -0
  42. package/server-helpers/cms-node-record.js +28 -0
  43. package/types/cms-plugins.d.ts +6 -0
  44. package/types/core-widget-placements.d.ts +6 -0
  45. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.d.ts +0 -6
  46. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-page-tree.js +0 -49
@@ -51,6 +51,7 @@ export type PhiCmsOverlayRenderContext = {
51
51
  signalRuntime: PhiRenderableBlockRuntime;
52
52
  features: PhiRuntimeFeatureState | null;
53
53
  featureFailures: ReadonlyMap<string, string>;
54
+ recordFields: Readonly<Record<string, unknown>> | null;
54
55
  links: Awaited<ReturnType<typeof resolvePhiCmsTreeLinkTargets>>;
55
56
  };
56
57
  export declare function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }: {
@@ -20,7 +20,7 @@ import { splitPhiCmsLayoutNamespacedTypeKey } from "../../constants/cms-layout-t
20
20
  import { createPhiSignalAddress, readPhiSignalRouteSet, } from "../../types/signals";
21
21
  import { readPhiRuntimeTreeRenderMode, resolvePhiRuntimeWidgetImplementationMode, } from "../../plugins/runtime-modules/render-mode";
22
22
  import { filterPhiCmsRenderableTreeForViewer } from "../../helpers/cms-access-policy";
23
- import { collectPhiCmsNodeFeatureNamespaces, readPhiCmsNodeVisibleWhen, readPhiCmsServerPageConditionState, resolvePhiCmsNodeVisibility, } from "../../helpers/cms-node-visibility";
23
+ import { collectPhiCmsNodeFeatureNamespaces, readPhiCmsNodeVisibleWhen, readPhiCmsServerPageConditionState, resolvePhiCmsNodeVisibility, settlePhiCmsNodeRecordConditions, } from "../../helpers/cms-node-visibility";
24
24
  import { logRuntimeEvent } from "../../net/log";
25
25
  import { PhiCmsNodeVisibilityGate } from "./clients/phi-cms-node-visibility-gate";
26
26
  import { PhiRuntimeModuleRenderClientHost } from "../runtime/runtime-module-render-client-manifest";
@@ -39,6 +39,11 @@ async function resolvePhiCmsTreeFeatures(...args) {
39
39
  const { resolvePhiCmsTreeFeatures: resolve } = await import("../../server-helpers/cms-node-features");
40
40
  return resolve(...args);
41
41
  }
42
+ /* The fields a `record` condition reads, loaded the same way and for the same reason. */
43
+ async function resolvePhiCmsTreeRecordConditionFields(...args) {
44
+ const { resolvePhiCmsTreeRecordConditionFields: resolve } = await import("../../server-helpers/cms-node-record");
45
+ return resolve(...args);
46
+ }
42
47
  /**
43
48
  * What a Layout that `translatesOwnText` is handed to translate the text in its config with -- the
44
49
  * Collapsible's panel titles. The node's `NoTranslate` flag is the switch, as for a Widget, and the
@@ -285,8 +290,9 @@ function buildLayoutTree(tree, blockDefaultsByType) {
285
290
  });
286
291
  }
287
292
  export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registry, signalScope, }) {
288
- const [featureResolution, links, translatedTree] = await Promise.all([
293
+ const [featureResolution, recordFields, links, translatedTree] = await Promise.all([
289
294
  resolvePhiCmsTreeFeatures(tree, registry, runtime),
295
+ resolvePhiCmsTreeRecordConditionFields(tree, registry, runtime),
290
296
  resolvePhiCmsTreeLinkTargets(tree, runtime),
291
297
  translatePhiCmsTreeWidgetTexts(tree, registry, runtime),
292
298
  ]);
@@ -308,6 +314,7 @@ export async function preparePhiCmsOverlayRenderContext({ tree, runtime, registr
308
314
  },
309
315
  features: featureResolution.features,
310
316
  featureFailures: featureResolution.failures,
317
+ recordFields,
311
318
  links,
312
319
  };
313
320
  }
@@ -340,6 +347,7 @@ export function renderPhiCmsOverlayZones(context, overlay) {
340
347
  signalParticipants,
341
348
  features: context.features,
342
349
  featureFailures: context.featureFailures,
350
+ recordFields: context.recordFields,
343
351
  links: context.links,
344
352
  }), {
345
353
  kind: "layout",
@@ -418,7 +426,11 @@ function renderContentWidget(widget, context) {
418
426
  : null;
419
427
  const widgetPlugin = runtimePlugin ?? previewPlugin;
420
428
  // Bound content that was never published is not on the live Site, and neither is its Widget.
421
- if (renderMode === "live" && widgetPlugin && isPhiCmsWidgetContentUnpublished(widgetPlugin.contentBinding, widget)) {
429
+ if (renderMode === "live" &&
430
+ widgetPlugin &&
431
+ isPhiCmsWidgetContentUnpublished(widgetPlugin.contentBinding, widget, {
432
+ aboutRecord: context.runtime.page?.record != null,
433
+ })) {
422
434
  return null;
423
435
  }
424
436
  if (widgetPlugin) {
@@ -568,13 +580,26 @@ function wrapPhiRenderedSlotChild(node, options) {
568
580
  slotChildSizing: resolvePhiSlotChildSizingForConfig(options.kind, options.slotSizePolicy, options.config), visibleWhen: options.visibleWhen, receiver: options.blockId != null ? createPhiSignalAddress("cms", options.blockId) : null, page: options.page ?? null, features: options.features ?? null, children: framed }, options.key))
569
581
  : framed;
570
582
  }
583
+ /**
584
+ * A child's condition with its `record` parts answered here (`settlePhiCmsNodeRecordConditions`), or
585
+ * `false` where they already rule the child out. The live Site leaves out a node that asks about a record
586
+ * the Page is not about; a Preview or the canvas draws it.
587
+ */
588
+ function readRenderedChildVisibleWhen(child, context) {
589
+ return settlePhiCmsNodeRecordConditions(readPhiCmsNodeVisibleWhen(child.config), {
590
+ fields: context.recordFields,
591
+ live: readPhiRuntimeTreeRenderMode(child.config) === "live",
592
+ });
593
+ }
571
594
  function buildRenderedChildEntries(node, context) {
572
595
  const page = readPhiCmsServerPageConditionState(context.runtime);
573
596
  const features = context.features;
574
597
  const failures = context.featureFailures;
575
598
  return [
576
599
  ...node.childLayouts.flatMap((child) => {
577
- const visibleWhen = readPhiCmsNodeVisibleWhen(child.config);
600
+ const visibleWhen = readRenderedChildVisibleWhen(child, context);
601
+ if (visibleWhen === false)
602
+ return [];
578
603
  const visibility = resolvePhiCmsNodeVisibility(visibleWhen, page, features);
579
604
  if (visibility === "omit")
580
605
  return [];
@@ -614,7 +639,9 @@ function buildRenderedChildEntries(node, context) {
614
639
  }];
615
640
  }),
616
641
  ...node.childWidgets.flatMap((child) => {
617
- const visibleWhen = readPhiCmsNodeVisibleWhen(child.config);
642
+ const visibleWhen = readRenderedChildVisibleWhen(child, context);
643
+ if (visibleWhen === false)
644
+ return [];
618
645
  const visibility = resolvePhiCmsNodeVisibility(visibleWhen, page, features);
619
646
  if (visibility === "omit")
620
647
  return [];
@@ -762,8 +789,9 @@ export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, reg
762
789
  viewer: runtime.viewer,
763
790
  registry,
764
791
  });
765
- const [{ features, failures: featureFailures }, links, filteredTree] = await Promise.all([
792
+ const [{ features, failures: featureFailures }, recordFields, links, filteredTree] = await Promise.all([
766
793
  resolvePhiCmsTreeFeatures(viewerTree, registry, runtime),
794
+ resolvePhiCmsTreeRecordConditionFields(viewerTree, registry, runtime),
767
795
  resolvePhiCmsTreeLinkTargets(viewerTree, runtime),
768
796
  translatePhiCmsTreeWidgetTexts(viewerTree, registry, runtime),
769
797
  ]);
@@ -798,6 +826,7 @@ export async function PhiCmsLayoutRenderer({ tree, runtime, regionClassName, reg
798
826
  signalParticipants,
799
827
  features,
800
828
  featureFailures,
829
+ recordFields,
801
830
  links,
802
831
  }), {
803
832
  kind: "layout",
@@ -6,8 +6,8 @@ export type PhiColorControlCustomColor = {
6
6
  value: string;
7
7
  };
8
8
  /**
9
- * The colour picker's swatches: the Theme's custom colours, its primary and text ladders, then the fixed
10
- * palettes.
9
+ * The colour picker's swatches: the Theme's custom colours, its primary ladder, its status colours and its
10
+ * text ladder, then the fixed palettes.
11
11
  *
12
12
  * With `storeThemeRoles`, a Theme swatch stores the role it shows (`PHI_COLOR.custom3`,
13
13
  * `PHI_COLOR.primaryBg`) rather than its colour, so what an author picks follows the Theme and the mode.
@@ -16,6 +16,13 @@ const PHI_PRIMARY_COLOR_TOKEN_KEYS = [
16
16
  "colorPrimaryText",
17
17
  "colorPrimaryTextActive",
18
18
  ];
19
+ /* What a colour says rather than what it looks like: done, careful, wrong, of note -- as Alerts and Tags say it. */
20
+ const PHI_STATUS_COLOR_TOKEN_KEYS = [
21
+ "colorSuccess",
22
+ "colorWarning",
23
+ "colorError",
24
+ "colorInfo",
25
+ ];
19
26
  const PHI_TEXT_COLOR_TOKEN_KEYS = [
20
27
  "colorTextBase",
21
28
  "colorText",
@@ -33,8 +40,8 @@ function resolvePhiColorTokenReference(tokenKey) {
33
40
  return `var(--phi-${tokenKey.replace(/[A-Z]/gu, (letter) => `-${letter.toLowerCase()}`)})`;
34
41
  }
35
42
  /**
36
- * The colour picker's swatches: the Theme's custom colours, its primary and text ladders, then the fixed
37
- * palettes.
43
+ * The colour picker's swatches: the Theme's custom colours, its primary ladder, its status colours and its
44
+ * text ladder, then the fixed palettes.
38
45
  *
39
46
  * With `storeThemeRoles`, a Theme swatch stores the role it shows (`PHI_COLOR.custom3`,
40
47
  * `PHI_COLOR.primaryBg`) rather than its colour, so what an author picks follows the Theme and the mode.
@@ -70,6 +77,13 @@ export function usePhiColorControlPresets({ labels = PHI_COLOR_PICKER_DEFAULT_LA
70
77
  colorLabels: [...PHI_PRIMARY_COLOR_TOKEN_KEYS],
71
78
  ...(storeThemeRoles ? { colorReferences: PHI_PRIMARY_COLOR_TOKEN_KEYS.map(resolvePhiColorTokenReference) } : {}),
72
79
  },
80
+ {
81
+ key: "phi-status",
82
+ label: labels.colors.status,
83
+ colors: PHI_STATUS_COLOR_TOKEN_KEYS.map((key) => token[key]),
84
+ colorLabels: [...PHI_STATUS_COLOR_TOKEN_KEYS],
85
+ ...(storeThemeRoles ? { colorReferences: PHI_STATUS_COLOR_TOKEN_KEYS.map(resolvePhiColorTokenReference) } : {}),
86
+ },
73
87
  {
74
88
  key: "phi-text",
75
89
  label: labels.colors.text,
@@ -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,14 @@ 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`. A setting holds the path and not an id, because
199
+ * a preset states the same path on every Site, and it is resolved to the Folder's id each time a session
200
+ * is begun, never kept resolved (`resolvePhiMediaUploadFolderPathId`). Where it is given it stands in
201
+ * for `folderId` and for `spaceAddress`: a path is read in the Site Space, whatever Space is in view.
202
+ */
203
+ folderPath?: readonly string[] | null;
196
204
  presentationFlags?: number | null;
197
205
  /**
198
206
  * The Space the surface is currently reading, as the control plane named it.
@@ -218,13 +226,35 @@ export type PhiMediaUploadContext = {
218
226
  * The Space is inherited whole and separately, because it is not a filter a panel owns: it is the Space
219
227
  * the control plane said it served. An upload started while looking at a group's library therefore goes
220
228
  * to that group instead of silently to the Site Space.
229
+ *
230
+ * A Folder the Widget's own setting names (`configFolderPath`, "Shop Images / Products") is the one
231
+ * exception to inheriting: it is where this Widget puts what it takes, whichever Folder the panel or the
232
+ * Controller has open, and it is a Folder of the Site Space. It travels as the path; the session resolves
233
+ * it. The flags are inherited as before. A blank setting is no setting.
221
234
  */
222
235
  export declare function resolvePhiMediaUploadInitOptions(input: {
223
236
  collectionContext?: PhiMediaUploadContext | null;
224
237
  previewState: PhiMediaUploadContext;
225
238
  configPresentationFlags?: number | null;
239
+ configFolderPath?: string | null;
226
240
  activeSpaceAddress?: string | null;
227
241
  }): PhiMediaUploadInitOptions;
242
+ /**
243
+ * The id of the Site Space's Folder a path of names leads to, the Folders it names that are not there yet
244
+ * created on the way, below the deepest one that is.
245
+ *
246
+ * Read afresh for every session rather than kept, because a Folder is renamed, moved or deleted between
247
+ * two uploads and the path is what the setting means. Creating is what makes a preset's Folder work on a
248
+ * Site that has never had it: the first upload brings it into being, with the same authority the upload
249
+ * itself needs, since writing into the Site Space is Media administration either way. A locked Folder on
250
+ * the way is not written into: Core refuses the new Folder (`media_folder_locked`) or the upload
251
+ * (`folder_locked`), and both read as the lock refusal.
252
+ *
253
+ * Two files dropped at once ask for the same path at once. They share one resolution, which is not
254
+ * stopped by either of them: a Folder half created is not worth stopping for, and the other file still
255
+ * needs it. Each caller stops waiting for itself.
256
+ */
257
+ export declare function resolvePhiMediaUploadFolderPathId(folderPath: readonly string[], signal?: AbortSignal): Promise<number>;
228
258
  export declare function initPhiMediaUploadSession(file: File, options?: PhiMediaUploadInitOptions, signal?: AbortSignal): Promise<PhiMediaUploadInitSession>;
229
259
  export declare function uploadPhiMediaUploadBody(plan: PhiMediaUploadPlan, file: File, onProgress?: PhiMediaUploadProgressHandler,
230
260
  /** 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,100 @@ 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
+ async function createPhiMediaUploadFolderPath(folderPath) {
388
+ const listing = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
389
+ headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
390
+ cache: "no-store",
391
+ }));
392
+ const reached = findPhiMediaFolderByNamePath(readPhiMediaUploadFolderPathFolders(listing.folders), folderPath);
393
+ let folderId = reached.folderId;
394
+ for (const name of folderPath.slice(reached.depth)) {
395
+ const body = new FormData();
396
+ body.set("name", name);
397
+ if (folderId != null)
398
+ body.set("parentId", String(folderId));
399
+ const created = await readJsonResponse(await fetch(PHI_MEDIA_FOLDERS_PATH, {
400
+ method: "POST",
401
+ headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
402
+ cache: "no-store",
403
+ body,
404
+ }));
405
+ const createdId = created.folder?.id;
406
+ if (typeof createdId !== "number" || !Number.isInteger(createdId) || createdId <= 0) {
407
+ throw new PhiMediaUploadError("The media folders route answered a created Folder without its id.", null, 500);
408
+ }
409
+ folderId = createdId;
410
+ }
411
+ if (folderId == null) {
412
+ throw new PhiMediaUploadError("An empty Folder path names no Folder.", null, 400);
413
+ }
414
+ return folderId;
415
+ }
319
416
  export async function initPhiMediaUploadSession(file, options, signal) {
320
- const folderId = Number.isInteger(options?.folderId) && (options?.folderId ?? 0) > 0
321
- ? options?.folderId
322
- : null;
417
+ const folderPath = options?.folderPath?.length ? options.folderPath : null;
418
+ const folderId = folderPath
419
+ ? await resolvePhiMediaUploadFolderPathId(folderPath, signal)
420
+ : Number.isInteger(options?.folderId) && (options?.folderId ?? 0) > 0
421
+ ? options?.folderId
422
+ : null;
323
423
  const presentationFlags = Number.isInteger(options?.presentationFlags) && (options?.presentationFlags ?? 0) >= 0 ? options?.presentationFlags : null;
324
424
  const meta = isPhiRecord(options?.meta)
325
425
  ? options.meta
326
426
  : null;
327
427
  // The Space is named the way every Media route names one -- as a query parameter -- while the Folder
328
428
  // 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;
429
+ const spaceAddress = folderPath ? null : options?.spaceAddress?.trim() || null;
330
430
  /*
331
431
  * Hashed before the session is asked for, because the Server signs the digest into the upload request
332
432
  * 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,
@@ -2,6 +2,7 @@ import type { PhiCmsInstanceId } from "../../../../types/cms-instance-id";
2
2
  import type { PhiCommandButtonConfig } from "../../../../types/core-widget-placements";
3
3
  import { type PhiSignalRouteSet } from "../../../../types/signals";
4
4
  import type { PhiToolbarControlItem } from "../../../controls/phi-toolbar-control";
5
+ import { type PhiButtonVariant } from "../../config/button-variant";
5
6
  import type { PhiCommonControlLabels } from "../../label-types/common-controls";
6
7
  export type PhiCommandButtonsOptions = {
7
8
  buttons: readonly PhiCommandButtonConfig[];
@@ -17,4 +18,15 @@ export type PhiCommandButtonsResult = {
17
18
  disabled: boolean;
18
19
  activate: (buttonKey: string) => void;
19
20
  };
21
+ /**
22
+ * How a command button stands out: its own variant where it states one, else its action's.
23
+ *
24
+ * An action answers for a button's words; its look is only the default. Save is a plain button on a
25
+ * Builder toolbar, and the one a dialog's footer leads with -- the footer says `variant: "primary"`
26
+ * beside `action: "save"`, and that is what it means. The Inspector clears the variant when an action is
27
+ * picked, so a button authored there keeps its action's look.
28
+ */
29
+ export declare function resolvePhiCommandButtonVariant(button: Pick<PhiCommandButtonConfig, "variant">, action: {
30
+ variant?: PhiButtonVariant;
31
+ } | null | undefined): PhiButtonVariant | undefined;
20
32
  export declare function usePhiCommandButtons({ buttons, signalRoutes, blockId, labels, disabled, signalsEnabled, }: PhiCommandButtonsOptions): PhiCommandButtonsResult;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createElement, useCallback, useEffect, useMemo, useState } from "react";
3
3
  import { createPhiSignalSubcontrolAddress, findPhiSignalRoutesByCapabilityId, } from "../../../../types/signals";
4
4
  import { usePhiSignalListener } from "../../../runtime/runtime-signal-bus";
5
5
  import { usePhiSignalEmitter, usePhiSignalIdentity } from "../../../runtime/runtime-signal-identity";
@@ -54,6 +54,26 @@ function resolveButtonBadge(button, runtimeBadge) {
54
54
  showZero: button.badgeShowZero,
55
55
  };
56
56
  }
57
+ /**
58
+ * How a command button stands out: its own variant where it states one, else its action's.
59
+ *
60
+ * An action answers for a button's words; its look is only the default. Save is a plain button on a
61
+ * Builder toolbar, and the one a dialog's footer leads with -- the footer says `variant: "primary"`
62
+ * beside `action: "save"`, and that is what it means. The Inspector clears the variant when an action is
63
+ * picked, so a button authored there keeps its action's look.
64
+ */
65
+ export function resolvePhiCommandButtonVariant(button, action) {
66
+ return button.variant ?? action?.variant;
67
+ }
68
+ /*
69
+ * The icon in its own colour, where the button names one: the glyph takes `currentColor`, so a span
70
+ * around it colours the icon and leaves the button's words and frame as its variant draws them.
71
+ */
72
+ function colorPhiCommandButtonIcon(icon, color) {
73
+ if (!color || icon == null)
74
+ return icon;
75
+ return createElement("span", { style: { display: "inline-flex", color } }, icon);
76
+ }
57
77
  export function usePhiCommandButtons({ buttons, signalRoutes, blockId, labels, disabled, signalsEnabled = true, }) {
58
78
  const signalIdentity = usePhiSignalIdentity();
59
79
  const signalPartition = usePhiSignalRuntimePartition();
@@ -276,12 +296,12 @@ export function usePhiCommandButtons({ buttons, signalRoutes, blockId, labels, d
276
296
  * A toolbar draws its buttons by primitive type alone, so a `gradient` command button stands as the
277
297
  * primary one it is underneath and a `glass` one as the plain one.
278
298
  */
279
- type: resolvePhiButtonVariantPresentation(action ? action.variant : button.variant).type ?? "default",
299
+ type: resolvePhiButtonVariantPresentation(resolvePhiCommandButtonVariant(button, action)).type ?? "default",
280
300
  danger: action ? action.danger === true : button.danger === true,
281
301
  disabled: button.disabled === true || buttonState.enabled === false,
282
302
  readOnly: button.readOnly === true,
283
303
  loading: buttonState.loading,
284
- icon: button.display === "label" ? null : resolvedIcon,
304
+ icon: button.display === "label" ? null : colorPhiCommandButtonIcon(resolvedIcon, button.iconColor),
285
305
  visible: buttonState.visible,
286
306
  badge: resolveButtonBadge(button, buttonState.badge),
287
307
  };
@@ -50,6 +50,7 @@ function readCommandButtonConfig(reader) {
50
50
  label: readPhiControlLabel(reader.record.label),
51
51
  tooltip: reader.string("tooltip"),
52
52
  icon: reader.string("icon"),
53
+ iconColor: reader.string("iconColor"),
53
54
  display: reader.oneOf("display", ["icon", "label", "icon-label"]),
54
55
  danger: reader.boolean("danger"),
55
56
  disabled: reader.boolean("disabled"),
@@ -142,6 +143,8 @@ export function buildPhiCommandButtonsField({ omit = [], labelVisibleWhen, extra
142
143
  },
143
144
  { key: "tooltip", type: "string", label: "Tooltip" },
144
145
  { key: "icon", type: "icon", label: "Icon" },
146
+ // Left empty, the button's own colour, which follows its variant and Danger.
147
+ { key: "iconColor", type: "color", label: "Icon color", mode: "single" },
145
148
  ...extraItemFields,
146
149
  ...(omitted.has("danger") ? [] : [{ key: "danger", type: "boolean", label: "Danger" }]),
147
150
  { key: "readOnly", type: "boolean", label: "Read only" },
@@ -8,6 +8,7 @@ const PHI_COLOR_PICKER_LABEL_SET = definePhiLabelSet({
8
8
  labels: {
9
9
  custom: PHI_COLOR_PICKER_DEFAULT_LABELS.custom,
10
10
  color_primary: PHI_COLOR_PICKER_DEFAULT_LABELS.colors.primary,
11
+ color_status: PHI_COLOR_PICKER_DEFAULT_LABELS.colors.status,
11
12
  color_text: PHI_COLOR_PICKER_DEFAULT_LABELS.colors.text,
12
13
  color_red: PHI_COLOR_PICKER_DEFAULT_LABELS.colors.red,
13
14
  color_volcano: PHI_COLOR_PICKER_DEFAULT_LABELS.colors.volcano,
@@ -30,6 +31,7 @@ export async function getPhiColorPickerLabels(options) {
30
31
  custom: labels.custom,
31
32
  colors: {
32
33
  primary: labels.color_primary,
34
+ status: labels.color_status,
33
35
  text: labels.color_text,
34
36
  red: labels.color_red,
35
37
  volcano: labels.color_volcano,
@@ -2,6 +2,7 @@ export type PhiColorPickerLabels = {
2
2
  custom: string;
3
3
  colors: {
4
4
  primary: string;
5
+ status: string;
5
6
  text: string;
6
7
  red: string;
7
8
  volcano: string;
@@ -2,6 +2,7 @@ export const PHI_COLOR_PICKER_DEFAULT_LABELS = {
2
2
  custom: "Custom",
3
3
  colors: {
4
4
  primary: "Primary",
5
+ status: "Status",
5
6
  text: "Text",
6
7
  red: "Red",
7
8
  volcano: "Volcano",
@@ -9,5 +9,11 @@ export declare function resolvePhiCmsWidgetContentBindingForConfig(binding: PhiC
9
9
  * Whether a bound Widget has nothing to show on the live Site: no published content and no value of its
10
10
  * own. That is a Widget the Site created whose content was never published -- the Builder's placeholder
11
11
  * is not live until somebody publishes it. A preset node keeps its shipped value and is never empty.
12
+ *
13
+ * A Widget that names a field of the page record (`binding.recordField`) on a Page about a record is
14
+ * not judged: it shows the record's field there, not content of its own, and draws nothing itself where
15
+ * the record lacks the field. Its own content only stands in on a Page about no record, and is judged there.
12
16
  */
13
- export declare function isPhiCmsWidgetContentUnpublished(binding: PhiCmsWidgetContentBinding | null | undefined, widget: Pick<PhiCmsContentWidgetNode, "config" | "resolvedContent">): boolean;
17
+ export declare function isPhiCmsWidgetContentUnpublished(binding: PhiCmsWidgetContentBinding | null | undefined, widget: Pick<PhiCmsContentWidgetNode, "config" | "resolvedContent">, page: {
18
+ aboutRecord: boolean;
19
+ }): boolean;