creo-edit 0.1.0
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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/clipboard/drop.d.ts +17 -0
- package/dist/clipboard/htmlParser.d.ts +18 -0
- package/dist/clipboard/htmlSerializer.d.ts +9 -0
- package/dist/commands/imageCommands.d.ts +32 -0
- package/dist/commands/insertCommands.d.ts +33 -0
- package/dist/commands/listCommands.d.ts +19 -0
- package/dist/commands/markCommands.d.ts +21 -0
- package/dist/commands/navigationCommands.d.ts +27 -0
- package/dist/commands/structuralCommands.d.ts +22 -0
- package/dist/commands/textCommands.d.ts +18 -0
- package/dist/controller/history.d.ts +31 -0
- package/dist/controller/navigation.d.ts +18 -0
- package/dist/controller/selection.d.ts +25 -0
- package/dist/controller/wordBoundary.d.ts +25 -0
- package/dist/createEditor.d.ts +252 -0
- package/dist/dom/anchorMap.d.ts +27 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +7833 -0
- package/dist/index.js.map +72 -0
- package/dist/input/keymap.d.ts +47 -0
- package/dist/input/mobile.d.ts +13 -0
- package/dist/input/nativeInput.d.ts +27 -0
- package/dist/markdown/serialize.d.ts +2 -0
- package/dist/model/blockText.d.ts +42 -0
- package/dist/model/cellAccess.d.ts +2 -0
- package/dist/model/doc.d.ts +45 -0
- package/dist/model/fractional.d.ts +57 -0
- package/dist/model/rebalance.d.ts +12 -0
- package/dist/model/types.d.ts +133 -0
- package/dist/plugin/anchorCodec.d.ts +18 -0
- package/dist/plugin/atomic.d.ts +2 -0
- package/dist/plugin/builtin.d.ts +10 -0
- package/dist/plugin/decorations.d.ts +35 -0
- package/dist/plugin/htmlCodec.d.ts +8 -0
- package/dist/plugin/keymapMatch.d.ts +2 -0
- package/dist/plugin/registry.d.ts +29 -0
- package/dist/plugin/runsAt.d.ts +9 -0
- package/dist/plugin/serializeCodec.d.ts +6 -0
- package/dist/plugin/triggers.d.ts +33 -0
- package/dist/plugin/types.d.ts +188 -0
- package/dist/plugins/add-block/index.d.ts +17 -0
- package/dist/plugins/calendar/index.d.ts +7 -0
- package/dist/plugins/calendar/view.d.ts +29 -0
- package/dist/plugins/cells/codecs.d.ts +6 -0
- package/dist/plugins/cells/commands.d.ts +5 -0
- package/dist/plugins/cells/controls.d.ts +3 -0
- package/dist/plugins/cells/htmlCodec.d.ts +6 -0
- package/dist/plugins/cells/index.d.ts +3 -0
- package/dist/plugins/cells/views.d.ts +27 -0
- package/dist/plugins/drag-handle/index.d.ts +6 -0
- package/dist/plugins/infinite-scroll/index.d.ts +44 -0
- package/dist/plugins/md-shortcuts/index.d.ts +2 -0
- package/dist/plugins/search/engine.d.ts +33 -0
- package/dist/plugins/search/highlight.d.ts +13 -0
- package/dist/plugins/search/index.d.ts +5 -0
- package/dist/plugins/search/navigate.d.ts +15 -0
- package/dist/plugins/search/styles.d.ts +1 -0
- package/dist/plugins/search/types.d.ts +73 -0
- package/dist/plugins/search/ui.d.ts +2 -0
- package/dist/plugins/slash/index.d.ts +12 -0
- package/dist/plugins/slash/items.d.ts +21 -0
- package/dist/plugins/slash/menu.d.ts +17 -0
- package/dist/plugins/styles.css +233 -0
- package/dist/render/DocView.d.ts +7 -0
- package/dist/render/InlineRunsView.d.ts +7 -0
- package/dist/render/blocks/CodeBlockView.d.ts +7 -0
- package/dist/render/blocks/HeadingView.d.ts +7 -0
- package/dist/render/blocks/ImageView.d.ts +8 -0
- package/dist/render/blocks/ListItemView.d.ts +7 -0
- package/dist/render/blocks/ParagraphView.d.ts +7 -0
- package/dist/virtual/VirtualDoc.d.ts +28 -0
- package/dist/virtual/heightIndex.d.ts +36 -0
- package/package.json +53 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import type { PublicView, Store } from "creo";
|
|
2
|
+
import { type SetBlockTypePayload } from "./commands/structuralCommands";
|
|
3
|
+
import { emptyDoc } from "./model/doc";
|
|
4
|
+
import type { Anchor, BlockId, BlockSpec, DistOmit, DocState, Mark, Selection } from "./model/types";
|
|
5
|
+
/**
|
|
6
|
+
* Input shape for `appendBlocks` / `prependBlocks` — same as `BlockSpec`
|
|
7
|
+
* but with `id` optional. The editor generates an id when missing so most
|
|
8
|
+
* callers can stay terse:
|
|
9
|
+
*
|
|
10
|
+
* editor.appendBlocks([{ type: "p", runs: [] }]);
|
|
11
|
+
*/
|
|
12
|
+
export type BlockInsertInput = DistOmit<BlockSpec, "id"> & {
|
|
13
|
+
id?: BlockId;
|
|
14
|
+
};
|
|
15
|
+
import { Registry } from "./plugin/registry";
|
|
16
|
+
import type { EditorPlugin } from "./plugin/types";
|
|
17
|
+
export type SerializedRun = {
|
|
18
|
+
text: string;
|
|
19
|
+
marks?: string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* SerializedBlock — wire shape the editor reads from `setDoc()` and emits
|
|
23
|
+
* from `toJSON()`. Built-in block types are listed exhaustively here so the
|
|
24
|
+
* compiler still catches typos in user code. Plugins that introduce new
|
|
25
|
+
* block types extend the runtime serialize codec registry without changing
|
|
26
|
+
* this type — their entries appear as the catch-all `Record<string, unknown>`
|
|
27
|
+
* branch.
|
|
28
|
+
*/
|
|
29
|
+
export type SerializedBlock = {
|
|
30
|
+
id?: string;
|
|
31
|
+
type: "p";
|
|
32
|
+
runs: SerializedRun[];
|
|
33
|
+
} | {
|
|
34
|
+
id?: string;
|
|
35
|
+
type: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
36
|
+
runs: SerializedRun[];
|
|
37
|
+
} | {
|
|
38
|
+
id?: string;
|
|
39
|
+
type: "li";
|
|
40
|
+
ordered: boolean;
|
|
41
|
+
depth?: 0 | 1 | 2 | 3;
|
|
42
|
+
runs: SerializedRun[];
|
|
43
|
+
} | {
|
|
44
|
+
id?: string;
|
|
45
|
+
type: "code";
|
|
46
|
+
runs: SerializedRun[];
|
|
47
|
+
lang?: string;
|
|
48
|
+
} | {
|
|
49
|
+
id?: string;
|
|
50
|
+
type: "img";
|
|
51
|
+
src: string;
|
|
52
|
+
alt?: string;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
} | {
|
|
56
|
+
id?: string;
|
|
57
|
+
type: "table";
|
|
58
|
+
rows: number;
|
|
59
|
+
cols: number;
|
|
60
|
+
cells: SerializedRun[][][];
|
|
61
|
+
} | {
|
|
62
|
+
id?: string;
|
|
63
|
+
type: "columns";
|
|
64
|
+
cols: number;
|
|
65
|
+
cells: SerializedRun[][];
|
|
66
|
+
} | {
|
|
67
|
+
id?: string;
|
|
68
|
+
type: "calendar";
|
|
69
|
+
date: string;
|
|
70
|
+
days: number;
|
|
71
|
+
} | {
|
|
72
|
+
id?: string;
|
|
73
|
+
type: "date-marker";
|
|
74
|
+
date: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Catch-all shape for plugin-introduced block types. Plugins serializing
|
|
78
|
+
* outside the built-in union should cast through this when constructing
|
|
79
|
+
* `SerializedDoc.blocks` — the runtime serialize codec registry handles
|
|
80
|
+
* dispatch by `type` and ignores extra fields.
|
|
81
|
+
*/
|
|
82
|
+
export type ExternalSerializedBlock = {
|
|
83
|
+
id?: string;
|
|
84
|
+
type: string;
|
|
85
|
+
[k: string]: unknown;
|
|
86
|
+
};
|
|
87
|
+
export type SerializedDoc = {
|
|
88
|
+
blocks: SerializedBlock[];
|
|
89
|
+
};
|
|
90
|
+
export type EditorViewProps = {
|
|
91
|
+
class?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Built-in command shape. Plugin commands dispatch through the same
|
|
95
|
+
* `dispatch()` entry point using the `{ t: string; payload?: unknown }`
|
|
96
|
+
* fallback shape — see `Editor.dispatch` below.
|
|
97
|
+
*/
|
|
98
|
+
export type Command = {
|
|
99
|
+
t: "noop";
|
|
100
|
+
} | {
|
|
101
|
+
t: "insertText";
|
|
102
|
+
text: string;
|
|
103
|
+
} | {
|
|
104
|
+
t: "deleteBackward";
|
|
105
|
+
} | {
|
|
106
|
+
t: "deleteForward";
|
|
107
|
+
} | {
|
|
108
|
+
t: "splitBlock";
|
|
109
|
+
} | {
|
|
110
|
+
t: "mergeBackward";
|
|
111
|
+
} | {
|
|
112
|
+
t: "mergeForward";
|
|
113
|
+
} | {
|
|
114
|
+
t: "setBlockType";
|
|
115
|
+
payload: SetBlockTypePayload;
|
|
116
|
+
} | {
|
|
117
|
+
t: "toggleMark";
|
|
118
|
+
mark: Mark;
|
|
119
|
+
} | {
|
|
120
|
+
t: "toggleList";
|
|
121
|
+
ordered: boolean;
|
|
122
|
+
} | {
|
|
123
|
+
t: "indentList";
|
|
124
|
+
} | {
|
|
125
|
+
t: "outdentList";
|
|
126
|
+
} | {
|
|
127
|
+
t: "insertImage";
|
|
128
|
+
src: string;
|
|
129
|
+
alt?: string;
|
|
130
|
+
width?: number;
|
|
131
|
+
height?: number;
|
|
132
|
+
} | {
|
|
133
|
+
t: "insertTable";
|
|
134
|
+
rows: number;
|
|
135
|
+
cols: number;
|
|
136
|
+
} | {
|
|
137
|
+
t: "insertColumns";
|
|
138
|
+
cols: number;
|
|
139
|
+
} | {
|
|
140
|
+
t: "tableInsertRow";
|
|
141
|
+
where: "above" | "below";
|
|
142
|
+
} | {
|
|
143
|
+
t: "tableInsertCol";
|
|
144
|
+
where: "before" | "after";
|
|
145
|
+
} | {
|
|
146
|
+
t: "tableRemoveRow";
|
|
147
|
+
} | {
|
|
148
|
+
t: "tableRemoveCol";
|
|
149
|
+
} | {
|
|
150
|
+
t: "moveCursor";
|
|
151
|
+
to: Anchor;
|
|
152
|
+
extend?: boolean;
|
|
153
|
+
};
|
|
154
|
+
/** Anything dispatchable — the typed `Command` union for built-ins, plus the
|
|
155
|
+
* open `{ t: string; payload?: unknown }` shape for plugin commands. */
|
|
156
|
+
export type DispatchableCommand = Command | {
|
|
157
|
+
t: string;
|
|
158
|
+
payload?: unknown;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Editing mode.
|
|
162
|
+
*
|
|
163
|
+
* - `"wysiwyg"`: rich-text editor with all blocks rendered visually.
|
|
164
|
+
* - `"md"`: raw markdown source view (the doc is serialized to markdown
|
|
165
|
+
* and edited as plain text); markdown-shortcut input rules also active
|
|
166
|
+
* when the user re-enters wysiwyg via mdShortcutsPlugin.
|
|
167
|
+
*
|
|
168
|
+
* Replaces the older `"regular" | "mono"` cosmetic flag — host apps that
|
|
169
|
+
* want a monospaced editor should add their own CSS class.
|
|
170
|
+
*/
|
|
171
|
+
export type EditorMode = "wysiwyg" | "md";
|
|
172
|
+
export type EditorOptions = {
|
|
173
|
+
initial?: SerializedDoc;
|
|
174
|
+
uploadImage?: (f: File) => Promise<string>;
|
|
175
|
+
/**
|
|
176
|
+
* Enable virtualized rendering — only blocks intersecting the viewport
|
|
177
|
+
* are mounted. Recommended for documents with > ~500 blocks. The host
|
|
178
|
+
* page must put a scroll container around the editor for this to work.
|
|
179
|
+
*/
|
|
180
|
+
virtualized?: boolean;
|
|
181
|
+
/** Estimated block height (px) when virtualized — default 32. */
|
|
182
|
+
virtualEstimatedHeight?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Initial editing mode — see `EditorMode`. Defaults to `"wysiwyg"`.
|
|
185
|
+
* Toggle at runtime via `editor.setMode(...)`.
|
|
186
|
+
*/
|
|
187
|
+
mode?: EditorMode;
|
|
188
|
+
/**
|
|
189
|
+
* Plugins to install in addition to the default set (paragraph, heading,
|
|
190
|
+
* list, code-block, image, cells). Registered AFTER built-ins so plugin
|
|
191
|
+
* codecs can override built-in HTML matchers by registering more specific
|
|
192
|
+
* tag matchers.
|
|
193
|
+
*/
|
|
194
|
+
plugins?: EditorPlugin[];
|
|
195
|
+
};
|
|
196
|
+
export type Editor = {
|
|
197
|
+
docStore: Store<DocState>;
|
|
198
|
+
selStore: Store<Selection>;
|
|
199
|
+
/** Dispatch any registered command — typed built-ins or plugin commands. */
|
|
200
|
+
dispatch: (cmd: DispatchableCommand) => void;
|
|
201
|
+
undo: () => void;
|
|
202
|
+
redo: () => void;
|
|
203
|
+
EditorView: PublicView<EditorViewProps, void>;
|
|
204
|
+
setDocFromHTML: (html: string) => void;
|
|
205
|
+
/**
|
|
206
|
+
* Replace the entire document with a SerializedDoc. Resets selection to
|
|
207
|
+
* the end and clears history — used for swapping content on top of a
|
|
208
|
+
* long-lived editor instance (e.g. routing between different docs in a
|
|
209
|
+
* docs site without reallocating the input pipeline & DOM listeners).
|
|
210
|
+
*/
|
|
211
|
+
setDoc: (doc: SerializedDoc) => void;
|
|
212
|
+
toJSON: () => SerializedDoc;
|
|
213
|
+
/**
|
|
214
|
+
* Append `specs` to the end of the doc. Preserves all existing block
|
|
215
|
+
* identities (no full rebuild) so existing renders stay; the renderer's
|
|
216
|
+
* identity-based shouldUpdate skips them. Returns the assigned block ids.
|
|
217
|
+
* Specs may omit `id`; an id is generated when missing. Selection is left
|
|
218
|
+
* untouched — callers move the caret separately if they want it on a new
|
|
219
|
+
* block.
|
|
220
|
+
*/
|
|
221
|
+
appendBlocks: (specs: BlockInsertInput[]) => BlockId[];
|
|
222
|
+
/**
|
|
223
|
+
* Prepend `specs` to the start of the doc. Same identity-preserving
|
|
224
|
+
* mutation as `appendBlocks`. NOTE: prepending grows the doc upward; the
|
|
225
|
+
* viewport will jump unless the host re-anchors scrollTop. The
|
|
226
|
+
* `infiniteScrollPlugin` does this anchoring automatically; manual
|
|
227
|
+
* callers can capture `scrollHeight` + `scrollTop` before the call and
|
|
228
|
+
* adjust after the next animation frame.
|
|
229
|
+
*/
|
|
230
|
+
prependBlocks: (specs: BlockInsertInput[]) => BlockId[];
|
|
231
|
+
focus: () => void;
|
|
232
|
+
blur: () => void;
|
|
233
|
+
/** Read or change the editing mode (wysiwyg ↔ md). */
|
|
234
|
+
getMode: () => EditorMode;
|
|
235
|
+
setMode: (mode: EditorMode) => void;
|
|
236
|
+
/** Plugin registry for this editor instance — exposed for advanced
|
|
237
|
+
* consumers (devtools, the M3 trigger manager, etc.). */
|
|
238
|
+
registry: Registry;
|
|
239
|
+
/**
|
|
240
|
+
* Scroll a block into view by id. Works for both virtualized and
|
|
241
|
+
* non-virtualized editors — for virtualized off-screen blocks, jumps
|
|
242
|
+
* the scroll container to the height-index-resolved Y. Used by the
|
|
243
|
+
* search plugin's jump-to-match; safe for any host code that wants
|
|
244
|
+
* to focus a specific block (e.g. permalink navigation).
|
|
245
|
+
*/
|
|
246
|
+
scrollToBlock: (blockId: BlockId, opts?: {
|
|
247
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
248
|
+
behavior?: ScrollBehavior;
|
|
249
|
+
}) => void;
|
|
250
|
+
};
|
|
251
|
+
export declare function createEditor(opts?: EditorOptions): Editor;
|
|
252
|
+
export { emptyDoc };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Anchor, BlockId } from "../model/types";
|
|
2
|
+
export type BlockKind = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "li" | "code" | "img" | "table" | "columns";
|
|
3
|
+
/**
|
|
4
|
+
* Find the OUTER block element with the given block id, scoped under `root`.
|
|
5
|
+
*
|
|
6
|
+
* Required filter: both `data-block-id` and `data-block-kind` — the latter
|
|
7
|
+
* disambiguates the block container from inner cells (table cells / column
|
|
8
|
+
* cells share the owning block's `data-block-id`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function findBlockElementById(root: HTMLElement, blockId: BlockId): HTMLElement | null;
|
|
11
|
+
/**
|
|
12
|
+
* Convert a (DOM node, offset) selection point into an editor Anchor.
|
|
13
|
+
*
|
|
14
|
+
* Returns null when the node is outside any block element (e.g. user clicked
|
|
15
|
+
* editor chrome). Coarse but never crashes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function domToAnchor(node: Node, offset: number, root: HTMLElement): Anchor | null;
|
|
18
|
+
export type DomPoint = {
|
|
19
|
+
node: Node;
|
|
20
|
+
offset: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Convert an editor Anchor into a (DOM node, offset) pair suitable for
|
|
24
|
+
* `Range.setStart` / `Selection.collapse`. Returns null when the block can't
|
|
25
|
+
* be found in the DOM (not yet rendered, virtualized off-screen, etc.).
|
|
26
|
+
*/
|
|
27
|
+
export declare function anchorToDom(anchor: Anchor, root: HTMLElement): DomPoint | null;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { createEditor } from "./createEditor";
|
|
2
|
+
export type { Editor, EditorOptions, EditorViewProps, Command, DispatchableCommand, BlockInsertInput, SerializedBlock, SerializedDoc, SerializedRun, EditorMode, } from "./createEditor";
|
|
3
|
+
export { DocView } from "./render/DocView";
|
|
4
|
+
export { ParagraphView } from "./render/blocks/ParagraphView";
|
|
5
|
+
export { HeadingView } from "./render/blocks/HeadingView";
|
|
6
|
+
export { ListItemView } from "./render/blocks/ListItemView";
|
|
7
|
+
export { CodeBlockView } from "./render/blocks/CodeBlockView";
|
|
8
|
+
export { TableViewPlugin as TableView } from "./plugins/cells/views";
|
|
9
|
+
export { ColumnsViewPlugin as ColumnsView } from "./plugins/cells/views";
|
|
10
|
+
export { ImageView } from "./render/blocks/ImageView";
|
|
11
|
+
export { InlineRunsView } from "./render/InlineRunsView";
|
|
12
|
+
export { isCoarsePointer } from "./input/mobile";
|
|
13
|
+
export { domToAnchor, anchorToDom, findBlockElementById, } from "./dom/anchorMap";
|
|
14
|
+
export { VirtualDoc } from "./virtual/VirtualDoc";
|
|
15
|
+
export { HeightIndex } from "./virtual/heightIndex";
|
|
16
|
+
export type { Block, BlockId, BlockSpec, BlockType, CodeBlock, ColumnsBlock, DistOmit, DocState, FracIndex, HeadingBlock, HeadingLevel, ImageBlock, InlineRun, ListItemBlock, Mark, ParagraphBlock, TableBlock, Anchor, Selection, } from "./model/types";
|
|
17
|
+
export { emptyDoc, docFromBlocks, insertAt, insertAfter, insertWithIndex, insertManyAt, updateBlock, removeBlock, findInsertionPos, findPos, blockAt, getBlock, iterBlocks, newBlockId, maybeRebalance, } from "./model/doc";
|
|
18
|
+
export { generateBetween, generateN, needsRebalance, rebalance, REBALANCE_THRESHOLD, } from "./model/fractional";
|
|
19
|
+
export type { EditorPlugin, BlockDef, CommandDef, KeymapDef, TriggerDef, TriggerCtx, TriggerController, DecorationDef, AnchorCodec, HtmlBlockCodec, HtmlParseCtx, SerializeCodec, RunsCtx, CommandCtx, DomPoint, } from "./plugin/types";
|
|
20
|
+
export { Registry } from "./plugin/registry";
|
|
21
|
+
export { defaultPlugins, paragraphPlugin, headingPlugin, listPlugin, codeBlockPlugin, imagePlugin, cellsPlugin, } from "./plugin/builtin";
|
|
22
|
+
export { runsAt, runsLengthAt } from "./plugin/runsAt";
|
|
23
|
+
export { atomicCodec, defaultTextCodec, codeBlockCodec, imageCodec, } from "./plugin/anchorCodec";
|
|
24
|
+
export { isAtomicBlockType, registerAtomic } from "./plugin/atomic";
|
|
25
|
+
export { TriggerManager } from "./plugin/triggers";
|
|
26
|
+
export { DecorationManager } from "./plugin/decorations";
|
|
27
|
+
export { slashCommandsPlugin, defaultSlashItems, defaultFilter as defaultSlashFilter, mountSlashMenu, type SlashItem, type MenuHandle as SlashMenuHandle, type MenuOptions as SlashMenuOptions, } from "./plugins/slash";
|
|
28
|
+
export { dragHandlePlugin, type DragHandleOptions } from "./plugins/drag-handle";
|
|
29
|
+
export { addBlockPlugin, type AddBlockOptions } from "./plugins/add-block";
|
|
30
|
+
export { mdShortcutsPlugin } from "./plugins/md-shortcuts";
|
|
31
|
+
export { calendarPlugin, calendarSlashItem, CalendarView, DateMarkerView, calendarHelpers, } from "./plugins/calendar";
|
|
32
|
+
export { infiniteScrollPlugin, type InfiniteScrollEditor, type InfiniteScrollOptions, } from "./plugins/infinite-scroll";
|
|
33
|
+
export { searchPlugin, type SearchOptions, type SearchController, type SearchSource, type SearchState, type SearchToggle, type SearchMatch, type SearchOpts, } from "./plugins/search";
|
|
34
|
+
export { docToMarkdown } from "./markdown/serialize";
|