@phis/ui 0.5.7 → 0.6.1

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 (116) hide show
  1. package/components/controls/phi-amount-list-control.d.ts +69 -0
  2. package/components/controls/phi-amount-list-control.js +15 -0
  3. package/components/controls/phi-button-control.js +16 -2
  4. package/components/controls/phi-form-control.d.ts +6 -0
  5. package/components/controls/phi-form-control.js +23 -7
  6. package/components/controls/phi-media-picker-control.d.ts +3 -1
  7. package/components/controls/phi-media-picker-control.js +2 -2
  8. package/components/forms/form-descriptor-runtime-client.d.ts +3 -1
  9. package/components/forms/form-descriptor-runtime-client.js +2 -2
  10. package/components/forms/form-field-provider-modules.d.ts +23 -0
  11. package/components/forms/form-field-provider-modules.js +28 -0
  12. package/components/forms/form-provider-contract.d.ts +7 -0
  13. package/components/forms/form-provider-contract.js +7 -0
  14. package/components/forms/lazy-form-field-control.d.ts +14 -0
  15. package/components/forms/lazy-form-field-control.js +35 -0
  16. package/components/forms/phi-form-widget.d.ts +3 -2
  17. package/components/forms/phi-form-widget.js +21 -3
  18. package/components/forms/shared-form-provider-registry.js +1 -33
  19. package/components/media/phi-area-upload-widget.js +6 -58
  20. package/components/media/phi-media-picker-binding.d.ts +16 -1
  21. package/components/media/phi-media-picker-binding.js +3 -2
  22. package/components/media/phi-media-upload.d.ts +12 -0
  23. package/components/media/phi-media-upload.js +22 -0
  24. package/components/media/phi-upload-drop-area.d.ts +22 -0
  25. package/components/media/phi-upload-drop-area.js +49 -0
  26. package/components/root/phi-root-layout.d.ts +1 -0
  27. package/components/root/phi-root-layout.js +1 -0
  28. package/components/widgets/helpers/semantic-html-translation.d.ts +4 -1
  29. package/components/widgets/helpers/semantic-html-translation.js +4 -2
  30. package/components/widgets/label-sets/admin-users.d.ts +9 -1
  31. package/components/widgets/label-sets/admin-users.js +14 -2
  32. package/components/widgets/label-sets/slot-upload.js +6 -3
  33. package/components/widgets/label-types/slot-upload.d.ts +7 -1
  34. package/components/widgets/label-types/slot-upload.js +2 -1
  35. package/components/widgets/shared/markdown-render.js +6 -6
  36. package/constants/media-library-provider-keys.d.ts +9 -0
  37. package/constants/media-library-provider-keys.js +9 -0
  38. package/constants/media.d.ts +2 -0
  39. package/constants/media.js +2 -0
  40. package/constants/runtime-module-ownership.js +2 -0
  41. package/controls.d.ts +4 -0
  42. package/controls.js +2 -0
  43. package/gateway/signet-route.d.ts +24 -0
  44. package/gateway/signet-route.js +107 -0
  45. package/gateway/site-proxy.js +14 -7
  46. package/helpers/phi-metadata.d.ts +8 -6
  47. package/helpers/phi-metadata.js +9 -2
  48. package/helpers/phi-signet-head.d.ts +26 -0
  49. package/helpers/phi-signet-head.js +53 -0
  50. package/helpers/phi-signet-paths.d.ts +16 -0
  51. package/helpers/phi-signet-paths.js +19 -0
  52. package/helpers/phi-signet.d.ts +40 -0
  53. package/helpers/phi-signet.js +70 -0
  54. package/net/phi-next-proxy.d.ts +10 -8
  55. package/net/phi-next-proxy.js +27 -84
  56. package/next/proxy-runtime.js +15 -0
  57. package/next/root-route.js +7 -4
  58. package/next/site-proxy.js +21 -0
  59. package/package.json +3 -3
  60. package/plugins/runtime-modules/area-definitions.d.ts +24 -3
  61. package/plugins/runtime-modules/area-definitions.js +11 -3
  62. package/plugins/runtime-modules/asset/definition.d.ts +44 -2
  63. package/plugins/runtime-modules/asset/definition.js +5 -2
  64. package/plugins/runtime-modules/asset/form-providers.d.ts +63 -0
  65. package/plugins/runtime-modules/asset/form-providers.js +54 -0
  66. package/plugins/runtime-modules/asset/form-ui-provider.js +13 -3
  67. package/plugins/runtime-modules/asset/media-asset-field.d.ts +20 -0
  68. package/plugins/runtime-modules/asset/media-asset-field.js +33 -0
  69. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +21 -0
  70. package/plugins/runtime-modules/asset/media-asset-form-control.js +74 -0
  71. package/plugins/runtime-modules/core/widgets/html/server.js +1 -1
  72. package/plugins/runtime-modules/core/widgets/slot-upload/client.js +28 -23
  73. package/plugins/runtime-modules/core/widgets/slot-upload/slot.d.ts +19 -0
  74. package/plugins/runtime-modules/core/widgets/slot-upload/slot.js +16 -0
  75. package/plugins/runtime-modules/public/presets.d.ts +12 -0
  76. package/plugins/runtime-modules/public/presets.js +10 -0
  77. package/plugins/runtime-modules/public/server.js +1 -1
  78. package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.d.ts +4 -0
  79. package/plugins/runtime-modules/public/trees/phi-default-pub-privacy-page-tree.js +66 -0
  80. package/plugins/runtime-modules/public-base-page-references.d.ts +2 -1
  81. package/plugins/runtime-modules/public-base-page-references.js +2 -1
  82. package/plugins/runtime-modules/resolver.js +38 -4
  83. package/plugins/runtime-modules/theme/controller/runtime.js +7 -2
  84. package/plugins/runtime-modules/theme/materialize-images.d.ts +16 -0
  85. package/plugins/runtime-modules/theme/materialize-images.js +37 -0
  86. package/plugins/runtime-modules/user-management/addon-roles.d.ts +35 -0
  87. package/plugins/runtime-modules/user-management/addon-roles.js +76 -0
  88. package/plugins/runtime-modules/user-management/cards.js +1 -1
  89. package/plugins/runtime-modules/user-management/client-data-providers.js +6 -0
  90. package/plugins/runtime-modules/user-management/data-providers.d.ts +11 -2
  91. package/plugins/runtime-modules/user-management/data-providers.js +12 -1
  92. package/plugins/runtime-modules/user-management/definition.d.ts +11 -2
  93. package/plugins/runtime-modules/user-management/ids.d.ts +1 -0
  94. package/plugins/runtime-modules/user-management/ids.js +1 -0
  95. package/plugins/runtime-modules/user-management/services/options.d.ts +8 -0
  96. package/plugins/runtime-modules/user-management/services/options.js +25 -0
  97. package/plugins/runtime-modules/user-management/services/table.js +9 -1
  98. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +20 -2
  99. package/server-helpers/cms-widget-texts.js +1 -1
  100. package/server-helpers/search-index.js +22 -13
  101. package/server-helpers/search-text.d.ts +3 -2
  102. package/server-helpers/search-text.js +6 -5
  103. package/server-helpers/translate.d.ts +13 -2
  104. package/server-helpers/translate.js +10 -6
  105. package/styles/amount-list.css +142 -0
  106. package/styles/controls.css +156 -7
  107. package/styles/gradients.css +21 -20
  108. package/theme/phi-theme-blocks.d.ts +7 -6
  109. package/theme/phi-theme-composition.d.ts +19 -1
  110. package/theme/phi-theme-composition.js +15 -0
  111. package/theme/phi-theme-signet.d.ts +31 -0
  112. package/theme/phi-theme-signet.js +53 -0
  113. package/theme/phi-tokens.d.ts +1 -1
  114. package/theme/phi-tokens.js +5 -1
  115. package/types/cms-plugins.d.ts +10 -1
  116. package/types/site-theme.d.ts +29 -0
@@ -0,0 +1,33 @@
1
+ import { PhiMediaKind, isPhiMediaAssetPublic } from "../../../constants/media";
2
+ import { createPhiConfigReader } from "../../../components/widgets/config/strict-config-reader";
3
+ const MEDIA_ASSET_FIELD_KINDS = [
4
+ PhiMediaKind.Image,
5
+ PhiMediaKind.Video,
6
+ PhiMediaKind.Audio,
7
+ PhiMediaKind.Pdf,
8
+ PhiMediaKind.Markdown,
9
+ PhiMediaKind.Font,
10
+ ];
11
+ /**
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.
15
+ */
16
+ export function readPhiMediaAssetFieldConfig(config) {
17
+ const reader = createPhiConfigReader(config ?? {}, "config");
18
+ return {
19
+ mediaType: reader.oneOf("mediaType", MEDIA_ASSET_FIELD_KINDS) ?? PhiMediaKind.Image,
20
+ publicOnly: reader.boolean("publicOnly") ?? false,
21
+ };
22
+ }
23
+ /**
24
+ * The Asset id a Form value holds, or `null`. A value that is not a positive whole number is not an id,
25
+ * and showing it as one would put a request for Asset `NaN` on the wire.
26
+ */
27
+ export function readPhiMediaAssetFieldValue(value) {
28
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : null;
29
+ }
30
+ /** Whether the picker lets one Asset be chosen: always, unless the field offers public Assets only. */
31
+ export function isPhiMediaAssetFieldSelectable(config, asset) {
32
+ return !config.publicOnly || isPhiMediaAssetPublic(asset.deliveryPolicy, asset.lifecycleStatus);
33
+ }
@@ -0,0 +1,21 @@
1
+ import { type ComponentType } from "react";
2
+ import type { PhiFormFieldProviderProps } from "../../../components/forms/form-provider-registry";
3
+ /**
4
+ * The `media-asset` field: one Asset of the Site's Media library (`FORMS.md`).
5
+ *
6
+ * The chosen Asset is shown as a preview, "Choose" / "Change" opens the library's own picker -- the
7
+ * binding every picker in the house runs on, not a second one -- and "Remove" empties the field. The
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
+ * the picker's open state.
10
+ *
11
+ * Only the Site Space is offered, in every Area (`siteSpaceOnly`): a Form stores a reference everybody
12
+ * who reads the stored value will follow, and a personal or a group Space cannot honestly stand behind
13
+ * that. `config.publicOnly` greys out the Assets that are not delivered publicly, from the delivery
14
+ * policy the library's list states for each. Both are interface rules. The Server that takes the value
15
+ * decides what it accepts, and a Form that must hold the line checks the Asset there.
16
+ *
17
+ * An id that arrived as an initial value is read through the Asset detail route the Inspector's image
18
+ * field reads (`usePhiAuthoringAssetDetails`), so the preview shows what is stored. Where that read is
19
+ * refused, the field says so and still lets the value be changed or removed.
20
+ */
21
+ export declare const PhiMediaAssetFormControl: ComponentType<PhiFormFieldProviderProps>;
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useMemo } from "react";
4
+ import { PhiButtonControl } from "../../../components/controls/phi-button-control";
5
+ import { PhiFlexControl } from "../../../components/controls/phi-flex-control";
6
+ import { PhiMediaAssetTileControl } from "../../../components/controls/phi-media-asset-tile-control";
7
+ import { PhiMediaPickerControl } from "../../../components/controls/phi-media-picker-control";
8
+ import { PhiTypographyControl } from "../../../components/controls/phi-typography-control";
9
+ import { PHI_MEDIA_WIDGET_DEFAULT_LABELS } from "../../../components/media/media-widget-labels";
10
+ import { usePhiMediaPickerBinding } from "../../../components/media/phi-media-picker-binding";
11
+ import { usePhiAuthoringAssetDetails } from "../../../components/media/use-authoring-asset-details";
12
+ import { PHI_SEARCH_WIDGET_DEFAULT_LABELS } from "../../../components/widgets/label-types/search";
13
+ import { isPhiMediaAssetPublic } from "../../../constants/media";
14
+ import { PHI_FORM_MEDIA_ASSET_LABEL_KEYS } from "./form-providers";
15
+ import { isPhiMediaAssetFieldSelectable, readPhiMediaAssetFieldConfig, readPhiMediaAssetFieldValue, } from "./media-asset-field";
16
+ const DEFAULT_LABELS = {
17
+ choose: "Choose",
18
+ change: "Change",
19
+ remove: "Remove",
20
+ publicOnlyHint: "Only publicly delivered files can be chosen.",
21
+ notPublic: "This file is not delivered publicly.",
22
+ unavailable: "The file could not be read.",
23
+ };
24
+ const PREVIEW_SIZE = 72;
25
+ /**
26
+ * The `media-asset` field: one Asset of the Site's Media library (`FORMS.md`).
27
+ *
28
+ * The chosen Asset is shown as a preview, "Choose" / "Change" opens the library's own picker -- the
29
+ * binding every picker in the house runs on, not a second one -- and "Remove" empties the field. The
30
+ * value is the Asset id as a number, `null` for none, and the field keeps no copy of it: what it keeps is
31
+ * the picker's open state.
32
+ *
33
+ * Only the Site Space is offered, in every Area (`siteSpaceOnly`): a Form stores a reference everybody
34
+ * who reads the stored value will follow, and a personal or a group Space cannot honestly stand behind
35
+ * that. `config.publicOnly` greys out the Assets that are not delivered publicly, from the delivery
36
+ * policy the library's list states for each. Both are interface rules. The Server that takes the value
37
+ * decides what it accepts, and a Form that must hold the line checks the Asset there.
38
+ *
39
+ * An id that arrived as an initial value is read through the Asset detail route the Inspector's image
40
+ * field reads (`usePhiAuthoringAssetDetails`), so the preview shows what is stored. Where that read is
41
+ * refused, the field says so and still lets the value be changed or removed.
42
+ */
43
+ export const PhiMediaAssetFormControl = ({ field, value, labels, disabled, readOnly, onChange, }) => {
44
+ const config = useMemo(() => readPhiMediaAssetFieldConfig(field.config), [field.config]);
45
+ const assetId = readPhiMediaAssetFieldValue(value);
46
+ const asset = usePhiAuthoringAssetDetails(assetId);
47
+ const read = (key) => labels?.[PHI_FORM_MEDIA_ASSET_LABEL_KEYS[key]]?.trim() || DEFAULT_LABELS[key];
48
+ const choose = read("choose");
49
+ const change = read("change");
50
+ const pickerLabels = useMemo(() => ({
51
+ ...PHI_MEDIA_WIDGET_DEFAULT_LABELS,
52
+ picker: {
53
+ ...PHI_MEDIA_WIDGET_DEFAULT_LABELS.picker,
54
+ triggerLabel: assetId == null ? choose : change,
55
+ },
56
+ }), [assetId, change, choose]);
57
+ const picker = usePhiMediaPickerBinding({
58
+ config: {
59
+ mediaType: config.mediaType,
60
+ pageSize: 12,
61
+ showPagination: true,
62
+ showSearchBar: true,
63
+ },
64
+ labels: pickerLabels,
65
+ searchLabels: PHI_SEARCH_WIDGET_DEFAULT_LABELS,
66
+ value: assetId,
67
+ siteSpaceOnly: true,
68
+ isAssetSelectable: config.publicOnly ? (candidate) => isPhiMediaAssetFieldSelectable(config, candidate) : undefined,
69
+ onAssetSelect: (picked) => onChange?.(picked.id),
70
+ onAssetClear: () => onChange?.(null),
71
+ });
72
+ const locked = disabled || readOnly;
73
+ 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] }));
74
+ };
@@ -57,7 +57,7 @@ export async function resolvePhiHtmlWidgetTranslatedHtml(config, runtime) {
57
57
  }
58
58
  return (sourceMode !== "url" && config?.resolvedContent != null) || config?.preferSource === true
59
59
  ? sourceHtml
60
- : translateSemanticHtml(sourceHtml, sourceMode === "url" ? config?.sourceLocale?.trim() : undefined, runtime.locale.current);
60
+ : translateSemanticHtml(sourceHtml, sourceMode === "url" ? config?.sourceLocale?.trim() : undefined, runtime.locale.current, runtime);
61
61
  }
62
62
  export async function PhiHtmlWidget({ blockId, config, runtime, }) {
63
63
  const translatedHtml = await resolvePhiHtmlWidgetTranslatedHtml(config, runtime);
@@ -3,10 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { PhiEntryListControl } from "../../../../../components/controls/phi-entry-list-control";
4
4
  import { PhiProgressControl } from "../../../../../components/controls/phi-progress-control";
5
5
  import { PhiButtonControl } from "../../../../../components/controls/phi-button-control";
6
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
+ import { useCallback, useEffect, useMemo, useState } from "react";
7
7
  import { usePhiMediaUpload } from "../../../../../components/media/phi-media-upload";
8
8
  import { runPhiAddonAssetUpload, } from "../../../../../components/media/media-upload-flow";
9
- import { PHI_MEDIA_UPLOAD_DEFAULT_LABELS } from "../../../../../components/media/phi-media-upload";
9
+ import { resolvePhiAreaUploadLabels, resolvePhiUploadStatusLabel } from "../../../../../components/media/phi-media-upload";
10
+ import { PhiUploadDropArea } from "../../../../../components/media/phi-upload-drop-area";
11
+ import { PhiTagControl } from "../../../../../components/controls/phi-tag-control";
12
+ import { readPhiSlotUploadAcceptance } from "./slot";
10
13
  import { usePhiSignalListener } from "../../../../../components/runtime/runtime-signal-bus";
11
14
  import { emitPhiSignalCapability, usePhiSignalEmitter, usePhiSignalIdentity, } from "../../../../../components/runtime/runtime-signal-identity";
12
15
  import { readPhiTableBindingParamsSignalValue } from "../../../../../types/table-signal-values";
@@ -189,18 +192,11 @@ export function PhiSlotUploadWidgetClient({ config, labels }) {
189
192
  });
190
193
  return { asset: { id: view.mediaAssetId } };
191
194
  }, [base, ownerId, read, slotName]);
192
- const fileInputRef = useRef(null);
195
+ const slotUpload = useMemo(() => readPhiSlotUploadAcceptance(slot), [slot]);
196
+ const uploadLabels = useMemo(() => resolvePhiAreaUploadLabels(labels.upload), [labels.upload]);
193
197
  const upload = usePhiMediaUpload({
194
- labels: PHI_MEDIA_UPLOAD_DEFAULT_LABELS,
195
- ...(slot
196
- ? {
197
- acceptance: {
198
- contentTypes: slot.contentTypes,
199
- maxBytes: slot.maxBytes,
200
- multiple: slot.cardinality === "many",
201
- },
202
- }
203
- : {}),
198
+ labels: uploadLabels,
199
+ ...(slotUpload ? { acceptance: slotUpload.acceptance } : {}),
204
200
  runSession,
205
201
  onUploaded: async () => {
206
202
  setFailure(null);
@@ -210,6 +206,20 @@ export function PhiSlotUploadWidgetClient({ config, labels }) {
210
206
  onRejected: (message) => setFailure(message),
211
207
  });
212
208
  const files = loaded?.ownerId === ownerId ? loaded.files : [];
209
+ /*
210
+ * A file still on its way or one that failed, as a line above the files that arrived: its name, then
211
+ * the percentage or "Failed" the Media folder's tiles say, a bar while it travels, and Retry for a
212
+ * failure. The reason for a failure is the alert's, which `onRejected` fills for both.
213
+ */
214
+ const pending = upload.items.filter((item) => item.status !== "done").map((item) => ({
215
+ key: item.localId,
216
+ title: (_jsxs(PhiFlexControl, { vertical: true, gap: 4, children: [_jsxs(PhiFlexControl, { align: "center", gap: 8, wrap: true, children: [_jsx("span", { children: item.file.name }), _jsx(PhiTagControl, { color: item.status === "error" ? "red" : "blue", children: resolvePhiUploadStatusLabel(item, labels.upload) })] }), item.status === "uploading" ? _jsx(PhiProgressControl, { percent: item.progress, size: "small" }) : null] })),
217
+ ...(item.status === "error"
218
+ ? {
219
+ action: (_jsx(PhiButtonControl, { size: "small", label: labels.upload.retryLabel, onClick: () => { void upload.retry(item.localId); } })),
220
+ }
221
+ : {}),
222
+ }));
213
223
  /*
214
224
  * The removal and the read after it fail apart: a DELETE that went through and a list that could not
215
225
  * be read again are two answers, and saying "That file stayed" for the second was untrue.
@@ -231,14 +241,9 @@ export function PhiSlotUploadWidgetClient({ config, labels }) {
231
241
  if (!base || !slotName) {
232
242
  return (_jsx(PhiLabeledControl, { label: config?.label, children: _jsx(PhiTypographyControl, { type: "secondary", children: labels.unconfigured }) }));
233
243
  }
234
- return (_jsx(PhiLabeledControl, { label: config?.label, fill: true, children: _jsxs(PhiFlexControl, { vertical: true, gap: 8, "data-phis-slot-upload": slotName, children: [ownerId === null ? (_jsx(PhiTypographyControl, { type: "secondary", children: labels.noRow })) : (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", hidden: true, multiple: slot?.cardinality === "many", accept: slot?.contentTypes.join(","), onChange: (event) => {
235
- for (const file of Array.from(event.target.files ?? []))
236
- void upload.upload(file);
237
- // Cleared so choosing the same file again is a change, and uploads again.
238
- event.target.value = "";
239
- } }), _jsx(PhiButtonControl, { icon: _jsx(PhiIcon, { name: "upload", size: "inherit" }), label: labels.choose, onClick: () => fileInputRef.current?.click() })] })), upload.items.filter((item) => item.status === "uploading").map((item) => (_jsx(PhiProgressControl, { percent: item.progress, size: "small" }, item.localId))), slotFailure ?? failure ? (_jsx(PhiTypographyControl, { type: "danger", role: "alert", children: slotFailure ?? failure })) : null, _jsx(PhiEntryListControl, { emptyDescription: labels.empty, entries: [...files].map((file) => ({
240
- key: String(file.id),
241
- title: (_jsx(SlotFileTitle, { file: file, text: formatPhiSlotUploadWidgetLabel(labels.fileTitle, file.contentType, file.byteSize) })),
242
- action: (_jsx(PhiButtonControl, { size: "small", icon: _jsx(PhiIcon, { name: "delete", size: "inherit" }), ariaLabel: labels.remove, tooltip: labels.remove, onClick: () => { void remove(file.id); } })),
243
- })) })] }) }));
244
+ return (_jsx(PhiLabeledControl, { label: config?.label, fill: true, children: _jsxs(PhiFlexControl, { vertical: true, gap: 8, "data-phis-slot-upload": slotName, children: [ownerId === null ? (_jsx(PhiTypographyControl, { type: "secondary", children: labels.noRow })) : (_jsx(_Fragment, { children: _jsx(PhiUploadDropArea, { ...(slotUpload ? { accept: slotUpload.accept, multiple: slotUpload.multiple } : {}), disabled: !slotUpload, title: labels.upload.dropTitle, hint: labels.upload.dropHint, onFile: (file) => void upload.upload(file) }) })), slotFailure ?? failure ? (_jsx(PhiTypographyControl, { type: "danger", role: "alert", children: slotFailure ?? failure })) : null, _jsx(PhiEntryListControl, { emptyDescription: labels.empty, entries: [...pending, ...files.map((file) => ({
245
+ key: String(file.id),
246
+ title: (_jsx(SlotFileTitle, { file: file, text: formatPhiSlotUploadWidgetLabel(labels.fileTitle, file.contentType, file.byteSize) })),
247
+ action: (_jsx(PhiButtonControl, { size: "small", icon: _jsx(PhiIcon, { name: "delete", size: "inherit" }), ariaLabel: labels.remove, tooltip: labels.remove, onClick: () => { void remove(file.id); } })),
248
+ }))] })] }) }));
244
249
  }
@@ -0,0 +1,19 @@
1
+ import type { PhiMediaUploadAcceptance } from "../../../../../components/media/phi-media-upload";
2
+ /** One slot as Core's `_assets` manifest declares it. */
3
+ export type PhiSlotDescriptor = {
4
+ name: string;
5
+ cardinality: "one" | "many";
6
+ maxBytes: number;
7
+ contentTypes: string[];
8
+ };
9
+ /**
10
+ * What the drop area offers and what the upload checks before it sends, both from the one descriptor:
11
+ * the file dialog's `accept` and `multiple` are the same facts the acceptance holds, so they cannot
12
+ * disagree. A slot that is not known yet takes nothing -- `null` -- rather than an upload that would
13
+ * skip the check.
14
+ */
15
+ export declare function readPhiSlotUploadAcceptance(slot: PhiSlotDescriptor | null): {
16
+ accept: string;
17
+ multiple: boolean;
18
+ acceptance: PhiMediaUploadAcceptance;
19
+ } | null;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What the drop area offers and what the upload checks before it sends, both from the one descriptor:
3
+ * the file dialog's `accept` and `multiple` are the same facts the acceptance holds, so they cannot
4
+ * disagree. A slot that is not known yet takes nothing -- `null` -- rather than an upload that would
5
+ * skip the check.
6
+ */
7
+ export function readPhiSlotUploadAcceptance(slot) {
8
+ if (!slot)
9
+ return null;
10
+ const multiple = slot.cardinality === "many";
11
+ return {
12
+ accept: slot.contentTypes.join(","),
13
+ multiple,
14
+ acceptance: { contentTypes: slot.contentTypes, maxBytes: slot.maxBytes, multiple },
15
+ };
16
+ }
@@ -46,6 +46,18 @@ export declare const PHI_PUBLIC_RUNTIME_MODULE_ROUTES: ({
46
46
  };
47
47
  }[];
48
48
  loadTree: ({ page }: PhiCmsDescriptorBuildContext) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
49
+ } | {
50
+ ownerModuleId: "@phis/ui/modules/public";
51
+ presetKey: "public-privacy-page";
52
+ presetVersion: number;
53
+ area: "public";
54
+ title: string;
55
+ path: string;
56
+ loadTree: ({ page }: PhiCmsDescriptorBuildContext & {
57
+ activeModuleIds: ReadonlySet<import("../contracts").PhiRuntimeModuleId>;
58
+ params: Readonly<Record<string, string>>;
59
+ }) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
60
+ navigation?: undefined;
49
61
  } | {
50
62
  ownerModuleId: "@phis/ui/modules/public";
51
63
  presetKey: "public-terms-page";
@@ -91,6 +91,16 @@ export const PHI_PUBLIC_RUNTIME_MODULE_ROUTES = [
91
91
  loadTree: ({ page }) => import("./trees/phi-default-pub-error-page-tree")
92
92
  .then((module) => module.buildPhiDefaultPubErrorPageTree({ code, page })),
93
93
  })),
94
+ {
95
+ ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
96
+ presetKey: PHI_PUBLIC_BASE_PAGE_PRESET_KEYS.privacy,
97
+ presetVersion: 1,
98
+ area: "public",
99
+ title: "Privacy",
100
+ path: "/privacy",
101
+ loadTree: ({ page }) => import("./trees/phi-default-pub-privacy-page-tree")
102
+ .then((module) => module.buildPhiDefaultPubPrivacyPageTree({ page })),
103
+ },
94
104
  {
95
105
  ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
96
106
  presetKey: PHI_PUBLIC_BASE_PAGE_PRESET_KEYS.terms,
@@ -12,7 +12,7 @@ export const PHI_PUBLIC_RUNTIME_MODULE_SERVER_AREA_CONTRIBUTION = definePhiRunti
12
12
  forms: PHI_PUBLIC_RUNTIME_MODULE_FORMS,
13
13
  areaShells: PHI_PUBLIC_RUNTIME_MODULE_AREA_SHELLS,
14
14
  /*
15
- * The landing, the error Pages, the terms, and the contact page: what no Site can do without. Each
15
+ * The landing, the error Pages, the privacy notice, the terms, and the contact page: what no Site can do without. Each
16
16
  * is a floor a package Module may cover (MODULES.md, "Who owns an address") -- the landing through
17
17
  * the root slot, the others through their path.
18
18
  */
@@ -0,0 +1,4 @@
1
+ import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../../../../types/cms";
2
+ export declare function buildPhiDefaultPubPrivacyPageTree({ page, }: {
3
+ page: PhiCmsPageNode;
4
+ }): Promise<PhiResolvedCmsPageTree>;
@@ -0,0 +1,66 @@
1
+ import { createPhiPresetCmsInstanceIdMap } from "../../../../types/cms-instance-id";
2
+ import { PHI_PUBLIC_RUNTIME_MODULE_ID } from "../ids";
3
+ import { PHI_CMS_DEFAULT_SLOT_INDEX } from "../../../../constants/cms-layout-types";
4
+ import { PhiCmsPageType } from "../../../../constants/phi-cms";
5
+ import { buildPhiBasePageColumnFrame } from "../../../../components/regions/presets/phi-base-page-column";
6
+ import { PHI_LAYOUT } from "../../../../theme/phi-tokens";
7
+ import { createPhiCmsPresetNodes } from "../../../../helpers/cms-preset-nodes";
8
+ import { createPhiPageUri } from "../../../../types/references";
9
+ import { PHI_PUBLIC_BASE_PAGE_REFERENCES } from "../../public-base-page-references";
10
+ /**
11
+ * Placeholder privacy page, carried inline for the reason the terms are. It is not a policy and does not
12
+ * pretend to be one: it says that the operator has published none here. The second sentence points at the
13
+ * contact page by reference, so the link follows whichever Module holds that Page.
14
+ */
15
+ const PHI_DEFAULT_PUB_PRIVACY_MARKDOWN = `# Privacy
16
+
17
+ The operator of this website has not published a privacy policy here yet.
18
+
19
+ If you have questions about how your data is handled, please [contact the operator](${createPhiPageUri(PHI_PUBLIC_BASE_PAGE_REFERENCES.contact)}).
20
+ `;
21
+ const SYNTHETIC_PRIVACY_REGION_IDS = {
22
+ regionContent: -330,
23
+ };
24
+ const SYNTHETIC_PRIVACY_LAYOUT_IDS = createPhiPresetCmsInstanceIdMap({
25
+ domain: "page",
26
+ ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
27
+ presetKey: "pub-privacy-page",
28
+ }, [
29
+ "layoutContent",
30
+ ]);
31
+ const SYNTHETIC_PRIVACY_WIDGET_IDS = createPhiPresetCmsInstanceIdMap({
32
+ domain: "page",
33
+ ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
34
+ presetKey: "pub-privacy-page",
35
+ }, [
36
+ "widgetMarkdown",
37
+ ]);
38
+ export async function buildPhiDefaultPubPrivacyPageTree({ page, }) {
39
+ const nodes = createPhiCmsPresetNodes(page);
40
+ return {
41
+ page: nodes.page({ pageType: PhiCmsPageType.Standard }),
42
+ overlays: [],
43
+ // On the base scaffold, in a column on the wash that stops at the reading measure.
44
+ ...buildPhiBasePageColumnFrame({
45
+ page,
46
+ regionId: SYNTHETIC_PRIVACY_REGION_IDS.regionContent,
47
+ columnId: SYNTHETIC_PRIVACY_LAYOUT_IDS.layoutContent,
48
+ label: "pub privacy page",
49
+ maxWidth: PHI_LAYOUT.readingMax,
50
+ }),
51
+ contentWidgets: [
52
+ nodes.widget({
53
+ typeKey: "markdown",
54
+ id: SYNTHETIC_PRIVACY_WIDGET_IDS.widgetMarkdown,
55
+ parentLayoutNodeId: SYNTHETIC_PRIVACY_LAYOUT_IDS.layoutContent,
56
+ slotIndex: PHI_CMS_DEFAULT_SLOT_INDEX,
57
+ sortOrder: 0,
58
+ label: "pub privacy markdown widget",
59
+ config: {
60
+ sourceMode: "inline",
61
+ markdown: PHI_DEFAULT_PUB_PRIVACY_MARKDOWN,
62
+ },
63
+ }),
64
+ ],
65
+ };
66
+ }
@@ -14,6 +14,7 @@ import { createPhiPageReference } from "../../types/references";
14
14
  export declare const PHI_PUBLIC_BASE_PAGE_PRESET_KEYS: {
15
15
  readonly welcome: "public-welcome-page";
16
16
  readonly home: "public-home-page";
17
+ readonly privacy: "public-privacy-page";
17
18
  readonly terms: "public-terms-page";
18
19
  readonly contact: "public-contact-page";
19
20
  readonly unsubscribe: "public-unsubscribe-page";
@@ -21,7 +22,7 @@ export declare const PHI_PUBLIC_BASE_PAGE_PRESET_KEYS: {
21
22
  /**
22
23
  * Ready-made references to the Pages every Site has, for a Module that links to one.
23
24
  *
24
- * The Public base brings a welcome, a home, terms and a contact Page, and a package Module may
25
+ * The Public base brings a welcome, a home, privacy, terms and a contact Page, and a package Module may
25
26
  * reasonably point at any of them -- phis.dev's closing line does exactly that. Without this it would
26
27
  * either type a path, which goes stale and cannot say which Module's Page it means where one covers
27
28
  * another, or assemble a reference from a preset key it copied, which nothing checks.
@@ -16,6 +16,7 @@ import { createPhiRuntimeModuleId } from "../../constants/module-identity";
16
16
  export const PHI_PUBLIC_BASE_PAGE_PRESET_KEYS = {
17
17
  welcome: "public-welcome-page",
18
18
  home: "public-home-page",
19
+ privacy: "public-privacy-page",
19
20
  terms: "public-terms-page",
20
21
  contact: "public-contact-page",
21
22
  unsubscribe: "public-unsubscribe-page",
@@ -25,7 +26,7 @@ const PHI_PUBLIC_RUNTIME_MODULE_ID = createPhiRuntimeModuleId(PHI_SHARED_PACKAGE
25
26
  /**
26
27
  * Ready-made references to the Pages every Site has, for a Module that links to one.
27
28
  *
28
- * The Public base brings a welcome, a home, terms and a contact Page, and a package Module may
29
+ * The Public base brings a welcome, a home, privacy, terms and a contact Page, and a package Module may
29
30
  * reasonably point at any of them -- phis.dev's closing line does exactly that. Without this it would
30
31
  * either type a path, which goes stale and cannot say which Module's Page it means where one covers
31
32
  * another, or assemble a reference from a preset key it copied, which nothing checks.
@@ -8,6 +8,7 @@ import { PHI_VIEWER_ACCESS_ANYONE, } from "../../types/access";
8
8
  import { stripRenderableBlockDefaults } from "../../helpers/renderable-block-serialization";
9
9
  import { PhiCmsWidgetType } from "../../constants/cms-widget-types";
10
10
  import { parsePhiFormWidgetConfig } from "../../components/forms/form-widget-config";
11
+ import { PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY, PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS, } from "../../constants/media-library-provider-keys";
11
12
  import { buildPhiRecordDeclarationsByKey } from "../../helpers/record-fields";
12
13
  function loadRuntimeWidgetPlugin(entry) {
13
14
  return entry.loadRuntime();
@@ -72,7 +73,11 @@ export async function resolvePhiRuntimeModuleSet({ catalog, moduleIds, area, ser
72
73
  }
73
74
  const installedOwnerModuleIdByWidgetType = new Map();
74
75
  const installedOwnerModuleIdByLayoutType = new Map();
76
+ const installedOwnerModuleIdByFormFieldTypeKey = new Map();
75
77
  for (const [moduleId, entry] of catalog) {
78
+ for (const descriptor of entry.definition.formProviders?.fieldTypes ?? []) {
79
+ installedOwnerModuleIdByFormFieldTypeKey.set(descriptor.key, moduleId);
80
+ }
76
81
  for (const widget of entry.widgets) {
77
82
  const type = buildPhiRuntimeModuleWidgetType(widget);
78
83
  installedOwnerModuleIdByWidgetType.set(type, moduleId);
@@ -210,7 +215,13 @@ export async function resolvePhiRuntimeModuleSet({ catalog, moduleIds, area, ser
210
215
  }
211
216
  for (const form of formDefinitionsById.values()) {
212
217
  for (const field of form.descriptor.fields) {
213
- if (!formFieldTypeProviderDescriptorsByKey.has(field.fieldProviderKey)) {
218
+ /*
219
+ * A field type that an installed Module owns, but that is not active in this Area, is not an error:
220
+ * the Form still stands there, and the field says that its Module is not available
221
+ * (`PhiFormControl`'s `unavailableFieldKeys`). A key nobody installed declares is one.
222
+ */
223
+ if (!formFieldTypeProviderDescriptorsByKey.has(field.fieldProviderKey) &&
224
+ !installedOwnerModuleIdByFormFieldTypeKey.has(field.fieldProviderKey)) {
214
225
  throw new Error(`Form "${form.formId}" requires unavailable field provider "${field.fieldProviderKey}".`);
215
226
  }
216
227
  for (const rule of field.validation ?? []) {
@@ -247,6 +258,7 @@ export async function resolvePhiRuntimeModuleSet({ catalog, moduleIds, area, ser
247
258
  platformModuleId,
248
259
  installedOwnerModuleIdByWidgetType,
249
260
  installedOwnerModuleIdByLayoutType,
261
+ installedOwnerModuleIdByFormFieldTypeKey,
250
262
  ownerModuleIdByControllerType,
251
263
  areaControllerSettings,
252
264
  };
@@ -348,6 +360,15 @@ export function collectPhiRuntimeDataProviderKeys({ moduleSet, trees, }) {
348
360
  const form = formId ? moduleSet.formDefinitionsById.get(formId) : null;
349
361
  if (form) {
350
362
  collectDataProviderKeysFromValue(form.descriptor, knownProviderKeys, collected);
363
+ /*
364
+ * A `media-asset` field reads the Media library through the picker, and a field descriptor names
365
+ * no Provider of its own to find it by. The field type is what needs it, so the scan says so
366
+ * once, here, instead of every Form that has one repeating the Provider in its descriptor.
367
+ */
368
+ if (form.descriptor.fields.some((field) => field.fieldProviderKey === PHI_MEDIA_ASSET_FORM_FIELD_PROVIDER_KEY) &&
369
+ knownProviderKeys.has(PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection)) {
370
+ collected.add(PHI_MEDIA_LIBRARY_DATA_PROVIDER_KEYS.collection);
371
+ }
351
372
  }
352
373
  }
353
374
  }
@@ -382,7 +403,12 @@ export function collectPhiRuntimeDataProviderKeys({ moduleSet, trees, }) {
382
403
  }
383
404
  return collected;
384
405
  }
385
- function collectPhiRuntimeFormOwnerModuleIds({ moduleSet, trees, }) {
406
+ /**
407
+ * The Modules the Forms on these Pages need mounted: each Form's owner, and the owner of every field
408
+ * type the Form uses, where that Module is active. A field type is a Module's to offer, and the Form
409
+ * widget mounts that Module's field Providers beside the Form owner's (`PhiFormWidget`).
410
+ */
411
+ function collectPhiRuntimeFormModuleIds({ moduleSet, trees, }) {
386
412
  const collected = new Set();
387
413
  for (const tree of trees) {
388
414
  for (const widget of tree.contentWidgets) {
@@ -400,6 +426,12 @@ function collectPhiRuntimeFormOwnerModuleIds({ moduleSet, trees, }) {
400
426
  const form = moduleSet.formDefinitionsById.get(config.formId);
401
427
  if (form) {
402
428
  collected.add(form.ownerModuleId);
429
+ for (const field of form.descriptor.fields) {
430
+ const fieldOwner = moduleSet.formFieldTypeProviderDescriptorsByKey.get(field.fieldProviderKey)?.ownerModuleId;
431
+ if (fieldOwner) {
432
+ collected.add(fieldOwner);
433
+ }
434
+ }
403
435
  }
404
436
  }
405
437
  }
@@ -420,7 +452,7 @@ export async function resolvePhiRuntimeRenderRegistry({ catalog, moduleSet, tree
420
452
  const widgetImplementationModes = collectTreeWidgetImplementationModes({ moduleSet, trees });
421
453
  const layoutTypes = collectTreeLayoutTypes(trees);
422
454
  const dataProviderKeys = collectPhiRuntimeDataProviderKeys({ moduleSet, trees });
423
- const formOwnerModuleIds = collectPhiRuntimeFormOwnerModuleIds({ moduleSet, trees });
455
+ const formModuleIds = collectPhiRuntimeFormModuleIds({ moduleSet, trees });
424
456
  const renderIssuesByWidgetType = new Map();
425
457
  const runtimeWidgetRenderIssuesByType = new Map();
426
458
  const previewWidgetRenderIssuesByType = new Map();
@@ -474,7 +506,7 @@ export async function resolvePhiRuntimeRenderRegistry({ catalog, moduleSet, tree
474
506
  const usedModuleIds = new Set([
475
507
  ...widgetEntries.map(([, entry]) => entry.ownerModuleId),
476
508
  ...layoutEntries.map(([, entry]) => entry.ownerModuleId),
477
- ...formOwnerModuleIds,
509
+ ...formModuleIds,
478
510
  ]);
479
511
  const dataProviderDescriptorsByKey = new Map([...dataProviderKeys].flatMap((providerKey) => {
480
512
  const descriptor = moduleSet.dataProviderDescriptorsByKey.get(providerKey);
@@ -604,6 +636,8 @@ export async function resolvePhiRuntimeRenderRegistry({ catalog, moduleSet, tree
604
636
  })),
605
637
  ownerModuleIdByLayoutType: new Map(layoutEntries.map(([type, entry]) => [type, entry.ownerModuleId])),
606
638
  uiProviderModuleIds,
639
+ activeModuleIds: moduleSet.activeModuleIds,
640
+ ownerModuleIdByFormFieldTypeKey: moduleSet.installedOwnerModuleIdByFormFieldTypeKey,
607
641
  /*
608
642
  * Every active Module's published facts, whether or not its Widgets happen to be on this page.
609
643
  *
@@ -9,7 +9,7 @@ import { createPhiCoreRuntimeControllerAddress } from "../../../../components/ru
9
9
  import { usePhiConfig } from "../../../../components/root/phi-config-provider";
10
10
  import { usePhiThemeBlockCatalog } from "../../../../components/root/phi-theme-block-catalog-provider";
11
11
  import { resolvePhiThemeComposition } from "../../../../theme/phi-theme-composition";
12
- import { materializePhiThemeBrandLogo, materializePhiThemeModuleBlocks } from "../materialize-images";
12
+ import { materializePhiThemeBrandLogo, materializePhiThemeBrandSignet, materializePhiThemeModuleBlocks } from "../materialize-images";
13
13
  import { buildPhiSiteThemeSelectOptions, createPhiSiteThemeSelectionValue, createPhiThemeDerivation, ensurePhiThemeDerivation, readPhiSiteThemeSelectionState, resolvePhiThemeSelectionValue, } from "../../../../theme/phi-theme-selection";
14
14
  import { dispatchPhiSignalCapability } from "../../../../components/runtime/runtime-signal-identity";
15
15
  import { formatPhiHistoryMoveMessage, formatPhiHistoryTooltip, } from "../../../../components/widgets/label-types/history";
@@ -339,7 +339,12 @@ export function PhiThemeControllerRuntime({ runtime, config, setOptions, history
339
339
  * The Logo is taken the same way, from every Set, core included: a Set offers it, and a Site that
340
340
  * saved has decided to keep it -- as a picture in its own library, not as a data URL in its record.
341
341
  */
342
- nextTheme = await materializePhiThemeBrandLogo(materialized.theme, resolvePhiThemeComposition(materialized.theme, themeBlocks).markSet);
342
+ const withLogo = await materializePhiThemeBrandLogo(materialized.theme, resolvePhiThemeComposition(materialized.theme, themeBlocks).markSet);
343
+ /*
344
+ * And the Signet, which the browser tab wears: the Site delivers it from its own Media library
345
+ * under a real address, so Safari -- which loads no icon from a data URL -- shows it too.
346
+ */
347
+ nextTheme = await materializePhiThemeBrandSignet(withLogo, resolvePhiThemeComposition(withLogo, themeBlocks).markSet);
343
348
  const response = await fetch("/api/site/cms/theme", {
344
349
  method: "POST",
345
350
  headers: {
@@ -38,3 +38,19 @@ export declare function materializePhiThemeModuleBlocks<T extends {
38
38
  export declare function materializePhiThemeBrandLogo<T extends {
39
39
  brand?: PhiSiteThemeBrand | null;
40
40
  }>(theme: T, markSet: PhiThemeSetBlock): Promise<T>;
41
+ /**
42
+ * Takes the Signet a Theme wears into the Site's record, the picture into the Media library.
43
+ *
44
+ * The Logo's rule, for the mark the browser tab wears: a Module's Set is taken over, the core Set is
45
+ * followed and never copied, and a Site that saved has decided to keep what it saw. From then on the
46
+ * record names an Asset, the Site delivers it at a real address like any other picture of its own, and
47
+ * switching the Module off no longer blanks the tab.
48
+ *
49
+ * What is taken is a picture still carried inline or served from this origin -- the record's own
50
+ * `url` Signet, or, where the record says nothing, the followed Set's. A Signet that is already an
51
+ * Asset stays; an address on somebody else's server is neither fetched nor copied. There is no picker
52
+ * for it: the Theme editor offers no Signet field, and this is the only way one enters the record.
53
+ */
54
+ export declare function materializePhiThemeBrandSignet<T extends {
55
+ brand?: PhiSiteThemeBrand | null;
56
+ }>(theme: T, markSet: PhiThemeSetBlock): Promise<T>;
@@ -173,3 +173,40 @@ export async function materializePhiThemeBrandLogo(theme, markSet) {
173
173
  }
174
174
  return { ...theme, brand: { ...(theme.brand ?? {}), logo: next } };
175
175
  }
176
+ /**
177
+ * Takes the Signet a Theme wears into the Site's record, the picture into the Media library.
178
+ *
179
+ * The Logo's rule, for the mark the browser tab wears: a Module's Set is taken over, the core Set is
180
+ * followed and never copied, and a Site that saved has decided to keep what it saw. From then on the
181
+ * record names an Asset, the Site delivers it at a real address like any other picture of its own, and
182
+ * switching the Module off no longer blanks the tab.
183
+ *
184
+ * What is taken is a picture still carried inline or served from this origin -- the record's own
185
+ * `url` Signet, or, where the record says nothing, the followed Set's. A Signet that is already an
186
+ * Asset stays; an address on somebody else's server is neither fetched nor copied. There is no picker
187
+ * for it: the Theme editor offers no Signet field, and this is the only way one enters the record.
188
+ */
189
+ export async function materializePhiThemeBrandSignet(theme, markSet) {
190
+ const authored = theme.brand?.signet;
191
+ if (authored?.sourceKind === "asset")
192
+ return theme;
193
+ // A core Set offers nothing to take, like its Logo; what the author set is still theirs.
194
+ const offered = isPhiCoreThemeSet(markSet) ? null : markSet.signet;
195
+ const source = authored?.sourceKind === "url"
196
+ ? authored.sourceUrl
197
+ : typeof offered === "string" && offered.startsWith("data:image/") ? offered : null;
198
+ if (!isPhiThemeCarriedSource(source))
199
+ return theme;
200
+ const file = await readPhiThemeImageFile(source, `${markSet.key}-signet`);
201
+ const result = await runPhiMediaUploadSession(file, undefined, {
202
+ meta: { source: PhiMediaAssetSource.ThemeBrandSignet },
203
+ });
204
+ const assetId = result.asset.id;
205
+ return {
206
+ ...theme,
207
+ brand: {
208
+ ...(theme.brand ?? {}),
209
+ signet: { sourceKind: "asset", assetId, url: buildPhiMediaAssetContentDeliveryUrl(assetId) },
210
+ },
211
+ };
212
+ }