From 896f2f3a7258bc168ffccc3b3ef3165de9d9d770 Mon Sep 17 00:00:00 2001
From: Julian Reichle <67505990+jurei733@users.noreply.github.com>
Date: Tue, 27 Oct 2026 18:14:43 +0100
Subject: [PATCH 1/2] Preserve ordered-list starts and styles when importing
HTML
---
e2e/schemer-embedded.spec.js | 34 ++++++++
.../extensions/ordered-list.spec.ts | 86 +++++++++++++++++++
.../extensions/ordered-list.ts | 9 +-
3 files changed, 128 insertions(+), 1 deletion(-)
diff --git a/e2e/schemer-embedded.spec.js b/e2e/schemer-embedded.spec.js
index 25d6da9..dc5c3da 100644
--- a/e2e/schemer-embedded.spec.js
+++ b/e2e/schemer-embedded.spec.js
@@ -1361,6 +1361,40 @@ test('embedded Schemer destroys rich text editors after save, cancel and Escape'
}
});
+test('embedded Schemer preserves pasted list numbering and styles after save and reopen', async ({ page }) => {
+ const frame = await loadEmbeddedSchemer(page);
+ await expect(frame.locator('.var-list-entry')).toHaveCount(2);
+ await frame.locator('var-coding .manual-instruction button').first().click();
+ const editor = frame.locator('.ProseMirror');
+ await editor.focus();
+ await editor.evaluate(element => {
+ const clipboardData = new DataTransfer();
+ clipboardData.setData('text/html', '
- Third'
+ + '
- Nested
- Fourth
');
+ clipboardData.setData('text/plain', 'Third\nNested\nFourth');
+ element.dispatchEvent(new ClipboardEvent('paste', { clipboardData, bubbles: true, cancelable: true }));
+ });
+ await expect(editor.locator('ol').first()).toHaveAttribute('start', '3');
+ await expect(editor.locator('ol').nth(1)).toHaveAttribute('start', '4');
+ await frame.getByRole('button', { name: 'Speichern', exact: true }).click();
+ await expect(frame.getByRole('dialog')).toHaveCount(0);
+
+ const storedLists = await page.evaluate(() => {
+ const changed = window.received.filter(message => message.type === 'vosSchemeChangedNotification').at(-1);
+ const html = JSON.parse(changed.codingScheme).variableCodings[0].manualInstruction;
+ return Array.from(new DOMParser().parseFromString(html, 'text/html').querySelectorAll('ol'))
+ .map(list => ({ start: list.start, style: list.style.listStyleType }));
+ });
+ expect(storedLists).toEqual([{ start: 3, style: 'lower-latin' }, { start: 4, style: 'upper-roman' }]);
+
+ await frame.locator('var-coding .manual-instruction button').first().click();
+ await expect(editor.locator('ol').first()).toHaveAttribute('start', '3');
+ await expect(editor.locator('ol').nth(1)).toHaveAttribute('start', '4');
+ expect(await editor.locator('ol').evaluateAll(lists => lists.map(list => list.style.listStyleType)))
+ .toEqual(['lower-latin', 'upper-roman']);
+ await frame.getByRole('button', { name: 'Abbrechen', exact: true }).click();
+});
+
test('embedded Schemer saves rich text and an asynchronous image and discards cancelled edits', async ({ page }) => {
const frame = await loadEmbeddedSchemer(page);
await expect(frame.locator('.var-list-entry')).toHaveCount(2);
diff --git a/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.spec.ts b/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.spec.ts
index 181a7b8..bdcf2c1 100644
--- a/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.spec.ts
+++ b/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.spec.ts
@@ -23,4 +23,90 @@ describe('Instruction list paste compatibility', () => {
expect(editor.getHTML()).not.toContain(' {
+ const content = editor.getJSON();
+ const html = editor.getHTML();
+ editor.commands.setContent(html, { emitUpdate: false });
+ expect(editor.getHTML()).toBe(html);
+ editor.commands.setContent(content, { emitUpdate: false });
+ expect(editor.getJSON()).toEqual(content);
+ expect(editor.getHTML()).toBe(html);
+ };
+
+ [3, 0, -2].forEach(start => {
+ it(`preserves the HTML clipboard numbering start ${start}`, () => {
+ expect(editor.view.pasteHTML(`- First
- Second
`)).toBeTrue();
+
+ expect(editor.view.dom.querySelector('ol')?.start).toBe(start);
+ expectStableRoundtrips();
+ });
+ });
+
+ [
+ ['a', 'lower-latin'], ['A', 'upper-latin'], ['i', 'lower-roman'], ['I', 'upper-roman'], ['1', 'decimal']
+ ].forEach(([type, listStyle]) => {
+ it(`preserves HTML clipboard type ${type} and maps it to the editor list style`, () => {
+ editor.view.pasteHTML(`- First
- Second
`);
+
+ expect(editor.view.dom.querySelector('ol')?.start).toBe(3);
+ expect(editor.getJSON().content?.[0].attrs?.['listStyle']).toBe(listStyle);
+ expect(editor.view.dom.querySelector('ol')?.style.listStyleType).toBe(listStyle);
+ expectStableRoundtrips();
+ });
+ });
+
+ it('keeps CSS list styles and font sizes ahead of a conflicting HTML type', () => {
+ editor.view.pasteHTML('' +
+ '- First
- Second
');
+
+ expect(editor.getJSON().content?.[0].attrs).toEqual(jasmine.objectContaining({
+ start: 3, listStyle: 'upper-roman', fontSize: '18px'
+ }));
+ expectStableRoundtrips();
+ });
+
+ it('imports the list style from a first list item, as supplied by Google Docs', () => {
+ editor.view.pasteHTML('- First
- Second
');
+
+ expect(editor.getJSON().content?.[0].attrs).toEqual(jasmine.objectContaining({
+ start: 3, listStyle: 'lower-alpha'
+ }));
+ expectStableRoundtrips();
+ });
+
+ it('preserves independent starts and styles in nested lists', () => {
+ editor.view.pasteHTML('- Outer' +
+ '
- Inner
- Next
');
+
+ const lists = Array.from(editor.view.dom.querySelectorAll('ol'));
+ expect(lists.map(list => list.start)).toEqual([3, 4]);
+ expect(lists.map(list => list.style.listStyleType)).toEqual(['lower-latin', 'upper-roman']);
+ expectStableRoundtrips();
+ });
+
+ it('keeps a user-selected custom style when a typed list is saved and reopened', () => {
+ editor.view.pasteHTML('- First
- Second
');
+ editor.commands.selectAll();
+ editor.commands.setOrderedListStyle('lower-greek');
+
+ expect(editor.view.dom.querySelector('ol')?.style.listStyleType).toBe('lower-greek');
+ expectStableRoundtrips();
+ expect(editor.view.dom.querySelector('ol')?.start).toBe(3);
+ });
+
+ it('reopens legacy JSON lists without changing their custom style', () => {
+ editor.commands.setContent({
+ type: 'doc',
+ content: [{
+ type: 'orderedList',
+ attrs: { listStyle: 'lower-greek', fontSize: '18px' },
+ content: [{ type: 'listItem', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Legacy' }] }] }]
+ }]
+ });
+
+ expect(editor.view.dom.querySelector('ol')?.start).toBe(1);
+ expect(editor.view.dom.querySelector('ol')?.style.listStyleType).toBe('lower-greek');
+ expectStableRoundtrips();
+ });
});
diff --git a/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.ts b/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.ts
index fd2f5f2..9b3b046 100644
--- a/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.ts
+++ b/projects/ngx-coding-components/src/lib/rich-text-editor/extensions/ordered-list.ts
@@ -1,5 +1,9 @@
import { OrderedList } from '@tiptap/extension-ordered-list';
+const listStyleByType = new Map([
+ ['1', 'decimal'], ['a', 'lower-latin'], ['A', 'upper-latin'], ['i', 'lower-roman'], ['I', 'upper-roman']
+]);
+
declare module '@tiptap/core' {
interface Commands {
orderedListExtension: {
@@ -12,9 +16,12 @@ declare module '@tiptap/core' {
export const OrderedListExtension = OrderedList.extend({
addAttributes() {
return {
+ ...this.parent?.(),
listStyle: {
default: 'upper-roman',
- parseHTML: element => element.style.listStyleType,
+ parseHTML: element => element.style.listStyleType ||
+ element.querySelector('li')?.style.listStyleType ||
+ listStyleByType.get(element.getAttribute('type') || '') || '',
renderHTML: attributes => ({ style: `list-style: ${attributes['listStyle']}` })
},
fontSize: {
From f982bcf6bff24e2097cb4a9f83a726ba60e69bb0 Mon Sep 17 00:00:00 2001
From: Julian Reichle <67505990+jurei733@users.noreply.github.com>
Date: Tue, 27 Oct 2026 18:14:43 +0100
Subject: [PATCH 2/2] Keep public codebook export declarations portable
---
.../codebook-export.component.ts | 2 +-
scripts/codebook-type-resolution.test.mjs | 77 +++++++++++++++----
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/projects/ngx-coding-components/codebook-export/codebook-export.component.ts b/projects/ngx-coding-components/codebook-export/codebook-export.component.ts
index cf3538e..ec1394e 100644
--- a/projects/ngx-coding-components/codebook-export/codebook-export.component.ts
+++ b/projects/ngx-coding-components/codebook-export/codebook-export.component.ts
@@ -56,7 +56,7 @@ export class CodebookExportComponent implements OnChanges, AfterViewInit {
@Output() cancel = new EventEmitter();
@ViewChild(MatSort) sort!: MatSort;
- dataSource = new MatTableDataSource([]);
+ dataSource: MatTableDataSource = new MatTableDataSource([]);
columns = ['select', 'key', 'name', 'group'];
selection: number[] = [];
filter = '';
diff --git a/scripts/codebook-type-resolution.test.mjs b/scripts/codebook-type-resolution.test.mjs
index d254e7d..64283bc 100644
--- a/scripts/codebook-type-resolution.test.mjs
+++ b/scripts/codebook-type-resolution.test.mjs
@@ -1,10 +1,36 @@
import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
import { test } from 'node:test';
-import { mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises';
+import { mkdtemp, mkdir, readFile, rm, symlink, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import ts from 'typescript';
+const expectTypeChecks = (source, consumer, resolution) => {
+ const program = ts.createProgram([source], {
+ noEmit: true,
+ strict: true,
+ skipLibCheck: false,
+ target: ts.ScriptTarget.ES2022,
+ module: resolution === 'NodeNext' ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext,
+ moduleResolution: ts.ModuleResolutionKind[resolution]
+ });
+ const errors = ts.getPreEmitDiagnostics(program)
+ .filter(diagnostic => diagnostic.category === ts.DiagnosticCategory.Error);
+ assert.equal(errors.length, 0, ts.formatDiagnosticsWithColorAndContext(errors, {
+ getCanonicalFileName: file => file,
+ getCurrentDirectory: () => consumer,
+ getNewLine: () => '\n'
+ }));
+};
+
+const npm = (args, cwd) => {
+ const result = spawnSync('npm', args, { cwd, encoding: 'utf8', timeout: 120000 });
+ assert.equal(result.error, undefined, result.error?.message);
+ assert.equal(result.status, 0, result.stderr || result.stdout);
+ return result.stdout;
+};
+
for (const resolution of ['Bundler', 'NodeNext']) {
test(`public codebook types support ${resolution} consumers`, async () => {
const consumer = await mkdtemp(join(tmpdir(), 'codebook-type-consumer-'));
@@ -27,22 +53,43 @@ for (const resolution of ['Bundler', 'NodeNext']) {
const output: Promise = CodebookGenerator.generateCodebook(units, options, []);
void output;
`);
- const program = ts.createProgram([source], {
- noEmit: true,
- strict: true,
- target: ts.ScriptTarget.ES2022,
- module: resolution === 'NodeNext' ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext,
- moduleResolution: ts.ModuleResolutionKind[resolution]
- });
- const errors = ts.getPreEmitDiagnostics(program)
- .filter(diagnostic => diagnostic.category === ts.DiagnosticCategory.Error);
- assert.equal(errors.length, 0, ts.formatDiagnosticsWithColorAndContext(errors, {
- getCanonicalFileName: file => file,
- getCurrentDirectory: () => consumer,
- getNewLine: () => '\n'
- }));
+ expectTypeChecks(source, consumer, resolution);
} finally {
await rm(consumer, { recursive: true, force: true });
}
});
}
+
+test('packed public Angular entry points support strict Bundler consumers', async () => {
+ const consumer = await mkdtemp(join(tmpdir(), 'packed-ui-type-consumer-'));
+ try {
+ const library = JSON.parse(await readFile('dist/ngx-coding-components/package.json', 'utf8'));
+ const lock = JSON.parse(await readFile('package-lock.json', 'utf8'));
+ const [tarball] = JSON.parse(npm(['pack', '--ignore-scripts', '--json', '--pack-destination', consumer],
+ resolve('dist/ngx-coding-components')));
+ // Use the host versions tested by this checkout, including one consistent Angular major.
+ const peers = Object.fromEntries(Object.keys(library.peerDependencies).map(name => (
+ [name, lock.packages[`node_modules/${name}`].version]
+ )));
+ await writeFile(join(consumer, 'package.json'), JSON.stringify({
+ name: 'packed-ui-type-consumer', private: true, type: 'module',
+ dependencies: { ...peers, [library.name]: `file:${join(consumer, tarball.filename)}` }
+ }));
+ npm(['install', '--ignore-scripts', '--no-audit', '--no-fund'], consumer);
+ const source = join(consumer, 'consumer.mts');
+ await writeFile(source, `
+ import { SchemerComponent } from '@iqb/ngx-coding-components';
+ import { CodebookExportComponent } from '@iqb/ngx-coding-components/codebook-export';
+ import { CodebookGenerator } from '@iqb/ngx-coding-components/codebook-generator';
+ import type { UnitSelectionItem } from '@iqb/ngx-coding-components/codebook-models';
+ import * as translations from '@iqb/ngx-coding-components/translations';
+ import type { MatTableDataSource } from '@angular/material/table';
+ const exportForm = null! as CodebookExportComponent;
+ const dataSource: MatTableDataSource = exportForm.dataSource;
+ void [SchemerComponent, CodebookGenerator, translations, dataSource];
+ `);
+ expectTypeChecks(source, consumer, 'Bundler');
+ } finally {
+ await rm(consumer, { recursive: true, force: true });
+ }
+});