@contentful/field-editor-rich-text 4.9.0 → 4.9.2

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.
@@ -25,6 +25,7 @@ const _emotion = require("emotion");
25
25
  const _fastdeepequal = /*#__PURE__*/ _interop_require_default(require("fast-deep-equal"));
26
26
  const _noop = /*#__PURE__*/ _interop_require_default(require("lodash/noop"));
27
27
  const _ContentfulEditorProvider = require("./ContentfulEditorProvider");
28
+ const _editoroverrides = require("./editor-overrides");
28
29
  const _toSlateValue = require("./helpers/toSlateValue");
29
30
  const _misc = require("./internal/misc");
30
31
  const _plugins = require("./plugins");
@@ -127,7 +128,8 @@ const ConnectedRichTextEditor = (props)=>{
127
128
  }), /*#__PURE__*/ _react.createElement(_platecommon.PlateContent, {
128
129
  id: id,
129
130
  className: classNames,
130
- readOnly: props.isDisabled
131
+ readOnly: props.isDisabled,
132
+ scrollSelectionIntoView: _editoroverrides.defaultScrollSelectionIntoView
131
133
  }))))));
132
134
  };
133
135
  const RichTextEditor = (props)=>{
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./scroll-selection-into-view"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "defaultScrollSelectionIntoView", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return defaultScrollSelectionIntoView;
9
+ }
10
+ });
11
+ const _scrollintoviewifneeded = /*#__PURE__*/ _interop_require_default(require("scroll-into-view-if-needed"));
12
+ const _internal = require("../internal");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const defaultScrollSelectionIntoView = (editor, domRange)=>{
19
+ if (domRange.getBoundingClientRect && (!editor.selection || editor.selection && _internal.Range.isCollapsed(editor.selection))) {
20
+ const leafEl = domRange.startContainer.parentElement;
21
+ const domRect = domRange.getBoundingClientRect();
22
+ const isZeroDimensionRect = domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0;
23
+ if (isZeroDimensionRect) {
24
+ const leafRect = leafEl.getBoundingClientRect();
25
+ const leafHasDimensions = leafRect.width > 0 || leafRect.height > 0;
26
+ if (leafHasDimensions) {
27
+ return;
28
+ }
29
+ }
30
+ leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
31
+ (0, _scrollintoviewifneeded.default)(leafEl, {
32
+ scrollMode: 'if-needed'
33
+ });
34
+ delete leafEl.getBoundingClientRect;
35
+ }
36
+ };
@@ -2,3 +2,52 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ Object.defineProperty(exports, "Range", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Range;
9
+ }
10
+ });
11
+ const _slate = /*#__PURE__*/ _interop_require_wildcard(require("slate"));
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function") return null;
14
+ var cacheBabelInterop = new WeakMap();
15
+ var cacheNodeInterop = new WeakMap();
16
+ return (_getRequireWildcardCache = function(nodeInterop) {
17
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
+ })(nodeInterop);
19
+ }
20
+ function _interop_require_wildcard(obj, nodeInterop) {
21
+ if (!nodeInterop && obj && obj.__esModule) {
22
+ return obj;
23
+ }
24
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
+ return {
26
+ default: obj
27
+ };
28
+ }
29
+ var cache = _getRequireWildcardCache(nodeInterop);
30
+ if (cache && cache.has(obj)) {
31
+ return cache.get(obj);
32
+ }
33
+ var newObj = {
34
+ __proto__: null
35
+ };
36
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
+ for(var key in obj){
38
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
39
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
40
+ if (desc && (desc.get || desc.set)) {
41
+ Object.defineProperty(newObj, key, desc);
42
+ } else {
43
+ newObj[key] = obj[key];
44
+ }
45
+ }
46
+ }
47
+ newObj.default = obj;
48
+ if (cache) {
49
+ cache.set(obj, newObj);
50
+ }
51
+ return newObj;
52
+ }
53
+ const Range = _slate.Range;
@@ -7,6 +7,7 @@ import { css, cx } from 'emotion';
7
7
  import deepEquals from 'fast-deep-equal';
8
8
  import noop from 'lodash/noop';
9
9
  import { ContentfulEditorIdProvider, getContentfulEditorId } from './ContentfulEditorProvider';
10
+ import { defaultScrollSelectionIntoView } from './editor-overrides';
10
11
  import { toSlateValue } from './helpers/toSlateValue';
11
12
  import { normalizeInitialValue } from './internal/misc';
12
13
  import { getPlugins, disableCorePlugins } from './plugins';
@@ -63,7 +64,8 @@ export const ConnectedRichTextEditor = (props)=>{
63
64
  }), /*#__PURE__*/ React.createElement(PlateContent, {
64
65
  id: id,
65
66
  className: classNames,
66
- readOnly: props.isDisabled
67
+ readOnly: props.isDisabled,
68
+ scrollSelectionIntoView: defaultScrollSelectionIntoView
67
69
  }))))));
68
70
  };
69
71
  const RichTextEditor = (props)=>{
@@ -0,0 +1 @@
1
+ export * from './scroll-selection-into-view';
@@ -0,0 +1,21 @@
1
+ import scrollIntoView from 'scroll-into-view-if-needed';
2
+ import { Range } from '../internal';
3
+ export const defaultScrollSelectionIntoView = (editor, domRange)=>{
4
+ if (domRange.getBoundingClientRect && (!editor.selection || editor.selection && Range.isCollapsed(editor.selection))) {
5
+ const leafEl = domRange.startContainer.parentElement;
6
+ const domRect = domRange.getBoundingClientRect();
7
+ const isZeroDimensionRect = domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0;
8
+ if (isZeroDimensionRect) {
9
+ const leafRect = leafEl.getBoundingClientRect();
10
+ const leafHasDimensions = leafRect.width > 0 || leafRect.height > 0;
11
+ if (leafHasDimensions) {
12
+ return;
13
+ }
14
+ }
15
+ leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
16
+ scrollIntoView(leafEl, {
17
+ scrollMode: 'if-needed'
18
+ });
19
+ delete leafEl.getBoundingClientRect;
20
+ }
21
+ };
@@ -1 +1,2 @@
1
- export { };
1
+ import * as s from 'slate';
2
+ export const Range = s.Range;
@@ -0,0 +1 @@
1
+ export * from './scroll-selection-into-view';
@@ -0,0 +1,2 @@
1
+ import { DOMRange, ReactEditor } from '../internal';
2
+ export declare const defaultScrollSelectionIntoView: (editor: ReactEditor, domRange: DOMRange) => void;
@@ -5,6 +5,7 @@ import { MARKS } from '@contentful/rich-text-types';
5
5
  import * as p from '@udecode/plate-common';
6
6
  import * as s from 'slate';
7
7
  import * as sr from 'slate-react';
8
+ import { DOMRange as SlateReactDomRange } from 'slate-react/dist/utils/dom';
8
9
  import type { SelectionMoveOptions as SlateSelectionMoveOptions, SelectionCollapseOptions as SlateSelectionCollapseOptions } from 'slate/dist/interfaces/transforms/selection';
9
10
  import type { TextInsertTextOptions as SlateTextInsertTextOptions } from 'slate/dist/interfaces/transforms/text';
10
11
  import { TrackingPluginActions } from '../../plugins/Tracking';
@@ -59,3 +60,5 @@ export type Span = p.TSpan;
59
60
  export type BasePoint = s.BasePoint;
60
61
  export type BaseSelection = s.BaseSelection;
61
62
  export type PathRef = s.PathRef;
63
+ export type DOMRange = SlateReactDomRange;
64
+ export declare const Range: s.RangeInterface;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "4.9.0",
3
+ "version": "4.9.2",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,7 +44,7 @@
44
44
  "@contentful/f36-icons": "^4.29.0",
45
45
  "@contentful/f36-tokens": "^4.0.5",
46
46
  "@contentful/f36-utils": "^4.24.3",
47
- "@contentful/field-editor-reference": "^6.10.0",
47
+ "@contentful/field-editor-reference": "^6.10.1",
48
48
  "@contentful/field-editor-shared": "^2.9.0",
49
49
  "@contentful/rich-text-plain-text-renderer": "^17.0.0",
50
50
  "@contentful/rich-text-types": "^17.0.0",
@@ -88,5 +88,5 @@
88
88
  "publishConfig": {
89
89
  "registry": "https://npm.pkg.github.com/"
90
90
  },
91
- "gitHead": "44e5546797a12db4d96f290e039a483297265ffa"
91
+ "gitHead": "c43c17b9bb1036b1d5aec267ad45adc8c136d528"
92
92
  }