@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
|
@@ -23,7 +23,7 @@ var translations_default = [
|
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
// packages/ui/react-ui-editor/src/index.ts
|
|
26
|
-
import { keymap as
|
|
26
|
+
import { keymap as keymap9 } from "@codemirror/view";
|
|
27
27
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
|
28
28
|
import { Doc, YText, YXmlFragment } from "@dxos/text-model";
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ import { tags as tags2 } from "@lezer/highlight";
|
|
|
32
32
|
|
|
33
33
|
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
34
34
|
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
35
|
-
import { EditorView as
|
|
35
|
+
import { EditorView as EditorView17, scrollPastEnd } from "@codemirror/view";
|
|
36
36
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
37
37
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
38
38
|
import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2, useMemo as useMemo2 } from "react";
|
|
@@ -596,7 +596,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
596
596
|
to: startLine.from + startLine.length,
|
|
597
597
|
value: Decoration2.mark({
|
|
598
598
|
attributes: {
|
|
599
|
-
style: `background-color: ${
|
|
599
|
+
style: `background-color: ${lightColor}`
|
|
600
600
|
},
|
|
601
601
|
class: "cm-collab-selection"
|
|
602
602
|
})
|
|
@@ -606,7 +606,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
606
606
|
to: end,
|
|
607
607
|
value: Decoration2.mark({
|
|
608
608
|
attributes: {
|
|
609
|
-
style: `background-color: ${
|
|
609
|
+
style: `background-color: ${lightColor}`
|
|
610
610
|
},
|
|
611
611
|
class: "cm-collab-selection"
|
|
612
612
|
})
|
|
@@ -618,7 +618,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
618
618
|
to: linePos,
|
|
619
619
|
value: Decoration2.line({
|
|
620
620
|
attributes: {
|
|
621
|
-
style: `background-color: ${
|
|
621
|
+
style: `background-color: ${lightColor}`,
|
|
622
622
|
class: "cm-collab-selectionLine"
|
|
623
623
|
}
|
|
624
624
|
})
|
|
@@ -1063,52 +1063,232 @@ var random = (min, max) => {
|
|
|
1063
1063
|
return min + ~~(Math.random() * (max - min + 1));
|
|
1064
1064
|
};
|
|
1065
1065
|
|
|
1066
|
-
// packages/ui/react-ui-editor/src/extensions/
|
|
1067
|
-
import {
|
|
1068
|
-
import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
|
|
1069
|
-
import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
|
|
1070
|
-
import sortBy from "lodash.sortby";
|
|
1071
|
-
import { useEffect } from "react";
|
|
1072
|
-
import { debounce } from "@dxos/async";
|
|
1073
|
-
import { nonNullable } from "@dxos/util";
|
|
1066
|
+
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
|
1067
|
+
import { EditorView as EditorView7, keymap as keymap3 } from "@codemirror/view";
|
|
1074
1068
|
|
|
1075
|
-
// packages/ui/react-ui-editor/src/
|
|
1076
|
-
import
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
{
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1069
|
+
// packages/ui/react-ui-editor/src/extensions/command/hint.ts
|
|
1070
|
+
import { RangeSetBuilder } from "@codemirror/state";
|
|
1071
|
+
import { Decoration as Decoration3, EditorView as EditorView6, ViewPlugin as ViewPlugin3, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1072
|
+
|
|
1073
|
+
// packages/ui/react-ui-editor/src/extensions/command/state.ts
|
|
1074
|
+
import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
|
|
1075
|
+
import { showTooltip } from "@codemirror/view";
|
|
1076
|
+
var commandConfig = Facet3.define({
|
|
1077
|
+
combine: (providers) => providers[0]
|
|
1078
|
+
});
|
|
1079
|
+
var commandState = StateField3.define({
|
|
1080
|
+
create: () => ({}),
|
|
1081
|
+
update: (state, tr) => {
|
|
1082
|
+
for (const effect of tr.effects) {
|
|
1083
|
+
if (effect.is(closeEffect)) {
|
|
1084
|
+
return {};
|
|
1085
|
+
}
|
|
1086
|
+
if (effect.is(openEffect)) {
|
|
1087
|
+
const options = tr.state.facet(commandConfig);
|
|
1088
|
+
const { pos, fullWidth } = effect.value;
|
|
1089
|
+
const tooltip = {
|
|
1090
|
+
pos,
|
|
1091
|
+
above: false,
|
|
1092
|
+
arrow: false,
|
|
1093
|
+
strictSide: true,
|
|
1094
|
+
create: (view) => {
|
|
1095
|
+
const dom = document.createElement("div");
|
|
1096
|
+
const tooltipView = {
|
|
1097
|
+
dom,
|
|
1098
|
+
mount: (view2) => {
|
|
1099
|
+
if (fullWidth) {
|
|
1100
|
+
const parent = dom.parentElement;
|
|
1101
|
+
const { paddingLeft, paddingRight } = window.getComputedStyle(parent);
|
|
1102
|
+
const widthWithoutPadding = parent.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight);
|
|
1103
|
+
dom.style.width = `${widthWithoutPadding}px`;
|
|
1104
|
+
}
|
|
1105
|
+
options.onRender(dom, (action) => {
|
|
1106
|
+
view2.dispatch({
|
|
1107
|
+
effects: closeEffect.of(null)
|
|
1108
|
+
});
|
|
1109
|
+
if (action?.insert?.length) {
|
|
1110
|
+
view2.dispatch({
|
|
1111
|
+
changes: {
|
|
1112
|
+
from: pos,
|
|
1113
|
+
insert: action.insert
|
|
1114
|
+
},
|
|
1115
|
+
selection: {
|
|
1116
|
+
anchor: pos + action.insert.length
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
setTimeout(() => view2.focus());
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
return tooltipView;
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
return {
|
|
1128
|
+
tooltip
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return state;
|
|
1101
1133
|
},
|
|
1134
|
+
provide: (f) => [
|
|
1135
|
+
showTooltip.from(f, (value) => value.tooltip ?? null)
|
|
1136
|
+
]
|
|
1137
|
+
});
|
|
1138
|
+
var openEffect = StateEffect2.define();
|
|
1139
|
+
var closeEffect = StateEffect2.define();
|
|
1140
|
+
var openCommand = (view) => {
|
|
1141
|
+
if (view.state.field(commandState, false)) {
|
|
1142
|
+
const selection = view.state.selection.main;
|
|
1143
|
+
const line = view.state.doc.lineAt(selection.from);
|
|
1144
|
+
if (line.from === selection.from && line.from === line.to) {
|
|
1145
|
+
view.dispatch({
|
|
1146
|
+
effects: openEffect.of({
|
|
1147
|
+
pos: selection.anchor,
|
|
1148
|
+
fullWidth: true
|
|
1149
|
+
})
|
|
1150
|
+
});
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return false;
|
|
1155
|
+
};
|
|
1156
|
+
var closeCommand = (view) => {
|
|
1157
|
+
if (view.state.field(commandState, false)) {
|
|
1158
|
+
view.dispatch({
|
|
1159
|
+
effects: closeEffect.of(null)
|
|
1160
|
+
});
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
return false;
|
|
1164
|
+
};
|
|
1165
|
+
var commandKeymap = [
|
|
1102
1166
|
{
|
|
1103
|
-
|
|
1104
|
-
|
|
1167
|
+
key: "/",
|
|
1168
|
+
run: openCommand
|
|
1105
1169
|
},
|
|
1106
1170
|
{
|
|
1107
|
-
|
|
1108
|
-
|
|
1171
|
+
key: "Escape",
|
|
1172
|
+
run: closeCommand
|
|
1109
1173
|
}
|
|
1110
1174
|
];
|
|
1111
|
-
|
|
1175
|
+
|
|
1176
|
+
// packages/ui/react-ui-editor/src/extensions/util/dom.ts
|
|
1177
|
+
var flattenRect = (rect, left) => {
|
|
1178
|
+
const x = left ? rect.left : rect.right;
|
|
1179
|
+
return {
|
|
1180
|
+
left: x,
|
|
1181
|
+
right: x,
|
|
1182
|
+
top: rect.top,
|
|
1183
|
+
bottom: rect.bottom
|
|
1184
|
+
};
|
|
1185
|
+
};
|
|
1186
|
+
var scratchRange;
|
|
1187
|
+
var textRange = (node, from, to = from) => {
|
|
1188
|
+
const range = scratchRange || (scratchRange = document.createRange());
|
|
1189
|
+
range.setEnd(node, to);
|
|
1190
|
+
range.setStart(node, from);
|
|
1191
|
+
return range;
|
|
1192
|
+
};
|
|
1193
|
+
var clientRectsFor = (dom) => {
|
|
1194
|
+
if (dom.nodeType === 3) {
|
|
1195
|
+
return textRange(dom, 0, dom.nodeValue.length).getClientRects();
|
|
1196
|
+
} else if (dom.nodeType === 1) {
|
|
1197
|
+
return dom.getClientRects();
|
|
1198
|
+
} else {
|
|
1199
|
+
return [];
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
// packages/ui/react-ui-editor/src/extensions/command/hint.ts
|
|
1204
|
+
var CommandHint = class extends WidgetType2 {
|
|
1205
|
+
constructor(content) {
|
|
1206
|
+
super();
|
|
1207
|
+
this.content = content;
|
|
1208
|
+
}
|
|
1209
|
+
toDOM() {
|
|
1210
|
+
const wrap = document.createElement("span");
|
|
1211
|
+
wrap.className = "cm-placeholder";
|
|
1212
|
+
wrap.style.pointerEvents = "none";
|
|
1213
|
+
wrap.appendChild(typeof this.content === "string" ? document.createTextNode(this.content) : this.content);
|
|
1214
|
+
if (typeof this.content === "string") {
|
|
1215
|
+
wrap.setAttribute("aria-label", "placeholder " + this.content);
|
|
1216
|
+
} else {
|
|
1217
|
+
wrap.setAttribute("aria-hidden", "true");
|
|
1218
|
+
}
|
|
1219
|
+
return wrap;
|
|
1220
|
+
}
|
|
1221
|
+
coordsAt(dom) {
|
|
1222
|
+
const rects = dom.firstChild ? clientRectsFor(dom.firstChild) : [];
|
|
1223
|
+
if (!rects.length) {
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
const style = window.getComputedStyle(dom.parentNode);
|
|
1227
|
+
const rect = flattenRect(rects[0], style.direction !== "rtl");
|
|
1228
|
+
const lineHeight = parseInt(style.lineHeight);
|
|
1229
|
+
if (rect.bottom - rect.top > lineHeight * 1.5) {
|
|
1230
|
+
return {
|
|
1231
|
+
left: rect.left,
|
|
1232
|
+
right: rect.right,
|
|
1233
|
+
top: rect.top,
|
|
1234
|
+
bottom: rect.top + lineHeight
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
return rect;
|
|
1238
|
+
}
|
|
1239
|
+
ignoreEvent() {
|
|
1240
|
+
return false;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var hintViewPlugin = ({ onHint }) => ViewPlugin3.fromClass(class {
|
|
1244
|
+
constructor() {
|
|
1245
|
+
this.deco = Decoration3.none;
|
|
1246
|
+
}
|
|
1247
|
+
update(update2) {
|
|
1248
|
+
const builder = new RangeSetBuilder();
|
|
1249
|
+
const cState = update2.view.state.field(commandState, false);
|
|
1250
|
+
if (!cState?.tooltip) {
|
|
1251
|
+
const selection = update2.view.state.selection.main;
|
|
1252
|
+
const line = update2.view.state.doc.lineAt(selection.from);
|
|
1253
|
+
if (selection.from === selection.to && line.from === line.to) {
|
|
1254
|
+
const hint = onHint();
|
|
1255
|
+
if (hint) {
|
|
1256
|
+
builder.add(selection.from, selection.to, Decoration3.widget({
|
|
1257
|
+
widget: new CommandHint(hint)
|
|
1258
|
+
}));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
this.deco = builder.finish();
|
|
1263
|
+
}
|
|
1264
|
+
}, {
|
|
1265
|
+
provide: (plugin) => [
|
|
1266
|
+
EditorView6.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration3.none)
|
|
1267
|
+
]
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
|
1271
|
+
var command = (options) => {
|
|
1272
|
+
return [
|
|
1273
|
+
commandState,
|
|
1274
|
+
keymap3.of(commandKeymap),
|
|
1275
|
+
hintViewPlugin(options),
|
|
1276
|
+
// Close tooltip on focus change.
|
|
1277
|
+
EditorView7.focusChangeEffect.of((_, focusing) => {
|
|
1278
|
+
return focusing ? closeEffect.of(null) : null;
|
|
1279
|
+
}),
|
|
1280
|
+
commandConfig.of(options)
|
|
1281
|
+
];
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1285
|
+
import { invertedEffects } from "@codemirror/commands";
|
|
1286
|
+
import { Facet as Facet4, StateEffect as StateEffect3, StateField as StateField4 } from "@codemirror/state";
|
|
1287
|
+
import { hoverTooltip, keymap as keymap4, Decoration as Decoration4, EditorView as EditorView8 } from "@codemirror/view";
|
|
1288
|
+
import sortBy from "lodash.sortby";
|
|
1289
|
+
import { useEffect } from "react";
|
|
1290
|
+
import { debounce } from "@dxos/async";
|
|
1291
|
+
import { nonNullable } from "@dxos/util";
|
|
1112
1292
|
|
|
1113
1293
|
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
|
1114
1294
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -1180,13 +1360,13 @@ var logChanges = (trs) => {
|
|
|
1180
1360
|
};
|
|
1181
1361
|
|
|
1182
1362
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1183
|
-
var documentId =
|
|
1363
|
+
var documentId = Facet4.define({
|
|
1184
1364
|
combine: (values) => values[0]
|
|
1185
1365
|
});
|
|
1186
|
-
var setComments =
|
|
1187
|
-
var setSelection =
|
|
1188
|
-
var setCommentState =
|
|
1189
|
-
var commentsState =
|
|
1366
|
+
var setComments = StateEffect3.define();
|
|
1367
|
+
var setSelection = StateEffect3.define();
|
|
1368
|
+
var setCommentState = StateEffect3.define();
|
|
1369
|
+
var commentsState = StateField4.define({
|
|
1190
1370
|
create: (state) => ({
|
|
1191
1371
|
id: state.facet(documentId),
|
|
1192
1372
|
comments: [],
|
|
@@ -1224,7 +1404,7 @@ var commentsState = StateField3.define({
|
|
|
1224
1404
|
return value;
|
|
1225
1405
|
}
|
|
1226
1406
|
});
|
|
1227
|
-
var styles3 =
|
|
1407
|
+
var styles3 = EditorView8.baseTheme({
|
|
1228
1408
|
"&light .cm-comment, &light .cm-comment-current": {
|
|
1229
1409
|
mixBlendMode: "darken"
|
|
1230
1410
|
},
|
|
@@ -1246,19 +1426,19 @@ var styles3 = EditorView6.baseTheme({
|
|
|
1246
1426
|
backgroundColor: getToken("extend.colors.yellow.950")
|
|
1247
1427
|
}
|
|
1248
1428
|
});
|
|
1249
|
-
var commentMark =
|
|
1429
|
+
var commentMark = Decoration4.mark({
|
|
1250
1430
|
class: "cm-comment",
|
|
1251
1431
|
attributes: {
|
|
1252
1432
|
"data-testid": "cm-comment"
|
|
1253
1433
|
}
|
|
1254
1434
|
});
|
|
1255
|
-
var commentCurrentMark =
|
|
1435
|
+
var commentCurrentMark = Decoration4.mark({
|
|
1256
1436
|
class: "cm-comment-current",
|
|
1257
1437
|
attributes: {
|
|
1258
1438
|
"data-testid": "cm-comment"
|
|
1259
1439
|
}
|
|
1260
1440
|
});
|
|
1261
|
-
var commentsDecorations =
|
|
1441
|
+
var commentsDecorations = EditorView8.decorations.compute([
|
|
1262
1442
|
commentsState
|
|
1263
1443
|
], (state) => {
|
|
1264
1444
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
|
@@ -1274,7 +1454,7 @@ var commentsDecorations = EditorView6.decorations.compute([
|
|
|
1274
1454
|
return commentMark.range(range.from, range.to);
|
|
1275
1455
|
}
|
|
1276
1456
|
}).filter(nonNullable);
|
|
1277
|
-
return
|
|
1457
|
+
return Decoration4.set(decorations);
|
|
1278
1458
|
});
|
|
1279
1459
|
var trackPastedComments = (onUpdate) => {
|
|
1280
1460
|
let tracked = null;
|
|
@@ -1296,7 +1476,7 @@ var trackPastedComments = (onUpdate) => {
|
|
|
1296
1476
|
}
|
|
1297
1477
|
};
|
|
1298
1478
|
return [
|
|
1299
|
-
|
|
1479
|
+
EditorView8.domEventHandlers({
|
|
1300
1480
|
cut: handleTrack,
|
|
1301
1481
|
copy: handleTrack
|
|
1302
1482
|
}),
|
|
@@ -1318,7 +1498,7 @@ var trackPastedComments = (onUpdate) => {
|
|
|
1318
1498
|
return effects;
|
|
1319
1499
|
}),
|
|
1320
1500
|
// Handle paste or the undo of comment deletion.
|
|
1321
|
-
|
|
1501
|
+
EditorView8.updateListener.of((update2) => {
|
|
1322
1502
|
const restore = [];
|
|
1323
1503
|
for (let i = 0; i < update2.transactions.length; i++) {
|
|
1324
1504
|
const tr = update2.transactions[i];
|
|
@@ -1374,7 +1554,7 @@ var mapTrackedComment = (comment, changes) => ({
|
|
|
1374
1554
|
from: changes.mapPos(comment.from, 1),
|
|
1375
1555
|
to: changes.mapPos(comment.to, 1)
|
|
1376
1556
|
});
|
|
1377
|
-
var restoreCommentEffect =
|
|
1557
|
+
var restoreCommentEffect = StateEffect3.define({
|
|
1378
1558
|
map: mapTrackedComment
|
|
1379
1559
|
});
|
|
1380
1560
|
var createComment = (view) => {
|
|
@@ -1415,7 +1595,7 @@ var createComment = (view) => {
|
|
|
1415
1595
|
}
|
|
1416
1596
|
return false;
|
|
1417
1597
|
};
|
|
1418
|
-
var optionsFacet =
|
|
1598
|
+
var optionsFacet = Facet4.define({
|
|
1419
1599
|
combine: (providers) => providers[0]
|
|
1420
1600
|
});
|
|
1421
1601
|
var comments = (options = {}) => {
|
|
@@ -1430,7 +1610,7 @@ var comments = (options = {}) => {
|
|
|
1430
1610
|
//
|
|
1431
1611
|
// Keymap.
|
|
1432
1612
|
//
|
|
1433
|
-
options.onCreate ?
|
|
1613
|
+
options.onCreate ? keymap4.of([
|
|
1434
1614
|
{
|
|
1435
1615
|
key: shortcut,
|
|
1436
1616
|
run: callbackWrapper(createComment)
|
|
@@ -1469,7 +1649,7 @@ var comments = (options = {}) => {
|
|
|
1469
1649
|
//
|
|
1470
1650
|
// Track deleted ranges and update ranges for decorations.
|
|
1471
1651
|
//
|
|
1472
|
-
|
|
1652
|
+
EditorView8.updateListener.of(({ view, state, changes }) => {
|
|
1473
1653
|
let mod = false;
|
|
1474
1654
|
const { comments: comments2, ...value } = state.field(commentsState);
|
|
1475
1655
|
changes.iterChanges((from, to, from2, to2) => {
|
|
@@ -1501,7 +1681,7 @@ var comments = (options = {}) => {
|
|
|
1501
1681
|
//
|
|
1502
1682
|
// Track selection/proximity.
|
|
1503
1683
|
//
|
|
1504
|
-
|
|
1684
|
+
EditorView8.updateListener.of(({ view, state }) => {
|
|
1505
1685
|
let min = Infinity;
|
|
1506
1686
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
|
1507
1687
|
const { head } = state.selection.main;
|
|
@@ -1550,7 +1730,7 @@ var focusComment = (view, id, center = true) => {
|
|
|
1550
1730
|
},
|
|
1551
1731
|
effects: [
|
|
1552
1732
|
//
|
|
1553
|
-
|
|
1733
|
+
EditorView8.scrollIntoView(range.from, center ? {
|
|
1554
1734
|
y: "center"
|
|
1555
1735
|
} : void 0),
|
|
1556
1736
|
setSelection.of({
|
|
@@ -1578,14 +1758,14 @@ var useComments = (view, id, comments2 = []) => {
|
|
|
1578
1758
|
};
|
|
1579
1759
|
|
|
1580
1760
|
// packages/ui/react-ui-editor/src/extensions/cursor-line-margin.ts
|
|
1581
|
-
import { Facet as
|
|
1582
|
-
import { EditorView as
|
|
1583
|
-
var cursorLineMarginFacet =
|
|
1761
|
+
import { Facet as Facet5, Transaction } from "@codemirror/state";
|
|
1762
|
+
import { EditorView as EditorView9 } from "@codemirror/view";
|
|
1763
|
+
var cursorLineMarginFacet = Facet5.define({
|
|
1584
1764
|
combine: (input) => input[0] ?? 3
|
|
1585
1765
|
});
|
|
1586
1766
|
var annotation = "cursorLineMargin";
|
|
1587
1767
|
var lineAtPos = (s, pos) => s.doc.lineAt(pos).number;
|
|
1588
|
-
var cursorLineMargin =
|
|
1768
|
+
var cursorLineMargin = EditorView9.updateListener.of(({ transactions, state, selectionSet, startState, view }) => {
|
|
1589
1769
|
if (transactions.length < 1 || transactions.some((tr) => tr.isUserEvent(annotation))) {
|
|
1590
1770
|
return;
|
|
1591
1771
|
}
|
|
@@ -1621,22 +1801,32 @@ var cursorLineMargin = EditorView7.updateListener.of(({ transactions, state, sel
|
|
|
1621
1801
|
}
|
|
1622
1802
|
view.dispatch({
|
|
1623
1803
|
annotations: Transaction.userEvent.of(annotation),
|
|
1624
|
-
effects:
|
|
1804
|
+
effects: EditorView9.scrollIntoView(s.selection.main.head, {
|
|
1625
1805
|
y: needsScrollTop ? "start" : "end",
|
|
1626
1806
|
yMargin: view.defaultLineHeight * cursorLineMargin2
|
|
1627
1807
|
})
|
|
1628
1808
|
});
|
|
1629
1809
|
});
|
|
1630
1810
|
|
|
1811
|
+
// packages/ui/react-ui-editor/src/extensions/dnd.ts
|
|
1812
|
+
import { EditorView as EditorView10 } from "@codemirror/view";
|
|
1813
|
+
var dnd = () => {
|
|
1814
|
+
return EditorView10.domEventHandlers({
|
|
1815
|
+
drop: (event, view) => {
|
|
1816
|
+
console.log(event);
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1631
1821
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
|
1632
|
-
import { EditorView as
|
|
1822
|
+
import { EditorView as EditorView11 } from "@codemirror/view";
|
|
1633
1823
|
var listener = ({ onFocus, onChange }) => {
|
|
1634
1824
|
const extensions = [];
|
|
1635
|
-
onFocus && extensions.push(
|
|
1825
|
+
onFocus && extensions.push(EditorView11.focusChangeEffect.of((_, focused) => {
|
|
1636
1826
|
onFocus(focused);
|
|
1637
1827
|
return null;
|
|
1638
1828
|
}));
|
|
1639
|
-
onChange && extensions.push(
|
|
1829
|
+
onChange && extensions.push(EditorView11.updateListener.of((update2) => {
|
|
1640
1830
|
onChange(update2.state.doc.toString());
|
|
1641
1831
|
}));
|
|
1642
1832
|
return extensions;
|
|
@@ -1651,7 +1841,7 @@ import { languages } from "@codemirror/language-data";
|
|
|
1651
1841
|
import { searchKeymap } from "@codemirror/search";
|
|
1652
1842
|
import { EditorState } from "@codemirror/state";
|
|
1653
1843
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
1654
|
-
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as
|
|
1844
|
+
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView12, highlightActiveLine as highlightActiveLine2, keymap as keymap5, placeholder as placeholder2 } from "@codemirror/view";
|
|
1655
1845
|
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
|
1656
1846
|
|
|
1657
1847
|
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
|
@@ -1845,7 +2035,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1845
2035
|
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1846
2036
|
var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => {
|
|
1847
2037
|
return [
|
|
1848
|
-
lineWrapping &&
|
|
2038
|
+
lineWrapping && EditorView12.lineWrapping,
|
|
1849
2039
|
EditorState.allowMultipleSelections.of(true),
|
|
1850
2040
|
EditorState.tabSize.of(2),
|
|
1851
2041
|
// https://github.com/codemirror/basic-setup
|
|
@@ -1880,7 +2070,7 @@ var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrap
|
|
|
1880
2070
|
themeMode === "dark" ? syntaxHighlighting2(oneDarkHighlightStyle2) : syntaxHighlighting2(defaultHighlightStyle2),
|
|
1881
2071
|
// Custom styles.
|
|
1882
2072
|
syntaxHighlighting2(markdownHighlightStyle()),
|
|
1883
|
-
|
|
2073
|
+
keymap5.of([
|
|
1884
2074
|
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
|
1885
2075
|
indentWithTab,
|
|
1886
2076
|
// https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
|
|
@@ -1897,17 +2087,17 @@ var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrap
|
|
|
1897
2087
|
|
|
1898
2088
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
|
1899
2089
|
import { syntaxTree } from "@codemirror/language";
|
|
1900
|
-
import { RangeSetBuilder } from "@codemirror/state";
|
|
1901
|
-
import { EditorView as
|
|
2090
|
+
import { RangeSetBuilder as RangeSetBuilder2, StateEffect as StateEffect4 } from "@codemirror/state";
|
|
2091
|
+
import { EditorView as EditorView13, Decoration as Decoration5, WidgetType as WidgetType3, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
|
1902
2092
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1903
|
-
var HorizontalRuleWidget = class extends
|
|
2093
|
+
var HorizontalRuleWidget = class extends WidgetType3 {
|
|
1904
2094
|
toDOM() {
|
|
1905
2095
|
const el = document.createElement("span");
|
|
1906
2096
|
el.className = "cm-hr";
|
|
1907
2097
|
return el;
|
|
1908
2098
|
}
|
|
1909
2099
|
};
|
|
1910
|
-
var LinkButton = class extends
|
|
2100
|
+
var LinkButton = class extends WidgetType3 {
|
|
1911
2101
|
constructor(url, render) {
|
|
1912
2102
|
super();
|
|
1913
2103
|
this.url = url;
|
|
@@ -1922,7 +2112,7 @@ var LinkButton = class extends WidgetType2 {
|
|
|
1922
2112
|
return el;
|
|
1923
2113
|
}
|
|
1924
2114
|
};
|
|
1925
|
-
var CheckboxWidget = class extends
|
|
2115
|
+
var CheckboxWidget = class extends WidgetType3 {
|
|
1926
2116
|
constructor(_checked) {
|
|
1927
2117
|
super();
|
|
1928
2118
|
this._checked = _checked;
|
|
@@ -1959,28 +2149,28 @@ var CheckboxWidget = class extends WidgetType2 {
|
|
|
1959
2149
|
return false;
|
|
1960
2150
|
}
|
|
1961
2151
|
};
|
|
1962
|
-
var hide =
|
|
1963
|
-
var fencedCodeLine =
|
|
2152
|
+
var hide = Decoration5.replace({});
|
|
2153
|
+
var fencedCodeLine = Decoration5.line({
|
|
1964
2154
|
class: mx2("cm-code cm-codeblock-line")
|
|
1965
2155
|
});
|
|
1966
|
-
var fencedCodeLineFirst =
|
|
2156
|
+
var fencedCodeLineFirst = Decoration5.line({
|
|
1967
2157
|
class: mx2("cm-code cm-codeblock-line", "cm-codeblock-first")
|
|
1968
2158
|
});
|
|
1969
|
-
var fencedCodeLineLast =
|
|
2159
|
+
var fencedCodeLineLast = Decoration5.line({
|
|
1970
2160
|
class: mx2("cm-code cm-codeblock-line", "cm-codeblock-last")
|
|
1971
2161
|
});
|
|
1972
|
-
var horizontalRule =
|
|
2162
|
+
var horizontalRule = Decoration5.replace({
|
|
1973
2163
|
widget: new HorizontalRuleWidget()
|
|
1974
2164
|
});
|
|
1975
|
-
var checkedTask =
|
|
2165
|
+
var checkedTask = Decoration5.replace({
|
|
1976
2166
|
widget: new CheckboxWidget(true)
|
|
1977
2167
|
});
|
|
1978
|
-
var uncheckedTask =
|
|
2168
|
+
var uncheckedTask = Decoration5.replace({
|
|
1979
2169
|
widget: new CheckboxWidget(false)
|
|
1980
2170
|
});
|
|
1981
|
-
var editingRange = (state, range) => {
|
|
2171
|
+
var editingRange = (state, range, focus) => {
|
|
1982
2172
|
const { readOnly, selection: { main: { head } } } = state;
|
|
1983
|
-
return !readOnly && head >= range.from && head
|
|
2173
|
+
return focus && !readOnly && head >= range.from && head < range.to;
|
|
1984
2174
|
};
|
|
1985
2175
|
var MarksByParent = /* @__PURE__ */ new Set([
|
|
1986
2176
|
"CodeMark",
|
|
@@ -1989,8 +2179,9 @@ var MarksByParent = /* @__PURE__ */ new Set([
|
|
|
1989
2179
|
"SubscriptMark",
|
|
1990
2180
|
"SuperscriptMark"
|
|
1991
2181
|
]);
|
|
1992
|
-
var buildDecorations = (view, options) => {
|
|
1993
|
-
const
|
|
2182
|
+
var buildDecorations = (view, options, focus) => {
|
|
2183
|
+
const deco = new RangeSetBuilder2();
|
|
2184
|
+
const atomicDeco = new RangeSetBuilder2();
|
|
1994
2185
|
const { state } = view;
|
|
1995
2186
|
for (const { from, to } of view.visibleRanges) {
|
|
1996
2187
|
syntaxTree(state).iterate({
|
|
@@ -1998,7 +2189,7 @@ var buildDecorations = (view, options) => {
|
|
|
1998
2189
|
to,
|
|
1999
2190
|
enter: (node) => {
|
|
2000
2191
|
if (node.name === "FencedCode") {
|
|
2001
|
-
const editing = editingRange(state, node);
|
|
2192
|
+
const editing = editingRange(state, node, focus);
|
|
2002
2193
|
for (const block of view.viewportLineBlocks) {
|
|
2003
2194
|
if (block.to < node.from) {
|
|
2004
2195
|
continue;
|
|
@@ -2008,22 +2199,22 @@ var buildDecorations = (view, options) => {
|
|
|
2008
2199
|
}
|
|
2009
2200
|
const first = block.from <= node.from;
|
|
2010
2201
|
const last = block.to >= node.to;
|
|
2011
|
-
|
|
2202
|
+
deco.add(block.from, block.from, first ? fencedCodeLineFirst : last ? fencedCodeLineLast : fencedCodeLine);
|
|
2012
2203
|
if (!editing && (first || last)) {
|
|
2013
|
-
|
|
2204
|
+
atomicDeco.add(block.from, block.to, hide);
|
|
2014
2205
|
}
|
|
2015
2206
|
}
|
|
2016
2207
|
return false;
|
|
2017
2208
|
} else if (node.name === "Link") {
|
|
2018
2209
|
const marks = node.node.getChildren("LinkMark");
|
|
2019
2210
|
const urlNode = node.node.getChild("URL");
|
|
2020
|
-
const editing = editingRange(state, node);
|
|
2211
|
+
const editing = editingRange(state, node, focus);
|
|
2021
2212
|
if (urlNode && marks.length >= 2) {
|
|
2022
2213
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
2023
2214
|
if (!editing) {
|
|
2024
|
-
|
|
2215
|
+
atomicDeco.add(node.from, marks[0].to, hide);
|
|
2025
2216
|
}
|
|
2026
|
-
|
|
2217
|
+
deco.add(marks[0].to, marks[1].from, Decoration5.mark({
|
|
2027
2218
|
tagName: "a",
|
|
2028
2219
|
attributes: {
|
|
2029
2220
|
class: "cm-link",
|
|
@@ -2033,57 +2224,86 @@ var buildDecorations = (view, options) => {
|
|
|
2033
2224
|
}
|
|
2034
2225
|
}));
|
|
2035
2226
|
if (!editing) {
|
|
2036
|
-
|
|
2227
|
+
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ? Decoration5.replace({
|
|
2037
2228
|
widget: new LinkButton(url, options.renderLinkButton)
|
|
2038
2229
|
}) : hide);
|
|
2039
2230
|
}
|
|
2040
2231
|
}
|
|
2041
2232
|
} else if (node.name === "HeaderMark") {
|
|
2042
2233
|
const parent = node.node.parent;
|
|
2043
|
-
if (/^ATX/.test(parent.name) && !editingRange(state, state.doc.lineAt(node.from))) {
|
|
2234
|
+
if (/^ATX/.test(parent.name) && !editingRange(state, state.doc.lineAt(node.from), focus)) {
|
|
2044
2235
|
const next = state.doc.sliceString(node.to, node.to + 1);
|
|
2045
|
-
|
|
2236
|
+
atomicDeco.add(node.from, node.to + (next === " " ? 1 : 0), hide);
|
|
2046
2237
|
}
|
|
2047
2238
|
} else if (node.name === "HorizontalRule") {
|
|
2048
|
-
if (!editingRange(state, node)) {
|
|
2049
|
-
|
|
2239
|
+
if (!editingRange(state, node, focus)) {
|
|
2240
|
+
deco.add(node.from, node.to, horizontalRule);
|
|
2050
2241
|
}
|
|
2051
2242
|
} else if (node.name === "TaskMarker") {
|
|
2052
|
-
if (!editingRange(state, node)) {
|
|
2243
|
+
if (!editingRange(state, node, focus)) {
|
|
2053
2244
|
const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
|
|
2054
|
-
|
|
2245
|
+
atomicDeco.add(node.from - 2, node.from - 1, Decoration5.mark({
|
|
2055
2246
|
class: "cm-task"
|
|
2056
2247
|
}));
|
|
2057
|
-
|
|
2248
|
+
atomicDeco.add(node.from, node.to, checked ? checkedTask : uncheckedTask);
|
|
2058
2249
|
}
|
|
2059
2250
|
} else if (MarksByParent.has(node.name)) {
|
|
2060
|
-
if (!editingRange(state, node.node.parent)) {
|
|
2061
|
-
|
|
2251
|
+
if (!editingRange(state, node.node.parent, focus)) {
|
|
2252
|
+
atomicDeco.add(node.from, node.to, hide);
|
|
2062
2253
|
}
|
|
2063
2254
|
}
|
|
2064
2255
|
}
|
|
2065
2256
|
});
|
|
2066
2257
|
}
|
|
2067
|
-
return
|
|
2258
|
+
return {
|
|
2259
|
+
deco: deco.finish(),
|
|
2260
|
+
atomicDeco: atomicDeco.finish()
|
|
2261
|
+
};
|
|
2068
2262
|
};
|
|
2263
|
+
var forceUpdate = StateEffect4.define();
|
|
2069
2264
|
var decorateMarkdown = (options = {}) => {
|
|
2070
2265
|
return [
|
|
2071
|
-
|
|
2266
|
+
ViewPlugin4.fromClass(class {
|
|
2072
2267
|
constructor(view) {
|
|
2073
|
-
this.
|
|
2268
|
+
this.pendingUpdate = -1;
|
|
2269
|
+
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations(view, options, view.hasFocus));
|
|
2074
2270
|
}
|
|
2075
2271
|
update(update2) {
|
|
2076
|
-
if (update2.docChanged || update2.
|
|
2077
|
-
this.
|
|
2272
|
+
if (update2.docChanged || update2.viewportChanged || update2.focusChanged || update2.transactions.some((tr) => tr.effects.some((e) => e.is(forceUpdate)))) {
|
|
2273
|
+
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations(update2.view, options, update2.view.hasFocus));
|
|
2274
|
+
this.clearUpdate();
|
|
2275
|
+
} else if (update2.selectionSet) {
|
|
2276
|
+
this.scheduleUpdate(update2.view);
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
clearUpdate() {
|
|
2280
|
+
if (this.pendingUpdate > -1) {
|
|
2281
|
+
window.clearTimeout(this.pendingUpdate);
|
|
2282
|
+
this.pendingUpdate = -1;
|
|
2078
2283
|
}
|
|
2079
2284
|
}
|
|
2285
|
+
scheduleUpdate(view) {
|
|
2286
|
+
this.clearUpdate();
|
|
2287
|
+
this.pendingUpdate = window.setTimeout(() => {
|
|
2288
|
+
view.dispatch({
|
|
2289
|
+
effects: forceUpdate.of(null)
|
|
2290
|
+
});
|
|
2291
|
+
}, options.selectionChangeDelay ?? 400);
|
|
2292
|
+
}
|
|
2293
|
+
destroy() {
|
|
2294
|
+
this.clearUpdate();
|
|
2295
|
+
}
|
|
2080
2296
|
}, {
|
|
2081
|
-
|
|
2297
|
+
provide: (plugin) => [
|
|
2298
|
+
EditorView13.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration5.none),
|
|
2299
|
+
EditorView13.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration5.none),
|
|
2300
|
+
EditorView13.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration5.none)
|
|
2301
|
+
]
|
|
2082
2302
|
}),
|
|
2083
2303
|
formattingStyles
|
|
2084
2304
|
];
|
|
2085
2305
|
};
|
|
2086
|
-
var formattingStyles =
|
|
2306
|
+
var formattingStyles = EditorView13.baseTheme({
|
|
2087
2307
|
"& .cm-code": {
|
|
2088
2308
|
fontFamily: getToken("fontFamily.mono", []).join(",")
|
|
2089
2309
|
},
|
|
@@ -2136,7 +2356,7 @@ var formattingStyles = EditorView10.baseTheme({
|
|
|
2136
2356
|
import { snippet } from "@codemirror/autocomplete";
|
|
2137
2357
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
2138
2358
|
import { EditorSelection } from "@codemirror/state";
|
|
2139
|
-
import { EditorView as
|
|
2359
|
+
import { EditorView as EditorView14, keymap as keymap6 } from "@codemirror/view";
|
|
2140
2360
|
import { useState, useMemo } from "react";
|
|
2141
2361
|
var compareFormatting = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.blockQuote === b.blockQuote;
|
|
2142
2362
|
var Inline;
|
|
@@ -3008,7 +3228,7 @@ var toggleCodeblock = (target) => {
|
|
|
3008
3228
|
};
|
|
3009
3229
|
var formatting = (options = {}) => {
|
|
3010
3230
|
return [
|
|
3011
|
-
|
|
3231
|
+
keymap6.of([
|
|
3012
3232
|
{
|
|
3013
3233
|
key: "meta-b",
|
|
3014
3234
|
run: toggleStrong
|
|
@@ -3206,7 +3426,7 @@ var getFormatting = (state) => {
|
|
|
3206
3426
|
};
|
|
3207
3427
|
var useFormattingState = () => {
|
|
3208
3428
|
const [state, setState] = useState(null);
|
|
3209
|
-
const observer = useMemo(() =>
|
|
3429
|
+
const observer = useMemo(() => EditorView14.updateListener.of((update2) => {
|
|
3210
3430
|
if (update2.docChanged || update2.selectionSet) {
|
|
3211
3431
|
const newState = getFormatting(update2.state);
|
|
3212
3432
|
if (!state || !compareFormatting(state, newState)) {
|
|
@@ -3222,12 +3442,12 @@ var useFormattingState = () => {
|
|
|
3222
3442
|
|
|
3223
3443
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
|
3224
3444
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
3225
|
-
import { StateField as
|
|
3226
|
-
import { Decoration as
|
|
3445
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
|
3446
|
+
import { Decoration as Decoration6, EditorView as EditorView15, WidgetType as WidgetType4 } from "@codemirror/view";
|
|
3227
3447
|
var image = (options = {}) => {
|
|
3228
|
-
return
|
|
3448
|
+
return StateField5.define({
|
|
3229
3449
|
create: (state) => {
|
|
3230
|
-
return
|
|
3450
|
+
return Decoration6.set(buildDecorations2(0, state.doc.length, state));
|
|
3231
3451
|
},
|
|
3232
3452
|
update: (value, tr) => {
|
|
3233
3453
|
if (!tr.docChanged && !tr.selection) {
|
|
@@ -3250,7 +3470,7 @@ var image = (options = {}) => {
|
|
|
3250
3470
|
add: buildDecorations2(from, to, tr.state)
|
|
3251
3471
|
});
|
|
3252
3472
|
},
|
|
3253
|
-
provide: (field) =>
|
|
3473
|
+
provide: (field) => EditorView15.decorations.from(field)
|
|
3254
3474
|
});
|
|
3255
3475
|
};
|
|
3256
3476
|
var preloaded = /* @__PURE__ */ new Set();
|
|
@@ -3272,7 +3492,7 @@ var buildDecorations2 = (from, to, state) => {
|
|
|
3272
3492
|
const hide2 = state.readOnly || cursor < node.from || cursor > node.to;
|
|
3273
3493
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
3274
3494
|
preloadImage(url);
|
|
3275
|
-
decorations.push(
|
|
3495
|
+
decorations.push(Decoration6.replace({
|
|
3276
3496
|
block: true,
|
|
3277
3497
|
widget: new ImageWidget(url)
|
|
3278
3498
|
}).range(hide2 ? node.from : node.to, node.to));
|
|
@@ -3284,7 +3504,7 @@ var buildDecorations2 = (from, to, state) => {
|
|
|
3284
3504
|
});
|
|
3285
3505
|
return decorations;
|
|
3286
3506
|
};
|
|
3287
|
-
var ImageWidget = class extends
|
|
3507
|
+
var ImageWidget = class extends WidgetType4 {
|
|
3288
3508
|
constructor(_url) {
|
|
3289
3509
|
super();
|
|
3290
3510
|
this._url = _url;
|
|
@@ -3337,17 +3557,17 @@ var linkTooltip = (render) => hoverTooltip2((view, pos, side) => {
|
|
|
3337
3557
|
|
|
3338
3558
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
|
3339
3559
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
|
3340
|
-
import { RangeSetBuilder as
|
|
3341
|
-
import { Decoration as
|
|
3560
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField6 } from "@codemirror/state";
|
|
3561
|
+
import { Decoration as Decoration7, EditorView as EditorView16, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
3342
3562
|
var table = (options = {}) => {
|
|
3343
|
-
return
|
|
3563
|
+
return StateField6.define({
|
|
3344
3564
|
create: (state) => update(state, options),
|
|
3345
3565
|
update: (_, tr) => update(tr.state, options),
|
|
3346
|
-
provide: (field) =>
|
|
3566
|
+
provide: (field) => EditorView16.decorations.from(field)
|
|
3347
3567
|
});
|
|
3348
3568
|
};
|
|
3349
3569
|
var update = (state, options) => {
|
|
3350
|
-
const builder = new
|
|
3570
|
+
const builder = new RangeSetBuilder3();
|
|
3351
3571
|
const cursor = state.selection.main.head;
|
|
3352
3572
|
const tables = [];
|
|
3353
3573
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -3387,16 +3607,16 @@ var update = (state, options) => {
|
|
|
3387
3607
|
});
|
|
3388
3608
|
tables.forEach((table2) => {
|
|
3389
3609
|
const hide2 = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
3390
|
-
hide2 && builder.add(table2.from, table2.to,
|
|
3610
|
+
hide2 && builder.add(table2.from, table2.to, Decoration7.replace({
|
|
3391
3611
|
widget: new TableWidget(table2)
|
|
3392
3612
|
}));
|
|
3393
|
-
builder.add(table2.from, table2.to,
|
|
3613
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
|
3394
3614
|
class: "cm-table"
|
|
3395
3615
|
}));
|
|
3396
3616
|
});
|
|
3397
3617
|
return builder.finish();
|
|
3398
3618
|
};
|
|
3399
|
-
var TableWidget = class extends
|
|
3619
|
+
var TableWidget = class extends WidgetType5 {
|
|
3400
3620
|
constructor(_table) {
|
|
3401
3621
|
super();
|
|
3402
3622
|
this._table = _table;
|
|
@@ -3463,10 +3683,10 @@ var mention = ({ onSearch }) => {
|
|
|
3463
3683
|
};
|
|
3464
3684
|
|
|
3465
3685
|
// packages/ui/react-ui-editor/src/extensions/modes.ts
|
|
3466
|
-
import { Facet as
|
|
3467
|
-
import { keymap as
|
|
3686
|
+
import { Facet as Facet6 } from "@codemirror/state";
|
|
3687
|
+
import { keymap as keymap7 } from "@codemirror/view";
|
|
3468
3688
|
import { vim } from "@replit/codemirror-vim";
|
|
3469
|
-
var editorMode =
|
|
3689
|
+
var editorMode = Facet6.define({
|
|
3470
3690
|
combine: (modes) => modes[0] ?? {}
|
|
3471
3691
|
});
|
|
3472
3692
|
var EditorModes = {
|
|
@@ -3477,7 +3697,7 @@ var EditorModes = {
|
|
|
3477
3697
|
type: "vim",
|
|
3478
3698
|
noTabster: true
|
|
3479
3699
|
}),
|
|
3480
|
-
|
|
3700
|
+
keymap7.of([
|
|
3481
3701
|
{
|
|
3482
3702
|
key: "Alt-Escape",
|
|
3483
3703
|
run: (view) => {
|
|
@@ -3497,7 +3717,7 @@ var outliner = (options = {}) => {
|
|
|
3497
3717
|
};
|
|
3498
3718
|
|
|
3499
3719
|
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
|
3500
|
-
import { keymap as
|
|
3720
|
+
import { keymap as keymap8 } from "@codemirror/view";
|
|
3501
3721
|
var defaultItems = [
|
|
3502
3722
|
"hello world!",
|
|
3503
3723
|
"this is a test.",
|
|
@@ -3507,7 +3727,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
|
3507
3727
|
let t;
|
|
3508
3728
|
let idx = 0;
|
|
3509
3729
|
return [
|
|
3510
|
-
|
|
3730
|
+
keymap8.of([
|
|
3511
3731
|
{
|
|
3512
3732
|
// Reset.
|
|
3513
3733
|
key: "alt-meta-'",
|
|
@@ -3805,7 +4025,7 @@ var codeTheme = {
|
|
|
3805
4025
|
|
|
3806
4026
|
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
3807
4027
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx";
|
|
3808
|
-
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, scrollTo =
|
|
4028
|
+
var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, scrollTo = EditorView17.scrollIntoView(0), moveToEndOfLine, selection, theme, slots = defaultSlots, extensions = [], scrollPastEnd: _scrollPastEnd, debug }, forwardedRef) => {
|
|
3809
4029
|
const tabsterDOMAttribute = useFocusableGroup({
|
|
3810
4030
|
tabBehavior: "limited"
|
|
3811
4031
|
});
|
|
@@ -3832,7 +4052,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3832
4052
|
selection,
|
|
3833
4053
|
extensions: [
|
|
3834
4054
|
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
3835
|
-
|
|
4055
|
+
EditorView17.exceptionSink.of((err) => {
|
|
3836
4056
|
log3.catch(err, void 0, {
|
|
3837
4057
|
F: __dxlog_file4,
|
|
3838
4058
|
L: 122,
|
|
@@ -3842,19 +4062,19 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3842
4062
|
}),
|
|
3843
4063
|
// Theme.
|
|
3844
4064
|
// TODO(burdon): Make base theme configurable.
|
|
3845
|
-
|
|
3846
|
-
theme &&
|
|
3847
|
-
|
|
3848
|
-
slots.editor?.className &&
|
|
4065
|
+
EditorView17.baseTheme(defaultTheme),
|
|
4066
|
+
theme && EditorView17.theme(theme),
|
|
4067
|
+
EditorView17.darkTheme.of(themeMode === "dark"),
|
|
4068
|
+
slots.editor?.className && EditorView17.editorAttributes.of({
|
|
3849
4069
|
class: slots.editor.className
|
|
3850
4070
|
}),
|
|
3851
|
-
slots.content?.className &&
|
|
4071
|
+
slots.content?.className && EditorView17.contentAttributes.of({
|
|
3852
4072
|
class: slots.content.className
|
|
3853
4073
|
}),
|
|
3854
4074
|
// NOTE: Assumes default line height.
|
|
3855
4075
|
_scrollPastEnd && scrollPastEnd(),
|
|
3856
4076
|
// Focus.
|
|
3857
|
-
|
|
4077
|
+
EditorView17.updateListener.of((update2) => {
|
|
3858
4078
|
update2.transactions.forEach((transaction) => {
|
|
3859
4079
|
if (transaction.isUserEvent("focus.container")) {
|
|
3860
4080
|
rootRef.current?.focus();
|
|
@@ -3862,7 +4082,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3862
4082
|
});
|
|
3863
4083
|
}),
|
|
3864
4084
|
// State.
|
|
3865
|
-
|
|
4085
|
+
EditorView17.editable.of(!readonly),
|
|
3866
4086
|
EditorState2.readOnly.of(!!readonly),
|
|
3867
4087
|
// Storage and replication.
|
|
3868
4088
|
// NOTE: This must come before user extensions.
|
|
@@ -3871,7 +4091,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3871
4091
|
...extensions
|
|
3872
4092
|
].filter(isNotFalsy4)
|
|
3873
4093
|
});
|
|
3874
|
-
const view2 = new
|
|
4094
|
+
const view2 = new EditorView17({
|
|
3875
4095
|
state,
|
|
3876
4096
|
parent: rootRef.current,
|
|
3877
4097
|
scrollTo,
|
|
@@ -4363,8 +4583,8 @@ var SpaceAwarenessProvider = class {
|
|
|
4363
4583
|
};
|
|
4364
4584
|
|
|
4365
4585
|
// packages/ui/react-ui-editor/src/hooks/defs.ts
|
|
4366
|
-
import { StateField as
|
|
4367
|
-
var modelState =
|
|
4586
|
+
import { StateField as StateField7 } from "@codemirror/state";
|
|
4587
|
+
var modelState = StateField7.define({
|
|
4368
4588
|
create: () => void 0,
|
|
4369
4589
|
update: (model) => model
|
|
4370
4590
|
});
|
|
@@ -4439,7 +4659,7 @@ var useEditorView = (id) => {
|
|
|
4439
4659
|
|
|
4440
4660
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
|
4441
4661
|
import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
|
|
4442
|
-
import { EditorView as
|
|
4662
|
+
import { EditorView as EditorView18 } from "@codemirror/view";
|
|
4443
4663
|
import { useEffect as useEffect3, useRef as useRef4, useState as useState5 } from "react";
|
|
4444
4664
|
import { log as log5 } from "@dxos/log";
|
|
4445
4665
|
import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
|
|
@@ -4456,7 +4676,7 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4456
4676
|
selection,
|
|
4457
4677
|
extensions: [
|
|
4458
4678
|
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
4459
|
-
|
|
4679
|
+
EditorView18.exceptionSink.of((err) => {
|
|
4460
4680
|
log5.catch(err, void 0, {
|
|
4461
4681
|
F: __dxlog_file6,
|
|
4462
4682
|
L: 57,
|
|
@@ -4465,12 +4685,12 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4465
4685
|
});
|
|
4466
4686
|
}),
|
|
4467
4687
|
extensions,
|
|
4468
|
-
|
|
4688
|
+
EditorView18.updateListener.of(() => {
|
|
4469
4689
|
onUpdate.current?.();
|
|
4470
4690
|
})
|
|
4471
4691
|
].filter(isNotFalsy5)
|
|
4472
4692
|
});
|
|
4473
|
-
view2 = new
|
|
4693
|
+
view2 = new EditorView18({
|
|
4474
4694
|
parent: parentRef.current,
|
|
4475
4695
|
scrollTo,
|
|
4476
4696
|
state,
|
|
@@ -4525,19 +4745,19 @@ var createDataExtensions = ({ readonly = false } = {}) => {
|
|
|
4525
4745
|
return [
|
|
4526
4746
|
//
|
|
4527
4747
|
EditorState3.readOnly.of(readonly),
|
|
4528
|
-
|
|
4748
|
+
EditorView18.editable.of(!readonly)
|
|
4529
4749
|
];
|
|
4530
4750
|
};
|
|
4531
4751
|
var createThemeExtensions = ({ theme, themeMode, slots } = {}) => {
|
|
4532
4752
|
return [
|
|
4533
4753
|
//
|
|
4534
|
-
|
|
4535
|
-
theme &&
|
|
4536
|
-
|
|
4537
|
-
|
|
4754
|
+
EditorView18.baseTheme(defaultTheme),
|
|
4755
|
+
theme && EditorView18.theme(theme),
|
|
4756
|
+
EditorView18.darkTheme.of(themeMode === "dark"),
|
|
4757
|
+
EditorView18.editorAttributes.of({
|
|
4538
4758
|
class: slots?.editor?.className ?? ""
|
|
4539
4759
|
}),
|
|
4540
|
-
|
|
4760
|
+
EditorView18.contentAttributes.of({
|
|
4541
4761
|
class: slots?.content?.className ?? ""
|
|
4542
4762
|
})
|
|
4543
4763
|
].filter(isNotFalsy5);
|
|
@@ -4550,11 +4770,15 @@ import { generateName } from "@dxos/display-name";
|
|
|
4550
4770
|
import { getRawDoc } from "@dxos/echo-schema";
|
|
4551
4771
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
4552
4772
|
import { isAutomergeObject } from "@dxos/react-client/echo";
|
|
4773
|
+
import { hueTokens } from "@dxos/react-ui-theme";
|
|
4774
|
+
import { hexToHue } from "@dxos/util";
|
|
4553
4775
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextModel.ts";
|
|
4554
4776
|
var useTextExtensions = ({ id, text, space, identity }) => {
|
|
4555
4777
|
const extensions = [
|
|
4556
4778
|
automerge(text)
|
|
4557
4779
|
];
|
|
4780
|
+
const peerId = identity?.identityKey.toHex();
|
|
4781
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? "0")];
|
|
4558
4782
|
if (space && identity) {
|
|
4559
4783
|
const awarenessProvider2 = new SpaceAwarenessProvider({
|
|
4560
4784
|
space,
|
|
@@ -4562,8 +4786,8 @@ var useTextExtensions = ({ id, text, space, identity }) => {
|
|
|
4562
4786
|
peerId: identity.identityKey.toHex(),
|
|
4563
4787
|
info: {
|
|
4564
4788
|
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
4565
|
-
color:
|
|
4566
|
-
lightColor:
|
|
4789
|
+
color: cursorDarkValue,
|
|
4790
|
+
lightColor: cursorLightValue
|
|
4567
4791
|
}
|
|
4568
4792
|
});
|
|
4569
4793
|
extensions.push(awareness(awarenessProvider2));
|
|
@@ -4586,7 +4810,7 @@ var createModel = ({ space, identity, text }) => {
|
|
|
4586
4810
|
}
|
|
4587
4811
|
invariant3(isAutomergeObject(text), void 0, {
|
|
4588
4812
|
F: __dxlog_file7,
|
|
4589
|
-
L:
|
|
4813
|
+
L: 87,
|
|
4590
4814
|
S: void 0,
|
|
4591
4815
|
A: [
|
|
4592
4816
|
"isAutomergeObject(text)",
|
|
@@ -4597,13 +4821,15 @@ var createModel = ({ space, identity, text }) => {
|
|
|
4597
4821
|
const doc = getRawDoc(obj, [
|
|
4598
4822
|
obj.field
|
|
4599
4823
|
]);
|
|
4824
|
+
const peerId = identity?.identityKey.toHex();
|
|
4825
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? "0")];
|
|
4600
4826
|
const awarenessProvider2 = space && new SpaceAwarenessProvider({
|
|
4601
4827
|
space,
|
|
4602
4828
|
channel: `automerge.awareness.${obj.id}`,
|
|
4603
4829
|
info: {
|
|
4604
4830
|
displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : void 0,
|
|
4605
|
-
color:
|
|
4606
|
-
lightColor:
|
|
4831
|
+
color: cursorLightValue,
|
|
4832
|
+
lightColor: cursorDarkValue
|
|
4607
4833
|
},
|
|
4608
4834
|
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
4609
4835
|
});
|
|
@@ -4657,6 +4883,7 @@ export {
|
|
|
4657
4883
|
blast,
|
|
4658
4884
|
callbackWrapper,
|
|
4659
4885
|
codeTheme,
|
|
4886
|
+
command,
|
|
4660
4887
|
comments,
|
|
4661
4888
|
compareFormatting,
|
|
4662
4889
|
createBasicBundle,
|
|
@@ -4672,6 +4899,7 @@ export {
|
|
|
4672
4899
|
defaultSlots,
|
|
4673
4900
|
defaultTextSlots,
|
|
4674
4901
|
defaultTheme,
|
|
4902
|
+
dnd,
|
|
4675
4903
|
editorFillLayoutEditor,
|
|
4676
4904
|
editorFillLayoutRoot,
|
|
4677
4905
|
editorMode,
|
|
@@ -4682,7 +4910,7 @@ export {
|
|
|
4682
4910
|
getToken,
|
|
4683
4911
|
image,
|
|
4684
4912
|
insertTable,
|
|
4685
|
-
|
|
4913
|
+
keymap9 as keymap,
|
|
4686
4914
|
linkTooltip,
|
|
4687
4915
|
listener,
|
|
4688
4916
|
logChanges,
|