@backmatter/core 0.0.61 → 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
package/src/node/eval-block.ts
CHANGED
|
@@ -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
|
|