@copilotkit/react-textarea 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4665 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/chunk-23Q6A46J.mjs +103 -0
- package/dist/chunk-23Q6A46J.mjs.map +1 -0
- package/dist/chunk-2C7O2EVM.mjs +27 -0
- package/dist/chunk-2C7O2EVM.mjs.map +1 -0
- package/dist/chunk-2IWVZ4PP.mjs +103 -0
- package/dist/chunk-2IWVZ4PP.mjs.map +1 -0
- package/dist/chunk-2QDCE7PD.mjs +32 -0
- package/dist/chunk-2QDCE7PD.mjs.map +1 -0
- package/dist/chunk-3QJOFG3V.mjs +25 -0
- package/dist/chunk-3QJOFG3V.mjs.map +1 -0
- package/dist/chunk-4NHVQZ67.mjs +108 -0
- package/dist/chunk-4NHVQZ67.mjs.map +1 -0
- package/dist/chunk-4PDYALMP.mjs +52 -0
- package/dist/chunk-4PDYALMP.mjs.map +1 -0
- package/dist/chunk-5GYFXESG.mjs +31 -0
- package/dist/chunk-5GYFXESG.mjs.map +1 -0
- package/dist/chunk-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-63LEUA5A.mjs +269 -0
- package/dist/chunk-63LEUA5A.mjs.map +1 -0
- package/dist/chunk-65XYKSXZ.mjs +226 -0
- package/dist/chunk-65XYKSXZ.mjs.map +1 -0
- package/dist/chunk-6SGWO63I.mjs +32 -0
- package/dist/chunk-6SGWO63I.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-AJ5OMEXM.mjs +13 -0
- package/dist/chunk-AJ5OMEXM.mjs.map +1 -0
- package/dist/chunk-D47EKHIF.mjs +26 -0
- package/dist/chunk-D47EKHIF.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +1 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-DFTV4TST.mjs +36 -0
- package/dist/chunk-DFTV4TST.mjs.map +1 -0
- package/dist/chunk-DL3JWL2E.mjs +170 -0
- package/dist/chunk-DL3JWL2E.mjs.map +1 -0
- package/dist/chunk-DRV2FOHZ.mjs +70 -0
- package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
- package/dist/chunk-ECR45NSD.mjs +104 -0
- package/dist/chunk-ECR45NSD.mjs.map +1 -0
- package/dist/chunk-EJGGLWWR.mjs +82 -0
- package/dist/chunk-EJGGLWWR.mjs.map +1 -0
- package/dist/chunk-F2ULK22F.mjs +39 -0
- package/dist/chunk-F2ULK22F.mjs.map +1 -0
- package/dist/chunk-F6RLSVG3.mjs +30 -0
- package/dist/chunk-F6RLSVG3.mjs.map +1 -0
- package/dist/chunk-GQN2HYFJ.mjs +22 -0
- package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +1 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-I72DKFHD.mjs +114 -0
- package/dist/chunk-I72DKFHD.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +1 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JLOABKLH.mjs +49 -0
- package/dist/chunk-JLOABKLH.mjs.map +1 -0
- package/dist/chunk-KMVGEY7Q.mjs +51 -0
- package/dist/chunk-KMVGEY7Q.mjs.map +1 -0
- package/dist/chunk-KNQIEOFP.mjs +19 -0
- package/dist/chunk-KNQIEOFP.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +1 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-LYB4B6MK.mjs +19 -0
- package/dist/chunk-LYB4B6MK.mjs.map +1 -0
- package/dist/chunk-MCNXIA4Q.mjs +75 -0
- package/dist/chunk-MCNXIA4Q.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +1 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +59 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-NAFNY4FL.mjs +17 -0
- package/dist/chunk-NAFNY4FL.mjs.map +1 -0
- package/dist/chunk-QFXR6DOA.mjs +64 -0
- package/dist/chunk-QFXR6DOA.mjs.map +1 -0
- package/dist/chunk-QJNFNPWH.mjs +85 -0
- package/dist/chunk-QJNFNPWH.mjs.map +1 -0
- package/dist/chunk-RUV6NBIF.mjs +1 -0
- package/dist/chunk-RUV6NBIF.mjs.map +1 -0
- package/dist/chunk-T4HVUB4T.mjs +60 -0
- package/dist/chunk-T4HVUB4T.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-VSVQZUPW.mjs +124 -0
- package/dist/chunk-VSVQZUPW.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +1 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WGWQRALG.mjs +83 -0
- package/dist/chunk-WGWQRALG.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +1 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-X2QR2YGZ.mjs +120 -0
- package/dist/chunk-X2QR2YGZ.mjs.map +1 -0
- package/dist/chunk-YLFAIYRY.mjs +50 -0
- package/dist/chunk-YLFAIYRY.mjs.map +1 -0
- package/dist/chunk-ZQSEYPNN.mjs +74 -0
- package/dist/chunk-ZQSEYPNN.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.css.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.d.ts +43 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js +1781 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.js.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +40 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/render-element.d.ts +7 -0
- package/dist/components/base-copilot-textarea/render-element.js +75 -0
- package/dist/components/base-copilot-textarea/render-element.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-element.mjs +8 -0
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.d.ts +7 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js +72 -0
- package/dist/components/base-copilot-textarea/render-placeholder.js.map +1 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +8 -0
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.d.ts +8 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js +112 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.js.map +1 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +9 -0
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.d.ts +3 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js +83 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.js.map +1 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +8 -0
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.css +9 -0
- package/dist/components/copilot-textarea/copilot-textarea.css.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.d.ts +171 -0
- package/dist/components/copilot-textarea/copilot-textarea.js +2261 -0
- package/dist/components/copilot-textarea/copilot-textarea.js.map +1 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs +49 -0
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.d.ts +18 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js +44 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +10 -0
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.d.ts +18 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js +164 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +16 -0
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.d.ts +12 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js +894 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.js.map +1 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +23 -0
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.d.ts +16 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js +603 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +18 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.d.ts +13 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js +626 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +19 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.d.ts +16 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js +133 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +12 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.d.ts +4 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js +626 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.js.map +1 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +20 -0
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -0
- package/dist/components/index.css +9 -0
- package/dist/components/index.css.map +1 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/index.js +2265 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +53 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.d.ts +10 -0
- package/dist/components/manual-ui/chip-with-icon.js +38 -0
- package/dist/components/manual-ui/chip-with-icon.js.map +1 -0
- package/dist/components/manual-ui/chip-with-icon.mjs +15 -0
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -0
- package/dist/components/source-search-box/source-search-box.d.ts +16 -0
- package/dist/components/source-search-box/source-search-box.js +240 -0
- package/dist/components/source-search-box/source-search-box.js.map +1 -0
- package/dist/components/source-search-box/source-search-box.mjs +13 -0
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -0
- package/dist/components/ui/button.d.ts +14 -0
- package/dist/components/ui/button.js +114 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/button.mjs +11 -0
- package/dist/components/ui/button.mjs.map +1 -0
- package/dist/components/ui/command.d.ts +53 -0
- package/dist/components/ui/command.js +285 -0
- package/dist/components/ui/command.js.map +1 -0
- package/dist/components/ui/command.mjs +26 -0
- package/dist/components/ui/command.mjs.map +1 -0
- package/dist/components/ui/dialog.d.ts +19 -0
- package/dist/components/ui/dialog.js +183 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dialog.mjs +21 -0
- package/dist/components/ui/dialog.mjs.map +1 -0
- package/dist/components/ui/label.d.ts +8 -0
- package/dist/components/ui/label.js +87 -0
- package/dist/components/ui/label.js.map +1 -0
- package/dist/components/ui/label.mjs +9 -0
- package/dist/components/ui/label.mjs.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +19 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.d.ts +15 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +11 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.d.ts +8 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js +194 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +9 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.d.ts +7 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js +180 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.js.map +1 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +10 -0
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.d.ts +22 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js +137 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +9 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.d.ts +23 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js +230 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.js.map +1 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +9 -0
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.d.ts +5 -0
- package/dist/hooks/misc/use-autosize-textarea.js +37 -0
- package/dist/hooks/misc/use-autosize-textarea.js.map +1 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs +8 -0
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -0
- package/dist/index.css +643 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2270 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +64 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/debouncer.d.ts +11 -0
- package/dist/lib/debouncer.js +76 -0
- package/dist/lib/debouncer.js.map +1 -0
- package/dist/lib/debouncer.mjs +8 -0
- package/dist/lib/debouncer.mjs.map +1 -0
- package/dist/lib/editor-to-text.d.ts +7 -0
- package/dist/lib/editor-to-text.js +69 -0
- package/dist/lib/editor-to-text.js.map +1 -0
- package/dist/lib/editor-to-text.mjs +8 -0
- package/dist/lib/editor-to-text.mjs.map +1 -0
- package/dist/lib/get-text-around-cursor.d.ts +15 -0
- package/dist/lib/get-text-around-cursor.js +131 -0
- package/dist/lib/get-text-around-cursor.js.map +1 -0
- package/dist/lib/get-text-around-cursor.mjs +14 -0
- package/dist/lib/get-text-around-cursor.mjs.map +1 -0
- package/dist/lib/retry.d.ts +3 -0
- package/dist/lib/retry.js +43 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/retry.mjs +8 -0
- package/dist/lib/retry.mjs.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js +51 -0
- package/dist/lib/slatejs-edits/add-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +8 -0
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.d.ts +8 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js +46 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.js.map +1 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +8 -0
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.d.ts +5 -0
- package/dist/lib/slatejs-edits/replace-text.js +53 -0
- package/dist/lib/slatejs-edits/replace-text.js.map +1 -0
- package/dist/lib/slatejs-edits/replace-text.mjs +8 -0
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.d.ts +8 -0
- package/dist/lib/slatejs-edits/with-partial-history.js +133 -0
- package/dist/lib/slatejs-edits/with-partial-history.js.map +1 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs +10 -0
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -0
- package/dist/lib/stream-promise-flatten.d.ts +12 -0
- package/dist/lib/stream-promise-flatten.js +72 -0
- package/dist/lib/stream-promise-flatten.js.map +1 -0
- package/dist/lib/stream-promise-flatten.mjs +8 -0
- package/dist/lib/stream-promise-flatten.mjs.map +1 -0
- package/dist/lib/utils.d.ts +9 -0
- package/dist/lib/utils.js +94 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/utils.mjs +16 -0
- package/dist/lib/utils.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.d.ts +23 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js +19 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.d.ts +20 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js +287 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.js.map +1 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +13 -0
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/editing-api-config.js +108 -0
- package/dist/types/autosuggestions-config/editing-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/index.d.ts +10 -0
- package/dist/types/autosuggestions-config/index.js +287 -0
- package/dist/types/autosuggestions-config/index.js.map +1 -0
- package/dist/types/autosuggestions-config/index.mjs +14 -0
- package/dist/types/autosuggestions-config/index.mjs.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js +101 -0
- package/dist/types/autosuggestions-config/insertions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.d.ts +3 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js +19 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.js.map +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +1 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.d.ts +15 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js +90 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.js.map +1 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +12 -0
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -0
- package/dist/types/base/autosuggestion-state.d.ts +8 -0
- package/dist/types/base/autosuggestion-state.js +19 -0
- package/dist/types/base/autosuggestion-state.js.map +1 -0
- package/dist/types/base/autosuggestion-state.mjs +1 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.d.ts +19 -0
- package/dist/types/base/autosuggestions-bare-function.js +19 -0
- package/dist/types/base/autosuggestions-bare-function.js.map +1 -0
- package/dist/types/base/autosuggestions-bare-function.mjs +1 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -0
- package/dist/types/base/base-autosuggestions-config.d.ts +87 -0
- package/dist/types/base/base-autosuggestions-config.js +54 -0
- package/dist/types/base/base-autosuggestions-config.js.map +1 -0
- package/dist/types/base/base-autosuggestions-config.mjs +8 -0
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.d.ts +5 -0
- package/dist/types/base/base-copilot-textarea-props.js +19 -0
- package/dist/types/base/base-copilot-textarea-props.js.map +1 -0
- package/dist/types/base/base-copilot-textarea-props.mjs +1 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -0
- package/dist/types/base/custom-editor.d.ts +29 -0
- package/dist/types/base/custom-editor.js +19 -0
- package/dist/types/base/custom-editor.js.map +1 -0
- package/dist/types/base/custom-editor.mjs +1 -0
- package/dist/types/base/custom-editor.mjs.map +1 -0
- package/dist/types/base/editor-autocomplete-state.d.ts +10 -0
- package/dist/types/base/editor-autocomplete-state.js +40 -0
- package/dist/types/base/editor-autocomplete-state.js.map +1 -0
- package/dist/types/base/editor-autocomplete-state.mjs +9 -0
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -0
- package/dist/types/base/index.d.ts +54 -0
- package/dist/types/base/index.js +56 -0
- package/dist/types/base/index.js.map +1 -0
- package/dist/types/base/index.mjs +9 -0
- package/dist/types/base/index.mjs.map +1 -0
- package/dist/types/html-copilot-textarea-element.d.ts +7 -0
- package/dist/types/html-copilot-textarea-element.js +19 -0
- package/dist/types/html-copilot-textarea-element.js.map +1 -0
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +289 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +19 -0
- package/dist/types/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +99 -0
- package/postcss.config.js +12 -0
- package/src/components/base-copilot-textarea/base-copilot-textarea.css +9 -0
- package/src/components/base-copilot-textarea/base-copilot-textarea.tsx +323 -0
- package/src/components/base-copilot-textarea/render-element.tsx +40 -0
- package/src/components/base-copilot-textarea/render-placeholder.tsx +24 -0
- package/src/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.tsx +80 -0
- package/src/components/base-copilot-textarea/use-add-branding-css.tsx +74 -0
- package/src/components/copilot-textarea/copilot-textarea.tsx +210 -0
- package/src/components/hovering-toolbar/hovering-editor-provider.tsx +31 -0
- package/src/components/hovering-toolbar/hovering-toolbar-components.tsx +88 -0
- package/src/components/hovering-toolbar/hovering-toolbar.tsx +154 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx +273 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.tsx +30 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.tsx +55 -0
- package/src/components/hovering-toolbar/text-insertion-prompt-box/index.ts +2 -0
- package/src/components/index.ts +4 -0
- package/src/components/manual-ui/chip-with-icon.tsx +17 -0
- package/src/components/source-search-box/source-search-box.tsx +117 -0
- package/src/components/ui/button.tsx +49 -0
- package/src/components/ui/command.tsx +141 -0
- package/src/components/ui/dialog.tsx +107 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/context/index.ts +1 -0
- package/src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts +142 -0
- package/src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx +100 -0
- package/src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts +93 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx +116 -0
- package/src/hooks/make-autosuggestions-function/use-make-standard-insertion-function.tsx +215 -0
- package/src/hooks/misc/use-autosize-textarea.tsx +18 -0
- package/src/index.tsx +7 -0
- package/src/lib/debouncer.ts +36 -0
- package/src/lib/editor-to-text.ts +61 -0
- package/src/lib/get-text-around-cursor.ts +135 -0
- package/src/lib/retry.tsx +23 -0
- package/src/lib/slatejs-edits/add-autocompletions.ts +30 -0
- package/src/lib/slatejs-edits/clear-autocompletions.ts +19 -0
- package/src/lib/slatejs-edits/replace-text.ts +28 -0
- package/src/lib/slatejs-edits/with-partial-history.ts +149 -0
- package/src/lib/stream-promise-flatten.ts +33 -0
- package/src/lib/utils.test.ts +7 -0
- package/src/lib/utils.ts +49 -0
- package/src/styles.css +3 -0
- package/src/types/autosuggestions-config/autosuggestions-config-user-specified.tsx +19 -0
- package/src/types/autosuggestions-config/autosuggestions-config.tsx +30 -0
- package/src/types/autosuggestions-config/editing-api-config.tsx +96 -0
- package/src/types/autosuggestions-config/index.ts +8 -0
- package/src/types/autosuggestions-config/insertions-api-config.tsx +87 -0
- package/src/types/autosuggestions-config/subtypes/make-system-prompt.ts +1 -0
- package/src/types/autosuggestions-config/suggestions-api-config.tsx +76 -0
- package/src/types/base/autosuggestion-state.ts +6 -0
- package/src/types/base/autosuggestions-bare-function.ts +30 -0
- package/src/types/base/base-autosuggestions-config.tsx +128 -0
- package/src/types/base/base-copilot-textarea-props.tsx +58 -0
- package/src/types/base/custom-editor.tsx +29 -0
- package/src/types/base/editor-autocomplete-state.ts +20 -0
- package/src/types/base/index.ts +6 -0
- package/src/types/html-copilot-textarea-element.ts +5 -0
- package/src/types/index.ts +3 -0
- package/tailwind.config.js +9 -0
- package/tsconfig.json +12 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
|
|
2
|
+
import { useCopilotContext } from "@copilotkit/react-core";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import {
|
|
5
|
+
CopilotRuntimeClient,
|
|
6
|
+
Message,
|
|
7
|
+
Role,
|
|
8
|
+
TextMessage,
|
|
9
|
+
convertGqlOutputToMessages,
|
|
10
|
+
convertMessagesToGqlInput,
|
|
11
|
+
filterAgentStateMessages,
|
|
12
|
+
CopilotRequestType,
|
|
13
|
+
} from "@copilotkit/runtime-client-gql";
|
|
14
|
+
import { retry } from "../../lib/retry";
|
|
15
|
+
import {
|
|
16
|
+
EditingEditorState,
|
|
17
|
+
Generator_InsertionOrEditingSuggestion,
|
|
18
|
+
} from "../../types/base/autosuggestions-bare-function";
|
|
19
|
+
import { InsertionsApiConfig } from "../../types/autosuggestions-config/insertions-api-config";
|
|
20
|
+
import { EditingApiConfig } from "../../types/autosuggestions-config/editing-api-config";
|
|
21
|
+
import { DocumentPointer } from "@copilotkit/react-core";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
25
|
+
* The function takes in the text before and after the cursor, and an abort signal.
|
|
26
|
+
* It sends a POST request to the API endpoint with the messages array containing the system message, few shot messages, and user messages.
|
|
27
|
+
* The function returns the suggestion from the API response.
|
|
28
|
+
*
|
|
29
|
+
* @param textareaPurpose - The purpose of the textarea. This is included in the system message.
|
|
30
|
+
* @param apiEndpoint - The API endpoint to send the autosuggestion request to.
|
|
31
|
+
* @param makeSystemMessage - A function that takes in a context string and returns a system message to include in the autosuggestion request.
|
|
32
|
+
* @param fewShotMessages - An array of few shot messages to include in the autosuggestion request.
|
|
33
|
+
* @param contextCategories - The categories of context strings we want to include. By default, we include the (default) "global" context category.
|
|
34
|
+
* @returns A memoized function that sends a request to the specified API endpoint to get an autosuggestion for the user's input.
|
|
35
|
+
*/
|
|
36
|
+
export function useMakeStandardInsertionOrEditingFunction(
|
|
37
|
+
textareaPurpose: string,
|
|
38
|
+
contextCategories: string[],
|
|
39
|
+
insertionApiConfig: InsertionsApiConfig,
|
|
40
|
+
editingApiConfig: EditingApiConfig,
|
|
41
|
+
): Generator_InsertionOrEditingSuggestion {
|
|
42
|
+
const runtimeClient: any = { generateCopilotResponse: (...args: any[]) => {} };
|
|
43
|
+
const { getContextString, copilotApiConfig } = useCopilotContext();
|
|
44
|
+
const headers = {
|
|
45
|
+
...(copilotApiConfig.publicApiKey
|
|
46
|
+
? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey }
|
|
47
|
+
: {}),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
async function runtimeClientResponseToStringStream(
|
|
51
|
+
responsePromise: ReturnType<typeof runtimeClient.generateCopilotResponse>,
|
|
52
|
+
) {
|
|
53
|
+
const messagesStream = runtimeClient.asStream(responsePromise);
|
|
54
|
+
|
|
55
|
+
return new ReadableStream({
|
|
56
|
+
async start(controller) {
|
|
57
|
+
const reader = messagesStream.getReader();
|
|
58
|
+
let sentContent = "";
|
|
59
|
+
|
|
60
|
+
while (true) {
|
|
61
|
+
const { done, value } = await reader.read();
|
|
62
|
+
if (done) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const messages = convertGqlOutputToMessages(value.generateCopilotResponse.messages);
|
|
67
|
+
|
|
68
|
+
let newContent = "";
|
|
69
|
+
|
|
70
|
+
for (const message of messages) {
|
|
71
|
+
if (message.isTextMessage()) {
|
|
72
|
+
newContent += message.content;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (newContent) {
|
|
76
|
+
const contentToSend = newContent.slice(sentContent.length);
|
|
77
|
+
controller.enqueue(contentToSend);
|
|
78
|
+
sentContent += contentToSend;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
controller.close();
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const insertionFunction = useCallback(
|
|
87
|
+
async (
|
|
88
|
+
editorState: EditingEditorState,
|
|
89
|
+
insertionPrompt: string,
|
|
90
|
+
documents: DocumentPointer[],
|
|
91
|
+
abortSignal: AbortSignal,
|
|
92
|
+
) => {
|
|
93
|
+
const res = await retry(async () => {
|
|
94
|
+
const messages: Message[] = [
|
|
95
|
+
new TextMessage({
|
|
96
|
+
role: Role.System,
|
|
97
|
+
content: insertionApiConfig.makeSystemPrompt(
|
|
98
|
+
textareaPurpose,
|
|
99
|
+
getContextString(documents, contextCategories),
|
|
100
|
+
),
|
|
101
|
+
}),
|
|
102
|
+
...insertionApiConfig.fewShotMessages,
|
|
103
|
+
new TextMessage({
|
|
104
|
+
role: Role.User,
|
|
105
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
106
|
+
}),
|
|
107
|
+
new TextMessage({
|
|
108
|
+
role: Role.User,
|
|
109
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
110
|
+
}),
|
|
111
|
+
new TextMessage({
|
|
112
|
+
role: Role.User,
|
|
113
|
+
content: `<InsertionPrompt>${insertionPrompt}</InsertionPrompt>`,
|
|
114
|
+
}),
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
return runtimeClientResponseToStringStream(
|
|
118
|
+
runtimeClient.generateCopilotResponse({
|
|
119
|
+
data: {
|
|
120
|
+
frontend: {
|
|
121
|
+
actions: [],
|
|
122
|
+
url: window.location.href,
|
|
123
|
+
},
|
|
124
|
+
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
125
|
+
metadata: {
|
|
126
|
+
requestType: CopilotRequestType.TextareaCompletion,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
properties: copilotApiConfig.properties,
|
|
130
|
+
signal: abortSignal,
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return res;
|
|
136
|
+
},
|
|
137
|
+
[insertionApiConfig, getContextString, contextCategories, textareaPurpose],
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const editingFunction = useCallback(
|
|
141
|
+
async (
|
|
142
|
+
editorState: EditingEditorState,
|
|
143
|
+
editingPrompt: string,
|
|
144
|
+
documents: DocumentPointer[],
|
|
145
|
+
abortSignal: AbortSignal,
|
|
146
|
+
) => {
|
|
147
|
+
const res = await retry(async () => {
|
|
148
|
+
const messages: Message[] = [
|
|
149
|
+
new TextMessage({
|
|
150
|
+
role: Role.System,
|
|
151
|
+
content: editingApiConfig.makeSystemPrompt(
|
|
152
|
+
textareaPurpose,
|
|
153
|
+
getContextString(documents, contextCategories),
|
|
154
|
+
),
|
|
155
|
+
}),
|
|
156
|
+
...editingApiConfig.fewShotMessages,
|
|
157
|
+
new TextMessage({
|
|
158
|
+
role: Role.User,
|
|
159
|
+
content: `<TextBeforeCursor>${editorState.textBeforeCursor}</TextBeforeCursor>`,
|
|
160
|
+
}),
|
|
161
|
+
new TextMessage({
|
|
162
|
+
role: Role.User,
|
|
163
|
+
content: `<TextToEdit>${editorState.selectedText}</TextToEdit>`,
|
|
164
|
+
}),
|
|
165
|
+
new TextMessage({
|
|
166
|
+
role: Role.User,
|
|
167
|
+
content: `<TextAfterCursor>${editorState.textAfterCursor}</TextAfterCursor>`,
|
|
168
|
+
}),
|
|
169
|
+
new TextMessage({
|
|
170
|
+
role: Role.User,
|
|
171
|
+
content: `<EditingPrompt>${editingPrompt}</EditingPrompt>`,
|
|
172
|
+
}),
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
return runtimeClientResponseToStringStream(
|
|
176
|
+
runtimeClient.generateCopilotResponse({
|
|
177
|
+
data: {
|
|
178
|
+
frontend: {
|
|
179
|
+
actions: [],
|
|
180
|
+
url: window.location.href,
|
|
181
|
+
},
|
|
182
|
+
messages: convertMessagesToGqlInput(filterAgentStateMessages(messages)),
|
|
183
|
+
metadata: {
|
|
184
|
+
requestType: CopilotRequestType.TextareaCompletion,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
properties: copilotApiConfig.properties,
|
|
188
|
+
signal: abortSignal,
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return res;
|
|
194
|
+
},
|
|
195
|
+
[editingApiConfig, getContextString, contextCategories, textareaPurpose],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const insertionOrEditingFunction = useCallback(
|
|
199
|
+
async (
|
|
200
|
+
editorState: EditingEditorState,
|
|
201
|
+
insertionPrompt: string,
|
|
202
|
+
documents: DocumentPointer[],
|
|
203
|
+
abortSignal: AbortSignal,
|
|
204
|
+
) => {
|
|
205
|
+
if (editorState.selectedText === "") {
|
|
206
|
+
return await insertionFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
207
|
+
} else {
|
|
208
|
+
return await editingFunction(editorState, insertionPrompt, documents, abortSignal);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
[insertionFunction, editingFunction],
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return insertionOrEditingFunction;
|
|
215
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ref, RefObject, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
// Updates the height of a <textarea> when the value changes.
|
|
4
|
+
const useAutosizeTextArea = (textAreaRef: RefObject<HTMLTextAreaElement | null>, value: string) => {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (textAreaRef.current !== null) {
|
|
7
|
+
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
|
|
8
|
+
textAreaRef.current.style.height = "0px";
|
|
9
|
+
const scrollHeight = textAreaRef.current.scrollHeight;
|
|
10
|
+
|
|
11
|
+
// We then set the height directly, outside of the render loop
|
|
12
|
+
// Trying to set this with state or a ref will product an incorrect value.
|
|
13
|
+
textAreaRef.current.style.height = scrollHeight + "px";
|
|
14
|
+
}
|
|
15
|
+
}, [textAreaRef, value]);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default useAutosizeTextArea;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type AsyncFunction<T extends any[]> = (...args: [...T, AbortSignal]) => Promise<void>;
|
|
2
|
+
|
|
3
|
+
export class Debouncer<T extends any[]> {
|
|
4
|
+
private timeoutId?: ReturnType<typeof setTimeout>;
|
|
5
|
+
private activeAbortController?: AbortController;
|
|
6
|
+
|
|
7
|
+
constructor(private wait: number) {}
|
|
8
|
+
|
|
9
|
+
debounce = async (func: AsyncFunction<T>, ...args: T) => {
|
|
10
|
+
// Abort the previous promise immediately
|
|
11
|
+
this.cancel();
|
|
12
|
+
|
|
13
|
+
this.timeoutId = setTimeout(async () => {
|
|
14
|
+
try {
|
|
15
|
+
this.activeAbortController = new AbortController();
|
|
16
|
+
|
|
17
|
+
// Pass the signal to the async function, assuming it supports it
|
|
18
|
+
await func(...args, this.activeAbortController.signal);
|
|
19
|
+
|
|
20
|
+
this.activeAbortController = undefined;
|
|
21
|
+
} catch (error) {}
|
|
22
|
+
}, this.wait);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
cancel = () => {
|
|
26
|
+
if (this.activeAbortController) {
|
|
27
|
+
this.activeAbortController.abort();
|
|
28
|
+
this.activeAbortController = undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.timeoutId !== undefined) {
|
|
32
|
+
clearTimeout(this.timeoutId);
|
|
33
|
+
this.timeoutId = undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BaseEditor, Descendant, Element } from "slate";
|
|
2
|
+
import { HistoryEditor } from "slate-history";
|
|
3
|
+
import { ReactEditor } from "slate-react";
|
|
4
|
+
import { SuggestionAwareText } from "../types/base/custom-editor";
|
|
5
|
+
|
|
6
|
+
function nodeChildrenToTextComponents(
|
|
7
|
+
editor: BaseEditor & ReactEditor & HistoryEditor,
|
|
8
|
+
nodes: Descendant[],
|
|
9
|
+
): SuggestionAwareText[] {
|
|
10
|
+
// find inlineable elements
|
|
11
|
+
const indeciesOfInlineElements = new Set(
|
|
12
|
+
nodes
|
|
13
|
+
.map((node, index) => {
|
|
14
|
+
if (Element.isElement(node) && editor.isInline(node)) {
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
17
|
+
return -1;
|
|
18
|
+
})
|
|
19
|
+
.filter((index) => index !== -1),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// ignorable elements = inline elements,
|
|
23
|
+
// or neighbors of inline elements that are {text: ""}
|
|
24
|
+
const nonIgnorableItems = nodes.filter((node, index) => {
|
|
25
|
+
const isInline = indeciesOfInlineElements.has(index);
|
|
26
|
+
if (isInline) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isNeighbourOfInline =
|
|
31
|
+
indeciesOfInlineElements.has(index - 1) || indeciesOfInlineElements.has(index + 1);
|
|
32
|
+
if (isNeighbourOfInline) {
|
|
33
|
+
return (node as any).text !== "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return nonIgnorableItems
|
|
40
|
+
.map((node) => {
|
|
41
|
+
if (Element.isElement(node)) {
|
|
42
|
+
switch (node.type) {
|
|
43
|
+
case "paragraph":
|
|
44
|
+
return nodeChildrenToTextComponents(editor, node.children);
|
|
45
|
+
case "suggestion":
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
return [node];
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.reduce((acc, val) => acc.concat(val), []);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const editorToText = (editor: BaseEditor & ReactEditor & HistoryEditor) => {
|
|
56
|
+
const flattened = nodeChildrenToTextComponents(editor, editor.children);
|
|
57
|
+
|
|
58
|
+
const text = flattened.map((textComponent) => textComponent.text).join("\n");
|
|
59
|
+
|
|
60
|
+
return text;
|
|
61
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from "slate";
|
|
2
|
+
import { EditorAutocompleteState } from "../types/base/editor-autocomplete-state";
|
|
3
|
+
|
|
4
|
+
export interface EditorTextState {
|
|
5
|
+
selection: BaseRange;
|
|
6
|
+
|
|
7
|
+
textBeforeCursor: string;
|
|
8
|
+
selectedText: string;
|
|
9
|
+
textAfterCursor: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {
|
|
13
|
+
const { selection } = editor;
|
|
14
|
+
if (!selection || !Range.isCollapsed(selection)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cursorPoint = selection.anchor;
|
|
19
|
+
|
|
20
|
+
// Create two ranges: one before the anchor and one after
|
|
21
|
+
const beforeRange: Range = {
|
|
22
|
+
anchor: Editor.start(editor, []),
|
|
23
|
+
focus: cursorPoint,
|
|
24
|
+
};
|
|
25
|
+
const afterRange: Range = {
|
|
26
|
+
anchor: cursorPoint,
|
|
27
|
+
focus: Editor.end(editor, []),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Extract text for these ranges
|
|
31
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
32
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
cursorPoint: cursorPoint,
|
|
36
|
+
textBeforeCursor: before,
|
|
37
|
+
textAfterCursor: after,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getTextAroundSelection(editor: Editor): EditorTextState | null {
|
|
42
|
+
const { selection } = editor;
|
|
43
|
+
if (!selection) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
48
|
+
|
|
49
|
+
// Create two ranges: one before the anchor and one after
|
|
50
|
+
const beforeRange: Range = {
|
|
51
|
+
anchor: Editor.start(editor, []),
|
|
52
|
+
focus: wellOrderedSelection.anchor,
|
|
53
|
+
};
|
|
54
|
+
const afterRange: Range = {
|
|
55
|
+
anchor: wellOrderedSelection.focus,
|
|
56
|
+
focus: Editor.end(editor, []),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Extract text for these ranges
|
|
60
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
61
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
62
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
selection: wellOrderedSelection,
|
|
66
|
+
textBeforeCursor: before,
|
|
67
|
+
selectedText,
|
|
68
|
+
textAfterCursor: after,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getFullEditorTextWithNewlines(editor: Editor): string {
|
|
73
|
+
const fullDocumentRange: Range = {
|
|
74
|
+
anchor: Editor.start(editor, []),
|
|
75
|
+
focus: Editor.end(editor, []),
|
|
76
|
+
};
|
|
77
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Helper function to extract text with newlines
|
|
81
|
+
export function extractTextWithNewlines(editor: Editor, range: Range): string {
|
|
82
|
+
const voids = false;
|
|
83
|
+
const [start, end] = Range.edges(range);
|
|
84
|
+
let text = "";
|
|
85
|
+
let lastBlock: Node | null = null;
|
|
86
|
+
|
|
87
|
+
for (const [node, path] of Editor.nodes(editor, {
|
|
88
|
+
at: range,
|
|
89
|
+
match: Text.isText,
|
|
90
|
+
voids,
|
|
91
|
+
})) {
|
|
92
|
+
let t = node.text;
|
|
93
|
+
|
|
94
|
+
// Determine the parent block of the current text node
|
|
95
|
+
const [block] = Editor.above(editor, {
|
|
96
|
+
at: path,
|
|
97
|
+
match: (n) => Element.isElement(n) && n.type === "paragraph",
|
|
98
|
+
}) || [null];
|
|
99
|
+
|
|
100
|
+
// If we encounter a new block, prepend a newline
|
|
101
|
+
if (lastBlock !== block && block) {
|
|
102
|
+
// check that lastBlock is not null to avoid adding a newline at the beginning
|
|
103
|
+
if (lastBlock) {
|
|
104
|
+
text += "\n";
|
|
105
|
+
}
|
|
106
|
+
lastBlock = block;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Path.equals(path, end.path)) {
|
|
110
|
+
t = t.slice(0, end.offset);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (Path.equals(path, start.path)) {
|
|
114
|
+
t = t.slice(start.offset);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
text += t;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return text;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function wellOrderedRange(range: BaseRange): BaseRange {
|
|
124
|
+
const { anchor, focus } = range;
|
|
125
|
+
// if anchor is before focus, return range as is
|
|
126
|
+
if (Point.isBefore(anchor, focus)) {
|
|
127
|
+
return range;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// if focus is before anchor, return range with anchor and focus swapped
|
|
131
|
+
return {
|
|
132
|
+
anchor: focus,
|
|
133
|
+
focus: anchor,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function retry<T>(
|
|
2
|
+
fn: () => Promise<T>,
|
|
3
|
+
retriesLeft: number = 2,
|
|
4
|
+
interval: number = 200,
|
|
5
|
+
backoff: number = 1.5,
|
|
6
|
+
): Promise<T> {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
fn()
|
|
9
|
+
.then(resolve)
|
|
10
|
+
.catch((error) => {
|
|
11
|
+
if (retriesLeft === 1) {
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
retry(fn, retriesLeft - 1, interval * backoff, backoff)
|
|
18
|
+
.then(resolve)
|
|
19
|
+
.catch(reject);
|
|
20
|
+
}, interval);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasePoint, Transforms } from "slate";
|
|
2
|
+
import { CustomEditor } from "../../types/base/custom-editor";
|
|
3
|
+
|
|
4
|
+
export function addAutocompletionsToEditor(
|
|
5
|
+
editor: CustomEditor,
|
|
6
|
+
newSuggestion: string,
|
|
7
|
+
point: BasePoint,
|
|
8
|
+
) {
|
|
9
|
+
const editorPosition = editor.selection;
|
|
10
|
+
|
|
11
|
+
Transforms.insertNodes(
|
|
12
|
+
editor,
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
type: "suggestion",
|
|
16
|
+
inline: true,
|
|
17
|
+
content: newSuggestion,
|
|
18
|
+
children: [{ text: "" }],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
{
|
|
22
|
+
at: point,
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// restore cursor position
|
|
27
|
+
if (editorPosition) {
|
|
28
|
+
editor.selection = editorPosition;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Element, Node, Path, Transforms } from "slate";
|
|
2
|
+
import { CustomEditor } from "../../types/base/custom-editor";
|
|
3
|
+
|
|
4
|
+
export function clearAutocompletionsFromEditor(editor: CustomEditor) {
|
|
5
|
+
// clear previous suggestion
|
|
6
|
+
const paths: Path[] = [];
|
|
7
|
+
for (const [node, path] of Node.nodes(editor)) {
|
|
8
|
+
if (Element.isElement(node) && node.type === "suggestion") {
|
|
9
|
+
paths.push(path);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const path of paths) {
|
|
13
|
+
try {
|
|
14
|
+
Transforms.removeNodes(editor, { at: path });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.log("CopilotTextarea.clearAutocompletionsFromEditor: error removing node", e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Editor, Transforms } from "slate";
|
|
2
|
+
|
|
3
|
+
export function replaceEditorText(editor: Editor, newText: string) {
|
|
4
|
+
// clear all previous text
|
|
5
|
+
Transforms.delete(editor, {
|
|
6
|
+
at: {
|
|
7
|
+
anchor: Editor.start(editor, []),
|
|
8
|
+
focus: Editor.end(editor, []),
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// insert new text
|
|
13
|
+
if (newText && newText !== "") {
|
|
14
|
+
// don't insert empty text - results in strange visual behavior
|
|
15
|
+
Transforms.insertNodes(
|
|
16
|
+
editor,
|
|
17
|
+
[
|
|
18
|
+
{
|
|
19
|
+
type: "paragraph",
|
|
20
|
+
children: [{ text: newText }],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
{
|
|
24
|
+
at: [0],
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|