funda-ui 4.7.222 → 4.7.252
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/Date/index.js +51 -0
- package/EventCalendar/index.js +30 -13
- package/EventCalendarTimeline/index.js +30 -13
- package/ModalDialog/index.d.ts +8 -4
- package/ModalDialog/index.js +30 -13
- package/Table/index.js +304 -183
- package/lib/cjs/Date/index.js +51 -0
- package/lib/cjs/EventCalendar/index.js +30 -13
- package/lib/cjs/EventCalendarTimeline/index.js +30 -13
- package/lib/cjs/ModalDialog/index.d.ts +8 -4
- package/lib/cjs/ModalDialog/index.js +30 -13
- package/lib/cjs/Table/index.js +304 -183
- package/lib/esm/Date/index.tsx +47 -18
- package/lib/esm/Input/index.tsx +1 -0
- package/lib/esm/ModalDialog/index.tsx +39 -20
- package/lib/esm/Table/Table.tsx +74 -15
- package/lib/esm/Table/TableCell.tsx +7 -3
- package/lib/esm/Table/utils/func.ts +12 -1
- package/lib/esm/Table/utils/hooks/useTableKeyPress.tsx +152 -72
- package/package.json +1 -1
package/lib/cjs/Table/index.js
CHANGED
|
@@ -655,7 +655,10 @@ function tableElemScrolledInit(root, w) {
|
|
|
655
655
|
}
|
|
656
656
|
}
|
|
657
657
|
function cellMark(row, col) {
|
|
658
|
-
|
|
658
|
+
var isNegative = function isNegative(num) {
|
|
659
|
+
return num < 0;
|
|
660
|
+
};
|
|
661
|
+
return "cell-".concat(isNegative(row) ? 0 : row, "-").concat(isNegative(col) ? 0 : col);
|
|
659
662
|
}
|
|
660
663
|
function removeCellFocusClassName(root) {
|
|
661
664
|
if (root) {
|
|
@@ -664,6 +667,15 @@ function removeCellFocusClassName(root) {
|
|
|
664
667
|
});
|
|
665
668
|
}
|
|
666
669
|
}
|
|
670
|
+
function getTableRowsColCount(root) {
|
|
671
|
+
var rows = allRows(root);
|
|
672
|
+
return rows.map(function (row, i) {
|
|
673
|
+
return {
|
|
674
|
+
row: i,
|
|
675
|
+
colCount: row.children.length
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
}
|
|
667
679
|
;// CONCATENATED MODULE: ./src/utils/hooks/useTableResponsive.tsx
|
|
668
680
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
669
681
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -1026,6 +1038,236 @@ function useTableDraggable(_ref, deps) {
|
|
|
1026
1038
|
};
|
|
1027
1039
|
}
|
|
1028
1040
|
/* harmony default export */ const hooks_useTableDraggable = (useTableDraggable);
|
|
1041
|
+
;// CONCATENATED MODULE: ./src/utils/hooks/useTableKeyPress.tsx
|
|
1042
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1043
|
+
function useTableKeyPress_toConsumableArray(arr) { return useTableKeyPress_arrayWithoutHoles(arr) || useTableKeyPress_iterableToArray(arr) || useTableKeyPress_unsupportedIterableToArray(arr) || useTableKeyPress_nonIterableSpread(); }
|
|
1044
|
+
function useTableKeyPress_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1045
|
+
function useTableKeyPress_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return useTableKeyPress_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return useTableKeyPress_arrayLikeToArray(o, minLen); }
|
|
1046
|
+
function useTableKeyPress_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1047
|
+
function useTableKeyPress_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return useTableKeyPress_arrayLikeToArray(arr); }
|
|
1048
|
+
function useTableKeyPress_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1049
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1050
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1051
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1052
|
+
/**
|
|
1053
|
+
* Listens for changes in the pressed state of a given key
|
|
1054
|
+
*
|
|
1055
|
+
* @usage:
|
|
1056
|
+
*
|
|
1057
|
+
const App = () => {
|
|
1058
|
+
const keyboardFocusable = true;
|
|
1059
|
+
const rootRef = useRef<any>(null);
|
|
1060
|
+
// Effective element movement on keystroke
|
|
1061
|
+
|
|
1062
|
+
const refNode = useRef(new Map<string, HTMLTableElement>());
|
|
1063
|
+
const [focusableCellId, setFocusableCellId] = useState<string>('');
|
|
1064
|
+
|
|
1065
|
+
// Count the number of columns per row
|
|
1066
|
+
const rootDataInfo = {"totalRow":2,"totalCol":[{"row":0,"colCount":6},{"row":1,"colCount":6},{"row":2,"colCount":6}]};
|
|
1067
|
+
|
|
1068
|
+
// Example: handle cell key press with edge detection
|
|
1069
|
+
const handleCellKeyPressed = (
|
|
1070
|
+
classname: string,
|
|
1071
|
+
elem: HTMLTableCellElement,
|
|
1072
|
+
event: React.KeyboardEvent<Element>,
|
|
1073
|
+
isLeftEdge: boolean,
|
|
1074
|
+
isRightEdge: boolean,
|
|
1075
|
+
isTopEdge: boolean,
|
|
1076
|
+
isBottomEdge: boolean
|
|
1077
|
+
) => {
|
|
1078
|
+
if (isLeftEdge) {
|
|
1079
|
+
// Handle when at the leftmost cell
|
|
1080
|
+
}
|
|
1081
|
+
if (isRightEdge) {
|
|
1082
|
+
// Handle when at the rightmost cell
|
|
1083
|
+
}
|
|
1084
|
+
if (isTopEdge) {
|
|
1085
|
+
// Handle when at the topmost cell
|
|
1086
|
+
}
|
|
1087
|
+
if (isBottomEdge) {
|
|
1088
|
+
// Handle when at the bottommost cell
|
|
1089
|
+
}
|
|
1090
|
+
// Your business logic here
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
const { handleKeyPressed } = useTableKeyPress({
|
|
1094
|
+
enabled: keyboardFocusable,
|
|
1095
|
+
data: [{ a: 1, b: 2, c: 3 }],
|
|
1096
|
+
spyElement: rootRef.current,
|
|
1097
|
+
rootDataInfo,
|
|
1098
|
+
refNode,
|
|
1099
|
+
focusableCellId,
|
|
1100
|
+
setFocusableCellId,
|
|
1101
|
+
onCellKeyPressed: handleCellKeyPressed,
|
|
1102
|
+
onCellPressEnter: () => {},
|
|
1103
|
+
}, [rootRef]);
|
|
1104
|
+
|
|
1105
|
+
return (
|
|
1106
|
+
<div
|
|
1107
|
+
ref={rootRef}
|
|
1108
|
+
tabIndex={-1}
|
|
1109
|
+
onKeyDown={handleKeyPressed} // require "tabIndex" attribute
|
|
1110
|
+
>Test</div>
|
|
1111
|
+
);
|
|
1112
|
+
};
|
|
1113
|
+
*/
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
var useTableKeyPress = function useTableKeyPress(_ref, deps) {
|
|
1117
|
+
var enabled = _ref.enabled,
|
|
1118
|
+
data = _ref.data,
|
|
1119
|
+
spyElement = _ref.spyElement,
|
|
1120
|
+
rootDataInfo = _ref.rootDataInfo,
|
|
1121
|
+
refNode = _ref.refNode,
|
|
1122
|
+
focusableCellId = _ref.focusableCellId,
|
|
1123
|
+
setFocusableCellId = _ref.setFocusableCellId,
|
|
1124
|
+
onCellKeyPressed = _ref.onCellKeyPressed,
|
|
1125
|
+
onCellPressEnter = _ref.onCellPressEnter,
|
|
1126
|
+
onKeyDown = _ref.onKeyDown;
|
|
1127
|
+
var focusableCellIdRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(focusableCellId);
|
|
1128
|
+
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1129
|
+
focusableCellIdRef.current = focusableCellId;
|
|
1130
|
+
}, [focusableCellId]);
|
|
1131
|
+
var handleKeyPressed = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/function () {
|
|
1132
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
1133
|
+
var _focusableCellIdRef$c;
|
|
1134
|
+
var key, currentCell, row, col, nextCellSignal, oldCellSignal, _row, _col, move, _nextCellSignal;
|
|
1135
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1136
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1137
|
+
case 0:
|
|
1138
|
+
key = event.code; // If Enter is pressed and keyboard navigation is disabled, just trigger onCellPressEnter
|
|
1139
|
+
if (!((key === 'Enter' || key === 'NumpadEnter') && !enabled)) {
|
|
1140
|
+
_context.next = 8;
|
|
1141
|
+
break;
|
|
1142
|
+
}
|
|
1143
|
+
currentCell = event.target;
|
|
1144
|
+
row = Number(currentCell.getAttribute('data-table-row'));
|
|
1145
|
+
col = Number(currentCell.getAttribute('data-table-col'));
|
|
1146
|
+
nextCellSignal = cellMark(row, col);
|
|
1147
|
+
onCellPressEnter === null || onCellPressEnter === void 0 ? void 0 : onCellPressEnter(nextCellSignal, refNode.current.get(nextCellSignal), event);
|
|
1148
|
+
return _context.abrupt("return");
|
|
1149
|
+
case 8:
|
|
1150
|
+
if (!(!Array.isArray(data) || rootDataInfo === null || spyElement === null || typeof enabled === 'undefined' || enabled === false)) {
|
|
1151
|
+
_context.next = 10;
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1154
|
+
return _context.abrupt("return");
|
|
1155
|
+
case 10:
|
|
1156
|
+
// Parse the current focused cell's row and column
|
|
1157
|
+
oldCellSignal = (_focusableCellIdRef$c = focusableCellIdRef.current) === null || _focusableCellIdRef$c === void 0 ? void 0 : _focusableCellIdRef$c.replace('cell-', '').split('-');
|
|
1158
|
+
_row = Number(oldCellSignal[0]);
|
|
1159
|
+
_col = Number(oldCellSignal[1]); // Move function to handle arrow key navigation
|
|
1160
|
+
move = function move(key) {
|
|
1161
|
+
var isLeftEdge = false;
|
|
1162
|
+
var isRightEdge = false;
|
|
1163
|
+
var isTopEdge = false;
|
|
1164
|
+
var isBottomEdge = false;
|
|
1165
|
+
var maxCol = 0;
|
|
1166
|
+
if (rootDataInfo && Array.isArray(rootDataInfo.totalCol)) {
|
|
1167
|
+
var rowInfo = rootDataInfo.totalCol.find(function (r) {
|
|
1168
|
+
return r.row === _row;
|
|
1169
|
+
});
|
|
1170
|
+
if (rowInfo) {
|
|
1171
|
+
maxCol = rowInfo.colCount;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
switch (key) {
|
|
1175
|
+
case 'ArrowLeft':
|
|
1176
|
+
case 'Numpad4':
|
|
1177
|
+
if (_col - 1 < 0) {
|
|
1178
|
+
isLeftEdge = true;
|
|
1179
|
+
_col = 0;
|
|
1180
|
+
} else {
|
|
1181
|
+
_col = _col - 1;
|
|
1182
|
+
}
|
|
1183
|
+
break;
|
|
1184
|
+
case 'ArrowRight':
|
|
1185
|
+
case 'Numpad6':
|
|
1186
|
+
{
|
|
1187
|
+
if (_col + 1 > maxCol - 1) {
|
|
1188
|
+
isRightEdge = true;
|
|
1189
|
+
_col = maxCol - 1;
|
|
1190
|
+
} else {
|
|
1191
|
+
_col = _col + 1;
|
|
1192
|
+
}
|
|
1193
|
+
break;
|
|
1194
|
+
}
|
|
1195
|
+
case 'ArrowUp':
|
|
1196
|
+
case 'Numpad8':
|
|
1197
|
+
if (_row - 1 < 0) {
|
|
1198
|
+
isTopEdge = true;
|
|
1199
|
+
_row = 0;
|
|
1200
|
+
} else {
|
|
1201
|
+
_row = _row - 1;
|
|
1202
|
+
}
|
|
1203
|
+
break;
|
|
1204
|
+
case 'ArrowDown':
|
|
1205
|
+
case 'Numpad2':
|
|
1206
|
+
if (_row + 1 > rootDataInfo.totalRow - 1) {
|
|
1207
|
+
isBottomEdge = true;
|
|
1208
|
+
_row = rootDataInfo.totalRow - 1;
|
|
1209
|
+
} else {
|
|
1210
|
+
_row = _row + 1;
|
|
1211
|
+
}
|
|
1212
|
+
break;
|
|
1213
|
+
}
|
|
1214
|
+
var nextCellSignal = cellMark(_row, _col);
|
|
1215
|
+
// Focus the current cell
|
|
1216
|
+
removeCellFocusClassName(spyElement);
|
|
1217
|
+
var targetCell = refNode.current.get(nextCellSignal);
|
|
1218
|
+
if (typeof targetCell !== 'undefined') {
|
|
1219
|
+
targetCell.classList.add('cell-focus');
|
|
1220
|
+
}
|
|
1221
|
+
setFocusableCellId(nextCellSignal);
|
|
1222
|
+
// Callback with edge detection
|
|
1223
|
+
onCellKeyPressed === null || onCellKeyPressed === void 0 ? void 0 : onCellKeyPressed(nextCellSignal, refNode.current.get(nextCellSignal), event, isLeftEdge, isRightEdge, isTopEdge, isBottomEdge);
|
|
1224
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
1225
|
+
}; // Handle arrow key navigation
|
|
1226
|
+
if (key === 'ArrowLeft' || key === 'Numpad4') {
|
|
1227
|
+
move('ArrowLeft');
|
|
1228
|
+
}
|
|
1229
|
+
if (key === 'ArrowRight' || key === 'Numpad6') {
|
|
1230
|
+
move('ArrowRight');
|
|
1231
|
+
}
|
|
1232
|
+
if (key === 'ArrowUp' || key === 'Numpad8') {
|
|
1233
|
+
move('ArrowUp');
|
|
1234
|
+
}
|
|
1235
|
+
if (key === 'ArrowDown' || key === 'Numpad2') {
|
|
1236
|
+
move('ArrowDown');
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// Handle Enter key
|
|
1240
|
+
if (key === 'Enter' || key === 'NumpadEnter') {
|
|
1241
|
+
_nextCellSignal = cellMark(_row, _col);
|
|
1242
|
+
onCellPressEnter === null || onCellPressEnter === void 0 ? void 0 : onCellPressEnter(_nextCellSignal, refNode.current.get(_nextCellSignal), event);
|
|
1243
|
+
}
|
|
1244
|
+
case 19:
|
|
1245
|
+
case "end":
|
|
1246
|
+
return _context.stop();
|
|
1247
|
+
}
|
|
1248
|
+
}, _callee);
|
|
1249
|
+
}));
|
|
1250
|
+
return function (_x) {
|
|
1251
|
+
return _ref2.apply(this, arguments);
|
|
1252
|
+
};
|
|
1253
|
+
}(), [focusableCellId, rootDataInfo, data]);
|
|
1254
|
+
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1255
|
+
if (enabled) {
|
|
1256
|
+
// Initialize custom props of table elements (only once)
|
|
1257
|
+
initOrderProps(spyElement);
|
|
1258
|
+
initRowColProps(spyElement);
|
|
1259
|
+
}
|
|
1260
|
+
}, [enabled, spyElement].concat(useTableKeyPress_toConsumableArray(deps)));
|
|
1261
|
+
return {
|
|
1262
|
+
handleKeyPressed: handleKeyPressed,
|
|
1263
|
+
/**
|
|
1264
|
+
* Expose handleKeyPressed for external usage, e.g., via contentRef in Table component.
|
|
1265
|
+
* This allows calling handleKeyPressed programmatically from outside, such as with a custom onCellKeyPressed method.
|
|
1266
|
+
*/
|
|
1267
|
+
triggerCellKeyPressed: handleKeyPressed
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
/* harmony default export */ const hooks_useTableKeyPress = (useTableKeyPress);
|
|
1029
1271
|
;// CONCATENATED MODULE: ./src/Table.tsx
|
|
1030
1272
|
var _excluded = ["contentRef", "children", "wrapperClassName", "tableClassName", "bordered", "colGroup", "cellAutoWidth", "colSortable", "onColSort", "rowDraggable", "onRowDrag", "responsive", "enhancedResponsive", "enhancedResponsiveWithScrollBar", "data", "filterFields", "filterControlClassName", "filterControlPlaceholder", "filterLabel", "onChangeFilter", "dataSelected", "rowSelectable", "onChangeRowSelect", "keyboardFocusable", "onCellKeyPressed", "onCellPressEnter"];
|
|
1031
1273
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
@@ -1044,6 +1286,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
1044
1286
|
|
|
1045
1287
|
|
|
1046
1288
|
|
|
1289
|
+
|
|
1047
1290
|
var Table = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function (_ref, externalRef) {
|
|
1048
1291
|
var contentRef = _ref.contentRef,
|
|
1049
1292
|
children = _ref.children,
|
|
@@ -1126,6 +1369,27 @@ var Table = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_a
|
|
|
1126
1369
|
handleDragEnd = _useTableDraggable.handleDragEnd,
|
|
1127
1370
|
handledragOver = _useTableDraggable.handledragOver,
|
|
1128
1371
|
handleTbodyEnter = _useTableDraggable.handleTbodyEnter;
|
|
1372
|
+
var tableKeyPress = hooks_useTableKeyPress({
|
|
1373
|
+
enabled: keyboardFocusable,
|
|
1374
|
+
data: data,
|
|
1375
|
+
spyElement: rootRef.current,
|
|
1376
|
+
rootDataInfo: rootDataInfo,
|
|
1377
|
+
refNode: refNode,
|
|
1378
|
+
focusableCellId: focusableCellId,
|
|
1379
|
+
setFocusableCellId: setFocusableCellId,
|
|
1380
|
+
onCellKeyPressed: onCellKeyPressed,
|
|
1381
|
+
onCellPressEnter: onCellPressEnter
|
|
1382
|
+
}, [data, rootRef, rootDataInfo, refNode, focusableCellId]);
|
|
1383
|
+
var updateFocusableCell = function updateFocusableCell(row, col) {
|
|
1384
|
+
setFocusableCellId(cellMark(row, col));
|
|
1385
|
+
|
|
1386
|
+
// Find and focus the cell element
|
|
1387
|
+
var targetCell = refNode.current.get(cellMark(row, col));
|
|
1388
|
+
if (typeof targetCell !== 'undefined') {
|
|
1389
|
+
removeCellFocusClassName(rootRef.current);
|
|
1390
|
+
targetCell.classList.add('cell-focus');
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1129
1393
|
|
|
1130
1394
|
// initialize context
|
|
1131
1395
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
@@ -1148,26 +1412,51 @@ var Table = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_a
|
|
|
1148
1412
|
if (rootRef.current) {
|
|
1149
1413
|
// Initialize custom props of table elements
|
|
1150
1414
|
initRowColProps(rootRef.current);
|
|
1415
|
+
|
|
1416
|
+
// Count the number of columns per row
|
|
1417
|
+
var totalCol = getTableRowsColCount(rootRef.current);
|
|
1418
|
+
setRootDataInfo({
|
|
1419
|
+
totalRow: Array.isArray(data) ? data.length : 0,
|
|
1420
|
+
totalCol: totalCol
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
// Initialize the focused index
|
|
1424
|
+
if (keyboardFocusable) {
|
|
1425
|
+
updateFocusableCell(0, 0);
|
|
1426
|
+
}
|
|
1151
1427
|
}
|
|
1152
1428
|
}, [data]); // Re-run when data changes
|
|
1153
1429
|
|
|
1154
1430
|
// exposes the following methods
|
|
1155
1431
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(contentRef, function () {
|
|
1156
1432
|
return {
|
|
1157
|
-
setFocusableCell:
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
// Find and focus the cell element
|
|
1162
|
-
var cellElement = (_rootRef$current = rootRef.current) === null || _rootRef$current === void 0 ? void 0 : _rootRef$current.querySelector(".".concat(cellMark(row, col)));
|
|
1163
|
-
if (cellElement) {
|
|
1433
|
+
setFocusableCell: updateFocusableCell,
|
|
1434
|
+
clearAllCellFocus: function clearAllCellFocus() {
|
|
1435
|
+
if (rootRef.current) {
|
|
1164
1436
|
removeCellFocusClassName(rootRef.current);
|
|
1165
|
-
|
|
1166
|
-
|
|
1437
|
+
var focusedCells = rootRef.current.querySelectorAll('td.cell-focus, th.cell-focus');
|
|
1438
|
+
focusedCells.forEach(function (cell) {
|
|
1439
|
+
if (typeof cell.blur === 'function') cell.blur();
|
|
1440
|
+
if (cell.classList) cell.classList.remove('cell-focus');
|
|
1441
|
+
});
|
|
1167
1442
|
}
|
|
1168
|
-
}
|
|
1443
|
+
},
|
|
1444
|
+
getCellElement: function getCellElement(row, col) {
|
|
1445
|
+
// Find and focus the cell element
|
|
1446
|
+
var targetCell = refNode.current.get(cellMark(row, col));
|
|
1447
|
+
return typeof targetCell !== 'undefined' ? targetCell : null;
|
|
1448
|
+
},
|
|
1449
|
+
forceFocusCell: function forceFocusCell(row, col) {
|
|
1450
|
+
// Find and focus the cell element
|
|
1451
|
+
var targetCell = refNode.current.get(cellMark(row, col));
|
|
1452
|
+
if (typeof targetCell !== 'undefined') {
|
|
1453
|
+
// After forcing focus, you can use the keyboard to listen directly
|
|
1454
|
+
targetCell.focus();
|
|
1455
|
+
}
|
|
1456
|
+
},
|
|
1457
|
+
triggerCellKeyPressed: tableKeyPress.triggerCellKeyPressed
|
|
1169
1458
|
};
|
|
1170
|
-
}, [rootRef]);
|
|
1459
|
+
}, [rootRef, data, rootDataInfo]);
|
|
1171
1460
|
return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement((external_root_React_commonjs2_react_commonjs_react_amd_react_default()).Fragment, null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(TableProvider, {
|
|
1172
1461
|
value: {
|
|
1173
1462
|
originData: data,
|
|
@@ -1247,175 +1536,6 @@ var TableBody = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_rea
|
|
|
1247
1536
|
}), children));
|
|
1248
1537
|
});
|
|
1249
1538
|
/* harmony default export */ const src_TableBody = (TableBody);
|
|
1250
|
-
;// CONCATENATED MODULE: ./src/utils/hooks/useTableKeyPress.tsx
|
|
1251
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1252
|
-
function useTableKeyPress_toConsumableArray(arr) { return useTableKeyPress_arrayWithoutHoles(arr) || useTableKeyPress_iterableToArray(arr) || useTableKeyPress_unsupportedIterableToArray(arr) || useTableKeyPress_nonIterableSpread(); }
|
|
1253
|
-
function useTableKeyPress_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1254
|
-
function useTableKeyPress_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return useTableKeyPress_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return useTableKeyPress_arrayLikeToArray(o, minLen); }
|
|
1255
|
-
function useTableKeyPress_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1256
|
-
function useTableKeyPress_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return useTableKeyPress_arrayLikeToArray(arr); }
|
|
1257
|
-
function useTableKeyPress_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1258
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1259
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1260
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1261
|
-
/**
|
|
1262
|
-
* Listens for changes in the pressed state of a given key
|
|
1263
|
-
*
|
|
1264
|
-
* @usage:
|
|
1265
|
-
|
|
1266
|
-
const App = () => {
|
|
1267
|
-
|
|
1268
|
-
const keyboardFocusable = true;
|
|
1269
|
-
const rootRef = useRef<any>(null);
|
|
1270
|
-
|
|
1271
|
-
// effective element movement on keystroke
|
|
1272
|
-
const [rootDataInfo, setRootDataInfo] = useState<null | {totalRow: number}>(null);
|
|
1273
|
-
const refNode = useRef(new Map<string, HTMLTableElement>());
|
|
1274
|
-
const [focusableCellId, setFocusableCellId] = useState<string>('');
|
|
1275
|
-
|
|
1276
|
-
const { handleKeyPressed } = useTableKeyPress({
|
|
1277
|
-
enabled: keyboardFocusable,
|
|
1278
|
-
data: [{a: 1, b: 2, c: 3}],
|
|
1279
|
-
spyElement: rootRef.current,
|
|
1280
|
-
rootDataInfo,
|
|
1281
|
-
setRootDataInfo,
|
|
1282
|
-
refNode,
|
|
1283
|
-
focusableCellId,
|
|
1284
|
-
setFocusableCellId,
|
|
1285
|
-
onCellKeyPressed,
|
|
1286
|
-
onCellPressEnter,
|
|
1287
|
-
}, [rootRef]);
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
return (
|
|
1291
|
-
<div
|
|
1292
|
-
ref={rootRef}
|
|
1293
|
-
tabIndex={-1}
|
|
1294
|
-
onKeyDown={handleKeyPressed} // require "tabIndex" attribute
|
|
1295
|
-
>Test</div>
|
|
1296
|
-
);
|
|
1297
|
-
};
|
|
1298
|
-
|
|
1299
|
-
*/
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
var useTableKeyPress = function useTableKeyPress(_ref, deps) {
|
|
1303
|
-
var enabled = _ref.enabled,
|
|
1304
|
-
data = _ref.data,
|
|
1305
|
-
spyElement = _ref.spyElement,
|
|
1306
|
-
rootDataInfo = _ref.rootDataInfo,
|
|
1307
|
-
setRootDataInfo = _ref.setRootDataInfo,
|
|
1308
|
-
refNode = _ref.refNode,
|
|
1309
|
-
focusableCellId = _ref.focusableCellId,
|
|
1310
|
-
setFocusableCellId = _ref.setFocusableCellId,
|
|
1311
|
-
onCellKeyPressed = _ref.onCellKeyPressed,
|
|
1312
|
-
onCellPressEnter = _ref.onCellPressEnter,
|
|
1313
|
-
onKeyDown = _ref.onKeyDown;
|
|
1314
|
-
var handleKeyPressed = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/function () {
|
|
1315
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
1316
|
-
var key, currentCell, row, col, nextCellSignal, oldCellSignal, _row, _col, move, _nextCellSignal;
|
|
1317
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1318
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1319
|
-
case 0:
|
|
1320
|
-
key = event.code;
|
|
1321
|
-
if (!((key === 'Enter' || key === 'NumpadEnter') && !enabled)) {
|
|
1322
|
-
_context.next = 8;
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
currentCell = event.target;
|
|
1326
|
-
row = Number(currentCell.getAttribute('data-table-row'));
|
|
1327
|
-
col = Number(currentCell.getAttribute('data-table-col'));
|
|
1328
|
-
nextCellSignal = cellMark(row, col);
|
|
1329
|
-
onCellPressEnter === null || onCellPressEnter === void 0 ? void 0 : onCellPressEnter(nextCellSignal, refNode.current.get(nextCellSignal), event);
|
|
1330
|
-
return _context.abrupt("return");
|
|
1331
|
-
case 8:
|
|
1332
|
-
if (!(!Array.isArray(data) || rootDataInfo === null || spyElement === null || typeof enabled === 'undefined' || enabled === false)) {
|
|
1333
|
-
_context.next = 10;
|
|
1334
|
-
break;
|
|
1335
|
-
}
|
|
1336
|
-
return _context.abrupt("return");
|
|
1337
|
-
case 10:
|
|
1338
|
-
oldCellSignal = focusableCellId === null || focusableCellId === void 0 ? void 0 : focusableCellId.replace('cell-', '').split('-');
|
|
1339
|
-
_row = Number(oldCellSignal[0]);
|
|
1340
|
-
_col = Number(oldCellSignal[1]);
|
|
1341
|
-
move = function move(key) {
|
|
1342
|
-
var _spyElement$querySele;
|
|
1343
|
-
switch (key) {
|
|
1344
|
-
case 'ArrowLeft':
|
|
1345
|
-
case 'Numpad4':
|
|
1346
|
-
_col = _col - 1 < 0 ? 0 : _col - 1;
|
|
1347
|
-
break;
|
|
1348
|
-
case 'ArrowRight':
|
|
1349
|
-
case 'Numpad6':
|
|
1350
|
-
_col = _col + 1 > data.length - 1 ? data.length - 1 : _col + 1;
|
|
1351
|
-
break;
|
|
1352
|
-
case 'ArrowUp':
|
|
1353
|
-
case 'Numpad8':
|
|
1354
|
-
_row = _row - 1 < 0 ? 0 : _row - 1;
|
|
1355
|
-
break;
|
|
1356
|
-
case 'ArrowDown':
|
|
1357
|
-
case 'Numpad2':
|
|
1358
|
-
_row = _row + 1 > rootDataInfo.totalRow - 1 ? rootDataInfo.totalRow - 1 : _row + 1;
|
|
1359
|
-
break;
|
|
1360
|
-
}
|
|
1361
|
-
var nextCellSignal = cellMark(_row, _col);
|
|
1362
|
-
|
|
1363
|
-
// focus current cell
|
|
1364
|
-
removeCellFocusClassName(spyElement);
|
|
1365
|
-
(_spyElement$querySele = spyElement.querySelector(".".concat(nextCellSignal))) === null || _spyElement$querySele === void 0 ? void 0 : _spyElement$querySele.classList.add('cell-focus');
|
|
1366
|
-
|
|
1367
|
-
//
|
|
1368
|
-
setFocusableCellId(nextCellSignal);
|
|
1369
|
-
|
|
1370
|
-
// callback
|
|
1371
|
-
onCellKeyPressed === null || onCellKeyPressed === void 0 ? void 0 : onCellKeyPressed(nextCellSignal, refNode.current.get(nextCellSignal), event);
|
|
1372
|
-
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
1373
|
-
};
|
|
1374
|
-
if (key === 'ArrowLeft' || key === 'Numpad4') {
|
|
1375
|
-
move('ArrowLeft');
|
|
1376
|
-
}
|
|
1377
|
-
if (key === 'ArrowRight' || key === 'Numpad6') {
|
|
1378
|
-
move('ArrowRight');
|
|
1379
|
-
}
|
|
1380
|
-
if (key === 'ArrowUp' || key === 'Numpad8') {
|
|
1381
|
-
move('ArrowUp');
|
|
1382
|
-
}
|
|
1383
|
-
if (key === 'ArrowDown' || key === 'Numpad2') {
|
|
1384
|
-
move('ArrowDown');
|
|
1385
|
-
}
|
|
1386
|
-
if (key === 'Enter' || key === 'NumpadEnter') {
|
|
1387
|
-
_nextCellSignal = cellMark(_row, _col);
|
|
1388
|
-
onCellPressEnter === null || onCellPressEnter === void 0 ? void 0 : onCellPressEnter(_nextCellSignal, refNode.current.get(_nextCellSignal), event);
|
|
1389
|
-
}
|
|
1390
|
-
case 19:
|
|
1391
|
-
case "end":
|
|
1392
|
-
return _context.stop();
|
|
1393
|
-
}
|
|
1394
|
-
}, _callee);
|
|
1395
|
-
}));
|
|
1396
|
-
return function (_x) {
|
|
1397
|
-
return _ref2.apply(this, arguments);
|
|
1398
|
-
};
|
|
1399
|
-
}(), [focusableCellId]);
|
|
1400
|
-
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
1401
|
-
if (enabled) {
|
|
1402
|
-
// Initialize custom props of table elements
|
|
1403
|
-
initOrderProps(spyElement);
|
|
1404
|
-
initRowColProps(spyElement);
|
|
1405
|
-
|
|
1406
|
-
// Update cell ids
|
|
1407
|
-
if (Array.isArray(data)) {
|
|
1408
|
-
setRootDataInfo({
|
|
1409
|
-
totalRow: data.length
|
|
1410
|
-
});
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}, [enabled, spyElement].concat(useTableKeyPress_toConsumableArray(deps)));
|
|
1414
|
-
return {
|
|
1415
|
-
handleKeyPressed: handleKeyPressed
|
|
1416
|
-
};
|
|
1417
|
-
};
|
|
1418
|
-
/* harmony default export */ const hooks_useTableKeyPress = (useTableKeyPress);
|
|
1419
1539
|
;// CONCATENATED MODULE: ./src/TableCell.tsx
|
|
1420
1540
|
function TableCell_typeof(obj) { "@babel/helpers - typeof"; return TableCell_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, TableCell_typeof(obj); }
|
|
1421
1541
|
var TableCell_excluded = ["children", "active", "nowrap", "activeClassName", "className", "colSpan", "style", "scope", "onClick", "onKeyDown"];
|
|
@@ -1463,7 +1583,6 @@ var TableCell = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_rea
|
|
|
1463
1583
|
data: originData,
|
|
1464
1584
|
spyElement: rootRef.current,
|
|
1465
1585
|
rootDataInfo: rootDataInfo,
|
|
1466
|
-
setRootDataInfo: setRootDataInfo,
|
|
1467
1586
|
refNode: refNode,
|
|
1468
1587
|
focusableCellId: focusableCellId,
|
|
1469
1588
|
setFocusableCellId: setFocusableCellId,
|
|
@@ -1485,7 +1604,9 @@ var TableCell = /*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_rea
|
|
|
1485
1604
|
if (node) {
|
|
1486
1605
|
var _row = node.dataset.tableRow;
|
|
1487
1606
|
var _col = node.dataset.tableCol;
|
|
1488
|
-
|
|
1607
|
+
if (typeof _row !== 'undefined' && typeof _col !== 'undefined') {
|
|
1608
|
+
refNode.current.set(cellMark(_row, _col), node);
|
|
1609
|
+
}
|
|
1489
1610
|
}
|
|
1490
1611
|
},
|
|
1491
1612
|
colSpan: colSpan,
|