UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

1,317 lines (1,078 loc) 37.4 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { __decorate } from "tslib"; import { action, computed, isArrayLike, isObservableArray, isObservableObject, observable, runInAction, toJS } from 'mobx'; import merge from 'lodash/merge'; import isObject from 'lodash/isObject'; import isNil from 'lodash/isNil'; import isString from 'lodash/isString'; import isNumber from 'lodash/isNumber'; import omit from 'lodash/omit'; import isPlainObject from 'lodash/isPlainObject'; import { getConfig } from '../../../es/configure'; import DataSet from './DataSet'; import Field from './Field'; import { axiosConfigAdapter, checkFieldType, childrenInfoForDelete, findBindFields, generateData, generateJSONData, generateResponseData, getRecordValue, isDirtyRecord, processIntlField, processToJSON, processValue, useCascade, useNormal, useSelected } from './utils'; import * as ObjectChainValue from '../_util/ObjectChainValue'; import localeContext from '../locale-context'; import { BooleanValue, DataSetEvents, FieldIgnore, FieldType, RecordStatus } from './enum'; import isSame from '../_util/isSame'; import { treeReduce as _treeReduce } from '../_util/treeUtils'; /** * 记录ID生成器 */ var IDGen = /*#__PURE__*/ _regeneratorRuntime.mark(function _callee(start) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!true) { _context.next = 5; break; } _context.next = 3; return ++start; case 3: _context.next = 0; break; case 5: case "end": return _context.stop(); } } }, _callee); })(1000); var EXPANDED_KEY = '__EXPANDED_KEY__'; var Record = /*#__PURE__*/ function () { function Record() { var _this = this; var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var dataSet = arguments.length > 1 ? arguments[1] : undefined; var status = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : RecordStatus.add; _classCallCheck(this, Record); this.dataSetSnapshot = {}; this.cascadeRecordsMap = {}; this.cascading = {}; runInAction(function () { var initData = isObservableObject(data) ? toJS(data) : data; _this.state = observable.map(); _this.fields = observable.map(); _this.status = status; _this.selectable = true; _this.isSelected = false; _this.isCurrent = false; _this.isCached = false; _this.id = IDGen.next().value; _this.data = initData; _this.dirtyData = observable.map(); if (dataSet) { _this.dataSet = dataSet; var fields = dataSet.fields; if (fields) { _this.initFields(fields); } } _this.processData(initData); }); } _createClass(Record, [{ key: "toData", value: function toData(needIgnore, noCascade, isCascadeSelect) { var all = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; var status = this.status, dataSet = this.dataSet; var dataToJSON = dataSet && dataSet.dataToJSON; var cascade = noCascade === undefined && dataToJSON ? useCascade(dataToJSON) : !noCascade; var normal = all || dataToJSON && useNormal(dataToJSON); var dirty = status !== RecordStatus.sync; var json = this.normalizeData(needIgnore); if (cascade && this.normalizeCascadeData(json, normal, isCascadeSelect)) { dirty = true; } return _objectSpread({}, json, { __dirty: dirty }); } }, { key: "toJSONData", value: function toJSONData(noCascade, isCascadeSelect) { var status = this.status; return _objectSpread({}, this.toData(true, noCascade, isCascadeSelect, false), _defineProperty({ __id: this.id }, getConfig('statusKey'), getConfig('status')[status === RecordStatus.sync ? RecordStatus.update : status])); } }, { key: "validate", value: function validate(all, noCascade) { var _this2 = this; var dataSetSnapshot = this.dataSetSnapshot, dataSet = this.dataSet, status = this.status, fields = this.fields; return Promise.all([].concat(_toConsumableArray(_toConsumableArray(fields.values()).map(function (field) { return all || status !== RecordStatus.sync ? field.checkValidity() : true; })), _toConsumableArray(!noCascade && dataSet ? Object.keys(dataSet.children).map(function (key) { var children = dataSet.children; var snapshot = dataSetSnapshot[key]; var ds = children[key]; var child = dataSet.current === _this2 ? ds : snapshot && new DataSet().restore(snapshot); if (child) { return child.validate(); } var dataToJSON = ds.dataToJSON; var cascade = noCascade === undefined && dataToJSON ? useCascade(dataToJSON) : !noCascade; return ((useSelected(dataToJSON) ? _this2.getCascadeSelectedRecords(key) : _this2.getCascadeRecords(key)) || []).map(function (record) { return record.validate(false, !cascade); }); }) : []))).then(function (results) { return results.every(function (result) { return result; }); }); } }, { key: "getField", value: function getField(fieldName) { if (fieldName) { return this.fields.get(fieldName); } } }, { key: "getCascadeRecordsIncludeDelete", value: function getCascadeRecordsIncludeDelete(fieldName) { var dataSet = this.dataSet; if (fieldName && dataSet) { var childDataSet = dataSet.children[fieldName]; if (childDataSet) { if (dataSet.current === this) { return childDataSet.records.slice(); } var snapshot = this.dataSetSnapshot[fieldName]; if (snapshot) { return snapshot.records; } var cascadeRecords = this.cascadeRecordsMap[fieldName]; if (cascadeRecords) { return cascadeRecords; } var data = this.get(fieldName); if (!this.cascading[fieldName] && isObservableArray(data)) { this.cascading[fieldName] = true; var records = childDataSet.processData(data); this.cascading[fieldName] = false; this.cascadeRecordsMap[fieldName] = records; return records; } } } } }, { key: "getCascadeRecords", value: function getCascadeRecords(fieldName) { var records = this.getCascadeRecordsIncludeDelete(fieldName); if (records) { return records.filter(function (r) { return !r.isRemoved; }); } } }, { key: "getCascadeSelectedRecordsIncludeDelete", value: function getCascadeSelectedRecordsIncludeDelete(fieldName) { var records = this.getCascadeRecordsIncludeDelete(fieldName); if (records) { return records.filter(function (r) { return r.isSelected; }); } } }, { key: "getCascadeSelectedRecords", value: function getCascadeSelectedRecords(fieldName) { var records = this.getCascadeRecordsIncludeDelete(fieldName); if (records) { return records.filter(function (r) { return !r.isRemoved && r.isSelected; }); } } }, { key: "get", value: function get(fieldName) { return getRecordValue.call(this, this.data, function (child, checkField) { return child.get(checkField); }, fieldName); } }, { key: "set", value: function set(item, value) { var _this3 = this; if (isString(item)) { var fieldName = item; var oldName = fieldName; var field = this.getField(fieldName) || this.addField(fieldName); checkFieldType(value, field); var bind = field.get('bind'); if (bind) { fieldName = bind; } var oldValue = toJS(this.get(fieldName)); var newValue = processValue(value, field); if (!isSame(processToJSON(oldValue), processToJSON(newValue))) { var fields = this.fields; ObjectChainValue.set(this.data, fieldName, newValue, fields); if (!this.dirtyData.has(fieldName)) { this.dirtyData.set(fieldName, oldValue); if (this.status === RecordStatus.sync) { this.status = RecordStatus.update; } } else if (isSame(toJS(this.dirtyData.get(fieldName)), newValue)) { this.dirtyData["delete"](fieldName); if (this.status === RecordStatus.update && this.dirtyData.size === 0 && _toConsumableArray(fields.values()).every(function (f) { return !f.dirty; })) { this.status = RecordStatus.sync; } } var dataSet = this.dataSet; if (dataSet) { dataSet.fireEvent(DataSetEvents.update, { dataSet: dataSet, record: this, name: oldName, value: newValue, oldValue: oldValue }); var checkField = dataSet.props.checkField; if (checkField && (checkField === fieldName || checkField === oldName)) { var children = this.children; if (children) { children.forEach(function (record) { return record.set(fieldName, value); }); } } } } findBindFields(field, this.fields).forEach(function (oneField) { // oneField.dirty = field.dirty, oneField.validator.reset(); oneField.checkValidity(); }); } else if (isPlainObject(item)) { Object.keys(item).forEach(function (key) { return _this3.set(key, item[key]); }); } return this; } }, { key: "getPristineValue", value: function getPristineValue(fieldName) { return fieldName && this.dirtyData.has(fieldName) ? this.dirtyData.get(fieldName) : this.get(fieldName); } }, { key: "init", value: function init(item, value) { var _this4 = this; var fields = this.fields, data = this.data, dirtyData = this.dirtyData; if (isString(item)) { var fieldName = item; var field = this.getField(fieldName) || this.addField(fieldName); var newValue = processValue(value, field); var bind = field.get('bind'); if (bind) { fieldName = bind; } dirtyData["delete"](fieldName); ObjectChainValue.set(data, fieldName, newValue, fields); field.commit(); } else if (isPlainObject(item)) { Object.keys(item).forEach(function (key) { return _this4.init(key, item[key]); }); } return this; } }, { key: "clone", value: function clone() { var dataSet = this.dataSet; var cloneData = this.toData(); if (dataSet) { var primaryKey = dataSet.props.primaryKey; if (primaryKey) { delete cloneData[primaryKey]; } return new Record(cloneData, dataSet); } return new Record(cloneData); } }, { key: "ready", value: function ready() { return Promise.all(_toConsumableArray(this.fields.values()).map(function (field) { return field.ready(); })); } }, { key: "tls", value: function () { var _tls = _asyncToGenerator( /*#__PURE__*/ _regeneratorRuntime.mark(function _callee2(name) { var _this5 = this; var tlsKey, dataSet, tlsData, axios, lang, primaryKey, newConfig, result, dataKey; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: tlsKey = getConfig('tlsKey'); dataSet = this.dataSet; if (!(dataSet && name)) { _context2.next = 16; break; } tlsData = this.get(tlsKey) || {}; if (name in tlsData) { _context2.next = 16; break; } axios = dataSet.axios, lang = dataSet.lang; primaryKey = dataSet.props.primaryKey; newConfig = axiosConfigAdapter('tls', dataSet, {}, primaryKey && { key: this.get(primaryKey) }, { name: name, record: this }); if (!(newConfig.url && !this.isNew)) { _context2.next = 15; break; } _context2.next = 11; return axios(newConfig); case 11: result = _context2.sent; if (result) { dataKey = getConfig('dataKey'); this.commitTls(generateResponseData(result, dataKey)[0], name); } _context2.next = 16; break; case 15: this.commitTls(_toConsumableArray(this.fields.entries()).reduce(function (data, _ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], field = _ref2[1]; if (field.type === FieldType.intl) { data[key] = _defineProperty({}, lang, _this5.get(key)); } return data; }, {}), name); case 16: case "end": return _context2.stop(); } } }, _callee2, this); })); function tls(_x) { return _tls.apply(this, arguments); } return tls; }() }, { key: "reset", value: function reset() { var status = this.status, fields = this.fields, dataSet = this.dataSet, dirty = this.dirty, isRemoved = this.isRemoved; _toConsumableArray(fields.values()).forEach(function (field) { return field.commit(); }); if (status === RecordStatus.update || isRemoved) { this.status = RecordStatus.sync; } if (isRemoved || dirty) { this.data = toJS(this.pristineData); this.dirtyData.clear(); this.memo = undefined; if (dataSet && !dataSet.resetInBatch) { dataSet.fireEvent(DataSetEvents.reset, { records: [this], dataSet: dataSet }); } } return this; } }, { key: "save", value: function save() { this.memo = toJS(this.data); return this; } }, { key: "restore", value: function restore() { var memo = this.memo; if (memo) { this.set(memo); this.memo = undefined; } return this; } }, { key: "clear", value: function clear() { return this.set(_toConsumableArray(this.fields.keys()).reduce(function (obj, key) { obj[key] = null; return obj; }, {})); } }, { key: "commit", value: function commit(data, dataSet) { var _this6 = this; var dataSetSnapshot = this.dataSetSnapshot, fields = this.fields, isRemoved = this.isRemoved, records = this.records, isNew = this.isNew; if (dataSet) { if (isRemoved) { var index = records.indexOf(this); if (index !== -1) { if (dataSet.records === records) { dataSet.totalCount -= 1; } records.splice(index, 1); } return this; } if (isNew) { var _index = records.indexOf(this); if (_index !== -1 && dataSet.records === records) { dataSet.totalCount += 1; } } if (data) { this.processData(data, true); this.pristineData = this.data; var children = dataSet.children; var keys = Object.keys(children); if (keys.length) { var isCurrent = dataSet.current === this; var tmpDs = new DataSet(); keys.forEach(function (key) { var snapshot = dataSetSnapshot[key]; var ds = children[key]; var child = isCurrent ? ds : snapshot && tmpDs.restore(snapshot); if (child) { dataSetSnapshot[key] = child.commitData(data[key] || []).snapshot(); } else { var cascadeRecords = _this6.getCascadeRecordsIncludeDelete(key); if (cascadeRecords) { cascadeRecords.forEach(function (r) { return r.commit(omit(r.toData(), ['__dirty']), ds); }); } } }); } } } _toConsumableArray(fields.values()).forEach(function (field) { return field.commit(); }); this.status = RecordStatus.sync; return this; } }, { key: "setState", value: function setState(item, value) { if (isString(item)) { this.state.set(item, value); } else if (isPlainObject(item)) { this.state.merge(item); } return this; } }, { key: "getState", value: function getState(key) { return this.state.get(key); } }, { key: "treeReduce", value: function treeReduce(fn, initialValue) { return _treeReduce([this], fn, initialValue); } }, { key: "commitTls", value: function commitTls() { var _this7 = this; var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var name = arguments.length > 1 ? arguments[1] : undefined; var dataSet = this.dataSet; var lang = dataSet ? dataSet.lang : localeContext.locale.lang; var tlsKey = getConfig('tlsKey'); var values = {}; if (!(name in data)) { data[name] = {}; } Object.keys(data).forEach(function (key) { var value = data[key]; var field = _this7.getField(key); if (field && field.dirty) { values["".concat(tlsKey, ".").concat(key, ".").concat(lang)] = _this7.get(key); } _this7.init("".concat(tlsKey, ".").concat(key), value); }); this.set(values); } }, { key: "initFields", value: function initFields(fields) { var _this8 = this; _toConsumableArray(fields.keys()).forEach(function (key) { return _this8.addField(key); }); } }, { key: "addField", value: function addField(name) { var _this9 = this; var fieldProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var dataSet = this.dataSet; fieldProps.name = name; return processIntlField(name, fieldProps, function (langName, langProps) { var field = new Field(langProps, dataSet, _this9); _this9.fields.set(langName, field); return field; }, dataSet); } }, { key: "getSortedFields", value: function getSortedFields() { var fields = this.fields; var normalFields = []; var objectBindFields = []; var bindFields = []; var transformResponseField = []; var dynamicFields = []; var dynamicObjectBindFields = []; var dynamicBindFields = []; _toConsumableArray(fields.entries()).forEach(function (entry) { var _entry = _slicedToArray(entry, 2), field = _entry[1]; var dynamicProps = field.get('dynamicProps'); if (dynamicProps) { if (dynamicProps.bind) { if (field.type === FieldType.object) { dynamicObjectBindFields.push(entry); } else { dynamicBindFields.push(entry); } } else { dynamicFields.push(entry); } } else { var bind = field.get('bind'); if (bind) { var targetNames = bind.split('.'); targetNames.pop(); if (targetNames.some(function (targetName) { var target = fields.get(targetName); return target && target.get('dynamicProps'); })) { if (field.type === FieldType.object) { dynamicObjectBindFields.push(entry); } else { dynamicBindFields.push(entry); } } else if (field.get('transformResponse')) { transformResponseField.push(entry); } else if (field.type === FieldType.object) { objectBindFields.push(entry); } else { bindFields.push(entry); } } else { normalFields.push(entry); } } }); return [].concat(normalFields, objectBindFields, bindFields, transformResponseField, dynamicFields, dynamicObjectBindFields, dynamicBindFields); } }, { key: "processData", value: function processData() { var _this10 = this; var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var needMerge = arguments.length > 1 ? arguments[1] : undefined; var newData = _objectSpread({}, data); var fields = this.fields; this.getSortedFields().forEach(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 2), fieldName = _ref4[0], field = _ref4[1]; var value = ObjectChainValue.get(newData, fieldName); var bind = field.get('bind'); var transformResponse = field.get('transformResponse'); if (bind) { fieldName = bind; var bindValue = ObjectChainValue.get(newData, fieldName); if (isNil(value) && !isNil(bindValue)) { value = bindValue; } } if (transformResponse) { value = transformResponse(value, data); } value = processValue(value, field, _this10.isNew); if (value === null) { value = undefined; } if (needMerge && isObject(value)) { var oldValue = _this10.get(fieldName); if (isObject(oldValue)) { value = merge(oldValue, value); } } ObjectChainValue.set(newData, fieldName, value, fields); ObjectChainValue.set(_this10.data, fieldName, value, fields); }); } }, { key: "normalizeData", value: function normalizeData(needIgnore) { var _this11 = this; var fields = this.fields; var json = toJS(this.data); var objectFieldsList = []; var normalFields = []; var ignoreFieldNames = new Set(); _toConsumableArray(fields.keys()).forEach(function (key) { var field = _this11.getField(key); if (field) { var ignore = field.get('ignore'); if (needIgnore && (ignore === FieldIgnore.always || ignore === FieldIgnore.clean && !field.dirty)) { ignoreFieldNames.add(key); } else { var type = field.get('type'); if (type === FieldType.object) { var level = key.split('.').length - 1; objectFieldsList[level] = (objectFieldsList[level] || []).concat(field); } else { normalFields.push(field); } } } }); [].concat(objectFieldsList, [normalFields]).forEach(function (items) { if (items) { items.forEach(function (field) { var name = field.name; var value = ObjectChainValue.get(json, name); var bind = field.get('bind'); var multiple = field.get('multiple'); var transformRequest = field.get('transformRequest'); if (bind) { value = _this11.get(bind); } if (isString(multiple) && isArrayLike(value)) { value = value.map(processToJSON).join(multiple); } if (transformRequest) { value = transformRequest(value, _this11); } if (value !== undefined) { ObjectChainValue.set(json, name, processToJSON(value), fields); } else { ignoreFieldNames.add(name); } }); } }); _toConsumableArray(ignoreFieldNames).forEach(function (key) { return ObjectChainValue.remove(json, key); }); return json; } }, { key: "normalizeCascadeData", value: function normalizeCascadeData(json, normal, isSelect) { var _this12 = this; var dataSetSnapshot = this.dataSetSnapshot, dataSet = this.dataSet, fields = this.fields, isRemoved = this.isRemoved; if (dataSet) { var dirty = false; var children = dataSet.children; if (isRemoved) { childrenInfoForDelete(json, children); } else { var isCurrent = dataSet.current === this; Object.keys(children).forEach(function (name) { var snapshot = dataSetSnapshot[name]; var child = !isCurrent && snapshot && new DataSet().restore(snapshot) || children[name]; if (child) { var dataToJSON = child.dataToJSON; var records = _this12.getCascadeRecordsIncludeDelete(name); var selected = isSelect || useSelected(dataToJSON) ? _this12.getCascadeSelectedRecordsIncludeDelete(name) : records; var jsonArray = normal || useNormal(dataToJSON) ? records && generateData(records) : selected && generateJSONData(child, selected); if (jsonArray) { if (jsonArray.dirty) { dirty = true; } ObjectChainValue.set(json, name, jsonArray.data, fields); } } }); } return dirty; } } }, { key: "pristineData", get: function get() { return _toConsumableArray(this.dirtyData.entries()).reduce(function (data, _ref5) { var _ref6 = _slicedToArray(_ref5, 2), key = _ref6[0], value = _ref6[1]; ObjectChainValue.set(data, key, value); return data; }, toJS(this.data)); }, set: function set(data) { var _this13 = this; runInAction(function () { var dirtyData = _this13.dirtyData; var dirtyKeys = _toConsumableArray(dirtyData.keys()); if (dirtyKeys.length) { var newData = {}; dirtyKeys.forEach(function (key) { var item = ObjectChainValue.get(_this13.data, key); ObjectChainValue.set(newData, key, item); var newItem = ObjectChainValue.get(data, key); if (isSame(item, newItem)) { dirtyData["delete"](key); } else { dirtyData.set(key, newItem); } }); _this13.data = merge({}, data, newData); } else { _this13.data = data; } }); } }, { key: "key", get: function get() { if (!this.isNew) { var dataSet = this.dataSet; if (dataSet) { var primaryKey = dataSet.props.primaryKey; if (primaryKey) { var key = this.get(primaryKey); if (isString(key) || isNumber(key)) { return key; } } } } return this.id; } }, { key: "index", get: function get() { var dataSet = this.dataSet; if (dataSet) { return dataSet.indexOf(this); } return -1; } }, { key: "indexInParent", get: function get() { var parent = this.parent, dataSet = this.dataSet; if (parent && parent.children) { return parent.children.indexOf(this); } if (dataSet) { return dataSet.treeRecords.indexOf(this); } return -1; } }, { key: "isRemoved", get: function get() { return this.status === RecordStatus["delete"]; } }, { key: "isNew", get: function get() { return this.status === RecordStatus.add; } }, { key: "isIndeterminate", get: function get() { var dataSet = this.dataSet; if (dataSet) { var checkField = dataSet.props.checkField; if (checkField) { var field = this.getField(checkField); var trueValue = field ? field.get(BooleanValue.trueValue) : true; var children = this.children; if (children) { var checkedLength = 0; return children.some(function (record) { if (record.isIndeterminate) { return true; } if (record.get(checkField) === trueValue) { checkedLength += 1; } return false; }) || checkedLength > 0 && checkedLength !== children.length; } } } return false; } }, { key: "isExpanded", get: function get() { var dataSet = this.dataSet; if (dataSet) { var expandField = dataSet.props.expandField; if (expandField) { var expanded = this.get(expandField); var field = this.getField(expandField); return expanded === (field ? field.get(BooleanValue.trueValue) : true); } } return this.getState(EXPANDED_KEY); }, set: function set(expand) { var dataSet = this.dataSet; if (dataSet) { var expandField = dataSet.props.expandField; if (expandField) { var field = this.getField(expandField); this.set(expandField, field ? expand ? field.get(BooleanValue.trueValue) : field.get(BooleanValue.falseValue) : expand); } else { this.setState(EXPANDED_KEY, expand); } } } }, { key: "previousRecord", get: function get() { var parent = this.parent, dataSet = this.dataSet; var children; if (parent) { children = parent.children; } else if (dataSet) { children = dataSet.treeData; } if (children) { return children[children.indexOf(this) - 1]; } return undefined; } }, { key: "nextRecord", get: function get() { var parent = this.parent, dataSet = this.dataSet; var children; if (parent) { children = parent.children; } else if (dataSet) { children = dataSet.treeData; } if (children) { return children[children.indexOf(this) + 1]; } return undefined; } }, { key: "records", get: function get() { var dataSet = this.dataSet; if (dataSet) { var cascadeParent = this.cascadeParent; if (cascadeParent && !cascadeParent.isCurrent) { return cascadeParent.getCascadeRecordsIncludeDelete(dataSet.parentName) || []; } return dataSet.records; } return []; } }, { key: "children", get: function get() { var _this14 = this; var dataSet = this.dataSet; if (dataSet) { var _dataSet$props = dataSet.props, parentField = _dataSet$props.parentField, idField = _dataSet$props.idField; if (parentField && idField) { var children = this.records.filter(function (record) { var childParentId = record.get(parentField); var id = _this14.get(idField); return !isNil(childParentId) && !isNil(id) && childParentId === id; }); return children.length > 0 ? children : undefined; } } return undefined; } }, { key: "parent", get: function get() { var _this15 = this; var dataSet = this.dataSet; if (dataSet) { var _dataSet$props2 = dataSet.props, parentField = _dataSet$props2.parentField, idField = _dataSet$props2.idField; if (parentField && idField) { return this.records.find(function (record) { var parentId = _this15.get(parentField); var id = record.get(idField); return !isNil(parentId) && !isNil(id) && parentId === id; }); } } return undefined; } }, { key: "parents", get: function get() { var parent = this.parent; if (parent) { return [parent].concat(_toConsumableArray(parent.parents)); } return []; } }, { key: "path", get: function get() { return [].concat(_toConsumableArray(this.parents), [this]); } }, { key: "level", get: function get() { var parent = this.parent; if (parent) { return parent.level + 1; } return 0; } }, { key: "dirty", get: function get() { var _this16 = this; var fields = this.fields, status = this.status, dataSet = this.dataSet, dirtyData = this.dirtyData; if (status === RecordStatus.update || dirtyData.size > 0 || _toConsumableArray(fields.values()).some(function (_ref7) { var dirty = _ref7.dirty; return dirty; })) { return true; } if (dataSet) { var children = dataSet.children; return Object.keys(children).some(function (key) { return (_this16.getCascadeRecordsIncludeDelete(key) || []).some(isDirtyRecord); }); } return false; } }, { key: "cascadeParent", get: function get() { var _this17 = this; var dataSet = this.dataSet; if (dataSet) { var parent = dataSet.parent, parentName = dataSet.parentName; if (parent && parentName) { return parent.cascadeRecords.find(function (record) { return (record.getCascadeRecordsIncludeDelete(parentName) || []).indexOf(_this17) !== -1; }); } } return undefined; } }]); return Record; }(); export { Record as default }; __decorate([observable], Record.prototype, "fields", void 0); __decorate([observable], Record.prototype, "data", void 0); __decorate([observable], Record.prototype, "dirtyData", void 0); __decorate([computed], Record.prototype, "pristineData", null); __decorate([observable], Record.prototype, "status", void 0); __decorate([observable], Record.prototype, "selectable", void 0); __decorate([observable], Record.prototype, "isSelected", void 0); __decorate([observable], Record.prototype, "isCurrent", void 0); __decorate([observable], Record.prototype, "isCached", void 0); __decorate([observable], Record.prototype, "editing", void 0); __decorate([observable], Record.prototype, "pending", void 0); __decorate([observable], Record.prototype, "childrenLoaded", void 0); __decorate([observable], Record.prototype, "state", void 0); __decorate([computed], Record.prototype, "key", null); __decorate([computed], Record.prototype, "index", null); __decorate([computed], Record.prototype, "indexInParent", null); __decorate([computed], Record.prototype, "isRemoved", null); __decorate([computed], Record.prototype, "isNew", null); __decorate([computed], Record.prototype, "isIndeterminate", null); __decorate([computed], Record.prototype, "isExpanded", null); __decorate([computed], Record.prototype, "previousRecord", null); __decorate([computed], Record.prototype, "nextRecord", null); __decorate([computed], Record.prototype, "records", null); __decorate([computed], Record.prototype, "children", null); __decorate([computed], Record.prototype, "parent", null); __decorate([computed], Record.prototype, "parents", null); __decorate([computed], Record.prototype, "path", null); __decorate([computed], Record.prototype, "level", null); __decorate([computed], Record.prototype, "dirty", null); __decorate([computed], Record.prototype, "cascadeParent", null); __decorate([action], Record.prototype, "set", null); __decorate([action], Record.prototype, "init", null); __decorate([action], Record.prototype, "tls", null); __decorate([action], Record.prototype, "reset", null); __decorate([action], Record.prototype, "save", null); __decorate([action], Record.prototype, "restore", null); __decorate([action], Record.prototype, "clear", null); __decorate([action], Record.prototype, "commit", null); __decorate([action], Record.prototype, "setState", null); __decorate([action], Record.prototype, "commitTls", null); __decorate([action], Record.prototype, "addField", null); //# sourceMappingURL=Record.js.map