@block-kit/plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/align/index.d.ts +12 -0
- package/dist/es/align/index.js +25 -0
- package/dist/es/align/types/index.d.ts +1 -0
- package/dist/es/align/types/index.js +3 -0
- package/dist/es/background/index.d.ts +12 -0
- package/dist/es/background/index.js +27 -0
- package/dist/es/background/types/index.d.ts +1 -0
- package/dist/es/background/types/index.js +3 -0
- package/dist/es/bold/index.d.ts +15 -0
- package/dist/es/bold/index.js +46 -0
- package/dist/es/bold/types/index.d.ts +1 -0
- package/dist/es/bold/types/index.js +3 -0
- package/dist/es/bullet-list/index.d.ts +16 -0
- package/dist/es/bullet-list/index.js +149 -0
- package/dist/es/bullet-list/types/index.d.ts +6 -0
- package/dist/es/bullet-list/types/index.js +8 -0
- package/dist/es/bullet-list/utils/is.d.ts +6 -0
- package/dist/es/bullet-list/view/list.d.ts +9 -0
- package/dist/es/divider/index.d.ts +17 -0
- package/dist/es/divider/index.js +60 -0
- package/dist/es/divider/types/index.d.ts +1 -0
- package/dist/es/divider/types/index.js +3 -0
- package/dist/es/dom-71a99400.js +45 -0
- package/dist/es/emoji/index.d.ts +16 -0
- package/dist/es/emoji/index.js +51 -0
- package/dist/es/emoji/types/index.d.ts +1 -0
- package/dist/es/emoji/types/index.js +3 -0
- package/dist/es/font-color/index.d.ts +12 -0
- package/dist/es/font-color/index.js +27 -0
- package/dist/es/font-color/types/index.d.ts +1 -0
- package/dist/es/font-color/types/index.js +3 -0
- package/dist/es/font-size/index.d.ts +12 -0
- package/dist/es/font-size/index.js +28 -0
- package/dist/es/font-size/types/index.d.ts +1 -0
- package/dist/es/font-size/types/index.js +3 -0
- package/dist/es/heading/index.d.ts +13 -0
- package/dist/es/heading/index.js +33 -0
- package/dist/es/heading/types/index.d.ts +1 -0
- package/dist/es/heading/types/index.js +3 -0
- package/dist/es/image/index.d.ts +21 -0
- package/dist/es/image/index.js +245 -0
- package/dist/es/image/types/index.d.ts +12 -0
- package/dist/es/image/types/index.js +14 -0
- package/dist/es/image/view/image.d.ts +10 -0
- package/dist/es/image/view/wrapper.d.ts +10 -0
- package/dist/es/indent/index.d.ts +14 -0
- package/dist/es/indent/index.js +67 -0
- package/dist/es/indent/types/index.d.ts +1 -0
- package/dist/es/indent/types/index.js +3 -0
- package/dist/es/index-1e46887d.js +205 -0
- package/dist/es/index-ddc2e5ac.js +493 -0
- package/dist/es/index.css +1 -0
- package/dist/es/index.d.ts +50 -0
- package/dist/es/index.js +64 -0
- package/dist/es/inline-code/index.d.ts +14 -0
- package/dist/es/inline-code/index.js +46 -0
- package/dist/es/inline-code/types/index.d.ts +1 -0
- package/dist/es/inline-code/types/index.js +3 -0
- package/dist/es/is-2b264ec8.js +11 -0
- package/dist/es/is-3de778e2.js +15 -0
- package/dist/es/is-7f3ae820.js +12 -0
- package/dist/es/italic/index.d.ts +15 -0
- package/dist/es/italic/index.js +43 -0
- package/dist/es/italic/types/index.d.ts +1 -0
- package/dist/es/italic/types/index.js +3 -0
- package/dist/es/line-height/index.d.ts +12 -0
- package/dist/es/line-height/index.js +25 -0
- package/dist/es/line-height/types/index.d.ts +1 -0
- package/dist/es/line-height/types/index.js +3 -0
- package/dist/es/link/index.d.ts +17 -0
- package/dist/es/link/index.js +64 -0
- package/dist/es/link/types/index.d.ts +3 -0
- package/dist/es/link/types/index.js +7 -0
- package/dist/es/link/view/a.d.ts +6 -0
- package/dist/es/marks-ac0ec630.js +46 -0
- package/dist/es/mention/index.d.ts +16 -0
- package/dist/es/mention/index.js +13 -0
- package/dist/es/mention/modules/suggest.d.ts +18 -0
- package/dist/es/mention/types/index.d.ts +2 -0
- package/dist/es/mention/types/index.js +4 -0
- package/dist/es/mention/utils/constant.d.ts +2 -0
- package/dist/es/mention/view/suggest.d.ts +9 -0
- package/dist/es/order-list/index.d.ts +16 -0
- package/dist/es/order-list/index.js +323 -0
- package/dist/es/order-list/types/index.d.ts +8 -0
- package/dist/es/order-list/types/index.js +10 -0
- package/dist/es/order-list/utils/format.d.ts +6 -0
- package/dist/es/order-list/utils/is.d.ts +6 -0
- package/dist/es/order-list/utils/serial.d.ts +10 -0
- package/dist/es/order-list/view/list.d.ts +10 -0
- package/dist/es/quote/index.d.ts +17 -0
- package/dist/es/quote/index.js +130 -0
- package/dist/es/quote/types/index.d.ts +1 -0
- package/dist/es/quote/types/index.js +3 -0
- package/dist/es/selection-badfb0bc.js +81 -0
- package/dist/es/shared/components/selection.d.ts +26 -0
- package/dist/es/shared/icons/divider.d.ts +2 -0
- package/dist/es/shared/icons/emoji.d.ts +2 -0
- package/dist/es/shared/icons/font-color.d.ts +2 -0
- package/dist/es/shared/icons/font-size.d.ts +2 -0
- package/dist/es/shared/icons/justify.d.ts +2 -0
- package/dist/es/shared/icons/line-height.d.ts +2 -0
- package/dist/es/shared/icons/text.d.ts +2 -0
- package/dist/es/shared/modules/selection.d.ts +12 -0
- package/dist/es/shared/utils/dom.d.ts +26 -0
- package/dist/es/shared/utils/event.d.ts +8 -0
- package/dist/es/shared/utils/is.d.ts +4 -0
- package/dist/es/shortcut/index.d.ts +14 -0
- package/dist/es/shortcut/index.js +85 -0
- package/dist/es/shortcut/modules/preset.d.ts +2 -0
- package/dist/es/shortcut/types/index.d.ts +10 -0
- package/dist/es/shortcut/types/index.js +3 -0
- package/dist/es/strike/index.d.ts +15 -0
- package/dist/es/strike/index.js +47 -0
- package/dist/es/strike/types/index.d.ts +1 -0
- package/dist/es/strike/types/index.js +3 -0
- package/dist/es/toolbar/context/basic.d.ts +4 -0
- package/dist/es/toolbar/context/float.d.ts +13 -0
- package/dist/es/toolbar/context/provider.d.ts +12 -0
- package/dist/es/toolbar/index.d.ts +26 -0
- package/dist/es/toolbar/index.js +34 -0
- package/dist/es/toolbar/modules/align.d.ts +2 -0
- package/dist/es/toolbar/modules/bold.d.ts +2 -0
- package/dist/es/toolbar/modules/bullet-list.d.ts +2 -0
- package/dist/es/toolbar/modules/cut.d.ts +3 -0
- package/dist/es/toolbar/modules/divider.d.ts +2 -0
- package/dist/es/toolbar/modules/emoji.d.ts +3 -0
- package/dist/es/toolbar/modules/font-color.d.ts +3 -0
- package/dist/es/toolbar/modules/font-size.d.ts +2 -0
- package/dist/es/toolbar/modules/heading.d.ts +2 -0
- package/dist/es/toolbar/modules/history.d.ts +2 -0
- package/dist/es/toolbar/modules/image.d.ts +2 -0
- package/dist/es/toolbar/modules/inline-code.d.ts +2 -0
- package/dist/es/toolbar/modules/italic.d.ts +2 -0
- package/dist/es/toolbar/modules/line-height.d.ts +3 -0
- package/dist/es/toolbar/modules/link.d.ts +5 -0
- package/dist/es/toolbar/modules/order-list.d.ts +2 -0
- package/dist/es/toolbar/modules/quote.d.ts +2 -0
- package/dist/es/toolbar/modules/strike.d.ts +2 -0
- package/dist/es/toolbar/modules/underline.d.ts +2 -0
- package/dist/es/toolbar/types/index.d.ts +8 -0
- package/dist/es/toolbar/types/index.js +7 -0
- package/dist/es/toolbar/utils/marks.d.ts +4 -0
- package/dist/es/tslib.es6-83956cc1.js +38 -0
- package/dist/es/underline/index.d.ts +15 -0
- package/dist/es/underline/index.js +45 -0
- package/dist/es/underline/types/index.d.ts +1 -0
- package/dist/es/underline/types/index.js +3 -0
- package/dist/lib/align/index.d.ts +12 -0
- package/dist/lib/align/index.js +29 -0
- package/dist/lib/align/types/index.d.ts +1 -0
- package/dist/lib/align/types/index.js +7 -0
- package/dist/lib/background/index.d.ts +12 -0
- package/dist/lib/background/index.js +31 -0
- package/dist/lib/background/types/index.d.ts +1 -0
- package/dist/lib/background/types/index.js +7 -0
- package/dist/lib/bold/index.d.ts +15 -0
- package/dist/lib/bold/index.js +50 -0
- package/dist/lib/bold/types/index.d.ts +1 -0
- package/dist/lib/bold/types/index.js +7 -0
- package/dist/lib/bullet-list/index.d.ts +16 -0
- package/dist/lib/bullet-list/index.js +153 -0
- package/dist/lib/bullet-list/types/index.d.ts +6 -0
- package/dist/lib/bullet-list/types/index.js +14 -0
- package/dist/lib/bullet-list/utils/is.d.ts +6 -0
- package/dist/lib/bullet-list/view/list.d.ts +9 -0
- package/dist/lib/divider/index.d.ts +17 -0
- package/dist/lib/divider/index.js +64 -0
- package/dist/lib/divider/types/index.d.ts +1 -0
- package/dist/lib/divider/types/index.js +7 -0
- package/dist/lib/dom-cb8b8e40.js +50 -0
- package/dist/lib/emoji/index.d.ts +16 -0
- package/dist/lib/emoji/index.js +59 -0
- package/dist/lib/emoji/types/index.d.ts +1 -0
- package/dist/lib/emoji/types/index.js +7 -0
- package/dist/lib/font-color/index.d.ts +12 -0
- package/dist/lib/font-color/index.js +31 -0
- package/dist/lib/font-color/types/index.d.ts +1 -0
- package/dist/lib/font-color/types/index.js +7 -0
- package/dist/lib/font-size/index.d.ts +12 -0
- package/dist/lib/font-size/index.js +32 -0
- package/dist/lib/font-size/types/index.d.ts +1 -0
- package/dist/lib/font-size/types/index.js +7 -0
- package/dist/lib/heading/index.d.ts +13 -0
- package/dist/lib/heading/index.js +37 -0
- package/dist/lib/heading/types/index.d.ts +1 -0
- package/dist/lib/heading/types/index.js +7 -0
- package/dist/lib/image/index.d.ts +21 -0
- package/dist/lib/image/index.js +249 -0
- package/dist/lib/image/types/index.d.ts +12 -0
- package/dist/lib/image/types/index.js +25 -0
- package/dist/lib/image/view/image.d.ts +10 -0
- package/dist/lib/image/view/wrapper.d.ts +10 -0
- package/dist/lib/indent/index.d.ts +14 -0
- package/dist/lib/indent/index.js +71 -0
- package/dist/lib/indent/types/index.d.ts +1 -0
- package/dist/lib/indent/types/index.js +7 -0
- package/dist/lib/index-f50053bf.js +506 -0
- package/dist/lib/index-ffc4bb34.js +212 -0
- package/dist/lib/index.css +1 -0
- package/dist/lib/index.d.ts +50 -0
- package/dist/lib/index.js +141 -0
- package/dist/lib/inline-code/index.d.ts +14 -0
- package/dist/lib/inline-code/index.js +50 -0
- package/dist/lib/inline-code/types/index.d.ts +1 -0
- package/dist/lib/inline-code/types/index.js +7 -0
- package/dist/lib/is-18806678.js +14 -0
- package/dist/lib/is-473d664a.js +18 -0
- package/dist/lib/is-fa1755d0.js +13 -0
- package/dist/lib/italic/index.d.ts +15 -0
- package/dist/lib/italic/index.js +47 -0
- package/dist/lib/italic/types/index.d.ts +1 -0
- package/dist/lib/italic/types/index.js +7 -0
- package/dist/lib/line-height/index.d.ts +12 -0
- package/dist/lib/line-height/index.js +29 -0
- package/dist/lib/line-height/types/index.d.ts +1 -0
- package/dist/lib/line-height/types/index.js +7 -0
- package/dist/lib/link/index.d.ts +17 -0
- package/dist/lib/link/index.js +68 -0
- package/dist/lib/link/types/index.d.ts +3 -0
- package/dist/lib/link/types/index.js +13 -0
- package/dist/lib/link/view/a.d.ts +6 -0
- package/dist/lib/marks-a30b8a0f.js +50 -0
- package/dist/lib/mention/index.d.ts +16 -0
- package/dist/lib/mention/index.js +21 -0
- package/dist/lib/mention/modules/suggest.d.ts +18 -0
- package/dist/lib/mention/types/index.d.ts +2 -0
- package/dist/lib/mention/types/index.js +9 -0
- package/dist/lib/mention/utils/constant.d.ts +2 -0
- package/dist/lib/mention/view/suggest.d.ts +9 -0
- package/dist/lib/order-list/index.d.ts +16 -0
- package/dist/lib/order-list/index.js +327 -0
- package/dist/lib/order-list/types/index.d.ts +8 -0
- package/dist/lib/order-list/types/index.js +17 -0
- package/dist/lib/order-list/utils/format.d.ts +6 -0
- package/dist/lib/order-list/utils/is.d.ts +6 -0
- package/dist/lib/order-list/utils/serial.d.ts +10 -0
- package/dist/lib/order-list/view/list.d.ts +10 -0
- package/dist/lib/quote/index.d.ts +17 -0
- package/dist/lib/quote/index.js +134 -0
- package/dist/lib/quote/types/index.d.ts +1 -0
- package/dist/lib/quote/types/index.js +7 -0
- package/dist/lib/selection-868f15c1.js +88 -0
- package/dist/lib/shared/components/selection.d.ts +26 -0
- package/dist/lib/shared/icons/divider.d.ts +2 -0
- package/dist/lib/shared/icons/emoji.d.ts +2 -0
- package/dist/lib/shared/icons/font-color.d.ts +2 -0
- package/dist/lib/shared/icons/font-size.d.ts +2 -0
- package/dist/lib/shared/icons/justify.d.ts +2 -0
- package/dist/lib/shared/icons/line-height.d.ts +2 -0
- package/dist/lib/shared/icons/text.d.ts +2 -0
- package/dist/lib/shared/modules/selection.d.ts +12 -0
- package/dist/lib/shared/utils/dom.d.ts +26 -0
- package/dist/lib/shared/utils/event.d.ts +8 -0
- package/dist/lib/shared/utils/is.d.ts +4 -0
- package/dist/lib/shortcut/index.d.ts +14 -0
- package/dist/lib/shortcut/index.js +89 -0
- package/dist/lib/shortcut/modules/preset.d.ts +2 -0
- package/dist/lib/shortcut/types/index.d.ts +10 -0
- package/dist/lib/shortcut/types/index.js +7 -0
- package/dist/lib/strike/index.d.ts +15 -0
- package/dist/lib/strike/index.js +51 -0
- package/dist/lib/strike/types/index.d.ts +1 -0
- package/dist/lib/strike/types/index.js +7 -0
- package/dist/lib/toolbar/context/basic.d.ts +4 -0
- package/dist/lib/toolbar/context/float.d.ts +13 -0
- package/dist/lib/toolbar/context/provider.d.ts +12 -0
- package/dist/lib/toolbar/index.d.ts +26 -0
- package/dist/lib/toolbar/index.js +44 -0
- package/dist/lib/toolbar/modules/align.d.ts +2 -0
- package/dist/lib/toolbar/modules/bold.d.ts +2 -0
- package/dist/lib/toolbar/modules/bullet-list.d.ts +2 -0
- package/dist/lib/toolbar/modules/cut.d.ts +3 -0
- package/dist/lib/toolbar/modules/divider.d.ts +2 -0
- package/dist/lib/toolbar/modules/emoji.d.ts +3 -0
- package/dist/lib/toolbar/modules/font-color.d.ts +3 -0
- package/dist/lib/toolbar/modules/font-size.d.ts +2 -0
- package/dist/lib/toolbar/modules/heading.d.ts +2 -0
- package/dist/lib/toolbar/modules/history.d.ts +2 -0
- package/dist/lib/toolbar/modules/image.d.ts +2 -0
- package/dist/lib/toolbar/modules/inline-code.d.ts +2 -0
- package/dist/lib/toolbar/modules/italic.d.ts +2 -0
- package/dist/lib/toolbar/modules/line-height.d.ts +3 -0
- package/dist/lib/toolbar/modules/link.d.ts +5 -0
- package/dist/lib/toolbar/modules/order-list.d.ts +2 -0
- package/dist/lib/toolbar/modules/quote.d.ts +2 -0
- package/dist/lib/toolbar/modules/strike.d.ts +2 -0
- package/dist/lib/toolbar/modules/underline.d.ts +2 -0
- package/dist/lib/toolbar/types/index.d.ts +8 -0
- package/dist/lib/toolbar/types/index.js +12 -0
- package/dist/lib/toolbar/utils/marks.d.ts +4 -0
- package/dist/lib/tslib.es6-d44c9a95.js +41 -0
- package/dist/lib/underline/index.d.ts +15 -0
- package/dist/lib/underline/index.js +49 -0
- package/dist/lib/underline/types/index.d.ts +1 -0
- package/dist/lib/underline/types/index.js +7 -0
- package/package.json +56 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./styles/index.scss";
|
|
2
|
+
import type { Editor, SerializeContext } from "@block-kit/core";
|
|
3
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
4
|
+
import type { ReactLeafContext } from "@block-kit/react";
|
|
5
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
export declare class InlineCodePlugin extends EditorPlugin {
|
|
8
|
+
key: string;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
constructor(editor: Editor);
|
|
11
|
+
match(attrs: AttributeMap): boolean;
|
|
12
|
+
serialize(context: SerializeContext): SerializeContext;
|
|
13
|
+
renderLeaf(context: ReactLeafContext): ReactNode;
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { _ as __decorate } from '../tslib.es6-83956cc1.js';
|
|
2
|
+
import { Priority } from '@block-kit/core';
|
|
3
|
+
import { EditorPlugin } from '@block-kit/react';
|
|
4
|
+
import { INLINE_CODE } from './types/index.js';
|
|
5
|
+
|
|
6
|
+
class InlineCodePlugin extends EditorPlugin {
|
|
7
|
+
destroy() { }
|
|
8
|
+
constructor(editor) {
|
|
9
|
+
super();
|
|
10
|
+
this.key = INLINE_CODE;
|
|
11
|
+
editor.command.register(INLINE_CODE, context => {
|
|
12
|
+
const sel = editor.selection.get();
|
|
13
|
+
sel && editor.perform.applyMarks(sel, { [INLINE_CODE]: context.value });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
match(attrs) {
|
|
17
|
+
return !!attrs[INLINE_CODE];
|
|
18
|
+
}
|
|
19
|
+
serialize(context) {
|
|
20
|
+
const { op, html } = context;
|
|
21
|
+
if (op.attributes && op.attributes[INLINE_CODE]) {
|
|
22
|
+
const strong = document.createElement("code");
|
|
23
|
+
strong.appendChild(html);
|
|
24
|
+
context.html = strong;
|
|
25
|
+
}
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
renderLeaf(context) {
|
|
29
|
+
const leaf = context.leafState;
|
|
30
|
+
const prev = leaf.prev(false);
|
|
31
|
+
const next = leaf.next(false);
|
|
32
|
+
if (!prev || !prev.op.attributes || !prev.op.attributes[INLINE_CODE]) {
|
|
33
|
+
context.classList.push("block-kit-inline-code-start");
|
|
34
|
+
}
|
|
35
|
+
context.classList.push("block-kit-inline-code");
|
|
36
|
+
if (!next || !next.op.attributes || !next.op.attributes[INLINE_CODE]) {
|
|
37
|
+
context.classList.push("block-kit-inline-code-end");
|
|
38
|
+
}
|
|
39
|
+
return context.children;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
__decorate([
|
|
43
|
+
Priority(100)
|
|
44
|
+
], InlineCodePlugin.prototype, "renderLeaf", null);
|
|
45
|
+
|
|
46
|
+
export { InlineCodePlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const INLINE_CODE = "inline-code";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEOLOp } from '@block-kit/delta';
|
|
2
|
+
|
|
3
|
+
const isEmptyLine = (line) => {
|
|
4
|
+
if (!line)
|
|
5
|
+
return true;
|
|
6
|
+
const lastLeaf = line.getLastLeaf();
|
|
7
|
+
const leaves = line.getLeaves();
|
|
8
|
+
// 没有最后的叶子结点, 或者仅单个节点且最后的叶子结点是换行符
|
|
9
|
+
return !lastLeaf || (leaves.length === 1 && isEOLOp(lastLeaf.op));
|
|
10
|
+
};
|
|
11
|
+
const isKeyCode = (event, code) => {
|
|
12
|
+
return event.keyCode === code;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { isKeyCode as a, isEmptyLine as i };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LIST_TYPE_KEY } from './bullet-list/types/index.js';
|
|
2
|
+
import { ORDER_LIST_TYPE } from './order-list/types/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 检查有序列表
|
|
6
|
+
* @param attrs
|
|
7
|
+
*/
|
|
8
|
+
const isOrderList = (attrs) => {
|
|
9
|
+
return attrs[LIST_TYPE_KEY] === ORDER_LIST_TYPE;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { isOrderList as i };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DeserializeContext, SerializeContext } from "@block-kit/core";
|
|
2
|
+
import type { Editor } from "@block-kit/core";
|
|
3
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
4
|
+
import type { ReactLeafContext } from "@block-kit/react";
|
|
5
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
export declare class ItalicPlugin extends EditorPlugin {
|
|
8
|
+
key: string;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
constructor(editor: Editor);
|
|
11
|
+
match(attrs: AttributeMap): boolean;
|
|
12
|
+
serialize(context: SerializeContext): SerializeContext;
|
|
13
|
+
deserialize(context: DeserializeContext): DeserializeContext;
|
|
14
|
+
renderLeaf(context: ReactLeafContext): ReactNode;
|
|
15
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isMatchHTMLTag, applyMarker } from '@block-kit/core';
|
|
2
|
+
import { EditorPlugin } from '@block-kit/react';
|
|
3
|
+
import { isHTMLElement, TRULY } from '@block-kit/utils';
|
|
4
|
+
import { ITALIC_KEY } from './types/index.js';
|
|
5
|
+
|
|
6
|
+
class ItalicPlugin extends EditorPlugin {
|
|
7
|
+
destroy() { }
|
|
8
|
+
constructor(editor) {
|
|
9
|
+
super();
|
|
10
|
+
this.key = ITALIC_KEY;
|
|
11
|
+
editor.command.register(ITALIC_KEY, context => {
|
|
12
|
+
const sel = editor.selection.get();
|
|
13
|
+
sel && editor.perform.applyMarks(sel, { [ITALIC_KEY]: context.value });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
match(attrs) {
|
|
17
|
+
return !!attrs[ITALIC_KEY];
|
|
18
|
+
}
|
|
19
|
+
serialize(context) {
|
|
20
|
+
const { op, html } = context;
|
|
21
|
+
if (op.attributes && op.attributes[ITALIC_KEY]) {
|
|
22
|
+
const strong = document.createElement("em");
|
|
23
|
+
strong.appendChild(html);
|
|
24
|
+
context.html = strong;
|
|
25
|
+
}
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
deserialize(context) {
|
|
29
|
+
const { delta, html } = context;
|
|
30
|
+
if (!isHTMLElement(html))
|
|
31
|
+
return context;
|
|
32
|
+
if (isMatchHTMLTag(html, "em") || html.style.fontStyle === "italic") {
|
|
33
|
+
applyMarker(delta, { [ITALIC_KEY]: TRULY });
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
}
|
|
37
|
+
renderLeaf(context) {
|
|
38
|
+
context.style.fontStyle = "italic";
|
|
39
|
+
return context.children;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { ItalicPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ITALIC_KEY = "italic";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Editor } from "@block-kit/core";
|
|
2
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
3
|
+
import type { ReactLineContext } from "@block-kit/react";
|
|
4
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
export declare class LineHeightPlugin extends EditorPlugin {
|
|
7
|
+
key: string;
|
|
8
|
+
destroy(): void;
|
|
9
|
+
constructor(editor: Editor);
|
|
10
|
+
match(attrs: AttributeMap): boolean;
|
|
11
|
+
renderLine(context: ReactLineContext): ReactNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EditorPlugin } from '@block-kit/react';
|
|
2
|
+
import { LINE_HEIGHT_KEY } from './types/index.js';
|
|
3
|
+
|
|
4
|
+
class LineHeightPlugin extends EditorPlugin {
|
|
5
|
+
destroy() { }
|
|
6
|
+
constructor(editor) {
|
|
7
|
+
super();
|
|
8
|
+
this.key = LINE_HEIGHT_KEY;
|
|
9
|
+
editor.command.register(LINE_HEIGHT_KEY, context => {
|
|
10
|
+
const sel = editor.selection.get();
|
|
11
|
+
sel && editor.perform.applyLineMarks(sel, { [LINE_HEIGHT_KEY]: context.value });
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
match(attrs) {
|
|
15
|
+
return !!attrs[LINE_HEIGHT_KEY];
|
|
16
|
+
}
|
|
17
|
+
renderLine(context) {
|
|
18
|
+
const attrs = context.attributes || {};
|
|
19
|
+
const height = attrs[LINE_HEIGHT_KEY];
|
|
20
|
+
context.style.lineHeight = height;
|
|
21
|
+
return context.children;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { LineHeightPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LINE_HEIGHT_KEY = "line-height";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Editor } from "@block-kit/core";
|
|
3
|
+
import type { CMDPayload } from "@block-kit/core";
|
|
4
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
5
|
+
import type { ReactLeafContext, ReactWrapLeafContext } from "@block-kit/react";
|
|
6
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
7
|
+
export declare class LinkPlugin extends EditorPlugin {
|
|
8
|
+
protected editor: Editor;
|
|
9
|
+
key: string;
|
|
10
|
+
protected modal: HTMLDivElement | null;
|
|
11
|
+
constructor(editor: Editor);
|
|
12
|
+
destroy(): void;
|
|
13
|
+
match(attrs: AttributeMap): boolean;
|
|
14
|
+
wrapLeaf(context: ReactWrapLeafContext): React.ReactNode;
|
|
15
|
+
renderLeaf(context: ReactLeafContext): React.ReactNode;
|
|
16
|
+
onExec(payload: CMDPayload): undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { _ as __decorate } from '../tslib.es6-83956cc1.js';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useReadonly, InjectWrapKeys, EditorPlugin } from '@block-kit/react';
|
|
4
|
+
import { CTRL_KEY, Bind } from '@block-kit/utils';
|
|
5
|
+
import { LINK_KEY, LINK_BLANK_KEY, LINK_TEMP_KEY } from './types/index.js';
|
|
6
|
+
import '@block-kit/core';
|
|
7
|
+
|
|
8
|
+
const A = props => {
|
|
9
|
+
const { attrs } = props;
|
|
10
|
+
const { readonly } = useReadonly();
|
|
11
|
+
const href = attrs[LINK_KEY];
|
|
12
|
+
const target = attrs[LINK_BLANK_KEY] ? "_blank" : "_self";
|
|
13
|
+
const onClick = (e) => {
|
|
14
|
+
e[CTRL_KEY] && window.open(href, "_blank");
|
|
15
|
+
e.preventDefault();
|
|
16
|
+
};
|
|
17
|
+
return (jsx("a", { href: href, target: target, rel: "noreferrer", className: "block-kit-hyper-link", onClick: readonly ? void 0 : onClick, children: props.children }));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
class LinkPlugin extends EditorPlugin {
|
|
21
|
+
constructor(editor) {
|
|
22
|
+
super();
|
|
23
|
+
this.editor = editor;
|
|
24
|
+
this.key = LINK_KEY;
|
|
25
|
+
this.modal = null;
|
|
26
|
+
editor.command.register(this.key, this.onExec);
|
|
27
|
+
}
|
|
28
|
+
destroy() {
|
|
29
|
+
this.modal && this.modal.remove();
|
|
30
|
+
this.modal = null;
|
|
31
|
+
}
|
|
32
|
+
match(attrs) {
|
|
33
|
+
return !!attrs[LINK_KEY] || !!attrs[LINK_TEMP_KEY];
|
|
34
|
+
}
|
|
35
|
+
wrapLeaf(context) {
|
|
36
|
+
const state = context.leafState;
|
|
37
|
+
const attrs = state.op.attributes || {};
|
|
38
|
+
const href = attrs[LINK_KEY];
|
|
39
|
+
if (!href)
|
|
40
|
+
return context.children;
|
|
41
|
+
return jsx(A, { attrs: attrs, children: context.children });
|
|
42
|
+
}
|
|
43
|
+
renderLeaf(context) {
|
|
44
|
+
const attrs = context.attributes;
|
|
45
|
+
if (attrs && attrs[LINK_TEMP_KEY]) {
|
|
46
|
+
context.style.backgroundColor = "rgba(0, 0, 0, 0.1)";
|
|
47
|
+
}
|
|
48
|
+
return context.children;
|
|
49
|
+
}
|
|
50
|
+
onExec(payload) {
|
|
51
|
+
const range = this.editor.selection.get() || payload.range;
|
|
52
|
+
const attrs = payload.attrs;
|
|
53
|
+
if (!range || attrs)
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
InjectWrapKeys(LINK_KEY)
|
|
59
|
+
], LinkPlugin.prototype, "wrapLeaf", null);
|
|
60
|
+
__decorate([
|
|
61
|
+
Bind
|
|
62
|
+
], LinkPlugin.prototype, "onExec", null);
|
|
63
|
+
|
|
64
|
+
export { LinkPlugin };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const PLUGIN_EVENTS = {
|
|
2
|
+
SHORTCUT_MARKS_CHANGE: "SHORTCUT_MARKS_CHANGE",
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const filterMarkMap = (ops) => {
|
|
6
|
+
const firstOp = ops[0];
|
|
7
|
+
if (!firstOp || !firstOp.attributes)
|
|
8
|
+
return {};
|
|
9
|
+
// FIX: 取首个对象会被 immutable 的设计影响
|
|
10
|
+
// 因此这里必须要将其 clone, 否则会影响渲染的内容
|
|
11
|
+
const target = Object.assign({}, firstOp.attributes);
|
|
12
|
+
// 全部存在且相同的属性才认为是此时存在的 mark
|
|
13
|
+
for (let i = 1; i < ops.length; i++) {
|
|
14
|
+
const op = ops[i];
|
|
15
|
+
const attrs = op.attributes;
|
|
16
|
+
const keys = attrs && Object.keys(attrs);
|
|
17
|
+
if (!keys || !keys.length)
|
|
18
|
+
return {};
|
|
19
|
+
for (const key of keys) {
|
|
20
|
+
if (attrs[key] !== target[key]) {
|
|
21
|
+
delete target[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return target;
|
|
26
|
+
};
|
|
27
|
+
const filterLineMarkMap = (attrs) => {
|
|
28
|
+
if (!attrs.length)
|
|
29
|
+
return {};
|
|
30
|
+
// FIX: 取首个对象会被 immutable 的设计影响
|
|
31
|
+
// 因此这里必须要将其 clone, 否则会影响渲染的内容
|
|
32
|
+
const target = Object.assign({}, attrs[0]);
|
|
33
|
+
for (let i = 1; i < attrs.length; i++) {
|
|
34
|
+
const keys = Object.keys(attrs[i]);
|
|
35
|
+
if (!keys || !keys.length)
|
|
36
|
+
return {};
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
if (attrs[i][key] !== target[key]) {
|
|
39
|
+
delete target[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return target;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { PLUGIN_EVENTS as P, filterMarkMap as a, filterLineMarkMap as f };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./styles/index.scss";
|
|
2
|
+
import type { Editor } from "@block-kit/core";
|
|
3
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
4
|
+
import type { ReactLeafContext } from "@block-kit/react";
|
|
5
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import { SuggestModule } from "./modules/suggest";
|
|
8
|
+
export declare class MentionPlugin extends EditorPlugin {
|
|
9
|
+
protected editor: Editor;
|
|
10
|
+
key: string;
|
|
11
|
+
protected suggest: SuggestModule;
|
|
12
|
+
constructor(editor: Editor);
|
|
13
|
+
destroy(): void;
|
|
14
|
+
match(attrs: AttributeMap): boolean;
|
|
15
|
+
renderLeaf(context: ReactLeafContext): ReactNode;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'react/jsx-runtime';
|
|
2
|
+
import '@block-kit/react';
|
|
3
|
+
export { M as MentionPlugin } from '../index-1e46887d.js';
|
|
4
|
+
import './types/index.js';
|
|
5
|
+
import '../tslib.es6-83956cc1.js';
|
|
6
|
+
import '@block-kit/core';
|
|
7
|
+
import '@block-kit/delta';
|
|
8
|
+
import '@block-kit/utils';
|
|
9
|
+
import 'react-dom';
|
|
10
|
+
import '../dom-71a99400.js';
|
|
11
|
+
import '../is-3de778e2.js';
|
|
12
|
+
import '@block-kit/utils/dist/es/hooks';
|
|
13
|
+
import 'react';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Editor, SelectionChangeEvent } from "@block-kit/core";
|
|
2
|
+
import { Point } from "@block-kit/core";
|
|
3
|
+
export declare class SuggestModule {
|
|
4
|
+
editor: Editor;
|
|
5
|
+
point: Point;
|
|
6
|
+
isMountSuggest: boolean;
|
|
7
|
+
mountSuggestNode: HTMLElement | null;
|
|
8
|
+
rect: {
|
|
9
|
+
top: number;
|
|
10
|
+
left: number;
|
|
11
|
+
} | null;
|
|
12
|
+
constructor(editor: Editor);
|
|
13
|
+
destroy(): void;
|
|
14
|
+
onKeydown(event: KeyboardEvent): void;
|
|
15
|
+
onSelectionChange(event: SelectionChangeEvent): void;
|
|
16
|
+
mountSuggestPanel(text?: string): undefined;
|
|
17
|
+
unmountSuggestPanel(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CMDPayload, Editor } from "@block-kit/core";
|
|
2
|
+
import type { AttributeMap } from "@block-kit/delta";
|
|
3
|
+
import type { ReactLineContext } from "@block-kit/react";
|
|
4
|
+
import { EditorPlugin } from "@block-kit/react";
|
|
5
|
+
import type { EventContext } from "@block-kit/utils";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
export declare class OrderListPlugin extends EditorPlugin {
|
|
8
|
+
protected editor: Editor;
|
|
9
|
+
key: string;
|
|
10
|
+
constructor(editor: Editor);
|
|
11
|
+
destroy(): void;
|
|
12
|
+
match(attrs: AttributeMap): boolean;
|
|
13
|
+
renderLine(context: ReactLineContext): ReactNode;
|
|
14
|
+
protected onExec(payload: CMDPayload): undefined;
|
|
15
|
+
protected onKeyDown(event: KeyboardEvent, context: EventContext): undefined;
|
|
16
|
+
}
|