[go: up one dir, main page]

Skip to content

Commit

Permalink
feat: make text in crepe configurable (#1458)
Browse files Browse the repository at this point in the history
* feat: make codemirror feature and block edit feature configurable

* feat: make text on link and image configurable

* refactor: remove icons in components lib

* feat: add cjk text example

* chore: fix circular
  • Loading branch information
Saul-Mirone committed Aug 4, 2024
1 parent 1723d36 commit 54f405e
Show file tree
Hide file tree
Showing 28 changed files with 434 additions and 333 deletions.
55 changes: 0 additions & 55 deletions packages/components/src/__internal__/icons.ts

This file was deleted.

17 changes: 8 additions & 9 deletions packages/components/src/code-block/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ import { $ctx } from '@milkdown/utils'
import type { Extension } from '@codemirror/state'
import type { LanguageDescription } from '@codemirror/language'
import { html } from 'atomico'
import { chevronDown, search, xCircle } from '../__internal__/icons'
import { withMeta } from '../__internal__/meta'

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

export const defaultConfig: CodeBlockConfig = {
extensions: [],
languages: [],
expandIcon: () => '⬇',
searchIcon: () => '🔍',
clearSearchIcon: () => '⌫',
searchPlaceholder: 'Search language',
expandIcon: () => chevronDown,
searchIcon: () => search,
clearSearchIcon: () => xCircle,
noResultText: () => 'No result',
noResultText: 'No result',
renderLanguage: language => html`${language}`,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/code-block/view/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const codeComponent: Component<CodeComponentProps> = ({

const renderedLanguageList = useMemo(() => {
if (!languages?.length)
return html`<li class="language-list-item no-result">${config?.noResultText()}</li>`
return html`<li class="language-list-item no-result">${config?.noResultText}</li>`

return languages.map(languageInfo =>
html`<li
Expand Down
13 changes: 6 additions & 7 deletions packages/components/src/image-block/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { $ctx } from '@milkdown/utils'
import { html } from 'atomico'
import { chatBubble, image } from '../__internal__/icons'
import { withMeta } from '../__internal__/meta'

export interface ImageBlockConfig {
imageIcon: () => ReturnType<typeof html>
captionIcon: () => ReturnType<typeof html>
uploadButton: () => ReturnType<typeof html>
confirmButton: () => ReturnType<typeof html>
imageIcon: () => ReturnType<typeof html> | string | HTMLElement
captionIcon: () => ReturnType<typeof html> | string | HTMLElement
uploadButton: () => ReturnType<typeof html> | string | HTMLElement
confirmButton: () => ReturnType<typeof html> | string | HTMLElement
uploadPlaceholderText: string
captionPlaceholderText: string
onUpload: (file: File) => Promise<string>
}

export const defaultImageBlockConfig: ImageBlockConfig = {
imageIcon: () => image,
captionIcon: () => chatBubble,
imageIcon: () => '🌌',
captionIcon: () => '💬',
uploadButton: () => html`Upload file`,
confirmButton: () => html`Confirm ⏎`,
uploadPlaceholderText: 'or paste the image link ...',
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/image-inline/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { $ctx } from '@milkdown/utils'
import { html } from 'atomico'
import { image } from '../__internal__/icons'
import { withMeta } from '../__internal__/meta'

export interface InlineImageConfig {
Expand All @@ -12,7 +11,7 @@ export interface InlineImageConfig {
}

export const defaultInlineImageConfig: InlineImageConfig = {
imageIcon: () => image,
imageIcon: () => '🌌',
uploadButton: () => html`Upload`,
confirmButton: () => html`⏎`,
uploadPlaceholderText: '/Paste',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const linkPreviewComponent: Component<LinkPreviewProps> = ({ config, src,
<span class="link-icon">
${config?.linkIcon()}
</span>
<span class="link-display">${src}</span>
<a href=${src} target="_blank" class="link-display">${src}</a>
<span class="button link-edit-button" onmousedown=${onClickEditButton}>
${config?.editButton()}
</span>
Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/link-tooltip/slices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { $ctx } from '@milkdown/utils'
import type { Mark } from '@milkdown/prose/model'
import { html } from 'atomico'
import { edit, link, trash } from '../__internal__/icons'
import { withMeta } from '../__internal__/meta'

export interface LinkToolTipState {
Expand Down Expand Up @@ -48,9 +47,9 @@ export interface LinkTooltipConfig {
}

const defaultConfig: LinkTooltipConfig = {
linkIcon: () => link,
editButton: () => edit,
removeButton: () => trash,
linkIcon: () => '🔗',
editButton: () => '✎',
removeButton: () => '⌫',
confirmButton: () => html`Confirm ⏎`,
onCopyLink: () => {},
inputPlaceholder: 'Paste link...',
Expand Down
23 changes: 23 additions & 0 deletions packages/crepe/src/feature/block-edit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,48 @@ import { block } from '@milkdown/kit/plugin/block'
import type { DefineFeature, Icon } from '../shared'
import { configureBlockHandle } from './handle'
import { configureMenu, menu, menuAPI } from './menu'
import type { GroupBuilder } from './menu/group-builder'

interface BlockEditConfig {
handleAddIcon: Icon
handleDragIcon: Icon
buildMenu: (builder: GroupBuilder) => void

slashMenuTextGroupLabel: string
slashMenuTextIcon: Icon
slashMenuTextLabel: string
slashMenuH1Icon: Icon
slashMenuH1Label: string
slashMenuH2Icon: Icon
slashMenuH2Label: string
slashMenuH3Icon: Icon
slashMenuH3Label: string
slashMenuH4Icon: Icon
slashMenuH4Label: string
slashMenuH5Icon: Icon
slashMenuH5Label: string
slashMenuH6Icon: Icon
slashMenuH6Label: string
slashMenuQuoteIcon: Icon
slashMenuQuoteLabel: string
slashMenuDividerIcon: Icon
slashMenuDividerLabel: string

slashMenuListGroupLabel: string
slashMenuBulletListIcon: Icon
slashMenuBulletListLabel: string
slashMenuOrderedListIcon: Icon
slashMenuOrderedListLabel: string
slashMenuTaskListIcon: Icon
slashMenuTaskListLabel: string

slashMenuAdvancedGroupLabel: string
slashMenuImageIcon: Icon
slashMenuImageLabel: string
slashMenuCodeBlockIcon: Icon
slashMenuCodeBlockLabel: string
slashMenuTableIcon: Icon
slashMenuTableLabel: string
}

export type BlockEditFeatureConfig = Partial<BlockEditConfig>
Expand Down
Loading

0 comments on commit 54f405e

Please sign in to comment.