@pie-lib/editable-html-tip-tap 1.2.0-next.12 → 1.2.0-next.13
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 +6 -0
- package/lib/components/CharacterPicker.js +1 -0
- package/lib/components/CharacterPicker.js.map +1 -1
- package/lib/components/EditableHtml.js +7 -0
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +40 -38
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +8 -2
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/extensions/math.js +1 -0
- package/lib/extensions/math.js.map +1 -1
- package/lib/extensions/responseArea.js +1 -1
- package/lib/extensions/responseArea.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/EditableHtml.test.jsx +35 -0
- package/src/components/CharacterPicker.jsx +1 -0
- package/src/components/EditableHtml.jsx +8 -0
- package/src/components/MenuBar.jsx +25 -22
- package/src/components/__tests__/CharacterPicker.test.jsx +22 -0
- package/src/components/__tests__/InlineDropdown.test.jsx +149 -0
- package/src/components/__tests__/MenuBar.test.jsx +32 -0
- package/src/components/respArea/InlineDropdown.jsx +10 -1
- package/src/extensions/__tests__/math.test.js +327 -0
- package/src/extensions/__tests__/responseArea.test.js +157 -0
- package/src/extensions/math.js +1 -0
- package/src/extensions/responseArea.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseArea.js","names":["_react","_interopRequireDefault","require","_prosemirrorState","_core","_react2","_ExplicitConstructedResponse","_DragInTheBlank","_InlineDropdown","_MathTemplated","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","lastIndexMap","normalizeType","type","String","replace","getAttrIndex","node","attrs","index","collectNodesOfType","doc","typeName","results","descendants","pos","name","countNodesOfType","count","getDefaultNode","_ref","schema","nodeType","nodes","create","id","value","selectionAfterPos","$pos","resolve","Math","min","content","size","TextSelection","near","ResponseAreaExtension","exports","Extension","addOptions","maxResponseAreas","error","options","respAreaToolbar","onHandleAreaChange","addProseMirrorPlugins","_this","key","PluginKey","concat","Plugin","view","undefined","state","idx","n","parseInt","Number","isNaN","update","prevState","eq","currentList","oldList","toolbar","disabled","currentIndexSet","Set","map","x","removed","has","addCommands","_this2","insertResponseArea","_ref2","tr","dispatch","commands","currentCount","prevIndex","newIndex","newInline","selection","insertPos","from","tryInsertAt","insert","usedPos","includes","setSelection","NodeSelection","after","nodeSize","focus","refreshResponseArea","_ref3","$from","nodeAfter","nodePos","setNodeMarkup","updated","Date","now","ExplicitConstructedResponseNode","Node","group","inline","atom","addAttributes","parseHTML","tag","getAttrs","el","dataset","renderHTML","_ref4","HTMLAttributes","addNodeView","_this3","ReactNodeViewRenderer","props","createElement","MathTemplatedNode","_ref5","_this4","DragInTheBlankNode","inTable","_ref6","_this5","InlineDropdownNode","_ref7","_this6"],"sources":["../../src/extensions/responseArea.js"],"sourcesContent":["import React from 'react';\nimport { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { Extension } from '@tiptap/core';\nimport { Node, ReactNodeViewRenderer } from '@tiptap/react';\nimport ExplicitConstructedResponse from '../components/respArea/ExplicitConstructedResponse';\nimport DragInTheBlank from '../components/respArea/DragInTheBlank/DragInTheBlank';\nimport InlineDropdown from '../components/respArea/InlineDropdown';\nimport MathTemplated from '../components/respArea/MathTemplated';\n\nconst lastIndexMap = {};\n\nconst normalizeType = (type) => String(type || '').replace(/-/g, '_');\n\nconst getAttrIndex = (node) => (node && node.attrs && node.attrs.index != null ? String(node.attrs.index) : null);\n\nconst collectNodesOfType = (doc, typeName) => {\n const results = [];\n\n doc.descendants((node, pos) => {\n if (node.type && node.type.name === typeName) {\n const index = getAttrIndex(node);\n if (index != null) results.push({ index, pos, node });\n }\n return true;\n });\n\n return results;\n};\n\nconst countNodesOfType = (doc, typeName) => {\n let count = 0;\n doc.descendants((node) => {\n if (node.type && node.type.name === typeName) count += 1;\n return true;\n });\n return count;\n};\n\nconst getDefaultNode = ({ schema, typeName, index }) => {\n const nodeType = schema.nodes[typeName];\n if (!nodeType) return null;\n\n // mirror your Slate \"getDefaultElement(opts, newIndex)\"\n // customize attrs as needed:\n return nodeType.create({\n index: String(index),\n id: String(index),\n value: '',\n });\n};\n\n// Find a good cursor position *after* an inserted node.\nconst selectionAfterPos = (doc, pos) => {\n const $pos = doc.resolve(Math.min(pos, doc.content.size));\n return TextSelection.near($pos, 1);\n};\n\nexport const ResponseAreaExtension = Extension.create({\n name: 'responseArea',\n\n addOptions() {\n return {\n maxResponseAreas: null,\n error: null,\n options: null,\n respAreaToolbar: null,\n onHandleAreaChange: null,\n };\n },\n\n addProseMirrorPlugins() {\n if (!this.options.type) {\n return [];\n }\n\n const typeName = normalizeType(this.options.type);\n const key = new PluginKey(`response-area-watcher:${typeName}`);\n\n return [\n new Plugin({\n key,\n\n view: (view) => {\n // Lazy init lastIndexMap[typeName]\n if (lastIndexMap[typeName] === undefined) {\n lastIndexMap[typeName] = 0;\n\n view.state.doc.descendants((node) => {\n if (node.type && node.type.name === typeName) {\n const idx = getAttrIndex(node);\n if (idx != null) {\n const n = parseInt(idx, 10);\n if (!Number.isNaN(n) && n > lastIndexMap[typeName]) {\n lastIndexMap[typeName] = n;\n }\n }\n }\n return true;\n });\n }\n\n return {\n update: (view, prevState) => {\n const state = view.state;\n if (prevState.doc.eq(state.doc)) return;\n\n const currentList = collectNodesOfType(state.doc, typeName);\n const oldList = collectNodesOfType(prevState.doc, typeName);\n\n if (this.options.toolbar) {\n this.options.toolbar.disabled = currentList.length >= this.options.maxResponseAreas;\n }\n\n // Removed elements (same logic as Slate)\n if (oldList.length > currentList.length) {\n const currentIndexSet = new Set(currentList.map((x) => x.index));\n\n const removed = oldList.filter((x) => !currentIndexSet.has(x.index));\n\n if (removed.length && typeof this.options.onHandleAreaChange === 'function') {\n this.options.onHandleAreaChange(removed);\n }\n }\n },\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n insertResponseArea:\n (type) =>\n ({ tr, state, dispatch, commands }) => {\n const typeName = normalizeType(type);\n\n // --- Slate: currentRespAreaList + max check ---\n const currentCount = countNodesOfType(state.doc, typeName);\n if (currentCount >= this.options.maxResponseAreas) {\n return false;\n }\n\n // --- Slate: indexing logic (kept identical) ---\n if (lastIndexMap[typeName] === undefined) lastIndexMap[typeName] = 0;\n\n const prevIndex = lastIndexMap[typeName];\n const newIndex = prevIndex === 0 ? prevIndex : prevIndex + 1;\n\n // Slate increments map even if newIndex === 0\n lastIndexMap[typeName] += 1;\n\n const newInline = getDefaultNode({\n schema: state.schema,\n typeName,\n index: newIndex,\n });\n\n if (!newInline) return false;\n\n // --- Insert logic ---\n const { selection } = state;\n let insertPos = selection.from;\n\n // If we're in a NodeSelection, insert before/after is ambiguous;\n // We'll insert at its \"from\" (like your current code).\n // If insertion fails, we fallback to end of doc.\n const tryInsertAt = (pos) => {\n try {\n tr.insert(pos, newInline);\n return pos;\n } catch (e) {\n return null;\n }\n };\n\n let usedPos = tryInsertAt(insertPos);\n\n // Slate branch: \"markup empty and there's no focus\"\n // ProseMirror doesn't expose \"no focus\" the same way, so the closest\n // equivalent fallback is inserting at end of document.\n if (usedPos == null) {\n usedPos = tryInsertAt(tr.doc.content.size);\n }\n if (usedPos == null) return false;\n\n // Optionally select the node you just inserted (like your original command)\n // tr.setSelection(NodeSelection.create(tr.doc, usedPos))\n\n // --- Cursor move behavior for certain types (Slate: moveFocusTo next text) ---\n if (['math_templated', 'inline_dropdown', 'explicit_constructed_response'].includes(typeName)) {\n tr.setSelection(NodeSelection.create(tr.doc, usedPos));\n } else {\n const after = usedPos + newInline.nodeSize;\n tr.setSelection(selectionAfterPos(tr.doc, after));\n }\n\n if (dispatch) {\n commands.focus();\n dispatch(tr);\n }\n\n return true;\n },\n refreshResponseArea:\n () =>\n ({ tr, state, commands, dispatch }) => {\n const { selection } = state;\n const node = selection.$from.nodeAfter;\n const nodePos = selection.from;\n\n tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, updated: `${Date.now()}` });\n tr.setSelection(NodeSelection.create(tr.doc, nodePos));\n\n if (dispatch) {\n commands.focus();\n dispatch(tr);\n }\n\n return true;\n },\n };\n },\n});\n\n/**\n * ExplicitConstructedResponse Node\n */\nexport const ExplicitConstructedResponseNode = Node.create({\n name: 'explicit_constructed_response',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"explicit_constructed_response\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'explicit_constructed_response',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <ExplicitConstructedResponse {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * MathTemplated Node\n */\nexport const MathTemplatedNode = Node.create({\n name: 'math_templated',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"math_templated\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'math_templated',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <MathTemplated {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * DragInTheBlank Node\n */\nexport const DragInTheBlankNode = Node.create({\n name: 'drag_in_the_blank',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n id: { default: null },\n value: { default: '' },\n inTable: { default: null },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"drag_in_the_blank\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n id: el.dataset.id,\n value: el.dataset.value,\n inTable: el.dataset.inTable,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'drag_in_the_blank',\n 'data-index': HTMLAttributes.index,\n 'data-id': HTMLAttributes.id,\n 'data-value': HTMLAttributes.value,\n 'data-in-table': HTMLAttributes.inTable,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <DragInTheBlank {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * InlineDropdown Node\n */\nexport const InlineDropdownNode = Node.create({\n name: 'inline_dropdown',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"inline_dropdown\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'inline_dropdown',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <InlineDropdown {...{ ...props, options: this.options }} />);\n },\n});\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,4BAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,eAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,eAAA,GAAAP,sB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E,iBAAiB;MAC9B,YAAY,EAAEA,cAAc,CAAC5G,KAAK;MAClC,YAAY,EAAE4G,cAAc,CAAC3F;IAC/B,CAAC,CACF;EACH,CAAC;EACD4F,WAAW,WAAXA,WAAWA,CAAA,EAAG;IAAA,IAAAc,MAAA;IACZ,OAAO,IAAAZ,6BAAqB,EAAC,UAACC,KAAK;MAAA,oBAAKvJ,MAAA,YAAAwJ,aAAA,CAAChJ,eAAA,WAAc,EAAAe,aAAA,CAAAA,aAAA,KAAUgI,KAAK;QAAE/E,OAAO,EAAE0F,MAAI,CAAC1F;MAAO,EAAK,CAAC;IAAA,EAAC;EACtG;AACF,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"responseArea.js","names":["_react","_interopRequireDefault","require","_prosemirrorState","_core","_react2","_ExplicitConstructedResponse","_DragInTheBlank","_InlineDropdown","_MathTemplated","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","lastIndexMap","normalizeType","type","String","replace","getAttrIndex","node","attrs","index","collectNodesOfType","doc","typeName","results","descendants","pos","name","countNodesOfType","count","getDefaultNode","_ref","schema","nodeType","nodes","create","id","value","selectionAfterPos","$pos","resolve","Math","min","content","size","TextSelection","near","ResponseAreaExtension","exports","Extension","addOptions","maxResponseAreas","error","options","respAreaToolbar","onHandleAreaChange","addProseMirrorPlugins","_this","key","PluginKey","concat","Plugin","view","undefined","state","idx","n","parseInt","Number","isNaN","update","prevState","eq","currentList","oldList","toolbar","disabled","currentIndexSet","Set","map","x","removed","has","addCommands","_this2","insertResponseArea","_ref2","tr","dispatch","commands","currentCount","prevIndex","newIndex","newInline","selection","insertPos","from","tryInsertAt","insert","usedPos","includes","setSelection","NodeSelection","after","nodeSize","focus","refreshResponseArea","_ref3","$from","nodeAfter","nodePos","setNodeMarkup","updated","Date","now","ExplicitConstructedResponseNode","Node","group","inline","atom","addAttributes","parseHTML","tag","getAttrs","el","dataset","renderHTML","_ref4","HTMLAttributes","addNodeView","_this3","ReactNodeViewRenderer","props","createElement","MathTemplatedNode","_ref5","_this4","DragInTheBlankNode","inTable","_ref6","_this5","InlineDropdownNode","_ref7","_this6"],"sources":["../../src/extensions/responseArea.js"],"sourcesContent":["import React from 'react';\nimport { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';\nimport { Extension } from '@tiptap/core';\nimport { Node, ReactNodeViewRenderer } from '@tiptap/react';\nimport ExplicitConstructedResponse from '../components/respArea/ExplicitConstructedResponse';\nimport DragInTheBlank from '../components/respArea/DragInTheBlank/DragInTheBlank';\nimport InlineDropdown from '../components/respArea/InlineDropdown';\nimport MathTemplated from '../components/respArea/MathTemplated';\n\nconst lastIndexMap = {};\n\nconst normalizeType = (type) => String(type || '').replace(/-/g, '_');\n\nconst getAttrIndex = (node) => (node && node.attrs && node.attrs.index != null ? String(node.attrs.index) : null);\n\nconst collectNodesOfType = (doc, typeName) => {\n const results = [];\n\n doc.descendants((node, pos) => {\n if (node.type && node.type.name === typeName) {\n const index = getAttrIndex(node);\n if (index != null) results.push({ index, pos, node });\n }\n return true;\n });\n\n return results;\n};\n\nconst countNodesOfType = (doc, typeName) => {\n let count = 0;\n doc.descendants((node) => {\n if (node.type && node.type.name === typeName) count += 1;\n return true;\n });\n return count;\n};\n\nconst getDefaultNode = ({ schema, typeName, index }) => {\n const nodeType = schema.nodes[typeName];\n if (!nodeType) return null;\n\n // mirror your Slate \"getDefaultElement(opts, newIndex)\"\n // customize attrs as needed:\n return nodeType.create({\n index: String(index),\n id: String(index),\n value: '',\n });\n};\n\n// Find a good cursor position *after* an inserted node.\nconst selectionAfterPos = (doc, pos) => {\n const $pos = doc.resolve(Math.min(pos, doc.content.size));\n return TextSelection.near($pos, 1);\n};\n\nexport const ResponseAreaExtension = Extension.create({\n name: 'responseArea',\n\n addOptions() {\n return {\n maxResponseAreas: null,\n error: null,\n options: null,\n respAreaToolbar: null,\n onHandleAreaChange: null,\n };\n },\n\n addProseMirrorPlugins() {\n if (!this.options.type) {\n return [];\n }\n\n const typeName = normalizeType(this.options.type);\n const key = new PluginKey(`response-area-watcher:${typeName}`);\n\n return [\n new Plugin({\n key,\n\n view: (view) => {\n // Lazy init lastIndexMap[typeName]\n if (lastIndexMap[typeName] === undefined) {\n lastIndexMap[typeName] = 0;\n\n view.state.doc.descendants((node) => {\n if (node.type && node.type.name === typeName) {\n const idx = getAttrIndex(node);\n if (idx != null) {\n const n = parseInt(idx, 10);\n if (!Number.isNaN(n) && n > lastIndexMap[typeName]) {\n lastIndexMap[typeName] = n;\n }\n }\n }\n return true;\n });\n }\n\n return {\n update: (view, prevState) => {\n const state = view.state;\n if (prevState.doc.eq(state.doc)) return;\n\n const currentList = collectNodesOfType(state.doc, typeName);\n const oldList = collectNodesOfType(prevState.doc, typeName);\n\n if (this.options.toolbar) {\n this.options.toolbar.disabled = currentList.length >= this.options.maxResponseAreas;\n }\n\n // Removed elements (same logic as Slate)\n if (oldList.length > currentList.length) {\n const currentIndexSet = new Set(currentList.map((x) => x.index));\n\n const removed = oldList.filter((x) => !currentIndexSet.has(x.index));\n\n if (removed.length && typeof this.options.onHandleAreaChange === 'function') {\n this.options.onHandleAreaChange(removed);\n }\n }\n },\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n insertResponseArea:\n (type) =>\n ({ tr, state, dispatch, commands }) => {\n const typeName = normalizeType(type);\n\n // --- Slate: currentRespAreaList + max check ---\n const currentCount = countNodesOfType(state.doc, typeName);\n if (currentCount >= this.options.maxResponseAreas) {\n return false;\n }\n\n // --- Slate: indexing logic (kept identical) ---\n if (lastIndexMap[typeName] === undefined) lastIndexMap[typeName] = 0;\n\n const prevIndex = lastIndexMap[typeName];\n const newIndex = prevIndex === 0 ? prevIndex : prevIndex + 1;\n\n // Slate increments map even if newIndex === 0\n lastIndexMap[typeName] += 1;\n\n const newInline = getDefaultNode({\n schema: state.schema,\n typeName,\n index: newIndex,\n });\n\n if (!newInline) return false;\n\n // --- Insert logic ---\n const { selection } = state;\n let insertPos = selection.from;\n\n // If we're in a NodeSelection, insert before/after is ambiguous;\n // We'll insert at its \"from\" (like your current code).\n // If insertion fails, we fallback to end of doc.\n const tryInsertAt = (pos) => {\n try {\n tr.insert(pos, newInline);\n return pos;\n } catch (e) {\n return null;\n }\n };\n\n let usedPos = tryInsertAt(insertPos);\n\n // Slate branch: \"markup empty and there's no focus\"\n // ProseMirror doesn't expose \"no focus\" the same way, so the closest\n // equivalent fallback is inserting at end of document.\n if (usedPos == null) {\n usedPos = tryInsertAt(tr.doc.content.size);\n }\n if (usedPos == null) return false;\n\n // Optionally select the node you just inserted (like your original command)\n // tr.setSelection(NodeSelection.create(tr.doc, usedPos))\n\n // --- Cursor move behavior for certain types (Slate: moveFocusTo next text) ---\n if (['math_templated', 'inline_dropdown', 'explicit_constructed_response'].includes(typeName)) {\n tr.setSelection(NodeSelection.create(tr.doc, usedPos));\n } else {\n const after = usedPos + newInline.nodeSize;\n tr.setSelection(selectionAfterPos(tr.doc, after));\n }\n\n if (dispatch) {\n commands.focus();\n dispatch(tr);\n }\n\n return true;\n },\n refreshResponseArea:\n () =>\n ({ tr, state, commands, dispatch }) => {\n const { selection } = state;\n const node = selection.$from.nodeAfter;\n const nodePos = selection.from;\n\n tr.setNodeMarkup(nodePos, undefined, { ...node?.attrs, updated: `${Date.now()}` });\n tr.setSelection(NodeSelection.create(tr.doc, nodePos));\n\n if (dispatch) {\n commands.focus();\n dispatch(tr);\n }\n\n return true;\n },\n };\n },\n});\n\n/**\n * ExplicitConstructedResponse Node\n */\nexport const ExplicitConstructedResponseNode = Node.create({\n name: 'explicit_constructed_response',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"explicit_constructed_response\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'explicit_constructed_response',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <ExplicitConstructedResponse {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * MathTemplated Node\n */\nexport const MathTemplatedNode = Node.create({\n name: 'math_templated',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"math_templated\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'math_templated',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <MathTemplated {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * DragInTheBlank Node\n */\nexport const DragInTheBlankNode = Node.create({\n name: 'drag_in_the_blank',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n id: { default: null },\n value: { default: '' },\n inTable: { default: null },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"drag_in_the_blank\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n id: el.dataset.id,\n value: el.dataset.value,\n inTable: el.dataset.inTable,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'drag_in_the_blank',\n 'data-index': HTMLAttributes.index,\n 'data-id': HTMLAttributes.id,\n 'data-value': HTMLAttributes.value,\n 'data-in-table': HTMLAttributes.inTable,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <DragInTheBlank {...{ ...props, options: this.options }} />);\n },\n});\n\n/**\n * InlineDropdown Node\n */\nexport const InlineDropdownNode = Node.create({\n name: 'inline_dropdown',\n group: 'inline',\n inline: true,\n atom: true,\n addAttributes() {\n return {\n index: { default: null },\n value: { default: '' },\n updated: { default: '' },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"inline_dropdown\"]',\n getAttrs: (el) => ({\n index: el.dataset.index,\n value: el.dataset.value,\n }),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return [\n 'span',\n {\n 'data-type': 'inline_dropdown',\n 'data-index': HTMLAttributes.index,\n 'data-value': HTMLAttributes.value,\n },\n ];\n },\n addNodeView() {\n return ReactNodeViewRenderer((props) => <InlineDropdown {...{ ...props, options: this.options }} />);\n },\n});\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,4BAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,eAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,eAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AAAiE,SAAAQ,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAA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|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.2.0-next.
|
|
6
|
+
"version": "1.2.0-next.13",
|
|
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": "a55cae1c6e8fbcbeadba23b79fd53924980571bf",
|
|
63
63
|
"scripts": {}
|
|
64
64
|
}
|
|
@@ -266,4 +266,39 @@ describe('EditableHtml', () => {
|
|
|
266
266
|
const { container } = render(<EditableHtml {...defaultProps} disableImageAlignmentButtons={true} />);
|
|
267
267
|
expect(container).toBeInTheDocument();
|
|
268
268
|
});
|
|
269
|
+
|
|
270
|
+
it('calls editorRef callback when editor is initialized', async () => {
|
|
271
|
+
const editorRef = jest.fn();
|
|
272
|
+
render(<EditableHtml {...defaultProps} editorRef={editorRef} />);
|
|
273
|
+
|
|
274
|
+
await waitFor(() => {
|
|
275
|
+
expect(editorRef).toHaveBeenCalled();
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('calls editorRef with the editor instance', async () => {
|
|
280
|
+
const editorRef = jest.fn();
|
|
281
|
+
render(<EditableHtml {...defaultProps} editorRef={editorRef} />);
|
|
282
|
+
|
|
283
|
+
await waitFor(() => {
|
|
284
|
+
expect(editorRef).toHaveBeenCalled();
|
|
285
|
+
// Verify it was called with an object that has editor-like properties
|
|
286
|
+
const callArg = editorRef.mock.calls[0][0];
|
|
287
|
+
expect(callArg).toHaveProperty('getHTML');
|
|
288
|
+
expect(callArg).toHaveProperty('commands');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('handles editorRef being undefined', () => {
|
|
293
|
+
const { container } = render(<EditableHtml {...defaultProps} editorRef={undefined} />);
|
|
294
|
+
expect(container).toBeInTheDocument();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('applies flex display to StyledEditorContent', async () => {
|
|
298
|
+
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
299
|
+
await waitFor(() => {
|
|
300
|
+
const editorContent = getByTestId('editor-content');
|
|
301
|
+
expect(editorContent).toBeInTheDocument();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
269
304
|
});
|
|
@@ -121,6 +121,7 @@ export function CharacterPicker({ editor, opts, onClose }) {
|
|
|
121
121
|
<div
|
|
122
122
|
ref={containerRef}
|
|
123
123
|
className="insert-character-dialog"
|
|
124
|
+
data-toolbar-for={editor.instanceId}
|
|
124
125
|
style={{
|
|
125
126
|
visibility: position.top === 0 && position.left === 0 ? 'hidden' : 'initial',
|
|
126
127
|
position: 'absolute',
|
|
@@ -280,6 +280,12 @@ export const EditableHtml = (props) => {
|
|
|
280
280
|
[props.charactersLimit],
|
|
281
281
|
);
|
|
282
282
|
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
if (props.editorRef) {
|
|
285
|
+
props.editorRef(editor);
|
|
286
|
+
}
|
|
287
|
+
}, [props.editorRef, editor]);
|
|
288
|
+
|
|
283
289
|
useEffect(() => {
|
|
284
290
|
editor?.setEditable(!props.disabled);
|
|
285
291
|
}, [props.disabled, editor]);
|
|
@@ -349,8 +355,10 @@ export const EditableHtml = (props) => {
|
|
|
349
355
|
const StyledEditorContent = styled(EditorContent, {
|
|
350
356
|
shouldForwardProp: (prop) => !['showParagraph', 'separateParagraph'].includes(prop),
|
|
351
357
|
})(({ showParagraph, separateParagraph }) => ({
|
|
358
|
+
display: 'flex',
|
|
352
359
|
outline: 'none !important',
|
|
353
360
|
'& .ProseMirror': {
|
|
361
|
+
flex: 1,
|
|
354
362
|
padding: '5px',
|
|
355
363
|
maxHeight: '500px',
|
|
356
364
|
outline: 'none !important',
|
|
@@ -95,9 +95,12 @@ function MenuBar({
|
|
|
95
95
|
ctx.editor?.isActive('imageUploadNode') ||
|
|
96
96
|
ctx.editor?.isActive('drag_in_the_blank');
|
|
97
97
|
|
|
98
|
+
const hasTextSelectionInTable = selection && selection.empty === false && ctx.editor.isActive('table');
|
|
99
|
+
|
|
98
100
|
return {
|
|
99
101
|
currentNode,
|
|
100
102
|
hideDefaultToolbar,
|
|
103
|
+
hasTextSelectionInTable,
|
|
101
104
|
isFocused: ctx.editor?.isFocused,
|
|
102
105
|
isBold: ctx.editor.isActive('bold') ?? false,
|
|
103
106
|
canBold: ctx.editor.can().chain().toggleBold().run() ?? false,
|
|
@@ -162,35 +165,35 @@ function MenuBar({
|
|
|
162
165
|
{
|
|
163
166
|
icon: <AddRow />,
|
|
164
167
|
onClick: (editor) => editor.chain().focus().addRowAfter().run(),
|
|
165
|
-
hidden: (state) => !state.isTable,
|
|
168
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
166
169
|
isActive: (state) => state.isTable,
|
|
167
170
|
isDisabled: (state) => !state.canTable,
|
|
168
171
|
},
|
|
169
172
|
{
|
|
170
173
|
icon: <RemoveRow />,
|
|
171
174
|
onClick: (editor) => editor.chain().focus().deleteRow().run(),
|
|
172
|
-
hidden: (state) => !state.isTable,
|
|
175
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
173
176
|
isActive: (state) => state.isTable,
|
|
174
177
|
isDisabled: (state) => !state.canTable,
|
|
175
178
|
},
|
|
176
179
|
{
|
|
177
180
|
icon: <AddColumn />,
|
|
178
181
|
onClick: (editor) => editor.chain().focus().addColumnAfter().run(),
|
|
179
|
-
hidden: (state) => !state.isTable,
|
|
182
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
180
183
|
isActive: (state) => state.isTable,
|
|
181
184
|
isDisabled: (state) => !state.canTable,
|
|
182
185
|
},
|
|
183
186
|
{
|
|
184
187
|
icon: <RemoveColumn />,
|
|
185
188
|
onClick: (editor) => editor.chain().focus().deleteColumn().run(),
|
|
186
|
-
hidden: (state) => !state.isTable,
|
|
189
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
187
190
|
isActive: (state) => state.isTable,
|
|
188
191
|
isDisabled: (state) => !state.canTable,
|
|
189
192
|
},
|
|
190
193
|
{
|
|
191
194
|
icon: <RemoveTable />,
|
|
192
195
|
onClick: (editor) => editor.chain().focus().deleteTable().run(),
|
|
193
|
-
hidden: (state) => !state.isTable,
|
|
196
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
194
197
|
isActive: (state) => state.isTable,
|
|
195
198
|
isDisabled: (state) => !state.canTable,
|
|
196
199
|
},
|
|
@@ -206,54 +209,54 @@ function MenuBar({
|
|
|
206
209
|
|
|
207
210
|
editor.commands.updateAttributes('table', update);
|
|
208
211
|
},
|
|
209
|
-
hidden: (state) => !state.isTable,
|
|
212
|
+
hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
|
|
210
213
|
isActive: (state) => state.tableHasBorder,
|
|
211
214
|
isDisabled: (state) => !state.canTable,
|
|
212
215
|
},
|
|
213
216
|
{
|
|
214
217
|
icon: <Bold />,
|
|
215
218
|
onClick: (editor) => editor.chain().focus().toggleBold().run(),
|
|
216
|
-
hidden: (
|
|
219
|
+
hidden: () => !activePlugins?.includes('bold'),
|
|
217
220
|
isActive: (state) => state.isBold,
|
|
218
221
|
isDisabled: (state) => !state.canBold,
|
|
219
222
|
},
|
|
220
223
|
{
|
|
221
224
|
icon: <Italic />,
|
|
222
225
|
onClick: (editor) => editor.chain().focus().toggleItalic().run(),
|
|
223
|
-
hidden: (
|
|
226
|
+
hidden: () => !activePlugins?.includes('italic'),
|
|
224
227
|
isActive: (state) => state.isItalic,
|
|
225
228
|
isDisabled: (state) => !state.canItalic,
|
|
226
229
|
},
|
|
227
230
|
{
|
|
228
231
|
icon: <Strikethrough />,
|
|
229
232
|
onClick: (editor) => editor.chain().focus().toggleStrike().run(),
|
|
230
|
-
hidden: (
|
|
233
|
+
hidden: () => !activePlugins?.includes('strikethrough'),
|
|
231
234
|
isActive: (state) => state.isStrike,
|
|
232
235
|
isDisabled: (state) => !state.canStrike,
|
|
233
236
|
},
|
|
234
237
|
{
|
|
235
238
|
icon: <Code />,
|
|
236
239
|
onClick: (editor) => editor.chain().focus().toggleCode().run(),
|
|
237
|
-
hidden: (
|
|
240
|
+
hidden: () => !activePlugins?.includes('code'),
|
|
238
241
|
isActive: (state) => state.isCode,
|
|
239
242
|
isDisabled: (state) => !state.canCode,
|
|
240
243
|
},
|
|
241
244
|
{
|
|
242
245
|
icon: <Underline />,
|
|
243
246
|
onClick: (editor) => editor.chain().focus().toggleUnderline().run(),
|
|
244
|
-
hidden: (
|
|
247
|
+
hidden: () => !activePlugins?.includes('underline'),
|
|
245
248
|
isActive: (state) => state.isUnderline,
|
|
246
249
|
},
|
|
247
250
|
{
|
|
248
251
|
icon: <SubscriptIcon />,
|
|
249
252
|
onClick: (editor) => editor.chain().focus().toggleSubscript().run(),
|
|
250
|
-
hidden: (
|
|
253
|
+
hidden: () => !activePlugins?.includes('subscript'),
|
|
251
254
|
isActive: (state) => state.isSubScript,
|
|
252
255
|
},
|
|
253
256
|
{
|
|
254
257
|
icon: <SuperscriptIcon />,
|
|
255
258
|
onClick: (editor) => editor.chain().focus().toggleSuperscript().run(),
|
|
256
|
-
hidden: (
|
|
259
|
+
hidden: () => !activePlugins?.includes('superscript'),
|
|
257
260
|
isActive: (state) => state.isSuperScript,
|
|
258
261
|
},
|
|
259
262
|
{
|
|
@@ -263,22 +266,22 @@ function MenuBar({
|
|
|
263
266
|
},
|
|
264
267
|
{
|
|
265
268
|
icon: <TheatersIcon />,
|
|
266
|
-
hidden: (
|
|
269
|
+
hidden: () => !activePlugins?.includes('video'),
|
|
267
270
|
onClick: (editor) => editor.chain().focus().insertMedia({ type: 'video' }).run(),
|
|
268
271
|
},
|
|
269
272
|
{
|
|
270
273
|
icon: <VolumeUpIcon />,
|
|
271
|
-
hidden: (
|
|
274
|
+
hidden: () => !activePlugins?.includes('audio'),
|
|
272
275
|
onClick: (editor) => editor.chain().focus().insertMedia({ type: 'audio', tag: 'audio' }).run(),
|
|
273
276
|
},
|
|
274
277
|
{
|
|
275
278
|
icon: <CSSIcon />,
|
|
276
|
-
hidden: (
|
|
279
|
+
hidden: () => !activePlugins?.includes('css'),
|
|
277
280
|
onClick: (editor) => editor.commands.openCSSClassDialog(),
|
|
278
281
|
},
|
|
279
282
|
{
|
|
280
283
|
icon: <HeadingIcon />,
|
|
281
|
-
hidden: (
|
|
284
|
+
hidden: () => !activePlugins?.includes('h3'),
|
|
282
285
|
onClick: (editor) => editor.chain().focus().toggleHeading({ level: 3 }).run(),
|
|
283
286
|
isActive: (state) => state.isHeading3,
|
|
284
287
|
},
|
|
@@ -299,30 +302,30 @@ function MenuBar({
|
|
|
299
302
|
},
|
|
300
303
|
{
|
|
301
304
|
icon: <TextAlignIcon editor={editor} />,
|
|
302
|
-
hidden: (
|
|
305
|
+
hidden: () => !activePlugins?.includes('text-align'),
|
|
303
306
|
onClick: () => {},
|
|
304
307
|
},
|
|
305
308
|
{
|
|
306
309
|
icon: <BulletedListIcon />,
|
|
307
|
-
hidden: (
|
|
310
|
+
hidden: () => !activePlugins?.includes('bulleted-list'),
|
|
308
311
|
onClick: (editor) => editor.chain().focus().toggleBulletList().run(),
|
|
309
312
|
isActive: (state) => state.isBulletList,
|
|
310
313
|
},
|
|
311
314
|
{
|
|
312
315
|
icon: <NumberedListIcon />,
|
|
313
|
-
hidden: (
|
|
316
|
+
hidden: () => !activePlugins?.includes('numbered-list'),
|
|
314
317
|
onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),
|
|
315
318
|
isActive: (state) => state.isOrderedList,
|
|
316
319
|
},
|
|
317
320
|
{
|
|
318
321
|
icon: <Undo />,
|
|
319
|
-
hidden: (
|
|
322
|
+
hidden: () => !activePlugins?.includes('undo'),
|
|
320
323
|
onClick: (editor) => editor.chain().focus().undo().run(),
|
|
321
324
|
isDisabled: (state) => !state.canUndo,
|
|
322
325
|
},
|
|
323
326
|
{
|
|
324
327
|
icon: <Redo />,
|
|
325
|
-
hidden: (
|
|
328
|
+
hidden: () => !activePlugins?.includes('redo'),
|
|
326
329
|
onClick: (editor) => editor.chain().focus().redo().run(),
|
|
327
330
|
isDisabled: (state) => !state.canRedo,
|
|
328
331
|
},
|
|
@@ -194,4 +194,26 @@ describe('CharacterPicker', () => {
|
|
|
194
194
|
const dialog = container.querySelector('.insert-character-dialog');
|
|
195
195
|
expect(dialog).toHaveStyle({ position: 'absolute' });
|
|
196
196
|
});
|
|
197
|
+
|
|
198
|
+
it('adds data-toolbar-for attribute with editor instanceId', () => {
|
|
199
|
+
const editorWithInstanceId = {
|
|
200
|
+
...mockEditor,
|
|
201
|
+
instanceId: 'editor-123',
|
|
202
|
+
};
|
|
203
|
+
const opts = {
|
|
204
|
+
characters: [['á', 'é']],
|
|
205
|
+
};
|
|
206
|
+
const { container } = render(<CharacterPicker editor={editorWithInstanceId} opts={opts} onClose={jest.fn()} />);
|
|
207
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
208
|
+
expect(dialog).toHaveAttribute('data-toolbar-for', 'editor-123');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('renders without instanceId gracefully', () => {
|
|
212
|
+
const opts = {
|
|
213
|
+
characters: [['á', 'é']],
|
|
214
|
+
};
|
|
215
|
+
const { container } = render(<CharacterPicker editor={mockEditor} opts={opts} onClose={jest.fn()} />);
|
|
216
|
+
const dialog = container.querySelector('.insert-character-dialog');
|
|
217
|
+
expect(dialog).toBeInTheDocument();
|
|
218
|
+
});
|
|
197
219
|
});
|
|
@@ -184,4 +184,153 @@ describe('InlineDropdown', () => {
|
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
+
|
|
188
|
+
it('passes editorCallback to InlineDropdownToolbar', async () => {
|
|
189
|
+
const mockToolbarComponent = jest.fn(({ editorCallback }) => {
|
|
190
|
+
editorCallback?.({ instanceId: 'test-instance' });
|
|
191
|
+
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const mockOptionsWithCallback = {
|
|
195
|
+
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const { queryByTestId } = render(
|
|
199
|
+
<InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
await waitFor(() => {
|
|
203
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('stores toolbar editor instance in ref when editorCallback is called', async () => {
|
|
208
|
+
let capturedCallback;
|
|
209
|
+
const mockToolbarComponent = ({ editorCallback }) => {
|
|
210
|
+
capturedCallback = editorCallback;
|
|
211
|
+
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const mockOptionsWithCallback = {
|
|
215
|
+
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const { queryByTestId } = render(
|
|
219
|
+
<InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
await waitFor(() => {
|
|
223
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Verify callback exists
|
|
227
|
+
expect(capturedCallback).toBeDefined();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('handles click outside logic with data-toolbar-for attribute', async () => {
|
|
231
|
+
const editorWithInstanceId = {
|
|
232
|
+
...mockEditor,
|
|
233
|
+
instanceId: 'editor-123',
|
|
234
|
+
_toolbarOpened: false,
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Mock the toolbar callback to set the toolbar editor instance
|
|
238
|
+
let capturedCallback;
|
|
239
|
+
const mockToolbarComponent = ({ editorCallback }) => {
|
|
240
|
+
React.useEffect(() => {
|
|
241
|
+
capturedCallback = editorCallback;
|
|
242
|
+
if (editorCallback) {
|
|
243
|
+
editorCallback({ instanceId: 'editor-123' });
|
|
244
|
+
}
|
|
245
|
+
}, [editorCallback]);
|
|
246
|
+
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const mockOptionsWithCallback = {
|
|
250
|
+
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const { container, queryByTestId } = render(
|
|
254
|
+
<InlineDropdown
|
|
255
|
+
{...defaultProps}
|
|
256
|
+
editor={editorWithInstanceId}
|
|
257
|
+
options={mockOptionsWithCallback}
|
|
258
|
+
selected={true}
|
|
259
|
+
/>,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
await waitFor(() => {
|
|
263
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Create an element with data-toolbar-for attribute
|
|
267
|
+
const otherToolbar = document.createElement('div');
|
|
268
|
+
otherToolbar.setAttribute('data-toolbar-for', 'editor-456');
|
|
269
|
+
document.body.appendChild(otherToolbar);
|
|
270
|
+
|
|
271
|
+
await waitFor(() => {
|
|
272
|
+
fireEvent.mouseDown(otherToolbar);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Cleanup
|
|
276
|
+
document.body.removeChild(otherToolbar);
|
|
277
|
+
expect(container).toBeInTheDocument();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('does not close when clicking inside same editor toolbar', async () => {
|
|
281
|
+
const editorWithInstanceId = {
|
|
282
|
+
...mockEditor,
|
|
283
|
+
instanceId: 'editor-123',
|
|
284
|
+
_toolbarOpened: false,
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
let toolbarEditorInstance;
|
|
288
|
+
const mockToolbarComponent = ({ editorCallback }) => {
|
|
289
|
+
React.useEffect(() => {
|
|
290
|
+
if (editorCallback) {
|
|
291
|
+
editorCallback({ instanceId: 'editor-123' });
|
|
292
|
+
toolbarEditorInstance = { instanceId: 'editor-123' };
|
|
293
|
+
}
|
|
294
|
+
}, [editorCallback]);
|
|
295
|
+
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const mockOptionsWithCallback = {
|
|
299
|
+
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
render(
|
|
303
|
+
<InlineDropdown
|
|
304
|
+
{...defaultProps}
|
|
305
|
+
editor={editorWithInstanceId}
|
|
306
|
+
options={mockOptionsWithCallback}
|
|
307
|
+
selected={true}
|
|
308
|
+
/>,
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
await waitFor(() => {
|
|
312
|
+
expect(mockOptionsWithCallback.respAreaToolbar).toHaveBeenCalled();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('checks editor._toolbarOpened in click outside handler', async () => {
|
|
317
|
+
const editorWithToolbarOpened = {
|
|
318
|
+
...mockEditor,
|
|
319
|
+
_toolbarOpened: true,
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const { queryByTestId } = render(
|
|
323
|
+
<InlineDropdown {...defaultProps} editor={editorWithToolbarOpened} selected={true} />,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
await waitFor(() => {
|
|
327
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// When _toolbarOpened is true, clicking outside should not close
|
|
331
|
+
fireEvent.mouseDown(document.body);
|
|
332
|
+
|
|
333
|
+
// Toolbar should still be visible
|
|
334
|
+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
335
|
+
});
|
|
187
336
|
});
|
|
@@ -214,4 +214,36 @@ describe('StyledMenuBar', () => {
|
|
|
214
214
|
toolbar?.dispatchEvent(event);
|
|
215
215
|
expect(preventDefaultSpy).toHaveBeenCalled();
|
|
216
216
|
});
|
|
217
|
+
|
|
218
|
+
it('calculates hasTextSelectionInTable correctly when selection is not empty in table', () => {
|
|
219
|
+
// This test verifies the hasTextSelectionInTable state computation
|
|
220
|
+
const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table', 'bold', 'italic']} />);
|
|
221
|
+
expect(container).toBeInTheDocument();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('hides table manipulation buttons when text is selected in table', () => {
|
|
225
|
+
// When hasTextSelectionInTable is true, table row/column buttons should be hidden
|
|
226
|
+
const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
|
|
227
|
+
// The component should render but table manipulation buttons should be conditional
|
|
228
|
+
expect(container).toBeInTheDocument();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('shows table manipulation buttons when no text is selected in table', () => {
|
|
232
|
+
// When hasTextSelectionInTable is false, table row/column buttons should be visible
|
|
233
|
+
const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table']} />);
|
|
234
|
+
expect(container).toBeInTheDocument();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('shows text formatting buttons regardless of table state', () => {
|
|
238
|
+
// Bold, italic, etc. should always be visible when their plugin is active
|
|
239
|
+
const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['bold', 'italic', 'underline']} />);
|
|
240
|
+
const buttons = container.querySelectorAll('button');
|
|
241
|
+
expect(buttons.length).toBeGreaterThan(0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('does not hide text formatting buttons when in table', () => {
|
|
245
|
+
// Verify that the removal of "|| state.isTable" condition works correctly
|
|
246
|
+
const { container } = render(<StyledMenuBar {...defaultProps} activePlugins={['table', 'bold', 'italic']} />);
|
|
247
|
+
expect(container).toBeInTheDocument();
|
|
248
|
+
});
|
|
217
249
|
});
|
|
@@ -12,6 +12,7 @@ const InlineDropdown = (props) => {
|
|
|
12
12
|
// Needed because items with values inside have different positioning for some reason
|
|
13
13
|
const html = value || '<div> </div>';
|
|
14
14
|
const toolbarRef = useRef(null);
|
|
15
|
+
const toolbarEditor = useRef(null);
|
|
15
16
|
const [showToolbar, setShowToolbar] = useState(false);
|
|
16
17
|
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
17
18
|
const InlineDropdownToolbar = options.respAreaToolbar(node, editor, () => {});
|
|
@@ -41,7 +42,11 @@ const InlineDropdown = (props) => {
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
const handleClickOutside = (event) => {
|
|
45
|
+
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
|
|
46
|
+
|
|
44
47
|
if (
|
|
48
|
+
(!insideSomeEditor || insideSomeEditor.dataset.toolbarFor !== toolbarEditor.current.instanceId) &&
|
|
49
|
+
!editor._toolbarOpened &&
|
|
45
50
|
toolbarRef.current &&
|
|
46
51
|
!toolbarRef.current.contains(event.target) &&
|
|
47
52
|
!event.target.closest('[data-inline-node]')
|
|
@@ -116,7 +121,11 @@ const InlineDropdown = (props) => {
|
|
|
116
121
|
{showToolbar &&
|
|
117
122
|
ReactDOM.createPortal(
|
|
118
123
|
<div ref={toolbarRef} style={{ zIndex: 1 }}>
|
|
119
|
-
<InlineDropdownToolbar
|
|
124
|
+
<InlineDropdownToolbar
|
|
125
|
+
editorCallback={(instance) => {
|
|
126
|
+
toolbarEditor.current = instance;
|
|
127
|
+
}}
|
|
128
|
+
/>
|
|
120
129
|
</div>,
|
|
121
130
|
document.body,
|
|
122
131
|
)}
|