@synerise/ds-code-area 0.3.4 → 0.4.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.4.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-code-area@0.4.0...@synerise/ds-code-area@0.4.1) (2024-12-13)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-code-area
9
+
10
+
11
+
12
+
13
+
14
+ # [0.4.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-code-area@0.3.4...@synerise/ds-code-area@0.4.0) (2024-12-11)
15
+
16
+
17
+ ### Features
18
+
19
+ * **code-area:** switch monaco library ([c0d4ef6](https://github.com/Synerise/synerise-design/commit/c0d4ef68e26e791e99b4086b9847cbb524505af1))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.3.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-code-area@0.3.3...@synerise/ds-code-area@0.3.4) (2024-12-04)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-code-area
package/dist/CodeArea.js CHANGED
@@ -10,12 +10,14 @@ var CodeArea = function CodeArea(_ref) {
10
10
  getPopupContainer = _ref$getPopupContaine === void 0 ? defaultGetPopupContainer : _ref$getPopupContaine,
11
11
  onFullscreenChange = _ref.onFullscreenChange,
12
12
  codeAreaProps = _objectWithoutPropertiesLoose(_ref, _excluded);
13
- var wrapperRef = useRef(null);
14
13
  var _useState = useState(false),
15
14
  isFullscreen = _useState[0],
16
15
  setIsFullscreen = _useState[1];
16
+ var wrapperRef = useRef(null);
17
17
  var toggleFullscreen = function toggleFullscreen() {
18
- setIsFullscreen(!isFullscreen);
18
+ setIsFullscreen(function (prevState) {
19
+ return !prevState;
20
+ });
19
21
  onFullscreenChange && onFullscreenChange(isFullscreen);
20
22
  };
21
23
  return /*#__PURE__*/React.createElement("div", {
@@ -1,6 +1,7 @@
1
- import type { CSSProperties, ReactNode } from 'react';
2
- import { MonacoEditorProps } from 'react-monaco-editor';
3
- import { TooltipProps } from 'antd/lib/tooltip';
1
+ import type monaco from 'monaco-editor/esm/vs/editor/editor.api';
2
+ import type { EditorProps } from '@monaco-editor/react';
3
+ import type { ReactNode, CSSProperties } from 'react';
4
+ import type { TooltipProps } from 'antd/lib/tooltip';
4
5
  import TooltipExtendedProps from '@synerise/ds-tooltip/dist/Tooltip.types';
5
6
  export type CodeAreaSyntax = 'json' | 'html' | 'css' | 'typescript' | 'javascript' | string;
6
7
  export type CodeAreaSyntaxOption<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = {
@@ -12,9 +13,8 @@ export type CodeAreaTexts = {
12
13
  closeFullscreen: ReactNode;
13
14
  fullscreenTitle: ReactNode;
14
15
  };
15
- export type CodeAreaProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = Omit<MonacoEditorProps, 'language'> & {
16
+ export type CodeAreaCommonProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = Omit<EditorProps, 'language'> & {
16
17
  label?: ReactNode;
17
- fullscreenLabel?: ReactNode;
18
18
  description?: ReactNode;
19
19
  texts?: Partial<CodeAreaTexts>;
20
20
  counter?: {
@@ -25,9 +25,12 @@ export type CodeAreaProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> =
25
25
  syntaxOptions?: CodeAreaSyntaxOption<SyntaxName>[];
26
26
  currentSyntax: SyntaxName;
27
27
  allowFullscreen?: boolean;
28
+ isFullscreen: boolean;
29
+ toggleFullscreen: () => void;
30
+ value?: string;
31
+ defaultValue?: string;
28
32
  readOnly?: boolean;
29
33
  tooltip?: ReactNode;
30
- getPopupContainer?: (node: HTMLElement) => HTMLElement;
31
34
  tooltipProps?: TooltipExtendedProps & TooltipProps;
32
35
  style?: CSSProperties;
33
36
  zIndex?: string | number;
@@ -37,15 +40,24 @@ export type CodeAreaProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> =
37
40
  count?: number;
38
41
  isValid?: boolean;
39
42
  }) => ReactNode;
43
+ onSyntaxChange?: (newSyntax: SyntaxName) => void;
44
+ };
45
+ export type CodeAreaEditorProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = CodeAreaCommonProps<SyntaxName> & {
46
+ fullscreenLabel?: ReactNode;
40
47
  renderAdditionalDescription?: (props: {
41
48
  isFullscreen?: boolean;
42
49
  count?: number;
43
50
  isValid?: boolean;
44
51
  }) => ReactNode;
52
+ };
53
+ export type CodeAreaProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = Omit<CodeAreaEditorProps<SyntaxName>, 'toggleFullscreen' | 'isFullscreen'> & {
45
54
  onFullscreenChange?: (isFullscreen: boolean) => void;
46
- onSyntaxChange?: (newSyntax: SyntaxName) => void;
55
+ getPopupContainer?: (node: HTMLElement) => HTMLElement;
47
56
  };
48
- export type CodeAreaEditorProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = CodeAreaProps<SyntaxName> & {
49
- isFullscreen: boolean;
50
- toggleFullscreen: () => void;
57
+ export type CodeAreaEditorRawProps<SyntaxName extends CodeAreaSyntax = CodeAreaSyntax> = CodeAreaCommonProps<SyntaxName> & {
58
+ isValid: boolean;
59
+ isSyntaxSelectVisible?: boolean;
60
+ onDidChangeMarkers?: (markers: monaco.editor.IMarker[]) => void;
61
+ counterLimit?: number;
62
+ count?: number;
51
63
  };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const AriaContainer: ({ element }: {
3
+ element: HTMLElement;
4
+ }) => React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ export var AriaContainer = function AriaContainer(_ref) {
3
+ var element = _ref.element;
4
+ var ariaContainerRef = useRef(null);
5
+ useEffect(function () {
6
+ var container = ariaContainerRef.current;
7
+ if (container && element.childNodes.length > 0) {
8
+ container.appendChild(element);
9
+ }
10
+ }, [element]);
11
+ return /*#__PURE__*/React.createElement("div", {
12
+ className: "monaco-aria-custom-container",
13
+ "data-testid": "monaco-aria-container",
14
+ ref: ariaContainerRef
15
+ });
16
+ };
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { CodeAreaEditorProps } from '../CodeArea.types';
3
- export declare const CodeAreaEditor: ({ label, description, counter, errorText, syntaxOptions, currentSyntax, allowFullscreen, fullscreenLabel, renderFooterContent, renderAdditionalDescription, tooltip, tooltipProps, style, className, texts, onChange, onSyntaxChange, value, readOnly, isFullscreen, toggleFullscreen, zIndex, ...monacoProps }: CodeAreaEditorProps) => React.JSX.Element;
3
+ export declare const CodeAreaEditor: ({ renderAdditionalDescription, description, errorText, style, zIndex, className, counter, fullscreenLabel, tooltip, label, tooltipProps, ...props }: CodeAreaEditorProps) => React.JSX.Element;
4
4
  export default CodeAreaEditor;
@@ -1,4 +1,4 @@
1
- var _excluded = ["label", "description", "counter", "errorText", "syntaxOptions", "currentSyntax", "allowFullscreen", "fullscreenLabel", "renderFooterContent", "renderAdditionalDescription", "tooltip", "tooltipProps", "style", "className", "texts", "onChange", "onSyntaxChange", "value", "readOnly", "isFullscreen", "toggleFullscreen", "zIndex"];
1
+ var _excluded = ["renderAdditionalDescription", "description", "errorText", "style", "zIndex", "className", "counter", "fullscreenLabel", "tooltip", "label", "tooltipProps"];
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
4
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -6,158 +6,75 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
6
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
7
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
8
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
- import React, { useState, useMemo, useRef, useEffect } from 'react';
10
- import MonacoEditor from 'react-monaco-editor';
11
- import { InlineSelect } from '@synerise/ds-inline-edit';
9
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
10
  import { Label } from '@synerise/ds-input';
13
- import { NOOP, useResizeObserver } from '@synerise/ds-utils';
11
+ import { useResizeObserver } from '@synerise/ds-utils';
12
+ import { getCharCount } from '../utils/getCharCount';
13
+ import { ContentAbove, ContentBelow, FullscreenHeader } from './index';
14
+ import { CodeAreaEditorRaw } from './CodeAreaEditorRaw';
14
15
  import * as S from '../CodeArea.styles';
15
- import { FullscreenHeader, ContentBelow, ContentAbove, BottomBar } from './index';
16
- import { getDefaultTexts, getCharCount, calculateRequiredSpace } from '../utils';
17
- import { MONACO_DEFAULT_OPTIONS, TRIGGER_SOURCE, DS_MONACO_THEME, DS_MONACO_THEME_NAME } from '../constants';
16
+ import { getDefaultTexts } from '../utils/getDefaultTexts';
17
+ import { calculateRequiredSpace } from '../utils/calculateRequiredSpace';
18
18
  export var CodeAreaEditor = function CodeAreaEditor(_ref) {
19
- var label = _ref.label,
19
+ var renderAdditionalDescription = _ref.renderAdditionalDescription,
20
20
  description = _ref.description,
21
- counter = _ref.counter,
22
21
  errorText = _ref.errorText,
23
- syntaxOptions = _ref.syntaxOptions,
24
- currentSyntax = _ref.currentSyntax,
25
- allowFullscreen = _ref.allowFullscreen,
22
+ style = _ref.style,
23
+ zIndex = _ref.zIndex,
24
+ className = _ref.className,
25
+ counter = _ref.counter,
26
26
  fullscreenLabel = _ref.fullscreenLabel,
27
- renderFooterContent = _ref.renderFooterContent,
28
- renderAdditionalDescription = _ref.renderAdditionalDescription,
29
27
  tooltip = _ref.tooltip,
28
+ label = _ref.label,
30
29
  tooltipProps = _ref.tooltipProps,
31
- style = _ref.style,
32
- className = _ref.className,
33
- texts = _ref.texts,
34
- onChange = _ref.onChange,
35
- onSyntaxChange = _ref.onSyntaxChange,
36
- value = _ref.value,
37
- readOnly = _ref.readOnly,
38
- isFullscreen = _ref.isFullscreen,
39
- toggleFullscreen = _ref.toggleFullscreen,
40
- zIndex = _ref.zIndex,
41
- monacoProps = _objectWithoutPropertiesLoose(_ref, _excluded);
30
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
31
+ var allowFullscreen = props.allowFullscreen,
32
+ texts = props.texts,
33
+ isFullscreen = props.isFullscreen,
34
+ toggleFullscreen = props.toggleFullscreen,
35
+ syntaxOptions = props.syntaxOptions,
36
+ value = props.value,
37
+ renderFooterContent = props.renderFooterContent,
38
+ readOnly = props.readOnly,
39
+ defaultValue = props.defaultValue;
42
40
  var _useState = useState(true),
43
41
  isValid = _useState[0],
44
42
  setIsValid = _useState[1];
45
- var editorRef = useRef(null);
46
- var monacoRef = useRef(null);
47
- var wrapperRef = useRef(null);
48
43
  var contentBelowRef = useRef(null);
49
- var _useResizeObserver = useResizeObserver(wrapperRef),
50
- height = _useResizeObserver.height,
51
- width = _useResizeObserver.width;
52
- var _useResizeObserver2 = useResizeObserver(contentBelowRef),
53
- contentBelowHeight = _useResizeObserver2.height;
44
+ var _useResizeObserver = useResizeObserver(contentBelowRef),
45
+ contentBelowHeight = _useResizeObserver.height;
54
46
  var counterLimit = counter == null ? void 0 : counter.limit;
55
- var count = getCharCount(value, counterLimit);
56
- var allTexts = getDefaultTexts(texts);
57
- var editorWillMount = monacoProps.editorWillMount,
58
- editorDidMount = monacoProps.editorDidMount,
59
- options = monacoProps.options;
60
- var combinedOptions = _objectSpread({}, MONACO_DEFAULT_OPTIONS, {}, options, {
61
- readOnly: readOnly,
62
- domReadOnly: readOnly
63
- });
64
- var handleEditorWillMount = function handleEditorWillMount(monacoInstance) {
65
- monacoRef.current = monacoInstance;
66
- monacoInstance.editor.defineTheme(DS_MONACO_THEME_NAME, DS_MONACO_THEME);
67
- monacoInstance.editor.setTheme(DS_MONACO_THEME_NAME);
68
- monacoInstance.editor.onDidChangeMarkers(function () {
69
- var markers = monacoInstance.editor.getModelMarkers({});
70
- setIsValid(!markers.length);
71
- });
72
- editorWillMount && editorWillMount(monacoInstance);
73
- };
74
- var handleEditorDidMount = function handleEditorDidMount(editor, monacoInstance) {
75
- editorRef.current = editor;
76
- editorDidMount && editorDidMount(editor, monacoInstance);
77
- };
78
- var handleChange = function handleChange(newValue, event) {
79
- if (counterLimit && newValue.length > counterLimit) {
80
- editorRef.current && editorRef.current.trigger(TRIGGER_SOURCE, 'undo', null);
81
- return;
82
- }
83
- if (editorRef.current) {
84
- editorRef.current.pushUndoStop();
85
- }
86
- onChange && onChange(newValue, event);
87
- };
88
- var labelWithTooltip = label && /*#__PURE__*/React.createElement(Label, {
89
- label: label,
90
- tooltip: tooltip,
91
- tooltipConfig: (tooltip || tooltipProps) && _objectSpread({}, tooltipProps, {
92
- placement: isFullscreen ? 'right' : undefined,
93
- title: tooltip
94
- })
95
- });
96
- var renderCounter = function renderCounter(placement) {
47
+ var count = getCharCount(value || defaultValue, counterLimit);
48
+ var renderCounter = useCallback(function (placement) {
97
49
  return counterLimit && (!placement || (counter == null ? void 0 : counter.placement) === placement) && /*#__PURE__*/React.createElement(S.Counter, null, count, " / ", counter.limit);
98
- };
50
+ }, [counterLimit, counter, count]);
51
+ var handleOnDidChangeMarkers = useCallback(function (markers) {
52
+ setIsValid(!markers.length);
53
+ }, []);
54
+ var labelWithTooltip = useMemo(function () {
55
+ return label && /*#__PURE__*/React.createElement(Label, {
56
+ label: label,
57
+ tooltip: tooltip,
58
+ tooltipConfig: (tooltip || tooltipProps) && _objectSpread({}, tooltipProps, {
59
+ placement: isFullscreen ? 'right' : undefined,
60
+ title: tooltip
61
+ })
62
+ });
63
+ }, [isFullscreen, tooltip, tooltipProps, label]);
64
+ var additionalDescription = useMemo(function () {
65
+ return renderAdditionalDescription && /*#__PURE__*/React.createElement(S.AdditionalDescription, null, renderAdditionalDescription({
66
+ isFullscreen: isFullscreen,
67
+ count: count,
68
+ isValid: isValid
69
+ }));
70
+ }, [count, isValid, isFullscreen, renderAdditionalDescription]);
99
71
  useEffect(function () {
100
72
  setIsValid(!errorText);
101
73
  }, [errorText]);
102
- useEffect(function () {
103
- if (editorRef.current) {
104
- var _editorRef$current, _monacoRef$current;
105
- var currentModel = (_editorRef$current = editorRef.current) == null ? void 0 : _editorRef$current.getModel();
106
- // eslint-disable-next-line no-unused-expressions
107
- currentModel && ((_monacoRef$current = monacoRef.current) == null ? void 0 : _monacoRef$current.editor.setModelLanguage(currentModel, currentSyntax));
108
- }
109
- }, [currentSyntax]);
110
- var _useMemo = useMemo(function () {
111
- var source = syntaxOptions == null ? void 0 : syntaxOptions.map(function (item) {
112
- var itemLabel = item.label,
113
- language = item.language;
114
- return {
115
- key: language,
116
- text: itemLabel || language
117
- };
118
- });
119
- var currentItem = syntaxOptions == null ? void 0 : syntaxOptions.find(function (item) {
120
- return item.language === currentSyntax;
121
- });
122
- return {
123
- syntaxDataSource: source,
124
- currentSyntaxItem: currentItem || {
125
- language: currentSyntax
126
- }
127
- };
128
- }, [currentSyntax, syntaxOptions]),
129
- syntaxDataSource = _useMemo.syntaxDataSource,
130
- currentSyntaxItem = _useMemo.currentSyntaxItem;
131
- var syntaxSelect = useMemo(function () {
132
- return syntaxDataSource && syntaxDataSource.length > 1 && !readOnly ? /*#__PURE__*/React.createElement(InlineSelect, {
133
- size: "small",
134
- expanded: false,
135
- input: {
136
- name: 'syntax-select',
137
- value: currentSyntaxItem.label || currentSyntaxItem.language,
138
- onChange: NOOP
139
- },
140
- onValueChange: function onValueChange(item) {
141
- item.key && onSyntaxChange && onSyntaxChange("" + item.key);
142
- },
143
- initialValue: currentSyntaxItem.label || currentSyntaxItem.language,
144
- dataSource: syntaxDataSource
145
- }) : /*#__PURE__*/React.createElement(S.SyntaxTitle, {
146
- size: "small"
147
- }, currentSyntaxItem.label || currentSyntaxItem.language);
148
- }, [currentSyntaxItem.label, currentSyntaxItem.language, onSyntaxChange, readOnly, syntaxDataSource]);
149
- var customFooterContent = renderFooterContent && /*#__PURE__*/React.createElement(S.BottomBarElement, null, renderFooterContent({
150
- isFullscreen: isFullscreen,
151
- count: count,
152
- isValid: isValid
153
- }));
154
- var additionalDescription = renderAdditionalDescription && /*#__PURE__*/React.createElement(S.AdditionalDescription, null, renderAdditionalDescription({
155
- isFullscreen: isFullscreen,
156
- count: count,
157
- isValid: isValid
158
- }));
159
- var isBottomBarShowing = Boolean(syntaxSelect || allowFullscreen && !isFullscreen || customFooterContent);
74
+ var isSyntaxSelectVisible = syntaxOptions && syntaxOptions.length > 1 && !readOnly;
75
+ var isBottomBarShowing = Boolean(isSyntaxSelectVisible || allowFullscreen && !isFullscreen || renderFooterContent);
160
76
  var requiredSpace = isFullscreen ? calculateRequiredSpace(isBottomBarShowing, contentBelowHeight) : 0;
77
+ var allTexts = getDefaultTexts(texts);
161
78
  return /*#__PURE__*/React.createElement(S.CodeAreaWrapper, {
162
79
  readOnly: !!readOnly,
163
80
  requiredSpace: requiredSpace,
@@ -172,27 +89,14 @@ export var CodeAreaEditor = function CodeAreaEditor(_ref) {
172
89
  }), !isFullscreen && /*#__PURE__*/React.createElement(ContentAbove, {
173
90
  label: labelWithTooltip,
174
91
  counter: renderCounter('top')
175
- }), /*#__PURE__*/React.createElement(S.CodeAreaContent, null, /*#__PURE__*/React.createElement(S.EditorWrapper, {
176
- hasError: Boolean(errorText)
177
- }, /*#__PURE__*/React.createElement(S.EditorInnerWrapper, {
178
- ref: wrapperRef
179
- }, /*#__PURE__*/React.createElement(MonacoEditor, _extends({
180
- theme: DS_MONACO_THEME_NAME,
181
- width: width,
182
- height: height
183
- }, monacoProps, {
184
- options: combinedOptions,
185
- value: value,
186
- onChange: handleChange,
187
- editorDidMount: handleEditorDidMount,
188
- editorWillMount: handleEditorWillMount,
189
- language: currentSyntax
190
- }))), isBottomBarShowing && /*#__PURE__*/React.createElement(BottomBar, {
191
- texts: allTexts,
192
- syntaxSelect: syntaxSelect,
193
- allowFullscreen: allowFullscreen && !isFullscreen,
194
- toggleFullscreen: toggleFullscreen,
195
- customFooterContent: customFooterContent
92
+ }), /*#__PURE__*/React.createElement(S.CodeAreaContent, null, /*#__PURE__*/React.createElement(CodeAreaEditorRaw, _extends({}, props, {
93
+ onDidChangeMarkers: handleOnDidChangeMarkers,
94
+ counter: counter,
95
+ errorText: errorText,
96
+ count: count,
97
+ counterLimit: counterLimit,
98
+ isSyntaxSelectVisible: isSyntaxSelectVisible,
99
+ isValid: isValid
196
100
  })), /*#__PURE__*/React.createElement(ContentBelow, {
197
101
  ref: contentBelowRef,
198
102
  errorText: errorText,
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { CodeAreaEditorRawProps } from 'CodeArea.types';
3
+ export declare const CodeAreaEditorRaw: ({ onMount, beforeMount, options, errorText, texts, allowFullscreen, toggleFullscreen, renderFooterContent, isFullscreen, count, counterLimit, onChange, isValid, onDidChangeMarkers, isSyntaxSelectVisible, syntaxOptions, currentSyntax, readOnly, onSyntaxChange, ...props }: CodeAreaEditorRawProps) => React.JSX.Element;
4
+ export default CodeAreaEditorRaw;
@@ -0,0 +1,162 @@
1
+ var _excluded = ["onMount", "beforeMount", "options", "errorText", "texts", "allowFullscreen", "toggleFullscreen", "renderFooterContent", "isFullscreen", "count", "counterLimit", "onChange", "isValid", "onDidChangeMarkers", "isSyntaxSelectVisible", "syntaxOptions", "currentSyntax", "readOnly", "onSyntaxChange"];
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
10
+ import Editor from '@monaco-editor/react';
11
+ import Loader from '@synerise/ds-loader';
12
+ import { InlineSelect } from '@synerise/ds-inline-edit';
13
+ import { NOOP, useResizeObserver } from '@synerise/ds-utils';
14
+ import { getDefaultTexts } from '../utils/getDefaultTexts';
15
+ import { DS_MONACO_THEME, DS_MONACO_THEME_NAME, MONACO_DEFAULT_OPTIONS, TRIGGER_SOURCE } from '../constants';
16
+ import { AriaContainer } from './AriaContainer';
17
+ import * as S from '../CodeArea.styles';
18
+ import { BottomBar } from './BottomBar';
19
+ export var CodeAreaEditorRaw = function CodeAreaEditorRaw(_ref) {
20
+ var onMount = _ref.onMount,
21
+ beforeMount = _ref.beforeMount,
22
+ options = _ref.options,
23
+ errorText = _ref.errorText,
24
+ texts = _ref.texts,
25
+ allowFullscreen = _ref.allowFullscreen,
26
+ toggleFullscreen = _ref.toggleFullscreen,
27
+ renderFooterContent = _ref.renderFooterContent,
28
+ isFullscreen = _ref.isFullscreen,
29
+ count = _ref.count,
30
+ counterLimit = _ref.counterLimit,
31
+ onChange = _ref.onChange,
32
+ isValid = _ref.isValid,
33
+ onDidChangeMarkers = _ref.onDidChangeMarkers,
34
+ isSyntaxSelectVisible = _ref.isSyntaxSelectVisible,
35
+ syntaxOptions = _ref.syntaxOptions,
36
+ currentSyntax = _ref.currentSyntax,
37
+ readOnly = _ref.readOnly,
38
+ onSyntaxChange = _ref.onSyntaxChange,
39
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
40
+ var monacoRef = useRef(null);
41
+ var editorRef = useRef(null);
42
+ var wrapperRef = useRef(null);
43
+ var _useResizeObserver = useResizeObserver(wrapperRef),
44
+ height = _useResizeObserver.height,
45
+ width = _useResizeObserver.width;
46
+ var monacoAriaContainerElement = useMemo(function () {
47
+ return document.createElement('div');
48
+ }, []);
49
+ var editorOptions = useMemo(function () {
50
+ return _objectSpread({}, MONACO_DEFAULT_OPTIONS, {}, options, {
51
+ readOnly: readOnly,
52
+ domReadOnly: readOnly,
53
+ ariaContainerElement: monacoAriaContainerElement
54
+ });
55
+ }, [options, readOnly, monacoAriaContainerElement]);
56
+ var allTexts = useMemo(function () {
57
+ return getDefaultTexts(texts);
58
+ }, [texts]);
59
+ var handleBeforeMount = useCallback(function (monacoInstance) {
60
+ monacoRef.current = monacoInstance;
61
+ monacoInstance.editor.defineTheme(DS_MONACO_THEME_NAME, DS_MONACO_THEME);
62
+ monacoInstance.editor.setTheme(DS_MONACO_THEME_NAME);
63
+ monacoInstance.editor.onDidChangeMarkers(function () {
64
+ var markers = monacoInstance.editor.getModelMarkers({});
65
+ onDidChangeMarkers && onDidChangeMarkers(markers);
66
+ });
67
+ beforeMount && beforeMount(monacoInstance);
68
+ }, [onDidChangeMarkers, beforeMount]);
69
+ var handleEditorDidMount = useCallback(function (monacoEditor, monacoInstance) {
70
+ editorRef.current = monacoEditor;
71
+ onMount && onMount(monacoEditor, monacoInstance);
72
+ }, [onMount]);
73
+ var handleChange = useCallback(function (newValue, event) {
74
+ if (counterLimit && newValue && newValue.length > counterLimit) {
75
+ editorRef.current && editorRef.current.trigger(TRIGGER_SOURCE, 'undo', null);
76
+ return;
77
+ }
78
+ if (editorRef.current) {
79
+ editorRef.current.pushUndoStop();
80
+ }
81
+ onChange && onChange(newValue, event);
82
+ }, [onChange, counterLimit]);
83
+ var _useMemo = useMemo(function () {
84
+ var source = syntaxOptions == null ? void 0 : syntaxOptions.map(function (item) {
85
+ var itemLabel = item.label,
86
+ language = item.language;
87
+ return {
88
+ key: language,
89
+ text: itemLabel || language
90
+ };
91
+ });
92
+ var currentItem = syntaxOptions == null ? void 0 : syntaxOptions.find(function (item) {
93
+ return item.language === currentSyntax;
94
+ });
95
+ return {
96
+ syntaxDataSource: source,
97
+ currentSyntaxItem: currentItem || {
98
+ language: currentSyntax
99
+ }
100
+ };
101
+ }, [currentSyntax, syntaxOptions]),
102
+ syntaxDataSource = _useMemo.syntaxDataSource,
103
+ currentSyntaxItem = _useMemo.currentSyntaxItem;
104
+ var syntaxSelect = useMemo(function () {
105
+ return syntaxDataSource && syntaxDataSource.length > 1 && !readOnly ? /*#__PURE__*/React.createElement(InlineSelect, {
106
+ size: "small",
107
+ expanded: false,
108
+ input: {
109
+ name: 'syntax-select',
110
+ value: currentSyntaxItem.label || currentSyntaxItem.language,
111
+ onChange: NOOP
112
+ },
113
+ onValueChange: function onValueChange(item) {
114
+ item.key && onSyntaxChange && onSyntaxChange("" + item.key);
115
+ },
116
+ initialValue: currentSyntaxItem.label || currentSyntaxItem.language,
117
+ dataSource: syntaxDataSource
118
+ }) : /*#__PURE__*/React.createElement(S.SyntaxTitle, {
119
+ size: "small"
120
+ }, currentSyntaxItem.label || currentSyntaxItem.language);
121
+ }, [currentSyntaxItem.label, currentSyntaxItem.language, onSyntaxChange, readOnly, syntaxDataSource]);
122
+ var customFooterContent = useMemo(function () {
123
+ return renderFooterContent && /*#__PURE__*/React.createElement(S.BottomBarElement, null, renderFooterContent({
124
+ isFullscreen: isFullscreen,
125
+ count: count,
126
+ isValid: isValid
127
+ }));
128
+ }, [renderFooterContent, isFullscreen, count, isValid]);
129
+ useEffect(function () {
130
+ if (editorRef.current) {
131
+ var _editorRef$current, _monacoRef$current;
132
+ var currentModel = (_editorRef$current = editorRef.current) == null ? void 0 : _editorRef$current.getModel();
133
+ // eslint-disable-next-line no-unused-expressions
134
+ currentModel && ((_monacoRef$current = monacoRef.current) == null ? void 0 : _monacoRef$current.editor.setModelLanguage(currentModel, currentSyntax));
135
+ }
136
+ }, [currentSyntax]);
137
+ var isBottomBarShowing = Boolean(isSyntaxSelectVisible || allowFullscreen && !isFullscreen);
138
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(S.EditorWrapper, {
139
+ hasError: Boolean(errorText)
140
+ }, /*#__PURE__*/React.createElement(S.EditorInnerWrapper, {
141
+ ref: wrapperRef
142
+ }, /*#__PURE__*/React.createElement(Editor, _extends({}, props, {
143
+ width: width,
144
+ height: height,
145
+ language: currentSyntax,
146
+ theme: DS_MONACO_THEME_NAME,
147
+ options: editorOptions,
148
+ onChange: handleChange,
149
+ beforeMount: handleBeforeMount,
150
+ onMount: handleEditorDidMount,
151
+ loading: /*#__PURE__*/React.createElement(Loader, null)
152
+ }))), isBottomBarShowing && /*#__PURE__*/React.createElement(BottomBar, {
153
+ texts: allTexts,
154
+ syntaxSelect: syntaxSelect,
155
+ allowFullscreen: allowFullscreen && !isFullscreen,
156
+ toggleFullscreen: toggleFullscreen,
157
+ customFooterContent: customFooterContent
158
+ })), /*#__PURE__*/React.createElement(AriaContainer, {
159
+ element: monacoAriaContainerElement
160
+ }));
161
+ };
162
+ export default CodeAreaEditorRaw;
@@ -2,4 +2,5 @@ export * from './ContentAbove';
2
2
  export * from './ContentBelow';
3
3
  export * from './FullscreenHeader';
4
4
  export * from './BottomBar';
5
+ export * from './CodeAreaEditorRaw';
5
6
  export * from './CodeAreaEditor';
@@ -2,4 +2,5 @@ export * from './ContentAbove';
2
2
  export * from './ContentBelow';
3
3
  export * from './FullscreenHeader';
4
4
  export * from './BottomBar';
5
+ export * from './CodeAreaEditorRaw';
5
6
  export * from './CodeAreaEditor';
@@ -1,5 +1,5 @@
1
- import type { monaco } from 'react-monaco-editor';
2
- export declare const MONACO_DEFAULT_OPTIONS: monaco.editor.IStandaloneEditorConstructionOptions;
1
+ import type { editor } from 'monaco-editor/esm/vs/editor/editor.api';
2
+ export declare const MONACO_DEFAULT_OPTIONS: editor.IStandaloneEditorConstructionOptions;
3
3
  export declare const TRIGGER_SOURCE = "ds-code-area";
4
4
  export declare const DS_MONACO_THEME_NAME = "DSTheme";
5
- export declare const DS_MONACO_THEME: monaco.editor.IStandaloneThemeData;
5
+ export declare const DS_MONACO_THEME: editor.IStandaloneThemeData;
package/dist/constants.js CHANGED
@@ -5,6 +5,10 @@ export var MONACO_DEFAULT_OPTIONS = {
5
5
  },
6
6
  automaticLayout: true,
7
7
  renderLineHighlight: 'none',
8
+ quickSuggestions: {
9
+ other: true,
10
+ strings: true
11
+ },
8
12
  scrollbar: {
9
13
  verticalScrollbarSize: 11,
10
14
  verticalSliderSize: 3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-code-area",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "CodeArea UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -34,16 +34,16 @@
34
34
  ],
35
35
  "types": "dist/index.d.ts",
36
36
  "dependencies": {
37
+ "@monaco-editor/react": "4.4.6",
37
38
  "@synerise/ds-button": "^0.22.0",
38
39
  "@synerise/ds-core": "^0.42.1",
39
40
  "@synerise/ds-icon": "^0.68.0",
40
- "@synerise/ds-inline-edit": "^0.9.4",
41
- "@synerise/ds-input": "^0.24.17",
41
+ "@synerise/ds-inline-edit": "^0.9.5",
42
+ "@synerise/ds-input": "^0.24.18",
42
43
  "@synerise/ds-tooltip": "^0.14.52",
43
44
  "@synerise/ds-typography": "^0.16.9",
44
45
  "@synerise/ds-utils": "^0.31.2",
45
- "monaco-editor": "0.47.0",
46
- "react-monaco-editor": "^0.55.0"
46
+ "monaco-editor": "0.34.1"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@synerise/ds-core": "*",
@@ -52,5 +52,5 @@
52
52
  "react-intl": ">=3.12.0 <= 6.8",
53
53
  "styled-components": "5.0.1"
54
54
  },
55
- "gitHead": "03c0625fb7b5baaa35f6633a425fb803469b6a20"
55
+ "gitHead": "f10ff573f65d5e70b13c695abded40a3289f792f"
56
56
  }