-
Notifications
You must be signed in to change notification settings - Fork 202
feat: control container option #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,7 @@ export class FormeoEditor { | |
|
|
||
| const { actions, events, debug, config, editorContainer, ...opts } = mergedOptions | ||
| if (editorContainer) { | ||
| this.editorContainer = | ||
| typeof editorContainer === 'string' ? document.querySelector(editorContainer) : editorContainer | ||
| this.editorContainer = dom.resolveContainer(editorContainer) || null | ||
| } | ||
| this.opts = opts | ||
| dom.setOptions = opts | ||
|
|
@@ -317,7 +316,10 @@ export class FormeoEditor { | |
| this.editor = dom.create(elemConfig) | ||
|
|
||
| const controlsContainer = this.controls.container || this.editor | ||
| controlsContainer.appendChild(this.controls.dom) | ||
| if (controlsContainer) { | ||
| dom.empty(controlsContainer) | ||
| controlsContainer.appendChild(this.controls.dom) | ||
| } | ||
|
Comment on lines
318
to
+322
|
||
|
|
||
| if (this.editorContainer) { | ||
| dom.empty(this.editorContainer) | ||
|
Comment on lines
+321
to
325
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolveContainercurrently returns any non-string value as-is and doesn’t guarddocument.querySelectoragainst invalid selector strings (which throw). This can lead to hard-to-debug runtime errors later (e.g., calling DOM APIs on a non-element) or immediate initialization failures for malformed selectors. Consider validating withisDOMElementand returningnull(or throwing a clear error) for unsupported types, and wrappingquerySelectorin a try/catch to returnnullfor invalid selectors.