@sanity/visual-editing
Version:
[](https://npm-stat.com/charts.html?package=@sanity/visual-editing) [](https://
1 lines • 2.15 kB
Source Map (JSON)
{"version":3,"file":"enableVisualEditing.cjs","sources":["../../src/ui/enableVisualEditing.tsx"],"sourcesContent":["import type {DisableVisualEditing, VisualEditingOptions} from '../types'\n\n/**\n * Enables Visual Editing overlay in a page with sourcemap encoding.\n *\n * This will overlay UI on hovered elements that deep-links to Sanity Studio.\n * @public\n */\nexport function enableVisualEditing(options: VisualEditingOptions = {}): DisableVisualEditing {\n const controller = new AbortController()\n // Lazy load everything, react, the app, all of it\n import('./renderVisualEditing').then(({renderVisualEditing}) => {\n const {signal} = controller\n /**\n * Due to lazy loading it's possible for the following to happen, and is a consequence of dynamic ESM imports not being cancellable natively:\n * 1. Userland calls `const disableVisualEditing = enableVisualEditing()` and the dynamic ESM import is started.\n * 2. The dynamic import uses the network, and it takes a while to load.\n * 3. The user navigates to a different page in the app that doesn't need Visual Editing, for example a login page.\n * 4. Since the app is no longer in a state where Visual Editing is needed, the user calls `disableVisualEditing()`.\n * 5. The dynamic import eventually resolves and this function is called.\n * When this happens we want to skip calling `renderVisualEditing` since we know it's no longer needed.\n */\n if (signal.aborted) return\n\n // Hand off to the render function with the signal, which will be subscribed to for detecting when to cancel the rendering if needed and unmount the app.\n renderVisualEditing(signal, options)\n })\n\n return () => {\n controller.abort()\n }\n}\n"],"names":["exports","e","enableVisualEditing","options","controller","AbortController","Promise","resolve","then","require","renderVisualEditing","signal","aborted","abort"],"mappings":"aA+BAA,QAAAC,EAvBgBC,SAAoBC,EAAgC,IAC5DC,MAAAA,EAAa,IAAIC,gBAEhB,OAAAC,QAAAC,UAAAC,MAAA,WAAA,OAAAC,QAAA,gCAAyBD,MAAK,EAAEE,0BAC/B,MAAAC,OAACA,GAAUP,EAUNQ,EAAAA,SAGXF,EAAoBC,EAAQR,EAAO,IAG9B,KACLC,EAAWS,OAAM,CAErB"}