Skip to content

Commit ee17a46

Browse files
committed
Revert "fix: address PR review — minProperties, RichContentInsertInput type, deduplicate alignment constant"
This reverts commit 4c04ebd.
1 parent 4c04ebd commit ee17a46

4 files changed

Lines changed: 30 additions & 50 deletions

File tree

packages/document-api/src/contract/schemas.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,27 +4869,24 @@ const operationSchemas: Record<OperationId, OperationSchemaSet> = {
48694869
id: { type: 'string' },
48704870
op: { const: 'format.apply', type: 'string' },
48714871
where: stepWhereSchema,
4872-
args: {
4873-
...objectSchema(
4874-
{
4875-
inline: buildInlineRunPatchSchema(),
4876-
alignment: {
4877-
type: 'string',
4878-
enum: ['left', 'center', 'right', 'justify'],
4879-
description:
4880-
'Set paragraph alignment on the target block(s). Can be combined with inline formatting in the same step.',
4881-
},
4882-
scope: {
4883-
type: 'string',
4884-
enum: ['match', 'block'],
4885-
description:
4886-
'When "block", inline formatting expands to cover the entire parent paragraph(s), not just the matched text. Use "block" after markdown inserts to format whole paragraphs with a short identifying pattern. Default: "match".',
4887-
},
4872+
args: objectSchema(
4873+
{
4874+
inline: buildInlineRunPatchSchema(),
4875+
alignment: {
4876+
type: 'string',
4877+
enum: ['left', 'center', 'right', 'justify'],
4878+
description:
4879+
'Set paragraph alignment on the target block(s). Can be combined with inline formatting in the same step.',
48884880
},
4889-
[], // No individual field is required
4890-
),
4891-
minProperties: 1, // At least one of inline, alignment, or scope must be present
4892-
},
4881+
scope: {
4882+
type: 'string',
4883+
enum: ['match', 'block'],
4884+
description:
4885+
'When "block", inline formatting expands to cover the entire parent paragraph(s), not just the matched text. Use "block" after markdown inserts to format whole paragraphs with a short identifying pattern. Default: "match".',
4886+
},
4887+
},
4888+
[], // No individual field is required — at least one must be present
4889+
),
48934890
},
48944891
['id', 'op', 'where', 'args'],
48954892
);

packages/document-api/src/insert/insert.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { SelectionTarget, TargetLocator, SDMutationReceipt } from '../types
33
import type { SDInsertInput } from '../types/structural-input.js';
44
import type { SDFragment } from '../types/fragment.js';
55
import type { StoryLocator } from '../types/story.types.js';
6-
import type { BlockNodeAddress } from '../types/base.js';
7-
import type { Placement } from '../types/placement.js';
86
import { PLACEMENT_VALUES } from '../types/placement.js';
97
import { DocumentApiValidationError } from '../errors.js';
108
import {
@@ -42,25 +40,6 @@ export type TextInsertInput = OptionalInsertLocator & {
4240
in?: StoryLocator;
4341
};
4442

45-
/**
46-
* Extended input for markdown/html inserts that also accept BlockNodeAddress
47-
* targets and placement. These route through the structural insert path.
48-
*/
49-
export type RichContentInsertInput = {
50-
/** Block target for positioned inserts. Accepts BlockNodeAddress or SelectionTarget. */
51-
target?: SelectionTarget | BlockNodeAddress;
52-
/** Optional mutation ref. Mutually exclusive with target. */
53-
ref?: string;
54-
/** The markdown/html content to insert. */
55-
value: string;
56-
/** Content format — must be 'markdown' or 'html' for this input shape. */
57-
type: 'markdown' | 'html';
58-
/** Where to place content relative to target. Only valid with BlockNodeAddress targets. */
59-
placement?: Placement;
60-
/** Target a specific document story. */
61-
in?: StoryLocator;
62-
};
63-
6443
/** @deprecated Use {@link TextInsertInput} instead. */
6544
export type LegacyInsertInput = TextInsertInput;
6645

@@ -74,7 +53,7 @@ export type LegacyInsertInput = TextInsertInput;
7453
* Discrimination: presence of `content` (structural) vs `value` (text string).
7554
* These are mutually exclusive — providing both is an error.
7655
*/
77-
export type InsertInput = TextInsertInput | RichContentInsertInput | SDInsertInput;
56+
export type InsertInput = TextInsertInput | SDInsertInput;
7857

7958
// ---------------------------------------------------------------------------
8059
// Allowlists for strict field validation
@@ -297,19 +276,16 @@ export function executeInsert(
297276
}
298277

299278
// Text string path
279+
const { target, ref, value } = input;
300280
const contentType = input.type ?? 'text';
301281

302282
// For non-text content types, delegate to the adapter's structured insert path.
303283
if (contentType !== 'text') {
304284
return writeAdapter.insertStructured(input, normalizeMutationOptions(options));
305285
}
306286

307-
// After the non-text branch, input is guaranteed to be a plain TextInsertInput.
308-
const textInput = input as TextInsertInput;
309-
const { target, ref, value } = textInput;
310-
311287
// Text path with target/ref → route through SelectionMutationAdapter
312-
const storyIn = textInput.in;
288+
const storyIn = input.in;
313289
if (target || ref) {
314290
const request = target
315291
? { kind: 'insert' as const, target, text: value, ...(storyIn ? { in: storyIn } : {}) }

packages/super-editor/src/editors/v1/document-api-adapters/plan-engine/executor.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import type {
3939
} from './executor-registry.types.js';
4040
import { getStepExecutor } from './executor-registry.js';
4141
import { planError } from './errors.js';
42-
import { ALIGNMENT_TO_JUSTIFICATION } from './paragraphs-wrappers.js';
4342
import { closeHistory } from 'prosemirror-history';
4443
import { yUndoPluginKey } from 'y-prosemirror';
4544
import { checkRevision, getRevision } from './revision-tracker.js';
@@ -805,13 +804,21 @@ export function executeTextDelete(
805804
return { changed: true };
806805
}
807806

807+
/** Alignment API value → OOXML justification value */
808+
const ALIGNMENT_TO_JUSTIFICATION: Record<string, string> = {
809+
left: 'left',
810+
center: 'center',
811+
right: 'right',
812+
justify: 'both',
813+
};
814+
808815
/**
809816
* Applies alignment to the paragraph node(s) that contain the given range.
810817
* Uses the same mechanism as paragraphsSetAlignmentWrapper: updates
811818
* paragraphProperties.justification via tr.setNodeMarkup.
812819
*/
813820
function applyAlignmentToRange(tr: Transaction, absFrom: number, absTo: number, alignment: string): boolean {
814-
const justification = ALIGNMENT_TO_JUSTIFICATION[alignment as keyof typeof ALIGNMENT_TO_JUSTIFICATION];
821+
const justification = ALIGNMENT_TO_JUSTIFICATION[alignment];
815822
if (!justification) return false;
816823

817824
let changed = false;

packages/super-editor/src/editors/v1/document-api-adapters/plan-engine/paragraphs-wrappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function mutateParagraphProperties(
238238
// Alignment mapping — external API → OOXML justification value
239239
// ---------------------------------------------------------------------------
240240

241-
export const ALIGNMENT_TO_JUSTIFICATION: Record<ParagraphAlignment, string> = {
241+
const ALIGNMENT_TO_JUSTIFICATION: Record<ParagraphAlignment, string> = {
242242
left: 'left',
243243
center: 'center',
244244
right: 'right',

0 commit comments

Comments
 (0)