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
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,52 @@ describe('create.contentControl default sdtPr seeding', () => {
expect(dateEl?.elements?.some((el) => el.name === 'w:storeMappedDataAs')).toBe(true);
expect(dateEl?.elements?.some((el) => el.name === 'w:calendar')).toBe(true);
});

it('defaults newly-created controls without controlType to richText', () => {
const editor = makeSdtEditor();
const adapter = createContentControlsAdapter(editor);

const result = adapter.create({ kind: 'inline' }, { changeMode: 'direct' });
expect(result.success).toBe(true);

const insertInline = editor.commands!.insertStructuredContentInline as ReturnType<typeof vi.fn>;
const attrs = insertInline.mock.calls[0][0].attrs as Record<string, unknown>;
expect(attrs.controlType).toBe('richText');
expect(attrs.type).toBe('richText');
const sdtPr = attrs.sdtPr as { elements?: Array<{ name: string }> };
expect(sdtPr.elements?.some((el) => el.name === 'w:richText')).toBe(true);
});

it('seeds explicit richText controls with w:richText in sdtPr', () => {
const editor = makeSdtEditor();
const adapter = createContentControlsAdapter(editor);

const result = adapter.create({ kind: 'inline', controlType: 'richText' }, { changeMode: 'direct' });
expect(result.success).toBe(true);

const insertInline = editor.commands!.insertStructuredContentInline as ReturnType<typeof vi.fn>;
const attrs = insertInline.mock.calls[0][0].attrs as Record<string, unknown>;
expect(attrs.controlType).toBe('richText');
const sdtPr = attrs.sdtPr as { elements?: Array<{ name: string }> };
expect(sdtPr.elements?.some((el) => el.name === 'w:richText')).toBe(true);
});
});

describe('contentControls.wrap default classification', () => {
it('sets wrapper controlType to richText and seeds w:richText in sdtPr', () => {
const editor = makeSdtEditor();
const adapter = createContentControlsAdapter(editor);

adapter.wrap({ target: SDT_TARGET, kind: 'block' }, { changeMode: 'direct' });

const createFn = editor.schema.nodes.structuredContentBlock.create as ReturnType<typeof vi.fn>;
expect(createFn).toHaveBeenCalledTimes(1);
const [attrs] = createFn.mock.calls[0];
expect(attrs.controlType).toBe('richText');
expect(attrs.type).toBe('richText');
const sdtPr = attrs.sdtPr as { elements?: Array<{ name: string }> };
expect(sdtPr.elements?.some((el) => el.name === 'w:richText')).toBe(true);
});
});

describe('contentControls.setType default sdtPr seeding', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,18 @@ function wrapWrapper(
const nodeType = editor.schema.nodes[nodeTypeName];
if (!nodeType) return false;

// ECMA-376 §17.5.2.26: typeless sdtPr resolves to richText. Default here so
// the wrapper classifies the same in-session and after reimport.
const wrapperNode = nodeType.create(
{ id, tag: input.tag, alias: input.alias, lockMode: input.lockMode ?? 'unlocked' },
{
id,
tag: input.tag,
alias: input.alias,
lockMode: input.lockMode ?? 'unlocked',
controlType: 'richText',
type: 'richText',
sdtPr: buildDefaultSdtPr('richText'),
},
resolved.node,
);
const { tr } = editor.state;
Expand Down Expand Up @@ -1809,15 +1819,18 @@ function createWrapper(
}

return executeSdtMutation(editor, target, options, () => {
// ECMA-376 §17.5.2.26: typeless sdtPr resolves to richText. 'unknown' is for
// unsupported/unrecognized type children, not a default for new controls.
const controlType = input.controlType ?? 'richText';
const attrs: Record<string, unknown> = {
id,
tag: input.tag,
alias: input.alias,
lockMode: input.lockMode ?? 'unlocked',
controlType: input.controlType ?? 'unknown',
type: input.controlType ?? 'unknown',
controlType,
type: controlType,
};
const defaultSdtPr = buildDefaultSdtPr(input.controlType ?? 'unknown');
const defaultSdtPr = buildDefaultSdtPr(controlType);
const isDateCreate = input.controlType === 'date' && input.content == null;
const dateDefaults = isDateCreate ? buildDateControlDefaults() : null;
const sdtPrWithDateDefaults = dateDefaults ? applyDateDefaultsToSdtPr(defaultSdtPr, dateDefaults) : defaultSdtPr;
Expand Down
Loading