@lobehub/editor 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/es/editor-kernel/kernel.d.ts +3 -1
- package/es/editor-kernel/kernel.js +27 -8
- package/es/editor-kernel/react/useEditable.d.ts +3 -0
- package/es/editor-kernel/react/useEditable.js +32 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/plugins/auto-complete/index.d.ts +2 -0
- package/es/plugins/auto-complete/index.js +2 -0
- package/es/plugins/auto-complete/node/placeholderNode.d.ts +30 -0
- package/es/plugins/auto-complete/node/placeholderNode.js +171 -0
- package/es/plugins/auto-complete/plugin/index.d.ts +17 -0
- package/es/plugins/auto-complete/plugin/index.js +398 -0
- package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.d.ts +4 -0
- package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.js +35 -0
- package/es/plugins/auto-complete/react/index.d.ts +1 -0
- package/es/plugins/auto-complete/react/index.js +1 -0
- package/es/plugins/auto-complete/react/style.d.ts +4 -0
- package/es/plugins/auto-complete/react/style.js +10 -0
- package/es/plugins/auto-complete/react/type.d.ts +11 -0
- package/es/plugins/auto-complete/react/type.js +1 -0
- package/es/plugins/common/plugin/index.js +0 -1
- package/es/plugins/common/plugin/register.js +3 -0
- package/es/plugins/common/react/ReactPlainText.js +9 -2
- package/es/plugins/common/react/style.js +1 -1
- package/es/plugins/common/react/type.d.ts +1 -0
- package/es/plugins/image/command/index.d.ts +2 -0
- package/es/plugins/image/command/index.js +10 -2
- package/es/plugins/image/node/basie-image-node.d.ts +1 -0
- package/es/plugins/image/node/basie-image-node.js +5 -0
- package/es/plugins/image/node/block-image-node.d.ts +31 -0
- package/es/plugins/image/node/block-image-node.js +209 -0
- package/es/plugins/image/node/image-node.d.ts +3 -0
- package/es/plugins/image/node/image-node.js +17 -0
- package/es/plugins/image/plugin/index.d.ts +4 -1
- package/es/plugins/image/plugin/index.js +51 -11
- package/es/plugins/image/react/ReactImagePlugin.js +3 -1
- package/es/plugins/image/react/components/Image.d.ts +4 -3
- package/es/plugins/image/react/components/Image.js +272 -24
- package/es/plugins/image/react/components/LazyImage.d.ts +7 -1
- package/es/plugins/image/react/components/LazyImage.js +11 -3
- package/es/plugins/image/react/components/style.d.ts +40 -0
- package/es/plugins/image/react/components/style.js +43 -0
- package/es/plugins/image/react/style.d.ts +10 -0
- package/es/plugins/image/react/style.js +10 -0
- package/es/plugins/image/react/type.d.ts +2 -0
- package/es/plugins/link/index.d.ts +1 -0
- package/es/plugins/link/index.js +2 -1
- package/es/plugins/link/plugin/index.js +3 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +20 -2
- package/es/plugins/link/react/components/LinkEdit.js +4 -1
- package/es/plugins/link/react/components/LinkToolbar.d.ts +1 -0
- package/es/plugins/link/react/components/LinkToolbar.js +8 -2
- package/es/plugins/link/service/i-link-service.d.ts +11 -0
- package/es/plugins/link/service/i-link-service.js +46 -0
- package/es/plugins/markdown/service/shortcut.d.ts +7 -2
- package/es/plugins/markdown/service/shortcut.js +12 -1
- package/es/plugins/markdown/utils/index.d.ts +2 -0
- package/es/plugins/markdown/utils/index.js +4 -1
- package/es/plugins/toolbar/index.d.ts +1 -0
- package/es/plugins/toolbar/index.js +1 -0
- package/es/plugins/toolbar/react/index.d.ts +3 -0
- package/es/plugins/toolbar/react/index.js +80 -0
- package/es/plugins/toolbar/react/style.d.ts +1 -0
- package/es/plugins/toolbar/react/style.js +9 -0
- package/es/plugins/toolbar/react/type.d.ts +5 -0
- package/es/plugins/toolbar/react/type.js +1 -0
- package/es/plugins/toolbar/utils/getDOMRangeRect.d.ts +8 -0
- package/es/plugins/toolbar/utils/getDOMRangeRect.js +21 -0
- package/es/plugins/toolbar/utils/setFloatingElemPosition.d.ts +1 -0
- package/es/plugins/toolbar/utils/setFloatingElemPosition.js +54 -0
- package/es/react/ChatInput/style.js +3 -2
- package/es/react/Editor/Editor.js +2 -0
- package/es/react/Editor/type.d.ts +1 -0
- package/es/react/hooks/useEditorState/index.js +41 -33
- package/es/types/kernel.d.ts +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,12 @@ A modern, extensible rich text editor built on Meta's Lexical framework with dua
|
|
|
48
48
|
- [Setup](#setup)
|
|
49
49
|
- [Available Scripts](#available-scripts)
|
|
50
50
|
- [Debug Environment Variables](#debug-environment-variables)
|
|
51
|
+
- [Project Architecture](#project-architecture)
|
|
52
|
+
- [🤝 Contributing](#-contributing)
|
|
53
|
+
- [🔗 Links](#-links)
|
|
54
|
+
- [More Products](#more-products)
|
|
55
|
+
- [Design Resources](#design-resources)
|
|
56
|
+
- [Development Resources](#development-resources)
|
|
51
57
|
|
|
52
58
|
####
|
|
53
59
|
|
|
@@ -82,7 +88,7 @@ $ pnpm add @lobehub/editor
|
|
|
82
88
|
|
|
83
89
|
<div align="right">
|
|
84
90
|
|
|
85
|
-
[
|
|
91
|
+
\[!\[][back-to-top\]](#readme-top)
|
|
86
92
|
|
|
87
93
|
</div>
|
|
88
94
|
|
|
@@ -231,7 +237,7 @@ editor.dispatchCommand(INSERT_HEADING_COMMAND, { tag: 'h2' });
|
|
|
231
237
|
|
|
232
238
|
<div align="right">
|
|
233
239
|
|
|
234
|
-
[
|
|
240
|
+
\[!\[][back-to-top\]](#readme-top)
|
|
235
241
|
|
|
236
242
|
</div>
|
|
237
243
|
|
|
@@ -390,7 +396,7 @@ CLEAR_FORMAT_COMMAND;
|
|
|
390
396
|
|
|
391
397
|
<div align="right">
|
|
392
398
|
|
|
393
|
-
[
|
|
399
|
+
\[!\[][back-to-top\]](#readme-top)
|
|
394
400
|
|
|
395
401
|
</div>
|
|
396
402
|
|
|
@@ -483,7 +489,6 @@ DEBUG=lobe-editor:plugin:*
|
|
|
483
489
|
DEBUG=lobe-editor:service:*
|
|
484
490
|
```
|
|
485
491
|
|
|
486
|
-
|
|
487
492
|
### Project Architecture
|
|
488
493
|
|
|
489
494
|
```
|
|
@@ -22,6 +22,7 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
|
|
|
22
22
|
private editor?;
|
|
23
23
|
constructor();
|
|
24
24
|
getHistoryState(): HistoryState;
|
|
25
|
+
isEditable(): boolean;
|
|
25
26
|
private detectDevelopmentMode;
|
|
26
27
|
/**
|
|
27
28
|
* Globally enable or disable hot reload mode for all kernel instances
|
|
@@ -35,7 +36,8 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
|
|
|
35
36
|
getLexicalEditor(): LexicalEditor | null;
|
|
36
37
|
destroy(): void;
|
|
37
38
|
getRootElement(): HTMLElement | null;
|
|
38
|
-
setRootElement(dom: HTMLElement): LexicalEditor;
|
|
39
|
+
setRootElement(dom: HTMLElement, editable?: boolean): LexicalEditor;
|
|
40
|
+
setEditable(editable: boolean): void;
|
|
39
41
|
initNodeEditor(): LexicalEditor;
|
|
40
42
|
setDocument(type: string, content: any): void;
|
|
41
43
|
focus(): void;
|
|
@@ -64,6 +64,12 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
64
64
|
value: function getHistoryState() {
|
|
65
65
|
return this.historyState;
|
|
66
66
|
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "isEditable",
|
|
69
|
+
value: function isEditable() {
|
|
70
|
+
var _this$editor;
|
|
71
|
+
return ((_this$editor = this.editor) === null || _this$editor === void 0 ? void 0 : _this$editor.isEditable()) || false;
|
|
72
|
+
}
|
|
67
73
|
}, {
|
|
68
74
|
key: "detectDevelopmentMode",
|
|
69
75
|
value: function detectDevelopmentMode() {
|
|
@@ -119,9 +125,9 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
119
125
|
}, {
|
|
120
126
|
key: "destroy",
|
|
121
127
|
value: function destroy() {
|
|
122
|
-
var _this$
|
|
128
|
+
var _this$editor2;
|
|
123
129
|
this.logger.info("\uD83D\uDDD1\uFE0F Destroying editor with ".concat(this.pluginsInstances.length, " plugins"));
|
|
124
|
-
(_this$
|
|
130
|
+
(_this$editor2 = this.editor) === null || _this$editor2 === void 0 || _this$editor2.setEditorState(createEmptyEditorState());
|
|
125
131
|
this.dataTypeMap.clear();
|
|
126
132
|
this.pluginsInstances.forEach(function (plugin) {
|
|
127
133
|
if (plugin.destroy) {
|
|
@@ -138,13 +144,14 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
138
144
|
}, {
|
|
139
145
|
key: "getRootElement",
|
|
140
146
|
value: function getRootElement() {
|
|
141
|
-
var _this$
|
|
142
|
-
return ((_this$
|
|
147
|
+
var _this$editor3;
|
|
148
|
+
return ((_this$editor3 = this.editor) === null || _this$editor3 === void 0 ? void 0 : _this$editor3.getRootElement()) || null;
|
|
143
149
|
}
|
|
144
150
|
}, {
|
|
145
151
|
key: "setRootElement",
|
|
146
152
|
value: function setRootElement(dom) {
|
|
147
153
|
var _this2 = this;
|
|
154
|
+
var editable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
148
155
|
// Check if editor is already initialized to prevent re-initialization
|
|
149
156
|
if (this.editor) {
|
|
150
157
|
this.logger.warn('[Editor] Editor is already initialized, updating root element only');
|
|
@@ -173,6 +180,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
173
180
|
var editor = this.editor = createEditor({
|
|
174
181
|
// @ts-expect-error Inject into lexical editor instance
|
|
175
182
|
__kernel: this,
|
|
183
|
+
editable: editable,
|
|
176
184
|
namespace: 'lobehub',
|
|
177
185
|
nodes: this.nodes,
|
|
178
186
|
onError: function onError(error) {
|
|
@@ -191,6 +199,17 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
191
199
|
this.emit('initialized', editor);
|
|
192
200
|
return this.editor;
|
|
193
201
|
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "setEditable",
|
|
204
|
+
value: function setEditable(editable) {
|
|
205
|
+
if (!this.editor) {
|
|
206
|
+
this.logger.error('❌ Editor not initialized');
|
|
207
|
+
throw new Error("Editor is not initialized.");
|
|
208
|
+
}
|
|
209
|
+
this.editor.setEditable(editable);
|
|
210
|
+
this.emit('editableChange', editable);
|
|
211
|
+
this.logger.debug("\u270F\uFE0F Editor editable set to ".concat(editable));
|
|
212
|
+
}
|
|
194
213
|
}, {
|
|
195
214
|
key: "initNodeEditor",
|
|
196
215
|
value: function initNodeEditor() {
|
|
@@ -253,14 +272,14 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
253
272
|
}, {
|
|
254
273
|
key: "focus",
|
|
255
274
|
value: function focus() {
|
|
256
|
-
var _this$
|
|
257
|
-
(_this$
|
|
275
|
+
var _this$editor4;
|
|
276
|
+
(_this$editor4 = this.editor) === null || _this$editor4 === void 0 || _this$editor4.focus();
|
|
258
277
|
}
|
|
259
278
|
}, {
|
|
260
279
|
key: "blur",
|
|
261
280
|
value: function blur() {
|
|
262
|
-
var _this$
|
|
263
|
-
(_this$
|
|
281
|
+
var _this$editor5;
|
|
282
|
+
(_this$editor5 = this.editor) === null || _this$editor5 === void 0 || _this$editor5.blur();
|
|
264
283
|
}
|
|
265
284
|
}, {
|
|
266
285
|
key: "getDocument",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
import { useEffect, useState } from 'react';
|
|
10
|
+
import { useLexicalComposerContext } from "./react-context";
|
|
11
|
+
export var useEditable = function useEditable() {
|
|
12
|
+
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
13
|
+
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
14
|
+
editor = _useLexicalComposerCo2[0];
|
|
15
|
+
// Don't render portal on server side
|
|
16
|
+
var _useState = useState(editor.isEditable()),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
editable = _useState2[0],
|
|
19
|
+
setEditable = _useState2[1];
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
var updateEditable = function updateEditable(newEditable) {
|
|
22
|
+
setEditable(newEditable);
|
|
23
|
+
};
|
|
24
|
+
editor.on('editableChange', updateEditable);
|
|
25
|
+
return function () {
|
|
26
|
+
editor.off('editableChange', updateEditable);
|
|
27
|
+
};
|
|
28
|
+
}, [editor]);
|
|
29
|
+
return {
|
|
30
|
+
editable: editable
|
|
31
|
+
};
|
|
32
|
+
};
|
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './editor-kernel';
|
|
2
2
|
export * from './editor-kernel/react';
|
|
3
|
+
export * from './plugins/auto-complete';
|
|
3
4
|
export * from './plugins/code';
|
|
4
5
|
export * from './plugins/codeblock';
|
|
5
6
|
export * from './plugins/common';
|
|
@@ -14,6 +15,7 @@ export * from './plugins/math';
|
|
|
14
15
|
export * from './plugins/mention';
|
|
15
16
|
export * from './plugins/slash';
|
|
16
17
|
export * from './plugins/table';
|
|
18
|
+
export * from './plugins/toolbar';
|
|
17
19
|
export * from './plugins/upload';
|
|
18
20
|
export type { IEditor } from './types';
|
|
19
21
|
export * from './types/hotkey';
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./editor-kernel";
|
|
2
2
|
export * from "./editor-kernel/react";
|
|
3
|
+
export * from "./plugins/auto-complete";
|
|
3
4
|
export * from "./plugins/code";
|
|
4
5
|
export * from "./plugins/codeblock";
|
|
5
6
|
export * from "./plugins/common";
|
|
@@ -14,6 +15,7 @@ export * from "./plugins/math";
|
|
|
14
15
|
export * from "./plugins/mention";
|
|
15
16
|
export * from "./plugins/slash";
|
|
16
17
|
export * from "./plugins/table";
|
|
18
|
+
export * from "./plugins/toolbar";
|
|
17
19
|
export * from "./plugins/upload";
|
|
18
20
|
// Hotkey utilities
|
|
19
21
|
export * from "./types/hotkey";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EditorConfig, ElementNode, SerializedElementNode } from 'lexical';
|
|
2
|
+
export type SerializedPlaceholderNode = SerializedElementNode;
|
|
3
|
+
export declare class PlaceholderNode extends ElementNode {
|
|
4
|
+
static getType(): string;
|
|
5
|
+
static clone(node: PlaceholderNode): PlaceholderNode;
|
|
6
|
+
static importJSON(serializedNode: SerializedPlaceholderNode): PlaceholderNode;
|
|
7
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
8
|
+
updateDOM(prevNode: unknown, dom: HTMLElement, config: EditorConfig): boolean;
|
|
9
|
+
canBeEmpty(): boolean;
|
|
10
|
+
isCardLike(): boolean;
|
|
11
|
+
isInline(): boolean;
|
|
12
|
+
canIndent(): boolean;
|
|
13
|
+
canInsertTextBefore(): boolean;
|
|
14
|
+
canInsertTextAfter(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class PlaceholderBlockNode extends ElementNode {
|
|
17
|
+
static getType(): string;
|
|
18
|
+
static clone(node: PlaceholderBlockNode): PlaceholderBlockNode;
|
|
19
|
+
static importJSON(serializedNode: SerializedPlaceholderNode): PlaceholderBlockNode;
|
|
20
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
21
|
+
updateDOM(prevNode: unknown, dom: HTMLElement, config: EditorConfig): boolean;
|
|
22
|
+
canBeEmpty(): boolean;
|
|
23
|
+
isCardLike(): boolean;
|
|
24
|
+
isInline(): boolean;
|
|
25
|
+
canIndent(): boolean;
|
|
26
|
+
canInsertTextBefore(): boolean;
|
|
27
|
+
canInsertTextAfter(): boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function $createPlaceholderNode(): PlaceholderNode;
|
|
30
|
+
export declare function $createPlaceholderBlockNode(): PlaceholderBlockNode;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
8
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
11
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
12
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
14
|
+
import { addClassNamesToElement } from '@lexical/utils';
|
|
15
|
+
import { $applyNodeReplacement, ElementNode } from 'lexical';
|
|
16
|
+
export var PlaceholderNode = /*#__PURE__*/function (_ElementNode) {
|
|
17
|
+
_inherits(PlaceholderNode, _ElementNode);
|
|
18
|
+
var _super = _createSuper(PlaceholderNode);
|
|
19
|
+
function PlaceholderNode() {
|
|
20
|
+
_classCallCheck(this, PlaceholderNode);
|
|
21
|
+
return _super.apply(this, arguments);
|
|
22
|
+
}
|
|
23
|
+
_createClass(PlaceholderNode, [{
|
|
24
|
+
key: "createDOM",
|
|
25
|
+
value: function createDOM(config) {
|
|
26
|
+
var element = document.createElement('span');
|
|
27
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-dataset
|
|
28
|
+
element.setAttribute('data-lexical-key', this.getKey());
|
|
29
|
+
addClassNamesToElement(element, config.theme.placeholderInline);
|
|
30
|
+
return element;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "updateDOM",
|
|
34
|
+
value: function updateDOM(prevNode, dom, config) {
|
|
35
|
+
// Update the class names if theme has changed
|
|
36
|
+
var prevTheme = prevNode ? prevNode : null;
|
|
37
|
+
if (prevTheme !== this) {
|
|
38
|
+
addClassNamesToElement(dom, config.theme.placeholderInline);
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "canBeEmpty",
|
|
44
|
+
value: function canBeEmpty() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "isCardLike",
|
|
49
|
+
value: function isCardLike() {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "isInline",
|
|
54
|
+
value: function isInline() {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "canIndent",
|
|
59
|
+
value: function canIndent() {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "canInsertTextBefore",
|
|
64
|
+
value: function canInsertTextBefore() {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "canInsertTextAfter",
|
|
69
|
+
value: function canInsertTextAfter() {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}], [{
|
|
73
|
+
key: "getType",
|
|
74
|
+
value: function getType() {
|
|
75
|
+
return 'PlaceholderInline';
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "clone",
|
|
79
|
+
value: function clone(node) {
|
|
80
|
+
return new PlaceholderNode(node.__key);
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "importJSON",
|
|
84
|
+
value: function importJSON(serializedNode) {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
86
|
+
return $createPlaceholderNode().updateFromJSON(serializedNode);
|
|
87
|
+
}
|
|
88
|
+
}]);
|
|
89
|
+
return PlaceholderNode;
|
|
90
|
+
}(ElementNode);
|
|
91
|
+
export var PlaceholderBlockNode = /*#__PURE__*/function (_ElementNode2) {
|
|
92
|
+
_inherits(PlaceholderBlockNode, _ElementNode2);
|
|
93
|
+
var _super2 = _createSuper(PlaceholderBlockNode);
|
|
94
|
+
function PlaceholderBlockNode() {
|
|
95
|
+
_classCallCheck(this, PlaceholderBlockNode);
|
|
96
|
+
return _super2.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
_createClass(PlaceholderBlockNode, [{
|
|
99
|
+
key: "createDOM",
|
|
100
|
+
value: function createDOM(config) {
|
|
101
|
+
var element = document.createElement('div');
|
|
102
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-dataset
|
|
103
|
+
element.setAttribute('data-lexical-key', this.getKey());
|
|
104
|
+
addClassNamesToElement(element, config.theme.placeholderBlock);
|
|
105
|
+
return element;
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "updateDOM",
|
|
109
|
+
value: function updateDOM(prevNode, dom, config) {
|
|
110
|
+
// Update the class names if theme has changed
|
|
111
|
+
var prevTheme = prevNode ? prevNode : null;
|
|
112
|
+
if (prevTheme !== this) {
|
|
113
|
+
addClassNamesToElement(dom, config.theme.placeholderBlock);
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "canBeEmpty",
|
|
119
|
+
value: function canBeEmpty() {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "isCardLike",
|
|
124
|
+
value: function isCardLike() {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "isInline",
|
|
129
|
+
value: function isInline() {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "canIndent",
|
|
134
|
+
value: function canIndent() {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}, {
|
|
138
|
+
key: "canInsertTextBefore",
|
|
139
|
+
value: function canInsertTextBefore() {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "canInsertTextAfter",
|
|
144
|
+
value: function canInsertTextAfter() {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}], [{
|
|
148
|
+
key: "getType",
|
|
149
|
+
value: function getType() {
|
|
150
|
+
return 'PlaceholderBlock';
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "clone",
|
|
154
|
+
value: function clone(node) {
|
|
155
|
+
return new PlaceholderBlockNode(node.__key);
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
key: "importJSON",
|
|
159
|
+
value: function importJSON(serializedNode) {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
161
|
+
return $createPlaceholderBlockNode().updateFromJSON(serializedNode);
|
|
162
|
+
}
|
|
163
|
+
}]);
|
|
164
|
+
return PlaceholderBlockNode;
|
|
165
|
+
}(ElementNode);
|
|
166
|
+
export function $createPlaceholderNode() {
|
|
167
|
+
return $applyNodeReplacement(new PlaceholderNode());
|
|
168
|
+
}
|
|
169
|
+
export function $createPlaceholderBlockNode() {
|
|
170
|
+
return $applyNodeReplacement(new PlaceholderBlockNode());
|
|
171
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IEditor, IEditorPluginConstructor } from "../../../types";
|
|
2
|
+
export interface AutoCompletePluginOptions {
|
|
3
|
+
/** Delay in milliseconds before triggering auto-complete (default: 1000ms) */
|
|
4
|
+
delay?: number;
|
|
5
|
+
onAutoComplete?: (opt: {
|
|
6
|
+
abortSignal: AbortSignal;
|
|
7
|
+
afterText: string;
|
|
8
|
+
editor: IEditor;
|
|
9
|
+
input: string;
|
|
10
|
+
selectionType: string;
|
|
11
|
+
}) => Promise<string | null>;
|
|
12
|
+
theme?: {
|
|
13
|
+
placeholderBlock?: string;
|
|
14
|
+
placeholderInline?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare const AutoCompletePlugin: IEditorPluginConstructor<AutoCompletePluginOptions>;
|