@kubohiroya/turbowarp-text-lines 0.6.0 → 0.6.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/dist/text-lines.js +48 -21
- package/package.json +1 -1
package/dist/text-lines.js
CHANGED
|
@@ -184,44 +184,71 @@ var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) =
|
|
|
184
184
|
settings: null
|
|
185
185
|
})
|
|
186
186
|
}));
|
|
187
|
-
/**
|
|
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",
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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