@schema-element-editor/host-sdk 2.0.3 → 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 -7
- 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 -7
- 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
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// src/core.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
|
+
var SdkCoordinator = class {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.isDestroyed = false;
|
|
26
|
+
/**
|
|
27
|
+
* 存储比当前 SDK 优先级更高的其他 SDK ID
|
|
28
|
+
* 按方法分类:如果某个方法的集合不为空,说明有更高优先级的 SDK 应该处理该方法
|
|
29
|
+
*/
|
|
30
|
+
this.higherLevelSdks = {
|
|
31
|
+
getSchema: /* @__PURE__ */ new Set(),
|
|
32
|
+
updateSchema: /* @__PURE__ */ new Set(),
|
|
33
|
+
checkPreview: /* @__PURE__ */ new Set(),
|
|
34
|
+
renderPreview: /* @__PURE__ */ new Set(),
|
|
35
|
+
cleanupPreview: /* @__PURE__ */ new Set(),
|
|
36
|
+
startRecording: /* @__PURE__ */ new Set(),
|
|
37
|
+
stopRecording: /* @__PURE__ */ new Set()
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 处理 SDK 协调消息
|
|
41
|
+
*/
|
|
42
|
+
this.handleCoordinationMessage = (event) => {
|
|
43
|
+
const isFromSelf = event.source === window;
|
|
44
|
+
const isFromParent = window !== window.top && event.source === window.parent;
|
|
45
|
+
if (!isFromSelf && !isFromParent) return;
|
|
46
|
+
const data = event.data;
|
|
47
|
+
if (!data || data.source !== SDK_COORDINATOR_SOURCE) return;
|
|
48
|
+
switch (data.type) {
|
|
49
|
+
case SDK_COORDINATION_MESSAGE_TYPES.query:
|
|
50
|
+
this.sendRegister();
|
|
51
|
+
break;
|
|
52
|
+
case SDK_COORDINATION_MESSAGE_TYPES.register:
|
|
53
|
+
this.handleSdkRegister(data.payload);
|
|
54
|
+
break;
|
|
55
|
+
case SDK_COORDINATION_MESSAGE_TYPES.unregister:
|
|
56
|
+
this.handleSdkUnregister(data.payload.sdkId);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.sdkId = config.sdkId || `sdk-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
61
|
+
this.messageSource = config.messageSource;
|
|
62
|
+
this.level = config.level ?? 0;
|
|
63
|
+
this.methodLevels = config.methodLevels ?? {};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 初始化协调器
|
|
67
|
+
*/
|
|
68
|
+
init() {
|
|
69
|
+
window.addEventListener("message", this.handleCoordinationMessage);
|
|
70
|
+
this.sendQuery();
|
|
71
|
+
this.sendRegister();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 销毁协调器
|
|
75
|
+
*/
|
|
76
|
+
destroy() {
|
|
77
|
+
this.isDestroyed = true;
|
|
78
|
+
this.sendUnregister();
|
|
79
|
+
window.removeEventListener("message", this.handleCoordinationMessage);
|
|
80
|
+
Object.values(this.higherLevelSdks).forEach((set) => set.clear());
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 判断是否应该响应某个方法的请求
|
|
84
|
+
* @param method - 方法名
|
|
85
|
+
* @returns 是否应该响应
|
|
86
|
+
*/
|
|
87
|
+
shouldRespond(method) {
|
|
88
|
+
if (this.isDestroyed) return false;
|
|
89
|
+
const higherSdks = this.higherLevelSdks[method];
|
|
90
|
+
return !higherSdks || higherSdks.size === 0;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 获取方法的优先级
|
|
94
|
+
*/
|
|
95
|
+
getMethodLevel(method) {
|
|
96
|
+
return this.methodLevels[method] ?? this.level;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 处理其他 SDK 的注册
|
|
100
|
+
*/
|
|
101
|
+
handleSdkRegister(info) {
|
|
102
|
+
if (info.sdkId === this.sdkId) return;
|
|
103
|
+
if (info.messageSource !== this.messageSource) return;
|
|
104
|
+
Object.keys(this.higherLevelSdks).forEach((method) => {
|
|
105
|
+
const myLevel = this.getMethodLevel(method);
|
|
106
|
+
const otherLevel = info.methodLevels[method] ?? info.level;
|
|
107
|
+
if (otherLevel > myLevel) {
|
|
108
|
+
this.higherLevelSdks[method].add(info.sdkId);
|
|
109
|
+
} else {
|
|
110
|
+
this.higherLevelSdks[method].delete(info.sdkId);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 处理其他 SDK 的注销
|
|
116
|
+
*/
|
|
117
|
+
handleSdkUnregister(sdkId) {
|
|
118
|
+
Object.values(this.higherLevelSdks).forEach((set) => {
|
|
119
|
+
set.delete(sdkId);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 发送查询消息
|
|
124
|
+
*/
|
|
125
|
+
sendQuery() {
|
|
126
|
+
const message = {
|
|
127
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
128
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.query,
|
|
129
|
+
payload: { sdkId: this.sdkId }
|
|
130
|
+
};
|
|
131
|
+
this.postCoordinationMessage(message);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 发送注册消息
|
|
135
|
+
*/
|
|
136
|
+
sendRegister() {
|
|
137
|
+
const message = {
|
|
138
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
139
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.register,
|
|
140
|
+
payload: {
|
|
141
|
+
sdkId: this.sdkId,
|
|
142
|
+
messageSource: this.messageSource,
|
|
143
|
+
level: this.level,
|
|
144
|
+
methodLevels: this.methodLevels
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
this.postCoordinationMessage(message);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 发送注销消息
|
|
151
|
+
*/
|
|
152
|
+
sendUnregister() {
|
|
153
|
+
const message = {
|
|
154
|
+
source: SDK_COORDINATOR_SOURCE,
|
|
155
|
+
type: SDK_COORDINATION_MESSAGE_TYPES.unregister,
|
|
156
|
+
payload: { sdkId: this.sdkId }
|
|
157
|
+
};
|
|
158
|
+
this.postCoordinationMessage(message);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 发送协调消息
|
|
162
|
+
*/
|
|
163
|
+
postCoordinationMessage(message) {
|
|
164
|
+
window.postMessage(message, "*");
|
|
165
|
+
if (window.top && window.top !== window) {
|
|
166
|
+
window.top.postMessage(message, "*");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function createSchemaElementEditorBridge(config) {
|
|
171
|
+
const {
|
|
172
|
+
getSchema,
|
|
173
|
+
updateSchema,
|
|
174
|
+
renderPreview,
|
|
175
|
+
sourceConfig,
|
|
176
|
+
messageTypes,
|
|
177
|
+
sdkId,
|
|
178
|
+
level,
|
|
179
|
+
methodLevels
|
|
180
|
+
} = config;
|
|
181
|
+
const mergedSourceConfig = {
|
|
182
|
+
...DEFAULT_SOURCE_CONFIG,
|
|
183
|
+
...sourceConfig
|
|
184
|
+
};
|
|
185
|
+
const mergedMessageTypes = {
|
|
186
|
+
...DEFAULT_MESSAGE_TYPES,
|
|
187
|
+
...messageTypes
|
|
188
|
+
};
|
|
189
|
+
const coordinator = new SdkCoordinator({
|
|
190
|
+
sdkId,
|
|
191
|
+
messageSource: mergedSourceConfig.contentSource,
|
|
192
|
+
level,
|
|
193
|
+
methodLevels
|
|
194
|
+
});
|
|
195
|
+
coordinator.init();
|
|
196
|
+
let previewCleanupFn = null;
|
|
197
|
+
const recordingParams = /* @__PURE__ */ new Set();
|
|
198
|
+
const currentConfig = { getSchema, updateSchema, renderPreview };
|
|
199
|
+
const sendResponse = (requestId, result) => {
|
|
200
|
+
const message = {
|
|
201
|
+
source: mergedSourceConfig.hostSource,
|
|
202
|
+
requestId,
|
|
203
|
+
...result
|
|
204
|
+
};
|
|
205
|
+
const targetWindow = window.top ?? window;
|
|
206
|
+
targetWindow.postMessage(message, "*");
|
|
207
|
+
};
|
|
208
|
+
const pushSchema = (params, data) => {
|
|
209
|
+
if (!recordingParams.has(params)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const message = {
|
|
213
|
+
source: mergedSourceConfig.hostSource,
|
|
214
|
+
type: mergedMessageTypes.schemaPush,
|
|
215
|
+
payload: {
|
|
216
|
+
success: true,
|
|
217
|
+
data,
|
|
218
|
+
params
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const targetWindow = window.top ?? window;
|
|
222
|
+
targetWindow.postMessage(message, "*");
|
|
223
|
+
};
|
|
224
|
+
const getMethodNameByType = (type) => {
|
|
225
|
+
if (type === mergedMessageTypes.getSchema) return "getSchema";
|
|
226
|
+
if (type === mergedMessageTypes.updateSchema) return "updateSchema";
|
|
227
|
+
if (type === mergedMessageTypes.checkPreview) return "checkPreview";
|
|
228
|
+
if (type === mergedMessageTypes.renderPreview) return "renderPreview";
|
|
229
|
+
if (type === mergedMessageTypes.cleanupPreview) return "cleanupPreview";
|
|
230
|
+
if (type === mergedMessageTypes.startRecording) return "startRecording";
|
|
231
|
+
if (type === mergedMessageTypes.stopRecording) return "stopRecording";
|
|
232
|
+
return null;
|
|
233
|
+
};
|
|
234
|
+
const handleMessage = (event) => {
|
|
235
|
+
const isFromSelf = event.source === window;
|
|
236
|
+
const isFromParent = window !== window.top && event.source === window.parent;
|
|
237
|
+
if (!isFromSelf && !isFromParent) return;
|
|
238
|
+
if (!event.data || event.data.source !== mergedSourceConfig.contentSource) return;
|
|
239
|
+
const { type, payload, requestId } = event.data;
|
|
240
|
+
if (!requestId) return;
|
|
241
|
+
const methodName = getMethodNameByType(type);
|
|
242
|
+
if (methodName && !coordinator.shouldRespond(methodName)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const { getSchema: getSchema2, updateSchema: updateSchema2, renderPreview: renderPreview2 } = currentConfig;
|
|
246
|
+
let result;
|
|
247
|
+
switch (type) {
|
|
248
|
+
case mergedMessageTypes.getSchema: {
|
|
249
|
+
const params = String(payload?.params ?? "");
|
|
250
|
+
try {
|
|
251
|
+
const data = getSchema2(params);
|
|
252
|
+
result = { success: true, data };
|
|
253
|
+
} catch (error) {
|
|
254
|
+
result = {
|
|
255
|
+
success: false,
|
|
256
|
+
error: error instanceof Error ? error.message : "\u83B7\u53D6 Schema \u5931\u8D25"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case mergedMessageTypes.updateSchema: {
|
|
262
|
+
const schema = payload?.schema;
|
|
263
|
+
const params = String(payload?.params ?? "");
|
|
264
|
+
try {
|
|
265
|
+
const success = updateSchema2(schema, params);
|
|
266
|
+
result = { success };
|
|
267
|
+
} catch (error) {
|
|
268
|
+
result = {
|
|
269
|
+
success: false,
|
|
270
|
+
error: error instanceof Error ? error.message : "\u66F4\u65B0 Schema \u5931\u8D25"
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
case mergedMessageTypes.checkPreview: {
|
|
276
|
+
result = { exists: typeof renderPreview2 === "function" };
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case mergedMessageTypes.renderPreview: {
|
|
280
|
+
if (typeof renderPreview2 !== "function") {
|
|
281
|
+
result = { success: false, error: "\u9884\u89C8\u529F\u80FD\u672A\u914D\u7F6E" };
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
const schema = payload?.schema;
|
|
285
|
+
const containerId = String(payload?.containerId ?? "");
|
|
286
|
+
try {
|
|
287
|
+
if (previewCleanupFn) {
|
|
288
|
+
previewCleanupFn();
|
|
289
|
+
previewCleanupFn = null;
|
|
290
|
+
}
|
|
291
|
+
const cleanup = renderPreview2(schema, containerId);
|
|
292
|
+
if (typeof cleanup === "function") {
|
|
293
|
+
previewCleanupFn = cleanup;
|
|
294
|
+
}
|
|
295
|
+
result = { success: true };
|
|
296
|
+
} catch (error) {
|
|
297
|
+
result = {
|
|
298
|
+
success: false,
|
|
299
|
+
error: error instanceof Error ? error.message : "\u6E32\u67D3\u9884\u89C8\u5931\u8D25"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case mergedMessageTypes.cleanupPreview: {
|
|
305
|
+
try {
|
|
306
|
+
if (previewCleanupFn) {
|
|
307
|
+
previewCleanupFn();
|
|
308
|
+
previewCleanupFn = null;
|
|
309
|
+
}
|
|
310
|
+
result = { success: true };
|
|
311
|
+
} catch (error) {
|
|
312
|
+
result = {
|
|
313
|
+
success: false,
|
|
314
|
+
error: error instanceof Error ? error.message : "\u6E05\u7406\u9884\u89C8\u5931\u8D25"
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
case mergedMessageTypes.startRecording: {
|
|
320
|
+
const params = String(payload?.params ?? "");
|
|
321
|
+
recordingParams.add(params);
|
|
322
|
+
result = { success: true };
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
case mergedMessageTypes.stopRecording: {
|
|
326
|
+
const params = String(payload?.params ?? "");
|
|
327
|
+
recordingParams.delete(params);
|
|
328
|
+
result = { success: true };
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
default:
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
sendResponse(requestId, result);
|
|
335
|
+
};
|
|
336
|
+
window.addEventListener("message", handleMessage);
|
|
337
|
+
return {
|
|
338
|
+
cleanup: () => {
|
|
339
|
+
coordinator.destroy();
|
|
340
|
+
window.removeEventListener("message", handleMessage);
|
|
341
|
+
if (previewCleanupFn) {
|
|
342
|
+
previewCleanupFn();
|
|
343
|
+
previewCleanupFn = null;
|
|
344
|
+
}
|
|
345
|
+
recordingParams.clear();
|
|
346
|
+
},
|
|
347
|
+
recording: {
|
|
348
|
+
push: pushSchema
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export {
|
|
354
|
+
createSchemaElementEditorBridge
|
|
355
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSchemaElementEditorBridge
|
|
3
|
+
} from "./chunk-BVGJ5UDR.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
|
+
getSchema: configRef.current.getSchema ? ((params) => configRef.current.getSchema(params)) : void 0,
|
|
30
|
+
updateSchema: configRef.current.updateSchema ? ((schema, params) => configRef.current.updateSchema(schema, params)) : void 0,
|
|
31
|
+
renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
|
|
32
|
+
sourceConfig,
|
|
33
|
+
messageTypes,
|
|
34
|
+
sdkId,
|
|
35
|
+
level,
|
|
36
|
+
methodLevels
|
|
37
|
+
};
|
|
38
|
+
const bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
39
|
+
bridgeRef.current = bridge;
|
|
40
|
+
return () => {
|
|
41
|
+
bridge.cleanup();
|
|
42
|
+
bridgeRef.current = null;
|
|
43
|
+
};
|
|
44
|
+
}, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
|
|
45
|
+
const push = useCallback((params, data) => {
|
|
46
|
+
bridgeRef.current?.recording.push(params, data);
|
|
47
|
+
}, []);
|
|
48
|
+
const recording = useMemo(() => ({ push }), [push]);
|
|
49
|
+
return { recording };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
useSchemaElementEditor
|
|
54
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSchemaElementEditorBridge
|
|
3
|
+
} from "./chunk-LJJYJHOZ.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,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSchemaElementEditorBridge
|
|
3
|
+
} from "./chunk-3OZ7E3LK.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
|
+
getSchema: configRef.current.getSchema ? (params) => configRef.current.getSchema(params) : void 0,
|
|
30
|
+
updateSchema: configRef.current.updateSchema ? (schema, params) => configRef.current.updateSchema(schema, params) : void 0,
|
|
31
|
+
renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
|
|
32
|
+
sourceConfig,
|
|
33
|
+
messageTypes,
|
|
34
|
+
sdkId,
|
|
35
|
+
level,
|
|
36
|
+
methodLevels
|
|
37
|
+
};
|
|
38
|
+
const bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
39
|
+
bridgeRef.current = bridge;
|
|
40
|
+
return () => {
|
|
41
|
+
bridge.cleanup();
|
|
42
|
+
bridgeRef.current = null;
|
|
43
|
+
};
|
|
44
|
+
}, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
|
|
45
|
+
const push = useCallback((params, data) => {
|
|
46
|
+
bridgeRef.current?.recording.push(params, data);
|
|
47
|
+
}, []);
|
|
48
|
+
const recording = useMemo(() => ({ push }), [push]);
|
|
49
|
+
return { recording };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
useSchemaElementEditor
|
|
54
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSchemaElementEditorBridge
|
|
3
|
+
} from "./chunk-BVGJ5UDR.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
|
+
getSchema,
|
|
30
|
+
updateSchema,
|
|
31
|
+
renderPreview,
|
|
32
|
+
sourceConfig,
|
|
33
|
+
messageTypes,
|
|
34
|
+
sdkId,
|
|
35
|
+
level,
|
|
36
|
+
methodLevels
|
|
37
|
+
};
|
|
38
|
+
const bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
39
|
+
bridgeRef.current = bridge;
|
|
40
|
+
return () => {
|
|
41
|
+
bridge.cleanup();
|
|
42
|
+
bridgeRef.current = null;
|
|
43
|
+
};
|
|
44
|
+
}, [enabled, getSchema, updateSchema, renderPreview, sourceConfig, messageTypes, sdkId, level, methodLevels]);
|
|
45
|
+
const push = useCallback((params, data) => {
|
|
46
|
+
bridgeRef.current?.recording.push(params, data);
|
|
47
|
+
}, []);
|
|
48
|
+
const recording = useMemo(() => ({ push }), [push]);
|
|
49
|
+
return { recording };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
useSchemaElementEditor
|
|
54
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSchemaElementEditorBridge
|
|
3
|
+
} from "./chunk-DGO4Z6NW.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
|
+
getSchema: configRef.current.getSchema ? ((params) => configRef.current.getSchema(params)) : void 0,
|
|
30
|
+
updateSchema: configRef.current.updateSchema ? ((schema, params) => configRef.current.updateSchema(schema, params)) : void 0,
|
|
31
|
+
renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
|
|
32
|
+
sourceConfig,
|
|
33
|
+
messageTypes,
|
|
34
|
+
sdkId,
|
|
35
|
+
level,
|
|
36
|
+
methodLevels
|
|
37
|
+
};
|
|
38
|
+
const bridge = createSchemaElementEditorBridge(proxyConfig);
|
|
39
|
+
bridgeRef.current = bridge;
|
|
40
|
+
return () => {
|
|
41
|
+
bridge.cleanup();
|
|
42
|
+
bridgeRef.current = null;
|
|
43
|
+
};
|
|
44
|
+
}, [enabled, configRef, sourceConfig, messageTypes, sdkId, level, methodLevels]);
|
|
45
|
+
const push = useCallback((params, data) => {
|
|
46
|
+
bridgeRef.current?.recording.push(params, data);
|
|
47
|
+
}, []);
|
|
48
|
+
const recording = useMemo(() => ({ push }), [push]);
|
|
49
|
+
return { recording };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
useSchemaElementEditor
|
|
54
|
+
};
|