{"version":3,"file":"BlockKeymap.cjs","sources":["../../../../../../../src/components/ui/editor/ihub-editor/blocks/BlockKeymap.ts"],"sourcesContent":["import { Extension } from \"@tiptap/core\";\nimport { Plugin, PluginKey } from \"@tiptap/pm/state\";\nimport { Decoration, DecorationSet } from \"@tiptap/pm/view\";\nimport { moveBlockSibling, movableBlockAt } from \"./blockOps\";\n\n/** Meta: the position of the block being dragged, or null when the drag ends. */\nexport const blockDragKey = new PluginKey<number | null>(\"ihubBlockDrag\");\n\n/**\n * ⌘⇧↑ / ⌘⇧↓ (Ctrl on Windows) move the current block within its parent (the\n * page, or a banner / callout / toggle), as in Notion,\n * and a decoration dims the block while it is being dragged. A decoration is\n * needed because ProseMirror redraws its own DOM and would drop a class added directly.\n */\nconst BlockKeymap = Extension.create({\n  name: \"blockKeymap\",\n\n  addKeyboardShortcuts() {\n    const move = (direction: -1 | 1) => () => {\n      const { state, view } = this.editor;\n      const pos = movableBlockAt(state);\n      if (pos === null) return false;\n      const tr = moveBlockSibling(state, pos, direction);\n      if (!tr) return true; // already at the edge: swallow so the caret doesn't jump\n      view.dispatch(tr);\n      return true;\n    };\n    return {\n      \"Mod-Shift-ArrowUp\": move(-1),\n      \"Mod-Shift-ArrowDown\": move(1),\n    };\n  },\n\n  addProseMirrorPlugins() {\n    return [\n      new Plugin<number | null>({\n        key: blockDragKey,\n        state: {\n          init: () => null,\n          apply: (tr, value) => {\n            const meta = tr.getMeta(blockDragKey);\n            if (meta !== undefined) return meta as number | null;\n            return value === null ? null : tr.mapping.map(value);\n          },\n        },\n        props: {\n          decorations: (state) => {\n            const pos = blockDragKey.getState(state);\n            if (pos === null || pos === undefined) return null;\n            const node = state.doc.nodeAt(pos);\n            if (!node) return null;\n            return DecorationSet.create(state.doc, [\n              Decoration.node(pos, pos + node.nodeSize, { class: \"ihub-te-block-dragging\" }),\n            ]);\n          },\n        },\n      }),\n    ];\n  },\n});\n\nexport default BlockKeymap;\n"],"names":["blockDragKey","PluginKey","BlockKeymap","Extension","create","name","addKeyboardShortcuts","_this","this","move","direction","_this$editor","editor","state","view","pos","movableBlockAt","tr","moveBlockSibling","dispatch","addProseMirrorPlugins","Plugin","key","init","apply","value","meta","getMeta","undefined","mapping","map","props","decorations","getState","node","doc","nodeAt","DecorationSet","Decoration","nodeSize","class"],"mappings":"odAMaA,EAAe,IAAIC,EAASA,UAAgB,iBAQnDC,EAAcC,EAASA,UAACC,OAAO,CACnCC,KAAM,cAENC,qBAAoB,WAAA,IAAAC,EAAAC,KACZC,EAAO,SAACC,GAAiB,OAAK,WAClC,IAAAC,EAAwBJ,EAAKK,OAArBC,EAAKF,EAALE,MAAOC,EAAIH,EAAJG,KACTC,EAAMC,iBAAeH,GAC3B,GAAY,OAARE,EAAc,OAAO,EACzB,IAAME,EAAKC,EAAgBA,iBAACL,EAAOE,EAAKL,GACxC,OAAKO,IACLH,EAAKK,SAASF,IACP,GACR,EACD,MAAO,CACL,oBAAqBR,GAAM,GAC3B,sBAAuBA,EAAK,GAE/B,EAEDW,sBAAqB,WACnB,MAAO,CACL,IAAIC,EAAAA,OAAsB,CACxBC,IAAKtB,EACLa,MAAO,CACLU,KAAM,WAAF,OAAQ,IAAI,EAChBC,MAAO,SAACP,EAAIQ,GACV,IAAMC,EAAOT,EAAGU,QAAQ3B,GACxB,YAAa4B,IAATF,EAA2BA,EACd,OAAVD,EAAiB,KAAOR,EAAGY,QAAQC,IAAIL,EAChD,GAEFM,MAAO,CACLC,YAAa,SAACnB,GACZ,IAAME,EAAMf,EAAaiC,SAASpB,GAClC,GAAIE,QAAmC,OAAO,KAC9C,IAAMmB,EAAOrB,EAAMsB,IAAIC,OAAOrB,GAC9B,OAAKmB,EACEG,gBAAcjC,OAAOS,EAAMsB,IAAK,CACrCG,aAAWJ,KAAKnB,EAAKA,EAAMmB,EAAKK,SAAU,CAAEC,MAAO,6BAFnC,IAIpB,KAIR"}