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
2 changes: 1 addition & 1 deletion apps/docs/document-api/reference/_generated-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,5 +604,5 @@
}
],
"marker": "{/* GENERATED FILE: DO NOT EDIT. Regenerate via `pnpm run docapi:sync`. */}",
"sourceHash": "b63b0a6c2c6b7ace1058a491081caef624f258010a0c36139755f1a3a9cd34b6"
"sourceHash": "d1b97baae61be333b72dc1211180bc02dd451e14a3767328d56929bf77a10132"
}
2 changes: 1 addition & 1 deletion apps/docs/document-api/reference/format/caps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Set or clear the `caps` inline run property on the target text range.
- API member path: `editor.doc.format.caps(...)`
- Mutates document: `yes`
- Idempotency: `conditional`
- Supports tracked mode: `no`
- Supports tracked mode: `yes`
- Supports dry run: `yes`
- Deterministic target resolution: `yes`

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/document-api/reference/format/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Canonical formatting mutation with directive semantics ('on', 'off', 'clear').
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/position"><code>format.position</code></a></span> | `format.position` | Yes | `conditional` | Yes | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/dstrike"><code>format.dstrike</code></a></span> | `format.dstrike` | Yes | `conditional` | No | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/small-caps"><code>format.smallCaps</code></a></span> | `format.smallCaps` | Yes | `conditional` | No | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/caps"><code>format.caps</code></a></span> | `format.caps` | Yes | `conditional` | No | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/caps"><code>format.caps</code></a></span> | `format.caps` | Yes | `conditional` | Yes | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/shading"><code>format.shading</code></a></span> | `format.shading` | Yes | `conditional` | No | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/border"><code>format.border</code></a></span> | `format.border` | Yes | `conditional` | No | Yes |
| <span style={{ whiteSpace: 'nowrap', wordBreak: 'normal', overflowWrap: 'normal' }}><a href="/document-api/reference/format/outline"><code>format.outline</code></a></span> | `format.outline` | Yes | `conditional` | No | Yes |
Expand Down
29 changes: 29 additions & 0 deletions packages/document-api/src/format/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ describe('executeInlineAlias', () => {
});
});

describe('executeInlineAlias: format.caps', () => {
it('format.caps accepts omitted value (defaults to true)', () => {
const adapter = makeAdapter();
executeInlineAlias(adapter, 'caps', { target: TARGET });
expect(adapter.apply).toHaveBeenCalledWith(
{ target: TARGET, inline: { caps: true } },
expect.objectContaining({ changeMode: 'direct' }),
);
});

it('format.caps accepts explicit false', () => {
const adapter = makeAdapter();
executeInlineAlias(adapter, 'caps', { target: TARGET, value: false });
expect(adapter.apply).toHaveBeenCalledWith(
{ target: TARGET, inline: { caps: false } },
expect.objectContaining({ changeMode: 'direct' }),
);
});

it('format.caps accepts null to clear', () => {
const adapter = makeAdapter();
executeInlineAlias(adapter, 'caps', { target: TARGET, value: null });
expect(adapter.apply).toHaveBeenCalledWith(
{ target: TARGET, inline: { caps: null } },
expect.objectContaining({ changeMode: 'direct' }),
);
});
});

// ---------------------------------------------------------------------------
// FormatInlineAliasInput — compile-time type shape assertions
// ---------------------------------------------------------------------------
Expand Down
46 changes: 46 additions & 0 deletions packages/document-api/src/format/inline-run-patch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, expect, it } from 'vitest';
import { INLINE_PROPERTY_BY_KEY } from './inline-run-patch.js';

describe('INLINE_PROPERTY_REGISTRY: caps entry', () => {
const entry = INLINE_PROPERTY_BY_KEY['caps'];

it('exists in the registry', () => {
expect(entry).toBeDefined();
});

it('uses mark storage (not runAttribute)', () => {
expect(entry.storage).toBe('mark');
});

it('targets the textStyle mark with textTransform attribute', () => {
expect(entry.carrier).toEqual({
storage: 'mark',
markName: 'textStyle',
textStyleAttr: 'textTransform',
});
});

it('accepts boolean input type', () => {
expect(entry.type).toBe('boolean');
});

it('maps to the w:caps OOXML element', () => {
expect(entry.ooxmlElement).toBe('w:caps');
});
});

describe('INLINE_PROPERTY_REGISTRY: smallCaps entry', () => {
const entry = INLINE_PROPERTY_BY_KEY['smallCaps'];

it('uses runAttribute storage (distinct from caps)', () => {
expect(entry.storage).toBe('runAttribute');
});

it('targets the run node with smallCaps property key', () => {
expect(entry.carrier).toEqual({
storage: 'runAttribute',
nodeName: 'run',
runPropertyKey: 'smallCaps',
});
});
});
5 changes: 3 additions & 2 deletions packages/document-api/src/format/inline-run-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ const markTextStyleValue = (
type: InlinePropertyType,
ooxmlElement: string,
schema: Record<string, unknown>,
textStyleAttr?: string,
): InlinePropertyRegistryEntry => ({
key,
type,
ooxmlElement,
storage: 'mark',
tracked: true,
carrier: markCarrier('textStyle', key),
carrier: markCarrier('textStyle', textStyleAttr ?? key),
schema,
});

Expand Down Expand Up @@ -279,7 +280,7 @@ export const INLINE_PROPERTY_REGISTRY = [
markTextStyleValue('position', 'number', 'w:position', schemaNumberOrNull()),
runAttribute('dstrike', 'boolean', 'w:dstrike', schemaBooleanOrNull()),
runAttribute('smallCaps', 'boolean', 'w:smallCaps', schemaBooleanOrNull()),
runAttribute('caps', 'boolean', 'w:caps', schemaBooleanOrNull()),
markTextStyleValue('caps', 'boolean', 'w:caps', schemaBooleanOrNull(), 'textTransform'),
runAttribute(
'shading',
'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ function buildMarksFromSetMarks(editor: Editor, setMarks?: SetMarks): readonly P

type InlineRunPatch = StyleApplyInput['inline'];
type TextStylePatchKey = 'color' | 'fontSize' | 'letterSpacing' | 'vertAlign' | 'position';
type TextStylePatch = Partial<Pick<InlineRunPatch, TextStylePatchKey>>;
type TextStylePatch = Partial<Pick<InlineRunPatch, TextStylePatchKey>> & {
/** Derived from `caps` boolean — mapped to the textStyle mark's `textTransform` attribute. */
textTransform?: string | null;
};

interface InlineTextSegment {
from: number;
Expand Down Expand Up @@ -161,6 +164,11 @@ function toHalfPoints(value: number): number {
return Math.round(value * 2);
}

function capsToTextTransform(caps: boolean | null): string | null {
if (caps === null) return null;
return caps ? 'uppercase' : 'none';
}

function collectInlineTextSegments(doc: ProseMirrorNode, absFrom: number, absTo: number): InlineTextSegment[] {
const segments: InlineTextSegment[] = [];

Expand Down Expand Up @@ -233,8 +241,7 @@ function applyHighlightPatch(
function mergeTextStyleAttrs(currentAttrs: Record<string, unknown>, patch: TextStylePatch): Record<string, unknown> {
const next = { ...currentAttrs };

for (const key of TEXT_STYLE_KEYS) {
const value = patch[key];
for (const [key, value] of Object.entries(patch)) {
if (value === undefined) continue;

if (value === null) {
Expand All @@ -251,7 +258,7 @@ function mergeTextStyleAttrs(currentAttrs: Record<string, unknown>, patch: TextS
continue;
}

next[key] = value as string;
next[key] = value;
}

return compactAttrs(next);
Expand Down Expand Up @@ -613,6 +620,9 @@ function applyInlinePatchToRange(
(textStylePatch as Record<string, unknown>)[key] = inline[key];
}
}
if (inline.caps !== undefined) {
textStylePatch.textTransform = capsToTextTransform(inline.caps ?? null);
}
if (applyTextStylePatch(tr, schema.marks.textStyle, absFrom, absTo, textStylePatch)) {
changed = true;
}
Expand Down
Loading