@backmatter/core 0.0.60 → 0.0.62

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": "@backmatter/core",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "Experimental Backmatter SDK. APIs will break. Not ready for production.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -5,6 +5,7 @@
5
5
  import { runInNewContext } from "node:vm";
6
6
  import { field } from "../fields";
7
7
  import { defineBlock, validBlockExamples, type BlockDef } from "../block";
8
+ import { defineObject } from "../object";
8
9
  import { compileLocalModules, pickBindings, withLocalModules, type LocalModules } from "./local-modules";
9
10
 
10
11
  const SOURCE_EXT = /\.(ts|tsx|js|jsx|mjs)$/;
@@ -175,6 +176,7 @@ export function evalBlockSource(
175
176
  const js = withLocalModules(transpile(wrapped), modules);
176
177
  const sandbox = Object.create(null) as {
177
178
  defineBlock: typeof defineBlock;
179
+ defineObject: typeof defineObject;
178
180
  field: typeof field;
179
181
  React: { createElement: (...args: unknown[]) => null; Fragment: string };
180
182
  jsx: (...args: unknown[]) => null;
@@ -183,6 +185,8 @@ export function evalBlockSource(
183
185
  };
184
186
  const el = () => null;
185
187
  sandbox.defineBlock = defineBlockKeepingValidExamples as typeof defineBlock;
188
+ // Site files a block imports (`../objects/galleryPhoto`) call defineObject.
189
+ sandbox.defineObject = defineObject;
186
190
  sandbox.field = field;
187
191
  sandbox.React = { createElement: el, Fragment: "Fragment" };
188
192
  sandbox.jsx = el;
@@ -9,8 +9,8 @@ const SOURCE_EXTS = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
9
9
  const INDEX_FILES = ["/index.ts", "/index.tsx", "/index.js"];
10
10
  const MAX_MODULES = 32;
11
11
  const CORE_SPECIFIERS = new Set(["@backmatter/core", "@backmatter/next"]);
12
- /** Names a site file may take from core; the sandbox provides them as globals. */
13
- const CORE_GLOBALS = new Set(["defineBlock", "field"]);
12
+ /** Names a site file may take from core; the block sandbox provides them as globals. */
13
+ const CORE_GLOBALS = new Set(["defineBlock", "defineObject", "field"]);
14
14
  const IMPORT_LINE = /^\s*import\s+(?:([\s\S]*?)\s+from\s+)?["']([^"']+)["']\s*;?\s*$/gm;
15
15
 
16
16
  /** Repo path a relative import from `fromPath` points at, if that file exists. */
@@ -231,7 +231,7 @@ function bindCore(spec: string): string {
231
231
  }
232
232
  }
233
233
  if (defaultName) lines.push(`var ${defaultName} = __stub;`);
234
- if (namespace) lines.push(`var ${namespace} = { defineBlock: defineBlock, field: field };`);
234
+ if (namespace) lines.push(`var ${namespace} = { defineBlock: defineBlock, defineObject: defineObject, field: field };`);
235
235
  return lines.join("\n");
236
236
  }
237
237
 
@@ -41,6 +41,11 @@ export type PreviewSessionClaims = {
41
41
  role: string;
42
42
  epoch: number;
43
43
  exp: number;
44
+ /**
45
+ * `view` follows its own branch whatever the person's checkout is, and
46
+ * cannot write. Absent is a full session that follows the checkout.
47
+ */
48
+ mode?: "view";
44
49
  };
45
50
 
46
51
  export type PreviewCookiePayload = {
@@ -140,6 +145,7 @@ function asSession(value: unknown): PreviewSessionClaims | null {
140
145
  role: v.role,
141
146
  epoch: v.epoch,
142
147
  exp: v.exp,
148
+ ...(v.mode === "view" ? { mode: "view" as const } : {}),
143
149
  };
144
150
  }
145
151