{"version":3,"file":"ShowSelection-DhXglbt8.cjs","names":[],"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    { enabledSet: new Set<string>() },\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.enabledSet.size === 0) {\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     * @param shouldShow - Whether to show the selection decoration\n     * @param key - The key of the selection to show or hide,\n     * this is necessary to prevent disabling ShowSelection from one place\n     * will interfere with other parts of the code that need to show the selection decoration\n     * (e.g.: CreateLinkButton and AIExtension)\n     */\n    showSelection(shouldShow: boolean, key: string) {\n      store.setState({\n        enabledSet: shouldShow\n          ? new Set([...store.state.enabledSet, key])\n          : new Set([...store.state.enabledSet].filter((k) => k !== key)),\n      });\n    },\n  } as const;\n});\n"],"mappings":"sHAOA,IAAM,EAAa,IAAI,EAAA,UAAU,2BAA2B,CAO/C,EAAyB,EAAA,GAAiB,CAAE,YAAa,CACpE,IAAM,EAAQ,EAAA,EACZ,CAAE,WAAY,IAAI,IAAe,CACjC,CACE,UAAW,CACT,EAAO,SAAU,GAAO,EAAG,QAAQ,EAAY,EAAE,CAAC,CAAC,EAEtD,CACF,CACD,MAAO,CACL,IAAK,gBACL,QACA,mBAAoB,CAClB,IAAI,EAAA,OAAO,CACT,IAAK,EACL,MAAO,CACL,YAAc,GAAU,CACtB,GAAM,CAAE,MAAK,aAAc,EAC3B,GAAI,EAAM,MAAM,WAAW,OAAS,EAClC,OAAO,EAAA,cAAc,MAEvB,IAAM,EAAM,EAAA,WAAW,OAAO,EAAU,KAAM,EAAU,GAAI,CAC1D,sBAAuB,OACxB,CAAC,CACF,OAAO,EAAA,cAAc,OAAO,EAAK,CAAC,EAAI,CAAC,EAE1C,CACF,CAAC,CACH,CAUD,cAAc,EAAqB,EAAa,CAC9C,EAAM,SAAS,CACb,WAAY,EACR,IAAI,IAAI,CAAC,GAAG,EAAM,MAAM,WAAY,EAAI,CAAC,CACzC,IAAI,IAAI,CAAC,GAAG,EAAM,MAAM,WAAW,CAAC,OAAQ,GAAM,IAAM,EAAI,CAAC,CAClE,CAAC,EAEL,EACD"}