@dxos/react-ui-editor 0.3.11-main.3f845e1 → 0.3.11-main.9bacd9f

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.
Files changed (24) hide show
  1. package/dist/lib/browser/index.mjs +92 -87
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +0 -3
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -2
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
  9. package/dist/types/src/components/TextEditor/extensions/index.d.ts +0 -1
  10. package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
  11. package/dist/types/src/components/TextEditor/extensions/link.d.ts +1 -0
  12. package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
  13. package/dist/types/src/components/TextEditor/extensions/listener.d.ts +5 -4
  14. package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
  15. package/package.json +21 -21
  16. package/src/components/TextEditor/MarkdownEditor.stories.tsx +10 -12
  17. package/src/components/TextEditor/TextEditor.tsx +4 -4
  18. package/src/components/TextEditor/extensions/comments.ts +2 -1
  19. package/src/components/TextEditor/extensions/index.ts +0 -1
  20. package/src/components/TextEditor/extensions/link.ts +66 -10
  21. package/src/components/TextEditor/extensions/listener.ts +25 -13
  22. package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
  23. package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
  24. package/src/components/TextEditor/extensions/tooltip.ts +0 -61
@@ -1099,7 +1099,7 @@ var BookmarkWidget = class extends WidgetType {
1099
1099
  this._handleClick = _handleClick;
1100
1100
  invariant3(this._id, void 0, {
1101
1101
  F: __dxlog_file5,
1102
- L: 150,
1102
+ L: 151,
1103
1103
  S: this,
1104
1104
  A: [
1105
1105
  "this._id",
@@ -1125,7 +1125,7 @@ var comments = (options = {}) => {
1125
1125
  const createCommentThread = (view) => {
1126
1126
  invariant3(options.onCreate, void 0, {
1127
1127
  F: __dxlog_file5,
1128
- L: 204,
1128
+ L: 205,
1129
1129
  S: void 0,
1130
1130
  A: [
1131
1131
  "options.onCreate",
@@ -1207,7 +1207,7 @@ var comments = (options = {}) => {
1207
1207
  options.onCreate ? keymap3.of([
1208
1208
  {
1209
1209
  key: options?.key ?? "meta-'",
1210
- run: createCommentThread
1210
+ run: callbackWrapper(createCommentThread)
1211
1211
  }
1212
1212
  ]) : [],
1213
1213
  //
@@ -1251,7 +1251,7 @@ var comments = (options = {}) => {
1251
1251
  changes.iterChanges((from, to, from2, to2) => {
1252
1252
  invariant3(model, void 0, {
1253
1253
  F: __dxlog_file5,
1254
- L: 333,
1254
+ L: 334,
1255
1255
  S: void 0,
1256
1256
  A: [
1257
1257
  "model",
@@ -1266,7 +1266,7 @@ var comments = (options = {}) => {
1266
1266
  thread: range.id
1267
1267
  }, {
1268
1268
  F: __dxlog_file5,
1269
- L: 339,
1269
+ L: 340,
1270
1270
  S: void 0,
1271
1271
  C: (f, a) => f(...a)
1272
1272
  });
@@ -1422,13 +1422,64 @@ var ImageWidget = class extends WidgetType3 {
1422
1422
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/link.ts
1423
1423
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1424
1424
  import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField5 } from "@codemirror/state";
1425
- import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType4 } from "@codemirror/view";
1425
+ import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType4, hoverTooltip as hoverTooltip2 } from "@codemirror/view";
1426
+ import { tooltipContent } from "@dxos/react-ui-theme";
1427
+ var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
1426
1428
  var link = (options = {}) => {
1427
- return StateField5.define({
1428
- create: (state) => update2(state, options),
1429
- update: (_, tr) => update2(tr.state, options),
1430
- provide: (field) => EditorView7.decorations.from(field)
1431
- });
1429
+ const extensions = [
1430
+ StateField5.define({
1431
+ create: (state) => update2(state, options),
1432
+ update: (_, tr) => update2(tr.state, options),
1433
+ provide: (field) => EditorView7.decorations.from(field)
1434
+ })
1435
+ ];
1436
+ if (options.onHover) {
1437
+ extensions.push(
1438
+ // https://codemirror.net/examples/tooltip
1439
+ // https://codemirror.net/docs/ref/#view.hoverTooltip
1440
+ // https://github.com/codemirror/view/blob/main/src/tooltip.ts
1441
+ hoverTooltip2((view, pos) => {
1442
+ const { from, text } = view.state.doc.lineAt(pos);
1443
+ const p = pos - from;
1444
+ let idx = 0;
1445
+ let match;
1446
+ do {
1447
+ match = text.substring(idx).match(markdownLinkRegexp);
1448
+ if (!match) {
1449
+ match = void 0;
1450
+ break;
1451
+ }
1452
+ idx = text.indexOf(match[0]);
1453
+ if (p >= idx && p < idx + match[0].length) {
1454
+ break;
1455
+ }
1456
+ idx += match[0].length;
1457
+ } while (true);
1458
+ if (!match) {
1459
+ return null;
1460
+ }
1461
+ const [, , url] = match ?? [];
1462
+ return {
1463
+ pos: idx + from,
1464
+ end: idx + from + match[0].length,
1465
+ above: true,
1466
+ create: () => {
1467
+ const el = document.createElement("div");
1468
+ el.className = tooltipContent({}, "pli-2 plb-1");
1469
+ options.onHover(el, url);
1470
+ return {
1471
+ dom: el,
1472
+ offset: {
1473
+ x: 0,
1474
+ y: 4
1475
+ }
1476
+ };
1477
+ }
1478
+ };
1479
+ })
1480
+ );
1481
+ }
1482
+ return extensions;
1432
1483
  };
1433
1484
  var LinkButton = class extends WidgetType4 {
1434
1485
  constructor(_pos, _url, _onAttach) {
@@ -1447,14 +1498,13 @@ var LinkButton = class extends WidgetType4 {
1447
1498
  }
1448
1499
  };
1449
1500
  var LinkText = class extends WidgetType4 {
1450
- constructor(_pos, _text, _url) {
1501
+ constructor(_text, _url) {
1451
1502
  super();
1452
- this._pos = _pos;
1453
1503
  this._text = _text;
1454
1504
  this._url = _url;
1455
1505
  }
1456
1506
  eq(other) {
1457
- return this._pos === other._pos && this._url === other._url;
1507
+ return this._url === other._url;
1458
1508
  }
1459
1509
  toDOM(view) {
1460
1510
  const link2 = document.createElement("a");
@@ -1468,7 +1518,7 @@ var LinkText = class extends WidgetType4 {
1468
1518
  link2.onclick = () => {
1469
1519
  view.dispatch({
1470
1520
  selection: {
1471
- anchor: this._pos
1521
+ anchor: view.posAtDOM(link2)
1472
1522
  }
1473
1523
  });
1474
1524
  };
@@ -1491,7 +1541,7 @@ var update2 = (state, options) => {
1491
1541
  }
1492
1542
  if (state.readOnly || cursor < node.from || cursor > node.to) {
1493
1543
  builder.add(node.from, node.to, Decoration5.replace({
1494
- widget: new LinkText(node.from, text, options.link ? url : void 0)
1544
+ widget: new LinkText(text, options.link ? url : void 0)
1495
1545
  }));
1496
1546
  }
1497
1547
  if (options.onRender) {
@@ -1507,17 +1557,17 @@ var update2 = (state, options) => {
1507
1557
  };
1508
1558
 
1509
1559
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/listener.ts
1510
- import { StateField as StateField6 } from "@codemirror/state";
1511
- var listener = ({ onChange }) => {
1512
- return StateField6.define({
1513
- create: () => null,
1514
- update: (_value, transaction) => {
1515
- if (transaction.docChanged && onChange) {
1516
- onChange(transaction.newDoc.toString());
1517
- }
1518
- return null;
1519
- }
1520
- });
1560
+ import { EditorView as EditorView8 } from "@codemirror/view";
1561
+ var listener = ({ onFocus, onChange }) => {
1562
+ const extensions = [];
1563
+ onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
1564
+ onFocus(focused);
1565
+ return null;
1566
+ }));
1567
+ onChange && extensions.push(EditorView8.updateListener.of((update4) => {
1568
+ onChange(update4.state.doc.toString());
1569
+ }));
1570
+ return extensions;
1521
1571
  };
1522
1572
 
1523
1573
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/bundle.ts
@@ -1529,7 +1579,7 @@ import { languages } from "@codemirror/language-data";
1529
1579
  import { searchKeymap } from "@codemirror/search";
1530
1580
  import { EditorState } from "@codemirror/state";
1531
1581
  import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
1532
- import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView8, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1582
+ import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView9, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1533
1583
 
1534
1584
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/highlight.ts
1535
1585
  import { markdownLanguage } from "@codemirror/lang-markdown";
@@ -1732,7 +1782,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1732
1782
  return [
1733
1783
  EditorState.allowMultipleSelections.of(true),
1734
1784
  EditorState.tabSize.of(2),
1735
- EditorView8.lineWrapping,
1785
+ EditorView9.lineWrapping,
1736
1786
  customKeymap(),
1737
1787
  bracketMatching2(),
1738
1788
  closeBrackets2(),
@@ -1810,13 +1860,13 @@ var mermaid = () => {
1810
1860
 
1811
1861
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/table.ts
1812
1862
  import { syntaxTree as syntaxTree3 } from "@codemirror/language";
1813
- import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField7 } from "@codemirror/state";
1814
- import { Decoration as Decoration6, EditorView as EditorView9, WidgetType as WidgetType5 } from "@codemirror/view";
1863
+ import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField6 } from "@codemirror/state";
1864
+ import { Decoration as Decoration6, EditorView as EditorView10, WidgetType as WidgetType5 } from "@codemirror/view";
1815
1865
  var table = (options = {}) => {
1816
- return StateField7.define({
1866
+ return StateField6.define({
1817
1867
  create: (state) => update3(state, options),
1818
1868
  update: (_, tr) => update3(tr.state, options),
1819
- provide: (field) => EditorView9.decorations.from(field)
1869
+ provide: (field) => EditorView10.decorations.from(field)
1820
1870
  });
1821
1871
  };
1822
1872
  var update3 = (state, options) => {
@@ -1905,8 +1955,8 @@ var TableWidget = class extends WidgetType5 {
1905
1955
  };
1906
1956
 
1907
1957
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/tasklist.ts
1908
- import { EditorView as EditorView10, Decoration as Decoration7, WidgetType as WidgetType6, MatchDecorator as MatchDecorator3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
1909
- var styles4 = EditorView10.baseTheme({
1958
+ import { EditorView as EditorView11, Decoration as Decoration7, WidgetType as WidgetType6, MatchDecorator as MatchDecorator3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
1959
+ var styles4 = EditorView11.baseTheme({
1910
1960
  "& .cm-task-item": {
1911
1961
  paddingLeft: "4px",
1912
1962
  paddingRight: "8px"
@@ -1979,7 +2029,7 @@ var tasklist = (options = {}) => {
1979
2029
  }
1980
2030
  }, {
1981
2031
  decorations: (value) => value.tasks,
1982
- provide: (plugin) => EditorView10.atomicRanges.of((view) => {
2032
+ provide: (plugin) => EditorView11.atomicRanges.of((view) => {
1983
2033
  return view.plugin(plugin)?.tasks || Decoration7.none;
1984
2034
  })
1985
2035
  });
@@ -1989,50 +2039,6 @@ var tasklist = (options = {}) => {
1989
2039
  ];
1990
2040
  };
1991
2041
 
1992
- // packages/ui/react-ui-editor/src/components/TextEditor/extensions/tooltip.ts
1993
- import { hoverTooltip as hoverTooltip2 } from "@codemirror/view";
1994
- import { tooltipContent } from "@dxos/react-ui-theme";
1995
- var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
1996
- var tooltip = ({ onHover, regexp = markdownLinkRegexp }) => hoverTooltip2((view, pos) => {
1997
- const { from, text } = view.state.doc.lineAt(pos);
1998
- const p = pos - from;
1999
- let idx = 0;
2000
- let match;
2001
- do {
2002
- match = text.substring(idx).match(regexp);
2003
- if (!match) {
2004
- match = void 0;
2005
- break;
2006
- }
2007
- idx = text.indexOf(match[0]);
2008
- if (p >= idx && p < idx + match[0].length) {
2009
- break;
2010
- }
2011
- idx += match[0].length;
2012
- } while (true);
2013
- if (!match) {
2014
- return null;
2015
- }
2016
- const [, , url] = match ?? [];
2017
- return {
2018
- pos: idx + from,
2019
- end: idx + from + match[0].length,
2020
- above: true,
2021
- create: () => {
2022
- const el = document.createElement("div");
2023
- el.className = tooltipContent({}, "pli-2 plb-1");
2024
- onHover(el, url);
2025
- return {
2026
- dom: el,
2027
- offset: {
2028
- x: 0,
2029
- y: 4
2030
- }
2031
- };
2032
- }
2033
- };
2034
- });
2035
-
2036
2042
  // packages/ui/react-ui-editor/src/components/TextEditor/extensions/typewriter.ts
2037
2043
  import { keymap as keymap5 } from "@codemirror/view";
2038
2044
  var defaultItems = [
@@ -2364,7 +2370,7 @@ var codeTheme = {
2364
2370
 
2365
2371
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
2366
2372
  import { EditorState as EditorState2 } from "@codemirror/state";
2367
- import { EditorView as EditorView11 } from "@codemirror/view";
2373
+ import { EditorView as EditorView12 } from "@codemirror/view";
2368
2374
  import { useFocusableGroup } from "@fluentui/react-tabster";
2369
2375
  import { vim } from "@replit/codemirror-vim";
2370
2376
  import defaultsDeep2 from "lodash.defaultsdeep";
@@ -2376,7 +2382,7 @@ var EditorModes = [
2376
2382
  "default",
2377
2383
  "vim"
2378
2384
  ];
2379
- var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, readonly, editorMode, extensions = [], slots = defaultSlots }, forwardedRef) => {
2385
+ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: comments2, extensions = [], editorMode, slots = defaultSlots }, forwardedRef) => {
2380
2386
  const { themeMode } = useThemeContext();
2381
2387
  const tabsterDOMAttribute = useFocusableGroup({
2382
2388
  tabBehavior: "limited"
@@ -2438,9 +2444,9 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
2438
2444
  editorMode === "vim" && vim(),
2439
2445
  // Theme.
2440
2446
  // TODO(burdon): Make theme configurable.
2441
- EditorView11.baseTheme(defaultTheme),
2442
- EditorView11.theme(slots?.editor?.theme ?? {}),
2443
- EditorView11.darkTheme.of(themeMode === "dark"),
2447
+ EditorView12.baseTheme(defaultTheme),
2448
+ EditorView12.theme(slots?.editor?.theme ?? {}),
2449
+ EditorView12.darkTheme.of(themeMode === "dark"),
2444
2450
  // Storage and replication.
2445
2451
  model.extension,
2446
2452
  // Custom.
@@ -2450,7 +2456,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, comments: comments2, r
2450
2456
  view?.destroy();
2451
2457
  setEditor({
2452
2458
  state: state2,
2453
- view: new EditorView11({
2459
+ view: new EditorView12({
2454
2460
  state: state2,
2455
2461
  parent: root
2456
2462
  })
@@ -2583,7 +2589,6 @@ export {
2583
2589
  tags2 as tags,
2584
2590
  tasklist,
2585
2591
  textTheme,
2586
- tooltip,
2587
2592
  typewriter,
2588
2593
  useTextModel
2589
2594
  };