From 3458719048dc6e31931839aa351fb8b8a36e1c5a Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Tue, 23 Jun 2026 20:56:06 +0200 Subject: [PATCH 1/3] Added data-- to the plate node --- packages/helpers/src/styleFields.test.ts | 31 +++++++++++++++++++ packages/helpers/src/styleFields.ts | 9 +++--- .../editor/plugins/block-width-plugin.test.ts | 6 ++++ .../editor/plugins/style-fields-plugin.ts | 17 ++++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/helpers/src/styleFields.test.ts b/packages/helpers/src/styleFields.test.ts index a74a4deb3..802024f42 100644 --- a/packages/helpers/src/styleFields.test.ts +++ b/packages/helpers/src/styleFields.test.ts @@ -38,6 +38,19 @@ const resolveDefinitions = vi.fn((fieldName: string) => { ]; } + if (fieldName === 'size') { + return [ + { + name: 's', + label: 'Small', + }, + { + name: 'm', + label: 'Medium', + }, + ]; + } + return []; }); @@ -104,6 +117,24 @@ describe('style fields helpers', () => { }); }); + it('returns semantic values even when a definition has no style object', () => { + expect( + resolveStyleFields({ + data: { + '@type': 'image', + size: 'm', + }, + fieldConfigs: { + size: {}, + }, + resolveDefinitions, + }), + ).toEqual({ + style: {}, + values: { size: 'm' }, + }); + }); + it('applies configured defaults for missing values', () => { const data = { type: 'p', diff --git a/packages/helpers/src/styleFields.ts b/packages/helpers/src/styleFields.ts index 6343a3dc1..5feb686fd 100644 --- a/packages/helpers/src/styleFields.ts +++ b/packages/helpers/src/styleFields.ts @@ -274,12 +274,13 @@ export const resolveStyleFields = ({ if (!effectiveValue) return; - const definition = findStyleDefinitionByName(definitions, effectiveValue); + values[fieldName] = effectiveValue; - if (!definition?.style) return; + const definition = findStyleDefinitionByName(definitions, effectiveValue); - values[fieldName] = effectiveValue; - Object.assign(style, definition.style); + if (definition?.style) { + Object.assign(style, definition.style); + } }); return { style, values }; diff --git a/packages/plate/components/editor/plugins/block-width-plugin.test.ts b/packages/plate/components/editor/plugins/block-width-plugin.test.ts index 74a5e87f0..bd54542f3 100644 --- a/packages/plate/components/editor/plugins/block-width-plugin.test.ts +++ b/packages/plate/components/editor/plugins/block-width-plugin.test.ts @@ -183,6 +183,7 @@ describe('block width plugin', () => { }, }), ).toEqual({ + 'data-style-blockWidth': 'default', style: { color: 'red', '--block-width': 'var(--default-container-width)', @@ -232,6 +233,7 @@ describe('block width plugin', () => { }, }), ).toEqual({ + 'data-style-blockWidth': 'full', style: { color: 'red', '--block-width': '100%', @@ -281,6 +283,7 @@ describe('block width plugin', () => { }, }), ).toEqual({ + 'data-style-blockWidth': 'layout', style: { color: 'red', '--block-width': 'var(--layout-container-width)', @@ -669,6 +672,7 @@ describe('block width plugin', () => { }, }), ).toEqual({ + 'data-style-blockWidth': 'layout', style: { color: 'red', '--block-width': 'var(--layout-container-width)', @@ -734,6 +738,7 @@ describe('block width plugin', () => { }, }), ).toEqual({ + 'data-style-blockWidth': 'default', style: { position: 'relative', '--block-width': 'var(--default-container-width)', @@ -1475,6 +1480,7 @@ describe('block width plugin', () => { props: { style: {} }, } as any), ).toEqual({ + 'data-style-theme': 'sand', style: { '--theme-color': 'wheat', }, diff --git a/packages/plate/components/editor/plugins/style-fields-plugin.ts b/packages/plate/components/editor/plugins/style-fields-plugin.ts index ed38360c8..a96dfadb3 100644 --- a/packages/plate/components/editor/plugins/style-fields-plugin.ts +++ b/packages/plate/components/editor/plugins/style-fields-plugin.ts @@ -30,6 +30,14 @@ type ValueElement = Record & { children?: unknown[]; }; +const toStyleFieldDataAttributes = (values: Record) => + Object.fromEntries( + Object.entries(values).map(([fieldName, value]) => [ + `data-style-${fieldName}`, + value, + ]), + ); + const isRecord = (value: unknown): value is Record => !!value && typeof value === 'object' && !Array.isArray(value); @@ -231,17 +239,22 @@ export const BaseStyleFieldsPlugin = createSlatePlugin({ return props; } - const { style } = resolveStyleFields({ + const { style, values } = resolveStyleFields({ data: element as Record, fieldConfigs: getElementStyleFieldConfigs(element), container: undefined, resolveDefinitions: getStyleFieldDefinitionsFromRegistry, }); - if (!Object.keys(style).length) return props; + const dataAttributes = toStyleFieldDataAttributes(values); + + if (!Object.keys(style).length && !Object.keys(dataAttributes).length) { + return props; + } return { ...props, + ...dataAttributes, style: { ...(props.style ?? {}), ...style, From 0310f2de08047978b783cb6a4b51defc1a9d88fb Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Tue, 23 Jun 2026 20:58:42 +0200 Subject: [PATCH 2/3] Add towncrier news for style field updates --- packages/helpers/news/+style-field-values.bugfix | 1 + packages/plate/news/+style-field-data-attrs.feature | 1 + 2 files changed, 2 insertions(+) create mode 100644 packages/helpers/news/+style-field-values.bugfix create mode 100644 packages/plate/news/+style-field-data-attrs.feature diff --git a/packages/helpers/news/+style-field-values.bugfix b/packages/helpers/news/+style-field-values.bugfix new file mode 100644 index 000000000..488d394a1 --- /dev/null +++ b/packages/helpers/news/+style-field-values.bugfix @@ -0,0 +1 @@ +Preserved resolved style field values even when the selected definition does not contribute CSS styles. @sneridagh diff --git a/packages/plate/news/+style-field-data-attrs.feature b/packages/plate/news/+style-field-data-attrs.feature new file mode 100644 index 000000000..9584e7418 --- /dev/null +++ b/packages/plate/news/+style-field-data-attrs.feature @@ -0,0 +1 @@ +Added `data-style-*` attributes for resolved style field values in the Somersault-based editor element props. @sneridagh From 1196f02dced1ec9c8f52b36811a8495ce3249edb Mon Sep 17 00:00:00 2001 From: Victor Fernandez de Alba Date: Tue, 23 Jun 2026 21:11:46 +0200 Subject: [PATCH 3/3] Fix cookieplone --- .github/workflows/cookieplone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cookieplone.yml b/.github/workflows/cookieplone.yml index c7cdee7d5..0899c7a92 100644 --- a/.github/workflows/cookieplone.yml +++ b/.github/workflows/cookieplone.yml @@ -32,7 +32,7 @@ jobs: - name: Generate Cookieplone-based frontend addon run: | - uvx cookieplone@2.0.0b1 aurora_addon --no-input + uvx --prerelease allow cookieplone aurora_addon --no-input - name: Install generated package working-directory: plone-aurora-add-on