@dxos/react-ui-editor 0.3.11-main.cd64fe0 → 0.3.11-main.cf49a01
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.
- package/dist/lib/browser/index.mjs +1016 -1024
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +12 -16
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +13 -5
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +6 -8
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/semaphore.d.ts +6 -6
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -2
- package/dist/types/src/extensions/awareness.d.ts +1 -1
- package/dist/types/src/extensions/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/basic.d.ts +4 -5
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +18 -14
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/cursor.d.ts +3 -3
- package/dist/types/src/extensions/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +0 -7
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +3 -6
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
- package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +7 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts +3 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -1
- package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +25 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -2
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +17 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts +2 -27
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +32 -35
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +60 -65
- package/src/components/TextEditor/TextEditor.tsx +91 -66
- package/src/components/TextEditor/comments.stories.tsx +45 -43
- package/src/extensions/autocomplete.ts +6 -3
- package/src/extensions/automerge/automerge.ts +35 -39
- package/src/extensions/automerge/defs.ts +8 -33
- package/src/extensions/automerge/semaphore.ts +17 -12
- package/src/extensions/automerge/update-automerge.ts +2 -2
- package/src/extensions/awareness.ts +14 -14
- package/src/extensions/basic.ts +22 -17
- package/src/extensions/comments.ts +161 -141
- package/src/extensions/cursor.ts +7 -3
- package/src/extensions/index.ts +0 -7
- package/src/extensions/markdown/bundle.ts +20 -30
- package/src/extensions/markdown/code.ts +127 -0
- package/src/extensions/markdown/heading.ts +59 -0
- package/src/extensions/markdown/highlight.ts +9 -15
- package/src/extensions/markdown/hr.ts +71 -0
- package/src/extensions/markdown/index.ts +7 -0
- package/src/extensions/{link.ts → markdown/link.ts} +1 -2
- package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +48 -34
- package/src/extensions/mention.ts +9 -2
- package/src/hooks/awareness-provider.ts +24 -20
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +2 -2
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +47 -56
- package/src/styles/markdown.ts +9 -10
- package/src/themes/default.ts +0 -2
- package/src/util.ts +26 -3
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/code.d.ts.map +0 -1
- package/dist/types/src/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/link.d.ts.map +0 -1
- package/dist/types/src/extensions/table.d.ts.map +0 -1
- package/dist/types/src/extensions/tasklist.d.ts +0 -7
- package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/index.d.ts +0 -2
- package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge.d.ts +0 -3
- package/dist/types/src/hooks/automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs.d.ts +0 -27
- package/dist/types/src/hooks/yjs.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
- package/dist/types/src/testing/proto/index.d.ts +0 -2
- package/dist/types/src/testing/proto/index.d.ts.map +0 -1
- package/dist/types/src/testing/replicator.d.ts +0 -45
- package/dist/types/src/testing/replicator.d.ts.map +0 -1
- package/src/components/TextEditor/codemirror.stories.ts +0 -115
- package/src/components/TextEditor/yjs.stories.tsx +0 -56
- package/src/extensions/code.ts +0 -104
- package/src/extensions/hr.ts +0 -72
- package/src/extensions/yjs/cursor.ts +0 -22
- package/src/extensions/yjs/index.ts +0 -5
- package/src/extensions/yjs/yjs.test.ts +0 -35
- package/src/extensions/yjs/yjs.ts +0 -16
- package/src/hooks/automerge.ts +0 -52
- package/src/hooks/yjs.ts +0 -156
- package/src/testing/index.ts +0 -6
- package/src/testing/proto/gen/schema.ts +0 -49
- package/src/testing/proto/index.ts +0 -5
- package/src/testing/proto/schema.proto +0 -15
- package/src/testing/replicator.ts +0 -184
- /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
- /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
- /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
- /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
- /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
- /package/src/extensions/{image.ts → markdown/image.ts} +0 -0
- /package/src/extensions/{table.ts → markdown/table.ts} +0 -0
|
@@ -2,55 +2,20 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import get from 'lodash.get';
|
|
6
6
|
import { useEffect, useState } from 'react';
|
|
7
|
-
import type * as YP from 'y-protocols/awareness';
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import { generateName } from '@dxos/display-name';
|
|
9
|
+
import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
11
|
+
import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
|
|
10
12
|
import { type Identity } from '@dxos/react-client/halo';
|
|
11
|
-
import
|
|
13
|
+
import { isNotNullOrUndefined } from '@dxos/util';
|
|
12
14
|
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* State field makes the model available to other extensions.
|
|
20
|
-
*/
|
|
21
|
-
export const modelState = StateField.define<EditorModel | undefined>({
|
|
22
|
-
create: () => undefined,
|
|
23
|
-
update: (model) => model,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export type Range = {
|
|
27
|
-
from: number;
|
|
28
|
-
to: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type CommentRange = {
|
|
32
|
-
id: string;
|
|
33
|
-
cursor: string; // TODO(burdon): Rename range.
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
37
|
-
export type EditorModel = {
|
|
38
|
-
id: string;
|
|
39
|
-
text: () => string;
|
|
40
|
-
extension?: Extension;
|
|
41
|
-
|
|
42
|
-
// TODO(burdon): Remove.
|
|
43
|
-
content: string | YText | YXmlFragment | DocAccessor;
|
|
44
|
-
|
|
45
|
-
// TODO(burdon): Move into extension.
|
|
46
|
-
awareness?: YP.Awareness;
|
|
47
|
-
|
|
48
|
-
// TODO(burdon): Remove.
|
|
49
|
-
peer?: {
|
|
50
|
-
id: string;
|
|
51
|
-
name?: string;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
15
|
+
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
16
|
+
import { type EditorModel, modelState } from './defs';
|
|
17
|
+
import { automerge, awareness, AwarenessProvider } from '../extensions';
|
|
18
|
+
import { cursorColor } from '../styles';
|
|
54
19
|
|
|
55
20
|
// TODO(burdon): Remove space/identity dependency. Define interface for the framework re content and presence.
|
|
56
21
|
export type UseTextModelProps = {
|
|
@@ -59,8 +24,6 @@ export type UseTextModelProps = {
|
|
|
59
24
|
text?: TextObject;
|
|
60
25
|
};
|
|
61
26
|
|
|
62
|
-
// TODO(burdon): Remove YJS/Automerge deps (from UI component -- create abstraction; incl. all ECHO/Space deps).
|
|
63
|
-
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
64
27
|
export const useTextModel = (props: UseTextModelProps): EditorModel | undefined => {
|
|
65
28
|
const { identity, space, text } = props;
|
|
66
29
|
const [model, setModel] = useState<EditorModel | undefined>();
|
|
@@ -68,13 +31,41 @@ export const useTextModel = (props: UseTextModelProps): EditorModel | undefined
|
|
|
68
31
|
return model;
|
|
69
32
|
};
|
|
70
33
|
|
|
71
|
-
const createModel = (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
34
|
+
const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
35
|
+
invariant(isAutomergeObject(text));
|
|
36
|
+
const obj = text as any as AutomergeTextCompat;
|
|
37
|
+
const doc = getRawDoc(obj, [obj.field]);
|
|
38
|
+
|
|
39
|
+
const awarenessProvider =
|
|
40
|
+
space &&
|
|
41
|
+
new SpaceAwarenessProvider({
|
|
42
|
+
space,
|
|
43
|
+
channel: `automerge.awareness.${obj.id}`,
|
|
44
|
+
info: {
|
|
45
|
+
displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : undefined,
|
|
46
|
+
color: cursorColor.color,
|
|
47
|
+
lightColor: cursorColor.light,
|
|
48
|
+
},
|
|
49
|
+
peerId: identity?.identityKey.toHex() ?? 'Anonymous',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const model: EditorModel = {
|
|
53
|
+
id: obj.id,
|
|
54
|
+
content: doc,
|
|
55
|
+
text: () => get(doc.handle.docSync(), doc.path),
|
|
56
|
+
extension: [
|
|
57
|
+
modelState.init(() => model),
|
|
58
|
+
automerge({ handle: doc.handle, path: doc.path }),
|
|
59
|
+
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
60
|
+
awareness(),
|
|
61
|
+
].filter(isNotNullOrUndefined),
|
|
62
|
+
peer: identity
|
|
63
|
+
? {
|
|
64
|
+
id: identity.identityKey.toHex(),
|
|
65
|
+
name: identity.profile?.displayName,
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return model;
|
|
80
71
|
};
|
package/src/styles/markdown.ts
CHANGED
|
@@ -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:
|
|
13
|
-
2:
|
|
14
|
-
3:
|
|
15
|
-
4:
|
|
16
|
-
5:
|
|
17
|
-
6:
|
|
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
|
|
21
|
-
|
|
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';
|
package/src/themes/default.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -2,17 +2,40 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type { Transaction } from '@codemirror/state';
|
|
6
|
+
|
|
5
7
|
import { log } from '@dxos/log';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* CodeMirror callbacks swallow errors so wrap handlers.
|
|
9
11
|
*/
|
|
10
|
-
// TODO(burdon):
|
|
12
|
+
// TODO(burdon): EditorView.exceptionSink should catch errors.
|
|
11
13
|
export const callbackWrapper = <T extends Function>(fn: T): T =>
|
|
12
14
|
((...args: any[]) => {
|
|
13
15
|
try {
|
|
14
16
|
return fn(...args);
|
|
15
|
-
} catch (
|
|
16
|
-
log.catch(
|
|
17
|
+
} catch (err) {
|
|
18
|
+
log.catch(err);
|
|
17
19
|
}
|
|
18
20
|
}) as unknown as T;
|
|
21
|
+
|
|
22
|
+
export const logChanges = (trs: readonly Transaction[]) => {
|
|
23
|
+
const changes = trs
|
|
24
|
+
.flatMap((tr) => {
|
|
25
|
+
if (tr.changes.empty) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const changes: any[] = [];
|
|
30
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) =>
|
|
31
|
+
changes.push(JSON.stringify({ fromA, toA, fromB, toB, inserted: inserted.toString() })),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return changes;
|
|
35
|
+
})
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
|
|
38
|
+
if (changes.length) {
|
|
39
|
+
console.log('changes', changes);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -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,12 +0,0 @@
|
|
|
1
|
-
import '@dxosTheme';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
title: string;
|
|
5
|
-
component: React.ForwardRefExoticComponent<import("./TextEditor").TextEditorProps & React.RefAttributes<import("@codemirror/view").EditorView>>;
|
|
6
|
-
decorators: import("@storybook/react").Decorator[];
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
export declare const Default: {
|
|
10
|
-
render: () => JSX.Element;
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=yjs.stories.d.ts.map
|
|
@@ -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":"AAsDA,eAAO,MAAM,EAAE,+CAiBd,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,7 +0,0 @@
|
|
|
1
|
-
import { ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
|
|
2
|
-
export type TasklistOptions = {};
|
|
3
|
-
export declare const tasklist: (options?: TasklistOptions) => ViewPlugin<{
|
|
4
|
-
decorations: DecorationSet;
|
|
5
|
-
update(update: ViewUpdate): void;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=tasklist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasklist.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasklist.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsC,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyCvH,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC;AAEjC,eAAO,MAAM,QAAQ,aAAa,eAAe;;mBAS5B,UAAU;EAe9B,CAAC"}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/index.ts"],"names":[],"mappings":"AAIA,cAAc,OAAO,CAAC"}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yjs.test.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/yjs/yjs.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"automerge.d.ts","sourceRoot":"","sources":["../../../../src/hooks/automerge.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAc,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAItF,eAAO,MAAM,oBAAoB,8BAA+B,iBAAiB,KAAG,WAqCnF,CAAC"}
|
|
@@ -1,27 +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, type UseTextModelProps } from './useTextModel';
|
|
6
|
-
export declare const createYjsModel: ({ identity, space, text }: UseTextModelProps) => EditorModel;
|
|
7
|
-
/**
|
|
8
|
-
* Yjs awareness provider on top of a DXOS space.
|
|
9
|
-
*/
|
|
10
|
-
export declare class YAwarenessProvider extends Observable<any> {
|
|
11
|
-
private readonly _space;
|
|
12
|
-
private readonly _awareness;
|
|
13
|
-
private readonly _clientId;
|
|
14
|
-
private readonly _channel;
|
|
15
|
-
constructor({ space, doc, channel, awareness, }: {
|
|
16
|
-
space: Space;
|
|
17
|
-
doc: Doc;
|
|
18
|
-
channel: string;
|
|
19
|
-
awareness?: YP.Awareness;
|
|
20
|
-
});
|
|
21
|
-
get awareness(): YP.Awareness;
|
|
22
|
-
private _handleAwarenessUpdate;
|
|
23
|
-
private _handleSpaceMessage;
|
|
24
|
-
private _readMessage;
|
|
25
|
-
private _handleBeforeUnload;
|
|
26
|
-
}
|
|
27
|
-
//# 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,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGtF,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 +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 +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"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
|
6
|
-
import { EditorState } from '@codemirror/state';
|
|
7
|
-
import { EditorView } from '@codemirror/view';
|
|
8
|
-
import { type StoryObj } from '@storybook/html';
|
|
9
|
-
import { basicSetup } from 'codemirror';
|
|
10
|
-
import { yCollab } from 'y-codemirror.next';
|
|
11
|
-
|
|
12
|
-
import { EventSubscriptions } from '@dxos/async';
|
|
13
|
-
import { generateName } from '@dxos/display-name';
|
|
14
|
-
import { Client, type PublicKey } from '@dxos/react-client';
|
|
15
|
-
import { type Space, TextObject } from '@dxos/react-client/echo';
|
|
16
|
-
import { type Identity } from '@dxos/react-client/halo';
|
|
17
|
-
import { joinCommonSpace, TestBuilder, textGenerator } from '@dxos/react-client/testing';
|
|
18
|
-
import { YText } from '@dxos/text-model';
|
|
19
|
-
|
|
20
|
-
import { YAwarenessProvider } from '../../hooks';
|
|
21
|
-
import { cursorColor } from '../../styles';
|
|
22
|
-
import { EditorDocument, types as schema } from '../../testing';
|
|
23
|
-
|
|
24
|
-
export default {
|
|
25
|
-
title: 'CodeMirror',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const testBuilder = new TestBuilder();
|
|
29
|
-
const views: Record<number, EditorView> = {};
|
|
30
|
-
const subscriptions = new EventSubscriptions();
|
|
31
|
-
|
|
32
|
-
const updateEditor = async (id: number, editor: HTMLDivElement, identity: Identity, space: Space, text: TextObject) => {
|
|
33
|
-
const doc = text.doc;
|
|
34
|
-
const ytext = text.content;
|
|
35
|
-
if (!(ytext instanceof YText) || !doc) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const { awareness } = new YAwarenessProvider({ space, doc, channel: `yjs.awareness.${text.id}` });
|
|
40
|
-
awareness.setLocalStateField('user', {
|
|
41
|
-
name: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
42
|
-
// TODO(wittjosiah): Pick colours from theme based on identity key.
|
|
43
|
-
color: cursorColor.color,
|
|
44
|
-
colorLight: cursorColor.light,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const state = EditorState.create({
|
|
48
|
-
doc: ytext.toString(),
|
|
49
|
-
extensions: [basicSetup, markdown({ base: markdownLanguage }), yCollab(ytext, awareness)],
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const view = views[id];
|
|
53
|
-
if (view) {
|
|
54
|
-
view.setState(state);
|
|
55
|
-
} else {
|
|
56
|
-
views[id] = new EditorView({ state, parent: editor });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (id === 0) {
|
|
60
|
-
subscriptions.clear();
|
|
61
|
-
subscriptions.add(textGenerator({ text: ytext }));
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const setupEditor = async (id: number, client: Client, spaceKey: PublicKey, editor: HTMLDivElement) => {
|
|
66
|
-
const space = await client.spaces.get(spaceKey)!;
|
|
67
|
-
const query = space.db.query(EditorDocument.filter());
|
|
68
|
-
query.subscribe(({ objects }) => {
|
|
69
|
-
const text = objects[0]?.content;
|
|
70
|
-
void (text && updateEditor(id, editor, client.halo.identity.get()!, space, text));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const text = query.objects[0]?.content;
|
|
74
|
-
void (text && updateEditor(id, editor, client.halo.identity.get()!, space, text));
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const setupSpace = async (count: number) => {
|
|
78
|
-
const clients = [...Array(count)].map(() => new Client({ services: testBuilder.createLocal() }));
|
|
79
|
-
await Promise.all(clients.map((client) => client.initialize()));
|
|
80
|
-
await Promise.all(clients.map((client) => client.halo.createIdentity()));
|
|
81
|
-
clients.map((client) => client.spaces.addSchema(schema));
|
|
82
|
-
|
|
83
|
-
const space = await clients[0].spaces.create();
|
|
84
|
-
const text = new TextObject('Hello, Storybook!');
|
|
85
|
-
const document = new EditorDocument({ content: text });
|
|
86
|
-
await space.db.add(document);
|
|
87
|
-
|
|
88
|
-
await joinCommonSpace(clients, space.key);
|
|
89
|
-
|
|
90
|
-
return { clients, spaceKey: space.key };
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const count = 2;
|
|
94
|
-
|
|
95
|
-
export const Default: StoryObj<{ id: number; client: Client; spaceKey: PublicKey }> = {
|
|
96
|
-
render: ({ id, client, spaceKey }) => {
|
|
97
|
-
const editor = document.createElement('div');
|
|
98
|
-
editor.setAttribute('style', 'min-width: 0; flex: 1; padding: 1rem;');
|
|
99
|
-
void setupEditor(id, client, spaceKey, editor);
|
|
100
|
-
return editor;
|
|
101
|
-
},
|
|
102
|
-
decorators: [
|
|
103
|
-
(story) => {
|
|
104
|
-
const container = document.createElement('div');
|
|
105
|
-
container.setAttribute('style', 'display: flex; justify-content: space-evenly');
|
|
106
|
-
void setupSpace(count).then(({ clients, spaceKey }) => {
|
|
107
|
-
clients.forEach((client, id) => {
|
|
108
|
-
// TODO(wittjosiah): According to the docs these types should be compatible.
|
|
109
|
-
container.appendChild(story({ args: { id, client, spaceKey } }) as HTMLElement);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
return container;
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxosTheme';
|
|
6
|
-
|
|
7
|
-
import React, { useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { PublicKey } from '@dxos/react-client';
|
|
10
|
-
import { TextKind } from '@dxos/react-client/echo';
|
|
11
|
-
import { ClientRepeater, textGenerator, useDataGenerator } from '@dxos/react-client/testing';
|
|
12
|
-
import { useId, Input } from '@dxos/react-ui';
|
|
13
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
14
|
-
|
|
15
|
-
import { MarkdownEditor } from './TextEditor';
|
|
16
|
-
import { Replicator, useYjsModel } from '../../testing';
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
title: 'react-ui-editor/YJS',
|
|
20
|
-
component: MarkdownEditor,
|
|
21
|
-
decorators: [withTheme],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const replicator = new Replicator(TextKind.PLAIN);
|
|
25
|
-
|
|
26
|
-
const Story = () => {
|
|
27
|
-
const [generate, setGenerate] = useState(false);
|
|
28
|
-
const generateId = useId('generate');
|
|
29
|
-
|
|
30
|
-
const [id] = useState(PublicKey.random().toHex());
|
|
31
|
-
const model = useYjsModel({ id, replicator });
|
|
32
|
-
|
|
33
|
-
useDataGenerator({
|
|
34
|
-
generator: generate ? textGenerator : undefined,
|
|
35
|
-
options: { text: typeof model?.content !== 'string' ? (model?.content as any) : undefined },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<main className='flex flex-col flex-1 p-4 gap-4'>
|
|
40
|
-
<div id={generateId} className='flex gap-2'>
|
|
41
|
-
<Input.Root>
|
|
42
|
-
<Input.Checkbox checked={generate} onCheckedChange={(checked) => setGenerate(!!checked)} />
|
|
43
|
-
<Input.Label>Start</Input.Label>
|
|
44
|
-
</Input.Root>
|
|
45
|
-
</div>
|
|
46
|
-
<div className='border'>
|
|
47
|
-
<MarkdownEditor model={model} />
|
|
48
|
-
</div>
|
|
49
|
-
</main>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const Default = {
|
|
54
|
-
// TODO(wittjosiah): Decorator for doing this without clients being initialized?
|
|
55
|
-
render: () => <ClientRepeater count={2} Component={Story} />,
|
|
56
|
-
};
|