@dajiaoai/algeo-sdk 1.2.1 → 2.4.2
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/README.md +262 -42
- package/dist/algeo-sdk.cjs.js +470 -83
- package/dist/algeo-sdk.esm.js +466 -84
- package/dist/algeo-sdk.umd.js +470 -83
- package/dist/embedded-editor.d.ts +27 -0
- package/dist/embedded-presentation.d.ts +15 -0
- package/dist/embedded-target.d.ts +33 -0
- package/dist/index.d.ts +6 -75
- package/dist/sdk.d.ts +22 -0
- package/dist/shared.d.ts +171 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
npm install @dajiaoai/algeo-sdk
|
|
12
12
|
|
|
13
13
|
# 安装指定版本(推荐生产环境锁定版本)
|
|
14
|
-
npm install @dajiaoai/algeo-sdk@
|
|
14
|
+
npm install @dajiaoai/algeo-sdk@2.0.0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
在 `package.json` 中:
|
|
@@ -19,7 +19,7 @@ npm install @dajiaoai/algeo-sdk@1.2.1
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dajiaoai/algeo-sdk": "
|
|
22
|
+
"@dajiaoai/algeo-sdk": "2.0.0" // 精确版本,生产推荐
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
|
@@ -29,7 +29,7 @@ npm install @dajiaoai/algeo-sdk@1.2.1
|
|
|
29
29
|
```json
|
|
30
30
|
{
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dajiaoai/algeo-sdk": "^
|
|
32
|
+
"@dajiaoai/algeo-sdk": "^2.0.0" // 兼容 2.x 的更新
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
@@ -39,14 +39,14 @@ npm install @dajiaoai/algeo-sdk@1.2.1
|
|
|
39
39
|
**unpkg**:
|
|
40
40
|
|
|
41
41
|
```html
|
|
42
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@
|
|
42
|
+
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.0.0/dist/algeo-sdk.umd.js"></script>
|
|
43
43
|
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
**jsDelivr**:
|
|
47
47
|
|
|
48
48
|
```html
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.0.0/dist/algeo-sdk.umd.js"></script>
|
|
50
50
|
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -54,31 +54,28 @@ npm install @dajiaoai/algeo-sdk@1.2.1
|
|
|
54
54
|
|
|
55
55
|
## 使用方式
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### 方式一:演示模式
|
|
58
58
|
|
|
59
59
|
```javascript
|
|
60
|
-
import {
|
|
60
|
+
import { createPresentation } from '@dajiaoai/algeo-sdk';
|
|
61
61
|
|
|
62
62
|
const container = document.getElementById('algeo-container');
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
initialId: '33TA3484', // 可选,初始加载的分享 ID
|
|
63
|
+
const presentation = await createPresentation(container, {
|
|
64
|
+
shareId: '33TA3484',
|
|
66
65
|
});
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (e.data?.type === 'ready') {
|
|
71
|
-
console.log('内嵌页就绪', e.data.version);
|
|
72
|
-
}
|
|
67
|
+
presentation.on('ready', (event) => {
|
|
68
|
+
console.log('演示模式已就绪', event.version);
|
|
73
69
|
});
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
presentation.loadShareById('33TA3484').then(() => console.log('加载成功'));
|
|
72
|
+
presentation
|
|
73
|
+
.getSlideCount()
|
|
74
|
+
.then(({ count }) => console.log('画板数量:', count));
|
|
75
|
+
presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
79
76
|
|
|
80
77
|
// 销毁
|
|
81
|
-
//
|
|
78
|
+
// presentation.destroy();
|
|
82
79
|
```
|
|
83
80
|
|
|
84
81
|
### 方式二:直接 iframe(无 SDK)
|
|
@@ -97,6 +94,79 @@ sdk.switchSlide(1).then(() => console.log('切换画板'));
|
|
|
97
94
|
|
|
98
95
|
> **全屏支持**:建议在 iframe 上添加 `allow="fullscreen"`,以便内嵌画板使用全屏功能。SDK 方式创建的 iframe 已自动包含此属性。
|
|
99
96
|
|
|
97
|
+
### 方式三:编辑模式
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import { createEditor } from '@dajiaoai/algeo-sdk';
|
|
101
|
+
|
|
102
|
+
const editor = await createEditor(document.getElementById('editor-root'), {
|
|
103
|
+
auth: {
|
|
104
|
+
appId: 'xxxx',
|
|
105
|
+
},
|
|
106
|
+
initialContent,
|
|
107
|
+
ui: {
|
|
108
|
+
navbar: true,
|
|
109
|
+
slidePanel: true,
|
|
110
|
+
toolboxPanel: true,
|
|
111
|
+
algebraPanel: false,
|
|
112
|
+
docPanel: false,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
editor.on('ready', (event) => {
|
|
117
|
+
console.log('iframe 已完成初始化', event);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
editor.on('contentChange', (event) => {
|
|
121
|
+
console.log('用户编辑后返回完整内容', event.content);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
editor.on('slideChange', (event) => {
|
|
125
|
+
console.log('用户切换后的最新画板索引', event.index);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
editor.on('save', async (event) => {
|
|
129
|
+
if (event.stage === 'request') {
|
|
130
|
+
const response = await fetch('/api/geometry-doc/save', {
|
|
131
|
+
method: 'POST',
|
|
132
|
+
headers: { 'Content-Type': 'application/json' },
|
|
133
|
+
body: JSON.stringify({
|
|
134
|
+
content: event.content,
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!response.ok) {
|
|
139
|
+
return {
|
|
140
|
+
status: 'error',
|
|
141
|
+
message: '保存失败',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
status: 'success',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
console.log('用户点击保存按钮且宿主返回成功后的完整内容', event.content);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
编辑器内嵌页点击保存按钮时,会触发 `editor.on('save', listener)` 的请求阶段监听器。只有宿主返回 `{ status: 'success' }` 后,iframe 才会展示成功态,并向外触发 `save` 的成功阶段事件。
|
|
155
|
+
|
|
156
|
+
如需通过统一入口分发模式,也可以使用 `create`:
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
import { create } from '@dajiaoai/algeo-sdk';
|
|
160
|
+
|
|
161
|
+
const editor = await create(document.getElementById('editor-root'), {
|
|
162
|
+
mode: 'editor',
|
|
163
|
+
editor: {
|
|
164
|
+
auth: { appId: 'xxxx' },
|
|
165
|
+
initialContent,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
100
170
|
## API
|
|
101
171
|
|
|
102
172
|
### 常量
|
|
@@ -112,35 +182,103 @@ console.log('Algeo SDK version:', VERSION);
|
|
|
112
182
|
|
|
113
183
|
---
|
|
114
184
|
|
|
115
|
-
###
|
|
185
|
+
### 入口函数
|
|
186
|
+
|
|
187
|
+
#### `create(container, options): Promise<EmbeddedEditor | EmbeddedPresentation>`
|
|
188
|
+
|
|
189
|
+
统一入口,按 `mode` 分发到具体实例:
|
|
190
|
+
|
|
191
|
+
- `mode: 'editor'` -> `EmbeddedEditor`
|
|
192
|
+
- `mode: 'presentation'` -> `EmbeddedPresentation`
|
|
193
|
+
|
|
194
|
+
#### `createEditor(container, options): Promise<EmbeddedEditor>`
|
|
195
|
+
|
|
196
|
+
编辑模式快捷入口。该函数负责真正创建并初始化 `EmbeddedEditor`。
|
|
197
|
+
|
|
198
|
+
该快捷入口不暴露 `baseUrl` 配置。如需自定义宿主地址,请使用统一入口 `create(container, { mode: 'editor', baseUrl, editor: options })`。
|
|
116
199
|
|
|
117
|
-
|
|
200
|
+
```javascript
|
|
201
|
+
create(container, {
|
|
202
|
+
mode: 'editor',
|
|
203
|
+
baseUrl: 'https://your-host.example',
|
|
204
|
+
editor: options,
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### `createPresentation(container, options): Promise<EmbeddedPresentation>`
|
|
209
|
+
|
|
210
|
+
演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
create(container, {
|
|
214
|
+
mode: 'presentation',
|
|
215
|
+
baseUrl: 'https://your-host.example',
|
|
216
|
+
presentation: options,
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### `create(container, options)`
|
|
221
|
+
|
|
222
|
+
异步创建并初始化具体实例。在 iframe 加载完成并收到 ready 消息后 resolve;若 30 秒内未收到 ready,则会以 `TIMEOUT` 错误 reject。
|
|
223
|
+
|
|
224
|
+
| 参数 | 类型 | 说明 |
|
|
225
|
+
| ----------- | -------------------- | ----------------------- |
|
|
226
|
+
| `container` | `HTMLElement` | 挂载 iframe 的 DOM 容器 |
|
|
227
|
+
| `options` | `AlgeoCreateOptions` | 创建配置 |
|
|
228
|
+
|
|
229
|
+
**AlgeoCreateOptions:**
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
type AlgeoCreateOptions =
|
|
233
|
+
| {
|
|
234
|
+
baseUrl?: string;
|
|
235
|
+
mode: 'editor';
|
|
236
|
+
editor: AlgeoEditorCreateOptions;
|
|
237
|
+
}
|
|
238
|
+
| {
|
|
239
|
+
baseUrl?: string;
|
|
240
|
+
mode: 'presentation';
|
|
241
|
+
presentation: AlgeoPresentationCreateOptions;
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**AlgeoEditorCreateOptions:**
|
|
246
|
+
|
|
247
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
248
|
+
| ---------------- | ------------------------------ | ------ | ------------------------------------------------------ |
|
|
249
|
+
| `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
|
|
250
|
+
| `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
|
|
251
|
+
| `initialContent` | `FileContentV10` | - | 初始化后自动注入的文件内容 |
|
|
252
|
+
| `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
|
|
118
253
|
|
|
119
|
-
|
|
254
|
+
**AlgeoPresentationCreateOptions:**
|
|
120
255
|
|
|
121
|
-
|
|
|
122
|
-
|
|
|
123
|
-
| `
|
|
124
|
-
| `options` | `AlgeoSdkOptions` | 可选配置 |
|
|
256
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
257
|
+
| --------- | -------- | ------ | -------------------------------------- |
|
|
258
|
+
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/e/:id` |
|
|
125
259
|
|
|
126
|
-
|
|
260
|
+
默认路径规则:
|
|
127
261
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| `baseUrl` | `string` | `https://dajiaoai.com` | 内嵌页基础 URL |
|
|
131
|
-
| `initialId` | `string` | `''` | 初始加载的分享 ID,为空则加载空白画板 |
|
|
262
|
+
- `mode: 'presentation'` -> `/e`,若传 `presentation.shareId` 则生成 `/e/:id`
|
|
263
|
+
- `mode: 'editor'` -> `/embed/edit/:appId`,其中 `:appId` 来自 `editor.auth.appId`;若传 `editor.shareId` 则生成 `/embed/edit/:appId/:id`
|
|
132
264
|
|
|
133
265
|
**示例:**
|
|
134
266
|
|
|
135
267
|
```javascript
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
268
|
+
const presentation = await create(container, {
|
|
269
|
+
mode: 'presentation',
|
|
270
|
+
presentation: {
|
|
271
|
+
shareId: '33TA3484',
|
|
272
|
+
},
|
|
139
273
|
});
|
|
140
274
|
```
|
|
141
275
|
|
|
142
276
|
---
|
|
143
277
|
|
|
278
|
+
### 类 `EmbeddedPresentation`
|
|
279
|
+
|
|
280
|
+
演示模式实例,保留当前已上线的 iframe 能力。
|
|
281
|
+
|
|
144
282
|
#### 实例属性(只读)
|
|
145
283
|
|
|
146
284
|
| 属性 | 类型 | 说明 |
|
|
@@ -148,11 +286,21 @@ const sdk = await AlgeoSdk.create(container, {
|
|
|
148
286
|
| `ready` | `boolean` | 是否已就绪(收到 iframe ready 通知) |
|
|
149
287
|
| `version` | `string \| null` | 内嵌页协议版本 |
|
|
150
288
|
|
|
289
|
+
#### 事件订阅
|
|
290
|
+
|
|
291
|
+
##### `presentation.on(event, listener): () => void`
|
|
292
|
+
|
|
293
|
+
当前稳定提供以下事件:
|
|
294
|
+
|
|
295
|
+
| 事件名 | 说明 |
|
|
296
|
+
| ------- | ----------------- |
|
|
297
|
+
| `ready` | iframe 完成初始化 |
|
|
298
|
+
|
|
151
299
|
---
|
|
152
300
|
|
|
153
301
|
#### 实例方法
|
|
154
302
|
|
|
155
|
-
##### `
|
|
303
|
+
##### `presentation.loadShareById(id: string): Promise<LoadShareByIdResult>`
|
|
156
304
|
|
|
157
305
|
按分享 ID 加载内容。
|
|
158
306
|
|
|
@@ -164,7 +312,7 @@ const sdk = await AlgeoSdk.create(container, {
|
|
|
164
312
|
|
|
165
313
|
---
|
|
166
314
|
|
|
167
|
-
##### `
|
|
315
|
+
##### `presentation.loadFile(content: FileContent): Promise<LoadFileResult>`
|
|
168
316
|
|
|
169
317
|
加载完整文件数据(覆盖式),需符合 FileContentV10 格式。
|
|
170
318
|
|
|
@@ -189,7 +337,7 @@ interface FileContent {
|
|
|
189
337
|
|
|
190
338
|
---
|
|
191
339
|
|
|
192
|
-
##### `
|
|
340
|
+
##### `presentation.getSlideCount(): Promise<GetSlideCountResult>`
|
|
193
341
|
|
|
194
342
|
查询当前画板数量。
|
|
195
343
|
|
|
@@ -197,7 +345,7 @@ interface FileContent {
|
|
|
197
345
|
|
|
198
346
|
---
|
|
199
347
|
|
|
200
|
-
##### `
|
|
348
|
+
##### `presentation.switchSlide(index: number): Promise<SwitchSlideResult>`
|
|
201
349
|
|
|
202
350
|
切换到指定索引的画板(索引从 0 开始)。
|
|
203
351
|
|
|
@@ -209,7 +357,7 @@ interface FileContent {
|
|
|
209
357
|
|
|
210
358
|
---
|
|
211
359
|
|
|
212
|
-
##### `
|
|
360
|
+
##### `presentation.repl(command: string): Promise<ReplResult>`
|
|
213
361
|
|
|
214
362
|
执行 REPL 指令,返回面向 AI 的文档/文本内容。需先通过 `loadShareById` 或 `loadFile` 加载内容后,部分指令才有数据可查。
|
|
215
363
|
|
|
@@ -230,7 +378,78 @@ interface FileContent {
|
|
|
230
378
|
|
|
231
379
|
---
|
|
232
380
|
|
|
233
|
-
|
|
381
|
+
### 类 `EmbeddedEditor`
|
|
382
|
+
|
|
383
|
+
编辑模式实例不再暴露一组扁平方法,而是拆成 capability units。
|
|
384
|
+
|
|
385
|
+
#### 实例属性(只读)
|
|
386
|
+
|
|
387
|
+
| 属性 | 类型 | 说明 |
|
|
388
|
+
| ---------- | ------------- | ------------------------------------ |
|
|
389
|
+
| `ready` | `boolean` | 是否已就绪(收到 iframe ready 通知) |
|
|
390
|
+
| `version` | `string` | 内嵌页协议版本 |
|
|
391
|
+
| `document` | `DocumentApi` | 画板文件相关能力 |
|
|
392
|
+
| `slides` | `SlidesApi` | 多画板管理能力 |
|
|
393
|
+
| `history` | `HistoryApi` | 历史记录能力 |
|
|
394
|
+
| `mode` | `ModeApi` | 编辑器展示模式控制 |
|
|
395
|
+
|
|
396
|
+
#### `editor.document`
|
|
397
|
+
|
|
398
|
+
| 方法 | 说明 |
|
|
399
|
+
| ---------------------- | -------------------------------- |
|
|
400
|
+
| `loadContent(content)` | 加载完整画板文件内容 |
|
|
401
|
+
| `getContent()` | 异步获取 iframe 当前实时画板内容 |
|
|
402
|
+
|
|
403
|
+
#### `editor.slides`
|
|
404
|
+
|
|
405
|
+
| 方法 | 说明 |
|
|
406
|
+
| -------------------------------- | -------------------- |
|
|
407
|
+
| `getCount()` | 获取当前已知画板数量 |
|
|
408
|
+
| `getCurrentIndex()` | 获取当前已知画板索引 |
|
|
409
|
+
| `switchTo(index)` | 切换画板 |
|
|
410
|
+
| `add()` | 在末尾新增画板 |
|
|
411
|
+
| `addAt(index)` | 在指定位置新增画板 |
|
|
412
|
+
| `remove(index)` | 删除指定画板 |
|
|
413
|
+
| `duplicate(index, targetIndex?)` | 复制画板 |
|
|
414
|
+
| `reorder(fromIndex, toIndex)` | 重排画板 |
|
|
415
|
+
|
|
416
|
+
#### `editor.history`
|
|
417
|
+
|
|
418
|
+
| 方法 | 说明 |
|
|
419
|
+
| ------------------- | -------------------- |
|
|
420
|
+
| `getCount()` | 获取当前已知历史步数 |
|
|
421
|
+
| `getCurrentIndex()` | 获取当前已知历史游标 |
|
|
422
|
+
| `undo()` | 撤销 |
|
|
423
|
+
| `redo()` | 重做 |
|
|
424
|
+
| `jumpTo(index)` | 跳转到指定历史位置 |
|
|
425
|
+
| `canUndo()` | 判断是否可撤销 |
|
|
426
|
+
| `canRedo()` | 判断是否可重做 |
|
|
427
|
+
| `clear()` | 清空历史 |
|
|
428
|
+
|
|
429
|
+
#### `editor.mode`
|
|
430
|
+
|
|
431
|
+
| 方法 | 说明 |
|
|
432
|
+
| --------------------- | ---------------- |
|
|
433
|
+
| `getUiConfig()` | 获取当前 UI 配置 |
|
|
434
|
+
| `setUiConfig(config)` | 更新 UI 配置 |
|
|
435
|
+
|
|
436
|
+
#### 编辑器事件
|
|
437
|
+
|
|
438
|
+
`editor.on(event, listener)` 当前支持以下事件:
|
|
439
|
+
|
|
440
|
+
| 事件名 | 事件数据 | 说明 |
|
|
441
|
+
| --------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
442
|
+
| `ready` | `{ type: 'ready', mode, version }` | iframe 初始化完成 |
|
|
443
|
+
| `contentChange` | `{ type: 'contentChange', source: 'user', content }` | 用户在 iframe 内编辑后回传完整 `FileContentV10` |
|
|
444
|
+
| `slideChange` | `{ type: 'slideChange', index }` | 用户在 iframe 内切换画板后回传当前索引 |
|
|
445
|
+
| `save` | `{ type: 'save', stage: 'request' \| 'success', content }` | `stage: 'request'` 时用于宿主处理保存,`stage: 'success'` 时表示保存成功后的通知 |
|
|
446
|
+
|
|
447
|
+
#### 事件与销毁
|
|
448
|
+
|
|
449
|
+
- `editor.on(event, listener)` / `editor.off(event, listener)`
|
|
450
|
+
- `editor.destroy(): Promise<void>`
|
|
451
|
+
|
|
452
|
+
##### `presentation.destroy(): Promise<void>`
|
|
234
453
|
|
|
235
454
|
销毁实例,移除 iframe 与事件监听,并拒绝所有未完成的 pending 请求。
|
|
236
455
|
|
|
@@ -255,6 +474,7 @@ try {
|
|
|
255
474
|
| 错误码 | 说明 |
|
|
256
475
|
| ------------------ | --------------------------- |
|
|
257
476
|
| `IFRAME_NOT_READY` | iframe 未加载完成即调用方法 |
|
|
258
|
-
| `TIMEOUT` |
|
|
477
|
+
| `TIMEOUT` | 请求或初始化超时(30 秒) |
|
|
259
478
|
| `DESTROYED` | SDK 已销毁 |
|
|
479
|
+
| `MISSING_APP_ID` | 编辑模式缺少 `auth.appId` |
|
|
260
480
|
| `BAD_REQUEST` | 非法请求(如重复 init) |
|