@atlaskit/editor-common 118.10.3 → 118.12.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/compass.yml +2 -2
  3. package/dist/cjs/core-utils/index.js +1 -8
  4. package/dist/cjs/extensibility/ExtensionSSRReactContextsProvider.js +1 -2
  5. package/dist/cjs/monitoring/error.js +1 -1
  6. package/dist/cjs/portal/common.js +2 -3
  7. package/dist/cjs/react-node-view/NodeViewContentHole.js +1 -2
  8. package/dist/cjs/react-node-view/index.js +1 -1
  9. package/dist/cjs/styles/shared/table.js +1 -1
  10. package/dist/cjs/ui/DropList/index.js +1 -1
  11. package/dist/cjs/ui/Mention/index.js +20 -1
  12. package/dist/cjs/ui/Mention/mention-node-data-provider.js +5 -0
  13. package/dist/cjs/ui/Mention/mention-with-profilecard.js +8 -0
  14. package/dist/cjs/ui/Mention/mention-with-providers.js +92 -15
  15. package/dist/cjs/utils/content-visibility.js +177 -0
  16. package/dist/es2019/core-utils/index.js +1 -2
  17. package/dist/es2019/extensibility/ExtensionSSRReactContextsProvider.js +1 -2
  18. package/dist/es2019/monitoring/error.js +1 -1
  19. package/dist/es2019/portal/common.js +2 -3
  20. package/dist/es2019/react-node-view/NodeViewContentHole.js +1 -2
  21. package/dist/es2019/react-node-view/index.js +2 -2
  22. package/dist/es2019/styles/shared/table.js +8 -0
  23. package/dist/es2019/ui/DropList/index.js +1 -1
  24. package/dist/es2019/ui/Mention/index.js +21 -2
  25. package/dist/es2019/ui/Mention/mention-node-data-provider.js +1 -0
  26. package/dist/es2019/ui/Mention/mention-with-profilecard.js +8 -0
  27. package/dist/es2019/ui/Mention/mention-with-providers.js +69 -2
  28. package/dist/es2019/utils/content-visibility.js +165 -0
  29. package/dist/esm/core-utils/index.js +1 -2
  30. package/dist/esm/extensibility/ExtensionSSRReactContextsProvider.js +1 -2
  31. package/dist/esm/monitoring/error.js +1 -1
  32. package/dist/esm/portal/common.js +2 -3
  33. package/dist/esm/react-node-view/NodeViewContentHole.js +1 -2
  34. package/dist/esm/react-node-view/index.js +2 -2
  35. package/dist/esm/styles/shared/table.js +1 -1
  36. package/dist/esm/ui/DropList/index.js +1 -1
  37. package/dist/esm/ui/Mention/index.js +21 -2
  38. package/dist/esm/ui/Mention/mention-node-data-provider.js +1 -0
  39. package/dist/esm/ui/Mention/mention-with-profilecard.js +8 -0
  40. package/dist/esm/ui/Mention/mention-with-providers.js +92 -15
  41. package/dist/esm/utils/content-visibility.js +166 -0
  42. package/dist/types/core-utils/index.d.ts +0 -1
  43. package/dist/types/mention.d.ts +1 -0
  44. package/dist/types/ui/Mention/index.d.ts +2 -0
  45. package/dist/types/ui/Mention/mention-node-data-provider.d.ts +32 -0
  46. package/dist/types/ui/Mention/mention-with-profilecard.d.ts +5 -1
  47. package/dist/types/ui/Mention/mention-with-providers.d.ts +11 -1
  48. package/dist/types/utils/content-visibility.d.ts +78 -0
  49. package/package.json +9 -3
  50. package/utils/content-visibility/package.json +10 -0
  51. package/dist/cjs/core-utils/is-ssr-streaming.js +0 -22
  52. package/dist/es2019/core-utils/is-ssr-streaming.js +0 -16
  53. package/dist/esm/core-utils/is-ssr-streaming.js +0 -16
  54. package/dist/types/core-utils/is-ssr-streaming.d.ts +0 -10
@@ -8,10 +8,12 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
8
8
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
9
  /* eslint-disable @repo/internal/react/no-class-components */
10
10
  import React, { PureComponent } from 'react';
11
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
11
12
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
13
  import { ProviderFactory, WithProviders } from '../../provider-factory';
13
- import { MentionWithProviders } from './mention-with-providers';
14
+ import { MentionWithAvatarProviders, MentionWithProviders } from './mention-with-providers';
14
15
  var MENTION_PROVIDERS = ['mentionProvider', 'profilecardProvider'];
16
+ var GENERIC_MENTION_IDS = ['HipChat', 'all', 'here'];
15
17
  var Mention = /*#__PURE__*/function (_PureComponent) {
16
18
  function Mention(props) {
17
19
  var _this;
@@ -26,9 +28,26 @@ var Mention = /*#__PURE__*/function (_PureComponent) {
26
28
  localId = _this$props.localId,
27
29
  userType = _this$props.userType,
28
30
  isDisabled = _this$props.isDisabled,
29
- disabledTooltip = _this$props.disabledTooltip;
31
+ disabledTooltip = _this$props.disabledTooltip,
32
+ mentionNodeDataProvider = _this$props.mentionNodeDataProvider;
30
33
  var mentionProvider = providers.mentionProvider,
31
34
  profilecardProvider = providers.profilecardProvider;
35
+ var isAvatarEnabled = Boolean(mentionNodeDataProvider) && userType !== 'SPECIAL' && !GENERIC_MENTION_IDS.includes(id) && isExperimentEnabled('platform_editor_mention_node_avatar');
36
+ if (isAvatarEnabled && mentionNodeDataProvider) {
37
+ return /*#__PURE__*/React.createElement(MentionWithAvatarProviders, {
38
+ id: id,
39
+ text: text,
40
+ accessLevel: accessLevel,
41
+ localId: localId,
42
+ userType: userType,
43
+ isDisabled: isDisabled,
44
+ disabledTooltip: disabledTooltip,
45
+ eventHandlers: eventHandlers,
46
+ mentionProvider: mentionProvider,
47
+ mentionNodeDataProvider: mentionNodeDataProvider,
48
+ profilecardProvider: profilecardProvider
49
+ });
50
+ }
32
51
  return /*#__PURE__*/React.createElement(MentionWithProviders, {
33
52
  id: id,
34
53
  text: text,
@@ -0,0 +1 @@
1
+ export {};
@@ -37,11 +37,15 @@ export default function MentionWithProfileCard(_ref) {
37
37
  id = _ref.id,
38
38
  text = _ref.text,
39
39
  accessLevel = _ref.accessLevel,
40
+ appType = _ref.appType,
41
+ avatarUrl = _ref.avatarUrl,
42
+ isAvatarImagePreShaped = _ref.isAvatarImagePreShaped,
40
43
  mentionProvider = _ref.mentionProvider,
41
44
  profilecardProvider = _ref.profilecardProvider,
42
45
  onClick = _ref.onClick,
43
46
  onMouseEnter = _ref.onMouseEnter,
44
47
  onMouseLeave = _ref.onMouseLeave,
48
+ renderAvatarSlot = _ref.renderAvatarSlot,
45
49
  localId = _ref.localId,
46
50
  ssrPlaceholderId = _ref.ssrPlaceholderId,
47
51
  userType = _ref.userType;
@@ -55,11 +59,15 @@ export default function MentionWithProfileCard(_ref) {
55
59
  id: id,
56
60
  text: text,
57
61
  accessLevel: accessLevel,
62
+ appType: appType,
63
+ avatarUrl: avatarUrl,
64
+ isAvatarImagePreShaped: isAvatarImagePreShaped,
58
65
  localId: localId,
59
66
  mentionProvider: mentionProvider,
60
67
  onClick: onClick,
61
68
  onMouseEnter: onMouseEnter,
62
69
  onMouseLeave: onMouseLeave,
70
+ renderAvatarSlot: renderAvatarSlot,
63
71
  ssrPlaceholderId: ssrPlaceholderId
64
72
  });
65
73
 
@@ -1,23 +1,73 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
1
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useLayoutEffect, useRef, useState } from 'react';
4
+ var _excluded = ["id", "mentionNodeDataProvider", "userType"];
5
+ import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
3
6
  import { ResourcedMention } from '@atlaskit/mention/element';
4
7
  import ResourcedMentionWithProfilecard from './mention-with-profilecard';
5
8
  var GENERIC_USER_IDS = ['HipChat', 'all', 'here'];
6
- export var MentionWithProviders = /*#__PURE__*/React.memo(function (_ref) {
7
- var accessLevel = _ref.accessLevel,
8
- disabledTooltip = _ref.disabledTooltip,
9
- eventHandlers = _ref.eventHandlers,
10
- id = _ref.id,
11
- isDisabled = _ref.isDisabled,
12
- mentionProvider = _ref.mentionProvider,
13
- profilecardProviderResolver = _ref.profilecardProvider,
14
- text = _ref.text,
15
- localId = _ref.localId,
9
+ var useMentionNodeData = function useMentionNodeData(_ref) {
10
+ var _state$data;
11
+ var id = _ref.id,
12
+ mentionNodeDataProvider = _ref.mentionNodeDataProvider,
16
13
  userType = _ref.userType;
17
- var _useState = useState(null),
14
+ var mention = useMemo(function () {
15
+ return {
16
+ id: id,
17
+ userType: userType
18
+ };
19
+ }, [id, userType]);
20
+ var mentionKey = "".concat(userType !== null && userType !== void 0 ? userType : 'DEFAULT', ":").concat(id);
21
+ var synchronousData = useMemo(function () {
22
+ return mentionNodeDataProvider.getMentionDataFromCache(mention);
23
+ }, [mention, mentionNodeDataProvider]);
24
+ var _useState = useState(function () {
25
+ return {
26
+ data: synchronousData,
27
+ key: mentionKey
28
+ };
29
+ }),
18
30
  _useState2 = _slicedToArray(_useState, 2),
19
- profilecardProvider = _useState2[0],
20
- setProfilecardProvider = _useState2[1];
31
+ state = _useState2[0],
32
+ setState = _useState2[1];
33
+ var data = state.key === mentionKey ? (_state$data = state.data) !== null && _state$data !== void 0 ? _state$data : synchronousData : synchronousData;
34
+ useEffect(function () {
35
+ if (synchronousData) {
36
+ return;
37
+ }
38
+ var isActive = true;
39
+ mentionNodeDataProvider.getMentionData(mention, function (payload) {
40
+ if (isActive && payload.data) {
41
+ setState({
42
+ data: payload.data,
43
+ key: mentionKey
44
+ });
45
+ }
46
+ });
47
+ return function () {
48
+ isActive = false;
49
+ };
50
+ }, [mention, mentionKey, mentionNodeDataProvider, synchronousData]);
51
+ return data;
52
+ };
53
+ export var MentionWithProviders = /*#__PURE__*/React.memo(function (_ref2) {
54
+ var accessLevel = _ref2.accessLevel,
55
+ disabledTooltip = _ref2.disabledTooltip,
56
+ eventHandlers = _ref2.eventHandlers,
57
+ id = _ref2.id,
58
+ isDisabled = _ref2.isDisabled,
59
+ mentionNodeData = _ref2.mentionNodeData,
60
+ mentionProvider = _ref2.mentionProvider,
61
+ profilecardProviderResolver = _ref2.profilecardProvider,
62
+ _ref2$renderAvatarSlo = _ref2.renderAvatarSlot,
63
+ renderAvatarSlot = _ref2$renderAvatarSlo === void 0 ? false : _ref2$renderAvatarSlo,
64
+ text = _ref2.text,
65
+ localId = _ref2.localId,
66
+ userType = _ref2.userType;
67
+ var _useState3 = useState(null),
68
+ _useState4 = _slicedToArray(_useState3, 2),
69
+ profilecardProvider = _useState4[0],
70
+ setProfilecardProvider = _useState4[1];
21
71
  var mountedRef = useRef(true);
22
72
  useLayoutEffect(function () {
23
73
  mountedRef.current = true;
@@ -52,11 +102,15 @@ export var MentionWithProviders = /*#__PURE__*/React.memo(function (_ref) {
52
102
  accessLevel: accessLevel,
53
103
  localId: localId,
54
104
  mentionProvider: mentionProvider,
105
+ appType: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.appType,
106
+ avatarUrl: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.avatarUrl,
107
+ isAvatarImagePreShaped: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.isAvatarImagePreShaped,
55
108
  isDisabled: true,
56
109
  disabledTooltip: disabledTooltip,
57
110
  onClick: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onClick,
58
111
  onMouseEnter: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onMouseEnter,
59
112
  onMouseLeave: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onMouseLeave,
113
+ renderAvatarSlot: renderAvatarSlot,
60
114
  ssrPlaceholderId: ssrPlaceholderId
61
115
  });
62
116
  }
@@ -66,7 +120,10 @@ export var MentionWithProviders = /*#__PURE__*/React.memo(function (_ref) {
66
120
  accessLevel: accessLevel,
67
121
  localId: localId,
68
122
  userType: userType,
69
- mentionProvider: mentionProvider
123
+ mentionProvider: mentionProvider,
124
+ appType: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.appType,
125
+ avatarUrl: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.avatarUrl,
126
+ isAvatarImagePreShaped: mentionNodeData === null || mentionNodeData === void 0 ? void 0 : mentionNodeData.isAvatarImagePreShaped
70
127
  // Ignored via go/ees005
71
128
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
129
  ,
@@ -74,6 +131,26 @@ export var MentionWithProviders = /*#__PURE__*/React.memo(function (_ref) {
74
131
  onClick: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onClick,
75
132
  onMouseEnter: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onMouseEnter,
76
133
  onMouseLeave: eventHandlers === null || eventHandlers === void 0 ? void 0 : eventHandlers.onMouseLeave,
134
+ renderAvatarSlot: renderAvatarSlot,
77
135
  ssrPlaceholderId: ssrPlaceholderId
78
136
  });
137
+ });
138
+ export var MentionWithAvatarProviders = /*#__PURE__*/React.memo(function (_ref3) {
139
+ var id = _ref3.id,
140
+ mentionNodeDataProvider = _ref3.mentionNodeDataProvider,
141
+ userType = _ref3.userType,
142
+ props = _objectWithoutProperties(_ref3, _excluded);
143
+ var mentionNodeData = useMentionNodeData({
144
+ id: id,
145
+ mentionNodeDataProvider: mentionNodeDataProvider,
146
+ userType: userType
147
+ });
148
+ return /*#__PURE__*/React.createElement(MentionWithProviders
149
+ // eslint-disable-next-line react/jsx-props-no-spreading -- The treatment adds only resolved avatar data to the existing mention props.
150
+ , _extends({}, props, {
151
+ id: id,
152
+ mentionNodeData: mentionNodeData,
153
+ renderAvatarSlot: true,
154
+ userType: userType
155
+ }));
79
156
  });
@@ -0,0 +1,166 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
+ import { calcMediaSinglePixelWidth } from '../media-single/utils';
6
+
7
+ // Rough per-node rendered-size constants (px), grounded in the real style defaults from
8
+ // `styles/shared/table.ts`, `EditorContentContainer/styles/expandStyles.ts` and
9
+ // `EditorContentContainer/styles/layout.ts`. These only need to be a decent first estimate: the
10
+ // `auto` keyword in `contain-intrinsic-*: auto <estimate>` makes the browser remember each
11
+ // element's real size after its first render, so any inaccuracy self-corrects on scroll. Where the
12
+ // estimate can't be exact we intentionally err slightly HIGH — over-reserving leaves a marginally
13
+ // long scrollbar that shrinks on scroll, whereas under-reserving makes content jump upward.
14
+ var TABLE_ROW_HEIGHT = 44; // row content: line-height + cell padding (space.100 ×2) + cell border
15
+ var TABLE_VERTICAL_MARGIN = 40; // tableMarginTop(24) + tableMarginBottom(16)
16
+ var TABLE_MIN_HEIGHT = 120;
17
+ var BLOCK_HEIGHT = 28; // a typical paragraph/block line + spacing
18
+
19
+ var EXPAND_HEADER_HEIGHT = 48; // min-height:25 + padding + margin of the title row
20
+ var EXPAND_CONTENT_PADDING = 8; // space.100 padding-top when expanded
21
+
22
+ var MEDIA_SINGLE_MIN_HEIGHT = 100;
23
+ var MEDIA_SINGLE_GUTTER = 12; // MEDIA_SINGLE_GUTTER_SIZE — gap between resizer handle and media
24
+ var MEDIA_SINGLE_VERTICAL_MARGIN = 24; // rich-media-item margin: space.150 top + bottom
25
+ var MEDIA_CAPTION_HEIGHT = 32; // caption line-height + vertical padding, when a caption is present
26
+ var DEFAULT_MEDIA_ASPECT_RATIO = 9 / 16; // used only when the media has no intrinsic dimensions
27
+
28
+ /**
29
+ * The intrinsic size a nodeView reserves while off-screen (`contain-intrinsic-width`/`-height`).
30
+ * `width` is optional: for block-level wrappers (expand, layout) the inline size comes from the
31
+ * containing block regardless of size containment, so only `height` is meaningful; for
32
+ * content-sized boxes (the `<table>` element, the mediaSingle wrapper) the width matters and must
33
+ * be supplied or the box collapses to 0 wide while contained.
34
+ */
35
+
36
+ /**
37
+ * Estimate the rendered height of a table from its row count. Cell padding and cell borders are
38
+ * already folded into `TABLE_ROW_HEIGHT`; the table's block margins are added as a small buffer.
39
+ */
40
+ export function estimateTableIntrinsicHeight(node) {
41
+ var rows = node.childCount;
42
+ return Math.max(TABLE_MIN_HEIGHT, rows * TABLE_ROW_HEIGHT + TABLE_VERTICAL_MARGIN);
43
+ }
44
+
45
+ /**
46
+ * Estimate the rendered height of an expand. A collapsed expand reserves only its header row; an
47
+ * expanded one additionally reserves space for its child blocks. `expanded` is passed in by the
48
+ * caller because the two expand implementations track expanded state differently (a WeakMap in
49
+ * single-player vs the `__expanded` attribute in legacy).
50
+ */
51
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
52
+ export function estimateExpandIntrinsicHeight(node, expanded) {
53
+ if (!expanded) {
54
+ return EXPAND_HEADER_HEIGHT;
55
+ }
56
+ return EXPAND_HEADER_HEIGHT + node.childCount * BLOCK_HEIGHT + EXPAND_CONTENT_PADDING;
57
+ }
58
+
59
+ /**
60
+ * Estimate the rendered width AND height of a mediaSingle. Unlike the structural estimates above,
61
+ * media carries its real dimensions in the ADF: the child `media` node's `width`/`height` attrs
62
+ * give the intrinsic aspect ratio, and the rendered pixel width is computed with the exact same
63
+ * `calcMediaSinglePixelWidth` helper the renderer uses (honouring `width`/`widthType`/`layout` and
64
+ * the editor's content/container width). Height then follows from width × aspect ratio — plus a
65
+ * caption row when present and the mediaSingle's block margins — so this is the most accurate
66
+ * estimate of any node type. The pixel width is returned as the intrinsic width because the
67
+ * mediaSingle wrapper is content-sized. `lineLength` and `containerWidth` come from the width
68
+ * plugin's shared state.
69
+ */
70
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
71
+ export function estimateMediaSingleIntrinsicSize(node, lineLength, containerWidth) {
72
+ var _media$attrs, _media$attrs2, _node$attrs$width, _ref;
73
+ var media = node.firstChild;
74
+ var origWidth = Number(media === null || media === void 0 || (_media$attrs = media.attrs) === null || _media$attrs === void 0 ? void 0 : _media$attrs.width) || 0;
75
+ var origHeight = Number(media === null || media === void 0 || (_media$attrs2 = media.attrs) === null || _media$attrs2 === void 0 ? void 0 : _media$attrs2.height) || 0;
76
+ var aspectRatio = origWidth && origHeight ? origHeight / origWidth : DEFAULT_MEDIA_ASPECT_RATIO;
77
+ var pixelWidth = calcMediaSinglePixelWidth({
78
+ width: (_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : undefined,
79
+ widthType: node.attrs.widthType,
80
+ origWidth: origWidth || lineLength || containerWidth,
81
+ layout: (_ref = node.attrs.layout) !== null && _ref !== void 0 ? _ref : 'center',
82
+ contentWidth: lineLength || undefined,
83
+ containerWidth: containerWidth || lineLength,
84
+ gutterOffset: MEDIA_SINGLE_GUTTER
85
+ });
86
+
87
+ // A caption child (childCount > 1) sits below the media, and the mediaSingle block reserves
88
+ // vertical margin above and below regardless.
89
+ var captionHeight = node.childCount > 1 ? MEDIA_CAPTION_HEIGHT : 0;
90
+ var height = Math.max(MEDIA_SINGLE_MIN_HEIGHT, Math.round(pixelWidth * aspectRatio) + captionHeight + MEDIA_SINGLE_VERTICAL_MARGIN);
91
+ return {
92
+ width: Math.round(pixelWidth),
93
+ height: height
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Produce a single-axis `contain-intrinsic-width`/`-height` value using the `auto` keyword so the
99
+ * browser remembers the element's real size after its first render and only uses the estimate
100
+ * beforehand.
101
+ */
102
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
103
+ export function formatIntrinsicSize(px) {
104
+ return "auto ".concat(Math.round(px), "px");
105
+ }
106
+
107
+ /**
108
+ * The `content-visibility` / `contain-intrinsic-*` styles applied to an eligible node. Width and
109
+ * height are kept as separate `contain-intrinsic-width`/`-height` axes rather than the
110
+ * `contain-intrinsic-size` shorthand: the shorthand's single value is applied to BOTH axes, which
111
+ * forces a wrong width on content-sized boxes (e.g. a 500px-tall `<table>` would reserve 500px
112
+ * wide). `containIntrinsicWidth` is omitted for block-level wrappers whose width comes from layout.
113
+ */
114
+
115
+ /**
116
+ * Resolve the `content-visibility` styles for a node, or `undefined` when the optimisation should
117
+ * not apply.
118
+ *
119
+ * Gating is delegated to limited mode: `limitedModeEnabled` should come from the limited-mode
120
+ * plugin's shared state, so this feature shares a single "large document" definition with limited
121
+ * mode rather than a bespoke threshold. The optimisation applies only when the feature gate is on
122
+ * AND limited mode is active.
123
+ *
124
+ * The intrinsic size is supplied lazily via `getIntrinsicSize` so callers can compute a
125
+ * per-instance estimate from the node's structure, and is only evaluated when actually applied.
126
+ */
127
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
128
+ export function getContentVisibilityStyle(limitedModeEnabled, getIntrinsicSize) {
129
+ if (!limitedModeEnabled || !isExperimentEnabled('cc_editor_limited_mode_perf_improvements')) {
130
+ return undefined;
131
+ }
132
+ var _getIntrinsicSize = getIntrinsicSize(),
133
+ width = _getIntrinsicSize.width,
134
+ height = _getIntrinsicSize.height;
135
+ return _objectSpread({
136
+ contentVisibility: 'auto',
137
+ containIntrinsicHeight: formatIntrinsicSize(height)
138
+ }, width !== undefined ? {
139
+ containIntrinsicWidth: formatIntrinsicSize(width)
140
+ } : {});
141
+ }
142
+
143
+ /**
144
+ * Imperatively apply the `content-visibility: auto` rendering optimisation to a node's top-level
145
+ * DOM element (for use in raw-DOM nodeViews), but only when both the feature gate is on and limited
146
+ * mode is active (see `getContentVisibilityStyle`).
147
+ *
148
+ * The intrinsic size uses the `auto` keyword so any initial inaccuracy self-corrects once the
149
+ * element has been rendered once. Safe to call repeatedly (e.g. on expand/collapse toggle) — it
150
+ * simply re-applies or, when ineligible, leaves the element untouched.
151
+ */
152
+ // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
153
+ export function applyContentVisibility(dom, limitedModeEnabled, getIntrinsicSize) {
154
+ var _style$containIntrins;
155
+ var style = getContentVisibilityStyle(limitedModeEnabled, getIntrinsicSize);
156
+ if (!style) {
157
+ dom.style.contentVisibility = '';
158
+ dom.style.containIntrinsicHeight = '';
159
+ dom.style.containIntrinsicWidth = '';
160
+ return false;
161
+ }
162
+ dom.style.contentVisibility = style.contentVisibility;
163
+ dom.style.containIntrinsicHeight = style.containIntrinsicHeight;
164
+ dom.style.containIntrinsicWidth = (_style$containIntrins = style.containIntrinsicWidth) !== null && _style$containIntrins !== void 0 ? _style$containIntrins : '';
165
+ return true;
166
+ }
@@ -1,4 +1,3 @@
1
1
  export { insideTable } from './inside';
2
2
  export { getDocStructure } from './document-logger';
3
3
  export { isSSR } from './is-ssr';
4
- export { isSSRStreaming } from './is-ssr-streaming';
@@ -1,3 +1,4 @@
1
1
  export { default as Mention } from './ui/Mention';
2
+ export type { MentionNodeDataCallback, MentionNodeDataIdentifier, MentionNodeDataProvider, MentionNodeDataUserType, } from './ui/Mention/mention-node-data-provider';
2
3
  export { MentionSharedCssClassName } from './styles/shared/mention';
3
4
  export { default as MentionWithProfileCard } from './ui/Mention/mention-with-profilecard';
@@ -3,6 +3,7 @@ import type { MentionUserType } from '@atlaskit/adf-schema';
3
3
  import { ProviderFactory } from '../../provider-factory';
4
4
  import type { ProfilecardProvider } from '../../provider-factory/profile-card-provider';
5
5
  import type { MentionEventHandlers } from '../EventHandlers';
6
+ import type { MentionNodeDataProvider } from './mention-node-data-provider';
6
7
  export interface MentionProps {
7
8
  accessLevel?: string;
8
9
  disabledTooltip?: string;
@@ -10,6 +11,7 @@ export interface MentionProps {
10
11
  id: string;
11
12
  isDisabled?: boolean;
12
13
  localId?: string;
14
+ mentionNodeDataProvider?: MentionNodeDataProvider;
13
15
  providers?: ProviderFactory;
14
16
  text: string;
15
17
  userType?: MentionUserType;
@@ -0,0 +1,32 @@
1
+ import type { MentionUserType } from '@atlaskit/adf-schema/mention';
2
+ import type { MentionNodeData } from '@atlaskit/mention/types';
3
+ export type MentionNodeDataCallback = (payload: {
4
+ data: MentionNodeData;
5
+ error?: undefined;
6
+ } | {
7
+ data?: undefined;
8
+ error: Error;
9
+ }) => void;
10
+ /** `AGENT` is emitted by editor agent sources at runtime but is not serialized as an ADF user type. */
11
+ export type MentionNodeDataUserType = MentionUserType | 'AGENT';
12
+ export interface MentionNodeDataIdentifier {
13
+ id: string;
14
+ userType?: MentionNodeDataUserType;
15
+ }
16
+ /**
17
+ * Product-facing bridge between mention data resolution and mention UI.
18
+ *
19
+ * Create one provider per renderer or editor instance and pass it through the
20
+ * renderer props or mentions plugin options. `getMentionDataFromCache` is used
21
+ * during render, including SSR, so it must never start a network request.
22
+ * Deterministic products may return data from it synchronously; network-backed
23
+ * products should return cached data or `undefined`, then resolve through
24
+ * `getMentionData` on the client.
25
+ *
26
+ * The UI depends only on these mention-specific methods to avoid a package
27
+ * cycle with the reusable implementation in editor-plugin-mentions.
28
+ */
29
+ export interface MentionNodeDataProvider {
30
+ getMentionData: (mention: MentionNodeDataIdentifier, callback: MentionNodeDataCallback) => void;
31
+ getMentionDataFromCache: (mention: MentionNodeDataIdentifier) => MentionNodeData | undefined;
32
+ }
@@ -5,14 +5,18 @@ import type { ProfilecardProvider } from '../../provider-factory/profile-card-pr
5
5
  import type { MentionEventHandler } from '../EventHandlers';
6
6
  export interface Props {
7
7
  accessLevel?: string;
8
+ appType?: string | null;
8
9
  autoFocus?: boolean;
10
+ avatarUrl?: string;
9
11
  id: string;
12
+ isAvatarImagePreShaped?: boolean;
10
13
  localId?: string;
11
14
  mentionProvider?: Promise<MentionProvider>;
12
15
  onClick?: MentionEventHandler;
13
16
  onMouseEnter?: MentionEventHandler;
14
17
  onMouseLeave?: MentionEventHandler;
15
18
  profilecardProvider: ProfilecardProvider;
19
+ renderAvatarSlot?: boolean;
16
20
  ssrPlaceholderId?: string;
17
21
  text: string;
18
22
  userType?: MentionUserType;
@@ -22,4 +26,4 @@ export interface Props {
22
26
  * 1. Agent mentions (`userType === 'APP'`, behind the `rovo_chat_mention_agents` experiment) open the Rovo agent profile card on click.
23
27
  * 2. Otherwise renders the person profile card (either via the provider's `renderUserMentionCard`/link fallback or the default user `ProfileCardTrigger`).
24
28
  */
25
- export default function MentionWithProfileCard({ autoFocus, id, text, accessLevel, mentionProvider, profilecardProvider, onClick, onMouseEnter, onMouseLeave, localId, ssrPlaceholderId, userType, }: Props): React.JSX.Element;
29
+ export default function MentionWithProfileCard({ autoFocus, id, text, accessLevel, appType, avatarUrl, isAvatarImagePreShaped, mentionProvider, profilecardProvider, onClick, onMouseEnter, onMouseLeave, renderAvatarSlot, localId, ssrPlaceholderId, userType, }: Props): React.JSX.Element;
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import type { MentionUserType } from '@atlaskit/adf-schema';
3
3
  import type { MentionProvider } from '@atlaskit/mention/resource';
4
+ import type { MentionNodeData } from '@atlaskit/mention/types';
4
5
  import type { ProfilecardProvider } from '../../provider-factory/profile-card-provider';
5
6
  import type { MentionEventHandlers } from '../EventHandlers';
7
+ import type { MentionNodeDataProvider } from './mention-node-data-provider';
6
8
  export interface Props {
7
9
  accessLevel?: string;
8
10
  disabledTooltip?: string;
@@ -10,12 +12,20 @@ export interface Props {
10
12
  id: string;
11
13
  isDisabled?: boolean;
12
14
  localId?: string;
15
+ mentionNodeDataProvider?: MentionNodeDataProvider;
13
16
  mentionProvider?: Promise<MentionProvider>;
14
17
  profilecardProvider?: Promise<ProfilecardProvider>;
15
18
  text: string;
16
19
  userType?: MentionUserType;
17
20
  }
21
+ export interface MentionWithProvidersProps extends Props {
22
+ mentionNodeData?: MentionNodeData;
23
+ renderAvatarSlot?: boolean;
24
+ }
18
25
  export interface State {
19
26
  profilecardProvider: ProfilecardProvider | null;
20
27
  }
21
- export declare const MentionWithProviders: React.MemoExoticComponent<({ accessLevel, eventHandlers, id, mentionProvider, profilecardProvider, text, localId, }: Props) => React.JSX.Element>;
28
+ export declare const MentionWithProviders: React.MemoExoticComponent<(props: MentionWithProvidersProps) => React.JSX.Element>;
29
+ export declare const MentionWithAvatarProviders: React.MemoExoticComponent<(props: Props & {
30
+ mentionNodeDataProvider: MentionNodeDataProvider;
31
+ }) => React.JSX.Element>;
@@ -0,0 +1,78 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ /**
3
+ * The intrinsic size a nodeView reserves while off-screen (`contain-intrinsic-width`/`-height`).
4
+ * `width` is optional: for block-level wrappers (expand, layout) the inline size comes from the
5
+ * containing block regardless of size containment, so only `height` is meaningful; for
6
+ * content-sized boxes (the `<table>` element, the mediaSingle wrapper) the width matters and must
7
+ * be supplied or the box collapses to 0 wide while contained.
8
+ */
9
+ export type IntrinsicSize = {
10
+ height: number;
11
+ width?: number;
12
+ };
13
+ /**
14
+ * Estimate the rendered height of a table from its row count. Cell padding and cell borders are
15
+ * already folded into `TABLE_ROW_HEIGHT`; the table's block margins are added as a small buffer.
16
+ */
17
+ export declare function estimateTableIntrinsicHeight(node: PMNode): number;
18
+ /**
19
+ * Estimate the rendered height of an expand. A collapsed expand reserves only its header row; an
20
+ * expanded one additionally reserves space for its child blocks. `expanded` is passed in by the
21
+ * caller because the two expand implementations track expanded state differently (a WeakMap in
22
+ * single-player vs the `__expanded` attribute in legacy).
23
+ */
24
+ export declare function estimateExpandIntrinsicHeight(node: PMNode, expanded: boolean): number;
25
+ /**
26
+ * Estimate the rendered width AND height of a mediaSingle. Unlike the structural estimates above,
27
+ * media carries its real dimensions in the ADF: the child `media` node's `width`/`height` attrs
28
+ * give the intrinsic aspect ratio, and the rendered pixel width is computed with the exact same
29
+ * `calcMediaSinglePixelWidth` helper the renderer uses (honouring `width`/`widthType`/`layout` and
30
+ * the editor's content/container width). Height then follows from width × aspect ratio — plus a
31
+ * caption row when present and the mediaSingle's block margins — so this is the most accurate
32
+ * estimate of any node type. The pixel width is returned as the intrinsic width because the
33
+ * mediaSingle wrapper is content-sized. `lineLength` and `containerWidth` come from the width
34
+ * plugin's shared state.
35
+ */
36
+ export declare function estimateMediaSingleIntrinsicSize(node: PMNode, lineLength: number, containerWidth: number): IntrinsicSize;
37
+ /**
38
+ * Produce a single-axis `contain-intrinsic-width`/`-height` value using the `auto` keyword so the
39
+ * browser remembers the element's real size after its first render and only uses the estimate
40
+ * beforehand.
41
+ */
42
+ export declare function formatIntrinsicSize(px: number): string;
43
+ /**
44
+ * The `content-visibility` / `contain-intrinsic-*` styles applied to an eligible node. Width and
45
+ * height are kept as separate `contain-intrinsic-width`/`-height` axes rather than the
46
+ * `contain-intrinsic-size` shorthand: the shorthand's single value is applied to BOTH axes, which
47
+ * forces a wrong width on content-sized boxes (e.g. a 500px-tall `<table>` would reserve 500px
48
+ * wide). `containIntrinsicWidth` is omitted for block-level wrappers whose width comes from layout.
49
+ */
50
+ type ContentVisibilityStyle = {
51
+ containIntrinsicHeight: string;
52
+ containIntrinsicWidth?: string;
53
+ contentVisibility: 'auto';
54
+ };
55
+ /**
56
+ * Resolve the `content-visibility` styles for a node, or `undefined` when the optimisation should
57
+ * not apply.
58
+ *
59
+ * Gating is delegated to limited mode: `limitedModeEnabled` should come from the limited-mode
60
+ * plugin's shared state, so this feature shares a single "large document" definition with limited
61
+ * mode rather than a bespoke threshold. The optimisation applies only when the feature gate is on
62
+ * AND limited mode is active.
63
+ *
64
+ * The intrinsic size is supplied lazily via `getIntrinsicSize` so callers can compute a
65
+ * per-instance estimate from the node's structure, and is only evaluated when actually applied.
66
+ */
67
+ export declare function getContentVisibilityStyle(limitedModeEnabled: boolean, getIntrinsicSize: () => IntrinsicSize): ContentVisibilityStyle | undefined;
68
+ /**
69
+ * Imperatively apply the `content-visibility: auto` rendering optimisation to a node's top-level
70
+ * DOM element (for use in raw-DOM nodeViews), but only when both the feature gate is on and limited
71
+ * mode is active (see `getContentVisibilityStyle`).
72
+ *
73
+ * The intrinsic size uses the `auto` keyword so any initial inaccuracy self-corrects once the
74
+ * element has been rendered once. Safe to call repeatedly (e.g. on expand/collapse toggle) — it
75
+ * simply re-applies or, when ineligible, leaves the element untouched.
76
+ */
77
+ export declare function applyContentVisibility(dom: HTMLElement, limitedModeEnabled: boolean, getIntrinsicSize: () => IntrinsicSize): boolean;
78
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "118.10.3",
3
+ "version": "118.12.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -64,7 +64,7 @@
64
64
  "@atlaskit/media-picker": "^72.1.0",
65
65
  "@atlaskit/media-ui": "^30.11.0",
66
66
  "@atlaskit/media-viewer": "^54.5.0",
67
- "@atlaskit/mention": "^27.15.0",
67
+ "@atlaskit/mention": "^27.16.0",
68
68
  "@atlaskit/menu": "^10.0.0",
69
69
  "@atlaskit/object": "^2.2.0",
70
70
  "@atlaskit/onboarding": "^15.1.0",
@@ -84,7 +84,7 @@
84
84
  "@atlaskit/task-decision": "^21.8.0",
85
85
  "@atlaskit/teams-app-config": "^2.2.0",
86
86
  "@atlaskit/textfield": "^10.0.0",
87
- "@atlaskit/tmp-editor-statsig": "^147.0.0",
87
+ "@atlaskit/tmp-editor-statsig": "^147.1.0",
88
88
  "@atlaskit/tokens": "^16.7.0",
89
89
  "@atlaskit/tooltip": "^24.0.0",
90
90
  "@atlaskit/width-detector": "^7.0.0",
@@ -266,5 +266,11 @@
266
266
  "platform_editor_embed_height_only_fallback": {
267
267
  "type": "boolean"
268
268
  }
269
+ },
270
+ "platform-experiments": {
271
+ "platform_editor_mention_node_avatar": {
272
+ "param": "isEnabled",
273
+ "defaultValue": false
274
+ }
269
275
  }
270
276
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@atlaskit/editor-common/utils/content-visibility",
3
+ "main": "../../dist/cjs/utils/content-visibility.js",
4
+ "module": "../../dist/esm/utils/content-visibility.js",
5
+ "module:es2019": "../../dist/es2019/utils/content-visibility.js",
6
+ "sideEffects": [
7
+ "**/*.compiled.css"
8
+ ],
9
+ "types": "../../dist/types/utils/content-visibility.d.ts"
10
+ }