@dajiaoai/algeo-sdk 2.15.1 → 2.15.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 +21 -1
- package/dist/algeo-sdk.cjs.js +86 -2
- package/dist/algeo-sdk.esm.js +86 -2
- package/dist/algeo-sdk.umd.js +86 -2
- package/dist/embedded-editor.d.ts +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/master-templates.d.ts +3 -0
- package/dist/shared.d.ts +25 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
|
|
4
4
|
|
|
5
|
-
当前版本:**2.15.
|
|
5
|
+
当前版本:**2.15.2**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.15.2)。
|
|
6
6
|
|
|
7
7
|
## 交流与支持
|
|
8
8
|
|
|
@@ -232,6 +232,24 @@ const editor = await createEditor(document.getElementById('editor-root'), {
|
|
|
232
232
|
|
|
233
233
|
`query` 返回的资源必须具有非空且不重复的 `id`、非空 `name`、`image/*` MIME 类型和完整 HTTP(S) URL。`width`、`height`、`size` 如提供,必须是正整数。搜索条件变化、面板关闭或 SDK 销毁时,请求可能通过 `signal` 被取消。
|
|
234
234
|
|
|
235
|
+
### 接入自有系统母版列表
|
|
236
|
+
|
|
237
|
+
编辑模式支持系统母版列表、预览和应用。母版面板默认关闭,设置 `ui.masterTemplatePanel: true` 开启面板,并通过 `masterTemplates.listSystem` 提供列表数据。
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const editor = await sdk.createEditor(document.getElementById('editor')!, {
|
|
241
|
+
auth: { appId: 'your-app-id' },
|
|
242
|
+
ui: { masterTemplatePanel: true },
|
|
243
|
+
masterTemplates: {
|
|
244
|
+
listSystem: async () => myApi.listSystemTemplates(),
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
配置 `listSystem` 后显示「系统母版」Tab。未配置该回调时,面板显示「未配置母版数据源」。
|
|
250
|
+
|
|
251
|
+
`listSystem` 返回 `Promise<MasterTemplateItem[]>`,每项包含 `id: string`、`name: string`、`content: string`,以及可选的 `created_at: string`、`edited_at: string | null`。列表内 ID 必须唯一。`content` 为完整的母版 JSON 字符串,可来自宿主接口或本地数据。宿主负责认证与业务校验;回调抛出的错误消息会展示在编辑器中,请求超过 60 秒视为超时。
|
|
252
|
+
|
|
235
253
|
## API
|
|
236
254
|
|
|
237
255
|
### 常量
|
|
@@ -318,6 +336,7 @@ type AlgeoCreateOptions =
|
|
|
318
336
|
| `initialContent` | `FileContentAny` | - | 初始化后自动注入的文件内容;SDK 会自动转换为最新格式 |
|
|
319
337
|
| `initialMode` | `'2d' \| '3d'` | `'2d'` | 空白画板模式,仅在没有初始内容或分享文件时生效 |
|
|
320
338
|
| `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
|
|
339
|
+
| `masterTemplates` | `MasterTemplateCallbacks` | - | 只读系统母版列表回调 |
|
|
321
340
|
| `fonts` | `AlgeoFontConfig` | - | 字体资源、字体选择器列表及默认字体配置 |
|
|
322
341
|
|
|
323
342
|
初始化优先级:`initialContent` > `shareId` > 指定 `initialMode` 的空画板。提供 `initialContent` 时不会请求分享文件;加载已有内容时保留内容中的画板模式。
|
|
@@ -330,6 +349,7 @@ type AlgeoCreateOptions =
|
|
|
330
349
|
| `slidePanel` | `boolean` | - | 是否展示画板列表 |
|
|
331
350
|
| `toolboxPanel` | `boolean` | - | 是否展示工具栏 |
|
|
332
351
|
| `algebraPanel` | `boolean` | - | 是否展示代数面板 |
|
|
352
|
+
| `masterTemplatePanel` | `boolean` | `false` | 是否展示母版面板,需显式开启 |
|
|
333
353
|
| `docPanel` | `boolean` | - | 是否展示文档面板 |
|
|
334
354
|
| `helpEntry` | `boolean` | - | 是否展示帮助入口 |
|
|
335
355
|
| `aiChatPanel` | `boolean` | `false` | 是否展示 AI 对话面板 |
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
|
|
|
4011
4011
|
}
|
|
4012
4012
|
|
|
4013
4013
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4014
|
-
const VERSION = '2.15.
|
|
4014
|
+
const VERSION = '2.15.2';
|
|
4015
4015
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4016
4016
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4017
4017
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4137,6 +4137,19 @@ function buildEmbedSrc(options) {
|
|
|
4137
4137
|
? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
|
|
4138
4138
|
: src;
|
|
4139
4139
|
}
|
|
4140
|
+
const MASTER_TEMPLATE_OPERATIONS = [
|
|
4141
|
+
'listSystem',
|
|
4142
|
+
];
|
|
4143
|
+
function isMasterTemplateRequestMessage(msg) {
|
|
4144
|
+
if (!msg || typeof msg !== 'object')
|
|
4145
|
+
return false;
|
|
4146
|
+
const value = msg;
|
|
4147
|
+
return (value.type === 'masterTemplateRequest' &&
|
|
4148
|
+
typeof value.requestId === 'string' &&
|
|
4149
|
+
MASTER_TEMPLATE_OPERATIONS.includes(value.operation) &&
|
|
4150
|
+
Array.isArray(value.args) &&
|
|
4151
|
+
value.args.every((arg) => typeof arg === 'string'));
|
|
4152
|
+
}
|
|
4140
4153
|
|
|
4141
4154
|
class EmbeddedTarget {
|
|
4142
4155
|
constructor(container, embedMode) {
|
|
@@ -4298,7 +4311,8 @@ class EmbeddedTarget {
|
|
|
4298
4311
|
}
|
|
4299
4312
|
if ((isSaveRequestMessage(data) ||
|
|
4300
4313
|
isAiRequestMessage(data) ||
|
|
4301
|
-
isResourceLibraryRequestMessage(data)
|
|
4314
|
+
isResourceLibraryRequestMessage(data) ||
|
|
4315
|
+
isMasterTemplateRequestMessage(data)) &&
|
|
4302
4316
|
this.handleRequestMessage(data, iframe.contentWindow)) {
|
|
4303
4317
|
return;
|
|
4304
4318
|
}
|
|
@@ -4493,9 +4507,40 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4493
4507
|
}
|
|
4494
4508
|
}
|
|
4495
4509
|
|
|
4510
|
+
/** 校验 iframe 参数和宿主返回值,所有操作只调用已声明的宿主回调。 */
|
|
4511
|
+
async function executeMasterTemplateCallback(callbacks, operation, args) {
|
|
4512
|
+
if (operation !== 'listSystem' || !Array.isArray(args) || args.length !== 0) {
|
|
4513
|
+
throw new Error('无效的母版请求参数');
|
|
4514
|
+
}
|
|
4515
|
+
const callback = callbacks[operation];
|
|
4516
|
+
if (typeof callback !== 'function')
|
|
4517
|
+
throw new Error(`宿主未配置 masterTemplates.${operation}`);
|
|
4518
|
+
const result = await callback.call(callbacks);
|
|
4519
|
+
const ids = new Set();
|
|
4520
|
+
if (!Array.isArray(result) ||
|
|
4521
|
+
!result.every((item) => {
|
|
4522
|
+
if (!item ||
|
|
4523
|
+
typeof item.id !== 'string' ||
|
|
4524
|
+
!item.id.trim() ||
|
|
4525
|
+
ids.has(item.id) ||
|
|
4526
|
+
typeof item.name !== 'string' ||
|
|
4527
|
+
typeof item.content !== 'string' ||
|
|
4528
|
+
(item.created_at !== undefined &&
|
|
4529
|
+
typeof item.created_at !== 'string') ||
|
|
4530
|
+
(item.edited_at != null && typeof item.edited_at !== 'string'))
|
|
4531
|
+
return false;
|
|
4532
|
+
ids.add(item.id);
|
|
4533
|
+
return true;
|
|
4534
|
+
}))
|
|
4535
|
+
throw new Error('母版列表必须返回含唯一 id、name、content 的数组');
|
|
4536
|
+
return result;
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4496
4539
|
class EmbeddedEditor extends EmbeddedTarget {
|
|
4497
4540
|
constructor(container) {
|
|
4498
4541
|
super(container, 'editor');
|
|
4542
|
+
this.masterTemplates = {};
|
|
4543
|
+
this.masterTemplateRequests = new Set();
|
|
4499
4544
|
this.resourceLibraryRequests = new Map();
|
|
4500
4545
|
this.currentSlideIndex = 0;
|
|
4501
4546
|
this.slideCount = 0;
|
|
@@ -4650,6 +4695,7 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4650
4695
|
}
|
|
4651
4696
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4652
4697
|
this.resourceLibrary = options.resourceLibrary;
|
|
4698
|
+
this.masterTemplates = options.masterTemplates ?? {};
|
|
4653
4699
|
if (options.fonts) {
|
|
4654
4700
|
validateFontConfig(options.fonts);
|
|
4655
4701
|
}
|
|
@@ -4662,6 +4708,9 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4662
4708
|
if (options.fonts) {
|
|
4663
4709
|
await this.post('setFontConfig', { config: options.fonts });
|
|
4664
4710
|
}
|
|
4711
|
+
await this.post('setMasterTemplateCapabilities', {
|
|
4712
|
+
operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
|
|
4713
|
+
});
|
|
4665
4714
|
await this.post('setResourceLibraryAvailability', {
|
|
4666
4715
|
available: Boolean(this.resourceLibrary),
|
|
4667
4716
|
});
|
|
@@ -4700,6 +4749,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4700
4749
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
|
|
4701
4750
|
}
|
|
4702
4751
|
handleRequestMessage(message, sourceWindow) {
|
|
4752
|
+
if (message.type === 'masterTemplateRequest') {
|
|
4753
|
+
void this.handleMasterTemplateRequest(message, sourceWindow);
|
|
4754
|
+
return true;
|
|
4755
|
+
}
|
|
4703
4756
|
if (message.type === 'resourceLibraryCancel') {
|
|
4704
4757
|
this.resourceLibraryRequests.get(message.requestId)?.abort();
|
|
4705
4758
|
this.resourceLibraryRequests.delete(message.requestId);
|
|
@@ -4720,11 +4773,42 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4720
4773
|
return false;
|
|
4721
4774
|
}
|
|
4722
4775
|
async destroy() {
|
|
4776
|
+
this.masterTemplateRequests.clear();
|
|
4723
4777
|
this.resourceLibraryRequests.forEach((controller) => controller.abort());
|
|
4724
4778
|
this.resourceLibraryRequests.clear();
|
|
4725
4779
|
this.cancelActiveAi('destroyed', true);
|
|
4726
4780
|
await super.destroy();
|
|
4727
4781
|
}
|
|
4782
|
+
async handleMasterTemplateRequest(message, sourceWindow) {
|
|
4783
|
+
this.masterTemplateRequests.add(message.requestId);
|
|
4784
|
+
try {
|
|
4785
|
+
const result = await executeMasterTemplateCallback(this.masterTemplates, message.operation, message.args);
|
|
4786
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4787
|
+
return;
|
|
4788
|
+
sourceWindow.postMessage({
|
|
4789
|
+
type: 'response',
|
|
4790
|
+
requestId: message.requestId,
|
|
4791
|
+
success: true,
|
|
4792
|
+
result,
|
|
4793
|
+
}, '*');
|
|
4794
|
+
}
|
|
4795
|
+
catch (error) {
|
|
4796
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4797
|
+
return;
|
|
4798
|
+
sourceWindow.postMessage({
|
|
4799
|
+
type: 'response',
|
|
4800
|
+
requestId: message.requestId,
|
|
4801
|
+
success: false,
|
|
4802
|
+
error: {
|
|
4803
|
+
code: EMBED_ERROR_CODES.BAD_REQUEST,
|
|
4804
|
+
message: error instanceof Error ? error.message : String(error),
|
|
4805
|
+
},
|
|
4806
|
+
}, '*');
|
|
4807
|
+
}
|
|
4808
|
+
finally {
|
|
4809
|
+
this.masterTemplateRequests.delete(message.requestId);
|
|
4810
|
+
}
|
|
4811
|
+
}
|
|
4728
4812
|
async handleResourceLibraryQuery(message, sourceWindow) {
|
|
4729
4813
|
const controller = new AbortController();
|
|
4730
4814
|
this.resourceLibraryRequests.set(message.requestId, controller);
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
|
|
|
4009
4009
|
}
|
|
4010
4010
|
|
|
4011
4011
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4012
|
-
const VERSION = '2.15.
|
|
4012
|
+
const VERSION = '2.15.2';
|
|
4013
4013
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4014
4014
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4015
4015
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4135,6 +4135,19 @@ function buildEmbedSrc(options) {
|
|
|
4135
4135
|
? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
|
|
4136
4136
|
: src;
|
|
4137
4137
|
}
|
|
4138
|
+
const MASTER_TEMPLATE_OPERATIONS = [
|
|
4139
|
+
'listSystem',
|
|
4140
|
+
];
|
|
4141
|
+
function isMasterTemplateRequestMessage(msg) {
|
|
4142
|
+
if (!msg || typeof msg !== 'object')
|
|
4143
|
+
return false;
|
|
4144
|
+
const value = msg;
|
|
4145
|
+
return (value.type === 'masterTemplateRequest' &&
|
|
4146
|
+
typeof value.requestId === 'string' &&
|
|
4147
|
+
MASTER_TEMPLATE_OPERATIONS.includes(value.operation) &&
|
|
4148
|
+
Array.isArray(value.args) &&
|
|
4149
|
+
value.args.every((arg) => typeof arg === 'string'));
|
|
4150
|
+
}
|
|
4138
4151
|
|
|
4139
4152
|
class EmbeddedTarget {
|
|
4140
4153
|
constructor(container, embedMode) {
|
|
@@ -4296,7 +4309,8 @@ class EmbeddedTarget {
|
|
|
4296
4309
|
}
|
|
4297
4310
|
if ((isSaveRequestMessage(data) ||
|
|
4298
4311
|
isAiRequestMessage(data) ||
|
|
4299
|
-
isResourceLibraryRequestMessage(data)
|
|
4312
|
+
isResourceLibraryRequestMessage(data) ||
|
|
4313
|
+
isMasterTemplateRequestMessage(data)) &&
|
|
4300
4314
|
this.handleRequestMessage(data, iframe.contentWindow)) {
|
|
4301
4315
|
return;
|
|
4302
4316
|
}
|
|
@@ -4491,9 +4505,40 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4491
4505
|
}
|
|
4492
4506
|
}
|
|
4493
4507
|
|
|
4508
|
+
/** 校验 iframe 参数和宿主返回值,所有操作只调用已声明的宿主回调。 */
|
|
4509
|
+
async function executeMasterTemplateCallback(callbacks, operation, args) {
|
|
4510
|
+
if (operation !== 'listSystem' || !Array.isArray(args) || args.length !== 0) {
|
|
4511
|
+
throw new Error('无效的母版请求参数');
|
|
4512
|
+
}
|
|
4513
|
+
const callback = callbacks[operation];
|
|
4514
|
+
if (typeof callback !== 'function')
|
|
4515
|
+
throw new Error(`宿主未配置 masterTemplates.${operation}`);
|
|
4516
|
+
const result = await callback.call(callbacks);
|
|
4517
|
+
const ids = new Set();
|
|
4518
|
+
if (!Array.isArray(result) ||
|
|
4519
|
+
!result.every((item) => {
|
|
4520
|
+
if (!item ||
|
|
4521
|
+
typeof item.id !== 'string' ||
|
|
4522
|
+
!item.id.trim() ||
|
|
4523
|
+
ids.has(item.id) ||
|
|
4524
|
+
typeof item.name !== 'string' ||
|
|
4525
|
+
typeof item.content !== 'string' ||
|
|
4526
|
+
(item.created_at !== undefined &&
|
|
4527
|
+
typeof item.created_at !== 'string') ||
|
|
4528
|
+
(item.edited_at != null && typeof item.edited_at !== 'string'))
|
|
4529
|
+
return false;
|
|
4530
|
+
ids.add(item.id);
|
|
4531
|
+
return true;
|
|
4532
|
+
}))
|
|
4533
|
+
throw new Error('母版列表必须返回含唯一 id、name、content 的数组');
|
|
4534
|
+
return result;
|
|
4535
|
+
}
|
|
4536
|
+
|
|
4494
4537
|
class EmbeddedEditor extends EmbeddedTarget {
|
|
4495
4538
|
constructor(container) {
|
|
4496
4539
|
super(container, 'editor');
|
|
4540
|
+
this.masterTemplates = {};
|
|
4541
|
+
this.masterTemplateRequests = new Set();
|
|
4497
4542
|
this.resourceLibraryRequests = new Map();
|
|
4498
4543
|
this.currentSlideIndex = 0;
|
|
4499
4544
|
this.slideCount = 0;
|
|
@@ -4648,6 +4693,7 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4648
4693
|
}
|
|
4649
4694
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4650
4695
|
this.resourceLibrary = options.resourceLibrary;
|
|
4696
|
+
this.masterTemplates = options.masterTemplates ?? {};
|
|
4651
4697
|
if (options.fonts) {
|
|
4652
4698
|
validateFontConfig(options.fonts);
|
|
4653
4699
|
}
|
|
@@ -4660,6 +4706,9 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4660
4706
|
if (options.fonts) {
|
|
4661
4707
|
await this.post('setFontConfig', { config: options.fonts });
|
|
4662
4708
|
}
|
|
4709
|
+
await this.post('setMasterTemplateCapabilities', {
|
|
4710
|
+
operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
|
|
4711
|
+
});
|
|
4663
4712
|
await this.post('setResourceLibraryAvailability', {
|
|
4664
4713
|
available: Boolean(this.resourceLibrary),
|
|
4665
4714
|
});
|
|
@@ -4698,6 +4747,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4698
4747
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
|
|
4699
4748
|
}
|
|
4700
4749
|
handleRequestMessage(message, sourceWindow) {
|
|
4750
|
+
if (message.type === 'masterTemplateRequest') {
|
|
4751
|
+
void this.handleMasterTemplateRequest(message, sourceWindow);
|
|
4752
|
+
return true;
|
|
4753
|
+
}
|
|
4701
4754
|
if (message.type === 'resourceLibraryCancel') {
|
|
4702
4755
|
this.resourceLibraryRequests.get(message.requestId)?.abort();
|
|
4703
4756
|
this.resourceLibraryRequests.delete(message.requestId);
|
|
@@ -4718,11 +4771,42 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4718
4771
|
return false;
|
|
4719
4772
|
}
|
|
4720
4773
|
async destroy() {
|
|
4774
|
+
this.masterTemplateRequests.clear();
|
|
4721
4775
|
this.resourceLibraryRequests.forEach((controller) => controller.abort());
|
|
4722
4776
|
this.resourceLibraryRequests.clear();
|
|
4723
4777
|
this.cancelActiveAi('destroyed', true);
|
|
4724
4778
|
await super.destroy();
|
|
4725
4779
|
}
|
|
4780
|
+
async handleMasterTemplateRequest(message, sourceWindow) {
|
|
4781
|
+
this.masterTemplateRequests.add(message.requestId);
|
|
4782
|
+
try {
|
|
4783
|
+
const result = await executeMasterTemplateCallback(this.masterTemplates, message.operation, message.args);
|
|
4784
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4785
|
+
return;
|
|
4786
|
+
sourceWindow.postMessage({
|
|
4787
|
+
type: 'response',
|
|
4788
|
+
requestId: message.requestId,
|
|
4789
|
+
success: true,
|
|
4790
|
+
result,
|
|
4791
|
+
}, '*');
|
|
4792
|
+
}
|
|
4793
|
+
catch (error) {
|
|
4794
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4795
|
+
return;
|
|
4796
|
+
sourceWindow.postMessage({
|
|
4797
|
+
type: 'response',
|
|
4798
|
+
requestId: message.requestId,
|
|
4799
|
+
success: false,
|
|
4800
|
+
error: {
|
|
4801
|
+
code: EMBED_ERROR_CODES.BAD_REQUEST,
|
|
4802
|
+
message: error instanceof Error ? error.message : String(error),
|
|
4803
|
+
},
|
|
4804
|
+
}, '*');
|
|
4805
|
+
}
|
|
4806
|
+
finally {
|
|
4807
|
+
this.masterTemplateRequests.delete(message.requestId);
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4726
4810
|
async handleResourceLibraryQuery(message, sourceWindow) {
|
|
4727
4811
|
const controller = new AbortController();
|
|
4728
4812
|
this.resourceLibraryRequests.set(message.requestId, controller);
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -4015,7 +4015,7 @@
|
|
|
4015
4015
|
}
|
|
4016
4016
|
|
|
4017
4017
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4018
|
-
const VERSION = '2.15.
|
|
4018
|
+
const VERSION = '2.15.2';
|
|
4019
4019
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4020
4020
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4021
4021
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4141,6 +4141,19 @@
|
|
|
4141
4141
|
? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
|
|
4142
4142
|
: src;
|
|
4143
4143
|
}
|
|
4144
|
+
const MASTER_TEMPLATE_OPERATIONS = [
|
|
4145
|
+
'listSystem',
|
|
4146
|
+
];
|
|
4147
|
+
function isMasterTemplateRequestMessage(msg) {
|
|
4148
|
+
if (!msg || typeof msg !== 'object')
|
|
4149
|
+
return false;
|
|
4150
|
+
const value = msg;
|
|
4151
|
+
return (value.type === 'masterTemplateRequest' &&
|
|
4152
|
+
typeof value.requestId === 'string' &&
|
|
4153
|
+
MASTER_TEMPLATE_OPERATIONS.includes(value.operation) &&
|
|
4154
|
+
Array.isArray(value.args) &&
|
|
4155
|
+
value.args.every((arg) => typeof arg === 'string'));
|
|
4156
|
+
}
|
|
4144
4157
|
|
|
4145
4158
|
class EmbeddedTarget {
|
|
4146
4159
|
constructor(container, embedMode) {
|
|
@@ -4302,7 +4315,8 @@
|
|
|
4302
4315
|
}
|
|
4303
4316
|
if ((isSaveRequestMessage(data) ||
|
|
4304
4317
|
isAiRequestMessage(data) ||
|
|
4305
|
-
isResourceLibraryRequestMessage(data)
|
|
4318
|
+
isResourceLibraryRequestMessage(data) ||
|
|
4319
|
+
isMasterTemplateRequestMessage(data)) &&
|
|
4306
4320
|
this.handleRequestMessage(data, iframe.contentWindow)) {
|
|
4307
4321
|
return;
|
|
4308
4322
|
}
|
|
@@ -4497,9 +4511,40 @@
|
|
|
4497
4511
|
}
|
|
4498
4512
|
}
|
|
4499
4513
|
|
|
4514
|
+
/** 校验 iframe 参数和宿主返回值,所有操作只调用已声明的宿主回调。 */
|
|
4515
|
+
async function executeMasterTemplateCallback(callbacks, operation, args) {
|
|
4516
|
+
if (operation !== 'listSystem' || !Array.isArray(args) || args.length !== 0) {
|
|
4517
|
+
throw new Error('无效的母版请求参数');
|
|
4518
|
+
}
|
|
4519
|
+
const callback = callbacks[operation];
|
|
4520
|
+
if (typeof callback !== 'function')
|
|
4521
|
+
throw new Error(`宿主未配置 masterTemplates.${operation}`);
|
|
4522
|
+
const result = await callback.call(callbacks);
|
|
4523
|
+
const ids = new Set();
|
|
4524
|
+
if (!Array.isArray(result) ||
|
|
4525
|
+
!result.every((item) => {
|
|
4526
|
+
if (!item ||
|
|
4527
|
+
typeof item.id !== 'string' ||
|
|
4528
|
+
!item.id.trim() ||
|
|
4529
|
+
ids.has(item.id) ||
|
|
4530
|
+
typeof item.name !== 'string' ||
|
|
4531
|
+
typeof item.content !== 'string' ||
|
|
4532
|
+
(item.created_at !== undefined &&
|
|
4533
|
+
typeof item.created_at !== 'string') ||
|
|
4534
|
+
(item.edited_at != null && typeof item.edited_at !== 'string'))
|
|
4535
|
+
return false;
|
|
4536
|
+
ids.add(item.id);
|
|
4537
|
+
return true;
|
|
4538
|
+
}))
|
|
4539
|
+
throw new Error('母版列表必须返回含唯一 id、name、content 的数组');
|
|
4540
|
+
return result;
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4500
4543
|
class EmbeddedEditor extends EmbeddedTarget {
|
|
4501
4544
|
constructor(container) {
|
|
4502
4545
|
super(container, 'editor');
|
|
4546
|
+
this.masterTemplates = {};
|
|
4547
|
+
this.masterTemplateRequests = new Set();
|
|
4503
4548
|
this.resourceLibraryRequests = new Map();
|
|
4504
4549
|
this.currentSlideIndex = 0;
|
|
4505
4550
|
this.slideCount = 0;
|
|
@@ -4654,6 +4699,7 @@
|
|
|
4654
4699
|
}
|
|
4655
4700
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4656
4701
|
this.resourceLibrary = options.resourceLibrary;
|
|
4702
|
+
this.masterTemplates = options.masterTemplates ?? {};
|
|
4657
4703
|
if (options.fonts) {
|
|
4658
4704
|
validateFontConfig(options.fonts);
|
|
4659
4705
|
}
|
|
@@ -4666,6 +4712,9 @@
|
|
|
4666
4712
|
if (options.fonts) {
|
|
4667
4713
|
await this.post('setFontConfig', { config: options.fonts });
|
|
4668
4714
|
}
|
|
4715
|
+
await this.post('setMasterTemplateCapabilities', {
|
|
4716
|
+
operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
|
|
4717
|
+
});
|
|
4669
4718
|
await this.post('setResourceLibraryAvailability', {
|
|
4670
4719
|
available: Boolean(this.resourceLibrary),
|
|
4671
4720
|
});
|
|
@@ -4704,6 +4753,10 @@
|
|
|
4704
4753
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
|
|
4705
4754
|
}
|
|
4706
4755
|
handleRequestMessage(message, sourceWindow) {
|
|
4756
|
+
if (message.type === 'masterTemplateRequest') {
|
|
4757
|
+
void this.handleMasterTemplateRequest(message, sourceWindow);
|
|
4758
|
+
return true;
|
|
4759
|
+
}
|
|
4707
4760
|
if (message.type === 'resourceLibraryCancel') {
|
|
4708
4761
|
this.resourceLibraryRequests.get(message.requestId)?.abort();
|
|
4709
4762
|
this.resourceLibraryRequests.delete(message.requestId);
|
|
@@ -4724,11 +4777,42 @@
|
|
|
4724
4777
|
return false;
|
|
4725
4778
|
}
|
|
4726
4779
|
async destroy() {
|
|
4780
|
+
this.masterTemplateRequests.clear();
|
|
4727
4781
|
this.resourceLibraryRequests.forEach((controller) => controller.abort());
|
|
4728
4782
|
this.resourceLibraryRequests.clear();
|
|
4729
4783
|
this.cancelActiveAi('destroyed', true);
|
|
4730
4784
|
await super.destroy();
|
|
4731
4785
|
}
|
|
4786
|
+
async handleMasterTemplateRequest(message, sourceWindow) {
|
|
4787
|
+
this.masterTemplateRequests.add(message.requestId);
|
|
4788
|
+
try {
|
|
4789
|
+
const result = await executeMasterTemplateCallback(this.masterTemplates, message.operation, message.args);
|
|
4790
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4791
|
+
return;
|
|
4792
|
+
sourceWindow.postMessage({
|
|
4793
|
+
type: 'response',
|
|
4794
|
+
requestId: message.requestId,
|
|
4795
|
+
success: true,
|
|
4796
|
+
result,
|
|
4797
|
+
}, '*');
|
|
4798
|
+
}
|
|
4799
|
+
catch (error) {
|
|
4800
|
+
if (!this.masterTemplateRequests.has(message.requestId))
|
|
4801
|
+
return;
|
|
4802
|
+
sourceWindow.postMessage({
|
|
4803
|
+
type: 'response',
|
|
4804
|
+
requestId: message.requestId,
|
|
4805
|
+
success: false,
|
|
4806
|
+
error: {
|
|
4807
|
+
code: EMBED_ERROR_CODES.BAD_REQUEST,
|
|
4808
|
+
message: error instanceof Error ? error.message : String(error),
|
|
4809
|
+
},
|
|
4810
|
+
}, '*');
|
|
4811
|
+
}
|
|
4812
|
+
finally {
|
|
4813
|
+
this.masterTemplateRequests.delete(message.requestId);
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4732
4816
|
async handleResourceLibraryQuery(message, sourceWindow) {
|
|
4733
4817
|
const controller = new AbortController();
|
|
4734
4818
|
this.resourceLibraryRequests.set(message.requestId, controller);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { EmbeddedTarget } from './embedded-target';
|
|
2
2
|
import { type AiApi, type AiCancelEvent, type ReplResult, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
|
|
3
3
|
export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedEditorEventListenerMap> {
|
|
4
|
+
private masterTemplates;
|
|
5
|
+
private readonly masterTemplateRequests;
|
|
4
6
|
private resourceLibrary?;
|
|
5
7
|
private readonly resourceLibraryRequests;
|
|
6
8
|
readonly document: DocumentApi;
|
|
@@ -26,6 +28,7 @@ export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMa
|
|
|
26
28
|
} | AiCancelEvent): void;
|
|
27
29
|
protected handleRequestMessage(message: EmbedRequestMessage, sourceWindow: Window): boolean;
|
|
28
30
|
destroy(): Promise<void>;
|
|
31
|
+
private handleMasterTemplateRequest;
|
|
29
32
|
private handleResourceLibraryQuery;
|
|
30
33
|
private validateResourceLibraryQuery;
|
|
31
34
|
private validateResourceLibraryResult;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
|
|
2
2
|
export type { FileContentAny, FileContentLatest, } from '@dajiaoai/algeo-protocol';
|
|
3
3
|
export { convertToLatest } from '@dajiaoai/algeo-protocol';
|
|
4
|
-
export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBound, ExportViewBounds, ExportViewCamera3D, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SetViewBoundsOptions, SetViewCamera3dOptions, ViewCamera3d, SlideChangeEvent, SlideIndexResult, SlideInfo, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
4
|
+
export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBound, ExportViewBounds, ExportViewCamera3D, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, MasterTemplateItem, MasterTemplateCallbacks, MasterTemplateOperation, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SetViewBoundsOptions, SetViewCamera3dOptions, ViewCamera3d, SlideChangeEvent, SlideIndexResult, SlideInfo, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
5
5
|
export { EmbeddedPresentation } from './embedded-presentation';
|
|
6
6
|
export { EmbeddedEditor } from './embedded-editor';
|
|
7
7
|
export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MasterTemplateCallbacks, MasterTemplateOperation } from './shared';
|
|
2
|
+
/** 校验 iframe 参数和宿主返回值,所有操作只调用已声明的宿主回调。 */
|
|
3
|
+
export declare function executeMasterTemplateCallback(callbacks: MasterTemplateCallbacks, operation: MasterTemplateOperation, args: string[]): Promise<unknown>;
|
package/dist/shared.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface AlgeoEditorUiConfig {
|
|
|
24
24
|
toolboxPanel?: boolean;
|
|
25
25
|
algebraPanel?: boolean;
|
|
26
26
|
docPanel?: boolean;
|
|
27
|
+
/** 母版面板,默认关闭,需显式设为 true。 */
|
|
28
|
+
masterTemplatePanel?: boolean;
|
|
27
29
|
helpEntry?: boolean;
|
|
28
30
|
aiChatPanel?: boolean;
|
|
29
31
|
}
|
|
@@ -83,6 +85,8 @@ export interface AlgeoEditorCreateOptions {
|
|
|
83
85
|
fonts?: AlgeoFontConfig;
|
|
84
86
|
/** 接入方提供的只读图片资源库。 */
|
|
85
87
|
resourceLibrary?: ResourceLibraryProvider;
|
|
88
|
+
/** 只读系统母版;未声明 listSystem 时隐藏系统母版 Tab。 */
|
|
89
|
+
masterTemplates?: MasterTemplateCallbacks;
|
|
86
90
|
}
|
|
87
91
|
export interface ResourceLibraryQuery {
|
|
88
92
|
/** 页码,从 1 开始。 */
|
|
@@ -524,7 +528,7 @@ export declare function validateFontConfig(config: AlgeoFontConfig): void;
|
|
|
524
528
|
export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
|
|
525
529
|
export declare function isReadyMessage(msg: unknown): msg is EmbedReadyMessage;
|
|
526
530
|
export type EmbedEventMessage = ContentChangeEvent | SlideChangeEvent | SaveSuccessEvent | AiCancelEvent;
|
|
527
|
-
export type EmbedRequestMessage = SaveRequestMessage | AiRequestMessage | ResourceLibraryQueryMessage | ResourceLibraryCancelMessage;
|
|
531
|
+
export type EmbedRequestMessage = MasterTemplateRequestMessage | SaveRequestMessage | AiRequestMessage | ResourceLibraryQueryMessage | ResourceLibraryCancelMessage;
|
|
528
532
|
export declare function isSaveRequestMessage(msg: unknown): msg is SaveRequestMessage;
|
|
529
533
|
export declare function isAiRequestMessage(msg: unknown): msg is AiRequestMessage;
|
|
530
534
|
export declare function isResourceLibraryRequestMessage(msg: unknown): msg is ResourceLibraryQueryMessage | ResourceLibraryCancelMessage;
|
|
@@ -539,3 +543,23 @@ export interface EmbedInitOptions extends AlgeoSdkOptions {
|
|
|
539
543
|
export declare function buildEmbedSrc(options: EmbedInitOptions): string;
|
|
540
544
|
export type KnownEventName = 'ready' | 'contentChange' | 'slideChange' | 'save' | 'aiRequest' | 'aiCancel';
|
|
541
545
|
export type TEventName<T extends string> = Extract<T, KnownEventName>;
|
|
546
|
+
/** 母版数据由接入方映射;content 为大角母版 JSON 字符串。 */
|
|
547
|
+
export interface MasterTemplateItem {
|
|
548
|
+
id: string;
|
|
549
|
+
name: string;
|
|
550
|
+
content: string;
|
|
551
|
+
created_at?: string;
|
|
552
|
+
edited_at?: string | null;
|
|
553
|
+
}
|
|
554
|
+
export interface MasterTemplateCallbacks {
|
|
555
|
+
listSystem?: () => Promise<MasterTemplateItem[]>;
|
|
556
|
+
}
|
|
557
|
+
export type MasterTemplateOperation = keyof MasterTemplateCallbacks;
|
|
558
|
+
export declare const MASTER_TEMPLATE_OPERATIONS: MasterTemplateOperation[];
|
|
559
|
+
export interface MasterTemplateRequestMessage {
|
|
560
|
+
type: 'masterTemplateRequest';
|
|
561
|
+
requestId: string;
|
|
562
|
+
operation: MasterTemplateOperation;
|
|
563
|
+
args: string[];
|
|
564
|
+
}
|
|
565
|
+
export declare function isMasterTemplateRequestMessage(msg: unknown): msg is MasterTemplateRequestMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dajiaoai/algeo-sdk",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.2",
|
|
4
4
|
"description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
|
|
5
5
|
"main": "dist/algeo-sdk.cjs.js",
|
|
6
6
|
"module": "dist/algeo-sdk.esm.js",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "rollup -c",
|
|
15
15
|
"typecheck": "tsc --noEmit",
|
|
16
|
+
"test": "npm run build && node --test tests/*.test.mjs",
|
|
16
17
|
"examples": "npx serve .",
|
|
17
18
|
"release": "npm run build && npm publish --access public"
|
|
18
19
|
},
|