@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
@@ -17,7 +17,7 @@ import { buildPhiMediaSpaceOptions, usePhiMediaSpaceSelectionAllowed, } from "./
17
17
  import { isPhiRecord } from "../../helpers/is-record";
18
18
  import { readPhiMediaSourceImportErrorMessage, usePhiMediaSources, } from "./phi-media-sources";
19
19
  import { usePhiCollectionProviderAction } from "../widgets/client/shared/phi-collection-provider";
20
- export function usePhiMediaPickerBinding({ config, labels, searchLabels, value: controlledValue, onAssetSelect, onAssetClear, open: controlledOpen, onOpenChange, onCommit, onDiscard, onPopupOpenChange, trigger, getPopupContainer, popupRootClassName, siteSpaceOnly = false, isAssetSelectable, }) {
20
+ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value: controlledValue, onAssetSelect, onAssetClear, open: controlledOpen, onOpenChange, onCommit, onDiscard, onPopupOpenChange, trigger, getPopupContainer, popupRootClassName, siteSpaceOnly = false, isAssetSelectable, upload, openOnFolder, }) {
21
21
  const [localOpen, setLocalOpen] = useState(false);
22
22
  const [localValue, setLocalValue] = useState(controlledValue ?? null);
23
23
  const [searchQuery, setSearchQuery] = useState("");
@@ -49,6 +49,17 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
49
49
  const [sourceFailed, setSourceFailed] = useState(false);
50
50
  const [importingItemId, setImportingItemId] = useState(null);
51
51
  const [importFailure, setImportFailure] = useState(null);
52
+ // True while the Folder the picker opens on is being asked for; the listing waits for it.
53
+ const [startFolderPending, setStartFolderPending] = useState(false);
54
+ const [startFolderFailure, setStartFolderFailure] = useState(null);
55
+ // The picker stands where `openOnFolder` put it, and the path it was asked for goes further.
56
+ const [onIncompleteStartFolder, setOnIncompleteStartFolder] = useState(false);
57
+ const startFolderRequestRef = useRef(null);
58
+ // The host's upload as of the last render, for the close below, which must not run again per render.
59
+ const uploadRef = useRef(upload);
60
+ useEffect(() => {
61
+ uploadRef.current = upload;
62
+ }, [upload]);
52
63
  const sourceRequestRef = useRef(null);
53
64
  const importRequestRef = useRef(null);
54
65
  const [total, setTotal] = useState(0);
@@ -99,7 +110,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
99
110
  },
100
111
  }), [presentationFlags, folderId, mediaType, page, pageSize, requestedSpaceAddress, searchQuery, spaceSelectionAllowed]);
101
112
  const querySignals = usePhiControlSignalController({ key: PHI_ASSET_SIGNAL_CHANNELS.query, signalRoutes: config?.signalRoutes, valueType: "string", typeKey: "media-picker-query", clearValue: "", onSetValue: (next) => { setSearchQuery(next); setPage(1); }, coerceValue: (next) => typeof next === "string" ? next : null });
102
- const pathSignals = usePhiControlSignalController({ key: PHI_ASSET_SIGNAL_CHANNELS.path, signalRoutes: config?.signalRoutes, valueType: "path", typeKey: "media-picker-path", clearValue: "/", onSetValue: (next) => { setFolderId(resolvePhiMediaFolderIdFromValue(folders, next)); setPage(1); }, coerceValue: (next) => typeof next === "string" ? next : null });
113
+ const pathSignals = usePhiControlSignalController({ key: PHI_ASSET_SIGNAL_CHANNELS.path, signalRoutes: config?.signalRoutes, valueType: "path", typeKey: "media-picker-path", clearValue: "/", onSetValue: (next) => { setFolderId(resolvePhiMediaFolderIdFromValue(folders, next)); setOnIncompleteStartFolder(false); setPage(1); }, coerceValue: (next) => typeof next === "string" ? next : null });
103
114
  const reloadSignals = usePhiControlSignalController({ key: PHI_ASSET_SIGNAL_CHANNELS.reload, signalRoutes: config?.signalRoutes, typeKey: "media-picker-reload", onReceiveCapability: (capabilityId) => { if (capabilityId !== "reload")
104
115
  return false; setRefreshToken((current) => current + 1); return true; } });
105
116
  const kindSignals = usePhiControlSignalController({ key: PHI_ASSET_SIGNAL_CHANNELS.kind, signalRoutes: config?.signalRoutes, valueType: "string", typeKey: "media-picker-kind", coerceValue: (next) => typeof next === "string" ? next : null });
@@ -116,6 +127,9 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
116
127
  // The source's items stand where the library's tiles do; the library is read again when it comes back.
117
128
  if (activeSource)
118
129
  return;
130
+ // The Folder it opens on is not known yet; reading the root first would ask twice.
131
+ if (startFolderPending)
132
+ return;
119
133
  const abortController = new AbortController();
120
134
  const load = async () => {
121
135
  setLoading(true);
@@ -161,7 +175,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
161
175
  };
162
176
  void load();
163
177
  return () => abortController.abort();
164
- }, [activeSource, isOpen, locale, provider, query, refreshToken, source, timeZone]);
178
+ }, [activeSource, isOpen, locale, provider, query, refreshToken, source, startFolderPending, timeZone]);
165
179
  const activeSourceId = activeSource?.id ?? null;
166
180
  const readSourcePage = useCallback(async (cursor, signal) => {
167
181
  if (!activeSource)
@@ -210,17 +224,24 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
210
224
  sourceRequestRef.current?.abort();
211
225
  };
212
226
  }, [activeSourceId, isOpen, readSourcePage]);
213
- // A closed picker stops what it asked: the listing and an import on its way.
227
+ /*
228
+ * A closed picker stops what it asked: the listing, an import or an upload on its way -- nothing is to
229
+ * choose for it afterwards -- and the Folder it opens on.
230
+ */
214
231
  useEffect(() => {
215
232
  if (isOpen)
216
233
  return;
234
+ uploadRef.current?.cancel();
217
235
  sourceRequestRef.current?.abort();
218
236
  importRequestRef.current?.abort();
219
237
  importRequestRef.current = null;
238
+ startFolderRequestRef.current?.abort();
239
+ startFolderRequestRef.current = null;
220
240
  }, [isOpen]);
221
241
  useEffect(() => () => {
222
242
  sourceRequestRef.current?.abort();
223
243
  importRequestRef.current?.abort();
244
+ startFolderRequestRef.current?.abort();
224
245
  }, []);
225
246
  const loadMoreSourceItems = () => {
226
247
  if (!sourceCursor || sourceLoading)
@@ -306,6 +327,72 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
306
327
  }
307
328
  };
308
329
  const resolvedAssets = provider && source ? assets : [];
330
+ /** Asks for the Folder the picker opens on (`openOnFolder`); the listing waits until it is answered. */
331
+ const openOnStartFolder = () => {
332
+ if (!openOnFolder)
333
+ return;
334
+ startFolderRequestRef.current?.abort();
335
+ const abortController = new AbortController();
336
+ startFolderRequestRef.current = abortController;
337
+ setStartFolderPending(true);
338
+ setStartFolderFailure(null);
339
+ setOnIncompleteStartFolder(false);
340
+ void (async () => {
341
+ try {
342
+ const startFolder = await openOnFolder(abortController.signal);
343
+ if (abortController.signal.aborted)
344
+ return;
345
+ setFolderId(startFolder.folderId);
346
+ setOnIncompleteStartFolder(!startFolder.complete);
347
+ setPage(1);
348
+ }
349
+ catch (error) {
350
+ if (abortController.signal.aborted)
351
+ return;
352
+ console.error("Media picker could not open its Folder.", error);
353
+ setFolderId(null);
354
+ setPage(1);
355
+ setStartFolderFailure(readPhiMediaSourceImportErrorMessage(error, labels.upload.refusals, labels.upload.refusals.errorGeneric));
356
+ }
357
+ finally {
358
+ if (startFolderRequestRef.current === abortController)
359
+ startFolderRequestRef.current = null;
360
+ // Closed or opened again meanwhile: a newer question is pending, or none is wanted.
361
+ if (startFolderRequestRef.current == null)
362
+ setStartFolderPending(false);
363
+ }
364
+ })();
365
+ };
366
+ /*
367
+ * The upload goes into the Folder in view, on the Site Space only (`PhiMediaPickerUploadBinding`) --
368
+ * into the start Folder's whole path while the picker stands on the part of it that is there, and the
369
+ * picker then shows the Folder the file landed in. The list is read again whatever came of it, so a
370
+ * finished upload stands among the tiles -- greyed out, where the host does not let it be chosen -- and
371
+ * what comes back is chosen like a picked tile.
372
+ */
373
+ const uploadOffered = upload != null && onSiteSpace;
374
+ const sendUpload = async (file) => {
375
+ if (!upload)
376
+ return null;
377
+ const intoStartFolder = onIncompleteStartFolder;
378
+ let tile = null;
379
+ try {
380
+ tile = await upload.send(file, folderId, intoStartFolder);
381
+ }
382
+ catch (error) {
383
+ console.error("Media picker upload failed.", error);
384
+ }
385
+ if (tile && intoStartFolder) {
386
+ setFolderId(tile.folderId);
387
+ setOnIncompleteStartFolder(false);
388
+ setPage(1);
389
+ }
390
+ setRefreshToken((current) => current + 1);
391
+ if (!tile)
392
+ return null;
393
+ assetCacheRef.current.set(tile.id, tile);
394
+ return tile;
395
+ };
309
396
  const updateOpen = (next) => {
310
397
  if (controlledOpen == null)
311
398
  setLocalOpen(next);
@@ -313,6 +400,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
313
400
  // A picker opens on the Site's library, whatever source the last opening ended in.
314
401
  setSourceId("");
315
402
  setImportFailure(null);
403
+ openOnStartFolder();
316
404
  setRefreshToken((current) => current + 1);
317
405
  reloadSignals.emitCapability("reload", null);
318
406
  kindSignals.emitCapability("kind", mediaType);
@@ -354,6 +442,10 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
354
442
  sourceHasMore: activeSource != null && sourceCursor != null,
355
443
  importingItemId,
356
444
  sourceNotice: importFailure,
445
+ onUpload: uploadOffered ? sendUpload : undefined,
446
+ uploadAccept: uploadOffered ? upload.accept : undefined,
447
+ uploadProgress: uploadOffered ? upload.progress : null,
448
+ uploadNotice: uploadOffered ? startFolderFailure ?? upload.notice : startFolderFailure,
357
449
  folders: provider && source ? folderOptions : [],
358
450
  folderValue,
359
451
  query: searchQuery,
@@ -366,7 +458,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
366
458
  showFolderFilter: config?.showFolderFilter ?? true,
367
459
  showPagination: config?.showPagination ?? true,
368
460
  trigger,
369
- labels: { trigger: labels.picker.triggerLabel, title: labels.picker.popoverTitle, search: labels.tool.searchPlaceholder ?? searchLabels.placeholder, folder: labels.tool.folderLabel, space: labels.space.label, empty: bindingError ?? (loadFailed ? labels.picker.loadFailedDescription : labels.picker.emptyDescription), sourceEmpty: sourceFailed ? labels.picker.sourceFailedText : labels.picker.emptyDescription, clear: labels.picker.clearLabel, reload: labels.tool.reloadLabel, tileSize: labels.picker.tileSizeLabel, source: labels.picker.sourceLabel, importing: labels.picker.importingLabel, loadMore: labels.picker.loadMoreLabel },
461
+ labels: { trigger: labels.picker.triggerLabel, title: labels.picker.popoverTitle, search: labels.tool.searchPlaceholder ?? searchLabels.placeholder, folder: labels.tool.folderLabel, space: labels.space.label, empty: bindingError ?? (loadFailed ? labels.picker.loadFailedDescription : labels.picker.emptyDescription), sourceEmpty: sourceFailed ? labels.picker.sourceFailedText : labels.picker.emptyDescription, clear: labels.picker.clearLabel, reload: labels.tool.reloadLabel, tileSize: labels.picker.tileSizeLabel, source: labels.picker.sourceLabel, importing: labels.picker.importingLabel, loadMore: labels.picker.loadMoreLabel, upload: labels.upload.uploadToggleLabel },
370
462
  getPopupContainer,
371
463
  popupRootClassName,
372
464
  isAssetSelectable,
@@ -381,6 +473,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
381
473
  setSpaceAddress(nextSpace);
382
474
  setRequestedSpaceAddress(nextSpace);
383
475
  setFolderId(null);
476
+ setOnIncompleteStartFolder(false);
384
477
  setPage(1);
385
478
  },
386
479
  onSourceChange: (nextSource) => {
@@ -392,7 +485,7 @@ export function usePhiMediaPickerBinding({ config, labels, searchLabels, value:
392
485
  },
393
486
  onSourceItemSelect: importSourceItem,
394
487
  onSourceLoadMore: loadMoreSourceItems,
395
- onFolderChange: (nextFolder) => { setFolderId(resolvePhiMediaFolderIdFromValue(folders, nextFolder)); setPage(1); pathSignals.emitCapability("path", nextFolder); },
488
+ onFolderChange: (nextFolder) => { setFolderId(resolvePhiMediaFolderIdFromValue(folders, nextFolder)); setOnIncompleteStartFolder(false); setPage(1); pathSignals.emitCapability("path", nextFolder); },
396
489
  onPageChange: (nextPage, nextPageSize) => { setPage(nextPage); setPageSize(nextPageSize); paginationSignals.emitCapability("pagination", { page: nextPage, pageSize: nextPageSize, total }); },
397
490
  onMinColumnWidthChange: setMinColumnWidth,
398
491
  onReload: () => { setRefreshToken((current) => current + 1); reloadSignals.emitCapability("reload", null); },
@@ -45,6 +45,8 @@ type PhiMediaUploadItem = {
45
45
  status: "uploading" | "done" | "error";
46
46
  error: string | null;
47
47
  assetId: number | null;
48
+ /** Where this one file was sent, where its caller named it (`upload(file, options)`); a retry sends it there again. */
49
+ initOptions?: PhiMediaUploadInitOptions;
48
50
  };
49
51
  /**
50
52
  * The shared half of every upload surface: accept, transport, progress, refusal.
@@ -58,6 +60,10 @@ type PhiMediaUploadItem = {
58
60
  * finalized that nobody will enter anywhere. `cancel()` does the same while the surface stays. A stopped
59
61
  * upload leaves the list and calls neither `onUploaded` nor `onRejected`: nobody is waiting for it.
60
62
  *
63
+ * `upload(file, options)` sends one file where `options` says instead of where `initOptions` does, for a
64
+ * surface whose target moves while it stands -- the `media-asset` field's picker uploads into the Folder
65
+ * it shows, which the reader changes.
66
+ *
61
67
  * `uploading` is true while any file is still on its way. A surface whose value is only complete once the
62
68
  * upload settled -- a form field that receives the Asset id in `onUploaded` -- reads it to hold back
63
69
  * whatever would act on the incomplete value.
@@ -90,7 +96,7 @@ export declare function usePhiMediaUpload<TAsset extends {
90
96
  accept: string;
91
97
  items: readonly PhiMediaUploadItem[];
92
98
  uploading: boolean;
93
- upload: (file: File) => Promise<TAsset | null>;
99
+ upload: (file: File, fileInitOptions?: PhiMediaUploadInitOptions) => Promise<TAsset | null>;
94
100
  retry: (localId: string) => Promise<TAsset | null>;
95
101
  cancel: () => void;
96
102
  reset: () => void;
@@ -95,6 +95,10 @@ export function readPhiMediaUploadErrorMessage(error, labels) {
95
95
  * finalized that nobody will enter anywhere. `cancel()` does the same while the surface stays. A stopped
96
96
  * upload leaves the list and calls neither `onUploaded` nor `onRejected`: nobody is waiting for it.
97
97
  *
98
+ * `upload(file, options)` sends one file where `options` says instead of where `initOptions` does, for a
99
+ * surface whose target moves while it stands -- the `media-asset` field's picker uploads into the Folder
100
+ * it shows, which the reader changes.
101
+ *
98
102
  * `uploading` is true while any file is still on its way. A surface whose value is only complete once the
99
103
  * upload settled -- a form field that receives the Asset id in `onUploaded` -- reads it to hold back
100
104
  * whatever would act on the incomplete value.
@@ -119,7 +123,7 @@ export function usePhiMediaUpload(input) {
119
123
  setItems((current) => current.map((item) => item.localId === localId ? { ...item, ...next } : item));
120
124
  }, []);
121
125
  /** One file into one item: a new item, or -- for a retry -- the failed one it had. */
122
- const run = useCallback(async (file, retryLocalId) => {
126
+ const run = useCallback(async (file, retryLocalId, fileInitOptions) => {
123
127
  const rejection = readPhiMediaUploadRejection(file, acceptance, labels);
124
128
  if (rejection) {
125
129
  onRejected?.(rejection, file);
@@ -130,13 +134,21 @@ export function usePhiMediaUpload(input) {
130
134
  sequence.current += 1;
131
135
  localId = `upload-${sequence.current}`;
132
136
  }
133
- const startedItem = { localId, file, progress: 0, status: "uploading", error: null, assetId: null };
137
+ const startedItem = {
138
+ localId,
139
+ file,
140
+ progress: 0,
141
+ status: "uploading",
142
+ error: null,
143
+ assetId: null,
144
+ ...(fileInitOptions ? { initOptions: fileInitOptions } : {}),
145
+ };
134
146
  setItems((current) => [startedItem, ...current.filter((item) => item.localId !== localId)]);
135
147
  const controller = new AbortController();
136
148
  running.current.add(controller);
137
149
  let asset;
138
150
  try {
139
- ({ asset } = await runSession(file, (progress) => patch(localId, { progress }), initOptions, controller.signal));
151
+ ({ asset } = await runSession(file, (progress) => patch(localId, { progress }), fileInitOptions ?? initOptions, controller.signal));
140
152
  }
141
153
  catch (error) {
142
154
  if (controller.signal.aborted || isPhiMediaUploadCancelled(error)) {
@@ -166,11 +178,11 @@ export function usePhiMediaUpload(input) {
166
178
  }
167
179
  return asset;
168
180
  }, [acceptance, initOptions, labels, onRejected, onUploaded, patch, runSession]);
169
- const upload = useCallback((file) => run(file), [run]);
181
+ const upload = useCallback((file, fileInitOptions) => run(file, undefined, fileInitOptions), [run]);
170
182
  /** Starts a failed item's file again, in the place it had. */
171
183
  const retry = useCallback((localId) => {
172
184
  const failed = items.find((item) => item.localId === localId && item.status === "error");
173
- return failed ? run(failed.file, localId) : Promise.resolve(null);
185
+ return failed ? run(failed.file, localId, failed.initOptions) : Promise.resolve(null);
174
186
  }, [items, run]);
175
187
  const cancel = useCallback(() => {
176
188
  for (const controller of running.current)
@@ -0,0 +1,45 @@
1
+ import type { PhiCoreRuntimeMessageValue } from "../../../../types";
2
+ import type { PhiCollectionProviderData, PhiCollectionProviderQuery, PhiCollectionViewBindingModel } from "../../../../types/collection-provider";
3
+ import type { PhiCmsCollectionViewWidgetConfig } from "../../../../types/collection-view-widget";
4
+ import type { PhiCollectionReorderContextValue } from "../../../controls/phi-collection-reorder-context";
5
+ import type { PhiCollectionViewWidgetLabels } from "../../label-types/collection-view";
6
+ type PhiCollectionItemKey = string | number;
7
+ /**
8
+ * The keys of the items in the order shown, where dragging them into another order is offered -- or
9
+ * `null` where it is not.
10
+ *
11
+ * Offered only where a drop can say the whole collection's order (`itemKeys`): reordering enabled, in
12
+ * `grid` or `stack` (a masonry's columns have no reading order a drop could follow), no search text, no
13
+ * filter apart from the ones the Widget's own initial query sets -- those are what the collection is --,
14
+ * and every item on the page (a total beyond what was answered is a second page, or a cut). Each item
15
+ * needs a key at the resource's `itemIdentityPath`, a string or a number, and no two the same.
16
+ */
17
+ export declare function resolvePhiCollectionReorderKeys(input: {
18
+ config: Pick<PhiCmsCollectionViewWidgetConfig, "presentation" | "features" | "initialQuery">;
19
+ query: PhiCollectionProviderQuery;
20
+ data: Pick<PhiCollectionProviderData, "items" | "total"> | null;
21
+ itemIdentityPath: string;
22
+ }): PhiCollectionItemKey[] | null;
23
+ /** The items in the order the keys give; an item whose key is not among them keeps its place at the end. */
24
+ export declare function orderPhiCollectionItems<TItem>(items: readonly TItem[], order: readonly PhiCollectionItemKey[], readKey: (item: TItem) => unknown): TItem[];
25
+ /**
26
+ * Drag reordering for a `collection-view` Widget: the binding its renderer is to draw from -- the items
27
+ * in the dropped order at once, while the Provider writes it -- and what its Collection Control needs to
28
+ * offer the handles (`PhiCollectionReorderContext`), or `null` where reordering is not offered.
29
+ *
30
+ * A drop sends the Provider's reorder action with every key in the new order (`itemKeys`). Its answer is
31
+ * the collection as it now stands and takes the dropped order's place; a refusal -- thrown, or answered
32
+ * with `error` -- puts the order the Provider has back, read again, and is said the way a Collection's
33
+ * other refused actions are (an application message, the Provider's words where it gave some).
34
+ */
35
+ export declare function usePhiCollectionReorderBinding({ config, binding, itemIdentityPath, labels, showMessage, }: {
36
+ config: PhiCmsCollectionViewWidgetConfig | null | undefined;
37
+ binding: PhiCollectionViewBindingModel;
38
+ itemIdentityPath: string | null;
39
+ labels: PhiCollectionViewWidgetLabels;
40
+ showMessage: (value: PhiCoreRuntimeMessageValue) => void;
41
+ }): {
42
+ binding: PhiCollectionViewBindingModel;
43
+ reorder: PhiCollectionReorderContextValue | null;
44
+ };
45
+ export {};
@@ -0,0 +1,110 @@
1
+ "use client";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { readPhiDotPath } from "../../../../helpers/dot-path";
4
+ /** The Provider action a reorder is sent as where the Widget names none. */
5
+ const PHI_COLLECTION_REORDER_DEFAULT_ACTION_KEY = "reorder";
6
+ function isBlankFilterValue(value) {
7
+ return value == null || value === "" || (Array.isArray(value) && value.length === 0);
8
+ }
9
+ /* The filters that narrow the list, blank ones left out, in one order, so two can be compared. */
10
+ function readNarrowingFilters(filters) {
11
+ return JSON.stringify(Object.entries(filters ?? {})
12
+ .filter(([, value]) => !isBlankFilterValue(value))
13
+ .sort(([left], [right]) => left.localeCompare(right)));
14
+ }
15
+ /**
16
+ * The keys of the items in the order shown, where dragging them into another order is offered -- or
17
+ * `null` where it is not.
18
+ *
19
+ * Offered only where a drop can say the whole collection's order (`itemKeys`): reordering enabled, in
20
+ * `grid` or `stack` (a masonry's columns have no reading order a drop could follow), no search text, no
21
+ * filter apart from the ones the Widget's own initial query sets -- those are what the collection is --,
22
+ * and every item on the page (a total beyond what was answered is a second page, or a cut). Each item
23
+ * needs a key at the resource's `itemIdentityPath`, a string or a number, and no two the same.
24
+ */
25
+ export function resolvePhiCollectionReorderKeys(input) {
26
+ const { config, query, data } = input;
27
+ if (config.features.reorder?.enabled !== true)
28
+ return null;
29
+ if (config.presentation.mode === "masonry")
30
+ return null;
31
+ if (!data || data.items.length === 0 || data.total > data.items.length)
32
+ return null;
33
+ if ((query.search ?? "").trim())
34
+ return null;
35
+ if (readNarrowingFilters(query.filters) !== readNarrowingFilters(config.initialQuery?.filters))
36
+ return null;
37
+ const keys = [];
38
+ const seen = new Set();
39
+ for (const item of data.items) {
40
+ const key = readPhiDotPath(item, input.itemIdentityPath);
41
+ if (typeof key !== "string" && typeof key !== "number")
42
+ return null;
43
+ if (seen.has(String(key)))
44
+ return null;
45
+ seen.add(String(key));
46
+ keys.push(key);
47
+ }
48
+ return keys;
49
+ }
50
+ /** The items in the order the keys give; an item whose key is not among them keeps its place at the end. */
51
+ export function orderPhiCollectionItems(items, order, readKey) {
52
+ const position = new Map(order.map((key, index) => [String(key), index]));
53
+ return items
54
+ .map((item, index) => ({ item, index, at: position.get(String(readKey(item))) }))
55
+ .sort((left, right) => (left.at ?? order.length + left.index) - (right.at ?? order.length + right.index))
56
+ .map((entry) => entry.item);
57
+ }
58
+ /**
59
+ * Drag reordering for a `collection-view` Widget: the binding its renderer is to draw from -- the items
60
+ * in the dropped order at once, while the Provider writes it -- and what its Collection Control needs to
61
+ * offer the handles (`PhiCollectionReorderContext`), or `null` where reordering is not offered.
62
+ *
63
+ * A drop sends the Provider's reorder action with every key in the new order (`itemKeys`). Its answer is
64
+ * the collection as it now stands and takes the dropped order's place; a refusal -- thrown, or answered
65
+ * with `error` -- puts the order the Provider has back, read again, and is said the way a Collection's
66
+ * other refused actions are (an application message, the Provider's words where it gave some).
67
+ */
68
+ export function usePhiCollectionReorderBinding({ config, binding, itemIdentityPath, labels, showMessage, }) {
69
+ const [pendingOrder, setPendingOrder] = useState(null);
70
+ // Not while the list is being read: what is shown may be the answer to another question (new params).
71
+ const itemKeys = useMemo(() => config && itemIdentityPath != null && !binding.loading
72
+ ? resolvePhiCollectionReorderKeys({ config, query: binding.query, data: binding.data, itemIdentityPath })
73
+ : null, [binding.data, binding.loading, binding.query, config, itemIdentityPath]);
74
+ const actionKey = config?.features.reorder?.actionKey ?? PHI_COLLECTION_REORDER_DEFAULT_ACTION_KEY;
75
+ const { activate, reload } = binding;
76
+ const onReorder = useCallback((nextKeys) => {
77
+ setPendingOrder(nextKeys);
78
+ void (async () => {
79
+ try {
80
+ const answered = await activate({ actionKey, itemKeys: nextKeys });
81
+ if (answered.error)
82
+ throw new Error(answered.error);
83
+ }
84
+ catch (error) {
85
+ showMessage({
86
+ level: "error",
87
+ content: error instanceof Error && error.message ? error.message : labels.reorderFailed,
88
+ durationSeconds: 2.8,
89
+ });
90
+ reload();
91
+ }
92
+ finally {
93
+ setPendingOrder(null);
94
+ }
95
+ })();
96
+ }, [actionKey, activate, labels.reorderFailed, reload, showMessage]);
97
+ const presentedBinding = useMemo(() => {
98
+ if (!pendingOrder || !binding.data || itemIdentityPath == null)
99
+ return binding;
100
+ const items = orderPhiCollectionItems(binding.data.items, pendingOrder, (item) => readPhiDotPath(item, itemIdentityPath));
101
+ return { ...binding, data: { ...binding.data, items } };
102
+ }, [binding, itemIdentityPath, pendingOrder]);
103
+ const reorder = useMemo(() => itemKeys ? {
104
+ itemKeys: pendingOrder ?? itemKeys,
105
+ onReorder,
106
+ disabled: pendingOrder != null,
107
+ handleLabel: labels.reorderHandle,
108
+ } : null, [itemKeys, labels.reorderHandle, onReorder, pendingOrder]);
109
+ return { binding: presentedBinding, reorder };
110
+ }
@@ -38,7 +38,8 @@ export function usePhiCollectionViewBinding({ source, initialQuery, pageSize, })
38
38
  */
39
39
  const latestRequestRef = useRef(0);
40
40
  const initialQueryKey = JSON.stringify(buildInitialQuery(initialQuery, pageSize));
41
- const sourceKey = `${source?.providerKey ?? ""}:${source?.resourceKey ?? ""}`;
41
+ // The params belong to the source: a new set (the Widget's `bindingParamsChange`) starts the list over.
42
+ const sourceKey = JSON.stringify([source?.providerKey ?? "", source?.resourceKey ?? "", source?.params ?? null]);
42
43
  const requestKey = useMemo(() => JSON.stringify([
43
44
  source?.providerKey ?? null,
44
45
  source?.resourceKey ?? null,
@@ -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" },
@@ -0,0 +1,4 @@
1
+ import "server-only";
2
+ import { type PhiGlobalTranslatorOptions } from "../../../gateway/tr";
3
+ import { type PhiCollectionViewWidgetLabels } from "../label-types/collection-view";
4
+ export declare function getPhiCollectionViewWidgetLabels(options: PhiGlobalTranslatorOptions): Promise<PhiCollectionViewWidgetLabels>;
@@ -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
+ }
@@ -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,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
+ };