@coze-editor/preset-chat 0.1.0-alpha.1e5e87
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/dist/esm/index.js +589 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +613 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 coze-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import universalPreset from "@coze-editor/preset-universal";
|
|
3
|
+
import { extension as extension2 } from "@coze-editor/core";
|
|
4
|
+
import { EditorView as EditorView3, keymap } from "@codemirror/view";
|
|
5
|
+
import { defaultKeymap, historyKeymap, history } from "@codemirror/commands";
|
|
6
|
+
|
|
7
|
+
// src/utils.ts
|
|
8
|
+
function extractElementData(node, text) {
|
|
9
|
+
const openTag = node.firstChild;
|
|
10
|
+
let tagName = null;
|
|
11
|
+
const attributes = {};
|
|
12
|
+
if (openTag && openTag.name === "OpenTag" && openTag.firstChild) {
|
|
13
|
+
let sibling = openTag.firstChild.nextSibling;
|
|
14
|
+
while (true) {
|
|
15
|
+
if (!sibling) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
if (sibling.name === "TagName") {
|
|
19
|
+
const { from, to } = sibling;
|
|
20
|
+
tagName = text.slice(from, to);
|
|
21
|
+
} else if (sibling.name === "Attribute") {
|
|
22
|
+
const nameNode = sibling.firstChild;
|
|
23
|
+
const isNode = nameNode == null ? void 0 : nameNode.nextSibling;
|
|
24
|
+
const valueNode = isNode == null ? void 0 : isNode.nextSibling;
|
|
25
|
+
if ((nameNode == null ? void 0 : nameNode.name) === "AttributeName" && (isNode == null ? void 0 : isNode.name) === "Is" && ((valueNode == null ? void 0 : valueNode.name) === "AttributeValue" || (valueNode == null ? void 0 : valueNode.name) === "UnquotedAttributeValue")) {
|
|
26
|
+
const name = text.slice(nameNode.from, nameNode.to);
|
|
27
|
+
const value = text.slice(valueNode.from, valueNode.to);
|
|
28
|
+
if (valueNode.name === "AttributeValue") {
|
|
29
|
+
attributes[name] = decodeURIComponent(value.slice(1, -1));
|
|
30
|
+
} else {
|
|
31
|
+
try {
|
|
32
|
+
attributes[name] = JSON.parse(decodeURIComponent(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else if ((nameNode == null ? void 0 : nameNode.name) === "AttributeName" && !isNode && !valueNode) {
|
|
37
|
+
const name = text.slice(nameNode.from, nameNode.to);
|
|
38
|
+
attributes[name] = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
sibling = sibling.nextSibling;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (tagName) {
|
|
45
|
+
return {
|
|
46
|
+
tagName,
|
|
47
|
+
attributes
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/language.ts
|
|
53
|
+
import { parser } from "@lezer/html";
|
|
54
|
+
import { LRLanguage } from "@codemirror/language";
|
|
55
|
+
var htmlParser = parser.configure({
|
|
56
|
+
dialect: "noMatch"
|
|
57
|
+
});
|
|
58
|
+
function parse(text) {
|
|
59
|
+
return htmlParser.parse(text);
|
|
60
|
+
}
|
|
61
|
+
var htmlLanguage = LRLanguage.define({
|
|
62
|
+
parser: htmlParser
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// src/schema.ts
|
|
66
|
+
var schemaUtils = {
|
|
67
|
+
toJSON(text) {
|
|
68
|
+
const tree = parse(text);
|
|
69
|
+
const tags = [];
|
|
70
|
+
tree.iterate({
|
|
71
|
+
enter(node) {
|
|
72
|
+
if (node.name === "Element" && node.matchContext(["Document"])) {
|
|
73
|
+
const data = extractElementData(node.node, text);
|
|
74
|
+
if (data) {
|
|
75
|
+
tags.push({
|
|
76
|
+
from: node.from,
|
|
77
|
+
to: node.to,
|
|
78
|
+
raw: text.slice(node.from, node.to),
|
|
79
|
+
...data
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
let pos = 0;
|
|
86
|
+
const elements = [];
|
|
87
|
+
for (const tag of tags) {
|
|
88
|
+
const { from, to, tagName, attributes, raw } = tag;
|
|
89
|
+
const { cmid, ...restAttributes } = attributes ?? {};
|
|
90
|
+
if (from < pos) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (from > pos) {
|
|
94
|
+
elements.push({
|
|
95
|
+
type: "text",
|
|
96
|
+
value: text.slice(pos, from)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
elements.push({
|
|
100
|
+
type: "element",
|
|
101
|
+
tagName,
|
|
102
|
+
attributes: restAttributes,
|
|
103
|
+
raw
|
|
104
|
+
});
|
|
105
|
+
pos = to;
|
|
106
|
+
}
|
|
107
|
+
if (pos < text.length) {
|
|
108
|
+
elements.push({
|
|
109
|
+
type: "text",
|
|
110
|
+
value: text.slice(pos)
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return elements;
|
|
114
|
+
},
|
|
115
|
+
fromJSON(elements) {
|
|
116
|
+
return elements.map((el) => {
|
|
117
|
+
if (el.type === "element") {
|
|
118
|
+
return toElementString(el);
|
|
119
|
+
} else if (el.type === "text") {
|
|
120
|
+
return el.value;
|
|
121
|
+
}
|
|
122
|
+
return "";
|
|
123
|
+
}).join("");
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function toElementString(element) {
|
|
127
|
+
const attrsString = attributesToString(element.attributes);
|
|
128
|
+
return `<${element.tagName}${attrsString ? ` ${attrsString}` : ""}></${element.tagName}>`;
|
|
129
|
+
}
|
|
130
|
+
var INTERNAL_ID = "cmid";
|
|
131
|
+
function uniqueId() {
|
|
132
|
+
return `e${Math.random()}`;
|
|
133
|
+
}
|
|
134
|
+
function attributesToString(attributes) {
|
|
135
|
+
const array = [];
|
|
136
|
+
let hasId = false;
|
|
137
|
+
Object.keys(attributes).forEach((key) => {
|
|
138
|
+
if (key === INTERNAL_ID) {
|
|
139
|
+
hasId = true;
|
|
140
|
+
}
|
|
141
|
+
const value = attributes[key];
|
|
142
|
+
if (value === true) {
|
|
143
|
+
array.push(key);
|
|
144
|
+
} else {
|
|
145
|
+
array.push(`${key}=${JSON.stringify(encodeURIComponent(value))}`);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (!hasId) {
|
|
149
|
+
array.unshift(`${INTERNAL_ID}="${uniqueId()}"`);
|
|
150
|
+
}
|
|
151
|
+
return array.join(" ");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/plugins.ts
|
|
155
|
+
import { api, extension, option } from "@coze-editor/core";
|
|
156
|
+
import { EditorView as EditorView2 } from "@codemirror/view";
|
|
157
|
+
import { EditorSelection as EditorSelection2, StateEffect, StateField as StateField2 } from "@codemirror/state";
|
|
158
|
+
|
|
159
|
+
// src/extension.ts
|
|
160
|
+
import { createPortal, flushSync } from "react-dom";
|
|
161
|
+
import { createElement } from "react";
|
|
162
|
+
import { createRoot } from "react-dom/client";
|
|
163
|
+
import { FacetCombineStrategy } from "@coze-editor/utils";
|
|
164
|
+
import { connector } from "@coze-editor/react";
|
|
165
|
+
import {
|
|
166
|
+
Decoration,
|
|
167
|
+
EditorView,
|
|
168
|
+
WidgetType
|
|
169
|
+
} from "@codemirror/view";
|
|
170
|
+
import {
|
|
171
|
+
EditorSelection,
|
|
172
|
+
Facet,
|
|
173
|
+
RangeSetBuilder,
|
|
174
|
+
StateField
|
|
175
|
+
} from "@codemirror/state";
|
|
176
|
+
import { syntaxTree } from "@codemirror/language";
|
|
177
|
+
|
|
178
|
+
// src/context.tsx
|
|
179
|
+
import React, { createContext, useContext } from "react";
|
|
180
|
+
var Context = createContext("");
|
|
181
|
+
function ElementProvider({
|
|
182
|
+
internalId,
|
|
183
|
+
children
|
|
184
|
+
}) {
|
|
185
|
+
return /* @__PURE__ */ React.createElement(Context.Provider, { value: internalId }, children);
|
|
186
|
+
}
|
|
187
|
+
function useElementId() {
|
|
188
|
+
const id = useContext(Context);
|
|
189
|
+
return id;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/extension.ts
|
|
193
|
+
var ElementWidget = class extends WidgetType {
|
|
194
|
+
constructor(definition, id, props) {
|
|
195
|
+
super();
|
|
196
|
+
this.definition = definition;
|
|
197
|
+
this.id = id;
|
|
198
|
+
this.props = props;
|
|
199
|
+
const element = document.createElement("span");
|
|
200
|
+
this.element = element;
|
|
201
|
+
this.root = createRoot(element);
|
|
202
|
+
}
|
|
203
|
+
$$type = "element";
|
|
204
|
+
root;
|
|
205
|
+
element;
|
|
206
|
+
view = null;
|
|
207
|
+
get elementId() {
|
|
208
|
+
return `element-${this.id}`;
|
|
209
|
+
}
|
|
210
|
+
toDOM(view) {
|
|
211
|
+
this.view = view;
|
|
212
|
+
const c = view.state.facet(connector);
|
|
213
|
+
queueMicrotask(() => {
|
|
214
|
+
flushSync(() => {
|
|
215
|
+
const jsxElement = createElement(ElementProvider, {
|
|
216
|
+
internalId: this.id,
|
|
217
|
+
children: createElement(this.definition.render, this.props)
|
|
218
|
+
});
|
|
219
|
+
c.connect(this.elementId, createPortal(jsxElement, this.element));
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
return this.element;
|
|
223
|
+
}
|
|
224
|
+
eq(other) {
|
|
225
|
+
return this.id === other.id && this.props && other.props && JSON.stringify(this.props) === JSON.stringify(other.props);
|
|
226
|
+
}
|
|
227
|
+
destroy() {
|
|
228
|
+
if (this.view) {
|
|
229
|
+
const c = this.view.state.facet(connector);
|
|
230
|
+
c.disconnect(this.elementId);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
ignoreEvent(event) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var elementsFacet = Facet.define({
|
|
238
|
+
combine: FacetCombineStrategy.Last
|
|
239
|
+
});
|
|
240
|
+
var field = StateField.define({
|
|
241
|
+
create(state) {
|
|
242
|
+
return build(state);
|
|
243
|
+
},
|
|
244
|
+
update(value, tr) {
|
|
245
|
+
if (tr.docChanged) {
|
|
246
|
+
return build(tr.state);
|
|
247
|
+
}
|
|
248
|
+
return value;
|
|
249
|
+
},
|
|
250
|
+
provide(f) {
|
|
251
|
+
return [
|
|
252
|
+
EditorView.decorations.of((view) => view.state.field(f)),
|
|
253
|
+
EditorView.atomicRanges.of((view) => view.state.field(f))
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
function build(state) {
|
|
258
|
+
const allElements = state.facet(elementsFacet);
|
|
259
|
+
if (!allElements) {
|
|
260
|
+
return Decoration.none;
|
|
261
|
+
}
|
|
262
|
+
const tree = syntaxTree(state);
|
|
263
|
+
const builder = new RangeSetBuilder();
|
|
264
|
+
tree.iterate({
|
|
265
|
+
enter(node) {
|
|
266
|
+
const data = extract(node.node, state);
|
|
267
|
+
if (data) {
|
|
268
|
+
const definition = allElements[data.tagName];
|
|
269
|
+
if (definition) {
|
|
270
|
+
builder.add(
|
|
271
|
+
node.from,
|
|
272
|
+
node.to,
|
|
273
|
+
Decoration.replace({
|
|
274
|
+
widget: new ElementWidget(
|
|
275
|
+
definition,
|
|
276
|
+
data.internalId,
|
|
277
|
+
data.props
|
|
278
|
+
)
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (node.matchContext(["Document"])) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const decorations = builder.finish();
|
|
290
|
+
return decorations;
|
|
291
|
+
}
|
|
292
|
+
function extract(node, state) {
|
|
293
|
+
if (node.name === "Element") {
|
|
294
|
+
const elementData = extractElementData(node.node, state.doc.toString());
|
|
295
|
+
if (elementData) {
|
|
296
|
+
const { tagName, attributes } = elementData;
|
|
297
|
+
const { [INTERNAL_ID]: internalId, ...props } = attributes ?? {};
|
|
298
|
+
return {
|
|
299
|
+
tagName,
|
|
300
|
+
internalId,
|
|
301
|
+
props
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
var CUSTOM_CLIPBOARD_MIMETYPE = "application/x-with-elements";
|
|
307
|
+
var copyPasteHandler = EditorView.domEventHandlers({
|
|
308
|
+
paste(event, view) {
|
|
309
|
+
var _a, _b;
|
|
310
|
+
try {
|
|
311
|
+
const xText = (_a = event.clipboardData) == null ? void 0 : _a.getData(CUSTOM_CLIPBOARD_MIMETYPE);
|
|
312
|
+
const plainText = (_b = event.clipboardData) == null ? void 0 : _b.getData("text/plain");
|
|
313
|
+
const text = xText ?? plainText ?? "";
|
|
314
|
+
const nodes = schemaUtils.toJSON(text);
|
|
315
|
+
const newText = schemaUtils.fromJSON(
|
|
316
|
+
nodes.map((node) => {
|
|
317
|
+
if (node.type === "text") {
|
|
318
|
+
return node;
|
|
319
|
+
}
|
|
320
|
+
if (node.type === "element") {
|
|
321
|
+
return {
|
|
322
|
+
...node,
|
|
323
|
+
attributes: {
|
|
324
|
+
...node.attributes ?? {},
|
|
325
|
+
cmid: `e${Math.random()}`
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}).filter((v) => isEditorNode(v))
|
|
330
|
+
);
|
|
331
|
+
view.dispatch({
|
|
332
|
+
changes: {
|
|
333
|
+
from: view.state.selection.main.from,
|
|
334
|
+
to: view.state.selection.main.to,
|
|
335
|
+
insert: newText
|
|
336
|
+
},
|
|
337
|
+
selection: EditorSelection.cursor(
|
|
338
|
+
view.state.selection.main.from + newText.length
|
|
339
|
+
)
|
|
340
|
+
});
|
|
341
|
+
return true;
|
|
342
|
+
} catch (e) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
copy(event, view) {
|
|
347
|
+
var _a, _b;
|
|
348
|
+
const definitions = view.state.facet(elementsFacet);
|
|
349
|
+
if (!definitions) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
const { from, to } = view.state.selection.main;
|
|
354
|
+
const slice = view.state.doc.sliceString(from, to);
|
|
355
|
+
const nodes = schemaUtils.toJSON(slice);
|
|
356
|
+
const plainText = nodes.map((node) => {
|
|
357
|
+
if (node.type === "text") {
|
|
358
|
+
return node.value;
|
|
359
|
+
}
|
|
360
|
+
if (node.type === "element") {
|
|
361
|
+
const definition = definitions[node.tagName];
|
|
362
|
+
const toString = definition == null ? void 0 : definition.toString;
|
|
363
|
+
if (!definition) {
|
|
364
|
+
return node.raw ?? "";
|
|
365
|
+
}
|
|
366
|
+
if (Object.prototype.hasOwnProperty.call(definition, "toString") && typeof toString === "function") {
|
|
367
|
+
return toString(node);
|
|
368
|
+
}
|
|
369
|
+
return `[${node.tagName}]`;
|
|
370
|
+
}
|
|
371
|
+
return "";
|
|
372
|
+
}).join("");
|
|
373
|
+
(_a = event.clipboardData) == null ? void 0 : _a.setData("text/plain", plainText);
|
|
374
|
+
(_b = event.clipboardData) == null ? void 0 : _b.setData(CUSTOM_CLIPBOARD_MIMETYPE, slice);
|
|
375
|
+
return true;
|
|
376
|
+
} catch (e) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
function isEditorNode(v) {
|
|
382
|
+
return Boolean(v);
|
|
383
|
+
}
|
|
384
|
+
function chatExtension() {
|
|
385
|
+
return [
|
|
386
|
+
field,
|
|
387
|
+
copyPasteHandler
|
|
388
|
+
// selectionEnlarger.of(state => {
|
|
389
|
+
// const decorations = state.field(field);
|
|
390
|
+
// const cursor = decorations.iter();
|
|
391
|
+
// const array = [];
|
|
392
|
+
// while (cursor.value) {
|
|
393
|
+
// const widget = cursor.value.spec?.widget;
|
|
394
|
+
// const { from, to } = cursor;
|
|
395
|
+
// if (isElementWidget(widget)) {
|
|
396
|
+
// array.push({
|
|
397
|
+
// source: { from, to },
|
|
398
|
+
// target: { from, to },
|
|
399
|
+
// });
|
|
400
|
+
// }
|
|
401
|
+
// cursor.next();
|
|
402
|
+
// }
|
|
403
|
+
// return array;
|
|
404
|
+
// }),
|
|
405
|
+
];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/plugins.ts
|
|
409
|
+
var focusedEffect = StateEffect.define();
|
|
410
|
+
var focusedField = StateField2.define({
|
|
411
|
+
create() {
|
|
412
|
+
return false;
|
|
413
|
+
},
|
|
414
|
+
update(value, tr) {
|
|
415
|
+
for (const effect of tr.effects) {
|
|
416
|
+
if (effect.is(focusedEffect)) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return value;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
function insertElement({ view }) {
|
|
424
|
+
return (element) => {
|
|
425
|
+
let selection = view.state.selection.main;
|
|
426
|
+
const hasFocused = view.state.field(focusedField, false);
|
|
427
|
+
if (hasFocused === false) {
|
|
428
|
+
selection = EditorSelection2.cursor(view.state.doc.length);
|
|
429
|
+
}
|
|
430
|
+
const insert = toElementString(element);
|
|
431
|
+
view.dispatch({
|
|
432
|
+
changes: {
|
|
433
|
+
from: selection.from,
|
|
434
|
+
to: selection.to,
|
|
435
|
+
insert
|
|
436
|
+
},
|
|
437
|
+
selection: EditorSelection2.cursor(selection.from + insert.length)
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var plugins = [
|
|
442
|
+
extension([
|
|
443
|
+
focusedField,
|
|
444
|
+
EditorView2.domEventObservers({
|
|
445
|
+
click(e, view) {
|
|
446
|
+
view.dispatch({
|
|
447
|
+
effects: focusedEffect.of(null)
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}),
|
|
451
|
+
chatExtension()
|
|
452
|
+
]),
|
|
453
|
+
api("insertElement", insertElement),
|
|
454
|
+
option(
|
|
455
|
+
"elements",
|
|
456
|
+
(elements) => elementsFacet.of(elements)
|
|
457
|
+
)
|
|
458
|
+
];
|
|
459
|
+
var plugins_default = plugins;
|
|
460
|
+
|
|
461
|
+
// src/hooks.tsx
|
|
462
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
463
|
+
import {
|
|
464
|
+
useEditor,
|
|
465
|
+
useInjector
|
|
466
|
+
} from "@coze-editor/react";
|
|
467
|
+
import { ViewPlugin } from "@codemirror/view";
|
|
468
|
+
import { EditorSelection as EditorSelection3 } from "@codemirror/state";
|
|
469
|
+
function useCurrentElement() {
|
|
470
|
+
const editor = useEditor();
|
|
471
|
+
const elementId = useElementId();
|
|
472
|
+
const injector = useInjector();
|
|
473
|
+
const [isSelected, setIsSelected] = useState(false);
|
|
474
|
+
const elementIdRef = useRef(elementId);
|
|
475
|
+
elementIdRef.current = elementId;
|
|
476
|
+
function select() {
|
|
477
|
+
var _a;
|
|
478
|
+
if (!editor) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const view = editor.$view;
|
|
482
|
+
const decorations = view.state.field(field);
|
|
483
|
+
const cursor = decorations.iter();
|
|
484
|
+
while (cursor.value) {
|
|
485
|
+
const { spec } = cursor.value;
|
|
486
|
+
if (((_a = spec == null ? void 0 : spec.widget) == null ? void 0 : _a.id) === elementId) {
|
|
487
|
+
view.dispatch({
|
|
488
|
+
selection: EditorSelection3.range(cursor.from, cursor.to)
|
|
489
|
+
});
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
cursor.next();
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function remove() {
|
|
496
|
+
if (!editor) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const view = editor.$view;
|
|
500
|
+
if (view.state.readOnly) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const range = findElement(view.state, elementId);
|
|
504
|
+
if (range) {
|
|
505
|
+
view.dispatch({
|
|
506
|
+
changes: {
|
|
507
|
+
from: range.from,
|
|
508
|
+
to: range.to,
|
|
509
|
+
insert: ""
|
|
510
|
+
},
|
|
511
|
+
selection: EditorSelection3.cursor(range.from)
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
useLayoutEffect(() => {
|
|
516
|
+
function selectionContainsCurrentElement(state) {
|
|
517
|
+
const range = findElement(state, elementId);
|
|
518
|
+
const { ranges } = state.selection;
|
|
519
|
+
if (!range) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
for (const r of ranges) {
|
|
523
|
+
if (r.from <= range.from && r.to >= range.to) {
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
const plugin = ViewPlugin.fromClass(
|
|
530
|
+
class {
|
|
531
|
+
constructor(view) {
|
|
532
|
+
const contains = selectionContainsCurrentElement(view.state);
|
|
533
|
+
setIsSelected(contains);
|
|
534
|
+
}
|
|
535
|
+
update(update) {
|
|
536
|
+
if (update.selectionSet) {
|
|
537
|
+
const contains = selectionContainsCurrentElement(update.state);
|
|
538
|
+
setIsSelected(contains);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
);
|
|
543
|
+
return injector.inject([plugin]);
|
|
544
|
+
}, [injector]);
|
|
545
|
+
return {
|
|
546
|
+
isSelected,
|
|
547
|
+
select,
|
|
548
|
+
remove
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function findElement(state, elementId) {
|
|
552
|
+
var _a;
|
|
553
|
+
const decorations = state.field(field);
|
|
554
|
+
const cursor = decorations.iter();
|
|
555
|
+
while (cursor.value) {
|
|
556
|
+
const { spec } = cursor.value;
|
|
557
|
+
if (((_a = spec == null ? void 0 : spec.widget) == null ? void 0 : _a.id) === elementId) {
|
|
558
|
+
return {
|
|
559
|
+
from: cursor.from,
|
|
560
|
+
to: cursor.to
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
cursor.next();
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/index.ts
|
|
568
|
+
var preset = [
|
|
569
|
+
...universalPreset,
|
|
570
|
+
extension2([
|
|
571
|
+
EditorView3.theme({
|
|
572
|
+
"&.cm-focused": {
|
|
573
|
+
outline: "none"
|
|
574
|
+
}
|
|
575
|
+
}),
|
|
576
|
+
htmlLanguage,
|
|
577
|
+
history(),
|
|
578
|
+
keymap.of([...defaultKeymap, ...historyKeymap])
|
|
579
|
+
]),
|
|
580
|
+
...plugins_default
|
|
581
|
+
];
|
|
582
|
+
var index_default = preset;
|
|
583
|
+
export {
|
|
584
|
+
CUSTOM_CLIPBOARD_MIMETYPE,
|
|
585
|
+
index_default as default,
|
|
586
|
+
schemaUtils,
|
|
587
|
+
useCurrentElement
|
|
588
|
+
};
|
|
589
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/utils.ts","../../src/language.ts","../../src/schema.ts","../../src/plugins.ts","../../src/extension.ts","../../src/context.tsx","../../src/hooks.tsx"],"sourcesContent":["import universalPreset from '@coze-editor/preset-universal';\nimport { extension, type InferEditorAPIFromPlugins } from '@coze-editor/core';\nimport { EditorView, keymap } from '@codemirror/view';\nimport { defaultKeymap, historyKeymap, history } from '@codemirror/commands';\n\nimport {\n type EditorNode,\n type EditorElement,\n type EditorText,\n schemaUtils,\n} from './schema';\nimport plugins from './plugins';\nimport { htmlLanguage } from './language';\nimport { useCurrentElement } from './hooks';\nimport { CUSTOM_CLIPBOARD_MIMETYPE, type ElementDefinition } from './extension';\n\nconst preset = [\n ...universalPreset,\n extension([\n EditorView.theme({\n '&.cm-focused': {\n outline: 'none',\n },\n }),\n htmlLanguage,\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n ]),\n ...plugins,\n];\n\ntype EditorAPI = InferEditorAPIFromPlugins<typeof preset>;\n\nexport default preset;\n\nexport { schemaUtils, useCurrentElement, CUSTOM_CLIPBOARD_MIMETYPE };\n\nexport type {\n EditorAPI,\n ElementDefinition,\n EditorNode,\n EditorElement,\n EditorText,\n};\n","/* eslint-disable complexity */\n\nimport { type SyntaxNode } from '@lezer/common';\n\nfunction extractElementData(node: SyntaxNode, text: string) {\n const openTag = node.firstChild;\n\n let tagName: string | null = null;\n const attributes: Record<string, any> = {};\n\n if (openTag && openTag.name === 'OpenTag' && openTag.firstChild) {\n let sibling = openTag.firstChild.nextSibling;\n while (true) {\n if (!sibling) {\n break;\n }\n\n if (sibling.name === 'TagName') {\n const { from, to } = sibling;\n tagName = text.slice(from, to);\n } else if (sibling.name === 'Attribute') {\n const nameNode = sibling.firstChild;\n const isNode = nameNode?.nextSibling;\n const valueNode = isNode?.nextSibling;\n if (\n nameNode?.name === 'AttributeName' &&\n isNode?.name === 'Is' &&\n (valueNode?.name === 'AttributeValue' ||\n valueNode?.name === 'UnquotedAttributeValue')\n ) {\n const name = text.slice(nameNode.from, nameNode.to);\n const value = text.slice(valueNode.from, valueNode.to);\n\n if (valueNode.name === 'AttributeValue') {\n attributes[name] = decodeURIComponent(value.slice(1, -1));\n } else {\n try {\n attributes[name] = JSON.parse(decodeURIComponent(value));\n } catch (e) {\n /* empty */\n }\n }\n } else if (\n nameNode?.name === 'AttributeName' &&\n !isNode &&\n !valueNode\n ) {\n const name = text.slice(nameNode.from, nameNode.to);\n attributes[name] = true;\n }\n }\n\n sibling = sibling.nextSibling;\n }\n }\n\n if (tagName) {\n return {\n tagName,\n attributes,\n };\n }\n}\n\nexport { extractElementData };\n","import { parser } from '@lezer/html';\nimport { LRLanguage } from '@codemirror/language';\n\nconst htmlParser = parser.configure({\n dialect: 'noMatch',\n});\n\nfunction parse(text: string) {\n return htmlParser.parse(text);\n}\n\nconst htmlLanguage = LRLanguage.define({\n parser: htmlParser,\n});\n\nexport { parse, htmlLanguage };\n","import { extractElementData } from './utils';\nimport { parse } from './language';\n\ninterface EditorElement<Attrs = Record<string, any>> {\n type: 'element';\n tagName: string;\n attributes: Attrs;\n raw?: string;\n}\n\ninterface EditorText {\n type: 'text';\n value: string;\n}\n\ntype EditorNode = EditorElement | EditorText;\n\nconst schemaUtils = {\n toJSON(text: string): EditorNode[] {\n const tree = parse(text);\n const tags: {\n from: number;\n to: number;\n tagName: string;\n attributes: Record<string, any>;\n raw: string;\n }[] = [];\n tree.iterate({\n enter(node) {\n if (node.name === 'Element' && node.matchContext(['Document'])) {\n const data = extractElementData(node.node, text);\n if (data) {\n tags.push({\n from: node.from,\n to: node.to,\n raw: text.slice(node.from, node.to),\n ...data,\n });\n }\n }\n },\n });\n\n let pos = 0;\n const elements: EditorNode[] = [];\n for (const tag of tags) {\n const { from, to, tagName, attributes, raw } = tag;\n const { cmid, ...restAttributes } = attributes ?? {};\n\n // overlap, skip this element\n if (from < pos) {\n continue;\n }\n\n if (from > pos) {\n elements.push({\n type: 'text',\n value: text.slice(pos, from),\n });\n }\n\n elements.push({\n type: 'element',\n tagName,\n attributes: restAttributes,\n raw,\n });\n\n pos = to;\n }\n\n if (pos < text.length) {\n elements.push({\n type: 'text',\n value: text.slice(pos),\n });\n }\n\n return elements;\n },\n fromJSON(elements: EditorNode[]): string {\n return elements\n .map(el => {\n if (el.type === 'element') {\n return toElementString(el);\n } else if (el.type === 'text') {\n return el.value;\n }\n return '';\n })\n .join('');\n },\n};\n\nfunction toElementString(element: Omit<EditorElement, 'type'>) {\n const attrsString = attributesToString(element.attributes);\n return `<${element.tagName}${attrsString ? ` ${attrsString}` : ''}></${element.tagName}>`;\n}\n\nconst INTERNAL_ID = 'cmid';\n\nfunction uniqueId() {\n return `e${Math.random()}`;\n}\n\nfunction attributesToString(attributes: EditorElement['attributes']) {\n const array: string[] = [];\n let hasId = false;\n\n Object.keys(attributes).forEach(key => {\n if (key === INTERNAL_ID) {\n hasId = true;\n }\n const value = attributes[key];\n if (value === true) {\n array.push(key);\n } else {\n array.push(`${key}=${JSON.stringify(encodeURIComponent(value))}`);\n }\n });\n\n if (!hasId) {\n array.unshift(`${INTERNAL_ID}=\"${uniqueId()}\"`);\n }\n\n return array.join(' ');\n}\n\nexport { schemaUtils, toElementString, INTERNAL_ID };\nexport type { EditorNode, EditorElement, EditorText };\n","import { api, extension, option } from '@coze-editor/core';\nimport { EditorView } from '@codemirror/view';\nimport { EditorSelection, StateEffect, StateField } from '@codemirror/state';\n\nimport { type EditorElement, toElementString } from './schema';\nimport {\n chatExtension,\n type ElementsDefinition,\n elementsFacet,\n} from './extension';\n\nconst focusedEffect = StateEffect.define();\n\nconst focusedField = StateField.define<boolean>({\n create() {\n return false;\n },\n update(value, tr) {\n for (const effect of tr.effects) {\n if (effect.is(focusedEffect)) {\n return true;\n }\n }\n\n return value;\n },\n});\n\nfunction insertElement({ view }: { view: EditorView }) {\n return (element: Omit<EditorElement, 'type'>) => {\n let selection = view.state.selection.main;\n\n const hasFocused = view.state.field(focusedField, false);\n if (hasFocused === false) {\n selection = EditorSelection.cursor(view.state.doc.length);\n }\n\n const insert = toElementString(element);\n view.dispatch({\n changes: {\n from: selection.from,\n to: selection.to,\n insert,\n },\n selection: EditorSelection.cursor(selection.from + insert.length),\n });\n };\n}\n\nconst plugins = [\n extension([\n focusedField,\n EditorView.domEventObservers({\n click(e, view) {\n view.dispatch({\n effects: focusedEffect.of(null),\n });\n },\n }),\n chatExtension(),\n ]),\n api('insertElement', insertElement),\n option('elements', (elements: ElementsDefinition) =>\n elementsFacet.of(elements),\n ),\n];\n\nexport default plugins;\n","import { createPortal, flushSync } from 'react-dom';\nimport { createElement, type ReactNode } from 'react';\n\nimport { createRoot, type Root } from 'react-dom/client';\nimport { type SyntaxNode } from '@lezer/common';\nimport { FacetCombineStrategy } from '@coze-editor/utils';\nimport { connector } from '@coze-editor/react';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n WidgetType,\n} from '@codemirror/view';\nimport {\n EditorSelection,\n type EditorState,\n Facet,\n RangeSetBuilder,\n StateField,\n} from '@codemirror/state';\nimport { syntaxTree } from '@codemirror/language';\n\nimport { extractElementData } from './utils';\nimport {\n type EditorElement,\n type EditorNode,\n INTERNAL_ID,\n schemaUtils,\n} from './schema';\nimport { ElementProvider } from './context';\n\ninterface ElementDefinition<Attrs = any> {\n render: (props: Attrs) => ReactNode;\n toString?: (element: EditorElement<Attrs>) => string;\n}\n\ninterface ElementsDefinition {\n [key: string]: ElementDefinition;\n}\n\nclass ElementWidget extends WidgetType {\n public $$type = 'element';\n private root: Root;\n private element: HTMLElement;\n private view: EditorView | null = null;\n constructor(\n public definition: ElementDefinition,\n public id: string,\n public props: any,\n ) {\n super();\n\n const element = document.createElement('span');\n this.element = element;\n this.root = createRoot(element);\n }\n\n get elementId() {\n return `element-${this.id}`;\n }\n\n toDOM(view: EditorView) {\n this.view = view;\n\n const c = view.state.facet(connector);\n queueMicrotask(() => {\n flushSync(() => {\n const jsxElement = createElement(ElementProvider, {\n internalId: this.id,\n children: createElement(this.definition.render, this.props),\n });\n c.connect(this.elementId, createPortal(jsxElement, this.element));\n });\n });\n return this.element;\n }\n\n eq(other: ElementWidget) {\n return (\n this.id === other.id &&\n this.props &&\n other.props &&\n JSON.stringify(this.props) === JSON.stringify(other.props)\n );\n }\n\n destroy(): void {\n if (this.view) {\n const c = this.view.state.facet(connector);\n c.disconnect(this.elementId);\n }\n }\n\n ignoreEvent(event: Event): boolean {\n return false;\n }\n}\n\n// function isElementWidget(widget: WidgetType | null) {\n// return (widget as any)?.$$type === 'element';\n// }\n\nconst elementsFacet = Facet.define<\n ElementsDefinition | undefined,\n ElementsDefinition | undefined\n>({\n combine: FacetCombineStrategy.Last,\n});\n\nconst field = StateField.define({\n create(state) {\n return build(state);\n },\n update(value, tr) {\n if (tr.docChanged) {\n return build(tr.state);\n }\n return value;\n },\n provide(f) {\n return [\n EditorView.decorations.of(view => view.state.field(f)),\n EditorView.atomicRanges.of(view => view.state.field(f)),\n ];\n },\n});\n\nfunction build(state: EditorState): DecorationSet {\n const allElements = state.facet(elementsFacet);\n\n if (!allElements) {\n return Decoration.none;\n }\n\n const tree = syntaxTree(state);\n const builder = new RangeSetBuilder<Decoration>();\n tree.iterate({\n enter(node) {\n const data = extract(node.node, state);\n if (data) {\n const definition = allElements[data.tagName];\n if (definition) {\n builder.add(\n node.from,\n node.to,\n Decoration.replace({\n widget: new ElementWidget(\n definition,\n data.internalId,\n data.props,\n ),\n }),\n );\n }\n }\n\n if (node.matchContext(['Document'])) {\n return false;\n }\n\n return true;\n },\n });\n\n const decorations = builder.finish();\n\n return decorations;\n}\n\nfunction extract(node: SyntaxNode, state: EditorState) {\n if (node.name === 'Element') {\n const elementData = extractElementData(node.node, state.doc.toString());\n\n if (elementData) {\n const { tagName, attributes } = elementData;\n const { [INTERNAL_ID]: internalId, ...props } = attributes ?? {};\n\n return {\n tagName,\n internalId,\n props,\n };\n }\n }\n}\n\nconst CUSTOM_CLIPBOARD_MIMETYPE = 'application/x-with-elements';\n\nconst copyPasteHandler = EditorView.domEventHandlers({\n paste(event, view) {\n try {\n const xText = event.clipboardData?.getData(CUSTOM_CLIPBOARD_MIMETYPE);\n const plainText = event.clipboardData?.getData('text/plain');\n\n const text = xText ?? plainText ?? '';\n\n const nodes = schemaUtils.toJSON(text);\n const newText = schemaUtils.fromJSON(\n nodes\n .map(node => {\n if (node.type === 'text') {\n return node;\n }\n\n if (node.type === 'element') {\n return {\n ...node,\n attributes: {\n ...(node.attributes ?? {}),\n cmid: `e${Math.random()}`,\n },\n } satisfies EditorElement;\n }\n })\n .filter(v => isEditorNode(v)),\n );\n\n view.dispatch({\n changes: {\n from: view.state.selection.main.from,\n to: view.state.selection.main.to,\n insert: newText,\n },\n selection: EditorSelection.cursor(\n view.state.selection.main.from + newText.length,\n ),\n });\n return true;\n } catch (e) {\n return false;\n }\n },\n copy(event, view) {\n const definitions = view.state.facet(elementsFacet);\n\n if (!definitions) {\n return false;\n }\n\n try {\n const { from, to } = view.state.selection.main;\n const slice = view.state.doc.sliceString(from, to);\n const nodes = schemaUtils.toJSON(slice);\n\n const plainText = nodes\n .map(node => {\n if (node.type === 'text') {\n return node.value;\n }\n\n if (node.type === 'element') {\n const definition = definitions[node.tagName];\n const toString = definition?.toString;\n\n if (!definition) {\n return node.raw ?? '';\n }\n\n if (\n Object.prototype.hasOwnProperty.call(definition, 'toString') &&\n typeof toString === 'function'\n ) {\n return toString(node);\n }\n\n return `[${node.tagName}]`;\n }\n\n return '';\n })\n .join('');\n\n event.clipboardData?.setData('text/plain', plainText);\n event.clipboardData?.setData(CUSTOM_CLIPBOARD_MIMETYPE, slice);\n\n return true;\n } catch (e) {\n return false;\n }\n },\n});\n\nfunction isEditorNode(v: unknown): v is EditorNode {\n return Boolean(v);\n}\n\nfunction chatExtension() {\n return [\n field,\n copyPasteHandler,\n // selectionEnlarger.of(state => {\n // const decorations = state.field(field);\n // const cursor = decorations.iter();\n // const array = [];\n\n // while (cursor.value) {\n // const widget = cursor.value.spec?.widget;\n // const { from, to } = cursor;\n // if (isElementWidget(widget)) {\n // array.push({\n // source: { from, to },\n // target: { from, to },\n // });\n // }\n\n // cursor.next();\n // }\n\n // return array;\n // }),\n ];\n}\n\nexport { field, chatExtension, elementsFacet, CUSTOM_CLIPBOARD_MIMETYPE };\n\nexport type { ElementsDefinition, ElementDefinition };\n","import React, { createContext, type ReactNode, useContext } from 'react';\n\nconst Context = createContext('');\n\nfunction ElementProvider({\n internalId,\n children,\n}: {\n internalId: string;\n children: ReactNode;\n}) {\n return <Context.Provider value={internalId}>{children}</Context.Provider>;\n}\n\nfunction useElementId() {\n const id = useContext(Context);\n return id;\n}\n\nexport { ElementProvider, useElementId };\n","import { useLayoutEffect, useRef, useState } from 'react';\n\nimport {\n type BuiltinEditorAPI,\n useEditor,\n useInjector,\n} from '@coze-editor/react';\nimport { type EditorView, ViewPlugin, type ViewUpdate } from '@codemirror/view';\nimport { EditorSelection, type EditorState } from '@codemirror/state';\n\nimport { field } from './extension';\nimport { useElementId } from './context';\n\nfunction useCurrentElement() {\n const editor = useEditor<BuiltinEditorAPI | null>();\n const elementId = useElementId();\n const injector = useInjector();\n const [isSelected, setIsSelected] = useState(false);\n const elementIdRef = useRef(elementId);\n\n elementIdRef.current = elementId;\n\n function select() {\n if (!editor) {\n return;\n }\n\n const view = editor.$view;\n\n const decorations = view.state.field(field);\n\n const cursor = decorations.iter();\n while (cursor.value) {\n const { spec } = cursor.value;\n if (spec?.widget?.id === elementId) {\n view.dispatch({\n selection: EditorSelection.range(cursor.from, cursor.to),\n });\n break;\n }\n cursor.next();\n }\n }\n\n function remove() {\n if (!editor) {\n return;\n }\n\n const view = editor.$view;\n\n if (view.state.readOnly) {\n return;\n }\n\n const range = findElement(view.state, elementId);\n if (range) {\n view.dispatch({\n changes: {\n from: range.from,\n to: range.to,\n insert: '',\n },\n selection: EditorSelection.cursor(range.from),\n });\n }\n }\n\n useLayoutEffect(() => {\n function selectionContainsCurrentElement(state: EditorState) {\n const range = findElement(state, elementId);\n const { ranges } = state.selection;\n if (!range) {\n return false;\n }\n\n for (const r of ranges) {\n if (r.from <= range.from && r.to >= range.to) {\n return true;\n }\n }\n\n return false;\n }\n\n const plugin = ViewPlugin.fromClass(\n class {\n constructor(view: EditorView) {\n const contains = selectionContainsCurrentElement(view.state);\n setIsSelected(contains);\n }\n\n update(update: ViewUpdate) {\n if (update.selectionSet) {\n const contains = selectionContainsCurrentElement(update.state);\n setIsSelected(contains);\n }\n }\n },\n );\n\n return injector.inject([plugin]);\n }, [injector]);\n\n return {\n isSelected,\n select,\n remove,\n };\n}\n\nfunction findElement(state: EditorState, elementId: string) {\n const decorations = state.field(field);\n\n const cursor = decorations.iter();\n while (cursor.value) {\n const { spec } = cursor.value;\n if (spec?.widget?.id === elementId) {\n return {\n from: cursor.from,\n to: cursor.to,\n };\n }\n cursor.next();\n }\n}\n\nexport { useCurrentElement };\n"],"mappings":";AAAA,OAAO,qBAAqB;AAC5B,SAAS,aAAAA,kBAAiD;AAC1D,SAAS,cAAAC,aAAY,cAAc;AACnC,SAAS,eAAe,eAAe,eAAe;;;ACCtD,SAAS,mBAAmB,MAAkB,MAAc;AAC1D,QAAM,UAAU,KAAK;AAErB,MAAI,UAAyB;AAC7B,QAAM,aAAkC,CAAC;AAEzC,MAAI,WAAW,QAAQ,SAAS,aAAa,QAAQ,YAAY;AAC/D,QAAI,UAAU,QAAQ,WAAW;AACjC,WAAO,MAAM;AACX,UAAI,CAAC,SAAS;AACZ;AAAA,MACF;AAEA,UAAI,QAAQ,SAAS,WAAW;AAC9B,cAAM,EAAE,MAAM,GAAG,IAAI;AACrB,kB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AC3D,wBAAc,QAAQ;AAAA,QACxB;AAAA,QAEA,OAAO,QAAoB;AACzB,cAAI,OAAO,cAAc;AACvB,kBAAM,WAAW,gCAAgC,OAAO,KAAK;AAC7D,0BAAc,QAAQ;AAAA,UACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO,SAAS,OAAO,CAAC,MAAM,CAAC;AAAA,EACjC,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,YAAY,OAAoB,WAAmB;AA/G5D;AAgHE,QAAM,cAAc,MAAM,MAAM,KAAK;AAErC,QAAM,SAAS,YAAY,KAAK;AAChC,SAAO,OAAO,OAAO;AACnB,UAAM,EAAE,KAAK,IAAI,OAAO;AACxB,UAAI,kCAAM,WAAN,mBAAc,QAAO,WAAW;AAClC,aAAO;AAAA,QACL,MAAM,OAAO;AAAA,QACb,IAAI,OAAO;AAAA,MACb;AAAA,IACF;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;AP7GA,IAAM,SAAS;AAAA,EACb,GAAG;AAAA,EACHC,WAAU;AAAA,IACRC,YAAW,MAAM;AAAA,MACf,gBAAgB;AAAA,QACd,SAAS;AAAA,MACX;AAAA,IACF,CAAC;AAAA,IACD;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,GAAG,CAAC,GAAG,eAAe,GAAG,aAAa,CAAC;AAAA,EAChD,CAAC;AAAA,EACD,GAAG;AACL;AAIA,IAAO,gBAAQ;","names":["extension","EditorView","EditorView","EditorSelection","StateField","StateField","EditorSelection","EditorView","EditorSelection","EditorSelection","extension","EditorView"]}
|