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