Skip to content

Commit 8564fc8

Browse files
feat: revert css injection (CopilotKit#585)
* Revert "feat: inject minified css in bundle (CopilotKit#560)" This reverts commit c2963a0. * fix import * regenerate package lock
1 parent b4c3f29 commit 8564fc8

24 files changed

Lines changed: 469 additions & 1654 deletions

File tree

CopilotKit/examples/next-openai/src/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import "../styles/globals.css";
2+
import "@copilotkit/react-ui/styles.css";
3+
import "@copilotkit/react-textarea/styles.css";
24

35
export default function RootLayout({ children }: { children: React.ReactNode }) {
46
return (

CopilotKit/packages/react-textarea/package.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,20 @@
4040
"devDependencies": {
4141
"@types/jest": "^29.5.4",
4242
"@types/lodash.merge": "^4.6.7",
43-
"@types/postcss-import": "^14.0.3",
44-
"@types/postcss-prefix-selector": "^1.16.3",
4543
"@types/react": "^18.2.5",
4644
"@types/react-dom": "^18.2.4",
4745
"@types/react-syntax-highlighter": "^15.5.7",
48-
"autoprefixer": "^10.4.13",
49-
"cssnano": "^7.0.6",
5046
"eslint": "^8.56.0",
5147
"eslint-config-custom": "workspace:*",
5248
"jest": "^29.6.4",
53-
"postcss": "^8.4.40",
54-
"postcss-import": "^16.1.0",
55-
"postcss-nested": "^6.2.0",
49+
"postcss": "^8.4.20",
5650
"postcss-prefix-selector": "^1.16.1",
5751
"react": "^18.2.0",
5852
"tailwind-config": "workspace:*",
59-
"tailwindcss": "3.3.2",
53+
"tailwindcss": "^3.3.0",
6054
"ts-jest": "^29.1.1",
6155
"tsconfig": "workspace:*",
62-
"tsup-async-inject-style": "0.0.2",
56+
"tsup": "^6.7.0",
6357
"typescript": "^5.2.3"
6458
},
6559
"dependencies": {
@@ -69,6 +63,7 @@
6963
"@emotion/css": "^11.11.2",
7064
"@emotion/react": "^11.11.1",
7165
"@emotion/styled": "^11.11.0",
66+
"@mui/material": "^5.14.11",
7267
"@radix-ui/react-dialog": "^1.1.1",
7368
"@radix-ui/react-label": "^2.0.2",
7469
"@radix-ui/react-separator": "^1.0.3",
@@ -80,7 +75,6 @@
8075
"lucide-react": "^0.274.0",
8176
"material-icons": "^1.13.10",
8277
"react-dom": "^18.2.0",
83-
"react-icons": "^5.3.0",
8478
"slate": "^0.94.1",
8579
"slate-history": "^0.93.0",
8680
"slate-react": "^0.98.1",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.copilot-textarea.with-branding::after {
2+
content: ''; /* Initially empty because we overrdie this CSS dynamically and we want to avoid flashing */
3+
position: absolute;
4+
}
5+
6+
7+
.copilot-textarea.no-branding::after {
8+
content: '';
9+
}

CopilotKit/packages/react-textarea/src/components/base-copilot-textarea/base-copilot-textarea.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { replaceEditorText } from "../../lib/slatejs-edits/replace-text";
1515
import { BaseAutosuggestionsConfig, defaultBaseAutosuggestionsConfig } from "../../types/base";
1616
import { AutosuggestionState } from "../../types/base/autosuggestion-state";
1717
import { BaseCopilotTextareaProps } from "../../types/base/base-copilot-textarea-props";
18+
import "./base-copilot-textarea.css";
1819
import { HoveringToolbar } from "../hovering-toolbar/hovering-toolbar";
1920
import { makeRenderElementFunction } from "./render-element";
2021
import { makeRenderPlaceholderFunction } from "./render-placeholder";

CopilotKit/packages/react-textarea/src/components/copilot-textarea/copilot-textarea.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*
1414
* ```tsx
1515
* import { CopilotTextarea } from '@copilotkit/react-textarea';
16+
* import "@copilotkit/react-textarea/styles.css";
17+
*
1618
* <CopilotTextarea
1719
* autosuggestionsConfig={{
1820
* textareaPurpose:
@@ -42,6 +44,8 @@
4244
* ```tsx
4345
* import { useState } from "react";
4446
* import { CopilotTextarea } from "@copilotkit/react-textarea";
47+
* import "@copilotkit/react-textarea/styles.css";
48+
*
4549
* export function ExampleComponent() {
4650
* const [text, setText] = useState("");
4751
*
@@ -68,8 +72,10 @@
6872
* ### Look & Feel
6973
*
7074
* By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
71-
* ```tsx fileName="YourRootComponent.tsx"
75+
* ```tsx fileName="YourRootComponent.tsx" {2}
7276
* ...
77+
* import "@copilotkit/react-textarea/styles.css";
78+
*
7379
* export function YourRootComponent() {
7480
* return (
7581
* <CopilotKit>

CopilotKit/packages/react-textarea/src/components/hovering-toolbar/hovering-toolbar-components.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ export const Button = React.forwardRef(
3636
),
3737
);
3838

39+
export const Icon = React.forwardRef(
40+
({ className, ...props }: PropsWithChildren<BaseProps>, ref: Ref<HTMLSpanElement | null>) => (
41+
<span
42+
{...props}
43+
ref={ref as Ref<HTMLSpanElement>}
44+
className={cx(
45+
"material-icons",
46+
className,
47+
css`
48+
font-size: 18px;
49+
vertical-align: text-bottom;
50+
`,
51+
)}
52+
/>
53+
),
54+
);
55+
3956
export const Menu = React.forwardRef(
4057
({ className, ...props }: PropsWithChildren<BaseProps>, ref: Ref<HTMLDivElement | null>) => {
4158
return (

CopilotKit/packages/react-textarea/src/components/hovering-toolbar/text-insertion-prompt-box/hovering-insertion-prompt-box-core.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Label } from "../../ui/label";
1010
import { useCallback, useEffect, useRef, useState } from "react";
1111

1212
import { streamPromiseFlatten } from "../../../lib/stream-promise-flatten";
13+
import { IncludedFilesPreview } from "./included-files-preview";
1314
import { useHoveringEditorContext } from "../hovering-editor-provider";
14-
import { MdArrowForward, MdCheck } from "react-icons/md";
1515

1616
export type SuggestionState = {
1717
editorState: EditingEditorState;
@@ -190,7 +190,7 @@ export const HoveringInsertionPromptBoxCore = ({
190190
onClick={beginGeneratingAdjustment}
191191
className="absolute right-2 bg-blue-500 text-white w-8 h-8 rounded-full flex items-center justify-center"
192192
>
193-
<MdArrowForward className="text-2xl" />
193+
<i className="material-icons">arrow_forward</i>
194194
</button>
195195
</div>
196196
</>
@@ -207,7 +207,7 @@ export const HoveringInsertionPromptBoxCore = ({
207207
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]"
208208
role="status"
209209
>
210-
<span className="absolute -m-px h-px w-px overflow-hidden whitespace-nowrap border-0 p-0 [clip:rect(0,0,0,0)]">
210+
<span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">
211211
Loading...
212212
</span>
213213
</div>
@@ -234,7 +234,7 @@ export const HoveringInsertionPromptBoxCore = ({
234234
performInsertion(editSuggestion);
235235
}}
236236
>
237-
Insert <MdCheck className="text-2xl" />
237+
Insert <i className="material-icons">check</i>
238238
</Button>
239239
</div>
240240
);
@@ -249,6 +249,9 @@ export const HoveringInsertionPromptBoxCore = ({
249249
return (
250250
<div className="w-full flex flex-col items-start relative gap-2">
251251
{AdjustmentPromptComponent}
252+
{filePointers.length > 0 && (
253+
<IncludedFilesPreview includedFiles={filePointers} setIncludedFiles={setFilePointers} />
254+
)}
252255
{sourceSearchWord !== undefined && (
253256
<SourceSearchBox
254257
searchTerm={sourceSearchWord}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { DocumentPointer } from "@copilotkit/react-core";
2+
import { Label } from "../../ui/label";
3+
import React from "react";
4+
import Chip from "@mui/material/Chip/Chip.js";
5+
import Avatar from "@mui/material/Avatar/Avatar.js";
6+
7+
export interface IncludedFilesPreviewProps {
8+
includedFiles: DocumentPointer[];
9+
setIncludedFiles: React.Dispatch<React.SetStateAction<DocumentPointer[]>>;
10+
}
11+
12+
export const IncludedFilesPreview = ({
13+
includedFiles,
14+
setIncludedFiles,
15+
}: IncludedFilesPreviewProps) => {
16+
return (
17+
<div className="flex flex-col gap-2 mt-2">
18+
<Label className="">Included context:</Label>
19+
<div className="flex flex-wrap gap-2">
20+
{includedFiles.map((filePointer, index) => {
21+
return (
22+
<FileChipPreview
23+
key={`file-${filePointer.sourceApplication}.${filePointer.name}`}
24+
filePointer={filePointer}
25+
onDelete={() => {
26+
setIncludedFiles((prev) => prev.filter((fp) => fp !== filePointer));
27+
}}
28+
/>
29+
);
30+
})}
31+
</div>
32+
</div>
33+
);
34+
};
35+
36+
export interface FileChipPreviewProps {
37+
filePointer: DocumentPointer;
38+
onDelete: () => void;
39+
}
40+
41+
export const FileChipPreview = ({ filePointer, onDelete }: FileChipPreviewProps) => {
42+
return (
43+
<Chip
44+
label={filePointer.name}
45+
onDelete={onDelete}
46+
avatar={
47+
<Avatar
48+
src={filePointer.iconImageUri}
49+
alt={filePointer.sourceApplication}
50+
sx={{ backgroundColor: "transparent" }}
51+
></Avatar>
52+
}
53+
/>
54+
);
55+
};
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
@tailwind utilities;
2-
3-
.copilot-textarea.with-branding::after {
4-
content: ''; /* Initially empty because we overrdie this CSS dynamically and we want to avoid flashing */
5-
position: absolute;
6-
}
1+
@import url("material-icons/iconfont/material-icons.css");
72

8-
.copilot-textarea.no-branding::after {
9-
content: '';
10-
}
3+
@tailwind utilities;
Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,16 @@
1-
import path from "path";
2-
import fs from "fs";
3-
import { defineConfig, Options } from "tsup-async-inject-style";
4-
import postcss from "postcss";
5-
import autoprefixer from "autoprefixer";
6-
import tailwindcss from "tailwindcss";
7-
import cssnano from "cssnano";
8-
import postcssPrefixSelector from "postcss-prefix-selector";
9-
import postcssImport from "postcss-import";
10-
import postcssNested from "postcss-nested";
1+
import { defineConfig, Options } from "tsup";
112

12-
export default defineConfig((options: Options) => {
13-
return {
14-
entry: ["src/**/*.ts", "src/**/*.tsx"],
15-
format: ["esm", "cjs"],
16-
dts: true,
17-
minify: false,
18-
external: ["react"],
19-
splitting: false,
20-
clean: true,
21-
sourcemap: true,
22-
exclude: [
23-
"**/*.test.ts", // Exclude TypeScript test files
24-
"**/*.test.tsx", // Exclude TypeScript React test files
25-
"**/__tests__/*", // Exclude any files inside a __tests__ directory
26-
],
27-
onSuccess: async () => {
28-
// Create index.css file for backwards compatibility
29-
fs.writeFileSync(
30-
path.resolve(process.cwd(), "dist/index.css"),
31-
`/* This is here for backwards compatibility */`,
32-
);
33-
},
34-
injectStyle: async (_, filePath) => {
35-
const cwd = process.cwd();
36-
const outputPath = path.resolve(cwd, "dist/index.css");
37-
const rawCSS = fs.readFileSync(filePath, "utf8");
38-
39-
const resultCSS = await postcss([
40-
postcssImport(),
41-
postcssNested(),
42-
postcssPrefixSelector({
43-
prefix: ".copilot-kit-textarea-css-scope",
44-
}),
45-
tailwindcss,
46-
autoprefixer,
47-
cssnano({ preset: "default" }),
48-
]).process(rawCSS, { from: filePath, to: outputPath });
49-
50-
if (resultCSS.css === undefined) {
51-
throw new Error("No CSS output");
52-
}
53-
54-
return `
55-
if (globalThis.hasOwnProperty("document")) {
56-
const style = document?.createElement("style");
57-
style.innerHTML = '${resultCSS}';
58-
document?.head.appendChild(style);
59-
}
60-
`;
61-
},
62-
...options,
63-
};
64-
});
3+
export default defineConfig((options: Options) => ({
4+
entry: ["src/**/*.{ts,tsx}"],
5+
format: ["esm", "cjs"],
6+
dts: true,
7+
minify: false,
8+
external: ["react"],
9+
sourcemap: true,
10+
exclude: [
11+
"**/*.test.ts", // Exclude TypeScript test files
12+
"**/*.test.tsx", // Exclude TypeScript React test files
13+
"**/__tests__/*", // Exclude any files inside a __tests__ directory
14+
],
15+
...options,
16+
}));

0 commit comments

Comments
 (0)