@schema-element-editor/host-sdk 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ import {
2
+ createSchemaElementEditorBridge
3
+ } from "./chunk-52EFKQHQ.js";
4
+
5
+ // src/react.ts
6
+ import { useEffect, useRef, useMemo, useCallback } from "react";
7
+ function useSchemaElementEditor(config) {
8
+ const { getSchema, updateSchema, renderPreview, sourceConfig, messageTypes, enabled } = config;
9
+ const configRef = useRef({ getSchema, updateSchema, renderPreview });
10
+ const bridgeRef = useRef(null);
11
+ useEffect(() => {
12
+ configRef.current = { getSchema, updateSchema, renderPreview };
13
+ }, [getSchema, updateSchema, renderPreview]);
14
+ useEffect(() => {
15
+ if (enabled === false) {
16
+ if (bridgeRef.current && typeof bridgeRef.current.cleanup === "function") {
17
+ bridgeRef.current.cleanup();
18
+ bridgeRef.current = null;
19
+ }
20
+ return;
21
+ }
22
+ const proxyConfig = {
23
+ getSchema: (params) => configRef.current.getSchema(params),
24
+ updateSchema: (schema, params) => configRef.current.updateSchema(schema, params),
25
+ renderPreview: configRef.current.renderPreview ? (schema, containerId) => configRef.current.renderPreview?.(schema, containerId) : void 0,
26
+ sourceConfig,
27
+ messageTypes
28
+ };
29
+ const bridge = createSchemaElementEditorBridge(proxyConfig);
30
+ bridgeRef.current = bridge;
31
+ return () => {
32
+ bridge.cleanup();
33
+ bridgeRef.current = null;
34
+ };
35
+ }, [enabled, configRef, sourceConfig, messageTypes]);
36
+ const push = useCallback((params, data) => {
37
+ bridgeRef.current?.recording.push(params, data);
38
+ }, []);
39
+ const recording = useMemo(() => ({ push }), [push]);
40
+ return { recording };
41
+ }
42
+
43
+ export {
44
+ useSchemaElementEditor
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schema-element-editor/host-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Schema Element Editor (SEE) 插件宿主接入 SDK,支持 React/Vue/纯 JS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -48,9 +48,9 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "tsup": "^8.0.0",
52
- "typescript": "^5.3.0",
53
- "vue": "^3.4.0"
51
+ "tsup": "^8.5.1",
52
+ "typescript": "^5.9.3",
53
+ "vue": "^3.5.25"
54
54
  },
55
55
  "keywords": [
56
56
  "schema-element-editor",