@coolon/angular-ui-powerups 1.11.4 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/bundles/coolon-angular-ui-powerups.umd.js +12 -2
- package/bundles/coolon-angular-ui-powerups.umd.js.map +1 -1
- package/bundles/coolon-angular-ui-powerups.umd.min.js +1 -1
- package/bundles/coolon-angular-ui-powerups.umd.min.js.map +1 -1
- package/esm2015/lib/components/table/column-model.js +12 -1
- package/esm2015/lib/components/table/column-model.js.map +1 -1
- package/esm2015/lib/components/table/column-model.metadata.json +1 -1
- package/esm2015/lib/components/table/table-model.js +1 -1
- package/esm2015/lib/components/table/table-model.js.map +1 -1
- package/esm5/lib/components/table/column-model.js +12 -1
- package/esm5/lib/components/table/column-model.js.map +1 -1
- package/esm5/lib/components/table/table-model.js +1 -1
- package/esm5/lib/components/table/table-model.js.map +1 -1
- package/fesm2015/coolon-angular-ui-powerups.js +12 -2
- package/fesm2015/coolon-angular-ui-powerups.js.map +1 -1
- package/fesm5/coolon-angular-ui-powerups.js +12 -2
- package/fesm5/coolon-angular-ui-powerups.js.map +1 -1
- package/lib/components/table/column-model.d.ts +6 -4
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ import { DefaultHeaderCellRendererComponent } from './default-header-cell-render
|
|
|
7
7
|
import { EditRowControls } from './edit-row-controls/edit-row-controls.component';
|
|
8
8
|
import { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';
|
|
9
9
|
import { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';
|
|
10
|
+
import { assert } from '@coolon/typescript-utilities';
|
|
10
11
|
export class ColumnModel {
|
|
11
12
|
constructor(columnId, defaults) {
|
|
12
13
|
this.columnId = columnId;
|
|
@@ -40,6 +41,7 @@ export class ColumnModel {
|
|
|
40
41
|
portal: new ComponentPortal(cellRenderer),
|
|
41
42
|
initialiseComponent: initialiser
|
|
42
43
|
};
|
|
44
|
+
return this;
|
|
43
45
|
}
|
|
44
46
|
setCellEditor(cellEditor) {
|
|
45
47
|
this._cellEditorConfig = cellEditor;
|
|
@@ -83,12 +85,14 @@ export class PropertyColumnModel extends ColumnModel {
|
|
|
83
85
|
constructor(property, defaults) {
|
|
84
86
|
super(property.toString(), defaults);
|
|
85
87
|
this.property = property;
|
|
88
|
+
this._format = (value) => value;
|
|
86
89
|
this.cellRenderer(DefaultCellRendererComponent);
|
|
87
90
|
}
|
|
88
91
|
cellRenderer(componentType) {
|
|
89
92
|
this.setCellRenderer(componentType, (component, row) => {
|
|
90
|
-
component.value = row[this.property];
|
|
93
|
+
component.value = this._format(row[this.property]);
|
|
91
94
|
});
|
|
95
|
+
return this;
|
|
92
96
|
}
|
|
93
97
|
cellEditor(editor, options) {
|
|
94
98
|
this.setCellEditor({
|
|
@@ -106,6 +110,11 @@ export class PropertyColumnModel extends ColumnModel {
|
|
|
106
110
|
});
|
|
107
111
|
return this;
|
|
108
112
|
}
|
|
113
|
+
format(formatter) {
|
|
114
|
+
assert.isFunction(formatter);
|
|
115
|
+
this._format = formatter;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
109
118
|
}
|
|
110
119
|
export class CustomValueColumnModel extends ColumnModel {
|
|
111
120
|
constructor(columnId, defaults, getValue) {
|
|
@@ -117,6 +126,7 @@ export class CustomValueColumnModel extends ColumnModel {
|
|
|
117
126
|
this.setCellRenderer(componentType, (component, row) => {
|
|
118
127
|
component.value = this.getValue(row);
|
|
119
128
|
});
|
|
129
|
+
return this;
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
export class EditorControlColumnModel extends ColumnModel {
|
|
@@ -130,6 +140,7 @@ export class EditorControlColumnModel extends ColumnModel {
|
|
|
130
140
|
component.editSession = editSession;
|
|
131
141
|
component.editRowCommand = editRowCommand;
|
|
132
142
|
});
|
|
143
|
+
return this;
|
|
133
144
|
}
|
|
134
145
|
getDefaultHeaderText() {
|
|
135
146
|
return '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/column-model.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAU,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAiB,sBAAsB,EAAkD,MAAM,gBAAgB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAC;AAI3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yDAAyD,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,MAAM,uEAAuE,CAAC;AAC3H,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uDAAuD,CAAC;AACpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,qEAAqE,CAAC;AAmBxH,MAAM,OAAO,WAAW;IAQtB,YAAqB,QAAgB,EAAU,QAA8B;QAAxD,aAAQ,GAAR,QAAQ,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAsB;QAC3E,IAAI,CAAC,kBAAkB,CAAC,kCAAkC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE;YAChF,SAAS,CAAC,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAGD,aAAa;;QACX,OAAO,OAAA,IAAI,CAAC,uBAAuB,EAAE,0CAAE,UAAU,OAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACrF,CAAC;IAES,oBAAoB;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAGD,uBAAuB;QACrB,OAAO,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACnF,CAAC;IAED,cAAc,CAAC,oBAA0C;QACvD,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,C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AI,CAAC,kBAAkB,CAAC,iCAAiC,EAAE,CAAC,SAAS,EAAE,EAAE;gBACvE,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;YAC5C,CAAC,CAAC,CAAC;SACJ;QACD,IAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE;YAChG,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;YACpB,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAES,oBAAoB;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { ComponentType } from '@angular/cdk/overlay';\nimport { ComponentPortal, Portal } from '@angular/cdk/portal';\nimport { Command, Form, MultipleSelectionModel, SelectionModel, Types, UnaryCommand, Validator } from '@coolon/pectin';\nimport { Memoize } from '@typescript-plus/fast-memoize-decorator/dist/src';\nimport { AbstractInputComponent } from '../forms/abstract-input.component';\nimport { CellEditorComponent } from './cell-editor.component';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { DefaultCellRendererComponent } from './default-cell-renderer/default-cell-renderer.component';\nimport { DefaultHeaderCellRendererComponent } from './default-header-cell-renderer/default-header-cell-renderer.component';\nimport { EditRowControls } from './edit-row-controls/edit-row-controls.component';\nimport { EditSession } from './edit-session';\nimport { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';\nimport { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';\n\n\nexport interface ColumnHeaderConfig<Row, C extends any> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, column: ColumnModel<Row>) => void;\n}\n\nexport interface CellRendererConfig<Row, C extends any> {\n portal: Portal<C>;\n pushState?: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void;\n}\n\nexport interface CellEditorConfig<Row, V, C extends AbstractInputComponent<V>> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, editSession: EditSession<Row>) => void;\n}\n\n\nexport class ColumnModel<Row> {\n\n private _columnTextProperties: ColumnTextProperties;\n\n private _columnHeaderConfig: ColumnHeaderConfig<Row, any>;\n private _cellRendererConfig: CellRendererConfig<any, any>;\n private _cellEditorConfig: CellEditorConfig<any, any, any>;\n\n constructor(readonly columnId: string, private defaults: ColumnModel.Defaults) {\n this.cellHeaderRenderer(DefaultHeaderCellRendererComponent, (component, column) => {\n component.headerText = column.getHeaderText();\n });\n }\n\n @Memoize()\n getHeaderText(): string {\n return this.getColumnTextProperties()?.headerText() || this.getDefaultHeaderText();\n }\n\n protected getDefaultHeaderText() {\n return this.columnId;\n }\n\n @Memoize()\n getColumnTextProperties(): ColumnTextProperties {\n return this._columnTextProperties || this.defaults.getColumnTextProperties(this);\n }\n\n textProperties(columnTextProperties: ColumnTextProperties): this {\n this._columnTextProperties = columnTextProperties;\n return this;\n }\n\n protected setCellRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void): void {\n this._cellRendererConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n pushState: initialiser\n };\n }\n\n cellHeaderRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, column: ColumnModel<Row>) => void): void {\n this._columnHeaderConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n initialiseComponent: initialiser\n };\n }\n\n protected setCellEditor<E extends AbstractInputComponent<any>>(cellEditor: CellEditorConfig<any, any, any>): void {\n this._cellEditorConfig = cellEditor;\n }\n\n get cellRendererPortal() {\n return this._cellRendererConfig.portal;\n }\n\n get columnHeaderCellRendererPortal() {\n return this._columnHeaderConfig.portal;\n }\n\n get cellEditorPortal() {\n return this._cellEditorConfig?.portal;\n }\n\n hasEditor() {\n return !!this._cellEditorConfig;\n }\n\n updateCellRenderer(component: any, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) {\n this._cellRendererConfig.pushState(component, row, editRowCommand, editSession);\n }\n\n initialiseHeader(component: any) {\n this._columnHeaderConfig.initialiseComponent(component, this);\n }\n\n initialiseEditor(component: any, editSession: EditSession<Row>) {\n this._cellEditorConfig.initialiseComponent(component, editSession);\n }\n}\n\nexport namespace ColumnModel {\n export interface Defaults {\n getColumnTextProperties(columnModel: ColumnModel<any>): ColumnTextProperties;\n }\n}\n\nexport interface CellEditorOptions<V, E extends CellEditorComponent<V>> { //extends CellRendererOptions<E> {\n validators?: Validator<V>[];\n\n initialiseComponent?(component: E);\n}\n\nexport class PropertyColumnModel<Row, P extends Types.ValuePropertiesOf<Row>> extends ColumnModel<Row> {\n\n constructor(readonly property: P, defaults: ColumnModel.Defaults) {\n super(property.toString(), defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: Row[P] }>) {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = row[this.property];\n });\n }\n\n cellEditor<E extends CellEditorComponent<Row[P]>>(editor: ComponentType<E>, options?: CellEditorOptions<Row[P], E>): this {\n this.setCellEditor({\n portal: new ComponentPortal<E>(editor),\n initialiseComponent: (component: E, editSession: EditSession<Row>) => {\n const formValueModel = editSession.form.pluck(this.property);\n if (options?.validators) {\n formValueModel.validateUsing(options.validators);\n }\n component.valueModel = formValueModel;\n if (options?.initialiseComponent) {\n options.initialiseComponent(component);\n }\n }\n });\n return this;\n }\n}\n\nexport class CustomValueColumnModel<Row, V> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, private getValue: (row: Row) => V) {\n super(columnId, defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: V }>) {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this.getValue(row);\n });\n }\n}\n\nexport class EditorControlColumnModel<Row> extends ColumnModel<Row> {\n\n constructor(columnId: string, saveCommand: UnaryCommand<Form<Row>, boolean>, defaults: ColumnModel.Defaults) {\n super(columnId, defaults);\n this.cellRenderer(EditRowControls);\n }\n\n cellRenderer(componentType: ComponentType<{ row: Row, editSession: EditSession<Row>, editRowCommand: Command<void> }>) {\n this.setCellRenderer(componentType, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.editSession = editSession;\n component.editRowCommand = editRowCommand;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\nexport class CustomTemplateColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, component: ComponentType<{ editCommand: Command<void>, saveCommand: Command<void>, cancelCommand: Command<void> }>) {\n super(columnId, defaults);\n }\n}\n\nexport class SelectionColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, selectionModel: SelectionModel<Row>) {\n super(columnId, defaults);\n if (selectionModel instanceof MultipleSelectionModel) {\n this.cellHeaderRenderer(SelectHeaderCellRendererComponent, (component) => {\n component.selectionModel = selectionModel;\n });\n }\n this.setCellRenderer(SelectCellRendererComponent, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.selectionModel = selectionModel;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"column-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/column-model.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAU,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAiB,sBAAsB,EAAkD,MAAM,gBAAgB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAC;AAI3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yDAAyD,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,MAAM,uEAAuE,CAAC;AAC3H,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uDAAuD,CAAC;AACpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,qEAAqE,CAAC;A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2BAA2B,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE;YAChG,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;YACpB,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAES,oBAAoB;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { ComponentType } from '@angular/cdk/overlay';\nimport { ComponentPortal, Portal } from '@angular/cdk/portal';\nimport { Command, Form, MultipleSelectionModel, SelectionModel, Types, UnaryCommand, Validator } from '@coolon/pectin';\nimport { Memoize } from '@typescript-plus/fast-memoize-decorator/dist/src';\nimport { AbstractInputComponent } from '../forms/abstract-input.component';\nimport { CellEditorComponent } from './cell-editor.component';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { DefaultCellRendererComponent } from './default-cell-renderer/default-cell-renderer.component';\nimport { DefaultHeaderCellRendererComponent } from './default-header-cell-renderer/default-header-cell-renderer.component';\nimport { EditRowControls } from './edit-row-controls/edit-row-controls.component';\nimport { EditSession } from './edit-session';\nimport { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';\nimport { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';\nimport { assert } from '@coolon/typescript-utilities';\n\n\nexport interface ColumnHeaderConfig<Row, C extends any> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, column: ColumnModel<Row>) => void;\n}\n\nexport interface CellRendererConfig<Row, C extends any> {\n portal: Portal<C>;\n pushState?: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void;\n}\n\nexport interface CellEditorConfig<Row, V, C extends AbstractInputComponent<V>> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, editSession: EditSession<Row>) => void;\n}\n\n\nexport class ColumnModel<Row> {\n\n private _columnTextProperties: ColumnTextProperties;\n\n private _columnHeaderConfig: ColumnHeaderConfig<Row, any>;\n private _cellRendererConfig: CellRendererConfig<any, any>;\n private _cellEditorConfig: CellEditorConfig<any, any, any>;\n\n constructor(readonly columnId: string, private defaults: ColumnModel.Defaults) {\n this.cellHeaderRenderer(DefaultHeaderCellRendererComponent, (component, column) => {\n component.headerText = column.getHeaderText();\n });\n }\n\n @Memoize()\n getHeaderText(): string {\n return this.getColumnTextProperties()?.headerText() || this.getDefaultHeaderText();\n }\n\n protected getDefaultHeaderText() {\n return this.columnId;\n }\n\n @Memoize()\n getColumnTextProperties(): ColumnTextProperties {\n return this._columnTextProperties || this.defaults.getColumnTextProperties(this);\n }\n\n textProperties(columnTextProperties: ColumnTextProperties): this {\n this._columnTextProperties = columnTextProperties;\n return this;\n }\n\n protected setCellRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void): void {\n this._cellRendererConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n pushState: initialiser\n };\n }\n\n cellHeaderRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, column: ColumnModel<Row>) => void): this {\n this._columnHeaderConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n initialiseComponent: initialiser\n };\n return this;\n }\n\n protected setCellEditor<E extends AbstractInputComponent<any>>(cellEditor: CellEditorConfig<any, any, any>): void {\n this._cellEditorConfig = cellEditor;\n }\n\n get cellRendererPortal() {\n return this._cellRendererConfig.portal;\n }\n\n get columnHeaderCellRendererPortal() {\n return this._columnHeaderConfig.portal;\n }\n\n get cellEditorPortal() {\n return this._cellEditorConfig?.portal;\n }\n\n hasEditor() {\n return !!this._cellEditorConfig;\n }\n\n updateCellRenderer(component: any, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) {\n this._cellRendererConfig.pushState(component, row, editRowCommand, editSession);\n }\n\n initialiseHeader(component: any) {\n this._columnHeaderConfig.initialiseComponent(component, this);\n }\n\n initialiseEditor(component: any, editSession: EditSession<Row>) {\n this._cellEditorConfig.initialiseComponent(component, editSession);\n }\n}\n\nexport namespace ColumnModel {\n export interface Defaults {\n getColumnTextProperties(columnModel: ColumnModel<any>): ColumnTextProperties;\n }\n}\n\nexport interface CellEditorOptions<V, E extends CellEditorComponent<V>> { //extends CellRendererOptions<E> {\n validators?: Validator<V>[];\n\n initialiseComponent?(component: E);\n}\n\nexport class PropertyColumnModel<Row, P extends Types.ValuePropertiesOf<Row>> extends ColumnModel<Row> {\n\n\n private _format: (value: Row[P]) => any = (value) => value;\n\n constructor(readonly property: P, defaults: ColumnModel.Defaults) {\n super(property.toString(), defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: Row[P] }>): this {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this._format(row[this.property]);\n });\n return this;\n }\n\n cellEditor<E extends CellEditorComponent<Row[P]>>(editor: ComponentType<E>, options?: CellEditorOptions<Row[P], E>): this {\n this.setCellEditor({\n portal: new ComponentPortal<E>(editor),\n initialiseComponent: (component: E, editSession: EditSession<Row>) => {\n const formValueModel = editSession.form.pluck(this.property);\n if (options?.validators) {\n formValueModel.validateUsing(options.validators);\n }\n component.valueModel = formValueModel;\n if (options?.initialiseComponent) {\n options.initialiseComponent(component);\n }\n }\n });\n return this;\n }\n\n format(formatter: (value: Row[P]) => any): this {\n assert.isFunction(formatter)\n this._format = formatter;\n return this;\n }\n}\n\nexport class CustomValueColumnModel<Row, V> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, private getValue: (row: Row) => V) {\n super(columnId, defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: V }>): this {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this.getValue(row);\n });\n return this;\n }\n}\n\nexport class EditorControlColumnModel<Row> extends ColumnModel<Row> {\n\n constructor(columnId: string, saveCommand: UnaryCommand<Form<Row>, boolean>, defaults: ColumnModel.Defaults) {\n super(columnId, defaults);\n this.cellRenderer(EditRowControls);\n }\n\n cellRenderer(componentType: ComponentType<{ row: Row, editSession: EditSession<Row>, editRowCommand: Command<void> }>): this {\n this.setCellRenderer(componentType, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.editSession = editSession;\n component.editRowCommand = editRowCommand;\n });\n return this;\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\nexport class CustomTemplateColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, component: ComponentType<{ editCommand: Command<void>, saveCommand: Command<void>, cancelCommand: Command<void> }>) {\n super(columnId, defaults);\n }\n}\n\nexport class SelectionColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, selectionModel: SelectionModel<Row>) {\n super(columnId, defaults);\n if (selectionModel instanceof MultipleSelectionModel) {\n this.cellHeaderRenderer(SelectHeaderCellRendererComponent, (component) => {\n component.selectionModel = selectionModel;\n });\n }\n this.setCellRenderer(SelectCellRendererComponent, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.selectionModel = selectionModel;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\n\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{"ColumnHeaderConfig":{"__symbolic":"interface"},"CellRendererConfig":{"__symbolic":"interface"},"CellEditorConfig":{"__symbolic":"interface"},"ColumnModel":{"__symbolic":"class","arity":1,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"}]}],"getHeaderText":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@typescript-plus/fast-memoize-decorator/dist/src","name":"Memoize","line":
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{"ColumnHeaderConfig":{"__symbolic":"interface"},"CellRendererConfig":{"__symbolic":"interface"},"CellEditorConfig":{"__symbolic":"interface"},"ColumnModel":{"__symbolic":"class","arity":1,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"}]}],"getHeaderText":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@typescript-plus/fast-memoize-decorator/dist/src","name":"Memoize","line":46,"character":3}}]}],"getDefaultHeaderText":[{"__symbolic":"method"}],"getColumnTextProperties":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@typescript-plus/fast-memoize-decorator/dist/src","name":"Memoize","line":55,"character":3}}]}],"textProperties":[{"__symbolic":"method"}],"setCellRenderer":[{"__symbolic":"method"}],"cellHeaderRenderer":[{"__symbolic":"method"}],"setCellEditor":[{"__symbolic":"method"}],"hasEditor":[{"__symbolic":"method"}],"updateCellRenderer":[{"__symbolic":"method"}],"initialiseHeader":[{"__symbolic":"method"}],"initialiseEditor":[{"__symbolic":"method"}]}},"CellEditorOptions":{"__symbolic":"interface"},"PropertyColumnModel":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"ColumnModel"},"arity":2,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"error","message":"Could not resolve type","line":130,"character":33,"context":{"typeName":"P"}},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"}]}],"cellRenderer":[{"__symbolic":"method"}],"cellEditor":[{"__symbolic":"method"}],"format":[{"__symbolic":"method"}]}},"CustomValueColumnModel":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"ColumnModel"},"arity":2,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"},{"__symbolic":"error","message":"Expression form not supported","line":167,"character":82}]}],"cellRenderer":[{"__symbolic":"method"}]}},"EditorControlColumnModel":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"ColumnModel"},"arity":1,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","module":"@coolon/pectin","name":"UnaryCommand","line":182,"character":45,"arguments":[{"__symbolic":"reference","module":"@coolon/pectin","name":"Form","line":182,"character":58,"arguments":[{"__symbolic":"error","message":"Could not resolve type","line":182,"character":63,"context":{"typeName":"Row"}}]},{"__symbolic":"reference","name":"boolean"}]},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"}]}],"cellRenderer":[{"__symbolic":"method"}],"getDefaultHeaderText":[{"__symbolic":"method"}]}},"CustomTemplateColumnModel":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"ColumnModel"},"arity":1,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"},{"__symbolic":"reference","module":"@angular/cdk/overlay","name":"ComponentType","line":202,"character":75,"arguments":[{"__symbolic":"error","message":"Expression form not supported","line":202,"character":89}]}]}]}},"SelectionColumnModel":{"__symbolic":"class","extends":{"__symbolic":"reference","name":"ColumnModel"},"arity":1,"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"string"},{"__symbolic":"select","expression":{"__symbolic":"reference","name":"ColumnModel"},"member":"Defaults"},{"__symbolic":"reference","module":"@coolon/pectin","name":"SelectionModel","line":208,"character":80,"arguments":[{"__symbolic":"error","message":"Could not resolve type","line":208,"character":95,"context":{"typeName":"Row"}}]}]}],"getDefaultHeaderText":[{"__symbolic":"method"}]}}}}]
|
|
@@ -133,7 +133,7 @@ let TableModel = TableModel_1 = class TableModel {
|
|
|
133
133
|
this._columnTextPropertiesLookup = columnTextProperties;
|
|
134
134
|
}
|
|
135
135
|
getColumnTextProperties(column) {
|
|
136
|
-
const factory = this._columnTextPropertiesLookup[column.columnId];
|
|
136
|
+
const factory = this._columnTextPropertiesLookup ? this._columnTextPropertiesLookup[column.columnId] : undefined;
|
|
137
137
|
return factory ? factory() : undefined;
|
|
138
138
|
}
|
|
139
139
|
startEditSession(row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/table-model.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,GAAG,EACH,IAAI,EACJ,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,EACL,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,oGAAoG;AACpG,oGAAoG;AAGpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH,IAAa,UAAU,kBAAvB,MAAa,UAAU;IAwBrB,YAA8B,aAA6B;QAA7B,kBAAa,GAAb,aAAa,CAAgB;QAtB1C,aAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAElC,aAAQ,GAAG,IAAI,gBAAgB,EAAoB,CAAC;QAE7D,oBAAe,GAAG,IAAI,gBAAgB,EAAoB,CAAC;QAmBjE,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC;QAC3C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClG,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,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AAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;;YA5F8C,SAAS;;AAxB3C,UAAU;IADtB,aAAa,CAAC,QAAQ,CAAC,IAAI,aAAa,CAAC,cAAc,EAAE,CAAC;qCAyBZ,SAAS;GAxB3C,UAAU,CAoHtB;SApHY,UAAU","sourcesContent":["import {\n BooleanValueModelChain,\n CanIdentify,\n Dsl,\n Form,\n GarbageCollector,\n lang,\n ListModel,\n ListModelChain,\n MapModelChain,\n MutableListModel,\n SelectionModel,\n TrackExternal,\n Types,\n UnaryCommand\n} from '@coolon/pectin';\nimport {\n ColumnModel,\n CustomValueColumnModel,\n EditorControlColumnModel,\n PropertyColumnModel,\n SelectionColumnModel\n} from './column-model';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { EditSession } from './edit-session';\n\n// export type StringPropertiesOf<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];\n// export type NumberPropertiesOf<T> = { [K in keyof T]: T[K] extends number ? K : never }[keyof T];\n\n\n/**\n * Example:\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * Editable tables\n * @example\n * const saveCommand = UnaryCommand.create((form: Form<Hero>) => {\n * if (form.validate()) {\n * // normal form save stuff\n * return true; // finish editing\n * }\n * return false; // continue editiing\n * }\n * const colorsNames: ListModel<string> = ...;\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\").cellEditor(StringInputComponent); <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.pluck(\"lastName\").cellEditor(StringInputComponent, {\n * validators: [Validator.present(\"We need a last name\")]\n * });\n * table.pluck(\"age\").cellEditor(NumberInputComponent);\n * table.pluck(\"favoriteColor\").cellEditor(SelectInputComponent, {\n * initialiseComponent(component: SelectInputComponent) {\n * selectInput.optionsModel = colorsNames; // <- initialise our component\n * }\n * });\n * table.addEditControls(saveCommand); // <- required to enable editing\n * });\n *\n * Selection models\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.addSelectionColumn(selectionModel); // <- can be single or multiple selection model\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * });\n *\n * Custom cell renderers and editors\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\")\n * .cellHeaderRenderer(CellHeaderRendererComponent, (component, column) => {\n * // configure your component with what ever you need.\n * });\n * .cellRenderer(CellRendererComponent) // <-- interface CellEditor { value: string; }\n * .cellEditor(CellEditorComponent.); // <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * I18n\n * @example\n * [table.yml]\n * table:\n * columns(ColumnTextProperties[]):\n * firstName:\n * headerText: \"First Name\"\n * fullName:\n * headerText: \"Full Name\"\n *\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\").cellRenderer(...).cellEditor(...);\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n *\n * table.columnTextProperties(I18n.table.columns); // <- configures all columns\n * });\n */\n@TrackExternal.Strategy(new TrackExternal.OneTimeBinding())\nexport class TableModel<Row> {\n\n private readonly _garbage = new GarbageCollector();\n\n private readonly _columns = new MutableListModel<ColumnModel<Row>>();\n private _columnsById: MapModelChain<string, ColumnModel<Row>>;\n private _editorSessions = new MutableListModel<EditSession<Row>>();\n private readonly _rowsBeingEdited: MutableListModel<Row>;\n\n private _columnTextPropertiesLookup: { [columnName: string]: () => ColumnTextProperties };\n\n readonly identityOf: CanIdentify<Row>['identityOf'];\n private saveCommand: UnaryCommand<Form<Row>, boolean>;\n private _editorSessionByRowId: MapModelChain<any, EditSession<Row>>;\n\n readonly editing: BooleanValueModelChain;\n readonly dataSource: ListModelChain<Row>;\n\n static fromList<Row>(sourceOfTruth: ListModel<Row>, builder?: (tableModel: TableModel<Row>) => void): TableModel<Row> {\n const model = new TableModel<Row>(sourceOfTruth);\n builder(model);\n return model;\n }\n\n protected constructor(private sourceOfTruth: ListModel<Row>) {\n this.identityOf = sourceOfTruth.identityOf;\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this._garbage);\n this._columnsById = chain(this._columns).indexBy('columnId');\n this._rowsBeingEdited = new MutableListModel<Row>([], {\n identifiedWith: this.identityOf\n });\n this._editorSessionByRowId = chain(this._editorSessions).indexBy('rowId');\n this.editing = chain(this._editorSessions).count().isGreaterThan(0);\n this.dataSource = chain(this.sourceOfTruth).replaceAll(this.rowsBeingEdited);\n }\n\n get rowsBeingEdited(): ListModel<Row> {\n return this._rowsBeingEdited.readonly;\n }\n\n getTrackByFunction() {\n return (index: number, item: Row) => {\n return this.identityOf ? this.identityOf(item) : index;\n };\n }\n\n get columns(): ListModel<ColumnModel<Row>> {\n return this._columns.readonly;\n }\n\n pluck<P extends Types.ValuePropertiesOf<Row>>(property: P): PropertyColumnModel<Row, P> {\n return this.addColumn(new PropertyColumnModel<Row, P>(property, this));\n }\n\n addSelectionColumn(selectionModel: SelectionModel<Row>): SelectionColumnModel<Row> {\n return this.addColumn(new SelectionColumnModel<Row>('selection', this, selectionModel));\n }\n\n addEditControls(saveCommand: UnaryCommand<Form<Row>, boolean>): EditorControlColumnModel<Row> {\n this.saveCommand = saveCommand;\n return this.addColumn(new EditorControlColumnModel<Row>('editControls', saveCommand, this));\n }\n\n addCustomColumn<V>(columnId: string, dataAccessor: (row: Row) => V): CustomValueColumnModel<Row, V> {\n return this.addColumn(new CustomValueColumnModel<Row, V>(columnId, this, dataAccessor));\n }\n\n protected addColumn<C extends ColumnModel<Row>>(column: C): C {\n if (this._columnsById.get(column.columnId)) {\n lang.illegalState(`Column with id=${column.columnId} already exists`);\n } else {\n this._columns.push(column);\n }\n return column;\n }\n\n columnTextProperties(columnTextProperties: { [columnName: string]: () => ColumnTextProperties }) {\n this._columnTextPropertiesLookup = columnTextProperties;\n }\n\n getColumnTextProperties(column: ColumnModel<Row>): ColumnTextProperties {\n const factory = this._columnTextPropertiesLookup[column.columnId];\n return factory ? factory() : undefined;\n }\n\n startEditSession(row: Row): EditSession<Row> {\n const rowId = this.identityOf(row);\n if (this._rowsBeingEdited.query().indexOf(row) > -1) {\n return lang.illegalState(`Row with id=${rowId} already being edited`);\n } else {\n const editSession = new EditSession<Row>(rowId, row, this.saveCommand);\n const { when } = Dsl.disposeWith(editSession);\n when.valueOf(editSession.rowValueModel).changes((editedValue) => {\n this._rowsBeingEdited.replaceOrPush(editedValue);\n }, { initialValue: 'triggerChangeUnlessNil' });\n\n this._editorSessions.push(editSession);\n editSession.onDispose(() => {\n this._rowsBeingEdited.remove(editSession.rowValueModel.value);\n this._editorSessions.remove(editSession);\n });\n return editSession;\n }\n }\n\n getEditSessionFor(row: Row): EditSession<Row> {\n return this._editorSessionByRowId.get(this.identityOf(row));\n }\n\n cancelAllEditorSessions() {\n this._editorSessions.runInTransaction((draft) => {\n this._rowsBeingEdited.runInTransaction(() => {\n draft.value.forEach(session => session.dispose());\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"table-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/table-model.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,GAAG,EACH,IAAI,EACJ,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,EACL,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,oGAAoG;AACpG,oGAAoG;AAGpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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gB,CAAC,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC9D,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;YACH,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;IAED,iBAAiB,CAAC,GAAQ;QACxB,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,uBAAuB;QACrB,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,EAAE;gBAC1C,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;;YA5F8C,SAAS;;AAxB3C,UAAU;IADtB,aAAa,CAAC,QAAQ,CAAC,IAAI,aAAa,CAAC,cAAc,EAAE,CAAC;qCAyBZ,SAAS;GAxB3C,UAAU,CAoHtB;SApHY,UAAU","sourcesContent":["import {\n BooleanValueModelChain,\n CanIdentify,\n Dsl,\n Form,\n GarbageCollector,\n lang,\n ListModel,\n ListModelChain,\n MapModelChain,\n MutableListModel,\n SelectionModel,\n TrackExternal,\n Types,\n UnaryCommand\n} from '@coolon/pectin';\nimport {\n ColumnModel,\n CustomValueColumnModel,\n EditorControlColumnModel,\n PropertyColumnModel,\n SelectionColumnModel\n} from './column-model';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { EditSession } from './edit-session';\n\n// export type StringPropertiesOf<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];\n// export type NumberPropertiesOf<T> = { [K in keyof T]: T[K] extends number ? K : never }[keyof T];\n\n\n/**\n * Example:\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * Editable tables\n * @example\n * const saveCommand = UnaryCommand.create((form: Form<Hero>) => {\n * if (form.validate()) {\n * // normal form save stuff\n * return true; // finish editing\n * }\n * return false; // continue editiing\n * }\n * const colorsNames: ListModel<string> = ...;\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\").cellEditor(StringInputComponent); <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.pluck(\"lastName\").cellEditor(StringInputComponent, {\n * validators: [Validator.present(\"We need a last name\")]\n * });\n * table.pluck(\"age\").cellEditor(NumberInputComponent);\n * table.pluck(\"favoriteColor\").cellEditor(SelectInputComponent, {\n * initialiseComponent(component: SelectInputComponent) {\n * selectInput.optionsModel = colorsNames; // <- initialise our component\n * }\n * });\n * table.addEditControls(saveCommand); // <- required to enable editing\n * });\n *\n * Selection models\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.addSelectionColumn(selectionModel); // <- can be single or multiple selection model\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * });\n *\n * Custom cell renderers and editors\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\")\n * .cellHeaderRenderer(CellHeaderRendererComponent, (component, column) => {\n * // configure your component with what ever you need.\n * });\n * .cellRenderer(CellRendererComponent) // <-- interface CellEditor { value: string; }\n * .cellEditor(CellEditorComponent.); // <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * I18n\n * @example\n * [table.yml]\n * table:\n * columns(ColumnTextProperties[]):\n * firstName:\n * headerText: \"First Name\"\n * fullName:\n * headerText: \"Full Name\"\n *\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\").cellRenderer(...).cellEditor(...);\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n *\n * table.columnTextProperties(I18n.table.columns); // <- configures all columns\n * });\n */\n@TrackExternal.Strategy(new TrackExternal.OneTimeBinding())\nexport class TableModel<Row> {\n\n private readonly _garbage = new GarbageCollector();\n\n private readonly _columns = new MutableListModel<ColumnModel<Row>>();\n private _columnsById: MapModelChain<string, ColumnModel<Row>>;\n private _editorSessions = new MutableListModel<EditSession<Row>>();\n private readonly _rowsBeingEdited: MutableListModel<Row>;\n\n private _columnTextPropertiesLookup: { [columnName: string]: () => ColumnTextProperties };\n\n readonly identityOf: CanIdentify<Row>['identityOf'];\n private saveCommand: UnaryCommand<Form<Row>, boolean>;\n private _editorSessionByRowId: MapModelChain<any, EditSession<Row>>;\n\n readonly editing: BooleanValueModelChain;\n readonly dataSource: ListModelChain<Row>;\n\n static fromList<Row>(sourceOfTruth: ListModel<Row>, builder?: (tableModel: TableModel<Row>) => void): TableModel<Row> {\n const model = new TableModel<Row>(sourceOfTruth);\n builder(model);\n return model;\n }\n\n protected constructor(private sourceOfTruth: ListModel<Row>) {\n this.identityOf = sourceOfTruth.identityOf;\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this._garbage);\n this._columnsById = chain(this._columns).indexBy('columnId');\n this._rowsBeingEdited = new MutableListModel<Row>([], {\n identifiedWith: this.identityOf\n });\n this._editorSessionByRowId = chain(this._editorSessions).indexBy('rowId');\n this.editing = chain(this._editorSessions).count().isGreaterThan(0);\n this.dataSource = chain(this.sourceOfTruth).replaceAll(this.rowsBeingEdited);\n }\n\n get rowsBeingEdited(): ListModel<Row> {\n return this._rowsBeingEdited.readonly;\n }\n\n getTrackByFunction() {\n return (index: number, item: Row) => {\n return this.identityOf ? this.identityOf(item) : index;\n };\n }\n\n get columns(): ListModel<ColumnModel<Row>> {\n return this._columns.readonly;\n }\n\n pluck<P extends Types.ValuePropertiesOf<Row>>(property: P): PropertyColumnModel<Row, P> {\n return this.addColumn(new PropertyColumnModel<Row, P>(property, this));\n }\n\n addSelectionColumn(selectionModel: SelectionModel<Row>): SelectionColumnModel<Row> {\n return this.addColumn(new SelectionColumnModel<Row>('selection', this, selectionModel));\n }\n\n addEditControls(saveCommand: UnaryCommand<Form<Row>, boolean>): EditorControlColumnModel<Row> {\n this.saveCommand = saveCommand;\n return this.addColumn(new EditorControlColumnModel<Row>('editControls', saveCommand, this));\n }\n\n addCustomColumn<V>(columnId: string, dataAccessor: (row: Row) => V): CustomValueColumnModel<Row, V> {\n return this.addColumn(new CustomValueColumnModel<Row, V>(columnId, this, dataAccessor));\n }\n\n protected addColumn<C extends ColumnModel<Row>>(column: C): C {\n if (this._columnsById.get(column.columnId)) {\n lang.illegalState(`Column with id=${column.columnId} already exists`);\n } else {\n this._columns.push(column);\n }\n return column;\n }\n\n columnTextProperties(columnTextProperties: { [columnName: string]: () => ColumnTextProperties }) {\n this._columnTextPropertiesLookup = columnTextProperties;\n }\n\n getColumnTextProperties(column: ColumnModel<Row>): ColumnTextProperties {\n const factory = this._columnTextPropertiesLookup ? this._columnTextPropertiesLookup[column.columnId] : undefined;\n return factory ? factory() : undefined;\n }\n\n startEditSession(row: Row): EditSession<Row> {\n const rowId = this.identityOf(row);\n if (this._rowsBeingEdited.query().indexOf(row) > -1) {\n return lang.illegalState(`Row with id=${rowId} already being edited`);\n } else {\n const editSession = new EditSession<Row>(rowId, row, this.saveCommand);\n const { when } = Dsl.disposeWith(editSession);\n when.valueOf(editSession.rowValueModel).changes((editedValue) => {\n this._rowsBeingEdited.replaceOrPush(editedValue);\n }, { initialValue: 'triggerChangeUnlessNil' });\n\n this._editorSessions.push(editSession);\n editSession.onDispose(() => {\n this._rowsBeingEdited.remove(editSession.rowValueModel.value);\n this._editorSessions.remove(editSession);\n });\n return editSession;\n }\n }\n\n getEditSessionFor(row: Row): EditSession<Row> {\n return this._editorSessionByRowId.get(this.identityOf(row));\n }\n\n cancelAllEditorSessions() {\n this._editorSessions.runInTransaction((draft) => {\n this._rowsBeingEdited.runInTransaction(() => {\n draft.value.forEach(session => session.dispose());\n });\n });\n }\n}\n"]}
|
|
@@ -7,6 +7,7 @@ import { DefaultHeaderCellRendererComponent } from './default-header-cell-render
|
|
|
7
7
|
import { EditRowControls } from './edit-row-controls/edit-row-controls.component';
|
|
8
8
|
import { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';
|
|
9
9
|
import { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';
|
|
10
|
+
import { assert } from '@coolon/typescript-utilities';
|
|
10
11
|
var ColumnModel = /** @class */ (function () {
|
|
11
12
|
function ColumnModel(columnId, defaults) {
|
|
12
13
|
this.columnId = columnId;
|
|
@@ -40,6 +41,7 @@ var ColumnModel = /** @class */ (function () {
|
|
|
40
41
|
portal: new ComponentPortal(cellRenderer),
|
|
41
42
|
initialiseComponent: initialiser
|
|
42
43
|
};
|
|
44
|
+
return this;
|
|
43
45
|
};
|
|
44
46
|
ColumnModel.prototype.setCellEditor = function (cellEditor) {
|
|
45
47
|
this._cellEditorConfig = cellEditor;
|
|
@@ -98,14 +100,16 @@ var PropertyColumnModel = /** @class */ (function (_super) {
|
|
|
98
100
|
function PropertyColumnModel(property, defaults) {
|
|
99
101
|
var _this = _super.call(this, property.toString(), defaults) || this;
|
|
100
102
|
_this.property = property;
|
|
103
|
+
_this._format = function (value) { return value; };
|
|
101
104
|
_this.cellRenderer(DefaultCellRendererComponent);
|
|
102
105
|
return _this;
|
|
103
106
|
}
|
|
104
107
|
PropertyColumnModel.prototype.cellRenderer = function (componentType) {
|
|
105
108
|
var _this = this;
|
|
106
109
|
this.setCellRenderer(componentType, function (component, row) {
|
|
107
|
-
component.value = row[_this.property];
|
|
110
|
+
component.value = _this._format(row[_this.property]);
|
|
108
111
|
});
|
|
112
|
+
return this;
|
|
109
113
|
};
|
|
110
114
|
PropertyColumnModel.prototype.cellEditor = function (editor, options) {
|
|
111
115
|
var _this = this;
|
|
@@ -124,6 +128,11 @@ var PropertyColumnModel = /** @class */ (function (_super) {
|
|
|
124
128
|
});
|
|
125
129
|
return this;
|
|
126
130
|
};
|
|
131
|
+
PropertyColumnModel.prototype.format = function (formatter) {
|
|
132
|
+
assert.isFunction(formatter);
|
|
133
|
+
this._format = formatter;
|
|
134
|
+
return this;
|
|
135
|
+
};
|
|
127
136
|
return PropertyColumnModel;
|
|
128
137
|
}(ColumnModel));
|
|
129
138
|
export { PropertyColumnModel };
|
|
@@ -140,6 +149,7 @@ var CustomValueColumnModel = /** @class */ (function (_super) {
|
|
|
140
149
|
this.setCellRenderer(componentType, function (component, row) {
|
|
141
150
|
component.value = _this.getValue(row);
|
|
142
151
|
});
|
|
152
|
+
return this;
|
|
143
153
|
};
|
|
144
154
|
return CustomValueColumnModel;
|
|
145
155
|
}(ColumnModel));
|
|
@@ -157,6 +167,7 @@ var EditorControlColumnModel = /** @class */ (function (_super) {
|
|
|
157
167
|
component.editSession = editSession;
|
|
158
168
|
component.editRowCommand = editRowCommand;
|
|
159
169
|
});
|
|
170
|
+
return this;
|
|
160
171
|
};
|
|
161
172
|
EditorControlColumnModel.prototype.getDefaultHeaderText = function () {
|
|
162
173
|
return '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/column-model.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAU,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAiB,sBAAsB,EAAkD,MAAM,gBAAgB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAC;AAI3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yDAAyD,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,MAAM,uEAAuE,CAAC;AAC3H,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,MAAM,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AAE,WAAW;YAC5F,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;YACpB,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;QAC5C,CAAC,CAAC,CAAC;;IACL,CAAC;IAES,mDAAoB,GAA9B;QACE,OAAO,EAAE,CAAC;IACZ,CAAC;IACH,2BAAC;AAAD,CAAC,AAjBD,CAA+C,WAAW,GAiBzD","sourcesContent":["import { ComponentType } from '@angular/cdk/overlay';\nimport { ComponentPortal, Portal } from '@angular/cdk/portal';\nimport { Command, Form, MultipleSelectionModel, SelectionModel, Types, UnaryCommand, Validator } from '@coolon/pectin';\nimport { Memoize } from '@typescript-plus/fast-memoize-decorator/dist/src';\nimport { AbstractInputComponent } from '../forms/abstract-input.component';\nimport { CellEditorComponent } from './cell-editor.component';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { DefaultCellRendererComponent } from './default-cell-renderer/default-cell-renderer.component';\nimport { DefaultHeaderCellRendererComponent } from './default-header-cell-renderer/default-header-cell-renderer.component';\nimport { EditRowControls } from './edit-row-controls/edit-row-controls.component';\nimport { EditSession } from './edit-session';\nimport { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';\nimport { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';\n\n\nexport interface ColumnHeaderConfig<Row, C extends any> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, column: ColumnModel<Row>) => void;\n}\n\nexport interface CellRendererConfig<Row, C extends any> {\n portal: Portal<C>;\n pushState?: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void;\n}\n\nexport interface CellEditorConfig<Row, V, C extends AbstractInputComponent<V>> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, editSession: EditSession<Row>) => void;\n}\n\n\nexport class ColumnModel<Row> {\n\n private _columnTextProperties: ColumnTextProperties;\n\n private _columnHeaderConfig: ColumnHeaderConfig<Row, any>;\n private _cellRendererConfig: CellRendererConfig<any, any>;\n private _cellEditorConfig: CellEditorConfig<any, any, any>;\n\n constructor(readonly columnId: string, private defaults: ColumnModel.Defaults) {\n this.cellHeaderRenderer(DefaultHeaderCellRendererComponent, (component, column) => {\n component.headerText = column.getHeaderText();\n });\n }\n\n @Memoize()\n getHeaderText(): string {\n return this.getColumnTextProperties()?.headerText() || this.getDefaultHeaderText();\n }\n\n protected getDefaultHeaderText() {\n return this.columnId;\n }\n\n @Memoize()\n getColumnTextProperties(): ColumnTextProperties {\n return this._columnTextProperties || this.defaults.getColumnTextProperties(this);\n }\n\n textProperties(columnTextProperties: ColumnTextProperties): this {\n this._columnTextProperties = columnTextProperties;\n return this;\n }\n\n protected setCellRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void): void {\n this._cellRendererConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n pushState: initialiser\n };\n }\n\n cellHeaderRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, column: ColumnModel<Row>) => void): void {\n this._columnHeaderConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n initialiseComponent: initialiser\n };\n }\n\n protected setCellEditor<E extends AbstractInputComponent<any>>(cellEditor: CellEditorConfig<any, any, any>): void {\n this._cellEditorConfig = cellEditor;\n }\n\n get cellRendererPortal() {\n return this._cellRendererConfig.portal;\n }\n\n get columnHeaderCellRendererPortal() {\n return this._columnHeaderConfig.portal;\n }\n\n get cellEditorPortal() {\n return this._cellEditorConfig?.portal;\n }\n\n hasEditor() {\n return !!this._cellEditorConfig;\n }\n\n updateCellRenderer(component: any, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) {\n this._cellRendererConfig.pushState(component, row, editRowCommand, editSession);\n }\n\n initialiseHeader(component: any) {\n this._columnHeaderConfig.initialiseComponent(component, this);\n }\n\n initialiseEditor(component: any, editSession: EditSession<Row>) {\n this._cellEditorConfig.initialiseComponent(component, editSession);\n }\n}\n\nexport namespace ColumnModel {\n export interface Defaults {\n getColumnTextProperties(columnModel: ColumnModel<any>): ColumnTextProperties;\n }\n}\n\nexport interface CellEditorOptions<V, E extends CellEditorComponent<V>> { //extends CellRendererOptions<E> {\n validators?: Validator<V>[];\n\n initialiseComponent?(component: E);\n}\n\nexport class PropertyColumnModel<Row, P extends Types.ValuePropertiesOf<Row>> extends ColumnModel<Row> {\n\n constructor(readonly property: P, defaults: ColumnModel.Defaults) {\n super(property.toString(), defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: Row[P] }>) {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = row[this.property];\n });\n }\n\n cellEditor<E extends CellEditorComponent<Row[P]>>(editor: ComponentType<E>, options?: CellEditorOptions<Row[P], E>): this {\n this.setCellEditor({\n portal: new ComponentPortal<E>(editor),\n initialiseComponent: (component: E, editSession: EditSession<Row>) => {\n const formValueModel = editSession.form.pluck(this.property);\n if (options?.validators) {\n formValueModel.validateUsing(options.validators);\n }\n component.valueModel = formValueModel;\n if (options?.initialiseComponent) {\n options.initialiseComponent(component);\n }\n }\n });\n return this;\n }\n}\n\nexport class CustomValueColumnModel<Row, V> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, private getValue: (row: Row) => V) {\n super(columnId, defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: V }>) {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this.getValue(row);\n });\n }\n}\n\nexport class EditorControlColumnModel<Row> extends ColumnModel<Row> {\n\n constructor(columnId: string, saveCommand: UnaryCommand<Form<Row>, boolean>, defaults: ColumnModel.Defaults) {\n super(columnId, defaults);\n this.cellRenderer(EditRowControls);\n }\n\n cellRenderer(componentType: ComponentType<{ row: Row, editSession: EditSession<Row>, editRowCommand: Command<void> }>) {\n this.setCellRenderer(componentType, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.editSession = editSession;\n component.editRowCommand = editRowCommand;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\nexport class CustomTemplateColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, component: ComponentType<{ editCommand: Command<void>, saveCommand: Command<void>, cancelCommand: Command<void> }>) {\n super(columnId, defaults);\n }\n}\n\nexport class SelectionColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, selectionModel: SelectionModel<Row>) {\n super(columnId, defaults);\n if (selectionModel instanceof MultipleSelectionModel) {\n this.cellHeaderRenderer(SelectHeaderCellRendererComponent, (component) => {\n component.selectionModel = selectionModel;\n });\n }\n this.setCellRenderer(SelectCellRendererComponent, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.selectionModel = selectionModel;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"column-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/column-model.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAU,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAiB,sBAAsB,EAAkD,MAAM,gBAAgB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,MAAM,kDAAkD,CAAC;AAI3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yDAAyD,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,MAAM,uEAAuE,CAAC;AAC3H,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAElF,OAAO,EAAE,2BAA2B,EAAE,MAAM,uDAAuD,CAAC;AACpG,OAAO,EAAE,iCAAiC,EAAE,MAAM,qEAAqE,CAAC;AACxH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAmBtD;IAQE,qBAAqB,QAAgB,EAAU,QAA8B;QAAxD,aAAQ,GAAR,QAAQ,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAsB;QAC3E,IAAI,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ACnE,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;YAC5C,CAAC,CAAC,CAAC;SACJ;QACD,KAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,UAAC,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,WAAW;YAC5F,SAAS,CAAC,GAAG,GAAG,GAAG,CAAC;YACpB,SAAS,CAAC,cAAc,GAAG,cAAc,CAAC;QAC5C,CAAC,CAAC,CAAC;;IACL,CAAC;IAES,mDAAoB,GAA9B;QACE,OAAO,EAAE,CAAC;IACZ,CAAC;IACH,2BAAC;AAAD,CAAC,AAjBD,CAA+C,WAAW,GAiBzD","sourcesContent":["import { ComponentType } from '@angular/cdk/overlay';\nimport { ComponentPortal, Portal } from '@angular/cdk/portal';\nimport { Command, Form, MultipleSelectionModel, SelectionModel, Types, UnaryCommand, Validator } from '@coolon/pectin';\nimport { Memoize } from '@typescript-plus/fast-memoize-decorator/dist/src';\nimport { AbstractInputComponent } from '../forms/abstract-input.component';\nimport { CellEditorComponent } from './cell-editor.component';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { DefaultCellRendererComponent } from './default-cell-renderer/default-cell-renderer.component';\nimport { DefaultHeaderCellRendererComponent } from './default-header-cell-renderer/default-header-cell-renderer.component';\nimport { EditRowControls } from './edit-row-controls/edit-row-controls.component';\nimport { EditSession } from './edit-session';\nimport { SelectCellRendererComponent } from './select-cell-renderer/select-cell-renderer.component';\nimport { SelectHeaderCellRendererComponent } from './select-header-cell-renderer/select-header-cell-renderer.component';\nimport { assert } from '@coolon/typescript-utilities';\n\n\nexport interface ColumnHeaderConfig<Row, C extends any> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, column: ColumnModel<Row>) => void;\n}\n\nexport interface CellRendererConfig<Row, C extends any> {\n portal: Portal<C>;\n pushState?: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void;\n}\n\nexport interface CellEditorConfig<Row, V, C extends AbstractInputComponent<V>> {\n portal: Portal<C>;\n initialiseComponent?: (component: C, editSession: EditSession<Row>) => void;\n}\n\n\nexport class ColumnModel<Row> {\n\n private _columnTextProperties: ColumnTextProperties;\n\n private _columnHeaderConfig: ColumnHeaderConfig<Row, any>;\n private _cellRendererConfig: CellRendererConfig<any, any>;\n private _cellEditorConfig: CellEditorConfig<any, any, any>;\n\n constructor(readonly columnId: string, private defaults: ColumnModel.Defaults) {\n this.cellHeaderRenderer(DefaultHeaderCellRendererComponent, (component, column) => {\n component.headerText = column.getHeaderText();\n });\n }\n\n @Memoize()\n getHeaderText(): string {\n return this.getColumnTextProperties()?.headerText() || this.getDefaultHeaderText();\n }\n\n protected getDefaultHeaderText() {\n return this.columnId;\n }\n\n @Memoize()\n getColumnTextProperties(): ColumnTextProperties {\n return this._columnTextProperties || this.defaults.getColumnTextProperties(this);\n }\n\n textProperties(columnTextProperties: ColumnTextProperties): this {\n this._columnTextProperties = columnTextProperties;\n return this;\n }\n\n protected setCellRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) => void): void {\n this._cellRendererConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n pushState: initialiser\n };\n }\n\n cellHeaderRenderer<C>(cellRenderer: ComponentType<C>, initialiser: (component: C, column: ColumnModel<Row>) => void): this {\n this._columnHeaderConfig = {\n portal: new ComponentPortal<C>(cellRenderer),\n initialiseComponent: initialiser\n };\n return this;\n }\n\n protected setCellEditor<E extends AbstractInputComponent<any>>(cellEditor: CellEditorConfig<any, any, any>): void {\n this._cellEditorConfig = cellEditor;\n }\n\n get cellRendererPortal() {\n return this._cellRendererConfig.portal;\n }\n\n get columnHeaderCellRendererPortal() {\n return this._columnHeaderConfig.portal;\n }\n\n get cellEditorPortal() {\n return this._cellEditorConfig?.portal;\n }\n\n hasEditor() {\n return !!this._cellEditorConfig;\n }\n\n updateCellRenderer(component: any, row: Row, editRowCommand: Command<void>, editSession: EditSession<Row>) {\n this._cellRendererConfig.pushState(component, row, editRowCommand, editSession);\n }\n\n initialiseHeader(component: any) {\n this._columnHeaderConfig.initialiseComponent(component, this);\n }\n\n initialiseEditor(component: any, editSession: EditSession<Row>) {\n this._cellEditorConfig.initialiseComponent(component, editSession);\n }\n}\n\nexport namespace ColumnModel {\n export interface Defaults {\n getColumnTextProperties(columnModel: ColumnModel<any>): ColumnTextProperties;\n }\n}\n\nexport interface CellEditorOptions<V, E extends CellEditorComponent<V>> { //extends CellRendererOptions<E> {\n validators?: Validator<V>[];\n\n initialiseComponent?(component: E);\n}\n\nexport class PropertyColumnModel<Row, P extends Types.ValuePropertiesOf<Row>> extends ColumnModel<Row> {\n\n\n private _format: (value: Row[P]) => any = (value) => value;\n\n constructor(readonly property: P, defaults: ColumnModel.Defaults) {\n super(property.toString(), defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: Row[P] }>): this {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this._format(row[this.property]);\n });\n return this;\n }\n\n cellEditor<E extends CellEditorComponent<Row[P]>>(editor: ComponentType<E>, options?: CellEditorOptions<Row[P], E>): this {\n this.setCellEditor({\n portal: new ComponentPortal<E>(editor),\n initialiseComponent: (component: E, editSession: EditSession<Row>) => {\n const formValueModel = editSession.form.pluck(this.property);\n if (options?.validators) {\n formValueModel.validateUsing(options.validators);\n }\n component.valueModel = formValueModel;\n if (options?.initialiseComponent) {\n options.initialiseComponent(component);\n }\n }\n });\n return this;\n }\n\n format(formatter: (value: Row[P]) => any): this {\n assert.isFunction(formatter)\n this._format = formatter;\n return this;\n }\n}\n\nexport class CustomValueColumnModel<Row, V> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, private getValue: (row: Row) => V) {\n super(columnId, defaults);\n this.cellRenderer(DefaultCellRendererComponent);\n }\n\n cellRenderer(componentType: ComponentType<{ value: V }>): this {\n this.setCellRenderer(componentType, (component, row) => {\n component.value = this.getValue(row);\n });\n return this;\n }\n}\n\nexport class EditorControlColumnModel<Row> extends ColumnModel<Row> {\n\n constructor(columnId: string, saveCommand: UnaryCommand<Form<Row>, boolean>, defaults: ColumnModel.Defaults) {\n super(columnId, defaults);\n this.cellRenderer(EditRowControls);\n }\n\n cellRenderer(componentType: ComponentType<{ row: Row, editSession: EditSession<Row>, editRowCommand: Command<void> }>): this {\n this.setCellRenderer(componentType, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.editSession = editSession;\n component.editRowCommand = editRowCommand;\n });\n return this;\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\nexport class CustomTemplateColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, component: ComponentType<{ editCommand: Command<void>, saveCommand: Command<void>, cancelCommand: Command<void> }>) {\n super(columnId, defaults);\n }\n}\n\nexport class SelectionColumnModel<Row> extends ColumnModel<Row> {\n constructor(columnId: string, defaults: ColumnModel.Defaults, selectionModel: SelectionModel<Row>) {\n super(columnId, defaults);\n if (selectionModel instanceof MultipleSelectionModel) {\n this.cellHeaderRenderer(SelectHeaderCellRendererComponent, (component) => {\n component.selectionModel = selectionModel;\n });\n }\n this.setCellRenderer(SelectCellRendererComponent, (component, row, editRowCommand, editSession) => {\n component.row = row;\n component.selectionModel = selectionModel;\n });\n }\n\n protected getDefaultHeaderText(): string {\n return '';\n }\n}\n\n\n"]}
|
|
@@ -142,7 +142,7 @@ var TableModel = /** @class */ (function () {
|
|
|
142
142
|
this._columnTextPropertiesLookup = columnTextProperties;
|
|
143
143
|
};
|
|
144
144
|
TableModel.prototype.getColumnTextProperties = function (column) {
|
|
145
|
-
var factory = this._columnTextPropertiesLookup[column.columnId];
|
|
145
|
+
var factory = this._columnTextPropertiesLookup ? this._columnTextPropertiesLookup[column.columnId] : undefined;
|
|
146
146
|
return factory ? factory() : undefined;
|
|
147
147
|
};
|
|
148
148
|
TableModel.prototype.startEditSession = function (row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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AAC;CAAA,AApHD,IAoHC;SApHY,UAAU","sourcesContent":["import {\n BooleanValueModelChain,\n CanIdentify,\n Dsl,\n Form,\n GarbageCollector,\n lang,\n ListModel,\n ListModelChain,\n MapModelChain,\n MutableListModel,\n SelectionModel,\n TrackExternal,\n Types,\n UnaryCommand\n} from '@coolon/pectin';\nimport {\n ColumnModel,\n CustomValueColumnModel,\n EditorControlColumnModel,\n PropertyColumnModel,\n SelectionColumnModel\n} from './column-model';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { EditSession } from './edit-session';\n\n// export type StringPropertiesOf<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];\n// export type NumberPropertiesOf<T> = { [K in keyof T]: T[K] extends number ? K : never }[keyof T];\n\n\n/**\n * Example:\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * Editable tables\n * @example\n * const saveCommand = UnaryCommand.create((form: Form<Hero>) => {\n * if (form.validate()) {\n * // normal form save stuff\n * return true; // finish editing\n * }\n * return false; // continue editiing\n * }\n * const colorsNames: ListModel<string> = ...;\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\").cellEditor(StringInputComponent); <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.pluck(\"lastName\").cellEditor(StringInputComponent, {\n * validators: [Validator.present(\"We need a last name\")]\n * });\n * table.pluck(\"age\").cellEditor(NumberInputComponent);\n * table.pluck(\"favoriteColor\").cellEditor(SelectInputComponent, {\n * initialiseComponent(component: SelectInputComponent) {\n * selectInput.optionsModel = colorsNames; // <- initialise our component\n * }\n * });\n * table.addEditControls(saveCommand); // <- required to enable editing\n * });\n *\n * Selection models\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.addSelectionColumn(selectionModel); // <- can be single or multiple selection model\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * });\n *\n * Custom cell renderers and editors\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\")\n * .cellHeaderRenderer(CellHeaderRendererComponent, (component, column) => {\n * // configure your component with what ever you need.\n * });\n * .cellRenderer(CellRendererComponent) // <-- interface CellEditor { value: string; }\n * .cellEditor(CellEditorComponent.); // <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * I18n\n * @example\n * [table.yml]\n * table:\n * columns(ColumnTextProperties[]):\n * firstName:\n * headerText: \"First Name\"\n * fullName:\n * headerText: \"Full Name\"\n *\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\").cellRenderer(...).cellEditor(...);\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n *\n * table.columnTextProperties(I18n.table.columns); // <- configures all columns\n * });\n */\n@TrackExternal.Strategy(new TrackExternal.OneTimeBinding())\nexport class TableModel<Row> {\n\n private readonly _garbage = new GarbageCollector();\n\n private readonly _columns = new MutableListModel<ColumnModel<Row>>();\n private _columnsById: MapModelChain<string, ColumnModel<Row>>;\n private _editorSessions = new MutableListModel<EditSession<Row>>();\n private readonly _rowsBeingEdited: MutableListModel<Row>;\n\n private _columnTextPropertiesLookup: { [columnName: string]: () => ColumnTextProperties };\n\n readonly identityOf: CanIdentify<Row>['identityOf'];\n private saveCommand: UnaryCommand<Form<Row>, boolean>;\n private _editorSessionByRowId: MapModelChain<any, EditSession<Row>>;\n\n readonly editing: BooleanValueModelChain;\n readonly dataSource: ListModelChain<Row>;\n\n static fromList<Row>(sourceOfTruth: ListModel<Row>, builder?: (tableModel: TableModel<Row>) => void): TableModel<Row> {\n const model = new TableModel<Row>(sourceOfTruth);\n builder(model);\n return model;\n }\n\n protected constructor(private sourceOfTruth: ListModel<Row>) {\n this.identityOf = sourceOfTruth.identityOf;\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this._garbage);\n this._columnsById = chain(this._columns).indexBy('columnId');\n this._rowsBeingEdited = new MutableListModel<Row>([], {\n identifiedWith: this.identityOf\n });\n this._editorSessionByRowId = chain(this._editorSessions).indexBy('rowId');\n this.editing = chain(this._editorSessions).count().isGreaterThan(0);\n this.dataSource = chain(this.sourceOfTruth).replaceAll(this.rowsBeingEdited);\n }\n\n get rowsBeingEdited(): ListModel<Row> {\n return this._rowsBeingEdited.readonly;\n }\n\n getTrackByFunction() {\n return (index: number, item: Row) => {\n return this.identityOf ? this.identityOf(item) : index;\n };\n }\n\n get columns(): ListModel<ColumnModel<Row>> {\n return this._columns.readonly;\n }\n\n pluck<P extends Types.ValuePropertiesOf<Row>>(property: P): PropertyColumnModel<Row, P> {\n return this.addColumn(new PropertyColumnModel<Row, P>(property, this));\n }\n\n addSelectionColumn(selectionModel: SelectionModel<Row>): SelectionColumnModel<Row> {\n return this.addColumn(new SelectionColumnModel<Row>('selection', this, selectionModel));\n }\n\n addEditControls(saveCommand: UnaryCommand<Form<Row>, boolean>): EditorControlColumnModel<Row> {\n this.saveCommand = saveCommand;\n return this.addColumn(new EditorControlColumnModel<Row>('editControls', saveCommand, this));\n }\n\n addCustomColumn<V>(columnId: string, dataAccessor: (row: Row) => V): CustomValueColumnModel<Row, V> {\n return this.addColumn(new CustomValueColumnModel<Row, V>(columnId, this, dataAccessor));\n }\n\n protected addColumn<C extends ColumnModel<Row>>(column: C): C {\n if (this._columnsById.get(column.columnId)) {\n lang.illegalState(`Column with id=${column.columnId} already exists`);\n } else {\n this._columns.push(column);\n }\n return column;\n }\n\n columnTextProperties(columnTextProperties: { [columnName: string]: () => ColumnTextProperties }) {\n this._columnTextPropertiesLookup = columnTextProperties;\n }\n\n getColumnTextProperties(column: ColumnModel<Row>): ColumnTextProperties {\n const factory = this._columnTextPropertiesLookup[column.columnId];\n return factory ? factory() : undefined;\n }\n\n startEditSession(row: Row): EditSession<Row> {\n const rowId = this.identityOf(row);\n if (this._rowsBeingEdited.query().indexOf(row) > -1) {\n return lang.illegalState(`Row with id=${rowId} already being edited`);\n } else {\n const editSession = new EditSession<Row>(rowId, row, this.saveCommand);\n const { when } = Dsl.disposeWith(editSession);\n when.valueOf(editSession.rowValueModel).changes((editedValue) => {\n this._rowsBeingEdited.replaceOrPush(editedValue);\n }, { initialValue: 'triggerChangeUnlessNil' });\n\n this._editorSessions.push(editSession);\n editSession.onDispose(() => {\n this._rowsBeingEdited.remove(editSession.rowValueModel.value);\n this._editorSessions.remove(editSession);\n });\n return editSession;\n }\n }\n\n getEditSessionFor(row: Row): EditSession<Row> {\n return this._editorSessionByRowId.get(this.identityOf(row));\n }\n\n cancelAllEditorSessions() {\n this._editorSessions.runInTransaction((draft) => {\n this._rowsBeingEdited.runInTransaction(() => {\n draft.value.forEach(session => session.dispose());\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"table-model.js","sourceRoot":"ng://@coolon/angular-ui-powerups/","sources":["lib/components/table/table-model.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,GAAG,EACH,IAAI,EACJ,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,KAAK,EACL,YAAY,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,oGAAoG;AACpG,oGAAoG;AAGpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAEH;IAwBE,oBAA8B,aAA6B;QAA7B,kBAAa,GAAb,aAAa,CAAgB;QAtB1C,aAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;Q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CAAC;SACpB;IACH,CAAC;IAED,sCAAiB,GAAjB,UAAkB,GAAQ;QACxB,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,4CAAuB,GAAvB;QAAA,iBAMC;QALC,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,UAAC,KAAK;YAC1C,KAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC;gBACrC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,OAAO,EAAE,EAAjB,CAAiB,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;;;gBA3F4C,SAAS;;IAxB3C,UAAU;QADtB,aAAa,CAAC,QAAQ,CAAC,IAAI,aAAa,CAAC,cAAc,EAAE,CAAC;yCAyBZ,SAAS;OAxB3C,UAAU,CAoHtB;IAAD,iBAAC;CAAA,AApHD,IAoHC;SApHY,UAAU","sourcesContent":["import {\n BooleanValueModelChain,\n CanIdentify,\n Dsl,\n Form,\n GarbageCollector,\n lang,\n ListModel,\n ListModelChain,\n MapModelChain,\n MutableListModel,\n SelectionModel,\n TrackExternal,\n Types,\n UnaryCommand\n} from '@coolon/pectin';\nimport {\n ColumnModel,\n CustomValueColumnModel,\n EditorControlColumnModel,\n PropertyColumnModel,\n SelectionColumnModel\n} from './column-model';\nimport { ColumnTextProperties } from './column-text-properties';\nimport { EditSession } from './edit-session';\n\n// export type StringPropertiesOf<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];\n// export type NumberPropertiesOf<T> = { [K in keyof T]: T[K] extends number ? K : never }[keyof T];\n\n\n/**\n * Example:\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * Editable tables\n * @example\n * const saveCommand = UnaryCommand.create((form: Form<Hero>) => {\n * if (form.validate()) {\n * // normal form save stuff\n * return true; // finish editing\n * }\n * return false; // continue editiing\n * }\n * const colorsNames: ListModel<string> = ...;\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"firstName\").cellEditor(StringInputComponent); <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.pluck(\"lastName\").cellEditor(StringInputComponent, {\n * validators: [Validator.present(\"We need a last name\")]\n * });\n * table.pluck(\"age\").cellEditor(NumberInputComponent);\n * table.pluck(\"favoriteColor\").cellEditor(SelectInputComponent, {\n * initialiseComponent(component: SelectInputComponent) {\n * selectInput.optionsModel = colorsNames; // <- initialise our component\n * }\n * });\n * table.addEditControls(saveCommand); // <- required to enable editing\n * });\n *\n * Selection models\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.addSelectionColumn(selectionModel); // <- can be single or multiple selection model\n * table.pluck(\"firstName\");\n * table.pluck(\"lastName\");\n * });\n *\n * Custom cell renderers and editors\n * @example\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\")\n * .cellHeaderRenderer(CellHeaderRendererComponent, (component, column) => {\n * // configure your component with what ever you need.\n * });\n * .cellRenderer(CellRendererComponent) // <-- interface CellEditor { value: string; }\n * .cellEditor(CellEditorComponent.); // <-- interface CellEditor { valueModel: FormValueModel<string> | ValueModel<string>; }\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n * });\n *\n * I18n\n * @example\n * [table.yml]\n * table:\n * columns(ColumnTextProperties[]):\n * firstName:\n * headerText: \"First Name\"\n * fullName:\n * headerText: \"Full Name\"\n *\n * const model = TableModel.fromList(heroList, table => {\n * table.pluck(\"favoriteColor\").cellRenderer(...).cellEditor(...);\n * table.addCustomColumn(\"fullName\", hero => `${hero.firstName} ${hero.lastName}`);\n *\n * table.columnTextProperties(I18n.table.columns); // <- configures all columns\n * });\n */\n@TrackExternal.Strategy(new TrackExternal.OneTimeBinding())\nexport class TableModel<Row> {\n\n private readonly _garbage = new GarbageCollector();\n\n private readonly _columns = new MutableListModel<ColumnModel<Row>>();\n private _columnsById: MapModelChain<string, ColumnModel<Row>>;\n private _editorSessions = new MutableListModel<EditSession<Row>>();\n private readonly _rowsBeingEdited: MutableListModel<Row>;\n\n private _columnTextPropertiesLookup: { [columnName: string]: () => ColumnTextProperties };\n\n readonly identityOf: CanIdentify<Row>['identityOf'];\n private saveCommand: UnaryCommand<Form<Row>, boolean>;\n private _editorSessionByRowId: MapModelChain<any, EditSession<Row>>;\n\n readonly editing: BooleanValueModelChain;\n readonly dataSource: ListModelChain<Row>;\n\n static fromList<Row>(sourceOfTruth: ListModel<Row>, builder?: (tableModel: TableModel<Row>) => void): TableModel<Row> {\n const model = new TableModel<Row>(sourceOfTruth);\n builder(model);\n return model;\n }\n\n protected constructor(private sourceOfTruth: ListModel<Row>) {\n this.identityOf = sourceOfTruth.identityOf;\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this._garbage);\n this._columnsById = chain(this._columns).indexBy('columnId');\n this._rowsBeingEdited = new MutableListModel<Row>([], {\n identifiedWith: this.identityOf\n });\n this._editorSessionByRowId = chain(this._editorSessions).indexBy('rowId');\n this.editing = chain(this._editorSessions).count().isGreaterThan(0);\n this.dataSource = chain(this.sourceOfTruth).replaceAll(this.rowsBeingEdited);\n }\n\n get rowsBeingEdited(): ListModel<Row> {\n return this._rowsBeingEdited.readonly;\n }\n\n getTrackByFunction() {\n return (index: number, item: Row) => {\n return this.identityOf ? this.identityOf(item) : index;\n };\n }\n\n get columns(): ListModel<ColumnModel<Row>> {\n return this._columns.readonly;\n }\n\n pluck<P extends Types.ValuePropertiesOf<Row>>(property: P): PropertyColumnModel<Row, P> {\n return this.addColumn(new PropertyColumnModel<Row, P>(property, this));\n }\n\n addSelectionColumn(selectionModel: SelectionModel<Row>): SelectionColumnModel<Row> {\n return this.addColumn(new SelectionColumnModel<Row>('selection', this, selectionModel));\n }\n\n addEditControls(saveCommand: UnaryCommand<Form<Row>, boolean>): EditorControlColumnModel<Row> {\n this.saveCommand = saveCommand;\n return this.addColumn(new EditorControlColumnModel<Row>('editControls', saveCommand, this));\n }\n\n addCustomColumn<V>(columnId: string, dataAccessor: (row: Row) => V): CustomValueColumnModel<Row, V> {\n return this.addColumn(new CustomValueColumnModel<Row, V>(columnId, this, dataAccessor));\n }\n\n protected addColumn<C extends ColumnModel<Row>>(column: C): C {\n if (this._columnsById.get(column.columnId)) {\n lang.illegalState(`Column with id=${column.columnId} already exists`);\n } else {\n this._columns.push(column);\n }\n return column;\n }\n\n columnTextProperties(columnTextProperties: { [columnName: string]: () => ColumnTextProperties }) {\n this._columnTextPropertiesLookup = columnTextProperties;\n }\n\n getColumnTextProperties(column: ColumnModel<Row>): ColumnTextProperties {\n const factory = this._columnTextPropertiesLookup ? this._columnTextPropertiesLookup[column.columnId] : undefined;\n return factory ? factory() : undefined;\n }\n\n startEditSession(row: Row): EditSession<Row> {\n const rowId = this.identityOf(row);\n if (this._rowsBeingEdited.query().indexOf(row) > -1) {\n return lang.illegalState(`Row with id=${rowId} already being edited`);\n } else {\n const editSession = new EditSession<Row>(rowId, row, this.saveCommand);\n const { when } = Dsl.disposeWith(editSession);\n when.valueOf(editSession.rowValueModel).changes((editedValue) => {\n this._rowsBeingEdited.replaceOrPush(editedValue);\n }, { initialValue: 'triggerChangeUnlessNil' });\n\n this._editorSessions.push(editSession);\n editSession.onDispose(() => {\n this._rowsBeingEdited.remove(editSession.rowValueModel.value);\n this._editorSessions.remove(editSession);\n });\n return editSession;\n }\n }\n\n getEditSessionFor(row: Row): EditSession<Row> {\n return this._editorSessionByRowId.get(this.identityOf(row));\n }\n\n cancelAllEditorSessions() {\n this._editorSessions.runInTransaction((draft) => {\n this._rowsBeingEdited.runInTransaction(() => {\n draft.value.forEach(session => session.dispose());\n });\n });\n }\n}\n"]}
|
|
@@ -2310,6 +2310,7 @@ class ColumnModel {
|
|
|
2310
2310
|
portal: new ComponentPortal(cellRenderer),
|
|
2311
2311
|
initialiseComponent: initialiser
|
|
2312
2312
|
};
|
|
2313
|
+
return this;
|
|
2313
2314
|
}
|
|
2314
2315
|
setCellEditor(cellEditor) {
|
|
2315
2316
|
this._cellEditorConfig = cellEditor;
|
|
@@ -2353,12 +2354,14 @@ class PropertyColumnModel extends ColumnModel {
|
|
|
2353
2354
|
constructor(property, defaults) {
|
|
2354
2355
|
super(property.toString(), defaults);
|
|
2355
2356
|
this.property = property;
|
|
2357
|
+
this._format = (value) => value;
|
|
2356
2358
|
this.cellRenderer(DefaultCellRendererComponent);
|
|
2357
2359
|
}
|
|
2358
2360
|
cellRenderer(componentType) {
|
|
2359
2361
|
this.setCellRenderer(componentType, (component, row) => {
|
|
2360
|
-
component.value = row[this.property];
|
|
2362
|
+
component.value = this._format(row[this.property]);
|
|
2361
2363
|
});
|
|
2364
|
+
return this;
|
|
2362
2365
|
}
|
|
2363
2366
|
cellEditor(editor, options) {
|
|
2364
2367
|
this.setCellEditor({
|
|
@@ -2376,6 +2379,11 @@ class PropertyColumnModel extends ColumnModel {
|
|
|
2376
2379
|
});
|
|
2377
2380
|
return this;
|
|
2378
2381
|
}
|
|
2382
|
+
format(formatter) {
|
|
2383
|
+
assert$1.isFunction(formatter);
|
|
2384
|
+
this._format = formatter;
|
|
2385
|
+
return this;
|
|
2386
|
+
}
|
|
2379
2387
|
}
|
|
2380
2388
|
class CustomValueColumnModel extends ColumnModel {
|
|
2381
2389
|
constructor(columnId, defaults, getValue) {
|
|
@@ -2387,6 +2395,7 @@ class CustomValueColumnModel extends ColumnModel {
|
|
|
2387
2395
|
this.setCellRenderer(componentType, (component, row) => {
|
|
2388
2396
|
component.value = this.getValue(row);
|
|
2389
2397
|
});
|
|
2398
|
+
return this;
|
|
2390
2399
|
}
|
|
2391
2400
|
}
|
|
2392
2401
|
class EditorControlColumnModel extends ColumnModel {
|
|
@@ -2400,6 +2409,7 @@ class EditorControlColumnModel extends ColumnModel {
|
|
|
2400
2409
|
component.editSession = editSession;
|
|
2401
2410
|
component.editRowCommand = editRowCommand;
|
|
2402
2411
|
});
|
|
2412
|
+
return this;
|
|
2403
2413
|
}
|
|
2404
2414
|
getDefaultHeaderText() {
|
|
2405
2415
|
return '';
|
|
@@ -2559,7 +2569,7 @@ let TableModel = TableModel_1 = class TableModel {
|
|
|
2559
2569
|
this._columnTextPropertiesLookup = columnTextProperties;
|
|
2560
2570
|
}
|
|
2561
2571
|
getColumnTextProperties(column) {
|
|
2562
|
-
const factory = this._columnTextPropertiesLookup[column.columnId];
|
|
2572
|
+
const factory = this._columnTextPropertiesLookup ? this._columnTextPropertiesLookup[column.columnId] : undefined;
|
|
2563
2573
|
return factory ? factory() : undefined;
|
|
2564
2574
|
}
|
|
2565
2575
|
startEditSession(row) {
|