@xiongtao.xt/tau-plugins 0.0.0-stage → 0.2.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 +49 -0
- package/types/packages/plugins/src/editor.d.ts +37 -0
- package/types/packages/plugins/src/index.d.ts +7 -0
- package/types/packages/plugins/src/pages.d.ts +23 -0
- package/types/packages/plugins/src/settings.d.ts +19 -0
- package/types/packages/plugins/src/sidebar.d.ts +29 -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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type FloatingPlacement = "top" | "bottom";
|
|
2
|
+
export type FloatingAnchorRect = {
|
|
3
|
+
top: number;
|
|
4
|
+
bottom: number;
|
|
5
|
+
left: number;
|
|
6
|
+
width: number;
|
|
7
|
+
};
|
|
8
|
+
export type CalculateFloatingPositionInput = {
|
|
9
|
+
anchorRect: FloatingAnchorRect;
|
|
10
|
+
viewportWidth: number;
|
|
11
|
+
viewportHeight: number;
|
|
12
|
+
floatingWidth: number;
|
|
13
|
+
floatingHeight: number;
|
|
14
|
+
gap?: number;
|
|
15
|
+
preferredPlacement?: FloatingPlacement;
|
|
16
|
+
};
|
|
17
|
+
export type FloatingPosition = {
|
|
18
|
+
top: number;
|
|
19
|
+
left: number;
|
|
20
|
+
placement: FloatingPlacement;
|
|
21
|
+
};
|
|
22
|
+
export declare function calculateFloatingPosition(input: CalculateFloatingPositionInput): FloatingPosition;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type OverlayBackDismissProps } from "../../services/overlayBackDismiss";
|
|
2
|
+
import React from "react";
|
|
3
|
+
/** 仅在 open 期间挂载宿主登记器;未提供服务时由浮层的按钮及焦点链关闭。 */
|
|
4
|
+
export default function OverlayBackDismiss(props: OverlayBackDismissProps): React.ReactElement<OverlayBackDismissProps, string | React.JSXElementConstructor<any>> | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Element, type Descendant, type Editor } from "slate";
|
|
2
|
+
import type { ElementSpec } from "../api/extension";
|
|
3
|
+
export declare const registerElementEmpty: (editor: Editor, elements: readonly ElementSpec[]) => void;
|
|
4
|
+
export declare const isNodeEmpty: (node: Descendant, editor?: Editor) => boolean;
|
|
5
|
+
export declare const isDeclaredElementEmpty: (editor: Editor | undefined, element: Element) => boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EditorMenuContribution, EditorMenuEntry } from "../api/menu";
|
|
2
|
+
/** 只组合转换菜单的展示结构,源类型与具体转换由领域提供。 */
|
|
3
|
+
export declare function createBlockConversionMenu(sourceTypes: readonly string[], entries: readonly EditorMenuEntry[]): Readonly<Record<string, EditorMenuContribution>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Node } from "slate";
|
|
2
|
+
import type { ParagraphElement } from "../types/element/paragraph";
|
|
3
|
+
export type { ParagraphElement } from "../types/element/paragraph";
|
|
4
|
+
export declare const createParagraph: () => ParagraphElement;
|
|
5
|
+
export declare const isParagraphElement: (node: Node) => node is ParagraphElement;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 扩展运行期错误的上报(01 §5.2):宿主可接入自己的日志 / 提示,缺省只写控制台 */
|
|
2
|
+
export interface ExtensionErrorEvent {
|
|
3
|
+
/** 出错扩展的元素 type;内核自带的快捷键记为 "editor" */
|
|
4
|
+
extension: string;
|
|
5
|
+
phase: "render" | "plugin" | "behavior" | "hotkey" | "command" | "ingest" | "copy" | "decorate";
|
|
6
|
+
error: unknown;
|
|
7
|
+
/** 这次错误是否触发熔断(该扩展的行为与快捷键此后停用) */
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ExtensionErrorReporter {
|
|
11
|
+
report(event: ExtensionErrorEvent): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const consoleErrorReporter: ExtensionErrorReporter;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ServiceIdentifier } from "./tokens";
|
|
2
|
+
import type { ServiceRegistry } from "./registry";
|
|
3
|
+
import type { EditorNotifier } from "./notifier";
|
|
4
|
+
/** 获取注册表本身,用于派生子注册表或非 React 场景转发 */
|
|
5
|
+
export declare function useServiceRegistry(): ServiceRegistry;
|
|
6
|
+
/** 获取必选服务,未注册时抛错 */
|
|
7
|
+
export declare function useService<T>(id: ServiceIdentifier<T>): T;
|
|
8
|
+
/** 获取可选服务,未注册时返回 undefined,由消费侧显式降级 */
|
|
9
|
+
export declare function useOptionalService<T>(id: ServiceIdentifier<T>): T | undefined;
|
|
10
|
+
/** 轻提示与确认:宿主没注册时用默认实现,编辑器组件不需要判空 */
|
|
11
|
+
export declare function useNotifier(): EditorNotifier;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑器内的轻提示与确认(取代 antd message / modal)。
|
|
3
|
+
* 默认实现:提示走 `@tau/ui` 的 toast(宿主须挂 `<ToastHost />`),确认与输入走 `@tau/ui` 的对话框
|
|
4
|
+
* (编辑器自带挂载点)。有自己提示体系的宿主(mobile)注册自己的实现。
|
|
5
|
+
*/
|
|
6
|
+
export interface EditorNotifier {
|
|
7
|
+
success(message: string): void;
|
|
8
|
+
error(message: string): void;
|
|
9
|
+
warning(message: string): void;
|
|
10
|
+
/** 常驻的进行中提示;返回的句柄用来把同一条提示落定为成功 / 失败 */
|
|
11
|
+
loading(message: string): EditorLoadingHandle;
|
|
12
|
+
/** 危险操作的确认;用户确认返回 true */
|
|
13
|
+
confirm(options: EditorConfirmOptions): Promise<boolean>;
|
|
14
|
+
/** 单行文本输入(如媒体的网络地址);提交返回去掉首尾空白的值,取消返回 null */
|
|
15
|
+
prompt(options: EditorPromptOptions): Promise<string | null>;
|
|
16
|
+
}
|
|
17
|
+
export interface EditorLoadingHandle {
|
|
18
|
+
success(message: string): void;
|
|
19
|
+
error(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
export interface EditorConfirmOptions {
|
|
22
|
+
title: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
confirmText?: string;
|
|
25
|
+
cancelText?: string;
|
|
26
|
+
danger?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface EditorPromptOptions {
|
|
29
|
+
/** 发起编辑器隐藏、卸载或换源时取消;宿主须关闭对应输入框并返回 null。 */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
title: string;
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
defaultValue?: string;
|
|
34
|
+
confirmText?: string;
|
|
35
|
+
cancelText?: string;
|
|
36
|
+
/** 虚拟键盘类型(同 HTML inputMode):url 让手机弹出网址键盘 */
|
|
37
|
+
inputMode?: "text" | "url";
|
|
38
|
+
/**
|
|
39
|
+
* 提交前校验(入参已去首尾空白,空值不会进来):返回错误文案则输入框保持打开并就地提示。
|
|
40
|
+
* 须是纯判断——输入框可能多次提交,副作用放在 prompt resolve 之后。
|
|
41
|
+
*/
|
|
42
|
+
validate?: (value: string) => string | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** 菜单构建函数等只需要结果反馈的地方收这个窄接口 */
|
|
45
|
+
export type EditorFeedback = Pick<EditorNotifier, "success" | "error" | "warning">;
|
|
46
|
+
export declare const defaultEditorNotifier: EditorNotifier;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
export interface OverlayBackDismissProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onDismiss: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface OverlayBackDismissAdapter {
|
|
7
|
+
/** 在当前编辑器所在的页面上下文登记退场;不渲染 UI,不监听全局按键。 */
|
|
8
|
+
Layer: ComponentType<OverlayBackDismissProps>;
|
|
9
|
+
}
|
|
10
|
+
export declare const IOverlayBackDismiss: import("../../../shared/service-contract").ServiceIdentifier<OverlayBackDismissAdapter>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 服务注册表实现已下沉到 @tau/shared/service-registry(编辑器与白板等宿主共用),
|
|
3
|
+
* 此处保留原导入路径与公共 API 不变。
|
|
4
|
+
*/
|
|
5
|
+
export { createServiceRegistry, createChildRegistry } from "../../../shared/service-registry";
|
|
6
|
+
export type { ServiceRegistry, ServiceRegister, ServiceRegistration, } from "../../../shared/service-registry";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ThemeService } from "../theme/ThemeService";
|
|
2
|
+
import type { ExtensionErrorReporter } from "./errorReporter";
|
|
3
|
+
import type { EditorNotifier } from "./notifier";
|
|
4
|
+
export { createServiceId, type ServiceIdentifier } from "../../../shared/service-contract";
|
|
5
|
+
/** 主题服务:未注册时编辑器用 DOM 默认实现(读 <html> 的 data-mode / data-theme) */
|
|
6
|
+
export declare const IThemeService: import("../../../shared/service-contract").ServiceIdentifier<ThemeService>;
|
|
7
|
+
/** 轻提示与确认:未注册时用 @tau/ui 的 toast(宿主需挂 ToastHost)与原生 confirm */
|
|
8
|
+
export declare const IEditorNotifier: import("../../../shared/service-contract").ServiceIdentifier<EditorNotifier>;
|
|
9
|
+
/** 扩展运行期错误上报:未注册时写控制台 */
|
|
10
|
+
export declare const IExtensionErrorReporter: import("../../../shared/service-contract").ServiceIdentifier<ExtensionErrorReporter>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 主题服务:编辑器读取「当前明暗」与「token 实际取值」的唯一入口。
|
|
3
|
+
*
|
|
4
|
+
* CSS 能表达的地方一律写 --ed-*(见 editor.css),不必经过本服务;本服务服务于 CSS 表达不了
|
|
5
|
+
* 的场景:mermaid / shiki / codemirror / canvas 这类要把颜色当值传进去的渲染器。
|
|
6
|
+
*/
|
|
7
|
+
export type EditorThemeMode = "light" | "dark";
|
|
8
|
+
export interface ThemeService {
|
|
9
|
+
/** 生效明暗 */
|
|
10
|
+
readonly mode: EditorThemeMode;
|
|
11
|
+
/** 宿主当前主题族的 key(桌面 paper/ocean…,移动端 apricot/midnight…);宿主未标注时为空串 */
|
|
12
|
+
readonly themeKey: string;
|
|
13
|
+
/** 读取 CSS 变量的计算值,传入不带 `--` 的词(`ink-1` 取 --tau-ink-1,`code-bg` 取 --ed-code-bg) */
|
|
14
|
+
token(word: string): string;
|
|
15
|
+
/** 主题变化时通知;返回取消订阅 */
|
|
16
|
+
subscribe(listener: () => void): () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 默认实现:明暗与主题族从 DOM 读(`data-mode` / `data-theme`),token 取计算样式。
|
|
20
|
+
* 传入 scope 可让 token 从编辑器子树读起(局部强制明暗的场景)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function createDomThemeService(root?: HTMLElement, scope?: () => HTMLElement | null): ThemeService;
|
|
23
|
+
/** 固定明暗的实现:预览、导出、测试等不跟随宿主的场景 */
|
|
24
|
+
export declare function createStaticThemeService(mode: EditorThemeMode, tokens?: Record<string, string>): ThemeService;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type EditorThemeMode, type ThemeService } from "./ThemeService";
|
|
3
|
+
/** 宿主用:让子树里的编辑器按给定明暗 / 主题族渲染,不跟随宿主;缺省的维度不覆盖 */
|
|
4
|
+
export declare function EditorThemeOverride({ mode, themeKey, children, }: {
|
|
5
|
+
mode?: EditorThemeMode;
|
|
6
|
+
themeKey?: string;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
/** 编辑器内部用:确定本编辑器的主题服务,并告知根节点是否要补作用域属性 */
|
|
10
|
+
export declare function EditorThemeScope({ service, children, }: {
|
|
11
|
+
/** 服务注册表里的 IThemeService;上下文里有服务时以上下文为准 */
|
|
12
|
+
service?: ThemeService;
|
|
13
|
+
children: (scope: {
|
|
14
|
+
themeKey: string;
|
|
15
|
+
mode: EditorThemeMode;
|
|
16
|
+
overridden: boolean;
|
|
17
|
+
}) => ReactNode;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export interface EditorTheme {
|
|
20
|
+
mode: EditorThemeMode;
|
|
21
|
+
isDark: boolean;
|
|
22
|
+
/** 读取 token 实际取值,给 mermaid / shiki / canvas 这类需要色值的渲染器用 */
|
|
23
|
+
token: (word: string) => string;
|
|
24
|
+
}
|
|
25
|
+
/** 编辑器内部读主题:明暗 + token 取值。未挂载 Editor 时回落 DOM 实现。 */
|
|
26
|
+
export declare function useEditorTheme(): EditorTheme;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Editor } from "slate";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface IBlockPanelListItem {
|
|
4
|
+
icon: React.ComponentType<{
|
|
5
|
+
className?: string;
|
|
6
|
+
}>;
|
|
7
|
+
title: string;
|
|
8
|
+
keywords: string[];
|
|
9
|
+
description: string;
|
|
10
|
+
onClick?: (editor: Editor) => void;
|
|
11
|
+
children?: IBlockPanelListItem[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParagraphElement } from "./element/paragraph";
|
|
2
|
+
import type { FormattedText } from "./text";
|
|
3
|
+
import type { ExtensionElementMap, ExtensionInlineElementMap } from "../../api";
|
|
4
|
+
export interface BuiltinElementMap {
|
|
5
|
+
paragraph: ParagraphElement;
|
|
6
|
+
}
|
|
7
|
+
export type CustomElement = (BuiltinElementMap & ExtensionElementMap)[keyof (BuiltinElementMap & ExtensionElementMap)];
|
|
8
|
+
export type InlineElement = ExtensionInlineElementMap[keyof ExtensionInlineElementMap];
|
|
9
|
+
export type CustomText = FormattedText;
|
|
10
|
+
export type BlockElement = Exclude<CustomElement, InlineElement>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseEditor, Editor as SlateEditor, Point } from "slate";
|
|
2
|
+
import { ReactEditor } from "slate-react";
|
|
3
|
+
import { HistoryEditor } from "slate-history";
|
|
4
|
+
import { CustomElement, CustomText } from "./custom-element";
|
|
5
|
+
import type { ServiceIdentifier } from "../services/tokens";
|
|
6
|
+
export type CustomField = {
|
|
7
|
+
type: string;
|
|
8
|
+
/** 非React插件代码获取必选服务,未注册时抛错 */
|
|
9
|
+
getService: <T>(id: ServiceIdentifier<T>) => T;
|
|
10
|
+
/** 非React插件代码获取可选服务,未注册时返回 undefined */
|
|
11
|
+
tryGetService: <T>(id: ServiceIdentifier<T>) => T | undefined;
|
|
12
|
+
/** 拖放落点交认领管线(withIngest)分发 */
|
|
13
|
+
handleDrop: (data: DataTransfer, point: Point) => Promise<void>;
|
|
14
|
+
/** 命令注册表的程序化入口(api/command.ts);热键、菜单、宿主统一经它执行 */
|
|
15
|
+
commands?: import("../api/command").EditorCommandsHandle;
|
|
16
|
+
};
|
|
17
|
+
export type CustomEditor = BaseEditor & ReactEditor & HistoryEditor & CustomField;
|
|
18
|
+
/**
|
|
19
|
+
* Editor component ref interface exposed via forwardRef
|
|
20
|
+
*/
|
|
21
|
+
export interface EditorRef {
|
|
22
|
+
/** Focus the editor and move cursor to the end */
|
|
23
|
+
focus: () => void;
|
|
24
|
+
/** Deselect the current selection */
|
|
25
|
+
deselect: () => void;
|
|
26
|
+
/** Get the underlying Slate editor instance */
|
|
27
|
+
getEditor: () => SlateEditor;
|
|
28
|
+
/** Check if the editor is currently focused */
|
|
29
|
+
isFocus: () => boolean;
|
|
30
|
+
}
|
|
31
|
+
declare module "slate" {
|
|
32
|
+
interface CustomTypes {
|
|
33
|
+
Editor: CustomEditor;
|
|
34
|
+
Element: CustomElement;
|
|
35
|
+
Text: CustomText;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { FormattedText } from "../../../markdown/src/model";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types/index";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TooltipProps } from "../../../ui/src/index";
|
|
2
|
+
/**
|
|
3
|
+
* 编辑器内的提示:外观同 @tau/ui,层级抬到悬浮工具条(z 9999)与编辑器浮层(~10100)之上,
|
|
4
|
+
* 否则工具条按钮的提示会被工具条自身盖住。
|
|
5
|
+
*/
|
|
6
|
+
export declare function Tooltip({ className, ...props }: TooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export type { TooltipProps };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Editor, Element as SlateElement, NodeEntry, Path } from "slate";
|
|
2
|
+
import type { ElementSpec } from "../api/extension";
|
|
3
|
+
export declare const registerBlockNavigationBoundaries: (editor: Editor, elements: readonly ElementSpec[]) => void;
|
|
4
|
+
export type BlockFocusPosition = "start" | "end";
|
|
5
|
+
export type BlockNavigationReason = "delete" | "arrow" | "enter";
|
|
6
|
+
export type BlockNavigationDirection = "backward" | "forward";
|
|
7
|
+
export interface BlockNavigationMeta {
|
|
8
|
+
reason: BlockNavigationReason;
|
|
9
|
+
direction: BlockNavigationDirection;
|
|
10
|
+
}
|
|
11
|
+
export interface BlockFocusContext {
|
|
12
|
+
editor: Editor;
|
|
13
|
+
element: SlateElement;
|
|
14
|
+
meta: BlockNavigationMeta;
|
|
15
|
+
}
|
|
16
|
+
export type BlockFocusHandler = (context: BlockFocusContext) => boolean;
|
|
17
|
+
export interface BlockNavigationHandler {
|
|
18
|
+
focusStart?: BlockFocusHandler;
|
|
19
|
+
focusEnd?: BlockFocusHandler;
|
|
20
|
+
}
|
|
21
|
+
export declare const registerBlockNavigation: (element: SlateElement, handler: BlockNavigationHandler) => void;
|
|
22
|
+
export declare const unregisterBlockNavigation: (element: SlateElement) => void;
|
|
23
|
+
export declare const hasBlockNavigation: (element: SlateElement) => boolean;
|
|
24
|
+
export declare const focusElementByNavigator: (editor: Editor, element: SlateElement, position: BlockFocusPosition, meta: BlockNavigationMeta) => boolean;
|
|
25
|
+
export declare const getSiblingBlockEntry: (editor: Editor, fromPath: Path, direction: BlockNavigationDirection) => NodeEntry<import("../../api").ParagraphElement> | undefined;
|
|
26
|
+
export declare const focusPreviousBlock: (editor: Editor, fromPath: Path, meta: BlockNavigationMeta) => boolean;
|
|
27
|
+
export declare const focusNextBlock: (editor: Editor, fromPath: Path, meta: BlockNavigationMeta) => boolean;
|
|
28
|
+
export declare const hasBlockNavigationBoundary: (editor: Editor, path: Path) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Editor, Node, Element, NodeMatch, NodeEntry, Path } from "slate";
|
|
2
|
+
import { ParagraphElement, BlockElement } from "../types";
|
|
3
|
+
export declare const getCurrentTextNode: (editor: Editor) => NodeEntry<Node>;
|
|
4
|
+
export declare const getClosestCurrentElement: (editor: Editor) => NodeEntry<BlockElement>;
|
|
5
|
+
export declare const getLeafParent: (editor: Editor) => NodeEntry<import("slate").Ancestor> | undefined;
|
|
6
|
+
export declare const getElementParent: (editor: Editor) => NodeEntry<import("slate").Ancestor> | undefined;
|
|
7
|
+
export declare const isAtParagraphStart: (editor: Editor) => boolean;
|
|
8
|
+
export declare const insertParagraphAndFocus: (editor: Editor, node: Element) => Path | null;
|
|
9
|
+
export declare const replaceNode: (editor: Editor, node: Node, match: NodeMatch<Node>, options?: {}) => Path | undefined;
|
|
10
|
+
export declare const isParagraphAndEmpty: (editor: Editor) => boolean;
|
|
11
|
+
export declare const isCollapsed: (editor: Editor) => boolean;
|
|
12
|
+
export declare const getCurrentEmptyNode: (editor: Editor) => NodeEntry<ParagraphElement> | undefined;
|
|
13
|
+
export declare const focusBlockElement: (editor: Editor, node: Node) => void;
|
|
14
|
+
export declare const removeCurrentEmptyNodeAndFocusPreviousNode: (editor: Editor) => void;
|
|
15
|
+
export declare const isFirstChild: (editor: Editor, node: Node) => boolean;
|
|
16
|
+
export declare const isLastChild: (editor: Editor, node: Node) => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CustomElement } from "../types";
|
|
2
|
+
import { Node, Editor } from "slate";
|
|
3
|
+
import { isNodeEmpty } from "../kit/elementEmpty";
|
|
4
|
+
export { isParagraphElement } from "../model/paragraph";
|
|
5
|
+
export declare const isLeafNode: (node: Node) => boolean;
|
|
6
|
+
export declare const isElementNode: (node: Node) => node is CustomElement;
|
|
7
|
+
export declare const getParentNodeByNode: (editor: Editor, node: Node) => import("slate").NodeEntry<import("slate").Ancestor>;
|
|
8
|
+
export declare const getPreviousSiblingNode: (editor: Editor, node: Node) => import("slate").NodeEntry | null;
|
|
9
|
+
export { isNodeEmpty };
|
|
10
|
+
export declare const isInlineElementEmpty: (node: import("slate").Descendant, editor?: Editor) => boolean;
|
|
11
|
+
export declare const isBlockElementEmpty: (node: import("slate").Descendant, editor?: Editor) => boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Editor, Path } from "slate";
|
|
2
|
+
import { BlockElement } from "../types";
|
|
3
|
+
interface InsertElementOptions {
|
|
4
|
+
select?: boolean;
|
|
5
|
+
reverse?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const focusInsertedPreviewElement: (editor: Editor, path?: Path, retry?: number) => void;
|
|
8
|
+
/** 当前选区能否 setOrInsertNode:需折叠且落在段落内(先问再弹输入框等场景用) */
|
|
9
|
+
export declare const canSetOrInsertNode: (editor: Editor) => boolean;
|
|
10
|
+
export declare const setOrInsertNode: (editor: Editor, node: BlockElement, options?: InsertElementOptions) => Path | undefined;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Editor, Node, Path } from "slate";
|
|
2
|
+
import type { EditorFeedback } from "../services/notifier";
|
|
3
|
+
/**
|
|
4
|
+
* 复制节点到剪贴板
|
|
5
|
+
* 支持两种格式:JSON 和纯文本
|
|
6
|
+
*/
|
|
7
|
+
export declare function copyNodeToClipboard(_editor: Editor, element: Node, message?: EditorFeedback, options?: {
|
|
8
|
+
allowPlainTextFallback?: boolean;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* 删除节点
|
|
13
|
+
* 如果是最后一个节点,则清空内容而不删除节点本身
|
|
14
|
+
*/
|
|
15
|
+
export declare function deleteNode(editor: Editor, path: Path): void;
|
|
16
|
+
/**
|
|
17
|
+
* 删除 void 块并补一个空段落承接焦点(图片 / 音视频 / 代码块等不可聚焦块的统一删除语义)
|
|
18
|
+
*/
|
|
19
|
+
export declare function deleteVoidBlock(editor: Editor, path: Path): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Editor, Node, Path } from "slate";
|
|
2
|
+
export declare const getPrevPath: (path: Path) => Path | undefined;
|
|
3
|
+
export declare const getNextPath: (path: Path) => Path;
|
|
4
|
+
export declare const getParentPath: (path: Path) => number[];
|
|
5
|
+
export declare const findPathSafely: (editor: Editor, node: Node) => Path | undefined;
|
|
6
|
+
export declare const getNodeAtPathSafely: (editor: Editor, path: Path) => Node | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Point {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 以某点为锚缩放时的新平移量:锚点下的内容保持不动。
|
|
7
|
+
* 坐标都相对舞台中心,内容以 `translate(pan) scale(zoom)` 摆放、变换原点在中心。
|
|
8
|
+
*/
|
|
9
|
+
export declare const panAroundAnchor: (pan: Point, zoom: number, nextZoom: number, anchor: Point) => Point;
|
|
10
|
+
/** 指针事件相对元素中心的坐标 */
|
|
11
|
+
export declare const pointFromCenter: (element: HTMLElement, event: {
|
|
12
|
+
clientX: number;
|
|
13
|
+
clientY: number;
|
|
14
|
+
}) => Point;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Descendant, Element } from "slate";
|
|
2
|
+
import type { MarkdownSerializer } from "./markdownSerializerRegistry";
|
|
3
|
+
/** 业务 directive 解析器:键为 directive 名,返回 null 视为丢弃该节点 */
|
|
4
|
+
export type CustomDirectiveHandler = (attributes: Record<string, string | undefined>) => Descendant | null;
|
|
5
|
+
/** mdast 节点(remark 解析产物)的最小形状,importNode 认领时只允许读这些字段 */
|
|
6
|
+
export interface MarkdownImportNode {
|
|
7
|
+
type: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
alt?: string;
|
|
11
|
+
lang?: string;
|
|
12
|
+
meta?: string;
|
|
13
|
+
depth?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
14
|
+
ordered?: boolean;
|
|
15
|
+
identifier?: string;
|
|
16
|
+
htmlType?: "block" | "inline";
|
|
17
|
+
attributes?: Record<string, string | undefined>;
|
|
18
|
+
children?: MarkdownImportNode[];
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/** importNode 的认领上下文:块级 / 行内判断与脚注取值用 */
|
|
22
|
+
export interface MarkdownImportContext {
|
|
23
|
+
parent: MarkdownImportNode | null;
|
|
24
|
+
siblings: readonly MarkdownImportNode[];
|
|
25
|
+
/** 脚注定义正文(footnoteReference 认领方用) */
|
|
26
|
+
getFootnote: (identifier: string) => string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 一个元素类型的 Markdown 编解码(01 §8.2)。框架不自带任何元素类型:
|
|
30
|
+
* 各扩展在自己的 markdown.ts(纯函数文件)里声明 codec,宿主把 codec 列表
|
|
31
|
+
* 合成一次交给 createMarkdownProcessor,kit 与 Electron 主进程共用。
|
|
32
|
+
*/
|
|
33
|
+
export interface MarkdownCodec {
|
|
34
|
+
/** 元素 type */
|
|
35
|
+
type: string;
|
|
36
|
+
/** 导入:按 directive 名解析(container / leaf / text 三种都查),优先于内置分支 */
|
|
37
|
+
directives?: Record<string, CustomDirectiveHandler>;
|
|
38
|
+
/**
|
|
39
|
+
* 导入:声明式围栏认领——```lang 的代码围栏映射为 { type, [property]: 源码 }。
|
|
40
|
+
* 语言小写匹配;同一语言被两个 codec 认领时建处理器直接报错
|
|
41
|
+
*/
|
|
42
|
+
fence?: {
|
|
43
|
+
language: string | readonly string[];
|
|
44
|
+
/** 源码落进元素的字段名,默认 "content"(mermaid 用 "chart") */
|
|
45
|
+
property?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 导入:通用 mdast 认领。返回元素(children 留空,由框架回填)或 null(不认领)。
|
|
49
|
+
* 按声明顺序遍历、首个认领生效——宽认领(如 code-block 认领所有 code 节点)
|
|
50
|
+
* 必须排在窄认领之后,由聚合列表的顺序保证
|
|
51
|
+
*/
|
|
52
|
+
importNode?: (node: MarkdownImportNode, context: MarkdownImportContext) => Descendant | null;
|
|
53
|
+
/** 导出 */
|
|
54
|
+
serializer?: Omit<MarkdownSerializer, "type">;
|
|
55
|
+
/** void 元素:位置映射只记元素级范围(导入、导出两个方向都生效) */
|
|
56
|
+
isVoid?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 行内包裹:导入时该 text directive 的子文本按 directive 整体范围记前后缀(位置映射用),
|
|
59
|
+
* 值为 directive 名
|
|
60
|
+
*/
|
|
61
|
+
inlineWrapperDirective?: string;
|
|
62
|
+
/** 配对 HTML 标签的行内认领;框架匹配同名嵌套标签并回填 children,领域负责创建节点。 */
|
|
63
|
+
inlineHtmlWrapper?: {
|
|
64
|
+
tag: string;
|
|
65
|
+
create: (opening: MarkdownImportNode) => Element;
|
|
66
|
+
};
|
|
67
|
+
/** 导入后规范化:返回替换本元素的序列(空数组 = 删除)或 null(保持原样) */
|
|
68
|
+
normalize?: (element: any, context: {
|
|
69
|
+
parent: Descendant | null;
|
|
70
|
+
previousSibling: Descendant | null;
|
|
71
|
+
nextSibling: Descendant | null;
|
|
72
|
+
/** 把块级子元素降级为行内形态(image→inline-image、html-block→html-inline),无声明则原样返回 */
|
|
73
|
+
demote: (child: Descendant) => Descendant;
|
|
74
|
+
}) => Descendant[] | null;
|
|
75
|
+
/** 按目标类型贡献规范化,先于该类型自身 normalize;按 codec 顺序首个非 null 替换生效。 */
|
|
76
|
+
normalizeFor?: Readonly<Record<string, NonNullable<MarkdownCodec["normalize"]>>>;
|
|
77
|
+
/** 段落内行内形态的构造(导入规范化时框架经 ctx.demote 调用) */
|
|
78
|
+
inlineForm?: (element: any) => Descendant;
|
|
79
|
+
/**
|
|
80
|
+
* 导入:从 code 节点(围栏或缩进代码块)认领的 void 元素,把源码区间记为
|
|
81
|
+
* 该属性的属性级位置映射(如 code-block 的 "code");缺省只有元素级映射
|
|
82
|
+
*/
|
|
83
|
+
fenceSourceProperty?: string;
|
|
84
|
+
/** 导出:子块级元素之间的接续符,默认 "\n\n";列表与表格声明 "\n" */
|
|
85
|
+
childSeparator?: "\n" | "\n\n";
|
|
86
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createMarkdownProcessor, type MarkdownProcessor, type MarkdownProcessorOptions, } from "./processor";
|
|
2
|
+
export type { MarkdownTextCodec, MarkdownTextRule, LeafSerializationResult } from "./textCodec";
|
|
3
|
+
export type { MarkdownCodec, CustomDirectiveHandler, MarkdownImportNode, MarkdownImportContext, } from "./codec";
|
|
4
|
+
export { isMarkdownLikeText, type ImportFromMarkdownOptions, type SlateWithPositions, } from "./markdown";
|
|
5
|
+
export { addExportFootnote, type MarkdownWithPositions } from "./markdown-helper";
|
|
6
|
+
export { MarkdownSerializerRegistry, type MarkdownSerializer, type SerializerOutput, } from "./markdownSerializerRegistry";
|
|
7
|
+
export { PositionMapper, type MarkdownPosition, type SlatePosition, type TextMapping, type ElementMapping, type PositionMapping, } from "./positionMapper";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Descendant } from "slate";
|
|
2
|
+
import type { CustomElement } from "./types";
|
|
3
|
+
import type { MarkdownSerializerRegistry } from "./markdownSerializerRegistry";
|
|
4
|
+
import { PositionMapper } from "./positionMapper";
|
|
5
|
+
import type { MarkdownTextRegistry } from "./textCodec";
|
|
6
|
+
/** 处理器级导出配置:注册表 + void 类型表 + 子元素接续表(内置 + 宿主 codec) */
|
|
7
|
+
export interface ExportConfig {
|
|
8
|
+
textRegistry: MarkdownTextRegistry;
|
|
9
|
+
registry: MarkdownSerializerRegistry;
|
|
10
|
+
voidTypes: ReadonlySet<string>;
|
|
11
|
+
/** 元素类型的子块级接续符(列表 / 表格为 "\n",缺省 "\n\n") */
|
|
12
|
+
childSeparators: ReadonlyMap<string, "\n" | "\n\n">;
|
|
13
|
+
}
|
|
14
|
+
/** codec 的序列化器登记脚注(如 annotation 的 [^n]),由导出入口统一追加到文末 */
|
|
15
|
+
export declare const addExportFootnote: (content: string) => number;
|
|
16
|
+
export declare const getMarkdownUsing: (config: ExportConfig, value: Descendant[]) => string;
|
|
17
|
+
export declare const elementToMarkdownUsing: (config: ExportConfig, element: CustomElement, parentElement: CustomElement | null) => string;
|
|
18
|
+
/**
|
|
19
|
+
* 带位置信息的 Markdown 输出
|
|
20
|
+
*/
|
|
21
|
+
export interface MarkdownWithPositions {
|
|
22
|
+
markdown: string;
|
|
23
|
+
positionMap: PositionMapper;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 带位置跟踪的序列化函数(重新设计)
|
|
27
|
+
*/
|
|
28
|
+
export declare const getMarkdownWithPositionsUsing: (config: ExportConfig, value: Descendant[]) => MarkdownWithPositions;
|