@bigbinary/neeto-fields-frontend 1.0.3 → 1.0.4
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/README.md +0 -4
- package/dist/index.cjs.js +4559 -204
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +4562 -207
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import React, { useContext, useState, useRef, useEffect } from 'react';
|
|
1
|
+
import React, { useContext, useState, useRef, useEffect, useLayoutEffect, useMemo, useCallback, createContext, memo, useReducer } from 'react';
|
|
2
2
|
import { Label, Button, Pane, Typography, Switch as Switch$1, TimePicker, DatePicker, Select as Select$1, Input as Input$1, Textarea, NoData, Table, Dropdown, Spinner, Alert } from '@bigbinary/neetoui';
|
|
3
3
|
import { values, pick, isEmpty, assoc, map, isNotNil, pluck, clone as clone$1, pipe, mergeAll, omit, isNil, prop, not, head } from 'ramda';
|
|
4
4
|
import { Input, Select, Switch, Form, ActionBlock, Button as Button$1 } from '@bigbinary/neetoui/formik';
|
|
5
5
|
import { useQuery, useQueryClient, useMutation } from 'react-query';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
|
|
8
|
-
import { filterBy, toLabelAndValue, isNotEmpty, findBy, capitalize as capitalize$1 } from '@bigbinary/neeto-commons-frontend/pure';
|
|
8
|
+
import { filterBy, toLabelAndValue, isNotEmpty, findBy, countBy, capitalize as capitalize$1, existsBy } from '@bigbinary/neeto-commons-frontend/pure';
|
|
9
9
|
import * as yup from 'yup';
|
|
10
10
|
import { useFormikContext, FieldArray, useField } from 'formik';
|
|
11
|
-
import { Delete, Check, MenuHorizontal } from '@bigbinary/neeto-icons';
|
|
11
|
+
import { Delete, Check, Reorder, MenuHorizontal } from '@bigbinary/neeto-icons';
|
|
12
12
|
import Container from '@bigbinary/neeto-molecules/Container';
|
|
13
13
|
import Header from '@bigbinary/neeto-molecules/Header';
|
|
14
14
|
import MenuBar from '@bigbinary/neeto-molecules/MenuBar';
|
|
15
15
|
import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
|
|
16
16
|
import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
|
|
17
17
|
import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
|
|
18
|
+
import { unstable_batchedUpdates, createPortal } from 'react-dom';
|
|
18
19
|
import classnames from 'classnames';
|
|
19
20
|
|
|
20
21
|
/*! @license DOMPurify 3.0.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.2/LICENSE */
|
|
@@ -1754,8 +1755,8 @@ function _toArray(arr) {
|
|
|
1754
1755
|
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
|
|
1755
1756
|
}
|
|
1756
1757
|
|
|
1757
|
-
function ownKeys$6
|
|
1758
|
-
function _objectSpread$6
|
|
1758
|
+
function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1759
|
+
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1759
1760
|
var consoleLogger = {
|
|
1760
1761
|
type: 'logger',
|
|
1761
1762
|
log: function log(args) {
|
|
@@ -1833,7 +1834,7 @@ var Logger = function () {
|
|
|
1833
1834
|
}, {
|
|
1834
1835
|
key: "create",
|
|
1835
1836
|
value: function create(moduleName) {
|
|
1836
|
-
return new Logger(this.logger, _objectSpread$6
|
|
1837
|
+
return new Logger(this.logger, _objectSpread$6(_objectSpread$6({}, {
|
|
1837
1838
|
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
1838
1839
|
}), this.options));
|
|
1839
1840
|
}
|
|
@@ -3715,7 +3716,7 @@ function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if
|
|
|
3715
3716
|
function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$7(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3716
3717
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
3717
3718
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
3718
|
-
function noop() {}
|
|
3719
|
+
function noop$1() {}
|
|
3719
3720
|
function bindMemberFunctions(inst) {
|
|
3720
3721
|
var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
3721
3722
|
mems.forEach(function (mem) {
|
|
@@ -3846,7 +3847,7 @@ var I18n = function (_EventEmitter) {
|
|
|
3846
3847
|
});
|
|
3847
3848
|
}
|
|
3848
3849
|
this.format = this.options.interpolation.format;
|
|
3849
|
-
if (!callback) callback = noop;
|
|
3850
|
+
if (!callback) callback = noop$1;
|
|
3850
3851
|
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
3851
3852
|
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3852
3853
|
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
@@ -3893,7 +3894,7 @@ var I18n = function (_EventEmitter) {
|
|
|
3893
3894
|
key: "loadResources",
|
|
3894
3895
|
value: function loadResources(language) {
|
|
3895
3896
|
var _this3 = this;
|
|
3896
|
-
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
3897
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
3897
3898
|
var usedCallback = callback;
|
|
3898
3899
|
var usedLng = typeof language === 'string' ? language : this.language;
|
|
3899
3900
|
if (typeof language === 'function') usedCallback = language;
|
|
@@ -3934,7 +3935,7 @@ var I18n = function (_EventEmitter) {
|
|
|
3934
3935
|
var deferred = defer();
|
|
3935
3936
|
if (!lngs) lngs = this.languages;
|
|
3936
3937
|
if (!ns) ns = this.options.ns;
|
|
3937
|
-
if (!callback) callback = noop;
|
|
3938
|
+
if (!callback) callback = noop$1;
|
|
3938
3939
|
this.services.backendConnector.reload(lngs, ns, function (err) {
|
|
3939
3940
|
deferred.resolve();
|
|
3940
3941
|
callback(err);
|
|
@@ -4178,7 +4179,7 @@ var I18n = function (_EventEmitter) {
|
|
|
4178
4179
|
value: function cloneInstance() {
|
|
4179
4180
|
var _this8 = this;
|
|
4180
4181
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4181
|
-
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
4182
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
4182
4183
|
var mergedOptions = _objectSpread$7(_objectSpread$7(_objectSpread$7({}, this.options), options), {
|
|
4183
4184
|
isClone: true
|
|
4184
4185
|
});
|
|
@@ -4629,10 +4630,10 @@ function getDefaultExportFromCjs (x) {
|
|
|
4629
4630
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
4630
4631
|
}
|
|
4631
4632
|
|
|
4632
|
-
function ownKeys$
|
|
4633
|
+
function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4633
4634
|
|
|
4634
|
-
function _objectSpread$
|
|
4635
|
-
var defaultOptions = {
|
|
4635
|
+
function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4636
|
+
var defaultOptions$1 = {
|
|
4636
4637
|
bindI18n: 'languageChanged',
|
|
4637
4638
|
bindI18nStore: '',
|
|
4638
4639
|
transEmptyNodeValue: '',
|
|
@@ -4645,10 +4646,10 @@ var i18nInstance;
|
|
|
4645
4646
|
var I18nContext = React.createContext();
|
|
4646
4647
|
function setDefaults() {
|
|
4647
4648
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4648
|
-
defaultOptions = _objectSpread$
|
|
4649
|
+
defaultOptions$1 = _objectSpread$5(_objectSpread$5({}, defaultOptions$1), options);
|
|
4649
4650
|
}
|
|
4650
4651
|
function getDefaults() {
|
|
4651
|
-
return defaultOptions;
|
|
4652
|
+
return defaultOptions$1;
|
|
4652
4653
|
}
|
|
4653
4654
|
var ReportNamespaces = function () {
|
|
4654
4655
|
function ReportNamespaces() {
|
|
@@ -4801,9 +4802,9 @@ function _slicedToArray(arr, i) {
|
|
|
4801
4802
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
4802
4803
|
}
|
|
4803
4804
|
|
|
4804
|
-
function ownKeys$
|
|
4805
|
+
function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4805
4806
|
|
|
4806
|
-
function _objectSpread$
|
|
4807
|
+
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4807
4808
|
function useTranslation(ns) {
|
|
4808
4809
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4809
4810
|
var i18nFromProps = props.i18n;
|
|
@@ -4831,7 +4832,7 @@ function useTranslation(ns) {
|
|
|
4831
4832
|
|
|
4832
4833
|
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
4833
4834
|
|
|
4834
|
-
var i18nOptions = _objectSpread$
|
|
4835
|
+
var i18nOptions = _objectSpread$4(_objectSpread$4(_objectSpread$4({}, getDefaults()), i18n.options.react), props);
|
|
4835
4836
|
|
|
4836
4837
|
var useSuspense = i18nOptions.useSuspense,
|
|
4837
4838
|
keyPrefix = i18nOptions.keyPrefix;
|
|
@@ -4915,6 +4916,7 @@ var titles = {
|
|
|
4915
4916
|
required: "Required",
|
|
4916
4917
|
dropdownOptions: "Dropdown options",
|
|
4917
4918
|
regexOptions: "Regex options",
|
|
4919
|
+
reorderFields: "Reorder fields",
|
|
4918
4920
|
filters: "Filters"
|
|
4919
4921
|
};
|
|
4920
4922
|
var labels = {
|
|
@@ -4930,7 +4932,10 @@ var labels = {
|
|
|
4930
4932
|
regexCondition: "Condition",
|
|
4931
4933
|
helpMessage: "Help message",
|
|
4932
4934
|
isRequired: "Is required",
|
|
4933
|
-
submit: "Submit"
|
|
4935
|
+
submit: "Submit",
|
|
4936
|
+
reorder: "Reorder",
|
|
4937
|
+
saveChanges: "Save changes",
|
|
4938
|
+
cancel: "Cancel"
|
|
4934
4939
|
};
|
|
4935
4940
|
var placeholders = {
|
|
4936
4941
|
enterFieldName: "Enter field name",
|
|
@@ -4962,7 +4967,8 @@ var messages = {
|
|
|
4962
4967
|
noFields: "There are no fields to show",
|
|
4963
4968
|
confirmDelete: "Are you sure want to delete the field ?. This action cannot be undone.",
|
|
4964
4969
|
manageFieldFor: "Manage fields for {{resource}}",
|
|
4965
|
-
invalidKind: "Invalid kind"
|
|
4970
|
+
invalidKind: "Invalid kind",
|
|
4971
|
+
reorderFields: "Fields are displayed from top to bottom."
|
|
4966
4972
|
};
|
|
4967
4973
|
var validations = {
|
|
4968
4974
|
regexConditionIsRequired: "Regex condition is required",
|
|
@@ -4977,6 +4983,9 @@ var validations = {
|
|
|
4977
4983
|
thisIsRequired: "This is s required field",
|
|
4978
4984
|
minOneItem: "Select at least one item"
|
|
4979
4985
|
};
|
|
4986
|
+
var tooltips = {
|
|
4987
|
+
reorder: "Fields a are displayed from top to bottom. Re-order them"
|
|
4988
|
+
};
|
|
4980
4989
|
var en = {
|
|
4981
4990
|
common: common,
|
|
4982
4991
|
titles: titles,
|
|
@@ -4984,7 +4993,8 @@ var en = {
|
|
|
4984
4993
|
placeholders: placeholders,
|
|
4985
4994
|
fields: fields,
|
|
4986
4995
|
messages: messages,
|
|
4987
|
-
validations: validations
|
|
4996
|
+
validations: validations,
|
|
4997
|
+
tooltips: tooltips
|
|
4988
4998
|
};
|
|
4989
4999
|
|
|
4990
5000
|
instance.use(Browser).use(initReactI18next).init({
|
|
@@ -5016,8 +5026,6 @@ instance.services.formatter.addCached("boldList", function (lng, options) {
|
|
|
5016
5026
|
};
|
|
5017
5027
|
});
|
|
5018
5028
|
|
|
5019
|
-
var DEFAULT_PAGE_INDEX = 1;
|
|
5020
|
-
var DEFAULT_PAGE_SIZE = 10;
|
|
5021
5029
|
var KINDS = {
|
|
5022
5030
|
text: "text",
|
|
5023
5031
|
number: "number",
|
|
@@ -5084,6 +5092,7 @@ var FIELDS_URL = "".concat(NEETO_FIELDS_URL, "/fields");
|
|
|
5084
5092
|
var FIELD_VALUES_URL = "".concat(NEETO_FIELDS_URL, "/field_values");
|
|
5085
5093
|
var FIELD_VALUE_URL = "".concat(NEETO_FIELDS_URL, "/field_values/:fieldValueId");
|
|
5086
5094
|
var FIELD_URL = "".concat(NEETO_FIELDS_URL, "/fields/:fieldId");
|
|
5095
|
+
var FIELDS_REORDER_URL = "".concat(FIELDS_URL, "/reorder");
|
|
5087
5096
|
var CONFIGS_URL = "".concat(NEETO_FIELDS_URL, "/configs");
|
|
5088
5097
|
var SINGULAR = {
|
|
5089
5098
|
count: 1
|
|
@@ -5098,15 +5107,11 @@ var fieldUrl = function fieldUrl(fieldId) {
|
|
|
5098
5107
|
});
|
|
5099
5108
|
};
|
|
5100
5109
|
var fetch$1 = function fetch(_ref) {
|
|
5101
|
-
var
|
|
5102
|
-
pageIndex = _ref.pageIndex,
|
|
5103
|
-
resourceType = _ref.resourceType,
|
|
5110
|
+
var resourceType = _ref.resourceType,
|
|
5104
5111
|
ownerId = _ref.ownerId,
|
|
5105
5112
|
state = _ref.state;
|
|
5106
5113
|
return axios.get(FIELDS_URL, {
|
|
5107
5114
|
params: {
|
|
5108
|
-
pageSize: pageSize,
|
|
5109
|
-
pageIndex: pageIndex,
|
|
5110
5115
|
resourceType: resourceType,
|
|
5111
5116
|
ownerId: ownerId,
|
|
5112
5117
|
state: state
|
|
@@ -5131,12 +5136,16 @@ var update$1 = function update(_ref2) {
|
|
|
5131
5136
|
field: payload
|
|
5132
5137
|
});
|
|
5133
5138
|
};
|
|
5139
|
+
var reorder = function reorder(payload) {
|
|
5140
|
+
return axios.patch(FIELDS_REORDER_URL, payload);
|
|
5141
|
+
};
|
|
5134
5142
|
var fieldsApi = {
|
|
5135
5143
|
fetch: fetch$1,
|
|
5136
5144
|
create: create$1,
|
|
5137
5145
|
show: show,
|
|
5138
5146
|
destroy: destroy$1,
|
|
5139
|
-
update: update$1
|
|
5147
|
+
update: update$1,
|
|
5148
|
+
reorder: reorder
|
|
5140
5149
|
};
|
|
5141
5150
|
|
|
5142
5151
|
var QUERY_KEYS = {
|
|
@@ -5147,15 +5156,11 @@ var QUERY_KEYS = {
|
|
|
5147
5156
|
|
|
5148
5157
|
var FIELDS = QUERY_KEYS.FIELDS;
|
|
5149
5158
|
var useFetchFields = function useFetchFields(_ref, options) {
|
|
5150
|
-
var
|
|
5151
|
-
pageIndex = _ref.pageIndex,
|
|
5152
|
-
resourceType = _ref.resourceType,
|
|
5159
|
+
var resourceType = _ref.resourceType,
|
|
5153
5160
|
ownerId = _ref.ownerId,
|
|
5154
5161
|
state = _ref.state;
|
|
5155
|
-
return useQuery([FIELDS,
|
|
5162
|
+
return useQuery([FIELDS, resourceType, ownerId, state], function () {
|
|
5156
5163
|
return fieldsApi.fetch({
|
|
5157
|
-
pageSize: pageSize,
|
|
5158
|
-
pageIndex: pageIndex,
|
|
5159
5164
|
resourceType: resourceType,
|
|
5160
5165
|
ownerId: ownerId,
|
|
5161
5166
|
state: state
|
|
@@ -5192,12 +5197,20 @@ var useDestroyField = function useDestroyField() {
|
|
|
5192
5197
|
}
|
|
5193
5198
|
});
|
|
5194
5199
|
};
|
|
5200
|
+
var useReorderFields = function useReorderFields() {
|
|
5201
|
+
var queryClient = useQueryClient();
|
|
5202
|
+
return useMutation(fieldsApi.reorder, {
|
|
5203
|
+
onSuccess: function onSuccess() {
|
|
5204
|
+
queryClient.invalidateQueries(FIELDS);
|
|
5205
|
+
}
|
|
5206
|
+
});
|
|
5207
|
+
};
|
|
5195
5208
|
|
|
5196
|
-
function ownKeys$
|
|
5197
|
-
function _objectSpread$
|
|
5209
|
+
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5210
|
+
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5198
5211
|
var arrangeOptionsDisplayOrder = function arrangeOptionsDisplayOrder(options) {
|
|
5199
5212
|
return options.map(function (option, index) {
|
|
5200
|
-
return _objectSpread$
|
|
5213
|
+
return _objectSpread$3(_objectSpread$3({}, option), {}, {
|
|
5201
5214
|
displayOrder: index
|
|
5202
5215
|
});
|
|
5203
5216
|
});
|
|
@@ -5209,7 +5222,7 @@ var buildPayload = function buildPayload(_ref) {
|
|
|
5209
5222
|
_ref$ownerId = _ref.ownerId,
|
|
5210
5223
|
ownerId = _ref$ownerId === void 0 ? "" : _ref$ownerId;
|
|
5211
5224
|
var kind = formValues.kind.value;
|
|
5212
|
-
return _objectSpread$
|
|
5225
|
+
return _objectSpread$3(_objectSpread$3({}, pick(["name", "isRequired"], formValues)), {}, {
|
|
5213
5226
|
kind: kind,
|
|
5214
5227
|
resourceType: isEmpty(resourceType) ? undefined : resourceType,
|
|
5215
5228
|
ownerId: isEmpty(ownerId) ? undefined : ownerId,
|
|
@@ -5235,7 +5248,7 @@ var getPermittedKinds = function getPermittedKinds(_ref2) {
|
|
|
5235
5248
|
return permittedKinds;
|
|
5236
5249
|
};
|
|
5237
5250
|
var generateValidationSchema = function generateValidationSchema(additionalValidations) {
|
|
5238
|
-
return yup.object().shape(_objectSpread$
|
|
5251
|
+
return yup.object().shape(_objectSpread$3(_objectSpread$3({}, BASIC_FIELD_FORM_VALIDATIONS), additionalValidations));
|
|
5239
5252
|
};
|
|
5240
5253
|
|
|
5241
5254
|
var regexValidationSchema = yup.object().shape({
|
|
@@ -6159,8 +6172,8 @@ var dateTimeToString = function dateTimeToString(dateTime) {
|
|
|
6159
6172
|
return dayjs(dateTime).toString();
|
|
6160
6173
|
};
|
|
6161
6174
|
|
|
6162
|
-
function ownKeys$
|
|
6163
|
-
function _objectSpread$
|
|
6175
|
+
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6176
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6164
6177
|
var useFormikFields = function useFormikFields(_ref) {
|
|
6165
6178
|
var name = _ref.name,
|
|
6166
6179
|
fieldId = _ref.id,
|
|
@@ -6205,7 +6218,7 @@ var useFormikFields = function useFormikFields(_ref) {
|
|
|
6205
6218
|
var isDropdown = ["single_option", "multi_option"].includes(kind);
|
|
6206
6219
|
return {
|
|
6207
6220
|
handleSubmit: handleSubmit,
|
|
6208
|
-
fieldProps: _objectSpread$
|
|
6221
|
+
fieldProps: _objectSpread$2(_objectSpread$2({}, formikFieldProps), {}, {
|
|
6209
6222
|
required: isRequired,
|
|
6210
6223
|
error: meta.error,
|
|
6211
6224
|
options: isDropdown && buildOptionsToLabelAndValue(fieldData),
|
|
@@ -6362,8 +6375,8 @@ var TextArea = function TextArea(props) {
|
|
|
6362
6375
|
}));
|
|
6363
6376
|
};
|
|
6364
6377
|
|
|
6365
|
-
function ownKeys$
|
|
6366
|
-
function _objectSpread$
|
|
6378
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6379
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6367
6380
|
var standardComponents = {
|
|
6368
6381
|
text: Text,
|
|
6369
6382
|
regex: Text,
|
|
@@ -6417,7 +6430,7 @@ var transformValues = function transformValues(_ref2) {
|
|
|
6417
6430
|
delete allFieldValues["".concat(name, "-").concat(id)];
|
|
6418
6431
|
});
|
|
6419
6432
|
var cleanedFieldValues = pipe(removeItemsWithNullData, removeNoiseFromValues)(neetoFieldValues);
|
|
6420
|
-
return _objectSpread$
|
|
6433
|
+
return _objectSpread$1(_objectSpread$1({}, allFieldValues), {}, {
|
|
6421
6434
|
fieldValuesAttributes: cleanedFieldValues
|
|
6422
6435
|
});
|
|
6423
6436
|
};
|
|
@@ -6478,21 +6491,15 @@ var useFetchConfigs = function useFetchConfigs() {
|
|
|
6478
6491
|
};
|
|
6479
6492
|
|
|
6480
6493
|
var FieldsTable = function FieldsTable(_ref) {
|
|
6481
|
-
var
|
|
6482
|
-
pageIndex = _ref$pageProps.pageIndex,
|
|
6483
|
-
pageSize = _ref$pageProps.pageSize,
|
|
6484
|
-
totalCount = _ref.totalCount,
|
|
6494
|
+
var totalCount = _ref.totalCount,
|
|
6485
6495
|
isLoading = _ref.isLoading,
|
|
6486
6496
|
rowData = _ref.rowData,
|
|
6487
6497
|
columnData = _ref.columnData,
|
|
6488
|
-
setPageProps = _ref.setPageProps,
|
|
6489
6498
|
setIsPaneOpen = _ref.setIsPaneOpen;
|
|
6490
6499
|
var _useTranslation = useTranslation(),
|
|
6491
6500
|
t = _useTranslation.t;
|
|
6492
6501
|
var showNoDataScreen = !isLoading && isEmpty(rowData);
|
|
6493
|
-
return /*#__PURE__*/React.createElement(TableWrapper, {
|
|
6494
|
-
hasPagination: pageIndex > totalCount / pageSize
|
|
6495
|
-
}, showNoDataScreen ? /*#__PURE__*/React.createElement("div", {
|
|
6502
|
+
return /*#__PURE__*/React.createElement(TableWrapper, null, showNoDataScreen ? /*#__PURE__*/React.createElement("div", {
|
|
6496
6503
|
className: "flex h-full w-full items-center justify-center"
|
|
6497
6504
|
}, /*#__PURE__*/React.createElement(NoData, {
|
|
6498
6505
|
title: t("messages.noFields"),
|
|
@@ -6506,153 +6513,4489 @@ var FieldsTable = function FieldsTable(_ref) {
|
|
|
6506
6513
|
fixedHeight: true,
|
|
6507
6514
|
allowRowClick: false,
|
|
6508
6515
|
columnData: columnData,
|
|
6509
|
-
currentPageNumber: pageIndex,
|
|
6510
|
-
defaultPageSize: pageSize,
|
|
6511
6516
|
loading: isLoading,
|
|
6512
6517
|
rowData: rowData,
|
|
6513
|
-
totalCount: totalCount
|
|
6514
|
-
handlePageChange: function handlePageChange(pageIndex, pageSize) {
|
|
6515
|
-
setPageProps({
|
|
6516
|
-
pageIndex: pageIndex,
|
|
6517
|
-
pageSize: pageSize
|
|
6518
|
-
});
|
|
6519
|
-
}
|
|
6518
|
+
totalCount: totalCount
|
|
6520
6519
|
}));
|
|
6521
6520
|
};
|
|
6522
6521
|
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
return
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6522
|
+
function useCombinedRefs() {
|
|
6523
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6524
|
+
refs[_key] = arguments[_key];
|
|
6525
|
+
}
|
|
6526
|
+
|
|
6527
|
+
return useMemo(() => node => {
|
|
6528
|
+
refs.forEach(ref => ref(node));
|
|
6529
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6530
|
+
refs);
|
|
6531
|
+
}
|
|
6532
|
+
|
|
6533
|
+
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
|
|
6534
|
+
const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
6535
|
+
|
|
6536
|
+
function isWindow(element) {
|
|
6537
|
+
const elementString = Object.prototype.toString.call(element);
|
|
6538
|
+
return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
|
|
6539
|
+
elementString === '[object global]';
|
|
6540
|
+
}
|
|
6541
|
+
|
|
6542
|
+
function isNode(node) {
|
|
6543
|
+
return 'nodeType' in node;
|
|
6544
|
+
}
|
|
6545
|
+
|
|
6546
|
+
function getWindow(target) {
|
|
6547
|
+
var _target$ownerDocument, _target$ownerDocument2;
|
|
6548
|
+
|
|
6549
|
+
if (!target) {
|
|
6550
|
+
return window;
|
|
6551
|
+
}
|
|
6552
|
+
|
|
6553
|
+
if (isWindow(target)) {
|
|
6554
|
+
return target;
|
|
6555
|
+
}
|
|
6556
|
+
|
|
6557
|
+
if (!isNode(target)) {
|
|
6558
|
+
return window;
|
|
6559
|
+
}
|
|
6560
|
+
|
|
6561
|
+
return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
|
|
6562
|
+
}
|
|
6563
|
+
|
|
6564
|
+
function isDocument(node) {
|
|
6565
|
+
const {
|
|
6566
|
+
Document
|
|
6567
|
+
} = getWindow(node);
|
|
6568
|
+
return node instanceof Document;
|
|
6569
|
+
}
|
|
6570
|
+
|
|
6571
|
+
function isHTMLElement(node) {
|
|
6572
|
+
if (isWindow(node)) {
|
|
6573
|
+
return false;
|
|
6574
|
+
}
|
|
6575
|
+
|
|
6576
|
+
return node instanceof getWindow(node).HTMLElement;
|
|
6577
|
+
}
|
|
6578
|
+
|
|
6579
|
+
function isSVGElement(node) {
|
|
6580
|
+
return node instanceof getWindow(node).SVGElement;
|
|
6581
|
+
}
|
|
6582
|
+
|
|
6583
|
+
function getOwnerDocument(target) {
|
|
6584
|
+
if (!target) {
|
|
6585
|
+
return document;
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6588
|
+
if (isWindow(target)) {
|
|
6589
|
+
return target.document;
|
|
6590
|
+
}
|
|
6591
|
+
|
|
6592
|
+
if (!isNode(target)) {
|
|
6593
|
+
return document;
|
|
6594
|
+
}
|
|
6595
|
+
|
|
6596
|
+
if (isDocument(target)) {
|
|
6597
|
+
return target;
|
|
6598
|
+
}
|
|
6599
|
+
|
|
6600
|
+
if (isHTMLElement(target)) {
|
|
6601
|
+
return target.ownerDocument;
|
|
6602
|
+
}
|
|
6603
|
+
|
|
6604
|
+
return document;
|
|
6605
|
+
}
|
|
6606
|
+
|
|
6607
|
+
/**
|
|
6608
|
+
* A hook that resolves to useEffect on the server and useLayoutEffect on the client
|
|
6609
|
+
* @param callback {function} Callback function that is invoked when the dependencies of the hook change
|
|
6610
|
+
*/
|
|
6611
|
+
|
|
6612
|
+
const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
|
|
6613
|
+
|
|
6614
|
+
function useEvent(handler) {
|
|
6615
|
+
const handlerRef = useRef(handler);
|
|
6616
|
+
useIsomorphicLayoutEffect(() => {
|
|
6617
|
+
handlerRef.current = handler;
|
|
6618
|
+
});
|
|
6619
|
+
return useCallback(function () {
|
|
6620
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6621
|
+
args[_key] = arguments[_key];
|
|
6553
6622
|
}
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6623
|
+
|
|
6624
|
+
return handlerRef.current == null ? void 0 : handlerRef.current(...args);
|
|
6625
|
+
}, []);
|
|
6626
|
+
}
|
|
6627
|
+
|
|
6628
|
+
function useInterval() {
|
|
6629
|
+
const intervalRef = useRef(null);
|
|
6630
|
+
const set = useCallback((listener, duration) => {
|
|
6631
|
+
intervalRef.current = setInterval(listener, duration);
|
|
6632
|
+
}, []);
|
|
6633
|
+
const clear = useCallback(() => {
|
|
6634
|
+
if (intervalRef.current !== null) {
|
|
6635
|
+
clearInterval(intervalRef.current);
|
|
6636
|
+
intervalRef.current = null;
|
|
6637
|
+
}
|
|
6638
|
+
}, []);
|
|
6639
|
+
return [set, clear];
|
|
6640
|
+
}
|
|
6641
|
+
|
|
6642
|
+
function useLatestValue(value, dependencies) {
|
|
6643
|
+
if (dependencies === void 0) {
|
|
6644
|
+
dependencies = [value];
|
|
6645
|
+
}
|
|
6646
|
+
|
|
6647
|
+
const valueRef = useRef(value);
|
|
6648
|
+
useIsomorphicLayoutEffect(() => {
|
|
6649
|
+
if (valueRef.current !== value) {
|
|
6650
|
+
valueRef.current = value;
|
|
6560
6651
|
}
|
|
6561
|
-
},
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6652
|
+
}, dependencies);
|
|
6653
|
+
return valueRef;
|
|
6654
|
+
}
|
|
6655
|
+
|
|
6656
|
+
function useLazyMemo(callback, dependencies) {
|
|
6657
|
+
const valueRef = useRef();
|
|
6658
|
+
return useMemo(() => {
|
|
6659
|
+
const newValue = callback(valueRef.current);
|
|
6660
|
+
valueRef.current = newValue;
|
|
6661
|
+
return newValue;
|
|
6662
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6663
|
+
[...dependencies]);
|
|
6664
|
+
}
|
|
6665
|
+
|
|
6666
|
+
function useNodeRef(onChange) {
|
|
6667
|
+
const onChangeHandler = useEvent(onChange);
|
|
6668
|
+
const node = useRef(null);
|
|
6669
|
+
const setNodeRef = useCallback(element => {
|
|
6670
|
+
if (element !== node.current) {
|
|
6671
|
+
onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
|
|
6567
6672
|
}
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6673
|
+
|
|
6674
|
+
node.current = element;
|
|
6675
|
+
}, //eslint-disable-next-line
|
|
6676
|
+
[]);
|
|
6677
|
+
return [node, setNodeRef];
|
|
6678
|
+
}
|
|
6679
|
+
|
|
6680
|
+
function usePrevious(value) {
|
|
6681
|
+
const ref = useRef();
|
|
6682
|
+
useEffect(() => {
|
|
6683
|
+
ref.current = value;
|
|
6684
|
+
}, [value]);
|
|
6685
|
+
return ref.current;
|
|
6686
|
+
}
|
|
6687
|
+
|
|
6688
|
+
let ids = {};
|
|
6689
|
+
function useUniqueId(prefix, value) {
|
|
6690
|
+
return useMemo(() => {
|
|
6691
|
+
if (value) {
|
|
6692
|
+
return value;
|
|
6693
|
+
}
|
|
6694
|
+
|
|
6695
|
+
const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
|
|
6696
|
+
ids[prefix] = id;
|
|
6697
|
+
return prefix + "-" + id;
|
|
6698
|
+
}, [prefix, value]);
|
|
6699
|
+
}
|
|
6700
|
+
|
|
6701
|
+
function createAdjustmentFn(modifier) {
|
|
6702
|
+
return function (object) {
|
|
6703
|
+
for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
6704
|
+
adjustments[_key - 1] = arguments[_key];
|
|
6705
|
+
}
|
|
6706
|
+
|
|
6707
|
+
return adjustments.reduce((accumulator, adjustment) => {
|
|
6708
|
+
const entries = Object.entries(adjustment);
|
|
6709
|
+
|
|
6710
|
+
for (const [key, valueAdjustment] of entries) {
|
|
6711
|
+
const value = accumulator[key];
|
|
6712
|
+
|
|
6713
|
+
if (value != null) {
|
|
6714
|
+
accumulator[key] = value + modifier * valueAdjustment;
|
|
6586
6715
|
}
|
|
6587
|
-
});
|
|
6588
|
-
});
|
|
6589
|
-
}
|
|
6590
|
-
return items.map(function (item) {
|
|
6591
|
-
return /*#__PURE__*/React.createElement(MenuBar.Item, {
|
|
6592
|
-
active: selectedMenu === item,
|
|
6593
|
-
description: t("messages.manageFieldFor", {
|
|
6594
|
-
resource: item
|
|
6595
|
-
}),
|
|
6596
|
-
key: item,
|
|
6597
|
-
label: capitalize$1(item),
|
|
6598
|
-
onClick: function onClick() {
|
|
6599
|
-
return setSelectedMenu(item);
|
|
6600
6716
|
}
|
|
6717
|
+
|
|
6718
|
+
return accumulator;
|
|
6719
|
+
}, { ...object
|
|
6601
6720
|
});
|
|
6602
|
-
}
|
|
6603
|
-
}
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6721
|
+
};
|
|
6722
|
+
}
|
|
6723
|
+
|
|
6724
|
+
const add = /*#__PURE__*/createAdjustmentFn(1);
|
|
6725
|
+
const subtract = /*#__PURE__*/createAdjustmentFn(-1);
|
|
6726
|
+
|
|
6727
|
+
function hasViewportRelativeCoordinates(event) {
|
|
6728
|
+
return 'clientX' in event && 'clientY' in event;
|
|
6729
|
+
}
|
|
6730
|
+
|
|
6731
|
+
function isKeyboardEvent(event) {
|
|
6732
|
+
if (!event) {
|
|
6733
|
+
return false;
|
|
6734
|
+
}
|
|
6735
|
+
|
|
6736
|
+
const {
|
|
6737
|
+
KeyboardEvent
|
|
6738
|
+
} = getWindow(event.target);
|
|
6739
|
+
return KeyboardEvent && event instanceof KeyboardEvent;
|
|
6740
|
+
}
|
|
6741
|
+
|
|
6742
|
+
function isTouchEvent(event) {
|
|
6743
|
+
if (!event) {
|
|
6744
|
+
return false;
|
|
6745
|
+
}
|
|
6746
|
+
|
|
6747
|
+
const {
|
|
6748
|
+
TouchEvent
|
|
6749
|
+
} = getWindow(event.target);
|
|
6750
|
+
return TouchEvent && event instanceof TouchEvent;
|
|
6751
|
+
}
|
|
6752
|
+
|
|
6753
|
+
/**
|
|
6754
|
+
* Returns the normalized x and y coordinates for mouse and touch events.
|
|
6755
|
+
*/
|
|
6756
|
+
|
|
6757
|
+
function getEventCoordinates(event) {
|
|
6758
|
+
if (isTouchEvent(event)) {
|
|
6759
|
+
if (event.touches && event.touches.length) {
|
|
6760
|
+
const {
|
|
6761
|
+
clientX: x,
|
|
6762
|
+
clientY: y
|
|
6763
|
+
} = event.touches[0];
|
|
6764
|
+
return {
|
|
6765
|
+
x,
|
|
6766
|
+
y
|
|
6767
|
+
};
|
|
6768
|
+
} else if (event.changedTouches && event.changedTouches.length) {
|
|
6769
|
+
const {
|
|
6770
|
+
clientX: x,
|
|
6771
|
+
clientY: y
|
|
6772
|
+
} = event.changedTouches[0];
|
|
6773
|
+
return {
|
|
6774
|
+
x,
|
|
6775
|
+
y
|
|
6776
|
+
};
|
|
6627
6777
|
}
|
|
6628
|
-
}
|
|
6629
|
-
};
|
|
6630
|
-
var getDashBoardTitle = function getDashBoardTitle(_ref4) {
|
|
6631
|
-
var _findBy;
|
|
6632
|
-
var isOwnerBased = _ref4.isOwnerBased,
|
|
6633
|
-
owners = _ref4.owners,
|
|
6634
|
-
selectedVal = _ref4.selectedVal;
|
|
6635
|
-
return t("messages.manageFieldFor", {
|
|
6636
|
-
resource: isOwnerBased ? (_findBy = findBy({
|
|
6637
|
-
id: selectedVal
|
|
6638
|
-
}, owners)) === null || _findBy === void 0 ? void 0 : _findBy.name : selectedVal
|
|
6639
|
-
});
|
|
6640
|
-
};
|
|
6778
|
+
}
|
|
6641
6779
|
|
|
6642
|
-
|
|
6643
|
-
|
|
6780
|
+
if (hasViewportRelativeCoordinates(event)) {
|
|
6781
|
+
return {
|
|
6782
|
+
x: event.clientX,
|
|
6783
|
+
y: event.clientY
|
|
6784
|
+
};
|
|
6785
|
+
}
|
|
6644
6786
|
|
|
6645
|
-
|
|
6787
|
+
return null;
|
|
6788
|
+
}
|
|
6646
6789
|
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6790
|
+
const CSS = /*#__PURE__*/Object.freeze({
|
|
6791
|
+
Translate: {
|
|
6792
|
+
toString(transform) {
|
|
6793
|
+
if (!transform) {
|
|
6794
|
+
return;
|
|
6795
|
+
}
|
|
6796
|
+
|
|
6797
|
+
const {
|
|
6798
|
+
x,
|
|
6799
|
+
y
|
|
6800
|
+
} = transform;
|
|
6801
|
+
return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
|
|
6802
|
+
}
|
|
6803
|
+
|
|
6804
|
+
},
|
|
6805
|
+
Scale: {
|
|
6806
|
+
toString(transform) {
|
|
6807
|
+
if (!transform) {
|
|
6808
|
+
return;
|
|
6809
|
+
}
|
|
6810
|
+
|
|
6811
|
+
const {
|
|
6812
|
+
scaleX,
|
|
6813
|
+
scaleY
|
|
6814
|
+
} = transform;
|
|
6815
|
+
return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
|
|
6816
|
+
}
|
|
6817
|
+
|
|
6818
|
+
},
|
|
6819
|
+
Transform: {
|
|
6820
|
+
toString(transform) {
|
|
6821
|
+
if (!transform) {
|
|
6822
|
+
return;
|
|
6823
|
+
}
|
|
6824
|
+
|
|
6825
|
+
return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
|
|
6826
|
+
}
|
|
6827
|
+
|
|
6828
|
+
},
|
|
6829
|
+
Transition: {
|
|
6830
|
+
toString(_ref) {
|
|
6831
|
+
let {
|
|
6832
|
+
property,
|
|
6833
|
+
duration,
|
|
6834
|
+
easing
|
|
6835
|
+
} = _ref;
|
|
6836
|
+
return property + " " + duration + "ms " + easing;
|
|
6837
|
+
}
|
|
6838
|
+
|
|
6839
|
+
}
|
|
6840
|
+
});
|
|
6841
|
+
|
|
6842
|
+
const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
|
|
6843
|
+
function findFirstFocusableNode(element) {
|
|
6844
|
+
if (element.matches(SELECTOR)) {
|
|
6845
|
+
return element;
|
|
6846
|
+
}
|
|
6847
|
+
|
|
6848
|
+
return element.querySelector(SELECTOR);
|
|
6849
|
+
}
|
|
6850
|
+
|
|
6851
|
+
const hiddenStyles = {
|
|
6852
|
+
display: 'none'
|
|
6853
|
+
};
|
|
6854
|
+
function HiddenText(_ref) {
|
|
6855
|
+
let {
|
|
6856
|
+
id,
|
|
6857
|
+
value
|
|
6858
|
+
} = _ref;
|
|
6859
|
+
return React.createElement("div", {
|
|
6860
|
+
id: id,
|
|
6861
|
+
style: hiddenStyles
|
|
6862
|
+
}, value);
|
|
6863
|
+
}
|
|
6864
|
+
|
|
6865
|
+
const visuallyHidden = {
|
|
6866
|
+
position: 'fixed',
|
|
6867
|
+
width: 1,
|
|
6868
|
+
height: 1,
|
|
6869
|
+
margin: -1,
|
|
6870
|
+
border: 0,
|
|
6871
|
+
padding: 0,
|
|
6872
|
+
overflow: 'hidden',
|
|
6873
|
+
clip: 'rect(0 0 0 0)',
|
|
6874
|
+
clipPath: 'inset(100%)',
|
|
6875
|
+
whiteSpace: 'nowrap'
|
|
6876
|
+
};
|
|
6877
|
+
function LiveRegion(_ref) {
|
|
6878
|
+
let {
|
|
6879
|
+
id,
|
|
6880
|
+
announcement
|
|
6881
|
+
} = _ref;
|
|
6882
|
+
return React.createElement("div", {
|
|
6883
|
+
id: id,
|
|
6884
|
+
style: visuallyHidden,
|
|
6885
|
+
role: "status",
|
|
6886
|
+
"aria-live": "assertive",
|
|
6887
|
+
"aria-atomic": true
|
|
6888
|
+
}, announcement);
|
|
6889
|
+
}
|
|
6890
|
+
|
|
6891
|
+
function useAnnouncement() {
|
|
6892
|
+
const [announcement, setAnnouncement] = useState('');
|
|
6893
|
+
const announce = useCallback(value => {
|
|
6894
|
+
if (value != null) {
|
|
6895
|
+
setAnnouncement(value);
|
|
6896
|
+
}
|
|
6897
|
+
}, []);
|
|
6898
|
+
return {
|
|
6899
|
+
announce,
|
|
6900
|
+
announcement
|
|
6901
|
+
};
|
|
6902
|
+
}
|
|
6903
|
+
|
|
6904
|
+
const DndMonitorContext = /*#__PURE__*/createContext(null);
|
|
6905
|
+
|
|
6906
|
+
function useDndMonitor(listener) {
|
|
6907
|
+
const registerListener = useContext(DndMonitorContext);
|
|
6908
|
+
useEffect(() => {
|
|
6909
|
+
if (!registerListener) {
|
|
6910
|
+
throw new Error('useDndMonitor must be used within a children of <DndContext>');
|
|
6911
|
+
}
|
|
6912
|
+
|
|
6913
|
+
const unsubscribe = registerListener(listener);
|
|
6914
|
+
return unsubscribe;
|
|
6915
|
+
}, [listener, registerListener]);
|
|
6916
|
+
}
|
|
6917
|
+
|
|
6918
|
+
function useDndMonitorProvider() {
|
|
6919
|
+
const [listeners] = useState(() => new Set());
|
|
6920
|
+
const registerListener = useCallback(listener => {
|
|
6921
|
+
listeners.add(listener);
|
|
6922
|
+
return () => listeners.delete(listener);
|
|
6923
|
+
}, [listeners]);
|
|
6924
|
+
const dispatch = useCallback(_ref => {
|
|
6925
|
+
let {
|
|
6926
|
+
type,
|
|
6927
|
+
event
|
|
6928
|
+
} = _ref;
|
|
6929
|
+
listeners.forEach(listener => {
|
|
6930
|
+
var _listener$type;
|
|
6931
|
+
|
|
6932
|
+
return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
|
|
6933
|
+
});
|
|
6934
|
+
}, [listeners]);
|
|
6935
|
+
return [dispatch, registerListener];
|
|
6936
|
+
}
|
|
6937
|
+
|
|
6938
|
+
const defaultScreenReaderInstructions = {
|
|
6939
|
+
draggable: "\n To pick up a draggable item, press the space bar.\n While dragging, use the arrow keys to move the item.\n Press space again to drop the item in its new position, or press escape to cancel.\n "
|
|
6940
|
+
};
|
|
6941
|
+
const defaultAnnouncements = {
|
|
6942
|
+
onDragStart(_ref) {
|
|
6943
|
+
let {
|
|
6944
|
+
active
|
|
6945
|
+
} = _ref;
|
|
6946
|
+
return "Picked up draggable item " + active.id + ".";
|
|
6947
|
+
},
|
|
6948
|
+
|
|
6949
|
+
onDragOver(_ref2) {
|
|
6950
|
+
let {
|
|
6951
|
+
active,
|
|
6952
|
+
over
|
|
6953
|
+
} = _ref2;
|
|
6954
|
+
|
|
6955
|
+
if (over) {
|
|
6956
|
+
return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
|
|
6957
|
+
}
|
|
6958
|
+
|
|
6959
|
+
return "Draggable item " + active.id + " is no longer over a droppable area.";
|
|
6960
|
+
},
|
|
6961
|
+
|
|
6962
|
+
onDragEnd(_ref3) {
|
|
6963
|
+
let {
|
|
6964
|
+
active,
|
|
6965
|
+
over
|
|
6966
|
+
} = _ref3;
|
|
6967
|
+
|
|
6968
|
+
if (over) {
|
|
6969
|
+
return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
|
|
6970
|
+
}
|
|
6971
|
+
|
|
6972
|
+
return "Draggable item " + active.id + " was dropped.";
|
|
6973
|
+
},
|
|
6974
|
+
|
|
6975
|
+
onDragCancel(_ref4) {
|
|
6976
|
+
let {
|
|
6977
|
+
active
|
|
6978
|
+
} = _ref4;
|
|
6979
|
+
return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
|
|
6980
|
+
}
|
|
6981
|
+
|
|
6982
|
+
};
|
|
6983
|
+
|
|
6984
|
+
function Accessibility(_ref) {
|
|
6985
|
+
let {
|
|
6986
|
+
announcements = defaultAnnouncements,
|
|
6987
|
+
container,
|
|
6988
|
+
hiddenTextDescribedById,
|
|
6989
|
+
screenReaderInstructions = defaultScreenReaderInstructions
|
|
6990
|
+
} = _ref;
|
|
6991
|
+
const {
|
|
6992
|
+
announce,
|
|
6993
|
+
announcement
|
|
6994
|
+
} = useAnnouncement();
|
|
6995
|
+
const liveRegionId = useUniqueId("DndLiveRegion");
|
|
6996
|
+
const [mounted, setMounted] = useState(false);
|
|
6997
|
+
useEffect(() => {
|
|
6998
|
+
setMounted(true);
|
|
6999
|
+
}, []);
|
|
7000
|
+
useDndMonitor(useMemo(() => ({
|
|
7001
|
+
onDragStart(_ref2) {
|
|
7002
|
+
let {
|
|
7003
|
+
active
|
|
7004
|
+
} = _ref2;
|
|
7005
|
+
announce(announcements.onDragStart({
|
|
7006
|
+
active
|
|
7007
|
+
}));
|
|
7008
|
+
},
|
|
7009
|
+
|
|
7010
|
+
onDragMove(_ref3) {
|
|
7011
|
+
let {
|
|
7012
|
+
active,
|
|
7013
|
+
over
|
|
7014
|
+
} = _ref3;
|
|
7015
|
+
|
|
7016
|
+
if (announcements.onDragMove) {
|
|
7017
|
+
announce(announcements.onDragMove({
|
|
7018
|
+
active,
|
|
7019
|
+
over
|
|
7020
|
+
}));
|
|
7021
|
+
}
|
|
7022
|
+
},
|
|
7023
|
+
|
|
7024
|
+
onDragOver(_ref4) {
|
|
7025
|
+
let {
|
|
7026
|
+
active,
|
|
7027
|
+
over
|
|
7028
|
+
} = _ref4;
|
|
7029
|
+
announce(announcements.onDragOver({
|
|
7030
|
+
active,
|
|
7031
|
+
over
|
|
7032
|
+
}));
|
|
7033
|
+
},
|
|
7034
|
+
|
|
7035
|
+
onDragEnd(_ref5) {
|
|
7036
|
+
let {
|
|
7037
|
+
active,
|
|
7038
|
+
over
|
|
7039
|
+
} = _ref5;
|
|
7040
|
+
announce(announcements.onDragEnd({
|
|
7041
|
+
active,
|
|
7042
|
+
over
|
|
7043
|
+
}));
|
|
7044
|
+
},
|
|
7045
|
+
|
|
7046
|
+
onDragCancel(_ref6) {
|
|
7047
|
+
let {
|
|
7048
|
+
active,
|
|
7049
|
+
over
|
|
7050
|
+
} = _ref6;
|
|
7051
|
+
announce(announcements.onDragCancel({
|
|
7052
|
+
active,
|
|
7053
|
+
over
|
|
7054
|
+
}));
|
|
7055
|
+
}
|
|
7056
|
+
|
|
7057
|
+
}), [announce, announcements]));
|
|
7058
|
+
|
|
7059
|
+
if (!mounted) {
|
|
7060
|
+
return null;
|
|
7061
|
+
}
|
|
7062
|
+
|
|
7063
|
+
const markup = React.createElement(React.Fragment, null, React.createElement(HiddenText, {
|
|
7064
|
+
id: hiddenTextDescribedById,
|
|
7065
|
+
value: screenReaderInstructions.draggable
|
|
7066
|
+
}), React.createElement(LiveRegion, {
|
|
7067
|
+
id: liveRegionId,
|
|
7068
|
+
announcement: announcement
|
|
7069
|
+
}));
|
|
7070
|
+
return container ? createPortal(markup, container) : markup;
|
|
7071
|
+
}
|
|
7072
|
+
|
|
7073
|
+
var Action;
|
|
7074
|
+
|
|
7075
|
+
(function (Action) {
|
|
7076
|
+
Action["DragStart"] = "dragStart";
|
|
7077
|
+
Action["DragMove"] = "dragMove";
|
|
7078
|
+
Action["DragEnd"] = "dragEnd";
|
|
7079
|
+
Action["DragCancel"] = "dragCancel";
|
|
7080
|
+
Action["DragOver"] = "dragOver";
|
|
7081
|
+
Action["RegisterDroppable"] = "registerDroppable";
|
|
7082
|
+
Action["SetDroppableDisabled"] = "setDroppableDisabled";
|
|
7083
|
+
Action["UnregisterDroppable"] = "unregisterDroppable";
|
|
7084
|
+
})(Action || (Action = {}));
|
|
7085
|
+
|
|
7086
|
+
function noop() {}
|
|
7087
|
+
|
|
7088
|
+
const defaultCoordinates = /*#__PURE__*/Object.freeze({
|
|
7089
|
+
x: 0,
|
|
7090
|
+
y: 0
|
|
7091
|
+
});
|
|
7092
|
+
|
|
7093
|
+
/**
|
|
7094
|
+
* Returns the distance between two points
|
|
7095
|
+
*/
|
|
7096
|
+
function distanceBetween(p1, p2) {
|
|
7097
|
+
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
|
7098
|
+
}
|
|
7099
|
+
|
|
7100
|
+
/**
|
|
7101
|
+
* Sort collisions from smallest to greatest value
|
|
7102
|
+
*/
|
|
7103
|
+
function sortCollisionsAsc(_ref, _ref2) {
|
|
7104
|
+
let {
|
|
7105
|
+
data: {
|
|
7106
|
+
value: a
|
|
7107
|
+
}
|
|
7108
|
+
} = _ref;
|
|
7109
|
+
let {
|
|
7110
|
+
data: {
|
|
7111
|
+
value: b
|
|
7112
|
+
}
|
|
7113
|
+
} = _ref2;
|
|
7114
|
+
return a - b;
|
|
7115
|
+
}
|
|
7116
|
+
/**
|
|
7117
|
+
* Sort collisions from greatest to smallest value
|
|
7118
|
+
*/
|
|
7119
|
+
|
|
7120
|
+
function sortCollisionsDesc(_ref3, _ref4) {
|
|
7121
|
+
let {
|
|
7122
|
+
data: {
|
|
7123
|
+
value: a
|
|
7124
|
+
}
|
|
7125
|
+
} = _ref3;
|
|
7126
|
+
let {
|
|
7127
|
+
data: {
|
|
7128
|
+
value: b
|
|
7129
|
+
}
|
|
7130
|
+
} = _ref4;
|
|
7131
|
+
return b - a;
|
|
7132
|
+
}
|
|
7133
|
+
function getFirstCollision(collisions, property) {
|
|
7134
|
+
if (!collisions || collisions.length === 0) {
|
|
7135
|
+
return null;
|
|
7136
|
+
}
|
|
7137
|
+
|
|
7138
|
+
const [firstCollision] = collisions;
|
|
7139
|
+
return property ? firstCollision[property] : firstCollision;
|
|
7140
|
+
}
|
|
7141
|
+
|
|
7142
|
+
/**
|
|
7143
|
+
* Returns the coordinates of the center of a given ClientRect
|
|
7144
|
+
*/
|
|
7145
|
+
|
|
7146
|
+
function centerOfRectangle(rect, left, top) {
|
|
7147
|
+
if (left === void 0) {
|
|
7148
|
+
left = rect.left;
|
|
7149
|
+
}
|
|
7150
|
+
|
|
7151
|
+
if (top === void 0) {
|
|
7152
|
+
top = rect.top;
|
|
7153
|
+
}
|
|
7154
|
+
|
|
7155
|
+
return {
|
|
7156
|
+
x: left + rect.width * 0.5,
|
|
7157
|
+
y: top + rect.height * 0.5
|
|
7158
|
+
};
|
|
7159
|
+
}
|
|
7160
|
+
/**
|
|
7161
|
+
* Returns the closest rectangles from an array of rectangles to the center of a given
|
|
7162
|
+
* rectangle.
|
|
7163
|
+
*/
|
|
7164
|
+
|
|
7165
|
+
|
|
7166
|
+
const closestCenter = _ref => {
|
|
7167
|
+
let {
|
|
7168
|
+
collisionRect,
|
|
7169
|
+
droppableRects,
|
|
7170
|
+
droppableContainers
|
|
7171
|
+
} = _ref;
|
|
7172
|
+
const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
|
|
7173
|
+
const collisions = [];
|
|
7174
|
+
|
|
7175
|
+
for (const droppableContainer of droppableContainers) {
|
|
7176
|
+
const {
|
|
7177
|
+
id
|
|
7178
|
+
} = droppableContainer;
|
|
7179
|
+
const rect = droppableRects.get(id);
|
|
7180
|
+
|
|
7181
|
+
if (rect) {
|
|
7182
|
+
const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
|
|
7183
|
+
collisions.push({
|
|
7184
|
+
id,
|
|
7185
|
+
data: {
|
|
7186
|
+
droppableContainer,
|
|
7187
|
+
value: distBetween
|
|
7188
|
+
}
|
|
7189
|
+
});
|
|
7190
|
+
}
|
|
7191
|
+
}
|
|
7192
|
+
|
|
7193
|
+
return collisions.sort(sortCollisionsAsc);
|
|
7194
|
+
};
|
|
7195
|
+
|
|
7196
|
+
/**
|
|
7197
|
+
* Returns the intersecting rectangle area between two rectangles
|
|
7198
|
+
*/
|
|
7199
|
+
|
|
7200
|
+
function getIntersectionRatio(entry, target) {
|
|
7201
|
+
const top = Math.max(target.top, entry.top);
|
|
7202
|
+
const left = Math.max(target.left, entry.left);
|
|
7203
|
+
const right = Math.min(target.left + target.width, entry.left + entry.width);
|
|
7204
|
+
const bottom = Math.min(target.top + target.height, entry.top + entry.height);
|
|
7205
|
+
const width = right - left;
|
|
7206
|
+
const height = bottom - top;
|
|
7207
|
+
|
|
7208
|
+
if (left < right && top < bottom) {
|
|
7209
|
+
const targetArea = target.width * target.height;
|
|
7210
|
+
const entryArea = entry.width * entry.height;
|
|
7211
|
+
const intersectionArea = width * height;
|
|
7212
|
+
const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
|
|
7213
|
+
return Number(intersectionRatio.toFixed(4));
|
|
7214
|
+
} // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
|
|
7215
|
+
|
|
7216
|
+
|
|
7217
|
+
return 0;
|
|
7218
|
+
}
|
|
7219
|
+
/**
|
|
7220
|
+
* Returns the rectangles that has the greatest intersection area with a given
|
|
7221
|
+
* rectangle in an array of rectangles.
|
|
7222
|
+
*/
|
|
7223
|
+
|
|
7224
|
+
const rectIntersection = _ref => {
|
|
7225
|
+
let {
|
|
7226
|
+
collisionRect,
|
|
7227
|
+
droppableRects,
|
|
7228
|
+
droppableContainers
|
|
7229
|
+
} = _ref;
|
|
7230
|
+
const collisions = [];
|
|
7231
|
+
|
|
7232
|
+
for (const droppableContainer of droppableContainers) {
|
|
7233
|
+
const {
|
|
7234
|
+
id
|
|
7235
|
+
} = droppableContainer;
|
|
7236
|
+
const rect = droppableRects.get(id);
|
|
7237
|
+
|
|
7238
|
+
if (rect) {
|
|
7239
|
+
const intersectionRatio = getIntersectionRatio(rect, collisionRect);
|
|
7240
|
+
|
|
7241
|
+
if (intersectionRatio > 0) {
|
|
7242
|
+
collisions.push({
|
|
7243
|
+
id,
|
|
7244
|
+
data: {
|
|
7245
|
+
droppableContainer,
|
|
7246
|
+
value: intersectionRatio
|
|
7247
|
+
}
|
|
7248
|
+
});
|
|
7249
|
+
}
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7252
|
+
|
|
7253
|
+
return collisions.sort(sortCollisionsDesc);
|
|
7254
|
+
};
|
|
7255
|
+
|
|
7256
|
+
function adjustScale(transform, rect1, rect2) {
|
|
7257
|
+
return { ...transform,
|
|
7258
|
+
scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
|
|
7259
|
+
scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
|
|
7260
|
+
};
|
|
7261
|
+
}
|
|
7262
|
+
|
|
7263
|
+
function getRectDelta(rect1, rect2) {
|
|
7264
|
+
return rect1 && rect2 ? {
|
|
7265
|
+
x: rect1.left - rect2.left,
|
|
7266
|
+
y: rect1.top - rect2.top
|
|
7267
|
+
} : defaultCoordinates;
|
|
7268
|
+
}
|
|
7269
|
+
|
|
7270
|
+
function createRectAdjustmentFn(modifier) {
|
|
7271
|
+
return function adjustClientRect(rect) {
|
|
7272
|
+
for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
7273
|
+
adjustments[_key - 1] = arguments[_key];
|
|
7274
|
+
}
|
|
7275
|
+
|
|
7276
|
+
return adjustments.reduce((acc, adjustment) => ({ ...acc,
|
|
7277
|
+
top: acc.top + modifier * adjustment.y,
|
|
7278
|
+
bottom: acc.bottom + modifier * adjustment.y,
|
|
7279
|
+
left: acc.left + modifier * adjustment.x,
|
|
7280
|
+
right: acc.right + modifier * adjustment.x
|
|
7281
|
+
}), { ...rect
|
|
7282
|
+
});
|
|
7283
|
+
};
|
|
7284
|
+
}
|
|
7285
|
+
const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
|
|
7286
|
+
|
|
7287
|
+
function parseTransform(transform) {
|
|
7288
|
+
if (transform.startsWith('matrix3d(')) {
|
|
7289
|
+
const transformArray = transform.slice(9, -1).split(/, /);
|
|
7290
|
+
return {
|
|
7291
|
+
x: +transformArray[12],
|
|
7292
|
+
y: +transformArray[13],
|
|
7293
|
+
scaleX: +transformArray[0],
|
|
7294
|
+
scaleY: +transformArray[5]
|
|
7295
|
+
};
|
|
7296
|
+
} else if (transform.startsWith('matrix(')) {
|
|
7297
|
+
const transformArray = transform.slice(7, -1).split(/, /);
|
|
7298
|
+
return {
|
|
7299
|
+
x: +transformArray[4],
|
|
7300
|
+
y: +transformArray[5],
|
|
7301
|
+
scaleX: +transformArray[0],
|
|
7302
|
+
scaleY: +transformArray[3]
|
|
7303
|
+
};
|
|
7304
|
+
}
|
|
7305
|
+
|
|
7306
|
+
return null;
|
|
7307
|
+
}
|
|
7308
|
+
|
|
7309
|
+
function inverseTransform(rect, transform, transformOrigin) {
|
|
7310
|
+
const parsedTransform = parseTransform(transform);
|
|
7311
|
+
|
|
7312
|
+
if (!parsedTransform) {
|
|
7313
|
+
return rect;
|
|
7314
|
+
}
|
|
7315
|
+
|
|
7316
|
+
const {
|
|
7317
|
+
scaleX,
|
|
7318
|
+
scaleY,
|
|
7319
|
+
x: translateX,
|
|
7320
|
+
y: translateY
|
|
7321
|
+
} = parsedTransform;
|
|
7322
|
+
const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
|
|
7323
|
+
const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
|
|
7324
|
+
const w = scaleX ? rect.width / scaleX : rect.width;
|
|
7325
|
+
const h = scaleY ? rect.height / scaleY : rect.height;
|
|
7326
|
+
return {
|
|
7327
|
+
width: w,
|
|
7328
|
+
height: h,
|
|
7329
|
+
top: y,
|
|
7330
|
+
right: x + w,
|
|
7331
|
+
bottom: y + h,
|
|
7332
|
+
left: x
|
|
7333
|
+
};
|
|
7334
|
+
}
|
|
7335
|
+
|
|
7336
|
+
const defaultOptions = {
|
|
7337
|
+
ignoreTransform: false
|
|
7338
|
+
};
|
|
7339
|
+
/**
|
|
7340
|
+
* Returns the bounding client rect of an element relative to the viewport.
|
|
7341
|
+
*/
|
|
7342
|
+
|
|
7343
|
+
function getClientRect(element, options) {
|
|
7344
|
+
if (options === void 0) {
|
|
7345
|
+
options = defaultOptions;
|
|
7346
|
+
}
|
|
7347
|
+
|
|
7348
|
+
let rect = element.getBoundingClientRect();
|
|
7349
|
+
|
|
7350
|
+
if (options.ignoreTransform) {
|
|
7351
|
+
const {
|
|
7352
|
+
transform,
|
|
7353
|
+
transformOrigin
|
|
7354
|
+
} = getWindow(element).getComputedStyle(element);
|
|
7355
|
+
|
|
7356
|
+
if (transform) {
|
|
7357
|
+
rect = inverseTransform(rect, transform, transformOrigin);
|
|
7358
|
+
}
|
|
7359
|
+
}
|
|
7360
|
+
|
|
7361
|
+
const {
|
|
7362
|
+
top,
|
|
7363
|
+
left,
|
|
7364
|
+
width,
|
|
7365
|
+
height,
|
|
7366
|
+
bottom,
|
|
7367
|
+
right
|
|
7368
|
+
} = rect;
|
|
7369
|
+
return {
|
|
7370
|
+
top,
|
|
7371
|
+
left,
|
|
7372
|
+
width,
|
|
7373
|
+
height,
|
|
7374
|
+
bottom,
|
|
7375
|
+
right
|
|
7376
|
+
};
|
|
7377
|
+
}
|
|
7378
|
+
/**
|
|
7379
|
+
* Returns the bounding client rect of an element relative to the viewport.
|
|
7380
|
+
*
|
|
7381
|
+
* @remarks
|
|
7382
|
+
* The ClientRect returned by this method does not take into account transforms
|
|
7383
|
+
* applied to the element it measures.
|
|
7384
|
+
*
|
|
7385
|
+
*/
|
|
7386
|
+
|
|
7387
|
+
function getTransformAgnosticClientRect(element) {
|
|
7388
|
+
return getClientRect(element, {
|
|
7389
|
+
ignoreTransform: true
|
|
7390
|
+
});
|
|
7391
|
+
}
|
|
7392
|
+
|
|
7393
|
+
function getWindowClientRect(element) {
|
|
7394
|
+
const width = element.innerWidth;
|
|
7395
|
+
const height = element.innerHeight;
|
|
7396
|
+
return {
|
|
7397
|
+
top: 0,
|
|
7398
|
+
left: 0,
|
|
7399
|
+
right: width,
|
|
7400
|
+
bottom: height,
|
|
7401
|
+
width,
|
|
7402
|
+
height
|
|
7403
|
+
};
|
|
7404
|
+
}
|
|
7405
|
+
|
|
7406
|
+
function isFixed(node, computedStyle) {
|
|
7407
|
+
if (computedStyle === void 0) {
|
|
7408
|
+
computedStyle = getWindow(node).getComputedStyle(node);
|
|
7409
|
+
}
|
|
7410
|
+
|
|
7411
|
+
return computedStyle.position === 'fixed';
|
|
7412
|
+
}
|
|
7413
|
+
|
|
7414
|
+
function isScrollable(element, computedStyle) {
|
|
7415
|
+
if (computedStyle === void 0) {
|
|
7416
|
+
computedStyle = getWindow(element).getComputedStyle(element);
|
|
7417
|
+
}
|
|
7418
|
+
|
|
7419
|
+
const overflowRegex = /(auto|scroll|overlay)/;
|
|
7420
|
+
const properties = ['overflow', 'overflowX', 'overflowY'];
|
|
7421
|
+
return properties.some(property => {
|
|
7422
|
+
const value = computedStyle[property];
|
|
7423
|
+
return typeof value === 'string' ? overflowRegex.test(value) : false;
|
|
7424
|
+
});
|
|
7425
|
+
}
|
|
7426
|
+
|
|
7427
|
+
function getScrollableAncestors(element, limit) {
|
|
7428
|
+
const scrollParents = [];
|
|
7429
|
+
|
|
7430
|
+
function findScrollableAncestors(node) {
|
|
7431
|
+
if (limit != null && scrollParents.length >= limit) {
|
|
7432
|
+
return scrollParents;
|
|
7433
|
+
}
|
|
7434
|
+
|
|
7435
|
+
if (!node) {
|
|
7436
|
+
return scrollParents;
|
|
7437
|
+
}
|
|
7438
|
+
|
|
7439
|
+
if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
|
|
7440
|
+
scrollParents.push(node.scrollingElement);
|
|
7441
|
+
return scrollParents;
|
|
7442
|
+
}
|
|
7443
|
+
|
|
7444
|
+
if (!isHTMLElement(node) || isSVGElement(node)) {
|
|
7445
|
+
return scrollParents;
|
|
7446
|
+
}
|
|
7447
|
+
|
|
7448
|
+
if (scrollParents.includes(node)) {
|
|
7449
|
+
return scrollParents;
|
|
7450
|
+
}
|
|
7451
|
+
|
|
7452
|
+
const computedStyle = getWindow(element).getComputedStyle(node);
|
|
7453
|
+
|
|
7454
|
+
if (node !== element) {
|
|
7455
|
+
if (isScrollable(node, computedStyle)) {
|
|
7456
|
+
scrollParents.push(node);
|
|
7457
|
+
}
|
|
7458
|
+
}
|
|
7459
|
+
|
|
7460
|
+
if (isFixed(node, computedStyle)) {
|
|
7461
|
+
return scrollParents;
|
|
7462
|
+
}
|
|
7463
|
+
|
|
7464
|
+
return findScrollableAncestors(node.parentNode);
|
|
7465
|
+
}
|
|
7466
|
+
|
|
7467
|
+
if (!element) {
|
|
7468
|
+
return scrollParents;
|
|
7469
|
+
}
|
|
7470
|
+
|
|
7471
|
+
return findScrollableAncestors(element);
|
|
7472
|
+
}
|
|
7473
|
+
function getFirstScrollableAncestor(node) {
|
|
7474
|
+
const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
|
|
7475
|
+
return firstScrollableAncestor != null ? firstScrollableAncestor : null;
|
|
7476
|
+
}
|
|
7477
|
+
|
|
7478
|
+
function getScrollableElement(element) {
|
|
7479
|
+
if (!canUseDOM || !element) {
|
|
7480
|
+
return null;
|
|
7481
|
+
}
|
|
7482
|
+
|
|
7483
|
+
if (isWindow(element)) {
|
|
7484
|
+
return element;
|
|
7485
|
+
}
|
|
7486
|
+
|
|
7487
|
+
if (!isNode(element)) {
|
|
7488
|
+
return null;
|
|
7489
|
+
}
|
|
7490
|
+
|
|
7491
|
+
if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) {
|
|
7492
|
+
return window;
|
|
7493
|
+
}
|
|
7494
|
+
|
|
7495
|
+
if (isHTMLElement(element)) {
|
|
7496
|
+
return element;
|
|
7497
|
+
}
|
|
7498
|
+
|
|
7499
|
+
return null;
|
|
7500
|
+
}
|
|
7501
|
+
|
|
7502
|
+
function getScrollXCoordinate(element) {
|
|
7503
|
+
if (isWindow(element)) {
|
|
7504
|
+
return element.scrollX;
|
|
7505
|
+
}
|
|
7506
|
+
|
|
7507
|
+
return element.scrollLeft;
|
|
7508
|
+
}
|
|
7509
|
+
function getScrollYCoordinate(element) {
|
|
7510
|
+
if (isWindow(element)) {
|
|
7511
|
+
return element.scrollY;
|
|
7512
|
+
}
|
|
7513
|
+
|
|
7514
|
+
return element.scrollTop;
|
|
7515
|
+
}
|
|
7516
|
+
function getScrollCoordinates(element) {
|
|
7517
|
+
return {
|
|
7518
|
+
x: getScrollXCoordinate(element),
|
|
7519
|
+
y: getScrollYCoordinate(element)
|
|
7520
|
+
};
|
|
7521
|
+
}
|
|
7522
|
+
|
|
7523
|
+
var Direction;
|
|
7524
|
+
|
|
7525
|
+
(function (Direction) {
|
|
7526
|
+
Direction[Direction["Forward"] = 1] = "Forward";
|
|
7527
|
+
Direction[Direction["Backward"] = -1] = "Backward";
|
|
7528
|
+
})(Direction || (Direction = {}));
|
|
7529
|
+
|
|
7530
|
+
function isDocumentScrollingElement(element) {
|
|
7531
|
+
if (!canUseDOM || !element) {
|
|
7532
|
+
return false;
|
|
7533
|
+
}
|
|
7534
|
+
|
|
7535
|
+
return element === document.scrollingElement;
|
|
7536
|
+
}
|
|
7537
|
+
|
|
7538
|
+
function getScrollPosition(scrollingContainer) {
|
|
7539
|
+
const minScroll = {
|
|
7540
|
+
x: 0,
|
|
7541
|
+
y: 0
|
|
7542
|
+
};
|
|
7543
|
+
const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
|
|
7544
|
+
height: window.innerHeight,
|
|
7545
|
+
width: window.innerWidth
|
|
7546
|
+
} : {
|
|
7547
|
+
height: scrollingContainer.clientHeight,
|
|
7548
|
+
width: scrollingContainer.clientWidth
|
|
7549
|
+
};
|
|
7550
|
+
const maxScroll = {
|
|
7551
|
+
x: scrollingContainer.scrollWidth - dimensions.width,
|
|
7552
|
+
y: scrollingContainer.scrollHeight - dimensions.height
|
|
7553
|
+
};
|
|
7554
|
+
const isTop = scrollingContainer.scrollTop <= minScroll.y;
|
|
7555
|
+
const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
|
|
7556
|
+
const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
|
|
7557
|
+
const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
|
|
7558
|
+
return {
|
|
7559
|
+
isTop,
|
|
7560
|
+
isLeft,
|
|
7561
|
+
isBottom,
|
|
7562
|
+
isRight,
|
|
7563
|
+
maxScroll,
|
|
7564
|
+
minScroll
|
|
7565
|
+
};
|
|
7566
|
+
}
|
|
7567
|
+
|
|
7568
|
+
const defaultThreshold = {
|
|
7569
|
+
x: 0.2,
|
|
7570
|
+
y: 0.2
|
|
7571
|
+
};
|
|
7572
|
+
function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
|
|
7573
|
+
let {
|
|
7574
|
+
top,
|
|
7575
|
+
left,
|
|
7576
|
+
right,
|
|
7577
|
+
bottom
|
|
7578
|
+
} = _ref;
|
|
7579
|
+
|
|
7580
|
+
if (acceleration === void 0) {
|
|
7581
|
+
acceleration = 10;
|
|
7582
|
+
}
|
|
7583
|
+
|
|
7584
|
+
if (thresholdPercentage === void 0) {
|
|
7585
|
+
thresholdPercentage = defaultThreshold;
|
|
7586
|
+
}
|
|
7587
|
+
|
|
7588
|
+
const {
|
|
7589
|
+
isTop,
|
|
7590
|
+
isBottom,
|
|
7591
|
+
isLeft,
|
|
7592
|
+
isRight
|
|
7593
|
+
} = getScrollPosition(scrollContainer);
|
|
7594
|
+
const direction = {
|
|
7595
|
+
x: 0,
|
|
7596
|
+
y: 0
|
|
7597
|
+
};
|
|
7598
|
+
const speed = {
|
|
7599
|
+
x: 0,
|
|
7600
|
+
y: 0
|
|
7601
|
+
};
|
|
7602
|
+
const threshold = {
|
|
7603
|
+
height: scrollContainerRect.height * thresholdPercentage.y,
|
|
7604
|
+
width: scrollContainerRect.width * thresholdPercentage.x
|
|
7605
|
+
};
|
|
7606
|
+
|
|
7607
|
+
if (!isTop && top <= scrollContainerRect.top + threshold.height) {
|
|
7608
|
+
// Scroll Up
|
|
7609
|
+
direction.y = Direction.Backward;
|
|
7610
|
+
speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
|
|
7611
|
+
} else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
|
|
7612
|
+
// Scroll Down
|
|
7613
|
+
direction.y = Direction.Forward;
|
|
7614
|
+
speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
|
|
7615
|
+
}
|
|
7616
|
+
|
|
7617
|
+
if (!isRight && right >= scrollContainerRect.right - threshold.width) {
|
|
7618
|
+
// Scroll Right
|
|
7619
|
+
direction.x = Direction.Forward;
|
|
7620
|
+
speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
|
|
7621
|
+
} else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
|
|
7622
|
+
// Scroll Left
|
|
7623
|
+
direction.x = Direction.Backward;
|
|
7624
|
+
speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
|
|
7625
|
+
}
|
|
7626
|
+
|
|
7627
|
+
return {
|
|
7628
|
+
direction,
|
|
7629
|
+
speed
|
|
7630
|
+
};
|
|
7631
|
+
}
|
|
7632
|
+
|
|
7633
|
+
function getScrollElementRect(element) {
|
|
7634
|
+
if (element === document.scrollingElement) {
|
|
7635
|
+
const {
|
|
7636
|
+
innerWidth,
|
|
7637
|
+
innerHeight
|
|
7638
|
+
} = window;
|
|
7639
|
+
return {
|
|
7640
|
+
top: 0,
|
|
7641
|
+
left: 0,
|
|
7642
|
+
right: innerWidth,
|
|
7643
|
+
bottom: innerHeight,
|
|
7644
|
+
width: innerWidth,
|
|
7645
|
+
height: innerHeight
|
|
7646
|
+
};
|
|
7647
|
+
}
|
|
7648
|
+
|
|
7649
|
+
const {
|
|
7650
|
+
top,
|
|
7651
|
+
left,
|
|
7652
|
+
right,
|
|
7653
|
+
bottom
|
|
7654
|
+
} = element.getBoundingClientRect();
|
|
7655
|
+
return {
|
|
7656
|
+
top,
|
|
7657
|
+
left,
|
|
7658
|
+
right,
|
|
7659
|
+
bottom,
|
|
7660
|
+
width: element.clientWidth,
|
|
7661
|
+
height: element.clientHeight
|
|
7662
|
+
};
|
|
7663
|
+
}
|
|
7664
|
+
|
|
7665
|
+
function getScrollOffsets(scrollableAncestors) {
|
|
7666
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
7667
|
+
return add(acc, getScrollCoordinates(node));
|
|
7668
|
+
}, defaultCoordinates);
|
|
7669
|
+
}
|
|
7670
|
+
function getScrollXOffset(scrollableAncestors) {
|
|
7671
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
7672
|
+
return acc + getScrollXCoordinate(node);
|
|
7673
|
+
}, 0);
|
|
7674
|
+
}
|
|
7675
|
+
function getScrollYOffset(scrollableAncestors) {
|
|
7676
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
7677
|
+
return acc + getScrollYCoordinate(node);
|
|
7678
|
+
}, 0);
|
|
7679
|
+
}
|
|
7680
|
+
|
|
7681
|
+
function scrollIntoViewIfNeeded(element, measure) {
|
|
7682
|
+
if (measure === void 0) {
|
|
7683
|
+
measure = getClientRect;
|
|
7684
|
+
}
|
|
7685
|
+
|
|
7686
|
+
if (!element) {
|
|
7687
|
+
return;
|
|
7688
|
+
}
|
|
7689
|
+
|
|
7690
|
+
const {
|
|
7691
|
+
top,
|
|
7692
|
+
left,
|
|
7693
|
+
bottom,
|
|
7694
|
+
right
|
|
7695
|
+
} = measure(element);
|
|
7696
|
+
const firstScrollableAncestor = getFirstScrollableAncestor(element);
|
|
7697
|
+
|
|
7698
|
+
if (!firstScrollableAncestor) {
|
|
7699
|
+
return;
|
|
7700
|
+
}
|
|
7701
|
+
|
|
7702
|
+
if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
|
|
7703
|
+
element.scrollIntoView({
|
|
7704
|
+
block: 'center',
|
|
7705
|
+
inline: 'center'
|
|
7706
|
+
});
|
|
7707
|
+
}
|
|
7708
|
+
}
|
|
7709
|
+
|
|
7710
|
+
const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
|
|
7711
|
+
class Rect {
|
|
7712
|
+
constructor(rect, element) {
|
|
7713
|
+
this.rect = void 0;
|
|
7714
|
+
this.width = void 0;
|
|
7715
|
+
this.height = void 0;
|
|
7716
|
+
this.top = void 0;
|
|
7717
|
+
this.bottom = void 0;
|
|
7718
|
+
this.right = void 0;
|
|
7719
|
+
this.left = void 0;
|
|
7720
|
+
const scrollableAncestors = getScrollableAncestors(element);
|
|
7721
|
+
const scrollOffsets = getScrollOffsets(scrollableAncestors);
|
|
7722
|
+
this.rect = { ...rect
|
|
7723
|
+
};
|
|
7724
|
+
this.width = rect.width;
|
|
7725
|
+
this.height = rect.height;
|
|
7726
|
+
|
|
7727
|
+
for (const [axis, keys, getScrollOffset] of properties) {
|
|
7728
|
+
for (const key of keys) {
|
|
7729
|
+
Object.defineProperty(this, key, {
|
|
7730
|
+
get: () => {
|
|
7731
|
+
const currentOffsets = getScrollOffset(scrollableAncestors);
|
|
7732
|
+
const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
|
|
7733
|
+
return this.rect[key] + scrollOffsetsDeltla;
|
|
7734
|
+
},
|
|
7735
|
+
enumerable: true
|
|
7736
|
+
});
|
|
7737
|
+
}
|
|
7738
|
+
}
|
|
7739
|
+
|
|
7740
|
+
Object.defineProperty(this, 'rect', {
|
|
7741
|
+
enumerable: false
|
|
7742
|
+
});
|
|
7743
|
+
}
|
|
7744
|
+
|
|
7745
|
+
}
|
|
7746
|
+
|
|
7747
|
+
class Listeners {
|
|
7748
|
+
constructor(target) {
|
|
7749
|
+
this.target = void 0;
|
|
7750
|
+
this.listeners = [];
|
|
7751
|
+
|
|
7752
|
+
this.removeAll = () => {
|
|
7753
|
+
this.listeners.forEach(listener => {
|
|
7754
|
+
var _this$target;
|
|
7755
|
+
|
|
7756
|
+
return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
|
|
7757
|
+
});
|
|
7758
|
+
};
|
|
7759
|
+
|
|
7760
|
+
this.target = target;
|
|
7761
|
+
}
|
|
7762
|
+
|
|
7763
|
+
add(eventName, handler, options) {
|
|
7764
|
+
var _this$target2;
|
|
7765
|
+
|
|
7766
|
+
(_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
|
|
7767
|
+
this.listeners.push([eventName, handler, options]);
|
|
7768
|
+
}
|
|
7769
|
+
|
|
7770
|
+
}
|
|
7771
|
+
|
|
7772
|
+
function getEventListenerTarget(target) {
|
|
7773
|
+
// If the `event.target` element is removed from the document events will still be targeted
|
|
7774
|
+
// at it, and hence won't always bubble up to the window or document anymore.
|
|
7775
|
+
// If there is any risk of an element being removed while it is being dragged,
|
|
7776
|
+
// the best practice is to attach the event listeners directly to the target.
|
|
7777
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
7778
|
+
const {
|
|
7779
|
+
EventTarget
|
|
7780
|
+
} = getWindow(target);
|
|
7781
|
+
return target instanceof EventTarget ? target : getOwnerDocument(target);
|
|
7782
|
+
}
|
|
7783
|
+
|
|
7784
|
+
function hasExceededDistance(delta, measurement) {
|
|
7785
|
+
const dx = Math.abs(delta.x);
|
|
7786
|
+
const dy = Math.abs(delta.y);
|
|
7787
|
+
|
|
7788
|
+
if (typeof measurement === 'number') {
|
|
7789
|
+
return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
|
|
7790
|
+
}
|
|
7791
|
+
|
|
7792
|
+
if ('x' in measurement && 'y' in measurement) {
|
|
7793
|
+
return dx > measurement.x && dy > measurement.y;
|
|
7794
|
+
}
|
|
7795
|
+
|
|
7796
|
+
if ('x' in measurement) {
|
|
7797
|
+
return dx > measurement.x;
|
|
7798
|
+
}
|
|
7799
|
+
|
|
7800
|
+
if ('y' in measurement) {
|
|
7801
|
+
return dy > measurement.y;
|
|
7802
|
+
}
|
|
7803
|
+
|
|
7804
|
+
return false;
|
|
7805
|
+
}
|
|
7806
|
+
|
|
7807
|
+
var EventName;
|
|
7808
|
+
|
|
7809
|
+
(function (EventName) {
|
|
7810
|
+
EventName["Click"] = "click";
|
|
7811
|
+
EventName["DragStart"] = "dragstart";
|
|
7812
|
+
EventName["Keydown"] = "keydown";
|
|
7813
|
+
EventName["ContextMenu"] = "contextmenu";
|
|
7814
|
+
EventName["Resize"] = "resize";
|
|
7815
|
+
EventName["SelectionChange"] = "selectionchange";
|
|
7816
|
+
EventName["VisibilityChange"] = "visibilitychange";
|
|
7817
|
+
})(EventName || (EventName = {}));
|
|
7818
|
+
|
|
7819
|
+
function preventDefault(event) {
|
|
7820
|
+
event.preventDefault();
|
|
7821
|
+
}
|
|
7822
|
+
function stopPropagation(event) {
|
|
7823
|
+
event.stopPropagation();
|
|
7824
|
+
}
|
|
7825
|
+
|
|
7826
|
+
var KeyboardCode;
|
|
7827
|
+
|
|
7828
|
+
(function (KeyboardCode) {
|
|
7829
|
+
KeyboardCode["Space"] = "Space";
|
|
7830
|
+
KeyboardCode["Down"] = "ArrowDown";
|
|
7831
|
+
KeyboardCode["Right"] = "ArrowRight";
|
|
7832
|
+
KeyboardCode["Left"] = "ArrowLeft";
|
|
7833
|
+
KeyboardCode["Up"] = "ArrowUp";
|
|
7834
|
+
KeyboardCode["Esc"] = "Escape";
|
|
7835
|
+
KeyboardCode["Enter"] = "Enter";
|
|
7836
|
+
})(KeyboardCode || (KeyboardCode = {}));
|
|
7837
|
+
|
|
7838
|
+
const defaultKeyboardCodes = {
|
|
7839
|
+
start: [KeyboardCode.Space, KeyboardCode.Enter],
|
|
7840
|
+
cancel: [KeyboardCode.Esc],
|
|
7841
|
+
end: [KeyboardCode.Space, KeyboardCode.Enter]
|
|
7842
|
+
};
|
|
7843
|
+
const defaultKeyboardCoordinateGetter = (event, _ref) => {
|
|
7844
|
+
let {
|
|
7845
|
+
currentCoordinates
|
|
7846
|
+
} = _ref;
|
|
7847
|
+
|
|
7848
|
+
switch (event.code) {
|
|
7849
|
+
case KeyboardCode.Right:
|
|
7850
|
+
return { ...currentCoordinates,
|
|
7851
|
+
x: currentCoordinates.x + 25
|
|
7852
|
+
};
|
|
7853
|
+
|
|
7854
|
+
case KeyboardCode.Left:
|
|
7855
|
+
return { ...currentCoordinates,
|
|
7856
|
+
x: currentCoordinates.x - 25
|
|
7857
|
+
};
|
|
7858
|
+
|
|
7859
|
+
case KeyboardCode.Down:
|
|
7860
|
+
return { ...currentCoordinates,
|
|
7861
|
+
y: currentCoordinates.y + 25
|
|
7862
|
+
};
|
|
7863
|
+
|
|
7864
|
+
case KeyboardCode.Up:
|
|
7865
|
+
return { ...currentCoordinates,
|
|
7866
|
+
y: currentCoordinates.y - 25
|
|
7867
|
+
};
|
|
7868
|
+
}
|
|
7869
|
+
|
|
7870
|
+
return undefined;
|
|
7871
|
+
};
|
|
7872
|
+
|
|
7873
|
+
class KeyboardSensor {
|
|
7874
|
+
constructor(props) {
|
|
7875
|
+
this.props = void 0;
|
|
7876
|
+
this.autoScrollEnabled = false;
|
|
7877
|
+
this.referenceCoordinates = void 0;
|
|
7878
|
+
this.listeners = void 0;
|
|
7879
|
+
this.windowListeners = void 0;
|
|
7880
|
+
this.props = props;
|
|
7881
|
+
const {
|
|
7882
|
+
event: {
|
|
7883
|
+
target
|
|
7884
|
+
}
|
|
7885
|
+
} = props;
|
|
7886
|
+
this.props = props;
|
|
7887
|
+
this.listeners = new Listeners(getOwnerDocument(target));
|
|
7888
|
+
this.windowListeners = new Listeners(getWindow(target));
|
|
7889
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
7890
|
+
this.handleCancel = this.handleCancel.bind(this);
|
|
7891
|
+
this.attach();
|
|
7892
|
+
}
|
|
7893
|
+
|
|
7894
|
+
attach() {
|
|
7895
|
+
this.handleStart();
|
|
7896
|
+
this.windowListeners.add(EventName.Resize, this.handleCancel);
|
|
7897
|
+
this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
|
|
7898
|
+
setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
|
|
7899
|
+
}
|
|
7900
|
+
|
|
7901
|
+
handleStart() {
|
|
7902
|
+
const {
|
|
7903
|
+
activeNode,
|
|
7904
|
+
onStart
|
|
7905
|
+
} = this.props;
|
|
7906
|
+
const node = activeNode.node.current;
|
|
7907
|
+
|
|
7908
|
+
if (node) {
|
|
7909
|
+
scrollIntoViewIfNeeded(node);
|
|
7910
|
+
}
|
|
7911
|
+
|
|
7912
|
+
onStart(defaultCoordinates);
|
|
7913
|
+
}
|
|
7914
|
+
|
|
7915
|
+
handleKeyDown(event) {
|
|
7916
|
+
if (isKeyboardEvent(event)) {
|
|
7917
|
+
const {
|
|
7918
|
+
active,
|
|
7919
|
+
context,
|
|
7920
|
+
options
|
|
7921
|
+
} = this.props;
|
|
7922
|
+
const {
|
|
7923
|
+
keyboardCodes = defaultKeyboardCodes,
|
|
7924
|
+
coordinateGetter = defaultKeyboardCoordinateGetter,
|
|
7925
|
+
scrollBehavior = 'smooth'
|
|
7926
|
+
} = options;
|
|
7927
|
+
const {
|
|
7928
|
+
code
|
|
7929
|
+
} = event;
|
|
7930
|
+
|
|
7931
|
+
if (keyboardCodes.end.includes(code)) {
|
|
7932
|
+
this.handleEnd(event);
|
|
7933
|
+
return;
|
|
7934
|
+
}
|
|
7935
|
+
|
|
7936
|
+
if (keyboardCodes.cancel.includes(code)) {
|
|
7937
|
+
this.handleCancel(event);
|
|
7938
|
+
return;
|
|
7939
|
+
}
|
|
7940
|
+
|
|
7941
|
+
const {
|
|
7942
|
+
collisionRect
|
|
7943
|
+
} = context.current;
|
|
7944
|
+
const currentCoordinates = collisionRect ? {
|
|
7945
|
+
x: collisionRect.left,
|
|
7946
|
+
y: collisionRect.top
|
|
7947
|
+
} : defaultCoordinates;
|
|
7948
|
+
|
|
7949
|
+
if (!this.referenceCoordinates) {
|
|
7950
|
+
this.referenceCoordinates = currentCoordinates;
|
|
7951
|
+
}
|
|
7952
|
+
|
|
7953
|
+
const newCoordinates = coordinateGetter(event, {
|
|
7954
|
+
active,
|
|
7955
|
+
context: context.current,
|
|
7956
|
+
currentCoordinates
|
|
7957
|
+
});
|
|
7958
|
+
|
|
7959
|
+
if (newCoordinates) {
|
|
7960
|
+
const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
|
|
7961
|
+
const scrollDelta = {
|
|
7962
|
+
x: 0,
|
|
7963
|
+
y: 0
|
|
7964
|
+
};
|
|
7965
|
+
const {
|
|
7966
|
+
scrollableAncestors
|
|
7967
|
+
} = context.current;
|
|
7968
|
+
|
|
7969
|
+
for (const scrollContainer of scrollableAncestors) {
|
|
7970
|
+
const direction = event.code;
|
|
7971
|
+
const {
|
|
7972
|
+
isTop,
|
|
7973
|
+
isRight,
|
|
7974
|
+
isLeft,
|
|
7975
|
+
isBottom,
|
|
7976
|
+
maxScroll,
|
|
7977
|
+
minScroll
|
|
7978
|
+
} = getScrollPosition(scrollContainer);
|
|
7979
|
+
const scrollElementRect = getScrollElementRect(scrollContainer);
|
|
7980
|
+
const clampedCoordinates = {
|
|
7981
|
+
x: Math.min(direction === KeyboardCode.Right ? scrollElementRect.right - scrollElementRect.width / 2 : scrollElementRect.right, Math.max(direction === KeyboardCode.Right ? scrollElementRect.left : scrollElementRect.left + scrollElementRect.width / 2, newCoordinates.x)),
|
|
7982
|
+
y: Math.min(direction === KeyboardCode.Down ? scrollElementRect.bottom - scrollElementRect.height / 2 : scrollElementRect.bottom, Math.max(direction === KeyboardCode.Down ? scrollElementRect.top : scrollElementRect.top + scrollElementRect.height / 2, newCoordinates.y))
|
|
7983
|
+
};
|
|
7984
|
+
const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
|
|
7985
|
+
const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
|
|
7986
|
+
|
|
7987
|
+
if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
|
|
7988
|
+
const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
|
|
7989
|
+
const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
|
|
7990
|
+
|
|
7991
|
+
if (canScrollToNewCoordinates && !coordinatesDelta.y) {
|
|
7992
|
+
// We don't need to update coordinates, the scroll adjustment alone will trigger
|
|
7993
|
+
// logic to auto-detect the new container we are over
|
|
7994
|
+
scrollContainer.scrollTo({
|
|
7995
|
+
left: newScrollCoordinates,
|
|
7996
|
+
behavior: scrollBehavior
|
|
7997
|
+
});
|
|
7998
|
+
return;
|
|
7999
|
+
}
|
|
8000
|
+
|
|
8001
|
+
if (canScrollToNewCoordinates) {
|
|
8002
|
+
scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
|
|
8003
|
+
} else {
|
|
8004
|
+
scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
|
|
8005
|
+
}
|
|
8006
|
+
|
|
8007
|
+
if (scrollDelta.x) {
|
|
8008
|
+
scrollContainer.scrollBy({
|
|
8009
|
+
left: -scrollDelta.x,
|
|
8010
|
+
behavior: scrollBehavior
|
|
8011
|
+
});
|
|
8012
|
+
}
|
|
8013
|
+
|
|
8014
|
+
break;
|
|
8015
|
+
} else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
|
|
8016
|
+
const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
|
|
8017
|
+
const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
|
|
8018
|
+
|
|
8019
|
+
if (canScrollToNewCoordinates && !coordinatesDelta.x) {
|
|
8020
|
+
// We don't need to update coordinates, the scroll adjustment alone will trigger
|
|
8021
|
+
// logic to auto-detect the new container we are over
|
|
8022
|
+
scrollContainer.scrollTo({
|
|
8023
|
+
top: newScrollCoordinates,
|
|
8024
|
+
behavior: scrollBehavior
|
|
8025
|
+
});
|
|
8026
|
+
return;
|
|
8027
|
+
}
|
|
8028
|
+
|
|
8029
|
+
if (canScrollToNewCoordinates) {
|
|
8030
|
+
scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
|
|
8031
|
+
} else {
|
|
8032
|
+
scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
|
|
8033
|
+
}
|
|
8034
|
+
|
|
8035
|
+
if (scrollDelta.y) {
|
|
8036
|
+
scrollContainer.scrollBy({
|
|
8037
|
+
top: -scrollDelta.y,
|
|
8038
|
+
behavior: scrollBehavior
|
|
8039
|
+
});
|
|
8040
|
+
}
|
|
8041
|
+
|
|
8042
|
+
break;
|
|
8043
|
+
}
|
|
8044
|
+
}
|
|
8045
|
+
|
|
8046
|
+
this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
|
|
8047
|
+
}
|
|
8048
|
+
}
|
|
8049
|
+
}
|
|
8050
|
+
|
|
8051
|
+
handleMove(event, coordinates) {
|
|
8052
|
+
const {
|
|
8053
|
+
onMove
|
|
8054
|
+
} = this.props;
|
|
8055
|
+
event.preventDefault();
|
|
8056
|
+
onMove(coordinates);
|
|
8057
|
+
}
|
|
8058
|
+
|
|
8059
|
+
handleEnd(event) {
|
|
8060
|
+
const {
|
|
8061
|
+
onEnd
|
|
8062
|
+
} = this.props;
|
|
8063
|
+
event.preventDefault();
|
|
8064
|
+
this.detach();
|
|
8065
|
+
onEnd();
|
|
8066
|
+
}
|
|
8067
|
+
|
|
8068
|
+
handleCancel(event) {
|
|
8069
|
+
const {
|
|
8070
|
+
onCancel
|
|
8071
|
+
} = this.props;
|
|
8072
|
+
event.preventDefault();
|
|
8073
|
+
this.detach();
|
|
8074
|
+
onCancel();
|
|
8075
|
+
}
|
|
8076
|
+
|
|
8077
|
+
detach() {
|
|
8078
|
+
this.listeners.removeAll();
|
|
8079
|
+
this.windowListeners.removeAll();
|
|
8080
|
+
}
|
|
8081
|
+
|
|
8082
|
+
}
|
|
8083
|
+
KeyboardSensor.activators = [{
|
|
8084
|
+
eventName: 'onKeyDown',
|
|
8085
|
+
handler: (event, _ref, _ref2) => {
|
|
8086
|
+
let {
|
|
8087
|
+
keyboardCodes = defaultKeyboardCodes,
|
|
8088
|
+
onActivation
|
|
8089
|
+
} = _ref;
|
|
8090
|
+
let {
|
|
8091
|
+
active
|
|
8092
|
+
} = _ref2;
|
|
8093
|
+
const {
|
|
8094
|
+
code
|
|
8095
|
+
} = event.nativeEvent;
|
|
8096
|
+
|
|
8097
|
+
if (keyboardCodes.start.includes(code)) {
|
|
8098
|
+
const activator = active.activatorNode.current;
|
|
8099
|
+
|
|
8100
|
+
if (activator && event.target !== activator) {
|
|
8101
|
+
return false;
|
|
8102
|
+
}
|
|
8103
|
+
|
|
8104
|
+
event.preventDefault();
|
|
8105
|
+
onActivation == null ? void 0 : onActivation({
|
|
8106
|
+
event: event.nativeEvent
|
|
8107
|
+
});
|
|
8108
|
+
return true;
|
|
8109
|
+
}
|
|
8110
|
+
|
|
8111
|
+
return false;
|
|
8112
|
+
}
|
|
8113
|
+
}];
|
|
8114
|
+
|
|
8115
|
+
function isDistanceConstraint(constraint) {
|
|
8116
|
+
return Boolean(constraint && 'distance' in constraint);
|
|
8117
|
+
}
|
|
8118
|
+
|
|
8119
|
+
function isDelayConstraint(constraint) {
|
|
8120
|
+
return Boolean(constraint && 'delay' in constraint);
|
|
8121
|
+
}
|
|
8122
|
+
|
|
8123
|
+
class AbstractPointerSensor {
|
|
8124
|
+
constructor(props, events, listenerTarget) {
|
|
8125
|
+
var _getEventCoordinates;
|
|
8126
|
+
|
|
8127
|
+
if (listenerTarget === void 0) {
|
|
8128
|
+
listenerTarget = getEventListenerTarget(props.event.target);
|
|
8129
|
+
}
|
|
8130
|
+
|
|
8131
|
+
this.props = void 0;
|
|
8132
|
+
this.events = void 0;
|
|
8133
|
+
this.autoScrollEnabled = true;
|
|
8134
|
+
this.document = void 0;
|
|
8135
|
+
this.activated = false;
|
|
8136
|
+
this.initialCoordinates = void 0;
|
|
8137
|
+
this.timeoutId = null;
|
|
8138
|
+
this.listeners = void 0;
|
|
8139
|
+
this.documentListeners = void 0;
|
|
8140
|
+
this.windowListeners = void 0;
|
|
8141
|
+
this.props = props;
|
|
8142
|
+
this.events = events;
|
|
8143
|
+
const {
|
|
8144
|
+
event
|
|
8145
|
+
} = props;
|
|
8146
|
+
const {
|
|
8147
|
+
target
|
|
8148
|
+
} = event;
|
|
8149
|
+
this.props = props;
|
|
8150
|
+
this.events = events;
|
|
8151
|
+
this.document = getOwnerDocument(target);
|
|
8152
|
+
this.documentListeners = new Listeners(this.document);
|
|
8153
|
+
this.listeners = new Listeners(listenerTarget);
|
|
8154
|
+
this.windowListeners = new Listeners(getWindow(target));
|
|
8155
|
+
this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
|
|
8156
|
+
this.handleStart = this.handleStart.bind(this);
|
|
8157
|
+
this.handleMove = this.handleMove.bind(this);
|
|
8158
|
+
this.handleEnd = this.handleEnd.bind(this);
|
|
8159
|
+
this.handleCancel = this.handleCancel.bind(this);
|
|
8160
|
+
this.handleKeydown = this.handleKeydown.bind(this);
|
|
8161
|
+
this.removeTextSelection = this.removeTextSelection.bind(this);
|
|
8162
|
+
this.attach();
|
|
8163
|
+
}
|
|
8164
|
+
|
|
8165
|
+
attach() {
|
|
8166
|
+
const {
|
|
8167
|
+
events,
|
|
8168
|
+
props: {
|
|
8169
|
+
options: {
|
|
8170
|
+
activationConstraint
|
|
8171
|
+
}
|
|
8172
|
+
}
|
|
8173
|
+
} = this;
|
|
8174
|
+
this.listeners.add(events.move.name, this.handleMove, {
|
|
8175
|
+
passive: false
|
|
8176
|
+
});
|
|
8177
|
+
this.listeners.add(events.end.name, this.handleEnd);
|
|
8178
|
+
this.windowListeners.add(EventName.Resize, this.handleCancel);
|
|
8179
|
+
this.windowListeners.add(EventName.DragStart, preventDefault);
|
|
8180
|
+
this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
|
|
8181
|
+
this.windowListeners.add(EventName.ContextMenu, preventDefault);
|
|
8182
|
+
this.documentListeners.add(EventName.Keydown, this.handleKeydown);
|
|
8183
|
+
|
|
8184
|
+
if (activationConstraint) {
|
|
8185
|
+
if (isDistanceConstraint(activationConstraint)) {
|
|
8186
|
+
return;
|
|
8187
|
+
}
|
|
8188
|
+
|
|
8189
|
+
if (isDelayConstraint(activationConstraint)) {
|
|
8190
|
+
this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
|
|
8191
|
+
return;
|
|
8192
|
+
}
|
|
8193
|
+
}
|
|
8194
|
+
|
|
8195
|
+
this.handleStart();
|
|
8196
|
+
}
|
|
8197
|
+
|
|
8198
|
+
detach() {
|
|
8199
|
+
this.listeners.removeAll();
|
|
8200
|
+
this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
|
|
8201
|
+
// This is necessary because we listen for `click` and `selection` events on the document
|
|
8202
|
+
|
|
8203
|
+
setTimeout(this.documentListeners.removeAll, 50);
|
|
8204
|
+
|
|
8205
|
+
if (this.timeoutId !== null) {
|
|
8206
|
+
clearTimeout(this.timeoutId);
|
|
8207
|
+
this.timeoutId = null;
|
|
8208
|
+
}
|
|
8209
|
+
}
|
|
8210
|
+
|
|
8211
|
+
handleStart() {
|
|
8212
|
+
const {
|
|
8213
|
+
initialCoordinates
|
|
8214
|
+
} = this;
|
|
8215
|
+
const {
|
|
8216
|
+
onStart
|
|
8217
|
+
} = this.props;
|
|
8218
|
+
|
|
8219
|
+
if (initialCoordinates) {
|
|
8220
|
+
this.activated = true; // Stop propagation of click events once activation constraints are met
|
|
8221
|
+
|
|
8222
|
+
this.documentListeners.add(EventName.Click, stopPropagation, {
|
|
8223
|
+
capture: true
|
|
8224
|
+
}); // Remove any text selection from the document
|
|
8225
|
+
|
|
8226
|
+
this.removeTextSelection(); // Prevent further text selection while dragging
|
|
8227
|
+
|
|
8228
|
+
this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
|
|
8229
|
+
onStart(initialCoordinates);
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
|
|
8233
|
+
handleMove(event) {
|
|
8234
|
+
var _getEventCoordinates2;
|
|
8235
|
+
|
|
8236
|
+
const {
|
|
8237
|
+
activated,
|
|
8238
|
+
initialCoordinates,
|
|
8239
|
+
props
|
|
8240
|
+
} = this;
|
|
8241
|
+
const {
|
|
8242
|
+
onMove,
|
|
8243
|
+
options: {
|
|
8244
|
+
activationConstraint
|
|
8245
|
+
}
|
|
8246
|
+
} = props;
|
|
8247
|
+
|
|
8248
|
+
if (!initialCoordinates) {
|
|
8249
|
+
return;
|
|
8250
|
+
}
|
|
8251
|
+
|
|
8252
|
+
const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
|
|
8253
|
+
const delta = subtract(initialCoordinates, coordinates);
|
|
8254
|
+
|
|
8255
|
+
if (!activated && activationConstraint) {
|
|
8256
|
+
// Constraint validation
|
|
8257
|
+
if (isDelayConstraint(activationConstraint)) {
|
|
8258
|
+
if (hasExceededDistance(delta, activationConstraint.tolerance)) {
|
|
8259
|
+
return this.handleCancel();
|
|
8260
|
+
}
|
|
8261
|
+
|
|
8262
|
+
return;
|
|
8263
|
+
}
|
|
8264
|
+
|
|
8265
|
+
if (isDistanceConstraint(activationConstraint)) {
|
|
8266
|
+
if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
|
|
8267
|
+
return this.handleCancel();
|
|
8268
|
+
}
|
|
8269
|
+
|
|
8270
|
+
if (hasExceededDistance(delta, activationConstraint.distance)) {
|
|
8271
|
+
return this.handleStart();
|
|
8272
|
+
}
|
|
8273
|
+
|
|
8274
|
+
return;
|
|
8275
|
+
}
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8278
|
+
if (event.cancelable) {
|
|
8279
|
+
event.preventDefault();
|
|
8280
|
+
}
|
|
8281
|
+
|
|
8282
|
+
onMove(coordinates);
|
|
8283
|
+
}
|
|
8284
|
+
|
|
8285
|
+
handleEnd() {
|
|
8286
|
+
const {
|
|
8287
|
+
onEnd
|
|
8288
|
+
} = this.props;
|
|
8289
|
+
this.detach();
|
|
8290
|
+
onEnd();
|
|
8291
|
+
}
|
|
8292
|
+
|
|
8293
|
+
handleCancel() {
|
|
8294
|
+
const {
|
|
8295
|
+
onCancel
|
|
8296
|
+
} = this.props;
|
|
8297
|
+
this.detach();
|
|
8298
|
+
onCancel();
|
|
8299
|
+
}
|
|
8300
|
+
|
|
8301
|
+
handleKeydown(event) {
|
|
8302
|
+
if (event.code === KeyboardCode.Esc) {
|
|
8303
|
+
this.handleCancel();
|
|
8304
|
+
}
|
|
8305
|
+
}
|
|
8306
|
+
|
|
8307
|
+
removeTextSelection() {
|
|
8308
|
+
var _this$document$getSel;
|
|
8309
|
+
|
|
8310
|
+
(_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
}
|
|
8314
|
+
|
|
8315
|
+
const events = {
|
|
8316
|
+
move: {
|
|
8317
|
+
name: 'pointermove'
|
|
8318
|
+
},
|
|
8319
|
+
end: {
|
|
8320
|
+
name: 'pointerup'
|
|
8321
|
+
}
|
|
8322
|
+
};
|
|
8323
|
+
class PointerSensor extends AbstractPointerSensor {
|
|
8324
|
+
constructor(props) {
|
|
8325
|
+
const {
|
|
8326
|
+
event
|
|
8327
|
+
} = props; // Pointer events stop firing if the target is unmounted while dragging
|
|
8328
|
+
// Therefore we attach listeners to the owner document instead
|
|
8329
|
+
|
|
8330
|
+
const listenerTarget = getOwnerDocument(event.target);
|
|
8331
|
+
super(props, events, listenerTarget);
|
|
8332
|
+
}
|
|
8333
|
+
|
|
8334
|
+
}
|
|
8335
|
+
PointerSensor.activators = [{
|
|
8336
|
+
eventName: 'onPointerDown',
|
|
8337
|
+
handler: (_ref, _ref2) => {
|
|
8338
|
+
let {
|
|
8339
|
+
nativeEvent: event
|
|
8340
|
+
} = _ref;
|
|
8341
|
+
let {
|
|
8342
|
+
onActivation
|
|
8343
|
+
} = _ref2;
|
|
8344
|
+
|
|
8345
|
+
if (!event.isPrimary || event.button !== 0) {
|
|
8346
|
+
return false;
|
|
8347
|
+
}
|
|
8348
|
+
|
|
8349
|
+
onActivation == null ? void 0 : onActivation({
|
|
8350
|
+
event
|
|
8351
|
+
});
|
|
8352
|
+
return true;
|
|
8353
|
+
}
|
|
8354
|
+
}];
|
|
8355
|
+
|
|
8356
|
+
const events$1 = {
|
|
8357
|
+
move: {
|
|
8358
|
+
name: 'mousemove'
|
|
8359
|
+
},
|
|
8360
|
+
end: {
|
|
8361
|
+
name: 'mouseup'
|
|
8362
|
+
}
|
|
8363
|
+
};
|
|
8364
|
+
var MouseButton;
|
|
8365
|
+
|
|
8366
|
+
(function (MouseButton) {
|
|
8367
|
+
MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
|
|
8368
|
+
})(MouseButton || (MouseButton = {}));
|
|
8369
|
+
|
|
8370
|
+
class MouseSensor extends AbstractPointerSensor {
|
|
8371
|
+
constructor(props) {
|
|
8372
|
+
super(props, events$1, getOwnerDocument(props.event.target));
|
|
8373
|
+
}
|
|
8374
|
+
|
|
8375
|
+
}
|
|
8376
|
+
MouseSensor.activators = [{
|
|
8377
|
+
eventName: 'onMouseDown',
|
|
8378
|
+
handler: (_ref, _ref2) => {
|
|
8379
|
+
let {
|
|
8380
|
+
nativeEvent: event
|
|
8381
|
+
} = _ref;
|
|
8382
|
+
let {
|
|
8383
|
+
onActivation
|
|
8384
|
+
} = _ref2;
|
|
8385
|
+
|
|
8386
|
+
if (event.button === MouseButton.RightClick) {
|
|
8387
|
+
return false;
|
|
8388
|
+
}
|
|
8389
|
+
|
|
8390
|
+
onActivation == null ? void 0 : onActivation({
|
|
8391
|
+
event
|
|
8392
|
+
});
|
|
8393
|
+
return true;
|
|
8394
|
+
}
|
|
8395
|
+
}];
|
|
8396
|
+
|
|
8397
|
+
const events$2 = {
|
|
8398
|
+
move: {
|
|
8399
|
+
name: 'touchmove'
|
|
8400
|
+
},
|
|
8401
|
+
end: {
|
|
8402
|
+
name: 'touchend'
|
|
8403
|
+
}
|
|
8404
|
+
};
|
|
8405
|
+
class TouchSensor extends AbstractPointerSensor {
|
|
8406
|
+
constructor(props) {
|
|
8407
|
+
super(props, events$2);
|
|
8408
|
+
}
|
|
8409
|
+
|
|
8410
|
+
static setup() {
|
|
8411
|
+
// Adding a non-capture and non-passive `touchmove` listener in order
|
|
8412
|
+
// to force `event.preventDefault()` calls to work in dynamically added
|
|
8413
|
+
// touchmove event handlers. This is required for iOS Safari.
|
|
8414
|
+
window.addEventListener(events$2.move.name, noop, {
|
|
8415
|
+
capture: false,
|
|
8416
|
+
passive: false
|
|
8417
|
+
});
|
|
8418
|
+
return function teardown() {
|
|
8419
|
+
window.removeEventListener(events$2.move.name, noop);
|
|
8420
|
+
}; // We create a new handler because the teardown function of another sensor
|
|
8421
|
+
// could remove our event listener if we use a referentially equal listener.
|
|
8422
|
+
|
|
8423
|
+
function noop() {}
|
|
8424
|
+
}
|
|
8425
|
+
|
|
8426
|
+
}
|
|
8427
|
+
TouchSensor.activators = [{
|
|
8428
|
+
eventName: 'onTouchStart',
|
|
8429
|
+
handler: (_ref, _ref2) => {
|
|
8430
|
+
let {
|
|
8431
|
+
nativeEvent: event
|
|
8432
|
+
} = _ref;
|
|
8433
|
+
let {
|
|
8434
|
+
onActivation
|
|
8435
|
+
} = _ref2;
|
|
8436
|
+
const {
|
|
8437
|
+
touches
|
|
8438
|
+
} = event;
|
|
8439
|
+
|
|
8440
|
+
if (touches.length > 1) {
|
|
8441
|
+
return false;
|
|
8442
|
+
}
|
|
8443
|
+
|
|
8444
|
+
onActivation == null ? void 0 : onActivation({
|
|
8445
|
+
event
|
|
8446
|
+
});
|
|
8447
|
+
return true;
|
|
8448
|
+
}
|
|
8449
|
+
}];
|
|
8450
|
+
|
|
8451
|
+
var AutoScrollActivator;
|
|
8452
|
+
|
|
8453
|
+
(function (AutoScrollActivator) {
|
|
8454
|
+
AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
|
|
8455
|
+
AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
|
|
8456
|
+
})(AutoScrollActivator || (AutoScrollActivator = {}));
|
|
8457
|
+
|
|
8458
|
+
var TraversalOrder;
|
|
8459
|
+
|
|
8460
|
+
(function (TraversalOrder) {
|
|
8461
|
+
TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
|
|
8462
|
+
TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
|
|
8463
|
+
})(TraversalOrder || (TraversalOrder = {}));
|
|
8464
|
+
|
|
8465
|
+
function useAutoScroller(_ref) {
|
|
8466
|
+
let {
|
|
8467
|
+
acceleration,
|
|
8468
|
+
activator = AutoScrollActivator.Pointer,
|
|
8469
|
+
canScroll,
|
|
8470
|
+
draggingRect,
|
|
8471
|
+
enabled,
|
|
8472
|
+
interval = 5,
|
|
8473
|
+
order = TraversalOrder.TreeOrder,
|
|
8474
|
+
pointerCoordinates,
|
|
8475
|
+
scrollableAncestors,
|
|
8476
|
+
scrollableAncestorRects,
|
|
8477
|
+
delta,
|
|
8478
|
+
threshold
|
|
8479
|
+
} = _ref;
|
|
8480
|
+
const scrollIntent = useScrollIntent({
|
|
8481
|
+
delta,
|
|
8482
|
+
disabled: !enabled
|
|
8483
|
+
});
|
|
8484
|
+
const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
|
|
8485
|
+
const scrollSpeed = useRef({
|
|
8486
|
+
x: 0,
|
|
8487
|
+
y: 0
|
|
8488
|
+
});
|
|
8489
|
+
const scrollDirection = useRef({
|
|
8490
|
+
x: 0,
|
|
8491
|
+
y: 0
|
|
8492
|
+
});
|
|
8493
|
+
const rect = useMemo(() => {
|
|
8494
|
+
switch (activator) {
|
|
8495
|
+
case AutoScrollActivator.Pointer:
|
|
8496
|
+
return pointerCoordinates ? {
|
|
8497
|
+
top: pointerCoordinates.y,
|
|
8498
|
+
bottom: pointerCoordinates.y,
|
|
8499
|
+
left: pointerCoordinates.x,
|
|
8500
|
+
right: pointerCoordinates.x
|
|
8501
|
+
} : null;
|
|
8502
|
+
|
|
8503
|
+
case AutoScrollActivator.DraggableRect:
|
|
8504
|
+
return draggingRect;
|
|
8505
|
+
}
|
|
8506
|
+
}, [activator, draggingRect, pointerCoordinates]);
|
|
8507
|
+
const scrollContainerRef = useRef(null);
|
|
8508
|
+
const autoScroll = useCallback(() => {
|
|
8509
|
+
const scrollContainer = scrollContainerRef.current;
|
|
8510
|
+
|
|
8511
|
+
if (!scrollContainer) {
|
|
8512
|
+
return;
|
|
8513
|
+
}
|
|
8514
|
+
|
|
8515
|
+
const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
|
|
8516
|
+
const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
|
|
8517
|
+
scrollContainer.scrollBy(scrollLeft, scrollTop);
|
|
8518
|
+
}, []);
|
|
8519
|
+
const sortedScrollableAncestors = useMemo(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
|
|
8520
|
+
useEffect(() => {
|
|
8521
|
+
if (!enabled || !scrollableAncestors.length || !rect) {
|
|
8522
|
+
clearAutoScrollInterval();
|
|
8523
|
+
return;
|
|
8524
|
+
}
|
|
8525
|
+
|
|
8526
|
+
for (const scrollContainer of sortedScrollableAncestors) {
|
|
8527
|
+
if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
|
|
8528
|
+
continue;
|
|
8529
|
+
}
|
|
8530
|
+
|
|
8531
|
+
const index = scrollableAncestors.indexOf(scrollContainer);
|
|
8532
|
+
const scrollContainerRect = scrollableAncestorRects[index];
|
|
8533
|
+
|
|
8534
|
+
if (!scrollContainerRect) {
|
|
8535
|
+
continue;
|
|
8536
|
+
}
|
|
8537
|
+
|
|
8538
|
+
const {
|
|
8539
|
+
direction,
|
|
8540
|
+
speed
|
|
8541
|
+
} = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
|
|
8542
|
+
|
|
8543
|
+
for (const axis of ['x', 'y']) {
|
|
8544
|
+
if (!scrollIntent[axis][direction[axis]]) {
|
|
8545
|
+
speed[axis] = 0;
|
|
8546
|
+
direction[axis] = 0;
|
|
8547
|
+
}
|
|
8548
|
+
}
|
|
8549
|
+
|
|
8550
|
+
if (speed.x > 0 || speed.y > 0) {
|
|
8551
|
+
clearAutoScrollInterval();
|
|
8552
|
+
scrollContainerRef.current = scrollContainer;
|
|
8553
|
+
setAutoScrollInterval(autoScroll, interval);
|
|
8554
|
+
scrollSpeed.current = speed;
|
|
8555
|
+
scrollDirection.current = direction;
|
|
8556
|
+
return;
|
|
8557
|
+
}
|
|
8558
|
+
}
|
|
8559
|
+
|
|
8560
|
+
scrollSpeed.current = {
|
|
8561
|
+
x: 0,
|
|
8562
|
+
y: 0
|
|
8563
|
+
};
|
|
8564
|
+
scrollDirection.current = {
|
|
8565
|
+
x: 0,
|
|
8566
|
+
y: 0
|
|
8567
|
+
};
|
|
8568
|
+
clearAutoScrollInterval();
|
|
8569
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8570
|
+
[acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8571
|
+
JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8572
|
+
JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8573
|
+
JSON.stringify(threshold)]);
|
|
8574
|
+
}
|
|
8575
|
+
const defaultScrollIntent = {
|
|
8576
|
+
x: {
|
|
8577
|
+
[Direction.Backward]: false,
|
|
8578
|
+
[Direction.Forward]: false
|
|
8579
|
+
},
|
|
8580
|
+
y: {
|
|
8581
|
+
[Direction.Backward]: false,
|
|
8582
|
+
[Direction.Forward]: false
|
|
8583
|
+
}
|
|
8584
|
+
};
|
|
8585
|
+
|
|
8586
|
+
function useScrollIntent(_ref2) {
|
|
8587
|
+
let {
|
|
8588
|
+
delta,
|
|
8589
|
+
disabled
|
|
8590
|
+
} = _ref2;
|
|
8591
|
+
const previousDelta = usePrevious(delta);
|
|
8592
|
+
return useLazyMemo(previousIntent => {
|
|
8593
|
+
if (disabled || !previousDelta || !previousIntent) {
|
|
8594
|
+
// Reset scroll intent tracking when auto-scrolling is disabled
|
|
8595
|
+
return defaultScrollIntent;
|
|
8596
|
+
}
|
|
8597
|
+
|
|
8598
|
+
const direction = {
|
|
8599
|
+
x: Math.sign(delta.x - previousDelta.x),
|
|
8600
|
+
y: Math.sign(delta.y - previousDelta.y)
|
|
8601
|
+
}; // Keep track of the user intent to scroll in each direction for both axis
|
|
8602
|
+
|
|
8603
|
+
return {
|
|
8604
|
+
x: {
|
|
8605
|
+
[Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
|
|
8606
|
+
[Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
|
|
8607
|
+
},
|
|
8608
|
+
y: {
|
|
8609
|
+
[Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
|
|
8610
|
+
[Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
|
|
8611
|
+
}
|
|
8612
|
+
};
|
|
8613
|
+
}, [disabled, delta, previousDelta]);
|
|
8614
|
+
}
|
|
8615
|
+
|
|
8616
|
+
function useCachedNode(draggableNodes, id) {
|
|
8617
|
+
const draggableNode = id !== null ? draggableNodes.get(id) : undefined;
|
|
8618
|
+
const node = draggableNode ? draggableNode.node.current : null;
|
|
8619
|
+
return useLazyMemo(cachedNode => {
|
|
8620
|
+
var _ref;
|
|
8621
|
+
|
|
8622
|
+
if (id === null) {
|
|
8623
|
+
return null;
|
|
8624
|
+
} // In some cases, the draggable node can unmount while dragging
|
|
8625
|
+
// This is the case for virtualized lists. In those situations,
|
|
8626
|
+
// we fall back to the last known value for that node.
|
|
8627
|
+
|
|
8628
|
+
|
|
8629
|
+
return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
|
|
8630
|
+
}, [node, id]);
|
|
8631
|
+
}
|
|
8632
|
+
|
|
8633
|
+
function useCombineActivators(sensors, getSyntheticHandler) {
|
|
8634
|
+
return useMemo(() => sensors.reduce((accumulator, sensor) => {
|
|
8635
|
+
const {
|
|
8636
|
+
sensor: Sensor
|
|
8637
|
+
} = sensor;
|
|
8638
|
+
const sensorActivators = Sensor.activators.map(activator => ({
|
|
8639
|
+
eventName: activator.eventName,
|
|
8640
|
+
handler: getSyntheticHandler(activator.handler, sensor)
|
|
8641
|
+
}));
|
|
8642
|
+
return [...accumulator, ...sensorActivators];
|
|
8643
|
+
}, []), [sensors, getSyntheticHandler]);
|
|
8644
|
+
}
|
|
8645
|
+
|
|
8646
|
+
var MeasuringStrategy;
|
|
8647
|
+
|
|
8648
|
+
(function (MeasuringStrategy) {
|
|
8649
|
+
MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
|
|
8650
|
+
MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
|
|
8651
|
+
MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
|
|
8652
|
+
})(MeasuringStrategy || (MeasuringStrategy = {}));
|
|
8653
|
+
|
|
8654
|
+
var MeasuringFrequency;
|
|
8655
|
+
|
|
8656
|
+
(function (MeasuringFrequency) {
|
|
8657
|
+
MeasuringFrequency["Optimized"] = "optimized";
|
|
8658
|
+
})(MeasuringFrequency || (MeasuringFrequency = {}));
|
|
8659
|
+
|
|
8660
|
+
const defaultValue = /*#__PURE__*/new Map();
|
|
8661
|
+
function useDroppableMeasuring(containers, _ref) {
|
|
8662
|
+
let {
|
|
8663
|
+
dragging,
|
|
8664
|
+
dependencies,
|
|
8665
|
+
config
|
|
8666
|
+
} = _ref;
|
|
8667
|
+
const [queue, setQueue] = useState(null);
|
|
8668
|
+
const {
|
|
8669
|
+
frequency,
|
|
8670
|
+
measure,
|
|
8671
|
+
strategy
|
|
8672
|
+
} = config;
|
|
8673
|
+
const containersRef = useRef(containers);
|
|
8674
|
+
const disabled = isDisabled();
|
|
8675
|
+
const disabledRef = useLatestValue(disabled);
|
|
8676
|
+
const measureDroppableContainers = useCallback(function (ids) {
|
|
8677
|
+
if (ids === void 0) {
|
|
8678
|
+
ids = [];
|
|
8679
|
+
}
|
|
8680
|
+
|
|
8681
|
+
if (disabledRef.current) {
|
|
8682
|
+
return;
|
|
8683
|
+
}
|
|
8684
|
+
|
|
8685
|
+
setQueue(value => {
|
|
8686
|
+
if (value === null) {
|
|
8687
|
+
return ids;
|
|
8688
|
+
}
|
|
8689
|
+
|
|
8690
|
+
return value.concat(ids.filter(id => !value.includes(id)));
|
|
8691
|
+
});
|
|
8692
|
+
}, [disabledRef]);
|
|
8693
|
+
const timeoutId = useRef(null);
|
|
8694
|
+
const droppableRects = useLazyMemo(previousValue => {
|
|
8695
|
+
if (disabled && !dragging) {
|
|
8696
|
+
return defaultValue;
|
|
8697
|
+
}
|
|
8698
|
+
|
|
8699
|
+
if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
|
|
8700
|
+
const map = new Map();
|
|
8701
|
+
|
|
8702
|
+
for (let container of containers) {
|
|
8703
|
+
if (!container) {
|
|
8704
|
+
continue;
|
|
8705
|
+
}
|
|
8706
|
+
|
|
8707
|
+
if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
|
|
8708
|
+
// This container does not need to be re-measured
|
|
8709
|
+
map.set(container.id, container.rect.current);
|
|
8710
|
+
continue;
|
|
8711
|
+
}
|
|
8712
|
+
|
|
8713
|
+
const node = container.node.current;
|
|
8714
|
+
const rect = node ? new Rect(measure(node), node) : null;
|
|
8715
|
+
container.rect.current = rect;
|
|
8716
|
+
|
|
8717
|
+
if (rect) {
|
|
8718
|
+
map.set(container.id, rect);
|
|
8719
|
+
}
|
|
8720
|
+
}
|
|
8721
|
+
|
|
8722
|
+
return map;
|
|
8723
|
+
}
|
|
8724
|
+
|
|
8725
|
+
return previousValue;
|
|
8726
|
+
}, [containers, queue, dragging, disabled, measure]);
|
|
8727
|
+
useEffect(() => {
|
|
8728
|
+
containersRef.current = containers;
|
|
8729
|
+
}, [containers]);
|
|
8730
|
+
useEffect(() => {
|
|
8731
|
+
if (disabled) {
|
|
8732
|
+
return;
|
|
8733
|
+
}
|
|
8734
|
+
|
|
8735
|
+
measureDroppableContainers();
|
|
8736
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8737
|
+
[dragging, disabled]);
|
|
8738
|
+
useEffect(() => {
|
|
8739
|
+
if (queue && queue.length > 0) {
|
|
8740
|
+
setQueue(null);
|
|
8741
|
+
}
|
|
8742
|
+
}, //eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8743
|
+
[JSON.stringify(queue)]);
|
|
8744
|
+
useEffect(() => {
|
|
8745
|
+
if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
|
|
8746
|
+
return;
|
|
8747
|
+
}
|
|
8748
|
+
|
|
8749
|
+
timeoutId.current = setTimeout(() => {
|
|
8750
|
+
measureDroppableContainers();
|
|
8751
|
+
timeoutId.current = null;
|
|
8752
|
+
}, frequency);
|
|
8753
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8754
|
+
[frequency, disabled, measureDroppableContainers, ...dependencies]);
|
|
8755
|
+
return {
|
|
8756
|
+
droppableRects,
|
|
8757
|
+
measureDroppableContainers,
|
|
8758
|
+
measuringScheduled: queue != null
|
|
8759
|
+
};
|
|
8760
|
+
|
|
8761
|
+
function isDisabled() {
|
|
8762
|
+
switch (strategy) {
|
|
8763
|
+
case MeasuringStrategy.Always:
|
|
8764
|
+
return false;
|
|
8765
|
+
|
|
8766
|
+
case MeasuringStrategy.BeforeDragging:
|
|
8767
|
+
return dragging;
|
|
8768
|
+
|
|
8769
|
+
default:
|
|
8770
|
+
return !dragging;
|
|
8771
|
+
}
|
|
8772
|
+
}
|
|
8773
|
+
}
|
|
8774
|
+
|
|
8775
|
+
function useInitialValue(value, computeFn) {
|
|
8776
|
+
return useLazyMemo(previousValue => {
|
|
8777
|
+
if (!value) {
|
|
8778
|
+
return null;
|
|
8779
|
+
}
|
|
8780
|
+
|
|
8781
|
+
if (previousValue) {
|
|
8782
|
+
return previousValue;
|
|
8783
|
+
}
|
|
8784
|
+
|
|
8785
|
+
return typeof computeFn === 'function' ? computeFn(value) : value;
|
|
8786
|
+
}, [computeFn, value]);
|
|
8787
|
+
}
|
|
8788
|
+
|
|
8789
|
+
function useInitialRect(node, measure) {
|
|
8790
|
+
return useInitialValue(node, measure);
|
|
8791
|
+
}
|
|
8792
|
+
|
|
8793
|
+
/**
|
|
8794
|
+
* Returns a new MutationObserver instance.
|
|
8795
|
+
* If `MutationObserver` is undefined in the execution environment, returns `undefined`.
|
|
8796
|
+
*/
|
|
8797
|
+
|
|
8798
|
+
function useMutationObserver(_ref) {
|
|
8799
|
+
let {
|
|
8800
|
+
callback,
|
|
8801
|
+
disabled
|
|
8802
|
+
} = _ref;
|
|
8803
|
+
const handleMutations = useEvent(callback);
|
|
8804
|
+
const mutationObserver = useMemo(() => {
|
|
8805
|
+
if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
|
|
8806
|
+
return undefined;
|
|
8807
|
+
}
|
|
8808
|
+
|
|
8809
|
+
const {
|
|
8810
|
+
MutationObserver
|
|
8811
|
+
} = window;
|
|
8812
|
+
return new MutationObserver(handleMutations);
|
|
8813
|
+
}, [handleMutations, disabled]);
|
|
8814
|
+
useEffect(() => {
|
|
8815
|
+
return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
|
|
8816
|
+
}, [mutationObserver]);
|
|
8817
|
+
return mutationObserver;
|
|
8818
|
+
}
|
|
8819
|
+
|
|
8820
|
+
/**
|
|
8821
|
+
* Returns a new ResizeObserver instance bound to the `onResize` callback.
|
|
8822
|
+
* If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
|
|
8823
|
+
*/
|
|
8824
|
+
|
|
8825
|
+
function useResizeObserver(_ref) {
|
|
8826
|
+
let {
|
|
8827
|
+
callback,
|
|
8828
|
+
disabled
|
|
8829
|
+
} = _ref;
|
|
8830
|
+
const handleResize = useEvent(callback);
|
|
8831
|
+
const resizeObserver = useMemo(() => {
|
|
8832
|
+
if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
|
|
8833
|
+
return undefined;
|
|
8834
|
+
}
|
|
8835
|
+
|
|
8836
|
+
const {
|
|
8837
|
+
ResizeObserver
|
|
8838
|
+
} = window;
|
|
8839
|
+
return new ResizeObserver(handleResize);
|
|
8840
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8841
|
+
[disabled]);
|
|
8842
|
+
useEffect(() => {
|
|
8843
|
+
return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
8844
|
+
}, [resizeObserver]);
|
|
8845
|
+
return resizeObserver;
|
|
8846
|
+
}
|
|
8847
|
+
|
|
8848
|
+
function defaultMeasure(element) {
|
|
8849
|
+
return new Rect(getClientRect(element), element);
|
|
8850
|
+
}
|
|
8851
|
+
|
|
8852
|
+
function useRect(element, measure, fallbackRect) {
|
|
8853
|
+
if (measure === void 0) {
|
|
8854
|
+
measure = defaultMeasure;
|
|
8855
|
+
}
|
|
8856
|
+
|
|
8857
|
+
const [rect, measureRect] = useReducer(reducer, null);
|
|
8858
|
+
const mutationObserver = useMutationObserver({
|
|
8859
|
+
callback(records) {
|
|
8860
|
+
if (!element) {
|
|
8861
|
+
return;
|
|
8862
|
+
}
|
|
8863
|
+
|
|
8864
|
+
for (const record of records) {
|
|
8865
|
+
const {
|
|
8866
|
+
type,
|
|
8867
|
+
target
|
|
8868
|
+
} = record;
|
|
8869
|
+
|
|
8870
|
+
if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
|
|
8871
|
+
measureRect();
|
|
8872
|
+
break;
|
|
8873
|
+
}
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
|
|
8877
|
+
});
|
|
8878
|
+
const resizeObserver = useResizeObserver({
|
|
8879
|
+
callback: measureRect
|
|
8880
|
+
});
|
|
8881
|
+
useIsomorphicLayoutEffect(() => {
|
|
8882
|
+
measureRect();
|
|
8883
|
+
|
|
8884
|
+
if (element) {
|
|
8885
|
+
resizeObserver == null ? void 0 : resizeObserver.observe(element);
|
|
8886
|
+
mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
|
|
8887
|
+
childList: true,
|
|
8888
|
+
subtree: true
|
|
8889
|
+
});
|
|
8890
|
+
} else {
|
|
8891
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
8892
|
+
mutationObserver == null ? void 0 : mutationObserver.disconnect();
|
|
8893
|
+
}
|
|
8894
|
+
}, [element]);
|
|
8895
|
+
return rect;
|
|
8896
|
+
|
|
8897
|
+
function reducer(currentRect) {
|
|
8898
|
+
if (!element) {
|
|
8899
|
+
return null;
|
|
8900
|
+
}
|
|
8901
|
+
|
|
8902
|
+
if (element.isConnected === false) {
|
|
8903
|
+
var _ref;
|
|
8904
|
+
|
|
8905
|
+
// Fall back to last rect we measured if the element is
|
|
8906
|
+
// no longer connected to the DOM.
|
|
8907
|
+
return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
|
|
8908
|
+
}
|
|
8909
|
+
|
|
8910
|
+
const newRect = measure(element);
|
|
8911
|
+
|
|
8912
|
+
if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
|
|
8913
|
+
return currentRect;
|
|
8914
|
+
}
|
|
8915
|
+
|
|
8916
|
+
return newRect;
|
|
8917
|
+
}
|
|
8918
|
+
}
|
|
8919
|
+
|
|
8920
|
+
function useRectDelta(rect) {
|
|
8921
|
+
const initialRect = useInitialValue(rect);
|
|
8922
|
+
return getRectDelta(rect, initialRect);
|
|
8923
|
+
}
|
|
8924
|
+
|
|
8925
|
+
const defaultValue$1 = [];
|
|
8926
|
+
function useScrollableAncestors(node) {
|
|
8927
|
+
const previousNode = useRef(node);
|
|
8928
|
+
const ancestors = useLazyMemo(previousValue => {
|
|
8929
|
+
if (!node) {
|
|
8930
|
+
return defaultValue$1;
|
|
8931
|
+
}
|
|
8932
|
+
|
|
8933
|
+
if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
|
|
8934
|
+
return previousValue;
|
|
8935
|
+
}
|
|
8936
|
+
|
|
8937
|
+
return getScrollableAncestors(node);
|
|
8938
|
+
}, [node]);
|
|
8939
|
+
useEffect(() => {
|
|
8940
|
+
previousNode.current = node;
|
|
8941
|
+
}, [node]);
|
|
8942
|
+
return ancestors;
|
|
8943
|
+
}
|
|
8944
|
+
|
|
8945
|
+
function useScrollOffsets(elements) {
|
|
8946
|
+
const [scrollCoordinates, setScrollCoordinates] = useState(null);
|
|
8947
|
+
const prevElements = useRef(elements); // To-do: Throttle the handleScroll callback
|
|
8948
|
+
|
|
8949
|
+
const handleScroll = useCallback(event => {
|
|
8950
|
+
const scrollingElement = getScrollableElement(event.target);
|
|
8951
|
+
|
|
8952
|
+
if (!scrollingElement) {
|
|
8953
|
+
return;
|
|
8954
|
+
}
|
|
8955
|
+
|
|
8956
|
+
setScrollCoordinates(scrollCoordinates => {
|
|
8957
|
+
if (!scrollCoordinates) {
|
|
8958
|
+
return null;
|
|
8959
|
+
}
|
|
8960
|
+
|
|
8961
|
+
scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
|
|
8962
|
+
return new Map(scrollCoordinates);
|
|
8963
|
+
});
|
|
8964
|
+
}, []);
|
|
8965
|
+
useEffect(() => {
|
|
8966
|
+
const previousElements = prevElements.current;
|
|
8967
|
+
|
|
8968
|
+
if (elements !== previousElements) {
|
|
8969
|
+
cleanup(previousElements);
|
|
8970
|
+
const entries = elements.map(element => {
|
|
8971
|
+
const scrollableElement = getScrollableElement(element);
|
|
8972
|
+
|
|
8973
|
+
if (scrollableElement) {
|
|
8974
|
+
scrollableElement.addEventListener('scroll', handleScroll, {
|
|
8975
|
+
passive: true
|
|
8976
|
+
});
|
|
8977
|
+
return [scrollableElement, getScrollCoordinates(scrollableElement)];
|
|
8978
|
+
}
|
|
8979
|
+
|
|
8980
|
+
return null;
|
|
8981
|
+
}).filter(entry => entry != null);
|
|
8982
|
+
setScrollCoordinates(entries.length ? new Map(entries) : null);
|
|
8983
|
+
prevElements.current = elements;
|
|
8984
|
+
}
|
|
8985
|
+
|
|
8986
|
+
return () => {
|
|
8987
|
+
cleanup(elements);
|
|
8988
|
+
cleanup(previousElements);
|
|
8989
|
+
};
|
|
8990
|
+
|
|
8991
|
+
function cleanup(elements) {
|
|
8992
|
+
elements.forEach(element => {
|
|
8993
|
+
const scrollableElement = getScrollableElement(element);
|
|
8994
|
+
scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
|
|
8995
|
+
});
|
|
8996
|
+
}
|
|
8997
|
+
}, [handleScroll, elements]);
|
|
8998
|
+
return useMemo(() => {
|
|
8999
|
+
if (elements.length) {
|
|
9000
|
+
return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
|
|
9001
|
+
}
|
|
9002
|
+
|
|
9003
|
+
return defaultCoordinates;
|
|
9004
|
+
}, [elements, scrollCoordinates]);
|
|
9005
|
+
}
|
|
9006
|
+
|
|
9007
|
+
function useScrollOffsetsDelta(scrollOffsets, dependencies) {
|
|
9008
|
+
if (dependencies === void 0) {
|
|
9009
|
+
dependencies = [];
|
|
9010
|
+
}
|
|
9011
|
+
|
|
9012
|
+
const initialScrollOffsets = useRef(null);
|
|
9013
|
+
useEffect(() => {
|
|
9014
|
+
initialScrollOffsets.current = null;
|
|
9015
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9016
|
+
dependencies);
|
|
9017
|
+
useEffect(() => {
|
|
9018
|
+
const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
|
|
9019
|
+
|
|
9020
|
+
if (hasScrollOffsets && !initialScrollOffsets.current) {
|
|
9021
|
+
initialScrollOffsets.current = scrollOffsets;
|
|
9022
|
+
}
|
|
9023
|
+
|
|
9024
|
+
if (!hasScrollOffsets && initialScrollOffsets.current) {
|
|
9025
|
+
initialScrollOffsets.current = null;
|
|
9026
|
+
}
|
|
9027
|
+
}, [scrollOffsets]);
|
|
9028
|
+
return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
|
|
9029
|
+
}
|
|
9030
|
+
|
|
9031
|
+
function useSensorSetup(sensors) {
|
|
9032
|
+
useEffect(() => {
|
|
9033
|
+
if (!canUseDOM) {
|
|
9034
|
+
return;
|
|
9035
|
+
}
|
|
9036
|
+
|
|
9037
|
+
const teardownFns = sensors.map(_ref => {
|
|
9038
|
+
let {
|
|
9039
|
+
sensor
|
|
9040
|
+
} = _ref;
|
|
9041
|
+
return sensor.setup == null ? void 0 : sensor.setup();
|
|
9042
|
+
});
|
|
9043
|
+
return () => {
|
|
9044
|
+
for (const teardown of teardownFns) {
|
|
9045
|
+
teardown == null ? void 0 : teardown();
|
|
9046
|
+
}
|
|
9047
|
+
};
|
|
9048
|
+
}, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
|
|
9049
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9050
|
+
sensors.map(_ref2 => {
|
|
9051
|
+
let {
|
|
9052
|
+
sensor
|
|
9053
|
+
} = _ref2;
|
|
9054
|
+
return sensor;
|
|
9055
|
+
}));
|
|
9056
|
+
}
|
|
9057
|
+
|
|
9058
|
+
function useSyntheticListeners(listeners, id) {
|
|
9059
|
+
return useMemo(() => {
|
|
9060
|
+
return listeners.reduce((acc, _ref) => {
|
|
9061
|
+
let {
|
|
9062
|
+
eventName,
|
|
9063
|
+
handler
|
|
9064
|
+
} = _ref;
|
|
9065
|
+
|
|
9066
|
+
acc[eventName] = event => {
|
|
9067
|
+
handler(event, id);
|
|
9068
|
+
};
|
|
9069
|
+
|
|
9070
|
+
return acc;
|
|
9071
|
+
}, {});
|
|
9072
|
+
}, [listeners, id]);
|
|
9073
|
+
}
|
|
9074
|
+
|
|
9075
|
+
function useWindowRect(element) {
|
|
9076
|
+
return useMemo(() => element ? getWindowClientRect(element) : null, [element]);
|
|
9077
|
+
}
|
|
9078
|
+
|
|
9079
|
+
const defaultValue$2 = [];
|
|
9080
|
+
function useRects(elements, measure) {
|
|
9081
|
+
if (measure === void 0) {
|
|
9082
|
+
measure = getClientRect;
|
|
9083
|
+
}
|
|
9084
|
+
|
|
9085
|
+
const [firstElement] = elements;
|
|
9086
|
+
const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
|
|
9087
|
+
const [rects, measureRects] = useReducer(reducer, defaultValue$2);
|
|
9088
|
+
const resizeObserver = useResizeObserver({
|
|
9089
|
+
callback: measureRects
|
|
9090
|
+
});
|
|
9091
|
+
|
|
9092
|
+
if (elements.length > 0 && rects === defaultValue$2) {
|
|
9093
|
+
measureRects();
|
|
9094
|
+
}
|
|
9095
|
+
|
|
9096
|
+
useIsomorphicLayoutEffect(() => {
|
|
9097
|
+
if (elements.length) {
|
|
9098
|
+
elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
|
|
9099
|
+
} else {
|
|
9100
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
9101
|
+
measureRects();
|
|
9102
|
+
}
|
|
9103
|
+
}, [elements]);
|
|
9104
|
+
return rects;
|
|
9105
|
+
|
|
9106
|
+
function reducer() {
|
|
9107
|
+
if (!elements.length) {
|
|
9108
|
+
return defaultValue$2;
|
|
9109
|
+
}
|
|
9110
|
+
|
|
9111
|
+
return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
|
|
9112
|
+
}
|
|
9113
|
+
}
|
|
9114
|
+
|
|
9115
|
+
function getMeasurableNode(node) {
|
|
9116
|
+
if (!node) {
|
|
9117
|
+
return null;
|
|
9118
|
+
}
|
|
9119
|
+
|
|
9120
|
+
if (node.children.length > 1) {
|
|
9121
|
+
return node;
|
|
9122
|
+
}
|
|
9123
|
+
|
|
9124
|
+
const firstChild = node.children[0];
|
|
9125
|
+
return isHTMLElement(firstChild) ? firstChild : node;
|
|
9126
|
+
}
|
|
9127
|
+
|
|
9128
|
+
function useDragOverlayMeasuring(_ref) {
|
|
9129
|
+
let {
|
|
9130
|
+
measure
|
|
9131
|
+
} = _ref;
|
|
9132
|
+
const [rect, setRect] = useState(null);
|
|
9133
|
+
const handleResize = useCallback(entries => {
|
|
9134
|
+
for (const {
|
|
9135
|
+
target
|
|
9136
|
+
} of entries) {
|
|
9137
|
+
if (isHTMLElement(target)) {
|
|
9138
|
+
setRect(rect => {
|
|
9139
|
+
const newRect = measure(target);
|
|
9140
|
+
return rect ? { ...rect,
|
|
9141
|
+
width: newRect.width,
|
|
9142
|
+
height: newRect.height
|
|
9143
|
+
} : newRect;
|
|
9144
|
+
});
|
|
9145
|
+
break;
|
|
9146
|
+
}
|
|
9147
|
+
}
|
|
9148
|
+
}, [measure]);
|
|
9149
|
+
const resizeObserver = useResizeObserver({
|
|
9150
|
+
callback: handleResize
|
|
9151
|
+
});
|
|
9152
|
+
const handleNodeChange = useCallback(element => {
|
|
9153
|
+
const node = getMeasurableNode(element);
|
|
9154
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
9155
|
+
|
|
9156
|
+
if (node) {
|
|
9157
|
+
resizeObserver == null ? void 0 : resizeObserver.observe(node);
|
|
9158
|
+
}
|
|
9159
|
+
|
|
9160
|
+
setRect(node ? measure(node) : null);
|
|
9161
|
+
}, [measure, resizeObserver]);
|
|
9162
|
+
const [nodeRef, setRef] = useNodeRef(handleNodeChange);
|
|
9163
|
+
return useMemo(() => ({
|
|
9164
|
+
nodeRef,
|
|
9165
|
+
rect,
|
|
9166
|
+
setRef
|
|
9167
|
+
}), [rect, nodeRef, setRef]);
|
|
9168
|
+
}
|
|
9169
|
+
|
|
9170
|
+
const defaultSensors = [{
|
|
9171
|
+
sensor: PointerSensor,
|
|
9172
|
+
options: {}
|
|
9173
|
+
}, {
|
|
9174
|
+
sensor: KeyboardSensor,
|
|
9175
|
+
options: {}
|
|
9176
|
+
}];
|
|
9177
|
+
const defaultData = {
|
|
9178
|
+
current: {}
|
|
9179
|
+
};
|
|
9180
|
+
const defaultMeasuringConfiguration = {
|
|
9181
|
+
draggable: {
|
|
9182
|
+
measure: getTransformAgnosticClientRect
|
|
9183
|
+
},
|
|
9184
|
+
droppable: {
|
|
9185
|
+
measure: getTransformAgnosticClientRect,
|
|
9186
|
+
strategy: MeasuringStrategy.WhileDragging,
|
|
9187
|
+
frequency: MeasuringFrequency.Optimized
|
|
9188
|
+
},
|
|
9189
|
+
dragOverlay: {
|
|
9190
|
+
measure: getClientRect
|
|
9191
|
+
}
|
|
9192
|
+
};
|
|
9193
|
+
|
|
9194
|
+
class DroppableContainersMap extends Map {
|
|
9195
|
+
get(id) {
|
|
9196
|
+
var _super$get;
|
|
9197
|
+
|
|
9198
|
+
return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
|
|
9199
|
+
}
|
|
9200
|
+
|
|
9201
|
+
toArray() {
|
|
9202
|
+
return Array.from(this.values());
|
|
9203
|
+
}
|
|
9204
|
+
|
|
9205
|
+
getEnabled() {
|
|
9206
|
+
return this.toArray().filter(_ref => {
|
|
9207
|
+
let {
|
|
9208
|
+
disabled
|
|
9209
|
+
} = _ref;
|
|
9210
|
+
return !disabled;
|
|
9211
|
+
});
|
|
9212
|
+
}
|
|
9213
|
+
|
|
9214
|
+
getNodeFor(id) {
|
|
9215
|
+
var _this$get$node$curren, _this$get;
|
|
9216
|
+
|
|
9217
|
+
return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
|
|
9218
|
+
}
|
|
9219
|
+
|
|
9220
|
+
}
|
|
9221
|
+
|
|
9222
|
+
const defaultPublicContext = {
|
|
9223
|
+
activatorEvent: null,
|
|
9224
|
+
active: null,
|
|
9225
|
+
activeNode: null,
|
|
9226
|
+
activeNodeRect: null,
|
|
9227
|
+
collisions: null,
|
|
9228
|
+
containerNodeRect: null,
|
|
9229
|
+
draggableNodes: /*#__PURE__*/new Map(),
|
|
9230
|
+
droppableRects: /*#__PURE__*/new Map(),
|
|
9231
|
+
droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
|
|
9232
|
+
over: null,
|
|
9233
|
+
dragOverlay: {
|
|
9234
|
+
nodeRef: {
|
|
9235
|
+
current: null
|
|
9236
|
+
},
|
|
9237
|
+
rect: null,
|
|
9238
|
+
setRef: noop
|
|
9239
|
+
},
|
|
9240
|
+
scrollableAncestors: [],
|
|
9241
|
+
scrollableAncestorRects: [],
|
|
9242
|
+
measuringConfiguration: defaultMeasuringConfiguration,
|
|
9243
|
+
measureDroppableContainers: noop,
|
|
9244
|
+
windowRect: null,
|
|
9245
|
+
measuringScheduled: false
|
|
9246
|
+
};
|
|
9247
|
+
const defaultInternalContext = {
|
|
9248
|
+
activatorEvent: null,
|
|
9249
|
+
activators: [],
|
|
9250
|
+
active: null,
|
|
9251
|
+
activeNodeRect: null,
|
|
9252
|
+
ariaDescribedById: {
|
|
9253
|
+
draggable: ''
|
|
9254
|
+
},
|
|
9255
|
+
dispatch: noop,
|
|
9256
|
+
draggableNodes: /*#__PURE__*/new Map(),
|
|
9257
|
+
over: null,
|
|
9258
|
+
measureDroppableContainers: noop
|
|
9259
|
+
};
|
|
9260
|
+
const InternalContext = /*#__PURE__*/createContext(defaultInternalContext);
|
|
9261
|
+
const PublicContext = /*#__PURE__*/createContext(defaultPublicContext);
|
|
9262
|
+
|
|
9263
|
+
function getInitialState() {
|
|
9264
|
+
return {
|
|
9265
|
+
draggable: {
|
|
9266
|
+
active: null,
|
|
9267
|
+
initialCoordinates: {
|
|
9268
|
+
x: 0,
|
|
9269
|
+
y: 0
|
|
9270
|
+
},
|
|
9271
|
+
nodes: new Map(),
|
|
9272
|
+
translate: {
|
|
9273
|
+
x: 0,
|
|
9274
|
+
y: 0
|
|
9275
|
+
}
|
|
9276
|
+
},
|
|
9277
|
+
droppable: {
|
|
9278
|
+
containers: new DroppableContainersMap()
|
|
9279
|
+
}
|
|
9280
|
+
};
|
|
9281
|
+
}
|
|
9282
|
+
function reducer(state, action) {
|
|
9283
|
+
switch (action.type) {
|
|
9284
|
+
case Action.DragStart:
|
|
9285
|
+
return { ...state,
|
|
9286
|
+
draggable: { ...state.draggable,
|
|
9287
|
+
initialCoordinates: action.initialCoordinates,
|
|
9288
|
+
active: action.active
|
|
9289
|
+
}
|
|
9290
|
+
};
|
|
9291
|
+
|
|
9292
|
+
case Action.DragMove:
|
|
9293
|
+
if (!state.draggable.active) {
|
|
9294
|
+
return state;
|
|
9295
|
+
}
|
|
9296
|
+
|
|
9297
|
+
return { ...state,
|
|
9298
|
+
draggable: { ...state.draggable,
|
|
9299
|
+
translate: {
|
|
9300
|
+
x: action.coordinates.x - state.draggable.initialCoordinates.x,
|
|
9301
|
+
y: action.coordinates.y - state.draggable.initialCoordinates.y
|
|
9302
|
+
}
|
|
9303
|
+
}
|
|
9304
|
+
};
|
|
9305
|
+
|
|
9306
|
+
case Action.DragEnd:
|
|
9307
|
+
case Action.DragCancel:
|
|
9308
|
+
return { ...state,
|
|
9309
|
+
draggable: { ...state.draggable,
|
|
9310
|
+
active: null,
|
|
9311
|
+
initialCoordinates: {
|
|
9312
|
+
x: 0,
|
|
9313
|
+
y: 0
|
|
9314
|
+
},
|
|
9315
|
+
translate: {
|
|
9316
|
+
x: 0,
|
|
9317
|
+
y: 0
|
|
9318
|
+
}
|
|
9319
|
+
}
|
|
9320
|
+
};
|
|
9321
|
+
|
|
9322
|
+
case Action.RegisterDroppable:
|
|
9323
|
+
{
|
|
9324
|
+
const {
|
|
9325
|
+
element
|
|
9326
|
+
} = action;
|
|
9327
|
+
const {
|
|
9328
|
+
id
|
|
9329
|
+
} = element;
|
|
9330
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
9331
|
+
containers.set(id, element);
|
|
9332
|
+
return { ...state,
|
|
9333
|
+
droppable: { ...state.droppable,
|
|
9334
|
+
containers
|
|
9335
|
+
}
|
|
9336
|
+
};
|
|
9337
|
+
}
|
|
9338
|
+
|
|
9339
|
+
case Action.SetDroppableDisabled:
|
|
9340
|
+
{
|
|
9341
|
+
const {
|
|
9342
|
+
id,
|
|
9343
|
+
key,
|
|
9344
|
+
disabled
|
|
9345
|
+
} = action;
|
|
9346
|
+
const element = state.droppable.containers.get(id);
|
|
9347
|
+
|
|
9348
|
+
if (!element || key !== element.key) {
|
|
9349
|
+
return state;
|
|
9350
|
+
}
|
|
9351
|
+
|
|
9352
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
9353
|
+
containers.set(id, { ...element,
|
|
9354
|
+
disabled
|
|
9355
|
+
});
|
|
9356
|
+
return { ...state,
|
|
9357
|
+
droppable: { ...state.droppable,
|
|
9358
|
+
containers
|
|
9359
|
+
}
|
|
9360
|
+
};
|
|
9361
|
+
}
|
|
9362
|
+
|
|
9363
|
+
case Action.UnregisterDroppable:
|
|
9364
|
+
{
|
|
9365
|
+
const {
|
|
9366
|
+
id,
|
|
9367
|
+
key
|
|
9368
|
+
} = action;
|
|
9369
|
+
const element = state.droppable.containers.get(id);
|
|
9370
|
+
|
|
9371
|
+
if (!element || key !== element.key) {
|
|
9372
|
+
return state;
|
|
9373
|
+
}
|
|
9374
|
+
|
|
9375
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
9376
|
+
containers.delete(id);
|
|
9377
|
+
return { ...state,
|
|
9378
|
+
droppable: { ...state.droppable,
|
|
9379
|
+
containers
|
|
9380
|
+
}
|
|
9381
|
+
};
|
|
9382
|
+
}
|
|
9383
|
+
|
|
9384
|
+
default:
|
|
9385
|
+
{
|
|
9386
|
+
return state;
|
|
9387
|
+
}
|
|
9388
|
+
}
|
|
9389
|
+
}
|
|
9390
|
+
|
|
9391
|
+
function RestoreFocus(_ref) {
|
|
9392
|
+
let {
|
|
9393
|
+
disabled
|
|
9394
|
+
} = _ref;
|
|
9395
|
+
const {
|
|
9396
|
+
active,
|
|
9397
|
+
activatorEvent,
|
|
9398
|
+
draggableNodes
|
|
9399
|
+
} = useContext(InternalContext);
|
|
9400
|
+
const previousActivatorEvent = usePrevious(activatorEvent);
|
|
9401
|
+
const previousActiveId = usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
|
|
9402
|
+
|
|
9403
|
+
useEffect(() => {
|
|
9404
|
+
if (disabled) {
|
|
9405
|
+
return;
|
|
9406
|
+
}
|
|
9407
|
+
|
|
9408
|
+
if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
|
|
9409
|
+
if (!isKeyboardEvent(previousActivatorEvent)) {
|
|
9410
|
+
return;
|
|
9411
|
+
}
|
|
9412
|
+
|
|
9413
|
+
if (document.activeElement === previousActivatorEvent.target) {
|
|
9414
|
+
// No need to restore focus
|
|
9415
|
+
return;
|
|
9416
|
+
}
|
|
9417
|
+
|
|
9418
|
+
const draggableNode = draggableNodes.get(previousActiveId);
|
|
9419
|
+
|
|
9420
|
+
if (!draggableNode) {
|
|
9421
|
+
return;
|
|
9422
|
+
}
|
|
9423
|
+
|
|
9424
|
+
const {
|
|
9425
|
+
activatorNode,
|
|
9426
|
+
node
|
|
9427
|
+
} = draggableNode;
|
|
9428
|
+
|
|
9429
|
+
if (!activatorNode.current && !node.current) {
|
|
9430
|
+
return;
|
|
9431
|
+
}
|
|
9432
|
+
|
|
9433
|
+
requestAnimationFrame(() => {
|
|
9434
|
+
for (const element of [activatorNode.current, node.current]) {
|
|
9435
|
+
if (!element) {
|
|
9436
|
+
continue;
|
|
9437
|
+
}
|
|
9438
|
+
|
|
9439
|
+
const focusableNode = findFirstFocusableNode(element);
|
|
9440
|
+
|
|
9441
|
+
if (focusableNode) {
|
|
9442
|
+
focusableNode.focus();
|
|
9443
|
+
break;
|
|
9444
|
+
}
|
|
9445
|
+
}
|
|
9446
|
+
});
|
|
9447
|
+
}
|
|
9448
|
+
}, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
|
|
9449
|
+
return null;
|
|
9450
|
+
}
|
|
9451
|
+
|
|
9452
|
+
function applyModifiers(modifiers, _ref) {
|
|
9453
|
+
let {
|
|
9454
|
+
transform,
|
|
9455
|
+
...args
|
|
9456
|
+
} = _ref;
|
|
9457
|
+
return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
|
|
9458
|
+
return modifier({
|
|
9459
|
+
transform: accumulator,
|
|
9460
|
+
...args
|
|
9461
|
+
});
|
|
9462
|
+
}, transform) : transform;
|
|
9463
|
+
}
|
|
9464
|
+
|
|
9465
|
+
function useMeasuringConfiguration(config) {
|
|
9466
|
+
return useMemo(() => ({
|
|
9467
|
+
draggable: { ...defaultMeasuringConfiguration.draggable,
|
|
9468
|
+
...(config == null ? void 0 : config.draggable)
|
|
9469
|
+
},
|
|
9470
|
+
droppable: { ...defaultMeasuringConfiguration.droppable,
|
|
9471
|
+
...(config == null ? void 0 : config.droppable)
|
|
9472
|
+
},
|
|
9473
|
+
dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
|
|
9474
|
+
...(config == null ? void 0 : config.dragOverlay)
|
|
9475
|
+
}
|
|
9476
|
+
}), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9477
|
+
[config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
|
|
9478
|
+
}
|
|
9479
|
+
|
|
9480
|
+
function useLayoutShiftScrollCompensation(_ref) {
|
|
9481
|
+
let {
|
|
9482
|
+
activeNode,
|
|
9483
|
+
measure,
|
|
9484
|
+
initialRect,
|
|
9485
|
+
config = true
|
|
9486
|
+
} = _ref;
|
|
9487
|
+
const initialized = useRef(false);
|
|
9488
|
+
const {
|
|
9489
|
+
x,
|
|
9490
|
+
y
|
|
9491
|
+
} = typeof config === 'boolean' ? {
|
|
9492
|
+
x: config,
|
|
9493
|
+
y: config
|
|
9494
|
+
} : config;
|
|
9495
|
+
useIsomorphicLayoutEffect(() => {
|
|
9496
|
+
const disabled = !x && !y;
|
|
9497
|
+
|
|
9498
|
+
if (disabled || !activeNode) {
|
|
9499
|
+
initialized.current = false;
|
|
9500
|
+
return;
|
|
9501
|
+
}
|
|
9502
|
+
|
|
9503
|
+
if (initialized.current || !initialRect) {
|
|
9504
|
+
// Return early if layout shift scroll compensation was already attempted
|
|
9505
|
+
// or if there is no initialRect to compare to.
|
|
9506
|
+
return;
|
|
9507
|
+
} // Get the most up to date node ref for the active draggable
|
|
9508
|
+
|
|
9509
|
+
|
|
9510
|
+
const node = activeNode == null ? void 0 : activeNode.node.current;
|
|
9511
|
+
|
|
9512
|
+
if (!node || node.isConnected === false) {
|
|
9513
|
+
// Return early if there is no attached node ref or if the node is
|
|
9514
|
+
// disconnected from the document.
|
|
9515
|
+
return;
|
|
9516
|
+
}
|
|
9517
|
+
|
|
9518
|
+
const rect = measure(node);
|
|
9519
|
+
const rectDelta = getRectDelta(rect, initialRect);
|
|
9520
|
+
|
|
9521
|
+
if (!x) {
|
|
9522
|
+
rectDelta.x = 0;
|
|
9523
|
+
}
|
|
9524
|
+
|
|
9525
|
+
if (!y) {
|
|
9526
|
+
rectDelta.y = 0;
|
|
9527
|
+
} // Only perform layout shift scroll compensation once
|
|
9528
|
+
|
|
9529
|
+
|
|
9530
|
+
initialized.current = true;
|
|
9531
|
+
|
|
9532
|
+
if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
|
|
9533
|
+
const firstScrollableAncestor = getFirstScrollableAncestor(node);
|
|
9534
|
+
|
|
9535
|
+
if (firstScrollableAncestor) {
|
|
9536
|
+
firstScrollableAncestor.scrollBy({
|
|
9537
|
+
top: rectDelta.y,
|
|
9538
|
+
left: rectDelta.x
|
|
9539
|
+
});
|
|
9540
|
+
}
|
|
9541
|
+
}
|
|
9542
|
+
}, [activeNode, x, y, initialRect, measure]);
|
|
9543
|
+
}
|
|
9544
|
+
|
|
9545
|
+
const ActiveDraggableContext = /*#__PURE__*/createContext({ ...defaultCoordinates,
|
|
9546
|
+
scaleX: 1,
|
|
9547
|
+
scaleY: 1
|
|
9548
|
+
});
|
|
9549
|
+
var Status;
|
|
9550
|
+
|
|
9551
|
+
(function (Status) {
|
|
9552
|
+
Status[Status["Uninitialized"] = 0] = "Uninitialized";
|
|
9553
|
+
Status[Status["Initializing"] = 1] = "Initializing";
|
|
9554
|
+
Status[Status["Initialized"] = 2] = "Initialized";
|
|
9555
|
+
})(Status || (Status = {}));
|
|
9556
|
+
|
|
9557
|
+
const DndContext = /*#__PURE__*/memo(function DndContext(_ref) {
|
|
9558
|
+
var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
|
|
9559
|
+
|
|
9560
|
+
let {
|
|
9561
|
+
id,
|
|
9562
|
+
accessibility,
|
|
9563
|
+
autoScroll = true,
|
|
9564
|
+
children,
|
|
9565
|
+
sensors = defaultSensors,
|
|
9566
|
+
collisionDetection = rectIntersection,
|
|
9567
|
+
measuring,
|
|
9568
|
+
modifiers,
|
|
9569
|
+
...props
|
|
9570
|
+
} = _ref;
|
|
9571
|
+
const store = useReducer(reducer, undefined, getInitialState);
|
|
9572
|
+
const [state, dispatch] = store;
|
|
9573
|
+
const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
|
|
9574
|
+
const [status, setStatus] = useState(Status.Uninitialized);
|
|
9575
|
+
const isInitialized = status === Status.Initialized;
|
|
9576
|
+
const {
|
|
9577
|
+
draggable: {
|
|
9578
|
+
active: activeId,
|
|
9579
|
+
nodes: draggableNodes,
|
|
9580
|
+
translate
|
|
9581
|
+
},
|
|
9582
|
+
droppable: {
|
|
9583
|
+
containers: droppableContainers
|
|
9584
|
+
}
|
|
9585
|
+
} = state;
|
|
9586
|
+
const node = activeId ? draggableNodes.get(activeId) : null;
|
|
9587
|
+
const activeRects = useRef({
|
|
9588
|
+
initial: null,
|
|
9589
|
+
translated: null
|
|
9590
|
+
});
|
|
9591
|
+
const active = useMemo(() => {
|
|
9592
|
+
var _node$data;
|
|
9593
|
+
|
|
9594
|
+
return activeId != null ? {
|
|
9595
|
+
id: activeId,
|
|
9596
|
+
// It's possible for the active node to unmount while dragging
|
|
9597
|
+
data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
|
|
9598
|
+
rect: activeRects
|
|
9599
|
+
} : null;
|
|
9600
|
+
}, [activeId, node]);
|
|
9601
|
+
const activeRef = useRef(null);
|
|
9602
|
+
const [activeSensor, setActiveSensor] = useState(null);
|
|
9603
|
+
const [activatorEvent, setActivatorEvent] = useState(null);
|
|
9604
|
+
const latestProps = useLatestValue(props, Object.values(props));
|
|
9605
|
+
const draggableDescribedById = useUniqueId("DndDescribedBy", id);
|
|
9606
|
+
const enabledDroppableContainers = useMemo(() => droppableContainers.getEnabled(), [droppableContainers]);
|
|
9607
|
+
const measuringConfiguration = useMeasuringConfiguration(measuring);
|
|
9608
|
+
const {
|
|
9609
|
+
droppableRects,
|
|
9610
|
+
measureDroppableContainers,
|
|
9611
|
+
measuringScheduled
|
|
9612
|
+
} = useDroppableMeasuring(enabledDroppableContainers, {
|
|
9613
|
+
dragging: isInitialized,
|
|
9614
|
+
dependencies: [translate.x, translate.y],
|
|
9615
|
+
config: measuringConfiguration.droppable
|
|
9616
|
+
});
|
|
9617
|
+
const activeNode = useCachedNode(draggableNodes, activeId);
|
|
9618
|
+
const activationCoordinates = useMemo(() => activatorEvent ? getEventCoordinates(activatorEvent) : null, [activatorEvent]);
|
|
9619
|
+
const autoScrollOptions = getAutoScrollerOptions();
|
|
9620
|
+
const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
|
|
9621
|
+
useLayoutShiftScrollCompensation({
|
|
9622
|
+
activeNode: activeId ? draggableNodes.get(activeId) : null,
|
|
9623
|
+
config: autoScrollOptions.layoutShiftCompensation,
|
|
9624
|
+
initialRect: initialActiveNodeRect,
|
|
9625
|
+
measure: measuringConfiguration.draggable.measure
|
|
9626
|
+
});
|
|
9627
|
+
const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
|
|
9628
|
+
const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
|
|
9629
|
+
const sensorContext = useRef({
|
|
9630
|
+
activatorEvent: null,
|
|
9631
|
+
active: null,
|
|
9632
|
+
activeNode,
|
|
9633
|
+
collisionRect: null,
|
|
9634
|
+
collisions: null,
|
|
9635
|
+
droppableRects,
|
|
9636
|
+
draggableNodes,
|
|
9637
|
+
draggingNode: null,
|
|
9638
|
+
draggingNodeRect: null,
|
|
9639
|
+
droppableContainers,
|
|
9640
|
+
over: null,
|
|
9641
|
+
scrollableAncestors: [],
|
|
9642
|
+
scrollAdjustedTranslate: null
|
|
9643
|
+
});
|
|
9644
|
+
const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
|
|
9645
|
+
const dragOverlay = useDragOverlayMeasuring({
|
|
9646
|
+
measure: measuringConfiguration.dragOverlay.measure
|
|
9647
|
+
}); // Use the rect of the drag overlay if it is mounted
|
|
9648
|
+
|
|
9649
|
+
const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
|
|
9650
|
+
const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
|
|
9651
|
+
const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
|
|
9652
|
+
// is only relevant when there is no drag overlay
|
|
9653
|
+
|
|
9654
|
+
const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
|
|
9655
|
+
|
|
9656
|
+
const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
|
|
9657
|
+
|
|
9658
|
+
const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
|
|
9659
|
+
const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
|
|
9660
|
+
|
|
9661
|
+
const modifiedTranslate = applyModifiers(modifiers, {
|
|
9662
|
+
transform: {
|
|
9663
|
+
x: translate.x - nodeRectDelta.x,
|
|
9664
|
+
y: translate.y - nodeRectDelta.y,
|
|
9665
|
+
scaleX: 1,
|
|
9666
|
+
scaleY: 1
|
|
9667
|
+
},
|
|
9668
|
+
activatorEvent,
|
|
9669
|
+
active,
|
|
9670
|
+
activeNodeRect,
|
|
9671
|
+
containerNodeRect,
|
|
9672
|
+
draggingNodeRect,
|
|
9673
|
+
over: sensorContext.current.over,
|
|
9674
|
+
overlayNodeRect: dragOverlay.rect,
|
|
9675
|
+
scrollableAncestors,
|
|
9676
|
+
scrollableAncestorRects,
|
|
9677
|
+
windowRect
|
|
9678
|
+
});
|
|
9679
|
+
const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
|
|
9680
|
+
const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
|
|
9681
|
+
|
|
9682
|
+
const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
|
|
9683
|
+
|
|
9684
|
+
const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
|
|
9685
|
+
const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
|
|
9686
|
+
const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
|
|
9687
|
+
const collisions = active && collisionRect ? collisionDetection({
|
|
9688
|
+
active,
|
|
9689
|
+
collisionRect,
|
|
9690
|
+
droppableRects,
|
|
9691
|
+
droppableContainers: enabledDroppableContainers,
|
|
9692
|
+
pointerCoordinates
|
|
9693
|
+
}) : null;
|
|
9694
|
+
const overId = getFirstCollision(collisions, 'id');
|
|
9695
|
+
const [over, setOver] = useState(null); // When there is no drag overlay used, we need to account for the
|
|
9696
|
+
// window scroll delta
|
|
9697
|
+
|
|
9698
|
+
const appliedTranslate = usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta);
|
|
9699
|
+
const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
|
|
9700
|
+
const instantiateSensor = useCallback((event, _ref2) => {
|
|
9701
|
+
let {
|
|
9702
|
+
sensor: Sensor,
|
|
9703
|
+
options
|
|
9704
|
+
} = _ref2;
|
|
9705
|
+
|
|
9706
|
+
if (activeRef.current == null) {
|
|
9707
|
+
return;
|
|
9708
|
+
}
|
|
9709
|
+
|
|
9710
|
+
const activeNode = draggableNodes.get(activeRef.current);
|
|
9711
|
+
|
|
9712
|
+
if (!activeNode) {
|
|
9713
|
+
return;
|
|
9714
|
+
}
|
|
9715
|
+
|
|
9716
|
+
const activatorEvent = event.nativeEvent;
|
|
9717
|
+
const sensorInstance = new Sensor({
|
|
9718
|
+
active: activeRef.current,
|
|
9719
|
+
activeNode,
|
|
9720
|
+
event: activatorEvent,
|
|
9721
|
+
options,
|
|
9722
|
+
// Sensors need to be instantiated with refs for arguments that change over time
|
|
9723
|
+
// otherwise they are frozen in time with the stale arguments
|
|
9724
|
+
context: sensorContext,
|
|
9725
|
+
|
|
9726
|
+
onStart(initialCoordinates) {
|
|
9727
|
+
const id = activeRef.current;
|
|
9728
|
+
|
|
9729
|
+
if (id == null) {
|
|
9730
|
+
return;
|
|
9731
|
+
}
|
|
9732
|
+
|
|
9733
|
+
const draggableNode = draggableNodes.get(id);
|
|
9734
|
+
|
|
9735
|
+
if (!draggableNode) {
|
|
9736
|
+
return;
|
|
9737
|
+
}
|
|
9738
|
+
|
|
9739
|
+
const {
|
|
9740
|
+
onDragStart
|
|
9741
|
+
} = latestProps.current;
|
|
9742
|
+
const event = {
|
|
9743
|
+
active: {
|
|
9744
|
+
id,
|
|
9745
|
+
data: draggableNode.data,
|
|
9746
|
+
rect: activeRects
|
|
9747
|
+
}
|
|
9748
|
+
};
|
|
9749
|
+
unstable_batchedUpdates(() => {
|
|
9750
|
+
onDragStart == null ? void 0 : onDragStart(event);
|
|
9751
|
+
setStatus(Status.Initializing);
|
|
9752
|
+
dispatch({
|
|
9753
|
+
type: Action.DragStart,
|
|
9754
|
+
initialCoordinates,
|
|
9755
|
+
active: id
|
|
9756
|
+
});
|
|
9757
|
+
dispatchMonitorEvent({
|
|
9758
|
+
type: 'onDragStart',
|
|
9759
|
+
event
|
|
9760
|
+
});
|
|
9761
|
+
});
|
|
9762
|
+
},
|
|
9763
|
+
|
|
9764
|
+
onMove(coordinates) {
|
|
9765
|
+
dispatch({
|
|
9766
|
+
type: Action.DragMove,
|
|
9767
|
+
coordinates
|
|
9768
|
+
});
|
|
9769
|
+
},
|
|
9770
|
+
|
|
9771
|
+
onEnd: createHandler(Action.DragEnd),
|
|
9772
|
+
onCancel: createHandler(Action.DragCancel)
|
|
9773
|
+
});
|
|
9774
|
+
unstable_batchedUpdates(() => {
|
|
9775
|
+
setActiveSensor(sensorInstance);
|
|
9776
|
+
setActivatorEvent(event.nativeEvent);
|
|
9777
|
+
});
|
|
9778
|
+
|
|
9779
|
+
function createHandler(type) {
|
|
9780
|
+
return async function handler() {
|
|
9781
|
+
const {
|
|
9782
|
+
active,
|
|
9783
|
+
collisions,
|
|
9784
|
+
over,
|
|
9785
|
+
scrollAdjustedTranslate
|
|
9786
|
+
} = sensorContext.current;
|
|
9787
|
+
let event = null;
|
|
9788
|
+
|
|
9789
|
+
if (active && scrollAdjustedTranslate) {
|
|
9790
|
+
const {
|
|
9791
|
+
cancelDrop
|
|
9792
|
+
} = latestProps.current;
|
|
9793
|
+
event = {
|
|
9794
|
+
activatorEvent,
|
|
9795
|
+
active: active,
|
|
9796
|
+
collisions,
|
|
9797
|
+
delta: scrollAdjustedTranslate,
|
|
9798
|
+
over
|
|
9799
|
+
};
|
|
9800
|
+
|
|
9801
|
+
if (type === Action.DragEnd && typeof cancelDrop === 'function') {
|
|
9802
|
+
const shouldCancel = await Promise.resolve(cancelDrop(event));
|
|
9803
|
+
|
|
9804
|
+
if (shouldCancel) {
|
|
9805
|
+
type = Action.DragCancel;
|
|
9806
|
+
}
|
|
9807
|
+
}
|
|
9808
|
+
}
|
|
9809
|
+
|
|
9810
|
+
activeRef.current = null;
|
|
9811
|
+
unstable_batchedUpdates(() => {
|
|
9812
|
+
dispatch({
|
|
9813
|
+
type
|
|
9814
|
+
});
|
|
9815
|
+
setStatus(Status.Uninitialized);
|
|
9816
|
+
setOver(null);
|
|
9817
|
+
setActiveSensor(null);
|
|
9818
|
+
setActivatorEvent(null);
|
|
9819
|
+
const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
|
|
9820
|
+
|
|
9821
|
+
if (event) {
|
|
9822
|
+
const handler = latestProps.current[eventName];
|
|
9823
|
+
handler == null ? void 0 : handler(event);
|
|
9824
|
+
dispatchMonitorEvent({
|
|
9825
|
+
type: eventName,
|
|
9826
|
+
event
|
|
9827
|
+
});
|
|
9828
|
+
}
|
|
9829
|
+
});
|
|
9830
|
+
};
|
|
9831
|
+
}
|
|
9832
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9833
|
+
[draggableNodes]);
|
|
9834
|
+
const bindActivatorToSensorInstantiator = useCallback((handler, sensor) => {
|
|
9835
|
+
return (event, active) => {
|
|
9836
|
+
const nativeEvent = event.nativeEvent;
|
|
9837
|
+
const activeDraggableNode = draggableNodes.get(active);
|
|
9838
|
+
|
|
9839
|
+
if ( // Another sensor is already instantiating
|
|
9840
|
+
activeRef.current !== null || // No active draggable
|
|
9841
|
+
!activeDraggableNode || // Event has already been captured
|
|
9842
|
+
nativeEvent.dndKit || nativeEvent.defaultPrevented) {
|
|
9843
|
+
return;
|
|
9844
|
+
}
|
|
9845
|
+
|
|
9846
|
+
const activationContext = {
|
|
9847
|
+
active: activeDraggableNode
|
|
9848
|
+
};
|
|
9849
|
+
const shouldActivate = handler(event, sensor.options, activationContext);
|
|
9850
|
+
|
|
9851
|
+
if (shouldActivate === true) {
|
|
9852
|
+
nativeEvent.dndKit = {
|
|
9853
|
+
capturedBy: sensor.sensor
|
|
9854
|
+
};
|
|
9855
|
+
activeRef.current = active;
|
|
9856
|
+
instantiateSensor(event, sensor);
|
|
9857
|
+
}
|
|
9858
|
+
};
|
|
9859
|
+
}, [draggableNodes, instantiateSensor]);
|
|
9860
|
+
const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
|
|
9861
|
+
useSensorSetup(sensors);
|
|
9862
|
+
useIsomorphicLayoutEffect(() => {
|
|
9863
|
+
if (activeNodeRect && status === Status.Initializing) {
|
|
9864
|
+
setStatus(Status.Initialized);
|
|
9865
|
+
}
|
|
9866
|
+
}, [activeNodeRect, status]);
|
|
9867
|
+
useEffect(() => {
|
|
9868
|
+
const {
|
|
9869
|
+
onDragMove
|
|
9870
|
+
} = latestProps.current;
|
|
9871
|
+
const {
|
|
9872
|
+
active,
|
|
9873
|
+
activatorEvent,
|
|
9874
|
+
collisions,
|
|
9875
|
+
over
|
|
9876
|
+
} = sensorContext.current;
|
|
9877
|
+
|
|
9878
|
+
if (!active || !activatorEvent) {
|
|
9879
|
+
return;
|
|
9880
|
+
}
|
|
9881
|
+
|
|
9882
|
+
const event = {
|
|
9883
|
+
active,
|
|
9884
|
+
activatorEvent,
|
|
9885
|
+
collisions,
|
|
9886
|
+
delta: {
|
|
9887
|
+
x: scrollAdjustedTranslate.x,
|
|
9888
|
+
y: scrollAdjustedTranslate.y
|
|
9889
|
+
},
|
|
9890
|
+
over
|
|
9891
|
+
};
|
|
9892
|
+
unstable_batchedUpdates(() => {
|
|
9893
|
+
onDragMove == null ? void 0 : onDragMove(event);
|
|
9894
|
+
dispatchMonitorEvent({
|
|
9895
|
+
type: 'onDragMove',
|
|
9896
|
+
event
|
|
9897
|
+
});
|
|
9898
|
+
});
|
|
9899
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9900
|
+
[scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
|
|
9901
|
+
useEffect(() => {
|
|
9902
|
+
const {
|
|
9903
|
+
active,
|
|
9904
|
+
activatorEvent,
|
|
9905
|
+
collisions,
|
|
9906
|
+
droppableContainers,
|
|
9907
|
+
scrollAdjustedTranslate
|
|
9908
|
+
} = sensorContext.current;
|
|
9909
|
+
|
|
9910
|
+
if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
|
|
9911
|
+
return;
|
|
9912
|
+
}
|
|
9913
|
+
|
|
9914
|
+
const {
|
|
9915
|
+
onDragOver
|
|
9916
|
+
} = latestProps.current;
|
|
9917
|
+
const overContainer = droppableContainers.get(overId);
|
|
9918
|
+
const over = overContainer && overContainer.rect.current ? {
|
|
9919
|
+
id: overContainer.id,
|
|
9920
|
+
rect: overContainer.rect.current,
|
|
9921
|
+
data: overContainer.data,
|
|
9922
|
+
disabled: overContainer.disabled
|
|
9923
|
+
} : null;
|
|
9924
|
+
const event = {
|
|
9925
|
+
active,
|
|
9926
|
+
activatorEvent,
|
|
9927
|
+
collisions,
|
|
9928
|
+
delta: {
|
|
9929
|
+
x: scrollAdjustedTranslate.x,
|
|
9930
|
+
y: scrollAdjustedTranslate.y
|
|
9931
|
+
},
|
|
9932
|
+
over
|
|
9933
|
+
};
|
|
9934
|
+
unstable_batchedUpdates(() => {
|
|
9935
|
+
setOver(over);
|
|
9936
|
+
onDragOver == null ? void 0 : onDragOver(event);
|
|
9937
|
+
dispatchMonitorEvent({
|
|
9938
|
+
type: 'onDragOver',
|
|
9939
|
+
event
|
|
9940
|
+
});
|
|
9941
|
+
});
|
|
9942
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9943
|
+
[overId]);
|
|
9944
|
+
useIsomorphicLayoutEffect(() => {
|
|
9945
|
+
sensorContext.current = {
|
|
9946
|
+
activatorEvent,
|
|
9947
|
+
active,
|
|
9948
|
+
activeNode,
|
|
9949
|
+
collisionRect,
|
|
9950
|
+
collisions,
|
|
9951
|
+
droppableRects,
|
|
9952
|
+
draggableNodes,
|
|
9953
|
+
draggingNode,
|
|
9954
|
+
draggingNodeRect,
|
|
9955
|
+
droppableContainers,
|
|
9956
|
+
over,
|
|
9957
|
+
scrollableAncestors,
|
|
9958
|
+
scrollAdjustedTranslate
|
|
9959
|
+
};
|
|
9960
|
+
activeRects.current = {
|
|
9961
|
+
initial: draggingNodeRect,
|
|
9962
|
+
translated: collisionRect
|
|
9963
|
+
};
|
|
9964
|
+
}, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
|
|
9965
|
+
useAutoScroller({ ...autoScrollOptions,
|
|
9966
|
+
delta: translate,
|
|
9967
|
+
draggingRect: collisionRect,
|
|
9968
|
+
pointerCoordinates,
|
|
9969
|
+
scrollableAncestors,
|
|
9970
|
+
scrollableAncestorRects
|
|
9971
|
+
});
|
|
9972
|
+
const publicContext = useMemo(() => {
|
|
9973
|
+
const context = {
|
|
9974
|
+
active,
|
|
9975
|
+
activeNode,
|
|
9976
|
+
activeNodeRect,
|
|
9977
|
+
activatorEvent,
|
|
9978
|
+
collisions,
|
|
9979
|
+
containerNodeRect,
|
|
9980
|
+
dragOverlay,
|
|
9981
|
+
draggableNodes,
|
|
9982
|
+
droppableContainers,
|
|
9983
|
+
droppableRects,
|
|
9984
|
+
over,
|
|
9985
|
+
measureDroppableContainers,
|
|
9986
|
+
scrollableAncestors,
|
|
9987
|
+
scrollableAncestorRects,
|
|
9988
|
+
measuringConfiguration,
|
|
9989
|
+
measuringScheduled,
|
|
9990
|
+
windowRect
|
|
9991
|
+
};
|
|
9992
|
+
return context;
|
|
9993
|
+
}, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
|
|
9994
|
+
const internalContext = useMemo(() => {
|
|
9995
|
+
const context = {
|
|
9996
|
+
activatorEvent,
|
|
9997
|
+
activators,
|
|
9998
|
+
active,
|
|
9999
|
+
activeNodeRect,
|
|
10000
|
+
ariaDescribedById: {
|
|
10001
|
+
draggable: draggableDescribedById
|
|
10002
|
+
},
|
|
10003
|
+
dispatch,
|
|
10004
|
+
draggableNodes,
|
|
10005
|
+
over,
|
|
10006
|
+
measureDroppableContainers
|
|
10007
|
+
};
|
|
10008
|
+
return context;
|
|
10009
|
+
}, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
|
|
10010
|
+
return React.createElement(DndMonitorContext.Provider, {
|
|
10011
|
+
value: registerMonitorListener
|
|
10012
|
+
}, React.createElement(InternalContext.Provider, {
|
|
10013
|
+
value: internalContext
|
|
10014
|
+
}, React.createElement(PublicContext.Provider, {
|
|
10015
|
+
value: publicContext
|
|
10016
|
+
}, React.createElement(ActiveDraggableContext.Provider, {
|
|
10017
|
+
value: transform
|
|
10018
|
+
}, children)), React.createElement(RestoreFocus, {
|
|
10019
|
+
disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
|
|
10020
|
+
})), React.createElement(Accessibility, { ...accessibility,
|
|
10021
|
+
hiddenTextDescribedById: draggableDescribedById
|
|
10022
|
+
}));
|
|
10023
|
+
|
|
10024
|
+
function getAutoScrollerOptions() {
|
|
10025
|
+
const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
|
|
10026
|
+
const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
|
|
10027
|
+
const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
|
|
10028
|
+
|
|
10029
|
+
if (typeof autoScroll === 'object') {
|
|
10030
|
+
return { ...autoScroll,
|
|
10031
|
+
enabled
|
|
10032
|
+
};
|
|
10033
|
+
}
|
|
10034
|
+
|
|
10035
|
+
return {
|
|
10036
|
+
enabled
|
|
10037
|
+
};
|
|
10038
|
+
}
|
|
10039
|
+
});
|
|
10040
|
+
|
|
10041
|
+
const NullContext = /*#__PURE__*/createContext(null);
|
|
10042
|
+
const defaultRole = 'button';
|
|
10043
|
+
const ID_PREFIX$1 = 'Droppable';
|
|
10044
|
+
function useDraggable(_ref) {
|
|
10045
|
+
let {
|
|
10046
|
+
id,
|
|
10047
|
+
data,
|
|
10048
|
+
disabled = false,
|
|
10049
|
+
attributes
|
|
10050
|
+
} = _ref;
|
|
10051
|
+
const key = useUniqueId(ID_PREFIX$1);
|
|
10052
|
+
const {
|
|
10053
|
+
activators,
|
|
10054
|
+
activatorEvent,
|
|
10055
|
+
active,
|
|
10056
|
+
activeNodeRect,
|
|
10057
|
+
ariaDescribedById,
|
|
10058
|
+
draggableNodes,
|
|
10059
|
+
over
|
|
10060
|
+
} = useContext(InternalContext);
|
|
10061
|
+
const {
|
|
10062
|
+
role = defaultRole,
|
|
10063
|
+
roleDescription = 'draggable',
|
|
10064
|
+
tabIndex = 0
|
|
10065
|
+
} = attributes != null ? attributes : {};
|
|
10066
|
+
const isDragging = (active == null ? void 0 : active.id) === id;
|
|
10067
|
+
const transform = useContext(isDragging ? ActiveDraggableContext : NullContext);
|
|
10068
|
+
const [node, setNodeRef] = useNodeRef();
|
|
10069
|
+
const [activatorNode, setActivatorNodeRef] = useNodeRef();
|
|
10070
|
+
const listeners = useSyntheticListeners(activators, id);
|
|
10071
|
+
const dataRef = useLatestValue(data);
|
|
10072
|
+
useIsomorphicLayoutEffect(() => {
|
|
10073
|
+
draggableNodes.set(id, {
|
|
10074
|
+
id,
|
|
10075
|
+
key,
|
|
10076
|
+
node,
|
|
10077
|
+
activatorNode,
|
|
10078
|
+
data: dataRef
|
|
10079
|
+
});
|
|
10080
|
+
return () => {
|
|
10081
|
+
const node = draggableNodes.get(id);
|
|
10082
|
+
|
|
10083
|
+
if (node && node.key === key) {
|
|
10084
|
+
draggableNodes.delete(id);
|
|
10085
|
+
}
|
|
10086
|
+
};
|
|
10087
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10088
|
+
[draggableNodes, id]);
|
|
10089
|
+
const memoizedAttributes = useMemo(() => ({
|
|
10090
|
+
role,
|
|
10091
|
+
tabIndex,
|
|
10092
|
+
'aria-disabled': disabled,
|
|
10093
|
+
'aria-pressed': isDragging && role === defaultRole ? true : undefined,
|
|
10094
|
+
'aria-roledescription': roleDescription,
|
|
10095
|
+
'aria-describedby': ariaDescribedById.draggable
|
|
10096
|
+
}), [disabled, role, tabIndex, isDragging, roleDescription, ariaDescribedById.draggable]);
|
|
10097
|
+
return {
|
|
10098
|
+
active,
|
|
10099
|
+
activatorEvent,
|
|
10100
|
+
activeNodeRect,
|
|
10101
|
+
attributes: memoizedAttributes,
|
|
10102
|
+
isDragging,
|
|
10103
|
+
listeners: disabled ? undefined : listeners,
|
|
10104
|
+
node,
|
|
10105
|
+
over,
|
|
10106
|
+
setNodeRef,
|
|
10107
|
+
setActivatorNodeRef,
|
|
10108
|
+
transform
|
|
10109
|
+
};
|
|
10110
|
+
}
|
|
10111
|
+
|
|
10112
|
+
function useDndContext() {
|
|
10113
|
+
return useContext(PublicContext);
|
|
10114
|
+
}
|
|
10115
|
+
|
|
10116
|
+
const ID_PREFIX$1$1 = 'Droppable';
|
|
10117
|
+
const defaultResizeObserverConfig = {
|
|
10118
|
+
timeout: 25
|
|
10119
|
+
};
|
|
10120
|
+
function useDroppable(_ref) {
|
|
10121
|
+
let {
|
|
10122
|
+
data,
|
|
10123
|
+
disabled = false,
|
|
10124
|
+
id,
|
|
10125
|
+
resizeObserverConfig
|
|
10126
|
+
} = _ref;
|
|
10127
|
+
const key = useUniqueId(ID_PREFIX$1$1);
|
|
10128
|
+
const {
|
|
10129
|
+
active,
|
|
10130
|
+
dispatch,
|
|
10131
|
+
over,
|
|
10132
|
+
measureDroppableContainers
|
|
10133
|
+
} = useContext(InternalContext);
|
|
10134
|
+
const previous = useRef({
|
|
10135
|
+
disabled
|
|
10136
|
+
});
|
|
10137
|
+
const resizeObserverConnected = useRef(false);
|
|
10138
|
+
const rect = useRef(null);
|
|
10139
|
+
const callbackId = useRef(null);
|
|
10140
|
+
const {
|
|
10141
|
+
disabled: resizeObserverDisabled,
|
|
10142
|
+
updateMeasurementsFor,
|
|
10143
|
+
timeout: resizeObserverTimeout
|
|
10144
|
+
} = { ...defaultResizeObserverConfig,
|
|
10145
|
+
...resizeObserverConfig
|
|
10146
|
+
};
|
|
10147
|
+
const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
|
|
10148
|
+
const handleResize = useCallback(() => {
|
|
10149
|
+
if (!resizeObserverConnected.current) {
|
|
10150
|
+
// ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
|
|
10151
|
+
// assuming the element is rendered and displayed.
|
|
10152
|
+
resizeObserverConnected.current = true;
|
|
10153
|
+
return;
|
|
10154
|
+
}
|
|
10155
|
+
|
|
10156
|
+
if (callbackId.current != null) {
|
|
10157
|
+
clearTimeout(callbackId.current);
|
|
10158
|
+
}
|
|
10159
|
+
|
|
10160
|
+
callbackId.current = setTimeout(() => {
|
|
10161
|
+
measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
|
|
10162
|
+
callbackId.current = null;
|
|
10163
|
+
}, resizeObserverTimeout);
|
|
10164
|
+
}, //eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10165
|
+
[resizeObserverTimeout]);
|
|
10166
|
+
const resizeObserver = useResizeObserver({
|
|
10167
|
+
callback: handleResize,
|
|
10168
|
+
disabled: resizeObserverDisabled || !active
|
|
10169
|
+
});
|
|
10170
|
+
const handleNodeChange = useCallback((newElement, previousElement) => {
|
|
10171
|
+
if (!resizeObserver) {
|
|
10172
|
+
return;
|
|
10173
|
+
}
|
|
10174
|
+
|
|
10175
|
+
if (previousElement) {
|
|
10176
|
+
resizeObserver.unobserve(previousElement);
|
|
10177
|
+
resizeObserverConnected.current = false;
|
|
10178
|
+
}
|
|
10179
|
+
|
|
10180
|
+
if (newElement) {
|
|
10181
|
+
resizeObserver.observe(newElement);
|
|
10182
|
+
}
|
|
10183
|
+
}, [resizeObserver]);
|
|
10184
|
+
const [nodeRef, setNodeRef] = useNodeRef(handleNodeChange);
|
|
10185
|
+
const dataRef = useLatestValue(data);
|
|
10186
|
+
useEffect(() => {
|
|
10187
|
+
if (!resizeObserver || !nodeRef.current) {
|
|
10188
|
+
return;
|
|
10189
|
+
}
|
|
10190
|
+
|
|
10191
|
+
resizeObserver.disconnect();
|
|
10192
|
+
resizeObserverConnected.current = false;
|
|
10193
|
+
resizeObserver.observe(nodeRef.current);
|
|
10194
|
+
}, [nodeRef, resizeObserver]);
|
|
10195
|
+
useIsomorphicLayoutEffect(() => {
|
|
10196
|
+
dispatch({
|
|
10197
|
+
type: Action.RegisterDroppable,
|
|
10198
|
+
element: {
|
|
10199
|
+
id,
|
|
10200
|
+
key,
|
|
10201
|
+
disabled,
|
|
10202
|
+
node: nodeRef,
|
|
10203
|
+
rect,
|
|
10204
|
+
data: dataRef
|
|
10205
|
+
}
|
|
10206
|
+
});
|
|
10207
|
+
return () => dispatch({
|
|
10208
|
+
type: Action.UnregisterDroppable,
|
|
10209
|
+
key,
|
|
10210
|
+
id
|
|
10211
|
+
});
|
|
10212
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10213
|
+
[id]);
|
|
10214
|
+
useEffect(() => {
|
|
10215
|
+
if (disabled !== previous.current.disabled) {
|
|
10216
|
+
dispatch({
|
|
10217
|
+
type: Action.SetDroppableDisabled,
|
|
10218
|
+
id,
|
|
10219
|
+
key,
|
|
10220
|
+
disabled
|
|
10221
|
+
});
|
|
10222
|
+
previous.current.disabled = disabled;
|
|
10223
|
+
}
|
|
10224
|
+
}, [id, key, disabled, dispatch]);
|
|
10225
|
+
return {
|
|
10226
|
+
active,
|
|
10227
|
+
rect,
|
|
10228
|
+
isOver: (over == null ? void 0 : over.id) === id,
|
|
10229
|
+
node: nodeRef,
|
|
10230
|
+
over,
|
|
10231
|
+
setNodeRef
|
|
10232
|
+
};
|
|
10233
|
+
}
|
|
10234
|
+
|
|
10235
|
+
/**
|
|
10236
|
+
* Move an array item to a different position. Returns a new array with the item moved to the new position.
|
|
10237
|
+
*/
|
|
10238
|
+
function arrayMove(array, from, to) {
|
|
10239
|
+
const newArray = array.slice();
|
|
10240
|
+
newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
|
|
10241
|
+
return newArray;
|
|
10242
|
+
}
|
|
10243
|
+
|
|
10244
|
+
function getSortedRects(items, rects) {
|
|
10245
|
+
return items.reduce((accumulator, id, index) => {
|
|
10246
|
+
const rect = rects.get(id);
|
|
10247
|
+
|
|
10248
|
+
if (rect) {
|
|
10249
|
+
accumulator[index] = rect;
|
|
10250
|
+
}
|
|
10251
|
+
|
|
10252
|
+
return accumulator;
|
|
10253
|
+
}, Array(items.length));
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10256
|
+
function isValidIndex(index) {
|
|
10257
|
+
return index !== null && index >= 0;
|
|
10258
|
+
}
|
|
10259
|
+
|
|
10260
|
+
function itemsEqual(a, b) {
|
|
10261
|
+
if (a === b) {
|
|
10262
|
+
return true;
|
|
10263
|
+
}
|
|
10264
|
+
|
|
10265
|
+
if (a.length !== b.length) {
|
|
10266
|
+
return false;
|
|
10267
|
+
}
|
|
10268
|
+
|
|
10269
|
+
for (let i = 0; i < a.length; i++) {
|
|
10270
|
+
if (a[i] !== b[i]) {
|
|
10271
|
+
return false;
|
|
10272
|
+
}
|
|
10273
|
+
}
|
|
10274
|
+
|
|
10275
|
+
return true;
|
|
10276
|
+
}
|
|
10277
|
+
|
|
10278
|
+
function normalizeDisabled(disabled) {
|
|
10279
|
+
if (typeof disabled === 'boolean') {
|
|
10280
|
+
return {
|
|
10281
|
+
draggable: disabled,
|
|
10282
|
+
droppable: disabled
|
|
10283
|
+
};
|
|
10284
|
+
}
|
|
10285
|
+
|
|
10286
|
+
return disabled;
|
|
10287
|
+
}
|
|
10288
|
+
|
|
10289
|
+
const rectSortingStrategy = _ref => {
|
|
10290
|
+
let {
|
|
10291
|
+
rects,
|
|
10292
|
+
activeIndex,
|
|
10293
|
+
overIndex,
|
|
10294
|
+
index
|
|
10295
|
+
} = _ref;
|
|
10296
|
+
const newRects = arrayMove(rects, overIndex, activeIndex);
|
|
10297
|
+
const oldRect = rects[index];
|
|
10298
|
+
const newRect = newRects[index];
|
|
10299
|
+
|
|
10300
|
+
if (!newRect || !oldRect) {
|
|
10301
|
+
return null;
|
|
10302
|
+
}
|
|
10303
|
+
|
|
10304
|
+
return {
|
|
10305
|
+
x: newRect.left - oldRect.left,
|
|
10306
|
+
y: newRect.top - oldRect.top,
|
|
10307
|
+
scaleX: newRect.width / oldRect.width,
|
|
10308
|
+
scaleY: newRect.height / oldRect.height
|
|
10309
|
+
};
|
|
10310
|
+
};
|
|
10311
|
+
|
|
10312
|
+
// To-do: We should be calculating scale transformation
|
|
10313
|
+
const defaultScale$1 = {
|
|
10314
|
+
scaleX: 1,
|
|
10315
|
+
scaleY: 1
|
|
10316
|
+
};
|
|
10317
|
+
const verticalListSortingStrategy = _ref => {
|
|
10318
|
+
var _rects$activeIndex;
|
|
10319
|
+
|
|
10320
|
+
let {
|
|
10321
|
+
activeIndex,
|
|
10322
|
+
activeNodeRect: fallbackActiveRect,
|
|
10323
|
+
index,
|
|
10324
|
+
rects,
|
|
10325
|
+
overIndex
|
|
10326
|
+
} = _ref;
|
|
10327
|
+
const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
|
|
10328
|
+
|
|
10329
|
+
if (!activeNodeRect) {
|
|
10330
|
+
return null;
|
|
10331
|
+
}
|
|
10332
|
+
|
|
10333
|
+
if (index === activeIndex) {
|
|
10334
|
+
const overIndexRect = rects[overIndex];
|
|
10335
|
+
|
|
10336
|
+
if (!overIndexRect) {
|
|
10337
|
+
return null;
|
|
10338
|
+
}
|
|
10339
|
+
|
|
10340
|
+
return {
|
|
10341
|
+
x: 0,
|
|
10342
|
+
y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
|
|
10343
|
+
...defaultScale$1
|
|
10344
|
+
};
|
|
10345
|
+
}
|
|
10346
|
+
|
|
10347
|
+
const itemGap = getItemGap$1(rects, index, activeIndex);
|
|
10348
|
+
|
|
10349
|
+
if (index > activeIndex && index <= overIndex) {
|
|
10350
|
+
return {
|
|
10351
|
+
x: 0,
|
|
10352
|
+
y: -activeNodeRect.height - itemGap,
|
|
10353
|
+
...defaultScale$1
|
|
10354
|
+
};
|
|
10355
|
+
}
|
|
10356
|
+
|
|
10357
|
+
if (index < activeIndex && index >= overIndex) {
|
|
10358
|
+
return {
|
|
10359
|
+
x: 0,
|
|
10360
|
+
y: activeNodeRect.height + itemGap,
|
|
10361
|
+
...defaultScale$1
|
|
10362
|
+
};
|
|
10363
|
+
}
|
|
10364
|
+
|
|
10365
|
+
return {
|
|
10366
|
+
x: 0,
|
|
10367
|
+
y: 0,
|
|
10368
|
+
...defaultScale$1
|
|
10369
|
+
};
|
|
10370
|
+
};
|
|
10371
|
+
|
|
10372
|
+
function getItemGap$1(clientRects, index, activeIndex) {
|
|
10373
|
+
const currentRect = clientRects[index];
|
|
10374
|
+
const previousRect = clientRects[index - 1];
|
|
10375
|
+
const nextRect = clientRects[index + 1];
|
|
10376
|
+
|
|
10377
|
+
if (!currentRect) {
|
|
10378
|
+
return 0;
|
|
10379
|
+
}
|
|
10380
|
+
|
|
10381
|
+
if (activeIndex < index) {
|
|
10382
|
+
return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
|
|
10383
|
+
}
|
|
10384
|
+
|
|
10385
|
+
return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
|
|
10386
|
+
}
|
|
10387
|
+
|
|
10388
|
+
const ID_PREFIX = 'Sortable';
|
|
10389
|
+
const Context = /*#__PURE__*/React.createContext({
|
|
10390
|
+
activeIndex: -1,
|
|
10391
|
+
containerId: ID_PREFIX,
|
|
10392
|
+
disableTransforms: false,
|
|
10393
|
+
items: [],
|
|
10394
|
+
overIndex: -1,
|
|
10395
|
+
useDragOverlay: false,
|
|
10396
|
+
sortedRects: [],
|
|
10397
|
+
strategy: rectSortingStrategy,
|
|
10398
|
+
disabled: {
|
|
10399
|
+
draggable: false,
|
|
10400
|
+
droppable: false
|
|
10401
|
+
}
|
|
10402
|
+
});
|
|
10403
|
+
function SortableContext(_ref) {
|
|
10404
|
+
let {
|
|
10405
|
+
children,
|
|
10406
|
+
id,
|
|
10407
|
+
items: userDefinedItems,
|
|
10408
|
+
strategy = rectSortingStrategy,
|
|
10409
|
+
disabled: disabledProp = false
|
|
10410
|
+
} = _ref;
|
|
10411
|
+
const {
|
|
10412
|
+
active,
|
|
10413
|
+
dragOverlay,
|
|
10414
|
+
droppableRects,
|
|
10415
|
+
over,
|
|
10416
|
+
measureDroppableContainers
|
|
10417
|
+
} = useDndContext();
|
|
10418
|
+
const containerId = useUniqueId(ID_PREFIX, id);
|
|
10419
|
+
const useDragOverlay = Boolean(dragOverlay.rect !== null);
|
|
10420
|
+
const items = useMemo(() => userDefinedItems.map(item => typeof item === 'object' && 'id' in item ? item.id : item), [userDefinedItems]);
|
|
10421
|
+
const isDragging = active != null;
|
|
10422
|
+
const activeIndex = active ? items.indexOf(active.id) : -1;
|
|
10423
|
+
const overIndex = over ? items.indexOf(over.id) : -1;
|
|
10424
|
+
const previousItemsRef = useRef(items);
|
|
10425
|
+
const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
|
|
10426
|
+
const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
|
|
10427
|
+
const disabled = normalizeDisabled(disabledProp);
|
|
10428
|
+
useIsomorphicLayoutEffect(() => {
|
|
10429
|
+
if (itemsHaveChanged && isDragging) {
|
|
10430
|
+
measureDroppableContainers(items);
|
|
10431
|
+
}
|
|
10432
|
+
}, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
|
|
10433
|
+
useEffect(() => {
|
|
10434
|
+
previousItemsRef.current = items;
|
|
10435
|
+
}, [items]);
|
|
10436
|
+
const contextValue = useMemo(() => ({
|
|
10437
|
+
activeIndex,
|
|
10438
|
+
containerId,
|
|
10439
|
+
disabled,
|
|
10440
|
+
disableTransforms,
|
|
10441
|
+
items,
|
|
10442
|
+
overIndex,
|
|
10443
|
+
useDragOverlay,
|
|
10444
|
+
sortedRects: getSortedRects(items, droppableRects),
|
|
10445
|
+
strategy
|
|
10446
|
+
}), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10447
|
+
[activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]);
|
|
10448
|
+
return React.createElement(Context.Provider, {
|
|
10449
|
+
value: contextValue
|
|
10450
|
+
}, children);
|
|
10451
|
+
}
|
|
10452
|
+
|
|
10453
|
+
const defaultNewIndexGetter = _ref => {
|
|
10454
|
+
let {
|
|
10455
|
+
id,
|
|
10456
|
+
items,
|
|
10457
|
+
activeIndex,
|
|
10458
|
+
overIndex
|
|
10459
|
+
} = _ref;
|
|
10460
|
+
return arrayMove(items, activeIndex, overIndex).indexOf(id);
|
|
10461
|
+
};
|
|
10462
|
+
const defaultAnimateLayoutChanges = _ref2 => {
|
|
10463
|
+
let {
|
|
10464
|
+
containerId,
|
|
10465
|
+
isSorting,
|
|
10466
|
+
wasDragging,
|
|
10467
|
+
index,
|
|
10468
|
+
items,
|
|
10469
|
+
newIndex,
|
|
10470
|
+
previousItems,
|
|
10471
|
+
previousContainerId,
|
|
10472
|
+
transition
|
|
10473
|
+
} = _ref2;
|
|
10474
|
+
|
|
10475
|
+
if (!transition || !wasDragging) {
|
|
10476
|
+
return false;
|
|
10477
|
+
}
|
|
10478
|
+
|
|
10479
|
+
if (previousItems !== items && index === newIndex) {
|
|
10480
|
+
return false;
|
|
10481
|
+
}
|
|
10482
|
+
|
|
10483
|
+
if (isSorting) {
|
|
10484
|
+
return true;
|
|
10485
|
+
}
|
|
10486
|
+
|
|
10487
|
+
return newIndex !== index && containerId === previousContainerId;
|
|
10488
|
+
};
|
|
10489
|
+
const defaultTransition = {
|
|
10490
|
+
duration: 200,
|
|
10491
|
+
easing: 'ease'
|
|
10492
|
+
};
|
|
10493
|
+
const transitionProperty = 'transform';
|
|
10494
|
+
const disabledTransition = /*#__PURE__*/CSS.Transition.toString({
|
|
10495
|
+
property: transitionProperty,
|
|
10496
|
+
duration: 0,
|
|
10497
|
+
easing: 'linear'
|
|
10498
|
+
});
|
|
10499
|
+
const defaultAttributes = {
|
|
10500
|
+
roleDescription: 'sortable'
|
|
10501
|
+
};
|
|
10502
|
+
|
|
10503
|
+
/*
|
|
10504
|
+
* When the index of an item changes while sorting,
|
|
10505
|
+
* we need to temporarily disable the transforms
|
|
10506
|
+
*/
|
|
10507
|
+
|
|
10508
|
+
function useDerivedTransform(_ref) {
|
|
10509
|
+
let {
|
|
10510
|
+
disabled,
|
|
10511
|
+
index,
|
|
10512
|
+
node,
|
|
10513
|
+
rect
|
|
10514
|
+
} = _ref;
|
|
10515
|
+
const [derivedTransform, setDerivedtransform] = useState(null);
|
|
10516
|
+
const previousIndex = useRef(index);
|
|
10517
|
+
useIsomorphicLayoutEffect(() => {
|
|
10518
|
+
if (!disabled && index !== previousIndex.current && node.current) {
|
|
10519
|
+
const initial = rect.current;
|
|
10520
|
+
|
|
10521
|
+
if (initial) {
|
|
10522
|
+
const current = getClientRect(node.current, {
|
|
10523
|
+
ignoreTransform: true
|
|
10524
|
+
});
|
|
10525
|
+
const delta = {
|
|
10526
|
+
x: initial.left - current.left,
|
|
10527
|
+
y: initial.top - current.top,
|
|
10528
|
+
scaleX: initial.width / current.width,
|
|
10529
|
+
scaleY: initial.height / current.height
|
|
10530
|
+
};
|
|
10531
|
+
|
|
10532
|
+
if (delta.x || delta.y) {
|
|
10533
|
+
setDerivedtransform(delta);
|
|
10534
|
+
}
|
|
10535
|
+
}
|
|
10536
|
+
}
|
|
10537
|
+
|
|
10538
|
+
if (index !== previousIndex.current) {
|
|
10539
|
+
previousIndex.current = index;
|
|
10540
|
+
}
|
|
10541
|
+
}, [disabled, index, node, rect]);
|
|
10542
|
+
useEffect(() => {
|
|
10543
|
+
if (derivedTransform) {
|
|
10544
|
+
setDerivedtransform(null);
|
|
10545
|
+
}
|
|
10546
|
+
}, [derivedTransform]);
|
|
10547
|
+
return derivedTransform;
|
|
10548
|
+
}
|
|
10549
|
+
|
|
10550
|
+
function useSortable(_ref) {
|
|
10551
|
+
let {
|
|
10552
|
+
animateLayoutChanges = defaultAnimateLayoutChanges,
|
|
10553
|
+
attributes: userDefinedAttributes,
|
|
10554
|
+
disabled: localDisabled,
|
|
10555
|
+
data: customData,
|
|
10556
|
+
getNewIndex = defaultNewIndexGetter,
|
|
10557
|
+
id,
|
|
10558
|
+
strategy: localStrategy,
|
|
10559
|
+
resizeObserverConfig,
|
|
10560
|
+
transition = defaultTransition
|
|
10561
|
+
} = _ref;
|
|
10562
|
+
const {
|
|
10563
|
+
items,
|
|
10564
|
+
containerId,
|
|
10565
|
+
activeIndex,
|
|
10566
|
+
disabled: globalDisabled,
|
|
10567
|
+
disableTransforms,
|
|
10568
|
+
sortedRects,
|
|
10569
|
+
overIndex,
|
|
10570
|
+
useDragOverlay,
|
|
10571
|
+
strategy: globalStrategy
|
|
10572
|
+
} = useContext(Context);
|
|
10573
|
+
const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
|
|
10574
|
+
const index = items.indexOf(id);
|
|
10575
|
+
const data = useMemo(() => ({
|
|
10576
|
+
sortable: {
|
|
10577
|
+
containerId,
|
|
10578
|
+
index,
|
|
10579
|
+
items
|
|
10580
|
+
},
|
|
10581
|
+
...customData
|
|
10582
|
+
}), [containerId, customData, index, items]);
|
|
10583
|
+
const itemsAfterCurrentSortable = useMemo(() => items.slice(items.indexOf(id)), [items, id]);
|
|
10584
|
+
const {
|
|
10585
|
+
rect,
|
|
10586
|
+
node,
|
|
10587
|
+
isOver,
|
|
10588
|
+
setNodeRef: setDroppableNodeRef
|
|
10589
|
+
} = useDroppable({
|
|
10590
|
+
id,
|
|
10591
|
+
data,
|
|
10592
|
+
disabled: disabled.droppable,
|
|
10593
|
+
resizeObserverConfig: {
|
|
10594
|
+
updateMeasurementsFor: itemsAfterCurrentSortable,
|
|
10595
|
+
...resizeObserverConfig
|
|
10596
|
+
}
|
|
10597
|
+
});
|
|
10598
|
+
const {
|
|
10599
|
+
active,
|
|
10600
|
+
activatorEvent,
|
|
10601
|
+
activeNodeRect,
|
|
10602
|
+
attributes,
|
|
10603
|
+
setNodeRef: setDraggableNodeRef,
|
|
10604
|
+
listeners,
|
|
10605
|
+
isDragging,
|
|
10606
|
+
over,
|
|
10607
|
+
setActivatorNodeRef,
|
|
10608
|
+
transform
|
|
10609
|
+
} = useDraggable({
|
|
10610
|
+
id,
|
|
10611
|
+
data,
|
|
10612
|
+
attributes: { ...defaultAttributes,
|
|
10613
|
+
...userDefinedAttributes
|
|
10614
|
+
},
|
|
10615
|
+
disabled: disabled.draggable
|
|
10616
|
+
});
|
|
10617
|
+
const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
|
|
10618
|
+
const isSorting = Boolean(active);
|
|
10619
|
+
const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
|
|
10620
|
+
const shouldDisplaceDragSource = !useDragOverlay && isDragging;
|
|
10621
|
+
const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
|
|
10622
|
+
const strategy = localStrategy != null ? localStrategy : globalStrategy;
|
|
10623
|
+
const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
|
|
10624
|
+
rects: sortedRects,
|
|
10625
|
+
activeNodeRect,
|
|
10626
|
+
activeIndex,
|
|
10627
|
+
overIndex,
|
|
10628
|
+
index
|
|
10629
|
+
}) : null;
|
|
10630
|
+
const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
|
|
10631
|
+
id,
|
|
10632
|
+
items,
|
|
10633
|
+
activeIndex,
|
|
10634
|
+
overIndex
|
|
10635
|
+
}) : index;
|
|
10636
|
+
const activeId = active == null ? void 0 : active.id;
|
|
10637
|
+
const previous = useRef({
|
|
10638
|
+
activeId,
|
|
10639
|
+
items,
|
|
10640
|
+
newIndex,
|
|
10641
|
+
containerId
|
|
10642
|
+
});
|
|
10643
|
+
const itemsHaveChanged = items !== previous.current.items;
|
|
10644
|
+
const shouldAnimateLayoutChanges = animateLayoutChanges({
|
|
10645
|
+
active,
|
|
10646
|
+
containerId,
|
|
10647
|
+
isDragging,
|
|
10648
|
+
isSorting,
|
|
10649
|
+
id,
|
|
10650
|
+
index,
|
|
10651
|
+
items,
|
|
10652
|
+
newIndex: previous.current.newIndex,
|
|
10653
|
+
previousItems: previous.current.items,
|
|
10654
|
+
previousContainerId: previous.current.containerId,
|
|
10655
|
+
transition,
|
|
10656
|
+
wasDragging: previous.current.activeId != null
|
|
10657
|
+
});
|
|
10658
|
+
const derivedTransform = useDerivedTransform({
|
|
10659
|
+
disabled: !shouldAnimateLayoutChanges,
|
|
10660
|
+
index,
|
|
10661
|
+
node,
|
|
10662
|
+
rect
|
|
10663
|
+
});
|
|
10664
|
+
useEffect(() => {
|
|
10665
|
+
if (isSorting && previous.current.newIndex !== newIndex) {
|
|
10666
|
+
previous.current.newIndex = newIndex;
|
|
10667
|
+
}
|
|
10668
|
+
|
|
10669
|
+
if (containerId !== previous.current.containerId) {
|
|
10670
|
+
previous.current.containerId = containerId;
|
|
10671
|
+
}
|
|
10672
|
+
|
|
10673
|
+
if (items !== previous.current.items) {
|
|
10674
|
+
previous.current.items = items;
|
|
10675
|
+
}
|
|
10676
|
+
}, [isSorting, newIndex, containerId, items]);
|
|
10677
|
+
useEffect(() => {
|
|
10678
|
+
if (activeId === previous.current.activeId) {
|
|
10679
|
+
return;
|
|
10680
|
+
}
|
|
10681
|
+
|
|
10682
|
+
if (activeId && !previous.current.activeId) {
|
|
10683
|
+
previous.current.activeId = activeId;
|
|
10684
|
+
return;
|
|
10685
|
+
}
|
|
10686
|
+
|
|
10687
|
+
const timeoutId = setTimeout(() => {
|
|
10688
|
+
previous.current.activeId = activeId;
|
|
10689
|
+
}, 50);
|
|
10690
|
+
return () => clearTimeout(timeoutId);
|
|
10691
|
+
}, [activeId]);
|
|
10692
|
+
return {
|
|
10693
|
+
active,
|
|
10694
|
+
activeIndex,
|
|
10695
|
+
attributes,
|
|
10696
|
+
data,
|
|
10697
|
+
rect,
|
|
10698
|
+
index,
|
|
10699
|
+
newIndex,
|
|
10700
|
+
items,
|
|
10701
|
+
isOver,
|
|
10702
|
+
isSorting,
|
|
10703
|
+
isDragging,
|
|
10704
|
+
listeners,
|
|
10705
|
+
node,
|
|
10706
|
+
overIndex,
|
|
10707
|
+
over,
|
|
10708
|
+
setNodeRef,
|
|
10709
|
+
setActivatorNodeRef,
|
|
10710
|
+
setDroppableNodeRef,
|
|
10711
|
+
setDraggableNodeRef,
|
|
10712
|
+
transform: derivedTransform != null ? derivedTransform : finalTransform,
|
|
10713
|
+
transition: getTransition()
|
|
10714
|
+
};
|
|
10715
|
+
|
|
10716
|
+
function getTransition() {
|
|
10717
|
+
if ( // Temporarily disable transitions for a single frame to set up derived transforms
|
|
10718
|
+
derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
|
|
10719
|
+
itemsHaveChanged && previous.current.newIndex === index) {
|
|
10720
|
+
return disabledTransition;
|
|
10721
|
+
}
|
|
10722
|
+
|
|
10723
|
+
if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
|
|
10724
|
+
return undefined;
|
|
10725
|
+
}
|
|
10726
|
+
|
|
10727
|
+
if (isSorting || shouldAnimateLayoutChanges) {
|
|
10728
|
+
return CSS.Transition.toString({ ...transition,
|
|
10729
|
+
property: transitionProperty
|
|
10730
|
+
});
|
|
10731
|
+
}
|
|
10732
|
+
|
|
10733
|
+
return undefined;
|
|
10734
|
+
}
|
|
10735
|
+
}
|
|
10736
|
+
|
|
10737
|
+
function normalizeLocalDisabled(localDisabled, globalDisabled) {
|
|
10738
|
+
var _localDisabled$dragga, _localDisabled$droppa;
|
|
10739
|
+
|
|
10740
|
+
if (typeof localDisabled === 'boolean') {
|
|
10741
|
+
return {
|
|
10742
|
+
draggable: localDisabled,
|
|
10743
|
+
// Backwards compatibility
|
|
10744
|
+
droppable: false
|
|
10745
|
+
};
|
|
10746
|
+
}
|
|
10747
|
+
|
|
10748
|
+
return {
|
|
10749
|
+
draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
|
|
10750
|
+
droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
|
|
10751
|
+
};
|
|
10752
|
+
}
|
|
10753
|
+
|
|
10754
|
+
[KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
|
|
10755
|
+
|
|
10756
|
+
var FieldBlock = function FieldBlock(_ref) {
|
|
10757
|
+
var field = _ref.field,
|
|
10758
|
+
index = _ref.index,
|
|
10759
|
+
fields = _ref.fields;
|
|
10760
|
+
var systemFieldsCount = countBy({
|
|
10761
|
+
isSystem: true
|
|
10762
|
+
}, fields);
|
|
10763
|
+
var _useSortable = useSortable({
|
|
10764
|
+
id: field.id,
|
|
10765
|
+
data: {
|
|
10766
|
+
index: index
|
|
10767
|
+
}
|
|
10768
|
+
}),
|
|
10769
|
+
attributes = _useSortable.attributes,
|
|
10770
|
+
listeners = _useSortable.listeners,
|
|
10771
|
+
setNodeRef = _useSortable.setNodeRef,
|
|
10772
|
+
transform = _useSortable.transform;
|
|
10773
|
+
var style = {
|
|
10774
|
+
transform: CSS.Transform.toString(transform)
|
|
10775
|
+
};
|
|
10776
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
10777
|
+
ref: setNodeRef,
|
|
10778
|
+
style: style
|
|
10779
|
+
}, attributes, listeners, {
|
|
10780
|
+
className: "neeto-ui-text-gray-800 mb-3 flex items-center space-x-4 font-medium"
|
|
10781
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
10782
|
+
className: "neeto-ui-bg-gray-100 neeto-ui-text-gray-700 neeto-ui-rounded-sm flex h-6 w-6 flex-shrink-0 items-center justify-center p-1"
|
|
10783
|
+
}, index - systemFieldsCount + 1), /*#__PURE__*/React.createElement("div", {
|
|
10784
|
+
className: "neeto-ui-border-gray-400 neeto-ui-bg-white neeto-ui-rounded neeto-ui-shadow-xs flex w-96 items-center space-x-4 border border-solid p-3"
|
|
10785
|
+
}, /*#__PURE__*/React.createElement(Reorder, null), /*#__PURE__*/React.createElement("div", null, field.name)));
|
|
10786
|
+
};
|
|
10787
|
+
var FieldBlock$1 = /*#__PURE__*/React.memo(FieldBlock);
|
|
10788
|
+
|
|
10789
|
+
var ReorderPane = function ReorderPane(_ref) {
|
|
10790
|
+
var isOpen = _ref.isOpen,
|
|
10791
|
+
onClose = _ref.onClose,
|
|
10792
|
+
allFields = _ref.allFields;
|
|
10793
|
+
var _useState = useState([]),
|
|
10794
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
10795
|
+
fields = _useState2[0],
|
|
10796
|
+
setFields = _useState2[1];
|
|
10797
|
+
var initialStateRef = useRef([]);
|
|
10798
|
+
var _useTranslation = useTranslation(),
|
|
10799
|
+
t = _useTranslation.t;
|
|
10800
|
+
var _useReorderFields = useReorderFields(),
|
|
10801
|
+
reorderField = _useReorderFields.mutate,
|
|
10802
|
+
isSubmitting = _useReorderFields.isLoading;
|
|
10803
|
+
var handleDragEnd = function handleDragEnd(_ref2) {
|
|
10804
|
+
var active = _ref2.active,
|
|
10805
|
+
over = _ref2.over;
|
|
10806
|
+
if (active.id !== over.id) {
|
|
10807
|
+
setFields(function (fields) {
|
|
10808
|
+
return arrayMove(fields, active.data.current.index, over.data.current.index);
|
|
10809
|
+
});
|
|
10810
|
+
}
|
|
10811
|
+
};
|
|
10812
|
+
var handleReorderSave = function handleReorderSave() {
|
|
10813
|
+
var params = [];
|
|
10814
|
+
fields.map(function (field, index) {
|
|
10815
|
+
return field.id !== allFields[index].id && params.push({
|
|
10816
|
+
id: field.id,
|
|
10817
|
+
displayOrder: index
|
|
10818
|
+
});
|
|
10819
|
+
});
|
|
10820
|
+
reorderField({
|
|
10821
|
+
fields: params
|
|
10822
|
+
}, {
|
|
10823
|
+
onSuccess: onClose
|
|
10824
|
+
});
|
|
10825
|
+
};
|
|
10826
|
+
useEffect(function () {
|
|
10827
|
+
setFields(allFields);
|
|
10828
|
+
initialStateRef.current = allFields;
|
|
10829
|
+
}, [allFields]);
|
|
10830
|
+
return /*#__PURE__*/React.createElement(Pane, {
|
|
10831
|
+
isOpen: isOpen,
|
|
10832
|
+
onClose: onClose
|
|
10833
|
+
}, /*#__PURE__*/React.createElement(Pane.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
10834
|
+
style: "h2",
|
|
10835
|
+
weight: "semibold"
|
|
10836
|
+
}, t("titles.reorderFields"))), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(Typography, {
|
|
10837
|
+
className: "mb-3",
|
|
10838
|
+
style: "body2"
|
|
10839
|
+
}, t("messages.reorderFields")), /*#__PURE__*/React.createElement("div", {
|
|
10840
|
+
className: "flex flex-col items-center"
|
|
10841
|
+
}, /*#__PURE__*/React.createElement(DndContext, {
|
|
10842
|
+
collisionDetection: closestCenter,
|
|
10843
|
+
onDragEnd: handleDragEnd
|
|
10844
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
10845
|
+
items: fields,
|
|
10846
|
+
strategy: verticalListSortingStrategy
|
|
10847
|
+
}, fields.map(function (field, index) {
|
|
10848
|
+
if (field.isSystem) return null;
|
|
10849
|
+
return /*#__PURE__*/React.createElement(FieldBlock$1, {
|
|
10850
|
+
field: field,
|
|
10851
|
+
fields: fields,
|
|
10852
|
+
index: index,
|
|
10853
|
+
key: index
|
|
10854
|
+
});
|
|
10855
|
+
}))))), /*#__PURE__*/React.createElement(Pane.Footer, {
|
|
10856
|
+
className: "flex items-center space-x-2"
|
|
10857
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
10858
|
+
disabled: initialStateRef.current === fields,
|
|
10859
|
+
label: t("labels.saveChanges"),
|
|
10860
|
+
loading: isSubmitting,
|
|
10861
|
+
onClick: handleReorderSave
|
|
10862
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
10863
|
+
label: t("labels.cancel"),
|
|
10864
|
+
style: "text",
|
|
10865
|
+
onClick: onClose
|
|
10866
|
+
})));
|
|
10867
|
+
};
|
|
10868
|
+
|
|
10869
|
+
var Menu = Dropdown.Menu,
|
|
10870
|
+
MenuItem = Dropdown.MenuItem;
|
|
10871
|
+
var buildDefaultColumns = function buildDefaultColumns(_ref) {
|
|
10872
|
+
var onDeleteClick = _ref.onDeleteClick,
|
|
10873
|
+
onEditClick = _ref.onEditClick;
|
|
10874
|
+
return [{
|
|
10875
|
+
key: "name",
|
|
10876
|
+
dataIndex: "name",
|
|
10877
|
+
title: t("titles.name"),
|
|
10878
|
+
render: function render(name, field) {
|
|
10879
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
10880
|
+
className: "flex items-center justify-between gap-x-3"
|
|
10881
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
10882
|
+
style: "body2"
|
|
10883
|
+
}, name), /*#__PURE__*/React.createElement(Dropdown, {
|
|
10884
|
+
buttonProps: {
|
|
10885
|
+
className: "flex-shrink-0"
|
|
10886
|
+
},
|
|
10887
|
+
buttonStyle: "text",
|
|
10888
|
+
icon: MenuHorizontal,
|
|
10889
|
+
strategy: "fixed"
|
|
10890
|
+
}, /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
10891
|
+
onClick: function onClick() {
|
|
10892
|
+
return onEditClick(field);
|
|
10893
|
+
}
|
|
10894
|
+
}, t("labels.edit")), !field.isSystem && /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
10895
|
+
onClick: function onClick() {
|
|
10896
|
+
return onDeleteClick(field);
|
|
10897
|
+
}
|
|
10898
|
+
}, t("labels.delete")))));
|
|
10899
|
+
}
|
|
10900
|
+
}, {
|
|
10901
|
+
key: "kind",
|
|
10902
|
+
dataIndex: "kind",
|
|
10903
|
+
title: t("titles.kind"),
|
|
10904
|
+
render: function render(kind) {
|
|
10905
|
+
return DISPLAY_KINDS[kind];
|
|
10906
|
+
}
|
|
10907
|
+
}, {
|
|
10908
|
+
key: "isRequired",
|
|
10909
|
+
dataIndex: "isRequired",
|
|
10910
|
+
title: t("titles.required"),
|
|
10911
|
+
render: function render(boolVal) {
|
|
10912
|
+
return boolVal ? t("common.yes") : t("common.no");
|
|
10913
|
+
}
|
|
10914
|
+
}];
|
|
10915
|
+
};
|
|
10916
|
+
var renderMenuBarItems = function renderMenuBarItems(_ref2) {
|
|
10917
|
+
var items = _ref2.items,
|
|
10918
|
+
isOwnerBased = _ref2.isOwnerBased,
|
|
10919
|
+
selectedMenu = _ref2.selectedMenu,
|
|
10920
|
+
setSelectedMenu = _ref2.setSelectedMenu;
|
|
10921
|
+
if (isOwnerBased) {
|
|
10922
|
+
return items.map(function (item) {
|
|
10923
|
+
return /*#__PURE__*/React.createElement(MenuBar.Item, {
|
|
10924
|
+
active: selectedMenu === item.id,
|
|
10925
|
+
description: t("messages.manageFieldFor", {
|
|
10926
|
+
resource: item.name
|
|
10927
|
+
}),
|
|
10928
|
+
key: item.id,
|
|
10929
|
+
label: capitalize$1(item.name),
|
|
10930
|
+
onClick: function onClick() {
|
|
10931
|
+
return setSelectedMenu(item.id);
|
|
10932
|
+
}
|
|
10933
|
+
});
|
|
10934
|
+
});
|
|
10935
|
+
}
|
|
10936
|
+
return items.map(function (item) {
|
|
10937
|
+
return /*#__PURE__*/React.createElement(MenuBar.Item, {
|
|
10938
|
+
active: selectedMenu === item,
|
|
10939
|
+
description: t("messages.manageFieldFor", {
|
|
10940
|
+
resource: item
|
|
10941
|
+
}),
|
|
10942
|
+
key: item,
|
|
10943
|
+
label: capitalize$1(item),
|
|
10944
|
+
onClick: function onClick() {
|
|
10945
|
+
return setSelectedMenu(item);
|
|
10946
|
+
}
|
|
10947
|
+
});
|
|
10948
|
+
});
|
|
10949
|
+
};
|
|
10950
|
+
var renderMenuBarFilters = function renderMenuBarFilters(_ref3) {
|
|
10951
|
+
var selectedState = _ref3.selectedState,
|
|
10952
|
+
setSelectedState = _ref3.setSelectedState,
|
|
10953
|
+
fieldStatesTaxonomy = _ref3.fieldStatesTaxonomy,
|
|
10954
|
+
activeFieldsCount = _ref3.activeFieldsCount,
|
|
10955
|
+
inactiveFieldsCount = _ref3.inactiveFieldsCount;
|
|
10956
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MenuBar.SubTitle, null, /*#__PURE__*/React.createElement(Typography, {
|
|
10957
|
+
style: "h5",
|
|
10958
|
+
textTransform: "uppercase",
|
|
10959
|
+
weight: "bold"
|
|
10960
|
+
}, t("titles.filters"))), /*#__PURE__*/React.createElement(MenuBar.Block, {
|
|
10961
|
+
active: selectedState === FIELD_STATES.active,
|
|
10962
|
+
count: activeFieldsCount,
|
|
10963
|
+
label: fieldStatesTaxonomy.active,
|
|
10964
|
+
onClick: function onClick() {
|
|
10965
|
+
return setSelectedState(FIELD_STATES.active);
|
|
10966
|
+
}
|
|
10967
|
+
}), /*#__PURE__*/React.createElement(MenuBar.Block, {
|
|
10968
|
+
active: selectedState === FIELD_STATES.inactive,
|
|
10969
|
+
count: inactiveFieldsCount,
|
|
10970
|
+
label: fieldStatesTaxonomy.inactive,
|
|
10971
|
+
onClick: function onClick() {
|
|
10972
|
+
return setSelectedState(FIELD_STATES.inactive);
|
|
10973
|
+
}
|
|
10974
|
+
}));
|
|
10975
|
+
};
|
|
10976
|
+
var getDashBoardTitle = function getDashBoardTitle(_ref4) {
|
|
10977
|
+
var _findBy;
|
|
10978
|
+
var isOwnerBased = _ref4.isOwnerBased,
|
|
10979
|
+
owners = _ref4.owners,
|
|
10980
|
+
selectedVal = _ref4.selectedVal;
|
|
10981
|
+
return t("messages.manageFieldFor", {
|
|
10982
|
+
resource: isOwnerBased ? (_findBy = findBy({
|
|
10983
|
+
id: selectedVal
|
|
10984
|
+
}, owners)) === null || _findBy === void 0 ? void 0 : _findBy.name : selectedVal
|
|
10985
|
+
});
|
|
10986
|
+
};
|
|
10987
|
+
|
|
10988
|
+
/** @type {React.FC<import("types").FieldsDashboardProps>} */
|
|
10989
|
+
|
|
10990
|
+
var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
10991
|
+
var _ref$rowData = _ref.rowData,
|
|
10992
|
+
rowData = _ref$rowData === void 0 ? [] : _ref$rowData,
|
|
10993
|
+
_ref$showOwnersInMenu = _ref.showOwnersInMenu,
|
|
10994
|
+
showOwnersInMenu = _ref$showOwnersInMenu === void 0 ? false : _ref$showOwnersInMenu,
|
|
10995
|
+
_ref$resourceType = _ref.resourceType,
|
|
10996
|
+
resourceType = _ref$resourceType === void 0 ? "" : _ref$resourceType,
|
|
10997
|
+
_ref$allowedKinds = _ref.allowedKinds,
|
|
10998
|
+
allowedKinds = _ref$allowedKinds === void 0 ? ALL_KINDS : _ref$allowedKinds,
|
|
6656
10999
|
paneProps = _ref.paneProps,
|
|
6657
11000
|
_ref$buildColumnData = _ref.buildColumnData,
|
|
6658
11001
|
buildColumnData = _ref$buildColumnData === void 0 ? function (_ref2) {
|
|
@@ -6678,25 +11021,22 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
6678
11021
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
6679
11022
|
isDeleteAlertOpen = _useState6[0],
|
|
6680
11023
|
setIsDeleteAlertOpen = _useState6[1];
|
|
6681
|
-
var _useState7 = useState(
|
|
11024
|
+
var _useState7 = useState(false),
|
|
6682
11025
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
var _useState9 = useState(
|
|
11026
|
+
isReorderPaneOpen = _useState8[0],
|
|
11027
|
+
setIsReorderPaneOpen = _useState8[1];
|
|
11028
|
+
var _useState9 = useState(""),
|
|
6686
11029
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
var _useState11 = useState(
|
|
11030
|
+
selectedMenu = _useState10[0],
|
|
11031
|
+
setSelectedMenu = _useState10[1];
|
|
11032
|
+
var _useState11 = useState({}),
|
|
6690
11033
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
var _useState13 = useState(
|
|
6694
|
-
pageIndex: DEFAULT_PAGE_INDEX,
|
|
6695
|
-
pageSize: DEFAULT_PAGE_SIZE
|
|
6696
|
-
}),
|
|
11034
|
+
selectedField = _useState12[0],
|
|
11035
|
+
setSelectedField = _useState12[1];
|
|
11036
|
+
var _useState13 = useState(FIELD_STATES.active),
|
|
6697
11037
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
6698
|
-
|
|
6699
|
-
|
|
11038
|
+
selectedState = _useState14[0],
|
|
11039
|
+
setSelectedState = _useState14[1];
|
|
6700
11040
|
var _useTranslation = useTranslation(),
|
|
6701
11041
|
t = _useTranslation.t;
|
|
6702
11042
|
var _useFetchConfigs = useFetchConfigs(),
|
|
@@ -6707,11 +11047,11 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
6707
11047
|
_useFetchConfigs$data4 = _useFetchConfigs$data2.resourceTypes,
|
|
6708
11048
|
resourceTypes = _useFetchConfigs$data4 === void 0 ? [] : _useFetchConfigs$data4,
|
|
6709
11049
|
isConfigsLoading = _useFetchConfigs.isLoading;
|
|
6710
|
-
var _useFetchFields = useFetchFields(
|
|
11050
|
+
var _useFetchFields = useFetchFields({
|
|
6711
11051
|
resourceType: !showOwnersInMenu ? selectedMenu : undefined,
|
|
6712
11052
|
ownerId: showOwnersInMenu ? selectedMenu : undefined,
|
|
6713
11053
|
state: selectedState
|
|
6714
|
-
},
|
|
11054
|
+
}, {
|
|
6715
11055
|
enabled: !!selectedMenu
|
|
6716
11056
|
}),
|
|
6717
11057
|
_useFetchFields$data = _useFetchFields.data,
|
|
@@ -6750,6 +11090,9 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
6750
11090
|
setIsDeleteAlertOpen(false);
|
|
6751
11091
|
setSelectedField({});
|
|
6752
11092
|
};
|
|
11093
|
+
var handleReorderPaneClose = function handleReorderPaneClose() {
|
|
11094
|
+
setIsReorderPaneOpen(false);
|
|
11095
|
+
};
|
|
6753
11096
|
var defaultColumns = buildDefaultColumns({
|
|
6754
11097
|
onDeleteClick: handleDeleteButtonClick,
|
|
6755
11098
|
onEditClick: handleEditButtonClick
|
|
@@ -6792,6 +11135,16 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
6792
11135
|
return setIsMenuBarOpen(not);
|
|
6793
11136
|
},
|
|
6794
11137
|
actionBlock: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
11138
|
+
label: t("labels.reorder"),
|
|
11139
|
+
style: "secondary",
|
|
11140
|
+
disabled: !existsBy({
|
|
11141
|
+
isSystem: false,
|
|
11142
|
+
state: "active"
|
|
11143
|
+
}, fields),
|
|
11144
|
+
onClick: function onClick() {
|
|
11145
|
+
return setIsReorderPaneOpen(true);
|
|
11146
|
+
}
|
|
11147
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
6795
11148
|
label: t("labels.addField"),
|
|
6796
11149
|
onClick: function onClick() {
|
|
6797
11150
|
return setIsPaneOpen(true);
|
|
@@ -6817,12 +11170,14 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
6817
11170
|
}), /*#__PURE__*/React.createElement(FieldsTable, {
|
|
6818
11171
|
columnData: columnData,
|
|
6819
11172
|
isLoading: isFieldsFetching || isFieldsLoading,
|
|
6820
|
-
pageProps: pageProps,
|
|
6821
11173
|
rowData: isEmpty(rowData) ? fields : rowData,
|
|
6822
11174
|
setIsPaneOpen: setIsPaneOpen,
|
|
6823
|
-
setPageProps: setPageProps,
|
|
6824
11175
|
totalCount: count
|
|
6825
|
-
})), /*#__PURE__*/React.createElement(
|
|
11176
|
+
})), /*#__PURE__*/React.createElement(ReorderPane, {
|
|
11177
|
+
allFields: fields,
|
|
11178
|
+
isOpen: isReorderPaneOpen,
|
|
11179
|
+
onClose: handleReorderPaneClose
|
|
11180
|
+
}), /*#__PURE__*/React.createElement(Alert, {
|
|
6826
11181
|
isOpen: isDeleteAlertOpen,
|
|
6827
11182
|
isSubmitting: isDeleting,
|
|
6828
11183
|
message: t("messages.confirmDelete"),
|