Skip to content

Commit 7ad7bed

Browse files
committed
Tried to make types/editors registration more easier
1 parent ad316b8 commit 7ad7bed

File tree

22 files changed

+50
-26
lines changed

22 files changed

+50
-26
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ import "./editor.scss";
55

66
export class Editor extends Base {
77
public static inputTypes = {
8-
number: "number",
9-
currency: "number",
10-
indicator: "number",
11-
progress: "number",
12-
date: "date",
13-
datetime: "datetime-local",
148
};
15-
public static getInputType(type: string) {
16-
return Editor.inputTypes[type];
9+
public static setInputType(typeName: string, inputType: string) {
10+
return Editor.inputTypes[typeName] = inputType;
11+
}
12+
public static getInputType(typeName: string) {
13+
return Editor.inputTypes[typeName];
1714
}
1815
public static editors = {
1916
default: "table4js-default-editor",
20-
bool: "table4js-checkbox-editor",
2117
};
22-
18+
public static setComponent(typeName: string, componentName: string) {
19+
return Editor.editors[typeName] = componentName;
20+
}
21+
public static getComponent(typeName: string) {
22+
return Editor.editors[typeName] || Editor.editors.default;
23+
}
24+
2325
constructor(private _data: any, private name: string) {
2426
super();
2527
this.value = _data[this.name];

sources/core/field-types/bool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { IFieldType } from "../domain";
22
import { Localization } from "../../localization";
3+
import { Editor } from "../editor";
4+
35

46
export class BoolField implements IFieldType {
57
name: string = "bool";
@@ -12,6 +14,8 @@ export class BoolField implements IFieldType {
1214
}
1315
}
1416

17+
Editor.setComponent("bool", "table4js-checkbox-editor");
18+
1519
// export const boolConverter = {
1620
// from: (val: any): boolean => val === true || val === "t" || val === "true",
1721
// to: (val: boolean): any => val === true ? true : false

sources/core/field-types/currency.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Editor } from "../editor";
12
import { IFieldType } from "../domain";
23

34
export class CurrencyField implements IFieldType {
@@ -18,3 +19,5 @@ export class CurrencyField implements IFieldType {
1819
return result;
1920
}
2021
}
22+
23+
Editor.setInputType("currency", "number");

sources/core/field-types/date.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IFieldType } from "../domain";
22
import { Localization } from "../../localization";
3+
import { Editor } from "../editor";
34

45
export class DateField implements IFieldType {
56
name: string = "date";
@@ -13,3 +14,5 @@ export class DateField implements IFieldType {
1314
return result;
1415
}
1516
}
17+
18+
Editor.setInputType("date", "date");

sources/core/field-types/datetime.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IFieldType } from "../domain";
22
import { Localization } from "../../localization";
3+
import { Editor } from "../editor";
34

45
export class DateTimeField implements IFieldType {
56
name: string = "datetime";
@@ -13,3 +14,5 @@ export class DateTimeField implements IFieldType {
1314
return result;
1415
}
1516
}
17+
18+
Editor.setInputType("datetime", "datetime-local");

sources/core/field-types/number.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { Editor } from "../editor";
12
import { IFieldType } from "../domain";
23

34
export class NumberField implements IFieldType {
45
name: string = "number";
56
css: string = "table4js-cell--right"
67
}
8+
9+
Editor.setInputType("number", "number");

sources/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from "./core/field-types/date";
88
export * from "./core/field-types/datetime";
99
export * from "./core/field-types/number";
1010
export * from "./core/find";
11+
export * from "./core/editor";
1112

1213
export * from "./table";
1314
export * from "./table/row";
@@ -28,7 +29,6 @@ export * from "./table/cell-types/indicator";
2829
export * from "./table/cell-types/number";
2930
export * from "./table/cell-types/progress";
3031

31-
export * from "./widgets/editor";
3232
export * from "./widgets/property";
3333
export * from "./widgets/form";
3434

sources/knockout/table/cell-editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ko from "knockout";
22
import { TableCell } from "../../table/cell";
3-
import { Editor } from "../../widgets/editor";
3+
import { Editor } from "../../core/editor";
44

55
export var cellEditorTemplate = require("./cell-editor.html").default;
66

@@ -13,7 +13,7 @@ ko.components.register("table4js-cell-editor", {
1313
...params,
1414
editor,
1515
inputType: Editor.getInputType(params.cell.type),
16-
component: Editor.editors[params.cell.type] || Editor.editors.default,
16+
component: Editor.getComponent(params.cell.type),
1717
containerCss: ko.computed(() => TableCell.getContainerCss(params.cell, isMergedCell())),
1818
contentCss: ko.computed(() => TableCell.getContentCss(params.cell, isMergedCell())),
1919
isMergedCell

sources/knockout/table/row-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ko from "knockout";
22
import { TableCell } from "../../table/cell";
3-
import { Editor } from "../../widgets/editor";
3+
import { Editor } from "../../core/editor";
44

55
export var rowEditorTemplate = require("./row-editor.html").default;
66

0 commit comments

Comments
 (0)