@pie-lib/editable-html-tip-tap 2.1.7 → 2.1.9
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/CHANGELOG.md +19 -0
- package/lib/components/EditableHtml.js +3 -1
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/TiptapContainer.js +8 -1
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +6 -0
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/extensions/css.js +17 -7
- package/lib/extensions/css.js.map +1 -1
- package/lib/extensions/math.js +83 -14
- package/lib/extensions/math.js.map +1 -1
- package/package.json +6 -6
- package/src/components/EditableHtml.jsx +1 -1
- package/src/components/TiptapContainer.jsx +17 -2
- package/src/components/__tests__/InlineDropdown.test.jsx +14 -0
- package/src/components/respArea/InlineDropdown.jsx +12 -0
- package/src/extensions/__tests__/math.test.js +146 -9
- package/src/extensions/css.js +16 -3
- package/src/extensions/math.js +92 -15
package/lib/extensions/math.js
CHANGED
|
@@ -38,7 +38,9 @@ var EnsureTextAfterMathPlugin = exports.EnsureTextAfterMathPlugin = function Ens
|
|
|
38
38
|
// Only act when the doc actually changed
|
|
39
39
|
if (!transactions.some(function (tr) {
|
|
40
40
|
return tr.docChanged;
|
|
41
|
-
}))
|
|
41
|
+
})) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
42
44
|
var tr = newState.tr;
|
|
43
45
|
var changed = false;
|
|
44
46
|
newState.doc.descendants(function (node, pos) {
|
|
@@ -224,6 +226,7 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
224
226
|
showToolbar = _useState2[0],
|
|
225
227
|
setShowToolbar = _useState2[1];
|
|
226
228
|
var toolbarRef = (0, _react.useRef)(null);
|
|
229
|
+
var nodeRef = (0, _react.useRef)(null);
|
|
227
230
|
var timestamp = (0, _react.useRef)(Date.now());
|
|
228
231
|
var _useState3 = (0, _react.useState)({
|
|
229
232
|
top: 0,
|
|
@@ -264,25 +267,90 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
264
267
|
editor.view.dispatch(tr);
|
|
265
268
|
editor.commands.focus();
|
|
266
269
|
};
|
|
270
|
+
|
|
271
|
+
// Only open the toolbar when this node is *explicitly* selected
|
|
272
|
+
// via a NodeSelection — not when it's merely included in a broader
|
|
273
|
+
// TextSelection or AllSelection (e.g. click-drag across math, or Cmd+A).
|
|
267
274
|
(0, _react.useEffect)(function () {
|
|
268
|
-
|
|
275
|
+
var _selection$node;
|
|
276
|
+
if (!selected) return;
|
|
277
|
+
var selection = editor.state.selection;
|
|
278
|
+
var isNodeSelected = ((_selection$node = selection.node) === null || _selection$node === void 0 || (_selection$node = _selection$node.type) === null || _selection$node === void 0 ? void 0 : _selection$node.name) === 'math';
|
|
279
|
+
if (isNodeSelected) {
|
|
269
280
|
setShowToolbar(true);
|
|
270
281
|
}
|
|
271
|
-
}, [selected]);
|
|
282
|
+
}, [selected, editor]);
|
|
272
283
|
(0, _react.useEffect)(function () {
|
|
273
284
|
(0, _toolbar.setToolbarOpened)(editor, selected || showToolbar);
|
|
274
285
|
}, [editor, showToolbar, selected]);
|
|
275
286
|
(0, _react.useEffect)(function () {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
if (!editor || !showToolbar) {
|
|
288
|
+
setPosition({
|
|
289
|
+
top: 0,
|
|
290
|
+
left: 0
|
|
291
|
+
});
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Clamp in viewport coordinates, then convert to portal-container-relative values
|
|
296
|
+
// for position: absolute (toolbar is portaled into _tiptapContainerEl or document.body).
|
|
297
|
+
var updatePosition = function updatePosition() {
|
|
298
|
+
var _nodeRef$current, _nodeRef$current$getB, _start$bottom;
|
|
299
|
+
if (!toolbarRef.current) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var from = editor.state.selection.from;
|
|
303
|
+
var start = editor.view.coordsAtPos(from);
|
|
304
|
+
var nodeRect = (_nodeRef$current = nodeRef.current) === null || _nodeRef$current === void 0 || (_nodeRef$current$getB = _nodeRef$current.getBoundingClientRect) === null || _nodeRef$current$getB === void 0 ? void 0 : _nodeRef$current$getB.call(_nodeRef$current);
|
|
305
|
+
|
|
306
|
+
// Anchor to the math node element when available; fall back to selection coords.
|
|
307
|
+
var anchorTop = nodeRect !== null && nodeRect !== void 0 && nodeRect.height ? nodeRect.top : start.top;
|
|
308
|
+
var anchorLeft = nodeRect !== null && nodeRect !== void 0 && nodeRect.width ? nodeRect.left : start.left;
|
|
309
|
+
var anchorBottom = nodeRect !== null && nodeRect !== void 0 && nodeRect.height ? nodeRect.bottom : (_start$bottom = start.bottom) !== null && _start$bottom !== void 0 ? _start$bottom : start.top;
|
|
310
|
+
var toolbarHeight = toolbarRef.current.offsetHeight;
|
|
311
|
+
var toolbarWidth = toolbarRef.current.offsetWidth;
|
|
312
|
+
var gap = 0;
|
|
313
|
+
var spaceBelow = window.innerHeight - (anchorBottom + gap);
|
|
314
|
+
|
|
315
|
+
// Place the toolbar's top-left corner directly below the anchor; flip above when needed.
|
|
316
|
+
var top = spaceBelow >= toolbarHeight ? anchorBottom + gap : anchorTop - toolbarHeight - gap;
|
|
317
|
+
var left = anchorLeft;
|
|
318
|
+
var margin = 8;
|
|
319
|
+
top = Math.max(margin, Math.min(top, window.innerHeight - toolbarHeight - margin));
|
|
320
|
+
left = Math.max(margin, Math.min(left, window.innerWidth - toolbarWidth - margin));
|
|
321
|
+
var portalEl = editor._tiptapContainerEl || document.body;
|
|
322
|
+
var containerRect = portalEl.getBoundingClientRect();
|
|
323
|
+
setPosition({
|
|
324
|
+
top: top - containerRect.top,
|
|
325
|
+
left: left - containerRect.left
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
updatePosition();
|
|
329
|
+
var frame = null;
|
|
330
|
+
var scheduleUpdate = function scheduleUpdate() {
|
|
331
|
+
if (frame !== null) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
frame = requestAnimationFrame(function () {
|
|
335
|
+
frame = null;
|
|
336
|
+
updatePosition();
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
frame = requestAnimationFrame(function () {
|
|
340
|
+
frame = null;
|
|
341
|
+
updatePosition();
|
|
285
342
|
});
|
|
343
|
+
window.addEventListener('scroll', scheduleUpdate, true);
|
|
344
|
+
window.addEventListener('resize', scheduleUpdate);
|
|
345
|
+
return function () {
|
|
346
|
+
if (frame !== null) {
|
|
347
|
+
cancelAnimationFrame(frame);
|
|
348
|
+
}
|
|
349
|
+
window.removeEventListener('scroll', scheduleUpdate, true);
|
|
350
|
+
window.removeEventListener('resize', scheduleUpdate);
|
|
351
|
+
};
|
|
352
|
+
}, [editor, showToolbar]);
|
|
353
|
+
(0, _react.useEffect)(function () {
|
|
286
354
|
var handleClickOutside = function handleClickOutside(event) {
|
|
287
355
|
var _document$querySelect, _document, _target$closest, _target$closest2, _target$closest3;
|
|
288
356
|
var target = event === null || event === void 0 ? void 0 : event.target;
|
|
@@ -314,7 +382,7 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
314
382
|
return function () {
|
|
315
383
|
return document.removeEventListener('click', handleClickOutside);
|
|
316
384
|
};
|
|
317
|
-
}, [editor, showToolbar]);
|
|
385
|
+
}, [editor, showToolbar, node]);
|
|
318
386
|
return /*#__PURE__*/_react["default"].createElement(_react2.NodeViewWrapper, {
|
|
319
387
|
className: "math-node-".concat(timestamp.current),
|
|
320
388
|
style: {
|
|
@@ -324,6 +392,7 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
324
392
|
},
|
|
325
393
|
"data-selected": selected
|
|
326
394
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
395
|
+
ref: nodeRef,
|
|
327
396
|
onClick: function onClick() {
|
|
328
397
|
return setShowToolbar(true);
|
|
329
398
|
},
|
|
@@ -337,7 +406,7 @@ var MathNodeView = exports.MathNodeView = function MathNodeView(props) {
|
|
|
337
406
|
position: 'absolute',
|
|
338
407
|
top: "".concat(position.top, "px"),
|
|
339
408
|
left: "".concat(position.left, "px"),
|
|
340
|
-
zIndex:
|
|
409
|
+
zIndex: 1000,
|
|
341
410
|
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
342
411
|
boxShadow: '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)'
|
|
343
412
|
}
|
|
@@ -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","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","coordsAtPos","editorDOM","element","editorRect","getBoundingClientRect","handleClickOutside","_document$querySelect","_document","_target$closest","_target$closest2","_target$closest3","target","equationEditorListboxes","document","querySelectorAll","equationEditorPopoverOpen","clickedEquationEditorSelect","id","includes","closest","clickedMathNode","concat","current","contains","addEventListener","removeEventListener","NodeViewWrapper","className","style","display","cursor","margin","onClick","contentEditable","MathPreview","ReactDOM","createPortal","ref","instanceId","zIndex","background","boxShadow","MathToolbar","autoFocus","onChange","onDone","additionalKeys","_tiptapContainerEl","body"],"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)) return null;\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 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 useEffect(() => {\n if (selected) {\n setShowToolbar(true);\n }\n }, [selected]);\n\n useEffect(() => {\n setToolbarOpened(editor, selected || showToolbar);\n }, [editor, showToolbar, selected]);\n\n useEffect(() => {\n // Calculate position relative to selection\n const { from } = editor.state.selection;\n const start = editor.view.coordsAtPos(from);\n const editorDOM = editor.options.element;\n const editorRect = editorDOM.getBoundingClientRect();\n\n setPosition({\n top: start.top - editorRect.top + 40, // shift above\n left: start.left - editorRect.left,\n });\n\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]);\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 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: 20,\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,I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ACnBV,UAAU,EAAEA,UAAW;IACvBE,oBAAoB,EAAEA,oBAAqB;IAC3C2D,cAAc,EAAEpL,sBAAsB,CAAC2H,UAAU,CAAE;IACnDC,kBAAkB,EAAEA,kBAAmB;IACvCC,oBAAoB,EAAEA;EAAqB,CAC5C,CACE,CAAC,EACN,CAAA9C,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEsG,kBAAkB,KAAIlC,QAAQ,CAACmC,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","_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,GAAA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7EtP,MAAA,YAAA6I,aAAA,CAACrI,YAAA,CAAA+O,WAAW;IAAClM,KAAK,EAAEA;EAAM,CAAE,CACzB,CAAC,EACLiG,WAAW,iBACVkG,oBAAQ,CAACC,YAAY,cACnBzP,MAAA,YAAA6I,aAAA;IACEuG,GAAG,EAAE5F,UAAW;IAChB,oBAAkB1B,MAAM,CAAC4H,UAAW;IACpCT,KAAK,EAAE;MACL/E,QAAQ,EAAE,UAAU;MACpBH,GAAG,KAAA8E,MAAA,CAAK3E,QAAQ,CAACH,GAAG,OAAI;MACxBC,IAAI,KAAA6E,MAAA,CAAK3E,QAAQ,CAACF,IAAI,OAAI;MAC1B2F,MAAM,EAAE,IAAI;MACZC,UAAU,EAAE,0CAA0C;MACtDC,SAAS,EACP;IACJ;EAAE,gBAEF7P,MAAA,YAAA6I,aAAA,CAACrI,YAAA,CAAAsP,WAAW;IACVzM,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":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.1.
|
|
6
|
+
"version": "2.1.9",
|
|
7
7
|
"description": "",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"main": "lib/index.js",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"@dnd-kit/utilities": "3.2.2",
|
|
17
17
|
"@mui/icons-material": "^7.3.4",
|
|
18
18
|
"@mui/material": "^7.3.4",
|
|
19
|
-
"@pie-lib/drag": "^4.0.
|
|
19
|
+
"@pie-lib/drag": "^4.0.6",
|
|
20
20
|
"@pie-lib/math-input": "^8.1.1",
|
|
21
|
-
"@pie-lib/math-rendering": "^5.0
|
|
22
|
-
"@pie-lib/math-toolbar": "^3.0.
|
|
23
|
-
"@pie-lib/render-ui": "^6.1.
|
|
21
|
+
"@pie-lib/math-rendering": "^5.1.0",
|
|
22
|
+
"@pie-lib/math-toolbar": "^3.0.6",
|
|
23
|
+
"@pie-lib/render-ui": "^6.1.3",
|
|
24
24
|
"@tiptap/core": "3.20.0",
|
|
25
25
|
"@tiptap/extension-character-count": "3.20.0",
|
|
26
26
|
"@tiptap/extension-color": "3.20.0",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.2.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "53796293aa3d939290388614fd6d4467fb81b178",
|
|
63
63
|
"scripts": {}
|
|
64
64
|
}
|
|
@@ -334,7 +334,7 @@ export const EditableHtml = (props) => {
|
|
|
334
334
|
const nextMarkup = normalizeInitialMarkup(props.markup);
|
|
335
335
|
|
|
336
336
|
if (nextMarkup !== editor.getHTML()) {
|
|
337
|
-
editor.commands.setContent(nextMarkup, false);
|
|
337
|
+
editor.commands.setContent(nextMarkup, { emitUpdate: false });
|
|
338
338
|
}
|
|
339
339
|
}, [props.markup, editor]);
|
|
340
340
|
|
|
@@ -171,10 +171,25 @@ function TiptapContainer(props) {
|
|
|
171
171
|
el.style.whiteSpace = 'nowrap';
|
|
172
172
|
el.textContent = 'W'.repeat(props.charactersLimit);
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
// Copy font styles from the editor container so the width measurement reflects the actual font
|
|
175
|
+
const computedStyles = window.getComputedStyle(rootRef.current);
|
|
176
|
+
const fontStyleProps = [
|
|
177
|
+
'fontFamily',
|
|
178
|
+
'fontSize',
|
|
179
|
+
'fontWeight',
|
|
180
|
+
'fontStyle',
|
|
181
|
+
'letterSpacing',
|
|
182
|
+
'wordSpacing',
|
|
183
|
+
'textTransform',
|
|
184
|
+
'lineHeight',
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
fontStyleProps.forEach((prop) => {
|
|
188
|
+
el.style[prop] = computedStyles[prop];
|
|
189
|
+
});
|
|
175
190
|
|
|
191
|
+
document.body.appendChild(el);
|
|
176
192
|
setAdjustedWidth(`${el.offsetWidth + 27}px`);
|
|
177
|
-
|
|
178
193
|
el.remove();
|
|
179
194
|
}
|
|
180
195
|
}, [props.adjustWidthForLimit, props.charactersLimit]);
|
|
@@ -464,6 +464,20 @@ describe('InlineDropdown', () => {
|
|
|
464
464
|
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
465
465
|
});
|
|
466
466
|
|
|
467
|
+
it('does not close toolbar when clicking the page scrollbar (documentElement)', async () => {
|
|
468
|
+
const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
|
|
469
|
+
|
|
470
|
+
await waitFor(() => {
|
|
471
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
fireEvent.mouseDown(document.documentElement);
|
|
475
|
+
|
|
476
|
+
await waitFor(() => {
|
|
477
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
|
|
467
481
|
it('renders delete control on portaled custom toolbar when container el is set', async () => {
|
|
468
482
|
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
|
|
469
483
|
expect(await findByLabelText('Delete')).toBeInTheDocument();
|
|
@@ -93,6 +93,14 @@ const InlineDropdown = (props) => {
|
|
|
93
93
|
}
|
|
94
94
|
}, [editor, node, selected]);
|
|
95
95
|
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const isScrollbarClicked = (event) =>
|
|
99
|
+
event.clientX > document.documentElement.clientWidth ||
|
|
100
|
+
event.clientY > document.documentElement.clientHeight ||
|
|
101
|
+
event.target === document.documentElement;
|
|
102
|
+
|
|
103
|
+
|
|
96
104
|
useEffect(() => {
|
|
97
105
|
// Calculate position relative to selection
|
|
98
106
|
const bodyRect = document.body.getBoundingClientRect();
|
|
@@ -105,6 +113,10 @@ const InlineDropdown = (props) => {
|
|
|
105
113
|
});
|
|
106
114
|
|
|
107
115
|
const handleClickOutside = (event) => {
|
|
116
|
+
|
|
117
|
+
if( isScrollbarClicked(event) ) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
108
120
|
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
|
|
109
121
|
|
|
110
122
|
if (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
2
|
+
import { render, waitFor, fireEvent, act } from '@testing-library/react';
|
|
3
3
|
import { EnsureTextAfterMathPlugin, MathNode, MathNodeView, ZeroWidthSpaceHandlingPlugin } from '../math';
|
|
4
4
|
import * as toolbarUtils from '../../utils/toolbar';
|
|
5
5
|
|
|
@@ -390,6 +390,7 @@ describe('MathNodeView', () => {
|
|
|
390
390
|
selection: {
|
|
391
391
|
from: 0,
|
|
392
392
|
to: 1,
|
|
393
|
+
node: { type: { name: 'math' } },
|
|
393
394
|
},
|
|
394
395
|
tr: {
|
|
395
396
|
setSelection: jest.fn().mockReturnThis(),
|
|
@@ -467,30 +468,31 @@ describe('MathNodeView', () => {
|
|
|
467
468
|
});
|
|
468
469
|
|
|
469
470
|
describe('toolbar positioning', () => {
|
|
470
|
-
it('positions relative to
|
|
471
|
+
it('positions relative to portal container using coordsAtPos', async () => {
|
|
471
472
|
const { container } = render(<MathNodeView {...defaultProps} selected={true} />);
|
|
472
473
|
await waitFor(() => {
|
|
473
474
|
const toolbar = container.querySelector('[data-toolbar-for]');
|
|
474
475
|
expect(toolbar).toBeInTheDocument();
|
|
475
|
-
expect(toolbar.style.top).toBe('
|
|
476
|
+
expect(toolbar.style.top).toBe('100px');
|
|
476
477
|
expect(toolbar.style.left).toBe('50px');
|
|
477
478
|
});
|
|
478
479
|
});
|
|
479
480
|
|
|
480
|
-
it('
|
|
481
|
-
const
|
|
481
|
+
it('offsets position by portal container getBoundingClientRect', async () => {
|
|
482
|
+
const containerEl = document.createElement('div');
|
|
483
|
+
containerEl.getBoundingClientRect = jest.fn(() => ({ top: 100, left: 50, width: 600, height: 400 }));
|
|
482
484
|
|
|
483
485
|
const editor = {
|
|
484
486
|
...defaultProps.editor,
|
|
485
|
-
|
|
487
|
+
_tiptapContainerEl: containerEl,
|
|
486
488
|
};
|
|
487
489
|
|
|
488
490
|
const { container } = render(<MathNodeView {...defaultProps} editor={editor} selected={true} />);
|
|
489
491
|
await waitFor(() => {
|
|
490
492
|
const toolbar = container.querySelector('[data-toolbar-for]');
|
|
491
493
|
expect(toolbar).toBeInTheDocument();
|
|
492
|
-
expect(toolbar.style.top).toBe('
|
|
493
|
-
expect(toolbar.style.left).toBe('
|
|
494
|
+
expect(toolbar.style.top).toBe('0px');
|
|
495
|
+
expect(toolbar.style.left).toBe('0px');
|
|
494
496
|
});
|
|
495
497
|
});
|
|
496
498
|
|
|
@@ -503,6 +505,15 @@ describe('MathNodeView', () => {
|
|
|
503
505
|
});
|
|
504
506
|
});
|
|
505
507
|
|
|
508
|
+
it('renders above other editor overlays with a high z-index', async () => {
|
|
509
|
+
const { container } = render(<MathNodeView {...defaultProps} selected={true} />);
|
|
510
|
+
await waitFor(() => {
|
|
511
|
+
const toolbar = container.querySelector('[data-toolbar-for]');
|
|
512
|
+
expect(toolbar).toBeInTheDocument();
|
|
513
|
+
expect(toolbar.style.zIndex).toBe('1000');
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
506
517
|
it('updates position from coordsAtPos when selection changes', async () => {
|
|
507
518
|
const editor = {
|
|
508
519
|
...defaultProps.editor,
|
|
@@ -517,11 +528,64 @@ describe('MathNodeView', () => {
|
|
|
517
528
|
await waitFor(() => {
|
|
518
529
|
const toolbar = container.querySelector('[data-toolbar-for]');
|
|
519
530
|
expect(toolbar).toBeInTheDocument();
|
|
520
|
-
expect(toolbar.style.top).toBe('
|
|
531
|
+
expect(toolbar.style.top).toBe('200px');
|
|
521
532
|
expect(toolbar.style.left).toBe('150px');
|
|
522
533
|
});
|
|
523
534
|
});
|
|
524
535
|
|
|
536
|
+
it('clamps toolbar position to viewport margins', async () => {
|
|
537
|
+
const originalInnerHeight = window.innerHeight;
|
|
538
|
+
const originalInnerWidth = window.innerWidth;
|
|
539
|
+
|
|
540
|
+
Object.defineProperty(window, 'innerHeight', { configurable: true, writable: true, value: 200 });
|
|
541
|
+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: 300 });
|
|
542
|
+
|
|
543
|
+
const editor = {
|
|
544
|
+
...defaultProps.editor,
|
|
545
|
+
view: {
|
|
546
|
+
...defaultProps.editor.view,
|
|
547
|
+
coordsAtPos: jest.fn(() => ({ top: 190, left: 280, bottom: 195 })),
|
|
548
|
+
dispatch: jest.fn(),
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
const { container } = render(<MathNodeView {...defaultProps} editor={editor} selected={true} />);
|
|
553
|
+
|
|
554
|
+
let toolbar;
|
|
555
|
+
await waitFor(() => {
|
|
556
|
+
toolbar = container.querySelector('[data-toolbar-for]');
|
|
557
|
+
expect(toolbar).toBeInTheDocument();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
Object.defineProperty(toolbar, 'offsetHeight', { configurable: true, value: 100 });
|
|
561
|
+
Object.defineProperty(toolbar, 'offsetWidth', { configurable: true, value: 150 });
|
|
562
|
+
|
|
563
|
+
await act(async () => {
|
|
564
|
+
window.dispatchEvent(new Event('resize'));
|
|
565
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
await waitFor(() => {
|
|
569
|
+
expect(parseInt(toolbar.style.top, 10)).toBeLessThanOrEqual(200 - 100 - 8);
|
|
570
|
+
expect(parseInt(toolbar.style.left, 10)).toBeLessThanOrEqual(300 - 150 - 8);
|
|
571
|
+
expect(parseInt(toolbar.style.top, 10)).toBeGreaterThanOrEqual(8);
|
|
572
|
+
expect(parseInt(toolbar.style.left, 10)).toBeGreaterThanOrEqual(8);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
Object.defineProperty(window, 'innerHeight', { configurable: true, writable: true, value: originalInnerHeight });
|
|
576
|
+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: originalInnerWidth });
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it('attaches scroll and resize listeners while toolbar is open', async () => {
|
|
580
|
+
const addSpy = jest.spyOn(window, 'addEventListener');
|
|
581
|
+
render(<MathNodeView {...defaultProps} selected={true} />);
|
|
582
|
+
await waitFor(() => {
|
|
583
|
+
expect(addSpy).toHaveBeenCalledWith('scroll', expect.any(Function), true);
|
|
584
|
+
expect(addSpy).toHaveBeenCalledWith('resize', expect.any(Function));
|
|
585
|
+
});
|
|
586
|
+
addSpy.mockRestore();
|
|
587
|
+
});
|
|
588
|
+
|
|
525
589
|
it('portals toolbar into _tiptapContainerEl when available', async () => {
|
|
526
590
|
const containerEl = document.createElement('div');
|
|
527
591
|
containerEl.getBoundingClientRect = jest.fn(() => ({ top: 0, left: 0, width: 600, height: 400 }));
|
|
@@ -648,6 +712,31 @@ describe('MathNodeView', () => {
|
|
|
648
712
|
});
|
|
649
713
|
});
|
|
650
714
|
|
|
715
|
+
it('re-registers click listener when node changes', async () => {
|
|
716
|
+
const addEventListenerSpy = jest.spyOn(document, 'addEventListener');
|
|
717
|
+
const removeEventListenerSpy = jest.spyOn(document, 'removeEventListener');
|
|
718
|
+
const nodeA = { attrs: { latex: 'x^2' } };
|
|
719
|
+
const nodeB = { attrs: { latex: 'y^2' } };
|
|
720
|
+
|
|
721
|
+
const { rerender } = render(<MathNodeView {...defaultProps} node={nodeA} selected={true} />);
|
|
722
|
+
|
|
723
|
+
await waitFor(() => {
|
|
724
|
+
expect(addEventListenerSpy).toHaveBeenCalledWith('click', expect.any(Function));
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
const initialCallCount = addEventListenerSpy.mock.calls.length;
|
|
728
|
+
|
|
729
|
+
rerender(<MathNodeView {...defaultProps} node={nodeB} selected={true} />);
|
|
730
|
+
|
|
731
|
+
await waitFor(() => {
|
|
732
|
+
expect(removeEventListenerSpy).toHaveBeenCalled();
|
|
733
|
+
expect(addEventListenerSpy.mock.calls.length).toBeGreaterThan(initialCallCount);
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
addEventListenerSpy.mockRestore();
|
|
737
|
+
removeEventListenerSpy.mockRestore();
|
|
738
|
+
});
|
|
739
|
+
|
|
651
740
|
it('does not close toolbar when clicking the math node preview', async () => {
|
|
652
741
|
const { getByTestId, queryByTestId } = render(<MathNodeView {...defaultProps} selected={true} />);
|
|
653
742
|
|
|
@@ -724,6 +813,54 @@ describe('MathNodeView', () => {
|
|
|
724
813
|
});
|
|
725
814
|
});
|
|
726
815
|
|
|
816
|
+
describe('selection-based toolbar guard', () => {
|
|
817
|
+
it('opens toolbar when selected transitions to true and the editor has a NodeSelection on math', async () => {
|
|
818
|
+
const { queryByTestId, rerender } = render(<MathNodeView {...defaultProps} selected={false} />);
|
|
819
|
+
expect(queryByTestId('math-toolbar')).not.toBeInTheDocument();
|
|
820
|
+
|
|
821
|
+
rerender(<MathNodeView {...defaultProps} selected={true} />);
|
|
822
|
+
await waitFor(() => {
|
|
823
|
+
expect(queryByTestId('math-toolbar')).toBeInTheDocument();
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
it('does not open toolbar when selected briefly becomes true but editor selection has no node (Cmd+A / drag case)', async () => {
|
|
828
|
+
const editor = {
|
|
829
|
+
...defaultProps.editor,
|
|
830
|
+
state: {
|
|
831
|
+
...defaultProps.editor.state,
|
|
832
|
+
selection: { from: 0, to: 100 }, // no .node — TextSelection / AllSelection shape
|
|
833
|
+
},
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
const { queryByTestId, rerender } = render(
|
|
837
|
+
<MathNodeView {...defaultProps} editor={editor} selected={false} />,
|
|
838
|
+
);
|
|
839
|
+
rerender(<MathNodeView {...defaultProps} editor={editor} selected={true} />);
|
|
840
|
+
|
|
841
|
+
await act(async () => {});
|
|
842
|
+
expect(queryByTestId('math-toolbar')).not.toBeInTheDocument();
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it('does not open toolbar when selected briefly becomes true but NodeSelection targets a non-math node', async () => {
|
|
846
|
+
const editor = {
|
|
847
|
+
...defaultProps.editor,
|
|
848
|
+
state: {
|
|
849
|
+
...defaultProps.editor.state,
|
|
850
|
+
selection: { from: 0, to: 1, node: { type: { name: 'image' } } },
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
const { queryByTestId, rerender } = render(
|
|
855
|
+
<MathNodeView {...defaultProps} editor={editor} selected={false} />,
|
|
856
|
+
);
|
|
857
|
+
rerender(<MathNodeView {...defaultProps} editor={editor} selected={true} />);
|
|
858
|
+
|
|
859
|
+
await act(async () => {});
|
|
860
|
+
expect(queryByTestId('math-toolbar')).not.toBeInTheDocument();
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
|
|
727
864
|
it('does not close toolbar when clicking equation editor dropdown', async () => {
|
|
728
865
|
const { queryByTestId } = render(<MathNodeView {...defaultProps} selected={true} />);
|
|
729
866
|
|