@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.
- package/dist/lib/browser/index.mjs +53 -62
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/extensions/tasklist.d.ts +5 -1
- package/dist/types/src/extensions/tasklist.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/extensions/tasklist.ts +51 -75
- package/src/extensions/yjs/yjs.test.ts +1 -1
- package/src/themes/default.ts +0 -8
|
@@ -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 {
|
|
2029
|
-
|
|
2030
|
-
|
|
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
|
|
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
|
|
2037
|
+
return this._checked === other._checked;
|
|
2044
2038
|
}
|
|
2045
2039
|
toDOM(view) {
|
|
2046
|
-
const
|
|
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 (
|
|
2043
|
+
if (view.state.readOnly) {
|
|
2054
2044
|
input.setAttribute("disabled", "true");
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
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
|
|
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
|
-
|
|
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.
|
|
2076
|
+
this.decorations = buildDecorations3(view);
|
|
2095
2077
|
}
|
|
2096
2078
|
update(update2) {
|
|
2097
|
-
|
|
2079
|
+
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
2080
|
+
this.decorations = buildDecorations3(update2.view);
|
|
2081
|
+
}
|
|
2098
2082
|
}
|
|
2099
2083
|
}, {
|
|
2100
|
-
decorations: (
|
|
2084
|
+
decorations: (v) => v.decorations,
|
|
2101
2085
|
provide: (plugin) => EditorView11.atomicRanges.of((view) => {
|
|
2102
|
-
return view.plugin(plugin)?.
|
|
2086
|
+
return view.plugin(plugin)?.decorations || Decoration8.none;
|
|
2103
2087
|
})
|
|
2104
2088
|
});
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
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 *": {
|