@snack-uikit/code-editor 0.5.1-preview-d4775873.0 → 0.5.1-preview-f7ec3fa7.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/README.md CHANGED
@@ -36,7 +36,6 @@
36
36
  | onMount | `OnMount` | - | Signature: function(editor: monaco.editor.IStandaloneCodeEditor, monaco: Monaco) => void An event is emitted when the editor is mounted It gets the editor instance as a first argument and the monaco instance as a second Defaults to "noop" |
37
37
  | onChange | `OnChange` | - | Signature: function(value: string \| undefined, ev: monaco.editor.IModelContentChangedEvent) => void An event is emitted when the content of the current model is changed |
38
38
  | onValidate | `OnValidate` | - | Signature: function(markers: monaco.editor.IMarker[]) => void An event is emitted when the content of the current model is changed and the current model markers are ready Defaults to "noop" |
39
- | hoverDescription | `HoverDescription` | - | |
40
39
 
41
40
 
42
41
  [//]: DOCUMENTATION_SECTION_END
@@ -10,4 +10,4 @@ export type CodeEditorProps = WithSupportProps<{
10
10
  */
11
11
  hasBackground?: boolean;
12
12
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
13
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, hoverDescription, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -37,17 +37,15 @@ function CodeEditor(_a) {
37
37
  loading,
38
38
  hasBackground = true,
39
39
  onMount,
40
- language,
41
- hoverDescription
40
+ language
42
41
  } = _a,
43
- props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "hoverDescription"]);
42
+ props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language"]);
44
43
  const monaco = (0, react_1.useMonaco)();
45
44
  const [wrapperElement, setWrapperElement] = (0, react_2.useState)(null);
46
45
  const {
47
46
  jsonSchemaProps,
48
47
  jsonSchemaOptions
49
48
  } = (0, hooks_1.useApplyJsonSchema)(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
50
- (0, hooks_1.useHoverProvider)(language, hoverDescription);
51
49
  const onEditorMount = (0, react_2.useCallback)((editor, monaco) => {
52
50
  var _a;
53
51
  monaco && (0, utils_1.isBrowser)() && ((_a = document === null || document === void 0 ? void 0 : document.fonts) === null || _a === void 0 ? void 0 : _a.ready.finally(monaco.editor.remeasureFonts));
@@ -1,4 +1,4 @@
1
- import { HoverDescription, JsonSchema } from './types';
1
+ import { JsonSchema } from './types';
2
2
  type UseCalculatedThemeValuesProps = {
3
3
  stylesOriginNode: HTMLDivElement | null;
4
4
  themeName?: string;
@@ -48,5 +48,4 @@ export declare function useApplyJsonSchema(language?: string, jsonSchema?: JsonS
48
48
  };
49
49
  jsonSchemaOptions: import("monaco-editor").editor.IStandaloneEditorConstructionOptions | undefined;
50
50
  };
51
- export declare function useHoverProvider(language?: string, hoverDescription?: HoverDescription): void;
52
51
  export {};
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useCalculatedThemeValues = useCalculatedThemeValues;
7
7
  exports.useApplyJsonSchema = useApplyJsonSchema;
8
- exports.useHoverProvider = useHoverProvider;
9
8
  const react_1 = require("@monaco-editor/react");
10
9
  const monaco_yaml_1 = require("monaco-yaml");
11
10
  const react_2 = require("react");
@@ -96,39 +95,4 @@ function useApplyJsonSchema(language, jsonSchema) {
96
95
  },
97
96
  jsonSchemaOptions
98
97
  }), [jsonSchemaOptions, modelPath]);
99
- }
100
- function useHoverProvider(language, hoverDescription) {
101
- const monaco = (0, react_1.useMonaco)();
102
- const configureHoverProvider = (0, react_2.useCallback)(() => {
103
- if (!monaco || !language || !hoverDescription) {
104
- return;
105
- }
106
- return monaco.languages.registerHoverProvider(language, {
107
- provideHover: (model, position) => {
108
- var _a;
109
- const wordInfo = model.getWordAtPosition(position);
110
- const hoveredDescription = hoverDescription[(_a = wordInfo === null || wordInfo === void 0 ? void 0 : wordInfo.word) !== null && _a !== void 0 ? _a : ''];
111
- if (wordInfo && hoveredDescription) {
112
- const {
113
- startColumn,
114
- endColumn
115
- } = wordInfo;
116
- return {
117
- range: new monaco.Range(position.lineNumber, startColumn, position.lineNumber, endColumn),
118
- contents: [{
119
- value: hoveredDescription
120
- }]
121
- };
122
- }
123
- return null;
124
- }
125
- });
126
- }, [monaco, language, hoverDescription]);
127
- (0, react_2.useEffect)(() => {
128
- var _a;
129
- const {
130
- dispose
131
- } = (_a = configureHoverProvider()) !== null && _a !== void 0 ? _a : {};
132
- return dispose;
133
- }, [configureHoverProvider]);
134
98
  }
@@ -1,11 +1,6 @@
1
1
  import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
2
2
  import { JSONSchema } from 'monaco-yaml';
3
- export type HoverDescription = {
4
- [word: string]: string;
5
- };
6
- export type EditorBaseProps = MonacoEditorProps & {
7
- hoverDescription?: HoverDescription;
8
- };
3
+ export type EditorBaseProps = MonacoEditorProps;
9
4
  export type SupportedSchemaLanguage = 'json' | 'yaml';
10
5
  export type JsonSchema = {
11
6
  uri?: string;
@@ -23,10 +18,8 @@ type WithoutJsonSchema = Pick<MonacoEditorProps, 'path'>;
23
18
  export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path'> & {
24
19
  language: SupportedSchemaLanguage;
25
20
  } & (WithJsonSchema | WithoutJsonSchema);
26
- export type Dispose = {
27
- dispose?: () => void;
28
- };
29
- export type ConfigureJsonSchemaReturn = ({
21
+ export type ConfigureJsonSchemaReturn = {
30
22
  options?: MonacoEditorProps['options'];
31
- } & Dispose) | undefined;
23
+ dispose?: () => void;
24
+ } | undefined;
32
25
  export {};
@@ -10,4 +10,4 @@ export type CodeEditorProps = WithSupportProps<{
10
10
  */
11
11
  hasBackground?: boolean;
12
12
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
13
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, hoverDescription, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -16,16 +16,15 @@ import { useCallback, useMemo, useState } from 'react';
16
16
  import { Spinner } from '@snack-uikit/loaders';
17
17
  import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
18
18
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
19
- import { useApplyJsonSchema, useCalculatedThemeValues, useHoverProvider } from './hooks';
19
+ import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
20
20
  import styles from './styles.module.css';
21
21
  import { initLoaderConfig, isDark } from './utils';
22
22
  initLoaderConfig();
23
23
  export function CodeEditor(_a) {
24
- var { themeName, className, theme, options, loading, hasBackground = true, onMount, language, hoverDescription } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "hoverDescription"]);
24
+ var { themeName, className, theme, options, loading, hasBackground = true, onMount, language } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language"]);
25
25
  const monaco = useMonaco();
26
26
  const [wrapperElement, setWrapperElement] = useState(null);
27
27
  const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
28
- useHoverProvider(language, hoverDescription);
29
28
  const onEditorMount = useCallback((editor, monaco) => {
30
29
  var _a;
31
30
  monaco && isBrowser() && ((_a = document === null || document === void 0 ? void 0 : document.fonts) === null || _a === void 0 ? void 0 : _a.ready.finally(monaco.editor.remeasureFonts));
@@ -1,4 +1,4 @@
1
- import { HoverDescription, JsonSchema } from './types';
1
+ import { JsonSchema } from './types';
2
2
  type UseCalculatedThemeValuesProps = {
3
3
  stylesOriginNode: HTMLDivElement | null;
4
4
  themeName?: string;
@@ -48,5 +48,4 @@ export declare function useApplyJsonSchema(language?: string, jsonSchema?: JsonS
48
48
  };
49
49
  jsonSchemaOptions: import("monaco-editor").editor.IStandaloneEditorConstructionOptions | undefined;
50
50
  };
51
- export declare function useHoverProvider(language?: string, hoverDescription?: HoverDescription): void;
52
51
  export {};
@@ -81,31 +81,3 @@ export function useApplyJsonSchema(language, jsonSchema) {
81
81
  jsonSchemaOptions,
82
82
  }), [jsonSchemaOptions, modelPath]);
83
83
  }
84
- export function useHoverProvider(language, hoverDescription) {
85
- const monaco = useMonaco();
86
- const configureHoverProvider = useCallback(() => {
87
- if (!monaco || !language || !hoverDescription) {
88
- return;
89
- }
90
- return monaco.languages.registerHoverProvider(language, {
91
- provideHover: (model, position) => {
92
- var _a;
93
- const wordInfo = model.getWordAtPosition(position);
94
- const hoveredDescription = hoverDescription[(_a = wordInfo === null || wordInfo === void 0 ? void 0 : wordInfo.word) !== null && _a !== void 0 ? _a : ''];
95
- if (wordInfo && hoveredDescription) {
96
- const { startColumn, endColumn } = wordInfo;
97
- return {
98
- range: new monaco.Range(position.lineNumber, startColumn, position.lineNumber, endColumn),
99
- contents: [{ value: hoveredDescription }],
100
- };
101
- }
102
- return null;
103
- },
104
- });
105
- }, [monaco, language, hoverDescription]);
106
- useEffect(() => {
107
- var _a;
108
- const { dispose } = (_a = configureHoverProvider()) !== null && _a !== void 0 ? _a : {};
109
- return dispose;
110
- }, [configureHoverProvider]);
111
- }
@@ -1,11 +1,6 @@
1
1
  import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
2
2
  import { JSONSchema } from 'monaco-yaml';
3
- export type HoverDescription = {
4
- [word: string]: string;
5
- };
6
- export type EditorBaseProps = MonacoEditorProps & {
7
- hoverDescription?: HoverDescription;
8
- };
3
+ export type EditorBaseProps = MonacoEditorProps;
9
4
  export type SupportedSchemaLanguage = 'json' | 'yaml';
10
5
  export type JsonSchema = {
11
6
  uri?: string;
@@ -23,10 +18,8 @@ type WithoutJsonSchema = Pick<MonacoEditorProps, 'path'>;
23
18
  export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path'> & {
24
19
  language: SupportedSchemaLanguage;
25
20
  } & (WithJsonSchema | WithoutJsonSchema);
26
- export type Dispose = {
27
- dispose?: () => void;
28
- };
29
- export type ConfigureJsonSchemaReturn = ({
21
+ export type ConfigureJsonSchemaReturn = {
30
22
  options?: MonacoEditorProps['options'];
31
- } & Dispose) | undefined;
23
+ dispose?: () => void;
24
+ } | undefined;
32
25
  export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.1-preview-d4775873.0",
7
+ "version": "0.5.1-preview-f7ec3fa7.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -37,8 +37,8 @@
37
37
  "scripts": {},
38
38
  "dependencies": {
39
39
  "@monaco-editor/react": "4.6.0",
40
- "@snack-uikit/loaders": "0.9.1",
41
- "@snack-uikit/utils": "3.7.0",
40
+ "@snack-uikit/loaders": "0.9.2-preview-f7ec3fa7.0",
41
+ "@snack-uikit/utils": "3.7.1-preview-f7ec3fa7.0",
42
42
  "chroma-js": "3.1.2",
43
43
  "classnames": "2.5.1",
44
44
  "monaco-yaml": "5.2.3"
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "@types/chroma-js": "2.4.4"
48
48
  },
49
- "gitHead": "1db3ab2954a7d659a5bd2cb7a8403d5500cecd31"
49
+ "gitHead": "41cd467095dc6f8b733bff37101ea84ab0e55351"
50
50
  }
@@ -6,7 +6,7 @@ import { Spinner } from '@snack-uikit/loaders';
6
6
  import { extractSupportProps, isBrowser, WithSupportProps } from '@snack-uikit/utils';
7
7
 
8
8
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
9
- import { useApplyJsonSchema, useCalculatedThemeValues, useHoverProvider } from './hooks';
9
+ import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
10
10
  import styles from './styles.module.scss';
11
11
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
12
12
  import { initLoaderConfig, isDark } from './utils';
@@ -34,7 +34,6 @@ export function CodeEditor({
34
34
  hasBackground = true,
35
35
  onMount,
36
36
  language,
37
- hoverDescription,
38
37
  ...props
39
38
  }: CodeEditorProps) {
40
39
  const monaco = useMonaco();
@@ -45,8 +44,6 @@ export function CodeEditor({
45
44
  'jsonSchema' in props ? props.jsonSchema : undefined,
46
45
  );
47
46
 
48
- useHoverProvider(language, hoverDescription);
49
-
50
47
  const onEditorMount = useCallback<OnMount>(
51
48
  (editor, monaco) => {
52
49
  monaco && isBrowser() && document?.fonts?.ready.finally(monaco.editor.remeasureFonts);
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
5
5
  import { useThemeContext } from '@snack-uikit/utils';
6
6
 
7
7
  import { THEME_VARS, YAML_CODE_EDITOR_OPTIONS } from './constants';
8
- import { ConfigureJsonSchemaReturn, Dispose, HoverDescription, JsonSchema } from './types';
8
+ import { ConfigureJsonSchemaReturn, JsonSchema } from './types';
9
9
  import { getJsonSchema } from './utils';
10
10
 
11
11
  function getThemeVars(styles: CSSStyleDeclaration) {
@@ -111,35 +111,3 @@ export function useApplyJsonSchema(language?: string, jsonSchema?: JsonSchema) {
111
111
  [jsonSchemaOptions, modelPath],
112
112
  );
113
113
  }
114
-
115
- export function useHoverProvider(language?: string, hoverDescription?: HoverDescription) {
116
- const monaco = useMonaco();
117
-
118
- const configureHoverProvider = useCallback((): Dispose | undefined => {
119
- if (!monaco || !language || !hoverDescription) {
120
- return;
121
- }
122
-
123
- return monaco.languages.registerHoverProvider(language, {
124
- provideHover: (model, position) => {
125
- const wordInfo = model.getWordAtPosition(position);
126
- const hoveredDescription = hoverDescription[wordInfo?.word ?? ''];
127
-
128
- if (wordInfo && hoveredDescription) {
129
- const { startColumn, endColumn } = wordInfo;
130
-
131
- return {
132
- range: new monaco.Range(position.lineNumber, startColumn, position.lineNumber, endColumn),
133
- contents: [{ value: hoveredDescription }],
134
- };
135
- }
136
- return null;
137
- },
138
- });
139
- }, [monaco, language, hoverDescription]);
140
-
141
- useEffect(() => {
142
- const { dispose } = configureHoverProvider() ?? {};
143
- return dispose;
144
- }, [configureHoverProvider]);
145
- }
@@ -1,13 +1,7 @@
1
1
  import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
2
2
  import { JSONSchema } from 'monaco-yaml';
3
3
 
4
- export type HoverDescription = {
5
- [word: string]: string;
6
- };
7
-
8
- export type EditorBaseProps = MonacoEditorProps & {
9
- hoverDescription?: HoverDescription;
10
- };
4
+ export type EditorBaseProps = MonacoEditorProps;
11
5
 
12
6
  export type SupportedSchemaLanguage = 'json' | 'yaml';
13
7
 
@@ -31,12 +25,9 @@ export type EditorWithJsonSchemaProps = Omit<EditorBaseProps, 'language' | 'path
31
25
  language: SupportedSchemaLanguage;
32
26
  } & (WithJsonSchema | WithoutJsonSchema);
33
27
 
34
- export type Dispose = {
35
- dispose?: () => void;
36
- };
37
-
38
28
  export type ConfigureJsonSchemaReturn =
39
- | ({
29
+ | {
40
30
  options?: MonacoEditorProps['options'];
41
- } & Dispose)
31
+ dispose?: () => void;
32
+ }
42
33
  | undefined;