UNPKG

ember-sortable

Version:
100 lines (93 loc) 2.28 kB
import { a as _defineProperty } from '../_rollupPluginBabelHelpers-a7bede49.js'; import s__default from '@ember/service'; class EmberSortableService extends s__default { constructor(...args) { super(...args); /** * Internal State for any groups currently in DOM * * { * groupName: { * groupModifier: object, * items: [] * } * } * @type {{}} */ _defineProperty(this, "groups", {}); } /** * Register a new group with the service * * @param {String} groupName * @param {SortableGroupModifier} groupModifier */ registerGroup(groupName, groupModifier) { if (this.groups[groupName] === undefined) { this.groups[groupName] = { groupModifier: groupModifier, items: [] }; } else { this.groups[groupName].groupModifier = groupModifier; } } /** * De-register a group with the service * * @param {String} groupName */ deregisterGroup(groupName) { delete this.groups[groupName]; } /** * Register an item with this group * * @method registerItem * @param {String} groupName * @param {SortableItemModifier} item */ registerItem(groupName, item) { const groupDef = this.fetchGroup(groupName); if (!groupDef) { return; } let items = groupDef.items; if (items.indexOf(item) === -1) { items = [...items, item]; } groupDef.items = items; } /** De-register an item with this group. @method deregisterItem @param groupName @param item */ deregisterItem(groupName, item) { const groupDef = this.fetchGroup(groupName); if (!groupDef) { return; } const items = groupDef.items; const index = items.indexOf(item); if (index !== -1) { const newItems = [...items.slice(0, index), ...items.slice(index + 1)]; groupDef.items = newItems; } } /** * Fetch a group definition * * @param {String} groupName * @returns {*} */ fetchGroup(groupName) { if (this.groups[groupName] === undefined) { this.registerGroup(groupName, undefined); } return this.groups[groupName]; } } export { EmberSortableService as default }; //# sourceMappingURL=ember-sortable-internal-state.js.map