@omegagrid/form 0.10.2 → 0.10.5
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/dist/constants.d.ts +52 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/model/formAdapter.d.ts +14 -0
- package/dist/model/formAdapter.d.ts.map +1 -0
- package/dist/model/formAdapter.js +21 -0
- package/dist/model/formAdapter.js.map +1 -0
- package/dist/model/formControlModel.d.ts +9 -0
- package/dist/model/formControlModel.d.ts.map +1 -0
- package/dist/model/formControlModel.js +9 -0
- package/dist/model/formControlModel.js.map +1 -0
- package/dist/model/formModel.d.ts +17 -0
- package/dist/model/formModel.d.ts.map +1 -0
- package/dist/model/formModel.js +42 -0
- package/dist/model/formModel.js.map +1 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +4 -0
- package/dist/model/index.js.map +1 -0
- package/dist/options.d.ts +3 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +17 -0
- package/dist/options.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/controls/baseControl.d.ts +32 -0
- package/dist/ui/controls/baseControl.d.ts.map +1 -0
- package/dist/ui/controls/baseControl.js +97 -0
- package/dist/ui/controls/baseControl.js.map +1 -0
- package/dist/ui/controls/button.d.ts +16 -0
- package/dist/ui/controls/button.d.ts.map +1 -0
- package/dist/ui/controls/button.js +80 -0
- package/dist/ui/controls/button.js.map +1 -0
- package/dist/ui/controls/calendarDateInput.d.ts +11 -0
- package/dist/ui/controls/calendarDateInput.d.ts.map +1 -0
- package/dist/ui/controls/calendarDateInput.js +67 -0
- package/dist/ui/controls/calendarDateInput.js.map +1 -0
- package/dist/ui/controls/checkbox.d.ts +8 -0
- package/dist/ui/controls/checkbox.d.ts.map +1 -0
- package/dist/ui/controls/checkbox.js +38 -0
- package/dist/ui/controls/checkbox.js.map +1 -0
- package/dist/ui/controls/colorInput.d.ts +9 -0
- package/dist/ui/controls/colorInput.d.ts.map +1 -0
- package/dist/ui/controls/colorInput.js +48 -0
- package/dist/ui/controls/colorInput.js.map +1 -0
- package/dist/ui/controls/dateInput.d.ts +11 -0
- package/dist/ui/controls/dateInput.d.ts.map +1 -0
- package/dist/ui/controls/dateInput.js +80 -0
- package/dist/ui/controls/dateInput.js.map +1 -0
- package/dist/ui/controls/fileInput.d.ts +6 -0
- package/dist/ui/controls/fileInput.d.ts.map +1 -0
- package/dist/ui/controls/fileInput.js +28 -0
- package/dist/ui/controls/fileInput.js.map +1 -0
- package/dist/ui/controls/index.d.ts +11 -0
- package/dist/ui/controls/index.d.ts.map +1 -0
- package/dist/ui/controls/index.js +11 -0
- package/dist/ui/controls/index.js.map +1 -0
- package/dist/ui/controls/label.d.ts +6 -0
- package/dist/ui/controls/label.d.ts.map +1 -0
- package/dist/ui/controls/label.js +53 -0
- package/dist/ui/controls/label.js.map +1 -0
- package/dist/ui/controls/list.d.ts +17 -0
- package/dist/ui/controls/list.d.ts.map +1 -0
- package/dist/ui/controls/list.js +83 -0
- package/dist/ui/controls/list.js.map +1 -0
- package/dist/ui/controls/numericInput.d.ts +14 -0
- package/dist/ui/controls/numericInput.d.ts.map +1 -0
- package/dist/ui/controls/numericInput.js +81 -0
- package/dist/ui/controls/numericInput.js.map +1 -0
- package/dist/ui/controls/textInput.d.ts +11 -0
- package/dist/ui/controls/textInput.d.ts.map +1 -0
- package/dist/ui/controls/textInput.js +67 -0
- package/dist/ui/controls/textInput.js.map +1 -0
- package/dist/ui/form.d.ts +38 -0
- package/dist/ui/form.d.ts.map +1 -0
- package/dist/ui/form.js +201 -0
- package/dist/ui/form.js.map +1 -0
- package/dist/ui/form.style.d.ts +2 -0
- package/dist/ui/form.style.d.ts.map +1 -0
- package/dist/ui/form.style.js +45 -0
- package/dist/ui/form.style.js.map +1 -0
- package/dist/ui/formContainer.d.ts +31 -0
- package/dist/ui/formContainer.d.ts.map +1 -0
- package/dist/ui/formContainer.js +197 -0
- package/dist/ui/formContainer.js.map +1 -0
- package/dist/ui/formContainer.style.d.ts +2 -0
- package/dist/ui/formContainer.style.d.ts.map +1 -0
- package/dist/ui/formContainer.style.js +39 -0
- package/dist/ui/formContainer.style.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FormButtonConfig, FormButtonType } from './types';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
PREFIX: string;
|
|
4
|
+
DEFAULT_ACCENT_COLOR: string;
|
|
5
|
+
DEFAULT_ACCENT_COLOR_2: import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | any | ArrayLike<number> | {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}> | ArrayLike<number> | {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}> | ArrayLike<number> | {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}> | ArrayLike<number> | {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}> | ArrayLike<number> | {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}> | ArrayLike<number> | {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}> | ArrayLike<number> | {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}> | ArrayLike<number> | {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}> | ArrayLike<number> | {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}> | ArrayLike<number> | {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}> | ArrayLike<number> | {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}> | ArrayLike<number> | {
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}>;
|
|
30
|
+
SIZER_SIZE: number;
|
|
31
|
+
SLIDER_SIZE: number;
|
|
32
|
+
SLIDER_MIN_LENGTH: number;
|
|
33
|
+
EXPANDER_SIZE: number;
|
|
34
|
+
LIST_ITEM_HEIGHT: number;
|
|
35
|
+
LIST_RENDERING_TRESHOLD: number;
|
|
36
|
+
LIST_AUTOSCROLL_TRESHOLD: number;
|
|
37
|
+
LIST_AUTOSCROLL_DELAY: number;
|
|
38
|
+
DEFAULT_TEXT_HIGHLIGHT_COLOR: string;
|
|
39
|
+
TOOLTIP_MARGIN: number;
|
|
40
|
+
MENU_ITEM_HEIGHT: number;
|
|
41
|
+
COLORPICKER_COLOR_SIZE: number;
|
|
42
|
+
DEFAULT_NUMBER_FORMAT: string;
|
|
43
|
+
BUTTON_HEIGHT: number;
|
|
44
|
+
FONT_SIZE: number;
|
|
45
|
+
FLOATING_WINDOW_MAX_WIDTH: number;
|
|
46
|
+
DEFAULT_FORM_CELL_PADDING: number;
|
|
47
|
+
DEFAULT_FORM_ROW_HEIGHT: number;
|
|
48
|
+
DEFAULT_FORM_LINE_HEIGHT: number;
|
|
49
|
+
BUTTON_CONFIG: Map<FormButtonType, FormButtonConfig>;
|
|
50
|
+
};
|
|
51
|
+
export default _default;
|
|
52
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,wBAYC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { constants as coreConstants, ColorTypes } from '@omegagrid/core';
|
|
2
|
+
export default {
|
|
3
|
+
DEFAULT_FORM_CELL_PADDING: 2,
|
|
4
|
+
DEFAULT_FORM_ROW_HEIGHT: 24,
|
|
5
|
+
DEFAULT_FORM_LINE_HEIGHT: 22,
|
|
6
|
+
BUTTON_CONFIG: new Map([
|
|
7
|
+
['save', { text: 'Save', color: ColorTypes.Accent, default: true }],
|
|
8
|
+
['reset', { text: 'Reset', color: ColorTypes.Gray }],
|
|
9
|
+
['validate', { text: 'Validate', color: ColorTypes.Gray }],
|
|
10
|
+
['storno', { text: 'Storno', color: ColorTypes.Gray }],
|
|
11
|
+
['close', { text: 'Close', color: ColorTypes.Gray }]
|
|
12
|
+
]),
|
|
13
|
+
...coreConstants
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGzE,eAAe;IACd,yBAAyB,EAAE,CAAC;IAC5B,uBAAuB,EAAE,EAAE;IAC3B,wBAAwB,EAAE,EAAE;IAC5B,aAAa,EAAE,IAAI,GAAG,CAAmC;QACxD,CAAC,MAAM,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;QACjE,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAC,CAAC;QAClD,CAAC,UAAU,EAAE,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAC,CAAC;QACxD,CAAC,QAAQ,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAC,CAAC;QACpD,CAAC,OAAO,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAC,CAAC;KAClD,CAAC;IACF,GAAG,aAAa;CAChB,CAAA","sourcesContent":["import { constants as coreConstants, ColorTypes } from '@omegagrid/core';\nimport { FormButtonConfig, FormButtonType } from './types';\n\nexport default {\n\tDEFAULT_FORM_CELL_PADDING: 2,\n\tDEFAULT_FORM_ROW_HEIGHT: 24,\n\tDEFAULT_FORM_LINE_HEIGHT: 22,\n\tBUTTON_CONFIG: new Map<FormButtonType, FormButtonConfig>([\n\t\t['save', {text: 'Save', color: ColorTypes.Accent, default: true}],\n\t\t['reset', {text: 'Reset', color: ColorTypes.Gray}],\n\t\t['validate', {text: 'Validate', color: ColorTypes.Gray}],\n\t\t['storno', {text: 'Storno', color: ColorTypes.Gray}],\n\t\t['close', {text: 'Close', color: ColorTypes.Gray}]\n\t]),\n\t...coreConstants\n}"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC","sourcesContent":["export * from './ui';\nexport * from './types';\nexport * from './model';"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentAdapter } from '@omegagrid/core';
|
|
2
|
+
import { Form } from '../ui';
|
|
3
|
+
import { FormSettings, FormColumn, FormControlProperties, FormRow, FormValues, FormAlert } from '../types';
|
|
4
|
+
import { FormContainerOptions } from '../types';
|
|
5
|
+
export declare abstract class FormAdapter extends ComponentAdapter<Form> {
|
|
6
|
+
getForms(): FormSettings[] | Promise<FormSettings[]>;
|
|
7
|
+
getRows(id: string | number): FormRow[] | Promise<FormRow[]>;
|
|
8
|
+
getColumns(id: string | number): FormColumn[] | Promise<FormColumn[]>;
|
|
9
|
+
abstract getControls(id: string | number): FormControlProperties[] | Promise<FormControlProperties[]>;
|
|
10
|
+
save(values: Map<string | number, FormValues>): boolean | FormAlert[] | Promise<boolean | FormAlert[]>;
|
|
11
|
+
getOptions(): FormContainerOptions | Promise<FormContainerOptions>;
|
|
12
|
+
onAction(action: string): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=formAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formAdapter.d.ts","sourceRoot":"","sources":["../../src/model/formAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,8BAAsB,WAAY,SAAQ,gBAAgB,CAAC,IAAI,CAAC;IAE/D,QAAQ,IAAI,YAAY,EAAE,GAAC,OAAO,CAAC,YAAY,EAAE,CAAC;IAIlD,OAAO,CAAC,EAAE,EAAE,MAAM,GAAC,MAAM,GAAG,OAAO,EAAE,GAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAIxD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAC,MAAM,GAAG,UAAU,EAAE,GAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAIjE,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAC,MAAM,GAAG,qBAAqB,EAAE,GAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAEjG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAC,MAAM,EAAE,UAAU,CAAC,GAAG,OAAO,GAAC,SAAS,EAAE,GAAC,OAAO,CAAC,OAAO,GAAC,SAAS,EAAE,CAAC;IAI9F,UAAU,IAAI,oBAAoB,GAAC,OAAO,CAAC,oBAAoB,CAAC;IAIhE,QAAQ,CAAC,MAAM,EAAE,MAAM;CAEvB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { ComponentAdapter } from '@omegagrid/core';
|
|
3
|
+
export class FormAdapter extends ComponentAdapter {
|
|
4
|
+
getForms() {
|
|
5
|
+
return [{ key: 0 }];
|
|
6
|
+
}
|
|
7
|
+
getRows(id) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
getColumns(id) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
save(values) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
getOptions() {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
onAction(action) { }
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=formAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formAdapter.js","sourceRoot":"","sources":["../../src/model/formAdapter.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnD,MAAM,OAAgB,WAAY,SAAQ,gBAAsB;IAE/D,QAAQ;QACP,OAAO,CAAC,EAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,EAAiB;QACxB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,UAAU,CAAC,EAAiB;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAID,IAAI,CAAC,MAAsC;QAC1C,OAAO,IAAI,CAAC;IACb,CAAC;IAED,UAAU;QACT,OAAO,EAAE,CAAC;IACX,CAAC;IAED,QAAQ,CAAC,MAAc,IAAI,CAAC;CAE5B","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport { ComponentAdapter } from '@omegagrid/core';\nimport { Form } from '../ui';\nimport { FormSettings, FormColumn, FormControlProperties, FormRow, FormValues, FormAlert } from '../types';\nimport { FormContainerOptions } from '../types';\n\nexport abstract class FormAdapter extends ComponentAdapter<Form> {\n\n\tgetForms(): FormSettings[]|Promise<FormSettings[]> {\n\t\treturn [{key: 0}];\n\t}\n\n\tgetRows(id: string|number): FormRow[]|Promise<FormRow[]> {\n\t\treturn [];\n\t}\n\n\tgetColumns(id: string|number): FormColumn[]|Promise<FormColumn[]> {\n\t\treturn [];\n\t}\n\n\tabstract getControls(id: string|number): FormControlProperties[]|Promise<FormControlProperties[]>;\n\n\tsave(values: Map<string|number, FormValues>): boolean|FormAlert[]|Promise<boolean|FormAlert[]> {\n\t\treturn true;\n\t}\n\n\tgetOptions(): FormContainerOptions|Promise<FormContainerOptions> {\n\t\treturn {};\n\t}\n\n\tonAction(action: string) { }\n\n}"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormControlProperties } from "../types";
|
|
2
|
+
export declare class FormControlModel {
|
|
3
|
+
readonly props: FormControlProperties;
|
|
4
|
+
readonly dependencies: FormControlModel[];
|
|
5
|
+
errors: string[];
|
|
6
|
+
constructor(props: FormControlProperties);
|
|
7
|
+
get key(): string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=formControlModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formControlModel.d.ts","sourceRoot":"","sources":["../../src/model/formControlModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,qBAAa,gBAAgB;aAMA,KAAK,EAAE,qBAAqB;IAJxD,SAAgB,YAAY,EAAE,gBAAgB,EAAE,CAAM;IAE/C,MAAM,EAAE,MAAM,EAAE,CAAM;gBAED,KAAK,EAAE,qBAAqB;IAExD,IAAI,GAAG,WAA4B;CAEnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formControlModel.js","sourceRoot":"","sources":["../../src/model/formControlModel.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,gBAAgB;IAM5B,YAA4B,KAA4B;QAA5B,UAAK,GAAL,KAAK,CAAuB;QAJxC,iBAAY,GAAuB,EAAE,CAAC;QAE/C,WAAM,GAAa,EAAE,CAAC;IAE+B,CAAC;IAE7D,IAAI,GAAG,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAA,CAAC,CAAC;CAEnC","sourcesContent":["import { FormControlProperties } from \"../types\";\n\nexport class FormControlModel {\n\n\tpublic readonly dependencies: FormControlModel[] = [];\n\n\tpublic errors: string[] = [];\n\n\tconstructor(public readonly props: FormControlProperties) { }\n\n\tget key() { return this.props.key }\n\n}"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormColumn, FormOptions, FormRow, FormSettings } from "../types";
|
|
2
|
+
import { FormControlModel } from "./formControlModel";
|
|
3
|
+
export declare class FormModel {
|
|
4
|
+
options: FormOptions;
|
|
5
|
+
controls: FormControlModel[][];
|
|
6
|
+
rows: FormRow[];
|
|
7
|
+
columns: FormColumn[];
|
|
8
|
+
private _rowCount;
|
|
9
|
+
private _colCount;
|
|
10
|
+
get rowCount(): number;
|
|
11
|
+
get colCount(): number;
|
|
12
|
+
readonly controlMap: Map<string, FormControlModel>;
|
|
13
|
+
get(key: string): FormControlModel;
|
|
14
|
+
constructor(sourceData: FormSettings);
|
|
15
|
+
populate(sourceData: FormSettings): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=formModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formModel.d.ts","sourceRoot":"","sources":["../../src/model/formModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,qBAAa,SAAS;IAErB,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,gBAAgB,EAAE,EAAE,CAAC;IAC/B,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,OAAO,EAAE,UAAU,EAAE,CAAC;IAEtB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,SAAS,CAAK;IAEtB,IAAI,QAAQ,WAA4B;IACxC,IAAI,QAAQ,WAA4B;IAExC,SAAgB,UAAU,gCAAuC;IAEjE,GAAG,CAAC,GAAG,EAAE,MAAM;gBAEH,UAAU,EAAE,YAAY;IAIpC,QAAQ,CAAC,UAAU,EAAE,YAAY;CA+BjC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FormControlModel } from "./formControlModel";
|
|
2
|
+
export class FormModel {
|
|
3
|
+
get rowCount() { return this._rowCount; }
|
|
4
|
+
get colCount() { return this._colCount; }
|
|
5
|
+
get(key) { return this.controlMap.get(key); }
|
|
6
|
+
constructor(sourceData) {
|
|
7
|
+
this._rowCount = 0;
|
|
8
|
+
this._colCount = 0;
|
|
9
|
+
this.controlMap = new Map();
|
|
10
|
+
this.populate(sourceData);
|
|
11
|
+
}
|
|
12
|
+
populate(sourceData) {
|
|
13
|
+
this.options = sourceData.options ?? {};
|
|
14
|
+
this.controlMap.clear();
|
|
15
|
+
this.controls = [];
|
|
16
|
+
this.rows = sourceData.rows || [];
|
|
17
|
+
this.columns = sourceData.columns || [];
|
|
18
|
+
this._rowCount = this.rows.length;
|
|
19
|
+
this._colCount = this.columns.length;
|
|
20
|
+
sourceData.controls.forEach(c => {
|
|
21
|
+
this._rowCount = Math.max(this._rowCount, c.row + 1);
|
|
22
|
+
this._colCount = Math.max(this._colCount, c.col + 1);
|
|
23
|
+
if (this._rowCount > this.rows.length)
|
|
24
|
+
this.rows.push({});
|
|
25
|
+
if (this._colCount > this.columns.length)
|
|
26
|
+
this.columns.push({});
|
|
27
|
+
c.key = c.key ?? ((c.row * this._colCount) + c.col).toString();
|
|
28
|
+
this.controlMap.set(c.key, new FormControlModel(c));
|
|
29
|
+
});
|
|
30
|
+
this.controls = [...Array(this.rowCount)].map(() => Array(this.colCount));
|
|
31
|
+
this.controlMap.forEach(c => {
|
|
32
|
+
this.controls[c.props.row][c.props.col] = c;
|
|
33
|
+
if (c.props.dependsOn) {
|
|
34
|
+
this.controlMap.get(c.props.dependsOn).dependencies.push(c);
|
|
35
|
+
}
|
|
36
|
+
if (c.props.for && this.controlMap.get(c.props.for)?.props.required) {
|
|
37
|
+
c.props.required = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=formModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formModel.js","sourceRoot":"","sources":["../../src/model/formModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,OAAO,SAAS;IAUrB,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAA,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAA,CAAC,CAAC;IAIxC,GAAG,CAAC,GAAW,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC;IAEpD,YAAY,UAAwB;QAV5B,cAAS,GAAG,CAAC,CAAC;QACd,cAAS,GAAG,CAAC,CAAC;QAKN,eAAU,GAAG,IAAI,GAAG,EAA4B,CAAC;QAKhE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC3B,CA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AC,GAAG,EAAE,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YAC3B,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC3C,IAAI,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBACvB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC7D,CAAC;YAED,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACrE,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;YACzB,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CAED","sourcesContent":["import { FormColumn, FormOptions, FormRow, FormSettings } from \"../types\";\nimport { FormControlModel } from \"./formControlModel\";\n\nexport class FormModel {\n\n\toptions: FormOptions;\n\tcontrols: FormControlModel[][];\n\trows: FormRow[];\n\tcolumns: FormColumn[];\n\n\tprivate _rowCount = 0;\n\tprivate _colCount = 0;\n\n\tget rowCount() { return this._rowCount }\n\tget colCount() { return this._colCount }\n\n\tpublic readonly controlMap = new Map<string, FormControlModel>();\n\n\tget(key: string) { return this.controlMap.get(key) }\n\n\tconstructor(sourceData: FormSettings) {\n\t\tthis.populate(sourceData);\n\t}\n\n\tpopulate(sourceData: FormSettings) {\n\t\tthis.options = sourceData.options ?? {};\n\t\tthis.controlMap.clear();\n\t\tthis.controls = [];\n\t\tthis.rows = sourceData.rows || [];\n\t\tthis.columns = sourceData.columns || [];\n\t\tthis._rowCount = this.rows.length;\n\t\tthis._colCount = this.columns.length;\n\n\t\tsourceData.controls.forEach(c => {\n\t\t\tthis._rowCount = Math.max(this._rowCount, c.row + 1);\n\t\t\tthis._colCount = Math.max(this._colCount, c.col + 1);\n\t\t\tif (this._rowCount > this.rows.length) this.rows.push({});\n\t\t\tif (this._colCount > this.columns.length) this.columns.push({});\n\t\t\tc.key = c.key ?? ((c.row * this._colCount) + c.col).toString();\n\t\t\tthis.controlMap.set(c.key, new FormControlModel(c));\n\t\t});\n\n\t\tthis.controls = [...Array(this.rowCount)].map(() => Array(this.colCount));\n\t\tthis.controlMap.forEach(c => {\n\t\t\tthis.controls[c.props.row][c.props.col] = c\n\t\t\tif (c.props.dependsOn) {\n\t\t\t\tthis.controlMap.get(c.props.dependsOn).dependencies.push(c);\n\t\t\t}\n\n\t\t\tif (c.props.for && this.controlMap.get(c.props.for)?.props.required) {\n\t\t\t\tc.props.required = true;\n\t\t\t}\n\t\t});\n\t}\n\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './formAdapter';\nexport * from './formModel';\nexport * from './formControlModel';"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAU/C,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,WAAW,GAAE,oBAA2B,GAAG,oBAAoB,CAOnI"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { initCommonOptions } from "@omegagrid/core";
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
caption: null,
|
|
4
|
+
buttonsPosition: 'bottom',
|
|
5
|
+
alertsPosition: 'bottom',
|
|
6
|
+
buttons: [],
|
|
7
|
+
closeAfterSave: true
|
|
8
|
+
};
|
|
9
|
+
export function initOptions(options, origOptions = null) {
|
|
10
|
+
return {
|
|
11
|
+
...initCommonOptions(options, origOptions),
|
|
12
|
+
...DEFAULT_OPTIONS,
|
|
13
|
+
...origOptions,
|
|
14
|
+
...options,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,eAAe,GAAkC;IACtD,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,QAAQ;IACzB,cAAc,EAAE,QAAQ;IACxB,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,OAAuC,EAAE,cAAoC,IAAI;IAC5G,OAAO;QACN,GAAG,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC;QAC1C,GAAG,eAAe;QAClB,GAAG,WAAW;QACd,GAAG,OAAO;KACV,CAAC;AACH,CAAC","sourcesContent":["import { initCommonOptions } from \"@omegagrid/core\";\nimport { FormContainerOptions } from './types';\n\nconst DEFAULT_OPTIONS: Partial<FormContainerOptions> = {\n\tcaption: null,\n\tbuttonsPosition: 'bottom',\n\talertsPosition: 'bottom',\n\tbuttons: [],\n\tcloseAfterSave: true\n};\n\nexport function initOptions(options?: Partial<FormContainerOptions>, origOptions: FormContainerOptions = null): FormContainerOptions {\n\treturn {\n\t\t...initCommonOptions(options, origOptions),\n\t\t...DEFAULT_OPTIONS,\n\t\t...origOptions,\n\t\t...options,\n\t};\n}"]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ComponentAdapter, CommonOptions, ColorTypes, AlertType, VerticalPosition, IconSpec } from "@omegagrid/core";
|
|
2
|
+
import { TreeAdapter } from "@omegagrid/tree";
|
|
3
|
+
export declare enum FormControlType {
|
|
4
|
+
TextInput = "text",
|
|
5
|
+
Button = "button",
|
|
6
|
+
NumericInput = "number",
|
|
7
|
+
DateInput = "date",
|
|
8
|
+
CalendarDateInput = "calendar",
|
|
9
|
+
Checkbox = "checkbox",
|
|
10
|
+
Label = "label",
|
|
11
|
+
List = "list",
|
|
12
|
+
ColorInput = "color",
|
|
13
|
+
FileInput = "file"
|
|
14
|
+
}
|
|
15
|
+
export type ValidationResult = {
|
|
16
|
+
valid: boolean;
|
|
17
|
+
message?: string;
|
|
18
|
+
};
|
|
19
|
+
export type FormControlProperties = {
|
|
20
|
+
/** Row index within form grid */
|
|
21
|
+
row: number;
|
|
22
|
+
/** Column index within form grid */
|
|
23
|
+
col: number;
|
|
24
|
+
/** Unique field identifier */
|
|
25
|
+
key?: string;
|
|
26
|
+
/** Key of bound form control */
|
|
27
|
+
for?: string;
|
|
28
|
+
/** Value validation pattern */
|
|
29
|
+
pattern?: RegExp;
|
|
30
|
+
/** Form control type */
|
|
31
|
+
type?: FormControlType;
|
|
32
|
+
/** Required field */
|
|
33
|
+
required?: boolean;
|
|
34
|
+
/** Readonly control */
|
|
35
|
+
readOnly?: boolean;
|
|
36
|
+
/** Current control value */
|
|
37
|
+
value?: unknown;
|
|
38
|
+
/** Key of parent element */
|
|
39
|
+
dependsOn?: string;
|
|
40
|
+
/** Component adapter where applicable (eg. TreeSelect) */
|
|
41
|
+
adapter?: ComponentAdapter;
|
|
42
|
+
/** Component item definition */
|
|
43
|
+
content?: unknown;
|
|
44
|
+
/** colspan */
|
|
45
|
+
cs?: number;
|
|
46
|
+
/** rowspan */
|
|
47
|
+
rs?: number;
|
|
48
|
+
/** control-specific options */
|
|
49
|
+
options?: Record<string, unknown>;
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
caption?: string;
|
|
52
|
+
/** validation callback */
|
|
53
|
+
validate?: (value: unknown, props: FormControlProperties) => ValidationResult | boolean | Promise<ValidationResult | boolean>;
|
|
54
|
+
};
|
|
55
|
+
export type FormAlert = {
|
|
56
|
+
text: string;
|
|
57
|
+
type: AlertType;
|
|
58
|
+
};
|
|
59
|
+
export type FormRow = {
|
|
60
|
+
height?: number;
|
|
61
|
+
};
|
|
62
|
+
export type FormColumn = {
|
|
63
|
+
width?: number;
|
|
64
|
+
};
|
|
65
|
+
export type FormGridModel = {
|
|
66
|
+
rows: FormRow[];
|
|
67
|
+
columns: FormColumn[];
|
|
68
|
+
};
|
|
69
|
+
export type FormOptions = {
|
|
70
|
+
treeAdapter?: TreeAdapter;
|
|
71
|
+
};
|
|
72
|
+
export type FormContainerOptions = {
|
|
73
|
+
caption?: string;
|
|
74
|
+
buttonsPosition?: VerticalPosition;
|
|
75
|
+
alertsPosition?: VerticalPosition;
|
|
76
|
+
buttons?: FormButtonType[];
|
|
77
|
+
formOptions?: FormOptions;
|
|
78
|
+
closeAfterSave?: boolean;
|
|
79
|
+
} & CommonOptions;
|
|
80
|
+
export type FormSettings = {
|
|
81
|
+
key?: string | number;
|
|
82
|
+
caption?: string;
|
|
83
|
+
treeAdapter?: TreeAdapter;
|
|
84
|
+
controls?: FormControlProperties[];
|
|
85
|
+
columns?: FormColumn[];
|
|
86
|
+
rows?: FormRow[];
|
|
87
|
+
options?: FormOptions;
|
|
88
|
+
};
|
|
89
|
+
export type FormButtonConfig = {
|
|
90
|
+
key?: string;
|
|
91
|
+
icon?: IconSpec | string;
|
|
92
|
+
text: string;
|
|
93
|
+
default?: boolean;
|
|
94
|
+
color?: ColorTypes;
|
|
95
|
+
};
|
|
96
|
+
export type FormButtonType = "save" | "reset" | "validate" | "storno" | "close" | FormButtonConfig;
|
|
97
|
+
export type FormAction = FormButtonType;
|
|
98
|
+
export type FormValues = Record<string, unknown>;
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,oBAAY,eAAe;IAC1B,SAAS,SAAS;IAClB,MAAM,WAAW;IACjB,YAAY,WAAW;IACvB,SAAS,SAAS;IAClB,iBAAiB,aAAa;IAC9B,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,UAAU,UAAU;IACpB,SAAS,SAAS;CAClB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IACnC,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,CAAC,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Type["Button"] = "button";
|
|
5
|
+
FormControlType["NumericInput"] = "number";
|
|
6
|
+
FormControlType["DateInput"] = "date";
|
|
7
|
+
FormControlType["CalendarDateInput"] = "calendar";
|
|
8
|
+
FormControlType["Checkbox"] = "checkbox";
|
|
9
|
+
FormControlType["Label"] = "label";
|
|
10
|
+
FormControlType["List"] = "list";
|
|
11
|
+
FormControlType["ColorInput"] = "color";
|
|
12
|
+
FormControlType["FileInput"] = "file";
|
|
13
|
+
})(FormControlType || (FormControlType = {}));
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,eAWX;AAXD,WAAY,eAAe;IAC1B,qCAAkB,CAAA;IAClB,oCAAiB,CAAA;IACjB,0CAAuB,CAAA;IACvB,qCAAkB,CAAA;IAClB,iDAA8B,CAAA;IAC9B,wCAAqB,CAAA;IACrB,kCAAe,CAAA;IACf,gCAAa,CAAA;IACb,uCAAoB,CAAA;IACpB,qCAAkB,CAAA;AACnB,CAAC,EAXW,eAAe,KAAf,eAAe,QAW1B","sourcesContent":["import { ComponentAdapter, CommonOptions, ColorTypes, AlertType, VerticalPosition, IconSpec } from \"@omegagrid/core\";\nimport { TreeAdapter } from \"@omegagrid/tree\";\n\nexport enum FormControlType {\n\tTextInput = 'text',\n\tButton = 'button',\n\tNumericInput = 'number',\n\tDateInput = 'date',\n\tCalendarDateInput = 'calendar',\n\tCheckbox = 'checkbox',\n\tLabel = 'label',\n\tList = 'list',\n\tColorInput = 'color',\n\tFileInput = 'file',\n}\n\nexport type ValidationResult = {\n\tvalid: boolean;\n\tmessage?: string;\n};\n\nexport type FormControlProperties = {\n\t/** Row index within form grid */\n\trow: number,\n\t/** Column index within form grid */\n\tcol: number,\n\t/** Unique field identifier */\n\tkey?: string,\n\t/** Key of bound form control */\n\tfor?: string,\n\t/** Value validation pattern */\n\tpattern?: RegExp,\n\t/** Form control type */\n\ttype?: FormControlType,\n\t/** Required field */\n\trequired?: boolean,\n\t/** Readonly control */\n\treadOnly?: boolean,\n\t/** Current control value */\n\tvalue?: unknown,\n\t/** Key of parent element */\n\tdependsOn?: string,\n\t/** Component adapter where applicable (eg. TreeSelect) */\n\tadapter?: ComponentAdapter,\n\t/** Component item definition */\n\tcontent?: unknown,\n\t/** colspan */\n\tcs?: number,\n\t/** rowspan */\n\trs?: number,\n\t/** control-specific options */\n\toptions?: Record<string, unknown>,\n\tplaceholder?: string,\n\tcaption?: string,\n\n\t/** validation callback */\n\tvalidate?: (value: unknown, props: FormControlProperties) => ValidationResult|boolean|Promise<ValidationResult|boolean>,\n};\n\nexport type FormAlert = {\n\ttext: string,\n\ttype: AlertType\n};\n\nexport type FormRow = {\n\theight?: number\n}\n\nexport type FormColumn = {\n\twidth?: number\n}\n\nexport type FormGridModel = {\n\trows: FormRow[],\n\tcolumns: FormColumn[],\n}\n\nexport type FormOptions = {\n\ttreeAdapter?: TreeAdapter\n}\n\nexport type FormContainerOptions = {\n\tcaption?: string,\n\tbuttonsPosition?: VerticalPosition,\n\talertsPosition?: VerticalPosition,\n\tbuttons?: FormButtonType[],\n\tformOptions?: FormOptions,\n\tcloseAfterSave?: boolean\n} & CommonOptions;\n\nexport type FormSettings = {\n\tkey?: string|number,\n\tcaption?: string,\n\ttreeAdapter?: TreeAdapter,\n\tcontrols?: FormControlProperties[],\n\tcolumns?: FormColumn[],\n\trows?: FormRow[],\n\toptions?: FormOptions\n}\n\nexport type FormButtonConfig = {\n\tkey?: string,\n\ticon?: IconSpec|string,\n\ttext: string,\n\tdefault?: boolean,\n\tcolor?: ColorTypes\n}\n\nexport type FormButtonType = \"save\"|\"reset\"|\"validate\"|\"storno\"|\"close\"|FormButtonConfig;\n\nexport type FormAction = FormButtonType;\n\nexport type FormValues = Record<string, unknown>;"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { ComponentAdapter } from '@omegagrid/core';
|
|
3
|
+
import { FormControlModel, FormModel } from '../../model';
|
|
4
|
+
export declare class ControlEvent<TValue> extends Event {
|
|
5
|
+
readonly model: FormControlModel;
|
|
6
|
+
readonly value: TValue;
|
|
7
|
+
constructor(type: string, model: FormControlModel, value: TValue);
|
|
8
|
+
}
|
|
9
|
+
export interface IControl<TValue = unknown, TAdapter extends ComponentAdapter = null> extends HTMLElement {
|
|
10
|
+
model: FormControlModel;
|
|
11
|
+
adapter: TAdapter;
|
|
12
|
+
value: TValue;
|
|
13
|
+
reset(dispatchEvent?: boolean): Promise<void>;
|
|
14
|
+
validate(): Promise<void>;
|
|
15
|
+
get isValid(): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class BaseControl<TValue = unknown, TAdapter extends ComponentAdapter = null> extends LitElement implements IControl<TValue, TAdapter> {
|
|
18
|
+
static styles: import("lit").CSSResult[];
|
|
19
|
+
model: FormControlModel;
|
|
20
|
+
formModel: FormModel;
|
|
21
|
+
adapter: TAdapter;
|
|
22
|
+
private _value;
|
|
23
|
+
get value(): TValue;
|
|
24
|
+
set value(value: TValue);
|
|
25
|
+
required: boolean;
|
|
26
|
+
protected updateValue(value: TValue, dispatchEvent?: boolean): Promise<void>;
|
|
27
|
+
willUpdate(changedProps: Map<PropertyKey, unknown>): void;
|
|
28
|
+
reset(dispatchEvent?: boolean): Promise<void>;
|
|
29
|
+
validate(): Promise<void>;
|
|
30
|
+
get isValid(): boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=baseControl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseControl.d.ts","sourceRoot":"","sources":["../../../src/ui/controls/baseControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,UAAU,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,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 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, LitElement } from 'lit';
|
|
8
|
+
import { property } from "lit/decorators.js";
|
|
9
|
+
export class ControlEvent extends Event {
|
|
10
|
+
constructor(type, model, value) {
|
|
11
|
+
super(type, { bubbles: true, cancelable: true, composed: true });
|
|
12
|
+
this.model = model;
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class BaseControl extends LitElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this._value = null;
|
|
20
|
+
this.required = false;
|
|
21
|
+
}
|
|
22
|
+
get value() { return this._value; }
|
|
23
|
+
set value(value) {
|
|
24
|
+
const oldValue = this._value;
|
|
25
|
+
this._value = value;
|
|
26
|
+
if (oldValue !== value) {
|
|
27
|
+
this.requestUpdate('value', oldValue);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async updateValue(value, dispatchEvent = true) {
|
|
31
|
+
this._value = value;
|
|
32
|
+
await this.validate();
|
|
33
|
+
if (dispatchEvent) {
|
|
34
|
+
this.dispatchEvent(new ControlEvent('change', this.model, value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
willUpdate(changedProps) {
|
|
38
|
+
if (changedProps.has('model')) {
|
|
39
|
+
if (this.value === null) {
|
|
40
|
+
this.value = this.model.props.value;
|
|
41
|
+
}
|
|
42
|
+
this.required = this.model.props.required;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async reset(dispatchEvent = true) {
|
|
46
|
+
const oldValue = this._value;
|
|
47
|
+
await this.updateValue(this.model.props.value, dispatchEvent);
|
|
48
|
+
this.requestUpdate('value', oldValue);
|
|
49
|
+
}
|
|
50
|
+
async validate() {
|
|
51
|
+
if (!this.model)
|
|
52
|
+
return;
|
|
53
|
+
this.model.errors = [];
|
|
54
|
+
if (this.required && (this.value == null || this.value === '')) {
|
|
55
|
+
this.model.errors = ['this field is required'];
|
|
56
|
+
}
|
|
57
|
+
else if (this.model.props?.validate) {
|
|
58
|
+
const result = await this.model.props.validate(this.value, this.model.props);
|
|
59
|
+
const validationResult = typeof result == 'boolean' ? { valid: result } : result;
|
|
60
|
+
if (!validationResult.valid) {
|
|
61
|
+
this.model.errors.push(validationResult.message || 'Invalid value');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
get isValid() { return this.model.errors.length == 0; }
|
|
66
|
+
}
|
|
67
|
+
BaseControl.styles = [css `
|
|
68
|
+
:host {
|
|
69
|
+
display: block;
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
* {
|
|
74
|
+
box-sizing: border-box;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
:host([required]) {
|
|
78
|
+
border: 2px solid var(--og-accent-color);
|
|
79
|
+
border-radius: var(--og-base-radius);
|
|
80
|
+
}
|
|
81
|
+
`];
|
|
82
|
+
__decorate([
|
|
83
|
+
property({ type: Object })
|
|
84
|
+
], BaseControl.prototype, "model", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
property({ type: Object })
|
|
87
|
+
], BaseControl.prototype, "formModel", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
property({ type: Object })
|
|
90
|
+
], BaseControl.prototype, "adapter", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
property({ type: Object })
|
|
93
|
+
], BaseControl.prototype, "value", null);
|
|
94
|
+
__decorate([
|
|
95
|
+
property({ type: Boolean, reflect: true })
|
|
96
|
+
], BaseControl.prototype, "required", void 0);
|
|
97
|
+
//# sourceMappingURL=baseControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseControl.js","sourceRoot":"","sources":["../../../src/ui/controls/baseControl.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK7C,MAAM,OAAO,YAAqB,SAAQ,KAAK;IAC9C,YACC,IAAY,EACI,KAAuB,EACvB,KAAa;QAE7B,KAAK,CAAC,IAAI,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;QAH/C,UAAK,GAAL,KAAK,CAAkB;QACvB,UAAK,GAAL,KAAK,CAAQ;IAG9B,CAAC;CACD;AAWD,MAAM,OAAgB,WACrB,SAAQ,UAAU;IADnB;;QA4BS,WAAM,GAAW,IAAI,CAAC;QAY9B,aAAQ,GAAG,KAAK,CAAC;IA2ClB,CAAC;IArDA,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,IAAI,KAAK,CAAC,KAAa;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACvC,CAAC;IACF,CAAC;IAKS,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,aAAa,GAAG,IAAI;QAC9D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC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,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7E,MAAM,gBAAgB,GAAG,OAAO,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,MAAM,EAAqB,CAAC,CAAC,CAAC,MAAM,CAAC;YACnG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;gBAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,IAAI,eAAe,CAAC,CAAC;YACrE,CAAC;QACF,CAAC;IACF,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAA,CAAC,CAAC;;AA9E/C,kBAAM,GAAG,CAAC,GAAG,CAAA;;;;;;;;;;;;;;EAcnB,CAAC,AAdW,CAcV;AAGH;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;0CACD;AAGxB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;8CACJ;AAGrB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;4CACP;AAIlB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;wCACU;AAUnC;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CACxB","sourcesContent":["import { css, LitElement } from 'lit';\nimport { property } from \"lit/decorators.js\";\nimport { ComponentAdapter } from '@omegagrid/core';\nimport { FormControlModel, FormModel } from '../../model';\nimport { ValidationResult } from '../../types';\n\nexport class ControlEvent<TValue> extends Event {\n\tconstructor(\n\t\ttype: string,\n\t\tpublic readonly model: FormControlModel,\n\t\tpublic readonly value: TValue\n\t) {\n\t\tsuper(type, {bubbles: true, cancelable: true, composed: true});\n\t}\n}\n\nexport interface IControl<TValue = unknown, TAdapter extends ComponentAdapter = null> extends HTMLElement {\n\tmodel: FormControlModel;\n\tadapter: TAdapter;\n\tvalue: TValue;\n\treset(dispatchEvent?: boolean): Promise<void>;\n\tvalidate() : Promise<void>;\n\tget isValid() : boolean;\n}\n\nexport abstract class BaseControl<TValue = unknown, TAdapter extends ComponentAdapter = null> \n\textends LitElement implements IControl<TValue, TAdapter> {\n\n\tstatic styles = [css`\n\t\t:host {\n\t\t\tdisplay: block;\n\t\t\tbox-sizing: border-box;\n\t\t}\n\n\t\t* {\n\t\t\tbox-sizing: border-box;\n\t\t}\n\n\t\t:host([required]) {\n\t\t\tborder: 2px solid var(--og-accent-color);\n\t\t\tborder-radius: var(--og-base-radius);\n\t\t}\n\t`];\n\n\t@property({type: Object})\n\tmodel: FormControlModel;\n\n\t@property({type: Object})\n\tformModel: FormModel;\n\n\t@property({type: Object})\n\tadapter: TAdapter;\n\n\tprivate _value: TValue = null;\n\t@property({type: Object})\n\tget value() { return this._value; }\n\tset value(value: TValue) {\n\t\tconst oldValue = this._value;\n\t\tthis._value = value;\n\t\tif (oldValue !== value) {\n\t\t\tthis.requestUpdate('value', oldValue);\n\t\t}\n\t}\n\t\n\t@property({type: Boolean, reflect: true})\n\trequired = false;\n\n\tprotected async updateValue(value: TValue, dispatchEvent = true) {\n\t\tthis._value = value;\n\t\tawait this.validate();\n\t\tif (dispatchEvent) {\n\t\t\tthis.dispatchEvent(new ControlEvent<TValue>('change', this.model, value));\n\t\t}\n\t}\n\n\twillUpdate(changedProps: Map<PropertyKey, unknown>): void {\n\t\tif (changedProps.has('model')) {\n\t\t\tif (this.value === null) {\n\t\t\t\tthis.value = this.model.props.value as TValue;\n\t\t\t}\n\t\t\tthis.required = this.model.props.required;\n\t\t}\n\t}\n\n\tasync reset(dispatchEvent = true) {\n\t\tconst oldValue = this._value;\n\t\tawait this.updateValue(this.model.props.value as TValue, dispatchEvent);\n\t\tthis.requestUpdate('value', oldValue);\n\t}\n\n\tasync validate() {\n\t\tif (!this.model) return;\n\n\t\tthis.model.errors = [];\n\n\t\tif (this.required && (this.value == null || this.value === '')) {\n\t\t\tthis.model.errors = ['this field is required'];\n\t\t} else if (this.model.props?.validate) {\n\t\t\tconst result = await this.model.props.validate(this.value, this.model.props);\n\t\t\tconst validationResult = typeof result == 'boolean' ? {valid: result} as ValidationResult : result;\n\t\t\tif (!validationResult.valid) {\n\t\t\t\tthis.model.errors.push(validationResult.message || 'Invalid value');\n\t\t\t}\n\t\t}\n\t}\n\n\tget isValid() { return this.model.errors.length == 0 }\n\t\n}"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Button as CoreButton } from "@omegagrid/core";
|
|
2
|
+
import { FormControlModel } from "../../model";
|
|
3
|
+
import { IControl } from "./baseControl";
|
|
4
|
+
export declare class FormButton extends CoreButton implements IControl<string> {
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
model: FormControlModel;
|
|
7
|
+
adapter: null;
|
|
8
|
+
value: string;
|
|
9
|
+
constructor();
|
|
10
|
+
protected updateValue(value: string, dispatchEvent?: boolean): void;
|
|
11
|
+
willUpdate(props: Map<PropertyKey, unknown>): void;
|
|
12
|
+
reset(): Promise<void>;
|
|
13
|
+
validate(): Promise<void>;
|
|
14
|
+
get isValid(): boolean;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../src/ui/controls/button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,MAAM,IAAI,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAGnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAgB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEvD,qBAEa,UAAW,SAAQ,UAAW,YAAW,QAAQ,CAAC,MAAM,CAAC;IAErE,MAAM,CAAC,MAAM,4BAKV;IAGH,KAAK,EAAE,gBAAgB,CAAC;IAGxB,OAAO,EAAE,IAAI,CAAC;IAGd,KAAK,EAAE,MAAM,CAAQ;;IAUrB,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,UAAO;IASzD,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI;IAuB5C,KAAK;IAIL,QAAQ;IAId,IAAI,OAAO,YAA4C;CAEvD"}
|