@haklex/rich-plugin-slash-menu 0.0.65 → 0.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -23
- package/dist/SlashMenuList.d.ts.map +1 -1
- package/dist/SlashMenuPlugin.d.ts +2 -2
- package/dist/SlashMenuPlugin.d.ts.map +1 -1
- package/dist/index.mjs +32 -61
- package/package.json +20 -15
package/README.md
CHANGED
|
@@ -1,44 +1,83 @@
|
|
|
1
1
|
# @haklex/rich-plugin-slash-menu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Slash command menu plugin for inserting blocks via `/` trigger.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add @haklex/rich-plugin-slash-menu
|
|
8
|
+
pnpm add @haklex/rich-plugin-slash-menu
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Peer Dependencies
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
| Package | Version |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `@lexical/list` | `^0.41.0` |
|
|
16
|
+
| `@lexical/react` | `^0.41.0` |
|
|
17
|
+
| `@lexical/rich-text` | `^0.41.0` |
|
|
18
|
+
| `@lexical/selection` | `^0.41.0` |
|
|
19
|
+
| `@lexical/table` | `^0.41.0` |
|
|
20
|
+
| `lexical` | `^0.41.0` |
|
|
21
|
+
| `lucide-react` | `^0.574.0` |
|
|
22
|
+
| `react` | `>= 19` |
|
|
23
|
+
| `react-dom` | `>= 19` |
|
|
20
24
|
|
|
21
|
-
##
|
|
25
|
+
## Usage
|
|
22
26
|
|
|
23
27
|
```tsx
|
|
24
28
|
import { SlashMenuPlugin } from '@haklex/rich-plugin-slash-menu'
|
|
25
|
-
import
|
|
29
|
+
import '@haklex/rich-plugin-slash-menu/style.css'
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
function Editor() {
|
|
32
|
+
return (
|
|
33
|
+
<RichEditor>
|
|
34
|
+
<SlashMenuPlugin />
|
|
35
|
+
</RichEditor>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
30
38
|
```
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
Typing `/` at the start of a block opens a command menu with filterable block insertion options (headings, lists, code blocks, tables, etc.). The menu supports keyboard navigation and fuzzy matching.
|
|
33
41
|
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
```tsx
|
|
43
|
+
import {
|
|
44
|
+
SlashMenuPlugin,
|
|
45
|
+
SlashMenuItem,
|
|
46
|
+
SlashMenuList,
|
|
47
|
+
getBuiltinItems,
|
|
48
|
+
collectNodeSlashItems,
|
|
49
|
+
} from '@haklex/rich-plugin-slash-menu'
|
|
50
|
+
import type { SlashMenuPluginProps } from '@haklex/rich-plugin-slash-menu'
|
|
51
|
+
|
|
52
|
+
// Get builtin slash menu items
|
|
53
|
+
const items = getBuiltinItems()
|
|
54
|
+
|
|
55
|
+
// Collect slash items registered by nodes
|
|
56
|
+
const nodeItems = collectNodeSlashItems()
|
|
40
57
|
```
|
|
41
58
|
|
|
59
|
+
## Exports
|
|
60
|
+
|
|
61
|
+
| Export | Type | Description |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `SlashMenuPlugin` | Component | Main plugin component to render inside `RichEditor` |
|
|
64
|
+
| `SlashMenuItem` | Component | Individual menu item component |
|
|
65
|
+
| `SlashMenuList` | Component | Menu list container component |
|
|
66
|
+
| `getBuiltinItems` | Function | Returns the default set of slash menu items |
|
|
67
|
+
| `collectNodeSlashItems` | Function | Collects slash menu items registered by editor nodes |
|
|
68
|
+
| `SlashMenuPluginProps` | TypeScript type | Props type for `SlashMenuPlugin` |
|
|
69
|
+
|
|
70
|
+
## Sub-path Exports
|
|
71
|
+
|
|
72
|
+
| Path | Description |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| `@haklex/rich-plugin-slash-menu` | Plugin component, menu items, utilities, and types |
|
|
75
|
+
| `@haklex/rich-plugin-slash-menu/style.css` | Stylesheet |
|
|
76
|
+
|
|
77
|
+
## Part of Haklex
|
|
78
|
+
|
|
79
|
+
This package is part of the [Haklex](../../README.md) rich editor ecosystem.
|
|
80
|
+
|
|
42
81
|
## License
|
|
43
82
|
|
|
44
83
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlashMenuList.d.ts","sourceRoot":"","sources":["../src/SlashMenuList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SlashMenuList.d.ts","sourceRoot":"","sources":["../src/SlashMenuList.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,UAAU,kBAAkB;IAC1B,aAAa,EAAE,WAAW,CAAC;IAC3B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,sBAAsB,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACxD,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAyBD,wBAAgB,aAAa,CAAC,EAC5B,aAAa,EACb,OAAO,EACP,aAAa,EACb,sBAAsB,EACtB,mBAAmB,GACpB,EAAE,kBAAkB,2CA+DpB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LexicalEditor } from 'lexical';
|
|
2
2
|
import { SlashMenuItem } from './SlashMenuItem';
|
|
3
3
|
export interface SlashMenuPluginProps {
|
|
4
|
-
items?: SlashMenuItem[];
|
|
5
4
|
extraItems?: SlashMenuItem[];
|
|
5
|
+
items?: SlashMenuItem[];
|
|
6
6
|
triggerChar?: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function collectNodeSlashItems(editor: LexicalEditor): SlashMenuItem[];
|
|
9
|
-
export declare function SlashMenuPlugin({ items, extraItems, triggerChar
|
|
9
|
+
export declare function SlashMenuPlugin({ items, extraItems, triggerChar }: SlashMenuPluginProps): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
//# sourceMappingURL=SlashMenuPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlashMenuPlugin.d.ts","sourceRoot":"","sources":["../src/SlashMenuPlugin.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"SlashMenuPlugin.d.ts","sourceRoot":"","sources":["../src/SlashMenuPlugin.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,SAAS,CAAC;AAMvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,EAAE,CAK5E;AAWD,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,WAAiB,EAAE,EAAE,oBAAoB,2CAuE7F"}
|
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { createElement, useEffect, useMemo, useState, useCallback } from "react"
|
|
|
12
12
|
import { MenuOption, useBasicTypeaheadTriggerMatch, LexicalTypeaheadMenuPlugin } from "@lexical/react/LexicalTypeaheadMenuPlugin";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useFloating, autoUpdate, offset, flip, shift } from "@floating-ui/react-dom";
|
|
15
|
-
import { collectCommandItems } from "@haklex/rich-editor";
|
|
15
|
+
import { collectCommandItems } from "@haklex/rich-editor/commands";
|
|
16
16
|
import { PortalThemeWrapper } from "@haklex/rich-style-token";
|
|
17
17
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
18
18
|
import { createPortal } from "react-dom";
|
|
@@ -218,57 +218,32 @@ function SlashMenuList({
|
|
|
218
218
|
}, [anchorElement, refs]);
|
|
219
219
|
const sections = useMemo(() => groupBySection(options), [options]);
|
|
220
220
|
if (options.length === 0) {
|
|
221
|
-
return /* @__PURE__ */ jsx(
|
|
222
|
-
"div",
|
|
223
|
-
{
|
|
224
|
-
ref: refs.setFloating,
|
|
225
|
-
style: floatingStyles,
|
|
226
|
-
className: slashMenu,
|
|
227
|
-
children: /* @__PURE__ */ jsx("div", { className: slashMenuEmpty, children: "No matching commands" })
|
|
228
|
-
}
|
|
229
|
-
);
|
|
221
|
+
return /* @__PURE__ */ jsx("div", { className: slashMenu, ref: refs.setFloating, style: floatingStyles, children: /* @__PURE__ */ jsx("div", { className: slashMenuEmpty, children: "No matching commands" }) });
|
|
230
222
|
}
|
|
231
|
-
return /* @__PURE__ */ jsx(
|
|
232
|
-
"
|
|
233
|
-
{
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
tabIndex: -1,
|
|
256
|
-
children: [
|
|
257
|
-
/* @__PURE__ */ jsx("span", { className: slashMenuItemIcon, children: item.icon }),
|
|
258
|
-
/* @__PURE__ */ jsxs("span", { className: slashMenuItemText, children: [
|
|
259
|
-
/* @__PURE__ */ jsx("span", { className: slashMenuItemTitle, children: item.title }),
|
|
260
|
-
item.description && /* @__PURE__ */ jsx("span", { className: slashMenuItemDescription, children: item.description })
|
|
261
|
-
] })
|
|
262
|
-
]
|
|
263
|
-
},
|
|
264
|
-
item.key
|
|
265
|
-
)) })
|
|
266
|
-
]
|
|
267
|
-
},
|
|
268
|
-
section.label
|
|
269
|
-
))
|
|
270
|
-
}
|
|
271
|
-
);
|
|
223
|
+
return /* @__PURE__ */ jsx("ul", { className: slashMenu, ref: refs.setFloating, role: "listbox", style: floatingStyles, children: sections.map((section, sectionIndex) => /* @__PURE__ */ jsxs("li", { className: slashMenuSectionWrapper, role: "presentation", children: [
|
|
224
|
+
sectionIndex > 0 && /* @__PURE__ */ jsx("div", { className: slashMenuSectionDivider }),
|
|
225
|
+
/* @__PURE__ */ jsx("div", { className: slashMenuSection, children: section.label }),
|
|
226
|
+
/* @__PURE__ */ jsx("ul", { className: slashMenuItems, role: "group", children: section.items.map(({ item, globalIndex }) => /* @__PURE__ */ jsxs(
|
|
227
|
+
"li",
|
|
228
|
+
{
|
|
229
|
+
"aria-selected": globalIndex === selectedIndex,
|
|
230
|
+
className: slashMenuItem,
|
|
231
|
+
ref: item.setRefElement,
|
|
232
|
+
role: "option",
|
|
233
|
+
tabIndex: -1,
|
|
234
|
+
onClick: () => selectOptionAndCleanUp(item),
|
|
235
|
+
onMouseEnter: () => setHighlightedIndex(globalIndex),
|
|
236
|
+
children: [
|
|
237
|
+
/* @__PURE__ */ jsx("span", { className: slashMenuItemIcon, children: item.icon }),
|
|
238
|
+
/* @__PURE__ */ jsxs("span", { className: slashMenuItemText, children: [
|
|
239
|
+
/* @__PURE__ */ jsx("span", { className: slashMenuItemTitle, children: item.title }),
|
|
240
|
+
item.description && /* @__PURE__ */ jsx("span", { className: slashMenuItemDescription, children: item.description })
|
|
241
|
+
] })
|
|
242
|
+
]
|
|
243
|
+
},
|
|
244
|
+
item.key
|
|
245
|
+
)) })
|
|
246
|
+
] }, section.label)) });
|
|
272
247
|
}
|
|
273
248
|
function collectNodeSlashItems(editor) {
|
|
274
249
|
const configs = collectCommandItems(editor);
|
|
@@ -282,11 +257,7 @@ function filterItems(query, items) {
|
|
|
282
257
|
return item.keywords.some((kw) => kw.toLowerCase().includes(lower));
|
|
283
258
|
});
|
|
284
259
|
}
|
|
285
|
-
function SlashMenuPlugin({
|
|
286
|
-
items,
|
|
287
|
-
extraItems,
|
|
288
|
-
triggerChar = "/"
|
|
289
|
-
}) {
|
|
260
|
+
function SlashMenuPlugin({ items, extraItems, triggerChar = "/" }) {
|
|
290
261
|
const [editor] = useLexicalComposerContext();
|
|
291
262
|
const [queryString, setQueryString] = useState(null);
|
|
292
263
|
const allItems = useMemo(() => {
|
|
@@ -321,10 +292,8 @@ function SlashMenuPlugin({
|
|
|
321
292
|
return /* @__PURE__ */ jsx(
|
|
322
293
|
LexicalTypeaheadMenuPlugin,
|
|
323
294
|
{
|
|
324
|
-
onQueryChange: setQueryString,
|
|
325
|
-
onSelectOption,
|
|
326
|
-
triggerFn: checkForTriggerMatch,
|
|
327
295
|
options: filteredItems,
|
|
296
|
+
triggerFn: checkForTriggerMatch,
|
|
328
297
|
menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
|
|
329
298
|
const anchorElement = anchorElementRef.current;
|
|
330
299
|
if (!anchorElement || filteredItems.length === 0) {
|
|
@@ -336,14 +305,16 @@ function SlashMenuPlugin({
|
|
|
336
305
|
{
|
|
337
306
|
anchorElement,
|
|
338
307
|
options: filteredItems,
|
|
339
|
-
selectedIndex,
|
|
340
308
|
selectOptionAndCleanUp,
|
|
309
|
+
selectedIndex,
|
|
341
310
|
setHighlightedIndex
|
|
342
311
|
}
|
|
343
312
|
) }),
|
|
344
313
|
anchorElement
|
|
345
314
|
);
|
|
346
|
-
}
|
|
315
|
+
},
|
|
316
|
+
onQueryChange: setQueryString,
|
|
317
|
+
onSelectOption
|
|
347
318
|
}
|
|
348
319
|
);
|
|
349
320
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-plugin-slash-menu",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.65",
|
|
3
|
+
"version": "0.0.67",
|
|
5
4
|
"description": "Slash command menu plugin",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Innei/haklex.git",
|
|
8
|
+
"directory": "packages/rich-plugin-slash-menu"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
14
|
"import": "./dist/index.mjs",
|
|
@@ -15,21 +20,10 @@
|
|
|
15
20
|
"files": [
|
|
16
21
|
"dist"
|
|
17
22
|
],
|
|
18
|
-
"peerDependencies": {
|
|
19
|
-
"@lexical/list": "^0.41.0",
|
|
20
|
-
"@lexical/react": "^0.41.0",
|
|
21
|
-
"@lexical/rich-text": "^0.41.0",
|
|
22
|
-
"@lexical/selection": "^0.41.0",
|
|
23
|
-
"@lexical/table": "^0.41.0",
|
|
24
|
-
"lexical": "^0.41.0",
|
|
25
|
-
"lucide-react": "^0.574.0",
|
|
26
|
-
"react": ">=19",
|
|
27
|
-
"react-dom": ">=19"
|
|
28
|
-
},
|
|
29
23
|
"dependencies": {
|
|
30
24
|
"@floating-ui/react-dom": "^2.1.8",
|
|
31
|
-
"@haklex/rich-editor": "0.0.
|
|
32
|
-
"@haklex/rich-style-token": "0.0.
|
|
25
|
+
"@haklex/rich-editor": "0.0.67",
|
|
26
|
+
"@haklex/rich-style-token": "0.0.67"
|
|
33
27
|
},
|
|
34
28
|
"devDependencies": {
|
|
35
29
|
"@lexical/list": "^0.41.0",
|
|
@@ -49,6 +43,17 @@
|
|
|
49
43
|
"vite": "^7.3.1",
|
|
50
44
|
"vite-plugin-dts": "^4.5.4"
|
|
51
45
|
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@lexical/list": "^0.41.0",
|
|
48
|
+
"@lexical/react": "^0.41.0",
|
|
49
|
+
"@lexical/rich-text": "^0.41.0",
|
|
50
|
+
"@lexical/selection": "^0.41.0",
|
|
51
|
+
"@lexical/table": "^0.41.0",
|
|
52
|
+
"lexical": "^0.41.0",
|
|
53
|
+
"lucide-react": "^0.574.0",
|
|
54
|
+
"react": ">=19",
|
|
55
|
+
"react-dom": ">=19"
|
|
56
|
+
},
|
|
52
57
|
"publishConfig": {
|
|
53
58
|
"access": "public"
|
|
54
59
|
},
|