@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
1 lines • 2.44 kB
Source Map (JSON)
{"version":3,"file":"ShowSelection-BW37oJ6h.cjs","sources":["../src/extensions/ShowSelection/ShowSelection.ts"],"sourcesContent":["import { Plugin, PluginKey } from \"prosemirror-state\";\nimport { Decoration, DecorationSet } from \"prosemirror-view\";\nimport {\n createExtension,\n createStore,\n} from \"../../editor/BlockNoteExtension.js\";\n\nconst PLUGIN_KEY = new PluginKey(`blocknote-show-selection`);\n\n/**\n * Plugin that shows adds a decoration around the current selection\n * This can be used to highlight the current selection in the UI even when the\n * text editor is not focused.\n */\nexport const ShowSelectionExtension = createExtension(({ editor }) => {\n const store = createStore(\n { enabled: false },\n {\n onUpdate() {\n editor.transact((tr) => tr.setMeta(PLUGIN_KEY, {}));\n },\n },\n );\n return {\n key: \"showSelection\",\n store,\n prosemirrorPlugins: [\n new Plugin({\n key: PLUGIN_KEY,\n props: {\n decorations: (state) => {\n const { doc, selection } = state;\n if (!store.state.enabled) {\n return DecorationSet.empty;\n }\n const dec = Decoration.inline(selection.from, selection.to, {\n \"data-show-selection\": \"true\",\n });\n return DecorationSet.create(doc, [dec]);\n },\n },\n }),\n ],\n /**\n * Show or hide the selection decoration\n */\n showSelection(shouldShow: boolean) {\n store.setState({ enabled: shouldShow });\n },\n } as const;\n});\n"],"names":["PLUGIN_KEY","PluginKey","ShowSelectionExtension","createExtension","editor","store","createStore","tr","Plugin","state","doc","selection","DecorationSet","dec","Decoration","shouldShow"],"mappings":"+HAOMA,EAAa,IAAIC,EAAAA,UAAU,0BAA0B,EAO9CC,EAAyBC,EAAAA,gBAAgB,CAAC,CAAE,OAAAC,KAAa,CACpE,MAAMC,EAAQC,EAAAA,YACZ,CAAE,QAAS,EAAA,EACX,CACE,UAAW,CACTF,EAAO,SAAUG,GAAOA,EAAG,QAAQP,EAAY,CAAA,CAAE,CAAC,CACpD,CAAA,CACF,EAEF,MAAO,CACL,IAAK,gBACL,MAAAK,EACA,mBAAoB,CAClB,IAAIG,SAAO,CACT,IAAKR,EACL,MAAO,CACL,YAAcS,GAAU,CACtB,KAAM,CAAE,IAAAC,EAAK,UAAAC,CAAA,EAAcF,EAC3B,GAAI,CAACJ,EAAM,MAAM,QACf,OAAOO,EAAAA,cAAc,MAEvB,MAAMC,EAAMC,EAAAA,WAAW,OAAOH,EAAU,KAAMA,EAAU,GAAI,CAC1D,sBAAuB,MAAA,CACxB,EACD,OAAOC,EAAAA,cAAc,OAAOF,EAAK,CAACG,CAAG,CAAC,CACxC,CAAA,CACF,CACD,CAAA,EAKH,cAAcE,EAAqB,CACjCV,EAAM,SAAS,CAAE,QAASU,CAAA,CAAY,CACxC,CAAA,CAEJ,CAAC"}