@stoplight/ui-kit 3.0.0-beta.4 → 3.0.0-beta.40

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.
Files changed (164) hide show
  1. package/AutoSizer/index.js +3 -2
  2. package/AutoSizer/index.js.map +1 -1
  3. package/CodeEditor/index.d.ts +2 -0
  4. package/CodeEditor/index.js +7 -5
  5. package/CodeEditor/index.js.map +1 -1
  6. package/CodeEditor/utils/highlightCode.js +2 -1
  7. package/CodeEditor/utils/highlightCode.js.map +1 -1
  8. package/CodeViewer/components/BlockCodeViewer/BlockCodeViewer.d.ts +8 -0
  9. package/CodeViewer/components/BlockCodeViewer/BlockCodeViewer.js +51 -0
  10. package/CodeViewer/components/BlockCodeViewer/BlockCodeViewer.js.map +1 -0
  11. package/CodeViewer/components/BlockCodeViewer/ObservableSet.d.ts +5 -0
  12. package/CodeViewer/components/BlockCodeViewer/ObservableSet.js +24 -0
  13. package/CodeViewer/components/BlockCodeViewer/ObservableSet.js.map +1 -0
  14. package/CodeViewer/components/BlockCodeViewer/SingleCodeBlock.d.ts +12 -0
  15. package/CodeViewer/components/BlockCodeViewer/SingleCodeBlock.js +59 -0
  16. package/CodeViewer/components/BlockCodeViewer/SingleCodeBlock.js.map +1 -0
  17. package/CodeViewer/components/BlockCodeViewer/consts.d.ts +1 -0
  18. package/{TableOfContents/types.js → CodeViewer/components/BlockCodeViewer/consts.js} +2 -1
  19. package/CodeViewer/components/BlockCodeViewer/consts.js.map +1 -0
  20. package/CodeViewer/components/BlockCodeViewer/hooks/useSlicedBlocks.d.ts +7 -0
  21. package/CodeViewer/components/BlockCodeViewer/hooks/useSlicedBlocks.js +29 -0
  22. package/CodeViewer/components/BlockCodeViewer/hooks/useSlicedBlocks.js.map +1 -0
  23. package/CodeViewer/components/BlockCodeViewer/index.d.ts +2 -0
  24. package/CodeViewer/components/BlockCodeViewer/index.js +5 -0
  25. package/CodeViewer/components/BlockCodeViewer/index.js.map +1 -0
  26. package/CodeViewer/components/InlineCodeViewer.d.ts +5 -0
  27. package/CodeViewer/components/InlineCodeViewer.js +11 -0
  28. package/CodeViewer/components/InlineCodeViewer.js.map +1 -0
  29. package/CodeViewer/index.d.ts +1 -2
  30. package/CodeViewer/index.js +7 -16
  31. package/CodeViewer/index.js.map +1 -1
  32. package/CodeViewer/utils/astToReact.d.ts +3 -0
  33. package/CodeViewer/utils/astToReact.js +16 -0
  34. package/CodeViewer/utils/astToReact.js.map +1 -0
  35. package/CodeViewer/utils/lineNumberify.d.ts +2 -0
  36. package/CodeViewer/utils/lineNumberify.js +94 -0
  37. package/CodeViewer/utils/lineNumberify.js.map +1 -0
  38. package/CodeViewer/utils/parseCode.d.ts +2 -0
  39. package/CodeViewer/utils/parseCode.js +58 -0
  40. package/CodeViewer/utils/parseCode.js.map +1 -0
  41. package/Dropdown/Dropdown.js +2 -2
  42. package/Dropdown/Dropdown.js.map +1 -1
  43. package/FAIcon/index.js +3 -2
  44. package/FAIcon/index.js.map +1 -1
  45. package/FormButton/index.js +1 -1
  46. package/FormButton/index.js.map +1 -1
  47. package/FormError/index.js +2 -1
  48. package/FormError/index.js.map +1 -1
  49. package/FormInput/index.js +1 -1
  50. package/FormInput/index.js.map +1 -1
  51. package/ScrollContainer/index.js +3 -3
  52. package/ScrollContainer/index.js.map +1 -1
  53. package/ScrollList/index.js +12 -6
  54. package/ScrollList/index.js.map +1 -1
  55. package/SecretInput/index.js +1 -1
  56. package/SecretInput/index.js.map +1 -1
  57. package/SimpleTabs/Tab.js +3 -3
  58. package/SimpleTabs/Tab.js.map +1 -1
  59. package/SimpleTabs/TabList.js +3 -3
  60. package/SimpleTabs/TabList.js.map +1 -1
  61. package/SimpleTabs/TabPanel.js +3 -3
  62. package/SimpleTabs/TabPanel.js.map +1 -1
  63. package/TableOfContents/index.d.ts +61 -10
  64. package/TableOfContents/index.js +171 -62
  65. package/TableOfContents/index.js.map +1 -1
  66. package/ThemeContainer/index.js +4 -3
  67. package/ThemeContainer/index.js.map +1 -1
  68. package/_hooks/useIsMobile.js +2 -1
  69. package/_hooks/useIsMobile.js.map +1 -1
  70. package/_hooks/useValidateSchema.js +2 -1
  71. package/_hooks/useValidateSchema.js.map +1 -1
  72. package/classes.d.ts +3 -1
  73. package/classes.js +1 -1
  74. package/classes.js.map +1 -1
  75. package/index.d.ts +1 -0
  76. package/index.js +1 -0
  77. package/index.js.map +1 -1
  78. package/package.json +10 -8
  79. package/styles/_blueprint.scss +4 -4
  80. package/styles/_components.scss +3 -0
  81. package/styles/blueprint/_variables.scss +3 -1
  82. package/styles/blueprint/select/blueprint-select.scss +8 -0
  83. package/styles/blueprint/select/components/_index.scss +6 -0
  84. package/styles/blueprint/select/components/omnibar/_omnibar.scss +63 -0
  85. package/styles/blueprint/select/components/select/_multi-select.scss +17 -0
  86. package/styles/blueprint/select/components/select/_select.scss +31 -0
  87. package/styles/blueprint/src/_reset.scss +43 -0
  88. package/styles/blueprint/src/_typography.scss +459 -0
  89. package/styles/blueprint/src/accessibility/_focus-states.scss +17 -0
  90. package/styles/blueprint/src/blueprint-hi-contrast.scss +22 -0
  91. package/styles/blueprint/src/blueprint.scss +16 -0
  92. package/styles/blueprint/src/common/_color-aliases.scss +43 -0
  93. package/styles/blueprint/src/common/_colors.scss +116 -0
  94. package/styles/blueprint/src/common/_flex.scss +49 -0
  95. package/styles/blueprint/src/common/_mixins.scss +128 -0
  96. package/styles/blueprint/src/common/_react-transition.scss +117 -0
  97. package/styles/blueprint/src/common/_variables.scss +131 -0
  98. package/styles/blueprint/src/components/_index.scss +38 -0
  99. package/styles/blueprint/src/components/alert/_alert.scss +33 -0
  100. package/styles/blueprint/src/components/breadcrumbs/_breadcrumbs.scss +142 -0
  101. package/styles/blueprint/src/components/button/_button-group.scss +240 -0
  102. package/styles/blueprint/src/components/button/_button.scss +206 -0
  103. package/styles/blueprint/src/components/button/_common.scss +507 -0
  104. package/styles/blueprint/src/components/callout/_callout.scss +99 -0
  105. package/styles/blueprint/src/components/card/_card.scss +91 -0
  106. package/styles/blueprint/src/components/collapse/_collapse.scss +20 -0
  107. package/styles/blueprint/src/components/context-menu/_context-menu.scss +10 -0
  108. package/styles/blueprint/src/components/dialog/_dialog.scss +146 -0
  109. package/styles/blueprint/src/components/divider/_divider.scss +19 -0
  110. package/styles/blueprint/src/components/drawer/_drawer.scss +232 -0
  111. package/styles/blueprint/src/components/editable-text/_editable-text.scss +156 -0
  112. package/styles/blueprint/src/components/forms/_common.scss +239 -0
  113. package/styles/blueprint/src/components/forms/_control-group.scss +276 -0
  114. package/styles/blueprint/src/components/forms/_controls.scss +526 -0
  115. package/styles/blueprint/src/components/forms/_file-input.scss +155 -0
  116. package/styles/blueprint/src/components/forms/_form-group.scss +111 -0
  117. package/styles/blueprint/src/components/forms/_index.scss +20 -0
  118. package/styles/blueprint/src/components/forms/_input-group.scss +247 -0
  119. package/styles/blueprint/src/components/forms/_input.scss +115 -0
  120. package/styles/blueprint/src/components/forms/_label.scss +114 -0
  121. package/styles/blueprint/src/components/forms/_numeric-input.scss +40 -0
  122. package/styles/blueprint/src/components/hotkeys/_hotkeys.scss +50 -0
  123. package/styles/blueprint/src/components/html-select/_common.scss +52 -0
  124. package/styles/blueprint/src/components/html-select/_html-select.scss +104 -0
  125. package/styles/blueprint/src/components/html-table/_html-table.scss +208 -0
  126. package/styles/blueprint/src/components/icon/_icon.scss +79 -0
  127. package/styles/blueprint/src/components/menu/_common.scss +172 -0
  128. package/styles/blueprint/src/components/menu/_menu.scss +197 -0
  129. package/styles/blueprint/src/components/menu/_submenu.scss +41 -0
  130. package/styles/blueprint/src/components/navbar/_navbar.scss +117 -0
  131. package/styles/blueprint/src/components/non-ideal-state/_non-ideal-state.scss +43 -0
  132. package/styles/blueprint/src/components/overflow-list/_overflow-list.scss +13 -0
  133. package/styles/blueprint/src/components/overlay/_overlay.scss +94 -0
  134. package/styles/blueprint/src/components/panel-stack/_panel-stack.scss +103 -0
  135. package/styles/blueprint/src/components/popover/_common.scss +171 -0
  136. package/styles/blueprint/src/components/popover/_popover.scss +127 -0
  137. package/styles/blueprint/src/components/portal/_portal.scss +15 -0
  138. package/styles/blueprint/src/components/progress-bar/_common.scss +9 -0
  139. package/styles/blueprint/src/components/progress-bar/_progress-bar.scss +98 -0
  140. package/styles/blueprint/src/components/skeleton/_common.scss +8 -0
  141. package/styles/blueprint/src/components/skeleton/_skeleton.scss +64 -0
  142. package/styles/blueprint/src/components/slider/_common.scss +48 -0
  143. package/styles/blueprint/src/components/slider/_slider.scss +216 -0
  144. package/styles/blueprint/src/components/spinner/_spinner.scss +65 -0
  145. package/styles/blueprint/src/components/tabs/_tabs.scss +199 -0
  146. package/styles/blueprint/src/components/tag/_common.scss +202 -0
  147. package/styles/blueprint/src/components/tag/_tag.scss +75 -0
  148. package/styles/blueprint/src/components/tag-input/_tag-input.scss +165 -0
  149. package/styles/blueprint/src/components/toast/_toast.scss +203 -0
  150. package/styles/blueprint/src/components/tooltip/_common.scss +11 -0
  151. package/styles/blueprint/src/components/tooltip/_tooltip.scss +61 -0
  152. package/styles/blueprint/src/components/tree/_tree.scss +194 -0
  153. package/styles/components/Code/_base.scss +104 -25
  154. package/styles/components/TableOfContents/_base.scss +50 -43
  155. package/styles/tailwind/_base.scss +15423 -10455
  156. package/styles/tailwind/tailwind.config.js +1 -0
  157. package/CodeViewer/types.d.ts +0 -9
  158. package/CodeViewer/types.js +0 -3
  159. package/CodeViewer/types.js.map +0 -1
  160. package/TableOfContents/types.d.ts +0 -14
  161. package/TableOfContents/types.js.map +0 -1
  162. package/withErrorBoundary.d.ts +0 -104
  163. package/withErrorBoundary.js +0 -51
  164. package/withErrorBoundary.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const React = require("react");
4
- const react_virtualized_auto_sizer_1 = require("react-virtualized-auto-sizer");
3
+ const tslib_1 = require("tslib");
4
+ const React = tslib_1.__importStar(require("react"));
5
+ const react_virtualized_auto_sizer_1 = tslib_1.__importDefault(require("react-virtualized-auto-sizer"));
5
6
  exports.AutoSizer = props => React.createElement(react_virtualized_auto_sizer_1.default, Object.assign({}, props));
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AutoSizer/index.tsx"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,+EAAgF;AAMnE,QAAA,SAAS,GAA4C,KAAK,CAAC,EAAE,CAAC,oBAAC,sCAAgB,oBAAK,KAAK,EAAI,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AutoSizer/index.tsx"],"names":[],"mappings":";;;AAAA,qDAA+B;AAC/B,wGAAgF;AAMnE,QAAA,SAAS,GAA4C,KAAK,CAAC,EAAE,CAAC,oBAAC,sCAAgB,oBAAK,KAAK,EAAI,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { Intent } from '@blueprintjs/core';
1
2
  import * as React from 'react';
2
3
  import ReactSimpleCodeEditor from 'react-simple-code-editor';
3
4
  interface ICodeEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
@@ -7,6 +8,7 @@ interface ICodeEditorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'o
7
8
  language?: string;
8
9
  autoFocus?: boolean;
9
10
  showLineNumbers?: boolean;
11
+ intent?: Intent;
10
12
  }
11
13
  declare const CodeEditor: React.ForwardRefExoticComponent<ICodeEditorProps & React.RefAttributes<ReactSimpleCodeEditor>>;
12
14
  export { CodeEditor, ICodeEditorProps };
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const classnames_1 = require("classnames");
5
- const React = require("react");
6
- const react_simple_code_editor_1 = require("react-simple-code-editor");
4
+ const classnames_1 = tslib_1.__importDefault(require("classnames"));
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const react_simple_code_editor_1 = tslib_1.__importDefault(require("react-simple-code-editor"));
7
7
  const classes_1 = require("../classes");
8
8
  const highlightCode_1 = require("./utils/highlightCode");
9
9
  const CodeEditor = React.forwardRef((props, ref) => {
10
- const { autoFocus, language, onChange, value, placeholder, className, padding, style, showLineNumbers } = props, rest = tslib_1.__rest(props, ["autoFocus", "language", "onChange", "value", "placeholder", "className", "padding", "style", "showLineNumbers"]);
10
+ const { autoFocus, language, onChange, value, placeholder, className, padding, style, showLineNumbers, intent } = props, rest = tslib_1.__rest(props, ["autoFocus", "language", "onChange", "value", "placeholder", "className", "padding", "style", "showLineNumbers", "intent"]);
11
11
  const highlight = React.useCallback((code) => highlightCode_1.highlightCode(code, language || '', showLineNumbers), [
12
12
  language,
13
13
  showLineNumbers,
14
14
  ]);
15
+ const lineNumberCharacterCount = showLineNumbers ? String(Array.from(value.matchAll(/\n/g)).length + 1).length : 0;
15
16
  return (React.createElement(react_simple_code_editor_1.default, Object.assign({}, rest, { ref: ref, className: classnames_1.default(classes_1.Classes.CODE_EDITOR, className, {
16
- [`${classes_1.Classes.CODE_EDITOR}--line-numbers`]: showLineNumbers,
17
+ [`${classes_1.Classes.CODE_EDITOR}--line-numbers ${classes_1.Classes.CODE_EDITOR}--line-numbers--${lineNumberCharacterCount}`]: showLineNumbers,
18
+ [`${classes_1.Classes.CODE_EDITOR}--${intent}`]: intent !== void 0,
17
19
  }), style: style, placeholder: placeholder, autoFocus: autoFocus, value: value, onValueChange: onChange, highlight: highlight, padding: padding })));
18
20
  });
19
21
  exports.CodeEditor = CodeEditor;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CodeEditor/index.tsx"],"names":[],"mappings":";;;AAAA,2CAA4B;AAC5B,+BAA+B;AAC/B,uEAA6D;AAE7D,wCAAqC;AACrC,yDAAsD;AActD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAA0C,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC1F,MAAM,EACJ,SAAS,EACT,QAAQ,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,EAAE,CAAC,6BAAa,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE,EAAE,eAAe,CAAC,EAAE;QAC1G,QAAQ;QACR,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,wBAAwB,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnH,OAAO,CACL,oBAAC,kCAAqB,oBAChB,IAAI,IAER,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,oBAAE,CAAC,iBAAO,CAAC,WAAW,EAAE,SAAS,EAAE;YAC5C,CAAC,GAAG,iBAAO,CAAC,WAAW,kBAAkB,iBAAO,CAAC,WAAW,mBAAmB,wBAAwB,EAAE,CAAC,EAAE,eAAe;YAC3H,CAAC,GAAG,iBAAO,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,KAAK,CAAC;SACzD,CAAC,EACF,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,QAAQ,EACvB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,IAChB,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAMM,gCAAU;AALnB,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const Prism = require("prismjs");
3
+ const tslib_1 = require("tslib");
4
+ const Prism = tslib_1.__importStar(require("prismjs"));
4
5
  require("prismjs/components/prism-bash");
5
6
  require("prismjs/components/prism-c");
6
7
  require("prismjs/components/prism-csharp");
@@ -1 +1 @@
1
- {"version":3,"file":"highlightCode.js","sourceRoot":"","sources":["../../../src/CodeEditor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;YAED,OAAO,oCAAoC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;SACjE;QAED,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QAEd,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ export interface IBlockCodeViewerProps extends React.HTMLAttributes<HTMLPreElement> {
3
+ value: string;
4
+ language: string | undefined;
5
+ showLineNumbers: boolean;
6
+ }
7
+ declare const BlockCodeViewer: React.FC<IBlockCodeViewerProps>;
8
+ export { BlockCodeViewer as default };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const classnames_1 = tslib_1.__importDefault(require("classnames"));
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const classes_1 = require("../../../classes");
7
+ const useSlicedBlocks_1 = require("./hooks/useSlicedBlocks");
8
+ const ObservableSet_1 = require("./ObservableSet");
9
+ const SingleCodeBlock_1 = require("./SingleCodeBlock");
10
+ const BlockCodeViewer = (_a) => {
11
+ var { className, language, value, showLineNumbers } = _a, rest = tslib_1.__rest(_a, ["className", "language", "value", "showLineNumbers"]);
12
+ const nodeRef = React.useRef(null);
13
+ const maxLines = 100;
14
+ const [observer, setObserver] = React.useState();
15
+ const viewportSet = React.useRef(new ObservableSet_1.ObservableSet());
16
+ const slicedBlocks = useSlicedBlocks_1.useSlicedBlocks(value !== null && value !== void 0 ? value : '', maxLines - 1);
17
+ const lineNumberCharacterCount = String(slicedBlocks.length * maxLines).length;
18
+ React.useEffect(() => {
19
+ const { current: viewport } = viewportSet;
20
+ if (nodeRef.current === null) {
21
+ return;
22
+ }
23
+ const observer = new IntersectionObserver(entries => {
24
+ for (const entry of entries) {
25
+ if (!entry.isIntersecting)
26
+ continue;
27
+ viewport.add(entry.target);
28
+ const { previousElementSibling, nextElementSibling } = entry.target;
29
+ if ((previousElementSibling === null || previousElementSibling === void 0 ? void 0 : previousElementSibling.tagName) === 'DIV') {
30
+ viewport.add(previousElementSibling);
31
+ }
32
+ if ((nextElementSibling === null || nextElementSibling === void 0 ? void 0 : nextElementSibling.tagName) === 'DIV') {
33
+ viewport.add(nextElementSibling);
34
+ }
35
+ }
36
+ }, {
37
+ root: null,
38
+ threshold: 0,
39
+ });
40
+ setObserver(observer);
41
+ return () => {
42
+ setObserver(void 0);
43
+ observer.disconnect();
44
+ };
45
+ }, [nodeRef]);
46
+ return (React.createElement("pre", Object.assign({ ref: nodeRef, className: classnames_1.default(classes_1.Classes.CODE_VIEWER, className, `language-${language || 'unknown'}`, {
47
+ [`${classes_1.Classes.CODE_VIEWER}--line-numbers ${classes_1.Classes.CODE_VIEWER}--line-numbers--${lineNumberCharacterCount}`]: showLineNumbers,
48
+ }) }, rest), slicedBlocks === null || slicedBlocks === void 0 ? void 0 : slicedBlocks.map(({ id, value }, index, blocks) => (React.createElement(SingleCodeBlock_1.SingleCodeBlock, { key: id, value: value, language: language, showLineNumbers: showLineNumbers, lineNumber: (index > 0 ? blocks[index - 1].lineCount : 0) + 1, observer: observer, viewport: viewportSet.current })))));
49
+ };
50
+ exports.default = BlockCodeViewer;
51
+ //# sourceMappingURL=BlockCodeViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockCodeViewer.js","sourceRoot":"","sources":["../../../../src/CodeViewer/components/BlockCodeViewer/BlockCodeViewer.tsx"],"names":[],"mappings":";;;AAAA,oEAA4B;AAC5B,qDAA+B;AAE/B,8CAA2C;AAC3C,6DAA0D;AAC1D,mDAAgD;AAChD,uDAAoD;AAQpD,MAAM,eAAe,GAAoC,CAAC,EAAwD,EAAE,EAAE;QAA5D,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,OAAW,EAAT,gFAAO;IAC9G,MAAM,OAAO,GAAG,KAAK,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AC,EACD;YACE,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,CAAC;SACb,CACF,CAAC;QAEF,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEtB,OAAO,GAAG,EAAE;YACV,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YACpB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,CACL,2CACE,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,oBAAE,CAAC,iBAAO,CAAC,WAAW,EAAE,SAAS,EAAE,YAAY,QAAQ,IAAI,SAAS,EAAE,EAAE;YACjF,CAAC,GAAG,iBAAO,CAAC,WAAW,kBAAkB,iBAAO,CAAC,WAAW,mBAAmB,wBAAwB,EAAE,CAAC,EAAE,eAAe;SAC5H,CAAC,IACE,IAAI,GAEP,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CACnD,oBAAC,iCAAe,IACd,GAAG,EAAE,EAAE,EACP,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAC7D,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,WAAW,CAAC,OAAO,GAC7B,CACH,EACG,CACP,CAAC;AACJ,CAAC,CAAC;AAE0B,kCAAO"}
@@ -0,0 +1,5 @@
1
+ export declare class ObservableSet extends WeakSet<Element> {
2
+ private readonly listeners;
3
+ addListener(item: Element, cb: Function): () => void;
4
+ add(item: Element): this;
5
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ObservableSet extends WeakSet {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.listeners = new WeakMap();
7
+ }
8
+ addListener(item, cb) {
9
+ this.listeners.set(item, cb);
10
+ return () => {
11
+ this.listeners.delete(item);
12
+ };
13
+ }
14
+ add(item) {
15
+ var _a;
16
+ if (super.has(item))
17
+ return this;
18
+ super.add(item);
19
+ (_a = this.listeners.get(item)) === null || _a === void 0 ? void 0 : _a();
20
+ return this;
21
+ }
22
+ }
23
+ exports.ObservableSet = ObservableSet;
24
+ //# sourceMappingURL=ObservableSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObservableSet.js","sourceRoot":"","sources":["../../../../src/CodeViewer/components/BlockCodeViewer/ObservableSet.ts"],"names":[],"mappings":";;AAAA,MAAa,aAAc,SAAQ,OAAgB;IAAnD;;QACmB,cAAS,GAAG,IAAI,OAAO,EAAqB,CAAC;IAiBhE,CAAC;IAfC,WAAW,CAAC,IAAa,EAAE,EAAY;QACrC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAE7B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,IAAa;;QACf,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAEjC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChB,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,4CAAK;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlBD,sCAkBC"}
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import type { ObservableSet } from './ObservableSet';
3
+ interface IBlockProps {
4
+ value: string;
5
+ language: string | undefined;
6
+ showLineNumbers: boolean;
7
+ lineNumber: number;
8
+ observer: IntersectionObserver | undefined;
9
+ viewport: ObservableSet;
10
+ }
11
+ export declare const SingleCodeBlock: React.FC<IBlockProps>;
12
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const React = tslib_1.__importStar(require("react"));
5
+ const astToReact_1 = require("../../utils/astToReact");
6
+ const lineNumberify_1 = require("../../utils/lineNumberify");
7
+ const parseCode_1 = require("../../utils/parseCode");
8
+ const WHITESPACE_REGEX = /^[\s\n]+$/;
9
+ function isWhitespace(str) {
10
+ return WHITESPACE_REGEX.test(str);
11
+ }
12
+ function isTrailingWhiteLine(node) {
13
+ if (node.type === 'text') {
14
+ return isWhitespace(node.value);
15
+ }
16
+ if ('children' in node && node.children.length === 1 && 'value' in node.children[0]) {
17
+ return isWhitespace(node.children[0].value);
18
+ }
19
+ return false;
20
+ }
21
+ exports.SingleCodeBlock = ({ value, language, showLineNumbers, lineNumber, observer, viewport, }) => {
22
+ const [markup, setMarkup] = React.useState();
23
+ const [isVisible, setIsVisible] = React.useState(false);
24
+ const nodeRef = React.useRef(null);
25
+ React.useEffect(() => {
26
+ const { current: node } = nodeRef;
27
+ if (node === null || observer === void 0) {
28
+ return;
29
+ }
30
+ observer.observe(node);
31
+ const removeListener = viewport.addListener(node, () => {
32
+ setIsVisible(true);
33
+ observer.unobserve(node);
34
+ });
35
+ return () => {
36
+ observer.unobserve(node);
37
+ removeListener();
38
+ };
39
+ }, [viewport, observer, nodeRef]);
40
+ React.useEffect(() => {
41
+ if (isVisible) {
42
+ try {
43
+ const tree = parseCode_1.parseCode(value, language);
44
+ const processedTree = showLineNumbers ? lineNumberify_1.lineNumberify(tree, lineNumber - 1) : tree;
45
+ if (showLineNumbers && tree.length > 0 && isTrailingWhiteLine(tree[tree.length - 1])) {
46
+ processedTree.pop();
47
+ }
48
+ setMarkup(processedTree.map(astToReact_1.astToReact(0)));
49
+ }
50
+ catch (_a) {
51
+ }
52
+ }
53
+ }, [isVisible, lineNumber, value, language, showLineNumbers]);
54
+ if (markup !== void 0) {
55
+ return React.createElement(React.Fragment, null, markup);
56
+ }
57
+ return React.createElement("div", { ref: nodeRef }, value);
58
+ };
59
+ //# sourceMappingURL=SingleCodeBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SingleCodeBlock.js","sourceRoot":"","sources":["../../../../src/CodeViewer/components/BlockCodeViewer/SingleCodeBlock.tsx"],"names":[],"mappings":";;;AAAA,qDAA+B;AAG/B,uDAAoD;AACpD,6DAA0D;AAC1D,qDAAkD;AAYlD,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAmB;IAC9C,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;QACxB,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACjC;IAED,IAAI,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;QACnF,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;KAC7C;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,eAAe,GAA0B,CAAC,EACrD,KAAK,EACL,QAAQ,EACR,eAAe,EACf,UAAU,EACV,QAAQ,EACR,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAqB,CAAC;IAChE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAA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EP;SACF;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9D,IAAI,MAAM,KAAK,KAAK,CAAC,EAAE;QACrB,OAAO,0CAAG,MAAM,CAAI,CAAC;KACtB;IAED,OAAO,6BAAK,GAAG,EAAE,OAAO,IAAG,KAAK,CAAO,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const SINGLE_LINE_SIZE = 24;
@@ -1,3 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
3
+ exports.SINGLE_LINE_SIZE = 24;
4
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../../src/CodeViewer/components/BlockCodeViewer/consts.ts"],"names":[],"mappings":";;AAAa,QAAA,gBAAgB,GAAG,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare type SlicedBlock = {
2
+ id: string;
3
+ value: string;
4
+ lineCount: number;
5
+ };
6
+ export declare const useSlicedBlocks: (value: string, maxLines: number) => SlicedBlock[];
7
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const React = tslib_1.__importStar(require("react"));
5
+ function createSlicedBlock() {
6
+ return {
7
+ id: Math.random().toString(36),
8
+ value: '',
9
+ lineCount: 0,
10
+ };
11
+ }
12
+ exports.useSlicedBlocks = (value, maxLines) => {
13
+ return React.useMemo(() => {
14
+ const blocks = [createSlicedBlock()];
15
+ for (let i = 0, n = 0; i < value.length; i++) {
16
+ const char = value[i];
17
+ blocks[blocks.length - 1].value += char;
18
+ if (char === '\n') {
19
+ n++;
20
+ if (n % maxLines === 0 && i + 1 !== value.length) {
21
+ blocks[blocks.length - 1].lineCount = n;
22
+ blocks.push(createSlicedBlock());
23
+ }
24
+ }
25
+ }
26
+ return blocks;
27
+ }, [value, maxLines]);
28
+ };
29
+ //# sourceMappingURL=useSlicedBlocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSlicedBlocks.js","sourceRoot":"","sources":["../../../../../src/CodeViewer/components/BlockCodeViewer/hooks/useSlicedBlocks.ts"],"names":[],"mappings":";;;AAAA,qDAA+B;AAQ/B,SAAS,iBAAiB;IACxB,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,CAAC;KACb,CAAC;AACJ,CAAC;AAEY,QAAA,eAAe,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAE,EAAE;IACjE,OAAO,KAAK,CAAC,OAAO,CAAgB,GAAG,EAAE;QACvC,MAAM,MAAM,GAAkB,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAEpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC;YAExC,IAAI,IAAI,KAAK,IAAI,EAAE;gBACjB,CAAC,EAAE,CAAC;gBAEJ,IAAI,CAAC,GAAG,QAAQ,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,MAAM,EAAE;oBAChD,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;oBACxC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;iBAClC;aACF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type { IBlockCodeViewerProps } from './BlockCodeViewer';
2
+ export { default as BlockCodeViewer } from './BlockCodeViewer';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BlockCodeViewer_1 = require("./BlockCodeViewer");
4
+ exports.BlockCodeViewer = BlockCodeViewer_1.default;
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/CodeViewer/components/BlockCodeViewer/index.tsx"],"names":[],"mappings":";;AACA,qDAA+D;AAAtD,4CAAA,OAAO,CAAmB"}
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ export interface IInlineCodeViewerProps extends React.HTMLAttributes<HTMLElement> {
3
+ value: string;
4
+ }
5
+ export declare const InlineCodeViewer: React.FC<IInlineCodeViewerProps>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const classnames_1 = tslib_1.__importDefault(require("classnames"));
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const classes_1 = require("../../classes");
7
+ exports.InlineCodeViewer = (_a) => {
8
+ var { className, value } = _a, rest = tslib_1.__rest(_a, ["className", "value"]);
9
+ return (React.createElement("code", Object.assign({ className: classnames_1.default(classes_1.Classes.CODE_VIEWER, className, `${classes_1.Classes.CODE_VIEWER}--inline`) }, rest), value));
10
+ };
11
+ //# sourceMappingURL=InlineCodeViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InlineCodeViewer.js","sourceRoot":"","sources":["../../../src/CodeViewer/components/InlineCodeViewer.tsx"],"names":[],"mappings":";;;AAAA,oEAA4B;AAC5B,qDAA+B;AAE/B,2CAAwC;AAM3B,QAAA,gBAAgB,GAAqC,CAAC,EAA6B,EAAE,EAAE;QAAjC,EAAE,SAAS,EAAE,KAAK,OAAW,EAAT,iDAAO;IAC5F,OAAO,CACL,4CAAM,SAAS,EAAE,oBAAE,CAAC,iBAAO,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,iBAAO,CAAC,WAAW,UAAU,CAAC,IAAM,IAAI,GAC5F,KAAK,CACD,CACR,CAAC;AACJ,CAAC,CAAC"}
@@ -1,6 +1,5 @@
1
- import 'prismjs';
2
1
  import * as React from 'react';
3
- interface ICodeViewerProps extends React.HTMLAttributes<HTMLDivElement> {
2
+ interface ICodeViewerProps extends React.HTMLAttributes<HTMLElement> {
4
3
  value: string;
5
4
  language?: string;
6
5
  showLineNumbers?: boolean;
@@ -1,28 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- require("prismjs");
5
- const cn = require("classnames");
6
- const React = require("react");
7
- const classes_1 = require("../classes");
8
- const highlightCode_1 = require("../CodeEditor/utils/highlightCode");
4
+ const React = tslib_1.__importStar(require("react"));
5
+ const BlockCodeViewer_1 = require("./components/BlockCodeViewer");
6
+ const InlineCodeViewer_1 = require("./components/InlineCodeViewer");
9
7
  const languageMaps = {
10
8
  md: 'markdown',
11
9
  };
12
10
  const CodeViewer = (_a) => {
13
- var { language, value, showLineNumbers = false, inline = false, className } = _a, rest = tslib_1.__rest(_a, ["language", "value", "showLineNumbers", "inline", "className"]);
14
- const lang = (language && languageMaps[language]) || language || '';
15
- const code = React.useMemo(() => highlightCode_1.highlightCode(value, lang, showLineNumbers), [value, lang, showLineNumbers]);
11
+ var { language, value, showLineNumbers = false, inline = false } = _a, rest = tslib_1.__rest(_a, ["language", "value", "showLineNumbers", "inline"]);
16
12
  if (inline) {
17
- return (React.createElement("code", Object.assign({ className: cn(classes_1.Classes.CODE_EDITOR, className, {
18
- [`${classes_1.Classes.CODE_EDITOR}--inline`]: inline,
19
- [`${classes_1.Classes.CODE_EDITOR}--line-numbers`]: showLineNumbers,
20
- }) }, rest, { dangerouslySetInnerHTML: { __html: code } })));
13
+ return React.createElement(InlineCodeViewer_1.InlineCodeViewer, Object.assign({ value: value }, rest));
21
14
  }
22
- return (React.createElement("pre", Object.assign({ className: cn(classes_1.Classes.CODE_EDITOR, className, `language-${lang || 'unknown'}`, {
23
- [`${classes_1.Classes.CODE_EDITOR}--inline`]: inline,
24
- [`${classes_1.Classes.CODE_EDITOR}--line-numbers`]: showLineNumbers,
25
- }) }, rest, { dangerouslySetInnerHTML: { __html: code } })));
15
+ const lang = (language && languageMaps[language]) || language;
16
+ return React.createElement(BlockCodeViewer_1.BlockCodeViewer, Object.assign({ showLineNumbers: showLineNumbers, language: lang, value: value }, rest));
26
17
  };
27
18
  exports.CodeViewer = CodeViewer;
28
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CodeViewer/index.tsx"],"names":[],"mappings":";;;AAAA,mBAAiB;AAEjB,iCAAiC;AACjC,+BAA+B;AAE/B,wCAAqC;AACrC,qEAAkE;AAElE,MAAM,YAAY,GAA+B;IAC/C,EAAE,EAAE,UAAU;CACf,CAAC;AAYF,MAAM,UAAU,GAA8C,CAAC,EAO9D,EAAE,EAAE;QAP0D,EAC7D,QAAQ,EACR,KAAK,EACL,eAAe,GAAG,KAAK,EACvB,MAAM,GAAG,KAAK,EACd,SAAS,OAEV,EADC,0FAAO;IAEP,MAAM,IAAI,GAAG,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,IAAI,EAAE,CAAC;IAEpE,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,6BAAa,CAAC,KAAK,EAAE,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9G,IAAI,MAAM,EAAE;QACV,OAAO,CACL,4CACE,SAAS,EAAE,EAAE,CAAC,iB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E,IAAI,EAAE,KAAK,EAAE,KAAK,IAAM,IAAI,EAAI,CAAC;AACvG,CAAC,CAAC;AAMO,gCAAU"}
@@ -0,0 +1,3 @@
1
+ import { ReactNode } from 'react';
2
+ import { RefractorNode } from 'refractor/core';
3
+ export declare function astToReact(depth?: number): (child: RefractorNode, i: number) => ReactNode;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ function mapChild(child, i, depth) {
5
+ if ('tagName' in child) {
6
+ return react_1.createElement(child.tagName, Object.assign(Object.assign({ key: `cv-${depth}-${i}` }, child.properties), { className: child.properties && (child.properties.className || []).join(' ') }), child.children && child.children.map(astToReact(depth + 1)));
7
+ }
8
+ return child.value;
9
+ }
10
+ function astToReact(depth = 0) {
11
+ return function mapChildrenWithDepth(child, i) {
12
+ return mapChild(child, i, depth);
13
+ };
14
+ }
15
+ exports.astToReact = astToReact;
16
+ //# sourceMappingURL=astToReact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astToReact.js","sourceRoot":"","sources":["../../../src/CodeViewer/utils/astToReact.ts"],"names":[],"mappings":";;AAAA,iCAAiD;AAIjD,SAAS,QAAQ,CAAC,KAAoB,EAAE,CAAS,EAAE,KAAa;IAC9D,IAAI,SAAS,IAAI,KAAK,EAAE;QACtB,OAAO,qBAAa,CAClB,KAAK,CAAC,OAAO,gCAEX,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,IACpB,KAAK,CAAC,UAAU,KACnB,SAAS,EAAE,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAE7E,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAC5D,CAAC;KACH;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,SAAgB,UAAU,CAAC,QAAgB,CAAC;IAC1C,OAAO,SAAS,oBAAoB,CAAC,KAAoB,EAAE,CAAS;QAClE,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAJD,gCAIC"}
@@ -0,0 +1,2 @@
1
+ import { RefractorNode } from 'refractor/core';
2
+ export declare function lineNumberify(codeTree: RefractorNode[], initialLineNumber: number): RefractorNode[];
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const newLineRegex = /\n/g;
4
+ function getNewLines(str) {
5
+ return str.match(newLineRegex);
6
+ }
7
+ function createLineElement({ children, lineNumber, className, }) {
8
+ return {
9
+ type: 'element',
10
+ tagName: 'span',
11
+ properties: Object.assign({ className: lineNumber === void 0 ? className : ['line-number'] }, (lineNumber !== void 0 && { 'data-node-index': lineNumber })),
12
+ children,
13
+ };
14
+ }
15
+ function flattenCodeTree(tree, className = []) {
16
+ const newTree = [];
17
+ for (const node of tree) {
18
+ if (node.type === 'text') {
19
+ newTree.push(createLineElement({
20
+ children: [node],
21
+ className,
22
+ }));
23
+ }
24
+ else if (node.children && node.properties.className !== void 0) {
25
+ const classNames = className.concat(node.properties.className);
26
+ newTree.push(...flattenCodeTree(node.children, classNames));
27
+ }
28
+ }
29
+ return newTree;
30
+ }
31
+ function lineNumberify(codeTree, initialLineNumber) {
32
+ const tree = flattenCodeTree(codeTree);
33
+ const newTree = [];
34
+ let lastLineBreakIndex = -1;
35
+ let index = 0;
36
+ while (index < tree.length) {
37
+ const node = tree[index];
38
+ const value = node.children[0].value;
39
+ const newLines = getNewLines(value);
40
+ if (newLines) {
41
+ const splitValue = value.split('\n');
42
+ splitValue.forEach((text, i) => {
43
+ const lineNumber = initialLineNumber + newTree.length + 1;
44
+ const newChild = { type: 'text', value: `${text}\n` };
45
+ if (i === 0) {
46
+ const children = tree.slice(lastLineBreakIndex + 1, index).concat(createLineElement({
47
+ children: [newChild],
48
+ className: node.properties.className,
49
+ }));
50
+ newTree.push(createLineElement({ children, lineNumber }));
51
+ }
52
+ else if (i === splitValue.length - 1) {
53
+ const stringChild = tree[index + 1] && tree[index + 1].children && tree[index + 1].children[0];
54
+ if (stringChild) {
55
+ const lastLineInPreviousSpan = { type: 'text', value: `${text}` };
56
+ const newElem = createLineElement({
57
+ children: [lastLineInPreviousSpan],
58
+ className: node.properties.className,
59
+ });
60
+ tree.splice(index + 1, 0, newElem);
61
+ }
62
+ else {
63
+ newTree.push(createLineElement({
64
+ children: [newChild],
65
+ lineNumber,
66
+ className: node.properties.className,
67
+ }));
68
+ }
69
+ }
70
+ else {
71
+ newTree.push(createLineElement({
72
+ children: [newChild],
73
+ lineNumber,
74
+ className: node.properties.className,
75
+ }));
76
+ }
77
+ });
78
+ lastLineBreakIndex = index;
79
+ }
80
+ index++;
81
+ }
82
+ if (lastLineBreakIndex !== tree.length - 1) {
83
+ const children = tree.slice(lastLineBreakIndex + 1, tree.length);
84
+ if (children && children.length) {
85
+ newTree.push(createLineElement({
86
+ children,
87
+ lineNumber: initialLineNumber + newTree.length + 1,
88
+ }));
89
+ }
90
+ }
91
+ return newTree;
92
+ }
93
+ exports.lineNumberify = lineNumberify;
94
+ //# sourceMappingURL=lineNumberify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineNumberify.js","sourceRoot":"","sources":["../../../src/CodeViewer/utils/lineNumberify.ts"],"names":[],"mappings":";;AAGA,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,iBAAiB,CAAC,EACzB,QAAQ,EACR,UAAU,EACV,SAAS,GAKV;IACC,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,MAAM;QACf,UAAU,kBACR,SAAS,EA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;4BAClC,SAAS,EAAE,IAAI,CAAC,UAAW,CAAC,SAAS;yBACtC,CAAC,CAAC;wBACH,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;qBACpC;yBAAM;wBACL,OAAO,CAAC,IAAI,CACV,iBAAiB,CAAC;4BAChB,QAAQ,EAAE,CAAC,QAAQ,CAAC;4BACpB,UAAU;4BACV,SAAS,EAAE,IAAI,CAAC,UAAW,CAAC,SAAS;yBACtC,CAAC,CACH,CAAC;qBACH;iBACF;qBAAM;oBACL,OAAO,CAAC,IAAI,CACV,iBAAiB,CAAC;wBAChB,QAAQ,EAAE,CAAC,QAAQ,CAAC;wBACpB,UAAU;wBACV,SAAS,EAAE,IAAI,CAAC,UAAW,CAAC,SAAS;qBACtC,CAAC,CACH,CAAC;iBACH;YACH,CAAC,CAAC,CAAC;YAEH,kBAAkB,GAAG,KAAK,CAAC;SAC5B;QACD,KAAK,EAAE,CAAC;KACT;IAED,IAAI,kBAAkB,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjE,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC/B,OAAO,CAAC,IAAI,CACV,iBAAiB,CAAC;gBAChB,QAAQ;gBACR,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC;aACnD,CAAC,CACH,CAAC;SACH;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAxED,sCAwEC"}
@@ -0,0 +1,2 @@
1
+ import * as refractor from 'refractor/core';
2
+ export declare function parseCode(code: string, language?: string): refractor.RefractorNode[];
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const refractor = tslib_1.__importStar(require("refractor/core"));
5
+ refractor.register(require('refractor/lang/bash'));
6
+ refractor.register(require('refractor/lang/c'));
7
+ refractor.register(require('refractor/lang/csharp'));
8
+ refractor.register(require('refractor/lang/diff'));
9
+ refractor.register(require('refractor/lang/git'));
10
+ refractor.register(require('refractor/lang/go'));
11
+ refractor.register(require('refractor/lang/graphql'));
12
+ refractor.register(require('refractor/lang/http'));
13
+ refractor.register(require('refractor/lang/java'));
14
+ refractor.register(require('refractor/lang/javascript'));
15
+ refractor.register(require('refractor/lang/json'));
16
+ refractor.register(require('refractor/lang/jsx'));
17
+ refractor.register(require('refractor/lang/markdown'));
18
+ refractor.register(require('refractor/lang/markup'));
19
+ refractor.register(require('refractor/lang/markup-templating'));
20
+ refractor.register(require('refractor/lang/objectivec'));
21
+ refractor.register(require('refractor/lang/ocaml'));
22
+ refractor.register(require('refractor/lang/php'));
23
+ refractor.register(require('refractor/lang/powershell'));
24
+ refractor.register(require('refractor/lang/protobuf'));
25
+ refractor.register(require('refractor/lang/python'));
26
+ refractor.register(require('refractor/lang/ruby'));
27
+ refractor.register(require('refractor/lang/sql'));
28
+ refractor.register(require('refractor/lang/swift'));
29
+ refractor.register(require('refractor/lang/typescript'));
30
+ refractor.register(require('refractor/lang/yaml'));
31
+ function parsePlainText(code) {
32
+ return code.split('\n').map((value, i, arr) => ({
33
+ type: 'element',
34
+ tagName: 'span',
35
+ properties: {},
36
+ children: [
37
+ {
38
+ type: 'text',
39
+ value: arr.length - 1 === i ? value : `${value}\n`,
40
+ },
41
+ ],
42
+ }));
43
+ }
44
+ function safeParse(code, language) {
45
+ if (language) {
46
+ try {
47
+ return refractor.highlight(code, language);
48
+ }
49
+ catch (ex) {
50
+ }
51
+ }
52
+ return parsePlainText(code);
53
+ }
54
+ function parseCode(code, language) {
55
+ return safeParse(code, language);
56
+ }
57
+ exports.parseCode = parseCode;
58
+ //# sourceMappingURL=parseCode.js.map