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