Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions docs/issue-99-workspaces-drawer-plan.md

This file was deleted.

46 changes: 0 additions & 46 deletions docs/pr-drawer-workspace-context-separation-plan.md

This file was deleted.

51 changes: 0 additions & 51 deletions docs/render-pipeline-multitab-spec-plan.md

This file was deleted.

32 changes: 32 additions & 0 deletions playwright/layout-panels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
expectCollapseButtonState,
expectPreviewHasRenderedContent,
getCollapseButton,
getPreviewFrame,
getToolsButton,
waitForInitialRender,
} from './helpers/app-test-helpers.js'
Expand Down Expand Up @@ -61,6 +62,37 @@ test('dark theme defaults preview background to editor background', async ({ pag
expect(toRgbChannels(colors.preview)).toEqual(toRgbChannels(colors.editor))
})

test('changing preview background keeps applied preview styles', async ({ page }) => {
await waitForInitialRender(page)

Comment thread
knightedcodemonkey marked this conversation as resolved.
const previewFrameRoot = getPreviewFrame(page).locator('html')

await expect(previewFrameRoot).toHaveCount(1)
const hasComponentStylesBefore = await previewFrameRoot.evaluate(() => {
const styleElement = document.getElementById('knighted-preview-styles')
if (!(styleElement instanceof HTMLStyleElement)) {
return false
}

return styleElement.textContent?.includes('.counter-button') ?? false
})
expect(hasComponentStylesBefore).toBe(true)

await page.getByLabel('Background').fill('#b1aaaa')

const hasComponentStylesAfter = await previewFrameRoot.evaluate(() => {
const styleElement = document.getElementById('knighted-preview-styles')
if (!(styleElement instanceof HTMLStyleElement)) {
return false
}

return styleElement.textContent?.includes('.counter-button') ?? false
})
expect(hasComponentStylesAfter).toBe(true)

await expect(previewFrameRoot).toHaveCSS('background-color', 'rgb(177, 170, 170)')
})

test('fixed layout keeps preview panel height within editor stack height', async ({
page,
}) => {
Expand Down
41 changes: 34 additions & 7 deletions src/modules/preview-runtime/iframe-preview-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const createIframeShellDocument = ({ channelId, parentOrigin, importMap }) => {
entrySpecifier: '',
reactRoot: null,
renderedNodes: [],
visualConfig: {
cssText: '',
hostPadding: '',
backgroundColor: '',
},
}

const __knightedRuntimeErrorFingerprints = new Set()
Expand Down Expand Up @@ -110,24 +115,37 @@ const createIframeShellDocument = ({ channelId, parentOrigin, importMap }) => {
}

const __knightedApplyVisualConfig = ({ cssText = '', hostPadding = '', backgroundColor = '' }) => {
__knightedState.visualConfig = {
cssText: typeof cssText === 'string' ? cssText : '',
hostPadding: typeof hostPadding === 'string' ? hostPadding : '',
backgroundColor: typeof backgroundColor === 'string' ? backgroundColor : '',
}

let styleElement = document.getElementById('knighted-preview-styles')
if (!(styleElement instanceof HTMLStyleElement)) {
styleElement = document.createElement('style')
styleElement.id = 'knighted-preview-styles'
document.head.append(styleElement)
}

styleElement.textContent = __knightedToBaseStyles(hostPadding) + '\\n' + String(cssText)
styleElement.textContent =
__knightedToBaseStyles(__knightedState.visualConfig.hostPadding) +
'\\n' +
String(__knightedState.visualConfig.cssText)

if (typeof hostPadding === 'string' && hostPadding.trim().length > 0) {
document.documentElement.style.setProperty('--preview-host-padding', hostPadding.trim())
if (__knightedState.visualConfig.hostPadding.trim().length > 0) {
document.documentElement.style.setProperty(
'--preview-host-padding',
__knightedState.visualConfig.hostPadding.trim(),
)
} else {
document.documentElement.style.removeProperty('--preview-host-padding')
}

if (typeof backgroundColor === 'string' && backgroundColor.length > 0) {
document.documentElement.style.backgroundColor = backgroundColor
document.body.style.backgroundColor = backgroundColor
if (__knightedState.visualConfig.backgroundColor.length > 0) {
document.documentElement.style.backgroundColor =
__knightedState.visualConfig.backgroundColor
document.body.style.backgroundColor = __knightedState.visualConfig.backgroundColor
return
}

Expand Down Expand Up @@ -285,7 +303,16 @@ const createIframeShellDocument = ({ channelId, parentOrigin, importMap }) => {
const data = event.data

if (data.type === __knightedMessageTypes.configPatch) {
__knightedApplyVisualConfig(data)
const patch =
data && typeof data.payload === 'object' && data.payload !== null
? data.payload
: data && typeof data === 'object'
? data
: {}
__knightedApplyVisualConfig({
...__knightedState.visualConfig,
...patch,
})
return
}

Expand Down
Loading