@kubohiroya/turbowarp-react-islands 0.7.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.7.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.7.0
39
+ pnpm add --save-exact @kubohiroya/turbowarp-react-islands@0.7.1
40
40
  ```
41
41
 
42
42
  ## What it does
@@ -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.7.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",
@@ -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
  }