@copilotkit/react-textarea 0.26.0-alpha.3 → 0.26.0-alpha.5
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/.turbo/turbo-build.log +184 -184
- package/CHANGELOG.md +22 -0
- package/dist/chunk-224UKA7C.mjs +33 -0
- package/dist/chunk-224UKA7C.mjs.map +1 -0
- package/dist/chunk-2C7O2EVM.mjs +27 -0
- package/dist/chunk-2C7O2EVM.mjs.map +1 -0
- package/dist/chunk-2QDCE7PD.mjs +29 -0
- package/dist/chunk-2QDCE7PD.mjs.map +1 -0
- package/dist/chunk-3PQ7GSFE.mjs +17 -0
- package/dist/chunk-3PQ7GSFE.mjs.map +1 -0
- package/dist/chunk-47L4PLG4.mjs +45 -0
- package/dist/chunk-47L4PLG4.mjs.map +1 -0
- package/dist/chunk-4NHVQZ67.mjs +107 -0
- package/dist/chunk-4NHVQZ67.mjs.map +1 -0
- package/dist/chunk-5FO6ISW4.mjs +3 -0
- package/dist/chunk-5FO6ISW4.mjs.map +1 -0
- package/dist/chunk-5UNJXFUO.mjs +29 -0
- package/dist/chunk-5UNJXFUO.mjs.map +1 -0
- package/dist/chunk-72P3KOHZ.mjs +91 -0
- package/dist/chunk-72P3KOHZ.mjs.map +1 -0
- package/dist/chunk-7LNP2LEL.mjs +217 -0
- package/dist/chunk-7LNP2LEL.mjs.map +1 -0
- package/dist/chunk-7LSRNPNI.mjs +59 -0
- package/dist/chunk-7LSRNPNI.mjs.map +1 -0
- package/dist/chunk-7SUZ6CXM.mjs +47 -0
- package/dist/chunk-7SUZ6CXM.mjs.map +1 -0
- package/dist/chunk-DE5K76I2.mjs +3 -0
- package/dist/chunk-DE5K76I2.mjs.map +1 -0
- package/dist/chunk-DRV2FOHZ.mjs +65 -0
- package/dist/chunk-DRV2FOHZ.mjs.map +1 -0
- package/dist/chunk-ECR45NSD.mjs +101 -0
- package/dist/chunk-ECR45NSD.mjs.map +1 -0
- package/dist/chunk-ELEY7HWW.mjs +202 -0
- package/dist/chunk-ELEY7HWW.mjs.map +1 -0
- package/dist/chunk-EPBVNDKE.mjs +46 -0
- package/dist/chunk-EPBVNDKE.mjs.map +1 -0
- package/dist/chunk-FJNUPSQK.mjs +72 -0
- package/dist/chunk-FJNUPSQK.mjs.map +1 -0
- package/dist/chunk-FP2EKU3L.mjs +28 -0
- package/dist/chunk-FP2EKU3L.mjs.map +1 -0
- package/dist/chunk-FRIYJQCI.mjs +99 -0
- package/dist/chunk-FRIYJQCI.mjs.map +1 -0
- package/dist/chunk-GQN2HYFJ.mjs +22 -0
- package/dist/chunk-GQN2HYFJ.mjs.map +1 -0
- package/dist/chunk-H4VKQGVU.mjs +3 -0
- package/dist/chunk-H4VKQGVU.mjs.map +1 -0
- package/dist/chunk-IU3WTXLQ.mjs +3 -0
- package/dist/chunk-IU3WTXLQ.mjs.map +1 -0
- package/dist/chunk-JJLQVT7S.mjs +10 -0
- package/dist/chunk-JJLQVT7S.mjs.map +1 -0
- package/dist/chunk-K5LNB36H.mjs +80 -0
- package/dist/chunk-K5LNB36H.mjs.map +1 -0
- package/dist/chunk-KDVMG3XF.mjs +63 -0
- package/dist/chunk-KDVMG3XF.mjs.map +1 -0
- package/dist/chunk-KFQZHRPJ.mjs +19 -0
- package/dist/chunk-KFQZHRPJ.mjs.map +1 -0
- package/dist/chunk-KNBNKEXR.mjs +27 -0
- package/dist/chunk-KNBNKEXR.mjs.map +1 -0
- package/dist/chunk-KNQIEOFP.mjs +18 -0
- package/dist/chunk-KNQIEOFP.mjs.map +1 -0
- package/dist/chunk-L7VVZH4Q.mjs +3 -0
- package/dist/chunk-L7VVZH4Q.mjs.map +1 -0
- package/dist/chunk-M2DR4KVB.mjs +33 -0
- package/dist/chunk-M2DR4KVB.mjs.map +1 -0
- package/dist/chunk-MMKBFUFE.mjs +46 -0
- package/dist/chunk-MMKBFUFE.mjs.map +1 -0
- package/dist/chunk-MMVDU6DF.mjs +3 -0
- package/dist/chunk-MMVDU6DF.mjs.map +1 -0
- package/dist/chunk-MRXNTQOX.mjs +55 -0
- package/dist/chunk-MRXNTQOX.mjs.map +1 -0
- package/dist/chunk-MTDBPK5D.mjs +53 -0
- package/dist/chunk-MTDBPK5D.mjs.map +1 -0
- package/dist/chunk-NTLVQENP.mjs +19 -0
- package/dist/chunk-NTLVQENP.mjs.map +1 -0
- package/dist/chunk-OHO4G6DR.mjs +19 -0
- package/dist/chunk-OHO4G6DR.mjs.map +1 -0
- package/dist/chunk-P4QVFRLY.mjs +103 -0
- package/dist/chunk-P4QVFRLY.mjs.map +1 -0
- package/dist/chunk-PTZVE6NC.mjs +94 -0
- package/dist/chunk-PTZVE6NC.mjs.map +1 -0
- package/dist/chunk-QDFAIRQF.mjs +45 -0
- package/dist/chunk-QDFAIRQF.mjs.map +1 -0
- package/dist/chunk-RBR32FWA.mjs +74 -0
- package/dist/chunk-RBR32FWA.mjs.map +1 -0
- package/dist/chunk-T6MTDQZ7.mjs +45 -0
- package/dist/chunk-T6MTDQZ7.mjs.map +1 -0
- package/dist/chunk-VPEH6V7T.mjs +83 -0
- package/dist/chunk-VPEH6V7T.mjs.map +1 -0
- package/dist/chunk-WADHCMPK.mjs +3 -0
- package/dist/chunk-WADHCMPK.mjs.map +1 -0
- package/dist/chunk-WFTAAA7R.mjs +44 -0
- package/dist/chunk-WFTAAA7R.mjs.map +1 -0
- package/dist/chunk-WJHSY5T6.mjs +3 -0
- package/dist/chunk-WJHSY5T6.mjs.map +1 -0
- package/dist/chunk-WTASPE2W.mjs +105 -0
- package/dist/chunk-WTASPE2W.mjs.map +1 -0
- package/dist/chunk-XV7MLLXQ.mjs +18 -0
- package/dist/chunk-XV7MLLXQ.mjs.map +1 -0
- package/dist/chunk-Y473E2ZQ.mjs +112 -0
- package/dist/chunk-Y473E2ZQ.mjs.map +1 -0
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs +35 -1745
- package/dist/components/base-copilot-textarea/base-copilot-textarea.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-element.mjs +3 -51
- package/dist/components/base-copilot-textarea/render-element.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/render-placeholder.mjs +3 -49
- package/dist/components/base-copilot-textarea/render-placeholder.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs +4 -86
- package/dist/components/base-copilot-textarea/track-cursor-moved-since-last-text-change.mjs.map +1 -1
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs +3 -57
- package/dist/components/base-copilot-textarea/use-add-branding-css.mjs.map +1 -1
- package/dist/components/copilot-textarea/copilot-textarea.mjs +47 -2202
- package/dist/components/copilot-textarea/copilot-textarea.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs +3 -17
- package/dist/components/hovering-toolbar/hovering-editor-provider.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs +3 -137
- package/dist/components/hovering-toolbar/hovering-toolbar-components.mjs.map +1 -1
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs +18 -875
- package/dist/components/hovering-toolbar/hovering-toolbar.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs +12 -558
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs +13 -581
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs +5 -102
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/included-files-preview.mjs.map +1 -1
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs +14 -581
- package/dist/components/hovering-toolbar/text-insertion-prompt-box/index.mjs.map +1 -1
- package/dist/components/index.mjs +48 -2203
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/manual-ui/chip-with-icon.mjs +6 -5
- package/dist/components/manual-ui/chip-with-icon.mjs.map +1 -1
- package/dist/components/source-search-box/source-search-box.mjs +6 -211
- package/dist/components/source-search-box/source-search-box.mjs.map +1 -1
- package/dist/components/ui/button.mjs +4 -85
- package/dist/components/ui/button.mjs.map +1 -1
- package/dist/components/ui/card.mjs +7 -53
- package/dist/components/ui/card.mjs.map +1 -1
- package/dist/components/ui/command.mjs +5 -244
- package/dist/components/ui/command.mjs.map +1 -1
- package/dist/components/ui/dialog.mjs +4 -144
- package/dist/components/ui/dialog.mjs.map +1 -1
- package/dist/components/ui/label.mjs +4 -60
- package/dist/components/ui/label.mjs.map +1 -1
- package/dist/components/ui/separator.mjs +8 -50
- package/dist/components/ui/separator.mjs.map +1 -1
- package/dist/components/ui/textarea.mjs +7 -48
- package/dist/components/ui/textarea.mjs.map +1 -1
- package/dist/context/index.mjs +2 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs +6 -158
- package/dist/hooks/base-copilot-textarea-implementation/use-autosuggestions.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs +4 -168
- package/dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map +1 -1
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs +5 -148
- package/dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map +1 -1
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs +14 -147
- package/dist/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.mjs.map +1 -1
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs +14 -193
- package/dist/hooks/make-autosuggestions-function/use-make-standard-insertion-function.mjs.map +1 -1
- package/dist/hooks/misc/use-autosize-textarea.mjs +3 -15
- package/dist/hooks/misc/use-autosize-textarea.mjs.map +1 -1
- package/dist/index.mjs +50 -2206
- package/dist/index.mjs.map +1 -1
- package/dist/lib/debouncer.mjs +3 -51
- package/dist/lib/debouncer.mjs.map +1 -1
- package/dist/lib/editor-to-text.mjs +3 -43
- package/dist/lib/editor-to-text.mjs.map +1 -1
- package/dist/lib/get-text-around-cursor.mjs +3 -102
- package/dist/lib/get-text-around-cursor.mjs.map +1 -1
- package/dist/lib/retry.mjs +3 -17
- package/dist/lib/retry.mjs.map +1 -1
- package/dist/lib/slatejs-edits/add-autocompletions.mjs +3 -25
- package/dist/lib/slatejs-edits/add-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs +3 -20
- package/dist/lib/slatejs-edits/clear-autocompletions.mjs.map +1 -1
- package/dist/lib/slatejs-edits/replace-text.mjs +3 -27
- package/dist/lib/slatejs-edits/replace-text.mjs.map +1 -1
- package/dist/lib/slatejs-edits/with-partial-history.mjs +3 -106
- package/dist/lib/slatejs-edits/with-partial-history.mjs.map +1 -1
- package/dist/lib/stream-promise-flatten.mjs +3 -47
- package/dist/lib/stream-promise-flatten.mjs.map +1 -1
- package/dist/lib/utils.mjs +3 -71
- package/dist/lib/utils.mjs.map +1 -1
- package/dist/lib/utils.test.mjs +1 -0
- package/dist/lib/utils.test.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs +2 -0
- package/dist/types/autosuggestions-config/autosuggestions-config-user-specified.mjs.map +1 -1
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs +8 -265
- package/dist/types/autosuggestions-config/autosuggestions-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/editing-api-config.mjs +3 -81
- package/dist/types/autosuggestions-config/editing-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/index.mjs +10 -327
- package/dist/types/autosuggestions-config/index.mjs.map +1 -1
- package/dist/types/autosuggestions-config/insertions-api-config.mjs +3 -75
- package/dist/types/autosuggestions-config/insertions-api-config.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs +3 -83
- package/dist/types/autosuggestions-config/subtypes/chatlike-api-endpoint.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/make-system-prompt.mjs.map +1 -1
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs +2 -0
- package/dist/types/autosuggestions-config/subtypes/minimal-chat-gpt-message.mjs.map +1 -1
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs +3 -64
- package/dist/types/autosuggestions-config/suggestions-api-config.mjs.map +1 -1
- package/dist/types/base/autosuggestion-state.mjs +2 -0
- package/dist/types/base/autosuggestion-state.mjs.map +1 -1
- package/dist/types/base/autosuggestions-bare-function.mjs +2 -0
- package/dist/types/base/autosuggestions-bare-function.mjs.map +1 -1
- package/dist/types/base/base-autosuggestions-config.mjs +3 -26
- package/dist/types/base/base-autosuggestions-config.mjs.map +1 -1
- package/dist/types/base/base-copilot-textarea-props.mjs +2 -0
- package/dist/types/base/base-copilot-textarea-props.mjs.map +1 -1
- package/dist/types/base/custom-editor.mjs +2 -0
- package/dist/types/base/custom-editor.mjs.map +1 -1
- package/dist/types/base/editor-autocomplete-state.mjs +4 -17
- package/dist/types/base/editor-autocomplete-state.mjs.map +1 -1
- package/dist/types/base/index.mjs +4 -26
- package/dist/types/base/index.mjs.map +1 -1
- package/dist/types/html-copilot-textarea-element.mjs +2 -0
- package/dist/types/html-copilot-textarea-element.mjs.map +1 -1
- package/dist/types/index.mjs +12 -328
- package/dist/types/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"names":["_a","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAA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AkC,KAAK;AACvC,gDAAgC,KAAK;AACrC,iBAAAA,MAAA,MAAM,cAAN,gBAAAA,IAAA,YAAkB;AAAA,cACpB;AAAA,cACA,WAAW;AAAA,eACP;AAAA,UACN;AAAA;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAaA,SAAS,+BACP,aACwC;AACxC,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,eAAe;AAAA,MACb,OAAO;AAAA,MACP,MAAM;AAAA,IACR;AAAA,EACF;AACF","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Descendant, Editor } from \"slate\";\nimport { Editable, Slate } from \"slate-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { useAutosuggestions } from \"../../hooks/base-copilot-textarea-implementation/use-autosuggestions\";\nimport { useCopilotTextareaEditor } from \"../../hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor\";\nimport { usePopulateCopilotTextareaRef } from \"../../hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref\";\nimport {\n getFullEditorTextWithNewlines,\n getTextAroundCollapsedCursor,\n} from \"../../lib/get-text-around-cursor\";\nimport { addAutocompletionsToEditor } from \"../../lib/slatejs-edits/add-autocompletions\";\nimport { clearAutocompletionsFromEditor } from \"../../lib/slatejs-edits/clear-autocompletions\";\nimport { replaceEditorText } from \"../../lib/slatejs-edits/replace-text\";\nimport { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from \"../../types/base\";\nimport { AutosuggestionState } from \"../../types/base/autosuggestion-state\";\nimport { BaseCopilotTextareaProps } from \"../../types/base/base-copilot-textarea-props\";\nimport \"./base-copilot-textarea.css\";\nimport { HoveringToolbar } from \"../hovering-toolbar/hovering-toolbar\";\nimport { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\nimport {\n HoveringEditorProvider,\n useHoveringEditorContext,\n} from \"../hovering-toolbar/hovering-editor-provider\";\nimport { EditorAutocompleteState } from \"../../types/base/editor-autocomplete-state\";\nimport { TrackerTextEditedSinceLastCursorMovement } from \"./track-cursor-moved-since-last-text-change\";\n\n/**\n * Purpose: to be used as the `ref` type for `CopilotTextarea` and `BaseCopilotTextarea`.\n *\n * This interface extends `HTMLElement`, and is the subset of `HTMLTextAreaElement` that \"actually matters\".\n * It provides the core functionality that consumers of `HTMLTextAreaElement` need 99.9% of the time:\n * - `value`: the current value of the textarea\n * - `focus`: make the textarea focused\n * - `blur`: make the textarea unfocused\n */\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n /**\n * The current value of the textarea.\n */\n value: string;\n\n /**\n * focus on the textarea\n */\n focus: () => void;\n\n /**\n * unfocus the textarea.\n *\n * Called `blur` for syntactic compatibility with `HTMLTextAreaElement`.\n */\n blur: () => void;\n}\n\n/**\n * Not intended for direct use. Use CopilotTextarea instead.\n *\n * The `BaseCopilotTextarea` includes the basic UX component,\n * without the business logic / AI logic that makes the content useful and coherent.\n *\n * It is useful if you want to build your own backend, with fully custom business logic\n * for figuring out which contnet to fill in.\n */\nexport const BaseCopilotTextarea = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {\n return (\n <HoveringEditorProvider>\n <BaseCopilotTextareaWithHoveringContext {...props} ref={ref} />\n </HoveringEditorProvider>\n );\n },\n);\n\n/**\n * Not intended for direct use. Use `CopilotTextarea` instead.\n *\n * This is the private core of the `BaseCopilotTextarea` component.\n * For practical purposes the implementation is cleaner assuming containment in a `HoveringEditorProviderContext`.\n *\n * Therefore we separate the core logic into this component,\n * and wrap it in a `HoveringEditorProviderContext` in `BaseCopilotTextarea`.\n */\nconst BaseCopilotTextareaWithHoveringContext = React.forwardRef(\n (props: BaseCopilotTextareaProps, ref: React.Ref<HTMLCopilotTextAreaElement>): JSX.Element => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.baseAutosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] = useState(valueOnInitialRender);\n const [cursorMovedSinceLastTextChange, setCursorMovedSinceLastTextChange] = useState(false);\n\n // // When the editor text changes, we want to reset the `textEditedSinceLastCursorMovement` state.\n // useEffect(() => {\n // setCursorMovedSinceLastTextChange(false);\n // }, [lastKnownFullEditorText]);\n\n const initialValue: Descendant[] = useMemo(() => {\n return [\n {\n type: \"paragraph\",\n children: [{ text: valueOnInitialRender }],\n },\n ];\n }, [valueOnInitialRender]);\n\n const editor = useCopilotTextareaEditor();\n\n const { isDisplayed: hoveringEditorIsDisplayed, setIsDisplayed: setHoveringEditorIsDisplayed } =\n useHoveringEditorContext();\n\n const insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor],\n );\n\n const shouldDisableAutosuggestions =\n // textarea is manually disabled:\n autosuggestionsConfig.disabled ||\n // hovering editor is displayed:\n hoveringEditorIsDisplayed ||\n // the cursor has moved since the last text change AND we are configured to disable autosuggestions in this case:\n (cursorMovedSinceLastTextChange &&\n autosuggestionsConfig.temporarilyDisableWhenMovingCursorWithoutChangingText);\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.shouldAcceptAutosuggestionOnKeyPress,\n autosuggestionsConfig.apiConfig.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n shouldDisableAutosuggestions,\n );\n\n const onKeyDownHandlerForHoveringEditor = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress(event)) {\n event.preventDefault();\n setHoveringEditorIsDisplayed(!hoveringEditorIsDisplayed);\n }\n },\n [\n hoveringEditorIsDisplayed,\n setHoveringEditorIsDisplayed,\n autosuggestionsConfig.shouldToggleHoveringEditorOnKeyPress,\n ],\n );\n\n // sync autosuggestions state with the editor\n useEffect(() => {\n clearAutocompletionsFromEditor(editor);\n if (currentAutocompleteSuggestion) {\n addAutocompletionsToEditor(\n editor,\n currentAutocompleteSuggestion.text,\n currentAutocompleteSuggestion.point,\n );\n }\n }, [currentAutocompleteSuggestion]);\n\n const suggestionStyleAugmented: React.CSSProperties = useMemo(() => {\n return {\n fontStyle: \"italic\",\n color: \"gray\",\n ...props.suggestionsStyle,\n };\n }, [props.suggestionsStyle]);\n\n const renderElementMemoized = useMemo(() => {\n return makeRenderElementFunction(suggestionStyleAugmented);\n }, [suggestionStyleAugmented]);\n\n const renderPlaceholderMemoized = useMemo(() => {\n // For some reason slateJS specifies a top value of 0, which makes for strange styling. We override this here.\n const placeholderStyleSlatejsOverrides: React.CSSProperties = {\n top: undefined,\n };\n\n const placeholderStyleAugmented: React.CSSProperties = {\n ...placeholderStyleSlatejsOverrides,\n ...props.placeholderStyle,\n };\n\n return makeRenderPlaceholderFunction(placeholderStyleAugmented);\n }, [props.placeholderStyle]);\n\n // update the editor text, but only when the value changes from outside the component\n useEffect(() => {\n if (props.value === lastKnownFullEditorText) {\n return;\n }\n\n setLastKnownFullEditorText(props.value ?? \"\");\n replaceEditorText(editor, props.value ?? \"\");\n }, [props.value]);\n\n // separate into TextareaHTMLAttributes<HTMLDivElement> and CopilotTextareaProps\n const {\n placeholderStyle,\n value,\n hoverMenuClassname,\n onValueChange,\n baseAutosuggestionsConfig: autosuggestionsConfigFromProps,\n className,\n onChange,\n onKeyDown,\n disableBranding,\n ...propsToForward\n } = props;\n\n useAddBrandingCss(suggestionStyleAugmented, disableBranding);\n usePopulateCopilotTextareaRef(editor, ref);\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = disableBranding ? \"no-branding\" : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(defaultTailwindClassName, className ?? \"\");\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCollapsedCursor(editor);\n\n const fullEditorText = newEditorState\n ? newEditorState.textBeforeCursor + newEditorState.textAfterCursor\n : getFullEditorTextWithNewlines(editor); // we don't double-parse the editor. When `newEditorState` is null, we didn't parse the editor yet.\n\n setLastKnownFullEditorText((prev) => {\n if (prev !== fullEditorText) {\n setCursorMovedSinceLastTextChange(false);\n }\n return fullEditorText;\n });\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <TrackerTextEditedSinceLastCursorMovement\n setCursorMovedSinceLastTextChange={setCursorMovedSinceLastTextChange}\n />\n <HoveringToolbar\n apiConfig={autosuggestionsConfig.apiConfig}\n contextCategories={autosuggestionsConfig.contextCategories}\n hoverMenuClassname={hoverMenuClassname}\n />\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\n onKeyDownHandlerForHoveringEditor(event); // forward the event for internal use\n onKeyDownHandlerForAutocomplete(event); // forward the event for internal use\n props.onKeyDown?.(event); // forward the event for external use\n }}\n className={moddedClassName}\n {...propsToForward}\n />\n </Slate>\n );\n },\n);\n\n// Consumers of <textarea> expect a `onChange: (React.ChangeEvent<HTMLTextAreaElement>) => void` event handler to be passed in.\n// This is *extremely* common, and we want to support it.\n//\n// We can't support the full functionality, but in 99% of cases, the consumer only cares about the `event.target.value` property --\n// that's how they get the new value of the textarea.\n//\n// So, the tradeoff we are making is minimizing compiler complaint, with a small chance of runtime error.\n// The alternative would be defining a different onChange entrypoint (we actually do have that in `onValueChange`),\n// And starting to explain subtleties to users the moment they try to use the component for the first time for very basic functionality.\n//\n// If this proves problematic, we can always revisit this decision.\nfunction makeSemiFakeReactTextAreaEvent(\n currentText: string,\n): React.ChangeEvent<HTMLTextAreaElement> {\n return {\n target: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n currentTarget: {\n value: currentText,\n type: \"copilot-textarea\",\n },\n } as React.ChangeEvent<HTMLTextAreaElement>;\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/components/base-copilot-textarea/use-add-branding-css.tsx
|
|
4
|
+
function useAddBrandingCss(suggestionStyleAugmented, disableBranding) {
|
|
5
|
+
const cssSelector = ".copilot-textarea.with-branding";
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (disableBranding) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const styleEl = document.createElement("style");
|
|
11
|
+
styleEl.id = "dynamic-styles";
|
|
12
|
+
let dynamicStyles = Object.entries(suggestionStyleAugmented).map(([key, value]) => {
|
|
13
|
+
const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
14
|
+
return `${kebabCaseKey}: ${value};`;
|
|
15
|
+
}).join(" ");
|
|
16
|
+
dynamicStyles += `font-style: normal; font-size: x-small;`;
|
|
17
|
+
dynamicStyles += `content: "CopilotKit";`;
|
|
18
|
+
dynamicStyles += `bottom: 6px;`;
|
|
19
|
+
dynamicStyles += `right: 6px;`;
|
|
20
|
+
dynamicStyles += `pointer-events: none;`;
|
|
21
|
+
dynamicStyles += `font-weight: 200;`;
|
|
22
|
+
dynamicStyles += `padding: 0;`;
|
|
23
|
+
dynamicStyles += `margin: 0;`;
|
|
24
|
+
dynamicStyles += `border: 0;`;
|
|
25
|
+
dynamicStyles += `line-height: 1;`;
|
|
26
|
+
dynamicStyles += `position: absolute;`;
|
|
27
|
+
styleEl.innerHTML = `
|
|
28
|
+
${cssSelector}::after {
|
|
29
|
+
${dynamicStyles}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
document.head.appendChild(styleEl);
|
|
33
|
+
const textarea = document.querySelector(cssSelector);
|
|
34
|
+
const handleScroll = () => {
|
|
35
|
+
const styleEl2 = document.getElementById("dynamic-styles");
|
|
36
|
+
if (styleEl2 && textarea) {
|
|
37
|
+
const offsetFromBottom = -textarea.scrollTop + 6;
|
|
38
|
+
const offsetFromRight = -textarea.scrollLeft + 6;
|
|
39
|
+
styleEl2.innerHTML = `
|
|
40
|
+
${cssSelector}::after {
|
|
41
|
+
${dynamicStyles}
|
|
42
|
+
bottom: ${offsetFromBottom}px;
|
|
43
|
+
right: ${offsetFromRight}px;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
textarea == null ? void 0 : textarea.addEventListener("scroll", handleScroll);
|
|
49
|
+
return () => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = document.getElementById("dynamic-styles")) == null ? void 0 : _a.remove();
|
|
52
|
+
textarea == null ? void 0 : textarea.removeEventListener("scroll", handleScroll);
|
|
53
|
+
};
|
|
54
|
+
}, [disableBranding, suggestionStyleAugmented]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { useAddBrandingCss };
|
|
58
|
+
//# sourceMappingURL=out.js.map
|
|
59
|
+
//# sourceMappingURL=chunk-7LSRNPNI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/base-copilot-textarea/use-add-branding-css.tsx"],"names":["styleEl"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,SAAS,kBACd,0BACA,iBACA;AACA,QAAM,cAAc;AACpB,YAAU,MAAM;AACd,QAAI,iBAAiB;AACnB;AAAA,IACF;AAIA,UAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,YAAQ,KAAK;AAGb,QAAI,gBAAgB,OAAO,QAAQ,wBAAwB,EACxD,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,YAAM,eAAe,IAAI,QAAQ,gCAAgC,OAAO,EAAE,YAAY;AACtF,aAAO,GAAG,iBAAiB;AAAA,IAC7B,CAAC,EACA,KAAK,GAAG;AAGX,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AACjB,qBAAiB;AAGjB,YAAQ,YAAY;AAAA,QAChB;AAAA,UACE;AAAA;AAAA;AAIN,aAAS,KAAK,YAAY,OAAO;AAIjC,UAAM,WAAW,SAAS,cAAc,WAAW;AACnD,UAAM,eAAe,MAAM;AACzB,YAAMA,WAAU,SAAS,eAAe,gBAAgB;AACxD,UAAIA,YAAW,UAAU;AACvB,cAAM,mBAAmB,CAAC,SAAS,YAAY;AAC/C,cAAM,kBAAkB,CAAC,SAAS,aAAa;AAC/C,QAAAA,SAAQ,YAAY;AAAA,YAChB;AAAA,cACE;AAAA,sBACQ;AAAA,qBACD;AAAA;AAAA;AAAA,MAGf;AAAA,IACF;AAEA,yCAAU,iBAAiB,UAAU;AAGrC,WAAO,MAAM;AApEjB;AAqEM,qBAAS,eAAe,gBAAgB,MAAxC,mBAA2C;AAC3C,2CAAU,oBAAoB,UAAU;AAAA,IAC1C;AAAA,EACF,GAAG,CAAC,iBAAiB,wBAAwB,CAAC;AAChD","sourcesContent":["import { useEffect } from \"react\";\n\nexport function useAddBrandingCss(\n suggestionStyleAugmented: React.CSSProperties,\n disableBranding: boolean | undefined,\n) {\n const cssSelector = \".copilot-textarea.with-branding\";\n useEffect(() => {\n if (disableBranding) {\n return;\n }\n\n // ---\n // 1: Add the CSS to the DOM\n const styleEl = document.createElement(\"style\");\n styleEl.id = \"dynamic-styles\";\n\n // Build the CSS string dynamically\n let dynamicStyles = Object.entries(suggestionStyleAugmented)\n .map(([key, value]) => {\n const kebabCaseKey = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, \"$1-$2\").toLowerCase();\n return `${kebabCaseKey}: ${value};`;\n })\n .join(\" \");\n\n // Append overrides for italics and font-size\n dynamicStyles += `font-style: normal; font-size: x-small;`;\n dynamicStyles += `content: \"CopilotKit\";`;\n dynamicStyles += `bottom: 6px;`;\n dynamicStyles += `right: 6px;`;\n dynamicStyles += `pointer-events: none;`;\n dynamicStyles += `font-weight: 200;`;\n dynamicStyles += `padding: 0;`;\n dynamicStyles += `margin: 0;`;\n dynamicStyles += `border: 0;`;\n dynamicStyles += `line-height: 1;`;\n dynamicStyles += `position: absolute;`;\n\n // Append it to the ::after class\n styleEl.innerHTML = `\n ${cssSelector}::after {\n ${dynamicStyles}\n }\n `;\n\n document.head.appendChild(styleEl);\n\n // ---\n // 2: Add the scroll listener (to keep the branding in the bottom right as the textarea scrolls)\n const textarea = document.querySelector(cssSelector);\n const handleScroll = () => {\n const styleEl = document.getElementById(\"dynamic-styles\");\n if (styleEl && textarea) {\n const offsetFromBottom = -textarea.scrollTop + 6;\n const offsetFromRight = -textarea.scrollLeft + 6;\n styleEl.innerHTML = `\n ${cssSelector}::after {\n ${dynamicStyles}\n bottom: ${offsetFromBottom}px;\n right: ${offsetFromRight}px;\n }\n `;\n }\n };\n\n textarea?.addEventListener(\"scroll\", handleScroll);\n\n // Cleanup\n return () => {\n document.getElementById(\"dynamic-styles\")?.remove();\n textarea?.removeEventListener(\"scroll\", handleScroll);\n };\n }, [disableBranding, suggestionStyleAugmented]);\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { customAlphabet } from 'nanoid';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
|
|
6
|
+
function cn(...inputs) {
|
|
7
|
+
return twMerge(clsx(inputs));
|
|
8
|
+
}
|
|
9
|
+
var nanoid = customAlphabet(
|
|
10
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
11
|
+
7
|
|
12
|
+
);
|
|
13
|
+
function fetcher(input, init) {
|
|
14
|
+
return __async(this, null, function* () {
|
|
15
|
+
const res = yield fetch(input, init);
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const json = yield res.json();
|
|
18
|
+
if (json.error) {
|
|
19
|
+
const error = new Error(json.error);
|
|
20
|
+
error.status = res.status;
|
|
21
|
+
throw error;
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error("An unexpected error occurred");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return res.json();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function formatDate(input) {
|
|
30
|
+
const date = new Date(input);
|
|
31
|
+
return date.toLocaleDateString("en-US", {
|
|
32
|
+
month: "long",
|
|
33
|
+
day: "numeric",
|
|
34
|
+
year: "numeric"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
var arraysAreEqual = (arr1, arr2) => arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
38
|
+
function nullableCompatibleEqualityCheck(naiveEqualityCheck, a, b) {
|
|
39
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
40
|
+
return a === b;
|
|
41
|
+
}
|
|
42
|
+
return naiveEqualityCheck(a, b);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { arraysAreEqual, cn, fetcher, formatDate, nanoid, nullableCompatibleEqualityCheck };
|
|
46
|
+
//# sourceMappingURL=out.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-7SUZ6CXM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/utils.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAA6B;AACtC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;AAEO,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;AAEA,SAAsB,QAAoB,OAAoB,MAAmC;AAAA;AAC/F,UAAM,MAAM,MAAM,MAAM,OAAO,IAAI;AAEnC,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAI,KAAK,OAAO;AACd,cAAM,QAAQ,IAAI,MAAM,KAAK,KAAK;AAGlC,cAAM,SAAS,IAAI;AACnB,cAAM;AAAA,MACR,OAAO;AACL,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AAAA,IACF;AAEA,WAAO,IAAI,KAAK;AAAA,EAClB;AAAA;AAEO,SAAS,WAAW,OAAuC;AAChE,QAAM,OAAO,IAAI,KAAK,KAAK;AAC3B,SAAO,KAAK,mBAAmB,SAAS;AAAA,IACtC,OAAO;AAAA,IACP,KAAK;AAAA,IACL,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,iBAAiB,CAAC,MAAgB,SAC7C,KAAK,WAAW,KAAK,UAAU,KAAK,MAAM,CAAC,OAAO,UAAU,UAAU,KAAK,KAAK,CAAC;AAE5E,SAAS,gCACd,oBACA,GACA,GACS;AACT,MAAI,MAAM,QAAQ,MAAM,UAAa,MAAM,QAAQ,MAAM,QAAW;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,SAAO,mBAAmB,GAAG,CAAC;AAChC","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { customAlphabet } from \"nanoid\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\nexport const nanoid = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n); // 7-character random string\n\nexport async function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON> {\n const res = await fetch(input, init);\n\n if (!res.ok) {\n const json = await res.json();\n if (json.error) {\n const error = new Error(json.error) as Error & {\n status: number;\n };\n error.status = res.status;\n throw error;\n } else {\n throw new Error(\"An unexpected error occurred\");\n }\n }\n\n return res.json();\n}\n\nexport function formatDate(input: string | number | Date): string {\n const date = new Date(input);\n return date.toLocaleDateString(\"en-US\", {\n month: \"long\",\n day: \"numeric\",\n year: \"numeric\",\n });\n}\n\nexport const arraysAreEqual = (arr1: number[], arr2: number[]): boolean =>\n arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);\n\nexport function nullableCompatibleEqualityCheck<T>(\n naiveEqualityCheck: (a: T, b: T) => boolean,\n a: T | null | undefined,\n b: T | null | undefined,\n): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n return naiveEqualityCheck(a, b);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { withPartialHistory, defaultShouldSave } from './chunk-4NHVQZ67.mjs';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { createEditor, Element } from 'slate';
|
|
4
|
+
import { withReact } from 'slate-react';
|
|
5
|
+
|
|
6
|
+
var shouldSave = (op, prev) => {
|
|
7
|
+
const excludedNodeType = "suggestion";
|
|
8
|
+
if (op.type === "insert_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (op.type === "remove_node" && Element.isElement(op.node) && op.node.type === excludedNodeType) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (op.type === "set_node" && "type" in op.newProperties && op.newProperties.type === excludedNodeType) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (op.type == "set_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (op.type === "merge_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (op.type === "split_node" && "type" in op.properties && op.properties.type === excludedNodeType) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return defaultShouldSave(op, prev);
|
|
27
|
+
};
|
|
28
|
+
function useCopilotTextareaEditor() {
|
|
29
|
+
const editor = useMemo(() => {
|
|
30
|
+
const editor2 = withPartialHistory(withReact(createEditor()), shouldSave);
|
|
31
|
+
const { isVoid } = editor2;
|
|
32
|
+
editor2.isVoid = (element) => {
|
|
33
|
+
switch (element.type) {
|
|
34
|
+
case "suggestion":
|
|
35
|
+
return true;
|
|
36
|
+
default:
|
|
37
|
+
return isVoid(element);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const { markableVoid } = editor2;
|
|
41
|
+
editor2.markableVoid = (element) => {
|
|
42
|
+
switch (element.type) {
|
|
43
|
+
case "suggestion":
|
|
44
|
+
return true;
|
|
45
|
+
default:
|
|
46
|
+
return markableVoid(element);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const { isInline } = editor2;
|
|
50
|
+
editor2.isInline = (element) => {
|
|
51
|
+
switch (element.type) {
|
|
52
|
+
case "suggestion":
|
|
53
|
+
return element.inline;
|
|
54
|
+
default:
|
|
55
|
+
return isInline(element);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return editor2;
|
|
59
|
+
}, []);
|
|
60
|
+
return editor;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { useCopilotTextareaEditor };
|
|
64
|
+
//# sourceMappingURL=out.js.map
|
|
65
|
+
//# sourceMappingURL=chunk-DRV2FOHZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx"],"names":["editor"],"mappings":";;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,cAAc,eAAe;AACtC,SAAS,iBAAiB;AAQ1B,IAAM,aAAk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7B,cAAQ,QAAQ,MAAM;AAAA,QACpB,KAAK;AACH,iBAAO,QAAQ;AAAA,QACjB;AACE,iBAAO,SAAS,OAAO;AAAA,MAC3B;AAAA,IACF;AAEA,WAAOA;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT","sourcesContent":["import { useMemo } from \"react\";\nimport { createEditor, Element } from \"slate\";\nimport { withReact } from \"slate-react\";\nimport {\n defaultShouldSave,\n ShouldSaveToHistory,\n withPartialHistory,\n} from \"../../lib/slatejs-edits/with-partial-history\";\nimport { CustomEditor } from \"../../types/base/custom-editor\";\n\nconst shouldSave: ShouldSaveToHistory = (op, prev) => {\n const excludedNodeType = \"suggestion\";\n // Check if the operation involves the suggestion inline node type\n if (\n op.type === \"insert_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"remove_node\" &&\n Element.isElement(op.node) &&\n op.node.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"set_node\" &&\n \"type\" in op.newProperties &&\n op.newProperties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (op.type == \"set_node\" && \"type\" in op.properties && op.properties.type === excludedNodeType) {\n return false;\n }\n\n if (\n op.type === \"merge_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n if (\n op.type === \"split_node\" &&\n \"type\" in op.properties &&\n op.properties.type === excludedNodeType\n ) {\n return false;\n }\n\n // Otherwise, save the operation to history\n return defaultShouldSave(op, prev);\n};\n\nexport function useCopilotTextareaEditor(): CustomEditor {\n const editor = useMemo(() => {\n const editor = withPartialHistory(withReact(createEditor()), shouldSave);\n\n const { isVoid } = editor;\n editor.isVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return isVoid(element);\n }\n };\n\n const { markableVoid } = editor;\n editor.markableVoid = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return true;\n default:\n return markableVoid(element);\n }\n };\n\n const { isInline } = editor;\n editor.isInline = (element) => {\n switch (element.type) {\n case \"suggestion\":\n return element.inline;\n default:\n return isInline(element);\n }\n };\n\n return editor;\n }, []);\n\n return editor;\n}\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Range, Editor, Text, Element, Path, Point } from 'slate';
|
|
2
|
+
|
|
3
|
+
// src/lib/get-text-around-cursor.ts
|
|
4
|
+
function getTextAroundCollapsedCursor(editor) {
|
|
5
|
+
const { selection } = editor;
|
|
6
|
+
if (!selection || !Range.isCollapsed(selection)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const cursorPoint = selection.anchor;
|
|
10
|
+
const beforeRange = {
|
|
11
|
+
anchor: Editor.start(editor, []),
|
|
12
|
+
focus: cursorPoint
|
|
13
|
+
};
|
|
14
|
+
const afterRange = {
|
|
15
|
+
anchor: cursorPoint,
|
|
16
|
+
focus: Editor.end(editor, [])
|
|
17
|
+
};
|
|
18
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
19
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
20
|
+
return {
|
|
21
|
+
cursorPoint,
|
|
22
|
+
textBeforeCursor: before,
|
|
23
|
+
textAfterCursor: after
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getTextAroundSelection(editor) {
|
|
27
|
+
const { selection } = editor;
|
|
28
|
+
if (!selection) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const wellOrderedSelection = wellOrderedRange(selection);
|
|
32
|
+
const beforeRange = {
|
|
33
|
+
anchor: Editor.start(editor, []),
|
|
34
|
+
focus: wellOrderedSelection.anchor
|
|
35
|
+
};
|
|
36
|
+
const afterRange = {
|
|
37
|
+
anchor: wellOrderedSelection.focus,
|
|
38
|
+
focus: Editor.end(editor, [])
|
|
39
|
+
};
|
|
40
|
+
const before = extractTextWithNewlines(editor, beforeRange);
|
|
41
|
+
const after = extractTextWithNewlines(editor, afterRange);
|
|
42
|
+
const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);
|
|
43
|
+
return {
|
|
44
|
+
selection: wellOrderedSelection,
|
|
45
|
+
textBeforeCursor: before,
|
|
46
|
+
selectedText,
|
|
47
|
+
textAfterCursor: after
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getFullEditorTextWithNewlines(editor) {
|
|
51
|
+
const fullDocumentRange = {
|
|
52
|
+
anchor: Editor.start(editor, []),
|
|
53
|
+
focus: Editor.end(editor, [])
|
|
54
|
+
};
|
|
55
|
+
return extractTextWithNewlines(editor, fullDocumentRange);
|
|
56
|
+
}
|
|
57
|
+
function extractTextWithNewlines(editor, range) {
|
|
58
|
+
const voids = false;
|
|
59
|
+
const [start, end] = Range.edges(range);
|
|
60
|
+
let text = "";
|
|
61
|
+
let lastBlock = null;
|
|
62
|
+
for (const [node, path] of Editor.nodes(editor, {
|
|
63
|
+
at: range,
|
|
64
|
+
match: Text.isText,
|
|
65
|
+
voids
|
|
66
|
+
})) {
|
|
67
|
+
let t = node.text;
|
|
68
|
+
const [block] = Editor.above(editor, {
|
|
69
|
+
at: path,
|
|
70
|
+
match: (n) => Element.isElement(n) && n.type === "paragraph"
|
|
71
|
+
}) || [null];
|
|
72
|
+
if (lastBlock !== block && block) {
|
|
73
|
+
if (lastBlock) {
|
|
74
|
+
text += "\n";
|
|
75
|
+
}
|
|
76
|
+
lastBlock = block;
|
|
77
|
+
}
|
|
78
|
+
if (Path.equals(path, end.path)) {
|
|
79
|
+
t = t.slice(0, end.offset);
|
|
80
|
+
}
|
|
81
|
+
if (Path.equals(path, start.path)) {
|
|
82
|
+
t = t.slice(start.offset);
|
|
83
|
+
}
|
|
84
|
+
text += t;
|
|
85
|
+
}
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
function wellOrderedRange(range) {
|
|
89
|
+
const { anchor, focus } = range;
|
|
90
|
+
if (Point.isBefore(anchor, focus)) {
|
|
91
|
+
return range;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
anchor: focus,
|
|
95
|
+
focus: anchor
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { extractTextWithNewlines, getFullEditorTextWithNewlines, getTextAroundCollapsedCursor, getTextAroundSelection };
|
|
100
|
+
//# sourceMappingURL=out.js.map
|
|
101
|
+
//# sourceMappingURL=chunk-ECR45NSD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/get-text-around-cursor.ts"],"names":[],"mappings":";AAAA,SAAS,QAAc,MAAM,OAAO,MAAM,SAA+B,aAAa;AAW/E,SAAS,6BAA6B,QAAgD;AAC3F,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,aAAa,CAAC,MAAM,YAAY,SAAS,GAAG;AAC/C,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,UAAU;AAG9B,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO;AAAA,EACT;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ;AAAA,IACR,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC;AAAA,EAC9B;AAGA,QAAM,SAAS,wBAAwB,QAAQ,WAAW;AAC1D,QAAM,QAAQ,wBAAwB,QAAQ,UAAU;AAExD,SAAO;AAAA,IACL;AAAA,IACA,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EACnB;AACF;AAEO,SAAS,uBAAuB,QAAwC;AAC7E,QAAM,EAAE,UAAU,IAAI;AACtB,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,QAAM,uBAAuB,iBAAiB,SAAS;AAGvD,QAAM,cAAqB;AAAA,IACzB,QAAQ,OAAO,MAAM,QAAQ,CAAC,CAAC;AAAA,IAC/B,OAAO,qBAAqB;AAAA,EAC9B;AACA,QAAM,aAAoB;AAAA,IACxB,QAAQ,qBAAqB;AAAA,IAC7B,OAAO,OAAO,IAAI,QAAQ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YAAQ;AAAA,EACV;AAEA,SAAO;AACT;AAEA,SAAS,iBAAiB,OAA6B;AACrD,QAAM,EAAE,QAAQ,MAAM,IAAI;AAE1B,MAAI,MAAM,SAAS,QAAQ,KAAK,GAAG;AACjC,WAAO;AAAA,EACT;AAGA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF","sourcesContent":["import { Editor, Node, Path, Range, Text, Element, BasePoint, BaseRange, Point } from \"slate\";\nimport { EditorAutocompleteState } from \"../types/base/editor-autocomplete-state\";\n\nexport interface EditorTextState {\n selection: BaseRange;\n\n textBeforeCursor: string;\n selectedText: string;\n textAfterCursor: string;\n}\n\nexport function getTextAroundCollapsedCursor(editor: Editor): EditorAutocompleteState | null {\n const { selection } = editor;\n if (!selection || !Range.isCollapsed(selection)) {\n return null;\n }\n\n const cursorPoint = selection.anchor;\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: cursorPoint,\n };\n const afterRange: Range = {\n anchor: cursorPoint,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n\n return {\n cursorPoint: cursorPoint,\n textBeforeCursor: before,\n textAfterCursor: after,\n };\n}\n\nexport function getTextAroundSelection(editor: Editor): EditorTextState | null {\n const { selection } = editor;\n if (!selection) {\n return null;\n }\n\n const wellOrderedSelection = wellOrderedRange(selection);\n\n // Create two ranges: one before the anchor and one after\n const beforeRange: Range = {\n anchor: Editor.start(editor, []),\n focus: wellOrderedSelection.anchor,\n };\n const afterRange: Range = {\n anchor: wellOrderedSelection.focus,\n focus: Editor.end(editor, []),\n };\n\n // Extract text for these ranges\n const before = extractTextWithNewlines(editor, beforeRange);\n const after = extractTextWithNewlines(editor, afterRange);\n const selectedText = extractTextWithNewlines(editor, wellOrderedSelection);\n\n return {\n selection: wellOrderedSelection,\n textBeforeCursor: before,\n selectedText,\n textAfterCursor: after,\n };\n}\n\nexport function getFullEditorTextWithNewlines(editor: Editor): string {\n const fullDocumentRange: Range = {\n anchor: Editor.start(editor, []),\n focus: Editor.end(editor, []),\n };\n return extractTextWithNewlines(editor, fullDocumentRange);\n}\n\n// Helper function to extract text with newlines\nexport function extractTextWithNewlines(editor: Editor, range: Range): string {\n const voids = false;\n const [start, end] = Range.edges(range);\n let text = \"\";\n let lastBlock: Node | null = null;\n\n for (const [node, path] of Editor.nodes(editor, {\n at: range,\n match: Text.isText,\n voids,\n })) {\n let t = node.text;\n\n // Determine the parent block of the current text node\n const [block] = Editor.above(editor, {\n at: path,\n match: (n) => Element.isElement(n) && n.type === \"paragraph\",\n }) || [null];\n\n // If we encounter a new block, prepend a newline\n if (lastBlock !== block && block) {\n // check that lastBlock is not null to avoid adding a newline at the beginning\n if (lastBlock) {\n text += \"\\n\";\n }\n lastBlock = block;\n }\n\n if (Path.equals(path, end.path)) {\n t = t.slice(0, end.offset);\n }\n\n if (Path.equals(path, start.path)) {\n t = t.slice(start.offset);\n }\n\n text += t;\n }\n\n return text;\n}\n\nfunction wellOrderedRange(range: BaseRange): BaseRange {\n const { anchor, focus } = range;\n // if anchor is before focus, return range as is\n if (Point.isBefore(anchor, focus)) {\n return range;\n }\n\n // if focus is before anchor, return range with anchor and focus swapped\n return {\n anchor: focus,\n focus: anchor,\n };\n}\n"]}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { IncludedFilesPreview } from './chunk-EPBVNDKE.mjs';
|
|
2
|
+
import { Label } from './chunk-KFQZHRPJ.mjs';
|
|
3
|
+
import { SourceSearchBox } from './chunk-FJNUPSQK.mjs';
|
|
4
|
+
import { Button } from './chunk-WFTAAA7R.mjs';
|
|
5
|
+
import { use_autosize_textarea_default } from './chunk-3PQ7GSFE.mjs';
|
|
6
|
+
import { streamPromiseFlatten } from './chunk-2QDCE7PD.mjs';
|
|
7
|
+
import { __async } from './chunk-MRXNTQOX.mjs';
|
|
8
|
+
import { useContext, useState, useRef, useEffect, useCallback } from 'react';
|
|
9
|
+
import { CopilotContext } from '@copilotkit/react-core';
|
|
10
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var HoveringInsertionPromptBoxCore = ({
|
|
13
|
+
performInsertion,
|
|
14
|
+
state,
|
|
15
|
+
insertionOrEditingFunction,
|
|
16
|
+
contextCategories
|
|
17
|
+
}) => {
|
|
18
|
+
const { getDocumentsContext } = useContext(CopilotContext);
|
|
19
|
+
const [editSuggestion, setEditSuggestion] = useState("");
|
|
20
|
+
const [suggestionIsLoading, setSuggestionIsLoading] = useState(false);
|
|
21
|
+
const [adjustmentPrompt, setAdjustmentPrompt] = useState("");
|
|
22
|
+
const [generatingSuggestion, setGeneratingSuggestion] = useState(
|
|
23
|
+
null
|
|
24
|
+
);
|
|
25
|
+
const adjustmentTextAreaRef = useRef(null);
|
|
26
|
+
const suggestionTextAreaRef = useRef(null);
|
|
27
|
+
const [filePointers, setFilePointers] = useState([]);
|
|
28
|
+
const [suggestedFiles, setSuggestedFiles] = useState([]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setSuggestedFiles(getDocumentsContext(contextCategories));
|
|
31
|
+
}, [contextCategories, getDocumentsContext]);
|
|
32
|
+
use_autosize_textarea_default(suggestionTextAreaRef, editSuggestion || "");
|
|
33
|
+
use_autosize_textarea_default(adjustmentTextAreaRef, adjustmentPrompt || "");
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!generatingSuggestion) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (generatingSuggestion.locked) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
setEditSuggestion("");
|
|
46
|
+
const reader = generatingSuggestion.getReader();
|
|
47
|
+
const read = () => __async(void 0, null, function* () {
|
|
48
|
+
setSuggestionIsLoading(true);
|
|
49
|
+
while (true) {
|
|
50
|
+
const { done, value } = yield reader.read();
|
|
51
|
+
if (done) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
setEditSuggestion((prev) => {
|
|
55
|
+
const newSuggestion = prev + value;
|
|
56
|
+
if (suggestionTextAreaRef.current) {
|
|
57
|
+
suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;
|
|
58
|
+
}
|
|
59
|
+
return newSuggestion;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
setSuggestionIsLoading(false);
|
|
63
|
+
});
|
|
64
|
+
read();
|
|
65
|
+
return () => {
|
|
66
|
+
const releaseLockIfNotClosed = () => __async(void 0, null, function* () {
|
|
67
|
+
try {
|
|
68
|
+
yield reader.closed;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
reader.releaseLock();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
releaseLockIfNotClosed();
|
|
74
|
+
};
|
|
75
|
+
}, [generatingSuggestion]);
|
|
76
|
+
const beginGeneratingAdjustment = useCallback(() => __async(void 0, null, function* () {
|
|
77
|
+
if (!adjustmentPrompt.trim()) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let modificationState = state.editorState;
|
|
81
|
+
if (editSuggestion !== "") {
|
|
82
|
+
modificationState.selectedText = editSuggestion;
|
|
83
|
+
}
|
|
84
|
+
const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(
|
|
85
|
+
modificationState,
|
|
86
|
+
adjustmentPrompt,
|
|
87
|
+
filePointers,
|
|
88
|
+
new AbortController().signal
|
|
89
|
+
);
|
|
90
|
+
const adjustmentSuggestionTextStream = streamPromiseFlatten(
|
|
91
|
+
adjustmentSuggestionTextStreamPromise
|
|
92
|
+
);
|
|
93
|
+
setGeneratingSuggestion(adjustmentSuggestionTextStream);
|
|
94
|
+
}), [
|
|
95
|
+
adjustmentPrompt,
|
|
96
|
+
editSuggestion,
|
|
97
|
+
state.editorState,
|
|
98
|
+
insertionOrEditingFunction,
|
|
99
|
+
filePointers
|
|
100
|
+
]);
|
|
101
|
+
const isLoading = suggestionIsLoading;
|
|
102
|
+
const textToEdit = editSuggestion || state.editorState.selectedText;
|
|
103
|
+
const adjustmentLabel = textToEdit === "" ? "Describe the text you want to insert" : "Describe adjustments to the suggested text";
|
|
104
|
+
const placeholder = textToEdit === "" ? "e.g. 'summarize the client's top 3 pain-points from @CallTranscript'" : "e.g. 'make it more formal', 'be more specific', ...";
|
|
105
|
+
const AdjustmentPromptComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(Label, { className: "", children: adjustmentLabel }),
|
|
107
|
+
/* @__PURE__ */ jsxs("div", { className: "relative w-full flex items-center", children: [
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
"textarea",
|
|
110
|
+
{
|
|
111
|
+
disabled: suggestionIsLoading,
|
|
112
|
+
ref: adjustmentTextAreaRef,
|
|
113
|
+
value: adjustmentPrompt,
|
|
114
|
+
onChange: (e) => setAdjustmentPrompt(e.target.value),
|
|
115
|
+
onKeyDown: (e) => {
|
|
116
|
+
if (e.key === "Enter" && e.shiftKey) {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
setAdjustmentPrompt(adjustmentPrompt + "\n");
|
|
119
|
+
} else if (e.key === "Enter") {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
beginGeneratingAdjustment();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
placeholder,
|
|
125
|
+
style: { minHeight: "3rem" },
|
|
126
|
+
className: "w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]",
|
|
127
|
+
rows: 1
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
"button",
|
|
132
|
+
{
|
|
133
|
+
onClick: beginGeneratingAdjustment,
|
|
134
|
+
className: "absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center",
|
|
135
|
+
children: /* @__PURE__ */ jsx("i", { className: "material-icons", children: "arrow_forward" })
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
] })
|
|
139
|
+
] });
|
|
140
|
+
const SuggestionComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
141
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-between items-end w-full", children: [
|
|
142
|
+
/* @__PURE__ */ jsx(Label, { className: "mt-4", children: "Suggested:" }),
|
|
143
|
+
/* @__PURE__ */ jsx("div", { className: "ml-auto", children: isLoading && /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center", children: /* @__PURE__ */ jsx(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
className: "inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]",
|
|
147
|
+
role: "status",
|
|
148
|
+
children: /* @__PURE__ */ jsx("span", { className: "!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]", children: "Loading..." })
|
|
149
|
+
}
|
|
150
|
+
) }) })
|
|
151
|
+
] }),
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"textarea",
|
|
154
|
+
{
|
|
155
|
+
ref: suggestionTextAreaRef,
|
|
156
|
+
value: editSuggestion,
|
|
157
|
+
disabled: suggestionIsLoading,
|
|
158
|
+
onChange: (e) => setEditSuggestion(e.target.value),
|
|
159
|
+
className: "w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50",
|
|
160
|
+
style: { overflow: "auto", maxHeight: "10em" }
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] });
|
|
164
|
+
const SubmitComponent = /* @__PURE__ */ jsx("div", { className: "flex w-full gap-4 justify-start", children: /* @__PURE__ */ jsxs(
|
|
165
|
+
Button,
|
|
166
|
+
{
|
|
167
|
+
className: " bg-green-700 text-white",
|
|
168
|
+
onClick: () => {
|
|
169
|
+
performInsertion(editSuggestion);
|
|
170
|
+
},
|
|
171
|
+
children: [
|
|
172
|
+
"Insert ",
|
|
173
|
+
/* @__PURE__ */ jsx("i", { className: "material-icons", children: "check" })
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
) });
|
|
177
|
+
const sourceSearchCandidate = adjustmentPrompt.split(" ").pop();
|
|
178
|
+
const sourceSearchWord = (sourceSearchCandidate == null ? void 0 : sourceSearchCandidate.startsWith("@")) ? sourceSearchCandidate.slice(1) : void 0;
|
|
179
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col items-start relative gap-2", children: [
|
|
180
|
+
AdjustmentPromptComponent,
|
|
181
|
+
filePointers.length > 0 && /* @__PURE__ */ jsx(IncludedFilesPreview, { includedFiles: filePointers, setIncludedFiles: setFilePointers }),
|
|
182
|
+
sourceSearchWord !== void 0 && /* @__PURE__ */ jsx(
|
|
183
|
+
SourceSearchBox,
|
|
184
|
+
{
|
|
185
|
+
searchTerm: sourceSearchWord,
|
|
186
|
+
suggestedFiles,
|
|
187
|
+
onSelectedFile: (filePointer) => {
|
|
188
|
+
var _a;
|
|
189
|
+
setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), ""));
|
|
190
|
+
setFilePointers((prev) => [...prev, filePointer]);
|
|
191
|
+
(_a = adjustmentTextAreaRef.current) == null ? void 0 : _a.focus();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
generatingSuggestion ? SuggestionComponent : null,
|
|
196
|
+
generatingSuggestion ? SubmitComponent : null
|
|
197
|
+
] });
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { HoveringInsertionPromptBoxCore };
|
|
201
|
+
//# sourceMappingURL=out.js.map
|
|
202
|
+
//# sourceMapping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;AAAA,MACV,SAAS,MAAM;AACb,yBAAiB,cAAc;AAAA,MACjC;AAAA,MACD;AAAA;AAAA,QACQ,oBAAC,OAAE,WAAU,kBAAiB,mBAAK;AAAA;AAAA;AAAA,EAC5C,GACF;AAIF,QAAM,wBAAwB,iBAAiB,MAAM,GAAG,EAAE,IAAI;AAE9D,QAAM,oBAAmB,+DAAuB,WAAW,QACvD,sBAAsB,MAAM,CAAC,IAC7B;AAEJ,SACE,qBAAC,SAAI,WAAU,mDACZ;AAAA;AAAA,IACA,aAAa,SAAS,KACrB,oBAAC,wBAAqB,eAAe,cAAc,kBAAkB,iBAAiB;AAAA,IAEvF,qBAAqB,UACpB;AAAA,MAAC;AAAA;AAAA,QACC,YAAY;AAAA,QACZ;AAAA,QACA,gBAAgB,CAAC,gBAAgB;AA9P3C;AA+PY,8BAAoB,iBAAiB,QAAQ,IAAI,OAAO,IAAI,mBAAmB,GAAG,EAAE,CAAC;AACrF,0BAAgB,CAAC,SAAS,CAAC,GAAG,MAAM,WAAW,CAAC;AAGhD,sCAAsB,YAAtB,mBAA+B;AAAA,QACjC;AAAA;AAAA,IACF;AAAA,IAED,uBAAuB,sBAAsB;AAAA,IAC7C,uBAAuB,kBAAkB;AAAA,KAC5C;AAEJ","sourcesContent":["import useAutosizeTextArea from \"../../../hooks/misc/use-autosize-textarea\";\nimport { MinimalChatGPTMessage } from \"../../../types\";\nimport {\n EditingEditorState,\n Generator_InsertionOrEditingSuggestion,\n} from \"../../../types/base/autosuggestions-bare-function\";\nimport { SourceSearchBox } from \"../../source-search-box/source-search-box\";\nimport { DocumentPointer } from \"@copilotkit/react-core\";\nimport { Button } from \"../../ui/button\";\nimport { Label } from \"../../ui/label\";\nimport React, { useCallback, useContext, useEffect, useRef, useState } from \"react\";\n\nimport { streamPromiseFlatten } from \"../../../lib/stream-promise-flatten\";\nimport { CopilotContext } from \"@copilotkit/react-core\";\nimport { IncludedFilesPreview } from \"./included-files-preview\";\n\nexport type SuggestionState = {\n editorState: EditingEditorState;\n};\n\nexport interface HoveringInsertionPromptBoxCoreProps {\n state: SuggestionState;\n performInsertion: (insertedText: string) => void;\n insertionOrEditingFunction: Generator_InsertionOrEditingSuggestion;\n contextCategories: string[];\n}\n\nexport const HoveringInsertionPromptBoxCore: React.FC<HoveringInsertionPromptBoxCoreProps> = ({\n performInsertion,\n state,\n insertionOrEditingFunction,\n contextCategories,\n}) => {\n const { getDocumentsContext } = useContext(CopilotContext);\n\n const [editSuggestion, setEditSuggestion] = useState<string>(\"\");\n const [suggestionIsLoading, setSuggestionIsLoading] = useState<boolean>(false);\n\n const [adjustmentPrompt, setAdjustmentPrompt] = useState<string>(\"\");\n\n const [generatingSuggestion, setGeneratingSuggestion] = useState<ReadableStream<string> | null>(\n null,\n );\n\n const adjustmentTextAreaRef = useRef<HTMLTextAreaElement>(null);\n const suggestionTextAreaRef = useRef<HTMLTextAreaElement>(null);\n\n const [filePointers, setFilePointers] = useState<DocumentPointer[]>([]);\n\n const [suggestedFiles, setSuggestedFiles] = useState<DocumentPointer[]>([]);\n useEffect(() => {\n setSuggestedFiles(getDocumentsContext(contextCategories));\n }, [contextCategories, getDocumentsContext]);\n\n useAutosizeTextArea(suggestionTextAreaRef, editSuggestion || \"\");\n useAutosizeTextArea(adjustmentTextAreaRef, adjustmentPrompt || \"\");\n\n // initially focus on the adjustment prompt text area\n useEffect(() => {\n adjustmentTextAreaRef.current?.focus();\n }, []);\n\n // continuously read the generating suggestion stream and update the edit suggestion\n useEffect(() => {\n // if no generating suggestion, do nothing\n if (!generatingSuggestion) {\n return;\n }\n\n // Check if the stream is already locked (i.e. already reading from it)\n if (generatingSuggestion.locked) {\n return;\n }\n\n // reset the edit suggestion\n setEditSuggestion(\"\");\n\n // read the generating suggestion stream and continuously update the edit suggestion\n const reader = generatingSuggestion.getReader();\n const read = async () => {\n setSuggestionIsLoading(true);\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n setEditSuggestion((prev) => {\n const newSuggestion = prev + value;\n\n // Scroll to the bottom of the textarea. We call this here to make sure scroll-to-bottom is synchronous with the state update.\n if (suggestionTextAreaRef.current) {\n suggestionTextAreaRef.current.scrollTop = suggestionTextAreaRef.current.scrollHeight;\n }\n return newSuggestion;\n });\n }\n\n setSuggestionIsLoading(false);\n };\n read();\n\n return () => {\n // release the lock if the reader is not closed on unmount\n const releaseLockIfNotClosed = async () => {\n try {\n await reader.closed;\n } catch {\n reader.releaseLock();\n }\n };\n\n releaseLockIfNotClosed();\n };\n }, [generatingSuggestion]);\n\n // generate an adjustment to the completed text, based on the adjustment prompt\n const beginGeneratingAdjustment = useCallback(async () => {\n // don't generate text if the prompt is empty\n if (!adjustmentPrompt.trim()) {\n return;\n }\n\n // editor state includes the text being edited, and the text before/after the selection\n // if the current edit suggestion is not empty, then use *it* as the \"selected text\" - instead of the editor state's selected text\n let modificationState = state.editorState;\n if (editSuggestion !== \"\") {\n modificationState.selectedText = editSuggestion;\n }\n\n // generate the adjustment suggestion\n const adjustmentSuggestionTextStreamPromise = insertionOrEditingFunction(\n modificationState,\n adjustmentPrompt,\n filePointers,\n new AbortController().signal,\n );\n const adjustmentSuggestionTextStream = streamPromiseFlatten(\n adjustmentSuggestionTextStreamPromise,\n );\n\n setGeneratingSuggestion(adjustmentSuggestionTextStream);\n }, [\n adjustmentPrompt,\n editSuggestion,\n state.editorState,\n insertionOrEditingFunction,\n filePointers,\n ]);\n\n const isLoading = suggestionIsLoading;\n\n const textToEdit = editSuggestion || state.editorState.selectedText;\n const adjustmentLabel =\n textToEdit === \"\"\n ? \"Describe the text you want to insert\"\n : \"Describe adjustments to the suggested text\";\n const placeholder =\n textToEdit === \"\"\n ? \"e.g. 'summarize the client's top 3 pain-points from @CallTranscript'\"\n : \"e.g. 'make it more formal', 'be more specific', ...\";\n\n const AdjustmentPromptComponent = (\n <>\n <Label className=\"\">{adjustmentLabel}</Label>\n <div className=\"relative w-full flex items-center\">\n <textarea\n disabled={suggestionIsLoading}\n ref={adjustmentTextAreaRef}\n value={adjustmentPrompt}\n onChange={(e) => setAdjustmentPrompt(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" && e.shiftKey) {\n e.preventDefault();\n setAdjustmentPrompt(adjustmentPrompt + \"\\n\");\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n beginGeneratingAdjustment();\n }\n }}\n placeholder={placeholder}\n style={{ minHeight: \"3rem\" }}\n className=\"w-full bg-slate-100 h-auto h-min-14 text-sm p-2 rounded-md resize-none overflow-visible focus:outline-none focus:ring-0 focus:border-non pr-[3rem]\"\n rows={1}\n />\n <button\n onClick={beginGeneratingAdjustment}\n className=\"absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center\"\n >\n <i className=\"material-icons\">arrow_forward</i>\n </button>\n </div>\n </>\n );\n\n const SuggestionComponent = (\n <>\n <div className=\"flex justify-between items-end w-full\">\n <Label className=\"mt-4\">Suggested:</Label>\n <div className=\"ml-auto\">\n {isLoading && (\n <div className=\"flex justify-center items-center\">\n <div\n className=\"inline-block h-4 w-4 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]\"\n role=\"status\"\n >\n <span className=\"!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]\">\n Loading...\n </span>\n </div>\n </div>\n )}\n </div>\n </div>\n <textarea\n ref={suggestionTextAreaRef}\n value={editSuggestion}\n disabled={suggestionIsLoading}\n onChange={(e) => setEditSuggestion(e.target.value)}\n className=\"w-full text-base p-2 border border-gray-300 rounded-md resize-none bg-green-50\"\n style={{ overflow: \"auto\", maxHeight: \"10em\" }}\n />\n </>\n );\n\n const SubmitComponent = (\n <div className=\"flex w-full gap-4 justify-start\">\n <Button\n className=\" bg-green-700 text-white\"\n onClick={() => {\n performInsertion(editSuggestion);\n }}\n >\n Insert <i className=\"material-icons\">check</i>\n </Button>\n </div>\n );\n\n // show source search if the last word in the adjustment prompt BEGINS with an @\n const sourceSearchCandidate = adjustmentPrompt.split(\" \").pop();\n // if the candidate is @someCandidate, then 'someCandidate', otherwise undefined\n const sourceSearchWord = sourceSearchCandidate?.startsWith(\"@\")\n ? sourceSearchCandidate.slice(1)\n : undefined;\n\n return (\n <div className=\"w-full flex flex-col items-start relative gap-2\">\n {AdjustmentPromptComponent}\n {filePointers.length > 0 && (\n <IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />\n )}\n {sourceSearchWord !== undefined && (\n <SourceSearchBox\n searchTerm={sourceSearchWord}\n suggestedFiles={suggestedFiles}\n onSelectedFile={(filePointer) => {\n setAdjustmentPrompt(adjustmentPrompt.replace(new RegExp(`@${sourceSearchWord}$`), \"\"));\n setFilePointers((prev) => [...prev, filePointer]);\n\n // focus back on the adjustment prompt, and move the cursor to the end\n adjustmentTextAreaRef.current?.focus();\n }}\n />\n )}\n {generatingSuggestion ? SuggestionComponent : null}\n {generatingSuggestion ? SubmitComponent : null}\n </div>\n );\n};\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Label } from './chunk-KFQZHRPJ.mjs';
|
|
2
|
+
import Chip from '@mui/material/Chip/Chip.js';
|
|
3
|
+
import Avatar from '@mui/material/Avatar/Avatar.js';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var IncludedFilesPreview = ({
|
|
7
|
+
includedFiles,
|
|
8
|
+
setIncludedFiles
|
|
9
|
+
}) => {
|
|
10
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 mt-2", children: [
|
|
11
|
+
/* @__PURE__ */ jsx(Label, { className: "", children: "Included context:" }),
|
|
12
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: includedFiles.map((filePointer, index) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
FileChipPreview,
|
|
15
|
+
{
|
|
16
|
+
filePointer,
|
|
17
|
+
onDelete: () => {
|
|
18
|
+
setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
`file-${filePointer.sourceApplication}.${filePointer.name}`
|
|
22
|
+
);
|
|
23
|
+
}) })
|
|
24
|
+
] });
|
|
25
|
+
};
|
|
26
|
+
var FileChipPreview = ({ filePointer, onDelete }) => {
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
Chip,
|
|
29
|
+
{
|
|
30
|
+
label: filePointer.name,
|
|
31
|
+
onDelete,
|
|
32
|
+
avatar: /* @__PURE__ */ jsx(
|
|
33
|
+
Avatar,
|
|
34
|
+
{
|
|
35
|
+
src: filePointer.iconImageUri,
|
|
36
|
+
alt: filePointer.sourceApplication,
|
|
37
|
+
sx: { backgroundColor: "transparent" }
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { FileChipPreview, IncludedFilesPreview };
|
|
45
|
+
//# sourceMappingURL=out.js.map
|
|
46
|
+
//# sourceMappingURL=chunk-EPBVNDKE.mjs.map
|