@phis/ui 0.4.4 → 0.4.6

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 (238) hide show
  1. package/README.md +9 -3
  2. package/cms/plugins.d.ts +1 -0
  3. package/cms/plugins.js +2 -0
  4. package/components/cms/phi-cms-root-layout.js +31 -2
  5. package/components/controls/phi-background-control.d.ts +6 -1
  6. package/components/controls/phi-background-control.js +12 -4
  7. package/components/controls/phi-button-control.d.ts +15 -1
  8. package/components/controls/phi-button-control.js +21 -3
  9. package/components/controls/phi-collapse-control.d.ts +6 -2
  10. package/components/controls/phi-collapse-control.js +2 -2
  11. package/components/controls/phi-dialog-control.d.ts +11 -5
  12. package/components/controls/phi-dialog-control.js +19 -13
  13. package/components/controls/phi-dropdown-control.js +2 -2
  14. package/components/controls/phi-media-asset-tile-control.js +10 -10
  15. package/components/controls/phi-menu-control-vocabulary.d.ts +7 -0
  16. package/components/controls/phi-menu-control-vocabulary.js +10 -0
  17. package/components/controls/phi-menu-control.d.ts +4 -1
  18. package/components/controls/phi-menu-control.js +6 -1
  19. package/components/controls/phi-progress-control.d.ts +10 -2
  20. package/components/controls/phi-progress-control.js +6 -2
  21. package/components/controls/phi-ribbon-control.d.ts +4 -1
  22. package/components/controls/phi-ribbon-control.js +5 -3
  23. package/components/controls/phi-ribbon-wrap-control.d.ts +7 -1
  24. package/components/controls/phi-ribbon-wrap-control.js +8 -2
  25. package/components/controls/phi-segmented-control.d.ts +4 -1
  26. package/components/controls/phi-segmented-control.js +13 -2
  27. package/components/controls/phi-surface-control.d.ts +2 -0
  28. package/components/controls/phi-surface-control.js +16 -1
  29. package/components/controls/phi-switch-control.d.ts +4 -1
  30. package/components/controls/phi-switch-control.js +8 -2
  31. package/components/controls/phi-tag-control.d.ts +4 -1
  32. package/components/controls/phi-tag-control.js +11 -3
  33. package/components/layouts/clients/phi-split-card-layout-client.js +13 -5
  34. package/components/layouts/clients/phi-three-column-layout-client.js +9 -3
  35. package/components/layouts/phi-layout-view-model.js +10 -1
  36. package/components/layouts/split-card-geometry.js +6 -2
  37. package/components/media/aspect-ratios.d.ts +2 -2
  38. package/components/menus/phi-account-menu.js +3 -1
  39. package/components/navigation/phi-link.js +7 -2
  40. package/components/navigation/use-phi-protected-mail.d.ts +11 -0
  41. package/components/navigation/use-phi-protected-mail.js +29 -0
  42. package/components/regions/clients/cms-region-container-client.js +16 -2
  43. package/components/regions/phi-cms-region-container.js +5 -1
  44. package/components/regions/phi-cms-region-shell.d.ts +11 -0
  45. package/components/regions/phi-cms-region-shell.js +64 -7
  46. package/components/regions/presets/phi-area-shell-preset-nodes.js +2 -1
  47. package/components/root/phi-config-provider.js +16 -0
  48. package/components/root/phi-root-layout.d.ts +1 -0
  49. package/components/root/phi-root-layout.js +1 -0
  50. package/components/root/phi-root-theme-resolver.js +12 -1
  51. package/components/root/phi-shell-chrome-overlay.d.ts +6 -0
  52. package/components/root/phi-shell-chrome-overlay.js +7 -1
  53. package/components/runtime/runtime-module-context.d.ts +12 -1
  54. package/components/runtime/runtime-module-context.js +6 -1
  55. package/components/shell/phi-cms-shell.d.ts +9 -1
  56. package/components/shell/phi-cms-shell.js +10 -4
  57. package/components/shell/phi-nav-link.js +7 -2
  58. package/components/shell/phi-shell-sider-drawer.d.ts +17 -0
  59. package/components/shell/phi-shell-sider-drawer.js +88 -0
  60. package/components/shell/use-phi-shell-header-bands.d.ts +5 -0
  61. package/components/shell/use-phi-shell-header-bands.js +64 -0
  62. package/components/shell/use-phi-shell-sticky-bottom.d.ts +18 -0
  63. package/components/shell/use-phi-shell-sticky-bottom.js +54 -0
  64. package/components/tables/client/phi-table-binding.d.ts +1 -0
  65. package/components/tables/client/phi-table-binding.js +22 -3
  66. package/components/trees/client/phi-tree-binding.d.ts +1 -0
  67. package/components/trees/client/phi-tree-binding.js +11 -2
  68. package/components/widgets/client/shared/phi-collection-provider.js +4 -3
  69. package/components/widgets/client/shared/phi-collection-view-binding.d.ts +1 -0
  70. package/components/widgets/client/shared/phi-collection-view-binding.js +16 -2
  71. package/components/widgets/client/shared/phi-command-buttons.js +6 -2
  72. package/components/widgets/config/background.d.ts +20 -0
  73. package/components/widgets/config/background.js +44 -2
  74. package/components/widgets/config/button-variant.d.ts +22 -4
  75. package/components/widgets/config/button-variant.js +24 -5
  76. package/components/widgets/config/common-action-field.d.ts +1 -1
  77. package/components/widgets/config/parser-primitives.js +4 -2
  78. package/components/widgets/config/theme-gradient.d.ts +11 -0
  79. package/components/widgets/config/theme-gradient.js +12 -0
  80. package/components/widgets/helpers/internal-reference-resolver.server.d.ts +1 -0
  81. package/components/widgets/helpers/internal-reference-resolver.server.js +4 -1
  82. package/components/widgets/label-sets/background.js +2 -0
  83. package/components/widgets/label-sets/geometry.js +2 -0
  84. package/components/widgets/label-sets/inspector.js +6 -0
  85. package/components/widgets/label-types/background.d.ts +1 -0
  86. package/components/widgets/label-types/background.js +1 -0
  87. package/components/widgets/label-types/common-controls.js +2 -2
  88. package/components/widgets/label-types/geometry.d.ts +1 -0
  89. package/components/widgets/label-types/geometry.js +1 -0
  90. package/components/widgets/label-types/inspector.d.ts +6 -0
  91. package/components/widgets/label-types/inspector.js +3 -0
  92. package/components/widgets/server/navigation-request.js +13 -1
  93. package/components/widgets/shared/card-body-client.d.ts +13 -0
  94. package/components/widgets/shared/card-body-client.js +40 -11
  95. package/components/widgets/shared/card-vocabulary.d.ts +36 -0
  96. package/components/widgets/shared/card-vocabulary.js +52 -0
  97. package/components/widgets/shared/collection-source-failure.d.ts +26 -0
  98. package/components/widgets/shared/collection-source-failure.js +42 -0
  99. package/components/widgets/shared/markdown-body-client.d.ts +29 -0
  100. package/components/widgets/shared/markdown-body-client.js +60 -5
  101. package/components/widgets/shared/markdown-image-vocabulary.d.ts +31 -0
  102. package/components/widgets/shared/markdown-image-vocabulary.js +68 -0
  103. package/components/widgets/shared/markdown-render.d.ts +5 -0
  104. package/components/widgets/shared/markdown-render.js +139 -11
  105. package/components/widgets/shared/markdown-sections.d.ts +40 -0
  106. package/components/widgets/shared/markdown-sections.js +111 -0
  107. package/components/widgets/shared/widget-failure-client.d.ts +10 -0
  108. package/components/widgets/shared/widget-failure-client.js +20 -0
  109. package/components/widgets/shared/widget-failure.d.ts +31 -0
  110. package/components/widgets/shared/widget-failure.js +20 -0
  111. package/components/widgets/shared/widget-failure.server.d.ts +9 -0
  112. package/components/widgets/shared/widget-failure.server.js +12 -0
  113. package/gateway/dashboard-card-memo.d.ts +3 -0
  114. package/gateway/dashboard-card-memo.js +25 -0
  115. package/helpers/cms-region-keys.d.ts +1 -1
  116. package/helpers/external-href.js +1 -1
  117. package/helpers/layout-style.d.ts +8 -4
  118. package/helpers/layout-style.js +3 -2
  119. package/helpers/mode-paint.d.ts +4 -0
  120. package/helpers/mode-paint.js +47 -0
  121. package/helpers/protected-mail.d.ts +16 -0
  122. package/helpers/protected-mail.js +81 -0
  123. package/helpers/surface-style.js +33 -11
  124. package/module-dashboard-cards.d.ts +1 -0
  125. package/module-dashboard-cards.js +1 -0
  126. package/module-records.d.ts +7 -0
  127. package/module-records.js +6 -0
  128. package/package.json +2 -2
  129. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +1 -1
  130. package/plugins/runtime-modules/builder/clients/inspector-surface-labels.js +1 -0
  131. package/plugins/runtime-modules/builder/clients/region-inspector.js +67 -3
  132. package/plugins/runtime-modules/builder/clients/runtime-module-authoring-boundary.js +1 -1
  133. package/plugins/runtime-modules/builder/controller/draft-command-controller.js +7 -4
  134. package/plugins/runtime-modules/builder/controller/page-controller.js +7 -0
  135. package/plugins/runtime-modules/builder/persistence.d.ts +3 -0
  136. package/plugins/runtime-modules/builder/persistence.js +9 -1
  137. package/plugins/runtime-modules/core/content-entries/record-source.server.d.ts +3 -1
  138. package/plugins/runtime-modules/core/content-entries/record-source.server.js +7 -4
  139. package/plugins/runtime-modules/core/widgets/button/client.js +2 -2
  140. package/plugins/runtime-modules/core/widgets/button/config.d.ts +40 -4
  141. package/plugins/runtime-modules/core/widgets/button/config.js +12 -0
  142. package/plugins/runtime-modules/core/widgets/card/config.d.ts +102 -1
  143. package/plugins/runtime-modules/core/widgets/card/config.js +60 -1
  144. package/plugins/runtime-modules/core/widgets/card/editor.js +17 -2
  145. package/plugins/runtime-modules/core/widgets/card/server.js +13 -1
  146. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.d.ts +4 -1
  147. package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +10 -3
  148. package/plugins/runtime-modules/core/widgets/collection-view/authoring.js +1 -1
  149. package/plugins/runtime-modules/core/widgets/collection-view/client.d.ts +3 -0
  150. package/plugins/runtime-modules/core/widgets/collection-view/client.js +47 -11
  151. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.d.ts +4 -1
  152. package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +2 -2
  153. package/plugins/runtime-modules/core/widgets/collection-view/plugin.js +3 -2
  154. package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +6 -1
  155. package/plugins/runtime-modules/core/widgets/collection-view/server.js +21 -3
  156. package/plugins/runtime-modules/core/widgets/entry-detail/plugin.js +1 -1
  157. package/plugins/runtime-modules/core/widgets/entry-detail/server.d.ts +3 -1
  158. package/plugins/runtime-modules/core/widgets/entry-detail/server.js +5 -2
  159. package/plugins/runtime-modules/core/widgets/entry-header/plugin.js +1 -1
  160. package/plugins/runtime-modules/core/widgets/entry-header/server.d.ts +3 -1
  161. package/plugins/runtime-modules/core/widgets/entry-header/server.js +5 -2
  162. package/plugins/runtime-modules/core/widgets/entry-list/plugin.js +1 -1
  163. package/plugins/runtime-modules/core/widgets/entry-list/server.d.ts +6 -3
  164. package/plugins/runtime-modules/core/widgets/entry-list/server.js +13 -6
  165. package/plugins/runtime-modules/core/widgets/entry-list/view.server.js +2 -1
  166. package/plugins/runtime-modules/core/widgets/gallery/config.d.ts +3 -3
  167. package/plugins/runtime-modules/core/widgets/gallery/plugin.js +1 -1
  168. package/plugins/runtime-modules/core/widgets/gallery/server.d.ts +5 -3
  169. package/plugins/runtime-modules/core/widgets/gallery/server.js +8 -6
  170. package/plugins/runtime-modules/core/widgets/header-navigation/client.d.ts +6 -1
  171. package/plugins/runtime-modules/core/widgets/header-navigation/client.js +40 -13
  172. package/plugins/runtime-modules/core/widgets/header-navigation/config.d.ts +26 -1
  173. package/plugins/runtime-modules/core/widgets/header-navigation/config.js +27 -0
  174. package/plugins/runtime-modules/core/widgets/header-navigation/plugin.js +1 -1
  175. package/plugins/runtime-modules/core/widgets/header-navigation/server.d.ts +2 -2
  176. package/plugins/runtime-modules/core/widgets/header-navigation/server.js +3 -1
  177. package/plugins/runtime-modules/core/widgets/image/client.js +11 -7
  178. package/plugins/runtime-modules/core/widgets/markdown/config.d.ts +16 -0
  179. package/plugins/runtime-modules/core/widgets/markdown/config.js +46 -1
  180. package/plugins/runtime-modules/core/widgets/markdown/server.js +22 -8
  181. package/plugins/runtime-modules/core/widgets/record/client.d.ts +4 -1
  182. package/plugins/runtime-modules/core/widgets/record/client.js +8 -3
  183. package/plugins/runtime-modules/core/widgets/record/plugin.js +3 -2
  184. package/plugins/runtime-modules/core/widgets/record/server.d.ts +3 -1
  185. package/plugins/runtime-modules/core/widgets/record/server.js +2 -2
  186. package/plugins/runtime-modules/core/widgets/segmented/client.js +1 -1
  187. package/plugins/runtime-modules/core/widgets/segmented/config.d.ts +21 -1
  188. package/plugins/runtime-modules/core/widgets/segmented/config.js +11 -1
  189. package/plugins/runtime-modules/core/widgets/simple-text/server.js +11 -1
  190. package/plugins/runtime-modules/core/widgets/switch/client.js +1 -1
  191. package/plugins/runtime-modules/core/widgets/switch/config.d.ts +19 -0
  192. package/plugins/runtime-modules/core/widgets/switch/config.js +11 -0
  193. package/plugins/runtime-modules/core/widgets/table/authoring.js +1 -1
  194. package/plugins/runtime-modules/core/widgets/table/client.d.ts +4 -1
  195. package/plugins/runtime-modules/core/widgets/table/client.js +16 -3
  196. package/plugins/runtime-modules/core/widgets/table/plugin.js +3 -2
  197. package/plugins/runtime-modules/core/widgets/table/server.d.ts +3 -1
  198. package/plugins/runtime-modules/core/widgets/table/server.js +2 -2
  199. package/plugins/runtime-modules/core/widgets/table/static-resource-editor.js +2 -1
  200. package/plugins/runtime-modules/core/widgets/timeline/authoring.js +1 -1
  201. package/plugins/runtime-modules/core/widgets/timeline/client.d.ts +1 -3
  202. package/plugins/runtime-modules/core/widgets/timeline/client.js +14 -4
  203. package/plugins/runtime-modules/core/widgets/tree/authoring.js +1 -1
  204. package/plugins/runtime-modules/core/widgets/tree/client.d.ts +4 -1
  205. package/plugins/runtime-modules/core/widgets/tree/client.js +13 -2
  206. package/plugins/runtime-modules/core/widgets/tree/plugin.js +3 -2
  207. package/plugins/runtime-modules/core/widgets/tree/server.d.ts +3 -1
  208. package/plugins/runtime-modules/core/widgets/tree/server.js +2 -2
  209. package/plugins/runtime-modules/theme/presets.d.ts +9 -1
  210. package/plugins/runtime-modules/theme/tour.d.ts +9 -1
  211. package/plugins/runtime-modules/theme/tour.js +10 -1
  212. package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +138 -7
  213. package/runtime-data-provider-client.d.ts +2 -0
  214. package/runtime-data-provider-client.js +7 -0
  215. package/styles/controls.css +118 -15
  216. package/styles/gradients.css +101 -0
  217. package/styles/layout.css +35 -0
  218. package/styles/root.css +18 -0
  219. package/styles/shell.css +206 -0
  220. package/theme/phi-button-shadow.d.ts +6 -0
  221. package/theme/phi-theme-gradients.d.ts +96 -0
  222. package/theme/phi-theme-gradients.js +245 -0
  223. package/theme/phi-theme-presets.d.ts +3 -0
  224. package/theme/phi-theme-presets.js +3 -0
  225. package/theme/phi-theme-tokens.d.ts +5 -1
  226. package/theme/phi-theme-tokens.js +14 -0
  227. package/theme/phi-tokens.d.ts +6 -0
  228. package/theme/phi-tokens.js +6 -0
  229. package/theme.d.ts +1 -0
  230. package/theme.js +6 -0
  231. package/types/cms-presets.d.ts +7 -0
  232. package/types/core-widget-placements.d.ts +8 -0
  233. package/types/layout-style.d.ts +9 -8
  234. package/types/layout-style.js +9 -8
  235. package/types/surface.d.ts +4 -0
  236. package/types/surface.js +4 -0
  237. package/types.d.ts +1 -1
  238. package/types.js +1 -1
@@ -0,0 +1,31 @@
1
+ /**
2
+ * How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
3
+ * shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
4
+ * golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
5
+ */
6
+ export declare const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS: readonly ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
7
+ export type PhiMarkdownImageAspectRatio = (typeof PHI_MARKDOWN_IMAGE_ASPECT_RATIOS)[number];
8
+ /** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
9
+ export declare const PHI_MARKDOWN_FIGURE_FLOATS: readonly ["start", "end", "none"];
10
+ export type PhiMarkdownFigureFloat = (typeof PHI_MARKDOWN_FIGURE_FLOATS)[number];
11
+ export declare function readPhiMarkdownImageAspectRatio(value: unknown): PhiMarkdownImageAspectRatio | undefined;
12
+ /** A step as a number, width over height; `auto` has none -- the picture decides. */
13
+ export declare function resolvePhiMarkdownImageAspectRatioValue(ratio: PhiMarkdownImageAspectRatio | undefined): number | null;
14
+ /** A step as CSS writes it (`16 / 9`); `auto` has none. */
15
+ export declare function resolvePhiMarkdownImageAspectRatioCss(ratio: PhiMarkdownImageAspectRatio | undefined): string | null;
16
+ /**
17
+ * A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
18
+ * `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
19
+ * later release learns more words for still names its Asset today.
20
+ */
21
+ export declare function readPhiMarkdownImageAddress(url: string): {
22
+ reference: string;
23
+ aspectRatio?: PhiMarkdownImageAspectRatio;
24
+ float?: PhiMarkdownFigureFloat;
25
+ };
26
+ /**
27
+ * How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
28
+ * (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
29
+ * reading column's.
30
+ */
31
+ export declare function resolvePhiMarkdownFigureSizes(float: PhiMarkdownFigureFloat): "(max-width: 768px) 100vw, 1120px" | "(max-width: 560px) 100vw, 440px";
@@ -0,0 +1,68 @@
1
+ /*
2
+ * How a Markdown text sets its pictures, apart from the Widget's Client half: the render on the server and
3
+ * the Widget's definition read these, and a value imported from the Client file would make it a client
4
+ * reference of every route.
5
+ *
6
+ * Two places say it, and the nearer one wins. The Widget states what every picture in its text does -- the
7
+ * Inspector's "Image proportion" and "Image Float" -- and a picture that needs something else says so in its
8
+ * own address, after the Asset: `![Server](phis:asset/12?ratio=16:9&float=none)`. The address stays a
9
+ * `phis:asset/<id>` reference for everything that reads one (the server's reference index finds the id at
10
+ * its start), and it is plain Markdown, so a translation carries it through untouched.
11
+ */
12
+ import { PHI_GOLDEN_RATIO } from "../../../theme/phi-tokens";
13
+ /**
14
+ * How tall a picture stands, as a proportion of its width. `auto` is the picture's own proportion -- a text
15
+ * shows what was put in it; a step crops into that box around the picture's focal rectangle. `phi` is the
16
+ * golden rectangle, φ : 1 (`PHI_GOLDEN_RATIO`), between 3:2 and 16:9.
17
+ */
18
+ export const PHI_MARKDOWN_IMAGE_ASPECT_RATIOS = ["auto", "phi", "3:2", "4:3", "16:9", "2:1", "1:1"];
19
+ /** Where a picture stands: at an edge with the text flowing past it, or on a line of its own (`none`). */
20
+ export const PHI_MARKDOWN_FIGURE_FLOATS = ["start", "end", "none"];
21
+ export function readPhiMarkdownImageAspectRatio(value) {
22
+ return PHI_MARKDOWN_IMAGE_ASPECT_RATIOS.find((ratio) => ratio === value);
23
+ }
24
+ function readPhiMarkdownFigureFloat(value) {
25
+ return PHI_MARKDOWN_FIGURE_FLOATS.find((float) => float === value);
26
+ }
27
+ /** A step as a number, width over height; `auto` has none -- the picture decides. */
28
+ export function resolvePhiMarkdownImageAspectRatioValue(ratio) {
29
+ if (ratio == null || ratio === "auto")
30
+ return null;
31
+ if (ratio === "phi")
32
+ return PHI_GOLDEN_RATIO;
33
+ const [width, height] = ratio.split(":").map(Number);
34
+ return width / height;
35
+ }
36
+ /** A step as CSS writes it (`16 / 9`); `auto` has none. */
37
+ export function resolvePhiMarkdownImageAspectRatioCss(ratio) {
38
+ const value = resolvePhiMarkdownImageAspectRatioValue(ratio);
39
+ if (value == null)
40
+ return null;
41
+ return ratio === "phi" ? `${PHI_GOLDEN_RATIO.toFixed(6)} / 1` : ratio.replace(":", " / ");
42
+ }
43
+ /**
44
+ * A picture's address read apart: the reference, and what the picture says for itself. Only `ratio` and
45
+ * `float` are read; anything else after the `?` is left out of the reference and ignored, so an address a
46
+ * later release learns more words for still names its Asset today.
47
+ */
48
+ export function readPhiMarkdownImageAddress(url) {
49
+ const question = url.indexOf("?");
50
+ if (question < 0)
51
+ return { reference: url };
52
+ const params = new URLSearchParams(url.slice(question + 1));
53
+ const aspectRatio = readPhiMarkdownImageAspectRatio(params.get("ratio"));
54
+ const float = readPhiMarkdownFigureFloat(params.get("float"));
55
+ return {
56
+ reference: url.slice(0, question),
57
+ ...(aspectRatio ? { aspectRatio } : {}),
58
+ ...(float ? { float } : {}),
59
+ };
60
+ }
61
+ /**
62
+ * How wide a picture is drawn, for the image optimiser: beside the text its golden share of the column
63
+ * (`styles/controls.css`, about 0.38 of a reading column of at most 1120 px), on a line of its own the
64
+ * reading column's.
65
+ */
66
+ export function resolvePhiMarkdownFigureSizes(float) {
67
+ return float === "none" ? "(max-width: 768px) 100vw, 1120px" : "(max-width: 560px) 100vw, 440px";
68
+ }
@@ -2,6 +2,8 @@ import type { PhiBlockRuntime, PhiRenderableBlockRenderMode } from "../../../typ
2
2
  import type { PhiCmsResolvedContent } from "../../../types/cms";
3
3
  import type { PhiMarkdownTocHeading } from "../../../types/markdown";
4
4
  import type { PhiMarkdownBlock } from "./markdown-body-client";
5
+ import type { PhiMarkdownImageFloat } from "../../../types/core-widget-placements";
6
+ import { type PhiMarkdownImageAspectRatio } from "./markdown-image-vocabulary";
5
7
  /**
6
8
  * Where Markdown comes from and how it is turned into blocks: inline text, a stored content field, or a
7
9
  * document fetched by URL, translated or not, with heading ids under a prefix of its own.
@@ -32,6 +34,9 @@ export type PhiMarkdownSourceConfig = {
32
34
  * header -- starts at `h2`, so `#` does not draw a second title of the same size. The level stops at 5.
33
35
  */
34
36
  headingOffset?: number;
37
+ /** What every picture in the text does, unless its own address says otherwise (`markdown-image-vocabulary.ts`). */
38
+ imageAspectRatio?: PhiMarkdownImageAspectRatio;
39
+ imageFloat?: PhiMarkdownImageFloat;
35
40
  };
36
41
  export type MarkdownRenderData = {
37
42
  blocks: PhiMarkdownBlock[];
@@ -3,9 +3,13 @@ import { unified } from "unified";
3
3
  import remarkParse from "remark-parse";
4
4
  import remarkGfm from "remark-gfm";
5
5
  import { trBulk, trBulkForLocale } from "../../../server-helpers/translate";
6
+ import { resolvePhiImagePresentation } from "../../media/image-presentation";
7
+ import { isPhiMediaSvgContentType } from "../../../constants/media";
8
+ import { readPhiMarkdownImageAddress, resolvePhiMarkdownImageAspectRatioCss, resolvePhiMarkdownImageAspectRatioValue, } from "./markdown-image-vocabulary";
6
9
  import { resolvePhiCodeLanguage, tokenizePhiCode } from "./markdown-code-tokens";
7
10
  import { readPhiInternalReference } from "../../../types/references";
8
11
  import { resolvePhiWidgetInternalReferences } from "../helpers/internal-reference-resolver.server";
12
+ import { protectPhiMailHref, splitPhiMailAddresses } from "../../../helpers/protected-mail";
9
13
  import { resolvePhiWidgetSourceUrl } from "../helpers/widget-source-url";
10
14
  const MARKDOWN_DEFAULT_REVALIDATE_SECONDS = 14400;
11
15
  function normalizeMarkdownSourceUrl(sourceUrl, publicUrl) {
@@ -77,11 +81,24 @@ function resolveExternalDocumentUrl(value, sourceUrl) {
77
81
  return null;
78
82
  }
79
83
  }
80
- function projectExternalMarkdownNodes(nodes, sourceUrl) {
84
+ /*
85
+ * The address a reader is sent to for the document the text was fetched from. GitHub serves a file's
86
+ * bytes on one host and its page on another; the bytes are what the Widget reads and what a picture
87
+ * needs, but a link in the text means the page -- a neighbouring document opened as raw text in a new
88
+ * tab is the source, not the document. Any other host is its own page.
89
+ */
90
+ function readExternalDocumentPageUrl(sourceUrl) {
91
+ const githubRawMatch = sourceUrl.match(/^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)\/(.+)$/u);
92
+ if (!githubRawMatch)
93
+ return sourceUrl;
94
+ const [, owner, repo, ref, path] = githubRawMatch;
95
+ return `https://github.com/${owner}/${repo}/blob/${ref}/${path}`;
96
+ }
97
+ function projectExternalMarkdownNodes(nodes, sourceUrl, pageUrl = readExternalDocumentPageUrl(sourceUrl)) {
81
98
  return (nodes ?? []).flatMap((node) => {
82
- const children = projectExternalMarkdownNodes(node.children, sourceUrl);
99
+ const children = projectExternalMarkdownNodes(node.children, sourceUrl, pageUrl);
83
100
  if (node.type === "link") {
84
- const url = resolveExternalDocumentUrl(node.url ?? "", sourceUrl);
101
+ const url = resolveExternalDocumentUrl(node.url ?? "", pageUrl);
85
102
  return url ? [{ ...node, url, children }] : children;
86
103
  }
87
104
  if (node.type === "image") {
@@ -94,10 +111,11 @@ function projectExternalMarkdownNodes(nodes, sourceUrl) {
94
111
  async function projectInternalMarkdownNodes(tree, runtime) {
95
112
  const pageReferences = [];
96
113
  const assetIds = [];
114
+ const figures = new Map();
97
115
  const collect = (nodes) => {
98
116
  for (const node of nodes ?? []) {
99
117
  if (node.type === "link" || node.type === "image") {
100
- const reference = readPhiInternalReference(node.url);
118
+ const reference = readPhiInternalReference(node.type === "image" ? readPhiMarkdownImageAddress(node.url ?? "").reference : node.url);
101
119
  if (reference?.kind === "page")
102
120
  pageReferences.push(reference.reference);
103
121
  if (reference?.kind === "asset")
@@ -121,10 +139,23 @@ async function projectInternalMarkdownNodes(tree, runtime) {
121
139
  return [{ ...node, children }];
122
140
  }
123
141
  if (node.type === "image") {
124
- const reference = readPhiInternalReference(node.url);
142
+ const address = readPhiMarkdownImageAddress(node.url ?? "");
143
+ const reference = readPhiInternalReference(address.reference);
125
144
  if (reference?.kind === "asset") {
126
- const src = resolved.assetUrls.get(reference.assetId);
127
- return src ? [{ ...node, url: src, children }] : [];
145
+ const asset = resolved.assets.get(reference.assetId);
146
+ if (!asset)
147
+ return [];
148
+ /*
149
+ * Each picture gets an address of its own, so two pictures of one Asset can say different things:
150
+ * the fragment never reaches the server, and it travels with the address through a translation.
151
+ */
152
+ const src = `${asset.deliveryUrl}#phi-figure-${figures.size}`;
153
+ figures.set(src, {
154
+ asset,
155
+ ...(address.aspectRatio ? { aspectRatio: address.aspectRatio } : {}),
156
+ ...(address.float ? { float: address.float } : {}),
157
+ });
158
+ return [{ ...node, url: src, children }];
128
159
  }
129
160
  if (!/^https?:/iu.test(node.url ?? "") && !PHI_INLINE_IMAGE_DATA_URL.test(node.url ?? ""))
130
161
  return [];
@@ -133,6 +164,57 @@ async function projectInternalMarkdownNodes(tree, runtime) {
133
164
  return [{ ...node, ...(node.children ? { children } : {}) }];
134
165
  });
135
166
  tree.children = project(tree.children);
167
+ return figures;
168
+ }
169
+ /*
170
+ * A paragraph that is one Media picture and nothing else is a figure: a block of its own, drawn by the
171
+ * house's picture Control -- optimised, sized, its box reserved and its corners the Theme's. A picture in
172
+ * the middle of a sentence, or one on somebody else's server, stays the plain picture it was.
173
+ */
174
+ function promoteMarkdownFigures(blocks, figures, defaults) {
175
+ if (figures.size === 0)
176
+ return blocks;
177
+ return blocks.map((block) => {
178
+ if (block.kind === "blockquote")
179
+ return { ...block, children: promoteMarkdownFigures(block.children, figures, defaults) };
180
+ if (block.kind === "list")
181
+ return { ...block, items: block.items.map((item) => promoteMarkdownFigures(item, figures, defaults)) };
182
+ if (block.kind !== "paragraph")
183
+ return block;
184
+ const content = block.inlines.filter((inline) => !(inline.kind === "text" && !inline.text.trim()));
185
+ const only = content.length === 1 ? content[0] : null;
186
+ const source = only?.kind === "image" ? figures.get(only.src) : undefined;
187
+ if (!only || only.kind !== "image" || !source)
188
+ return block;
189
+ return { kind: "image", image: buildMarkdownFigure(only, source, defaults) };
190
+ });
191
+ }
192
+ function buildMarkdownFigure(image, source, defaults) {
193
+ const aspectRatio = source.aspectRatio ?? defaults.aspectRatio ?? "auto";
194
+ const frameAspectRatio = resolvePhiMarkdownImageAspectRatioValue(aspectRatio);
195
+ const { asset } = source;
196
+ const presentation = resolvePhiImagePresentation({
197
+ sourceKind: "asset",
198
+ assetId: asset.id,
199
+ variantKey: null,
200
+ variantVersion: asset.variantVersion,
201
+ deliveryRevision: asset.deliveryRevision,
202
+ originalUrl: asset.deliveryUrl,
203
+ focalRect: asset.focalRect,
204
+ sourceWidth: asset.width,
205
+ sourceHeight: asset.height,
206
+ frameAspectRatio,
207
+ });
208
+ return {
209
+ presentation,
210
+ alt: (image.alt || asset.altText || "").trim(),
211
+ ...(image.title ? { title: image.title } : {}),
212
+ blurDataUrl: asset.blurDataUrl,
213
+ // Only a public Asset resolves here; the optimiser takes every original that is not an SVG.
214
+ optimizable: !isPhiMediaSvgContentType(asset.contentType),
215
+ aspectRatio: resolvePhiMarkdownImageAspectRatioCss(aspectRatio),
216
+ float: source.float ?? defaults.float ?? "none",
217
+ };
136
218
  }
137
219
  function mapInlineNodes(nodes) {
138
220
  return (nodes ?? []).flatMap((node) => {
@@ -504,20 +586,24 @@ export async function resolveMarkdownRenderData(config, runtime) {
504
586
  */
505
587
  config?.sourceLocale?.trim() || undefined, sourceMode, sourceMode === "url" && config?.sourceUrl
506
588
  ? normalizeMarkdownSourceUrl(config.sourceUrl, runtime?.site.publicUrl)
507
- : null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0);
589
+ : null, runtime, config?.extent ?? "document", config?.headingOffset ?? 0, {
590
+ ...(config?.imageAspectRatio ? { aspectRatio: config.imageAspectRatio } : {}),
591
+ ...(config?.imageFloat ? { float: config.imageFloat } : {}),
592
+ });
508
593
  }
509
- async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0) {
594
+ async function resolveMarkdownRenderDataFromSource(markdown, translate, headingIdPrefix, sourceLocale, sourceMode = "inline", sourceUrl = null, runtime, extent = "document", headingOffset = 0, imageDefaults = {}) {
510
595
  const tree = parseMarkdown(markdown);
511
596
  if (extent === "first-paragraph") {
512
597
  // Cut by the parser's own reading, never by blank lines: a fence or a list may hold those too.
513
598
  const paragraph = tree.children?.find((node) => node.type === "paragraph");
514
599
  tree.children = paragraph ? [paragraph] : [];
515
600
  }
601
+ let figures = new Map();
516
602
  if (sourceMode === "url" && sourceUrl) {
517
603
  tree.children = projectExternalMarkdownNodes(tree.children, sourceUrl);
518
604
  }
519
605
  else if (runtime) {
520
- await projectInternalMarkdownNodes(tree, runtime);
606
+ figures = await projectInternalMarkdownNodes(tree, runtime);
521
607
  }
522
608
  const context = {
523
609
  headings: [],
@@ -526,7 +612,7 @@ async function resolveMarkdownRenderDataFromSource(markdown, translate, headingI
526
612
  headingOffset,
527
613
  };
528
614
  const inlineMap = await buildMarkdownInlineMap(tree, translate, sourceLocale, runtime?.locale.current);
529
- const blocks = mapBlockNodes(tree.children, context, inlineMap);
615
+ const blocks = promoteMarkdownFigures(protectMarkdownMail(mapBlockNodes(tree.children, context, inlineMap)), figures, imageDefaults);
530
616
  return { blocks, headings: context.headings };
531
617
  }
532
618
  /** remark-gfm states `left`, `center`, `right` or nothing; nothing else can come out of its parser. */
@@ -539,3 +625,45 @@ function readMarkdownTableAlign(value) {
539
625
  }
540
626
  throw new Error(`Unknown Markdown table alignment "${value}".`);
541
627
  }
628
+ /*
629
+ * Every address in the finished blocks, protected (`helpers/protected-mail.ts`): a `mailto:` link's
630
+ * target, and an address written as text, a link's own label among them. Once, over the blocks, because
631
+ * they are built along two roads -- straight from the tree and back out of a translation.
632
+ */
633
+ function protectMarkdownMail(blocks) {
634
+ return blocks.map((block) => {
635
+ switch (block.kind) {
636
+ case "heading":
637
+ case "paragraph":
638
+ return { ...block, inlines: protectMarkdownInlineMail(block.inlines) };
639
+ case "blockquote":
640
+ return { ...block, children: protectMarkdownMail(block.children) };
641
+ case "list":
642
+ return { ...block, items: block.items.map(protectMarkdownMail) };
643
+ case "table":
644
+ return {
645
+ ...block,
646
+ header: block.header.map(protectMarkdownInlineMail),
647
+ rows: block.rows.map((cells) => cells.map(protectMarkdownInlineMail)),
648
+ };
649
+ default:
650
+ return block;
651
+ }
652
+ });
653
+ }
654
+ function protectMarkdownInlineMail(inlines) {
655
+ return inlines.flatMap((inline) => {
656
+ switch (inline.kind) {
657
+ case "text":
658
+ return splitPhiMailAddresses(inline.text).map((segment) => segment.kind === "mail" ? { kind: "mail_text", token: segment.token } : { kind: "text", text: segment.text });
659
+ case "link":
660
+ return [{ ...inline, href: protectPhiMailHref(inline.href), children: protectMarkdownInlineMail(inline.children) }];
661
+ case "strong":
662
+ case "emphasis":
663
+ case "delete":
664
+ return [{ ...inline, children: protectMarkdownInlineMail(inline.children) }];
665
+ default:
666
+ return [inline];
667
+ }
668
+ });
669
+ }
@@ -0,0 +1,40 @@
1
+ import type { PhiMarkdownBlock } from "./markdown-body-client";
2
+ /** Whether the text's sections fold, and how: each on its own, or one open at a time. */
3
+ export declare const PHI_MARKDOWN_FOLD_SECTIONS: readonly ["none", "independent", "accordion"];
4
+ export type PhiMarkdownFoldSections = (typeof PHI_MARKDOWN_FOLD_SECTIONS)[number];
5
+ export declare function readPhiMarkdownFoldSections(value: unknown): PhiMarkdownFoldSections | undefined;
6
+ type PhiMarkdownHeadingBlock = Extract<PhiMarkdownBlock, {
7
+ kind: "heading";
8
+ }>;
9
+ export type PhiMarkdownSection = {
10
+ heading: PhiMarkdownHeadingBlock;
11
+ blocks: PhiMarkdownBlock[];
12
+ };
13
+ export type PhiMarkdownSegment = {
14
+ kind: "text";
15
+ blocks: PhiMarkdownBlock[];
16
+ } | {
17
+ kind: "sections";
18
+ sections: PhiMarkdownSection[];
19
+ };
20
+ /** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
21
+ export declare function resolvePhiMarkdownFoldLevel(headingOffset: number | undefined): number;
22
+ /** The text in order: open runs of blocks, and runs of sections that fold. */
23
+ export declare function splitPhiMarkdownSegments(blocks: readonly PhiMarkdownBlock[], level: number): PhiMarkdownSegment[];
24
+ /**
25
+ * The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
26
+ * Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
27
+ */
28
+ export declare function buildPhiMarkdownFaqStructuredData(blocks: readonly PhiMarkdownBlock[], level: number): {
29
+ "@context": string;
30
+ "@type": string;
31
+ mainEntity: {
32
+ "@type": string;
33
+ name: string;
34
+ acceptedAnswer: {
35
+ "@type": string;
36
+ text: string;
37
+ };
38
+ }[];
39
+ } | null;
40
+ export {};
@@ -0,0 +1,111 @@
1
+ /*
2
+ * A Markdown text read as sections that fold (`foldSections` on the Markdown Widget): every heading of the
3
+ * text's second level -- `##` as written, moved down with the text's `headingOffset` -- opens a section
4
+ * that runs to the next heading of that level or above. What stands before the first one, and what follows
5
+ * a heading above the level, stays open text. The FAQ case: a question is a `##`, its answer what follows.
6
+ *
7
+ * Pure, and apart from the Client half, because both halves read it: the Client draws the sections, the
8
+ * server writes the same questions and answers as schema.org `FAQPage` data.
9
+ */
10
+ /** Whether the text's sections fold, and how: each on its own, or one open at a time. */
11
+ export const PHI_MARKDOWN_FOLD_SECTIONS = ["none", "independent", "accordion"];
12
+ export function readPhiMarkdownFoldSections(value) {
13
+ return PHI_MARKDOWN_FOLD_SECTIONS.find((mode) => mode === value);
14
+ }
15
+ /** The level that folds: `##` as written, after the text's own offset; a heading never goes below 5. */
16
+ export function resolvePhiMarkdownFoldLevel(headingOffset) {
17
+ return Math.min(5, 2 + Math.max(0, headingOffset ?? 0));
18
+ }
19
+ /** The text in order: open runs of blocks, and runs of sections that fold. */
20
+ export function splitPhiMarkdownSegments(blocks, level) {
21
+ const segments = [];
22
+ let current = null;
23
+ const textRun = () => {
24
+ const last = segments.at(-1);
25
+ if (last?.kind === "text")
26
+ return last.blocks;
27
+ const run = [];
28
+ segments.push({ kind: "text", blocks: run });
29
+ return run;
30
+ };
31
+ for (const block of blocks) {
32
+ if (block.kind === "heading" && block.level === level) {
33
+ current = { heading: block, blocks: [] };
34
+ const last = segments.at(-1);
35
+ if (last?.kind === "sections")
36
+ last.sections.push(current);
37
+ else
38
+ segments.push({ kind: "sections", sections: [current] });
39
+ continue;
40
+ }
41
+ if (block.kind === "heading" && block.level < level)
42
+ current = null;
43
+ if (current)
44
+ current.blocks.push(block);
45
+ else
46
+ textRun().push(block);
47
+ }
48
+ return segments;
49
+ }
50
+ /** The words of a run of inlines, as a reader would read them aloud; a protected address is left out. */
51
+ function readPhiMarkdownInlineText(inlines) {
52
+ return inlines.map((inline) => {
53
+ switch (inline.kind) {
54
+ case "text":
55
+ case "inline_code":
56
+ return inline.text;
57
+ case "strong":
58
+ case "emphasis":
59
+ case "delete":
60
+ case "link":
61
+ return readPhiMarkdownInlineText(inline.children);
62
+ case "image":
63
+ return inline.alt;
64
+ case "break":
65
+ return "\n";
66
+ default:
67
+ return "";
68
+ }
69
+ }).join("");
70
+ }
71
+ function readPhiMarkdownBlockText(block) {
72
+ switch (block.kind) {
73
+ case "heading":
74
+ case "paragraph":
75
+ return readPhiMarkdownInlineText(block.inlines);
76
+ case "blockquote":
77
+ return block.children.map(readPhiMarkdownBlockText).join("\n");
78
+ case "list":
79
+ return block.items.map((item) => item.map(readPhiMarkdownBlockText).join(" ")).join("\n");
80
+ case "table":
81
+ return [block.header, ...block.rows].map((cells) => cells.map(readPhiMarkdownInlineText).join(" | ")).join("\n");
82
+ case "image":
83
+ return block.image.alt;
84
+ default:
85
+ return "";
86
+ }
87
+ }
88
+ /**
89
+ * The folding sections as schema.org `FAQPage` data: each heading a question, what follows it the answer.
90
+ * Absent when the text has no section with an answer -- an empty FAQ is not a claim worth making.
91
+ */
92
+ export function buildPhiMarkdownFaqStructuredData(blocks, level) {
93
+ const questions = splitPhiMarkdownSegments(blocks, level)
94
+ .flatMap((segment) => segment.kind === "sections" ? segment.sections : [])
95
+ .map((section) => ({
96
+ name: readPhiMarkdownInlineText(section.heading.inlines).trim(),
97
+ text: section.blocks.map(readPhiMarkdownBlockText).filter((line) => line.trim()).join("\n").trim(),
98
+ }))
99
+ .filter((entry) => entry.name && entry.text);
100
+ if (questions.length === 0)
101
+ return null;
102
+ return {
103
+ "@context": "https://schema.org",
104
+ "@type": "FAQPage",
105
+ mainEntity: questions.map((entry) => ({
106
+ "@type": "Question",
107
+ name: entry.name,
108
+ acceptedAnswer: { "@type": "Answer", text: entry.text },
109
+ })),
110
+ };
111
+ }
@@ -0,0 +1,10 @@
1
+ import { type PhiWidgetFailureProps } from "./widget-failure";
2
+ /**
3
+ * A Widget's data or configuration failure, found in the browser -- a Provider the Area does not offer,
4
+ * a read that failed after hydration.
5
+ *
6
+ * The warning is written from an effect, once for each distinct failure while the Widget stays mounted:
7
+ * a Client re-renders for reasons that have nothing to do with the failure, and a line per render would
8
+ * bury the one that matters. See `PhiWidgetFailureProps` for what counts and who sees it.
9
+ */
10
+ export declare function PhiWidgetFailure(props: PhiWidgetFailureProps): import("react").JSX.Element | null;
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import { useEffect, useEffectEvent } from "react";
3
+ import { logPhiWidgetFailure, renderPhiWidgetFailureNotice } from "./widget-failure";
4
+ /**
5
+ * A Widget's data or configuration failure, found in the browser -- a Provider the Area does not offer,
6
+ * a read that failed after hydration.
7
+ *
8
+ * The warning is written from an effect, once for each distinct failure while the Widget stays mounted:
9
+ * a Client re-renders for reasons that have nothing to do with the failure, and a line per render would
10
+ * bury the one that matters. See `PhiWidgetFailureProps` for what counts and who sees it.
11
+ */
12
+ export function PhiWidgetFailure(props) {
13
+ const { renderMode, widgetType, widgetId, title, description } = props;
14
+ // `error` is read, not watched: it is a new object whenever the same failure is raised again.
15
+ const log = useEffectEvent(() => logPhiWidgetFailure(props));
16
+ useEffect(() => {
17
+ log();
18
+ }, [description, renderMode, title, widgetId, widgetType]);
19
+ return renderPhiWidgetFailureNotice(props);
20
+ }
@@ -0,0 +1,31 @@
1
+ import type { PhiCmsInstanceId } from "../../../types/cms-instance-id";
2
+ import type { PhiRenderableBlockRenderMode } from "../../../types/renderable-block";
3
+ /**
4
+ * A Widget that cannot show what it was placed to show, because its data or its configuration failed:
5
+ * the Provider it is bound to is not offered, the binding does not hold, the record cannot be read, the
6
+ * renderer it names is gone, the read itself failed.
7
+ *
8
+ * Said to the person who can do something about it, as the renderer says an unrenderable block
9
+ * (`renderCmsDiagnostic`). In the Builder that is the author, and the card stands in the Widget's own
10
+ * place with the cause. On a live page -- a revision preview is one -- it is nobody: a visitor cannot
11
+ * rebind a Provider, and a heading over an error, or over an empty frame, reads as a broken Site or as
12
+ * one that published nothing. So the Widget is absent and the rest of the page stands. The warning is
13
+ * written either way, which is where an operator finds it.
14
+ *
15
+ * What a visitor is meant to read -- a form's own answer, an empty state, a refusal addressed to them --
16
+ * is content, not a failure, and does not come here.
17
+ */
18
+ export type PhiWidgetFailureProps = {
19
+ renderMode: PhiRenderableBlockRenderMode;
20
+ /** The Widget type, as the log names it; the card does not, the author already knows what they placed. */
21
+ widgetType: string;
22
+ widgetId?: PhiCmsInstanceId | null;
23
+ title: string;
24
+ description?: string | null;
25
+ /** What was thrown, for the log only; the card says `title` and `description`. */
26
+ error?: unknown;
27
+ };
28
+ export declare const PHI_WIDGET_FAILURE_LOG_EVENT = "cms.widget.unavailable";
29
+ export declare function logPhiWidgetFailure({ renderMode, widgetType, widgetId, title, description, error, }: PhiWidgetFailureProps): void;
30
+ /** The card itself, or nothing on a live page. Both variants draw through this, so they cannot drift. */
31
+ export declare function renderPhiWidgetFailureNotice({ renderMode, widgetType, widgetId, title, description, }: PhiWidgetFailureProps): import("react").JSX.Element | null;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { logRuntimeEvent } from "../../../net/log";
3
+ import { PhiAlertControl } from "../../controls/phi-alert-control";
4
+ export const PHI_WIDGET_FAILURE_LOG_EVENT = "cms.widget.unavailable";
5
+ export function logPhiWidgetFailure({ renderMode, widgetType, widgetId, title, description, error, }) {
6
+ logRuntimeEvent("warn", PHI_WIDGET_FAILURE_LOG_EVENT, {
7
+ message: `Widget "${widgetType}" is unavailable: ${title}${description ? ` ${description}` : ""}`,
8
+ targetType: "widget",
9
+ targetId: widgetId == null ? null : String(widgetId),
10
+ error,
11
+ meta: { widgetType, title, description: description ?? null, renderMode },
12
+ });
13
+ }
14
+ /** The card itself, or nothing on a live page. Both variants draw through this, so they cannot drift. */
15
+ export function renderPhiWidgetFailureNotice({ renderMode, widgetType, widgetId, title, description, }) {
16
+ if (renderMode === "live") {
17
+ return null;
18
+ }
19
+ return (_jsx("div", { "data-phi-widget-failure": widgetType, "data-phi-widget-failure-id": widgetId == null ? undefined : String(widgetId), children: _jsx(PhiAlertControl, { level: "error", showIcon: true, title: title, description: description ?? undefined }) }));
20
+ }
@@ -0,0 +1,9 @@
1
+ import "server-only";
2
+ import { type PhiWidgetFailureProps } from "./widget-failure";
3
+ /**
4
+ * A Widget's data or configuration failure, decided while the page is drawn on the server.
5
+ *
6
+ * The warning is written here, during the render, because this render happens once per request and on
7
+ * the machine whose log an operator reads. See `PhiWidgetFailureProps` for what counts and who sees it.
8
+ */
9
+ export declare function PhiWidgetFailureServer(props: PhiWidgetFailureProps): import("react").JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import "server-only";
2
+ import { logPhiWidgetFailure, renderPhiWidgetFailureNotice } from "./widget-failure";
3
+ /**
4
+ * A Widget's data or configuration failure, decided while the page is drawn on the server.
5
+ *
6
+ * The warning is written here, during the render, because this render happens once per request and on
7
+ * the machine whose log an operator reads. See `PhiWidgetFailureProps` for what counts and who sees it.
8
+ */
9
+ export function PhiWidgetFailureServer(props) {
10
+ logPhiWidgetFailure(props);
11
+ return renderPhiWidgetFailureNotice(props);
12
+ }
@@ -0,0 +1,3 @@
1
+ import "server-only";
2
+ import type { PhiDashboardCardContext } from "../types/dashboard-cards";
3
+ export declare function definePhiDashboardCardRead<TResult>(load: (context: PhiDashboardCardContext) => Promise<TResult>): (context: PhiDashboardCardContext) => Promise<TResult>;
@@ -0,0 +1,25 @@
1
+ import "server-only";
2
+ /*
3
+ * A read that several cards of one Dashboard ask for, done once for that Dashboard.
4
+ *
5
+ * The cards of a list request are resolved side by side in a Route Handler, which is outside a render,
6
+ * so `definePhiRequestMemo` (React's request scope) loads every time there. What they do share is the
7
+ * card context: the route resolves it once and hands the same object to every card it resolves. Keying
8
+ * by that object is the request scope a card has -- four cards reading one Add-on route make one call,
9
+ * and a card refreshed on its own gets a fresh context and so a fresh read. Nothing outlives the
10
+ * context, so nothing goes stale.
11
+ *
12
+ * `load` must answer from the context alone; anything else a card wants to vary belongs in its own call.
13
+ * A rejected load stays rejected for that context, so every card sharing the read reports the same error.
14
+ */
15
+ export function definePhiDashboardCardRead(load) {
16
+ const reads = new WeakMap();
17
+ return (context) => {
18
+ let result = reads.get(context);
19
+ if (!result) {
20
+ result = load(context);
21
+ reads.set(context, result);
22
+ }
23
+ return result;
24
+ };
25
+ }
@@ -33,5 +33,5 @@ export declare function resolvePhiCmsRegionOwnership(regionKey: string | null |
33
33
  * know is not a placement anybody chose -- refusing it would hide Widgets over a typo.
34
34
  */
35
35
  export declare function phiCmsRegionAcceptsWidget(regionKey: string | null | undefined, required: PhiCmsRegionOwnership | null | undefined): boolean;
36
- export declare function resolvePhiCmsRegionType(regionKey: string | null | undefined): 10 | 40 | 12 | 50 | 11 | 20 | 21 | 25 | 30 | 39 | 41;
36
+ export declare function resolvePhiCmsRegionType(regionKey: string | null | undefined): 11 | 10 | 40 | 12 | 50 | 20 | 21 | 25 | 30 | 39 | 41;
37
37
  export declare function resolvePhiCmsRegionKey(regionType: number | null | undefined): "content" | "header_top" | "header_main" | "header_bottom" | "sider_left" | "sider_right" | "hero" | "footer_top" | "footer_main" | "footer_bottom" | "drawer_right" | undefined;
@@ -1,3 +1,3 @@
1
1
  export function isPhiExternalHref(href) {
2
- return /^(https?:)?\/\//.test(href) || href.startsWith("mailto:") || href.startsWith("tel:");
2
+ return /^(https?:)?\/\//.test(href) || href.startsWith("mailto:") || href.startsWith("tel:") || href.startsWith("phi-mail:");
3
3
  }