@dxos/react-ui-editor 0.3.11-main.7ff9773 → 0.3.11-main.80db41b

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 (166) hide show
  1. package/dist/lib/browser/index.mjs +1402 -934
  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/MarkdownEditor.stories.d.ts +1 -2
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +3 -2
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +1 -1
  9. package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/{yjs.stories.d.ts → hooks.stories.d.ts} +13 -2
  11. package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/Toolbar/Toolbar.d.ts +25 -0
  13. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  14. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +23 -0
  15. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  17. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  18. package/dist/types/src/components/index.d.ts +1 -0
  19. package/dist/types/src/components/index.d.ts.map +1 -1
  20. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  21. package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
  22. package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
  23. package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
  24. package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
  25. package/dist/types/src/extensions/automerge/defs.d.ts +5 -5
  26. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  27. package/dist/types/src/extensions/automerge/semaphore.d.ts +2 -1
  28. package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
  29. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  30. package/dist/types/src/extensions/awareness.d.ts +2 -4
  31. package/dist/types/src/extensions/awareness.d.ts.map +1 -1
  32. package/dist/types/src/extensions/basic.d.ts +2 -2
  33. package/dist/types/src/extensions/basic.d.ts.map +1 -1
  34. package/dist/types/src/extensions/comments.d.ts +9 -5
  35. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  36. package/dist/types/src/extensions/index.d.ts +0 -7
  37. package/dist/types/src/extensions/index.d.ts.map +1 -1
  38. package/dist/types/src/extensions/markdown/bundle.d.ts +2 -2
  39. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  40. package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
  41. package/dist/types/src/extensions/markdown/formatting.d.ts +13 -0
  42. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
  43. package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
  44. package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
  45. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  46. package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
  47. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
  48. package/dist/types/src/extensions/markdown/index.d.ts +8 -0
  49. package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
  50. package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
  51. package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
  52. package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
  53. package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
  54. package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
  55. package/dist/types/src/hooks/defs.d.ts +1 -4
  56. package/dist/types/src/hooks/defs.d.ts.map +1 -1
  57. package/dist/types/src/hooks/index.d.ts +3 -2
  58. package/dist/types/src/hooks/index.d.ts.map +1 -1
  59. package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
  60. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
  61. package/dist/types/src/hooks/useEditorView.d.ts +17 -0
  62. package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
  63. package/dist/types/src/hooks/useTextEditor.d.ts +39 -0
  64. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
  65. package/dist/types/src/hooks/useTextModel.d.ts +12 -0
  66. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  67. package/dist/types/src/index.d.ts +1 -1
  68. package/dist/types/src/index.d.ts.map +1 -1
  69. package/dist/types/src/styles/markdown.d.ts +2 -2
  70. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  71. package/dist/types/src/themes/default.d.ts.map +1 -1
  72. package/package.json +39 -29
  73. package/src/components/TextEditor/MarkdownEditor.stories.tsx +15 -19
  74. package/src/components/TextEditor/TextEditor.tsx +46 -27
  75. package/src/components/TextEditor/automerge.stories.tsx +1 -2
  76. package/src/components/TextEditor/hooks.stories.tsx +106 -0
  77. package/src/components/Toolbar/Toolbar.stories.tsx +90 -0
  78. package/src/components/Toolbar/Toolbar.tsx +166 -0
  79. package/src/components/Toolbar/index.ts +5 -0
  80. package/src/components/index.ts +1 -0
  81. package/src/extensions/automerge/automerge.spec.tsx +76 -0
  82. package/src/extensions/automerge/automerge.test.ts +13 -0
  83. package/src/extensions/automerge/automerge.ts +44 -10
  84. package/src/extensions/automerge/cursor.ts +3 -3
  85. package/src/extensions/automerge/defs.ts +9 -9
  86. package/src/extensions/automerge/semaphore.ts +17 -19
  87. package/src/extensions/automerge/update-automerge.ts +12 -6
  88. package/src/extensions/automerge/update-codemirror.ts +5 -5
  89. package/src/extensions/awareness.ts +21 -35
  90. package/src/extensions/basic.ts +17 -15
  91. package/src/extensions/blast.ts +4 -1
  92. package/src/extensions/comments.ts +137 -79
  93. package/src/extensions/index.ts +0 -7
  94. package/src/extensions/markdown/bundle.ts +9 -8
  95. package/src/extensions/markdown/code.ts +150 -0
  96. package/src/extensions/markdown/formatting.ts +188 -0
  97. package/src/extensions/markdown/heading.ts +59 -0
  98. package/src/extensions/markdown/highlight.ts +9 -15
  99. package/src/extensions/{hr.ts → markdown/hr.ts} +3 -4
  100. package/src/extensions/markdown/index.ts +8 -0
  101. package/src/extensions/{link.ts → markdown/link.ts} +13 -4
  102. package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +2 -3
  103. package/src/hooks/awareness-provider.ts +24 -20
  104. package/src/hooks/defs.ts +1 -6
  105. package/src/hooks/index.ts +3 -2
  106. package/src/hooks/useActionHandler.ts +62 -0
  107. package/src/hooks/useEditorView.ts +29 -0
  108. package/src/hooks/useTextEditor.ts +153 -0
  109. package/src/hooks/useTextModel.ts +65 -12
  110. package/src/index.ts +1 -1
  111. package/src/styles/markdown.ts +9 -10
  112. package/src/themes/default.ts +11 -8
  113. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
  114. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
  115. package/dist/types/src/components/TextEditor/comments.stories.d.ts +0 -26
  116. package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +0 -1
  117. package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
  118. package/dist/types/src/extensions/code.d.ts.map +0 -1
  119. package/dist/types/src/extensions/hr.d.ts.map +0 -1
  120. package/dist/types/src/extensions/image.d.ts.map +0 -1
  121. package/dist/types/src/extensions/link.d.ts.map +0 -1
  122. package/dist/types/src/extensions/table.d.ts.map +0 -1
  123. package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
  124. package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
  125. package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
  126. package/dist/types/src/extensions/yjs/index.d.ts +0 -2
  127. package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
  128. package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
  129. package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
  130. package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
  131. package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
  132. package/dist/types/src/hooks/automerge.d.ts +0 -4
  133. package/dist/types/src/hooks/automerge.d.ts.map +0 -1
  134. package/dist/types/src/hooks/yjs.d.ts +0 -28
  135. package/dist/types/src/hooks/yjs.d.ts.map +0 -1
  136. package/dist/types/src/testing/index.d.ts +0 -3
  137. package/dist/types/src/testing/index.d.ts.map +0 -1
  138. package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
  139. package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
  140. package/dist/types/src/testing/proto/index.d.ts +0 -2
  141. package/dist/types/src/testing/proto/index.d.ts.map +0 -1
  142. package/dist/types/src/testing/replicator.d.ts +0 -45
  143. package/dist/types/src/testing/replicator.d.ts.map +0 -1
  144. package/src/components/TextEditor/codemirror.stories.ts +0 -115
  145. package/src/components/TextEditor/comments.stories.tsx +0 -357
  146. package/src/components/TextEditor/yjs.stories.tsx +0 -56
  147. package/src/extensions/code.ts +0 -104
  148. package/src/extensions/yjs/cursor.ts +0 -22
  149. package/src/extensions/yjs/index.ts +0 -5
  150. package/src/extensions/yjs/yjs.test.ts +0 -35
  151. package/src/extensions/yjs/yjs.ts +0 -16
  152. package/src/hooks/automerge.ts +0 -53
  153. package/src/hooks/yjs.ts +0 -157
  154. package/src/testing/index.ts +0 -6
  155. package/src/testing/proto/gen/schema.ts +0 -49
  156. package/src/testing/proto/index.ts +0 -5
  157. package/src/testing/proto/schema.proto +0 -15
  158. package/src/testing/replicator.ts +0 -184
  159. /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
  160. /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
  161. /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
  162. /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
  163. /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
  164. /package/dist/types/src/extensions/{tasklist.d.ts → markdown/tasklist.d.ts} +0 -0
  165. /package/src/extensions/{image.ts → markdown/image.ts} +0 -0
  166. /package/src/extensions/{table.ts → markdown/table.ts} +0 -0
@@ -0,0 +1,153 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import {
6
+ EditorSelection,
7
+ EditorState,
8
+ type EditorStateConfig,
9
+ type Extension,
10
+ type StateEffect,
11
+ } from '@codemirror/state';
12
+ import { EditorView } from '@codemirror/view';
13
+ import { type RefObject, useEffect, useRef, useState } from 'react';
14
+
15
+ import { log } from '@dxos/log';
16
+ import { type ThemeMode } from '@dxos/react-ui';
17
+ import { isNotFalsy } from '@dxos/util';
18
+
19
+ import { type ThemeStyles } from '..//styles';
20
+ import { defaultTheme } from '../themes';
21
+ import { logChanges } from '../util';
22
+
23
+ export type UseTextEditorOptions = {
24
+ autoFocus?: boolean;
25
+ scrollTo?: StateEffect<any>;
26
+ debug?: boolean;
27
+ } & EditorStateConfig;
28
+
29
+ export type UseTextEditor = {
30
+ parentRef: RefObject<HTMLDivElement>;
31
+ view?: EditorView;
32
+ };
33
+
34
+ /**
35
+ * Hook for creating editor.
36
+ */
37
+ export const useTextEditor = ({
38
+ autoFocus,
39
+ scrollTo,
40
+ debug,
41
+ doc,
42
+ selection,
43
+ extensions,
44
+ }: UseTextEditorOptions = {}): UseTextEditor => {
45
+ const onUpdate = useRef<() => void>();
46
+ const [view, setView] = useState<EditorView>();
47
+ const parentRef = useRef<HTMLDivElement>(null);
48
+ useEffect(() => {
49
+ if (parentRef.current) {
50
+ // https://codemirror.net/docs/ref/#state.EditorStateConfig
51
+ const state = EditorState.create({
52
+ doc,
53
+ selection,
54
+ extensions: [
55
+ // TODO(burdon): Doesn't catch errors in keymap functions.
56
+ EditorView.exceptionSink.of((err) => {
57
+ log.catch(err);
58
+ }),
59
+ extensions,
60
+ EditorView.updateListener.of(() => {
61
+ onUpdate.current?.();
62
+ }),
63
+ ].filter(isNotFalsy),
64
+ });
65
+
66
+ // https://codemirror.net/docs/ref/#view.EditorViewConfig
67
+ const view = new EditorView({
68
+ parent: parentRef.current,
69
+ scrollTo,
70
+ state,
71
+ // NOTE: Uncomment to debug/monitor all transactions.
72
+ // https://codemirror.net/docs/ref/#view.EditorView.dispatch
73
+ dispatchTransactions: (trs, view) => {
74
+ if (debug) {
75
+ logChanges(trs);
76
+ }
77
+ view.update(trs);
78
+ },
79
+ });
80
+
81
+ setView(view);
82
+ }
83
+
84
+ return () => {
85
+ view?.destroy();
86
+ };
87
+ }, [parentRef]);
88
+
89
+ useEffect(() => {
90
+ if (view) {
91
+ // Select end of line if not specified.
92
+ if (!selection && !view.state.selection.main.anchor) {
93
+ selection = EditorSelection.single(view.state.doc.line(1).to);
94
+ }
95
+
96
+ // Set selection after first update (since content may rerender on focus).
97
+ // TODO(burdon): BUG on first render may appear in middle of formatted heading.
98
+ // TODO(burdon): Make invisible until first render?
99
+ if (selection || scrollTo) {
100
+ onUpdate.current = () => {
101
+ onUpdate.current = undefined;
102
+ view.dispatch({ selection, effects: scrollTo && [scrollTo], scrollIntoView: !scrollTo });
103
+ };
104
+ }
105
+
106
+ if (autoFocus) {
107
+ view.focus();
108
+ }
109
+ }
110
+ }, [view, autoFocus, selection, scrollTo]);
111
+
112
+ return { parentRef, view };
113
+ };
114
+
115
+ // TODO(burdon): Factor out extension factories.
116
+
117
+ export type DataExtensionsOptions = {
118
+ readonly?: boolean;
119
+ };
120
+
121
+ // TODO(burdon): Pass in TextObject (remove model).
122
+ export const createDataExtensions = ({ readonly = false } = {}): Extension => {
123
+ return [
124
+ //
125
+ EditorState.readOnly.of(readonly),
126
+ EditorView.editable.of(!readonly),
127
+ ];
128
+ };
129
+
130
+ export type ThemeExtensionsOptions = {
131
+ theme?: ThemeStyles;
132
+ themeMode?: ThemeMode;
133
+ lineWrap?: boolean;
134
+ slots?: {
135
+ editor?: {
136
+ className?: string;
137
+ };
138
+ content?: {
139
+ className?: string;
140
+ };
141
+ };
142
+ };
143
+
144
+ export const createThemeExtensions = ({ theme, themeMode, slots }: ThemeExtensionsOptions = {}): Extension => {
145
+ return [
146
+ //
147
+ EditorView.baseTheme(defaultTheme),
148
+ theme && EditorView.theme(theme),
149
+ EditorView.darkTheme.of(themeMode === 'dark'),
150
+ EditorView.editorAttributes.of({ class: slots?.editor?.className ?? '' }),
151
+ EditorView.contentAttributes.of({ class: slots?.content?.className ?? '' }),
152
+ ].filter(isNotFalsy);
153
+ };
@@ -2,14 +2,19 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { useEffect, useState } from 'react';
5
+ import get from 'lodash.get';
6
+ import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
6
7
 
8
+ import { generateName } from '@dxos/display-name';
9
+ import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
10
+ import { invariant } from '@dxos/invariant';
7
11
  import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
8
12
  import { type Identity } from '@dxos/react-client/halo';
9
13
 
10
- import { createAutomergeModel } from './automerge';
11
- import { type EditorModel } from './defs';
12
- import { createYjsModel } from './yjs';
14
+ import { SpaceAwarenessProvider } from './awareness-provider';
15
+ import { type EditorModel, modelState } from './defs';
16
+ import { automerge, awareness } from '../extensions';
17
+ import { cursorColor } from '../styles';
13
18
 
14
19
  // TODO(burdon): Remove space/identity dependency. Define interface for the framework re content and presence.
15
20
  export type UseTextModelProps = {
@@ -25,13 +30,61 @@ export const useTextModel = (props: UseTextModelProps): EditorModel | undefined
25
30
  return model;
26
31
  };
27
32
 
28
- const createModel = (props: UseTextModelProps) => {
29
- const { text } = props;
30
- if (isAutomergeObject(text)) {
31
- return createAutomergeModel(props);
32
- } else if (text?.doc) {
33
- return createYjsModel(props);
34
- } else {
35
- return undefined;
33
+ /**
34
+ * For use primarily in stories & tests so the dependence on TextObject can be avoided.
35
+ * @param id
36
+ * @param defaultContent
37
+ */
38
+ export const useInMemoryTextModel = ({
39
+ id,
40
+ defaultContent,
41
+ }: {
42
+ id: string;
43
+ defaultContent?: string;
44
+ }): EditorModel & { setContent: Dispatch<SetStateAction<string>> } => {
45
+ const [content, setContent] = useState(defaultContent ?? '');
46
+ return { id, content, setContent, text: () => content };
47
+ };
48
+
49
+ const createModel = ({ space, identity, text }: UseTextModelProps) => {
50
+ invariant(isAutomergeObject(text));
51
+ const obj = text as any as AutomergeTextCompat;
52
+ const doc = getRawDoc(obj, [obj.field]);
53
+
54
+ const awarenessProvider =
55
+ space &&
56
+ new SpaceAwarenessProvider({
57
+ space,
58
+ channel: `automerge.awareness.${obj.id}`,
59
+ info: {
60
+ displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : undefined,
61
+ color: cursorColor.color,
62
+ lightColor: cursorColor.light,
63
+ },
64
+ peerId: identity?.identityKey.toHex() ?? 'Anonymous',
65
+ });
66
+
67
+ const extensions = [
68
+ //
69
+ modelState.init(() => model),
70
+ automerge({ handle: doc.handle, path: doc.path }),
71
+ ];
72
+ if (awarenessProvider) {
73
+ extensions.push(awareness(awarenessProvider));
36
74
  }
75
+
76
+ const model: EditorModel = {
77
+ id: obj.id,
78
+ content: doc,
79
+ text: () => get(doc.handle.docSync(), doc.path),
80
+ extension: extensions,
81
+ peer: identity
82
+ ? {
83
+ id: identity.identityKey.toHex(),
84
+ name: identity.profile?.displayName,
85
+ }
86
+ : undefined,
87
+ };
88
+
89
+ return model;
37
90
  };
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  export { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
6
6
  export { Doc, YText, YXmlFragment } from '@dxos/text-model';
7
7
  export { type Extension } from '@codemirror/state';
8
- export { type EditorView } from '@codemirror/view';
8
+ export { type EditorView, keymap } from '@codemirror/view';
9
9
 
10
10
  export * from './components';
11
11
  export * from './extensions';
@@ -8,18 +8,17 @@ export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
8
8
 
9
9
  // TODO(burdon): Better way to align vertically than negative margin? Font-specific?
10
10
  // https://tailwindcss.com/docs/font-weight
11
- export const headings: Record<HeadingLevel, string[]> = {
12
- 1: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl', '-ml-[10px]'],
13
- 2: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl', '-ml-[8px]'],
14
- 3: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl', '-ml-[7px]'],
15
- 4: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-xl', '-ml-[6px]'],
16
- 5: ['mbs-4 mbe-2 font-medium text-inherit no-underline text-lg', '-ml-[5px]'],
17
- 6: ['mbs-4 mbe-2 font-medium text-inherit no-underline', '-ml-[4px]'],
11
+ export const headings: Record<HeadingLevel, string> = {
12
+ 1: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl',
13
+ 2: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl',
14
+ 3: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl',
15
+ 4: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-xl',
16
+ 5: 'mbs-4 mbe-2 font-medium text-inherit no-underline text-lg',
17
+ 6: 'mbs-4 mbe-2 font-medium text-inherit no-underline',
18
18
  };
19
19
 
20
- export const heading = (level: HeadingLevel, readonly?: boolean) => {
21
- const [style, offset] = headings[level];
22
- return mx(style, readonly && offset);
20
+ export const heading = (level: HeadingLevel) => {
21
+ return headings[level];
23
22
  };
24
23
 
25
24
  export const text = 'text-neutral-800 dark:text-neutral-200';
@@ -49,9 +49,11 @@ export const defaultTheme: ThemeStyles = {
49
49
  '&.cm-focused': {
50
50
  outline: 'none',
51
51
  },
52
+
52
53
  '.cm-scroller': {
53
- overflow: 'visible',
54
+ // overflow: 'visible',
54
55
  fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
56
+ lineHeight: 1.4,
55
57
  },
56
58
 
57
59
  '.cm-content': {
@@ -60,11 +62,11 @@ export const defaultTheme: ThemeStyles = {
60
62
  fontSize: '16px',
61
63
  },
62
64
  '&light .cm-content': {
63
- color: get(tokens, 'extend.colors.neutral.900', 'black'),
65
+ color: get(tokens, 'extend.semanticColors.base.fg.light', 'black'),
64
66
  caretColor: 'black',
65
67
  },
66
68
  '&dark .cm-content': {
67
- color: get(tokens, 'extend.colors.neutral.100', 'white'),
69
+ color: get(tokens, 'extend.semanticColors.base.fg.dark', 'white'),
68
70
  caretColor: 'white',
69
71
  },
70
72
 
@@ -77,8 +79,11 @@ export const defaultTheme: ThemeStyles = {
77
79
  '&dark .cm-cursor, &dark .cm-dropCursor': {
78
80
  borderLeft: '2px solid white',
79
81
  },
80
- '.cm-placeholder': {
81
- fontWeight: 100,
82
+ '&light .cm-placeholder': {
83
+ color: get(tokens, 'extend.semanticColors.description.light', 'rgba(0,0,0,.2)'),
84
+ },
85
+ '&dark .cm-placeholder': {
86
+ color: get(tokens, 'extend.semanticColors.description.dark', 'rgba(255,255,255,.2)'),
82
87
  },
83
88
 
84
89
  //
@@ -86,11 +91,9 @@ export const defaultTheme: ThemeStyles = {
86
91
  //
87
92
  '.cm-line': {
88
93
  paddingInline: 0,
89
- // TODO(burdon): Other values leave gaps between lines when highlighted.
90
- // lineHeight: 'normal',
91
94
  },
92
95
  '.cm-activeLine': {
93
- background: 'inherit',
96
+ background: 'transparent',
94
97
  },
95
98
 
96
99
  //
@@ -1,12 +0,0 @@
1
- import { type StoryObj } from '@storybook/html';
2
- import { Client, type PublicKey } from '@dxos/react-client';
3
- declare const _default: {
4
- title: string;
5
- };
6
- export default _default;
7
- export declare const Default: StoryObj<{
8
- id: number;
9
- client: Client;
10
- spaceKey: PublicKey;
11
- }>;
12
- //# sourceMappingURL=codemirror.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codemirror.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/codemirror.stories.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAMhD,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;;;;AAU5D,wBAEE;AAqEF,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAE,CAoBjF,CAAC"}
@@ -1,26 +0,0 @@
1
- import '@dxosTheme';
2
- import { type EditorView } from '@codemirror/view';
3
- import React from 'react';
4
- type StoryProps = {
5
- text?: string;
6
- autoCreate?: boolean;
7
- };
8
- declare const _default: {
9
- title: string;
10
- component: React.ForwardRefExoticComponent<import("./TextEditor").TextEditorProps & React.RefAttributes<EditorView>>;
11
- decorators: import("@storybook/react").Decorator[];
12
- render: (args: StoryProps) => JSX.Element;
13
- };
14
- export default _default;
15
- export declare const Default: {
16
- args: {
17
- text: string;
18
- };
19
- };
20
- export declare const Testing: {
21
- args: {
22
- text: string;
23
- autoCreate: boolean;
24
- };
25
- };
26
- //# sourceMappingURL=comments.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"comments.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/comments.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,UAAU,EAAU,MAAM,kBAAkB,CAAC;AAG3D,OAAO,KAAwD,MAAM,OAAO,CAAC;AA6M7E,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;;;;;mBAoHe,UAAU;;AAJ3B,wBAKE;AAWF,eAAO,MAAM,OAAO;;;;CAInB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"yjs.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/yjs.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC;;;;;;AAWxC,wBAIE;AA+BF,eAAO,MAAM,OAAO;;CAGnB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../../../src/extensions/code.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,IAAI,+CAiDhB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../../../src/extensions/hr.ts"],"names":[],"mappings":"AAmDA,eAAO,MAAM,EAAE,+CAoBd,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../src/extensions/image.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,SAAS,EAA4C,MAAM,mBAAmB,CAAC;AAG/G,MAAM,MAAM,YAAY,GAAG,EAAE,CAAC;AAE9B,eAAO,MAAM,KAAK,aAAa,YAAY,KAAQ,SA8BlD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../src/extensions/link.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AAkBpE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,aAAa,WAAW,KAAQ,SAsDhD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../src/extensions/table.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,QAAQ,EAAmB,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AASnH,MAAM,MAAM,YAAY,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,eAAO,MAAM,KAAK,aAAa,YAAY,8BAM1C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tasklist.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasklist.ts"],"names":[],"mappings":"AAsFA,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC;AAEjC,eAAO,MAAM,QAAQ,aAAa,eAAe,4CAsBhD,CAAC"}
@@ -1,4 +0,0 @@
1
- import * as Y from 'yjs';
2
- import { type CursorConverter } from '../cursor';
3
- export declare const cursorConverter: (text: Y.Text) => CursorConverter;
4
- //# sourceMappingURL=cursor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/cursor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,eAW7C,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './yjs';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/index.ts"],"names":[],"mappings":"AAIA,cAAc,OAAO,CAAC"}
@@ -1,4 +0,0 @@
1
- import type * as YP from 'y-protocols/awareness';
2
- import type { YText } from '@dxos/text-model';
3
- export declare const yjs: (content: YText, awareness?: YP.Awareness) => import("@codemirror/state").Extension[];
4
- //# sourceMappingURL=yjs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yjs.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/yjs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAK9C,eAAO,MAAM,GAAG,YAAa,KAAK,cAAc,GAAG,SAAS,4CAG3D,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=yjs.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yjs.test.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/yjs.test.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import { type EditorModel } from './defs';
2
- import { type UseTextModelProps } from './useTextModel';
3
- export declare const createAutomergeModel: ({ space, identity, text }: UseTextModelProps) => EditorModel;
4
- //# sourceMappingURL=automerge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"automerge.d.ts","sourceRoot":"","sources":["../../../../src/hooks/automerge.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIxD,eAAO,MAAM,oBAAoB,8BAA+B,iBAAiB,KAAG,WAqCnF,CAAC"}
@@ -1,28 +0,0 @@
1
- import { Observable } from 'lib0/observable';
2
- import * as YP from 'y-protocols/awareness';
3
- import { type Doc } from 'yjs';
4
- import { type Space } from '@dxos/react-client/echo';
5
- import { type EditorModel } from './defs';
6
- import { type UseTextModelProps } from './useTextModel';
7
- export declare const createYjsModel: ({ identity, space, text }: UseTextModelProps) => EditorModel;
8
- /**
9
- * Yjs awareness provider on top of a DXOS space.
10
- */
11
- export declare class YAwarenessProvider extends Observable<any> {
12
- private readonly _space;
13
- private readonly _awareness;
14
- private readonly _clientId;
15
- private readonly _channel;
16
- constructor({ space, doc, channel, awareness, }: {
17
- space: Space;
18
- doc: Doc;
19
- channel: string;
20
- awareness?: YP.Awareness;
21
- });
22
- get awareness(): YP.Awareness;
23
- private _handleAwarenessUpdate;
24
- private _handleSpaceMessage;
25
- private _readMessage;
26
- private _handleBeforeUnload;
27
- }
28
- //# sourceMappingURL=yjs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yjs.d.ts","sourceRoot":"","sources":["../../../../src/hooks/yjs.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAI/B,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAIrD,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,eAAO,MAAM,cAAc,8BAA+B,iBAAiB,KAAG,WAqB7E,CAAC;AAOF;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU,CAAC,GAAG,CAAC;IACrD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,EACV,KAAK,EACL,GAAG,EACH,OAAO,EACP,SAAS,GACV,EAAE;QACD,KAAK,EAAE,KAAK,CAAC;QACb,GAAG,EAAE,GAAG,CAAC;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC;KAC1B;IA4BD,IAAI,SAAS,IAAI,EAAE,CAAC,SAAS,CAE5B;IAED,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,YAAY;IAoCpB,OAAO,CAAC,mBAAmB;CAG5B"}
@@ -1,3 +0,0 @@
1
- export * from './proto';
2
- export * from './replicator';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -1,15 +0,0 @@
1
- /**
2
- * @generated @dxos/echo-typegen src/testing/proto/schema.proto
3
- **/
4
- import * as dxos_echo_schema from "@dxos/echo-schema";
5
- export declare const types: dxos_echo_schema.TypeCollection;
6
- export type EditorDocumentProps = {
7
- content: dxos_echo_schema.Text;
8
- };
9
- export declare class EditorDocument extends dxos_echo_schema.TypedObject<EditorDocumentProps> {
10
- static readonly schema: dxos_echo_schema.Schema;
11
- static filter(filter?: Partial<EditorDocumentProps> | dxos_echo_schema.OperatorFilter<EditorDocument>): dxos_echo_schema.Filter<EditorDocument>;
12
- constructor(initValues?: Partial<EditorDocumentProps>, opts?: dxos_echo_schema.TypedObjectOptions);
13
- content: dxos_echo_schema.Text;
14
- }
15
- //# sourceMappingURL=schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../../src/testing/proto/gen/schema.ts"],"names":[],"mappings":"AAAA;;IAEI;AAEJ,OAAO,KAAK,gBAAgB,MAAM,mBAAmB,CAAC;AAEtD,eAAO,MAAM,KAAK,iCAAwC,CAAC;AAE3D,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,gBAAgB,CAAC,IAAI,CAAC;CAChC,CAAC;AAEF,qBAAa,cAAe,SAAQ,gBAAgB,CAAC,WAAW,CAAC,mBAAmB,CAAC;IACnF,gBAAwB,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAExD,MAAM,CAAC,MAAM,CACX,MAAM,CAAC,EACH,OAAO,CAAC,mBAAmB,CAAC,GAC5B,gBAAgB,CAAC,cAAc,CAAC,cAAc,CAAC,GAClD,gBAAgB,CAAC,MAAM,CAAC,cAAc,CAAC;gBAQxC,UAAU,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,EACzC,IAAI,CAAC,EAAE,gBAAgB,CAAC,kBAAkB;IAIpC,OAAO,EAAE,gBAAgB,CAAC,IAAI,CAAC;CACxC"}
@@ -1,2 +0,0 @@
1
- export * from './gen/schema';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/testing/proto/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC"}
@@ -1,45 +0,0 @@
1
- import { Observable } from 'lib0/observable';
2
- import * as YP from 'y-protocols/awareness';
3
- import { Doc } from 'yjs';
4
- import { Event } from '@dxos/async';
5
- import { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
6
- import { type EditorModel } from '../hooks';
7
- type Awareness = YP.Awareness;
8
- /**
9
- * Yjs awareness provider in-memory.
10
- */
11
- export declare class AwarenessProvider extends Observable<any> {
12
- private readonly _remoteUpdate;
13
- private readonly _awareness;
14
- private readonly _doc;
15
- constructor({ update, doc, awareness }: {
16
- update: Event<Uint8Array>;
17
- doc: Doc;
18
- awareness?: Awareness;
19
- });
20
- get awareness(): Awareness;
21
- private _handleDocUpdate;
22
- private _handleAwarenessUpdate;
23
- private _handleRemoteUpdate;
24
- private _readMessage;
25
- private _handleBeforeUnload;
26
- }
27
- /**
28
- * This mocks the replication across the swarm.
29
- */
30
- export declare class Replicator {
31
- private readonly _kind;
32
- private readonly _update;
33
- private _peers;
34
- constructor(_kind: TextKind);
35
- setPeers(peers: EditorModel[]): void;
36
- createPeer: (id: string, doc?: Doc) => EditorModel;
37
- }
38
- export type UseYjsModelOptions = {
39
- replicator: Replicator;
40
- id: string;
41
- doc?: Doc;
42
- };
43
- export declare const useYjsModel: ({ replicator, id, doc }: UseYjsModelOptions) => EditorModel;
44
- export {};
45
- //# sourceMappingURL=replicator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replicator.d.ts","sourceRoot":"","sources":["../../../../src/testing/replicator.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAEtE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,KAAK,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;AAM9B;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,UAAU,CAAC,GAAG,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoB;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAM;gBAEf,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,GAAG,EAAE,GAAG,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE;IA4BtG,IAAI,SAAS,IAAI,SAAS,CAEzB;IAED,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,YAAY;IA0CpB,OAAO,CAAC,mBAAmB;CAG5B;AAED;;GAEG;AACH,qBAAa,UAAU;IAIT,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHlC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,MAAM,CAAqB;gBAEN,KAAK,EAAE,QAAQ;IAE5C,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE;IAI7B,UAAU,OAAQ,MAAM,QAAO,GAAG,KAAe,WAAW,CAoB1D;CACH;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,UAAU,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,eAAO,MAAM,WAAW,4BAA6B,kBAAkB,KAAG,WAEzE,CAAC"}