@editora/toast 1.0.2 → 2.0.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/README.md +901 -7
- package/dist/core/AnimationUtils.d.ts +36 -0
- package/dist/core/ToastLifecycle.d.ts +25 -0
- package/dist/core/ToastManager.d.ts +36 -0
- package/dist/core/ToastQueue.d.ts +19 -0
- package/dist/core/ToastRenderer.d.ts +20 -0
- package/dist/core/ToastStore.d.ts +31 -0
- package/dist/core/types.d.ts +168 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +32 -7
- package/dist/index.esm.js +1061 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/toast.css +783 -18
- package/package.json +45 -12
- package/LICENSE +0 -21
- package/dist/index.js +0 -70
- package/dist/packages/core/src/Editor.d.ts +0 -15
- package/dist/packages/core/src/Editor.js +0 -37
- package/dist/packages/core/src/EditorState.d.ts +0 -13
- package/dist/packages/core/src/EditorState.js +0 -14
- package/dist/packages/core/src/Selection.d.ts +0 -126
- package/dist/packages/core/src/Selection.js +0 -232
- package/dist/packages/core/src/commands/CommandManager.d.ts +0 -56
- package/dist/packages/core/src/commands/CommandManager.js +0 -166
- package/dist/packages/core/src/index.d.ts +0 -7
- package/dist/packages/core/src/index.js +0 -4
- package/dist/packages/core/src/model/Fragment.d.ts +0 -80
- package/dist/packages/core/src/model/Fragment.js +0 -172
- package/dist/packages/core/src/model/Mark.d.ts +0 -108
- package/dist/packages/core/src/model/Mark.js +0 -138
- package/dist/packages/core/src/model/Node.d.ts +0 -172
- package/dist/packages/core/src/model/Node.js +0 -458
- package/dist/packages/core/src/model/types.d.ts +0 -29
- package/dist/packages/core/src/model/types.js +0 -1
- package/dist/packages/core/src/plugins/Plugin.d.ts +0 -37
- package/dist/packages/core/src/plugins/Plugin.js +0 -31
- package/dist/packages/core/src/plugins/PluginManager.d.ts +0 -75
- package/dist/packages/core/src/plugins/PluginManager.js +0 -185
- package/dist/packages/core/src/schema/Node.d.ts +0 -26
- package/dist/packages/core/src/schema/Node.js +0 -12
- package/dist/packages/core/src/schema/Schema.d.ts +0 -52
- package/dist/packages/core/src/schema/Schema.js +0 -296
- package/dist/packages/core/src/security/Sanitizer.d.ts +0 -81
- package/dist/packages/core/src/security/Sanitizer.js +0 -200
- package/dist/packages/editora-toast/src/index.d.ts +0 -18
- package/dist/packages/editora-toast/src/index.js +0 -70
- package/src/index.ts +0 -83
- package/src/toast.css +0 -42
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { Fragment } from './Fragment';
|
|
2
|
-
import { Mark, MarkType } from './Mark';
|
|
3
|
-
import { Attrs, AttributeSpec, ParseRule, DOMOutputSpec } from './types';
|
|
4
|
-
export type { Attrs, AttributeSpec, ParseRule, DOMOutputSpec };
|
|
5
|
-
/**
|
|
6
|
-
* A node in the document tree.
|
|
7
|
-
* Nodes can be either block nodes (like paragraphs, headings) or inline nodes (like text).
|
|
8
|
-
*/
|
|
9
|
-
export declare class Node {
|
|
10
|
-
readonly type: NodeType;
|
|
11
|
-
readonly attrs: Attrs;
|
|
12
|
-
readonly content: Fragment;
|
|
13
|
-
readonly marks: readonly Mark[];
|
|
14
|
-
constructor(type: NodeType, attrs?: Attrs, content?: Fragment, marks?: readonly Mark[]);
|
|
15
|
-
/**
|
|
16
|
-
* Create a node from a NodeType.
|
|
17
|
-
*/
|
|
18
|
-
static create(type: NodeType, attrs?: Attrs, content?: Fragment, marks?: readonly Mark[]): Node;
|
|
19
|
-
/**
|
|
20
|
-
* Create a text node.
|
|
21
|
-
*/
|
|
22
|
-
static text(text: string, marks?: readonly Mark[]): Node;
|
|
23
|
-
/**
|
|
24
|
-
* Create a node from JSON representation.
|
|
25
|
-
*/
|
|
26
|
-
static fromJSON(schema: any, json: any): Node;
|
|
27
|
-
/**
|
|
28
|
-
* Validate that this node conforms to its type specification.
|
|
29
|
-
*/
|
|
30
|
-
private validate;
|
|
31
|
-
/**
|
|
32
|
-
* Check if this is a block node.
|
|
33
|
-
*/
|
|
34
|
-
get isBlock(): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Check if this is an inline node.
|
|
37
|
-
*/
|
|
38
|
-
get isInline(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Check if this is a text node.
|
|
41
|
-
*/
|
|
42
|
-
get isText(): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Check if this is a leaf node (has no content).
|
|
45
|
-
*/
|
|
46
|
-
get isLeaf(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Replace content in a range with new content.
|
|
49
|
-
*/
|
|
50
|
-
replace(from: number, to: number, replacement: Fragment): Node;
|
|
51
|
-
/**
|
|
52
|
-
* Get the text content of the entire document.
|
|
53
|
-
*/
|
|
54
|
-
get textContent(): string;
|
|
55
|
-
/**
|
|
56
|
-
* Get the size of this node in the document.
|
|
57
|
-
*/
|
|
58
|
-
get nodeSize(): number;
|
|
59
|
-
/**
|
|
60
|
-
* Create a new node with different attributes.
|
|
61
|
-
*/
|
|
62
|
-
withAttrs(attrs: Attrs): Node;
|
|
63
|
-
/**
|
|
64
|
-
* Create a new node with different content.
|
|
65
|
-
*/
|
|
66
|
-
withContent(content: Fragment): Node;
|
|
67
|
-
/**
|
|
68
|
-
* Create a new node with different marks.
|
|
69
|
-
*/
|
|
70
|
-
withMarks(marks: readonly Mark[]): Node;
|
|
71
|
-
/**
|
|
72
|
-
* Create a new text node with different text.
|
|
73
|
-
*/
|
|
74
|
-
withText(text: string): Node;
|
|
75
|
-
/**
|
|
76
|
-
* Create a slice of this node's content.
|
|
77
|
-
*/
|
|
78
|
-
slice(from: number, to?: number): Fragment;
|
|
79
|
-
/**
|
|
80
|
-
* Cut out a slice of this node.
|
|
81
|
-
*/
|
|
82
|
-
cut(from: number, to?: number): Node | null;
|
|
83
|
-
/**
|
|
84
|
-
* Get the node at a specific position within this node.
|
|
85
|
-
*/
|
|
86
|
-
nodeAt(pos: number): Node | null;
|
|
87
|
-
/**
|
|
88
|
-
* Iterate over nodes between two positions.
|
|
89
|
-
*/
|
|
90
|
-
nodesBetween(from: number, to: number, callback: (node: Node, pos: number, parent: Node | null) => void | boolean, startPos?: number): void;
|
|
91
|
-
/**
|
|
92
|
-
* Check if this node has a mark in the given range.
|
|
93
|
-
*/
|
|
94
|
-
rangeHasMark(from: number, to: number, markType: MarkType): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Remove a mark from a range in this node.
|
|
97
|
-
*/
|
|
98
|
-
removeMark(from: number, to: number, markType: MarkType): Node;
|
|
99
|
-
/**
|
|
100
|
-
* Add a mark to a range in this node.
|
|
101
|
-
*/
|
|
102
|
-
addMark(from: number, to: number, mark: Mark): Node;
|
|
103
|
-
/**
|
|
104
|
-
* Check if this node can be joined with another node.
|
|
105
|
-
*/
|
|
106
|
-
canJoin(other: Node): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Join this node with another compatible node.
|
|
109
|
-
*/
|
|
110
|
-
join(other: Node): Node;
|
|
111
|
-
/**
|
|
112
|
-
* Check if this node equals another node.
|
|
113
|
-
*/
|
|
114
|
-
equals(other: Node): boolean;
|
|
115
|
-
/**
|
|
116
|
-
* Check if attributes are equal.
|
|
117
|
-
*/
|
|
118
|
-
private attrsEqual;
|
|
119
|
-
/**
|
|
120
|
-
* Convert to JSON representation.
|
|
121
|
-
*/
|
|
122
|
-
toJSON(): any;
|
|
123
|
-
/**
|
|
124
|
-
* Create a string representation for debugging.
|
|
125
|
-
*/
|
|
126
|
-
toString(): string;
|
|
127
|
-
private static schema;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Node type definition with specifications.
|
|
131
|
-
*/
|
|
132
|
-
export declare class NodeType {
|
|
133
|
-
readonly name: string;
|
|
134
|
-
readonly spec: NodeSpec;
|
|
135
|
-
readonly schema: any;
|
|
136
|
-
constructor(name: string, spec: NodeSpec, schema: any);
|
|
137
|
-
/**
|
|
138
|
-
* Check if this is a block node type.
|
|
139
|
-
*/
|
|
140
|
-
get isBlock(): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Check if this is an inline node type.
|
|
143
|
-
*/
|
|
144
|
-
get isInline(): boolean;
|
|
145
|
-
/**
|
|
146
|
-
* Check if this is a text node type.
|
|
147
|
-
*/
|
|
148
|
-
get isText(): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Create a node of this type.
|
|
151
|
-
*/
|
|
152
|
-
create(attrs?: Attrs, content?: Fragment, marks?: readonly Mark[]): Node;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Specification for a node type.
|
|
156
|
-
*/
|
|
157
|
-
export interface NodeSpec {
|
|
158
|
-
content?: string;
|
|
159
|
-
attrs?: {
|
|
160
|
-
[key: string]: AttributeSpec;
|
|
161
|
-
};
|
|
162
|
-
group?: string;
|
|
163
|
-
inline?: boolean;
|
|
164
|
-
isText?: boolean;
|
|
165
|
-
selectable?: boolean;
|
|
166
|
-
draggable?: boolean;
|
|
167
|
-
code?: boolean;
|
|
168
|
-
whitespace?: 'pre' | 'normal';
|
|
169
|
-
defining?: boolean;
|
|
170
|
-
parseDOM?: ParseRule[];
|
|
171
|
-
toDOM?: (node: Node) => DOMOutputSpec;
|
|
172
|
-
}
|
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
import { Fragment } from './Fragment';
|
|
2
|
-
import { Mark } from './Mark';
|
|
3
|
-
/**
|
|
4
|
-
* A node in the document tree.
|
|
5
|
-
* Nodes can be either block nodes (like paragraphs, headings) or inline nodes (like text).
|
|
6
|
-
*/
|
|
7
|
-
export class Node {
|
|
8
|
-
constructor(type, attrs = {}, content, marks = []) {
|
|
9
|
-
this.type = type;
|
|
10
|
-
this.attrs = attrs;
|
|
11
|
-
this.content = content || Fragment.from([]);
|
|
12
|
-
this.marks = marks;
|
|
13
|
-
// Validate node structure
|
|
14
|
-
this.validate();
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create a node from a NodeType.
|
|
18
|
-
*/
|
|
19
|
-
static create(type, attrs = {}, content, marks = []) {
|
|
20
|
-
return new Node(type, attrs, content, marks);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a text node.
|
|
24
|
-
*/
|
|
25
|
-
static text(text, marks = []) {
|
|
26
|
-
// This requires access to schema, so we'll create a simple implementation
|
|
27
|
-
const textNode = new Node({ name: 'text', isText: true }, // Simplified NodeType
|
|
28
|
-
{ text }, undefined, marks);
|
|
29
|
-
return textNode;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Create a node from JSON representation.
|
|
33
|
-
*/
|
|
34
|
-
static fromJSON(schema, json) {
|
|
35
|
-
const type = schema.nodes[json.type];
|
|
36
|
-
if (!type) {
|
|
37
|
-
throw new Error(`Unknown node type: ${json.type}`);
|
|
38
|
-
}
|
|
39
|
-
const attrs = json.attrs || {};
|
|
40
|
-
const content = json.content ? Fragment.fromJSON(schema, json.content) : undefined;
|
|
41
|
-
const marks = (json.marks || []).map((markJSON) => Mark.fromJSON(schema, markJSON));
|
|
42
|
-
return new Node(type, attrs, content, marks);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Validate that this node conforms to its type specification.
|
|
46
|
-
*/
|
|
47
|
-
validate() {
|
|
48
|
-
var _a;
|
|
49
|
-
// Basic validation - more comprehensive validation would be implemented
|
|
50
|
-
if (this.type.isBlock && this.content.size === 0 && !((_a = this.type.spec.content) === null || _a === void 0 ? void 0 : _a.includes('empty'))) {
|
|
51
|
-
// Allow empty blocks for now
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Check if this is a block node.
|
|
56
|
-
*/
|
|
57
|
-
get isBlock() {
|
|
58
|
-
return this.type.isBlock;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Check if this is an inline node.
|
|
62
|
-
*/
|
|
63
|
-
get isInline() {
|
|
64
|
-
return this.type.isInline;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if this is a text node.
|
|
68
|
-
*/
|
|
69
|
-
get isText() {
|
|
70
|
-
return this.type.isText;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if this is a leaf node (has no content).
|
|
74
|
-
*/
|
|
75
|
-
get isLeaf() {
|
|
76
|
-
return this.content.childCount === 0;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Replace content in a range with new content.
|
|
80
|
-
*/
|
|
81
|
-
replace(from, to, replacement) {
|
|
82
|
-
if (this.isText) {
|
|
83
|
-
const text = this.attrs.text || '';
|
|
84
|
-
const before = text.slice(0, from);
|
|
85
|
-
const after = text.slice(to);
|
|
86
|
-
const newText = before + replacement.textContent + after;
|
|
87
|
-
return this.withText(newText);
|
|
88
|
-
}
|
|
89
|
-
const newContent = this.content.replace(from, to, replacement);
|
|
90
|
-
return this.withContent(newContent);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get the text content of the entire document.
|
|
94
|
-
*/
|
|
95
|
-
get textContent() {
|
|
96
|
-
if (this.isText) {
|
|
97
|
-
return this.attrs.text || '';
|
|
98
|
-
}
|
|
99
|
-
let text = '';
|
|
100
|
-
this.content.children.forEach(child => {
|
|
101
|
-
text += child.textContent;
|
|
102
|
-
});
|
|
103
|
-
return text;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the size of this node in the document.
|
|
107
|
-
*/
|
|
108
|
-
get nodeSize() {
|
|
109
|
-
if (this.isText) {
|
|
110
|
-
return (this.attrs.text || '').length;
|
|
111
|
-
}
|
|
112
|
-
return 1 + this.content.size;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Create a new node with different attributes.
|
|
116
|
-
*/
|
|
117
|
-
withAttrs(attrs) {
|
|
118
|
-
return new Node(this.type, Object.assign(Object.assign({}, this.attrs), attrs), this.content, this.marks);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create a new node with different content.
|
|
122
|
-
*/
|
|
123
|
-
withContent(content) {
|
|
124
|
-
return new Node(this.type, this.attrs, content, this.marks);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Create a new node with different marks.
|
|
128
|
-
*/
|
|
129
|
-
withMarks(marks) {
|
|
130
|
-
return new Node(this.type, this.attrs, this.content, marks);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Create a new text node with different text.
|
|
134
|
-
*/
|
|
135
|
-
withText(text) {
|
|
136
|
-
if (!this.isText) {
|
|
137
|
-
throw new Error('Can only set text on text nodes');
|
|
138
|
-
}
|
|
139
|
-
return new Node(this.type, Object.assign(Object.assign({}, this.attrs), { text }), this.content, this.marks);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Create a slice of this node's content.
|
|
143
|
-
*/
|
|
144
|
-
slice(from, to) {
|
|
145
|
-
// For text nodes, return a fragment with the sliced text
|
|
146
|
-
if (this.isText) {
|
|
147
|
-
const text = this.attrs.text || '';
|
|
148
|
-
const actualTo = to !== null && to !== void 0 ? to : text.length;
|
|
149
|
-
const slicedText = text.slice(from, actualTo);
|
|
150
|
-
if (slicedText) {
|
|
151
|
-
return Fragment.from([this.withText(slicedText)]);
|
|
152
|
-
}
|
|
153
|
-
return Fragment.from([]);
|
|
154
|
-
}
|
|
155
|
-
// For complex nodes, this would need more sophisticated slicing
|
|
156
|
-
// For now, return the entire content
|
|
157
|
-
return this.content;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Cut out a slice of this node.
|
|
161
|
-
*/
|
|
162
|
-
cut(from, to) {
|
|
163
|
-
if (this.isText) {
|
|
164
|
-
const text = this.attrs.text || '';
|
|
165
|
-
const actualTo = to !== null && to !== void 0 ? to : text.length;
|
|
166
|
-
if (from === 0 && actualTo === text.length) {
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
const cutText = text.slice(from, actualTo);
|
|
170
|
-
return cutText ? this.withText(cutText) : null;
|
|
171
|
-
}
|
|
172
|
-
// For non-text nodes, cutting is more complex
|
|
173
|
-
// This is a simplified implementation
|
|
174
|
-
if (from === 0 && (to === undefined || to >= this.nodeSize)) {
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
// For now, return null for partial cuts of complex nodes
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Get the node at a specific position within this node.
|
|
182
|
-
*/
|
|
183
|
-
nodeAt(pos) {
|
|
184
|
-
if (pos === 0) {
|
|
185
|
-
return this;
|
|
186
|
-
}
|
|
187
|
-
if (this.isText) {
|
|
188
|
-
return pos <= (this.attrs.text || '').length ? this : null;
|
|
189
|
-
}
|
|
190
|
-
const child = this.content.findChildAt(pos - 1);
|
|
191
|
-
if (child) {
|
|
192
|
-
return child.node.nodeAt(pos - 1 - child.offset);
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Iterate over nodes between two positions.
|
|
198
|
-
*/
|
|
199
|
-
nodesBetween(from, to, callback, startPos = 0) {
|
|
200
|
-
if (this.isText) {
|
|
201
|
-
callback(this, startPos, null);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
let pos = startPos;
|
|
205
|
-
this.content.children.forEach((child, index) => {
|
|
206
|
-
const childStart = pos + 1;
|
|
207
|
-
const childEnd = childStart + child.nodeSize;
|
|
208
|
-
if (childEnd > from && childStart < to) {
|
|
209
|
-
const result = callback(child, childStart, this);
|
|
210
|
-
if (result !== false && !child.isText) {
|
|
211
|
-
child.nodesBetween(Math.max(0, from - childStart), Math.min(child.nodeSize, to - childStart), callback, childStart);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
pos = childEnd;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Check if this node has a mark in the given range.
|
|
219
|
-
*/
|
|
220
|
-
rangeHasMark(from, to, markType) {
|
|
221
|
-
if (this.isText) {
|
|
222
|
-
return this.marks.some(mark => mark.type === markType);
|
|
223
|
-
}
|
|
224
|
-
// Check if ALL text nodes in the range have the mark
|
|
225
|
-
let hasAnyText = false;
|
|
226
|
-
let allHaveMark = true;
|
|
227
|
-
let pos = 1;
|
|
228
|
-
for (const child of this.content.children) {
|
|
229
|
-
const childStart = pos;
|
|
230
|
-
const childEnd = pos + child.nodeSize;
|
|
231
|
-
if (child.isText && childEnd > from && childStart < to) {
|
|
232
|
-
hasAnyText = true;
|
|
233
|
-
if (!child.marks.some(mark => mark.type === markType)) {
|
|
234
|
-
allHaveMark = false;
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else if (!child.isText && childEnd > from && childStart < to) {
|
|
239
|
-
const childHasMark = child.rangeHasMark(Math.max(0, from - childStart), Math.min(child.nodeSize, to - childStart), markType);
|
|
240
|
-
if (childHasMark) {
|
|
241
|
-
hasAnyText = true;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
allHaveMark = false;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
pos = childEnd;
|
|
249
|
-
}
|
|
250
|
-
return hasAnyText && allHaveMark;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Remove a mark from a range in this node.
|
|
254
|
-
*/
|
|
255
|
-
removeMark(from, to, markType) {
|
|
256
|
-
if (this.isText) {
|
|
257
|
-
const newMarks = this.marks.filter(mark => mark.type !== markType);
|
|
258
|
-
return this.withMarks(newMarks);
|
|
259
|
-
}
|
|
260
|
-
const newChildren = [];
|
|
261
|
-
let pos = 1;
|
|
262
|
-
this.content.children.forEach(child => {
|
|
263
|
-
const childStart = pos;
|
|
264
|
-
const childEnd = pos + child.nodeSize;
|
|
265
|
-
if (child.isText && childEnd > from && childStart < to) {
|
|
266
|
-
const text = child.attrs.text || '';
|
|
267
|
-
const textStart = Math.max(0, from - childStart);
|
|
268
|
-
const textEnd = Math.min(text.length, to - childStart + 1);
|
|
269
|
-
if (textStart > 0) {
|
|
270
|
-
newChildren.push(child.withText(text.slice(0, textStart)));
|
|
271
|
-
}
|
|
272
|
-
const selectedText = text.slice(textStart, textEnd);
|
|
273
|
-
if (selectedText) {
|
|
274
|
-
const unmarkedNode = child.withText(selectedText).withMarks(child.marks.filter(mark => mark.type !== markType));
|
|
275
|
-
newChildren.push(unmarkedNode);
|
|
276
|
-
}
|
|
277
|
-
if (textEnd < text.length) {
|
|
278
|
-
newChildren.push(child.withText(text.slice(textEnd)));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else if (!child.isText && childEnd > from && childStart < to) {
|
|
282
|
-
newChildren.push(child.removeMark(Math.max(0, from - childStart), Math.min(child.nodeSize, to - childStart), markType));
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
newChildren.push(child);
|
|
286
|
-
}
|
|
287
|
-
pos = childEnd;
|
|
288
|
-
});
|
|
289
|
-
return this.withContent(Fragment.from(newChildren));
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Add a mark to a range in this node.
|
|
293
|
-
*/
|
|
294
|
-
addMark(from, to, mark) {
|
|
295
|
-
if (this.isText) {
|
|
296
|
-
const newMarks = mark.addToSet(this.marks);
|
|
297
|
-
return this.withMarks(newMarks);
|
|
298
|
-
}
|
|
299
|
-
const newChildren = [];
|
|
300
|
-
let pos = 1;
|
|
301
|
-
this.content.children.forEach((child, idx) => {
|
|
302
|
-
const childStart = pos;
|
|
303
|
-
const childEnd = pos + child.nodeSize;
|
|
304
|
-
if (child.isText && childEnd > from && childStart < to) {
|
|
305
|
-
const text = child.attrs.text || '';
|
|
306
|
-
const textStart = Math.max(0, from - childStart);
|
|
307
|
-
const textEnd = Math.min(text.length, to - childStart + 1);
|
|
308
|
-
if (textStart > 0) {
|
|
309
|
-
newChildren.push(child.withText(text.slice(0, textStart)));
|
|
310
|
-
}
|
|
311
|
-
const selectedText = text.slice(textStart, textEnd);
|
|
312
|
-
if (selectedText) {
|
|
313
|
-
const markedNode = child.withText(selectedText).withMarks(mark.addToSet(child.marks));
|
|
314
|
-
newChildren.push(markedNode);
|
|
315
|
-
}
|
|
316
|
-
if (textEnd < text.length) {
|
|
317
|
-
newChildren.push(child.withText(text.slice(textEnd)));
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else if (!child.isText && childEnd > from && childStart < to) {
|
|
321
|
-
newChildren.push(child.addMark(Math.max(0, from - childStart), Math.min(child.nodeSize, to - childStart), mark));
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
newChildren.push(child);
|
|
325
|
-
}
|
|
326
|
-
pos = childEnd;
|
|
327
|
-
});
|
|
328
|
-
return this.withContent(Fragment.from(newChildren));
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Check if this node can be joined with another node.
|
|
332
|
-
*/
|
|
333
|
-
canJoin(other) {
|
|
334
|
-
return this.type === other.type && this.type.spec.content === other.type.spec.content;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Join this node with another compatible node.
|
|
338
|
-
*/
|
|
339
|
-
join(other) {
|
|
340
|
-
if (!this.canJoin(other)) {
|
|
341
|
-
throw new Error('Cannot join incompatible nodes');
|
|
342
|
-
}
|
|
343
|
-
if (this.isText && other.isText) {
|
|
344
|
-
return this.withText(this.textContent + other.textContent);
|
|
345
|
-
}
|
|
346
|
-
return this.withContent(this.content.appendFragment(other.content));
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Check if this node equals another node.
|
|
350
|
-
*/
|
|
351
|
-
equals(other) {
|
|
352
|
-
if (this.type !== other.type) {
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
if (!this.attrsEqual(other.attrs)) {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
if (!this.content.equals(other.content)) {
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
if (this.marks.length !== other.marks.length) {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
for (let i = 0; i < this.marks.length; i++) {
|
|
365
|
-
if (!this.marks[i].equals(other.marks[i])) {
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Check if attributes are equal.
|
|
373
|
-
*/
|
|
374
|
-
attrsEqual(otherAttrs) {
|
|
375
|
-
const keys1 = Object.keys(this.attrs);
|
|
376
|
-
const keys2 = Object.keys(otherAttrs);
|
|
377
|
-
if (keys1.length !== keys2.length) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
for (const key of keys1) {
|
|
381
|
-
if (this.attrs[key] !== otherAttrs[key]) {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return true;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Convert to JSON representation.
|
|
389
|
-
*/
|
|
390
|
-
toJSON() {
|
|
391
|
-
const result = {
|
|
392
|
-
type: this.type.name,
|
|
393
|
-
};
|
|
394
|
-
if (Object.keys(this.attrs).length > 0) {
|
|
395
|
-
result.attrs = this.attrs;
|
|
396
|
-
}
|
|
397
|
-
if (!this.content.equals(Fragment.from([]))) {
|
|
398
|
-
result.content = this.content.toJSON();
|
|
399
|
-
}
|
|
400
|
-
if (this.marks.length > 0) {
|
|
401
|
-
result.marks = this.marks.map(mark => mark.toJSON());
|
|
402
|
-
}
|
|
403
|
-
return result;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Create a string representation for debugging.
|
|
407
|
-
*/
|
|
408
|
-
toString() {
|
|
409
|
-
if (this.isText) {
|
|
410
|
-
return this.attrs.text || '';
|
|
411
|
-
}
|
|
412
|
-
const attrs = Object.keys(this.attrs).length > 0
|
|
413
|
-
? `(${Object.entries(this.attrs).map(([k, v]) => `${k}=${v}`).join(', ')})`
|
|
414
|
-
: '';
|
|
415
|
-
if (this.isLeaf) {
|
|
416
|
-
return `<${this.type.name}${attrs} />`;
|
|
417
|
-
}
|
|
418
|
-
const content = this.content.toString();
|
|
419
|
-
return `<${this.type.name}${attrs}>${content}</${this.type.name}>`;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
// Placeholder for schema - will be set by the schema system
|
|
423
|
-
Node.schema = null;
|
|
424
|
-
/**
|
|
425
|
-
* Node type definition with specifications.
|
|
426
|
-
*/
|
|
427
|
-
export class NodeType {
|
|
428
|
-
constructor(name, spec, schema) {
|
|
429
|
-
this.name = name;
|
|
430
|
-
this.spec = spec;
|
|
431
|
-
this.schema = schema;
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Check if this is a block node type.
|
|
435
|
-
*/
|
|
436
|
-
get isBlock() {
|
|
437
|
-
return !this.spec.inline && !this.spec.isText;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Check if this is an inline node type.
|
|
441
|
-
*/
|
|
442
|
-
get isInline() {
|
|
443
|
-
return !!this.spec.inline;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Check if this is a text node type.
|
|
447
|
-
*/
|
|
448
|
-
get isText() {
|
|
449
|
-
return !!this.spec.isText;
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Create a node of this type.
|
|
453
|
-
*/
|
|
454
|
-
create(attrs = {}, content, marks = []) {
|
|
455
|
-
return Node.create(this, attrs, content, marks);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
// Types are imported from types.ts
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Attributes for nodes and marks.
|
|
3
|
-
*/
|
|
4
|
-
export type Attrs = {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Specification for a node or mark attribute.
|
|
9
|
-
*/
|
|
10
|
-
export interface AttributeSpec {
|
|
11
|
-
default?: any;
|
|
12
|
-
validate?: (value: any) => boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Parse rule for DOM parsing.
|
|
16
|
-
*/
|
|
17
|
-
export interface ParseRule {
|
|
18
|
-
tag?: string;
|
|
19
|
-
style?: string;
|
|
20
|
-
attrs?: {
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
};
|
|
23
|
-
getAttrs?: (node: HTMLElement | string) => any | null;
|
|
24
|
-
clearMark?: (mark: any) => boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* DOM output specification.
|
|
28
|
-
*/
|
|
29
|
-
export type DOMOutputSpec = string | [string, ...any[]];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Schema, NodeSpec } from '../schema/Node';
|
|
2
|
-
import { EditorState } from '../EditorState';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
export interface ToolbarItem {
|
|
5
|
-
label: string;
|
|
6
|
-
command: string;
|
|
7
|
-
icon?: string;
|
|
8
|
-
type?: 'button' | 'dropdown' | 'input' | 'inline-menu';
|
|
9
|
-
options?: Array<{
|
|
10
|
-
label: string;
|
|
11
|
-
value: string;
|
|
12
|
-
}>;
|
|
13
|
-
placeholder?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface PluginContext {
|
|
16
|
-
provider?: React.FC<{
|
|
17
|
-
children: React.ReactNode;
|
|
18
|
-
}>;
|
|
19
|
-
initialize?: () => void;
|
|
20
|
-
destroy?: () => void;
|
|
21
|
-
onEditorReady?: (editor: any) => void;
|
|
22
|
-
}
|
|
23
|
-
export interface Plugin {
|
|
24
|
-
name: string;
|
|
25
|
-
nodes?: Record<string, NodeSpec>;
|
|
26
|
-
marks?: Record<string, NodeSpec>;
|
|
27
|
-
commands?: Record<string, (state: EditorState) => EditorState | null>;
|
|
28
|
-
toolbar?: ToolbarItem[];
|
|
29
|
-
context?: PluginContext;
|
|
30
|
-
}
|
|
31
|
-
export declare class PluginManager {
|
|
32
|
-
plugins: Plugin[];
|
|
33
|
-
register(plugin: Plugin): void;
|
|
34
|
-
buildSchema(): Schema;
|
|
35
|
-
getCommands(): Record<string, (state: EditorState) => EditorState | null>;
|
|
36
|
-
getToolbarItems(): ToolbarItem[];
|
|
37
|
-
}
|