@haklex/rich-plugin-slash-menu 0.32.0 → 0.34.0

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.
@@ -7,12 +7,14 @@ export declare class SlashMenuItem extends MenuOption {
7
7
  description: string;
8
8
  keywords: string[];
9
9
  section: string;
10
+ nested: boolean;
10
11
  onSelect: (editor: LexicalEditor, queryString: string) => void;
11
12
  constructor(title: string, options: {
12
13
  icon?: JSX.Element;
13
14
  description?: string;
14
15
  keywords?: string[];
15
16
  section?: string;
17
+ nested?: boolean;
16
18
  onSelect: (editor: LexicalEditor, queryString: string) => void;
17
19
  });
18
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SlashMenuItem.d.ts","sourceRoot":"","sources":["../src/SlashMenuItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,qBAAa,aAAc,SAAQ,UAAU;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;gBAG7D,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;KAChE;CAUJ"}
1
+ {"version":3,"file":"SlashMenuItem.d.ts","sourceRoot":"","sources":["../src/SlashMenuItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,qBAAa,aAAc,SAAQ,UAAU;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;gBAG7D,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;KAChE;CAWJ"}
@@ -3,8 +3,9 @@ import { SlashMenuItem } from './SlashMenuItem';
3
3
  export interface SlashMenuPluginProps {
4
4
  extraItems?: SlashMenuItem[];
5
5
  items?: SlashMenuItem[];
6
+ nested?: boolean;
6
7
  triggerChar?: string;
7
8
  }
8
9
  export declare function collectNodeSlashItems(editor: LexicalEditor): SlashMenuItem[];
9
- export declare function SlashMenuPlugin({ items, extraItems, triggerChar }: SlashMenuPluginProps): import("react").JSX.Element;
10
+ export declare function SlashMenuPlugin({ items, extraItems, nested, triggerChar, }: SlashMenuPluginProps): import("react").JSX.Element;
10
11
  //# 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,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,CAc5E;AAWD,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,WAAiB,EAAE,EAAE,oBAAoB,+BAuE7F"}
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,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,EAAE,CAe5E;AAWD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,UAAU,EACV,MAAM,EACN,WAAiB,GAClB,EAAE,oBAAoB,+BA6EtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"builtinItems.d.ts","sourceRoot":"","sources":["../src/builtinItems.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAM/C,wBAAgB,eAAe,IAAI,aAAa,EAAE,CAiIjD"}
1
+ {"version":3,"file":"builtinItems.d.ts","sourceRoot":"","sources":["../src/builtinItems.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAMhD,wBAAgB,eAAe,IAAI,aAAa,EAAE,CAkIjD"}
package/dist/index.mjs CHANGED
@@ -13,7 +13,7 @@ import { collectCommandItems } from "@haklex/rich-editor/commands";
13
13
  import { PortalThemeWrapper } from "@haklex/rich-style-token";
14
14
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
15
15
  import { createPortal } from "react-dom";
16
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
16
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
17
17
  function _typeof(o) {
18
18
  "@babel/helpers - typeof";
19
19
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -23,7 +23,7 @@ function _typeof(o) {
23
23
  }, _typeof(o);
24
24
  }
25
25
  //#endregion
26
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
26
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
27
27
  function toPrimitive(t, r) {
28
28
  if ("object" != _typeof(t) || !t) return t;
29
29
  var e = t[Symbol.toPrimitive];
@@ -35,13 +35,13 @@ function toPrimitive(t, r) {
35
35
  return ("string" === r ? String : Number)(t);
36
36
  }
37
37
  //#endregion
38
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
38
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
39
39
  function toPropertyKey(t) {
40
40
  var i = toPrimitive(t, "string");
41
41
  return "symbol" == _typeof(i) ? i : i + "";
42
42
  }
43
43
  //#endregion
44
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
44
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
45
45
  function _defineProperty(e, r, t) {
46
46
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
47
47
  value: t,
@@ -60,12 +60,14 @@ var SlashMenuItem = class extends MenuOption {
60
60
  _defineProperty(this, "description", void 0);
61
61
  _defineProperty(this, "keywords", void 0);
62
62
  _defineProperty(this, "section", void 0);
63
+ _defineProperty(this, "nested", void 0);
63
64
  _defineProperty(this, "onSelect", void 0);
64
65
  this.title = title;
65
66
  this.icon = options.icon;
66
67
  this.description = options.description ?? "";
67
68
  this.keywords = options.keywords ?? [];
68
69
  this.section = options.section ?? "BASIC BLOCKS";
70
+ this.nested = options.nested ?? true;
69
71
  this.onSelect = options.onSelect;
70
72
  }
71
73
  };
@@ -173,6 +175,7 @@ function getBuiltinItems() {
173
175
  icon: createElement(Table, { size: ICON_SIZE }),
174
176
  description: "Add a table",
175
177
  keywords: ["table", "grid"],
178
+ nested: false,
176
179
  section: SECTION_BASIC,
177
180
  onSelect: (editor) => {
178
181
  editor.dispatchCommand(INSERT_TABLE_COMMAND, {
@@ -336,6 +339,7 @@ function collectNodeSlashItems(editor) {
336
339
  description: c.description,
337
340
  icon: isValidElement(c.icon) ? c.icon : void 0,
338
341
  keywords: c.keywords,
342
+ nested: c.nested,
339
343
  section: c.section,
340
344
  onSelect: c.onSelect
341
345
  }));
@@ -348,24 +352,43 @@ function filterItems(query, items) {
348
352
  return item.keywords.some((kw) => kw.toLowerCase().includes(lower));
349
353
  });
350
354
  }
351
- function SlashMenuPlugin({ items, extraItems, triggerChar = "/" }) {
355
+ function SlashMenuPlugin({ items, extraItems, nested, triggerChar = "/" }) {
352
356
  const [editor] = useLexicalComposerContext();
353
357
  const [queryString, setQueryString] = useState(null);
354
358
  const allItems = useMemo(() => {
355
- if (items) return items;
356
- const builtins = getBuiltinItems();
357
- const nodeItems = collectNodeSlashItems(editor);
358
- const combined = [...builtins, ...nodeItems];
359
- return extraItems ? [...combined, ...extraItems] : combined;
359
+ let combined;
360
+ if (items) combined = items;
361
+ else {
362
+ const builtins = getBuiltinItems();
363
+ const nodeItems = collectNodeSlashItems(editor);
364
+ combined = extraItems ? [
365
+ ...builtins,
366
+ ...nodeItems,
367
+ ...extraItems
368
+ ] : [...builtins, ...nodeItems];
369
+ }
370
+ return nested ? combined.filter((item) => item.nested !== false) : combined;
360
371
  }, [
361
372
  items,
362
373
  extraItems,
374
+ nested,
363
375
  editor
364
376
  ]);
365
377
  const filteredItems = useMemo(() => filterItems(queryString ?? "", allItems), [queryString, allItems]);
378
+ const checkForTriggerMatch = useBasicTypeaheadTriggerMatch(triggerChar, { minLength: 0 });
379
+ const onSelectOption = useCallback((option, textNodeContainingQuery, closeMenu, matchingString) => {
380
+ editor.update(() => {
381
+ if (textNodeContainingQuery) {
382
+ const selection = $getSelection();
383
+ if ($isRangeSelection(selection)) textNodeContainingQuery.remove();
384
+ }
385
+ });
386
+ closeMenu();
387
+ option.onSelect(editor, matchingString);
388
+ }, [editor]);
366
389
  return /* @__PURE__ */ jsx(LexicalTypeaheadMenuPlugin, {
367
390
  options: filteredItems,
368
- triggerFn: useBasicTypeaheadTriggerMatch(triggerChar, { minLength: 0 }),
391
+ triggerFn: checkForTriggerMatch,
369
392
  menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
370
393
  const anchorElement = anchorElementRef.current;
371
394
  if (!anchorElement || filteredItems.length === 0) return null;
@@ -378,15 +401,7 @@ function SlashMenuPlugin({ items, extraItems, triggerChar = "/" }) {
378
401
  }) }), anchorElement);
379
402
  },
380
403
  onQueryChange: setQueryString,
381
- onSelectOption: useCallback((option, textNodeContainingQuery, closeMenu, matchingString) => {
382
- editor.update(() => {
383
- if (textNodeContainingQuery) {
384
- if ($isRangeSelection($getSelection())) textNodeContainingQuery.remove();
385
- }
386
- });
387
- closeMenu();
388
- option.onSelect(editor, matchingString);
389
- }, [editor])
404
+ onSelectOption
390
405
  });
391
406
  }
392
407
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-plugin-slash-menu",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "Slash command menu plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,35 +24,35 @@
24
24
  "@floating-ui/react-dom": "^2.1.9"
25
25
  },
26
26
  "devDependencies": {
27
- "@lexical/list": "^0.48.0",
28
- "@lexical/react": "^0.48.0",
29
- "@lexical/rich-text": "^0.48.0",
30
- "@lexical/selection": "^0.48.0",
31
- "@lexical/table": "^0.48.0",
32
- "@types/react": "^19.2.17",
33
- "@types/react-dom": "^19.2.3",
34
- "@vanilla-extract/css": "^1.21.1",
35
- "@vanilla-extract/vite-plugin": "^5.2.5",
36
- "lexical": "^0.48.0",
37
- "lucide-react": "^1.26.0",
27
+ "@lexical/list": "^0.49.0",
28
+ "@lexical/react": "^0.49.0",
29
+ "@lexical/rich-text": "^0.49.0",
30
+ "@lexical/selection": "^0.49.0",
31
+ "@lexical/table": "^0.49.0",
32
+ "@types/react": "^19.2.18",
33
+ "@types/react-dom": "^19.2.4",
34
+ "@vanilla-extract/css": "^1.21.2",
35
+ "@vanilla-extract/vite-plugin": "^5.2.6",
36
+ "lexical": "^0.49.0",
37
+ "lucide-react": "^1.28.0",
38
38
  "react": "^19.2.8",
39
39
  "react-dom": "^19.2.8",
40
40
  "typescript": "^7.0.2",
41
41
  "unplugin-dts": "^1.0.3",
42
- "vite": "^8.1.5"
42
+ "vite": "^8.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@lexical/list": "^0.47.0",
46
- "@lexical/react": "^0.47.0",
47
- "@lexical/rich-text": "^0.47.0",
48
- "@lexical/selection": "^0.47.0",
49
- "@lexical/table": "^0.47.0",
50
- "lexical": "^0.47.0",
45
+ "@lexical/list": "^0.49.0",
46
+ "@lexical/react": "^0.49.0",
47
+ "@lexical/rich-text": "^0.49.0",
48
+ "@lexical/selection": "^0.49.0",
49
+ "@lexical/table": "^0.49.0",
50
+ "lexical": "^0.49.0",
51
51
  "lucide-react": "^1.0.0",
52
52
  "react": ">=19",
53
53
  "react-dom": ">=19",
54
- "@haklex/rich-style-token": "^0.32.0",
55
- "@haklex/rich-editor": "^0.32.0"
54
+ "@haklex/rich-editor": "^0.34.0",
55
+ "@haklex/rich-style-token": "^0.34.0"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"