@dxos/react-ui-editor 0.8.4-main.c1de068 → 0.8.4-main.e098934
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 +2074 -996
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +71 -1
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +2074 -996
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +71 -1
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/components/{Popover → CommandMenu}/CommandMenu.d.ts +10 -6
- package/dist/types/src/components/CommandMenu/CommandMenu.d.ts.map +1 -0
- package/dist/types/src/components/CommandMenu/index.d.ts +2 -0
- package/dist/types/src/components/CommandMenu/index.d.ts.map +1 -0
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/util.d.ts +2 -2
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts +20 -7
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts +9 -18
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/autoscroll.d.ts +10 -0
- package/dist/types/src/extensions/autoscroll.d.ts.map +1 -0
- package/dist/types/src/extensions/command/action.d.ts +1 -1
- package/dist/types/src/extensions/command/action.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts +2 -7
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/state.d.ts +1 -1
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +3 -4
- package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/dnd.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +2 -7
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- 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/action.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +8 -2
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts +9 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/selection.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts +2 -2
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts +3 -6
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/extensions/tags/extended-markdown.d.ts +10 -0
- package/dist/types/src/extensions/tags/extended-markdown.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts +2 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/index.d.ts +4 -0
- package/dist/types/src/extensions/tags/index.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/streamer.d.ts +12 -0
- package/dist/types/src/extensions/tags/streamer.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts +71 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts +10 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/Command.stories.d.ts +12 -4
- package/dist/types/src/stories/Command.stories.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +10 -3
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +21 -9
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +39 -2
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +22 -12
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +32 -42
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +15 -20
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +21 -6
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts +17 -0
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
- package/dist/types/src/stories/TextEditor.stories.d.ts +38 -51
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +3 -6
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/dist/types/src/testing/PreviewPopover.d.ts +20 -0
- package/dist/types/src/testing/PreviewPopover.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +1 -0
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -1
- package/dist/types/src/types/types.d.ts +1 -1
- package/dist/types/src/util/cursor.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/decorations.d.ts +4 -0
- package/dist/types/src/util/decorations.d.ts.map +1 -0
- package/dist/types/src/util/dom.d.ts +2 -12
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/domino.d.ts +18 -0
- package/dist/types/src/util/domino.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -51
- package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +93 -26
- package/src/components/{Popover → CommandMenu}/index.ts +0 -2
- package/src/components/Editor/Editor.tsx +1 -1
- package/src/components/EditorToolbar/EditorToolbar.tsx +40 -30
- package/src/components/EditorToolbar/blocks.ts +21 -24
- package/src/components/EditorToolbar/formatting.ts +22 -25
- package/src/components/EditorToolbar/headings.ts +10 -5
- package/src/components/EditorToolbar/image.ts +8 -4
- package/src/components/EditorToolbar/lists.ts +16 -19
- package/src/components/EditorToolbar/search.ts +8 -4
- package/src/components/EditorToolbar/util.ts +16 -5
- package/src/components/EditorToolbar/view-mode.ts +11 -6
- package/src/components/index.ts +1 -1
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete.ts +204 -54
- package/src/extensions/automerge/automerge.stories.tsx +25 -18
- package/src/extensions/automerge/automerge.ts +4 -3
- package/src/extensions/automerge/defs.ts +1 -1
- package/src/extensions/automerge/sync.ts +1 -1
- package/src/extensions/automerge/update-automerge.ts +1 -1
- package/src/extensions/autoscroll.ts +157 -0
- package/src/extensions/awareness/awareness.ts +2 -2
- package/src/extensions/command/action.ts +1 -2
- package/src/extensions/command/command-menu.ts +7 -6
- package/src/extensions/command/command.ts +3 -3
- package/src/extensions/command/floating-menu.ts +10 -15
- package/src/extensions/command/hint.ts +2 -1
- package/src/extensions/command/placeholder.ts +1 -1
- package/src/extensions/command/state.ts +4 -3
- package/src/extensions/command/typeahead.ts +2 -2
- package/src/extensions/command/useCommandMenu.ts +6 -9
- package/src/extensions/comments.ts +18 -13
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +9 -21
- package/src/extensions/folding.tsx +2 -2
- package/src/extensions/index.ts +2 -0
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +25 -3
- package/src/extensions/markdown/changes.ts +1 -1
- package/src/extensions/markdown/decorate.ts +23 -14
- package/src/extensions/markdown/formatting.test.ts +6 -6
- package/src/extensions/markdown/formatting.ts +3 -3
- package/src/extensions/markdown/highlight.ts +1 -1
- package/src/extensions/markdown/image.ts +3 -4
- package/src/extensions/markdown/link.ts +3 -0
- package/src/extensions/markdown/table.ts +7 -1
- package/src/extensions/mention.ts +1 -1
- package/src/extensions/outliner/outliner.test.ts +3 -2
- package/src/extensions/outliner/outliner.ts +6 -5
- package/src/extensions/outliner/selection.ts +1 -1
- package/src/extensions/outliner/tree.test.ts +2 -1
- package/src/extensions/outliner/tree.ts +2 -2
- package/src/extensions/preview/preview.ts +59 -62
- package/src/extensions/tags/extended-markdown.test.ts +261 -0
- package/src/extensions/tags/extended-markdown.ts +78 -0
- package/src/extensions/tags/index.ts +7 -0
- package/src/extensions/tags/streamer.ts +244 -0
- package/src/extensions/tags/xml-tags.ts +335 -0
- package/src/extensions/tags/xml-util.ts +94 -0
- package/src/hooks/useTextEditor.ts +3 -15
- package/src/stories/Command.stories.tsx +24 -31
- package/src/stories/CommandMenu.stories.tsx +28 -29
- package/src/stories/Comments.stories.tsx +10 -6
- package/src/stories/EditorToolbar.stories.tsx +8 -8
- package/src/stories/Experimental.stories.tsx +12 -8
- package/src/stories/Markdown.stories.tsx +21 -17
- package/src/stories/Outliner.stories.tsx +42 -30
- package/src/stories/Preview.stories.tsx +30 -29
- package/src/stories/Tags.stories.tsx +81 -0
- package/src/stories/TextEditor.stories.tsx +40 -34
- package/src/stories/components/EditorStory.tsx +9 -10
- package/src/styles/theme.ts +8 -6
- package/src/testing/PreviewPopover.tsx +78 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/util.ts +2 -0
- package/src/translations.ts +1 -1
- package/src/util/cursor.ts +2 -1
- package/src/util/debug.ts +2 -2
- package/src/util/decorations.ts +21 -0
- package/src/util/dom.ts +5 -27
- package/src/util/domino.ts +51 -0
- package/src/util/index.ts +2 -0
- package/src/util/react.tsx +1 -1
- package/dist/types/src/components/Popover/CommandMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +0 -21
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts +0 -34
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +0 -1
- package/dist/types/src/components/Popover/index.d.ts +0 -4
- package/dist/types/src/components/Popover/index.d.ts.map +0 -1
- package/src/components/Popover/RefDropdownMenu.tsx +0 -85
- package/src/components/Popover/RefPopover.tsx +0 -99
@@ -25,8 +25,8 @@ var translations = [
|
|
25
25
|
"selection overlaps existing comment label": "Selection overlaps existing comment",
|
26
26
|
"select text to comment label": "Select text to comment",
|
27
27
|
"image label": "Insert image",
|
28
|
-
"heading label": "Heading level",
|
29
28
|
"table label": "Create table",
|
29
|
+
"heading label": "Heading level",
|
30
30
|
"heading level label_zero": "Paragraph",
|
31
31
|
"heading level label_one": "Heading level {{count}}",
|
32
32
|
"heading level label_other": "Heading level {{count}}",
|
@@ -42,7 +42,7 @@ var translations = [
|
|
42
42
|
|
43
43
|
// src/index.ts
|
44
44
|
import { EditorState as EditorState4 } from "@codemirror/state";
|
45
|
-
import { EditorView as
|
45
|
+
import { EditorView as EditorView31, keymap as keymap14 } from "@codemirror/view";
|
46
46
|
import { tags as tags2 } from "@lezer/highlight";
|
47
47
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
48
48
|
|
@@ -50,28 +50,38 @@ import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
|
50
50
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
51
51
|
import React3, { forwardRef, useImperativeHandle } from "react";
|
52
52
|
import { useThemeContext } from "@dxos/react-ui";
|
53
|
-
import { mx as
|
53
|
+
import { mx as mx7 } from "@dxos/react-ui-theme";
|
54
54
|
|
55
55
|
// src/hooks/useTextEditor.ts
|
56
56
|
import { EditorState as EditorState3 } from "@codemirror/state";
|
57
|
-
import { EditorView as
|
57
|
+
import { EditorView as EditorView30 } from "@codemirror/view";
|
58
58
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
59
59
|
import { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef as useRef2, useState as useState2 } from "react";
|
60
|
-
import { log as
|
61
|
-
import { getProviderValue, isNotFalsy as
|
60
|
+
import { log as log9 } from "@dxos/log";
|
61
|
+
import { getProviderValue, isNotFalsy as isNotFalsy5 } from "@dxos/util";
|
62
62
|
|
63
63
|
// src/extensions/annotations.ts
|
64
64
|
import { RangeSetBuilder } from "@codemirror/state";
|
65
65
|
import { Decoration, EditorView, ViewPlugin } from "@codemirror/view";
|
66
|
+
function _define_property(obj, key, value) {
|
67
|
+
if (key in obj) {
|
68
|
+
Object.defineProperty(obj, key, {
|
69
|
+
value,
|
70
|
+
enumerable: true,
|
71
|
+
configurable: true,
|
72
|
+
writable: true
|
73
|
+
});
|
74
|
+
} else {
|
75
|
+
obj[key] = value;
|
76
|
+
}
|
77
|
+
return obj;
|
78
|
+
}
|
66
79
|
var annotationMark = Decoration.mark({
|
67
80
|
class: "cm-annotation"
|
68
81
|
});
|
69
82
|
var annotations = ({ match } = {}) => {
|
70
83
|
return [
|
71
84
|
ViewPlugin.fromClass(class {
|
72
|
-
constructor() {
|
73
|
-
this.decorations = Decoration.none;
|
74
|
-
}
|
75
85
|
update(update2) {
|
76
86
|
const builder = new RangeSetBuilder();
|
77
87
|
if (match) {
|
@@ -88,6 +98,9 @@ var annotations = ({ match } = {}) => {
|
|
88
98
|
}
|
89
99
|
this.decorations = builder.finish();
|
90
100
|
}
|
101
|
+
constructor() {
|
102
|
+
_define_property(this, "decorations", Decoration.none);
|
103
|
+
}
|
91
104
|
}, {
|
92
105
|
decorations: (v) => v.decorations
|
93
106
|
}),
|
@@ -102,58 +115,530 @@ var annotations = ({ match } = {}) => {
|
|
102
115
|
};
|
103
116
|
|
104
117
|
// src/extensions/autocomplete.ts
|
105
|
-
import {
|
106
|
-
import {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
118
|
+
import { Prec } from "@codemirror/state";
|
119
|
+
import { Decoration as Decoration2, EditorView as EditorView2, ViewPlugin as ViewPlugin2, WidgetType, keymap } from "@codemirror/view";
|
120
|
+
function _define_property2(obj, key, value) {
|
121
|
+
if (key in obj) {
|
122
|
+
Object.defineProperty(obj, key, {
|
123
|
+
value,
|
124
|
+
enumerable: true,
|
125
|
+
configurable: true,
|
126
|
+
writable: true
|
127
|
+
});
|
128
|
+
} else {
|
129
|
+
obj[key] = value;
|
130
|
+
}
|
131
|
+
return obj;
|
132
|
+
}
|
133
|
+
var autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }) => {
|
134
|
+
const suggest = ViewPlugin2.fromClass(class {
|
135
|
+
update(update2) {
|
136
|
+
if (update2.docChanged || update2.selectionSet) {
|
137
|
+
this._decorations = this.computeDecorations(update2.view);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
computeDecorations(view) {
|
141
|
+
const text = view.state.doc.toString();
|
142
|
+
const suggestions = onSuggest?.(text) ?? [];
|
143
|
+
if (!suggestions.length) {
|
144
|
+
this._currentSuggestion = null;
|
145
|
+
return Decoration2.none;
|
146
|
+
}
|
147
|
+
this._currentSuggestion = suggestions[0];
|
148
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
149
|
+
if (!suffix) {
|
150
|
+
return Decoration2.none;
|
151
|
+
}
|
152
|
+
return Decoration2.set([
|
153
|
+
Decoration2.widget({
|
154
|
+
widget: new InlineSuggestionWidget(suffix),
|
155
|
+
side: 1
|
156
|
+
}).range(view.state.doc.length)
|
157
|
+
]);
|
158
|
+
}
|
159
|
+
completeSuggestion(view) {
|
160
|
+
if (!this._currentSuggestion) {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
const text = view.state.doc.toString();
|
164
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
165
|
+
if (!suffix) {
|
166
|
+
return false;
|
167
|
+
}
|
168
|
+
view.dispatch({
|
169
|
+
changes: {
|
170
|
+
from: view.state.doc.length,
|
171
|
+
insert: suffix
|
172
|
+
},
|
173
|
+
selection: {
|
174
|
+
anchor: view.state.doc.length + suffix.length
|
175
|
+
}
|
176
|
+
});
|
177
|
+
return true;
|
178
|
+
}
|
179
|
+
constructor(view) {
|
180
|
+
_define_property2(this, "_decorations", void 0);
|
181
|
+
_define_property2(this, "_currentSuggestion", null);
|
182
|
+
this._decorations = this.computeDecorations(view);
|
183
|
+
}
|
184
|
+
}, {
|
185
|
+
decorations: (v) => v._decorations
|
186
|
+
});
|
187
|
+
return [
|
188
|
+
suggest,
|
189
|
+
EditorView2.theme({
|
190
|
+
".cm-inline-suggestion": {
|
191
|
+
opacity: 0.4
|
192
|
+
}
|
193
|
+
}),
|
194
|
+
Prec.highest(keymap.of([
|
195
|
+
{
|
196
|
+
key: "Tab",
|
197
|
+
preventDefault: true,
|
198
|
+
run: (view) => {
|
199
|
+
const plugin = view.plugin(suggest);
|
200
|
+
return plugin?.completeSuggestion(view) ?? false;
|
201
|
+
}
|
202
|
+
},
|
203
|
+
{
|
204
|
+
key: "ArrowRight",
|
205
|
+
preventDefault: true,
|
206
|
+
run: (view) => {
|
207
|
+
if (view.state.selection.main.head !== view.state.doc.length) {
|
208
|
+
return false;
|
129
209
|
}
|
130
|
-
|
131
|
-
|
132
|
-
options: onSearch(match.text.toLowerCase())
|
133
|
-
};
|
210
|
+
const plugin = view.plugin(suggest);
|
211
|
+
return plugin?.completeSuggestion(view) ?? false;
|
134
212
|
}
|
135
|
-
}
|
136
|
-
|
213
|
+
},
|
214
|
+
{
|
215
|
+
key: "Enter",
|
216
|
+
preventDefault: true,
|
217
|
+
run: (view) => {
|
218
|
+
const text = view.state.doc.toString().trim();
|
219
|
+
if (onSubmit && (fireIfEmpty || text.length > 0)) {
|
220
|
+
const reset = onSubmit(text);
|
221
|
+
if (reset) {
|
222
|
+
view.dispatch({
|
223
|
+
changes: {
|
224
|
+
from: 0,
|
225
|
+
to: view.state.doc.length,
|
226
|
+
insert: ""
|
227
|
+
}
|
228
|
+
});
|
229
|
+
}
|
230
|
+
}
|
231
|
+
return true;
|
232
|
+
}
|
233
|
+
},
|
234
|
+
{
|
235
|
+
key: "Shift-Enter",
|
236
|
+
preventDefault: true,
|
237
|
+
run: (view) => {
|
238
|
+
view.dispatch({
|
239
|
+
changes: {
|
240
|
+
from: view.state.selection.main.head,
|
241
|
+
insert: "\n"
|
242
|
+
},
|
243
|
+
selection: {
|
244
|
+
anchor: view.state.selection.main.head + 1,
|
245
|
+
head: view.state.selection.main.head + 1
|
246
|
+
}
|
247
|
+
});
|
248
|
+
return true;
|
249
|
+
}
|
250
|
+
},
|
251
|
+
{
|
252
|
+
key: "Escape",
|
253
|
+
preventDefault: true,
|
254
|
+
run: (view) => {
|
255
|
+
view.dispatch({
|
256
|
+
changes: {
|
257
|
+
from: 0,
|
258
|
+
to: view.state.doc.length,
|
259
|
+
insert: ""
|
260
|
+
}
|
261
|
+
});
|
262
|
+
onCancel?.();
|
263
|
+
return true;
|
264
|
+
}
|
265
|
+
}
|
266
|
+
]))
|
267
|
+
];
|
268
|
+
};
|
269
|
+
var InlineSuggestionWidget = class extends WidgetType {
|
270
|
+
toDOM() {
|
271
|
+
const span = document.createElement("span");
|
272
|
+
span.textContent = this.suffix;
|
273
|
+
span.className = "cm-inline-suggestion";
|
274
|
+
return span;
|
137
275
|
}
|
138
|
-
|
276
|
+
eq(other) {
|
277
|
+
return other.suffix === this.suffix;
|
278
|
+
}
|
279
|
+
constructor(suffix) {
|
280
|
+
super(), _define_property2(this, "suffix", void 0), this.suffix = suffix;
|
281
|
+
}
|
282
|
+
};
|
283
|
+
|
284
|
+
// src/extensions/autoscroll.ts
|
285
|
+
import { StateEffect } from "@codemirror/state";
|
286
|
+
import { EditorView as EditorView3, ViewPlugin as ViewPlugin3 } from "@codemirror/view";
|
287
|
+
|
288
|
+
// src/util/facet.ts
|
289
|
+
import { Facet } from "@codemirror/state";
|
290
|
+
var singleValueFacet = (defaultValue) => Facet.define({
|
291
|
+
// Called immediately.
|
292
|
+
combine: (providers) => {
|
293
|
+
return providers[0] ?? defaultValue;
|
294
|
+
}
|
295
|
+
});
|
296
|
+
|
297
|
+
// src/util/cursor.ts
|
298
|
+
function _define_property3(obj, key, value) {
|
299
|
+
if (key in obj) {
|
300
|
+
Object.defineProperty(obj, key, {
|
301
|
+
value,
|
302
|
+
enumerable: true,
|
303
|
+
configurable: true,
|
304
|
+
writable: true
|
305
|
+
});
|
306
|
+
} else {
|
307
|
+
obj[key] = value;
|
308
|
+
}
|
309
|
+
return obj;
|
310
|
+
}
|
311
|
+
var overlap = (a, b) => a.from <= b.to && a.to >= b.from;
|
312
|
+
var defaultCursorConverter = {
|
313
|
+
toCursor: (position) => position.toString(),
|
314
|
+
fromCursor: (cursor2) => parseInt(cursor2)
|
315
|
+
};
|
316
|
+
var Cursor = class {
|
317
|
+
};
|
318
|
+
_define_property3(Cursor, "converter", singleValueFacet(defaultCursorConverter));
|
319
|
+
_define_property3(Cursor, "getCursorFromRange", (state, range) => {
|
320
|
+
const cursorConverter2 = state.facet(Cursor.converter);
|
321
|
+
const from = cursorConverter2.toCursor(range.from);
|
322
|
+
const to = cursorConverter2.toCursor(range.to, -1);
|
323
|
+
return [
|
324
|
+
from,
|
325
|
+
to
|
326
|
+
].join(":");
|
327
|
+
});
|
328
|
+
_define_property3(Cursor, "getRangeFromCursor", (state, cursor2) => {
|
329
|
+
const cursorConverter2 = state.facet(Cursor.converter);
|
330
|
+
const parts = cursor2.split(":");
|
331
|
+
const from = cursorConverter2.fromCursor(parts[0]);
|
332
|
+
const to = cursorConverter2.fromCursor(parts[1]);
|
333
|
+
return from !== void 0 && to !== void 0 ? {
|
334
|
+
from,
|
335
|
+
to
|
336
|
+
} : void 0;
|
337
|
+
});
|
338
|
+
|
339
|
+
// src/util/decorations.ts
|
340
|
+
var decorationSetToArray = (deco) => {
|
341
|
+
const ranges = [];
|
342
|
+
const iter = deco.iter();
|
343
|
+
while (iter.value) {
|
344
|
+
ranges.push({
|
345
|
+
from: iter.from,
|
346
|
+
to: iter.to,
|
347
|
+
value: iter.value
|
348
|
+
});
|
349
|
+
iter.next();
|
350
|
+
}
|
351
|
+
return ranges;
|
352
|
+
};
|
353
|
+
|
354
|
+
// src/util/debug.ts
|
355
|
+
import { log } from "@dxos/log";
|
356
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/util/debug.ts";
|
357
|
+
var wrapWithCatch = (fn, label) => {
|
358
|
+
return (...args) => {
|
359
|
+
try {
|
360
|
+
return fn(...args);
|
361
|
+
} catch (err) {
|
362
|
+
log.catch(err, {
|
363
|
+
label
|
364
|
+
}, {
|
365
|
+
F: __dxlog_file,
|
366
|
+
L: 15,
|
367
|
+
S: void 0,
|
368
|
+
C: (f, a) => f(...a)
|
369
|
+
});
|
370
|
+
}
|
371
|
+
};
|
372
|
+
};
|
373
|
+
var callbackWrapper = (fn) => (...args) => {
|
374
|
+
try {
|
375
|
+
return fn(...args);
|
376
|
+
} catch (err) {
|
377
|
+
log.catch(err, void 0, {
|
378
|
+
F: __dxlog_file,
|
379
|
+
L: 29,
|
380
|
+
S: void 0,
|
381
|
+
C: (f, a) => f(...a)
|
382
|
+
});
|
383
|
+
}
|
384
|
+
};
|
385
|
+
var debugDispatcher = (trs, view) => {
|
386
|
+
logChanges(trs);
|
387
|
+
view.update(trs);
|
388
|
+
};
|
389
|
+
var logChanges = (trs) => {
|
390
|
+
const changes = trs.flatMap((tr) => {
|
391
|
+
if (tr.changes.empty) {
|
392
|
+
return void 0;
|
393
|
+
}
|
394
|
+
const changes2 = [];
|
395
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => changes2.push(JSON.stringify({
|
396
|
+
fromA,
|
397
|
+
toA,
|
398
|
+
fromB,
|
399
|
+
toB,
|
400
|
+
inserted: inserted.toString()
|
401
|
+
})));
|
402
|
+
return changes2;
|
403
|
+
}).filter(Boolean);
|
404
|
+
if (changes.length) {
|
405
|
+
log("changes", {
|
406
|
+
changes
|
407
|
+
}, {
|
408
|
+
F: __dxlog_file,
|
409
|
+
L: 62,
|
410
|
+
S: void 0,
|
411
|
+
C: (f, a) => f(...a)
|
412
|
+
});
|
413
|
+
}
|
414
|
+
};
|
415
|
+
|
416
|
+
// src/util/dom.ts
|
417
|
+
var flattenRect = (rect, left) => {
|
418
|
+
const x = left ? rect.left : rect.right;
|
419
|
+
return {
|
420
|
+
left: x,
|
421
|
+
right: x,
|
422
|
+
top: rect.top,
|
423
|
+
bottom: rect.bottom
|
424
|
+
};
|
425
|
+
};
|
426
|
+
var scratchRange;
|
427
|
+
var textRange = (node, from, to = from) => {
|
428
|
+
const range = scratchRange || (scratchRange = document.createRange());
|
429
|
+
range.setEnd(node, to);
|
430
|
+
range.setStart(node, from);
|
431
|
+
return range;
|
432
|
+
};
|
433
|
+
var clientRectsFor = (dom) => {
|
434
|
+
if (dom.nodeType === 3) {
|
435
|
+
return textRange(dom, 0, dom.nodeValue.length).getClientRects();
|
436
|
+
} else if (dom.nodeType === 1) {
|
437
|
+
return dom.getClientRects();
|
438
|
+
} else {
|
439
|
+
return [];
|
440
|
+
}
|
441
|
+
};
|
442
|
+
|
443
|
+
// src/util/domino.ts
|
444
|
+
import { mx } from "@dxos/react-ui-theme";
|
445
|
+
function _define_property4(obj, key, value) {
|
446
|
+
if (key in obj) {
|
447
|
+
Object.defineProperty(obj, key, {
|
448
|
+
value,
|
449
|
+
enumerable: true,
|
450
|
+
configurable: true,
|
451
|
+
writable: true
|
452
|
+
});
|
453
|
+
} else {
|
454
|
+
obj[key] = value;
|
455
|
+
}
|
456
|
+
return obj;
|
457
|
+
}
|
458
|
+
var Domino = class _Domino {
|
459
|
+
static of(tag) {
|
460
|
+
return new _Domino(tag);
|
461
|
+
}
|
462
|
+
classNames(...classNames) {
|
463
|
+
this._el.className = mx(classNames);
|
464
|
+
return this;
|
465
|
+
}
|
466
|
+
text(value) {
|
467
|
+
this._el.textContent = value;
|
468
|
+
return this;
|
469
|
+
}
|
470
|
+
data(key, value) {
|
471
|
+
this._el.dataset[key] = value;
|
472
|
+
return this;
|
473
|
+
}
|
474
|
+
style(styles4) {
|
475
|
+
Object.assign(this._el.style, styles4);
|
476
|
+
return this;
|
477
|
+
}
|
478
|
+
attr(key, value) {
|
479
|
+
this._el[key] = value;
|
480
|
+
return this;
|
481
|
+
}
|
482
|
+
child(...children) {
|
483
|
+
children.forEach((child) => this._el.appendChild(child.build()));
|
484
|
+
return this;
|
485
|
+
}
|
486
|
+
on(event, handler) {
|
487
|
+
this._el.addEventListener(event, handler);
|
488
|
+
return this;
|
489
|
+
}
|
490
|
+
build() {
|
491
|
+
return this._el;
|
492
|
+
}
|
493
|
+
constructor(tag) {
|
494
|
+
_define_property4(this, "_el", void 0);
|
495
|
+
this._el = document.createElement(tag);
|
496
|
+
}
|
497
|
+
};
|
498
|
+
|
499
|
+
// src/util/react.tsx
|
500
|
+
import React from "react";
|
501
|
+
import { createRoot } from "react-dom/client";
|
502
|
+
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
503
|
+
import { defaultTx } from "@dxos/react-ui-theme";
|
504
|
+
var renderRoot = (root, node) => {
|
505
|
+
createRoot(root).render(/* @__PURE__ */ React.createElement(ThemeProvider, {
|
506
|
+
tx: defaultTx
|
507
|
+
}, node));
|
508
|
+
return root;
|
509
|
+
};
|
510
|
+
var createRenderer = (Component) => (el, props) => {
|
511
|
+
renderRoot(el, /* @__PURE__ */ React.createElement(ThemeProvider, {
|
512
|
+
tx: defaultTx
|
513
|
+
}, /* @__PURE__ */ React.createElement(Tooltip.Provider, null, /* @__PURE__ */ React.createElement(Component, props))));
|
514
|
+
};
|
515
|
+
|
516
|
+
// src/extensions/autoscroll.ts
|
517
|
+
var lineHeight = 24;
|
518
|
+
var scrollToBottomEffect = StateEffect.define();
|
519
|
+
var autoScroll = ({ overscroll = 4 * lineHeight, throttle: throttle2 = 2e3 } = {}) => {
|
520
|
+
let isThrottled = false;
|
521
|
+
let isPinned = true;
|
522
|
+
let timeout;
|
523
|
+
let buttonContainer;
|
524
|
+
let lastScrollTop = 0;
|
525
|
+
let scrollCounter = 0;
|
526
|
+
const hideScrollbar = (view) => {
|
527
|
+
view.scrollDOM.classList.add("cm-hide-scrollbar");
|
528
|
+
clearTimeout(timeout);
|
529
|
+
timeout = setTimeout(() => {
|
530
|
+
view.scrollDOM.classList.remove("cm-hide-scrollbar");
|
531
|
+
}, 1e3);
|
532
|
+
};
|
533
|
+
const scrollToBottom = (view) => {
|
534
|
+
isPinned = true;
|
535
|
+
scrollCounter = 0;
|
536
|
+
buttonContainer?.classList.add("opacity-0");
|
537
|
+
requestAnimationFrame(() => {
|
538
|
+
hideScrollbar(view);
|
539
|
+
view.scrollDOM.scrollTo({
|
540
|
+
top: view.scrollDOM.scrollHeight,
|
541
|
+
behavior: "smooth"
|
542
|
+
});
|
543
|
+
});
|
544
|
+
};
|
545
|
+
return [
|
546
|
+
// Scroll button.
|
547
|
+
ViewPlugin3.fromClass(class {
|
548
|
+
constructor(view) {
|
549
|
+
const scroller = view.scrollDOM.parentElement;
|
550
|
+
buttonContainer = Domino.of("div").classNames("cm-scroll-button transition-opacity duration-300 opacity-0").child(Domino.of("button").classNames("dx-button bg-accentSurface").data("density", "fine").child(Domino.of("dx-icon").attr("icon", "ph--arrow-down--regular")).on("click", () => {
|
551
|
+
scrollToBottom(view);
|
552
|
+
})).build();
|
553
|
+
scroller?.appendChild(buttonContainer);
|
554
|
+
}
|
555
|
+
}),
|
556
|
+
// Update listener for logging when scrolling is needed.
|
557
|
+
EditorView3.updateListener.of((update2) => {
|
558
|
+
update2.transactions.forEach((transaction) => {
|
559
|
+
for (const effect of transaction.effects) {
|
560
|
+
if (effect.is(scrollToBottomEffect)) {
|
561
|
+
scrollToBottom(update2.view);
|
562
|
+
}
|
563
|
+
}
|
564
|
+
});
|
565
|
+
if (update2.docChanged && isPinned && !isThrottled) {
|
566
|
+
const distanceFromBottom = calcDistance(update2.view.scrollDOM);
|
567
|
+
if (distanceFromBottom >= overscroll) {
|
568
|
+
isThrottled = true;
|
569
|
+
requestAnimationFrame(() => {
|
570
|
+
scrollToBottom(update2.view);
|
571
|
+
});
|
572
|
+
setTimeout(() => {
|
573
|
+
isThrottled = false;
|
574
|
+
}, throttle2);
|
575
|
+
}
|
576
|
+
}
|
577
|
+
}),
|
578
|
+
// Detect user scroll.
|
579
|
+
// NOTE: Multiple scroll events are triggered during programmatic smooth scrolling.
|
580
|
+
EditorView3.domEventHandlers({
|
581
|
+
scroll: (event, view) => {
|
582
|
+
const scroller = view.scrollDOM;
|
583
|
+
if (lastScrollTop > scroller.scrollTop) {
|
584
|
+
scrollCounter++;
|
585
|
+
}
|
586
|
+
lastScrollTop = scroller.scrollTop;
|
587
|
+
const distanceFromBottom = calcDistance(scroller);
|
588
|
+
if (distanceFromBottom === 0) {
|
589
|
+
isPinned = true;
|
590
|
+
buttonContainer?.classList.add("opacity-0");
|
591
|
+
scrollCounter = 0;
|
592
|
+
} else if (scrollCounter > 3) {
|
593
|
+
isPinned = false;
|
594
|
+
buttonContainer?.classList.remove("opacity-0");
|
595
|
+
}
|
596
|
+
}
|
597
|
+
}),
|
598
|
+
EditorView3.theme({
|
599
|
+
".cm-scroller": {
|
600
|
+
paddingBottom: `${overscroll}px`,
|
601
|
+
scrollbarWidth: "thin"
|
602
|
+
},
|
603
|
+
".cm-scroller.cm-hide-scrollbar": {
|
604
|
+
scrollbarWidth: "none"
|
605
|
+
},
|
606
|
+
".cm-scroller.cm-hide-scrollbar::-webkit-scrollbar": {
|
607
|
+
display: "none"
|
608
|
+
},
|
609
|
+
// TODO(burdon): IconButton.
|
610
|
+
".cm-scroll-button": {
|
611
|
+
position: "absolute",
|
612
|
+
bottom: "0.5rem",
|
613
|
+
right: "1rem"
|
614
|
+
}
|
615
|
+
})
|
616
|
+
];
|
617
|
+
};
|
618
|
+
var calcDistance = (scroller) => {
|
619
|
+
const scrollTop = scroller.scrollTop;
|
620
|
+
const scrollHeight = scroller.scrollHeight;
|
621
|
+
const clientHeight = scroller.clientHeight;
|
622
|
+
const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
|
623
|
+
return distanceFromBottom;
|
139
624
|
};
|
140
625
|
|
141
626
|
// src/extensions/automerge/automerge.ts
|
142
627
|
import { next as A3 } from "@automerge/automerge";
|
143
628
|
import { StateField } from "@codemirror/state";
|
144
|
-
import { EditorView as
|
629
|
+
import { EditorView as EditorView4, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
145
630
|
|
146
631
|
// src/extensions/automerge/cursor.ts
|
147
|
-
import { log } from "@dxos/log";
|
632
|
+
import { log as log2 } from "@dxos/log";
|
148
633
|
import { fromCursor, toCursor } from "@dxos/react-client/echo";
|
149
|
-
var
|
634
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts";
|
150
635
|
var cursorConverter = (accessor) => ({
|
151
636
|
toCursor: (pos, assoc) => {
|
152
637
|
try {
|
153
638
|
return toCursor(accessor, pos, assoc);
|
154
639
|
} catch (err) {
|
155
|
-
|
156
|
-
F:
|
640
|
+
log2.catch(err, void 0, {
|
641
|
+
F: __dxlog_file2,
|
157
642
|
L: 15,
|
158
643
|
S: void 0,
|
159
644
|
C: (f, a) => f(...a)
|
@@ -161,12 +646,12 @@ var cursorConverter = (accessor) => ({
|
|
161
646
|
return "";
|
162
647
|
}
|
163
648
|
},
|
164
|
-
fromCursor: (
|
649
|
+
fromCursor: (cursor2) => {
|
165
650
|
try {
|
166
|
-
return fromCursor(accessor,
|
651
|
+
return fromCursor(accessor, cursor2);
|
167
652
|
} catch (err) {
|
168
|
-
|
169
|
-
F:
|
653
|
+
log2.catch(err, void 0, {
|
654
|
+
F: __dxlog_file2,
|
170
655
|
L: 24,
|
171
656
|
S: void 0,
|
172
657
|
C: (f, a) => f(...a)
|
@@ -177,10 +662,10 @@ var cursorConverter = (accessor) => ({
|
|
177
662
|
});
|
178
663
|
|
179
664
|
// src/extensions/automerge/defs.ts
|
180
|
-
import { Annotation, StateEffect } from "@codemirror/state";
|
665
|
+
import { Annotation, StateEffect as StateEffect2 } from "@codemirror/state";
|
181
666
|
var getPath = (state, field) => state.field(field).path;
|
182
667
|
var getLastHeads = (state, field) => state.field(field).lastHeads;
|
183
|
-
var updateHeadsEffect =
|
668
|
+
var updateHeadsEffect = StateEffect2.define({});
|
184
669
|
var updateHeads = (newHeads) => updateHeadsEffect.of({
|
185
670
|
newHeads
|
186
671
|
});
|
@@ -331,13 +816,20 @@ var charPath = (textPath, candidatePath) => {
|
|
331
816
|
};
|
332
817
|
|
333
818
|
// src/extensions/automerge/sync.ts
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
819
|
+
function _define_property5(obj, key, value) {
|
820
|
+
if (key in obj) {
|
821
|
+
Object.defineProperty(obj, key, {
|
822
|
+
value,
|
823
|
+
enumerable: true,
|
824
|
+
configurable: true,
|
825
|
+
writable: true
|
826
|
+
});
|
827
|
+
} else {
|
828
|
+
obj[key] = value;
|
340
829
|
}
|
830
|
+
return obj;
|
831
|
+
}
|
832
|
+
var Syncer = class {
|
341
833
|
reconcile(view, editor2) {
|
342
834
|
if (this._pending) {
|
343
835
|
return;
|
@@ -372,172 +864,31 @@ var Syncer = class {
|
|
372
864
|
annotations: reconcileAnnotation.of(false)
|
373
865
|
});
|
374
866
|
}
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
}
|
384
|
-
});
|
385
|
-
|
386
|
-
// src/util/cursor.ts
|
387
|
-
var overlap = (a, b) => a.from <= b.to && a.to >= b.from;
|
388
|
-
var defaultCursorConverter = {
|
389
|
-
toCursor: (position) => position.toString(),
|
390
|
-
fromCursor: (cursor) => parseInt(cursor)
|
391
|
-
};
|
392
|
-
var Cursor = class _Cursor {
|
393
|
-
static {
|
394
|
-
this.converter = singleValueFacet(defaultCursorConverter);
|
395
|
-
}
|
396
|
-
static {
|
397
|
-
this.getCursorFromRange = (state, range) => {
|
398
|
-
const cursorConverter2 = state.facet(_Cursor.converter);
|
399
|
-
const from = cursorConverter2.toCursor(range.from);
|
400
|
-
const to = cursorConverter2.toCursor(range.to, -1);
|
401
|
-
return [
|
402
|
-
from,
|
403
|
-
to
|
404
|
-
].join(":");
|
405
|
-
};
|
406
|
-
}
|
407
|
-
static {
|
408
|
-
this.getRangeFromCursor = (state, cursor) => {
|
409
|
-
const cursorConverter2 = state.facet(_Cursor.converter);
|
410
|
-
const parts = cursor.split(":");
|
411
|
-
const from = cursorConverter2.fromCursor(parts[0]);
|
412
|
-
const to = cursorConverter2.fromCursor(parts[1]);
|
413
|
-
return from !== void 0 && to !== void 0 ? {
|
414
|
-
from,
|
415
|
-
to
|
416
|
-
} : void 0;
|
417
|
-
};
|
867
|
+
// prettier-ignore
|
868
|
+
constructor(_handle, _state) {
|
869
|
+
_define_property5(this, "_handle", void 0);
|
870
|
+
_define_property5(this, "_state", void 0);
|
871
|
+
_define_property5(this, "_pending", void 0);
|
872
|
+
this._handle = _handle;
|
873
|
+
this._state = _state;
|
874
|
+
this._pending = false;
|
418
875
|
}
|
419
876
|
};
|
420
877
|
|
421
|
-
// src/
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
log2.catch(err, void 0, {
|
430
|
-
F: __dxlog_file2,
|
431
|
-
L: 15,
|
432
|
-
S: void 0,
|
433
|
-
C: (f, a) => f(...a)
|
434
|
-
});
|
435
|
-
}
|
436
|
-
};
|
437
|
-
};
|
438
|
-
var callbackWrapper = (fn) => (...args) => {
|
439
|
-
try {
|
440
|
-
return fn(...args);
|
441
|
-
} catch (err) {
|
442
|
-
log2.catch(err, void 0, {
|
443
|
-
F: __dxlog_file2,
|
444
|
-
L: 29,
|
445
|
-
S: void 0,
|
446
|
-
C: (f, a) => f(...a)
|
447
|
-
});
|
448
|
-
}
|
449
|
-
};
|
450
|
-
var debugDispatcher = (trs, view) => {
|
451
|
-
logChanges(trs);
|
452
|
-
view.update(trs);
|
453
|
-
};
|
454
|
-
var logChanges = (trs) => {
|
455
|
-
const changes = trs.flatMap((tr) => {
|
456
|
-
if (tr.changes.empty) {
|
457
|
-
return void 0;
|
458
|
-
}
|
459
|
-
const changes2 = [];
|
460
|
-
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => changes2.push(JSON.stringify({
|
461
|
-
fromA,
|
462
|
-
toA,
|
463
|
-
fromB,
|
464
|
-
toB,
|
465
|
-
inserted: inserted.toString()
|
466
|
-
})));
|
467
|
-
return changes2;
|
468
|
-
}).filter(Boolean);
|
469
|
-
if (changes.length) {
|
470
|
-
log2("changes", {
|
471
|
-
changes
|
472
|
-
}, {
|
473
|
-
F: __dxlog_file2,
|
474
|
-
L: 62,
|
475
|
-
S: void 0,
|
476
|
-
C: (f, a) => f(...a)
|
878
|
+
// src/extensions/automerge/automerge.ts
|
879
|
+
function _define_property6(obj, key, value) {
|
880
|
+
if (key in obj) {
|
881
|
+
Object.defineProperty(obj, key, {
|
882
|
+
value,
|
883
|
+
enumerable: true,
|
884
|
+
configurable: true,
|
885
|
+
writable: true
|
477
886
|
});
|
478
|
-
}
|
479
|
-
};
|
480
|
-
|
481
|
-
// src/util/dom.ts
|
482
|
-
var flattenRect = (rect, left) => {
|
483
|
-
const x = left ? rect.left : rect.right;
|
484
|
-
return {
|
485
|
-
left: x,
|
486
|
-
right: x,
|
487
|
-
top: rect.top,
|
488
|
-
bottom: rect.bottom
|
489
|
-
};
|
490
|
-
};
|
491
|
-
var scratchRange;
|
492
|
-
var textRange = (node, from, to = from) => {
|
493
|
-
const range = scratchRange || (scratchRange = document.createRange());
|
494
|
-
range.setEnd(node, to);
|
495
|
-
range.setStart(node, from);
|
496
|
-
return range;
|
497
|
-
};
|
498
|
-
var clientRectsFor = (dom) => {
|
499
|
-
if (dom.nodeType === 3) {
|
500
|
-
return textRange(dom, 0, dom.nodeValue.length).getClientRects();
|
501
|
-
} else if (dom.nodeType === 1) {
|
502
|
-
return dom.getClientRects();
|
503
887
|
} else {
|
504
|
-
|
505
|
-
}
|
506
|
-
};
|
507
|
-
var createElement = (tag, options, children) => {
|
508
|
-
const el = document.createElement(tag);
|
509
|
-
if (options?.className) {
|
510
|
-
el.className = options.className;
|
511
|
-
}
|
512
|
-
if (options?.text) {
|
513
|
-
el.textContent = options.text;
|
888
|
+
obj[key] = value;
|
514
889
|
}
|
515
|
-
|
516
|
-
|
517
|
-
children
|
518
|
-
]);
|
519
|
-
}
|
520
|
-
return el;
|
521
|
-
};
|
522
|
-
|
523
|
-
// src/util/react.tsx
|
524
|
-
import React from "react";
|
525
|
-
import { createRoot } from "react-dom/client";
|
526
|
-
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
527
|
-
import { defaultTx } from "@dxos/react-ui-theme";
|
528
|
-
var renderRoot = (root, node) => {
|
529
|
-
createRoot(root).render(/* @__PURE__ */ React.createElement(ThemeProvider, {
|
530
|
-
tx: defaultTx
|
531
|
-
}, node));
|
532
|
-
return root;
|
533
|
-
};
|
534
|
-
var createRenderer = (Component) => (el, props) => {
|
535
|
-
renderRoot(el, /* @__PURE__ */ React.createElement(ThemeProvider, {
|
536
|
-
tx: defaultTx
|
537
|
-
}, /* @__PURE__ */ React.createElement(Tooltip.Provider, null, /* @__PURE__ */ React.createElement(Component, props))));
|
538
|
-
};
|
539
|
-
|
540
|
-
// src/extensions/automerge/automerge.ts
|
890
|
+
return obj;
|
891
|
+
}
|
541
892
|
var automerge = (accessor) => {
|
542
893
|
const syncState = StateField.define({
|
543
894
|
create: () => ({
|
@@ -574,20 +925,22 @@ var automerge = (accessor) => {
|
|
574
925
|
// Track heads.
|
575
926
|
syncState,
|
576
927
|
// Reconcile external updates.
|
577
|
-
|
928
|
+
ViewPlugin4.fromClass(class {
|
929
|
+
destroy() {
|
930
|
+
accessor.handle.removeListener("change", this._handleChange);
|
931
|
+
}
|
578
932
|
constructor(_view) {
|
933
|
+
_define_property6(this, "_view", void 0);
|
934
|
+
_define_property6(this, "_handleChange", void 0);
|
579
935
|
this._view = _view;
|
580
936
|
this._handleChange = () => {
|
581
937
|
syncer.reconcile(this._view, false);
|
582
938
|
};
|
583
939
|
accessor.handle.addListener("change", this._handleChange);
|
584
940
|
}
|
585
|
-
destroy() {
|
586
|
-
accessor.handle.removeListener("change", this._handleChange);
|
587
|
-
}
|
588
941
|
}),
|
589
942
|
// Reconcile local updates.
|
590
|
-
|
943
|
+
EditorView4.updateListener.of(({ view, changes }) => {
|
591
944
|
if (!changes.empty) {
|
592
945
|
syncer.reconcile(view, true);
|
593
946
|
}
|
@@ -597,9 +950,22 @@ var automerge = (accessor) => {
|
|
597
950
|
|
598
951
|
// src/extensions/awareness/awareness.ts
|
599
952
|
import { Annotation as Annotation2, RangeSet } from "@codemirror/state";
|
600
|
-
import { Decoration as
|
953
|
+
import { Decoration as Decoration3, EditorView as EditorView5, ViewPlugin as ViewPlugin5, WidgetType as WidgetType2 } from "@codemirror/view";
|
601
954
|
import { Event } from "@dxos/async";
|
602
955
|
import { Context } from "@dxos/context";
|
956
|
+
function _define_property7(obj, key, value) {
|
957
|
+
if (key in obj) {
|
958
|
+
Object.defineProperty(obj, key, {
|
959
|
+
value,
|
960
|
+
enumerable: true,
|
961
|
+
configurable: true,
|
962
|
+
writable: true
|
963
|
+
});
|
964
|
+
} else {
|
965
|
+
obj[key] = value;
|
966
|
+
}
|
967
|
+
return obj;
|
968
|
+
}
|
603
969
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/awareness/awareness.ts";
|
604
970
|
var dummyProvider = {
|
605
971
|
remoteStateChange: new Event(),
|
@@ -616,30 +982,13 @@ var RemoteSelectionChangedAnnotation = Annotation2.define();
|
|
616
982
|
var awareness = (provider = dummyProvider) => {
|
617
983
|
return [
|
618
984
|
awarenessProvider.of(provider),
|
619
|
-
|
985
|
+
ViewPlugin5.fromClass(RemoteSelectionsDecorator, {
|
620
986
|
decorations: (value) => value.decorations
|
621
987
|
}),
|
622
988
|
styles
|
623
989
|
];
|
624
990
|
};
|
625
991
|
var RemoteSelectionsDecorator = class {
|
626
|
-
constructor(view) {
|
627
|
-
this._ctx = new Context(void 0, {
|
628
|
-
F: __dxlog_file3,
|
629
|
-
L: 80
|
630
|
-
});
|
631
|
-
this.decorations = RangeSet.of([]);
|
632
|
-
this._cursorConverter = view.state.facet(Cursor.converter);
|
633
|
-
this._provider = view.state.facet(awarenessProvider);
|
634
|
-
this._provider.open();
|
635
|
-
this._provider.remoteStateChange.on(this._ctx, () => {
|
636
|
-
view.dispatch({
|
637
|
-
annotations: [
|
638
|
-
RemoteSelectionChangedAnnotation.of([])
|
639
|
-
]
|
640
|
-
});
|
641
|
-
});
|
642
|
-
}
|
643
992
|
destroy() {
|
644
993
|
void this._ctx.dispose();
|
645
994
|
this._provider.close();
|
@@ -680,7 +1029,7 @@ var RemoteSelectionsDecorator = class {
|
|
680
1029
|
decorations2.push({
|
681
1030
|
from: start,
|
682
1031
|
to: end,
|
683
|
-
value:
|
1032
|
+
value: Decoration3.mark({
|
684
1033
|
attributes: {
|
685
1034
|
style: `background-color: ${lightColor}`
|
686
1035
|
},
|
@@ -691,7 +1040,7 @@ var RemoteSelectionsDecorator = class {
|
|
691
1040
|
decorations2.push({
|
692
1041
|
from: start,
|
693
1042
|
to: startLine.from + startLine.length,
|
694
|
-
value:
|
1043
|
+
value: Decoration3.mark({
|
695
1044
|
attributes: {
|
696
1045
|
style: `background-color: ${lightColor}`
|
697
1046
|
},
|
@@ -701,7 +1050,7 @@ var RemoteSelectionsDecorator = class {
|
|
701
1050
|
decorations2.push({
|
702
1051
|
from: endLine.from,
|
703
1052
|
to: end,
|
704
|
-
value:
|
1053
|
+
value: Decoration3.mark({
|
705
1054
|
attributes: {
|
706
1055
|
style: `background-color: ${lightColor}`
|
707
1056
|
},
|
@@ -713,7 +1062,7 @@ var RemoteSelectionsDecorator = class {
|
|
713
1062
|
decorations2.push({
|
714
1063
|
from: linePos,
|
715
1064
|
to: linePos,
|
716
|
-
value:
|
1065
|
+
value: Decoration3.line({
|
717
1066
|
attributes: {
|
718
1067
|
style: `background-color: ${lightColor}`,
|
719
1068
|
class: "cm-collab-selectionLine"
|
@@ -725,20 +1074,38 @@ var RemoteSelectionsDecorator = class {
|
|
725
1074
|
decorations2.push({
|
726
1075
|
from: head,
|
727
1076
|
to: head,
|
728
|
-
value:
|
1077
|
+
value: Decoration3.widget({
|
729
1078
|
side: head - anchor > 0 ? -1 : 1,
|
730
1079
|
block: false,
|
731
1080
|
widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", darkColor)
|
732
1081
|
})
|
733
1082
|
});
|
734
1083
|
}
|
735
|
-
this.decorations =
|
1084
|
+
this.decorations = Decoration3.set(decorations2, true);
|
736
1085
|
}
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
1086
|
+
constructor(view) {
|
1087
|
+
_define_property7(this, "_ctx", new Context(void 0, {
|
1088
|
+
F: __dxlog_file3,
|
1089
|
+
L: 80
|
1090
|
+
}));
|
1091
|
+
_define_property7(this, "_cursorConverter", void 0);
|
1092
|
+
_define_property7(this, "_provider", void 0);
|
1093
|
+
_define_property7(this, "_lastAnchor", void 0);
|
1094
|
+
_define_property7(this, "_lastHead", void 0);
|
1095
|
+
_define_property7(this, "decorations", RangeSet.of([]));
|
1096
|
+
this._cursorConverter = view.state.facet(Cursor.converter);
|
1097
|
+
this._provider = view.state.facet(awarenessProvider);
|
1098
|
+
this._provider.open();
|
1099
|
+
this._provider.remoteStateChange.on(this._ctx, () => {
|
1100
|
+
view.dispatch({
|
1101
|
+
annotations: [
|
1102
|
+
RemoteSelectionChangedAnnotation.of([])
|
1103
|
+
]
|
1104
|
+
});
|
1105
|
+
});
|
741
1106
|
}
|
1107
|
+
};
|
1108
|
+
var RemoteCaretWidget = class extends WidgetType2 {
|
742
1109
|
toDOM() {
|
743
1110
|
const span = document.createElement("span");
|
744
1111
|
span.className = "cm-collab-selectionCaret";
|
@@ -768,8 +1135,11 @@ var RemoteCaretWidget = class extends WidgetType {
|
|
768
1135
|
ignoreEvent() {
|
769
1136
|
return true;
|
770
1137
|
}
|
1138
|
+
constructor(_name, _color) {
|
1139
|
+
super(), _define_property7(this, "_name", void 0), _define_property7(this, "_color", void 0), this._name = _name, this._color = _color;
|
1140
|
+
}
|
771
1141
|
};
|
772
|
-
var styles =
|
1142
|
+
var styles = EditorView5.theme({
|
773
1143
|
".cm-collab-selection": {},
|
774
1144
|
".cm-collab-selectionLine": {
|
775
1145
|
padding: 0,
|
@@ -832,17 +1202,22 @@ import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
832
1202
|
import { Context as Context2 } from "@dxos/context";
|
833
1203
|
import { invariant } from "@dxos/invariant";
|
834
1204
|
import { log as log3 } from "@dxos/log";
|
1205
|
+
function _define_property8(obj, key, value) {
|
1206
|
+
if (key in obj) {
|
1207
|
+
Object.defineProperty(obj, key, {
|
1208
|
+
value,
|
1209
|
+
enumerable: true,
|
1210
|
+
configurable: true,
|
1211
|
+
writable: true
|
1212
|
+
});
|
1213
|
+
} else {
|
1214
|
+
obj[key] = value;
|
1215
|
+
}
|
1216
|
+
return obj;
|
1217
|
+
}
|
835
1218
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/awareness/awareness-provider.ts";
|
836
1219
|
var DEBOUNCE_INTERVAL = 100;
|
837
1220
|
var SpaceAwarenessProvider = class {
|
838
|
-
constructor(params) {
|
839
|
-
this._remoteStates = /* @__PURE__ */ new Map();
|
840
|
-
this.remoteStateChange = new Event2();
|
841
|
-
this._space = params.space;
|
842
|
-
this._channel = params.channel;
|
843
|
-
this._peerId = params.peerId;
|
844
|
-
this._info = params.info;
|
845
|
-
}
|
846
1221
|
open() {
|
847
1222
|
this._ctx = new Context2(void 0, {
|
848
1223
|
F: __dxlog_file4,
|
@@ -932,13 +1307,41 @@ var SpaceAwarenessProvider = class {
|
|
932
1307
|
this._remoteStates.set(message.state.peerId, message.state);
|
933
1308
|
this.remoteStateChange.emit();
|
934
1309
|
}
|
1310
|
+
constructor(params) {
|
1311
|
+
_define_property8(this, "_remoteStates", /* @__PURE__ */ new Map());
|
1312
|
+
_define_property8(this, "_space", void 0);
|
1313
|
+
_define_property8(this, "_channel", void 0);
|
1314
|
+
_define_property8(this, "_peerId", void 0);
|
1315
|
+
_define_property8(this, "_info", void 0);
|
1316
|
+
_define_property8(this, "_ctx", void 0);
|
1317
|
+
_define_property8(this, "_postTask", void 0);
|
1318
|
+
_define_property8(this, "_localState", void 0);
|
1319
|
+
_define_property8(this, "remoteStateChange", new Event2());
|
1320
|
+
this._space = params.space;
|
1321
|
+
this._channel = params.channel;
|
1322
|
+
this._peerId = params.peerId;
|
1323
|
+
this._info = params.info;
|
1324
|
+
}
|
935
1325
|
};
|
936
1326
|
|
937
1327
|
// src/extensions/blast.ts
|
938
|
-
import { EditorView as
|
1328
|
+
import { EditorView as EditorView6, keymap as keymap2 } from "@codemirror/view";
|
939
1329
|
import defaultsDeep from "lodash.defaultsdeep";
|
940
1330
|
import { throttle } from "@dxos/async";
|
941
1331
|
import { invariant as invariant2 } from "@dxos/invariant";
|
1332
|
+
function _define_property9(obj, key, value) {
|
1333
|
+
if (key in obj) {
|
1334
|
+
Object.defineProperty(obj, key, {
|
1335
|
+
value,
|
1336
|
+
enumerable: true,
|
1337
|
+
configurable: true,
|
1338
|
+
writable: true
|
1339
|
+
});
|
1340
|
+
} else {
|
1341
|
+
obj[key] = value;
|
1342
|
+
}
|
1343
|
+
return obj;
|
1344
|
+
}
|
942
1345
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
|
943
1346
|
var defaultOptions = {
|
944
1347
|
effect: 2,
|
@@ -984,7 +1387,7 @@ var blast = (options = defaultOptions) => {
|
|
984
1387
|
};
|
985
1388
|
return [
|
986
1389
|
// Cursor moved.
|
987
|
-
|
1390
|
+
EditorView6.updateListener.of((update2) => {
|
988
1391
|
if (blaster?.node !== update2.view.scrollDOM) {
|
989
1392
|
if (blaster) {
|
990
1393
|
blaster.destroy();
|
@@ -1033,34 +1436,6 @@ var blast = (options = defaultOptions) => {
|
|
1033
1436
|
];
|
1034
1437
|
};
|
1035
1438
|
var Blaster = class {
|
1036
|
-
constructor(_node, _options) {
|
1037
|
-
this._node = _node;
|
1038
|
-
this._options = _options;
|
1039
|
-
this._running = false;
|
1040
|
-
this._shakeTime = 0;
|
1041
|
-
this._shakeTimeMax = 0;
|
1042
|
-
this._particles = [];
|
1043
|
-
this._particlePointer = 0;
|
1044
|
-
this._lastPoint = {
|
1045
|
-
x: 0,
|
1046
|
-
y: 0
|
1047
|
-
};
|
1048
|
-
this.shake = throttle(({ time }) => {
|
1049
|
-
this._shakeTime = this._shakeTimeMax || time;
|
1050
|
-
this._shakeTimeMax = time;
|
1051
|
-
}, 100);
|
1052
|
-
this.spawn = throttle(({ element, point }) => {
|
1053
|
-
const color = getRGBComponents(element, this._options.color);
|
1054
|
-
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
1055
|
-
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
1056
|
-
this._lastPoint = point;
|
1057
|
-
for (let i = numParticles; i--; i > 0) {
|
1058
|
-
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
1059
|
-
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
1060
|
-
}
|
1061
|
-
}, 100);
|
1062
|
-
this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
|
1063
|
-
}
|
1064
1439
|
get node() {
|
1065
1440
|
return this._node;
|
1066
1441
|
}
|
@@ -1124,7 +1499,7 @@ var Blaster = class {
|
|
1124
1499
|
}
|
1125
1500
|
this._ctx.clearRect(0, 0, this._canvas.width ?? 0, this._canvas.height ?? 0);
|
1126
1501
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
1127
|
-
this._lastTime
|
1502
|
+
this._lastTime ?? (this._lastTime = now);
|
1128
1503
|
const dt = (now - this._lastTime) / 1e3;
|
1129
1504
|
this._lastTime = now;
|
1130
1505
|
if (this._shakeTime > 0) {
|
@@ -1149,9 +1524,52 @@ var Blaster = class {
|
|
1149
1524
|
this._effect.update(this._ctx, particle);
|
1150
1525
|
}
|
1151
1526
|
}
|
1527
|
+
constructor(_node, _options) {
|
1528
|
+
_define_property9(this, "_node", void 0);
|
1529
|
+
_define_property9(this, "_options", void 0);
|
1530
|
+
_define_property9(this, "_effect", void 0);
|
1531
|
+
_define_property9(this, "_canvas", void 0);
|
1532
|
+
_define_property9(this, "_ctx", void 0);
|
1533
|
+
_define_property9(this, "_running", void 0);
|
1534
|
+
_define_property9(this, "_lastTime", void 0);
|
1535
|
+
_define_property9(this, "_shakeTime", void 0);
|
1536
|
+
_define_property9(this, "_shakeTimeMax", void 0);
|
1537
|
+
_define_property9(this, "_particles", void 0);
|
1538
|
+
_define_property9(this, "_particlePointer", void 0);
|
1539
|
+
_define_property9(this, "_lastPoint", void 0);
|
1540
|
+
_define_property9(this, "shake", void 0);
|
1541
|
+
_define_property9(this, "spawn", void 0);
|
1542
|
+
this._node = _node;
|
1543
|
+
this._options = _options;
|
1544
|
+
this._running = false;
|
1545
|
+
this._shakeTime = 0;
|
1546
|
+
this._shakeTimeMax = 0;
|
1547
|
+
this._particles = [];
|
1548
|
+
this._particlePointer = 0;
|
1549
|
+
this._lastPoint = {
|
1550
|
+
x: 0,
|
1551
|
+
y: 0
|
1552
|
+
};
|
1553
|
+
this.shake = throttle(({ time }) => {
|
1554
|
+
this._shakeTime = this._shakeTimeMax || time;
|
1555
|
+
this._shakeTimeMax = time;
|
1556
|
+
}, 100);
|
1557
|
+
this.spawn = throttle(({ element, point }) => {
|
1558
|
+
const color = getRGBComponents(element, this._options.color);
|
1559
|
+
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
1560
|
+
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
1561
|
+
this._lastPoint = point;
|
1562
|
+
for (let i = numParticles; i--; i > 0) {
|
1563
|
+
this._particles[this._particlePointer] = this._effect.create(point.x - dir * 16, point.y, color);
|
1564
|
+
this._particlePointer = (this._particlePointer + 1) % this._options.maxParticles;
|
1565
|
+
}
|
1566
|
+
}, 100);
|
1567
|
+
this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
|
1568
|
+
}
|
1152
1569
|
};
|
1153
1570
|
var Effect = class {
|
1154
1571
|
constructor(_options) {
|
1572
|
+
_define_property9(this, "_options", void 0);
|
1155
1573
|
this._options = _options;
|
1156
1574
|
}
|
1157
1575
|
};
|
@@ -1234,7 +1652,7 @@ var random = (min, max) => {
|
|
1234
1652
|
};
|
1235
1653
|
|
1236
1654
|
// src/extensions/command/action.ts
|
1237
|
-
import { StateEffect as
|
1655
|
+
import { StateEffect as StateEffect3 } from "@codemirror/state";
|
1238
1656
|
|
1239
1657
|
// src/extensions/command/state.ts
|
1240
1658
|
import { StateField as StateField2 } from "@codemirror/state";
|
@@ -1307,8 +1725,8 @@ var commandState = StateField2.define({
|
|
1307
1725
|
});
|
1308
1726
|
|
1309
1727
|
// src/extensions/command/action.ts
|
1310
|
-
var openEffect =
|
1311
|
-
var closeEffect =
|
1728
|
+
var openEffect = StateEffect3.define();
|
1729
|
+
var closeEffect = StateEffect3.define();
|
1312
1730
|
var openCommand = (view) => {
|
1313
1731
|
if (view.state.field(commandState, false)) {
|
1314
1732
|
const selection = view.state.selection.main;
|
@@ -1337,7 +1755,6 @@ var closeCommand = (view) => {
|
|
1337
1755
|
var commandKeyBindings = [
|
1338
1756
|
{
|
1339
1757
|
key: "/",
|
1340
|
-
preventDefault: true,
|
1341
1758
|
run: openCommand
|
1342
1759
|
},
|
1343
1760
|
{
|
@@ -1347,18 +1764,28 @@ var commandKeyBindings = [
|
|
1347
1764
|
];
|
1348
1765
|
|
1349
1766
|
// src/extensions/command/command.ts
|
1350
|
-
import { Prec } from "@codemirror/state";
|
1351
|
-
import { EditorView as
|
1767
|
+
import { Prec as Prec2 } from "@codemirror/state";
|
1768
|
+
import { EditorView as EditorView8, keymap as keymap3 } from "@codemirror/view";
|
1352
1769
|
import { isNonNullable } from "@dxos/util";
|
1353
1770
|
|
1354
1771
|
// src/extensions/command/hint.ts
|
1355
1772
|
import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
|
1356
|
-
import { Decoration as
|
1773
|
+
import { Decoration as Decoration4, EditorView as EditorView7, ViewPlugin as ViewPlugin6, WidgetType as WidgetType3 } from "@codemirror/view";
|
1774
|
+
function _define_property10(obj, key, value) {
|
1775
|
+
if (key in obj) {
|
1776
|
+
Object.defineProperty(obj, key, {
|
1777
|
+
value,
|
1778
|
+
enumerable: true,
|
1779
|
+
configurable: true,
|
1780
|
+
writable: true
|
1781
|
+
});
|
1782
|
+
} else {
|
1783
|
+
obj[key] = value;
|
1784
|
+
}
|
1785
|
+
return obj;
|
1786
|
+
}
|
1357
1787
|
var hint = ({ delay = 3e3, onHint }) => {
|
1358
|
-
return
|
1359
|
-
constructor() {
|
1360
|
-
this.decorations = Decoration3.none;
|
1361
|
-
}
|
1788
|
+
return ViewPlugin6.fromClass(class {
|
1362
1789
|
update(update2) {
|
1363
1790
|
if (this.timeout) {
|
1364
1791
|
clearTimeout(this.timeout);
|
@@ -1374,7 +1801,7 @@ var hint = ({ delay = 3e3, onHint }) => {
|
|
1374
1801
|
const hint2 = onHint?.();
|
1375
1802
|
if (hint2) {
|
1376
1803
|
const builder2 = new RangeSetBuilder2();
|
1377
|
-
builder2.add(selection.from, selection.to,
|
1804
|
+
builder2.add(selection.from, selection.to, Decoration4.widget({
|
1378
1805
|
widget: new Hint(hint2)
|
1379
1806
|
}));
|
1380
1807
|
this.decorations = builder2.finish();
|
@@ -1390,16 +1817,17 @@ var hint = ({ delay = 3e3, onHint }) => {
|
|
1390
1817
|
clearTimeout(this.timeout);
|
1391
1818
|
}
|
1392
1819
|
}
|
1820
|
+
constructor() {
|
1821
|
+
_define_property10(this, "decorations", Decoration4.none);
|
1822
|
+
_define_property10(this, "timeout", void 0);
|
1823
|
+
}
|
1393
1824
|
}, {
|
1394
1825
|
provide: (plugin) => [
|
1395
|
-
|
1826
|
+
EditorView7.decorations.of((view) => view.plugin(plugin)?.decorations ?? Decoration4.none)
|
1396
1827
|
]
|
1397
1828
|
});
|
1398
1829
|
};
|
1399
|
-
var Hint = class extends
|
1400
|
-
constructor(content) {
|
1401
|
-
super(), this.content = content;
|
1402
|
-
}
|
1830
|
+
var Hint = class extends WidgetType3 {
|
1403
1831
|
toDOM() {
|
1404
1832
|
const wrap = document.createElement("span");
|
1405
1833
|
wrap.className = "cm-placeholder";
|
@@ -1419,13 +1847,13 @@ var Hint = class extends WidgetType2 {
|
|
1419
1847
|
}
|
1420
1848
|
const style = window.getComputedStyle(dom.parentNode);
|
1421
1849
|
const rect = flattenRect(rects[0], style.direction !== "rtl");
|
1422
|
-
const
|
1423
|
-
if (rect.bottom - rect.top >
|
1850
|
+
const lineHeight2 = parseInt(style.lineHeight);
|
1851
|
+
if (rect.bottom - rect.top > lineHeight2 * 1.5) {
|
1424
1852
|
return {
|
1425
1853
|
left: rect.left,
|
1426
1854
|
right: rect.right,
|
1427
1855
|
top: rect.top,
|
1428
|
-
bottom: rect.top +
|
1856
|
+
bottom: rect.top + lineHeight2
|
1429
1857
|
};
|
1430
1858
|
}
|
1431
1859
|
return rect;
|
@@ -1433,17 +1861,20 @@ var Hint = class extends WidgetType2 {
|
|
1433
1861
|
ignoreEvent() {
|
1434
1862
|
return false;
|
1435
1863
|
}
|
1864
|
+
constructor(content) {
|
1865
|
+
super(), _define_property10(this, "content", void 0), this.content = content;
|
1866
|
+
}
|
1436
1867
|
};
|
1437
1868
|
|
1438
1869
|
// src/extensions/command/command.ts
|
1439
1870
|
var command = (options = {}) => {
|
1440
1871
|
return [
|
1441
|
-
|
1872
|
+
Prec2.highest(keymap3.of(commandKeyBindings)),
|
1442
1873
|
commandConfig.of(options),
|
1443
1874
|
commandState,
|
1444
1875
|
options.onHint && hint(options),
|
1445
|
-
|
1446
|
-
|
1876
|
+
EditorView8.focusChangeEffect.of((_, focusing) => focusing ? closeEffect.of(null) : null),
|
1877
|
+
EditorView8.theme({
|
1447
1878
|
".cm-tooltip": {
|
1448
1879
|
background: "transparent"
|
1449
1880
|
}
|
@@ -1452,16 +1883,26 @@ var command = (options = {}) => {
|
|
1452
1883
|
};
|
1453
1884
|
|
1454
1885
|
// src/extensions/command/command-menu.ts
|
1455
|
-
import {
|
1456
|
-
import {
|
1886
|
+
import { Prec as Prec3, RangeSetBuilder as RangeSetBuilder3, StateEffect as StateEffect4, StateField as StateField3 } from "@codemirror/state";
|
1887
|
+
import { Decoration as Decoration6, EditorView as EditorView10, ViewPlugin as ViewPlugin8, keymap as keymap4 } from "@codemirror/view";
|
1457
1888
|
|
1458
1889
|
// src/extensions/command/placeholder.ts
|
1459
|
-
import { Decoration as
|
1890
|
+
import { Decoration as Decoration5, EditorView as EditorView9, ViewPlugin as ViewPlugin7, WidgetType as WidgetType4 } from "@codemirror/view";
|
1891
|
+
function _define_property11(obj, key, value) {
|
1892
|
+
if (key in obj) {
|
1893
|
+
Object.defineProperty(obj, key, {
|
1894
|
+
value,
|
1895
|
+
enumerable: true,
|
1896
|
+
configurable: true,
|
1897
|
+
writable: true
|
1898
|
+
});
|
1899
|
+
} else {
|
1900
|
+
obj[key] = value;
|
1901
|
+
}
|
1902
|
+
return obj;
|
1903
|
+
}
|
1460
1904
|
var placeholder = ({ delay = 3e3, content }) => {
|
1461
|
-
const plugin =
|
1462
|
-
constructor() {
|
1463
|
-
this.decorations = Decoration4.none;
|
1464
|
-
}
|
1905
|
+
const plugin = ViewPlugin7.fromClass(class {
|
1465
1906
|
update(update2) {
|
1466
1907
|
if (this.timeout) {
|
1467
1908
|
window.clearTimeout(this.timeout);
|
@@ -1472,8 +1913,8 @@ var placeholder = ({ delay = 3e3, content }) => {
|
|
1472
1913
|
if (isEmpty) {
|
1473
1914
|
const lineStart = activeLine.from;
|
1474
1915
|
this.timeout = setTimeout(() => {
|
1475
|
-
this.decorations =
|
1476
|
-
|
1916
|
+
this.decorations = Decoration5.set([
|
1917
|
+
Decoration5.widget({
|
1477
1918
|
widget: new Placeholder(content),
|
1478
1919
|
side: 1
|
1479
1920
|
}).range(lineStart)
|
@@ -1481,31 +1922,32 @@ var placeholder = ({ delay = 3e3, content }) => {
|
|
1481
1922
|
update2.view.update([]);
|
1482
1923
|
}, delay);
|
1483
1924
|
}
|
1484
|
-
this.decorations =
|
1925
|
+
this.decorations = Decoration5.none;
|
1485
1926
|
}
|
1486
1927
|
destroy() {
|
1487
1928
|
if (this.timeout) {
|
1488
1929
|
clearTimeout(this.timeout);
|
1489
1930
|
}
|
1490
1931
|
}
|
1932
|
+
constructor() {
|
1933
|
+
_define_property11(this, "decorations", Decoration5.none);
|
1934
|
+
_define_property11(this, "timeout", void 0);
|
1935
|
+
}
|
1491
1936
|
}, {
|
1492
1937
|
provide: (plugin2) => {
|
1493
1938
|
return [
|
1494
|
-
|
1939
|
+
EditorView9.decorations.of((view) => view.plugin(plugin2)?.decorations ?? Decoration5.none)
|
1495
1940
|
];
|
1496
1941
|
}
|
1497
1942
|
});
|
1498
1943
|
return typeof content === "string" ? [
|
1499
1944
|
plugin,
|
1500
|
-
|
1945
|
+
EditorView9.contentAttributes.of({
|
1501
1946
|
"aria-placeholder": content
|
1502
1947
|
})
|
1503
1948
|
] : plugin;
|
1504
1949
|
};
|
1505
|
-
var Placeholder = class extends
|
1506
|
-
constructor(content) {
|
1507
|
-
super(), this.content = content;
|
1508
|
-
}
|
1950
|
+
var Placeholder = class extends WidgetType4 {
|
1509
1951
|
toDOM(view) {
|
1510
1952
|
const wrap = document.createElement("span");
|
1511
1953
|
wrap.className = "cm-placeholder";
|
@@ -1521,13 +1963,13 @@ var Placeholder = class extends WidgetType3 {
|
|
1521
1963
|
}
|
1522
1964
|
const style = window.getComputedStyle(dom.parentNode);
|
1523
1965
|
const rect = flattenRect(rects[0], style.direction !== "rtl");
|
1524
|
-
const
|
1525
|
-
if (rect.bottom - rect.top >
|
1966
|
+
const lineHeight2 = parseInt(style.lineHeight);
|
1967
|
+
if (rect.bottom - rect.top > lineHeight2 * 1.5) {
|
1526
1968
|
return {
|
1527
1969
|
left: rect.left,
|
1528
1970
|
right: rect.right,
|
1529
1971
|
top: rect.top,
|
1530
|
-
bottom: rect.top +
|
1972
|
+
bottom: rect.top + lineHeight2
|
1531
1973
|
};
|
1532
1974
|
}
|
1533
1975
|
return rect;
|
@@ -1535,15 +1977,27 @@ var Placeholder = class extends WidgetType3 {
|
|
1535
1977
|
ignoreEvent() {
|
1536
1978
|
return false;
|
1537
1979
|
}
|
1980
|
+
constructor(content) {
|
1981
|
+
super(), _define_property11(this, "content", void 0), this.content = content;
|
1982
|
+
}
|
1538
1983
|
};
|
1539
1984
|
|
1540
1985
|
// src/extensions/command/command-menu.ts
|
1986
|
+
function _define_property12(obj, key, value) {
|
1987
|
+
if (key in obj) {
|
1988
|
+
Object.defineProperty(obj, key, {
|
1989
|
+
value,
|
1990
|
+
enumerable: true,
|
1991
|
+
configurable: true,
|
1992
|
+
writable: true
|
1993
|
+
});
|
1994
|
+
} else {
|
1995
|
+
obj[key] = value;
|
1996
|
+
}
|
1997
|
+
return obj;
|
1998
|
+
}
|
1541
1999
|
var commandMenu = (options) => {
|
1542
|
-
const commandMenuPlugin =
|
1543
|
-
constructor(view) {
|
1544
|
-
this.view = view;
|
1545
|
-
this.decorations = Decoration5.none;
|
1546
|
-
}
|
2000
|
+
const commandMenuPlugin = ViewPlugin8.fromClass(class {
|
1547
2001
|
// TODO(wittjosiah): The decorations are repainted on every update, this occasionally causes menu to flicker.
|
1548
2002
|
update(update2) {
|
1549
2003
|
const builder = new RangeSetBuilder3();
|
@@ -1551,9 +2005,9 @@ var commandMenu = (options) => {
|
|
1551
2005
|
const { range: activeRange, trigger } = update2.view.state.field(commandMenuState) ?? {};
|
1552
2006
|
const shouldShowWidget = activeRange && selection.head >= activeRange.from && selection.head <= activeRange.to;
|
1553
2007
|
if (shouldShowWidget) {
|
1554
|
-
builder.add(activeRange.from, activeRange.to,
|
1555
|
-
tagName: "dx-
|
1556
|
-
class: "cm-
|
2008
|
+
builder.add(activeRange.from, activeRange.to, Decoration6.mark({
|
2009
|
+
tagName: "dx-anchor",
|
2010
|
+
class: "cm-floating-menu-trigger",
|
1557
2011
|
attributes: {
|
1558
2012
|
"data-auto-trigger": "true",
|
1559
2013
|
"data-trigger": trigger
|
@@ -1567,6 +2021,12 @@ var commandMenu = (options) => {
|
|
1567
2021
|
}
|
1568
2022
|
this.decorations = builder.finish();
|
1569
2023
|
}
|
2024
|
+
constructor(view) {
|
2025
|
+
_define_property12(this, "view", void 0);
|
2026
|
+
_define_property12(this, "decorations", void 0);
|
2027
|
+
this.view = view;
|
2028
|
+
this.decorations = Decoration6.none;
|
2029
|
+
}
|
1570
2030
|
}, {
|
1571
2031
|
decorations: (v) => v.decorations
|
1572
2032
|
});
|
@@ -1644,7 +2104,7 @@ var commandMenu = (options) => {
|
|
1644
2104
|
}
|
1645
2105
|
}
|
1646
2106
|
]);
|
1647
|
-
const updateListener =
|
2107
|
+
const updateListener = EditorView10.updateListener.of((update2) => {
|
1648
2108
|
const { trigger, range: activeRange } = update2.view.state.field(commandMenuState) ?? {};
|
1649
2109
|
if (!activeRange || !trigger) {
|
1650
2110
|
return;
|
@@ -1671,7 +2131,7 @@ var commandMenu = (options) => {
|
|
1671
2131
|
}
|
1672
2132
|
});
|
1673
2133
|
return [
|
1674
|
-
|
2134
|
+
Prec3.highest(commandKeymap),
|
1675
2135
|
placeholder(Object.assign({
|
1676
2136
|
content: `Press '${Array.isArray(options.trigger) ? options.trigger[0] : options.trigger}' for commands`
|
1677
2137
|
}, options.placeholder)),
|
@@ -1680,7 +2140,7 @@ var commandMenu = (options) => {
|
|
1680
2140
|
commandMenuPlugin
|
1681
2141
|
];
|
1682
2142
|
};
|
1683
|
-
var commandRangeEffect =
|
2143
|
+
var commandRangeEffect = StateEffect4.define();
|
1684
2144
|
var commandMenuState = StateField3.define({
|
1685
2145
|
create: () => null,
|
1686
2146
|
update: (value, tr) => {
|
@@ -1695,30 +2155,23 @@ var commandMenuState = StateField3.define({
|
|
1695
2155
|
});
|
1696
2156
|
|
1697
2157
|
// src/extensions/command/floating-menu.ts
|
1698
|
-
import { EditorView as
|
2158
|
+
import { EditorView as EditorView11, ViewPlugin as ViewPlugin9 } from "@codemirror/view";
|
1699
2159
|
import { addEventListener } from "@dxos/async";
|
2160
|
+
function _define_property13(obj, key, value) {
|
2161
|
+
if (key in obj) {
|
2162
|
+
Object.defineProperty(obj, key, {
|
2163
|
+
value,
|
2164
|
+
enumerable: true,
|
2165
|
+
configurable: true,
|
2166
|
+
writable: true
|
2167
|
+
});
|
2168
|
+
} else {
|
2169
|
+
obj[key] = value;
|
2170
|
+
}
|
2171
|
+
return obj;
|
2172
|
+
}
|
1700
2173
|
var floatingMenu = (options = {}) => [
|
1701
|
-
|
1702
|
-
constructor(view) {
|
1703
|
-
this.view = view;
|
1704
|
-
const container = view.scrollDOM;
|
1705
|
-
if (getComputedStyle(container).position === "static") {
|
1706
|
-
container.style.position = "relative";
|
1707
|
-
}
|
1708
|
-
{
|
1709
|
-
const icon = document.createElement("dx-icon");
|
1710
|
-
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
1711
|
-
const button = document.createElement("button");
|
1712
|
-
button.appendChild(icon);
|
1713
|
-
this.tag = document.createElement("dx-ref-tag");
|
1714
|
-
this.tag.classList.add("cm-ref-tag");
|
1715
|
-
this.tag.appendChild(button);
|
1716
|
-
}
|
1717
|
-
container.appendChild(this.tag);
|
1718
|
-
const handler = () => this.scheduleUpdate();
|
1719
|
-
this.cleanup = addEventListener(container, "scroll", handler);
|
1720
|
-
this.scheduleUpdate();
|
1721
|
-
}
|
2174
|
+
ViewPlugin9.fromClass(class {
|
1722
2175
|
destroy() {
|
1723
2176
|
this.cleanup?.();
|
1724
2177
|
this.tag.remove();
|
@@ -1735,7 +2188,7 @@ var floatingMenu = (options = {}) => [
|
|
1735
2188
|
this.tag.style.display = "none";
|
1736
2189
|
this.tag.classList.add("opacity-10");
|
1737
2190
|
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
1738
|
-
this.tag.style.display = "
|
2191
|
+
this.tag.style.display = "";
|
1739
2192
|
} else if (update2.docChanged || update2.focusChanged || update2.geometryChanged || update2.selectionSet || update2.viewportChanged) {
|
1740
2193
|
this.scheduleUpdate();
|
1741
2194
|
}
|
@@ -1748,13 +2201,13 @@ var floatingMenu = (options = {}) => [
|
|
1748
2201
|
if (!coords) {
|
1749
2202
|
return;
|
1750
2203
|
}
|
1751
|
-
const
|
1752
|
-
const dy = (
|
2204
|
+
const lineHeight2 = coords.bottom - coords.top;
|
2205
|
+
const dy = (lineHeight2 - (options.height ?? 32)) / 2;
|
1753
2206
|
const offsetTop = coords.top + dy;
|
1754
2207
|
const offsetLeft = x + width + (options.padding ?? 8);
|
1755
2208
|
this.tag.style.top = `${offsetTop}px`;
|
1756
2209
|
this.tag.style.left = `${offsetLeft}px`;
|
1757
|
-
this.tag.style.display = "
|
2210
|
+
this.tag.style.display = "";
|
1758
2211
|
}
|
1759
2212
|
scheduleUpdate() {
|
1760
2213
|
if (this.rafId != null) {
|
@@ -1762,30 +2215,62 @@ var floatingMenu = (options = {}) => [
|
|
1762
2215
|
}
|
1763
2216
|
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1764
2217
|
}
|
2218
|
+
constructor(view) {
|
2219
|
+
_define_property13(this, "view", void 0);
|
2220
|
+
_define_property13(this, "tag", void 0);
|
2221
|
+
_define_property13(this, "rafId", void 0);
|
2222
|
+
_define_property13(this, "cleanup", void 0);
|
2223
|
+
this.view = view;
|
2224
|
+
const container = view.scrollDOM;
|
2225
|
+
if (getComputedStyle(container).position === "static") {
|
2226
|
+
container.style.position = "relative";
|
2227
|
+
}
|
2228
|
+
{
|
2229
|
+
const icon = document.createElement("dx-icon");
|
2230
|
+
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
2231
|
+
this.tag = document.createElement("dx-anchor");
|
2232
|
+
this.tag.classList.add("cm-floating-menu-trigger");
|
2233
|
+
this.tag.appendChild(icon);
|
2234
|
+
}
|
2235
|
+
container.appendChild(this.tag);
|
2236
|
+
const handler = () => this.scheduleUpdate();
|
2237
|
+
this.cleanup = addEventListener(container, "scroll", handler);
|
2238
|
+
this.scheduleUpdate();
|
2239
|
+
}
|
1765
2240
|
}),
|
1766
|
-
|
1767
|
-
".cm-
|
2241
|
+
EditorView11.theme({
|
2242
|
+
".cm-floating-menu-trigger": {
|
1768
2243
|
position: "fixed",
|
1769
2244
|
padding: "0",
|
1770
2245
|
border: "none",
|
1771
|
-
opacity: "0"
|
1772
|
-
},
|
1773
|
-
"[data-has-focus] & .cm-ref-tag": {
|
1774
|
-
opacity: "1"
|
1775
|
-
},
|
1776
|
-
".cm-ref-tag button": {
|
2246
|
+
opacity: "0",
|
1777
2247
|
display: "grid",
|
1778
|
-
|
1779
|
-
justifyContent: "center",
|
2248
|
+
placeContent: "center",
|
1780
2249
|
width: "2rem",
|
1781
2250
|
height: "2rem"
|
2251
|
+
},
|
2252
|
+
"&:focus-within .cm-floating-menu-trigger": {
|
2253
|
+
opacity: "1"
|
1782
2254
|
}
|
1783
2255
|
})
|
1784
2256
|
];
|
1785
2257
|
|
1786
2258
|
// src/extensions/command/typeahead.ts
|
1787
|
-
import { EditorSelection, Prec as
|
1788
|
-
import { Decoration as
|
2259
|
+
import { EditorSelection, Prec as Prec4, RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
2260
|
+
import { Decoration as Decoration7, ViewPlugin as ViewPlugin10, keymap as keymap5 } from "@codemirror/view";
|
2261
|
+
function _define_property14(obj, key, value) {
|
2262
|
+
if (key in obj) {
|
2263
|
+
Object.defineProperty(obj, key, {
|
2264
|
+
value,
|
2265
|
+
enumerable: true,
|
2266
|
+
configurable: true,
|
2267
|
+
writable: true
|
2268
|
+
});
|
2269
|
+
} else {
|
2270
|
+
obj[key] = value;
|
2271
|
+
}
|
2272
|
+
return obj;
|
2273
|
+
}
|
1789
2274
|
var typeahead = ({ onComplete } = {}) => {
|
1790
2275
|
let hint2;
|
1791
2276
|
const complete = (view) => {
|
@@ -1806,10 +2291,7 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1806
2291
|
return true;
|
1807
2292
|
};
|
1808
2293
|
return [
|
1809
|
-
|
1810
|
-
constructor() {
|
1811
|
-
this.decorations = Decoration6.none;
|
1812
|
-
}
|
2294
|
+
ViewPlugin10.fromClass(class {
|
1813
2295
|
update(update2) {
|
1814
2296
|
const builder = new RangeSetBuilder4();
|
1815
2297
|
const selection = update2.view.state.selection.main;
|
@@ -1820,18 +2302,21 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1820
2302
|
line: str
|
1821
2303
|
});
|
1822
2304
|
if (hint2) {
|
1823
|
-
builder.add(selection.from, selection.to,
|
2305
|
+
builder.add(selection.from, selection.to, Decoration7.widget({
|
1824
2306
|
widget: new Hint(hint2)
|
1825
2307
|
}));
|
1826
2308
|
}
|
1827
2309
|
}
|
1828
2310
|
this.decorations = builder.finish();
|
1829
2311
|
}
|
2312
|
+
constructor() {
|
2313
|
+
_define_property14(this, "decorations", Decoration7.none);
|
2314
|
+
}
|
1830
2315
|
}, {
|
1831
2316
|
decorations: (v) => v.decorations
|
1832
2317
|
}),
|
1833
2318
|
// Keys.
|
1834
|
-
|
2319
|
+
Prec4.highest(keymap5.of([
|
1835
2320
|
{
|
1836
2321
|
key: "Tab",
|
1837
2322
|
preventDefault: true,
|
@@ -1871,7 +2356,6 @@ var matchCompletion = (completion, str, minLength = 0) => {
|
|
1871
2356
|
// src/extensions/command/useCommandMenu.ts
|
1872
2357
|
import { useCallback, useMemo, useRef, useState } from "react";
|
1873
2358
|
var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu }) => {
|
1874
|
-
const triggerRef = useRef(null);
|
1875
2359
|
const currentRef = useRef(null);
|
1876
2360
|
const groupsRef = useRef([]);
|
1877
2361
|
const [currentItem, setCurrentItem] = useState();
|
@@ -1883,7 +2367,6 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu })
|
|
1883
2367
|
}
|
1884
2368
|
setOpen(open2);
|
1885
2369
|
if (!open2) {
|
1886
|
-
triggerRef.current = null;
|
1887
2370
|
setCurrentItem(void 0);
|
1888
2371
|
viewRef.current?.dispatch({
|
1889
2372
|
effects: [
|
@@ -1899,7 +2382,6 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu })
|
|
1899
2382
|
if (item) {
|
1900
2383
|
currentRef.current = item;
|
1901
2384
|
}
|
1902
|
-
triggerRef.current = event.trigger;
|
1903
2385
|
const triggerKey = event.trigger.getAttribute("data-trigger");
|
1904
2386
|
if (!open && triggerKey) {
|
1905
2387
|
await handleOpenChange(true, triggerKey);
|
@@ -1917,7 +2399,7 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu })
|
|
1917
2399
|
void item.onSelect?.(view, selection.head);
|
1918
2400
|
}, []);
|
1919
2401
|
const serializedTrigger = Array.isArray(trigger) ? trigger.join(",") : trigger;
|
1920
|
-
const
|
2402
|
+
const memoizedCommandMenu = useMemo(() => {
|
1921
2403
|
return commandMenu({
|
1922
2404
|
trigger,
|
1923
2405
|
placeholder: placeholder3,
|
@@ -1958,10 +2440,9 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu })
|
|
1958
2440
|
placeholder3
|
1959
2441
|
]);
|
1960
2442
|
return {
|
1961
|
-
commandMenu:
|
2443
|
+
commandMenu: memoizedCommandMenu,
|
1962
2444
|
currentItem,
|
1963
2445
|
groupsRef,
|
1964
|
-
ref: triggerRef,
|
1965
2446
|
open,
|
1966
2447
|
onActivate: handleActivate,
|
1967
2448
|
onOpenChange: setOpen,
|
@@ -1971,8 +2452,8 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu })
|
|
1971
2452
|
|
1972
2453
|
// src/extensions/comments.ts
|
1973
2454
|
import { invertedEffects } from "@codemirror/commands";
|
1974
|
-
import { StateEffect as
|
1975
|
-
import {
|
2455
|
+
import { StateEffect as StateEffect5, StateField as StateField4 } from "@codemirror/state";
|
2456
|
+
import { Decoration as Decoration8, EditorView as EditorView13, ViewPlugin as ViewPlugin11, hoverTooltip, keymap as keymap7 } from "@codemirror/view";
|
1976
2457
|
import sortBy from "lodash.sortby";
|
1977
2458
|
import { useEffect } from "react";
|
1978
2459
|
import { debounce as debounce2 } from "@dxos/async";
|
@@ -1981,7 +2462,7 @@ import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
1981
2462
|
|
1982
2463
|
// src/extensions/selection.ts
|
1983
2464
|
import { Transaction } from "@codemirror/state";
|
1984
|
-
import { EditorView as
|
2465
|
+
import { EditorView as EditorView12, keymap as keymap6 } from "@codemirror/view";
|
1985
2466
|
import { debounce } from "@dxos/async";
|
1986
2467
|
import { invariant as invariant3 } from "@dxos/invariant";
|
1987
2468
|
import { isNotFalsy } from "@dxos/util";
|
@@ -1992,7 +2473,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
1992
2473
|
return {
|
1993
2474
|
selection,
|
1994
2475
|
scrollIntoView: !scrollTo,
|
1995
|
-
effects: scrollTo ?
|
2476
|
+
effects: scrollTo ? EditorView12.scrollIntoView(scrollTo, {
|
1996
2477
|
yMargin: 96
|
1997
2478
|
}) : void 0,
|
1998
2479
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
@@ -2034,7 +2515,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
2034
2515
|
// setStateDebounced(id, {});
|
2035
2516
|
// },
|
2036
2517
|
// }),
|
2037
|
-
|
2518
|
+
EditorView12.updateListener.of(({ view, transactions }) => {
|
2038
2519
|
const id = view.state.facet(documentId);
|
2039
2520
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
2040
2521
|
return;
|
@@ -2073,10 +2554,23 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
2073
2554
|
};
|
2074
2555
|
|
2075
2556
|
// src/extensions/comments.ts
|
2557
|
+
function _define_property15(obj, key, value) {
|
2558
|
+
if (key in obj) {
|
2559
|
+
Object.defineProperty(obj, key, {
|
2560
|
+
value,
|
2561
|
+
enumerable: true,
|
2562
|
+
configurable: true,
|
2563
|
+
writable: true
|
2564
|
+
});
|
2565
|
+
} else {
|
2566
|
+
obj[key] = value;
|
2567
|
+
}
|
2568
|
+
return obj;
|
2569
|
+
}
|
2076
2570
|
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
2077
|
-
var setComments =
|
2078
|
-
var setSelection =
|
2079
|
-
var setCommentState =
|
2571
|
+
var setComments = StateEffect5.define();
|
2572
|
+
var setSelection = StateEffect5.define();
|
2573
|
+
var setCommentState = StateEffect5.define();
|
2080
2574
|
var commentsState = StateField4.define({
|
2081
2575
|
create: (state) => ({
|
2082
2576
|
id: state.facet(documentId),
|
@@ -2115,27 +2609,27 @@ var commentsState = StateField4.define({
|
|
2115
2609
|
return value;
|
2116
2610
|
}
|
2117
2611
|
});
|
2118
|
-
var styles2 =
|
2612
|
+
var styles2 = EditorView13.theme({
|
2119
2613
|
".cm-comment, .cm-comment-current": {
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2614
|
+
padding: "3px 0",
|
2615
|
+
backgroundColor: "var(--dx-cmCommentSurface)"
|
2616
|
+
},
|
2617
|
+
".cm-comment > span, .cm-comment-current > span": {
|
2618
|
+
boxDecorationBreak: "clone",
|
2619
|
+
boxShadow: "0 0 1px 3px var(--dx-cmCommentSurface)",
|
2123
2620
|
backgroundColor: "var(--dx-cmCommentSurface)",
|
2124
2621
|
color: "var(--dx-cmComment)",
|
2125
2622
|
cursor: "pointer"
|
2126
|
-
},
|
2127
|
-
".cm-comment:hover, .cm-comment-current": {
|
2128
|
-
textDecoration: "underline"
|
2129
2623
|
}
|
2130
2624
|
});
|
2131
|
-
var createCommentMark = (id, isCurrent) =>
|
2625
|
+
var createCommentMark = (id, isCurrent) => Decoration8.mark({
|
2132
2626
|
class: isCurrent ? "cm-comment-current" : "cm-comment",
|
2133
2627
|
attributes: {
|
2134
2628
|
"data-testid": "cm-comment",
|
2135
2629
|
"data-comment-id": id
|
2136
2630
|
}
|
2137
2631
|
});
|
2138
|
-
var commentsDecorations =
|
2632
|
+
var commentsDecorations = EditorView13.decorations.compute([
|
2139
2633
|
commentsState
|
2140
2634
|
], (state) => {
|
2141
2635
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
@@ -2144,7 +2638,7 @@ var commentsDecorations = EditorView11.decorations.compute([
|
|
2144
2638
|
if (!range) {
|
2145
2639
|
log4.warn("Invalid range:", range, {
|
2146
2640
|
F: __dxlog_file7,
|
2147
|
-
L:
|
2641
|
+
L: 140,
|
2148
2642
|
S: void 0,
|
2149
2643
|
C: (f, a) => f(...a)
|
2150
2644
|
});
|
@@ -2155,10 +2649,10 @@ var commentsDecorations = EditorView11.decorations.compute([
|
|
2155
2649
|
const mark = createCommentMark(comment.comment.id, comment.comment.id === current);
|
2156
2650
|
return mark.range(range.from, range.to);
|
2157
2651
|
}).filter(isNonNullable2);
|
2158
|
-
return
|
2652
|
+
return Decoration8.set(decorations2);
|
2159
2653
|
});
|
2160
|
-
var commentClickedEffect =
|
2161
|
-
var handleCommentClick =
|
2654
|
+
var commentClickedEffect = StateEffect5.define();
|
2655
|
+
var handleCommentClick = EditorView13.domEventHandlers({
|
2162
2656
|
click: (event, view) => {
|
2163
2657
|
let target = event.target;
|
2164
2658
|
const editorRoot = view.dom;
|
@@ -2197,7 +2691,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2197
2691
|
}
|
2198
2692
|
};
|
2199
2693
|
return [
|
2200
|
-
|
2694
|
+
EditorView13.domEventHandlers({
|
2201
2695
|
cut: handleTrack,
|
2202
2696
|
copy: handleTrack
|
2203
2697
|
}),
|
@@ -2219,7 +2713,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2219
2713
|
return effects;
|
2220
2714
|
}),
|
2221
2715
|
// Handle paste or the undo of comment deletion.
|
2222
|
-
|
2716
|
+
EditorView13.updateListener.of((update2) => {
|
2223
2717
|
const restore = [];
|
2224
2718
|
for (let i = 0; i < update2.transactions.length; i++) {
|
2225
2719
|
const tr = update2.transactions[i];
|
@@ -2260,10 +2754,10 @@ var trackPastedComments = (onUpdate) => {
|
|
2260
2754
|
const { comments: comments2 } = update2.startState.field(commentsState);
|
2261
2755
|
const exists = comments2.some((c) => c.comment.id === comment.id && c.range.from < c.range.to);
|
2262
2756
|
if (!exists) {
|
2263
|
-
const
|
2757
|
+
const cursor2 = Cursor.getCursorFromRange(update2.state, comment);
|
2264
2758
|
onUpdate({
|
2265
2759
|
id: comment.id,
|
2266
|
-
cursor
|
2760
|
+
cursor: cursor2
|
2267
2761
|
});
|
2268
2762
|
}
|
2269
2763
|
}
|
@@ -2275,7 +2769,7 @@ var mapTrackedComment = (comment, changes) => ({
|
|
2275
2769
|
from: changes.mapPos(comment.from, 1),
|
2276
2770
|
to: changes.mapPos(comment.to, 1)
|
2277
2771
|
});
|
2278
|
-
var restoreCommentEffect =
|
2772
|
+
var restoreCommentEffect = StateEffect5.define({
|
2279
2773
|
map: mapTrackedComment
|
2280
2774
|
});
|
2281
2775
|
var createComment = (view) => {
|
@@ -2292,13 +2786,13 @@ var createComment = (view) => {
|
|
2292
2786
|
}
|
2293
2787
|
});
|
2294
2788
|
}
|
2295
|
-
const
|
2789
|
+
const cursor2 = Cursor.getCursorFromRange(view.state, {
|
2296
2790
|
from,
|
2297
2791
|
to
|
2298
2792
|
});
|
2299
|
-
if (
|
2793
|
+
if (cursor2) {
|
2300
2794
|
options.onCreate?.({
|
2301
|
-
cursor,
|
2795
|
+
cursor: cursor2,
|
2302
2796
|
from,
|
2303
2797
|
location: view.coordsAtPos(from)
|
2304
2798
|
});
|
@@ -2361,7 +2855,7 @@ var comments = (options = {}) => {
|
|
2361
2855
|
//
|
2362
2856
|
// Track deleted ranges and update ranges for decorations.
|
2363
2857
|
//
|
2364
|
-
|
2858
|
+
EditorView13.updateListener.of(({ view, state, changes }) => {
|
2365
2859
|
let mod = false;
|
2366
2860
|
const { comments: comments2, ...value } = state.field(commentsState);
|
2367
2861
|
changes.iterChanges((from, to, from2, to2) => {
|
@@ -2393,7 +2887,7 @@ var comments = (options = {}) => {
|
|
2393
2887
|
//
|
2394
2888
|
// Track selection/proximity.
|
2395
2889
|
//
|
2396
|
-
|
2890
|
+
EditorView13.updateListener.of(({ view, state }) => {
|
2397
2891
|
let min = Infinity;
|
2398
2892
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
2399
2893
|
const { head } = state.selection.main;
|
@@ -2447,7 +2941,7 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2447
2941
|
anchor: range.from
|
2448
2942
|
} : void 0,
|
2449
2943
|
effects: [
|
2450
|
-
needsScroll ?
|
2944
|
+
needsScroll ? EditorView13.scrollIntoView(range.from, center ? {
|
2451
2945
|
y: "center"
|
2452
2946
|
} : void 0) : [],
|
2453
2947
|
needsSelectionUpdate ? setSelection.of({
|
@@ -2460,9 +2954,10 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2460
2954
|
};
|
2461
2955
|
var ExternalCommentSync = class {
|
2462
2956
|
constructor(view, id, subscribe, getComments) {
|
2463
|
-
this
|
2957
|
+
_define_property15(this, "unsubscribe", void 0);
|
2958
|
+
_define_property15(this, "destroy", () => {
|
2464
2959
|
this.unsubscribe();
|
2465
|
-
};
|
2960
|
+
});
|
2466
2961
|
const updateComments = () => {
|
2467
2962
|
const comments2 = getComments();
|
2468
2963
|
if (id === view.state.facet(documentId)) {
|
@@ -2477,7 +2972,7 @@ var ExternalCommentSync = class {
|
|
2477
2972
|
this.unsubscribe = subscribe(updateComments);
|
2478
2973
|
}
|
2479
2974
|
};
|
2480
|
-
var createExternalCommentSync = (id, subscribe, getComments) =>
|
2975
|
+
var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin11.fromClass(class {
|
2481
2976
|
constructor(view) {
|
2482
2977
|
return new ExternalCommentSync(view, id, subscribe, getComments);
|
2483
2978
|
}
|
@@ -2500,9 +2995,9 @@ var useComments = (view, id, comments2) => {
|
|
2500
2995
|
// src/extensions/debug.ts
|
2501
2996
|
import { syntaxTree } from "@codemirror/language";
|
2502
2997
|
import { StateField as StateField5 } from "@codemirror/state";
|
2503
|
-
var debugNodeLogger = (
|
2998
|
+
var debugNodeLogger = (log10 = console.log) => {
|
2504
2999
|
const logTokens = (state) => syntaxTree(state).iterate({
|
2505
|
-
enter: (node) =>
|
3000
|
+
enter: (node) => log10(node.type)
|
2506
3001
|
});
|
2507
3002
|
return StateField5.define({
|
2508
3003
|
create: (state) => logTokens(state),
|
@@ -2511,8 +3006,8 @@ var debugNodeLogger = (log9 = console.log) => {
|
|
2511
3006
|
};
|
2512
3007
|
|
2513
3008
|
// src/extensions/dnd.ts
|
2514
|
-
import {
|
2515
|
-
var styles3 =
|
3009
|
+
import { EditorView as EditorView14, dropCursor } from "@codemirror/view";
|
3010
|
+
var styles3 = EditorView14.theme({
|
2516
3011
|
".cm-dropCursor": {
|
2517
3012
|
borderLeft: "2px solid var(--dx-accentText)",
|
2518
3013
|
color: "var(--dx-accentText)",
|
@@ -2526,7 +3021,7 @@ var dropFile = (options = {}) => {
|
|
2526
3021
|
return [
|
2527
3022
|
styles3,
|
2528
3023
|
dropCursor(),
|
2529
|
-
|
3024
|
+
EditorView14.domEventHandlers({
|
2530
3025
|
drop: (event, view) => {
|
2531
3026
|
event.preventDefault();
|
2532
3027
|
const files = event.dataTransfer?.files;
|
@@ -2553,50 +3048,19 @@ import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@cod
|
|
2553
3048
|
import { searchKeymap } from "@codemirror/search";
|
2554
3049
|
import { EditorState } from "@codemirror/state";
|
2555
3050
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
2556
|
-
import { EditorView as
|
3051
|
+
import { EditorView as EditorView17, ViewPlugin as ViewPlugin12, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap8, lineNumbers, placeholder as placeholder2, scrollPastEnd } from "@codemirror/view";
|
2557
3052
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
2558
3053
|
import merge from "lodash.merge";
|
2559
3054
|
import { generateName } from "@dxos/display-name";
|
2560
3055
|
import { log as log5 } from "@dxos/log";
|
2561
3056
|
import { hexToHue, isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
2562
3057
|
|
2563
|
-
// src/extensions/focus.ts
|
2564
|
-
import { StateEffect as StateEffect5, StateField as StateField6 } from "@codemirror/state";
|
2565
|
-
import { EditorView as EditorView13 } from "@codemirror/view";
|
2566
|
-
var focusEffect = StateEffect5.define();
|
2567
|
-
var focusField = StateField6.define({
|
2568
|
-
create: () => false,
|
2569
|
-
update: (value, tr) => {
|
2570
|
-
for (const effect of tr.effects) {
|
2571
|
-
if (effect.is(focusEffect)) {
|
2572
|
-
return effect.value;
|
2573
|
-
}
|
2574
|
-
}
|
2575
|
-
return value;
|
2576
|
-
}
|
2577
|
-
});
|
2578
|
-
var focus = [
|
2579
|
-
focusField,
|
2580
|
-
EditorView13.domEventHandlers({
|
2581
|
-
focus: (event, view) => {
|
2582
|
-
setTimeout(() => view.dispatch({
|
2583
|
-
effects: focusEffect.of(true)
|
2584
|
-
}));
|
2585
|
-
},
|
2586
|
-
blur: (event, view) => {
|
2587
|
-
setTimeout(() => view.dispatch({
|
2588
|
-
effects: focusEffect.of(false)
|
2589
|
-
}));
|
2590
|
-
}
|
2591
|
-
})
|
2592
|
-
];
|
2593
|
-
|
2594
3058
|
// src/defaults.ts
|
2595
|
-
import { EditorView as
|
2596
|
-
import { mx as
|
3059
|
+
import { EditorView as EditorView15 } from "@codemirror/view";
|
3060
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
2597
3061
|
|
2598
3062
|
// src/styles/markdown.ts
|
2599
|
-
import { mx } from "@dxos/react-ui-theme";
|
3063
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
2600
3064
|
var headings = {
|
2601
3065
|
1: "text-4xl",
|
2602
3066
|
2: "text-3xl",
|
@@ -2610,7 +3074,7 @@ var theme = {
|
|
2610
3074
|
codeMark: "font-mono text-primary-500",
|
2611
3075
|
mark: "opacity-50",
|
2612
3076
|
heading: (level) => {
|
2613
|
-
return
|
3077
|
+
return mx2(headings[level], "dark:text-primary-400");
|
2614
3078
|
}
|
2615
3079
|
};
|
2616
3080
|
|
@@ -2645,7 +3109,7 @@ var defaultTheme = {
|
|
2645
3109
|
fontFamily: fontBody,
|
2646
3110
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
2647
3111
|
fontSize: "16px",
|
2648
|
-
lineHeight:
|
3112
|
+
lineHeight: "24px",
|
2649
3113
|
color: "unset"
|
2650
3114
|
},
|
2651
3115
|
/**
|
@@ -2653,8 +3117,7 @@ var defaultTheme = {
|
|
2653
3117
|
* NOTE: Gutters should have the same top margin as the content.
|
2654
3118
|
*/
|
2655
3119
|
".cm-gutters": {
|
2656
|
-
borderRight: "none"
|
2657
|
-
background: "transparent"
|
3120
|
+
borderRight: "none"
|
2658
3121
|
},
|
2659
3122
|
".cm-gutter": {},
|
2660
3123
|
".cm-gutter.cm-lineNumbers": {
|
@@ -2668,13 +3131,14 @@ var defaultTheme = {
|
|
2668
3131
|
* Height is set to match the corresponding line (which may have wrapped).
|
2669
3132
|
*/
|
2670
3133
|
".cm-gutterElement": {
|
2671
|
-
|
2672
|
-
|
3134
|
+
lineHeight: "24px",
|
3135
|
+
fontSize: "12px"
|
2673
3136
|
},
|
2674
3137
|
/**
|
2675
3138
|
* Line.
|
2676
3139
|
*/
|
2677
3140
|
".cm-line": {
|
3141
|
+
lineHeight: "24px",
|
2678
3142
|
paddingInline: 0
|
2679
3143
|
},
|
2680
3144
|
".cm-activeLine": {
|
@@ -2729,7 +3193,7 @@ var defaultTheme = {
|
|
2729
3193
|
* Tooltip.
|
2730
3194
|
*/
|
2731
3195
|
".cm-tooltip": {
|
2732
|
-
background: "var(--dx-
|
3196
|
+
background: "var(--dx-modalSurface)"
|
2733
3197
|
},
|
2734
3198
|
".cm-tooltip-below": {},
|
2735
3199
|
/**
|
@@ -2749,7 +3213,8 @@ var defaultTheme = {
|
|
2749
3213
|
padding: "4px"
|
2750
3214
|
},
|
2751
3215
|
".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]": {
|
2752
|
-
background: "var(--dx-
|
3216
|
+
background: "var(--dx-accentSurface)",
|
3217
|
+
color: "var(--dx-accentSurfaceText)"
|
2753
3218
|
},
|
2754
3219
|
".cm-tooltip.cm-tooltip-autocomplete > ul > completion-section": {
|
2755
3220
|
paddingLeft: "4px !important",
|
@@ -2803,7 +3268,7 @@ var defaultTheme = {
|
|
2803
3268
|
outline: "1px solid transparent"
|
2804
3269
|
},
|
2805
3270
|
".cm-panel input, .cm-panel button": {
|
2806
|
-
backgroundColor: "var(--dx-
|
3271
|
+
backgroundColor: "var(--dx-inputSurface)"
|
2807
3272
|
},
|
2808
3273
|
".cm-panel input:focus, .cm-panel button:focus": {
|
2809
3274
|
outline: "1px solid var(--dx-neutralFocusIndicator)"
|
@@ -2845,19 +3310,52 @@ var editorSlots = {
|
|
2845
3310
|
className: editorWidth
|
2846
3311
|
}
|
2847
3312
|
};
|
2848
|
-
var editorGutter =
|
3313
|
+
var editorGutter = EditorView15.theme({
|
2849
3314
|
".cm-gutters": {
|
2850
|
-
|
3315
|
+
// NOTE: Color required to cover content if scrolling horizontally.
|
3316
|
+
// TODO(burdon): Non-transparent background clips the focus ring.
|
3317
|
+
background: "var(--dx-baseSurface) !important",
|
2851
3318
|
paddingRight: "1rem"
|
2852
3319
|
}
|
2853
3320
|
});
|
2854
|
-
var editorMonospace =
|
3321
|
+
var editorMonospace = EditorView15.theme({
|
2855
3322
|
".cm-content": {
|
2856
3323
|
fontFamily: fontMono
|
2857
3324
|
}
|
2858
3325
|
});
|
2859
3326
|
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
2860
|
-
var stackItemContentEditorClassNames = (role) =>
|
3327
|
+
var stackItemContentEditorClassNames = (role) => mx3("p-0.5 dx-focus-ring-inset attention-surface data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
3328
|
+
|
3329
|
+
// src/extensions/focus.ts
|
3330
|
+
import { StateEffect as StateEffect6, StateField as StateField6 } from "@codemirror/state";
|
3331
|
+
import { EditorView as EditorView16 } from "@codemirror/view";
|
3332
|
+
var focusEffect = StateEffect6.define();
|
3333
|
+
var focusField = StateField6.define({
|
3334
|
+
create: () => false,
|
3335
|
+
update: (value, tr) => {
|
3336
|
+
for (const effect of tr.effects) {
|
3337
|
+
if (effect.is(focusEffect)) {
|
3338
|
+
return effect.value;
|
3339
|
+
}
|
3340
|
+
}
|
3341
|
+
return value;
|
3342
|
+
}
|
3343
|
+
});
|
3344
|
+
var focus = [
|
3345
|
+
focusField,
|
3346
|
+
EditorView16.domEventHandlers({
|
3347
|
+
focus: (event, view) => {
|
3348
|
+
setTimeout(() => view.dispatch({
|
3349
|
+
effects: focusEffect.of(true)
|
3350
|
+
}));
|
3351
|
+
},
|
3352
|
+
blur: (event, view) => {
|
3353
|
+
setTimeout(() => view.dispatch({
|
3354
|
+
effects: focusEffect.of(false)
|
3355
|
+
}));
|
3356
|
+
}
|
3357
|
+
})
|
3358
|
+
];
|
2861
3359
|
|
2862
3360
|
// src/extensions/factories.ts
|
2863
3361
|
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
|
@@ -2871,7 +3369,7 @@ var defaultBasicOptions = {
|
|
2871
3369
|
history: true,
|
2872
3370
|
keymap: "standard",
|
2873
3371
|
lineWrapping: true,
|
2874
|
-
search:
|
3372
|
+
search: false
|
2875
3373
|
};
|
2876
3374
|
var keymaps = {
|
2877
3375
|
// https://codemirror.net/docs/ref/#commands.standardKeymap
|
@@ -2883,10 +3381,10 @@ var createBasicExtensions = (_props) => {
|
|
2883
3381
|
const props = defaultsDeep2({}, _props, defaultBasicOptions);
|
2884
3382
|
return [
|
2885
3383
|
// NOTE: Doesn't catch errors in keymap functions.
|
2886
|
-
|
3384
|
+
EditorView17.exceptionSink.of((err) => {
|
2887
3385
|
log5.catch(err, void 0, {
|
2888
3386
|
F: __dxlog_file8,
|
2889
|
-
L:
|
3387
|
+
L: 102,
|
2890
3388
|
S: void 0,
|
2891
3389
|
C: (f, a) => f(...a)
|
2892
3390
|
});
|
@@ -2898,7 +3396,7 @@ var createBasicExtensions = (_props) => {
|
|
2898
3396
|
props.drawSelection && drawSelection({
|
2899
3397
|
cursorBlinkRate: 1200
|
2900
3398
|
}),
|
2901
|
-
props.editable !== void 0 &&
|
3399
|
+
props.editable !== void 0 && EditorView17.editable.of(props.editable),
|
2902
3400
|
props.focus && focus,
|
2903
3401
|
props.highlightActiveLine && highlightActiveLine(),
|
2904
3402
|
props.history && history(),
|
@@ -2906,7 +3404,7 @@ var createBasicExtensions = (_props) => {
|
|
2906
3404
|
lineNumbers(),
|
2907
3405
|
editorGutter
|
2908
3406
|
],
|
2909
|
-
props.lineWrapping &&
|
3407
|
+
props.lineWrapping && EditorView17.lineWrapping,
|
2910
3408
|
props.monospace && editorMonospace,
|
2911
3409
|
props.placeholder && placeholder2(props.placeholder),
|
2912
3410
|
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
@@ -2947,27 +3445,21 @@ var fullWidth = {
|
|
2947
3445
|
}
|
2948
3446
|
};
|
2949
3447
|
var defaultThemeSlots = grow;
|
2950
|
-
var createThemeExtensions = ({ themeMode, styles: styles4, syntaxHighlighting:
|
3448
|
+
var createThemeExtensions = ({ themeMode, styles: styles4, syntaxHighlighting: syntaxHighlightingProps, slots: _slots } = {}) => {
|
2951
3449
|
const slots = defaultsDeep2({}, _slots, defaultThemeSlots);
|
2952
3450
|
return [
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
slots.editor?.className && EditorView15.editorAttributes.of({
|
3451
|
+
EditorView17.darkTheme.of(themeMode === "dark"),
|
3452
|
+
EditorView17.baseTheme(styles4 ? merge({}, defaultTheme, styles4) : defaultTheme),
|
3453
|
+
syntaxHighlightingProps && syntaxHighlighting(themeMode === "dark" ? oneDarkHighlightStyle : defaultHighlightStyle),
|
3454
|
+
slots.editor?.className && EditorView17.editorAttributes.of({
|
2958
3455
|
class: slots.editor.className
|
2959
3456
|
}),
|
2960
|
-
slots.content?.className &&
|
3457
|
+
slots.content?.className && EditorView17.contentAttributes.of({
|
2961
3458
|
class: slots.content.className
|
2962
3459
|
}),
|
2963
|
-
slots.scroll?.className &&
|
2964
|
-
constructor(view) {
|
2965
|
-
view.scrollDOM.classList.add(slots.scroll.className);
|
2966
|
-
}
|
2967
|
-
}),
|
2968
|
-
slots.scroller?.className && ViewPlugin10.fromClass(class {
|
3460
|
+
slots.scroll?.className && ViewPlugin12.fromClass(class {
|
2969
3461
|
constructor(view) {
|
2970
|
-
view.
|
3462
|
+
view.scrollDOM.classList.add(...slots.scroll.className.split(/\s+/));
|
2971
3463
|
}
|
2972
3464
|
})
|
2973
3465
|
].filter(isNotFalsy2);
|
@@ -2985,9 +3477,9 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2985
3477
|
channel: `awareness.${id}`,
|
2986
3478
|
peerId: identity.identityKey.toHex(),
|
2987
3479
|
info: {
|
2988
|
-
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
2989
3480
|
darkColor: `var(--dx-${hue}Cursor)`,
|
2990
|
-
lightColor: `var(--dx-${hue}Cursor)
|
3481
|
+
lightColor: `var(--dx-${hue}Cursor)`,
|
3482
|
+
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex())
|
2991
3483
|
}
|
2992
3484
|
})));
|
2993
3485
|
}
|
@@ -2996,7 +3488,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2996
3488
|
|
2997
3489
|
// src/extensions/folding.tsx
|
2998
3490
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
2999
|
-
import { EditorView as
|
3491
|
+
import { EditorView as EditorView18 } from "@codemirror/view";
|
3000
3492
|
import React2 from "react";
|
3001
3493
|
import { Icon } from "@dxos/react-ui";
|
3002
3494
|
var folding = (_props = {}) => [
|
@@ -3007,9 +3499,7 @@ var folding = (_props = {}) => [
|
|
3007
3499
|
}),
|
3008
3500
|
foldGutter({
|
3009
3501
|
markerDOM: (open) => {
|
3010
|
-
const el =
|
3011
|
-
className: "flex h-full items-center"
|
3012
|
-
});
|
3502
|
+
const el = Domino.of("div").classNames("flex h-full items-center").build();
|
3013
3503
|
return renderRoot(el, /* @__PURE__ */ React2.createElement(Icon, {
|
3014
3504
|
icon: "ph--caret-right--bold",
|
3015
3505
|
size: 3,
|
@@ -3020,7 +3510,7 @@ var folding = (_props = {}) => [
|
|
3020
3510
|
}));
|
3021
3511
|
}
|
3022
3512
|
}),
|
3023
|
-
|
3513
|
+
EditorView18.theme({
|
3024
3514
|
".cm-foldGutter": {
|
3025
3515
|
opacity: 0.3,
|
3026
3516
|
transition: "opacity 0.3s",
|
@@ -3033,40 +3523,54 @@ var folding = (_props = {}) => [
|
|
3033
3523
|
];
|
3034
3524
|
|
3035
3525
|
// src/extensions/hashtag.tsx
|
3036
|
-
import { Decoration as
|
3037
|
-
import { getHashColor, mx as
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3526
|
+
import { Decoration as Decoration9, EditorView as EditorView19, MatchDecorator, ViewPlugin as ViewPlugin13, WidgetType as WidgetType5 } from "@codemirror/view";
|
3527
|
+
import { getHashColor, mx as mx4 } from "@dxos/react-ui-theme";
|
3528
|
+
function _define_property16(obj, key, value) {
|
3529
|
+
if (key in obj) {
|
3530
|
+
Object.defineProperty(obj, key, {
|
3531
|
+
value,
|
3532
|
+
enumerable: true,
|
3533
|
+
configurable: true,
|
3534
|
+
writable: true
|
3535
|
+
});
|
3536
|
+
} else {
|
3537
|
+
obj[key] = value;
|
3041
3538
|
}
|
3539
|
+
return obj;
|
3540
|
+
}
|
3541
|
+
var TagWidget = class extends WidgetType5 {
|
3042
3542
|
toDOM() {
|
3043
3543
|
const span = document.createElement("span");
|
3044
|
-
span.className =
|
3544
|
+
span.className = mx4("cm-tag", getHashColor(this._text).tag);
|
3045
3545
|
span.textContent = this._text;
|
3046
3546
|
return span;
|
3047
3547
|
}
|
3548
|
+
constructor(_text) {
|
3549
|
+
super(), _define_property16(this, "_text", void 0), this._text = _text;
|
3550
|
+
}
|
3048
3551
|
};
|
3049
3552
|
var tagMatcher = new MatchDecorator({
|
3050
3553
|
regexp: /#(\w+)\W/g,
|
3051
|
-
decoration: (match) =>
|
3554
|
+
decoration: (match) => Decoration9.replace({
|
3052
3555
|
widget: new TagWidget(match[1])
|
3053
3556
|
})
|
3054
3557
|
});
|
3055
3558
|
var hashtag = () => [
|
3056
|
-
|
3057
|
-
constructor(view) {
|
3058
|
-
this.tags = tagMatcher.createDeco(view);
|
3059
|
-
}
|
3559
|
+
ViewPlugin13.fromClass(class {
|
3060
3560
|
update(update2) {
|
3061
3561
|
this.tags = tagMatcher.updateDeco(update2, this.tags);
|
3062
3562
|
}
|
3563
|
+
constructor(view) {
|
3564
|
+
_define_property16(this, "tags", void 0);
|
3565
|
+
this.tags = tagMatcher.createDeco(view);
|
3566
|
+
}
|
3063
3567
|
}, {
|
3064
3568
|
decorations: (instance) => instance.tags,
|
3065
|
-
provide: (plugin) =>
|
3066
|
-
return view.plugin(plugin)?.tags ||
|
3569
|
+
provide: (plugin) => EditorView19.atomicRanges.of((view) => {
|
3570
|
+
return view.plugin(plugin)?.tags || Decoration9.none;
|
3067
3571
|
})
|
3068
3572
|
}),
|
3069
|
-
|
3573
|
+
EditorView19.theme({
|
3070
3574
|
".cm-tag": {
|
3071
3575
|
borderRadius: "4px",
|
3072
3576
|
marginRight: "6px",
|
@@ -3121,14 +3625,14 @@ var schemaLinter = (validate) => (view) => {
|
|
3121
3625
|
};
|
3122
3626
|
|
3123
3627
|
// src/extensions/listener.ts
|
3124
|
-
import { EditorView as
|
3628
|
+
import { EditorView as EditorView20 } from "@codemirror/view";
|
3125
3629
|
var listener = ({ onFocus, onChange }) => {
|
3126
3630
|
const extensions = [];
|
3127
|
-
onFocus && extensions.push(
|
3631
|
+
onFocus && extensions.push(EditorView20.focusChangeEffect.of((_, focusing) => {
|
3128
3632
|
onFocus(focusing);
|
3129
3633
|
return null;
|
3130
3634
|
}));
|
3131
|
-
onChange && extensions.push(
|
3635
|
+
onChange && extensions.push(EditorView20.updateListener.of((update2) => {
|
3132
3636
|
onChange(update2.state.doc.toString(), update2.state.facet(documentId));
|
3133
3637
|
}));
|
3134
3638
|
return extensions;
|
@@ -3138,7 +3642,7 @@ var listener = ({ onFocus, onChange }) => {
|
|
3138
3642
|
import { snippet } from "@codemirror/autocomplete";
|
3139
3643
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
3140
3644
|
import { EditorSelection as EditorSelection2 } from "@codemirror/state";
|
3141
|
-
import { EditorView as
|
3645
|
+
import { EditorView as EditorView21, keymap as keymap9 } from "@codemirror/view";
|
3142
3646
|
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
3143
3647
|
import { debounceAndThrottle } from "@dxos/async";
|
3144
3648
|
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;
|
@@ -4237,7 +4741,7 @@ var useFormattingState = (state) => {
|
|
4237
4741
|
}, 100), [
|
4238
4742
|
state
|
4239
4743
|
]);
|
4240
|
-
return useMemo2(() =>
|
4744
|
+
return useMemo2(() => EditorView21.updateListener.of(handleUpdate), [
|
4241
4745
|
handleUpdate
|
4242
4746
|
]);
|
4243
4747
|
};
|
@@ -4292,18 +4796,18 @@ var processEditorPayload = (view, { type, data }) => {
|
|
4292
4796
|
};
|
4293
4797
|
|
4294
4798
|
// src/extensions/markdown/bundle.ts
|
4295
|
-
import { completionKeymap
|
4799
|
+
import { completionKeymap } from "@codemirror/autocomplete";
|
4296
4800
|
import { defaultKeymap as defaultKeymap2, indentWithTab as indentWithTab2 } from "@codemirror/commands";
|
4297
|
-
import { markdownLanguage as
|
4801
|
+
import { markdown, markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
|
4298
4802
|
import { syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
4299
4803
|
import { languages } from "@codemirror/language-data";
|
4300
4804
|
import { keymap as keymap10 } from "@codemirror/view";
|
4301
4805
|
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
4302
4806
|
|
4303
4807
|
// src/extensions/markdown/highlight.ts
|
4304
|
-
import { markdownLanguage
|
4808
|
+
import { markdownLanguage } from "@codemirror/lang-markdown";
|
4305
4809
|
import { HighlightStyle } from "@codemirror/language";
|
4306
|
-
import {
|
4810
|
+
import { Tag, styleTags, tags } from "@lezer/highlight";
|
4307
4811
|
import { Table } from "@lezer/markdown";
|
4308
4812
|
var markdownTags = {
|
4309
4813
|
Blockquote: Tag.define(),
|
@@ -4472,7 +4976,7 @@ var markdownHighlightStyle = (_options = {}) => {
|
|
4472
4976
|
class: "font-mono"
|
4473
4977
|
}
|
4474
4978
|
], {
|
4475
|
-
scope:
|
4979
|
+
scope: markdownLanguage,
|
4476
4980
|
all: {
|
4477
4981
|
fontFamily: fontBody
|
4478
4982
|
}
|
@@ -4491,7 +4995,7 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4491
4995
|
// NOTE: This extends the parser; it doesn't affect rendering.
|
4492
4996
|
// https://github.github.com/gfm
|
4493
4997
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
4494
|
-
base:
|
4998
|
+
base: markdownLanguage2,
|
4495
4999
|
// Languages for syntax highlighting fenced code blocks.
|
4496
5000
|
codeLanguages: languages,
|
4497
5001
|
// Don't complete HTML tags.
|
@@ -4499,7 +5003,8 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4499
5003
|
// Parser extensions.
|
4500
5004
|
extensions: [
|
4501
5005
|
// GFM provided by default.
|
4502
|
-
markdownTagsExtensions
|
5006
|
+
markdownTagsExtensions,
|
5007
|
+
...options.extensions ?? defaultExtensions()
|
4503
5008
|
]
|
4504
5009
|
}),
|
4505
5010
|
// Custom styles.
|
@@ -4509,10 +5014,25 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4509
5014
|
options.indentWithTab !== false && indentWithTab2,
|
4510
5015
|
// https://codemirror.net/docs/ref/#commands.defaultKeymap
|
4511
5016
|
...defaultKeymap2,
|
4512
|
-
...
|
5017
|
+
...completionKeymap
|
4513
5018
|
].filter(isNotFalsy3))
|
4514
5019
|
];
|
4515
5020
|
};
|
5021
|
+
var defaultExtensions = () => [
|
5022
|
+
noSetExtHeading,
|
5023
|
+
noHtml
|
5024
|
+
];
|
5025
|
+
var noSetExtHeading = {
|
5026
|
+
remove: [
|
5027
|
+
"SetextHeading"
|
5028
|
+
]
|
5029
|
+
};
|
5030
|
+
var noHtml = {
|
5031
|
+
remove: [
|
5032
|
+
"HTMLBlock",
|
5033
|
+
"HTMLTag"
|
5034
|
+
]
|
5035
|
+
};
|
4516
5036
|
|
4517
5037
|
// src/extensions/markdown/debug.ts
|
4518
5038
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
@@ -4522,19 +5042,19 @@ var debugTree = (cb) => StateField7.define({
|
|
4522
5042
|
update: (value, tr) => cb(convertTreeToJson(tr.state))
|
4523
5043
|
});
|
4524
5044
|
var convertTreeToJson = (state) => {
|
4525
|
-
const treeToJson = (
|
5045
|
+
const treeToJson = (cursor2) => {
|
4526
5046
|
const node = {
|
4527
|
-
type:
|
4528
|
-
from:
|
4529
|
-
to:
|
4530
|
-
text: state.doc.slice(
|
5047
|
+
type: cursor2.type.name,
|
5048
|
+
from: cursor2.from,
|
5049
|
+
to: cursor2.to,
|
5050
|
+
text: state.doc.slice(cursor2.from, cursor2.to).toString(),
|
4531
5051
|
children: []
|
4532
5052
|
};
|
4533
|
-
if (
|
5053
|
+
if (cursor2.firstChild()) {
|
4534
5054
|
do {
|
4535
|
-
node.children.push(treeToJson(
|
4536
|
-
} while (
|
4537
|
-
|
5055
|
+
node.children.push(treeToJson(cursor2));
|
5056
|
+
} while (cursor2.nextSibling());
|
5057
|
+
cursor2.parent();
|
4538
5058
|
}
|
4539
5059
|
return node;
|
4540
5060
|
};
|
@@ -4543,17 +5063,17 @@ var convertTreeToJson = (state) => {
|
|
4543
5063
|
|
4544
5064
|
// src/extensions/markdown/decorate.ts
|
4545
5065
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4546
|
-
import { RangeSetBuilder as RangeSetBuilder6, StateEffect as
|
4547
|
-
import {
|
5066
|
+
import { Prec as Prec5, RangeSetBuilder as RangeSetBuilder6, StateEffect as StateEffect7 } from "@codemirror/state";
|
5067
|
+
import { Decoration as Decoration12, EditorView as EditorView25, ViewPlugin as ViewPlugin15, WidgetType as WidgetType8 } from "@codemirror/view";
|
4548
5068
|
import { invariant as invariant4 } from "@dxos/invariant";
|
4549
|
-
import { mx as
|
5069
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
4550
5070
|
|
4551
5071
|
// src/extensions/markdown/changes.ts
|
4552
5072
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
4553
5073
|
import { Transaction as Transaction2 } from "@codemirror/state";
|
4554
|
-
import { ViewPlugin as
|
5074
|
+
import { ViewPlugin as ViewPlugin14 } from "@codemirror/view";
|
4555
5075
|
var adjustChanges = () => {
|
4556
|
-
return
|
5076
|
+
return ViewPlugin14.fromClass(class {
|
4557
5077
|
update(update2) {
|
4558
5078
|
const tree = syntaxTree4(update2.state);
|
4559
5079
|
const adjustments = [];
|
@@ -4695,21 +5215,34 @@ var getValidUrl = (str) => {
|
|
4695
5215
|
// src/extensions/markdown/image.ts
|
4696
5216
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
4697
5217
|
import { StateField as StateField8 } from "@codemirror/state";
|
4698
|
-
import { Decoration as
|
5218
|
+
import { Decoration as Decoration10, EditorView as EditorView22, WidgetType as WidgetType6 } from "@codemirror/view";
|
5219
|
+
function _define_property17(obj, key, value) {
|
5220
|
+
if (key in obj) {
|
5221
|
+
Object.defineProperty(obj, key, {
|
5222
|
+
value,
|
5223
|
+
enumerable: true,
|
5224
|
+
configurable: true,
|
5225
|
+
writable: true
|
5226
|
+
});
|
5227
|
+
} else {
|
5228
|
+
obj[key] = value;
|
5229
|
+
}
|
5230
|
+
return obj;
|
5231
|
+
}
|
4699
5232
|
var image = (_options = {}) => {
|
4700
5233
|
return [
|
4701
5234
|
StateField8.define({
|
4702
5235
|
create: (state) => {
|
4703
|
-
return
|
5236
|
+
return Decoration10.set(buildDecorations(state, 0, state.doc.length));
|
4704
5237
|
},
|
4705
5238
|
update: (value, tr) => {
|
4706
5239
|
if (!tr.docChanged && !tr.selection) {
|
4707
5240
|
return value;
|
4708
5241
|
}
|
4709
|
-
const
|
5242
|
+
const cursor2 = tr.state.selection.main.head;
|
4710
5243
|
const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
|
4711
|
-
let from = Math.min(
|
4712
|
-
let to = Math.max(
|
5244
|
+
let from = Math.min(cursor2, oldCursor);
|
5245
|
+
let to = Math.max(cursor2, oldCursor);
|
4713
5246
|
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
4714
5247
|
from = Math.min(from, fromB);
|
4715
5248
|
to = Math.max(to, toB);
|
@@ -4720,28 +5253,28 @@ var image = (_options = {}) => {
|
|
4720
5253
|
filterFrom: from,
|
4721
5254
|
filterTo: to,
|
4722
5255
|
filter: () => false,
|
4723
|
-
add: buildDecorations(from, to
|
5256
|
+
add: buildDecorations(tr.state, from, to)
|
4724
5257
|
});
|
4725
5258
|
},
|
4726
|
-
provide: (field) =>
|
5259
|
+
provide: (field) => EditorView22.decorations.from(field)
|
4727
5260
|
})
|
4728
5261
|
];
|
4729
5262
|
};
|
4730
|
-
var buildDecorations = (from, to
|
5263
|
+
var buildDecorations = (state, from, to) => {
|
4731
5264
|
const decorations2 = [];
|
4732
|
-
const
|
5265
|
+
const cursor2 = state.selection.main.head;
|
4733
5266
|
syntaxTree5(state).iterate({
|
4734
5267
|
enter: (node) => {
|
4735
5268
|
if (node.name === "Image") {
|
4736
5269
|
const urlNode = node.node.getChild("URL");
|
4737
5270
|
if (urlNode) {
|
4738
|
-
const hide2 = state.readOnly ||
|
5271
|
+
const hide2 = state.readOnly || cursor2 < node.from || cursor2 > node.to || !state.field(focusField);
|
4739
5272
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
4740
5273
|
if (url.match(/^https?:\/\//) === null && url.match(/^file?:\/\//) === null) {
|
4741
5274
|
return;
|
4742
5275
|
}
|
4743
5276
|
preloadImage(url);
|
4744
|
-
decorations2.push(
|
5277
|
+
decorations2.push(Decoration10.replace({
|
4745
5278
|
block: true,
|
4746
5279
|
widget: new ImageWidget(url)
|
4747
5280
|
}).range(hide2 ? node.from : node.to, node.to));
|
@@ -4761,10 +5294,7 @@ var preloadImage = (url) => {
|
|
4761
5294
|
preloaded.add(url);
|
4762
5295
|
}
|
4763
5296
|
};
|
4764
|
-
var ImageWidget = class extends
|
4765
|
-
constructor(_url) {
|
4766
|
-
super(), this._url = _url;
|
4767
|
-
}
|
5297
|
+
var ImageWidget = class extends WidgetType6 {
|
4768
5298
|
eq(other) {
|
4769
5299
|
return this._url === other._url;
|
4770
5300
|
}
|
@@ -4779,13 +5309,16 @@ var ImageWidget = class extends WidgetType5 {
|
|
4779
5309
|
}
|
4780
5310
|
return img;
|
4781
5311
|
}
|
5312
|
+
constructor(_url) {
|
5313
|
+
super(), _define_property17(this, "_url", void 0), this._url = _url;
|
5314
|
+
}
|
4782
5315
|
};
|
4783
5316
|
|
4784
5317
|
// src/extensions/markdown/styles.ts
|
4785
|
-
import { EditorView as
|
5318
|
+
import { EditorView as EditorView23 } from "@codemirror/view";
|
4786
5319
|
var bulletListIndentationWidth = 24;
|
4787
5320
|
var orderedListIndentationWidth = 36;
|
4788
|
-
var formattingStyles =
|
5321
|
+
var formattingStyles = EditorView23.theme({
|
4789
5322
|
/**
|
4790
5323
|
* Horizontal rule.
|
4791
5324
|
*/
|
@@ -4907,17 +5440,30 @@ var formattingStyles = EditorView21.theme({
|
|
4907
5440
|
// src/extensions/markdown/table.ts
|
4908
5441
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
4909
5442
|
import { RangeSetBuilder as RangeSetBuilder5, StateField as StateField9 } from "@codemirror/state";
|
4910
|
-
import { Decoration as
|
5443
|
+
import { Decoration as Decoration11, EditorView as EditorView24, WidgetType as WidgetType7 } from "@codemirror/view";
|
5444
|
+
function _define_property18(obj, key, value) {
|
5445
|
+
if (key in obj) {
|
5446
|
+
Object.defineProperty(obj, key, {
|
5447
|
+
value,
|
5448
|
+
enumerable: true,
|
5449
|
+
configurable: true,
|
5450
|
+
writable: true
|
5451
|
+
});
|
5452
|
+
} else {
|
5453
|
+
obj[key] = value;
|
5454
|
+
}
|
5455
|
+
return obj;
|
5456
|
+
}
|
4911
5457
|
var table = (options = {}) => {
|
4912
5458
|
return StateField9.define({
|
4913
5459
|
create: (state) => update(state, options),
|
4914
5460
|
update: (_, tr) => update(tr.state, options),
|
4915
|
-
provide: (field) =>
|
5461
|
+
provide: (field) => EditorView24.decorations.from(field)
|
4916
5462
|
});
|
4917
5463
|
};
|
4918
5464
|
var update = (state, _options) => {
|
4919
5465
|
const builder = new RangeSetBuilder5();
|
4920
|
-
const
|
5466
|
+
const cursor2 = state.selection.main.head;
|
4921
5467
|
const tables = [];
|
4922
5468
|
const getTable = () => tables[tables.length - 1];
|
4923
5469
|
const getRow = () => {
|
@@ -4939,7 +5485,8 @@ var update = (state, _options) => {
|
|
4939
5485
|
break;
|
4940
5486
|
}
|
4941
5487
|
case "TableRow": {
|
4942
|
-
|
5488
|
+
var _getTable;
|
5489
|
+
((_getTable = getTable()).rows ?? (_getTable.rows = [])).push([]);
|
4943
5490
|
break;
|
4944
5491
|
}
|
4945
5492
|
case "TableCell": {
|
@@ -4955,24 +5502,21 @@ var update = (state, _options) => {
|
|
4955
5502
|
}
|
4956
5503
|
});
|
4957
5504
|
tables.forEach((table2) => {
|
4958
|
-
const replace = state.readOnly ||
|
5505
|
+
const replace = state.readOnly || cursor2 < table2.from || cursor2 > table2.to;
|
4959
5506
|
if (replace) {
|
4960
|
-
builder.add(table2.from, table2.to,
|
5507
|
+
builder.add(table2.from, table2.to, Decoration11.replace({
|
4961
5508
|
block: true,
|
4962
5509
|
widget: new TableWidget(table2)
|
4963
5510
|
}));
|
4964
5511
|
} else {
|
4965
|
-
builder.add(table2.from, table2.to,
|
5512
|
+
builder.add(table2.from, table2.to, Decoration11.mark({
|
4966
5513
|
class: "cm-table"
|
4967
5514
|
}));
|
4968
5515
|
}
|
4969
5516
|
});
|
4970
5517
|
return builder.finish();
|
4971
5518
|
};
|
4972
|
-
var TableWidget = class extends
|
4973
|
-
constructor(_table) {
|
4974
|
-
super(), this._table = _table;
|
4975
|
-
}
|
5519
|
+
var TableWidget = class extends WidgetType7 {
|
4976
5520
|
eq(other) {
|
4977
5521
|
return this._table.header?.join() === other._table.header?.join() && this._table.rows?.join() === other._table.rows?.join();
|
4978
5522
|
}
|
@@ -5000,9 +5544,25 @@ var TableWidget = class extends WidgetType6 {
|
|
5000
5544
|
ignoreEvent(e) {
|
5001
5545
|
return !/^mouse/.test(e.type);
|
5002
5546
|
}
|
5547
|
+
constructor(_table) {
|
5548
|
+
super(), _define_property18(this, "_table", void 0), this._table = _table;
|
5549
|
+
}
|
5003
5550
|
};
|
5004
5551
|
|
5005
5552
|
// src/extensions/markdown/decorate.ts
|
5553
|
+
function _define_property19(obj, key, value) {
|
5554
|
+
if (key in obj) {
|
5555
|
+
Object.defineProperty(obj, key, {
|
5556
|
+
value,
|
5557
|
+
enumerable: true,
|
5558
|
+
configurable: true,
|
5559
|
+
writable: true
|
5560
|
+
});
|
5561
|
+
} else {
|
5562
|
+
obj[key] = value;
|
5563
|
+
}
|
5564
|
+
return obj;
|
5565
|
+
}
|
5006
5566
|
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts";
|
5007
5567
|
var Unicode = {
|
5008
5568
|
emDash: "\u2014",
|
@@ -5010,17 +5570,14 @@ var Unicode = {
|
|
5010
5570
|
bulletSmall: "\u2219",
|
5011
5571
|
bulletSquare: "\u2B1D"
|
5012
5572
|
};
|
5013
|
-
var HorizontalRuleWidget = class extends
|
5573
|
+
var HorizontalRuleWidget = class extends WidgetType8 {
|
5014
5574
|
toDOM() {
|
5015
5575
|
const el = document.createElement("span");
|
5016
5576
|
el.className = "cm-hr";
|
5017
5577
|
return el;
|
5018
5578
|
}
|
5019
5579
|
};
|
5020
|
-
var LinkButton = class extends
|
5021
|
-
constructor(url, render) {
|
5022
|
-
super(), this.url = url, this.render = render;
|
5023
|
-
}
|
5580
|
+
var LinkButton = class extends WidgetType8 {
|
5024
5581
|
eq(other) {
|
5025
5582
|
return this.url === other.url;
|
5026
5583
|
}
|
@@ -5032,11 +5589,11 @@ var LinkButton = class extends WidgetType7 {
|
|
5032
5589
|
}, view);
|
5033
5590
|
return el;
|
5034
5591
|
}
|
5592
|
+
constructor(url, render) {
|
5593
|
+
super(), _define_property19(this, "url", void 0), _define_property19(this, "render", void 0), this.url = url, this.render = render;
|
5594
|
+
}
|
5035
5595
|
};
|
5036
|
-
var CheckboxWidget = class extends
|
5037
|
-
constructor(_checked) {
|
5038
|
-
super(), this._checked = _checked;
|
5039
|
-
}
|
5596
|
+
var CheckboxWidget = class extends WidgetType8 {
|
5040
5597
|
eq(other) {
|
5041
5598
|
return this._checked === other._checked;
|
5042
5599
|
}
|
@@ -5076,11 +5633,11 @@ var CheckboxWidget = class extends WidgetType7 {
|
|
5076
5633
|
ignoreEvent() {
|
5077
5634
|
return false;
|
5078
5635
|
}
|
5079
|
-
|
5080
|
-
|
5081
|
-
constructor(text, className) {
|
5082
|
-
super(), this.text = text, this.className = className;
|
5636
|
+
constructor(_checked) {
|
5637
|
+
super(), _define_property19(this, "_checked", void 0), this._checked = _checked;
|
5083
5638
|
}
|
5639
|
+
};
|
5640
|
+
var TextWidget = class extends WidgetType8 {
|
5084
5641
|
toDOM() {
|
5085
5642
|
const el = document.createElement("span");
|
5086
5643
|
if (this.className) {
|
@@ -5089,30 +5646,33 @@ var TextWidget = class extends WidgetType7 {
|
|
5089
5646
|
el.innerText = this.text;
|
5090
5647
|
return el;
|
5091
5648
|
}
|
5649
|
+
constructor(text, className) {
|
5650
|
+
super(), _define_property19(this, "text", void 0), _define_property19(this, "className", void 0), this.text = text, this.className = className;
|
5651
|
+
}
|
5092
5652
|
};
|
5093
|
-
var hide =
|
5094
|
-
var blockQuote =
|
5653
|
+
var hide = Decoration12.replace({});
|
5654
|
+
var blockQuote = Decoration12.line({
|
5095
5655
|
class: "cm-blockquote"
|
5096
5656
|
});
|
5097
|
-
var fencedCodeLine =
|
5657
|
+
var fencedCodeLine = Decoration12.line({
|
5098
5658
|
class: "cm-code cm-codeblock-line"
|
5099
5659
|
});
|
5100
|
-
var fencedCodeLineFirst =
|
5101
|
-
class:
|
5660
|
+
var fencedCodeLineFirst = Decoration12.line({
|
5661
|
+
class: mx5("cm-code cm-codeblock-line", "cm-codeblock-start")
|
5102
5662
|
});
|
5103
|
-
var fencedCodeLineLast =
|
5104
|
-
class:
|
5663
|
+
var fencedCodeLineLast = Decoration12.line({
|
5664
|
+
class: mx5("cm-code cm-codeblock-line", "cm-codeblock-end")
|
5105
5665
|
});
|
5106
5666
|
var commentBlockLine = fencedCodeLine;
|
5107
5667
|
var commentBlockLineFirst = fencedCodeLineFirst;
|
5108
5668
|
var commentBlockLineLast = fencedCodeLineLast;
|
5109
|
-
var horizontalRule =
|
5669
|
+
var horizontalRule = Decoration12.replace({
|
5110
5670
|
widget: new HorizontalRuleWidget()
|
5111
5671
|
});
|
5112
|
-
var checkedTask =
|
5672
|
+
var checkedTask = Decoration12.replace({
|
5113
5673
|
widget: new CheckboxWidget(true)
|
5114
5674
|
});
|
5115
|
-
var uncheckedTask =
|
5675
|
+
var uncheckedTask = Decoration12.replace({
|
5116
5676
|
widget: new CheckboxWidget(false)
|
5117
5677
|
});
|
5118
5678
|
var editingRange = (state, range, focus2) => {
|
@@ -5135,7 +5695,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5135
5695
|
const getHeaderLevels = (node, level) => {
|
5136
5696
|
invariant4(level > 0, void 0, {
|
5137
5697
|
F: __dxlog_file9,
|
5138
|
-
L:
|
5698
|
+
L: 180,
|
5139
5699
|
S: void 0,
|
5140
5700
|
A: [
|
5141
5701
|
"level > 0",
|
@@ -5174,7 +5734,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5174
5734
|
const getCurrentListLevel = () => {
|
5175
5735
|
invariant4(listLevels.length, void 0, {
|
5176
5736
|
F: __dxlog_file9,
|
5177
|
-
L:
|
5737
|
+
L: 202,
|
5178
5738
|
S: void 0,
|
5179
5739
|
A: [
|
5180
5740
|
"listLevels.length",
|
@@ -5209,14 +5769,14 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5209
5769
|
const mark = node.node.firstChild;
|
5210
5770
|
if (mark?.name === "HeaderMark") {
|
5211
5771
|
const { from, to = 6 } = options.numberedHeadings ?? {};
|
5212
|
-
const text =
|
5772
|
+
const text = state.sliceDoc(node.from, node.to);
|
5213
5773
|
const len = text.match(/[#\s]+/)[0].length;
|
5214
5774
|
if (!from || level < from || level > to) {
|
5215
5775
|
atomicDeco.add(mark.from, mark.from + len, hide);
|
5216
5776
|
} else {
|
5217
5777
|
const num = headers.slice(from - 1).map((level2) => level2?.number ?? 0).join(".") + " ";
|
5218
5778
|
if (num.length) {
|
5219
|
-
atomicDeco.add(mark.from, mark.from + len,
|
5779
|
+
atomicDeco.add(mark.from, mark.from + len, Decoration12.replace({
|
5220
5780
|
widget: new TextWidget(num, theme.heading(level))
|
5221
5781
|
}));
|
5222
5782
|
}
|
@@ -5241,7 +5801,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5241
5801
|
if (node.from === line.to - 1) {
|
5242
5802
|
return false;
|
5243
5803
|
}
|
5244
|
-
deco.add(line.from, line.from,
|
5804
|
+
deco.add(line.from, line.from, Decoration12.line({
|
5245
5805
|
class: "cm-list-item",
|
5246
5806
|
attributes: {
|
5247
5807
|
style: `padding-left: ${offset}px; text-indent: -${width}px;`
|
@@ -5258,7 +5818,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5258
5818
|
const label = list.type === "OrderedList" ? `${++list.number}.` : Unicode.bulletSmall;
|
5259
5819
|
const line = state.doc.lineAt(node.from);
|
5260
5820
|
const to = state.doc.sliceString(node.to, node.to + 1) === " " ? node.to + 1 : node.to;
|
5261
|
-
atomicDeco.add(line.from, to,
|
5821
|
+
atomicDeco.add(line.from, to, Decoration12.replace({
|
5262
5822
|
widget: new TextWidget(label, list.type === "OrderedList" ? "cm-list-mark cm-list-mark-ordered" : "cm-list-mark cm-list-mark-bullet")
|
5263
5823
|
}));
|
5264
5824
|
break;
|
@@ -5342,10 +5902,16 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5342
5902
|
const editing = editingRange(state, node, focus2);
|
5343
5903
|
if (urlNode && marks.length >= 2) {
|
5344
5904
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
5905
|
+
if (options.skip?.({
|
5906
|
+
name: "Link",
|
5907
|
+
url
|
5908
|
+
})) {
|
5909
|
+
break;
|
5910
|
+
}
|
5345
5911
|
if (!editing) {
|
5346
5912
|
atomicDeco.add(node.from, marks[0].to, hide);
|
5347
5913
|
}
|
5348
|
-
deco.add(marks[0].to, marks[1].from,
|
5914
|
+
deco.add(marks[0].to, marks[1].from, Decoration12.mark({
|
5349
5915
|
tagName: "a",
|
5350
5916
|
attributes: {
|
5351
5917
|
class: "cm-link",
|
@@ -5355,7 +5921,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5355
5921
|
}
|
5356
5922
|
}));
|
5357
5923
|
if (!editing) {
|
5358
|
-
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ?
|
5924
|
+
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ? Decoration12.replace({
|
5359
5925
|
widget: new LinkButton(url, options.renderLinkButton)
|
5360
5926
|
}) : hide);
|
5361
5927
|
}
|
@@ -5395,14 +5961,14 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5395
5961
|
tree.iterate({
|
5396
5962
|
from,
|
5397
5963
|
to,
|
5398
|
-
enter: wrapWithCatch(enterNode),
|
5399
|
-
leave: wrapWithCatch(leaveNode)
|
5964
|
+
enter: wrapWithCatch(enterNode, "decorate.enter"),
|
5965
|
+
leave: wrapWithCatch(leaveNode, "decorate.leave")
|
5400
5966
|
});
|
5401
5967
|
}
|
5402
5968
|
} else {
|
5403
5969
|
tree.iterate({
|
5404
|
-
enter: wrapWithCatch(enterNode),
|
5405
|
-
leave: wrapWithCatch(leaveNode)
|
5970
|
+
enter: wrapWithCatch(enterNode, "decorate.enter"),
|
5971
|
+
leave: wrapWithCatch(leaveNode, "decorate.leave")
|
5406
5972
|
});
|
5407
5973
|
}
|
5408
5974
|
return {
|
@@ -5410,13 +5976,10 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5410
5976
|
atomicDeco: atomicDeco.finish()
|
5411
5977
|
};
|
5412
5978
|
};
|
5413
|
-
var forceUpdate =
|
5979
|
+
var forceUpdate = StateEffect7.define();
|
5414
5980
|
var decorateMarkdown = (options = {}) => {
|
5415
5981
|
return [
|
5416
|
-
|
5417
|
-
constructor(view) {
|
5418
|
-
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(view, options, view.hasFocus));
|
5419
|
-
}
|
5982
|
+
ViewPlugin15.fromClass(class {
|
5420
5983
|
update(update2) {
|
5421
5984
|
if (update2.docChanged || update2.viewportChanged || update2.focusChanged || update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(forceUpdate))) || update2.selectionSet && !options.selectionChangeDelay) {
|
5422
5985
|
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(update2.view, options, update2.view.hasFocus));
|
@@ -5443,11 +6006,17 @@ var decorateMarkdown = (options = {}) => {
|
|
5443
6006
|
destroy() {
|
5444
6007
|
this.clearUpdate();
|
5445
6008
|
}
|
6009
|
+
constructor(view) {
|
6010
|
+
_define_property19(this, "deco", void 0);
|
6011
|
+
_define_property19(this, "atomicDeco", void 0);
|
6012
|
+
_define_property19(this, "pendingUpdate", void 0);
|
6013
|
+
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(view, options, view.hasFocus));
|
6014
|
+
}
|
5446
6015
|
}, {
|
5447
6016
|
provide: (plugin) => [
|
5448
|
-
|
5449
|
-
|
5450
|
-
|
6017
|
+
Prec5.low(EditorView25.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration12.none)),
|
6018
|
+
EditorView25.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration12.none),
|
6019
|
+
EditorView25.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration12.none)
|
5451
6020
|
]
|
5452
6021
|
}),
|
5453
6022
|
image(),
|
@@ -5473,6 +6042,9 @@ var linkTooltip = (renderTooltip) => {
|
|
5473
6042
|
return null;
|
5474
6043
|
}
|
5475
6044
|
const urlText = view.state.sliceDoc(url.from, url.to);
|
6045
|
+
if (urlText.startsWith("dxn")) {
|
6046
|
+
return null;
|
6047
|
+
}
|
5476
6048
|
return {
|
5477
6049
|
pos: link.from,
|
5478
6050
|
end: link.to,
|
@@ -5500,11 +6072,11 @@ var linkTooltip = (renderTooltip) => {
|
|
5500
6072
|
};
|
5501
6073
|
|
5502
6074
|
// src/extensions/mention.ts
|
5503
|
-
import { autocompletion
|
6075
|
+
import { autocompletion } from "@codemirror/autocomplete";
|
5504
6076
|
import { log as log6 } from "@dxos/log";
|
5505
6077
|
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/mention.ts";
|
5506
6078
|
var mention = ({ debug, onSearch }) => {
|
5507
|
-
return
|
6079
|
+
return autocompletion({
|
5508
6080
|
// TODO(burdon): Not working.
|
5509
6081
|
activateOnTyping: true,
|
5510
6082
|
// activateOnTypingDelay: 100,
|
@@ -5584,6 +6156,19 @@ import { syntaxTree as syntaxTree9 } from "@codemirror/language";
|
|
5584
6156
|
import { StateField as StateField10 } from "@codemirror/state";
|
5585
6157
|
import { Facet as Facet2 } from "@codemirror/state";
|
5586
6158
|
import { invariant as invariant5 } from "@dxos/invariant";
|
6159
|
+
function _define_property20(obj, key, value) {
|
6160
|
+
if (key in obj) {
|
6161
|
+
Object.defineProperty(obj, key, {
|
6162
|
+
value,
|
6163
|
+
enumerable: true,
|
6164
|
+
configurable: true,
|
6165
|
+
writable: true
|
6166
|
+
});
|
6167
|
+
} else {
|
6168
|
+
obj[key] = value;
|
6169
|
+
}
|
6170
|
+
return obj;
|
6171
|
+
}
|
5587
6172
|
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/tree.ts";
|
5588
6173
|
var itemToJSON = ({ type, index, level, lineRange, contentRange, children }) => {
|
5589
6174
|
return {
|
@@ -5596,18 +6181,6 @@ var itemToJSON = ({ type, index, level, lineRange, contentRange, children }) =>
|
|
5596
6181
|
};
|
5597
6182
|
};
|
5598
6183
|
var Tree = class {
|
5599
|
-
constructor(node) {
|
5600
|
-
this.type = "root";
|
5601
|
-
this.index = -1;
|
5602
|
-
this.level = -1;
|
5603
|
-
this.children = [];
|
5604
|
-
this.node = node;
|
5605
|
-
this.lineRange = {
|
5606
|
-
from: node.from,
|
5607
|
-
to: node.to
|
5608
|
-
};
|
5609
|
-
this.contentRange = this.lineRange;
|
5610
|
-
}
|
5611
6184
|
toJSON() {
|
5612
6185
|
return itemToJSON(this);
|
5613
6186
|
}
|
@@ -5657,6 +6230,21 @@ var Tree = class {
|
|
5657
6230
|
lastDescendant(item) {
|
5658
6231
|
return item.children.length > 0 ? this.lastDescendant(item.children.at(-1)) : item;
|
5659
6232
|
}
|
6233
|
+
constructor(node) {
|
6234
|
+
_define_property20(this, "type", "root");
|
6235
|
+
_define_property20(this, "index", -1);
|
6236
|
+
_define_property20(this, "level", -1);
|
6237
|
+
_define_property20(this, "node", void 0);
|
6238
|
+
_define_property20(this, "lineRange", void 0);
|
6239
|
+
_define_property20(this, "contentRange", void 0);
|
6240
|
+
_define_property20(this, "children", []);
|
6241
|
+
this.node = node;
|
6242
|
+
this.lineRange = {
|
6243
|
+
from: node.from,
|
6244
|
+
to: node.to
|
6245
|
+
};
|
6246
|
+
this.contentRange = this.lineRange;
|
6247
|
+
}
|
5660
6248
|
};
|
5661
6249
|
var getRange = (tree, item) => {
|
5662
6250
|
const lastDescendant = tree.lastDescendant(item);
|
@@ -5717,7 +6305,7 @@ var format = (value) => JSON.stringify(value, (key, value2) => {
|
|
5717
6305
|
var treeFacet = Facet2.define({
|
5718
6306
|
combine: (values) => values[0]
|
5719
6307
|
});
|
5720
|
-
var outlinerTree = (
|
6308
|
+
var outlinerTree = (_options = {}) => {
|
5721
6309
|
const buildTree = (state) => {
|
5722
6310
|
let tree;
|
5723
6311
|
let parent;
|
@@ -6143,18 +6731,18 @@ var commands = () => keymap12.of([
|
|
6143
6731
|
]);
|
6144
6732
|
|
6145
6733
|
// src/extensions/outliner/outliner.ts
|
6146
|
-
import { Prec as
|
6147
|
-
import { Decoration as
|
6148
|
-
import { mx as
|
6734
|
+
import { Prec as Prec6 } from "@codemirror/state";
|
6735
|
+
import { Decoration as Decoration13, EditorView as EditorView26, ViewPlugin as ViewPlugin17 } from "@codemirror/view";
|
6736
|
+
import { mx as mx6 } from "@dxos/react-ui-theme";
|
6149
6737
|
|
6150
6738
|
// src/extensions/outliner/editor.ts
|
6151
6739
|
import { EditorSelection as EditorSelection4, EditorState as EditorState2 } from "@codemirror/state";
|
6152
|
-
import { ViewPlugin as
|
6740
|
+
import { ViewPlugin as ViewPlugin16 } from "@codemirror/view";
|
6153
6741
|
import { log as log7 } from "@dxos/log";
|
6154
6742
|
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/editor.ts";
|
6155
6743
|
var LIST_ITEM_REGEX = /^\s*- (\[ \]|\[x\])? /;
|
6156
6744
|
var initialize = () => {
|
6157
|
-
return
|
6745
|
+
return ViewPlugin16.fromClass(class {
|
6158
6746
|
constructor(view) {
|
6159
6747
|
const first = view.state.doc.lineAt(0);
|
6160
6748
|
const text = view.state.sliceDoc(first.from, first.to);
|
@@ -6337,9 +6925,22 @@ var editor = () => [
|
|
6337
6925
|
];
|
6338
6926
|
|
6339
6927
|
// src/extensions/outliner/outliner.ts
|
6340
|
-
|
6928
|
+
function _define_property21(obj, key, value) {
|
6929
|
+
if (key in obj) {
|
6930
|
+
Object.defineProperty(obj, key, {
|
6931
|
+
value,
|
6932
|
+
enumerable: true,
|
6933
|
+
configurable: true,
|
6934
|
+
writable: true
|
6935
|
+
});
|
6936
|
+
} else {
|
6937
|
+
obj[key] = value;
|
6938
|
+
}
|
6939
|
+
return obj;
|
6940
|
+
}
|
6941
|
+
var outliner = (_options = {}) => [
|
6341
6942
|
// Commands.
|
6342
|
-
|
6943
|
+
Prec6.highest(commands()),
|
6343
6944
|
// Selection.
|
6344
6945
|
selectionCompartment.of(selectionFacet.of([])),
|
6345
6946
|
// State.
|
@@ -6355,16 +6956,12 @@ var outliner = (options = {}) => [
|
|
6355
6956
|
listPaddingLeft: 8
|
6356
6957
|
}),
|
6357
6958
|
// Researve space for menu.
|
6358
|
-
|
6959
|
+
EditorView26.contentAttributes.of({
|
6359
6960
|
class: "is-full !mr-[3rem]"
|
6360
6961
|
})
|
6361
6962
|
];
|
6362
6963
|
var decorations = () => [
|
6363
|
-
|
6364
|
-
constructor(view) {
|
6365
|
-
this.decorations = Decoration12.none;
|
6366
|
-
this.updateDecorations(view.state, view);
|
6367
|
-
}
|
6964
|
+
ViewPlugin17.fromClass(class {
|
6368
6965
|
update(update2) {
|
6369
6966
|
const selectionChanged = !selectionEquals(update2.state.facet(selectionFacet), update2.startState.facet(selectionFacet));
|
6370
6967
|
if (update2.focusChanged || update2.docChanged || update2.viewportChanged || update2.selectionSet || selectionChanged) {
|
@@ -6384,18 +6981,22 @@ var decorations = () => [
|
|
6384
6981
|
const lineFrom = doc.lineAt(item.contentRange.from);
|
6385
6982
|
const lineTo = doc.lineAt(item.contentRange.to);
|
6386
6983
|
const isSelected = selection.includes(item.index) || item === current;
|
6387
|
-
decorations2.push(
|
6388
|
-
class:
|
6984
|
+
decorations2.push(Decoration13.line({
|
6985
|
+
class: mx6("cm-list-item", lineFrom.number === line.number && "cm-list-item-start", lineTo.number === line.number && "cm-list-item-end", isSelected && (hasFocus ? "cm-list-item-focused" : "cm-list-item-selected"))
|
6389
6986
|
}).range(line.from, line.from));
|
6390
6987
|
}
|
6391
6988
|
}
|
6392
|
-
this.decorations =
|
6989
|
+
this.decorations = Decoration13.set(decorations2);
|
6990
|
+
}
|
6991
|
+
constructor(view) {
|
6992
|
+
_define_property21(this, "decorations", Decoration13.none);
|
6993
|
+
this.updateDecorations(view.state, view);
|
6393
6994
|
}
|
6394
6995
|
}, {
|
6395
6996
|
decorations: (v) => v.decorations
|
6396
6997
|
}),
|
6397
6998
|
// Theme.
|
6398
|
-
|
6999
|
+
EditorView26.theme(Object.assign({
|
6399
7000
|
".cm-list-item": {
|
6400
7001
|
borderLeftWidth: "1px",
|
6401
7002
|
borderRightWidth: "1px",
|
@@ -6412,127 +7013,701 @@ var decorations = () => [
|
|
6412
7013
|
paddingTop: "4px",
|
6413
7014
|
marginTop: "2px"
|
6414
7015
|
},
|
6415
|
-
".cm-list-item-end": {
|
6416
|
-
borderBottomWidth: "1px",
|
6417
|
-
borderBottomLeftRadius: "4px",
|
6418
|
-
borderBottomRightRadius: "4px",
|
6419
|
-
paddingBottom: "4px",
|
6420
|
-
marginBottom: "2px"
|
7016
|
+
".cm-list-item-end": {
|
7017
|
+
borderBottomWidth: "1px",
|
7018
|
+
borderBottomLeftRadius: "4px",
|
7019
|
+
borderBottomRightRadius: "4px",
|
7020
|
+
paddingBottom: "4px",
|
7021
|
+
marginBottom: "2px"
|
7022
|
+
},
|
7023
|
+
".cm-list-item-focused": {
|
7024
|
+
borderColor: "var(--dx-accentFocusIndicator)"
|
7025
|
+
},
|
7026
|
+
"&:focus-within .cm-list-item-selected": {
|
7027
|
+
borderColor: "var(--dx-separator)"
|
7028
|
+
}
|
7029
|
+
}))
|
7030
|
+
];
|
7031
|
+
|
7032
|
+
// src/extensions/preview/preview.ts
|
7033
|
+
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
7034
|
+
import { RangeSetBuilder as RangeSetBuilder7, StateField as StateField11 } from "@codemirror/state";
|
7035
|
+
import { Decoration as Decoration14, EditorView as EditorView27, WidgetType as WidgetType9 } from "@codemirror/view";
|
7036
|
+
function _define_property22(obj, key, value) {
|
7037
|
+
if (key in obj) {
|
7038
|
+
Object.defineProperty(obj, key, {
|
7039
|
+
value,
|
7040
|
+
enumerable: true,
|
7041
|
+
configurable: true,
|
7042
|
+
writable: true
|
7043
|
+
});
|
7044
|
+
} else {
|
7045
|
+
obj[key] = value;
|
7046
|
+
}
|
7047
|
+
return obj;
|
7048
|
+
}
|
7049
|
+
var preview = (options = {}) => {
|
7050
|
+
return [
|
7051
|
+
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
7052
|
+
// "Block decorations may not be specified via plugins".
|
7053
|
+
StateField11.define({
|
7054
|
+
create: (state) => buildDecorations3(state, options),
|
7055
|
+
update: (decorations2, tr) => {
|
7056
|
+
if (tr.docChanged) {
|
7057
|
+
return buildDecorations3(tr.state, options);
|
7058
|
+
}
|
7059
|
+
return decorations2.map(tr.changes);
|
7060
|
+
},
|
7061
|
+
provide: (field) => [
|
7062
|
+
EditorView27.decorations.from(field),
|
7063
|
+
EditorView27.atomicRanges.of((view) => view.state.field(field))
|
7064
|
+
]
|
7065
|
+
})
|
7066
|
+
];
|
7067
|
+
};
|
7068
|
+
var buildDecorations3 = (state, options) => {
|
7069
|
+
const builder = new RangeSetBuilder7();
|
7070
|
+
syntaxTree10(state).iterate({
|
7071
|
+
enter: (node) => {
|
7072
|
+
switch (node.name) {
|
7073
|
+
//
|
7074
|
+
// Inline widget.
|
7075
|
+
// [Label](dxn:echo:123)
|
7076
|
+
//
|
7077
|
+
case "Link": {
|
7078
|
+
const link = getLinkRef(state, node.node);
|
7079
|
+
if (link) {
|
7080
|
+
builder.add(node.from, node.to, Decoration14.replace({
|
7081
|
+
widget: new PreviewInlineWidget(options, link),
|
7082
|
+
side: 1
|
7083
|
+
}));
|
7084
|
+
}
|
7085
|
+
return false;
|
7086
|
+
}
|
7087
|
+
//
|
7088
|
+
// Block widget (transclusion).
|
7089
|
+
// 
|
7090
|
+
//
|
7091
|
+
case "Image": {
|
7092
|
+
if (options.addBlockContainer && options.removeBlockContainer) {
|
7093
|
+
const link = getLinkRef(state, node.node);
|
7094
|
+
if (link) {
|
7095
|
+
builder.add(node.from, node.to, Decoration14.replace({
|
7096
|
+
block: true,
|
7097
|
+
widget: new PreviewBlockWidget(options, link)
|
7098
|
+
}));
|
7099
|
+
}
|
7100
|
+
}
|
7101
|
+
return false;
|
7102
|
+
}
|
7103
|
+
}
|
7104
|
+
}
|
7105
|
+
});
|
7106
|
+
return builder.finish();
|
7107
|
+
};
|
7108
|
+
var getLinkRef = (state, node) => {
|
7109
|
+
const mark = node.getChildren("LinkMark");
|
7110
|
+
const urlNode = node.getChild("URL");
|
7111
|
+
if (mark && urlNode) {
|
7112
|
+
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
7113
|
+
if (url.startsWith("dxn:")) {
|
7114
|
+
const label = state.sliceDoc(mark[0].to, mark[1].from);
|
7115
|
+
return {
|
7116
|
+
block: state.sliceDoc(mark[0].from, mark[0].from + 1) === "!",
|
7117
|
+
label,
|
7118
|
+
ref: url
|
7119
|
+
};
|
7120
|
+
}
|
7121
|
+
}
|
7122
|
+
};
|
7123
|
+
var PreviewInlineWidget = class extends WidgetType9 {
|
7124
|
+
// override ignoreEvent() {
|
7125
|
+
// return false;
|
7126
|
+
// }
|
7127
|
+
eq(other) {
|
7128
|
+
return this._link.ref === other._link.ref && this._link.label === other._link.label;
|
7129
|
+
}
|
7130
|
+
toDOM(_view) {
|
7131
|
+
const root = document.createElement("dx-anchor");
|
7132
|
+
root.classList.add("dx-tag--anchor");
|
7133
|
+
root.textContent = this._link.label;
|
7134
|
+
root.setAttribute("refId", this._link.ref);
|
7135
|
+
return root;
|
7136
|
+
}
|
7137
|
+
constructor(_options, _link) {
|
7138
|
+
super(), _define_property22(this, "_options", void 0), _define_property22(this, "_link", void 0), this._options = _options, this._link = _link;
|
7139
|
+
}
|
7140
|
+
};
|
7141
|
+
var PreviewBlockWidget = class extends WidgetType9 {
|
7142
|
+
// override ignoreEvent() {
|
7143
|
+
// return true;
|
7144
|
+
// }
|
7145
|
+
eq(other) {
|
7146
|
+
return this._link.ref === other._link.ref;
|
7147
|
+
}
|
7148
|
+
toDOM(_view) {
|
7149
|
+
const root = document.createElement("div");
|
7150
|
+
root.classList.add("cm-preview-block", "density-coarse");
|
7151
|
+
this._options.addBlockContainer?.(this._link, root);
|
7152
|
+
return root;
|
7153
|
+
}
|
7154
|
+
destroy() {
|
7155
|
+
this._options.removeBlockContainer?.(this._link);
|
7156
|
+
}
|
7157
|
+
constructor(_options, _link) {
|
7158
|
+
super(), _define_property22(this, "_options", void 0), _define_property22(this, "_link", void 0), this._options = _options, this._link = _link;
|
7159
|
+
}
|
7160
|
+
};
|
7161
|
+
|
7162
|
+
// src/extensions/tags/extended-markdown.ts
|
7163
|
+
import { xmlLanguage } from "@codemirror/lang-xml";
|
7164
|
+
import { parseMixed } from "@lezer/common";
|
7165
|
+
var extendedMarkdown = ({ registry } = {}) => {
|
7166
|
+
return [
|
7167
|
+
createMarkdownExtensions({
|
7168
|
+
extensions: [
|
7169
|
+
{
|
7170
|
+
wrap: mixedParser(registry),
|
7171
|
+
parseBlock: [
|
7172
|
+
// Disable SetextHeading since it causes flickering when parsing/rendering tasks in chunks.
|
7173
|
+
{
|
7174
|
+
name: "SetextHeading",
|
7175
|
+
parse: () => false
|
7176
|
+
}
|
7177
|
+
]
|
7178
|
+
}
|
7179
|
+
]
|
7180
|
+
})
|
7181
|
+
];
|
7182
|
+
};
|
7183
|
+
var mixedParser = (registry) => {
|
7184
|
+
const customTags = Object.keys(registry ?? {});
|
7185
|
+
const tagPattern = new RegExp(`<(${customTags.join("|")})`);
|
7186
|
+
return parseMixed((node, input) => {
|
7187
|
+
switch (node.name) {
|
7188
|
+
// Ignore XML inside of fenced and inline code.
|
7189
|
+
case "FencedCode":
|
7190
|
+
case "InlineCode": {
|
7191
|
+
return null;
|
7192
|
+
}
|
7193
|
+
// Parse multi-line HTML blocks.
|
7194
|
+
// case 'XMLBlock':
|
7195
|
+
case "HTMLBlock": {
|
7196
|
+
return {
|
7197
|
+
parser: xmlLanguage.parser
|
7198
|
+
};
|
7199
|
+
}
|
7200
|
+
// Parse paragraphs that contain custom XML tags.
|
7201
|
+
// TODO(burdon): Entire paragraph should be parsed as XML.
|
7202
|
+
case "Paragraph": {
|
7203
|
+
const content = input.read(node.from, node.to);
|
7204
|
+
if (tagPattern.test(content)) {
|
7205
|
+
return {
|
7206
|
+
parser: xmlLanguage.parser
|
7207
|
+
};
|
7208
|
+
}
|
7209
|
+
return null;
|
7210
|
+
}
|
7211
|
+
}
|
7212
|
+
return null;
|
7213
|
+
});
|
7214
|
+
};
|
7215
|
+
|
7216
|
+
// src/extensions/tags/streamer.ts
|
7217
|
+
import { StateEffect as StateEffect8, StateField as StateField12 } from "@codemirror/state";
|
7218
|
+
import { Decoration as Decoration15, EditorView as EditorView28, ViewPlugin as ViewPlugin18, WidgetType as WidgetType10 } from "@codemirror/view";
|
7219
|
+
import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
|
7220
|
+
function _define_property23(obj, key, value) {
|
7221
|
+
if (key in obj) {
|
7222
|
+
Object.defineProperty(obj, key, {
|
7223
|
+
value,
|
7224
|
+
enumerable: true,
|
7225
|
+
configurable: true,
|
7226
|
+
writable: true
|
7227
|
+
});
|
7228
|
+
} else {
|
7229
|
+
obj[key] = value;
|
7230
|
+
}
|
7231
|
+
return obj;
|
7232
|
+
}
|
7233
|
+
var BLINK_RATE = 2e3;
|
7234
|
+
var streamer = (options = {}) => {
|
7235
|
+
return [
|
7236
|
+
options.cursor && cursor(),
|
7237
|
+
options.fadeIn && fadeIn(typeof options.fadeIn === "object" ? options.fadeIn : {})
|
7238
|
+
].filter(isNotFalsy4);
|
7239
|
+
};
|
7240
|
+
var cursor = () => {
|
7241
|
+
const hideCursor = StateEffect8.define();
|
7242
|
+
const showCursor = StateField12.define({
|
7243
|
+
create: () => true,
|
7244
|
+
update: (value, tr) => {
|
7245
|
+
for (const effect of tr.effects) {
|
7246
|
+
if (effect.is(hideCursor)) {
|
7247
|
+
return false;
|
7248
|
+
}
|
7249
|
+
}
|
7250
|
+
if (tr.docChanged) {
|
7251
|
+
return true;
|
7252
|
+
}
|
7253
|
+
return value;
|
7254
|
+
}
|
7255
|
+
});
|
7256
|
+
const timerPlugin = ViewPlugin18.fromClass(class {
|
7257
|
+
update(update2) {
|
7258
|
+
if (update2.docChanged) {
|
7259
|
+
clearTimeout(this.timer);
|
7260
|
+
this.timer = setTimeout(() => {
|
7261
|
+
this.view.dispatch({
|
7262
|
+
effects: hideCursor.of(null)
|
7263
|
+
});
|
7264
|
+
}, BLINK_RATE);
|
7265
|
+
}
|
7266
|
+
}
|
7267
|
+
destroy() {
|
7268
|
+
clearTimeout(this.timer);
|
7269
|
+
}
|
7270
|
+
constructor(view) {
|
7271
|
+
_define_property23(this, "view", void 0);
|
7272
|
+
_define_property23(this, "timer", void 0);
|
7273
|
+
this.view = view;
|
7274
|
+
}
|
7275
|
+
});
|
7276
|
+
const cursorDecoration = StateField12.define({
|
7277
|
+
create: () => Decoration15.none,
|
7278
|
+
update: (_decorations, tr) => {
|
7279
|
+
const show = tr.state.field(showCursor);
|
7280
|
+
if (!show) {
|
7281
|
+
return Decoration15.none;
|
7282
|
+
}
|
7283
|
+
const endPos = tr.state.doc.length;
|
7284
|
+
return Decoration15.set([
|
7285
|
+
Decoration15.widget({
|
7286
|
+
widget: new CursorWidget(),
|
7287
|
+
side: 1
|
7288
|
+
}).range(endPos)
|
7289
|
+
]);
|
7290
|
+
},
|
7291
|
+
provide: (f) => EditorView28.decorations.from(f)
|
7292
|
+
});
|
7293
|
+
return [
|
7294
|
+
showCursor,
|
7295
|
+
timerPlugin,
|
7296
|
+
cursorDecoration
|
7297
|
+
];
|
7298
|
+
};
|
7299
|
+
var CursorWidget = class extends WidgetType10 {
|
7300
|
+
toDOM() {
|
7301
|
+
return Domino.of("span").style({
|
7302
|
+
opacity: "0.8"
|
7303
|
+
}).child(Domino.of("span").text("\u258F").style({
|
7304
|
+
animation: "blink 2s infinite"
|
7305
|
+
})).build();
|
7306
|
+
}
|
7307
|
+
};
|
7308
|
+
var fadeIn = (options = {}) => {
|
7309
|
+
const FADE_IN_DURATION = 1e3;
|
7310
|
+
const DEFAULT_REMOVAL_DELAY = 5e3;
|
7311
|
+
const removalDelay = options.removalDelay ?? DEFAULT_REMOVAL_DELAY;
|
7312
|
+
const removeDecoration = StateEffect8.define();
|
7313
|
+
const fadeField = StateField12.define({
|
7314
|
+
create: () => Decoration15.none,
|
7315
|
+
update: (decorations2, tr) => {
|
7316
|
+
let next = decorations2;
|
7317
|
+
for (const effect of tr.effects) {
|
7318
|
+
if (effect.is(removeDecoration)) {
|
7319
|
+
const target = effect.value;
|
7320
|
+
next = next.update({
|
7321
|
+
filter: (from, to) => !(from === target.from && to === target.to)
|
7322
|
+
});
|
7323
|
+
}
|
7324
|
+
}
|
7325
|
+
if (!tr.docChanged) {
|
7326
|
+
return next;
|
7327
|
+
}
|
7328
|
+
let isReset = tr.state.doc.length === 0;
|
7329
|
+
if (!isReset) {
|
7330
|
+
tr.changes.iterChanges((fromA, toA) => {
|
7331
|
+
if (fromA === 0 && toA === tr.startState.doc.length) {
|
7332
|
+
isReset = true;
|
7333
|
+
}
|
7334
|
+
});
|
7335
|
+
}
|
7336
|
+
if (isReset) {
|
7337
|
+
return Decoration15.none;
|
7338
|
+
}
|
7339
|
+
const add = [];
|
7340
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
7341
|
+
if (fromB === 0 && toB === inserted.length) {
|
7342
|
+
return;
|
7343
|
+
}
|
7344
|
+
if (toA === tr.startState.doc.length && inserted.length > 0) {
|
7345
|
+
add.push(Decoration15.mark({
|
7346
|
+
class: "cm-fade-in"
|
7347
|
+
}).range(fromB, toB));
|
7348
|
+
}
|
7349
|
+
});
|
7350
|
+
return next.update({
|
7351
|
+
add
|
7352
|
+
});
|
7353
|
+
},
|
7354
|
+
provide: (f) => EditorView28.decorations.from(f)
|
7355
|
+
});
|
7356
|
+
const timerPlugin = ViewPlugin18.fromClass(class {
|
7357
|
+
update(update2) {
|
7358
|
+
if (!update2.docChanged) {
|
7359
|
+
return;
|
7360
|
+
}
|
7361
|
+
update2.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
7362
|
+
if (toA !== update2.startState.doc.length || inserted.length === 0) {
|
7363
|
+
return;
|
7364
|
+
}
|
7365
|
+
const key = `${fromB}-${toB}`;
|
7366
|
+
if (this._timers.has(key)) {
|
7367
|
+
clearTimeout(this._timers.get(key));
|
7368
|
+
}
|
7369
|
+
const totalDelay = FADE_IN_DURATION + removalDelay;
|
7370
|
+
const id = setTimeout(() => {
|
7371
|
+
this.view.dispatch({
|
7372
|
+
effects: removeDecoration.of({
|
7373
|
+
from: fromB,
|
7374
|
+
to: toB
|
7375
|
+
})
|
7376
|
+
});
|
7377
|
+
this._timers.delete(key);
|
7378
|
+
}, totalDelay);
|
7379
|
+
this._timers.set(key, id);
|
7380
|
+
});
|
7381
|
+
}
|
7382
|
+
destroy() {
|
7383
|
+
for (const id of this._timers.values()) {
|
7384
|
+
clearTimeout(id);
|
7385
|
+
}
|
7386
|
+
this._timers.clear();
|
7387
|
+
}
|
7388
|
+
constructor(view) {
|
7389
|
+
_define_property23(this, "view", void 0);
|
7390
|
+
_define_property23(this, "_timers", void 0);
|
7391
|
+
this.view = view;
|
7392
|
+
this._timers = /* @__PURE__ */ new Map();
|
7393
|
+
}
|
7394
|
+
});
|
7395
|
+
return [
|
7396
|
+
fadeField,
|
7397
|
+
timerPlugin,
|
7398
|
+
EditorView28.theme({
|
7399
|
+
".cm-line > span": {
|
7400
|
+
opacity: "0.8"
|
7401
|
+
},
|
7402
|
+
".cm-fade-in": {
|
7403
|
+
animation: "fade-in 3s ease-out forwards"
|
7404
|
+
},
|
7405
|
+
"@keyframes fade-in": {
|
7406
|
+
"0%": {
|
7407
|
+
opacity: "0"
|
7408
|
+
},
|
7409
|
+
"80%": {
|
7410
|
+
opacity: "1"
|
7411
|
+
},
|
7412
|
+
"100%": {
|
7413
|
+
opacity: "0.8"
|
7414
|
+
}
|
7415
|
+
}
|
7416
|
+
})
|
7417
|
+
];
|
7418
|
+
};
|
7419
|
+
|
7420
|
+
// src/extensions/tags/xml-tags.ts
|
7421
|
+
import { syntaxTree as syntaxTree11 } from "@codemirror/language";
|
7422
|
+
import { RangeSetBuilder as RangeSetBuilder8, StateEffect as StateEffect9, StateField as StateField13 } from "@codemirror/state";
|
7423
|
+
import { Decoration as Decoration16, EditorView as EditorView29, WidgetType as WidgetType11 } from "@codemirror/view";
|
7424
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
7425
|
+
import { log as log8 } from "@dxos/log";
|
7426
|
+
|
7427
|
+
// src/extensions/tags/xml-util.ts
|
7428
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
7429
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/tags/xml-util.ts";
|
7430
|
+
var nodeToJson = (state, node) => {
|
7431
|
+
invariant6(node.type.name === "Element", "Node is not an Element", {
|
7432
|
+
F: __dxlog_file13,
|
7433
|
+
L: 18,
|
7434
|
+
S: void 0,
|
7435
|
+
A: [
|
7436
|
+
"node.type.name === 'Element'",
|
7437
|
+
"'Node is not an Element'"
|
7438
|
+
]
|
7439
|
+
});
|
7440
|
+
const openTag = node.node.getChild("OpenTag") || node.node.getChild("SelfClosingTag");
|
7441
|
+
if (openTag) {
|
7442
|
+
const tagName = openTag.getChild("TagName");
|
7443
|
+
if (!tagName) {
|
7444
|
+
return;
|
7445
|
+
}
|
7446
|
+
const tag = {
|
7447
|
+
_tag: state.doc.sliceString(tagName.from, tagName.to)
|
7448
|
+
};
|
7449
|
+
let attributeNode = openTag.getChild("Attribute");
|
7450
|
+
while (attributeNode) {
|
7451
|
+
const attrName = attributeNode.getChild("AttributeName");
|
7452
|
+
const attrValue = attributeNode.getChild("AttributeValue");
|
7453
|
+
if (attrName) {
|
7454
|
+
const attr = state.doc.sliceString(attrName.from, attrName.to);
|
7455
|
+
let value = true;
|
7456
|
+
if (attrValue) {
|
7457
|
+
const rawValue = state.doc.sliceString(attrValue.from, attrValue.to);
|
7458
|
+
if (rawValue.startsWith('"') && rawValue.endsWith('"') || rawValue.startsWith("'") && rawValue.endsWith("'")) {
|
7459
|
+
value = rawValue.slice(1, -1);
|
7460
|
+
} else {
|
7461
|
+
value = rawValue;
|
7462
|
+
}
|
7463
|
+
}
|
7464
|
+
tag[attr] = value;
|
7465
|
+
}
|
7466
|
+
attributeNode = attributeNode.nextSibling;
|
7467
|
+
}
|
7468
|
+
if (node.type.name === "Element" && openTag.type.name !== "SelfClosingTag") {
|
7469
|
+
const children = [];
|
7470
|
+
let child = node.node.firstChild;
|
7471
|
+
while (child) {
|
7472
|
+
if (child.type.name !== "OpenTag" && child.type.name !== "CloseTag") {
|
7473
|
+
if (child.type.name === "Text") {
|
7474
|
+
const text = state.doc.sliceString(child.from, child.to).trim();
|
7475
|
+
if (text) {
|
7476
|
+
children.push(text);
|
7477
|
+
}
|
7478
|
+
} else if (child.type.name === "Element") {
|
7479
|
+
const data = nodeToJson(state, child);
|
7480
|
+
if (data) {
|
7481
|
+
children.push(data);
|
7482
|
+
}
|
7483
|
+
}
|
7484
|
+
}
|
7485
|
+
child = child.nextSibling;
|
7486
|
+
}
|
7487
|
+
if (children.length > 0) {
|
7488
|
+
tag.children = children;
|
7489
|
+
}
|
7490
|
+
}
|
7491
|
+
return tag;
|
7492
|
+
}
|
7493
|
+
};
|
7494
|
+
|
7495
|
+
// src/extensions/tags/xml-tags.ts
|
7496
|
+
function _define_property24(obj, key, value) {
|
7497
|
+
if (key in obj) {
|
7498
|
+
Object.defineProperty(obj, key, {
|
7499
|
+
value,
|
7500
|
+
enumerable: true,
|
7501
|
+
configurable: true,
|
7502
|
+
writable: true
|
7503
|
+
});
|
7504
|
+
} else {
|
7505
|
+
obj[key] = value;
|
7506
|
+
}
|
7507
|
+
return obj;
|
7508
|
+
}
|
7509
|
+
var __dxlog_file14 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/extensions/tags/xml-tags.ts";
|
7510
|
+
var xmlTagContextEffect = StateEffect9.define();
|
7511
|
+
var xmlTagUpdateEffect = StateEffect9.define();
|
7512
|
+
var xmlTagResetEffect = StateEffect9.define();
|
7513
|
+
var xmlTags = (options = {}) => {
|
7514
|
+
const contextState = StateField13.define({
|
7515
|
+
create: () => void 0,
|
7516
|
+
update: (value, tr) => {
|
7517
|
+
for (const effect of tr.effects) {
|
7518
|
+
if (effect.is(xmlTagContextEffect)) {
|
7519
|
+
return effect.value;
|
7520
|
+
}
|
7521
|
+
}
|
7522
|
+
return value;
|
7523
|
+
}
|
7524
|
+
});
|
7525
|
+
const widgets = /* @__PURE__ */ new Map();
|
7526
|
+
const notifier = {
|
7527
|
+
mounted: (widget) => {
|
7528
|
+
widgets.set(widget.id, widget);
|
7529
|
+
options.setWidgets?.([
|
7530
|
+
...widgets.values()
|
7531
|
+
]);
|
7532
|
+
},
|
7533
|
+
unmounted: (id) => {
|
7534
|
+
widgets.delete(id);
|
7535
|
+
options.setWidgets?.([
|
7536
|
+
...widgets.values()
|
7537
|
+
]);
|
7538
|
+
}
|
7539
|
+
};
|
7540
|
+
const decorationsState = StateField13.define({
|
7541
|
+
create: (state) => {
|
7542
|
+
return buildDecorations4(state, 0, state.doc.length, state.field(contextState), state.field(widgetState), options, notifier);
|
6421
7543
|
},
|
6422
|
-
|
6423
|
-
|
7544
|
+
update: ({ from, decorations: decorations2 }, tr) => {
|
7545
|
+
for (const effect of tr.effects) {
|
7546
|
+
if (effect.is(xmlTagResetEffect)) {
|
7547
|
+
return {
|
7548
|
+
from: 0,
|
7549
|
+
decorations: Decoration16.none
|
7550
|
+
};
|
7551
|
+
}
|
7552
|
+
}
|
7553
|
+
if (tr.docChanged) {
|
7554
|
+
const { state } = tr;
|
7555
|
+
const reset = tr.changes.touchesRange(0, from);
|
7556
|
+
const result = buildDecorations4(state, reset ? 0 : from, state.doc.length, state.field(contextState), state.field(widgetState), options, notifier);
|
7557
|
+
return {
|
7558
|
+
from: result.from,
|
7559
|
+
decorations: decorations2.update({
|
7560
|
+
add: decorationSetToArray(result.decorations)
|
7561
|
+
})
|
7562
|
+
};
|
7563
|
+
}
|
7564
|
+
return {
|
7565
|
+
from,
|
7566
|
+
decorations: decorations2
|
7567
|
+
};
|
6424
7568
|
},
|
6425
|
-
|
6426
|
-
|
7569
|
+
provide: (field) => [
|
7570
|
+
EditorView29.decorations.from(field, (v) => v.decorations),
|
7571
|
+
EditorView29.atomicRanges.of((view) => view.state.field(field).decorations || Decoration16.none)
|
7572
|
+
]
|
7573
|
+
});
|
7574
|
+
const widgetState = StateField13.define({
|
7575
|
+
create: () => ({}),
|
7576
|
+
update: (map, tr) => {
|
7577
|
+
for (const effect of tr.effects) {
|
7578
|
+
if (effect.is(xmlTagResetEffect)) {
|
7579
|
+
return {};
|
7580
|
+
}
|
7581
|
+
if (effect.is(xmlTagUpdateEffect)) {
|
7582
|
+
const { id, value } = effect.value;
|
7583
|
+
const state = typeof value === "function" ? value(map[id]) : value;
|
7584
|
+
const { decorations: decorations2 } = tr.state.field(decorationsState);
|
7585
|
+
for (const range of decorationSetToArray(decorations2)) {
|
7586
|
+
const deco = range.value;
|
7587
|
+
const widget = deco?.spec?.widget;
|
7588
|
+
if (widget && widget instanceof PlaceholderWidget && widget.id === effect.value.id && widget.root) {
|
7589
|
+
const props = {
|
7590
|
+
...widget.props,
|
7591
|
+
...state
|
7592
|
+
};
|
7593
|
+
notifier.mounted({
|
7594
|
+
id: widget.id,
|
7595
|
+
props,
|
7596
|
+
root: widget.root,
|
7597
|
+
Component: widget.Component
|
7598
|
+
});
|
7599
|
+
}
|
7600
|
+
}
|
7601
|
+
return {
|
7602
|
+
...map,
|
7603
|
+
[id]: state
|
7604
|
+
};
|
7605
|
+
}
|
7606
|
+
}
|
7607
|
+
return map;
|
6427
7608
|
}
|
6428
|
-
})
|
6429
|
-
];
|
6430
|
-
|
6431
|
-
// src/extensions/preview/preview.ts
|
6432
|
-
import "@dxos/lit-ui/dx-ref-tag.pcss";
|
6433
|
-
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
6434
|
-
import { RangeSetBuilder as RangeSetBuilder7, StateField as StateField11 } from "@codemirror/state";
|
6435
|
-
import { Decoration as Decoration13, EditorView as EditorView25, WidgetType as WidgetType8 } from "@codemirror/view";
|
6436
|
-
var preview = (options = {}) => {
|
7609
|
+
});
|
6437
7610
|
return [
|
6438
|
-
|
6439
|
-
|
6440
|
-
|
6441
|
-
create: (state) => buildDecorations3(state, options),
|
6442
|
-
update: (_, tr) => buildDecorations3(tr.state, options),
|
6443
|
-
provide: (field) => [
|
6444
|
-
EditorView25.decorations.from(field),
|
6445
|
-
EditorView25.atomicRanges.of((view) => view.state.field(field))
|
6446
|
-
]
|
6447
|
-
})
|
7611
|
+
contextState,
|
7612
|
+
decorationsState,
|
7613
|
+
widgetState
|
6448
7614
|
];
|
6449
7615
|
};
|
6450
|
-
var
|
6451
|
-
const
|
6452
|
-
const
|
6453
|
-
if (
|
6454
|
-
const ref = state.sliceDoc(label.from + 1, label.to - 1);
|
7616
|
+
var buildDecorations4 = (state, from, to, context, widgetState, options, notifier) => {
|
7617
|
+
const builder = new RangeSetBuilder8();
|
7618
|
+
const tree = syntaxTree11(state);
|
7619
|
+
if (!tree || tree.type.name === "Program" && tree.length === 0) {
|
6455
7620
|
return {
|
6456
|
-
|
6457
|
-
|
6458
|
-
label: state.sliceDoc(mark.to, label.from - 1),
|
6459
|
-
ref: ref.startsWith("?") ? ref.slice(1) : ref
|
7621
|
+
from,
|
7622
|
+
decorations: Decoration16.none
|
6460
7623
|
};
|
6461
7624
|
}
|
6462
|
-
|
6463
|
-
|
6464
|
-
|
6465
|
-
syntaxTree10(state).iterate({
|
7625
|
+
tree.iterate({
|
7626
|
+
from,
|
7627
|
+
to,
|
6466
7628
|
enter: (node) => {
|
6467
|
-
switch (node.name) {
|
6468
|
-
//
|
6469
|
-
|
6470
|
-
|
6471
|
-
|
6472
|
-
|
6473
|
-
|
6474
|
-
|
6475
|
-
|
6476
|
-
|
6477
|
-
|
6478
|
-
|
6479
|
-
|
6480
|
-
|
6481
|
-
|
6482
|
-
|
6483
|
-
|
6484
|
-
|
6485
|
-
|
6486
|
-
|
6487
|
-
|
6488
|
-
|
6489
|
-
|
6490
|
-
|
6491
|
-
|
6492
|
-
|
7629
|
+
switch (node.type.name) {
|
7630
|
+
// XML Element.
|
7631
|
+
case "Element": {
|
7632
|
+
try {
|
7633
|
+
if (options.registry) {
|
7634
|
+
const props = nodeToJson(state, node.node);
|
7635
|
+
if (props) {
|
7636
|
+
const def = options.registry[props._tag];
|
7637
|
+
if (def) {
|
7638
|
+
const { block, factory, Component } = def;
|
7639
|
+
const state2 = props.id ? widgetState[props.id] : void 0;
|
7640
|
+
const args = {
|
7641
|
+
context,
|
7642
|
+
...props,
|
7643
|
+
...state2
|
7644
|
+
};
|
7645
|
+
const widget = factory ? factory(args) : Component ? props.id && new PlaceholderWidget(props.id, Component, args, notifier) : void 0;
|
7646
|
+
if (widget) {
|
7647
|
+
from = node.node.to;
|
7648
|
+
builder.add(node.node.from, node.node.to, Decoration16.replace({
|
7649
|
+
widget,
|
7650
|
+
block,
|
7651
|
+
atomic: true,
|
7652
|
+
inclusive: true
|
7653
|
+
}));
|
7654
|
+
}
|
7655
|
+
}
|
7656
|
+
}
|
7657
|
+
}
|
7658
|
+
} catch (err) {
|
7659
|
+
log8.catch(err, void 0, {
|
7660
|
+
F: __dxlog_file14,
|
7661
|
+
L: 285,
|
7662
|
+
S: void 0,
|
7663
|
+
C: (f, a) => f(...a)
|
7664
|
+
});
|
6493
7665
|
}
|
6494
|
-
|
7666
|
+
return false;
|
6495
7667
|
}
|
6496
7668
|
}
|
6497
7669
|
}
|
6498
7670
|
});
|
6499
|
-
return
|
7671
|
+
return {
|
7672
|
+
from,
|
7673
|
+
decorations: builder.finish()
|
7674
|
+
};
|
6500
7675
|
};
|
6501
|
-
var
|
6502
|
-
|
6503
|
-
|
7676
|
+
var PlaceholderWidget = class _PlaceholderWidget extends WidgetType11 {
|
7677
|
+
get root() {
|
7678
|
+
return this._root;
|
6504
7679
|
}
|
6505
|
-
// override ignoreEvent() {
|
6506
|
-
// return false;
|
6507
|
-
// }
|
6508
7680
|
eq(other) {
|
6509
|
-
return
|
6510
|
-
}
|
6511
|
-
toDOM(view) {
|
6512
|
-
const root = document.createElement("dx-ref-tag");
|
6513
|
-
root.textContent = this._link.label;
|
6514
|
-
root.setAttribute("refId", this._link.ref);
|
6515
|
-
return root;
|
7681
|
+
return other instanceof _PlaceholderWidget && this.id === other.id;
|
6516
7682
|
}
|
6517
|
-
|
6518
|
-
|
6519
|
-
constructor(_options, _link) {
|
6520
|
-
super(), this._options = _options, this._link = _link;
|
7683
|
+
ignoreEvent() {
|
7684
|
+
return true;
|
6521
7685
|
}
|
6522
|
-
|
6523
|
-
|
6524
|
-
|
6525
|
-
|
6526
|
-
|
7686
|
+
toDOM(_view) {
|
7687
|
+
this._root = document.createElement("span");
|
7688
|
+
this.notifier.mounted({
|
7689
|
+
id: this.id,
|
7690
|
+
props: this.props,
|
7691
|
+
root: this._root,
|
7692
|
+
Component: this.Component
|
7693
|
+
});
|
7694
|
+
return this._root;
|
6527
7695
|
}
|
6528
|
-
|
6529
|
-
|
6530
|
-
|
6531
|
-
this._options.addBlockContainer?.(this._link, root);
|
6532
|
-
return root;
|
7696
|
+
destroy(_dom) {
|
7697
|
+
this.notifier.unmounted(this.id);
|
7698
|
+
this._root = null;
|
6533
7699
|
}
|
6534
|
-
|
6535
|
-
this.
|
7700
|
+
constructor(id, Component, props, notifier) {
|
7701
|
+
super(), _define_property24(this, "id", void 0), _define_property24(this, "Component", void 0), _define_property24(this, "props", void 0), _define_property24(this, "notifier", void 0), _define_property24(this, "_root", void 0), this.id = id, this.Component = Component, this.props = props, this.notifier = notifier, this._root = null;
|
7702
|
+
invariant7(id, void 0, {
|
7703
|
+
F: __dxlog_file14,
|
7704
|
+
L: 310,
|
7705
|
+
S: this,
|
7706
|
+
A: [
|
7707
|
+
"id",
|
7708
|
+
""
|
7709
|
+
]
|
7710
|
+
});
|
6536
7711
|
}
|
6537
7712
|
};
|
6538
7713
|
|
@@ -6594,7 +7769,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
6594
7769
|
};
|
6595
7770
|
|
6596
7771
|
// src/hooks/useTextEditor.ts
|
6597
|
-
var
|
7772
|
+
var __dxlog_file15 = "/__w/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
|
6598
7773
|
var instanceCount = 0;
|
6599
7774
|
var useTextEditor = (props = {}, deps = []) => {
|
6600
7775
|
const { id, doc, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } = useMemo3(() => getProviderValue(props), deps ?? []);
|
@@ -6604,12 +7779,12 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6604
7779
|
useEffect2(() => {
|
6605
7780
|
let view2;
|
6606
7781
|
if (parentRef.current) {
|
6607
|
-
|
7782
|
+
log9("create", {
|
6608
7783
|
id,
|
6609
7784
|
instanceId,
|
6610
7785
|
doc: initialValue?.length ?? 0
|
6611
7786
|
}, {
|
6612
|
-
F:
|
7787
|
+
F: __dxlog_file15,
|
6613
7788
|
L: 75,
|
6614
7789
|
S: void 0,
|
6615
7790
|
C: (f, a) => f(...a)
|
@@ -6633,20 +7808,20 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6633
7808
|
id && documentId.of(id),
|
6634
7809
|
extensions,
|
6635
7810
|
// NOTE: This doesn't catch errors in keymap functions.
|
6636
|
-
|
6637
|
-
|
6638
|
-
F:
|
7811
|
+
EditorView30.exceptionSink.of((err) => {
|
7812
|
+
log9.catch(err, void 0, {
|
7813
|
+
F: __dxlog_file15,
|
6639
7814
|
L: 97,
|
6640
7815
|
S: void 0,
|
6641
7816
|
C: (f, a) => f(...a)
|
6642
7817
|
});
|
6643
7818
|
})
|
6644
|
-
].filter(
|
7819
|
+
].filter(isNotFalsy5)
|
6645
7820
|
});
|
6646
|
-
view2 = new
|
7821
|
+
view2 = new EditorView30({
|
6647
7822
|
parent: parentRef.current,
|
6648
7823
|
state,
|
6649
|
-
scrollTo: scrollTo ?
|
7824
|
+
scrollTo: scrollTo ? EditorView30.scrollIntoView(scrollTo, {
|
6650
7825
|
yMargin: 96
|
6651
7826
|
}) : void 0,
|
6652
7827
|
dispatchTransactions: debug ? debugDispatcher : void 0
|
@@ -6664,11 +7839,11 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6664
7839
|
setView(view2);
|
6665
7840
|
}
|
6666
7841
|
return () => {
|
6667
|
-
|
7842
|
+
log9("destroy", {
|
6668
7843
|
id
|
6669
7844
|
}, {
|
6670
|
-
F:
|
6671
|
-
L:
|
7845
|
+
F: __dxlog_file15,
|
7846
|
+
L: 122,
|
6672
7847
|
S: void 0,
|
6673
7848
|
C: (f, a) => f(...a)
|
6674
7849
|
});
|
@@ -6679,13 +7854,13 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6679
7854
|
if (view) {
|
6680
7855
|
if (scrollTo || selection) {
|
6681
7856
|
if (selection && selection.anchor > view.state.doc.length) {
|
6682
|
-
|
7857
|
+
log9.warn("invalid selection", {
|
6683
7858
|
length: view.state.doc.length,
|
6684
7859
|
scrollTo,
|
6685
7860
|
selection
|
6686
7861
|
}, {
|
6687
|
-
F:
|
6688
|
-
L:
|
7862
|
+
F: __dxlog_file15,
|
7863
|
+
L: 131,
|
6689
7864
|
S: void 0,
|
6690
7865
|
C: (f, a) => f(...a)
|
6691
7866
|
});
|
@@ -6759,7 +7934,7 @@ var Editor = /* @__PURE__ */ forwardRef(({ classNames, id, text, ...props }, for
|
|
6759
7934
|
]);
|
6760
7935
|
return /* @__PURE__ */ React3.createElement("div", {
|
6761
7936
|
ref: parentRef,
|
6762
|
-
className:
|
7937
|
+
className: mx7(classNames),
|
6763
7938
|
...focusAttributes
|
6764
7939
|
});
|
6765
7940
|
} finally {
|
@@ -6782,23 +7957,32 @@ import { createMenuAction, createMenuItemGroup } from "@dxos/react-ui-menu";
|
|
6782
7957
|
var useEditorToolbarState = (initialState = {}) => {
|
6783
7958
|
return useMemo4(() => live(initialState), []);
|
6784
7959
|
};
|
6785
|
-
var createEditorAction = (id,
|
7960
|
+
var createEditorAction = (id, props, invoke) => {
|
6786
7961
|
const { label = [
|
6787
7962
|
`${id} label`,
|
6788
7963
|
{
|
6789
7964
|
ns: translationKey
|
6790
7965
|
}
|
6791
|
-
], ...rest } =
|
7966
|
+
], ...rest } = props;
|
6792
7967
|
return createMenuAction(id, invoke, {
|
6793
7968
|
label,
|
6794
7969
|
...rest
|
6795
7970
|
});
|
6796
7971
|
};
|
6797
|
-
var createEditorActionGroup = (id, props, icon) =>
|
6798
|
-
|
6799
|
-
|
6800
|
-
|
6801
|
-
|
7972
|
+
var createEditorActionGroup = (id, props, icon) => {
|
7973
|
+
const { label = [
|
7974
|
+
`${id} label`,
|
7975
|
+
{
|
7976
|
+
ns: translationKey
|
7977
|
+
}
|
7978
|
+
], ...rest } = props;
|
7979
|
+
return createMenuItemGroup(id, {
|
7980
|
+
label,
|
7981
|
+
icon,
|
7982
|
+
iconOnly: true,
|
7983
|
+
...rest
|
7984
|
+
});
|
7985
|
+
};
|
6802
7986
|
|
6803
7987
|
// src/components/EditorToolbar/blocks.ts
|
6804
7988
|
var createBlockGroupAction = (value) => createEditorActionGroup("block", {
|
@@ -6812,7 +7996,13 @@ var createBlockActions = (value, getView, blankLine) => Object.entries({
|
|
6812
7996
|
table: "ph--table--regular"
|
6813
7997
|
}).map(([type, icon]) => {
|
6814
7998
|
const checked = type === value;
|
6815
|
-
return createEditorAction(type,
|
7999
|
+
return createEditorAction(type, {
|
8000
|
+
checked,
|
8001
|
+
...type === "table" && {
|
8002
|
+
disabled: !!blankLine
|
8003
|
+
},
|
8004
|
+
icon
|
8005
|
+
}, () => {
|
6816
8006
|
const view = getView();
|
6817
8007
|
if (!view) {
|
6818
8008
|
return;
|
@@ -6828,12 +8018,6 @@ var createBlockActions = (value, getView, blankLine) => Object.entries({
|
|
6828
8018
|
insertTable(view);
|
6829
8019
|
break;
|
6830
8020
|
}
|
6831
|
-
}, {
|
6832
|
-
checked,
|
6833
|
-
...type === "table" && {
|
6834
|
-
disabled: !!blankLine
|
6835
|
-
},
|
6836
|
-
icon
|
6837
8021
|
});
|
6838
8022
|
});
|
6839
8023
|
var createBlocks = (state, getView) => {
|
@@ -6873,7 +8057,10 @@ var createFormattingGroup = (formatting) => createEditorActionGroup("formatting"
|
|
6873
8057
|
});
|
6874
8058
|
var createFormattingActions = (formatting, getView) => Object.entries(formats).map(([type, icon]) => {
|
6875
8059
|
const checked = !!formatting[type];
|
6876
|
-
return createEditorAction(type,
|
8060
|
+
return createEditorAction(type, {
|
8061
|
+
checked,
|
8062
|
+
icon
|
8063
|
+
}, () => {
|
6877
8064
|
const view = getView();
|
6878
8065
|
if (!view) {
|
6879
8066
|
return;
|
@@ -6884,9 +8071,6 @@ var createFormattingActions = (formatting, getView) => Object.entries(formats).m
|
|
6884
8071
|
}
|
6885
8072
|
const inlineType = type === "strong" ? Inline.Strong : type === "emphasis" ? Inline.Emphasis : type === "strikethrough" ? Inline.Strikethrough : Inline.Code;
|
6886
8073
|
setStyle(inlineType, !checked)(view);
|
6887
|
-
}, {
|
6888
|
-
checked,
|
6889
|
-
icon
|
6890
8074
|
});
|
6891
8075
|
});
|
6892
8076
|
var createFormatting = (state, getView) => {
|
@@ -6927,7 +8111,7 @@ var createHeadingActions = (getView) => Object.entries({
|
|
6927
8111
|
"6": "ph--text-h-six--regular"
|
6928
8112
|
}).map(([levelStr, icon]) => {
|
6929
8113
|
const level = parseInt(levelStr);
|
6930
|
-
return createEditorAction(`heading--${levelStr}`,
|
8114
|
+
return createEditorAction(`heading--${levelStr}`, {
|
6931
8115
|
label: [
|
6932
8116
|
"heading level label",
|
6933
8117
|
{
|
@@ -6936,7 +8120,7 @@ var createHeadingActions = (getView) => Object.entries({
|
|
6936
8120
|
}
|
6937
8121
|
],
|
6938
8122
|
icon
|
6939
|
-
});
|
8123
|
+
}, () => setHeading(level)(getView()));
|
6940
8124
|
});
|
6941
8125
|
var computeHeadingValue = (state) => {
|
6942
8126
|
const blockType = state ? state.blockType : "paragraph";
|
@@ -6966,10 +8150,10 @@ var createHeadings = (state, getView) => {
|
|
6966
8150
|
};
|
6967
8151
|
|
6968
8152
|
// src/components/EditorToolbar/image.ts
|
6969
|
-
var createImageUploadAction = (onImageUpload) => createEditorAction("image",
|
8153
|
+
var createImageUploadAction = (onImageUpload) => createEditorAction("image", {
|
6970
8154
|
testId: "editor.toolbar.image",
|
6971
8155
|
icon: "ph--image-square--regular"
|
6972
|
-
});
|
8156
|
+
}, onImageUpload);
|
6973
8157
|
var createImageUpload = (onImageUpload) => ({
|
6974
8158
|
nodes: [
|
6975
8159
|
createImageUploadAction(onImageUpload)
|
@@ -6995,7 +8179,10 @@ var createListGroupAction = (value) => createEditorActionGroup("list", {
|
|
6995
8179
|
});
|
6996
8180
|
var createListActions = (value, getView) => Object.entries(listStyles).map(([listStyle, icon]) => {
|
6997
8181
|
const checked = value === listStyle;
|
6998
|
-
return createEditorAction(`list-${listStyle}`,
|
8182
|
+
return createEditorAction(`list-${listStyle}`, {
|
8183
|
+
checked,
|
8184
|
+
icon
|
8185
|
+
}, () => {
|
6999
8186
|
const view = getView();
|
7000
8187
|
if (!view) {
|
7001
8188
|
return;
|
@@ -7006,9 +8193,6 @@ var createListActions = (value, getView) => Object.entries(listStyles).map(([lis
|
|
7006
8193
|
} else {
|
7007
8194
|
addList(listType)(view);
|
7008
8195
|
}
|
7009
|
-
}, {
|
7010
|
-
checked,
|
7011
|
-
icon
|
7012
8196
|
});
|
7013
8197
|
});
|
7014
8198
|
var createLists = (state, getView) => {
|
@@ -7035,10 +8219,10 @@ var createLists = (state, getView) => {
|
|
7035
8219
|
|
7036
8220
|
// src/components/EditorToolbar/search.ts
|
7037
8221
|
import { openSearchPanel } from "@codemirror/search";
|
7038
|
-
var createSearchAction = (getView) => createEditorAction("search",
|
8222
|
+
var createSearchAction = (getView) => createEditorAction("search", {
|
7039
8223
|
testId: "editor.toolbar.search",
|
7040
8224
|
icon: "ph--magnifying-glass--regular"
|
7041
|
-
});
|
8225
|
+
}, () => openSearchPanel(getView()));
|
7042
8226
|
var createSearch = (getView) => ({
|
7043
8227
|
nodes: [
|
7044
8228
|
createSearchAction(getView)
|
@@ -7064,7 +8248,7 @@ var createViewModeActions = (value, onViewModeChange) => Object.entries({
|
|
7064
8248
|
readonly: "ph--pencil-slash--regular"
|
7065
8249
|
}).map(([viewMode, icon]) => {
|
7066
8250
|
const checked = viewMode === value;
|
7067
|
-
return createEditorAction(`view-mode--${viewMode}`,
|
8251
|
+
return createEditorAction(`view-mode--${viewMode}`, {
|
7068
8252
|
label: [
|
7069
8253
|
`${viewMode} mode label`,
|
7070
8254
|
{
|
@@ -7073,7 +8257,7 @@ var createViewModeActions = (value, onViewModeChange) => Object.entries({
|
|
7073
8257
|
],
|
7074
8258
|
checked,
|
7075
8259
|
icon
|
7076
|
-
});
|
8260
|
+
}, () => onViewModeChange(viewMode));
|
7077
8261
|
});
|
7078
8262
|
var createViewMode = (state, onViewModeChange) => {
|
7079
8263
|
const value = state.viewMode ?? "source";
|
@@ -7098,61 +8282,62 @@ var createViewMode = (state, onViewModeChange) => {
|
|
7098
8282
|
};
|
7099
8283
|
|
7100
8284
|
// src/components/EditorToolbar/EditorToolbar.tsx
|
7101
|
-
var
|
8285
|
+
var createToolbarActions = ({ getView, state, customActions, ...features }) => {
|
7102
8286
|
return Rx.make((get2) => {
|
7103
|
-
const
|
7104
|
-
|
8287
|
+
const graph = {
|
8288
|
+
nodes: [],
|
8289
|
+
edges: []
|
8290
|
+
};
|
7105
8291
|
if (features.headings ?? true) {
|
7106
8292
|
const headings2 = get2(rxFromSignal(() => createHeadings(state, getView)));
|
7107
|
-
nodes.push(...headings2.nodes);
|
7108
|
-
edges.push(...headings2.edges);
|
8293
|
+
graph.nodes.push(...headings2.nodes);
|
8294
|
+
graph.edges.push(...headings2.edges);
|
7109
8295
|
}
|
7110
8296
|
if (features.formatting ?? true) {
|
7111
8297
|
const formatting = get2(rxFromSignal(() => createFormatting(state, getView)));
|
7112
|
-
nodes.push(...formatting.nodes);
|
7113
|
-
edges.push(...formatting.edges);
|
8298
|
+
graph.nodes.push(...formatting.nodes);
|
8299
|
+
graph.edges.push(...formatting.edges);
|
7114
8300
|
}
|
7115
8301
|
if (features.lists ?? true) {
|
7116
8302
|
const lists = get2(rxFromSignal(() => createLists(state, getView)));
|
7117
|
-
nodes.push(...lists.nodes);
|
7118
|
-
edges.push(...lists.edges);
|
8303
|
+
graph.nodes.push(...lists.nodes);
|
8304
|
+
graph.edges.push(...lists.edges);
|
7119
8305
|
}
|
7120
8306
|
if (features.blocks ?? true) {
|
7121
8307
|
const blocks = get2(rxFromSignal(() => createBlocks(state, getView)));
|
7122
|
-
nodes.push(...blocks.nodes);
|
7123
|
-
edges.push(...blocks.edges);
|
8308
|
+
graph.nodes.push(...blocks.nodes);
|
8309
|
+
graph.edges.push(...blocks.edges);
|
7124
8310
|
}
|
7125
8311
|
if (features.image) {
|
7126
8312
|
const image2 = get2(rxFromSignal(() => createImageUpload(features.image)));
|
7127
|
-
nodes.push(...image2.nodes);
|
7128
|
-
edges.push(...image2.edges);
|
8313
|
+
graph.nodes.push(...image2.nodes);
|
8314
|
+
graph.edges.push(...image2.edges);
|
8315
|
+
}
|
8316
|
+
{
|
8317
|
+
const gap = createGapSeparator();
|
8318
|
+
graph.nodes.push(...gap.nodes);
|
8319
|
+
graph.edges.push(...gap.edges);
|
7129
8320
|
}
|
7130
|
-
const editorToolbarGap = createGapSeparator();
|
7131
|
-
nodes.push(...editorToolbarGap.nodes);
|
7132
|
-
edges.push(...editorToolbarGap.edges);
|
7133
8321
|
if (customActions) {
|
7134
8322
|
const custom = get2(customActions);
|
7135
|
-
nodes.push(...custom.nodes);
|
7136
|
-
edges.push(...custom.edges);
|
8323
|
+
graph.nodes.push(...custom.nodes);
|
8324
|
+
graph.edges.push(...custom.edges);
|
7137
8325
|
}
|
7138
8326
|
if (features.search ?? true) {
|
7139
8327
|
const search = get2(rxFromSignal(() => createSearch(getView)));
|
7140
|
-
nodes.push(...search.nodes);
|
7141
|
-
edges.push(...search.edges);
|
8328
|
+
graph.nodes.push(...search.nodes);
|
8329
|
+
graph.edges.push(...search.edges);
|
7142
8330
|
}
|
7143
8331
|
if (features.viewMode) {
|
7144
8332
|
const viewMode = get2(rxFromSignal(() => createViewMode(state, features.viewMode)));
|
7145
|
-
nodes.push(...viewMode.nodes);
|
7146
|
-
edges.push(...viewMode.edges);
|
8333
|
+
graph.nodes.push(...viewMode.nodes);
|
8334
|
+
graph.edges.push(...viewMode.edges);
|
7147
8335
|
}
|
7148
|
-
return
|
7149
|
-
nodes,
|
7150
|
-
edges
|
7151
|
-
};
|
8336
|
+
return graph;
|
7152
8337
|
});
|
7153
8338
|
};
|
7154
8339
|
var useEditorToolbarActionGraph = (props) => {
|
7155
|
-
const menuCreator = useMemo5(() =>
|
8340
|
+
const menuCreator = useMemo5(() => createToolbarActions({
|
7156
8341
|
getView: props.getView,
|
7157
8342
|
state: props.state,
|
7158
8343
|
customActions: props.customActions,
|
@@ -7195,26 +8380,64 @@ var EditorToolbar = /* @__PURE__ */ memo(({ classNames, attendableId, role, ...p
|
|
7195
8380
|
}
|
7196
8381
|
});
|
7197
8382
|
|
7198
|
-
// src/components/
|
8383
|
+
// src/components/CommandMenu/CommandMenu.tsx
|
7199
8384
|
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
7200
|
-
import
|
8385
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
8386
|
+
import React5, { Fragment, useCallback as useCallback4, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
8387
|
+
import { addEventListener as addEventListener2 } from "@dxos/async";
|
7201
8388
|
import { Icon as Icon2, Popover, toLocalizedString, useThemeContext as useThemeContext2, useTranslation } from "@dxos/react-ui";
|
7202
|
-
var
|
8389
|
+
var CommandMenuProvider = ({ groups, onSelect, onActivate, currentItem, children, open: propsOpen, onOpenChange, defaultOpen }) => {
|
7203
8390
|
var _effect = _useSignals3();
|
7204
8391
|
try {
|
7205
8392
|
const { tx } = useThemeContext2();
|
7206
8393
|
const groupsWithItems = groups.filter((group) => group.items.length > 0);
|
7207
|
-
|
8394
|
+
const trigger = useRef3(null);
|
8395
|
+
const [open, setOpen] = useControllableState({
|
8396
|
+
prop: propsOpen,
|
8397
|
+
onChange: onOpenChange,
|
8398
|
+
defaultProp: defaultOpen
|
8399
|
+
});
|
8400
|
+
const handleDxAnchorActivate = useCallback4((event) => {
|
8401
|
+
const { trigger: dxTrigger, refId } = event;
|
8402
|
+
if (!refId) {
|
8403
|
+
trigger.current = dxTrigger;
|
8404
|
+
if (onActivate) {
|
8405
|
+
onActivate(event);
|
8406
|
+
} else {
|
8407
|
+
queueMicrotask(() => setOpen(true));
|
8408
|
+
}
|
8409
|
+
}
|
8410
|
+
}, [
|
8411
|
+
onActivate
|
8412
|
+
]);
|
8413
|
+
const [rootRef, setRootRef] = useState3(null);
|
8414
|
+
useEffect3(() => {
|
8415
|
+
if (!rootRef || !handleDxAnchorActivate) {
|
8416
|
+
return;
|
8417
|
+
}
|
8418
|
+
return addEventListener2(rootRef, "dx-anchor-activate", handleDxAnchorActivate, {
|
8419
|
+
capture: true,
|
8420
|
+
passive: false
|
8421
|
+
});
|
8422
|
+
}, [
|
8423
|
+
rootRef,
|
8424
|
+
handleDxAnchorActivate
|
8425
|
+
]);
|
8426
|
+
return /* @__PURE__ */ React5.createElement(Popover.Root, {
|
8427
|
+
modal: false,
|
8428
|
+
open,
|
8429
|
+
onOpenChange: setOpen
|
8430
|
+
}, /* @__PURE__ */ React5.createElement(Popover.Portal, null, /* @__PURE__ */ React5.createElement(Popover.Content, {
|
7208
8431
|
align: "start",
|
7209
8432
|
onOpenAutoFocus: (event) => event.preventDefault(),
|
7210
8433
|
classNames: tx("menu.content", "menu--exotic-unfocusable", {
|
7211
8434
|
elevation: "positioned"
|
7212
8435
|
}, [
|
7213
|
-
"max-
|
8436
|
+
"max-bs-80 overflow-y-auto"
|
7214
8437
|
])
|
7215
8438
|
}, /* @__PURE__ */ React5.createElement(Popover.Viewport, {
|
7216
8439
|
classNames: tx("menu.viewport", "menu__viewport--exotic-unfocusable", {})
|
7217
|
-
}, /* @__PURE__ */ React5.createElement("ul", null, groupsWithItems.map((group, index) => /* @__PURE__ */ React5.createElement(
|
8440
|
+
}, /* @__PURE__ */ React5.createElement("ul", null, groupsWithItems.map((group, index) => /* @__PURE__ */ React5.createElement(Fragment, {
|
7218
8441
|
key: group.id
|
7219
8442
|
}, /* @__PURE__ */ React5.createElement(CommandGroup, {
|
7220
8443
|
group,
|
@@ -7222,7 +8445,13 @@ var CommandMenu = ({ groups, currentItem, onSelect }) => {
|
|
7222
8445
|
onSelect
|
7223
8446
|
}), index < groupsWithItems.length - 1 && /* @__PURE__ */ React5.createElement("div", {
|
7224
8447
|
className: tx("menu.separator", "menu__item", {})
|
7225
|
-
})))))))
|
8448
|
+
}))))), /* @__PURE__ */ React5.createElement(Popover.Arrow, null))), /* @__PURE__ */ React5.createElement(Popover.VirtualTrigger, {
|
8449
|
+
virtualRef: trigger
|
8450
|
+
}), /* @__PURE__ */ React5.createElement("div", {
|
8451
|
+
role: "none",
|
8452
|
+
className: "contents",
|
8453
|
+
ref: setRootRef
|
8454
|
+
}, children));
|
7226
8455
|
} finally {
|
7227
8456
|
_effect.f();
|
7228
8457
|
}
|
@@ -7459,179 +8688,21 @@ var linkSlashCommands = {
|
|
7459
8688
|
}
|
7460
8689
|
]
|
7461
8690
|
};
|
7462
|
-
|
7463
|
-
// src/components/Popover/RefPopover.tsx
|
7464
|
-
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
7465
|
-
import { createContext } from "@radix-ui/react-context";
|
7466
|
-
import React6, { useRef as useRef4, useState as useState3, useEffect as useEffect4, useCallback as useCallback5, forwardRef as forwardRef2 } from "react";
|
7467
|
-
import { addEventListener as addEventListener2 } from "@dxos/async";
|
7468
|
-
import { Popover as Popover2 } from "@dxos/react-ui";
|
7469
|
-
var customEventOptions = {
|
7470
|
-
capture: true,
|
7471
|
-
passive: false
|
7472
|
-
};
|
7473
|
-
var RefPopover = /* @__PURE__ */ forwardRef2(({ children, open, onOpenChange, modal, onActivate }, ref) => {
|
7474
|
-
var _effect = _useSignals4();
|
7475
|
-
try {
|
7476
|
-
const [rootRef, setRootRef] = useState3(null);
|
7477
|
-
useEffect4(() => {
|
7478
|
-
if (!rootRef || !onActivate) {
|
7479
|
-
return;
|
7480
|
-
}
|
7481
|
-
return addEventListener2(rootRef, "dx-ref-tag-activate", onActivate, customEventOptions);
|
7482
|
-
}, [
|
7483
|
-
rootRef,
|
7484
|
-
onActivate
|
7485
|
-
]);
|
7486
|
-
return /* @__PURE__ */ React6.createElement(Popover2.Root, {
|
7487
|
-
open,
|
7488
|
-
onOpenChange,
|
7489
|
-
modal
|
7490
|
-
}, /* @__PURE__ */ React6.createElement(Popover2.VirtualTrigger, {
|
7491
|
-
virtualRef: ref
|
7492
|
-
}), /* @__PURE__ */ React6.createElement("div", {
|
7493
|
-
role: "none",
|
7494
|
-
className: "contents",
|
7495
|
-
ref: setRootRef
|
7496
|
-
}, children));
|
7497
|
-
} finally {
|
7498
|
-
_effect.f();
|
7499
|
-
}
|
7500
|
-
});
|
7501
|
-
var REF_POPOVER = "RefPopover";
|
7502
|
-
var [RefPopoverContextProvider, useRefPopover] = createContext(REF_POPOVER, {});
|
7503
|
-
var PreviewProvider = ({ children, onLookup }) => {
|
7504
|
-
var _effect = _useSignals4();
|
7505
|
-
try {
|
7506
|
-
const trigger = useRef4(null);
|
7507
|
-
const [value, setValue] = useState3({});
|
7508
|
-
const [open, setOpen] = useState3(false);
|
7509
|
-
const handleDxRefTagActivate = useCallback5((event) => {
|
7510
|
-
const { refId, label, trigger: dxTrigger } = event;
|
7511
|
-
setValue((value2) => ({
|
7512
|
-
...value2,
|
7513
|
-
link: {
|
7514
|
-
label,
|
7515
|
-
ref: refId
|
7516
|
-
},
|
7517
|
-
pending: true
|
7518
|
-
}));
|
7519
|
-
trigger.current = dxTrigger;
|
7520
|
-
queueMicrotask(() => setOpen(true));
|
7521
|
-
void onLookup?.({
|
7522
|
-
label,
|
7523
|
-
ref: refId
|
7524
|
-
}).then((target) => setValue((value2) => ({
|
7525
|
-
...value2,
|
7526
|
-
target: target ?? void 0,
|
7527
|
-
pending: false
|
7528
|
-
})));
|
7529
|
-
}, [
|
7530
|
-
onLookup
|
7531
|
-
]);
|
7532
|
-
return /* @__PURE__ */ React6.createElement(RefPopoverContextProvider, {
|
7533
|
-
pending: value.pending,
|
7534
|
-
link: value.link,
|
7535
|
-
target: value.target
|
7536
|
-
}, /* @__PURE__ */ React6.createElement(RefPopover, {
|
7537
|
-
ref: trigger,
|
7538
|
-
open,
|
7539
|
-
onOpenChange: setOpen,
|
7540
|
-
onActivate: handleDxRefTagActivate
|
7541
|
-
}, children));
|
7542
|
-
} finally {
|
7543
|
-
_effect.f();
|
7544
|
-
}
|
7545
|
-
};
|
7546
|
-
|
7547
|
-
// src/components/Popover/RefDropdownMenu.tsx
|
7548
|
-
import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
|
7549
|
-
import { createContext as createContext2 } from "@radix-ui/react-context";
|
7550
|
-
import React7, { useRef as useRef5, useState as useState4, useEffect as useEffect5, useCallback as useCallback6 } from "react";
|
7551
|
-
import { addEventListener as addEventListener3 } from "@dxos/async";
|
7552
|
-
import { DropdownMenu } from "@dxos/react-ui";
|
7553
|
-
var customEventOptions2 = {
|
7554
|
-
capture: true,
|
7555
|
-
passive: false
|
7556
|
-
};
|
7557
|
-
var REF_DROPDOWN_MENU = "RefDropdownMenu";
|
7558
|
-
var [RefDropdownMenuContextProvider, useRefDropdownMenu] = createContext2(REF_DROPDOWN_MENU, {});
|
7559
|
-
var RefDropdownMenuProvider = ({ children, onLookup }) => {
|
7560
|
-
var _effect = _useSignals5();
|
7561
|
-
try {
|
7562
|
-
const trigger = useRef5(null);
|
7563
|
-
const [value, setValue] = useState4({});
|
7564
|
-
const [rootRef, setRootRef] = useState4(null);
|
7565
|
-
const [open, setOpen] = useState4(false);
|
7566
|
-
const handleDxRefTagActivate = useCallback6((event) => {
|
7567
|
-
const { refId, label, trigger: dxTrigger } = event;
|
7568
|
-
setValue((value2) => ({
|
7569
|
-
...value2,
|
7570
|
-
link: {
|
7571
|
-
label,
|
7572
|
-
ref: refId
|
7573
|
-
},
|
7574
|
-
pending: true
|
7575
|
-
}));
|
7576
|
-
trigger.current = dxTrigger;
|
7577
|
-
queueMicrotask(() => setOpen(true));
|
7578
|
-
void onLookup?.({
|
7579
|
-
label,
|
7580
|
-
ref: refId
|
7581
|
-
}).then((target) => setValue((value2) => ({
|
7582
|
-
...value2,
|
7583
|
-
target: target ?? void 0,
|
7584
|
-
pending: false
|
7585
|
-
})));
|
7586
|
-
}, [
|
7587
|
-
onLookup
|
7588
|
-
]);
|
7589
|
-
useEffect5(() => {
|
7590
|
-
if (!rootRef) {
|
7591
|
-
return;
|
7592
|
-
}
|
7593
|
-
return addEventListener3(rootRef, "dx-ref-tag-activate", handleDxRefTagActivate, customEventOptions2);
|
7594
|
-
}, [
|
7595
|
-
rootRef
|
7596
|
-
]);
|
7597
|
-
return /* @__PURE__ */ React7.createElement(RefDropdownMenuContextProvider, {
|
7598
|
-
pending: value.pending,
|
7599
|
-
link: value.link,
|
7600
|
-
target: value.target
|
7601
|
-
}, /* @__PURE__ */ React7.createElement(DropdownMenu.Root, {
|
7602
|
-
open,
|
7603
|
-
onOpenChange: setOpen
|
7604
|
-
}, /* @__PURE__ */ React7.createElement(DropdownMenu.VirtualTrigger, {
|
7605
|
-
virtualRef: trigger
|
7606
|
-
}), /* @__PURE__ */ React7.createElement("div", {
|
7607
|
-
role: "none",
|
7608
|
-
className: "contents",
|
7609
|
-
ref: setRootRef
|
7610
|
-
}, children)));
|
7611
|
-
} finally {
|
7612
|
-
_effect.f();
|
7613
|
-
}
|
7614
|
-
};
|
7615
|
-
var RefDropdownMenu = {
|
7616
|
-
Provider: RefDropdownMenuProvider
|
7617
|
-
};
|
7618
8691
|
export {
|
7619
|
-
|
8692
|
+
CommandMenuProvider,
|
7620
8693
|
Cursor,
|
8694
|
+
Domino,
|
7621
8695
|
Editor,
|
7622
8696
|
EditorInputMode,
|
7623
8697
|
EditorInputModes,
|
7624
8698
|
EditorState4 as EditorState,
|
7625
8699
|
EditorToolbar,
|
7626
|
-
|
8700
|
+
EditorView31 as EditorView,
|
7627
8701
|
EditorViewMode,
|
7628
8702
|
EditorViewModes,
|
7629
8703
|
Inline,
|
7630
8704
|
InputModeExtensions,
|
7631
8705
|
List,
|
7632
|
-
PreviewProvider,
|
7633
|
-
RefDropdownMenu,
|
7634
|
-
RefPopover,
|
7635
8706
|
RemoteSelectionsDecorator,
|
7636
8707
|
SpaceAwarenessProvider,
|
7637
8708
|
TextKind,
|
@@ -7642,6 +8713,7 @@ export {
|
|
7642
8713
|
addList,
|
7643
8714
|
addStyle,
|
7644
8715
|
annotations,
|
8716
|
+
autoScroll,
|
7645
8717
|
autocomplete,
|
7646
8718
|
automerge,
|
7647
8719
|
awareness,
|
@@ -7668,7 +8740,6 @@ export {
|
|
7668
8740
|
createEditorActionGroup,
|
7669
8741
|
createEditorStateStore,
|
7670
8742
|
createEditorStateTransaction,
|
7671
|
-
createElement,
|
7672
8743
|
createExternalCommentSync,
|
7673
8744
|
createJsonExtensions,
|
7674
8745
|
createMarkdownExtensions,
|
@@ -7678,6 +8749,8 @@ export {
|
|
7678
8749
|
debugNodeLogger,
|
7679
8750
|
debugTree,
|
7680
8751
|
decorateMarkdown,
|
8752
|
+
decorationSetToArray,
|
8753
|
+
defaultExtensions,
|
7681
8754
|
defaultOptions,
|
7682
8755
|
defaultThemeSlots,
|
7683
8756
|
deleteItem,
|
@@ -7689,6 +8762,7 @@ export {
|
|
7689
8762
|
editorSlots,
|
7690
8763
|
editorWidth,
|
7691
8764
|
editorWithToolbarLayout,
|
8765
|
+
extendedMarkdown,
|
7692
8766
|
filterItems,
|
7693
8767
|
flattenRect,
|
7694
8768
|
floatingMenu,
|
@@ -7742,6 +8816,7 @@ export {
|
|
7742
8816
|
removeStyle,
|
7743
8817
|
renderRoot,
|
7744
8818
|
scrollThreadIntoView,
|
8819
|
+
scrollToBottomEffect,
|
7745
8820
|
selectionState,
|
7746
8821
|
setBlockquote,
|
7747
8822
|
setComments,
|
@@ -7751,6 +8826,7 @@ export {
|
|
7751
8826
|
singleValueFacet,
|
7752
8827
|
stackItemContentEditorClassNames,
|
7753
8828
|
staticCompletion,
|
8829
|
+
streamer,
|
7754
8830
|
table,
|
7755
8831
|
tags2 as tags,
|
7756
8832
|
textRange,
|
@@ -7772,9 +8848,11 @@ export {
|
|
7772
8848
|
useComments,
|
7773
8849
|
useEditorToolbarState,
|
7774
8850
|
useFormattingState,
|
7775
|
-
useRefDropdownMenu,
|
7776
|
-
useRefPopover,
|
7777
8851
|
useTextEditor,
|
7778
|
-
wrapWithCatch
|
8852
|
+
wrapWithCatch,
|
8853
|
+
xmlTagContextEffect,
|
8854
|
+
xmlTagResetEffect,
|
8855
|
+
xmlTagUpdateEffect,
|
8856
|
+
xmlTags
|
7779
8857
|
};
|
7780
8858
|
//# sourceMappingURL=index.mjs.map
|