@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
@@ -0,0 +1,39 @@
1
+ import { PHI_SEARCH_DEFAULT_LIMIT, PHI_SEARCH_MAX_LIMIT } from "@phis/contracts/search";
2
+ import { resolvePhiCmsWidgetPluginKey } from "../../../../../constants/cms-widget-types";
3
+ import { readInteger, readRenderableBlockConfig, readString, } from "../../../../../components/widgets/config/parser-primitives";
4
+ function readLimit(value) {
5
+ const limit = readInteger(value);
6
+ if (!limit || limit <= 0)
7
+ return PHI_SEARCH_DEFAULT_LIMIT;
8
+ return Math.min(limit, PHI_SEARCH_MAX_LIMIT);
9
+ }
10
+ function normalizePhiSearchResultsWidgetConfig(raw) {
11
+ return {
12
+ ...readRenderableBlockConfig(raw),
13
+ limit: readLimit(raw.limit),
14
+ title: readString(raw.title)?.trim() ?? "",
15
+ };
16
+ }
17
+ export const PHI_SEARCH_RESULTS_WIDGET_DEFINITION = {
18
+ kind: "widget",
19
+ pluginKey: resolvePhiCmsWidgetPluginKey("search-results"),
20
+ typeKey: "search-results",
21
+ title: "Search Results",
22
+ description: "The Site's pages matching the search in the page's address, best first.",
23
+ category: "content",
24
+ tags: ["search", "results", "find"],
25
+ translatesOwnText: true,
26
+ icon: "antd:search",
27
+ slotSizePolicy: "fill-inline",
28
+ fields: [
29
+ {
30
+ key: "limit",
31
+ type: "number",
32
+ label: "Hits",
33
+ description: `How many at most. ${PHI_SEARCH_DEFAULT_LIMIT} by default, ${PHI_SEARCH_MAX_LIMIT} at the very most.`,
34
+ },
35
+ { key: "title", type: "string", label: "Heading", description: "Empty names the query." },
36
+ ],
37
+ defaultConfig: normalizePhiSearchResultsWidgetConfig({}),
38
+ parseConfig: normalizePhiSearchResultsWidgetConfig,
39
+ };
@@ -0,0 +1,3 @@
1
+ import type { PhiCmsServerWidgetPlugin } from "../../../../../types";
2
+ import { type PhiSearchResultsWidgetConfig } from "./config";
3
+ export declare const PHI_SEARCH_RESULTS_WIDGET_PLUGIN: PhiCmsServerWidgetPlugin<PhiSearchResultsWidgetConfig>;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PhiCmsFlags } from "../../../../../constants/phi-cms";
3
+ import { hasPhiFlag } from "../../../../../helpers/flags";
4
+ import { definePhiPassiveWidgetRenderers } from "../../../../../plugins/factories/widget-renderers";
5
+ import { PHI_SEARCH_RESULTS_WIDGET_DEFINITION } from "./config";
6
+ import { PhiSearchResultsWidget } from "./server";
7
+ export const PHI_SEARCH_RESULTS_WIDGET_PLUGIN = {
8
+ ...PHI_SEARCH_RESULTS_WIDGET_DEFINITION,
9
+ ...definePhiPassiveWidgetRenderers(({ widget, config, runtime }) => (_jsx(PhiSearchResultsWidget, { config: config, runtime: runtime, translate: !hasPhiFlag(widget.flags, PhiCmsFlags.NoTranslate), widgetId: widget.id }, `widget-${widget.id}`))),
10
+ };
@@ -0,0 +1,20 @@
1
+ import type { PhiNoLabels, PhiServerBlockBaseProps } from "../../../../../types";
2
+ import type { PhiCmsInstanceId } from "../../../../../types/cms-instance-id";
3
+ import type { PhiSearchResultsWidgetConfig } from "./config";
4
+ export type PhiSearchResultsWidgetProps = PhiServerBlockBaseProps<PhiNoLabels, PhiSearchResultsWidgetConfig> & {
5
+ translate?: boolean;
6
+ widgetId?: PhiCmsInstanceId | null;
7
+ };
8
+ /**
9
+ * The results, decided on the server from the URL alone.
10
+ *
11
+ * No parameter at all is a page nobody searched on yet -- the preset Page opened directly -- and says so
12
+ * quietly. A parameter too short to be a query says what a query needs. A query is asked of Core with the
13
+ * Areas this reader may search, and each hit's address is written the way every link of this Site is,
14
+ * locale and Area in front (`resolvePhiNavHref`), so a hit from Public read in the App still leads to
15
+ * Public.
16
+ *
17
+ * A failed read is `PhiWidgetFailureServer`: an empty list would tell the visitor the Site has nothing on
18
+ * the subject, which is not what happened.
19
+ */
20
+ export declare function PhiSearchResultsWidget({ config, runtime, translate, widgetId }: PhiSearchResultsWidgetProps): Promise<import("react").JSX.Element>;
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PHI_SEARCH_MIN_QUERY_LENGTH, PHI_SEARCH_QUERY_PARAM, readPhiSearchQuery, } from "@phis/contracts/search";
3
+ import { PhiCmsVisibilityContext } from "@phis/contracts/cms";
4
+ import { PhiRuntimeModuleRenderClientHost } from "../../../../../components/runtime/runtime-module-render-client-manifest";
5
+ import { getPhiSearchResultsWidgetLabels } from "../../../../../components/widgets/label-sets/search-results";
6
+ import { PhiWidgetFailureServer } from "../../../../../components/widgets/shared/widget-failure.server";
7
+ import { PhiCmsWidgetType } from "../../../../../constants/cms-widget-types";
8
+ import { resolvePhiNavHref } from "../../../../../helpers/locale";
9
+ import { fetchPhiSiteSearch } from "../../../../../gateway/site-search";
10
+ import { phiRuntime } from "../../../../../server-helpers/phi-runtime";
11
+ import { trBulkForLocale } from "../../../../../server-helpers/translate";
12
+ import { readPhiRuntimeTreeRenderMode } from "../../../render-mode";
13
+ /** The Areas a reader standing in `area` may search (SEARCH.md): App and Public from the App, else Public. */
14
+ function resolvePhiSearchedAreas(area) {
15
+ return area === "app" ? ["app", "public"] : ["public"];
16
+ }
17
+ function readHitArea(areaMask) {
18
+ return areaMask === PhiCmsVisibilityContext.AppArea ? "app" : "public";
19
+ }
20
+ /**
21
+ * The results, decided on the server from the URL alone.
22
+ *
23
+ * No parameter at all is a page nobody searched on yet -- the preset Page opened directly -- and says so
24
+ * quietly. A parameter too short to be a query says what a query needs. A query is asked of Core with the
25
+ * Areas this reader may search, and each hit's address is written the way every link of this Site is,
26
+ * locale and Area in front (`resolvePhiNavHref`), so a hit from Public read in the App still leads to
27
+ * Public.
28
+ *
29
+ * A failed read is `PhiWidgetFailureServer`: an empty list would tell the visitor the Site has nothing on
30
+ * the subject, which is not what happened.
31
+ */
32
+ export async function PhiSearchResultsWidget({ config, runtime, translate = true, widgetId }) {
33
+ const rt = phiRuntime(runtime);
34
+ const locale = runtime.locale.current;
35
+ const renderMode = readPhiRuntimeTreeRenderMode(config ?? {});
36
+ const [labels, [title]] = await Promise.all([
37
+ getPhiSearchResultsWidgetLabels({ apiBaseUrl: rt.apiBaseUrl, internalToken: rt.internalToken, locale }),
38
+ config?.title && translate ? trBulkForLocale(locale, [config.title]) : [config?.title ?? ""],
39
+ ]);
40
+ const raw = runtime.request?.searchParams?.[PHI_SEARCH_QUERY_PARAM];
41
+ const query = readPhiSearchQuery(raw);
42
+ const base = { title: title || undefined, minLength: PHI_SEARCH_MIN_QUERY_LENGTH };
43
+ const render = (state) => (_jsx(PhiRuntimeModuleRenderClientHost, { type: PhiCmsWidgetType.SearchResults, componentProps: { labels, config: state } }));
44
+ if (raw === undefined) {
45
+ return render({ ...base, state: "idle" });
46
+ }
47
+ if (!query) {
48
+ return render({ ...base, state: "short", query: raw.trim() });
49
+ }
50
+ let answer;
51
+ try {
52
+ answer = await fetchPhiSiteSearch({
53
+ apiBaseUrl: rt.apiBaseUrl,
54
+ internalToken: rt.internalToken,
55
+ siteKey: rt.siteKey,
56
+ query,
57
+ locale,
58
+ areas: resolvePhiSearchedAreas(runtime.area),
59
+ limit: config?.limit ?? 20,
60
+ });
61
+ }
62
+ catch (error) {
63
+ return (_jsx(PhiWidgetFailureServer, { renderMode: renderMode, widgetType: PhiCmsWidgetType.SearchResults, widgetId: widgetId, title: labels.unavailable, description: error instanceof Error ? error.message : String(error), error: error }));
64
+ }
65
+ const hits = answer.hits.map((hit) => ({
66
+ href: resolvePhiNavHref(locale, readHitArea(hit.areaMask), hit.path),
67
+ title: hit.title || hit.path,
68
+ description: hit.description,
69
+ snippet: hit.snippet,
70
+ area: readHitArea(hit.areaMask),
71
+ }));
72
+ return render({ ...base, state: "results", query: answer.query || query, total: answer.total, hits });
73
+ }
@@ -1,10 +1,21 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { PhiCmsFlags } from "../../../../../constants/phi-cms";
3
3
  import { hasPhiFlag } from "../../../../../helpers/flags";
4
+ import { translatePhiSearchWidgetTexts } from "../../../../../server-helpers/search-text";
4
5
  import { PhiSimpleTextWidget } from "./server";
5
6
  import { PHI_SIMPLE_TEXT_WIDGET_DEFINITION, PHI_SIMPLE_TEXT_WIDGET_PLUGIN_TYPE, resolvePhiSimpleTextWidgetText, } from "./config";
6
7
  export const PHI_SIMPLE_TEXT_WIDGET_PLUGIN = {
7
8
  ...PHI_SIMPLE_TEXT_WIDGET_DEFINITION,
9
+ // The text as the render shows it: a record's already in the page's language, the Widget's own translated here.
10
+ searchText: ({ widget, config, runtime }) => {
11
+ const noTranslate = hasPhiFlag(widget.flags, PhiCmsFlags.NoTranslate);
12
+ const hasResolvedText = Boolean(widget.resolvedContent?.textFields.text);
13
+ const text = resolvePhiSimpleTextWidgetText({ ...config, resolvedContent: widget.resolvedContent ?? null }, { preferSource: noTranslate }, "");
14
+ return translatePhiSearchWidgetTexts(runtime, [text], {
15
+ translate: !noTranslate && !hasResolvedText,
16
+ textSource: config.textSource,
17
+ });
18
+ },
8
19
  render: ({ widget, config, runtime }) => {
9
20
  const noTranslate = hasPhiFlag(widget.flags, PhiCmsFlags.NoTranslate);
10
21
  // A record's text is already translated; only the Widget's own still has to be.
@@ -45,6 +45,8 @@ import { PHI_GALLERY_WIDGET_DEFINITION } from "./widgets/gallery/config";
45
45
  import { PHI_STEPS_WIDGET_DEFINITION } from "./widgets/steps/config";
46
46
  import { PHI_TIMELINE_WIDGET_DEFINITION } from "./widgets/timeline/config";
47
47
  import { PHI_ENTRY_LIST_WIDGET_DEFINITION } from "./widgets/entry-list/config";
48
+ import { PHI_SEARCH_BOX_WIDGET_DEFINITION } from "./widgets/search-box/config";
49
+ import { PHI_SEARCH_RESULTS_WIDGET_DEFINITION } from "./widgets/search-results/config";
48
50
  import { PHI_ENTRY_DETAIL_WIDGET_DEFINITION } from "./widgets/entry-detail/config";
49
51
  import { PHI_ENTRY_HEADER_WIDGET_DEFINITION } from "./widgets/entry-header/config";
50
52
  import { PHI_THREAD_CONVERSATION_WIDGET_DEFINITION } from "./widgets/thread-conversation/config";
@@ -371,6 +373,21 @@ export const PHI_RUNTIME_MODULE_WIDGETS = [
371
373
  loadRuntime: () => import("./widgets/timeline/plugin").then((module) => module.PHI_TIMELINE_WIDGET_PLUGIN),
372
374
  loadPreview: () => import("./widgets/timeline/plugin").then((module) => module.PHI_TIMELINE_WIDGET_PLUGIN),
373
375
  }),
376
+ // The Site's own search (SEARCH.md): the box a visitor types into and the Page that answers it.
377
+ defineFirstPartyWidget({
378
+ definition: PHI_SEARCH_BOX_WIDGET_DEFINITION,
379
+ ownerModuleId: PHI_CORE_RUNTIME_MODULE_ID,
380
+ renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
381
+ loadRuntime: () => import("./widgets/search-box/plugin").then((module) => module.PHI_SEARCH_BOX_WIDGET_PLUGIN),
382
+ loadPreview: () => import("./widgets/search-box/plugin").then((module) => module.PHI_SEARCH_BOX_WIDGET_PLUGIN),
383
+ }),
384
+ defineFirstPartyWidget({
385
+ definition: PHI_SEARCH_RESULTS_WIDGET_DEFINITION,
386
+ ownerModuleId: PHI_CORE_RUNTIME_MODULE_ID,
387
+ renderPolicies: { "runtime": "custom", "preview": "custom", "authoring": "custom" },
388
+ loadRuntime: () => import("./widgets/search-results/plugin").then((module) => module.PHI_SEARCH_RESULTS_WIDGET_PLUGIN),
389
+ loadPreview: () => import("./widgets/search-results/plugin").then((module) => module.PHI_SEARCH_RESULTS_WIDGET_PLUGIN),
390
+ }),
374
391
  // A content kind's entries and one entry of it, for every kind's Module (`CONTENT_ENTRIES.md`).
375
392
  defineFirstPartyWidget({
376
393
  definition: PHI_ENTRY_LIST_WIDGET_DEFINITION,
@@ -25,6 +25,7 @@ export declare const PHI_PUBLIC_RUNTIME_MODULE_ROUTES: ({
25
25
  path: string;
26
26
  loadTree: ({ page, runtime }: PhiCmsDescriptorBuildContext) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
27
27
  navigation?: undefined;
28
+ defaultPageFlags?: undefined;
28
29
  } | {
29
30
  ownerModuleId: "@phis/ui/modules/public";
30
31
  presetKey: "public-home-page";
@@ -46,6 +47,7 @@ export declare const PHI_PUBLIC_RUNTIME_MODULE_ROUTES: ({
46
47
  };
47
48
  }[];
48
49
  loadTree: ({ page }: PhiCmsDescriptorBuildContext) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
50
+ defaultPageFlags?: undefined;
49
51
  } | {
50
52
  ownerModuleId: "@phis/ui/modules/public";
51
53
  presetKey: "public-terms-page";
@@ -58,6 +60,20 @@ export declare const PHI_PUBLIC_RUNTIME_MODULE_ROUTES: ({
58
60
  params: Readonly<Record<string, string>>;
59
61
  }) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
60
62
  navigation?: undefined;
63
+ defaultPageFlags?: undefined;
64
+ } | {
65
+ ownerModuleId: "@phis/ui/modules/public";
66
+ presetKey: "public-search-page";
67
+ presetVersion: number;
68
+ area: "public";
69
+ title: string;
70
+ path: string;
71
+ navigation: never[];
72
+ defaultPageFlags: number;
73
+ loadTree: ({ page }: PhiCmsDescriptorBuildContext & {
74
+ activeModuleIds: ReadonlySet<import("../contracts").PhiRuntimeModuleId>;
75
+ params: Readonly<Record<string, string>>;
76
+ }) => Promise<import("../../../types").PhiResolvedCmsPageTree>;
61
77
  })[];
62
78
  /**
63
79
  * The Public form pages, in their own list because they appear only where Forms are allowed. The
@@ -101,6 +101,28 @@ export const PHI_PUBLIC_RUNTIME_MODULE_ROUTES = [
101
101
  loadTree: ({ page }) => import("./trees/phi-default-pub-terms-page-tree")
102
102
  .then((module) => module.buildPhiDefaultPubTermsPageTree({ page })),
103
103
  },
104
+ /*
105
+ * Where a search goes (SEARCH.md): the box on any Page sends its query here, and the results Widget
106
+ * reads it from the address. Core's, because the box is Core's and a box without a Page to answer it is
107
+ * a field that leads nowhere. No menu entry -- nobody browses to a results Page -- and `NoIndex`, so
108
+ * neither a crawler nor the Site's own index lists a Page whose words are whatever was last searched.
109
+ */
110
+ {
111
+ ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
112
+ presetKey: PHI_PUBLIC_BASE_PAGE_PRESET_KEYS.search,
113
+ presetVersion: 1,
114
+ area: "public",
115
+ title: "Search",
116
+ path: "/search",
117
+ navigation: [],
118
+ defaultPageFlags: PhiCmsFlags.NoIndex,
119
+ loadTree: ({ page }) => import("../search-page-tree")
120
+ .then((module) => module.buildPhiDefaultSearchPageTree({
121
+ page,
122
+ ownerModuleId: PHI_PUBLIC_RUNTIME_MODULE_ID,
123
+ presetKey: PHI_PUBLIC_BASE_PAGE_PRESET_KEYS.search,
124
+ })),
125
+ },
104
126
  ];
105
127
  /**
106
128
  * The Public form pages, in their own list because they appear only where Forms are allowed. The
@@ -17,6 +17,7 @@ export declare const PHI_PUBLIC_BASE_PAGE_PRESET_KEYS: {
17
17
  readonly terms: "public-terms-page";
18
18
  readonly contact: "public-contact-page";
19
19
  readonly unsubscribe: "public-unsubscribe-page";
20
+ readonly search: "public-search-page";
20
21
  };
21
22
  /**
22
23
  * Ready-made references to the Pages every Site has, for a Module that links to one.
@@ -19,6 +19,7 @@ export const PHI_PUBLIC_BASE_PAGE_PRESET_KEYS = {
19
19
  terms: "public-terms-page",
20
20
  contact: "public-contact-page",
21
21
  unsubscribe: "public-unsubscribe-page",
22
+ search: "public-search-page",
22
23
  };
23
24
  // Named by id, as data, for the same reason: `public/ids` would bind the door to the Module folder.
24
25
  const PHI_PUBLIC_RUNTIME_MODULE_ID = createPhiRuntimeModuleId(PHI_SHARED_PACKAGE_NAME, "public");
@@ -0,0 +1,20 @@
1
+ import { type PhiLinkTarget } from "../../types/references";
2
+ import type { PhiCmsAreaKey } from "../../constants/cms-areas";
3
+ /**
4
+ * The search results Pages (SEARCH.md), one per Area that is indexed, named once.
5
+ *
6
+ * The App base brings its own rather than sending a signed-in reader to the Public one: the App's
7
+ * results Page searches App and Public, the Public one only Public, and which Area a reader stands in
8
+ * is what decides between them. The Search Box Widget reads the Area it is placed in and links to that
9
+ * Area's Page unless its author chose another; the Pages themselves are declared beside the other base
10
+ * Pages of their Modules, with the keys from here so the two cannot drift.
11
+ *
12
+ * Kept apart from the Module folders for the reason `public-base-page-references.ts` is: a Core Widget
13
+ * links to these Pages, and importing them from beside the trees would compile the whole Module with it.
14
+ */
15
+ export declare const PHI_APP_SEARCH_PAGE_PRESET_KEY = "app-search-page";
16
+ /**
17
+ * Where a Search Box in `area` sends its query when its author chose no Page: the Area's own results
18
+ * Page, and for an Area that has none -- the operator's chrome -- the Public one, resolved in Public.
19
+ */
20
+ export declare function resolvePhiSearchPageLinkTarget(area: PhiCmsAreaKey): PhiLinkTarget;
@@ -0,0 +1,35 @@
1
+ import { createPhiPageReference } from "../../types/references";
2
+ import { PHI_SHARED_PACKAGE_NAME } from "../../constants/package";
3
+ import { createPhiRuntimeModuleId } from "../../constants/module-identity";
4
+ import { PHI_PUBLIC_BASE_PAGE_REFERENCES } from "./public-base-page-references";
5
+ /**
6
+ * The search results Pages (SEARCH.md), one per Area that is indexed, named once.
7
+ *
8
+ * The App base brings its own rather than sending a signed-in reader to the Public one: the App's
9
+ * results Page searches App and Public, the Public one only Public, and which Area a reader stands in
10
+ * is what decides between them. The Search Box Widget reads the Area it is placed in and links to that
11
+ * Area's Page unless its author chose another; the Pages themselves are declared beside the other base
12
+ * Pages of their Modules, with the keys from here so the two cannot drift.
13
+ *
14
+ * Kept apart from the Module folders for the reason `public-base-page-references.ts` is: a Core Widget
15
+ * links to these Pages, and importing them from beside the trees would compile the whole Module with it.
16
+ */
17
+ export const PHI_APP_SEARCH_PAGE_PRESET_KEY = "app-search-page";
18
+ const PHI_APP_RUNTIME_MODULE_ID = createPhiRuntimeModuleId(PHI_SHARED_PACKAGE_NAME, "app");
19
+ const PHI_APP_SEARCH_PAGE_REFERENCE = createPhiPageReference({
20
+ kind: "module",
21
+ ownerModuleId: PHI_APP_RUNTIME_MODULE_ID,
22
+ presetKey: PHI_APP_SEARCH_PAGE_PRESET_KEY,
23
+ });
24
+ /**
25
+ * Where a Search Box in `area` sends its query when its author chose no Page: the Area's own results
26
+ * Page, and for an Area that has none -- the operator's chrome -- the Public one, resolved in Public.
27
+ */
28
+ export function resolvePhiSearchPageLinkTarget(area) {
29
+ if (area === "app") {
30
+ return { kind: "page", reference: PHI_APP_SEARCH_PAGE_REFERENCE };
31
+ }
32
+ return area === "public"
33
+ ? { kind: "page", reference: PHI_PUBLIC_BASE_PAGE_REFERENCES.search }
34
+ : { kind: "page", reference: PHI_PUBLIC_BASE_PAGE_REFERENCES.search, area: "public" };
35
+ }
@@ -0,0 +1,14 @@
1
+ import type { PhiCmsPageNode, PhiResolvedCmsPageTree } from "../../types/cms";
2
+ /**
3
+ * The results Page every indexed Area brings (SEARCH.md): the box, so a reader can search again without
4
+ * going back, and under it the results, which read the query from the page's address.
5
+ *
6
+ * One tree for both Areas because the Page is the same in both; what differs -- which Areas are searched
7
+ * -- is decided by the Widget from where it stands, not written into the tree. The ids are derived from
8
+ * the preset identity, so the Public and the App Page are two sets of nodes.
9
+ */
10
+ export declare function buildPhiDefaultSearchPageTree({ page, ownerModuleId, presetKey, }: {
11
+ page: PhiCmsPageNode;
12
+ ownerModuleId: `${string}/${string}`;
13
+ presetKey: string;
14
+ }): Promise<PhiResolvedCmsPageTree>;
@@ -0,0 +1,63 @@
1
+ import { buildPhiBasePageContentScaffold, PHI_BASE_PAGE_LAYOUT_NODE_ID, } from "../../components/regions/presets/phi-base-page-layout";
2
+ import { PHI_CMS_DEFAULT_SLOT_INDEX } from "../../constants/cms-layout-types";
3
+ import { PhiCmsPageType } from "../../constants/phi-cms";
4
+ import { createPhiCmsPresetNodes } from "../../helpers/cms-preset-nodes";
5
+ import { PHI_SPACE } from "../../theme/antd-css-var-contract";
6
+ import { createPhiPresetCmsInstanceIdMap } from "../../types/cms-instance-id";
7
+ /** Synthetic Region id; negative, and unique among the base Presets. */
8
+ const SYNTHETIC_SEARCH_REGION_IDS = {
9
+ regionContent: -260,
10
+ };
11
+ /**
12
+ * The results Page every indexed Area brings (SEARCH.md): the box, so a reader can search again without
13
+ * going back, and under it the results, which read the query from the page's address.
14
+ *
15
+ * One tree for both Areas because the Page is the same in both; what differs -- which Areas are searched
16
+ * -- is decided by the Widget from where it stands, not written into the tree. The ids are derived from
17
+ * the preset identity, so the Public and the App Page are two sets of nodes.
18
+ */
19
+ export async function buildPhiDefaultSearchPageTree({ page, ownerModuleId, presetKey, }) {
20
+ const identity = { domain: "page", ownerModuleId, presetKey };
21
+ const layoutIds = createPhiPresetCmsInstanceIdMap(identity, ["layoutContent"]);
22
+ const widgetIds = createPhiPresetCmsInstanceIdMap(identity, ["widgetBox", "widgetResults"]);
23
+ const nodes = createPhiCmsPresetNodes(page);
24
+ const scaffold = buildPhiBasePageContentScaffold({ page, regionId: SYNTHETIC_SEARCH_REGION_IDS.regionContent });
25
+ return {
26
+ page: nodes.page({ pageType: PhiCmsPageType.Standard }),
27
+ overlays: [],
28
+ regions: [scaffold.region],
29
+ layoutNodes: [
30
+ scaffold.layoutNode,
31
+ nodes.layout({
32
+ creationPreset: { layoutKind: "verticalflex", preset: "panel" },
33
+ typeKey: "flex-vertical",
34
+ id: layoutIds.layoutContent,
35
+ parentLayoutNodeId: PHI_BASE_PAGE_LAYOUT_NODE_ID,
36
+ slotIndex: PHI_CMS_DEFAULT_SLOT_INDEX,
37
+ label: "search page stack",
38
+ config: { gap: PHI_SPACE.lg },
39
+ }),
40
+ ],
41
+ contentWidgets: [
42
+ nodes.widget({
43
+ typeKey: "search-box",
44
+ id: widgetIds.widgetBox,
45
+ parentLayoutNodeId: layoutIds.layoutContent,
46
+ slotIndex: PHI_CMS_DEFAULT_SLOT_INDEX,
47
+ sortOrder: 0,
48
+ label: "search page box",
49
+ config: { controlSize: "large" },
50
+ }),
51
+ nodes.widget({
52
+ typeKey: "search-results",
53
+ id: widgetIds.widgetResults,
54
+ parentLayoutNodeId: layoutIds.layoutContent,
55
+ sortOrder: 1,
56
+ label: "search page results",
57
+ config: {},
58
+ // A vertical stack flows by slot: one child per `slotIndex`, in that order.
59
+ slotIndex: 1,
60
+ }),
61
+ ],
62
+ };
63
+ }
@@ -0,0 +1,28 @@
1
+ import "server-only";
2
+ import type { PhiCmsSiteBridge } from "../types/cms-plugins";
3
+ /**
4
+ * The Site's half of its search (SEARCH.md): the documents phis indexes, built from the published Pages.
5
+ *
6
+ * A Page's words are not in one place phis could read -- Widget configs, content bound to an instance in
7
+ * a tree, documents fetched while the Page is drawn -- so the Site reads each Page the way a visitor's
8
+ * request does and writes what it saw. The enumeration is the sitemap's: the Area's published Pages and
9
+ * the active Module routes are the candidates, and resolving each one as a lookup decides whether a
10
+ * visitor would get a document. The text is each Widget's own answer (`searchText` on its plugin),
11
+ * translated for the language being indexed; the title and description are the Page's own.
12
+ *
13
+ * Two Areas, read as the reader who may search them: Public anonymously, App as a signed-in member with
14
+ * no further roles. A Page with a narrower access policy than that is not written.
15
+ *
16
+ * It runs when the Site's read marker is first seen by this process and whenever it moves -- which a
17
+ * publish does -- and writes only the sets whose fingerprint phis does not hold yet, so several
18
+ * processes noticing one publish produce one write. One run at a time per process; a marker that moves
19
+ * during a run queues one more.
20
+ */
21
+ declare const PHI_SEARCH_INDEX_AREAS: readonly ["public", "app"];
22
+ type PhiSearchIndexArea = (typeof PHI_SEARCH_INDEX_AREAS)[number];
23
+ /**
24
+ * Names the Bridge an Area's Pages are read through. The Area host registers itself when it is created
25
+ * (next/areas/*.ts); an Area this process never served is not indexed by it, and another process will.
26
+ */
27
+ export declare function registerPhiSearchIndexArea(area: PhiSearchIndexArea, bridge: PhiCmsSiteBridge): void;
28
+ export {};