@niscorp/moss 0.2.3 → 0.2.4

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.
@@ -1,3 +1,4 @@
1
+ import { ScreenHead } from '@niscorp/nova/document';
1
2
  import * as _niscorp_nova from '@niscorp/nova';
2
3
  import { LayoutPaletteEntry, ActionDefinition, Shell, FetchFn, LayoutNode, CanvasConfig, ActionFragment, FunctionHandler, RenderNode } from '@niscorp/nova';
3
4
  import { PgPool, MutationClient, CacheBackend, ScopePolicy, ScopeBehaviors, SeedEntry, SeedMutation } from '@niscorp/vex';
@@ -967,6 +968,7 @@ type DocumentConfig = {
967
968
  };
968
969
  draw: (snapshot: ShellSnapshot) => string | Promise<string>;
969
970
  htmlAttributes?: (snapshot: ShellSnapshot) => Record<string, string>;
971
+ site?: string;
970
972
  tokenKey?: string;
971
973
  waitMs?: number;
972
974
  root?: string;
@@ -977,6 +979,7 @@ type DrawnDocument = {
977
979
  drawn: boolean;
978
980
  principal: string | null;
979
981
  page?: string;
982
+ head?: ScreenHead;
980
983
  live?: boolean;
981
984
  why?: string[];
982
985
  drawnWith?: string[];
@@ -987,6 +990,7 @@ type ExportedDocument = {
987
990
  path: string;
988
991
  html: string;
989
992
  page?: string;
993
+ head?: ScreenHead;
990
994
  drawn: boolean;
991
995
  live: boolean;
992
996
  why: string[];
@@ -1,3 +1,4 @@
1
+ import { ScreenHead } from '@niscorp/nova/document';
1
2
  import * as _niscorp_nova from '@niscorp/nova';
2
3
  import { LayoutPaletteEntry, ActionDefinition, Shell, FetchFn, LayoutNode, CanvasConfig, ActionFragment, FunctionHandler, RenderNode } from '@niscorp/nova';
3
4
  import { PgPool, MutationClient, CacheBackend, ScopePolicy, ScopeBehaviors, SeedEntry, SeedMutation } from '@niscorp/vex';
@@ -967,6 +968,7 @@ type DocumentConfig = {
967
968
  };
968
969
  draw: (snapshot: ShellSnapshot) => string | Promise<string>;
969
970
  htmlAttributes?: (snapshot: ShellSnapshot) => Record<string, string>;
971
+ site?: string;
970
972
  tokenKey?: string;
971
973
  waitMs?: number;
972
974
  root?: string;
@@ -977,6 +979,7 @@ type DrawnDocument = {
977
979
  drawn: boolean;
978
980
  principal: string | null;
979
981
  page?: string;
982
+ head?: ScreenHead;
980
983
  live?: boolean;
981
984
  why?: string[];
982
985
  drawnWith?: string[];
@@ -987,6 +990,7 @@ type ExportedDocument = {
987
990
  path: string;
988
991
  html: string;
989
992
  page?: string;
993
+ head?: ScreenHead;
990
994
  drawn: boolean;
991
995
  live: boolean;
992
996
  why: string[];
package/dist/index.cjs CHANGED
@@ -16,6 +16,7 @@ var zod = require('zod');
16
16
  var reflect = require('@niscorp/nova/reflect');
17
17
  var i18n = require('@niscorp/nova/i18n');
18
18
  var prism = require('@niscorp/prism');
19
+ var document = require('@niscorp/nova/document');
19
20
 
20
21
  // src/app.ts
21
22
  var defineApp = (app) => app;
@@ -3554,8 +3555,6 @@ var createTideDriver = (config) => {
3554
3555
  }
3555
3556
  };
3556
3557
  };
3557
-
3558
- // src/document.ts
3559
3558
  var SNAPSHOT_ELEMENT_ID = "nisc-snapshot";
3560
3559
  var DEFAULT_TOKEN_KEY = "nisc.token";
3561
3560
  var DEFAULT_ROOT = '<div id="root"></div>';
@@ -3599,9 +3598,12 @@ var renderDocument = async (config) => {
3599
3598
  });
3600
3599
  const screen = await draw(snapshot);
3601
3600
  const attributes = Object.entries(config.htmlAttributes?.(snapshot) ?? {}).map(([name, value]) => ` ${name}="${escapeAttribute(value)}"`).join("");
3602
- const html = template.replace(root, () => `${root.replace("></div>", () => `>${screen}</div>`)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
3601
+ const placed = template.replace(root, () => `${root.replace("></div>", () => `>${screen}</div>`)}${embedSnapshot(snapshot, principal, request.path)}`).replace(/<html([^>]*)>/, (whole, existing) => attributes === "" ? whole : `<html${existing}${attributes}>`);
3602
+ const head = document.headOf({ frame: () => snapshot.frame, canvasTree: (id) => snapshot.trees[id] ?? [] });
3603
+ const html = document.placeHead(placed, head?.head, { ...config.site !== void 0 ? { site: config.site } : {}, path: request.path });
3603
3604
  return {
3604
3605
  html,
3606
+ ...head !== void 0 ? { head } : {},
3605
3607
  headers: {
3606
3608
  ...documentHeaders(principal),
3607
3609
  ...token !== null && principal === null ? { "set-cookie": `${encodeURIComponent(tokenKey)}=; Path=/; Max-Age=0; SameSite=Lax` } : {}
@@ -3628,6 +3630,7 @@ var exportDocuments = async (config) => {
3628
3630
  path,
3629
3631
  html: page.html,
3630
3632
  ...page.page !== void 0 ? { page: page.page } : {},
3633
+ ...page.head !== void 0 ? { head: page.head } : {},
3631
3634
  drawn: page.drawn,
3632
3635
  // undrawn is not concluded finished
3633
3636
  live: page.live ?? true,