@dxos/react-ui-editor 0.8.1-staging.391c573 → 0.8.1-staging.5be625a

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.
@@ -64,6 +64,7 @@ __export(node_exports, {
64
64
  createDataExtensions: () => createDataExtensions,
65
65
  createEditorAction: () => createEditorAction,
66
66
  createEditorActionGroup: () => createEditorActionGroup,
67
+ createEditorStateStore: () => createEditorStateStore,
67
68
  createEditorStateTransaction: () => createEditorStateTransaction,
68
69
  createElement: () => createElement,
69
70
  createExternalCommentSync: () => createExternalCommentSync,
@@ -207,6 +208,8 @@ var import_util2 = require("@dxos/util");
207
208
  var import_state11 = require("@codemirror/state");
208
209
  var import_view12 = require("@codemirror/view");
209
210
  var import_async4 = require("@dxos/async");
211
+ var import_invariant3 = require("@dxos/invariant");
212
+ var import_util3 = require("@dxos/util");
210
213
  var import_language = require("@codemirror/language");
211
214
  var import_state12 = require("@codemirror/state");
212
215
  var import_view13 = require("@codemirror/view");
@@ -221,13 +224,12 @@ var import_lodash4 = __toESM(require("lodash.defaultsdeep"));
221
224
  var import_lodash5 = __toESM(require("lodash.merge"));
222
225
  var import_display_name = require("@dxos/display-name");
223
226
  var import_log5 = require("@dxos/log");
224
- var import_util3 = require("@dxos/util");
227
+ var import_util4 = require("@dxos/util");
225
228
  var import_state14 = require("@codemirror/state");
226
229
  var import_view15 = require("@codemirror/view");
227
230
  var import_language3 = require("@codemirror/language");
228
231
  var import_view16 = require("@codemirror/view");
229
232
  var import_react5 = __toESM(require("react"));
230
- var import_async5 = require("@dxos/async");
231
233
  var import_react_ui3 = require("@dxos/react-ui");
232
234
  var import_view17 = require("@codemirror/view");
233
235
  var import_autocomplete3 = require("@codemirror/autocomplete");
@@ -251,7 +253,7 @@ var import_state16 = require("@codemirror/state");
251
253
  var import_language8 = require("@codemirror/language");
252
254
  var import_state17 = require("@codemirror/state");
253
255
  var import_view20 = require("@codemirror/view");
254
- var import_invariant3 = require("@dxos/invariant");
256
+ var import_invariant4 = require("@dxos/invariant");
255
257
  var import_react_ui_theme7 = require("@dxos/react-ui-theme");
256
258
  var import_language9 = require("@codemirror/language");
257
259
  var import_state18 = require("@codemirror/state");
@@ -279,7 +281,7 @@ var import_view28 = require("@codemirror/view");
279
281
  var import_react_tabster = require("@fluentui/react-tabster");
280
282
  var import_react8 = require("react");
281
283
  var import_log7 = require("@dxos/log");
282
- var import_util4 = require("@dxos/util");
284
+ var import_util5 = require("@dxos/util");
283
285
  var translationKey = "react-ui-editor";
284
286
  var translations_default = [
285
287
  {
@@ -562,7 +564,7 @@ var createViewMode = (state) => {
562
564
  ]
563
565
  };
564
566
  };
565
- var stackItemContentEditorClassNames = (role) => (0, import_react_ui_theme2.mx)("dx-focus-ring-inset data-[toolbar=disabled]:pbs-2 attention-surface", role === "article" ? "min-bs-0" : "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24");
567
+ var stackItemContentEditorClassNames = (role) => (0, import_react_ui_theme2.mx)("dx-focus-ring-inset data-[toolbar=disabled]:pbs-2 attention-surface", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
566
568
  var stackItemContentToolbarClassNames = (role) => (0, import_react_ui_theme2.mx)("attention-surface is-full border-be !border-separator", role === "section" && "sticky block-start-0 z-[1] -mbe-px min-is-0");
567
569
  var createToolbar = ({ state, customActions, ...features }) => {
568
570
  const nodes = [];
@@ -754,6 +756,7 @@ var defaultTheme = {
754
756
  ".cm-link": {
755
757
  textDecorationLine: "underline",
756
758
  textDecorationThickness: "1px",
759
+ textDecorationColor: "var(--dx-separator)",
757
760
  textUnderlineOffset: "2px",
758
761
  borderRadius: ".125rem"
759
762
  },
@@ -966,7 +969,7 @@ var logChanges = (trs) => {
966
969
  return changes2;
967
970
  }).filter(Boolean);
968
971
  if (changes.length) {
969
- import_log.log.info("changes", {
972
+ (0, import_log.log)("changes", {
970
973
  changes
971
974
  }, {
972
975
  F: __dxlog_file,
@@ -2185,6 +2188,7 @@ var command = (options) => {
2185
2188
  })
2186
2189
  ];
2187
2190
  };
2191
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/selection.ts";
2188
2192
  var documentId = singleValueFacet();
2189
2193
  var stateRestoreAnnotation = "dxos.org/cm/state-restore";
2190
2194
  var createEditorStateTransaction = ({ scrollTo, selection }) => {
@@ -2197,10 +2201,34 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
2197
2201
  annotations: import_state11.Transaction.userEvent.of(stateRestoreAnnotation)
2198
2202
  };
2199
2203
  };
2200
- var selectionState = (state = {}) => {
2201
- const setState = (id, selectionState2) => {
2202
- state[id] = selectionState2;
2203
- };
2204
+ var createEditorStateStore = (keyPrefix) => ({
2205
+ getState: (id) => {
2206
+ (0, import_invariant3.invariant)(id, void 0, {
2207
+ F: __dxlog_file6,
2208
+ L: 47,
2209
+ S: void 0,
2210
+ A: [
2211
+ "id",
2212
+ ""
2213
+ ]
2214
+ });
2215
+ const state = localStorage.getItem(`${keyPrefix}/${id}`);
2216
+ return state ? JSON.parse(state) : void 0;
2217
+ },
2218
+ setState: (id, state) => {
2219
+ (0, import_invariant3.invariant)(id, void 0, {
2220
+ F: __dxlog_file6,
2221
+ L: 53,
2222
+ S: void 0,
2223
+ A: [
2224
+ "id",
2225
+ ""
2226
+ ]
2227
+ });
2228
+ localStorage.setItem(`${keyPrefix}/${id}`, JSON.stringify(state));
2229
+ }
2230
+ });
2231
+ var selectionState = ({ getState, setState } = {}) => {
2204
2232
  const setStateDebounced = (0, import_async4.debounce)(setState, 1e3);
2205
2233
  return [
2206
2234
  // TODO(burdon): Track scrolling (currently only updates when cursor moves).
@@ -2214,37 +2242,39 @@ var selectionState = (state = {}) => {
2214
2242
  if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
2215
2243
  return;
2216
2244
  }
2217
- const { scrollTop } = view.scrollDOM;
2218
- const pos = view.posAtCoords({
2219
- x: 0,
2220
- y: scrollTop
2221
- });
2222
- if (pos !== null) {
2223
- const { anchor, head } = view.state.selection.main;
2224
- setStateDebounced(id, {
2225
- scrollTo: pos,
2226
- selection: {
2227
- anchor,
2228
- head
2229
- }
2245
+ if (setState) {
2246
+ const { scrollTop } = view.scrollDOM;
2247
+ const pos = view.posAtCoords({
2248
+ x: 0,
2249
+ y: scrollTop
2230
2250
  });
2251
+ if (pos !== null) {
2252
+ const { anchor, head } = view.state.selection.main;
2253
+ setStateDebounced(id, {
2254
+ scrollTo: pos,
2255
+ selection: {
2256
+ anchor,
2257
+ head
2258
+ }
2259
+ });
2260
+ }
2231
2261
  }
2232
2262
  }),
2233
- import_view12.keymap.of([
2263
+ getState && import_view12.keymap.of([
2234
2264
  {
2235
2265
  key: "ctrl-r",
2236
2266
  run: (view) => {
2237
- const selection = state[view.state.facet(documentId)];
2238
- if (selection) {
2239
- view.dispatch(createEditorStateTransaction(selection));
2267
+ const state = getState(view.state.facet(documentId));
2268
+ if (state) {
2269
+ view.dispatch(createEditorStateTransaction(state));
2240
2270
  }
2241
2271
  return true;
2242
2272
  }
2243
2273
  }
2244
2274
  ])
2245
- ];
2275
+ ].filter(import_util3.isNotFalsy);
2246
2276
  };
2247
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
2277
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
2248
2278
  var setComments = import_state10.StateEffect.define();
2249
2279
  var setSelection = import_state10.StateEffect.define();
2250
2280
  var setCommentState = import_state10.StateEffect.define();
@@ -2314,7 +2344,7 @@ var commentsDecorations = import_view11.EditorView.decorations.compute([
2314
2344
  const range = comment.range;
2315
2345
  if (!range) {
2316
2346
  import_log4.log.warn("Invalid range:", range, {
2317
- F: __dxlog_file6,
2347
+ F: __dxlog_file7,
2318
2348
  L: 144,
2319
2349
  S: void 0,
2320
2350
  C: (f, a) => f(...a)
@@ -2773,7 +2803,7 @@ var focus = [
2773
2803
  }
2774
2804
  })
2775
2805
  ];
2776
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
2806
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
2777
2807
  var preventNewline = import_state13.EditorState.transactionFilter.of((tr) => tr.newDoc.lines > 1 ? [] : tr);
2778
2808
  var defaultBasicOptions = {
2779
2809
  allowMultipleSelections: true,
@@ -2799,8 +2829,8 @@ var createBasicExtensions = (_props) => {
2799
2829
  // NOTE: Doesn't catch errors in keymap functions.
2800
2830
  import_view14.EditorView.exceptionSink.of((err) => {
2801
2831
  import_log5.log.catch(err, void 0, {
2802
- F: __dxlog_file7,
2803
- L: 96,
2832
+ F: __dxlog_file8,
2833
+ L: 97,
2804
2834
  S: void 0,
2805
2835
  C: (f, a) => f(...a)
2806
2836
  });
@@ -2845,8 +2875,8 @@ var createBasicExtensions = (_props) => {
2845
2875
  preventDefault: true,
2846
2876
  run: () => true
2847
2877
  }
2848
- ].filter(import_util3.isNotFalsy))
2849
- ].filter(import_util3.isNotFalsy);
2878
+ ].filter(import_util4.isNotFalsy))
2879
+ ].filter(import_util4.isNotFalsy);
2850
2880
  };
2851
2881
  var defaultThemeSlots = {
2852
2882
  editor: {
@@ -2866,7 +2896,7 @@ var createThemeExtensions = ({ themeMode, styles: styles5, syntaxHighlighting: _
2866
2896
  slots.content?.className && import_view14.EditorView.contentAttributes.of({
2867
2897
  class: slots.content.className
2868
2898
  })
2869
- ].filter(import_util3.isNotFalsy);
2899
+ ].filter(import_util4.isNotFalsy);
2870
2900
  };
2871
2901
  var createDataExtensions = ({ id, text, space, identity }) => {
2872
2902
  const extensions = [];
@@ -2875,7 +2905,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
2875
2905
  }
2876
2906
  if (space && identity) {
2877
2907
  const peerId = identity?.identityKey.toHex();
2878
- const hue = identity?.profile?.data?.hue ?? (0, import_util3.hexToHue)(peerId ?? "0");
2908
+ const hue = identity?.profile?.data?.hue ?? (0, import_util4.hexToHue)(peerId ?? "0");
2879
2909
  extensions.push(awareness(new SpaceAwarenessProvider({
2880
2910
  space,
2881
2911
  channel: `awareness.${id}`,
@@ -2889,76 +2919,38 @@ var createDataExtensions = ({ id, text, space, identity }) => {
2889
2919
  }
2890
2920
  return extensions;
2891
2921
  };
2892
- var folding = (state = {}) => {
2893
- const setState = (id, foldState) => {
2894
- state[id] = foldState;
2895
- };
2896
- const setStateDebounced = (0, import_async5.debounce)(setState, 1e3);
2897
- let initialized = false;
2898
- return [
2899
- (0, import_language3.codeFolding)({
2900
- placeholderDOM: () => {
2901
- return document.createElement("span");
2902
- }
2903
- }),
2904
- (0, import_language3.foldGutter)({
2905
- markerDOM: (open) => {
2906
- const el = createElement("div", {
2907
- className: "flex h-full items-center"
2908
- });
2909
- return renderRoot(el, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Icon, {
2910
- icon: "ph--caret-right--regular",
2911
- size: 3,
2912
- classNames: [
2913
- "mx-3 cursor-pointer",
2914
- open && "rotate-90"
2915
- ]
2916
- }));
2917
- }
2918
- }),
2919
- import_view16.EditorView.theme({
2920
- ".cm-foldGutter": {
2921
- opacity: 0.3,
2922
- transition: "opacity 0.3s",
2923
- width: "32px"
2924
- },
2925
- ".cm-foldGutter:hover": {
2926
- opacity: 1
2927
- }
2928
- }),
2929
- import_view16.EditorView.updateListener.of(({ view }) => {
2930
- const id = view.state.facet(documentId);
2931
- if (!id) {
2932
- return;
2933
- }
2934
- if (!initialized) {
2935
- initialized = true;
2936
- const foldState2 = state[id];
2937
- if (foldState2?.foldedRanges?.length) {
2938
- view.dispatch({
2939
- effects: foldState2.foldedRanges.map((range) => import_language3.foldEffect.of({
2940
- from: range.from,
2941
- to: range.to
2942
- }))
2943
- });
2944
- }
2945
- return;
2946
- }
2947
- const decorations = (0, import_language3.foldedRanges)(view.state);
2948
- const ranges = [];
2949
- decorations.between(0, view.state.doc.length, (from, to) => {
2950
- ranges.push({
2951
- from,
2952
- to
2953
- });
2922
+ var folding = (_props = {}) => [
2923
+ (0, import_language3.codeFolding)({
2924
+ placeholderDOM: () => {
2925
+ return document.createElement("span");
2926
+ }
2927
+ }),
2928
+ (0, import_language3.foldGutter)({
2929
+ markerDOM: (open) => {
2930
+ const el = createElement("div", {
2931
+ className: "flex h-full items-center"
2954
2932
  });
2955
- const foldState = {
2956
- foldedRanges: ranges
2957
- };
2958
- setStateDebounced?.(id, foldState);
2959
- })
2960
- ];
2961
- };
2933
+ return renderRoot(el, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Icon, {
2934
+ icon: "ph--caret-right--regular",
2935
+ size: 3,
2936
+ classNames: [
2937
+ "mx-3 cursor-pointer",
2938
+ open && "rotate-90"
2939
+ ]
2940
+ }));
2941
+ }
2942
+ }),
2943
+ import_view16.EditorView.theme({
2944
+ ".cm-foldGutter": {
2945
+ opacity: 0.3,
2946
+ transition: "opacity 0.3s",
2947
+ width: "32px"
2948
+ },
2949
+ ".cm-foldGutter:hover": {
2950
+ opacity: 1
2951
+ }
2952
+ })
2953
+ ];
2962
2954
  var listener = ({ onFocus, onChange }) => {
2963
2955
  const extensions = [];
2964
2956
  onFocus && extensions.push(import_view17.EditorView.focusChangeEffect.of((_, focusing) => {
@@ -4779,7 +4771,7 @@ var TableWidget = class extends import_view24.WidgetType {
4779
4771
  return !/^mouse/.test(e.type);
4780
4772
  }
4781
4773
  };
4782
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts";
4774
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts";
4783
4775
  var Unicode = {
4784
4776
  emDash: "\u2014",
4785
4777
  bullet: "\u2022",
@@ -4912,8 +4904,8 @@ var buildDecorations2 = (view, options, focus2) => {
4912
4904
  const { state } = view;
4913
4905
  const headerLevels = [];
4914
4906
  const getHeaderLevels = (node, level) => {
4915
- (0, import_invariant3.invariant)(level > 0, void 0, {
4916
- F: __dxlog_file8,
4907
+ (0, import_invariant4.invariant)(level > 0, void 0, {
4908
+ F: __dxlog_file9,
4917
4909
  L: 178,
4918
4910
  S: void 0,
4919
4911
  A: [
@@ -4951,8 +4943,8 @@ var buildDecorations2 = (view, options, focus2) => {
4951
4943
  listLevels.pop();
4952
4944
  };
4953
4945
  const getCurrentListLevel = () => {
4954
- (0, import_invariant3.invariant)(listLevels.length, void 0, {
4955
- F: __dxlog_file8,
4946
+ (0, import_invariant4.invariant)(listLevels.length, void 0, {
4947
+ F: __dxlog_file9,
4956
4948
  L: 200,
4957
4949
  S: void 0,
4958
4950
  A: [
@@ -5266,7 +5258,7 @@ var linkTooltip = (render) => {
5266
5258
  };
5267
5259
  });
5268
5260
  };
5269
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/mention.ts";
5261
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/mention.ts";
5270
5262
  var mention = ({ debug, onSearch }) => {
5271
5263
  return (0, import_autocomplete5.autocompletion)({
5272
5264
  // TODO(burdon): Not working.
@@ -5281,7 +5273,7 @@ var mention = ({ debug, onSearch }) => {
5281
5273
  import_log6.log.info("completion context", {
5282
5274
  context
5283
5275
  }, {
5284
- F: __dxlog_file9,
5276
+ F: __dxlog_file10,
5285
5277
  L: 27,
5286
5278
  S: void 0,
5287
5279
  C: (f, a) => f(...a)
@@ -5399,10 +5391,10 @@ var useActionHandler = (view) => {
5399
5391
  view
5400
5392
  ]);
5401
5393
  };
5402
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
5394
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
5403
5395
  var instanceCount = 0;
5404
5396
  var useTextEditor = (props = {}, deps = []) => {
5405
- const { id, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } = (0, import_react8.useMemo)(() => (0, import_util4.getProviderValue)(props), deps ?? []);
5397
+ const { id, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } = (0, import_react8.useMemo)(() => (0, import_util5.getProviderValue)(props), deps ?? []);
5406
5398
  const [instanceId] = (0, import_react8.useState)(() => `text-editor-${++instanceCount}`);
5407
5399
  const [view, setView] = (0, import_react8.useState)();
5408
5400
  const parentRef = (0, import_react8.useRef)(null);
@@ -5414,7 +5406,7 @@ var useTextEditor = (props = {}, deps = []) => {
5414
5406
  instanceId,
5415
5407
  doc: initialValue?.length ?? 0
5416
5408
  }, {
5417
- F: __dxlog_file10,
5409
+ F: __dxlog_file11,
5418
5410
  L: 75,
5419
5411
  S: void 0,
5420
5412
  C: (f, a) => f(...a)
@@ -5440,13 +5432,13 @@ var useTextEditor = (props = {}, deps = []) => {
5440
5432
  // NOTE: This doesn't catch errors in keymap functions.
5441
5433
  import_view28.EditorView.exceptionSink.of((err) => {
5442
5434
  import_log7.log.catch(err, void 0, {
5443
- F: __dxlog_file10,
5435
+ F: __dxlog_file11,
5444
5436
  L: 97,
5445
5437
  S: void 0,
5446
5438
  C: (f, a) => f(...a)
5447
5439
  });
5448
5440
  })
5449
- ].filter(import_util4.isNotFalsy)
5441
+ ].filter(import_util5.isNotFalsy)
5450
5442
  });
5451
5443
  view2 = new import_view28.EditorView({
5452
5444
  parent: parentRef.current,
@@ -5472,7 +5464,7 @@ var useTextEditor = (props = {}, deps = []) => {
5472
5464
  (0, import_log7.log)("destroy", {
5473
5465
  id
5474
5466
  }, {
5475
- F: __dxlog_file10,
5467
+ F: __dxlog_file11,
5476
5468
  L: 134,
5477
5469
  S: void 0,
5478
5470
  C: (f, a) => f(...a)
@@ -5489,7 +5481,7 @@ var useTextEditor = (props = {}, deps = []) => {
5489
5481
  scrollTo,
5490
5482
  selection
5491
5483
  }, {
5492
- F: __dxlog_file10,
5484
+ F: __dxlog_file11,
5493
5485
  L: 143,
5494
5486
  S: void 0,
5495
5487
  C: (f, a) => f(...a)
@@ -5582,6 +5574,7 @@ var useTextEditor = (props = {}, deps = []) => {
5582
5574
  createDataExtensions,
5583
5575
  createEditorAction,
5584
5576
  createEditorActionGroup,
5577
+ createEditorStateStore,
5585
5578
  createEditorStateTransaction,
5586
5579
  createElement,
5587
5580
  createExternalCommentSync,