Files
railwaysystem/RuoYi-Vue/ruoyi-ui/node_modules2/handsontable/translations/maps/linkedPhysicalIndexToValueMap.js
T
2026-09-10 15:40:10 +08:00

149 lines
5.6 KiB
JavaScript

"use strict";
exports.__esModule = true;
require("core-js/modules/es.error.cause.js");
var _indexMap = require("./indexMap");
var _physicallyIndexed = require("./utils/physicallyIndexed");
var _indexesSequence = require("./utils/indexesSequence");
var _actionsOnIndexes = require("./utils/actionsOnIndexes");
var _function = require("../../helpers/function");
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 _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/**
* Map for storing mappings from an physical index to a value. Those entries are linked and stored in a certain order.
*
* It does not update stored values on remove/add row or column action. Otherwise, order of entries is updated after
* such changes.
*
* @class LinkedPhysicalIndexToValueMap
*/
class LinkedPhysicalIndexToValueMap extends _indexMap.IndexMap {
constructor() {
super(...arguments);
/**
* Indexes and values corresponding to them (entries) are stored in a certain order.
*
* @private
* @type {Array<number>}
*/
_defineProperty(this, "orderOfIndexes", []);
}
/**
* Get full list of ordered values for particular indexes.
*
* @returns {Array}
*/
getValues() {
return this.orderOfIndexes.map(physicalIndex => this.indexedValues[physicalIndex]);
}
/**
* Set new values for particular indexes. Entries are linked and stored in a certain order.
*
* Note: Please keep in mind that `change` hook triggered by the method may not update cache of a collection immediately.
*
* @param {Array} values List of set values.
*/
setValues(values) {
this.orderOfIndexes = [...Array(values.length).keys()];
super.setValues(values);
}
/**
* Set value at index and add it to the linked list of entries. Entries are stored in a certain order.
*
* Note: Value will be added at the end of the queue.
*
* @param {number} index The index.
* @param {*} value The value to save.
* @param {number} position Position to which entry will be added.
*
* @returns {boolean}
*/
setValueAtIndex(index, value) {
let position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.orderOfIndexes.length;
if (index < this.indexedValues.length) {
this.indexedValues[index] = value;
if (this.orderOfIndexes.includes(index) === false) {
this.orderOfIndexes.splice(position, 0, index);
}
this.runLocalHooks('change');
return true;
}
return false;
}
/**
* Clear value for particular index.
*
* @param {number} physicalIndex Physical index.
*/
clearValue(physicalIndex) {
this.orderOfIndexes = (0, _indexesSequence.getListWithRemovedItems)(this.orderOfIndexes, [physicalIndex]);
if ((0, _function.isFunction)(this.initValueOrFn)) {
super.setValueAtIndex(physicalIndex, this.initValueOrFn(physicalIndex));
} else {
super.setValueAtIndex(physicalIndex, this.initValueOrFn);
}
}
/**
* Get length of the index map.
*
* @returns {number}
*/
getLength() {
return this.orderOfIndexes.length;
}
/**
* Set default values for elements from `0` to `n`, where `n` is equal to the handled variable.
*
* Note: Please keep in mind that `change` hook triggered by the method may not update cache of a collection immediately.
*
* @private
* @param {number} [length] Length of list.
*/
setDefaultValues() {
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.indexedValues.length;
this.orderOfIndexes.length = 0;
super.setDefaultValues(length);
}
/**
* Add values to list and reorganize. It updates list of indexes related to ordered values.
*
* @private
* @param {number} insertionIndex Position inside the list.
* @param {Array} insertedIndexes List of inserted indexes.
*/
insert(insertionIndex, insertedIndexes) {
this.indexedValues = (0, _physicallyIndexed.getListWithInsertedItems)(this.indexedValues, insertionIndex, insertedIndexes, this.initValueOrFn);
this.orderOfIndexes = (0, _actionsOnIndexes.getIncreasedIndexes)(this.orderOfIndexes, insertedIndexes);
super.insert(insertionIndex, insertedIndexes);
}
/**
* Remove values from the list and reorganize. It updates list of indexes related to ordered values.
*
* @private
* @param {Array} removedIndexes List of removed indexes.
*/
remove(removedIndexes) {
this.indexedValues = (0, _physicallyIndexed.getListWithRemovedItems)(this.indexedValues, removedIndexes);
this.orderOfIndexes = (0, _indexesSequence.getListWithRemovedItems)(this.orderOfIndexes, removedIndexes);
this.orderOfIndexes = (0, _actionsOnIndexes.getDecreasedIndexes)(this.orderOfIndexes, removedIndexes);
super.remove(removedIndexes);
}
/**
* Get every entry containing index and value, respecting order of indexes.
*
* @returns {Array}
*/
getEntries() {
return this.orderOfIndexes.map(physicalIndex => [physicalIndex, this.getValueAtIndex(physicalIndex)]);
}
}
exports.LinkedPhysicalIndexToValueMap = LinkedPhysicalIndexToValueMap;