slate-react 0.88.2 → 0.89.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.
@@ -1644,7 +1644,7 @@
1644
1644
  // next or previous node, depending on which side the `x` and `y`
1645
1645
  // coordinates are closest to.
1646
1646
 
1647
- if (slate.Editor.isVoid(editor, node)) {
1647
+ if (slate.Element.isElement(node) && slate.Editor.isVoid(editor, node)) {
1648
1648
  var rect = target.getBoundingClientRect();
1649
1649
  var isPrev = editor.isInline(node) ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y;
1650
1650
  var edge = slate.Editor.point(editor, path, {
@@ -1886,6 +1886,46 @@
1886
1886
  if (!focus) {
1887
1887
  return null;
1888
1888
  }
1889
+ /**
1890
+ * suppose we have this document:
1891
+ *
1892
+ * { type: 'paragraph',
1893
+ * children: [
1894
+ * { text: 'foo ' },
1895
+ * { text: 'bar' },
1896
+ * { text: ' baz' }
1897
+ * ]
1898
+ * }
1899
+ *
1900
+ * a double click on "bar" on chrome will create this range:
1901
+ *
1902
+ * anchor -> [0,1] offset 0
1903
+ * focus -> [0,1] offset 3
1904
+ *
1905
+ * while on firefox will create this range:
1906
+ *
1907
+ * anchor -> [0,0] offset 4
1908
+ * focus -> [0,2] offset 0
1909
+ *
1910
+ * let's try to fix it...
1911
+ */
1912
+
1913
+
1914
+ if (IS_FIREFOX && !isCollapsed && anchorNode !== focusNode) {
1915
+ var isEnd = slate.Editor.isEnd(editor, anchor, anchor.path);
1916
+ var isStart = slate.Editor.isStart(editor, focus, focus.path);
1917
+
1918
+ if (isEnd) {
1919
+ var after = slate.Editor.after(editor, anchor); // Editor.after() might return undefined
1920
+
1921
+ anchor = after || anchor;
1922
+ }
1923
+
1924
+ if (isStart) {
1925
+ var before = slate.Editor.before(editor, focus);
1926
+ focus = before || focus;
1927
+ }
1928
+ }
1889
1929
 
1890
1930
  var range = {
1891
1931
  anchor: anchor,
@@ -1941,7 +1981,7 @@
1941
1981
  isTargetInsideNonReadonlyVoid: function isTargetInsideNonReadonlyVoid(editor, target) {
1942
1982
  if (IS_READ_ONLY.get(editor)) return false;
1943
1983
  var slateNode = ReactEditor.hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
1944
- return slate.Editor.isVoid(editor, slateNode);
1984
+ return slate.Element.isElement(slateNode) && slate.Editor.isVoid(editor, slateNode);
1945
1985
  },
1946
1986
 
1947
1987
  /**
@@ -2007,6 +2047,505 @@
2007
2047
  return true;
2008
2048
  };
2009
2049
 
2050
+ var resizeObservers = [];
2051
+
2052
+ var hasActiveObservations = function () {
2053
+ return resizeObservers.some(function (ro) { return ro.activeTargets.length > 0; });
2054
+ };
2055
+
2056
+ var hasSkippedObservations = function () {
2057
+ return resizeObservers.some(function (ro) { return ro.skippedTargets.length > 0; });
2058
+ };
2059
+
2060
+ var msg = 'ResizeObserver loop completed with undelivered notifications.';
2061
+ var deliverResizeLoopError = function () {
2062
+ var event;
2063
+ if (typeof ErrorEvent === 'function') {
2064
+ event = new ErrorEvent('error', {
2065
+ message: msg
2066
+ });
2067
+ }
2068
+ else {
2069
+ event = document.createEvent('Event');
2070
+ event.initEvent('error', false, false);
2071
+ event.message = msg;
2072
+ }
2073
+ window.dispatchEvent(event);
2074
+ };
2075
+
2076
+ var ResizeObserverBoxOptions;
2077
+ (function (ResizeObserverBoxOptions) {
2078
+ ResizeObserverBoxOptions["BORDER_BOX"] = "border-box";
2079
+ ResizeObserverBoxOptions["CONTENT_BOX"] = "content-box";
2080
+ ResizeObserverBoxOptions["DEVICE_PIXEL_CONTENT_BOX"] = "device-pixel-content-box";
2081
+ })(ResizeObserverBoxOptions || (ResizeObserverBoxOptions = {}));
2082
+
2083
+ var freeze = function (obj) { return Object.freeze(obj); };
2084
+
2085
+ var ResizeObserverSize = (function () {
2086
+ function ResizeObserverSize(inlineSize, blockSize) {
2087
+ this.inlineSize = inlineSize;
2088
+ this.blockSize = blockSize;
2089
+ freeze(this);
2090
+ }
2091
+ return ResizeObserverSize;
2092
+ }());
2093
+
2094
+ var DOMRectReadOnly = (function () {
2095
+ function DOMRectReadOnly(x, y, width, height) {
2096
+ this.x = x;
2097
+ this.y = y;
2098
+ this.width = width;
2099
+ this.height = height;
2100
+ this.top = this.y;
2101
+ this.left = this.x;
2102
+ this.bottom = this.top + this.height;
2103
+ this.right = this.left + this.width;
2104
+ return freeze(this);
2105
+ }
2106
+ DOMRectReadOnly.prototype.toJSON = function () {
2107
+ var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left, width = _a.width, height = _a.height;
2108
+ return { x: x, y: y, top: top, right: right, bottom: bottom, left: left, width: width, height: height };
2109
+ };
2110
+ DOMRectReadOnly.fromRect = function (rectangle) {
2111
+ return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
2112
+ };
2113
+ return DOMRectReadOnly;
2114
+ }());
2115
+
2116
+ var isSVG = function (target) { return target instanceof SVGElement && 'getBBox' in target; };
2117
+ var isHidden = function (target) {
2118
+ if (isSVG(target)) {
2119
+ var _a = target.getBBox(), width = _a.width, height = _a.height;
2120
+ return !width && !height;
2121
+ }
2122
+ var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
2123
+ return !(offsetWidth || offsetHeight || target.getClientRects().length);
2124
+ };
2125
+ var isElement = function (obj) {
2126
+ var _a;
2127
+ if (obj instanceof Element) {
2128
+ return true;
2129
+ }
2130
+ var scope = (_a = obj === null || obj === void 0 ? void 0 : obj.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
2131
+ return !!(scope && obj instanceof scope.Element);
2132
+ };
2133
+ var isReplacedElement = function (target) {
2134
+ switch (target.tagName) {
2135
+ case 'INPUT':
2136
+ if (target.type !== 'image') {
2137
+ break;
2138
+ }
2139
+ case 'VIDEO':
2140
+ case 'AUDIO':
2141
+ case 'EMBED':
2142
+ case 'OBJECT':
2143
+ case 'CANVAS':
2144
+ case 'IFRAME':
2145
+ case 'IMG':
2146
+ return true;
2147
+ }
2148
+ return false;
2149
+ };
2150
+
2151
+ var global$1 = typeof window !== 'undefined' ? window : {};
2152
+
2153
+ var cache = new WeakMap();
2154
+ var scrollRegexp = /auto|scroll/;
2155
+ var verticalRegexp = /^tb|vertical/;
2156
+ var IE = (/msie|trident/i).test(global$1.navigator && global$1.navigator.userAgent);
2157
+ var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
2158
+ var size = function (inlineSize, blockSize, switchSizes) {
2159
+ if (inlineSize === void 0) { inlineSize = 0; }
2160
+ if (blockSize === void 0) { blockSize = 0; }
2161
+ if (switchSizes === void 0) { switchSizes = false; }
2162
+ return new ResizeObserverSize((switchSizes ? blockSize : inlineSize) || 0, (switchSizes ? inlineSize : blockSize) || 0);
2163
+ };
2164
+ var zeroBoxes = freeze({
2165
+ devicePixelContentBoxSize: size(),
2166
+ borderBoxSize: size(),
2167
+ contentBoxSize: size(),
2168
+ contentRect: new DOMRectReadOnly(0, 0, 0, 0)
2169
+ });
2170
+ var calculateBoxSizes = function (target, forceRecalculation) {
2171
+ if (forceRecalculation === void 0) { forceRecalculation = false; }
2172
+ if (cache.has(target) && !forceRecalculation) {
2173
+ return cache.get(target);
2174
+ }
2175
+ if (isHidden(target)) {
2176
+ cache.set(target, zeroBoxes);
2177
+ return zeroBoxes;
2178
+ }
2179
+ var cs = getComputedStyle(target);
2180
+ var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
2181
+ var removePadding = !IE && cs.boxSizing === 'border-box';
2182
+ var switchSizes = verticalRegexp.test(cs.writingMode || '');
2183
+ var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
2184
+ var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
2185
+ var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
2186
+ var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
2187
+ var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
2188
+ var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
2189
+ var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
2190
+ var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
2191
+ var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
2192
+ var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
2193
+ var horizontalPadding = paddingLeft + paddingRight;
2194
+ var verticalPadding = paddingTop + paddingBottom;
2195
+ var horizontalBorderArea = borderLeft + borderRight;
2196
+ var verticalBorderArea = borderTop + borderBottom;
2197
+ var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
2198
+ var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
2199
+ var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
2200
+ var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
2201
+ var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
2202
+ var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
2203
+ var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
2204
+ var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
2205
+ var boxes = freeze({
2206
+ devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
2207
+ borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
2208
+ contentBoxSize: size(contentWidth, contentHeight, switchSizes),
2209
+ contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
2210
+ });
2211
+ cache.set(target, boxes);
2212
+ return boxes;
2213
+ };
2214
+ var calculateBoxSize = function (target, observedBox, forceRecalculation) {
2215
+ var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize, contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
2216
+ switch (observedBox) {
2217
+ case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
2218
+ return devicePixelContentBoxSize;
2219
+ case ResizeObserverBoxOptions.BORDER_BOX:
2220
+ return borderBoxSize;
2221
+ default:
2222
+ return contentBoxSize;
2223
+ }
2224
+ };
2225
+
2226
+ var ResizeObserverEntry = (function () {
2227
+ function ResizeObserverEntry(target) {
2228
+ var boxes = calculateBoxSizes(target);
2229
+ this.target = target;
2230
+ this.contentRect = boxes.contentRect;
2231
+ this.borderBoxSize = freeze([boxes.borderBoxSize]);
2232
+ this.contentBoxSize = freeze([boxes.contentBoxSize]);
2233
+ this.devicePixelContentBoxSize = freeze([boxes.devicePixelContentBoxSize]);
2234
+ }
2235
+ return ResizeObserverEntry;
2236
+ }());
2237
+
2238
+ var calculateDepthForNode = function (node) {
2239
+ if (isHidden(node)) {
2240
+ return Infinity;
2241
+ }
2242
+ var depth = 0;
2243
+ var parent = node.parentNode;
2244
+ while (parent) {
2245
+ depth += 1;
2246
+ parent = parent.parentNode;
2247
+ }
2248
+ return depth;
2249
+ };
2250
+
2251
+ var broadcastActiveObservations = function () {
2252
+ var shallowestDepth = Infinity;
2253
+ var callbacks = [];
2254
+ resizeObservers.forEach(function processObserver(ro) {
2255
+ if (ro.activeTargets.length === 0) {
2256
+ return;
2257
+ }
2258
+ var entries = [];
2259
+ ro.activeTargets.forEach(function processTarget(ot) {
2260
+ var entry = new ResizeObserverEntry(ot.target);
2261
+ var targetDepth = calculateDepthForNode(ot.target);
2262
+ entries.push(entry);
2263
+ ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
2264
+ if (targetDepth < shallowestDepth) {
2265
+ shallowestDepth = targetDepth;
2266
+ }
2267
+ });
2268
+ callbacks.push(function resizeObserverCallback() {
2269
+ ro.callback.call(ro.observer, entries, ro.observer);
2270
+ });
2271
+ ro.activeTargets.splice(0, ro.activeTargets.length);
2272
+ });
2273
+ for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
2274
+ var callback = callbacks_1[_i];
2275
+ callback();
2276
+ }
2277
+ return shallowestDepth;
2278
+ };
2279
+
2280
+ var gatherActiveObservationsAtDepth = function (depth) {
2281
+ resizeObservers.forEach(function processObserver(ro) {
2282
+ ro.activeTargets.splice(0, ro.activeTargets.length);
2283
+ ro.skippedTargets.splice(0, ro.skippedTargets.length);
2284
+ ro.observationTargets.forEach(function processTarget(ot) {
2285
+ if (ot.isActive()) {
2286
+ if (calculateDepthForNode(ot.target) > depth) {
2287
+ ro.activeTargets.push(ot);
2288
+ }
2289
+ else {
2290
+ ro.skippedTargets.push(ot);
2291
+ }
2292
+ }
2293
+ });
2294
+ });
2295
+ };
2296
+
2297
+ var process = function () {
2298
+ var depth = 0;
2299
+ gatherActiveObservationsAtDepth(depth);
2300
+ while (hasActiveObservations()) {
2301
+ depth = broadcastActiveObservations();
2302
+ gatherActiveObservationsAtDepth(depth);
2303
+ }
2304
+ if (hasSkippedObservations()) {
2305
+ deliverResizeLoopError();
2306
+ }
2307
+ return depth > 0;
2308
+ };
2309
+
2310
+ var trigger;
2311
+ var callbacks = [];
2312
+ var notify = function () { return callbacks.splice(0).forEach(function (cb) { return cb(); }); };
2313
+ var queueMicroTask = function (callback) {
2314
+ if (!trigger) {
2315
+ var toggle_1 = 0;
2316
+ var el_1 = document.createTextNode('');
2317
+ var config = { characterData: true };
2318
+ new MutationObserver(function () { return notify(); }).observe(el_1, config);
2319
+ trigger = function () { el_1.textContent = "".concat(toggle_1 ? toggle_1-- : toggle_1++); };
2320
+ }
2321
+ callbacks.push(callback);
2322
+ trigger();
2323
+ };
2324
+
2325
+ var queueResizeObserver = function (cb) {
2326
+ queueMicroTask(function ResizeObserver() {
2327
+ requestAnimationFrame(cb);
2328
+ });
2329
+ };
2330
+
2331
+ var watching = 0;
2332
+ var isWatching = function () { return !!watching; };
2333
+ var CATCH_PERIOD = 250;
2334
+ var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
2335
+ var events = [
2336
+ 'resize',
2337
+ 'load',
2338
+ 'transitionend',
2339
+ 'animationend',
2340
+ 'animationstart',
2341
+ 'animationiteration',
2342
+ 'keyup',
2343
+ 'keydown',
2344
+ 'mouseup',
2345
+ 'mousedown',
2346
+ 'mouseover',
2347
+ 'mouseout',
2348
+ 'blur',
2349
+ 'focus'
2350
+ ];
2351
+ var time = function (timeout) {
2352
+ if (timeout === void 0) { timeout = 0; }
2353
+ return Date.now() + timeout;
2354
+ };
2355
+ var scheduled = false;
2356
+ var Scheduler = (function () {
2357
+ function Scheduler() {
2358
+ var _this = this;
2359
+ this.stopped = true;
2360
+ this.listener = function () { return _this.schedule(); };
2361
+ }
2362
+ Scheduler.prototype.run = function (timeout) {
2363
+ var _this = this;
2364
+ if (timeout === void 0) { timeout = CATCH_PERIOD; }
2365
+ if (scheduled) {
2366
+ return;
2367
+ }
2368
+ scheduled = true;
2369
+ var until = time(timeout);
2370
+ queueResizeObserver(function () {
2371
+ var elementsHaveResized = false;
2372
+ try {
2373
+ elementsHaveResized = process();
2374
+ }
2375
+ finally {
2376
+ scheduled = false;
2377
+ timeout = until - time();
2378
+ if (!isWatching()) {
2379
+ return;
2380
+ }
2381
+ if (elementsHaveResized) {
2382
+ _this.run(1000);
2383
+ }
2384
+ else if (timeout > 0) {
2385
+ _this.run(timeout);
2386
+ }
2387
+ else {
2388
+ _this.start();
2389
+ }
2390
+ }
2391
+ });
2392
+ };
2393
+ Scheduler.prototype.schedule = function () {
2394
+ this.stop();
2395
+ this.run();
2396
+ };
2397
+ Scheduler.prototype.observe = function () {
2398
+ var _this = this;
2399
+ var cb = function () { return _this.observer && _this.observer.observe(document.body, observerConfig); };
2400
+ document.body ? cb() : global$1.addEventListener('DOMContentLoaded', cb);
2401
+ };
2402
+ Scheduler.prototype.start = function () {
2403
+ var _this = this;
2404
+ if (this.stopped) {
2405
+ this.stopped = false;
2406
+ this.observer = new MutationObserver(this.listener);
2407
+ this.observe();
2408
+ events.forEach(function (name) { return global$1.addEventListener(name, _this.listener, true); });
2409
+ }
2410
+ };
2411
+ Scheduler.prototype.stop = function () {
2412
+ var _this = this;
2413
+ if (!this.stopped) {
2414
+ this.observer && this.observer.disconnect();
2415
+ events.forEach(function (name) { return global$1.removeEventListener(name, _this.listener, true); });
2416
+ this.stopped = true;
2417
+ }
2418
+ };
2419
+ return Scheduler;
2420
+ }());
2421
+ var scheduler$1 = new Scheduler();
2422
+ var updateCount = function (n) {
2423
+ !watching && n > 0 && scheduler$1.start();
2424
+ watching += n;
2425
+ !watching && scheduler$1.stop();
2426
+ };
2427
+
2428
+ var skipNotifyOnElement = function (target) {
2429
+ return !isSVG(target)
2430
+ && !isReplacedElement(target)
2431
+ && getComputedStyle(target).display === 'inline';
2432
+ };
2433
+ var ResizeObservation = (function () {
2434
+ function ResizeObservation(target, observedBox) {
2435
+ this.target = target;
2436
+ this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
2437
+ this.lastReportedSize = {
2438
+ inlineSize: 0,
2439
+ blockSize: 0
2440
+ };
2441
+ }
2442
+ ResizeObservation.prototype.isActive = function () {
2443
+ var size = calculateBoxSize(this.target, this.observedBox, true);
2444
+ if (skipNotifyOnElement(this.target)) {
2445
+ this.lastReportedSize = size;
2446
+ }
2447
+ if (this.lastReportedSize.inlineSize !== size.inlineSize
2448
+ || this.lastReportedSize.blockSize !== size.blockSize) {
2449
+ return true;
2450
+ }
2451
+ return false;
2452
+ };
2453
+ return ResizeObservation;
2454
+ }());
2455
+
2456
+ var ResizeObserverDetail = (function () {
2457
+ function ResizeObserverDetail(resizeObserver, callback) {
2458
+ this.activeTargets = [];
2459
+ this.skippedTargets = [];
2460
+ this.observationTargets = [];
2461
+ this.observer = resizeObserver;
2462
+ this.callback = callback;
2463
+ }
2464
+ return ResizeObserverDetail;
2465
+ }());
2466
+
2467
+ var observerMap = new WeakMap();
2468
+ var getObservationIndex = function (observationTargets, target) {
2469
+ for (var i = 0; i < observationTargets.length; i += 1) {
2470
+ if (observationTargets[i].target === target) {
2471
+ return i;
2472
+ }
2473
+ }
2474
+ return -1;
2475
+ };
2476
+ var ResizeObserverController = (function () {
2477
+ function ResizeObserverController() {
2478
+ }
2479
+ ResizeObserverController.connect = function (resizeObserver, callback) {
2480
+ var detail = new ResizeObserverDetail(resizeObserver, callback);
2481
+ observerMap.set(resizeObserver, detail);
2482
+ };
2483
+ ResizeObserverController.observe = function (resizeObserver, target, options) {
2484
+ var detail = observerMap.get(resizeObserver);
2485
+ var firstObservation = detail.observationTargets.length === 0;
2486
+ if (getObservationIndex(detail.observationTargets, target) < 0) {
2487
+ firstObservation && resizeObservers.push(detail);
2488
+ detail.observationTargets.push(new ResizeObservation(target, options && options.box));
2489
+ updateCount(1);
2490
+ scheduler$1.schedule();
2491
+ }
2492
+ };
2493
+ ResizeObserverController.unobserve = function (resizeObserver, target) {
2494
+ var detail = observerMap.get(resizeObserver);
2495
+ var index = getObservationIndex(detail.observationTargets, target);
2496
+ var lastObservation = detail.observationTargets.length === 1;
2497
+ if (index >= 0) {
2498
+ lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
2499
+ detail.observationTargets.splice(index, 1);
2500
+ updateCount(-1);
2501
+ }
2502
+ };
2503
+ ResizeObserverController.disconnect = function (resizeObserver) {
2504
+ var _this = this;
2505
+ var detail = observerMap.get(resizeObserver);
2506
+ detail.observationTargets.slice().forEach(function (ot) { return _this.unobserve(resizeObserver, ot.target); });
2507
+ detail.activeTargets.splice(0, detail.activeTargets.length);
2508
+ };
2509
+ return ResizeObserverController;
2510
+ }());
2511
+
2512
+ var ResizeObserver = (function () {
2513
+ function ResizeObserver(callback) {
2514
+ if (arguments.length === 0) {
2515
+ throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
2516
+ }
2517
+ if (typeof callback !== 'function') {
2518
+ throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
2519
+ }
2520
+ ResizeObserverController.connect(this, callback);
2521
+ }
2522
+ ResizeObserver.prototype.observe = function (target, options) {
2523
+ if (arguments.length === 0) {
2524
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
2525
+ }
2526
+ if (!isElement(target)) {
2527
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
2528
+ }
2529
+ ResizeObserverController.observe(this, target, options);
2530
+ };
2531
+ ResizeObserver.prototype.unobserve = function (target) {
2532
+ if (arguments.length === 0) {
2533
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
2534
+ }
2535
+ if (!isElement(target)) {
2536
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
2537
+ }
2538
+ ResizeObserverController.unobserve(this, target);
2539
+ };
2540
+ ResizeObserver.prototype.disconnect = function () {
2541
+ ResizeObserverController.disconnect(this);
2542
+ };
2543
+ ResizeObserver.toString = function () {
2544
+ return 'function ResizeObserver () { [polyfill code] }';
2545
+ };
2546
+ return ResizeObserver;
2547
+ }());
2548
+
2010
2549
  /**
2011
2550
  * Leaf content strings.
2012
2551
  */
@@ -2151,6 +2690,22 @@
2151
2690
  return editor;
2152
2691
  };
2153
2692
 
2693
+ /**
2694
+ * Returns a set of rules that use the `:where` selector if it is supported,
2695
+ * otherwise it falls back to the provided selector on its own.
2696
+ *
2697
+ * The `:where` selector is used to give a selector a lower specificity,
2698
+ * allowing the rule to be overridden by a user-defined stylesheet.
2699
+ *
2700
+ * Older browsers do not support the `:where` selector.
2701
+ * If it is not supported, the selector will be used without `:where`,
2702
+ * which means that the rule will have a higher specificity and a user-defined
2703
+ * stylesheet will not be able to override it easily.
2704
+ */
2705
+ function whereIfSupported(selector, styles) {
2706
+ return "@supports (selector(:where(".concat(selector, "))) {") + ":where(".concat(selector, ") { ").concat(styles, " }") + "}" + "@supports not (selector(:where(".concat(selector, "))) {") + "".concat(selector, " { ").concat(styles, " }") + "}";
2707
+ }
2708
+
2154
2709
  /**
2155
2710
  * Individual leaves in a text node with unique formatting.
2156
2711
  */
@@ -2190,7 +2745,8 @@
2190
2745
  if (placeholderEl) placeholderResizeObserver.current.observe(placeholderEl);
2191
2746
  } else if (placeholderEl) {
2192
2747
  // Create a new observer and observe the placeholder element.
2193
- placeholderResizeObserver.current = new ResizeObserver(function (_ref) {
2748
+ var ResizeObserver$1 = window.ResizeObserver || ResizeObserver;
2749
+ placeholderResizeObserver.current = new ResizeObserver$1(function (_ref) {
2194
2750
  var _ref2 = _slicedToArray(_ref, 1),
2195
2751
  target = _ref2[0].target;
2196
2752
 
@@ -2198,8 +2754,9 @@
2198
2754
 
2199
2755
  if (styleElement) {
2200
2756
  // Make the min-height the height of the placeholder.
2201
- var minHeight = "".concat(target.clientHeight, "px");
2202
- styleElement.innerHTML = ":where([data-slate-editor-id=\"".concat(editor.id, "\"]) { min-height: ").concat(minHeight, "; }");
2757
+ var selector = "[data-slate-editor-id=\"".concat(editor.id, "\"]");
2758
+ var styles = "min-height: ".concat(target.clientHeight, "px;");
2759
+ styleElement.innerHTML = whereIfSupported(selector, styles);
2203
2760
  }
2204
2761
  });
2205
2762
  placeholderResizeObserver.current.observe(placeholderEl);
@@ -2328,7 +2885,7 @@
2328
2885
  * Element.
2329
2886
  */
2330
2887
 
2331
- var Element = function Element(props) {
2888
+ var Element$1 = function Element(props) {
2332
2889
  var decorations = props.decorations,
2333
2890
  element = props.element,
2334
2891
  _props$renderElement = props.renderElement,
@@ -2426,7 +2983,7 @@
2426
2983
  });
2427
2984
  };
2428
2985
 
2429
- var MemoizedElement = /*#__PURE__*/React__default['default'].memo(Element, function (prev, next) {
2986
+ var MemoizedElement = /*#__PURE__*/React__default['default'].memo(Element$1, function (prev, next) {
2430
2987
  return prev.element === next.element && prev.renderElement === next.renderElement && prev.renderLeaf === next.renderLeaf && isDecoratorRangeListEqual(prev.decorations, next.decorations) && (prev.selection === next.selection || !!prev.selection && !!next.selection && slate.Range.equals(prev.selection, next.selection));
2431
2988
  });
2432
2989
  /**
@@ -3375,7 +3932,7 @@
3375
3932
 
3376
3933
  var parentBlock = slate.Editor.above(editor, {
3377
3934
  match: function match(n) {
3378
- return slate.Editor.isBlock(editor, n);
3935
+ return slate.Element.isElement(n) && slate.Editor.isBlock(editor, n);
3379
3936
  },
3380
3937
  at: path
3381
3938
  });
@@ -4828,7 +5385,7 @@
4828
5385
  var block = slate.Editor.above(editor, {
4829
5386
  at: anchor.path,
4830
5387
  match: function match(n) {
4831
- return slate.Editor.isBlock(editor, n);
5388
+ return slate.Element.isElement(n) && slate.Editor.isBlock(editor, n);
4832
5389
  }
4833
5390
  });
4834
5391
 
@@ -5119,12 +5676,13 @@
5119
5676
  // Set global default styles for editors.
5120
5677
  var defaultStylesElement = document.createElement('style');
5121
5678
  defaultStylesElement.setAttribute('data-slate-default-styles', 'true');
5122
- defaultStylesElement.innerHTML = // :where is used to give these rules lower specificity so user stylesheets can override them.
5123
- ":where([data-slate-editor]) {" + // Allow positioning relative to the editable element.
5679
+ var selector = '[data-slate-editor]';
5680
+ var defaultStyles = // Allow positioning relative to the editable element.
5124
5681
  "position: relative;" + // Prevent the default outline styles.
5125
5682
  "outline: none;" + // Preserve adjacent whitespace and new lines.
5126
5683
  "white-space: pre-wrap;" + // Allow words to break if they are too long.
5127
- "word-wrap: break-word;" + "}";
5684
+ "word-wrap: break-word;";
5685
+ defaultStylesElement.innerHTML = whereIfSupported(selector, defaultStyles);
5128
5686
  document.head.appendChild(defaultStylesElement);
5129
5687
  }
5130
5688
 
@@ -5280,12 +5838,12 @@
5280
5838
  if (event.detail === TRIPLE_CLICK && path.length >= 1) {
5281
5839
  var blockPath = path;
5282
5840
 
5283
- if (!slate.Editor.isBlock(editor, node)) {
5841
+ if (!(slate.Element.isElement(node) && slate.Editor.isBlock(editor, node))) {
5284
5842
  var _block$;
5285
5843
 
5286
5844
  var block = slate.Editor.above(editor, {
5287
5845
  match: function match(n) {
5288
- return slate.Editor.isBlock(editor, n);
5846
+ return slate.Element.isElement(n) && slate.Editor.isBlock(editor, n);
5289
5847
  },
5290
5848
  at: path
5291
5849
  });
@@ -5381,7 +5939,7 @@
5381
5939
 
5382
5940
  var inline = slate.Editor.above(editor, {
5383
5941
  match: function match(n) {
5384
- return slate.Editor.isInline(editor, n);
5942
+ return slate.Element.isElement(n) && slate.Editor.isInline(editor, n);
5385
5943
  },
5386
5944
  mode: 'highest'
5387
5945
  });
@@ -5433,7 +5991,7 @@
5433
5991
  // default, and calling `preventDefault` hides the cursor.
5434
5992
  var node = ReactEditor.toSlateNode(editor, event.target);
5435
5993
 
5436
- if (slate.Editor.isVoid(editor, node)) {
5994
+ if (slate.Element.isElement(node) && slate.Editor.isVoid(editor, node)) {
5437
5995
  event.preventDefault();
5438
5996
  }
5439
5997
  }
@@ -5442,7 +6000,7 @@
5442
6000
  if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
5443
6001
  var node = ReactEditor.toSlateNode(editor, event.target);
5444
6002
  var path = ReactEditor.findPath(editor, node);
5445
- var voidMatch = slate.Editor.isVoid(editor, node) || slate.Editor["void"](editor, {
6003
+ var voidMatch = slate.Element.isElement(node) && slate.Editor.isVoid(editor, node) || slate.Editor["void"](editor, {
5446
6004
  at: path,
5447
6005
  voids: true
5448
6006
  }); // If starting a drag on a void node, make sure it is selected
@@ -6096,8 +6654,8 @@
6096
6654
  });
6097
6655
  handleSelectorChange(editor);
6098
6656
  }, [onChange]);
6099
- EDITOR_TO_ON_CHANGE.set(editor, onContextChange);
6100
6657
  React.useEffect(function () {
6658
+ EDITOR_TO_ON_CHANGE.set(editor, onContextChange);
6101
6659
  return function () {
6102
6660
  EDITOR_TO_ON_CHANGE.set(editor, function () {});
6103
6661
  unmountRef.current = true;
@@ -33722,7 +34280,7 @@
33722
34280
  if (e.selection && slate.Range.isCollapsed(e.selection)) {
33723
34281
  var parentBlockEntry = slate.Editor.above(e, {
33724
34282
  match: function match(n) {
33725
- return slate.Editor.isBlock(e, n);
34283
+ return slate.Element.isElement(n) && slate.Editor.isBlock(e, n);
33726
34284
  },
33727
34285
  at: e.selection
33728
34286
  });