@contentful/field-editor-rich-text 2.0.0-next.7 → 2.0.0-next.8

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.
@@ -12,7 +12,7 @@ import constate from 'constate';
12
12
  import { createDeserializeDocxPlugin } from '@udecode/plate-serializer-docx';
13
13
  import { createSoftBreakPlugin as createSoftBreakPlugin$1, createExitBreakPlugin as createExitBreakPlugin$1 } from '@udecode/plate-break';
14
14
  import isHotkey from 'is-hotkey';
15
- import { useSelected, useReadOnly, ReactEditor, useFocused } from 'slate-react';
15
+ import { ReactEditor, useSelected, useReadOnly, useFocused } from 'slate-react';
16
16
  import { AssetCard, Menu, Text as Text$1, Notification, EntryCard, MenuItem, Button, Flex, Icon, InlineEntryCard, Tooltip, ModalContent, Form, FormControl, TextInput, Select, FormLabel, TextLink, ModalControls, IconButton } from '@contentful/f36-components';
17
17
  import mimetype from '@contentful/mimetype';
18
18
  import get from 'lodash-es/get';
@@ -484,6 +484,18 @@ function getParents(el) {
484
484
  return parents;
485
485
  }
486
486
 
487
+ // "modern" Edge was released at 79.x
488
+ var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
489
+ // and older, Chrome 76+ can use `beforeInput` though.
490
+
491
+ var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
492
+ // Chrome Legacy doesn't support `beforeinput` correctly
493
+
494
+ var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
495
+ typeof globalThis !== 'undefined' && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'; // The `getTargetRanges` property isn't recognized.
496
+
497
+ var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
498
+
487
499
  var LINK_TYPES = [INLINES.HYPERLINK, INLINES.ENTRY_HYPERLINK, INLINES.ASSET_HYPERLINK];
488
500
  function isBlockSelected(editor, type) {
489
501
  var _Array$from = Array.from(Editor.nodes(editor, {
@@ -701,6 +713,17 @@ var isInlineOrText = function isInlineOrText(node) {
701
713
  // either text or inline elements
702
714
  return Text.isText(node) || Element.isElement(node) && INLINE_TYPES.includes(node.type);
703
715
  };
716
+ var focus = function focus(editor) {
717
+ var x = window.scrollX;
718
+ var y = window.scrollY;
719
+ ReactEditor.focus(editor); // Safari has issues with `editor.focus({ preventScroll: true })`, it ignores the option `preventScroll`
720
+
721
+ if (IS_SAFARI) {
722
+ setTimeout(function () {
723
+ window.scrollTo(x, y); // restore position
724
+ }, 0);
725
+ }
726
+ };
704
727
 
705
728
  function withLinkTracking(tracking, Component) {
706
729
  return function ComponentWithTracking(props) {
@@ -712,16 +735,6 @@ function withLinkTracking(tracking, Component) {
712
735
  };
713
736
  }
714
737
 
715
- // "modern" Edge was released at 79.x
716
- var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
717
- // and older, Chrome 76+ can use `beforeInput` though.
718
-
719
- var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
720
- // Chrome Legacy doesn't support `beforeinput` correctly
721
-
722
- var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
723
- typeof globalThis !== 'undefined' && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'; // The `getTargetRanges` property isn't recognized.
724
-
725
738
  function useSdk(_ref) {
726
739
  var sdk = _ref.sdk;
727
740
  var sdkMemo = useMemo(function () {
@@ -1100,7 +1113,7 @@ function FetchingWrappedEntryCard(props) {
1100
1113
 
1101
1114
  var styles$3 = {
1102
1115
  root: /*#__PURE__*/css({
1103
- marginBottom: '1.25rem'
1116
+ marginBottom: '1.25rem !important'
1104
1117
  })
1105
1118
  };
1106
1119
  function LinkedEntityBlock(props) {
@@ -1260,9 +1273,11 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1260
1273
 
1261
1274
 
1262
1275
  var IteratorPrototype = {};
1263
- define(IteratorPrototype, iteratorSymbol, function () {
1276
+
1277
+ IteratorPrototype[iteratorSymbol] = function () {
1264
1278
  return this;
1265
- });
1279
+ };
1280
+
1266
1281
  var getProto = Object.getPrototypeOf;
1267
1282
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1268
1283
 
@@ -1273,9 +1288,8 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1273
1288
  }
1274
1289
 
1275
1290
  var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1276
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
1277
- define(Gp, "constructor", GeneratorFunctionPrototype);
1278
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
1291
+ GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
1292
+ GeneratorFunctionPrototype.constructor = GeneratorFunction;
1279
1293
  GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
1280
1294
  // Iterator interface in terms of a single ._invoke method.
1281
1295
 
@@ -1380,9 +1394,11 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1380
1394
  }
1381
1395
 
1382
1396
  defineIteratorMethods(AsyncIterator.prototype);
1383
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1397
+
1398
+ AsyncIterator.prototype[asyncIteratorSymbol] = function () {
1384
1399
  return this;
1385
- });
1400
+ };
1401
+
1386
1402
  exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
1387
1403
  // AsyncIterator objects; they just return a Promise for the value of
1388
1404
  // the final result produced by the iterator.
@@ -1559,12 +1575,13 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1559
1575
  // object to not be returned from this call. This ensures that doesn't happen.
1560
1576
  // See https://github.com/facebook/regenerator/issues/274 for more details.
1561
1577
 
1562
- define(Gp, iteratorSymbol, function () {
1578
+ Gp[iteratorSymbol] = function () {
1563
1579
  return this;
1564
- });
1565
- define(Gp, "toString", function () {
1580
+ };
1581
+
1582
+ Gp.toString = function () {
1566
1583
  return "[object Generator]";
1567
- });
1584
+ };
1568
1585
 
1569
1586
  function pushTryEntry(locs) {
1570
1587
  var entry = {
@@ -1876,19 +1893,14 @@ var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
1876
1893
  } catch (accidentalStrictMode) {
1877
1894
  // This module should not be running in strict mode, so the above
1878
1895
  // assignment should always work unless something is misconfigured. Just
1879
- // in case runtime.js accidentally runs in strict mode, in modern engines
1880
- // we can explicitly access globalThis. In older engines we can escape
1896
+ // in case runtime.js accidentally runs in strict mode, we can escape
1881
1897
  // strict mode using a global Function call. This could conceivably fail
1882
1898
  // if a Content Security Policy forbids using Function, but in that case
1883
1899
  // the proper solution is to fix the accidental strict mode problem. If
1884
1900
  // you've misconfigured your bundler to force strict mode and applied a
1885
1901
  // CSP to forbid Function, and you're not willing to fix either of those
1886
1902
  // problems, please detail your unique predicament in a GitHub issue.
1887
- if (typeof globalThis === "object") {
1888
- globalThis.regeneratorRuntime = runtime;
1889
- } else {
1890
- Function("r", "regeneratorRuntime = r")(runtime);
1891
- }
1903
+ Function("r", "regeneratorRuntime = r")(runtime);
1892
1904
  }
1893
1905
  });
1894
1906
 
@@ -2064,7 +2076,7 @@ function insertBlock(editor, nodeType, entity) {
2064
2076
  Transforms.setNodes(editor, linkedEntityBlock);
2065
2077
  }
2066
2078
 
2067
- ReactEditor.focus(editor);
2079
+ focus(editor);
2068
2080
  }
2069
2081
 
2070
2082
  var styles$4 = {
@@ -2402,7 +2414,7 @@ function _selectEntityAndInsert$1() {
2402
2414
 
2403
2415
  case 4:
2404
2416
  entry = _context2.sent;
2405
- ReactEditor.focus(editor); // Dialog steals focus from editor, return it.
2417
+ focus(editor); // Dialog steals focus from editor, return it.
2406
2418
 
2407
2419
  if (entry) {
2408
2420
  _context2.next = 8;
@@ -2620,7 +2632,7 @@ function ToolbarHeadingButton(props) {
2620
2632
  position.*/
2621
2633
 
2622
2634
  editor.onChange = function () {
2623
- ReactEditor.focus(editor);
2635
+ focus(editor);
2624
2636
  editor.onChange = prevOnChange;
2625
2637
  prevOnChange.apply(void 0, arguments);
2626
2638
  };
@@ -2915,7 +2927,7 @@ function ToolbarHrButton(props) {
2915
2927
  hasText ? Transforms.insertNodes(editor, hr) : setNodes(editor, hr); // Move focus to the next paragraph (added by TrailingParagraph plugin)
2916
2928
 
2917
2929
  moveToTheNextLine(editor);
2918
- ReactEditor.focus(editor);
2930
+ focus(editor);
2919
2931
  }
2920
2932
 
2921
2933
  if (!editor) return null;
@@ -3407,7 +3419,7 @@ function _addOrEditLink() {
3407
3419
  path: path
3408
3420
  });
3409
3421
  });
3410
- ReactEditor.focus(editor);
3422
+ focus(editor);
3411
3423
 
3412
3424
  case 15:
3413
3425
  case "end":
@@ -4161,7 +4173,7 @@ function ToolbarListButton(props) {
4161
4173
  toggleList(editor, {
4162
4174
  type: type
4163
4175
  });
4164
- ReactEditor.focus(editor);
4176
+ focus(editor);
4165
4177
  };
4166
4178
  }
4167
4179
 
@@ -4189,7 +4201,7 @@ function ToolbarBoldButton(props) {
4189
4201
  toggleMark(editor, {
4190
4202
  key: MARKS.BOLD
4191
4203
  });
4192
- ReactEditor.focus(editor);
4204
+ focus(editor);
4193
4205
  }
4194
4206
 
4195
4207
  if (!editor) return null;
@@ -4248,7 +4260,7 @@ function ToolbarCodeButton(props) {
4248
4260
  toggleMark(editor, {
4249
4261
  key: MARKS.CODE
4250
4262
  });
4251
- ReactEditor.focus(editor);
4263
+ focus(editor);
4252
4264
  }
4253
4265
 
4254
4266
  if (!editor) return null;
@@ -4298,7 +4310,7 @@ function ToolbarItalicButton(props) {
4298
4310
  toggleMark(editor, {
4299
4311
  key: MARKS.ITALIC
4300
4312
  });
4301
- ReactEditor.focus(editor);
4313
+ focus(editor);
4302
4314
  }
4303
4315
 
4304
4316
  if (!editor) return null;
@@ -4352,7 +4364,7 @@ function ToolbarUnderlineButton(props) {
4352
4364
  toggleMark(editor, {
4353
4365
  key: MARKS.UNDERLINE
4354
4366
  });
4355
- ReactEditor.focus(editor);
4367
+ focus(editor);
4356
4368
  }
4357
4369
 
4358
4370
  if (!editor) return null;
@@ -4837,7 +4849,7 @@ function ToolbarQuoteButton(props) {
4837
4849
  function handleOnClick() {
4838
4850
  if (!editor) return;
4839
4851
  toggleQuote(editor);
4840
- ReactEditor.focus(editor);
4852
+ focus(editor);
4841
4853
  }
4842
4854
 
4843
4855
  if (!editor) return null;
@@ -5193,11 +5205,7 @@ var TableActions = function TableActions() {
5193
5205
 
5194
5206
  var close = React__default.useCallback(function () {
5195
5207
  setOpen(false);
5196
- if (!editor) return; // Makes sure we keep the editor in focus when clicking on/out
5197
- // the dropdown menu
5198
-
5199
- ReactEditor.focus(editor);
5200
- }, [editor]);
5208
+ }, []);
5201
5209
  React__default.useEffect(function () {
5202
5210
  setHeaderEnabled(Boolean(editor && isTableHeaderEnabled(editor)));
5203
5211
  }, [editor]);
@@ -5466,7 +5474,7 @@ function ToolbarTableButton(props) {
5466
5474
  case 2:
5467
5475
  onViewportAction('insertTable');
5468
5476
  insertTableAndFocusFirstCell(editor);
5469
- ReactEditor.focus(editor);
5477
+ focus(editor);
5470
5478
 
5471
5479
  case 5:
5472
5480
  case "end":
@@ -5610,11 +5618,14 @@ var createVoidsPlugin = function createVoidsPlugin() {
5610
5618
  }, {
5611
5619
  // Inserts a new paragraph on enter when a void element is focused
5612
5620
  hotkey: 'enter',
5621
+ // exploit the internal use of Array.slice(0, level + 1) by the exitBreak plugin
5622
+ // to stay in the parent element
5623
+ level: -2,
5613
5624
  query: {
5614
5625
  filter: function filter(_ref2) {
5615
5626
  var node = _ref2[0],
5616
5627
  path = _ref2[1];
5617
- return !isFirstChild(path) && !!node.isVoid;
5628
+ return !(isRootLevel(path) && isFirstChild(path)) && !!node.isVoid;
5618
5629
  }
5619
5630
  }
5620
5631
  }],