@uiw/react-codemirror 4.21.23 → 4.21.25
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/cjs/getDefaultExtensions.d.ts +2 -2
- package/cjs/index.d.ts +4 -4
- package/cjs/useCodeMirror.d.ts +3 -3
- package/cjs/utils.d.ts +2 -2
- package/dist/codemirror.js +77 -31
- package/dist/codemirror.min.js +1 -1
- package/esm/getDefaultExtensions.d.ts +2 -2
- package/esm/index.d.ts +4 -4
- package/esm/useCodeMirror.d.ts +3 -3
- package/esm/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/getDefaultExtensions.ts +2 -2
- package/src/index.tsx +4 -4
- package/src/useCodeMirror.ts +4 -4
- package/src/utils.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Extension } from '@codemirror/state';
|
|
2
|
-
import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
1
|
+
import { type Extension } from '@codemirror/state';
|
|
2
|
+
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
3
3
|
export * from '@codemirror/theme-one-dark';
|
|
4
4
|
export * from './theme/light';
|
|
5
5
|
export interface DefaultExtensionsOptions {
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';
|
|
3
|
-
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
|
-
import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
5
|
-
import { Statistics } from './utils';
|
|
2
|
+
import type { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';
|
|
3
|
+
import type { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
|
+
import { type BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
5
|
+
import { type Statistics } from './utils';
|
|
6
6
|
export * from '@codemirror/view';
|
|
7
7
|
export * from '@codemirror/state';
|
|
8
8
|
export * from '@uiw/codemirror-extensions-basic-setup';
|
package/cjs/useCodeMirror.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EditorState } from '@codemirror/state';
|
|
2
2
|
import { EditorView } from '@codemirror/view';
|
|
3
|
-
import { ReactCodeMirrorProps } from '.';
|
|
3
|
+
import { type ReactCodeMirrorProps } from '.';
|
|
4
4
|
export interface UseCodeMirror extends ReactCodeMirrorProps {
|
|
5
5
|
container?: HTMLDivElement | null;
|
|
6
6
|
}
|
|
@@ -9,6 +9,6 @@ export declare function useCodeMirror(props: UseCodeMirror): {
|
|
|
9
9
|
setState: import("react").Dispatch<import("react").SetStateAction<EditorState | undefined>>;
|
|
10
10
|
view: EditorView | undefined;
|
|
11
11
|
setView: import("react").Dispatch<import("react").SetStateAction<EditorView | undefined>>;
|
|
12
|
-
container: HTMLDivElement | undefined;
|
|
13
|
-
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | undefined>>;
|
|
12
|
+
container: HTMLDivElement | null | undefined;
|
|
13
|
+
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null | undefined>>;
|
|
14
14
|
};
|
package/cjs/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EditorSelection, SelectionRange, Line } from '@codemirror/state';
|
|
2
|
-
import { ViewUpdate } from '@codemirror/view';
|
|
1
|
+
import type { EditorSelection, SelectionRange, Line } from '@codemirror/state';
|
|
2
|
+
import type { ViewUpdate } from '@codemirror/view';
|
|
3
3
|
export interface Statistics {
|
|
4
4
|
/** total length of the document */
|
|
5
5
|
length: number;
|
package/dist/codemirror.js
CHANGED
|
@@ -1496,7 +1496,7 @@ class FuzzyMatcher {
|
|
|
1496
1496
|
ret(score, matched) {
|
|
1497
1497
|
this.score = score;
|
|
1498
1498
|
this.matched = matched;
|
|
1499
|
-
return
|
|
1499
|
+
return this;
|
|
1500
1500
|
}
|
|
1501
1501
|
// Matches a given word (completion) against the pattern (input).
|
|
1502
1502
|
// Will return a boolean indicating whether there was a match and,
|
|
@@ -1509,7 +1509,7 @@ class FuzzyMatcher {
|
|
|
1509
1509
|
if (this.pattern.length == 0)
|
|
1510
1510
|
return this.ret(-100 /* Penalty.NotFull */, []);
|
|
1511
1511
|
if (word.length < this.pattern.length)
|
|
1512
|
-
return
|
|
1512
|
+
return null;
|
|
1513
1513
|
let { chars, folded, any, precise, byWord } = this;
|
|
1514
1514
|
// For single-character queries, only match when they occur right
|
|
1515
1515
|
// at the start
|
|
@@ -1520,7 +1520,7 @@ class FuzzyMatcher {
|
|
|
1520
1520
|
else if (first == folded[0])
|
|
1521
1521
|
score += -200 /* Penalty.CaseFold */;
|
|
1522
1522
|
else
|
|
1523
|
-
return
|
|
1523
|
+
return null;
|
|
1524
1524
|
return this.ret(score, [0, firstSize]);
|
|
1525
1525
|
}
|
|
1526
1526
|
let direct = word.indexOf(this.pattern);
|
|
@@ -1536,7 +1536,7 @@ class FuzzyMatcher {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
// No match, exit immediately
|
|
1538
1538
|
if (anyTo < len)
|
|
1539
|
-
return
|
|
1539
|
+
return null;
|
|
1540
1540
|
}
|
|
1541
1541
|
// This tracks the extent of the precise (non-folded, not
|
|
1542
1542
|
// necessarily adjacent) match
|
|
@@ -1589,7 +1589,7 @@ class FuzzyMatcher {
|
|
|
1589
1589
|
if (byWordTo == len)
|
|
1590
1590
|
return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0) + -700 /* Penalty.NotStart */ +
|
|
1591
1591
|
(wordAdjacent ? 0 : -1100 /* Penalty.Gap */), byWord, word);
|
|
1592
|
-
return chars.length == 2 ?
|
|
1592
|
+
return chars.length == 2 ? null
|
|
1593
1593
|
: this.result((any[0] ? -700 /* Penalty.NotStart */ : 0) + -200 /* Penalty.CaseFold */ + -1100 /* Penalty.Gap */, any, word);
|
|
1594
1594
|
}
|
|
1595
1595
|
result(score, positions, word) {
|
|
@@ -1606,6 +1606,25 @@ class FuzzyMatcher {
|
|
|
1606
1606
|
return this.ret(score - word.length, result);
|
|
1607
1607
|
}
|
|
1608
1608
|
}
|
|
1609
|
+
class StrictMatcher {
|
|
1610
|
+
constructor(pattern) {
|
|
1611
|
+
this.pattern = pattern;
|
|
1612
|
+
this.matched = [];
|
|
1613
|
+
this.score = 0;
|
|
1614
|
+
this.folded = pattern.toLowerCase();
|
|
1615
|
+
}
|
|
1616
|
+
match(word) {
|
|
1617
|
+
if (word.length < this.pattern.length)
|
|
1618
|
+
return null;
|
|
1619
|
+
let start = word.slice(0, this.pattern.length);
|
|
1620
|
+
let match = start == this.pattern ? 0 : start.toLowerCase() == this.folded ? -200 /* Penalty.CaseFold */ : null;
|
|
1621
|
+
if (match == null)
|
|
1622
|
+
return null;
|
|
1623
|
+
this.matched = [0, start.length];
|
|
1624
|
+
this.score = match + (word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */);
|
|
1625
|
+
return this;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1609
1628
|
|
|
1610
1629
|
const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
1611
1630
|
combine(configs) {
|
|
@@ -1623,6 +1642,7 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
1623
1642
|
icons: true,
|
|
1624
1643
|
addToOptions: [],
|
|
1625
1644
|
positionInfo: defaultPositionInfo,
|
|
1645
|
+
filterStrict: false,
|
|
1626
1646
|
compareCompletions: (a, b) => a.label.localeCompare(b.label),
|
|
1627
1647
|
interactionDelay: 75,
|
|
1628
1648
|
updateSyncTime: 100
|
|
@@ -1632,7 +1652,8 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
1632
1652
|
icons: (a, b) => a && b,
|
|
1633
1653
|
tooltipClass: (a, b) => c => joinClass(a(c), b(c)),
|
|
1634
1654
|
optionClass: (a, b) => c => joinClass(a(c), b(c)),
|
|
1635
|
-
addToOptions: (a, b) => a.concat(b)
|
|
1655
|
+
addToOptions: (a, b) => a.concat(b),
|
|
1656
|
+
filterStrict: (a, b) => a || b,
|
|
1636
1657
|
});
|
|
1637
1658
|
}
|
|
1638
1659
|
});
|
|
@@ -1992,6 +2013,7 @@ function sortOptions(active, state) {
|
|
|
1992
2013
|
sections.push(typeof section == "string" ? { name } : section);
|
|
1993
2014
|
}
|
|
1994
2015
|
};
|
|
2016
|
+
let conf = state.facet(completionConfig);
|
|
1995
2017
|
for (let a of active)
|
|
1996
2018
|
if (a.hasResult()) {
|
|
1997
2019
|
let getMatch = a.result.getMatch;
|
|
@@ -2001,11 +2023,12 @@ function sortOptions(active, state) {
|
|
|
2001
2023
|
}
|
|
2002
2024
|
}
|
|
2003
2025
|
else {
|
|
2004
|
-
let
|
|
2026
|
+
let pattern = state.sliceDoc(a.from, a.to), match;
|
|
2027
|
+
let matcher = conf.filterStrict ? new StrictMatcher(pattern) : new FuzzyMatcher(pattern);
|
|
2005
2028
|
for (let option of a.result.options)
|
|
2006
|
-
if (matcher.match(option.label)) {
|
|
2007
|
-
let matched = !option.displayLabel ?
|
|
2008
|
-
addOption(new Option(option, a.source, matched,
|
|
2029
|
+
if (match = matcher.match(option.label)) {
|
|
2030
|
+
let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : [];
|
|
2031
|
+
addOption(new Option(option, a.source, matched, match.score + (option.boost || 0)));
|
|
2009
2032
|
}
|
|
2010
2033
|
}
|
|
2011
2034
|
}
|
|
@@ -2023,7 +2046,7 @@ function sortOptions(active, state) {
|
|
|
2023
2046
|
}
|
|
2024
2047
|
}
|
|
2025
2048
|
let result = [], prev = null;
|
|
2026
|
-
let compare =
|
|
2049
|
+
let compare = conf.compareCompletions;
|
|
2027
2050
|
for (let opt of options.sort((a, b) => (b.score - a.score) || compare(a.completion, b.completion))) {
|
|
2028
2051
|
let cur = opt.completion;
|
|
2029
2052
|
if (!prev || prev.label != cur.label || prev.detail != cur.detail ||
|
|
@@ -2191,26 +2214,33 @@ class ActiveResult extends ActiveSource {
|
|
|
2191
2214
|
hasResult() { return true; }
|
|
2192
2215
|
handleUserEvent(tr, type, conf) {
|
|
2193
2216
|
var _a;
|
|
2217
|
+
let result = this.result;
|
|
2218
|
+
if (result.map && !tr.changes.empty)
|
|
2219
|
+
result = result.map(result, tr.changes);
|
|
2194
2220
|
let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
|
|
2195
2221
|
let pos = cur(tr.state);
|
|
2196
2222
|
if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
|
|
2197
|
-
pos > to ||
|
|
2223
|
+
pos > to || !result ||
|
|
2198
2224
|
type == "delete" && cur(tr.startState) == this.from)
|
|
2199
2225
|
return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */);
|
|
2200
|
-
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos)
|
|
2201
|
-
if (checkValid(
|
|
2202
|
-
return new ActiveResult(this.source, explicitPos,
|
|
2203
|
-
if (
|
|
2204
|
-
(
|
|
2205
|
-
return new ActiveResult(this.source, explicitPos,
|
|
2226
|
+
let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
|
|
2227
|
+
if (checkValid(result.validFor, tr.state, from, to))
|
|
2228
|
+
return new ActiveResult(this.source, explicitPos, result, from, to);
|
|
2229
|
+
if (result.update &&
|
|
2230
|
+
(result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
|
|
2231
|
+
return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
|
|
2206
2232
|
return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
|
|
2207
2233
|
}
|
|
2208
2234
|
handleChange(tr) {
|
|
2209
2235
|
return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
|
|
2210
2236
|
}
|
|
2211
2237
|
map(mapping) {
|
|
2212
|
-
|
|
2213
|
-
|
|
2238
|
+
if (mapping.empty)
|
|
2239
|
+
return this;
|
|
2240
|
+
let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
|
|
2241
|
+
if (!result)
|
|
2242
|
+
return new ActiveSource(this.source, 0 /* State.Inactive */);
|
|
2243
|
+
return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
|
|
2214
2244
|
}
|
|
2215
2245
|
}
|
|
2216
2246
|
function checkValid(validFor, state, from, to) {
|
|
@@ -2461,6 +2491,21 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
|
|
|
2461
2491
|
}
|
|
2462
2492
|
}
|
|
2463
2493
|
});
|
|
2494
|
+
const windows = typeof navigator == "object" && /*@__PURE__*//Win/.test(navigator.platform);
|
|
2495
|
+
const commitCharacters = /*@__PURE__*/state_.Prec.highest(/*@__PURE__*/view_.EditorView.domEventHandlers({
|
|
2496
|
+
keydown(event, view) {
|
|
2497
|
+
let field = view.state.field(completionState, false);
|
|
2498
|
+
if (!field || !field.open || field.open.disabled || field.open.selected < 0 ||
|
|
2499
|
+
event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey)
|
|
2500
|
+
return false;
|
|
2501
|
+
let option = field.open.options[field.open.selected];
|
|
2502
|
+
let result = field.active.find(a => a.source == option.source);
|
|
2503
|
+
let commitChars = option.completion.commitCharacters || result.result.commitCharacters;
|
|
2504
|
+
if (commitChars && commitChars.indexOf(event.key) > -1)
|
|
2505
|
+
applyCompletion(view, option);
|
|
2506
|
+
return false;
|
|
2507
|
+
}
|
|
2508
|
+
}));
|
|
2464
2509
|
|
|
2465
2510
|
const dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
|
|
2466
2511
|
".cm-tooltip.cm-tooltip-autocomplete": {
|
|
@@ -3182,6 +3227,7 @@ Returns an extension that enables autocompletion.
|
|
|
3182
3227
|
*/
|
|
3183
3228
|
function autocompletion(config = {}) {
|
|
3184
3229
|
return [
|
|
3230
|
+
commitCharacters,
|
|
3185
3231
|
completionState,
|
|
3186
3232
|
completionConfig.of(config),
|
|
3187
3233
|
completionPlugin,
|
|
@@ -4432,7 +4478,7 @@ function toPrimitive(t, r) {
|
|
|
4432
4478
|
|
|
4433
4479
|
function toPropertyKey(t) {
|
|
4434
4480
|
var i = toPrimitive(t, "string");
|
|
4435
|
-
return "symbol" == _typeof(i) ? i :
|
|
4481
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
4436
4482
|
}
|
|
4437
4483
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
4438
4484
|
|
|
@@ -7167,7 +7213,7 @@ class StyleModule {
|
|
|
7167
7213
|
let set = root[SET], nonce = options && options.nonce
|
|
7168
7214
|
if (!set) set = new StyleSet(root, nonce)
|
|
7169
7215
|
else if (nonce) set.setNonce(nonce)
|
|
7170
|
-
set.mount(Array.isArray(modules) ? modules : [modules])
|
|
7216
|
+
set.mount(Array.isArray(modules) ? modules : [modules], root)
|
|
7171
7217
|
}
|
|
7172
7218
|
}
|
|
7173
7219
|
|
|
@@ -7178,24 +7224,18 @@ class StyleSet {
|
|
|
7178
7224
|
let doc = root.ownerDocument || root, win = doc.defaultView
|
|
7179
7225
|
if (!root.head && root.adoptedStyleSheets && win.CSSStyleSheet) {
|
|
7180
7226
|
let adopted = adoptedSet.get(doc)
|
|
7181
|
-
if (adopted)
|
|
7182
|
-
root.adoptedStyleSheets = [adopted.sheet, ...root.adoptedStyleSheets]
|
|
7183
|
-
return root[SET] = adopted
|
|
7184
|
-
}
|
|
7227
|
+
if (adopted) return root[SET] = adopted
|
|
7185
7228
|
this.sheet = new win.CSSStyleSheet
|
|
7186
|
-
root.adoptedStyleSheets = [this.sheet, ...root.adoptedStyleSheets]
|
|
7187
7229
|
adoptedSet.set(doc, this)
|
|
7188
7230
|
} else {
|
|
7189
7231
|
this.styleTag = doc.createElement("style")
|
|
7190
7232
|
if (nonce) this.styleTag.setAttribute("nonce", nonce)
|
|
7191
|
-
let target = root.head || root
|
|
7192
|
-
target.insertBefore(this.styleTag, target.firstChild)
|
|
7193
7233
|
}
|
|
7194
7234
|
this.modules = []
|
|
7195
7235
|
root[SET] = this
|
|
7196
7236
|
}
|
|
7197
7237
|
|
|
7198
|
-
mount(modules) {
|
|
7238
|
+
mount(modules, root) {
|
|
7199
7239
|
let sheet = this.sheet
|
|
7200
7240
|
let pos = 0 /* Current rule offset */, j = 0 /* Index into this.modules */
|
|
7201
7241
|
for (let i = 0; i < modules.length; i++) {
|
|
@@ -7216,11 +7256,17 @@ class StyleSet {
|
|
|
7216
7256
|
}
|
|
7217
7257
|
}
|
|
7218
7258
|
|
|
7219
|
-
if (
|
|
7259
|
+
if (sheet) {
|
|
7260
|
+
if (root.adoptedStyleSheets.indexOf(this.sheet) < 0)
|
|
7261
|
+
root.adoptedStyleSheets = [this.sheet, ...root.adoptedStyleSheets]
|
|
7262
|
+
} else {
|
|
7220
7263
|
let text = ""
|
|
7221
7264
|
for (let i = 0; i < this.modules.length; i++)
|
|
7222
7265
|
text += this.modules[i].getRules() + "\n"
|
|
7223
7266
|
this.styleTag.textContent = text
|
|
7267
|
+
let target = root.head || root
|
|
7268
|
+
if (this.styleTag.parentNode != target)
|
|
7269
|
+
target.insertBefore(this.styleTag, target.firstChild)
|
|
7224
7270
|
}
|
|
7225
7271
|
}
|
|
7226
7272
|
|