@kubohiroya/turbowarp-react-islands 0.6.0 → 0.7.1

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/README.ja.md CHANGED
@@ -33,7 +33,7 @@ MVPでは、TurboWarp内でReactを実行しきることはしません。まず
33
33
  ## インストール
34
34
 
35
35
  ```bash
36
- pnpm add --save-exact @kubohiroya/turbowarp-react-islands@0.6.0
36
+ pnpm add --save-exact @kubohiroya/turbowarp-react-islands@0.7.1
37
37
  ```
38
38
 
39
39
  ## できること
package/README.md CHANGED
@@ -36,7 +36,7 @@ descriptors and HTML fragments that a later build step can consume.
36
36
  ## Installation
37
37
 
38
38
  ```bash
39
- pnpm add --save-exact @kubohiroya/turbowarp-react-islands@0.6.0
39
+ pnpm add --save-exact @kubohiroya/turbowarp-react-islands@0.7.1
40
40
  ```
41
41
 
42
42
  ## What it does
@@ -8805,7 +8805,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8805
8805
  module.exports.fastUri = fastUri;
8806
8806
  }));
8807
8807
  //#endregion
8808
- //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.5.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-json.js
8808
+ //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.8.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-json.js
8809
8809
  var JsonSnapshotError = class extends Error {
8810
8810
  constructor(kind, dataPath) {
8811
8811
  super("JSON snapshot failed.");
@@ -8867,7 +8867,7 @@ function isJsonRecord(value) {
8867
8867
  return value !== null && typeof value === "object" && !Array.isArray(value);
8868
8868
  }
8869
8869
  //#endregion
8870
- //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.5.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-engine.js
8870
+ //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.8.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-engine.js
8871
8871
  var import_ajv = require_ajv();
8872
8872
  var import__2020 = require__2020();
8873
8873
  var import_dist = /* @__PURE__ */ __toESM(require_dist(), 1);
@@ -9213,7 +9213,7 @@ function compileSchemaBundle(input) {
9213
9213
  }
9214
9214
  }
9215
9215
  //#endregion
9216
- //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.5.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-compose.js
9216
+ //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.8.1_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/schema-compose.js
9217
9217
  function deepFreeze(value) {
9218
9218
  if (value !== null && typeof value === "object") {
9219
9219
  Object.values(value).forEach(deepFreeze);
@@ -9428,22 +9428,52 @@ function sourceBinding(argument, bundle, read, check = read, format = "json", ui
9428
9428
  }
9429
9429
  };
9430
9430
  }
9431
- /** The optional capability keeps legacy hosts and the startup flag safely inactive. */
9431
+ /**
9432
+ * The optional capability keeps legacy hosts and the startup flag safely inactive.
9433
+ * Every project load disposes the runtime, which releases the registrations, but the extension
9434
+ * stays loaded for the next project, so they are registered again once that project has loaded.
9435
+ * Only the returned owner dispose is final.
9436
+ */
9432
9437
  function registerSourceEditors(scratch, definitions) {
9433
9438
  const host = scratch;
9434
9439
  const api = host.gui?.blockEditors;
9435
9440
  if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== "function") return () => {};
9441
+ const runtime = host.vm?.runtime;
9436
9442
  const removers = [];
9437
9443
  let active = true;
9444
+ let released = false;
9445
+ const release = () => {
9446
+ for (const remove of removers.splice(0).reverse()) remove();
9447
+ };
9448
+ const register = () => {
9449
+ try {
9450
+ for (const definition of definitions) removers.push(api.registerSourceEditor.call(api, definition));
9451
+ } catch (error) {
9452
+ release();
9453
+ throw error;
9454
+ }
9455
+ };
9456
+ const releaseForProjectLoad = () => {
9457
+ if (!active || released) return;
9458
+ released = true;
9459
+ release();
9460
+ };
9461
+ const restoreAfterProjectLoad = () => {
9462
+ if (!active || !released) return;
9463
+ register();
9464
+ released = false;
9465
+ };
9438
9466
  const dispose = () => {
9439
9467
  if (!active) return;
9440
9468
  active = false;
9441
- host.vm?.runtime?.off?.("RUNTIME_DISPOSED", dispose);
9442
- for (const remove of removers.splice(0).reverse()) remove();
9469
+ runtime?.off?.("RUNTIME_DISPOSED", releaseForProjectLoad);
9470
+ runtime?.off?.("PROJECT_LOADED", restoreAfterProjectLoad);
9471
+ release();
9443
9472
  };
9444
9473
  try {
9445
- for (const definition of definitions) removers.push(api.registerSourceEditor.call(api, definition));
9446
- host.vm?.runtime?.on?.("RUNTIME_DISPOSED", dispose);
9474
+ register();
9475
+ runtime?.on?.("RUNTIME_DISPOSED", releaseForProjectLoad);
9476
+ runtime?.on?.("PROJECT_LOADED", restoreAfterProjectLoad);
9447
9477
  } catch (error) {
9448
9478
  dispose();
9449
9479
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-react-islands",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "TurboWarp extension and helpers for describing React islands in turbowarp-http-server HTML responses.",
5
5
  "author": {
6
6
  "name": "Hiroya Kubo",
@@ -71,7 +71,7 @@
71
71
  "devDependencies": {
72
72
  "@eslint/js": "^9.39.5",
73
73
  "@kubohiroya/turbowarp-extension-manifest": "^0.5.0",
74
- "@kubohiroya/vite-plugin-turbowarp-extension": "^0.10.0",
74
+ "@kubohiroya/vite-plugin-turbowarp-extension": "^0.11.0",
75
75
  "@types/node": "^24.13.3",
76
76
  "eslint": "^9.39.5",
77
77
  "typescript": "^5.9.3",
@@ -81,7 +81,7 @@
81
81
  "react-dom": "18.3.1"
82
82
  },
83
83
  "dependencies": {
84
- "@kubohiroya/turbowarp-extension-data-editor": "^0.5.0"
84
+ "@kubohiroya/turbowarp-extension-data-editor": "^0.8.1"
85
85
  },
86
86
  "gitHead": "78570baedc751aa5d6e1494eb13abb61eed8bc99",
87
87
  "x-turbowarp-source": {
@@ -35,23 +35,47 @@ export function sourceBinding(argument: string, bundle: SchemaBundle,
35
35
  };
36
36
  }
37
37
 
38
- /** The optional capability keeps legacy hosts and the startup flag safely inactive. */
38
+ /**
39
+ * The optional capability keeps legacy hosts and the startup flag safely inactive.
40
+ * Every project load disposes the runtime, which releases the registrations, but the extension
41
+ * stays loaded for the next project, so they are registered again once that project has loaded.
42
+ * Only the returned owner dispose is final.
43
+ */
39
44
  export function registerSourceEditors(scratch: unknown, definitions: readonly SourceEditorOptions[]): () => void {
40
45
  const host = scratch as {gui?: {blockEditors?: {apiVersion?: number; registerSourceEditor?: (options: SourceEditorOptions) => () => void}};
41
46
  vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}}};
42
47
  const api = host.gui?.blockEditors;
43
48
  if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function') return () => {};
49
+ const runtime = host.vm?.runtime;
44
50
  const removers: (() => void)[] = [];
45
51
  let active = true;
52
+ let released = false;
53
+ const release = () => {for (const remove of removers.splice(0).reverse()) remove();};
54
+ const register = () => {
55
+ try {for (const definition of definitions) removers.push(api.registerSourceEditor!.call(api, definition));}
56
+ catch (error) {release(); throw error;}
57
+ };
58
+ const releaseForProjectLoad = () => {
59
+ if (!active || released) return;
60
+ released = true;
61
+ release();
62
+ };
63
+ const restoreAfterProjectLoad = () => {
64
+ if (!active || !released) return;
65
+ register();
66
+ released = false;
67
+ };
46
68
  const dispose = () => {
47
69
  if (!active) return;
48
70
  active = false;
49
- host.vm?.runtime?.off?.('RUNTIME_DISPOSED', dispose);
50
- for (const remove of removers.splice(0).reverse()) remove();
71
+ runtime?.off?.('RUNTIME_DISPOSED', releaseForProjectLoad);
72
+ runtime?.off?.('PROJECT_LOADED', restoreAfterProjectLoad);
73
+ release();
51
74
  };
52
75
  try {
53
- for (const definition of definitions) removers.push(api.registerSourceEditor.call(api, definition));
54
- host.vm?.runtime?.on?.('RUNTIME_DISPOSED', dispose);
76
+ register();
77
+ runtime?.on?.('RUNTIME_DISPOSED', releaseForProjectLoad);
78
+ runtime?.on?.('PROJECT_LOADED', restoreAfterProjectLoad);
55
79
  } catch (error) {dispose(); throw error;}
56
80
  return dispose;
57
81
  }