@dajiaoai/algeo-sdk 2.15.1 → 2.15.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
4
4
 
5
- 当前版本:**2.15.1**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.15.1)。
5
+ 当前版本:**2.15.3**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.15.3)。
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 对话面板 |
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.15.1';
4014
+ const VERSION = '2.15.3';
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,11 @@ class EmbeddedEditor extends EmbeddedTarget {
4662
4708
  if (options.fonts) {
4663
4709
  await this.post('setFontConfig', { config: options.fonts });
4664
4710
  }
4711
+ // Optional configuration: older hosts ignore this message. Send it before
4712
+ // the remaining initialization requests without requiring a response.
4713
+ this.postEvent('setMasterTemplateCapabilities', {
4714
+ operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
4715
+ });
4665
4716
  await this.post('setResourceLibraryAvailability', {
4666
4717
  available: Boolean(this.resourceLibrary),
4667
4718
  });
@@ -4700,6 +4751,10 @@ class EmbeddedEditor extends EmbeddedTarget {
4700
4751
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4701
4752
  }
4702
4753
  handleRequestMessage(message, sourceWindow) {
4754
+ if (message.type === 'masterTemplateRequest') {
4755
+ void this.handleMasterTemplateRequest(message, sourceWindow);
4756
+ return true;
4757
+ }
4703
4758
  if (message.type === 'resourceLibraryCancel') {
4704
4759
  this.resourceLibraryRequests.get(message.requestId)?.abort();
4705
4760
  this.resourceLibraryRequests.delete(message.requestId);
@@ -4720,11 +4775,42 @@ class EmbeddedEditor extends EmbeddedTarget {
4720
4775
  return false;
4721
4776
  }
4722
4777
  async destroy() {
4778
+ this.masterTemplateRequests.clear();
4723
4779
  this.resourceLibraryRequests.forEach((controller) => controller.abort());
4724
4780
  this.resourceLibraryRequests.clear();
4725
4781
  this.cancelActiveAi('destroyed', true);
4726
4782
  await super.destroy();
4727
4783
  }
4784
+ async handleMasterTemplateRequest(message, sourceWindow) {
4785
+ this.masterTemplateRequests.add(message.requestId);
4786
+ try {
4787
+ const result = await executeMasterTemplateCallback(this.masterTemplates, message.operation, message.args);
4788
+ if (!this.masterTemplateRequests.has(message.requestId))
4789
+ return;
4790
+ sourceWindow.postMessage({
4791
+ type: 'response',
4792
+ requestId: message.requestId,
4793
+ success: true,
4794
+ result,
4795
+ }, '*');
4796
+ }
4797
+ catch (error) {
4798
+ if (!this.masterTemplateRequests.has(message.requestId))
4799
+ return;
4800
+ sourceWindow.postMessage({
4801
+ type: 'response',
4802
+ requestId: message.requestId,
4803
+ success: false,
4804
+ error: {
4805
+ code: EMBED_ERROR_CODES.BAD_REQUEST,
4806
+ message: error instanceof Error ? error.message : String(error),
4807
+ },
4808
+ }, '*');
4809
+ }
4810
+ finally {
4811
+ this.masterTemplateRequests.delete(message.requestId);
4812
+ }
4813
+ }
4728
4814
  async handleResourceLibraryQuery(message, sourceWindow) {
4729
4815
  const controller = new AbortController();
4730
4816
  this.resourceLibraryRequests.set(message.requestId, controller);
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.15.1';
4012
+ const VERSION = '2.15.3';
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,11 @@ class EmbeddedEditor extends EmbeddedTarget {
4660
4706
  if (options.fonts) {
4661
4707
  await this.post('setFontConfig', { config: options.fonts });
4662
4708
  }
4709
+ // Optional configuration: older hosts ignore this message. Send it before
4710
+ // the remaining initialization requests without requiring a response.
4711
+ this.postEvent('setMasterTemplateCapabilities', {
4712
+ operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
4713
+ });
4663
4714
  await this.post('setResourceLibraryAvailability', {
4664
4715
  available: Boolean(this.resourceLibrary),
4665
4716
  });
@@ -4698,6 +4749,10 @@ class EmbeddedEditor extends EmbeddedTarget {
4698
4749
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4699
4750
  }
4700
4751
  handleRequestMessage(message, sourceWindow) {
4752
+ if (message.type === 'masterTemplateRequest') {
4753
+ void this.handleMasterTemplateRequest(message, sourceWindow);
4754
+ return true;
4755
+ }
4701
4756
  if (message.type === 'resourceLibraryCancel') {
4702
4757
  this.resourceLibraryRequests.get(message.requestId)?.abort();
4703
4758
  this.resourceLibraryRequests.delete(message.requestId);
@@ -4718,11 +4773,42 @@ class EmbeddedEditor extends EmbeddedTarget {
4718
4773
  return false;
4719
4774
  }
4720
4775
  async destroy() {
4776
+ this.masterTemplateRequests.clear();
4721
4777
  this.resourceLibraryRequests.forEach((controller) => controller.abort());
4722
4778
  this.resourceLibraryRequests.clear();
4723
4779
  this.cancelActiveAi('destroyed', true);
4724
4780
  await super.destroy();
4725
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
+ }
4726
4812
  async handleResourceLibraryQuery(message, sourceWindow) {
4727
4813
  const controller = new AbortController();
4728
4814
  this.resourceLibraryRequests.set(message.requestId, controller);
@@ -4015,7 +4015,7 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.15.1';
4018
+ const VERSION = '2.15.3';
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,11 @@
4666
4712
  if (options.fonts) {
4667
4713
  await this.post('setFontConfig', { config: options.fonts });
4668
4714
  }
4715
+ // Optional configuration: older hosts ignore this message. Send it before
4716
+ // the remaining initialization requests without requiring a response.
4717
+ this.postEvent('setMasterTemplateCapabilities', {
4718
+ operations: MASTER_TEMPLATE_OPERATIONS.filter((operation) => typeof this.masterTemplates[operation] === 'function'),
4719
+ });
4669
4720
  await this.post('setResourceLibraryAvailability', {
4670
4721
  available: Boolean(this.resourceLibrary),
4671
4722
  });
@@ -4704,6 +4755,10 @@
4704
4755
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4705
4756
  }
4706
4757
  handleRequestMessage(message, sourceWindow) {
4758
+ if (message.type === 'masterTemplateRequest') {
4759
+ void this.handleMasterTemplateRequest(message, sourceWindow);
4760
+ return true;
4761
+ }
4707
4762
  if (message.type === 'resourceLibraryCancel') {
4708
4763
  this.resourceLibraryRequests.get(message.requestId)?.abort();
4709
4764
  this.resourceLibraryRequests.delete(message.requestId);
@@ -4724,11 +4779,42 @@
4724
4779
  return false;
4725
4780
  }
4726
4781
  async destroy() {
4782
+ this.masterTemplateRequests.clear();
4727
4783
  this.resourceLibraryRequests.forEach((controller) => controller.abort());
4728
4784
  this.resourceLibraryRequests.clear();
4729
4785
  this.cancelActiveAi('destroyed', true);
4730
4786
  await super.destroy();
4731
4787
  }
4788
+ async handleMasterTemplateRequest(message, sourceWindow) {
4789
+ this.masterTemplateRequests.add(message.requestId);
4790
+ try {
4791
+ const result = await executeMasterTemplateCallback(this.masterTemplates, message.operation, message.args);
4792
+ if (!this.masterTemplateRequests.has(message.requestId))
4793
+ return;
4794
+ sourceWindow.postMessage({
4795
+ type: 'response',
4796
+ requestId: message.requestId,
4797
+ success: true,
4798
+ result,
4799
+ }, '*');
4800
+ }
4801
+ catch (error) {
4802
+ if (!this.masterTemplateRequests.has(message.requestId))
4803
+ return;
4804
+ sourceWindow.postMessage({
4805
+ type: 'response',
4806
+ requestId: message.requestId,
4807
+ success: false,
4808
+ error: {
4809
+ code: EMBED_ERROR_CODES.BAD_REQUEST,
4810
+ message: error instanceof Error ? error.message : String(error),
4811
+ },
4812
+ }, '*');
4813
+ }
4814
+ finally {
4815
+ this.masterTemplateRequests.delete(message.requestId);
4816
+ }
4817
+ }
4732
4818
  async handleResourceLibraryQuery(message, sourceWindow) {
4733
4819
  const controller = new AbortController();
4734
4820
  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.1",
3
+ "version": "2.15.3",
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
  },