@codemirror/view 0.19.14 → 0.19.18

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 CHANGED
@@ -1,3 +1,35 @@
1
+ ## 0.19.18 (2021-11-16)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where the editor wasn't aware it was line-wrapping with its own `lineWrapping` extension enabled.
6
+
7
+ ## 0.19.17 (2021-11-16)
8
+
9
+ ### Bug fixes
10
+
11
+ Avoid an issue where stretches of whitespace on line wrap points could cause the cursor to be placed outside of the content.
12
+
13
+ ## 0.19.16 (2021-11-11)
14
+
15
+ ### Breaking changes
16
+
17
+ Block replacement decorations now default to inclusive, because non-inclusive block decorations are rarely what you need.
18
+
19
+ ### Bug fixes
20
+
21
+ Fix an issue that caused block widgets to always have a large side value, making it impossible to show them between to replacement decorations.
22
+
23
+ Fix a crash that could happen after some types of viewport changes, due to a bug in the block widget view data structure.
24
+
25
+ ## 0.19.15 (2021-11-09)
26
+
27
+ ### Bug fixes
28
+
29
+ Fix a bug where the editor would think it was invisible when the document body was given screen height and scroll behavior.
30
+
31
+ Fix selection reading inside a shadow root on iOS.
32
+
1
33
  ## 0.19.14 (2021-11-07)
2
34
 
3
35
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -252,19 +252,6 @@ function dispatchKey(elt, name, code) {
252
252
  elt.dispatchEvent(up);
253
253
  return down.defaultPrevented || up.defaultPrevented;
254
254
  }
255
- let _plainTextSupported = null;
256
- function contentEditablePlainTextSupported() {
257
- if (_plainTextSupported == null) {
258
- _plainTextSupported = false;
259
- let dummy = document.createElement("div");
260
- try {
261
- dummy.contentEditable = "plaintext-only";
262
- _plainTextSupported = dummy.contentEditable == "plaintext-only";
263
- }
264
- catch (_) { }
265
- }
266
- return _plainTextSupported;
267
- }
268
255
  function getRoot(node) {
269
256
  while (node) {
270
257
  if (node && (node.nodeType == 9 || node.nodeType == 11 && node.host))
@@ -679,7 +666,7 @@ function textCoords(text, pos, side) {
679
666
  let rect = rects[(flatten ? flatten < 0 : side >= 0) ? 0 : rects.length - 1];
680
667
  if (browser.safari && !flatten && rect.width == 0)
681
668
  rect = Array.prototype.find.call(rects, r => r.width) || rect;
682
- return flatten ? flattenRect(rect, flatten < 0) : rect;
669
+ return flatten ? flattenRect(rect, flatten < 0) : rect || null;
683
670
  }
684
671
  // Also used for collapsed ranges that don't have a placeholder widget!
685
672
  class WidgetView extends InlineView {
@@ -787,7 +774,7 @@ class WidgetBufferView extends InlineView {
787
774
  domBoundsAround() { return null; }
788
775
  coordsAt(pos) {
789
776
  let rects = clientRectsFor(this.dom);
790
- return rects[rects.length - 1];
777
+ return rects[rects.length - 1] || null;
791
778
  }
792
779
  get overrideDOMText() {
793
780
  return text.Text.of([this.dom.nodeValue.replace(/\u200b/g, "")]);
@@ -929,7 +916,7 @@ function coordsInChildren(view, pos, side) {
929
916
  if (!last)
930
917
  return view.dom.getBoundingClientRect();
931
918
  let rects = clientRectsFor(last);
932
- return rects[rects.length - 1];
919
+ return rects[rects.length - 1] || null;
933
920
  }
934
921
 
935
922
  function combineAttrs(source, target) {
@@ -1097,8 +1084,6 @@ class Decoration extends rangeset.RangeValue {
1097
1084
  */
1098
1085
  static widget(spec) {
1099
1086
  let side = spec.side || 0;
1100
- if (spec.block)
1101
- side += (200000000 /* BigBlock */ + 1) * (side > 0 ? 1 : -1);
1102
1087
  return new PointDecoration(spec, side, side, !!spec.block, spec.widget || null, false);
1103
1088
  }
1104
1089
  /**
@@ -1107,9 +1092,9 @@ class Decoration extends rangeset.RangeValue {
1107
1092
  */
1108
1093
  static replace(spec) {
1109
1094
  let block = !!spec.block;
1110
- let { start, end } = getInclusive(spec);
1111
- let startSide = block ? -200000000 /* BigBlock */ * (start ? 2 : 1) : 100000000 /* BigInline */ * (start ? -1 : 1);
1112
- let endSide = block ? 200000000 /* BigBlock */ * (end ? 2 : 1) : 100000000 /* BigInline */ * (end ? 1 : -1);
1095
+ let { start, end } = getInclusive(spec, block);
1096
+ let startSide = 100000000 /* Big */ * (start ? -1 : 1) * (block ? 2 : 1);
1097
+ let endSide = 100000000 /* Big */ * (end ? 1 : -1) * (block ? 2 : 1);
1113
1098
  return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
1114
1099
  }
1115
1100
  /**
@@ -1139,7 +1124,7 @@ Decoration.none = rangeset.RangeSet.empty;
1139
1124
  class MarkDecoration extends Decoration {
1140
1125
  constructor(spec) {
1141
1126
  let { start, end } = getInclusive(spec);
1142
- super(100000000 /* BigInline */ * (start ? -1 : 1), 100000000 /* BigInline */ * (end ? 1 : -1), null, spec);
1127
+ super(100000000 /* Big */ * (start ? -1 : 1), 100000000 /* Big */ * (end ? 1 : -1), null, spec);
1143
1128
  this.tagName = spec.tagName || "span";
1144
1129
  this.class = spec.class || "";
1145
1130
  this.attrs = spec.attributes || null;
@@ -1160,7 +1145,7 @@ class MarkDecoration extends Decoration {
1160
1145
  MarkDecoration.prototype.point = false;
1161
1146
  class LineDecoration extends Decoration {
1162
1147
  constructor(spec) {
1163
- super(-100000000 /* BigInline */, -100000000 /* BigInline */, null, spec);
1148
+ super(-100000000 /* Big */, -100000000 /* Big */, null, spec);
1164
1149
  }
1165
1150
  eq(other) {
1166
1151
  return other instanceof LineDecoration && attrsEq(this.spec.attributes, other.spec.attributes);
@@ -1201,13 +1186,13 @@ class PointDecoration extends Decoration {
1201
1186
  }
1202
1187
  }
1203
1188
  PointDecoration.prototype.point = true;
1204
- function getInclusive(spec) {
1189
+ function getInclusive(spec, block = false) {
1205
1190
  let { inclusiveStart: start, inclusiveEnd: end } = spec;
1206
1191
  if (start == null)
1207
1192
  start = spec.inclusive;
1208
1193
  if (end == null)
1209
1194
  end = spec.inclusive;
1210
- return { start: start || false, end: end || false };
1195
+ return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block };
1211
1196
  }
1212
1197
  function widgetsEq(a, b) {
1213
1198
  return a == b || !!(a && b && a.compare(b));
@@ -1375,7 +1360,9 @@ class BlockWidgetView extends ContentView {
1375
1360
  split(at) {
1376
1361
  let len = this.length - at;
1377
1362
  this.length = at;
1378
- return new BlockWidgetView(this.widget, len, this.type);
1363
+ let end = new BlockWidgetView(this.widget, len, this.type);
1364
+ end.breakAfter = this.breakAfter;
1365
+ return end;
1379
1366
  }
1380
1367
  get children() { return none$1; }
1381
1368
  sync() {
@@ -3755,7 +3742,7 @@ handlers.beforeinput = (view, event) => {
3755
3742
  }
3756
3743
  };
3757
3744
 
3758
- const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line"];
3745
+ const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
3759
3746
  class HeightOracle {
3760
3747
  constructor() {
3761
3748
  this.doc = text.Text.empty;
@@ -4402,18 +4389,20 @@ function visiblePixelRange(dom, paddingTop) {
4402
4389
  let rect = dom.getBoundingClientRect();
4403
4390
  let left = Math.max(0, rect.left), right = Math.min(innerWidth, rect.right);
4404
4391
  let top = Math.max(0, rect.top), bottom = Math.min(innerHeight, rect.bottom);
4405
- for (let parent = dom.parentNode; parent;) { // (Cast to any because TypeScript is useless with Node types)
4392
+ let body = dom.ownerDocument.body;
4393
+ for (let parent = dom.parentNode; parent && parent != body;) {
4406
4394
  if (parent.nodeType == 1) {
4407
- let style = window.getComputedStyle(parent);
4408
- if ((parent.scrollHeight > parent.clientHeight || parent.scrollWidth > parent.clientWidth) &&
4395
+ let elt = parent;
4396
+ let style = window.getComputedStyle(elt);
4397
+ if ((elt.scrollHeight > elt.clientHeight || elt.scrollWidth > elt.clientWidth) &&
4409
4398
  style.overflow != "visible") {
4410
- let parentRect = parent.getBoundingClientRect();
4399
+ let parentRect = elt.getBoundingClientRect();
4411
4400
  left = Math.max(left, parentRect.left);
4412
4401
  right = Math.min(right, parentRect.right);
4413
4402
  top = Math.max(top, parentRect.top);
4414
4403
  bottom = Math.min(bottom, parentRect.bottom);
4415
4404
  }
4416
- parent = style.position == "absolute" || style.position == "fixed" ? parent.offsetParent : parent.parentNode;
4405
+ parent = style.position == "absolute" || style.position == "fixed" ? elt.offsetParent : elt.parentNode;
4417
4406
  }
4418
4407
  else if (parent.nodeType == 11) { // Shadow root
4419
4408
  parent = parent.host;
@@ -4943,10 +4932,14 @@ const baseTheme = buildTheme("." + baseThemeID, {
4943
4932
  wordWrap: "normal",
4944
4933
  boxSizing: "border-box",
4945
4934
  padding: "4px 0",
4946
- outline: "none"
4935
+ outline: "none",
4936
+ "&[contenteditable=true]": {
4937
+ WebkitUserModify: "read-write-plaintext-only",
4938
+ }
4947
4939
  },
4948
4940
  ".cm-lineWrapping": {
4949
- whiteSpace: "pre-wrap",
4941
+ whiteSpace_fallback: "pre-wrap",
4942
+ whiteSpace: "break-spaces",
4950
4943
  wordBreak: "break-word",
4951
4944
  overflowWrap: "anywhere"
4952
4945
  },
@@ -5925,7 +5918,7 @@ class EditorView {
5925
5918
  autocorrect: "off",
5926
5919
  autocapitalize: "off",
5927
5920
  translate: "no",
5928
- contenteditable: !this.state.facet(editable) ? "false" : contentEditablePlainTextSupported() ? "plaintext-only" : "true",
5921
+ contenteditable: !this.state.facet(editable) ? "false" : "true",
5929
5922
  class: "cm-content",
5930
5923
  style: `${browser.tabSize}: ${this.state.tabSize}`,
5931
5924
  role: "textbox",
package/dist/index.d.ts CHANGED
@@ -91,7 +91,8 @@ interface ReplaceDecorationSpec {
91
91
  /**
92
92
  Whether this range covers the positions on its sides. This
93
93
  influences whether new content becomes part of the range and
94
- whether the cursor can be drawn on its sides. Defaults to false.
94
+ whether the cursor can be drawn on its sides. Defaults to false
95
+ for inline replacements, and true for block replacements.
95
96
  */
96
97
  inclusive?: boolean;
97
98
  /**
package/dist/index.js CHANGED
@@ -249,19 +249,6 @@ function dispatchKey(elt, name, code) {
249
249
  elt.dispatchEvent(up);
250
250
  return down.defaultPrevented || up.defaultPrevented;
251
251
  }
252
- let _plainTextSupported = null;
253
- function contentEditablePlainTextSupported() {
254
- if (_plainTextSupported == null) {
255
- _plainTextSupported = false;
256
- let dummy = document.createElement("div");
257
- try {
258
- dummy.contentEditable = "plaintext-only";
259
- _plainTextSupported = dummy.contentEditable == "plaintext-only";
260
- }
261
- catch (_) { }
262
- }
263
- return _plainTextSupported;
264
- }
265
252
  function getRoot(node) {
266
253
  while (node) {
267
254
  if (node && (node.nodeType == 9 || node.nodeType == 11 && node.host))
@@ -676,7 +663,7 @@ function textCoords(text, pos, side) {
676
663
  let rect = rects[(flatten ? flatten < 0 : side >= 0) ? 0 : rects.length - 1];
677
664
  if (browser.safari && !flatten && rect.width == 0)
678
665
  rect = Array.prototype.find.call(rects, r => r.width) || rect;
679
- return flatten ? flattenRect(rect, flatten < 0) : rect;
666
+ return flatten ? flattenRect(rect, flatten < 0) : rect || null;
680
667
  }
681
668
  // Also used for collapsed ranges that don't have a placeholder widget!
682
669
  class WidgetView extends InlineView {
@@ -784,7 +771,7 @@ class WidgetBufferView extends InlineView {
784
771
  domBoundsAround() { return null; }
785
772
  coordsAt(pos) {
786
773
  let rects = clientRectsFor(this.dom);
787
- return rects[rects.length - 1];
774
+ return rects[rects.length - 1] || null;
788
775
  }
789
776
  get overrideDOMText() {
790
777
  return Text.of([this.dom.nodeValue.replace(/\u200b/g, "")]);
@@ -926,7 +913,7 @@ function coordsInChildren(view, pos, side) {
926
913
  if (!last)
927
914
  return view.dom.getBoundingClientRect();
928
915
  let rects = clientRectsFor(last);
929
- return rects[rects.length - 1];
916
+ return rects[rects.length - 1] || null;
930
917
  }
931
918
 
932
919
  function combineAttrs(source, target) {
@@ -1093,8 +1080,6 @@ class Decoration extends RangeValue {
1093
1080
  */
1094
1081
  static widget(spec) {
1095
1082
  let side = spec.side || 0;
1096
- if (spec.block)
1097
- side += (200000000 /* BigBlock */ + 1) * (side > 0 ? 1 : -1);
1098
1083
  return new PointDecoration(spec, side, side, !!spec.block, spec.widget || null, false);
1099
1084
  }
1100
1085
  /**
@@ -1103,9 +1088,9 @@ class Decoration extends RangeValue {
1103
1088
  */
1104
1089
  static replace(spec) {
1105
1090
  let block = !!spec.block;
1106
- let { start, end } = getInclusive(spec);
1107
- let startSide = block ? -200000000 /* BigBlock */ * (start ? 2 : 1) : 100000000 /* BigInline */ * (start ? -1 : 1);
1108
- let endSide = block ? 200000000 /* BigBlock */ * (end ? 2 : 1) : 100000000 /* BigInline */ * (end ? 1 : -1);
1091
+ let { start, end } = getInclusive(spec, block);
1092
+ let startSide = 100000000 /* Big */ * (start ? -1 : 1) * (block ? 2 : 1);
1093
+ let endSide = 100000000 /* Big */ * (end ? 1 : -1) * (block ? 2 : 1);
1109
1094
  return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
1110
1095
  }
1111
1096
  /**
@@ -1135,7 +1120,7 @@ Decoration.none = RangeSet.empty;
1135
1120
  class MarkDecoration extends Decoration {
1136
1121
  constructor(spec) {
1137
1122
  let { start, end } = getInclusive(spec);
1138
- super(100000000 /* BigInline */ * (start ? -1 : 1), 100000000 /* BigInline */ * (end ? 1 : -1), null, spec);
1123
+ super(100000000 /* Big */ * (start ? -1 : 1), 100000000 /* Big */ * (end ? 1 : -1), null, spec);
1139
1124
  this.tagName = spec.tagName || "span";
1140
1125
  this.class = spec.class || "";
1141
1126
  this.attrs = spec.attributes || null;
@@ -1156,7 +1141,7 @@ class MarkDecoration extends Decoration {
1156
1141
  MarkDecoration.prototype.point = false;
1157
1142
  class LineDecoration extends Decoration {
1158
1143
  constructor(spec) {
1159
- super(-100000000 /* BigInline */, -100000000 /* BigInline */, null, spec);
1144
+ super(-100000000 /* Big */, -100000000 /* Big */, null, spec);
1160
1145
  }
1161
1146
  eq(other) {
1162
1147
  return other instanceof LineDecoration && attrsEq(this.spec.attributes, other.spec.attributes);
@@ -1197,13 +1182,13 @@ class PointDecoration extends Decoration {
1197
1182
  }
1198
1183
  }
1199
1184
  PointDecoration.prototype.point = true;
1200
- function getInclusive(spec) {
1185
+ function getInclusive(spec, block = false) {
1201
1186
  let { inclusiveStart: start, inclusiveEnd: end } = spec;
1202
1187
  if (start == null)
1203
1188
  start = spec.inclusive;
1204
1189
  if (end == null)
1205
1190
  end = spec.inclusive;
1206
- return { start: start || false, end: end || false };
1191
+ return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block };
1207
1192
  }
1208
1193
  function widgetsEq(a, b) {
1209
1194
  return a == b || !!(a && b && a.compare(b));
@@ -1371,7 +1356,9 @@ class BlockWidgetView extends ContentView {
1371
1356
  split(at) {
1372
1357
  let len = this.length - at;
1373
1358
  this.length = at;
1374
- return new BlockWidgetView(this.widget, len, this.type);
1359
+ let end = new BlockWidgetView(this.widget, len, this.type);
1360
+ end.breakAfter = this.breakAfter;
1361
+ return end;
1375
1362
  }
1376
1363
  get children() { return none$1; }
1377
1364
  sync() {
@@ -3750,7 +3737,7 @@ handlers.beforeinput = (view, event) => {
3750
3737
  }
3751
3738
  };
3752
3739
 
3753
- const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line"];
3740
+ const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
3754
3741
  class HeightOracle {
3755
3742
  constructor() {
3756
3743
  this.doc = Text.empty;
@@ -4396,18 +4383,20 @@ function visiblePixelRange(dom, paddingTop) {
4396
4383
  let rect = dom.getBoundingClientRect();
4397
4384
  let left = Math.max(0, rect.left), right = Math.min(innerWidth, rect.right);
4398
4385
  let top = Math.max(0, rect.top), bottom = Math.min(innerHeight, rect.bottom);
4399
- for (let parent = dom.parentNode; parent;) { // (Cast to any because TypeScript is useless with Node types)
4386
+ let body = dom.ownerDocument.body;
4387
+ for (let parent = dom.parentNode; parent && parent != body;) {
4400
4388
  if (parent.nodeType == 1) {
4401
- let style = window.getComputedStyle(parent);
4402
- if ((parent.scrollHeight > parent.clientHeight || parent.scrollWidth > parent.clientWidth) &&
4389
+ let elt = parent;
4390
+ let style = window.getComputedStyle(elt);
4391
+ if ((elt.scrollHeight > elt.clientHeight || elt.scrollWidth > elt.clientWidth) &&
4403
4392
  style.overflow != "visible") {
4404
- let parentRect = parent.getBoundingClientRect();
4393
+ let parentRect = elt.getBoundingClientRect();
4405
4394
  left = Math.max(left, parentRect.left);
4406
4395
  right = Math.min(right, parentRect.right);
4407
4396
  top = Math.max(top, parentRect.top);
4408
4397
  bottom = Math.min(bottom, parentRect.bottom);
4409
4398
  }
4410
- parent = style.position == "absolute" || style.position == "fixed" ? parent.offsetParent : parent.parentNode;
4399
+ parent = style.position == "absolute" || style.position == "fixed" ? elt.offsetParent : elt.parentNode;
4411
4400
  }
4412
4401
  else if (parent.nodeType == 11) { // Shadow root
4413
4402
  parent = parent.host;
@@ -4937,10 +4926,14 @@ const baseTheme = /*@__PURE__*/buildTheme("." + baseThemeID, {
4937
4926
  wordWrap: "normal",
4938
4927
  boxSizing: "border-box",
4939
4928
  padding: "4px 0",
4940
- outline: "none"
4929
+ outline: "none",
4930
+ "&[contenteditable=true]": {
4931
+ WebkitUserModify: "read-write-plaintext-only",
4932
+ }
4941
4933
  },
4942
4934
  ".cm-lineWrapping": {
4943
- whiteSpace: "pre-wrap",
4935
+ whiteSpace_fallback: "pre-wrap",
4936
+ whiteSpace: "break-spaces",
4944
4937
  wordBreak: "break-word",
4945
4938
  overflowWrap: "anywhere"
4946
4939
  },
@@ -5919,7 +5912,7 @@ class EditorView {
5919
5912
  autocorrect: "off",
5920
5913
  autocapitalize: "off",
5921
5914
  translate: "no",
5922
- contenteditable: !this.state.facet(editable) ? "false" : contentEditablePlainTextSupported() ? "plaintext-only" : "true",
5915
+ contenteditable: !this.state.facet(editable) ? "false" : "true",
5923
5916
  class: "cm-content",
5924
5917
  style: `${browser.tabSize}: ${this.state.tabSize}`,
5925
5918
  role: "textbox",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "0.19.14",
3
+ "version": "0.19.18",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",