@dxos/react-ui-editor 0.4.8 → 0.4.9-main.1057b49

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.
@@ -24,6 +24,8 @@ import {
24
24
  TextHFive,
25
25
  TextHSix,
26
26
  TextItalic,
27
+ CaretDown,
28
+ Check,
27
29
  } from '@phosphor-icons/react';
28
30
  import { createContext } from '@radix-ui/react-context';
29
31
  import React, { type PropsWithChildren, useEffect, useRef, useState } from 'react';
@@ -32,13 +34,14 @@ import { useDropzone } from 'react-dropzone';
32
34
  import {
33
35
  DensityProvider,
34
36
  ElevationProvider,
35
- Select,
36
37
  Toolbar as NaturalToolbar,
37
38
  Tooltip,
38
39
  type ThemedClassName,
39
40
  type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
40
41
  type ToolbarButtonProps as NaturalToolbarButtonProps,
41
42
  useTranslation,
43
+ DropdownMenu,
44
+ Button,
42
45
  } from '@dxos/react-ui';
43
46
  import { getSize } from '@dxos/react-ui-theme';
44
47
 
@@ -156,9 +159,9 @@ const MarkdownHeading = () => {
156
159
  }
157
160
  }}
158
161
  >
159
- <Select.Root
160
- disabled={value === null}
161
- value={value ?? '0'}
162
+ {/* TODO(thure): `Select` encounters a ref error if used here (repro: select a heading, then select another
163
+ heading). Determine the root cause and fix or report to Radix. */}
164
+ <DropdownMenu.Root
162
165
  open={selectOpen}
163
166
  onOpenChange={(nextOpen: boolean) => {
164
167
  if (!nextOpen) {
@@ -166,39 +169,42 @@ const MarkdownHeading = () => {
166
169
  }
167
170
  return setSelectOpen(nextOpen);
168
171
  }}
169
- onValueChange={(value) => onAction?.({ type: 'heading', data: parseInt(value) })}
170
172
  >
171
173
  <Tooltip.Trigger asChild>
172
174
  <NaturalToolbar.Button asChild>
173
- <Select.TriggerButton variant='ghost' classNames={buttonStyles}>
174
- <span className='sr-only'>{t('heading label')}</span>
175
- <HeadingIcon className={iconStyles} />
176
- </Select.TriggerButton>
175
+ <DropdownMenu.Trigger asChild>
176
+ <Button variant='ghost' classNames={buttonStyles} disabled={value === null}>
177
+ <span className='sr-only'>{t('heading label')}</span>
178
+ <HeadingIcon className={iconStyles} />
179
+ <CaretDown />
180
+ </Button>
181
+ </DropdownMenu.Trigger>
177
182
  </NaturalToolbar.Button>
178
183
  </Tooltip.Trigger>
179
- <Select.Portal>
180
- <Select.Content>
181
- <Select.ScrollUpButton />
182
- <Select.Viewport>
183
- <Select.Option value='0'>
184
- <Paragraph className={iconStyles} />
185
- </Select.Option>
186
- {[1, 2, 3, 4, 5, 6].map((level) => (
187
- <Select.Option key={level} value={String(level)}>
188
- {level === 1 && <TextHOne className={iconStyles} />}
189
- {level === 2 && <TextHTwo className={iconStyles} />}
190
- {level === 3 && <TextHThree className={iconStyles} />}
191
- {level === 4 && <TextHFour className={iconStyles} />}
192
- {level === 5 && <TextHFive className={iconStyles} />}
193
- {level === 6 && <TextHSix className={iconStyles} />}
194
- </Select.Option>
195
- ))}
196
- </Select.Viewport>
197
- <Select.ScrollDownButton />
198
- <Select.Arrow />
199
- </Select.Content>
200
- </Select.Portal>
201
- </Select.Root>
184
+ <DropdownMenu.Portal>
185
+ <DropdownMenu.Content classNames='is-min md:is-min' onCloseAutoFocus={(e) => e.preventDefault()}>
186
+ <DropdownMenu.Viewport>
187
+ {Object.keys(HeadingIcons).map((level) => {
188
+ const Icon = HeadingIcons[level];
189
+ return (
190
+ <DropdownMenu.CheckboxItem
191
+ key={level}
192
+ checked={value === level}
193
+ onClick={() => onAction?.({ type: 'heading', data: level })}
194
+ >
195
+ <span className='sr-only'>{t('heading level label', { count: parseInt(level) })}</span>
196
+ <Icon className={iconStyles} />
197
+ <DropdownMenu.ItemIndicator>
198
+ <Check />
199
+ </DropdownMenu.ItemIndicator>
200
+ </DropdownMenu.CheckboxItem>
201
+ );
202
+ })}
203
+ </DropdownMenu.Viewport>
204
+ <DropdownMenu.Arrow />
205
+ </DropdownMenu.Content>
206
+ </DropdownMenu.Portal>
207
+ </DropdownMenu.Root>
202
208
  <Tooltip.Portal>
203
209
  <Tooltip.Content {...tooltipProps}>
204
210
  {t('heading label')}
package/src/index.ts CHANGED
@@ -9,7 +9,6 @@ export { type EditorView, keymap } from '@codemirror/view';
9
9
  export { tags } from '@lezer/highlight';
10
10
 
11
11
  export { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
12
- export { Doc, YText, YXmlFragment } from '@dxos/text-model'; // TODO(burdon): Remove.
13
12
 
14
13
  export * from './components';
15
14
  export * from './extensions';
@@ -22,6 +22,9 @@ export default [
22
22
  'image label': 'Insert image',
23
23
  'heading label': 'Heading level',
24
24
  'table label': 'Create table',
25
+ 'heading level label_zero': 'Paragraph',
26
+ 'heading level label_one': 'Heading level {{count}}',
27
+ 'heading level label_other': 'Heading level {{count}}',
25
28
  },
26
29
  },
27
30
  },