@uiw/react-codemirror 4.11.4 → 4.12.0
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/README.md +61 -3
- package/cjs/index.d.ts +8 -1
- package/cjs/index.js +4 -2
- package/cjs/index.js.map +3 -2
- package/cjs/useCodeMirror.js +5 -4
- package/cjs/useCodeMirror.js.map +7 -2
- package/dist/mdeditor.js +191 -97
- package/dist/mdeditor.min.js +1 -1
- package/esm/index.d.ts +8 -1
- package/esm/index.js +5 -3
- package/esm/index.js.map +3 -2
- package/esm/useCodeMirror.js +5 -3
- package/esm/useCodeMirror.js.map +7 -2
- package/package.json +2 -2
- package/src/index.tsx +10 -1
- package/src/useCodeMirror.ts +6 -2
package/dist/mdeditor.js
CHANGED
|
@@ -612,6 +612,10 @@ class dist_Tree {
|
|
|
612
612
|
/// position. If 1, it'll move into nodes that start at the
|
|
613
613
|
/// position. With 0, it'll only enter nodes that cover the position
|
|
614
614
|
/// from both sides.
|
|
615
|
+
///
|
|
616
|
+
/// Note that this will not enter
|
|
617
|
+
/// [overlays](#common.MountedTree.overlay), and you often want
|
|
618
|
+
/// [`resolveInner`](#common.Tree.resolveInner) instead.
|
|
615
619
|
resolve(pos, side = 0) {
|
|
616
620
|
let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
|
|
617
621
|
CachedNode.set(this, node);
|
|
@@ -2094,14 +2098,14 @@ function enterFragments(mounts, ranges) {
|
|
|
2094
2098
|
for (let i = 0, pos = from;; i++) {
|
|
2095
2099
|
let last = i == changes.length, end = last ? to : changes[i].from;
|
|
2096
2100
|
if (end > pos)
|
|
2097
|
-
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos, frag.to <= end));
|
|
2101
|
+
result.push(new TreeFragment(pos, end, mount.tree, -startPos, frag.from >= pos || frag.openStart, frag.to <= end || frag.openEnd));
|
|
2098
2102
|
if (last)
|
|
2099
2103
|
break;
|
|
2100
2104
|
pos = changes[i].to;
|
|
2101
2105
|
}
|
|
2102
2106
|
}
|
|
2103
2107
|
else {
|
|
2104
|
-
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos, frag.to <= endPos));
|
|
2108
|
+
result.push(new TreeFragment(from, to, mount.tree, -startPos, frag.from >= startPos || frag.openStart, frag.to <= endPos || frag.openEnd));
|
|
2105
2109
|
}
|
|
2106
2110
|
}
|
|
2107
2111
|
return result;
|
|
@@ -3746,6 +3750,7 @@ function indentRange(state, from, to) {
|
|
|
3746
3750
|
let changes = [];
|
|
3747
3751
|
for (let pos = from; pos <= to;) {
|
|
3748
3752
|
let line = state.doc.lineAt(pos);
|
|
3753
|
+
pos = line.to + 1;
|
|
3749
3754
|
let indent = getIndentation(context, line.from);
|
|
3750
3755
|
if (indent == null)
|
|
3751
3756
|
continue;
|
|
@@ -3757,7 +3762,6 @@ function indentRange(state, from, to) {
|
|
|
3757
3762
|
updated[line.from] = indent;
|
|
3758
3763
|
changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
|
|
3759
3764
|
}
|
|
3760
|
-
pos = line.to + 1;
|
|
3761
3765
|
}
|
|
3762
3766
|
return state.changes(changes);
|
|
3763
3767
|
}
|
|
@@ -4717,13 +4721,13 @@ function matchMarkedBrackets(_state, _pos, dir, token, matching, brackets) {
|
|
|
4717
4721
|
depth++;
|
|
4718
4722
|
}
|
|
4719
4723
|
else if (matchingNodes(cursor.type, -dir, brackets)) {
|
|
4720
|
-
depth--;
|
|
4721
4724
|
if (depth == 0)
|
|
4722
4725
|
return {
|
|
4723
4726
|
start: firstToken,
|
|
4724
4727
|
end: cursor.from == cursor.to ? undefined : { from: cursor.from, to: cursor.to },
|
|
4725
4728
|
matched: false
|
|
4726
4729
|
};
|
|
4730
|
+
depth--;
|
|
4727
4731
|
}
|
|
4728
4732
|
}
|
|
4729
4733
|
} while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
|
|
@@ -6049,6 +6053,14 @@ end of the indentation instead of the start of the line.
|
|
|
6049
6053
|
*/
|
|
6050
6054
|
const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
|
|
6051
6055
|
/**
|
|
6056
|
+
Move the selection one line wrap point to the left.
|
|
6057
|
+
*/
|
|
6058
|
+
const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
6059
|
+
/**
|
|
6060
|
+
Move the selection one line wrap point to the right.
|
|
6061
|
+
*/
|
|
6062
|
+
const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
6063
|
+
/**
|
|
6052
6064
|
Move the selection to the start of the line.
|
|
6053
6065
|
*/
|
|
6054
6066
|
const cursorLineStart = view => moveSel(view, range => state_.EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
|
|
@@ -6183,6 +6195,14 @@ Move the selection head to the previous line boundary.
|
|
|
6183
6195
|
*/
|
|
6184
6196
|
const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
|
|
6185
6197
|
/**
|
|
6198
|
+
Move the selection head one line boundary to the left.
|
|
6199
|
+
*/
|
|
6200
|
+
const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
6201
|
+
/**
|
|
6202
|
+
Move the selection head one line boundary to the right.
|
|
6203
|
+
*/
|
|
6204
|
+
const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
6205
|
+
/**
|
|
6186
6206
|
Move the selection head to the start of the line.
|
|
6187
6207
|
*/
|
|
6188
6208
|
const selectLineStart = view => extendSel(view, range => state_.EditorSelection.cursor(view.lineBlockAt(range.head).from));
|
|
@@ -6751,11 +6771,11 @@ property changed to `mac`.)
|
|
|
6751
6771
|
*/
|
|
6752
6772
|
const standardKeymap = /*@__PURE__*/[
|
|
6753
6773
|
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
|
|
6754
|
-
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft },
|
|
6755
|
-
{ mac: "Cmd-ArrowLeft", run:
|
|
6774
|
+
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true },
|
|
6775
|
+
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true },
|
|
6756
6776
|
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
|
|
6757
|
-
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight },
|
|
6758
|
-
{ mac: "Cmd-ArrowRight", run:
|
|
6777
|
+
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true },
|
|
6778
|
+
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true },
|
|
6759
6779
|
{ key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
|
|
6760
6780
|
{ mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
|
|
6761
6781
|
{ mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
|
|
@@ -6883,7 +6903,8 @@ class SearchCursor {
|
|
|
6883
6903
|
[`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
|
|
6884
6904
|
(when supported).
|
|
6885
6905
|
*/
|
|
6886
|
-
constructor(text, query, from = 0, to = text.length, normalize) {
|
|
6906
|
+
constructor(text, query, from = 0, to = text.length, normalize, test) {
|
|
6907
|
+
this.test = test;
|
|
6887
6908
|
/**
|
|
6888
6909
|
The current match (only holds a meaningful value after
|
|
6889
6910
|
[`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when
|
|
@@ -6977,6 +6998,8 @@ class SearchCursor {
|
|
|
6977
6998
|
else
|
|
6978
6999
|
this.matches.push(1, pos);
|
|
6979
7000
|
}
|
|
7001
|
+
if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos))
|
|
7002
|
+
match = null;
|
|
6980
7003
|
return match;
|
|
6981
7004
|
}
|
|
6982
7005
|
}
|
|
@@ -6997,6 +7020,7 @@ class RegExpCursor {
|
|
|
6997
7020
|
`new RegExp`).
|
|
6998
7021
|
*/
|
|
6999
7022
|
constructor(text, query, options, from = 0, to = text.length) {
|
|
7023
|
+
this.text = text;
|
|
7000
7024
|
this.to = to;
|
|
7001
7025
|
this.curLine = "";
|
|
7002
7026
|
/**
|
|
@@ -7013,10 +7037,11 @@ class RegExpCursor {
|
|
|
7013
7037
|
if (/\\[sWDnr]|\n|\r|\[\^/.test(query))
|
|
7014
7038
|
return new MultilineRegExpCursor(text, query, options, from, to);
|
|
7015
7039
|
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
7040
|
+
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
7016
7041
|
this.iter = text.iter();
|
|
7017
7042
|
let startLine = text.lineAt(from);
|
|
7018
7043
|
this.curLineStart = startLine.from;
|
|
7019
|
-
this.matchPos = from;
|
|
7044
|
+
this.matchPos = toCharEnd(text, from);
|
|
7020
7045
|
this.getLine(this.curLineStart);
|
|
7021
7046
|
}
|
|
7022
7047
|
getLine(skip) {
|
|
@@ -7047,10 +7072,10 @@ class RegExpCursor {
|
|
|
7047
7072
|
let match = this.matchPos <= this.to && this.re.exec(this.curLine);
|
|
7048
7073
|
if (match) {
|
|
7049
7074
|
let from = this.curLineStart + match.index, to = from + match[0].length;
|
|
7050
|
-
this.matchPos = to + (from == to ? 1 : 0);
|
|
7075
|
+
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7051
7076
|
if (from == this.curLine.length)
|
|
7052
7077
|
this.nextLine();
|
|
7053
|
-
if (from < to || from > this.value.to) {
|
|
7078
|
+
if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) {
|
|
7054
7079
|
this.value = { from, to, match };
|
|
7055
7080
|
return this;
|
|
7056
7081
|
}
|
|
@@ -7101,8 +7126,9 @@ class MultilineRegExpCursor {
|
|
|
7101
7126
|
this.to = to;
|
|
7102
7127
|
this.done = false;
|
|
7103
7128
|
this.value = empty;
|
|
7104
|
-
this.matchPos = from;
|
|
7129
|
+
this.matchPos = toCharEnd(text, from);
|
|
7105
7130
|
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
7131
|
+
this.test = options === null || options === void 0 ? void 0 : options.test;
|
|
7106
7132
|
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Base */));
|
|
7107
7133
|
}
|
|
7108
7134
|
chunkEnd(pos) {
|
|
@@ -7117,24 +7143,23 @@ class MultilineRegExpCursor {
|
|
|
7117
7143
|
this.re.lastIndex = off + 1;
|
|
7118
7144
|
match = this.re.exec(this.flat.text);
|
|
7119
7145
|
}
|
|
7120
|
-
// If a match goes almost to the end of a noncomplete chunk, try
|
|
7121
|
-
// again, since it'll likely be able to match more
|
|
7122
|
-
if (match && this.flat.to < this.to && match.index + match[0].length > this.flat.text.length - 10)
|
|
7123
|
-
match = null;
|
|
7124
7146
|
if (match) {
|
|
7125
7147
|
let from = this.flat.from + match.index, to = from + match[0].length;
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
this.done = true;
|
|
7148
|
+
// If a match goes almost to the end of a noncomplete chunk, try
|
|
7149
|
+
// again, since it'll likely be able to match more
|
|
7150
|
+
if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) &&
|
|
7151
|
+
(!this.test || this.test(from, to, match))) {
|
|
7152
|
+
this.value = { from, to, match };
|
|
7153
|
+
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7133
7154
|
return this;
|
|
7134
7155
|
}
|
|
7135
|
-
// Grow the flattened doc
|
|
7136
|
-
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
|
|
7137
7156
|
}
|
|
7157
|
+
if (this.flat.to == this.to) {
|
|
7158
|
+
this.done = true;
|
|
7159
|
+
return this;
|
|
7160
|
+
}
|
|
7161
|
+
// Grow the flattened doc
|
|
7162
|
+
this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2));
|
|
7138
7163
|
}
|
|
7139
7164
|
}
|
|
7140
7165
|
}
|
|
@@ -7151,6 +7176,14 @@ function validRegExp(source) {
|
|
|
7151
7176
|
return false;
|
|
7152
7177
|
}
|
|
7153
7178
|
}
|
|
7179
|
+
function toCharEnd(text, pos) {
|
|
7180
|
+
if (pos >= text.length)
|
|
7181
|
+
return pos;
|
|
7182
|
+
let line = text.lineAt(pos), next;
|
|
7183
|
+
while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000)
|
|
7184
|
+
pos++;
|
|
7185
|
+
return pos;
|
|
7186
|
+
}
|
|
7154
7187
|
|
|
7155
7188
|
function createLineDialog(view) {
|
|
7156
7189
|
let input = crelt("input", { class: "cm-textfield", name: "line" });
|
|
@@ -7402,12 +7435,13 @@ const selectNextOccurrence = ({ state, dispatch }) => {
|
|
|
7402
7435
|
|
|
7403
7436
|
const searchConfigFacet = /*@__PURE__*/state_.Facet.define({
|
|
7404
7437
|
combine(configs) {
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7438
|
+
return (0,state_.combineConfig)(configs, {
|
|
7439
|
+
top: false,
|
|
7440
|
+
caseSensitive: false,
|
|
7441
|
+
literal: false,
|
|
7442
|
+
wholeWord: false,
|
|
7443
|
+
createPanel: view => new SearchPanel(view)
|
|
7444
|
+
});
|
|
7411
7445
|
}
|
|
7412
7446
|
});
|
|
7413
7447
|
/**
|
|
@@ -7429,17 +7463,20 @@ class SearchQuery {
|
|
|
7429
7463
|
constructor(config) {
|
|
7430
7464
|
this.search = config.search;
|
|
7431
7465
|
this.caseSensitive = !!config.caseSensitive;
|
|
7466
|
+
this.literal = !!config.literal;
|
|
7432
7467
|
this.regexp = !!config.regexp;
|
|
7433
7468
|
this.replace = config.replace || "";
|
|
7434
7469
|
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
|
|
7435
|
-
this.unquoted =
|
|
7470
|
+
this.unquoted = this.literal ? this.search : this.search.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\");
|
|
7471
|
+
this.wholeWord = !!config.wholeWord;
|
|
7436
7472
|
}
|
|
7437
7473
|
/**
|
|
7438
7474
|
Compare this query to another query.
|
|
7439
7475
|
*/
|
|
7440
7476
|
eq(other) {
|
|
7441
7477
|
return this.search == other.search && this.replace == other.replace &&
|
|
7442
|
-
this.caseSensitive == other.caseSensitive && this.regexp == other.regexp
|
|
7478
|
+
this.caseSensitive == other.caseSensitive && this.regexp == other.regexp &&
|
|
7479
|
+
this.wholeWord == other.wholeWord;
|
|
7443
7480
|
}
|
|
7444
7481
|
/**
|
|
7445
7482
|
@internal
|
|
@@ -7449,10 +7486,13 @@ class SearchQuery {
|
|
|
7449
7486
|
}
|
|
7450
7487
|
/**
|
|
7451
7488
|
Get a search cursor for this query, searching through the given
|
|
7452
|
-
range in the given
|
|
7489
|
+
range in the given state.
|
|
7453
7490
|
*/
|
|
7454
|
-
getCursor(
|
|
7455
|
-
|
|
7491
|
+
getCursor(state, from = 0, to) {
|
|
7492
|
+
let st = state.doc ? state : state_.EditorState.create({ doc: state });
|
|
7493
|
+
if (to == null)
|
|
7494
|
+
to = st.doc.length;
|
|
7495
|
+
return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to);
|
|
7456
7496
|
}
|
|
7457
7497
|
}
|
|
7458
7498
|
class QueryType {
|
|
@@ -7460,25 +7500,37 @@ class QueryType {
|
|
|
7460
7500
|
this.spec = spec;
|
|
7461
7501
|
}
|
|
7462
7502
|
}
|
|
7463
|
-
function stringCursor(spec,
|
|
7464
|
-
return new SearchCursor(doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase());
|
|
7503
|
+
function stringCursor(spec, state, from, to) {
|
|
7504
|
+
return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
|
|
7505
|
+
}
|
|
7506
|
+
function stringWordTest(doc, categorizer) {
|
|
7507
|
+
return (from, to, buf, bufPos) => {
|
|
7508
|
+
if (bufPos > from || bufPos + buf.length < to) {
|
|
7509
|
+
bufPos = Math.max(0, from - 2);
|
|
7510
|
+
buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2));
|
|
7511
|
+
}
|
|
7512
|
+
return categorizer(charAfter(buf, from - bufPos)) != state_.CharCategory.Word ||
|
|
7513
|
+
categorizer(charBefore(buf, to - bufPos)) != state_.CharCategory.Word ||
|
|
7514
|
+
(categorizer(charBefore(buf, from - bufPos)) != state_.CharCategory.Word &&
|
|
7515
|
+
categorizer(charAfter(buf, to - bufPos)) != state_.CharCategory.Word);
|
|
7516
|
+
};
|
|
7465
7517
|
}
|
|
7466
7518
|
class StringQuery extends QueryType {
|
|
7467
7519
|
constructor(spec) {
|
|
7468
7520
|
super(spec);
|
|
7469
7521
|
}
|
|
7470
|
-
nextMatch(
|
|
7471
|
-
let cursor = stringCursor(this.spec,
|
|
7522
|
+
nextMatch(state, curFrom, curTo) {
|
|
7523
|
+
let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
|
|
7472
7524
|
if (cursor.done)
|
|
7473
|
-
cursor = stringCursor(this.spec,
|
|
7525
|
+
cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
|
|
7474
7526
|
return cursor.done ? null : cursor.value;
|
|
7475
7527
|
}
|
|
7476
7528
|
// Searching in reverse is, rather than implementing inverted search
|
|
7477
7529
|
// cursor, done by scanning chunk after chunk forward.
|
|
7478
|
-
prevMatchInRange(
|
|
7530
|
+
prevMatchInRange(state, from, to) {
|
|
7479
7531
|
for (let pos = to;;) {
|
|
7480
7532
|
let start = Math.max(from, pos - 10000 /* ChunkSize */ - this.spec.unquoted.length);
|
|
7481
|
-
let cursor = stringCursor(this.spec,
|
|
7533
|
+
let cursor = stringCursor(this.spec, state, start, pos), range = null;
|
|
7482
7534
|
while (!cursor.nextOverlapping().done)
|
|
7483
7535
|
range = cursor.value;
|
|
7484
7536
|
if (range)
|
|
@@ -7488,13 +7540,13 @@ class StringQuery extends QueryType {
|
|
|
7488
7540
|
pos -= 10000 /* ChunkSize */;
|
|
7489
7541
|
}
|
|
7490
7542
|
}
|
|
7491
|
-
prevMatch(
|
|
7492
|
-
return this.prevMatchInRange(
|
|
7493
|
-
this.prevMatchInRange(
|
|
7543
|
+
prevMatch(state, curFrom, curTo) {
|
|
7544
|
+
return this.prevMatchInRange(state, 0, curFrom) ||
|
|
7545
|
+
this.prevMatchInRange(state, curTo, state.doc.length);
|
|
7494
7546
|
}
|
|
7495
7547
|
getReplacement(_result) { return this.spec.replace; }
|
|
7496
|
-
matchAll(
|
|
7497
|
-
let cursor = stringCursor(this.spec,
|
|
7548
|
+
matchAll(state, limit) {
|
|
7549
|
+
let cursor = stringCursor(this.spec, state, 0, state.doc.length), ranges = [];
|
|
7498
7550
|
while (!cursor.next().done) {
|
|
7499
7551
|
if (ranges.length >= limit)
|
|
7500
7552
|
return null;
|
|
@@ -7502,26 +7554,42 @@ class StringQuery extends QueryType {
|
|
|
7502
7554
|
}
|
|
7503
7555
|
return ranges;
|
|
7504
7556
|
}
|
|
7505
|
-
highlight(
|
|
7506
|
-
let cursor = stringCursor(this.spec,
|
|
7557
|
+
highlight(state, from, to, add) {
|
|
7558
|
+
let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length));
|
|
7507
7559
|
while (!cursor.next().done)
|
|
7508
7560
|
add(cursor.value.from, cursor.value.to);
|
|
7509
7561
|
}
|
|
7510
7562
|
}
|
|
7511
|
-
function regexpCursor(spec,
|
|
7512
|
-
return new RegExpCursor(doc, spec.search,
|
|
7563
|
+
function regexpCursor(spec, state, from, to) {
|
|
7564
|
+
return new RegExpCursor(state.doc, spec.search, {
|
|
7565
|
+
ignoreCase: !spec.caseSensitive,
|
|
7566
|
+
test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
|
|
7567
|
+
}, from, to);
|
|
7568
|
+
}
|
|
7569
|
+
function charBefore(str, index) {
|
|
7570
|
+
return str.slice((0,state_.findClusterBreak)(str, index, false), index);
|
|
7571
|
+
}
|
|
7572
|
+
function charAfter(str, index) {
|
|
7573
|
+
return str.slice(index, (0,state_.findClusterBreak)(str, index));
|
|
7574
|
+
}
|
|
7575
|
+
function regexpWordTest(categorizer) {
|
|
7576
|
+
return (_from, _to, match) => !match[0].length ||
|
|
7577
|
+
categorizer(charAfter(match.input, match.index)) != state_.CharCategory.Word ||
|
|
7578
|
+
categorizer(charBefore(match.input, match.index + match[0].length)) != state_.CharCategory.Word ||
|
|
7579
|
+
(categorizer(charBefore(match.input, match.index)) != state_.CharCategory.Word &&
|
|
7580
|
+
categorizer(charAfter(match.input, match.index + match[0].length)) != state_.CharCategory.Word);
|
|
7513
7581
|
}
|
|
7514
7582
|
class RegExpQuery extends QueryType {
|
|
7515
|
-
nextMatch(
|
|
7516
|
-
let cursor = regexpCursor(this.spec,
|
|
7583
|
+
nextMatch(state, curFrom, curTo) {
|
|
7584
|
+
let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next();
|
|
7517
7585
|
if (cursor.done)
|
|
7518
|
-
cursor = regexpCursor(this.spec,
|
|
7586
|
+
cursor = regexpCursor(this.spec, state, 0, curFrom).next();
|
|
7519
7587
|
return cursor.done ? null : cursor.value;
|
|
7520
7588
|
}
|
|
7521
|
-
prevMatchInRange(
|
|
7589
|
+
prevMatchInRange(state, from, to) {
|
|
7522
7590
|
for (let size = 1;; size++) {
|
|
7523
7591
|
let start = Math.max(from, to - size * 10000 /* ChunkSize */);
|
|
7524
|
-
let cursor = regexpCursor(this.spec,
|
|
7592
|
+
let cursor = regexpCursor(this.spec, state, start, to), range = null;
|
|
7525
7593
|
while (!cursor.next().done)
|
|
7526
7594
|
range = cursor.value;
|
|
7527
7595
|
if (range && (start == from || range.from > start + 10))
|
|
@@ -7530,9 +7598,9 @@ class RegExpQuery extends QueryType {
|
|
|
7530
7598
|
return null;
|
|
7531
7599
|
}
|
|
7532
7600
|
}
|
|
7533
|
-
prevMatch(
|
|
7534
|
-
return this.prevMatchInRange(
|
|
7535
|
-
this.prevMatchInRange(
|
|
7601
|
+
prevMatch(state, curFrom, curTo) {
|
|
7602
|
+
return this.prevMatchInRange(state, 0, curFrom) ||
|
|
7603
|
+
this.prevMatchInRange(state, curTo, state.doc.length);
|
|
7536
7604
|
}
|
|
7537
7605
|
getReplacement(result) {
|
|
7538
7606
|
return this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$"
|
|
@@ -7540,8 +7608,8 @@ class RegExpQuery extends QueryType {
|
|
|
7540
7608
|
: i != "0" && +i < result.match.length ? result.match[i]
|
|
7541
7609
|
: m);
|
|
7542
7610
|
}
|
|
7543
|
-
matchAll(
|
|
7544
|
-
let cursor = regexpCursor(this.spec,
|
|
7611
|
+
matchAll(state, limit) {
|
|
7612
|
+
let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = [];
|
|
7545
7613
|
while (!cursor.next().done) {
|
|
7546
7614
|
if (ranges.length >= limit)
|
|
7547
7615
|
return null;
|
|
@@ -7549,8 +7617,8 @@ class RegExpQuery extends QueryType {
|
|
|
7549
7617
|
}
|
|
7550
7618
|
return ranges;
|
|
7551
7619
|
}
|
|
7552
|
-
highlight(
|
|
7553
|
-
let cursor = regexpCursor(this.spec,
|
|
7620
|
+
highlight(state, from, to, add) {
|
|
7621
|
+
let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* HighlightMargin */), Math.min(to + 250 /* HighlightMargin */, state.doc.length));
|
|
7554
7622
|
while (!cursor.next().done)
|
|
7555
7623
|
add(cursor.value.from, cursor.value.to);
|
|
7556
7624
|
}
|
|
@@ -7586,6 +7654,13 @@ function getSearchQuery(state) {
|
|
|
7586
7654
|
let curState = state.field(searchState, false);
|
|
7587
7655
|
return curState ? curState.query.spec : defaultQuery(state);
|
|
7588
7656
|
}
|
|
7657
|
+
/**
|
|
7658
|
+
Query whether the search panel is open in the given editor state.
|
|
7659
|
+
*/
|
|
7660
|
+
function searchPanelOpen(state) {
|
|
7661
|
+
var _a;
|
|
7662
|
+
return ((_a = state.field(searchState, false)) === null || _a === void 0 ? void 0 : _a.panel) != null;
|
|
7663
|
+
}
|
|
7589
7664
|
class SearchState {
|
|
7590
7665
|
constructor(query, panel) {
|
|
7591
7666
|
this.query = query;
|
|
@@ -7612,7 +7687,7 @@ const searchHighlighter = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
|
|
|
7612
7687
|
let { from, to } = ranges[i];
|
|
7613
7688
|
while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* HighlightMargin */)
|
|
7614
7689
|
to = ranges[++i].to;
|
|
7615
|
-
query.highlight(view.state
|
|
7690
|
+
query.highlight(view.state, from, to, (from, to) => {
|
|
7616
7691
|
let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to);
|
|
7617
7692
|
builder.add(from, to, selected ? selectedMatchMark : matchMark);
|
|
7618
7693
|
});
|
|
@@ -7635,9 +7710,9 @@ Will wrap around to the start of the document when it reaches the
|
|
|
7635
7710
|
end.
|
|
7636
7711
|
*/
|
|
7637
7712
|
const findNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7638
|
-
let {
|
|
7639
|
-
let next = query.nextMatch(view.state
|
|
7640
|
-
if (!next
|
|
7713
|
+
let { to } = view.state.selection.main;
|
|
7714
|
+
let next = query.nextMatch(view.state, to, to);
|
|
7715
|
+
if (!next)
|
|
7641
7716
|
return false;
|
|
7642
7717
|
view.dispatch({
|
|
7643
7718
|
selection: { anchor: next.from, head: next.to },
|
|
@@ -7653,8 +7728,8 @@ before the current main selection. Will wrap past the start
|
|
|
7653
7728
|
of the document to start searching at the end again.
|
|
7654
7729
|
*/
|
|
7655
7730
|
const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7656
|
-
let { state } = view, { from
|
|
7657
|
-
let range = query.prevMatch(state
|
|
7731
|
+
let { state } = view, { from } = state.selection.main;
|
|
7732
|
+
let range = query.prevMatch(state, from, from);
|
|
7658
7733
|
if (!range)
|
|
7659
7734
|
return false;
|
|
7660
7735
|
view.dispatch({
|
|
@@ -7669,7 +7744,7 @@ const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7669
7744
|
Select all instances of the search query.
|
|
7670
7745
|
*/
|
|
7671
7746
|
const selectMatches = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7672
|
-
let ranges = query.matchAll(view.state
|
|
7747
|
+
let ranges = query.matchAll(view.state, 1000);
|
|
7673
7748
|
if (!ranges || !ranges.length)
|
|
7674
7749
|
return false;
|
|
7675
7750
|
view.dispatch({
|
|
@@ -7707,7 +7782,7 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7707
7782
|
let { state } = view, { from, to } = state.selection.main;
|
|
7708
7783
|
if (state.readOnly)
|
|
7709
7784
|
return false;
|
|
7710
|
-
let next = query.nextMatch(state
|
|
7785
|
+
let next = query.nextMatch(state, from, from);
|
|
7711
7786
|
if (!next)
|
|
7712
7787
|
return false;
|
|
7713
7788
|
let changes = [], selection, replacement;
|
|
@@ -7715,7 +7790,7 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
|
7715
7790
|
if (next.from == from && next.to == to) {
|
|
7716
7791
|
replacement = state.toText(query.getReplacement(next));
|
|
7717
7792
|
changes.push({ from: next.from, to: next.to, insert: replacement });
|
|
7718
|
-
next = query.nextMatch(state
|
|
7793
|
+
next = query.nextMatch(state, next.from, next.to);
|
|
7719
7794
|
announce.push(view_.EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
|
|
7720
7795
|
}
|
|
7721
7796
|
if (next) {
|
|
@@ -7738,7 +7813,7 @@ replacement.
|
|
|
7738
7813
|
const replaceAll = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7739
7814
|
if (view.state.readOnly)
|
|
7740
7815
|
return false;
|
|
7741
|
-
let changes = query.matchAll(view.state
|
|
7816
|
+
let changes = query.matchAll(view.state, 1e9).map(match => {
|
|
7742
7817
|
let { from, to } = match;
|
|
7743
7818
|
return { from, to, insert: query.getReplacement(match) };
|
|
7744
7819
|
});
|
|
@@ -7756,11 +7831,18 @@ function createSearchPanel(view) {
|
|
|
7756
7831
|
return view.state.facet(searchConfigFacet).createPanel(view);
|
|
7757
7832
|
}
|
|
7758
7833
|
function defaultQuery(state, fallback) {
|
|
7759
|
-
var _a;
|
|
7834
|
+
var _a, _b, _c, _d;
|
|
7760
7835
|
let sel = state.selection.main;
|
|
7761
7836
|
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
|
|
7762
|
-
|
|
7763
|
-
|
|
7837
|
+
if (fallback && !selText)
|
|
7838
|
+
return fallback;
|
|
7839
|
+
let config = state.facet(searchConfigFacet);
|
|
7840
|
+
return new SearchQuery({
|
|
7841
|
+
search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"),
|
|
7842
|
+
caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive,
|
|
7843
|
+
literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal,
|
|
7844
|
+
wholeWord: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _d !== void 0 ? _d : config.wholeWord
|
|
7845
|
+
});
|
|
7764
7846
|
}
|
|
7765
7847
|
/**
|
|
7766
7848
|
Make sure the search panel is open and focused.
|
|
@@ -7855,6 +7937,12 @@ class SearchPanel {
|
|
|
7855
7937
|
checked: query.regexp,
|
|
7856
7938
|
onchange: this.commit
|
|
7857
7939
|
});
|
|
7940
|
+
this.wordField = crelt("input", {
|
|
7941
|
+
type: "checkbox",
|
|
7942
|
+
name: "word",
|
|
7943
|
+
checked: query.wholeWord,
|
|
7944
|
+
onchange: this.commit
|
|
7945
|
+
});
|
|
7858
7946
|
function button(name, onclick, content) {
|
|
7859
7947
|
return crelt("button", { class: "cm-button", name, onclick, type: "button" }, content);
|
|
7860
7948
|
}
|
|
@@ -7865,6 +7953,7 @@ class SearchPanel {
|
|
|
7865
7953
|
button("select", () => selectMatches(view), [phrase(view, "all")]),
|
|
7866
7954
|
crelt("label", null, [this.caseField, phrase(view, "match case")]),
|
|
7867
7955
|
crelt("label", null, [this.reField, phrase(view, "regexp")]),
|
|
7956
|
+
crelt("label", null, [this.wordField, phrase(view, "by word")]),
|
|
7868
7957
|
...view.state.readOnly ? [] : [
|
|
7869
7958
|
crelt("br"),
|
|
7870
7959
|
this.replaceField,
|
|
@@ -7884,7 +7973,8 @@ class SearchPanel {
|
|
|
7884
7973
|
search: this.searchField.value,
|
|
7885
7974
|
caseSensitive: this.caseField.checked,
|
|
7886
7975
|
regexp: this.reField.checked,
|
|
7887
|
-
|
|
7976
|
+
wholeWord: this.wordField.checked,
|
|
7977
|
+
replace: this.replaceField.value,
|
|
7888
7978
|
});
|
|
7889
7979
|
if (!query.eq(this.query)) {
|
|
7890
7980
|
this.query = query;
|
|
@@ -7917,6 +8007,7 @@ class SearchPanel {
|
|
|
7917
8007
|
this.replaceField.value = query.replace;
|
|
7918
8008
|
this.caseField.checked = query.caseSensitive;
|
|
7919
8009
|
this.reField.checked = query.regexp;
|
|
8010
|
+
this.wordField.checked = query.wholeWord;
|
|
7920
8011
|
}
|
|
7921
8012
|
mount() {
|
|
7922
8013
|
this.searchField.select();
|
|
@@ -8306,6 +8397,7 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
8306
8397
|
combine(configs) {
|
|
8307
8398
|
return (0,state_.combineConfig)(configs, {
|
|
8308
8399
|
activateOnTyping: true,
|
|
8400
|
+
selectOnOpen: true,
|
|
8309
8401
|
override: null,
|
|
8310
8402
|
closeOnBlur: true,
|
|
8311
8403
|
maxRenderedOptions: 100,
|
|
@@ -8313,7 +8405,8 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
8313
8405
|
optionClass: () => "",
|
|
8314
8406
|
aboveCursor: false,
|
|
8315
8407
|
icons: true,
|
|
8316
|
-
addToOptions: []
|
|
8408
|
+
addToOptions: [],
|
|
8409
|
+
compareCompletions: (a, b) => a.label.localeCompare(b.label)
|
|
8317
8410
|
}, {
|
|
8318
8411
|
defaultKeymap: (a, b) => a && b,
|
|
8319
8412
|
closeOnBlur: (a, b) => a && b,
|
|
@@ -8376,6 +8469,8 @@ function optionContent(config) {
|
|
|
8376
8469
|
function rangeAroundSelected(total, selected, max) {
|
|
8377
8470
|
if (total <= max)
|
|
8378
8471
|
return { from: 0, to: total };
|
|
8472
|
+
if (selected < 0)
|
|
8473
|
+
selected = 0;
|
|
8379
8474
|
if (selected <= (total >> 1)) {
|
|
8380
8475
|
let off = Math.floor(selected / max);
|
|
8381
8476
|
return { from: off * max, to: (off + 1) * max };
|
|
@@ -8583,7 +8678,8 @@ function sortOptions(active, state) {
|
|
|
8583
8678
|
}
|
|
8584
8679
|
}
|
|
8585
8680
|
let result = [], prev = null;
|
|
8586
|
-
|
|
8681
|
+
let compare = state.facet(completionConfig).compareCompletions;
|
|
8682
|
+
for (let opt of options.sort((a, b) => (b.match[0] - a.match[0]) || compare(a.completion, b.completion))) {
|
|
8587
8683
|
if (!prev || prev.label != opt.completion.label || prev.detail != opt.completion.detail ||
|
|
8588
8684
|
(prev.type != null && opt.completion.type != null && prev.type != opt.completion.type) ||
|
|
8589
8685
|
prev.apply != opt.completion.apply)
|
|
@@ -8610,8 +8706,8 @@ class CompletionDialog {
|
|
|
8610
8706
|
let options = sortOptions(active, state);
|
|
8611
8707
|
if (!options.length)
|
|
8612
8708
|
return null;
|
|
8613
|
-
let selected = 0;
|
|
8614
|
-
if (prev && prev.selected) {
|
|
8709
|
+
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
|
|
8710
|
+
if (prev && prev.selected != selected && prev.selected != -1) {
|
|
8615
8711
|
let selectedValue = prev.options[prev.selected].completion;
|
|
8616
8712
|
for (let i = 0; i < options.length; i++)
|
|
8617
8713
|
if (options[i].completion == selectedValue) {
|
|
@@ -8681,20 +8777,16 @@ const baseAttrs = {
|
|
|
8681
8777
|
"aria-autocomplete": "list"
|
|
8682
8778
|
};
|
|
8683
8779
|
function makeAttrs(id, selected) {
|
|
8684
|
-
|
|
8780
|
+
let result = {
|
|
8685
8781
|
"aria-autocomplete": "list",
|
|
8686
8782
|
"aria-haspopup": "listbox",
|
|
8687
|
-
"aria-activedescendant": id + "-" + selected,
|
|
8688
8783
|
"aria-controls": id
|
|
8689
8784
|
};
|
|
8785
|
+
if (selected > -1)
|
|
8786
|
+
result["aria-activedescendant"] = id + "-" + selected;
|
|
8787
|
+
return result;
|
|
8690
8788
|
}
|
|
8691
8789
|
const dist_none = [];
|
|
8692
|
-
function cmpOption(a, b) {
|
|
8693
|
-
let dScore = b.match[0] - a.match[0];
|
|
8694
|
-
if (dScore)
|
|
8695
|
-
return dScore;
|
|
8696
|
-
return a.completion.label.localeCompare(b.completion.label);
|
|
8697
|
-
}
|
|
8698
8790
|
function getUserEvent(tr) {
|
|
8699
8791
|
return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
|
|
8700
8792
|
}
|
|
@@ -8802,7 +8894,8 @@ function moveCompletionSelection(forward, by = "option") {
|
|
|
8802
8894
|
if (by == "page" && (tooltip = (0,view_.getTooltip)(view, cState.open.tooltip)))
|
|
8803
8895
|
step = Math.max(2, Math.floor(tooltip.dom.offsetHeight /
|
|
8804
8896
|
tooltip.dom.querySelector("li").offsetHeight) - 1);
|
|
8805
|
-
let
|
|
8897
|
+
let { length } = cState.open.options;
|
|
8898
|
+
let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
|
|
8806
8899
|
if (selected < 0)
|
|
8807
8900
|
selected = by == "page" ? 0 : length - 1;
|
|
8808
8901
|
else if (selected >= length)
|
|
@@ -8816,7 +8909,8 @@ Accept the current completion.
|
|
|
8816
8909
|
*/
|
|
8817
8910
|
const acceptCompletion = (view) => {
|
|
8818
8911
|
let cState = view.state.field(completionState, false);
|
|
8819
|
-
if (view.state.readOnly || !cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin
|
|
8912
|
+
if (view.state.readOnly || !cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin ||
|
|
8913
|
+
cState.open.selected < 0)
|
|
8820
8914
|
return false;
|
|
8821
8915
|
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
8822
8916
|
return true;
|
|
@@ -9729,7 +9823,7 @@ Return the currently selected completion, if any.
|
|
|
9729
9823
|
function selectedCompletion(state) {
|
|
9730
9824
|
var _a;
|
|
9731
9825
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
9732
|
-
return open ? open.options[open.selected].completion : null;
|
|
9826
|
+
return open && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
9733
9827
|
}
|
|
9734
9828
|
/**
|
|
9735
9829
|
Returns the currently selected position in the active completion
|
|
@@ -9738,7 +9832,7 @@ list, or null if no completions are active.
|
|
|
9738
9832
|
function selectedCompletionIndex(state) {
|
|
9739
9833
|
var _a;
|
|
9740
9834
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
9741
|
-
return open ? open.selected : null;
|
|
9835
|
+
return open && open.selected >= 0 ? open.selected : null;
|
|
9742
9836
|
}
|
|
9743
9837
|
/**
|
|
9744
9838
|
Create an effect that can be attached to a transaction to change
|
|
@@ -10626,12 +10720,12 @@ var theme_one_dark_ = __webpack_require__(362);
|
|
|
10626
10720
|
;// CONCATENATED MODULE: ./src/utils.ts
|
|
10627
10721
|
var getStatistics=function getStatistics(view){return{line:view.state.doc.lineAt(view.state.selection.main.from),lineCount:view.state.doc.lines,lineBreak:view.state.lineBreak,length:view.state.doc.length,readOnly:view.state.readOnly,tabSize:view.state.tabSize,selection:view.state.selection,selectionAsSingle:view.state.selection.asSingle().main,ranges:view.state.selection.ranges,selectionCode:view.state.sliceDoc(view.state.selection.main.from,view.state.selection.main.to),selections:view.state.selection.ranges.map(function(r){return view.state.sliceDoc(r.from,r.to);}),selectedText:view.state.selection.ranges.some(function(r){return!r.empty;})};};
|
|
10628
10722
|
;// CONCATENATED MODULE: ./src/useCodeMirror.ts
|
|
10629
|
-
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'){var doc=vu.state.doc;var _value=doc.toString();onChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var getExtensions=[updateListener,defaultThemeOption];if(defaultIndentWithTab){getExtensions.unshift(view_.keymap.of([indentWithTab]));}if(defaultBasicSetup){if(typeof defaultBasicSetup==='boolean'){getExtensions.unshift(basicSetup());}else{getExtensions.unshift(basicSetup(defaultBasicSetup));}}if(placeholderStr){getExtensions.unshift((0,view_.placeholder)(placeholderStr));}switch(theme){case'light':getExtensions.push(defaultLightThemeOption);break;case'dark':getExtensions.push(theme_one_dark_.oneDark);break;default:getExtensions.push(theme);break;}if(editable===false){getExtensions.push(view_.EditorView.editable.of(false));}if(readOnly){getExtensions.push(state_.EditorState.readOnly.of(true));}if(onUpdate&&typeof onUpdate==='function'){getExtensions.push(view_.EditorView.updateListener.of(onUpdate));}getExtensions=getExtensions.concat(extensions);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(container&&!state){var
|
|
10723
|
+
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root,initialState=props.initialState;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'){var doc=vu.state.doc;var _value=doc.toString();onChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var getExtensions=[updateListener,defaultThemeOption];if(defaultIndentWithTab){getExtensions.unshift(view_.keymap.of([indentWithTab]));}if(defaultBasicSetup){if(typeof defaultBasicSetup==='boolean'){getExtensions.unshift(basicSetup());}else{getExtensions.unshift(basicSetup(defaultBasicSetup));}}if(placeholderStr){getExtensions.unshift((0,view_.placeholder)(placeholderStr));}switch(theme){case'light':getExtensions.push(defaultLightThemeOption);break;case'dark':getExtensions.push(theme_one_dark_.oneDark);break;default:getExtensions.push(theme);break;}if(editable===false){getExtensions.push(view_.EditorView.editable.of(false));}if(readOnly){getExtensions.push(state_.EditorState.readOnly.of(true));}if(onUpdate&&typeof onUpdate==='function'){getExtensions.push(view_.EditorView.updateListener.of(onUpdate));}getExtensions=getExtensions.concat(extensions);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(container&&!state){var config={doc:value,selection:selection,extensions:getExtensions};var stateCurrent=initialState?state_.EditorState.fromJSON(initialState.json,config,initialState.fields):state_.EditorState.create(config);setState(stateCurrent);if(!view){var viewCurrent=new view_.EditorView({state:stateCurrent,parent:container,root:root});setView(viewCurrent);onCreateEditor&&onCreateEditor(viewCurrent,stateCurrent);}}return function(){if(view){setState(undefined);setView(undefined);}};},[container,state]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return setContainer(props.container);},[props.container]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return function(){if(view){view.destroy();setView(undefined);}};},[view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(autoFocus&&view){view.focus();}},[autoFocus,view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(view){view.dispatch({effects:state_.StateEffect.reconfigure.of(getExtensions)});}// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10630
10724
|
},[theme,extensions,height,minHeight,maxHeight,width,minWidth,maxWidth,placeholderStr,editable,readOnly,defaultIndentWithTab,defaultBasicSetup,onChange,onUpdate]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){var currentValue=view?view.state.doc.toString():'';if(view&&value!==currentValue){view.dispatch({changes:{from:0,to:currentValue.length,insert:value||''}});}},[value,view]);return{state:state,setState:setState,view:view,setView:setView,container:container,setContainer:setContainer};}
|
|
10631
10725
|
// EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
|
|
10632
10726
|
var jsx_runtime = __webpack_require__(605);
|
|
10633
10727
|
;// CONCATENATED MODULE: ./src/index.tsx
|
|
10634
|
-
var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container,setContainer=_useCodeMirror.setContainer;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
|
|
10728
|
+
var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container,setContainer=_useCodeMirror.setContainer;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
|
|
10635
10729
|
if(typeof value!=='string'){throw new Error("value must be typeof string but got ".concat(typeof value));}var defaultClassNames=typeof theme==='string'?"cm-theme-".concat(theme):'cm-theme';return/*#__PURE__*/(0,jsx_runtime.jsx)("div",_objectSpread2({ref:editor,className:"".concat(defaultClassNames).concat(className?" ".concat(className):'')},other));});ReactCodeMirror.displayName='CodeMirror';/* harmony default export */ const src = (ReactCodeMirror);
|
|
10636
10730
|
})();
|
|
10637
10731
|
|