@copilotkit/react-textarea 0.15.0 → 0.15.1

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @copilotkit/react-textarea@0.15.0 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-textarea
2
+ > @copilotkit/react-textarea@0.15.1 build /home/runner/work/CopilotKit/CopilotKit/CopilotKit/packages/react-textarea
3
3
  > tsup --treeshake
4
4
 
5
5
  CLI Building entry: src/index.tsx, src/components/index.ts, src/context/index.ts, src/hooks/index.ts, src/lib/debouncer.ts, src/lib/editor-to-text.ts, src/lib/get-text-around-cursor.ts, src/lib/utils.test.ts, src/lib/utils.ts, src/types/html-copilot-textarea-element.ts, src/types/index.ts, src/components/base-copilot-textarea/base-copilot-textarea.tsx, src/components/base-copilot-textarea/render-element.tsx, src/components/base-copilot-textarea/render-placeholder.tsx, src/components/base-copilot-textarea/use-add-branding-css.tsx, src/components/copilot-textarea/copilot-textarea.tsx, src/hooks/base-copilot-textarea-implementation/use-autosuggestions.ts, src/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.tsx, src/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.ts, src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx, src/lib/slatejs-edits/add-autocompletions.ts, src/lib/slatejs-edits/clear-autocompletions.ts, src/lib/slatejs-edits/replace-text.ts, src/lib/slatejs-edits/with-partial-history.ts, src/types/base/autosuggestion-state.ts, src/types/base/autosuggestions-bare-function.ts, src/types/base/base-autosuggestions-config.tsx, src/types/base/base-copilot-textarea-props.tsx, src/types/base/custom-editor.tsx, src/types/base/editor-autocomplete-state.ts, src/types/base/index.ts, src/types/standard-autosuggestions/autosuggestions-config.tsx, src/types/standard-autosuggestions/chatlike-api-endpoint.tsx, src/types/standard-autosuggestions/index.ts, src/types/standard-autosuggestions/minimal-chat-gpt-message.tsx
@@ -57,11 +57,11 @@ Generated an empty chunk: "chunk-H4VKQGVU".
57
57
  ESM dist/components/copilot-textarea/copilot-textarea.mjs 907.00 B
58
58
  ESM dist/index.mjs 1.12 KB
59
59
  ESM dist/components/index.mjs 888.00 B
60
- ESM dist/chunk-DRXBRCHN.mjs 1.23 KB
60
+ ESM dist/chunk-K3P3PCV7.mjs 1.23 KB
61
61
  ESM dist/chunk-4ES2IIB6.mjs 1.76 KB
62
62
  ESM dist/chunk-LGK56BTO.mjs 2.86 KB
63
63
  ESM dist/chunk-3A2CNIG5.mjs 949.00 B
64
- ESM dist/chunk-M6QFKIBE.mjs 5.99 KB
64
+ ESM dist/chunk-QZ2PN6ZU.mjs 6.02 KB
65
65
  ESM dist/chunk-HZGSG7ST.mjs 3.02 KB
66
66
  ESM dist/chunk-UW3ITU2Y.mjs 496.00 B
67
67
  ESM dist/chunk-CSGFJU3L.mjs 2.01 KB
@@ -122,11 +122,11 @@ Generated an empty chunk: "chunk-H4VKQGVU".
122
122
  ESM dist/components/copilot-textarea/copilot-textarea.mjs.map 51.00 B
123
123
  ESM dist/index.mjs.map 51.00 B
124
124
  ESM dist/components/index.mjs.map 51.00 B
125
- ESM dist/chunk-DRXBRCHN.mjs.map 2.17 KB
125
+ ESM dist/chunk-K3P3PCV7.mjs.map 2.17 KB
126
126
  ESM dist/chunk-4ES2IIB6.mjs.map 4.41 KB
127
127
  ESM dist/chunk-LGK56BTO.mjs.map 4.17 KB
128
128
  ESM dist/chunk-3A2CNIG5.mjs.map 2.15 KB
129
- ESM dist/chunk-M6QFKIBE.mjs.map 10.78 KB
129
+ ESM dist/chunk-QZ2PN6ZU.mjs.map 10.79 KB
130
130
  ESM dist/chunk-HZGSG7ST.mjs.map 5.83 KB
131
131
  ESM dist/chunk-UW3ITU2Y.mjs.map 878.00 B
132
132
  ESM dist/chunk-CSGFJU3L.mjs.map 3.82 KB
@@ -159,12 +159,12 @@ Generated an empty chunk: "chunk-H4VKQGVU".
159
159
  ESM dist/types/standard-autosuggestions/autosuggestions-config.mjs.map 51.00 B
160
160
  ESM dist/hooks/base-copilot-textarea-implementation/use-copilot-textarea-editor.mjs.map 51.00 B
161
161
  ESM dist/hooks/base-copilot-textarea-implementation/use-populate-copilot-textarea-ref.mjs.map 51.00 B
162
- ESM ⚡️ Build success in 3150ms
162
+ ESM ⚡️ Build success in 3598ms
163
163
  Export "AutosuggestionsConfig" of module "src/types/standard-autosuggestions/autosuggestions-config.tsx" was reexported through module "src/types/standard-autosuggestions/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
164
164
  Either change the import in "src/components/copilot-textarea/copilot-textarea.tsx" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.
165
165
  Export "MakeSystemPrompt" of module "src/types/standard-autosuggestions/autosuggestions-config.tsx" was reexported through module "src/types/standard-autosuggestions/index.ts" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
166
166
  Either change the import in "src/hooks/make-autosuggestions-function/use-make-standard-autosuggestions-function.tsx" to point directly to the exporting module or do not use "preserveModules" to ensure these modules end up in the same chunk.
167
- DTS ⚡️ Build success in 5403ms
167
+ DTS ⚡️ Build success in 6637ms
168
168
  DTS dist/index.d.ts 1.01 KB
169
169
  DTS dist/components/base-copilot-textarea/base-copilot-textarea.d.ts 669.00 B
170
170
  DTS dist/components/copilot-textarea/copilot-textarea.d.ts 875.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ui
2
2
 
3
+ ## 0.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 8f4b3d1: do not include disableBranding in props forwarded to DOM
8
+
3
9
  ## 0.15.0
4
10
 
5
11
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  import { useMakeStandardAutosuggestionFunction } from './chunk-4ES2IIB6.mjs';
2
2
  import { defaultAutosuggestionsConfig } from './chunk-LGK56BTO.mjs';
3
- import { BaseCopilotTextarea } from './chunk-M6QFKIBE.mjs';
3
+ import { BaseCopilotTextarea } from './chunk-QZ2PN6ZU.mjs';
4
4
  import { __spreadValues, __spreadProps } from './chunk-MRXNTQOX.mjs';
5
5
  import React from 'react';
6
6
  import { jsx, Fragment } from 'react/jsx-runtime';
@@ -29,4 +29,4 @@ var CopilotTextarea = React.forwardRef(
29
29
 
30
30
  export { CopilotTextarea };
31
31
  //# sourceMappingURL=out.js.map
32
- //# sourceMappingURL=chunk-DRXBRCHN.mjs.map
32
+ //# sourceMappingURL=chunk-K3P3PCV7.mjs.map
@@ -69,7 +69,6 @@ var BaseCopilotTextarea = React.forwardRef(
69
69
  color: "gray"
70
70
  }, props.suggestionsStyle);
71
71
  }, [props.suggestionsStyle]);
72
- useAddBrandingCss(suggestionStyleAugmented, props.disableBranding);
73
72
  const renderElementMemoized = useMemo(() => {
74
73
  return makeRenderElementFunction(suggestionStyleAugmented);
75
74
  }, [suggestionStyleAugmented]);
@@ -96,7 +95,8 @@ var BaseCopilotTextarea = React.forwardRef(
96
95
  autosuggestionsFunction,
97
96
  className,
98
97
  onChange,
99
- onKeyDown
98
+ onKeyDown,
99
+ disableBranding
100
100
  } = _a, propsToForward = __objRest(_a, [
101
101
  "placeholderStyle",
102
102
  "value",
@@ -105,11 +105,14 @@ var BaseCopilotTextarea = React.forwardRef(
105
105
  "autosuggestionsFunction",
106
106
  "className",
107
107
  "onChange",
108
- "onKeyDown"
108
+ "onKeyDown",
109
+ "disableBranding"
109
110
  ]);
111
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
112
+ usePopulateCopilotTextareaRef(editor, ref);
110
113
  const moddedClassName = (() => {
111
114
  const baseClassName = "copilot-textarea";
112
- const brandingClass = props.disableBranding ? "no-branding" : "with-branding";
115
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
113
116
  const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
114
117
  const mergedClassName = twMerge(
115
118
  defaultTailwindClassName,
@@ -117,7 +120,6 @@ var BaseCopilotTextarea = React.forwardRef(
117
120
  );
118
121
  return `${baseClassName} ${brandingClass} ${mergedClassName}`;
119
122
  })();
120
- usePopulateCopilotTextareaRef(editor, ref);
121
123
  return /* @__PURE__ */ jsx(Slate, {
122
124
  editor,
123
125
  initialValue,
@@ -158,4 +160,4 @@ function makeSemiFakeReactTextAreaEvent(currentText) {
158
160
 
159
161
  export { BaseCopilotTextarea };
160
162
  //# sourceMappingURL=out.js.map
161
- //# sourceMappingURL=chunk-M6QFKIBE.mjs.map
163
+ //# sourceMappingURL=chunk-QZ2PN6ZU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"names":["_a","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AA4KhB;AA/ID,IAAM,sBAAsB,MAAM;AAAA,EACvC,CACE,OAGA,QACgB;AAChB,UAAM,wBAAmD,kCACpD,mCACA,MAAM;AAGX,UAAM,uBAAuB,QAAQ,MAAG;AA5C5C,UAAAA;AA4C+C,cAAAA,MAAA,MAAM,UAAN,OAAAA,MAAe;AAAA,OAAI,CAAC,CAAC;AAChE,UAAM,CAAC,yBAAyB,0BAA0B,IACxD,SAAS,oBAAoB;AAE/B,UAAM,eAA6B,QAAQ,MAAM;AAC/C,aAAO;AAAA,QACL;AAAA,UACE,MAAM;AAAA,UACN,UAAU,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,GAAG,CAAC,oBAAoB,CAAC;AAEzB,UAAM,SAAS,yBAAyB;AAExC,UAAM,aAAa;AAAA,MACjB,CAAC,mBAAwC;AACvC,eAAO,WAAW,QAAQ,eAAe,MAAM;AAAA,UAC7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{ 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 getTextAroundCursor,\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 {\n AutosuggestionsBareFunction,\n BaseAutosuggestionsConfig,\n defaultBaseAutosuggestionsConfig,\n} 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 { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\n\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n value: string;\n focus: () => void;\n blur: () => void;\n}\n\nexport const BaseCopilotTextarea = React.forwardRef(\n (\n props: BaseCopilotTextareaProps & {\n autosuggestionsFunction: AutosuggestionsBareFunction;\n },\n ref: React.Ref<HTMLCopilotTextAreaElement>\n ): JSX.Element => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.autosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] =\n useState(valueOnInitialRender);\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 insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor]\n );\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.acceptAutosuggestionKey,\n props.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n autosuggestionsConfig.disabled\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 onValueChange,\n autosuggestionsConfig: autosuggestionsConfigFromProps,\n autosuggestionsFunction,\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(\n defaultTailwindClassName,\n className ?? \"\"\n );\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCursor(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(fullEditorText);\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\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"]}
@@ -1,4 +1,4 @@
1
- export { BaseCopilotTextarea } from '../../chunk-M6QFKIBE.mjs';
1
+ export { BaseCopilotTextarea } from '../../chunk-QZ2PN6ZU.mjs';
2
2
  import '../../chunk-HZGSG7ST.mjs';
3
3
  import '../../chunk-UW3ITU2Y.mjs';
4
4
  import '../../chunk-CSGFJU3L.mjs';
@@ -1,9 +1,9 @@
1
- export { CopilotTextarea } from '../../chunk-DRXBRCHN.mjs';
1
+ export { CopilotTextarea } from '../../chunk-K3P3PCV7.mjs';
2
2
  import '../../chunk-4ES2IIB6.mjs';
3
3
  import '../../chunk-SL4J5HMW.mjs';
4
4
  import '../../chunk-LGK56BTO.mjs';
5
5
  import '../../chunk-3A2CNIG5.mjs';
6
- import '../../chunk-M6QFKIBE.mjs';
6
+ import '../../chunk-QZ2PN6ZU.mjs';
7
7
  import '../../chunk-HZGSG7ST.mjs';
8
8
  import '../../chunk-UW3ITU2Y.mjs';
9
9
  import '../../chunk-CSGFJU3L.mjs';
@@ -1,10 +1,10 @@
1
1
  import '../chunk-MMVDU6DF.mjs';
2
- export { CopilotTextarea } from '../chunk-DRXBRCHN.mjs';
2
+ export { CopilotTextarea } from '../chunk-K3P3PCV7.mjs';
3
3
  import '../chunk-4ES2IIB6.mjs';
4
4
  import '../chunk-SL4J5HMW.mjs';
5
5
  import '../chunk-LGK56BTO.mjs';
6
6
  import '../chunk-3A2CNIG5.mjs';
7
- export { BaseCopilotTextarea } from '../chunk-M6QFKIBE.mjs';
7
+ export { BaseCopilotTextarea } from '../chunk-QZ2PN6ZU.mjs';
8
8
  import '../chunk-HZGSG7ST.mjs';
9
9
  import '../chunk-UW3ITU2Y.mjs';
10
10
  import '../chunk-CSGFJU3L.mjs';
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import './chunk-DE5K76I2.mjs';
2
2
  import './chunk-WADHCMPK.mjs';
3
3
  import './chunk-MMVDU6DF.mjs';
4
- export { CopilotTextarea } from './chunk-DRXBRCHN.mjs';
4
+ export { CopilotTextarea } from './chunk-K3P3PCV7.mjs';
5
5
  import './chunk-4ES2IIB6.mjs';
6
6
  import './chunk-SL4J5HMW.mjs';
7
7
  export { defaultAutosuggestionsConfig, defaultFewShotMessages, defaultMakeSystemPrompt } from './chunk-LGK56BTO.mjs';
8
8
  export { ChatlikeApiEndpoint } from './chunk-3A2CNIG5.mjs';
9
- export { BaseCopilotTextarea } from './chunk-M6QFKIBE.mjs';
9
+ export { BaseCopilotTextarea } from './chunk-QZ2PN6ZU.mjs';
10
10
  import './chunk-HZGSG7ST.mjs';
11
11
  import './chunk-UW3ITU2Y.mjs';
12
12
  import './chunk-CSGFJU3L.mjs';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.15.0",
7
+ "version": "0.15.1",
8
8
  "sideEffects": [
9
9
  "**/*.css"
10
10
  ],
@@ -99,8 +99,6 @@ export const BaseCopilotTextarea = React.forwardRef(
99
99
  };
100
100
  }, [props.suggestionsStyle]);
101
101
 
102
- useAddBrandingCss(suggestionStyleAugmented, props.disableBranding);
103
-
104
102
  const renderElementMemoized = useMemo(() => {
105
103
  return makeRenderElementFunction(suggestionStyleAugmented);
106
104
  }, [suggestionStyleAugmented]);
@@ -139,14 +137,16 @@ export const BaseCopilotTextarea = React.forwardRef(
139
137
  className,
140
138
  onChange,
141
139
  onKeyDown,
140
+ disableBranding,
142
141
  ...propsToForward
143
142
  } = props;
144
143
 
144
+ useAddBrandingCss(suggestionStyleAugmented, disableBranding);
145
+ usePopulateCopilotTextareaRef(editor, ref);
146
+
145
147
  const moddedClassName = (() => {
146
148
  const baseClassName = "copilot-textarea";
147
- const brandingClass = props.disableBranding
148
- ? "no-branding"
149
- : "with-branding";
149
+ const brandingClass = disableBranding ? "no-branding" : "with-branding";
150
150
  const defaultTailwindClassName = "bg-white overflow-y-auto resize-y";
151
151
  const mergedClassName = twMerge(
152
152
  defaultTailwindClassName,
@@ -155,8 +155,6 @@ export const BaseCopilotTextarea = React.forwardRef(
155
155
  return `${baseClassName} ${brandingClass} ${mergedClassName}`;
156
156
  })();
157
157
 
158
- usePopulateCopilotTextareaRef(editor, ref);
159
-
160
158
  return (
161
159
  <Slate
162
160
  editor={editor}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/base-copilot-textarea/base-copilot-textarea.tsx"],"names":["_a","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,SAAS,aAAa,WAAW,SAAS,gBAAgB;AACjE,SAAqB,cAAc;AACnC,SAAS,UAAU,aAAa;AAChC,SAAS,eAAe;AA8KhB;AAjJD,IAAM,sBAAsB,MAAM;AAAA,EACvC,CACE,OAGA,QACgB;AAChB,UAAM,wBAAmD,kCACpD,mCACA,MAAM;AAGX,UAAM,uBAAuB,QAAQ,MAAG;AA5C5C,UAAAA;AA4C+C,cAAAA,MAAA,MAAM,UAAN,OAAAA,MAAe;AAAA,OAAI,CAAC,CAAC;AAChE,UAAM,CAAC,yBAAyB,0BAA0B,IACxD,SAAS,oBAAoB;AAE/B,UAAM,eAA6B,QAAQ,MAAM;AAC/C,aAAO;AAAA,QACL;AAAA,UACE,MAAM;AAAA,UACN,UAAU,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF,GAAG,CAAC,oBAAoB,CAAC;AAEzB,UAAM,SAAS,yBAAyB;AAExC,UAAM,aAAa;AAAA,MACjB,CAAC,mBAA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A,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 getTextAroundCursor,\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 {\n AutosuggestionsBareFunction,\n BaseAutosuggestionsConfig,\n defaultBaseAutosuggestionsConfig,\n} 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 { makeRenderElementFunction } from \"./render-element\";\nimport { makeRenderPlaceholderFunction } from \"./render-placeholder\";\nimport { useAddBrandingCss } from \"./use-add-branding-css\";\n\nexport interface HTMLCopilotTextAreaElement extends HTMLElement {\n value: string;\n focus: () => void;\n blur: () => void;\n}\n\nexport const BaseCopilotTextarea = React.forwardRef(\n (\n props: BaseCopilotTextareaProps & {\n autosuggestionsFunction: AutosuggestionsBareFunction;\n },\n ref: React.Ref<HTMLCopilotTextAreaElement>\n ): JSX.Element => {\n const autosuggestionsConfig: BaseAutosuggestionsConfig = {\n ...defaultBaseAutosuggestionsConfig,\n ...props.autosuggestionsConfig,\n };\n\n const valueOnInitialRender = useMemo(() => props.value ?? \"\", []);\n const [lastKnownFullEditorText, setLastKnownFullEditorText] =\n useState(valueOnInitialRender);\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 insertText = useCallback(\n (autosuggestion: AutosuggestionState) => {\n Editor.insertText(editor, autosuggestion.text, {\n at: autosuggestion.point,\n });\n },\n [editor]\n );\n\n const {\n currentAutocompleteSuggestion,\n onChangeHandler: onChangeHandlerForAutocomplete,\n onKeyDownHandler: onKeyDownHandlerForAutocomplete,\n } = useAutosuggestions(\n autosuggestionsConfig.debounceTime,\n autosuggestionsConfig.acceptAutosuggestionKey,\n props.autosuggestionsFunction,\n insertText,\n autosuggestionsConfig.disableWhenEmpty,\n autosuggestionsConfig.disabled\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 useAddBrandingCss(suggestionStyleAugmented, props.disableBranding);\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 onValueChange,\n autosuggestionsConfig: autosuggestionsConfigFromProps,\n autosuggestionsFunction,\n className,\n onChange,\n onKeyDown,\n ...propsToForward\n } = props;\n\n const moddedClassName = (() => {\n const baseClassName = \"copilot-textarea\";\n const brandingClass = props.disableBranding\n ? \"no-branding\"\n : \"with-branding\";\n const defaultTailwindClassName = \"bg-white overflow-y-auto resize-y\";\n const mergedClassName = twMerge(\n defaultTailwindClassName,\n className ?? \"\"\n );\n return `${baseClassName} ${brandingClass} ${mergedClassName}`;\n })();\n\n usePopulateCopilotTextareaRef(editor, ref);\n\n return (\n <Slate\n editor={editor}\n initialValue={initialValue}\n onChange={(value) => {\n const newEditorState = getTextAroundCursor(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(fullEditorText);\n onChangeHandlerForAutocomplete(newEditorState);\n\n props.onValueChange?.(fullEditorText);\n props.onChange?.(makeSemiFakeReactTextAreaEvent(fullEditorText));\n }}\n >\n <Editable\n renderElement={renderElementMemoized}\n renderPlaceholder={renderPlaceholderMemoized}\n onKeyDown={(event) => {\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"]}