@kubohiroya/turbowarp-text-lines 0.6.0 → 0.7.0

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.
Files changed (2) hide show
  1. package/dist/text-lines.js +49 -22
  2. package/package.json +3 -3
@@ -21,7 +21,7 @@ var extensionConfig = {
21
21
  blockIconURI: `data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 48 48\"><g fill=\"#4C97FF\"><circle cx=\"11\" cy=\"16\" r=\"2.6\"/><circle cx=\"11\" cy=\"24\" r=\"2.6\"/><circle cx=\"11\" cy=\"32\" r=\"2.6\"/></g><path d=\"M19 16h20M19 24h20M19 32h13\" fill=\"none\" stroke=\"#59C059\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>")}`
22
22
  };
23
23
  //#endregion
24
- //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.5.0_react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/fixed-input-schema.js
24
+ //#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.11.0_react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/fixed-input-schema.js
25
25
  var numberToken = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/u;
26
26
  var invalidNumber = Object.freeze({
27
27
  kind: "invalid",
@@ -184,44 +184,71 @@ var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) =
184
184
  settings: null
185
185
  })
186
186
  }));
187
- /** Registration follows the advertised opcode membership and the optional host capability. */
187
+ /**
188
+ * Registration follows the advertised opcode membership and the optional host capability.
189
+ * Loading a project disposes the runtime, which releases the registrations, but the extension
190
+ * stays loaded for the next project: they are registered again once that project has loaded.
191
+ * Only the owner's dispose is final.
192
+ */
188
193
  function fixedInputRegistration(scratch) {
189
194
  const host = scratch ?? {};
190
195
  let active;
191
196
  let membership = "";
192
197
  const removers = [];
193
198
  let stopped = false;
199
+ let released = false;
200
+ let requested = [];
194
201
  const clear = () => {
195
- host.vm?.runtime?.off?.("RUNTIME_DISPOSED", shutdown);
202
+ host.vm?.runtime?.off?.("RUNTIME_DISPOSED", release);
203
+ host.vm?.runtime?.off?.("PROJECT_LOADED", restore);
196
204
  for (const remove of removers.splice(0).reverse()) remove();
197
205
  active = void 0;
198
206
  membership = "";
199
207
  };
208
+ const register = (visibleOpcodes) => {
209
+ const api = host.gui?.blockEditors;
210
+ const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
211
+ const key = definitions.map((definition) => definition.editorId).join(",");
212
+ if (api === active && membership === key) return;
213
+ clear();
214
+ if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
215
+ try {
216
+ for (const definition of definitions) {
217
+ const remove = api.registerFixedInputEditor.call(api, definition);
218
+ if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
219
+ removers.push(remove);
220
+ }
221
+ active = api;
222
+ membership = key;
223
+ host.vm?.runtime?.on?.("RUNTIME_DISPOSED", release);
224
+ } catch (error) {
225
+ clear();
226
+ throw error;
227
+ }
228
+ };
229
+ /** The runtime of this project is gone; wait for the next project before registering again. */
230
+ const release = () => {
231
+ clear();
232
+ released = true;
233
+ host.vm?.runtime?.on?.("PROJECT_LOADED", restore);
234
+ };
235
+ const restore = () => {
236
+ if (stopped || !released) return;
237
+ released = false;
238
+ try {
239
+ register(requested);
240
+ } catch {}
241
+ };
200
242
  const shutdown = () => {
201
243
  stopped = true;
244
+ released = false;
202
245
  clear();
203
246
  };
204
247
  return {
205
248
  ensure(visibleOpcodes) {
206
- const api = host.gui?.blockEditors;
207
- const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
208
- const key = definitions.map((definition) => definition.editorId).join(",");
209
- if (stopped || api === active && membership === key) return;
210
- clear();
211
- if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
212
- try {
213
- for (const definition of definitions) {
214
- const remove = api.registerFixedInputEditor.call(api, definition);
215
- if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
216
- removers.push(remove);
217
- }
218
- active = api;
219
- membership = key;
220
- host.vm?.runtime?.on?.("RUNTIME_DISPOSED", shutdown);
221
- } catch (error) {
222
- clear();
223
- throw error;
224
- }
249
+ requested = visibleOpcodes;
250
+ if (stopped || released) return;
251
+ register(visibleOpcodes);
225
252
  },
226
253
  dispose: shutdown
227
254
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-text-lines",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Use multiline text in TurboWarp projects with line counting, lookup, and list-writing blocks.",
5
5
  "author": {
6
6
  "name": "Hiroya Kubo",
@@ -57,12 +57,12 @@
57
57
  "pages:build": "node scripts/prepare-pages.mjs"
58
58
  },
59
59
  "devDependencies": {
60
- "@kubohiroya/vite-plugin-turbowarp-extension": "^0.10.0",
60
+ "@kubohiroya/vite-plugin-turbowarp-extension": "^0.11.0",
61
61
  "@types/node": "^22.20.1",
62
62
  "typescript": "^5.9.3",
63
63
  "vite": "^8.2.2",
64
64
  "vitest": "^4.1.10",
65
- "@kubohiroya/turbowarp-extension-data-editor": "^0.5.0"
65
+ "@kubohiroya/turbowarp-extension-data-editor": "^0.11.0"
66
66
  },
67
67
  "gitHead": "86365d0f44d92bcf6ad828be8d165e4852abd7f4",
68
68
  "x-turbowarp-source": {