@seljs/editor-react 1.1.0-beta.2 → 1.1.0-beta.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.
@@ -3,22 +3,32 @@ let react = require("react");
3
3
  //#region src/use-sel-editor.ts
4
4
  function useSELEditor(config) {
5
5
  const viewRef = (0, react.useRef)(null);
6
+ const [parent, setParent] = (0, react.useState)(null);
6
7
  const [view, setView] = (0, react.useState)(null);
7
8
  const [value, setValue] = (0, react.useState)(config.value ?? "");
8
9
  const [valid, setValid] = (0, react.useState)(true);
9
10
  const configRef = (0, react.useRef)(config);
10
11
  configRef.current = config;
11
12
  const ref = (0, react.useCallback)((node) => {
13
+ setParent(node);
14
+ }, []);
15
+ (0, react.useEffect)(() => {
16
+ if (!parent) {
17
+ if (viewRef.current) {
18
+ viewRef.current.destroy();
19
+ viewRef.current = null;
20
+ setView(null);
21
+ }
22
+ return;
23
+ }
12
24
  if (viewRef.current) {
13
25
  viewRef.current.destroy();
14
26
  viewRef.current = null;
15
- setView(null);
16
27
  }
17
- if (!node) return;
18
28
  const currentConfig = configRef.current;
19
29
  const editor = (0, _seljs_editor.createSELEditor)({
20
30
  ...currentConfig,
21
- parent: node,
31
+ parent,
22
32
  onChange: (newValue, isValid) => {
23
33
  setValue(newValue);
24
34
  setValid(isValid);
@@ -27,13 +37,26 @@ function useSELEditor(config) {
27
37
  });
28
38
  viewRef.current = editor;
29
39
  setView(editor);
30
- }, [config.schema]);
31
- (0, react.useEffect)(() => {
32
40
  return () => {
33
- viewRef.current?.destroy();
41
+ editor.destroy();
34
42
  viewRef.current = null;
43
+ setView(null);
35
44
  };
36
- }, []);
45
+ }, [
46
+ parent,
47
+ config.schema,
48
+ config.dark,
49
+ config.readOnly,
50
+ config.placeholder,
51
+ config.checkerOptions,
52
+ config.features?.linting,
53
+ config.features?.autocomplete,
54
+ config.features?.semanticHighlighting,
55
+ config.features?.typeDisplay,
56
+ config.features?.view?.minLines,
57
+ config.features?.tooltip?.parent,
58
+ config.features?.tooltip?.position
59
+ ]);
37
60
  return {
38
61
  ref,
39
62
  view,
@@ -3,22 +3,32 @@ import { useCallback, useEffect, useRef, useState } from "react";
3
3
  //#region src/use-sel-editor.ts
4
4
  function useSELEditor(config) {
5
5
  const viewRef = useRef(null);
6
+ const [parent, setParent] = useState(null);
6
7
  const [view, setView] = useState(null);
7
8
  const [value, setValue] = useState(config.value ?? "");
8
9
  const [valid, setValid] = useState(true);
9
10
  const configRef = useRef(config);
10
11
  configRef.current = config;
11
12
  const ref = useCallback((node) => {
13
+ setParent(node);
14
+ }, []);
15
+ useEffect(() => {
16
+ if (!parent) {
17
+ if (viewRef.current) {
18
+ viewRef.current.destroy();
19
+ viewRef.current = null;
20
+ setView(null);
21
+ }
22
+ return;
23
+ }
12
24
  if (viewRef.current) {
13
25
  viewRef.current.destroy();
14
26
  viewRef.current = null;
15
- setView(null);
16
27
  }
17
- if (!node) return;
18
28
  const currentConfig = configRef.current;
19
29
  const editor = createSELEditor({
20
30
  ...currentConfig,
21
- parent: node,
31
+ parent,
22
32
  onChange: (newValue, isValid) => {
23
33
  setValue(newValue);
24
34
  setValid(isValid);
@@ -27,13 +37,26 @@ function useSELEditor(config) {
27
37
  });
28
38
  viewRef.current = editor;
29
39
  setView(editor);
30
- }, [config.schema]);
31
- useEffect(() => {
32
40
  return () => {
33
- viewRef.current?.destroy();
41
+ editor.destroy();
34
42
  viewRef.current = null;
43
+ setView(null);
35
44
  };
36
- }, []);
45
+ }, [
46
+ parent,
47
+ config.schema,
48
+ config.dark,
49
+ config.readOnly,
50
+ config.placeholder,
51
+ config.checkerOptions,
52
+ config.features?.linting,
53
+ config.features?.autocomplete,
54
+ config.features?.semanticHighlighting,
55
+ config.features?.typeDisplay,
56
+ config.features?.view?.minLines,
57
+ config.features?.tooltip?.parent,
58
+ config.features?.tooltip?.position
59
+ ]);
37
60
  return {
38
61
  ref,
39
62
  view,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/editor-react",
3
- "version": "1.1.0-beta.2",
3
+ "version": "1.1.0-beta.3",
4
4
  "repository": {
5
5
  "url": "https://github.com/abinnovision/seljs"
6
6
  },
@@ -51,16 +51,16 @@
51
51
  ]
52
52
  },
53
53
  "dependencies": {
54
- "@seljs/editor": "1.1.0-beta.2",
54
+ "@seljs/editor": "1.1.0-beta.3",
55
55
  "@seljs/schema": "1.0.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@abinnovision/eslint-config-base": "^3.2.0",
59
59
  "@abinnovision/prettier-config": "^2.1.5",
60
60
  "@seljs-internal/tsconfig": "^0.0.0",
61
- "@seljs/checker": "1.1.0-beta.2",
62
- "@seljs/env": "^1.1.0-beta.2",
63
- "@seljs/runtime": "^1.1.0-beta.2",
61
+ "@seljs/checker": "1.1.0-beta.3",
62
+ "@seljs/env": "^1.1.0-beta.3",
63
+ "@seljs/runtime": "^1.1.0-beta.3",
64
64
  "@shazow/whatsabi": "^0.26.0",
65
65
  "@storybook/react": "^10.2.19",
66
66
  "@storybook/react-vite": "^10.2.19",