@dxos/react-ui-editor 0.4.8-main.aa7abac → 0.4.8-main.aafbaef

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.
@@ -24,7 +24,7 @@ var translations_default = [
24
24
  ];
25
25
 
26
26
  // packages/ui/react-ui-editor/src/index.ts
27
- import { keymap as keymap10 } from "@codemirror/view";
27
+ import { keymap as keymap11 } from "@codemirror/view";
28
28
  import { tags as tags2 } from "@lezer/highlight";
29
29
  import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
30
30
  import { Doc, YText, YXmlFragment } from "@dxos/text-model";
@@ -33,7 +33,7 @@ import { Doc, YText, YXmlFragment } from "@dxos/text-model";
33
33
  import { EditorState as EditorState2 } from "@codemirror/state";
34
34
  import { EditorView as EditorView17 } from "@codemirror/view";
35
35
  import { useFocusableGroup } from "@fluentui/react-tabster";
36
- import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState } from "react";
36
+ import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
37
37
  import { log as log9 } from "@dxos/log";
38
38
  import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
39
39
 
@@ -475,13 +475,13 @@ var automerge = (accessor) => {
475
475
  ViewPlugin.fromClass(class {
476
476
  constructor(_view) {
477
477
  this._view = _view;
478
- accessor.handle.addListener("change", this._handleChange.bind(this));
478
+ this._handleChange = () => {
479
+ syncer.reconcile(this._view, false);
480
+ };
481
+ accessor.handle.addListener("change", this._handleChange);
479
482
  }
480
483
  destroy() {
481
- accessor.handle.removeListener("change", this._handleChange.bind(this));
482
- }
483
- _handleChange() {
484
- syncer.reconcile(this._view, false);
484
+ accessor.handle.removeListener("change", this._handleChange);
485
485
  }
486
486
  }),
487
487
  // Reconcile local updates.
@@ -1952,11 +1952,12 @@ var dnd = () => {
1952
1952
  };
1953
1953
 
1954
1954
  // packages/ui/react-ui-editor/src/extensions/factories.ts
1955
- import { closeBrackets } from "@codemirror/autocomplete";
1956
- import { history } from "@codemirror/commands";
1955
+ import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
1956
+ import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
1957
1957
  import { bracketMatching } from "@codemirror/language";
1958
+ import { searchKeymap } from "@codemirror/search";
1958
1959
  import { EditorState } from "@codemirror/state";
1959
- import { EditorView as EditorView10, crosshairCursor, drawSelection, dropCursor, highlightActiveLine, lineNumbers, placeholder, scrollPastEnd } from "@codemirror/view";
1960
+ import { EditorView as EditorView10, crosshairCursor, drawSelection, dropCursor, highlightActiveLine, highlightSpecialChars, keymap as keymap5, lineNumbers, placeholder, scrollPastEnd } from "@codemirror/view";
1960
1961
  import defaultsDeep2 from "lodash.defaultsdeep";
1961
1962
  import { generateName } from "@dxos/display-name";
1962
1963
  import { log as log7 } from "@dxos/log";
@@ -2164,41 +2165,60 @@ var defaultTheme = {
2164
2165
  * </div>
2165
2166
  * </div
2166
2167
  */
2167
- ".cm-panels": {
2168
- border: `1px solid ${get3(tokens, "extend.colors.neutral.200")}`
2169
- },
2168
+ ".cm-panels": {},
2170
2169
  ".cm-panel": {
2171
- background: get3(tokens, "extend.colors.neutral.50"),
2172
2170
  fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2173
2171
  },
2172
+ ".cm-panel input[type=checkbox]": {
2173
+ marginRight: "0.4rem !important"
2174
+ },
2175
+ "&light .cm-panel": {
2176
+ background: get3(tokens, "extend.colors.neutral.50")
2177
+ },
2178
+ "&dark .cm-panel": {
2179
+ background: get3(tokens, "extend.colors.neutral.850")
2180
+ },
2174
2181
  ".cm-button": {
2175
2182
  margin: "4px",
2176
2183
  fontFamily: get3(tokens, "fontFamily.body", []).join(","),
2177
- background: get3(tokens, "extend.colors.neutral.100"),
2178
2184
  backgroundImage: "none",
2179
2185
  border: "none",
2186
+ "&:active": {
2187
+ backgroundImage: "none"
2188
+ }
2189
+ },
2190
+ "&light .cm-button": {
2191
+ background: get3(tokens, "extend.colors.neutral.100"),
2180
2192
  "&:hover": {
2181
2193
  background: get3(tokens, "extend.colors.neutral.200")
2182
2194
  },
2183
2195
  "&:active": {
2184
- background: get3(tokens, "extend.colors.neutral.300"),
2185
- backgroundImage: "none"
2196
+ background: get3(tokens, "extend.colors.neutral.300")
2186
2197
  }
2187
2198
  },
2188
- ".cm-panel input[type=checkbox]": {
2189
- marginRight: "0.4rem !important"
2199
+ "&dark .cm-button": {
2200
+ background: get3(tokens, "extend.colors.neutral.800"),
2201
+ "&:hover": {
2202
+ background: get3(tokens, "extend.colors.neutral.700")
2203
+ },
2204
+ "&:active": {
2205
+ background: get3(tokens, "extend.colors.neutral.600")
2206
+ }
2190
2207
  }
2191
2208
  };
2192
2209
 
2193
2210
  // packages/ui/react-ui-editor/src/extensions/factories.ts
2194
2211
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
2195
2212
  var defaults = {
2213
+ allowMultipleSelections: true,
2196
2214
  bracketMatching: true,
2197
2215
  closeBrackets: true,
2198
2216
  drawSelection: true,
2199
2217
  editable: true,
2200
2218
  history: true,
2201
- lineWrapping: true
2219
+ standardKeymap: true,
2220
+ lineWrapping: true,
2221
+ search: true
2202
2222
  };
2203
2223
  var createBasicExtensions = (_props) => {
2204
2224
  const props = defaultsDeep2({}, _props, defaults);
@@ -2207,7 +2227,7 @@ var createBasicExtensions = (_props) => {
2207
2227
  EditorView10.exceptionSink.of((err) => {
2208
2228
  log7.catch(err, void 0, {
2209
2229
  F: __dxlog_file9,
2210
- L: 78,
2230
+ L: 85,
2211
2231
  S: void 0,
2212
2232
  C: (f, a) => f(...a)
2213
2233
  });
@@ -2219,6 +2239,7 @@ var createBasicExtensions = (_props) => {
2219
2239
  props.dropCursor && dropCursor(),
2220
2240
  props.drawSelection && drawSelection(),
2221
2241
  props.highlightActiveLine && highlightActiveLine(),
2242
+ highlightSpecialChars(),
2222
2243
  props.history && history(),
2223
2244
  props.lineNumbers && lineNumbers(),
2224
2245
  props.lineWrapping && EditorView10.lineWrapping,
@@ -2228,7 +2249,22 @@ var createBasicExtensions = (_props) => {
2228
2249
  EditorView10.editable.of(false)
2229
2250
  ],
2230
2251
  props.scrollPastEnd && scrollPastEnd(),
2231
- props.tabSize && EditorState.tabSize.of(props.tabSize)
2252
+ props.tabSize && EditorState.tabSize.of(props.tabSize),
2253
+ // https://codemirror.net/docs/ref/#view.KeyBinding
2254
+ keymap5.of([
2255
+ // https://codemirror.net/docs/ref/#commands.standardKeymap
2256
+ ...props.standardKeymap ? standardKeymap : [],
2257
+ // https://codemirror.net/docs/ref/#commands.indentWithTab
2258
+ ...props.indentWithTab ? [
2259
+ indentWithTab
2260
+ ] : [],
2261
+ // https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
2262
+ ...props.closeBrackets ? closeBracketsKeymap : [],
2263
+ // https://codemirror.net/docs/ref/#commands.historyKeymap
2264
+ ...props.history ? historyKeymap : [],
2265
+ // https://codemirror.net/docs/ref/#search.searchKeymap
2266
+ ...props.search ? searchKeymap : []
2267
+ ].filter(isNotFalsy2))
2232
2268
  ].filter(isNotFalsy2);
2233
2269
  };
2234
2270
  var defaultSlots = {
@@ -2287,14 +2323,14 @@ var listener = ({ onFocus, onChange }) => {
2287
2323
  };
2288
2324
 
2289
2325
  // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
2290
- import { closeBracketsKeymap } from "@codemirror/autocomplete";
2291
- import { historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
2326
+ import { completionKeymap as completionKeymap2 } from "@codemirror/autocomplete";
2327
+ import { defaultKeymap, indentWithTab as indentWithTab2 } from "@codemirror/commands";
2292
2328
  import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
2293
2329
  import { defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
2294
2330
  import { languages } from "@codemirror/language-data";
2295
- import { searchKeymap } from "@codemirror/search";
2331
+ import { lintKeymap } from "@codemirror/lint";
2296
2332
  import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
2297
- import { keymap as keymap5 } from "@codemirror/view";
2333
+ import { keymap as keymap6 } from "@codemirror/view";
2298
2334
 
2299
2335
  // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
2300
2336
  import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
@@ -2509,17 +2545,13 @@ var createMarkdownExtensions = ({ themeMode } = {}) => {
2509
2545
  themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
2510
2546
  // Custom styles.
2511
2547
  syntaxHighlighting(markdownHighlightStyle()),
2512
- keymap5.of([
2548
+ keymap6.of([
2513
2549
  // https://codemirror.net/docs/ref/#commands.indentWithTab
2514
- indentWithTab,
2515
- // https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
2516
- ...closeBracketsKeymap,
2517
- // https://codemirror.net/docs/ref/#commands.historyKeymap
2518
- ...historyKeymap,
2519
- // https://codemirror.net/docs/ref/#search.searchKeymap
2520
- ...searchKeymap,
2521
- // https://codemirror.net/docs/ref/#commands.standardKeymap
2522
- ...standardKeymap
2550
+ indentWithTab2,
2551
+ // https://codemirror.net/docs/ref/#commands.defaultKeymap
2552
+ ...defaultKeymap,
2553
+ ...completionKeymap2,
2554
+ ...lintKeymap
2523
2555
  ])
2524
2556
  ];
2525
2557
  };
@@ -2796,9 +2828,8 @@ var formattingStyles = EditorView12.baseTheme({
2796
2828
  import { snippet } from "@codemirror/autocomplete";
2797
2829
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
2798
2830
  import { EditorSelection } from "@codemirror/state";
2799
- import { EditorView as EditorView13, keymap as keymap6 } from "@codemirror/view";
2800
- import { useMemo } from "react";
2801
- import { useStateRef } from "@dxos/react-async";
2831
+ import { EditorView as EditorView13, keymap as keymap7 } from "@codemirror/view";
2832
+ import { useMemo, useState } from "react";
2802
2833
  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;
2803
2834
  var Inline;
2804
2835
  (function(Inline2) {
@@ -3669,7 +3700,7 @@ var toggleCodeblock = (target) => {
3669
3700
  };
3670
3701
  var formattingKeymap = (options = {}) => {
3671
3702
  return [
3672
- keymap6.of([
3703
+ keymap7.of([
3673
3704
  {
3674
3705
  key: "meta-b",
3675
3706
  run: toggleStrong
@@ -3866,15 +3897,20 @@ var getFormatting = (state2) => {
3866
3897
  };
3867
3898
  };
3868
3899
  var useFormattingState = () => {
3869
- const [state2, setState, stateRef] = useStateRef();
3900
+ const [state2, setState] = useState();
3870
3901
  const observer = useMemo(() => EditorView13.updateListener.of((update2) => {
3871
3902
  if (update2.docChanged || update2.selectionSet) {
3872
- const newState = getFormatting(update2.state);
3873
- if (!stateRef.current || !formattingEquals(stateRef.current, newState)) {
3874
- setState(newState);
3875
- }
3903
+ setState((prevState) => {
3904
+ const newState = getFormatting(update2.state);
3905
+ if (!prevState || !formattingEquals(prevState, newState)) {
3906
+ return newState;
3907
+ }
3908
+ return prevState;
3909
+ });
3876
3910
  }
3877
- }), []);
3911
+ }), [
3912
+ setState
3913
+ ]);
3878
3914
  return [
3879
3915
  state2,
3880
3916
  observer
@@ -4138,21 +4174,30 @@ var mention = ({ onSearch }) => {
4138
4174
 
4139
4175
  // packages/ui/react-ui-editor/src/extensions/modes.ts
4140
4176
  import { Facet as Facet6 } from "@codemirror/state";
4141
- import { keymap as keymap7 } from "@codemirror/view";
4177
+ import { keymap as keymap8 } from "@codemirror/view";
4142
4178
  import { vim } from "@replit/codemirror-vim";
4179
+ import { vscodeKeymap } from "@replit/codemirror-vscode-keymap";
4143
4180
  var focusEvent = "focus.container";
4144
4181
  var editorMode = Facet6.define({
4145
4182
  combine: (modes) => modes[0] ?? {}
4146
4183
  });
4147
4184
  var EditorModes = {
4148
4185
  default: [],
4186
+ vscode: [
4187
+ // https://github.com/replit/codemirror-vscode-keymap
4188
+ editorMode.of({
4189
+ type: "vscode"
4190
+ }),
4191
+ keymap8.of(vscodeKeymap)
4192
+ ],
4149
4193
  vim: [
4194
+ // https://github.com/replit/codemirror-vim
4150
4195
  vim(),
4151
4196
  editorMode.of({
4152
4197
  type: "vim",
4153
4198
  noTabster: true
4154
4199
  }),
4155
- keymap7.of([
4200
+ keymap8.of([
4156
4201
  {
4157
4202
  key: "Alt-Escape",
4158
4203
  run: (view) => {
@@ -4168,7 +4213,7 @@ var EditorModes = {
4168
4213
 
4169
4214
  // packages/ui/react-ui-editor/src/extensions/state.ts
4170
4215
  import { Transaction as Transaction2 } from "@codemirror/state";
4171
- import { EditorView as EditorView16, keymap as keymap8 } from "@codemirror/view";
4216
+ import { EditorView as EditorView16, keymap as keymap9 } from "@codemirror/view";
4172
4217
  import { debounce as debounce2 } from "@dxos/async";
4173
4218
  import { invariant as invariant4 } from "@dxos/invariant";
4174
4219
  import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
@@ -4232,7 +4277,7 @@ var state = ({ getState, setState } = {}) => {
4232
4277
  }
4233
4278
  }
4234
4279
  }),
4235
- getState && keymap8.of([
4280
+ getState && keymap9.of([
4236
4281
  {
4237
4282
  key: "ctrl-r",
4238
4283
  run: (view) => {
@@ -4254,7 +4299,7 @@ var state = ({ getState, setState } = {}) => {
4254
4299
  };
4255
4300
 
4256
4301
  // packages/ui/react-ui-editor/src/extensions/typewriter.ts
4257
- import { keymap as keymap9 } from "@codemirror/view";
4302
+ import { keymap as keymap10 } from "@codemirror/view";
4258
4303
  var defaultItems = [
4259
4304
  "hello world!",
4260
4305
  "this is a test.",
@@ -4264,7 +4309,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
4264
4309
  let t;
4265
4310
  let idx = 0;
4266
4311
  return [
4267
- keymap9.of([
4312
+ keymap10.of([
4268
4313
  {
4269
4314
  // Reset.
4270
4315
  key: "alt-meta-'",
@@ -4316,12 +4361,12 @@ var instanceCount = 0;
4316
4361
  var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, className, autoFocus, scrollTo = EditorView17.scrollIntoView(0, {
4317
4362
  yMargin: 0
4318
4363
  }), moveToEndOfLine, debug, dataTestId }, forwardedRef) => {
4319
- const [instanceId] = useState(() => `text-editor-${++instanceCount}`);
4364
+ const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4320
4365
  const tabsterDOMAttribute = useFocusableGroup({
4321
4366
  tabBehavior: "limited"
4322
4367
  });
4323
4368
  const rootRef = useRef(null);
4324
- const [view, setView] = useState(null);
4369
+ const [view, setView] = useState2(null);
4325
4370
  useImperativeHandle(forwardedRef, () => view, [
4326
4371
  view
4327
4372
  ]);
@@ -4435,7 +4480,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4435
4480
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
4436
4481
  import { ChatText, Code, CodeBlock, Image, Link, ListBullets, ListChecks, ListNumbers, Paragraph, Quotes, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic } from "@phosphor-icons/react";
4437
4482
  import { createContext } from "@radix-ui/react-context";
4438
- import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
4483
+ import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
4439
4484
  import { useDropzone } from "react-dropzone";
4440
4485
  import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, Tooltip, useTranslation } from "@dxos/react-ui";
4441
4486
  import { getSize } from "@dxos/react-ui-theme";
@@ -4508,8 +4553,8 @@ var MarkdownHeading = () => {
4508
4553
  const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : void 0;
4509
4554
  const HeadingIcon = HeadingIcons[value ?? "0"];
4510
4555
  const suppressNextTooltip = useRef2(false);
4511
- const [tooltipOpen, setTooltipOpen] = useState2(false);
4512
- const [selectOpen, setSelectOpen] = useState2(false);
4556
+ const [tooltipOpen, setTooltipOpen] = useState3(false);
4557
+ const [selectOpen, setSelectOpen] = useState3(false);
4513
4558
  return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
4514
4559
  open: tooltipOpen,
4515
4560
  onOpenChange: (nextOpen) => {
@@ -4736,6 +4781,7 @@ var MarkdownActions = () => {
4736
4781
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ToolbarButton, {
4737
4782
  value: "comment",
4738
4783
  Icon: ChatText,
4784
+ "data-testid": "editor.toolbar.comment",
4739
4785
  onClick: () => onAction?.({
4740
4786
  type: "comment"
4741
4787
  })
@@ -4820,14 +4866,14 @@ var useDocAccessor = (text) => {
4820
4866
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4821
4867
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4822
4868
  import { EditorView as EditorView18 } from "@codemirror/view";
4823
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
4869
+ import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4824
4870
  import { log as log10 } from "@dxos/log";
4825
4871
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4826
4872
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4827
4873
  var useTextEditor = (cb = () => ({}), deps = []) => {
4828
4874
  let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4829
4875
  const onUpdate = useRef3();
4830
- const [view, setView] = useState3();
4876
+ const [view, setView] = useState4();
4831
4877
  const parentRef = useRef3(null);
4832
4878
  useEffect4(() => {
4833
4879
  let view2;
@@ -4970,7 +5016,7 @@ export {
4970
5016
  image,
4971
5017
  imageUpload,
4972
5018
  insertTable,
4973
- keymap10 as keymap,
5019
+ keymap11 as keymap,
4974
5020
  linkTooltip,
4975
5021
  listener,
4976
5022
  localStorageStateStoreAdapter,