@dxos/react-ui-stack 0.7.4 → 0.7.5-labs.071a3e2

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 (43) hide show
  1. package/dist/lib/browser/index.mjs +228 -130
  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 +229 -129
  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 +228 -130
  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/LayoutControls.d.ts.map +1 -1
  11. package/dist/types/src/components/Stack.d.ts +3 -0
  12. package/dist/types/src/components/Stack.d.ts.map +1 -1
  13. package/dist/types/src/components/Stack.stories.d.ts.map +1 -1
  14. package/dist/types/src/components/StackContext.d.ts +9 -4
  15. package/dist/types/src/components/StackContext.d.ts.map +1 -1
  16. package/dist/types/src/components/StackItem.d.ts +14 -9
  17. package/dist/types/src/components/StackItem.d.ts.map +1 -1
  18. package/dist/types/src/components/StackItemContent.d.ts +35 -2
  19. package/dist/types/src/components/StackItemContent.d.ts.map +1 -1
  20. package/dist/types/src/components/StackItemDragHandle.d.ts +6 -0
  21. package/dist/types/src/components/StackItemDragHandle.d.ts.map +1 -0
  22. package/dist/types/src/components/StackItemHeading.d.ts.map +1 -1
  23. package/dist/types/src/components/StackItemResizeHandle.d.ts +1 -0
  24. package/dist/types/src/components/StackItemResizeHandle.d.ts.map +1 -1
  25. package/dist/types/src/components/StackItemSigil.d.ts.map +1 -1
  26. package/dist/types/src/components/index.d.ts +1 -0
  27. package/dist/types/src/components/index.d.ts.map +1 -1
  28. package/dist/types/tsconfig.tsbuildinfo +1 -0
  29. package/package.json +28 -26
  30. package/src/components/LayoutControls.tsx +1 -3
  31. package/src/components/Stack.stories.tsx +5 -4
  32. package/src/components/Stack.tsx +73 -10
  33. package/src/components/StackContext.tsx +13 -4
  34. package/src/components/StackItem.tsx +49 -16
  35. package/src/components/StackItemContent.tsx +48 -33
  36. package/src/components/StackItemDragHandle.tsx +22 -0
  37. package/src/components/StackItemHeading.tsx +3 -5
  38. package/src/components/StackItemResizeHandle.tsx +27 -15
  39. package/src/components/StackItemSigil.tsx +90 -103
  40. package/src/components/index.ts +1 -0
  41. package/dist/types/src/testing/EditorContent.d.ts +0 -8
  42. package/dist/types/src/testing/EditorContent.d.ts.map +0 -1
  43. package/src/testing/EditorContent.tsx +0 -60
@@ -10,12 +10,13 @@ import React, { useLayoutEffect, useRef } from 'react';
10
10
 
11
11
  import { mx } from '@dxos/react-ui-theme';
12
12
 
13
- import { useStack, useStackItem } from './StackContext';
14
- import { DEFAULT_EXTRINSIC_SIZE, type StackItemSize } from './StackItem';
13
+ import { useStack, useStackItem, type StackItemSize } from './StackContext';
14
+ import { DEFAULT_EXTRINSIC_SIZE } from './StackItem';
15
15
 
16
16
  const REM = parseFloat(getComputedStyle(document.documentElement).fontSize);
17
17
 
18
- const MIN_SIZE = 20;
18
+ const MIN_WIDTH = 20;
19
+ const MIN_HEIGHT = 3;
19
20
 
20
21
  const measureStackItem = (element: HTMLButtonElement): { width: number; height: number } => {
21
22
  const stackItemElement = element.closest('[data-dx-stack-item]');
@@ -23,9 +24,14 @@ const measureStackItem = (element: HTMLButtonElement): { width: number; height:
23
24
  };
24
25
 
25
26
  const getNextSize = (startSize: number, location: DragLocationHistory, client: 'clientX' | 'clientY') => {
26
- return Math.max(MIN_SIZE, startSize + (location.current.input[client] - location.initial.input[client]) / REM);
27
+ return Math.max(
28
+ client === 'clientX' ? MIN_WIDTH : MIN_HEIGHT,
29
+ startSize + (location.current.input[client] - location.initial.input[client]) / REM,
30
+ );
27
31
  };
28
32
 
33
+ export type StackItemResizeHandleProps = {};
34
+
29
35
  export const StackItemResizeHandle = () => {
30
36
  const { orientation } = useStack();
31
37
  const { setSize, size } = useStackItem();
@@ -42,11 +48,10 @@ export const StackItemResizeHandle = () => {
42
48
  draggable({
43
49
  element: buttonRef.current,
44
50
  onGenerateDragPreview: ({ nativeSetDragImage }) => {
45
- // we will be moving the line to indicate a drag
46
- // we can disable the native drag preview
51
+ // We will be moving the line to indicate a drag; we can disable the native drag preview.
47
52
  disableNativeDragPreview({ nativeSetDragImage });
48
- // we don't want any native drop animation for when the user
49
- // does not drop on a drop target. we want the drag to finish immediately
53
+ // We don't want any native drop animation for when the user does not drop on a drop target.
54
+ // We want the drag to finish immediately.
50
55
  preventUnhandled.start();
51
56
  },
52
57
  onDragStart: () => {
@@ -80,29 +85,36 @@ export const StackItemResizeHandle = () => {
80
85
  <button
81
86
  ref={buttonRef}
82
87
  className={mx(
83
- orientation === 'horizontal' ? 'cursor-col-resize' : 'cursor-row-resize',
84
- 'group absolute is-3 bs-full inline-end-[-1px] !border-lb-0',
88
+ 'group absolute',
89
+ orientation === 'horizontal'
90
+ ? 'cursor-col-resize is-3 bs-full inline-end-[-1px] !border-lb-0 before:inset-block-0 before:inline-end-0 before:is-1'
91
+ : 'cursor-row-resize bs-3 is-full block-end-[-1px] !border-li-0 before:inset-inline-0 before:block-end-0 before:bs-1',
85
92
  'before:transition-opacity before:duration-100 before:ease-in-out before:opacity-0 hover:before:opacity-100 focus-visible:before:opacity-100 active:before:opacity-100',
86
- 'before:absolute before:block before:inset-block-0 before:inline-end-0 before:is-1 before:bg-accentFocusIndicator',
93
+ 'before:absolute before:block before:bg-accentFocusIndicator',
87
94
  )}
88
95
  >
89
96
  <div
90
97
  role='none'
91
- className='absolute block-start-0 inline-end-[1px] bs-[--rail-size] flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0'
98
+ className={mx(
99
+ 'absolute flex items-center group-hover:opacity-0 group-focus-visible:opacity-0 group-active:opacity-0',
100
+ orientation === 'horizontal'
101
+ ? 'block-start-0 inline-end-px bs-[--rail-size]'
102
+ : 'inline-start-0 block-end-px is-[--rail-size] flex justify-center',
103
+ )}
92
104
  >
93
- <DragHandleSignifier />
105
+ <DragHandleSignifier orientation={orientation} />
94
106
  </div>
95
107
  </button>
96
108
  );
97
109
  };
98
110
 
99
- const DragHandleSignifier = () => {
111
+ const DragHandleSignifier = ({ orientation }: { orientation: 'horizontal' | 'vertical' }) => {
100
112
  return (
101
113
  <svg
102
114
  xmlns='http://www.w3.org/2000/svg'
103
115
  viewBox='0 0 256 256'
104
116
  fill='currentColor'
105
- className='shrink-0 bs-[1em] is-[1em] text-unAccent'
117
+ className={mx('shrink-0 bs-[1em] is-[1em] text-unAccent', orientation === 'vertical' && 'rotate-90')}
106
118
  >
107
119
  {/* two pips: <path d='M256,120c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' />
108
120
  <path d='M256,232c-8.8,0-16-7.2-16-16v-56c0-8.8,7.2-16,16-16v88Z' /> */}
@@ -6,15 +6,7 @@ import React, { Fragment, type PropsWithChildren, forwardRef, useRef, useState }
6
6
 
7
7
  import { type ActionLike } from '@dxos/app-graph';
8
8
  import { keySymbols } from '@dxos/keyboard';
9
- import {
10
- Button,
11
- type ButtonProps,
12
- DropdownMenu,
13
- Icon,
14
- toLocalizedString,
15
- Tooltip,
16
- useTranslation,
17
- } from '@dxos/react-ui';
9
+ import { Button, type ButtonProps, DropdownMenu, Icon, toLocalizedString, useTranslation } from '@dxos/react-ui';
18
10
  import { type AttendableId, type Related, useAttention } from '@dxos/react-ui-attention';
19
11
  import { descriptionText, mx } from '@dxos/react-ui-theme';
20
12
  import { getHostPlatform } from '@dxos/util';
@@ -42,7 +34,7 @@ export const StackItemSigilButton = forwardRef<HTMLButtonElement, StackItemSigil
42
34
  <Button
43
35
  {...props}
44
36
  variant={variant}
45
- classNames={['m-1 shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative', classNames]}
37
+ classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative app-no-drag', classNames]}
46
38
  ref={forwardedRef}
47
39
  >
48
40
  <MenuSignifierHorizontal />
@@ -68,103 +60,98 @@ export const StackItemSigil = forwardRef<HTMLButtonElement, StackItemSigilProps>
68
60
  const suppressNextTooltip = useRef(false);
69
61
 
70
62
  const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
71
- const [triggerTooltipOpen, setTriggerTooltipOpen] = useState(false);
63
+
64
+ const hasActions = actionGroups && actionGroups.length > 0;
65
+
66
+ const button = (
67
+ <StackItemSigilButton
68
+ attendableId={attendableId}
69
+ related={related}
70
+ // TODO(wittjosiah): Better disabling of interactive styles when no action are available.
71
+ // Remove underscore icon when no actions are available?
72
+ classNames={!hasActions && 'cursor-default'}
73
+ >
74
+ <span className='sr-only'>{triggerLabel}</span>
75
+ <Icon icon={icon} size={5} />
76
+ </StackItemSigilButton>
77
+ );
78
+
79
+ if (!hasActions) {
80
+ return button;
81
+ }
72
82
 
73
83
  return (
74
- <Tooltip.Root
75
- open={triggerTooltipOpen}
76
- onOpenChange={(nextOpen) => {
77
- if (suppressNextTooltip.current) {
78
- setTriggerTooltipOpen(false);
79
- suppressNextTooltip.current = false;
80
- } else {
81
- setTriggerTooltipOpen(nextOpen);
82
- }
84
+ <DropdownMenu.Root
85
+ {...{
86
+ open: optionsMenuOpen,
87
+ onOpenChange: (nextOpen: boolean) => {
88
+ if (!nextOpen) {
89
+ suppressNextTooltip.current = true;
90
+ }
91
+ return setOptionsMenuOpen(nextOpen);
92
+ },
83
93
  }}
84
94
  >
85
- <DropdownMenu.Root
86
- {...{
87
- open: optionsMenuOpen,
88
- onOpenChange: (nextOpen: boolean) => {
89
- if (!nextOpen) {
90
- suppressNextTooltip.current = true;
91
- }
92
- return setOptionsMenuOpen(nextOpen);
93
- },
94
- }}
95
- >
96
- <Tooltip.Trigger asChild>
97
- <DropdownMenu.Trigger asChild ref={forwardedRef}>
98
- <StackItemSigilButton attendableId={attendableId} related={related}>
99
- <span className='sr-only'>{triggerLabel}</span>
100
- <Icon icon={icon} size={5} />
101
- </StackItemSigilButton>
102
- </DropdownMenu.Trigger>
103
- </Tooltip.Trigger>
104
- <DropdownMenu.Portal>
105
- <DropdownMenu.Content classNames='z-[31]'>
106
- <DropdownMenu.Viewport>
107
- {actionGroups?.map((actions, index) => {
108
- const separator = index > 0 ? <DropdownMenu.Separator /> : null;
109
- return (
110
- <Fragment key={index}>
111
- {separator}
112
- {actions.map((action) => {
113
- const shortcut =
114
- typeof action.properties.keyBinding === 'string'
115
- ? action.properties.keyBinding
116
- : action.properties.keyBinding?.[getHostPlatform()];
117
-
118
- const menuItemType = action.properties.menuItemType;
119
- const Root = menuItemType === 'toggle' ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
120
-
121
- return (
122
- <Root
123
- key={action.id}
124
- onClick={(event) => {
125
- if (action.properties.disabled) {
126
- return;
127
- }
128
- event.stopPropagation();
129
- // TODO(thure): Why does Dialog’s modal-ness cause issues if we don’t explicitly close the menu here?
130
- suppressNextTooltip.current = true;
131
- setOptionsMenuOpen(false);
132
- onAction?.(action);
133
- }}
134
- classNames='gap-2'
135
- disabled={action.properties.disabled}
136
- checked={menuItemType === 'toggle' ? action.properties.isChecked : undefined}
137
- {...(action.properties?.testId && { 'data-testid': action.properties.testId })}
138
- >
139
- <Icon icon={action.properties.icon ?? 'ph--placeholder--regular'} size={4} />
140
- <span className='grow truncate'>{toLocalizedString(action.properties.label ?? '', t)}</span>
141
- {menuItemType === 'toggle' && (
142
- <DropdownMenu.ItemIndicator asChild>
143
- <Icon icon='ph--check--regular' size={4} />
144
- </DropdownMenu.ItemIndicator>
145
- )}
146
- {shortcut && (
147
- <span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>
148
- )}
149
- </Root>
150
- );
151
- })}
152
- </Fragment>
153
- );
154
- })}
155
- {children}
156
- </DropdownMenu.Viewport>
157
- <DropdownMenu.Arrow />
158
- </DropdownMenu.Content>
159
- </DropdownMenu.Portal>
160
- </DropdownMenu.Root>
161
- <Tooltip.Portal>
162
- <Tooltip.Content style={{ zIndex: 70 }} side='bottom'>
163
- {triggerLabel}
164
- <Tooltip.Arrow />
165
- </Tooltip.Content>
166
- </Tooltip.Portal>
167
- </Tooltip.Root>
95
+ <DropdownMenu.Trigger asChild ref={forwardedRef}>
96
+ {button}
97
+ </DropdownMenu.Trigger>
98
+ <DropdownMenu.Portal>
99
+ <DropdownMenu.Content classNames='z-[31]'>
100
+ <DropdownMenu.Viewport>
101
+ {actionGroups?.map((actions, index) => {
102
+ const separator = index > 0 ? <DropdownMenu.Separator /> : null;
103
+ return (
104
+ <Fragment key={index}>
105
+ {separator}
106
+ {actions.map((action) => {
107
+ const shortcut =
108
+ typeof action.properties.keyBinding === 'string'
109
+ ? action.properties.keyBinding
110
+ : action.properties.keyBinding?.[getHostPlatform()];
111
+
112
+ const menuItemType = action.properties.menuItemType;
113
+ const Root = menuItemType === 'toggle' ? DropdownMenu.CheckboxItem : DropdownMenu.Item;
114
+
115
+ return (
116
+ <Root
117
+ key={action.id}
118
+ onClick={(event) => {
119
+ if (action.properties.disabled) {
120
+ return;
121
+ }
122
+ event.stopPropagation();
123
+ // TODO(thure): Why does Dialog’s modal-ness cause issues if we don’t explicitly close the menu here?
124
+ suppressNextTooltip.current = true;
125
+ setOptionsMenuOpen(false);
126
+ onAction?.(action);
127
+ }}
128
+ classNames='gap-2'
129
+ disabled={action.properties.disabled}
130
+ checked={menuItemType === 'toggle' ? action.properties.isChecked : undefined}
131
+ {...(action.properties?.testId && { 'data-testid': action.properties.testId })}
132
+ >
133
+ <Icon icon={action.properties.icon ?? 'ph--placeholder--regular'} size={4} />
134
+ <span className='grow truncate'>{toLocalizedString(action.properties.label ?? '', t)}</span>
135
+ {menuItemType === 'toggle' && (
136
+ <DropdownMenu.ItemIndicator asChild>
137
+ <Icon icon='ph--check--regular' size={4} />
138
+ </DropdownMenu.ItemIndicator>
139
+ )}
140
+ {shortcut && (
141
+ <span className={mx('shrink-0', descriptionText)}>{keySymbols(shortcut).join('')}</span>
142
+ )}
143
+ </Root>
144
+ );
145
+ })}
146
+ </Fragment>
147
+ );
148
+ })}
149
+ {children}
150
+ </DropdownMenu.Viewport>
151
+ <DropdownMenu.Arrow />
152
+ </DropdownMenu.Content>
153
+ </DropdownMenu.Portal>
154
+ </DropdownMenu.Root>
168
155
  );
169
156
  },
170
157
  );
@@ -5,3 +5,4 @@
5
5
  export * from './Stack';
6
6
  export * from './StackItem';
7
7
  export * from './LayoutControls';
8
+ export * from './StackContext';
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import { type StackItemContentProps } from '../components';
3
- export declare const EditorContent: ({ data: { content } }: {
4
- data: StackItemContentProps & {
5
- content?: string;
6
- };
7
- }) => React.JSX.Element;
8
- //# sourceMappingURL=EditorContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../../../../src/testing/EditorContent.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAkBxC,OAAO,EAAa,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,aAAa,0BAAgC;IAAE,IAAI,EAAE,qBAAqB,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,sBAmC/G,CAAC"}
@@ -1,60 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React, { useState } from 'react';
6
-
7
- import { Expando } from '@dxos/echo-schema';
8
- import { create } from '@dxos/live-object';
9
- import { useThemeContext } from '@dxos/react-ui';
10
- import {
11
- createBasicExtensions,
12
- createMarkdownExtensions,
13
- createThemeExtensions,
14
- decorateMarkdown,
15
- formattingKeymap,
16
- Toolbar,
17
- useActionHandler,
18
- useFormattingState,
19
- useTextEditor,
20
- } from '@dxos/react-ui-editor';
21
- import { focusRing, mx, textBlockWidth } from '@dxos/react-ui-theme';
22
-
23
- import { StackItem, type StackItemContentProps } from '../components';
24
-
25
- export const EditorContent = ({ data: { content = '' } }: { data: StackItemContentProps & { content?: string } }) => {
26
- const { themeMode } = useThemeContext();
27
- const [text] = useState(create(Expando, { content }));
28
- const id = text.id;
29
- const [formattingState, formattingObserver] = useFormattingState();
30
- const { parentRef, view, focusAttributes } = useTextEditor(() => {
31
- return {
32
- id,
33
- initialValue: text.content,
34
- extensions: [
35
- formattingObserver,
36
- createBasicExtensions(),
37
- createMarkdownExtensions({ themeMode }),
38
- createThemeExtensions({ themeMode, syntaxHighlighting: true, slots: { editor: { className: 'p-2' } } }),
39
- decorateMarkdown(),
40
- formattingKeymap(),
41
- ],
42
- };
43
- }, [id, formattingObserver, themeMode]);
44
-
45
- const handleAction = useActionHandler(view);
46
-
47
- return (
48
- <StackItem.Content>
49
- <div {...focusAttributes} className={mx(textBlockWidth, focusRing, 'rounded-sm order-last')} ref={parentRef} />
50
- <Toolbar.Root
51
- onAction={handleAction}
52
- state={formattingState}
53
- classNames='sticky block-start-0 bg-[--sticky-bg] z-10'
54
- >
55
- <Toolbar.Markdown />
56
- <Toolbar.Separator />
57
- </Toolbar.Root>
58
- </StackItem.Content>
59
- );
60
- };