@dxos/react-ui-editor 0.4.8-main.c67d72c → 0.4.8-main.cd60bd2

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 (71) hide show
  1. package/dist/lib/browser/index.mjs +1926 -1743
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -2
  5. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +2 -1
  7. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  8. package/dist/types/src/components/Toolbar/Toolbar.d.ts +12 -11
  9. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  10. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -2
  11. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  12. package/dist/types/src/extensions/automerge/automerge.stories.d.ts +1 -0
  13. package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
  14. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  15. package/dist/types/src/extensions/dnd.d.ts +7 -1
  16. package/dist/types/src/extensions/dnd.d.ts.map +1 -1
  17. package/dist/types/src/extensions/factories.d.ts +5 -1
  18. package/dist/types/src/extensions/factories.d.ts.map +1 -1
  19. package/dist/types/src/extensions/index.d.ts +1 -1
  20. package/dist/types/src/extensions/index.d.ts.map +1 -1
  21. package/dist/types/src/extensions/markdown/action.d.ts +9 -0
  22. package/dist/types/src/extensions/markdown/action.d.ts.map +1 -0
  23. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  24. package/dist/types/src/extensions/markdown/formatting.d.ts +7 -4
  25. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
  26. package/dist/types/src/extensions/markdown/image.d.ts +6 -0
  27. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
  28. package/dist/types/src/extensions/markdown/index.d.ts +1 -0
  29. package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
  30. package/dist/types/src/extensions/modes.d.ts +2 -1
  31. package/dist/types/src/extensions/modes.d.ts.map +1 -1
  32. package/dist/types/src/extensions/state.d.ts +20 -0
  33. package/dist/types/src/extensions/state.d.ts.map +1 -0
  34. package/dist/types/src/hooks/useActionHandler.d.ts +2 -2
  35. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -1
  36. package/dist/types/src/hooks/useDocAccessor.d.ts +4 -2
  37. package/dist/types/src/hooks/useDocAccessor.d.ts.map +1 -1
  38. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
  39. package/dist/types/src/hooks/useTextEditor.stories.d.ts +1 -0
  40. package/dist/types/src/hooks/useTextEditor.stories.d.ts.map +1 -1
  41. package/dist/types/src/themes/default.d.ts.map +1 -1
  42. package/dist/types/src/translations.d.ts +1 -0
  43. package/dist/types/src/translations.d.ts.map +1 -1
  44. package/package.json +26 -24
  45. package/src/components/TextEditor/TextEditor.stories.tsx +30 -6
  46. package/src/components/TextEditor/TextEditor.tsx +13 -12
  47. package/src/components/Toolbar/Toolbar.stories.tsx +23 -24
  48. package/src/components/Toolbar/Toolbar.tsx +102 -60
  49. package/src/extensions/automerge/automerge.ts +4 -4
  50. package/src/extensions/command/state.ts +2 -2
  51. package/src/extensions/comments.ts +2 -2
  52. package/src/extensions/dnd.ts +31 -9
  53. package/src/extensions/factories.ts +41 -15
  54. package/src/extensions/index.ts +1 -1
  55. package/src/extensions/markdown/action.ts +112 -0
  56. package/src/extensions/markdown/bundle.ts +8 -11
  57. package/src/extensions/markdown/formatting.test.ts +13 -13
  58. package/src/extensions/markdown/formatting.ts +95 -87
  59. package/src/extensions/markdown/image.ts +6 -0
  60. package/src/extensions/markdown/index.ts +1 -0
  61. package/src/extensions/modes.ts +11 -2
  62. package/src/extensions/state.ts +90 -0
  63. package/src/hooks/useActionHandler.ts +4 -85
  64. package/src/hooks/useDocAccessor.ts +8 -2
  65. package/src/hooks/useTextEditor.stories.tsx +3 -3
  66. package/src/hooks/useTextEditor.ts +3 -0
  67. package/src/themes/default.ts +24 -8
  68. package/src/translations.ts +1 -0
  69. package/dist/types/src/extensions/cursor-line-margin.d.ts +0 -7
  70. package/dist/types/src/extensions/cursor-line-margin.d.ts.map +0 -1
  71. package/src/extensions/cursor-line-margin.ts +0 -94
@@ -1,94 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- // Based upon @acheronfail’s implementation, fetched 16 Feb 2024
6
- // https://discuss.codemirror.net/t/cursorscrollmargin-for-v6/7448/5
7
-
8
- import { type EditorState, type Extension, Transaction } from '@codemirror/state';
9
- import { EditorView } from '@codemirror/view';
10
-
11
- import { log } from '@dxos/log';
12
-
13
- const annotation = 'cursorLineMargin';
14
- const lineAtPos = (s: EditorState, pos: number) => s.doc.lineAt(pos).number;
15
-
16
- type Options = {
17
- lines?: number;
18
- };
19
-
20
- // TODO(burdon): Remove. Buggy and creates scrolling problems. Find better (more general) way to deal with HALO notch.
21
- export const cursorLineMargin = (options: Options = { lines: 3 }): Extension => {
22
- const { lines } = options;
23
- if (!lines || lines <= 0) {
24
- return [];
25
- }
26
-
27
- return EditorView.updateListener.of(({ transactions, state, selectionSet, startState, view }) => {
28
- // make sure we don't trigger an infinite loop and ignore our own changes
29
- if (transactions.length < 1 || transactions.some((tr) => tr.isUserEvent(annotation))) {
30
- return;
31
- }
32
-
33
- const s = state;
34
- const { main } = s.selection;
35
-
36
- // editor rect
37
- const rect = view.dom.getBoundingClientRect();
38
- // top and bottom pixel positions of the visible region of the editor
39
- const viewportTop = rect.top - view.documentTop;
40
- const viewportBottom = rect.bottom - view.documentTop;
41
-
42
- // line with main selection
43
- const mainLine = lineAtPos(s, main.head);
44
- // top most visible line
45
- const _visTopLine = lineAtPos(s, view.lineBlockAtHeight(viewportTop).from);
46
-
47
- // bottom most visible line
48
- // NOTE: calculating this is slightly more complex - if the editor is
49
- // larger than all the lines in it, and the `scrollPastEnd()` extension is
50
- // enabled, then we need to calculate where the bottom most visible line
51
- // should be if it extended all the way to the bottom of the editor
52
- const botLineBlk = view.lineBlockAtHeight(viewportBottom);
53
- const visBotLineDoc = lineAtPos(s, Math.min(botLineBlk.to, s.doc.length));
54
- const visBotLine =
55
- botLineBlk.bottom >= viewportBottom
56
- ? visBotLineDoc
57
- : visBotLineDoc + Math.floor((viewportBottom - botLineBlk.bottom) / view.defaultLineHeight);
58
-
59
- // const needsScrollTop = mainLine <= visTopLine + cursorLineMargin;
60
- const needsScrollTop = false;
61
- const needsScrollBot = mainLine >= visBotLine - lines;
62
-
63
- // the scroll margins are overlapping
64
- if (needsScrollTop && needsScrollBot) {
65
- log.warn('is cursorScrollMargin too large for the editor size?');
66
- return;
67
- }
68
-
69
- // no need to scroll, we're in between scroll regions
70
- if (!needsScrollTop && !needsScrollBot) {
71
- return;
72
- }
73
-
74
- // if we're within the margin, but moving the other way, then don't scroll
75
- if (selectionSet) {
76
- const { head } = startState.selection.main;
77
- const oldMainLine = lineAtPos(startState, head);
78
- if (needsScrollTop && oldMainLine < mainLine) {
79
- return;
80
- }
81
- if (needsScrollBot && oldMainLine > mainLine) {
82
- return;
83
- }
84
- }
85
-
86
- view.dispatch({
87
- annotations: Transaction.userEvent.of(annotation),
88
- effects: EditorView.scrollIntoView(s.selection.main.head, {
89
- y: needsScrollTop ? 'start' : 'end',
90
- yMargin: view.defaultLineHeight * lines,
91
- }),
92
- });
93
- });
94
- };