Skip to content
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
17 changes: 3 additions & 14 deletions dev/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ export class Generator {
generateWorkspaceFiles = async () => {
const filesToGenerate: [Path, (prev: string) => string][] = [
[this.workspace.join('tsconfig.json'), this.genProjectTsConfig, 'json'],
[
this.workspace.join('tsconfig.legacy.json'),
this.genPackageTsConfig.bind(this, this.workspace.getPackage('tvh')),
'json',
],
...this.workspace.packages
.filter((p) => p.isTsProject)
// This legacy is handled by tvh's tsconfig.legacy.json
.filter((p) => p.name !== 'tvh')
.map(
(p) =>
[
Expand Down Expand Up @@ -74,13 +67,9 @@ export class Generator {
modify(
prev,
['references'],
[
{ path: './tsconfig.legacy.json' },
...this.workspace.packages
.filter((p) => p.isTsProject)
.filter((p) => p.name !== 'tvh')
.map((p) => ({ path: p.path.relativePath })),
],
this.workspace.packages
.filter((p) => p.isTsProject)
.map((p) => ({ path: p.path.relativePath })),
{}
)
)
Expand Down
5 changes: 5 additions & 0 deletions docs/api/crepe.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ const config: CrepeConfig = {
}
```

> **Note**: The `onUpload` callback is used for both the click-to-upload button and drag-and-drop file uploads.
> Crepe has a built-in upload plugin (`@milkdown/plugin-upload`) that handles drag-and-drop and paste image uploads.
> When the `ImageBlock` feature is enabled, the upload plugin will use the `onUpload` from the image block configuration to process files and create `image-block` nodes.
> If no custom `onUpload` is provided, files will be converted to local blob URLs by default.

#### BlockEdit Feature

```typescript
Expand Down
5 changes: 5 additions & 0 deletions e2e/tests/input/ordered-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ test('ordered list with custom start number', async ({ page }) => {
await page.keyboard.type('3. First item')
await expect(editor.locator('ol li')).toHaveText('First item')
await expect(editor.locator('ol')).toHaveAttribute('start', '3')
await expect(editor.locator('ol li')).toHaveAttribute('data-label', '3.')
let markdown = await getMarkdown(page)
expect(markdown).toBe('3. First item\n')

await page.keyboard.press('Enter')
await page.keyboard.type('Second item')
await expect(editor.locator('ol li:last-child')).toHaveText('Second item')
await expect(editor.locator('ol li:last-child')).toHaveAttribute(
'data-label',
'4.'
)
markdown = await getMarkdown(page)
expect(markdown).toBe('3. First item\n4. Second item\n')
})
4 changes: 2 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"exclude": ["src/**/*.spec.ts"],
"references": [
{ "path": "../ctx" },
{ "path": "../exception" },
{ "path": "../prose" },
{ "path": "../transformer" },
{ "path": "../exception" }
{ "path": "../transformer" }
]
}
41 changes: 39 additions & 2 deletions packages/crepe/src/core/builder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { imageBlockConfig } from '@milkdown/kit/component/image-block'
import {
type DefaultValue,
defaultValueCtx,
Expand All @@ -16,14 +17,16 @@ import {
type ListenerManager,
} from '@milkdown/kit/plugin/listener'
import { trailing } from '@milkdown/kit/plugin/trailing'
import { upload, uploadConfig } from '@milkdown/kit/plugin/upload'
import { commonmark } from '@milkdown/kit/preset/commonmark'
import { gfm } from '@milkdown/kit/preset/gfm'
import { getMarkdown } from '@milkdown/kit/utils'

import type { CrepeFeature, CrepeFeatureConfig } from '../feature'
import type { CrepeFeatureConfig } from '../feature'
import type { DefineFeature } from '../feature/shared'

import { CrepeCtx, FeaturesCtx } from './slice'
import { CrepeFeature } from '../feature'
import { CrepeCtx, FeaturesCtx, useCrepeFeatures } from './slice'

/// The crepe builder configuration.
export interface CrepeBuilderConfig {
Expand Down Expand Up @@ -69,13 +72,47 @@ export class CrepeBuilder {
...value,
size: 4,
}))
ctx.update(uploadConfig.key, (prev) => ({
...prev,
uploader: async (files, schema, ctx) => {
const features = useCrepeFeatures(ctx).get()
const hasImageBlock = features.includes(CrepeFeature.ImageBlock)
const nodeType = hasImageBlock
? schema.nodes['image-block']
: schema.nodes['image']

if (!nodeType) return []

const onUpload = hasImageBlock
? ctx.get(imageBlockConfig.key).onUpload
: undefined

const images: File[] = []
for (let i = 0; i < files.length; i++) {
const file = files.item(i)
if (file && file.type.includes('image')) images.push(file)
}

const nodes = await Promise.all(
images.map(async (file) => {
const src = onUpload
? await onUpload(file)
: URL.createObjectURL(file)
return nodeType.createAndFill({ src })!
})
)

return nodes
},
}))
})
.use(commonmark)
.use(listener)
.use(history)
.use(indent)
.use(trailing)
.use(clipboard)
.use(upload)
.use(gfm)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/plugin-collab/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
},
"include": ["src"],
"references": [
{ "path": "../../exception" },
{ "path": "../../core" },
{ "path": "../../ctx" },
{ "path": "../../exception" },
{ "path": "../../prose" }
]
}
6 changes: 3 additions & 3 deletions packages/plugins/plugin-emoji/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
},
"include": ["src"],
"references": [
{ "path": "../../exception" },
{ "path": "../../utils" },
{ "path": "../../core" },
{ "path": "../../ctx" },
{ "path": "../../exception" },
{ "path": "../../prose" },
{ "path": "../../transformer" }
{ "path": "../../transformer" },
{ "path": "../../utils" }
]
}
4 changes: 2 additions & 2 deletions packages/plugins/plugin-indent/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"include": ["src"],
"references": [
{ "path": "../../utils" },
{ "path": "../../ctx" },
{ "path": "../../prose" }
{ "path": "../../prose" },
{ "path": "../../utils" }
]
}
4 changes: 2 additions & 2 deletions packages/plugins/plugin-prism/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"include": ["src"],
"references": [
{ "path": "../../utils" },
{ "path": "../../ctx" },
{ "path": "../../prose" }
{ "path": "../../prose" },
{ "path": "../../utils" }
]
}
4 changes: 2 additions & 2 deletions packages/plugins/plugin-slash/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"include": ["src"],
"references": [
{ "path": "../../utils" },
{ "path": "../../ctx" },
{ "path": "../../prose" }
{ "path": "../../prose" },
{ "path": "../../utils" }
]
}
2 changes: 1 addition & 1 deletion packages/plugins/plugin-upload/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"references": [
{ "path": "../../core" },
{ "path": "../../ctx" },
{ "path": "../../prose" },
{ "path": "../../exception" },
{ "path": "../../prose" },
{ "path": "../../utils" }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export const syncListOrderPlugin = $prose((ctx) => {

const handleNodeItem = (
attrs: Record<string, any>,
index: number
index: number,
order: number = 1
): boolean => {
let changed = false
const expectedLabel = `${index + 1}.`
const expectedLabel = `${index + order}.`
if (attrs.label !== expectedLabel) {
attrs.label = expectedLabel
changed = true
Expand Down Expand Up @@ -85,7 +86,8 @@ export const syncListOrderPlugin = $prose((ctx) => {
}

const base = parent?.maybeChild(0)
if (base) changed = handleNodeItem(attrs, index)
if (base)
changed = handleNodeItem(attrs, index, parent?.attrs.order ?? 1)

if (changed) {
tr = tr.setNodeMarkup(pos, undefined, attrs)
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/preset-gfm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"references": [
{ "path": "../../core" },
{ "path": "../../ctx" },
{ "path": "../../prose" },
{ "path": "../../exception" },
{ "path": "../preset-commonmark" },
{ "path": "../../prose" },
{ "path": "../../transformer" },
{ "path": "../../exception" },
{ "path": "../../utils" }
]
}
4 changes: 2 additions & 2 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"references": [
{ "path": "../core" },
{ "path": "../ctx" },
{ "path": "../exception" },
{ "path": "../prose" },
{ "path": "../transformer" },
{ "path": "../exception" }
{ "path": "../transformer" }
]
}