@openeditor/core 0.0.25 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,11 +8,6 @@ type ProseMirrorMark = {
8
8
  type: string;
9
9
  attrs?: ProseMirrorAttrs;
10
10
  };
11
- type OpenEditorNodeMeta = {
12
- id?: string;
13
- block?: string;
14
- custom?: Record<string, unknown>;
15
- };
16
11
  type ProseMirrorNode = {
17
12
  type: string;
18
13
  attrs?: ProseMirrorAttrs;
@@ -22,11 +17,20 @@ type ProseMirrorNode = {
22
17
  };
23
18
  type OpenEditorBlock = ProseMirrorNode & {
24
19
  attrs?: ProseMirrorAttrs & {
25
- "data-openeditor-id"?: string;
26
- "data-openeditor-block"?: string;
27
- openeditor?: OpenEditorNodeMeta;
20
+ "openeditor-id"?: string;
28
21
  };
29
22
  };
23
+ /** Stable identity used by commands and interaction adapters. */
24
+ type OpenEditorBlockRef = {
25
+ id: string;
26
+ nodeType: string;
27
+ blockName?: string;
28
+ };
29
+ type OpenEditorBlockLocation = OpenEditorBlockRef & {
30
+ parentId: string | null;
31
+ index: number;
32
+ path: readonly number[];
33
+ };
30
34
  type OpenEditorDocumentMeta = {
31
35
  id?: string;
32
36
  title?: string;
@@ -217,7 +221,9 @@ type PlatformSupportResult = {
217
221
  document: OpenEditorDocument;
218
222
  issues: PlatformSupportIssue[];
219
223
  };
224
+ declare const OPENEDITOR_BLOCK_ID_ATTR = "openeditor-id";
220
225
  declare const cloneNode: <T extends ProseMirrorNode>(node: T) => T;
226
+ declare const createBlockId: (prefix?: string) => string;
221
227
  declare const createDocument: (content?: ProseMirrorNode[], meta?: OpenEditorDocumentMeta) => OpenEditorDocument;
222
228
  declare const createEditorState: (document: OpenEditorDocument, selection?: EditorSelection) => SerializedEditorState;
223
229
  declare const toProseMirrorDocument: (document: OpenEditorDocument) => ProseMirrorDocument;
@@ -226,11 +232,10 @@ declare const createTextNode: (text: string, marks?: ProseMirrorMark[]) => Prose
226
232
  declare const textBlock: (type: string, text: string, attrs?: ProseMirrorAttrs) => OpenEditorBlock;
227
233
  declare const createBlockRegistry: (specs: readonly BlockSpec[]) => BlockRegistry;
228
234
  declare const findBlockSpecForNode: (registry: BlockRegistry, node: ProseMirrorNode) => BlockSpec | undefined;
229
- declare const getNodeMeta: (node: ProseMirrorNode) => OpenEditorNodeMeta | undefined;
230
- declare const withNodeMeta: <T extends ProseMirrorNode>(node: T, meta: OpenEditorNodeMeta) => T;
231
235
  declare const getBlockId: (node: ProseMirrorNode) => string | undefined;
232
- declare const createBlockId: (prefix?: string) => string;
236
+ declare const withBlockId: <T extends ProseMirrorNode>(node: T, id: string) => T;
233
237
  declare const ensureBlockIds: (document: OpenEditorDocument, createId?: () => string) => OpenEditorDocument;
238
+ declare const findBlockLocation: (document: OpenEditorDocument, id: string) => OpenEditorBlockLocation | null;
234
239
  declare const normalizeDocument: (document: OpenEditorDocument) => OpenEditorDocument;
235
240
  declare const validateDocument: (document: unknown) => DocumentValidationResult;
236
241
  declare const isOpenEditorDocument: (value: unknown) => value is OpenEditorDocument;
@@ -248,4 +253,4 @@ declare const duplicateTopLevelBlock: (document: OpenEditorDocument, index: numb
248
253
  declare const deleteTopLevelBlock: (document: OpenEditorDocument, index: number, emptyBlock?: OpenEditorBlock) => OpenEditorDocument;
249
254
  declare const createTransaction: (before: OpenEditorDocument, after: OpenEditorDocument, command?: EditorCommand) => EditorTransaction;
250
255
 
251
- export { type BlockGroup, type BlockRegistry, type BlockSpec, DEFAULT_CALLOUT_EMOJI, DEFAULT_PAGE_EMOJI, type DocumentValidationIssue, type DocumentValidationResult, type EditorCommand, type EditorPlatform, type EditorSelection, type EditorTransaction, type JsonObject, type JsonPrimitive, type JsonValue, type OpenEditorAttachmentRuntime, type OpenEditorAttachmentSnapshot, type OpenEditorAttachmentUploadCallbacks, type OpenEditorAttachmentUploadInput, type OpenEditorAttachmentValidationResult, type OpenEditorBlock, type OpenEditorCommand, type OpenEditorConfig, type OpenEditorController, type OpenEditorDocument, type OpenEditorDocumentMeta, type OpenEditorEventHandlers, type OpenEditorFeatureName, type OpenEditorFeatureSet, type OpenEditorMarkName, type OpenEditorNodeMeta, type PlatformSupport, type PlatformSupportIssue, type PlatformSupportLevel, type PlatformSupportResult, type ProseMirrorAttrs, type ProseMirrorDocument, type ProseMirrorMark, type ProseMirrorNode, type SerializedEditorState, applyCommand, cloneNode, createAttachmentSnapshot, createBlockId, createBlockRegistry, createDocument, createEditorState, createTextNode, createTransaction, deleteTopLevelBlock, duplicateTopLevelBlock, ensureBlockIds, findBlockSpecForNode, fromProseMirrorDocument, getBlockId, getDocumentText, getNodeMeta, getPlatformDocument, getPlatformSupport, isOpenEditorDocument, moveTopLevelBlock, normalizeDocument, normalizeEmoji, parseEditorState, parseOpenEditorDocument, replaceTopLevelNode, replaceTopLevelRange, serializeEditorState, textBlock, toProseMirrorDocument, validateDocument, withNodeMeta };
256
+ export { type BlockGroup, type BlockRegistry, type BlockSpec, DEFAULT_CALLOUT_EMOJI, DEFAULT_PAGE_EMOJI, type DocumentValidationIssue, type DocumentValidationResult, type EditorCommand, type EditorPlatform, type EditorSelection, type EditorTransaction, type JsonObject, type JsonPrimitive, type JsonValue, OPENEDITOR_BLOCK_ID_ATTR, type OpenEditorAttachmentRuntime, type OpenEditorAttachmentSnapshot, type OpenEditorAttachmentUploadCallbacks, type OpenEditorAttachmentUploadInput, type OpenEditorAttachmentValidationResult, type OpenEditorBlock, type OpenEditorBlockLocation, type OpenEditorBlockRef, type OpenEditorCommand, type OpenEditorConfig, type OpenEditorController, type OpenEditorDocument, type OpenEditorDocumentMeta, type OpenEditorEventHandlers, type OpenEditorFeatureName, type OpenEditorFeatureSet, type OpenEditorMarkName, type PlatformSupport, type PlatformSupportIssue, type PlatformSupportLevel, type PlatformSupportResult, type ProseMirrorAttrs, type ProseMirrorDocument, type ProseMirrorMark, type ProseMirrorNode, type SerializedEditorState, applyCommand, cloneNode, createAttachmentSnapshot, createBlockId, createBlockRegistry, createDocument, createEditorState, createTextNode, createTransaction, deleteTopLevelBlock, duplicateTopLevelBlock, ensureBlockIds, findBlockLocation, findBlockSpecForNode, fromProseMirrorDocument, getBlockId, getDocumentText, getPlatformDocument, getPlatformSupport, isOpenEditorDocument, moveTopLevelBlock, normalizeDocument, normalizeEmoji, parseEditorState, parseOpenEditorDocument, replaceTopLevelNode, replaceTopLevelRange, serializeEditorState, textBlock, toProseMirrorDocument, validateDocument, withBlockId };
package/dist/index.js CHANGED
@@ -9,9 +9,7 @@ var createAttachmentSnapshot = (attrs = {}) => ({
9
9
  var DEFAULT_CALLOUT_EMOJI = "\u{1F4A1}";
10
10
  var DEFAULT_PAGE_EMOJI = "\u{1F4C4}";
11
11
  var normalizeEmoji = (value, fallback) => typeof value === "string" && value.trim() ? value.trim() : fallback;
12
- var OPENEDITOR_ATTR = "openeditor";
13
- var OPENEDITOR_ID_ATTR = "data-openeditor-id";
14
- var OPENEDITOR_BLOCK_ATTR = "data-openeditor-block";
12
+ var OPENEDITOR_BLOCK_ID_ATTR = "openeditor-id";
15
13
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
16
14
  var normalizeMeta = (meta) => meta && Object.keys(meta).length ? { ...meta } : void 0;
17
15
  var cloneAttrs = (attrs) => attrs ? { ...attrs } : void 0;
@@ -19,18 +17,43 @@ var cloneMark = (mark) => ({
19
17
  type: mark.type,
20
18
  ...mark.attrs ? { attrs: cloneAttrs(mark.attrs) } : {}
21
19
  });
22
- var cloneNode = (node) => ({
20
+ var cloneNodeShallow = (node) => ({
23
21
  ...node,
24
22
  ...node.attrs ? { attrs: cloneAttrs(node.attrs) } : {},
25
- ...node.marks ? { marks: node.marks.map(cloneMark) } : {},
26
- ...node.content ? { content: node.content.map(cloneNode) } : {}
23
+ ...node.marks ? { marks: node.marks.map(cloneMark) } : {}
27
24
  });
28
- var createDocument = (content = [], meta) => ({
29
- type: "doc",
30
- version: 1,
31
- content: content.map(cloneNode),
32
- ...normalizeMeta(meta) ? { meta: normalizeMeta(meta) } : {}
25
+ var cloneNode = (node) => ({
26
+ ...cloneNodeShallow(node),
27
+ ...node.content ? { content: node.content.map(cloneNode) } : {}
33
28
  });
29
+ var createBlockId = (prefix = "oe") => {
30
+ const random = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID() : Math.random().toString(36).slice(2);
31
+ return `${prefix}_${random.replaceAll("-", "").slice(0, 24)}`;
32
+ };
33
+ var cloneNodeWithIds = (node, createId, seenIds) => {
34
+ if (node.type === "text") return cloneNode(node);
35
+ const cloned = cloneNodeShallow(node);
36
+ const existingId = getBlockId(cloned);
37
+ let id = existingId && !seenIds.has(existingId) ? existingId : createId();
38
+ while (!id.trim() || seenIds.has(id)) id = createId();
39
+ seenIds.add(id);
40
+ const withId = withBlockId(cloned, id);
41
+ return {
42
+ ...withId,
43
+ ...node.content ? { content: node.content.map((child) => cloneNodeWithIds(child, createId, seenIds)) } : {}
44
+ };
45
+ };
46
+ var createDocumentWithIds = (content = [], meta, createId = createBlockId) => {
47
+ const normalizedMeta = normalizeMeta(meta);
48
+ const seenIds = /* @__PURE__ */ new Set();
49
+ return {
50
+ type: "doc",
51
+ version: 1,
52
+ content: content.map((node) => cloneNodeWithIds(node, createId, seenIds)),
53
+ ...normalizedMeta ? { meta: normalizedMeta } : {}
54
+ };
55
+ };
56
+ var createDocument = (content = [], meta) => createDocumentWithIds(content, meta);
34
57
  var createEditorState = (document, selection = { type: "none" }) => ({
35
58
  document: normalizeDocument(document),
36
59
  selection
@@ -80,50 +103,35 @@ var findBlockSpecForNode = (registry, node) => {
80
103
  }
81
104
  return void 0;
82
105
  };
83
- var getNodeMeta = (node) => {
84
- const attrs = node.attrs;
85
- const nested = attrs?.[OPENEDITOR_ATTR];
86
- const id = attrs?.[OPENEDITOR_ID_ATTR];
87
- const block = attrs?.[OPENEDITOR_BLOCK_ATTR];
88
- if (isRecord(nested)) {
89
- return {
90
- ...nested,
91
- ...typeof id === "string" ? { id } : {},
92
- ...typeof block === "string" ? { block } : {}
93
- };
94
- }
95
- if (typeof id === "string" || typeof block === "string") {
96
- return {
97
- ...typeof id === "string" ? { id } : {},
98
- ...typeof block === "string" ? { block } : {}
99
- };
100
- }
101
- return void 0;
106
+ var getBlockId = (node) => {
107
+ const value = node.attrs?.[OPENEDITOR_BLOCK_ID_ATTR];
108
+ return typeof value === "string" && value.trim() ? value : void 0;
102
109
  };
103
- var withNodeMeta = (node, meta) => {
104
- const attrs = cloneAttrs(node.attrs) ?? {};
105
- const previous = getNodeMeta(node);
106
- const nextMeta = { ...previous, ...meta };
107
- if (nextMeta.id) {
108
- attrs[OPENEDITOR_ID_ATTR] = nextMeta.id;
109
- }
110
- if (nextMeta.block) {
111
- attrs[OPENEDITOR_BLOCK_ATTR] = nextMeta.block;
110
+ var withBlockId = (node, id) => ({
111
+ ...node,
112
+ attrs: {
113
+ ...cloneAttrs(node.attrs),
114
+ [OPENEDITOR_BLOCK_ID_ATTR]: id
112
115
  }
113
- attrs[OPENEDITOR_ATTR] = nextMeta;
114
- return { ...node, attrs };
115
- };
116
- var getBlockId = (node) => getNodeMeta(node)?.id;
117
- var createBlockId = (prefix = "oe") => {
118
- const random = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID() : Math.random().toString(36).slice(2);
119
- return `${prefix}_${random.replaceAll("-", "").slice(0, 24)}`;
116
+ });
117
+ var ensureBlockIds = (document, createId = createBlockId) => createDocumentWithIds(document.content, document.meta, createId);
118
+ var findBlockLocation = (document, id) => {
119
+ const visit = (nodes, parentId, path) => {
120
+ for (let index = 0; index < nodes.length; index += 1) {
121
+ const node = nodes[index];
122
+ if (!node) continue;
123
+ const nodeId = getBlockId(node);
124
+ const nodePath = [...path, index];
125
+ if (nodeId === id) {
126
+ return { id, nodeType: node.type, parentId, index, path: nodePath };
127
+ }
128
+ const nested = node.content?.length ? visit(node.content, nodeId ?? parentId, nodePath) : null;
129
+ if (nested) return nested;
130
+ }
131
+ return null;
132
+ };
133
+ return visit(document.content, null, []);
120
134
  };
121
- var ensureBlockIds = (document, createId = createBlockId) => createDocument(
122
- document.content.map(
123
- (node) => getBlockId(node) ? node : withNodeMeta(node, { id: createId() })
124
- ),
125
- document.meta
126
- );
127
135
  var normalizeNode = (node) => {
128
136
  if (node.type === "heading") {
129
137
  const level = typeof node.attrs?.level === "number" ? node.attrs.level : 2;
@@ -374,6 +382,6 @@ var createTransaction = (before, after, command) => ({
374
382
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
375
383
  });
376
384
 
377
- export { DEFAULT_CALLOUT_EMOJI, DEFAULT_PAGE_EMOJI, applyCommand, cloneNode, createAttachmentSnapshot, createBlockId, createBlockRegistry, createDocument, createEditorState, createTextNode, createTransaction, deleteTopLevelBlock, duplicateTopLevelBlock, ensureBlockIds, findBlockSpecForNode, fromProseMirrorDocument, getBlockId, getDocumentText, getNodeMeta, getPlatformDocument, getPlatformSupport, isOpenEditorDocument, moveTopLevelBlock, normalizeDocument, normalizeEmoji, parseEditorState, parseOpenEditorDocument, replaceTopLevelNode, replaceTopLevelRange, serializeEditorState, textBlock, toProseMirrorDocument, validateDocument, withNodeMeta };
385
+ export { DEFAULT_CALLOUT_EMOJI, DEFAULT_PAGE_EMOJI, OPENEDITOR_BLOCK_ID_ATTR, applyCommand, cloneNode, createAttachmentSnapshot, createBlockId, createBlockRegistry, createDocument, createEditorState, createTextNode, createTransaction, deleteTopLevelBlock, duplicateTopLevelBlock, ensureBlockIds, findBlockLocation, findBlockSpecForNode, fromProseMirrorDocument, getBlockId, getDocumentText, getPlatformDocument, getPlatformSupport, isOpenEditorDocument, moveTopLevelBlock, normalizeDocument, normalizeEmoji, parseEditorState, parseOpenEditorDocument, replaceTopLevelNode, replaceTopLevelRange, serializeEditorState, textBlock, toProseMirrorDocument, validateDocument, withBlockId };
378
386
  //# sourceMappingURL=index.js.map
379
387
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @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AO,kBAAkB,QAAQ,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,GAAG,QAAA;AAAA,IACH,OAAA,EAAS,QAAA,CAAS,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAA,EAAG,YAAA,KAAiB,YAAA,KAAiB,KAAK,CAAA,CAAE,GAAA,CAAI,SAAS;AAAA,GAC5F,CAAA;AACH;AAEO,IAAM,iBAAA,GAAoB,CAC/B,MAAA,EACA,KAAA,EACA,OAAA,MACuB;AAAA,EACvB,MAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY,EAAC;AAAA,EAC7B,SAAA,EAAA,iBAAW,IAAI,IAAA,EAAK,EAAE,WAAA;AACxB,CAAA","file":"index.js","sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue | undefined };\n\nexport type ProseMirrorAttrs = Record<string, unknown>;\n\nexport type ProseMirrorMark = {\n type: string;\n attrs?: ProseMirrorAttrs;\n};\n\nexport type OpenEditorNodeMeta = {\n id?: string;\n block?: string;\n custom?: Record<string, unknown>;\n};\n\nexport type ProseMirrorNode = {\n type: string;\n attrs?: ProseMirrorAttrs;\n content?: ProseMirrorNode[];\n marks?: ProseMirrorMark[];\n text?: string;\n};\n\nexport type OpenEditorBlock = ProseMirrorNode & {\n attrs?: ProseMirrorAttrs & {\n \"data-openeditor-id\"?: string;\n \"data-openeditor-block\"?: string;\n openeditor?: OpenEditorNodeMeta;\n };\n};\n\nexport type OpenEditorDocumentMeta = {\n id?: string;\n title?: string;\n source?: string;\n createdAt?: string;\n updatedAt?: string;\n schemaVersion?: number;\n platform?: EditorPlatform;\n custom?: Record<string, unknown>;\n};\n\nexport type OpenEditorDocument = {\n type: \"doc\";\n version: 1;\n content: OpenEditorBlock[];\n meta?: OpenEditorDocumentMeta;\n};\n\nexport type ProseMirrorDocument = {\n type: \"doc\";\n content: ProseMirrorNode[];\n};\n\nexport type EditorPlatform = \"web\" | \"native\";\n\nexport type PlatformSupportLevel = \"supported\" | \"unsupported\";\n\nexport type PlatformSupport = {\n web: PlatformSupportLevel;\n native: PlatformSupportLevel;\n};\n\nexport type BlockGroup = \"text\" | \"media\" | \"layout\" | \"structure\" | \"embed\";\n\nexport type BlockSpec = {\n name: string;\n /** ProseMirror node type. Defaults to `name`. */\n nodeType?: string;\n label: string;\n group: BlockGroup;\n defaultNode: () => OpenEditorBlock;\n matchNode?: (node: ProseMirrorNode) => boolean;\n support?: PlatformSupport;\n};\n\nexport type BlockRegistry = ReadonlyMap<string, BlockSpec>;\n\nexport type EditorSelection =\n | { type: \"none\" }\n | { type: \"text\"; anchor: number; head: number }\n | { type: \"node\"; from: number; to: number; nodeType?: string }\n | { type: \"block\"; blockId: string };\n\nexport type OpenEditorMarkName =\n | \"bold\"\n | \"italic\"\n | \"underline\"\n | \"strike\"\n | \"code\"\n | \"link\";\n\nexport type OpenEditorFeatureName =\n | \"headings\"\n | \"lists\"\n | \"taskLists\"\n | \"quotes\"\n | \"codeBlocks\"\n | \"dividers\"\n | \"links\"\n | \"images\"\n | \"columns\"\n | \"tables\"\n | \"toggleLists\"\n | \"callouts\"\n | \"diagrams\"\n | \"pages\"\n | \"attachments\";\n\n/** Durable, portable attributes stored on an attachment node. */\nexport type OpenEditorAttachmentSnapshot = {\n attachmentId: string | null;\n name: string;\n mimeType: string | null;\n size: number | null;\n url: string | null;\n};\n\n/**\n * A host-selected local file. `source` is deliberately opaque: on web it may\n * be a File, while native hosts typically use a picker result or local URI.\n * OpenEditor never serializes it.\n */\nexport type OpenEditorAttachmentUploadInput<TSource = unknown> = {\n name: string;\n mimeType: string | null;\n size: number | null;\n source: TSource;\n};\n\nexport type OpenEditorAttachmentUploadCallbacks = {\n onProgress?: (progress: number) => void;\n signal?: AbortSignal;\n};\n\nexport type OpenEditorAttachmentValidationResult =\n | { accepted: true }\n | { accepted: false; message: string };\n\n/** Host-owned storage, picker, policy, resolution, and platform actions. */\nexport type OpenEditorAttachmentRuntime<TSource = unknown> = {\n selectAttachment?: (options?: { signal?: AbortSignal }) =>\n | Promise<OpenEditorAttachmentUploadInput<TSource> | null>\n | OpenEditorAttachmentUploadInput<TSource>\n | null;\n validateAttachment?: (\n input: OpenEditorAttachmentUploadInput<TSource>,\n ) => OpenEditorAttachmentValidationResult | Promise<OpenEditorAttachmentValidationResult>;\n uploadAttachment?: (\n input: OpenEditorAttachmentUploadInput<TSource>,\n callbacks?: OpenEditorAttachmentUploadCallbacks,\n ) => Promise<OpenEditorAttachmentSnapshot>;\n resolveAttachment?: (attachmentId: string, options?: { signal?: AbortSignal }) =>\n Promise<OpenEditorAttachmentSnapshot | null>;\n openAttachment?: (attachment: OpenEditorAttachmentSnapshot) => void | Promise<void>;\n renameAttachment?: (attachmentId: string, name: string) => void | Promise<void>;\n replaceAttachment?: (\n attachmentId: string,\n input: OpenEditorAttachmentUploadInput<TSource>,\n callbacks?: OpenEditorAttachmentUploadCallbacks,\n ) => Promise<OpenEditorAttachmentSnapshot>;\n};\n\nexport const createAttachmentSnapshot = (\n attrs: Partial<OpenEditorAttachmentSnapshot> = {},\n): OpenEditorAttachmentSnapshot => ({\n attachmentId: typeof attrs.attachmentId === \"string\" ? attrs.attachmentId : null,\n name: typeof attrs.name === \"string\" ? attrs.name : \"\",\n mimeType: typeof attrs.mimeType === \"string\" ? attrs.mimeType : null,\n size: typeof attrs.size === \"number\" && Number.isFinite(attrs.size) && attrs.size >= 0 ? attrs.size : null,\n url: typeof attrs.url === \"string\" ? attrs.url : null,\n});\n\nexport type OpenEditorFeatureSet = Readonly<Record<OpenEditorFeatureName, boolean>>;\n\nexport const DEFAULT_CALLOUT_EMOJI = \"💡\";\nexport const DEFAULT_PAGE_EMOJI = \"📄\";\n\nexport const normalizeEmoji = (value: unknown, fallback: string) =>\n typeof value === \"string\" && value.trim() ? value.trim() : fallback;\n\nexport type SerializedEditorState = {\n document: OpenEditorDocument;\n selection?: EditorSelection;\n};\n\nexport type EditorTransaction = {\n before: OpenEditorDocument;\n after: OpenEditorDocument;\n command?: OpenEditorCommand;\n timestamp: string;\n};\n\nexport type OpenEditorCommand =\n | { type: \"setContent\"; document: OpenEditorDocument }\n | { type: \"insertBlock\"; block: string; at?: number; attrs?: ProseMirrorAttrs }\n | { type: \"moveBlock\"; from: number; to: number }\n | { type: \"duplicateBlock\"; index: number }\n | { type: \"deleteBlock\"; index: number }\n | { type: \"setLink\"; href?: string }\n | { type: \"toggleMark\"; mark: OpenEditorMarkName }\n | { type: \"undo\" }\n | { type: \"redo\" }\n | { type: \"replaceDocument\"; document: OpenEditorDocument }\n | { type: \"setSelection\"; selection: EditorSelection };\n\nexport type EditorCommand = OpenEditorCommand;\n\nexport type OpenEditorEventHandlers = {\n onChange?: (document: OpenEditorDocument) => void;\n onSelectionChange?: (selection: EditorSelection) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onReady?: (controller: OpenEditorController) => void;\n onCommand?: (command: OpenEditorCommand, transaction: EditorTransaction) => void;\n};\n\nexport type OpenEditorConfig = OpenEditorEventHandlers & {\n document?: OpenEditorDocument;\n editable?: boolean;\n placeholder?: string;\n enabledBlocks?: readonly string[];\n theme?: Record<string, string | number>;\n features?: Partial<OpenEditorFeatureSet>;\n};\n\nexport type OpenEditorController = {\n getDocument: () => OpenEditorDocument;\n setDocument: (document: OpenEditorDocument) => void;\n getSelection: () => EditorSelection;\n execute: (command: OpenEditorCommand) => void;\n};\n\nexport type DocumentValidationIssue = {\n path: string;\n message: string;\n};\n\nexport type DocumentValidationResult = {\n valid: boolean;\n issues: DocumentValidationIssue[];\n};\n\nexport type PlatformSupportIssue = {\n path: string;\n block: string;\n platform: EditorPlatform;\n support: PlatformSupportLevel;\n};\n\nexport type PlatformSupportResult = {\n platform: EditorPlatform;\n document: OpenEditorDocument;\n issues: PlatformSupportIssue[];\n};\n\nconst OPENEDITOR_ATTR = \"openeditor\";\nconst OPENEDITOR_ID_ATTR = \"data-openeditor-id\";\nconst OPENEDITOR_BLOCK_ATTR = \"data-openeditor-block\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst normalizeMeta = (meta?: OpenEditorDocumentMeta): OpenEditorDocumentMeta | undefined =>\n meta && Object.keys(meta).length ? { ...meta } : undefined;\n\nconst cloneAttrs = (attrs?: ProseMirrorAttrs): ProseMirrorAttrs | undefined =>\n attrs ? { ...attrs } : undefined;\n\nconst cloneMark = (mark: ProseMirrorMark): ProseMirrorMark => ({\n type: mark.type,\n ...(mark.attrs ? { attrs: cloneAttrs(mark.attrs) } : {}),\n});\n\nexport const cloneNode = <T extends ProseMirrorNode>(node: T): T => ({\n ...node,\n ...(node.attrs ? { attrs: cloneAttrs(node.attrs) } : {}),\n ...(node.marks ? { marks: node.marks.map(cloneMark) } : {}),\n ...(node.content ? { content: node.content.map(cloneNode) } : {}),\n});\n\nexport const createDocument = (\n content: ProseMirrorNode[] = [],\n meta?: OpenEditorDocumentMeta,\n): OpenEditorDocument => ({\n type: \"doc\",\n version: 1,\n content: content.map(cloneNode) as OpenEditorBlock[],\n ...(normalizeMeta(meta) ? { meta: normalizeMeta(meta) } : {}),\n});\n\nexport const createEditorState = (\n document: OpenEditorDocument,\n selection: EditorSelection = { type: \"none\" },\n): SerializedEditorState => ({\n document: normalizeDocument(document),\n selection,\n});\n\nexport const toProseMirrorDocument = (document: OpenEditorDocument): ProseMirrorDocument => ({\n type: \"doc\",\n content: document.content.map(cloneNode),\n});\n\nexport const fromProseMirrorDocument = (\n document: ProseMirrorDocument,\n meta?: OpenEditorDocumentMeta,\n): OpenEditorDocument => createDocument(document.content, meta);\n\nexport const createTextNode = (text: string, marks?: ProseMirrorMark[]): ProseMirrorNode => ({\n type: \"text\",\n text,\n ...(marks?.length ? { marks: marks.map(cloneMark) } : {}),\n});\n\nexport const textBlock = (type: string, text: string, attrs?: ProseMirrorAttrs): OpenEditorBlock => ({\n type,\n ...(attrs ? { attrs: cloneAttrs(attrs) } : {}),\n content: text ? [createTextNode(text)] : [],\n});\n\nexport const createBlockRegistry = (specs: readonly BlockSpec[]): BlockRegistry => {\n const registry = new Map<string, BlockSpec>();\n const nodeTypes = new Map<string, string>();\n\n for (const spec of specs) {\n if (!spec.name.trim()) {\n throw new Error(\"OpenEditor block names must not be empty.\");\n }\n if (registry.has(spec.name)) {\n throw new Error(`Duplicate OpenEditor block name \"${spec.name}\".`);\n }\n\n const nodeType = spec.nodeType ?? spec.name;\n const existing = nodeTypes.get(nodeType);\n if (existing) {\n throw new Error(\n `OpenEditor blocks \"${existing}\" and \"${spec.name}\" both claim node type \"${nodeType}\".`,\n );\n }\n\n registry.set(spec.name, spec);\n nodeTypes.set(nodeType, spec.name);\n }\n\n return registry;\n};\n\nexport const findBlockSpecForNode = (\n registry: BlockRegistry,\n node: ProseMirrorNode,\n): BlockSpec | undefined => {\n for (const spec of registry.values()) {\n if (spec.matchNode?.(node) || (spec.nodeType ?? spec.name) === node.type) {\n return spec;\n }\n }\n\n return undefined;\n};\n\nexport const getNodeMeta = (node: ProseMirrorNode): OpenEditorNodeMeta | undefined => {\n const attrs = node.attrs;\n const nested = attrs?.[OPENEDITOR_ATTR];\n const id = attrs?.[OPENEDITOR_ID_ATTR];\n const block = attrs?.[OPENEDITOR_BLOCK_ATTR];\n\n if (isRecord(nested)) {\n return {\n ...nested,\n ...(typeof id === \"string\" ? { id } : {}),\n ...(typeof block === \"string\" ? { block } : {}),\n } as OpenEditorNodeMeta;\n }\n\n if (typeof id === \"string\" || typeof block === \"string\") {\n return {\n ...(typeof id === \"string\" ? { id } : {}),\n ...(typeof block === \"string\" ? { block } : {}),\n };\n }\n\n return undefined;\n};\n\nexport const withNodeMeta = <T extends ProseMirrorNode>(\n node: T,\n meta: OpenEditorNodeMeta,\n): T => {\n const attrs = cloneAttrs(node.attrs) ?? {};\n const previous = getNodeMeta(node);\n const nextMeta = { ...previous, ...meta };\n\n if (nextMeta.id) {\n attrs[OPENEDITOR_ID_ATTR] = nextMeta.id;\n }\n\n if (nextMeta.block) {\n attrs[OPENEDITOR_BLOCK_ATTR] = nextMeta.block;\n }\n\n attrs[OPENEDITOR_ATTR] = nextMeta;\n return { ...node, attrs } as T;\n};\n\nexport const getBlockId = (node: ProseMirrorNode): string | undefined =>\n getNodeMeta(node)?.id;\n\nexport const createBlockId = (prefix = \"oe\"): string => {\n const random =\n typeof globalThis.crypto?.randomUUID === \"function\"\n ? globalThis.crypto.randomUUID()\n : Math.random().toString(36).slice(2);\n\n return `${prefix}_${random.replaceAll(\"-\", \"\").slice(0, 24)}`;\n};\n\nexport const ensureBlockIds = (\n document: OpenEditorDocument,\n createId: () => string = createBlockId,\n): OpenEditorDocument =>\n createDocument(\n document.content.map((node) =>\n getBlockId(node) ? node : withNodeMeta(node, { id: createId() }),\n ),\n document.meta,\n );\n\nconst normalizeNode = (node: ProseMirrorNode): OpenEditorBlock => {\n if (node.type === \"heading\") {\n const level = typeof node.attrs?.level === \"number\" ? node.attrs.level : 2;\n const content = node.content?.map(normalizeNode);\n\n return {\n ...cloneNode(node),\n attrs: { ...node.attrs, level: Math.min(Math.max(level, 1), 6) },\n ...(content ? { content } : {}),\n };\n }\n\n if (node.type === \"columns\") {\n const content = node.content?.length\n ? node.content.map(normalizeNode)\n : [\n { type: \"column\", content: [textBlock(\"paragraph\", \"\")] },\n { type: \"column\", content: [textBlock(\"paragraph\", \"\")] },\n ];\n\n return {\n ...cloneNode(node),\n attrs: Object.fromEntries(\n Object.entries(node.attrs ?? {}).filter(([name]) => name !== \"count\"),\n ),\n content,\n };\n }\n\n if (node.type === \"column\" && !node.content?.length) {\n return { ...cloneNode(node), content: [textBlock(\"paragraph\", \"\")] };\n }\n\n const content = node.content?.map(normalizeNode);\n return {\n ...cloneNode(node),\n ...(content ? { content } : {}),\n };\n};\n\nexport const normalizeDocument = (document: OpenEditorDocument): OpenEditorDocument =>\n createDocument(document.content.map(normalizeNode), document.meta);\n\nexport const validateDocument = (document: unknown): DocumentValidationResult => {\n const issues: DocumentValidationIssue[] = [];\n const push = (path: string, message: string) => issues.push({ path, message });\n\n const validateNode = (node: unknown, path: string) => {\n if (!isRecord(node)) {\n push(path, \"Node must be an object.\");\n return;\n }\n\n if (typeof node.type !== \"string\" || !node.type) {\n push(`${path}.type`, \"Node type must be a non-empty string.\");\n }\n\n if (\"text\" in node && typeof node.text !== \"string\") {\n push(`${path}.text`, \"Text node content must be a string.\");\n }\n\n if (\"attrs\" in node && node.attrs !== undefined && !isRecord(node.attrs)) {\n push(`${path}.attrs`, \"Node attrs must be an object.\");\n }\n\n if (\"marks\" in node && node.marks !== undefined) {\n if (!Array.isArray(node.marks)) {\n push(`${path}.marks`, \"Marks must be an array.\");\n } else {\n node.marks.forEach((mark, index) => {\n if (!isRecord(mark) || typeof mark.type !== \"string\" || !mark.type) {\n push(`${path}.marks.${index}`, \"Mark must have a non-empty type.\");\n }\n });\n }\n }\n\n if (\"content\" in node && node.content !== undefined) {\n if (!Array.isArray(node.content)) {\n push(`${path}.content`, \"Node content must be an array.\");\n } else {\n node.content.forEach((child, index) => validateNode(child, `${path}.content.${index}`));\n }\n }\n };\n\n if (!isRecord(document)) {\n return {\n valid: false,\n issues: [{ path: \"$\", message: \"Document must be an object.\" }],\n };\n }\n\n if (document.type !== \"doc\") {\n push(\"$.type\", 'Document type must be \"doc\".');\n }\n\n if (document.version !== 1) {\n push(\"$.version\", \"Document version must be 1.\");\n }\n\n if (!Array.isArray(document.content)) {\n push(\"$.content\", \"Document content must be an array.\");\n } else {\n document.content.forEach((node, index) => validateNode(node, `$.content.${index}`));\n }\n\n if (\"meta\" in document && document.meta !== undefined && !isRecord(document.meta)) {\n push(\"$.meta\", \"Document meta must be an object.\");\n }\n\n return {\n valid: issues.length === 0,\n issues,\n };\n};\n\nexport const isOpenEditorDocument = (value: unknown): value is OpenEditorDocument =>\n validateDocument(value).valid;\n\nexport const parseOpenEditorDocument = (\n value: unknown,\n defaultDocument: OpenEditorDocument = createDocument(),\n): OpenEditorDocument => {\n if (isOpenEditorDocument(value)) {\n return normalizeDocument(value);\n }\n\n if (isRecord(value) && value.type === \"doc\" && Array.isArray(value.content)) {\n return fromProseMirrorDocument(value as ProseMirrorDocument, defaultDocument.meta);\n }\n\n return defaultDocument;\n};\n\nexport const serializeEditorState = (state: SerializedEditorState): string =>\n JSON.stringify({\n document: normalizeDocument(state.document),\n ...(state.selection ? { selection: state.selection } : {}),\n });\n\nexport const parseEditorState = (\n value: unknown,\n defaultState: SerializedEditorState = createEditorState(createDocument()),\n): SerializedEditorState => {\n let parsed: unknown;\n\n try {\n parsed = typeof value === \"string\" ? JSON.parse(value) : value;\n } catch {\n return defaultState;\n }\n\n if (!isRecord(parsed)) {\n return defaultState;\n }\n\n return {\n document: parseOpenEditorDocument(parsed.document, defaultState.document),\n selection: isRecord(parsed.selection) ? (parsed.selection as EditorSelection) : defaultState.selection,\n };\n};\n\nexport const getPlatformDocument = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n platform: EditorPlatform,\n): OpenEditorDocument => getPlatformSupport(document, registry, platform).document;\n\nexport const getPlatformSupport = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n platform: EditorPlatform,\n): PlatformSupportResult => {\n const issues: PlatformSupportIssue[] = [];\n\n const mapNode = (node: OpenEditorBlock, path: string): OpenEditorBlock => {\n const spec = findBlockSpecForNode(registry, node);\n const support = spec?.support?.[platform] ?? \"supported\";\n\n if (support !== \"supported\") {\n issues.push({\n path,\n block: spec?.name ?? node.type,\n platform,\n support,\n });\n }\n\n return normalizeNode({\n ...cloneNode(node),\n content: node.content?.map((child, index) => mapNode(child, `${path}.content.${index}`)),\n });\n };\n\n return {\n platform,\n document: createDocument(\n document.content.map((node, index) => mapNode(node, `$.content.${index}`)),\n { ...document.meta, platform },\n ),\n issues,\n };\n};\n\nconst INLINE_NODE_TYPES = new Set([\"text\", \"hardBreak\"]);\n\nexport const getDocumentText = (node: OpenEditorDocument | ProseMirrorNode): string => {\n if (\"text\" in node && typeof node.text === \"string\") {\n return node.text;\n }\n\n const content = \"content\" in node ? node.content : undefined;\n\n if (!content?.length) {\n return \"\";\n }\n\n const isInlineContainer = content.every(\n (child) => INLINE_NODE_TYPES.has(child.type) || child.type === \"link\",\n );\n const joiner = isInlineContainer ? \"\" : \"\\n\";\n return content.map(getDocumentText).filter(Boolean).join(joiner);\n};\n\nexport const applyCommand = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n command: OpenEditorCommand,\n): OpenEditorDocument => {\n if (command.type === \"setContent\") {\n return normalizeDocument(command.document);\n }\n\n if (command.type === \"replaceDocument\") {\n return normalizeDocument(command.document);\n }\n\n if (command.type === \"setSelection\") {\n return document;\n }\n\n if (command.type === \"moveBlock\") {\n return moveTopLevelBlock(document, command.from, command.to);\n }\n\n if (command.type === \"duplicateBlock\") {\n return duplicateTopLevelBlock(document, command.index);\n }\n\n if (command.type === \"deleteBlock\") {\n return deleteTopLevelBlock(document, command.index);\n }\n\n if (\n command.type === \"setLink\"\n || command.type === \"toggleMark\"\n || command.type === \"undo\"\n || command.type === \"redo\"\n ) {\n return normalizeDocument(document);\n }\n\n const spec = registry.get(command.block);\n if (!spec) {\n throw new Error(`Unknown block \"${command.block}\"`);\n }\n\n const nextContent = [...document.content];\n const index = command.at ?? nextContent.length;\n const defaultNode = spec.defaultNode();\n const node = command.attrs\n ? { ...defaultNode, attrs: { ...defaultNode.attrs, ...command.attrs } }\n : defaultNode;\n\n nextContent.splice(index, 0, node);\n return normalizeDocument(createDocument(nextContent, document.meta));\n};\n\nexport const replaceTopLevelRange = (\n document: OpenEditorDocument,\n start: number,\n length: number,\n replacement: ProseMirrorNode[],\n): OpenEditorDocument =>\n normalizeDocument({\n ...document,\n content: [\n ...document.content.slice(0, start),\n ...replacement.map(cloneNode),\n ...document.content.slice(start + length),\n ],\n });\n\nexport const replaceTopLevelNode = (\n document: OpenEditorDocument,\n index: number,\n replacement: ProseMirrorNode,\n): OpenEditorDocument =>\n normalizeDocument({\n ...document,\n content: document.content.map((node, nodeIndex) => nodeIndex === index ? cloneNode(replacement) : cloneNode(node)),\n });\n\nexport const moveTopLevelBlock = (\n document: OpenEditorDocument,\n from: number,\n to: number,\n): OpenEditorDocument => {\n if (from < 0 || from >= document.content.length || to < 0 || to >= document.content.length || from === to) {\n return normalizeDocument(document);\n }\n\n const nextContent = document.content.map(cloneNode);\n const [item] = nextContent.splice(from, 1);\n if (!item) {\n return normalizeDocument(document);\n }\n\n nextContent.splice(to, 0, item);\n return normalizeDocument({ ...document, content: nextContent });\n};\n\nexport const duplicateTopLevelBlock = (\n document: OpenEditorDocument,\n index: number,\n): OpenEditorDocument => {\n if (index < 0 || index >= document.content.length) {\n return normalizeDocument(document);\n }\n\n const nextContent = document.content.map(cloneNode);\n nextContent.splice(index + 1, 0, cloneNode(document.content[index]));\n return normalizeDocument({ ...document, content: nextContent });\n};\n\nexport const deleteTopLevelBlock = (\n document: OpenEditorDocument,\n index: number,\n emptyBlock: OpenEditorBlock = textBlock(\"paragraph\", \"\"),\n): OpenEditorDocument => {\n if (document.content.length <= 1) {\n return normalizeDocument({ ...document, content: [cloneNode(emptyBlock)] });\n }\n\n if (index < 0 || index >= document.content.length) {\n return normalizeDocument(document);\n }\n\n return normalizeDocument({\n ...document,\n content: document.content.filter((_, currentIndex) => currentIndex !== index).map(cloneNode),\n });\n};\n\nexport const createTransaction = (\n before: OpenEditorDocument,\n after: OpenEditorDocument,\n command?: EditorCommand,\n): EditorTransaction => ({\n before,\n after,\n ...(command ? { command } : {}),\n timestamp: new Date().toISOString(),\n});\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["content"],"mappings":";AA0KO,IAAM,wBAAA,GAA2B,CACtC,KAAA,GAA+C,EAAC,MACd;AAAA,EAClC,cAAc,OAAO,KAAA,CAAM,YAAA,KAAiB,QAAA,GAAW,MAAM,YAAA,GAAe,IAAA;AAAA,EAC5E,MAAM,OAAO,KAAA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AS,CAAA;AAClD,EAAA,WAAA,CAAY,MAAA,CAAO,QAAQ,CAAA,EAAG,CAAA,EAAG,UAAU,QAAA,CAAS,OAAA,CAAQ,KAAK,CAAC,CAAC,CAAA;AACnE,EAAA,OAAO,kBAAkB,EAAE,GAAG,QAAA,EAAU,OAAA,EAAS,aAAa,CAAA;AAChE;AAEO,IAAM,mBAAA,GAAsB,CACjC,QAAA,EACA,KAAA,EACA,aAA8B,SAAA,CAAU,WAAA,EAAa,EAAE,CAAA,KAChC;AACvB,EAAA,IAAI,QAAA,CAAS,OAAA,CAAQ,MAAA,IAAU,CAAA,EAAG;AAChC,IAAA,OAAO,iBAAA,CAAkB,EAAE,GAAG,QAAA,EAAU,OAAA,EAAS,CAAC,SAAA,CAAU,UAAU,CAAC,CAAA,EAAG,CAAA;AAAA,EAC5E;AAEA,EAAA,IAAI,KAAA,GAAQ,CAAA,IAAK,KAAA,IAAS,QAAA,CAAS,QAAQ,MAAA,EAAQ;AACjD,IAAA,OAAO,kBAAkB,QAAQ,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,GAAG,QAAA;AAAA,IACH,OAAA,EAAS,QAAA,CAAS,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAA,EAAG,YAAA,KAAiB,YAAA,KAAiB,KAAK,CAAA,CAAE,GAAA,CAAI,SAAS;AAAA,GAC5F,CAAA;AACH;AAEO,IAAM,iBAAA,GAAoB,CAC/B,MAAA,EACA,KAAA,EACA,OAAA,MACuB;AAAA,EACvB,MAAA;AAAA,EACA,KAAA;AAAA,EACA,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY,EAAC;AAAA,EAC7B,SAAA,EAAA,iBAAW,IAAI,IAAA,EAAK,EAAE,WAAA;AACxB,CAAA","file":"index.js","sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue | undefined };\n\nexport type ProseMirrorAttrs = Record<string, unknown>;\n\nexport type ProseMirrorMark = {\n type: string;\n attrs?: ProseMirrorAttrs;\n};\n\nexport type ProseMirrorNode = {\n type: string;\n attrs?: ProseMirrorAttrs;\n content?: ProseMirrorNode[];\n marks?: ProseMirrorMark[];\n text?: string;\n};\n\nexport type OpenEditorBlock = ProseMirrorNode & {\n attrs?: ProseMirrorAttrs & {\n \"openeditor-id\"?: string;\n };\n};\n\n/** Stable identity used by commands and interaction adapters. */\nexport type OpenEditorBlockRef = {\n id: string;\n nodeType: string;\n blockName?: string;\n};\n\nexport type OpenEditorBlockLocation = OpenEditorBlockRef & {\n parentId: string | null;\n index: number;\n path: readonly number[];\n};\n\nexport type OpenEditorDocumentMeta = {\n id?: string;\n title?: string;\n source?: string;\n createdAt?: string;\n updatedAt?: string;\n schemaVersion?: number;\n platform?: EditorPlatform;\n custom?: Record<string, unknown>;\n};\n\nexport type OpenEditorDocument = {\n type: \"doc\";\n version: 1;\n content: OpenEditorBlock[];\n meta?: OpenEditorDocumentMeta;\n};\n\nexport type ProseMirrorDocument = {\n type: \"doc\";\n content: ProseMirrorNode[];\n};\n\nexport type EditorPlatform = \"web\" | \"native\";\n\nexport type PlatformSupportLevel = \"supported\" | \"unsupported\";\n\nexport type PlatformSupport = {\n web: PlatformSupportLevel;\n native: PlatformSupportLevel;\n};\n\nexport type BlockGroup = \"text\" | \"media\" | \"layout\" | \"structure\" | \"embed\";\n\nexport type BlockSpec = {\n name: string;\n /** ProseMirror node type. Defaults to `name`. */\n nodeType?: string;\n label: string;\n group: BlockGroup;\n defaultNode: () => OpenEditorBlock;\n matchNode?: (node: ProseMirrorNode) => boolean;\n support?: PlatformSupport;\n};\n\nexport type BlockRegistry = ReadonlyMap<string, BlockSpec>;\n\nexport type EditorSelection =\n | { type: \"none\" }\n | { type: \"text\"; anchor: number; head: number }\n | { type: \"node\"; from: number; to: number; nodeType?: string }\n | { type: \"block\"; blockId: string };\n\nexport type OpenEditorMarkName =\n | \"bold\"\n | \"italic\"\n | \"underline\"\n | \"strike\"\n | \"code\"\n | \"link\";\n\nexport type OpenEditorFeatureName =\n | \"headings\"\n | \"lists\"\n | \"taskLists\"\n | \"quotes\"\n | \"codeBlocks\"\n | \"dividers\"\n | \"links\"\n | \"images\"\n | \"columns\"\n | \"tables\"\n | \"toggleLists\"\n | \"callouts\"\n | \"diagrams\"\n | \"pages\"\n | \"attachments\";\n\n/** Durable, portable attributes stored on an attachment node. */\nexport type OpenEditorAttachmentSnapshot = {\n attachmentId: string | null;\n name: string;\n mimeType: string | null;\n size: number | null;\n url: string | null;\n};\n\n/**\n * A host-selected local file. `source` is deliberately opaque: on web it may\n * be a File, while native hosts typically use a picker result or local URI.\n * OpenEditor never serializes it.\n */\nexport type OpenEditorAttachmentUploadInput<TSource = unknown> = {\n name: string;\n mimeType: string | null;\n size: number | null;\n source: TSource;\n};\n\nexport type OpenEditorAttachmentUploadCallbacks = {\n onProgress?: (progress: number) => void;\n signal?: AbortSignal;\n};\n\nexport type OpenEditorAttachmentValidationResult =\n | { accepted: true }\n | { accepted: false; message: string };\n\n/** Host-owned storage, picker, policy, resolution, and platform actions. */\nexport type OpenEditorAttachmentRuntime<TSource = unknown> = {\n selectAttachment?: (options?: { signal?: AbortSignal }) =>\n | Promise<OpenEditorAttachmentUploadInput<TSource> | null>\n | OpenEditorAttachmentUploadInput<TSource>\n | null;\n validateAttachment?: (\n input: OpenEditorAttachmentUploadInput<TSource>,\n ) => OpenEditorAttachmentValidationResult | Promise<OpenEditorAttachmentValidationResult>;\n uploadAttachment?: (\n input: OpenEditorAttachmentUploadInput<TSource>,\n callbacks?: OpenEditorAttachmentUploadCallbacks,\n ) => Promise<OpenEditorAttachmentSnapshot>;\n resolveAttachment?: (attachmentId: string, options?: { signal?: AbortSignal }) =>\n Promise<OpenEditorAttachmentSnapshot | null>;\n openAttachment?: (attachment: OpenEditorAttachmentSnapshot) => void | Promise<void>;\n renameAttachment?: (attachmentId: string, name: string) => void | Promise<void>;\n replaceAttachment?: (\n attachmentId: string,\n input: OpenEditorAttachmentUploadInput<TSource>,\n callbacks?: OpenEditorAttachmentUploadCallbacks,\n ) => Promise<OpenEditorAttachmentSnapshot>;\n};\n\nexport const createAttachmentSnapshot = (\n attrs: Partial<OpenEditorAttachmentSnapshot> = {},\n): OpenEditorAttachmentSnapshot => ({\n attachmentId: typeof attrs.attachmentId === \"string\" ? attrs.attachmentId : null,\n name: typeof attrs.name === \"string\" ? attrs.name : \"\",\n mimeType: typeof attrs.mimeType === \"string\" ? attrs.mimeType : null,\n size: typeof attrs.size === \"number\" && Number.isFinite(attrs.size) && attrs.size >= 0 ? attrs.size : null,\n url: typeof attrs.url === \"string\" ? attrs.url : null,\n});\n\nexport type OpenEditorFeatureSet = Readonly<Record<OpenEditorFeatureName, boolean>>;\n\nexport const DEFAULT_CALLOUT_EMOJI = \"💡\";\nexport const DEFAULT_PAGE_EMOJI = \"📄\";\n\nexport const normalizeEmoji = (value: unknown, fallback: string) =>\n typeof value === \"string\" && value.trim() ? value.trim() : fallback;\n\nexport type SerializedEditorState = {\n document: OpenEditorDocument;\n selection?: EditorSelection;\n};\n\nexport type EditorTransaction = {\n before: OpenEditorDocument;\n after: OpenEditorDocument;\n command?: OpenEditorCommand;\n timestamp: string;\n};\n\nexport type OpenEditorCommand =\n | { type: \"setContent\"; document: OpenEditorDocument }\n | { type: \"insertBlock\"; block: string; at?: number; attrs?: ProseMirrorAttrs }\n | { type: \"moveBlock\"; from: number; to: number }\n | { type: \"duplicateBlock\"; index: number }\n | { type: \"deleteBlock\"; index: number }\n | { type: \"setLink\"; href?: string }\n | { type: \"toggleMark\"; mark: OpenEditorMarkName }\n | { type: \"undo\" }\n | { type: \"redo\" }\n | { type: \"replaceDocument\"; document: OpenEditorDocument }\n | { type: \"setSelection\"; selection: EditorSelection };\n\nexport type EditorCommand = OpenEditorCommand;\n\nexport type OpenEditorEventHandlers = {\n onChange?: (document: OpenEditorDocument) => void;\n onSelectionChange?: (selection: EditorSelection) => void;\n onFocus?: () => void;\n onBlur?: () => void;\n onReady?: (controller: OpenEditorController) => void;\n onCommand?: (command: OpenEditorCommand, transaction: EditorTransaction) => void;\n};\n\nexport type OpenEditorConfig = OpenEditorEventHandlers & {\n document?: OpenEditorDocument;\n editable?: boolean;\n placeholder?: string;\n enabledBlocks?: readonly string[];\n theme?: Record<string, string | number>;\n features?: Partial<OpenEditorFeatureSet>;\n};\n\nexport type OpenEditorController = {\n getDocument: () => OpenEditorDocument;\n setDocument: (document: OpenEditorDocument) => void;\n getSelection: () => EditorSelection;\n execute: (command: OpenEditorCommand) => void;\n};\n\nexport type DocumentValidationIssue = {\n path: string;\n message: string;\n};\n\nexport type DocumentValidationResult = {\n valid: boolean;\n issues: DocumentValidationIssue[];\n};\n\nexport type PlatformSupportIssue = {\n path: string;\n block: string;\n platform: EditorPlatform;\n support: PlatformSupportLevel;\n};\n\nexport type PlatformSupportResult = {\n platform: EditorPlatform;\n document: OpenEditorDocument;\n issues: PlatformSupportIssue[];\n};\n\nexport const OPENEDITOR_BLOCK_ID_ATTR = \"openeditor-id\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst normalizeMeta = (meta?: OpenEditorDocumentMeta): OpenEditorDocumentMeta | undefined =>\n meta && Object.keys(meta).length ? { ...meta } : undefined;\n\nconst cloneAttrs = (attrs?: ProseMirrorAttrs): ProseMirrorAttrs | undefined =>\n attrs ? { ...attrs } : undefined;\n\nconst cloneMark = (mark: ProseMirrorMark): ProseMirrorMark => ({\n type: mark.type,\n ...(mark.attrs ? { attrs: cloneAttrs(mark.attrs) } : {}),\n});\n\nconst cloneNodeShallow = <T extends ProseMirrorNode>(node: T): T => ({\n ...node,\n ...(node.attrs ? { attrs: cloneAttrs(node.attrs) } : {}),\n ...(node.marks ? { marks: node.marks.map(cloneMark) } : {}),\n});\n\nexport const cloneNode = <T extends ProseMirrorNode>(node: T): T => ({\n ...cloneNodeShallow(node),\n ...(node.content ? { content: node.content.map(cloneNode) } : {}),\n});\n\nexport const createBlockId = (prefix = \"oe\"): string => {\n const random =\n typeof globalThis.crypto?.randomUUID === \"function\"\n ? globalThis.crypto.randomUUID()\n : Math.random().toString(36).slice(2);\n\n return `${prefix}_${random.replaceAll(\"-\", \"\").slice(0, 24)}`;\n};\n\nconst cloneNodeWithIds = (\n node: ProseMirrorNode,\n createId: () => string,\n seenIds: Set<string>,\n): ProseMirrorNode => {\n if (node.type === \"text\") return cloneNode(node);\n const cloned = cloneNodeShallow(node);\n const existingId = getBlockId(cloned);\n let id = existingId && !seenIds.has(existingId) ? existingId : createId();\n while (!id.trim() || seenIds.has(id)) id = createId();\n seenIds.add(id);\n const withId = withBlockId(cloned, id);\n return {\n ...withId,\n ...(node.content\n ? { content: node.content.map((child) => cloneNodeWithIds(child, createId, seenIds)) }\n : {}),\n };\n};\n\nconst createDocumentWithIds = (\n content: ProseMirrorNode[] = [],\n meta?: OpenEditorDocumentMeta,\n createId: () => string = createBlockId,\n): OpenEditorDocument => {\n const normalizedMeta = normalizeMeta(meta);\n const seenIds = new Set<string>();\n return {\n type: \"doc\",\n version: 1,\n content: content.map((node) => cloneNodeWithIds(node, createId, seenIds)) as OpenEditorBlock[],\n ...(normalizedMeta ? { meta: normalizedMeta } : {}),\n };\n};\n\nexport const createDocument = (\n content: ProseMirrorNode[] = [],\n meta?: OpenEditorDocumentMeta,\n): OpenEditorDocument => createDocumentWithIds(content, meta);\n\nexport const createEditorState = (\n document: OpenEditorDocument,\n selection: EditorSelection = { type: \"none\" },\n): SerializedEditorState => ({\n document: normalizeDocument(document),\n selection,\n});\n\nexport const toProseMirrorDocument = (document: OpenEditorDocument): ProseMirrorDocument => ({\n type: \"doc\",\n content: document.content.map(cloneNode),\n});\n\nexport const fromProseMirrorDocument = (\n document: ProseMirrorDocument,\n meta?: OpenEditorDocumentMeta,\n): OpenEditorDocument => createDocument(document.content, meta);\n\nexport const createTextNode = (text: string, marks?: ProseMirrorMark[]): ProseMirrorNode => ({\n type: \"text\",\n text,\n ...(marks?.length ? { marks: marks.map(cloneMark) } : {}),\n});\n\nexport const textBlock = (type: string, text: string, attrs?: ProseMirrorAttrs): OpenEditorBlock => ({\n type,\n ...(attrs ? { attrs: cloneAttrs(attrs) } : {}),\n content: text ? [createTextNode(text)] : [],\n});\n\nexport const createBlockRegistry = (specs: readonly BlockSpec[]): BlockRegistry => {\n const registry = new Map<string, BlockSpec>();\n const nodeTypes = new Map<string, string>();\n\n for (const spec of specs) {\n if (!spec.name.trim()) {\n throw new Error(\"OpenEditor block names must not be empty.\");\n }\n if (registry.has(spec.name)) {\n throw new Error(`Duplicate OpenEditor block name \"${spec.name}\".`);\n }\n\n const nodeType = spec.nodeType ?? spec.name;\n const existing = nodeTypes.get(nodeType);\n if (existing) {\n throw new Error(\n `OpenEditor blocks \"${existing}\" and \"${spec.name}\" both claim node type \"${nodeType}\".`,\n );\n }\n\n registry.set(spec.name, spec);\n nodeTypes.set(nodeType, spec.name);\n }\n\n return registry;\n};\n\nexport const findBlockSpecForNode = (\n registry: BlockRegistry,\n node: ProseMirrorNode,\n): BlockSpec | undefined => {\n for (const spec of registry.values()) {\n if (spec.matchNode?.(node) || (spec.nodeType ?? spec.name) === node.type) {\n return spec;\n }\n }\n\n return undefined;\n};\n\nexport const getBlockId = (node: ProseMirrorNode): string | undefined => {\n const value = node.attrs?.[OPENEDITOR_BLOCK_ID_ATTR];\n return typeof value === \"string\" && value.trim() ? value : undefined;\n};\n\nexport const withBlockId = <T extends ProseMirrorNode>(node: T, id: string): T => ({\n ...node,\n attrs: {\n ...cloneAttrs(node.attrs),\n [OPENEDITOR_BLOCK_ID_ATTR]: id,\n },\n});\n\nexport const ensureBlockIds = (\n document: OpenEditorDocument,\n createId: () => string = createBlockId,\n): OpenEditorDocument => createDocumentWithIds(document.content, document.meta, createId);\n\nexport const findBlockLocation = (\n document: OpenEditorDocument,\n id: string,\n): OpenEditorBlockLocation | null => {\n const visit = (\n nodes: readonly ProseMirrorNode[],\n parentId: string | null,\n path: readonly number[],\n ): OpenEditorBlockLocation | null => {\n for (let index = 0; index < nodes.length; index += 1) {\n const node = nodes[index];\n if (!node) continue;\n const nodeId = getBlockId(node);\n const nodePath = [...path, index];\n if (nodeId === id) {\n return { id, nodeType: node.type, parentId, index, path: nodePath };\n }\n const nested = node.content?.length\n ? visit(node.content, nodeId ?? parentId, nodePath)\n : null;\n if (nested) return nested;\n }\n return null;\n };\n\n return visit(document.content, null, []);\n};\n\nconst normalizeNode = (node: ProseMirrorNode): OpenEditorBlock => {\n if (node.type === \"heading\") {\n const level = typeof node.attrs?.level === \"number\" ? node.attrs.level : 2;\n const content = node.content?.map(normalizeNode);\n\n return {\n ...cloneNode(node),\n attrs: { ...node.attrs, level: Math.min(Math.max(level, 1), 6) },\n ...(content ? { content } : {}),\n };\n }\n\n if (node.type === \"columns\") {\n const content = node.content?.length\n ? node.content.map(normalizeNode)\n : [\n { type: \"column\", content: [textBlock(\"paragraph\", \"\")] },\n { type: \"column\", content: [textBlock(\"paragraph\", \"\")] },\n ];\n\n return {\n ...cloneNode(node),\n attrs: Object.fromEntries(\n Object.entries(node.attrs ?? {}).filter(([name]) => name !== \"count\"),\n ),\n content,\n };\n }\n\n if (node.type === \"column\" && !node.content?.length) {\n return { ...cloneNode(node), content: [textBlock(\"paragraph\", \"\")] };\n }\n\n const content = node.content?.map(normalizeNode);\n return {\n ...cloneNode(node),\n ...(content ? { content } : {}),\n };\n};\n\nexport const normalizeDocument = (document: OpenEditorDocument): OpenEditorDocument =>\n createDocument(document.content.map(normalizeNode), document.meta);\n\nexport const validateDocument = (document: unknown): DocumentValidationResult => {\n const issues: DocumentValidationIssue[] = [];\n const push = (path: string, message: string) => issues.push({ path, message });\n\n const validateNode = (node: unknown, path: string) => {\n if (!isRecord(node)) {\n push(path, \"Node must be an object.\");\n return;\n }\n\n if (typeof node.type !== \"string\" || !node.type) {\n push(`${path}.type`, \"Node type must be a non-empty string.\");\n }\n\n if (\"text\" in node && typeof node.text !== \"string\") {\n push(`${path}.text`, \"Text node content must be a string.\");\n }\n\n if (\"attrs\" in node && node.attrs !== undefined && !isRecord(node.attrs)) {\n push(`${path}.attrs`, \"Node attrs must be an object.\");\n }\n\n if (\"marks\" in node && node.marks !== undefined) {\n if (!Array.isArray(node.marks)) {\n push(`${path}.marks`, \"Marks must be an array.\");\n } else {\n node.marks.forEach((mark, index) => {\n if (!isRecord(mark) || typeof mark.type !== \"string\" || !mark.type) {\n push(`${path}.marks.${index}`, \"Mark must have a non-empty type.\");\n }\n });\n }\n }\n\n if (\"content\" in node && node.content !== undefined) {\n if (!Array.isArray(node.content)) {\n push(`${path}.content`, \"Node content must be an array.\");\n } else {\n node.content.forEach((child, index) => validateNode(child, `${path}.content.${index}`));\n }\n }\n };\n\n if (!isRecord(document)) {\n return {\n valid: false,\n issues: [{ path: \"$\", message: \"Document must be an object.\" }],\n };\n }\n\n if (document.type !== \"doc\") {\n push(\"$.type\", 'Document type must be \"doc\".');\n }\n\n if (document.version !== 1) {\n push(\"$.version\", \"Document version must be 1.\");\n }\n\n if (!Array.isArray(document.content)) {\n push(\"$.content\", \"Document content must be an array.\");\n } else {\n document.content.forEach((node, index) => validateNode(node, `$.content.${index}`));\n }\n\n if (\"meta\" in document && document.meta !== undefined && !isRecord(document.meta)) {\n push(\"$.meta\", \"Document meta must be an object.\");\n }\n\n return {\n valid: issues.length === 0,\n issues,\n };\n};\n\nexport const isOpenEditorDocument = (value: unknown): value is OpenEditorDocument =>\n validateDocument(value).valid;\n\nexport const parseOpenEditorDocument = (\n value: unknown,\n defaultDocument: OpenEditorDocument = createDocument(),\n): OpenEditorDocument => {\n if (isOpenEditorDocument(value)) {\n return normalizeDocument(value);\n }\n\n if (isRecord(value) && value.type === \"doc\" && Array.isArray(value.content)) {\n return fromProseMirrorDocument(value as ProseMirrorDocument, defaultDocument.meta);\n }\n\n return defaultDocument;\n};\n\nexport const serializeEditorState = (state: SerializedEditorState): string =>\n JSON.stringify({\n document: normalizeDocument(state.document),\n ...(state.selection ? { selection: state.selection } : {}),\n });\n\nexport const parseEditorState = (\n value: unknown,\n defaultState: SerializedEditorState = createEditorState(createDocument()),\n): SerializedEditorState => {\n let parsed: unknown;\n\n try {\n parsed = typeof value === \"string\" ? JSON.parse(value) : value;\n } catch {\n return defaultState;\n }\n\n if (!isRecord(parsed)) {\n return defaultState;\n }\n\n return {\n document: parseOpenEditorDocument(parsed.document, defaultState.document),\n selection: isRecord(parsed.selection) ? (parsed.selection as EditorSelection) : defaultState.selection,\n };\n};\n\nexport const getPlatformDocument = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n platform: EditorPlatform,\n): OpenEditorDocument => getPlatformSupport(document, registry, platform).document;\n\nexport const getPlatformSupport = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n platform: EditorPlatform,\n): PlatformSupportResult => {\n const issues: PlatformSupportIssue[] = [];\n\n const mapNode = (node: OpenEditorBlock, path: string): OpenEditorBlock => {\n const spec = findBlockSpecForNode(registry, node);\n const support = spec?.support?.[platform] ?? \"supported\";\n\n if (support !== \"supported\") {\n issues.push({\n path,\n block: spec?.name ?? node.type,\n platform,\n support,\n });\n }\n\n return normalizeNode({\n ...cloneNode(node),\n content: node.content?.map((child, index) => mapNode(child, `${path}.content.${index}`)),\n });\n };\n\n return {\n platform,\n document: createDocument(\n document.content.map((node, index) => mapNode(node, `$.content.${index}`)),\n { ...document.meta, platform },\n ),\n issues,\n };\n};\n\nconst INLINE_NODE_TYPES = new Set([\"text\", \"hardBreak\"]);\n\nexport const getDocumentText = (node: OpenEditorDocument | ProseMirrorNode): string => {\n if (\"text\" in node && typeof node.text === \"string\") {\n return node.text;\n }\n\n const content = \"content\" in node ? node.content : undefined;\n\n if (!content?.length) {\n return \"\";\n }\n\n const isInlineContainer = content.every(\n (child) => INLINE_NODE_TYPES.has(child.type) || child.type === \"link\",\n );\n const joiner = isInlineContainer ? \"\" : \"\\n\";\n return content.map(getDocumentText).filter(Boolean).join(joiner);\n};\n\nexport const applyCommand = (\n document: OpenEditorDocument,\n registry: BlockRegistry,\n command: OpenEditorCommand,\n): OpenEditorDocument => {\n if (command.type === \"setContent\") {\n return normalizeDocument(command.document);\n }\n\n if (command.type === \"replaceDocument\") {\n return normalizeDocument(command.document);\n }\n\n if (command.type === \"setSelection\") {\n return document;\n }\n\n if (command.type === \"moveBlock\") {\n return moveTopLevelBlock(document, command.from, command.to);\n }\n\n if (command.type === \"duplicateBlock\") {\n return duplicateTopLevelBlock(document, command.index);\n }\n\n if (command.type === \"deleteBlock\") {\n return deleteTopLevelBlock(document, command.index);\n }\n\n if (\n command.type === \"setLink\"\n || command.type === \"toggleMark\"\n || command.type === \"undo\"\n || command.type === \"redo\"\n ) {\n return normalizeDocument(document);\n }\n\n const spec = registry.get(command.block);\n if (!spec) {\n throw new Error(`Unknown block \"${command.block}\"`);\n }\n\n const nextContent = [...document.content];\n const index = command.at ?? nextContent.length;\n const defaultNode = spec.defaultNode();\n const node = command.attrs\n ? { ...defaultNode, attrs: { ...defaultNode.attrs, ...command.attrs } }\n : defaultNode;\n\n nextContent.splice(index, 0, node);\n return normalizeDocument(createDocument(nextContent, document.meta));\n};\n\nexport const replaceTopLevelRange = (\n document: OpenEditorDocument,\n start: number,\n length: number,\n replacement: ProseMirrorNode[],\n): OpenEditorDocument =>\n normalizeDocument({\n ...document,\n content: [\n ...document.content.slice(0, start),\n ...replacement.map(cloneNode),\n ...document.content.slice(start + length),\n ],\n });\n\nexport const replaceTopLevelNode = (\n document: OpenEditorDocument,\n index: number,\n replacement: ProseMirrorNode,\n): OpenEditorDocument =>\n normalizeDocument({\n ...document,\n content: document.content.map((node, nodeIndex) => nodeIndex === index ? cloneNode(replacement) : cloneNode(node)),\n });\n\nexport const moveTopLevelBlock = (\n document: OpenEditorDocument,\n from: number,\n to: number,\n): OpenEditorDocument => {\n if (from < 0 || from >= document.content.length || to < 0 || to >= document.content.length || from === to) {\n return normalizeDocument(document);\n }\n\n const nextContent = document.content.map(cloneNode);\n const [item] = nextContent.splice(from, 1);\n if (!item) {\n return normalizeDocument(document);\n }\n\n nextContent.splice(to, 0, item);\n return normalizeDocument({ ...document, content: nextContent });\n};\n\nexport const duplicateTopLevelBlock = (\n document: OpenEditorDocument,\n index: number,\n): OpenEditorDocument => {\n if (index < 0 || index >= document.content.length) {\n return normalizeDocument(document);\n }\n\n const nextContent = document.content.map(cloneNode);\n nextContent.splice(index + 1, 0, cloneNode(document.content[index]));\n return normalizeDocument({ ...document, content: nextContent });\n};\n\nexport const deleteTopLevelBlock = (\n document: OpenEditorDocument,\n index: number,\n emptyBlock: OpenEditorBlock = textBlock(\"paragraph\", \"\"),\n): OpenEditorDocument => {\n if (document.content.length <= 1) {\n return normalizeDocument({ ...document, content: [cloneNode(emptyBlock)] });\n }\n\n if (index < 0 || index >= document.content.length) {\n return normalizeDocument(document);\n }\n\n return normalizeDocument({\n ...document,\n content: document.content.filter((_, currentIndex) => currentIndex !== index).map(cloneNode),\n });\n};\n\nexport const createTransaction = (\n before: OpenEditorDocument,\n after: OpenEditorDocument,\n command?: EditorCommand,\n): EditorTransaction => ({\n before,\n after,\n ...(command ? { command } : {}),\n timestamp: new Date().toISOString(),\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openeditor/core",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "repository": {