igniteui-react-core
Version:
Ignite UI React Core.
750 lines (749 loc) • 25.3 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, IList_$type, runOn, String_$type, EnumUtil, fromEnum, typeCast, Array_$type, delegateRemove, delegateCombine, markType } from "./type";
import { IDataSourceLocalDataProvider_$type } from "./IDataSourceLocalDataProvider";
import { IDataSourceSchema_$type } from "./IDataSourceSchema";
import { DataSourceSchemaPropertyType_$type } from "./DataSourceSchemaPropertyType";
import { DefaultDataSourceSchema } from "./DefaultDataSourceSchema";
import { SortDescriptionCollection } from "./SortDescriptionCollection";
import { FilterExpressionCollection } from "./FilterExpressionCollection";
import { SummaryDescriptionCollection } from "./SummaryDescriptionCollection";
import { Dictionary$2 } from "./Dictionary$2";
import { FastReflectionHelper } from "./FastReflectionHelper";
import { HashSet$1 } from "./HashSet$1";
import { DataSourceDataProviderSchemaChangedEventArgs } from "./DataSourceDataProviderSchemaChangedEventArgs";
import { List$1 } from "./List$1";
import { INotifyCollectionChanged_$type } from "./INotifyCollectionChanged";
import { getAllPropertyNames } from "./componentUtil";
import { stringStartsWith } from "./string";
/**
* @hidden
*/
export let DataSourceLocalDataProvider = /*@__PURE__*/ (() => {
class DataSourceLocalDataProvider extends Base {
constructor() {
super();
this.n = null;
this.m = null;
this.g = null;
this.o = null;
this.f = 0;
this.aa = 5;
this.ab = null;
this.u = new Dictionary$2(String_$type, DataSourceSchemaPropertyType_$type, 0);
this.ad = null;
this.schemaChanged = null;
this.t = new Dictionary$2(String_$type, FastReflectionHelper.$, 0);
this.v = new HashSet$1(String_$type, 0);
this.j = null;
this.y = null;
this.r = false;
this.i = null;
this.h = null;
this.q = false;
this.a = null;
this.p = false;
this.b = null;
this.n = new SortDescriptionCollection();
this.n.n(runOn(this, this.au));
this.m = new SortDescriptionCollection();
this.o = new SummaryDescriptionCollection();
this.g = new FilterExpressionCollection();
}
au(a, b) {
this.queueAutoRefresh();
}
clone() {
let a = new DataSourceLocalDataProvider();
a.deferAutoRefresh = this.deferAutoRefresh;
a.executionContext = this.executionContext;
a.dataSource = this.dataSource;
a.propertiesRequested = this.propertiesRequested;
a.schemaHints = this.schemaHints;
a.summaryScope = this.summaryScope;
for (let b = 0; b < this.groupDescriptions.k.count; b++) {
a.groupDescriptions.add(this.groupDescriptions.k.item(b));
}
for (let c = 0; c < this.sortDescriptions.k.count; c++) {
a.sortDescriptions.add(this.sortDescriptions.k.item(c));
}
for (let d = 0; d < this.filterExpressions.k.count; d++) {
a.filterExpressions.add(this.filterExpressions.k.item(d));
}
for (let e = 0; e < this.summaryDescriptions.k.count; e++) {
a.summaryDescriptions.add(this.summaryDescriptions.k.item(e));
}
return a;
}
get dataSource() {
return this.ab;
}
set dataSource(a) {
let b = this.ab;
this.ab = a;
if (b != this.ab) {
this.ao("ItemsSource", b, this.ab);
}
}
get schemaHints() {
return this.ad;
}
set schemaHints(a) {
let b = this.ad;
this.ad = a;
if (b != this.ad) {
this.ao("SchemaHints", b, this.ad);
}
}
ap() {
if (this.ad == null) {
return;
}
this.u.clear();
let a = this.ad.split(',');
for (let b = 0; b < a.length; b++) {
let c = a[b].trim().split(':');
if (c.length != 2) {
continue;
}
let d = c[0];
let e = this.d(c[1]);
this.u.addItem(d, e);
}
}
d(a) {
let b = EnumUtil.parse(DataSourceSchemaPropertyType_$type, a, true);
if (b != null) {
return EnumUtil.getEnumValue(DataSourceSchemaPropertyType_$type, b);
}
return 11;
}
getItemAtIndex(a) {
if (this.y == null) {
return null;
}
if (this.r) {
return this.y[a];
}
return this.y.item(a);
}
getItemValue(a, b) {
this.ak();
let c;
let d = this.t.tryGetValue(b, c);
c = d.p1;
if (c == null && !this.v.contains(b)) {
let e = b.split('.');
let f = a;
let g = true;
for (let h = 0; h < e.length; h++) {
f = f[e[h]];
if ((f === undefined)) {
g = false;
break;
}
}
if (g) {
c = new FastReflectionHelper(false, b);
this.t.addItem(b, c);
}
else {
this.v.add_1(b);
}
}
if (c == null) {
return null;
}
let val_ = c.getPropertyValue(a);
if ((val_ === undefined)) {
return null;
}
return val_;
}
setItemValue(a, b, c) {
this.ak();
let d;
let e = this.t.tryGetValue(b, d);
d = e.p1;
if (d == null) {
return;
}
d.setPropertyValue(a, c);
}
removeItem(a) {
if (this.y != null) {
let b = this.y.indexOf(a);
if (this.r) {
this.y.splice(b, 1);
}
else {
this.y.removeAt(b);
}
this.notifyRemoveItem(b, a);
}
}
addItem(a) {
if (this.y != null) {
let b = this.actualCount;
if (this.r) {
this.y.splice(b, 0, a);
}
else {
this.y.insert(b, a);
}
this.notifyInsertItem(this.actualCount - 1, a);
}
}
ak() {
if (this.j == null) {
this.j = this.actualSchema;
if (this.schemaChanged != null) {
this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.j, this.actualCount));
}
}
}
get actualCount() {
if (this.y == null) {
return 0;
}
if (this.r) {
return (this.y.length);
}
return this.y.count;
}
get actualSchema() {
if (this.j == null) {
if (this.y == null) {
this.j = new DefaultDataSourceSchema([], [], null, null, []);
}
else {
this.j = this.l();
}
}
return this.j;
}
l() {
let a = this.ac();
if (a == null) {
return new DefaultDataSourceSchema([], [], null, null, []);
}
this.t.clear();
this.v.clear();
return this.k(a, null, 0);
}
k(a, b, c) {
if (c >= this.aa) {
return null;
}
if (a == null) {
return null;
}
if ((typeof a === 'function')) {
return null;
}
if ((Array.isArray(a))) {
return null;
}
let check_ = a;
if ((check_ instanceof HTMLElement)) {
return null;
}
let d = new List$1(String_$type, 0);
let e = new HashSet$1(String_$type, 0);
let f = new List$1(DataSourceSchemaPropertyType_$type, 0);
let g = new List$1(List$1.$.specialize(String_$type), 0);
let h = this.w(a);
let i = new List$1(IDataSourceSchema_$type, 0);
if (this.schemaIncludedProperties == null || this.schemaIncludedProperties.length > 0) {
for (let j = 0; j < h.count; j++) {
let k = h._inner[j];
if (this.schemaIncludedProperties != null && this.schemaIncludedProperties.length > 0) {
let l = false;
for (let m = 0; m < this.schemaIncludedProperties.length; m++) {
if (this.schemaIncludedProperties[m] == k) {
l = true;
break;
}
}
if (!l) {
continue;
}
}
if (stringStartsWith(k, "_")) {
continue;
}
if (k == "$hashCode" || k == "$type") {
continue;
}
if ((typeof check_[k] === 'function')) {
continue;
}
if (e.contains(k)) {
continue;
}
else {
let n = b == null ? k : b + "." + k;
d.add(k);
e.add_1(k);
this.t.addItem(n, new FastReflectionHelper(false, n));
if (this.u.containsKey(n)) {
f.add(this.u.item(n));
this.u.removeItem(n);
}
else {
f.add(this.c(a, k));
}
g.add(this.x(a, k));
if (f._inner[f.count - 1] == 11) {
i.add(this.k(a[k], n, c + 1));
}
else {
i.add(null);
}
}
}
for (let o of fromEnum(this.u)) {
let p = o.key.split('.');
for (let q = 0; q < p.length; q++) {
if (e.contains(p[q])) {
continue;
}
else {
d.add(p[q]);
e.add_1(p[q]);
f.add(q == p.length - 1 ? o.value : 11);
g.add(new List$1(String_$type, 0));
}
}
}
}
let r = new Array(g.count);
for (let s = 0; s < g.count; s++) {
r[s] = g._inner[s].toArray();
}
return new DefaultDataSourceSchema(d.toArray(), f.toArray(), null, r, i.toArray());
}
resolveSchemaPropertyType(a) {
let b = a.split('.');
let c = a.indexOf("[") >= 0;
if (b.length == 1) {
for (let d = 0; d < this.actualSchema.propertyNames.length; d++) {
if (this.actualSchema.propertyNames[d] == b[0]) {
return this.actualSchema.propertyTypes[d];
}
}
if (c) {
let e = this.ac();
let f = this.getItemValue(e, a);
if (f == null) {
return 11;
}
else {
return DataSourceLocalDataProvider.e(f);
}
}
return 11;
}
else {
let g = this.ac();
let h = this.getItemValue(g, a);
if (h == null) {
return 11;
}
else {
return DataSourceLocalDataProvider.e(h);
}
}
}
setSchema(a) {
this.j = a;
if (this.schemaChanged != null) {
this.schemaChanged(this, new DataSourceDataProviderSchemaChangedEventArgs(this.j, this.actualCount));
}
}
w(schemaItem_) {
let a = new HashSet$1(String_$type, 0);
let propertyKey_ = null;
let ret_ = new List$1(String_$type, 0);
let exclusions_ = {};
for (propertyKey_ in schemaItem_) {
if (!isNaN(propertyKey_)) {
continue;
}
if (!exclusions_.hasOwnProperty(propertyKey_)) {
ret_.add(propertyKey_);
}
}
;
for (let b of fromEnum(ret_)) {
a.add_1(b);
}
let c = (getAllPropertyNames(schemaItem_));
for (let e = 0; e < c.length; e++) {
let d = c[e];
if (!a.contains(d)) {
a.add_1(d);
ret_.add(d);
}
}
return ret_;
}
am(a, item_, propertyName_, b) {
if ((item_.__dataIntents !== undefined)) {
if ((item_.__dataIntents[propertyName_] !== undefined)) {
this.al(a, item_, propertyName_);
}
let selfName_ = "self." + propertyName_;
if (!b && (item_.__dataIntents[selfName_] !== undefined)) {
this.al(a, item_, selfName_);
}
let selfName2_ = "self_" + propertyName_;
if (!b && (item_.__dataIntents[selfName2_] !== undefined)) {
this.al(a, item_, selfName2_);
}
}
}
al(a, item_, propertyName_) {
let val_ = item_.__dataIntents[propertyName_];
let b = typeCast(Array_$type, val_) !== null;
if (!b) {
b = (Array.isArray(val_));
}
if (b) {
let c = val_;
for (let d = 0; d < c.length; d++) {
if (c[d] != null) {
a.add(c[d].toString());
}
}
}
}
x(item_, propertyName_) {
let a = new List$1(String_$type, 0);
let list_ = this.y;
let dataIntents_ = null;
this.am(a, item_, propertyName_, false);
this.am(a, list_, propertyName_, true);
return a;
}
c(item_, propertyName_) {
if (item_ == null) {
return 11;
}
if ((item_[propertyName_] == undefined)) {
return 11;
}
let value_ = item_[propertyName_];
return DataSourceLocalDataProvider.e(value_);
}
static e(value_) {
if (value_ == null) {
return 11;
}
if ((typeof value_ == 'number')) {
return 5;
}
if ((typeof value_ == 'boolean')) {
return 2;
}
if ((typeof value_ == 'string')) {
return 0;
}
if ((typeof value_ == 'object')) {
if ((value_ instanceof Date)) {
return 8;
}
}
return 11;
}
ac() {
let a = 0;
if (this.r) {
a = (this.y.length);
}
else {
a = this.y.count;
}
for (let b = 0; b < a; b++) {
let c;
if (this.r) {
c = this.y[b];
}
else {
c = this.y.item(b);
}
if (c != null) {
return c;
}
}
return null;
}
ao(a, b, c) {
this.aq(a, b, c);
}
get z() {
return this.y;
}
aq(a, b, c) {
switch (a) {
case "ItemsSource":
this.j = null;
if (b != null) {
if (typeCast(INotifyCollectionChanged_$type, b) !== null) {
let d = typeCast(INotifyCollectionChanged_$type, b);
d.collectionChanged = delegateRemove(d.collectionChanged, runOn(this, this.an));
}
}
if (this.dataSource != null) {
this.r = false;
if (typeCast(Array_$type, this.dataSource) !== null) {
this.r = true;
this.y = this.dataSource;
}
else if (typeCast(IList_$type, this.dataSource) !== null) {
this.y = this.dataSource;
}
if (!this.r && this.y == null) {
let source_ = this.dataSource;
this.r = (Array.isArray(source_));
if (this.r) {
this.y = this.dataSource;
}
}
if (typeCast(INotifyCollectionChanged_$type, this.dataSource) !== null) {
let e = typeCast(INotifyCollectionChanged_$type, this.dataSource);
e.collectionChanged = delegateCombine(e.collectionChanged, runOn(this, this.an));
}
}
else {
this.y = null;
}
this.ak();
break;
case "DeferAutoRefresh":
if (!c) {
this.queueAutoRefresh();
}
break;
case "SchemaHints":
this.j = null;
this.ap();
this.ak();
break;
}
}
an(a, b) {
switch (b.action) {
case 0:
if (b.newItems != null) {
this.notifyInsertItem(b.newStartingIndex, b.newItems.item(0));
}
break;
case 1:
if (b.oldItems != null) {
this.notifyRemoveItem(b.oldStartingIndex, b.oldItems.item(0));
}
break;
case 2:
if (b.newItems != null) {
this.notifySetItem(b.newStartingIndex, b.oldItems.item(0), b.newItems.item(0));
}
break;
case 4:
this.notifyClearItems();
break;
}
}
get executionContext() {
return this.i;
}
set executionContext(a) {
this.i = a;
}
get s() {
return false;
}
notifySetItem(a, b, c) {
if (this.s) {
if (this.r) {
this.y[a] = c;
}
else {
this.y.item(a, c);
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifySetItem(a, b, c);
}
}
notifyClearItems() {
if (this.s) {
if (this.r) {
this.y.length = 0;
}
else {
this.y.clear();
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyClearItems();
}
}
notifyInsertItem(a, b) {
if (this.s) {
if (this.r) {
this.y.splice(a, 0, b);
}
else {
this.y.insert(a, b);
}
}
let c = 0;
if (this.r) {
c = (this.y.length);
}
else {
c = this.y.count;
}
if (this.y != null && c == 1 && (this.actualSchema == null || this.actualSchema.propertyNames.length == 0)) {
this.j = null;
this.ak();
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyInsertItem(a, b);
}
}
notifyRemoveItem(a, b) {
if (this.s) {
if (this.r) {
this.y.splice(a, 1);
}
else {
this.y.remove(a);
}
}
if (this.updateNotifier != null) {
this.updateNotifier.notifyRemoveItem(a, b);
}
}
get updateNotifier() {
return this.h;
}
set updateNotifier(a) {
this.h = a;
}
get deferAutoRefresh() {
return this.q;
}
set deferAutoRefresh(a) {
let b = this.q;
this.q = a;
if (this.q != b) {
this.ao("DeferAutoRefresh", b, this.q);
}
}
get isSortingSupported() {
return false;
}
get isFilteringSupported() {
return false;
}
get sortDescriptions() {
return this.n;
}
get filterExpressions() {
return this.g;
}
get summaryDescriptions() {
return this.o;
}
get summaryScope() {
return this.f;
}
set summaryScope(a) {
this.f = a;
}
get notifyUsingSourceIndexes() {
return true;
}
get propertiesRequested() {
return this.a;
}
set propertiesRequested(a) {
let b = this.a;
this.a = a;
if (b != this.a) {
}
}
get isItemIndexLookupSupported() {
return true;
}
get isKeyIndexLookupSupported() {
return false;
}
get isGroupingSupported() {
return false;
}
get groupDescriptions() {
return this.m;
}
queueAutoRefresh() {
if (this.deferAutoRefresh) {
return;
}
if (this.p) {
return;
}
if (this.executionContext != null) {
this.p = true;
this.executionContext.enqueueAction(runOn(this, this.aj));
}
}
aj() {
if (this.deferAutoRefresh) {
this.p = false;
return;
}
if (!this.p) {
return;
}
this.p = false;
this.ar();
}
ar() {
this.as();
}
as() {
}
flushAutoRefresh() {
this.aj();
}
refresh() {
this.ar();
}
indexOfItem(a) {
if (this.y == null) {
return -1;
}
return this.y.indexOf(a);
}
indexOfKey(a) {
return -1;
}
get schemaIncludedProperties() {
return this.b;
}
set schemaIncludedProperties(a) {
let b = this.b;
this.b = a;
if (b != this.b) {
}
}
}
DataSourceLocalDataProvider.$t = /*@__PURE__*/ markType(DataSourceLocalDataProvider, 'DataSourceLocalDataProvider', Base.$, [IDataSourceLocalDataProvider_$type]);
return DataSourceLocalDataProvider;
})();