@atlaskit/editor-core 172.0.5 → 172.1.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.
Files changed (207) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/cjs/create-editor/ReactEditorView.js +11 -2
  3. package/dist/cjs/create-editor/ReactEditorViewContext.js +15 -0
  4. package/dist/cjs/create-editor/create-plugins-list.js +2 -1
  5. package/dist/cjs/editor.js +7 -1
  6. package/dist/cjs/labs/next/mobile.js +5 -3
  7. package/dist/cjs/messages.js +5 -0
  8. package/dist/cjs/plugins/analytics/types/enums.js +1 -0
  9. package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/styled.js +1 -1
  10. package/dist/cjs/plugins/card/nodeviews/inlineCard.js +8 -0
  11. package/dist/cjs/plugins/card/pm-plugins/doc.js +2 -26
  12. package/dist/cjs/plugins/card/toolbar.js +118 -86
  13. package/dist/cjs/plugins/code-block/nodeviews/code-block.js +9 -2
  14. package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +37 -1
  15. package/dist/cjs/plugins/code-block/toolbar.js +3 -1
  16. package/dist/cjs/plugins/code-block/ui/class-names.js +2 -0
  17. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +4 -3
  18. package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.js +3 -1
  19. package/dist/cjs/plugins/floating-toolbar/ui/Toolbar.js +42 -2
  20. package/dist/cjs/plugins/hyperlink/Toolbar.js +43 -8
  21. package/dist/cjs/plugins/media/commands/helpers.js +1 -8
  22. package/dist/cjs/plugins/media/index.js +1 -1
  23. package/dist/cjs/plugins/media/nodeviews/mediaNodeView/index.js +0 -10
  24. package/dist/cjs/plugins/media/nodeviews/mediaNodeView/media.js +2 -3
  25. package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +10 -0
  26. package/dist/cjs/plugins/media/picker-facade.js +1 -0
  27. package/dist/cjs/plugins/media/pm-plugins/main.js +3 -13
  28. package/dist/cjs/plugins/panel/pm-plugins/keymaps.js +1 -1
  29. package/dist/cjs/plugins/paste/handlers.js +9 -20
  30. package/dist/cjs/plugins/paste/md.js +8 -2
  31. package/dist/cjs/plugins/paste/newline-md-plugin.js +67 -0
  32. package/dist/cjs/plugins/paste/paragraph-md-plugin.js +72 -0
  33. package/dist/cjs/plugins/table/commands/hover.js +4 -4
  34. package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +2 -1
  35. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  36. package/dist/cjs/plugins/table/utils/decoration.js +53 -3
  37. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -0
  38. package/dist/cjs/plugins/type-ahead/ui/InputQuery.js +3 -2
  39. package/dist/cjs/plugins/type-ahead/ui/TypeAheadList.js +78 -53
  40. package/dist/cjs/plugins/type-ahead/ui/TypeAheadPopup.js +1 -1
  41. package/dist/cjs/ui/Addon/ClickAreaBlock/index.js +7 -2
  42. package/dist/cjs/ui/Addon/ClickAreaMobile/index.js +8 -2
  43. package/dist/cjs/ui/Appearance/Comment/Comment.js +13 -13
  44. package/dist/cjs/ui/Appearance/FullPage/FullPage.js +8 -7
  45. package/dist/cjs/ui/Appearance/FullPage/FullPageContentArea.js +2 -1
  46. package/dist/cjs/ui/Appearance/Mobile.js +4 -2
  47. package/dist/cjs/ui/AppearanceComponents/Mobile.js +5 -4
  48. package/dist/cjs/ui/DropList/index.js +1 -1
  49. package/dist/cjs/ui/DropdownMenu/index.js +5 -5
  50. package/dist/cjs/ui/with-outer-listeners.js +105 -50
  51. package/dist/cjs/utils/deprecation-warnings.js +4 -0
  52. package/dist/cjs/utils/linking-utils.js +40 -1
  53. package/dist/cjs/version-wrapper.js +1 -1
  54. package/dist/cjs/version.json +1 -1
  55. package/dist/es2019/create-editor/ReactEditorView.js +11 -2
  56. package/dist/es2019/create-editor/ReactEditorViewContext.js +3 -0
  57. package/dist/es2019/create-editor/create-plugins-list.js +2 -1
  58. package/dist/es2019/editor.js +7 -1
  59. package/dist/es2019/labs/next/mobile.js +5 -3
  60. package/dist/es2019/messages.js +5 -0
  61. package/dist/es2019/plugins/analytics/types/enums.js +1 -0
  62. package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +1 -1
  63. package/dist/es2019/plugins/card/nodeviews/inlineCard.js +10 -0
  64. package/dist/es2019/plugins/card/pm-plugins/doc.js +1 -24
  65. package/dist/es2019/plugins/card/toolbar.js +114 -86
  66. package/dist/es2019/plugins/code-block/nodeviews/code-block.js +9 -2
  67. package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +40 -2
  68. package/dist/es2019/plugins/code-block/toolbar.js +2 -1
  69. package/dist/es2019/plugins/code-block/ui/class-names.js +2 -0
  70. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +4 -3
  71. package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.js +3 -2
  72. package/dist/es2019/plugins/floating-toolbar/ui/Toolbar.js +37 -0
  73. package/dist/es2019/plugins/hyperlink/Toolbar.js +40 -9
  74. package/dist/es2019/plugins/media/commands/helpers.js +0 -2
  75. package/dist/es2019/plugins/media/index.js +1 -1
  76. package/dist/es2019/plugins/media/nodeviews/mediaNodeView/index.js +0 -7
  77. package/dist/es2019/plugins/media/nodeviews/mediaNodeView/media.js +2 -3
  78. package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +10 -0
  79. package/dist/es2019/plugins/media/picker-facade.js +1 -0
  80. package/dist/es2019/plugins/media/pm-plugins/main.js +3 -13
  81. package/dist/es2019/plugins/panel/pm-plugins/keymaps.js +1 -1
  82. package/dist/es2019/plugins/paste/handlers.js +7 -19
  83. package/dist/es2019/plugins/paste/md.js +6 -2
  84. package/dist/es2019/plugins/paste/newline-md-plugin.js +56 -0
  85. package/dist/es2019/plugins/paste/paragraph-md-plugin.js +61 -0
  86. package/dist/es2019/plugins/table/commands/hover.js +4 -4
  87. package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +2 -1
  88. package/dist/es2019/plugins/table/ui/common-styles.js +39 -0
  89. package/dist/es2019/plugins/table/utils/decoration.js +60 -24
  90. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -0
  91. package/dist/es2019/plugins/type-ahead/ui/InputQuery.js +4 -3
  92. package/dist/es2019/plugins/type-ahead/ui/TypeAheadList.js +78 -59
  93. package/dist/es2019/plugins/type-ahead/ui/TypeAheadPopup.js +2 -2
  94. package/dist/es2019/ui/Addon/ClickAreaBlock/index.js +6 -2
  95. package/dist/es2019/ui/Addon/ClickAreaMobile/index.js +7 -2
  96. package/dist/es2019/ui/Appearance/Comment/Comment.js +12 -6
  97. package/dist/es2019/ui/Appearance/FullPage/FullPage.js +7 -2
  98. package/dist/es2019/ui/Appearance/FullPage/FullPageContentArea.js +2 -1
  99. package/dist/es2019/ui/Appearance/Mobile.js +4 -2
  100. package/dist/es2019/ui/AppearanceComponents/Mobile.js +5 -4
  101. package/dist/es2019/ui/DropList/index.js +1 -1
  102. package/dist/es2019/ui/DropdownMenu/index.js +10 -6
  103. package/dist/es2019/ui/with-outer-listeners.js +83 -33
  104. package/dist/es2019/utils/deprecation-warnings.js +4 -0
  105. package/dist/es2019/utils/linking-utils.js +37 -0
  106. package/dist/es2019/version-wrapper.js +1 -1
  107. package/dist/es2019/version.json +1 -1
  108. package/dist/esm/create-editor/ReactEditorView.js +11 -2
  109. package/dist/esm/create-editor/ReactEditorViewContext.js +3 -0
  110. package/dist/esm/create-editor/create-plugins-list.js +2 -1
  111. package/dist/esm/editor.js +7 -1
  112. package/dist/esm/labs/next/mobile.js +5 -3
  113. package/dist/esm/messages.js +5 -0
  114. package/dist/esm/plugins/analytics/types/enums.js +1 -0
  115. package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +1 -1
  116. package/dist/esm/plugins/card/nodeviews/inlineCard.js +9 -0
  117. package/dist/esm/plugins/card/pm-plugins/doc.js +1 -20
  118. package/dist/esm/plugins/card/toolbar.js +108 -83
  119. package/dist/esm/plugins/code-block/nodeviews/code-block.js +9 -2
  120. package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +37 -2
  121. package/dist/esm/plugins/code-block/toolbar.js +2 -1
  122. package/dist/esm/plugins/code-block/ui/class-names.js +2 -0
  123. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +4 -3
  124. package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.js +3 -2
  125. package/dist/esm/plugins/floating-toolbar/ui/Toolbar.js +41 -2
  126. package/dist/esm/plugins/hyperlink/Toolbar.js +43 -10
  127. package/dist/esm/plugins/media/commands/helpers.js +0 -4
  128. package/dist/esm/plugins/media/index.js +1 -1
  129. package/dist/esm/plugins/media/nodeviews/mediaNodeView/index.js +0 -8
  130. package/dist/esm/plugins/media/nodeviews/mediaNodeView/media.js +2 -3
  131. package/dist/esm/plugins/media/nodeviews/mediaSingle.js +10 -0
  132. package/dist/esm/plugins/media/picker-facade.js +1 -0
  133. package/dist/esm/plugins/media/pm-plugins/main.js +3 -15
  134. package/dist/esm/plugins/panel/pm-plugins/keymaps.js +1 -1
  135. package/dist/esm/plugins/paste/handlers.js +11 -22
  136. package/dist/esm/plugins/paste/md.js +6 -2
  137. package/dist/esm/plugins/paste/newline-md-plugin.js +58 -0
  138. package/dist/esm/plugins/paste/paragraph-md-plugin.js +63 -0
  139. package/dist/esm/plugins/table/commands/hover.js +4 -4
  140. package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +2 -1
  141. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  142. package/dist/esm/plugins/table/utils/decoration.js +50 -3
  143. package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +1 -0
  144. package/dist/esm/plugins/type-ahead/ui/InputQuery.js +4 -3
  145. package/dist/esm/plugins/type-ahead/ui/TypeAheadList.js +77 -51
  146. package/dist/esm/plugins/type-ahead/ui/TypeAheadPopup.js +2 -2
  147. package/dist/esm/ui/Addon/ClickAreaBlock/index.js +7 -2
  148. package/dist/esm/ui/Addon/ClickAreaMobile/index.js +8 -2
  149. package/dist/esm/ui/Appearance/Comment/Comment.js +12 -12
  150. package/dist/esm/ui/Appearance/FullPage/FullPage.js +7 -6
  151. package/dist/esm/ui/Appearance/FullPage/FullPageContentArea.js +2 -1
  152. package/dist/esm/ui/Appearance/Mobile.js +4 -2
  153. package/dist/esm/ui/AppearanceComponents/Mobile.js +5 -4
  154. package/dist/esm/ui/DropList/index.js +1 -1
  155. package/dist/esm/ui/DropdownMenu/index.js +5 -5
  156. package/dist/esm/ui/with-outer-listeners.js +105 -51
  157. package/dist/esm/utils/deprecation-warnings.js +4 -0
  158. package/dist/esm/utils/linking-utils.js +37 -0
  159. package/dist/esm/version-wrapper.js +1 -1
  160. package/dist/esm/version.json +1 -1
  161. package/dist/types/create-editor/ReactEditorView.d.ts +3 -0
  162. package/dist/types/create-editor/ReactEditorViewContext.d.ts +8 -0
  163. package/dist/types/messages.d.ts +5 -0
  164. package/dist/types/plugins/analytics/types/enums.d.ts +1 -0
  165. package/dist/types/plugins/analytics/types/events.d.ts +2 -2
  166. package/dist/types/plugins/analytics/types/link-tool-bar-events.d.ts +1 -0
  167. package/dist/types/plugins/card/nodeviews/inlineCard.d.ts +3 -0
  168. package/dist/types/plugins/card/pm-plugins/doc.d.ts +1 -2
  169. package/dist/types/plugins/card/toolbar.d.ts +1 -0
  170. package/dist/types/plugins/card/ui/ResizableEmbedCard.d.ts +1 -1
  171. package/dist/types/plugins/code-block/pm-plugins/ide-ux.d.ts +4 -1
  172. package/dist/types/plugins/code-block/ui/class-names.d.ts +2 -0
  173. package/dist/types/plugins/hyperlink/types.d.ts +1 -0
  174. package/dist/types/plugins/media/commands/helpers.d.ts +0 -1
  175. package/dist/types/plugins/media/nodeviews/mediaNodeView/index.d.ts +0 -1
  176. package/dist/types/plugins/media/nodeviews/mediaNodeView/media.d.ts +0 -1
  177. package/dist/types/plugins/media/pm-plugins/main.d.ts +0 -2
  178. package/dist/types/plugins/media/pm-plugins/types.d.ts +0 -2
  179. package/dist/types/plugins/media/ui/ResizableMediaSingle/index.d.ts +1 -1
  180. package/dist/types/plugins/paste/newline-md-plugin.d.ts +2 -0
  181. package/dist/types/plugins/paste/paragraph-md-plugin.d.ts +2 -0
  182. package/dist/types/plugins/table/utils/decoration.d.ts +1 -1
  183. package/dist/types/types/editor-appearance-component.d.ts +1 -0
  184. package/dist/types/types/feature-flags.d.ts +9 -0
  185. package/dist/types/ui/Addon/ClickAreaBlock/index.d.ts +1 -0
  186. package/dist/types/ui/Addon/ClickAreaMobile/index.d.ts +1 -0
  187. package/dist/types/ui/Appearance/FullPage/FullPage.d.ts +1 -0
  188. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +3 -3
  189. package/dist/types/ui/Appearance/Mobile.d.ts +1 -1
  190. package/dist/types/ui/AppearanceComponents/Mobile.d.ts +2 -1
  191. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  192. package/dist/types/ui/Dropdown/index.d.ts +1 -1
  193. package/dist/types/ui/with-outer-listeners.d.ts +2 -1
  194. package/dist/types/utils/linking-utils.d.ts +1 -0
  195. package/package.json +39 -41
  196. package/dist/cjs/plugins/type-ahead/ui/DynamicHeightListItem.js +0 -77
  197. package/dist/cjs/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +0 -118
  198. package/dist/cjs/plugins/type-ahead/ui/hooks/use-resize-observer.js +0 -70
  199. package/dist/es2019/plugins/type-ahead/ui/DynamicHeightListItem.js +0 -51
  200. package/dist/es2019/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +0 -97
  201. package/dist/es2019/plugins/type-ahead/ui/hooks/use-resize-observer.js +0 -53
  202. package/dist/esm/plugins/type-ahead/ui/DynamicHeightListItem.js +0 -51
  203. package/dist/esm/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +0 -101
  204. package/dist/esm/plugins/type-ahead/ui/hooks/use-resize-observer.js +0 -48
  205. package/dist/types/plugins/type-ahead/ui/DynamicHeightListItem.d.ts +0 -21
  206. package/dist/types/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.d.ts +0 -25
  207. package/dist/types/plugins/type-ahead/ui/hooks/use-resize-observer.d.ts +0 -8
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.useResizeObserver = exports.ResizeObserverProvider = exports.ResizeObserverContext = void 0;
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _utils = require("@atlaskit/editor-common/utils");
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- var Context = /*#__PURE__*/(0, _react.createContext)(null);
19
- var ResizeObserverContext = Context;
20
- exports.ResizeObserverContext = ResizeObserverContext;
21
-
22
- var ResizeObserverProvider = /*#__PURE__*/_react.default.memo(function (_ref) {
23
- var children = _ref.children;
24
- var instance = (0, _react.useMemo)(function () {
25
- if (!_utils.browser.supportsResizeObserver) {
26
- return null;
27
- }
28
-
29
- return new window.ResizeObserver(function (entries) {
30
- entries.forEach(function (entry) {
31
- var onResize = entry.target.onResize;
32
-
33
- if (onResize) {
34
- onResize(entry);
35
- }
36
- });
37
- });
38
- }, []);
39
- (0, _react.useEffect)(function () {
40
- return function () {
41
- if (instance) {
42
- instance.disconnect();
43
- }
44
- };
45
- }, [instance]);
46
- return /*#__PURE__*/_react.default.createElement(Context.Provider, {
47
- value: instance
48
- }, children);
49
- });
50
-
51
- exports.ResizeObserverProvider = ResizeObserverProvider;
52
-
53
- var useResizeObserver = function useResizeObserver(targetRef, onResize) {
54
- var resizeObserver = (0, _react.useContext)(Context);
55
- (0, _react.useLayoutEffect)(function () {
56
- if (!targetRef || !targetRef.current || resizeObserver === null) {
57
- return;
58
- }
59
-
60
- var target = targetRef.current;
61
- target.onResize = onResize;
62
- resizeObserver.observe(target);
63
- return function () {
64
- resizeObserver.unobserve(target);
65
- delete target.onResize;
66
- };
67
- }, [targetRef, resizeObserver, onResize]);
68
- };
69
-
70
- exports.useResizeObserver = useResizeObserver;
@@ -1,51 +0,0 @@
1
- import React, { useContext, useRef, useCallback } from 'react';
2
- import { TypeAheadListItem } from './TypeAheadListItem';
3
- import { useResizeObserver } from './hooks/use-resize-observer';
4
-
5
- const noop = () => {};
6
-
7
- export const SelectedIndexContext = /*#__PURE__*/React.createContext(0);
8
- export const ListItemActionsContext = /*#__PURE__*/React.createContext({
9
- onItemClick: noop,
10
- onItemHover: noop
11
- });
12
- export const UpdateListItemHeightContext = /*#__PURE__*/React.createContext(noop);
13
- export const DynamicHeightListItem = ({
14
- index,
15
- data,
16
- style
17
- }) => {
18
- const item = data[index];
19
- const selectedIndex = useContext(SelectedIndexContext);
20
- const {
21
- onItemClick,
22
- onItemHover
23
- } = useContext(ListItemActionsContext);
24
- const updateItemHeight = useContext(UpdateListItemHeightContext);
25
- const innerDivRef = useRef(document.createElement('div'));
26
- const onResize = useCallback(entry => {
27
- if (typeof updateItemHeight !== 'function') {
28
- return;
29
- }
30
-
31
- updateItemHeight({
32
- index,
33
- height: entry.contentRect.height
34
- });
35
- }, [updateItemHeight, index]);
36
- useResizeObserver(innerDivRef, onResize);
37
- return /*#__PURE__*/React.createElement("div", {
38
- style: style,
39
- "data-index": index
40
- }, /*#__PURE__*/React.createElement("div", {
41
- ref: innerDivRef,
42
- "data-testid": `list-item-height-observed-${index}`
43
- }, /*#__PURE__*/React.createElement(TypeAheadListItem, {
44
- key: item.title,
45
- item: item,
46
- itemIndex: index,
47
- selectedIndex: selectedIndex,
48
- onItemClick: onItemClick,
49
- onItemHover: onItemHover
50
- })));
51
- };
@@ -1,97 +0,0 @@
1
- import { useMemo, useState, useRef, useCallback, useLayoutEffect } from 'react';
2
- import throttle from 'lodash/throttle';
3
- export const calcVisibleListHeight = ({
4
- startIndex,
5
- indexHeightMap,
6
- limit,
7
- listMaxHeight,
8
- listItemEstimatedHeight
9
- }) => {
10
- let hasSpace = true;
11
- let totalHeight = 0;
12
- let i = startIndex;
13
-
14
- while (hasSpace && i < limit) {
15
- const nextHeight = indexHeightMap[i] || listItemEstimatedHeight;
16
-
17
- if (totalHeight < listMaxHeight) {
18
- totalHeight += nextHeight;
19
- }
20
-
21
- i++;
22
- hasSpace = totalHeight <= listMaxHeight;
23
- }
24
-
25
- return totalHeight;
26
- };
27
- export const useDynamicListHeightCalculation = ({
28
- redrawListAtIndex,
29
- getFirstVisibleIndex,
30
- listLength,
31
- listMaxHeight,
32
- listItemEstimatedHeight
33
- }) => {
34
- const [renderedListHeight, setRenderedListHeight] = useState(null);
35
- const indexHeightMap = useRef([]);
36
- const resetScreenThrottled = useMemo(() => {
37
- return throttle(() => {
38
- requestAnimationFrame(() => {
39
- const startIndex = getFirstVisibleIndex();
40
- const lastItemRenderer = indexHeightMap.current[startIndex];
41
-
42
- if (!lastItemRenderer) {
43
- return;
44
- } // This is an expensive method
45
- // So, we are calling it only
46
- // for the last top one visible
47
-
48
-
49
- redrawListAtIndex(startIndex);
50
- const nextListHeight = calcVisibleListHeight({
51
- startIndex,
52
- limit: listLength,
53
- indexHeightMap: indexHeightMap.current,
54
- listMaxHeight,
55
- listItemEstimatedHeight
56
- });
57
-
58
- if (nextListHeight) {
59
- setRenderedListHeight(nextListHeight);
60
- }
61
- });
62
- }, 16 // wait for one frame
63
- );
64
- }, [redrawListAtIndex, listLength, listMaxHeight, listItemEstimatedHeight, getFirstVisibleIndex]);
65
- const setListItemHeight = useCallback(({
66
- index,
67
- height
68
- }) => {
69
- if (typeof height !== 'number') {
70
- return;
71
- }
72
-
73
- indexHeightMap.current[index] = height;
74
- resetScreenThrottled();
75
- }, [resetScreenThrottled]);
76
- const getListItemHeight = useCallback(index => {
77
- const result = indexHeightMap.current[index];
78
-
79
- if (result && typeof result === 'number') {
80
- return result;
81
- }
82
-
83
- return listItemEstimatedHeight;
84
- }, [listItemEstimatedHeight]);
85
- useLayoutEffect(() => {
86
- indexHeightMap.current = [];
87
- return () => {
88
- indexHeightMap.current = [];
89
- };
90
- }, [listLength]); // eslint-disable-line react-hooks/exhaustive-deps
91
-
92
- return {
93
- getListItemHeight,
94
- setListItemHeight,
95
- renderedListHeight
96
- };
97
- };
@@ -1,53 +0,0 @@
1
- import React, { useMemo, useEffect, useContext, useLayoutEffect, createContext } from 'react';
2
- import { browser } from '@atlaskit/editor-common/utils';
3
- const Context = /*#__PURE__*/createContext(null);
4
- export const ResizeObserverContext = Context;
5
- export const ResizeObserverProvider = /*#__PURE__*/React.memo(({
6
- children
7
- }) => {
8
- const instance = useMemo(() => {
9
- if (!browser.supportsResizeObserver) {
10
- return null;
11
- }
12
-
13
- return new window.ResizeObserver(entries => {
14
- entries.forEach(entry => {
15
- const {
16
- onResize
17
- } = entry.target;
18
-
19
- if (onResize) {
20
- onResize(entry);
21
- }
22
- });
23
- });
24
- }, []);
25
- useEffect(() => {
26
- return () => {
27
- if (instance) {
28
- instance.disconnect();
29
- }
30
- };
31
- }, [instance]);
32
- return /*#__PURE__*/React.createElement(Context.Provider, {
33
- value: instance
34
- }, children);
35
- });
36
- export const useResizeObserver = (targetRef, onResize) => {
37
- const resizeObserver = useContext(Context);
38
- useLayoutEffect(() => {
39
- if (!targetRef || !targetRef.current || resizeObserver === null) {
40
- return;
41
- }
42
-
43
- const {
44
- current: target
45
- } = targetRef;
46
- target.onResize = onResize;
47
- resizeObserver.observe(target);
48
- return () => {
49
- resizeObserver.unobserve(target);
50
- delete target.onResize;
51
- };
52
- }, [targetRef, resizeObserver, onResize]);
53
- };
@@ -1,51 +0,0 @@
1
- import React, { useContext, useRef, useCallback } from 'react';
2
- import { TypeAheadListItem } from './TypeAheadListItem';
3
- import { useResizeObserver } from './hooks/use-resize-observer';
4
-
5
- var noop = function noop() {};
6
-
7
- export var SelectedIndexContext = /*#__PURE__*/React.createContext(0);
8
- export var ListItemActionsContext = /*#__PURE__*/React.createContext({
9
- onItemClick: noop,
10
- onItemHover: noop
11
- });
12
- export var UpdateListItemHeightContext = /*#__PURE__*/React.createContext(noop);
13
- export var DynamicHeightListItem = function DynamicHeightListItem(_ref) {
14
- var index = _ref.index,
15
- data = _ref.data,
16
- style = _ref.style;
17
- var item = data[index];
18
- var selectedIndex = useContext(SelectedIndexContext);
19
-
20
- var _useContext = useContext(ListItemActionsContext),
21
- onItemClick = _useContext.onItemClick,
22
- onItemHover = _useContext.onItemHover;
23
-
24
- var updateItemHeight = useContext(UpdateListItemHeightContext);
25
- var innerDivRef = useRef(document.createElement('div'));
26
- var onResize = useCallback(function (entry) {
27
- if (typeof updateItemHeight !== 'function') {
28
- return;
29
- }
30
-
31
- updateItemHeight({
32
- index: index,
33
- height: entry.contentRect.height
34
- });
35
- }, [updateItemHeight, index]);
36
- useResizeObserver(innerDivRef, onResize);
37
- return /*#__PURE__*/React.createElement("div", {
38
- style: style,
39
- "data-index": index
40
- }, /*#__PURE__*/React.createElement("div", {
41
- ref: innerDivRef,
42
- "data-testid": "list-item-height-observed-".concat(index)
43
- }, /*#__PURE__*/React.createElement(TypeAheadListItem, {
44
- key: item.title,
45
- item: item,
46
- itemIndex: index,
47
- selectedIndex: selectedIndex,
48
- onItemClick: onItemClick,
49
- onItemHover: onItemHover
50
- })));
51
- };
@@ -1,101 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { useMemo, useState, useRef, useCallback, useLayoutEffect } from 'react';
3
- import throttle from 'lodash/throttle';
4
- export var calcVisibleListHeight = function calcVisibleListHeight(_ref) {
5
- var startIndex = _ref.startIndex,
6
- indexHeightMap = _ref.indexHeightMap,
7
- limit = _ref.limit,
8
- listMaxHeight = _ref.listMaxHeight,
9
- listItemEstimatedHeight = _ref.listItemEstimatedHeight;
10
- var hasSpace = true;
11
- var totalHeight = 0;
12
- var i = startIndex;
13
-
14
- while (hasSpace && i < limit) {
15
- var nextHeight = indexHeightMap[i] || listItemEstimatedHeight;
16
-
17
- if (totalHeight < listMaxHeight) {
18
- totalHeight += nextHeight;
19
- }
20
-
21
- i++;
22
- hasSpace = totalHeight <= listMaxHeight;
23
- }
24
-
25
- return totalHeight;
26
- };
27
- export var useDynamicListHeightCalculation = function useDynamicListHeightCalculation(_ref2) {
28
- var redrawListAtIndex = _ref2.redrawListAtIndex,
29
- getFirstVisibleIndex = _ref2.getFirstVisibleIndex,
30
- listLength = _ref2.listLength,
31
- listMaxHeight = _ref2.listMaxHeight,
32
- listItemEstimatedHeight = _ref2.listItemEstimatedHeight;
33
-
34
- var _useState = useState(null),
35
- _useState2 = _slicedToArray(_useState, 2),
36
- renderedListHeight = _useState2[0],
37
- setRenderedListHeight = _useState2[1];
38
-
39
- var indexHeightMap = useRef([]);
40
- var resetScreenThrottled = useMemo(function () {
41
- return throttle(function () {
42
- requestAnimationFrame(function () {
43
- var startIndex = getFirstVisibleIndex();
44
- var lastItemRenderer = indexHeightMap.current[startIndex];
45
-
46
- if (!lastItemRenderer) {
47
- return;
48
- } // This is an expensive method
49
- // So, we are calling it only
50
- // for the last top one visible
51
-
52
-
53
- redrawListAtIndex(startIndex);
54
- var nextListHeight = calcVisibleListHeight({
55
- startIndex: startIndex,
56
- limit: listLength,
57
- indexHeightMap: indexHeightMap.current,
58
- listMaxHeight: listMaxHeight,
59
- listItemEstimatedHeight: listItemEstimatedHeight
60
- });
61
-
62
- if (nextListHeight) {
63
- setRenderedListHeight(nextListHeight);
64
- }
65
- });
66
- }, 16 // wait for one frame
67
- );
68
- }, [redrawListAtIndex, listLength, listMaxHeight, listItemEstimatedHeight, getFirstVisibleIndex]);
69
- var setListItemHeight = useCallback(function (_ref3) {
70
- var index = _ref3.index,
71
- height = _ref3.height;
72
-
73
- if (typeof height !== 'number') {
74
- return;
75
- }
76
-
77
- indexHeightMap.current[index] = height;
78
- resetScreenThrottled();
79
- }, [resetScreenThrottled]);
80
- var getListItemHeight = useCallback(function (index) {
81
- var result = indexHeightMap.current[index];
82
-
83
- if (result && typeof result === 'number') {
84
- return result;
85
- }
86
-
87
- return listItemEstimatedHeight;
88
- }, [listItemEstimatedHeight]);
89
- useLayoutEffect(function () {
90
- indexHeightMap.current = [];
91
- return function () {
92
- indexHeightMap.current = [];
93
- };
94
- }, [listLength]); // eslint-disable-line react-hooks/exhaustive-deps
95
-
96
- return {
97
- getListItemHeight: getListItemHeight,
98
- setListItemHeight: setListItemHeight,
99
- renderedListHeight: renderedListHeight
100
- };
101
- };
@@ -1,48 +0,0 @@
1
- import React, { useMemo, useEffect, useContext, useLayoutEffect, createContext } from 'react';
2
- import { browser } from '@atlaskit/editor-common/utils';
3
- var Context = /*#__PURE__*/createContext(null);
4
- export var ResizeObserverContext = Context;
5
- export var ResizeObserverProvider = /*#__PURE__*/React.memo(function (_ref) {
6
- var children = _ref.children;
7
- var instance = useMemo(function () {
8
- if (!browser.supportsResizeObserver) {
9
- return null;
10
- }
11
-
12
- return new window.ResizeObserver(function (entries) {
13
- entries.forEach(function (entry) {
14
- var onResize = entry.target.onResize;
15
-
16
- if (onResize) {
17
- onResize(entry);
18
- }
19
- });
20
- });
21
- }, []);
22
- useEffect(function () {
23
- return function () {
24
- if (instance) {
25
- instance.disconnect();
26
- }
27
- };
28
- }, [instance]);
29
- return /*#__PURE__*/React.createElement(Context.Provider, {
30
- value: instance
31
- }, children);
32
- });
33
- export var useResizeObserver = function useResizeObserver(targetRef, onResize) {
34
- var resizeObserver = useContext(Context);
35
- useLayoutEffect(function () {
36
- if (!targetRef || !targetRef.current || resizeObserver === null) {
37
- return;
38
- }
39
-
40
- var target = targetRef.current;
41
- target.onResize = onResize;
42
- resizeObserver.observe(target);
43
- return function () {
44
- resizeObserver.unobserve(target);
45
- delete target.onResize;
46
- };
47
- }, [targetRef, resizeObserver, onResize]);
48
- };
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
3
- import type { TypeAheadItem, OnSelectItem } from '../types';
4
- declare type ListItemActionsContextProps = {
5
- onItemHover: OnSelectItem;
6
- onItemClick: (mode: SelectItemMode, index: number) => void;
7
- };
8
- declare type DynamicHeightListItemProps = {
9
- index: number;
10
- data: Array<TypeAheadItem>;
11
- style: any;
12
- };
13
- declare type UpdateListItemHeightContextType = (props: {
14
- index: number;
15
- height: number;
16
- }) => void;
17
- export declare const SelectedIndexContext: React.Context<number>;
18
- export declare const ListItemActionsContext: React.Context<ListItemActionsContextProps>;
19
- export declare const UpdateListItemHeightContext: React.Context<UpdateListItemHeightContextType>;
20
- export declare const DynamicHeightListItem: React.FC<DynamicHeightListItemProps>;
21
- export {};
@@ -1,25 +0,0 @@
1
- export declare const calcVisibleListHeight: ({ startIndex, indexHeightMap, limit, listMaxHeight, listItemEstimatedHeight, }: {
2
- startIndex: number;
3
- indexHeightMap: Array<number>;
4
- limit: number;
5
- listMaxHeight: number;
6
- listItemEstimatedHeight: number;
7
- }) => number;
8
- declare type SetListItemHeight = (props: {
9
- index: number;
10
- height: number;
11
- }) => void;
12
- declare type GetListItemHeight = (index: number) => number;
13
- declare type Props = {
14
- redrawListAtIndex: (index: number) => void;
15
- getFirstVisibleIndex: () => number;
16
- listLength: number;
17
- listMaxHeight: number;
18
- listItemEstimatedHeight: number;
19
- };
20
- export declare const useDynamicListHeightCalculation: ({ redrawListAtIndex, getFirstVisibleIndex, listLength, listMaxHeight, listItemEstimatedHeight, }: Props) => {
21
- getListItemHeight: GetListItemHeight;
22
- setListItemHeight: SetListItemHeight;
23
- renderedListHeight: number | null;
24
- };
25
- export {};
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- interface ElementResizable extends Element {
3
- onResize?: (entry: ResizeObserverEntry) => void;
4
- }
5
- export declare const ResizeObserverContext: React.Context<ResizeObserver | null>;
6
- export declare const ResizeObserverProvider: React.FC;
7
- export declare const useResizeObserver: <T extends ElementResizable>(targetRef: React.MutableRefObject<T> | null, onResize: (entry: ResizeObserverEntry) => void) => void;
8
- export {};