@notionhq/custom-blocks-dev-shell 0.1.12 → 0.1.14

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/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Workers local shell</title>
7
- <script type="module" crossorigin src="/assets/index-BjlUlu5e.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-3yGtnx4Z.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-D-pOONlZ.css">
9
9
  </head>
10
10
  <body>
@@ -16,6 +16,53 @@ export function buildBlockRegistry(blocks, basePort = BLOCK_BASE_PORT) {
16
16
  url: `http://localhost:${basePort + index}/`,
17
17
  }));
18
18
  }
19
+ const ANSI_PATTERN = /\x1b\[[0-9;]*m/g;
20
+ const VITE_CHANGE_PATTERN = /\b(page reload|hmr update)\s+(.+)$/;
21
+ /**
22
+ * Parse a Vite dev-server log line into a file-change event, or `undefined`
23
+ * for every other line. Vite writes these to stdout, which the shell
24
+ * otherwise discards.
25
+ */
26
+ export function parseViteChange(line) {
27
+ const match = line.replace(ANSI_PATTERN, "").match(VITE_CHANGE_PATTERN);
28
+ if (match === null) {
29
+ return undefined;
30
+ }
31
+ return {
32
+ kind: match[1] === "page reload" ? "reload" : "update",
33
+ detail: match[2],
34
+ };
35
+ }
36
+ /**
37
+ * One save can emit several Vite change lines at once — an hmr update
38
+ * followed by the page reload that supersedes it, or one update per touched
39
+ * module — so changes buffer briefly and print once with the final outcome.
40
+ */
41
+ export const CHANGE_LOG_BUFFER_MS = 150;
42
+ /** Wrap a change-notice printer so each burst of change lines logs once. */
43
+ export function makeChangeLogger(print, schedule = flush => void setTimeout(flush, CHANGE_LOG_BUFFER_MS)) {
44
+ let pending;
45
+ return line => {
46
+ const change = parseViteChange(line);
47
+ if (change === undefined) {
48
+ return;
49
+ }
50
+ if (pending === undefined) {
51
+ pending = change;
52
+ schedule(() => {
53
+ if (pending === undefined) {
54
+ return;
55
+ }
56
+ const outcome = pending.kind === "reload" ? "restarting block" : "updated in place";
57
+ print(`${pending.detail} changed — ${outcome}`);
58
+ pending = undefined;
59
+ });
60
+ }
61
+ else if (change.kind === "reload") {
62
+ pending = change;
63
+ }
64
+ };
65
+ }
19
66
  /** Import specifier from `fromDir` to `toPath`, POSIX-style for ESM. */
20
67
  function relativeImport(fromDir, toPath) {
21
68
  const rel = relative(fromDir, toPath).split(/[\\/]/).join("/");
package/dist-cli/main.js CHANGED
@@ -9,8 +9,9 @@ import { spawn } from "node:child_process";
9
9
  import { existsSync, readFileSync } from "node:fs";
10
10
  import { createRequire } from "node:module";
11
11
  import { basename, dirname, join, resolve } from "node:path";
12
+ import { createInterface } from "node:readline";
12
13
  import { fileURLToPath } from "node:url";
13
- import { BLOCK_BASE_PORT, buildBlockRegistry, SHELL_PORT, writeBlockViteConfig, } from "./block-server.js";
14
+ import { BLOCK_BASE_PORT, buildBlockRegistry, makeChangeLogger, SHELL_PORT, writeBlockViteConfig, } from "./block-server.js";
14
15
  import { runConvert } from "./convert.js";
15
16
  import { readDataSources } from "./data-sources.js";
16
17
  import { materializeWorkerSchemaDataSources } from "./materialize.js";
@@ -159,11 +160,14 @@ async function main() {
159
160
  "--strictPort",
160
161
  ], {
161
162
  cwd: workerDir,
162
- stdio: ["ignore", "ignore", "inherit"],
163
+ stdio: ["ignore", "pipe", "inherit"],
163
164
  // Process groups (and negative-PID kills) are POSIX-only; on
164
165
  // Windows children are killed individually in shutdown().
165
166
  detached: process.platform !== "win32",
166
167
  });
168
+ if (proc.stdout !== null) {
169
+ createInterface({ input: proc.stdout }).on("line", makeChangeLogger(message => console.log(`${label(capability.key)} ${message}`)));
170
+ }
167
171
  proc.on("exit", code => {
168
172
  if (shuttingDown || code === 0 || code === null) {
169
173
  return;
package/docs/bindings.md CHANGED
@@ -21,13 +21,12 @@ ambiguous or absent stays unmapped. Re-picking a source resets the slot's
21
21
  mappings and re-runs auto-map. Manual mapping offers only source properties
22
22
  of exactly the required type — no coercion.
23
23
 
24
- ## Initialization & live edits
24
+ ## Initialization & binding edits
25
25
 
26
26
  Once every slot is bound and every property mapped, the block initializes and
27
- renders. From then on, binding edits reach the running block through
28
- `dataSourcesChanged` without reloading it. Crossing between incomplete and
29
- complete bindings restarts the block insteadinitialization is terminal, so
30
- a block that failed to initialize can only recover through a reload.
27
+ renders. Any binding edit restarts the block: the shell recreates the block's
28
+ iframe, and the fresh initialization carries the new bindings. A block that
29
+ failed to initialize recovers the same wayfix its bindings and save.
31
30
 
32
31
  Bindings last for the page load, per block: refresh the shell and every block
33
32
  returns to unbound.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks-dev-shell",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Local preview shell for Notion custom block workers.",
5
5
  "license": "MIT",
6
6
  "repository": {