@xiongtao.xt/tau-plugins 0.32.0 → 0.34.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/client/{chunk-SVY5LBAT.js → chunk-FZTR4KOY.js} +10 -0
  3. package/docs/README.md +18 -17
  4. package/docs/editor.md +183 -4
  5. package/docs/excerpts.md +1 -1
  6. package/docs/plugin-basics.md +3 -0
  7. package/docs/storage-and-network.md +1 -1
  8. package/docs/ui.md +236 -7
  9. package/docs/user-data.md +388 -72
  10. package/package.js +1 -1
  11. package/package.json +1 -1
  12. package/publish-artifacts.js +66 -2
  13. package/types/packages/db-schema/content-resources.d.ts +76 -0
  14. package/types/packages/editor/contracts.d.ts +1 -1
  15. package/types/packages/editor/source-contracts.d.ts +41 -1
  16. package/types/packages/editor/src/core/api/extension.d.ts +18 -0
  17. package/types/packages/editor/src/core/api/index.d.ts +6 -1
  18. package/types/packages/editor/src/core/api/inputRules.d.ts +37 -0
  19. package/types/packages/editor/src/core/api/resources.d.ts +6 -0
  20. package/types/packages/editor/src/core/components/ElementFrame/index.d.ts +25 -0
  21. package/types/packages/editor/src/core/utils/blockKeyTarget.d.ts +9 -0
  22. package/types/packages/plugins/src/actions.d.ts +61 -0
  23. package/types/packages/plugins/src/app.d.ts +106 -8
  24. package/types/packages/plugins/src/components.d.ts +22 -0
  25. package/types/packages/plugins/src/content-input.d.ts +34 -0
  26. package/types/packages/plugins/src/contract.d.ts +18 -0
  27. package/types/packages/plugins/src/data.d.ts +179 -11
  28. package/types/packages/plugins/src/editor-fields.d.ts +10 -0
  29. package/types/packages/plugins/src/editor.d.ts +3 -1
  30. package/types/packages/plugins/src/element.d.ts +11 -0
  31. package/types/packages/plugins/src/entities.d.ts +28 -3
  32. package/types/packages/plugins/src/events.d.ts +9 -3
  33. package/types/packages/plugins/src/excerpts.d.ts +1 -1
  34. package/types/packages/plugins/src/home.d.ts +20 -0
  35. package/types/packages/plugins/src/index.d.ts +21 -5
  36. package/types/packages/plugins/src/links.d.ts +39 -0
  37. package/types/packages/plugins/src/media.d.ts +69 -0
  38. package/types/packages/plugins/src/pages.d.ts +12 -0
  39. package/types/packages/plugins/src/permissions.d.ts +1 -1
  40. package/types/packages/plugins/src/query.d.ts +64 -0
  41. package/types/packages/plugins/src/records.d.ts +50 -0
  42. package/types/packages/plugins/src/sidebar.d.ts +63 -1
  43. package/types/packages/plugins/src/transaction.d.ts +40 -0
  44. package/types/packages/plugins/src/views.d.ts +26 -0
  45. package/types/packages/ui/src/index.d.ts +1 -0
  46. package/types/packages/ui/src/primitives/Sortable.d.ts +32 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,64 @@
1
1
  import {
2
2
  PLUGIN_SHARED_MODULES,
3
3
  validatePluginManifest
4
- } from "./client/chunk-SVY5LBAT.js";
4
+ } from "./client/chunk-FZTR4KOY.js";
5
+
6
+ // packages/db-schema/content-resources.ts
7
+ var CONTENT_RESOURCE_KINDS = [
8
+ "image",
9
+ "video",
10
+ "audio",
11
+ "file"
12
+ ];
13
+ var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
14
+ var SEGMENT = /^[A-Za-z_$][\w$-]*(\[\])?$/;
15
+ var FIELD = /^[A-Za-z_$][\w$-]*$/;
16
+ var MAX_SPECS = 16;
17
+ var MAX_PATH_LENGTH = 128;
18
+ var isField = (value) => typeof value === "string" && FIELD.test(value) && !UNSAFE_SEGMENTS.has(value);
19
+ function isValidPath(path) {
20
+ if (typeof path !== "string" || !path || path.length > MAX_PATH_LENGTH) return false;
21
+ const parts = path.split(".");
22
+ return parts.every(
23
+ (part, index) => SEGMENT.test(part) && !UNSAFE_SEGMENTS.has(part.replace(/\[\]$/, "")) && (index < parts.length - 1 || !part.endsWith("[]"))
24
+ );
25
+ }
26
+ function isContentResourceSpec(value) {
27
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
28
+ const spec = value;
29
+ return isValidPath(spec.path) && CONTENT_RESOURCE_KINDS.includes(spec.kind) && ["preview", "alt", "caption"].every((key) => spec[key] === void 0 || isField(spec[key])) && Object.keys(spec).every((key) => ["path", "kind", "preview", "alt", "caption"].includes(key));
30
+ }
31
+ function assertContentResourceSpecs(value) {
32
+ if (!Array.isArray(value) || value.length > MAX_SPECS || !value.every(isContentResourceSpec))
33
+ throw new Error("\u8D44\u6E90\u58F0\u660E\u65E0\u6548");
34
+ }
35
+
36
+ // packages/plugins/src/editor-fields.ts
37
+ var OPEN_EXTENSION_FIELDS = [
38
+ "id",
39
+ "apiVersion",
40
+ "elements",
41
+ "commands",
42
+ "hotkeys",
43
+ "menu",
44
+ "blockPanel",
45
+ "behaviorsFor"
46
+ ];
47
+ var PLUGIN_EXTENSION_FIELDS = /* @__PURE__ */ new Set([
48
+ ...OPEN_EXTENSION_FIELDS,
49
+ "styleSources",
50
+ "htmlSerializers"
51
+ ]);
52
+ function assertPluginEditorExtension(extension) {
53
+ if (typeof extension !== "object" || extension === null) throw new Error("\u7F16\u8F91\u5668\u6269\u5C55\u5FC5\u987B\u662F\u5BF9\u8C61");
54
+ const prototype = Object.getPrototypeOf(extension);
55
+ if (prototype !== Object.prototype && prototype !== null)
56
+ throw new Error("\u7F16\u8F91\u5668\u6269\u5C55\u5FC5\u987B\u662F\u666E\u901A\u5BF9\u8C61");
57
+ if ("plugins" in extension) throw new Error("\u7F16\u8F91\u5668\u63D2\u4EF6\u4E0D\u652F\u6301\u539F\u59CB Slate \u5305\u88C5\u5668");
58
+ const closed = Reflect.ownKeys(extension).filter((key) => !PLUGIN_EXTENSION_FIELDS.has(key));
59
+ if (closed.length)
60
+ throw new Error(`\u7F16\u8F91\u5668\u6269\u5C55\u542B\u672A\u5F00\u653E\u7684\u5B57\u6BB5\uFF1A${closed.map((key) => String(key)).join("\u3001")}`);
61
+ }
5
62
 
6
63
  // packages/plugins/src/rendering.ts
7
64
  var PLUGIN_RENDER_VERSION = 1;
@@ -45,10 +102,17 @@ function validatePluginDefinition(manifest, definition) {
45
102
  function getPluginNodeTypes(definition) {
46
103
  const types = [];
47
104
  for (const extension of definition.editorExtensions ?? []) {
48
- if ("plugins" in extension) throw new Error("\u7F16\u8F91\u5668\u63D2\u4EF6\u4E0D\u652F\u6301\u539F\u59CB Slate \u5305\u88C5\u5668");
105
+ assertPluginEditorExtension(extension);
49
106
  for (const element of extension.elements ?? []) {
50
107
  if (!element.type || types.includes(element.type))
51
108
  throw new Error(`\u63D2\u4EF6\u8282\u70B9\u7C7B\u578B\u4E3A\u7A7A\u6216\u91CD\u590D\uFF1A${element.type}`);
109
+ if (element.resources !== void 0) {
110
+ try {
111
+ assertContentResourceSpecs(element.resources);
112
+ } catch {
113
+ throw new Error(`\u63D2\u4EF6\u8282\u70B9\u8D44\u6E90\u58F0\u660E\u65E0\u6548\uFF1A${element.type}`);
114
+ }
115
+ }
52
116
  types.push(element.type);
53
117
  }
54
118
  }
@@ -0,0 +1,76 @@
1
+ export type ContentResourceKind = "image" | "video" | "audio" | "file";
2
+ export declare const CONTENT_RESOURCE_KINDS: readonly ContentResourceKind[];
3
+ export interface ContentResourceSpec {
4
+ /** 字段路径:`url`、`images[].url`;`[]` 表示数组的每一项 */
5
+ path: string;
6
+ kind: ContentResourceKind;
7
+ /** 同一资源的显示版本(如裁剪结果),与 path 末段同层的字段名,同样参与上传与改写 */
8
+ preview?: string;
9
+ /** 替代文字字段,与 path 末段同层 */
10
+ alt?: string;
11
+ /** 说明文字字段,与 path 末段同层 */
12
+ caption?: string;
13
+ }
14
+ /** 节点类型 → 资源字段 */
15
+ export type ContentResourceDeclarations = Readonly<Record<string, readonly ContentResourceSpec[]>>;
16
+ /** 宿主内置节点的资源字段 */
17
+ export declare const BUILTIN_CONTENT_RESOURCES: {
18
+ readonly image: readonly [{
19
+ readonly path: "url";
20
+ readonly kind: "image";
21
+ readonly preview: "previewUrl";
22
+ readonly alt: "alt";
23
+ readonly caption: "description";
24
+ }];
25
+ readonly "inline-image": readonly [{
26
+ readonly path: "url";
27
+ readonly kind: "image";
28
+ readonly alt: "alt";
29
+ }];
30
+ readonly audio: readonly [{
31
+ readonly path: "src";
32
+ readonly kind: "audio";
33
+ }];
34
+ readonly video: readonly [{
35
+ readonly path: "src";
36
+ readonly kind: "video";
37
+ }];
38
+ readonly "file-attachment": readonly [{
39
+ readonly path: "filePath";
40
+ readonly kind: "file";
41
+ }, {
42
+ readonly path: "localFilePath";
43
+ readonly kind: "file";
44
+ }];
45
+ };
46
+ export declare function isContentResourceSpec(value: unknown): value is ContentResourceSpec;
47
+ /** 校验来自插件或其他设备的声明;形状不对时抛错 */
48
+ export declare function assertContentResourceSpecs(value: unknown): asserts value is readonly ContentResourceSpec[];
49
+ /** 合并多份声明,后者覆盖同类型的前者 */
50
+ export declare function mergeContentResources(...sources: readonly ContentResourceDeclarations[]): ContentResourceDeclarations;
51
+ /** 资源所在的对象(字段的父对象)及字段名 */
52
+ export interface ContentResourceSlot {
53
+ spec: ContentResourceSpec;
54
+ owner: Record<string, unknown>;
55
+ field: string;
56
+ }
57
+ /** 按声明列出一个节点里的资源位置(不深入子节点) */
58
+ export declare function contentResourceSlots(node: unknown, specs: readonly ContentResourceSpec[] | undefined): ContentResourceSlot[];
59
+ /** 资源位置上实际的地址:主地址与显示版本,空串跳过 */
60
+ export declare function contentResourceValues(slot: ContentResourceSlot): string[];
61
+ export interface ContentResourceEntry {
62
+ node: Record<string, unknown>;
63
+ slot: ContentResourceSlot;
64
+ }
65
+ /** 按文档顺序遍历节点树里所有声明了资源的位置 */
66
+ export declare function forEachContentResource(nodes: readonly unknown[], declarations: ContentResourceDeclarations, visit: (entry: ContentResourceEntry) => void): void;
67
+ /** 收集节点树里的资源地址(去重,保持首次出现的顺序) */
68
+ export declare function collectContentResources(nodes: readonly unknown[], declarations: ContentResourceDeclarations): {
69
+ url: string;
70
+ kind: ContentResourceKind;
71
+ }[];
72
+ export type ContentResourceMapper = (url: string, kind: ContentResourceKind) => string | undefined;
73
+ /** 不可变地改写一个节点里声明的资源(不深入子节点);返回 undefined 表示保留原值 */
74
+ export declare function mapNodeResources<T>(node: T, specs: readonly ContentResourceSpec[] | undefined, mapper: ContentResourceMapper): T;
75
+ /** 不可变地改写整棵节点树里声明的资源 */
76
+ export declare function mapContentResources<T>(nodes: readonly T[], declarations: ContentResourceDeclarations, mapper: ContentResourceMapper): T[];
@@ -1,3 +1,3 @@
1
1
  /** 无 React/DOM 运行时代码的声明入口,供应用 SDK 适配现有扩展协议。 */
2
2
  export { defineExtension, defineElement } from "./src/core/api/extension";
3
- export type { EditorExtension, ElementSpec, ElementRenderProps } from "./src/core/api/extension";
3
+ export type { EditorExtension, ElementSpec, ElementRenderProps, ElementFrame, } from "./src/core/api/extension";
@@ -1,4 +1,4 @@
1
- import type { ReactNode, ReactElement } from "react";
1
+ import type { MouseEvent, ReactNode, ReactElement } from "react";
2
2
  import type { LucideIcon } from "lucide-react";
3
3
  import type { Editor, Element, Path } from "slate";
4
4
  import type { ElementBehaviors, ParagraphElement, BlockElement } from "./api";
@@ -35,6 +35,46 @@ export interface SourceEditorRuntime {
35
35
  insertSourceBlock(editor: Editor, element: BlockElement, line?: number): Path | undefined;
36
36
  sourceBlockParagraphBehavior(type: string): ElementBehaviors<ParagraphElement>;
37
37
  }
38
+ export interface ElementAccess {
39
+ readOnly: boolean;
40
+ /** 外框里的块是否被点选;未声明外框时恒为 false */
41
+ selected: boolean;
42
+ /** 字段合并进节点,进入撤销记录并同步给协作者;只读、节点已被替换或卸载后不写入 */
43
+ update(properties: Record<string, unknown>): void;
44
+ remove(): void;
45
+ /** 选中外框里的块 */
46
+ select(): void;
47
+ /** 在指定位置打开块菜单;需要外框 */
48
+ openMenu(position: {
49
+ x: number;
50
+ y: number;
51
+ }): void;
52
+ }
53
+ export interface BlockToolbarProps {
54
+ /** 无障碍名称(如「画廊属性」) */
55
+ label: string;
56
+ className?: string;
57
+ children: ReactNode;
58
+ }
59
+ export interface BlockToolbarButtonProps {
60
+ /** 按钮名称:图标按钮的提示与无障碍名称 */
61
+ title: string;
62
+ shortcut?: string;
63
+ /** 显示在图标旁的文字(主操作用) */
64
+ label?: string;
65
+ icon?: ReactNode;
66
+ active?: boolean;
67
+ mono?: boolean;
68
+ onClick(event: MouseEvent<HTMLButtonElement>): void;
69
+ }
70
+ export interface ElementRuntime {
71
+ useElement(element: Element): ElementAccess;
72
+ /** 打开文档图片查看器,定位到该元素的第 index 个图片资源(按资源声明计) */
73
+ useMediaViewer(element: Element): (index?: number) => void;
74
+ BlockToolbar(props: BlockToolbarProps): ReactElement;
75
+ BlockToolbarButton(props: BlockToolbarButtonProps): ReactElement;
76
+ BlockToolbarGap(): ReactElement;
77
+ }
38
78
  export interface InlineSourceRuntime {
39
79
  useInlineSource(element: Element): {
40
80
  readOnly: boolean;
@@ -9,6 +9,8 @@ import type { ElementDrag } from "./drag";
9
9
  import type { ElementIngestSpec } from "./ingest";
10
10
  import type { ElementCopy } from "./copy";
11
11
  import type { DecorationSpec, MarkSpec } from "./marks";
12
+ import type { InputRule } from "./inputRules";
13
+ import type { ContentResourceSpec } from "../../../../db-schema/content-resources";
12
14
  /**
13
15
  * 扩展 API v2(01 §5.1):声明式描述「这个扩展贡献了什么」,内核负责装配、隔离与分发。
14
16
  * 所有扩展都是 defineExtension 的产物(旧 IExtension 适配层已删除,ER-019)。
@@ -35,6 +37,16 @@ export interface ElementEmptyContext {
35
37
  /** 使用当前编辑器已安装的声明判断子节点;未知或失败时保留。 */
36
38
  isEmpty(node: Descendant): boolean;
37
39
  }
40
+ /**
41
+ * void 块的公共外框:点选描边、右键菜单、选中时 Delete / Backspace 删除与 Escape 取消、末尾「添加段落」。
42
+ * 声明后 render 只渲染内容(收到的 attributes 为空对象、children 为 null)。
43
+ */
44
+ export interface ElementFrame {
45
+ /** 末尾的「添加段落」,默认显示 */
46
+ appendParagraph?: boolean;
47
+ /** 选中时的按键 → 命令 id(如 `{ Enter: "yourname.gallery.edit" }`),命令收到该元素 */
48
+ keys?: Readonly<Record<string, string>>;
49
+ }
38
50
  export interface ElementSpec<E extends Element = Element> {
39
51
  /** 元素 type;内置类型沿用现有名字,兼容已有文档 */
40
52
  type: string;
@@ -53,6 +65,10 @@ export interface ElementSpec<E extends Element = Element> {
53
65
  drag?: ElementDrag;
54
66
  /** 内容注入声明(01 §5.4):drop 与 paste 共用的认领规则;块组件不再改写 insertData */
55
67
  ingest?: ElementIngestSpec;
68
+ /** 节点里的资源字段:导出打包、协作上传、灯箱等只按它找图片、视频、音频与文件 */
69
+ resources?: readonly ContentResourceSpec[];
70
+ /** void 块的公共外框;只适用于 `kind: "block"` 且 `isVoid` 的元素 */
71
+ frame?: boolean | ElementFrame;
56
72
  }
57
73
  export interface ExtensionLayerProps {
58
74
  /** 根 UI 在 Editable 外,不能通过 Slate 的 useReadOnly 读取此状态。 */
@@ -64,6 +80,8 @@ export interface EditorExtension {
64
80
  readonly apiVersion: typeof EXTENSION_API_VERSION;
65
81
  readonly elements?: readonly ElementSpec[];
66
82
  readonly marks?: readonly MarkSpec[];
83
+ /** 行内输入规则:输入成对定界符时转成标记或行内元素,如 `**粗体**`、`$公式$` */
84
+ readonly inputRules?: readonly InputRule[];
67
85
  /** 暂态装饰(不进文档);外观由本扩展 marks 里 keys 对应的声明渲染 */
68
86
  readonly decorations?: readonly DecorationSpec[];
69
87
  /** 在编辑器的 Slate/Kit 上下文挂载辅助 UI,组件自行接宿主浮层仲裁。 */
@@ -4,16 +4,21 @@
4
4
  * 只放写扩展需要的东西:声明、服务、主题、少量工具。编辑器组件、kit 工厂等宿主用的留在包根入口。
5
5
  * 未标注过渡用途的导出按稳定 API 维护;过渡导出只供现有内部消费者迁移使用。
6
6
  */
7
- export { EXTENSION_API_VERSION, defineExtension, defineElement, type EditorExtension, type ExtensionDefinition, type ElementSpec, type ElementEmptyContext, type ElementBehaviors, type ElementRenderProps, type ExtensionLayerProps, } from "./extension";
7
+ export { EXTENSION_API_VERSION, defineExtension, defineElement, type EditorExtension, type ExtensionDefinition, type ElementSpec, type ElementFrame, type ElementEmptyContext, type ElementBehaviors, type ElementRenderProps, type ExtensionLayerProps, } from "./extension";
8
8
  export type { AnyExtension } from "./legacy";
9
9
  export type { CopyDecision, CopyContext, ElementCopy } from "./copy";
10
10
  export type { MarkSpec, MarkRenderProps, DecorationSpec } from "./marks";
11
+ export type { InputRule, MarkInputRule, InlineInputRule } from "./inputRules";
11
12
  export { useToolbarState } from "./toolbar";
12
13
  export { default as ToolbarSubmenu } from "../components/HoveringToolbar/FloatingSubmenu";
13
14
  export { Tooltip as EditorTooltip } from "../ui/Tooltip";
14
15
  export { CaretRight as EditorCaretRight } from "../ui/CaretRight";
15
16
  export { getParagraphShortcutEntry } from "../utils/paragraphShortcut";
16
17
  export type { IngestContext, ElementIngestSpec } from "./ingest";
18
+ export { getElementResources } from "./resources";
19
+ export { ELEMENT_SELECTED_OUTLINE_CLASS, useElementFrame, type ElementFrameState, } from "../components/ElementFrame/index";
20
+ export { isOverlayTarget, isTextTarget, shouldIgnoreBlockKey } from "../utils/blockKeyTarget";
21
+ export type { ContentResourceSpec, ContentResourceKind, ContentResourceDeclarations, } from "../../../../db-schema/content-resources";
17
22
  export { CommandRegistry, createCommandDispatcher, type EditorCommand, type EditorCommandContext, type EditorHotkey, type RegisteredCommand, type CommandDispatcher, type CommandGuard, } from "./command";
18
23
  export { type EditorMenuEntry, type EditorMenuContext, type EditorMenuContribution, type MenuValue, } from "./menu";
19
24
  export { createServiceId, IThemeService, IExtensionErrorReporter, IEditorNotifier, type ServiceIdentifier, } from "../services/tokens";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 行内输入规则:输入成对定界符的收尾字符时,把两段定界符之间的文字转成标记(`**粗体**`)
3
+ * 或行内元素(`$公式$`)。只在键入(含输入法上屏)时触发,粘贴不触发;转换单独成一个撤销步,
4
+ * 撤销回到原始符号。
5
+ */
6
+ interface InputRuleBase {
7
+ /** 全局唯一,冲突在 kit 创建时报错 */
8
+ id: string;
9
+ /** 由同一字符重复组成的定界符,如 `**`、`~~`;末字符即触发字符 */
10
+ delimiter: string;
11
+ /** 定界符外侧不能紧邻字母或数字(`_` 写法,避免把 snake_case 当成斜体) */
12
+ wordBoundary?: boolean;
13
+ /** 光标所在文本已带这些标记时不触发(如行内代码里的原样文本) */
14
+ excludeMarks?: readonly string[];
15
+ }
16
+ export interface MarkInputRule extends InputRuleBase {
17
+ /** 匹配后给定界符之间的文字加的标记字段,必须由已安装扩展的 marks 声明 */
18
+ marks: Readonly<Record<string, unknown>>;
19
+ inline?: never;
20
+ }
21
+ export interface InlineInputRule extends InputRuleBase {
22
+ /**
23
+ * 匹配后把定界符连同其间文字替换成行内元素;`type` 必须是已安装扩展声明的 inline 元素,
24
+ * `create` 由定界符之间的文字给出元素的其余字段(children 由内核补空文本)。
25
+ */
26
+ inline: {
27
+ type: string;
28
+ create(text: string): Readonly<Record<string, unknown>>;
29
+ };
30
+ marks?: never;
31
+ }
32
+ export type InputRule = MarkInputRule | InlineInputRule;
33
+ export interface RegisteredInputRule {
34
+ readonly owner: string;
35
+ readonly rule: InputRule;
36
+ }
37
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Editor } from "slate";
2
+ import type { ContentResourceDeclarations } from "../../../../db-schema/content-resources";
3
+ /** 内核在创建编辑器时绑定当前装配的资源声明 */
4
+ export declare function bindElementResources(editor: Editor, resources: ContentResourceDeclarations): void;
5
+ /** 当前编辑器已安装的节点资源声明(节点类型 → 资源字段) */
6
+ export declare function getElementResources(editor: Editor): ContentResourceDeclarations;
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from "react";
2
+ import { type RenderElementProps } from "slate-react";
3
+ import type { ElementFrame as ElementFrameOptions } from "../../api/extension";
4
+ /** 选中描边:外扩 3px,随内容圆角 */
5
+ export declare const ELEMENT_SELECTED_OUTLINE_CLASS = "outline-solid outline-2 outline-offset-[3px] outline-[var(--ed-accent)]";
6
+ export interface ElementFrameState {
7
+ selected: boolean;
8
+ select(): void;
9
+ deselect(): void;
10
+ /** 在指定位置打开块菜单(与右键、块手柄同一份条目) */
11
+ openMenu(position: {
12
+ x: number;
13
+ y: number;
14
+ }): void;
15
+ }
16
+ /** 外框里的块读取选中与菜单状态;不在外框里时为 null */
17
+ export declare const useElementFrame: () => ElementFrameState | null;
18
+ /**
19
+ * void 块的公共外框:点选与选中描边、右键菜单、选中时的删除与声明的按键、末尾「添加段落」。
20
+ * 块的 render 只渲染内容,attributes 与 children 由外框处理。
21
+ */
22
+ export declare function ElementFrame({ attributes, element, children, options, content, }: RenderElementProps & {
23
+ options: ElementFrameOptions;
24
+ content: ReactNode;
25
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ /** 按键目标是文本输入(input / textarea / 可编辑区):块级快捷键不拦截 */
2
+ export declare const isTextTarget: (target: EventTarget | null) => boolean;
3
+ /** 按键目标在浮层里(灯箱、裁剪编辑器、对话框):交给浮层自己处理 */
4
+ export declare const isOverlayTarget: (target: EventTarget | null) => boolean;
5
+ /**
6
+ * 选中媒体块时的块级快捷键是否应忽略这次按键:输入法组合、浮层内、文本输入(如说明框)都不处理。
7
+ * 点选块后焦点通常留在外层编辑器根上——它包含这个块,不算文本输入,快捷键照常生效。
8
+ */
9
+ export declare function shouldIgnoreBlockKey(event: KeyboardEvent, block: HTMLElement | null): boolean;
@@ -0,0 +1,61 @@
1
+ import type { Disposable } from "./contract";
2
+ import type { PluginIcon } from "./icons";
3
+ /**
4
+ * 对象动作可以挂在哪类对象上:document 为项目文档;material 为划线、PDF 标注与剪藏;
5
+ * chat-message 为对话里的一条消息;text 为用户在命令面板里输入的文字。
6
+ */
7
+ export type PluginActionTargetKind = "card" | "article" | "document" | "material" | "chat-message" | "text";
8
+ type PluginActionEntityKind = "card" | "article" | "document" | "material";
9
+ /** 卡片、文章、项目文档、材料:与 PluginEntityRef 相同 */
10
+ export type PluginActionEntityTarget = {
11
+ [K in PluginActionEntityKind]: {
12
+ kind: K;
13
+ id: string;
14
+ };
15
+ }[PluginActionEntityKind];
16
+ /**
17
+ * 对话里的一条消息。text 是消息正文(用户亲手交给插件,不需要权限);
18
+ * session 之后与 pick 选中的一样,可以显示与关联;messageIds 是这条消息在会话里的记录 ID,
19
+ * 一条 AI 回答可能由多条记录组成。
20
+ */
21
+ export interface PluginChatMessageTarget {
22
+ kind: "chat-message";
23
+ session: {
24
+ kind: "chat-session";
25
+ id: string;
26
+ };
27
+ messageIds: readonly string[];
28
+ role: "user" | "assistant";
29
+ text: string;
30
+ }
31
+ /** 用户在命令面板里输入的文字(亲手交给插件,不需要权限) */
32
+ export interface PluginTextTarget {
33
+ kind: "text";
34
+ text: string;
35
+ }
36
+ export type PluginActionTarget = PluginActionEntityTarget | PluginChatMessageTarget | PluginTextTarget;
37
+ /** 某几类目标对应的对象:run 的参数随 targets 收窄 */
38
+ export type PluginActionTargetOf<K extends PluginActionTargetKind> = Extract<PluginActionTarget, {
39
+ kind: K;
40
+ }>;
41
+ export interface PluginActionDefinition<K extends PluginActionTargetKind = PluginActionTargetKind> {
42
+ id: string;
43
+ /** 菜单里显示的名称 */
44
+ title: string;
45
+ /** 缺省使用插件图标 */
46
+ icon?: PluginIcon;
47
+ targets: readonly K[];
48
+ /**
49
+ * 用户在对象的「⋯」菜单里点击时调用。这个对象(对话消息为所在会话)之后与 pick 选中的一样,
50
+ * 不需要读取权限就能读标题、显示与关联;读正文仍按权限。
51
+ */
52
+ run(target: PluginActionTargetOf<K>): unknown;
53
+ }
54
+ export interface PluginActions {
55
+ /** 只在主窗口出现,独立编辑窗口不列插件动作 */
56
+ register<K extends PluginActionTargetKind>(definition: PluginActionDefinition<K>): Disposable;
57
+ }
58
+ export declare const PLUGIN_ACTION_TARGET_KINDS: readonly PluginActionTargetKind[];
59
+ /** 交给插件前复制并冻结,插件拿不到宿主对象上的其他字段 */
60
+ export declare function snapshotActionTarget(target: PluginActionTarget): PluginActionTarget;
61
+ export {};
@@ -1,19 +1,46 @@
1
+ import type { PluginContentInput } from "./content-input";
1
2
  import type { PluginContentRef } from "./data";
2
3
  /**
3
4
  * 关联与打开已有内容:插件页面(如自建画布)引用用户的卡片、日记、待办等,并在点击时打开。
4
- * 引用可以序列化后存入插件自己的数据;id 与 context.data 中同类实体的 id 一致。
5
+ * 引用可以序列化后存入插件自己的数据;id 对插件不透明,与 context.data 中同类实体的 id 一致。
5
6
  */
6
- export type PluginEntityKind = "card" | "article" | "document" | "diary" | "whiteboard" | "todo" | "event";
7
+ import type { PluginPermission } from "./permissions";
8
+ export type PluginEntityKind = "card" | "article" | "document" | "diary" | "whiteboard" | "todo" | "event" | "project" | "notebook"
9
+ /** 外部材料:划线、PDF 标注与剪藏 */
10
+ | "material" | "chat-session"
11
+ /** 插件自建的内容,包括其他插件的 */
12
+ | "plugin-entity";
7
13
  export declare const PLUGIN_ENTITY_KINDS: readonly PluginEntityKind[];
14
+ /**
15
+ * 不经选择时,读取一类引用的标题所需的权限;null 表示只能经用户选择获得。
16
+ * 插件读取自己创建的插件内容不需要权限。
17
+ */
18
+ export declare const PLUGIN_ENTITY_READ_PERMISSIONS: Readonly<Record<PluginEntityKind, PluginPermission | null>>;
8
19
  export interface PluginEntityRef {
9
20
  kind: PluginEntityKind;
10
21
  id: string;
11
22
  }
12
- /** 用户选中的一项:标题是选择时的快照,之后的改名需要读取权限才能取到 */
23
+ /** 用户选中的一项:标题是选择时的快照;之后可用 describe 取最新标题,不需要读取权限 */
13
24
  export interface PluginPickedEntity {
14
25
  ref: PluginEntityRef;
15
26
  title: string;
16
27
  }
28
+ /**
29
+ * 一项引用的当前状态。ok:title 为最新标题;missing:内容已删除;denied:用户没有选择过这项,
30
+ * 也没有授予 permission(为 null 时这类内容只能经用户选择获得)。
31
+ */
32
+ export type PluginEntityDescription = {
33
+ ref: PluginEntityRef;
34
+ status: "ok";
35
+ title: string;
36
+ } | {
37
+ ref: PluginEntityRef;
38
+ status: "missing";
39
+ } | {
40
+ ref: PluginEntityRef;
41
+ status: "denied";
42
+ permission: PluginPermission | null;
43
+ };
17
44
  export interface PluginPickOptions {
18
45
  /** 可选类型,顺序即弹窗中的分组顺序 */
19
46
  kinds: readonly PluginEntityKind[];
@@ -24,7 +51,10 @@ export interface PluginPickOptions {
24
51
  }
25
52
  export type PluginExportFormat = "markdown" | "image" | "pdf" | "epub";
26
53
  export declare const PLUGIN_EXPORT_FORMATS: readonly PluginExportFormat[];
27
- /** 宿主动作:界面与确认都由 Tau 提供,插件拿不到正文;目前支持卡片、文章与项目文档的正文 */
54
+ /**
55
+ * 宿主动作:界面与确认都由 Tau 提供,插件拿不到正文。content.* 支持卡片、文章、项目文档与
56
+ * 插件内容的正文。
57
+ */
28
58
  export interface PluginAppActions {
29
59
  /** Markdown 直接保存文件;图片、PDF、EPUB 打开导出窗口 */
30
60
  "content.export": {
@@ -39,6 +69,63 @@ export interface PluginAppActions {
39
69
  "content.share": {
40
70
  ref: PluginContentRef;
41
71
  };
72
+ /** 打开 Tau 的新建卡片窗口并预填,用户可以修改后保存 */
73
+ "card.create": {
74
+ content?: PluginContentInput;
75
+ tags?: string[];
76
+ };
77
+ /** 打开「插入到项目」窗口,由用户选择项目与位置,复制这份正文为新的项目文档 */
78
+ "project.insertDocument": {
79
+ content: PluginContentInput;
80
+ title?: string;
81
+ };
82
+ /**
83
+ * 确认后新建 Notebook,sources 作为资料一次性带入(之后不同步):有正文的内容成为笔记资料,
84
+ * 划线与 PDF 标注合并为一份、剪藏各一份,其他类型不带入。from 记为 Notebook 的来源,
85
+ * 显示在 Notebook 页顶部,见 PLUGIN_NOTEBOOK_FROM_KINDS。
86
+ */
87
+ "notebook.create": {
88
+ title: string;
89
+ sources?: PluginEntityRef[];
90
+ from?: PluginEntityRef;
91
+ };
92
+ /**
93
+ * 在对话页(page,默认)或右侧停靠栏(dock)开一个新对话:prompt 预填进输入框,context 作为
94
+ * 引用插入,由用户修改后发送。context 只支持 PLUGIN_CHAT_CONTEXT_KINDS 中的类型。
95
+ */
96
+ "chat.start": {
97
+ prompt?: string;
98
+ context?: PluginEntityRef[];
99
+ placement?: "page" | "dock";
100
+ };
101
+ }
102
+ /** 正文中的位置:第几个顶层块(从 0 开始,与 content.read 的 nodes 顺序一致),越界时落到开头 */
103
+ export interface PluginContentLocation {
104
+ block: number;
105
+ }
106
+ export interface PluginOpenOptions {
107
+ /**
108
+ * page(默认):主窗口的页面;window:独立编辑窗口,只支持卡片、文章与项目文档,不能同时定位;
109
+ * dock:右侧停靠栏,只支持主对话。
110
+ */
111
+ placement?: "page" | "window" | "dock";
112
+ /** 打开后滚动并闪烁到的位置;只支持卡片、文章、项目文档、日记与插件内容 */
113
+ at?: PluginContentLocation;
114
+ }
115
+ /** 可以作为对话上下文(chat.start 的 context)的类型 */
116
+ export declare const PLUGIN_CHAT_CONTEXT_KINDS: readonly PluginEntityKind[];
117
+ /** 可以作为 Notebook 来源(notebook.create 的 from)的类型 */
118
+ export declare const PLUGIN_NOTEBOOK_FROM_KINDS: readonly PluginEntityKind[];
119
+ /** 各动作的结果:新建类返回新内容的引用,用户取消时为 null */
120
+ export interface PluginAppActionResults {
121
+ "content.export": void;
122
+ "content.present": void;
123
+ "content.share": void;
124
+ "card.create": PluginEntityRef | null;
125
+ "project.insertDocument": PluginEntityRef | null;
126
+ "notebook.create": PluginEntityRef | null;
127
+ /** 用户发出第一条消息后返回对话的引用;没发送就关闭、切到别的对话或插件停用时为 null */
128
+ "chat.start": PluginEntityRef | null;
42
129
  }
43
130
  export type PluginAppAction = keyof PluginAppActions;
44
131
  export declare const PLUGIN_APP_ACTIONS: readonly PluginAppAction[];
@@ -48,8 +135,19 @@ export interface PluginApp {
48
135
  * 用户亲手挑选即视为同意插件引用这些内容,不需要读取权限。只能在用户操作(点击、按键)后调用。
49
136
  */
50
137
  pick(options: PluginPickOptions): Promise<PluginPickedEntity[]>;
51
- /** 打开对应的页面:卡片详情、日记当天、待办详情、日程详情等。只能在用户操作后调用;内容已删除时抛错。 */
52
- open(ref: PluginEntityRef): Promise<void>;
53
- /** 执行宿主动作,对应界面打开后返回。只能在用户操作后调用;不需要数据权限;内容已删除时抛错。 */
54
- run<A extends PluginAppAction>(action: A, options: PluginAppActions[A]): Promise<void>;
138
+ /**
139
+ * 打开对应的页面:卡片详情、日记当天、待办详情、日程详情等。只能在用户操作后调用;内容已删除时抛错。
140
+ * 打开位置与定位见 PluginOpenOptions,不支持的组合抛错。
141
+ */
142
+ open(ref: PluginEntityRef, options?: PluginOpenOptions): Promise<void>;
143
+ /**
144
+ * 批量取引用的当前标题与是否已删除,结果与 refs 一一对应,每次最多 200 项。用户选择过的内容、
145
+ * 本插件自己的内容不需要权限;其余需要该类的读取权限,未获准时为 denied,不弹窗询问。
146
+ */
147
+ describe(refs: readonly PluginEntityRef[]): Promise<PluginEntityDescription[]>;
148
+ /**
149
+ * 执行宿主动作,用户关闭对应界面后返回结果,见 PluginAppActionResults。只能在用户操作后调用,
150
+ * 同一时间只能打开一个;不需要数据权限,用户在界面中确认即同意。内容已删除时抛错。
151
+ */
152
+ run<A extends PluginAppAction>(action: A, options: PluginAppActions[A]): Promise<PluginAppActionResults[A]>;
55
153
  }
@@ -1,5 +1,12 @@
1
1
  import type { ReactElement } from "react";
2
2
  import type { PluginContentRef } from "./data";
3
+ import type { PluginEntityRef } from "./app";
4
+ /**
5
+ * 编辑器套件。full(默认):与卡片详情相同的完整套件。compact:精简套件,与白板图形文字、
6
+ * PDF 批注等简短内容的编辑器相同,不含内容链接、文件附件、白板块、数据库块与文档待办;
7
+ * 正文里已有的这些块显示为占位,数据原样保留。编辑与预览同一份内容时应使用同一套件。
8
+ */
9
+ export type ContentEditorKit = "full" | "compact";
3
10
  /**
4
11
  * 与卡片详情相同的正文编辑器:协作、内置与已安装的编辑器扩展、文档待办都由宿主提供。
5
12
  * 可编辑需要所属实体的写入权限,只读需要读取权限;未授权时显示「允许访问」,由用户点击后询问。
@@ -13,18 +20,33 @@ export interface ContentEditorProps {
13
20
  placeholder?: string;
14
21
  /** 打开后滚动并闪烁到的位置:从 Tau 打开插件内容时页面参数 params.at 原样传入 */
15
22
  at?: string;
23
+ /** 默认 full */
24
+ kit?: ContentEditorKit;
16
25
  }
17
26
  /** 正文开头几块的只读渲染,用于列表与卡面;需要所属实体的读取权限。 */
18
27
  export interface ContentPreviewProps {
19
28
  contentRef: PluginContentRef;
20
29
  /** 显示的块数,默认 3 */
21
30
  maxBlocks?: number;
31
+ /** 默认 full;与编辑这份内容的 ContentEditor 保持一致 */
32
+ kit?: ContentEditorKit;
33
+ }
34
+ /**
35
+ * 一项引用的显示:图标、类型名与标题由宿主渲染,内容已删除时显示「已删除」。授权口径与
36
+ * context.app.describe 相同;未获准时显示类型名与「允许访问」,由用户点击后询问。
37
+ */
38
+ export interface EntityRefProps {
39
+ target: PluginEntityRef;
40
+ /** 默认 true:点击时用 context.app.open 打开 */
41
+ openable?: boolean;
22
42
  }
23
43
  /** 宿主注入的实现;SDK 根入口只引用 React 类型,不加载 React 运行时。 */
24
44
  export interface ContentComponentsRuntime {
25
45
  ContentEditor(props: ContentEditorProps): ReactElement | null;
26
46
  ContentPreview(props: ContentPreviewProps): ReactElement | null;
47
+ EntityRef(props: EntityRefProps): ReactElement | null;
27
48
  }
28
49
  export declare function configureContentComponents(value: ContentComponentsRuntime): void;
29
50
  export declare const ContentEditor: (props: ContentEditorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
30
51
  export declare const ContentPreview: (props: ContentPreviewProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
52
+ export declare const EntityRef: (props: EntityRefProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;