@dxos/react-ui-menu 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446

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 (51) hide show
  1. package/dist/lib/browser/index.mjs +63 -58
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +58 -53
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +63 -58
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/ActionLabel.d.ts +4 -8
  11. package/dist/types/src/components/ActionLabel.d.ts.map +1 -1
  12. package/dist/types/src/components/DropdownMenu.d.ts +2 -3
  13. package/dist/types/src/components/DropdownMenu.d.ts.map +1 -1
  14. package/dist/types/src/components/MenuContext.d.ts +13 -4
  15. package/dist/types/src/components/MenuContext.d.ts.map +1 -1
  16. package/dist/types/src/components/ToolbarMenu.d.ts +1 -5
  17. package/dist/types/src/components/ToolbarMenu.d.ts.map +1 -1
  18. package/dist/types/src/{types.d.ts → defs.d.ts} +5 -3
  19. package/dist/types/src/defs.d.ts.map +1 -0
  20. package/dist/types/src/hooks.d.ts +17 -0
  21. package/dist/types/src/hooks.d.ts.map +1 -0
  22. package/dist/types/src/index.d.ts +1 -1
  23. package/dist/types/src/index.d.ts.map +1 -1
  24. package/dist/types/src/{components → testing}/Menus.stories.d.ts +1 -1
  25. package/dist/types/src/testing/Menus.stories.d.ts.map +1 -0
  26. package/dist/types/src/testing/index.d.ts +25 -1
  27. package/dist/types/src/testing/index.d.ts.map +1 -1
  28. package/dist/types/src/util.d.ts +2 -2
  29. package/dist/types/src/util.d.ts.map +1 -1
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +12 -18
  32. package/src/components/ActionLabel.tsx +8 -11
  33. package/src/components/DropdownMenu.tsx +5 -5
  34. package/src/components/MenuContext.tsx +26 -11
  35. package/src/components/ToolbarMenu.tsx +29 -27
  36. package/src/{types.ts → defs.ts} +5 -2
  37. package/src/{hooks/useMenuActions.ts → hooks.ts} +20 -20
  38. package/src/index.ts +1 -1
  39. package/src/{components → testing}/Menus.stories.tsx +13 -13
  40. package/src/testing/index.ts +107 -1
  41. package/src/util.ts +7 -7
  42. package/dist/types/src/components/Menus.stories.d.ts.map +0 -1
  43. package/dist/types/src/hooks/index.d.ts +0 -2
  44. package/dist/types/src/hooks/index.d.ts.map +0 -1
  45. package/dist/types/src/hooks/useMenuActions.d.ts +0 -12
  46. package/dist/types/src/hooks/useMenuActions.d.ts.map +0 -1
  47. package/dist/types/src/testing/generator.d.ts +0 -26
  48. package/dist/types/src/testing/generator.d.ts.map +0 -1
  49. package/dist/types/src/types.d.ts.map +0 -1
  50. package/src/hooks/index.ts +0 -5
  51. package/src/testing/generator.ts +0 -115
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type ToolbarRootProps } from '@dxos/react-ui';
3
3
  import { type MenuScopedProps } from './MenuContext';
4
- import { type MenuAction, type MenuItem, type MenuItemGroup, type MenuActionProperties, type MenuMultipleSelectActionGroup, type MenuSingleSelectActionGroup } from '../types';
4
+ import { type MenuItem, type MenuItemGroup, type MenuActionProperties, type MenuMultipleSelectActionGroup, type MenuSingleSelectActionGroup } from '../defs';
5
5
  export type ToolbarMenuDropdownMenuActionGroup = Omit<MenuActionProperties, 'variant' | 'icon'> & {
6
6
  variant: 'dropdownMenu';
7
7
  icon: string;
@@ -16,9 +16,5 @@ export type ToolbarMenuActionGroupProps = {
16
16
  group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
17
17
  items?: MenuItem[];
18
18
  };
19
- export type ToolbarMenuActionProps = {
20
- group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
21
- action: MenuAction;
22
- };
23
19
  export declare const ToolbarMenu: ({ __menuScope, classNames, ...props }: MenuScopedProps<ToolbarMenuProps>) => React.JSX.Element;
24
20
  //# sourceMappingURL=ToolbarMenu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolbarMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ToolbarMenu.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAmC,KAAK,gBAAgB,EAAkB,MAAM,gBAAgB,CAAC;AAKxG,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,eAAe,CAAC;AAE5E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EAGb,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EACjC,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,kCAAkC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,MAAM,CAAC,GAAG;IAChG,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG;IACtF,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,CAC3C,kCAAkC,GAClC,iCAAiC,CACpC,GACC,CAAC,2BAA2B,GAAG,6BAA6B,CAAC,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,MAAM,EAAE,UAAU,CAAC;CACpB,CAAC;AAyGF,eAAO,MAAM,WAAW,GAAI,uCAAuC,eAAe,CAAC,gBAAgB,CAAC,sBA2BnG,CAAC"}
1
+ {"version":3,"file":"ToolbarMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ToolbarMenu.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAyD,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAK9G,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,eAAe,CAAC;AAC5E,OAAO,EAEL,KAAK,QAAQ,EAGb,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EACjC,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,kCAAkC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,MAAM,CAAC,GAAG;IAChG,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG;IACtF,OAAO,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,CAC3C,kCAAkC,GAClC,iCAAiC,CACpC,GACC,CAAC,2BAA2B,GAAG,6BAA6B,CAAC,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEhD,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,aAAa,CAAC,gCAAgC,CAAC,CAAC;IACvD,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB,CAAC;AAiHF,eAAO,MAAM,WAAW,0CAA2C,eAAe,CAAC,gBAAgB,CAAC,sBA2BnG,CAAC"}
@@ -18,6 +18,7 @@ export type MenuItemGroupProperties = {
18
18
  iconOnly?: boolean;
19
19
  };
20
20
  export type MenuAction<P extends {} = {}> = Action<P & MenuActionProperties>;
21
+ export type MenuActionHandler<A extends Node = MenuAction> = (action: A) => void;
21
22
  export declare const MenuSeparatorType: "@dxos/react-ui-toolbar/separator";
22
23
  export type MenuSeparator = Node<never, Pick<ToolbarSeparatorProps, 'variant'>> & {
23
24
  type: typeof MenuSeparatorType;
@@ -35,9 +36,10 @@ export type MenuItemGroup<P extends Record<string, any> = Record<string, any>> =
35
36
  export declare const isMenuGroup: (node: Node) => node is MenuItemGroup;
36
37
  export type MenuItem = MenuSeparator | MenuAction | MenuItemGroup;
37
38
  export type MenuItemsResolver = (group?: MenuItemGroup) => MenuItem[] | null;
38
- export type MenuContextValue = {
39
- useGroupItems: MenuItemsResolver;
39
+ export type MenuContextValue<A extends Node = MenuAction> = {
40
+ resolveGroupItems: MenuItemsResolver;
40
41
  iconSize: IconButtonProps['size'];
42
+ onAction: MenuActionHandler<A>;
41
43
  attendableId?: string;
42
44
  };
43
- //# sourceMappingURL=types.d.ts.map
45
+ //# sourceMappingURL=defs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEnH,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC;AAE7E,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;AAEjF,eAAO,MAAM,iBAAiB,EAAG,kCAA2C,CAAC;AAE7E,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,GAAG;IAChF,IAAI,EAAE,OAAO,iBAAiB,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,WAAW,SAAU,IAAI,KAAG,IAAI,IAAI,aAAgD,CAAC;AAElG,MAAM,MAAM,2BAA2B,GAAG;IAAE,iBAAiB,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACzF,MAAM,MAAM,6BAA6B,GAAG;IAAE,iBAAiB,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;AAEhG,eAAO,MAAM,WAAW,SAAU,IAAI,KAAG,IAAI,IAAI,aAAgD,CAAC;AAElG,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,aAAa,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC,EAAE,aAAa,KAAK,QAAQ,EAAE,GAAG,IAAI,CAAC;AAE7E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,IAAI,GAAG,UAAU,IAAI;IAC1D,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type NodeArg } from '@dxos/app-graph';
2
+ import { type MenuItem, type MenuItemGroup } from './defs';
3
+ type Edge = {
4
+ source: string;
5
+ target: string;
6
+ };
7
+ export type ActionGraphNodes = NodeArg<any>[];
8
+ export type ActionGraphEdges = Edge[];
9
+ export type ActionGraphProps = {
10
+ nodes: ActionGraphNodes;
11
+ edges: ActionGraphEdges;
12
+ };
13
+ export declare const useMenuActions: (actionCreator: () => ActionGraphProps) => {
14
+ resolveGroupItems: (sourceNode?: MenuItemGroup) => MenuItem[] | null;
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,KAAK,OAAO,EAAa,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE3D,KAAK,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA6B/C,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,EAAE,CAAC;AACtC,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,cAAc,kBAAmB,MAAM,gBAAgB;qCAgBnD,aAAa;CAW7B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export * from './components';
2
+ export * from './defs';
2
3
  export * from './hooks';
3
- export * from './types';
4
4
  export { createMenuAction, createMenuItemGroup, createLineSeparator, createGapSeparator } from './util';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC"}
@@ -2,7 +2,7 @@ import '@dxos-theme';
2
2
  import React from 'react';
3
3
  declare const _default: {
4
4
  title: string;
5
- component: ({ __menuScope, classNames, ...props }: import("./MenuContext").MenuScopedProps<import("./ToolbarMenu").ToolbarMenuProps>) => React.JSX.Element;
5
+ component: ({ __menuScope, classNames, ...props }: import("..").MenuScopedProps<import("..").ToolbarMenuProps>) => React.JSX.Element;
6
6
  decorators: import("@storybook/react").Decorator[];
7
7
  parameters: {
8
8
  translations: readonly [{
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Menus.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/Menus.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AACrB,OAAO,KAAsB,MAAM,OAAO,CAAC;;;;;;;;;;;;;AAc3C,wBAKE;AAOF,eAAO,MAAM,YAAY;;CAcxB,CAAC;AAEF,eAAO,MAAM,OAAO;;CAQnB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;CASjC,CAAC"}
@@ -1,2 +1,26 @@
1
- export * from './generator';
1
+ import { type Action, ACTION_TYPE, ACTION_GROUP_TYPE } from '@dxos/app-graph';
2
+ import { type MenuAction, type MenuItemGroup, type MenuItem } from '../defs';
3
+ import { type ActionGraphProps } from '../hooks';
4
+ export type CreateActionsParams = Partial<{
5
+ type?: typeof ACTION_TYPE | typeof ACTION_GROUP_TYPE;
6
+ callback: () => void;
7
+ count: number;
8
+ }>;
9
+ export declare const createActions: (params?: CreateActionsParams) => import("@dxos/live-object").ReactiveObject<{
10
+ id: string;
11
+ type: "dxos.org/type/GraphActionGroup" | "dxos.org/type/GraphAction";
12
+ data: symbol | (() => void);
13
+ properties: {
14
+ variant?: string | undefined;
15
+ label: string;
16
+ icon: string;
17
+ disabled: boolean;
18
+ };
19
+ }>[];
20
+ export declare const createNestedActions: () => ActionGraphProps;
21
+ export declare const createNestedActionsResolver: (groupParams?: CreateActionsParams, params?: CreateActionsParams) => {
22
+ resolveGroupItems: (groupNode?: MenuItemGroup) => MenuItem[] | null;
23
+ };
24
+ export declare const mutateActionsOnInterval: (actions: Action[]) => NodeJS.Timeout;
25
+ export declare const useMutateActions: (actions: MenuAction[]) => void;
2
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAuB,WAAW,EAAE,iBAAiB,EAAqB,MAAM,iBAAiB,CAAC;AAKtH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC;IACxC,IAAI,CAAC,EAAE,OAAO,WAAW,GAAG,OAAO,iBAAiB,CAAC;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAqBH,eAAO,MAAM,aAAa,YAAa,mBAAmB;;;0BAvBxC,IAAI;;;;;;;IAyCrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,wBAY/B,CAAC;AAEF,eAAO,MAAM,2BAA2B,iBAAkB,mBAAmB,WAAW,mBAAmB;oCAgBlE,aAAa,KACE,QAAQ,EAAE,GAAG,IAAI;CAExE,CAAC;AAEF,eAAO,MAAM,uBAAuB,YAAa,MAAM,EAAE,mBAUxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,UAAU,EAAE,SAI9C,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { actionGroupSymbol, type ActionLike } from '@dxos/app-graph';
2
- import { type MenuActionProperties, type MenuItemGroupProperties } from './types';
2
+ import { type MenuActionProperties, type MenuItemGroupProperties } from './defs';
3
3
  export declare const getShortcut: (action: ActionLike) => any;
4
4
  export declare const fallbackIcon = "ph--placeholder--regular";
5
- export declare const createMenuAction: <P extends {} = {}>(id: string, invoke: () => void, properties: P & MenuActionProperties) => {
5
+ export declare const createMenuAction: <P extends {} = {}>(id: string, properties: P & MenuActionProperties) => {
6
6
  id: string;
7
7
  type: string;
8
8
  properties: P & MenuActionProperties;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGrG,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAE7B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,WAAW,GAAI,QAAQ,UAAU,QAI7C,CAAC;AAEF,eAAO,MAAM,YAAY,6BAA6B,CAAC;AAEvD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,EAAE,GAAG,EAAE,EAChD,IAAI,MAAM,EACV,QAAQ,MAAM,IAAI,EAClB,YAAY,CAAC,GAAG,oBAAoB;;;;gBADtB,IAAI;CAQK,CAAC;AAE1B,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,uBAAuB,GAAG,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC,EAE3F,IAAI,MAAM,EACV,YAAY,CAAC;;;;;CAOa,CAAC;AAE7B,eAAO,MAAM,kBAAkB,GAAI,KAAI,MAAc,EAAE,SAAQ,MAAe;;;;;;;cAMrD,KAAK;;;;;;CAI5B,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAAI,KAAI,MAAe,EAAE,SAAQ,MAAe;;;;;;;cAMvD,KAAK;;;;;;CAI5B,CAAC"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGrG,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,uBAAuB,EAE7B,MAAM,QAAQ,CAAC;AAEhB,eAAO,MAAM,WAAW,WAAY,UAAU,QAI7C,CAAC;AAEF,eAAO,MAAM,YAAY,6BAA6B,CAAC;AAMvD,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,EAAE,WAAW,MAAM,cAAc,CAAC,GAAG,oBAAoB;;;;;CAM3E,CAAC;AAE1B,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,uBAAuB,gEAE7B,MAAM,cACE,CAAC;;;;;CAOa,CAAC;AAE7B,eAAO,MAAM,kBAAkB,QAAQ,MAAM,WAAkB,MAAM;;;;;;;cAM5C,KAAK;;;;;;CAI5B,CAAC;AAEH,eAAO,MAAM,mBAAmB,QAAQ,MAAM,WAAmB,MAAM;;;;;;;cAM9C,KAAK;;;;;;CAI5B,CAAC"}
@@ -1 +1 @@
1
- {"version":"5.8.3"}
1
+ {"version":"5.7.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-menu",
3
- "version": "0.8.2-main.fbd8ed0",
3
+ "version": "0.8.2-staging.7ac8446",
4
4
  "description": "Components for facilitating reactive and consistent menus.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -27,34 +27,28 @@
27
27
  "@preact/signals-react": "^1.3.8",
28
28
  "@radix-ui/react-context": "1.1.1",
29
29
  "@radix-ui/react-use-controllable-state": "1.1.0",
30
- "@dxos/app-graph": "0.8.2-main.fbd8ed0",
31
- "@dxos/keyboard": "0.8.2-main.fbd8ed0",
32
- "@dxos/react-ui-attention": "0.8.2-main.fbd8ed0",
33
- "@dxos/util": "0.8.2-main.fbd8ed0"
30
+ "@dxos/app-graph": "0.8.2-staging.7ac8446",
31
+ "@dxos/keyboard": "0.8.2-staging.7ac8446",
32
+ "@dxos/react-ui-attention": "0.8.2-staging.7ac8446",
33
+ "@dxos/util": "0.8.2-staging.7ac8446"
34
34
  },
35
35
  "devDependencies": {
36
- "@effect-rx/rx-react": "^0.34.1",
37
- "@effect/platform": "0.80.12",
38
36
  "@types/react": "~18.2.0",
39
37
  "@types/react-dom": "~18.2.0",
40
- "effect": "3.14.21",
41
38
  "react": "~18.2.0",
42
39
  "react-dom": "~18.2.0",
43
40
  "vite": "5.4.7",
44
- "@dxos/live-object": "0.8.2-main.fbd8ed0",
45
- "@dxos/react-ui": "0.8.2-main.fbd8ed0",
46
- "@dxos/random": "0.8.2-main.fbd8ed0",
47
- "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
48
- "@dxos/storybook-utils": "0.8.2-main.fbd8ed0"
41
+ "@dxos/live-object": "0.8.2-staging.7ac8446",
42
+ "@dxos/random": "0.8.2-staging.7ac8446",
43
+ "@dxos/react-ui": "0.8.2-staging.7ac8446",
44
+ "@dxos/react-ui-theme": "0.8.2-staging.7ac8446",
45
+ "@dxos/storybook-utils": "0.8.2-staging.7ac8446"
49
46
  },
50
47
  "peerDependencies": {
51
- "@effect-rx/rx-react": "^0.34.1",
52
- "@effect/platform": "0.80.12",
53
- "effect": "^3.13.3",
54
48
  "react": "~18.2.0",
55
49
  "react-dom": "~18.2.0",
56
- "@dxos/react-ui-theme": "0.8.2-main.fbd8ed0",
57
- "@dxos/react-ui": "0.8.2-main.fbd8ed0"
50
+ "@dxos/react-ui": "0.8.2-staging.7ac8446",
51
+ "@dxos/react-ui-theme": "0.8.2-staging.7ac8446"
58
52
  },
59
53
  "publishConfig": {
60
54
  "access": "public"
@@ -4,18 +4,20 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { type Action as GraphAction, type ActionGroup } from '@dxos/app-graph';
7
+ import { type Action, type ActionGroup } from '@dxos/app-graph';
8
8
  import { keySymbols } from '@dxos/keyboard';
9
- import { toLocalizedString, useTranslation, type TFunction } from '@dxos/react-ui';
9
+ import { toLocalizedString, useTranslation } from '@dxos/react-ui';
10
10
  import { mx, descriptionText } from '@dxos/react-ui-theme';
11
11
 
12
+ import { type MenuActionProperties } from '../defs';
12
13
  import { translationKey } from '../translations';
13
- import { type MenuActionProperties } from '../types';
14
14
  import { getShortcut } from '../util';
15
15
 
16
- type Action = GraphAction<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
17
-
18
- export const ActionLabel = ({ action }: { action: Action }) => {
16
+ export const ActionLabel = ({
17
+ action,
18
+ }: {
19
+ action: Action<MenuActionProperties> | ActionGroup<Omit<MenuActionProperties, 'variant'>>;
20
+ }) => {
19
21
  const shortcut = getShortcut(action);
20
22
  const { t } = useTranslation(translationKey);
21
23
 
@@ -26,8 +28,3 @@ export const ActionLabel = ({ action }: { action: Action }) => {
26
28
  </>
27
29
  );
28
30
  };
29
-
30
- export const actionLabel = (action: Action, t: TFunction) => {
31
- const shortcut = getShortcut(action);
32
- return `${toLocalizedString(action.properties!.label, t)}${shortcut ? ` (${keySymbols(shortcut).join('')})` : ''}`;
33
- };
@@ -9,13 +9,12 @@ import { DropdownMenu as NaturalDropdownMenu, Icon, type DropdownMenuRootProps }
9
9
 
10
10
  import { ActionLabel } from './ActionLabel';
11
11
  import { type MenuScopedProps, useMenu, useMenuItems } from './MenuContext';
12
- import { type MenuAction, type MenuItem, type MenuItemGroup } from '../types';
12
+ import { type MenuAction, type MenuItem, type MenuItemGroup } from '../defs';
13
13
 
14
14
  export type DropdownMenuProps = DropdownMenuRootProps & {
15
15
  group?: MenuItemGroup;
16
16
  items?: MenuItem[];
17
17
  suppressNextTooltip?: MutableRefObject<boolean>;
18
- caller?: string;
19
18
  };
20
19
 
21
20
  const DropdownMenuItem = ({
@@ -50,7 +49,6 @@ const DropdownMenuRoot = ({
50
49
  defaultOpen,
51
50
  onOpenChange,
52
51
  suppressNextTooltip,
53
- caller,
54
52
  children,
55
53
  __menuScope,
56
54
  ...naturalProps
@@ -61,6 +59,8 @@ const DropdownMenuRoot = ({
61
59
  onChange: onOpenChange,
62
60
  });
63
61
 
62
+ const { onAction } = useMenu('DropdownMenuRoot', __menuScope);
63
+
64
64
  const handleActionClick = useCallback(
65
65
  (action: MenuAction, event: MouseEvent) => {
66
66
  if (action.properties?.disabled) {
@@ -72,9 +72,9 @@ const DropdownMenuRoot = ({
72
72
  suppressNextTooltip.current = true;
73
73
  }
74
74
  setOptionsMenuOpen(false);
75
- void action.data?.({ parent: group, caller });
75
+ onAction?.(action);
76
76
  },
77
- [suppressNextTooltip, group, caller],
77
+ [onAction],
78
78
  );
79
79
 
80
80
  const items = useMenuItems(group, propsItems);
@@ -5,7 +5,15 @@
5
5
  import { createContextScope, type Scope } from '@radix-ui/react-context';
6
6
  import React, { type PropsWithChildren, useMemo } from 'react';
7
7
 
8
- import { type MenuContextValue, type MenuItem, type MenuItemGroup } from '../types';
8
+ import { type Node } from '@dxos/app-graph';
9
+
10
+ import {
11
+ type MenuActionHandler,
12
+ type MenuAction,
13
+ type MenuContextValue,
14
+ type MenuItem,
15
+ type MenuItemGroup,
16
+ } from '../defs';
9
17
 
10
18
  export type MenuScopedProps<P> = P & { __menuScope?: Scope };
11
19
 
@@ -13,24 +21,32 @@ const MENU_NAME = 'GraphMenu';
13
21
 
14
22
  const [createMenuContext, createMenuScope] = createContextScope(MENU_NAME, []);
15
23
 
16
- const [MenuContextProvider, useMenu] = createMenuContext<MenuContextValue>(MENU_NAME);
24
+ const [MenuContextProvider, useMenu] = createMenuContext<MenuContextValue<any>>(MENU_NAME);
17
25
 
18
- export const menuContextDefaults: MenuContextValue = {
26
+ export const menuContextDefaults: MenuContextValue<MenuAction> = {
19
27
  iconSize: 5,
20
- useGroupItems: () => null,
28
+ onAction: () => {},
29
+ resolveGroupItems: () => null,
21
30
  };
22
31
 
23
32
  const useMenuScope = createMenuScope();
24
33
 
25
- const MenuProvider = ({
34
+ const MenuProvider = <A extends Node = MenuAction>({
26
35
  children,
27
- useGroupItems = menuContextDefaults.useGroupItems,
36
+ resolveGroupItems = menuContextDefaults.resolveGroupItems,
37
+ onAction = menuContextDefaults.onAction as MenuActionHandler<A>,
28
38
  iconSize = menuContextDefaults.iconSize,
29
39
  attendableId,
30
- }: PropsWithChildren<Partial<MenuContextValue>>) => {
40
+ }: PropsWithChildren<Partial<MenuContextValue<A>>>) => {
31
41
  const { scope } = useMenuScope(undefined);
32
42
  return (
33
- <MenuContextProvider useGroupItems={useGroupItems} iconSize={iconSize} attendableId={attendableId} scope={scope}>
43
+ <MenuContextProvider
44
+ resolveGroupItems={resolveGroupItems}
45
+ onAction={onAction}
46
+ iconSize={iconSize}
47
+ attendableId={attendableId}
48
+ scope={scope}
49
+ >
34
50
  {children}
35
51
  </MenuContextProvider>
36
52
  );
@@ -42,9 +58,8 @@ export const useMenuItems = (
42
58
  consumerName: string = 'useMenuItemConsumer',
43
59
  __menuScope?: Scope,
44
60
  ) => {
45
- const { useGroupItems } = useMenu(consumerName, __menuScope);
46
- const groupItems = useGroupItems(group);
47
- return useMemo(() => propsItems ?? groupItems ?? undefined, [propsItems, groupItems]);
61
+ const { resolveGroupItems } = useMenu(consumerName, __menuScope);
62
+ return useMemo(() => propsItems ?? resolveGroupItems?.(group) ?? undefined, [propsItems, group, resolveGroupItems]);
48
63
  };
49
64
 
50
65
  export { useMenu, createMenuScope, MenuProvider };
@@ -4,13 +4,12 @@
4
4
 
5
5
  import React, { useCallback, useRef } from 'react';
6
6
 
7
- import { Icon, Toolbar as NaturalToolbar, type ToolbarRootProps, useTranslation } from '@dxos/react-ui';
7
+ import { Icon, type IconButtonProps, Toolbar as NaturalToolbar, type ToolbarRootProps } from '@dxos/react-ui';
8
8
  import { useAttention } from '@dxos/react-ui-attention';
9
9
 
10
- import { actionLabel, ActionLabel } from './ActionLabel';
10
+ import { ActionLabel } from './ActionLabel';
11
11
  import { DropdownMenu } from './DropdownMenu';
12
12
  import { type MenuScopedProps, useMenu, useMenuItems } from './MenuContext';
13
- import { translationKey } from '../translations';
14
13
  import {
15
14
  type MenuAction,
16
15
  type MenuItem,
@@ -20,7 +19,7 @@ import {
20
19
  type MenuActionProperties,
21
20
  type MenuMultipleSelectActionGroup,
22
21
  type MenuSingleSelectActionGroup,
23
- } from '../types';
22
+ } from '../defs';
24
23
 
25
24
  export type ToolbarMenuDropdownMenuActionGroup = Omit<MenuActionProperties, 'variant' | 'icon'> & {
26
25
  variant: 'dropdownMenu';
@@ -45,19 +44,15 @@ export type ToolbarMenuActionGroupProps = {
45
44
  items?: MenuItem[];
46
45
  };
47
46
 
48
- export type ToolbarMenuActionProps = {
49
- group: MenuItemGroup<ToolbarMenuActionGroupProperties>;
50
- action: MenuAction;
51
- };
52
-
53
47
  const ActionToolbarItem = ({ action, __menuScope }: MenuScopedProps<{ action: MenuAction }>) => {
54
- const { iconSize } = useMenu('ActionToolbarItem', __menuScope);
55
- const { t } = useTranslation(translationKey);
56
- const handleClick = useCallback(() => action.data?.(), [action]);
48
+ const { onAction, iconSize } = useMenu('ActionToolbarItem', __menuScope);
49
+ const handleClick = useCallback(() => {
50
+ onAction?.(action);
51
+ }, [action, onAction]);
57
52
  const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
58
53
  const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
59
54
  const rootProps = icon
60
- ? { icon, size: iconSize, iconOnly, label: actionLabel(action, t) }
55
+ ? { icon, size: iconSize, iconOnly, label: <ActionLabel action={action} /> }
61
56
  : { children: <ActionLabel action={action} /> };
62
57
  return hidden ? null : (
63
58
  <Root
@@ -66,7 +61,7 @@ const ActionToolbarItem = ({ action, __menuScope }: MenuScopedProps<{ action: Me
66
61
  onClick={handleClick}
67
62
  variant='ghost'
68
63
  {...(testId && { 'data-testid': testId })}
69
- {...(rootProps as any)}
64
+ {...(rootProps as IconButtonProps)}
70
65
  classNames={classNames}
71
66
  />
72
67
  );
@@ -79,7 +74,6 @@ const DropdownMenuToolbarItem = ({
79
74
  }: MenuScopedProps<ToolbarMenuActionGroupProps>) => {
80
75
  const { iconOnly, disabled, testId } = group.properties;
81
76
  const suppressNextTooltip = useRef(false);
82
- const { t } = useTranslation(translationKey);
83
77
  const { iconSize } = useMenu('DropdownMenuToolbarItem', __menuScope);
84
78
  const items = useMenuItems(group, propsItems, 'DropdownMenuToolbarItem', __menuScope);
85
79
  const activeItem = items?.find((item) => !!(item as MenuAction).properties.checked);
@@ -89,13 +83,15 @@ const DropdownMenuToolbarItem = ({
89
83
  (activeItem as MenuAction)?.properties.icon) ||
90
84
  group.properties.icon;
91
85
  const Root = icon ? NaturalToolbar.IconButton : NaturalToolbar.Button;
92
- const labelAction = (group.properties as any).applyActive && activeItem ? (activeItem as MenuAction) : group;
86
+ const label = (
87
+ <ActionLabel action={(group.properties as any).applyActive && activeItem ? (activeItem as MenuAction) : group} />
88
+ );
93
89
  const rootProps = icon
94
- ? { icon, size: iconSize, iconOnly, label: actionLabel(labelAction, t), caretDown: true, suppressNextTooltip }
90
+ ? { icon, size: iconSize, iconOnly, label, caretDown: true, suppressNextTooltip }
95
91
  : {
96
92
  children: (
97
93
  <>
98
- <ActionLabel action={labelAction} />
94
+ {label}
99
95
  <Icon size={3} icon='ph--caret-down--bold' classNames='mis-1' />
100
96
  </>
101
97
  ),
@@ -103,20 +99,26 @@ const DropdownMenuToolbarItem = ({
103
99
  return (
104
100
  <DropdownMenu.Root group={group} items={items} suppressNextTooltip={suppressNextTooltip}>
105
101
  <DropdownMenu.Trigger asChild>
106
- <Root variant='ghost' disabled={disabled} {...(rootProps as any)} {...(testId && { 'data-testid': testId })} />
102
+ <Root
103
+ variant='ghost'
104
+ disabled={disabled}
105
+ {...(rootProps as IconButtonProps)}
106
+ {...(testId && { 'data-testid': testId })}
107
+ />
107
108
  </DropdownMenu.Trigger>
108
109
  </DropdownMenu.Root>
109
110
  );
110
111
  };
111
112
 
112
- const ToggleGroupItem = ({ group, action, __menuScope }: MenuScopedProps<ToolbarMenuActionProps>) => {
113
- const { iconSize } = useMenu('ToggleGroupItem', __menuScope);
114
- const { t } = useTranslation(translationKey);
113
+ const ToggleGroupItem = ({ action, __menuScope }: MenuScopedProps<{ action: MenuAction }>) => {
114
+ const { iconSize, onAction } = useMenu('ToggleGroupItem', __menuScope);
115
115
  const { icon, iconOnly = true, disabled, testId, hidden, classNames } = action.properties;
116
- const handleClick = useCallback(() => action.data?.({ parent: group }), [action, group]);
116
+ const handleClick = useCallback(() => {
117
+ onAction?.(action);
118
+ }, [action, onAction]);
117
119
  const Root = icon ? NaturalToolbar.ToggleGroupIconItem : NaturalToolbar.ToggleGroupItem;
118
120
  const rootProps = icon
119
- ? { icon, size: iconSize, iconOnly, label: actionLabel(action, t) }
121
+ ? { icon, size: iconSize, iconOnly, label: <ActionLabel action={action} /> }
120
122
  : { children: <ActionLabel action={action} /> };
121
123
  return hidden ? null : (
122
124
  <Root
@@ -126,7 +128,7 @@ const ToggleGroupItem = ({ group, action, __menuScope }: MenuScopedProps<Toolbar
126
128
  onClick={handleClick}
127
129
  variant='ghost'
128
130
  {...(testId && { 'data-testid': testId })}
129
- {...(rootProps as any)}
131
+ {...(rootProps as IconButtonProps)}
130
132
  classNames={classNames}
131
133
  />
132
134
  );
@@ -146,7 +148,7 @@ const ToggleGroupToolbarItem = ({
146
148
  {
147
149
  // TODO(thure): Handle other menu item types.
148
150
  (items as MenuAction[]).map((action) => (
149
- <ToggleGroupItem key={action.id} group={group} action={action} />
151
+ <ToggleGroupItem key={action.id} action={action} />
150
152
  ))
151
153
  }
152
154
  </NaturalToolbar.ToggleGroup>
@@ -160,7 +162,7 @@ export const ToolbarMenu = ({ __menuScope, classNames, ...props }: MenuScopedPro
160
162
  return (
161
163
  <NaturalToolbar.Root
162
164
  {...props}
163
- classNames={['p-1', !hasAttention && '[&>*]:opacity-20 !bg-transparent', classNames]}
165
+ classNames={['p-0 pointer-fine:p-1 attention-surface', !hasAttention && 'opacity-20', classNames]}
164
166
  >
165
167
  {items?.map((item: MenuItem, i: number) =>
166
168
  isSeparator(item) ? (
@@ -26,6 +26,8 @@ export type MenuItemGroupProperties = {
26
26
 
27
27
  export type MenuAction<P extends {} = {}> = Action<P & MenuActionProperties>;
28
28
 
29
+ export type MenuActionHandler<A extends Node = MenuAction> = (action: A) => void;
30
+
29
31
  export const MenuSeparatorType = '@dxos/react-ui-toolbar/separator' as const;
30
32
 
31
33
  export type MenuSeparator = Node<never, Pick<ToolbarSeparatorProps, 'variant'>> & {
@@ -45,8 +47,9 @@ export type MenuItem = MenuSeparator | MenuAction | MenuItemGroup;
45
47
 
46
48
  export type MenuItemsResolver = (group?: MenuItemGroup) => MenuItem[] | null;
47
49
 
48
- export type MenuContextValue = {
49
- useGroupItems: MenuItemsResolver;
50
+ export type MenuContextValue<A extends Node = MenuAction> = {
51
+ resolveGroupItems: MenuItemsResolver;
50
52
  iconSize: IconButtonProps['size'];
53
+ onAction: MenuActionHandler<A>;
51
54
  attendableId?: string;
52
55
  };
@@ -2,15 +2,16 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { RegistryContext, useRxValue } from '@effect-rx/rx-react';
6
5
  import { useSignalEffect } from '@preact/signals-react';
7
- import { useCallback, useContext, useState } from 'react';
6
+ import { useCallback, useState } from 'react';
8
7
 
9
- import { type Edge, type Edges, Graph, type NodeArg, type Node, ROOT_ID } from '@dxos/app-graph';
8
+ import { Graph, type NodeArg, type Node } from '@dxos/app-graph';
10
9
 
11
- import { type MenuItem, type MenuItemGroup } from '../types';
10
+ import { type MenuItem, type MenuItemGroup } from './defs';
12
11
 
13
- const edgesArrayToRecord = (edges: Edge[]): Record<string, Edges> => {
12
+ type Edge = { source: string; target: string };
13
+
14
+ const edgesArrayToRecord = (edges: { source: string; target: string }[]): Record<string, string[]> => {
14
15
  return Object.fromEntries(
15
16
  Object.entries(
16
17
  edges.reduce((acc: Record<string, { inbound: string[]; outbound: string[] }>, { source, target }) => {
@@ -33,7 +34,7 @@ const edgesArrayToRecord = (edges: Edge[]): Record<string, Edges> => {
33
34
 
34
35
  return acc;
35
36
  }, {}),
36
- ),
37
+ ).map(([id, { outbound }]): [string, string[]] => [id, outbound]),
37
38
  );
38
39
  };
39
40
 
@@ -42,31 +43,30 @@ export type ActionGraphEdges = Edge[];
42
43
  export type ActionGraphProps = { nodes: ActionGraphNodes; edges: ActionGraphEdges };
43
44
 
44
45
  export const useMenuActions = (actionCreator: () => ActionGraphProps) => {
45
- const registry = useContext(RegistryContext);
46
46
  const initialMenuGraphProps = actionCreator();
47
47
 
48
48
  const [graph] = useState(
49
- new Graph({
50
- registry,
51
- nodes: initialMenuGraphProps.nodes as Node[],
52
- edges: edgesArrayToRecord(initialMenuGraphProps.edges),
53
- }),
49
+ new Graph({ nodes: initialMenuGraphProps.nodes as Node[], edges: edgesArrayToRecord(initialMenuGraphProps.edges) }),
54
50
  );
55
51
 
56
- // TODO(wittjosiah): Remove dependence on signals.
57
52
  useSignalEffect(() => {
58
53
  const menuGraphProps = actionCreator();
59
- graph.addNodes(menuGraphProps.nodes);
60
- graph.addEdges(menuGraphProps.edges);
54
+ // @ts-ignore
55
+ graph._addNodes(menuGraphProps.nodes);
56
+ // @ts-ignore
57
+ graph._addEdges(menuGraphProps.edges);
61
58
  });
62
59
 
63
- const useGroupItems = useCallback(
64
- (sourceNode?: MenuItemGroup) => {
65
- const items = useRxValue(graph.connections(sourceNode?.id || ROOT_ID)) as MenuItem[];
66
- return items;
60
+ const resolveGroupItems = useCallback(
61
+ (sourceNode: MenuItemGroup = graph.root as MenuItemGroup) => {
62
+ if (graph) {
63
+ return (graph.nodes(sourceNode, { filter: (n): n is any => true }) || null) as MenuItem[] | null;
64
+ } else {
65
+ return null;
66
+ }
67
67
  },
68
68
  [graph],
69
69
  );
70
70
 
71
- return { useGroupItems };
71
+ return { resolveGroupItems };
72
72
  };
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from './components';
6
+ export * from './defs';
6
7
  export * from './hooks';
7
- export * from './types';
8
8
  export { createMenuAction, createMenuItemGroup, createLineSeparator, createGapSeparator } from './util';