@pingux/astro 2.125.1-alpha.0 → 2.126.0-alpha.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.
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { CodeEditorProps } from '../../types';
3
- declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<HTMLElement>>;
3
+ declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<HTMLDivElement>>;
4
4
  export default CodeEditor;
@@ -10,34 +10,77 @@ _Object$defineProperty(exports, "__esModule", {
10
10
  });
11
11
  exports["default"] = void 0;
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
13
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
13
14
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
14
15
  var _react = _interopRequireWildcard(require("react"));
15
16
  var _react2 = _interopRequireDefault(require("@monaco-editor/react"));
17
+ var _hooks = require("../../hooks");
16
18
  var _index = require("../../index");
19
+ var _languageMapping = _interopRequireDefault(require("../../utils/devUtils/constants/languageMapping"));
17
20
  var _react3 = require("@emotion/react");
18
- var _excluded = ["value", "language", "onChange", "onValidate", "height"];
21
+ var _excluded = ["defaultValue", "language", "onChange", "onValidate", "height", "className", "isReadOnly", "iconButtonProps"];
19
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
24
  var CodeEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
22
- var value = props.value,
25
+ var defaultValue = props.defaultValue,
23
26
  language = props.language,
24
27
  onChange = props.onChange,
25
28
  onValidate = props.onValidate,
26
29
  height = props.height,
30
+ className = props.className,
31
+ isReadOnly = props.isReadOnly,
32
+ iconButtonProps = props.iconButtonProps,
27
33
  others = (0, _objectWithoutProperties2["default"])(props, _excluded);
34
+ var _useStatusClasses = (0, _hooks.useStatusClasses)(className, {
35
+ isReadOnly: isReadOnly
36
+ }),
37
+ classNames = _useStatusClasses.classNames;
28
38
  var editorRef = (0, _react.useRef)(null);
39
+ var _useState = (0, _react.useState)(''),
40
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
41
+ code = _useState2[0],
42
+ setCode = _useState2[1];
43
+ var handleChange = function handleChange(value) {
44
+ if (value) {
45
+ setCode(value);
46
+ if (onChange) {
47
+ onChange(value);
48
+ }
49
+ }
50
+ };
51
+ var languageName = function languageName(languageExtension) {
52
+ return _languageMapping["default"][languageExtension] || languageExtension;
53
+ };
29
54
  return (0, _react3.jsx)(_index.Box, (0, _extends2["default"])({}, others, {
30
55
  ref: ref
31
56
  }), (0, _react3.jsx)(_index.Box, {
32
- variant: "codeEditor.wrapper",
33
- ref: editorRef,
34
- height: height
57
+ ref: ref,
58
+ className: classNames,
59
+ variant: "codeEditor.wrapper"
60
+ }, (0, _react3.jsx)(_index.Box, {
61
+ isRow: true,
62
+ justifyContent: "space-between",
63
+ alignItems: "center",
64
+ variant: "codeEditor.header"
65
+ }, (0, _react3.jsx)(_index.Text, {
66
+ mb: "0",
67
+ mr: "sm",
68
+ py: "sm"
69
+ }, typeof language === 'string' ? languageName(language) : ''), (0, _react3.jsx)(_index.CopyText, {
70
+ ref: ref,
71
+ mode: "rightText",
72
+ textToCopy: code || defaultValue,
73
+ iconButtonProps: iconButtonProps
74
+ })), (0, _react3.jsx)(_index.Box, {
75
+ height: height,
76
+ className: classNames,
77
+ ref: editorRef
35
78
  }, (0, _react3.jsx)(_react2["default"], {
36
79
  height: "100%",
37
80
  language: language,
38
- value: value,
81
+ defaultValue: defaultValue,
39
82
  theme: "vs-light",
40
- onChange: onChange,
83
+ onChange: handleChange,
41
84
  onValidate: onValidate,
42
85
  options: {
43
86
  fontSize: 14,
@@ -47,9 +90,15 @@ var CodeEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
47
90
  },
48
91
  stickyScroll: {
49
92
  enabled: false
93
+ },
94
+ readOnly: isReadOnly,
95
+ scrollBeyondLastLine: false,
96
+ padding: {
97
+ top: 13,
98
+ bottom: 13
50
99
  }
51
100
  }
52
- })));
101
+ }))));
53
102
  });
54
103
  var _default = CodeEditor;
55
104
  exports["default"] = _default;
@@ -3,7 +3,7 @@ import { StoryFn } from '@storybook/react';
3
3
  import { CodeEditorProps } from '../../types';
4
4
  declare const _default: {
5
5
  title: string;
6
- component: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<HTMLElement>>;
6
+ component: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<HTMLDivElement>>;
7
7
  parameters: {
8
8
  docs: {
9
9
  page: () => React.JSX.Element;
@@ -25,3 +25,4 @@ export default _default;
25
25
  export declare const TypescriptEditor: StoryFn<CodeEditorProps>;
26
26
  export declare const JavascriptEditor: StoryFn<CodeEditorProps>;
27
27
  export declare const JsonEditor: StoryFn<CodeEditorProps>;
28
+ export declare const ReadOnly: StoryFn<CodeEditorProps>;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
5
5
  _Object$defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = exports.TypescriptEditor = exports.JsonEditor = exports.JavascriptEditor = void 0;
8
+ exports["default"] = exports.TypescriptEditor = exports.ReadOnly = exports.JsonEditor = exports.JavascriptEditor = void 0;
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _storybookDocsLayout = _interopRequireDefault(require("../../../.storybook/storybookDocsLayout"));
11
11
  var _index = require("../../index");
@@ -42,7 +42,7 @@ var tsCode = "const stringValue: string = 15;\n\nfunction addOne(integer: number
42
42
  var jsCode = "\nfunction factorial(n) {\n if (n === 0 || n === 1) {\n return 1;\n } else {\n return n * factorial(n - 1);\n }\n}\n\nconsole.log(factorial(5));\n\n(a) => {};\n";
43
43
  var TypescriptEditor = function TypescriptEditor() {
44
44
  return (0, _react2.jsx)(_index.CodeEditor, {
45
- value: tsCode,
45
+ defaultValue: tsCode,
46
46
  language: "typescript",
47
47
  height: "200px"
48
48
  });
@@ -50,7 +50,7 @@ var TypescriptEditor = function TypescriptEditor() {
50
50
  exports.TypescriptEditor = TypescriptEditor;
51
51
  var JavascriptEditor = function JavascriptEditor() {
52
52
  return (0, _react2.jsx)(_index.CodeEditor, {
53
- value: jsCode,
53
+ defaultValue: jsCode,
54
54
  language: "javascript",
55
55
  height: "200px"
56
56
  });
@@ -58,9 +58,18 @@ var JavascriptEditor = function JavascriptEditor() {
58
58
  exports.JavascriptEditor = JavascriptEditor;
59
59
  var JsonEditor = function JsonEditor() {
60
60
  return (0, _react2.jsx)(_index.CodeEditor, {
61
- value: jsonCode,
61
+ defaultValue: jsonCode,
62
62
  language: "json",
63
63
  height: "200px"
64
64
  });
65
65
  };
66
- exports.JsonEditor = JsonEditor;
66
+ exports.JsonEditor = JsonEditor;
67
+ var ReadOnly = function ReadOnly() {
68
+ return (0, _react2.jsx)(_index.CodeEditor, {
69
+ defaultValue: jsonCode,
70
+ language: "json",
71
+ height: "200px",
72
+ isReadOnly: true
73
+ });
74
+ };
75
+ exports.ReadOnly = ReadOnly;
@@ -5,6 +5,21 @@ declare const _default: {
5
5
  borderStyle: string;
6
6
  borderWidth: string;
7
7
  width: string;
8
+ '&.is-read-only': {
9
+ borderWidth: string;
10
+ '&:after': {
11
+ display: string;
12
+ };
13
+ };
14
+ };
15
+ header: {
16
+ color: string;
17
+ px: string;
18
+ width: string;
19
+ borderBottom: string;
20
+ borderColor: string;
21
+ lineHeight: string;
22
+ fontWeight: string;
8
23
  };
9
24
  };
10
25
  export default _default;
@@ -19,12 +19,28 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
19
19
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
20
20
  var wrapper = _objectSpread(_objectSpread({}, _Input.input.fieldControlWrapper), {}, {
21
21
  borderColor: 'neutral.80',
22
- borderRadius: '3px 4px 4px 3px',
22
+ borderRadius: '4px 0 0 4px',
23
23
  borderStyle: 'solid',
24
24
  borderWidth: '1px 1px 1px 0px',
25
- width: '100%'
25
+ width: '100%',
26
+ '&.is-read-only': {
27
+ borderWidth: '1px',
28
+ '&:after': {
29
+ display: 'none'
30
+ }
31
+ }
26
32
  });
33
+ var header = {
34
+ color: 'gray-300',
35
+ px: 'md',
36
+ width: '100%',
37
+ borderBottom: '1px solid',
38
+ borderColor: 'neutral.80',
39
+ lineHeight: 'body',
40
+ fontWeight: '600'
41
+ };
27
42
  var _default = {
28
- wrapper: wrapper
43
+ wrapper: wrapper,
44
+ header: header
29
45
  };
30
46
  exports["default"] = _default;
@@ -24,7 +24,7 @@ var jsCode = "\n function helloWorld() {\n console.log(\"Hello, World!\");\n
24
24
  },
25
25
  renderComponent: function renderComponent(props) {
26
26
  return (0, _react2.jsx)(_index.CodeEditor, (0, _extends2["default"])({}, defaultProps, props, {
27
- value: jsCode,
27
+ defaultValue: jsCode,
28
28
  language: "javascript"
29
29
  }));
30
30
  }
@@ -35,14 +35,14 @@ jest.mock('@monaco-editor/react', function () {
35
35
  "default": function _default(_ref) {
36
36
  var _context;
37
37
  var language = _ref.language,
38
- value = _ref.value,
38
+ defaultValue = _ref.defaultValue,
39
39
  _onChange = _ref.onChange;
40
40
  return (0, _react2.jsx)("textarea", {
41
41
  "data-testid": "mock-monaco-editor",
42
42
  onChange: function onChange(e) {
43
43
  return _onChange(e.target.value);
44
44
  },
45
- value: (0, _concat["default"])(_context = "Editor Language: ".concat(language, ", Code:")).call(_context, value),
45
+ value: (0, _concat["default"])(_context = "Editor Language: ".concat(language, ", Code:")).call(_context, defaultValue),
46
46
  "aria-label": "Code editor"
47
47
  });
48
48
  }
@@ -53,7 +53,7 @@ describe('CodeEditor', function () {
53
53
  var value = 'console.log("Hello, World!");';
54
54
  (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
55
55
  language: "javascript",
56
- value: value
56
+ defaultValue: value
57
57
  }));
58
58
  expect(_testWrapper.screen.getByTestId('mock-monaco-editor')).toBeInTheDocument();
59
59
  expect(_testWrapper.screen.getByText('Editor Language: javascript, Code:console.log("Hello, World!");')).toBeInTheDocument();
@@ -63,7 +63,7 @@ describe('CodeEditor', function () {
63
63
  var mockOnChange = jest.fn();
64
64
  (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
65
65
  language: "javascript",
66
- value: value,
66
+ defaultValue: value,
67
67
  onChange: mockOnChange
68
68
  }));
69
69
  var editor = _testWrapper.screen.getByTestId('mock-monaco-editor');
@@ -79,4 +79,28 @@ describe('CodeEditor', function () {
79
79
  });
80
80
  expect(mockOnChange).toHaveBeenCalled();
81
81
  });
82
+ it('displays the correct language name in the header for mapped languages', function () {
83
+ (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
84
+ language: "typescript",
85
+ defaultValue: jsCode
86
+ }));
87
+ expect(_testWrapper.screen.getByText('TypeScript')).toBeInTheDocument();
88
+ (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
89
+ language: "scss",
90
+ defaultValue: jsCode
91
+ }));
92
+ expect(_testWrapper.screen.getByText('SCSS')).toBeInTheDocument();
93
+ (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
94
+ language: "python",
95
+ defaultValue: jsCode
96
+ }));
97
+ expect(_testWrapper.screen.getByText('Python')).toBeInTheDocument();
98
+ });
99
+ it('displays the language extension as-is if not mapped', function () {
100
+ (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, {
101
+ language: "unknownlang",
102
+ defaultValue: jsCode
103
+ }));
104
+ expect(_testWrapper.screen.getByText('unknownlang')).toBeInTheDocument();
105
+ });
82
106
  });
@@ -1,12 +1,15 @@
1
1
  import { type editor } from 'monaco-editor';
2
2
  import * as monaco from 'monaco-editor';
3
+ import { IconButtonProps } from './iconButton';
3
4
  import { DOMAttributes, StyleProps } from './shared';
4
5
  import { FocusableElement } from '.';
5
6
  export interface CodeEditorProps extends Omit<DOMAttributes<FocusableElement>, 'onChange'>, StyleProps {
6
- value?: string;
7
+ defaultValue?: string;
7
8
  language?: string;
8
9
  onChange?: (value: string | undefined) => void;
9
10
  onValidate?: (markers: editor.IMarker[]) => void;
11
+ isReadOnly?: boolean;
12
+ iconButtonProps?: Omit<IconButtonProps, 'onPress'>;
10
13
  }
11
14
  export interface CustomEditorOptions extends monaco.editor.IStandaloneEditorConstructionOptions {
12
15
  stickyScroll?: {
@@ -0,0 +1,31 @@
1
+ declare const _default: {
2
+ typescript: string;
3
+ javascript: string;
4
+ css: string;
5
+ less: string;
6
+ scss: string;
7
+ json: string;
8
+ html: string;
9
+ xml: string;
10
+ php: string;
11
+ csharp: string;
12
+ cpp: string;
13
+ razor: string;
14
+ markdown: string;
15
+ diff: string;
16
+ java: string;
17
+ vb: string;
18
+ coffeescript: string;
19
+ handlebars: string;
20
+ bat: string;
21
+ pug: string;
22
+ fsharp: string;
23
+ lua: string;
24
+ powershell: string;
25
+ python: string;
26
+ ruby: string;
27
+ sass: string;
28
+ r: string;
29
+ 'objective-c': string;
30
+ };
31
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _default = {
9
+ 'typescript': 'TypeScript',
10
+ 'javascript': 'JavaScript',
11
+ 'css': 'CSS',
12
+ 'less': 'LESS',
13
+ 'scss': 'SCSS',
14
+ 'json': 'JSON',
15
+ 'html': 'HTML',
16
+ 'xml': 'XML',
17
+ 'php': 'PHP',
18
+ 'csharp': 'C#',
19
+ 'cpp': 'C++',
20
+ 'razor': 'Razor',
21
+ 'markdown': 'Markdown',
22
+ 'diff': 'Diff',
23
+ 'java': 'Java',
24
+ 'vb': 'VB',
25
+ 'coffeescript': 'CoffeeScript',
26
+ 'handlebars': 'Handlebars',
27
+ 'bat': 'Batch',
28
+ 'pug': 'Pug',
29
+ 'fsharp': 'F#',
30
+ 'lua': 'Lua',
31
+ 'powershell': 'PowerShell',
32
+ 'python': 'Python',
33
+ 'ruby': 'Ruby',
34
+ 'sass': 'SASS',
35
+ 'r': 'R',
36
+ 'objective-c': 'Objective-C'
37
+ };
38
+ exports["default"] = _default;
@@ -1,30 +1,73 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
3
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["value", "language", "onChange", "onValidate", "height"];
4
- import React, { forwardRef, useRef } from 'react';
4
+ var _excluded = ["defaultValue", "language", "onChange", "onValidate", "height", "className", "isReadOnly", "iconButtonProps"];
5
+ import React, { forwardRef, useRef, useState } from 'react';
5
6
  import Editor from '@monaco-editor/react';
6
- import { Box } from '../../index';
7
+ import { useStatusClasses } from '../../hooks';
8
+ import { Box, CopyText, Text } from '../../index';
9
+ import languageMapping from '../../utils/devUtils/constants/languageMapping';
7
10
  import { jsx as ___EmotionJSX } from "@emotion/react";
8
11
  var CodeEditor = /*#__PURE__*/forwardRef(function (props, ref) {
9
- var value = props.value,
12
+ var defaultValue = props.defaultValue,
10
13
  language = props.language,
11
14
  onChange = props.onChange,
12
15
  onValidate = props.onValidate,
13
16
  height = props.height,
17
+ className = props.className,
18
+ isReadOnly = props.isReadOnly,
19
+ iconButtonProps = props.iconButtonProps,
14
20
  others = _objectWithoutProperties(props, _excluded);
21
+ var _useStatusClasses = useStatusClasses(className, {
22
+ isReadOnly: isReadOnly
23
+ }),
24
+ classNames = _useStatusClasses.classNames;
15
25
  var editorRef = useRef(null);
26
+ var _useState = useState(''),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ code = _useState2[0],
29
+ setCode = _useState2[1];
30
+ var handleChange = function handleChange(value) {
31
+ if (value) {
32
+ setCode(value);
33
+ if (onChange) {
34
+ onChange(value);
35
+ }
36
+ }
37
+ };
38
+ var languageName = function languageName(languageExtension) {
39
+ return languageMapping[languageExtension] || languageExtension;
40
+ };
16
41
  return ___EmotionJSX(Box, _extends({}, others, {
17
42
  ref: ref
18
43
  }), ___EmotionJSX(Box, {
19
- variant: "codeEditor.wrapper",
20
- ref: editorRef,
21
- height: height
44
+ ref: ref,
45
+ className: classNames,
46
+ variant: "codeEditor.wrapper"
47
+ }, ___EmotionJSX(Box, {
48
+ isRow: true,
49
+ justifyContent: "space-between",
50
+ alignItems: "center",
51
+ variant: "codeEditor.header"
52
+ }, ___EmotionJSX(Text, {
53
+ mb: "0",
54
+ mr: "sm",
55
+ py: "sm"
56
+ }, typeof language === 'string' ? languageName(language) : ''), ___EmotionJSX(CopyText, {
57
+ ref: ref,
58
+ mode: "rightText",
59
+ textToCopy: code || defaultValue,
60
+ iconButtonProps: iconButtonProps
61
+ })), ___EmotionJSX(Box, {
62
+ height: height,
63
+ className: classNames,
64
+ ref: editorRef
22
65
  }, ___EmotionJSX(Editor, {
23
66
  height: "100%",
24
67
  language: language,
25
- value: value,
68
+ defaultValue: defaultValue,
26
69
  theme: "vs-light",
27
- onChange: onChange,
70
+ onChange: handleChange,
28
71
  onValidate: onValidate,
29
72
  options: {
30
73
  fontSize: 14,
@@ -34,8 +77,14 @@ var CodeEditor = /*#__PURE__*/forwardRef(function (props, ref) {
34
77
  },
35
78
  stickyScroll: {
36
79
  enabled: false
80
+ },
81
+ readOnly: isReadOnly,
82
+ scrollBeyondLastLine: false,
83
+ padding: {
84
+ top: 13,
85
+ bottom: 13
37
86
  }
38
87
  }
39
- })));
88
+ }))));
40
89
  });
41
90
  export default CodeEditor;
@@ -33,22 +33,30 @@ var tsCode = "const stringValue: string = 15;\n\nfunction addOne(integer: number
33
33
  var jsCode = "\nfunction factorial(n) {\n if (n === 0 || n === 1) {\n return 1;\n } else {\n return n * factorial(n - 1);\n }\n}\n\nconsole.log(factorial(5));\n\n(a) => {};\n";
34
34
  export var TypescriptEditor = function TypescriptEditor() {
35
35
  return ___EmotionJSX(CodeEditor, {
36
- value: tsCode,
36
+ defaultValue: tsCode,
37
37
  language: "typescript",
38
38
  height: "200px"
39
39
  });
40
40
  };
41
41
  export var JavascriptEditor = function JavascriptEditor() {
42
42
  return ___EmotionJSX(CodeEditor, {
43
- value: jsCode,
43
+ defaultValue: jsCode,
44
44
  language: "javascript",
45
45
  height: "200px"
46
46
  });
47
47
  };
48
48
  export var JsonEditor = function JsonEditor() {
49
49
  return ___EmotionJSX(CodeEditor, {
50
- value: jsonCode,
50
+ defaultValue: jsonCode,
51
51
  language: "json",
52
52
  height: "200px"
53
53
  });
54
+ };
55
+ export var ReadOnly = function ReadOnly() {
56
+ return ___EmotionJSX(CodeEditor, {
57
+ defaultValue: jsonCode,
58
+ language: "json",
59
+ height: "200px",
60
+ isReadOnly: true
61
+ });
54
62
  };
@@ -12,11 +12,27 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
  import { input } from '../Input/Input.styles';
13
13
  var wrapper = _objectSpread(_objectSpread({}, input.fieldControlWrapper), {}, {
14
14
  borderColor: 'neutral.80',
15
- borderRadius: '3px 4px 4px 3px',
15
+ borderRadius: '4px 0 0 4px',
16
16
  borderStyle: 'solid',
17
17
  borderWidth: '1px 1px 1px 0px',
18
- width: '100%'
18
+ width: '100%',
19
+ '&.is-read-only': {
20
+ borderWidth: '1px',
21
+ '&:after': {
22
+ display: 'none'
23
+ }
24
+ }
19
25
  });
26
+ var header = {
27
+ color: 'gray-300',
28
+ px: 'md',
29
+ width: '100%',
30
+ borderBottom: '1px solid',
31
+ borderColor: 'neutral.80',
32
+ lineHeight: 'body',
33
+ fontWeight: '600'
34
+ };
20
35
  export default {
21
- wrapper: wrapper
36
+ wrapper: wrapper,
37
+ header: header
22
38
  };
@@ -21,7 +21,7 @@ universalComponentTests({
21
21
  },
22
22
  renderComponent: function renderComponent(props) {
23
23
  return ___EmotionJSX(CodeEditor, _extends({}, defaultProps, props, {
24
- value: jsCode,
24
+ defaultValue: jsCode,
25
25
  language: "javascript"
26
26
  }));
27
27
  }
@@ -32,14 +32,14 @@ jest.mock('@monaco-editor/react', function () {
32
32
  "default": function _default(_ref) {
33
33
  var _context;
34
34
  var language = _ref.language,
35
- value = _ref.value,
35
+ defaultValue = _ref.defaultValue,
36
36
  _onChange = _ref.onChange;
37
37
  return ___EmotionJSX("textarea", {
38
38
  "data-testid": "mock-monaco-editor",
39
39
  onChange: function onChange(e) {
40
40
  return _onChange(e.target.value);
41
41
  },
42
- value: _concatInstanceProperty(_context = "Editor Language: ".concat(language, ", Code:")).call(_context, value),
42
+ value: _concatInstanceProperty(_context = "Editor Language: ".concat(language, ", Code:")).call(_context, defaultValue),
43
43
  "aria-label": "Code editor"
44
44
  });
45
45
  }
@@ -50,7 +50,7 @@ describe('CodeEditor', function () {
50
50
  var value = 'console.log("Hello, World!");';
51
51
  render(___EmotionJSX(CodeEditor, {
52
52
  language: "javascript",
53
- value: value
53
+ defaultValue: value
54
54
  }));
55
55
  expect(screen.getByTestId('mock-monaco-editor')).toBeInTheDocument();
56
56
  expect(screen.getByText('Editor Language: javascript, Code:console.log("Hello, World!");')).toBeInTheDocument();
@@ -60,7 +60,7 @@ describe('CodeEditor', function () {
60
60
  var mockOnChange = jest.fn();
61
61
  render(___EmotionJSX(CodeEditor, {
62
62
  language: "javascript",
63
- value: value,
63
+ defaultValue: value,
64
64
  onChange: mockOnChange
65
65
  }));
66
66
  var editor = screen.getByTestId('mock-monaco-editor');
@@ -76,4 +76,28 @@ describe('CodeEditor', function () {
76
76
  });
77
77
  expect(mockOnChange).toHaveBeenCalled();
78
78
  });
79
+ it('displays the correct language name in the header for mapped languages', function () {
80
+ render(___EmotionJSX(CodeEditor, {
81
+ language: "typescript",
82
+ defaultValue: jsCode
83
+ }));
84
+ expect(screen.getByText('TypeScript')).toBeInTheDocument();
85
+ render(___EmotionJSX(CodeEditor, {
86
+ language: "scss",
87
+ defaultValue: jsCode
88
+ }));
89
+ expect(screen.getByText('SCSS')).toBeInTheDocument();
90
+ render(___EmotionJSX(CodeEditor, {
91
+ language: "python",
92
+ defaultValue: jsCode
93
+ }));
94
+ expect(screen.getByText('Python')).toBeInTheDocument();
95
+ });
96
+ it('displays the language extension as-is if not mapped', function () {
97
+ render(___EmotionJSX(CodeEditor, {
98
+ language: "unknownlang",
99
+ defaultValue: jsCode
100
+ }));
101
+ expect(screen.getByText('unknownlang')).toBeInTheDocument();
102
+ });
79
103
  });
@@ -0,0 +1,30 @@
1
+ export default {
2
+ 'typescript': 'TypeScript',
3
+ 'javascript': 'JavaScript',
4
+ 'css': 'CSS',
5
+ 'less': 'LESS',
6
+ 'scss': 'SCSS',
7
+ 'json': 'JSON',
8
+ 'html': 'HTML',
9
+ 'xml': 'XML',
10
+ 'php': 'PHP',
11
+ 'csharp': 'C#',
12
+ 'cpp': 'C++',
13
+ 'razor': 'Razor',
14
+ 'markdown': 'Markdown',
15
+ 'diff': 'Diff',
16
+ 'java': 'Java',
17
+ 'vb': 'VB',
18
+ 'coffeescript': 'CoffeeScript',
19
+ 'handlebars': 'Handlebars',
20
+ 'bat': 'Batch',
21
+ 'pug': 'Pug',
22
+ 'fsharp': 'F#',
23
+ 'lua': 'Lua',
24
+ 'powershell': 'PowerShell',
25
+ 'python': 'Python',
26
+ 'ruby': 'Ruby',
27
+ 'sass': 'SASS',
28
+ 'r': 'R',
29
+ 'objective-c': 'Objective-C'
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.125.1-alpha.0",
3
+ "version": "2.126.0-alpha.0",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",