@atlaskit/editor-common 78.34.0 → 78.36.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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/portal/PortalBucket.js +44 -0
- package/dist/cjs/portal/PortalManager.js +209 -0
- package/dist/cjs/portal/index.js +26 -0
- package/dist/cjs/portal/usePortalProvider.js +80 -0
- package/dist/cjs/table/SortingIcon.js +144 -0
- package/dist/cjs/table/consts.js +7 -0
- package/dist/cjs/table/index.js +28 -0
- package/dist/cjs/table/messages.js +56 -0
- package/dist/cjs/ui/DropList/index.js +1 -1
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/portal/PortalBucket.js +29 -0
- package/dist/es2019/portal/PortalManager.js +157 -0
- package/dist/es2019/portal/index.js +3 -0
- package/dist/es2019/portal/usePortalProvider.js +58 -0
- package/dist/es2019/table/SortingIcon.js +183 -0
- package/dist/es2019/table/consts.js +1 -0
- package/dist/es2019/table/index.js +2 -0
- package/dist/es2019/table/messages.js +50 -0
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/portal/PortalBucket.js +34 -0
- package/dist/esm/portal/PortalManager.js +202 -0
- package/dist/esm/portal/index.js +3 -0
- package/dist/esm/portal/usePortalProvider.js +70 -0
- package/dist/esm/table/SortingIcon.js +139 -0
- package/dist/esm/table/consts.js +1 -0
- package/dist/esm/table/index.js +2 -0
- package/dist/esm/table/messages.js +50 -0
- package/dist/esm/ui/DropList/index.js +1 -1
- package/dist/types/portal/PortalBucket.d.ts +18 -0
- package/dist/types/portal/PortalManager.d.ts +53 -0
- package/dist/types/portal/index.d.ts +3 -0
- package/dist/types/portal/usePortalProvider.d.ts +18 -0
- package/dist/types/table/SortingIcon.d.ts +23 -0
- package/dist/types/table/consts.d.ts +1 -0
- package/dist/types/table/index.d.ts +2 -0
- package/dist/types/table/messages.d.ts +49 -0
- package/dist/types-ts4.5/portal/PortalBucket.d.ts +18 -0
- package/dist/types-ts4.5/portal/PortalManager.d.ts +53 -0
- package/dist/types-ts4.5/portal/index.d.ts +3 -0
- package/dist/types-ts4.5/portal/usePortalProvider.d.ts +21 -0
- package/dist/types-ts4.5/table/SortingIcon.d.ts +23 -0
- package/dist/types-ts4.5/table/consts.d.ts +1 -0
- package/dist/types-ts4.5/table/index.d.ts +2 -0
- package/dist/types-ts4.5/table/messages.d.ts +49 -0
- package/package.json +4 -2
- package/portal/package.json +15 -0
- package/table/package.json +15 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
var DEFAULT_INITIAL_BUCKETS = 50;
|
|
8
|
+
var DEFAULT_MAX_BUCKET_CAPACITY = 50;
|
|
9
|
+
var DEFAULT_SCALE_RATIO = 0.5;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an empty bucket object with a specified capacity. Each bucket is designed
|
|
13
|
+
* to hold a certain number of React portals and has an associated updater function
|
|
14
|
+
* which can be null initially.
|
|
15
|
+
*
|
|
16
|
+
* @function createEmptyBucket
|
|
17
|
+
* @param {number} capacity - The maximum capacity of the bucket.
|
|
18
|
+
* @returns {PortalBucketType} An object representing an empty bucket with the specified capacity.
|
|
19
|
+
*/
|
|
20
|
+
function createEmptyBucket(capacity) {
|
|
21
|
+
return {
|
|
22
|
+
portals: {},
|
|
23
|
+
capacity: capacity,
|
|
24
|
+
updater: null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A utility class to manage and dynamically scale React portals across multiple buckets.
|
|
30
|
+
* It allows for efficient rendering of large numbers of React portals by distributing them
|
|
31
|
+
* across "buckets" and updating these buckets as necessary to balance load and performance.
|
|
32
|
+
*
|
|
33
|
+
* @class PortalManager
|
|
34
|
+
* @typedef {Object} PortalManager
|
|
35
|
+
*
|
|
36
|
+
* @property {number} maxBucketCapacity - The maximum capacity of each bucket before a new bucket is created.
|
|
37
|
+
* @property {number} scaleRatio - The ratio to determine the number of new buckets to add when scaling up.
|
|
38
|
+
* @property {Array<PortalBucketType>} buckets - An array of bucket objects where each bucket holds a record of React portals.
|
|
39
|
+
* @property {Set<number>} availableBuckets - A set of indices representing buckets that have available capacity.
|
|
40
|
+
* @property {Map<React.Key, number>} portalToBucketMap - A map of React portal keys to their corresponding bucket indices.
|
|
41
|
+
* @property {PortalRendererUpdater|null} portalRendererUpdater - A function to trigger updates to the rendering of portals.
|
|
42
|
+
* @property {number} scaleCapacityThreshold - The threshold at which the buckets are scaled up to accommodate more portals.
|
|
43
|
+
*
|
|
44
|
+
* @param {number} [initialBuckets=DEFAULT_INITIAL_BUCKETS] - The initial number of buckets to create.
|
|
45
|
+
* @param {number} [maxBucketCapacity=DEFAULT_MAX_BUCKET_CAPACITY] - The maximum number of portals a single bucket can hold.
|
|
46
|
+
* @param {number} [scaleRatio=DEFAULT_SCALE_RATIO] - The ratio used to calculate the number of new buckets to add when scaling.
|
|
47
|
+
*/
|
|
48
|
+
export var PortalManager = /*#__PURE__*/function () {
|
|
49
|
+
function PortalManager() {
|
|
50
|
+
var initialBuckets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_INITIAL_BUCKETS;
|
|
51
|
+
var maxBucketCapacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_MAX_BUCKET_CAPACITY;
|
|
52
|
+
var scaleRatio = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_SCALE_RATIO;
|
|
53
|
+
_classCallCheck(this, PortalManager);
|
|
54
|
+
this.maxBucketCapacity = maxBucketCapacity;
|
|
55
|
+
this.scaleRatio = scaleRatio;
|
|
56
|
+
|
|
57
|
+
// Initialise buckets array by creating an array of length `initialBuckets` containing empty buckets
|
|
58
|
+
this.buckets = Array.from({
|
|
59
|
+
length: initialBuckets
|
|
60
|
+
}, function () {
|
|
61
|
+
return createEmptyBucket(maxBucketCapacity);
|
|
62
|
+
});
|
|
63
|
+
this.portalToBucketMap = new Map();
|
|
64
|
+
this.availableBuckets = new Set(Array.from({
|
|
65
|
+
length: initialBuckets
|
|
66
|
+
}, function (_, i) {
|
|
67
|
+
return i;
|
|
68
|
+
}));
|
|
69
|
+
this.portalRendererUpdater = null;
|
|
70
|
+
this.scaleCapacityThreshold = maxBucketCapacity / 2;
|
|
71
|
+
}
|
|
72
|
+
_createClass(PortalManager, [{
|
|
73
|
+
key: "getCurrentBucket",
|
|
74
|
+
value: function getCurrentBucket() {
|
|
75
|
+
return this.availableBuckets.values().next().value;
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "createBucket",
|
|
79
|
+
value: function createBucket() {
|
|
80
|
+
var _this$portalRendererU;
|
|
81
|
+
var currentBucket = this.getCurrentBucket();
|
|
82
|
+
|
|
83
|
+
//If the current bucket has capacity, skip this logic
|
|
84
|
+
if (this.buckets[currentBucket].capacity > 0) {
|
|
85
|
+
return;
|
|
86
|
+
} else {
|
|
87
|
+
// The current bucket is full, delete the bucket from the list of available buckets
|
|
88
|
+
this.availableBuckets.delete(currentBucket);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Skip creating new bucket if there are buckets still available
|
|
92
|
+
if (this.availableBuckets.size > 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Scale the buckets up only if there are no available buckets left
|
|
97
|
+
// Calculate how many new buckets need to be added
|
|
98
|
+
var numBucketsToAdd = Math.floor(this.buckets.length * this.scaleRatio);
|
|
99
|
+
this.buckets = _toConsumableArray(this.buckets);
|
|
100
|
+
for (var i = 0; i < numBucketsToAdd; i++) {
|
|
101
|
+
this.buckets.push(createEmptyBucket(this.maxBucketCapacity));
|
|
102
|
+
this.availableBuckets.add(this.buckets.length - 1);
|
|
103
|
+
}
|
|
104
|
+
(_this$portalRendererU = this.portalRendererUpdater) === null || _this$portalRendererU === void 0 || _this$portalRendererU.call(this, this.buckets);
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "getBuckets",
|
|
108
|
+
value: function getBuckets() {
|
|
109
|
+
return this.buckets;
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "registerBucket",
|
|
113
|
+
value: function registerBucket(id, updater) {
|
|
114
|
+
var _this$buckets$id$upda,
|
|
115
|
+
_this$buckets$id,
|
|
116
|
+
_this = this;
|
|
117
|
+
this.buckets[id].updater = updater;
|
|
118
|
+
(_this$buckets$id$upda = (_this$buckets$id = this.buckets[id]).updater) === null || _this$buckets$id$upda === void 0 || _this$buckets$id$upda.call(_this$buckets$id, function () {
|
|
119
|
+
return _objectSpread({}, _this.buckets[id].portals);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "unregisterBucket",
|
|
124
|
+
value: function unregisterBucket(id) {
|
|
125
|
+
this.buckets[id].updater = null;
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "updateBuckets",
|
|
129
|
+
value: function updateBuckets(id) {
|
|
130
|
+
var _this$buckets$id$upda2,
|
|
131
|
+
_this$buckets$id2,
|
|
132
|
+
_this2 = this;
|
|
133
|
+
(_this$buckets$id$upda2 = (_this$buckets$id2 = this.buckets[id]).updater) === null || _this$buckets$id$upda2 === void 0 || _this$buckets$id$upda2.call(_this$buckets$id2, function () {
|
|
134
|
+
// new object is required to trigger react updates
|
|
135
|
+
return _objectSpread({}, _this2.buckets[id].portals);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
key: "registerPortal",
|
|
140
|
+
value: function registerPortal(key, portal) {
|
|
141
|
+
var _this$portalToBucketM,
|
|
142
|
+
_this3 = this;
|
|
143
|
+
this.createBucket();
|
|
144
|
+
this.buckets[this.getCurrentBucket()].capacity -= 1;
|
|
145
|
+
var id = (_this$portalToBucketM = this.portalToBucketMap.get(key)) !== null && _this$portalToBucketM !== void 0 ? _this$portalToBucketM : this.getCurrentBucket();
|
|
146
|
+
this.portalToBucketMap.set(key, id);
|
|
147
|
+
if (this.buckets[id].portals[key] !== portal) {
|
|
148
|
+
this.buckets[id].portals[key] = portal;
|
|
149
|
+
this.updateBuckets(id);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//returns a function to unregister the portal
|
|
153
|
+
return function () {
|
|
154
|
+
delete _this3.buckets[id].portals[key];
|
|
155
|
+
_this3.portalToBucketMap.delete(key);
|
|
156
|
+
_this3.buckets[id].capacity += 1;
|
|
157
|
+
if (_this3.buckets[id].capacity > _this3.scaleCapacityThreshold) {
|
|
158
|
+
_this3.availableBuckets.add(id);
|
|
159
|
+
}
|
|
160
|
+
_this3.updateBuckets(id);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "registerPortalRenderer",
|
|
165
|
+
value: function registerPortalRenderer(updater) {
|
|
166
|
+
var _this4 = this;
|
|
167
|
+
if (!this.portalRendererUpdater) {
|
|
168
|
+
updater(function () {
|
|
169
|
+
return _this4.buckets;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
this.portalRendererUpdater = updater;
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
key: "unregisterPortalRenderer",
|
|
176
|
+
value: function unregisterPortalRenderer() {
|
|
177
|
+
this.portalRendererUpdater = null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Cleans up resources used by the PortalManager. This includes clearing all portals,
|
|
182
|
+
* unregistering all buckets, and resetting internal state.
|
|
183
|
+
*/
|
|
184
|
+
}, {
|
|
185
|
+
key: "destroy",
|
|
186
|
+
value: function destroy() {
|
|
187
|
+
var _this5 = this;
|
|
188
|
+
// Iterate through each bucket and clear its portals and unset the updater function
|
|
189
|
+
this.buckets.forEach(function (bucket, id) {
|
|
190
|
+
bucket.portals = {}; // Clearing all portals from the bucket
|
|
191
|
+
bucket.updater = null; // Unsetting the bucket's updater function
|
|
192
|
+
_this5.availableBuckets.add(id); // Mark all buckets as available
|
|
193
|
+
});
|
|
194
|
+
this.portalToBucketMap.clear();
|
|
195
|
+
this.portalRendererUpdater = null;
|
|
196
|
+
this.availableBuckets = new Set(this.buckets.map(function (_, index) {
|
|
197
|
+
return index;
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
}]);
|
|
201
|
+
return PortalManager;
|
|
202
|
+
}();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useEffect, useLayoutEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { PortalBucket } from './PortalBucket';
|
|
5
|
+
import { PortalManager } from './PortalManager';
|
|
6
|
+
function createPortalRendererComponent(portalManager) {
|
|
7
|
+
return function PortalRenderer() {
|
|
8
|
+
var _useState = useState(portalManager.getBuckets()),
|
|
9
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
10
|
+
buckets = _useState2[0],
|
|
11
|
+
setBuckets = _useState2[1];
|
|
12
|
+
useLayoutEffect(function () {
|
|
13
|
+
portalManager.registerPortalRenderer(setBuckets);
|
|
14
|
+
return function () {
|
|
15
|
+
portalManager.unregisterPortalRenderer();
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
var portalsElements = useMemo(function () {
|
|
19
|
+
return buckets.map(function (_, i) {
|
|
20
|
+
return /*#__PURE__*/React.createElement(PortalBucket, {
|
|
21
|
+
key: i,
|
|
22
|
+
id: i,
|
|
23
|
+
portalManager: portalManager
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}, [buckets]);
|
|
27
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, portalsElements);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initializes PortalManager and creates PortalRendererComponent. Offers an API (portalProviderAPI) for managing portals.
|
|
33
|
+
* @returns {[PortalProviderAPI, PortalRendererComponent]} An array containing two elements:
|
|
34
|
+
* 1. portalProviderAPI: An object providing an API for rendering and removing portals.
|
|
35
|
+
* 2. PortalRenderer: A React component responsible for rendering the portal content.
|
|
36
|
+
*/
|
|
37
|
+
export function usePortalProvider() {
|
|
38
|
+
var portalManager = useMemo(function () {
|
|
39
|
+
return new PortalManager();
|
|
40
|
+
}, []);
|
|
41
|
+
var PortalRenderer = useMemo(function () {
|
|
42
|
+
return createPortalRendererComponent(portalManager);
|
|
43
|
+
}, [portalManager]);
|
|
44
|
+
var portalProviderAPI = useMemo(function () {
|
|
45
|
+
var portalsMap = new Map();
|
|
46
|
+
return {
|
|
47
|
+
render: function render(key, children, container) {
|
|
48
|
+
var portal = /*#__PURE__*/createPortal(children(), container, key);
|
|
49
|
+
portalsMap.set(key, portalManager.registerPortal(key, portal));
|
|
50
|
+
},
|
|
51
|
+
remove: function remove(key) {
|
|
52
|
+
var _portalsMap$get;
|
|
53
|
+
(_portalsMap$get = portalsMap.get(key)) === null || _portalsMap$get === void 0 || _portalsMap$get();
|
|
54
|
+
portalsMap.delete(key);
|
|
55
|
+
},
|
|
56
|
+
destroy: function destroy() {
|
|
57
|
+
portalsMap.clear();
|
|
58
|
+
portalManager.destroy();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, [portalManager]);
|
|
62
|
+
|
|
63
|
+
// Cleanup on unmount
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
return function () {
|
|
66
|
+
portalProviderAPI.destroy();
|
|
67
|
+
};
|
|
68
|
+
}, [portalManager, portalProviderAPI]);
|
|
69
|
+
return [portalProviderAPI, PortalRenderer];
|
|
70
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2;
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
5
|
+
import { injectIntl } from 'react-intl-next';
|
|
6
|
+
import { N20, N30 } from '@atlaskit/theme/colors';
|
|
7
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
8
|
+
import { SortOrder } from '../types';
|
|
9
|
+
import { SORTABLE_COLUMN_ICON_CLASSNAME } from './consts';
|
|
10
|
+
import { sortingAriaLabelMessages, sortingIconMessages } from './messages';
|
|
11
|
+
export var StatusClassNames = /*#__PURE__*/function (StatusClassNames) {
|
|
12
|
+
StatusClassNames["ASC"] = "sorting-icon-svg__asc";
|
|
13
|
+
StatusClassNames["DESC"] = "sorting-icon-svg__desc";
|
|
14
|
+
StatusClassNames["NO_ORDER"] = "sorting-icon-svg__no_order";
|
|
15
|
+
StatusClassNames["SORTING_NOT_ALLOWED"] = "sorting-icon-svg__not-allowed";
|
|
16
|
+
return StatusClassNames;
|
|
17
|
+
}({});
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @atlaskit/design-system/no-css-tagged-template-expression -- needs manual remediation
|
|
20
|
+
var buttonStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n display: flex;\n height: 28px;\n width: 28px;\n margin: ", ";\n right: 0;\n top: 0;\n border: 2px solid ", ";\n border-radius: ", ";\n background-color: ", ";\n justify-content: center;\n align-items: center;\n cursor: pointer;\n\n &:hover {\n background-color: ", ";\n }\n\n &:active {\n background-color: ", ";\n }\n\n &.", "__not-allowed {\n cursor: not-allowed;\n }\n"])), "var(--ds-space-075, 6px)", "var(--ds-border, #fff)", "var(--ds-border-radius-100, 4px)", "var(--ds-surface-overlay, ".concat(N20, ")"), "var(--ds-surface-overlay-hovered, ".concat(N30, ")"), "var(--ds-surface-overlay-pressed, rgba(179, 212, 255, 0.6))", SORTABLE_COLUMN_ICON_CLASSNAME);
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @atlaskit/design-system/no-css-tagged-template-expression -- needs manual remediation
|
|
23
|
+
var iconWrapperStyles = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 8px;\n height: 12px;\n transition: transform 0.3s cubic-bezier(0.15, 1, 0.3, 1);\n transform-origin: 50% 50%;\n display: flex;\n justify-content: center;\n\n &.", " {\n transform: rotate(-180deg);\n }\n\n &.", "-inactive {\n opacity: 0.7;\n }\n"])), StatusClassNames.DESC, SORTABLE_COLUMN_ICON_CLASSNAME);
|
|
24
|
+
|
|
25
|
+
// The icon is created with CSS due to the following Firefox issue: https://product-fabric.atlassian.net/browse/ED-8001
|
|
26
|
+
// The TL;DR is that svg's in tables mess up how HTML is copied in Firefox. Using a styled div instead solves the problem.
|
|
27
|
+
// For this reason, svg's should be avoided in tables until this issue is fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=1664350
|
|
28
|
+
var iconStyles = css({
|
|
29
|
+
height: '100%',
|
|
30
|
+
width: '2px',
|
|
31
|
+
borderRadius: '50px',
|
|
32
|
+
background: "var(--ds-icon, #42526E)",
|
|
33
|
+
'&::before, &::after': {
|
|
34
|
+
background: "var(--ds-icon, #42526E)",
|
|
35
|
+
content: "''",
|
|
36
|
+
height: '2px',
|
|
37
|
+
width: '6px',
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
borderRadius: '50px'
|
|
40
|
+
},
|
|
41
|
+
'&::before': {
|
|
42
|
+
transform: 'rotate(45deg) translate(3.4px, 8.5px)'
|
|
43
|
+
},
|
|
44
|
+
'&::after': {
|
|
45
|
+
transform: 'rotate(-45deg) translate(-6.3px, 5.7px)'
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var getIconClassName = function getIconClassName(isSortingAllowed, sortOrdered) {
|
|
49
|
+
var activated = sortOrdered !== SortOrder.NO_ORDER;
|
|
50
|
+
var activeStatusClass = "".concat(SORTABLE_COLUMN_ICON_CLASSNAME, "-").concat(activated ? 'active' : 'inactive');
|
|
51
|
+
if (!isSortingAllowed) {
|
|
52
|
+
return "".concat(StatusClassNames.SORTING_NOT_ALLOWED, " ").concat(activeStatusClass);
|
|
53
|
+
}
|
|
54
|
+
switch (sortOrdered) {
|
|
55
|
+
case SortOrder.ASC:
|
|
56
|
+
return "".concat(StatusClassNames.ASC, " ").concat(activeStatusClass);
|
|
57
|
+
case SortOrder.DESC:
|
|
58
|
+
return "".concat(StatusClassNames.DESC, " ").concat(activeStatusClass);
|
|
59
|
+
default:
|
|
60
|
+
return "".concat(StatusClassNames.NO_ORDER, " ").concat(activeStatusClass);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var getTooltipTitle = function getTooltipTitle(intl, isSortingAllowed, sortOrdered) {
|
|
64
|
+
var noOrderLabel = sortingIconMessages.noOrderLabel,
|
|
65
|
+
ascOrderLabel = sortingIconMessages.ascOrderLabel,
|
|
66
|
+
descOrderLabel = sortingIconMessages.descOrderLabel,
|
|
67
|
+
invalidLabel = sortingIconMessages.invalidLabel;
|
|
68
|
+
if (!isSortingAllowed) {
|
|
69
|
+
return intl.formatMessage(invalidLabel);
|
|
70
|
+
}
|
|
71
|
+
switch (sortOrdered) {
|
|
72
|
+
case SortOrder.NO_ORDER:
|
|
73
|
+
return intl.formatMessage(noOrderLabel);
|
|
74
|
+
case SortOrder.ASC:
|
|
75
|
+
return intl.formatMessage(ascOrderLabel);
|
|
76
|
+
case SortOrder.DESC:
|
|
77
|
+
return intl.formatMessage(descOrderLabel);
|
|
78
|
+
}
|
|
79
|
+
return '';
|
|
80
|
+
};
|
|
81
|
+
var getAriaLabel = function getAriaLabel(intl, isSortingAllowed, sortOrdered) {
|
|
82
|
+
var noOrderLabel = sortingAriaLabelMessages.noOrderLabel,
|
|
83
|
+
ascOrderLabel = sortingAriaLabelMessages.ascOrderLabel,
|
|
84
|
+
descOrderLabel = sortingAriaLabelMessages.descOrderLabel,
|
|
85
|
+
invalidLabel = sortingAriaLabelMessages.invalidLabel,
|
|
86
|
+
defaultLabel = sortingAriaLabelMessages.defaultLabel;
|
|
87
|
+
if (!isSortingAllowed) {
|
|
88
|
+
return intl.formatMessage(invalidLabel);
|
|
89
|
+
}
|
|
90
|
+
switch (sortOrdered) {
|
|
91
|
+
case SortOrder.NO_ORDER:
|
|
92
|
+
return intl.formatMessage(noOrderLabel);
|
|
93
|
+
case SortOrder.ASC:
|
|
94
|
+
return intl.formatMessage(ascOrderLabel);
|
|
95
|
+
case SortOrder.DESC:
|
|
96
|
+
return intl.formatMessage(descOrderLabel);
|
|
97
|
+
}
|
|
98
|
+
return intl.formatMessage(defaultLabel);
|
|
99
|
+
};
|
|
100
|
+
var SortingIcon = function SortingIcon(_ref) {
|
|
101
|
+
var isSortingAllowed = _ref.isSortingAllowed,
|
|
102
|
+
sortOrdered = _ref.sortOrdered,
|
|
103
|
+
intl = _ref.intl,
|
|
104
|
+
onClick = _ref.onClick,
|
|
105
|
+
onKeyDown = _ref.onKeyDown;
|
|
106
|
+
var buttonClassName = "".concat(SORTABLE_COLUMN_ICON_CLASSNAME, " ").concat(sortOrdered !== SortOrder.NO_ORDER ? 'is-active' : '').concat(isSortingAllowed ? '' : " ".concat(SORTABLE_COLUMN_ICON_CLASSNAME, "__not-allowed "));
|
|
107
|
+
var content = getTooltipTitle(intl, isSortingAllowed, sortOrdered);
|
|
108
|
+
var ariaLabel = getAriaLabel(intl, isSortingAllowed, sortOrdered);
|
|
109
|
+
var handleClick = function handleClick() {
|
|
110
|
+
if (isSortingAllowed) {
|
|
111
|
+
onClick();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var handleKeyDown = function handleKeyDown(event) {
|
|
115
|
+
if (isSortingAllowed) {
|
|
116
|
+
onKeyDown(event);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
return jsx(Tooltip, {
|
|
120
|
+
delay: 0,
|
|
121
|
+
content: content,
|
|
122
|
+
position: "top"
|
|
123
|
+
}, jsx("div", {
|
|
124
|
+
css: buttonStyles,
|
|
125
|
+
className: buttonClassName,
|
|
126
|
+
role: "button",
|
|
127
|
+
tabIndex: isSortingAllowed ? 0 : -1,
|
|
128
|
+
"aria-label": ariaLabel,
|
|
129
|
+
"aria-disabled": !isSortingAllowed,
|
|
130
|
+
onClick: handleClick,
|
|
131
|
+
onKeyDown: handleKeyDown
|
|
132
|
+
}, jsx("div", {
|
|
133
|
+
css: iconWrapperStyles,
|
|
134
|
+
className: getIconClassName(isSortingAllowed, sortOrdered)
|
|
135
|
+
}, jsx("div", {
|
|
136
|
+
css: iconStyles
|
|
137
|
+
}))));
|
|
138
|
+
};
|
|
139
|
+
export default injectIntl(SortingIcon);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var SORTABLE_COLUMN_ICON_CLASSNAME = "ak-renderer-tableHeader-sorting-icon";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export var sortingIconMessages = defineMessages({
|
|
3
|
+
noOrderLabel: {
|
|
4
|
+
id: 'fabric.editor.headingLink.noOrderLabel',
|
|
5
|
+
defaultMessage: 'Sort column A to Z',
|
|
6
|
+
description: 'Sort the column in ascending order'
|
|
7
|
+
},
|
|
8
|
+
ascOrderLabel: {
|
|
9
|
+
id: 'fabric.editor.headingLink.ascOrderLabel',
|
|
10
|
+
defaultMessage: 'Sort column Z to A',
|
|
11
|
+
description: 'Sort the column in descending order'
|
|
12
|
+
},
|
|
13
|
+
descOrderLabel: {
|
|
14
|
+
id: 'fabric.editor.headingLink.descOrderLabel',
|
|
15
|
+
defaultMessage: 'Clear sorting',
|
|
16
|
+
description: 'clear the sorting from this column'
|
|
17
|
+
},
|
|
18
|
+
invalidLabel: {
|
|
19
|
+
id: 'fabric.editor.headingLink.invalidLabel',
|
|
20
|
+
defaultMessage: "\u26A0\uFE0F You can't sort a table with merged cells",
|
|
21
|
+
description: 'this sort is invalid for merged cells'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
export var sortingAriaLabelMessages = defineMessages({
|
|
25
|
+
noOrderLabel: {
|
|
26
|
+
id: 'fabric.editor.tableHeader.sorting.no',
|
|
27
|
+
defaultMessage: 'No sort applied to the column',
|
|
28
|
+
description: 'Aria-label for Sort column button when sorting was not applied or the sorting has been cleared'
|
|
29
|
+
},
|
|
30
|
+
ascOrderLabel: {
|
|
31
|
+
id: 'fabric.editor.tableHeader.sorting.asc',
|
|
32
|
+
defaultMessage: 'Ascending sort applied',
|
|
33
|
+
description: 'Aria-label for Sort column button when ascending sorting was applied'
|
|
34
|
+
},
|
|
35
|
+
descOrderLabel: {
|
|
36
|
+
id: 'fabric.editor.tableHeader.sorting.desc',
|
|
37
|
+
defaultMessage: 'Descending sort applied',
|
|
38
|
+
description: 'Aria-label for Sort column button when descending sorting was applied'
|
|
39
|
+
},
|
|
40
|
+
invalidLabel: {
|
|
41
|
+
id: 'fabric.editor.tableHeader.sorting.invalid',
|
|
42
|
+
defaultMessage: "You can't sort a table with merged cells",
|
|
43
|
+
description: 'Aria-label for Sort column button when sorting is not possible'
|
|
44
|
+
},
|
|
45
|
+
defaultLabel: {
|
|
46
|
+
id: 'fabric.editor.tableHeader.sorting.default',
|
|
47
|
+
defaultMessage: 'Sort the column',
|
|
48
|
+
description: 'Default aria-label for Sort column button'
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -15,7 +15,7 @@ import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@
|
|
|
15
15
|
import { N0, N50A, N60A, N900 } from '@atlaskit/theme/colors';
|
|
16
16
|
import Layer from '../Layer';
|
|
17
17
|
var packageName = "@atlaskit/editor-common";
|
|
18
|
-
var packageVersion = "78.
|
|
18
|
+
var packageVersion = "78.36.0";
|
|
19
19
|
var halfFocusRing = 1;
|
|
20
20
|
var dropOffset = '0, 8';
|
|
21
21
|
var DropList = /*#__PURE__*/function (_Component) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { PortalManager } from './PortalManager';
|
|
3
|
+
type PortalBucketProps = {
|
|
4
|
+
id: number;
|
|
5
|
+
portalManager: PortalManager;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A component for rendering portals managed by a `PortalManager`.
|
|
9
|
+
* It subscribes to a `PortalManager` instance to listen for changes in the portal content
|
|
10
|
+
* and renders the content of its assigned portal bucket.
|
|
11
|
+
*
|
|
12
|
+
* @param {PortalBucketProps} props The component props.
|
|
13
|
+
* @param {number} props.id The ID for the portal bucket. This ID is used by the `PortalManager` to manage the content of this bucket.
|
|
14
|
+
* @param {PortalManager} props.portalManager An instance of `PortalManager` which manages the registration and unregistration of portal buckets and their content.
|
|
15
|
+
* @returns {React.ReactElement} The React element(s) that are currently registered to this portal bucket.
|
|
16
|
+
*/
|
|
17
|
+
export declare function PortalBucket({ id, portalManager }: PortalBucketProps): JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type PortalsBucketUpdater = React.Dispatch<React.SetStateAction<Record<React.Key, React.ReactPortal>>>;
|
|
3
|
+
type PortalRendererUpdater = React.Dispatch<React.SetStateAction<Array<PortalBucketType>>>;
|
|
4
|
+
type PortalBucketType = {
|
|
5
|
+
portals: Record<React.Key, React.ReactPortal>;
|
|
6
|
+
capacity: number;
|
|
7
|
+
updater: PortalsBucketUpdater | null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A utility class to manage and dynamically scale React portals across multiple buckets.
|
|
11
|
+
* It allows for efficient rendering of large numbers of React portals by distributing them
|
|
12
|
+
* across "buckets" and updating these buckets as necessary to balance load and performance.
|
|
13
|
+
*
|
|
14
|
+
* @class PortalManager
|
|
15
|
+
* @typedef {Object} PortalManager
|
|
16
|
+
*
|
|
17
|
+
* @property {number} maxBucketCapacity - The maximum capacity of each bucket before a new bucket is created.
|
|
18
|
+
* @property {number} scaleRatio - The ratio to determine the number of new buckets to add when scaling up.
|
|
19
|
+
* @property {Array<PortalBucketType>} buckets - An array of bucket objects where each bucket holds a record of React portals.
|
|
20
|
+
* @property {Set<number>} availableBuckets - A set of indices representing buckets that have available capacity.
|
|
21
|
+
* @property {Map<React.Key, number>} portalToBucketMap - A map of React portal keys to their corresponding bucket indices.
|
|
22
|
+
* @property {PortalRendererUpdater|null} portalRendererUpdater - A function to trigger updates to the rendering of portals.
|
|
23
|
+
* @property {number} scaleCapacityThreshold - The threshold at which the buckets are scaled up to accommodate more portals.
|
|
24
|
+
*
|
|
25
|
+
* @param {number} [initialBuckets=DEFAULT_INITIAL_BUCKETS] - The initial number of buckets to create.
|
|
26
|
+
* @param {number} [maxBucketCapacity=DEFAULT_MAX_BUCKET_CAPACITY] - The maximum number of portals a single bucket can hold.
|
|
27
|
+
* @param {number} [scaleRatio=DEFAULT_SCALE_RATIO] - The ratio used to calculate the number of new buckets to add when scaling.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PortalManager {
|
|
30
|
+
private maxBucketCapacity;
|
|
31
|
+
private scaleRatio;
|
|
32
|
+
private buckets;
|
|
33
|
+
private availableBuckets;
|
|
34
|
+
private portalToBucketMap;
|
|
35
|
+
private portalRendererUpdater;
|
|
36
|
+
private scaleCapacityThreshold;
|
|
37
|
+
constructor(initialBuckets?: number, maxBucketCapacity?: number, scaleRatio?: number);
|
|
38
|
+
private getCurrentBucket;
|
|
39
|
+
private createBucket;
|
|
40
|
+
getBuckets(): PortalBucketType[];
|
|
41
|
+
registerBucket(id: number, updater: PortalsBucketUpdater): void;
|
|
42
|
+
unregisterBucket(id: number): void;
|
|
43
|
+
updateBuckets(id: number): void;
|
|
44
|
+
registerPortal(key: React.Key, portal: React.ReactPortal): () => void;
|
|
45
|
+
registerPortalRenderer(updater: PortalRendererUpdater): void;
|
|
46
|
+
unregisterPortalRenderer(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Cleans up resources used by the PortalManager. This includes clearing all portals,
|
|
49
|
+
* unregistering all buckets, and resetting internal state.
|
|
50
|
+
*/
|
|
51
|
+
destroy(): void;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type RenderFn = (key: string, children: () => React.ReactChild | JSX.Element | null, container: HTMLElement) => void;
|
|
3
|
+
type RemoveFn = (key: string) => void;
|
|
4
|
+
interface PortalProviderAPI {
|
|
5
|
+
render: RenderFn;
|
|
6
|
+
remove: RemoveFn;
|
|
7
|
+
destroy: () => void;
|
|
8
|
+
}
|
|
9
|
+
type PortalRendererComponent = () => JSX.Element;
|
|
10
|
+
type UsePortalProviderReturnType = [PortalProviderAPI, PortalRendererComponent];
|
|
11
|
+
/**
|
|
12
|
+
* Initializes PortalManager and creates PortalRendererComponent. Offers an API (portalProviderAPI) for managing portals.
|
|
13
|
+
* @returns {[PortalProviderAPI, PortalRendererComponent]} An array containing two elements:
|
|
14
|
+
* 1. portalProviderAPI: An object providing an API for rendering and removing portals.
|
|
15
|
+
* 2. PortalRenderer: A React component responsible for rendering the portal content.
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePortalProvider(): UsePortalProviderReturnType;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import { SortOrder } from '../types';
|
|
4
|
+
export declare enum StatusClassNames {
|
|
5
|
+
ASC = "sorting-icon-svg__asc",
|
|
6
|
+
DESC = "sorting-icon-svg__desc",
|
|
7
|
+
NO_ORDER = "sorting-icon-svg__no_order",
|
|
8
|
+
SORTING_NOT_ALLOWED = "sorting-icon-svg__not-allowed"
|
|
9
|
+
}
|
|
10
|
+
declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<{
|
|
11
|
+
isSortingAllowed: boolean;
|
|
12
|
+
sortOrdered?: SortOrder | undefined;
|
|
13
|
+
onClick: () => void;
|
|
14
|
+
onKeyDown: (event: import("react").KeyboardEvent<HTMLElement>) => void;
|
|
15
|
+
} & WrappedComponentProps>> & {
|
|
16
|
+
WrappedComponent: import("react").ComponentType<{
|
|
17
|
+
isSortingAllowed: boolean;
|
|
18
|
+
sortOrdered?: SortOrder | undefined;
|
|
19
|
+
onClick: () => void;
|
|
20
|
+
onKeyDown: (event: import("react").KeyboardEvent<HTMLElement>) => void;
|
|
21
|
+
} & WrappedComponentProps>;
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SORTABLE_COLUMN_ICON_CLASSNAME = "ak-renderer-tableHeader-sorting-icon";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const sortingIconMessages: {
|
|
2
|
+
noOrderLabel: {
|
|
3
|
+
id: string;
|
|
4
|
+
defaultMessage: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
ascOrderLabel: {
|
|
8
|
+
id: string;
|
|
9
|
+
defaultMessage: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
descOrderLabel: {
|
|
13
|
+
id: string;
|
|
14
|
+
defaultMessage: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
invalidLabel: {
|
|
18
|
+
id: string;
|
|
19
|
+
defaultMessage: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare const sortingAriaLabelMessages: {
|
|
24
|
+
noOrderLabel: {
|
|
25
|
+
id: string;
|
|
26
|
+
defaultMessage: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
ascOrderLabel: {
|
|
30
|
+
id: string;
|
|
31
|
+
defaultMessage: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
descOrderLabel: {
|
|
35
|
+
id: string;
|
|
36
|
+
defaultMessage: string;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
invalidLabel: {
|
|
40
|
+
id: string;
|
|
41
|
+
defaultMessage: string;
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
defaultLabel: {
|
|
45
|
+
id: string;
|
|
46
|
+
defaultMessage: string;
|
|
47
|
+
description: string;
|
|
48
|
+
};
|
|
49
|
+
};
|