UNPKG

amisa-grid-view

Version:

amisa.grid.view component of amisa!

882 lines (879 loc) 49.3 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value; var __publicField = (obj, key, value) => (__defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }, __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); const formatNumberShowZero = (num) => typeof num == "number" ? num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") : ""; Number.prototype.formatNumberShowZero = function() { return formatNumberShowZero(this); }; const isDownTheseKeys = (e, shiftKey, ctrlKey, altKey) => { const isShiftKey2 = shiftKey == null || shiftKey && e.shiftKey ? !0 : !shiftKey && !e.shiftKey, isCtrlKey = ctrlKey == null || ctrlKey && e.ctrlKey ? !0 : !ctrlKey && !e.ctrlKey, isAltKey2 = altKey == null || altKey && e.altKey ? !0 : !altKey && !e.altKey; return isShiftKey2 && isCtrlKey && isAltKey2; }, isArrowUpKey = (e, shift, ctrl, alt) => e.key.toUpperCase() === "arrowUp".toUpperCase() && isDownTheseKeys(e, shift, ctrl, alt) ? (e.preventDefault(), !0) : !1, isArrowDownKey = (e, shift, ctrl, alt) => e.key.toUpperCase() === "arrowDown".toUpperCase() && isDownTheseKeys(e, shift, ctrl, alt) ? (e.preventDefault(), !0) : !1, isArrowLeftKey = (e, shift, ctrl, alt) => e.key.toUpperCase() === "arrowLeft".toUpperCase() && isDownTheseKeys(e, shift, ctrl, alt) ? (e.preventDefault(), !0) : !1, isArrowRightKey = (e, shift, ctrl, alt) => e.key.toUpperCase() === "arrowRight".toUpperCase() && isDownTheseKeys(e, shift, ctrl, alt) ? (e.preventDefault(), !0) : !1; var __defProp2 = Object.defineProperty, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField2 = (obj, key, value) => (__defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck2 = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }, __privateGet2 = (obj, member, getter) => (__accessCheck2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd2 = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }, __privateSet2 = (obj, member, value, setter) => (__accessCheck2(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value), __privateMethod2 = (obj, member, method) => (__accessCheck2(obj, member, "access private method"), method), _styleElement; class PaginationStyleManager { constructor(paginationManager) { __privateAdd2(this, _styleElement, void 0), this.paginationManager = paginationManager, __privateSet2(this, _styleElement, document.createElement("style")), __privateGet2(this, _styleElement).textContent = ` nav { width: 100%; padding-top:3px; padding-bottom:3px; display: block; } ul { display: flex; align-items: center; justify-content: center; padding-left: 0; list-style: none; border-radius: 0.25rem; margin-top: 0.1rem; margin-bottom: 0.1rem; } ul > li:first-child > button { margin-right: 0; border-top-right-radius: 0.25rem; border-bottom-right-radius: 0.25rem; } ul > li:last-child > button { border-top-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem; } button.separator { display: block; padding: 0.4rem 0.6rem; margin-left: -1px; color: #6c757d; pointer-events: none; cursor: auto; background-color: #2c343f; border: 1px solid #dee2e6; border-radius: 0; } button { display: block; padding: 0.4rem 0.6rem; margin-left: -1px; color: rgba(255, 255, 255, 0.7); background-color: #2c343f; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 0; min-width: 38px; } button:disabled { color: #6c757d; pointer-events: none; cursor: auto; background-color: #2c343f; border-color: rgba(255, 255, 255, 0.2); }button.active { z-index: 1; color: #1e2b41; background-color: rgba(255, 255, 255, 0.7); border-color: rgba(255, 255, 255, 0.2); } button:hover:not(.active) { color: #0056b3; text-decoration: none; background-color: #e9ecef; border-color: rgba(255, 255, 255, 0.2); } button:focus { z-index: 2; outline: 0; box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); } button:not(:disabled):not(.disabled) { cursor: pointer; } `; } get styleElement() { return __privateGet2(this, _styleElement); } } _styleElement = /* @__PURE__ */ new WeakMap(); var _navElement, _ulElement; class PaginationNavManager { constructor(paginationManager) { __privateAdd2(this, _navElement, void 0), __privateAdd2(this, _ulElement, void 0), __publicField2(this, "remove", () => { }), __publicField2(this, "create", () => { __privateGet2(this, _navElement).classList.add("pagination"), this.initialize(), __privateGet2(this, _navElement).appendChild(this.paginationManager.paginationStyleManager.styleElement), __privateGet2(this, _navElement).appendChild(__privateGet2(this, _ulElement)); }), __publicField2(this, "initialize", () => { this.paginationManager.pagesManager.previousPageManager.refresh(), __privateGet2(this, _ulElement).appendChild(this.paginationManager.pagesManager.previousPageManager.liElement), this.paginationManager.pagesManager.pagesButton.forEach((element) => { __privateGet2(this, _ulElement).appendChild(element.liElement); }), this.paginationManager.pagesManager.nextPageManager.refresh(), __privateGet2(this, _ulElement).appendChild(this.paginationManager.pagesManager.nextPageManager.liElement); }), __publicField2(this, "refresh", () => { this.paginationManager.pagesManager.refresh(), this.initialize(); }), this.paginationManager = paginationManager, __privateSet2(this, _navElement, document.createElement("nav")), __privateGet2(this, _navElement).style.userSelect = "none", __privateSet2(this, _ulElement, document.createElement("ul")), this.create(); } get navElement() { return __privateGet2(this, _navElement); } get ulElement() { return __privateGet2(this, _ulElement); } } _navElement = /* @__PURE__ */ new WeakMap(), _ulElement = /* @__PURE__ */ new WeakMap(); var _liElement, _buttonElement, _onClick; class PageButtonManagerBase { constructor(paginationManager) { __privateAdd2(this, _liElement, void 0), __privateAdd2(this, _buttonElement, void 0), __publicField2(this, "refresh", () => { __privateGet2(this, _buttonElement).disabled = this.disabled, __privateGet2(this, _buttonElement).textContent = this.caption, typeof this.pageNumber == "number" && this.pageNumber === this.paginationManager.currentPage && __privateGet2(this, _buttonElement).classList.add("active"); }), __publicField2(this, "remove", () => { this.liElement.remove(); }), __privateAdd2(this, _onClick, (e) => { e.preventDefault(), this.onClick(); }), this.paginationManager = paginationManager, __privateSet2(this, _liElement, document.createElement("li")), __privateSet2(this, _buttonElement, document.createElement("button")), __privateGet2(this, _liElement).appendChild(__privateGet2(this, _buttonElement)), __privateGet2(this, _buttonElement).addEventListener("click", __privateGet2(this, _onClick)); } get liElement() { return __privateGet2(this, _liElement); } get buttonElement() { return __privateGet2(this, _buttonElement); } } _liElement = /* @__PURE__ */ new WeakMap(), _buttonElement = /* @__PURE__ */ new WeakMap(), _onClick = /* @__PURE__ */ new WeakMap(); class NextPageManager extends PageButtonManagerBase { get disabled() { return this.paginationManager.currentPage >= this.paginationManager.totalPages; } get caption() { return "بعد"; } get pageNumber() { } constructor(paginationManager) { super(paginationManager), this.refresh(); } onClick() { this.paginationManager.currentPage < this.paginationManager.totalPages && this.paginationManager.setActivePage(this.paginationManager.currentPage + 1); } } class PageButtonNumberManager extends PageButtonManagerBase { constructor(paginationManager, pageNumber) { super(paginationManager), this.pageNumber = pageNumber, this.refresh(); } get disabled() { return !1; } get caption() { var _a; return ((_a = this.pageNumber) == null ? void 0 : _a.toString()) || "??"; } onClick() { this.paginationManager.setActivePage(this.pageNumber); } } class PageButtonSeperatorManager extends PageButtonManagerBase { get disabled() { return !0; } get caption() { return "..."; } get pageNumber() { } constructor(paginationManager) { super(paginationManager), this.buttonElement.classList.add("separator"), this.refresh(); } onClick() { } } class PreviousPageManager extends PageButtonManagerBase { get disabled() { return this.paginationManager.currentPage === 1; } get caption() { return "قبل"; } get pageNumber() { } constructor(paginationManager) { super(paginationManager), this.refresh(); } onClick() { this.paginationManager.currentPage > 1 && this.paginationManager.setActivePage(this.paginationManager.currentPage - 1); } } var _totalPages, totalPages_get, _currentPage, currentPage_get, _previousPageManager, _nextPageManager, _pages, _initializeLessThan11, _initializeLessThan16, initializeLessThan16_fn, _initializeLessThan16To8, initializeLessThan16To8_fn, _initializeLessThan16MoreThan8, initializeLessThan16MoreThan8_fn, _initializeMoreThan15; class PagesManager { constructor(paginationManager) { __privateAdd2(this, _totalPages), __privateAdd2(this, _currentPage), __privateAdd2(this, _initializeLessThan16), __privateAdd2(this, _initializeLessThan16To8), __privateAdd2(this, _initializeLessThan16MoreThan8), __privateAdd2(this, _previousPageManager, void 0), __privateAdd2(this, _nextPageManager, void 0), __privateAdd2(this, _pages, []), __publicField2(this, "initialize", () => { __privateSet2(this, _pages, []), this.paginationManager.totalPages < 11 ? __privateGet2(this, _initializeLessThan11).call(this) : this.paginationManager.totalPages < 16 ? __privateMethod2(this, _initializeLessThan16, initializeLessThan16_fn).call(this) : __privateGet2(this, _initializeMoreThan15).call(this); }), __privateAdd2(this, _initializeLessThan11, () => { for (let page = 1; page <= this.paginationManager.totalPages; page++) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, page)); }), __privateAdd2(this, _initializeMoreThan15, () => { if (__privateGet2(this, _currentPage, currentPage_get) < 5) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 2)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 3)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 4)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 5)), __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 2)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 0)); else if (__privateGet2(this, _currentPage, currentPage_get) > 4 && __privateGet2(this, _currentPage, currentPage_get) < __privateGet2(this, _totalPages, totalPages_get) - 3) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 2)), __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _currentPage, currentPage_get) - 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _currentPage, currentPage_get) - 0)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _currentPage, currentPage_get) + 1)), __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 0)); else if (__privateGet2(this, _currentPage, currentPage_get) >= this.totalPages_3 && __privateGet2(this, _currentPage, currentPage_get) <= __privateGet2(this, _totalPages, totalPages_get)) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 2)), __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 5)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 4)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 3)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 2)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 0)); else throw new Error(`Total page : '${__privateGet2(this, _totalPages, totalPages_get)}' Current Page: '${__privateGet2(this, _currentPage, currentPage_get)}'`); }), __publicField2(this, "refresh", () => { __privateGet2(this, _previousPageManager).remove(), __privateGet2(this, _pages).forEach((button) => { button.liElement.remove(); }), __privateGet2(this, _nextPageManager).remove(), this.initialize(); }), this.paginationManager = paginationManager, __privateSet2(this, _previousPageManager, new PreviousPageManager(this.paginationManager)), __privateSet2(this, _nextPageManager, new NextPageManager(this.paginationManager)); } get previousPageManager() { return __privateGet2(this, _previousPageManager); } get nextPageManager() { return __privateGet2(this, _nextPageManager); } get pagesButton() { return __privateGet2(this, _pages); } get totalPages_3() { return __privateGet2(this, _totalPages, totalPages_get) - 3; } } _totalPages = /* @__PURE__ */ new WeakSet(), totalPages_get = function() { return this.paginationManager.totalPages; }, _currentPage = /* @__PURE__ */ new WeakSet(), currentPage_get = function() { return this.paginationManager.currentPage; }, _previousPageManager = /* @__PURE__ */ new WeakMap(), _nextPageManager = /* @__PURE__ */ new WeakMap(), _pages = /* @__PURE__ */ new WeakMap(), _initializeLessThan11 = /* @__PURE__ */ new WeakMap(), _initializeLessThan16 = /* @__PURE__ */ new WeakSet(), initializeLessThan16_fn = function() { __privateGet2(this, _currentPage, currentPage_get) < 8 ? __privateMethod2(this, _initializeLessThan16To8, initializeLessThan16To8_fn).call(this) : __privateMethod2(this, _initializeLessThan16MoreThan8, initializeLessThan16MoreThan8_fn).call(this); }, _initializeLessThan16To8 = /* @__PURE__ */ new WeakSet(), initializeLessThan16To8_fn = function() { for (let pageNumber = 1; pageNumber <= 8; pageNumber++) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, pageNumber)); __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get) - 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, __privateGet2(this, _totalPages, totalPages_get))); }, _initializeLessThan16MoreThan8 = /* @__PURE__ */ new WeakSet(), initializeLessThan16MoreThan8_fn = function() { __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 1)), __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, 2)), __privateGet2(this, _pages).push(new PageButtonSeperatorManager(this.paginationManager)); for (let pageNumber = __privateGet2(this, _totalPages, totalPages_get) - 8; pageNumber <= __privateGet2(this, _totalPages, totalPages_get); pageNumber++) __privateGet2(this, _pages).push(new PageButtonNumberManager(this.paginationManager, pageNumber)); }, _initializeMoreThan15 = /* @__PURE__ */ new WeakMap(); var _paginationNavManager, _paginationStyleManager, _pagesManager, _currentPage2, _totalPages2, _triggerEvents, _events; class PaginationManager { constructor() { __privateAdd2(this, _paginationNavManager, void 0), __privateAdd2(this, _paginationStyleManager, void 0), __privateAdd2(this, _pagesManager, void 0), __privateAdd2(this, _currentPage2, 1), __privateAdd2(this, _totalPages2, 1), __publicField2(this, "setActivePage", (newPageNumber) => { __privateGet2(this, _triggerEvents).call(this, "onCurrentPageChange", newPageNumber, __privateGet2(this, _currentPage2)), __privateSet2(this, _currentPage2, newPageNumber), __privateGet2(this, _paginationNavManager).refresh(); }), __publicField2(this, "setData", (totalPages, currentPage) => { __privateSet2(this, _totalPages2, totalPages || 1), __privateSet2(this, _currentPage2, currentPage || 1), this.refresh(); }), __publicField2(this, "refresh", () => { __privateGet2(this, _paginationNavManager).refresh(); }), __privateAdd2(this, _triggerEvents, async (eventName, newPageNumber, oldPageNumber) => { __privateGet2(this, _events).filter((i) => i[0] === eventName).forEach(async (eventData) => { eventData[1](newPageNumber, oldPageNumber); }); }), __publicField2(this, "addEventListener", (eventName, eventCallBackFunction) => { __privateGet2(this, _events).push([eventName, eventCallBackFunction]); }), __privateAdd2(this, _events, []), __privateSet2(this, _pagesManager, new PagesManager(this)), __privateSet2(this, _paginationStyleManager, new PaginationStyleManager(this)), __privateSet2(this, _paginationNavManager, new PaginationNavManager(this)); } get paginationNavManager() { return __privateGet2(this, _paginationNavManager); } get paginationStyleManager() { return __privateGet2(this, _paginationStyleManager); } get pagesManager() { return __privateGet2(this, _pagesManager); } get navElement() { return __privateGet2(this, _paginationNavManager).navElement; } get currentPage() { return __privateGet2(this, _currentPage2); } get totalPages() { return __privateGet2(this, _totalPages2); } } _paginationNavManager = /* @__PURE__ */ new WeakMap(), _paginationStyleManager = /* @__PURE__ */ new WeakMap(), _pagesManager = /* @__PURE__ */ new WeakMap(), _currentPage2 = /* @__PURE__ */ new WeakMap(), _totalPages2 = /* @__PURE__ */ new WeakMap(), _triggerEvents = /* @__PURE__ */ new WeakMap(), _events = /* @__PURE__ */ new WeakMap(); var _oldRow, _newRow, _setActiveRow, setActiveRow_fn, _setActiveCol, setActiveCol_fn, _row, _col, _getFirstFocusableRow, _getFirstFocusableCol; class SelectActiveCellManager { constructor(tableManager) { __privateAdd(this, _setActiveRow); __privateAdd(this, _setActiveCol); __publicField(this, "focus", () => { var _a; (_a = this.activeRow) == null || _a.inValidate(); }); __privateAdd(this, _oldRow, void 0); __privateAdd(this, _newRow, void 0); __publicField(this, "cell"); __privateAdd(this, _row, 1); __privateAdd(this, _col, 1); __privateAdd(this, _getFirstFocusableRow, () => 1); __privateAdd(this, _getFirstFocusableCol, () => 1); this.tableManager = tableManager, this.cell = [this.rowIndex, this.colIndex]; } setActiveCell(value) { var _a, _b; __privateMethod(this, _setActiveRow, setActiveRow_fn).call(this, value[0]), __privateMethod(this, _setActiveCol, setActiveCol_fn).call(this, value[0]), this.cell = [this.rowIndex, this.colIndex], (_a = __privateGet(this, _oldRow)) == null || _a.inValidate(), (_b = __privateGet(this, _newRow)) == null || _b.inValidate(); } get isCurrentCellEditable() { return !0; } getCellElement(_row2, _col3) { } get rowIndex() { return __privateGet(this, _row) ? __privateGet(this, _row) : __privateGet(this, _getFirstFocusableRow).call(this); } get activeRow() { const tr = this.tableManager.tableElement.rows[this.rowIndex]; if (tr) return tr[this.tableManager.any.rowInentifier]; } get colIndex() { return __privateGet(this, _col) ? __privateGet(this, _col) : __privateGet(this, _getFirstFocusableCol).call(this); } } _oldRow = new WeakMap(), _newRow = new WeakMap(), _setActiveRow = new WeakSet(), setActiveRow_fn = function(newRowIndex) { if (typeof __privateGet(this, _row) == "number") { const currentRow = this.tableManager.tableElement.rows[__privateGet(this, _row)]; currentRow ? (currentRow.classList.remove("active"), __privateSet(this, _oldRow, currentRow[this.tableManager.any.rowInentifier])) : __privateSet(this, _oldRow, void 0); } else __privateSet(this, _oldRow, void 0); __privateSet(this, _row, newRowIndex); const newRow = this.tableManager.tableElement.rows[__privateGet(this, _row)]; newRow && (newRow.classList.add("active"), __privateSet(this, _newRow, newRow[this.tableManager.any.rowInentifier])); }, _setActiveCol = new WeakSet(), setActiveCol_fn = function(newColIndex) { if (typeof __privateGet(this, _row) == "number") { const currentCol = this.tableManager.tableElement.rows[__privateGet(this, _col)]; currentCol && currentCol.classList.remove("active"); } __privateSet(this, _col, newColIndex); }, _row = new WeakMap(), _col = new WeakMap(), _getFirstFocusableRow = new WeakMap(), _getFirstFocusableCol = new WeakMap(); var _container; class SelectTableRowInformationManager { constructor(rowManager) { __publicField(this, "dispose", () => { __privateGet(this, _container).remove(); }); __privateAdd(this, _container, void 0); this.rowManager = rowManager, __privateSet(this, _container, document.createElement("div")), __privateGet(this, _container).style.width = "100$", __privateGet(this, _container).style.height = "2px", __privateGet(this, _container).style.display = "table-row", __privateGet(this, _container).style.backgroundColor = "#0400ff", this.rowManager.trBody.appendChild(__privateGet(this, _container)); } } _container = new WeakMap(); var _information, _amisaCellManagerSymbol, _tr, _trBody, _initialize; const _SelectTableRowManager = class _SelectTableRowManager { constructor(tableManager, rowValues) { __publicField(this, "activate", (cell) => { this.tableManager.activeCell = [this.tr.rowIndex, cell.td.cellIndex]; }); __privateAdd(this, _information, void 0); __publicField(this, "height"); __publicField(this, "inValidate", () => { this.isActiveRow ? (this.tr.classList.add("active"), __privateGet(this, _information) || __privateSet(this, _information, new SelectTableRowInformationManager(this))) : (this.tr.classList.remove("active"), __privateGet(this, _information) && __privateGet(this, _information).dispose()); for (var cellIndex = 0; cellIndex < this.tr.cells.length; cellIndex++) this.tr.cells[cellIndex][__privateGet(this, _amisaCellManagerSymbol)].invalidate(); }); __privateAdd(this, _amisaCellManagerSymbol, "amisaCellManager"); __privateAdd(this, _tr, void 0); __privateAdd(this, _trBody, void 0); __privateAdd(this, _initialize, () => { __privateSet(this, _tr, document.createElement("tr")), __privateSet(this, _trBody, document.createElement("tbody")), __privateSet(this, _information, new SelectTableRowInformationManager(this)), __privateGet(this, _tr).style.height = "24px", __privateGet(this, _trBody).style.height = "24px", __privateGet(this, _trBody).appendChild(__privateGet(this, _tr)), this.tableManager.tableHeadManager.columns.forEach((column) => { var cellManager = column.getCellManager(this, this.rowValues[column.index]); if (__privateGet(this, _tr)) __privateGet(this, _tr).appendChild(cellManager.td); else throw new Error("tr can not be null or undefined"); }), __privateGet(this, _tr)[this.tableManager.any.rowInentifier] = this; }); this.tableManager = tableManager, this.rowValues = rowValues, __privateGet(this, _initialize).call(this); } get newRow() { return this.tr.rowIndex === this.tableManager.rowCount; } get activeCol() { const colIndex = this.tableManager.activeCell[1]; return this.tableManager.any.tableHeadManager.columns[colIndex]; } get any() { return this; } get tr() { if (__privateGet(this, _tr)) return __privateGet(this, _tr); throw new Error("tr can not null or undefined!!!"); } get trBody() { if (__privateGet(this, _trBody)) return __privateGet(this, _trBody); throw new Error("tr can not null or undefined!!!"); } static create(tableManager, rowValues) { const row = new _SelectTableRowManager(tableManager, rowValues); return tableManager.tableElement.appendChild(row.trBody), row; } get isActiveRow() { return this.tr.rowIndex === this.tableManager.activeCell[0]; } get isFristRow() { return this.tr.rowIndex === 1; } get isLastRow() { return this.tr.rowIndex === this.tableManager.tableElement.rows.length; } get firstCell() { return this.getCellManager(1); } get lastCell() { const index = this.tr.cells.length - 1; return this.getCellManager(index); } getCellManager(cellIndex) { const cell = this.tr.cells[cellIndex]; if (cell) return cell[__privateGet(this, _amisaCellManagerSymbol)]; throw new Error("can not find cell by this index : " + cellIndex); } }; _information = new WeakMap(), _amisaCellManagerSymbol = new WeakMap(), _tr = new WeakMap(), _trBody = new WeakMap(), _initialize = new WeakMap(); let SelectTableRowManager = _SelectTableRowManager; var _containerElement, _tableElement; class SelectTableBinderManager { constructor(tableManager) { __publicField(this, "containerId", "root"); __privateAdd(this, _containerElement, void 0); __privateAdd(this, _tableElement, void 0); __publicField(this, "refresh", () => { var _a, _b; (_b = (_a = this.tableManager.data) == null ? void 0 : _a.rows) == null || _b.forEach((row) => { SelectTableRowManager.create(this.tableManager, row); }); }); this.tableManager = tableManager; } get containerElement() { if (__privateGet(this, _containerElement)) return __privateGet(this, _containerElement); if (__privateSet(this, _containerElement, document.getElementById(this.containerId)), __privateGet(this, _containerElement)) return __privateGet(this, _containerElement); throw new Error("can not fine container of table id: " + this.containerId); } get tableElement() { if (__privateGet(this, _tableElement)) return __privateGet(this, _tableElement); throw new Error("can not initialize table!!"); } } _containerElement = new WeakMap(), _tableElement = new WeakMap(); var _tableManager, _td; class SelectTableCellManager { constructor(row, col, value) { __privateAdd(this, _tableManager, void 0); __privateAdd(this, _td, void 0); __publicField(this, "activate", () => { this.row.activate(this); }); __publicField(this, "invalidate", () => { this.isActiveCell ? __privateGet(this, _td).classList.add("active") : (__privateGet(this, _td).classList.remove("active"), __privateGet(this, _td).textContent = this.textContent); }); this.row = row, this.col = col, this.value = value, __privateSet(this, _tableManager, row.tableManager), __privateSet(this, _td, document.createElement("td")), __privateGet(this, _td).amisaCellManager = this, __privateGet(this, _td).textContent = this.textContent, __privateGet(this, _td).addEventListener("mouseup", this.activate); } get tableManager() { return __privateGet(this, _tableManager); } get tr() { return this.row.tr; } get textContent() { var _a; return (_a = this.value) == null ? void 0 : _a.toString(); } get td() { return __privateGet(this, _td); } get isActiveCell() { return this.row.isActiveRow && this.row.activeCol == this.col; } } _tableManager = new WeakMap(), _td = new WeakMap(); var _col2, _th, _index; class SelectTableColumnManager { constructor(selectTableHeadManager, colType, json) { __publicField(this, "visible", !0); __privateAdd(this, _col2, void 0); __privateAdd(this, _th, void 0); __privateAdd(this, _index, void 0); __publicField(this, "title"); __publicField(this, "width"); __publicField(this, "locales"); __publicField(this, "getCellManager", (row, value) => { const finalValue = this.formater(value); return new SelectTableCellManager(row, this, finalValue); }); this.selectTableHeadManager = selectTableHeadManager, this.colType = colType, this.json = json, __privateSet(this, _col2, document.createElement("col")), __privateSet(this, _th, document.createElement("th")), this.index = selectTableHeadManager.columns.length, this.visible = json.hide || !0, this.locales = json.locales || "fa-IR", this.title = json.title || "text??", this.width = json.width || "filler", __privateGet(this, _th).textContent = this.title, __privateGet(this, _th).scope = "col", typeof this.width == "number" && this.width > 0 ? (__privateGet(this, _col2).style.minWidth = `${this.width}px`, __privateGet(this, _col2).style.maxWidth = `${this.width}px`, __privateGet(this, _col2).style.width = `${this.width}px`) : typeof this.width == "string" && this.width === "filler" && (__privateGet(this, _col2).style.width = "100%"); } get index() { if (typeof __privateGet(this, _index) == "number") return __privateGet(this, _index); throw new Error("Index of column can not be undefined!!"); } set index(indexValue) { if (typeof __privateGet(this, _index) == "number") throw new Error("Can not change value of index column"); __privateSet(this, _index, indexValue); } get col() { return __privateGet(this, _col2); } get th() { return __privateGet(this, _th); } get any() { return this; } } _col2 = new WeakMap(), _th = new WeakMap(), _index = new WeakMap(); class SelectTableDateColumnManager extends SelectTableColumnManager { constructor(selectTableHeadManager, colType, json) { super(selectTableHeadManager, colType, json); __publicField(this, "formater", (value) => typeof value == "string" ? value.replace(/\d/g, (d) => "۰۱۲۳۴۵۶۷۸۹"[d]) : value); this.title = json.title || "date??", this.width = json.width || 75; } } class SelectTableNumColumnManager extends SelectTableColumnManager { constructor(selectTableHeadManager, colType, json) { super(selectTableHeadManager, colType, json); __publicField(this, "formater", (value) => typeof value == "number" ? value.toLocaleString(this.locales, { maximumFractionDigits: 0 }) : value); this.title = json.title || "num??", this.width = json.width || 50; } } class SelectTableAmountColumnManager extends SelectTableColumnManager { constructor(selectTableHeadManager, colType, json) { super(selectTableHeadManager, colType, json); __publicField(this, "formater", (value) => typeof value == "number" ? value.toLocaleString(this.locales, { maximumFractionDigits: 0 }) : value); } } class SelectTableStringColumnManager extends SelectTableColumnManager { constructor(selectTableHeadManager, colType, json) { super(selectTableHeadManager, colType, json); __publicField(this, "formater", (value) => value); } } var _tableHeadRowElement, _tableHeadElement, _cols, _initializeColumns, _initializeNumColumn, _initializeAmountColumn, _initializeDateColumn, _initializeStringColumn; class SelectTableHeadManager { constructor(tableMager) { __privateAdd(this, _tableHeadRowElement, void 0); __privateAdd(this, _tableHeadElement, void 0); __privateAdd(this, _cols, []); __publicField(this, "initialize", (columns) => { __privateSet(this, _cols, []), __privateSet(this, _tableHeadElement, document.createElement("thead")), __privateSet(this, _tableHeadRowElement, document.createElement("tr")), __privateGet(this, _initializeColumns).call(this, columns), __privateGet(this, _tableHeadElement).appendChild(__privateGet(this, _tableHeadRowElement)), this.tableMager.tableElement.appendChild(__privateGet(this, _tableHeadElement)); }); __privateAdd(this, _initializeColumns, (clmns) => { clmns == null || clmns.forEach((clmn) => { let column; switch (clmn.type) { case "num": column = __privateGet(this, _initializeNumColumn).call(this, clmn); break; case "date": column = __privateGet(this, _initializeDateColumn).call(this, clmn); break; case "amount": column = __privateGet(this, _initializeAmountColumn).call(this, clmn); break; default: column = __privateGet(this, _initializeStringColumn).call(this, clmn); break; } __privateGet(this, _cols).push(column), this.tableMager.tableElement.appendChild(column.col), __privateGet(this, _tableHeadRowElement).appendChild(column.th); }); }); __privateAdd(this, _initializeNumColumn, (clmn) => (clmn.title = clmn.title || "num??", clmn.width = clmn.width || 50, new SelectTableNumColumnManager(this, "num", clmn))); __privateAdd(this, _initializeAmountColumn, (clmn) => (clmn.title = clmn.title || "amout??", clmn.width = clmn.width || 120, new SelectTableAmountColumnManager(this, "amount", clmn))); __privateAdd(this, _initializeDateColumn, (clmn) => (clmn.title = clmn.title || "date??", clmn.width = clmn.width || 90, new SelectTableDateColumnManager(this, "date", clmn))); __privateAdd(this, _initializeStringColumn, (clmn) => (clmn.title = clmn.title || "string??", clmn.width = clmn.width || "filler", new SelectTableStringColumnManager(this, "string", clmn))); this.tableMager = tableMager; } get tableHeadRowElement() { return __privateGet(this, _tableHeadRowElement); } get tableHeadElement() { if (__privateGet(this, _tableHeadElement)) return __privateGet(this, _tableHeadElement); if (__privateGet(this, _tableHeadElement)) return __privateGet(this, _tableHeadElement); throw new Error("table header can not be generate"); } get columns() { return __privateGet(this, _cols); } } _tableHeadRowElement = new WeakMap(), _tableHeadElement = new WeakMap(), _cols = new WeakMap(), _initializeColumns = new WeakMap(), _initializeNumColumn = new WeakMap(), _initializeAmountColumn = new WeakMap(), _initializeDateColumn = new WeakMap(), _initializeStringColumn = new WeakMap(); var _tableElement2, _removeOldTable; class SelectTableManager { constructor(tableManager) { __privateAdd(this, _tableElement2, void 0); __privateAdd(this, _removeOldTable, () => { var existedTable = this.tableManager.formElement.querySelector("table#amisaSelect"); existedTable && (this.tableManager.formElement.removeChild(existedTable), __privateSet(this, _tableElement2, void 0)); }); __publicField(this, "reCreateTable", () => { __privateGet(this, _removeOldTable).call(this), __privateSet(this, _tableElement2, document.createElement("table")), __privateGet(this, _tableElement2).appendChild(this.tableManager.tableStyleElement), __privateGet(this, _tableElement2).style.overflow = "scroll", __privateGet(this, _tableElement2).style.display = "block", __privateGet(this, _tableElement2).style.border = "solid .1px #00000050", __privateGet(this, _tableElement2).style.borderCollapse = "collapse", __privateGet(this, _tableElement2).id = "amisaSelect"; }); __publicField(this, "setTableSize", (table) => { if (!table) return; const rec = this.tableManager.containerElement.getBoundingClientRect(), com = window.getComputedStyle(this.tableManager.containerElement), paddingLeft = parseInt(com.paddingLeft) || 0, paddingRight = parseInt(com.paddingRight) || 0, paddingTop = parseInt(com.paddingTop) || 0, paddingBottom = parseInt(com.paddingBottom) || 0, marginLeft = parseInt(com.marginLeft) || 0, marginRight = parseInt(com.marginRight) || 0, marginTop = parseInt(com.marginTop) || 0, marginBottom = parseInt(com.marginBottom) || 0; table.style.width = `${rec.width - paddingLeft - paddingRight - marginLeft - marginRight}px`, table.style.height = `${rec.height - paddingTop - paddingBottom - marginTop - marginBottom}px`; }); this.tableManager = tableManager, window.addEventListener("resize", () => { this.setTableSize(this.tableElement); }); } get tableElement() { if (__privateGet(this, _tableElement2)) return __privateGet(this, _tableElement2); throw new Error("can not initialize table!!"); } } _tableElement2 = new WeakMap(), _removeOldTable = new WeakMap(); var _styleElement2, _initialize2; class SelectTableStyleManager { constructor(tableManager) { __privateAdd(this, _styleElement2, void 0); __privateAdd(this, _initialize2, () => { __privateSet(this, _styleElement2, document.createElement("style")), __privateGet(this, _styleElement2).textContent = ` td, th { border: 1px solid #ddd; padding: 1px; text-align: center; overflow-wrap: anywhere; } tbody:nth-child(odd) { background-color: #213547d6; color: #f2f2f2; } tbody:nth-child(even){ background-color: #f2f2f2; color: #213547; } tbody:hover { background: #029CFD;} tr.active {background-color: #029cfdad; } th { padding-top: 12px; padding-bottom: 12px; background-color: #04AA6D; color: white; font-size: small } form { direction:rtl } `; }); this.tableManager = tableManager; } get styleElement() { if (__privateGet(this, _styleElement2)) return __privateGet(this, _styleElement2); if (__privateGet(this, _initialize2).call(this), __privateGet(this, _styleElement2)) return __privateGet(this, _styleElement2); throw new Error("table style can not be null or undefined"); } } _styleElement2 = new WeakMap(), _initialize2 = new WeakMap(); class SelectTableCellNavigation { constructor(tableManager) { __publicField(this, "getNextActiveCell", () => { if (!this.activeRow) return null; const cellIndex = this.tableManager.activeCellManager.colIndex + 1; for (var i = cellIndex; i < this.activeRow.tr.cells.length; i++) return this.activeRow.getCellManager(i); const row = this.nextRow; return row ? row.firstCell : null; }); __publicField(this, "getPreviousActiveCell", () => { if (!this.activeRow) return null; const cellIndex = this.tableManager.activeCellManager.colIndex - 1; for (var i = cellIndex; i > 0; i--) return this.activeRow.getCellManager(i); const row = this.previouseRow; return row ? row.lastCell : null; }); __publicField(this, "getUpActiveCell", () => { var _a, _b; if (!this.activeRow) return ((_a = this.getRow(1)) == null ? void 0 : _a.firstCell) || null; const cellIndex = this.tableManager.activeCellManager.colIndex; return ((_b = this.previouseRow) == null ? void 0 : _b.getCellManager(cellIndex)) || null; }); __publicField(this, "getDownActiveCell", () => { var _a, _b; if (!this.activeRow) return ((_a = this.getRow(1)) == null ? void 0 : _a.firstCell) || null; const cellIndex = this.tableManager.activeCellManager.colIndex; return ((_b = this.nextRow) == null ? void 0 : _b.getCellManager(cellIndex)) || null; }); this.tableManager = tableManager; } get activeRow() { return this.tableManager.activeCellManager.activeRow; } get previouseRow() { if (!this.activeRow) return this.getRow(1); const rowIndex = this.activeRow.tr.rowIndex - 1; for (var i = rowIndex; i > 0; i--) return this.getRow(i); return null; } get nextRow() { if (!this.activeRow || this.activeRow.isLastRow) return null; const rowIndex = this.activeRow.tr.rowIndex + 1; for (var i = rowIndex; i <= this.tableManager.tableElement.rows.length; i++) return this.getRow(i); return null; } getRow(index) { const row = this.tableManager.tableElement.rows[index]; return row ? row[this.tableManager.any.rowInentifier] : null; } } var _formElement, _containerElement2, _tableCellNavigation, _onKeyDown; class SelectTableFormManager { constructor(gridViewManager, containerKey) { __privateAdd(this, _formElement, void 0); __privateAdd(this, _containerElement2, void 0); __privateAdd(this, _tableCellNavigation, void 0); __privateAdd(this, _onKeyDown, (e) => { this.handle(e); }); __publicField(this, "handle", (e) => { var _a, _b; if (isArrowRightKey(e, !0)) { const previous = __privateGet(this, _tableCellNavigation).getPreviousActiveCell(); previous ? previous.activate() : console.log("must go to previous element"); } else if (isArrowLeftKey(e)) { const next = __privateGet(this, _tableCellNavigation).getNextActiveCell(); next ? next.activate() : console.log("nex tor"); } else isArrowUpKey(e) ? (_a = __privateGet(this, _tableCellNavigation).getUpActiveCell()) == null || _a.activate() : isArrowDownKey(e) && ((_b = __privateGet(this, _tableCellNavigation).getDownActiveCell()) == null || _b.activate()); }); if (this.gridViewManager = gridViewManager, this.containerKey = containerKey, __privateSet(this, _containerElement2, document.getElementById(this.containerKey)), !__privateGet(this, _containerElement2)) throw new Error("can not fine container of table id: " + this.containerKey); __privateSet(this, _tableCellNavigation, new SelectTableCellNavigation(this.gridViewManager)), __privateSet(this, _formElement, document.createElement("form")), __privateGet(this, _formElement).tabIndex = 0, __privateGet(this, _formElement).addEventListener("keydown", __privateGet(this, _onKeyDown)), new IntersectionObserver((entries) => { entries.forEach((_entry) => { setTimeout(() => { this.gridViewManager.activeCellManager.focus(), __privateGet(this, _formElement).focus(); }, 100); }); }, { rootMargin: "0px", threshold: 1 }).observe(this.formElement); } get any() { return this; } get formElement() { return __privateGet(this, _formElement); } get containerElement() { return __privateGet(this, _containerElement2); } get tableCellNavigation() { return __privateGet(this, _tableCellNavigation); } } _formElement = new WeakMap(), _containerElement2 = new WeakMap(), _tableCellNavigation = new WeakMap(), _onKeyDown = new WeakMap(); var _paginationManager; class GridViewBindPagination { constructor(gridViewManager) { __privateAdd(this, _paginationManager, void 0); __publicField(this, "onCurrentPageChanged", (newPageNumber, oldPageNumber) => { this.gridViewManager.formElement.dispatchEvent(new Event("change", { bubbles: !0, cancelable: !1, composed: !0 })); }); __publicField(this, "setData", (pagination) => { __privateGet(this, _paginationManager).setData((pagination == null ? void 0 : pagination.totalPage) || 1, (pagination == null ? void 0 : pagination.currentPage) || 1); }); this.gridViewManager = gridViewManager, __privateSet(this, _paginationManager, new PaginationManager()), __privateGet(this, _paginationManager).addEventListener("onCurrentPageChange", this.onCurrentPageChanged); } get pagination() { return __privateGet(this, _paginationManager); } } _paginationManager = new WeakMap(); var _pagination, _selectTableBinderManager, _data, _activeCellManager, _initializer, _selectTableFormManager, _tableHeadManager, _reCreate; class GridViewManager { constructor(containerKey) { __privateAdd(this, _pagination, void 0); __privateAdd(this, _selectTableBinderManager, void 0); __privateAdd(this, _data, void 0); __privateAdd(this, _activeCellManager, new SelectActiveCellManager(this)); __privateAdd(this, _initializer, void 0); __privateAdd(this, _selectTableFormManager, void 0); __privateAdd(this, _tableHeadManager, void 0); __publicField(this, "tableStyleManager"); __privateAdd(this, _reCreate, () => { __privateGet(this, _initializer).reCreateTable(); }); __publicField(this, "setData", (data) => { data && data.columns && (__privateSet(this, _data, data), __privateGet(this, _reCreate).call(this), __privateGet(this, _tableHeadManager).initialize(data.columns), __privateGet(this, _selectTableBinderManager).refresh(), __privateGet(this, _pagination).setData(__privateGet(this, _data).pagination), this.formElement.append(this.tableElement), this.formElement.append(this.pagination.pagination.navElement), this.containerElement.append(this.formElement), __privateGet(this, _initializer).setTableSize(this.tableElement)); }); __publicField(this, "getValues", () => ({ totalPages: __privateGet(this, _pagination).pagination.totalPages, currentPage: __privateGet(this, _pagination).pagination.currentPage, currentRowIndex: this.activeCell[0] })); __privateSet(this, _selectTableFormManager, new SelectTableFormManager(this, containerKey)), this.tableStyleManager = new SelectTableStyleManager(this), __privateSet(this, _tableHeadManager, new SelectTableHeadManager(this)), __privateSet(this, _pagination, new GridViewBindPagination(this)), __privateSet(this, _initializer, new SelectTableManager(this)), __privateSet(this, _selectTableBinderManager, new SelectTableBinderManager(this)), this.containerElement.style.overflow = "hidden", document.body.style.overflow = "hidden"; } get any() { return this; } get pagination() { return __privateGet(this, _pagination); } get data() { return __privateGet(this, _data); } get activeCellManager() { return __privateGet(this, _activeCellManager); } get activeCell() { return __privateGet(this, _activeCellManager).cell; } set activeCell(value) { __privateGet(this, _activeCellManager).setActiveCell(value); } get formElement() { return __privateGet(this, _selectTableFormManager).formElement; } get containerElement() { return __privateGet(this, _selectTableFormManager).containerElement; } get tableHeadElement() { return __privateGet(this, _tableHeadManager).tableHeadElement; } get tableHeadManager() { return __privateGet(this, _tableHeadManager); } get tableStyleElement() { return this.tableStyleManager.styleElement; } get tableElement() { return __privateGet(this, _initializer).tableElement; } get rowCount() { return this.tableElement.rows.length - 1; } } _pagination = new WeakMap(), _selectTableBinderManager = new WeakMap(), _data = new WeakMap(), _activeCellManager = new WeakMap(), _initializer = new WeakMap(), _selectTableFormManager = new WeakMap(), _tableHeadManager = new WeakMap(), _reCreate = new WeakMap(); export { GridViewManager, PaginationManager, isArrowDownKey, isArrowLeftKey, isArrowRightKey, isArrowUpKey };