@monolith-forensics/monolith-ui 1.9.1-dev.10 → 1.9.1-dev.11

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.
@@ -81,6 +81,29 @@ export interface MonolithDefaultTheme {
81
81
  action: {
82
82
  hover: string;
83
83
  };
84
+ codeBlock?: {
85
+ background: string;
86
+ text: string;
87
+ border: string;
88
+ selection: string;
89
+ syntax: {
90
+ comment: string;
91
+ punctuation: string;
92
+ property: string;
93
+ selector: string;
94
+ operator: string;
95
+ keyword: string;
96
+ string: string;
97
+ number: string;
98
+ function: string;
99
+ variable: string;
100
+ tag: string;
101
+ attribute: string;
102
+ literal: string;
103
+ deleted: string;
104
+ inserted: string;
105
+ };
106
+ };
84
107
  divider: string;
85
108
  };
86
109
  header: {
@@ -9,10 +9,6 @@ import TextColors from "../Enums/TextColors";
9
9
  import HighlightColors from "../Enums/HighlightColors";
10
10
  import LinkEditor from "./LinkEditor";
11
11
  import { hasInlineCode, toggleInlineCode } from "../Utils/codeUtils";
12
- import CodeBlockLanguageSelect from "./CodeBlockLanguageSelect";
13
- import CodeBlockCopyButton from "./CodeBlockCopyButton";
14
- import CodeBlockWrapButton from "./CodeBlockWrapButton";
15
- import CodeBlockFormatButton from "./CodeBlockFormatButton";
16
12
  import { hasSyntaxHighlightedCodeBlock, toggleCodeBlock, } from "../Utils/codeBlockUtils";
17
13
  const getMenuItems = (editor, customMenuItems, theme, openLinkEditor) => {
18
14
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -77,7 +73,8 @@ const getMenuItems = (editor, customMenuItems, theme, openLinkEditor) => {
77
73
  data: {
78
74
  Icon: CaseSensitiveIcon,
79
75
  command: (editor) => {
80
- if (editor.isActive("bulletList") || editor.isActive("orderedList")) {
76
+ if (editor.isActive("bulletList") ||
77
+ editor.isActive("orderedList")) {
81
78
  editor
82
79
  .chain()
83
80
  .focus()
@@ -387,11 +384,11 @@ const BubbleItemButton = styled(Button) `
387
384
  `;
388
385
  const CodeBlockBubbleTools = ({ editor, theme, }) => {
389
386
  const nodeTypeMenu = getMenuItems(editor, [], theme, () => undefined).find((item) => item.name === "node_type");
390
- return (_jsxs(_Fragment, { children: [(nodeTypeMenu === null || nodeTypeMenu === void 0 ? void 0 : nodeTypeMenu.type) === "menu" && (_jsx(DropDownMenu, Object.assign({ data: nodeTypeMenu.items, size: "xs", arrow: nodeTypeMenu.arrow, buttonProps: nodeTypeMenu.buttonProps, variant: "subtle", buttonRender: nodeTypeMenu.buttonRender, onItemSelect: (item) => { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.command) === null || _b === void 0 ? void 0 : _b.call(_a, editor, ""); }, dropDownProps: {
391
- style: { width: 135 },
392
- } }, nodeTypeMenu.dropDownProps, { children: nodeTypeMenu.icon
393
- ? (_jsx(nodeTypeMenu.icon, { size: 14 }))
394
- : (nodeTypeMenu.label || nodeTypeMenu.name) }))), _jsx(CodeBlockLanguageSelect, { editor: editor }), _jsx(CodeBlockWrapButton, { editor: editor }), _jsx(CodeBlockFormatButton, { editor: editor }), _jsx(CodeBlockCopyButton, { editor: editor })] }));
387
+ return (_jsx(_Fragment, { children: (nodeTypeMenu === null || nodeTypeMenu === void 0 ? void 0 : nodeTypeMenu.type) === "menu" && (_jsx(DropDownMenu, Object.assign({ data: nodeTypeMenu.items, size: "xs", arrow: nodeTypeMenu.arrow, buttonProps: nodeTypeMenu.buttonProps, variant: "subtle", buttonRender: nodeTypeMenu.buttonRender, onItemSelect: (item) => { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.command) === null || _b === void 0 ? void 0 : _b.call(_a, editor, ""); }, dropDownProps: {
388
+ style: { width: 135 },
389
+ } }, nodeTypeMenu.dropDownProps, { children: nodeTypeMenu.icon
390
+ ? (_jsx(nodeTypeMenu.icon, { size: 14 }))
391
+ : (nodeTypeMenu.label || nodeTypeMenu.name) }))) }));
395
392
  };
396
393
  const BubbleMenu = ({ className, editor, customMenuItems = [], }) => {
397
394
  const theme = useTheme();
@@ -0,0 +1,18 @@
1
+ export declare const CodeBlockBaseButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
2
+ ref?: import("react").RefObject<HTMLButtonElement>;
3
+ children?: import("react").ReactNode | string;
4
+ className?: string;
5
+ loading?: boolean;
6
+ leftSection?: import("react").ReactNode;
7
+ rightSection?: import("react").ReactNode;
8
+ href?: string | null;
9
+ download?: string | null;
10
+ fullWidth?: boolean;
11
+ size?: import("../../core").Size;
12
+ variant?: import("../../core").Variant;
13
+ color?: import("../../Button").ButtonColor;
14
+ disabled?: boolean;
15
+ selected?: boolean;
16
+ justify?: "start" | "center" | "end";
17
+ onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
18
+ }, never>> & string & Omit<import("react").FC<import("../../Button").ButtonProps>, keyof import("react").Component<any, {}, any>>;
@@ -0,0 +1,6 @@
1
+ import styled from "styled-components";
2
+ import { Button } from "../../Button";
3
+ export const CodeBlockBaseButton = styled(Button) `
4
+ padding: 5px;
5
+ background-color: ${({ theme }) => theme.palette.background.paper};
6
+ `;
@@ -5,5 +5,5 @@ type CodeBlockCopyButtonProps = {
5
5
  text?: string;
6
6
  size?: "xs" | "sm";
7
7
  };
8
- declare const CodeBlockCopyButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<CodeBlockCopyButtonProps, never>> & string & Omit<({ className, editor, text, size }: CodeBlockCopyButtonProps) => import("react/jsx-runtime").JSX.Element, keyof import("react").Component<any, {}, any>>;
8
+ declare const CodeBlockCopyButton: ({ className, editor, text, size, }: CodeBlockCopyButtonProps) => import("react/jsx-runtime").JSX.Element;
9
9
  export default CodeBlockCopyButton;
@@ -9,11 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { useEffect, useState } from "react";
12
- import styled from "styled-components";
13
12
  import { CheckIcon, CopyIcon } from "lucide-react";
14
- import { Button } from "../../Button";
15
13
  import { copyCodeBlockText, getActiveCodeBlockText, } from "../Utils/codeBlockUtils";
16
- const CodeBlockCopyButton = styled(({ className, editor, text, size = "xs" }) => {
14
+ import { CodeBlockBaseButton } from "./CodeBlockBaseButton";
15
+ const CodeBlockCopyButton = ({ className, editor, text, size = "xs", }) => {
17
16
  const [copied, setCopied] = useState(false);
18
17
  const [copyFailed, setCopyFailed] = useState(false);
19
18
  const code = text !== null && text !== void 0 ? text : getActiveCodeBlockText(editor || null);
@@ -26,7 +25,7 @@ const CodeBlockCopyButton = styled(({ className, editor, text, size = "xs" }) =>
26
25
  }, 1400);
27
26
  return () => window.clearTimeout(timeout);
28
27
  }, [copied, copyFailed]);
29
- return (_jsx(Button, { className: className, size: size, variant: "outlined", title: copyFailed ? "Unable to copy" : copied ? "Copied" : "Copy code", "aria-label": copyFailed ? "Unable to copy code" : copied ? "Copied" : "Copy code", disabled: !code, onClick: (event) => __awaiter(void 0, void 0, void 0, function* () {
28
+ return (_jsx(CodeBlockBaseButton, { className: className, size: size, variant: "outlined", title: copyFailed ? "Unable to copy" : copied ? "Copied" : "Copy code", "aria-label": copyFailed ? "Unable to copy code" : copied ? "Copied" : "Copy code", disabled: !code, onClick: (event) => __awaiter(void 0, void 0, void 0, function* () {
30
29
  event.preventDefault();
31
30
  event.stopPropagation();
32
31
  try {
@@ -39,7 +38,5 @@ const CodeBlockCopyButton = styled(({ className, editor, text, size = "xs" }) =>
39
38
  setCopyFailed(true);
40
39
  }
41
40
  }), children: copied ? _jsx(CheckIcon, { size: 14 }) : _jsx(CopyIcon, { size: 14 }) }));
42
- }) `
43
- padding: 3px;
44
- `;
41
+ };
45
42
  export default CodeBlockCopyButton;
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { useEffect, useState } from "react";
12
12
  import { CheckIcon, TriangleAlertIcon, WandSparklesIcon } from "lucide-react";
13
- import { Button } from "../../Button";
14
13
  import { canFormatCodeBlockLanguage, formatActiveCodeBlock, getCodeBlockLanguage, } from "../Utils/codeBlockUtils";
14
+ import { CodeBlockBaseButton } from "./CodeBlockBaseButton";
15
15
  const CodeBlockFormatButton = ({ className, editor, language, onFormat, size = "xs", }) => {
16
16
  const [formatted, setFormatted] = useState(false);
17
17
  const [formatFailed, setFormatFailed] = useState(false);
@@ -26,7 +26,7 @@ const CodeBlockFormatButton = ({ className, editor, language, onFormat, size = "
26
26
  }, 1400);
27
27
  return () => window.clearTimeout(timeout);
28
28
  }, [formatted, formatFailed]);
29
- return (_jsx(Button, { className: className, size: size, variant: "outlined", title: !canFormat
29
+ return (_jsx(CodeBlockBaseButton, { className: className, size: size, variant: "outlined", title: !canFormat
30
30
  ? "Formatting is not supported for this language"
31
31
  : formatFailed
32
32
  ? "Unable to format code"
@@ -1,6 +1,9 @@
1
1
  import { Editor } from "@tiptap/react";
2
2
  type CodeBlockLanguageSelectProps = {
3
- editor: Editor | null;
3
+ className?: string;
4
+ editor?: Editor | null;
5
+ language?: string;
6
+ onLanguageChange?: (language: string) => void;
4
7
  };
5
- declare const CodeBlockLanguageSelect: ({ editor }: CodeBlockLanguageSelectProps) => import("react/jsx-runtime").JSX.Element;
8
+ declare const CodeBlockLanguageSelect: ({ className, editor, language, onLanguageChange, }: CodeBlockLanguageSelectProps) => import("react/jsx-runtime").JSX.Element;
6
9
  export default CodeBlockLanguageSelect;
@@ -2,15 +2,24 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { CodeXmlIcon } from "lucide-react";
3
3
  import { DropDownMenu } from "../../DropDownMenu";
4
4
  import { CODE_BLOCK_LANGUAGES, getCodeBlockLanguage, getCodeBlockLanguageOption, setCodeBlockLanguage, } from "../Utils/codeBlockUtils";
5
- const CodeBlockLanguageSelect = ({ editor }) => {
6
- const language = getCodeBlockLanguage(editor);
7
- const selectedLanguage = getCodeBlockLanguageOption(language);
8
- return (_jsx(DropDownMenu, { data: CODE_BLOCK_LANGUAGES, value: [selectedLanguage], enableSelectedOptionStyling: true, size: "xs", variant: "outlined", disabled: !(editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock")), onItemSelect: (item) => {
9
- setCodeBlockLanguage(editor, item.value);
5
+ import { useTheme } from "styled-components";
6
+ const CodeBlockLanguageSelect = ({ className, editor, language, onLanguageChange, }) => {
7
+ const theme = useTheme();
8
+ const codeLanguage = language !== null && language !== void 0 ? language : getCodeBlockLanguage(editor || null);
9
+ const selectedLanguage = getCodeBlockLanguageOption(codeLanguage);
10
+ return (_jsx(DropDownMenu, { className: className, data: CODE_BLOCK_LANGUAGES, value: [selectedLanguage], enableSelectedOptionStyling: true, size: "xs", variant: "outlined", disabled: !onLanguageChange && !(editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock")), onItemSelect: (item) => {
11
+ if (onLanguageChange) {
12
+ onLanguageChange(item.value);
13
+ return;
14
+ }
15
+ setCodeBlockLanguage(editor || null, item.value);
10
16
  }, buttonProps: {
11
17
  title: "Select code language",
12
18
  leftSection: _jsx(CodeXmlIcon, { size: 12 }),
13
- style: { padding: "1px 6px" },
19
+ style: {
20
+ padding: "1px 6px",
21
+ backgroundColor: theme.palette.background.paper,
22
+ },
14
23
  }, dropDownProps: {
15
24
  style: {
16
25
  width: 150,
@@ -12,11 +12,12 @@ import { NodeViewContent, NodeViewWrapper, } from "@tiptap/react";
12
12
  import CodeBlockCopyButton from "./CodeBlockCopyButton";
13
13
  import CodeBlockWrapButton from "./CodeBlockWrapButton";
14
14
  import CodeBlockFormatButton from "./CodeBlockFormatButton";
15
+ import CodeBlockLanguageSelect from "./CodeBlockLanguageSelect";
15
16
  import { formatCodeBlockText, replaceCodeBlockContent, } from "../Utils/codeBlockUtils";
16
17
  const CodeBlockNodeView = ({ editor, getPos, node, updateAttributes, }) => {
17
18
  const language = node.attrs.language;
18
19
  const wrap = Boolean(node.attrs.wrap);
19
- return (_jsxs(NodeViewWrapper, { as: "pre", className: "editor-code-block", "data-language": language || "plaintext", "data-wrap": wrap ? "true" : "false", children: [_jsxs("div", { className: "editor-code-block-actions", contentEditable: false, children: [_jsx(CodeBlockWrapButton, { className: "editor-code-block-action", active: wrap, onToggle: () => updateAttributes({ wrap: !wrap }) }), _jsx(CodeBlockFormatButton, { className: "editor-code-block-action", language: language, onFormat: () => __awaiter(void 0, void 0, void 0, function* () {
20
+ return (_jsxs(NodeViewWrapper, { as: "pre", className: "editor-code-block", "data-language": language || "plaintext", "data-wrap": wrap ? "true" : "false", children: [_jsxs("div", { className: "editor-code-block-actions", contentEditable: false, children: [_jsx(CodeBlockLanguageSelect, { language: language, onLanguageChange: (language) => updateAttributes({ language }) }), _jsx(CodeBlockWrapButton, { active: wrap, onToggle: () => updateAttributes({ wrap: !wrap }) }), _jsx(CodeBlockFormatButton, { className: "editor-code-block-action", language: language, onFormat: () => __awaiter(void 0, void 0, void 0, function* () {
20
21
  const pos = getPos();
21
22
  if (typeof pos !== "number")
22
23
  return;
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { WrapTextIcon } from "lucide-react";
3
- import { Button } from "../../Button";
4
- import { getCodeBlockWrap, toggleCodeBlockWrap, } from "../Utils/codeBlockUtils";
3
+ import { getCodeBlockWrap, toggleCodeBlockWrap } from "../Utils/codeBlockUtils";
4
+ import { CodeBlockBaseButton } from "./CodeBlockBaseButton";
5
5
  const CodeBlockWrapButton = ({ className, editor, active, onToggle, size = "xs", }) => {
6
6
  const isWrapped = active !== null && active !== void 0 ? active : getCodeBlockWrap(editor || null);
7
- return (_jsx(Button, { className: className, size: size, variant: "outlined", title: isWrapped ? "Disable code wrapping" : "Enable code wrapping", "aria-label": isWrapped ? "Disable code wrapping" : "Enable code wrapping", selected: isWrapped, disabled: !onToggle && !(editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock")), onClick: (event) => {
7
+ return (_jsx(CodeBlockBaseButton, { className: className, size: size, variant: "outlined", title: isWrapped ? "Disable code wrapping" : "Enable code wrapping", "aria-label": isWrapped ? "Disable code wrapping" : "Enable code wrapping", selected: isWrapped, disabled: !onToggle && !(editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock")), onClick: (event) => {
8
8
  event.preventDefault();
9
9
  event.stopPropagation();
10
10
  if (onToggle) {
@@ -6,6 +6,7 @@ export declare enum SlashCommands {
6
6
  Heading4 = "Heading 4",
7
7
  BulletList = "Bullet List",
8
8
  NumberedList = "Numbered List",
9
+ Code = "Code",
9
10
  CodeBlock = "Code Block",
10
11
  CurrentDate = "Current Date",
11
12
  CurrentTimestamp = "Current Timestamp",
@@ -7,6 +7,7 @@ export var SlashCommands;
7
7
  SlashCommands["Heading4"] = "Heading 4";
8
8
  SlashCommands["BulletList"] = "Bullet List";
9
9
  SlashCommands["NumberedList"] = "Numbered List";
10
+ SlashCommands["Code"] = "Code";
10
11
  SlashCommands["CodeBlock"] = "Code Block";
11
12
  SlashCommands["CurrentDate"] = "Current Date";
12
13
  SlashCommands["CurrentTimestamp"] = "Current Timestamp";
@@ -62,7 +62,6 @@ const CommandDescription = styled.div `
62
62
  color: ${({ theme }) => theme.palette.text.secondary};
63
63
  text-overflow: ellipsis;
64
64
  overflow: hidden;
65
- white-space: nowrap;
66
65
  `;
67
66
  const updateScrollView = (container, item) => {
68
67
  const containerHeight = container.offsetHeight;
@@ -11,7 +11,7 @@ import { Extension } from "@tiptap/core";
11
11
  import Suggestion from "@tiptap/suggestion";
12
12
  import { ReactRenderer } from "@tiptap/react";
13
13
  import tippy from "tippy.js";
14
- import { Heading1, Heading2, Heading3, Heading4, List, ListOrdered, Text, Image as ImageIcon, Calendar, ClockIcon, SquareCodeIcon, } from "lucide-react";
14
+ import { Heading1, Heading2, Heading3, Heading4, List, ListOrdered, Text, Image as ImageIcon, Calendar, CodeIcon, ClockIcon, SquareCodeIcon, } from "lucide-react";
15
15
  import { startImageUpload, } from "../Plugins/UploadImagesPlugin.js";
16
16
  import { PluginKey } from "@tiptap/pm/state";
17
17
  import SlashCommandList from "./SlashCommandList";
@@ -116,6 +116,15 @@ const getCommandItems = (values, options) => {
116
116
  editor.chain().focus().deleteRange(range).toggleOrderedList().run();
117
117
  },
118
118
  },
119
+ {
120
+ title: SlashCommands.Code,
121
+ description: "Start typing inline code.",
122
+ searchTerms: ["inline", "monospace"],
123
+ icon: CodeIcon,
124
+ command: ({ editor, range }) => {
125
+ editor.chain().focus().deleteRange(range).setCode().run();
126
+ },
127
+ },
119
128
  {
120
129
  title: SlashCommands.CodeBlock,
121
130
  description: "Create a syntax-highlighted code block.",
@@ -1,4 +1,3 @@
1
- import "highlight.js/styles/github-dark.css";
2
1
  import { Editor } from "@tiptap/react";
3
2
  import { ExtensionPreset, ExtensionType } from "./Extensions/getTiptapExtensions";
4
3
  import { HandleImageUrlUpload, HandleImageUpload } from "./Plugins/UploadImagesPlugin";
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
12
12
  import styled from "styled-components";
13
- import "highlight.js/styles/github-dark.css";
14
13
  import { EditorContent, useEditor } from "@tiptap/react";
15
14
  import { BubbleMenu as TiptapBubbleMenu, } from "@tiptap/react/menus";
16
15
  import { isTextSelection } from "@tiptap/core";
@@ -25,6 +24,61 @@ import BubbleMenuContent from "./Components/BubbleMenu";
25
24
  import Fonts from "./Enums/Fonts";
26
25
  import RichTextEditorContext from "./Contexts/RichTextEditorContext";
27
26
  import { getLinkAttributesAtPosition, getLinkRangeAtPosition, openLink, } from "./Utils/linkUtils";
27
+ const codeBlockFallbacks = {
28
+ light: {
29
+ background: "#f6f8fa",
30
+ text: "#24292f",
31
+ border: "#d0d7de",
32
+ selection: "#0969da2e",
33
+ syntax: {
34
+ comment: "#6e7781",
35
+ punctuation: "#24292f",
36
+ property: "#0550ae",
37
+ selector: "#116329",
38
+ operator: "#cf222e",
39
+ keyword: "#cf222e",
40
+ string: "#0a3069",
41
+ number: "#0550ae",
42
+ function: "#8250df",
43
+ variable: "#953800",
44
+ tag: "#116329",
45
+ attribute: "#0550ae",
46
+ literal: "#0550ae",
47
+ deleted: "#82071e",
48
+ inserted: "#116329",
49
+ },
50
+ },
51
+ dark: {
52
+ background: "#0d1117",
53
+ text: "#c9d1d9",
54
+ border: "#30363d",
55
+ selection: "#1f6feb40",
56
+ syntax: {
57
+ comment: "#8b949e",
58
+ punctuation: "#c9d1d9",
59
+ property: "#79c0ff",
60
+ selector: "#7ee787",
61
+ operator: "#ff7b72",
62
+ keyword: "#ff7b72",
63
+ string: "#a5d6ff",
64
+ number: "#79c0ff",
65
+ function: "#d2a8ff",
66
+ variable: "#ffa657",
67
+ tag: "#7ee787",
68
+ attribute: "#79c0ff",
69
+ literal: "#79c0ff",
70
+ deleted: "#ffa198",
71
+ inserted: "#aff5b4",
72
+ },
73
+ },
74
+ };
75
+ const getCodeBlockTheme = (theme) => {
76
+ if (theme.palette.codeBlock)
77
+ return theme.palette.codeBlock;
78
+ return theme.palette.mode === "DARK"
79
+ ? codeBlockFallbacks.dark
80
+ : codeBlockFallbacks.light;
81
+ };
28
82
  const getImageFilesFromClipboard = (clipboardData) => {
29
83
  return Array.from(clipboardData.files).filter((file) => file.type.includes("image/"));
30
84
  };
@@ -339,12 +393,12 @@ const StyledContent = styled.div `
339
393
  .editor-code-block {
340
394
  position: relative;
341
395
  margin: 0.5rem 0;
342
- padding: 0.875rem 1rem;
396
+ padding: 1rem 0.875rem;
343
397
  overflow-x: auto;
344
- border: 1px solid #30363d;
398
+ border: 1px solid ${({ theme }) => getCodeBlockTheme(theme).border};
345
399
  border-radius: 6px;
346
- background-color: #0d1117;
347
- color: #c9d1d9;
400
+ background-color: ${({ theme }) => getCodeBlockTheme(theme).background};
401
+ color: ${({ theme }) => getCodeBlockTheme(theme).text};
348
402
  font-family:
349
403
  ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Monaco, Consolas,
350
404
  "Liberation Mono", "Courier New", monospace;
@@ -352,6 +406,10 @@ const StyledContent = styled.div `
352
406
  line-height: 1.45rem;
353
407
  white-space: pre;
354
408
 
409
+ ::selection {
410
+ background-color: ${({ theme }) => getCodeBlockTheme(theme).selection};
411
+ }
412
+
355
413
  &[data-wrap="true"] {
356
414
  white-space: pre-wrap;
357
415
  word-break: break-word;
@@ -375,6 +433,7 @@ const StyledContent = styled.div `
375
433
 
376
434
  .editor-code-block-actions {
377
435
  display: flex;
436
+ align-items: center;
378
437
  position: absolute;
379
438
  top: 0.4rem;
380
439
  right: 0.4rem;
@@ -384,16 +443,91 @@ const StyledContent = styled.div `
384
443
  transition: opacity 120ms ease-in-out;
385
444
  }
386
445
 
387
- .editor-code-block-action {
388
- background-color: #161b22;
389
- color: #c9d1d9;
390
- border-color: #30363d;
391
- }
392
-
393
446
  &:hover .editor-code-block-actions,
394
447
  &:focus-within .editor-code-block-actions {
395
448
  opacity: 1;
396
449
  }
450
+
451
+ .hljs-comment,
452
+ .hljs-quote {
453
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.comment};
454
+ }
455
+
456
+ .hljs-punctuation {
457
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.punctuation};
458
+ }
459
+
460
+ .hljs-property,
461
+ .hljs-attr,
462
+ .hljs-attribute,
463
+ .hljs-doctag {
464
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.property};
465
+ }
466
+
467
+ .hljs-selector-tag,
468
+ .hljs-selector-id,
469
+ .hljs-selector-class,
470
+ .hljs-selector-attr,
471
+ .hljs-selector-pseudo {
472
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.selector};
473
+ }
474
+
475
+ .hljs-operator,
476
+ .hljs-params {
477
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.operator};
478
+ }
479
+
480
+ .hljs-keyword,
481
+ .hljs-meta .hljs-keyword,
482
+ .hljs-template-tag,
483
+ .hljs-template-variable {
484
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.keyword};
485
+ }
486
+
487
+ .hljs-string,
488
+ .hljs-regexp {
489
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.string};
490
+ }
491
+
492
+ .hljs-number {
493
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.number};
494
+ }
495
+
496
+ .hljs-title,
497
+ .hljs-title.function_,
498
+ .hljs-title.class_ {
499
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.function};
500
+ }
501
+
502
+ .hljs-variable,
503
+ .hljs-name,
504
+ .hljs-section,
505
+ .hljs-symbol {
506
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.variable};
507
+ }
508
+
509
+ .hljs-tag {
510
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.tag};
511
+ }
512
+
513
+ .hljs-built_in,
514
+ .hljs-type,
515
+ .hljs-literal {
516
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.literal};
517
+ }
518
+
519
+ .hljs-meta,
520
+ .hljs-link {
521
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.attribute};
522
+ }
523
+
524
+ .hljs-deletion {
525
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.deleted};
526
+ }
527
+
528
+ .hljs-addition {
529
+ color: ${({ theme }) => getCodeBlockTheme(theme).syntax.inserted};
530
+ }
397
531
  }
398
532
  ul {
399
533
  margin: 0;
@@ -627,6 +761,9 @@ export const RichTextEditor = ({ className, editorInstanceRef, defaultValue = ""
627
761
  }), [disabledExtensions, extensionPreset, extensions]);
628
762
  const resolvedExtensionSet = useMemo(() => new Set(resolvedExtensions), [resolvedExtensions]);
629
763
  const resolvedSlashCommands = useMemo(() => slashCommands.filter((command) => {
764
+ if (command === SlashCommands.Code) {
765
+ return resolvedExtensionSet.has(Extensions.Code);
766
+ }
630
767
  if (command === SlashCommands.CodeBlock) {
631
768
  return resolvedExtensionSet.has(Extensions.CodeBlock);
632
769
  }
@@ -12,7 +12,6 @@ import { Popover } from "../../Popover";
12
12
  import TextColors from "../Enums/TextColors";
13
13
  import HighlightColors from "../Enums/HighlightColors";
14
14
  import LinkEditor from "../Components/LinkEditor";
15
- import CodeBlockLanguageSelect from "../Components/CodeBlockLanguageSelect";
16
15
  import CodeBlockWrapButton from "../Components/CodeBlockWrapButton";
17
16
  import CodeBlockFormatButton from "../Components/CodeBlockFormatButton";
18
17
  import { hasSyntaxHighlightedCodeBlock } from "../Utils/codeBlockUtils";
@@ -117,7 +116,7 @@ export const Toolbar = styled(({ className, editor, toolbarOptions }) => {
117
116
  height: 210,
118
117
  },
119
118
  }, children: _jsx(HighlighterIcon, { size: 14 }) })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.LINK)) && (_jsxs(Popover, { opened: linkPopoverOpen, onChange: setLinkPopoverOpen, position: "bottom", width: 330, trapFocus: true, children: [_jsx(Popover.Target, { children: _jsx(Button, { size: "xs", variant: "outlined", title: "Link", "aria-label": "Link", selected: linkPopoverOpen || Boolean(editor === null || editor === void 0 ? void 0 : editor.isActive("link")), disabled: !editor, style: { padding: "1px 6px" }, children: _jsx(LinkIcon, { size: 14 }) }) }), _jsx(Popover.Dropdown, { children: editor && (_jsx(LinkEditor, { editor: editor, autoFocus: linkPopoverOpen, onClose: () => setLinkPopoverOpen(false) })) })] })), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.BOLD)) && _jsx(BoldControl, { editor: editor }), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.ITALIC)) && (_jsx(ItalicControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.UNDERLINE)) && (_jsx(UnderlineControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.STRIKE)) && (_jsx(StrikeThroughControl, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.CODE)) && _jsx(CodeControl, { editor: editor }), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.CODE_BLOCK)) && (_jsx(CodeBlockControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.CODE_BLOCK)) &&
120
- showCodeBlockLanguageSelect && (_jsxs(_Fragment, { children: [_jsx(CodeBlockLanguageSelect, { editor: editor }), _jsx(CodeBlockWrapButton, { editor: editor }), _jsx(CodeBlockFormatButton, { editor: editor })] }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_1)) && (_jsx(Heading1Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_2)) && (_jsx(Heading2Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_3)) && (_jsx(Heading3Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_4)) && (_jsx(Heading4Control, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.BULLET_LIST)) && (_jsx(BulletListControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.ORDERED_LIST)) && (_jsx(OrderedListControl, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_LEFT)) && (_jsx(AlignLeftControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_CENTER)) && (_jsx(AlignCenterControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_RIGHT)) && (_jsx(AlignRightControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_JUSTIFIED)) && (_jsx(AlignJustifiedControl, { editor: editor }))] })] }));
119
+ showCodeBlockLanguageSelect && (_jsxs(_Fragment, { children: [_jsx(CodeBlockWrapButton, { editor: editor }), _jsx(CodeBlockFormatButton, { editor: editor })] }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_1)) && (_jsx(Heading1Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_2)) && (_jsx(Heading2Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_3)) && (_jsx(Heading3Control, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.HEADING_4)) && (_jsx(Heading4Control, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.BULLET_LIST)) && (_jsx(BulletListControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.ORDERED_LIST)) && (_jsx(OrderedListControl, { editor: editor }))] }), _jsxs(ControlsGroup, { children: [(controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_LEFT)) && (_jsx(AlignLeftControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_CENTER)) && (_jsx(AlignCenterControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_RIGHT)) && (_jsx(AlignRightControl, { editor: editor })), (controls === null || controls === void 0 ? void 0 : controls.includes(Controls.TEXT_ALIGN_JUSTIFIED)) && (_jsx(AlignJustifiedControl, { editor: editor }))] })] }));
121
120
  }) `
122
121
  display: flex;
123
122
  flex-direction: row;
@@ -122,6 +122,29 @@ const lightVariant = {
122
122
  action: {
123
123
  hover: "rgba(0, 0, 0, 0.1)",
124
124
  },
125
+ codeBlock: {
126
+ background: "#f6f8fa",
127
+ text: "#24292f",
128
+ border: "#d0d7de",
129
+ selection: "#0969da2e",
130
+ syntax: {
131
+ comment: "#6e7781",
132
+ punctuation: "#24292f",
133
+ property: "#0550ae",
134
+ selector: "#116329",
135
+ operator: "#cf222e",
136
+ keyword: "#cf222e",
137
+ string: "#0a3069",
138
+ number: "#0550ae",
139
+ function: "#8250df",
140
+ variable: "#953800",
141
+ tag: "#116329",
142
+ attribute: "#0550ae",
143
+ literal: "#0550ae",
144
+ deleted: "#82071e",
145
+ inserted: "#116329",
146
+ },
147
+ },
125
148
  divider: "rgba(0, 0, 0, 0.3)",
126
149
  },
127
150
  header: {
@@ -282,6 +305,29 @@ const darkVariant = merge(lightVariant, {
282
305
  dataGrid: {
283
306
  hover: "#2f2f2f",
284
307
  },
308
+ codeBlock: {
309
+ background: "#191919",
310
+ text: "#c9d1d9",
311
+ border: "rgba(255, 255, 255, 0.15)",
312
+ selection: "#1f6feb40",
313
+ syntax: {
314
+ comment: "#8b949e",
315
+ punctuation: "#c9d1d9",
316
+ property: "#79c0ff",
317
+ selector: "#7ee787",
318
+ operator: "#ff7b72",
319
+ keyword: "#ff7b72",
320
+ string: "#a5d6ff",
321
+ number: "#79c0ff",
322
+ function: "#d2a8ff",
323
+ variable: "#ffa657",
324
+ tag: "#7ee787",
325
+ attribute: "#79c0ff",
326
+ literal: "#79c0ff",
327
+ deleted: "#ffa198",
328
+ inserted: "#aff5b4",
329
+ },
330
+ },
285
331
  },
286
332
  header: {
287
333
  color: grey[300],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.9.1-dev.10",
3
+ "version": "1.9.1-dev.11",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",