Skip to content

feat(editor): migrate code block to vue #1806

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 4 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion e2e/shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="cypress" />
/// <reference types="vite/client" />

import type { Editor } from '@milkdown/core'
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/crepe/latex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test'
import { focusEditor, getMarkdown } from 'tests/misc'
import { focusEditor, getMarkdown } from '../misc'

test.beforeEach(async ({ page }) => {
await page.goto('/crepe/')
Expand All @@ -10,7 +10,7 @@ test('latex block preview toggle', async ({ page }) => {
await page.keyboard.type('$$')
await page.keyboard.press('Enter')

const codeBlock = page.locator('milkdown-code-block')
const codeBlock = page.locator('.milkdown-code-block')
const codemirror = codeBlock.locator('.codemirror-host')
const preview = codeBlock.locator('.preview')
const codeTools = codeBlock.locator('.tools')
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/crepe/listener.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test'
import { focusEditor } from 'tests/misc'
import { focusEditor } from '../misc'

test('listen change before editor is created', async ({ page }) => {
await page.addInitScript(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/__internal__/components/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function Icon({ icon, class: className }: IconProps) {
class={clsx('milkdown-icon', className)}
ref={(el) => {
if (el && icon) {
;(el as HTMLElement).innerHTML = icon
;(el as HTMLElement).innerHTML = icon.trim()
}
}}
/>
Expand Down
18 changes: 7 additions & 11 deletions packages/components/src/code-block/config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { $ctx } from '@milkdown/utils'
import type { Extension } from '@codemirror/state'
import type { LanguageDescription } from '@codemirror/language'
import { html } from 'atomico'
import { withMeta } from '../__internal__/meta'

export interface CodeBlockConfig {
extensions: Extension[]
languages: LanguageDescription[]
expandIcon: () => ReturnType<typeof html> | string
searchIcon: () => ReturnType<typeof html> | string
clearSearchIcon: () => ReturnType<typeof html> | string
expandIcon: () => string
searchIcon: () => string
clearSearchIcon: () => string
searchPlaceholder: string
noResultText: string
renderLanguage: (
language: string,
selected: boolean
) => ReturnType<typeof html>
renderLanguage: (language: string, selected: boolean) => string
renderPreview: (
language: string,
content: string
) => null | string | HTMLElement
previewToggleButton: (previewOnlyMode: boolean) => ReturnType<typeof html>
previewLabel: () => ReturnType<typeof html>
previewToggleButton: (previewOnlyMode: boolean) => string
previewLabel: () => string
}

export const defaultConfig: CodeBlockConfig = {
Expand All @@ -32,7 +28,7 @@ export const defaultConfig: CodeBlockConfig = {
clearSearchIcon: () => '⌫',
searchPlaceholder: 'Search language',
noResultText: 'No result',
renderLanguage: (language) => html`${language}`,
renderLanguage: (language) => language,
renderPreview: () => null,
previewToggleButton: (previewOnlyMode) => (previewOnlyMode ? 'Edit' : 'Hide'),
previewLabel: () => 'Preview',
Expand Down
282 changes: 0 additions & 282 deletions packages/components/src/code-block/view/component.ts

This file was deleted.

Loading