@block-kit/react 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/hooks/use-editor.d.ts +21 -0
- package/dist/es/hooks/use-editor.js +26 -0
- package/dist/es/hooks/use-readonly.d.ts +5 -0
- package/dist/es/hooks/use-readonly.js +6 -0
- package/dist/es/index.d.ts +18 -0
- package/dist/es/index.js +17 -0
- package/dist/es/model/block.d.ts +7 -0
- package/dist/es/model/block.js +142 -0
- package/dist/es/model/eol.d.ts +6 -0
- package/dist/es/model/eol.js +18 -0
- package/dist/es/model/leaf.d.ts +7 -0
- package/dist/es/model/leaf.js +38 -0
- package/dist/es/model/line.d.ts +7 -0
- package/dist/es/model/line.js +152 -0
- package/dist/es/plugin/index.d.ts +25 -0
- package/dist/es/plugin/index.js +3 -0
- package/dist/es/plugin/modules/priority.d.ts +13 -0
- package/dist/es/plugin/modules/priority.js +26 -0
- package/dist/es/plugin/modules/wrap.d.ts +26 -0
- package/dist/es/plugin/modules/wrap.js +72 -0
- package/dist/es/plugin/types/index.d.ts +35 -0
- package/dist/es/plugin/types/index.js +7 -0
- package/dist/es/preset/block-kit.d.ts +6 -0
- package/dist/es/preset/block-kit.js +17 -0
- package/dist/es/preset/editable.d.ts +16 -0
- package/dist/es/preset/editable.js +42 -0
- package/dist/es/preset/embed.d.ts +14 -0
- package/dist/es/preset/embed.js +23 -0
- package/dist/es/preset/isolate.d.ts +12 -0
- package/dist/es/preset/isolate.js +10 -0
- package/dist/es/preset/text.d.ts +9 -0
- package/dist/es/preset/text.js +34 -0
- package/dist/es/preset/void.d.ts +14 -0
- package/dist/es/preset/void.js +23 -0
- package/dist/es/preset/zero.d.ts +23 -0
- package/dist/es/preset/zero.js +20 -0
- package/dist/es/utils/constant.d.ts +2 -0
- package/dist/es/utils/constant.js +6 -0
- package/dist/es/utils/event.d.ts +2 -0
- package/dist/es/utils/event.js +7 -0
- package/dist/es/utils/is.d.ts +2 -0
- package/dist/es/utils/is.js +12 -0
- package/dist/es/utils/weak-map.d.ts +17 -0
- package/dist/es/utils/weak-map.js +15 -0
- package/dist/es/utils/wrapper.d.ts +7 -0
- package/dist/es/utils/wrapper.js +25 -0
- package/dist/lib/hooks/use-editor.d.ts +21 -0
- package/dist/lib/hooks/use-editor.js +53 -0
- package/dist/lib/hooks/use-readonly.d.ts +5 -0
- package/dist/lib/hooks/use-readonly.js +33 -0
- package/dist/lib/index.d.ts +18 -0
- package/dist/lib/index.js +40 -0
- package/dist/lib/model/block.d.ts +7 -0
- package/dist/lib/model/block.js +168 -0
- package/dist/lib/model/eol.d.ts +6 -0
- package/dist/lib/model/eol.js +24 -0
- package/dist/lib/model/leaf.d.ts +7 -0
- package/dist/lib/model/leaf.js +64 -0
- package/dist/lib/model/line.d.ts +7 -0
- package/dist/lib/model/line.js +178 -0
- package/dist/lib/plugin/index.d.ts +25 -0
- package/dist/lib/plugin/index.js +7 -0
- package/dist/lib/plugin/modules/priority.d.ts +13 -0
- package/dist/lib/plugin/modules/priority.js +31 -0
- package/dist/lib/plugin/modules/wrap.d.ts +26 -0
- package/dist/lib/plugin/modules/wrap.js +78 -0
- package/dist/lib/plugin/types/index.d.ts +35 -0
- package/dist/lib/plugin/types/index.js +10 -0
- package/dist/lib/preset/block-kit.d.ts +6 -0
- package/dist/lib/preset/block-kit.js +21 -0
- package/dist/lib/preset/editable.d.ts +16 -0
- package/dist/lib/preset/editable.js +46 -0
- package/dist/lib/preset/embed.d.ts +14 -0
- package/dist/lib/preset/embed.js +30 -0
- package/dist/lib/preset/isolate.d.ts +12 -0
- package/dist/lib/preset/isolate.js +14 -0
- package/dist/lib/preset/text.d.ts +9 -0
- package/dist/lib/preset/text.js +37 -0
- package/dist/lib/preset/void.d.ts +14 -0
- package/dist/lib/preset/void.js +30 -0
- package/dist/lib/preset/zero.d.ts +23 -0
- package/dist/lib/preset/zero.js +23 -0
- package/dist/lib/utils/constant.d.ts +2 -0
- package/dist/lib/utils/constant.js +9 -0
- package/dist/lib/utils/event.d.ts +2 -0
- package/dist/lib/utils/event.js +12 -0
- package/dist/lib/utils/is.d.ts +2 -0
- package/dist/lib/utils/is.js +16 -0
- package/dist/lib/utils/weak-map.d.ts +17 -0
- package/dist/lib/utils/weak-map.js +18 -0
- package/dist/lib/utils/wrapper.d.ts +7 -0
- package/dist/lib/utils/wrapper.js +29 -0
- package/package.json +38 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LeafContext, LeafState, LineContext, LineState } from "@block-kit/core";
|
|
3
|
+
/**
|
|
4
|
+
* 包装行状态
|
|
5
|
+
*/
|
|
6
|
+
export type ReactWrapLineContext = {
|
|
7
|
+
lineState: LineState;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 包装叶子状态
|
|
12
|
+
*/
|
|
13
|
+
export type ReactWrapLeafContext = {
|
|
14
|
+
leafState: LeafState;
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 行状态
|
|
19
|
+
*/
|
|
20
|
+
export interface ReactLineContext extends LineContext {
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 叶子状态
|
|
25
|
+
*/
|
|
26
|
+
export interface ReactLeafContext extends LeafContext {
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 包装类型
|
|
31
|
+
*/
|
|
32
|
+
export declare const WRAP_TYPE: {
|
|
33
|
+
readonly LINE: "wrapLine";
|
|
34
|
+
readonly LEAF: "wrapLeaf";
|
|
35
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockKit = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const core_1 = require("@block-kit/core");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const use_editor_1 = require("../hooks/use-editor");
|
|
8
|
+
const use_readonly_1 = require("../hooks/use-readonly");
|
|
9
|
+
const wrap_1 = require("../plugin/modules/wrap");
|
|
10
|
+
const BlockKit = props => {
|
|
11
|
+
const { editor, readonly, children } = props;
|
|
12
|
+
if (editor.state.get(core_1.EDITOR_STATE.READONLY) !== readonly) {
|
|
13
|
+
editor.state.set(core_1.EDITOR_STATE.READONLY, readonly || false);
|
|
14
|
+
}
|
|
15
|
+
(0, react_1.useMemo)(() => {
|
|
16
|
+
// 希望在 Editor 初始化后立即执行一次
|
|
17
|
+
(0, wrap_1.initWrapPlugins)(editor);
|
|
18
|
+
}, [editor]);
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(use_editor_1.BlockKitContext.Provider, { value: editor, children: (0, jsx_runtime_1.jsx)(use_readonly_1.ReadonlyContext.Provider, { value: !!readonly, children: children }) }));
|
|
20
|
+
};
|
|
21
|
+
exports.BlockKit = BlockKit;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* 编辑节点
|
|
4
|
+
* @param props
|
|
5
|
+
*/
|
|
6
|
+
export declare const Editable: React.FC<{
|
|
7
|
+
/** 节点类名 */
|
|
8
|
+
className?: string;
|
|
9
|
+
/** 自动聚焦 */
|
|
10
|
+
autoFocus?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 占位节点
|
|
13
|
+
* - 节点会脱离文档流, 需要注意 CSS 布局
|
|
14
|
+
*/
|
|
15
|
+
placeholder?: React.ReactNode;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Editable = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const core_1 = require("@block-kit/core");
|
|
6
|
+
const utils_1 = require("@block-kit/utils");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const use_editor_1 = require("../hooks/use-editor");
|
|
9
|
+
const use_readonly_1 = require("../hooks/use-readonly");
|
|
10
|
+
const block_1 = require("../model/block");
|
|
11
|
+
/**
|
|
12
|
+
* 编辑节点
|
|
13
|
+
* @param props
|
|
14
|
+
*/
|
|
15
|
+
const Editable = props => {
|
|
16
|
+
const { className, autoFocus } = props;
|
|
17
|
+
const { editor } = (0, use_editor_1.useEditorStatic)();
|
|
18
|
+
const { readonly } = (0, use_readonly_1.useReadonly)();
|
|
19
|
+
const ref = (0, react_1.useRef)(null);
|
|
20
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
21
|
+
const el = ref.current;
|
|
22
|
+
el && editor.onMount(el);
|
|
23
|
+
return () => {
|
|
24
|
+
editor.destroy();
|
|
25
|
+
};
|
|
26
|
+
}, [editor]);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
// COMPAT: 这里有个奇怪的表现
|
|
29
|
+
// 当自动聚焦时, 必须要先更新浏览器选区再聚焦
|
|
30
|
+
// 否则会造成立即按下回车时, 光标不会跟随选区移动
|
|
31
|
+
// 无论是 Model 选区还是浏览器选区, 都已经更新但是却不移动
|
|
32
|
+
if (autoFocus) {
|
|
33
|
+
const start = new core_1.Point(0, 0);
|
|
34
|
+
editor.selection.set(new core_1.Range(start, start), true);
|
|
35
|
+
editor.selection.focus();
|
|
36
|
+
}
|
|
37
|
+
}, [autoFocus, editor.selection]);
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: (0, utils_1.cs)(className, "notranslate"), [core_1.EDITOR_KEY]: true, contentEditable: !readonly, suppressContentEditableWarning: true, style: {
|
|
39
|
+
outline: "none",
|
|
40
|
+
position: "relative",
|
|
41
|
+
whiteSpace: "pre-wrap",
|
|
42
|
+
wordBreak: "break-word",
|
|
43
|
+
overflowWrap: "break-word",
|
|
44
|
+
}, children: (0, jsx_runtime_1.jsx)(block_1.BlockModel, { editor: editor, state: editor.state.block, placeholder: props.placeholder }) }));
|
|
45
|
+
};
|
|
46
|
+
exports.Editable = Editable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { ReactLeafContext } from "../plugin/types";
|
|
4
|
+
export type EmbedProps = PropsWithChildren<{
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
context: ReactLeafContext;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Embed 嵌入节点 HOC
|
|
11
|
+
* - Inline Block HOC
|
|
12
|
+
* @param props
|
|
13
|
+
*/
|
|
14
|
+
export declare const Embed: FC<EmbedProps>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Embed = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const core_1 = require("@block-kit/core");
|
|
9
|
+
const core_2 = require("@block-kit/core");
|
|
10
|
+
const core_3 = require("@block-kit/core");
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const use_editor_1 = require("../hooks/use-editor");
|
|
13
|
+
const zero_1 = require("./zero");
|
|
14
|
+
/**
|
|
15
|
+
* Embed 嵌入节点 HOC
|
|
16
|
+
* - Inline Block HOC
|
|
17
|
+
* @param props
|
|
18
|
+
*/
|
|
19
|
+
const Embed = props => {
|
|
20
|
+
const { context } = props;
|
|
21
|
+
const { editor } = (0, use_editor_1.useEditorStatic)();
|
|
22
|
+
const leaf = context.leafState;
|
|
23
|
+
const onMouseDown = () => {
|
|
24
|
+
const point = new core_3.Point(leaf.parent.index, leaf.offset + 1);
|
|
25
|
+
const range = new core_2.Range(point, point.clone());
|
|
26
|
+
editor.selection.set(range, true);
|
|
27
|
+
};
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(zero_1.ZeroSpace, { embed: true, len: leaf.length > 1 ? leaf.length : void 0 }), (0, jsx_runtime_1.jsx)("span", { className: props.className, style: Object.assign({ margin: "0 0.1px" }, props.style), contentEditable: false, [core_1.VOID_KEY]: true, onMouseDown: onMouseDown, children: props.children })] }));
|
|
29
|
+
};
|
|
30
|
+
exports.Embed = Embed;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export type IsolateProps = PropsWithChildren<{
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* 独立节点嵌入 HOC
|
|
9
|
+
* - 独立区域 完全隔离所有事件
|
|
10
|
+
* @param props
|
|
11
|
+
*/
|
|
12
|
+
export declare const Isolate: FC<IsolateProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Isolate = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const event_1 = require("../utils/event");
|
|
6
|
+
/**
|
|
7
|
+
* 独立节点嵌入 HOC
|
|
8
|
+
* - 独立区域 完全隔离所有事件
|
|
9
|
+
* @param props
|
|
10
|
+
*/
|
|
11
|
+
const Isolate = props => {
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: props.className, style: Object.assign({ userSelect: "none" }, props.style), contentEditable: false, onMouseDown: event_1.preventReactEvent, onCopy: event_1.preventReactEvent, children: props.children }));
|
|
13
|
+
};
|
|
14
|
+
exports.Isolate = Isolate;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Text = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const core_1 = require("@block-kit/core");
|
|
6
|
+
const utils_1 = require("@block-kit/utils");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
/**
|
|
9
|
+
* 文本节点
|
|
10
|
+
* @param props
|
|
11
|
+
*/
|
|
12
|
+
exports.Text = (0, react_1.forwardRef)((props, ref) => {
|
|
13
|
+
const onRef = (dom) => {
|
|
14
|
+
// 处理外部引用的 ref
|
|
15
|
+
if ((0, utils_1.isFunction)(ref)) {
|
|
16
|
+
ref(dom);
|
|
17
|
+
}
|
|
18
|
+
else if (ref) {
|
|
19
|
+
ref.current = dom;
|
|
20
|
+
}
|
|
21
|
+
// COMPAT: 避免 React 非受控与 IME 造成的 DOM 内容问题
|
|
22
|
+
if (!dom || props.children === dom.textContent)
|
|
23
|
+
return void 0;
|
|
24
|
+
const nodes = dom.childNodes;
|
|
25
|
+
// If the text content is inconsistent due to the modification of the input
|
|
26
|
+
// it needs to be corrected
|
|
27
|
+
for (let i = 1; i < nodes.length; ++i) {
|
|
28
|
+
const node = nodes[i];
|
|
29
|
+
node && node.remove();
|
|
30
|
+
}
|
|
31
|
+
// Guaranteed to have only one text child
|
|
32
|
+
if ((0, utils_1.isDOMText)(dom.firstChild)) {
|
|
33
|
+
dom.firstChild.nodeValue = props.children;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)("span", { ref: onRef, [core_1.LEAF_STRING]: true, children: props.children }));
|
|
37
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FC, PropsWithChildren } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { ReactLeafContext } from "../plugin/types";
|
|
4
|
+
export type VoidProps = PropsWithChildren<{
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
context: ReactLeafContext;
|
|
8
|
+
tag?: "span" | "div";
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* 空嵌入节点 HOC
|
|
12
|
+
* @param props
|
|
13
|
+
*/
|
|
14
|
+
export declare const Void: FC<VoidProps>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Void = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const core_1 = require("@block-kit/core");
|
|
9
|
+
const core_2 = require("@block-kit/core");
|
|
10
|
+
const core_3 = require("@block-kit/core");
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const use_editor_1 = require("../hooks/use-editor");
|
|
13
|
+
const zero_1 = require("./zero");
|
|
14
|
+
/**
|
|
15
|
+
* 空嵌入节点 HOC
|
|
16
|
+
* @param props
|
|
17
|
+
*/
|
|
18
|
+
const Void = props => {
|
|
19
|
+
const { context, tag: Tag = "span" } = props;
|
|
20
|
+
const { editor } = (0, use_editor_1.useEditorStatic)();
|
|
21
|
+
const leaf = context.leafState;
|
|
22
|
+
const onMouseDown = () => {
|
|
23
|
+
// FIX: 修复选区偏移量, leaf 的长度可能 > 1, 而 DOM 节点的长度仅为 1
|
|
24
|
+
const point = new core_3.Point(leaf.parent.index, leaf.offset + 1);
|
|
25
|
+
const range = new core_2.Range(point, point.clone());
|
|
26
|
+
editor.selection.set(range, true);
|
|
27
|
+
};
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(zero_1.ZeroSpace, { void: true, hide: true, len: leaf.length > 1 ? leaf.length : void 0 }), (0, jsx_runtime_1.jsx)(Tag, { className: props.className, style: Object.assign({ userSelect: "none" }, props.style), contentEditable: false, [core_1.VOID_KEY]: true, onMouseDown: onMouseDown, children: props.children })] }));
|
|
29
|
+
};
|
|
30
|
+
exports.Void = Void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type ZeroSpaceProps = {
|
|
3
|
+
/** 隐藏光标 */
|
|
4
|
+
hide?: boolean;
|
|
5
|
+
/** void-block 空节点 */
|
|
6
|
+
void?: boolean;
|
|
7
|
+
/** embed(inline-block) 嵌入节点 */
|
|
8
|
+
embed?: boolean;
|
|
9
|
+
/** 行末尾占位 */
|
|
10
|
+
enter?: boolean;
|
|
11
|
+
/** 空节点占位长度 */
|
|
12
|
+
len?: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 零宽字符组件
|
|
16
|
+
* - void hide => 独占一行的空节点, 例如 Image
|
|
17
|
+
* - embed => 嵌入节点, 例如 Mention
|
|
18
|
+
* - enter => 行末尾占位, 保留于 EOLView
|
|
19
|
+
* - len => 空节点占位长度, 配合 Void/Embed
|
|
20
|
+
* @param props
|
|
21
|
+
* @param ref
|
|
22
|
+
*/
|
|
23
|
+
export declare const ZeroSpace: import("react").ForwardRefExoticComponent<ZeroSpaceProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZeroSpace = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const core_1 = require("@block-kit/core");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const constant_1 = require("../utils/constant");
|
|
8
|
+
/**
|
|
9
|
+
* 零宽字符组件
|
|
10
|
+
* - void hide => 独占一行的空节点, 例如 Image
|
|
11
|
+
* - embed => 嵌入节点, 例如 Mention
|
|
12
|
+
* - enter => 行末尾占位, 保留于 EOLView
|
|
13
|
+
* - len => 空节点占位长度, 配合 Void/Embed
|
|
14
|
+
* @param props
|
|
15
|
+
* @param ref
|
|
16
|
+
*/
|
|
17
|
+
exports.ZeroSpace = (0, react_1.forwardRef)((props, ref) => {
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)("span", { ref: ref, [core_1.ZERO_SPACE_KEY]: true,
|
|
19
|
+
[core_1.ZERO_VOID_KEY]: props.void,
|
|
20
|
+
[core_1.ZERO_ENTER_KEY]: props.enter,
|
|
21
|
+
[core_1.ZERO_EMBED_KEY]: props.embed,
|
|
22
|
+
[core_1.VOID_LEN_KEY]: props.len, style: props.hide ? constant_1.NO_CURSOR : void 0, children: core_1.ZERO_SYMBOL }));
|
|
23
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preventReactEvent = exports.preventNativeEvent = void 0;
|
|
4
|
+
const preventNativeEvent = (e) => {
|
|
5
|
+
e.preventDefault();
|
|
6
|
+
e.stopPropagation();
|
|
7
|
+
};
|
|
8
|
+
exports.preventNativeEvent = preventNativeEvent;
|
|
9
|
+
const preventReactEvent = (e) => {
|
|
10
|
+
(0, exports.preventNativeEvent)(e.nativeEvent);
|
|
11
|
+
};
|
|
12
|
+
exports.preventReactEvent = preventReactEvent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isStrictEmptyLine = void 0;
|
|
4
|
+
const isStrictEmptyLine = (line) => {
|
|
5
|
+
const leaves = line.getLeaves();
|
|
6
|
+
if (!leaves.length) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (leaves.length === 1 &&
|
|
10
|
+
leaves[0].eol &&
|
|
11
|
+
(!leaves[0].op.attributes || !Object.keys(leaves[0].op.attributes).length)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
exports.isStrictEmptyLine = isStrictEmptyLine;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LeafState, LineState } from "@block-kit/core";
|
|
3
|
+
/**
|
|
4
|
+
* LeafState 与 Text 节点的映射
|
|
5
|
+
* - 仅处理文本节点, 零宽字符节点暂不处理
|
|
6
|
+
*/
|
|
7
|
+
export declare const LEAF_TO_TEXT: WeakMap<LeafState, HTMLElement | null>;
|
|
8
|
+
/**
|
|
9
|
+
* JSX.Element 与 State 的映射
|
|
10
|
+
* - 渲染时即刻加入映射, wrap 时即刻消费映射
|
|
11
|
+
*/
|
|
12
|
+
export declare const JSX_TO_STATE: WeakMap<JSX.Element, LineState | LeafState>;
|
|
13
|
+
/**
|
|
14
|
+
* State 与 Wrapper Symbol 的映射
|
|
15
|
+
* - 主要是取得已经处理过的节点, 避免重复处理
|
|
16
|
+
*/
|
|
17
|
+
export declare const STATE_TO_SYMBOL: WeakMap<LineState | LeafState, string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STATE_TO_SYMBOL = exports.JSX_TO_STATE = exports.LEAF_TO_TEXT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* LeafState 与 Text 节点的映射
|
|
6
|
+
* - 仅处理文本节点, 零宽字符节点暂不处理
|
|
7
|
+
*/
|
|
8
|
+
exports.LEAF_TO_TEXT = new WeakMap();
|
|
9
|
+
/**
|
|
10
|
+
* JSX.Element 与 State 的映射
|
|
11
|
+
* - 渲染时即刻加入映射, wrap 时即刻消费映射
|
|
12
|
+
*/
|
|
13
|
+
exports.JSX_TO_STATE = new WeakMap();
|
|
14
|
+
/**
|
|
15
|
+
* State 与 Wrapper Symbol 的映射
|
|
16
|
+
* - 主要是取得已经处理过的节点, 避免重复处理
|
|
17
|
+
*/
|
|
18
|
+
exports.STATE_TO_SYMBOL = new WeakMap();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWrapSymbol = void 0;
|
|
4
|
+
const weak_map_1 = require("./weak-map");
|
|
5
|
+
/**
|
|
6
|
+
* 根据属性获取唯一标识值
|
|
7
|
+
* @param keys
|
|
8
|
+
* @param element
|
|
9
|
+
*/
|
|
10
|
+
const getWrapSymbol = (keys, el) => {
|
|
11
|
+
if (!el)
|
|
12
|
+
return null;
|
|
13
|
+
const state = weak_map_1.JSX_TO_STATE.get(el);
|
|
14
|
+
const cache = state && weak_map_1.STATE_TO_SYMBOL.get(state);
|
|
15
|
+
if (cache || !state)
|
|
16
|
+
return cache || null;
|
|
17
|
+
const attrs = state.op.attributes;
|
|
18
|
+
if (!attrs || !Object.keys(attrs).length || !keys.length) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const suite = [];
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
attrs[key] && suite.push(`${key}${attrs[key]}`);
|
|
24
|
+
}
|
|
25
|
+
const symbol = suite.join("");
|
|
26
|
+
weak_map_1.STATE_TO_SYMBOL.set(state, symbol);
|
|
27
|
+
return symbol;
|
|
28
|
+
};
|
|
29
|
+
exports.getWrapSymbol = getWrapSymbol;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@block-kit/react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/lib/index.js",
|
|
6
|
+
"types": "./dist/es/index.d.ts",
|
|
7
|
+
"module": "./dist/es/index.js",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css",
|
|
10
|
+
"**/*.scss",
|
|
11
|
+
"**/*.less"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.lib.json",
|
|
18
|
+
"test": "",
|
|
19
|
+
"lint:ts": "tsc -p tsconfig.build.json --noEmit",
|
|
20
|
+
"lint:circular": "madge --extensions js --circular ./dist"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=16",
|
|
27
|
+
"react-dom": ">=16"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@block-kit/core": "1.0.0",
|
|
31
|
+
"@block-kit/delta": "1.0.0",
|
|
32
|
+
"@block-kit/utils": "1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "17.0.2",
|
|
36
|
+
"@types/react-dom": "17.0.2"
|
|
37
|
+
}
|
|
38
|
+
}
|