@kubohiroya/turbowarp-markdown 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/README.md +1 -1
- package/dist/turbowarp-markdown.js +48 -21
- package/package.json +1 -1
- package/src/fixed-input-editors.ts +44 -19
package/README.md
CHANGED
|
@@ -183,44 +183,71 @@ var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) =
|
|
|
183
183
|
settings: null
|
|
184
184
|
})
|
|
185
185
|
}));
|
|
186
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Registration follows the advertised opcode membership and the optional host capability.
|
|
188
|
+
* Loading a project disposes the runtime, which releases the registrations, but the extension
|
|
189
|
+
* stays loaded for the next project: they are registered again once that project has loaded.
|
|
190
|
+
* Only the owner's dispose is final.
|
|
191
|
+
*/
|
|
187
192
|
function fixedInputRegistration(scratch) {
|
|
188
193
|
const host = scratch ?? {};
|
|
189
194
|
let active;
|
|
190
195
|
let membership = "";
|
|
191
196
|
const removers = [];
|
|
192
197
|
let stopped = false;
|
|
198
|
+
let released = false;
|
|
199
|
+
let requested = [];
|
|
193
200
|
const clear = () => {
|
|
194
|
-
host.vm?.runtime?.off?.("RUNTIME_DISPOSED",
|
|
201
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", release);
|
|
202
|
+
host.vm?.runtime?.off?.("PROJECT_LOADED", restore);
|
|
195
203
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
196
204
|
active = void 0;
|
|
197
205
|
membership = "";
|
|
198
206
|
};
|
|
207
|
+
const register = (visibleOpcodes) => {
|
|
208
|
+
const api = host.gui?.blockEditors;
|
|
209
|
+
const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
|
|
210
|
+
const key = definitions.map((definition) => definition.editorId).join(",");
|
|
211
|
+
if (api === active && membership === key) return;
|
|
212
|
+
clear();
|
|
213
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
|
|
214
|
+
try {
|
|
215
|
+
for (const definition of definitions) {
|
|
216
|
+
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
217
|
+
if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
|
|
218
|
+
removers.push(remove);
|
|
219
|
+
}
|
|
220
|
+
active = api;
|
|
221
|
+
membership = key;
|
|
222
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", release);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
clear();
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
/** The runtime of this project is gone; wait for the next project before registering again. */
|
|
229
|
+
const release = () => {
|
|
230
|
+
clear();
|
|
231
|
+
released = true;
|
|
232
|
+
host.vm?.runtime?.on?.("PROJECT_LOADED", restore);
|
|
233
|
+
};
|
|
234
|
+
const restore = () => {
|
|
235
|
+
if (stopped || !released) return;
|
|
236
|
+
released = false;
|
|
237
|
+
try {
|
|
238
|
+
register(requested);
|
|
239
|
+
} catch {}
|
|
240
|
+
};
|
|
199
241
|
const shutdown = () => {
|
|
200
242
|
stopped = true;
|
|
243
|
+
released = false;
|
|
201
244
|
clear();
|
|
202
245
|
};
|
|
203
246
|
return {
|
|
204
247
|
ensure(visibleOpcodes) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (stopped || api === active && membership === key) return;
|
|
209
|
-
clear();
|
|
210
|
-
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
|
|
211
|
-
try {
|
|
212
|
-
for (const definition of definitions) {
|
|
213
|
-
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
214
|
-
if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
|
|
215
|
-
removers.push(remove);
|
|
216
|
-
}
|
|
217
|
-
active = api;
|
|
218
|
-
membership = key;
|
|
219
|
-
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", shutdown);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
clear();
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
248
|
+
requested = visibleOpcodes;
|
|
249
|
+
if (stopped || released) return;
|
|
250
|
+
register(visibleOpcodes);
|
|
224
251
|
},
|
|
225
252
|
dispose: shutdown
|
|
226
253
|
};
|
package/package.json
CHANGED
|
@@ -75,38 +75,63 @@ interface OptionalFixedHost {
|
|
|
75
75
|
gui?: {blockEditors?: {apiVersion?: number; registerFixedInputEditor?: (definition: FixedInputEditorOptions) => () => void}};
|
|
76
76
|
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
77
77
|
}
|
|
78
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Registration follows the advertised opcode membership and the optional host capability.
|
|
80
|
+
* Loading a project disposes the runtime, which releases the registrations, but the extension
|
|
81
|
+
* stays loaded for the next project: they are registered again once that project has loaded.
|
|
82
|
+
* Only the owner's dispose is final.
|
|
83
|
+
*/
|
|
79
84
|
export function fixedInputRegistration(scratch: unknown) {
|
|
80
85
|
const host = (scratch ?? {}) as OptionalFixedHost;
|
|
81
86
|
let active: unknown;
|
|
82
87
|
let membership = '';
|
|
83
88
|
const removers: (() => void)[] = [];
|
|
84
89
|
let stopped = false;
|
|
90
|
+
let released = false;
|
|
91
|
+
let requested: readonly string[] = [];
|
|
85
92
|
const clear = () => {
|
|
86
|
-
host.vm?.runtime?.off?.('RUNTIME_DISPOSED',
|
|
93
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', release);
|
|
94
|
+
host.vm?.runtime?.off?.('PROJECT_LOADED', restore);
|
|
87
95
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
88
96
|
active = undefined;
|
|
89
97
|
membership = '';
|
|
90
98
|
};
|
|
91
|
-
const
|
|
99
|
+
const register = (visibleOpcodes: readonly string[]) => {
|
|
100
|
+
const api = host.gui?.blockEditors;
|
|
101
|
+
const definitions = fixedInputEditors.filter(definition => definition.opcodes.every(opcode => visibleOpcodes.includes(opcode)));
|
|
102
|
+
const key = definitions.map(definition => definition.editorId).join(',');
|
|
103
|
+
if (api === active && membership === key) return;
|
|
104
|
+
clear();
|
|
105
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function' || !definitions.length) return;
|
|
106
|
+
try {
|
|
107
|
+
for (const definition of definitions) {
|
|
108
|
+
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
109
|
+
if (typeof remove !== 'function') throw new TypeError('Invalid fixed input cleanup.');
|
|
110
|
+
removers.push(remove);
|
|
111
|
+
}
|
|
112
|
+
active = api;
|
|
113
|
+
membership = key;
|
|
114
|
+
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', release);
|
|
115
|
+
} catch (error) {clear(); throw error;}
|
|
116
|
+
};
|
|
117
|
+
/** The runtime of this project is gone; wait for the next project before registering again. */
|
|
118
|
+
const release = () => {
|
|
119
|
+
clear();
|
|
120
|
+
released = true;
|
|
121
|
+
host.vm?.runtime?.on?.('PROJECT_LOADED', restore);
|
|
122
|
+
};
|
|
123
|
+
const restore = () => {
|
|
124
|
+
if (stopped || !released) return;
|
|
125
|
+
released = false;
|
|
126
|
+
// A refusal here must not break the VM's event dispatch; the next getInfo() retries.
|
|
127
|
+
try {register(requested);} catch {/* retried by the next ensure() */}
|
|
128
|
+
};
|
|
129
|
+
const shutdown = () => {stopped = true; released = false; clear();};
|
|
92
130
|
return {
|
|
93
131
|
ensure(visibleOpcodes: readonly string[]) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (stopped || (api === active && membership === key)) return;
|
|
98
|
-
clear();
|
|
99
|
-
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function' || !definitions.length) return;
|
|
100
|
-
try {
|
|
101
|
-
for (const definition of definitions) {
|
|
102
|
-
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
103
|
-
if (typeof remove !== 'function') throw new TypeError('Invalid fixed input cleanup.');
|
|
104
|
-
removers.push(remove);
|
|
105
|
-
}
|
|
106
|
-
active = api;
|
|
107
|
-
membership = key;
|
|
108
|
-
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', shutdown);
|
|
109
|
-
} catch (error) {clear(); throw error;}
|
|
132
|
+
requested = visibleOpcodes;
|
|
133
|
+
if (stopped || released) return;
|
|
134
|
+
register(visibleOpcodes);
|
|
110
135
|
},
|
|
111
136
|
dispose: shutdown
|
|
112
137
|
};
|