@contentstack/live-preview-utils
Version:
Contentstack provides the Live Preview SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane.
1 lines • 1.36 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/visualBuilder/utils/insertSpaceAtCursor.ts"],"sourcesContent":["import { unicodeNonBreakingSpace } from \"./constants\";\n\nexport function insertSpaceAtCursor(element: HTMLElement) {\n // Check if the browser supports modern selection API\n const selection = window.getSelection();\n\n // Ensure there's a valid selection\n if (selection && selection.rangeCount > 0) {\n const range = selection.getRangeAt(0);\n\n // Create a text node with a space\n const spaceNode = document.createTextNode(unicodeNonBreakingSpace);\n\n // Delete any selected content first\n range.deleteContents();\n\n // Insert the space node\n range.insertNode(spaceNode);\n\n // Move cursor after the inserted space\n range.setStartAfter(spaceNode);\n range.setEndAfter(spaceNode);\n\n // Update the selection\n selection.removeAllRanges();\n selection.addRange(range);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAwC;AAEjC,SAAS,oBAAoB,SAAsB;AAEtD,QAAM,YAAY,OAAO,aAAa;AAGtC,MAAI,aAAa,UAAU,aAAa,GAAG;AACvC,UAAM,QAAQ,UAAU,WAAW,CAAC;AAGpC,UAAM,YAAY,SAAS,eAAe,wCAAuB;AAGjE,UAAM,eAAe;AAGrB,UAAM,WAAW,SAAS;AAG1B,UAAM,cAAc,SAAS;AAC7B,UAAM,YAAY,SAAS;AAG3B,cAAU,gBAAgB;AAC1B,cAAU,SAAS,KAAK;AAAA,EAC5B;AACJ;","names":[]}