@dxos/react-ui-editor 0.3.6 → 0.3.7-main.0bad7ea
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 +23 -17
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts +15 -0
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -0
- package/dist/types/src/components/{Composer/Composer.stories.d.ts → Editor/Editor.stories.d.ts} +3 -3
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -0
- package/dist/types/src/components/Editor/index.d.ts +2 -0
- package/dist/types/src/components/Editor/index.d.ts.map +1 -0
- package/dist/types/src/components/Markdown/Markdown.d.ts +6 -6
- package/dist/types/src/components/Markdown/Markdown.d.ts.map +1 -1
- package/dist/types/src/components/Markdown/Markdown.stories.d.ts +1 -1
- package/dist/types/src/components/Markdown/markdownTheme.d.ts +10 -4
- package/dist/types/src/components/Markdown/markdownTheme.d.ts.map +1 -1
- package/dist/types/src/components/RichText/RichText.d.ts +7 -7
- package/dist/types/src/components/RichText/RichText.d.ts.map +1 -1
- package/dist/types/src/components/RichText/RichText.stories.d.ts +5 -5
- package/dist/types/src/components/RichText/RichText.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/model.d.ts +3 -3
- package/dist/types/src/model.d.ts.map +1 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +4 -4
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +1 -1
- package/dist/types/src/testing/replicator.d.ts +4 -4
- package/dist/types/src/testing/replicator.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/components/{Composer/Composer.stories.tsx → Editor/Editor.stories.tsx} +8 -8
- package/src/components/Editor/Editor.tsx +33 -0
- package/src/components/{Composer → Editor}/index.ts +1 -1
- package/src/components/Markdown/Markdown.stories.tsx +3 -3
- package/src/components/Markdown/Markdown.tsx +6 -6
- package/src/components/Markdown/markdownTheme.ts +12 -6
- package/src/components/RichText/RichText.stories.tsx +4 -4
- package/src/components/RichText/RichText.tsx +6 -6
- package/src/components/index.ts +1 -1
- package/src/model.ts +4 -4
- package/src/testing/proto/gen/schema.ts +10 -10
- package/src/testing/proto/schema.proto +2 -2
- package/src/testing/replicator.ts +6 -6
- package/dist/types/src/components/Composer/Composer.d.ts +0 -15
- package/dist/types/src/components/Composer/Composer.d.ts.map +0 -1
- package/dist/types/src/components/Composer/Composer.stories.d.ts.map +0 -1
- package/dist/types/src/components/Composer/index.d.ts +0 -2
- package/dist/types/src/components/Composer/index.d.ts.map +0 -1
- package/src/components/Composer/Composer.tsx +0 -33
|
@@ -15,7 +15,7 @@ import { Event } from '@dxos/async';
|
|
|
15
15
|
import { log } from '@dxos/log';
|
|
16
16
|
import { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
|
|
17
17
|
|
|
18
|
-
import { type
|
|
18
|
+
import { type EditorModel } from '../model';
|
|
19
19
|
import { cursorColor } from '../yjs';
|
|
20
20
|
|
|
21
21
|
type Awareness = awarenessProtocol.Awareness;
|
|
@@ -148,15 +148,15 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
148
148
|
*/
|
|
149
149
|
export class Replicator {
|
|
150
150
|
private readonly _update = new Event<Uint8Array>();
|
|
151
|
-
private _peers:
|
|
151
|
+
private _peers: EditorModel[] = [];
|
|
152
152
|
|
|
153
153
|
constructor(private readonly _kind: TextKind) {}
|
|
154
154
|
|
|
155
|
-
setPeers(peers:
|
|
155
|
+
setPeers(peers: EditorModel[]) {
|
|
156
156
|
this._peers = peers;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
createPeer = (id: string, doc: Doc = new Doc()):
|
|
159
|
+
createPeer = (id: string, doc: Doc = new Doc()): EditorModel => {
|
|
160
160
|
const provider = new AwarenessProvider({ update: this._update, doc });
|
|
161
161
|
provider.awareness.setLocalStateField('user', {
|
|
162
162
|
name: 'Anonymous ' + Math.floor(Math.random() * 100),
|
|
@@ -165,7 +165,7 @@ export class Replicator {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
// TODO(burdon): Create concrete class that implements SyncModel?
|
|
168
|
-
const model:
|
|
168
|
+
const model: EditorModel = {
|
|
169
169
|
id: doc.guid,
|
|
170
170
|
content: this._kind === TextKind.PLAIN ? doc.getText('content') : doc.getXmlFragment('content'),
|
|
171
171
|
provider,
|
|
@@ -184,7 +184,7 @@ export type UseYjsModelOptions = {
|
|
|
184
184
|
doc?: Doc;
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
-
export const useYjsModel = ({ replicator, id, doc }: UseYjsModelOptions):
|
|
187
|
+
export const useYjsModel = ({ replicator, id, doc }: UseYjsModelOptions): EditorModel => {
|
|
188
188
|
const peer = useMemo(() => replicator.createPeer(id, doc), [doc]);
|
|
189
189
|
|
|
190
190
|
return peer;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type ComposerSlots, type UseTextModelOptions } from '../../model';
|
|
3
|
-
import { type MarkdownComposerRef } from '../Markdown';
|
|
4
|
-
export type ComposerProps = UseTextModelOptions & {
|
|
5
|
-
slots?: ComposerSlots;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Memoized composer which depends DXOS platform.
|
|
9
|
-
*
|
|
10
|
-
* Determines which composer to render based on the kind of text.
|
|
11
|
-
*/
|
|
12
|
-
export declare const Composer: React.MemoExoticComponent<React.ForwardRefExoticComponent<UseTextModelOptions & {
|
|
13
|
-
slots?: ComposerSlots | undefined;
|
|
14
|
-
} & React.RefAttributes<MarkdownComposerRef | import("@tiptap/react").Editor>>>;
|
|
15
|
-
//# sourceMappingURL=Composer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Composer.d.ts","sourceRoot":"","sources":["../../../../../src/components/Composer/Composer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAI1D,OAAO,EAAE,KAAK,aAAa,EAAgB,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGzE,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG;IAChD,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AAGH,eAAO,MAAM,QAAQ;;+EASpB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Composer.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Composer/Composer.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAAmB,MAAM,OAAO,CAAC;;;;;;AAWxC,wBAEE;AAoCF,eAAO,MAAM,QAAQ;mBACJ;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;;CAE9B,CAAC;AAWF,eAAO,MAAM,IAAI;mBACA;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;;;;;;;;;CAS9B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Composer/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { forwardRef, memo, type Ref } from 'react';
|
|
6
|
-
|
|
7
|
-
import { YXmlFragment } from '@dxos/text-model';
|
|
8
|
-
|
|
9
|
-
import { type ComposerSlots, useTextModel, type UseTextModelOptions } from '../../model';
|
|
10
|
-
import { MarkdownComposer, type MarkdownComposerRef } from '../Markdown';
|
|
11
|
-
import { RichTextComposer, type TipTapEditor } from '../RichText';
|
|
12
|
-
|
|
13
|
-
export type ComposerProps = UseTextModelOptions & {
|
|
14
|
-
slots?: ComposerSlots;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Memoized composer which depends DXOS platform.
|
|
19
|
-
*
|
|
20
|
-
* Determines which composer to render based on the kind of text.
|
|
21
|
-
*/
|
|
22
|
-
// NOTE: Without `memo`, if parent component uses `observer` the composer re-renders excessively.
|
|
23
|
-
// TODO(wittjosiah): Factor out?
|
|
24
|
-
export const Composer = memo(
|
|
25
|
-
forwardRef<TipTapEditor | MarkdownComposerRef, ComposerProps>(({ slots, ...options }, forwardedRef) => {
|
|
26
|
-
const model = useTextModel(options);
|
|
27
|
-
if (model?.content instanceof YXmlFragment) {
|
|
28
|
-
return <RichTextComposer ref={forwardedRef as Ref<TipTapEditor>} model={model} slots={slots} />;
|
|
29
|
-
} else {
|
|
30
|
-
return <MarkdownComposer ref={forwardedRef as Ref<MarkdownComposerRef>} model={model} slots={slots} />;
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
);
|