@phis/ui 0.6.1 → 0.6.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phis/ui",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect } from "react";
4
4
  import { PhiDeveloperBuilderCanvasWidgetClient } from "./canvas-widget";
5
- import { getPhiBuilderRegionDraftKey } from "../region-keys";
5
+ import { getPhiBuilderPageDraftKey } from "../region-keys";
6
6
  import { mergePhiDeveloperDeletedPageDrafts, mergePhiDeveloperPageMetaDrafts, setPhiDeveloperBuilderPageControllerSettings, usePhiDeveloperBuilderStateValue, } from "../developer-workspace-store";
7
7
  import { isPhiBuilderConstructedRootPage } from "../offered-page-catalog";
8
8
  export function PhiDeveloperBuilderPagesWorkspaceWidgetClient({ pageDraftsByScope, pageMeta, pageMetaArea, pageMetaPageKey, serverPreviewRegions, previewRegionDrafts = null, regionLabels, pickerLabels, }) {
@@ -13,14 +13,14 @@ export function PhiDeveloperBuilderPagesWorkspaceWidgetClient({ pageDraftsByScop
13
13
  const constructedRoot = usePhiDeveloperBuilderStateValue((state) => isPhiBuilderConstructedRootPage(state, pageMetaArea, pageMetaPageKey));
14
14
  useEffect(() => {
15
15
  mergePhiDeveloperPageMetaDrafts(pageMetaArea, {
16
- [getPhiBuilderRegionDraftKey(pageMetaArea, "page_meta", pageMetaPageKey)]: {
16
+ [getPhiBuilderPageDraftKey(pageMetaArea, "page_meta", pageMetaPageKey)]: {
17
17
  title: pageMeta?.title ?? null,
18
18
  description: pageMeta?.description ?? null,
19
19
  index: pageMeta?.index ?? true,
20
20
  },
21
21
  });
22
22
  mergePhiDeveloperDeletedPageDrafts(pageMetaArea, {
23
- [getPhiBuilderRegionDraftKey(pageMetaArea, "page_delete", pageMetaPageKey)]: pageMeta?.isDeleted === true,
23
+ [getPhiBuilderPageDraftKey(pageMetaArea, "page_delete", pageMetaPageKey)]: pageMeta?.isDeleted === true,
24
24
  });
25
25
  }, [
26
26
  pageMeta?.description,
@@ -37,7 +37,7 @@ export function PhiDeveloperBuilderPagesWorkspaceWidgetClient({ pageDraftsByScop
37
37
  useEffect(() => {
38
38
  if (!pageMeta)
39
39
  return;
40
- setPhiDeveloperBuilderPageControllerSettings(getPhiBuilderRegionDraftKey(pageMetaArea, "page_meta", pageMetaPageKey), constructedRoot ? [] : pageMeta.controllerSettings);
40
+ setPhiDeveloperBuilderPageControllerSettings(getPhiBuilderPageDraftKey(pageMetaArea, "page_meta", pageMetaPageKey), constructedRoot ? [] : pageMeta.controllerSettings);
41
41
  }, [constructedRoot, pageMeta, pageMetaArea, pageMetaPageKey]);
42
42
  return (_jsx("div", { style: { minWidth: 0, width: "100%", minHeight: 0, flex: "1 1 auto" }, children: _jsx(PhiDeveloperBuilderCanvasWidgetClient, { workspace: "pages", pageDraftsByScope: pageDraftsByScope, serverPreviewRegions: serverPreviewRegions, previewRegionDrafts: previewRegionDrafts, targetArea: pageMetaArea, regionLabels: regionLabels, pickerLabels: pickerLabels }) }));
43
43
  }
@@ -5,7 +5,7 @@ import { usePhiConfirmDialog } from "../../../../components/controls/phi-confirm
5
5
  import { formatPhiHistoryMoveMessage, } from "../../../../components/widgets/label-types/history";
6
6
  import { usePhiApplicationFeedback } from "../../../../components/runtime/use-phi-application-feedback";
7
7
  import { createPhiDefaultAreaRuntimeModuleIds } from "../../area-module-defaults";
8
- import { getPhiBuilderRegionDraftKey } from "../region-keys";
8
+ import { getPhiBuilderPageDraftKey } from "../region-keys";
9
9
  import { resolvePhiBuilderCmsStoragePath } from "../../../../helpers/cms-paths";
10
10
  import { resolvePhiBuilderActivePageCatalog, resolvePhiBuilderActivePageKey, resolvePhiBuilderPagePresetSource, } from "../../../../helpers/cms-page-catalog";
11
11
  import { deleteCmsDraft } from "../../../../helpers/cms-draft-delete";
@@ -388,7 +388,7 @@ export function usePhiBuilderDraftCommandController({ effectiveArea, effectiveNa
388
388
  pageKey: effectivePageKey,
389
389
  title: "",
390
390
  });
391
- const pageDeleteDraftKey = getPhiBuilderRegionDraftKey(effectiveArea, "page_delete", effectivePageKey);
391
+ const pageDeleteDraftKey = getPhiBuilderPageDraftKey(effectiveArea, "page_delete", effectivePageKey);
392
392
  mergePhiDeveloperRegionDrafts(nextDrafts);
393
393
  markPhiBuilderPageDeleted(pageDeleteDraftKey);
394
394
  const result = await savePhiDeveloperBuilderDraft({
@@ -17,7 +17,7 @@ import { describePhiBuilderModuleAddressConflict, describePhiBuilderPageAddressC
17
17
  import { PHI_BUILDER_AREA_SEARCH_PARAM, PHI_BUILDER_PAGE_SEARCH_PARAM, } from "../../../../helpers/cms-scope-search-params";
18
18
  import { PHI_BUILDER_PREVIEW_SEARCH_PARAM } from "../preview-transport";
19
19
  import { mergePhiDeveloperRegionDrafts, openPhiBuilderPage, setPhiBuilderPageMetaDraft, startPhiBuilderNewPageDrafts, getPhiDeveloperBuilderStateSnapshot, } from "../developer-workspace-store";
20
- import { getPhiBuilderRegionDraftKey } from "../region-keys";
20
+ import { getPhiBuilderPageDraftKey } from "../region-keys";
21
21
  import { capturePhiBuilderWorkspaceHistoryState, createPhiBuilderHistoryContext, phiBuilderHistory, } from "../history";
22
22
  import { createPhiBuilderControllerAddress } from "../controller/address";
23
23
  import { PHI_SIGNAL_VALUE_SCHEMAS } from "../../../../types/signals";
@@ -80,7 +80,7 @@ export function usePhiBuilderPageController({ emitCapability, effectiveArea, eff
80
80
  }
81
81
  }
82
82
  function openPageMetaDialog(mode) {
83
- const pageMetaDraftKey = getPhiBuilderRegionDraftKey(effectiveArea, "page_meta", effectivePageKey);
83
+ const pageMetaDraftKey = getPhiBuilderPageDraftKey(effectiveArea, "page_meta", effectivePageKey);
84
84
  const currentMetaDraft = state.pageMetaDrafts[pageMetaDraftKey] ?? {};
85
85
  const pageTitle = currentMetaDraft.title?.trim() || resolvePageTitleForInput(effectivePageKey);
86
86
  const currentPath = normalizePhiBuilderCmsCatalogPath(resolvePhiBuilderCmsStoragePath(effectiveArea, effectivePageKey, currentPageTree));
@@ -188,7 +188,7 @@ export function usePhiBuilderPageController({ emitCapability, effectiveArea, eff
188
188
  path: requestedPath,
189
189
  })
190
190
  : null;
191
- const pageMetaDraftKey = getPhiBuilderRegionDraftKey(effectiveArea, "page_meta", effectivePageKey);
191
+ const pageMetaDraftKey = getPhiBuilderPageDraftKey(effectiveArea, "page_meta", effectivePageKey);
192
192
  const historyBefore = capturePhiBuilderWorkspaceHistoryState(getPhiDeveloperBuilderStateSnapshot());
193
193
  setPhiBuilderPageMetaDraft(pageMetaDraftKey, { title: editedTitle, description, ...indexPatch });
194
194
  phiBuilderHistory.record(createPhiBuilderHistoryContext({
@@ -283,9 +283,9 @@ export function usePhiBuilderPageController({ emitCapability, effectiveArea, eff
283
283
  addPhiWorkspaceCustomPage(effectiveArea, { key: requestedKey, title, storagePath: requestedStoragePath });
284
284
  // The page's meta and delete drafts are edits in progress, so they stay with the Builder.
285
285
  startPhiBuilderNewPageDrafts({
286
- metaDraftKey: getPhiBuilderRegionDraftKey(effectiveArea, "page_meta", requestedKey),
286
+ metaDraftKey: getPhiBuilderPageDraftKey(effectiveArea, "page_meta", requestedKey),
287
287
  meta: { title, description, ...indexPatch },
288
- deleteDraftKey: getPhiBuilderRegionDraftKey(effectiveArea, "page_delete", requestedKey),
288
+ deleteDraftKey: getPhiBuilderPageDraftKey(effectiveArea, "page_delete", requestedKey),
289
289
  });
290
290
  await reloadPersistedPageCatalog(effectiveArea);
291
291
  navigateToBuilderPage(requestedKey);
@@ -3,7 +3,7 @@ import { phiAreaPath } from "../../../helpers/locale";
3
3
  import { resolvePhiBuilderAreaAsCmsArea, resolvePhiBuilderAreaMask } from "../../../constants/cms-areas";
4
4
  import { PhiCmsFlags, PhiCmsStatus } from "../../../constants/phi-cms";
5
5
  import { readPhiCmsInstanceId } from "../../../types/cms-instance-id";
6
- import { getPhiBuilderRegionDraftKey, PHI_BUILDER_PAGE_REGION_KEYS, PHI_BUILDER_SHELL_REGION_KEYS, } from "./region-keys";
6
+ import { getPhiBuilderPageDraftKey, getPhiBuilderRegionDraftKey, PHI_BUILDER_PAGE_REGION_KEYS, PHI_BUILDER_SHELL_REGION_KEYS, } from "./region-keys";
7
7
  import { getPhiBuilderDefaultRegionDraft } from "./region-defaults";
8
8
  import { serializePhiDeveloperBuilderRegionConfig } from "./region-hydration";
9
9
  import { stripPhiResolvedAssetProjections } from "../../../components/media/image-presentation";
@@ -546,7 +546,7 @@ export async function savePhiDeveloperBuilderDraft(state, regionDrafts, workspac
546
546
  const pagePath = resolvePhiBuilderCmsStoragePath(area, pageKey, pages);
547
547
  const currentPagePresetSource = resolvePhiBuilderPagePresetSource(pageKey, pages);
548
548
  const currentAreaPresetSource = state.areaPresetSourcesByArea[area] ?? null;
549
- const pageMetaDraft = state.pageMetaDrafts?.[getPhiBuilderRegionDraftKey(area, "page_meta", pageKey)] ?? null;
549
+ const pageMetaDraft = state.pageMetaDrafts?.[getPhiBuilderPageDraftKey(area, "page_meta", pageKey)] ?? null;
550
550
  /*
551
551
  * The Page flags travel apart from the rest of the meta draft: the titles become translated
552
552
  * messages and this is a column on the row, so the payload splits them even though the dialog
@@ -563,7 +563,7 @@ export async function savePhiDeveloperBuilderDraft(state, regionDrafts, workspac
563
563
  const pageFlags = pageMetaDraft?.index == null
564
564
  ? resolvePhiBuilderPageDefaultFlags(pageKey, pages)
565
565
  : pageMetaDraft.index === false ? PhiCmsFlags.NoIndex : 0;
566
- const isDeletedPageDraft = state.deletedPageDrafts?.[getPhiBuilderRegionDraftKey(area, "page_delete", pageKey)] === true;
566
+ const isDeletedPageDraft = state.deletedPageDrafts?.[getPhiBuilderPageDraftKey(area, "page_delete", pageKey)] === true;
567
567
  const allocationKey = createPhiBuilderDraftAllocationKey(area, pageKey, workspaceKind === "pages" ? "page" : "area");
568
568
  const draftAllocation = state.draftAllocations[allocationKey] ??
569
569
  await getPhiDeveloperBuilderDraftAllocation({
@@ -657,7 +657,7 @@ export async function savePhiDeveloperBuilderDraft(state, regionDrafts, workspac
657
657
  overlays: [],
658
658
  layoutNodes,
659
659
  contentWidgets,
660
- controllerSettings: requirePhiBuilderControllerSettings(state.pageControllerSettings, getPhiBuilderRegionDraftKey(area, "page_meta", pageKey), `Page "${pageKey}"`),
660
+ controllerSettings: requirePhiBuilderControllerSettings(state.pageControllerSettings, getPhiBuilderPageDraftKey(area, "page_meta", pageKey), `Page "${pageKey}"`),
661
661
  });
662
662
  storePhiDeveloperBuilderDraftAllocation(allocationKey, result);
663
663
  savedDraftState = result;
@@ -5,3 +5,13 @@ export type PhiBuilderPageRegionKey = (typeof PHI_BUILDER_PAGE_REGION_KEYS)[numb
5
5
  export type PhiBuilderRegionKey = PhiBuilderShellRegionKey | PhiBuilderPageRegionKey;
6
6
  export declare function isPhiBuilderPageScopedRegion(regionKey: string): regionKey is PhiBuilderPageRegionKey;
7
7
  export declare function getPhiBuilderRegionDraftKey(area: string, regionKey: string, pageKey?: string | null): string;
8
+ /** What the Builder keeps per Page beside its Regions: the meta as edited, and that the Page is to be deleted. */
9
+ export type PhiBuilderPageDraftKind = "page_meta" | "page_delete";
10
+ /**
11
+ * The key of a Page's own draft state in the workspace.
12
+ *
13
+ * Not a Region key: `page_meta` and `page_delete` are not Regions, so `getPhiBuilderRegionDraftKey` leaves the
14
+ * Page out of them and every Page of an Area would share one slot -- the first Page opened would fill it, and
15
+ * the rest would save its title, description and indexing as their own.
16
+ */
17
+ export declare function getPhiBuilderPageDraftKey(area: string, kind: PhiBuilderPageDraftKind, pageKey: string): string;
@@ -10,3 +10,13 @@ export function getPhiBuilderRegionDraftKey(area, regionKey, pageKey) {
10
10
  }
11
11
  return `${area}:${regionKey}`;
12
12
  }
13
+ /**
14
+ * The key of a Page's own draft state in the workspace.
15
+ *
16
+ * Not a Region key: `page_meta` and `page_delete` are not Regions, so `getPhiBuilderRegionDraftKey` leaves the
17
+ * Page out of them and every Page of an Area would share one slot -- the first Page opened would fill it, and
18
+ * the rest would save its title, description and indexing as their own.
19
+ */
20
+ export function getPhiBuilderPageDraftKey(area, kind, pageKey) {
21
+ return `${area}:${pageKey}:${kind}`;
22
+ }
@@ -18,6 +18,7 @@ import { resolvePhiCmsLookup } from "./cms-lookup";
18
18
  import { resolvePhiAreaRouteScope } from "./cms-request";
19
19
  import { runWithPhiRequestRuntime } from "./request-runtime";
20
20
  import { loadPhiSiteRequestContext } from "./runtime";
21
+ import { getPhiSiteBuildId } from "./site-build-id";
21
22
  import { joinPhiSearchText } from "./search-text";
22
23
  /**
23
24
  * The Site's half of its search (SEARCH.md): the documents phis indexes, built from the published Pages.
@@ -47,11 +48,6 @@ const PHI_SEARCH_RUNTIME_MODULE_ID = createPhiRuntimeModuleId(PHI_SHARED_PACKAGE
47
48
  const PHI_SEARCH_INDEX_RESOLVE_CONCURRENCY = 4;
48
49
  /** How long after the marker moved the run starts, so a burst of publishes is one run. */
49
50
  const PHI_SEARCH_INDEX_DEBOUNCE_MS = 2_000;
50
- /**
51
- * What the extraction is, named in the fingerprint: a change in how documents are built reindexes every
52
- * Site on its next start, which the published revisions alone would not do.
53
- */
54
- const PHI_SEARCH_INDEX_FORMAT = 2;
55
51
  const REGISTRY_KEY = Symbol.for("phis-ui.search-index");
56
52
  function readRegistry() {
57
53
  const holder = globalThis;
@@ -205,9 +201,14 @@ async function indexArea({ area, bridge, credentials, heldFingerprint, failures,
205
201
  * translated. Publishing content moves the read marker (the Site's publish triggers), correcting a
206
202
  * translation moves a translation marker, and without them here either left the old words in the
207
203
  * index. The price is a run per published change, which is what SEARCH.md promises.
204
+ *
205
+ * The build is in here because what a document contains depends on the code that builds it (phis-ui,
206
+ * the Site package, the Modules), and no list of inputs can name that. A new build of the Site is
207
+ * therefore a reason to write again, and the build's id says exactly that. The consequence is one run
208
+ * per Area and language after every rollout, and none between.
208
209
  */
209
210
  const fingerprint = createHash("sha256").update(JSON.stringify({
210
- format: PHI_SEARCH_INDEX_FORMAT,
211
+ build: getPhiSiteBuildId(),
211
212
  area,
212
213
  publishedPages,
213
214
  areaPreset: areaPreset?.preset ?? null,
@@ -0,0 +1,25 @@
1
+ import "server-only";
2
+ /**
3
+ * The identity of the Site's build: the token Next writes to `BUILD_ID` in its output directory on every
4
+ * `next build`. It is the one thing that says "different code is running" without anyone keeping a number
5
+ * (SEARCH.md, "When the index is written").
6
+ *
7
+ * Next has no public runtime API for it, and phis-ui names no output directory anywhere else, so this
8
+ * assumes the default: `.next` under the working directory, which for a Site's service is the directory of
9
+ * its release. A Site that sets `distDir` gets the fallback below, which re-indexes on every start --
10
+ * correct, only more often than needed. It deliberately does not read the Core's `release.json`: that file
11
+ * exists only for Sites the phis CLI built.
12
+ *
13
+ * Read once per process. Without the file (`next dev`, tests) the id is made once per process, so a
14
+ * development start indexes anew and nothing fails. A read failure other than "no such file" is logged
15
+ * once and treated the same way.
16
+ */
17
+ export type PhiSiteBuildIdOptions = {
18
+ /** The Next output directory; defaults to `.next` under the working directory. */
19
+ directory?: string;
20
+ /** Reads the file's text; defaults to `node:fs`. Throws as `readFileSync` does. */
21
+ readFile?: (filePath: string) => string;
22
+ };
23
+ export declare function readPhiSiteBuildId(options?: PhiSiteBuildIdOptions): string;
24
+ /** The build id of this process, read on first use and kept (also across duplicate module instances). */
25
+ export declare function getPhiSiteBuildId(): string;
@@ -0,0 +1,27 @@
1
+ import "server-only";
2
+ import { randomUUID } from "node:crypto";
3
+ import { readFileSync } from "node:fs";
4
+ import path from "node:path";
5
+ export function readPhiSiteBuildId(options = {}) {
6
+ const directory = options.directory ?? path.join(process.cwd(), ".next");
7
+ const readFile = options.readFile ?? ((filePath) => readFileSync(filePath, "utf8"));
8
+ const filePath = path.join(directory, "BUILD_ID");
9
+ try {
10
+ const id = readFile(filePath).trim();
11
+ if (id)
12
+ return id;
13
+ }
14
+ catch (error) {
15
+ if (error?.code !== "ENOENT") {
16
+ console.error(`[phis-ui] The Site's build id could not be read from ${filePath}.`, error);
17
+ }
18
+ }
19
+ return `process-${randomUUID()}`;
20
+ }
21
+ const BUILD_ID_KEY = Symbol.for("phis-ui.site-build-id");
22
+ /** The build id of this process, read on first use and kept (also across duplicate module instances). */
23
+ export function getPhiSiteBuildId() {
24
+ const holder = globalThis;
25
+ holder[BUILD_ID_KEY] ??= readPhiSiteBuildId();
26
+ return holder[BUILD_ID_KEY];
27
+ }