@schema-element-editor/host-sdk 2.1.0 → 2.1.1

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.
@@ -0,0 +1,456 @@
1
+ // src/constants.ts
2
+ var DEFAULT_SOURCE_CONFIG = {
3
+ contentSource: "schema-element-editor-content",
4
+ hostSource: "schema-element-editor-host"
5
+ };
6
+ var SDK_COORDINATOR_SOURCE = "schema-element-editor-sdk-coordinator";
7
+ var DEFAULT_MESSAGE_TYPES = {
8
+ getSchema: "GET_SCHEMA",
9
+ updateSchema: "UPDATE_SCHEMA",
10
+ checkPreview: "CHECK_PREVIEW",
11
+ renderPreview: "RENDER_PREVIEW",
12
+ cleanupPreview: "CLEANUP_PREVIEW",
13
+ // 录制模式相关
14
+ startRecording: "START_RECORDING",
15
+ stopRecording: "STOP_RECORDING",
16
+ schemaPush: "SCHEMA_PUSH"
17
+ };
18
+ var SDK_COORDINATION_MESSAGE_TYPES = {
19
+ register: "SDK_REGISTER",
20
+ unregister: "SDK_UNREGISTER",
21
+ query: "SDK_QUERY"
22
+ };
23
+
24
+ // src/coordinator.ts
25
+ function generateSdkId() {
26
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
27
+ return crypto.randomUUID();
28
+ }
29
+ return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
30
+ }
31
+ var SdkCoordinator = class {
32
+ constructor(config) {
33
+ /**
34
+ * SDK 销毁标志
35
+ *
36
+ * 作用:防止在 cleanup() 执行期间,监听器移除前仍然响应请求
37
+ *
38
+ * 场景:cleanup() 中先调用 destroy()(设置 isDestroyed = true),
39
+ * 然后才移除 handleMessage 监听器。在这个微小的时间窗口内,
40
+ * 如果插件请求到达,没有 isDestroyed 检查会导致已销毁的 SDK 仍然响应。
41
+ */
42
+ this.isDestroyed = false;
43
+ /**
44
+ * 存储比当前 SDK 优先级更高的其他 SDK ID
45
+ * 按方法分类:如果某个方法的集合不为空,说明有更高优先级的 SDK 应该处理该方法
46
+ *
47
+ * 优化:只为当前 SDK 实现了的方法维护优先级集合
48
+ */
49
+ this.higherLevelSDKs = {};
50
+ /**
51
+ * 存储与当前 SDK 优先级相同的其他 SDK ID
52
+ * 按方法分类:用于判断是否需要在执行失败时跳过响应
53
+ *
54
+ * 当有同级竞争者时,SDK在执行失败/无数据时会跳过响应,让其他SDK有机会响应
55
+ */
56
+ this.sameLevelSDKs = {};
57
+ /**
58
+ * 处理 SDK 协调消息
59
+ */
60
+ this.handleCoordinationMessage = (event) => {
61
+ const isFromSelf = event.source === window;
62
+ const isFromParent = window !== window.top && event.source === window.parent;
63
+ if (!isFromSelf && !isFromParent) return;
64
+ const data = event.data;
65
+ if (!data || data.source !== SDK_COORDINATOR_SOURCE) return;
66
+ switch (data.type) {
67
+ case SDK_COORDINATION_MESSAGE_TYPES.query:
68
+ this.sendRegister();
69
+ break;
70
+ case SDK_COORDINATION_MESSAGE_TYPES.register:
71
+ this.handleSdkRegister(data.payload);
72
+ break;
73
+ case SDK_COORDINATION_MESSAGE_TYPES.unregister:
74
+ this.handleSdkUnregister(data.payload.sdkId);
75
+ break;
76
+ }
77
+ };
78
+ this.sdkId = config.sdkId || generateSdkId();
79
+ this.messageSource = config.messageSource;
80
+ this.level = config.level ?? 0;
81
+ this.methodLevels = config.methodLevels ?? {};
82
+ this.implementedMethods = config.implementedMethods;
83
+ this.implementedMethods.forEach((method) => {
84
+ this.higherLevelSDKs[method] = /* @__PURE__ */ new Set();
85
+ this.sameLevelSDKs[method] = /* @__PURE__ */ new Set();
86
+ });
87
+ }
88
+ /**
89
+ * 初始化协调器
90
+ */
91
+ init() {
92
+ window.addEventListener("message", this.handleCoordinationMessage);
93
+ this.sendQuery();
94
+ this.sendRegister();
95
+ }
96
+ /**
97
+ * 销毁协调器
98
+ */
99
+ destroy() {
100
+ this.isDestroyed = true;
101
+ this.sendUnregister();
102
+ window.removeEventListener("message", this.handleCoordinationMessage);
103
+ Object.values(this.higherLevelSDKs).forEach((set) => set.clear());
104
+ Object.values(this.sameLevelSDKs).forEach((set) => set.clear());
105
+ }
106
+ /**
107
+ * 判断是否应该响应某个方法的请求
108
+ * @param method - 方法名
109
+ * @returns 是否应该响应
110
+ */
111
+ shouldRespond(method) {
112
+ if (this.isDestroyed) return false;
113
+ if (!this.implementedMethods.includes(method)) {
114
+ return false;
115
+ }
116
+ const higherSDKs = this.higherLevelSDKs[method];
117
+ return !higherSDKs || higherSDKs.size === 0;
118
+ }
119
+ /**
120
+ * 判断某个方法是否有相同优先级的竞争者
121
+ * @param method - 方法名
122
+ * @returns 是否存在同级竞争者
123
+ */
124
+ hasSameLevelCompetitors(method) {
125
+ const sameSDKs = this.sameLevelSDKs[method];
126
+ return sameSDKs ? sameSDKs.size > 0 : false;
127
+ }
128
+ /**
129
+ * 获取方法的优先级
130
+ */
131
+ getMethodLevel(method) {
132
+ return this.methodLevels[method] ?? this.level;
133
+ }
134
+ /**
135
+ * 处理其他 SDK 的注册
136
+ */
137
+ handleSdkRegister(info) {
138
+ if (info.sdkId === this.sdkId) return;
139
+ if (info.messageSource !== this.messageSource) return;
140
+ this.implementedMethods.forEach((method) => {
141
+ if (!info.implementedMethods.includes(method)) {
142
+ return;
143
+ }
144
+ const myLevel = this.getMethodLevel(method);
145
+ const otherLevel = info.methodLevels[method] ?? info.level;
146
+ if (otherLevel > myLevel) {
147
+ this.higherLevelSDKs[method].add(info.sdkId);
148
+ this.sameLevelSDKs[method].delete(info.sdkId);
149
+ } else if (otherLevel === myLevel) {
150
+ this.sameLevelSDKs[method].add(info.sdkId);
151
+ this.higherLevelSDKs[method].delete(info.sdkId);
152
+ } else {
153
+ this.higherLevelSDKs[method].delete(info.sdkId);
154
+ this.sameLevelSDKs[method].delete(info.sdkId);
155
+ }
156
+ });
157
+ }
158
+ /**
159
+ * 处理其他 SDK 的注销
160
+ */
161
+ handleSdkUnregister(sdkId) {
162
+ Object.values(this.higherLevelSDKs).forEach((set) => {
163
+ set.delete(sdkId);
164
+ });
165
+ Object.values(this.sameLevelSDKs).forEach((set) => {
166
+ set.delete(sdkId);
167
+ });
168
+ }
169
+ /**
170
+ * 发送查询消息
171
+ */
172
+ sendQuery() {
173
+ const message = {
174
+ source: SDK_COORDINATOR_SOURCE,
175
+ type: SDK_COORDINATION_MESSAGE_TYPES.query,
176
+ payload: { sdkId: this.sdkId }
177
+ };
178
+ this.postCoordinationMessage(message);
179
+ }
180
+ /**
181
+ * 发送注册消息
182
+ */
183
+ sendRegister() {
184
+ const message = {
185
+ source: SDK_COORDINATOR_SOURCE,
186
+ type: SDK_COORDINATION_MESSAGE_TYPES.register,
187
+ payload: {
188
+ sdkId: this.sdkId,
189
+ messageSource: this.messageSource,
190
+ level: this.level,
191
+ methodLevels: this.methodLevels,
192
+ implementedMethods: this.implementedMethods
193
+ }
194
+ };
195
+ this.postCoordinationMessage(message);
196
+ }
197
+ /**
198
+ * 发送注销消息
199
+ */
200
+ sendUnregister() {
201
+ const message = {
202
+ source: SDK_COORDINATOR_SOURCE,
203
+ type: SDK_COORDINATION_MESSAGE_TYPES.unregister,
204
+ payload: { sdkId: this.sdkId }
205
+ };
206
+ this.postCoordinationMessage(message);
207
+ }
208
+ /**
209
+ * 发送协调消息
210
+ */
211
+ postCoordinationMessage(message) {
212
+ window.postMessage(message, "*");
213
+ if (window.top && window.top !== window) {
214
+ window.top.postMessage(message, "*");
215
+ }
216
+ }
217
+ };
218
+
219
+ // src/bridge.ts
220
+ var METHOD_NAMES = {
221
+ GET_SCHEMA: "getSchema",
222
+ UPDATE_SCHEMA: "updateSchema",
223
+ CHECK_PREVIEW: "checkPreview",
224
+ RENDER_PREVIEW: "renderPreview",
225
+ CLEANUP_PREVIEW: "cleanupPreview",
226
+ START_RECORDING: "startRecording",
227
+ STOP_RECORDING: "stopRecording"
228
+ };
229
+ function shouldSkipFailedResponse(method, result) {
230
+ switch (method) {
231
+ case METHOD_NAMES.GET_SCHEMA:
232
+ return result.success === true && result.data === void 0;
233
+ case METHOD_NAMES.UPDATE_SCHEMA:
234
+ return result.success === false;
235
+ case METHOD_NAMES.RENDER_PREVIEW:
236
+ case METHOD_NAMES.CLEANUP_PREVIEW:
237
+ return result.success === false;
238
+ case METHOD_NAMES.CHECK_PREVIEW:
239
+ case METHOD_NAMES.START_RECORDING:
240
+ case METHOD_NAMES.STOP_RECORDING:
241
+ return false;
242
+ default:
243
+ return false;
244
+ }
245
+ }
246
+ function createSchemaElementEditorBridge(config) {
247
+ const {
248
+ getSchema,
249
+ updateSchema,
250
+ renderPreview,
251
+ sourceConfig,
252
+ messageTypes,
253
+ sdkId,
254
+ level,
255
+ methodLevels
256
+ } = config;
257
+ const mergedSourceConfig = {
258
+ ...DEFAULT_SOURCE_CONFIG,
259
+ ...sourceConfig
260
+ };
261
+ const mergedMessageTypes = {
262
+ ...DEFAULT_MESSAGE_TYPES,
263
+ ...messageTypes
264
+ };
265
+ const implementedMethods = [];
266
+ if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
267
+ if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
268
+ if (typeof renderPreview === "function") {
269
+ implementedMethods.push(
270
+ METHOD_NAMES.CHECK_PREVIEW,
271
+ METHOD_NAMES.RENDER_PREVIEW,
272
+ METHOD_NAMES.CLEANUP_PREVIEW
273
+ );
274
+ }
275
+ implementedMethods.push(METHOD_NAMES.START_RECORDING, METHOD_NAMES.STOP_RECORDING);
276
+ const coordinator = new SdkCoordinator({
277
+ sdkId,
278
+ messageSource: mergedSourceConfig.contentSource,
279
+ level,
280
+ methodLevels,
281
+ implementedMethods
282
+ });
283
+ coordinator.init();
284
+ let previewCleanupFn = null;
285
+ const recordingParams = /* @__PURE__ */ new Set();
286
+ const currentConfig = { getSchema, updateSchema, renderPreview };
287
+ const methodTypeToName = {
288
+ [mergedMessageTypes.getSchema]: METHOD_NAMES.GET_SCHEMA,
289
+ [mergedMessageTypes.updateSchema]: METHOD_NAMES.UPDATE_SCHEMA,
290
+ [mergedMessageTypes.checkPreview]: METHOD_NAMES.CHECK_PREVIEW,
291
+ [mergedMessageTypes.renderPreview]: METHOD_NAMES.RENDER_PREVIEW,
292
+ [mergedMessageTypes.cleanupPreview]: METHOD_NAMES.CLEANUP_PREVIEW,
293
+ [mergedMessageTypes.startRecording]: METHOD_NAMES.START_RECORDING,
294
+ [mergedMessageTypes.stopRecording]: METHOD_NAMES.STOP_RECORDING
295
+ };
296
+ const getMethodNameByType = (type) => {
297
+ return methodTypeToName[type] ?? null;
298
+ };
299
+ const sendResponse = (requestId, result) => {
300
+ const message = {
301
+ source: mergedSourceConfig.hostSource,
302
+ requestId,
303
+ ...result
304
+ };
305
+ const targetWindow = window.top ?? window;
306
+ targetWindow.postMessage(message, "*");
307
+ };
308
+ const pushSchema = (params, data) => {
309
+ if (!recordingParams.has(params)) {
310
+ return;
311
+ }
312
+ const message = {
313
+ source: mergedSourceConfig.hostSource,
314
+ type: mergedMessageTypes.schemaPush,
315
+ payload: {
316
+ success: true,
317
+ data,
318
+ params
319
+ }
320
+ };
321
+ const targetWindow = window.top ?? window;
322
+ targetWindow.postMessage(message, "*");
323
+ };
324
+ const handleMessage = (event) => {
325
+ const isFromSelf = event.source === window;
326
+ const isFromParent = window !== window.top && event.source === window.parent;
327
+ if (!isFromSelf && !isFromParent) return;
328
+ if (!event.data || event.data.source !== mergedSourceConfig.contentSource) return;
329
+ const { type, payload, requestId } = event.data;
330
+ if (!requestId) return;
331
+ const methodName = getMethodNameByType(type);
332
+ if (!methodName) return;
333
+ if (!coordinator.shouldRespond(methodName)) {
334
+ return;
335
+ }
336
+ const { getSchema: getSchema2, updateSchema: updateSchema2, renderPreview: renderPreview2 } = currentConfig;
337
+ let result;
338
+ switch (type) {
339
+ case mergedMessageTypes.getSchema: {
340
+ if (typeof getSchema2 !== "function") {
341
+ return;
342
+ }
343
+ const params = String(payload?.params ?? "");
344
+ try {
345
+ const data = getSchema2(params);
346
+ result = { success: true, data };
347
+ } catch (error) {
348
+ result = {
349
+ success: false,
350
+ error: error instanceof Error ? error.message : "\u83B7\u53D6 Schema \u5931\u8D25"
351
+ };
352
+ }
353
+ break;
354
+ }
355
+ case mergedMessageTypes.updateSchema: {
356
+ if (typeof updateSchema2 !== "function") {
357
+ return;
358
+ }
359
+ const schema = payload?.schema;
360
+ const params = String(payload?.params ?? "");
361
+ try {
362
+ const success = updateSchema2(schema, params);
363
+ result = { success };
364
+ } catch (error) {
365
+ result = {
366
+ success: false,
367
+ error: error instanceof Error ? error.message : "\u66F4\u65B0 Schema \u5931\u8D25"
368
+ };
369
+ }
370
+ break;
371
+ }
372
+ case mergedMessageTypes.checkPreview: {
373
+ result = { exists: typeof renderPreview2 === "function" };
374
+ break;
375
+ }
376
+ case mergedMessageTypes.renderPreview: {
377
+ if (typeof renderPreview2 !== "function") {
378
+ result = { success: false, error: "\u9884\u89C8\u529F\u80FD\u672A\u914D\u7F6E" };
379
+ break;
380
+ }
381
+ const schema = payload?.schema;
382
+ const containerId = String(payload?.containerId ?? "");
383
+ try {
384
+ if (previewCleanupFn) {
385
+ previewCleanupFn();
386
+ previewCleanupFn = null;
387
+ }
388
+ const cleanup = renderPreview2(schema, containerId);
389
+ if (typeof cleanup === "function") {
390
+ previewCleanupFn = cleanup;
391
+ }
392
+ result = { success: true };
393
+ } catch (error) {
394
+ result = {
395
+ success: false,
396
+ error: error instanceof Error ? error.message : "\u6E32\u67D3\u9884\u89C8\u5931\u8D25"
397
+ };
398
+ }
399
+ break;
400
+ }
401
+ case mergedMessageTypes.cleanupPreview: {
402
+ try {
403
+ if (previewCleanupFn) {
404
+ previewCleanupFn();
405
+ previewCleanupFn = null;
406
+ }
407
+ result = { success: true };
408
+ } catch (error) {
409
+ result = {
410
+ success: false,
411
+ error: error instanceof Error ? error.message : "\u6E05\u7406\u9884\u89C8\u5931\u8D25"
412
+ };
413
+ }
414
+ break;
415
+ }
416
+ case mergedMessageTypes.startRecording: {
417
+ const params = String(payload?.params ?? "");
418
+ recordingParams.add(params);
419
+ result = { success: true };
420
+ break;
421
+ }
422
+ case mergedMessageTypes.stopRecording: {
423
+ const params = String(payload?.params ?? "");
424
+ recordingParams.delete(params);
425
+ result = { success: true };
426
+ break;
427
+ }
428
+ default:
429
+ return;
430
+ }
431
+ const hasSameLevelSdks = coordinator.hasSameLevelCompetitors(methodName);
432
+ if (hasSameLevelSdks && shouldSkipFailedResponse(methodName, result)) {
433
+ return;
434
+ }
435
+ sendResponse(requestId, result);
436
+ };
437
+ window.addEventListener("message", handleMessage);
438
+ return {
439
+ cleanup: () => {
440
+ coordinator.destroy();
441
+ window.removeEventListener("message", handleMessage);
442
+ if (previewCleanupFn) {
443
+ previewCleanupFn();
444
+ previewCleanupFn = null;
445
+ }
446
+ recordingParams.clear();
447
+ },
448
+ recording: {
449
+ push: pushSchema
450
+ }
451
+ };
452
+ }
453
+
454
+ export {
455
+ createSchemaElementEditorBridge
456
+ };
@@ -0,0 +1,56 @@
1
+ import {
2
+ createSchemaElementEditorBridge
3
+ } from "./chunk-DLMX4NDA.js";
4
+
5
+ // src/react.ts
6
+ import { useEffect, useRef, useMemo, useCallback } from "react";
7
+ function useSchemaElementEditor(config) {
8
+ const {
9
+ getSchema,
10
+ updateSchema,
11
+ renderPreview,
12
+ sourceConfig,
13
+ messageTypes,
14
+ enabled,
15
+ sdkId,
16
+ level,
17
+ methodLevels
18
+ } = config;
19
+ const configRef = useRef({ getSchema, updateSchema, renderPreview });
20
+ const bridgeRef = useRef(null);
21
+ useEffect(() => {
22
+ configRef.current = { getSchema, updateSchema, renderPreview };
23
+ }, [getSchema, updateSchema, renderPreview]);
24
+ useEffect(() => {
25
+ if (enabled === false) {
26
+ return;
27
+ }
28
+ const proxyConfig = {
29
+ // 外层检查确保初始时函数存在才创建代理
30
+ // 内层使用可选链安全访问,配合类型断言确保类型正确
31
+ getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
32
+ updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
33
+ renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
34
+ sourceConfig,
35
+ messageTypes,
36
+ sdkId,
37
+ level,
38
+ methodLevels
39
+ };
40
+ const bridge = createSchemaElementEditorBridge(proxyConfig);
41
+ bridgeRef.current = bridge;
42
+ return () => {
43
+ bridge.cleanup();
44
+ bridgeRef.current = null;
45
+ };
46
+ }, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
47
+ const push = useCallback((params, data) => {
48
+ bridgeRef.current?.recording.push(params, data);
49
+ }, []);
50
+ const recording = useMemo(() => ({ push }), [push]);
51
+ return { recording };
52
+ }
53
+
54
+ export {
55
+ useSchemaElementEditor
56
+ };
package/dist/core.cjs CHANGED
@@ -48,6 +48,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
48
48
  };
49
49
 
50
50
  // src/coordinator.ts
51
+ function generateSdkId() {
52
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
53
+ return crypto.randomUUID();
54
+ }
55
+ return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
56
+ }
51
57
  var SdkCoordinator = class {
52
58
  constructor(config) {
53
59
  /**
@@ -95,7 +101,7 @@ var SdkCoordinator = class {
95
101
  break;
96
102
  }
97
103
  };
98
- this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
104
+ this.sdkId = config.sdkId || generateSdkId();
99
105
  this.messageSource = config.messageSource;
100
106
  this.level = config.level ?? 0;
101
107
  this.methodLevels = config.methodLevels ?? {};
package/dist/core.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-432BCQVI.js";
2
2
  import {
3
3
  createSchemaElementEditorBridge
4
- } from "./chunk-LJJYJHOZ.js";
4
+ } from "./chunk-DLMX4NDA.js";
5
5
  export {
6
6
  createSchemaElementEditorBridge
7
7
  };
package/dist/index.cjs CHANGED
@@ -52,6 +52,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
52
52
  };
53
53
 
54
54
  // src/coordinator.ts
55
+ function generateSdkId() {
56
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
57
+ return crypto.randomUUID();
58
+ }
59
+ return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
60
+ }
55
61
  var SdkCoordinator = class {
56
62
  constructor(config) {
57
63
  /**
@@ -99,7 +105,7 @@ var SdkCoordinator = class {
99
105
  break;
100
106
  }
101
107
  };
102
- this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
108
+ this.sdkId = config.sdkId || generateSdkId();
103
109
  this.messageSource = config.messageSource;
104
110
  this.level = config.level ?? 0;
105
111
  this.methodLevels = config.methodLevels ?? {};
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./chunk-432BCQVI.js";
2
2
  import {
3
3
  useSchemaElementEditor
4
- } from "./chunk-Q6EJUFM6.js";
4
+ } from "./chunk-MK3EDWC5.js";
5
5
  import {
6
6
  createSchemaElementEditorBridge
7
- } from "./chunk-LJJYJHOZ.js";
7
+ } from "./chunk-DLMX4NDA.js";
8
8
  export {
9
9
  createSchemaElementEditorBridge,
10
10
  useSchemaElementEditor
package/dist/react.cjs CHANGED
@@ -49,6 +49,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
49
49
  };
50
50
 
51
51
  // src/coordinator.ts
52
+ function generateSdkId() {
53
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
54
+ return crypto.randomUUID();
55
+ }
56
+ return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
57
+ }
52
58
  var SdkCoordinator = class {
53
59
  constructor(config) {
54
60
  /**
@@ -96,7 +102,7 @@ var SdkCoordinator = class {
96
102
  break;
97
103
  }
98
104
  };
99
- this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
105
+ this.sdkId = config.sdkId || generateSdkId();
100
106
  this.messageSource = config.messageSource;
101
107
  this.level = config.level ?? 0;
102
108
  this.methodLevels = config.methodLevels ?? {};
package/dist/react.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useSchemaElementEditor
3
- } from "./chunk-Q6EJUFM6.js";
4
- import "./chunk-LJJYJHOZ.js";
3
+ } from "./chunk-MK3EDWC5.js";
4
+ import "./chunk-DLMX4NDA.js";
5
5
  export {
6
6
  useSchemaElementEditor
7
7
  };
package/dist/vue.cjs CHANGED
@@ -49,6 +49,12 @@ var SDK_COORDINATION_MESSAGE_TYPES = {
49
49
  };
50
50
 
51
51
  // src/coordinator.ts
52
+ function generateSdkId() {
53
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
54
+ return crypto.randomUUID();
55
+ }
56
+ return `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
57
+ }
52
58
  var SdkCoordinator = class {
53
59
  constructor(config) {
54
60
  /**
@@ -96,7 +102,7 @@ var SdkCoordinator = class {
96
102
  break;
97
103
  }
98
104
  };
99
- this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
105
+ this.sdkId = config.sdkId || generateSdkId();
100
106
  this.messageSource = config.messageSource;
101
107
  this.level = config.level ?? 0;
102
108
  this.methodLevels = config.methodLevels ?? {};
package/dist/vue.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createSchemaElementEditorBridge
3
- } from "./chunk-LJJYJHOZ.js";
3
+ } from "./chunk-DLMX4NDA.js";
4
4
 
5
5
  // src/vue.ts
6
6
  import { onMounted, onUnmounted, watch, toValue } from "vue";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schema-element-editor/host-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Schema Element Editor (SEE) 插件宿主接入 SDK,支持 React/Vue/纯 JS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",