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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,457 @@
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 (renderPreview !== void 0) {
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
+ const exists = typeof renderPreview2 === "function";
374
+ result = { exists };
375
+ break;
376
+ }
377
+ case mergedMessageTypes.renderPreview: {
378
+ if (typeof renderPreview2 !== "function") {
379
+ result = { success: false, error: "\u9884\u89C8\u529F\u80FD\u672A\u914D\u7F6E" };
380
+ break;
381
+ }
382
+ const schema = payload?.schema;
383
+ const containerId = String(payload?.containerId ?? "");
384
+ try {
385
+ if (previewCleanupFn) {
386
+ previewCleanupFn();
387
+ previewCleanupFn = null;
388
+ }
389
+ const cleanup = renderPreview2(schema, containerId);
390
+ if (typeof cleanup === "function") {
391
+ previewCleanupFn = cleanup;
392
+ }
393
+ result = { success: true };
394
+ } catch (error) {
395
+ result = {
396
+ success: false,
397
+ error: error instanceof Error ? error.message : "\u6E32\u67D3\u9884\u89C8\u5931\u8D25"
398
+ };
399
+ }
400
+ break;
401
+ }
402
+ case mergedMessageTypes.cleanupPreview: {
403
+ try {
404
+ if (previewCleanupFn) {
405
+ previewCleanupFn();
406
+ previewCleanupFn = null;
407
+ }
408
+ result = { success: true };
409
+ } catch (error) {
410
+ result = {
411
+ success: false,
412
+ error: error instanceof Error ? error.message : "\u6E05\u7406\u9884\u89C8\u5931\u8D25"
413
+ };
414
+ }
415
+ break;
416
+ }
417
+ case mergedMessageTypes.startRecording: {
418
+ const params = String(payload?.params ?? "");
419
+ recordingParams.add(params);
420
+ result = { success: true };
421
+ break;
422
+ }
423
+ case mergedMessageTypes.stopRecording: {
424
+ const params = String(payload?.params ?? "");
425
+ recordingParams.delete(params);
426
+ result = { success: true };
427
+ break;
428
+ }
429
+ default:
430
+ return;
431
+ }
432
+ const hasSameLevelSdks = coordinator.hasSameLevelCompetitors(methodName);
433
+ if (hasSameLevelSdks && shouldSkipFailedResponse(methodName, result)) {
434
+ return;
435
+ }
436
+ sendResponse(requestId, result);
437
+ };
438
+ window.addEventListener("message", handleMessage);
439
+ return {
440
+ cleanup: () => {
441
+ coordinator.destroy();
442
+ window.removeEventListener("message", handleMessage);
443
+ if (previewCleanupFn) {
444
+ previewCleanupFn();
445
+ previewCleanupFn = null;
446
+ }
447
+ recordingParams.clear();
448
+ },
449
+ recording: {
450
+ push: pushSchema
451
+ }
452
+ };
453
+ }
454
+
455
+ export {
456
+ createSchemaElementEditorBridge
457
+ };
@@ -0,0 +1,56 @@
1
+ import {
2
+ createSchemaElementEditorBridge
3
+ } from "./chunk-4TXQK4JI.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
+ };
@@ -0,0 +1,60 @@
1
+ import {
2
+ createSchemaElementEditorBridge
3
+ } from "./chunk-H36IVM7V.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 需要特殊处理:
34
+ // - undefined: 不传递(不参与竞争)
35
+ // - null: 传递 null(参与竞争但阻止预览)
36
+ // - function: 创建代理函数
37
+ renderPreview: configRef.current.renderPreview === null ? null : configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
38
+ sourceConfig,
39
+ messageTypes,
40
+ sdkId,
41
+ level,
42
+ methodLevels
43
+ };
44
+ const bridge = createSchemaElementEditorBridge(proxyConfig);
45
+ bridgeRef.current = bridge;
46
+ return () => {
47
+ bridge.cleanup();
48
+ bridgeRef.current = null;
49
+ };
50
+ }, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
51
+ const push = useCallback((params, data) => {
52
+ bridgeRef.current?.recording.push(params, data);
53
+ }, []);
54
+ const recording = useMemo(() => ({ push }), [push]);
55
+ return { recording };
56
+ }
57
+
58
+ export {
59
+ useSchemaElementEditor
60
+ };
package/dist/core.cjs CHANGED
@@ -291,7 +291,7 @@ function createSchemaElementEditorBridge(config) {
291
291
  const implementedMethods = [];
292
292
  if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
293
293
  if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
294
- if (typeof renderPreview === "function") {
294
+ if (renderPreview !== void 0) {
295
295
  implementedMethods.push(
296
296
  METHOD_NAMES.CHECK_PREVIEW,
297
297
  METHOD_NAMES.RENDER_PREVIEW,
@@ -396,7 +396,8 @@ function createSchemaElementEditorBridge(config) {
396
396
  break;
397
397
  }
398
398
  case mergedMessageTypes.checkPreview: {
399
- result = { exists: typeof renderPreview2 === "function" };
399
+ const exists = typeof renderPreview2 === "function";
400
+ result = { exists };
400
401
  break;
401
402
  }
402
403
  case mergedMessageTypes.renderPreview: {
package/dist/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as SchemaElementEditorConfig, c as SchemaElementEditorBridge } from './types-D2ZJx8T_.cjs';
1
+ import { b as SchemaElementEditorConfig, c as SchemaElementEditorBridge } from './types-BSn4QaId.cjs';
2
2
 
3
3
  /**
4
4
  * Schema Element Editor Host SDK - Bridge
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as SchemaElementEditorConfig, c as SchemaElementEditorBridge } from './types-D2ZJx8T_.js';
1
+ import { b as SchemaElementEditorConfig, c as SchemaElementEditorBridge } from './types-BSn4QaId.js';
2
2
 
3
3
  /**
4
4
  * Schema Element Editor Host SDK - Bridge
package/dist/core.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-432BCQVI.js";
2
2
  import {
3
3
  createSchemaElementEditorBridge
4
- } from "./chunk-DLMX4NDA.js";
4
+ } from "./chunk-H36IVM7V.js";
5
5
  export {
6
6
  createSchemaElementEditorBridge
7
7
  };
package/dist/index.cjs CHANGED
@@ -295,7 +295,7 @@ function createSchemaElementEditorBridge(config) {
295
295
  const implementedMethods = [];
296
296
  if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
297
297
  if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
298
- if (typeof renderPreview === "function") {
298
+ if (renderPreview !== void 0) {
299
299
  implementedMethods.push(
300
300
  METHOD_NAMES.CHECK_PREVIEW,
301
301
  METHOD_NAMES.RENDER_PREVIEW,
@@ -400,7 +400,8 @@ function createSchemaElementEditorBridge(config) {
400
400
  break;
401
401
  }
402
402
  case mergedMessageTypes.checkPreview: {
403
- result = { exists: typeof renderPreview2 === "function" };
403
+ const exists = typeof renderPreview2 === "function";
404
+ result = { exists };
404
405
  break;
405
406
  }
406
407
  case mergedMessageTypes.renderPreview: {
@@ -508,7 +509,11 @@ function useSchemaElementEditor(config) {
508
509
  // 内层使用可选链安全访问,配合类型断言确保类型正确
509
510
  getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
510
511
  updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
511
- renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
512
+ // renderPreview 需要特殊处理:
513
+ // - undefined: 不传递(不参与竞争)
514
+ // - null: 传递 null(参与竞争但阻止预览)
515
+ // - function: 创建代理函数
516
+ renderPreview: configRef.current.renderPreview === null ? null : configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
512
517
  sourceConfig,
513
518
  messageTypes,
514
519
  sdkId,
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { useSchemaElementEditor } from './react.cjs';
1
+ export { ReactSchemaElementEditorConfig, useSchemaElementEditor } from './react.cjs';
2
2
  export { createSchemaElementEditorBridge } from './core.cjs';
3
- export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-D2ZJx8T_.cjs';
3
+ export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-BSn4QaId.cjs';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { useSchemaElementEditor } from './react.js';
1
+ export { ReactSchemaElementEditorConfig, useSchemaElementEditor } from './react.js';
2
2
  export { createSchemaElementEditorBridge } from './core.js';
3
- export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-D2ZJx8T_.js';
3
+ export { M as MethodLevelConfig, P as PostMessageSourceConfig, a as PostMessageTypeConfig, c as SchemaElementEditorBridge, b as SchemaElementEditorConfig, d as SchemaElementEditorRecording, S as SchemaValue } from './types-BSn4QaId.js';
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./chunk-432BCQVI.js";
2
2
  import {
3
3
  useSchemaElementEditor
4
- } from "./chunk-MK3EDWC5.js";
4
+ } from "./chunk-X4JAISLV.js";
5
5
  import {
6
6
  createSchemaElementEditorBridge
7
- } from "./chunk-DLMX4NDA.js";
7
+ } from "./chunk-H36IVM7V.js";
8
8
  export {
9
9
  createSchemaElementEditorBridge,
10
10
  useSchemaElementEditor