@pie-lib/editable-html-tip-tap 2.1.2-next.85 → 2.1.2-next.91
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/lib/components/respArea/InlineDropdown.js +9 -1
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/extensions/math.js +37 -11
- package/lib/extensions/math.js.map +1 -1
- package/package.json +2 -2
- package/src/components/__tests__/InlineDropdown.test.jsx +32 -1
- package/src/components/respArea/InlineDropdown.jsx +12 -6
- package/src/extensions/__tests__/math.test.js +2 -0
- package/src/extensions/math.js +30 -8
|
@@ -8,11 +8,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports["default"] = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
|
+
var _mathRendering = require("@pie-lib/math-rendering");
|
|
11
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
14
|
var _react2 = require("@tiptap/react");
|
|
13
15
|
var _prosemirrorState = require("prosemirror-state");
|
|
14
16
|
var _RespArea = require("../icons/RespArea");
|
|
15
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
16
17
|
var _customToolbarWrapper = _interopRequireDefault(require("../../extensions/custom-toolbar-wrapper"));
|
|
17
18
|
var _toolbar = require("../../utils/toolbar");
|
|
18
19
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
@@ -30,6 +31,7 @@ var InlineDropdown = function InlineDropdown(props) {
|
|
|
30
31
|
var toolbarRef = (0, _react.useRef)(null);
|
|
31
32
|
var toolbarEditor = (0, _react.useRef)(null);
|
|
32
33
|
var pendingCloseRequest = (0, _react.useRef)(false);
|
|
34
|
+
var elementRef = (0, _react.useRef)(null);
|
|
33
35
|
var isHeld = function isHeld() {
|
|
34
36
|
return editor._holdInlineDropdownToolbarIndex != null && String(editor._holdInlineDropdownToolbarIndex) === String(node.attrs.index);
|
|
35
37
|
};
|
|
@@ -98,6 +100,11 @@ var InlineDropdown = function InlineDropdown(props) {
|
|
|
98
100
|
var isScrollbarClicked = function isScrollbarClicked(event) {
|
|
99
101
|
return event.clientX > document.documentElement.clientWidth || event.clientY > document.documentElement.clientHeight || event.target === document.documentElement;
|
|
100
102
|
};
|
|
103
|
+
(0, _react.useEffect)(function () {
|
|
104
|
+
if (elementRef.current && typeof _mathRendering.renderMath === 'function') {
|
|
105
|
+
(0, _mathRendering.renderMath)(elementRef.current);
|
|
106
|
+
}
|
|
107
|
+
}, [value]);
|
|
101
108
|
(0, _react.useEffect)(function () {
|
|
102
109
|
// Calculate position relative to selection
|
|
103
110
|
var bodyRect = document.body.getBoundingClientRect();
|
|
@@ -136,6 +143,7 @@ var InlineDropdown = function InlineDropdown(props) {
|
|
|
136
143
|
cursor: 'pointer'
|
|
137
144
|
}
|
|
138
145
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
146
|
+
ref: elementRef,
|
|
139
147
|
style: {
|
|
140
148
|
display: 'inline-flex',
|
|
141
149
|
minWidth: '178px',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineDropdown.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_react2","_prosemirrorState","_RespArea","_reactDom","_customToolbarWrapper","_toolbar","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","InlineDropdown","props","editor","node","getPos","options","selected","attributes","attrs","value","error","html","pos","toolbarRef","useRef","toolbarEditor","pendingCloseRequest","isHeld","_holdInlineDropdownToolbarIndex","String","index","_useState","useState","_useState2","_slicedToArray2","showToolbar","setShowToolbar","_useState3","top","left","_useState4","position","setPosition","closeToolbar","InlineDropdownToolbar","respAreaToolbar","reselectNode","tr","state","nodeAtPos","doc","nodeAt","selection","from","to","nodeSize","setSelection","NodeSelection","create","view","dispatch","requestClose","current","onToolbarCloseRequest","setTimeout","useEffect","onlyThisNodeSelected","isScrollbarClicked","event","clientX","document","documentElement","clientWidth","clientY","clientHeight","target","bodyRect","body","getBoundingClientRect","start","coordsAtPos","Math","abs","handleClickOutside","_toolbarEditor$curren","insideSomeEditor","closest","dataset","toolbarFor","instanceId","_toolbarOpened","contains","addEventListener","removeEventListener","createElement","NodeViewWrapper","className","style","display","height","cursor","minWidth","background","border","boxSizing","borderRadius","margin","alignItems","onClick","flex","overflow","padding","whiteSpace","textOverflow","verticalAlign","dangerouslySetInnerHTML","__html","Chevron","direction","right","Fragment","ReactDOM","createPortal","ref","editorCallback","instance","_tiptapContainerEl","deletable","toolbarOpts","autoWidth","onDelete","setToolbarOpened","commands","focus","showDone","propTypes","PropTypes","object","selectedItem","oneOfType","string","_default","exports"],"sources":["../../../src/components/respArea/InlineDropdown.jsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { NodeViewWrapper } from '@tiptap/react';\nimport { NodeSelection } from 'prosemirror-state';\nimport { Chevron } from '../icons/RespArea';\nimport ReactDOM from 'react-dom';\nimport CustomToolbarWrapper from '../../extensions/custom-toolbar-wrapper';\nimport { setToolbarOpened } from '../../utils/toolbar';\n\nconst InlineDropdown = (props) => {\n const { editor, node, getPos, options, selected } = props;\n const { attrs: attributes } = node;\n const { value, error } = attributes;\n const html = value || '<div> </div>';\n const pos = getPos();\n const toolbarRef = useRef(null);\n const toolbarEditor = useRef(null);\n const pendingCloseRequest = useRef(false);\n\n const isHeld = () =>\n editor._holdInlineDropdownToolbarIndex != null &&\n String(editor._holdInlineDropdownToolbarIndex) === String(node.attrs.index);\n\n const [showToolbar, setShowToolbar] = useState(false);\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const closeToolbar = () => {\n if (isHeld()) {\n return;\n }\n\n setShowToolbar(false);\n };\n\n const InlineDropdownToolbar = options.respAreaToolbar([node, pos], editor, closeToolbar);\n\n const reselectNode = () => {\n const { tr } = editor.state;\n const nodeAtPos = tr.doc.nodeAt(pos);\n\n if (!nodeAtPos) {\n return;\n }\n\n const { selection } = tr;\n\n if (selection.from === pos && selection.to === pos + nodeAtPos.nodeSize) {\n return;\n }\n\n tr.setSelection(NodeSelection.create(tr.doc, pos));\n editor.view.dispatch(tr);\n };\n\n const requestClose = () => {\n if (pendingCloseRequest.current) {\n return;\n }\n\n if (options.onToolbarCloseRequest) {\n pendingCloseRequest.current = true;\n\n options.onToolbarCloseRequest(\n [node, pos],\n editor,\n () => {\n pendingCloseRequest.current = false;\n delete editor._holdInlineDropdownToolbarIndex;\n closeToolbar();\n },\n () => {\n pendingCloseRequest.current = false;\n delete editor._holdInlineDropdownToolbarIndex;\n setShowToolbar(true);\n setTimeout(reselectNode, 0);\n },\n );\n } else {\n closeToolbar();\n }\n };\n\n useEffect(() => {\n const { selection } = editor.state;\n const onlyThisNodeSelected = selection.from + node.nodeSize === selection.to;\n\n if (selected) {\n if (onlyThisNodeSelected) {\n setShowToolbar(true);\n }\n } else if (showToolbar) {\n requestClose();\n }\n }, [editor, node, selected]);\n\n\n \n const isScrollbarClicked = (event) =>\n event.clientX > document.documentElement.clientWidth ||\n event.clientY > document.documentElement.clientHeight ||\n event.target === document.documentElement;\n \n\n useEffect(() => {\n // Calculate position relative to selection\n const bodyRect = document.body.getBoundingClientRect();\n const { from } = editor.state.selection;\n const start = editor.view.coordsAtPos(from);\n\n setPosition({\n top: start.top + Math.abs(bodyRect.top) + 40, // shift above\n left: start.left,\n });\n\n const handleClickOutside = (event) => {\n\n if( isScrollbarClicked(event) ) {\n return;\n }\n const insideSomeEditor = event.target.closest('[data-toolbar-for]');\n\n if (\n !event.target.closest('[data-inline-dropdown-toolbar]') &&\n (!insideSomeEditor || insideSomeEditor.dataset.toolbarFor !== toolbarEditor.current?.instanceId) &&\n !editor._toolbarOpened &&\n toolbarRef.current &&\n !toolbarRef.current.contains(event.target) &&\n !event.target.closest('[data-inline-node]')\n ) {\n requestClose();\n }\n };\n\n if (showToolbar) {\n document.addEventListener('mousedown', handleClickOutside);\n } else {\n document.removeEventListener('mousedown', handleClickOutside);\n }\n\n return () => document.removeEventListener('mousedown', handleClickOutside);\n }, [showToolbar, node]);\n\n return (\n <NodeViewWrapper\n className=\"inline-dropdown\"\n data-selected={selected}\n style={{\n display: 'inline-flex',\n height: '50px',\n cursor: 'pointer',\n }}\n >\n <div\n style={{\n display: 'inline-flex',\n minWidth: '178px',\n height: '36px',\n background: '#FFF',\n border: '1px solid #C0C3CF',\n boxSizing: 'border-box',\n borderRadius: '3px',\n margin: '0 2px',\n position: 'relative',\n alignItems: 'center',\n }}\n onClick={() => setShowToolbar(true)}\n >\n <div\n style={{\n flex: 1,\n overflow: 'hidden',\n padding: '0 25px 0 8px',\n whiteSpace: 'nowrap',\n textOverflow: 'ellipsis',\n }}\n >\n <span\n style={{\n display: 'inline-block',\n verticalAlign: 'middle',\n }}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n </div>\n <Chevron direction=\"down\" style={{ position: 'absolute', top: '5px', right: '5px' }} />\n </div>\n {showToolbar && (\n <React.Fragment>\n {ReactDOM.createPortal(\n <div ref={toolbarRef}>\n <InlineDropdownToolbar\n editorCallback={(instance) => {\n toolbarEditor.current = instance;\n }}\n />\n </div>,\n editor?._tiptapContainerEl || document.body,\n )}\n\n {editor._tiptapContainerEl &&\n ReactDOM.createPortal(\n <CustomToolbarWrapper\n deletable\n toolbarOpts={{ minWidth: 'auto' }}\n autoWidth\n style={{ top: -40, left: 0, right: 0 }}\n onDelete={() => {\n const { tr } = editor.state;\n tr.delete(pos, pos + node.nodeSize);\n // Prevent the debounced onBlur/onDone from firing into the\n // now-deleted node's stale position\n setToolbarOpened(editor, false);\n delete editor._holdInlineDropdownToolbarIndex;\n editor.view.dispatch(tr);\n setShowToolbar(false);\n editor.commands.focus();\n }}\n showDone={false}\n />,\n editor._tiptapContainerEl,\n )}\n </React.Fragment>\n )}\n </NodeViewWrapper>\n );\n};\n\nInlineDropdown.propTypes = {\n attributes: PropTypes.object,\n selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),\n};\n\nexport default InlineDropdown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,qBAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAAuD,SAAAD,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,wBAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GA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AAQ;MACd,IAAQnF,EAAE,GAAKnC,MAAM,CAACoC,KAAK,CAAnBD,EAAE;MACVA,EAAE,UAAO,CAACzB,GAAG,EAAEA,GAAG,GAAGT,IAAI,CAAC0C,QAAQ,CAAC;MACnC;MACA;MACA,IAAA4E,yBAAgB,EAACvH,MAAM,EAAE,KAAK,CAAC;MAC/B,OAAOA,MAAM,CAACgB,+BAA+B;MAC7ChB,MAAM,CAAC+C,IAAI,CAACC,QAAQ,CAACb,EAAE,CAAC;MACxBX,cAAc,CAAC,KAAK,CAAC;MACrBxB,MAAM,CAACwH,QAAQ,CAACC,KAAK,CAAC,CAAC;IACzB,CAAE;IACFC,QAAQ,EAAE;EAAM,CACjB,CAAC,EACF1H,MAAM,CAACkH,kBACT,CACY,CAEH,CAAC;AAEtB,CAAC;AAEDpH,cAAc,CAAC6H,SAAS,GAAG;EACzBtH,UAAU,EAAEuH,qBAAS,CAACC,MAAM;EAC5BC,YAAY,EAAEF,qBAAS,CAACG,SAAS,CAAC,CAACH,qBAAS,CAACI,MAAM,EAAEJ,qBAAS,CAACC,MAAM,CAAC;AACxE,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,cAEapI,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"InlineDropdown.js","names":["_react","_interopRequireWildcard","require","_reactDom","_interopRequireDefault","_mathRendering","_propTypes","_react2","_prosemirrorState","_RespArea","_customToolbarWrapper","_toolbar","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","InlineDropdown","props","editor","node","getPos","options","selected","attributes","attrs","value","error","html","pos","toolbarRef","useRef","toolbarEditor","pendingCloseRequest","elementRef","isHeld","_holdInlineDropdownToolbarIndex","String","index","_useState","useState","_useState2","_slicedToArray2","showToolbar","setShowToolbar","_useState3","top","left","_useState4","position","setPosition","closeToolbar","InlineDropdownToolbar","respAreaToolbar","reselectNode","tr","state","nodeAtPos","doc","nodeAt","selection","from","to","nodeSize","setSelection","NodeSelection","create","view","dispatch","requestClose","current","onToolbarCloseRequest","setTimeout","useEffect","onlyThisNodeSelected","isScrollbarClicked","event","clientX","document","documentElement","clientWidth","clientY","clientHeight","target","renderMath","bodyRect","body","getBoundingClientRect","start","coordsAtPos","Math","abs","handleClickOutside","_toolbarEditor$curren","insideSomeEditor","closest","dataset","toolbarFor","instanceId","_toolbarOpened","contains","addEventListener","removeEventListener","createElement","NodeViewWrapper","className","style","display","height","cursor","ref","minWidth","background","border","boxSizing","borderRadius","margin","alignItems","onClick","flex","overflow","padding","whiteSpace","textOverflow","verticalAlign","dangerouslySetInnerHTML","__html","Chevron","direction","right","Fragment","ReactDOM","createPortal","editorCallback","instance","_tiptapContainerEl","deletable","toolbarOpts","autoWidth","onDelete","setToolbarOpened","commands","focus","showDone","propTypes","PropTypes","object","selectedItem","oneOfType","string","_default","exports"],"sources":["../../../src/components/respArea/InlineDropdown.jsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport PropTypes from 'prop-types';\nimport { NodeViewWrapper } from '@tiptap/react';\nimport { NodeSelection } from 'prosemirror-state';\nimport { Chevron } from '../icons/RespArea';\nimport CustomToolbarWrapper from '../../extensions/custom-toolbar-wrapper';\nimport { setToolbarOpened } from '../../utils/toolbar';\n\nconst InlineDropdown = (props) => {\n const { editor, node, getPos, options, selected } = props;\n const { attrs: attributes } = node;\n const { value, error } = attributes;\n const html = value || '<div> </div>';\n const pos = getPos();\n const toolbarRef = useRef(null);\n const toolbarEditor = useRef(null);\n const pendingCloseRequest = useRef(false);\n const elementRef = useRef(null);\n\n const isHeld = () =>\n editor._holdInlineDropdownToolbarIndex != null &&\n String(editor._holdInlineDropdownToolbarIndex) === String(node.attrs.index);\n\n const [showToolbar, setShowToolbar] = useState(false);\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const closeToolbar = () => {\n if (isHeld()) {\n return;\n }\n\n setShowToolbar(false);\n };\n\n const InlineDropdownToolbar = options.respAreaToolbar([node, pos], editor, closeToolbar);\n\n const reselectNode = () => {\n const { tr } = editor.state;\n const nodeAtPos = tr.doc.nodeAt(pos);\n\n if (!nodeAtPos) {\n return;\n }\n\n const { selection } = tr;\n\n if (selection.from === pos && selection.to === pos + nodeAtPos.nodeSize) {\n return;\n }\n\n tr.setSelection(NodeSelection.create(tr.doc, pos));\n editor.view.dispatch(tr);\n };\n\n const requestClose = () => {\n if (pendingCloseRequest.current) {\n return;\n }\n\n if (options.onToolbarCloseRequest) {\n pendingCloseRequest.current = true;\n\n options.onToolbarCloseRequest(\n [node, pos],\n editor,\n () => {\n pendingCloseRequest.current = false;\n delete editor._holdInlineDropdownToolbarIndex;\n closeToolbar();\n },\n () => {\n pendingCloseRequest.current = false;\n delete editor._holdInlineDropdownToolbarIndex;\n setShowToolbar(true);\n setTimeout(reselectNode, 0);\n },\n );\n } else {\n closeToolbar();\n }\n };\n\n useEffect(() => {\n const { selection } = editor.state;\n const onlyThisNodeSelected = selection.from + node.nodeSize === selection.to;\n\n if (selected) {\n if (onlyThisNodeSelected) {\n setShowToolbar(true);\n }\n } else if (showToolbar) {\n requestClose();\n }\n }, [editor, node, selected]);\n\n const isScrollbarClicked = (event) =>\n event.clientX > document.documentElement.clientWidth ||\n event.clientY > document.documentElement.clientHeight ||\n event.target === document.documentElement;\n\n useEffect(() => {\n if (elementRef.current && typeof renderMath === 'function') {\n renderMath(elementRef.current);\n }\n }, [value]);\n\n useEffect(() => {\n // Calculate position relative to selection\n const bodyRect = document.body.getBoundingClientRect();\n const { from } = editor.state.selection;\n const start = editor.view.coordsAtPos(from);\n\n setPosition({\n top: start.top + Math.abs(bodyRect.top) + 40, // shift above\n left: start.left,\n });\n\n const handleClickOutside = (event) => {\n if (isScrollbarClicked(event)) {\n return;\n }\n\n const insideSomeEditor = event.target.closest('[data-toolbar-for]');\n\n if (\n !event.target.closest('[data-inline-dropdown-toolbar]') &&\n (!insideSomeEditor || insideSomeEditor.dataset.toolbarFor !== toolbarEditor.current?.instanceId) &&\n !editor._toolbarOpened &&\n toolbarRef.current &&\n !toolbarRef.current.contains(event.target) &&\n !event.target.closest('[data-inline-node]')\n ) {\n requestClose();\n }\n };\n\n if (showToolbar) {\n document.addEventListener('mousedown', handleClickOutside);\n } else {\n document.removeEventListener('mousedown', handleClickOutside);\n }\n\n return () => document.removeEventListener('mousedown', handleClickOutside);\n }, [showToolbar, node]);\n\n return (\n <NodeViewWrapper\n className=\"inline-dropdown\"\n data-selected={selected}\n style={{\n display: 'inline-flex',\n height: '50px',\n cursor: 'pointer',\n }}\n >\n <div\n ref={elementRef}\n style={{\n display: 'inline-flex',\n minWidth: '178px',\n height: '36px',\n background: '#FFF',\n border: '1px solid #C0C3CF',\n boxSizing: 'border-box',\n borderRadius: '3px',\n margin: '0 2px',\n position: 'relative',\n alignItems: 'center',\n }}\n onClick={() => setShowToolbar(true)}\n >\n <div\n style={{\n flex: 1,\n overflow: 'hidden',\n padding: '0 25px 0 8px',\n whiteSpace: 'nowrap',\n textOverflow: 'ellipsis',\n }}\n >\n <span\n style={{\n display: 'inline-block',\n verticalAlign: 'middle',\n }}\n dangerouslySetInnerHTML={{ __html: html }}\n />\n </div>\n <Chevron direction=\"down\" style={{ position: 'absolute', top: '5px', right: '5px' }} />\n </div>\n {showToolbar && (\n <React.Fragment>\n {ReactDOM.createPortal(\n <div ref={toolbarRef}>\n <InlineDropdownToolbar\n editorCallback={(instance) => {\n toolbarEditor.current = instance;\n }}\n />\n </div>,\n editor?._tiptapContainerEl || document.body,\n )}\n\n {editor._tiptapContainerEl &&\n ReactDOM.createPortal(\n <CustomToolbarWrapper\n deletable\n toolbarOpts={{ minWidth: 'auto' }}\n autoWidth\n style={{ top: -40, left: 0, right: 0 }}\n onDelete={() => {\n const { tr } = editor.state;\n tr.delete(pos, pos + node.nodeSize);\n // Prevent the debounced onBlur/onDone from firing into the\n // now-deleted node's stale position\n setToolbarOpened(editor, false);\n delete editor._holdInlineDropdownToolbarIndex;\n editor.view.dispatch(tr);\n setShowToolbar(false);\n editor.commands.focus();\n }}\n showDone={false}\n />,\n editor._tiptapContainerEl,\n )}\n </React.Fragment>\n )}\n </NodeViewWrapper>\n );\n};\n\nInlineDropdown.propTypes = {\n attributes: PropTypes.object,\n selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),\n};\n\nexport default InlineDropdown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,qBAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AAAuD,SAAAD,wBAAAW,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,YAAAA,wBAAAW,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EA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,EAAE,CAAC,EAAE;MAAEC,IAAI,EAAE,CAAC;MAAEkF,KAAK,EAAE;IAAE,CAAE;IACvCU,QAAQ,EAAE,SAAVA,QAAQA,CAAA,EAAQ;MACd,IAAQpF,EAAE,GAAKpC,MAAM,CAACqC,KAAK,CAAnBD,EAAE;MACVA,EAAE,UAAO,CAAC1B,GAAG,EAAEA,GAAG,GAAGT,IAAI,CAAC2C,QAAQ,CAAC;MACnC;MACA;MACA,IAAA6E,yBAAgB,EAACzH,MAAM,EAAE,KAAK,CAAC;MAC/B,OAAOA,MAAM,CAACiB,+BAA+B;MAC7CjB,MAAM,CAACgD,IAAI,CAACC,QAAQ,CAACb,EAAE,CAAC;MACxBX,cAAc,CAAC,KAAK,CAAC;MACrBzB,MAAM,CAAC0H,QAAQ,CAACC,KAAK,CAAC,CAAC;IACzB,CAAE;IACFC,QAAQ,EAAE;EAAM,CACjB,CAAC,EACF5H,MAAM,CAACoH,kBACT,CACY,CAEH,CAAC;AAEtB,CAAC;AAEDtH,cAAc,CAAC+H,SAAS,GAAG;EACzBxH,UAAU,EAAEyH,qBAAS,CAACC,MAAM;EAC5BC,YAAY,EAAEF,qBAAS,CAACG,SAAS,CAAC,CAACH,qBAAS,CAACI,MAAM,EAAEJ,qBAAS,CAACC,MAAM,CAAC;AACxE,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,cAEatI,cAAc","ignoreList":[]}
|
package/lib/extensions/math.js
CHANGED
|
@@ -220,7 +220,8 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
220
220
|
updateAttributes = props.updateAttributes,
|
|
221
221
|
editor = props.editor,
|
|
222
222
|
selected = props.selected,
|
|
223
|
-
options = props.options
|
|
223
|
+
options = props.options,
|
|
224
|
+
getPos = props.getPos;
|
|
224
225
|
var _useState = (0, _react.useState)(selected),
|
|
225
226
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
226
227
|
showToolbar = _useState2[0],
|
|
@@ -251,20 +252,33 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
251
252
|
latex: newLatex
|
|
252
253
|
});
|
|
253
254
|
};
|
|
255
|
+
|
|
256
|
+
// moveCursorAfterNode is set explicitly by the caller (not inferred from
|
|
257
|
+
// editor.state.selection: every keystroke while editing already calls
|
|
258
|
+
// updateAttributes, which replaces this node's content and — per a
|
|
259
|
+
// ProseMirror mapping quirk — collapses any NodeSelection on it into a
|
|
260
|
+
// plain TextSelection right away, so the live selection can't be trusted
|
|
261
|
+
// to still describe this node by the time handleDone runs).
|
|
262
|
+
//
|
|
263
|
+
// - Check icon: always move the cursor to just after this node.
|
|
264
|
+
// - Clicking elsewhere in the editable content while the toolbar was
|
|
265
|
+
// open (see handleClickOutside): leave the cursor where the user
|
|
266
|
+
// actually clicked instead of overriding it.
|
|
254
267
|
var handleDone = function handleDone(newLatex) {
|
|
268
|
+
var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
269
|
+
_ref4$moveCursorAfter = _ref4.moveCursorAfterNode,
|
|
270
|
+
moveCursorAfterNode = _ref4$moveCursorAfter === void 0 ? true : _ref4$moveCursorAfter;
|
|
255
271
|
updateAttributes({
|
|
256
272
|
latex: newLatex
|
|
257
273
|
});
|
|
258
274
|
setShowToolbar(false);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
tr.setSelection(sel);
|
|
267
|
-
editor.view.dispatch(tr);
|
|
275
|
+
if (moveCursorAfterNode && typeof getPos === 'function') {
|
|
276
|
+
var pos = getPos();
|
|
277
|
+
var doc = editor.state.doc;
|
|
278
|
+
var sel = _prosemirrorState.TextSelection.create(doc, pos + node.nodeSize);
|
|
279
|
+
var tr = editor.state.tr.setSelection(sel);
|
|
280
|
+
editor.view.dispatch(tr);
|
|
281
|
+
}
|
|
268
282
|
editor.commands.focus();
|
|
269
283
|
};
|
|
270
284
|
|
|
@@ -368,8 +382,20 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
368
382
|
// event cycle and close the toolbar before it could open.
|
|
369
383
|
var clickedMathNode = !!(target !== null && target !== void 0 && (_target$closest2 = target.closest) !== null && _target$closest2 !== void 0 && _target$closest2.call(target, ".math-node-".concat(timestamp.current)));
|
|
370
384
|
if (toolbarRef.current && !toolbarRef.current.contains(target) && !(target !== null && target !== void 0 && (_target$closest3 = target.closest) !== null && _target$closest3 !== void 0 && _target$closest3.call(target, '[data-inline-node]')) && !equationEditorPopoverOpen && !clickedEquationEditorSelect && !clickedMathNode) {
|
|
385
|
+
var _editor$view;
|
|
371
386
|
setShowToolbar(false);
|
|
372
|
-
|
|
387
|
+
|
|
388
|
+
// If the click landed inside the editable content itself, respect
|
|
389
|
+
// it and leave the cursor where the user clicked. If it landed
|
|
390
|
+
// fully outside the editor (e.g. on other page UI), there's no
|
|
391
|
+
// click position to preserve — falling back to "leave selection
|
|
392
|
+
// untouched" there renders the browser's native NodeSelection
|
|
393
|
+
// fallback caret at the start of the node, so explicitly move the
|
|
394
|
+
// cursor after it instead, same as the check-icon path.
|
|
395
|
+
var clickedInsideEditableContent = !!(editor !== null && editor !== void 0 && (_editor$view = editor.view) !== null && _editor$view !== void 0 && (_editor$view = _editor$view.dom) !== null && _editor$view !== void 0 && _editor$view.contains(target));
|
|
396
|
+
handleDone(node.attrs.latex, {
|
|
397
|
+
moveCursorAfterNode: !clickedInsideEditableContent
|
|
398
|
+
});
|
|
373
399
|
}
|
|
374
400
|
};
|
|
375
401
|
if (showToolbar) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","names":["_react","_interopRequireWildcard","require","_reactDom","_interopRequireDefault","_core","_react2","_prosemirrorState","_mathToolbar","_mathRendering","_toolbar","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ownKeys","keys","getOwnPropertySymbols","filter","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","ensureTextAfterMathPluginKey","PluginKey","generateAdditionalKeys","keyData","undefined","map","key","name","latex","write","label","EnsureTextAfterMathPlugin","exports","mathNodeName","Plugin","appendTransaction","transactions","oldState","newState","some","tr","docChanged","changed","doc","descendants","node","pos","type","nextPos","nodeSize","nextNode","nodeAt","insert","schema","text","nodeBeforeZeroWidthSpace","from","_currentDoc$type","_currentDoc$type2","currentDoc","textContent","ZeroWidthSpaceHandlingPlugin","props","handleKeyDown","view","event","state","dispatch","selection","empty","start","resolved","resolve","maybeNode","nodeAfter","nodeBefore","nodeResolved","setSelection","NodeSelection","create","TextSelection","MathNode","Node","group","inline","atom","addAttributes","wrapper","html","addProseMirrorPlugins","parseHTML","tag","getAttrs","el","getAttribute","innerHTML","addCommands","_this","insertMath","_ref","_node$type","editor","nodes","math","$from","sel","setToolbarOpened","renderHTML","_ref2","HTMLAttributes","dangerouslySetInnerHTML","__html","wrapMath","addNodeView","_this2","ReactNodeViewRenderer","createElement","MathNodeView","options","updateAttributes","selected","_useState","useState","_useState2","_slicedToArray2","showToolbar","setShowToolbar","toolbarRef","useRef","nodeRef","timestamp","Date","now","_useState3","top","left","_useState4","position","setPosition","_ref3","_ref3$math","mathOptions","keypadMode","_mathOptions$controll","controlledKeypadMode","_mathOptions$customKe","customKeys","keyPadCharacterRef","setKeypadInteraction","attrs","handleChange","newLatex","handleDone","_editor$state","commands","focus","useEffect","_selection$node","isNodeSelected","updatePosition","_nodeRef$current","_nodeRef$current$getB","_start$bottom","current","coordsAtPos","nodeRect","getBoundingClientRect","anchorTop","height","anchorLeft","width","anchorBottom","bottom","toolbarHeight","offsetHeight","toolbarWidth","offsetWidth","gap","spaceBelow","window","innerHeight","margin","Math","max","min","innerWidth","portalEl","_tiptapContainerEl","document","body","containerRect","frame","scheduleUpdate","requestAnimationFrame","addEventListener","cancelAnimationFrame","removeEventListener","handleClickOutside","_document$querySelect","_document","_target$closest","_target$closest2","_target$closest3","target","equationEditorListboxes","querySelectorAll","equationEditorPopoverOpen","clickedEquationEditorSelect","id","includes","closest","clickedMathNode","concat","contains","NodeViewWrapper","className","style","display","cursor","ref","onClick","contentEditable","MathPreview","ReactDOM","createPortal","instanceId","zIndex","background","boxShadow","MathToolbar","autoFocus","onChange","onDone","additionalKeys"],"sources":["../../src/extensions/math.js"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { Node } from '@tiptap/core';\nimport { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';\nimport { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath } from '@pie-lib/math-rendering';\nimport { setToolbarOpened } from '../utils/toolbar';\n\nconst ensureTextAfterMathPluginKey = new PluginKey('ensureTextAfterMath');\n\nconst generateAdditionalKeys = (keyData = []) => {\n return keyData.map((key) => ({\n name: key,\n latex: key,\n write: key,\n label: key,\n }));\n};\n\nexport const EnsureTextAfterMathPlugin = (mathNodeName) =>\n new Plugin({\n key: ensureTextAfterMathPluginKey,\n appendTransaction: (transactions, oldState, newState) => {\n // Only act when the doc actually changed\n if (!transactions.some((tr) => tr.docChanged)) {\n return null;\n }\n\n const tr = newState.tr;\n let changed = false;\n\n newState.doc.descendants((node, pos) => {\n if (node.type.name === mathNodeName) {\n const nextPos = pos + node.nodeSize;\n const nextNode = newState.doc.nodeAt(nextPos);\n\n // If there's no node after, or the next node isn't text, insert a space\n if (!nextNode || nextNode.type.name !== 'text') {\n tr.insert(nextPos, newState.schema.text('\\u200b'));\n changed = true;\n }\n }\n });\n\n return changed ? tr : null;\n },\n });\n\nconst nodeBeforeZeroWidthSpace = (doc, from) => {\n let i;\n\n // finding if previous to the cursor there's a zero-width space\n // and a non-text element, and deleting everything until the space\n for (i = from; i > 0; i--) {\n const currentDoc = doc.nodeAt(i);\n\n if (currentDoc?.type?.name === 'text' && currentDoc.textContent !== '\\u200b') {\n return -1;\n }\n\n if (currentDoc && currentDoc?.type?.name !== 'text') {\n break;\n }\n }\n\n return i;\n};\n\nexport const ZeroWidthSpaceHandlingPlugin = new Plugin({\n key: new PluginKey('zeroWidthSpaceHandling'),\n props: {\n handleKeyDown(view, event) {\n const { state, dispatch } = view;\n const { selection, doc } = state;\n const { from, empty } = selection;\n\n if (empty && event.key === 'Backspace' && from > 0) {\n const start = nodeBeforeZeroWidthSpace(doc, from);\n\n if (start === -1) {\n return false;\n }\n\n const tr = state.tr.delete(start, from);\n dispatch(tr);\n return true; // handled\n }\n\n if (empty && event.key === 'ArrowLeft' && from > 0) {\n const start = nodeBeforeZeroWidthSpace(doc, from);\n\n if (start === -1) {\n return false;\n }\n\n const resolved = state.doc.resolve(start);\n const maybeNode = resolved.nodeAfter || resolved.nodeBefore;\n\n // Check if there's an inline selectable node (e.g., your math node)\n if (maybeNode) {\n const nodeResolved = state.doc.resolve(start);\n const tr = state.tr.setSelection(NodeSelection.create(state.doc, nodeResolved.pos));\n dispatch(tr);\n return true;\n } else {\n // Just move the text cursor before the zwsp\n const tr = state.tr.setSelection(TextSelection.create(state.doc, from - 2));\n dispatch(tr);\n return true;\n }\n }\n\n return false;\n },\n },\n});\n\nexport const MathNode = Node.create({\n name: 'math',\n group: 'inline',\n inline: true,\n atom: true,\n\n addAttributes() {\n return {\n latex: { default: '' },\n wrapper: { default: null },\n html: { default: null },\n };\n },\n\n addProseMirrorPlugins() {\n return [EnsureTextAfterMathPlugin(this.name), ZeroWidthSpaceHandlingPlugin];\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-latex]',\n getAttrs: (el) => ({\n latex: el.getAttribute('data-raw') || el.textContent,\n }),\n },\n {\n tag: 'span[data-type=\"mathml\"]',\n getAttrs: (el) => ({\n html: el.innerHTML,\n }),\n },\n ];\n },\n\n addCommands() {\n return {\n insertMath:\n (latex = '') =>\n ({ tr, editor, dispatch }) => {\n const { state } = editor.view;\n const node = state.schema.nodes.math.create({\n latex,\n });\n const { selection } = state;\n\n // The inserted node is typically just before the cursor\n const pos = selection.$from.pos;\n\n tr.insert(pos, node);\n\n if (node?.type?.name === this.name) {\n // Create a NodeSelection from the current doc\n const sel = NodeSelection.create(tr.doc, selection.$from.pos);\n\n // Build a fresh transaction from the current state and set the selection\n tr.setSelection(sel);\n }\n\n dispatch(tr);\n\n setToolbarOpened(editor, true);\n return true;\n },\n };\n },\n\n renderHTML({ HTMLAttributes }) {\n if (HTMLAttributes.html) {\n return ['span', { 'data-type': 'mathml', dangerouslySetInnerHTML: { __html: HTMLAttributes.html } }];\n }\n\n return [\n 'span',\n { 'data-latex': '', 'data-raw': HTMLAttributes.latex },\n wrapMath(HTMLAttributes.latex, HTMLAttributes.wrapper),\n ];\n },\n\n addNodeView() {\n return ReactNodeViewRenderer((props) => <MathNodeView {...{ ...props, options: this.options }} />);\n },\n});\n\nexport const MathNodeView = (props) => {\n const { node, updateAttributes, editor, selected, options } = props;\n const [showToolbar, setShowToolbar] = useState(selected);\n const toolbarRef = useRef(null);\n const nodeRef = useRef(null);\n const timestamp = useRef(Date.now());\n const [position, setPosition] = useState({ top: 0, left: 0 });\n const { math: mathOptions = {} } = options || {};\n const {\n keypadMode,\n controlledKeypadMode = true,\n customKeys = [],\n keyPadCharacterRef,\n setKeypadInteraction,\n } = mathOptions;\n\n const latex = node.attrs.latex || '';\n\n const handleChange = (newLatex) => {\n updateAttributes({ latex: newLatex });\n };\n\n const handleDone = (newLatex) => {\n updateAttributes({ latex: newLatex });\n setShowToolbar(false);\n\n const { selection, tr, doc } = editor.state;\n const sel = TextSelection.create(doc, selection.from + 1);\n\n // Build a fresh transaction from the current state and set the selection\n tr.setSelection(sel);\n editor.view.dispatch(tr);\n editor.commands.focus();\n };\n\n // Only open the toolbar when this node is *explicitly* selected\n // via a NodeSelection — not when it's merely included in a broader\n // TextSelection or AllSelection (e.g. click-drag across math, or Cmd+A).\n useEffect(() => {\n if (!selected) return;\n\n const { selection } = editor.state;\n const isNodeSelected = selection.node?.type?.name === 'math';\n\n if (isNodeSelected) {\n setShowToolbar(true);\n }\n }, [selected, editor]);\n\n useEffect(() => {\n setToolbarOpened(editor, selected || showToolbar);\n }, [editor, showToolbar, selected]);\n\n useEffect(() => {\n if (!editor || !showToolbar) {\n setPosition({ top: 0, left: 0 });\n return;\n }\n\n // Clamp in viewport coordinates, then convert to portal-container-relative values\n // for position: absolute (toolbar is portaled into _tiptapContainerEl or document.body).\n const updatePosition = () => {\n if (!toolbarRef.current) {\n return;\n }\n\n const { from } = editor.state.selection;\n const start = editor.view.coordsAtPos(from);\n const nodeRect = nodeRef.current?.getBoundingClientRect?.();\n\n // Anchor to the math node element when available; fall back to selection coords.\n const anchorTop = nodeRect?.height ? nodeRect.top : start.top;\n const anchorLeft = nodeRect?.width ? nodeRect.left : start.left;\n const anchorBottom = nodeRect?.height ? nodeRect.bottom : (start.bottom ?? start.top);\n\n const toolbarHeight = toolbarRef.current.offsetHeight;\n const toolbarWidth = toolbarRef.current.offsetWidth;\n\n const gap = 0;\n const spaceBelow = window.innerHeight - (anchorBottom + gap);\n\n // Place the toolbar's top-left corner directly below the anchor; flip above when needed.\n let top = spaceBelow >= toolbarHeight ? anchorBottom + gap : anchorTop - toolbarHeight - gap;\n let left = anchorLeft;\n\n const margin = 8;\n top = Math.max(margin, Math.min(top, window.innerHeight - toolbarHeight - margin));\n left = Math.max(margin, Math.min(left, window.innerWidth - toolbarWidth - margin));\n\n const portalEl = editor._tiptapContainerEl || document.body;\n const containerRect = portalEl.getBoundingClientRect();\n\n setPosition({\n top: top - containerRect.top,\n left: left - containerRect.left,\n });\n };\n\n updatePosition();\n\n let frame = null;\n const scheduleUpdate = () => {\n if (frame !== null) {\n return;\n }\n\n frame = requestAnimationFrame(() => {\n frame = null;\n updatePosition();\n });\n };\n\n frame = requestAnimationFrame(() => {\n frame = null;\n updatePosition();\n });\n\n window.addEventListener('scroll', scheduleUpdate, true);\n window.addEventListener('resize', scheduleUpdate);\n\n return () => {\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\n\n window.removeEventListener('scroll', scheduleUpdate, true);\n window.removeEventListener('resize', scheduleUpdate);\n };\n }, [editor, showToolbar]);\n\n useEffect(() => {\n const handleClickOutside = (event) => {\n const target = event?.target;\n\n // MUI's `Select` renders its dropdown options in a portal attached to `document.body`.\n // Those clicks should not dismiss the math toolbar.\n const equationEditorListboxes =\n document.querySelectorAll?.(\n '[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]',\n ) || [];\n\n const equationEditorPopoverOpen = equationEditorListboxes.length > 0;\n const clickedEquationEditorSelect =\n !!(target?.id && target.id.includes('equation-editor-select')) ||\n !!target?.closest?.('[id*=\"equation-editor-select\"]');\n\n // If the click originated from the math node preview itself (the element\n // that opens the toolbar), ignore it here — the node's own onClick handler\n // will keep/re-open the toolbar. Without this guard, closing and then\n // immediately clicking the math node would fire this listener in the same\n // event cycle and close the toolbar before it could open.\n const clickedMathNode = !!target?.closest?.(`.math-node-${timestamp.current}`);\n\n if (\n toolbarRef.current &&\n !toolbarRef.current.contains(target) &&\n !target?.closest?.('[data-inline-node]') &&\n !equationEditorPopoverOpen &&\n !clickedEquationEditorSelect &&\n !clickedMathNode\n ) {\n setShowToolbar(false);\n handleDone(node.attrs.latex);\n }\n };\n\n if (showToolbar) {\n // Use `click` (not `mousedown`) so interacting with browser UI like the scrollbar\n // doesn't automatically dismiss the math toolbar.\n document.addEventListener('click', handleClickOutside);\n } else {\n document.removeEventListener('click', handleClickOutside);\n }\n\n return () => document.removeEventListener('click', handleClickOutside);\n }, [editor, showToolbar, node]);\n\n return (\n <NodeViewWrapper\n className={`math-node-${timestamp.current}`}\n style={{\n display: 'inline-flex',\n cursor: 'pointer',\n margin: '0 4px',\n }}\n data-selected={selected}\n >\n <div ref={nodeRef} onClick={() => setShowToolbar(true)} contentEditable={false}>\n <MathPreview latex={latex} />\n </div>\n {showToolbar &&\n ReactDOM.createPortal(\n <div\n ref={toolbarRef}\n data-toolbar-for={editor.instanceId}\n style={{\n position: 'absolute',\n top: `${position.top}px`,\n left: `${position.left}px`,\n zIndex: 1000,\n background: 'var(--editable-html-toolbar-bg, #efefef)',\n boxShadow:\n '0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',\n }}\n >\n <MathToolbar\n latex={latex}\n autoFocus\n onChange={handleChange}\n onDone={handleDone}\n keypadMode={keypadMode}\n controlledKeypadMode={controlledKeypadMode}\n additionalKeys={generateAdditionalKeys(customKeys)}\n keyPadCharacterRef={keyPadCharacterRef}\n setKeypadInteraction={setKeypadInteraction}\n />\n </div>,\n editor?._tiptapContainerEl || document.body,\n )}\n </NodeViewWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAAoD,SAAAD,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,wBAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,G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VzM,KAAK,EAAEA,KAAM;IACb0M,SAAS;IACTC,QAAQ,EAAEjF,YAAa;IACvBkF,MAAM,EAAEhF,UAAW;IACnBV,UAAU,EAAEA,UAAW;IACvBE,oBAAoB,EAAEA,oBAAqB;IAC3CyF,cAAc,EAAEnN,sBAAsB,CAAC4H,UAAU,CAAE;IACnDC,kBAAkB,EAAEA,kBAAmB;IACvCC,oBAAoB,EAAEA;EAAqB,CAC5C,CACE,CAAC,EACN,CAAA/C,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEsF,kBAAkB,KAAIC,QAAQ,CAACC,IACzC,CACa,CAAC;AAEtB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"math.js","names":["_react","_interopRequireWildcard","require","_reactDom","_interopRequireDefault","_core","_react2","_prosemirrorState","_mathToolbar","_mathRendering","_toolbar","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ownKeys","keys","getOwnPropertySymbols","filter","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","ensureTextAfterMathPluginKey","PluginKey","generateAdditionalKeys","keyData","undefined","map","key","name","latex","write","label","EnsureTextAfterMathPlugin","exports","mathNodeName","Plugin","appendTransaction","transactions","oldState","newState","some","tr","docChanged","changed","doc","descendants","node","pos","type","nextPos","nodeSize","nextNode","nodeAt","insert","schema","text","nodeBeforeZeroWidthSpace","from","_currentDoc$type","_currentDoc$type2","currentDoc","textContent","ZeroWidthSpaceHandlingPlugin","props","handleKeyDown","view","event","state","dispatch","selection","empty","start","resolved","resolve","maybeNode","nodeAfter","nodeBefore","nodeResolved","setSelection","NodeSelection","create","TextSelection","MathNode","Node","group","inline","atom","addAttributes","wrapper","html","addProseMirrorPlugins","parseHTML","tag","getAttrs","el","getAttribute","innerHTML","addCommands","_this","insertMath","_ref","_node$type","editor","nodes","math","$from","sel","setToolbarOpened","renderHTML","_ref2","HTMLAttributes","dangerouslySetInnerHTML","__html","wrapMath","addNodeView","_this2","ReactNodeViewRenderer","createElement","MathNodeView","options","updateAttributes","selected","getPos","_useState","useState","_useState2","_slicedToArray2","showToolbar","setShowToolbar","toolbarRef","useRef","nodeRef","timestamp","Date","now","_useState3","top","left","_useState4","position","setPosition","_ref3","_ref3$math","mathOptions","keypadMode","_mathOptions$controll","controlledKeypadMode","_mathOptions$customKe","customKeys","keyPadCharacterRef","setKeypadInteraction","attrs","handleChange","newLatex","handleDone","_ref4","_ref4$moveCursorAfter","moveCursorAfterNode","commands","focus","useEffect","_selection$node","isNodeSelected","updatePosition","_nodeRef$current","_nodeRef$current$getB","_start$bottom","current","coordsAtPos","nodeRect","getBoundingClientRect","anchorTop","height","anchorLeft","width","anchorBottom","bottom","toolbarHeight","offsetHeight","toolbarWidth","offsetWidth","gap","spaceBelow","window","innerHeight","margin","Math","max","min","innerWidth","portalEl","_tiptapContainerEl","document","body","containerRect","frame","scheduleUpdate","requestAnimationFrame","addEventListener","cancelAnimationFrame","removeEventListener","handleClickOutside","_document$querySelect","_document","_target$closest","_target$closest2","_target$closest3","target","equationEditorListboxes","querySelectorAll","equationEditorPopoverOpen","clickedEquationEditorSelect","id","includes","closest","clickedMathNode","concat","contains","_editor$view","clickedInsideEditableContent","dom","NodeViewWrapper","className","style","display","cursor","ref","onClick","contentEditable","MathPreview","ReactDOM","createPortal","instanceId","zIndex","background","boxShadow","MathToolbar","autoFocus","onChange","onDone","additionalKeys"],"sources":["../../src/extensions/math.js"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport ReactDOM from 'react-dom';\nimport { Node } from '@tiptap/core';\nimport { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react';\nimport { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { MathPreview, MathToolbar } from '@pie-lib/math-toolbar';\nimport { wrapMath } from '@pie-lib/math-rendering';\nimport { setToolbarOpened } from '../utils/toolbar';\n\nconst ensureTextAfterMathPluginKey = new PluginKey('ensureTextAfterMath');\n\nconst generateAdditionalKeys = (keyData = []) => {\n return keyData.map((key) => ({\n name: key,\n latex: key,\n write: key,\n label: key,\n }));\n};\n\nexport const EnsureTextAfterMathPlugin = (mathNodeName) =>\n new Plugin({\n key: ensureTextAfterMathPluginKey,\n appendTransaction: (transactions, oldState, newState) => {\n // Only act when the doc actually changed\n if (!transactions.some((tr) => tr.docChanged)) {\n return null;\n }\n\n const tr = newState.tr;\n let changed = false;\n\n newState.doc.descendants((node, pos) => {\n if (node.type.name === mathNodeName) {\n const nextPos = pos + node.nodeSize;\n const nextNode = newState.doc.nodeAt(nextPos);\n\n // If there's no node after, or the next node isn't text, insert a space\n if (!nextNode || nextNode.type.name !== 'text') {\n tr.insert(nextPos, newState.schema.text('\\u200b'));\n changed = true;\n }\n }\n });\n\n return changed ? tr : null;\n },\n });\n\nconst nodeBeforeZeroWidthSpace = (doc, from) => {\n let i;\n\n // finding if previous to the cursor there's a zero-width space\n // and a non-text element, and deleting everything until the space\n for (i = from; i > 0; i--) {\n const currentDoc = doc.nodeAt(i);\n\n if (currentDoc?.type?.name === 'text' && currentDoc.textContent !== '\\u200b') {\n return -1;\n }\n\n if (currentDoc && currentDoc?.type?.name !== 'text') {\n break;\n }\n }\n\n return i;\n};\n\nexport const ZeroWidthSpaceHandlingPlugin = new Plugin({\n key: new PluginKey('zeroWidthSpaceHandling'),\n props: {\n handleKeyDown(view, event) {\n const { state, dispatch } = view;\n const { selection, doc } = state;\n const { from, empty } = selection;\n\n if (empty && event.key === 'Backspace' && from > 0) {\n const start = nodeBeforeZeroWidthSpace(doc, from);\n\n if (start === -1) {\n return false;\n }\n\n const tr = state.tr.delete(start, from);\n dispatch(tr);\n return true; // handled\n }\n\n if (empty && event.key === 'ArrowLeft' && from > 0) {\n const start = nodeBeforeZeroWidthSpace(doc, from);\n\n if (start === -1) {\n return false;\n }\n\n const resolved = state.doc.resolve(start);\n const maybeNode = resolved.nodeAfter || resolved.nodeBefore;\n\n // Check if there's an inline selectable node (e.g., your math node)\n if (maybeNode) {\n const nodeResolved = state.doc.resolve(start);\n const tr = state.tr.setSelection(NodeSelection.create(state.doc, nodeResolved.pos));\n dispatch(tr);\n return true;\n } else {\n // Just move the text cursor before the zwsp\n const tr = state.tr.setSelection(TextSelection.create(state.doc, from - 2));\n dispatch(tr);\n return true;\n }\n }\n\n return false;\n },\n },\n});\n\nexport const MathNode = Node.create({\n name: 'math',\n group: 'inline',\n inline: true,\n atom: true,\n\n addAttributes() {\n return {\n latex: { default: '' },\n wrapper: { default: null },\n html: { default: null },\n };\n },\n\n addProseMirrorPlugins() {\n return [EnsureTextAfterMathPlugin(this.name), ZeroWidthSpaceHandlingPlugin];\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-latex]',\n getAttrs: (el) => ({\n latex: el.getAttribute('data-raw') || el.textContent,\n }),\n },\n {\n tag: 'span[data-type=\"mathml\"]',\n getAttrs: (el) => ({\n html: el.innerHTML,\n }),\n },\n ];\n },\n\n addCommands() {\n return {\n insertMath:\n (latex = '') =>\n ({ tr, editor, dispatch }) => {\n const { state } = editor.view;\n const node = state.schema.nodes.math.create({\n latex,\n });\n const { selection } = state;\n\n // The inserted node is typically just before the cursor\n const pos = selection.$from.pos;\n\n tr.insert(pos, node);\n\n if (node?.type?.name === this.name) {\n // Create a NodeSelection from the current doc\n const sel = NodeSelection.create(tr.doc, selection.$from.pos);\n\n // Build a fresh transaction from the current state and set the selection\n tr.setSelection(sel);\n }\n\n dispatch(tr);\n\n setToolbarOpened(editor, true);\n return true;\n },\n };\n },\n\n renderHTML({ HTMLAttributes }) {\n if (HTMLAttributes.html) {\n return ['span', { 'data-type': 'mathml', dangerouslySetInnerHTML: { __html: HTMLAttributes.html } }];\n }\n\n return [\n 'span',\n { 'data-latex': '', 'data-raw': HTMLAttributes.latex },\n wrapMath(HTMLAttributes.latex, HTMLAttributes.wrapper),\n ];\n },\n\n addNodeView() {\n return ReactNodeViewRenderer((props) => <MathNodeView {...{ ...props, options: this.options }} />);\n },\n});\n\nexport const MathNodeView = (props) => {\n const { node, updateAttributes, editor, selected, options, getPos } = props;\n const [showToolbar, setShowToolbar] = useState(selected);\n const toolbarRef = useRef(null);\n const nodeRef = useRef(null);\n const timestamp = useRef(Date.now());\n const [position, setPosition] = useState({ top: 0, left: 0 });\n const { math: mathOptions = {} } = options || {};\n const {\n keypadMode,\n controlledKeypadMode = true,\n customKeys = [],\n keyPadCharacterRef,\n setKeypadInteraction,\n } = mathOptions;\n\n const latex = node.attrs.latex || '';\n\n const handleChange = (newLatex) => {\n updateAttributes({ latex: newLatex });\n };\n\n // moveCursorAfterNode is set explicitly by the caller (not inferred from\n // editor.state.selection: every keystroke while editing already calls\n // updateAttributes, which replaces this node's content and — per a\n // ProseMirror mapping quirk — collapses any NodeSelection on it into a\n // plain TextSelection right away, so the live selection can't be trusted\n // to still describe this node by the time handleDone runs).\n //\n // - Check icon: always move the cursor to just after this node.\n // - Clicking elsewhere in the editable content while the toolbar was\n // open (see handleClickOutside): leave the cursor where the user\n // actually clicked instead of overriding it.\n const handleDone = (newLatex, { moveCursorAfterNode = true } = {}) => {\n updateAttributes({ latex: newLatex });\n setShowToolbar(false);\n\n if (moveCursorAfterNode && typeof getPos === 'function') {\n const pos = getPos();\n const { doc } = editor.state;\n const sel = TextSelection.create(doc, pos + node.nodeSize);\n const tr = editor.state.tr.setSelection(sel);\n editor.view.dispatch(tr);\n }\n\n editor.commands.focus();\n };\n\n // Only open the toolbar when this node is *explicitly* selected\n // via a NodeSelection — not when it's merely included in a broader\n // TextSelection or AllSelection (e.g. click-drag across math, or Cmd+A).\n useEffect(() => {\n if (!selected) return;\n\n const { selection } = editor.state;\n const isNodeSelected = selection.node?.type?.name === 'math';\n\n if (isNodeSelected) {\n setShowToolbar(true);\n }\n }, [selected, editor]);\n\n useEffect(() => {\n setToolbarOpened(editor, selected || showToolbar);\n }, [editor, showToolbar, selected]);\n\n useEffect(() => {\n if (!editor || !showToolbar) {\n setPosition({ top: 0, left: 0 });\n return;\n }\n\n // Clamp in viewport coordinates, then convert to portal-container-relative values\n // for position: absolute (toolbar is portaled into _tiptapContainerEl or document.body).\n const updatePosition = () => {\n if (!toolbarRef.current) {\n return;\n }\n\n const { from } = editor.state.selection;\n const start = editor.view.coordsAtPos(from);\n const nodeRect = nodeRef.current?.getBoundingClientRect?.();\n\n // Anchor to the math node element when available; fall back to selection coords.\n const anchorTop = nodeRect?.height ? nodeRect.top : start.top;\n const anchorLeft = nodeRect?.width ? nodeRect.left : start.left;\n const anchorBottom = nodeRect?.height ? nodeRect.bottom : (start.bottom ?? start.top);\n\n const toolbarHeight = toolbarRef.current.offsetHeight;\n const toolbarWidth = toolbarRef.current.offsetWidth;\n\n const gap = 0;\n const spaceBelow = window.innerHeight - (anchorBottom + gap);\n\n // Place the toolbar's top-left corner directly below the anchor; flip above when needed.\n let top = spaceBelow >= toolbarHeight ? anchorBottom + gap : anchorTop - toolbarHeight - gap;\n let left = anchorLeft;\n\n const margin = 8;\n top = Math.max(margin, Math.min(top, window.innerHeight - toolbarHeight - margin));\n left = Math.max(margin, Math.min(left, window.innerWidth - toolbarWidth - margin));\n\n const portalEl = editor._tiptapContainerEl || document.body;\n const containerRect = portalEl.getBoundingClientRect();\n\n setPosition({\n top: top - containerRect.top,\n left: left - containerRect.left,\n });\n };\n\n updatePosition();\n\n let frame = null;\n const scheduleUpdate = () => {\n if (frame !== null) {\n return;\n }\n\n frame = requestAnimationFrame(() => {\n frame = null;\n updatePosition();\n });\n };\n\n frame = requestAnimationFrame(() => {\n frame = null;\n updatePosition();\n });\n\n window.addEventListener('scroll', scheduleUpdate, true);\n window.addEventListener('resize', scheduleUpdate);\n\n return () => {\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\n\n window.removeEventListener('scroll', scheduleUpdate, true);\n window.removeEventListener('resize', scheduleUpdate);\n };\n }, [editor, showToolbar]);\n\n useEffect(() => {\n const handleClickOutside = (event) => {\n const target = event?.target;\n\n // MUI's `Select` renders its dropdown options in a portal attached to `document.body`.\n // Those clicks should not dismiss the math toolbar.\n const equationEditorListboxes =\n document.querySelectorAll?.(\n '[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]',\n ) || [];\n\n const equationEditorPopoverOpen = equationEditorListboxes.length > 0;\n const clickedEquationEditorSelect =\n !!(target?.id && target.id.includes('equation-editor-select')) ||\n !!target?.closest?.('[id*=\"equation-editor-select\"]');\n\n // If the click originated from the math node preview itself (the element\n // that opens the toolbar), ignore it here — the node's own onClick handler\n // will keep/re-open the toolbar. Without this guard, closing and then\n // immediately clicking the math node would fire this listener in the same\n // event cycle and close the toolbar before it could open.\n const clickedMathNode = !!target?.closest?.(`.math-node-${timestamp.current}`);\n\n if (\n toolbarRef.current &&\n !toolbarRef.current.contains(target) &&\n !target?.closest?.('[data-inline-node]') &&\n !equationEditorPopoverOpen &&\n !clickedEquationEditorSelect &&\n !clickedMathNode\n ) {\n setShowToolbar(false);\n\n // If the click landed inside the editable content itself, respect\n // it and leave the cursor where the user clicked. If it landed\n // fully outside the editor (e.g. on other page UI), there's no\n // click position to preserve — falling back to \"leave selection\n // untouched\" there renders the browser's native NodeSelection\n // fallback caret at the start of the node, so explicitly move the\n // cursor after it instead, same as the check-icon path.\n const clickedInsideEditableContent = !!editor?.view?.dom?.contains(target);\n handleDone(node.attrs.latex, { moveCursorAfterNode: !clickedInsideEditableContent });\n }\n };\n\n if (showToolbar) {\n // Use `click` (not `mousedown`) so interacting with browser UI like the scrollbar\n // doesn't automatically dismiss the math toolbar.\n document.addEventListener('click', handleClickOutside);\n } else {\n document.removeEventListener('click', handleClickOutside);\n }\n\n return () => document.removeEventListener('click', handleClickOutside);\n }, [editor, showToolbar, node]);\n\n return (\n <NodeViewWrapper\n className={`math-node-${timestamp.current}`}\n style={{\n display: 'inline-flex',\n cursor: 'pointer',\n margin: '0 4px',\n }}\n data-selected={selected}\n >\n <div ref={nodeRef} onClick={() => setShowToolbar(true)} contentEditable={false}>\n <MathPreview latex={latex} />\n </div>\n {showToolbar &&\n ReactDOM.createPortal(\n <div\n ref={toolbarRef}\n data-toolbar-for={editor.instanceId}\n style={{\n position: 'absolute',\n top: `${position.top}px`,\n left: `${position.left}px`,\n zIndex: 1000,\n background: 'var(--editable-html-toolbar-bg, #efefef)',\n boxShadow:\n '0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',\n }}\n >\n <MathToolbar\n latex={latex}\n autoFocus\n onChange={handleChange}\n onDone={handleDone}\n keypadMode={keypadMode}\n controlledKeypadMode={controlledKeypadMode}\n additionalKeys={generateAdditionalKeys(customKeys)}\n keyPadCharacterRef={keyPadCharacterRef}\n setKeypadInteraction={setKeypadInteraction}\n />\n </div>,\n editor?._tiptapContainerEl || document.body,\n )}\n </NodeViewWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAAoD,SAAAD,wBAAAU,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAZ,uBAAA,YAAAA,wBAAAU,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,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
},
|
|
6
|
-
"version": "2.1.2-next.
|
|
6
|
+
"version": "2.1.2-next.91+a418b6c75",
|
|
7
7
|
"description": "",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"main": "lib/index.js",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "a418b6c757d2a50fa6a92fac217483efa3d75b85",
|
|
63
63
|
"scripts": {}
|
|
64
64
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
|
+
import { renderMath } from '@pie-lib/math-rendering';
|
|
3
4
|
import InlineDropdown from '../respArea/InlineDropdown';
|
|
4
5
|
|
|
6
|
+
jest.mock('@pie-lib/math-rendering', () => ({
|
|
7
|
+
renderMath: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
5
10
|
jest.mock('@tiptap/react', () => ({
|
|
6
11
|
NodeViewWrapper: ({ children, ...props }) => (
|
|
7
12
|
<div data-testid="node-view-wrapper" {...props}>
|
|
@@ -104,6 +109,32 @@ describe('InlineDropdown', () => {
|
|
|
104
109
|
expect(valueDiv).toBeInTheDocument();
|
|
105
110
|
});
|
|
106
111
|
|
|
112
|
+
it('renders math inside the value control on mount', () => {
|
|
113
|
+
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
114
|
+
const valueDiv = container.querySelector('div[style*="border"]');
|
|
115
|
+
|
|
116
|
+
expect(renderMath).toHaveBeenCalledWith(valueDiv);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('re-renders math when the value changes', () => {
|
|
120
|
+
const updatedNode = {
|
|
121
|
+
...mockNode,
|
|
122
|
+
attrs: {
|
|
123
|
+
...mockNode.attrs,
|
|
124
|
+
value: '<span>Updated math</span>',
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const { container, rerender } = render(<InlineDropdown {...defaultProps} />);
|
|
129
|
+
|
|
130
|
+
renderMath.mockClear();
|
|
131
|
+
|
|
132
|
+
rerender(<InlineDropdown {...defaultProps} node={updatedNode} />);
|
|
133
|
+
|
|
134
|
+
const valueDiv = container.querySelector('div[style*="border"]');
|
|
135
|
+
expect(renderMath).toHaveBeenCalledWith(valueDiv);
|
|
136
|
+
});
|
|
137
|
+
|
|
107
138
|
it('uses 2px horizontal margin on the value control and no horizontal margin on the wrapper', () => {
|
|
108
139
|
const { container, getByTestId } = render(<InlineDropdown {...defaultProps} />);
|
|
109
140
|
const valueDiv = container.querySelector('div[style*="border"]');
|
|
@@ -476,7 +507,7 @@ describe('InlineDropdown', () => {
|
|
|
476
507
|
await waitFor(() => {
|
|
477
508
|
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
478
509
|
});
|
|
479
|
-
});
|
|
510
|
+
});
|
|
480
511
|
|
|
481
512
|
it('renders delete control on portaled custom toolbar when container el is set', async () => {
|
|
482
513
|
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { renderMath } from '@pie-lib/math-rendering';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import { NodeViewWrapper } from '@tiptap/react';
|
|
4
6
|
import { NodeSelection } from 'prosemirror-state';
|
|
5
7
|
import { Chevron } from '../icons/RespArea';
|
|
6
|
-
import ReactDOM from 'react-dom';
|
|
7
8
|
import CustomToolbarWrapper from '../../extensions/custom-toolbar-wrapper';
|
|
8
9
|
import { setToolbarOpened } from '../../utils/toolbar';
|
|
9
10
|
|
|
@@ -16,6 +17,7 @@ const InlineDropdown = (props) => {
|
|
|
16
17
|
const toolbarRef = useRef(null);
|
|
17
18
|
const toolbarEditor = useRef(null);
|
|
18
19
|
const pendingCloseRequest = useRef(false);
|
|
20
|
+
const elementRef = useRef(null);
|
|
19
21
|
|
|
20
22
|
const isHeld = () =>
|
|
21
23
|
editor._holdInlineDropdownToolbarIndex != null &&
|
|
@@ -93,13 +95,16 @@ const InlineDropdown = (props) => {
|
|
|
93
95
|
}
|
|
94
96
|
}, [editor, node, selected]);
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
98
|
const isScrollbarClicked = (event) =>
|
|
99
99
|
event.clientX > document.documentElement.clientWidth ||
|
|
100
100
|
event.clientY > document.documentElement.clientHeight ||
|
|
101
101
|
event.target === document.documentElement;
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (elementRef.current && typeof renderMath === 'function') {
|
|
105
|
+
renderMath(elementRef.current);
|
|
106
|
+
}
|
|
107
|
+
}, [value]);
|
|
103
108
|
|
|
104
109
|
useEffect(() => {
|
|
105
110
|
// Calculate position relative to selection
|
|
@@ -113,10 +118,10 @@ const InlineDropdown = (props) => {
|
|
|
113
118
|
});
|
|
114
119
|
|
|
115
120
|
const handleClickOutside = (event) => {
|
|
116
|
-
|
|
117
|
-
if( isScrollbarClicked(event) ) {
|
|
121
|
+
if (isScrollbarClicked(event)) {
|
|
118
122
|
return;
|
|
119
123
|
}
|
|
124
|
+
|
|
120
125
|
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
|
|
121
126
|
|
|
122
127
|
if (
|
|
@@ -151,6 +156,7 @@ const InlineDropdown = (props) => {
|
|
|
151
156
|
}}
|
|
152
157
|
>
|
|
153
158
|
<div
|
|
159
|
+
ref={elementRef}
|
|
154
160
|
style={{
|
|
155
161
|
display: 'inline-flex',
|
|
156
162
|
minWidth: '178px',
|
|
@@ -416,6 +416,7 @@ describe('MathNodeView', () => {
|
|
|
416
416
|
attrs: {
|
|
417
417
|
latex: 'x^2',
|
|
418
418
|
},
|
|
419
|
+
nodeSize: 1,
|
|
419
420
|
};
|
|
420
421
|
|
|
421
422
|
let defaultProps;
|
|
@@ -429,6 +430,7 @@ describe('MathNodeView', () => {
|
|
|
429
430
|
editor: createMockEditor(),
|
|
430
431
|
selected: false,
|
|
431
432
|
options: {},
|
|
433
|
+
getPos: jest.fn(() => 0),
|
|
432
434
|
};
|
|
433
435
|
});
|
|
434
436
|
|
package/src/extensions/math.js
CHANGED
|
@@ -201,7 +201,7 @@ export const MathNode = Node.create({
|
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
export const MathNodeView = (props) => {
|
|
204
|
-
const { node, updateAttributes, editor, selected, options } = props;
|
|
204
|
+
const { node, updateAttributes, editor, selected, options, getPos } = props;
|
|
205
205
|
const [showToolbar, setShowToolbar] = useState(selected);
|
|
206
206
|
const toolbarRef = useRef(null);
|
|
207
207
|
const nodeRef = useRef(null);
|
|
@@ -222,16 +222,29 @@ export const MathNodeView = (props) => {
|
|
|
222
222
|
updateAttributes({ latex: newLatex });
|
|
223
223
|
};
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
// moveCursorAfterNode is set explicitly by the caller (not inferred from
|
|
226
|
+
// editor.state.selection: every keystroke while editing already calls
|
|
227
|
+
// updateAttributes, which replaces this node's content and — per a
|
|
228
|
+
// ProseMirror mapping quirk — collapses any NodeSelection on it into a
|
|
229
|
+
// plain TextSelection right away, so the live selection can't be trusted
|
|
230
|
+
// to still describe this node by the time handleDone runs).
|
|
231
|
+
//
|
|
232
|
+
// - Check icon: always move the cursor to just after this node.
|
|
233
|
+
// - Clicking elsewhere in the editable content while the toolbar was
|
|
234
|
+
// open (see handleClickOutside): leave the cursor where the user
|
|
235
|
+
// actually clicked instead of overriding it.
|
|
236
|
+
const handleDone = (newLatex, { moveCursorAfterNode = true } = {}) => {
|
|
226
237
|
updateAttributes({ latex: newLatex });
|
|
227
238
|
setShowToolbar(false);
|
|
228
239
|
|
|
229
|
-
|
|
230
|
-
|
|
240
|
+
if (moveCursorAfterNode && typeof getPos === 'function') {
|
|
241
|
+
const pos = getPos();
|
|
242
|
+
const { doc } = editor.state;
|
|
243
|
+
const sel = TextSelection.create(doc, pos + node.nodeSize);
|
|
244
|
+
const tr = editor.state.tr.setSelection(sel);
|
|
245
|
+
editor.view.dispatch(tr);
|
|
246
|
+
}
|
|
231
247
|
|
|
232
|
-
// Build a fresh transaction from the current state and set the selection
|
|
233
|
-
tr.setSelection(sel);
|
|
234
|
-
editor.view.dispatch(tr);
|
|
235
248
|
editor.commands.focus();
|
|
236
249
|
};
|
|
237
250
|
|
|
@@ -362,7 +375,16 @@ export const MathNodeView = (props) => {
|
|
|
362
375
|
!clickedMathNode
|
|
363
376
|
) {
|
|
364
377
|
setShowToolbar(false);
|
|
365
|
-
|
|
378
|
+
|
|
379
|
+
// If the click landed inside the editable content itself, respect
|
|
380
|
+
// it and leave the cursor where the user clicked. If it landed
|
|
381
|
+
// fully outside the editor (e.g. on other page UI), there's no
|
|
382
|
+
// click position to preserve — falling back to "leave selection
|
|
383
|
+
// untouched" there renders the browser's native NodeSelection
|
|
384
|
+
// fallback caret at the start of the node, so explicitly move the
|
|
385
|
+
// cursor after it instead, same as the check-icon path.
|
|
386
|
+
const clickedInsideEditableContent = !!editor?.view?.dom?.contains(target);
|
|
387
|
+
handleDone(node.attrs.latex, { moveCursorAfterNode: !clickedInsideEditableContent });
|
|
366
388
|
}
|
|
367
389
|
};
|
|
368
390
|
|