@schema-element-editor/host-sdk 2.0.2 → 2.1.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.
- package/LICENSE +21 -0
- package/dist/chunk-3OZ7E3LK.js +391 -0
- package/dist/chunk-432BCQVI.js +0 -0
- package/dist/chunk-5URPGJPF.js +391 -0
- package/dist/chunk-APBK7FQZ.js +437 -0
- package/dist/chunk-BVGJ5UDR.js +390 -0
- package/dist/chunk-D67MT673.js +44 -0
- package/dist/chunk-DGO4Z6NW.js +399 -0
- package/dist/chunk-EIQP2PZ6.js +56 -0
- package/dist/chunk-IYQL6QJY.js +60 -0
- package/dist/chunk-LD4OEJ4X.js +56 -0
- package/dist/chunk-LJJYJHOZ.js +450 -0
- package/dist/chunk-MQTHVJYR.js +54 -0
- package/dist/chunk-NF4H2OT3.js +355 -0
- package/dist/chunk-NWZVU75I.js +54 -0
- package/dist/chunk-Q6EJUFM6.js +56 -0
- package/dist/chunk-R4LAS3QA.js +54 -0
- package/dist/chunk-XIS7CAP4.js +54 -0
- package/dist/chunk-Y2OF4YA4.js +54 -0
- package/dist/core.cjs +282 -1
- package/dist/core.d.cts +16 -81
- package/dist/core.d.ts +16 -81
- package/dist/core.js +2 -1
- package/dist/index.cjs +301 -11
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/react.cjs +301 -11
- package/dist/react.d.cts +2 -3
- package/dist/react.d.ts +2 -3
- package/dist/react.js +2 -2
- package/dist/types-D2ZJx8T_.d.cts +103 -0
- package/dist/types-D2ZJx8T_.d.ts +103 -0
- package/dist/vue.cjs +300 -5
- package/dist/vue.d.cts +17 -3
- package/dist/vue.d.ts +17 -3
- package/dist/vue.js +20 -4
- package/package.json +5 -6
package/dist/react.cjs
CHANGED
|
@@ -25,11 +25,12 @@ __export(react_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(react_exports);
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/constants.ts
|
|
29
29
|
var DEFAULT_SOURCE_CONFIG = {
|
|
30
30
|
contentSource: "schema-element-editor-content",
|
|
31
31
|
hostSource: "schema-element-editor-host"
|
|
32
32
|
};
|
|
33
|
+
var SDK_COORDINATOR_SOURCE = "schema-element-editor-sdk-coordinator";
|
|
33
34
|
var DEFAULT_MESSAGE_TYPES = {
|
|
34
35
|
getSchema: "GET_SCHEMA",
|
|
35
36
|
updateSchema: "UPDATE_SCHEMA",
|
|
@@ -41,8 +42,239 @@ var DEFAULT_MESSAGE_TYPES = {
|
|
|
41
42
|
stopRecording: "STOP_RECORDING",
|
|
42
43
|
schemaPush: "SCHEMA_PUSH"
|
|
43
44
|
};
|
|
45
|
+
var SDK_COORDINATION_MESSAGE_TYPES = {
|
|
46
|
+
register: "SDK_REGISTER",
|
|
47
|
+
unregister: "SDK_UNREGISTER",
|
|
48
|
+
query: "SDK_QUERY"
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/coordinator.ts
|
|
52
|
+
var SdkCoordinator = class {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
/**
|
|
55
|
+
* SDK 销毁标志
|
|
56
|
+
*
|
|
57
|
+
* 作用:防止在 cleanup() 执行期间,监听器移除前仍然响应请求
|
|
58
|
+
*
|
|
59
|
+
* 场景:cleanup() 中先调用 destroy()(设置 isDestroyed = true),
|
|
60
|
+
* 然后才移除 handleMessage 监听器。在这个微小的时间窗口内,
|
|
61
|
+
* 如果插件请求到达,没有 isDestroyed 检查会导致已销毁的 SDK 仍然响应。
|
|
62
|
+
*/
|
|
63
|
+
this.isDestroyed = false;
|
|
64
|
+
/**
|
|
65
|
+
* 存储比当前 SDK 优先级更高的其他 SDK ID
|
|
66
|
+
* 按方法分类:如果某个方法的集合不为空,说明有更高优先级的 SDK 应该处理该方法
|
|
67
|
+
*
|
|
68
|
+
* 优化:只为当前 SDK 实现了的方法维护优先级集合
|
|
69
|
+
*/
|
|
70
|
+
this.higherLevelSDKs = {};
|
|
71
|
+
/**
|
|
72
|
+
* 存储与当前 SDK 优先级相同的其他 SDK ID
|
|
73
|
+
* 按方法分类:用于判断是否需要在执行失败时跳过响应
|
|
74
|
+
*
|
|
75
|
+
* 当有同级竞争者时,SDK在执行失败/无数据时会跳过响应,让其他SDK有机会响应
|
|
76
|
+
*/
|
|
77
|
+
this.sameLevelSDKs = {};
|
|
78
|
+
/**
|
|
79
|
+
* 处理 SDK 协调消息
|
|
80
|
+
*/
|
|
81
|
+
this.handleCoordinationMessage = (event) => {
|
|
82
|
+
const isFromSelf = event.source === window;
|
|
83
|
+
const isFromParent = window !== window.top && event.source === window.parent;
|
|
84
|
+
if (!isFromSelf && !isFromParent) return;
|
|
85
|
+
const data = event.data;
|
|
86
|
+
if (!data || data.source !== SDK_COORDINATOR_SOURCE) return;
|
|
87
|
+
switch (data.type) {
|
|
88
|
+
case SDK_COORDINATION_MESSAGE_TYPES.query:
|
|
89
|
+
this.sendRegister();
|
|
90
|
+
break;
|
|
91
|
+
case SDK_COORDINATION_MESSAGE_TYPES.register:
|
|
92
|
+
this.handleSdkRegister(data.payload);
|
|
93
|
+
break;
|
|
94
|
+
case SDK_COORDINATION_MESSAGE_TYPES.unregister:
|
|
95
|
+
this.handleSdkUnregister(data.payload.sdkId);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
100
|
+
this.messageSource = config.messageSource;
|
|
101
|
+
this.level = config.level ?? 0;
|
|
102
|
+
this.methodLevels = config.methodLevels ?? {};
|
|
103
|
+
this.implementedMethods = config.implementedMethods;
|
|
104
|
+
this.implementedMethods.forEach((method) => {
|
|
105
|
+
this.higherLevelSDKs[method] = /* @__PURE__ */ new Set();
|
|
106
|
+
this.sameLevelSDKs[method] = /* @__PURE__ */ new Set();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 初始化协调器
|
|
111
|
+
*/
|
|
112
|
+
init() {
|
|
113
|
+
window.addEventListener("message", this.handleCoordinationMessage);
|
|
114
|
+
this.sendQuery();
|
|
115
|
+
this.sendRegister();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 销毁协调器
|
|
119
|
+
*/
|
|
120
|
+
destroy() {
|
|
121
|
+
this.isDestroyed = true;
|
|
122
|
+
this.sendUnregister();
|
|
123
|
+
window.removeEventListener("message", this.handleCoordinationMessage);
|
|
124
|
+
Object.values(this.higherLevelSDKs).forEach((set) => set.clear());
|
|
125
|
+
Object.values(this.sameLevelSDKs).forEach((set) => set.clear());
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 判断是否应该响应某个方法的请求
|
|
129
|
+
* @param method - 方法名
|
|
130
|
+
* @returns 是否应该响应
|
|
131
|
+
*/
|
|
132
|
+
shouldRespond(method) {
|
|
133
|
+
if (this.isDestroyed) return false;
|
|
134
|
+
if (!this.implementedMethods.includes(method)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const higherSDKs = this.higherLevelSDKs[method];
|
|
138
|
+
return !higherSDKs || higherSDKs.size === 0;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 判断某个方法是否有相同优先级的竞争者
|
|
142
|
+
* @param method - 方法名
|
|
143
|
+
* @returns 是否存在同级竞争者
|
|
144
|
+
*/
|
|
145
|
+
hasSameLevelCompetitors(method) {
|
|
146
|
+
const sameSDKs = this.sameLevelSDKs[method];
|
|
147
|
+
return sameSDKs ? sameSDKs.size > 0 : false;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 获取方法的优先级
|
|
151
|
+
*/
|
|
152
|
+
getMethodLevel(method) {
|
|
153
|
+
return this.methodLevels[method] ?? this.level;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 处理其他 SDK 的注册
|
|
157
|
+
*/
|
|
158
|
+
handleSdkRegister(info) {
|
|
159
|
+
if (info.sdkId === this.sdkId) return;
|
|
160
|
+
if (info.messageSource !== this.messageSource) return;
|
|
161
|
+
this.implementedMethods.forEach((method) => {
|
|
162
|
+
if (!info.implementedMethods.includes(method)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const myLevel = this.getMethodLevel(method);
|
|
166
|
+
const otherLevel = info.methodLevels[method] ?? info.level;
|
|
167
|
+
if (otherLevel > myLevel) {
|
|
168
|
+
this.higherLevelSDKs[method].add(info.sdkId);
|
|
169
|
+
this.sameLevelSDKs[method].delete(info.sdkId);
|
|
170
|
+
} else if (otherLevel === myLevel) {
|
|
171
|
+
this.sameLevelSDKs[method].add(info.sdkId);
|
|
172
|
+
this.higherLevelSDKs[method].delete(info.sdkId);
|
|
173
|
+
} else {
|
|
174
|
+
this.higherLevelSDKs[method].delete(info.sdkId);
|
|
175
|
+
this.sameLevelSDKs[method].delete(info.sdkId);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 处理其他 SDK 的注销
|
|
181
|
+
*/
|
|
182
|
+
handleSdkUnregister(sdkId) {
|
|
183
|
+
Object.values(this.higherLevelSDKs).forEach((set) => {
|
|
184
|
+
set.delete(sdkId);
|
|
185
|
+
});
|
|
186
|
+
Object.values(this.sameLevelSDKs).forEach((set) => {
|
|
187
|
+
set.delete(sdkId);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 发送查询消息
|
|
192
|
+
*/
|
|
193
|
+
sendQuery() {
|
|
194
|
+
const message = {
|
|
195
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
196
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.query,
|
|
197
|
+
payload: { sdkId: this.sdkId }
|
|
198
|
+
};
|
|
199
|
+
this.postCoordinationMessage(message);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 发送注册消息
|
|
203
|
+
*/
|
|
204
|
+
sendRegister() {
|
|
205
|
+
const message = {
|
|
206
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
207
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.register,
|
|
208
|
+
payload: {
|
|
209
|
+
sdkId: this.sdkId,
|
|
210
|
+
messageSource: this.messageSource,
|
|
211
|
+
level: this.level,
|
|
212
|
+
methodLevels: this.methodLevels,
|
|
213
|
+
implementedMethods: this.implementedMethods
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
this.postCoordinationMessage(message);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 发送注销消息
|
|
220
|
+
*/
|
|
221
|
+
sendUnregister() {
|
|
222
|
+
const message = {
|
|
223
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
224
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.unregister,
|
|
225
|
+
payload: { sdkId: this.sdkId }
|
|
226
|
+
};
|
|
227
|
+
this.postCoordinationMessage(message);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* 发送协调消息
|
|
231
|
+
*/
|
|
232
|
+
postCoordinationMessage(message) {
|
|
233
|
+
window.postMessage(message, "*");
|
|
234
|
+
if (window.top && window.top !== window) {
|
|
235
|
+
window.top.postMessage(message, "*");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/bridge.ts
|
|
241
|
+
var METHOD_NAMES = {
|
|
242
|
+
GET_SCHEMA: "getSchema",
|
|
243
|
+
UPDATE_SCHEMA: "updateSchema",
|
|
244
|
+
CHECK_PREVIEW: "checkPreview",
|
|
245
|
+
RENDER_PREVIEW: "renderPreview",
|
|
246
|
+
CLEANUP_PREVIEW: "cleanupPreview",
|
|
247
|
+
START_RECORDING: "startRecording",
|
|
248
|
+
STOP_RECORDING: "stopRecording"
|
|
249
|
+
};
|
|
250
|
+
function shouldSkipFailedResponse(method, result) {
|
|
251
|
+
switch (method) {
|
|
252
|
+
case METHOD_NAMES.GET_SCHEMA:
|
|
253
|
+
return result.success === true && result.data === void 0;
|
|
254
|
+
case METHOD_NAMES.UPDATE_SCHEMA:
|
|
255
|
+
return result.success === false;
|
|
256
|
+
case METHOD_NAMES.RENDER_PREVIEW:
|
|
257
|
+
case METHOD_NAMES.CLEANUP_PREVIEW:
|
|
258
|
+
return result.success === false;
|
|
259
|
+
case METHOD_NAMES.CHECK_PREVIEW:
|
|
260
|
+
case METHOD_NAMES.START_RECORDING:
|
|
261
|
+
case METHOD_NAMES.STOP_RECORDING:
|
|
262
|
+
return false;
|
|
263
|
+
default:
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
44
267
|
function createSchemaElementEditorBridge(config) {
|
|
45
|
-
const {
|
|
268
|
+
const {
|
|
269
|
+
getSchema,
|
|
270
|
+
updateSchema,
|
|
271
|
+
renderPreview,
|
|
272
|
+
sourceConfig,
|
|
273
|
+
messageTypes,
|
|
274
|
+
sdkId,
|
|
275
|
+
level,
|
|
276
|
+
methodLevels
|
|
277
|
+
} = config;
|
|
46
278
|
const mergedSourceConfig = {
|
|
47
279
|
...DEFAULT_SOURCE_CONFIG,
|
|
48
280
|
...sourceConfig
|
|
@@ -51,9 +283,40 @@ function createSchemaElementEditorBridge(config) {
|
|
|
51
283
|
...DEFAULT_MESSAGE_TYPES,
|
|
52
284
|
...messageTypes
|
|
53
285
|
};
|
|
286
|
+
const implementedMethods = [];
|
|
287
|
+
if (typeof getSchema === "function") implementedMethods.push(METHOD_NAMES.GET_SCHEMA);
|
|
288
|
+
if (typeof updateSchema === "function") implementedMethods.push(METHOD_NAMES.UPDATE_SCHEMA);
|
|
289
|
+
if (typeof renderPreview === "function") {
|
|
290
|
+
implementedMethods.push(
|
|
291
|
+
METHOD_NAMES.CHECK_PREVIEW,
|
|
292
|
+
METHOD_NAMES.RENDER_PREVIEW,
|
|
293
|
+
METHOD_NAMES.CLEANUP_PREVIEW
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
implementedMethods.push(METHOD_NAMES.START_RECORDING, METHOD_NAMES.STOP_RECORDING);
|
|
297
|
+
const coordinator = new SdkCoordinator({
|
|
298
|
+
sdkId,
|
|
299
|
+
messageSource: mergedSourceConfig.contentSource,
|
|
300
|
+
level,
|
|
301
|
+
methodLevels,
|
|
302
|
+
implementedMethods
|
|
303
|
+
});
|
|
304
|
+
coordinator.init();
|
|
54
305
|
let previewCleanupFn = null;
|
|
55
306
|
const recordingParams = /* @__PURE__ */ new Set();
|
|
56
307
|
const currentConfig = { getSchema, updateSchema, renderPreview };
|
|
308
|
+
const methodTypeToName = {
|
|
309
|
+
[mergedMessageTypes.getSchema]: METHOD_NAMES.GET_SCHEMA,
|
|
310
|
+
[mergedMessageTypes.updateSchema]: METHOD_NAMES.UPDATE_SCHEMA,
|
|
311
|
+
[mergedMessageTypes.checkPreview]: METHOD_NAMES.CHECK_PREVIEW,
|
|
312
|
+
[mergedMessageTypes.renderPreview]: METHOD_NAMES.RENDER_PREVIEW,
|
|
313
|
+
[mergedMessageTypes.cleanupPreview]: METHOD_NAMES.CLEANUP_PREVIEW,
|
|
314
|
+
[mergedMessageTypes.startRecording]: METHOD_NAMES.START_RECORDING,
|
|
315
|
+
[mergedMessageTypes.stopRecording]: METHOD_NAMES.STOP_RECORDING
|
|
316
|
+
};
|
|
317
|
+
const getMethodNameByType = (type) => {
|
|
318
|
+
return methodTypeToName[type] ?? null;
|
|
319
|
+
};
|
|
57
320
|
const sendResponse = (requestId, result) => {
|
|
58
321
|
const message = {
|
|
59
322
|
source: mergedSourceConfig.hostSource,
|
|
@@ -86,10 +349,18 @@ function createSchemaElementEditorBridge(config) {
|
|
|
86
349
|
if (!event.data || event.data.source !== mergedSourceConfig.contentSource) return;
|
|
87
350
|
const { type, payload, requestId } = event.data;
|
|
88
351
|
if (!requestId) return;
|
|
352
|
+
const methodName = getMethodNameByType(type);
|
|
353
|
+
if (!methodName) return;
|
|
354
|
+
if (!coordinator.shouldRespond(methodName)) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
89
357
|
const { getSchema: getSchema2, updateSchema: updateSchema2, renderPreview: renderPreview2 } = currentConfig;
|
|
90
358
|
let result;
|
|
91
359
|
switch (type) {
|
|
92
360
|
case mergedMessageTypes.getSchema: {
|
|
361
|
+
if (typeof getSchema2 !== "function") {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
93
364
|
const params = String(payload?.params ?? "");
|
|
94
365
|
try {
|
|
95
366
|
const data = getSchema2(params);
|
|
@@ -103,6 +374,9 @@ function createSchemaElementEditorBridge(config) {
|
|
|
103
374
|
break;
|
|
104
375
|
}
|
|
105
376
|
case mergedMessageTypes.updateSchema: {
|
|
377
|
+
if (typeof updateSchema2 !== "function") {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
106
380
|
const schema = payload?.schema;
|
|
107
381
|
const params = String(payload?.params ?? "");
|
|
108
382
|
try {
|
|
@@ -175,11 +449,16 @@ function createSchemaElementEditorBridge(config) {
|
|
|
175
449
|
default:
|
|
176
450
|
return;
|
|
177
451
|
}
|
|
452
|
+
const hasSameLevelSdks = coordinator.hasSameLevelCompetitors(methodName);
|
|
453
|
+
if (hasSameLevelSdks && shouldSkipFailedResponse(methodName, result)) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
178
456
|
sendResponse(requestId, result);
|
|
179
457
|
};
|
|
180
458
|
window.addEventListener("message", handleMessage);
|
|
181
459
|
return {
|
|
182
460
|
cleanup: () => {
|
|
461
|
+
coordinator.destroy();
|
|
183
462
|
window.removeEventListener("message", handleMessage);
|
|
184
463
|
if (previewCleanupFn) {
|
|
185
464
|
previewCleanupFn();
|
|
@@ -195,7 +474,17 @@ function createSchemaElementEditorBridge(config) {
|
|
|
195
474
|
|
|
196
475
|
// src/react.ts
|
|
197
476
|
function useSchemaElementEditor(config) {
|
|
198
|
-
const {
|
|
477
|
+
const {
|
|
478
|
+
getSchema,
|
|
479
|
+
updateSchema,
|
|
480
|
+
renderPreview,
|
|
481
|
+
sourceConfig,
|
|
482
|
+
messageTypes,
|
|
483
|
+
enabled,
|
|
484
|
+
sdkId,
|
|
485
|
+
level,
|
|
486
|
+
methodLevels
|
|
487
|
+
} = config;
|
|
199
488
|
const configRef = (0, import_react.useRef)({ getSchema, updateSchema, renderPreview });
|
|
200
489
|
const bridgeRef = (0, import_react.useRef)(null);
|
|
201
490
|
(0, import_react.useEffect)(() => {
|
|
@@ -203,18 +492,19 @@ function useSchemaElementEditor(config) {
|
|
|
203
492
|
}, [getSchema, updateSchema, renderPreview]);
|
|
204
493
|
(0, import_react.useEffect)(() => {
|
|
205
494
|
if (enabled === false) {
|
|
206
|
-
if (bridgeRef.current && typeof bridgeRef.current.cleanup === "function") {
|
|
207
|
-
bridgeRef.current.cleanup();
|
|
208
|
-
bridgeRef.current = null;
|
|
209
|
-
}
|
|
210
495
|
return;
|
|
211
496
|
}
|
|
212
497
|
const proxyConfig = {
|
|
213
|
-
|
|
214
|
-
|
|
498
|
+
// 外层检查确保初始时函数存在才创建代理
|
|
499
|
+
// 内层使用可选链安全访问,配合类型断言确保类型正确
|
|
500
|
+
getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema?.(params) : void 0,
|
|
501
|
+
updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema?.(schema, params) : void 0,
|
|
215
502
|
renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
|
|
216
503
|
sourceConfig,
|
|
217
|
-
messageTypes
|
|
504
|
+
messageTypes,
|
|
505
|
+
sdkId,
|
|
506
|
+
level,
|
|
507
|
+
methodLevels
|
|
218
508
|
};
|
|
219
509
|
const bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
220
510
|
bridgeRef.current = bridge;
|
|
@@ -222,7 +512,7 @@ function useSchemaElementEditor(config) {
|
|
|
222
512
|
bridge.cleanup();
|
|
223
513
|
bridgeRef.current = null;
|
|
224
514
|
};
|
|
225
|
-
}, [enabled, configRef, sourceConfig, messageTypes]);
|
|
515
|
+
}, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
|
|
226
516
|
const push = (0, import_react.useCallback)((params, data) => {
|
|
227
517
|
bridgeRef.current?.recording.push(params, data);
|
|
228
518
|
}, []);
|
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SchemaElementEditorConfig, SchemaElementEditorRecording } from './
|
|
2
|
-
export { PostMessageSourceConfig, PostMessageTypeConfig, SchemaElementEditorBridge, SchemaValue } from './core.cjs';
|
|
1
|
+
import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.cjs';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Schema Element Editor Host SDK - React
|
|
@@ -51,4 +50,4 @@ interface UseSchemaElementEditorReturn {
|
|
|
51
50
|
*/
|
|
52
51
|
declare function useSchemaElementEditor(config: ReactSchemaElementEditorConfig): UseSchemaElementEditorReturn;
|
|
53
52
|
|
|
54
|
-
export { type ReactSchemaElementEditorConfig,
|
|
53
|
+
export { type ReactSchemaElementEditorConfig, type UseSchemaElementEditorReturn, useSchemaElementEditor };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SchemaElementEditorConfig, SchemaElementEditorRecording } from './
|
|
2
|
-
export { PostMessageSourceConfig, PostMessageTypeConfig, SchemaElementEditorBridge, SchemaValue } from './core.js';
|
|
1
|
+
import { b as SchemaElementEditorConfig, d as SchemaElementEditorRecording } from './types-D2ZJx8T_.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Schema Element Editor Host SDK - React
|
|
@@ -51,4 +50,4 @@ interface UseSchemaElementEditorReturn {
|
|
|
51
50
|
*/
|
|
52
51
|
declare function useSchemaElementEditor(config: ReactSchemaElementEditorConfig): UseSchemaElementEditorReturn;
|
|
53
52
|
|
|
54
|
-
export { type ReactSchemaElementEditorConfig,
|
|
53
|
+
export { type ReactSchemaElementEditorConfig, type UseSchemaElementEditorReturn, useSchemaElementEditor };
|
package/dist/react.js
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Element Editor Host SDK - Types
|
|
3
|
+
* 类型定义
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Schema 数据类型
|
|
7
|
+
* 支持所有 JSON.parse 可返回的类型
|
|
8
|
+
*/
|
|
9
|
+
type SchemaValue = Record<string, unknown> | unknown[] | string | number | boolean | null;
|
|
10
|
+
/** postMessage 消息标识配置 */
|
|
11
|
+
interface PostMessageSourceConfig {
|
|
12
|
+
/** 插件端发送消息的 source 标识 */
|
|
13
|
+
contentSource: string;
|
|
14
|
+
/** 宿主端响应消息的 source 标识 */
|
|
15
|
+
hostSource: string;
|
|
16
|
+
}
|
|
17
|
+
/** postMessage 消息类型配置 */
|
|
18
|
+
interface PostMessageTypeConfig {
|
|
19
|
+
getSchema: string;
|
|
20
|
+
updateSchema: string;
|
|
21
|
+
checkPreview: string;
|
|
22
|
+
renderPreview: string;
|
|
23
|
+
cleanupPreview: string;
|
|
24
|
+
startRecording: string;
|
|
25
|
+
stopRecording: string;
|
|
26
|
+
schemaPush: string;
|
|
27
|
+
}
|
|
28
|
+
/** SDK 方法级别配置 */
|
|
29
|
+
interface MethodLevelConfig {
|
|
30
|
+
getSchema?: number;
|
|
31
|
+
updateSchema?: number;
|
|
32
|
+
checkPreview?: number;
|
|
33
|
+
renderPreview?: number;
|
|
34
|
+
cleanupPreview?: number;
|
|
35
|
+
startRecording?: number;
|
|
36
|
+
stopRecording?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Schema Element Editor 配置接口
|
|
40
|
+
*/
|
|
41
|
+
interface SchemaElementEditorConfig {
|
|
42
|
+
/**
|
|
43
|
+
* 获取 Schema 数据(可选)
|
|
44
|
+
* @param params - 元素参数(通常是 data-id 的值)
|
|
45
|
+
* @returns Schema 数据(支持所有 JSON 类型)
|
|
46
|
+
*/
|
|
47
|
+
getSchema?: (params: string) => SchemaValue;
|
|
48
|
+
/**
|
|
49
|
+
* 更新 Schema 数据(可选)
|
|
50
|
+
* @param schema - 新的 Schema 数据(支持所有 JSON 类型)
|
|
51
|
+
* @param params - 元素参数
|
|
52
|
+
* @returns 是否更新成功
|
|
53
|
+
*/
|
|
54
|
+
updateSchema?: (schema: SchemaValue, params: string) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 渲染预览(可选)
|
|
57
|
+
* @param schema - Schema 数据(支持所有 JSON 类型)
|
|
58
|
+
* @param containerId - 预览容器 ID
|
|
59
|
+
* @returns 清理函数(可选)
|
|
60
|
+
*/
|
|
61
|
+
renderPreview?: (schema: SchemaValue, containerId: string) => (() => void) | void;
|
|
62
|
+
/** 消息标识配置(可选,有默认值) */
|
|
63
|
+
sourceConfig?: Partial<PostMessageSourceConfig>;
|
|
64
|
+
/** 消息类型配置(可选,有默认值) */
|
|
65
|
+
messageTypes?: Partial<PostMessageTypeConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* SDK 实例唯一标识(可选,自动生成)
|
|
68
|
+
* 用于多 SDK 实例协调
|
|
69
|
+
*/
|
|
70
|
+
sdkId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* SDK 优先级(可选,默认 0)
|
|
73
|
+
* 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
|
|
74
|
+
*/
|
|
75
|
+
level?: number;
|
|
76
|
+
/**
|
|
77
|
+
* 方法级别优先级配置(可选)
|
|
78
|
+
* 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
|
|
79
|
+
*/
|
|
80
|
+
methodLevels?: MethodLevelConfig;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 录制相关方法
|
|
84
|
+
*/
|
|
85
|
+
interface SchemaElementEditorRecording {
|
|
86
|
+
/**
|
|
87
|
+
* 推送 Schema 数据(SDK 内部判断是否在录制,未录制时静默忽略)
|
|
88
|
+
* @param params - 元素参数(data-id 的值)
|
|
89
|
+
* @param data - Schema 数据
|
|
90
|
+
*/
|
|
91
|
+
push: (params: string, data: SchemaValue) => void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Schema Element Editor 桥接器返回值
|
|
95
|
+
*/
|
|
96
|
+
interface SchemaElementEditorBridge {
|
|
97
|
+
/** 清理桥接器,移除事件监听 */
|
|
98
|
+
cleanup: () => void;
|
|
99
|
+
/** 录制相关方法 */
|
|
100
|
+
recording: SchemaElementEditorRecording;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type { MethodLevelConfig as M, PostMessageSourceConfig as P, SchemaValue as S, PostMessageTypeConfig as a, SchemaElementEditorConfig as b, SchemaElementEditorBridge as c, SchemaElementEditorRecording as d };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Element Editor Host SDK - Types
|
|
3
|
+
* 类型定义
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Schema 数据类型
|
|
7
|
+
* 支持所有 JSON.parse 可返回的类型
|
|
8
|
+
*/
|
|
9
|
+
type SchemaValue = Record<string, unknown> | unknown[] | string | number | boolean | null;
|
|
10
|
+
/** postMessage 消息标识配置 */
|
|
11
|
+
interface PostMessageSourceConfig {
|
|
12
|
+
/** 插件端发送消息的 source 标识 */
|
|
13
|
+
contentSource: string;
|
|
14
|
+
/** 宿主端响应消息的 source 标识 */
|
|
15
|
+
hostSource: string;
|
|
16
|
+
}
|
|
17
|
+
/** postMessage 消息类型配置 */
|
|
18
|
+
interface PostMessageTypeConfig {
|
|
19
|
+
getSchema: string;
|
|
20
|
+
updateSchema: string;
|
|
21
|
+
checkPreview: string;
|
|
22
|
+
renderPreview: string;
|
|
23
|
+
cleanupPreview: string;
|
|
24
|
+
startRecording: string;
|
|
25
|
+
stopRecording: string;
|
|
26
|
+
schemaPush: string;
|
|
27
|
+
}
|
|
28
|
+
/** SDK 方法级别配置 */
|
|
29
|
+
interface MethodLevelConfig {
|
|
30
|
+
getSchema?: number;
|
|
31
|
+
updateSchema?: number;
|
|
32
|
+
checkPreview?: number;
|
|
33
|
+
renderPreview?: number;
|
|
34
|
+
cleanupPreview?: number;
|
|
35
|
+
startRecording?: number;
|
|
36
|
+
stopRecording?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Schema Element Editor 配置接口
|
|
40
|
+
*/
|
|
41
|
+
interface SchemaElementEditorConfig {
|
|
42
|
+
/**
|
|
43
|
+
* 获取 Schema 数据(可选)
|
|
44
|
+
* @param params - 元素参数(通常是 data-id 的值)
|
|
45
|
+
* @returns Schema 数据(支持所有 JSON 类型)
|
|
46
|
+
*/
|
|
47
|
+
getSchema?: (params: string) => SchemaValue;
|
|
48
|
+
/**
|
|
49
|
+
* 更新 Schema 数据(可选)
|
|
50
|
+
* @param schema - 新的 Schema 数据(支持所有 JSON 类型)
|
|
51
|
+
* @param params - 元素参数
|
|
52
|
+
* @returns 是否更新成功
|
|
53
|
+
*/
|
|
54
|
+
updateSchema?: (schema: SchemaValue, params: string) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 渲染预览(可选)
|
|
57
|
+
* @param schema - Schema 数据(支持所有 JSON 类型)
|
|
58
|
+
* @param containerId - 预览容器 ID
|
|
59
|
+
* @returns 清理函数(可选)
|
|
60
|
+
*/
|
|
61
|
+
renderPreview?: (schema: SchemaValue, containerId: string) => (() => void) | void;
|
|
62
|
+
/** 消息标识配置(可选,有默认值) */
|
|
63
|
+
sourceConfig?: Partial<PostMessageSourceConfig>;
|
|
64
|
+
/** 消息类型配置(可选,有默认值) */
|
|
65
|
+
messageTypes?: Partial<PostMessageTypeConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* SDK 实例唯一标识(可选,自动生成)
|
|
68
|
+
* 用于多 SDK 实例协调
|
|
69
|
+
*/
|
|
70
|
+
sdkId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* SDK 优先级(可选,默认 0)
|
|
73
|
+
* 数值越大优先级越高,当多个 SDK 实例共存时,优先级高的响应请求
|
|
74
|
+
*/
|
|
75
|
+
level?: number;
|
|
76
|
+
/**
|
|
77
|
+
* 方法级别优先级配置(可选)
|
|
78
|
+
* 可以为每个方法单独配置优先级,未配置的方法使用 level 作为优先级
|
|
79
|
+
*/
|
|
80
|
+
methodLevels?: MethodLevelConfig;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 录制相关方法
|
|
84
|
+
*/
|
|
85
|
+
interface SchemaElementEditorRecording {
|
|
86
|
+
/**
|
|
87
|
+
* 推送 Schema 数据(SDK 内部判断是否在录制,未录制时静默忽略)
|
|
88
|
+
* @param params - 元素参数(data-id 的值)
|
|
89
|
+
* @param data - Schema 数据
|
|
90
|
+
*/
|
|
91
|
+
push: (params: string, data: SchemaValue) => void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Schema Element Editor 桥接器返回值
|
|
95
|
+
*/
|
|
96
|
+
interface SchemaElementEditorBridge {
|
|
97
|
+
/** 清理桥接器,移除事件监听 */
|
|
98
|
+
cleanup: () => void;
|
|
99
|
+
/** 录制相关方法 */
|
|
100
|
+
recording: SchemaElementEditorRecording;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type { MethodLevelConfig as M, PostMessageSourceConfig as P, SchemaValue as S, PostMessageTypeConfig as a, SchemaElementEditorConfig as b, SchemaElementEditorBridge as c, SchemaElementEditorRecording as d };
|