-
-
Notifications
You must be signed in to change notification settings - Fork 93
Replace react with preact #3221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { Config } from "jest"; | ||
| import { preactModuleNameMapper } from "@cursorless/common"; | ||
|
|
||
| const config: Config = { | ||
| preset: "ts-jest", | ||
| testEnvironment: "jsdom", | ||
| moduleNameMapper: { | ||
| ...preactModuleNameMapper, | ||
| "^@cursorless/cheatsheet$": "<rootDir>/../cheatsheet/src/index.ts", | ||
| "\\.(css|scss)$": "<rootDir>/src/test/styleMock.ts", | ||
| }, | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,36 @@ | ||
| import { render } from "@testing-library/react"; | ||
| import { fakeCheatsheetInfo } from "@cursorless/cheatsheet"; | ||
| import { render } from "preact"; | ||
| import { act } from "preact/test-utils"; | ||
| import { App } from "./app"; | ||
|
|
||
| describe("App", () => { | ||
| it("should render successfully", () => { | ||
| const { baseElement } = render(<App />); | ||
| beforeEach(() => { | ||
| document.cheatsheetInfo = fakeCheatsheetInfo; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| expect(baseElement).toBeTruthy(); | ||
| it("should render successfully", async () => { | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
|
|
||
| await act(() => { | ||
| render(<App />, container); | ||
| }); | ||
|
|
||
| expect(container).toBeTruthy(); | ||
| }); | ||
|
|
||
| it("should have a greeting as the title", () => { | ||
| const { getByText } = render(<App />); | ||
| it("should have a greeting as the title", async () => { | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
|
|
||
| await act(() => { | ||
| render(<App />, container); | ||
| }); | ||
|
|
||
| expect(getByText(/Welcome cheatsheet-local/gi)).toBeTruthy(); | ||
| expect(container.textContent).toMatch(/Cursorless Cheatsheet/gi); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| import { StrictMode } from "react"; | ||
| import * as ReactDOM from "react-dom/client"; | ||
| import { render } from "preact"; | ||
| import { StrictMode } from "preact/compat"; | ||
| import { App } from "./app/app"; | ||
|
|
||
| const root = ReactDOM.createRoot( | ||
| document.getElementById("root") as HTMLElement, | ||
| ); | ||
| root.render( | ||
| render( | ||
| <StrictMode> | ||
| <App /> | ||
| </StrictMode>, | ||
| getRoot(), | ||
| ); | ||
|
|
||
| function getRoot() { | ||
| const root = document.getElementById("root"); | ||
| if (root == null) { | ||
| throw new Error("Missing root container"); | ||
| } | ||
| return root; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import type { Config } from "jest"; | ||
| import { preactModuleNameMapper } from "@cursorless/common"; | ||
|
|
||
| const config: Config = { | ||
| preset: "ts-jest", | ||
| testEnvironment: "jsdom", | ||
| moduleNameMapper: preactModuleNameMapper, | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| import { render } from "@testing-library/react"; | ||
| import { render } from "preact"; | ||
| import { act } from "preact/test-utils"; | ||
| import { CheatsheetPage } from "./CheatsheetPage"; | ||
| import { fakeCheatsheetInfo } from "./fakeCheatsheetInfo"; | ||
|
|
||
| describe("Cheatsheet", () => { | ||
| it("should render successfully", () => { | ||
| const { baseElement } = render( | ||
| <CheatsheetPage cheatsheetInfo={fakeCheatsheetInfo} />, | ||
| ); | ||
| expect(baseElement).toBeTruthy(); | ||
| afterEach(() => { | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| it("should render successfully", async () => { | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
|
|
||
| await act(() => { | ||
| render(<CheatsheetPage cheatsheetInfo={fakeCheatsheetInfo} />, container); | ||
| }); | ||
|
|
||
| expect(container).toBeTruthy(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/cheatsheet/src/lib/components/CheatsheetListComponent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/cheatsheet/src/lib/components/CheatsheetNotesComponent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/cheatsheet/src/lib/components/formatCaptures.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { render } from "preact"; | ||
| import { act } from "preact/test-utils"; | ||
| import { formatCaptures } from "./formatCaptures"; | ||
|
|
||
| describe("formatCaptures", () => { | ||
| afterEach(() => { | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| it("formats capture placeholders", async () => { | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
|
|
||
| await act(() => { | ||
| render(<div>{formatCaptures("hello <target> world")}</div>, container); | ||
| }); | ||
|
|
||
| expect(container.textContent).toBe("hello [target] world"); | ||
| expect(container.querySelector('a[href="#legend"]')).not.toBeNull(); | ||
| }); | ||
|
|
||
| it("leaves malformed captures as plain text", async () => { | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
| const input = "<<=<=<="; | ||
|
|
||
| await act(() => { | ||
| render(<div>{formatCaptures(input)}</div>, container); | ||
| }); | ||
|
|
||
| expect(container.textContent).toBe(input); | ||
| expect(container.querySelector('a[href="#legend"]')).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,48 @@ | ||
| import reactStringReplace from "react-string-replace"; | ||
| import type { ComponentChildren } from "preact"; | ||
| import SmartLink from "./SmartLink"; | ||
|
|
||
| export function formatCaptures(input: string) { | ||
| return reactStringReplace(input, captureRegex, (match, i) => { | ||
| const parts: ComponentChildren[] = []; | ||
| let lastIndex = 0; | ||
|
|
||
| for (const match of input.matchAll(captureRegex)) { | ||
|
|
||
| const [fullMatch, capture] = match; | ||
| const index = match.index ?? 0; | ||
|
|
||
| if (index > lastIndex) { | ||
| parts.push(input.slice(lastIndex, index)); | ||
| } | ||
|
|
||
| const innerElement = | ||
| match === "ordinal" ? ( | ||
| capture === "ordinal" ? ( | ||
| <span> | ||
| n<sup>th</sup> | ||
| </span> | ||
| ) : ( | ||
| match | ||
| capture | ||
| ); | ||
|
|
||
| return ( | ||
| parts.push( | ||
| <span | ||
| key={i} | ||
| key={index} | ||
| className="inline-block rounded-md bg-[#8686864C] p-[2px] text-[#000000E3] dark:bg-[#FFFFFF33] dark:text-[#FFFFFFE3]" | ||
| > | ||
| <SmartLink to="#legend" noFormatting={true}> | ||
| {"["} | ||
| {innerElement} | ||
| {"]"} | ||
| </SmartLink> | ||
| </span> | ||
| </span>, | ||
| ); | ||
| }); | ||
|
|
||
| lastIndex = index + fullMatch.length; | ||
| } | ||
|
|
||
| if (lastIndex < input.length) { | ||
| parts.push(input.slice(lastIndex)); | ||
| } | ||
|
|
||
| return parts; | ||
| } | ||
|
|
||
| const captureRegex = /<([^>]+)>/g; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.