mirror of https://github.com/artf/grapesjs.git
8 changed files with 117 additions and 1 deletions
@ -0,0 +1,7 @@ |
|||||
|
import { ItemManagerModule } from '../abstract/Module'; |
||||
|
import { DataSources } from './model/DataSources'; |
||||
|
|
||||
|
export default class DataSourceManager extends ItemManagerModule<{}, DataSources> { |
||||
|
storageKey = ''; |
||||
|
destroy(): void {} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
import { keys } from 'underscore'; |
||||
|
import { Collection, Model } from '../../common'; |
||||
|
import { DataRecordProps } from '../types'; |
||||
|
|
||||
|
export class DataRecord<T extends DataRecordProps = DataRecordProps> extends Model<T> { |
||||
|
// collection?: Collection<T>;
|
||||
|
|
||||
|
constructor(props: T, opts = {}) { |
||||
|
super(props, opts); |
||||
|
this.on('change', dr => { |
||||
|
const changed = dr.changedAttributes(); |
||||
|
keys(changed).forEach(prop => { |
||||
|
const eventKey = `${this.dataSource.id}.${this.id}.${prop}`; |
||||
|
console.log('changed', eventKey); |
||||
|
// em.trigger(eventKey);
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
get dataSource() { |
||||
|
return (this.collection as any).dataSource; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
import { Collection } from '../../common'; |
||||
|
import { DataRecordProps } from '../types'; |
||||
|
import { DataRecord } from './DataRecord'; |
||||
|
import { DataSource } from './DataSource'; |
||||
|
|
||||
|
export class DataRecords extends Collection<DataRecord> { |
||||
|
dataSource: DataSource; |
||||
|
|
||||
|
constructor(models: DataRecord[] | Array<DataRecordProps>, options: { dataSource: DataSource }) { |
||||
|
super(models, options); |
||||
|
this.dataSource = options.dataSource; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
DataRecords.prototype.model = DataRecord; |
||||
@ -0,0 +1,15 @@ |
|||||
|
import { Model } from '../../common'; |
||||
|
import { DataSourceProps } from '../types'; |
||||
|
import { DataRecords } from './DataRecords'; |
||||
|
|
||||
|
export class DataSource extends Model<DataSourceProps> { |
||||
|
defaults() { |
||||
|
return { |
||||
|
records: [], |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
get records() { |
||||
|
return this.attributes.records as DataRecords; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
import { Collection } from '../../common'; |
||||
|
import { DataSource } from './DataSource'; |
||||
|
|
||||
|
export class DataSources extends Collection<DataSource> {} |
||||
@ -0,0 +1,22 @@ |
|||||
|
import { ObjectAny } from '../common'; |
||||
|
import { DataRecord } from './model/DataRecord'; |
||||
|
import { DataRecords } from './model/DataRecords'; |
||||
|
|
||||
|
export interface DataSourceProps { |
||||
|
/** |
||||
|
* DataSource id. |
||||
|
*/ |
||||
|
id: string; |
||||
|
|
||||
|
/** |
||||
|
* DataSource records. |
||||
|
*/ |
||||
|
records?: DataRecords | DataRecord[] | DataRecordProps[]; |
||||
|
} |
||||
|
|
||||
|
export interface DataRecordProps extends ObjectAny { |
||||
|
/** |
||||
|
* Record id. |
||||
|
*/ |
||||
|
id: string; |
||||
|
} |
||||
Loading…
Reference in new issue