@uiw/react-codemirror 4.3.2 → 4.4.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.
@@ -1,8 +1,8 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { basicSetup as defaultBasicSetup } from '@codemirror/basic-setup';
2
+ import { basicSetup } from '@codemirror/basic-setup';
3
3
  import { EditorState, StateEffect } from '@codemirror/state';
4
- import { indentWithTab as defaultIndentWithTab } from '@codemirror/commands';
5
- import { EditorView, keymap, ViewUpdate, placeholder as extendPlaceholder } from '@codemirror/view';
4
+ import { indentWithTab } from '@codemirror/commands';
5
+ import { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';
6
6
  import { oneDark } from '@codemirror/theme-one-dark';
7
7
  import { ReactCodeMirrorProps } from './';
8
8
  import { defaultLightThemeOption } from './theme/light';
@@ -23,13 +23,13 @@ export function useCodeMirror(props: UseCodeMirror) {
23
23
  height = '',
24
24
  minHeight = '',
25
25
  maxHeight = '',
26
- placeholder = '',
26
+ placeholder: placeholderStr = '',
27
27
  width = '',
28
28
  minWidth = '',
29
29
  maxWidth = '',
30
30
  editable = true,
31
- indentWithTab = true,
32
- basicSetup = true,
31
+ indentWithTab: defaultIndentWithTab = true,
32
+ basicSetup: defaultBasicSetup = true,
33
33
  root,
34
34
  } = props;
35
35
  const [container, setContainer] = useState(props.container);
@@ -53,15 +53,15 @@ export function useCodeMirror(props: UseCodeMirror) {
53
53
  }
54
54
  });
55
55
  let getExtensions = [updateListener, defaultThemeOption];
56
- if (indentWithTab) {
57
- getExtensions.unshift(keymap.of([defaultIndentWithTab]));
56
+ if (defaultIndentWithTab) {
57
+ getExtensions.unshift(keymap.of([indentWithTab]));
58
58
  }
59
- if (basicSetup) {
60
- getExtensions.unshift(defaultBasicSetup);
59
+ if (defaultBasicSetup) {
60
+ getExtensions.unshift(basicSetup);
61
61
  }
62
62
 
63
- if (placeholder) {
64
- getExtensions.unshift(extendPlaceholder(placeholder));
63
+ if (placeholderStr) {
64
+ getExtensions.unshift(placeholder(placeholderStr));
65
65
  }
66
66
 
67
67
  switch (theme) {
@@ -96,7 +96,7 @@ export function useCodeMirror(props: UseCodeMirror) {
96
96
  if (!view) {
97
97
  const viewCurrent = new EditorView({
98
98
  state: stateCurrent,
99
- parent: container as any,
99
+ parent: container,
100
100
  root,
101
101
  });
102
102
  setView(viewCurrent);
@@ -105,22 +105,24 @@ export function useCodeMirror(props: UseCodeMirror) {
105
105
  // eslint-disable-next-line react-hooks/exhaustive-deps
106
106
  }, [container, state]);
107
107
 
108
- useEffect(() => {
109
- return () => {
108
+ useEffect(
109
+ () => () => {
110
110
  if (view) {
111
111
  view.destroy();
112
+ setView(undefined);
112
113
  }
113
- };
114
- }, [view]);
114
+ },
115
+ [view],
116
+ );
117
+
118
+ useEffect(() => autoFocus && view && (view.focus() as any), [autoFocus, view]);
115
119
 
116
120
  useEffect(() => {
117
- if (view) {
118
- const currentValue = view.state.doc.toString();
119
- if (value !== currentValue) {
120
- view.dispatch({
121
- changes: { from: 0, to: currentValue.length, insert: value || '' },
122
- });
123
- }
121
+ const currentValue = view ? view.state.doc.toString() : '';
122
+ if (view && value !== currentValue) {
123
+ view.dispatch({
124
+ changes: { from: 0, to: currentValue.length, insert: value || '' },
125
+ });
124
126
  }
125
127
  }, [value, view]);
126
128
 
@@ -132,23 +134,17 @@ export function useCodeMirror(props: UseCodeMirror) {
132
134
  }, [
133
135
  theme,
134
136
  extensions,
135
- placeholder,
136
137
  height,
137
138
  minHeight,
138
139
  maxHeight,
139
140
  width,
141
+ placeholderStr,
140
142
  minWidth,
141
143
  maxWidth,
142
144
  editable,
143
- indentWithTab,
144
- basicSetup,
145
+ defaultIndentWithTab,
146
+ defaultBasicSetup,
145
147
  ]);
146
148
 
147
- useEffect(() => {
148
- if (autoFocus && view) {
149
- view.focus();
150
- }
151
- }, [autoFocus, view]);
152
-
153
149
  return { state, setState, view, setView, container, setContainer };
154
150
  }
@@ -1 +0,0 @@
1
- /// <reference types="react-scripts" />