@xiongtao.xt/tau-plugins 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +4 -2
- package/package.json +31 -3
- package/runtime.js +1 -0
- package/types/packages/editor/api.d.ts +10 -0
- package/types/packages/editor/contracts.d.ts +3 -0
- package/types/packages/editor/src/api/command.d.ts +61 -0
- package/types/packages/editor/src/api/copy.d.ts +23 -0
- package/types/packages/editor/src/api/drag.d.ts +24 -0
- package/types/packages/editor/src/api/extension.d.ts +100 -0
- package/types/packages/editor/src/api/index.d.ts +54 -0
- package/types/packages/editor/src/api/ingest.d.ts +39 -0
- package/types/packages/editor/src/api/legacy.d.ts +10 -0
- package/types/packages/editor/src/api/marks.d.ts +35 -0
- package/types/packages/editor/src/api/menu.d.ts +37 -0
- package/types/packages/editor/src/api/submission.d.ts +38 -0
- package/types/packages/editor/src/api/toolbar.d.ts +3 -0
- package/types/packages/editor/src/components/AddParagraph/index.d.ts +11 -0
- package/types/packages/editor/src/components/BlockDrag/index.d.ts +35 -0
- package/types/packages/editor/src/components/ElementMenu/index.d.ts +11 -0
- package/types/packages/editor/src/components/FloatingToolbar/index.d.ts +23 -0
- package/types/packages/editor/src/components/HoveringToolbar/FloatingSubmenu.d.ts +19 -0
- package/types/packages/editor/src/components/HoveringToolbar/context.d.ts +8 -0
- package/types/packages/editor/src/components/HoveringToolbar/floatingPosition.d.ts +22 -0
- package/types/packages/editor/src/components/InlineChromiumBugFix/index.d.ts +2 -0
- package/types/packages/editor/src/components/OverlayBackDismiss/index.d.ts +4 -0
- package/types/packages/editor/src/hooks/useIsLastElement.d.ts +3 -0
- package/types/packages/editor/src/kit/elementEmpty.d.ts +5 -0
- package/types/packages/editor/src/menu/conversion.d.ts +3 -0
- package/types/packages/editor/src/model/paragraph.d.ts +5 -0
- package/types/packages/editor/src/services/editorNotifier.d.ts +4 -0
- package/types/packages/editor/src/services/errorReporter.d.ts +13 -0
- package/types/packages/editor/src/services/hooks.d.ts +11 -0
- package/types/packages/editor/src/services/notifier.d.ts +46 -0
- package/types/packages/editor/src/services/overlayBackDismiss.d.ts +10 -0
- package/types/packages/editor/src/services/registry.d.ts +6 -0
- package/types/packages/editor/src/services/tokens.d.ts +10 -0
- package/types/packages/editor/src/theme/ThemeService.d.ts +24 -0
- package/types/packages/editor/src/theme/context.d.ts +26 -0
- package/types/packages/editor/src/types/block-panel.d.ts +12 -0
- package/types/packages/editor/src/types/custom-element.d.ts +10 -0
- package/types/packages/editor/src/types/editor.d.ts +37 -0
- package/types/packages/editor/src/types/element/paragraph.d.ts +6 -0
- package/types/packages/editor/src/types/hotkeys.d.ts +6 -0
- package/types/packages/editor/src/types/hovering-bar.d.ts +8 -0
- package/types/packages/editor/src/types/index.d.ts +7 -0
- package/types/packages/editor/src/types/text.d.ts +1 -0
- package/types/packages/editor/src/types.d.ts +1 -0
- package/types/packages/editor/src/ui/CaretRight.d.ts +3 -0
- package/types/packages/editor/src/ui/Tooltip.d.ts +7 -0
- package/types/packages/editor/src/utils/blockNavigation.d.ts +28 -0
- package/types/packages/editor/src/utils/commandTarget.d.ts +4 -0
- package/types/packages/editor/src/utils/container.d.ts +3 -0
- package/types/packages/editor/src/utils/editor.d.ts +16 -0
- package/types/packages/editor/src/utils/element.d.ts +11 -0
- package/types/packages/editor/src/utils/insertElement.d.ts +11 -0
- package/types/packages/editor/src/utils/nodeOperations.d.ts +19 -0
- package/types/packages/editor/src/utils/paragraphShortcut.d.ts +4 -0
- package/types/packages/editor/src/utils/path.d.ts +6 -0
- package/types/packages/editor/src/utils/plugin.d.ts +4 -0
- package/types/packages/editor/src/utils/selectionSnapshot.d.ts +3 -0
- package/types/packages/editor/src/utils/zoomPan.d.ts +14 -0
- package/types/packages/markdown/src/codec.d.ts +86 -0
- package/types/packages/markdown/src/index.d.ts +7 -0
- package/types/packages/markdown/src/markdown-helper.d.ts +28 -0
- package/types/packages/markdown/src/markdown.d.ts +35 -0
- package/types/packages/markdown/src/markdownSerializerRegistry.d.ts +47 -0
- package/types/packages/markdown/src/model.d.ts +7 -0
- package/types/packages/markdown/src/positionMapper.d.ts +161 -0
- package/types/packages/markdown/src/processor.d.ts +27 -0
- package/types/packages/markdown/src/textCodec.d.ts +39 -0
- package/types/packages/markdown/src/types.d.ts +8 -0
- package/types/packages/plugins/src/contract.d.ts +47 -0
- package/types/packages/plugins/src/editor.d.ts +37 -0
- package/types/packages/plugins/src/index.d.ts +6 -0
- package/types/packages/plugins/src/pages.d.ts +23 -0
- package/types/packages/plugins/src/settings.d.ts +19 -0
- package/types/packages/shared/service-contract.d.ts +6 -0
- package/types/packages/shared/service-registry.d.ts +25 -0
- package/types/packages/themes/src/bootstrap.d.ts +26 -0
- package/types/packages/themes/src/defineTheme.d.ts +45 -0
- package/types/packages/themes/src/index.d.ts +10 -0
- package/types/packages/themes/src/register.d.ts +9 -0
- package/types/packages/themes/src/themes/ink.theme.d.ts +11 -0
- package/types/packages/themes/src/themes/mint.theme.d.ts +11 -0
- package/types/packages/themes/src/themes/ocean.theme.d.ts +12 -0
- package/types/packages/themes/src/themes/paper.theme.d.ts +16 -0
- package/types/packages/themes/src/themes/sakura.theme.d.ts +11 -0
- package/types/packages/themes/src/themes/wisteria.theme.d.ts +10 -0
- package/types/packages/themes/src/tokenContract.d.ts +30 -0
- package/types/packages/ui/src/UiProvider.d.ts +17 -0
- package/types/packages/ui/src/cn.d.ts +23 -0
- package/types/packages/ui/src/hooks/fadeScrollClass.d.ts +8 -0
- package/types/packages/ui/src/hooks/index.d.ts +3 -0
- package/types/packages/ui/src/hooks/isEditableTarget.d.ts +2 -0
- package/types/packages/ui/src/hooks/lockBodyScroll.d.ts +1 -0
- package/types/packages/ui/src/hooks/scrollbarAutoHide.d.ts +9 -0
- package/types/packages/ui/src/hooks/useEdgeFade.d.ts +22 -0
- package/types/packages/ui/src/index.d.ts +47 -0
- package/types/packages/ui/src/patterns/FormRow.d.ts +20 -0
- package/types/packages/ui/src/primitives/AnchoredPanel.d.ts +53 -0
- package/types/packages/ui/src/primitives/Button.d.ts +31 -0
- package/types/packages/ui/src/primitives/Checkbox.d.ts +24 -0
- package/types/packages/ui/src/primitives/ConfirmDialog.d.ts +44 -0
- package/types/packages/ui/src/primitives/Dialog.d.ts +82 -0
- package/types/packages/ui/src/primitives/Drawer.d.ts +87 -0
- package/types/packages/ui/src/primitives/EditText.d.ts +32 -0
- package/types/packages/ui/src/primitives/ErrorBoundary.d.ts +16 -0
- package/types/packages/ui/src/primitives/FadeScroll.d.ts +18 -0
- package/types/packages/ui/src/primitives/FileDropZone.d.ts +14 -0
- package/types/packages/ui/src/primitives/FilterPill.d.ts +19 -0
- package/types/packages/ui/src/primitives/IconButton.d.ts +6 -0
- package/types/packages/ui/src/primitives/If.d.ts +6 -0
- package/types/packages/ui/src/primitives/ImagePreview.d.ts +16 -0
- package/types/packages/ui/src/primitives/Loading.d.ts +18 -0
- package/types/packages/ui/src/primitives/LoadingOverlay.d.ts +7 -0
- package/types/packages/ui/src/primitives/Menu.d.ts +93 -0
- package/types/packages/ui/src/primitives/Notification.d.ts +110 -0
- package/types/packages/ui/src/primitives/Panel.d.ts +28 -0
- package/types/packages/ui/src/primitives/Popover.d.ts +58 -0
- package/types/packages/ui/src/primitives/PortalToBody.d.ts +7 -0
- package/types/packages/ui/src/primitives/Radio.d.ts +27 -0
- package/types/packages/ui/src/primitives/RadioGroup.d.ts +32 -0
- package/types/packages/ui/src/primitives/ResizableAndHideableSidebar.d.ts +40 -0
- package/types/packages/ui/src/primitives/ResizeHandle.d.ts +23 -0
- package/types/packages/ui/src/primitives/Segmented.d.ts +44 -0
- package/types/packages/ui/src/primitives/Select.d.ts +78 -0
- package/types/packages/ui/src/primitives/Switch.d.ts +23 -0
- package/types/packages/ui/src/primitives/Tabs.d.ts +17 -0
- package/types/packages/ui/src/primitives/Tag.d.ts +24 -0
- package/types/packages/ui/src/primitives/Toast.d.ts +67 -0
- package/types/packages/ui/src/primitives/Tooltip.d.ts +40 -0
- package/types/packages/ui/src/primitives/ValueDisplay.d.ts +25 -0
- package/types/packages/ui/src/primitives/YearHeatmap.d.ts +15 -0
- package/types/packages/ui/src/primitives/anchoredPosition.d.ts +44 -0
- package/types/packages/ui/src/primitives/datepicker/DatePicker.d.ts +71 -0
- package/types/packages/ui/src/primitives/datepicker/DateRangePicker.d.ts +70 -0
- package/types/packages/ui/src/primitives/datepicker/calendarEngine.d.ts +45 -0
- package/types/packages/ui/src/primitives/editTextClasses.d.ts +1 -0
- package/types/packages/ui/src/primitives/input/Input.d.ts +35 -0
- package/types/packages/ui/src/primitives/input/NumberInput.d.ts +25 -0
- package/types/packages/ui/src/primitives/input/Textarea.d.ts +14 -0
- package/types/packages/ui/src/primitives/mergeRefs.d.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LastKnightCoder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tau plugins 作者契约
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
通过 npm 别名安装为 `@tau/plugins`。运行时由 Tau 桌面宿主提供,构建时必须 external;不可在普通 Node.js 程序中直接执行。
|
|
4
|
+
|
|
5
|
+
模板与使用说明:https://github.com/LastKnightCoder/tau-plugin-template
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiongtao.xt/tau-plugins",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/LastKnightCoder/editor.git"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"registry": "https://registry.npmjs.org"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"description": "Tau 桌面开发插件契约;运行时由宿主提供",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./types/packages/plugins/src/index.d.ts",
|
|
18
|
+
"default": "./runtime.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@types/react": "19.2.0",
|
|
23
|
+
"@types/react-dom": "19.2.0",
|
|
24
|
+
"slate": "0.126.2",
|
|
25
|
+
"slate-react": "0.126.4",
|
|
26
|
+
"clsx": "2.1.1",
|
|
27
|
+
"lucide-react": "0.399.0",
|
|
28
|
+
"slate-history": "0.113.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "19.2.0",
|
|
32
|
+
"react-dom": "19.2.0"
|
|
33
|
+
}
|
|
6
34
|
}
|
package/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error("Tau 插件模块由桌面宿主提供,请在插件构建中设为 external");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./src/api/index";
|
|
2
|
+
/** 扩展包通过模块增强登记元素;不要求内核知道包名或实现文件。 */
|
|
3
|
+
declare const extensionElementMapBrand: unique symbol;
|
|
4
|
+
declare const extensionInlineElementMapBrand: unique symbol;
|
|
5
|
+
export interface ExtensionElementMap {
|
|
6
|
+
[extensionElementMapBrand]: never;
|
|
7
|
+
}
|
|
8
|
+
export interface ExtensionInlineElementMap {
|
|
9
|
+
[extensionInlineElementMapBrand]: never;
|
|
10
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Editor, Element, Path } from "slate";
|
|
2
|
+
/**
|
|
3
|
+
* 命令注册表(01 §5.1):命令是编辑器的唯一动词层——热键、菜单、块面板、宿主
|
|
4
|
+
* 都引用命令 id 触发动作,enablement(when)与错误隔离(按贡献扩展熔断)只有一份。
|
|
5
|
+
*/
|
|
6
|
+
export interface EditorCommandContext {
|
|
7
|
+
/** 经热键触发时的键盘事件 */
|
|
8
|
+
event?: React.KeyboardEvent<HTMLDivElement>;
|
|
9
|
+
/** 调用方传参(如待插入的类型) */
|
|
10
|
+
payload?: unknown;
|
|
11
|
+
/** 入口针对的目标元素(块菜单打开的块);热键路径没有 */
|
|
12
|
+
element?: Element;
|
|
13
|
+
/** 目标元素的路径(与 element 成对出现),命令省一次 ReactEditor.findPath */
|
|
14
|
+
path?: Path;
|
|
15
|
+
}
|
|
16
|
+
export interface EditorCommand {
|
|
17
|
+
/** 全局唯一;内置用 `tau.*`,宿主 `host.*`,第三方将来用作者命名空间 */
|
|
18
|
+
id: string;
|
|
19
|
+
/** 展示名(菜单 / 命令面板用),可省 */
|
|
20
|
+
title?: string;
|
|
21
|
+
/** enablement:false 时热键跳过、菜单灰显 */
|
|
22
|
+
when?: (editor: Editor) => boolean;
|
|
23
|
+
/** 异步动作应返回 Promise,交给 dispatcher 隔离失败 */
|
|
24
|
+
run: (editor: Editor, ctx: EditorCommandContext) => void;
|
|
25
|
+
}
|
|
26
|
+
/** 热键只绑命令 id,不绑函数 */
|
|
27
|
+
export interface EditorHotkey {
|
|
28
|
+
key: string | string[];
|
|
29
|
+
command: string;
|
|
30
|
+
/** 普通扩展热键未消费时才尝试,仍早于内核通用兜底;同段保持声明顺序。 */
|
|
31
|
+
fallback?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface RegisteredCommand {
|
|
34
|
+
readonly command: EditorCommand;
|
|
35
|
+
/** 贡献者(扩展 id 或内核 "editor");熔断与上报按它计 */
|
|
36
|
+
readonly owner: string;
|
|
37
|
+
}
|
|
38
|
+
export declare class CommandRegistry {
|
|
39
|
+
private readonly commands;
|
|
40
|
+
register(owner: string, commands: readonly EditorCommand[]): void;
|
|
41
|
+
get(id: string): RegisteredCommand | undefined;
|
|
42
|
+
list(): readonly RegisteredCommand[];
|
|
43
|
+
}
|
|
44
|
+
/** 命令执行的最小守卫接口(ExtensionCircuitBreaker 结构兼容) */
|
|
45
|
+
export interface CommandGuard {
|
|
46
|
+
isDisabled(owner: string): boolean;
|
|
47
|
+
record(owner: string, phase: "command", error: unknown): void;
|
|
48
|
+
}
|
|
49
|
+
export interface CommandDispatcher {
|
|
50
|
+
/**
|
|
51
|
+
* 执行命令。返回 false 表示未执行(没有这个命令会告警;when 不满足静默跳过),
|
|
52
|
+
* 调用方据此决定要不要回落到别的处理;异步命令返回 true 表示已启动。
|
|
53
|
+
*/
|
|
54
|
+
execute(editor: Editor, id: string, ctx?: EditorCommandContext): boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare function createCommandDispatcher(registry: CommandRegistry, guard: CommandGuard): CommandDispatcher;
|
|
57
|
+
/** 程序化执行命令的句柄,挂在 editor 实例上(热键、菜单与宿主统一入口) */
|
|
58
|
+
export interface EditorCommandsHandle {
|
|
59
|
+
/** payload 仅传领域参数;目标 element/path 单独传入,run 会收到组合后的上下文。 */
|
|
60
|
+
execute(id: string, payload?: unknown, element?: Element, path?: Path): boolean;
|
|
61
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Descendant, Element } from "slate";
|
|
2
|
+
export type CopyDecision = "keep" | "unwrap";
|
|
3
|
+
type DeepReadonly<T> = T extends object ? {
|
|
4
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
5
|
+
} : T;
|
|
6
|
+
type CopiedElement<E extends Element> = E extends Element ? Omit<DeepReadonly<E>, "children"> & {
|
|
7
|
+
/** 解包后的片段子节点可能不再满足原元素的完整文档 schema。 */
|
|
8
|
+
readonly children: readonly DeepReadonly<Descendant>[];
|
|
9
|
+
} : never;
|
|
10
|
+
export interface CopyContext<E extends Element = Element> {
|
|
11
|
+
/** 子节点已处理的冻结片段,不是原文档节点。 */
|
|
12
|
+
readonly element: CopiedElement<E>;
|
|
13
|
+
readonly fullySelected: boolean;
|
|
14
|
+
/** 原节点的祖先类型,从外到内,不含自身。 */
|
|
15
|
+
readonly ancestorTypes: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
export type ElementCopy<E extends Element = Element> = (context: CopyContext<E>) => CopyDecision;
|
|
18
|
+
/** 装配后的有效元素策略;同类型覆盖时连同 owner 一起替换。 */
|
|
19
|
+
export interface RegisteredCopy {
|
|
20
|
+
readonly owner: string;
|
|
21
|
+
readonly copy: ElementCopy;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Element } from "slate";
|
|
2
|
+
/**
|
|
3
|
+
* 拖拽声明(01 §5.4):知识归属容器——块自己声明可拖性与放置谓词,
|
|
4
|
+
* 内核(BlockDragHost)统一渲染手柄 / 插入线 / 悬停标记,块组件只渲染内容。
|
|
5
|
+
*/
|
|
6
|
+
export interface ElementDragSpec {
|
|
7
|
+
/** 自身可拖(显示手柄);false 时本块仅作为放置目标参与 */
|
|
8
|
+
self: boolean;
|
|
9
|
+
/** 内部子内容是否参与块级拖拽;false 时更深的子块不显示手柄(如勾选项里的段落) */
|
|
10
|
+
children: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 放置谓词:拖动元素能否落到本块(含本块内部)。缺省接受任何块。
|
|
13
|
+
* 「拖到本块内部的子块前后」也经过本谓词——容器不必认识子块的类型细节。
|
|
14
|
+
*/
|
|
15
|
+
accepts?: (dragElement: Element) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* 手柄位置微调(经 cn 合并,可覆盖默认 left / top / 尺寸;如标题让出折叠箭头的位置)。
|
|
18
|
+
* 手柄挂在 chrome wrapper 上,em 按 wrapper(正文)字号计算;需随元素属性变化(如标题级别)时传函数。
|
|
19
|
+
*/
|
|
20
|
+
handleClassName?: string | ((element: Element) => string | undefined);
|
|
21
|
+
}
|
|
22
|
+
/** `true` 是 `{ self: true, children: true }` 的简写;未声明的类型没有拖拽 chrome */
|
|
23
|
+
export type ElementDrag = boolean | ElementDragSpec;
|
|
24
|
+
export declare const normalizeDragSpec: (drag: ElementDrag | undefined) => ElementDragSpec | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { Descendant, Editor, Element, NodeEntry, TextUnit } from "slate";
|
|
3
|
+
import type { RenderElementProps } from "slate-react";
|
|
4
|
+
import type { Plugin } from "../utils/plugin";
|
|
5
|
+
import type { IBlockPanelListItem, IConfigItem } from "../types";
|
|
6
|
+
import type { EditorCommand, EditorHotkey } from "./command";
|
|
7
|
+
import type { EditorMenuContribution } from "./menu";
|
|
8
|
+
import type { ElementDrag } from "./drag";
|
|
9
|
+
import type { ElementIngestSpec } from "./ingest";
|
|
10
|
+
import type { ElementCopy } from "./copy";
|
|
11
|
+
import type { DecorationSpec, MarkSpec } from "./marks";
|
|
12
|
+
/**
|
|
13
|
+
* 扩展 API v2(01 §5.1):声明式描述「这个扩展贡献了什么」,内核负责装配、隔离与分发。
|
|
14
|
+
* 所有扩展都是 defineExtension 的产物(旧 IExtension 适配层已删除,ER-019)。
|
|
15
|
+
*/
|
|
16
|
+
export declare const EXTENSION_API_VERSION = 1;
|
|
17
|
+
/** 元素渲染组件的 props;`attributes` 与 `children` 必须原样交给最外层元素 */
|
|
18
|
+
export interface ElementRenderProps<E extends Element = Element> {
|
|
19
|
+
attributes: RenderElementProps["attributes"];
|
|
20
|
+
element: E;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 元素的行为:只在选区落在该类型的元素内时调用(从最内层元素往外找),
|
|
25
|
+
* 不再全局改写 `editor.insertBreak`。返回 `true` 表示已处理;`false` 交给外层元素,最后回到默认行为。
|
|
26
|
+
*/
|
|
27
|
+
export interface ElementBehaviors<E extends Element = Element> {
|
|
28
|
+
insertBreak?(editor: Editor, entry: NodeEntry<E>): boolean;
|
|
29
|
+
deleteBackward?(editor: Editor, entry: NodeEntry<E>, unit: TextUnit): boolean;
|
|
30
|
+
insertText?(editor: Editor, entry: NodeEntry<E>, text: string): boolean;
|
|
31
|
+
/** 规范化该类型的节点;做了修改返回 `true`(Slate 会再规范化一轮) */
|
|
32
|
+
normalize?(editor: Editor, entry: NodeEntry<E>): boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ElementEmptyContext {
|
|
35
|
+
/** 使用当前编辑器已安装的声明判断子节点;未知或失败时保留。 */
|
|
36
|
+
isEmpty(node: Descendant): boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ElementSpec<E extends Element = Element> {
|
|
39
|
+
/** 元素 type;内置类型沿用现有名字,兼容已有文档 */
|
|
40
|
+
type: string;
|
|
41
|
+
kind: "block" | "inline";
|
|
42
|
+
isVoid?: boolean;
|
|
43
|
+
/** 后代的方向键/退格导航由领域接管,核心不执行默认相邻块导航。 */
|
|
44
|
+
isolateBlockNavigation?: boolean;
|
|
45
|
+
/** 判定源码等非 children 内容是否为空;未声明时内核不推断扩展私有字段 */
|
|
46
|
+
isEmpty?: (element: E, context: ElementEmptyContext) => boolean;
|
|
47
|
+
/** 渲染组件,可以是 `lazy()`:加载期间内核显示保留结构的空壳 */
|
|
48
|
+
render: ComponentType<ElementRenderProps<E>>;
|
|
49
|
+
behaviors?: ElementBehaviors<E>;
|
|
50
|
+
/** 选区复制的包装策略;未声明时保留整棵片段子树。仅非 void 块生效。 */
|
|
51
|
+
copy?: ElementCopy<E>;
|
|
52
|
+
/** 拖拽声明(01 §5.4):未声明的类型没有拖拽 chrome;块组件不再自己接手柄 */
|
|
53
|
+
drag?: ElementDrag;
|
|
54
|
+
/** 内容注入声明(01 §5.4):drop 与 paste 共用的认领规则;块组件不再改写 insertData */
|
|
55
|
+
ingest?: ElementIngestSpec;
|
|
56
|
+
}
|
|
57
|
+
export interface ExtensionLayerProps {
|
|
58
|
+
/** 根 UI 在 Editable 外,不能通过 Slate 的 useReadOnly 读取此状态。 */
|
|
59
|
+
readonly readOnly: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface EditorExtension {
|
|
62
|
+
/** 全局唯一;内置用 `tau.*`,第三方将来用作者命名空间 */
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly apiVersion: typeof EXTENSION_API_VERSION;
|
|
65
|
+
readonly elements?: readonly ElementSpec[];
|
|
66
|
+
readonly marks?: readonly MarkSpec[];
|
|
67
|
+
/** 暂态装饰(不进文档);外观由本扩展 marks 里 keys 对应的声明渲染 */
|
|
68
|
+
readonly decorations?: readonly DecorationSpec[];
|
|
69
|
+
/** 在编辑器的 Slate/Kit 上下文挂载辅助 UI,组件自行接宿主浮层仲裁。 */
|
|
70
|
+
readonly layers?: readonly ComponentType<ExtensionLayerProps>[];
|
|
71
|
+
/** 块菜单条目;给函数时每次打开菜单求值 */
|
|
72
|
+
readonly blockPanel?: readonly IBlockPanelListItem[] | ((editor: Editor) => readonly IBlockPanelListItem[]);
|
|
73
|
+
/** 悬浮工具条条目 */
|
|
74
|
+
readonly toolbar?: readonly IConfigItem[];
|
|
75
|
+
/** 贡献的命令:菜单、块面板、宿主都引用命令 id 触发动作 */
|
|
76
|
+
readonly commands?: readonly EditorCommand[];
|
|
77
|
+
/** 热键只绑命令 id(不绑函数);同一键位允许多条声明按顺序匹配(沿用旧语义) */
|
|
78
|
+
readonly hotkeys?: readonly EditorHotkey[];
|
|
79
|
+
/** 手柄菜单与右键菜单的特有条目(01 §5.4);条目只引用命令 id */
|
|
80
|
+
readonly menu?: EditorMenuContribution;
|
|
81
|
+
/** 贡献到指定源类型的菜单;不改变 menu 默认归属自身元素的规则。 */
|
|
82
|
+
readonly menuFor?: Readonly<Record<string, EditorMenuContribution>>;
|
|
83
|
+
/**
|
|
84
|
+
* 挂到**其他**元素类型上的行为,给「在别的元素里触发、产出本元素」的场景,
|
|
85
|
+
* 典型是快捷语法(段落里输入 `---` 回车变分割线)。与该类型自身的行为按扩展顺序一起分发。
|
|
86
|
+
*/
|
|
87
|
+
readonly behaviorsFor?: Readonly<Record<string, ElementBehaviors>>;
|
|
88
|
+
/**
|
|
89
|
+
* @internal 受信任层(ER-005):原始 Slate 插件,只给内核内置扩展表达声明式写不出的跨节点逻辑。
|
|
90
|
+
* 将来开放第三方时不进公开类型。
|
|
91
|
+
*/
|
|
92
|
+
readonly plugins?: readonly Plugin[];
|
|
93
|
+
}
|
|
94
|
+
export type ExtensionDefinition = Omit<EditorExtension, "apiVersion"> & {
|
|
95
|
+
apiVersion?: typeof EXTENSION_API_VERSION;
|
|
96
|
+
};
|
|
97
|
+
export declare function defineExtension(definition: ExtensionDefinition): EditorExtension;
|
|
98
|
+
/** 按元素类型收窄 render / behaviors 的参数类型;运行时原样返回 */
|
|
99
|
+
export declare function defineElement<E extends Element>(spec: ElementSpec<E>): ElementSpec;
|
|
100
|
+
export declare const isEditorExtension: (value: unknown) => value is EditorExtension;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tau/editor/api`:扩展作者的渲染入口;纯服务契约经 /api/services(ER-021)。
|
|
3
|
+
*
|
|
4
|
+
* 只放写扩展需要的东西:声明、服务、主题、少量工具。编辑器组件、kit 工厂等宿主用的留在包根入口。
|
|
5
|
+
* 未标注过渡用途的导出按稳定 API 维护;过渡导出只供现有内部消费者迁移使用。
|
|
6
|
+
*/
|
|
7
|
+
export { EXTENSION_API_VERSION, defineExtension, defineElement, type EditorExtension, type ExtensionDefinition, type ElementSpec, type ElementEmptyContext, type ElementBehaviors, type ElementRenderProps, type ExtensionLayerProps, } from "./extension";
|
|
8
|
+
export type { AnyExtension } from "./legacy";
|
|
9
|
+
export type { CopyDecision, CopyContext, ElementCopy } from "./copy";
|
|
10
|
+
export type { MarkSpec, MarkRenderProps, DecorationSpec } from "./marks";
|
|
11
|
+
export { useToolbarState } from "./toolbar";
|
|
12
|
+
export { default as ToolbarSubmenu } from "../components/HoveringToolbar/FloatingSubmenu";
|
|
13
|
+
export { Tooltip as EditorTooltip } from "../ui/Tooltip";
|
|
14
|
+
export { CaretRight as EditorCaretRight } from "../ui/CaretRight";
|
|
15
|
+
export { getParagraphShortcutEntry } from "../utils/paragraphShortcut";
|
|
16
|
+
export type { IngestContext, ElementIngestSpec } from "./ingest";
|
|
17
|
+
export { CommandRegistry, createCommandDispatcher, type EditorCommand, type EditorCommandContext, type EditorHotkey, type RegisteredCommand, type CommandDispatcher, type CommandGuard, } from "./command";
|
|
18
|
+
export { type EditorMenuEntry, type EditorMenuContext, type EditorMenuContribution, type MenuValue, } from "./menu";
|
|
19
|
+
export { createServiceId, IThemeService, IExtensionErrorReporter, IEditorNotifier, type ServiceIdentifier, } from "../services/tokens";
|
|
20
|
+
export { useService, useOptionalService, useNotifier } from "../services/hooks";
|
|
21
|
+
export { notifierOf } from "../services/editorNotifier";
|
|
22
|
+
export type { EditorNotifier, EditorFeedback, EditorLoadingHandle, EditorConfirmOptions, EditorPromptOptions, } from "../services/notifier";
|
|
23
|
+
export { useEditorTheme, type EditorTheme } from "../theme/context";
|
|
24
|
+
export type { ThemeService, EditorThemeMode } from "../theme/ThemeService";
|
|
25
|
+
export type { IBlockPanelListItem, IConfigItem } from "../types";
|
|
26
|
+
export type { CustomElement, InlineElement, BlockElement } from "../types/custom-element";
|
|
27
|
+
export { setOrInsertNode, canSetOrInsertNode, focusInsertedPreviewElement, } from "../utils/insertElement";
|
|
28
|
+
export { default as ElementMenu, type ElementMenuProps } from "../components/ElementMenu/index";
|
|
29
|
+
export { default as InlineChromiumBugfix } from "../components/InlineChromiumBugFix/index";
|
|
30
|
+
export { default as useIsLastElement } from "../hooks/useIsLastElement";
|
|
31
|
+
export { registerBlockNavigation, hasBlockNavigation, unregisterBlockNavigation, focusPreviousBlock, focusNextBlock, type BlockNavigationHandler, } from "../utils/blockNavigation";
|
|
32
|
+
export { isCollapsed, getCurrentTextNode } from "../utils/editor";
|
|
33
|
+
export { deleteVoidBlock } from "../utils/nodeOperations";
|
|
34
|
+
export { getSelectionSnapshot, isSelectionSnapshotUnchanged } from "../utils/selectionSnapshot";
|
|
35
|
+
export { createParagraph, isParagraphElement, type ParagraphElement } from "../model/paragraph";
|
|
36
|
+
export { insertParagraphAndFocus } from "../utils/editor";
|
|
37
|
+
export { isAtParagraphStart, isParagraphAndEmpty } from "../utils/editor";
|
|
38
|
+
export { isNodeEmpty } from "../kit/elementEmpty";
|
|
39
|
+
export { createBlockConversionMenu } from "../menu/conversion";
|
|
40
|
+
export { getCommandElementPath } from "../utils/commandTarget";
|
|
41
|
+
export { captureEditorSubmission, captureElementSubmission, captureInsertionSubmission, type Submission, type SubmissionOutcome, type SubmissionDiscardReason, } from "./submission";
|
|
42
|
+
export { default as AddParagraph, type AddParagraphRef } from "../components/AddParagraph/index";
|
|
43
|
+
export { IOverlayBackDismiss, type OverlayBackDismissProps, type OverlayBackDismissAdapter, } from "../services/overlayBackDismiss";
|
|
44
|
+
export { default as OverlayBackDismiss } from "../components/OverlayBackDismiss/index";
|
|
45
|
+
export { getElementParent, getClosestCurrentElement } from "../utils/editor";
|
|
46
|
+
export { getParentNodeByNode, getPreviousSiblingNode } from "../utils/element";
|
|
47
|
+
export { getPrevPath } from "../utils/path";
|
|
48
|
+
export { hitEmptyOrInlineChild, exitContainerOnEmptyParagraph } from "../utils/container";
|
|
49
|
+
export { replaceNode } from "../utils/editor";
|
|
50
|
+
export { findPathSafely } from "../utils/path";
|
|
51
|
+
export type { Plugin } from "../utils/plugin";
|
|
52
|
+
export { BLOCK_DRAG_GROUP, DragHandle, type DragHandleProps } from "../components/BlockDrag/index";
|
|
53
|
+
export { panAroundAnchor, pointFromCenter, type Point as ZoomPanPoint } from "../utils/zoomPan";
|
|
54
|
+
export { FloatingToolbar, ToolbarDivider, ToolbarIconButton } from "../components/FloatingToolbar/index";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Editor, Point } from "slate";
|
|
2
|
+
/**
|
|
3
|
+
* 内容注入声明(01 §5.4):drop 与 paste 归并为一条认领式管线(共同形状是 DataTransfer)。
|
|
4
|
+
* 扩展声明自己认领什么(files 的 MIME / text 的谓词),内核负责分桶、隔离与熔断;
|
|
5
|
+
* drop 与 paste 共用同一个 run,经 ctx.source 区分来源。
|
|
6
|
+
*/
|
|
7
|
+
export interface IngestContext {
|
|
8
|
+
editor: Editor;
|
|
9
|
+
/** 认领到的文件(files 侧);drop 与 paste 都可能是多个 */
|
|
10
|
+
files?: readonly File[];
|
|
11
|
+
/** 原始剪贴板 / 拖拽数据(text 侧认领与兜底读取用) */
|
|
12
|
+
data: DataTransfer;
|
|
13
|
+
/** 拖放落点(source 为 drop 时有;粘贴跟随当前选区) */
|
|
14
|
+
point?: Point;
|
|
15
|
+
source: "drop" | "paste";
|
|
16
|
+
}
|
|
17
|
+
export interface IngestFilesRule {
|
|
18
|
+
/** MIME 认领(`image/*` 前缀通配或 `application/pdf` 精确);完全相同 accept 重复声明建 kit 抛错 */
|
|
19
|
+
accept: string;
|
|
20
|
+
/** 认领到的整批文件一次处理;抛错按贡献扩展熔断 */
|
|
21
|
+
run: (ctx: IngestContext) => void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface IngestTextRule {
|
|
24
|
+
/** 文本侧认领谓词;求值在 markdown 导入之前 */
|
|
25
|
+
when: (data: DataTransfer) => boolean;
|
|
26
|
+
run: (ctx: IngestContext) => void | Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export interface ElementIngestSpec {
|
|
29
|
+
files?: IngestFilesRule;
|
|
30
|
+
text?: IngestTextRule;
|
|
31
|
+
}
|
|
32
|
+
/** 一个扩展的内容注入声明(装配产出的形态);owner 用于隔离熔断与日志 */
|
|
33
|
+
export interface IngestSource {
|
|
34
|
+
readonly owner: string;
|
|
35
|
+
readonly files?: IngestFilesRule;
|
|
36
|
+
readonly text?: IngestTextRule;
|
|
37
|
+
}
|
|
38
|
+
/** accept 匹配:`*` 全收、`type/*` 前缀、其余精确 */
|
|
39
|
+
export declare const ingestAccepts: (accept: string, mimeType: string) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditorExtension } from "./extension";
|
|
2
|
+
/**
|
|
3
|
+
* kit 接受的扩展。旧 `IExtension` 适配层已随三端迁移完成而删除(2026-09-30,
|
|
4
|
+
* docs/editor-refactor DECISIONS):所有扩展都是 defineExtension 的产物。
|
|
5
|
+
* `AnyExtension` 保留为 `EditorExtension` 的别名,等全仓标注自然更替后再收。
|
|
6
|
+
*/
|
|
7
|
+
export type AnyExtension = EditorExtension;
|
|
8
|
+
export declare const toEditorExtension: (extension: AnyExtension) => EditorExtension;
|
|
9
|
+
/** 扩展贡献的元素类型 */
|
|
10
|
+
export declare const elementTypesOf: (extension: EditorExtension) => string[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { Editor, NodeEntry, Range, Text } from "slate";
|
|
3
|
+
export interface MarkRenderProps {
|
|
4
|
+
readonly leaf: Readonly<Text>;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export interface MarkSpec {
|
|
8
|
+
id: string;
|
|
9
|
+
keys: readonly string[];
|
|
10
|
+
/** 只包装 children;Slate 属性及文本承载由核心持有。 */
|
|
11
|
+
render: ComponentType<MarkRenderProps>;
|
|
12
|
+
/**
|
|
13
|
+
* 非包含标记:光标落到这些标记的边缘时默认停在标记外侧(如行内代码)。
|
|
14
|
+
* 其余标记默认沿用光标左侧的格式;用户可用左右键切换偏向。
|
|
15
|
+
*/
|
|
16
|
+
nonInclusiveKeys?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export interface RegisteredMark {
|
|
19
|
+
readonly owner: string;
|
|
20
|
+
readonly spec: MarkSpec;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 暂态装饰:按节点算出带属性的 Range,属性只出现在渲染用的叶子上,不进文档、不被保存。
|
|
24
|
+
* 配合同一扩展声明的 MarkSpec(keys 取装饰属性名)渲染外观。与宿主的 decorate 合并执行。
|
|
25
|
+
*/
|
|
26
|
+
export interface DecorationSpec {
|
|
27
|
+
id: string;
|
|
28
|
+
decorate(editor: Editor, entry: NodeEntry): Range[];
|
|
29
|
+
/** 外部数据变化时使装饰重算,订阅随实例及服务作用域清理。 */
|
|
30
|
+
subscribe?(editor: Editor, invalidate: () => void): (() => void) | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface RegisteredDecoration {
|
|
33
|
+
readonly owner: string;
|
|
34
|
+
readonly spec: DecorationSpec;
|
|
35
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { Editor, Element, Path } from "slate";
|
|
3
|
+
/**
|
|
4
|
+
* 菜单贡献点(01 §5.4):手柄菜单与右键菜单统一的数据来源。
|
|
5
|
+
* 条目只引用命令 id(不写内联函数),执行、enablement 与熔断与热键共用命令注册表。
|
|
6
|
+
*/
|
|
7
|
+
/** 菜单声明的求值上下文:菜单针对的目标元素及其路径(打开时求一次) */
|
|
8
|
+
export interface EditorMenuContext {
|
|
9
|
+
editor: Editor;
|
|
10
|
+
element: Element;
|
|
11
|
+
path: Path;
|
|
12
|
+
}
|
|
13
|
+
/** `T | ((ctx) => T)`:静态声明或打开菜单时求值(如「收起 / 展开」的动态标题) */
|
|
14
|
+
export type MenuValue<T> = T | ((ctx: EditorMenuContext) => T);
|
|
15
|
+
export interface EditorMenuEntry {
|
|
16
|
+
/** 条目 id,同一份菜单内唯一;内核默认条目直接用命令 id */
|
|
17
|
+
id: string;
|
|
18
|
+
title: MenuValue<string>;
|
|
19
|
+
icon?: MenuValue<ReactNode>;
|
|
20
|
+
/** 引用的命令 id;只有 `children` 的父条目可省 */
|
|
21
|
+
command?: string;
|
|
22
|
+
/** 命令的静态参数(如 `{ level: 2 }`),与目标元素一起进命令上下文 */
|
|
23
|
+
payload?: unknown;
|
|
24
|
+
/** `false` 时条目(连同 children)不出现:条目对目标元素的适用范围 */
|
|
25
|
+
when?: (ctx: EditorMenuContext) => boolean;
|
|
26
|
+
/** `false` 时灰显(enablement),打开菜单时求值 */
|
|
27
|
+
disabled?: (ctx: EditorMenuContext) => boolean;
|
|
28
|
+
/** 分组;缺省 `"actions"`(扩展特有条目)。组间画分隔线,组内按 `order` 与声明顺序 */
|
|
29
|
+
group?: string;
|
|
30
|
+
order?: number;
|
|
31
|
+
danger?: boolean;
|
|
32
|
+
children?: readonly EditorMenuEntry[];
|
|
33
|
+
/** 同名顶层无命令菜单均声明时合并子项;未声明仍整项覆盖。 */
|
|
34
|
+
mergeChildren?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** 扩展贡献的菜单:静态数组,或需要按 editor 求值的工厂(如过滤服务提供的动作) */
|
|
37
|
+
export type EditorMenuContribution = readonly EditorMenuEntry[] | ((editor: Editor) => readonly EditorMenuEntry[]);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Editor, Element, Path, type BaseRange } from "slate";
|
|
2
|
+
import type { ServiceIdentifier } from "../services/tokens";
|
|
3
|
+
interface SubmissionOptions {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
/** 只跟踪本操作依赖的服务;无关主题或插槽派生不取消操作。 */
|
|
6
|
+
services?: readonly ServiceIdentifier<unknown>[];
|
|
7
|
+
}
|
|
8
|
+
export type SubmissionDiscardReason = "cancelled" | "scope-ended" | "readonly" | "target-lost" | "target-changed";
|
|
9
|
+
export type SubmissionOutcome = {
|
|
10
|
+
status: "committed";
|
|
11
|
+
} | {
|
|
12
|
+
status: "discarded";
|
|
13
|
+
reason: SubmissionDiscardReason;
|
|
14
|
+
};
|
|
15
|
+
export interface Submission<T> {
|
|
16
|
+
readonly signal: AbortSignal;
|
|
17
|
+
/** 失效时终结操作并释放引用;不能放进要求纯判断的表单 validate。 */
|
|
18
|
+
check(): SubmissionDiscardReason | undefined;
|
|
19
|
+
/** 只提交一次;回调必须同步,异常向上传播,不能依赖事务回滚。 */
|
|
20
|
+
commit(write: (target: T) => undefined): SubmissionOutcome;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
}
|
|
23
|
+
/** 无元素目标的输入请求只绑定编辑会话和调用方取消信号。 */
|
|
24
|
+
export declare const captureEditorSubmission: (editor: Editor, options?: SubmissionOptions) => Submission<void>;
|
|
25
|
+
export declare function captureElementSubmission<E extends Element>(editor: Editor, options: SubmissionOptions & {
|
|
26
|
+
element: E;
|
|
27
|
+
path?: Path;
|
|
28
|
+
accept?: (current: E) => boolean;
|
|
29
|
+
}): Submission<{
|
|
30
|
+
element: E;
|
|
31
|
+
path: Path;
|
|
32
|
+
}>;
|
|
33
|
+
/** 段落内的原始折叠落点;后续选区变化不会改写该落点。 */
|
|
34
|
+
export declare function captureInsertionSubmission(editor: Editor, signal?: AbortSignal): Submission<{
|
|
35
|
+
range: BaseRange;
|
|
36
|
+
path: Path;
|
|
37
|
+
}>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Element } from "slate";
|
|
3
|
+
interface IAddParagraphProps {
|
|
4
|
+
element: Element;
|
|
5
|
+
onAddParagraph?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface AddParagraphRef {
|
|
8
|
+
addParagraph: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare const AddParagraph: React.ForwardRefExoticComponent<IAddParagraphProps & React.RefAttributes<AddParagraphRef>>;
|
|
11
|
+
export default AddParagraph;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentType, MouseEvent, ReactNode, Ref } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* 块的拖拽手柄与放置指示,所有块共用。
|
|
4
|
+
*
|
|
5
|
+
* 显示逻辑按块隔离:块的外层容器加 `BLOCK_DRAG_GROUP`,带 `data-block-reveal` 的元素(手柄、标题折叠箭头)
|
|
6
|
+
* 只在**最内层**被悬停的块里出现,规则见 `theme/editor.css`。
|
|
7
|
+
* 不用 Tailwind 命名 group:`group-hover/x` 匹配的是「任意同名祖先被悬停」,嵌套块会一起亮。
|
|
8
|
+
*/
|
|
9
|
+
export declare const BLOCK_DRAG_GROUP = "ed-block";
|
|
10
|
+
export interface DragHandleProps {
|
|
11
|
+
/** useDragAndDrop 返回的 drag 连接器 */
|
|
12
|
+
dragRef: Ref<HTMLDivElement> | ((node: HTMLDivElement | null) => void);
|
|
13
|
+
canDrag: boolean;
|
|
14
|
+
onClick?: (event: MouseEvent) => void;
|
|
15
|
+
/** 位置微调(经 cn 合并,可覆盖 top / left / height) */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** 手柄图标;传 null 渲染无图标的热区 */
|
|
18
|
+
icon?: ComponentType<{
|
|
19
|
+
className?: string;
|
|
20
|
+
}> | null;
|
|
21
|
+
iconClassName?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function DragHandle({ dragRef, canDrag, onClick, className, icon: Icon, iconClassName, }: DragHandleProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export interface DropIndicatorProps {
|
|
25
|
+
/** 当前是否有可放置的拖拽经过本块 */
|
|
26
|
+
active: boolean;
|
|
27
|
+
/** 插入到本块之前(上方)还是之后(下方) */
|
|
28
|
+
before: boolean;
|
|
29
|
+
/** 位置微调(经 cn 合并,可覆盖 top / bottom) */
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
/** 拖拽经过时的 accent 插入线;父元素需 position: relative */
|
|
33
|
+
export declare function DropIndicator({ active, before, className }: DropIndicatorProps): ReactNode;
|
|
34
|
+
/** 拖拽源 / 放置目标的半透明(原 .dragging / .drop 的 opacity: 0.5) */
|
|
35
|
+
export declare const dimWhileDragging: (dragging: boolean) => "opacity-50" | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Element } from "slate";
|
|
2
|
+
export interface ElementMenuProps {
|
|
3
|
+
element: Element;
|
|
4
|
+
position: {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
/** 在指定位置打开目标元素已注册的菜单,不接受绕过命令协议的条目。 */
|
|
11
|
+
export default function ElementMenu({ element, position, onClose }: ElementMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { LucideIcon } from "lucide-react";
|
|
3
|
+
/**
|
|
4
|
+
* 块右上角的悬浮操作条(代码块、源码预览块共用):浅色实底 + 描边 + 浮起投影,随主题。
|
|
5
|
+
* 显隐交给调用方的 group-hover 类(Tailwind 需要静态类名),例如
|
|
6
|
+
* `group-hover/code:pointer-events-auto group-hover/code:translate-y-0 group-hover/code:opacity-100`。
|
|
7
|
+
* 定位取 min(右上角, 垂直居中):块较矮(如单行)时居中,较高时贴右上角。
|
|
8
|
+
*/
|
|
9
|
+
export declare const FloatingToolbar: ({ className, children, }: {
|
|
10
|
+
className?: string;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const ToolbarDivider: () => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const ToolbarIconButton: ({ icon: Icon, title, onClick, disabled, tone, active, className, }: {
|
|
15
|
+
icon: LucideIcon;
|
|
16
|
+
title: string;
|
|
17
|
+
onClick?: () => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
tone?: "default" | "danger" | "ok";
|
|
20
|
+
/** 按下态(开关类按钮) */
|
|
21
|
+
active?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { HoveringSubmenuTrigger } from "./context";
|
|
3
|
+
import { type FloatingPlacement } from "./floatingPosition";
|
|
4
|
+
interface FloatingSubmenuProps {
|
|
5
|
+
open: boolean;
|
|
6
|
+
onOpenChange: (open: boolean) => void;
|
|
7
|
+
trigger: HoveringSubmenuTrigger;
|
|
8
|
+
isHoveringBarShow: boolean;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
content: React.ReactNode;
|
|
11
|
+
preferredPlacement?: FloatingPlacement;
|
|
12
|
+
gap?: number;
|
|
13
|
+
zIndex?: number;
|
|
14
|
+
triggerClassName?: string;
|
|
15
|
+
panelClassName?: string;
|
|
16
|
+
panelStyle?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
declare const FloatingSubmenu: (props: FloatingSubmenuProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export default FloatingSubmenu;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type HoveringSubmenuTrigger = "hover" | "click";
|
|
3
|
+
export interface IHoveringBarContext {
|
|
4
|
+
isHoveringBarShow: boolean;
|
|
5
|
+
isCompact: boolean;
|
|
6
|
+
submenuTrigger: HoveringSubmenuTrigger;
|
|
7
|
+
}
|
|
8
|
+
export declare const HoveringBarContext: React.Context<IHoveringBarContext>;
|