@dxos/react-ui-editor 0.3.11-main.67451e9 → 0.3.11-main.68db74e

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.
@@ -2025,87 +2025,85 @@ var TableWidget = class extends WidgetType5 {
2025
2025
  };
2026
2026
 
2027
2027
  // packages/ui/react-ui-editor/src/extensions/tasklist.ts
2028
- import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType6, MatchDecorator as MatchDecorator2, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
2029
- var styles5 = EditorView11.baseTheme({
2030
- "& .cm-task-item": {
2031
- paddingLeft: "4px",
2032
- paddingRight: "8px"
2033
- }
2034
- });
2028
+ import { syntaxTree as syntaxTree4 } from "@codemirror/language";
2029
+ import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
2030
+ import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType6, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
2035
2031
  var CheckboxWidget = class extends WidgetType6 {
2036
- constructor(_checked, _indent, _onCheck) {
2032
+ constructor(_checked) {
2037
2033
  super();
2038
2034
  this._checked = _checked;
2039
- this._indent = _indent;
2040
- this._onCheck = _onCheck;
2041
2035
  }
2042
2036
  eq(other) {
2043
- return this._checked === other._checked && this._indent === other._indent;
2037
+ return this._checked === other._checked;
2044
2038
  }
2045
2039
  toDOM(view) {
2046
- const wrap = document.createElement("span");
2047
- wrap.className = "cm-task-item";
2048
- wrap.setAttribute("aria-hidden", "true");
2049
- wrap.style.setProperty("margin-left", this._indent * 24 + "px");
2050
- const input = wrap.appendChild(document.createElement("input"));
2040
+ const input = document.createElement("input");
2051
2041
  input.type = "checkbox";
2052
2042
  input.checked = this._checked;
2053
- if (!this._onCheck) {
2043
+ if (view.state.readOnly) {
2054
2044
  input.setAttribute("disabled", "true");
2055
- }
2056
- if (this._onCheck) {
2057
- input.onchange = (event) => {
2058
- this._onCheck?.(event.target.checked);
2059
- return true;
2045
+ } else {
2046
+ input.onmousedown = (event) => {
2047
+ const pos = view.posAtDOM(input);
2048
+ const text = view.state.sliceDoc(pos, pos + 3);
2049
+ if (text === (this._checked ? "[x]" : "[ ]")) {
2050
+ view.dispatch({
2051
+ changes: {
2052
+ from: pos + 1,
2053
+ to: pos + 2,
2054
+ insert: this._checked ? " " : "x"
2055
+ }
2056
+ });
2057
+ event.preventDefault();
2058
+ }
2060
2059
  };
2061
2060
  }
2062
- return wrap;
2061
+ return input;
2063
2062
  }
2064
2063
  ignoreEvent() {
2065
2064
  return false;
2066
2065
  }
2067
2066
  };
2067
+ var checkedDeco = Decoration8.replace({
2068
+ widget: new CheckboxWidget(true)
2069
+ });
2070
+ var uncheckedDeco = Decoration8.replace({
2071
+ widget: new CheckboxWidget(false)
2072
+ });
2068
2073
  var tasklist = (options = {}) => {
2069
- const taskMatcher = new MatchDecorator2({
2070
- regexp: /^(\s*)- \[([ xX])\]\s/g,
2071
- decoration: (match, view, pos) => {
2072
- const indent = Math.floor(match[1].length / 2);
2073
- const checked = match[2] === "x" || match[2] === "X";
2074
- return Decoration8.replace({
2075
- widget: new CheckboxWidget(checked, indent, view.state.readOnly ? void 0 : (checked2) => {
2076
- const idx = pos + match[0].indexOf("[") + 1;
2077
- view.dispatch({
2078
- changes: {
2079
- from: idx,
2080
- to: idx + 1,
2081
- insert: checked2 ? "x" : " "
2082
- },
2083
- // TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
2084
- selection: {
2085
- anchor: idx + 3
2086
- }
2087
- });
2088
- })
2089
- });
2090
- }
2091
- });
2092
- const tasks = ViewPlugin6.fromClass(class {
2074
+ return ViewPlugin6.fromClass(class {
2093
2075
  constructor(view) {
2094
- this.tasks = taskMatcher.createDeco(view);
2076
+ this.decorations = buildDecorations3(view);
2095
2077
  }
2096
2078
  update(update2) {
2097
- this.tasks = taskMatcher.updateDeco(update2, this.tasks);
2079
+ if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
2080
+ this.decorations = buildDecorations3(update2.view);
2081
+ }
2098
2082
  }
2099
2083
  }, {
2100
- decorations: (value) => value.tasks,
2084
+ decorations: (v) => v.decorations,
2101
2085
  provide: (plugin) => EditorView11.atomicRanges.of((view) => {
2102
- return view.plugin(plugin)?.tasks || Decoration8.none;
2086
+ return view.plugin(plugin)?.decorations || Decoration8.none;
2103
2087
  })
2104
2088
  });
2105
- return [
2106
- tasks,
2107
- styles5
2108
- ];
2089
+ };
2090
+ var buildDecorations3 = (view) => {
2091
+ const builder = new RangeSetBuilder3();
2092
+ const { state } = view;
2093
+ const cursor = state.selection.main.head;
2094
+ for (const { from, to } of view.visibleRanges) {
2095
+ syntaxTree4(state).iterate({
2096
+ enter: (node) => {
2097
+ if (node.name === "TaskMarker" && (cursor < node.from || cursor > node.to)) {
2098
+ const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
2099
+ builder.add(node.from, node.to, checked ? checkedDeco : uncheckedDeco);
2100
+ }
2101
+ },
2102
+ from,
2103
+ to
2104
+ });
2105
+ }
2106
+ return builder.finish();
2109
2107
  };
2110
2108
 
2111
2109
  // packages/ui/react-ui-editor/src/extensions/typewriter.ts
@@ -2315,13 +2313,6 @@ var defaultTheme = {
2315
2313
  textDecoration: "none"
2316
2314
  },
2317
2315
  //
2318
- // widgets
2319
- //
2320
- ".cm-widgetBuffer": {
2321
- display: "none",
2322
- height: 0
2323
- },
2324
- //
2325
2316
  // table
2326
2317
  //
2327
2318
  ".cm-table *": {