๐Ÿ“ Sign Up | ๐Ÿ” Log In

โ† Root | โ†‘ Up

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ๐Ÿ“„ shadcn/directory/udecode/plate/(plugins)/(functionality)/(combobox)/slash-command.cn โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘

title: ๆ–œๆ ๅ‘ฝไปค docs:

  • route: /docs/combobox title: ็ป„ๅˆๆก†
  • route: components/slash-node title: ๆ–œๆ ่พ“ๅ…ฅๅ…ƒ็ด 
  • route: https://pro.platejs.org/docs/components/slash-node title: ๆ–œๆ ่พ“ๅ…ฅๅ…ƒ็ด 

<ComponentPreview name="slash-command-demo" /> <PackageInfo>

็‰นๆ€ง

  • ๅฟซ้€Ÿ่ฎฟ้—ฎๅ„็ง็ผ–่พ‘ๅ™จๅ‘ฝไปค
  • ้€š่ฟ‡ / ๅญ—็ฌฆ่งฆๅ‘
  • ๆ”ฏๆŒ้”ฎ็›˜ๅฏผ่ˆชๅ’Œ็ญ›้€‰
  • ๅฏ่‡ชๅฎšไน‰็š„ๅ‘ฝไปค็ป„ๅ’Œ้€‰้กน
</PackageInfo>

ๅฅ—ไปถไฝฟ็”จ

<Steps>

ๅฎ‰่ฃ…

ๆทปๅŠ ๆ–œๆ ๅ‘ฝไปคๅŠŸ่ƒฝๆœ€ๅฟซ็š„ๆ–นๅผๆ˜ฏไฝฟ็”จ SlashKit๏ผŒๅฎƒๅŒ…ๅซ้ข„้…็ฝฎ็š„ SlashPlugin ๅ’Œ SlashInputPlugin ไปฅๅŠๅฎƒไปฌ็š„ Plate UI ็ป„ไปถใ€‚

<ComponentSource name="slash-kit" />
  • SlashInputElement: ๆธฒๆŸ“ๅธฆๆœ‰้ข„ๅฎšไน‰้€‰้กน็š„ๆ–œๆ ๅ‘ฝไปค็ป„ๅˆๆก†

ๆทปๅŠ ๅฅ—ไปถ

import { createPlateEditor } from 'platejs/react';
import { SlashKit } from '@/components/editor/plugins/slash-kit';

const editor = createPlateEditor({
  plugins: [
    // ...ๅ…ถไป–ๆ’ไปถ
    ...SlashKit,
  ],
});
</Steps>

ๆ‰‹ๅŠจไฝฟ็”จ

<Steps>

ๅฎ‰่ฃ…

npm install @platejs/slash-command

ๆทปๅŠ ๆ’ไปถ

import { SlashPlugin, SlashInputPlugin } from '@platejs/slash-command/react';
import { createPlateEditor } from 'platejs/react';

const editor = createPlateEditor({
  plugins: [
    // ...ๅ…ถไป–ๆ’ไปถ
    SlashPlugin,
    SlashInputPlugin,
  ],
});

้…็ฝฎๆ’ไปถ

import { SlashPlugin, SlashInputPlugin } from '@platejs/slash-command/react';
import { createPlateEditor } from 'platejs/react';
import { SlashInputElement } from '@/components/ui/slash-node';
import { KEYS } from 'platejs';

const editor = createPlateEditor({
  plugins: [
    // ...ๅ…ถไป–ๆ’ไปถ
    SlashPlugin.configure({
      options: {
        trigger: '/',
        triggerPreviousCharPattern: /^\s?$/,
        triggerQuery: (editor) =>
          !editor.api.some({
            match: { type: editor.getType(KEYS.codeBlock) },
          }),
      },
    }),
    SlashInputPlugin.withComponent(SlashInputElement),
  ],
});
  • options.trigger: ่งฆๅ‘ๆ–œๆ ๅ‘ฝไปค็ป„ๅˆๆก†็š„ๅญ—็ฌฆ๏ผˆ้ป˜่ฎค: /๏ผ‰
  • options.triggerPreviousCharPattern: ๅŒน้…่งฆๅ‘ๅญ—็ฌฆๅ‰ๅญ—็ฌฆ็š„ๆญฃๅˆ™่กจ่พพๅผ
  • options.triggerQuery: ๅˆคๆ–ญไฝ•ๆ—ถๅฏ็”จๆ–œๆ ๅ‘ฝไปค็š„ๅ‡ฝๆ•ฐ
  • withComponent: ๆŒ‡ๅฎšๆ–œๆ ๅ‘ฝไปค็•Œ้ข็š„UI็ป„ไปถ
</Steps>

ไฝฟ็”จๆ–นๅผ

ๅฆ‚ไฝ•ไฝฟ็”จๆ–œๆ ๅ‘ฝไปค๏ผš

  1. ๅœจๆ–‡ๆกฃไปปๆ„ไฝ็ฝฎ่พ“ๅ…ฅ / ๆ‰“ๅผ€ๆ–œๆ ่œๅ•
  2. ๅผ€ๅง‹่พ“ๅ…ฅไปฅ็ญ›้€‰้€‰้กน๏ผŒๆˆ–ไฝฟ็”จๆ–นๅ‘้”ฎๅฏผ่ˆช
  3. ๆŒ‰ๅ›ž่ฝฆๆˆ–็‚นๅ‡ป้€‰ๆ‹ฉ้€‰้กน
  4. ๆŒ‰ESC้”ฎไธ้€‰ๆ‹ฉ็›ดๆŽฅๅ…ณ้—ญ่œๅ•

ๅฏ็”จ้€‰้กนๅŒ…ๆ‹ฌ๏ผš

  • ๆ–‡ๆœฌๅ—๏ผˆๆฎต่ฝใ€ๆ ‡้ข˜๏ผ‰
  • ๅˆ—่กจ๏ผˆ้กน็›ฎ็ฌฆๅทใ€็ผ–ๅทใ€ๅพ…ๅŠžไบ‹้กน๏ผ‰
  • ้ซ˜็บงๅ—๏ผˆ่กจๆ ผใ€ไปฃ็ ๅ—ใ€ๆ ‡ๆณจ๏ผ‰
  • ่กŒๅ†…ๅ…ƒ็ด ๏ผˆๆ—ฅๆœŸใ€ๅ…ฌๅผ๏ผ‰
<Callout type="info"> ไฝฟ็”จๅ…ณ้”ฎ่ฏๅฟซ้€ŸๆŸฅๆ‰พ้€‰้กนใ€‚ไพ‹ๅฆ‚่พ“ๅ…ฅ '/ul' ๆŸฅๆ‰พ้กน็›ฎ็ฌฆๅทๅˆ—่กจ๏ผŒๆˆ– '/h1' ๆŸฅๆ‰พไธ€็บงๆ ‡้ข˜ใ€‚ </Callout>

Plate Plus

<ComponentPreviewPro name="slash-command-pro" />

ๆ’ไปถ

SlashPlugin

ๅฎž็Žฐๆ–œๆ ๅ‘ฝไปคๅŠŸ่ƒฝ็š„ๆ’ไปถใ€‚ๆ‰ฉๅฑ•่‡ช TriggerComboboxPluginOptionsใ€‚

<API name="SlashPlugin"> <APIOptions> <APIItem name="trigger" type="string" optional> ่งฆๅ‘ๆ–œๆ ๅ‘ฝไปค็ป„ๅˆๆก†็š„ๅญ—็ฌฆใ€‚ - **้ป˜่ฎคๅ€ผ:** `'/'` </APIItem> <APIItem name="triggerPreviousCharPattern" type="RegExp" optional> ๅŒน้…่งฆๅ‘ๅญ—็ฌฆๅ‰ๅญ—็ฌฆ็š„ๆญฃๅˆ™่กจ่พพๅผใ€‚ - **้ป˜่ฎคๅ€ผ:** `/^\s?$/` </APIItem> <APIItem name="createComboboxInput" type="() => TComboboxInputElement" optional> ๅˆ›ๅปบ็ป„ๅˆๆก†่พ“ๅ…ฅๅ…ƒ็ด ็š„ๅ‡ฝๆ•ฐใ€‚ - **้ป˜่ฎคๅ€ผ:** ```tsx () => ({ children: [{ text: '' }], type: KEYS.slashInput, }); ``` </APIItem> <APIItem name="triggerQuery" type="(editor: PlateEditor) => boolean" optional> ๅˆคๆ–ญไฝ•ๆ—ถๅฏ็”จๆ–œๆ ๅ‘ฝไปค็š„ๅ‡ฝๆ•ฐใ€‚ๅฏ็”จไบŽๅœจไปฃ็ ๅ—็ญ‰็‰นๅฎšไธŠไธ‹ๆ–‡ไธญ็ฆ็”จๅŠŸ่ƒฝใ€‚ </APIItem> </APIOptions> </API>

SlashInputPlugin

ๅค„็†ๆ–œๆ ๅ‘ฝไปคๆ’ๅ…ฅ็š„่พ“ๅ…ฅ่กŒไธบใ€‚

โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โ† Root | โ†‘ Up