@dxos/react-ui-editor 0.4.8-main.6304ea3 → 0.4.8-main.67b703c

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,59 @@ 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
+ lineWrapping: true,
2220
+ search: true
2202
2221
  };
2203
2222
  var createBasicExtensions = (_props) => {
2204
2223
  const props = defaultsDeep2({}, _props, defaults);
@@ -2207,7 +2226,7 @@ var createBasicExtensions = (_props) => {
2207
2226
  EditorView10.exceptionSink.of((err) => {
2208
2227
  log7.catch(err, void 0, {
2209
2228
  F: __dxlog_file9,
2210
- L: 78,
2229
+ L: 83,
2211
2230
  S: void 0,
2212
2231
  C: (f, a) => f(...a)
2213
2232
  });
@@ -2219,6 +2238,7 @@ var createBasicExtensions = (_props) => {
2219
2238
  props.dropCursor && dropCursor(),
2220
2239
  props.drawSelection && drawSelection(),
2221
2240
  props.highlightActiveLine && highlightActiveLine(),
2241
+ highlightSpecialChars(),
2222
2242
  props.history && history(),
2223
2243
  props.lineNumbers && lineNumbers(),
2224
2244
  props.lineWrapping && EditorView10.lineWrapping,
@@ -2228,7 +2248,20 @@ var createBasicExtensions = (_props) => {
2228
2248
  EditorView10.editable.of(false)
2229
2249
  ],
2230
2250
  props.scrollPastEnd && scrollPastEnd(),
2231
- props.tabSize && EditorState.tabSize.of(props.tabSize)
2251
+ props.tabSize && EditorState.tabSize.of(props.tabSize),
2252
+ // https://codemirror.net/docs/ref/#view.KeyBinding
2253
+ keymap5.of([
2254
+ // https://codemirror.net/docs/ref/#commands.standardKeymap
2255
+ ...standardKeymap,
2256
+ // https://codemirror.net/docs/ref/#commands.indentWithTab
2257
+ props.indentWithTab && indentWithTab,
2258
+ // https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
2259
+ ...props.closeBrackets ? closeBracketsKeymap : [],
2260
+ // https://codemirror.net/docs/ref/#commands.historyKeymap
2261
+ ...props.history ? historyKeymap : [],
2262
+ // https://codemirror.net/docs/ref/#search.searchKeymap
2263
+ ...props.search ? searchKeymap : []
2264
+ ].filter(isNotFalsy2))
2232
2265
  ].filter(isNotFalsy2);
2233
2266
  };
2234
2267
  var defaultSlots = {
@@ -2287,14 +2320,14 @@ var listener = ({ onFocus, onChange }) => {
2287
2320
  };
2288
2321
 
2289
2322
  // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
2290
- import { closeBracketsKeymap } from "@codemirror/autocomplete";
2291
- import { historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
2323
+ import { completionKeymap as completionKeymap2 } from "@codemirror/autocomplete";
2324
+ import { defaultKeymap, indentWithTab as indentWithTab2 } from "@codemirror/commands";
2292
2325
  import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
2293
2326
  import { defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
2294
2327
  import { languages } from "@codemirror/language-data";
2295
- import { searchKeymap } from "@codemirror/search";
2328
+ import { lintKeymap } from "@codemirror/lint";
2296
2329
  import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
2297
- import { keymap as keymap5 } from "@codemirror/view";
2330
+ import { keymap as keymap6 } from "@codemirror/view";
2298
2331
 
2299
2332
  // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
2300
2333
  import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
@@ -2509,17 +2542,13 @@ var createMarkdownExtensions = ({ themeMode } = {}) => {
2509
2542
  themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
2510
2543
  // Custom styles.
2511
2544
  syntaxHighlighting(markdownHighlightStyle()),
2512
- keymap5.of([
2545
+ keymap6.of([
2513
2546
  // 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
2547
+ indentWithTab2,
2548
+ // https://codemirror.net/docs/ref/#commands.defaultKeymap
2549
+ ...defaultKeymap,
2550
+ ...completionKeymap2,
2551
+ ...lintKeymap
2523
2552
  ])
2524
2553
  ];
2525
2554
  };
@@ -2796,9 +2825,8 @@ var formattingStyles = EditorView12.baseTheme({
2796
2825
  import { snippet } from "@codemirror/autocomplete";
2797
2826
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
2798
2827
  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";
2828
+ import { EditorView as EditorView13, keymap as keymap7 } from "@codemirror/view";
2829
+ import { useMemo, useState } from "react";
2802
2830
  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
2831
  var Inline;
2804
2832
  (function(Inline2) {
@@ -3669,7 +3697,7 @@ var toggleCodeblock = (target) => {
3669
3697
  };
3670
3698
  var formattingKeymap = (options = {}) => {
3671
3699
  return [
3672
- keymap6.of([
3700
+ keymap7.of([
3673
3701
  {
3674
3702
  key: "meta-b",
3675
3703
  run: toggleStrong
@@ -3866,15 +3894,20 @@ var getFormatting = (state2) => {
3866
3894
  };
3867
3895
  };
3868
3896
  var useFormattingState = () => {
3869
- const [state2, setState, stateRef] = useStateRef();
3897
+ const [state2, setState] = useState();
3870
3898
  const observer = useMemo(() => EditorView13.updateListener.of((update2) => {
3871
3899
  if (update2.docChanged || update2.selectionSet) {
3872
- const newState = getFormatting(update2.state);
3873
- if (!stateRef.current || !formattingEquals(stateRef.current, newState)) {
3874
- setState(newState);
3875
- }
3900
+ setState((prevState) => {
3901
+ const newState = getFormatting(update2.state);
3902
+ if (!prevState || !formattingEquals(prevState, newState)) {
3903
+ return newState;
3904
+ }
3905
+ return prevState;
3906
+ });
3876
3907
  }
3877
- }), []);
3908
+ }), [
3909
+ setState
3910
+ ]);
3878
3911
  return [
3879
3912
  state2,
3880
3913
  observer
@@ -4138,21 +4171,30 @@ var mention = ({ onSearch }) => {
4138
4171
 
4139
4172
  // packages/ui/react-ui-editor/src/extensions/modes.ts
4140
4173
  import { Facet as Facet6 } from "@codemirror/state";
4141
- import { keymap as keymap7 } from "@codemirror/view";
4174
+ import { keymap as keymap8 } from "@codemirror/view";
4142
4175
  import { vim } from "@replit/codemirror-vim";
4176
+ import { vscodeKeymap } from "@replit/codemirror-vscode-keymap";
4143
4177
  var focusEvent = "focus.container";
4144
4178
  var editorMode = Facet6.define({
4145
4179
  combine: (modes) => modes[0] ?? {}
4146
4180
  });
4147
4181
  var EditorModes = {
4148
4182
  default: [],
4183
+ vscode: [
4184
+ // https://github.com/replit/codemirror-vscode-keymap
4185
+ editorMode.of({
4186
+ type: "vscode"
4187
+ }),
4188
+ keymap8.of(vscodeKeymap)
4189
+ ],
4149
4190
  vim: [
4191
+ // https://github.com/replit/codemirror-vim
4150
4192
  vim(),
4151
4193
  editorMode.of({
4152
4194
  type: "vim",
4153
4195
  noTabster: true
4154
4196
  }),
4155
- keymap7.of([
4197
+ keymap8.of([
4156
4198
  {
4157
4199
  key: "Alt-Escape",
4158
4200
  run: (view) => {
@@ -4168,7 +4210,7 @@ var EditorModes = {
4168
4210
 
4169
4211
  // packages/ui/react-ui-editor/src/extensions/state.ts
4170
4212
  import { Transaction as Transaction2 } from "@codemirror/state";
4171
- import { EditorView as EditorView16, keymap as keymap8 } from "@codemirror/view";
4213
+ import { EditorView as EditorView16, keymap as keymap9 } from "@codemirror/view";
4172
4214
  import { debounce as debounce2 } from "@dxos/async";
4173
4215
  import { invariant as invariant4 } from "@dxos/invariant";
4174
4216
  import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
@@ -4232,7 +4274,7 @@ var state = ({ getState, setState } = {}) => {
4232
4274
  }
4233
4275
  }
4234
4276
  }),
4235
- getState && keymap8.of([
4277
+ getState && keymap9.of([
4236
4278
  {
4237
4279
  key: "ctrl-r",
4238
4280
  run: (view) => {
@@ -4254,7 +4296,7 @@ var state = ({ getState, setState } = {}) => {
4254
4296
  };
4255
4297
 
4256
4298
  // packages/ui/react-ui-editor/src/extensions/typewriter.ts
4257
- import { keymap as keymap9 } from "@codemirror/view";
4299
+ import { keymap as keymap10 } from "@codemirror/view";
4258
4300
  var defaultItems = [
4259
4301
  "hello world!",
4260
4302
  "this is a test.",
@@ -4264,7 +4306,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
4264
4306
  let t;
4265
4307
  let idx = 0;
4266
4308
  return [
4267
- keymap9.of([
4309
+ keymap10.of([
4268
4310
  {
4269
4311
  // Reset.
4270
4312
  key: "alt-meta-'",
@@ -4316,12 +4358,12 @@ var instanceCount = 0;
4316
4358
  var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, className, autoFocus, scrollTo = EditorView17.scrollIntoView(0, {
4317
4359
  yMargin: 0
4318
4360
  }), moveToEndOfLine, debug, dataTestId }, forwardedRef) => {
4319
- const [instanceId] = useState(() => `text-editor-${++instanceCount}`);
4361
+ const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4320
4362
  const tabsterDOMAttribute = useFocusableGroup({
4321
4363
  tabBehavior: "limited"
4322
4364
  });
4323
4365
  const rootRef = useRef(null);
4324
- const [view, setView] = useState(null);
4366
+ const [view, setView] = useState2(null);
4325
4367
  useImperativeHandle(forwardedRef, () => view, [
4326
4368
  view
4327
4369
  ]);
@@ -4435,7 +4477,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4435
4477
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
4436
4478
  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
4479
  import { createContext } from "@radix-ui/react-context";
4438
- import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
4480
+ import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
4439
4481
  import { useDropzone } from "react-dropzone";
4440
4482
  import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, Tooltip, useTranslation } from "@dxos/react-ui";
4441
4483
  import { getSize } from "@dxos/react-ui-theme";
@@ -4508,8 +4550,8 @@ var MarkdownHeading = () => {
4508
4550
  const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : void 0;
4509
4551
  const HeadingIcon = HeadingIcons[value ?? "0"];
4510
4552
  const suppressNextTooltip = useRef2(false);
4511
- const [tooltipOpen, setTooltipOpen] = useState2(false);
4512
- const [selectOpen, setSelectOpen] = useState2(false);
4553
+ const [tooltipOpen, setTooltipOpen] = useState3(false);
4554
+ const [selectOpen, setSelectOpen] = useState3(false);
4513
4555
  return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
4514
4556
  open: tooltipOpen,
4515
4557
  onOpenChange: (nextOpen) => {
@@ -4821,14 +4863,14 @@ var useDocAccessor = (text) => {
4821
4863
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4822
4864
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4823
4865
  import { EditorView as EditorView18 } from "@codemirror/view";
4824
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
4866
+ import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4825
4867
  import { log as log10 } from "@dxos/log";
4826
4868
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4827
4869
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4828
4870
  var useTextEditor = (cb = () => ({}), deps = []) => {
4829
4871
  let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4830
4872
  const onUpdate = useRef3();
4831
- const [view, setView] = useState3();
4873
+ const [view, setView] = useState4();
4832
4874
  const parentRef = useRef3(null);
4833
4875
  useEffect4(() => {
4834
4876
  let view2;
@@ -4971,7 +5013,7 @@ export {
4971
5013
  image,
4972
5014
  imageUpload,
4973
5015
  insertTable,
4974
- keymap10 as keymap,
5016
+ keymap11 as keymap,
4975
5017
  linkTooltip,
4976
5018
  listener,
4977
5019
  localStorageStateStoreAdapter,