-
Notifications
You must be signed in to change notification settings - Fork 12
feat(sanity-plugin-markdown): migrate styling to vanilla-extract #1844
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
Open
stipsan
wants to merge
4
commits into
main
Choose a base branch
from
cursor/migrate-markdown-vanilla-extract-dd27
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
82d4ed3
feat(sanity-plugin-markdown): migrate styling to vanilla-extract
cursoragent 7d784c5
Merge branch 'main' into cursor/migrate-markdown-vanilla-extract-dd27
cursoragent 00479cf
fix(sanity-plugin-markdown): keep /next CSS-free and merge style props
cursoragent 996745c
fix(sanity-plugin-markdown): align sanity peer resolution
cursoragent 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,5 @@ | ||
| --- | ||
| "sanity-plugin-markdown": patch | ||
| --- | ||
|
|
||
| Migrate styling from styled-components to vanilla-extract (zero-runtime CSS) |
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
79 changes: 79 additions & 0 deletions
79
plugins/sanity-plugin-markdown/src/components/MarkdownInput.css.ts
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,79 @@ | ||
| import {createVar, globalStyle, style} from '@vanilla-extract/css' | ||
|
|
||
| export const fgVar = createVar() | ||
| export const borderVar = createVar() | ||
| export const bgVar = createVar() | ||
| export const selectionHoveredBgVar = createVar() | ||
|
|
||
| export const markdownInput = style({}) | ||
|
|
||
| globalStyle(`${markdownInput} .CodeMirror.CodeMirror`, { | ||
| color: fgVar, | ||
| borderColor: borderVar, | ||
| backgroundColor: 'inherit', | ||
| }) | ||
|
|
||
| globalStyle(`${markdownInput} .cm-s-easymde .CodeMirror-cursor`, { | ||
| borderColor: fgVar, | ||
| }) | ||
|
|
||
| globalStyle(`${markdownInput} .editor-toolbar, ${markdownInput} .editor-preview-side`, { | ||
| borderColor: borderVar, | ||
| }) | ||
|
|
||
| globalStyle( | ||
| `${markdownInput} .CodeMirror-focused .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected`, | ||
| { | ||
| backgroundColor: selectionHoveredBgVar, | ||
| }, | ||
| ) | ||
|
|
||
| globalStyle(`${markdownInput} .CodeMirror-selected.CodeMirror-selected.CodeMirror-selected`, { | ||
| backgroundColor: bgVar, | ||
| }) | ||
|
|
||
| globalStyle(`${markdownInput} .editor-toolbar > *`, { | ||
| color: fgVar, | ||
| }) | ||
|
|
||
| globalStyle( | ||
| [ | ||
| `${markdownInput} .editor-toolbar > .active`, | ||
| `${markdownInput} .editor-toolbar > button:hover`, | ||
| `${markdownInput} .editor-preview pre`, | ||
| `${markdownInput} .cm-s-easymde .cm-comment`, | ||
| ].join(', '), | ||
| { | ||
| backgroundColor: bgVar, | ||
| }, | ||
| ) | ||
|
|
||
| globalStyle(`${markdownInput} .editor-preview`, { | ||
| backgroundColor: bgVar, | ||
| }) | ||
|
|
||
| globalStyle( | ||
| [ | ||
| `${markdownInput} .editor-preview h1`, | ||
| `${markdownInput} .editor-preview h2`, | ||
| `${markdownInput} .editor-preview h3`, | ||
| `${markdownInput} .editor-preview h4`, | ||
| `${markdownInput} .editor-preview h5`, | ||
| `${markdownInput} .editor-preview h6`, | ||
| ].join(', '), | ||
| { | ||
| fontSize: 'revert', | ||
| }, | ||
| ) | ||
|
|
||
| globalStyle( | ||
| [`${markdownInput} .editor-preview ul`, `${markdownInput} .editor-preview li`].join(', '), | ||
| { | ||
| listStyle: 'revert', | ||
| padding: 'revert', | ||
| }, | ||
| ) | ||
|
|
||
| globalStyle(`${markdownInput} .editor-preview a`, { | ||
| textDecoration: 'revert', | ||
| }) |
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 was deleted.
Oops, something went wrong.
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,5 +1,5 @@ | ||
| { | ||
| "extends": ["@sanity/tsconfig/strictest"], | ||
| "include": ["**/*.ts", "**/*.tsx", "src/typings.d.ts"], | ||
| "include": ["**/*.ts", "**/*.tsx"], | ||
| "exclude": ["dist", "node_modules"] | ||
| } |
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,11 +1,37 @@ | ||
| import {defineConfig} from '@sanity/tsdown-config' | ||
| import type {UserConfig} from 'tsdown' | ||
| import type {TsdownPlugin, UserConfig} from 'tsdown' | ||
|
|
||
| export default defineConfig({ | ||
| entry: { | ||
| index: './src/index.ts', | ||
| next: './src/indexNext.ts', | ||
| /** | ||
| * `vanillaExtract: true` injects `import "sanity-plugin-markdown/bundle.css"` into every entry | ||
| * that transitively uses `.css.ts` styles. The `/next` entry must stay CSS-import-free for | ||
| * Next.js `pages` (see README) — consumers import easymde + bundle.css in `_app.tsx` instead. | ||
| */ | ||
| const stripBundleCssFromNextEntry = { | ||
| name: 'strip-bundle-css-from-next-entry', | ||
| generateBundle(_options, bundle) { | ||
| const chunk = bundle['next.js'] | ||
| if (chunk?.type !== 'chunk') return | ||
| chunk.code = chunk.code.replace(/^import ["']sanity-plugin-markdown\/bundle\.css["'];\n/, '') | ||
| }, | ||
| styledComponents: true, | ||
| reactCompiler: true, | ||
| }) satisfies Promise<UserConfig> | ||
| } satisfies TsdownPlugin | ||
|
|
||
| async function createConfig(): Promise<UserConfig> { | ||
| const config = await defineConfig({ | ||
| entry: { | ||
| index: './src/index.ts', | ||
| next: './src/indexNext.ts', | ||
| }, | ||
| reactCompiler: true, | ||
| vanillaExtract: true, | ||
| }) | ||
|
|
||
| return { | ||
| ...config, | ||
| plugins: [ | ||
| ...(Array.isArray(config.plugins) ? config.plugins : []), | ||
| stripBundleCssFromNextEntry, | ||
| ], | ||
| } | ||
| } | ||
|
|
||
| export default createConfig() |
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
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.