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 @@ -496,5 +496,5 @@
}
],
"marker": "{/* GENERATED FILE: DO NOT EDIT. Regenerate via `pnpm run docapi:sync`. */}",
"sourceHash": "ee513c6250d785a2081789da920000cc75e2077ffd129acafd7ef7983c6518b1"
"sourceHash": "e06db0688bf06e7963ac3e777833076f02a71b4fa840cf301ca76a51efedc48f"
}
3,063 changes: 2,876 additions & 187 deletions apps/docs/document-api/reference/styles/apply.mdx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/document-api/src/contract/operation-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { DeleteInput } from '../delete/delete.js';
import type { MutationOptions, RevisionGuardOptions } from '../write/write.js';
import type { FormatInlineAliasInput, StyleApplyInput } from '../format/format.js';
import type { InlineRunPatchKey } from '../format/inline-run-patch.js';
import type { StylesApplyInput, StylesApplyOptions, StylesApplyReceipt } from '../styles/styles.js';
import type { StylesApplyInput, StylesApplyOptions, StylesApplyReceipt } from '../styles/index.js';
import type {
CommentsCreateInput,
CommentsPatchInput,
Expand Down
125 changes: 5 additions & 120 deletions packages/document-api/src/contract/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CLEAR_BORDER_SIDES,
LINE_RULES,
} from '../paragraphs/paragraphs.js';
import { buildPatchSchema, buildStateSchema } from '../styles/index.js';

type JsonSchema = Record<string, unknown>;

Expand Down Expand Up @@ -624,7 +625,7 @@
};
}

function listsExitResultSchemaFor(operationId: OperationId): JsonSchema {

Check warning on line 628 in packages/document-api/src/contract/schemas.ts

View workflow job for this annotation

GitHub Actions / validate

'listsExitResultSchemaFor' is defined but never used. Allowed unused vars must match /^_/u
return {
oneOf: [listsExitSuccessSchema, listsFailureSchemaFor(operationId)],
};
Expand Down Expand Up @@ -1851,120 +1852,25 @@
failure: paragraphMutationFailureSchemaFor('format.paragraph.clearShading'),
},
'styles.apply': (() => {
// --- Sub-schemas for object properties (all require minProperties: 1) ---
const fontFamilySchema = {
...objectSchema(
{
hint: { type: 'string' },
ascii: { type: 'string' },
hAnsi: { type: 'string' },
eastAsia: { type: 'string' },
cs: { type: 'string' },
val: { type: 'string' },
asciiTheme: { type: 'string' },
hAnsiTheme: { type: 'string' },
eastAsiaTheme: { type: 'string' },
cstheme: { type: 'string' },
},
[],
),
minProperties: 1,
};
const colorSchema = {
...objectSchema(
{
val: { type: 'string' },
themeColor: { type: 'string' },
themeTint: { type: 'string' },
themeShade: { type: 'string' },
},
[],
),
minProperties: 1,
};
const spacingSchema = {
...objectSchema(
{
after: { type: 'integer' },
afterAutospacing: { type: 'boolean' },
afterLines: { type: 'integer' },
before: { type: 'integer' },
beforeAutospacing: { type: 'boolean' },
beforeLines: { type: 'integer' },
line: { type: 'integer' },
lineRule: { enum: ['auto', 'exact', 'atLeast'] },
},
[],
),
minProperties: 1,
};
const indentSchema = {
...objectSchema(
{
end: { type: 'integer' },
endChars: { type: 'integer' },
firstLine: { type: 'integer' },
firstLineChars: { type: 'integer' },
hanging: { type: 'integer' },
hangingChars: { type: 'integer' },
left: { type: 'integer' },
leftChars: { type: 'integer' },
right: { type: 'integer' },
rightChars: { type: 'integer' },
start: { type: 'integer' },
startChars: { type: 'integer' },
},
[],
),
minProperties: 1,
};

// --- Run-channel input (channel: "run" → run patch) ---
// Derived from PROPERTY_REGISTRY — no hardcoded property lists
const runInputSchema = objectSchema(
{
target: objectSchema({ scope: { const: 'docDefaults' }, channel: { const: 'run' } }, ['scope', 'channel']),
patch: {
...objectSchema(
{
bold: { type: 'boolean' },
italic: { type: 'boolean' },
fontSize: { type: 'integer' },
fontSizeCs: { type: 'integer' },
letterSpacing: { type: 'integer' },
fontFamily: fontFamilySchema,
color: colorSchema,
},
[],
),
minProperties: 1,
},
patch: buildPatchSchema('run'),
},
['target', 'patch'],
);

// --- Paragraph-channel input (channel: "paragraph" → paragraph patch) ---
const paragraphInputSchema = objectSchema(
{
target: objectSchema({ scope: { const: 'docDefaults' }, channel: { const: 'paragraph' } }, [
'scope',
'channel',
]),
patch: {
...objectSchema(
{
justification: { enum: ['left', 'center', 'right', 'justify', 'distribute'] },
spacing: spacingSchema,
indent: indentSchema,
},
[],
),
minProperties: 1,
},
patch: buildPatchSchema('paragraph'),
},
['target', 'patch'],
);

// --- Resolution: discriminated by channel with concrete xmlPath values ---
const stylesTargetResolutionSchema = objectSchema(
{
scope: { const: 'docDefaults' },
Expand All @@ -1975,27 +1881,7 @@
['scope', 'channel', 'xmlPart', 'xmlPath'],
);

// --- Before/after state map for receipts ---
const booleanStateSchema = { enum: ['on', 'off', 'inherit'] };
const numberOrInheritSchema = { oneOf: [{ type: 'number' }, { const: 'inherit' }] };
const stringOrInheritSchema = { oneOf: [{ type: 'string' }, { const: 'inherit' }] };
const objectOrInheritSchema = { oneOf: [{ type: 'object' }, { const: 'inherit' }] };
const stylesStateSchema = {
type: 'object' as const,
properties: {
bold: booleanStateSchema,
italic: booleanStateSchema,
fontSize: numberOrInheritSchema,
fontSizeCs: numberOrInheritSchema,
letterSpacing: numberOrInheritSchema,
fontFamily: objectOrInheritSchema,
color: objectOrInheritSchema,
justification: stringOrInheritSchema,
spacing: objectOrInheritSchema,
indent: objectOrInheritSchema,
},
additionalProperties: false,
};
const stylesStateSchema = buildStateSchema();

const stylesSuccessSchema = objectSchema(
{
Expand Down Expand Up @@ -2024,7 +1910,6 @@
['success', 'resolution', 'failure'],
);
return {
// Discriminated input: oneOf with channel as the discriminator
input: { oneOf: [runInputSchema, paragraphInputSchema] },
output: { oneOf: [stylesSuccessSchema, stylesFailureSchema] },
success: stylesSuccessSchema,
Expand Down
21 changes: 15 additions & 6 deletions packages/document-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import type {
StylesApplyInput,
StylesApplyOptions,
StylesApplyReceipt,
} from './styles/styles.js';
import { executeStylesApply } from './styles/styles.js';
} from './styles/index.js';
import { executeStylesApply } from './styles/index.js';
import type { GetNodeAdapter, GetNodeByIdInput } from './get-node/get-node.js';
import { executeGetNode, executeGetNodeById } from './get-node/get-node.js';
import { executeGetText, type GetTextAdapter, type GetTextInput } from './get-text/get-text.js';
Expand Down Expand Up @@ -380,10 +380,19 @@ export {
validateInlineRunPatch,
buildInlineRunPatchSchema,
} from './format/inline-run-patch.js';
export { PROPERTY_REGISTRY } from './styles/styles.js';
export {
PROPERTY_REGISTRY,
EXCLUDED_KEYS,
ALLOWED_KEYS_BY_CHANNEL,
getPropertyDefinition,
toJsonSchema,
buildPatchSchema,
buildStateSchema,
} from './styles/index.js';
export type {
ValueSchema,
MergeStrategy,
PropertyDefinition,
ObjectSchema,
StylesAdapter,
StylesApplyInput,
StylesApplyRunInput,
Expand All @@ -394,16 +403,16 @@ export type {
StylesNumberState,
StylesEnumState,
StylesObjectState,
StylesArrayState,
StylesStateMap,
StylesChannel,
StylesJustification,
StylesRunPatch,
StylesParagraphPatch,
StylesTargetResolution,
StylesApplyReceiptSuccess,
StylesApplyReceiptFailure,
NormalizedStylesApplyOptions,
} from './styles/styles.js';
} from './styles/index.js';
export type { CreateAdapter } from './create/create.js';
export type {
TrackChangesAdapter,
Expand Down
2 changes: 1 addition & 1 deletion packages/document-api/src/invoke/invoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { FindAdapter } from '../find/find.js';
import type { GetNodeAdapter } from '../get-node/get-node.js';
import type { WriteAdapter } from '../write/write.js';
import type { FormatAdapter } from '../format/format.js';
import type { StylesAdapter } from '../styles/styles.js';
import type { StylesAdapter } from '../styles/index.js';
import type { TrackChangesAdapter } from '../track-changes/track-changes.js';
import type { CreateAdapter } from '../create/create.js';
import type { ListsAdapter } from '../lists/lists.js';
Expand Down
Loading
Loading