@dxos/react-ui-editor 0.8.1-staging.5be625a → 0.8.1-staging.97aedb1
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 +276 -140
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +310 -178
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +276 -140
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/InputMode.stories.d.ts +2 -2
- package/dist/types/src/TextEditor.stories.d.ts +5 -40
- package/dist/types/src/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts +2 -0
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts +4 -2
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts +12 -0
- package/dist/types/src/extensions/command/menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command/preview.d.ts +12 -0
- package/dist/types/src/extensions/command/preview.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +3 -3
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +1 -1
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/{styles/stack-item-content-class-names.d.ts → fragments.d.ts} +1 -1
- package/dist/types/src/fragments.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/package.json +27 -27
- package/src/InputMode.stories.tsx +4 -4
- package/src/TextEditor.stories.tsx +173 -59
- package/src/components/EditorToolbar/EditorToolbar.tsx +4 -5
- package/src/defaults.ts +12 -0
- package/src/extensions/command/command.ts +21 -2
- package/src/extensions/command/hint.ts +3 -0
- package/src/extensions/command/menu.ts +100 -0
- package/src/extensions/command/preview.ts +79 -0
- package/src/extensions/command/state.ts +9 -4
- package/src/extensions/comments.ts +6 -10
- package/src/extensions/factories.ts +3 -3
- package/src/{styles/stack-item-content-class-names.ts → fragments.ts} +3 -1
- package/src/index.ts +0 -4
- package/src/styles/theme.ts +5 -1
- package/dist/types/src/styles/stack-item-content-class-names.d.ts.map +0 -1
@@ -37,14 +37,14 @@ var translations_default = [
|
|
37
37
|
|
38
38
|
// packages/ui/react-ui-editor/src/index.ts
|
39
39
|
import { EditorState as EditorState3 } from "@codemirror/state";
|
40
|
-
import { EditorView as
|
40
|
+
import { EditorView as EditorView22, keymap as keymap11 } from "@codemirror/view";
|
41
41
|
import { tags as tags2 } from "@lezer/highlight";
|
42
42
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
43
43
|
|
44
44
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/EditorToolbar.tsx
|
45
45
|
import React, { useCallback } from "react";
|
46
46
|
import { ElevationProvider } from "@dxos/react-ui";
|
47
|
-
import { ToolbarMenu,
|
47
|
+
import { MenuProvider, ToolbarMenu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
|
48
48
|
import { textBlockWidth } from "@dxos/react-ui-theme";
|
49
49
|
|
50
50
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/util.ts
|
@@ -313,9 +313,8 @@ var createViewMode = (state) => {
|
|
313
313
|
};
|
314
314
|
};
|
315
315
|
|
316
|
-
// packages/ui/react-ui-editor/src/
|
316
|
+
// packages/ui/react-ui-editor/src/fragments.ts
|
317
317
|
import { mx } from "@dxos/react-ui-theme";
|
318
|
-
var stackItemContentEditorClassNames = (role) => mx("dx-focus-ring-inset data-[toolbar=disabled]:pbs-2 attention-surface", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
319
318
|
var stackItemContentToolbarClassNames = (role) => mx("attention-surface is-full border-be !border-separator", role === "section" && "sticky block-start-0 z-[1] -mbe-px min-is-0");
|
320
319
|
|
321
320
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/EditorToolbar.tsx
|
@@ -467,6 +466,10 @@ var defaultTheme = {
|
|
467
466
|
background: "transparent"
|
468
467
|
},
|
469
468
|
".cm-gutter": {},
|
469
|
+
".cm-gutter.cm-lineNumbers": {
|
470
|
+
paddingRight: "4px",
|
471
|
+
borderRight: "1px solid var(--dx-separator)"
|
472
|
+
},
|
470
473
|
".cm-gutter.cm-lineNumbers .cm-gutterElement": {
|
471
474
|
minWidth: "40px",
|
472
475
|
alignContent: "center"
|
@@ -476,7 +479,7 @@ var defaultTheme = {
|
|
476
479
|
*/
|
477
480
|
".cm-gutterElement": {
|
478
481
|
alignItems: "center",
|
479
|
-
fontSize: "
|
482
|
+
fontSize: "12px"
|
480
483
|
},
|
481
484
|
/**
|
482
485
|
* Line.
|
@@ -651,6 +654,8 @@ var editorMonospace = EditorView.theme({
|
|
651
654
|
}
|
652
655
|
});
|
653
656
|
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
657
|
+
var stackItemContentEditorClassNames = (role) => mx3("attention-surface dx-focus-ring-inset data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
658
|
+
var stackItemContentToolbarClassNames2 = (role) => mx3("attention-surface is-full border-be !border-separator", role === "section" && "sticky block-start-0 z-[1] -mbe-px min-is-0");
|
654
659
|
|
655
660
|
// packages/ui/react-ui-editor/src/extensions/annotations.ts
|
656
661
|
import { StateField } from "@codemirror/state";
|
@@ -1855,7 +1860,7 @@ var random = (min, max) => {
|
|
1855
1860
|
};
|
1856
1861
|
|
1857
1862
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
1858
|
-
import { EditorView as
|
1863
|
+
import { EditorView as EditorView8, keymap as keymap3 } from "@codemirror/view";
|
1859
1864
|
|
1860
1865
|
// packages/ui/react-ui-editor/src/extensions/command/hint.ts
|
1861
1866
|
import { RangeSetBuilder } from "@codemirror/state";
|
@@ -1891,18 +1896,19 @@ var commandState = StateField3.define({
|
|
1891
1896
|
const widthWithoutPadding = parent.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight);
|
1892
1897
|
dom.style.width = `${widthWithoutPadding}px`;
|
1893
1898
|
}
|
1894
|
-
options.
|
1899
|
+
options.onRenderDialog(dom, (action) => {
|
1895
1900
|
view2.dispatch({
|
1896
1901
|
effects: closeEffect.of(null)
|
1897
1902
|
});
|
1898
1903
|
if (action?.insert?.length) {
|
1904
|
+
const text = action.insert + "\n";
|
1899
1905
|
view2.dispatch({
|
1900
1906
|
changes: {
|
1901
1907
|
from: pos,
|
1902
|
-
insert:
|
1908
|
+
insert: text
|
1903
1909
|
},
|
1904
1910
|
selection: {
|
1905
|
-
anchor: pos +
|
1911
|
+
anchor: pos + text.length
|
1906
1912
|
}
|
1907
1913
|
});
|
1908
1914
|
}
|
@@ -2029,23 +2035,156 @@ var hintViewPlugin = ({ onHint }) => ViewPlugin3.fromClass(class {
|
|
2029
2035
|
]
|
2030
2036
|
});
|
2031
2037
|
|
2038
|
+
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
2039
|
+
import { ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
2040
|
+
var floatingMenu = (options) => ViewPlugin4.fromClass(class {
|
2041
|
+
constructor(view) {
|
2042
|
+
this.rafId = null;
|
2043
|
+
this.view = view;
|
2044
|
+
const container = view.scrollDOM;
|
2045
|
+
if (getComputedStyle(container).position === "static") {
|
2046
|
+
container.style.position = "relative";
|
2047
|
+
}
|
2048
|
+
this.button = document.createElement("div");
|
2049
|
+
this.button.style.position = "absolute";
|
2050
|
+
this.button.style.zIndex = "10";
|
2051
|
+
this.button.style.display = "none";
|
2052
|
+
options.onRenderMenu(this.button, () => {
|
2053
|
+
openCommand(view);
|
2054
|
+
});
|
2055
|
+
container.appendChild(this.button);
|
2056
|
+
container.addEventListener("scroll", this.scheduleUpdate);
|
2057
|
+
this.scheduleUpdate();
|
2058
|
+
}
|
2059
|
+
update(update2) {
|
2060
|
+
if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
2061
|
+
this.button.style.display = "none";
|
2062
|
+
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
2063
|
+
this.button.style.display = "block";
|
2064
|
+
} else if (update2.selectionSet || update2.viewportChanged || update2.docChanged || update2.geometryChanged) {
|
2065
|
+
this.scheduleUpdate();
|
2066
|
+
}
|
2067
|
+
}
|
2068
|
+
scheduleUpdate() {
|
2069
|
+
if (this.rafId != null) {
|
2070
|
+
cancelAnimationFrame(this.rafId);
|
2071
|
+
}
|
2072
|
+
this.rafId = requestAnimationFrame(() => this.updateButtonPosition());
|
2073
|
+
}
|
2074
|
+
updateButtonPosition() {
|
2075
|
+
const pos = this.view.state.selection.main.head;
|
2076
|
+
const lineBlock = this.view.lineBlockAt(pos);
|
2077
|
+
const domInfo = this.view.domAtPos(lineBlock.from);
|
2078
|
+
let node = domInfo.node;
|
2079
|
+
while (node && !(node instanceof HTMLElement)) {
|
2080
|
+
node = node.parentNode;
|
2081
|
+
}
|
2082
|
+
if (!node) {
|
2083
|
+
this.button.style.display = "none";
|
2084
|
+
return;
|
2085
|
+
}
|
2086
|
+
const lineRect = node.getBoundingClientRect();
|
2087
|
+
const containerRect = this.view.scrollDOM.getBoundingClientRect();
|
2088
|
+
const offsetTop = lineRect.top - containerRect.top + this.view.scrollDOM.scrollTop;
|
2089
|
+
const offsetLeft = this.view.scrollDOM.clientWidth + this.view.scrollDOM.scrollLeft - lineRect.x;
|
2090
|
+
this.button.style.top = `${offsetTop}px`;
|
2091
|
+
this.button.style.left = `${offsetLeft}px`;
|
2092
|
+
this.button.style.display = "block";
|
2093
|
+
}
|
2094
|
+
destroy() {
|
2095
|
+
this.button.remove();
|
2096
|
+
if (this.rafId != null) {
|
2097
|
+
cancelAnimationFrame(this.rafId);
|
2098
|
+
}
|
2099
|
+
}
|
2100
|
+
});
|
2101
|
+
|
2102
|
+
// packages/ui/react-ui-editor/src/extensions/command/preview.ts
|
2103
|
+
import { syntaxTree } from "@codemirror/language";
|
2104
|
+
import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField4 } from "@codemirror/state";
|
2105
|
+
import { Decoration as Decoration4, EditorView as EditorView7, WidgetType as WidgetType3 } from "@codemirror/view";
|
2106
|
+
var preview = (options) => {
|
2107
|
+
return [
|
2108
|
+
StateField4.define({
|
2109
|
+
create: (state) => buildDecorations(state, options),
|
2110
|
+
update: (_, tr) => buildDecorations(tr.state, options),
|
2111
|
+
// TODO(burdon): Make atomic.
|
2112
|
+
provide: (field) => EditorView7.decorations.from(field)
|
2113
|
+
})
|
2114
|
+
];
|
2115
|
+
};
|
2116
|
+
var buildDecorations = (state, options) => {
|
2117
|
+
const builder = new RangeSetBuilder2();
|
2118
|
+
syntaxTree(state).iterate({
|
2119
|
+
enter: (node) => {
|
2120
|
+
if (node.name === "Link") {
|
2121
|
+
const urlNode = node.node.getChild("URL");
|
2122
|
+
if (urlNode) {
|
2123
|
+
const text = state.sliceDoc(node.from + 1, urlNode.from - 2);
|
2124
|
+
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
2125
|
+
builder.add(node.from, node.to, Decoration4.replace({
|
2126
|
+
block: true,
|
2127
|
+
widget: new PreviewWidget(options.onRenderPreview, url, text)
|
2128
|
+
}));
|
2129
|
+
}
|
2130
|
+
}
|
2131
|
+
}
|
2132
|
+
});
|
2133
|
+
return builder.finish();
|
2134
|
+
};
|
2135
|
+
var PreviewWidget = class extends WidgetType3 {
|
2136
|
+
constructor(_onRenderPreview, _url, _text) {
|
2137
|
+
super();
|
2138
|
+
this._onRenderPreview = _onRenderPreview;
|
2139
|
+
this._url = _url;
|
2140
|
+
this._text = _text;
|
2141
|
+
}
|
2142
|
+
eq(other) {
|
2143
|
+
return this._url === other._url;
|
2144
|
+
}
|
2145
|
+
toDOM(view) {
|
2146
|
+
const root = document.createElement("div");
|
2147
|
+
root.classList.add("cm-preview");
|
2148
|
+
this._onRenderPreview(root, {
|
2149
|
+
url: this._url,
|
2150
|
+
text: this._text
|
2151
|
+
});
|
2152
|
+
return root;
|
2153
|
+
}
|
2154
|
+
};
|
2155
|
+
|
2032
2156
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
2033
2157
|
var command = (options) => {
|
2034
2158
|
return [
|
2035
2159
|
commandConfig.of(options),
|
2036
2160
|
commandState,
|
2037
2161
|
keymap3.of(commandKeyBindings),
|
2162
|
+
preview(options),
|
2163
|
+
floatingMenu(options),
|
2038
2164
|
hintViewPlugin(options),
|
2039
|
-
|
2165
|
+
EditorView8.focusChangeEffect.of((_, focusing) => {
|
2040
2166
|
return focusing ? closeEffect.of(null) : null;
|
2167
|
+
}),
|
2168
|
+
EditorView8.theme({
|
2169
|
+
".cm-tooltip": {
|
2170
|
+
background: "transparent"
|
2171
|
+
},
|
2172
|
+
".cm-preview": {
|
2173
|
+
marginLeft: "-1rem",
|
2174
|
+
marginRight: "-1rem",
|
2175
|
+
padding: "1rem",
|
2176
|
+
borderRadius: "1rem",
|
2177
|
+
background: "var(--dx-modalSurface)",
|
2178
|
+
border: "1px solid var(--dx-separator)"
|
2179
|
+
}
|
2041
2180
|
})
|
2042
2181
|
];
|
2043
2182
|
};
|
2044
2183
|
|
2045
2184
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
2046
2185
|
import { invertedEffects } from "@codemirror/commands";
|
2047
|
-
import { StateEffect as StateEffect3, StateField as
|
2048
|
-
import { hoverTooltip, keymap as keymap5, Decoration as
|
2186
|
+
import { StateEffect as StateEffect3, StateField as StateField5 } from "@codemirror/state";
|
2187
|
+
import { hoverTooltip, keymap as keymap5, Decoration as Decoration5, EditorView as EditorView10, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
2049
2188
|
import sortBy from "lodash.sortby";
|
2050
2189
|
import { useEffect, useMemo as useMemo2 } from "react";
|
2051
2190
|
import { debounce as debounce2 } from "@dxos/async";
|
@@ -2054,7 +2193,7 @@ import { isNonNullable } from "@dxos/util";
|
|
2054
2193
|
|
2055
2194
|
// packages/ui/react-ui-editor/src/extensions/selection.ts
|
2056
2195
|
import { Transaction } from "@codemirror/state";
|
2057
|
-
import { EditorView as
|
2196
|
+
import { EditorView as EditorView9, keymap as keymap4 } from "@codemirror/view";
|
2058
2197
|
import { debounce } from "@dxos/async";
|
2059
2198
|
import { invariant as invariant3 } from "@dxos/invariant";
|
2060
2199
|
import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
@@ -2065,7 +2204,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
2065
2204
|
return {
|
2066
2205
|
selection,
|
2067
2206
|
scrollIntoView: !scrollTo,
|
2068
|
-
effects: scrollTo ?
|
2207
|
+
effects: scrollTo ? EditorView9.scrollIntoView(scrollTo, {
|
2069
2208
|
yMargin: 96
|
2070
2209
|
}) : void 0,
|
2071
2210
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
@@ -2107,7 +2246,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
2107
2246
|
// setStateDebounced(id, {});
|
2108
2247
|
// },
|
2109
2248
|
// }),
|
2110
|
-
|
2249
|
+
EditorView9.updateListener.of(({ view, transactions }) => {
|
2111
2250
|
const id = view.state.facet(documentId);
|
2112
2251
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
2113
2252
|
return;
|
@@ -2150,7 +2289,7 @@ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src
|
|
2150
2289
|
var setComments = StateEffect3.define();
|
2151
2290
|
var setSelection = StateEffect3.define();
|
2152
2291
|
var setCommentState = StateEffect3.define();
|
2153
|
-
var commentsState =
|
2292
|
+
var commentsState = StateField5.define({
|
2154
2293
|
create: (state) => ({
|
2155
2294
|
id: state.facet(documentId),
|
2156
2295
|
comments: [],
|
@@ -2188,7 +2327,7 @@ var commentsState = StateField4.define({
|
|
2188
2327
|
return value;
|
2189
2328
|
}
|
2190
2329
|
});
|
2191
|
-
var styles3 =
|
2330
|
+
var styles3 = EditorView10.theme({
|
2192
2331
|
".cm-comment, .cm-comment-current": {
|
2193
2332
|
margin: "0 -3px",
|
2194
2333
|
padding: "3px",
|
@@ -2201,14 +2340,14 @@ var styles3 = EditorView9.theme({
|
|
2201
2340
|
textDecoration: "underline"
|
2202
2341
|
}
|
2203
2342
|
});
|
2204
|
-
var createCommentMark = (id, isCurrent) =>
|
2343
|
+
var createCommentMark = (id, isCurrent) => Decoration5.mark({
|
2205
2344
|
class: isCurrent ? "cm-comment-current" : "cm-comment",
|
2206
2345
|
attributes: {
|
2207
2346
|
"data-testid": "cm-comment",
|
2208
2347
|
"data-comment-id": id
|
2209
2348
|
}
|
2210
2349
|
});
|
2211
|
-
var commentsDecorations =
|
2350
|
+
var commentsDecorations = EditorView10.decorations.compute([
|
2212
2351
|
commentsState
|
2213
2352
|
], (state) => {
|
2214
2353
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
@@ -2228,10 +2367,10 @@ var commentsDecorations = EditorView9.decorations.compute([
|
|
2228
2367
|
const mark = createCommentMark(comment.comment.id, comment.comment.id === current);
|
2229
2368
|
return mark.range(range.from, range.to);
|
2230
2369
|
}).filter(isNonNullable);
|
2231
|
-
return
|
2370
|
+
return Decoration5.set(decorations);
|
2232
2371
|
});
|
2233
2372
|
var commentClickedEffect = StateEffect3.define();
|
2234
|
-
var handleCommentClick =
|
2373
|
+
var handleCommentClick = EditorView10.domEventHandlers({
|
2235
2374
|
click: (event, view) => {
|
2236
2375
|
let target = event.target;
|
2237
2376
|
const editorRoot = view.dom;
|
@@ -2270,7 +2409,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2270
2409
|
}
|
2271
2410
|
};
|
2272
2411
|
return [
|
2273
|
-
|
2412
|
+
EditorView10.domEventHandlers({
|
2274
2413
|
cut: handleTrack,
|
2275
2414
|
copy: handleTrack
|
2276
2415
|
}),
|
@@ -2292,7 +2431,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2292
2431
|
return effects;
|
2293
2432
|
}),
|
2294
2433
|
// Handle paste or the undo of comment deletion.
|
2295
|
-
|
2434
|
+
EditorView10.updateListener.of((update2) => {
|
2296
2435
|
const restore = [];
|
2297
2436
|
for (let i = 0; i < update2.transactions.length; i++) {
|
2298
2437
|
const tr = update2.transactions[i];
|
@@ -2432,7 +2571,7 @@ var comments = (options = {}) => {
|
|
2432
2571
|
//
|
2433
2572
|
// Track deleted ranges and update ranges for decorations.
|
2434
2573
|
//
|
2435
|
-
|
2574
|
+
EditorView10.updateListener.of(({ view, state, changes }) => {
|
2436
2575
|
let mod = false;
|
2437
2576
|
const { comments: comments2, ...value } = state.field(commentsState);
|
2438
2577
|
changes.iterChanges((from, to, from2, to2) => {
|
@@ -2464,7 +2603,7 @@ var comments = (options = {}) => {
|
|
2464
2603
|
//
|
2465
2604
|
// Track selection/proximity.
|
2466
2605
|
//
|
2467
|
-
|
2606
|
+
EditorView10.updateListener.of(({ view, state }) => {
|
2468
2607
|
let min = Infinity;
|
2469
2608
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
2470
2609
|
const { head } = state.selection.main;
|
@@ -2518,7 +2657,7 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2518
2657
|
anchor: range.from
|
2519
2658
|
} : void 0,
|
2520
2659
|
effects: [
|
2521
|
-
needsScroll ?
|
2660
|
+
needsScroll ? EditorView10.scrollIntoView(range.from, center ? {
|
2522
2661
|
y: "center"
|
2523
2662
|
} : void 0) : [],
|
2524
2663
|
needsSelectionUpdate ? setSelection.of({
|
@@ -2564,13 +2703,13 @@ var ExternalCommentSync = class {
|
|
2564
2703
|
this.unsubscribe = subscribe(updateComments);
|
2565
2704
|
}
|
2566
2705
|
};
|
2567
|
-
var createExternalCommentSync = (id, subscribe, getComments) =>
|
2706
|
+
var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin5.fromClass(class {
|
2568
2707
|
constructor(view) {
|
2569
2708
|
return new ExternalCommentSync(view, id, subscribe, getComments);
|
2570
2709
|
}
|
2571
2710
|
});
|
2572
2711
|
var useCommentState = (state) => {
|
2573
|
-
return useMemo2(() =>
|
2712
|
+
return useMemo2(() => EditorView10.updateListener.of((update2) => {
|
2574
2713
|
if (update2.docChanged || update2.selectionSet) {
|
2575
2714
|
state.comment = selectionOverlapsComment(update2.state);
|
2576
2715
|
state.selection = hasActiveSelection(update2.state);
|
@@ -2594,7 +2733,7 @@ var useComments = (view, id, comments2) => {
|
|
2594
2733
|
});
|
2595
2734
|
};
|
2596
2735
|
var useCommentClickListener = (onCommentClick) => {
|
2597
|
-
return useMemo2(() =>
|
2736
|
+
return useMemo2(() => EditorView10.updateListener.of((update2) => {
|
2598
2737
|
update2.transactions.forEach((transaction) => {
|
2599
2738
|
transaction.effects.forEach((effect) => {
|
2600
2739
|
if (effect.is(commentClickedEffect)) {
|
@@ -2608,21 +2747,21 @@ var useCommentClickListener = (onCommentClick) => {
|
|
2608
2747
|
};
|
2609
2748
|
|
2610
2749
|
// packages/ui/react-ui-editor/src/extensions/debug.ts
|
2611
|
-
import { syntaxTree } from "@codemirror/language";
|
2612
|
-
import { StateField as
|
2750
|
+
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
2751
|
+
import { StateField as StateField6 } from "@codemirror/state";
|
2613
2752
|
var debugNodeLogger = (log8 = console.log) => {
|
2614
|
-
const logTokens = (state) =>
|
2753
|
+
const logTokens = (state) => syntaxTree2(state).iterate({
|
2615
2754
|
enter: (node) => log8(node.type)
|
2616
2755
|
});
|
2617
|
-
return
|
2756
|
+
return StateField6.define({
|
2618
2757
|
create: (state) => logTokens(state),
|
2619
2758
|
update: (_, tr) => logTokens(tr.state)
|
2620
2759
|
});
|
2621
2760
|
};
|
2622
2761
|
|
2623
2762
|
// packages/ui/react-ui-editor/src/extensions/dnd.ts
|
2624
|
-
import { dropCursor, EditorView as
|
2625
|
-
var styles4 =
|
2763
|
+
import { dropCursor, EditorView as EditorView11 } from "@codemirror/view";
|
2764
|
+
var styles4 = EditorView11.theme({
|
2626
2765
|
".cm-dropCursor": {
|
2627
2766
|
borderLeft: "2px solid var(--dx-accentText)",
|
2628
2767
|
color: "var(--dx-accentText)",
|
@@ -2636,7 +2775,7 @@ var dropFile = (options = {}) => {
|
|
2636
2775
|
return [
|
2637
2776
|
styles4,
|
2638
2777
|
dropCursor(),
|
2639
|
-
|
2778
|
+
EditorView11.domEventHandlers({
|
2640
2779
|
drop: (event, view) => {
|
2641
2780
|
event.preventDefault();
|
2642
2781
|
const files = event.dataTransfer?.files;
|
@@ -2663,7 +2802,7 @@ import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@cod
|
|
2663
2802
|
import { searchKeymap } from "@codemirror/search";
|
2664
2803
|
import { EditorState } from "@codemirror/state";
|
2665
2804
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
2666
|
-
import { EditorView as
|
2805
|
+
import { EditorView as EditorView13, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap6, lineNumbers, placeholder, scrollPastEnd } from "@codemirror/view";
|
2667
2806
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
2668
2807
|
import merge from "lodash.merge";
|
2669
2808
|
import { generateName } from "@dxos/display-name";
|
@@ -2671,10 +2810,10 @@ import { log as log5 } from "@dxos/log";
|
|
2671
2810
|
import { hexToHue, isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
2672
2811
|
|
2673
2812
|
// packages/ui/react-ui-editor/src/extensions/focus.ts
|
2674
|
-
import { StateEffect as StateEffect4, StateField as
|
2675
|
-
import { EditorView as
|
2813
|
+
import { StateEffect as StateEffect4, StateField as StateField7 } from "@codemirror/state";
|
2814
|
+
import { EditorView as EditorView12 } from "@codemirror/view";
|
2676
2815
|
var focusEffect = StateEffect4.define();
|
2677
|
-
var focusField =
|
2816
|
+
var focusField = StateField7.define({
|
2678
2817
|
create: () => false,
|
2679
2818
|
update: (value, tr) => {
|
2680
2819
|
for (const effect of tr.effects) {
|
@@ -2687,7 +2826,7 @@ var focusField = StateField6.define({
|
|
2687
2826
|
});
|
2688
2827
|
var focus = [
|
2689
2828
|
focusField,
|
2690
|
-
|
2829
|
+
EditorView12.domEventHandlers({
|
2691
2830
|
focus: (event, view) => {
|
2692
2831
|
setTimeout(() => view.dispatch({
|
2693
2832
|
effects: focusEffect.of(true)
|
@@ -2709,7 +2848,6 @@ var defaultBasicOptions = {
|
|
2709
2848
|
bracketMatching: true,
|
2710
2849
|
closeBrackets: true,
|
2711
2850
|
drawSelection: true,
|
2712
|
-
editable: true,
|
2713
2851
|
focus: true,
|
2714
2852
|
history: true,
|
2715
2853
|
keymap: "standard",
|
@@ -2726,10 +2864,10 @@ var createBasicExtensions = (_props) => {
|
|
2726
2864
|
const props = defaultsDeep2({}, _props, defaultBasicOptions);
|
2727
2865
|
return [
|
2728
2866
|
// NOTE: Doesn't catch errors in keymap functions.
|
2729
|
-
|
2867
|
+
EditorView13.exceptionSink.of((err) => {
|
2730
2868
|
log5.catch(err, void 0, {
|
2731
2869
|
F: __dxlog_file8,
|
2732
|
-
L:
|
2870
|
+
L: 96,
|
2733
2871
|
S: void 0,
|
2734
2872
|
C: (f, a) => f(...a)
|
2735
2873
|
});
|
@@ -2741,16 +2879,14 @@ var createBasicExtensions = (_props) => {
|
|
2741
2879
|
props.drawSelection && drawSelection({
|
2742
2880
|
cursorBlinkRate: 1200
|
2743
2881
|
}),
|
2882
|
+
props.editable !== void 0 && EditorView13.editable.of(props.editable),
|
2744
2883
|
props.focus && focus,
|
2745
2884
|
props.highlightActiveLine && highlightActiveLine(),
|
2746
2885
|
props.history && history(),
|
2747
2886
|
props.lineNumbers && lineNumbers(),
|
2748
|
-
props.lineWrapping &&
|
2887
|
+
props.lineWrapping && EditorView13.lineWrapping,
|
2749
2888
|
props.placeholder && placeholder(props.placeholder),
|
2750
|
-
props.
|
2751
|
-
EditorState.readOnly.of(true),
|
2752
|
-
EditorView12.editable.of(false)
|
2753
|
-
],
|
2889
|
+
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
2754
2890
|
props.scrollPastEnd && scrollPastEnd(),
|
2755
2891
|
props.tabSize && EditorState.tabSize.of(props.tabSize),
|
2756
2892
|
// https://codemirror.net/docs/ref/#view.KeyBinding
|
@@ -2785,14 +2921,14 @@ var defaultThemeSlots = {
|
|
2785
2921
|
var createThemeExtensions = ({ themeMode, styles: styles5, syntaxHighlighting: _syntaxHighlighting, slots: _slots } = {}) => {
|
2786
2922
|
const slots = defaultsDeep2({}, _slots, defaultThemeSlots);
|
2787
2923
|
return [
|
2788
|
-
|
2789
|
-
|
2924
|
+
EditorView13.darkTheme.of(themeMode === "dark"),
|
2925
|
+
EditorView13.baseTheme(styles5 ? merge({}, defaultTheme, styles5) : defaultTheme),
|
2790
2926
|
// https://github.com/codemirror/theme-one-dark
|
2791
2927
|
_syntaxHighlighting && (themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)),
|
2792
|
-
slots.editor?.className &&
|
2928
|
+
slots.editor?.className && EditorView13.editorAttributes.of({
|
2793
2929
|
class: slots.editor.className
|
2794
2930
|
}),
|
2795
|
-
slots.content?.className &&
|
2931
|
+
slots.content?.className && EditorView13.contentAttributes.of({
|
2796
2932
|
class: slots.content.className
|
2797
2933
|
})
|
2798
2934
|
].filter(isNotFalsy3);
|
@@ -2821,7 +2957,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2821
2957
|
|
2822
2958
|
// packages/ui/react-ui-editor/src/extensions/folding.tsx
|
2823
2959
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
2824
|
-
import { EditorView as
|
2960
|
+
import { EditorView as EditorView14 } from "@codemirror/view";
|
2825
2961
|
import React3 from "react";
|
2826
2962
|
import { Icon } from "@dxos/react-ui";
|
2827
2963
|
var folding = (_props = {}) => [
|
@@ -2845,7 +2981,7 @@ var folding = (_props = {}) => [
|
|
2845
2981
|
}));
|
2846
2982
|
}
|
2847
2983
|
}),
|
2848
|
-
|
2984
|
+
EditorView14.theme({
|
2849
2985
|
".cm-foldGutter": {
|
2850
2986
|
opacity: 0.3,
|
2851
2987
|
transition: "opacity 0.3s",
|
@@ -2858,14 +2994,14 @@ var folding = (_props = {}) => [
|
|
2858
2994
|
];
|
2859
2995
|
|
2860
2996
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
2861
|
-
import { EditorView as
|
2997
|
+
import { EditorView as EditorView15 } from "@codemirror/view";
|
2862
2998
|
var listener = ({ onFocus, onChange }) => {
|
2863
2999
|
const extensions = [];
|
2864
|
-
onFocus && extensions.push(
|
3000
|
+
onFocus && extensions.push(EditorView15.focusChangeEffect.of((_, focusing) => {
|
2865
3001
|
onFocus(focusing);
|
2866
3002
|
return null;
|
2867
3003
|
}));
|
2868
|
-
onChange && extensions.push(
|
3004
|
+
onChange && extensions.push(EditorView15.updateListener.of((update2) => {
|
2869
3005
|
onChange(update2.state.doc.toString(), update2.state.facet(documentId));
|
2870
3006
|
}));
|
2871
3007
|
return extensions;
|
@@ -2873,9 +3009,9 @@ var listener = ({ onFocus, onChange }) => {
|
|
2873
3009
|
|
2874
3010
|
// packages/ui/react-ui-editor/src/extensions/markdown/formatting.ts
|
2875
3011
|
import { snippet } from "@codemirror/autocomplete";
|
2876
|
-
import { syntaxTree as
|
3012
|
+
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
2877
3013
|
import { EditorSelection } from "@codemirror/state";
|
2878
|
-
import { EditorView as
|
3014
|
+
import { EditorView as EditorView16, keymap as keymap7 } from "@codemirror/view";
|
2879
3015
|
import { useMemo as useMemo3 } from "react";
|
2880
3016
|
var formattingEquals = (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;
|
2881
3017
|
var Inline;
|
@@ -2898,7 +3034,7 @@ var setHeading = (level) => {
|
|
2898
3034
|
let prevBlock = -1;
|
2899
3035
|
for (const range of ranges) {
|
2900
3036
|
let sawBlock = false;
|
2901
|
-
|
3037
|
+
syntaxTree3(state).iterate({
|
2902
3038
|
from: range.from,
|
2903
3039
|
to: range.to,
|
2904
3040
|
enter: (node) => {
|
@@ -3007,7 +3143,7 @@ var setStyle = (type, enable) => {
|
|
3007
3143
|
let startCovered = false;
|
3008
3144
|
let endCovered = false;
|
3009
3145
|
let { from, to } = range;
|
3010
|
-
|
3146
|
+
syntaxTree3(state).iterate({
|
3011
3147
|
from,
|
3012
3148
|
to,
|
3013
3149
|
enter: (node) => {
|
@@ -3210,7 +3346,7 @@ var insertTable = (view) => {
|
|
3210
3346
|
snippets.table(view, null, from, from);
|
3211
3347
|
};
|
3212
3348
|
var removeLinkInner = (from, to, changes, state) => {
|
3213
|
-
|
3349
|
+
syntaxTree3(state).iterate({
|
3214
3350
|
from,
|
3215
3351
|
to,
|
3216
3352
|
enter: (node) => {
|
@@ -3255,7 +3391,7 @@ var addLink = ({ url, image: image2 } = {}) => {
|
|
3255
3391
|
let { from, to } = range;
|
3256
3392
|
const cutStyles = [];
|
3257
3393
|
let okay = null;
|
3258
|
-
|
3394
|
+
syntaxTree3(state).iterate({
|
3259
3395
|
from,
|
3260
3396
|
to,
|
3261
3397
|
enter: (node) => {
|
@@ -3350,7 +3486,7 @@ var addList = (type) => {
|
|
3350
3486
|
let parentColumn = null;
|
3351
3487
|
const blocks = [];
|
3352
3488
|
for (const { from, to } of state.selection.ranges) {
|
3353
|
-
|
3489
|
+
syntaxTree3(state).iterate({
|
3354
3490
|
from,
|
3355
3491
|
to,
|
3356
3492
|
enter: (node) => {
|
@@ -3485,7 +3621,7 @@ var removeList = (type) => {
|
|
3485
3621
|
const stack = [];
|
3486
3622
|
const targetNodeType = type === 0 ? "OrderedList" : type === 1 ? "BulletList" : "TaskList";
|
3487
3623
|
for (const { from, to } of state.selection.ranges) {
|
3488
|
-
|
3624
|
+
syntaxTree3(state).iterate({
|
3489
3625
|
from,
|
3490
3626
|
to,
|
3491
3627
|
enter: (node) => {
|
@@ -3572,7 +3708,7 @@ var setBlockquote = (enable) => {
|
|
3572
3708
|
let lastBlock = -1;
|
3573
3709
|
for (const { from, to } of state.selection.ranges) {
|
3574
3710
|
const sawBlock = false;
|
3575
|
-
|
3711
|
+
syntaxTree3(state).iterate({
|
3576
3712
|
from,
|
3577
3713
|
to,
|
3578
3714
|
enter: (node) => {
|
@@ -3662,7 +3798,7 @@ var addCodeblock = (target) => {
|
|
3662
3798
|
for (const { from, to } of selection.ranges) {
|
3663
3799
|
let blockFrom = from;
|
3664
3800
|
let blockTo = to;
|
3665
|
-
|
3801
|
+
syntaxTree3(state).iterate({
|
3666
3802
|
from,
|
3667
3803
|
to,
|
3668
3804
|
enter: (node) => {
|
@@ -3713,7 +3849,7 @@ var removeCodeblock = ({ state, dispatch }) => {
|
|
3713
3849
|
let lastBlock = -1;
|
3714
3850
|
const changes = [];
|
3715
3851
|
for (const { from, to } of state.selection.ranges) {
|
3716
|
-
|
3852
|
+
syntaxTree3(state).iterate({
|
3717
3853
|
from,
|
3718
3854
|
to,
|
3719
3855
|
enter: (node) => {
|
@@ -3875,7 +4011,7 @@ var getFormatting = (state) => {
|
|
3875
4011
|
}
|
3876
4012
|
}
|
3877
4013
|
}
|
3878
|
-
|
4014
|
+
syntaxTree3(state).iterate({
|
3879
4015
|
from: range.from,
|
3880
4016
|
to: range.to,
|
3881
4017
|
enter: (node) => {
|
@@ -3964,7 +4100,7 @@ var getFormatting = (state) => {
|
|
3964
4100
|
};
|
3965
4101
|
};
|
3966
4102
|
var useFormattingState = (state) => {
|
3967
|
-
return useMemo3(() =>
|
4103
|
+
return useMemo3(() => EditorView16.updateListener.of((update2) => {
|
3968
4104
|
if (update2.docChanged || update2.selectionSet) {
|
3969
4105
|
Object.entries(getFormatting(update2.state)).forEach(([key, active]) => {
|
3970
4106
|
state[key] = active;
|
@@ -4247,9 +4383,9 @@ var createMarkdownExtensions = ({ themeMode } = {}) => {
|
|
4247
4383
|
};
|
4248
4384
|
|
4249
4385
|
// packages/ui/react-ui-editor/src/extensions/markdown/debug.ts
|
4250
|
-
import { syntaxTree as
|
4251
|
-
import { StateField as
|
4252
|
-
var debugTree = (cb) =>
|
4386
|
+
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
4387
|
+
import { StateField as StateField8 } from "@codemirror/state";
|
4388
|
+
var debugTree = (cb) => StateField8.define({
|
4253
4389
|
create: (state) => cb(convertTreeToJson(state)),
|
4254
4390
|
update: (value, tr) => cb(convertTreeToJson(tr.state))
|
4255
4391
|
});
|
@@ -4270,24 +4406,24 @@ var convertTreeToJson = (state) => {
|
|
4270
4406
|
}
|
4271
4407
|
return node;
|
4272
4408
|
};
|
4273
|
-
return treeToJson(
|
4409
|
+
return treeToJson(syntaxTree4(state).cursor());
|
4274
4410
|
};
|
4275
4411
|
|
4276
4412
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
4277
|
-
import { syntaxTree as
|
4278
|
-
import { RangeSetBuilder as
|
4279
|
-
import { EditorView as
|
4413
|
+
import { syntaxTree as syntaxTree8 } from "@codemirror/language";
|
4414
|
+
import { RangeSetBuilder as RangeSetBuilder4, StateEffect as StateEffect5 } from "@codemirror/state";
|
4415
|
+
import { EditorView as EditorView20, Decoration as Decoration8, WidgetType as WidgetType6, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
4280
4416
|
import { invariant as invariant4 } from "@dxos/invariant";
|
4281
4417
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
4282
4418
|
|
4283
4419
|
// packages/ui/react-ui-editor/src/extensions/markdown/changes.ts
|
4284
|
-
import { syntaxTree as
|
4420
|
+
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
4285
4421
|
import { Transaction as Transaction2 } from "@codemirror/state";
|
4286
|
-
import { ViewPlugin as
|
4422
|
+
import { ViewPlugin as ViewPlugin6 } from "@codemirror/view";
|
4287
4423
|
var adjustChanges = () => {
|
4288
|
-
return
|
4424
|
+
return ViewPlugin6.fromClass(class {
|
4289
4425
|
update(update2) {
|
4290
|
-
const tree =
|
4426
|
+
const tree = syntaxTree5(update2.state);
|
4291
4427
|
const adjustments = [];
|
4292
4428
|
for (const tr of update2.transactions) {
|
4293
4429
|
const event = tr.annotation(Transaction2.userEvent);
|
@@ -4425,14 +4561,14 @@ var getValidUrl = (str) => {
|
|
4425
4561
|
};
|
4426
4562
|
|
4427
4563
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
4428
|
-
import { syntaxTree as
|
4429
|
-
import { StateField as
|
4430
|
-
import { Decoration as
|
4564
|
+
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
4565
|
+
import { StateField as StateField9 } from "@codemirror/state";
|
4566
|
+
import { Decoration as Decoration6, EditorView as EditorView17, WidgetType as WidgetType4 } from "@codemirror/view";
|
4431
4567
|
var image = (_options = {}) => {
|
4432
4568
|
return [
|
4433
|
-
|
4569
|
+
StateField9.define({
|
4434
4570
|
create: (state) => {
|
4435
|
-
return
|
4571
|
+
return Decoration6.set(buildDecorations2(0, state.doc.length, state));
|
4436
4572
|
},
|
4437
4573
|
update: (value, tr) => {
|
4438
4574
|
if (!tr.docChanged && !tr.selection) {
|
@@ -4452,10 +4588,10 @@ var image = (_options = {}) => {
|
|
4452
4588
|
filterFrom: from,
|
4453
4589
|
filterTo: to,
|
4454
4590
|
filter: () => false,
|
4455
|
-
add:
|
4591
|
+
add: buildDecorations2(from, to, tr.state)
|
4456
4592
|
});
|
4457
4593
|
},
|
4458
|
-
provide: (field) =>
|
4594
|
+
provide: (field) => EditorView17.decorations.from(field)
|
4459
4595
|
})
|
4460
4596
|
];
|
4461
4597
|
};
|
@@ -4467,10 +4603,10 @@ var preloadImage = (url) => {
|
|
4467
4603
|
preloaded.add(url);
|
4468
4604
|
}
|
4469
4605
|
};
|
4470
|
-
var
|
4606
|
+
var buildDecorations2 = (from, to, state) => {
|
4471
4607
|
const decorations = [];
|
4472
4608
|
const cursor = state.selection.main.head;
|
4473
|
-
|
4609
|
+
syntaxTree6(state).iterate({
|
4474
4610
|
enter: (node) => {
|
4475
4611
|
if (node.name === "Image") {
|
4476
4612
|
const urlNode = node.node.getChild("URL");
|
@@ -4481,7 +4617,7 @@ var buildDecorations = (from, to, state) => {
|
|
4481
4617
|
return;
|
4482
4618
|
}
|
4483
4619
|
preloadImage(url);
|
4484
|
-
decorations.push(
|
4620
|
+
decorations.push(Decoration6.replace({
|
4485
4621
|
block: true,
|
4486
4622
|
widget: new ImageWidget(url)
|
4487
4623
|
}).range(hide2 ? node.from : node.to, node.to));
|
@@ -4493,7 +4629,7 @@ var buildDecorations = (from, to, state) => {
|
|
4493
4629
|
});
|
4494
4630
|
return decorations;
|
4495
4631
|
};
|
4496
|
-
var ImageWidget = class extends
|
4632
|
+
var ImageWidget = class extends WidgetType4 {
|
4497
4633
|
constructor(_url) {
|
4498
4634
|
super();
|
4499
4635
|
this._url = _url;
|
@@ -4515,10 +4651,10 @@ var ImageWidget = class extends WidgetType3 {
|
|
4515
4651
|
};
|
4516
4652
|
|
4517
4653
|
// packages/ui/react-ui-editor/src/extensions/markdown/styles.ts
|
4518
|
-
import { EditorView as
|
4654
|
+
import { EditorView as EditorView18 } from "@codemirror/view";
|
4519
4655
|
var bulletListIndentationWidth = 24;
|
4520
4656
|
var orderedListIndentationWidth = 36;
|
4521
|
-
var formattingStyles =
|
4657
|
+
var formattingStyles = EditorView18.theme({
|
4522
4658
|
/**
|
4523
4659
|
* Horizontal rule.
|
4524
4660
|
*/
|
@@ -4637,18 +4773,18 @@ var formattingStyles = EditorView17.theme({
|
|
4637
4773
|
});
|
4638
4774
|
|
4639
4775
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
4640
|
-
import { syntaxTree as
|
4641
|
-
import { RangeSetBuilder as
|
4642
|
-
import { Decoration as
|
4776
|
+
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4777
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField10 } from "@codemirror/state";
|
4778
|
+
import { Decoration as Decoration7, EditorView as EditorView19, WidgetType as WidgetType5 } from "@codemirror/view";
|
4643
4779
|
var table = (options = {}) => {
|
4644
|
-
return
|
4780
|
+
return StateField10.define({
|
4645
4781
|
create: (state) => update(state, options),
|
4646
4782
|
update: (_, tr) => update(tr.state, options),
|
4647
|
-
provide: (field) =>
|
4783
|
+
provide: (field) => EditorView19.decorations.from(field)
|
4648
4784
|
});
|
4649
4785
|
};
|
4650
4786
|
var update = (state, _options) => {
|
4651
|
-
const builder = new
|
4787
|
+
const builder = new RangeSetBuilder3();
|
4652
4788
|
const cursor = state.selection.main.head;
|
4653
4789
|
const tables = [];
|
4654
4790
|
const getTable = () => tables[tables.length - 1];
|
@@ -4656,7 +4792,7 @@ var update = (state, _options) => {
|
|
4656
4792
|
const table2 = getTable();
|
4657
4793
|
return table2.rows?.[table2.rows.length - 1];
|
4658
4794
|
};
|
4659
|
-
|
4795
|
+
syntaxTree7(state).iterate({
|
4660
4796
|
enter: (node) => {
|
4661
4797
|
switch (node.name) {
|
4662
4798
|
case "Table": {
|
@@ -4689,19 +4825,19 @@ var update = (state, _options) => {
|
|
4689
4825
|
tables.forEach((table2) => {
|
4690
4826
|
const replace = state.readOnly || cursor < table2.from || cursor > table2.to;
|
4691
4827
|
if (replace) {
|
4692
|
-
builder.add(table2.from, table2.to,
|
4828
|
+
builder.add(table2.from, table2.to, Decoration7.replace({
|
4693
4829
|
block: true,
|
4694
4830
|
widget: new TableWidget(table2)
|
4695
4831
|
}));
|
4696
4832
|
} else {
|
4697
|
-
builder.add(table2.from, table2.to,
|
4833
|
+
builder.add(table2.from, table2.to, Decoration7.mark({
|
4698
4834
|
class: "cm-table"
|
4699
4835
|
}));
|
4700
4836
|
}
|
4701
4837
|
});
|
4702
4838
|
return builder.finish();
|
4703
4839
|
};
|
4704
|
-
var TableWidget = class extends
|
4840
|
+
var TableWidget = class extends WidgetType5 {
|
4705
4841
|
constructor(_table) {
|
4706
4842
|
super();
|
4707
4843
|
this._table = _table;
|
@@ -4743,14 +4879,14 @@ var Unicode = {
|
|
4743
4879
|
bulletSmall: "\u2219",
|
4744
4880
|
bulletSquare: "\u2B1D"
|
4745
4881
|
};
|
4746
|
-
var HorizontalRuleWidget = class extends
|
4882
|
+
var HorizontalRuleWidget = class extends WidgetType6 {
|
4747
4883
|
toDOM() {
|
4748
4884
|
const el = document.createElement("span");
|
4749
4885
|
el.className = "cm-hr";
|
4750
4886
|
return el;
|
4751
4887
|
}
|
4752
4888
|
};
|
4753
|
-
var LinkButton = class extends
|
4889
|
+
var LinkButton = class extends WidgetType6 {
|
4754
4890
|
constructor(url, render) {
|
4755
4891
|
super();
|
4756
4892
|
this.url = url;
|
@@ -4766,7 +4902,7 @@ var LinkButton = class extends WidgetType5 {
|
|
4766
4902
|
return el;
|
4767
4903
|
}
|
4768
4904
|
};
|
4769
|
-
var CheckboxWidget = class extends
|
4905
|
+
var CheckboxWidget = class extends WidgetType6 {
|
4770
4906
|
constructor(_checked) {
|
4771
4907
|
super();
|
4772
4908
|
this._checked = _checked;
|
@@ -4811,7 +4947,7 @@ var CheckboxWidget = class extends WidgetType5 {
|
|
4811
4947
|
return false;
|
4812
4948
|
}
|
4813
4949
|
};
|
4814
|
-
var TextWidget = class extends
|
4950
|
+
var TextWidget = class extends WidgetType6 {
|
4815
4951
|
constructor(text, className) {
|
4816
4952
|
super();
|
4817
4953
|
this.text = text;
|
@@ -4826,29 +4962,29 @@ var TextWidget = class extends WidgetType5 {
|
|
4826
4962
|
return el;
|
4827
4963
|
}
|
4828
4964
|
};
|
4829
|
-
var hide =
|
4830
|
-
var blockQuote =
|
4965
|
+
var hide = Decoration8.replace({});
|
4966
|
+
var blockQuote = Decoration8.line({
|
4831
4967
|
class: mx4("cm-blockquote")
|
4832
4968
|
});
|
4833
|
-
var fencedCodeLine =
|
4969
|
+
var fencedCodeLine = Decoration8.line({
|
4834
4970
|
class: mx4("cm-code cm-codeblock-line")
|
4835
4971
|
});
|
4836
|
-
var fencedCodeLineFirst =
|
4972
|
+
var fencedCodeLineFirst = Decoration8.line({
|
4837
4973
|
class: mx4("cm-code cm-codeblock-line", "cm-codeblock-first")
|
4838
4974
|
});
|
4839
|
-
var fencedCodeLineLast =
|
4975
|
+
var fencedCodeLineLast = Decoration8.line({
|
4840
4976
|
class: mx4("cm-code cm-codeblock-line", "cm-codeblock-last")
|
4841
4977
|
});
|
4842
4978
|
var commentBlockLine = fencedCodeLine;
|
4843
4979
|
var commentBlockLineFirst = fencedCodeLineFirst;
|
4844
4980
|
var commentBlockLineLast = fencedCodeLineLast;
|
4845
|
-
var horizontalRule =
|
4981
|
+
var horizontalRule = Decoration8.replace({
|
4846
4982
|
widget: new HorizontalRuleWidget()
|
4847
4983
|
});
|
4848
|
-
var checkedTask =
|
4984
|
+
var checkedTask = Decoration8.replace({
|
4849
4985
|
widget: new CheckboxWidget(true)
|
4850
4986
|
});
|
4851
|
-
var uncheckedTask =
|
4987
|
+
var uncheckedTask = Decoration8.replace({
|
4852
4988
|
widget: new CheckboxWidget(false)
|
4853
4989
|
});
|
4854
4990
|
var editingRange = (state, range, focus2) => {
|
@@ -4863,9 +4999,9 @@ var autoHideTags = /* @__PURE__ */ new Set([
|
|
4863
4999
|
"SubscriptMark",
|
4864
5000
|
"SuperscriptMark"
|
4865
5001
|
]);
|
4866
|
-
var
|
4867
|
-
const deco = new
|
4868
|
-
const atomicDeco = new
|
5002
|
+
var buildDecorations3 = (view, options, focus2) => {
|
5003
|
+
const deco = new RangeSetBuilder4();
|
5004
|
+
const atomicDeco = new RangeSetBuilder4();
|
4869
5005
|
const { state } = view;
|
4870
5006
|
const headerLevels = [];
|
4871
5007
|
const getHeaderLevels = (node, level) => {
|
@@ -4952,7 +5088,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4952
5088
|
} else {
|
4953
5089
|
const num = headers.slice(from - 1).map((level2) => level2?.number ?? 0).join(".") + " ";
|
4954
5090
|
if (num.length) {
|
4955
|
-
atomicDeco.add(mark.from, mark.from + len,
|
5091
|
+
atomicDeco.add(mark.from, mark.from + len, Decoration8.replace({
|
4956
5092
|
widget: new TextWidget(num, theme.heading(level))
|
4957
5093
|
}));
|
4958
5094
|
}
|
@@ -4977,7 +5113,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4977
5113
|
if (node.from === line.to - 1) {
|
4978
5114
|
return false;
|
4979
5115
|
}
|
4980
|
-
deco.add(line.from, line.from,
|
5116
|
+
deco.add(line.from, line.from, Decoration8.line({
|
4981
5117
|
class: "cm-list-item",
|
4982
5118
|
attributes: {
|
4983
5119
|
style: `padding-left: ${offset}px; text-indent: -${width}px;`
|
@@ -4994,7 +5130,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4994
5130
|
const label = list.type === "OrderedList" ? `${++list.number}.` : Unicode.bulletSmall;
|
4995
5131
|
const line = state.doc.lineAt(node.from);
|
4996
5132
|
const to = state.doc.sliceString(node.to, node.to + 1) === " " ? node.to + 1 : node.to;
|
4997
|
-
atomicDeco.add(line.from, to,
|
5133
|
+
atomicDeco.add(line.from, to, Decoration8.replace({
|
4998
5134
|
widget: new TextWidget(label, list.type === "OrderedList" ? "cm-list-mark cm-list-mark-ordered" : "cm-list-mark cm-list-mark-bullet")
|
4999
5135
|
}));
|
5000
5136
|
break;
|
@@ -5081,7 +5217,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5081
5217
|
if (!editing) {
|
5082
5218
|
atomicDeco.add(node.from, marks[0].to, hide);
|
5083
5219
|
}
|
5084
|
-
deco.add(marks[0].to, marks[1].from,
|
5220
|
+
deco.add(marks[0].to, marks[1].from, Decoration8.mark({
|
5085
5221
|
tagName: "a",
|
5086
5222
|
attributes: {
|
5087
5223
|
class: "cm-link",
|
@@ -5091,7 +5227,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5091
5227
|
}
|
5092
5228
|
}));
|
5093
5229
|
if (!editing) {
|
5094
|
-
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ?
|
5230
|
+
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ? Decoration8.replace({
|
5095
5231
|
widget: new LinkButton(url, options.renderLinkButton)
|
5096
5232
|
}) : hide);
|
5097
5233
|
}
|
@@ -5125,7 +5261,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5125
5261
|
}
|
5126
5262
|
}
|
5127
5263
|
};
|
5128
|
-
const tree =
|
5264
|
+
const tree = syntaxTree8(state);
|
5129
5265
|
if (options.numberedHeadings?.from === void 0) {
|
5130
5266
|
for (const { from, to } of view.visibleRanges) {
|
5131
5267
|
tree.iterate({
|
@@ -5149,13 +5285,13 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5149
5285
|
var forceUpdate = StateEffect5.define();
|
5150
5286
|
var decorateMarkdown = (options = {}) => {
|
5151
5287
|
return [
|
5152
|
-
|
5288
|
+
ViewPlugin7.fromClass(class {
|
5153
5289
|
constructor(view) {
|
5154
|
-
({ deco: this.deco, atomicDeco: this.atomicDeco } =
|
5290
|
+
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations3(view, options, view.hasFocus));
|
5155
5291
|
}
|
5156
5292
|
update(update2) {
|
5157
5293
|
if (update2.docChanged || update2.viewportChanged || update2.focusChanged || update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(forceUpdate))) || update2.selectionSet && !options.selectionChangeDelay) {
|
5158
|
-
({ deco: this.deco, atomicDeco: this.atomicDeco } =
|
5294
|
+
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations3(update2.view, options, update2.view.hasFocus));
|
5159
5295
|
this.clearUpdate();
|
5160
5296
|
} else if (update2.selectionSet) {
|
5161
5297
|
this.scheduleUpdate(update2.view);
|
@@ -5181,9 +5317,9 @@ var decorateMarkdown = (options = {}) => {
|
|
5181
5317
|
}
|
5182
5318
|
}, {
|
5183
5319
|
provide: (plugin) => [
|
5184
|
-
|
5185
|
-
|
5186
|
-
|
5320
|
+
EditorView20.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration8.none),
|
5321
|
+
EditorView20.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration8.none),
|
5322
|
+
EditorView20.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration8.none)
|
5187
5323
|
]
|
5188
5324
|
}),
|
5189
5325
|
image(),
|
@@ -5194,12 +5330,12 @@ var decorateMarkdown = (options = {}) => {
|
|
5194
5330
|
};
|
5195
5331
|
|
5196
5332
|
// packages/ui/react-ui-editor/src/extensions/markdown/link.ts
|
5197
|
-
import { syntaxTree as
|
5333
|
+
import { syntaxTree as syntaxTree9 } from "@codemirror/language";
|
5198
5334
|
import { hoverTooltip as hoverTooltip2 } from "@codemirror/view";
|
5199
5335
|
import { tooltipContent } from "@dxos/react-ui-theme";
|
5200
5336
|
var linkTooltip = (render) => {
|
5201
5337
|
return hoverTooltip2((view, pos, side) => {
|
5202
|
-
const syntax =
|
5338
|
+
const syntax = syntaxTree9(view.state).resolveInner(pos, side);
|
5203
5339
|
let link = null;
|
5204
5340
|
for (let i = 0, node = syntax; !link && node && i < 5; node = node.parent, i++) {
|
5205
5341
|
link = node.name === "Link" ? node : null;
|
@@ -5380,7 +5516,7 @@ var useActionHandler = (view) => {
|
|
5380
5516
|
|
5381
5517
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
5382
5518
|
import { EditorState as EditorState2 } from "@codemirror/state";
|
5383
|
-
import { EditorView as
|
5519
|
+
import { EditorView as EditorView21 } from "@codemirror/view";
|
5384
5520
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
5385
5521
|
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo4, useRef, useState } from "react";
|
5386
5522
|
import { log as log7 } from "@dxos/log";
|
@@ -5424,7 +5560,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5424
5560
|
id && documentId.of(id),
|
5425
5561
|
extensions,
|
5426
5562
|
// NOTE: This doesn't catch errors in keymap functions.
|
5427
|
-
|
5563
|
+
EditorView21.exceptionSink.of((err) => {
|
5428
5564
|
log7.catch(err, void 0, {
|
5429
5565
|
F: __dxlog_file11,
|
5430
5566
|
L: 97,
|
@@ -5434,10 +5570,10 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5434
5570
|
})
|
5435
5571
|
].filter(isNotFalsy4)
|
5436
5572
|
});
|
5437
|
-
view2 = new
|
5573
|
+
view2 = new EditorView21({
|
5438
5574
|
parent: parentRef.current,
|
5439
5575
|
state,
|
5440
|
-
scrollTo: scrollTo ?
|
5576
|
+
scrollTo: scrollTo ? EditorView21.scrollIntoView(scrollTo, {
|
5441
5577
|
yMargin: 96
|
5442
5578
|
}) : void 0,
|
5443
5579
|
dispatchTransactions: debug ? debugDispatcher : void 0
|
@@ -5536,7 +5672,7 @@ export {
|
|
5536
5672
|
EditorInputModes,
|
5537
5673
|
EditorState3 as EditorState,
|
5538
5674
|
EditorToolbar,
|
5539
|
-
|
5675
|
+
EditorView22 as EditorView,
|
5540
5676
|
EditorViewMode,
|
5541
5677
|
EditorViewModes,
|
5542
5678
|
Inline,
|
@@ -5622,7 +5758,7 @@ export {
|
|
5622
5758
|
setStyle,
|
5623
5759
|
singleValueFacet,
|
5624
5760
|
stackItemContentEditorClassNames,
|
5625
|
-
stackItemContentToolbarClassNames,
|
5761
|
+
stackItemContentToolbarClassNames2 as stackItemContentToolbarClassNames,
|
5626
5762
|
table,
|
5627
5763
|
tags2 as tags,
|
5628
5764
|
textRange,
|