miyuan-editor 0.0.3
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 +525 -0
- package/dist/core/index.cjs.js +40 -0
- package/dist/core/index.esm.js +4 -0
- package/dist/dist-5Q_Z9Ell.js +6390 -0
- package/dist/dist-5Q_Z9Ell.js.map +1 -0
- package/dist/dist-CMM6n8DO.cjs +4629 -0
- package/dist/dist-CMM6n8DO.cjs.map +1 -0
- package/dist/dist-CRSJDo2G.cjs +6617 -0
- package/dist/dist-CRSJDo2G.cjs.map +1 -0
- package/dist/dist-CZw77IJK.js +4612 -0
- package/dist/dist-CZw77IJK.js.map +1 -0
- package/dist/dist-CnVrDtsI.js +556 -0
- package/dist/dist-CnVrDtsI.js.map +1 -0
- package/dist/dist-rItBfhNb.cjs +591 -0
- package/dist/dist-rItBfhNb.cjs.map +1 -0
- package/dist/export-utils-CYaNoyVg.cjs +167 -0
- package/dist/export-utils-CYaNoyVg.cjs.map +1 -0
- package/dist/export-utils-DN0Gu8Vu.js +144 -0
- package/dist/export-utils-DN0Gu8Vu.js.map +1 -0
- package/dist/extension-BPFuYyzN.cjs +338 -0
- package/dist/extension-BPFuYyzN.cjs.map +1 -0
- package/dist/extension-Cl6x5MDR.js +321 -0
- package/dist/extension-Cl6x5MDR.js.map +1 -0
- package/dist/extensions/index.cjs.js +3462 -0
- package/dist/extensions/index.cjs.js.map +1 -0
- package/dist/extensions/index.esm.js +3412 -0
- package/dist/extensions/index.esm.js.map +1 -0
- package/dist/prompt-B4AOP8f_.js +24143 -0
- package/dist/prompt-B4AOP8f_.js.map +1 -0
- package/dist/prompt-CGLw2O21.cjs +25530 -0
- package/dist/prompt-CGLw2O21.cjs.map +1 -0
- package/dist/react/index.cjs.js +839 -0
- package/dist/react/index.cjs.js.map +1 -0
- package/dist/react/index.esm.js +820 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/shortcut-panel-BskGXV8n.js +49468 -0
- package/dist/shortcut-panel-BskGXV8n.js.map +1 -0
- package/dist/shortcut-panel-yP4RPTFt.cjs +49563 -0
- package/dist/shortcut-panel-yP4RPTFt.cjs.map +1 -0
- package/dist/toc-extension-BESc0uEW.js +150 -0
- package/dist/toc-extension-BESc0uEW.js.map +1 -0
- package/dist/toc-extension-SRvSuskn.cjs +173 -0
- package/dist/toc-extension-SRvSuskn.cjs.map +1 -0
- package/dist/toolbar-config-Cgc9mV2v.js +243 -0
- package/dist/toolbar-config-Cgc9mV2v.js.map +1 -0
- package/dist/toolbar-config-Cjt_fPMi.cjs +260 -0
- package/dist/toolbar-config-Cjt_fPMi.cjs.map +1 -0
- package/dist/ui/index.cjs.js +18 -0
- package/dist/ui/index.esm.js +3 -0
- package/dist/vue/index.cjs.js +323 -0
- package/dist/vue/index.cjs.js.map +1 -0
- package/dist/vue/index.esm.js +307 -0
- package/dist/vue/index.esm.js.map +1 -0
- package/dist/vue2/index.cjs.js +323 -0
- package/dist/vue2/index.cjs.js.map +1 -0
- package/dist/vue2/index.esm.js +307 -0
- package/dist/vue2/index.esm.js.map +1 -0
- package/package.json +116 -0
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import { fi as __commonJSMin, hi as __require } from "../prompt-B4AOP8f_.js";
|
|
2
|
+
import { A as DOMParser, d as EditorState, m as PluginKey, p as Plugin } from "../dist-5Q_Z9Ell.js";
|
|
3
|
+
import { n as DecorationSet, t as Decoration } from "../dist-CZw77IJK.js";
|
|
4
|
+
import { r as EditorView, t as ExtensionManager } from "../extension-Cl6x5MDR.js";
|
|
5
|
+
import { a as AIMenu$1, c as AIService, d as BubbleMenu$1, f as Toolbar$1, h as ensureStylesInjected, i as AIWriter$1, n as TocPanel$1, o as loadAIConfig, r as WordCountDisplay$1, t as ShortcutPanel$1, u as DragHandle$1 } from "../shortcut-panel-BskGXV8n.js";
|
|
6
|
+
import { n as OPTIONAL_TOOLBAR_ITEMS, r as createToolbarConfig, t as DEFAULT_TOOLBAR_CONFIG } from "../toolbar-config-Cgc9mV2v.js";
|
|
7
|
+
import { i as exportAsPlainText, n as exportAsJSON, r as exportAsMarkdown, t as exportAsHTML } from "../export-utils-DN0Gu8Vu.js";
|
|
8
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
9
|
+
//#region src/react/use-editor.ts
|
|
10
|
+
/**
|
|
11
|
+
* useEditor: React hook that creates and manages an EditorView backed by ProseMirror.
|
|
12
|
+
*/
|
|
13
|
+
function useEditor(options = {}) {
|
|
14
|
+
const { extensions = [], content, editable = true, onUpdate, onSelectionChange } = options;
|
|
15
|
+
const viewRef = useRef(null);
|
|
16
|
+
const managerRef = useRef(null);
|
|
17
|
+
const [, setVersion] = useState(0);
|
|
18
|
+
if (!managerRef.current) managerRef.current = new ExtensionManager(extensions);
|
|
19
|
+
const manager = managerRef.current;
|
|
20
|
+
const schema = manager.schema;
|
|
21
|
+
const createState = useCallback(() => {
|
|
22
|
+
let doc;
|
|
23
|
+
if (content) try {
|
|
24
|
+
const container = document.createElement("div");
|
|
25
|
+
container.innerHTML = content;
|
|
26
|
+
doc = DOMParser.fromSchema(schema).parse(container);
|
|
27
|
+
} catch {}
|
|
28
|
+
return EditorState.create({
|
|
29
|
+
schema,
|
|
30
|
+
doc,
|
|
31
|
+
plugins: manager.plugins
|
|
32
|
+
});
|
|
33
|
+
}, [
|
|
34
|
+
schema,
|
|
35
|
+
content,
|
|
36
|
+
manager.plugins
|
|
37
|
+
]);
|
|
38
|
+
const stateRef = useRef(null);
|
|
39
|
+
if (!stateRef.current) stateRef.current = createState();
|
|
40
|
+
const forceUpdate = useCallback(() => {
|
|
41
|
+
setVersion((v) => v + 1);
|
|
42
|
+
}, []);
|
|
43
|
+
const dispatchTransaction = useCallback((tr) => {
|
|
44
|
+
const view = viewRef.current;
|
|
45
|
+
if (!view) return;
|
|
46
|
+
const newState = view.state.apply(tr);
|
|
47
|
+
view.updateState(newState);
|
|
48
|
+
stateRef.current = newState;
|
|
49
|
+
if (onUpdate) onUpdate(newState);
|
|
50
|
+
if (onSelectionChange) onSelectionChange(newState);
|
|
51
|
+
forceUpdate();
|
|
52
|
+
}, [
|
|
53
|
+
onUpdate,
|
|
54
|
+
onSelectionChange,
|
|
55
|
+
forceUpdate
|
|
56
|
+
]);
|
|
57
|
+
const editableRef = useRef(editable);
|
|
58
|
+
editableRef.current = editable;
|
|
59
|
+
const createView = useCallback((element) => {
|
|
60
|
+
if (viewRef.current) return;
|
|
61
|
+
const view = new EditorView({
|
|
62
|
+
state: stateRef.current,
|
|
63
|
+
element,
|
|
64
|
+
editable: editableRef.current,
|
|
65
|
+
dispatchTransaction
|
|
66
|
+
});
|
|
67
|
+
viewRef.current = view;
|
|
68
|
+
stateRef.current = view.state;
|
|
69
|
+
forceUpdate();
|
|
70
|
+
}, [
|
|
71
|
+
editable,
|
|
72
|
+
dispatchTransaction,
|
|
73
|
+
forceUpdate
|
|
74
|
+
]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
return () => {
|
|
77
|
+
if (viewRef.current) {
|
|
78
|
+
viewRef.current.destroy();
|
|
79
|
+
viewRef.current = null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
return {
|
|
84
|
+
view: viewRef.current,
|
|
85
|
+
state: stateRef.current,
|
|
86
|
+
schema,
|
|
87
|
+
commands: manager.commands,
|
|
88
|
+
forceUpdate,
|
|
89
|
+
_createView: createView
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region node_modules/.pnpm/react@19.2.7/node_modules/react/cjs/react-jsx-runtime.production.js
|
|
94
|
+
/**
|
|
95
|
+
* @license React
|
|
96
|
+
* react-jsx-runtime.production.js
|
|
97
|
+
*
|
|
98
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
99
|
+
*
|
|
100
|
+
* This source code is licensed under the MIT license found in the
|
|
101
|
+
* LICENSE file in the root directory of this source tree.
|
|
102
|
+
*/
|
|
103
|
+
var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
104
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
105
|
+
function jsxProd(type, config, maybeKey) {
|
|
106
|
+
var key = null;
|
|
107
|
+
void 0 !== maybeKey && (key = "" + maybeKey);
|
|
108
|
+
void 0 !== config.key && (key = "" + config.key);
|
|
109
|
+
if ("key" in config) {
|
|
110
|
+
maybeKey = {};
|
|
111
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
112
|
+
} else maybeKey = config;
|
|
113
|
+
config = maybeKey.ref;
|
|
114
|
+
return {
|
|
115
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
116
|
+
type,
|
|
117
|
+
key,
|
|
118
|
+
ref: void 0 !== config ? config : null,
|
|
119
|
+
props: maybeKey
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
123
|
+
exports.jsx = jsxProd;
|
|
124
|
+
exports.jsxs = jsxProd;
|
|
125
|
+
}));
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region node_modules/.pnpm/react@19.2.7/node_modules/react/cjs/react-jsx-runtime.development.js
|
|
128
|
+
/**
|
|
129
|
+
* @license React
|
|
130
|
+
* react-jsx-runtime.development.js
|
|
131
|
+
*
|
|
132
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
133
|
+
*
|
|
134
|
+
* This source code is licensed under the MIT license found in the
|
|
135
|
+
* LICENSE file in the root directory of this source tree.
|
|
136
|
+
*/
|
|
137
|
+
var require_react_jsx_runtime_development = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
138
|
+
"production" !== process.env.NODE_ENV && (function() {
|
|
139
|
+
function getComponentNameFromType(type) {
|
|
140
|
+
if (null == type) return null;
|
|
141
|
+
if ("function" === typeof type) return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
142
|
+
if ("string" === typeof type) return type;
|
|
143
|
+
switch (type) {
|
|
144
|
+
case REACT_FRAGMENT_TYPE: return "Fragment";
|
|
145
|
+
case REACT_PROFILER_TYPE: return "Profiler";
|
|
146
|
+
case REACT_STRICT_MODE_TYPE: return "StrictMode";
|
|
147
|
+
case REACT_SUSPENSE_TYPE: return "Suspense";
|
|
148
|
+
case REACT_SUSPENSE_LIST_TYPE: return "SuspenseList";
|
|
149
|
+
case REACT_ACTIVITY_TYPE: return "Activity";
|
|
150
|
+
}
|
|
151
|
+
if ("object" === typeof type) switch ("number" === typeof type.tag && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
152
|
+
case REACT_PORTAL_TYPE: return "Portal";
|
|
153
|
+
case REACT_CONTEXT_TYPE: return type.displayName || "Context";
|
|
154
|
+
case REACT_CONSUMER_TYPE: return (type._context.displayName || "Context") + ".Consumer";
|
|
155
|
+
case REACT_FORWARD_REF_TYPE:
|
|
156
|
+
var innerType = type.render;
|
|
157
|
+
type = type.displayName;
|
|
158
|
+
type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
159
|
+
return type;
|
|
160
|
+
case REACT_MEMO_TYPE: return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
161
|
+
case REACT_LAZY_TYPE:
|
|
162
|
+
innerType = type._payload;
|
|
163
|
+
type = type._init;
|
|
164
|
+
try {
|
|
165
|
+
return getComponentNameFromType(type(innerType));
|
|
166
|
+
} catch (x) {}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function testStringCoercion(value) {
|
|
171
|
+
return "" + value;
|
|
172
|
+
}
|
|
173
|
+
function checkKeyStringCoercion(value) {
|
|
174
|
+
try {
|
|
175
|
+
testStringCoercion(value);
|
|
176
|
+
var JSCompiler_inline_result = !1;
|
|
177
|
+
} catch (e) {
|
|
178
|
+
JSCompiler_inline_result = !0;
|
|
179
|
+
}
|
|
180
|
+
if (JSCompiler_inline_result) {
|
|
181
|
+
JSCompiler_inline_result = console;
|
|
182
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
183
|
+
var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
184
|
+
JSCompiler_temp_const.call(JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0);
|
|
185
|
+
return testStringCoercion(value);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function getTaskName(type) {
|
|
189
|
+
if (type === REACT_FRAGMENT_TYPE) return "<>";
|
|
190
|
+
if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE) return "<...>";
|
|
191
|
+
try {
|
|
192
|
+
var name = getComponentNameFromType(type);
|
|
193
|
+
return name ? "<" + name + ">" : "<...>";
|
|
194
|
+
} catch (x) {
|
|
195
|
+
return "<...>";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function getOwner() {
|
|
199
|
+
var dispatcher = ReactSharedInternals.A;
|
|
200
|
+
return null === dispatcher ? null : dispatcher.getOwner();
|
|
201
|
+
}
|
|
202
|
+
function UnknownOwner() {
|
|
203
|
+
return Error("react-stack-top-frame");
|
|
204
|
+
}
|
|
205
|
+
function hasValidKey(config) {
|
|
206
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
207
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
208
|
+
if (getter && getter.isReactWarning) return !1;
|
|
209
|
+
}
|
|
210
|
+
return void 0 !== config.key;
|
|
211
|
+
}
|
|
212
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
213
|
+
function warnAboutAccessingKey() {
|
|
214
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName));
|
|
215
|
+
}
|
|
216
|
+
warnAboutAccessingKey.isReactWarning = !0;
|
|
217
|
+
Object.defineProperty(props, "key", {
|
|
218
|
+
get: warnAboutAccessingKey,
|
|
219
|
+
configurable: !0
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
223
|
+
var componentName = getComponentNameFromType(this.type);
|
|
224
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."));
|
|
225
|
+
componentName = this.props.ref;
|
|
226
|
+
return void 0 !== componentName ? componentName : null;
|
|
227
|
+
}
|
|
228
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
229
|
+
var refProp = props.ref;
|
|
230
|
+
type = {
|
|
231
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
232
|
+
type,
|
|
233
|
+
key,
|
|
234
|
+
props,
|
|
235
|
+
_owner: owner
|
|
236
|
+
};
|
|
237
|
+
null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
|
|
238
|
+
enumerable: !1,
|
|
239
|
+
get: elementRefGetterWithDeprecationWarning
|
|
240
|
+
}) : Object.defineProperty(type, "ref", {
|
|
241
|
+
enumerable: !1,
|
|
242
|
+
value: null
|
|
243
|
+
});
|
|
244
|
+
type._store = {};
|
|
245
|
+
Object.defineProperty(type._store, "validated", {
|
|
246
|
+
configurable: !1,
|
|
247
|
+
enumerable: !1,
|
|
248
|
+
writable: !0,
|
|
249
|
+
value: 0
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
252
|
+
configurable: !1,
|
|
253
|
+
enumerable: !1,
|
|
254
|
+
writable: !0,
|
|
255
|
+
value: null
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(type, "_debugStack", {
|
|
258
|
+
configurable: !1,
|
|
259
|
+
enumerable: !1,
|
|
260
|
+
writable: !0,
|
|
261
|
+
value: debugStack
|
|
262
|
+
});
|
|
263
|
+
Object.defineProperty(type, "_debugTask", {
|
|
264
|
+
configurable: !1,
|
|
265
|
+
enumerable: !1,
|
|
266
|
+
writable: !0,
|
|
267
|
+
value: debugTask
|
|
268
|
+
});
|
|
269
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
270
|
+
return type;
|
|
271
|
+
}
|
|
272
|
+
function jsxDEVImpl(type, config, maybeKey, isStaticChildren, debugStack, debugTask) {
|
|
273
|
+
var children = config.children;
|
|
274
|
+
if (void 0 !== children) if (isStaticChildren) if (isArrayImpl(children)) {
|
|
275
|
+
for (isStaticChildren = 0; isStaticChildren < children.length; isStaticChildren++) validateChildKeys(children[isStaticChildren]);
|
|
276
|
+
Object.freeze && Object.freeze(children);
|
|
277
|
+
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
278
|
+
else validateChildKeys(children);
|
|
279
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
280
|
+
children = getComponentNameFromType(type);
|
|
281
|
+
var keys = Object.keys(config).filter(function(k) {
|
|
282
|
+
return "key" !== k;
|
|
283
|
+
});
|
|
284
|
+
isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
285
|
+
didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", isStaticChildren, children, keys, children), didWarnAboutKeySpread[children + isStaticChildren] = !0);
|
|
286
|
+
}
|
|
287
|
+
children = null;
|
|
288
|
+
void 0 !== maybeKey && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey);
|
|
289
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key);
|
|
290
|
+
if ("key" in config) {
|
|
291
|
+
maybeKey = {};
|
|
292
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
293
|
+
} else maybeKey = config;
|
|
294
|
+
children && defineKeyPropWarningGetter(maybeKey, "function" === typeof type ? type.displayName || type.name || "Unknown" : type);
|
|
295
|
+
return ReactElement(type, children, maybeKey, getOwner(), debugStack, debugTask);
|
|
296
|
+
}
|
|
297
|
+
function validateChildKeys(node) {
|
|
298
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
299
|
+
}
|
|
300
|
+
function isValidElement(object) {
|
|
301
|
+
return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
302
|
+
}
|
|
303
|
+
var React = __require("react"), REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() {
|
|
304
|
+
return null;
|
|
305
|
+
};
|
|
306
|
+
React = { react_stack_bottom_frame: function(callStackForError) {
|
|
307
|
+
return callStackForError();
|
|
308
|
+
} };
|
|
309
|
+
var specialPropKeyWarningShown;
|
|
310
|
+
var didWarnAboutElementRef = {};
|
|
311
|
+
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(React, UnknownOwner)();
|
|
312
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
313
|
+
var didWarnAboutKeySpread = {};
|
|
314
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
315
|
+
exports.jsx = function(type, config, maybeKey) {
|
|
316
|
+
var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
317
|
+
return jsxDEVImpl(type, config, maybeKey, !1, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
318
|
+
};
|
|
319
|
+
exports.jsxs = function(type, config, maybeKey) {
|
|
320
|
+
var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
321
|
+
return jsxDEVImpl(type, config, maybeKey, !0, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
322
|
+
};
|
|
323
|
+
})();
|
|
324
|
+
}));
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/react/editor-content.tsx
|
|
327
|
+
var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
328
|
+
if (process.env.NODE_ENV === "production") module.exports = require_react_jsx_runtime_production();
|
|
329
|
+
else module.exports = require_react_jsx_runtime_development();
|
|
330
|
+
})))();
|
|
331
|
+
function createEditorAdapter(editor) {
|
|
332
|
+
return {
|
|
333
|
+
getView: () => editor.view,
|
|
334
|
+
getState: () => editor.state,
|
|
335
|
+
getSchema: () => editor.schema,
|
|
336
|
+
getCommands: () => editor.commands
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function EditorContent({ editor, className, style }) {
|
|
340
|
+
const containerRef = useRef(null);
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
const el = containerRef.current;
|
|
343
|
+
if (!el) return;
|
|
344
|
+
ensureStylesInjected();
|
|
345
|
+
editor._createView(el);
|
|
346
|
+
}, [editor]);
|
|
347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
348
|
+
ref: containerRef,
|
|
349
|
+
className,
|
|
350
|
+
style
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/react/bubble-menu.tsx
|
|
355
|
+
function BubbleMenu({ editor, className }) {
|
|
356
|
+
const containerRef = useRef(null);
|
|
357
|
+
const compRef = useRef(null);
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
if (!containerRef.current || compRef.current) return;
|
|
360
|
+
const comp = new BubbleMenu$1(createEditorAdapter(editor));
|
|
361
|
+
comp.mount(containerRef.current);
|
|
362
|
+
compRef.current = comp;
|
|
363
|
+
return () => {
|
|
364
|
+
comp.destroy();
|
|
365
|
+
compRef.current = null;
|
|
366
|
+
};
|
|
367
|
+
}, [editor]);
|
|
368
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
369
|
+
ref: containerRef,
|
|
370
|
+
className
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/react/ai-menu.tsx
|
|
375
|
+
var AIMenu = forwardRef(function AIMenu({ editor, className }, ref) {
|
|
376
|
+
const containerRef = useRef(null);
|
|
377
|
+
const compRef = useRef(null);
|
|
378
|
+
useEffect(() => {
|
|
379
|
+
if (!containerRef.current || compRef.current) return;
|
|
380
|
+
const comp = new AIMenu$1(createEditorAdapter(editor));
|
|
381
|
+
comp.mount(containerRef.current);
|
|
382
|
+
compRef.current = comp;
|
|
383
|
+
return () => {
|
|
384
|
+
comp.destroy();
|
|
385
|
+
compRef.current = null;
|
|
386
|
+
};
|
|
387
|
+
}, [editor]);
|
|
388
|
+
useImperativeHandle(ref, () => ({ open: () => compRef.current?.open() }), []);
|
|
389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
390
|
+
ref: containerRef,
|
|
391
|
+
className
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
//#endregion
|
|
395
|
+
//#region src/react/ai-writer.tsx
|
|
396
|
+
var AIWriter = forwardRef(function AIWriter({ editor, className }, ref) {
|
|
397
|
+
const containerRef = useRef(null);
|
|
398
|
+
const compRef = useRef(null);
|
|
399
|
+
useEffect(() => {
|
|
400
|
+
if (!containerRef.current || compRef.current) return;
|
|
401
|
+
const comp = new AIWriter$1(createEditorAdapter(editor));
|
|
402
|
+
comp.mount(containerRef.current);
|
|
403
|
+
compRef.current = comp;
|
|
404
|
+
return () => {
|
|
405
|
+
comp.destroy();
|
|
406
|
+
compRef.current = null;
|
|
407
|
+
};
|
|
408
|
+
}, [editor]);
|
|
409
|
+
useImperativeHandle(ref, () => ({
|
|
410
|
+
open: () => compRef.current?.open(),
|
|
411
|
+
openProductCard: () => compRef.current?.openProductCard()
|
|
412
|
+
}), []);
|
|
413
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
414
|
+
ref: containerRef,
|
|
415
|
+
className
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/react/toolbar.tsx
|
|
420
|
+
function Toolbar({ editor, className }) {
|
|
421
|
+
const containerRef = useRef(null);
|
|
422
|
+
const compRef = useRef(null);
|
|
423
|
+
useEffect(() => {
|
|
424
|
+
if (!containerRef.current || compRef.current) return;
|
|
425
|
+
const comp = new Toolbar$1(createEditorAdapter(editor));
|
|
426
|
+
comp.mount(containerRef.current);
|
|
427
|
+
compRef.current = comp;
|
|
428
|
+
return () => {
|
|
429
|
+
comp.destroy();
|
|
430
|
+
compRef.current = null;
|
|
431
|
+
};
|
|
432
|
+
}, [editor]);
|
|
433
|
+
useEffect(() => {
|
|
434
|
+
compRef.current?.update();
|
|
435
|
+
});
|
|
436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
437
|
+
ref: containerRef,
|
|
438
|
+
className
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/react/drag-handle.tsx
|
|
443
|
+
function DragHandle({ editor, className }) {
|
|
444
|
+
const containerRef = useRef(null);
|
|
445
|
+
const compRef = useRef(null);
|
|
446
|
+
useEffect(() => {
|
|
447
|
+
if (!containerRef.current || compRef.current) return;
|
|
448
|
+
const comp = new DragHandle$1(createEditorAdapter(editor));
|
|
449
|
+
comp.mount(containerRef.current);
|
|
450
|
+
compRef.current = comp;
|
|
451
|
+
return () => {
|
|
452
|
+
comp.destroy();
|
|
453
|
+
compRef.current = null;
|
|
454
|
+
};
|
|
455
|
+
}, [editor]);
|
|
456
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
457
|
+
ref: containerRef,
|
|
458
|
+
className
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/ai/autocomplete.ts
|
|
463
|
+
var autocompleteKey = new PluginKey("aiAutocomplete");
|
|
464
|
+
var DEFAULT_SYSTEM_PROMPT = `你是一个文本补全助手。根据用户提供的上下文,自然地续写接下来的内容。
|
|
465
|
+
规则:
|
|
466
|
+
1. 只输出需要补全的内容,不要重复已有文本
|
|
467
|
+
2. 保持与上下文一致的语言、风格和语气
|
|
468
|
+
3. 补全内容应该简短自然,通常1-2句话即可
|
|
469
|
+
4. 不要输出任何解释、标记或格式符号
|
|
470
|
+
5. 如果上下文不完整,补全当前句子;如果已经完整,可以续写下一句`;
|
|
471
|
+
function getContextBeforeCursor(state, maxChars) {
|
|
472
|
+
const { from } = state.selection;
|
|
473
|
+
const startPos = Math.max(0, from - maxChars);
|
|
474
|
+
return {
|
|
475
|
+
text: state.doc.textBetween(startPos, from, " ", "").slice(-maxChars),
|
|
476
|
+
pos: from
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function shouldTrigger(text, minLen) {
|
|
480
|
+
if (text.length < minLen) return false;
|
|
481
|
+
const lastChar = text.slice(-1);
|
|
482
|
+
if (lastChar === "\n" || lastChar === " ") return false;
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
function createGhostTextDecoration(pos, text) {
|
|
486
|
+
const span = document.createElement("span");
|
|
487
|
+
span.className = "mi-ai-ghost-text";
|
|
488
|
+
span.textContent = text;
|
|
489
|
+
span.style.cssText = "color: #aaa; pointer-events: none; font-style: italic; opacity: 0.7;";
|
|
490
|
+
return Decoration.widget(pos, span, { key: "ai-ghost" });
|
|
491
|
+
}
|
|
492
|
+
function createAutocompletePlugin(config) {
|
|
493
|
+
const { getService, debounceMs = 800, minTriggerLength = 4, maxContextChars = 500, systemPrompt = DEFAULT_SYSTEM_PROMPT, enabled: initialEnabled = true } = config;
|
|
494
|
+
let debounceTimer = null;
|
|
495
|
+
let abortController = null;
|
|
496
|
+
let currentSuggestion = "";
|
|
497
|
+
let isEnabled = initialEnabled;
|
|
498
|
+
let lastTriggerPos = -1;
|
|
499
|
+
function clearPending() {
|
|
500
|
+
if (debounceTimer) {
|
|
501
|
+
clearTimeout(debounceTimer);
|
|
502
|
+
debounceTimer = null;
|
|
503
|
+
}
|
|
504
|
+
if (abortController) {
|
|
505
|
+
abortController.abort();
|
|
506
|
+
abortController = null;
|
|
507
|
+
}
|
|
508
|
+
currentSuggestion = "";
|
|
509
|
+
}
|
|
510
|
+
async function requestCompletion(context, view) {
|
|
511
|
+
const service = getService();
|
|
512
|
+
if (!service) return;
|
|
513
|
+
if (abortController) abortController.abort();
|
|
514
|
+
abortController = new AbortController();
|
|
515
|
+
currentSuggestion = "";
|
|
516
|
+
try {
|
|
517
|
+
await service.streamChat({
|
|
518
|
+
messages: [{
|
|
519
|
+
role: "system",
|
|
520
|
+
content: systemPrompt
|
|
521
|
+
}, {
|
|
522
|
+
role: "user",
|
|
523
|
+
content: context
|
|
524
|
+
}],
|
|
525
|
+
temperature: .3,
|
|
526
|
+
maxTokens: 150
|
|
527
|
+
}, (chunk) => {
|
|
528
|
+
if (abortController?.signal.aborted) return;
|
|
529
|
+
currentSuggestion += chunk;
|
|
530
|
+
if (autocompleteKey.getState(view.state)) view.dispatch(view.state.tr.setMeta(autocompleteKey, {
|
|
531
|
+
type: "update-suggestion",
|
|
532
|
+
suggestion: currentSuggestion
|
|
533
|
+
}));
|
|
534
|
+
});
|
|
535
|
+
} catch {} finally {
|
|
536
|
+
abortController = null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return new Plugin({
|
|
540
|
+
key: autocompleteKey,
|
|
541
|
+
state: {
|
|
542
|
+
init() {
|
|
543
|
+
return {
|
|
544
|
+
decorations: DecorationSet.empty,
|
|
545
|
+
suggestion: "",
|
|
546
|
+
loading: false,
|
|
547
|
+
triggerPos: -1,
|
|
548
|
+
enabled: isEnabled
|
|
549
|
+
};
|
|
550
|
+
},
|
|
551
|
+
apply(tr, prev) {
|
|
552
|
+
const meta = tr.getMeta(autocompleteKey);
|
|
553
|
+
if (meta?.type === "set-enabled") {
|
|
554
|
+
isEnabled = meta.enabled;
|
|
555
|
+
clearPending();
|
|
556
|
+
return {
|
|
557
|
+
...prev,
|
|
558
|
+
decorations: DecorationSet.empty,
|
|
559
|
+
suggestion: "",
|
|
560
|
+
loading: false,
|
|
561
|
+
triggerPos: -1,
|
|
562
|
+
enabled: isEnabled
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (meta?.type === "clear") {
|
|
566
|
+
clearPending();
|
|
567
|
+
return {
|
|
568
|
+
...prev,
|
|
569
|
+
decorations: DecorationSet.empty,
|
|
570
|
+
suggestion: "",
|
|
571
|
+
loading: false,
|
|
572
|
+
triggerPos: -1
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
if (meta?.type === "update-suggestion") {
|
|
576
|
+
const suggestion = meta.suggestion;
|
|
577
|
+
const pos = prev.triggerPos;
|
|
578
|
+
if (!suggestion || pos < 0) return {
|
|
579
|
+
...prev,
|
|
580
|
+
suggestion: "",
|
|
581
|
+
decorations: DecorationSet.empty,
|
|
582
|
+
loading: false
|
|
583
|
+
};
|
|
584
|
+
const deco = createGhostTextDecoration(pos, suggestion);
|
|
585
|
+
return {
|
|
586
|
+
...prev,
|
|
587
|
+
suggestion,
|
|
588
|
+
loading: true,
|
|
589
|
+
decorations: DecorationSet.create(tr.doc, [deco])
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (meta?.type === "show-suggestion") {
|
|
593
|
+
const suggestion = meta.suggestion;
|
|
594
|
+
const pos = meta.pos;
|
|
595
|
+
if (!suggestion) return {
|
|
596
|
+
...prev,
|
|
597
|
+
suggestion: "",
|
|
598
|
+
decorations: DecorationSet.empty,
|
|
599
|
+
loading: false
|
|
600
|
+
};
|
|
601
|
+
const deco = createGhostTextDecoration(pos, suggestion);
|
|
602
|
+
return {
|
|
603
|
+
...prev,
|
|
604
|
+
suggestion,
|
|
605
|
+
loading: false,
|
|
606
|
+
triggerPos: pos,
|
|
607
|
+
decorations: DecorationSet.create(tr.doc, [deco])
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
if (!isEnabled) return prev;
|
|
611
|
+
if (tr.docChanged) {
|
|
612
|
+
clearPending();
|
|
613
|
+
return {
|
|
614
|
+
...prev,
|
|
615
|
+
decorations: DecorationSet.empty,
|
|
616
|
+
suggestion: "",
|
|
617
|
+
loading: false,
|
|
618
|
+
triggerPos: -1
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return prev;
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
props: {
|
|
625
|
+
decorations(state) {
|
|
626
|
+
return autocompleteKey.getState(state)?.decorations ?? DecorationSet.empty;
|
|
627
|
+
},
|
|
628
|
+
handleKeyDown(view, event) {
|
|
629
|
+
const pluginState = autocompleteKey.getState(view.state);
|
|
630
|
+
if (!pluginState?.suggestion) return false;
|
|
631
|
+
if (event.key === "Tab") {
|
|
632
|
+
event.preventDefault();
|
|
633
|
+
const suggestion = pluginState.suggestion;
|
|
634
|
+
const triggerPos = pluginState.triggerPos;
|
|
635
|
+
clearPending();
|
|
636
|
+
if (suggestion && triggerPos >= 0) {
|
|
637
|
+
const tr = view.state.tr.insertText(suggestion, triggerPos);
|
|
638
|
+
view.dispatch(tr);
|
|
639
|
+
}
|
|
640
|
+
view.dispatch(view.state.tr.setMeta(autocompleteKey, { type: "clear" }));
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
if (event.key === "Escape") {
|
|
644
|
+
event.preventDefault();
|
|
645
|
+
clearPending();
|
|
646
|
+
view.dispatch(view.state.tr.setMeta(autocompleteKey, { type: "clear" }));
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
if (event.key !== "Tab" && event.key !== "Escape") {
|
|
650
|
+
clearPending();
|
|
651
|
+
view.dispatch(view.state.tr.setMeta(autocompleteKey, { type: "clear" }));
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
view(_editorView) {
|
|
657
|
+
return {
|
|
658
|
+
update(view) {
|
|
659
|
+
if (!isEnabled) return;
|
|
660
|
+
if (!getService()) return;
|
|
661
|
+
if (autocompleteKey.getState(view.state)?.suggestion) return;
|
|
662
|
+
const { text, pos } = getContextBeforeCursor(view.state, maxContextChars);
|
|
663
|
+
if (!shouldTrigger(text, minTriggerLength)) return;
|
|
664
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
665
|
+
lastTriggerPos = pos;
|
|
666
|
+
debounceTimer = setTimeout(() => {
|
|
667
|
+
if (autocompleteKey.getState(view.state)?.suggestion) return;
|
|
668
|
+
requestCompletion(text, view).then(() => {
|
|
669
|
+
if (currentSuggestion && !abortController?.signal.aborted) view.dispatch(view.state.tr.setMeta(autocompleteKey, {
|
|
670
|
+
type: "show-suggestion",
|
|
671
|
+
suggestion: currentSuggestion,
|
|
672
|
+
pos: lastTriggerPos
|
|
673
|
+
}));
|
|
674
|
+
});
|
|
675
|
+
}, debounceMs);
|
|
676
|
+
},
|
|
677
|
+
destroy() {
|
|
678
|
+
clearPending();
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function setAutocompleteEnabled(view, enabled) {
|
|
685
|
+
view.dispatch(view.state.tr.setMeta(autocompleteKey, {
|
|
686
|
+
type: "set-enabled",
|
|
687
|
+
enabled
|
|
688
|
+
}));
|
|
689
|
+
}
|
|
690
|
+
//#endregion
|
|
691
|
+
//#region src/react/ai-autocomplete.tsx
|
|
692
|
+
var STORAGE_KEY = "mibao-ai-config";
|
|
693
|
+
function createAIAutocompletePlugin(holder, config) {
|
|
694
|
+
return createAutocompletePlugin({
|
|
695
|
+
getService: () => holder.service,
|
|
696
|
+
debounceMs: config?.debounceMs,
|
|
697
|
+
minTriggerLength: config?.minTriggerLength
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
var AIAutocomplete = forwardRef(function AIAutocomplete({ editor, enabled = false }, ref) {
|
|
701
|
+
const [active, setActive] = useState(enabled);
|
|
702
|
+
const viewRef = useRef(editor.view);
|
|
703
|
+
viewRef.current = editor.view;
|
|
704
|
+
const holderRef = useRef(null);
|
|
705
|
+
const serviceRef = useRef(null);
|
|
706
|
+
const initService = useCallback(() => {
|
|
707
|
+
const holder = window.__aiAutocompleteHolder;
|
|
708
|
+
if (!holder) return;
|
|
709
|
+
const config = loadAIConfig();
|
|
710
|
+
if (!config) {
|
|
711
|
+
if (serviceRef.current) {
|
|
712
|
+
serviceRef.current.close();
|
|
713
|
+
serviceRef.current = null;
|
|
714
|
+
holder.service = null;
|
|
715
|
+
}
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (serviceRef.current) serviceRef.current.close();
|
|
719
|
+
const service = new AIService(config);
|
|
720
|
+
serviceRef.current = service;
|
|
721
|
+
holder.service = service;
|
|
722
|
+
holderRef.current = holder;
|
|
723
|
+
}, []);
|
|
724
|
+
useEffect(() => {
|
|
725
|
+
initService();
|
|
726
|
+
const handleStorage = (e) => {
|
|
727
|
+
if (e.key === STORAGE_KEY) initService();
|
|
728
|
+
};
|
|
729
|
+
window.addEventListener("storage", handleStorage);
|
|
730
|
+
return () => {
|
|
731
|
+
window.removeEventListener("storage", handleStorage);
|
|
732
|
+
if (serviceRef.current) {
|
|
733
|
+
serviceRef.current.close();
|
|
734
|
+
serviceRef.current = null;
|
|
735
|
+
const holder = window.__aiAutocompleteHolder;
|
|
736
|
+
if (holder) holder.service = null;
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}, [initService]);
|
|
740
|
+
useEffect(() => {
|
|
741
|
+
if (!viewRef.current) return;
|
|
742
|
+
setAutocompleteEnabled(viewRef.current, active);
|
|
743
|
+
}, [active]);
|
|
744
|
+
useImperativeHandle(ref, () => ({
|
|
745
|
+
setEnabled: (v) => setActive(v),
|
|
746
|
+
isEnabled: () => active
|
|
747
|
+
}), [active]);
|
|
748
|
+
return null;
|
|
749
|
+
});
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region src/react/word-count-display.tsx
|
|
752
|
+
function WordCountDisplay({ editor, className, showDetails = false }) {
|
|
753
|
+
const containerRef = useRef(null);
|
|
754
|
+
const compRef = useRef(null);
|
|
755
|
+
useEffect(() => {
|
|
756
|
+
if (!containerRef.current || compRef.current) return;
|
|
757
|
+
const comp = new WordCountDisplay$1(createEditorAdapter(editor), { showDetails });
|
|
758
|
+
comp.mount(containerRef.current);
|
|
759
|
+
compRef.current = comp;
|
|
760
|
+
return () => {
|
|
761
|
+
comp.destroy();
|
|
762
|
+
compRef.current = null;
|
|
763
|
+
};
|
|
764
|
+
}, [editor]);
|
|
765
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
766
|
+
ref: containerRef,
|
|
767
|
+
className
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
//#endregion
|
|
771
|
+
//#region src/react/toc-panel.tsx
|
|
772
|
+
function TocPanel({ editor, className, title, onItemClick }) {
|
|
773
|
+
const containerRef = useRef(null);
|
|
774
|
+
const compRef = useRef(null);
|
|
775
|
+
useEffect(() => {
|
|
776
|
+
if (!containerRef.current || compRef.current) return;
|
|
777
|
+
const comp = new TocPanel$1(createEditorAdapter(editor), {
|
|
778
|
+
title,
|
|
779
|
+
onItemClick
|
|
780
|
+
});
|
|
781
|
+
comp.mount(containerRef.current);
|
|
782
|
+
compRef.current = comp;
|
|
783
|
+
return () => {
|
|
784
|
+
comp.destroy();
|
|
785
|
+
compRef.current = null;
|
|
786
|
+
};
|
|
787
|
+
}, [editor]);
|
|
788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
789
|
+
ref: containerRef,
|
|
790
|
+
className
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/react/shortcut-panel.tsx
|
|
795
|
+
var ShortcutPanel = forwardRef(function ShortcutPanel({ editor, className, shortcuts }, ref) {
|
|
796
|
+
const containerRef = useRef(null);
|
|
797
|
+
const compRef = useRef(null);
|
|
798
|
+
useEffect(() => {
|
|
799
|
+
if (!containerRef.current || compRef.current) return;
|
|
800
|
+
const comp = new ShortcutPanel$1(createEditorAdapter(editor), { shortcuts });
|
|
801
|
+
comp.mount(containerRef.current);
|
|
802
|
+
compRef.current = comp;
|
|
803
|
+
return () => {
|
|
804
|
+
comp.destroy();
|
|
805
|
+
compRef.current = null;
|
|
806
|
+
};
|
|
807
|
+
}, [editor]);
|
|
808
|
+
useImperativeHandle(ref, () => ({
|
|
809
|
+
open: () => compRef.current?.open(),
|
|
810
|
+
close: () => compRef.current?.close()
|
|
811
|
+
}), []);
|
|
812
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
813
|
+
ref: containerRef,
|
|
814
|
+
className
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
//#endregion
|
|
818
|
+
export { AIAutocomplete, AIMenu, AIWriter, BubbleMenu, DEFAULT_TOOLBAR_CONFIG, DragHandle, EditorContent, OPTIONAL_TOOLBAR_ITEMS, ShortcutPanel, TocPanel, Toolbar, WordCountDisplay, createAIAutocompletePlugin, createToolbarConfig, exportAsHTML, exportAsJSON, exportAsMarkdown, exportAsPlainText, useEditor };
|
|
819
|
+
|
|
820
|
+
//# sourceMappingURL=index.esm.js.map
|