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