@dxos/react-ui-editor 0.4.5-main.f10c180 → 0.4.5-next.ea4f804

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.
@@ -33,6 +33,7 @@ import {
33
33
  Select,
34
34
  type ThemedClassName,
35
35
  Toolbar as NaturalToolbar,
36
+ Tooltip,
36
37
  type ToolbarToggleGroupItemProps,
37
38
  useTranslation,
38
39
  } from '@dxos/react-ui';
@@ -41,6 +42,8 @@ import { getSize } from '@dxos/react-ui-theme';
41
42
  import { type Formatting } from '../../extensions';
42
43
  import { translationKey } from '../../translations';
43
44
 
45
+ const tooltipProps = { side: 'top' as const, classNames: 'z-10' };
46
+
44
47
  const HeadingIcons: { [key: string]: Icon } = {
45
48
  '0': Paragraph,
46
49
  '1': TextHOne,
@@ -112,10 +115,20 @@ type ToolbarButtonProps = ToolbarToggleGroupItemProps & { Icon: Icon };
112
115
 
113
116
  const ToolbarButton = ({ Icon, children, ...props }: ToolbarButtonProps) => {
114
117
  return (
115
- <NaturalToolbar.ToggleGroupItem variant='ghost' {...props} classNames={buttonStyles}>
116
- <Icon className={iconStyles} />
117
- <span className='sr-only'>{children}</span>
118
- </NaturalToolbar.ToggleGroupItem>
118
+ <Tooltip.Root>
119
+ <Tooltip.Trigger asChild>
120
+ <NaturalToolbar.ToggleGroupItem variant='ghost' {...props} classNames={buttonStyles}>
121
+ <Icon className={iconStyles} />
122
+ <span className='sr-only'>{children}</span>
123
+ </NaturalToolbar.ToggleGroupItem>
124
+ </Tooltip.Trigger>
125
+ <Tooltip.Portal>
126
+ <Tooltip.Content {...tooltipProps}>
127
+ {children}
128
+ <Tooltip.Arrow />
129
+ </Tooltip.Content>
130
+ </Tooltip.Portal>
131
+ </Tooltip.Root>
119
132
  );
120
133
  };
121
134
 
@@ -129,40 +142,50 @@ const MarkdownHeading = () => {
129
142
  const value = header ? header[1] : blockType === 'paragraph' || !blockType ? '0' : undefined;
130
143
  const HeadingIcon = HeadingIcons[value ?? '0'];
131
144
  return (
132
- <Select.Root
133
- disabled={value === null}
134
- value={value ?? '0'}
135
- onValueChange={(value) => onAction?.({ type: 'heading', data: parseInt(value) })}
136
- >
137
- <NaturalToolbar.Button asChild>
138
- <Select.TriggerButton variant='ghost' classNames={buttonStyles}>
139
- <span className='sr-only'>{t('heading label')}</span>
140
- <HeadingIcon className={iconStyles} />
141
- </Select.TriggerButton>
142
- </NaturalToolbar.Button>
143
- <Select.Portal>
144
- <Select.Content>
145
- <Select.ScrollUpButton />
146
- <Select.Viewport>
147
- <Select.Option value='0'>
148
- <Paragraph className={iconStyles} />
149
- </Select.Option>
150
- {[1, 2, 3, 4, 5, 6].map((level) => (
151
- <Select.Option key={level} value={String(level)}>
152
- {level === 1 && <TextHOne className={iconStyles} />}
153
- {level === 2 && <TextHTwo className={iconStyles} />}
154
- {level === 3 && <TextHThree className={iconStyles} />}
155
- {level === 4 && <TextHFour className={iconStyles} />}
156
- {level === 5 && <TextHFive className={iconStyles} />}
157
- {level === 6 && <TextHSix className={iconStyles} />}
145
+ <Tooltip.Root>
146
+ <Select.Root
147
+ disabled={value === null}
148
+ value={value ?? '0'}
149
+ onValueChange={(value) => onAction?.({ type: 'heading', data: parseInt(value) })}
150
+ >
151
+ <Tooltip.Trigger asChild>
152
+ <NaturalToolbar.Button asChild>
153
+ <Select.TriggerButton variant='ghost' classNames={buttonStyles}>
154
+ <span className='sr-only'>{t('heading label')}</span>
155
+ <HeadingIcon className={iconStyles} />
156
+ </Select.TriggerButton>
157
+ </NaturalToolbar.Button>
158
+ </Tooltip.Trigger>
159
+ <Select.Portal>
160
+ <Select.Content>
161
+ <Select.ScrollUpButton />
162
+ <Select.Viewport>
163
+ <Select.Option value='0'>
164
+ <Paragraph className={iconStyles} />
158
165
  </Select.Option>
159
- ))}
160
- </Select.Viewport>
161
- <Select.ScrollDownButton />
162
- <Select.Arrow />
163
- </Select.Content>
164
- </Select.Portal>
165
- </Select.Root>
166
+ {[1, 2, 3, 4, 5, 6].map((level) => (
167
+ <Select.Option key={level} value={String(level)}>
168
+ {level === 1 && <TextHOne className={iconStyles} />}
169
+ {level === 2 && <TextHTwo className={iconStyles} />}
170
+ {level === 3 && <TextHThree className={iconStyles} />}
171
+ {level === 4 && <TextHFour className={iconStyles} />}
172
+ {level === 5 && <TextHFive className={iconStyles} />}
173
+ {level === 6 && <TextHSix className={iconStyles} />}
174
+ </Select.Option>
175
+ ))}
176
+ </Select.Viewport>
177
+ <Select.ScrollDownButton />
178
+ <Select.Arrow />
179
+ </Select.Content>
180
+ </Select.Portal>
181
+ </Select.Root>
182
+ <Tooltip.Portal>
183
+ <Tooltip.Content {...tooltipProps}>
184
+ {t('heading label')}
185
+ <Tooltip.Arrow />
186
+ </Tooltip.Content>
187
+ </Tooltip.Portal>
188
+ </Tooltip.Root>
166
189
  );
167
190
  };
168
191
 
@@ -276,15 +299,25 @@ const MarkdownExtended = () => {
276
299
  const { onAction } = useToolbarContext('MarkdownStyles');
277
300
  const { t } = useTranslation(translationKey);
278
301
  return (
279
- <NaturalToolbar.Button
280
- variant='ghost'
281
- data-testid='editor.toolbar.comment'
282
- onClick={() => onAction?.({ type: 'comment' })}
283
- classNames={buttonStyles}
284
- >
285
- <ChatText className={iconStyles} />
286
- <span className='sr-only'>{t('comment label')}</span>
287
- </NaturalToolbar.Button>
302
+ <Tooltip.Root>
303
+ <Tooltip.Trigger asChild>
304
+ <NaturalToolbar.Button
305
+ variant='ghost'
306
+ data-testid='editor.toolbar.comment'
307
+ onClick={() => onAction?.({ type: 'comment' })}
308
+ classNames={buttonStyles}
309
+ >
310
+ <ChatText className={iconStyles} />
311
+ <span className='sr-only'>{t('comment label')}</span>
312
+ </NaturalToolbar.Button>
313
+ </Tooltip.Trigger>
314
+ <Tooltip.Portal>
315
+ <Tooltip.Content {...tooltipProps}>
316
+ {t('comment label')}
317
+ <Tooltip.Arrow />
318
+ </Tooltip.Content>
319
+ </Tooltip.Portal>
320
+ </Tooltip.Root>
288
321
  );
289
322
  };
290
323
 
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  //
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
+ import translations from './translations';
4
5
 
5
6
  export { type Extension, type EditorState } from '@codemirror/state';
6
7
  export { type EditorView, keymap } from '@codemirror/view';
@@ -20,3 +21,4 @@ export {
20
21
  } from './styles';
21
22
  export * from './themes';
22
23
  export * from './util';
24
+ export { translations };
@@ -8,10 +8,11 @@ export default [
8
8
  {
9
9
  'en-US': {
10
10
  [translationKey]: {
11
- 'strong label': 'Strong',
12
- 'emphasis label': 'Emphasis',
13
- 'strikethrough label': 'Strike-through',
11
+ 'strong label': 'Bold',
12
+ 'emphasis label': 'Italics',
13
+ 'strikethrough label': 'Strikethrough',
14
14
  'code label': 'Code',
15
+ 'link label': 'Link',
15
16
  'list-bullet label': 'Bullet list',
16
17
  'list-ordered label': 'Numbered list',
17
18
  'list-task label': 'Task list',
@@ -19,6 +20,7 @@ export default [
19
20
  'codeblock label': 'Code block',
20
21
  'comment label': 'Create comment',
21
22
  'heading label': 'Heading level',
23
+ 'table label': 'Create table',
22
24
  },
23
25
  },
24
26
  },