@kubohiroya/turbowarp-markdown 0.2.0 → 0.3.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.
- package/README.ja.md +5 -1
- package/README.md +6 -2
- package/assets/block-icon.svg +1 -0
- package/dist/turbowarp-markdown.js +843 -630
- package/docs/fixed-input-editors.ja.md +17 -0
- package/docs/index.html +53 -2
- package/package.json +24 -14
- package/schemas/block-editor-fixed-inputs.schema.json +18 -0
- package/src/config.ts +1 -1
- package/src/extension.ts +6 -0
- package/src/fixed-input-editors.ts +113 -0
- package/src/fixed-input-schema.ts +15 -0
- package/schemas/extension-manifest.schema.json +0 -49
- package/src/extension-manifest.ts +0 -149
|
@@ -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
|
+
|`heading`|`LEVEL`|数値入力(NP)|
|
|
8
|
+
|
|
9
|
+
数値の新規入力は、空白を除いた完全な有限JSON数値トークンを受け付け、指数表記・負のゼロ・表記を保持します。空文字、16進表記、先頭の`+`、先頭ゼロや未完成トークンは新規保存しません。既存値は開いただけで書き換えません。既存の有限数値別表記は参照用に投影し、未編集の生値を保ちます。未知の旧enum値も無操作では保存し直しません。
|
|
10
|
+
|
|
11
|
+
`LEVEL` は有限数を受け付け、実行時の既存の切捨てと1〜6への補正を維持します。編集Schemaを整数1〜6へ狭めません。
|
|
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/docs/index.html
CHANGED
|
@@ -10,9 +10,26 @@
|
|
|
10
10
|
pre{background:#f8fafc;border:1px solid #e5e7eb;padding:1rem;overflow:auto;border-radius:.5rem}
|
|
11
11
|
table{border-collapse:collapse;width:100%}
|
|
12
12
|
th,td{border:1px solid #d1d5db;padding:.5rem;text-align:left;vertical-align:top}
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
:root{color-scheme:light dark}
|
|
15
|
+
@media (prefers-color-scheme:dark){
|
|
16
|
+
body{color:#e7eaf2;background:#12141a}
|
|
17
|
+
code{background:#242833}
|
|
18
|
+
pre{background:#1b1e26;border-color:#2a303b}
|
|
19
|
+
th,td{border-color:#2a303b}
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
<style id="block-reference-style">
|
|
23
|
+
#extension-block-reference{max-width:72rem;margin:2rem auto;padding:1rem;line-height:1.6;overflow-wrap:anywhere}
|
|
24
|
+
#extension-block-reference .block-reference-entry{display:block;scroll-margin-top:6rem;margin:2rem 0;padding:1rem;border:1px solid currentColor;border-radius:.5rem}
|
|
25
|
+
#extension-block-reference .block-reference-table{overflow-x:auto}
|
|
26
|
+
#extension-block-reference table{border-collapse:collapse;width:100%}
|
|
27
|
+
#extension-block-reference th,#extension-block-reference td{text-align:left;vertical-align:top;border:1px solid currentColor;padding:.5rem}
|
|
28
|
+
#extension-block-reference code{white-space:pre-wrap}
|
|
29
|
+
#extension-block-reference a:focus-visible{outline:3px solid currentColor;outline-offset:3px}
|
|
30
|
+
</style>
|
|
14
31
|
</head>
|
|
15
|
-
<body>
|
|
32
|
+
<body><p lang="en" class="complete-block-reference-link"><a href="#extension-block-reference">Complete block reference (19 blocks)</a></p>
|
|
16
33
|
<h1>TurboWarp Markdown</h1>
|
|
17
34
|
<p>TurboWarp Markdown builds Markdown as immutable structured fragments. Blocks create escaped inline fragments, block fragments, lists, and sequences; final Markdown text is produced only by an explicit render block.</p>
|
|
18
35
|
|
|
@@ -48,5 +65,39 @@ render Markdown [combined result]</code></pre>
|
|
|
48
65
|
|
|
49
66
|
<h2>TypeScript API</h2>
|
|
50
67
|
<p>The package also exports block-free builder functions from <code>@kubohiroya/turbowarp-markdown</code>, including <code>text</code>, <code>bold</code>, <code>italic</code>, <code>link</code>, <code>heading</code>, <code>paragraph</code>, <code>quote</code>, <code>codeBlock</code>, <code>listItem</code>, <code>unorderedList</code>, <code>orderedList</code>, <code>concat</code>, and <code>render</code>.</p>
|
|
68
|
+
<!-- BEGIN COMPLETE BLOCK REFERENCE -->
|
|
69
|
+
<section lang="en" id="extension-block-reference" aria-labelledby="block-reference-title">
|
|
70
|
+
<h2 id="block-reference-title">TurboWarp Markdown: complete block reference</h2>
|
|
71
|
+
<p>All 19 blocks are documented below, including compatibility blocks and blocks available through optional features. Select a block to read its behavior, arguments, default values, and menu choices. Each block has a permanent link.</p>
|
|
72
|
+
<nav aria-label="Block reference"><ul><li><a href="#block-text"><code>text [TEXT]</code></a></li>
|
|
73
|
+
<li><a href="#block-bold"><code>bold [CONTENT]</code></a></li>
|
|
74
|
+
<li><a href="#block-italic"><code>italic [CONTENT]</code></a></li>
|
|
75
|
+
<li><a href="#block-link"><code>link [CONTENT] URL [URL]</code></a></li>
|
|
76
|
+
<li><a href="#block-code"><code>code [TEXT]</code></a></li>
|
|
77
|
+
<li><a href="#block-heading"><code>heading [LEVEL] [CONTENT]</code></a></li>
|
|
78
|
+
<li><a href="#block-paragraph"><code>paragraph [CONTENT]</code></a></li>
|
|
79
|
+
<li><a href="#block-quote"><code>quote [CONTENT]</code></a></li>
|
|
80
|
+
<li><a href="#block-codeBlock"><code>code block [TEXT] language [LANGUAGE]</code></a></li>
|
|
81
|
+
<li><a href="#block-listItem"><code>list item [CONTENT]</code></a></li>
|
|
82
|
+
<li><a href="#block-unorderedList"><code>unordered list [ITEMS]</code></a></li>
|
|
83
|
+
<li><a href="#block-orderedList"><code>ordered list [ITEMS]</code></a></li>
|
|
84
|
+
<li><a href="#block-concat"><code>[LEFT] followed by [RIGHT]</code></a></li>
|
|
85
|
+
<li><a href="#block-render"><code>render Markdown [FRAGMENT]</code></a></li>
|
|
86
|
+
<li><a href="#block-renderWithValidation"><code>render Markdown with validation [FRAGMENT]</code></a></li>
|
|
87
|
+
<li><a href="#block-lastValidationErrors"><code>last Markdown validation errors</code></a></li>
|
|
88
|
+
<li><a href="#block-lastRenderHasValidationErrors"><code>last rendered Markdown has validation errors?</code></a></li>
|
|
89
|
+
<li><a href="#block-validateMarkdown"><code>validate Markdown [FRAGMENT]</code></a></li>
|
|
90
|
+
<li><a href="#block-isValidMarkdown"><code>Markdown [FRAGMENT] is valid?</code></a></li>
|
|
91
|
+
</ul></nav>
|
|
92
|
+
<article id="block-text" class="block-reference-entry"><h3><code>text [TEXT]</code></h3><p>Creates escaped Markdown text.</p><p>Block type: REPORTER. Opcode: <code>text</code>. <a href="#block-text">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>TEXT</code></th><td>STRING</td><td><code>Hello *world*</code></td><td></td></tr></tbody></table></div></article><article id="block-bold" class="block-reference-entry"><h3><code>bold [CONTENT]</code></h3><p>Creates bold inline Markdown content.</p><p>Block type: REPORTER. Opcode: <code>bold</code>. <a href="#block-bold">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>important</code></td><td></td></tr></tbody></table></div></article><article id="block-italic" class="block-reference-entry"><h3><code>italic [CONTENT]</code></h3><p>Creates italic inline Markdown content.</p><p>Block type: REPORTER. Opcode: <code>italic</code>. <a href="#block-italic">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>note</code></td><td></td></tr></tbody></table></div></article><article id="block-link" class="block-reference-entry"><h3><code>link [CONTENT] URL [URL]</code></h3><p>Creates a Markdown link with a conservatively validated destination.</p><p>Block type: REPORTER. Opcode: <code>link</code>. <a href="#block-link">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>TurboWarp</code></td><td></td></tr><tr><th scope="row"><code>URL</code></th><td>STRING</td><td><code>https://turbowarp.org/</code></td><td></td></tr></tbody></table></div></article><article id="block-code" class="block-reference-entry"><h3><code>code [TEXT]</code></h3><p>Creates inline code content.</p><p>Block type: REPORTER. Opcode: <code>code</code>. <a href="#block-code">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>TEXT</code></th><td>STRING</td><td><code>status</code></td><td></td></tr></tbody></table></div></article><article id="block-heading" class="block-reference-entry"><h3><code>heading [LEVEL] [CONTENT]</code></h3><p>Creates a heading with the level clamped to 1 through 6.</p><p>Block type: REPORTER. Opcode: <code>heading</code>. <a href="#block-heading">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>LEVEL</code></th><td>NUMBER</td><td><code>1</code></td><td></td></tr><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>Sensor</code></td><td></td></tr></tbody></table></div><p lang="ja" class="fixed-input-help"><a href="#fixed-input-editors">このブロックの固定入力編集と互換性</a></p>
|
|
93
|
+
</article><article id="block-paragraph" class="block-reference-entry"><h3><code>paragraph [CONTENT]</code></h3><p>Creates a paragraph block.</p><p>Block type: REPORTER. Opcode: <code>paragraph</code>. <a href="#block-paragraph">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>ready</code></td><td></td></tr></tbody></table></div></article><article id="block-quote" class="block-reference-entry"><h3><code>quote [CONTENT]</code></h3><p>Creates a block quote.</p><p>Block type: REPORTER. Opcode: <code>quote</code>. <a href="#block-quote">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>quoted</code></td><td></td></tr></tbody></table></div></article><article id="block-codeBlock" class="block-reference-entry"><h3><code>code block [TEXT] language [LANGUAGE]</code></h3><p>Creates a fenced code block.</p><p>Block type: REPORTER. Opcode: <code>codeBlock</code>. <a href="#block-codeBlock">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>TEXT</code></th><td>STRING</td><td><code>console.log('ok')</code></td><td></td></tr><tr><th scope="row"><code>LANGUAGE</code></th><td>STRING</td><td><code>js</code></td><td></td></tr></tbody></table></div></article><article id="block-listItem" class="block-reference-entry"><h3><code>list item [CONTENT]</code></h3><p>Creates a list item fragment.</p><p>Block type: REPORTER. Opcode: <code>listItem</code>. <a href="#block-listItem">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>CONTENT</code></th><td>STRING</td><td><code>item</code></td><td></td></tr></tbody></table></div></article><article id="block-unorderedList" class="block-reference-entry"><h3><code>unordered list [ITEMS]</code></h3><p>Creates an unordered list from item fragments.</p><p>Block type: REPORTER. Opcode: <code>unorderedList</code>. <a href="#block-unorderedList">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>ITEMS</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-orderedList" class="block-reference-entry"><h3><code>ordered list [ITEMS]</code></h3><p>Creates an ordered list from item fragments.</p><p>Block type: REPORTER. Opcode: <code>orderedList</code>. <a href="#block-orderedList">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>ITEMS</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-concat" class="block-reference-entry"><h3><code>[LEFT] followed by [RIGHT]</code></h3><p>Creates a new Markdown fragment sequence without mutating either input.</p><p>Block type: REPORTER. Opcode: <code>concat</code>. <a href="#block-concat">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>LEFT</code></th><td>STRING</td><td><code></code></td><td></td></tr><tr><th scope="row"><code>RIGHT</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-render" class="block-reference-entry"><h3><code>render Markdown [FRAGMENT]</code></h3><p>Renders a Markdown fragment to final Markdown text without updating stored validation errors.</p><p>Block type: REPORTER. Opcode: <code>render</code>. <a href="#block-render">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>FRAGMENT</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-renderWithValidation" class="block-reference-entry"><h3><code>render Markdown with validation [FRAGMENT]</code></h3><p>Validates a Markdown fragment, stores any validation errors, and renders final Markdown text.</p><p>Block type: REPORTER. Opcode: <code>renderWithValidation</code>. <a href="#block-renderWithValidation">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>FRAGMENT</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-lastValidationErrors" class="block-reference-entry"><h3><code>last Markdown validation errors</code></h3><p>Returns validation errors stored by the most recent render Markdown with validation block.</p><p>Block type: REPORTER. Opcode: <code>lastValidationErrors</code>. <a href="#block-lastValidationErrors">Permanent link</a></p><p>This block has no arguments.</p></article><article id="block-lastRenderHasValidationErrors" class="block-reference-entry"><h3><code>last rendered Markdown has validation errors?</code></h3><p>Reports whether the most recent validated Markdown render stored validation errors.</p><p>Block type: BOOLEAN. Opcode: <code>lastRenderHasValidationErrors</code>. <a href="#block-lastRenderHasValidationErrors">Permanent link</a></p><p>This block has no arguments.</p></article><article id="block-validateMarkdown" class="block-reference-entry"><h3><code>validate Markdown [FRAGMENT]</code></h3><p>Returns simple validation diagnostics for a Markdown fragment.</p><p>Block type: REPORTER. Opcode: <code>validateMarkdown</code>. <a href="#block-validateMarkdown">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>FRAGMENT</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article><article id="block-isValidMarkdown" class="block-reference-entry"><h3><code>Markdown [FRAGMENT] is valid?</code></h3><p>Reports whether simple validation found no Markdown errors.</p><p>Block type: BOOLEAN. Opcode: <code>isValidMarkdown</code>. <a href="#block-isValidMarkdown">Permanent link</a></p><div class="block-reference-table"><table><thead><tr><th>Argument</th><th>Type</th><th>Default value</th><th>Menu choices</th></tr></thead><tbody><tr><th scope="row"><code>FRAGMENT</code></th><td>STRING</td><td><code></code></td><td></td></tr></tbody></table></div></article>
|
|
94
|
+
<p><a href="https://github.com/kubohiroya/turbowarp-markdown/blob/main/README.md">Repository guide and examples</a></p>
|
|
95
|
+
</section>
|
|
96
|
+
<!-- END COMPLETE BLOCK REFERENCE -->
|
|
97
|
+
<section lang="ja" id="fixed-input-editors"><h2>固定入力の編集</h2><p>対応GUIの固定入力機能は既定OFFです。既存値は開いただけでは変更せず、reporter接続は評価・置換しません。新しい選択と有限JSON数値入力のみを検証して保存し、既存の補正・丸め処理を維持します。機能OFFで従来の編集へ戻せます。</p><p><a href="fixed-input-editors.ja.md">対象入力・Schemaの正本・互換性・切戻し</a></p></section>
|
|
98
|
+
<!-- The shared TurboWarp Plus header. It inserts itself at the top of the
|
|
99
|
+
page in a shadow root, so it cannot disturb the styles below. -->
|
|
100
|
+
<script type="module"
|
|
101
|
+
src="https://kubohiroya.github.io/turbowarp-plus-site-header/dist/auto.js"></script>
|
|
51
102
|
</body>
|
|
52
103
|
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "An immutable Markdown builder extension for TurboWarp.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
25
|
"files": [
|
|
26
|
+
"assets/",
|
|
26
27
|
"dist/",
|
|
27
28
|
"docs/",
|
|
28
|
-
"schemas/",
|
|
29
29
|
"src/",
|
|
30
30
|
"README.md",
|
|
31
31
|
"README.ja.md",
|
|
32
|
-
"LICENSE"
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"schemas/"
|
|
33
34
|
],
|
|
34
35
|
"exports": {
|
|
35
36
|
".": "./src/markdown.ts",
|
|
@@ -39,19 +40,10 @@
|
|
|
39
40
|
"access": "public",
|
|
40
41
|
"registry": "https://registry.npmjs.org/"
|
|
41
42
|
},
|
|
43
|
+
"packageManager": "pnpm@11.11.0",
|
|
42
44
|
"engines": {
|
|
43
45
|
"node": ">=22.18.0"
|
|
44
46
|
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@eslint/js": "^9.39.5",
|
|
47
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
48
|
-
"@types/node": "^24.13.3",
|
|
49
|
-
"eslint": "^9.39.5",
|
|
50
|
-
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.66.0",
|
|
52
|
-
"vite": "^8.2.2",
|
|
53
|
-
"vitest": "^4.1.10"
|
|
54
|
-
},
|
|
55
47
|
"scripts": {
|
|
56
48
|
"dev": "vite build --watch",
|
|
57
49
|
"typecheck": "tsc --noEmit",
|
|
@@ -65,5 +57,23 @@
|
|
|
65
57
|
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
66
58
|
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run docs:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
67
59
|
"check:dist": "pnpm run build && node scripts/check-dist.ts"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/js": "^9.39.5",
|
|
63
|
+
"@kubohiroya/turbowarp-extension-manifest": "^0.3.2",
|
|
64
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "^0.8.0",
|
|
65
|
+
"@types/node": "^24.13.3",
|
|
66
|
+
"eslint": "^9.39.5",
|
|
67
|
+
"typescript": "^5.9.3",
|
|
68
|
+
"typescript-eslint": "^8.66.0",
|
|
69
|
+
"vite": "^8.2.2",
|
|
70
|
+
"vitest": "^4.1.10",
|
|
71
|
+
"@kubohiroya/turbowarp-extension-data-editor": "^0.3.4"
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "23c6fc48d20d69219b8ba6e5e2ab5c7e674623fc",
|
|
74
|
+
"x-turbowarp-source": {
|
|
75
|
+
"revision": "23c6fc48d20d69219b8ba6e5e2ab5c7e674623fc",
|
|
76
|
+
"revisionRole": "base-commit",
|
|
77
|
+
"sourceState": "local-release-overlay"
|
|
68
78
|
}
|
|
69
|
-
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://kubohiroya.github.io/turbowarp-markdown/schemas/block-editor-fixed-inputs.schema.json",
|
|
4
|
+
"$defs": {
|
|
5
|
+
"heading": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"LEVEL": {
|
|
9
|
+
"type": "number"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"required": [
|
|
13
|
+
"LEVEL"
|
|
14
|
+
],
|
|
15
|
+
"additionalProperties": true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -8,5 +8,5 @@ export const extensionConfig = {
|
|
|
8
8
|
unsandboxed: false,
|
|
9
9
|
docsURI: 'https://kubohiroya.github.io/turbowarp-markdown/',
|
|
10
10
|
blockIconURI:
|
|
11
|
-
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+
|
|
11
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCI+PHJlY3QgeD0iNiIgeT0iOCIgd2lkdGg9IjM2IiBoZWlnaHQ9IjMyIiByeD0iNCIgZmlsbD0iIzJGNjM4NiIvPjxwYXRoIGQ9Ik0xMyAzMFYxOGw1IDcgNS03djEyTTI3LjUgMjB2MTBNMjcuNSAyMGgyLjVhNSA1IDAgMCAxIDAgMTBoLTIuNSIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmZmZmIiBzdHJva2Utd2lkdGg9IjMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg=='
|
|
12
12
|
} as const;
|
package/src/extension.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {fixedInputRegistration} from './fixed-input-editors.js';
|
|
1
2
|
import {extensionConfig} from './config';
|
|
2
3
|
import definitions from './block-definitions.json';
|
|
3
4
|
import {
|
|
@@ -44,7 +45,12 @@ const SERIALIZED_PREFIX = 'turbowarp-markdown:v1:';
|
|
|
44
45
|
const blockDefinitions = definitions.blocks as readonly BlockDefinition[];
|
|
45
46
|
|
|
46
47
|
export class MarkdownExtension implements TurboWarpExtension {
|
|
48
|
+
private readonly fixedInputs = fixedInputRegistration(typeof Scratch === 'undefined' ? undefined : Scratch);
|
|
49
|
+
|
|
50
|
+
public dispose(): void {this.fixedInputs.dispose();}
|
|
51
|
+
|
|
47
52
|
public getInfo(): Record<string, unknown> {
|
|
53
|
+
this.fixedInputs.ensure(blockDefinitions.map(block => `${extensionConfig.id}_${block.opcode}`));
|
|
48
54
|
return {
|
|
49
55
|
id: extensionConfig.id,
|
|
50
56
|
name: Scratch.translate(definitions.extensionName),
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {parseFixedNumberInput} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
2
|
+
import type {FixedInputBinding, FixedInputEditorOptions, JsonValue, LiteralValue} from '@kubohiroya/turbowarp-extension-data-editor';
|
|
3
|
+
import {fixedInputBundle} from './fixed-input-schema.js';
|
|
4
|
+
const extensionId = "kubohiroyamarkdown";
|
|
5
|
+
const repository = "turbowarp-markdown";
|
|
6
|
+
interface Field {opcode: string; argument: string; control: 'number' | 'enum'; choices: readonly string[];
|
|
7
|
+
normalization: string; shape: string; maxBytes: boolean}
|
|
8
|
+
const fields: readonly Field[] = [
|
|
9
|
+
{
|
|
10
|
+
"opcode": "heading",
|
|
11
|
+
"argument": "LEVEL",
|
|
12
|
+
"control": "number",
|
|
13
|
+
"choices": [],
|
|
14
|
+
"normalization": "identity",
|
|
15
|
+
"shape": "math_number.NUM",
|
|
16
|
+
"maxBytes": false
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
function literalString(value: JsonValue | LiteralValue): string {
|
|
20
|
+
if (typeof value !== 'string') throw new TypeError('Expected a string literal.');
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
/** Legacy nonempty finite aliases are projections; opening never creates a write. */
|
|
24
|
+
export function existingFixedNumber(value: JsonValue | LiteralValue): number {
|
|
25
|
+
if ((typeof value !== 'string' && typeof value !== 'number') ||
|
|
26
|
+
(typeof value === 'string' && value.trim() === '')) throw new TypeError('Unavailable numeric projection.');
|
|
27
|
+
const number = Number(value);
|
|
28
|
+
if (!Number.isFinite(number)) throw new TypeError('Unavailable numeric projection.');
|
|
29
|
+
return number;
|
|
30
|
+
}
|
|
31
|
+
function normalizeChoice(field: Field, raw: string): string {
|
|
32
|
+
if (field.normalization === 'lowercase') return raw.toLowerCase();
|
|
33
|
+
if (field.normalization === 'method') return raw.trim().toUpperCase();
|
|
34
|
+
if (field.normalization === 'trim') return raw.trim();
|
|
35
|
+
if (field.normalization === 'parse-format') {
|
|
36
|
+
const lower = raw.trim().toLowerCase();
|
|
37
|
+
return lower === 'json' ? 'JSON' : lower === 'yaml' ? 'YAML' : lower === 'auto' ? 'auto' : raw;
|
|
38
|
+
}
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
function binding(field: Field): FixedInputBinding {
|
|
42
|
+
return {argument: field.argument, schemaBundle: fixedInputBundle(field.opcode, field.argument),
|
|
43
|
+
control: {kind: field.control, ...(field.control === 'enum' ? {choices: field.choices.map(value => ({value}))} : {})},
|
|
44
|
+
read(value) {return field.control === 'number' ? existingFixedNumber(value) : normalizeChoice(field, literalString(value));},
|
|
45
|
+
encode(value) {
|
|
46
|
+
if (field.control === 'number') {
|
|
47
|
+
const parsed = parseFixedNumberInput(value);
|
|
48
|
+
if (parsed.kind !== 'valid') throw new TypeError('Invalid new numeric input.');
|
|
49
|
+
return parsed.token;
|
|
50
|
+
}
|
|
51
|
+
const raw = literalString(value), normalized = normalizeChoice(field, raw);
|
|
52
|
+
if (!field.choices.includes(normalized)) throw new TypeError('Unsupported fixed choice.');
|
|
53
|
+
return field.shape === 'menu-shadow' || field.shape === 'direct-field-dropdown' ? normalized : raw;
|
|
54
|
+
},
|
|
55
|
+
validateCandidate(value) {
|
|
56
|
+
try {
|
|
57
|
+
if (field.control === 'number') {
|
|
58
|
+
const number = existingFixedNumber(value);
|
|
59
|
+
if (field.maxBytes && (!Number.isSafeInteger(Math.trunc(number)) || Math.trunc(number) < 1)) return [{message: 'Invalid named body size.'}];
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
return field.choices.includes(normalizeChoice(field, literalString(value))) ? [] : [{message: 'Unsupported fixed choice.'}];
|
|
63
|
+
} catch {return [{message: 'Invalid fixed input.'}];}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export const fixedInputEditors: readonly FixedInputEditorOptions[] = [...new Set(fields.map(f => f.opcode))].map(opcode => ({
|
|
68
|
+
apiVersion: 1, extensionId, editorId: `${opcode}-fixed-inputs`, opcodes: [`${extensionId}_${opcode}`],
|
|
69
|
+
contractId: `${repository}/${opcode}`, contractRevision: 'fixed-inputs-v1',
|
|
70
|
+
bindings: fields.filter(field => field.opcode === opcode).map(binding),
|
|
71
|
+
validationContext: () => ({consumerId: repository, nowMs: 0, settings: null})
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
interface OptionalFixedHost {
|
|
75
|
+
gui?: {blockEditors?: {apiVersion?: number; registerFixedInputEditor?: (definition: FixedInputEditorOptions) => () => void}};
|
|
76
|
+
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
77
|
+
}
|
|
78
|
+
/** Registration follows the advertised opcode membership and the optional host capability. */
|
|
79
|
+
export function fixedInputRegistration(scratch: unknown) {
|
|
80
|
+
const host = (scratch ?? {}) as OptionalFixedHost;
|
|
81
|
+
let active: unknown;
|
|
82
|
+
let membership = '';
|
|
83
|
+
const removers: (() => void)[] = [];
|
|
84
|
+
let stopped = false;
|
|
85
|
+
const clear = () => {
|
|
86
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', shutdown);
|
|
87
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
88
|
+
active = undefined;
|
|
89
|
+
membership = '';
|
|
90
|
+
};
|
|
91
|
+
const shutdown = () => {stopped = true; clear();};
|
|
92
|
+
return {
|
|
93
|
+
ensure(visibleOpcodes: readonly string[]) {
|
|
94
|
+
const api = host.gui?.blockEditors;
|
|
95
|
+
const definitions = fixedInputEditors.filter(definition => definition.opcodes.every(opcode => visibleOpcodes.includes(opcode)));
|
|
96
|
+
const key = definitions.map(definition => definition.editorId).join(',');
|
|
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;}
|
|
110
|
+
},
|
|
111
|
+
dispose: shutdown
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type {SchemaBundle, SchemaDocument} from '@kubohiroya/turbowarp-extension-data-editor/schema';
|
|
2
|
+
import document from '../schemas/block-editor-fixed-inputs.schema.json' with {type: 'json'};
|
|
3
|
+
const repository = "turbowarp-markdown";
|
|
4
|
+
/** The owner JSON document is canonical; this selects a primitive field fragment. */
|
|
5
|
+
export function fixedInputBundle(opcode: string, argument: string): SchemaBundle {
|
|
6
|
+
const pointer = `#/$defs/${opcode}/properties/${argument}`;
|
|
7
|
+
const source = {repository, path: 'schemas/block-editor-fixed-inputs.schema.json', symbol: pointer};
|
|
8
|
+
const blocks = document.$defs as Record<string, {properties: Record<string, SchemaDocument>}>;
|
|
9
|
+
return {identity: {ownerId: repository, contractId: opcode, revision: 'fixed-inputs-v1', variantId: argument},
|
|
10
|
+
dialect: '2020-12', root: {retrievalUri: document.$id, document: blocks[opcode]!.properties[argument]!,
|
|
11
|
+
artifact: {role: 'canonical-schema', source}},
|
|
12
|
+
resources: [],
|
|
13
|
+
provenance: {canonicalSources: [source, {repository, path: 'src/extension.ts', symbol: opcode}],
|
|
14
|
+
generatedFiles: [], referenceSchemas: [], generationSources: []}};
|
|
15
|
+
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://raw.githubusercontent.com/kubohiroya/turbowarp-markdown/main/schemas/extension-manifest.schema.json",
|
|
4
|
-
"title": "TurboWarp Extension API Manifest",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"additionalProperties": false,
|
|
7
|
-
"required": ["formatVersion", "id", "blocks", "menus"],
|
|
8
|
-
"properties": {
|
|
9
|
-
"formatVersion": {"const": 1},
|
|
10
|
-
"id": {"type": "string", "pattern": "^[a-z0-9]+$"},
|
|
11
|
-
"blocks": {
|
|
12
|
-
"type": "array",
|
|
13
|
-
"items": {
|
|
14
|
-
"type": "object",
|
|
15
|
-
"additionalProperties": false,
|
|
16
|
-
"required": ["opcode", "blockType", "arguments"],
|
|
17
|
-
"properties": {
|
|
18
|
-
"opcode": {"type": "string", "minLength": 1},
|
|
19
|
-
"blockType": {"type": "string", "minLength": 1},
|
|
20
|
-
"arguments": {
|
|
21
|
-
"type": "array",
|
|
22
|
-
"items": {
|
|
23
|
-
"type": "object",
|
|
24
|
-
"additionalProperties": false,
|
|
25
|
-
"required": ["id", "type"],
|
|
26
|
-
"properties": {
|
|
27
|
-
"id": {"type": "string", "minLength": 1},
|
|
28
|
-
"type": {"type": "string", "minLength": 1},
|
|
29
|
-
"menu": {"type": "string", "minLength": 1}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"menus": {
|
|
37
|
-
"type": "array",
|
|
38
|
-
"items": {
|
|
39
|
-
"type": "object",
|
|
40
|
-
"additionalProperties": false,
|
|
41
|
-
"required": ["id", "acceptReporters"],
|
|
42
|
-
"properties": {
|
|
43
|
-
"id": {"type": "string", "minLength": 1},
|
|
44
|
-
"acceptReporters": {"type": "boolean"}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import type {Plugin} from 'vite';
|
|
2
|
-
|
|
3
|
-
export const EXTENSION_MANIFEST_FORMAT_VERSION = 1 as const;
|
|
4
|
-
|
|
5
|
-
export interface ExtensionManifestArgument {
|
|
6
|
-
id: string;
|
|
7
|
-
type: string;
|
|
8
|
-
menu?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ExtensionManifestBlock {
|
|
12
|
-
opcode: string;
|
|
13
|
-
blockType: string;
|
|
14
|
-
arguments: ExtensionManifestArgument[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ExtensionManifestMenu {
|
|
18
|
-
id: string;
|
|
19
|
-
acceptReporters: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ExtensionManifest {
|
|
23
|
-
formatVersion: typeof EXTENSION_MANIFEST_FORMAT_VERSION;
|
|
24
|
-
id: string;
|
|
25
|
-
blocks: ExtensionManifestBlock[];
|
|
26
|
-
menus: ExtensionManifestMenu[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface ExtensionManifestPluginOptions {
|
|
30
|
-
id: string;
|
|
31
|
-
definitions: unknown;
|
|
32
|
-
fileName?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function createExtensionManifest(id: string, definitions: unknown): ExtensionManifest {
|
|
36
|
-
if (!/^[a-z0-9]+$/.test(id)) {
|
|
37
|
-
throw new TypeError('Extension manifest ID must contain only lowercase letters and numbers.');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const source = requireRecord(definitions, 'Block definitions');
|
|
41
|
-
const sourceBlocks = source.blocks;
|
|
42
|
-
if (!Array.isArray(sourceBlocks)) {
|
|
43
|
-
throw new TypeError('Block definitions must contain a blocks array.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const menus = normalizeMenus(source.menus);
|
|
47
|
-
const menuIds = new Set(menus.map((menu) => menu.id));
|
|
48
|
-
const seenOpcodes = new Set<string>();
|
|
49
|
-
const blocks = sourceBlocks.map((block, index) => {
|
|
50
|
-
const normalized = normalizeBlock(block, index, menuIds);
|
|
51
|
-
if (seenOpcodes.has(normalized.opcode)) {
|
|
52
|
-
throw new TypeError(`Duplicate block opcode: ${normalized.opcode}`);
|
|
53
|
-
}
|
|
54
|
-
seenOpcodes.add(normalized.opcode);
|
|
55
|
-
return normalized;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
formatVersion: EXTENSION_MANIFEST_FORMAT_VERSION,
|
|
60
|
-
id,
|
|
61
|
-
blocks: blocks.sort((left, right) => compareIds(left.opcode, right.opcode)),
|
|
62
|
-
menus
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function serializeExtensionManifest(id: string, definitions: unknown): string {
|
|
67
|
-
return `${JSON.stringify(createExtensionManifest(id, definitions), null, 2)}\n`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function extensionManifestPlugin(options: ExtensionManifestPluginOptions): Plugin {
|
|
71
|
-
return {
|
|
72
|
-
name: 'extension-api-manifest',
|
|
73
|
-
apply: 'build',
|
|
74
|
-
enforce: 'post',
|
|
75
|
-
generateBundle() {
|
|
76
|
-
this.emitFile({
|
|
77
|
-
type: 'asset',
|
|
78
|
-
fileName: options.fileName ?? 'extension-manifest.json',
|
|
79
|
-
source: serializeExtensionManifest(options.id, options.definitions)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function normalizeBlock(
|
|
86
|
-
value: unknown,
|
|
87
|
-
index: number,
|
|
88
|
-
menuIds: ReadonlySet<string>
|
|
89
|
-
): ExtensionManifestBlock {
|
|
90
|
-
const block = requireRecord(value, `Block at index ${index}`);
|
|
91
|
-
const opcode = requireNonEmptyString(block.opcode, `Block at index ${index} opcode`);
|
|
92
|
-
const blockType = requireNonEmptyString(block.blockType, `Block ${opcode} blockType`);
|
|
93
|
-
const sourceArguments = block.arguments ?? {};
|
|
94
|
-
const argumentRecord = requireRecord(sourceArguments, `Block ${opcode} arguments`);
|
|
95
|
-
const argumentsList = Object.entries(argumentRecord).map(([argumentId, argument]) => {
|
|
96
|
-
requireNonEmptyString(argumentId, `Block ${opcode} argument ID`);
|
|
97
|
-
const definition = requireRecord(argument, `Block ${opcode} argument ${argumentId}`);
|
|
98
|
-
const type = requireNonEmptyString(
|
|
99
|
-
definition.type,
|
|
100
|
-
`Block ${opcode} argument ${argumentId} type`
|
|
101
|
-
);
|
|
102
|
-
const menu = definition.menu;
|
|
103
|
-
if (menu !== undefined && (typeof menu !== 'string' || !menuIds.has(menu))) {
|
|
104
|
-
throw new TypeError(`Block ${opcode} argument ${argumentId} references unknown menu: ${menu}`);
|
|
105
|
-
}
|
|
106
|
-
return menu === undefined ? {id: argumentId, type} : {id: argumentId, type, menu};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
opcode,
|
|
111
|
-
blockType,
|
|
112
|
-
arguments: argumentsList.sort((left, right) => compareIds(left.id, right.id))
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function normalizeMenus(value: unknown): ExtensionManifestMenu[] {
|
|
117
|
-
const menuRecord = requireRecord(value ?? {}, 'Block definition menus');
|
|
118
|
-
return Object.entries(menuRecord)
|
|
119
|
-
.map(([id, menu]) => {
|
|
120
|
-
requireNonEmptyString(id, 'Menu ID');
|
|
121
|
-
const definition = requireRecord(menu, `Menu ${id}`);
|
|
122
|
-
const acceptReporters = definition.acceptReporters ?? false;
|
|
123
|
-
if (typeof acceptReporters !== 'boolean') {
|
|
124
|
-
throw new TypeError(`Menu ${id} acceptReporters must be a boolean.`);
|
|
125
|
-
}
|
|
126
|
-
return {id, acceptReporters};
|
|
127
|
-
})
|
|
128
|
-
.sort((left, right) => compareIds(left.id, right.id));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
|
132
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
133
|
-
throw new TypeError(`${label} must be an object.`);
|
|
134
|
-
}
|
|
135
|
-
return value as Record<string, unknown>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function requireNonEmptyString(value: unknown, label: string): string {
|
|
139
|
-
if (typeof value !== 'string' || value.length === 0) {
|
|
140
|
-
throw new TypeError(`${label} must be a non-empty string.`);
|
|
141
|
-
}
|
|
142
|
-
return value;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function compareIds(left: string, right: string): number {
|
|
146
|
-
if (left < right) return -1;
|
|
147
|
-
if (left > right) return 1;
|
|
148
|
-
return 0;
|
|
149
|
-
}
|