@pingux/astro 2.144.0-alpha.1 → 2.144.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
31
31
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
32
32
  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; }
33
33
  var CodeEditor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
34
- var defaultValue = props.defaultValue,
34
+ var _props$defaultValue = props.defaultValue,
35
+ defaultValue = _props$defaultValue === void 0 ? '\n' : _props$defaultValue,
35
36
  language = props.language,
36
37
  onChange = props.onChange,
37
38
  onValidate = props.onValidate,
@@ -22,6 +22,7 @@ declare const _default: {
22
22
  };
23
23
  };
24
24
  export default _default;
25
+ export declare const Default: StoryFn<CodeEditorProps>;
25
26
  export declare const TypescriptEditor: StoryFn<CodeEditorProps>;
26
27
  export declare const JavascriptEditor: StoryFn<CodeEditorProps>;
27
28
  export declare const JsonEditor: 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.ReadOnly = exports.JsonEditor = exports.JavascriptEditor = void 0;
8
+ exports["default"] = exports.TypescriptEditor = exports.ReadOnly = exports.JsonEditor = exports.JavascriptEditor = exports.Default = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
  var _storybookDocsLayout = _interopRequireDefault(require("../../../.storybook/storybookDocsLayout"));
@@ -41,6 +41,13 @@ exports["default"] = _default;
41
41
  var jsonCode = "{\n \"name\": \"Luke Skywalker\", \n \"height\": \"172\", \n \"mass\": \"77\", \n \"hair_color\": \"blond\", \n \"skin_color\": \"fair\", \n \"eye_color\": \"blue\", \n \"birth_year\": \"19BBY\", \n \"gender\": \"male\", \n \"homeworld\": \"https://swapi.dev/api/planets/1/\", \n \"films\": [\n \"https://swapi.dev/api/films/1/\", \n \"https://swapi.dev/api/films/2/\", \n \"https://swapi.dev/api/films/3/\", \n \"https://swapi.dev/api/films/6/\"\n ],\n \"starships\": [\n \"https://swapi.dev/api/starships/12/\", \n \"https://swapi.dev/api/starships/22/\"\n ]\n}";
42
42
  var tsCode = "const stringValue: string = 15;\n\nfunction addOne(integer: number) {\n return integer + 1;\n}\n\naddOne('I am a string');\n";
43
43
  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";
44
+ var Default = function Default(args) {
45
+ return (0, _react2.jsx)(_index.CodeEditor, (0, _extends2["default"])({}, args, {
46
+ height: "200px",
47
+ language: "Default"
48
+ }));
49
+ };
50
+ exports.Default = Default;
44
51
  var TypescriptEditor = function TypescriptEditor(args) {
45
52
  return (0, _react2.jsx)(_index.CodeEditor, (0, _extends2["default"])({}, args, {
46
53
  defaultValue: tsCode,
@@ -58,6 +58,11 @@ describe('CodeEditor', function () {
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();
60
60
  });
61
+ it('renders with null/undefined', function () {
62
+ (0, _testWrapper.render)((0, _react2.jsx)(_index.CodeEditor, null));
63
+ expect(_testWrapper.screen.getByTestId('mock-monaco-editor')).toBeInTheDocument();
64
+ expect(_testWrapper.screen.getByText('Editor Language: undefined, Code:')).toBeInTheDocument();
65
+ });
61
66
  it('calls onChange when code changes', function () {
62
67
  var value = 'console.log("Hello, World!");';
63
68
  var mockOnChange = jest.fn();
@@ -82,7 +82,7 @@ var CodeView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
82
82
  console.warn("Prism language module for \"".concat(String(language), "\" not found."));
83
83
  }
84
84
  }, [language]);
85
- var content = (0, _react2.jsx)(_prismReactRenderer["default"], (0, _extends2["default"])({}, _prismReactRenderer.defaultProps, {
85
+ var content = code ? (0, _react2.jsx)(_prismReactRenderer["default"], (0, _extends2["default"])({}, _prismReactRenderer.defaultProps, {
86
86
  theme: codeViewTheme,
87
87
  code: code,
88
88
  language: language,
@@ -117,7 +117,7 @@ var CodeView = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
117
117
  }));
118
118
  }));
119
119
  }));
120
- });
120
+ }) : '';
121
121
 
122
122
  /* istanbul ignore next */
123
123
  if (isOnyx) {
@@ -39,7 +39,7 @@ var defaultProps = {
39
39
  var textValue = "\nexport const Default = args => (\n <>\n <Text sx={{ fontWeight: 2 }}>JSON</Text>\n <CodeView {...args} />\n </>\n);\n";
40
40
  var getComponent = function getComponent() {
41
41
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
42
- return (0, _testWrapper.render)((0, _react2.jsx)(_.CodeView, (0, _extends2["default"])({}, defaultProps, props), textValue));
42
+ return (0, _testWrapper.render)((0, _react2.jsx)(_.CodeView, (0, _extends2["default"])({}, defaultProps, props), 'children' in props ? props.children : textValue));
43
43
  };
44
44
  beforeEach(function () {
45
45
  var mockClipboard = {
@@ -183,7 +183,7 @@ test('after button click, the tooltip renders with the text "Copied!"', /*#__PUR
183
183
  }, _callee4);
184
184
  })));
185
185
  test('renders CodeView component with default language', function () {
186
- var children = ' ';
186
+ var children = '{}';
187
187
  getComponent({
188
188
  children: children
189
189
  });
@@ -191,6 +191,17 @@ test('renders CodeView component with default language', function () {
191
191
  expect(codeViewElement).toBeInTheDocument();
192
192
  expect(codeViewElement).toHaveClass('language-json');
193
193
  });
194
+ test('renders CodeView component with null/undefined', function () {
195
+ var children = undefined;
196
+ getComponent({
197
+ children: children
198
+ });
199
+ _testWrapper.screen.getByRole('button', {
200
+ name: /copy to clipboard/i
201
+ });
202
+ var codeViewElement = _testWrapper.screen.getByTestId(testId).querySelector('pre');
203
+ expect(codeViewElement).not.toBeInTheDocument();
204
+ });
194
205
  test('renders CodeView component with highlighted code', function () {
195
206
  var children = "\n export const Default = args => (\n <>\n <Text sx={{ fontWeight: 2 }}>JSON</Text>\n <CodeView {...args} />\n </>\n );\n ";
196
207
  var language = 'jsx';
@@ -203,14 +214,15 @@ test('renders CodeView component with highlighted code', function () {
203
214
  expect(codeViewElement).toHaveClass("language-".concat(language));
204
215
  });
205
216
  test('isOnyx prop renders CodeView component with next-gen theme', function () {
206
- var children = ' ';
217
+ var children = '{}';
207
218
  getComponent({
208
219
  children: children,
209
220
  isOnyx: true,
210
221
  language: 'json'
211
222
  });
212
- var codeViewElement = _testWrapper.screen.getByTestId(testId);
213
- expect(codeViewElement).toHaveTextContent('JSON');
223
+ var codeViewElement = _testWrapper.screen.getByTestId(testId).querySelector('pre');
224
+ expect(codeViewElement).toBeInTheDocument();
225
+ expect(codeViewElement).toHaveClass('language-json');
214
226
  });
215
227
  test('if textToCopy is provided it\'s copied to clipboard instead of children text data', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
216
228
  var textToCopy, button;
@@ -34,6 +34,7 @@ var TooltipWrapper = function TooltipWrapper(_ref) {
34
34
  }, others), children, (0, _react2.jsx)(_index.Tooltip, null, tooltip));
35
35
  };
36
36
  var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
37
+ var _props, _props2;
37
38
  var children = props.children,
38
39
  textToCopy = props.textToCopy,
39
40
  tooltipText = props.tooltipText,
@@ -42,7 +43,7 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
42
43
  wrapperProps = props.wrapperProps,
43
44
  iconButtonProps = props.iconButtonProps,
44
45
  others = (0, _objectWithoutProperties2["default"])(props, _excluded2);
45
- var value = textToCopy || (mode === 'link' ? children.props.href : children.props.children);
46
+ var value = textToCopy || (mode === 'link' ? children === null || children === void 0 || (_props = children.props) === null || _props === void 0 ? void 0 : _props.href : (_props2 = children.props) === null || _props2 === void 0 ? void 0 : _props2.children);
46
47
  var _useState = (0, _react.useState)(false),
47
48
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
48
49
  isCopied = _useState2[0],
@@ -125,7 +126,8 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
125
126
  return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
126
127
  ref: ref,
127
128
  isRow: true,
128
- variant: "copyText.copy"
129
+ variant: "copyText.copy",
130
+ justifyContent: content ? 'start' : 'end'
129
131
  }, wrapperProps, others), content, (0, _react2.jsx)(TooltipWrapper, (0, _extends2["default"])({
130
132
  isOpen: isTooltipOpen,
131
133
  tooltip: tooltip
@@ -20,7 +20,8 @@ import { Box, CopyText, Text } from '../../index';
20
20
  import languageMapping from '../../utils/devUtils/constants/languageMapping';
21
21
  import { jsx as ___EmotionJSX } from "@emotion/react";
22
22
  var CodeEditor = /*#__PURE__*/forwardRef(function (props, ref) {
23
- var defaultValue = props.defaultValue,
23
+ var _props$defaultValue = props.defaultValue,
24
+ defaultValue = _props$defaultValue === void 0 ? '\n' : _props$defaultValue,
24
25
  language = props.language,
25
26
  onChange = props.onChange,
26
27
  onValidate = props.onValidate,
@@ -32,6 +32,12 @@ export default {
32
32
  var jsonCode = "{\n \"name\": \"Luke Skywalker\", \n \"height\": \"172\", \n \"mass\": \"77\", \n \"hair_color\": \"blond\", \n \"skin_color\": \"fair\", \n \"eye_color\": \"blue\", \n \"birth_year\": \"19BBY\", \n \"gender\": \"male\", \n \"homeworld\": \"https://swapi.dev/api/planets/1/\", \n \"films\": [\n \"https://swapi.dev/api/films/1/\", \n \"https://swapi.dev/api/films/2/\", \n \"https://swapi.dev/api/films/3/\", \n \"https://swapi.dev/api/films/6/\"\n ],\n \"starships\": [\n \"https://swapi.dev/api/starships/12/\", \n \"https://swapi.dev/api/starships/22/\"\n ]\n}";
33
33
  var tsCode = "const stringValue: string = 15;\n\nfunction addOne(integer: number) {\n return integer + 1;\n}\n\naddOne('I am a string');\n";
34
34
  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";
35
+ export var Default = function Default(args) {
36
+ return ___EmotionJSX(CodeEditor, _extends({}, args, {
37
+ height: "200px",
38
+ language: "Default"
39
+ }));
40
+ };
35
41
  export var TypescriptEditor = function TypescriptEditor(args) {
36
42
  return ___EmotionJSX(CodeEditor, _extends({}, args, {
37
43
  defaultValue: tsCode,
@@ -55,6 +55,11 @@ describe('CodeEditor', function () {
55
55
  expect(screen.getByTestId('mock-monaco-editor')).toBeInTheDocument();
56
56
  expect(screen.getByText('Editor Language: javascript, Code:console.log("Hello, World!");')).toBeInTheDocument();
57
57
  });
58
+ it('renders with null/undefined', function () {
59
+ render(___EmotionJSX(CodeEditor, null));
60
+ expect(screen.getByTestId('mock-monaco-editor')).toBeInTheDocument();
61
+ expect(screen.getByText('Editor Language: undefined, Code:')).toBeInTheDocument();
62
+ });
58
63
  it('calls onChange when code changes', function () {
59
64
  var value = 'console.log("Hello, World!");';
60
65
  var mockOnChange = jest.fn();
@@ -72,7 +72,7 @@ var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
72
72
  console.warn("Prism language module for \"".concat(String(language), "\" not found."));
73
73
  }
74
74
  }, [language]);
75
- var content = ___EmotionJSX(Highlight, _extends({}, defaultProps, {
75
+ var content = code ? ___EmotionJSX(Highlight, _extends({}, defaultProps, {
76
76
  theme: codeViewTheme,
77
77
  code: code,
78
78
  language: language,
@@ -107,7 +107,7 @@ var CodeView = /*#__PURE__*/forwardRef(function (props, ref) {
107
107
  }));
108
108
  }));
109
109
  }));
110
- });
110
+ }) : '';
111
111
 
112
112
  /* istanbul ignore next */
113
113
  if (isOnyx) {
@@ -35,7 +35,7 @@ var defaultProps = {
35
35
  var textValue = "\nexport const Default = args => (\n <>\n <Text sx={{ fontWeight: 2 }}>JSON</Text>\n <CodeView {...args} />\n </>\n);\n";
36
36
  var getComponent = function getComponent() {
37
37
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38
- return render(___EmotionJSX(CodeView, _extends({}, defaultProps, props), textValue));
38
+ return render(___EmotionJSX(CodeView, _extends({}, defaultProps, props), 'children' in props ? props.children : textValue));
39
39
  };
40
40
  beforeEach(function () {
41
41
  var mockClipboard = {
@@ -179,7 +179,7 @@ test('after button click, the tooltip renders with the text "Copied!"', /*#__PUR
179
179
  }, _callee4);
180
180
  })));
181
181
  test('renders CodeView component with default language', function () {
182
- var children = ' ';
182
+ var children = '{}';
183
183
  getComponent({
184
184
  children: children
185
185
  });
@@ -187,6 +187,17 @@ test('renders CodeView component with default language', function () {
187
187
  expect(codeViewElement).toBeInTheDocument();
188
188
  expect(codeViewElement).toHaveClass('language-json');
189
189
  });
190
+ test('renders CodeView component with null/undefined', function () {
191
+ var children = undefined;
192
+ getComponent({
193
+ children: children
194
+ });
195
+ screen.getByRole('button', {
196
+ name: /copy to clipboard/i
197
+ });
198
+ var codeViewElement = screen.getByTestId(testId).querySelector('pre');
199
+ expect(codeViewElement).not.toBeInTheDocument();
200
+ });
190
201
  test('renders CodeView component with highlighted code', function () {
191
202
  var children = "\n export const Default = args => (\n <>\n <Text sx={{ fontWeight: 2 }}>JSON</Text>\n <CodeView {...args} />\n </>\n );\n ";
192
203
  var language = 'jsx';
@@ -199,14 +210,15 @@ test('renders CodeView component with highlighted code', function () {
199
210
  expect(codeViewElement).toHaveClass("language-".concat(language));
200
211
  });
201
212
  test('isOnyx prop renders CodeView component with next-gen theme', function () {
202
- var children = ' ';
213
+ var children = '{}';
203
214
  getComponent({
204
215
  children: children,
205
216
  isOnyx: true,
206
217
  language: 'json'
207
218
  });
208
- var codeViewElement = screen.getByTestId(testId);
209
- expect(codeViewElement).toHaveTextContent('JSON');
219
+ var codeViewElement = screen.getByTestId(testId).querySelector('pre');
220
+ expect(codeViewElement).toBeInTheDocument();
221
+ expect(codeViewElement).toHaveClass('language-json');
210
222
  });
211
223
  test('if textToCopy is provided it\'s copied to clipboard instead of children text data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
212
224
  var textToCopy, button;
@@ -21,6 +21,7 @@ var TooltipWrapper = function TooltipWrapper(_ref) {
21
21
  }, others), children, ___EmotionJSX(Tooltip, null, tooltip));
22
22
  };
23
23
  var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
24
+ var _props, _props2;
24
25
  var children = props.children,
25
26
  textToCopy = props.textToCopy,
26
27
  tooltipText = props.tooltipText,
@@ -29,7 +30,7 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
29
30
  wrapperProps = props.wrapperProps,
30
31
  iconButtonProps = props.iconButtonProps,
31
32
  others = _objectWithoutProperties(props, _excluded2);
32
- var value = textToCopy || (mode === 'link' ? children.props.href : children.props.children);
33
+ var value = textToCopy || (mode === 'link' ? children === null || children === void 0 || (_props = children.props) === null || _props === void 0 ? void 0 : _props.href : (_props2 = children.props) === null || _props2 === void 0 ? void 0 : _props2.children);
33
34
  var _useState = useState(false),
34
35
  _useState2 = _slicedToArray(_useState, 2),
35
36
  isCopied = _useState2[0],
@@ -112,7 +113,8 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
112
113
  return ___EmotionJSX(Box, _extends({
113
114
  ref: ref,
114
115
  isRow: true,
115
- variant: "copyText.copy"
116
+ variant: "copyText.copy",
117
+ justifyContent: content ? 'start' : 'end'
116
118
  }, wrapperProps, others), content, ___EmotionJSX(TooltipWrapper, _extends({
117
119
  isOpen: isTooltipOpen,
118
120
  tooltip: tooltip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.144.0-alpha.1",
3
+ "version": "2.144.0-alpha.2",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",