@datalayer/jupyter-lexical 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/lib/components/InsertEquationDialog.d.ts +6 -0
- package/lib/components/InsertEquationDialog.js +17 -0
- package/lib/components/InsertEquationDialog.js.map +1 -0
- package/lib/components/InsertImageDialog.d.ts +13 -0
- package/lib/components/InsertImageDialog.js +48 -0
- package/lib/components/InsertImageDialog.js.map +1 -0
- package/lib/components/JupyterCellComponent.d.ts +2 -0
- package/lib/components/JupyterCellComponent.js +12 -0
- package/lib/components/JupyterCellComponent.js.map +1 -0
- package/lib/components/JupyterOutputComponent.d.ts +13 -0
- package/lib/components/JupyterOutputComponent.js +8 -0
- package/lib/components/JupyterOutputComponent.js.map +1 -0
- package/lib/convert/LexicalToNbFormat.d.ts +4 -0
- package/lib/convert/LexicalToNbFormat.js +100 -0
- package/lib/convert/LexicalToNbFormat.js.map +1 -0
- package/lib/convert/NbFormatToLexical.d.ts +4 -0
- package/lib/convert/NbFormatToLexical.js +31 -0
- package/lib/convert/NbFormatToLexical.js.map +1 -0
- package/lib/convert/markdown/MarkdownExport.d.ts +11 -0
- package/lib/convert/markdown/MarkdownExport.js +129 -0
- package/lib/convert/markdown/MarkdownExport.js.map +1 -0
- package/lib/convert/markdown/MarkdownImport.d.ts +2 -0
- package/lib/convert/markdown/MarkdownImport.js +246 -0
- package/lib/convert/markdown/MarkdownImport.js.map +1 -0
- package/lib/convert/markdown/MarkdownShortcuts.d.ts +10 -0
- package/lib/convert/markdown/MarkdownShortcuts.js +254 -0
- package/lib/convert/markdown/MarkdownShortcuts.js.map +1 -0
- package/lib/convert/markdown/MarkdownTransformers.d.ts +39 -0
- package/lib/convert/markdown/MarkdownTransformers.js +242 -0
- package/lib/convert/markdown/MarkdownTransformers.js.map +1 -0
- package/lib/convert/markdown/convertToMarkdown.d.ts +1 -0
- package/lib/convert/markdown/convertToMarkdown.js +126 -0
- package/lib/convert/markdown/convertToMarkdown.js.map +1 -0
- package/lib/convert/markdown/index.d.ts +17 -0
- package/lib/convert/markdown/index.js +46 -0
- package/lib/convert/markdown/index.js.map +1 -0
- package/lib/convert/markdown/utils.d.ts +24 -0
- package/lib/convert/markdown/utils.js +303 -0
- package/lib/convert/markdown/utils.js.map +1 -0
- package/lib/convert/transformers/MarkdownTransformers.d.ts +13 -0
- package/lib/convert/transformers/MarkdownTransformers.js +178 -0
- package/lib/convert/transformers/MarkdownTransformers.js.map +1 -0
- package/lib/examples/App.d.ts +1 -0
- package/lib/examples/App.js +22 -0
- package/lib/examples/App.js.map +1 -0
- package/lib/examples/Editor.d.ts +9 -0
- package/lib/examples/Editor.js +81 -0
- package/lib/examples/Editor.js.map +1 -0
- package/lib/examples/Example.d.ts +1 -0
- package/lib/examples/Example.js +11 -0
- package/lib/examples/Example.js.map +1 -0
- package/lib/examples/content/Example.ipynb.json +98 -0
- package/lib/examples/content/Example.lexical.json +259 -0
- package/lib/examples/context/LexicalContext.d.ts +13 -0
- package/lib/examples/context/LexicalContext.js +22 -0
- package/lib/examples/context/LexicalContext.js.map +1 -0
- package/lib/examples/plugins/ToolbarPlugin.d.ts +2 -0
- package/lib/examples/plugins/ToolbarPlugin.js +448 -0
- package/lib/examples/plugins/ToolbarPlugin.js.map +1 -0
- package/lib/examples/plugins/TreeViewPlugin.d.ts +2 -0
- package/lib/examples/plugins/TreeViewPlugin.js +13 -0
- package/lib/examples/plugins/TreeViewPlugin.js.map +1 -0
- package/lib/examples/themes/Theme.d.ts +10 -0
- package/lib/examples/themes/Theme.js +94 -0
- package/lib/examples/themes/Theme.js.map +1 -0
- package/lib/hooks/useModal.d.ts +2 -0
- package/lib/hooks/useModal.js +39 -0
- package/lib/hooks/useModal.js.map +1 -0
- package/lib/images/yellow-flower-small.jpg +0 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +55 -0
- package/lib/index.js.map +1 -0
- package/lib/jupyter/index.d.ts +0 -0
- package/lib/jupyter/index.js +6 -0
- package/lib/jupyter/index.js.map +1 -0
- package/lib/jupyter/lab/Example.d.ts +1 -0
- package/lib/jupyter/lab/Example.js +11 -0
- package/lib/jupyter/lab/Example.js.map +1 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.d.ts +0 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.js +11 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.js.map +1 -0
- package/lib/jupyter/lab/component/MockComponent.d.ts +2 -0
- package/lib/jupyter/lab/component/MockComponent.js +17 -0
- package/lib/jupyter/lab/component/MockComponent.js.map +1 -0
- package/lib/jupyter/lab/component/MockTab1.d.ts +2 -0
- package/lib/jupyter/lab/component/MockTab1.js +14 -0
- package/lib/jupyter/lab/component/MockTab1.js.map +1 -0
- package/lib/jupyter/lab/handler.d.ts +8 -0
- package/lib/jupyter/lab/handler.js +41 -0
- package/lib/jupyter/lab/handler.js.map +1 -0
- package/lib/jupyter/lab/index.d.ts +7 -0
- package/lib/jupyter/lab/index.js +73 -0
- package/lib/jupyter/lab/index.js.map +1 -0
- package/lib/jupyter/lab/widget.d.ts +6 -0
- package/lib/jupyter/lab/widget.js +18 -0
- package/lib/jupyter/lab/widget.js.map +1 -0
- package/lib/nodes/EquationNode.d.ts +31 -0
- package/lib/nodes/EquationNode.js +118 -0
- package/lib/nodes/EquationNode.js.map +1 -0
- package/lib/nodes/ImageNode.css +50 -0
- package/lib/nodes/ImageNode.d.ts +58 -0
- package/lib/nodes/ImageNode.js +275 -0
- package/lib/nodes/ImageNode.js.map +1 -0
- package/lib/nodes/JupyterCodeHighlightNode.d.ts +49 -0
- package/lib/nodes/JupyterCodeHighlightNode.js +165 -0
- package/lib/nodes/JupyterCodeHighlightNode.js.map +1 -0
- package/lib/nodes/JupyterCodeHighlighter.d.ts +28 -0
- package/lib/nodes/JupyterCodeHighlighter.js +522 -0
- package/lib/nodes/JupyterCodeHighlighter.js.map +1 -0
- package/lib/nodes/JupyterCodeNode.d.ts +50 -0
- package/lib/nodes/JupyterCodeNode.js +277 -0
- package/lib/nodes/JupyterCodeNode.js.map +1 -0
- package/lib/nodes/JupyterOutputNode.d.ts +58 -0
- package/lib/nodes/JupyterOutputNode.js +144 -0
- package/lib/nodes/JupyterOutputNode.js.map +1 -0
- package/lib/nodes/YouTubeNode.d.ts +28 -0
- package/lib/nodes/YouTubeNode.js +56 -0
- package/lib/nodes/YouTubeNode.js.map +1 -0
- package/lib/plugins/AutoEmbedPlugin.d.ts +17 -0
- package/lib/plugins/AutoEmbedPlugin.js +110 -0
- package/lib/plugins/AutoEmbedPlugin.js.map +1 -0
- package/lib/plugins/AutoLinkPlugin.d.ts +2 -0
- package/lib/plugins/AutoLinkPlugin.js +34 -0
- package/lib/plugins/AutoLinkPlugin.js.map +1 -0
- package/lib/plugins/CodeActionMenuPlugin.css +52 -0
- package/lib/plugins/CodeActionMenuPlugin.d.ts +12 -0
- package/lib/plugins/CodeActionMenuPlugin.js +108 -0
- package/lib/plugins/CodeActionMenuPlugin.js.map +1 -0
- package/lib/plugins/ComponentPickerMenuPlugin.d.ts +2 -0
- package/lib/plugins/ComponentPickerMenuPlugin.js +244 -0
- package/lib/plugins/ComponentPickerMenuPlugin.js.map +1 -0
- package/lib/plugins/EquationsPlugin.d.ts +21 -0
- package/lib/plugins/EquationsPlugin.js +48 -0
- package/lib/plugins/EquationsPlugin.js.map +1 -0
- package/lib/plugins/HorizontalRulePlugin.d.ts +2 -0
- package/lib/plugins/HorizontalRulePlugin.js +40 -0
- package/lib/plugins/HorizontalRulePlugin.js.map +1 -0
- package/lib/plugins/ImagesPlugin.d.ts +25 -0
- package/lib/plugins/ImagesPlugin.js +212 -0
- package/lib/plugins/ImagesPlugin.js.map +1 -0
- package/lib/plugins/JupyterPlugin.css +13 -0
- package/lib/plugins/JupyterPlugin.d.ts +16 -0
- package/lib/plugins/JupyterPlugin.js +169 -0
- package/lib/plugins/JupyterPlugin.js.map +1 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.d.ts +4 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.js +49 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.js.map +1 -0
- package/lib/plugins/MardownPlugin.d.ts +2 -0
- package/lib/plugins/MardownPlugin.js +20 -0
- package/lib/plugins/MardownPlugin.js.map +1 -0
- package/lib/plugins/NbformatContentPlugin.d.ts +6 -0
- package/lib/plugins/NbformatContentPlugin.js +20 -0
- package/lib/plugins/NbformatContentPlugin.js.map +1 -0
- package/lib/plugins/TableOfContentsPlugin.css +87 -0
- package/lib/plugins/TableOfContentsPlugin.d.ts +3 -0
- package/lib/plugins/TableOfContentsPlugin.js +115 -0
- package/lib/plugins/TableOfContentsPlugin.js.map +1 -0
- package/lib/plugins/YouTubePlugin.d.ts +4 -0
- package/lib/plugins/YouTubePlugin.js +34 -0
- package/lib/plugins/YouTubePlugin.js.map +1 -0
- package/lib/ui/Button.css +40 -0
- package/lib/ui/Button.d.ts +18 -0
- package/lib/ui/Button.js +8 -0
- package/lib/ui/Button.js.map +1 -0
- package/lib/ui/ContentEditable.css +24 -0
- package/lib/ui/ContentEditable.d.ts +5 -0
- package/lib/ui/ContentEditable.js +20 -0
- package/lib/ui/ContentEditable.js.map +1 -0
- package/lib/ui/CopyButton.d.ts +7 -0
- package/lib/ui/CopyButton.js +47 -0
- package/lib/ui/CopyButton.js.map +1 -0
- package/lib/ui/Dialog.css +23 -0
- package/lib/ui/Dialog.d.ts +16 -0
- package/lib/ui/Dialog.js +21 -0
- package/lib/ui/Dialog.js.map +1 -0
- package/lib/ui/DropDown.d.ts +23 -0
- package/lib/ui/DropDown.js +119 -0
- package/lib/ui/DropDown.js.map +1 -0
- package/lib/ui/EquationEditor.css +42 -0
- package/lib/ui/EquationEditor.d.ts +18 -0
- package/lib/ui/EquationEditor.js +31 -0
- package/lib/ui/EquationEditor.js.map +1 -0
- package/lib/ui/FileInput.d.ts +15 -0
- package/lib/ui/FileInput.js +18 -0
- package/lib/ui/FileInput.js.map +1 -0
- package/lib/ui/ImageResizer.d.ts +16 -0
- package/lib/ui/ImageResizer.js +166 -0
- package/lib/ui/ImageResizer.js.map +1 -0
- package/lib/ui/Input.css +37 -0
- package/lib/ui/KatexEquationAlterer.css +45 -0
- package/lib/ui/KatexEquationAlterer.d.ts +7 -0
- package/lib/ui/KatexEquationAlterer.js +33 -0
- package/lib/ui/KatexEquationAlterer.js.map +1 -0
- package/lib/ui/KatexRenderer.d.ts +6 -0
- package/lib/ui/KatexRenderer.js +36 -0
- package/lib/ui/KatexRenderer.js.map +1 -0
- package/lib/ui/Modal.css +67 -0
- package/lib/ui/Modal.d.ts +15 -0
- package/lib/ui/Modal.js +58 -0
- package/lib/ui/Modal.js.map +1 -0
- package/lib/ui/Placeholder.css +29 -0
- package/lib/ui/Placeholder.d.ts +14 -0
- package/lib/ui/Placeholder.js +7 -0
- package/lib/ui/Placeholder.js.map +1 -0
- package/lib/ui/PrettierButton.css +20 -0
- package/lib/ui/PrettierButton.tsx_tmp +133 -0
- package/lib/ui/TextInput.d.ts +16 -0
- package/lib/ui/TextInput.js +20 -0
- package/lib/ui/TextInput.js.map +1 -0
- package/lib/utils/canUseDOM.d.ts +8 -0
- package/lib/utils/canUseDOM.js +16 -0
- package/lib/utils/canUseDOM.js.map +1 -0
- package/lib/utils/debouncer.d.ts +1 -0
- package/lib/utils/debouncer.js +24 -0
- package/lib/utils/debouncer.js.map +1 -0
- package/lib/utils/invariant.d.ts +8 -0
- package/lib/utils/invariant.js +23 -0
- package/lib/utils/invariant.js.map +1 -0
- package/lib/utils/join.d.ts +8 -0
- package/lib/utils/join.js +16 -0
- package/lib/utils/join.js.map +1 -0
- package/lib/utils/selection.d.ts +8 -0
- package/lib/utils/selection.js +14 -0
- package/lib/utils/selection.js.map +1 -0
- package/lib/utils/useLayoutEffect.d.ts +10 -0
- package/lib/utils/useLayoutEffect.js +19 -0
- package/lib/utils/useLayoutEffect.js.map +1 -0
- package/package.json +166 -0
- package/style/base.css +16 -0
- package/style/index.css +7 -0
- package/style/index.js +7 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { createPortal } from 'react-dom';
|
|
16
|
+
const DropDownContext = React.createContext(null);
|
|
17
|
+
export function DropDownItem({ children, className, onClick, title, }) {
|
|
18
|
+
const ref = useRef(null);
|
|
19
|
+
const dropDownContext = React.useContext(DropDownContext);
|
|
20
|
+
if (dropDownContext === null) {
|
|
21
|
+
throw new Error('DropDownItem must be used within a DropDown');
|
|
22
|
+
}
|
|
23
|
+
const { registerItem } = dropDownContext;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (ref && ref.current) {
|
|
26
|
+
registerItem(ref);
|
|
27
|
+
}
|
|
28
|
+
}, [ref, registerItem]);
|
|
29
|
+
return (_jsx("button", { className: className, onClick: onClick, ref: ref, title: title, children: children }));
|
|
30
|
+
}
|
|
31
|
+
function DropDownItems({ children, dropDownRef, onClose, }) {
|
|
32
|
+
const [items, setItems] = useState();
|
|
33
|
+
const [highlightedItem, setHighlightedItem] = useState();
|
|
34
|
+
const registerItem = useCallback((itemRef) => {
|
|
35
|
+
setItems((prev) => (prev ? [...prev, itemRef] : [itemRef]));
|
|
36
|
+
}, [setItems]);
|
|
37
|
+
const handleKeyDown = (event) => {
|
|
38
|
+
if (!items)
|
|
39
|
+
return;
|
|
40
|
+
const key = event.key;
|
|
41
|
+
if (['Escape', 'ArrowUp', 'ArrowDown', 'Tab'].includes(key)) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
}
|
|
44
|
+
if (key === 'Escape' || key === 'Tab') {
|
|
45
|
+
onClose();
|
|
46
|
+
}
|
|
47
|
+
else if (key === 'ArrowUp') {
|
|
48
|
+
setHighlightedItem((prev) => {
|
|
49
|
+
if (!prev)
|
|
50
|
+
return items[0];
|
|
51
|
+
const index = items.indexOf(prev) - 1;
|
|
52
|
+
return items[index === -1 ? items.length - 1 : index];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (key === 'ArrowDown') {
|
|
56
|
+
setHighlightedItem((prev) => {
|
|
57
|
+
if (!prev)
|
|
58
|
+
return items[0];
|
|
59
|
+
return items[items.indexOf(prev) + 1];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const contextValue = useMemo(() => ({
|
|
64
|
+
registerItem,
|
|
65
|
+
}), [registerItem]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (items && !highlightedItem) {
|
|
68
|
+
setHighlightedItem(items[0]);
|
|
69
|
+
}
|
|
70
|
+
if (highlightedItem && highlightedItem.current) {
|
|
71
|
+
highlightedItem.current.focus();
|
|
72
|
+
}
|
|
73
|
+
}, [items, highlightedItem]);
|
|
74
|
+
return (_jsx(DropDownContext.Provider, { value: contextValue, children: _jsx("div", { className: "dropdown", ref: dropDownRef, onKeyDown: handleKeyDown, children: children }) }));
|
|
75
|
+
}
|
|
76
|
+
export const DropDown = ({ buttonLabel, buttonAriaLabel, buttonClassName, buttonIconClassName, children, stopCloseOnClickSelf, }) => {
|
|
77
|
+
const dropDownRef = useRef(null);
|
|
78
|
+
const buttonRef = useRef(null);
|
|
79
|
+
const [showDropDown, setShowDropDown] = useState(false);
|
|
80
|
+
const handleClose = () => {
|
|
81
|
+
setShowDropDown(false);
|
|
82
|
+
if (buttonRef && buttonRef.current) {
|
|
83
|
+
buttonRef.current.focus();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
const button = buttonRef.current;
|
|
88
|
+
const dropDown = dropDownRef.current;
|
|
89
|
+
if (showDropDown && button !== null && dropDown !== null) {
|
|
90
|
+
const { top, left } = button.getBoundingClientRect();
|
|
91
|
+
dropDown.style.top = `${top + 40}px`;
|
|
92
|
+
dropDown.style.left = `${Math.min(left, window.innerWidth - dropDown.offsetWidth - 20)}px`;
|
|
93
|
+
}
|
|
94
|
+
}, [dropDownRef, buttonRef, showDropDown]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const button = buttonRef.current;
|
|
97
|
+
if (button !== null && showDropDown) {
|
|
98
|
+
const handle = (event) => {
|
|
99
|
+
const target = event.target;
|
|
100
|
+
if (stopCloseOnClickSelf) {
|
|
101
|
+
if (dropDownRef.current &&
|
|
102
|
+
dropDownRef.current.contains(target))
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!button.contains(target)) {
|
|
106
|
+
setShowDropDown(false);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
document.addEventListener('click', handle);
|
|
110
|
+
return () => {
|
|
111
|
+
document.removeEventListener('click', handle);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}, [dropDownRef, buttonRef, showDropDown, stopCloseOnClickSelf]);
|
|
115
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { "aria-label": buttonAriaLabel || buttonLabel, className: buttonClassName, onClick: () => setShowDropDown(!showDropDown), ref: buttonRef, children: [buttonIconClassName && _jsx("span", { className: buttonIconClassName }), buttonLabel && (_jsx("span", { className: "text dropdown-button-text", children: buttonLabel })), _jsx("i", { className: "chevron-down" })] }), showDropDown &&
|
|
116
|
+
createPortal(_jsx(DropDownItems, { dropDownRef: dropDownRef, onClose: handleClose, children: children }), document.body)] }));
|
|
117
|
+
};
|
|
118
|
+
export default DropDown;
|
|
119
|
+
//# sourceMappingURL=Drop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C,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAChD,CAAC,CAAC;SACH;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAEjE,OAAO,CACL,8BACE,gCACc,eAAe,IAAI,WAAW,EAC1C,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,YAAY,CAAC,EAC7C,GAAG,EAAE,SAAS,aACb,mBAAmB,IAAI,eAAM,SAAS,EAAE,mBAAmB,GAAI,EAC/D,WAAW,IAAI,CACd,eAAM,SAAS,EAAC,2BAA2B,YAAE,WAAW,GAAQ,CACjE,EACD,YAAG,SAAS,EAAC,cAAc,GAAG,IACvB,EAER,YAAY;gBACX,YAAY,CACV,KAAC,aAAa,IAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,YAC1D,QAAQ,GACK,EAChB,QAAQ,CAAC,IAAI,CACd,IACF,CACJ,CAAC;AACJ,CAAC,CAAA;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
.EquationEditor_inlineEditor {
|
|
15
|
+
padding: 0;
|
|
16
|
+
margin: 0;
|
|
17
|
+
border: 0;
|
|
18
|
+
outline: 0;
|
|
19
|
+
color: #8421a2;
|
|
20
|
+
background-color: inherit;
|
|
21
|
+
resize: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.EquationEditor_blockEditor {
|
|
25
|
+
padding: 0;
|
|
26
|
+
margin: 0;
|
|
27
|
+
border: 0;
|
|
28
|
+
outline: 0;
|
|
29
|
+
color: #8421a2;
|
|
30
|
+
background-color: inherit;
|
|
31
|
+
resize: none;
|
|
32
|
+
width: '100%';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.EquationEditor_inputBackground {
|
|
36
|
+
background-color: #eee;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.EquationEditor_dollarSign {
|
|
40
|
+
text-align: left;
|
|
41
|
+
color: #b0b0b0;
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
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
|
+
import './EquationEditor.css';
|
|
9
|
+
type BaseEquationEditorProps = {
|
|
10
|
+
equation: string;
|
|
11
|
+
inline: boolean;
|
|
12
|
+
inputRef: {
|
|
13
|
+
current: null | HTMLInputElement | HTMLTextAreaElement;
|
|
14
|
+
};
|
|
15
|
+
setEquation: (equation: string) => void;
|
|
16
|
+
};
|
|
17
|
+
export default function EquationEditor({ equation, setEquation, inline, inputRef, }: BaseEquationEditorProps): JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import './EquationEditor.css';
|
|
14
|
+
export default function EquationEditor({ equation, setEquation, inline, inputRef, }) {
|
|
15
|
+
const onChange = (event) => {
|
|
16
|
+
setEquation(event.target.value);
|
|
17
|
+
};
|
|
18
|
+
const props = {
|
|
19
|
+
equation,
|
|
20
|
+
inputRef,
|
|
21
|
+
onChange,
|
|
22
|
+
};
|
|
23
|
+
return inline ? (_jsx(InlineEquationEditor, { ...props, inputRef: inputRef })) : (_jsx(BlockEquationEditor, { ...props, inputRef: inputRef }));
|
|
24
|
+
}
|
|
25
|
+
function InlineEquationEditor({ equation, onChange, inputRef, }) {
|
|
26
|
+
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: "$" })] }));
|
|
27
|
+
}
|
|
28
|
+
function BlockEquationEditor({ equation, onChange, inputRef, }) {
|
|
29
|
+
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$$' })] }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=EquationEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EquationEditor.js","sourceRoot":"","sources":["../../src/ui/EquationEditor.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,OAAO,sBAAsB,CAAC;AAW9B,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,QAAQ,EACR,WAAW,EACX,MAAM,EACN,QAAQ,GACgB;IACxB,MAAM,QAAQ,GAAG,CAAC,KAAkB,EAAE,EAAE;QACtC,WAAW,CAAE,KAAK,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG;QACZ,QAAQ;QACR,QAAQ;QACR,QAAQ;KACT,CAAC;IAEF,OAAO,MAAM,CAAC,CAAC,CAAC,CACd,KAAC,oBAAoB,OACf,KAAK,EACT,QAAQ,EAAE,QAAuC,GACjD,CACH,CAAC,CAAC,CAAC,CACF,KAAC,mBAAmB,OACd,KAAK,EACT,QAAQ,EAAE,QAA0C,GACpD,CACH,CAAC;AACJ,CAAC;AAQD,SAAS,oBAAoB,CAAC,EAC5B,QAAQ,EACR,QAAQ,EACR,QAAQ,GACgB;IACxB,OAAO,CACL,gBAAM,SAAS,EAAC,gCAAgC,aAC9C,eAAM,SAAS,EAAC,2BAA2B,kBAAS,EACpD,gBACE,SAAS,EAAC,6BAA6B,EACvC,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,IAAI,EACf,GAAG,EAAE,QAAQ,GACb,EACF,eAAM,SAAS,EAAC,2BAA2B,kBAAS,IAC/C,CACR,CAAC;AACJ,CAAC;AAQD,SAAS,mBAAmB,CAAC,EAC3B,QAAQ,EACR,QAAQ,EACR,QAAQ,GACqB;IAC7B,OAAO,CACL,eAAK,SAAS,EAAC,gCAAgC,aAC7C,eAAM,SAAS,EAAC,2BAA2B,YAAE,MAAM,GAAQ,EAC3D,mBACE,SAAS,EAAC,4BAA4B,EACtC,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,QAAQ,GACb,EACF,eAAM,SAAS,EAAC,2BAA2B,YAAE,MAAM,GAAQ,IACvD,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import './Input.css';
|
|
8
|
+
type Props = Readonly<{
|
|
9
|
+
'data-test-id'?: string;
|
|
10
|
+
accept?: string;
|
|
11
|
+
label: string;
|
|
12
|
+
onChange: (files: FileList | null) => void;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const FileInput: ({ accept, label, onChange, "data-test-id": dataTestId, }: Props) => JSX.Element;
|
|
15
|
+
export default FileInput;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import './Input.css';
|
|
14
|
+
export const FileInput = ({ accept, label, onChange, 'data-test-id': dataTestId, }) => {
|
|
15
|
+
return (_jsxs("div", { className: "Input__wrapper", children: [_jsx("label", { className: "Input__label", children: label }), _jsx("input", { type: "file", accept: accept, className: "Input__input", onChange: (e) => onChange(e.target.files), "data-test-id": dataTestId })] }));
|
|
16
|
+
};
|
|
17
|
+
export default FileInput;
|
|
18
|
+
//# sourceMappingURL=FileInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileInput.js","sourceRoot":"","sources":["../../src/ui/FileInput.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,OAAO,aAAa,CAAC;AASrB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,MAAM,EACN,KAAK,EACL,QAAQ,EACR,cAAc,EAAE,UAAU,GACpB,EAAe,EAAE;IACvB,OAAO,CACL,eAAK,SAAS,EAAC,gBAAgB,aAC7B,gBAAO,SAAS,EAAC,cAAc,YAAE,KAAK,GAAS,EAC/C,gBACE,IAAI,EAAC,MAAM,EACX,MAAM,EAAE,MAAM,EACd,SAAS,EAAC,cAAc,EACxB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,kBAC3B,UAAU,GACxB,IACE,CACP,CAAC;AACJ,CAAC,CAAA;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LexicalEditor } from 'lexical';
|
|
2
|
+
export declare const ImageResizer: ({ onResizeStart, onResizeEnd, buttonRef, imageRef, maxWidth, editor, showCaption, setShowCaption, }: {
|
|
3
|
+
editor: LexicalEditor;
|
|
4
|
+
buttonRef: {
|
|
5
|
+
current: null | HTMLButtonElement;
|
|
6
|
+
};
|
|
7
|
+
imageRef: {
|
|
8
|
+
current: null | HTMLElement;
|
|
9
|
+
};
|
|
10
|
+
maxWidth?: number | undefined;
|
|
11
|
+
onResizeEnd: (width: 'inherit' | number, height: 'inherit' | number) => void;
|
|
12
|
+
onResizeStart: () => void;
|
|
13
|
+
setShowCaption: (show: boolean) => void;
|
|
14
|
+
showCaption: boolean;
|
|
15
|
+
}) => JSX.Element;
|
|
16
|
+
export default ImageResizer;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
function clamp(value, min, max) {
|
|
4
|
+
return Math.min(Math.max(value, min), max);
|
|
5
|
+
}
|
|
6
|
+
const Direction = {
|
|
7
|
+
east: 1 << 0,
|
|
8
|
+
north: 1 << 3,
|
|
9
|
+
south: 1 << 1,
|
|
10
|
+
west: 1 << 2,
|
|
11
|
+
};
|
|
12
|
+
export const ImageResizer = ({ onResizeStart, onResizeEnd, buttonRef, imageRef, maxWidth, editor, showCaption, setShowCaption, }) => {
|
|
13
|
+
const controlWrapperRef = useRef(null);
|
|
14
|
+
const userSelect = useRef({
|
|
15
|
+
priority: '',
|
|
16
|
+
value: 'default',
|
|
17
|
+
});
|
|
18
|
+
const positioningRef = useRef({
|
|
19
|
+
currentHeight: 0,
|
|
20
|
+
currentWidth: 0,
|
|
21
|
+
direction: 0,
|
|
22
|
+
isResizing: false,
|
|
23
|
+
ratio: 0,
|
|
24
|
+
startHeight: 0,
|
|
25
|
+
startWidth: 0,
|
|
26
|
+
startX: 0,
|
|
27
|
+
startY: 0,
|
|
28
|
+
});
|
|
29
|
+
const editorRootElement = editor.getRootElement();
|
|
30
|
+
// Find max width, accounting for editor padding.
|
|
31
|
+
const maxWidthContainer = maxWidth
|
|
32
|
+
? maxWidth
|
|
33
|
+
: editorRootElement !== null
|
|
34
|
+
? editorRootElement.getBoundingClientRect().width - 20
|
|
35
|
+
: 100;
|
|
36
|
+
const maxHeightContainer = editorRootElement !== null
|
|
37
|
+
? editorRootElement.getBoundingClientRect().height - 20
|
|
38
|
+
: 100;
|
|
39
|
+
const minWidth = 100;
|
|
40
|
+
const minHeight = 100;
|
|
41
|
+
const setStartCursor = (direction) => {
|
|
42
|
+
const ew = direction === Direction.east || direction === Direction.west;
|
|
43
|
+
const ns = direction === Direction.north || direction === Direction.south;
|
|
44
|
+
const nwse = (direction & Direction.north && direction & Direction.west) ||
|
|
45
|
+
(direction & Direction.south && direction & Direction.east);
|
|
46
|
+
const cursorDir = ew ? 'ew' : ns ? 'ns' : nwse ? 'nwse' : 'nesw';
|
|
47
|
+
if (editorRootElement !== null) {
|
|
48
|
+
editorRootElement.style.setProperty('cursor', `${cursorDir}-resize`, 'important');
|
|
49
|
+
}
|
|
50
|
+
if (document.body !== null) {
|
|
51
|
+
document.body.style.setProperty('cursor', `${cursorDir}-resize`, 'important');
|
|
52
|
+
userSelect.current.value = document.body.style.getPropertyValue('-webkit-user-select');
|
|
53
|
+
userSelect.current.priority = document.body.style.getPropertyPriority('-webkit-user-select');
|
|
54
|
+
document.body.style.setProperty('-webkit-user-select', `none`, 'important');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const setEndCursor = () => {
|
|
58
|
+
if (editorRootElement !== null) {
|
|
59
|
+
editorRootElement.style.setProperty('cursor', 'default');
|
|
60
|
+
}
|
|
61
|
+
if (document.body !== null) {
|
|
62
|
+
document.body.style.setProperty('cursor', 'default');
|
|
63
|
+
document.body.style.setProperty('-webkit-user-select', userSelect.current.value, userSelect.current.priority);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handlePointerDown = (event, direction) => {
|
|
67
|
+
const image = imageRef.current;
|
|
68
|
+
const controlWrapper = controlWrapperRef.current;
|
|
69
|
+
if (image !== null && controlWrapper !== null) {
|
|
70
|
+
const { width, height } = image.getBoundingClientRect();
|
|
71
|
+
const positioning = positioningRef.current;
|
|
72
|
+
positioning.startWidth = width;
|
|
73
|
+
positioning.startHeight = height;
|
|
74
|
+
positioning.ratio = width / height;
|
|
75
|
+
positioning.currentWidth = width;
|
|
76
|
+
positioning.currentHeight = height;
|
|
77
|
+
positioning.startX = event.clientX;
|
|
78
|
+
positioning.startY = event.clientY;
|
|
79
|
+
positioning.isResizing = true;
|
|
80
|
+
positioning.direction = direction;
|
|
81
|
+
setStartCursor(direction);
|
|
82
|
+
onResizeStart();
|
|
83
|
+
controlWrapper.classList.add('image-control-wrapper--resizing');
|
|
84
|
+
image.style.height = `${height}px`;
|
|
85
|
+
image.style.width = `${width}px`;
|
|
86
|
+
document.addEventListener('pointermove', handlePointerMove);
|
|
87
|
+
document.addEventListener('pointerup', handlePointerUp);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const handlePointerMove = (event) => {
|
|
91
|
+
const image = imageRef.current;
|
|
92
|
+
const positioning = positioningRef.current;
|
|
93
|
+
const isHorizontal = positioning.direction & (Direction.east | Direction.west);
|
|
94
|
+
const isVertical = positioning.direction & (Direction.south | Direction.north);
|
|
95
|
+
if (image !== null && positioning.isResizing) {
|
|
96
|
+
// Corner cursor
|
|
97
|
+
if (isHorizontal && isVertical) {
|
|
98
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
99
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
100
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
101
|
+
const height = width / positioning.ratio;
|
|
102
|
+
image.style.width = `${width}px`;
|
|
103
|
+
image.style.height = `${height}px`;
|
|
104
|
+
positioning.currentHeight = height;
|
|
105
|
+
positioning.currentWidth = width;
|
|
106
|
+
}
|
|
107
|
+
else if (isVertical) {
|
|
108
|
+
let diff = Math.floor(positioning.startY - event.clientY);
|
|
109
|
+
diff = positioning.direction & Direction.south ? -diff : diff;
|
|
110
|
+
const height = clamp(positioning.startHeight + diff, minHeight, maxHeightContainer);
|
|
111
|
+
image.style.height = `${height}px`;
|
|
112
|
+
positioning.currentHeight = height;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
116
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
117
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
118
|
+
image.style.width = `${width}px`;
|
|
119
|
+
positioning.currentWidth = width;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handlePointerUp = () => {
|
|
124
|
+
const image = imageRef.current;
|
|
125
|
+
const positioning = positioningRef.current;
|
|
126
|
+
const controlWrapper = controlWrapperRef.current;
|
|
127
|
+
if (image !== null && controlWrapper !== null && positioning.isResizing) {
|
|
128
|
+
const width = positioning.currentWidth;
|
|
129
|
+
const height = positioning.currentHeight;
|
|
130
|
+
positioning.startWidth = 0;
|
|
131
|
+
positioning.startHeight = 0;
|
|
132
|
+
positioning.ratio = 0;
|
|
133
|
+
positioning.startX = 0;
|
|
134
|
+
positioning.startY = 0;
|
|
135
|
+
positioning.currentWidth = 0;
|
|
136
|
+
positioning.currentHeight = 0;
|
|
137
|
+
positioning.isResizing = false;
|
|
138
|
+
controlWrapper.classList.remove('image-control-wrapper--resizing');
|
|
139
|
+
setEndCursor();
|
|
140
|
+
onResizeEnd(width, height);
|
|
141
|
+
document.removeEventListener('pointermove', handlePointerMove);
|
|
142
|
+
document.removeEventListener('pointerup', handlePointerUp);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return (_jsxs("div", { ref: controlWrapperRef, children: [!showCaption && (_jsx("button", { className: "image-caption-button", ref: buttonRef, onClick: () => {
|
|
146
|
+
setShowCaption(!showCaption);
|
|
147
|
+
}, children: "Add Caption" })), _jsx("div", { className: "image-resizer image-resizer-n", onPointerDown: (event) => {
|
|
148
|
+
handlePointerDown(event, Direction.north);
|
|
149
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-ne", onPointerDown: (event) => {
|
|
150
|
+
handlePointerDown(event, Direction.north | Direction.east);
|
|
151
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-e", onPointerDown: (event) => {
|
|
152
|
+
handlePointerDown(event, Direction.east);
|
|
153
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-se", onPointerDown: (event) => {
|
|
154
|
+
handlePointerDown(event, Direction.south | Direction.east);
|
|
155
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-s", onPointerDown: (event) => {
|
|
156
|
+
handlePointerDown(event, Direction.south);
|
|
157
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-sw", onPointerDown: (event) => {
|
|
158
|
+
handlePointerDown(event, Direction.south | Direction.west);
|
|
159
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-w", onPointerDown: (event) => {
|
|
160
|
+
handlePointerDown(event, Direction.west);
|
|
161
|
+
} }), _jsx("div", { className: "image-resizer image-resizer-nw", onPointerDown: (event) => {
|
|
162
|
+
handlePointerDown(event, Direction.north | Direction.west);
|
|
163
|
+
} })] }));
|
|
164
|
+
};
|
|
165
|
+
export default ImageResizer;
|
|
166
|
+
//# sourceMappingURL=ImageResizer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,SAAS,EAAC,gCAAgC,EAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC7D,CAAC,GACD,EACF,cACE,SAAS,EAAC,+BAA+B,EACzC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC3C,CAAC,GACD,EACF,cACE,SAAS,EAAC,gCAAgC,EAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;oBACvB,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC7D,CAAC,GACD,IACE,CACP,CAAC;AACJ,CAAC,CAAA;AAED,eAAe,YAAY,CAAC"}
|
package/lib/ui/Input.css
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
.Input__wrapper {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
align-items: center;
|
|
19
|
+
margin-bottom: 10px;
|
|
20
|
+
}
|
|
21
|
+
.Input__label {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex: 1;
|
|
24
|
+
color: #666;
|
|
25
|
+
}
|
|
26
|
+
.Input__input {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex: 2;
|
|
29
|
+
border: 1px solid #999;
|
|
30
|
+
padding-top: 7px;
|
|
31
|
+
padding-bottom: 7px;
|
|
32
|
+
padding-left: 10px;
|
|
33
|
+
padding-right: 10px;
|
|
34
|
+
font-size: 16px;
|
|
35
|
+
border-radius: 5px;
|
|
36
|
+
min-width: 0;
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
.KatexEquationAlterer_defaultRow {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: row;
|
|
17
|
+
margin-top: 10px;
|
|
18
|
+
margin-bottom: 10px;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.KatexEquationAlterer_dialogActions {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: row;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
margin-top: 20px;
|
|
28
|
+
margin-bottom: 0;
|
|
29
|
+
justify-content: right;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.KatexEquationAlterer_centerRow {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: 'row';
|
|
35
|
+
margin-top: 10px;
|
|
36
|
+
margin-bottom: 10px;
|
|
37
|
+
justify-content: center;
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.KatexEquationAlterer_textArea {
|
|
42
|
+
width: 100%;
|
|
43
|
+
resize: none;
|
|
44
|
+
padding: 7px;
|
|
45
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import './KatexEquationAlterer.css';
|
|
2
|
+
type Props = {
|
|
3
|
+
initialEquation?: string;
|
|
4
|
+
onConfirm: (equation: string, inline: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const KatexEquationAlterer: ({ onConfirm, initialEquation, }: Props) => JSX.Element;
|
|
7
|
+
export default KatexEquationAlterer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import { useCallback, useState } from 'react';
|
|
14
|
+
import Button from '../ui/Button';
|
|
15
|
+
import KatexRenderer from './KatexRenderer';
|
|
16
|
+
import './KatexEquationAlterer.css';
|
|
17
|
+
export const KatexEquationAlterer = ({ onConfirm, initialEquation = '', }) => {
|
|
18
|
+
const [equation, setEquation] = useState(initialEquation);
|
|
19
|
+
const [inline, setInline] = useState(true);
|
|
20
|
+
const onClick = useCallback(() => {
|
|
21
|
+
onConfirm(equation, inline);
|
|
22
|
+
}, [onConfirm, equation, inline]);
|
|
23
|
+
const onCheckboxChange = useCallback(() => {
|
|
24
|
+
setInline(!inline);
|
|
25
|
+
}, [setInline, inline]);
|
|
26
|
+
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", { onChange: (event) => {
|
|
27
|
+
setEquation(event.target.value);
|
|
28
|
+
}, value: equation, className: "KatexEquationAlterer_textArea" })) : (_jsx("textarea", { onChange: (event) => {
|
|
29
|
+
setEquation(event.target.value);
|
|
30
|
+
}, 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" }) })] }));
|
|
31
|
+
};
|
|
32
|
+
export default KatexEquationAlterer;
|
|
33
|
+
//# sourceMappingURL=KatexEquationAlterer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KatexEquationAlterer.js","sourceRoot":"","sources":["../../src/ui/KatexEquationAlterer.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC5C,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,4BAA4B,CAAC;AAOpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,SAAS,EACT,eAAe,GAAG,EAAE,GACd,EAAe,EAAE;IACvB,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAS,eAAe,CAAC,CAAC;IAClE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IAClC,MAAM,gBAAgB,GAAG,WA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yright (c) 2021-2023 Datalayer, Inc.
|
|
4
|
+
*
|
|
5
|
+
* MIT License
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*/
|
|
13
|
+
import katex from 'katex';
|
|
14
|
+
import { useEffect, useRef } from 'react';
|
|
15
|
+
export default function KatexRenderer({ equation, inline, onClick, }) {
|
|
16
|
+
const katexElementRef = useRef(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const katexElement = katexElementRef.current;
|
|
19
|
+
if (katexElement !== null) {
|
|
20
|
+
katex.render(equation, katexElement, {
|
|
21
|
+
displayMode: !inline,
|
|
22
|
+
errorColor: '#cc0000',
|
|
23
|
+
output: 'html',
|
|
24
|
+
strict: 'warn',
|
|
25
|
+
throwOnError: false,
|
|
26
|
+
trust: false,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}, [equation, inline]);
|
|
30
|
+
return (
|
|
31
|
+
// We use spacers either side to ensure Android doesn't try and compose from the
|
|
32
|
+
// inner text from Katex. There didn't seem to be any other way of making this work,
|
|
33
|
+
// without having a physical space.
|
|
34
|
+
_jsxs(_Fragment, { children: [_jsx("span", { className: "spacer", children: " " }), _jsx("span", { role: "button", tabIndex: -1, onClick: onClick, ref: katexElementRef }), _jsx("span", { className: "spacer", children: " " })] }));
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=KatexRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KatexRenderer.js","sourceRoot":"","sources":["../../src/ui/KatexRenderer.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,QAAQ,EACR,MAAM,EACN,OAAO,GAKP;IACA,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAErC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC;QAE7C,IAAI,YAAY,KAAK,IAAI,EAAE;YACzB,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE;gBACnC,WAAW,EAAE,CAAC,MAAM;gBACpB,UAAU,EAAE,SAAS;gBACrB,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,MAAM;gBACd,YAAY,EAAE,KAAK;gBACnB,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;SACJ;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvB,OAAO;IACL,gFAAgF;IAChF,oFAAoF;IACpF,mCAAmC;IACnC,8BACE,eAAM,SAAS,EAAC,QAAQ,kBAAS,EACjC,eACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,eAAe,GACpB,EACF,eAAM,SAAS,EAAC,QAAQ,kBAAS,IAChC,CACJ,CAAC;AACJ,CAAC"}
|