@snack-uikit/code-editor 0.6.5-preview-580e8472.0 → 0.6.5-preview-6c5a9bc3.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
@@ -15,7 +15,8 @@
15
15
  | jsonSchema* | `JsonSchema` | - | Схема для валидации |
16
16
  | themeName | `string` | - | Название текущей темы. Значение не важно, важно что смена значения запускает пересчет стилей. |
17
17
  | hasBackground | `boolean` | true | Включение/отключение псевдобекграунда |
18
- | onCopyClick | `MouseEventHandler<HTMLElement>` | - | Клик по кнопке копирования |
18
+ | hasCopyHeader | `boolean` | - | Включение/отключение шапки с кнопкой копирования |
19
+ | onCopyClick | `() => void` | - | Клик по кнопке копирования |
19
20
  | defaultValue | `string` | - | Default value of the current model |
20
21
  | defaultLanguage | `string` | - | Default language of the current model |
21
22
  | defaultPath | `string` | - | Default path of the current model Will be passed as the third argument to `.createModel` method `monaco.editor.createModel(..., ..., monaco.Uri.parse(defaultPath))` |
@@ -1,4 +1,3 @@
1
- import { ButtonFunctionProps } from '@snack-uikit/button';
2
1
  import { WithSupportProps } from '@snack-uikit/utils';
3
2
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
4
3
  export type CodeEditorProps = WithSupportProps<{
@@ -10,9 +9,13 @@ export type CodeEditorProps = WithSupportProps<{
10
9
  * Включение/отключение псевдобекграунда
11
10
  */
12
11
  hasBackground?: boolean;
12
+ /**
13
+ * Включение/отключение шапки с кнопкой копирования
14
+ */
15
+ hasCopyHeader?: boolean;
13
16
  /**
14
17
  * Клик по кнопке копирования
15
18
  */
16
- onCopyClick?: ButtonFunctionProps['onClick'];
19
+ onCopyClick?(): void;
17
20
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
18
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, hasCopyHeader, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -22,7 +22,6 @@ const react_1 = require("@monaco-editor/react");
22
22
  const classnames_1 = __importDefault(require("classnames"));
23
23
  const react_2 = require("react");
24
24
  const loaders_1 = require("@snack-uikit/loaders");
25
- const locale_1 = require("@snack-uikit/locale");
26
25
  const typography_1 = require("@snack-uikit/typography");
27
26
  const utils_1 = require("@snack-uikit/utils");
28
27
  const constants_1 = require("./constants");
@@ -40,14 +39,12 @@ function CodeEditor(_a) {
40
39
  hasBackground = true,
41
40
  onMount,
42
41
  language,
43
- onCopyClick
42
+ onCopyClick,
43
+ hasCopyHeader
44
44
  } = _a,
45
- props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick"]);
45
+ props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick", "hasCopyHeader"]);
46
46
  const monaco = (0, react_1.useMonaco)();
47
47
  const [wrapperElement, setWrapperElement] = (0, react_2.useState)(null);
48
- const {
49
- t
50
- } = (0, locale_1.useLocale)();
51
48
  const {
52
49
  jsonSchemaProps,
53
50
  jsonSchemaOptions
@@ -122,10 +119,10 @@ function CodeEditor(_a) {
122
119
  className: className
123
120
  }, (0, utils_1.extractSupportProps)(props), {
124
121
  ref: setWrapperElement,
125
- children: [(0, jsx_runtime_1.jsxs)("div", {
122
+ children: [hasCopyHeader && (0, jsx_runtime_1.jsxs)("div", {
126
123
  className: styles_module_scss_1.default.headline,
127
- children: [(0, jsx_runtime_1.jsx)(typography_1.Typography.SansLabelS, {
128
- children: t('Markdown.codeEditorTitle')
124
+ children: [language && (0, jsx_runtime_1.jsx)(typography_1.Typography.SansLabelS, {
125
+ children: (0, utils_2.toTitleCase)(language)
129
126
  }), (0, jsx_runtime_1.jsx)(CopyButton_1.CopyButton, {
130
127
  valueToCopy: props.value || '',
131
128
  size: 's',
@@ -54,7 +54,7 @@ function CopyButton(_a) {
54
54
  clearTimeout(timerId.current);
55
55
  }, []);
56
56
  return (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, {
57
- tip: t('Markdown.copyButtonToolTip'),
57
+ tip: t('CodeEditor.copyButtonToolTip'),
58
58
  children: (0, jsx_runtime_1.jsx)(button_1.ButtonFunction, Object.assign({}, (0, utils_1.extractSupportProps)(rest), {
59
59
  onClick: handleClick,
60
60
  className: className,
@@ -3,3 +3,4 @@ import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
6
+ export declare function toTitleCase(value: string): string;
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", {
11
11
  exports.getJsonSchema = void 0;
12
12
  exports.rgb2hsl = rgb2hsl;
13
13
  exports.isDark = isDark;
14
+ exports.toTitleCase = toTitleCase;
14
15
  const chroma_js_1 = __importDefault(require("chroma-js"));
15
16
  const constants_1 = require("./constants");
16
17
  function rgb2hsl(HTMLcolor) {
@@ -50,4 +51,12 @@ const getJsonSchema = jsonSchema => jsonSchema && Object.assign(Object.assign({}
50
51
  uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || constants_1.DEFAULT_SCHEMA_URI,
51
52
  fileMatch: [jsonSchema.fileMatch]
52
53
  });
53
- exports.getJsonSchema = getJsonSchema;
54
+ exports.getJsonSchema = getJsonSchema;
55
+ function toTitleCase(value) {
56
+ if (value.trim().length === 0) {
57
+ return value;
58
+ }
59
+ const valueLetters = value.trim().split('');
60
+ valueLetters[0] = valueLetters[0].toUpperCase();
61
+ return valueLetters.join('');
62
+ }
@@ -1,4 +1,3 @@
1
- import { ButtonFunctionProps } from '@snack-uikit/button';
2
1
  import { WithSupportProps } from '@snack-uikit/utils';
3
2
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
4
3
  export type CodeEditorProps = WithSupportProps<{
@@ -10,9 +9,13 @@ export type CodeEditorProps = WithSupportProps<{
10
9
  * Включение/отключение псевдобекграунда
11
10
  */
12
11
  hasBackground?: boolean;
12
+ /**
13
+ * Включение/отключение шапки с кнопкой копирования
14
+ */
15
+ hasCopyHeader?: boolean;
13
16
  /**
14
17
  * Клик по кнопке копирования
15
18
  */
16
- onCopyClick?: ButtonFunctionProps['onClick'];
19
+ onCopyClick?(): void;
17
20
  }> & (EditorBaseProps | EditorWithJsonSchemaProps);
18
- export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function CodeEditor({ themeName, className, theme, options, loading, hasBackground, onMount, language, onCopyClick, hasCopyHeader, ...props }: CodeEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -14,19 +14,17 @@ import { Editor, useMonaco } from '@monaco-editor/react';
14
14
  import cn from 'classnames';
15
15
  import { useCallback, useMemo, useState } from 'react';
16
16
  import { Spinner } from '@snack-uikit/loaders';
17
- import { useLocale } from '@snack-uikit/locale';
18
17
  import { Typography } from '@snack-uikit/typography';
19
18
  import { extractSupportProps, isBrowser } from '@snack-uikit/utils';
20
19
  import { CODE_EDITOR_OPTIONS, DEFAULT_THEME_OPTIONS, DEFAULT_THEME_VALUES } from './constants';
21
20
  import { CopyButton } from './CopyButton';
22
21
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
23
22
  import styles from './styles.module.css';
24
- import { isDark } from './utils';
23
+ import { isDark, toTitleCase } from './utils';
25
24
  export function CodeEditor(_a) {
26
- var { themeName, className, theme, options, loading, hasBackground = true, onMount, language, onCopyClick } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick"]);
25
+ var { themeName, className, theme, options, loading, hasBackground = true, onMount, language, onCopyClick, hasCopyHeader } = _a, props = __rest(_a, ["themeName", "className", "theme", "options", "loading", "hasBackground", "onMount", "language", "onCopyClick", "hasCopyHeader"]);
27
26
  const monaco = useMonaco();
28
27
  const [wrapperElement, setWrapperElement] = useState(null);
29
- const { t } = useLocale();
30
28
  const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(language, 'jsonSchema' in props ? props.jsonSchema : undefined);
31
29
  const onEditorMount = useCallback((editor, monaco) => {
32
30
  var _a;
@@ -91,5 +89,5 @@ export function CodeEditor(_a) {
91
89
  fontFamily: themeValues.mono.body.s['font-family'],
92
90
  }
93
91
  : DEFAULT_THEME_OPTIONS.mono.s)), options)), [options, themeValues === null || themeValues === void 0 ? void 0 : themeValues.mono, jsonSchemaOptions]);
94
- return (_jsxs("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, children: [_jsxs("div", { className: styles.headline, children: [_jsx(Typography.SansLabelS, { children: t('Markdown.codeEditorTitle') }), _jsx(CopyButton, { valueToCopy: props.value || '', size: 's', onClick: onCopyClick })] }), _jsx(Editor, Object.assign({}, jsonSchemaProps, props, { theme: theme !== null && theme !== void 0 ? theme : (dark ? 'snackDark' : 'snack'), className: cn({ [styles.editor]: hasBackground }), loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions, onMount: onEditorMount, language: language }))] })));
92
+ return (_jsxs("div", Object.assign({ className: className }, extractSupportProps(props), { ref: setWrapperElement, children: [hasCopyHeader && (_jsxs("div", { className: styles.headline, children: [language && _jsx(Typography.SansLabelS, { children: toTitleCase(language) }), _jsx(CopyButton, { valueToCopy: props.value || '', size: 's', onClick: onCopyClick })] })), _jsx(Editor, Object.assign({}, jsonSchemaProps, props, { theme: theme !== null && theme !== void 0 ? theme : (dark ? 'snackDark' : 'snack'), className: cn({ [styles.editor]: hasBackground }), loading: loading !== null && loading !== void 0 ? loading : _jsx(Spinner, {}), options: mergedOptions, onMount: onEditorMount, language: language }))] })));
95
93
  }
@@ -37,5 +37,5 @@ export function CopyButton(_a) {
37
37
  closeChecked();
38
38
  clearTimeout(timerId.current);
39
39
  }, []);
40
- return (_jsx(Tooltip, { tip: t('Markdown.copyButtonToolTip'), children: _jsx(ButtonFunction, Object.assign({}, extractSupportProps(rest), { onClick: handleClick, className: className, "data-test-id": 'button-copy-value', type: 'button', icon: isChecked ? _jsx(CheckSVG, { className: styles.checkIcon }) : _jsx(CopySVG, {}), size: size })) }));
40
+ return (_jsx(Tooltip, { tip: t('CodeEditor.copyButtonToolTip'), children: _jsx(ButtonFunction, Object.assign({}, extractSupportProps(rest), { onClick: handleClick, className: className, "data-test-id": 'button-copy-value', type: 'button', icon: isChecked ? _jsx(CheckSVG, { className: styles.checkIcon }) : _jsx(CopySVG, {}), size: size })) }));
41
41
  }
@@ -3,3 +3,4 @@ import { JsonSchema } from './types';
3
3
  export declare function rgb2hsl(HTMLcolor: string): number[];
4
4
  export declare function isDark(color: string): boolean;
5
5
  export declare const getJsonSchema: (jsonSchema?: JsonSchema) => SchemasSettings | undefined;
6
+ export declare function toTitleCase(value: string): string;
@@ -38,3 +38,11 @@ export function isDark(color) {
38
38
  return (h < 0.55 && l >= 0.5) || (h >= 0.55 && l >= 0.75);
39
39
  }
40
40
  export const getJsonSchema = (jsonSchema) => jsonSchema && Object.assign(Object.assign({}, jsonSchema), { uri: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.uri) || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] });
41
+ export function toTitleCase(value) {
42
+ if (value.trim().length === 0) {
43
+ return value;
44
+ }
45
+ const valueLetters = value.trim().split('');
46
+ valueLetters[0] = valueLetters[0].toUpperCase();
47
+ return valueLetters.join('');
48
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.5-preview-580e8472.0",
7
+ "version": "0.6.5-preview-6c5a9bc3.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -41,7 +41,7 @@
41
41
  "@snack-uikit/button": "0.19.11",
42
42
  "@snack-uikit/icons": "0.26.3",
43
43
  "@snack-uikit/loaders": "0.9.5",
44
- "@snack-uikit/locale": "0.14.1-preview-580e8472.0",
44
+ "@snack-uikit/locale": "0.14.1-preview-6c5a9bc3.0",
45
45
  "@snack-uikit/tooltip": "0.17.2",
46
46
  "@snack-uikit/typography": "0.8.7",
47
47
  "@snack-uikit/utils": "3.8.2",
@@ -52,5 +52,5 @@
52
52
  "devDependencies": {
53
53
  "@types/chroma-js": "2.4.4"
54
54
  },
55
- "gitHead": "83474111057d185ee911d5bb4489288c89f1490f"
55
+ "gitHead": "f7b20fc5008846a7aaddf93c2cbeb6197978e97f"
56
56
  }
@@ -2,9 +2,7 @@ import { Editor, OnMount, useMonaco } from '@monaco-editor/react';
2
2
  import cn from 'classnames';
3
3
  import { useCallback, useMemo, useState } from 'react';
4
4
 
5
- import { ButtonFunctionProps } from '@snack-uikit/button';
6
5
  import { Spinner } from '@snack-uikit/loaders';
7
- import { useLocale } from '@snack-uikit/locale';
8
6
  import { Typography } from '@snack-uikit/typography';
9
7
  import { extractSupportProps, isBrowser, WithSupportProps } from '@snack-uikit/utils';
10
8
 
@@ -13,7 +11,7 @@ import { CopyButton } from './CopyButton';
13
11
  import { useApplyJsonSchema, useCalculatedThemeValues } from './hooks';
14
12
  import styles from './styles.module.scss';
15
13
  import { EditorBaseProps, EditorWithJsonSchemaProps } from './types';
16
- import { isDark } from './utils';
14
+ import { isDark, toTitleCase } from './utils';
17
15
 
18
16
  export type CodeEditorProps = WithSupportProps<{
19
17
  /**
@@ -24,10 +22,14 @@ export type CodeEditorProps = WithSupportProps<{
24
22
  * Включение/отключение псевдобекграунда
25
23
  */
26
24
  hasBackground?: boolean;
25
+ /**
26
+ * Включение/отключение шапки с кнопкой копирования
27
+ */
28
+ hasCopyHeader?: boolean;
27
29
  /**
28
30
  * Клик по кнопке копирования
29
31
  */
30
- onCopyClick?: ButtonFunctionProps['onClick'];
32
+ onCopyClick?(): void;
31
33
  }> &
32
34
  (EditorBaseProps | EditorWithJsonSchemaProps);
33
35
 
@@ -41,13 +43,12 @@ export function CodeEditor({
41
43
  onMount,
42
44
  language,
43
45
  onCopyClick,
46
+ hasCopyHeader,
44
47
  ...props
45
48
  }: CodeEditorProps) {
46
49
  const monaco = useMonaco();
47
50
  const [wrapperElement, setWrapperElement] = useState<HTMLDivElement | null>(null);
48
51
 
49
- const { t } = useLocale();
50
-
51
52
  const { jsonSchemaProps, jsonSchemaOptions } = useApplyJsonSchema(
52
53
  language,
53
54
  'jsonSchema' in props ? props.jsonSchema : undefined,
@@ -143,10 +144,12 @@ export function CodeEditor({
143
144
 
144
145
  return (
145
146
  <div className={className} {...extractSupportProps(props)} ref={setWrapperElement}>
146
- <div className={styles.headline}>
147
- <Typography.SansLabelS>{t('Markdown.codeEditorTitle')}</Typography.SansLabelS>
148
- <CopyButton valueToCopy={props.value || ''} size={'s'} onClick={onCopyClick} />
149
- </div>
147
+ {hasCopyHeader && (
148
+ <div className={styles.headline}>
149
+ {language && <Typography.SansLabelS>{toTitleCase(language)}</Typography.SansLabelS>}
150
+ <CopyButton valueToCopy={props.value || ''} size={'s'} onClick={onCopyClick} />
151
+ </div>
152
+ )}
150
153
  <Editor
151
154
  {...jsonSchemaProps}
152
155
  {...props}
@@ -41,7 +41,7 @@ export function CopyButton({ valueToCopy, size = 's', className, onClick, ...res
41
41
  );
42
42
 
43
43
  return (
44
- <Tooltip tip={t('Markdown.copyButtonToolTip')}>
44
+ <Tooltip tip={t('CodeEditor.copyButtonToolTip')}>
45
45
  <ButtonFunction
46
46
  {...extractSupportProps(rest)}
47
47
  onClick={handleClick}
@@ -1,6 +1,6 @@
1
- @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
1
+ @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables' as ste;
2
2
 
3
3
 
4
4
  .checkIcon {
5
- fill: styles-theme-variables.$sys-green-accent-default
5
+ fill: ste.$sys-green-accent-default
6
6
  }
@@ -1,5 +1,6 @@
1
- @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables';
2
- @use '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-markdown';
1
+ @use '@snack-uikit/figma-tokens/build/scss/styles-theme-variables' as var;
2
+ @use '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-markdown' as stm;
3
+
3
4
 
4
5
 
5
6
  .editor {
@@ -15,19 +16,18 @@
15
16
 
16
17
  width: 100%;
17
18
 
18
- opacity: styles-theme-variables.$opacity-a004;
19
- background-color: styles-theme-variables.$sys-neutral-accent-default;
19
+ opacity: var.$opacity-a004;
20
+ background-color: var.$sys-neutral-accent-default;
20
21
  }
21
22
  }
22
23
 
23
24
  .headline {
24
- @include styles-tokens-markdown.composite-var(styles-tokens-markdown.$markdown-syntax-code-editor-headline);
25
+ @include stm.composite-var(stm.$markdown-syntax-code-editor-headline);
25
26
 
26
27
  display: flex;
27
28
  align-items: center;
28
29
  justify-content: space-between;
29
30
 
30
- background-color: styles-tokens-markdown.$sys-neutral-background;
31
- border-color: styles-tokens-markdown.$sys-neutral-decor-default;
32
-
31
+ background-color: stm.$sys-neutral-background;
32
+ border-color: stm.$sys-neutral-decor-default;
33
33
  }
@@ -56,3 +56,13 @@ export function isDark(color: string) {
56
56
 
57
57
  export const getJsonSchema = (jsonSchema?: JsonSchema): SchemasSettings | undefined =>
58
58
  jsonSchema && { ...jsonSchema, uri: jsonSchema?.uri || DEFAULT_SCHEMA_URI, fileMatch: [jsonSchema.fileMatch] };
59
+
60
+ export function toTitleCase(value: string) {
61
+ if (value.trim().length === 0) {
62
+ return value;
63
+ }
64
+
65
+ const valueLetters = value.trim().split('');
66
+ valueLetters[0] = valueLetters[0].toUpperCase();
67
+ return valueLetters.join('');
68
+ }