@use-kona/editor 0.1.3 → 0.1.4

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.
Files changed (213) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +1 -2
  3. package/dist/plugins/CodeBlockPlugin/index.d.ts +1 -0
  4. package/dist/plugins/FloatingMenuPlugin/FloatingMenu.js +15 -28
  5. package/dist/plugins/FloatingMenuPlugin/types.d.ts +4 -1
  6. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.d.ts +1 -0
  7. package/dist/plugins/HighlightsPlugin/HighlightsPlugin.js +3 -0
  8. package/dist/plugins/index.d.ts +1 -1
  9. package/package.json +12 -11
  10. package/src/index.ts +0 -1
  11. package/src/plugins/CodeBlockPlugin/index.ts +1 -0
  12. package/src/plugins/FloatingMenuPlugin/FloatingMenu.tsx +13 -22
  13. package/src/plugins/FloatingMenuPlugin/types.ts +4 -1
  14. package/src/plugins/HighlightsPlugin/HighlightsPlugin.tsx +4 -0
  15. package/src/plugins/index.ts +1 -1
  16. package/dist/examples/Backdrop.d.ts +0 -5
  17. package/dist/examples/Backdrop.js +0 -13
  18. package/dist/examples/Backdrop.module.js +0 -5
  19. package/dist/examples/Backdrop_module.css +0 -6
  20. package/dist/examples/CodeBlock.d.ts +0 -12
  21. package/dist/examples/CodeBlock.js +0 -163
  22. package/dist/examples/CodeBlock.module.js +0 -9
  23. package/dist/examples/CodeBlock_module.css +0 -66
  24. package/dist/examples/DragBlock.d.ts +0 -11
  25. package/dist/examples/DragBlock.js +0 -38
  26. package/dist/examples/DragBlock.module.js +0 -9
  27. package/dist/examples/DragBlock_module.css +0 -43
  28. package/dist/examples/DragHandler.d.ts +0 -2
  29. package/dist/examples/DragHandler.js +0 -44
  30. package/dist/examples/DragHandler.module.js +0 -8
  31. package/dist/examples/DragHandler_module.css +0 -18
  32. package/dist/examples/Editor.d.ts +0 -8
  33. package/dist/examples/Editor.js +0 -44
  34. package/dist/examples/Editor.module.js +0 -12
  35. package/dist/examples/Editor_module.css +0 -127
  36. package/dist/examples/Emoji.d.ts +0 -5
  37. package/dist/examples/Emoji.js +0 -8
  38. package/dist/examples/EmojiSelector.d.ts +0 -16
  39. package/dist/examples/EmojiSelector.js +0 -91
  40. package/dist/examples/EmojiSelector.module.js +0 -7
  41. package/dist/examples/EmojiSelector_module.css +0 -36
  42. package/dist/examples/FloatingMenu.d.ts +0 -19
  43. package/dist/examples/FloatingMenu.js +0 -244
  44. package/dist/examples/FloatingMenu.module.js +0 -9
  45. package/dist/examples/FloatingMenu_module.css +0 -75
  46. package/dist/examples/LinksHint.d.ts +0 -7
  47. package/dist/examples/LinksHint.js +0 -50
  48. package/dist/examples/LinksHint.module.js +0 -6
  49. package/dist/examples/LinksHint_module.css +0 -28
  50. package/dist/examples/Menu.d.ts +0 -6
  51. package/dist/examples/Menu.js +0 -94
  52. package/dist/examples/Menu.module.js +0 -8
  53. package/dist/examples/Menu_module.css +0 -38
  54. package/dist/examples/colors.d.ts +0 -10
  55. package/dist/examples/colors.js +0 -12
  56. package/dist/examples/getCommands.d.ts +0 -2
  57. package/dist/examples/getCommands.js +0 -100
  58. package/dist/examples/getPlugins.d.ts +0 -2
  59. package/dist/examples/getPlugins.js +0 -144
  60. package/dist/examples/getShortcuts.d.ts +0 -2
  61. package/dist/examples/getShortcuts.js +0 -90
  62. package/dist/examples/icons/bold.d.ts +0 -2
  63. package/dist/examples/icons/bold.js +0 -27
  64. package/dist/examples/icons/check.d.ts +0 -2
  65. package/dist/examples/icons/check.js +0 -24
  66. package/dist/examples/icons/chevronRight.d.ts +0 -2
  67. package/dist/examples/icons/chevronRight.js +0 -24
  68. package/dist/examples/icons/code.d.ts +0 -2
  69. package/dist/examples/icons/code.js +0 -30
  70. package/dist/examples/icons/color.d.ts +0 -2
  71. package/dist/examples/icons/color.js +0 -30
  72. package/dist/examples/icons/copy.d.ts +0 -2
  73. package/dist/examples/icons/copy.js +0 -27
  74. package/dist/examples/icons/cross.d.ts +0 -2
  75. package/dist/examples/icons/cross.js +0 -27
  76. package/dist/examples/icons/drag.d.ts +0 -2
  77. package/dist/examples/icons/drag.js +0 -39
  78. package/dist/examples/icons/edit.d.ts +0 -2
  79. package/dist/examples/icons/edit.js +0 -30
  80. package/dist/examples/icons/external.d.ts +0 -2
  81. package/dist/examples/icons/external.js +0 -30
  82. package/dist/examples/icons/heading1.d.ts +0 -2
  83. package/dist/examples/icons/heading1.js +0 -45
  84. package/dist/examples/icons/heading2.d.ts +0 -2
  85. package/dist/examples/icons/heading2.js +0 -45
  86. package/dist/examples/icons/heading3.d.ts +0 -2
  87. package/dist/examples/icons/heading3.js +0 -48
  88. package/dist/examples/icons/italic.d.ts +0 -2
  89. package/dist/examples/icons/italic.js +0 -30
  90. package/dist/examples/icons/link.d.ts +0 -2
  91. package/dist/examples/icons/link.js +0 -30
  92. package/dist/examples/icons/ol.d.ts +0 -2
  93. package/dist/examples/icons/ol.js +0 -36
  94. package/dist/examples/icons/strikethrough.d.ts +0 -2
  95. package/dist/examples/icons/strikethrough.js +0 -27
  96. package/dist/examples/icons/text.d.ts +0 -2
  97. package/dist/examples/icons/text.js +0 -22
  98. package/dist/examples/icons/types.d.ts +0 -3
  99. package/dist/examples/icons/types.js +0 -0
  100. package/dist/examples/icons/ul.d.ts +0 -2
  101. package/dist/examples/icons/ul.js +0 -39
  102. package/dist/examples/icons/underline.d.ts +0 -2
  103. package/dist/examples/icons/underline.js +0 -27
  104. package/dist/examples/store.d.ts +0 -9
  105. package/dist/examples/store.js +0 -7
  106. package/dist/examples/styles.module.js +0 -11
  107. package/dist/examples/styles_module.css +0 -78
  108. package/dist/examples/text.d.ts +0 -3
  109. package/dist/examples/text.js +0 -65
  110. package/dist/examples/ui/Button/Button.d.ts +0 -8
  111. package/dist/examples/ui/Button/Button.js +0 -15
  112. package/dist/examples/ui/Button/ButtonWrapper.d.ts +0 -4
  113. package/dist/examples/ui/Button/ButtonWrapper.js +0 -14
  114. package/dist/examples/ui/Button/index.d.ts +0 -2
  115. package/dist/examples/ui/Button/index.js +0 -3
  116. package/dist/examples/ui/Button/styles.module.js +0 -10
  117. package/dist/examples/ui/Button/styles_module.css +0 -72
  118. package/dist/examples/ui/Button/types.d.ts +0 -1
  119. package/dist/examples/ui/Button/types.js +0 -0
  120. package/dist/examples/ui/Dropdown/Dropdown.d.ts +0 -16
  121. package/dist/examples/ui/Dropdown/Dropdown.js +0 -75
  122. package/dist/examples/ui/Dropdown/index.d.ts +0 -1
  123. package/dist/examples/ui/Dropdown/index.js +0 -2
  124. package/dist/examples/ui/Menu/Menu.d.ts +0 -41
  125. package/dist/examples/ui/Menu/Menu.js +0 -404
  126. package/dist/examples/ui/Menu/MenuDelimiter.d.ts +0 -1
  127. package/dist/examples/ui/Menu/MenuDelimiter.js +0 -6
  128. package/dist/examples/ui/Menu/MenuHotkey.d.ts +0 -6
  129. package/dist/examples/ui/Menu/MenuHotkey.js +0 -12
  130. package/dist/examples/ui/Menu/MenuIcon.d.ts +0 -6
  131. package/dist/examples/ui/Menu/MenuIcon.js +0 -12
  132. package/dist/examples/ui/Menu/MenuItem.d.ts +0 -6
  133. package/dist/examples/ui/Menu/MenuItem.js +0 -17
  134. package/dist/examples/ui/Menu/MenuTitle.d.ts +0 -6
  135. package/dist/examples/ui/Menu/MenuTitle.js +0 -12
  136. package/dist/examples/ui/Menu/SafeSpace.d.ts +0 -6
  137. package/dist/examples/ui/Menu/SafeSpace.js +0 -65
  138. package/dist/examples/ui/Menu/index.d.ts +0 -2
  139. package/dist/examples/ui/Menu/index.js +0 -2
  140. package/dist/examples/ui/Menu/styles.module.js +0 -21
  141. package/dist/examples/ui/Menu/styles_module.css +0 -140
  142. package/dist/examples/ui/Menu/types.d.ts +0 -16
  143. package/dist/examples/ui/Menu/types.js +0 -0
  144. package/dist/examples/ui/useMenuPosition.d.ts +0 -18
  145. package/dist/examples/ui/useMenuPosition.js +0 -51
  146. package/dist/examples/ui/useMergeRefs.d.ts +0 -23
  147. package/dist/examples/ui/useMergeRefs.js +0 -11
  148. package/src/examples/Backdrop.module.css +0 -8
  149. package/src/examples/Backdrop.tsx +0 -16
  150. package/src/examples/CodeBlock.module.css +0 -65
  151. package/src/examples/CodeBlock.tsx +0 -109
  152. package/src/examples/DragBlock.module.css +0 -42
  153. package/src/examples/DragBlock.tsx +0 -57
  154. package/src/examples/DragHandler.module.css +0 -17
  155. package/src/examples/DragHandler.tsx +0 -39
  156. package/src/examples/Editor.module.css +0 -129
  157. package/src/examples/Editor.tsx +0 -68
  158. package/src/examples/Emoji.tsx +0 -9
  159. package/src/examples/EmojiSelector.module.css +0 -35
  160. package/src/examples/EmojiSelector.tsx +0 -115
  161. package/src/examples/FloatingMenu.module.css +0 -74
  162. package/src/examples/FloatingMenu.tsx +0 -278
  163. package/src/examples/LinksHint.module.css +0 -27
  164. package/src/examples/LinksHint.tsx +0 -58
  165. package/src/examples/Menu.module.css +0 -37
  166. package/src/examples/Menu.tsx +0 -94
  167. package/src/examples/colors.ts +0 -11
  168. package/src/examples/getCommands.tsx +0 -92
  169. package/src/examples/getPlugins.tsx +0 -164
  170. package/src/examples/getShortcuts.ts +0 -107
  171. package/src/examples/icons/bold.tsx +0 -20
  172. package/src/examples/icons/check.tsx +0 -19
  173. package/src/examples/icons/chevronRight.tsx +0 -19
  174. package/src/examples/icons/code.tsx +0 -21
  175. package/src/examples/icons/color.tsx +0 -23
  176. package/src/examples/icons/copy.tsx +0 -20
  177. package/src/examples/icons/cross.tsx +0 -20
  178. package/src/examples/icons/drag.tsx +0 -24
  179. package/src/examples/icons/edit.tsx +0 -21
  180. package/src/examples/icons/external.tsx +0 -21
  181. package/src/examples/icons/heading1.tsx +0 -26
  182. package/src/examples/icons/heading2.tsx +0 -26
  183. package/src/examples/icons/heading3.tsx +0 -27
  184. package/src/examples/icons/italic.tsx +0 -21
  185. package/src/examples/icons/link.tsx +0 -21
  186. package/src/examples/icons/ol.tsx +0 -23
  187. package/src/examples/icons/strikethrough.tsx +0 -20
  188. package/src/examples/icons/text.tsx +0 -18
  189. package/src/examples/icons/types.ts +0 -3
  190. package/src/examples/icons/ul.tsx +0 -24
  191. package/src/examples/icons/underline.tsx +0 -20
  192. package/src/examples/store.ts +0 -16
  193. package/src/examples/styles.module.css +0 -77
  194. package/src/examples/text.tsx +0 -138
  195. package/src/examples/ui/Button/Button.tsx +0 -34
  196. package/src/examples/ui/Button/ButtonWrapper.tsx +0 -22
  197. package/src/examples/ui/Button/index.ts +0 -2
  198. package/src/examples/ui/Button/styles.module.css +0 -75
  199. package/src/examples/ui/Button/types.ts +0 -1
  200. package/src/examples/ui/Dropdown/Dropdown.tsx +0 -101
  201. package/src/examples/ui/Dropdown/index.ts +0 -1
  202. package/src/examples/ui/Menu/Menu.tsx +0 -576
  203. package/src/examples/ui/Menu/MenuDelimiter.tsx +0 -3
  204. package/src/examples/ui/Menu/MenuHotkey.tsx +0 -17
  205. package/src/examples/ui/Menu/MenuIcon.tsx +0 -17
  206. package/src/examples/ui/Menu/MenuItem.tsx +0 -45
  207. package/src/examples/ui/Menu/MenuTitle.tsx +0 -17
  208. package/src/examples/ui/Menu/SafeSpace.tsx +0 -84
  209. package/src/examples/ui/Menu/index.ts +0 -2
  210. package/src/examples/ui/Menu/styles.module.css +0 -143
  211. package/src/examples/ui/Menu/types.ts +0 -18
  212. package/src/examples/ui/useMenuPosition.ts +0 -72
  213. package/src/examples/ui/useMergeRefs.ts +0 -39
@@ -1,14 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import styles_module from "./styles.module.js";
4
- const ButtonWrapper = /*#__PURE__*/ forwardRef((props, ref)=>{
5
- const { size, variant = 'secondary', className, ...rest } = props;
6
- const sizeClass = styles_module[`size${size.charAt(0).toUpperCase()}${size.slice(1)}`];
7
- const variantClass = styles_module[variant];
8
- return /*#__PURE__*/ jsx("button", {
9
- ref: ref,
10
- className: `${styles_module.button} ${sizeClass} ${variantClass} ${className || ''}`,
11
- ...rest
12
- });
13
- });
14
- export { ButtonWrapper };
@@ -1,2 +0,0 @@
1
- export { Button } from './Button';
2
- export { ButtonWrapper } from './ButtonWrapper';
@@ -1,3 +0,0 @@
1
- import { Button } from "./Button.js";
2
- import { ButtonWrapper } from "./ButtonWrapper.js";
3
- export { Button, ButtonWrapper };
@@ -1,10 +0,0 @@
1
- import "./styles_module.css";
2
- const styles_module = {
3
- button: "button-sJxDuy",
4
- sizeSm: "sizeSm-iMrC7k",
5
- sizeMd: "sizeMd-O5aM4H",
6
- sizeLg: "sizeLg-qDIX7h",
7
- secondary: "secondary-pZ6jNc",
8
- transparent: "transparent-HNysWI"
9
- };
10
- export { styles_module as default };
@@ -1,72 +0,0 @@
1
- .button-sJxDuy {
2
- user-select: none;
3
- border-style: solid;
4
- border-width: 1px;
5
- border-radius: 4px;
6
- outline: none;
7
- justify-content: center;
8
- align-items: center;
9
- column-gap: 4px;
10
- font-size: 12px;
11
- transition: background-color, border .1s ease-in-out;
12
- display: flex;
13
- }
14
-
15
- .sizeSm-iMrC7k {
16
- height: 28px;
17
- padding: 4px;
18
- }
19
-
20
- .sizeMd-O5aM4H {
21
- height: 32px;
22
- padding: 4px 8px;
23
- }
24
-
25
- .sizeLg-qDIX7h {
26
- height: 36px;
27
- padding: 4px 12px;
28
- }
29
-
30
- .secondary-pZ6jNc {
31
- color: var(--kona-editor-text-color, #444);
32
- background-color: var(--kona-editor-background-color, #fff);
33
- border-color: var(--kona-editor-border-color, #ddd);
34
- }
35
-
36
- .secondary-pZ6jNc:disabled {
37
- color: #999;
38
- background-color: #f0f0f0;
39
- }
40
-
41
- .secondary-pZ6jNc:focus {
42
- border-color: #0000;
43
- outline: 1px solid #06c;
44
- }
45
-
46
- .secondary-pZ6jNc:hover:not(:disabled) {
47
- background-color: var(--kona-editor-background-color, #f0f0f0);
48
- }
49
-
50
- .transparent-HNysWI {
51
- color: #333;
52
- background-color: #0000;
53
- border-color: #0000;
54
- }
55
-
56
- .transparent-HNysWI:disabled {
57
- color: #999;
58
- }
59
-
60
- .transparent-HNysWI:focus {
61
- border-color: #0000;
62
- outline: 1px solid #06c;
63
- }
64
-
65
- .transparent-HNysWI:hover:not(:disabled) {
66
- background-color: #0000000d;
67
- }
68
-
69
- .button-sJxDuy:active:not(:disabled) {
70
- transform: scale(.95);
71
- }
72
-
@@ -1 +0,0 @@
1
- export type ButtonVariant = 'primary' | 'secondary' | 'transparent';
File without changes
@@ -1,16 +0,0 @@
1
- import { type JSX, type RefObject } from 'react';
2
- import { type MenuConfig } from '../Menu';
3
- type ChildrenProps = {
4
- ref: RefObject<any>;
5
- onClick: () => void;
6
- };
7
- type DropdownProps = {
8
- config: MenuConfig;
9
- children: (props: ChildrenProps) => React.ReactNode;
10
- target?: HTMLElement;
11
- Menu?: JSX.ElementType;
12
- MenuBody?: JSX.ElementType;
13
- onClose?: () => void;
14
- };
15
- export declare const Dropdown: (props: DropdownProps) => import("react/jsx-runtime").JSX.Element;
16
- export {};
@@ -1,75 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useLayoutEffect, useRef, useState } from "react";
3
- import { Menu } from "../Menu/index.js";
4
- import { useMenuPosition } from "../useMenuPosition.js";
5
- const Dropdown = (props)=>{
6
- const { config, target, children, onClose = ()=>{}, Menu: MenuComponent, MenuBody } = props;
7
- const [rect, setRect] = useState();
8
- const [isOpen, setOpen] = useState(false);
9
- const ref = useRef(null);
10
- const menuRef = useRef(null);
11
- useLayoutEffect(()=>{
12
- if (ref.current) {
13
- const rect = ref.current.getBoundingClientRect();
14
- setRect(rect);
15
- }
16
- }, [
17
- isOpen
18
- ]);
19
- const coords = {
20
- x: rect?.left ?? 0,
21
- y: (rect?.top ?? 0) + (rect?.height ?? 0)
22
- };
23
- const [transform, newCoords] = useMenuPosition(coords, (context)=>{
24
- const [horizontal, vertical] = context.helpers.isWithinWindow();
25
- if (!vertical) context.flip([
26
- false,
27
- true
28
- ]).move(0, -(rect?.height ?? 0));
29
- if (!horizontal) context.flip([
30
- true,
31
- false
32
- ]).move(rect?.width ?? 0, 0);
33
- return context.point;
34
- });
35
- const changeOpen = (value)=>{
36
- setOpen(value);
37
- if (!value) onClose();
38
- };
39
- useLayoutEffect(()=>{
40
- if (menuRef.current) transform(menuRef.current);
41
- }, [
42
- isOpen,
43
- rect?.left,
44
- rect?.top,
45
- config
46
- ]);
47
- const handleClick = ()=>{
48
- changeOpen(!isOpen);
49
- };
50
- const handleToggle = (value)=>{
51
- changeOpen(void 0 === value ? !isOpen : value);
52
- };
53
- return /*#__PURE__*/ jsxs(Fragment, {
54
- children: [
55
- children({
56
- ref,
57
- onClick: handleClick
58
- }),
59
- /*#__PURE__*/ jsx(Menu, {
60
- target: target,
61
- ref: menuRef,
62
- Menu: MenuComponent,
63
- MenuBody: MenuBody,
64
- coords: [
65
- newCoords.x,
66
- newCoords.y
67
- ],
68
- isOpen: isOpen,
69
- config: config,
70
- onToggle: handleToggle
71
- })
72
- ]
73
- });
74
- };
75
- export { Dropdown };
@@ -1 +0,0 @@
1
- export { Dropdown } from './Dropdown';
@@ -1,2 +0,0 @@
1
- import { Dropdown } from "./Dropdown.js";
2
- export { Dropdown };
@@ -1,41 +0,0 @@
1
- import { type JSX } from 'react';
2
- import { MenuDelimiter } from './MenuDelimiter';
3
- import { MenuHotkey } from './MenuHotkey';
4
- import { MenuIcon } from './MenuIcon';
5
- import { MenuItem } from './MenuItem';
6
- import { MenuTitle } from './MenuTitle';
7
- import type { MenuConfig } from './types';
8
- type Coords = [number, number];
9
- type MenuProps = {
10
- config: MenuConfig;
11
- className?: string;
12
- isOpen?: boolean;
13
- coords: Coords;
14
- target?: HTMLElement;
15
- onToggle?: (isOpen?: boolean) => void;
16
- Menu?: JSX.ElementType;
17
- MenuBody?: JSX.ElementType;
18
- };
19
- /**
20
- * Component for rendering various types of menus.
21
- */
22
- export declare const MenuComponent: import("react").ForwardRefExoticComponent<MenuProps & import("react").RefAttributes<HTMLMenuElement>>;
23
- export declare const Menu: typeof MenuComponent & {
24
- Root: typeof Root;
25
- Body: typeof MenuBody;
26
- Item: typeof MenuItem;
27
- Icon: typeof MenuIcon;
28
- Title: typeof MenuTitle;
29
- Hotkey: typeof MenuHotkey;
30
- Delimiter: typeof MenuDelimiter;
31
- };
32
- interface RootProps extends React.MenuHTMLAttributes<HTMLMenuElement> {
33
- coords: Coords;
34
- className?: string;
35
- }
36
- declare const Root: import("react").ForwardRefExoticComponent<RootProps & import("react").RefAttributes<HTMLMenuElement>>;
37
- interface MenuBodyProps extends React.HTMLAttributes<HTMLDivElement> {
38
- className?: string;
39
- }
40
- declare const MenuBody: import("react").ForwardRefExoticComponent<MenuBodyProps & import("react").RefAttributes<HTMLDivElement>>;
41
- export {};
@@ -1,404 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import clsx from "clsx";
3
- import { forwardRef, useEffect, useLayoutEffect, useRef, useState } from "react";
4
- import { createPortal } from "react-dom";
5
- import { ChevronRightIcon } from "../../icons/chevronRight.js";
6
- import { useMenuPosition } from "../useMenuPosition.js";
7
- import { useMergeRefs } from "../useMergeRefs.js";
8
- import { MenuDelimiter } from "./MenuDelimiter.js";
9
- import { MenuHotkey } from "./MenuHotkey.js";
10
- import { MenuIcon } from "./MenuIcon.js";
11
- import { MenuItem } from "./MenuItem.js";
12
- import { MenuTitle } from "./MenuTitle.js";
13
- import { SafeSpace } from "./SafeSpace.js";
14
- import styles_module from "./styles.module.js";
15
- const MenuComponent = /*#__PURE__*/ forwardRef((props, menuRef)=>{
16
- const { isOpen, className, coords, config, Menu: MenuRootComponent, MenuBody, onToggle, target = document.body } = props;
17
- const ref = useRef(null);
18
- const mergedRef = useMergeRefs([
19
- menuRef,
20
- ref
21
- ]);
22
- const refs = useRef({});
23
- const [rects, setRects] = useState({});
24
- const [prevSelected, setPrevSelected] = useState([]);
25
- const [selected, setSelected] = useState([]);
26
- const isSelected = (index, level)=>selected[level] === index;
27
- const getConfig = (path, level)=>path.slice(0, level + 1).reduce((prev, current)=>(prev || config).items?.[current]?.config || null, null);
28
- const getCurrentConfig = (path)=>{
29
- if (1 === path.length) return config;
30
- return path.reduce((prev = config, current)=>{
31
- const currentConfig = prev || config;
32
- return currentConfig.items?.[current]?.config || prev;
33
- }, null);
34
- };
35
- const updateRect = (path)=>{
36
- const rect = refs.current[path.join(',')]?.getBoundingClientRect();
37
- setRects({
38
- ...rects,
39
- [path.join(',')]: rect
40
- });
41
- };
42
- useLayoutEffect(()=>{
43
- if (ref.current) {
44
- const rect = ref.current.getBoundingClientRect();
45
- setRects({
46
- '@': rect
47
- });
48
- }
49
- }, [
50
- isOpen
51
- ]);
52
- useEffect(()=>{
53
- if (isOpen) {
54
- const firstSelectable = config.items?.findIndex((item)=>item.selectable ?? true);
55
- if (void 0 !== firstSelectable) setSelected([
56
- firstSelectable
57
- ]);
58
- }
59
- }, [
60
- isOpen
61
- ]);
62
- useEffect(()=>{
63
- if (!isOpen) return;
64
- let timeout;
65
- selected.forEach((_, level)=>{
66
- const config = 0 === level ? props.config : getConfig(selected, level);
67
- if (config?.onOpen && prevSelected[level] !== selected[level]) timeout = setTimeout(()=>{
68
- config.onOpen?.();
69
- });
70
- });
71
- setPrevSelected(selected);
72
- return ()=>{
73
- clearTimeout(timeout);
74
- };
75
- }, [
76
- selected,
77
- isOpen
78
- ]);
79
- const currentConfig = getCurrentConfig(selected);
80
- useEffect(()=>{
81
- if (isOpen) {
82
- const handleKeyDown = (event)=>{
83
- switch(event.key){
84
- case 'ArrowDown':
85
- {
86
- const firstSelectableIndex = currentConfig?.items?.findIndex((item)=>item.selectable ?? true) ?? -1;
87
- const nextSelectableIndex = currentConfig?.items?.findIndex((item, index)=>(item.selectable ?? true) && index > selected[selected.length - 1]);
88
- if (nextSelectableIndex) setSelected((selected)=>{
89
- const newSelected = [
90
- ...selected.slice(0, selected.length - 1),
91
- -1 === nextSelectableIndex ? firstSelectableIndex : nextSelectableIndex
92
- ];
93
- updateRect(newSelected);
94
- refs.current[newSelected.join(',')]?.scrollIntoView({
95
- block: 'nearest'
96
- });
97
- return newSelected;
98
- });
99
- event.preventDefault();
100
- event.stopPropagation();
101
- break;
102
- }
103
- case 'ArrowUp':
104
- {
105
- if (!currentConfig?.items?.length) return;
106
- const lastSelectableIndex = currentConfig?.items?.reduce((acc, item, index)=>item.selectable ?? true ? index : acc, -1);
107
- const prevSelectableIndex = currentConfig?.items?.slice(0, selected[selected.length - 1]).reverse().findIndex((item)=>item.selectable ?? true);
108
- const newSelected = [
109
- ...selected.slice(0, selected.length - 1),
110
- -1 === prevSelectableIndex ? lastSelectableIndex : selected[selected.length - 1] - prevSelectableIndex - 1
111
- ];
112
- setSelected(()=>{
113
- updateRect(newSelected);
114
- refs.current[newSelected.join(',')].scrollIntoView({
115
- block: 'nearest'
116
- });
117
- return newSelected;
118
- });
119
- event.preventDefault();
120
- event.stopPropagation();
121
- break;
122
- }
123
- case 'ArrowRight':
124
- {
125
- const currentItem = currentConfig?.items?.[selected[selected.length - 1]];
126
- if (currentItem?.config?.items) {
127
- const firstSelectableIndex = currentConfig?.items?.findIndex((item)=>item.selectable ?? true);
128
- if (void 0 !== firstSelectableIndex) setSelected((selected)=>{
129
- const newSelected = [
130
- ...selected,
131
- firstSelectableIndex
132
- ];
133
- updateRect(newSelected);
134
- return newSelected;
135
- });
136
- currentItem.config?.onFocus?.();
137
- }
138
- event.preventDefault();
139
- event.stopPropagation();
140
- break;
141
- }
142
- case 'ArrowLeft':
143
- setSelected((selected)=>selected.slice(0, selected.length - 1));
144
- event.preventDefault();
145
- event.stopPropagation();
146
- break;
147
- case 'Escape':
148
- onToggle?.(false);
149
- event.preventDefault();
150
- event.stopPropagation();
151
- break;
152
- case 'Enter':
153
- {
154
- const currentItem = currentConfig?.items?.[selected[selected.length - 1]];
155
- if (currentItem?.onSelect) currentItem.onSelect();
156
- onToggle?.(false);
157
- event.preventDefault();
158
- event.stopPropagation();
159
- break;
160
- }
161
- case ' ':
162
- {
163
- const currentItem = currentConfig?.items?.[selected[selected.length - 1]];
164
- if (currentItem?.onSelect) currentItem.onSelect();
165
- event.preventDefault();
166
- event.stopPropagation();
167
- break;
168
- }
169
- }
170
- };
171
- document.addEventListener('keydown', handleKeyDown);
172
- return ()=>{
173
- document.removeEventListener('keydown', handleKeyDown);
174
- };
175
- }
176
- }, [
177
- isOpen,
178
- currentConfig,
179
- selected
180
- ]);
181
- const renderSubMenu = ()=>selected.map((_, selectedIndex)=>{
182
- const config = getConfig(selected, selectedIndex);
183
- const items = config?.items;
184
- const path = selected.slice(0, selectedIndex + 1).join(',');
185
- const rect = rects[path];
186
- if (!rect || !items) return null;
187
- const coords = [
188
- rect.left + rect.width,
189
- rect.top
190
- ];
191
- return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs(InnerMenu, {
192
- rect: rect,
193
- coords: coords,
194
- Menu: MenuRootComponent,
195
- MenuBody: MenuBody,
196
- children: [
197
- config?.header?.(),
198
- /*#__PURE__*/ jsx(Scrollable, {
199
- children: items.map((item, index)=>/*#__PURE__*/ jsxs(MenuItem, {
200
- ref: (element)=>{
201
- if (element && (item.selectable ?? true)) {
202
- const selectedPath = [
203
- ...selected.slice(0, selectedIndex + 1),
204
- index
205
- ];
206
- refs.current[selectedPath.join(',')] = element;
207
- }
208
- },
209
- selectable: item.selectable,
210
- isSelected: isSelected(index, selectedIndex + 1),
211
- onMouseEnter: (event)=>{
212
- if (item.selectable ?? true) {
213
- const selectedPath = [
214
- ...selected.slice(0, selectedIndex + 1),
215
- index
216
- ];
217
- const rect = event.currentTarget.getBoundingClientRect();
218
- setSelected(selectedPath);
219
- setRects((rects)=>({
220
- ...rects,
221
- [selectedPath.join(',')]: rect
222
- }));
223
- }
224
- },
225
- onClick: ()=>{
226
- const autoClose = item.autoClose ?? true;
227
- autoClose && onToggle?.(false);
228
- item.onSelect?.();
229
- },
230
- children: [
231
- item.render(),
232
- item.config?.items && /*#__PURE__*/ jsx(ChevronRightIcon, {
233
- size: 16
234
- })
235
- ]
236
- }, index))
237
- }),
238
- config?.footer?.()
239
- ]
240
- }, path), target);
241
- });
242
- if (!isOpen) return null;
243
- return /*#__PURE__*/ jsxs(Fragment, {
244
- children: [
245
- /*#__PURE__*/ createPortal(/*#__PURE__*/ jsxs(Fragment, {
246
- children: [
247
- /*#__PURE__*/ jsxs(InnerMenu, {
248
- className: className,
249
- ref: mergedRef,
250
- coords: coords,
251
- rect: rects['@'],
252
- Menu: MenuRootComponent,
253
- MenuBody: MenuBody,
254
- root: true,
255
- children: [
256
- config?.header?.(),
257
- /*#__PURE__*/ jsx(Scrollable, {
258
- children: config.items?.map((item, index)=>/*#__PURE__*/ jsxs(MenuItem, {
259
- ref: (element)=>{
260
- if (element && (item.selectable ?? true)) refs.current[index] = element;
261
- },
262
- selectable: item.selectable,
263
- isSelected: isSelected(index, 0),
264
- onMouseEnter: (event)=>{
265
- if (item.selectable ?? true) {
266
- const rect = event.currentTarget.getBoundingClientRect();
267
- setSelected([
268
- index
269
- ]);
270
- setRects((rects)=>({
271
- ...rects,
272
- [index]: rect
273
- }));
274
- }
275
- },
276
- onClick: ()=>{
277
- const autoClose = item.autoClose ?? true;
278
- autoClose && onToggle?.(false);
279
- item.onSelect?.();
280
- },
281
- children: [
282
- item.render(),
283
- item.config?.items && /*#__PURE__*/ jsx(ChevronRightIcon, {
284
- size: 16
285
- })
286
- ]
287
- }, index))
288
- }),
289
- config?.footer?.()
290
- ]
291
- }),
292
- /*#__PURE__*/ jsx(Backdrop, {
293
- onClick: ()=>onToggle?.(false)
294
- })
295
- ]
296
- }), target),
297
- renderSubMenu()
298
- ]
299
- });
300
- });
301
- const InnerMenu = /*#__PURE__*/ forwardRef((props, ref)=>{
302
- const { root, className, coords, rect, children, Menu: MenuRootComponent = Root, MenuBody: MenuBodyComponent = Menu_MenuBody } = props;
303
- const [itemRect, setItemRect] = useState();
304
- const itemRef = useRef(null);
305
- const [transform, newCoords] = useMenuPosition({
306
- x: coords[0],
307
- y: coords[1]
308
- }, (context)=>{
309
- const [horizontal, vertical] = context.helpers.isWithinWindow();
310
- if (root) return context.point;
311
- if (!rect) return context.point;
312
- if (!horizontal) context.flip([
313
- true,
314
- false
315
- ]).move(-rect?.width, 0).move(-4, 0);
316
- if (!vertical) context.flip([
317
- false,
318
- true
319
- ]).move(0, rect?.height).move(0, -4);
320
- return context.point;
321
- });
322
- useLayoutEffect(()=>{
323
- if (itemRef.current && !root) transform(itemRef.current);
324
- }, [
325
- coords[0],
326
- coords[1],
327
- root
328
- ]);
329
- useEffect(()=>{
330
- if (itemRef.current) setItemRect(itemRef.current.getBoundingClientRect());
331
- }, [
332
- newCoords
333
- ]);
334
- const menuCoords = root ? coords : [
335
- newCoords.x,
336
- newCoords.y
337
- ];
338
- return /*#__PURE__*/ jsxs(Fragment, {
339
- children: [
340
- !root && /*#__PURE__*/ jsx(SafeSpace, {
341
- rect: itemRect
342
- }),
343
- /*#__PURE__*/ jsx(MenuRootComponent, {
344
- className: className,
345
- ref: ref,
346
- coords: menuCoords,
347
- style: {
348
- left: menuCoords[0],
349
- top: menuCoords[1]
350
- },
351
- children: /*#__PURE__*/ jsx(MenuBodyComponent, {
352
- ref: itemRef,
353
- children: children
354
- })
355
- })
356
- ]
357
- });
358
- });
359
- const Menu = MenuComponent;
360
- const Root = /*#__PURE__*/ forwardRef((props, ref)=>{
361
- const { coords, className, children, ...rest } = props;
362
- return /*#__PURE__*/ jsx("menu", {
363
- ref: ref,
364
- className: clsx(styles_module.menu, styles_module.menuEnterAnimation, className),
365
- style: {
366
- left: coords[0],
367
- top: coords[1]
368
- },
369
- ...rest,
370
- children: children
371
- });
372
- });
373
- const Menu_MenuBody = /*#__PURE__*/ forwardRef((props, ref)=>{
374
- const { className, children, ...rest } = props;
375
- return /*#__PURE__*/ jsx("div", {
376
- ref: ref,
377
- className: clsx(styles_module.menuBody, className),
378
- ...rest,
379
- children: children
380
- });
381
- });
382
- const Scrollable = (props)=>{
383
- const { className, children, ...rest } = props;
384
- return /*#__PURE__*/ jsx("div", {
385
- className: clsx(styles_module.menuScrollable, className),
386
- ...rest,
387
- children: children
388
- });
389
- };
390
- const Backdrop = (props)=>{
391
- const { className, ...rest } = props;
392
- return /*#__PURE__*/ jsx("div", {
393
- className: clsx(styles_module.menuBackdrop, className),
394
- ...rest
395
- });
396
- };
397
- Menu.Root = Root;
398
- Menu.Body = Menu_MenuBody;
399
- Menu.Item = MenuItem;
400
- Menu.Icon = MenuIcon;
401
- Menu.Title = MenuTitle;
402
- Menu.Hotkey = MenuHotkey;
403
- Menu.Delimiter = MenuDelimiter;
404
- export { Menu, MenuComponent };
@@ -1 +0,0 @@
1
- export declare const MenuDelimiter: () => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import styles_module from "./styles.module.js";
3
- const MenuDelimiter = ()=>/*#__PURE__*/ jsx("hr", {
4
- className: styles_module.delimiter
5
- });
6
- export { MenuDelimiter };
@@ -1,6 +0,0 @@
1
- type MenuHotkeyProps = {
2
- children: React.ReactNode;
3
- className?: string;
4
- };
5
- export declare const MenuHotkey: (props: MenuHotkeyProps) => import("react/jsx-runtime").JSX.Element;
6
- export {};