@dxos/react-ui-editor 0.4.7-main.e015b9e → 0.4.7-main.e5c4f14
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 +392 -164
- 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 +6 -0
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts +10 -0
- package/dist/types/src/extensions/command/command.d.ts.map +1 -0
- package/dist/types/src/extensions/command/hint.d.ts +7 -0
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -0
- package/dist/types/src/extensions/command/index.d.ts +2 -0
- package/dist/types/src/extensions/command/index.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts +18 -0
- package/dist/types/src/extensions/command/state.d.ts.map +1 -0
- package/dist/types/src/extensions/dnd.d.ts +3 -0
- package/dist/types/src/extensions/dnd.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts +1 -0
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/util/dom.d.ts +15 -0
- package/dist/types/src/extensions/util/dom.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/styles/index.d.ts +0 -1
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +72 -4
- package/src/components/TextEditor/TextEditor.tsx +2 -0
- package/src/extensions/awareness.ts +3 -3
- package/src/extensions/command/command.ts +38 -0
- package/src/extensions/command/hint.ts +75 -0
- package/src/extensions/command/index.ts +5 -0
- package/src/extensions/command/state.ts +106 -0
- package/src/extensions/dnd.ts +15 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/markdown/bundle.ts +0 -1
- package/src/extensions/markdown/decorate.ts +68 -31
- package/src/extensions/util/dom.ts +36 -0
- package/src/hooks/useTextModel.ts +12 -5
- package/src/styles/index.ts +0 -1
- package/dist/types/src/styles/cursors.d.ts +0 -5
- package/dist/types/src/styles/cursors.d.ts.map +0 -1
- package/src/styles/cursors.ts +0 -21
|
@@ -11,12 +11,13 @@ import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
12
12
|
import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
|
|
13
13
|
import { type Identity } from '@dxos/react-client/halo';
|
|
14
|
+
import { hueTokens } from '@dxos/react-ui-theme';
|
|
15
|
+
import { hexToHue } from '@dxos/util';
|
|
14
16
|
|
|
15
17
|
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
16
18
|
import { type EditorModel, modelState } from './defs';
|
|
17
19
|
import { automerge, awareness } from '../extensions';
|
|
18
20
|
import { type DocAccessor } from '../extensions/automerge/defs';
|
|
19
|
-
import { cursorColor } from '../styles';
|
|
20
21
|
|
|
21
22
|
export type useTextExtensionsProps = {
|
|
22
23
|
id: string;
|
|
@@ -29,6 +30,9 @@ export type useTextExtensionsProps = {
|
|
|
29
30
|
export const useTextExtensions = ({ id, text, space, identity }: useTextExtensionsProps): Extension[] => {
|
|
30
31
|
const extensions: Extension[] = [automerge(text)];
|
|
31
32
|
|
|
33
|
+
const peerId = identity?.identityKey.toHex();
|
|
34
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? '0')];
|
|
35
|
+
|
|
32
36
|
if (space && identity) {
|
|
33
37
|
const awarenessProvider = new SpaceAwarenessProvider({
|
|
34
38
|
space,
|
|
@@ -36,8 +40,8 @@ export const useTextExtensions = ({ id, text, space, identity }: useTextExtensio
|
|
|
36
40
|
peerId: identity.identityKey.toHex(),
|
|
37
41
|
info: {
|
|
38
42
|
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
39
|
-
color:
|
|
40
|
-
lightColor:
|
|
43
|
+
color: cursorDarkValue,
|
|
44
|
+
lightColor: cursorLightValue,
|
|
41
45
|
},
|
|
42
46
|
});
|
|
43
47
|
|
|
@@ -84,6 +88,9 @@ const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
|
84
88
|
const obj = text as any as AutomergeTextCompat;
|
|
85
89
|
const doc = getRawDoc(obj, [obj.field]);
|
|
86
90
|
|
|
91
|
+
const peerId = identity?.identityKey.toHex();
|
|
92
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? '0')];
|
|
93
|
+
|
|
87
94
|
const awarenessProvider =
|
|
88
95
|
space &&
|
|
89
96
|
new SpaceAwarenessProvider({
|
|
@@ -91,8 +98,8 @@ const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
|
91
98
|
channel: `automerge.awareness.${obj.id}`,
|
|
92
99
|
info: {
|
|
93
100
|
displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : undefined,
|
|
94
|
-
color:
|
|
95
|
-
lightColor:
|
|
101
|
+
color: cursorLightValue,
|
|
102
|
+
lightColor: cursorDarkValue,
|
|
96
103
|
},
|
|
97
104
|
peerId: identity?.identityKey.toHex() ?? 'Anonymous',
|
|
98
105
|
});
|
package/src/styles/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursors.d.ts","sourceRoot":"","sources":["../../../../src/styles/cursors.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW;;;CAAsD,CAAC"}
|
package/src/styles/cursors.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Copied from https://github.com/yjs/y-codemirror.next#example.
|
|
6
|
-
|
|
7
|
-
import * as random from 'lib0/random';
|
|
8
|
-
|
|
9
|
-
const cursorColors = [
|
|
10
|
-
{ color: '#30bced', light: '#30bced33' },
|
|
11
|
-
{ color: '#6eeb83', light: '#6eeb8333' },
|
|
12
|
-
{ color: '#ffbc42', light: '#ffbc4233' },
|
|
13
|
-
{ color: '#ecd444', light: '#ecd44433' },
|
|
14
|
-
{ color: '#ee6352', light: '#ee635233' },
|
|
15
|
-
{ color: '#9ac2c9', light: '#9ac2c933' },
|
|
16
|
-
{ color: '#8acb88', light: '#8acb8833' },
|
|
17
|
-
{ color: '#1be7ff', light: '#1be7ff33' },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
// Select a random color for this user.
|
|
21
|
-
export const cursorColor = cursorColors[random.uint32() % cursorColors.length];
|