@codemirror/view 6.9.0 → 6.9.1
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/CHANGELOG.md +8 -0
- package/dist/index.cjs +56 -21
- package/dist/index.js +57 -22
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 6.9.1 (2023-02-17)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Improve the way `posAtCoords` picks the side of a widget to return by comparing the coordinates the center of the widget.
|
|
6
|
+
|
|
7
|
+
Fix an issue where transactions created for the `focusChangeEffect` facet were sometimes not dispatched.
|
|
8
|
+
|
|
1
9
|
## 6.9.0 (2023-02-15)
|
|
2
10
|
|
|
3
11
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -519,6 +519,7 @@ class ContentView {
|
|
|
519
519
|
}
|
|
520
520
|
static get(node) { return node.cmView; }
|
|
521
521
|
get isEditable() { return true; }
|
|
522
|
+
get isWidget() { return false; }
|
|
522
523
|
merge(from, to, source, hasStart, openStart, openEnd) {
|
|
523
524
|
return false;
|
|
524
525
|
}
|
|
@@ -893,6 +894,7 @@ class WidgetView extends ContentView {
|
|
|
893
894
|
return this.length ? rect : flattenRect(rect, this.side > 0);
|
|
894
895
|
}
|
|
895
896
|
get isEditable() { return false; }
|
|
897
|
+
get isWidget() { return true; }
|
|
896
898
|
destroy() {
|
|
897
899
|
super.destroy();
|
|
898
900
|
if (this.dom)
|
|
@@ -1603,6 +1605,8 @@ class BlockWidgetView extends ContentView {
|
|
|
1603
1605
|
}
|
|
1604
1606
|
ignoreMutation() { return true; }
|
|
1605
1607
|
ignoreEvent(event) { return this.widget.ignoreEvent(event); }
|
|
1608
|
+
get isEditable() { return false; }
|
|
1609
|
+
get isWidget() { return true; }
|
|
1606
1610
|
destroy() {
|
|
1607
1611
|
super.destroy();
|
|
1608
1612
|
if (this.dom)
|
|
@@ -2027,11 +2031,6 @@ class ViewUpdate {
|
|
|
2027
2031
|
let changedRanges = [];
|
|
2028
2032
|
this.changes.iterChangedRanges((fromA, toA, fromB, toB) => changedRanges.push(new ChangedRange(fromA, toA, fromB, toB)));
|
|
2029
2033
|
this.changedRanges = changedRanges;
|
|
2030
|
-
let focus = view.hasFocus;
|
|
2031
|
-
if (focus != view.inputState.notifiedFocused) {
|
|
2032
|
-
view.inputState.notifiedFocused = focus;
|
|
2033
|
-
this.flags |= 1 /* UpdateFlag.Focus */;
|
|
2034
|
-
}
|
|
2035
2034
|
}
|
|
2036
2035
|
/**
|
|
2037
2036
|
@internal
|
|
@@ -3167,11 +3166,11 @@ function domPosInText(node, x, y) {
|
|
|
3167
3166
|
}
|
|
3168
3167
|
return { node, offset: closestOffset > -1 ? closestOffset : generalSide > 0 ? node.nodeValue.length : 0 };
|
|
3169
3168
|
}
|
|
3170
|
-
function posAtCoords(view,
|
|
3169
|
+
function posAtCoords(view, coords, precise, bias = -1) {
|
|
3171
3170
|
var _a;
|
|
3172
3171
|
let content = view.contentDOM.getBoundingClientRect(), docTop = content.top + view.viewState.paddingTop;
|
|
3173
3172
|
let block, { docHeight } = view.viewState;
|
|
3174
|
-
let yOffset = y - docTop;
|
|
3173
|
+
let { x, y } = coords, yOffset = y - docTop;
|
|
3175
3174
|
if (yOffset < 0)
|
|
3176
3175
|
return 0;
|
|
3177
3176
|
if (yOffset > docHeight)
|
|
@@ -3242,7 +3241,17 @@ function posAtCoords(view, { x, y }, precise, bias = -1) {
|
|
|
3242
3241
|
return yOffset > block.top + block.height / 2 ? block.to : block.from;
|
|
3243
3242
|
({ node, offset } = domPosAtCoords(line.dom, x, y));
|
|
3244
3243
|
}
|
|
3245
|
-
|
|
3244
|
+
let nearest = view.docView.nearest(node);
|
|
3245
|
+
if (!nearest)
|
|
3246
|
+
return null;
|
|
3247
|
+
if (nearest.isWidget) {
|
|
3248
|
+
let rect = nearest.dom.getBoundingClientRect();
|
|
3249
|
+
return coords.y < rect.top || coords.y <= rect.bottom && coords.x <= (rect.left + rect.right) / 2
|
|
3250
|
+
? nearest.posAtStart : nearest.posAtEnd;
|
|
3251
|
+
}
|
|
3252
|
+
else {
|
|
3253
|
+
return nearest.localPosFromDOM(node, offset) + nearest.posAtStart;
|
|
3254
|
+
}
|
|
3246
3255
|
}
|
|
3247
3256
|
function posAtCoordsImprecise(view, contentRect, block, x, y) {
|
|
3248
3257
|
let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
|
|
@@ -4033,17 +4042,23 @@ handlers.copy = handlers.cut = (view, event) => {
|
|
|
4033
4042
|
userEvent: "delete.cut"
|
|
4034
4043
|
});
|
|
4035
4044
|
};
|
|
4045
|
+
const isFocusChange = state.Annotation.define();
|
|
4046
|
+
function focusChangeTransaction(state, focus) {
|
|
4047
|
+
let effects = [];
|
|
4048
|
+
for (let getEffect of state.facet(focusChangeEffect)) {
|
|
4049
|
+
let effect = getEffect(state, focus);
|
|
4050
|
+
if (effect)
|
|
4051
|
+
effects.push(effect);
|
|
4052
|
+
}
|
|
4053
|
+
return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
|
|
4054
|
+
}
|
|
4036
4055
|
function updateForFocusChange(view) {
|
|
4037
4056
|
setTimeout(() => {
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
effects.push(effect);
|
|
4044
|
-
}
|
|
4045
|
-
if (effects.length)
|
|
4046
|
-
view.dispatch({ effects });
|
|
4057
|
+
let focus = view.hasFocus;
|
|
4058
|
+
if (focus != view.inputState.notifiedFocused) {
|
|
4059
|
+
let tr = focusChangeTransaction(view.state, focus);
|
|
4060
|
+
if (tr)
|
|
4061
|
+
view.dispatch(tr);
|
|
4047
4062
|
else
|
|
4048
4063
|
view.update([]);
|
|
4049
4064
|
}
|
|
@@ -6427,6 +6442,20 @@ class EditorView {
|
|
|
6427
6442
|
this.viewState.state = state$1;
|
|
6428
6443
|
return;
|
|
6429
6444
|
}
|
|
6445
|
+
let focus = this.hasFocus, focusFlag = 0, dispatchFocus = null;
|
|
6446
|
+
if (transactions.some(tr => tr.annotation(isFocusChange))) {
|
|
6447
|
+
this.inputState.notifiedFocused = focus;
|
|
6448
|
+
// If a focus-change transaction is being dispatched, set this update flag.
|
|
6449
|
+
focusFlag = 1 /* UpdateFlag.Focus */;
|
|
6450
|
+
}
|
|
6451
|
+
else if (focus != this.inputState.notifiedFocused) {
|
|
6452
|
+
this.inputState.notifiedFocused = focus;
|
|
6453
|
+
// Schedule a separate focus transaction if necessary, otherwise
|
|
6454
|
+
// add a flag to this update
|
|
6455
|
+
dispatchFocus = focusChangeTransaction(state$1, focus);
|
|
6456
|
+
if (!dispatchFocus)
|
|
6457
|
+
focusFlag = 1 /* UpdateFlag.Focus */;
|
|
6458
|
+
}
|
|
6430
6459
|
// If there was a pending DOM change, eagerly read it and try to
|
|
6431
6460
|
// apply it after the given transactions.
|
|
6432
6461
|
let pendingKey = this.observer.delayedAndroidKey, domChange = null;
|
|
@@ -6445,6 +6474,7 @@ class EditorView {
|
|
|
6445
6474
|
if (state$1.facet(state.EditorState.phrases) != this.state.facet(state.EditorState.phrases))
|
|
6446
6475
|
return this.setState(state$1);
|
|
6447
6476
|
update = ViewUpdate.create(this, state$1, transactions);
|
|
6477
|
+
update.flags |= focusFlag;
|
|
6448
6478
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6449
6479
|
try {
|
|
6450
6480
|
this.updateState = 2 /* UpdateState.Updating */;
|
|
@@ -6482,10 +6512,15 @@ class EditorView {
|
|
|
6482
6512
|
if (!update.empty)
|
|
6483
6513
|
for (let listener of this.state.facet(updateListener))
|
|
6484
6514
|
listener(update);
|
|
6485
|
-
if (domChange)
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6515
|
+
if (dispatchFocus || domChange)
|
|
6516
|
+
Promise.resolve().then(() => {
|
|
6517
|
+
if (dispatchFocus && this.state == dispatchFocus.startState)
|
|
6518
|
+
this.dispatch(dispatchFocus);
|
|
6519
|
+
if (domChange) {
|
|
6520
|
+
if (!applyDOMChange(this, domChange) && pendingKey.force)
|
|
6521
|
+
dispatchKey(this.contentDOM, pendingKey.key, pendingKey.keyCode);
|
|
6522
|
+
}
|
|
6523
|
+
});
|
|
6489
6524
|
}
|
|
6490
6525
|
/**
|
|
6491
6526
|
Reset the view to the given state. (This will cause the entire
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory, Transaction, Prec, codePointAt, codePointSize, combineConfig, StateField, RangeSetBuilder, countColumn } from '@codemirror/state';
|
|
1
|
+
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory, Annotation, Transaction, Prec, codePointAt, codePointSize, combineConfig, StateField, RangeSetBuilder, countColumn } from '@codemirror/state';
|
|
2
2
|
import { StyleModule } from 'style-mod';
|
|
3
3
|
import { keyName, base, shift } from 'w3c-keyname';
|
|
4
4
|
|
|
@@ -515,6 +515,7 @@ class ContentView {
|
|
|
515
515
|
}
|
|
516
516
|
static get(node) { return node.cmView; }
|
|
517
517
|
get isEditable() { return true; }
|
|
518
|
+
get isWidget() { return false; }
|
|
518
519
|
merge(from, to, source, hasStart, openStart, openEnd) {
|
|
519
520
|
return false;
|
|
520
521
|
}
|
|
@@ -889,6 +890,7 @@ class WidgetView extends ContentView {
|
|
|
889
890
|
return this.length ? rect : flattenRect(rect, this.side > 0);
|
|
890
891
|
}
|
|
891
892
|
get isEditable() { return false; }
|
|
893
|
+
get isWidget() { return true; }
|
|
892
894
|
destroy() {
|
|
893
895
|
super.destroy();
|
|
894
896
|
if (this.dom)
|
|
@@ -1598,6 +1600,8 @@ class BlockWidgetView extends ContentView {
|
|
|
1598
1600
|
}
|
|
1599
1601
|
ignoreMutation() { return true; }
|
|
1600
1602
|
ignoreEvent(event) { return this.widget.ignoreEvent(event); }
|
|
1603
|
+
get isEditable() { return false; }
|
|
1604
|
+
get isWidget() { return true; }
|
|
1601
1605
|
destroy() {
|
|
1602
1606
|
super.destroy();
|
|
1603
1607
|
if (this.dom)
|
|
@@ -2022,11 +2026,6 @@ class ViewUpdate {
|
|
|
2022
2026
|
let changedRanges = [];
|
|
2023
2027
|
this.changes.iterChangedRanges((fromA, toA, fromB, toB) => changedRanges.push(new ChangedRange(fromA, toA, fromB, toB)));
|
|
2024
2028
|
this.changedRanges = changedRanges;
|
|
2025
|
-
let focus = view.hasFocus;
|
|
2026
|
-
if (focus != view.inputState.notifiedFocused) {
|
|
2027
|
-
view.inputState.notifiedFocused = focus;
|
|
2028
|
-
this.flags |= 1 /* UpdateFlag.Focus */;
|
|
2029
|
-
}
|
|
2030
2029
|
}
|
|
2031
2030
|
/**
|
|
2032
2031
|
@internal
|
|
@@ -3161,11 +3160,11 @@ function domPosInText(node, x, y) {
|
|
|
3161
3160
|
}
|
|
3162
3161
|
return { node, offset: closestOffset > -1 ? closestOffset : generalSide > 0 ? node.nodeValue.length : 0 };
|
|
3163
3162
|
}
|
|
3164
|
-
function posAtCoords(view,
|
|
3163
|
+
function posAtCoords(view, coords, precise, bias = -1) {
|
|
3165
3164
|
var _a;
|
|
3166
3165
|
let content = view.contentDOM.getBoundingClientRect(), docTop = content.top + view.viewState.paddingTop;
|
|
3167
3166
|
let block, { docHeight } = view.viewState;
|
|
3168
|
-
let yOffset = y - docTop;
|
|
3167
|
+
let { x, y } = coords, yOffset = y - docTop;
|
|
3169
3168
|
if (yOffset < 0)
|
|
3170
3169
|
return 0;
|
|
3171
3170
|
if (yOffset > docHeight)
|
|
@@ -3236,7 +3235,17 @@ function posAtCoords(view, { x, y }, precise, bias = -1) {
|
|
|
3236
3235
|
return yOffset > block.top + block.height / 2 ? block.to : block.from;
|
|
3237
3236
|
({ node, offset } = domPosAtCoords(line.dom, x, y));
|
|
3238
3237
|
}
|
|
3239
|
-
|
|
3238
|
+
let nearest = view.docView.nearest(node);
|
|
3239
|
+
if (!nearest)
|
|
3240
|
+
return null;
|
|
3241
|
+
if (nearest.isWidget) {
|
|
3242
|
+
let rect = nearest.dom.getBoundingClientRect();
|
|
3243
|
+
return coords.y < rect.top || coords.y <= rect.bottom && coords.x <= (rect.left + rect.right) / 2
|
|
3244
|
+
? nearest.posAtStart : nearest.posAtEnd;
|
|
3245
|
+
}
|
|
3246
|
+
else {
|
|
3247
|
+
return nearest.localPosFromDOM(node, offset) + nearest.posAtStart;
|
|
3248
|
+
}
|
|
3240
3249
|
}
|
|
3241
3250
|
function posAtCoordsImprecise(view, contentRect, block, x, y) {
|
|
3242
3251
|
let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
|
|
@@ -4027,17 +4036,23 @@ handlers.copy = handlers.cut = (view, event) => {
|
|
|
4027
4036
|
userEvent: "delete.cut"
|
|
4028
4037
|
});
|
|
4029
4038
|
};
|
|
4039
|
+
const isFocusChange = /*@__PURE__*/Annotation.define();
|
|
4040
|
+
function focusChangeTransaction(state, focus) {
|
|
4041
|
+
let effects = [];
|
|
4042
|
+
for (let getEffect of state.facet(focusChangeEffect)) {
|
|
4043
|
+
let effect = getEffect(state, focus);
|
|
4044
|
+
if (effect)
|
|
4045
|
+
effects.push(effect);
|
|
4046
|
+
}
|
|
4047
|
+
return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
|
|
4048
|
+
}
|
|
4030
4049
|
function updateForFocusChange(view) {
|
|
4031
4050
|
setTimeout(() => {
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
effects.push(effect);
|
|
4038
|
-
}
|
|
4039
|
-
if (effects.length)
|
|
4040
|
-
view.dispatch({ effects });
|
|
4051
|
+
let focus = view.hasFocus;
|
|
4052
|
+
if (focus != view.inputState.notifiedFocused) {
|
|
4053
|
+
let tr = focusChangeTransaction(view.state, focus);
|
|
4054
|
+
if (tr)
|
|
4055
|
+
view.dispatch(tr);
|
|
4041
4056
|
else
|
|
4042
4057
|
view.update([]);
|
|
4043
4058
|
}
|
|
@@ -6420,6 +6435,20 @@ class EditorView {
|
|
|
6420
6435
|
this.viewState.state = state;
|
|
6421
6436
|
return;
|
|
6422
6437
|
}
|
|
6438
|
+
let focus = this.hasFocus, focusFlag = 0, dispatchFocus = null;
|
|
6439
|
+
if (transactions.some(tr => tr.annotation(isFocusChange))) {
|
|
6440
|
+
this.inputState.notifiedFocused = focus;
|
|
6441
|
+
// If a focus-change transaction is being dispatched, set this update flag.
|
|
6442
|
+
focusFlag = 1 /* UpdateFlag.Focus */;
|
|
6443
|
+
}
|
|
6444
|
+
else if (focus != this.inputState.notifiedFocused) {
|
|
6445
|
+
this.inputState.notifiedFocused = focus;
|
|
6446
|
+
// Schedule a separate focus transaction if necessary, otherwise
|
|
6447
|
+
// add a flag to this update
|
|
6448
|
+
dispatchFocus = focusChangeTransaction(state, focus);
|
|
6449
|
+
if (!dispatchFocus)
|
|
6450
|
+
focusFlag = 1 /* UpdateFlag.Focus */;
|
|
6451
|
+
}
|
|
6423
6452
|
// If there was a pending DOM change, eagerly read it and try to
|
|
6424
6453
|
// apply it after the given transactions.
|
|
6425
6454
|
let pendingKey = this.observer.delayedAndroidKey, domChange = null;
|
|
@@ -6438,6 +6467,7 @@ class EditorView {
|
|
|
6438
6467
|
if (state.facet(EditorState.phrases) != this.state.facet(EditorState.phrases))
|
|
6439
6468
|
return this.setState(state);
|
|
6440
6469
|
update = ViewUpdate.create(this, state, transactions);
|
|
6470
|
+
update.flags |= focusFlag;
|
|
6441
6471
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6442
6472
|
try {
|
|
6443
6473
|
this.updateState = 2 /* UpdateState.Updating */;
|
|
@@ -6475,10 +6505,15 @@ class EditorView {
|
|
|
6475
6505
|
if (!update.empty)
|
|
6476
6506
|
for (let listener of this.state.facet(updateListener))
|
|
6477
6507
|
listener(update);
|
|
6478
|
-
if (domChange)
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6508
|
+
if (dispatchFocus || domChange)
|
|
6509
|
+
Promise.resolve().then(() => {
|
|
6510
|
+
if (dispatchFocus && this.state == dispatchFocus.startState)
|
|
6511
|
+
this.dispatch(dispatchFocus);
|
|
6512
|
+
if (domChange) {
|
|
6513
|
+
if (!applyDOMChange(this, domChange) && pendingKey.force)
|
|
6514
|
+
dispatchKey(this.contentDOM, pendingKey.key, pendingKey.keyCode);
|
|
6515
|
+
}
|
|
6516
|
+
});
|
|
6482
6517
|
}
|
|
6483
6518
|
/**
|
|
6484
6519
|
Reset the view to the given state. (This will cause the entire
|