@blocklet/editor 2.2.47 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.d.ts +2 -2
  2. package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.js +3 -3
  3. package/lib/main/editor.js +3 -7
  4. package/lib/main/index.css +16 -18
  5. package/lib/main/markdown-editor/editor.js +1 -1
  6. package/lib/main/markdown-editor/transformers.js +7 -6
  7. package/lib/main/nodes/EmojiNode.d.ts +1 -2
  8. package/lib/main/nodes/EmojiNode.js +4 -9
  9. package/lib/main/nodes/EquationNode.js +14 -7
  10. package/lib/main/nodes/ImageComponent.js +2 -2
  11. package/lib/main/nodes/PlaygroundNodes.js +0 -2
  12. package/lib/main/nodes/StickyComponent.js +1 -1
  13. package/lib/main/plugins/CodeActionMenuPlugin/index.js +24 -28
  14. package/lib/main/plugins/MarkdownTransformers/index.d.ts +1 -4
  15. package/lib/main/plugins/MarkdownTransformers/index.js +48 -79
  16. package/lib/main/plugins/TableActionMenuPlugin/index.js +229 -171
  17. package/lib/main/plugins/TableCellResizer/index.css +8 -2
  18. package/lib/main/plugins/TableCellResizer/index.js +168 -120
  19. package/lib/main/plugins/TableOfContentsPlugin/index.js +2 -2
  20. package/lib/main/plugins/TablePlugin.d.ts +3 -4
  21. package/lib/main/plugins/TablePlugin.js +7 -24
  22. package/lib/main/plugins/ToolbarPlugin/index.js +0 -1
  23. package/lib/main/themes/defaultTheme.js +3 -1
  24. package/lib/main/ui/ContentEditable.d.ts +1 -4
  25. package/lib/main/ui/Modal.css +1 -1
  26. package/lib/main/ui/TextInput.d.ts +4 -3
  27. package/lib/main/ui/TextInput.js +3 -19
  28. package/package.json +20 -21
  29. package/lib/main/nodes/AutocompleteNode.d.ts +0 -34
  30. package/lib/main/nodes/AutocompleteNode.js +0 -52
  31. package/lib/main/nodes/EquationComponent.d.ts +0 -16
  32. package/lib/main/nodes/EquationComponent.js +0 -64
  33. package/lib/main/plugins/ActionsPlugin/index.d.ts +0 -11
  34. package/lib/main/plugins/ActionsPlugin/index.js +0 -129
  35. package/lib/main/plugins/AutocompletePlugin/index.d.ts +0 -10
  36. package/lib/main/plugins/AutocompletePlugin/index.js +0 -2461
  37. package/lib/main/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +0 -14
  38. package/lib/main/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +0 -17
  39. package/lib/main/plugins/CodeActionMenuPlugin/components/PrettierButton/index.js +0 -95
  40. package/lib/main/plugins/EquationsPlugin/index.d.ts +0 -21
  41. package/lib/main/plugins/EquationsPlugin/index.js +0 -42
  42. package/lib/main/plugins/SpeechToTextPlugin/index.d.ts +0 -12
  43. package/lib/main/plugins/SpeechToTextPlugin/index.js +0 -87
  44. package/lib/main/ui/EquationEditor.css +0 -38
  45. package/lib/main/ui/EquationEditor.d.ts +0 -19
  46. package/lib/main/ui/EquationEditor.js +0 -26
  47. package/lib/main/ui/KatexEquationAlterer.css +0 -41
  48. package/lib/main/ui/KatexEquationAlterer.d.ts +0 -15
  49. package/lib/main/ui/KatexEquationAlterer.js +0 -34
  50. package/lib/main/ui/KatexRenderer.d.ts +0 -13
  51. package/lib/main/ui/KatexRenderer.js +0 -33
@@ -1,14 +0,0 @@
1
- .code-action-menu-container .prettier-wrapper {
2
- position: relative;
3
- }
4
-
5
- .code-action-menu-container .prettier-wrapper .code-error-tips {
6
- padding: 5px;
7
- border-radius: 4px;
8
- color: #fff;
9
- background: #222;
10
- margin-top: 4px;
11
- position: absolute;
12
- top: 26px;
13
- right: 0;
14
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import './index.css';
9
- import { LexicalEditor } from 'lexical';
10
- interface Props {
11
- lang: string;
12
- editor: LexicalEditor;
13
- getCodeDOMNode: () => HTMLElement | null;
14
- }
15
- export declare function canBePrettier(lang: string): boolean;
16
- export declare function PrettierButton({ lang, editor, getCodeDOMNode }: Props): import("react/jsx-runtime").JSX.Element;
17
- export {};
@@ -1,95 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import './index.css';
10
- import { $isCodeNode } from '@lexical/code';
11
- import { $getNearestNodeFromDOMNode } from 'lexical';
12
- // import { Options } from 'prettier';
13
- // import * as babelParser from 'prettier/parser-babel';
14
- // import * as htmlParser from 'prettier/parser-html';
15
- // import * as markdownParser from 'prettier/parser-markdown';
16
- // import * as cssParser from 'prettier/parser-postcss';
17
- // import { format } from 'prettier/standalone';
18
- import { useState } from 'react';
19
- const PRETTIER_OPTIONS_BY_LANG = {
20
- css: {
21
- parser: 'css',
22
- // plugins: [cssParser],
23
- },
24
- html: {
25
- parser: 'html',
26
- // plugins: [htmlParser],
27
- },
28
- js: {
29
- parser: 'babel',
30
- // plugins: [babelParser],
31
- },
32
- markdown: {
33
- parser: 'markdown',
34
- // plugins: [markdownParser],
35
- },
36
- };
37
- const LANG_CAN_BE_PRETTIER = Object.keys(PRETTIER_OPTIONS_BY_LANG);
38
- export function canBePrettier(lang) {
39
- return LANG_CAN_BE_PRETTIER.includes(lang);
40
- }
41
- function getPrettierOptions(lang) {
42
- const options = PRETTIER_OPTIONS_BY_LANG[lang];
43
- if (!options) {
44
- throw new Error(`CodeActionMenuPlugin: Prettier does not support this language: ${lang}`);
45
- }
46
- return options;
47
- }
48
- export function PrettierButton({ lang, editor, getCodeDOMNode }) {
49
- const [syntaxError, setSyntaxError] = useState('');
50
- const [tipsVisible, setTipsVisible] = useState(false);
51
- // eslint-disable-next-line require-await
52
- async function handleClick() {
53
- const codeDOMNode = getCodeDOMNode();
54
- if (!codeDOMNode) {
55
- return;
56
- }
57
- editor.update(() => {
58
- const codeNode = $getNearestNodeFromDOMNode(codeDOMNode);
59
- if ($isCodeNode(codeNode)) {
60
- const content = codeNode.getTextContent();
61
- const options = getPrettierOptions(lang);
62
- const parsed = '';
63
- try {
64
- // parsed = format(content, options);
65
- }
66
- catch (error) {
67
- if (error instanceof Error) {
68
- setSyntaxError(error.message);
69
- setTipsVisible(true);
70
- }
71
- else {
72
- console.error('Unexpected error: ', error);
73
- }
74
- }
75
- if (parsed !== '') {
76
- const selection = codeNode.select(0);
77
- selection.insertText(parsed);
78
- setSyntaxError('');
79
- setTipsVisible(false);
80
- }
81
- }
82
- });
83
- }
84
- function handleMouseEnter() {
85
- if (syntaxError !== '') {
86
- setTipsVisible(true);
87
- }
88
- }
89
- function handleMouseLeave() {
90
- if (syntaxError !== '') {
91
- setTipsVisible(false);
92
- }
93
- }
94
- return (_jsxs("div", { className: "prettier-wrapper", children: [_jsx("button", { className: "menu-item", onClick: handleClick, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, "aria-label": "prettier", children: syntaxError ? _jsx("i", { className: "format prettier-error" }) : _jsx("i", { className: "format prettier" }) }), tipsVisible ? _jsx("pre", { className: "code-error-tips", children: syntaxError }) : null] }));
95
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- /// <reference types="react" />
9
- import 'katex/dist/katex.css';
10
- import { LexicalCommand, LexicalEditor } from 'lexical';
11
- type CommandPayload = {
12
- equation: string;
13
- inline: boolean;
14
- };
15
- export declare const INSERT_EQUATION_COMMAND: LexicalCommand<CommandPayload>;
16
- export declare function InsertEquationDialog({ activeEditor, onClose, }: {
17
- activeEditor: LexicalEditor;
18
- onClose: () => void;
19
- }): JSX.Element;
20
- export default function EquationsPlugin(): JSX.Element | null;
21
- export {};
@@ -1,42 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import 'katex/dist/katex.css';
10
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
11
- import { $wrapNodeInElement } from '@lexical/utils';
12
- import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR, createCommand, } from 'lexical';
13
- import { useCallback, useEffect } from 'react';
14
- import { lazyRetry as lazy } from '@arcblock/ux/lib/Util';
15
- import { $createEquationNode, EquationNode } from '../../nodes/EquationNode';
16
- const KatexEquationAlterer = lazy(() => import('../../ui/KatexEquationAlterer'));
17
- export const INSERT_EQUATION_COMMAND = createCommand('INSERT_EQUATION_COMMAND');
18
- export function InsertEquationDialog({ activeEditor, onClose, }) {
19
- const onEquationConfirm = useCallback((equation, inline) => {
20
- activeEditor.dispatchCommand(INSERT_EQUATION_COMMAND, { equation, inline });
21
- onClose();
22
- }, [activeEditor, onClose]);
23
- return _jsx(KatexEquationAlterer, { onConfirm: onEquationConfirm });
24
- }
25
- export default function EquationsPlugin() {
26
- const [editor] = useLexicalComposerContext();
27
- useEffect(() => {
28
- if (!editor.hasNodes([EquationNode])) {
29
- throw new Error('EquationsPlugins: EquationsNode not registered on editor');
30
- }
31
- return editor.registerCommand(INSERT_EQUATION_COMMAND, (payload) => {
32
- const { equation, inline } = payload;
33
- const equationNode = $createEquationNode(equation, inline);
34
- $insertNodes([equationNode]);
35
- if ($isRootOrShadowRoot(equationNode.getParentOrThrow())) {
36
- $wrapNodeInElement(equationNode, $createParagraphNode).selectEnd();
37
- }
38
- return true;
39
- }, COMMAND_PRIORITY_EDITOR);
40
- }, [editor]);
41
- return null;
42
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import type { LexicalCommand } from 'lexical';
9
- export declare const SPEECH_TO_TEXT_COMMAND: LexicalCommand<boolean>;
10
- export declare const SUPPORT_SPEECH_RECOGNITION: boolean;
11
- declare const _default: () => null;
12
- export default _default;
@@ -1,87 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
- import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand, REDO_COMMAND, UNDO_COMMAND, } from 'lexical';
10
- import { useEffect, useRef, useState } from 'react';
11
- import useReport from '../../hooks/useReport';
12
- export const SPEECH_TO_TEXT_COMMAND = createCommand('SPEECH_TO_TEXT_COMMAND');
13
- const VOICE_COMMANDS = {
14
- '\n': ({ selection }) => {
15
- selection.insertParagraph();
16
- },
17
- redo: ({ editor }) => {
18
- editor.dispatchCommand(REDO_COMMAND, undefined);
19
- },
20
- undo: ({ editor }) => {
21
- editor.dispatchCommand(UNDO_COMMAND, undefined);
22
- },
23
- };
24
- export const SUPPORT_SPEECH_RECOGNITION = 'SpeechRecognition' in window || 'webkitSpeechRecognition' in window;
25
- function SpeechToTextPlugin() {
26
- const [editor] = useLexicalComposerContext();
27
- const [isEnabled, setIsEnabled] = useState(false);
28
- const SpeechRecognition =
29
- // @ts-ignore
30
- window.SpeechRecognition || window.webkitSpeechRecognition;
31
- const recognition = useRef(null);
32
- const report = useReport();
33
- useEffect(() => {
34
- if (isEnabled && recognition.current === null) {
35
- recognition.current = new SpeechRecognition();
36
- recognition.current.continuous = true;
37
- recognition.current.interimResults = true;
38
- recognition.current.addEventListener('result', (event) => {
39
- const resultItem = event.results.item(event.resultIndex);
40
- const { transcript } = resultItem.item(0);
41
- report(transcript);
42
- if (!resultItem.isFinal) {
43
- return;
44
- }
45
- editor.update(() => {
46
- const selection = $getSelection();
47
- if ($isRangeSelection(selection)) {
48
- const command = VOICE_COMMANDS[transcript.toLowerCase().trim()];
49
- if (command) {
50
- command({
51
- editor,
52
- selection,
53
- });
54
- }
55
- else if (transcript.match(/\s*\n\s*/)) {
56
- selection.insertParagraph();
57
- }
58
- else {
59
- selection.insertText(transcript);
60
- }
61
- }
62
- });
63
- });
64
- }
65
- if (recognition.current) {
66
- if (isEnabled) {
67
- recognition.current.start();
68
- }
69
- else {
70
- recognition.current.stop();
71
- }
72
- }
73
- return () => {
74
- if (recognition.current !== null) {
75
- recognition.current.stop();
76
- }
77
- };
78
- }, [SpeechRecognition, editor, isEnabled, report]);
79
- useEffect(() => {
80
- return editor.registerCommand(SPEECH_TO_TEXT_COMMAND, (_isEnabled) => {
81
- setIsEnabled(_isEnabled);
82
- return true;
83
- }, COMMAND_PRIORITY_EDITOR);
84
- }, [editor]);
85
- return null;
86
- }
87
- export default (SUPPORT_SPEECH_RECOGNITION ? SpeechToTextPlugin : () => null);
@@ -1,38 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- */
9
-
10
- .EquationEditor_inlineEditor {
11
- padding: 0;
12
- margin: 0;
13
- border: 0;
14
- outline: 0;
15
- color: #8421a2;
16
- background-color: inherit;
17
- resize: none;
18
- }
19
-
20
- .EquationEditor_blockEditor {
21
- padding: 0;
22
- margin: 0;
23
- border: 0;
24
- outline: 0;
25
- color: #8421a2;
26
- background-color: inherit;
27
- resize: none;
28
- width: '100%';
29
- }
30
-
31
- .EquationEditor_inputBackground {
32
- background-color: #eee;
33
- }
34
-
35
- .EquationEditor_dollarSign {
36
- text-align: left;
37
- color: #b0b0b0;
38
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- /// <reference types="react" />
9
- import './EquationEditor.css';
10
- type BaseEquationEditorProps = {
11
- equation: string;
12
- inline: boolean;
13
- inputRef: {
14
- current: null | HTMLInputElement | HTMLTextAreaElement;
15
- };
16
- setEquation: (equation: string) => void;
17
- };
18
- export default function EquationEditor({ equation, setEquation, inline, inputRef, }: BaseEquationEditorProps): JSX.Element;
19
- export {};
@@ -1,26 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import './EquationEditor.css';
10
- export default function EquationEditor({ equation, setEquation, inline, inputRef, }) {
11
- const onChange = (event) => {
12
- setEquation(event.target.value);
13
- };
14
- const props = {
15
- equation,
16
- inputRef,
17
- onChange,
18
- };
19
- return inline ? (_jsx(InlineEquationEditor, { ...props, inputRef: inputRef })) : (_jsx(BlockEquationEditor, { ...props, inputRef: inputRef }));
20
- }
21
- function InlineEquationEditor({ equation, onChange, inputRef }) {
22
- return (_jsxs("span", { className: "EquationEditor_inputBackground", children: [_jsx("span", { className: "EquationEditor_dollarSign", children: "$" }), _jsx("input", { className: "EquationEditor_inlineEditor", value: equation, onChange: onChange, autoFocus: true, ref: inputRef }), _jsx("span", { className: "EquationEditor_dollarSign", children: "$" })] }));
23
- }
24
- function BlockEquationEditor({ equation, onChange, inputRef }) {
25
- return (_jsxs("div", { className: "EquationEditor_inputBackground", children: [_jsx("span", { className: "EquationEditor_dollarSign", children: '$$\n' }), _jsx("textarea", { className: "EquationEditor_blockEditor", value: equation, onChange: onChange, ref: inputRef }), _jsx("span", { className: "EquationEditor_dollarSign", children: '\n$$' })] }));
26
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- */
9
-
10
- .KatexEquationAlterer_defaultRow {
11
- display: flex;
12
- flex-direction: row;
13
- margin-top: 10px;
14
- margin-bottom: 10px;
15
- justify-content: space-between;
16
- overflow: hidden;
17
- }
18
-
19
- .KatexEquationAlterer_dialogActions {
20
- display: flex;
21
- flex-direction: row;
22
- overflow: hidden;
23
- margin-top: 20px;
24
- margin-bottom: 0;
25
- justify-content: right;
26
- }
27
-
28
- .KatexEquationAlterer_centerRow {
29
- display: flex;
30
- flex-direction: 'row';
31
- margin-top: 10px;
32
- margin-bottom: 10px;
33
- justify-content: center;
34
- overflow: hidden;
35
- }
36
-
37
- .KatexEquationAlterer_textArea {
38
- width: 100%;
39
- resize: none;
40
- padding: 7px;
41
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- /// <reference types="react" />
9
- import './KatexEquationAlterer.css';
10
- type Props = {
11
- initialEquation?: string;
12
- onConfirm: (equation: string, inline: boolean) => void;
13
- };
14
- export default function KatexEquationAlterer({ onConfirm, initialEquation }: Props): JSX.Element;
15
- export {};
@@ -1,34 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import './KatexEquationAlterer.css';
10
- import { useCallback, useEffect, useRef, useState } from 'react';
11
- import { lazyRetry as lazy } from '@arcblock/ux/lib/Util';
12
- import Button from './Button';
13
- const KatexRenderer = lazy(() => import('./KatexRenderer'));
14
- export default function KatexEquationAlterer({ onConfirm, initialEquation = '' }) {
15
- const [equation, setEquation] = useState(initialEquation);
16
- const [inline, setInline] = useState(true);
17
- const onClick = useCallback(() => {
18
- onConfirm(equation, inline);
19
- }, [onConfirm, equation, inline]);
20
- const onCheckboxChange = useCallback(() => {
21
- setInline(!inline);
22
- }, [setInline, inline]);
23
- const input = useRef(null);
24
- useEffect(() => {
25
- setTimeout(() => {
26
- input.current?.focus();
27
- });
28
- }, []);
29
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "KatexEquationAlterer_defaultRow", children: ["Inline", _jsx("input", { type: "checkbox", checked: inline, onChange: onCheckboxChange })] }), _jsx("div", { className: "KatexEquationAlterer_defaultRow", children: "Equation " }), _jsx("div", { className: "KatexEquationAlterer_centerRow", children: inline ? (_jsx("input", { ref: input, onChange: (event) => {
30
- setEquation(event.target.value);
31
- }, value: equation, className: "KatexEquationAlterer_textArea" })) : (_jsx("textarea", { ref: input, onChange: (event) => {
32
- setEquation(event.target.value);
33
- }, value: equation, className: "KatexEquationAlterer_textArea" })) }), _jsx("div", { className: "KatexEquationAlterer_defaultRow", children: "Visualization " }), _jsx("div", { className: "KatexEquationAlterer_centerRow", children: _jsx(KatexRenderer, { equation: equation, inline: false, onClick: () => null }) }), _jsx("div", { className: "KatexEquationAlterer_dialogActions", children: _jsx(Button, { onClick: onClick, children: "Confirm" }) })] }));
34
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- /// <reference types="react" />
9
- export default function KatexRenderer({ equation, inline, onClick, }: Readonly<{
10
- equation: string;
11
- inline: boolean;
12
- onClick: () => void;
13
- }>): JSX.Element;
@@ -1,33 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import { useEffect, useRef } from 'react';
10
- export default function KatexRenderer({ equation, inline, onClick, }) {
11
- const katexElementRef = useRef(null);
12
- useEffect(() => {
13
- const katexElement = katexElementRef.current;
14
- if (katexElement !== null) {
15
- import('katex').then(({ default: katex }) => {
16
- // @ts-ignore
17
- katex.render(equation, katexElement, {
18
- displayMode: !inline,
19
- errorColor: '#cc0000',
20
- output: 'html',
21
- strict: 'warn',
22
- throwOnError: false,
23
- trust: false,
24
- });
25
- });
26
- }
27
- }, [equation, inline]);
28
- return (
29
- // We use spacers either side to ensure Android doesn't try and compose from the
30
- // inner text from Katex. There didn't seem to be any other way of making this work,
31
- // without having a physical space.
32
- _jsxs(_Fragment, { children: [_jsx("span", { className: "spacer", children: " " }), _jsx("span", { role: "button", tabIndex: -1, onClick: onClick, ref: katexElementRef }), _jsx("span", { className: "spacer", children: " " })] }));
33
- }