@dxos/react-ui-editor 0.3.11-main.d56f337 → 0.3.11-main.d8b8a39
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 +595 -665
- 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 +13 -14
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +14 -6
- 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 +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 +7 -9
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/index.d.ts +0 -1
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/semaphore.d.ts +7 -12
- 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/code.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +27 -18
- 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/hr.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +1 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -5
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/mention.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner.d.ts +4 -0
- package/dist/types/src/extensions/outliner.d.ts.map +1 -0
- package/dist/types/src/extensions/tasklist.d.ts +1 -5
- package/dist/types/src/extensions/tasklist.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/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +31 -34
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +64 -69
- package/src/components/TextEditor/TextEditor.tsx +95 -70
- package/src/components/TextEditor/comments.stories.tsx +104 -76
- package/src/extensions/autocomplete.ts +6 -3
- package/src/extensions/automerge/automerge.ts +39 -45
- package/src/extensions/automerge/defs.ts +10 -31
- package/src/extensions/automerge/index.ts +0 -1
- package/src/extensions/automerge/semaphore.ts +23 -20
- package/src/extensions/automerge/update-automerge.ts +2 -2
- package/src/extensions/awareness.ts +15 -14
- package/src/extensions/basic.ts +22 -17
- package/src/extensions/code.ts +15 -17
- package/src/extensions/comments.ts +199 -161
- package/src/extensions/cursor.ts +7 -3
- package/src/extensions/hr.ts +49 -50
- package/src/extensions/index.ts +1 -1
- package/src/extensions/link.ts +3 -3
- package/src/extensions/markdown/bundle.ts +18 -24
- package/src/extensions/mention.ts +9 -2
- package/src/extensions/outliner.ts +12 -0
- package/src/extensions/tasklist.ts +49 -33
- package/src/hooks/awareness-provider.ts +24 -20
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +47 -56
- 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/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/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/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":"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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Y from 'yjs';
|
|
6
|
-
|
|
7
|
-
import { arrayToString, stringToArray } from '@dxos/util';
|
|
8
|
-
|
|
9
|
-
import { type CursorConverter } from '../cursor';
|
|
10
|
-
|
|
11
|
-
export const cursorConverter = (text: Y.Text): CursorConverter => ({
|
|
12
|
-
toCursor: (index, assoc) => {
|
|
13
|
-
return arrayToString(Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text, index, assoc)));
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
fromCursor: (cursor) => {
|
|
17
|
-
return (
|
|
18
|
-
Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(cursor)), text.doc!)?.index ??
|
|
19
|
-
0
|
|
20
|
-
);
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import * as Y from 'yjs';
|
|
7
|
-
|
|
8
|
-
import { TextObject } from '@dxos/echo-schema';
|
|
9
|
-
import { describe, test } from '@dxos/test';
|
|
10
|
-
import { type YText } from '@dxos/text-model';
|
|
11
|
-
|
|
12
|
-
describe('YJS', () => {
|
|
13
|
-
// https://docs.yjs.dev/api/shared-types/y.text
|
|
14
|
-
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
15
|
-
test.skip('absolute position', () => {
|
|
16
|
-
const obj = new TextObject('hello world');
|
|
17
|
-
const index = obj.text.indexOf('world');
|
|
18
|
-
const relPos = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(obj.content as YText, index));
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
const cursor = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(relPos), obj.doc!);
|
|
22
|
-
expect(cursor!.index).to.equal(index);
|
|
23
|
-
expect(obj.text.substring(cursor!.index)).to.equal('world');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
(obj.content as YText).insert(index, 'cruel ');
|
|
27
|
-
expect(obj.text).to.equal('hello cruel world');
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
const cursor = Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(relPos), obj.doc!);
|
|
31
|
-
expect(cursor!.index).not.to.equal(index);
|
|
32
|
-
expect(obj.text.substring(cursor!.index)).to.equal('world');
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { yCollab } from 'y-codemirror.next';
|
|
6
|
-
import type * as YP from 'y-protocols/awareness';
|
|
7
|
-
|
|
8
|
-
import type { YText } from '@dxos/text-model';
|
|
9
|
-
|
|
10
|
-
import { cursorConverter } from './cursor';
|
|
11
|
-
import { Cursor } from '../cursor';
|
|
12
|
-
|
|
13
|
-
export const yjs = (content: YText, awareness?: YP.Awareness) => [
|
|
14
|
-
Cursor.converter.of(cursorConverter(content)),
|
|
15
|
-
yCollab(content, awareness),
|
|
16
|
-
];
|
package/src/hooks/automerge.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import get from 'lodash.get';
|
|
6
|
-
|
|
7
|
-
import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
8
|
-
import { isNotNullOrUndefined } from '@dxos/util';
|
|
9
|
-
|
|
10
|
-
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
11
|
-
import { type EditorModel, modelState, type UseTextModelProps } from './useTextModel';
|
|
12
|
-
import { automerge, awareness, AwarenessProvider } from '../extensions';
|
|
13
|
-
import { cursorColor } from '../styles';
|
|
14
|
-
|
|
15
|
-
export const createAutomergeModel = ({ space, identity, text }: UseTextModelProps): EditorModel => {
|
|
16
|
-
const obj = text as any as AutomergeTextCompat;
|
|
17
|
-
const doc = getRawDoc(obj, [obj.field]);
|
|
18
|
-
|
|
19
|
-
const awarenessProvider =
|
|
20
|
-
space &&
|
|
21
|
-
new SpaceAwarenessProvider({
|
|
22
|
-
space,
|
|
23
|
-
channel: `automerge.awareness.${obj.id}`,
|
|
24
|
-
info: {
|
|
25
|
-
displayName: identity?.profile?.displayName ?? '',
|
|
26
|
-
color: cursorColor.color,
|
|
27
|
-
lightColor: cursorColor.light,
|
|
28
|
-
},
|
|
29
|
-
peerId: identity?.identityKey.toHex() ?? 'Anonymous',
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const model: EditorModel = {
|
|
33
|
-
id: obj.id,
|
|
34
|
-
content: doc,
|
|
35
|
-
text: () => get(doc.handle.docSync(), doc.path),
|
|
36
|
-
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
37
|
-
extension: [
|
|
38
|
-
modelState.init(() => model),
|
|
39
|
-
automerge({ handle: doc.handle, path: doc.path }),
|
|
40
|
-
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
41
|
-
awareness(),
|
|
42
|
-
].filter(isNotNullOrUndefined),
|
|
43
|
-
peer: identity
|
|
44
|
-
? {
|
|
45
|
-
id: identity.identityKey.toHex(),
|
|
46
|
-
name: identity.profile?.displayName,
|
|
47
|
-
}
|
|
48
|
-
: undefined,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return model;
|
|
52
|
-
};
|