@kubohiroya/turbowarp-text-lines 0.2.0 → 0.2.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 +2 -0
- package/dist/text-lines.js +250 -0
- package/docs/fixed-input-editors.ja.md +17 -0
- package/package.json +20 -10
- package/schemas/block-editor-fixed-inputs.schema.json +18 -0
package/README.md
CHANGED
package/dist/text-lines.js
CHANGED
|
@@ -7,6 +7,211 @@
|
|
|
7
7
|
(function (Scratch) {
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
+
//#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.2.1_react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/fixed-input-schema.js
|
|
11
|
+
var numberToken = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/u;
|
|
12
|
+
var invalidNumber = Object.freeze({
|
|
13
|
+
kind: "invalid",
|
|
14
|
+
code: "fixed-number-input-invalid"
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Parse a NEW numeric draft according to NP-finite-new-input-v1.
|
|
18
|
+
* Never apply this to opening/no-op raw values or use it as an owner validator.
|
|
19
|
+
* Keep the validated token so negative zero, precision and exponent spelling survive.
|
|
20
|
+
*/
|
|
21
|
+
function parseFixedNumberInput(input) {
|
|
22
|
+
if (typeof input === "number") {
|
|
23
|
+
if (!Number.isFinite(input)) return invalidNumber;
|
|
24
|
+
return Object.freeze({
|
|
25
|
+
kind: "valid",
|
|
26
|
+
token: Object.is(input, -0) ? "-0" : String(input),
|
|
27
|
+
value: input
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (typeof input !== "string") return invalidNumber;
|
|
31
|
+
const token = input.trim();
|
|
32
|
+
if (!numberToken.test(token)) return invalidNumber;
|
|
33
|
+
const value = Number(token);
|
|
34
|
+
return Number.isFinite(value) ? Object.freeze({
|
|
35
|
+
kind: "valid",
|
|
36
|
+
token,
|
|
37
|
+
value
|
|
38
|
+
}) : invalidNumber;
|
|
39
|
+
}
|
|
40
|
+
var block_editor_fixed_inputs_schema_default = {
|
|
41
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
42
|
+
$id: "https://kubohiroya.github.io/turbowarp-text-lines/schemas/block-editor-fixed-inputs.schema.json",
|
|
43
|
+
$defs: { "lineAt": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"properties": { "LINE": { "type": "number" } },
|
|
46
|
+
"required": ["LINE"],
|
|
47
|
+
"additionalProperties": true
|
|
48
|
+
} }
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/fixed-input-schema.ts
|
|
52
|
+
var repository$1 = "turbowarp-text-lines";
|
|
53
|
+
/** The owner JSON document is canonical; this selects a primitive field fragment. */
|
|
54
|
+
function fixedInputBundle(opcode, argument) {
|
|
55
|
+
const source = {
|
|
56
|
+
repository: repository$1,
|
|
57
|
+
path: "schemas/block-editor-fixed-inputs.schema.json",
|
|
58
|
+
symbol: `#/$defs/${opcode}/properties/${argument}`
|
|
59
|
+
};
|
|
60
|
+
const blocks = block_editor_fixed_inputs_schema_default.$defs;
|
|
61
|
+
return {
|
|
62
|
+
identity: {
|
|
63
|
+
ownerId: repository$1,
|
|
64
|
+
contractId: opcode,
|
|
65
|
+
revision: "fixed-inputs-v1",
|
|
66
|
+
variantId: argument
|
|
67
|
+
},
|
|
68
|
+
dialect: "2020-12",
|
|
69
|
+
root: {
|
|
70
|
+
retrievalUri: block_editor_fixed_inputs_schema_default.$id,
|
|
71
|
+
document: blocks[opcode].properties[argument],
|
|
72
|
+
artifact: {
|
|
73
|
+
role: "canonical-schema",
|
|
74
|
+
source
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
resources: [],
|
|
78
|
+
provenance: {
|
|
79
|
+
canonicalSources: [source, {
|
|
80
|
+
repository: repository$1,
|
|
81
|
+
path: "src/extension.ts",
|
|
82
|
+
symbol: opcode
|
|
83
|
+
}],
|
|
84
|
+
generatedFiles: [],
|
|
85
|
+
referenceSchemas: [],
|
|
86
|
+
generationSources: []
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/fixed-input-editors.ts
|
|
92
|
+
var extensionId = "kubohiroyatextlines";
|
|
93
|
+
var repository = "turbowarp-text-lines";
|
|
94
|
+
var fields = [{
|
|
95
|
+
"opcode": "lineAt",
|
|
96
|
+
"argument": "LINE",
|
|
97
|
+
"control": "number",
|
|
98
|
+
"choices": [],
|
|
99
|
+
"normalization": "identity",
|
|
100
|
+
"shape": "math_number.NUM",
|
|
101
|
+
"maxBytes": false
|
|
102
|
+
}];
|
|
103
|
+
function literalString(value) {
|
|
104
|
+
if (typeof value !== "string") throw new TypeError("Expected a string literal.");
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
/** Legacy nonempty finite aliases are projections; opening never creates a write. */
|
|
108
|
+
function existingFixedNumber(value) {
|
|
109
|
+
if (typeof value !== "string" && typeof value !== "number" || typeof value === "string" && value.trim() === "") throw new TypeError("Unavailable numeric projection.");
|
|
110
|
+
const number = Number(value);
|
|
111
|
+
if (!Number.isFinite(number)) throw new TypeError("Unavailable numeric projection.");
|
|
112
|
+
return number;
|
|
113
|
+
}
|
|
114
|
+
function normalizeChoice(field, raw) {
|
|
115
|
+
if (field.normalization === "lowercase") return raw.toLowerCase();
|
|
116
|
+
if (field.normalization === "method") return raw.trim().toUpperCase();
|
|
117
|
+
if (field.normalization === "trim") return raw.trim();
|
|
118
|
+
if (field.normalization === "parse-format") {
|
|
119
|
+
const lower = raw.trim().toLowerCase();
|
|
120
|
+
return lower === "json" ? "JSON" : lower === "yaml" ? "YAML" : lower === "auto" ? "auto" : raw;
|
|
121
|
+
}
|
|
122
|
+
return raw;
|
|
123
|
+
}
|
|
124
|
+
function binding(field) {
|
|
125
|
+
return {
|
|
126
|
+
argument: field.argument,
|
|
127
|
+
schemaBundle: fixedInputBundle(field.opcode, field.argument),
|
|
128
|
+
control: {
|
|
129
|
+
kind: field.control,
|
|
130
|
+
...field.control === "enum" ? { choices: field.choices.map((value) => ({ value })) } : {}
|
|
131
|
+
},
|
|
132
|
+
read(value) {
|
|
133
|
+
return field.control === "number" ? existingFixedNumber(value) : normalizeChoice(field, literalString(value));
|
|
134
|
+
},
|
|
135
|
+
encode(value) {
|
|
136
|
+
if (field.control === "number") {
|
|
137
|
+
const parsed = parseFixedNumberInput(value);
|
|
138
|
+
if (parsed.kind !== "valid") throw new TypeError("Invalid new numeric input.");
|
|
139
|
+
return parsed.token;
|
|
140
|
+
}
|
|
141
|
+
const raw = literalString(value), normalized = normalizeChoice(field, raw);
|
|
142
|
+
if (!field.choices.includes(normalized)) throw new TypeError("Unsupported fixed choice.");
|
|
143
|
+
return field.shape === "menu-shadow" || field.shape === "direct-field-dropdown" ? normalized : raw;
|
|
144
|
+
},
|
|
145
|
+
validateCandidate(value) {
|
|
146
|
+
try {
|
|
147
|
+
if (field.control === "number") {
|
|
148
|
+
const number = existingFixedNumber(value);
|
|
149
|
+
if (field.maxBytes && (!Number.isSafeInteger(Math.trunc(number)) || Math.trunc(number) < 1)) return [{ message: "Invalid named body size." }];
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
return field.choices.includes(normalizeChoice(field, literalString(value))) ? [] : [{ message: "Unsupported fixed choice." }];
|
|
153
|
+
} catch {
|
|
154
|
+
return [{ message: "Invalid fixed input." }];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) => ({
|
|
160
|
+
apiVersion: 1,
|
|
161
|
+
extensionId,
|
|
162
|
+
editorId: `${opcode}-fixed-inputs`,
|
|
163
|
+
opcodes: [`${extensionId}_${opcode}`],
|
|
164
|
+
contractId: `${repository}/${opcode}`,
|
|
165
|
+
contractRevision: "fixed-inputs-v1",
|
|
166
|
+
bindings: fields.filter((field) => field.opcode === opcode).map(binding),
|
|
167
|
+
validationContext: () => ({
|
|
168
|
+
consumerId: repository,
|
|
169
|
+
nowMs: 0,
|
|
170
|
+
settings: null
|
|
171
|
+
})
|
|
172
|
+
}));
|
|
173
|
+
/** Registration follows the advertised opcode membership and the optional host capability. */
|
|
174
|
+
function fixedInputRegistration(scratch) {
|
|
175
|
+
const host = scratch ?? {};
|
|
176
|
+
let active;
|
|
177
|
+
let membership = "";
|
|
178
|
+
const removers = [];
|
|
179
|
+
let stopped = false;
|
|
180
|
+
const clear = () => {
|
|
181
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", shutdown);
|
|
182
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
183
|
+
active = void 0;
|
|
184
|
+
membership = "";
|
|
185
|
+
};
|
|
186
|
+
const shutdown = () => {
|
|
187
|
+
stopped = true;
|
|
188
|
+
clear();
|
|
189
|
+
};
|
|
190
|
+
return {
|
|
191
|
+
ensure(visibleOpcodes) {
|
|
192
|
+
const api = host.gui?.blockEditors;
|
|
193
|
+
const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
|
|
194
|
+
const key = definitions.map((definition) => definition.editorId).join(",");
|
|
195
|
+
if (stopped || api === active && membership === key) return;
|
|
196
|
+
clear();
|
|
197
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
|
|
198
|
+
try {
|
|
199
|
+
for (const definition of definitions) {
|
|
200
|
+
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
201
|
+
if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
|
|
202
|
+
removers.push(remove);
|
|
203
|
+
}
|
|
204
|
+
active = api;
|
|
205
|
+
membership = key;
|
|
206
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", shutdown);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
clear();
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
dispose: shutdown
|
|
213
|
+
};
|
|
214
|
+
}
|
|
10
215
|
var block_definitions_default = {
|
|
11
216
|
extensionName: "Text Lines",
|
|
12
217
|
blocks: [
|
|
@@ -55,10 +260,55 @@
|
|
|
55
260
|
]
|
|
56
261
|
};
|
|
57
262
|
//#endregion
|
|
263
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
264
|
+
function _typeof(o) {
|
|
265
|
+
"@babel/helpers - typeof";
|
|
266
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
267
|
+
return typeof o;
|
|
268
|
+
} : function(o) {
|
|
269
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
270
|
+
}, _typeof(o);
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
274
|
+
function toPrimitive(t, r) {
|
|
275
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
276
|
+
var e = t[Symbol.toPrimitive];
|
|
277
|
+
if (void 0 !== e) {
|
|
278
|
+
var i = e.call(t, r || "default");
|
|
279
|
+
if ("object" != _typeof(i)) return i;
|
|
280
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
281
|
+
}
|
|
282
|
+
return ("string" === r ? String : Number)(t);
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
286
|
+
function toPropertyKey(t) {
|
|
287
|
+
var i = toPrimitive(t, "string");
|
|
288
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
292
|
+
function _defineProperty(e, r, t) {
|
|
293
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
294
|
+
value: t,
|
|
295
|
+
enumerable: !0,
|
|
296
|
+
configurable: !0,
|
|
297
|
+
writable: !0
|
|
298
|
+
}) : e[r] = t, e;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
58
301
|
//#region src/extension.ts
|
|
59
302
|
var blockDefinitions = block_definitions_default.blocks;
|
|
60
303
|
var TextLinesExtension = class {
|
|
304
|
+
constructor() {
|
|
305
|
+
_defineProperty(this, "fixedInputs", fixedInputRegistration(typeof Scratch === "undefined" ? void 0 : Scratch));
|
|
306
|
+
}
|
|
307
|
+
dispose() {
|
|
308
|
+
this.fixedInputs.dispose();
|
|
309
|
+
}
|
|
61
310
|
getInfo() {
|
|
311
|
+
this.fixedInputs.ensure(blockDefinitions.map((block) => `kubohiroyatextlines_${block.opcode}`));
|
|
62
312
|
const translate = Scratch.translate;
|
|
63
313
|
return {
|
|
64
314
|
id: "kubohiroyatextlines",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 固定入力の編集
|
|
2
|
+
|
|
3
|
+
S3-4のローカル実装です。対応GUIの固定入力機能は既定OFFです。旧GUI・API無し・固定入力機能OFFではブロックの従来動作を保ちます。`getInfo()` に存在する対象opcodeだけ登録し、再取得・APIの置換・拡張の`dispose()`・runtimeの破棄に対応します。既存SOURCEエディターとopcodeは分離しています。
|
|
4
|
+
|
|
5
|
+
|ブロックopcode|引数|UI|
|
|
6
|
+
|---|---|---|
|
|
7
|
+
|`lineAt`|`LINE`|数値入力(NP)|
|
|
8
|
+
|
|
9
|
+
数値の新規入力は、空白を除いた完全な有限JSON数値トークンを受け付け、指数表記・負のゼロ・表記を保持します。空文字、16進表記、先頭の`+`、先頭ゼロや未完成トークンは新規保存しません。既存値は開いただけで書き換えません。既存の有限数値別表記は参照用に投影し、未編集の生値を保ちます。未知の旧enum値も無操作では保存し直しません。
|
|
10
|
+
|
|
11
|
+
`LINE` は有限数を受け付け、既存の切捨てと範囲外時の空文字を維持します。リスト名候補や接続reporterは評価しません。
|
|
12
|
+
|
|
13
|
+
reporter接続は読取専用で、実行・置換しません。新しい選択や数値を保存するときだけ純粋codecとSchemaで検証します。検証失敗時は全変更を拒否し、ブロックや接続を部分的に書き換えません。
|
|
14
|
+
|
|
15
|
+
正本は本ownerの `schemas/block-editor-fixed-inputs.schema.json`、TSモジュールは選択・参照用、`dist`は生成物です。外部候補取得や実行時Schema生成は行いません。
|
|
16
|
+
|
|
17
|
+
切戻しはGUIの固定入力機能OFFで行えます。既存のプロジェクト形式・opcode・メニュー・defaultValue・実行時の処理は維持します。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-text-lines",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Use multiline text in TurboWarp projects with line counting, lookup, and list-writing blocks.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -24,22 +24,18 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/",
|
|
26
26
|
"README.md",
|
|
27
|
-
"LICENSE"
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"schemas/",
|
|
29
|
+
"docs/fixed-input-editors.ja.md"
|
|
28
30
|
],
|
|
29
31
|
"publishConfig": {
|
|
30
32
|
"access": "public",
|
|
31
33
|
"registry": "https://registry.npmjs.org/"
|
|
32
34
|
},
|
|
35
|
+
"packageManager": "pnpm@11.11.0",
|
|
33
36
|
"engines": {
|
|
34
37
|
"node": ">=22.18.0"
|
|
35
38
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
38
|
-
"@types/node": "^22.20.1",
|
|
39
|
-
"typescript": "^5.9.3",
|
|
40
|
-
"vite": "^8.2.2",
|
|
41
|
-
"vitest": "^4.1.10"
|
|
42
|
-
},
|
|
43
39
|
"scripts": {
|
|
44
40
|
"dev": "vite build --watch",
|
|
45
41
|
"typecheck": "tsc --noEmit",
|
|
@@ -51,5 +47,19 @@
|
|
|
51
47
|
"repo:check": "node scripts/check-repo.ts",
|
|
52
48
|
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
53
49
|
"check": "pnpm run typecheck && pnpm run test && pnpm run build && pnpm run docs:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "0.6.1",
|
|
53
|
+
"@types/node": "^22.20.1",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"vite": "^8.2.2",
|
|
56
|
+
"vitest": "^4.1.10",
|
|
57
|
+
"@kubohiroya/turbowarp-extension-data-editor": "0.2.1"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "6c59c2dd0cc4634192a4e5c210fe4e09e4b8a0be",
|
|
60
|
+
"x-turbowarp-source": {
|
|
61
|
+
"revision": "6c59c2dd0cc4634192a4e5c210fe4e09e4b8a0be",
|
|
62
|
+
"revisionRole": "base-commit",
|
|
63
|
+
"sourceState": "local-release-overlay"
|
|
54
64
|
}
|
|
55
|
-
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://kubohiroya.github.io/turbowarp-text-lines/schemas/block-editor-fixed-inputs.schema.json",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"lineAt": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"LINE": {
|
|
9
|
+
"type": "number"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"required": [
|
|
13
|
+
"LINE"
|
|
14
|
+
],
|
|
15
|
+
"additionalProperties": true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|