WebTaleScriptから動的に、HTMLエレメントの追加 - #220
Merged
Merged
Conversation
git commit -m "feat(parser): add/removeタグの検証定義を追加"
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
WebTaleScript(WTS)から動的に任意のHTML要素を追加・削除できるようにし、クリックイベント(<onclick>)からシナリオ割り込み実行を可能にするための変更です。Core のコマンド拡張と、WTSノード→DOM変換ロジックの追加を通じて、ゲーム画面上のDOM操作をサポートしています。
Changes:
<add>/<remove>コマンドを Core に追加し、DOM要素の追加・削除・表示切替を管理するDomElementHandlerを導入<add>配下のノードを DOM に再帰変換するconvertNodesToDomを新規追加し、<onclick>によるクリック→シナリオ挿入を実装Drawer.createDecoratedElementを static 化し、既存UI側の呼び出しも更新
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/nodeToDomConverter.ts | WTSノード配列をDOMに変換し、<onclick> をクリックイベントとして解釈 |
| src/core/domElementHandler.ts | <add>/<remove> によるDOM要素の生成・管理・表示切替を提供 |
| src/core/index.js | Core のコマンドに add/remove を追加し、show/hide の dom モード対応を追加 |
| src/core/drawer.ts | createDecoratedElement を static に変更 |
| src/core/defaultUIHandler.ts | static 化に合わせて Drawer.createDecoratedElement 呼び出しへ更新 |
| parser/checker.js | add/remove/onclick の許可と属性定義を追加 |
| package.json | ビルド時コピーを shx 経由に変更し、依存を追加 |
| example/src/scene/dialog.scene | <add> と <onclick> の動作例を追加 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { generateStore } from '../utils/store' | ||
| import { EventBus } from '../utils/eventBus' | ||
| import { DefaultUIHandler } from './defaultUIHandler' | ||
| import { DomElementHandler } from './domElementHandler' |
Comment on lines
+69
to
+80
| // 5. type が KNOWN_ATTRIBUTES にない未知タグ -> HTML要素として処理 | ||
| const element = document.createElement(type); | ||
|
|
||
| // type/content 以外の属性を setAttribute で透過。 | ||
| // ただし属性名が on で始まるもの(onclick等の生JS属性)は透過せず console.warn を出して無視する | ||
| for (const [key, value] of Object.entries(attributes)) { | ||
| if (key.startsWith('on')) { | ||
| console.warn(`[nodeToDomConverter] Skipping prohibited attribute "${key}" on <${type}>`); | ||
| continue; | ||
| } | ||
| element.setAttribute(key, String(value)); | ||
| } |
Comment on lines
+61
to
+63
| // @ts-ignore: KNOWN_ATTRIBUTES is from a JS file | ||
| const isKnownType = type in KNOWN_ATTRIBUTES; | ||
|
|
Comment on lines
+85
to
+87
| if (element) { | ||
| element.style.display = line.show === false ? 'none' : 'block'; | ||
| } else { |
Comment on lines
+90
to
+92
| if (fallbackElement) { | ||
| fallbackElement.style.display = line.show === false ? 'none' : 'block'; | ||
| } else { |
Comment on lines
434
to
+442
| async hideHandler(line) { | ||
| if (line.mode === 'dom') { | ||
| this.domElementHandler.setVisibility({ | ||
| name: line.name, | ||
| show: false | ||
| }) | ||
| return | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.