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

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/dist/index.cjs CHANGED
@@ -206,6 +206,10 @@ function useSchemaElementEditor(config) {
206
206
  }, [getSchema, updateSchema, renderPreview]);
207
207
  (0, import_react.useEffect)(() => {
208
208
  if (enabled === false) {
209
+ if (bridgeRef.current && typeof bridgeRef.current.cleanup === "function") {
210
+ bridgeRef.current.cleanup();
211
+ bridgeRef.current = null;
212
+ }
209
213
  return;
210
214
  }
211
215
  const proxyConfig = {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useSchemaElementEditor
3
- } from "./chunk-HBZGOJIJ.js";
3
+ } from "./chunk-3RNKTSDC.js";
4
4
  import {
5
5
  createSchemaElementEditorBridge
6
6
  } from "./chunk-52EFKQHQ.js";
package/dist/react.cjs CHANGED
@@ -203,6 +203,10 @@ function useSchemaElementEditor(config) {
203
203
  }, [getSchema, updateSchema, renderPreview]);
204
204
  (0, import_react.useEffect)(() => {
205
205
  if (enabled === false) {
206
+ if (bridgeRef.current && typeof bridgeRef.current.cleanup === "function") {
207
+ bridgeRef.current.cleanup();
208
+ bridgeRef.current = null;
209
+ }
206
210
  return;
207
211
  }
208
212
  const proxyConfig = {
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useSchemaElementEditor
3
- } from "./chunk-HBZGOJIJ.js";
3
+ } from "./chunk-3RNKTSDC.js";
4
4
  import "./chunk-52EFKQHQ.js";
5
5
  export {
6
6
  useSchemaElementEditor
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.2",
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",