@dxos/react-ui-editor 0.4.3 → 0.4.4-main.20c0bd9

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.
@@ -23,42 +23,53 @@ const styles = EditorView.baseTheme({
23
23
  '& .cm-code': {
24
24
  fontFamily: getToken('fontFamily.mono', []).join(','),
25
25
  },
26
- '& .cm-codeblock': {
27
- width: '100%',
26
+ '& .cm-codeblock-line': {
28
27
  paddingInline: '1rem !important',
28
+ },
29
+
30
+ '& .cm-codeblock-end': {
31
+ display: 'inline-block',
32
+ width: '100%',
29
33
  position: 'relative',
30
34
  '&::after': {
31
- content: '""',
32
35
  position: 'absolute',
33
36
  inset: 0,
34
- },
35
- },
36
- '&light .cm-codeblock': {
37
- '&::after': {
38
- background: getToken('extend.semanticColors.input.light'),
39
- mixBlendMode: 'darken',
40
- },
41
- },
42
- '&dark .cm-codeblock': {
43
- '&::after': {
44
- background: getToken('extend.semanticColors.input.dark'),
45
- mixBlendMode: 'lighten',
37
+ content: '""',
46
38
  },
47
39
  },
48
40
  '& .cm-codeblock-first': {
49
- display: 'inline-block',
50
41
  '&::after': {
51
42
  borderTopLeftRadius: '.5rem',
52
43
  borderTopRightRadius: '.5rem',
53
44
  },
54
45
  },
55
46
  '& .cm-codeblock-last': {
56
- display: 'inline-block',
57
47
  '&::after': {
58
48
  borderBottomLeftRadius: '.5rem',
59
49
  borderBottomRightRadius: '.5rem',
60
50
  },
61
51
  },
52
+
53
+ '&light .cm-codeblock-line, &light .cm-activeLine.cm-codeblock-line': {
54
+ background: getToken('extend.semanticColors.input.light'),
55
+ mixBlendMode: 'darken',
56
+ },
57
+ '&dark .cm-codeblock-line, &dark .cm-activeLine.cm-codeblock-line': {
58
+ background: getToken('extend.semanticColors.input.dark'),
59
+ mixBlendMode: 'lighten',
60
+ },
61
+ '&light .cm-codeblock-first, &light .cm-codeblock-last': {
62
+ mixBlendMode: 'darken',
63
+ '&::after': {
64
+ background: getToken('extend.semanticColors.input.light'),
65
+ },
66
+ },
67
+ '&dark .cm-codeblock-first, &dark .cm-codeblock-last': {
68
+ mixBlendMode: 'lighten',
69
+ '&::after': {
70
+ background: getToken('extend.semanticColors.input.dark'),
71
+ },
72
+ },
62
73
  });
63
74
 
64
75
  // TODO(burdon): Start from EditorView.lineBlockAt(pos).
@@ -68,7 +79,10 @@ const getLineRange = (lines: BlockInfo[], from: number, to: number) => {
68
79
  return [start, end];
69
80
  };
70
81
 
71
- // TODO(burdon): Add copy to clipboard widget.
82
+ /**
83
+ * Widget for first/last line of code block (read-only).
84
+ */
85
+ // TODO(burdon): Add copy-to-clipboard button.
72
86
  class LineWidget extends WidgetType {
73
87
  constructor(private readonly _className: string) {
74
88
  super();
@@ -82,10 +96,8 @@ class LineWidget extends WidgetType {
82
96
  }
83
97
  }
84
98
 
85
- const top = new LineWidget('cm-codeblock-first');
86
- const bottom = new LineWidget('cm-codeblock-last');
87
-
88
- // TODO(burdon): Selection isn't visible unless multiline (e.g., can't highlight word).
99
+ const top = new LineWidget('cm-codeblock-end cm-codeblock-first');
100
+ const bottom = new LineWidget('cm-codeblock-end cm-codeblock-last');
89
101
 
90
102
  const buildDecorations = (view: EditorView): DecorationSet => {
91
103
  const builder = new RangeSetBuilder<Decoration>();
@@ -98,11 +110,11 @@ const buildDecorations = (view: EditorView): DecorationSet => {
98
110
  enter: (node) => {
99
111
  if (node.name === 'FencedCode') {
100
112
  // FencedCode > CodeMark > [CodeInfo] > CodeText > CodeMark
101
- const edit = !view.state.readOnly && cursor >= node.from && cursor <= node.to;
113
+ const editing = !view.state.readOnly && cursor >= node.from && cursor <= node.to;
102
114
  const range = getLineRange(blocks, node.from, node.to);
103
115
  for (let i = range[0]; i <= range[1]; i++) {
104
116
  const block = blocks[i];
105
- if (!edit && (i === range[0] || i === range[1])) {
117
+ if (!editing && (i === range[0] || i === range[1])) {
106
118
  builder.add(block.from, block.to, Decoration.replace({ widget: i === range[0] ? top : bottom }));
107
119
  } else {
108
120
  builder.add(
@@ -110,7 +122,7 @@ const buildDecorations = (view: EditorView): DecorationSet => {
110
122
  block.from,
111
123
  Decoration.line({
112
124
  class: mx(
113
- 'cm-code cm-codeblock',
125
+ 'cm-code cm-codeblock-line',
114
126
  i === range[0] && 'cm-codeblock-first',
115
127
  i === range[1] && 'cm-codeblock-last',
116
128
  ),
@@ -370,7 +370,7 @@ describe('removeBlockquote', () => {
370
370
  });
371
371
 
372
372
  describe('addCodeblock', () => {
373
- testCommand('add a code block to a blank line', '{}', addCodeblock, '```{}\n```');
373
+ testCommand('add a code block to a blank line', '{}', addCodeblock, '```{}\n\n```');
374
374
 
375
375
  testCommand(
376
376
  'can turn a paragraph into a code block',
@@ -356,6 +356,7 @@ const snippets = {
356
356
  [
357
357
  //
358
358
  '```#{}',
359
+ '',
359
360
  '```',
360
361
  ].join('\n'),
361
362
  ),
package/src/index.ts CHANGED
@@ -11,6 +11,12 @@ export { Doc, YText, YXmlFragment } from '@dxos/text-model';
11
11
  export * from './components';
12
12
  export * from './extensions';
13
13
  export * from './hooks';
14
- export { getToken, editorWithToolbarLayout } from './styles';
14
+ export {
15
+ getToken,
16
+ editorWithToolbarLayout,
17
+ editorFillLayoutEditor,
18
+ editorFillLayoutRoot,
19
+ editorHalfViewportOverscrollContent,
20
+ } from './styles';
15
21
  export * from './themes';
16
22
  export * from './util';
@@ -3,4 +3,9 @@
3
3
  //
4
4
 
5
5
  export const editorWithToolbarLayout =
6
- 'fixed inset-0 grid grid-cols-1 grid-rows-[min-content_1fr] justify-center content-start overflow-hidden';
6
+ 'grid grid-cols-1 grid-rows-[min-content_1fr] justify-center content-start overflow-hidden';
7
+
8
+ export const editorFillLayoutRoot = 'min-bs-full grid';
9
+ export const editorFillLayoutEditor = 'min-bs-full';
10
+
11
+ export const editorHalfViewportOverscrollContent = 'after:block after:min-bs-[50dvh] after:pointer-events-none';