UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

393 lines (379 loc) • 16 kB
/** * DevExtreme (cjs/renovation/ui/pager/content.js) * Version: 22.1.9 * Build date: Tue Apr 18 2023 * * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; function _typeof(obj) { 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) } exports.viewFunction = exports.PagerContentProps = exports.PagerContent = void 0; var _inferno = require("inferno"); var _inferno2 = require("@devextreme/runtime/inferno"); var _info = require("./info"); var _page_index_selector = require("./pages/page_index_selector"); var _selector = require("./page_size/selector"); var _consts = require("./common/consts"); var _pager_props = require("./common/pager_props"); var _combine_classes = require("../../utils/combine_classes"); var _widget = require("../common/widget"); var _accessibility = require("../../../ui/shared/accessibility"); var _excluded = ["className", "displayMode", "gridCompatibility", "hasKnownLastPage", "infoText", "infoTextRef", "infoTextVisible", "isLargeDisplayMode", "label", "lightModeEnabled", "maxPagesCount", "onKeyDown", "pageCount", "pageIndex", "pageIndexChange", "pageSize", "pageSizeChange", "pageSizes", "pageSizesRef", "pagesCountText", "pagesNavigatorVisible", "pagesRef", "rootElementRef", "rtlEnabled", "showInfo", "showNavigationButtons", "showPageSizes", "totalCount", "visible"]; function _objectWithoutProperties(source, excluded) { if (null == source) { return {} } var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) { continue } if (!Object.prototype.propertyIsEnumerable.call(source, key)) { continue } target[key] = source[key] } } return target } function _objectWithoutPropertiesLoose(source, excluded) { if (null == source) { return {} } var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) { continue } target[key] = source[key] } return target } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }) } else { obj[key] = value } return obj } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true } Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor) } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) { _defineProperties(Constructor.prototype, protoProps) } if (staticProps) { _defineProperties(Constructor, staticProps) } Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return "symbol" === _typeof(key) ? key : String(key) } function _toPrimitive(input, hint) { if ("object" !== _typeof(input) || null === input) { return input } var prim = input[Symbol.toPrimitive]; if (void 0 !== prim) { var res = prim.call(input, hint || "default"); if ("object" !== _typeof(res)) { return res } throw new TypeError("@@toPrimitive must return a primitive value.") } return ("string" === hint ? String : Number)(input) } function _assertThisInitialized(self) { if (void 0 === self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called") } return self } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass) } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) { o.__proto__ = p; return o }; return _setPrototypeOf(o, p) } 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) } var viewFunction = function(_ref) { var aria = _ref.aria, classes = _ref.classes, infoVisible = _ref.infoVisible, isLargeDisplayMode = _ref.isLargeDisplayMode, pageIndexSelectorVisible = _ref.pageIndexSelectorVisible, pagesContainerVisibility = _ref.pagesContainerVisibility, pagesContainerVisible = _ref.pagesContainerVisible, _ref$props = _ref.props, hasKnownLastPage = _ref$props.hasKnownLastPage, infoText = _ref$props.infoText, infoTextRef = _ref$props.infoTextRef, maxPagesCount = _ref$props.maxPagesCount, pageCount = _ref$props.pageCount, pageIndex = _ref$props.pageIndex, pageIndexChange = _ref$props.pageIndexChange, pageSize = _ref$props.pageSize, pageSizeChange = _ref$props.pageSizeChange, pageSizes = _ref$props.pageSizes, pageSizesRef = _ref$props.pageSizesRef, pagesCountText = _ref$props.pagesCountText, pagesRef = _ref$props.pagesRef, rtlEnabled = _ref$props.rtlEnabled, showNavigationButtons = _ref$props.showNavigationButtons, showPageSizes = _ref$props.showPageSizes, totalCount = _ref$props.totalCount, visible = _ref$props.visible, restAttributes = _ref.restAttributes, widgetRootElementRef = _ref.widgetRootElementRef; return (0, _inferno.normalizeProps)((0, _inferno.createComponentVNode)(2, _widget.Widget, _extends({ rootElementRef: widgetRootElementRef, rtlEnabled: rtlEnabled, classes: classes, visible: visible, aria: aria }, restAttributes, { children: [showPageSizes && (0, _inferno.createComponentVNode)(2, _selector.PageSizeSelector, { rootElementRef: pageSizesRef, isLargeDisplayMode: isLargeDisplayMode, pageSize: pageSize, pageSizeChange: pageSizeChange, pageSizes: pageSizes }), pagesContainerVisible && (0, _inferno.createVNode)(1, "div", _consts.PAGER_PAGES_CLASS, [infoVisible && (0, _inferno.createComponentVNode)(2, _info.InfoText, { rootElementRef: infoTextRef, infoText: infoText, pageCount: pageCount, pageIndex: pageIndex, totalCount: totalCount }), pageIndexSelectorVisible && (0, _inferno.createVNode)(1, "div", _consts.PAGER_PAGE_INDEXES_CLASS, (0, _inferno.createComponentVNode)(2, _page_index_selector.PageIndexSelector, { hasKnownLastPage: hasKnownLastPage, isLargeDisplayMode: isLargeDisplayMode, maxPagesCount: maxPagesCount, pageCount: pageCount, pageIndex: pageIndex, pageIndexChange: pageIndexChange, pagesCountText: pagesCountText, showNavigationButtons: showNavigationButtons, totalCount: totalCount }), 2, null, null, pagesRef)], 0, { style: (0, _inferno2.normalizeStyles)({ visibility: pagesContainerVisibility }) })] }))) }; exports.viewFunction = viewFunction; var PagerContentProps = Object.create(Object.prototype, _extends(Object.getOwnPropertyDescriptors(_pager_props.InternalPagerProps), Object.getOwnPropertyDescriptors({ infoTextVisible: true, isLargeDisplayMode: true }))); exports.PagerContentProps = PagerContentProps; var PagerContent = function(_InfernoComponent) { _inheritsLoose(PagerContent, _InfernoComponent); function PagerContent(props) { var _this; _this = _InfernoComponent.call(this, props) || this; _this.state = {}; _this.widgetRootElementRef = (0, _inferno.createRef)(); _this.__getterCache = {}; _this.setRootElementRef = _this.setRootElementRef.bind(_assertThisInitialized(_this)); _this.createFakeInstance = _this.createFakeInstance.bind(_assertThisInitialized(_this)); return _this } var _proto = PagerContent.prototype; _proto.createEffects = function() { return [new _inferno2.InfernoEffect(this.setRootElementRef, [])] }; _proto.getChildContext = function() { return _extends({}, this.context, { KeyboardActionContext: this.keyboardAction }) }; _proto.setRootElementRef = function() { var rootElementRef = this.props.rootElementRef; if (rootElementRef) { rootElementRef.current = this.widgetRootElementRef.current } }; _proto.createFakeInstance = function() { var _this2 = this; return { option: function() { return false }, element: function() { return _this2.widgetRootElementRef.current }, _createActionByOption: function() { return function(e) { var _this2$props$onKeyDow, _this2$props; null === (_this2$props$onKeyDow = (_this2$props = _this2.props).onKeyDown) || void 0 === _this2$props$onKeyDow ? void 0 : _this2$props$onKeyDow.call(_this2$props, e) } } } }; _proto.componentWillUpdate = function(nextProps, nextState, context) { _InfernoComponent.prototype.componentWillUpdate.call(this); if (this.props.onKeyDown !== nextProps.onKeyDown) { this.__getterCache.keyboardAction = void 0 } }; _proto.render = function() { var props = this.props; return viewFunction({ props: _extends({}, props), widgetRootElementRef: this.widgetRootElementRef, keyboardAction: this.keyboardAction, infoVisible: this.infoVisible, pageIndexSelectorVisible: this.pageIndexSelectorVisible, pagesContainerVisible: this.pagesContainerVisible, pagesContainerVisibility: this.pagesContainerVisibility, isLargeDisplayMode: this.isLargeDisplayMode, classes: this.classes, aria: this.aria, restAttributes: this.restAttributes }) }; _createClass(PagerContent, [{ key: "keyboardAction", get: function() { var _this3 = this; if (void 0 !== this.__getterCache.keyboardAction) { return this.__getterCache.keyboardAction } return this.__getterCache.keyboardAction = { registerKeyboardAction: function(element, action) { var fakePagerInstance = _this3.createFakeInstance(); return (0, _accessibility.registerKeyboardAction)("pager", fakePagerInstance, element, void 0, action) } } } }, { key: "infoVisible", get: function() { var _this$props = this.props, infoTextVisible = _this$props.infoTextVisible, showInfo = _this$props.showInfo; return showInfo && infoTextVisible } }, { key: "pageIndexSelectorVisible", get: function() { return 0 !== this.props.pageSize } }, { key: "normalizedDisplayMode", get: function() { var _this$props2 = this.props, displayMode = _this$props2.displayMode, lightModeEnabled = _this$props2.lightModeEnabled; if ("adaptive" === displayMode && void 0 !== lightModeEnabled) { return lightModeEnabled ? "compact" : "full" } return displayMode } }, { key: "pagesContainerVisible", get: function() { return !!this.props.pagesNavigatorVisible && this.props.pageCount > 0 } }, { key: "pagesContainerVisibility", get: function() { if ("auto" === this.props.pagesNavigatorVisible && 1 === this.props.pageCount && this.props.hasKnownLastPage) { return "hidden" } return } }, { key: "isLargeDisplayMode", get: function() { var displayMode = this.normalizedDisplayMode; var result = false; if ("adaptive" === displayMode) { result = this.props.isLargeDisplayMode } else { result = "full" === displayMode } return result } }, { key: "classes", get: function() { var _classesMap; var classesMap = (_classesMap = {}, _defineProperty(_classesMap, "".concat(this.props.className), !!this.props.className), _defineProperty(_classesMap, _consts.PAGER_CLASS, true), _defineProperty(_classesMap, _consts.LIGHT_MODE_CLASS, !this.isLargeDisplayMode), _classesMap); return (0, _combine_classes.combineClasses)(classesMap) } }, { key: "aria", get: function() { return { role: "navigation", label: this.props.label } } }, { key: "restAttributes", get: function() { var _this$props3 = this.props, restProps = (_this$props3.className, _this$props3.displayMode, _this$props3.gridCompatibility, _this$props3.hasKnownLastPage, _this$props3.infoText, _this$props3.infoTextRef, _this$props3.infoTextVisible, _this$props3.isLargeDisplayMode, _this$props3.label, _this$props3.lightModeEnabled, _this$props3.maxPagesCount, _this$props3.onKeyDown, _this$props3.pageCount, _this$props3.pageIndex, _this$props3.pageIndexChange, _this$props3.pageSize, _this$props3.pageSizeChange, _this$props3.pageSizes, _this$props3.pageSizesRef, _this$props3.pagesCountText, _this$props3.pagesNavigatorVisible, _this$props3.pagesRef, _this$props3.rootElementRef, _this$props3.rtlEnabled, _this$props3.showInfo, _this$props3.showNavigationButtons, _this$props3.showPageSizes, _this$props3.totalCount, _this$props3.visible, _objectWithoutProperties(_this$props3, _excluded)); return restProps } }]); return PagerContent }(_inferno2.InfernoComponent); exports.PagerContent = PagerContent; PagerContent.defaultProps = PagerContentProps;