@phis/ui 0.4.6 → 0.4.8

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 (69) hide show
  1. package/components/controls/phi-text-control.d.ts +6 -1
  2. package/components/controls/phi-text-control.js +2 -1
  3. package/components/regions/presets/phi-area-shell-preset-nodes.d.ts +5 -0
  4. package/components/regions/presets/phi-area-shell-preset-nodes.js +17 -2
  5. package/components/widgets/label-sets/search-results.d.ts +4 -0
  6. package/components/widgets/label-sets/search-results.js +35 -0
  7. package/components/widgets/label-types/search-results.d.ts +15 -0
  8. package/components/widgets/label-types/search-results.js +10 -0
  9. package/constants/cms-widget-types.d.ts +2 -0
  10. package/constants/cms-widget-types.js +4 -0
  11. package/gateway/site-area.d.ts +10 -7
  12. package/gateway/site-area.js +13 -11
  13. package/gateway/site-config.js +7 -1
  14. package/gateway/site-read-marker-listeners.d.ts +24 -0
  15. package/gateway/site-read-marker-listeners.js +22 -0
  16. package/gateway/site-search.d.ts +37 -0
  17. package/gateway/site-search.js +116 -0
  18. package/next/areas/app.js +5 -1
  19. package/next/areas/public.js +5 -1
  20. package/next/seo-routes.js +2 -2
  21. package/package.json +2 -2
  22. package/plugins/runtime-modules/app/presets.js +23 -0
  23. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.d.ts +2 -1
  24. package/plugins/runtime-modules/app/trees/phi-default-app-area-preset-tree.js +3 -2
  25. package/plugins/runtime-modules/client-manifests/common.js +8 -0
  26. package/plugins/runtime-modules/core/authoring-widgets.js +4 -0
  27. package/plugins/runtime-modules/core/widgets/card/plugin.js +18 -0
  28. package/plugins/runtime-modules/core/widgets/description/plugin.js +10 -0
  29. package/plugins/runtime-modules/core/widgets/html/plugin.js +16 -1
  30. package/plugins/runtime-modules/core/widgets/html/server.d.ts +6 -0
  31. package/plugins/runtime-modules/core/widgets/html/server.js +12 -4
  32. package/plugins/runtime-modules/core/widgets/markdown/plugin.js +16 -0
  33. package/plugins/runtime-modules/core/widgets/search-box/authoring.d.ts +6 -0
  34. package/plugins/runtime-modules/core/widgets/search-box/authoring.js +10 -0
  35. package/plugins/runtime-modules/core/widgets/search-box/client.d.ts +21 -0
  36. package/plugins/runtime-modules/core/widgets/search-box/client.js +17 -0
  37. package/plugins/runtime-modules/core/widgets/search-box/config.d.ts +63 -0
  38. package/plugins/runtime-modules/core/widgets/search-box/config.js +48 -0
  39. package/plugins/runtime-modules/core/widgets/search-box/plugin.d.ts +3 -0
  40. package/plugins/runtime-modules/core/widgets/search-box/plugin.js +11 -0
  41. package/plugins/runtime-modules/core/widgets/search-box/server.d.ts +21 -0
  42. package/plugins/runtime-modules/core/widgets/search-box/server.js +48 -0
  43. package/plugins/runtime-modules/core/widgets/search-results/authoring.d.ts +6 -0
  44. package/plugins/runtime-modules/core/widgets/search-results/authoring.js +10 -0
  45. package/plugins/runtime-modules/core/widgets/search-results/client.d.ts +34 -0
  46. package/plugins/runtime-modules/core/widgets/search-results/client.js +32 -0
  47. package/plugins/runtime-modules/core/widgets/search-results/config.d.ts +41 -0
  48. package/plugins/runtime-modules/core/widgets/search-results/config.js +39 -0
  49. package/plugins/runtime-modules/core/widgets/search-results/plugin.d.ts +3 -0
  50. package/plugins/runtime-modules/core/widgets/search-results/plugin.js +10 -0
  51. package/plugins/runtime-modules/core/widgets/search-results/server.d.ts +20 -0
  52. package/plugins/runtime-modules/core/widgets/search-results/server.js +73 -0
  53. package/plugins/runtime-modules/core/widgets/simple-text/plugin.js +11 -0
  54. package/plugins/runtime-modules/core/widgets.js +17 -0
  55. package/plugins/runtime-modules/public/presets.d.ts +16 -0
  56. package/plugins/runtime-modules/public/presets.js +22 -0
  57. package/plugins/runtime-modules/public-base-page-references.d.ts +1 -0
  58. package/plugins/runtime-modules/public-base-page-references.js +1 -0
  59. package/plugins/runtime-modules/search-page-references.d.ts +20 -0
  60. package/plugins/runtime-modules/search-page-references.js +35 -0
  61. package/plugins/runtime-modules/search-page-tree.d.ts +14 -0
  62. package/plugins/runtime-modules/search-page-tree.js +63 -0
  63. package/server-helpers/search-index.d.ts +28 -0
  64. package/server-helpers/search-index.js +310 -0
  65. package/server-helpers/search-text.d.ts +40 -0
  66. package/server-helpers/search-text.js +152 -0
  67. package/server-helpers.d.ts +1 -0
  68. package/server-helpers.js +1 -0
  69. package/types/cms-plugins.d.ts +20 -2
@@ -5,6 +5,11 @@ export type PhiTextControlPresentation = "input" | "password" | "textarea" | "hi
5
5
  export type PhiTextControlProps = {
6
6
  /** The DOM id of the input, so a `<label for>` outside the control can name it. */
7
7
  id?: string;
8
+ /**
9
+ * The field's name in a form that submits the browser's way -- a `GET` form the page answers by its
10
+ * query. Only such a form has a use for it; a controlled field in a Form host reads its value.
11
+ */
12
+ name?: string;
8
13
  value?: string | null;
9
14
  label?: ReactNode;
10
15
  description?: ReactNode;
@@ -49,4 +54,4 @@ export type PhiTextControlProps = {
49
54
  */
50
55
  inputStyle?: CSSProperties;
51
56
  };
52
- export declare function PhiTextControl({ id, value, label, description, inputType, presentation, disabled, readOnly, allowClear, clearLabel, placeholder, ariaLabel, prefix, autoFocus, autoComplete, minLength, maxLength, rows, cols, autoSize, tabIndex, size, variant, inputRef, textareaRef, onChange, onPressEnter, onKeyDown, onFocus, onBlur, onClear, style, inputStyle, }: PhiTextControlProps): import("react").JSX.Element;
57
+ export declare function PhiTextControl({ id, name, value, label, description, inputType, presentation, disabled, readOnly, allowClear, clearLabel, placeholder, ariaLabel, prefix, autoFocus, autoComplete, minLength, maxLength, rows, cols, autoSize, tabIndex, size, variant, inputRef, textareaRef, onChange, onPressEnter, onKeyDown, onFocus, onBlur, onClear, style, inputStyle, }: PhiTextControlProps): import("react").JSX.Element;
@@ -72,7 +72,7 @@ function resolveTextAreaClearStyle(style, inputStyle) {
72
72
  alignItems: "center",
73
73
  };
74
74
  }
75
- export function PhiTextControl({ id, value, label, description, inputType = "text", presentation = "input", disabled = false, readOnly = false, allowClear = true, clearLabel, placeholder, ariaLabel, prefix, autoFocus, autoComplete, minLength, maxLength, rows, cols, autoSize, tabIndex, size, variant, inputRef, textareaRef, onChange, onPressEnter, onKeyDown, onFocus, onBlur, onClear, style, inputStyle, }) {
75
+ export function PhiTextControl({ id, name, value, label, description, inputType = "text", presentation = "input", disabled = false, readOnly = false, allowClear = true, clearLabel, placeholder, ariaLabel, prefix, autoFocus, autoComplete, minLength, maxLength, rows, cols, autoSize, tabIndex, size, variant, inputRef, textareaRef, onChange, onPressEnter, onKeyDown, onFocus, onBlur, onClear, style, inputStyle, }) {
76
76
  const { labelId, labelledBy } = usePhiControlLabel(label, ariaLabel);
77
77
  const resolvedKind = resolveTextInputKind(inputType);
78
78
  const { token } = theme.useToken();
@@ -83,6 +83,7 @@ export function PhiTextControl({ id, value, label, description, inputType = "tex
83
83
  const commonProps = {
84
84
  ref: inputRef,
85
85
  id,
86
+ name,
86
87
  "aria-label": ariaLabel,
87
88
  "aria-labelledby": labelledBy,
88
89
  autoFocus,
@@ -43,6 +43,11 @@ export declare function buildPhiAreaShellSiderLeftNodes({ nodes, runtime, labelP
43
43
  regionSiderLeft: number;
44
44
  layoutSiderLeft: PhiCmsInstanceId;
45
45
  widgetSiderLeftNav: PhiCmsInstanceId;
46
+ /**
47
+ * A search box above the navigation (SEARCH.md), for an Area whose Pages are indexed. Absent draws
48
+ * none: the operator's Areas have nothing a reader searches.
49
+ */
50
+ widgetSiderLeftSearch?: PhiCmsInstanceId;
46
51
  };
47
52
  }): PhiAreaShellPresetNodes;
48
53
  /** Several node groups as one tree body, in the order given. */
@@ -135,12 +135,27 @@ export function buildPhiAreaShellSiderLeftNodes({ nodes, runtime, labelPrefix, n
135
135
  }),
136
136
  ],
137
137
  contentWidgets: [
138
+ ...(ids.widgetSiderLeftSearch
139
+ ? [
140
+ nodes.widget({
141
+ typeKey: "search-box",
142
+ id: ids.widgetSiderLeftSearch,
143
+ parentLayoutNodeId: ids.layoutSiderLeft,
144
+ slotIndex: PHI_CMS_DEFAULT_SLOT_INDEX,
145
+ sortOrder: 0,
146
+ label: `${labelPrefix} sider left search`,
147
+ // The Area's own results Page; the box reads which from where it stands.
148
+ config: { padding: PHI_SPACE.xs },
149
+ }),
150
+ ]
151
+ : []),
138
152
  nodes.widget({
139
153
  typeKey: "sidebar-navigation",
140
154
  id: ids.widgetSiderLeftNav,
141
155
  parentLayoutNodeId: ids.layoutSiderLeft,
142
- slotIndex: PHI_CMS_DEFAULT_SLOT_INDEX,
143
- sortOrder: 0,
156
+ // The stack flows by slot, one child each: the navigation takes the slot after the search box.
157
+ slotIndex: ids.widgetSiderLeftSearch ? 1 : PHI_CMS_DEFAULT_SLOT_INDEX,
158
+ sortOrder: 1,
144
159
  label: `${labelPrefix} sider left navigation`,
145
160
  config: {
146
161
  side: "left",
@@ -0,0 +1,4 @@
1
+ import "server-only";
2
+ import { type PhiGlobalTranslatorOptions } from "../../../gateway/tr";
3
+ import { type PhiSearchResultsWidgetLabels } from "../label-types/search-results";
4
+ export declare function getPhiSearchResultsWidgetLabels(options: PhiGlobalTranslatorOptions): Promise<PhiSearchResultsWidgetLabels>;
@@ -0,0 +1,35 @@
1
+ import "server-only";
2
+ import { definePhiLabelSet, definePhiMessageLabel, getPhiLabelSet } from "../../../gateway/label-set";
3
+ import { PHI_TR_CTX_WEB_UI_LABEL, } from "../../../gateway/tr";
4
+ import { PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS, } from "../label-types/search-results";
5
+ /**
6
+ * What the results Widget says around the hits (SEARCH.md). The hits' own words -- titles, snippets --
7
+ * are the Pages' and arrive from Core in the page's language already.
8
+ */
9
+ const PHI_SEARCH_RESULTS_WIDGET_LABEL_SET = definePhiLabelSet({
10
+ key: "widget:search-results",
11
+ ctx: PHI_TR_CTX_WEB_UI_LABEL,
12
+ labels: {
13
+ heading: PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.heading,
14
+ count: PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.count,
15
+ count_one: PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.countOne,
16
+ empty: definePhiMessageLabel(PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.empty),
17
+ short: definePhiMessageLabel(PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.short),
18
+ idle: definePhiMessageLabel(PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.idle),
19
+ unavailable: definePhiMessageLabel(PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.unavailable),
20
+ region: PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS.region,
21
+ },
22
+ });
23
+ export async function getPhiSearchResultsWidgetLabels(options) {
24
+ const labels = await getPhiLabelSet(options, PHI_SEARCH_RESULTS_WIDGET_LABEL_SET);
25
+ return {
26
+ heading: labels.heading,
27
+ count: labels.count,
28
+ countOne: labels.count_one,
29
+ empty: labels.empty,
30
+ short: labels.short,
31
+ idle: labels.idle,
32
+ unavailable: labels.unavailable,
33
+ region: labels.region,
34
+ };
35
+ }
@@ -0,0 +1,15 @@
1
+ export type PhiSearchResultsWidgetLabels = {
2
+ /** `%1` is the query. */
3
+ heading: string;
4
+ /** `%1` is how many Pages matched in all. */
5
+ count: string;
6
+ countOne: string;
7
+ /** `%1` is the query. */
8
+ empty: string;
9
+ /** `%1` is how many characters a query needs. */
10
+ short: string;
11
+ idle: string;
12
+ unavailable: string;
13
+ region: string;
14
+ };
15
+ export declare const PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS: PhiSearchResultsWidgetLabels;
@@ -0,0 +1,10 @@
1
+ export const PHI_SEARCH_RESULTS_WIDGET_DEFAULT_LABELS = {
2
+ heading: "Results for “%1”",
3
+ count: "%1 pages",
4
+ countOne: "1 page",
5
+ empty: "Nothing found for “%1”.",
6
+ short: "Type at least %1 characters.",
7
+ idle: "Enter what you are looking for.",
8
+ unavailable: "The search is not available just now.",
9
+ region: "Search results",
10
+ };
@@ -47,6 +47,8 @@ export declare const PhiCmsWidgetType: {
47
47
  readonly VideoEmbed: string;
48
48
  readonly TourButton: string;
49
49
  readonly Result: string;
50
+ readonly SearchBox: string;
51
+ readonly SearchResults: string;
50
52
  readonly Pagination: string;
51
53
  readonly Segmented: string;
52
54
  readonly SelectBox: string;
@@ -101,6 +101,8 @@ const PHI_CMS_WIDGET_MODULE_BY_TYPE_KEY = {
101
101
  "record": "core",
102
102
  "rate": "core",
103
103
  "result": "core",
104
+ "search-box": "core",
105
+ "search-results": "core",
104
106
  "segmented": "core",
105
107
  "select-box": "core",
106
108
  "sidebar-navigation": "core",
@@ -175,6 +177,8 @@ export const PhiCmsWidgetType = {
175
177
  VideoEmbed: defineWidgetType(resolvePhiCmsWidgetPluginKey("video-embed"), "video-embed"),
176
178
  TourButton: defineWidgetType(resolvePhiCmsWidgetPluginKey("tour-button"), "tour-button"),
177
179
  Result: defineWidgetType(resolvePhiCmsWidgetPluginKey("result"), "result"),
180
+ SearchBox: defineWidgetType(resolvePhiCmsWidgetPluginKey("search-box"), "search-box"),
181
+ SearchResults: defineWidgetType(resolvePhiCmsWidgetPluginKey("search-results"), "search-results"),
178
182
  Pagination: defineWidgetType(resolvePhiCmsWidgetPluginKey("pagination"), "pagination"),
179
183
  Segmented: defineWidgetType(resolvePhiCmsWidgetPluginKey("segmented"), "segmented"),
180
184
  SelectBox: defineWidgetType(resolvePhiCmsWidgetPluginKey("select-box"), "select-box"),
@@ -15,27 +15,30 @@ export type GetExactSiteAreaOptions = {
15
15
  sourcePreset: PhiCmsPresetIdentity;
16
16
  };
17
17
  export declare const getExactSiteArea: (options: GetExactSiteAreaOptions) => Promise<PhiResolvedCmsAreaPresetPayload | null>;
18
- export type PhiPublishedPublicPage = {
18
+ export type PhiPublishedPage = {
19
19
  path: string | null;
20
20
  ownerModuleId: string | null;
21
21
  presetKey: string | null;
22
22
  revisionId: number;
23
23
  publishedAt: string;
24
24
  };
25
- export type PhiPublicAreaWithPublishedPages = {
26
- /** Null while the Public Area has never been published; the code-owned preset answers then. */
25
+ export type PhiAreaWithPublishedPages = {
26
+ /** Null while the Area has never been published; the code-owned preset answers then. */
27
27
  area: PhiResolvedCmsAreaPresetPayload | null;
28
- publishedPages: PhiPublishedPublicPage[];
28
+ publishedPages: PhiPublishedPage[];
29
29
  };
30
30
  /**
31
- * The published Public Area together with its published Pages, as the sitemap reads them.
31
+ * A published Area together with its published Pages, as the sitemap and the search index read them.
32
32
  *
33
33
  * One request for both: the sitemap needs the Area's `index` and `sitemap` switches and the Pages it
34
34
  * may list, and the server adds the second to the first on `include=publishedPages`. The Pages are
35
35
  * candidates, not answers -- whether one is listed the caller finds out by resolving it. Live and
36
- * anonymous only, so no cookie is sent and no draft can be asked for.
36
+ * anonymous only, so no cookie is sent and no draft can be asked for. Core answers it for the Public
37
+ * and the App Area, the two anything indexes (SEARCH.md).
37
38
  */
38
- export declare function getPublicSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, }: Pick<GetExactSiteAreaOptions, "apiBaseUrl" | "internalToken" | "siteKey" | "locale" | "sourcePreset">): Promise<PhiPublicAreaWithPublishedPages>;
39
+ export declare function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, area, }: Pick<GetExactSiteAreaOptions, "apiBaseUrl" | "internalToken" | "siteKey" | "locale" | "sourcePreset"> & {
40
+ area?: "public" | "app";
41
+ }): Promise<PhiAreaWithPublishedPages>;
39
42
  type PhiSiteAreaStructureRequest = {
40
43
  area: string;
41
44
  ownerModuleId: string;
@@ -35,9 +35,9 @@ export const getExactSiteArea = definePhiRequestMemo(async function getExactSite
35
35
  }
36
36
  return payload;
37
37
  });
38
- function readPublishedPublicPage(entry) {
38
+ function readPublishedPage(entry) {
39
39
  if (!isPhiRecord(entry)) {
40
- throw new Error("Invalid published Public Page projection.");
40
+ throw new Error("Invalid published Page projection.");
41
41
  }
42
42
  const value = entry;
43
43
  const isNullableString = (field) => field === null || typeof field === "string";
@@ -46,7 +46,7 @@ function readPublishedPublicPage(entry) {
46
46
  !isNullableString(value.presetKey) ||
47
47
  !Number.isSafeInteger(value.revisionId) ||
48
48
  typeof value.publishedAt !== "string") {
49
- throw new Error("Invalid published Public Page projection.");
49
+ throw new Error("Invalid published Page projection.");
50
50
  }
51
51
  return {
52
52
  path: value.path,
@@ -57,36 +57,38 @@ function readPublishedPublicPage(entry) {
57
57
  };
58
58
  }
59
59
  /**
60
- * The published Public Area together with its published Pages, as the sitemap reads them.
60
+ * A published Area together with its published Pages, as the sitemap and the search index read them.
61
61
  *
62
62
  * One request for both: the sitemap needs the Area's `index` and `sitemap` switches and the Pages it
63
63
  * may list, and the server adds the second to the first on `include=publishedPages`. The Pages are
64
64
  * candidates, not answers -- whether one is listed the caller finds out by resolving it. Live and
65
- * anonymous only, so no cookie is sent and no draft can be asked for.
65
+ * anonymous only, so no cookie is sent and no draft can be asked for. Core answers it for the Public
66
+ * and the App Area, the two anything indexes (SEARCH.md).
66
67
  */
67
- export async function getPublicSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, }) {
68
+ export async function getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset, area = "public", }) {
68
69
  const payload = await fetchPhiSiteApi({
69
- context: "getPublicSiteAreaWithPublishedPages",
70
+ context: "getSiteAreaWithPublishedPages",
70
71
  apiBaseUrl,
71
72
  internalToken,
72
73
  siteKey,
73
74
  path: "/api/v1/site/area",
74
75
  searchParams: {
75
- path: "/",
76
+ // Core reads the Area off the path's first segment; Public has none.
77
+ path: area === "public" ? "/" : `/${area}`,
76
78
  ownerModuleId: sourcePreset.ownerModuleId,
77
79
  presetKey: sourcePreset.presetKey,
78
80
  include: "publishedPages",
79
81
  },
80
82
  locale,
81
- failure: "Failed to fetch the Public Area with its Pages",
83
+ failure: `Failed to fetch the ${area} Area with its Pages`,
82
84
  userAgent: "phis-ui-sitemap/1.0",
83
85
  });
84
86
  if (!payload || !Array.isArray(payload.publishedPages)) {
85
- throw new Error("Missing published Public Page projection.");
87
+ throw new Error("Missing published Page projection.");
86
88
  }
87
89
  return {
88
90
  area: payload.preset ? payload : null,
89
- publishedPages: payload.publishedPages.map(readPublishedPublicPage),
91
+ publishedPages: payload.publishedPages.map(readPublishedPage),
90
92
  };
91
93
  }
92
94
  function readAreaStructurePayload(value, area, kind) {
@@ -1,6 +1,7 @@
1
1
  import "server-only";
2
2
  import { syncPhiTranslationChangeMarkers } from "../helpers/translation-cache";
3
3
  import { clearPhiSiteReadCache, readPhiSiteReadCache } from "./site-read-cache";
4
+ import { emitPhiSiteReadMarker } from "./site-read-marker-listeners";
4
5
  import { fetchPhiSiteApi } from "./site-api-request";
5
6
  /**
6
7
  * How long a Site process keeps its config before asking Core again. The config is small and carries the
@@ -72,8 +73,13 @@ async function fetchSiteConfig({ apiBaseUrl, internalToken, siteKey }, cacheKey)
72
73
  const markerKey = siteKey.trim().toLowerCase();
73
74
  const previous = seen.get(markerKey);
74
75
  seen.set(markerKey, payload.site.readMarker);
75
- if (previous !== undefined && previous !== payload.site.readMarker) {
76
+ const moved = previous !== undefined && previous !== payload.site.readMarker;
77
+ if (moved) {
76
78
  clearPhiSiteReadCache({ keep: cacheKey });
77
79
  }
80
+ // The first sight and every move: whoever rebuilds from a publish listens here (site-read-marker-listeners.ts).
81
+ if (previous === undefined || moved) {
82
+ emitPhiSiteReadMarker({ siteKey: markerKey, marker: payload.site.readMarker, moved });
83
+ }
78
84
  return payload.site;
79
85
  }
@@ -0,0 +1,24 @@
1
+ import "server-only";
2
+ /**
3
+ * Who wants to know that a Site's read marker was seen (gateway/site-config.ts).
4
+ *
5
+ * The config read is where a process learns that something was published, possibly through another
6
+ * process, and it empties its caches there. Other work follows the same signal -- the search index is
7
+ * rebuilt from it (server-helpers/search-index.ts) -- but the config read must not know about it: the
8
+ * gateway is the floor of the house, and a reader of it that imported the indexer would pull the whole
9
+ * page resolution into every config fetch. So the read says what it saw, and whoever registered listens.
10
+ *
11
+ * On `globalThis`, like the read cache: the config read and the listener can be bundled separately.
12
+ */
13
+ export type PhiSiteReadMarkerEvent = {
14
+ siteKey: string;
15
+ marker: string;
16
+ /** `false` the first time this process sees the Site's marker; `true` when it differs from the last one. */
17
+ moved: boolean;
18
+ };
19
+ type Listener = (event: PhiSiteReadMarkerEvent) => void;
20
+ /** Registers `listener`; registering the same function twice registers it once. */
21
+ export declare function onPhiSiteReadMarker(listener: Listener): void;
22
+ /** Tells every listener; a listener that throws is reported and does not stop the others or the read. */
23
+ export declare function emitPhiSiteReadMarker(event: PhiSiteReadMarkerEvent): void;
24
+ export {};
@@ -0,0 +1,22 @@
1
+ import "server-only";
2
+ const LISTENERS_KEY = Symbol.for("phis-ui.site-read-marker-listeners");
3
+ function readListeners() {
4
+ const holder = globalThis;
5
+ holder[LISTENERS_KEY] ??= new Set();
6
+ return holder[LISTENERS_KEY];
7
+ }
8
+ /** Registers `listener`; registering the same function twice registers it once. */
9
+ export function onPhiSiteReadMarker(listener) {
10
+ readListeners().add(listener);
11
+ }
12
+ /** Tells every listener; a listener that throws is reported and does not stop the others or the read. */
13
+ export function emitPhiSiteReadMarker(event) {
14
+ for (const listener of readListeners()) {
15
+ try {
16
+ listener(event);
17
+ }
18
+ catch (error) {
19
+ console.error("[phis-ui] A read marker listener failed.", error);
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,37 @@
1
+ import "server-only";
2
+ import { type PhiSearchDocument, type PhiSearchIndexState, type PhiSearchIndexWriteResult, type PhiSearchResponse } from "@phis/contracts/search";
3
+ import type { PhiCmsAreaKey } from "../constants/cms-areas";
4
+ type PhiSiteSearchCredentials = {
5
+ apiBaseUrl: string;
6
+ internalToken: string;
7
+ siteKey: string;
8
+ };
9
+ export type FetchPhiSiteSearchOptions = PhiSiteSearchCredentials & {
10
+ /** The query as `readPhiSearchQuery` read it. */
11
+ query: string;
12
+ locale: string;
13
+ /** The Areas this visitor may search; the Widget decided from where it stands. */
14
+ areas: readonly PhiCmsAreaKey[];
15
+ limit: number;
16
+ };
17
+ /**
18
+ * The Pages matching a visitor's query, read while the results Page is drawn (SEARCH.md).
19
+ *
20
+ * A Gateway read with the internal token: Core answers only the Site, and the Site has already decided
21
+ * which Areas this visitor may search. The request carries a query, so the Page is never static and
22
+ * every visitor gets their own answer.
23
+ */
24
+ export declare function fetchPhiSiteSearch(options: FetchPhiSiteSearchOptions): Promise<PhiSearchResponse>;
25
+ /** The sets Core holds of this Site, so the indexer writes only the ones that are behind. */
26
+ export declare function fetchPhiSiteSearchIndexStates(credentials: PhiSiteSearchCredentials): Promise<PhiSearchIndexState[]>;
27
+ export type PutPhiSiteSearchIndexSetOptions = PhiSiteSearchCredentials & {
28
+ area: PhiCmsAreaKey;
29
+ locale: string;
30
+ fingerprint: string;
31
+ documents: readonly PhiSearchDocument[];
32
+ };
33
+ /** One set, replacing what Core held of that Area and language. */
34
+ export declare function putPhiSiteSearchIndexSet(options: PutPhiSiteSearchIndexSetOptions): Promise<PhiSearchIndexWriteResult & {
35
+ dropped: number;
36
+ }>;
37
+ export {};
@@ -0,0 +1,116 @@
1
+ import "server-only";
2
+ import { PHI_SEARCH_QUERY_PARAM, } from "@phis/contracts/search";
3
+ import { isPhiRecord } from "../helpers/is-record";
4
+ import { fetchPhiSiteApi } from "./site-api-request";
5
+ function readString(value) {
6
+ return typeof value === "string" ? value : "";
7
+ }
8
+ function readHit(value) {
9
+ if (!isPhiRecord(value))
10
+ return null;
11
+ const path = readString(value.path);
12
+ if (!path)
13
+ return null;
14
+ return {
15
+ path,
16
+ areaMask: typeof value.areaMask === "number" ? value.areaMask : 1,
17
+ title: readString(value.title),
18
+ description: readString(value.description),
19
+ snippet: Array.isArray(value.snippet)
20
+ ? value.snippet.flatMap((segment) => isPhiRecord(segment) && typeof segment.text === "string"
21
+ ? [{ text: segment.text, match: segment.match === true }]
22
+ : [])
23
+ : [],
24
+ rank: typeof value.rank === "number" ? value.rank : 0,
25
+ };
26
+ }
27
+ /**
28
+ * The Pages matching a visitor's query, read while the results Page is drawn (SEARCH.md).
29
+ *
30
+ * A Gateway read with the internal token: Core answers only the Site, and the Site has already decided
31
+ * which Areas this visitor may search. The request carries a query, so the Page is never static and
32
+ * every visitor gets their own answer.
33
+ */
34
+ export async function fetchPhiSiteSearch(options) {
35
+ const payload = await fetchPhiSiteApi({
36
+ context: "fetchPhiSiteSearch",
37
+ apiBaseUrl: options.apiBaseUrl,
38
+ internalToken: options.internalToken,
39
+ siteKey: options.siteKey,
40
+ path: "/api/v1/site/search",
41
+ searchParams: {
42
+ [PHI_SEARCH_QUERY_PARAM]: options.query,
43
+ areas: options.areas.join(","),
44
+ limit: String(options.limit),
45
+ },
46
+ locale: options.locale,
47
+ failure: "Search failed",
48
+ userAgent: "phis-ui-search/1.0",
49
+ });
50
+ if (!isPhiRecord(payload) || !Array.isArray(payload.hits)) {
51
+ throw new Error("Search answered without a list.");
52
+ }
53
+ return {
54
+ query: readString(payload.query),
55
+ locale: readString(payload.locale) || options.locale,
56
+ areaMask: typeof payload.areaMask === "number" ? payload.areaMask : 0,
57
+ hits: payload.hits.map(readHit).filter((hit) => hit !== null),
58
+ total: typeof payload.total === "number" ? payload.total : 0,
59
+ };
60
+ }
61
+ function readState(value) {
62
+ if (!isPhiRecord(value))
63
+ return null;
64
+ if (typeof value.areaMask !== "number" || typeof value.locale !== "string" || typeof value.fingerprint !== "string") {
65
+ return null;
66
+ }
67
+ return {
68
+ areaMask: value.areaMask,
69
+ locale: value.locale,
70
+ fingerprint: value.fingerprint,
71
+ documentCount: typeof value.documentCount === "number" ? value.documentCount : 0,
72
+ indexedAt: readString(value.indexedAt),
73
+ };
74
+ }
75
+ /** The sets Core holds of this Site, so the indexer writes only the ones that are behind. */
76
+ export async function fetchPhiSiteSearchIndexStates(credentials) {
77
+ const payload = await fetchPhiSiteApi({
78
+ context: "fetchPhiSiteSearchIndexStates",
79
+ ...credentials,
80
+ path: "/api/v1/site/search/index",
81
+ failure: "Search index states fetch failed",
82
+ userAgent: "phis-ui-search-index/1.0",
83
+ });
84
+ if (!isPhiRecord(payload) || !Array.isArray(payload.sets)) {
85
+ throw new Error("The search index answered without its sets.");
86
+ }
87
+ return payload.sets.map(readState).filter((state) => state !== null);
88
+ }
89
+ /** One set, replacing what Core held of that Area and language. */
90
+ export async function putPhiSiteSearchIndexSet(options) {
91
+ const payload = await fetchPhiSiteApi({
92
+ context: "putPhiSiteSearchIndexSet",
93
+ apiBaseUrl: options.apiBaseUrl,
94
+ internalToken: options.internalToken,
95
+ siteKey: options.siteKey,
96
+ path: "/api/v1/site/search/index",
97
+ method: "PUT",
98
+ body: {
99
+ area: options.area,
100
+ locale: options.locale,
101
+ fingerprint: options.fingerprint,
102
+ documents: options.documents,
103
+ },
104
+ failure: `Search index write failed (${options.area}, ${options.locale})`,
105
+ userAgent: "phis-ui-search-index/1.0",
106
+ });
107
+ const state = isPhiRecord(payload) ? readState(payload.state) : null;
108
+ if (!isPhiRecord(payload) || !state) {
109
+ throw new Error("The search index write answered without its state.");
110
+ }
111
+ return {
112
+ accepted: payload.accepted === true,
113
+ state,
114
+ dropped: typeof payload.dropped === "number" ? payload.dropped : 0,
115
+ };
116
+ }
package/next/areas/app.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import "server-only";
2
2
  import { createPhiAppRuntimeModuleCatalog } from "../../plugins/runtime-modules/area-catalogs/app";
3
+ import { registerPhiSearchIndexArea } from "../../server-helpers/search-index";
3
4
  import { createPhiNextCmsSiteBridge } from "../site-bridge";
4
5
  /**
5
6
  * The Area host, given what this Site installed.
@@ -8,8 +9,11 @@ import { createPhiNextCmsSiteBridge } from "../site-bridge";
8
9
  * inside `@phis/ui`; the Skeleton passes it in once and never changes again when a Module is added.
9
10
  */
10
11
  export function createPhiAppCmsSiteBridge(siteModules = {}) {
11
- return createPhiNextCmsSiteBridge({
12
+ const bridge = createPhiNextCmsSiteBridge({
12
13
  runtimeModuleCatalog: createPhiAppRuntimeModuleCatalog(siteModules),
13
14
  });
15
+ // The App Pages are indexed for the Site's search from this Bridge (SEARCH.md).
16
+ registerPhiSearchIndexArea("app", bridge);
17
+ return bridge;
14
18
  }
15
19
  export const PHI_APP_CMS_SITE_BRIDGE = createPhiAppCmsSiteBridge();
@@ -1,5 +1,6 @@
1
1
  import "server-only";
2
2
  import { createPhiPublicRuntimeModuleCatalog } from "../../plugins/runtime-modules/area-catalogs/public";
3
+ import { registerPhiSearchIndexArea } from "../../server-helpers/search-index";
3
4
  import { createPhiNextCmsSiteBridge } from "../site-bridge";
4
5
  /**
5
6
  * The Area host, given what this Site installed.
@@ -8,8 +9,11 @@ import { createPhiNextCmsSiteBridge } from "../site-bridge";
8
9
  * inside `@phis/ui`; the Skeleton passes it in once and never changes again when a Module is added.
9
10
  */
10
11
  export function createPhiPublicCmsSiteBridge(siteModules = {}) {
11
- return createPhiNextCmsSiteBridge({
12
+ const bridge = createPhiNextCmsSiteBridge({
12
13
  runtimeModuleCatalog: createPhiPublicRuntimeModuleCatalog(siteModules),
13
14
  });
15
+ // The Public Pages are indexed for the Site's search from this Bridge (SEARCH.md).
16
+ registerPhiSearchIndexArea("public", bridge);
17
+ return bridge;
14
18
  }
15
19
  export const PHI_PUBLIC_CMS_SITE_BRIDGE = createPhiPublicCmsSiteBridge();
@@ -1,7 +1,7 @@
1
1
  import "server-only";
2
2
  import { createHash } from "node:crypto";
3
3
  import { resolvePhiCmsPageRedirect } from "../components/cms/phi-cms-page-redirect";
4
- import { getPublicSiteAreaWithPublishedPages } from "../gateway/site-area";
4
+ import { getSiteAreaWithPublishedPages } from "../gateway/site-area";
5
5
  import { PHI_AREA_META_PUBLIC_DEFAULTS, readPhiAreaLandingSelection, readPhiAreaMeta, readPhiAreaPublicRoutePaths, } from "../helpers/cms-area-config";
6
6
  import { collectPhiSitemapCandidates, renderPhiRobotsTxt, renderPhiSitemapXml, resolvePhiSitePublicBase, } from "../helpers/phi-seo";
7
7
  import { createPhiFingerprintCache } from "../helpers/phi-sitemap-cache";
@@ -40,7 +40,7 @@ async function loadPhiPublicSeoContext(bridge, { withPublishedPages }) {
40
40
  presetKey: shellBinding.descriptor.presetKey,
41
41
  };
42
42
  const { area: areaPreset, publishedPages } = withPublishedPages
43
- ? await getPublicSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset })
43
+ ? await getSiteAreaWithPublishedPages({ apiBaseUrl, internalToken, siteKey, locale, sourcePreset })
44
44
  : {
45
45
  area: await getPhiExactSiteArea({
46
46
  path: "/",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -503,7 +503,7 @@
503
503
  "@lexical/rich-text": "0.50.0",
504
504
  "@lexical/selection": "0.50.0",
505
505
  "@lexical/utils": "0.50.0",
506
- "@phis/contracts": "^0.7.2",
506
+ "@phis/contracts": "^0.7.3",
507
507
  "dayjs": "^1.11.23",
508
508
  "dom-serializer": "^2.0.0",
509
509
  "htmlparser2": "^10.1.0",
@@ -1,5 +1,7 @@
1
1
  import { PHI_BASE_PAGE_LAYOUT_VERSION } from "../../../components/regions/presets/phi-base-page-layout";
2
+ import { PhiCmsFlags } from "../../../constants/phi-cms";
2
3
  import { buildPhiAreaRootRoutePresetDescriptor } from "../area-root-route";
4
+ import { PHI_APP_SEARCH_PAGE_PRESET_KEY } from "../search-page-references";
3
5
  import { PHI_APP_RUNTIME_MODULE_ID } from "./ids";
4
6
  /* What the App base Module brings: its Area shell, the Area root and the profile Page. */
5
7
  export const PHI_APP_RUNTIME_MODULE_AREA_SHELLS = [
@@ -64,4 +66,25 @@ export const PHI_APP_RUNTIME_MODULE_ROUTES = [
64
66
  loadTree: ({ page, runtime }) => import("./trees/phi-default-app-profile-page-tree")
65
67
  .then((module) => module.buildPhiDefaultAppProfilePageTree({ page, runtime })),
66
68
  },
69
+ /*
70
+ * The App's own results Page (SEARCH.md). A signed-in member searches the App and the Public Site
71
+ * at once, and that is decided by where the results Widget stands: on this Page, in the App. The box
72
+ * in the App's sider leads here. No menu entry and `NoIndex`, as for the Public one.
73
+ */
74
+ {
75
+ ownerModuleId: PHI_APP_RUNTIME_MODULE_ID,
76
+ presetKey: PHI_APP_SEARCH_PAGE_PRESET_KEY,
77
+ presetVersion: 1,
78
+ area: "app",
79
+ title: "Search",
80
+ path: "/search",
81
+ navigation: [],
82
+ defaultPageFlags: PhiCmsFlags.NoIndex,
83
+ loadTree: ({ page }) => import("../search-page-tree")
84
+ .then((module) => module.buildPhiDefaultSearchPageTree({
85
+ page,
86
+ ownerModuleId: PHI_APP_RUNTIME_MODULE_ID,
87
+ presetKey: PHI_APP_SEARCH_PAGE_PRESET_KEY,
88
+ })),
89
+ },
67
90
  ];
@@ -10,7 +10,8 @@ import type { PhiBlockRuntime } from "../../../../types";
10
10
  *
11
11
  * The sider is where the Area's navigation belongs, and the reason is in SETTINGS.md section 3: a
12
12
  * shell Region outlives a move between Pages, while a Page-owned one is built again for each of them.
13
- * Navigation placed in the latter rebuilds itself under the hand that just used it.
13
+ * Navigation placed in the latter rebuilds itself under the hand that just used it. The search box
14
+ * stands above it for the same reason (SEARCH.md): a member searches from wherever they are.
14
15
  */
15
16
  export declare function buildPhiDefaultAppAreaPresetTree({ page, runtime, }: {
16
17
  page: PhiCmsPageNode;