@dxos/react-ui-editor 0.4.8-main.eb5ae94 → 0.4.8-main.fff1521

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 (127) hide show
  1. package/dist/lib/browser/index.mjs +2725 -2711
  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 +18 -34
  5. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +80 -5
  7. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  8. package/dist/types/src/components/Toolbar/Toolbar.d.ts +11 -5
  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.d.ts +1 -1
  13. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  14. package/dist/types/src/extensions/automerge/automerge.stories.d.ts +2 -1
  15. package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
  16. package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
  17. package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
  18. package/dist/types/src/extensions/automerge/defs.d.ts +1 -15
  19. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  20. package/dist/types/src/extensions/automerge/index.d.ts +0 -1
  21. package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
  22. package/dist/types/src/extensions/automerge/sync.d.ts +2 -1
  23. package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
  24. package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -1
  25. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  26. package/dist/types/src/{hooks → extensions/awareness}/awareness-provider.d.ts +1 -1
  27. package/dist/types/src/extensions/awareness/awareness-provider.d.ts.map +1 -0
  28. package/dist/types/src/extensions/awareness/awareness.d.ts.map +1 -0
  29. package/dist/types/src/extensions/awareness/index.d.ts +3 -0
  30. package/dist/types/src/extensions/awareness/index.d.ts.map +1 -0
  31. package/dist/types/src/extensions/comments.d.ts +2 -2
  32. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  33. package/dist/types/src/extensions/cursor-line-margin.d.ts +6 -7
  34. package/dist/types/src/extensions/cursor-line-margin.d.ts.map +1 -1
  35. package/dist/types/src/extensions/cursor.d.ts +1 -1
  36. package/dist/types/src/extensions/cursor.d.ts.map +1 -1
  37. package/dist/types/src/extensions/doc.d.ts +3 -0
  38. package/dist/types/src/extensions/doc.d.ts.map +1 -0
  39. package/dist/types/src/extensions/factories.d.ts +49 -0
  40. package/dist/types/src/extensions/factories.d.ts.map +1 -0
  41. package/dist/types/src/extensions/index.d.ts +4 -1
  42. package/dist/types/src/extensions/index.d.ts.map +1 -1
  43. package/dist/types/src/extensions/markdown/bundle.d.ts +5 -4
  44. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  45. package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
  46. package/dist/types/src/extensions/markdown/formatting.d.ts +8 -5
  47. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
  48. package/dist/types/src/extensions/markdown/image.d.ts +6 -0
  49. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
  50. package/dist/types/src/extensions/markdown/table.d.ts +2 -2
  51. package/dist/types/src/extensions/markdown/table.d.ts.map +1 -1
  52. package/dist/types/src/extensions/modes.d.ts +1 -0
  53. package/dist/types/src/extensions/modes.d.ts.map +1 -1
  54. package/dist/types/src/extensions/state.d.ts +20 -0
  55. package/dist/types/src/extensions/state.d.ts.map +1 -0
  56. package/dist/types/src/extensions/types.d.ts +9 -0
  57. package/dist/types/src/extensions/types.d.ts.map +1 -0
  58. package/dist/types/src/hooks/index.d.ts +1 -4
  59. package/dist/types/src/hooks/index.d.ts.map +1 -1
  60. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -1
  61. package/dist/types/src/hooks/useDocAccessor.d.ts +7 -0
  62. package/dist/types/src/hooks/useDocAccessor.d.ts.map +1 -0
  63. package/dist/types/src/hooks/useTextEditor.d.ts +3 -44
  64. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
  65. package/dist/types/src/hooks/useTextEditor.stories.d.ts +7 -0
  66. package/dist/types/src/hooks/useTextEditor.stories.d.ts.map +1 -1
  67. package/dist/types/src/themes/default.d.ts +0 -3
  68. package/dist/types/src/themes/default.d.ts.map +1 -1
  69. package/dist/types/src/translations.d.ts +1 -0
  70. package/dist/types/src/translations.d.ts.map +1 -1
  71. package/package.json +25 -27
  72. package/src/components/TextEditor/TextEditor.stories.tsx +520 -23
  73. package/src/components/TextEditor/TextEditor.tsx +45 -156
  74. package/src/components/Toolbar/Toolbar.stories.tsx +54 -55
  75. package/src/components/Toolbar/Toolbar.tsx +96 -35
  76. package/src/extensions/automerge/automerge.stories.tsx +16 -17
  77. package/src/extensions/automerge/automerge.ts +2 -1
  78. package/src/extensions/automerge/cursor.ts +1 -1
  79. package/src/extensions/automerge/defs.ts +1 -22
  80. package/src/extensions/automerge/index.ts +0 -1
  81. package/src/extensions/automerge/sync.ts +2 -9
  82. package/src/extensions/automerge/update-automerge.ts +2 -1
  83. package/src/{hooks → extensions/awareness}/awareness-provider.ts +1 -1
  84. package/src/extensions/{awareness.ts → awareness/awareness.ts} +1 -1
  85. package/src/extensions/awareness/index.ts +6 -0
  86. package/src/extensions/command/state.ts +1 -1
  87. package/src/extensions/comments.ts +9 -5
  88. package/src/extensions/cursor-line-margin.ts +17 -18
  89. package/src/extensions/cursor.ts +1 -1
  90. package/src/extensions/doc.ts +14 -0
  91. package/src/extensions/factories.ts +167 -0
  92. package/src/extensions/index.ts +4 -1
  93. package/src/extensions/markdown/bundle.ts +11 -28
  94. package/src/extensions/markdown/decorate.ts +2 -4
  95. package/src/extensions/markdown/formatting.test.ts +13 -13
  96. package/src/extensions/markdown/formatting.ts +106 -93
  97. package/src/extensions/markdown/image.ts +7 -0
  98. package/src/extensions/markdown/table.ts +11 -3
  99. package/src/extensions/modes.ts +3 -1
  100. package/src/extensions/state.ts +90 -0
  101. package/src/extensions/types.ts +16 -0
  102. package/src/hooks/index.ts +1 -5
  103. package/src/hooks/useActionHandler.ts +5 -1
  104. package/src/hooks/useDocAccessor.ts +21 -0
  105. package/src/hooks/useTextEditor.stories.tsx +40 -35
  106. package/src/hooks/useTextEditor.ts +14 -120
  107. package/src/index.ts +1 -1
  108. package/src/themes/default.ts +1 -28
  109. package/src/translations.ts +1 -0
  110. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +0 -103
  111. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +0 -1
  112. package/dist/types/src/extensions/awareness.d.ts.map +0 -1
  113. package/dist/types/src/extensions/outliner.d.ts +0 -4
  114. package/dist/types/src/extensions/outliner.d.ts.map +0 -1
  115. package/dist/types/src/hooks/awareness-provider.d.ts.map +0 -1
  116. package/dist/types/src/hooks/defs.d.ts +0 -20
  117. package/dist/types/src/hooks/defs.d.ts.map +0 -1
  118. package/dist/types/src/hooks/useEditorView.d.ts +0 -20
  119. package/dist/types/src/hooks/useEditorView.d.ts.map +0 -1
  120. package/dist/types/src/hooks/useTextModel.d.ts +0 -33
  121. package/dist/types/src/hooks/useTextModel.d.ts.map +0 -1
  122. package/src/components/TextEditor/MarkdownEditor.stories.tsx +0 -524
  123. package/src/extensions/outliner.ts +0 -12
  124. package/src/hooks/defs.ts +0 -30
  125. package/src/hooks/useEditorView.ts +0 -32
  126. package/src/hooks/useTextModel.ts +0 -121
  127. /package/dist/types/src/extensions/{awareness.d.ts → awareness/awareness.d.ts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownEditor.stories.d.ts","sourceRoot":"","sources":["../../../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BAAa,yBAA0B,YAAW,WAAW;IACpD,WAAW,EAAE,aAAa,CAAmB;IAEpD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,WAAW,CAAC,CAAqB;IACzC,OAAO,CAAC,SAAS,CAAC,CAAqB;gBAE3B,IAAI,EAAE,UAAU;IAS5B,OAAO;IAKP,MAAM,CAAC,MAAM,EAAE,UAAU;IAKzB,OAAO,CAAC,qBAAqB;IAoB7B,OAAO,CAAC,uBAAuB;CA4EhC"}
@@ -1,4 +0,0 @@
1
- import { type Extension } from '@codemirror/state';
2
- export type OutlinerOptions = {};
3
- export declare const outliner: (options?: OutlinerOptions) => Extension;
4
- //# sourceMappingURL=outliner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"outliner.d.ts","sourceRoot":"","sources":["../../../../src/extensions/outliner.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC;AAGjC,eAAO,MAAM,QAAQ,aAAa,eAAe,KAAQ,SAExD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"awareness-provider.d.ts","sourceRoot":"","sources":["../../../../src/hooks/awareness-provider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,EAAS,MAAM,aAAa,CAAC;AAIzD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAaxH,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,sBAAuB,YAAW,iBAAiB;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IAEnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IAEtC,OAAO,CAAC,IAAI,CAAC,CAAU;IACvB,OAAO,CAAC,SAAS,CAAC,CAAe;IACjC,OAAO,CAAC,WAAW,CAAC,CAAiB;IAErC,SAAgB,iBAAiB,cAAqB;gBAE1C,MAAM,EAAE,uBAAuB;IAO3C,IAAI;IAqCJ,KAAK;IAML,eAAe,IAAI,cAAc,EAAE;IAInC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI;IAWrD,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,kBAAkB;CAK3B"}
@@ -1,20 +0,0 @@
1
- import { type Extension } from '@codemirror/state';
2
- import { type DocAccessor } from '@dxos/echo-schema';
3
- export type Range = {
4
- from: number;
5
- to: number;
6
- };
7
- export type Comment = {
8
- id: string;
9
- cursor?: string;
10
- };
11
- /**
12
- * @deprecated
13
- */
14
- export type EditorModel = {
15
- id: string;
16
- text: () => string;
17
- content: string | DocAccessor;
18
- extension?: Extension;
19
- };
20
- //# sourceMappingURL=defs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../../src/hooks/defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAGF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AAEH,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC"}
@@ -1,20 +0,0 @@
1
- import { type EditorView } from '@codemirror/view';
2
- import { type MutableRefObject } from 'react';
3
- /**
4
- * Hook for accessing the editor view.
5
- * @deprecated
6
- *
7
- * ```tsx
8
- * const Test = () => {
9
- * const [editorRef, viewInvalidated] = useEditorView();
10
- * useEffect(() => {
11
- * if (editorRef.current && !viewInvalidated) {
12
- * editorView?.focus();
13
- * }
14
- * }, [editorView]);
15
- * return <TextEditor ref={editorRef} />;
16
- * };
17
- * ```
18
- */
19
- export declare const useEditorView: (id: string) => [MutableRefObject<EditorView | null>, boolean];
20
- //# sourceMappingURL=useEditorView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEditorView.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useEditorView.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,gBAAgB,EAAoB,MAAM,OAAO,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,OAAQ,MAAM,KAAG,CAAC,iBAAiB,UAAU,GAAG,IAAI,CAAC,EAAE,OAAO,CAQvF,CAAC"}
@@ -1,33 +0,0 @@
1
- import { type Extension } from '@codemirror/state';
2
- import { type Dispatch, type SetStateAction } from 'react';
3
- import { type Space, type TextObject } from '@dxos/react-client/echo';
4
- import { type Identity } from '@dxos/react-client/halo';
5
- import { type EditorModel } from './defs';
6
- import { type DocAccessor } from '../extensions/automerge/defs';
7
- export type useTextExtensionsProps = {
8
- id: string;
9
- text: DocAccessor;
10
- space?: Space;
11
- identity?: Identity;
12
- };
13
- export declare const useTextExtensions: ({ id, text, space, identity }: useTextExtensionsProps) => Extension[];
14
- export type UseTextModelProps = {
15
- text?: TextObject;
16
- space?: Space;
17
- identity?: Identity | null;
18
- };
19
- /**
20
- * @deprecated
21
- */
22
- export declare const useTextModel: (props: UseTextModelProps) => EditorModel | undefined;
23
- /**
24
- * For use primarily in stories & tests so the dependence on TextObject can be avoided.
25
- * @deprecated
26
- */
27
- export declare const useInMemoryTextModel: ({ id, defaultContent, }: {
28
- id: string;
29
- defaultContent?: string | undefined;
30
- }) => EditorModel & {
31
- setContent: Dispatch<SetStateAction<string>>;
32
- };
33
- //# sourceMappingURL=useTextModel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTextModel.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTextModel.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAqB,MAAM,OAAO,CAAC;AAK9E,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAKxD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,MAAM,sBAAsB,GAAG;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAGF,eAAO,MAAM,iBAAiB,kCAAmC,sBAAsB,KAAG,SAAS,EAuBlG,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,YAAY,UAAW,iBAAiB,KAAG,WAAW,GAAG,SACb,CAAC;AAE1D;;;GAGG;AAEH,eAAO,MAAM,oBAAoB;QAI3B,MAAM;;;gBAEoB,SAAS,eAAe,MAAM,CAAC,CAAC;CAG/D,CAAC"}
@@ -1,524 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxosTheme';
6
-
7
- import { type EditorView } from '@codemirror/view';
8
- import { ArrowSquareOut, X } from '@phosphor-icons/react';
9
- import defaultsDeep from 'lodash.defaultsdeep';
10
- import React, { type FC, type KeyboardEvent, StrictMode, useRef, useState } from 'react';
11
- import { createRoot } from 'react-dom/client';
12
-
13
- import { TextObject } from '@dxos/echo-schema';
14
- import { keySymbols, parseShortcut } from '@dxos/keyboard';
15
- import { PublicKey } from '@dxos/keys';
16
- import { faker } from '@dxos/random';
17
- import { Button, DensityProvider, Input, ThemeProvider } from '@dxos/react-ui';
18
- import { baseSurface, defaultTx, getSize, mx, textBlockWidth } from '@dxos/react-ui-theme';
19
- import { withTheme } from '@dxos/storybook-utils';
20
-
21
- import { MarkdownEditor, type TextEditorProps } from './TextEditor';
22
- import {
23
- annotations,
24
- autocomplete,
25
- blast,
26
- command,
27
- comments,
28
- decorateMarkdown,
29
- defaultOptions,
30
- dnd,
31
- formatting,
32
- image,
33
- linkTooltip,
34
- mention,
35
- table,
36
- typewriter,
37
- useComments,
38
- EditorModes,
39
- type CommandAction,
40
- type CommandOptions,
41
- type CommentsOptions,
42
- listener,
43
- } from '../../extensions';
44
- import { type Comment, useTextModel } from '../../hooks';
45
- import translations from '../../translations';
46
-
47
- faker.seed(101);
48
-
49
- const str = (...lines: string[]) => lines.join('\n');
50
-
51
- const num = () => faker.number.int({ min: 0, max: 9999 }).toLocaleString();
52
-
53
- const img = '![dxos](https://pbs.twimg.com/profile_banners/1268328127673044992/1684766689/1500x500)';
54
-
55
- const text = {
56
- tasks: str(
57
- //
58
- '## Tasks',
59
- '',
60
- '- [x] decorator',
61
- '- [ ] checkbox',
62
- ' - [ ] state',
63
- ' - [ ] indent',
64
- ' - [x] style',
65
- '',
66
- ),
67
-
68
- list: str(
69
- //
70
- '## List',
71
- '',
72
- '- new york',
73
- '- london',
74
- '- tokyo',
75
- '',
76
- ),
77
-
78
- numbered: str(
79
- //
80
- '## Numbered',
81
- '',
82
- '1. one',
83
- '2. two',
84
- '3. three',
85
- '',
86
- ),
87
-
88
- code: str(
89
- '## Code',
90
- '',
91
- '```',
92
- '$ ls -las',
93
- '```',
94
- '',
95
- '```tsx',
96
- 'const Component = () => {',
97
- ' const x = 100;',
98
- '',
99
- ' return () => <div>Test</div>;',
100
- '};',
101
- '```',
102
- '',
103
- ),
104
-
105
- links: str(
106
- '## Links',
107
- '',
108
- 'This is a naked link https://dxos.org within a sentence.',
109
- '',
110
- 'Take a look at [DXOS](https://dxos.org) and how to [get started](https://docs.dxos.org/guide/getting-started.html).',
111
- '',
112
- ),
113
-
114
- table: str(
115
- '# Table',
116
- '',
117
- `| ${faker.lorem.word().padStart(12)} | ${faker.lorem.word().padStart(12)} | ${faker.lorem.word().padStart(12)} |`,
118
- `|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|`,
119
- `| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
120
- `| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
121
- `| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
122
- '',
123
- ),
124
-
125
- image: str('# Image', '', img),
126
-
127
- headings: str(
128
- ...[1, 2, 3, 4, 5, 6].map((level) => ['#'.repeat(level) + ` Heading ${level}`, faker.lorem.sentences(), '']).flat(),
129
- ),
130
-
131
- paragraphs: str(...faker.helpers.multiple(() => [faker.lorem.paragraph(), ''], { count: 3 }).flat()),
132
-
133
- footer: str('', '', '', '', ''),
134
- };
135
-
136
- const document = str(
137
- '# Markdown',
138
- '',
139
- '> This is a block quote.',
140
- '',
141
- '> This is a long wrapping block quote. Neque reiciendis ullam quae error labore sit, at, et, nulla, aut at nostrum omnis quas nostrum, at consectetur vitae eos asperiores non omnis ullam in beatae at vitae deserunt asperiores sapiente.',
142
- '',
143
- '> This is',
144
- '> a multi-line',
145
- '> block quote.',
146
- '',
147
- 'This is all about https://dxos.org and related technologies.',
148
- '',
149
- 'This this is **bold**, ~~strikethrough~~, _italic_, and `f(INLINE)`.',
150
- '',
151
- '---',
152
- text.links,
153
- '---',
154
- text.list,
155
- '---',
156
- text.tasks,
157
- '---',
158
- text.numbered,
159
- '---',
160
- text.code,
161
- '---',
162
- text.headings,
163
- '---',
164
- text.table,
165
- '---',
166
- text.image,
167
- text.footer,
168
- );
169
-
170
- const links = [
171
- { label: 'DXOS', apply: '[DXOS](https://dxos.org)' },
172
- { label: 'GitHub', apply: '[DXOS GitHub](https://github.com/dxos)' },
173
- { label: 'Automerge', apply: '[Automerge](https://automerge.org/)' },
174
- { label: 'IPFS', apply: '[Protocol Labs](https://docs.ipfs.tech)' },
175
- { label: 'StackEdit', apply: '[StackEdit](https://stackedit.io/app)' },
176
- ];
177
-
178
- const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
179
-
180
- const hover =
181
- 'rounded-sm text-base text-primary-600 hover:text-primary-500 dark:text-primary-300 hover:dark:text-primary-200';
182
-
183
- const renderLinkTooltip = (el: Element, url: string) => {
184
- const web = new URL(url);
185
- createRoot(el).render(
186
- <StrictMode>
187
- <a href={url} target='_blank' rel='noreferrer' className={hover}>
188
- {web.origin}
189
- <ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1')} />
190
- </a>
191
- </StrictMode>,
192
- );
193
- };
194
-
195
- const Key: FC<{ char: string }> = ({ char }) => (
196
- <span className='flex justify-center items-center w-[24px] h-[24px] rounded text-xs bg-neutral-200 text-black'>
197
- {char}
198
- </span>
199
- );
200
-
201
- const onCommentsHover: CommentsOptions['onHover'] = (el, shortcut) => {
202
- createRoot(el).render(
203
- <StrictMode>
204
- <div className='flex items-center gap-2 px-2 py-2 bg-neutral-700 text-white text-xs rounded'>
205
- <div>Create comment</div>
206
- <div className='flex gap-1'>
207
- {keySymbols(parseShortcut(shortcut)).map((char) => (
208
- <Key key={char} char={char} />
209
- ))}
210
- </div>
211
- </div>
212
- </StrictMode>,
213
- );
214
- };
215
-
216
- const renderLinkButton = (el: Element, url: string) => {
217
- createRoot(el).render(
218
- <StrictMode>
219
- <a href={url} target='_blank' rel='noreferrer' className={hover}>
220
- <ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1 mb-[2px]')} />
221
- </a>
222
- </StrictMode>,
223
- );
224
- };
225
-
226
- type StoryProps = {
227
- id?: string;
228
- text?: string;
229
- comments?: Comment[];
230
- } & Pick<TextEditorProps, 'readonly' | 'placeholder' | 'extensions'>;
231
-
232
- const Story = ({ id = 'test', text, comments, placeholder = 'New document.', ...props }: StoryProps) => {
233
- const [item] = useState({ text: new TextObject(text) });
234
- const view = useRef<EditorView>(null);
235
- const model = useTextModel({ text: item.text });
236
- useComments(view.current, id, comments);
237
- if (!model) {
238
- return null;
239
- }
240
-
241
- return (
242
- <MarkdownEditor
243
- ref={view}
244
- model={model}
245
- placeholder={placeholder}
246
- slots={{
247
- root: { className: mx(textBlockWidth, 'min-bs-dvh') },
248
- editor: { className: 'min-bs-dvh px-8 bg-white dark:bg-black' },
249
- }}
250
- {...props}
251
- />
252
- );
253
- };
254
-
255
- export default {
256
- title: 'react-ui-editor/MarkdownEditor',
257
- component: MarkdownEditor,
258
- decorators: [withTheme],
259
- render: Story,
260
- parameters: { translations, layout: 'fullscreen' },
261
- };
262
-
263
- const defaults = [
264
- autocomplete({
265
- onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
266
- }),
267
- decorateMarkdown({ renderLinkButton }),
268
- formatting(),
269
- image(),
270
- linkTooltip(renderLinkTooltip),
271
- table(),
272
- ];
273
-
274
- export const Default = {
275
- render: () => <Story text={document} extensions={defaults} />,
276
- };
277
-
278
- export const Readonly = {
279
- render: () => <Story text={document} extensions={defaults} readonly />,
280
- };
281
-
282
- export const NoExtensions = {
283
- render: () => <Story text={document} />,
284
- };
285
-
286
- const large = faker.helpers.multiple(() => faker.lorem.paragraph({ min: 8, max: 16 }), { count: 20 }).join('\n\n');
287
-
288
- const largeWithImages = faker.helpers
289
- .multiple(() => [faker.lorem.paragraph({ min: 12, max: 16 }), img], { count: 20 })
290
- .flatMap((x) => x)
291
- .join('\n\n');
292
-
293
- export const Empty = {
294
- render: () => <Story />,
295
- };
296
-
297
- export const Scrolling = {
298
- render: () => <Story text={str('# Large Document', '', large)} />,
299
- };
300
-
301
- export const ScrollingWithImages = {
302
- render: () => <Story text={str('# Large Document', '', largeWithImages)} extensions={[image()]} />,
303
- };
304
-
305
- export const Links = {
306
- render: () => <Story text={str(text.links, text.footer)} extensions={[linkTooltip(renderLinkTooltip)]} />,
307
- };
308
-
309
- export const Image = {
310
- render: () => <Story text={str(text.image, text.footer)} extensions={[image()]} />,
311
- };
312
-
313
- export const Code = {
314
- render: () => <Story text={str(text.code, text.footer)} extensions={[decorateMarkdown()]} />,
315
- };
316
-
317
- export const Lists = {
318
- render: () => (
319
- <Story text={str(text.tasks, '', text.list, '', text.numbered, text.footer)} extensions={[decorateMarkdown()]} />
320
- ),
321
- };
322
-
323
- export const Table = {
324
- render: () => <Story text={str(text.table, text.footer)} extensions={[table()]} />,
325
- };
326
-
327
- // export const Outliner = {
328
- // render: () => (
329
- // <Story
330
- // text={str('# Outliner', '', 'Block', ': this is a block', ': with multiple lines', text.footer)}
331
- // extensions={[outliner()]}
332
- // />
333
- // ),
334
- // };
335
-
336
- export const Autocomplete = {
337
- render: () => (
338
- <Story
339
- text={str('# Autocomplete', '', 'Press Ctrl-Space...', text.footer)}
340
- extensions={[
341
- decorateMarkdown({ renderLinkButton }),
342
- autocomplete({
343
- onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
344
- }),
345
- ]}
346
- />
347
- ),
348
- };
349
-
350
- export const Mention = {
351
- render: () => (
352
- <Story
353
- text={str('# Mention', '', 'Type @...', text.footer)}
354
- extensions={[
355
- mention({
356
- onSearch: (text) => names.filter((name) => name.toLowerCase().startsWith(text.toLowerCase())),
357
- }),
358
- ]}
359
- />
360
- ),
361
- };
362
-
363
- const CommandDialog: FC<{ onClose: (action?: CommandAction) => void }> = ({ onClose }) => {
364
- const [text, setText] = useState('');
365
- const handleInsert = () => {
366
- onClose(text.length ? { insert: text + '\n' } : undefined);
367
- };
368
-
369
- const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
370
- switch (event.key) {
371
- case 'Enter': {
372
- handleInsert();
373
- break;
374
- }
375
- case 'Escape': {
376
- onClose();
377
- break;
378
- }
379
- }
380
- };
381
-
382
- return (
383
- <DensityProvider density='fine'>
384
- <div className={mx('flex items-center p-2 gap-2 border rounded-md', baseSurface)}>
385
- <Input.Root>
386
- <Input.TextInput
387
- autoFocus={true}
388
- placeholder='Enter command.'
389
- value={text}
390
- onChange={({ target: { value } }) => setText(value)}
391
- onKeyDown={handleKeyDown}
392
- />
393
- </Input.Root>
394
- <Button variant='ghost' classNames='pli-0' onClick={() => onClose()}>
395
- <X className={getSize(5)} />
396
- </Button>
397
- </div>
398
- </DensityProvider>
399
- );
400
- };
401
-
402
- const renderCommandDialog: CommandOptions['onRender'] = (el, onClose) => {
403
- createRoot(el).render(
404
- <StrictMode>
405
- <ThemeProvider tx={defaultTx}>
406
- <CommandDialog onClose={onClose} />
407
- </ThemeProvider>
408
- </StrictMode>,
409
- );
410
- };
411
-
412
- export const Command = {
413
- render: () => (
414
- <Story
415
- text={str('# Command', '')}
416
- extensions={[command({ onRender: renderCommandDialog, onHint: () => 'Press / for commands.' })]}
417
- />
418
- ),
419
- };
420
-
421
- export const Comments = {
422
- render: () => {
423
- const [_comments, setComments] = useState<Comment[]>([]);
424
-
425
- return (
426
- <Story
427
- text={str('# Comments', '', text.paragraphs, text.footer)}
428
- comments={_comments}
429
- extensions={[
430
- comments({
431
- onHover: onCommentsHover,
432
- onCreate: ({ cursor }) => {
433
- const id = PublicKey.random().toHex();
434
- setComments((commentRanges) => [...commentRanges, { id, cursor }]);
435
- return id;
436
- },
437
- onSelect: (state) => {
438
- const debug = false;
439
- if (debug) {
440
- console.log(
441
- 'update',
442
- JSON.stringify({
443
- comments: state.comments.length,
444
- active: state.selection.current?.slice(0, 8),
445
- closest: state.selection.closest?.slice(0, 8),
446
- }),
447
- );
448
- }
449
- },
450
- }),
451
- ]}
452
- />
453
- );
454
- },
455
- };
456
-
457
- export const Vim = {
458
- render: () => (
459
- <Story
460
- text={str('# Vim Mode', '', 'The distant future. The year 2000.', '', text.paragraphs)}
461
- extensions={[defaults, EditorModes.vim]}
462
- />
463
- ),
464
- };
465
-
466
- export const Annotations = {
467
- render: () => <Story text={str('# Annotations', '', large)} extensions={[annotations({ match: /volup/gi })]} />,
468
- };
469
-
470
- export const DND = {
471
- render: () => <Story text={str('# DND', '')} extensions={[dnd()]} />,
472
- };
473
-
474
- const typewriterItems = localStorage.getItem('dxos.org/plugin/markdown/typewriter')?.split(',');
475
-
476
- export const Listener = {
477
- render: () => (
478
- <Story
479
- text={str('# Listener', '', text.footer)}
480
- extensions={[
481
- listener({
482
- onFocus: (focusing) => {
483
- console.log({ focusing });
484
- },
485
- onChange: (text) => {
486
- console.log({ text });
487
- },
488
- }),
489
- ]}
490
- />
491
- ),
492
- };
493
-
494
- export const Typewriter = {
495
- render: () => (
496
- <Story
497
- text={str('# Typewriter', '', text.paragraphs, text.footer)}
498
- extensions={[typewriter({ items: typewriterItems })]}
499
- />
500
- ),
501
- };
502
-
503
- export const Blast = {
504
- render: () => (
505
- <Story
506
- text={str('# Blast', '', text.paragraphs, text.code, text.paragraphs)}
507
- extensions={[
508
- typewriter({ items: typewriterItems }),
509
- blast(
510
- defaultsDeep(
511
- {
512
- effect: 2,
513
- particleGravity: 0.2,
514
- particleShrinkRate: 0.995,
515
- color: () => [faker.number.int({ min: 100, max: 200 }), 0, 0],
516
- // color: () => [faker.number.int(256), faker.number.int(256), faker.number.int(256)],
517
- },
518
- defaultOptions,
519
- ),
520
- ),
521
- ]}
522
- />
523
- ),
524
- };
@@ -1,12 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Extension } from '@codemirror/state';
6
-
7
- export type OutlinerOptions = {};
8
-
9
- // TODO(burdon): Experimental component: multiple hierarchical draggable editor sections.
10
- export const outliner = (options: OutlinerOptions = {}): Extension => {
11
- return [];
12
- };
package/src/hooks/defs.ts DELETED
@@ -1,30 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Extension } from '@codemirror/state';
6
-
7
- import { type DocAccessor } from '@dxos/echo-schema';
8
-
9
- // Runtime data structure.
10
- export type Range = {
11
- from: number;
12
- to: number;
13
- };
14
-
15
- // Persistent data structure.
16
- export type Comment = {
17
- id: string;
18
- cursor?: string;
19
- };
20
-
21
- /**
22
- * @deprecated
23
- */
24
- // TODO(burdon): Remove.
25
- export type EditorModel = {
26
- id: string;
27
- text: () => string;
28
- content: string | DocAccessor;
29
- extension?: Extension;
30
- };