@dxos/react-ui-editor 0.4.6-main.9c97a50 → 0.4.6-main.e47f68d
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 +77 -53
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts +3 -5
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts +2 -7
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts +2 -3
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +9 -2
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +1 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts +1 -0
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +2 -2
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +12 -4
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/automerge.stories.tsx +15 -16
- package/src/extensions/automerge/automerge.ts +10 -15
- package/src/extensions/automerge/cursor.ts +2 -3
- package/src/extensions/automerge/defs.ts +15 -2
- package/src/hooks/defs.ts +2 -0
- package/src/hooks/useEditorView.ts +2 -0
- package/src/hooks/useTextEditor.ts +6 -10
- package/src/hooks/useTextModel.ts +34 -5
- package/src/themes/default.ts +7 -0
|
@@ -189,7 +189,7 @@ import get from "lodash.get";
|
|
|
189
189
|
import { next as A } from "@dxos/automerge/automerge";
|
|
190
190
|
import { log } from "@dxos/log";
|
|
191
191
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts";
|
|
192
|
-
var cursorConverter = (handle, path) => ({
|
|
192
|
+
var cursorConverter = ({ handle, path }) => ({
|
|
193
193
|
// TODO(burdon): Handle assoc to associate with a previous character.
|
|
194
194
|
toCursor: (pos) => {
|
|
195
195
|
const doc = handle.docSync();
|
|
@@ -205,7 +205,7 @@ var cursorConverter = (handle, path) => ({
|
|
|
205
205
|
} catch (err) {
|
|
206
206
|
log.catch(err, void 0, {
|
|
207
207
|
F: __dxlog_file,
|
|
208
|
-
L:
|
|
208
|
+
L: 30,
|
|
209
209
|
S: void 0,
|
|
210
210
|
C: (f, a) => f(...a)
|
|
211
211
|
});
|
|
@@ -233,7 +233,7 @@ var cursorConverter = (handle, path) => ({
|
|
|
233
233
|
} catch (err) {
|
|
234
234
|
log.catch(err, void 0, {
|
|
235
235
|
F: __dxlog_file,
|
|
236
|
-
L:
|
|
236
|
+
L: 58,
|
|
237
237
|
S: void 0,
|
|
238
238
|
C: (f, a) => f(...a)
|
|
239
239
|
});
|
|
@@ -244,6 +244,7 @@ var cursorConverter = (handle, path) => ({
|
|
|
244
244
|
|
|
245
245
|
// packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
|
|
246
246
|
import { Annotation, StateEffect } from "@codemirror/state";
|
|
247
|
+
import get2 from "lodash.get";
|
|
247
248
|
var getPath = (state, field) => state.field(field).path;
|
|
248
249
|
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
|
249
250
|
var updateHeadsEffect = StateEffect.define({});
|
|
@@ -441,16 +442,16 @@ var Syncer = class {
|
|
|
441
442
|
};
|
|
442
443
|
|
|
443
444
|
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
444
|
-
var automerge = (
|
|
445
|
+
var automerge = (accessor) => {
|
|
445
446
|
const syncState = StateField2.define({
|
|
446
447
|
create: () => ({
|
|
447
|
-
path: path.slice(),
|
|
448
|
-
lastHeads: A4.getHeads(handle.docSync()),
|
|
448
|
+
path: accessor.path.slice(),
|
|
449
|
+
lastHeads: A4.getHeads(accessor.handle.docSync()),
|
|
449
450
|
unreconciledTransactions: []
|
|
450
451
|
}),
|
|
451
452
|
update: (value, tr) => {
|
|
452
453
|
const result = {
|
|
453
|
-
path: path.slice(),
|
|
454
|
+
path: accessor.path.slice(),
|
|
454
455
|
lastHeads: value.lastHeads,
|
|
455
456
|
unreconciledTransactions: value.unreconciledTransactions.slice()
|
|
456
457
|
};
|
|
@@ -471,18 +472,18 @@ var automerge = ({ handle, path }) => {
|
|
|
471
472
|
return result;
|
|
472
473
|
}
|
|
473
474
|
});
|
|
474
|
-
const syncer = new Syncer(handle, syncState);
|
|
475
|
+
const syncer = new Syncer(accessor.handle, syncState);
|
|
475
476
|
return [
|
|
476
|
-
Cursor.converter.of(cursorConverter(
|
|
477
|
+
Cursor.converter.of(cursorConverter(accessor)),
|
|
477
478
|
syncState,
|
|
478
479
|
// Reconcile external updates.
|
|
479
480
|
ViewPlugin.fromClass(class {
|
|
480
481
|
constructor(_view) {
|
|
481
482
|
this._view = _view;
|
|
482
|
-
handle.addListener("change", this._handleChange.bind(this));
|
|
483
|
+
accessor.handle.addListener("change", this._handleChange.bind(this));
|
|
483
484
|
}
|
|
484
485
|
destroy() {
|
|
485
|
-
handle.removeListener("change", this._handleChange.bind(this));
|
|
486
|
+
accessor.handle.removeListener("change", this._handleChange.bind(this));
|
|
486
487
|
}
|
|
487
488
|
_handleChange() {
|
|
488
489
|
syncer.reconcile(this._view, false);
|
|
@@ -1133,10 +1134,10 @@ var inlineUrl = mx(code, "px-1");
|
|
|
1133
1134
|
var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
|
|
1134
1135
|
|
|
1135
1136
|
// packages/ui/react-ui-editor/src/styles/tokens.ts
|
|
1136
|
-
import
|
|
1137
|
+
import get3 from "lodash.get";
|
|
1137
1138
|
import { tailwindConfig } from "@dxos/react-ui-theme";
|
|
1138
1139
|
var tokens = tailwindConfig({}).theme;
|
|
1139
|
-
var getToken = (path, defaultValue = void 0) =>
|
|
1140
|
+
var getToken = (path, defaultValue = void 0) => get3(tokens, path, defaultValue);
|
|
1140
1141
|
|
|
1141
1142
|
// packages/ui/react-ui-editor/src/styles/layout.ts
|
|
1142
1143
|
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
|
@@ -3572,7 +3573,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
3572
3573
|
};
|
|
3573
3574
|
|
|
3574
3575
|
// packages/ui/react-ui-editor/src/themes/default.ts
|
|
3575
|
-
import
|
|
3576
|
+
import get4 from "lodash.get";
|
|
3576
3577
|
var defaultTheme = {
|
|
3577
3578
|
//
|
|
3578
3579
|
// Main layout:
|
|
@@ -3606,7 +3607,7 @@ var defaultTheme = {
|
|
|
3606
3607
|
// TODO(burdon): Reconcile with docs: https://codemirror.net/docs/guide
|
|
3607
3608
|
// Inside of that is the scroller element. If the editor has its own scrollbar, this one should be styled with overflow: auto. But it doesn't have to—the editor also supports growing to accomodate its content, or growing up to a certain max-height and then scrolling.
|
|
3608
3609
|
overflowY: "auto",
|
|
3609
|
-
fontFamily:
|
|
3610
|
+
fontFamily: get4(tokens, "fontFamily.mono", []).join(","),
|
|
3610
3611
|
lineHeight: 1.5
|
|
3611
3612
|
},
|
|
3612
3613
|
".cm-content": {
|
|
@@ -3616,11 +3617,11 @@ var defaultTheme = {
|
|
|
3616
3617
|
fontSize: "16px"
|
|
3617
3618
|
},
|
|
3618
3619
|
"&light .cm-content": {
|
|
3619
|
-
color:
|
|
3620
|
+
color: get4(tokens, "extend.semanticColors.base.fg.light", "black"),
|
|
3620
3621
|
caretColor: "black"
|
|
3621
3622
|
},
|
|
3622
3623
|
"&dark .cm-content": {
|
|
3623
|
-
color:
|
|
3624
|
+
color: get4(tokens, "extend.semanticColors.base.fg.dark", "white"),
|
|
3624
3625
|
caretColor: "white"
|
|
3625
3626
|
},
|
|
3626
3627
|
//
|
|
@@ -3633,10 +3634,10 @@ var defaultTheme = {
|
|
|
3633
3634
|
borderLeft: "2px solid white"
|
|
3634
3635
|
},
|
|
3635
3636
|
"&light .cm-placeholder": {
|
|
3636
|
-
color:
|
|
3637
|
+
color: get4(tokens, "extend.semanticColors.description.light", "rgba(0,0,0,.2)")
|
|
3637
3638
|
},
|
|
3638
3639
|
"&dark .cm-placeholder": {
|
|
3639
|
-
color:
|
|
3640
|
+
color: get4(tokens, "extend.semanticColors.description.dark", "rgba(255,255,255,.2)")
|
|
3640
3641
|
},
|
|
3641
3642
|
//
|
|
3642
3643
|
// line
|
|
@@ -3648,39 +3649,45 @@ var defaultTheme = {
|
|
|
3648
3649
|
background: "transparent"
|
|
3649
3650
|
},
|
|
3650
3651
|
//
|
|
3652
|
+
// gutter
|
|
3653
|
+
//
|
|
3654
|
+
".cm-gutterElement": {
|
|
3655
|
+
width: "48px"
|
|
3656
|
+
},
|
|
3657
|
+
//
|
|
3651
3658
|
// Selection
|
|
3652
3659
|
//
|
|
3653
3660
|
"&light .cm-selectionBackground": {
|
|
3654
|
-
background:
|
|
3661
|
+
background: get4(tokens, "extend.colors.primary.100")
|
|
3655
3662
|
},
|
|
3656
3663
|
"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
3657
|
-
background:
|
|
3664
|
+
background: get4(tokens, "extend.colors.primary.200")
|
|
3658
3665
|
},
|
|
3659
3666
|
"&dark .cm-selectionBackground": {
|
|
3660
|
-
background:
|
|
3667
|
+
background: get4(tokens, "extend.colors.primary.700")
|
|
3661
3668
|
},
|
|
3662
3669
|
"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
3663
|
-
background:
|
|
3670
|
+
background: get4(tokens, "extend.colors.primary.600")
|
|
3664
3671
|
},
|
|
3665
3672
|
//
|
|
3666
3673
|
// Search
|
|
3667
3674
|
//
|
|
3668
3675
|
"&light .cm-searchMatch": {
|
|
3669
|
-
backgroundColor:
|
|
3676
|
+
backgroundColor: get4(tokens, "extend.colors.yellow.100")
|
|
3670
3677
|
},
|
|
3671
3678
|
"&dark .cm-searchMatch": {
|
|
3672
|
-
backgroundColor:
|
|
3679
|
+
backgroundColor: get4(tokens, "extend.colors.yellow.700")
|
|
3673
3680
|
},
|
|
3674
3681
|
//
|
|
3675
3682
|
// link
|
|
3676
3683
|
//
|
|
3677
3684
|
".cm-link": {
|
|
3678
|
-
color:
|
|
3685
|
+
color: get4(tokens, "extend.colors.primary.500"),
|
|
3679
3686
|
textDecorationLine: "underline",
|
|
3680
3687
|
textDecorationThickness: "1px",
|
|
3681
3688
|
textUnderlineOffset: "2px",
|
|
3682
3689
|
borderRadius: ".125rem",
|
|
3683
|
-
fontFamily:
|
|
3690
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3684
3691
|
},
|
|
3685
3692
|
//
|
|
3686
3693
|
// tooltip
|
|
@@ -3702,7 +3709,7 @@ var defaultTheme = {
|
|
|
3702
3709
|
display: "none"
|
|
3703
3710
|
},
|
|
3704
3711
|
".cm-completionLabel": {
|
|
3705
|
-
fontFamily:
|
|
3712
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3706
3713
|
},
|
|
3707
3714
|
".cm-completionMatchedText": {
|
|
3708
3715
|
textDecoration: "none"
|
|
@@ -3711,15 +3718,15 @@ var defaultTheme = {
|
|
|
3711
3718
|
// table
|
|
3712
3719
|
//
|
|
3713
3720
|
".cm-table *": {
|
|
3714
|
-
fontFamily: `${
|
|
3721
|
+
fontFamily: `${get4(tokens, "fontFamily.mono", []).join(",")} !important`,
|
|
3715
3722
|
textDecoration: "none !important"
|
|
3716
3723
|
},
|
|
3717
3724
|
".cm-table-head": {
|
|
3718
3725
|
padding: "2px 16px 2px 0px",
|
|
3719
|
-
borderBottom: `1px solid ${
|
|
3726
|
+
borderBottom: `1px solid ${get4(tokens, "extend.colors.neutral.500")}`,
|
|
3720
3727
|
fontWeight: 100,
|
|
3721
3728
|
textAlign: "left",
|
|
3722
|
-
color:
|
|
3729
|
+
color: get4(tokens, "extend.colors.neutral.500")
|
|
3723
3730
|
},
|
|
3724
3731
|
".cm-table-cell": {
|
|
3725
3732
|
padding: "2px 16px 2px 0px"
|
|
@@ -3766,23 +3773,23 @@ var defaultTheme = {
|
|
|
3766
3773
|
* </div
|
|
3767
3774
|
*/
|
|
3768
3775
|
".cm-panels": {
|
|
3769
|
-
border: `1px solid ${
|
|
3776
|
+
border: `1px solid ${get4(tokens, "extend.colors.neutral.200")}`
|
|
3770
3777
|
},
|
|
3771
3778
|
".cm-panel": {
|
|
3772
|
-
background:
|
|
3773
|
-
fontFamily:
|
|
3779
|
+
background: get4(tokens, "extend.colors.neutral.50"),
|
|
3780
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3774
3781
|
},
|
|
3775
3782
|
".cm-button": {
|
|
3776
3783
|
margin: "4px",
|
|
3777
|
-
fontFamily:
|
|
3778
|
-
background:
|
|
3784
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(","),
|
|
3785
|
+
background: get4(tokens, "extend.colors.neutral.100"),
|
|
3779
3786
|
backgroundImage: "none",
|
|
3780
3787
|
border: "none",
|
|
3781
3788
|
"&:hover": {
|
|
3782
|
-
background:
|
|
3789
|
+
background: get4(tokens, "extend.colors.neutral.200")
|
|
3783
3790
|
},
|
|
3784
3791
|
"&:active": {
|
|
3785
|
-
background:
|
|
3792
|
+
background: get4(tokens, "extend.colors.neutral.300"),
|
|
3786
3793
|
backgroundImage: "none"
|
|
3787
3794
|
}
|
|
3788
3795
|
},
|
|
@@ -3792,26 +3799,26 @@ var defaultTheme = {
|
|
|
3792
3799
|
};
|
|
3793
3800
|
var textTheme = {
|
|
3794
3801
|
".cm-scroller": {
|
|
3795
|
-
fontFamily:
|
|
3802
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3796
3803
|
},
|
|
3797
3804
|
".cm-placeholder": {
|
|
3798
|
-
fontFamily:
|
|
3805
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3799
3806
|
}
|
|
3800
3807
|
};
|
|
3801
3808
|
var markdownTheme = {
|
|
3802
3809
|
".cm-scroller": {
|
|
3803
|
-
fontFamily:
|
|
3810
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3804
3811
|
},
|
|
3805
3812
|
".cm-placeholder": {
|
|
3806
|
-
fontFamily:
|
|
3813
|
+
fontFamily: get4(tokens, "fontFamily.body", []).join(",")
|
|
3807
3814
|
}
|
|
3808
3815
|
};
|
|
3809
3816
|
var codeTheme = {
|
|
3810
3817
|
".cm-scroller": {
|
|
3811
|
-
fontFamily:
|
|
3818
|
+
fontFamily: get4(tokens, "fontFamily.mono", []).join(",")
|
|
3812
3819
|
},
|
|
3813
3820
|
".cm-placeholder": {
|
|
3814
|
-
fontFamily:
|
|
3821
|
+
fontFamily: get4(tokens, "fontFamily.mono", []).join(",")
|
|
3815
3822
|
}
|
|
3816
3823
|
};
|
|
3817
3824
|
|
|
@@ -4456,7 +4463,7 @@ import { useEffect as useEffect3, useRef as useRef4, useState as useState5 } fro
|
|
|
4456
4463
|
import { log as log5 } from "@dxos/log";
|
|
4457
4464
|
import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
|
|
4458
4465
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
|
|
4459
|
-
var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions } = {}) => {
|
|
4466
|
+
var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions } = {}, deps) => {
|
|
4460
4467
|
const onUpdate = useRef4();
|
|
4461
4468
|
const [view, setView] = useState5();
|
|
4462
4469
|
const parentRef = useRef4(null);
|
|
@@ -4471,7 +4478,7 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4471
4478
|
EditorView15.exceptionSink.of((err) => {
|
|
4472
4479
|
log5.catch(err, void 0, {
|
|
4473
4480
|
F: __dxlog_file6,
|
|
4474
|
-
L:
|
|
4481
|
+
L: 57,
|
|
4475
4482
|
S: void 0,
|
|
4476
4483
|
C: (f, a) => f(...a)
|
|
4477
4484
|
});
|
|
@@ -4500,10 +4507,7 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4500
4507
|
return () => {
|
|
4501
4508
|
view2?.destroy();
|
|
4502
4509
|
};
|
|
4503
|
-
},
|
|
4504
|
-
doc,
|
|
4505
|
-
extensions
|
|
4506
|
-
]);
|
|
4510
|
+
}, deps);
|
|
4507
4511
|
useEffect3(() => {
|
|
4508
4512
|
if (view) {
|
|
4509
4513
|
if (!selection && !view.state.selection.main.anchor) {
|
|
@@ -4559,13 +4563,32 @@ var createThemeExtensions = ({ theme, themeMode, slots } = {}) => {
|
|
|
4559
4563
|
};
|
|
4560
4564
|
|
|
4561
4565
|
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
4562
|
-
import
|
|
4566
|
+
import get5 from "lodash.get";
|
|
4563
4567
|
import { useState as useState6, useMemo as useMemo3 } from "react";
|
|
4564
4568
|
import { generateName } from "@dxos/display-name";
|
|
4565
4569
|
import { getRawDoc } from "@dxos/echo-schema";
|
|
4566
4570
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
4567
4571
|
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
4568
4572
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextModel.ts";
|
|
4573
|
+
var useTextExtensions = ({ id, text, space, identity }) => {
|
|
4574
|
+
const extensions = [
|
|
4575
|
+
automerge(text)
|
|
4576
|
+
];
|
|
4577
|
+
if (space && identity) {
|
|
4578
|
+
const awarenessProvider2 = new SpaceAwarenessProvider({
|
|
4579
|
+
space,
|
|
4580
|
+
channel: `awareness.${id}`,
|
|
4581
|
+
peerId: identity.identityKey.toHex(),
|
|
4582
|
+
info: {
|
|
4583
|
+
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
4584
|
+
color: cursorColor.color,
|
|
4585
|
+
lightColor: cursorColor.light
|
|
4586
|
+
}
|
|
4587
|
+
});
|
|
4588
|
+
extensions.push(awareness(awarenessProvider2));
|
|
4589
|
+
}
|
|
4590
|
+
return extensions;
|
|
4591
|
+
};
|
|
4569
4592
|
var useTextModel = (props) => useMemo3(() => createModel(props), Object.values(props));
|
|
4570
4593
|
var useInMemoryTextModel = ({ id, defaultContent }) => {
|
|
4571
4594
|
const [content, setContent] = useState6(defaultContent ?? "");
|
|
@@ -4582,7 +4605,7 @@ var createModel = ({ space, identity, text }) => {
|
|
|
4582
4605
|
}
|
|
4583
4606
|
invariant3(isAutomergeObject(text), void 0, {
|
|
4584
4607
|
F: __dxlog_file7,
|
|
4585
|
-
L:
|
|
4608
|
+
L: 83,
|
|
4586
4609
|
S: void 0,
|
|
4587
4610
|
A: [
|
|
4588
4611
|
"isAutomergeObject(text)",
|
|
@@ -4616,7 +4639,7 @@ var createModel = ({ space, identity, text }) => {
|
|
|
4616
4639
|
const model = {
|
|
4617
4640
|
id: obj.id,
|
|
4618
4641
|
content: doc,
|
|
4619
|
-
text: () =>
|
|
4642
|
+
text: () => get5(doc.handle.docSync(), doc.path),
|
|
4620
4643
|
extension: extensions,
|
|
4621
4644
|
peer: identity ? {
|
|
4622
4645
|
id: identity.identityKey.toHex(),
|
|
@@ -4718,6 +4741,7 @@ export {
|
|
|
4718
4741
|
useFormattingState,
|
|
4719
4742
|
useInMemoryTextModel,
|
|
4720
4743
|
useTextEditor,
|
|
4744
|
+
useTextExtensions,
|
|
4721
4745
|
useTextModel,
|
|
4722
4746
|
useToolbarContext
|
|
4723
4747
|
};
|