@dxos/react-ui-editor 0.4.10-main.c32f430 → 0.4.10-main.ccba876

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.
@@ -37,6 +37,7 @@ import { EditorView as EditorView16 } from "@codemirror/view";
37
37
  import { useFocusableGroup } from "@fluentui/react-tabster";
38
38
  import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
39
39
  import { log as log7 } from "@dxos/log";
40
+ import { useDefaultValue } from "@dxos/react-ui";
40
41
  import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
41
42
 
42
43
  // packages/ui/react-ui-editor/src/extensions/annotations.ts
@@ -180,30 +181,21 @@ var autocomplete = ({ onSearch }) => {
180
181
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
181
182
  import { StateField as StateField2 } from "@codemirror/state";
182
183
  import { EditorView as EditorView2, ViewPlugin } from "@codemirror/view";
183
- import { next as A4 } from "@dxos/automerge/automerge";
184
+ import { next as A3 } from "@dxos/automerge/automerge";
184
185
 
185
186
  // packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
186
- import get from "lodash.get";
187
- import { next as A } from "@dxos/automerge/automerge";
187
+ import { toCursor, fromCursor } from "@dxos/echo-schema";
188
188
  import { log } from "@dxos/log";
189
189
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts";
190
- var cursorConverter = ({ handle, path }) => ({
190
+ var cursorConverter = (accessor) => ({
191
191
  // TODO(burdon): Handle assoc to associate with a previous character.
192
192
  toCursor: (pos) => {
193
- const doc = handle.docSync();
194
- if (!doc) {
195
- return "";
196
- }
197
- const value = get(doc, path);
198
- if (typeof value === "string" && value.length <= pos) {
199
- return "end";
200
- }
201
193
  try {
202
- return A.getCursor(doc, path.slice(), pos);
194
+ return toCursor(accessor, pos);
203
195
  } catch (err) {
204
196
  log.catch(err, void 0, {
205
197
  F: __dxlog_file,
206
- L: 30,
198
+ L: 16,
207
199
  S: void 0,
208
200
  C: (f, a) => f(...a)
209
201
  });
@@ -211,27 +203,12 @@ var cursorConverter = ({ handle, path }) => ({
211
203
  }
212
204
  },
213
205
  fromCursor: (cursor) => {
214
- if (cursor === "") {
215
- return 0;
216
- }
217
- const doc = handle.docSync();
218
- if (!doc) {
219
- return 0;
220
- }
221
- if (cursor === "end") {
222
- const value = get(doc, path);
223
- if (typeof value === "string") {
224
- return value.length;
225
- } else {
226
- return 0;
227
- }
228
- }
229
206
  try {
230
- return A.getCursorPosition(doc, path.slice(), cursor);
207
+ return fromCursor(accessor, cursor);
231
208
  } catch (err) {
232
209
  log.catch(err, void 0, {
233
210
  F: __dxlog_file,
234
- L: 58,
211
+ L: 25,
235
212
  S: void 0,
236
213
  C: (f, a) => f(...a)
237
214
  });
@@ -254,10 +231,10 @@ var isReconcile = (tr) => {
254
231
  };
255
232
 
256
233
  // packages/ui/react-ui-editor/src/extensions/automerge/sync.ts
257
- import { next as A3 } from "@dxos/automerge/automerge";
234
+ import { next as A2 } from "@dxos/automerge/automerge";
258
235
 
259
236
  // packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
260
- import { next as A2 } from "@dxos/automerge/automerge";
237
+ import { next as A } from "@dxos/automerge/automerge";
261
238
  var updateAutomerge = (field, handle, transactions, state2) => {
262
239
  const { lastHeads, path } = state2.field(field);
263
240
  let hasChanges = false;
@@ -281,7 +258,7 @@ var updateAutomerge = (field, handle, transactions, state2) => {
281
258
  });
282
259
  }
283
260
  invertedTransactions.reverse().forEach(({ from, del, insert }) => {
284
- A2.splice(doc, path.slice(), from, del, insert.toString());
261
+ A.splice(doc, path.slice(), from, del, insert.toString());
285
262
  });
286
263
  });
287
264
  return newHeads ?? void 0;
@@ -426,8 +403,8 @@ var Syncer = class {
426
403
  }
427
404
  onAutomergeChange(view) {
428
405
  const oldHeads = getLastHeads(view.state, this._state);
429
- const newHeads = A3.getHeads(this._handle.docSync());
430
- const diff = A3.equals(oldHeads, newHeads) ? [] : A3.diff(this._handle.docSync(), oldHeads, newHeads);
406
+ const newHeads = A2.getHeads(this._handle.docSync());
407
+ const diff = A2.equals(oldHeads, newHeads) ? [] : A2.diff(this._handle.docSync(), oldHeads, newHeads);
431
408
  const selection = view.state.selection;
432
409
  const path = getPath(view.state, this._state);
433
410
  updateCodeMirror(view, selection, path, diff);
@@ -443,7 +420,7 @@ var automerge = (accessor) => {
443
420
  const syncState = StateField2.define({
444
421
  create: () => ({
445
422
  path: accessor.path.slice(),
446
- lastHeads: A4.getHeads(accessor.handle.docSync()),
423
+ lastHeads: A3.getHeads(accessor.handle.docSync()),
447
424
  unreconciledTransactions: []
448
425
  }),
449
426
  update: (value, tr) => {
@@ -1395,10 +1372,10 @@ var inlineUrl = mx(code, "px-1");
1395
1372
  var blockquote = mx("pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30", light);
1396
1373
 
1397
1374
  // packages/ui/react-ui-editor/src/styles/tokens.ts
1398
- import get2 from "lodash.get";
1375
+ import get from "lodash.get";
1399
1376
  import { tailwindConfig } from "@dxos/react-ui-theme";
1400
1377
  var tokens = tailwindConfig({}).theme;
1401
- var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue);
1378
+ var getToken = (path, defaultValue = void 0) => get(tokens, path, defaultValue);
1402
1379
 
1403
1380
  // packages/ui/react-ui-editor/src/styles/layout.ts
1404
1381
  var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
@@ -1922,7 +1899,7 @@ import { hueTokens } from "@dxos/react-ui-theme";
1922
1899
  import { hexToHue, isNotFalsy as isNotFalsy2 } from "@dxos/util";
1923
1900
 
1924
1901
  // packages/ui/react-ui-editor/src/themes/default.ts
1925
- import get3 from "lodash.get";
1902
+ import get2 from "lodash.get";
1926
1903
  var defaultTheme = {
1927
1904
  //
1928
1905
  // Main layout:
@@ -1956,7 +1933,7 @@ var defaultTheme = {
1956
1933
  // TODO(burdon): Reconcile with docs: https://codemirror.net/docs/guide
1957
1934
  // Inside of that is the scroller element. If the editor has its own scrollbar, this one should be styled with overflow: auto. But it doesn't have to—the editor also supports growing to accomodate its content, or growing up to a certain max-height and then scrolling.
1958
1935
  overflowY: "auto",
1959
- fontFamily: get3(tokens, "fontFamily.body", []).join(","),
1936
+ fontFamily: get2(tokens, "fontFamily.body", []).join(","),
1960
1937
  lineHeight: 1.5
1961
1938
  },
1962
1939
  ".cm-content": {
@@ -1966,11 +1943,11 @@ var defaultTheme = {
1966
1943
  fontSize: "16px"
1967
1944
  },
1968
1945
  "&light .cm-content": {
1969
- color: get3(tokens, "extend.semanticColors.base.fg.light", "black"),
1946
+ color: get2(tokens, "extend.semanticColors.base.fg.light", "black"),
1970
1947
  caretColor: "black"
1971
1948
  },
1972
1949
  "&dark .cm-content": {
1973
- color: get3(tokens, "extend.semanticColors.base.fg.dark", "white"),
1950
+ color: get2(tokens, "extend.semanticColors.base.fg.dark", "white"),
1974
1951
  caretColor: "white"
1975
1952
  },
1976
1953
  //
@@ -1983,10 +1960,10 @@ var defaultTheme = {
1983
1960
  borderLeft: "2px solid white"
1984
1961
  },
1985
1962
  "&light .cm-placeholder": {
1986
- color: get3(tokens, "extend.semanticColors.description.light", "rgba(0,0,0,.2)")
1963
+ color: get2(tokens, "extend.semanticColors.description.light", "rgba(0,0,0,.2)")
1987
1964
  },
1988
1965
  "&dark .cm-placeholder": {
1989
- color: get3(tokens, "extend.semanticColors.description.dark", "rgba(255,255,255,.2)")
1966
+ color: get2(tokens, "extend.semanticColors.description.dark", "rgba(255,255,255,.2)")
1990
1967
  },
1991
1968
  //
1992
1969
  // line
@@ -2007,36 +1984,36 @@ var defaultTheme = {
2007
1984
  // Selection
2008
1985
  //
2009
1986
  "&light .cm-selectionBackground": {
2010
- background: get3(tokens, "extend.colors.primary.100")
1987
+ background: get2(tokens, "extend.colors.primary.100")
2011
1988
  },
2012
1989
  "&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
2013
- background: get3(tokens, "extend.colors.primary.200")
1990
+ background: get2(tokens, "extend.colors.primary.200")
2014
1991
  },
2015
1992
  "&dark .cm-selectionBackground": {
2016
- background: get3(tokens, "extend.colors.primary.700")
1993
+ background: get2(tokens, "extend.colors.primary.700")
2017
1994
  },
2018
1995
  "&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
2019
- background: get3(tokens, "extend.colors.primary.600")
1996
+ background: get2(tokens, "extend.colors.primary.600")
2020
1997
  },
2021
1998
  //
2022
1999
  // Search
2023
2000
  //
2024
2001
  "&light .cm-searchMatch": {
2025
- backgroundColor: get3(tokens, "extend.colors.yellow.100")
2002
+ backgroundColor: get2(tokens, "extend.colors.yellow.100")
2026
2003
  },
2027
2004
  "&dark .cm-searchMatch": {
2028
- backgroundColor: get3(tokens, "extend.colors.yellow.700")
2005
+ backgroundColor: get2(tokens, "extend.colors.yellow.700")
2029
2006
  },
2030
2007
  //
2031
2008
  // link
2032
2009
  //
2033
2010
  ".cm-link": {
2034
- color: get3(tokens, "extend.colors.primary.500"),
2011
+ color: get2(tokens, "extend.colors.primary.500"),
2035
2012
  textDecorationLine: "underline",
2036
2013
  textDecorationThickness: "1px",
2037
2014
  textUnderlineOffset: "2px",
2038
2015
  borderRadius: ".125rem",
2039
- fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2016
+ fontFamily: get2(tokens, "fontFamily.body", []).join(",")
2040
2017
  },
2041
2018
  //
2042
2019
  // tooltip
@@ -2059,7 +2036,7 @@ var defaultTheme = {
2059
2036
  display: "none"
2060
2037
  },
2061
2038
  ".cm-completionLabel": {
2062
- fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2039
+ fontFamily: get2(tokens, "fontFamily.body", []).join(",")
2063
2040
  },
2064
2041
  ".cm-completionMatchedText": {
2065
2042
  textDecoration: "none"
@@ -2068,15 +2045,15 @@ var defaultTheme = {
2068
2045
  // table
2069
2046
  //
2070
2047
  ".cm-table *": {
2071
- fontFamily: `${get3(tokens, "fontFamily.mono", []).join(",")} !important`,
2048
+ fontFamily: `${get2(tokens, "fontFamily.mono", []).join(",")} !important`,
2072
2049
  textDecoration: "none !important"
2073
2050
  },
2074
2051
  ".cm-table-head": {
2075
2052
  padding: "2px 16px 2px 0px",
2076
- borderBottom: `1px solid ${get3(tokens, "extend.colors.neutral.500")}`,
2053
+ borderBottom: `1px solid ${get2(tokens, "extend.colors.neutral.500")}`,
2077
2054
  fontWeight: 100,
2078
2055
  textAlign: "left",
2079
- color: get3(tokens, "extend.colors.neutral.500")
2056
+ color: get2(tokens, "extend.colors.neutral.500")
2080
2057
  },
2081
2058
  ".cm-table-cell": {
2082
2059
  padding: "2px 16px 2px 0px"
@@ -2124,20 +2101,20 @@ var defaultTheme = {
2124
2101
  */
2125
2102
  ".cm-panels": {},
2126
2103
  ".cm-panel": {
2127
- fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2104
+ fontFamily: get2(tokens, "fontFamily.body", []).join(",")
2128
2105
  },
2129
2106
  ".cm-panel input[type=checkbox]": {
2130
2107
  marginRight: "0.4rem !important"
2131
2108
  },
2132
2109
  "&light .cm-panel": {
2133
- background: get3(tokens, "extend.colors.neutral.50")
2110
+ background: get2(tokens, "extend.colors.neutral.50")
2134
2111
  },
2135
2112
  "&dark .cm-panel": {
2136
- background: get3(tokens, "extend.colors.neutral.850")
2113
+ background: get2(tokens, "extend.colors.neutral.850")
2137
2114
  },
2138
2115
  ".cm-button": {
2139
2116
  margin: "4px",
2140
- fontFamily: get3(tokens, "fontFamily.body", []).join(","),
2117
+ fontFamily: get2(tokens, "fontFamily.body", []).join(","),
2141
2118
  backgroundImage: "none",
2142
2119
  border: "none",
2143
2120
  "&:active": {
@@ -2145,21 +2122,21 @@ var defaultTheme = {
2145
2122
  }
2146
2123
  },
2147
2124
  "&light .cm-button": {
2148
- background: get3(tokens, "extend.colors.neutral.100"),
2125
+ background: get2(tokens, "extend.colors.neutral.100"),
2149
2126
  "&:hover": {
2150
- background: get3(tokens, "extend.colors.neutral.200")
2127
+ background: get2(tokens, "extend.colors.neutral.200")
2151
2128
  },
2152
2129
  "&:active": {
2153
- background: get3(tokens, "extend.colors.neutral.300")
2130
+ background: get2(tokens, "extend.colors.neutral.300")
2154
2131
  }
2155
2132
  },
2156
2133
  "&dark .cm-button": {
2157
- background: get3(tokens, "extend.colors.neutral.800"),
2134
+ background: get2(tokens, "extend.colors.neutral.800"),
2158
2135
  "&:hover": {
2159
- background: get3(tokens, "extend.colors.neutral.700")
2136
+ background: get2(tokens, "extend.colors.neutral.700")
2160
2137
  },
2161
2138
  "&:active": {
2162
- background: get3(tokens, "extend.colors.neutral.600")
2139
+ background: get2(tokens, "extend.colors.neutral.600")
2163
2140
  }
2164
2141
  }
2165
2142
  };
@@ -2247,9 +2224,9 @@ var createThemeExtensions = ({ theme, themeMode, slots: _slots } = {}) => {
2247
2224
  ].filter(isNotFalsy2);
2248
2225
  };
2249
2226
  var createDataExtensions = ({ id, text, space, identity }) => {
2250
- const extensions = [
2227
+ const extensions = text ? [
2251
2228
  automerge(text)
2252
- ];
2229
+ ] : [];
2253
2230
  if (space && identity) {
2254
2231
  const peerId = identity?.identityKey.toHex();
2255
2232
  const { cursorLightValue, cursorDarkValue } = hueTokens[identity?.profile?.data?.hue ?? hexToHue(peerId ?? "0")];
@@ -4404,10 +4381,23 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
4404
4381
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
4405
4382
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx";
4406
4383
  var instanceCount = 0;
4407
- var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, className, autoFocus, scrollTo = EditorView16.scrollIntoView(0, {
4408
- yMargin: 0
4409
- }), moveToEndOfLine, debug, dataTestId }, forwardedRef) => {
4384
+ var TextEditor = /* @__PURE__ */ forwardRef(({
4385
+ id,
4386
+ // TODO(wittjosiah): Rename initialText?
4387
+ doc,
4388
+ selection,
4389
+ extensions,
4390
+ className,
4391
+ autoFocus,
4392
+ scrollTo: propsScrollTo,
4393
+ moveToEndOfLine,
4394
+ debug,
4395
+ dataTestId
4396
+ }, forwardedRef) => {
4410
4397
  const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4398
+ const scrollTo = useDefaultValue(propsScrollTo, EditorView16.scrollIntoView(0, {
4399
+ yMargin: 0
4400
+ }));
4411
4401
  const tabsterDOMAttribute = useFocusableGroup({
4412
4402
  tabBehavior: "limited"
4413
4403
  });
@@ -4430,20 +4420,19 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4430
4420
  instanceId
4431
4421
  }, {
4432
4422
  F: __dxlog_file10,
4433
- L: 88,
4423
+ L: 91,
4434
4424
  S: void 0,
4435
4425
  C: (f, a) => f(...a)
4436
4426
  });
4437
4427
  const state2 = EditorState2.create({
4438
4428
  doc,
4439
- selection,
4440
4429
  extensions: [
4441
4430
  id && documentId2.of(id),
4442
4431
  // TODO(burdon): NOTE: Doesn't catch errors in keymap functions.
4443
4432
  EditorView16.exceptionSink.of((err) => {
4444
4433
  log7.catch(err, void 0, {
4445
4434
  F: __dxlog_file10,
4446
- L: 101,
4435
+ L: 104,
4447
4436
  S: void 0,
4448
4437
  C: (f, a) => f(...a)
4449
4438
  });
@@ -4490,15 +4479,17 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4490
4479
  instanceId
4491
4480
  }, {
4492
4481
  F: __dxlog_file10,
4493
- L: 150,
4482
+ L: 153,
4494
4483
  S: void 0,
4495
4484
  C: (f, a) => f(...a)
4496
4485
  });
4497
4486
  view2?.destroy();
4498
4487
  };
4499
4488
  }, [
4500
- doc,
4489
+ id,
4501
4490
  selection,
4491
+ scrollTo,
4492
+ editorMode,
4502
4493
  extensions
4503
4494
  ]);
4504
4495
  const handleKeyUp = useCallback((event) => {
@@ -4837,28 +4828,15 @@ var useActionHandler = (view) => {
4837
4828
  return (action) => view && processAction(view, action);
4838
4829
  };
4839
4830
 
4840
- // packages/ui/react-ui-editor/src/hooks/useDocAccessor.ts
4841
- import { useMemo as useMemo2 } from "react";
4842
- import { createDocAccessor, getTextContent } from "@dxos/echo-schema";
4843
- var useDocAccessor = (text) => {
4844
- return useMemo2(() => ({
4845
- id: text.id,
4846
- doc: getTextContent(text),
4847
- accessor: createDocAccessor(text)
4848
- }), [
4849
- text
4850
- ]);
4851
- };
4852
-
4853
4831
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4854
4832
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4855
4833
  import { EditorView as EditorView17 } from "@codemirror/view";
4856
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4834
+ import { useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
4857
4835
  import { log as log8 } from "@dxos/log";
4858
4836
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4859
4837
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4860
4838
  var useTextEditor = (cb = () => ({}), deps = []) => {
4861
- let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4839
+ let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo2(cb, deps ?? []);
4862
4840
  const onUpdate = useRef3();
4863
4841
  const [view, setView] = useState4();
4864
4842
  const parentRef = useRef3(null);
@@ -4875,7 +4853,6 @@ var useTextEditor = (cb = () => ({}), deps = []) => {
4875
4853
  });
4876
4854
  const state2 = EditorState3.create({
4877
4855
  doc,
4878
- selection,
4879
4856
  extensions: [
4880
4857
  id && documentId2.of(id),
4881
4858
  // TODO(burdon): Doesn't catch errors in keymap functions.
@@ -5034,7 +5011,6 @@ export {
5034
5011
  typewriter,
5035
5012
  useActionHandler,
5036
5013
  useComments,
5037
- useDocAccessor,
5038
5014
  useFormattingState,
5039
5015
  useTextEditor,
5040
5016
  useToolbarContext