@gantfdt/semiword 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +258 -2
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs +442 -0
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs.map +1 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs +141 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs.map +1 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs +120 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs.map +1 -0
- package/dist-lib/ai.d.mts +33 -0
- package/dist-lib/ai.mjs +14 -0
- package/dist-lib/ai.mjs.map +1 -0
- package/dist-lib/chunk-347SCO7S.mjs +3 -0
- package/dist-lib/chunk-347SCO7S.mjs.map +1 -0
- package/dist-lib/chunk-4F4NEVHE.mjs +100 -0
- package/dist-lib/chunk-4F4NEVHE.mjs.map +1 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs +474 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs.map +1 -0
- package/dist-lib/chunk-7AAZUM6M.mjs +45 -0
- package/dist-lib/chunk-7AAZUM6M.mjs.map +1 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs +1510 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs.map +1 -0
- package/dist-lib/chunk-CREU4TZJ.mjs +24 -0
- package/dist-lib/chunk-CREU4TZJ.mjs.map +1 -0
- package/dist-lib/chunk-EEUFVA37.mjs +4024 -0
- package/dist-lib/chunk-EEUFVA37.mjs.map +1 -0
- package/dist-lib/chunk-EOIJPQZI.mjs +370 -0
- package/dist-lib/chunk-EOIJPQZI.mjs.map +1 -0
- package/dist-lib/chunk-EOUNN3NA.mjs +1517 -0
- package/dist-lib/chunk-EOUNN3NA.mjs.map +1 -0
- package/dist-lib/chunk-FOIP7DEC.mjs +12 -0
- package/dist-lib/chunk-FOIP7DEC.mjs.map +1 -0
- package/dist-lib/chunk-GGIOCI2I.mjs +2442 -0
- package/dist-lib/chunk-GGIOCI2I.mjs.map +1 -0
- package/dist-lib/chunk-IICCIMZU.mjs +5272 -0
- package/dist-lib/chunk-IICCIMZU.mjs.map +1 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs +600 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs.map +1 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs +6327 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs.map +1 -0
- package/dist-lib/chunk-NPPS63UI.mjs +285 -0
- package/dist-lib/chunk-NPPS63UI.mjs.map +1 -0
- package/dist-lib/chunk-PFA3XERW.mjs +19 -0
- package/dist-lib/chunk-PFA3XERW.mjs.map +1 -0
- package/dist-lib/chunk-QWDJU3H7.mjs +18 -0
- package/dist-lib/chunk-QWDJU3H7.mjs.map +1 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs +3917 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs.map +1 -0
- package/dist-lib/chunk-W627LLF4.mjs +16 -0
- package/dist-lib/chunk-W627LLF4.mjs.map +1 -0
- package/dist-lib/chunk-XAEALEVP.mjs +547 -0
- package/dist-lib/chunk-XAEALEVP.mjs.map +1 -0
- package/dist-lib/chunk-ZM3WULHX.mjs +910 -0
- package/dist-lib/chunk-ZM3WULHX.mjs.map +1 -0
- package/dist-lib/context-DKwyjx1q.d.mts +37 -0
- package/dist-lib/designer.d.mts +215 -0
- package/dist-lib/designer.mjs +15 -0
- package/dist-lib/designer.mjs.map +1 -0
- package/dist-lib/document.d.mts +12 -0
- package/dist-lib/document.mjs +4 -0
- package/dist-lib/document.mjs.map +1 -0
- package/dist-lib/editor.d.mts +408 -0
- package/dist-lib/editor.mjs +19 -0
- package/dist-lib/editor.mjs.map +1 -0
- package/dist-lib/gant-ai.d.mts +40 -0
- package/dist-lib/gant-ai.mjs +217 -0
- package/dist-lib/gant-ai.mjs.map +1 -0
- package/dist-lib/index.d.mts +22 -0
- package/dist-lib/index.mjs +19 -0
- package/dist-lib/index.mjs.map +1 -0
- package/dist-lib/interface-RYndHNLS.d.mts +91 -0
- package/dist-lib/io.d.mts +75 -0
- package/dist-lib/io.mjs +9 -0
- package/dist-lib/io.mjs.map +1 -0
- package/dist-lib/memoryHistoryStore-DY47xjO_.d.mts +280 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs +4 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs.map +1 -0
- package/dist-lib/resolve-BMcwblyP.d.mts +114 -0
- package/dist-lib/sdk.d.mts +60 -0
- package/dist-lib/sdk.mjs +137 -0
- package/dist-lib/sdk.mjs.map +1 -0
- package/dist-lib/shapes-5SMSF6ML.mjs +4 -0
- package/dist-lib/shapes-5SMSF6ML.mjs.map +1 -0
- package/dist-lib/storage.d.mts +91 -0
- package/dist-lib/storage.mjs +5 -0
- package/dist-lib/storage.mjs.map +1 -0
- package/dist-lib/template.d.mts +155 -0
- package/dist-lib/template.mjs +6 -0
- package/dist-lib/template.mjs.map +1 -0
- package/dist-lib/types-CO6ppyIY.d.mts +18 -0
- package/dist-lib/types-CUsV1hUm.d.mts +49 -0
- package/dist-lib/types-ClQ38-C_.d.mts +256 -0
- package/dist-lib/types-D1D2miCr.d.mts +117 -0
- package/dist-lib/types-DiyyKlc1.d.mts +355 -0
- package/dist-lib/types-s1JYaGtG.d.mts +56 -0
- package/dist-lib/types-vl8k8NDK.d.mts +562 -0
- package/dist-lib/useDocumentPersistence-DOpnQsZQ.d.mts +228 -0
- package/package.json +282 -4
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { a as DesignerBlock, B as BuildIssue, b as BlockTypeMeta, D as DesignerTemplate, c as BuildResult, d as DesignerTableVariant } from './types-ClQ38-C_.mjs';
|
|
2
|
+
import { JSONContent } from '@tiptap/core';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { h as TemplateBlockKind, T as TemplateDataSource, i as TemplateSlotDefinition } from './types-DiyyKlc1.mjs';
|
|
5
|
+
import { P as ParseResult, a as TemplateDesignerProps, b as TemplateExportFormat, I as ImportTemplateResult } from './interface-RYndHNLS.mjs';
|
|
6
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
|
+
import { c as TemplateHistoryEntry, a as TemplateHistoryStore } from './types-D1D2miCr.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 设计器块描述符注册契约。
|
|
11
|
+
*
|
|
12
|
+
* 业务注册自定义块类型时唯一要读的文件:实现 DesignerBlockDescriptor 后经
|
|
13
|
+
* ./registry 的 registerDesignerBlocks 注册;编辑器侧还需 registerTemplateBlocks
|
|
14
|
+
* 注册对应 kind 的 adapter。物料项、设置区渲染、编译/反解析、大纲摘要都挂在这里。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** 组件库(添加块按钮区)中的一个物料项。 */
|
|
18
|
+
interface DesignerBlockPaletteItem {
|
|
19
|
+
/** 物料项标识(同一描述符内唯一,如 table-data / table-form)。 */
|
|
20
|
+
key: string;
|
|
21
|
+
/** 物料项显示名(如「数据表格(可新增行)」)。 */
|
|
22
|
+
label: string;
|
|
23
|
+
/** 创建该物料项对应的块(uid 由设计器统一分配,无需提供)。 */
|
|
24
|
+
create: () => Omit<DesignerBlock, 'uid'>;
|
|
25
|
+
}
|
|
26
|
+
/** 块设置区(卡片内)渲染 props。 */
|
|
27
|
+
interface DesignerBlockSettingsProps {
|
|
28
|
+
block: DesignerBlock;
|
|
29
|
+
/** 就地合并块属性(等价于设计器的 patchBlock(uid, patch))。 */
|
|
30
|
+
onPatch: (patch: Partial<DesignerBlock>) => void;
|
|
31
|
+
/** 当前模板选择的数据源,供文本/表格绑定控件使用。 */
|
|
32
|
+
dataSource?: TemplateDataSource;
|
|
33
|
+
/** 画布联动选中的单元格(仅表格类块由页面注入;null/缺省 = 无手动选中)。 */
|
|
34
|
+
cellSelection?: {
|
|
35
|
+
row: number;
|
|
36
|
+
cell: number;
|
|
37
|
+
} | null;
|
|
38
|
+
/** 单元格选中变化上报(网格点选;null = 清除,结构变化下标错位时组件主动清除)。 */
|
|
39
|
+
onCellSelectionChange?: (cell: {
|
|
40
|
+
row: number;
|
|
41
|
+
cell: number;
|
|
42
|
+
} | null) => void;
|
|
43
|
+
}
|
|
44
|
+
/** 描述符编译输出:顶层裸节点(不含 templateSlot,由编译器统一注入)+ 可选槽位覆盖。 */
|
|
45
|
+
interface DesignerBlockCompileOutput {
|
|
46
|
+
/** 顶层块节点(无需携带 templateSlot / 结构载体属性)。 */
|
|
47
|
+
node: JSONContent;
|
|
48
|
+
/** 完整覆盖缺省槽位声明(表格等特殊块用;缺省按 kind/label/required 推导)。 */
|
|
49
|
+
slot?: TemplateSlotDefinition;
|
|
50
|
+
/** 编译问题。 */
|
|
51
|
+
issues?: BuildIssue[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 设计器块描述符:一种块类型的全部设计器行为。
|
|
55
|
+
* 业务注册自定义块时实现本接口;编辑器侧还需 registerTemplateBlocks 注册对应 kind 的 adapter。
|
|
56
|
+
*/
|
|
57
|
+
interface DesignerBlockDescriptor {
|
|
58
|
+
/** 块类型标识(DesignerBlock.type),如 'bomReference'。 */
|
|
59
|
+
type: string;
|
|
60
|
+
/** 类型显示名(块卡片 Tag / 大纲)。 */
|
|
61
|
+
label: string;
|
|
62
|
+
/** 对应的模板槽位 kind(需已在编辑器侧注册 adapter)。 */
|
|
63
|
+
kind: TemplateBlockKind;
|
|
64
|
+
/** 是否可标记为槽位(不可则始终为固定文字)。 */
|
|
65
|
+
slotEligible: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 表格类块恒受结构保护(缺省 false):不可切自由块(必填开关隐藏、始终按非自由块
|
|
68
|
+
* 判定),标签必填(固定表格也须有标签),设置区分组标题取「表格设置」固定文案。
|
|
69
|
+
* 通用层(types/compile/BlockSettingsForm)一律读本能力位,不再比对 'table' 字面量。
|
|
70
|
+
*/
|
|
71
|
+
alwaysStructured?: boolean;
|
|
72
|
+
/** 组件库排序权重,缺省 100;内置:标题 10 / 文本 20 / 图片 30 / 表格 40 / 代码块 50。 */
|
|
73
|
+
order?: number;
|
|
74
|
+
/** 组件库物料项;缺省为单物料项(label 取 descriptor.label)。 */
|
|
75
|
+
getPaletteItems?: () => DesignerBlockPaletteItem[];
|
|
76
|
+
/** 块设置区渲染(嵌入块卡片内部,位于类型/标签/填写开关等通用控件之间下方)。 */
|
|
77
|
+
renderSettings?: (props: DesignerBlockSettingsProps) => ReactNode;
|
|
78
|
+
/** 编译为 TemplateDefinition 的顶层节点。 */
|
|
79
|
+
compile: (block: DesignerBlock, index: number) => DesignerBlockCompileOutput;
|
|
80
|
+
/** 从 TemplateDefinition 顶层节点反解析(JSON 导入);无法识别返回 null。 */
|
|
81
|
+
parse?: (node: JSONContent) => Omit<DesignerBlock, 'uid' | 'zone' | 'groupId' | 'groupLabel'> | null;
|
|
82
|
+
/** 大纲行/画布兜底占位的摘要行(如「3 列 × 5 行」);缺省返回 label。 */
|
|
83
|
+
getSummary?: (block: DesignerBlock) => string;
|
|
84
|
+
}
|
|
85
|
+
/** 组件库条目:描述符 × 物料项,按 order 升序(缺省 100),再按注册序。 */
|
|
86
|
+
interface DesignerPaletteEntry {
|
|
87
|
+
descriptor: DesignerBlockDescriptor;
|
|
88
|
+
items: DesignerBlockPaletteItem[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 设计器块描述符注册表。
|
|
93
|
+
*
|
|
94
|
+
* 类似 features/template/utils/registry.ts(编辑器块 adapter 注册)的统一注册入口:
|
|
95
|
+
* 内置块(标题/文本/图片/表格/代码块)只在本模块注册一次;业务项目在应用启动文件
|
|
96
|
+
* 调用 registerDesignerBlocks 即可让自定义块出现在设计器的组件库、块设置区、
|
|
97
|
+
* 编译与 JSON 导入中——无需改动设计器代码。
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
declare function nextDesignerUid(): string;
|
|
101
|
+
/**
|
|
102
|
+
* 注册设计器块描述符,支持单个或批量;同 type 重复注册默认忽略,
|
|
103
|
+
* override: true 时覆盖(便于业务替换内置块行为)。
|
|
104
|
+
*/
|
|
105
|
+
declare function registerDesignerBlocks(input: DesignerBlockDescriptor | readonly DesignerBlockDescriptor[], options?: {
|
|
106
|
+
override?: boolean;
|
|
107
|
+
}): void;
|
|
108
|
+
/** 获取全部已注册的块描述符(含内置),注册序。 */
|
|
109
|
+
declare function getDesignerBlockDescriptors(): DesignerBlockDescriptor[];
|
|
110
|
+
/** 按类型取块描述符;未注册返回 undefined。 */
|
|
111
|
+
declare function getDesignerBlockDescriptor(type: string): DesignerBlockDescriptor | undefined;
|
|
112
|
+
/** 获取组件库全部条目(多物料项的描述符如表格渲染为下拉分组)。 */
|
|
113
|
+
declare function getDesignerPalette(): DesignerPaletteEntry[];
|
|
114
|
+
/** 兼容旧 API:取块类型元信息(内置静态清单优先,其次注册表,最终按原类型生成 generic 兜底)。 */
|
|
115
|
+
declare function blockTypeMeta(type: string): BlockTypeMeta;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 设计器模型 → 编辑器模板定义(TemplateDefinition)的编译编排器。
|
|
119
|
+
*
|
|
120
|
+
* 各块类型的节点构建/反解析由块描述符(registry)提供;本模块负责通用编排:
|
|
121
|
+
* - templateSlot 声明统一注入(key/kind/label/required/validation + 描述符覆盖);
|
|
122
|
+
* - 结构载体属性(templatePin / templateBlockRef / templateBefore / templateAfter /
|
|
123
|
+
* templateGroupId / templateGroupLabel)统一写入顶层块,由编辑器侧编译器
|
|
124
|
+
* (features/template/utils/compile.ts)消费进 TemplateBlockMeta 后剥离;
|
|
125
|
+
* - 钉住顺序(置顶 → 中间 → 置底)、组件组(成员连续、不含自由块)与块级偏序
|
|
126
|
+
* (目标存在且受保护、当前顺序满足、整体拓扑无环)的编译期校验;
|
|
127
|
+
* - TemplateDefinition 反向解析(JSON 导入回设计器继续编辑;before/after 的定义层
|
|
128
|
+
* ref 经两遍解析重映射为新分配的设计器 uid)。
|
|
129
|
+
*
|
|
130
|
+
* 编译规则对齐 features/template/utils/compile.ts:
|
|
131
|
+
* - templateSlot 只声明在顶层块;
|
|
132
|
+
* - codeBlock 若有预填文本,validation 必须带 ignoreInitialContent,否则被判为 CODE_HINT_AS_VALUE;
|
|
133
|
+
* - image 槽位使用 image 节点;table 槽位使用 table 节点。
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 结构校验(钉住顺序 + 组件组 + 偏序约束),供设计器在移动/改钉住/改偏序/入组前预判合法性。
|
|
138
|
+
* 与 buildDefinition 内部使用同一套规则。
|
|
139
|
+
*/
|
|
140
|
+
declare function validateBlockStructure(blocks: readonly DesignerBlock[]): BuildIssue[];
|
|
141
|
+
/**
|
|
142
|
+
* 将设计器模型编译为 TemplateDefinition。
|
|
143
|
+
* 做基础校验(名称、ID、块非空、标签必填、钉住顺序、组件组、偏序约束),细粒度 schema 校验交由编辑器编译期完成。
|
|
144
|
+
*/
|
|
145
|
+
declare function buildDefinition(designer: DesignerTemplate): BuildResult;
|
|
146
|
+
/**
|
|
147
|
+
* 将 TemplateDefinition 反向解析为设计器模型,用于导入后继续编辑。
|
|
148
|
+
*
|
|
149
|
+
* 按注册表分派到各块描述符的反解析;未注册类型或未识别节点跳过并计入 skipped。
|
|
150
|
+
* 槽位信息(label/required)从 templateSlot 还原;pin/组件组从结构载体属性还原
|
|
151
|
+
* (readStructureCarriers 只认 templatePin,块上只写 pin);
|
|
152
|
+
* before/after 为定义层 ref,经两遍解析重映射为新分配的设计器 uid(无法解析的丢弃,
|
|
153
|
+
* 逐条记入 warnings 供 UI 提示)。
|
|
154
|
+
*/
|
|
155
|
+
declare function parseDefinition(definition: unknown): ParseResult;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 模板设计器页面入口:解析存储端口并下发。
|
|
159
|
+
*
|
|
160
|
+
* 解析顺序:props.storage → 祖先 TemplateStorageProvider → 全局默认存储(内存兜底)。
|
|
161
|
+
* 内层 Provider 让子组件(历史面板等)与页面自身读到同一份实例——注意 Provider 只对
|
|
162
|
+
* 子树生效,因此页面自身(渲染 Provider 的那一层)拿不到 Context,须显式下传。
|
|
163
|
+
*/
|
|
164
|
+
declare function TemplateDesigner({ storage: storageProp, headerLeading, headerActionsExtra, onBack, dataSources, aiRegistrar, }: TemplateDesignerProps): react_jsx_runtime.JSX.Element;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 触发导出下载;编译失败/内容为空时返回 { ok: false, message }。
|
|
168
|
+
*
|
|
169
|
+
* - json:buildDefinition 编译(失败返回首条 issue),JSON.stringify 后下载 {id}.json;
|
|
170
|
+
* - markdown:编译后 jsonToMarkdown 输出快照(槽位值/占位以文本形式保留),下载 {id}.md;
|
|
171
|
+
* - html:编译后经降级遍历 + generateHTML 得 body 片段,exportHtml 内部
|
|
172
|
+
* sanitize + 拼装 CSS + 下载 {id}.html。
|
|
173
|
+
*/
|
|
174
|
+
declare function exportTemplate(designer: DesignerTemplate, format: TemplateExportFormat): {
|
|
175
|
+
ok: boolean;
|
|
176
|
+
message?: string;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* 解析导入文件内容为设计器模型。
|
|
180
|
+
*
|
|
181
|
+
* 按扩展名识别:.json → 无损反解析;.md/.markdown → markdownToHtml 后走 HTML
|
|
182
|
+
* 共用逻辑;.html/.htm → HTML 共用逻辑(sanitize → generateJSON → 包装为
|
|
183
|
+
* TemplateDefinition → parseDefinition,不支持的块被跳过并计数)。
|
|
184
|
+
*/
|
|
185
|
+
declare function importTemplateFile(file: File): Promise<ImportTemplateResult>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 表格 JSON 容错解析:把 AI 生成 / Excel 导入产出的宽松 JSON 解析为设计器表格块。
|
|
189
|
+
*
|
|
190
|
+
* 输入契约见同目录 TABLE_JSON.md(Excel 导入 / AI 图片识别生成 JSON 的目标格式)。
|
|
191
|
+
* 接受三种输入形态(完整块 / 带包装 / 裸模型),变体可显式声明也可按内容探测
|
|
192
|
+
* (columns → 数据表格,rows → 固定表格)。字段级容错:未知字段丢弃、非法值回退
|
|
193
|
+
* 缺省并记入 warnings(中文一句话一条,供 UI 提示哪些内容被修正),只有结构性
|
|
194
|
+
* 问题(无列 / 无行)才解析失败。
|
|
195
|
+
*
|
|
196
|
+
* 解析产物交给 normalizeTableBlock 走一遍归一化(defaultRows/defaultData 行列裁齐、
|
|
197
|
+
* 公式互斥、幽灵格重对齐),因此与 DesignerDataTableModel / DesignerFormTableModel
|
|
198
|
+
* 完全同构,补上 uid 即可直接进入设计器与编译流程(uid 由设计器统一分配)。
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
/** 表格 JSON 解析结果。 */
|
|
202
|
+
type TableJsonParseResult = {
|
|
203
|
+
ok: true;
|
|
204
|
+
block: Omit<DesignerBlock, 'uid'>;
|
|
205
|
+
variant: DesignerTableVariant;
|
|
206
|
+
warnings: string[];
|
|
207
|
+
} | {
|
|
208
|
+
ok: false;
|
|
209
|
+
message: string;
|
|
210
|
+
};
|
|
211
|
+
/** 解析表格 JSON 文本为设计器表格块(不含 uid,由设计器分配)。 */
|
|
212
|
+
declare function parseTableJson(text: string): TableJsonParseResult;
|
|
213
|
+
|
|
214
|
+
/** TemplateHistoryDrawer 属性(与 TemplateHistoryPanel 一致,另加开关)。 */
|
|
215
|
+
interface TemplateHistoryDrawerProps {
|
|
216
|
+
/** 是否打开。 */
|
|
217
|
+
open: boolean;
|
|
218
|
+
/** 关闭回调。 */
|
|
219
|
+
onClose: () => void;
|
|
220
|
+
/** 模板 ID(历史按此维度存取)。 */
|
|
221
|
+
templateId: string;
|
|
222
|
+
/** 模板名称(用于确认弹窗文案)。 */
|
|
223
|
+
templateName: string;
|
|
224
|
+
/** 草稿上限(页面持有并持久化)。 */
|
|
225
|
+
maxDrafts: number;
|
|
226
|
+
/** 草稿上限修改回调(页面负责持久化)。 */
|
|
227
|
+
onMaxDraftsChange: (value: number) => void;
|
|
228
|
+
/** 恢复回调(面板内已 confirm,页面直接应用 entry.designer)。 */
|
|
229
|
+
onRestore: (entry: TemplateHistoryEntry) => void;
|
|
230
|
+
}
|
|
231
|
+
/** 模板历史版本抽屉。 */
|
|
232
|
+
declare function TemplateHistoryDrawer(props: TemplateHistoryDrawerProps): JSX.Element;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 模板历史子系统(history/ 各模块)的类型定义集合。
|
|
236
|
+
*
|
|
237
|
+
* 模块级 interface / type 声明(仅类型,
|
|
238
|
+
* 不含任何常量、组件与函数);各实现文件经 `import type { ... } from './interface'` 取用。
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
/** TemplateHistoryPanel 属性。 */
|
|
242
|
+
interface TemplateHistoryPanelProps {
|
|
243
|
+
/** 模板 ID(历史按此维度存取)。 */
|
|
244
|
+
templateId: string;
|
|
245
|
+
/** 模板名称(用于确认弹窗文案)。 */
|
|
246
|
+
templateName: string;
|
|
247
|
+
/** 草稿上限(页面持有并持久化)。 */
|
|
248
|
+
maxDrafts: number;
|
|
249
|
+
/** 草稿上限修改回调(页面负责持久化)。 */
|
|
250
|
+
onMaxDraftsChange: (value: number) => void;
|
|
251
|
+
/** 恢复回调(面板内已 confirm,页面直接应用 entry.designer)。 */
|
|
252
|
+
onRestore: (entry: TemplateHistoryEntry) => void;
|
|
253
|
+
}
|
|
254
|
+
/** useTemplateDraftHistory 配置。 */
|
|
255
|
+
interface UseTemplateDraftHistoryOptions {
|
|
256
|
+
/** 当前编辑中的设计器模型(页面 state,引用随编辑变化)。 */
|
|
257
|
+
template: DesignerTemplate;
|
|
258
|
+
/** 草稿保留条数上限(配置由页面持有并持久化)。 */
|
|
259
|
+
maxDrafts: number;
|
|
260
|
+
/** 是否启用;缺省 true。template.id 为空时内部自动禁用。 */
|
|
261
|
+
enabled?: boolean;
|
|
262
|
+
/** 内容变化后的防抖毫秒数,缺省 2000。 */
|
|
263
|
+
debounceMs?: number;
|
|
264
|
+
/** 历史存储覆盖;缺省取 TemplateStorageProvider / 全局默认存储的 history。 */
|
|
265
|
+
store?: TemplateHistoryStore;
|
|
266
|
+
}
|
|
267
|
+
/** useTemplateDraftHistory 返回值。 */
|
|
268
|
+
interface UseTemplateDraftHistoryResult {
|
|
269
|
+
/** 最近一次实际落盘草稿的时间戳;从未落盘为 null。 */
|
|
270
|
+
lastCapturedAt: number | null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** 自动草稿落盘 hook(详见文件头说明)。 */
|
|
274
|
+
declare function useTemplateDraftHistory(options: UseTemplateDraftHistoryOptions): UseTemplateDraftHistoryResult;
|
|
275
|
+
|
|
276
|
+
/** 创建内存历史存储(进程内共享,不做持久化)。 */
|
|
277
|
+
declare function createMemoryHistoryStore(): TemplateHistoryStore;
|
|
278
|
+
|
|
279
|
+
export { TemplateDesigner as f, TemplateHistoryDrawer as g, blockTypeMeta as i, buildDefinition as j, createMemoryHistoryStore as k, exportTemplate as l, getDesignerBlockDescriptor as m, getDesignerBlockDescriptors as n, getDesignerPalette as o, importTemplateFile as p, nextDesignerUid as q, parseDefinition as r, parseTableJson as s, registerDesignerBlocks as t, useTemplateDraftHistory as u, validateBlockStructure as v };
|
|
280
|
+
export type { DesignerBlockCompileOutput as D, TemplateHistoryPanelProps as T, UseTemplateDraftHistoryOptions as U, DesignerBlockDescriptor as a, DesignerBlockPaletteItem as b, DesignerBlockSettingsProps as c, DesignerPaletteEntry as d, TableJsonParseResult as e, TemplateHistoryDrawerProps as h };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"mindmapConstants-X75XUXV3.mjs"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { JSONContent, Extensions } from '@tiptap/core';
|
|
2
|
+
import { Node } from '@tiptap/pm/model';
|
|
3
|
+
import { h as TemplateBlockKind, i as TemplateSlotDefinition, j as TemplateBlockMeta, k as TemplateStructureCarriers, a as TemplatePin, b as TemplateDefinition, l as TemplateDataResolveResult, T as TemplateDataSource } from './types-DiyyKlc1.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 模板功能模块的独立类型定义。
|
|
7
|
+
*
|
|
8
|
+
* 收纳同目录 compile.ts / adapters.ts / state.ts 的模块级 interface / type 声明,
|
|
9
|
+
* 定义内容与原位置逐字一致;实现文件与同目录消费者经 `./interface` 导入。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 偏序拓扑校验的输入载体:结构载体子集(types.ts 的 TemplateStructureCarriers)
|
|
14
|
+
* 加顶层序号。pin/blockRef 兼容 null(与缺省同义)——运行时编译器与设计器编译器
|
|
15
|
+
* 内部均以 null 表示「无声明」,在此归一两种口径,调用方无需做 null → undefined 转换。
|
|
16
|
+
*/
|
|
17
|
+
type OrderConstraintCarrier = Omit<TemplateStructureCarriers, 'zone' | 'groupId' | 'groupLabel' | 'pin' | 'blockRef'> & {
|
|
18
|
+
/** 顶层块序号(供错误定位)。 */
|
|
19
|
+
index: number;
|
|
20
|
+
pin?: TemplatePin | null;
|
|
21
|
+
blockRef?: string | null;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 模板块适配器接口,定义每种块类型的完整行为契约。
|
|
25
|
+
*
|
|
26
|
+
* - instantiate: 从定义节点创建运行时节点
|
|
27
|
+
* - isFilled: 判断节点是否已填写
|
|
28
|
+
* - toUnlockedNode: 去锁转换为普通节点(用于复制/导出)
|
|
29
|
+
*/
|
|
30
|
+
interface TemplateBlockAdapter {
|
|
31
|
+
/** 块种类标识符。 */
|
|
32
|
+
kind: TemplateBlockKind;
|
|
33
|
+
/** 支持的源节点类型列表,'*' 表示任意类型。 */
|
|
34
|
+
sourceNodeTypes: readonly string[];
|
|
35
|
+
/** 从定义节点实例化运行时节点。 */
|
|
36
|
+
instantiate(input: InstantiateBlockInput): InstantiateBlockOutput;
|
|
37
|
+
/** 判断节点是否已填写。 */
|
|
38
|
+
isFilled(node: Node, meta: TemplateBlockMeta): boolean;
|
|
39
|
+
/** 去锁转换为普通节点,用于复制和导出场景。 */
|
|
40
|
+
toUnlockedNode(node: Node): JSONContent | null;
|
|
41
|
+
}
|
|
42
|
+
/** 模板块注册项,包含 adapter 和可选的 Tiptap Extension。 */
|
|
43
|
+
interface TemplateBlockRegistration {
|
|
44
|
+
/** 块适配器。 */
|
|
45
|
+
adapter: TemplateBlockAdapter;
|
|
46
|
+
/** 特殊业务块可把自身 Tiptap Extension 与 adapter 一次注册。 */
|
|
47
|
+
extensions?: Extensions;
|
|
48
|
+
}
|
|
49
|
+
/** 实例化输入参数。 */
|
|
50
|
+
interface InstantiateBlockInput {
|
|
51
|
+
/** 源节点(已剥离定义属性)。 */
|
|
52
|
+
sourceNode: JSONContent;
|
|
53
|
+
/** 块 ID。 */
|
|
54
|
+
blockId: string;
|
|
55
|
+
/** 槽位定义。 */
|
|
56
|
+
slot: TemplateSlotDefinition;
|
|
57
|
+
}
|
|
58
|
+
/** 实例化输出(运行时节点)。 */
|
|
59
|
+
interface InstantiateBlockOutput {
|
|
60
|
+
/** 运行时节点(将被包装进 protectedBlock)。 */
|
|
61
|
+
runtimeNode: JSONContent;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 块适配器注册表。
|
|
66
|
+
* 支持按 kind 和 nodeType 两种维度查找 adapter。
|
|
67
|
+
*/
|
|
68
|
+
declare class AdapterRegistry {
|
|
69
|
+
private readonly byKind;
|
|
70
|
+
private readonly byNodeType;
|
|
71
|
+
/** 注册适配器,override 选项允许覆盖同 kind 的已有 adapter。 */
|
|
72
|
+
register(adapter: TemplateBlockAdapter, options?: {
|
|
73
|
+
override?: boolean;
|
|
74
|
+
}): void;
|
|
75
|
+
/** 按 kind 获取适配器。 */
|
|
76
|
+
get(kind: TemplateBlockKind): TemplateBlockAdapter | undefined;
|
|
77
|
+
/** 检查 kind 是否已注册。 */
|
|
78
|
+
has(kind: TemplateBlockKind): boolean;
|
|
79
|
+
/** 按节点类型获取适配器。 */
|
|
80
|
+
getByNodeType(nodeType: string): TemplateBlockAdapter | undefined;
|
|
81
|
+
/** 获取所有已注册的适配器。 */
|
|
82
|
+
all(): TemplateBlockAdapter[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 模板块注册表。
|
|
87
|
+
*
|
|
88
|
+
* 类似 procomponents.setSchemaMaps 的统一注册入口。
|
|
89
|
+
* 默认块只在本模块注册一次;特殊业务块在应用启动文件调用一次即可。
|
|
90
|
+
* 同时收集各块关联的 Tiptap Extension,供插件统一注册。
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/** 注册输入类型,可以是纯 adapter 或包含扩展的完整注册项。 */
|
|
94
|
+
type TemplateBlockRegistrationInput = TemplateBlockAdapter | TemplateBlockRegistration;
|
|
95
|
+
/**
|
|
96
|
+
* 注册模板块,支持单个或批量注册。
|
|
97
|
+
* 每个注册项包含 adapter(必须)和可选的 Tiptap extensions。
|
|
98
|
+
* override 选项允许覆盖已注册的同 kind adapter。
|
|
99
|
+
*/
|
|
100
|
+
declare function registerTemplateBlocks(registrations: TemplateBlockRegistrationInput | readonly TemplateBlockRegistrationInput[], options?: {
|
|
101
|
+
override?: boolean;
|
|
102
|
+
}): AdapterRegistry;
|
|
103
|
+
/**
|
|
104
|
+
* 全局注册模板定义,支持单个或批量。
|
|
105
|
+
* 应用启动时注册一次,各编辑器实例即可通过 initialTemplateId / applyTemplate 使用,
|
|
106
|
+
* 无需逐个传入 template.definitions;同名 id 后注册覆盖先注册(prop definitions 优先级仍最高)。
|
|
107
|
+
*/
|
|
108
|
+
declare function registerTemplates(definitions: TemplateDefinition | readonly TemplateDefinition[]): void;
|
|
109
|
+
|
|
110
|
+
declare function resolveTemplateData(definition: TemplateDefinition, data: unknown): TemplateDataResolveResult;
|
|
111
|
+
declare function resolveTemplateDataFromSource(definition: TemplateDefinition, sources: readonly TemplateDataSource[]): Promise<TemplateDataResolveResult>;
|
|
112
|
+
|
|
113
|
+
export { registerTemplates as b, resolveTemplateData as c, resolveTemplateDataFromSource as d, registerTemplateBlocks as r };
|
|
114
|
+
export type { OrderConstraintCarrier as O, TemplateBlockAdapter as T, TemplateBlockRegistration as a };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SemiWordDocumentSnapshot } from './document.mjs';
|
|
2
|
+
import { EditorRef, RichEditorProps } from './editor.mjs';
|
|
3
|
+
import '@tiptap/core';
|
|
4
|
+
import 'yjs';
|
|
5
|
+
import 'react';
|
|
6
|
+
import './types-DiyyKlc1.mjs';
|
|
7
|
+
|
|
8
|
+
/** 命令式挂载配置:RichEditor 全部 props + 挂载容器。 */
|
|
9
|
+
interface SemiWordSDKOptions extends RichEditorProps {
|
|
10
|
+
/** 挂载容器:DOM 元素或 CSS 选择器。 */
|
|
11
|
+
container: HTMLElement | string;
|
|
12
|
+
}
|
|
13
|
+
type SemiWordSDKUpdateOptions = Partial<Omit<SemiWordSDKOptions, 'container'>>;
|
|
14
|
+
/**
|
|
15
|
+
* 命令式 facade(`new SDK()` 形态):内部经 createRoot 挂载 RichEditor,
|
|
16
|
+
* 与 React 组件用法共享同一核心;面向非 React 页面或命令式集成场景。
|
|
17
|
+
*/
|
|
18
|
+
declare class SemiWordSDK {
|
|
19
|
+
/** 编辑器就绪后 resolve;方法调用前建议 await sdk.ready。 */
|
|
20
|
+
readonly ready: Promise<EditorRef>;
|
|
21
|
+
private root;
|
|
22
|
+
private editorProps;
|
|
23
|
+
private editorRef;
|
|
24
|
+
private resolveReady;
|
|
25
|
+
private destroyed;
|
|
26
|
+
constructor(options: SemiWordSDKOptions);
|
|
27
|
+
private render;
|
|
28
|
+
private requireRef;
|
|
29
|
+
/** 更新 props 并重渲染;改 documentId 触发重挂载。 */
|
|
30
|
+
update(patch: SemiWordSDKUpdateOptions): void;
|
|
31
|
+
/** 卸载编辑器并释放 root;销毁后实例不可再用。 */
|
|
32
|
+
destroy(): void;
|
|
33
|
+
getHTML(): string;
|
|
34
|
+
getJSON(): ReturnType<EditorRef['getJSON']>;
|
|
35
|
+
getText(): string;
|
|
36
|
+
getSnapshot(): SemiWordDocumentSnapshot;
|
|
37
|
+
setContent(html: string): ReturnType<EditorRef['setContent']>;
|
|
38
|
+
clear(): ReturnType<EditorRef['clear']>;
|
|
39
|
+
focus(): void;
|
|
40
|
+
setEditable(editable: boolean): void;
|
|
41
|
+
getEditorElement(): HTMLElement | null;
|
|
42
|
+
getEditor(): EditorRef['editor'];
|
|
43
|
+
getYDoc(): ReturnType<EditorRef['getYDoc']>;
|
|
44
|
+
applyTemplate(request: Parameters<EditorRef['applyTemplate']>[0]): ReturnType<EditorRef['applyTemplate']>;
|
|
45
|
+
validateTemplate(): ReturnType<EditorRef['validateTemplate']>;
|
|
46
|
+
focusTemplateBlock(blockId: string): ReturnType<EditorRef['focusTemplateBlock']>;
|
|
47
|
+
getBlockAttributes(query: Parameters<EditorRef['getBlockAttributes']>[0]): ReturnType<EditorRef['getBlockAttributes']>;
|
|
48
|
+
updateBlockAttributes(query: Parameters<EditorRef['updateBlockAttributes']>[0], attrs: Parameters<EditorRef['updateBlockAttributes']>[1]): ReturnType<EditorRef['updateBlockAttributes']>;
|
|
49
|
+
getAiCommands(): ReturnType<EditorRef['getAiCommands']>;
|
|
50
|
+
insertBlocksAt(position: Parameters<EditorRef['insertBlocksAt']>[0], html: string): ReturnType<EditorRef['insertBlocksAt']>;
|
|
51
|
+
removeBlock(blockId?: string): ReturnType<EditorRef['removeBlock']>;
|
|
52
|
+
insertDiagram(spec: Parameters<EditorRef['insertDiagram']>[0], position?: Parameters<EditorRef['insertDiagram']>[1]): ReturnType<EditorRef['insertDiagram']>;
|
|
53
|
+
applyMarksToRange(blockId: Parameters<EditorRef['applyMarksToRange']>[0], target: Parameters<EditorRef['applyMarksToRange']>[1], marks: Parameters<EditorRef['applyMarksToRange']>[2]): ReturnType<EditorRef['applyMarksToRange']>;
|
|
54
|
+
fillSlot(target: Parameters<EditorRef['fillSlot']>[0], value: string): ReturnType<EditorRef['fillSlot']>;
|
|
55
|
+
tableOps(blockId: Parameters<EditorRef['tableOps']>[0], op: Parameters<EditorRef['tableOps']>[1], coords?: Parameters<EditorRef['tableOps']>[2]): ReturnType<EditorRef['tableOps']>;
|
|
56
|
+
getOutlineItems(): ReturnType<EditorRef['getOutlineItems']>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { SemiWordSDK };
|
|
60
|
+
export type { SemiWordSDKOptions, SemiWordSDKUpdateOptions };
|
package/dist-lib/sdk.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createDocumentSnapshot } from './chunk-QWDJU3H7.mjs';
|
|
2
|
+
import { RichEditor } from './chunk-GGIOCI2I.mjs';
|
|
3
|
+
import './chunk-BBZ5ZBEK.mjs';
|
|
4
|
+
import './chunk-K7Z56Q4M.mjs';
|
|
5
|
+
import './chunk-ZM3WULHX.mjs';
|
|
6
|
+
import './chunk-4W6PPBHQ.mjs';
|
|
7
|
+
import './chunk-EOUNN3NA.mjs';
|
|
8
|
+
import './chunk-W627LLF4.mjs';
|
|
9
|
+
import './chunk-CREU4TZJ.mjs';
|
|
10
|
+
import { createElement } from 'react';
|
|
11
|
+
import { createRoot } from 'react-dom/client';
|
|
12
|
+
|
|
13
|
+
var SemiWordSDK = class {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.editorRef = null;
|
|
16
|
+
this.destroyed = false;
|
|
17
|
+
const { container, ...editorProps } = options;
|
|
18
|
+
const element = typeof container === "string" ? document.querySelector(container) : container;
|
|
19
|
+
if (!element) {
|
|
20
|
+
throw new Error(`[SemiWordSDK] \u6302\u8F7D\u5BB9\u5668\u4E0D\u5B58\u5728: ${String(container)}`);
|
|
21
|
+
}
|
|
22
|
+
this.editorProps = editorProps;
|
|
23
|
+
this.ready = new Promise((resolve) => {
|
|
24
|
+
this.resolveReady = resolve;
|
|
25
|
+
});
|
|
26
|
+
this.root = createRoot(element);
|
|
27
|
+
this.render();
|
|
28
|
+
}
|
|
29
|
+
render() {
|
|
30
|
+
this.root.render(
|
|
31
|
+
createElement(RichEditor, {
|
|
32
|
+
...this.editorProps,
|
|
33
|
+
// documentId 变化即重挂载:content 仅为初始值,与组件用法口径一致
|
|
34
|
+
key: this.editorProps.documentId ?? "semiword-sdk",
|
|
35
|
+
ref: (ref) => {
|
|
36
|
+
this.editorRef = ref;
|
|
37
|
+
if (ref) this.resolveReady(ref);
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
requireRef() {
|
|
43
|
+
if (this.destroyed) throw new Error("[SemiWordSDK] \u5B9E\u4F8B\u5DF2\u9500\u6BC1");
|
|
44
|
+
if (!this.editorRef) throw new Error("[SemiWordSDK] \u7F16\u8F91\u5668\u672A\u5C31\u7EEA\uFF0C\u8BF7\u5148 await sdk.ready");
|
|
45
|
+
return this.editorRef;
|
|
46
|
+
}
|
|
47
|
+
/** 更新 props 并重渲染;改 documentId 触发重挂载。 */
|
|
48
|
+
update(patch) {
|
|
49
|
+
if (this.destroyed) throw new Error("[SemiWordSDK] \u5B9E\u4F8B\u5DF2\u9500\u6BC1");
|
|
50
|
+
this.editorProps = { ...this.editorProps, ...patch };
|
|
51
|
+
this.render();
|
|
52
|
+
}
|
|
53
|
+
/** 卸载编辑器并释放 root;销毁后实例不可再用。 */
|
|
54
|
+
destroy() {
|
|
55
|
+
if (this.destroyed) return;
|
|
56
|
+
this.destroyed = true;
|
|
57
|
+
this.root.unmount();
|
|
58
|
+
this.editorRef = null;
|
|
59
|
+
}
|
|
60
|
+
getHTML() {
|
|
61
|
+
return this.requireRef().getHTML();
|
|
62
|
+
}
|
|
63
|
+
getJSON() {
|
|
64
|
+
return this.requireRef().getJSON();
|
|
65
|
+
}
|
|
66
|
+
getText() {
|
|
67
|
+
return this.requireRef().getText();
|
|
68
|
+
}
|
|
69
|
+
getSnapshot() {
|
|
70
|
+
const ref = this.requireRef();
|
|
71
|
+
return createDocumentSnapshot(ref.getJSON(), ref.getHTML());
|
|
72
|
+
}
|
|
73
|
+
setContent(html) {
|
|
74
|
+
return this.requireRef().setContent(html);
|
|
75
|
+
}
|
|
76
|
+
clear() {
|
|
77
|
+
return this.requireRef().clear();
|
|
78
|
+
}
|
|
79
|
+
focus() {
|
|
80
|
+
this.requireRef().focus();
|
|
81
|
+
}
|
|
82
|
+
setEditable(editable) {
|
|
83
|
+
this.requireRef().setEditable(editable);
|
|
84
|
+
}
|
|
85
|
+
getEditorElement() {
|
|
86
|
+
return this.requireRef().getEditorElement();
|
|
87
|
+
}
|
|
88
|
+
getEditor() {
|
|
89
|
+
return this.editorRef?.editor ?? null;
|
|
90
|
+
}
|
|
91
|
+
getYDoc() {
|
|
92
|
+
return this.requireRef().getYDoc();
|
|
93
|
+
}
|
|
94
|
+
applyTemplate(request) {
|
|
95
|
+
return this.requireRef().applyTemplate(request);
|
|
96
|
+
}
|
|
97
|
+
validateTemplate() {
|
|
98
|
+
return this.requireRef().validateTemplate();
|
|
99
|
+
}
|
|
100
|
+
focusTemplateBlock(blockId) {
|
|
101
|
+
return this.requireRef().focusTemplateBlock(blockId);
|
|
102
|
+
}
|
|
103
|
+
getBlockAttributes(query) {
|
|
104
|
+
return this.requireRef().getBlockAttributes(query);
|
|
105
|
+
}
|
|
106
|
+
updateBlockAttributes(query, attrs) {
|
|
107
|
+
return this.requireRef().updateBlockAttributes(query, attrs);
|
|
108
|
+
}
|
|
109
|
+
getAiCommands() {
|
|
110
|
+
return this.requireRef().getAiCommands();
|
|
111
|
+
}
|
|
112
|
+
insertBlocksAt(position, html) {
|
|
113
|
+
return this.requireRef().insertBlocksAt(position, html);
|
|
114
|
+
}
|
|
115
|
+
removeBlock(blockId) {
|
|
116
|
+
return this.requireRef().removeBlock(blockId);
|
|
117
|
+
}
|
|
118
|
+
insertDiagram(spec, position) {
|
|
119
|
+
return this.requireRef().insertDiagram(spec, position);
|
|
120
|
+
}
|
|
121
|
+
applyMarksToRange(blockId, target, marks) {
|
|
122
|
+
return this.requireRef().applyMarksToRange(blockId, target, marks);
|
|
123
|
+
}
|
|
124
|
+
fillSlot(target, value) {
|
|
125
|
+
return this.requireRef().fillSlot(target, value);
|
|
126
|
+
}
|
|
127
|
+
tableOps(blockId, op, coords) {
|
|
128
|
+
return this.requireRef().tableOps(blockId, op, coords);
|
|
129
|
+
}
|
|
130
|
+
getOutlineItems() {
|
|
131
|
+
return this.requireRef().getOutlineItems();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export { SemiWordSDK };
|
|
136
|
+
//# sourceMappingURL=sdk.mjs.map
|
|
137
|
+
//# sourceMappingURL=sdk.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editor/sdk.ts"],"names":[],"mappings":";;;;;;;;;;;;AAmBO,IAAM,cAAN,MAAkB;AAAA,EAUvB,YAAY,OAAA,EAA6B;AAJzC,IAAA,IAAA,CAAQ,SAAA,GAA8B,IAAA;AAEtC,IAAA,IAAA,CAAQ,SAAA,GAAY,KAAA;AAGlB,IAAA,MAAM,EAAE,SAAA,EAAW,GAAG,WAAA,EAAY,GAAI,OAAA;AACtC,IAAA,MAAM,UAAU,OAAO,SAAA,KAAc,WAAW,QAAA,CAAS,aAAA,CAA2B,SAAS,CAAA,GAAI,SAAA;AACjG,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,0DAAA,EAA0B,MAAA,CAAO,SAAS,CAAC,CAAA,CAAE,CAAA;AAAA,IAC/D;AACA,IAAA,IAAA,CAAK,WAAA,GAAc,WAAA;AACnB,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,OAAA,CAAmB,CAAA,OAAA,KAAW;AAC7C,MAAA,IAAA,CAAK,YAAA,GAAe,OAAA;AAAA,IACtB,CAAC,CAAA;AACD,IAAA,I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;AAAA,EACjD;AAAA,EAEA,QAAA,CACE,OAAA,EACA,EAAA,EACA,MAAA,EACmC;AACnC,IAAA,OAAO,KAAK,UAAA,EAAW,CAAE,QAAA,CAAS,OAAA,EAAS,IAAI,MAAM,CAAA;AAAA,EACvD;AAAA,EAEA,eAAA,GAA4D;AAC1D,IAAA,OAAO,IAAA,CAAK,UAAA,EAAW,CAAE,eAAA,EAAgB;AAAA,EAC3C;AACF","file":"sdk.mjs","sourcesContent":["import { createElement } from 'react';\nimport { createRoot, type Root } from 'react-dom/client';\nimport { RichEditor } from './core/components/RichEditor';\nimport { createDocumentSnapshot } from './document';\nimport type { SemiWordDocumentSnapshot } from './document';\nimport type { EditorRef, RichEditorProps } from './core/types';\n\n/** 命令式挂载配置:RichEditor 全部 props + 挂载容器。 */\nexport interface SemiWordSDKOptions extends RichEditorProps {\n /** 挂载容器:DOM 元素或 CSS 选择器。 */\n container: HTMLElement | string;\n}\n\nexport type SemiWordSDKUpdateOptions = Partial<Omit<SemiWordSDKOptions, 'container'>>;\n\n/**\n * 命令式 facade(`new SDK()` 形态):内部经 createRoot 挂载 RichEditor,\n * 与 React 组件用法共享同一核心;面向非 React 页面或命令式集成场景。\n */\nexport class SemiWordSDK {\n /** 编辑器就绪后 resolve;方法调用前建议 await sdk.ready。 */\n readonly ready: Promise<EditorRef>;\n\n private root: Root;\n private editorProps: RichEditorProps;\n private editorRef: EditorRef | null = null;\n private resolveReady!: (ref: EditorRef) => void;\n private destroyed = false;\n\n constructor(options: SemiWordSDKOptions) {\n const { container, ...editorProps } = options;\n const element = typeof container === 'string' ? document.querySelector<HTMLElement>(container) : container;\n if (!element) {\n throw new Error(`[SemiWordSDK] 挂载容器不存在: ${String(container)}`);\n }\n this.editorProps = editorProps;\n this.ready = new Promise<EditorRef>(resolve => {\n this.resolveReady = resolve;\n });\n this.root = createRoot(element);\n this.render();\n }\n\n private render(): void {\n this.root.render(\n createElement(RichEditor, {\n ...this.editorProps,\n // documentId 变化即重挂载:content 仅为初始值,与组件用法口径一致\n key: this.editorProps.documentId ?? 'semiword-sdk',\n ref: (ref: EditorRef | null) => {\n this.editorRef = ref;\n if (ref) this.resolveReady(ref);\n },\n })\n );\n }\n\n private requireRef(): EditorRef {\n if (this.destroyed) throw new Error('[SemiWordSDK] 实例已销毁');\n if (!this.editorRef) throw new Error('[SemiWordSDK] 编辑器未就绪,请先 await sdk.ready');\n return this.editorRef;\n }\n\n /** 更新 props 并重渲染;改 documentId 触发重挂载。 */\n update(patch: SemiWordSDKUpdateOptions): void {\n if (this.destroyed) throw new Error('[SemiWordSDK] 实例已销毁');\n this.editorProps = { ...this.editorProps, ...patch };\n this.render();\n }\n\n /** 卸载编辑器并释放 root;销毁后实例不可再用。 */\n destroy(): void {\n if (this.destroyed) return;\n this.destroyed = true;\n this.root.unmount();\n this.editorRef = null;\n }\n\n getHTML(): string {\n return this.requireRef().getHTML();\n }\n\n getJSON(): ReturnType<EditorRef['getJSON']> {\n return this.requireRef().getJSON();\n }\n\n getText(): string {\n return this.requireRef().getText();\n }\n\n getSnapshot(): SemiWordDocumentSnapshot {\n const ref = this.requireRef();\n return createDocumentSnapshot(ref.getJSON(), ref.getHTML());\n }\n\n setContent(html: string): ReturnType<EditorRef['setContent']> {\n return this.requireRef().setContent(html);\n }\n\n clear(): ReturnType<EditorRef['clear']> {\n return this.requireRef().clear();\n }\n\n focus(): void {\n this.requireRef().focus();\n }\n\n setEditable(editable: boolean): void {\n this.requireRef().setEditable(editable);\n }\n\n getEditorElement(): HTMLElement | null {\n return this.requireRef().getEditorElement();\n }\n\n getEditor(): EditorRef['editor'] {\n return this.editorRef?.editor ?? null;\n }\n\n getYDoc(): ReturnType<EditorRef['getYDoc']> {\n return this.requireRef().getYDoc();\n }\n\n applyTemplate(request: Parameters<EditorRef['applyTemplate']>[0]): ReturnType<EditorRef['applyTemplate']> {\n return this.requireRef().applyTemplate(request);\n }\n\n validateTemplate(): ReturnType<EditorRef['validateTemplate']> {\n return this.requireRef().validateTemplate();\n }\n\n focusTemplateBlock(blockId: string): ReturnType<EditorRef['focusTemplateBlock']> {\n return this.requireRef().focusTemplateBlock(blockId);\n }\n\n getBlockAttributes(\n query: Parameters<EditorRef['getBlockAttributes']>[0]\n ): ReturnType<EditorRef['getBlockAttributes']> {\n return this.requireRef().getBlockAttributes(query);\n }\n\n updateBlockAttributes(\n query: Parameters<EditorRef['updateBlockAttributes']>[0],\n attrs: Parameters<EditorRef['updateBlockAttributes']>[1]\n ): ReturnType<EditorRef['updateBlockAttributes']> {\n return this.requireRef().updateBlockAttributes(query, attrs);\n }\n\n getAiCommands(): ReturnType<EditorRef['getAiCommands']> {\n return this.requireRef().getAiCommands();\n }\n\n insertBlocksAt(\n position: Parameters<EditorRef['insertBlocksAt']>[0],\n html: string\n ): ReturnType<EditorRef['insertBlocksAt']> {\n return this.requireRef().insertBlocksAt(position, html);\n }\n\n removeBlock(blockId?: string): ReturnType<EditorRef['removeBlock']> {\n return this.requireRef().removeBlock(blockId);\n }\n\n insertDiagram(\n spec: Parameters<EditorRef['insertDiagram']>[0],\n position?: Parameters<EditorRef['insertDiagram']>[1]\n ): ReturnType<EditorRef['insertDiagram']> {\n return this.requireRef().insertDiagram(spec, position);\n }\n\n applyMarksToRange(\n blockId: Parameters<EditorRef['applyMarksToRange']>[0],\n target: Parameters<EditorRef['applyMarksToRange']>[1],\n marks: Parameters<EditorRef['applyMarksToRange']>[2]\n ): ReturnType<EditorRef['applyMarksToRange']> {\n return this.requireRef().applyMarksToRange(blockId, target, marks);\n }\n\n fillSlot(target: Parameters<EditorRef['fillSlot']>[0], value: string): ReturnType<EditorRef['fillSlot']> {\n return this.requireRef().fillSlot(target, value);\n }\n\n tableOps(\n blockId: Parameters<EditorRef['tableOps']>[0],\n op: Parameters<EditorRef['tableOps']>[1],\n coords?: Parameters<EditorRef['tableOps']>[2]\n ): ReturnType<EditorRef['tableOps']> {\n return this.requireRef().tableOps(blockId, op, coords);\n }\n\n getOutlineItems(): ReturnType<EditorRef['getOutlineItems']> {\n return this.requireRef().getOutlineItems();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"shapes-5SMSF6ML.mjs"}
|