Skip to content

feat: control container option#428

Merged
kevinchappell merged 5 commits into
mainfrom
feat/controls-container
May 16, 2026
Merged

feat: control container option#428
kevinchappell merged 5 commits into
mainfrom
feat/controls-container

Conversation

@kevinchappell
Copy link
Copy Markdown
Collaborator

activates the existing controls.container option. Controls will now be appended to the element defined in this option.

Copilot AI review requested due to automatic review settings January 30, 2026 20:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Activates the existing controls.container option so editor controls can be mounted into a user-specified DOM element/selector.

Changes:

  • Add controls.container to default editor options.
  • Introduce dom.resolveContainer() utility (with unit tests) to resolve selector strings to DOM elements.
  • Update editor/controls initialization to resolve and use the configured controls container during render.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/lib/js/editor.js Uses resolved containers and attempts to mount controls into controls.container during render.
src/lib/js/config.js Adds default controls.container: null configuration.
src/lib/js/components/controls/index.js Resolves controls.container via dom.resolveContainer() when applying options.
src/lib/js/common/dom.js Adds resolveContainer() helper for selector/element resolution.
src/lib/js/common/dom.test.js Adds unit test coverage for resolveContainer().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/js/editor.js
Comment on lines 319 to +322
const controlsContainer = this.controls.container || this.editor
controlsContainer.appendChild(this.controls.dom)
if (controlsContainer) {
dom.empty(controlsContainer)
controlsContainer.appendChild(this.controls.dom)
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dom.empty(controlsContainer) will clear the editor root when controls.container is not set (default null), because controlsContainer falls back to this.editor. That removes the stage DOM nodes you just created in elemConfig.content, so the rendered editor will only contain the controls. Instead of emptying unconditionally, only clear/replace when an external controls.container is configured (or remove/replace an existing .formeo-controls node) and leave this.editor content intact.

Copilot uses AI. Check for mistakes.
Comment thread src/lib/js/editor.js
Comment on lines +321 to 325
controlsContainer.appendChild(this.controls.dom)
}

if (this.editorContainer) {
dom.empty(this.editorContainer)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If controls.container resolves to the same element as editorContainer, controls are appended and then immediately removed when dom.empty(this.editorContainer) runs (and similarly if the controls container is inside editorContainer, it gets removed by the empty call). Consider handling the “shared container” case by clearing once and appending both controls + editor in the intended order, or documenting/enforcing that these containers must be distinct/dedicated.

Copilot uses AI. Check for mistakes.
Comment thread src/lib/js/common/dom.js
}

resolveContainer(container) {
return typeof container === 'string' ? document.querySelector(container) : container
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveContainer currently returns any non-string value as-is and doesn’t guard document.querySelector against 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 with isDOMElement and returning null (or throwing a clear error) for unsupported types, and wrapping querySelector in a try/catch to return null for invalid selectors.

Suggested change
return typeof container === 'string' ? document.querySelector(container) : container
if (typeof container === 'string') {
try {
return document.querySelector(container)
} catch (e) {
// Invalid selector string
return null
}
}
if (this.isDOMElement(container)) {
return container
}
return null

Copilot uses AI. Check for mistakes.
Comment thread src/lib/js/editor.js
Comment on lines 319 to +322
const controlsContainer = this.controls.container || this.editor
controlsContainer.appendChild(this.controls.dom)
if (controlsContainer) {
dom.empty(controlsContainer)
controlsContainer.appendChild(this.controls.dom)
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces/activates controls.container behavior, but there doesn’t appear to be any Playwright coverage asserting that controls render into a custom container (and continue to render correctly on re-render). Adding an e2e test that configures controls.container (and optionally the interaction with editorContainer) would help prevent regressions here.

Copilot uses AI. Check for mistakes.
@kevinchappell
Copy link
Copy Markdown
Collaborator Author

@copilot apply changes based on the comments in this thread

@kevinchappell kevinchappell force-pushed the feat/controls-container branch from 4bce39e to 157f3b1 Compare May 16, 2026 06:57
Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

@copilot apply changes based on the comments in this thread

Implemented in 8d88a8d (on top of 9050e02). I addressed the review thread items: fixed editor render behavior so default rendering no longer clears stage content, handled shared/nested controls.container + editorContainer cases safely, hardened dom.resolveContainer (invalid selector/type-safe), and added Playwright coverage for custom/shared controls container rendering and rerender behavior. Screenshot: /tmp/controls-container-ui.png.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdnjs.cloudflare.com
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-edgeupdater --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl -test --no-warnibash (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-edgeupdater --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl -test --no-warninode (dns block)
    • Triggering command: /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell /home/REDACTED/.cache/ms-playwright/chromium_headless_shell-1223/chrome-headless-shell-linux64/chrome-headless-shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-edgeupdater --disable-extensions --disable-features=AvoidUnnecessaryBeforeUnloadCheckSync,BoundaryEventDispatchTracksNodeRemoval,DestroyProfileOnBrowserClose,DialMediaRouteProvider,GlobalMediaControls,HttpsUpgrades,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Transl (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@kevinchappell kevinchappell force-pushed the feat/controls-container branch from 8d88a8d to 26b4466 Compare May 16, 2026 07:11
@kevinchappell kevinchappell merged commit 7314e52 into main May 16, 2026
2 of 3 checks passed
@kevinchappell kevinchappell deleted the feat/controls-container branch May 16, 2026 17:48
@kevinchappell
Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants