UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

191 lines (190 loc) 7.01 kB
/** * DevExtreme (esm/__internal/ui/list/m_list.edit.provider.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import Class from "../../../core/class"; import $ from "../../../core/renderer"; import { noop } from "../../../core/utils/common"; import { extend } from "../../../core/utils/extend"; import { each } from "../../../core/utils/iterator"; import errors from "../../../ui/widget/ui.errors"; import { registry } from "./m_list.edit.decorator_registry"; const editOptionsRegistry = []; const registerOption = function(enabledFunc, decoratorTypeFunc, decoratorSubTypeFunc) { editOptionsRegistry.push({ enabled: enabledFunc, decoratorType: decoratorTypeFunc, decoratorSubType: decoratorSubTypeFunc }) }; registerOption((function() { return this.option("menuItems").length }), (() => "menu"), (function() { return this.option("menuMode") })); registerOption((function() { return !this.option("menuItems").length && this.option("allowItemDeleting") }), (function() { const mode = this.option("itemDeleteMode"); return "toggle" === mode || "slideButton" === mode || "swipe" === mode || "static" === mode ? "delete" : "menu" }), (function() { let mode = this.option("itemDeleteMode"); if ("slideItem" === mode) { mode = "slide" } return mode })); registerOption((function() { return "none" !== this.option("selectionMode") && this.option("showSelectionControls") }), (() => "selection"), (() => "default")); registerOption((function() { return this.option("itemDragging.allowReordering") || this.option("itemDragging.allowDropInsideItem") || this.option("itemDragging.group") }), (() => "reorder"), (() => "default")); const LIST_ITEM_BEFORE_BAG_CLASS = "dx-list-item-before-bag"; const LIST_ITEM_AFTER_BAG_CLASS = "dx-list-item-after-bag"; const DECORATOR_BEFORE_BAG_CREATE_METHOD = "beforeBag"; const DECORATOR_AFTER_BAG_CREATE_METHOD = "afterBag"; const DECORATOR_MODIFY_ELEMENT_METHOD = "modifyElement"; const DECORATOR_AFTER_RENDER_METHOD = "afterRender"; const DECORATOR_GET_EXCLUDED_SELECTORS_METHOD = "getExcludedSelectors"; class EditProvider extends(Class.inherit({})) { ctor(list) { this._list = list; this._fetchRequiredDecorators() } dispose() { var _this$_decorators; if (null !== (_this$_decorators = this._decorators) && void 0 !== _this$_decorators && _this$_decorators.length) { each(this._decorators, ((_, decorator) => { decorator.dispose() })) } } _fetchRequiredDecorators() { this._decorators = []; each(editOptionsRegistry, ((_, option) => { const optionEnabled = option.enabled.call(this._list); if (optionEnabled) { const decoratorType = option.decoratorType.call(this._list); const decoratorSubType = option.decoratorSubType.call(this._list); const decorator = this._createDecorator(decoratorType, decoratorSubType); this._decorators.push(decorator) } })) } _createDecorator(type, subType) { const decoratorClass = this._findDecorator(type, subType); return new decoratorClass(this._list) } _findDecorator(type, subType) { var _registry$type; const foundDecorator = null === (_registry$type = registry[type]) || void 0 === _registry$type ? void 0 : _registry$type[subType]; if (!foundDecorator) { throw errors.Error("E1012", type, subType) } return foundDecorator } modifyItemElement(args) { const $itemElement = $(args.itemElement); const config = { $itemElement: $itemElement }; this._prependBeforeBags($itemElement, config); this._appendAfterBags($itemElement, config); this._applyDecorators("modifyElement", config) } afterItemsRendered() { this._applyDecorators("afterRender") } _prependBeforeBags($itemElement, config) { const $beforeBags = this._collectDecoratorsMarkup("beforeBag", config, "dx-list-item-before-bag"); $itemElement.prepend($beforeBags) } _appendAfterBags($itemElement, config) { const $afterBags = this._collectDecoratorsMarkup("afterBag", config, "dx-list-item-after-bag"); $itemElement.append($afterBags) } _collectDecoratorsMarkup(method, config, containerClass) { const $collector = $("<div>"); each(this._decorators, (function() { const $container = $("<div>").addClass(containerClass); this[method](extend({ $container: $container }, config)); if ($container.children().length) { $collector.append($container) } })); return $collector.children() } _applyDecorators(method, config) { each(this._decorators, (function() { this[method](config) })) } _handlerExists(name) { if (!this._decorators) { return false } const decorators = this._decorators; const { length: length } = decorators; for (let i = 0; i < length; i++) { if (decorators[i][name] !== noop) { return true } } return false } _eventHandler(name, $itemElement, e) { if (!this._decorators) { return false } let response = false; const decorators = this._decorators; const { length: length } = decorators; for (let i = 0; i < length; i++) { response = decorators[i][name]($itemElement, e); if (response) { break } } return response } handleClick($itemElement, e) { return this._eventHandler("handleClick", $itemElement, e) } handleKeyboardEvents(currentFocusedIndex, moveFocusUp) { return this._eventHandler("handleKeyboardEvents", currentFocusedIndex, moveFocusUp) } handleEnterPressing(e) { return this._eventHandler("handleEnterPressing", e) } contextMenuHandlerExists() { return this._handlerExists("handleContextMenu") } handleContextMenu($itemElement, e) { return this._eventHandler("handleContextMenu", $itemElement, e) } getExcludedItemSelectors() { const excludedSelectors = []; this._applyDecorators("getExcludedSelectors", excludedSelectors); return excludedSelectors.join(",") } } export default EditProvider;