@dxos/react-ui-editor 0.8.1-staging.391c573 → 0.8.1-staging.5be625a
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 +111 -119
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +113 -120
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +111 -119
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +1 -0
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/folding.d.ts +2 -8
- package/dist/types/src/extensions/folding.d.ts.map +1 -1
- package/dist/types/src/extensions/selection.d.ts +6 -1
- package/dist/types/src/extensions/selection.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/package.json +27 -27
- package/src/TextEditor.stories.tsx +10 -2
- package/src/extensions/factories.ts +1 -0
- package/src/extensions/folding.tsx +30 -73
- package/src/extensions/selection.ts +41 -21
- package/src/styles/stack-item-content-class-names.ts +1 -1
- package/src/styles/theme.ts +1 -0
- package/src/util/debug.ts +1 -1
@@ -315,7 +315,7 @@ var createViewMode = (state) => {
|
|
315
315
|
|
316
316
|
// packages/ui/react-ui-editor/src/styles/stack-item-content-class-names.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 === "
|
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
319
|
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
320
|
|
321
321
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/EditorToolbar.tsx
|
@@ -522,6 +522,7 @@ var defaultTheme = {
|
|
522
522
|
".cm-link": {
|
523
523
|
textDecorationLine: "underline",
|
524
524
|
textDecorationThickness: "1px",
|
525
|
+
textDecorationColor: "var(--dx-separator)",
|
525
526
|
textUnderlineOffset: "2px",
|
526
527
|
borderRadius: ".125rem"
|
527
528
|
},
|
@@ -749,7 +750,7 @@ var logChanges = (trs) => {
|
|
749
750
|
return changes2;
|
750
751
|
}).filter(Boolean);
|
751
752
|
if (changes.length) {
|
752
|
-
log
|
753
|
+
log("changes", {
|
753
754
|
changes
|
754
755
|
}, {
|
755
756
|
F: __dxlog_file,
|
@@ -2055,6 +2056,9 @@ import { isNonNullable } from "@dxos/util";
|
|
2055
2056
|
import { Transaction } from "@codemirror/state";
|
2056
2057
|
import { EditorView as EditorView8, keymap as keymap4 } from "@codemirror/view";
|
2057
2058
|
import { debounce } from "@dxos/async";
|
2059
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
2060
|
+
import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
2061
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/selection.ts";
|
2058
2062
|
var documentId = singleValueFacet();
|
2059
2063
|
var stateRestoreAnnotation = "dxos.org/cm/state-restore";
|
2060
2064
|
var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
@@ -2067,10 +2071,34 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
2067
2071
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
2068
2072
|
};
|
2069
2073
|
};
|
2070
|
-
var
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
+
var createEditorStateStore = (keyPrefix) => ({
|
2075
|
+
getState: (id) => {
|
2076
|
+
invariant3(id, void 0, {
|
2077
|
+
F: __dxlog_file6,
|
2078
|
+
L: 47,
|
2079
|
+
S: void 0,
|
2080
|
+
A: [
|
2081
|
+
"id",
|
2082
|
+
""
|
2083
|
+
]
|
2084
|
+
});
|
2085
|
+
const state = localStorage.getItem(`${keyPrefix}/${id}`);
|
2086
|
+
return state ? JSON.parse(state) : void 0;
|
2087
|
+
},
|
2088
|
+
setState: (id, state) => {
|
2089
|
+
invariant3(id, void 0, {
|
2090
|
+
F: __dxlog_file6,
|
2091
|
+
L: 53,
|
2092
|
+
S: void 0,
|
2093
|
+
A: [
|
2094
|
+
"id",
|
2095
|
+
""
|
2096
|
+
]
|
2097
|
+
});
|
2098
|
+
localStorage.setItem(`${keyPrefix}/${id}`, JSON.stringify(state));
|
2099
|
+
}
|
2100
|
+
});
|
2101
|
+
var selectionState = ({ getState, setState } = {}) => {
|
2074
2102
|
const setStateDebounced = debounce(setState, 1e3);
|
2075
2103
|
return [
|
2076
2104
|
// TODO(burdon): Track scrolling (currently only updates when cursor moves).
|
@@ -2084,39 +2112,41 @@ var selectionState = (state = {}) => {
|
|
2084
2112
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
2085
2113
|
return;
|
2086
2114
|
}
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
if (pos !== null) {
|
2093
|
-
const { anchor, head } = view.state.selection.main;
|
2094
|
-
setStateDebounced(id, {
|
2095
|
-
scrollTo: pos,
|
2096
|
-
selection: {
|
2097
|
-
anchor,
|
2098
|
-
head
|
2099
|
-
}
|
2115
|
+
if (setState) {
|
2116
|
+
const { scrollTop } = view.scrollDOM;
|
2117
|
+
const pos = view.posAtCoords({
|
2118
|
+
x: 0,
|
2119
|
+
y: scrollTop
|
2100
2120
|
});
|
2121
|
+
if (pos !== null) {
|
2122
|
+
const { anchor, head } = view.state.selection.main;
|
2123
|
+
setStateDebounced(id, {
|
2124
|
+
scrollTo: pos,
|
2125
|
+
selection: {
|
2126
|
+
anchor,
|
2127
|
+
head
|
2128
|
+
}
|
2129
|
+
});
|
2130
|
+
}
|
2101
2131
|
}
|
2102
2132
|
}),
|
2103
|
-
keymap4.of([
|
2133
|
+
getState && keymap4.of([
|
2104
2134
|
{
|
2105
2135
|
key: "ctrl-r",
|
2106
2136
|
run: (view) => {
|
2107
|
-
const
|
2108
|
-
if (
|
2109
|
-
view.dispatch(createEditorStateTransaction(
|
2137
|
+
const state = getState(view.state.facet(documentId));
|
2138
|
+
if (state) {
|
2139
|
+
view.dispatch(createEditorStateTransaction(state));
|
2110
2140
|
}
|
2111
2141
|
return true;
|
2112
2142
|
}
|
2113
2143
|
}
|
2114
2144
|
])
|
2115
|
-
];
|
2145
|
+
].filter(isNotFalsy2);
|
2116
2146
|
};
|
2117
2147
|
|
2118
2148
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
2119
|
-
var
|
2149
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
2120
2150
|
var setComments = StateEffect3.define();
|
2121
2151
|
var setSelection = StateEffect3.define();
|
2122
2152
|
var setCommentState = StateEffect3.define();
|
@@ -2186,7 +2216,7 @@ var commentsDecorations = EditorView9.decorations.compute([
|
|
2186
2216
|
const range = comment.range;
|
2187
2217
|
if (!range) {
|
2188
2218
|
log4.warn("Invalid range:", range, {
|
2189
|
-
F:
|
2219
|
+
F: __dxlog_file7,
|
2190
2220
|
L: 144,
|
2191
2221
|
S: void 0,
|
2192
2222
|
C: (f, a) => f(...a)
|
@@ -2638,7 +2668,7 @@ import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2638
2668
|
import merge from "lodash.merge";
|
2639
2669
|
import { generateName } from "@dxos/display-name";
|
2640
2670
|
import { log as log5 } from "@dxos/log";
|
2641
|
-
import { hexToHue, isNotFalsy as
|
2671
|
+
import { hexToHue, isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
2642
2672
|
|
2643
2673
|
// packages/ui/react-ui-editor/src/extensions/focus.ts
|
2644
2674
|
import { StateEffect as StateEffect4, StateField as StateField6 } from "@codemirror/state";
|
@@ -2672,7 +2702,7 @@ var focus = [
|
|
2672
2702
|
];
|
2673
2703
|
|
2674
2704
|
// packages/ui/react-ui-editor/src/extensions/factories.ts
|
2675
|
-
var
|
2705
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
|
2676
2706
|
var preventNewline = EditorState.transactionFilter.of((tr) => tr.newDoc.lines > 1 ? [] : tr);
|
2677
2707
|
var defaultBasicOptions = {
|
2678
2708
|
allowMultipleSelections: true,
|
@@ -2698,8 +2728,8 @@ var createBasicExtensions = (_props) => {
|
|
2698
2728
|
// NOTE: Doesn't catch errors in keymap functions.
|
2699
2729
|
EditorView12.exceptionSink.of((err) => {
|
2700
2730
|
log5.catch(err, void 0, {
|
2701
|
-
F:
|
2702
|
-
L:
|
2731
|
+
F: __dxlog_file8,
|
2732
|
+
L: 97,
|
2703
2733
|
S: void 0,
|
2704
2734
|
C: (f, a) => f(...a)
|
2705
2735
|
});
|
@@ -2744,8 +2774,8 @@ var createBasicExtensions = (_props) => {
|
|
2744
2774
|
preventDefault: true,
|
2745
2775
|
run: () => true
|
2746
2776
|
}
|
2747
|
-
].filter(
|
2748
|
-
].filter(
|
2777
|
+
].filter(isNotFalsy3))
|
2778
|
+
].filter(isNotFalsy3);
|
2749
2779
|
};
|
2750
2780
|
var defaultThemeSlots = {
|
2751
2781
|
editor: {
|
@@ -2765,7 +2795,7 @@ var createThemeExtensions = ({ themeMode, styles: styles5, syntaxHighlighting: _
|
|
2765
2795
|
slots.content?.className && EditorView12.contentAttributes.of({
|
2766
2796
|
class: slots.content.className
|
2767
2797
|
})
|
2768
|
-
].filter(
|
2798
|
+
].filter(isNotFalsy3);
|
2769
2799
|
};
|
2770
2800
|
var createDataExtensions = ({ id, text, space, identity }) => {
|
2771
2801
|
const extensions = [];
|
@@ -2790,81 +2820,42 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2790
2820
|
};
|
2791
2821
|
|
2792
2822
|
// packages/ui/react-ui-editor/src/extensions/folding.tsx
|
2793
|
-
import { codeFolding, foldGutter
|
2823
|
+
import { codeFolding, foldGutter } from "@codemirror/language";
|
2794
2824
|
import { EditorView as EditorView13 } from "@codemirror/view";
|
2795
2825
|
import React3 from "react";
|
2796
|
-
import { debounce as debounce3 } from "@dxos/async";
|
2797
2826
|
import { Icon } from "@dxos/react-ui";
|
2798
|
-
var folding = (
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
}
|
2809
|
-
}),
|
2810
|
-
foldGutter({
|
2811
|
-
markerDOM: (open) => {
|
2812
|
-
const el = createElement("div", {
|
2813
|
-
className: "flex h-full items-center"
|
2814
|
-
});
|
2815
|
-
return renderRoot(el, /* @__PURE__ */ React3.createElement(Icon, {
|
2816
|
-
icon: "ph--caret-right--regular",
|
2817
|
-
size: 3,
|
2818
|
-
classNames: [
|
2819
|
-
"mx-3 cursor-pointer",
|
2820
|
-
open && "rotate-90"
|
2821
|
-
]
|
2822
|
-
}));
|
2823
|
-
}
|
2824
|
-
}),
|
2825
|
-
EditorView13.theme({
|
2826
|
-
".cm-foldGutter": {
|
2827
|
-
opacity: 0.3,
|
2828
|
-
transition: "opacity 0.3s",
|
2829
|
-
width: "32px"
|
2830
|
-
},
|
2831
|
-
".cm-foldGutter:hover": {
|
2832
|
-
opacity: 1
|
2833
|
-
}
|
2834
|
-
}),
|
2835
|
-
EditorView13.updateListener.of(({ view }) => {
|
2836
|
-
const id = view.state.facet(documentId);
|
2837
|
-
if (!id) {
|
2838
|
-
return;
|
2839
|
-
}
|
2840
|
-
if (!initialized) {
|
2841
|
-
initialized = true;
|
2842
|
-
const foldState2 = state[id];
|
2843
|
-
if (foldState2?.foldedRanges?.length) {
|
2844
|
-
view.dispatch({
|
2845
|
-
effects: foldState2.foldedRanges.map((range) => foldEffect.of({
|
2846
|
-
from: range.from,
|
2847
|
-
to: range.to
|
2848
|
-
}))
|
2849
|
-
});
|
2850
|
-
}
|
2851
|
-
return;
|
2852
|
-
}
|
2853
|
-
const decorations = foldedRanges(view.state);
|
2854
|
-
const ranges = [];
|
2855
|
-
decorations.between(0, view.state.doc.length, (from, to) => {
|
2856
|
-
ranges.push({
|
2857
|
-
from,
|
2858
|
-
to
|
2859
|
-
});
|
2827
|
+
var folding = (_props = {}) => [
|
2828
|
+
codeFolding({
|
2829
|
+
placeholderDOM: () => {
|
2830
|
+
return document.createElement("span");
|
2831
|
+
}
|
2832
|
+
}),
|
2833
|
+
foldGutter({
|
2834
|
+
markerDOM: (open) => {
|
2835
|
+
const el = createElement("div", {
|
2836
|
+
className: "flex h-full items-center"
|
2860
2837
|
});
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
|
2866
|
-
|
2867
|
-
|
2838
|
+
return renderRoot(el, /* @__PURE__ */ React3.createElement(Icon, {
|
2839
|
+
icon: "ph--caret-right--regular",
|
2840
|
+
size: 3,
|
2841
|
+
classNames: [
|
2842
|
+
"mx-3 cursor-pointer",
|
2843
|
+
open && "rotate-90"
|
2844
|
+
]
|
2845
|
+
}));
|
2846
|
+
}
|
2847
|
+
}),
|
2848
|
+
EditorView13.theme({
|
2849
|
+
".cm-foldGutter": {
|
2850
|
+
opacity: 0.3,
|
2851
|
+
transition: "opacity 0.3s",
|
2852
|
+
width: "32px"
|
2853
|
+
},
|
2854
|
+
".cm-foldGutter:hover": {
|
2855
|
+
opacity: 1
|
2856
|
+
}
|
2857
|
+
})
|
2858
|
+
];
|
2868
2859
|
|
2869
2860
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
2870
2861
|
import { EditorView as EditorView14 } from "@codemirror/view";
|
@@ -4286,7 +4277,7 @@ var convertTreeToJson = (state) => {
|
|
4286
4277
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4287
4278
|
import { RangeSetBuilder as RangeSetBuilder3, StateEffect as StateEffect5 } from "@codemirror/state";
|
4288
4279
|
import { EditorView as EditorView19, Decoration as Decoration7, WidgetType as WidgetType5, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
|
4289
|
-
import { invariant as
|
4280
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
4290
4281
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
4291
4282
|
|
4292
4283
|
// packages/ui/react-ui-editor/src/extensions/markdown/changes.ts
|
@@ -4745,7 +4736,7 @@ var TableWidget = class extends WidgetType4 {
|
|
4745
4736
|
};
|
4746
4737
|
|
4747
4738
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
4748
|
-
var
|
4739
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts";
|
4749
4740
|
var Unicode = {
|
4750
4741
|
emDash: "\u2014",
|
4751
4742
|
bullet: "\u2022",
|
@@ -4878,8 +4869,8 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4878
4869
|
const { state } = view;
|
4879
4870
|
const headerLevels = [];
|
4880
4871
|
const getHeaderLevels = (node, level) => {
|
4881
|
-
|
4882
|
-
F:
|
4872
|
+
invariant4(level > 0, void 0, {
|
4873
|
+
F: __dxlog_file9,
|
4883
4874
|
L: 178,
|
4884
4875
|
S: void 0,
|
4885
4876
|
A: [
|
@@ -4917,8 +4908,8 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4917
4908
|
listLevels.pop();
|
4918
4909
|
};
|
4919
4910
|
const getCurrentListLevel = () => {
|
4920
|
-
|
4921
|
-
F:
|
4911
|
+
invariant4(listLevels.length, void 0, {
|
4912
|
+
F: __dxlog_file9,
|
4922
4913
|
L: 200,
|
4923
4914
|
S: void 0,
|
4924
4915
|
A: [
|
@@ -5241,7 +5232,7 @@ var linkTooltip = (render) => {
|
|
5241
5232
|
// packages/ui/react-ui-editor/src/extensions/mention.ts
|
5242
5233
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
5243
5234
|
import { log as log6 } from "@dxos/log";
|
5244
|
-
var
|
5235
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/mention.ts";
|
5245
5236
|
var mention = ({ debug, onSearch }) => {
|
5246
5237
|
return autocompletion2({
|
5247
5238
|
// TODO(burdon): Not working.
|
@@ -5256,7 +5247,7 @@ var mention = ({ debug, onSearch }) => {
|
|
5256
5247
|
log6.info("completion context", {
|
5257
5248
|
context
|
5258
5249
|
}, {
|
5259
|
-
F:
|
5250
|
+
F: __dxlog_file10,
|
5260
5251
|
L: 27,
|
5261
5252
|
S: void 0,
|
5262
5253
|
C: (f, a) => f(...a)
|
@@ -5393,8 +5384,8 @@ import { EditorView as EditorView20 } from "@codemirror/view";
|
|
5393
5384
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
5394
5385
|
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo4, useRef, useState } from "react";
|
5395
5386
|
import { log as log7 } from "@dxos/log";
|
5396
|
-
import { getProviderValue, isNotFalsy as
|
5397
|
-
var
|
5387
|
+
import { getProviderValue, isNotFalsy as isNotFalsy4 } from "@dxos/util";
|
5388
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
|
5398
5389
|
var instanceCount = 0;
|
5399
5390
|
var useTextEditor = (props = {}, deps = []) => {
|
5400
5391
|
const { id, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } = useMemo4(() => getProviderValue(props), deps ?? []);
|
@@ -5409,7 +5400,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5409
5400
|
instanceId,
|
5410
5401
|
doc: initialValue?.length ?? 0
|
5411
5402
|
}, {
|
5412
|
-
F:
|
5403
|
+
F: __dxlog_file11,
|
5413
5404
|
L: 75,
|
5414
5405
|
S: void 0,
|
5415
5406
|
C: (f, a) => f(...a)
|
@@ -5435,13 +5426,13 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5435
5426
|
// NOTE: This doesn't catch errors in keymap functions.
|
5436
5427
|
EditorView20.exceptionSink.of((err) => {
|
5437
5428
|
log7.catch(err, void 0, {
|
5438
|
-
F:
|
5429
|
+
F: __dxlog_file11,
|
5439
5430
|
L: 97,
|
5440
5431
|
S: void 0,
|
5441
5432
|
C: (f, a) => f(...a)
|
5442
5433
|
});
|
5443
5434
|
})
|
5444
|
-
].filter(
|
5435
|
+
].filter(isNotFalsy4)
|
5445
5436
|
});
|
5446
5437
|
view2 = new EditorView20({
|
5447
5438
|
parent: parentRef.current,
|
@@ -5467,7 +5458,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5467
5458
|
log7("destroy", {
|
5468
5459
|
id
|
5469
5460
|
}, {
|
5470
|
-
F:
|
5461
|
+
F: __dxlog_file11,
|
5471
5462
|
L: 134,
|
5472
5463
|
S: void 0,
|
5473
5464
|
C: (f, a) => f(...a)
|
@@ -5484,7 +5475,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
5484
5475
|
scrollTo,
|
5485
5476
|
selection
|
5486
5477
|
}, {
|
5487
|
-
F:
|
5478
|
+
F: __dxlog_file11,
|
5488
5479
|
L: 143,
|
5489
5480
|
S: void 0,
|
5490
5481
|
C: (f, a) => f(...a)
|
@@ -5576,6 +5567,7 @@ export {
|
|
5576
5567
|
createDataExtensions,
|
5577
5568
|
createEditorAction,
|
5578
5569
|
createEditorActionGroup,
|
5570
|
+
createEditorStateStore,
|
5579
5571
|
createEditorStateTransaction,
|
5580
5572
|
createElement,
|
5581
5573
|
createExternalCommentSync,
|