@ng-atomic/common 18.2.1 → 18.5.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/common.module.d.ts +15 -0
- package/esm2022/common.module.mjs +34 -0
- package/esm2022/index.mjs +2 -2
- package/esm2022/interceptors/authorization/authorization.interceptor.mjs +2 -2
- package/esm2022/models/index.mjs +1 -1
- package/esm2022/pipes/data-accessor/data-accessor.pipe.mjs +7 -4
- package/esm2022/pipes/domain/domain.pipe.mjs +19 -1
- package/esm2022/pipes/smart-field/smart-field.pipe.mjs +2 -2
- package/esm2022/services/app/app.service.mjs +48 -2
- package/esm2022/services/fab/fab.service.mjs +11 -5
- package/esm2022/services/form/_index/index.service.mjs +2 -2
- package/esm2022/services/form/columns/columns.service.mjs +19 -10
- package/esm2022/services/form/json-schema/index.mjs +2 -0
- package/esm2022/services/form/json-schema/json-schema.mjs +51 -0
- package/esm2022/services/form/json-schema/json-schema.service.mjs +140 -0
- package/esm2022/services/form/json-schema/ng-atomic-common-services-form-json-schema.mjs +5 -0
- package/esm2022/services/initializer/initializer.service.mjs +2 -2
- package/esm2022/services/loading/loading.service.mjs +28 -31
- package/esm2022/services/root-property/root-property.service.mjs +3 -1
- package/esm2022/services/sheets/actions/actions.sheet.mjs +45 -0
- package/esm2022/services/sheets/actions/index.mjs +2 -0
- package/esm2022/services/sheets/actions/ng-atomic-common-services-sheets-actions.mjs +5 -0
- package/esm2022/services/sheets/index.mjs +3 -0
- package/esm2022/services/sheets/ng-atomic-common-services-sheets.mjs +5 -0
- package/esm2022/services/sheets/sheets.module.mjs +25 -0
- package/esm2022/services/sheets/sheets.service.mjs +22 -0
- package/esm2022/services/side-app/side-app.service.mjs +33 -3
- package/esm2022/services/ui/ui.helpers.mjs +47 -65
- package/esm2022/stores/entities/entity-store-adapter.mjs +4 -1
- package/esm2022/stores/entities/entity-store.mjs +13 -1
- package/esm2022/utils/inject/inject.mjs +61 -22
- package/fesm2022/ng-atomic-common-interceptors-authorization.mjs +1 -1
- package/fesm2022/ng-atomic-common-interceptors-authorization.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-pipes-data-accessor.mjs +7 -4
- package/fesm2022/ng-atomic-common-pipes-data-accessor.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-pipes-domain.mjs +18 -0
- package/fesm2022/ng-atomic-common-pipes-domain.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-pipes-smart-field.mjs +1 -1
- package/fesm2022/ng-atomic-common-pipes-smart-field.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-app.mjs +49 -3
- package/fesm2022/ng-atomic-common-services-app.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-fab.mjs +10 -4
- package/fesm2022/ng-atomic-common-services-fab.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-form-_index.mjs +1 -1
- package/fesm2022/ng-atomic-common-services-form-_index.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-form-columns.mjs +18 -9
- package/fesm2022/ng-atomic-common-services-form-columns.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-form-json-schema.mjs +194 -0
- package/fesm2022/ng-atomic-common-services-form-json-schema.mjs.map +1 -0
- package/fesm2022/ng-atomic-common-services-initializer.mjs +1 -1
- package/fesm2022/ng-atomic-common-services-initializer.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-loading.mjs +26 -29
- package/fesm2022/ng-atomic-common-services-loading.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-root-property.mjs +2 -0
- package/fesm2022/ng-atomic-common-services-root-property.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-sheets-actions.mjs +52 -0
- package/fesm2022/ng-atomic-common-services-sheets-actions.mjs.map +1 -0
- package/fesm2022/ng-atomic-common-services-sheets.mjs +50 -0
- package/fesm2022/ng-atomic-common-services-sheets.mjs.map +1 -0
- package/fesm2022/ng-atomic-common-services-side-app.mjs +33 -3
- package/fesm2022/ng-atomic-common-services-side-app.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-services-ui.mjs +46 -64
- package/fesm2022/ng-atomic-common-services-ui.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-stores-entities.mjs +15 -0
- package/fesm2022/ng-atomic-common-stores-entities.mjs.map +1 -1
- package/fesm2022/ng-atomic-common-utils.mjs +62 -23
- package/fesm2022/ng-atomic-common-utils.mjs.map +1 -1
- package/fesm2022/ng-atomic-common.mjs +76 -0
- package/fesm2022/ng-atomic-common.mjs.map +1 -1
- package/index.d.ts +1 -1
- package/models/index.d.ts +1 -0
- package/package.json +20 -2
- package/pipes/data-accessor/data-accessor.pipe.d.ts +4 -3
- package/pipes/domain/domain.pipe.d.ts +2 -1
- package/pipes/smart-field/smart-field.pipe.d.ts +1 -1
- package/services/app/app.service.d.ts +12 -0
- package/services/fab/fab.service.d.ts +3 -3
- package/services/form/columns/columns.service.d.ts +8 -1
- package/services/form/json-schema/index.d.ts +1 -0
- package/services/form/json-schema/json-schema.d.ts +2 -0
- package/services/form/json-schema/json-schema.service.d.ts +54 -0
- package/services/loading/loading.service.d.ts +13 -12
- package/services/sheets/actions/actions.sheet.d.ts +9 -0
- package/services/sheets/actions/index.d.ts +1 -0
- package/services/sheets/index.d.ts +2 -0
- package/services/sheets/sheets.module.d.ts +11 -0
- package/services/sheets/sheets.service.d.ts +10 -0
- package/services/side-app/side-app.service.d.ts +12 -0
- package/services/ui/ui.helpers.d.ts +6 -5
- package/stores/entities/entity-store-adapter.d.ts +3 -6
- package/stores/entities/entity-store.d.ts +4 -0
- package/utils/inject/inject.d.ts +29 -7
|
@@ -39,26 +39,30 @@ class ColumnsFormBuilder {
|
|
|
39
39
|
type: this.fb.control({ value: 'tree', disabled: true }),
|
|
40
40
|
headerText: this.fb.control(column.headerText),
|
|
41
41
|
visible: this.fb.control(column.visible),
|
|
42
|
-
width: this.fb.control(
|
|
42
|
+
width: this.fb.control(column.width),
|
|
43
|
+
sticky: this.fb.control(column.sticky),
|
|
43
44
|
});
|
|
44
45
|
case 'text':
|
|
45
46
|
return this.fb.group({
|
|
46
47
|
type: this.fb.control({ value: 'text', disabled: true }),
|
|
47
48
|
visible: this.fb.control(column.visible),
|
|
48
|
-
width: this.fb.control(
|
|
49
|
+
width: this.fb.control(column.width),
|
|
50
|
+
sticky: this.fb.control(column.sticky),
|
|
49
51
|
});
|
|
50
52
|
case 'checkbox':
|
|
51
53
|
return this.fb.group({
|
|
52
54
|
type: this.fb.control({ value: 'checkbox', disabled: true }),
|
|
53
55
|
visible: this.fb.control(column.visible),
|
|
54
|
-
width: this.fb.control(
|
|
56
|
+
width: this.fb.control(column.width),
|
|
57
|
+
sticky: this.fb.control(column.sticky),
|
|
55
58
|
});
|
|
56
59
|
case 'actions':
|
|
57
60
|
return this.fb.group({
|
|
58
61
|
type: this.fb.control({ value: 'actions', disabled: true }),
|
|
59
62
|
visible: this.fb.control(column.visible),
|
|
60
|
-
width: this.fb.control(
|
|
63
|
+
width: this.fb.control(column.width),
|
|
61
64
|
actions: this.fb.control(column.actions),
|
|
65
|
+
sticky: this.fb.control(column.sticky),
|
|
62
66
|
});
|
|
63
67
|
default:
|
|
64
68
|
throw new Error(`Unknown column type: ${column.type}`);
|
|
@@ -74,7 +78,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImpor
|
|
|
74
78
|
function injectColumnsForm() {
|
|
75
79
|
return inject(ColumnsFormBuilder).build();
|
|
76
80
|
}
|
|
77
|
-
function toColumns(column, i) {
|
|
81
|
+
function toColumns(column, i, sticky) {
|
|
78
82
|
if (typeof column === 'string') {
|
|
79
83
|
if (column === '__actions') {
|
|
80
84
|
return {
|
|
@@ -82,6 +86,7 @@ function toColumns(column, i) {
|
|
|
82
86
|
name: `actions_${i}`,
|
|
83
87
|
visible: true,
|
|
84
88
|
width: 80,
|
|
89
|
+
sticky,
|
|
85
90
|
};
|
|
86
91
|
}
|
|
87
92
|
else if (column === '__checkbox') {
|
|
@@ -89,7 +94,8 @@ function toColumns(column, i) {
|
|
|
89
94
|
type: 'checkbox',
|
|
90
95
|
name: 'checkbox',
|
|
91
96
|
visible: true,
|
|
92
|
-
width:
|
|
97
|
+
width: 24,
|
|
98
|
+
sticky,
|
|
93
99
|
};
|
|
94
100
|
}
|
|
95
101
|
else if (column.startsWith('__tree')) {
|
|
@@ -98,7 +104,8 @@ function toColumns(column, i) {
|
|
|
98
104
|
name: column.split('__tree_')?.[1] ?? '__tree',
|
|
99
105
|
headerText: column.split('__tree_')?.[1] ?? '',
|
|
100
106
|
visible: true,
|
|
101
|
-
width:
|
|
107
|
+
width: 320,
|
|
108
|
+
sticky,
|
|
102
109
|
};
|
|
103
110
|
}
|
|
104
111
|
else {
|
|
@@ -107,6 +114,7 @@ function toColumns(column, i) {
|
|
|
107
114
|
name: column,
|
|
108
115
|
visible: true,
|
|
109
116
|
width: 80,
|
|
117
|
+
sticky,
|
|
110
118
|
};
|
|
111
119
|
}
|
|
112
120
|
}
|
|
@@ -116,12 +124,13 @@ function toColumns(column, i) {
|
|
|
116
124
|
name: `actions_${i}`,
|
|
117
125
|
visible: true,
|
|
118
126
|
width: 80,
|
|
127
|
+
sticky,
|
|
119
128
|
actions: wrapActions(column),
|
|
120
129
|
};
|
|
121
130
|
}
|
|
122
131
|
}
|
|
123
|
-
function buildColumns(columns) {
|
|
124
|
-
const _columns = columns.map((column, i) => toColumns(column, i));
|
|
132
|
+
function buildColumns(columns, { stickyStart = 0, stickyEnd = 0, } = {}) {
|
|
133
|
+
const _columns = columns.map((column, i) => toColumns(column, i, i < stickyStart || i >= columns.length - stickyEnd));
|
|
125
134
|
return {
|
|
126
135
|
ids: _columns.map((column) => column.name),
|
|
127
136
|
map: _columns.reduce((obj, column) => ({ ...obj, [column.name]: column }), {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-atomic-common-services-form-columns.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/form/columns/columns.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/form/columns/ng-atomic-common-services-form-columns.ts"],"sourcesContent":["import { inject, Injectable } from \"@angular/core\";\nimport { FormArray, FormBuilder, FormControl, FormGroup, FormRecord, Validators } from \"@angular/forms\";\nimport { Actions, wrapActions } from \"@ng-atomic/core\";\nimport { Column } from \"@ng-atomic/common/models\";\n\nexport type ActionsColumnForm = FormGroup<{\n type: FormControl<'actions'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n actions: FormControl<any>,\n}>;\n\nexport type CheckboxColumnForm = FormGroup<{\n type: FormControl<'checkbox'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n}>;\n\nexport type TextColumnForm = FormGroup<{\n type: FormControl<'text'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n}>;\n\nexport type TreeColumnForm = FormGroup<{\n type: FormControl<'tree'>,\n headerText: FormControl<string>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n}>;\n\nexport type ColumnsForm = FormArray<FormRecord<ActionsColumnForm | CheckboxColumnForm | TextColumnForm | TreeColumnForm>>;\n\nexport interface ColumnsFormValue {\n ids: string[],\n map: { [key: string]: Column },\n}\n\n@Injectable({providedIn: 'root'})\nexport class ColumnsFormBuilder {\n protected readonly fb = inject(FormBuilder).nonNullable;\n\n build(columns: ColumnsFormValue = {\n ids: ['id', 'user'],\n map: {\n user: {\n type: 'text' as const,\n headerText: 'User',\n width: 80,\n visible: true,\n },\n id: {\n type: 'text',\n headerText: 'ID',\n width: 80,\n visible: true,\n },\n },\n }) {\n return this.fb.group({\n ids: this.fb.control(columns.ids, Validators.required),\n map: this.fb.group(Object.entries(columns.map).reduce((obj, [key, value]) => ({\n ...obj,\n [key]: this.buildColumnForm(value),\n }), {})),\n });\n }\n\n protected buildColumnForm(column: Column) {\n switch (column.type) {\n case 'tree':\n return this.fb.group({\n type: this.fb.control({value: 'tree' as const, disabled: true}),\n headerText: this.fb.control(column.headerText),\n visible: this.fb.control(column.visible),\n width: this.fb.control(80),\n }) as TreeColumnForm;\n case 'text': \n return this.fb.group({\n type: this.fb.control({value: 'text' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(80),\n }) as TextColumnForm;\n case 'checkbox':\n return this.fb.group({\n type: this.fb.control({value: 'checkbox' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(80),\n }) as CheckboxColumnForm;\n case 'actions':\n return this.fb.group({\n type: this.fb.control({value: 'actions' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(80),\n actions: this.fb.control(column.actions),\n }) as ActionsColumnForm;\n default:\n throw new Error(`Unknown column type: ${(column as any).type}`);\n }\n }\n}\n\nexport function injectColumnsForm() {\n return inject(ColumnsFormBuilder).build();\n}\n\nfunction toColumns(column: (string | Actions), i: number): Column {\n if (typeof column === 'string') {\n if (column === '__actions') {\n return {\n type: 'actions',\n name: `actions_${i}`,\n visible: true,\n width: 80,\n }\n } else if (column === '__checkbox') {\n return {\n type: 'checkbox',\n name: 'checkbox',\n visible: true,\n width: 80,\n }\n } else if (column.startsWith('__tree')) {\n return {\n type: 'tree',\n name: column.split('__tree_')?.[1] ?? '__tree',\n headerText: column.split('__tree_')?.[1] ?? '',\n visible: true,\n width: 200,\n }\n } else {\n return {\n type: 'text',\n name: column,\n visible: true,\n width: 80,\n };\n } \n } else {\n return {\n type: 'actions',\n name: `actions_${i}`,\n visible: true,\n width: 80,\n actions: wrapActions(column),\n };\n }\n}\n\nexport function buildColumns(columns: (string | Actions)[]): {ids: string[], map: {[key: string]: Column}} {\n const _columns = columns.map((column, i) => toColumns(column, i));\n return {\n ids: _columns.map((column) => column.name),\n map: _columns.reduce((obj, column) => ({...obj, [column.name]: column}), {}),\n };\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAuCa,kBAAkB,CAAA;AAD/B,IAAA,WAAA,GAAA;AAEqB,QAAA,IAAA,CAAA,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CA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,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,MAAM,EAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,EAAC,CAAC,EAAE,EAAE,CAAC;KAC7E,CAAC;AACJ;;AC3JA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-atomic-common-services-form-columns.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/form/columns/columns.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/form/columns/ng-atomic-common-services-form-columns.ts"],"sourcesContent":["import { inject, Injectable } from \"@angular/core\";\nimport { FormArray, FormBuilder, FormControl, FormGroup, FormRecord, Validators } from \"@angular/forms\";\nimport { Actions, wrapActions } from \"@ng-atomic/core\";\nimport { Column } from \"@ng-atomic/common/models\";\n\nexport type ActionsColumnForm = FormGroup<{\n type: FormControl<'actions'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n actions: FormControl<any>,\n sticky: FormControl<boolean>,\n}>;\n\nexport type CheckboxColumnForm = FormGroup<{\n type: FormControl<'checkbox'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n sticky: FormControl<boolean>,\n}>;\n\nexport type TextColumnForm = FormGroup<{\n type: FormControl<'text'>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n sticky: FormControl<boolean>,\n}>;\n\nexport type TreeColumnForm = FormGroup<{\n type: FormControl<'tree'>,\n headerText: FormControl<string>,\n visible: FormControl<boolean>,\n width: FormControl<number>,\n sticky: FormControl<boolean>,\n}>;\n\nexport type ColumnsForm = FormArray<FormRecord<ActionsColumnForm | CheckboxColumnForm | TextColumnForm | TreeColumnForm>>;\n\nexport interface ColumnsFormValue {\n ids: string[],\n map: { [key: string]: Column },\n}\n\n@Injectable({providedIn: 'root'})\nexport class ColumnsFormBuilder {\n protected readonly fb = inject(FormBuilder).nonNullable;\n\n build(columns: ColumnsFormValue = {\n ids: ['id', 'user'],\n map: {\n user: {\n type: 'text' as const,\n headerText: 'User',\n width: 80,\n visible: true,\n },\n id: {\n type: 'text',\n headerText: 'ID',\n width: 80,\n visible: true,\n },\n },\n }) {\n return this.fb.group({\n ids: this.fb.control(columns.ids, Validators.required),\n map: this.fb.group(Object.entries(columns.map).reduce((obj, [key, value]) => ({\n ...obj,\n [key]: this.buildColumnForm(value),\n }), {})),\n });\n }\n\n protected buildColumnForm(column: Column) {\n switch (column.type) {\n case 'tree':\n return this.fb.group({\n type: this.fb.control({value: 'tree' as const, disabled: true}),\n headerText: this.fb.control(column.headerText),\n visible: this.fb.control(column.visible),\n width: this.fb.control(column.width),\n sticky: this.fb.control(column.sticky),\n }) as TreeColumnForm;\n case 'text': \n return this.fb.group({\n type: this.fb.control({value: 'text' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(column.width),\n sticky: this.fb.control(column.sticky),\n }) as TextColumnForm;\n case 'checkbox':\n return this.fb.group({\n type: this.fb.control({value: 'checkbox' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(column.width),\n sticky: this.fb.control(column.sticky),\n }) as CheckboxColumnForm;\n case 'actions':\n return this.fb.group({\n type: this.fb.control({value: 'actions' as const, disabled: true}),\n visible: this.fb.control(column.visible),\n width: this.fb.control(column.width),\n actions: this.fb.control(column.actions),\n sticky: this.fb.control(column.sticky),\n }) as ActionsColumnForm;\n default:\n throw new Error(`Unknown column type: ${(column as any).type}`);\n }\n }\n}\n\nexport function injectColumnsForm() {\n return inject(ColumnsFormBuilder).build();\n}\n\nfunction toColumns(column: (string | Actions), i: number, sticky: boolean): Column {\n if (typeof column === 'string') {\n if (column === '__actions') {\n return {\n type: 'actions',\n name: `actions_${i}`,\n visible: true,\n width: 80,\n sticky,\n }\n } else if (column === '__checkbox') {\n return {\n type: 'checkbox',\n name: 'checkbox',\n visible: true,\n width: 24,\n sticky,\n }\n } else if (column.startsWith('__tree')) {\n return {\n type: 'tree',\n name: column.split('__tree_')?.[1] ?? '__tree',\n headerText: column.split('__tree_')?.[1] ?? '',\n visible: true,\n width: 320,\n sticky,\n }\n } else {\n return {\n type: 'text',\n name: column,\n visible: true,\n width: 80,\n sticky,\n };\n } \n } else {\n return {\n type: 'actions',\n name: `actions_${i}`,\n visible: true,\n width: 80,\n sticky,\n actions: wrapActions(column),\n };\n }\n}\n\nexport function buildColumns(columns: (string | Actions)[], {\n stickyStart = 0,\n stickyEnd = 0,\n}: {\n stickyStart?: number,\n stickyEnd?: number,\n} = {}): {ids: string[], map: {[key: string]: Column}} {\n const _columns = columns.map((column, i) => toColumns(column, i, i < stickyStart || i >= columns.length - stickyEnd));\n return {\n ids: _columns.map((column) => column.name),\n map: _columns.reduce((obj, column) => ({...obj, [column.name]: column}), {}),\n };\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MA2Ca,kBAAkB,CAAA;AAD/B,IAAA,WAAA,GAAA;AAEqB,QAAA,IAAA,CAAA,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC;AAgEzD,KAAA;AA9DC,IAAA,KAAK,CAAC,OAA4B,GAAA;AAChC,QAAA,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;AACnB,QAAA,GAAG,EAAE;AACH,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,MAAe;AACrB,gBAAA,UAAU,EAAE,MAAM;AAClB,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,OAAO,EAAE,IAAI;AACd,aAAA;AACD,YAAA,EAAE,EAAE;AACF,gBAAA,IAAI,EAAE,MAAM;AACZ,gBAAA,UAAU,EAAE,IAAI;AAChB,gBAAA,KAAK,EAAE,EAAE;AACT,gBAAA,OAAO,EAAE,IAAI;AACd,aAAA;AACF,SAAA;AACF,KAAA,EAAA;AACC,QAAA,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC;AACnB,YAAA,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC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,MAAM,MAAM,EAAC,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,EAAC,CAAC,EAAE,EAAE,CAAC;KAC7E,CAAC;AACJ;;AC9KA;;AAEG;;;;"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, Injectable } from '@angular/core';
|
|
3
|
+
import { Validators, FormBuilder } from '@angular/forms';
|
|
4
|
+
import { ValidationTypes } from 'class-validator';
|
|
5
|
+
import { targetConstructorToSchema as targetConstructorToSchema$1 } from 'class-validator-jsonschema';
|
|
6
|
+
import { defaultMetadataStorage } from 'class-transformer/esm5/storage';
|
|
7
|
+
import { merge } from 'lodash-es';
|
|
8
|
+
|
|
9
|
+
function getPropType(target, property) {
|
|
10
|
+
return Reflect.getMetadata('design:type', target, property);
|
|
11
|
+
}
|
|
12
|
+
function targetToSchema(type, options) {
|
|
13
|
+
if (typeof type === 'function') {
|
|
14
|
+
if (type.prototype === String.prototype ||
|
|
15
|
+
type.prototype === Symbol.prototype) {
|
|
16
|
+
return { type: 'string' };
|
|
17
|
+
}
|
|
18
|
+
else if (type.prototype === Number.prototype) {
|
|
19
|
+
return { type: 'number' };
|
|
20
|
+
}
|
|
21
|
+
else if (type.prototype === Boolean.prototype) {
|
|
22
|
+
return { type: 'boolean' };
|
|
23
|
+
}
|
|
24
|
+
return targetConstructorToSchema(type, options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const additionalConverters = {
|
|
28
|
+
[ValidationTypes.NESTED_VALIDATION]: (meta, options) => {
|
|
29
|
+
if (typeof meta.target === 'function') {
|
|
30
|
+
const typeMeta = options.classTransformerMetadataStorage
|
|
31
|
+
? options.classTransformerMetadataStorage.findTypeMetadata(meta.target, meta.propertyName)
|
|
32
|
+
: null;
|
|
33
|
+
const childType = typeMeta
|
|
34
|
+
? typeMeta.typeFunction()
|
|
35
|
+
: getPropType(meta.target.prototype, meta.propertyName);
|
|
36
|
+
return targetToSchema(childType, options);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
isDayjs: (meta) => {
|
|
40
|
+
return {
|
|
41
|
+
type: 'string',
|
|
42
|
+
format: 'date-time', // JSON Schemaで日付型を指定
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
function targetConstructorToSchema(target, options = {}) {
|
|
47
|
+
return targetConstructorToSchema$1(target, {
|
|
48
|
+
...options,
|
|
49
|
+
additionalConverters,
|
|
50
|
+
classTransformerMetadataStorage: defaultMetadataStorage,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildFormGroupByJsonSchema(schema, { fb = inject(FormBuilder).nonNullable, value = {}, } = {}) {
|
|
55
|
+
console.debug('[buildFormGroupByJsonSchema] schema:', schema);
|
|
56
|
+
if (!schema || !schema?.properties) {
|
|
57
|
+
return fb.group({});
|
|
58
|
+
}
|
|
59
|
+
const group = {};
|
|
60
|
+
for (const key in schema.properties) {
|
|
61
|
+
const property = schema.properties[key];
|
|
62
|
+
const validators = [];
|
|
63
|
+
if (schema.required && schema.required.includes(key)) {
|
|
64
|
+
validators.push(Validators.required);
|
|
65
|
+
}
|
|
66
|
+
group[key] = buildFormByJsonSchemaProperty(property, { fb, value: value?.[key], validators });
|
|
67
|
+
}
|
|
68
|
+
return fb.group(group);
|
|
69
|
+
}
|
|
70
|
+
function buildFormArrayByJsonSchema(schema, { fb = inject(FormBuilder).nonNullable, value = [], } = {}) {
|
|
71
|
+
if (!schema || !schema.items) {
|
|
72
|
+
return fb.array([]);
|
|
73
|
+
}
|
|
74
|
+
console.debug('[buildFormArrayByJsonSchema] schema:', schema);
|
|
75
|
+
const array = fb.array([
|
|
76
|
+
buildFormGroupByJsonSchema(schema.items, { fb }),
|
|
77
|
+
]);
|
|
78
|
+
return array;
|
|
79
|
+
}
|
|
80
|
+
function buildFormByJsonSchemaProperty(property, { fb = inject(FormBuilder).nonNullable, value = null, validators = [], } = {}) {
|
|
81
|
+
if (property.type === 'string') {
|
|
82
|
+
if (property.format === 'date-time') {
|
|
83
|
+
return fb.control(value ?? property.default ?? null, validators);
|
|
84
|
+
}
|
|
85
|
+
else if (property.format === 'binary') {
|
|
86
|
+
return fb.control(value ?? property.default ?? null, validators);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return fb.control(value ?? property.default ?? '', validators);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (property.type === 'integer') {
|
|
93
|
+
return fb.control(value ?? property.default ?? 0, validators);
|
|
94
|
+
}
|
|
95
|
+
else if (property.type === 'number') {
|
|
96
|
+
return fb.control(value ?? property.default ?? 0, validators);
|
|
97
|
+
}
|
|
98
|
+
else if (property.type === 'object') {
|
|
99
|
+
return buildFormGroupByJsonSchema(property, { fb, value: (value || {}) });
|
|
100
|
+
}
|
|
101
|
+
else if (property.type === 'array') {
|
|
102
|
+
return buildFormArrayByJsonSchema(property, { fb, value: (value || []) });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function buildFormFieldMapByJsonSchema(schema, options = {}) {
|
|
106
|
+
if (!schema || !schema.properties) {
|
|
107
|
+
return {
|
|
108
|
+
id: { type: 'hidden' },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const fieldMap = {};
|
|
112
|
+
for (const key in schema.properties) {
|
|
113
|
+
const property = schema.properties[key];
|
|
114
|
+
if (property.type === 'string') {
|
|
115
|
+
if (property.enum) {
|
|
116
|
+
fieldMap[key] = { type: 'select', options: property.enum.map((v) => ({ value: v, name: v })) };
|
|
117
|
+
}
|
|
118
|
+
else if (property.format === 'date-time') {
|
|
119
|
+
fieldMap[key] = { type: 'date' };
|
|
120
|
+
}
|
|
121
|
+
else if (property.format === 'binary') {
|
|
122
|
+
fieldMap[key] = { type: 'file' };
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
fieldMap[key] = { type: 'text' };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (property.type === 'object') {
|
|
129
|
+
const childFieldMap = buildFormFieldMapByJsonSchema(property, options);
|
|
130
|
+
for (const childKey in childFieldMap) {
|
|
131
|
+
fieldMap[`${key}.${childKey}`] = childFieldMap[childKey];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (property.type === 'array') {
|
|
135
|
+
const childFieldMap = buildFormFieldMapByJsonSchema(property.items, options);
|
|
136
|
+
for (const childKey in childFieldMap) {
|
|
137
|
+
// TODO: 正規表現でパスマッチを判定できるようにする。
|
|
138
|
+
fieldMap[`${key}.\\d+.${childKey}`] = childFieldMap[childKey];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
fieldMap[key] = { type: property.type };
|
|
143
|
+
}
|
|
144
|
+
// const type = ? 'date' : property.type;
|
|
145
|
+
}
|
|
146
|
+
console.debug('[buildFormFieldMapByJsonSchema] fieldMap:', fieldMap);
|
|
147
|
+
return merge(fieldMap, options.merge);
|
|
148
|
+
}
|
|
149
|
+
function buildFormByJsonSchema(schema, { fb = inject(FormBuilder).nonNullable, value = {}, fieldMap = {}, } = {}) {
|
|
150
|
+
return {
|
|
151
|
+
form: buildFormGroupByJsonSchema(schema, { fb, value }),
|
|
152
|
+
fieldMap: buildFormFieldMapByJsonSchema(schema, { merge: fieldMap }),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function buildFormGroup(klass, { fb = inject(FormBuilder).nonNullable, value, }) {
|
|
156
|
+
const schema = targetConstructorToSchema(klass);
|
|
157
|
+
return buildFormGroupByJsonSchema(schema, { fb, value });
|
|
158
|
+
}
|
|
159
|
+
function buildFormFieldMap(klass, options) {
|
|
160
|
+
const schema = targetConstructorToSchema(klass);
|
|
161
|
+
const map = buildFormFieldMapByJsonSchema(schema, options);
|
|
162
|
+
return merge(map, options.merge);
|
|
163
|
+
}
|
|
164
|
+
function buildForm(klass, { fb = inject(FormBuilder).nonNullable, value = {}, fieldMap = {}, } = {}) {
|
|
165
|
+
const schema = targetConstructorToSchema(klass);
|
|
166
|
+
return {
|
|
167
|
+
form: buildFormGroupByJsonSchema(schema, { fb, value }),
|
|
168
|
+
fieldMap: buildFormFieldMapByJsonSchema(schema, { merge: fieldMap }),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
class JsonSchemaFormService {
|
|
172
|
+
constructor() {
|
|
173
|
+
this.fb = inject(FormBuilder).nonNullable;
|
|
174
|
+
}
|
|
175
|
+
build(schema, { fb = this.fb, value = {}, } = {}) {
|
|
176
|
+
return buildFormGroupByJsonSchema(schema, { fb, value });
|
|
177
|
+
}
|
|
178
|
+
buildFieldMap(schema, options = {}) {
|
|
179
|
+
return buildFormFieldMapByJsonSchema(schema, options);
|
|
180
|
+
}
|
|
181
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: JsonSchemaFormService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
182
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: JsonSchemaFormService, providedIn: 'root' }); }
|
|
183
|
+
}
|
|
184
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: JsonSchemaFormService, decorators: [{
|
|
185
|
+
type: Injectable,
|
|
186
|
+
args: [{ providedIn: 'root' }]
|
|
187
|
+
}] });
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Generated bundle index. Do not edit.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
export { JsonSchemaFormService, buildForm, buildFormArrayByJsonSchema, buildFormByJsonSchema, buildFormByJsonSchemaProperty, buildFormFieldMap, buildFormFieldMapByJsonSchema, buildFormGroup, buildFormGroupByJsonSchema };
|
|
194
|
+
//# sourceMappingURL=ng-atomic-common-services-form-json-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ng-atomic-common-services-form-json-schema.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/form/json-schema/json-schema.ts","../../../../../packages/@ng-atomic/common/src/lib/services/form/json-schema/json-schema.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/form/json-schema/ng-atomic-common-services-form-json-schema.ts"],"sourcesContent":["import { ValidationTypes } from \"class-validator\"\nimport { targetConstructorToSchema as _targetConstructorToSchema } from \"class-validator-jsonschema\"\nimport { IOptions } from \"class-validator-jsonschema/build/options\";\nimport { JSONSchema7 } from 'json-schema';\n// TODO(@NozomuMiyamoto): fix\n// @ts-ignore\n// const { defaultMetadataStorage } = require('class-transformer/cjs/storage');\nimport { defaultMetadataStorage } from 'class-transformer/esm5/storage';\n\nfunction getPropType(target: object, property: string) {\n return Reflect.getMetadata('design:type', target, property)\n}\n\nfunction targetToSchema(\n type: any,\n options: any\n): any {\n if (typeof type === 'function') {\n if (\n type.prototype === String.prototype ||\n type.prototype === Symbol.prototype\n ) {\n return { type: 'string' }\n } else if (type.prototype === Number.prototype) {\n return { type: 'number' }\n } else if (type.prototype === Boolean.prototype) {\n return { type: 'boolean' }\n }\n\n return targetConstructorToSchema(type, options)\n }\n}\n\nconst additionalConverters= {\n [ValidationTypes.NESTED_VALIDATION]: (meta: any, options: any) => {\n if (typeof meta.target === 'function') {\n const typeMeta = options.classTransformerMetadataStorage\n ? options.classTransformerMetadataStorage.findTypeMetadata(\n meta.target,\n meta.propertyName\n )\n : null\n const childType = typeMeta\n ? typeMeta.typeFunction()\n : getPropType(meta.target.prototype, meta.propertyName)\n return targetToSchema(childType, options)\n }\n },\n isDayjs: (meta: any): JSONSchema7 => {\n return {\n type: 'string',\n format: 'date-time', // JSON Schemaで日付型を指定\n };\n },\n};\n\nexport function targetConstructorToSchema(target: Function, options: Partial<IOptions> = {}) {\n return _targetConstructorToSchema(target, {\n ...options,\n additionalConverters,\n classTransformerMetadataStorage: defaultMetadataStorage,\n });\n}\n","import { Injectable, inject } from \"@angular/core\";\nimport { FormBuilder, FormGroup, NonNullableFormBuilder, Validators } from \"@angular/forms\";\nimport { JsonSchema } from \"json-schema-library\";\nimport { targetConstructorToSchema } from './json-schema';\nimport { merge } from \"lodash-es\";\n\nexport function buildFormGroupByJsonSchema(schema: JsonSchema, {\n fb = inject(FormBuilder).nonNullable,\n value = {},\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object,\n} = {}): FormGroup {\n console.debug('[buildFormGroupByJsonSchema] schema:', schema);\n if (!schema || !schema?.properties) {\n return fb.group({});\n }\n const group: any = {};\n \n for (const key in schema.properties) {\n const property = schema.properties[key];\n const validators = [];\n\n if (schema.required && schema.required.includes(key)) {\n validators.push(Validators.required);\n }\n group[key] = buildFormByJsonSchemaProperty(property, {fb, value: value?.[key], validators});\n }\n return fb.group(group);\n}\n\nexport function buildFormArrayByJsonSchema(schema: JsonSchema, {\n fb = inject(FormBuilder).nonNullable,\n value = [],\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: any[],\n} = {}): any {\n if (!schema || !schema.items) {\n return fb.array([]);\n }\n console.debug('[buildFormArrayByJsonSchema] schema:', schema);\n const array = fb.array([\n buildFormGroupByJsonSchema(schema.items, {fb}),\n ])\n return array;\n}\n\nexport function buildFormByJsonSchemaProperty(property: JsonSchema, {\n fb = inject(FormBuilder).nonNullable,\n value = null,\n validators = [],\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object | object[],\n validators?: any[],\n} = {}): any {\n if (property.type === 'string') {\n if (property.format === 'date-time') {\n return fb.control(value ?? property.default ?? null, validators);\n } else if (property.format === 'binary') {\n return fb.control(value ?? property.default ?? null, validators);\n } else {\n return fb.control(value ?? property.default ?? '', validators);\n }\n } else if (property.type === 'integer') {\n return fb.control(value ?? property.default ?? 0, validators);\n } else if (property.type === 'number') {\n return fb.control(value ?? property.default ?? 0, validators);\n } else if (property.type === 'object') {\n return buildFormGroupByJsonSchema(property, {fb, value: (value || {}) as object});\n }\n else if (property.type === 'array') {\n return buildFormArrayByJsonSchema(property, {fb, value: (value || []) as any[]});\n }\n}\n\nexport function buildFormFieldMapByJsonSchema(\n schema: JsonSchema,\n options: {\n merge?: { [key: string]: any },\n } = {},\n): any {\n if (!schema || !schema.properties) {\n return {\n id: { type: 'hidden' },\n };\n }\n const fieldMap: any = {};\n \n for (const key in schema.properties) {\n const property = schema.properties[key];\n if (property.type === 'string') {\n if (property.enum) {\n fieldMap[key] = { type: 'select', options: property.enum.map((v: string) => ({ value: v, name: v })) };\n } else if (property.format === 'date-time') {\n fieldMap[key] = { type: 'date' };\n } else if (property.format === 'binary') {\n fieldMap[key] = { type: 'file' };\n } else {\n fieldMap[key] = { type: 'text' };\n }\n } else if (property.type === 'object') {\n const childFieldMap = buildFormFieldMapByJsonSchema(property, options);\n for (const childKey in childFieldMap) {\n fieldMap[`${key}.${childKey}`] = childFieldMap[childKey];\n }\n } else if (property.type === 'array') {\n const childFieldMap = buildFormFieldMapByJsonSchema(property.items, options);\n for (const childKey in childFieldMap) {\n // TODO: 正規表現でパスマッチを判定できるようにする。\n fieldMap[`${key}.\\\\d+.${childKey}`] = childFieldMap[childKey];\n }\n } else {\n fieldMap[key] = { type: property.type };\n }\n // const type = ? 'date' : property.type;\n }\n\n console.debug('[buildFormFieldMapByJsonSchema] fieldMap:', fieldMap);\n\n return merge(fieldMap, options.merge);\n}\n\nexport function buildFormByJsonSchema(schema: JsonSchema, {\n fb = inject(FormBuilder).nonNullable,\n value = {},\n fieldMap = {},\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object,\n fieldMap?: object,\n} = {}): any {\n return {\n form: buildFormGroupByJsonSchema(schema, {fb, value}),\n fieldMap: buildFormFieldMapByJsonSchema(schema, {merge: fieldMap}),\n };\n}\n\nexport function buildFormGroup(klass: new() => any, {\n fb = inject(FormBuilder).nonNullable,\n value,\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object,\n}): FormGroup {\n const schema = targetConstructorToSchema(klass);\n return buildFormGroupByJsonSchema(schema, {fb, value});\n}\n\n\nexport function buildFormFieldMap(klass: new() => any, options: {\n merge?: { [key: string]: any },\n}): any {\n const schema = targetConstructorToSchema(klass);\n const map = buildFormFieldMapByJsonSchema(schema, options);\n return merge(map, options.merge);\n}\n\nexport function buildForm(klass: new() => any, {\n fb = inject(FormBuilder).nonNullable,\n value = {},\n fieldMap = {},\n}: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object,\n fieldMap?: object,\n} = {}): any {\n const schema = targetConstructorToSchema(klass);\n return {\n form: buildFormGroupByJsonSchema(schema, {fb, value}),\n fieldMap: buildFormFieldMapByJsonSchema(schema, {merge: fieldMap}),\n };\n}\n\n\n@Injectable({ providedIn: 'root' })\nexport class JsonSchemaFormService {\n private fb = inject(FormBuilder).nonNullable;\n\n build(schema: JsonSchema, {\n fb = this.fb,\n value = {},\n }: {\n fb?: FormBuilder | NonNullableFormBuilder,\n value?: object,\n } = {}): FormGroup {\n return buildFormGroupByJsonSchema(schema, {fb, value});\n }\n\n buildFieldMap(\n schema: JsonSchema,\n options: {\n merge?: { [key: string]: any },\n } = {},\n ): any {\n return buildFormFieldMapByJsonSchema(schema, options);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["_targetConstructorToSchema"],"mappings":";;;;;;;;AASA,SAAS,WAAW,CAAC,MAAc,EAAE,QAAgB,EAAA;IACnD,OAAO,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAC7D,CAAC;AAED,SAAS,cAAc,CACrB,IAAS,EACT,OAAY,EAAA;AAEZ,IAAA,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;AAC9B,QAAA,IACE,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS;AACnC,YAAA,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,EACnC;AACA,YAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CA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U,QAAA,IAAA,CAAA,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC;AAoB9C,KAAA;AAlBC,IAAA,KAAK,CAAC,MAAkB,EAAE,EACxB,EAAE,GAAG,IAAI,CAAC,EAAE,EACZ,KAAK,GAAG,EAAE,MAIR,EAAE,EAAA;QACJ,OAAO,0BAA0B,CAAC,MAAM,EAAE,EAAC,EAAE,EAAE,KAAK,EAAC,CAAC,CAAC;KACxD;AAED,IAAA,aAAa,CACX,MAAkB,EAClB,OAAA,GAEI,EAAE,EAAA;AAEN,QAAA,OAAO,6BAA6B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACvD;8GApBU,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAArB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cADR,MAAM,EAAA,CAAA,CAAA,EAAA;;2FACnB,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBADjC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;AChLlC;;AAEG;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, inject, Injector, runInInjectionContext, Injectable } from '@angular/core';
|
|
3
3
|
|
|
4
|
-
const STORE_INITIALIZER = new InjectionToken('[@ng-atomic/
|
|
4
|
+
const STORE_INITIALIZER = new InjectionToken('[@ng-atomic/common/pages/form] StoreInitializer');
|
|
5
5
|
function provideStoreInitializer(key, initializer) {
|
|
6
6
|
return [
|
|
7
7
|
{ provide: STORE_INITIALIZER, useValue: { key, initializer }, multi: true },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-atomic-common-services-initializer.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/initializer/initializer.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/initializer/ng-atomic-common-services-initializer.ts"],"sourcesContent":["import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\nimport { InjectionToken } from \"@angular/core\";\n\ntype StoreInitializer<S> = (store: S) => Promise<void> | void;\n\ninterface StoreInitializerEntry<S> {\n key: { new(): S };\n initializer: StoreInitializer<S>;\n}\n\nconst STORE_INITIALIZER = new InjectionToken<StoreInitializer<any>>('[@ng-atomic/
|
|
1
|
+
{"version":3,"file":"ng-atomic-common-services-initializer.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/initializer/initializer.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/initializer/ng-atomic-common-services-initializer.ts"],"sourcesContent":["import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\nimport { InjectionToken } from \"@angular/core\";\n\ntype StoreInitializer<S> = (store: S) => Promise<void> | void;\n\ninterface StoreInitializerEntry<S> {\n key: { new(): S };\n initializer: StoreInitializer<S>;\n}\n\nconst STORE_INITIALIZER = new InjectionToken<StoreInitializer<any>>('[@ng-atomic/common/pages/form] StoreInitializer');\n\nfunction provideStoreInitializer<S>(key: {new(): S}, initializer: StoreInitializer<S>) {\n return [\n { provide: STORE_INITIALIZER, useValue: { key, initializer}, multi: true },\n ];\n}\n\nfunction injectInitializerEntries<S>(): StoreInitializerEntry<S>[] {\n return inject<StoreInitializerEntry<S>[]>(STORE_INITIALIZER, {optional: true}) ?? [];\n}\n\nfunction injectStoreInitializers<S>(key: {new(): S}): StoreInitializer<S>[] {\n const entries = injectInitializerEntries<S>();\n return entries.filter(entry => entry.key === key).map(entry => entry.initializer);\n}\n\nexport function makeInitializerConfig<S>(klass: {new(): S}) {\n return {\n provide<SI extends StoreInitializer<S>>(initializer: SI) {\n return provideStoreInitializer(klass, initializer);\n },\n inject(): StoreInitializer<S>[] {\n return injectStoreInitializers(klass);\n },\n async initializeStore(store: S) {\n const injector = inject(Injector);\n const initializers = injectStoreInitializers(klass);\n for (const initializer of initializers) {\n await runInInjectionContext(injector, () => initializer(store));\n }\n },\n }\n}\n\n@Injectable({\n providedIn: 'root'\n})\nexport class InitializerService {\n\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAUA,MAAM,iBAAiB,GAAG,IAAI,cAAc,CAAwB,iDAAiD,CAAC,CAAC;AAEvH,SAAS,uBAAuB,CAAI,GAAe,EAAE,WAAgC,EAAA;IACnF,OAAO;AACL,QAAA,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,WAAW,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE;KAC3E,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,GAAA;AAC/B,IAAA,OAAO,MAAM,CAA6B,iBAAiB,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,IAAI,EAAE,CAAC;AACvF,CAAC;AAED,SAAS,uBAAuB,CAAI,GAAe,EAAA;AACjD,IAAA,MAAM,OAAO,GAAG,wBAAwB,EAAK,CAAC;IAC9C,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;AACpF,CAAC;AAEK,SAAU,qBAAqB,CAAI,KAAiB,EAAA;IACxD,OAAO;AACL,QAAA,OAAO,CAAiC,WAAe,EAAA;AACrD,YAAA,OAAO,uBAAuB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;SACpD;QACD,MAAM,GAAA;AACJ,YAAA,OAAO,uBAAuB,CAAC,KAAK,CAAC,CAAC;SACvC;QACD,MAAM,eAAe,CAAC,KAAQ,EAAA;AAC5B,YAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClC,YAAA,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;AACpD,YAAA,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;AACtC,gBAAA,MAAM,qBAAqB,CAAC,QAAQ,EAAE,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;aACjE;SACF;KACF,CAAA;AACH,CAAC;MAKY,kBAAkB,CAAA;8GAAlB,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAAlB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cAFjB,MAAM,EAAA,CAAA,CAAA,EAAA;;2FAEP,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA,CAAA;;;AC/CD;;AAEG;;;;"}
|
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable } from '@angular/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { signal, effect, computed, Injectable } from '@angular/core';
|
|
3
|
+
import { toObservable } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { get, set, unset } from 'lodash-es';
|
|
5
|
+
import { of } from 'rxjs';
|
|
6
|
+
import { tap, switchMap } from 'rxjs/operators';
|
|
6
7
|
|
|
7
8
|
class LoadingService {
|
|
8
9
|
constructor() {
|
|
9
|
-
this.
|
|
10
|
-
this.loadingMap$ = this.
|
|
11
|
-
this.
|
|
12
|
-
this.isLoading$ = this.
|
|
13
|
-
this.
|
|
10
|
+
this.loadingMap = signal({});
|
|
11
|
+
this.loadingMap$ = toObservable(this.loadingMap);
|
|
12
|
+
this.isLoading = this.getIsLoading();
|
|
13
|
+
this.isLoading$ = toObservable(this.isLoading);
|
|
14
|
+
this.isProgress = (domain = 'progress') => this.getIsLoading(domain)();
|
|
15
|
+
effect(() => console.info('LoadingService.loadingMap:', this.loadingMap()));
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
return key;
|
|
18
|
-
}
|
|
19
|
-
end(key) {
|
|
20
|
-
this.loadingEntries$.next([key, false]);
|
|
17
|
+
getIsLoading(domain = 'default') {
|
|
18
|
+
return computed(() => Object.keys(get(this.loadingMap(), [domain], {}))?.length > 0);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
start(key = randomStr(16), domain = 'default') {
|
|
21
|
+
this.loadingMap.update((map) => ({ ...set(map, [domain, key], true) }));
|
|
22
|
+
return key;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.end(key);
|
|
24
|
+
end(key, domain = 'default') {
|
|
25
|
+
this.loadingMap.update((map) => ({ ...(unset(map, [domain, key]), map) }));
|
|
29
26
|
}
|
|
30
|
-
async await(callback) {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
27
|
+
async await(callback, domain = 'default', key = randomStr(16)) {
|
|
28
|
+
this.start(key, domain);
|
|
29
|
+
const wrappedCallback = async () => await callback();
|
|
30
|
+
const res = await wrappedCallback().catch(error => { console.error(error); });
|
|
31
|
+
this.end(key, domain);
|
|
34
32
|
return res;
|
|
35
33
|
}
|
|
36
|
-
switchMap(project) {
|
|
37
|
-
|
|
38
|
-
return (source) => source.pipe(tap(() => this.start(key)), switchMap(project), tap(() => this.end(key)));
|
|
34
|
+
switchMap(project, domain = 'default', key = randomStr(16)) {
|
|
35
|
+
return (source) => source.pipe(tap(() => this.start(key, domain)), switchMap(project), tap(() => this.end(key, domain)));
|
|
39
36
|
}
|
|
40
37
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: LoadingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
41
38
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.2", ngImport: i0, type: LoadingService, providedIn: 'root' }); }
|
|
@@ -45,7 +42,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.2", ngImpor
|
|
|
45
42
|
args: [{
|
|
46
43
|
providedIn: 'root',
|
|
47
44
|
}]
|
|
48
|
-
}] });
|
|
45
|
+
}], ctorParameters: () => [] });
|
|
49
46
|
class NoopLoadingService extends LoadingService {
|
|
50
47
|
constructor() {
|
|
51
48
|
super(...arguments);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-atomic-common-services-loading.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/loading/loading.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/loading/ng-atomic-common-services-loading.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport {
|
|
1
|
+
{"version":3,"file":"ng-atomic-common-services-loading.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/loading/loading.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/loading/ng-atomic-common-services-loading.ts"],"sourcesContent":["import { computed, effect, Injectable, Signal, signal } from '@angular/core';\nimport { toObservable } from '@angular/core/rxjs-interop';\nimport { set, unset, get } from 'lodash-es';\nimport { ObservableInput, ObservedValueOf, OperatorFunction, of } from 'rxjs';\nimport { tap, switchMap } from 'rxjs/operators';\n\ntype LoadingMap = Record<string, Record<string, boolean>>;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class LoadingService {\n readonly loadingMap = signal<LoadingMap>({})\n readonly loadingMap$ = toObservable(this.loadingMap);\n readonly isLoading = this.getIsLoading();\n readonly isLoading$ = toObservable(this.isLoading);\n readonly isProgress = (domain = 'progress') => this.getIsLoading(domain)();\n\n constructor() {\n effect(() => console.info('LoadingService.loadingMap:', this.loadingMap()));\n }\n\n getIsLoading(domain = 'default'): Signal<boolean> {\n return computed(() => Object.keys(get(this.loadingMap(), [domain], {}))?.length > 0);\n }\n\n start(key: string = randomStr(16), domain = 'default'): string {\n this.loadingMap.update((map) => ({...set(map, [domain, key], true)}));\n return key;\n }\n\n end(key: string, domain = 'default'): void {\n this.loadingMap.update((map) => ({...(unset(map, [domain, key]), map)}));\n }\n\n async await<T = any>(\n callback: (...args: any[]) => Promise<T | void> | (T | void),\n domain = 'default',\n key = randomStr(16),\n ): Promise<T | void> {\n this.start(key, domain);\n const wrappedCallback = async () => await callback();\n const res = await wrappedCallback().catch(error => {console.error(error);});\n this.end(key, domain);\n return res;\n }\n\n switchMap<T, O extends ObservableInput<any>>(\n project: (value: T, index: number) => O,\n domain = 'default',\n key = randomStr(16),\n ): OperatorFunction<T, ObservedValueOf<O>> {\n return (source) => source.pipe(\n tap(() => this.start(key, domain)),\n switchMap(project),\n tap(() => this.end(key, domain)),\n );\n }\n}\n\n@Injectable()\nexport class NoopLoadingService extends LoadingService {\n readonly isLoading$ = of(false);\n}\n\nexport function provideNoopLoadingService() {\n return { provide: LoadingService, useClass: NoopLoadingService };\n}\n\nexport function randomStr(n = 16): string {\n return Math.random().toString(36).substr(2, n);\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAWa,cAAc,CAAA;AAOzB,IAAA,WAAA,GAAA;AANS,QAAA,IAAA,CAAA,UAAU,GAAG,MAAM,CAAa,EAAE,CAAC,CAAA;AACnC,QAAA,IAAA,CAAA,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC5C,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;AAChC,QAAA,IAAA,CAAA,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,SA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EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;kHAAlB,kBAAkB,EAAA,CAAA,CAAA,EAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAD9B,UAAU;;SAKK,yBAAyB,GAAA;IACvC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;AACnE,CAAC;AAEe,SAAA,SAAS,CAAC,CAAC,GAAG,EAAE,EAAA;AAC9B,IAAA,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACjD;;ACvEA;;AAEG;;;;"}
|
|
@@ -82,6 +82,8 @@ class RootPropertyService {
|
|
|
82
82
|
'--loading-primary-color': 'var(--accent-color)',
|
|
83
83
|
'--background-primary-color': 'var(--primary-color)',
|
|
84
84
|
'--background-on-primary-color': 'var(--on-primary-color)',
|
|
85
|
+
'--table-background-color': 'var(--background-color)',
|
|
86
|
+
'--table-on-background-color': 'var(--on-background-color)',
|
|
85
87
|
'--selection-color': 'var(--background-color)',
|
|
86
88
|
'--selection-background-color': 'var(--on-background-color)',
|
|
87
89
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-atomic-common-services-root-property.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/root-property/root-property.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/root-property/root-property.di.ts","../../../../../packages/@ng-atomic/common/src/lib/services/root-property/ng-atomic-common-services-root-property.ts"],"sourcesContent":["import { isPlatformBrowser, isPlatformServer } from '@angular/common';\nimport { Directive, ElementRef, Injectable, PLATFORM_ID, effect, inject } from '@angular/core';\nimport { toObservable } from '@angular/core/rxjs-interop';\nimport { makeConfig, UIContext } from '@ng-atomic/common/services/ui';\nimport { MaterialCssVarsService } from 'angular-material-css-vars';\nimport { Observable, delay, filter, map, of } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class RootPropertyService {\n static readonly Config = makeConfig(() => {\n return (context) => {\n switch (context.breakpoint) {\n case 'xSmall': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '100vw',\n '--page-width-lv2': '100vw',\n '--page-width-lv3': '100vw',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'small':\n case 'medium': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '64px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw, 1600px) - 360px - var(--menu-width)), 360px)',\n '--page-width-lv3': 'max(calc(min(100vw, 1600px) - var(--menu-width)), 360px)',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'large': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw, 1600px) - var(--page-width-lv1) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv3': 'max(calc(min(100vw, 1600px) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'xLarge': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw) - var(--page-width-lv1) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv3': 'max(calc(min(100vw) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n }\n };\n }, ['root', 'properties']);\n static provideColorSchemaA() {\n return RootPropertyService.Config.provide(() => {\n return (config) => ({\n ...config,\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--accent-color': '#d8ab12',\n '--background-color': '#ffffff',\n '--on-background-color': '#404040',\n '--menu-background-color': '#404040',\n '--menu-on-background-color': '#f0f0f0',\n '--navigator-background-color': '#404040',\n '--navigator-on-background-color': '#f0f0f0',\n '--loading-primary-color': 'var(--accent-color)',\n '--background-primary-color': 'var(--primary-color)',\n '--background-on-primary-color': 'var(--on-primary-color)',\n '--selection-color': 'var(--background-color)',\n '--selection-background-color': 'var(--on-background-color)',\n });\n });\n }\n\n static provideColorSchema1 = RootPropertyService.provideColorSchemaA;\n static provideMenuWidthForIconButtonMenu() {\n return RootPropertyService.Config.provide(() => {\n const getMenuWidth = (context: UIContext) => {\n switch (context.breakpoint) {\n case 'xSmall': return '220px';\n case 'small':\n case 'medium':\n case 'large':\n case 'xLarge': return '64px';\n }\n }\n return (config, context) => ({\n ...config,\n '--menu-width': getMenuWidth(context),\n });\n });\n }\n\n readonly config = RootPropertyService.Config.inject();\n\n readonly platformId = inject(PLATFORM_ID);\n readonly matCssVar = inject(MaterialCssVarsService);\n\n constructor() {\n effect(() => {\n if (isPlatformBrowser(this.platformId)) {\n for (const [key, value] of Object.entries(this.config?.() ?? {})) {\n document.documentElement.style.setProperty(key, value);\n }\n }\n this.matCssVar.setPrimaryColor(this.config()['--primary-color']);\n this.matCssVar.setAccentColor(this.config()['--accent-color']);\n this.matCssVar.setWarnColor(this.config()['--warn-color']);\n this.matCssVar.setDarkTheme(false);\n });\n }\n}\n\n@Directive({ standalone: true, selector: '[atomicStyle]' })\nexport class NgAtomicStyleDirective {\n readonly #el = inject(ElementRef);\n readonly platformId = inject(PLATFORM_ID);\n\n constructor(private rootPropertyService: RootPropertyService) {\n effect(() => {\n for (const [key, value] of Object.entries(this.rootPropertyService.config?.() ?? {})) {\n this.#el.nativeElement.style.setProperty(key, value);\n }\n });\n }\n}\n\n@Injectable({providedIn: 'root'})\nexport class RootPropertyGuard {\n\treadonly properties = RootPropertyService.Config.inject();\n\treadonly properties$ = toObservable(this.properties);\n\treadonly platformId = inject(PLATFORM_ID);\n\n\tcanActivate(): Observable<boolean> {\n\t\tif (isPlatformServer(this.platformId)) return of(null);\t\n\t\treturn this.properties$.pipe(\n\t\t\tfilter(properties => properties['--background-color'] === '#f0f0f0'),\n\t\t\tdelay(500),\n\t\t\tmap(() => true),\n\t\t);\n\t}\n}\n","import { ENVIRONMENT_INITIALIZER, inject } from \"@angular/core\";\nimport { provideMaterialCssVars } from \"angular-material-css-vars\";\nimport { RootPropertyService } from \"./root-property.service\";\n\nexport function provideRootProperty() {\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n useFactory: () => () => inject(RootPropertyService),\n multi: true,\n },\n provideMaterialCssVars({}),\n RootPropertyService.provideColorSchemaA(),\n ]\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAQa,mBAAmB,CAAA;AACd,IAAA,SAAA,IAAA,CAAA,MAAM,GAAG,UAAU,CAAC,MAAK;QACvC,OAAO,CAAC,OAAO,KAAI;AACjB,YAAA,QAAQ,OAAO,CAAC,UAAU;gBACxB,KAAK,QAAQ,EAAE,OAAO;AACpB,oBAAA,iBAAiB,EAAE,SAAS;AAC5B,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,iBAAiB,EAAE,MAAM;AACzB,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,oBAAoB,EAAE,MAAM;AAC5B,oBAAA,cAAc,EAAE,OAAO;AACvB,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,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AE,MAAM,EAAC,CAAA;;;SC3IhB,mBAAmB,GAAA;IACjC,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,uBAAuB;YAChC,UAAU,EAAE,MAAM,MAAM,MAAM,CAAC,mBAAmB,CAAC;AACnD,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;QACD,sBAAsB,CAAC,EAAE,CAAC;QAC1B,mBAAmB,CAAC,mBAAmB,EAAE;KAC1C,CAAA;AACH;;ACdA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-atomic-common-services-root-property.mjs","sources":["../../../../../packages/@ng-atomic/common/src/lib/services/root-property/root-property.service.ts","../../../../../packages/@ng-atomic/common/src/lib/services/root-property/root-property.di.ts","../../../../../packages/@ng-atomic/common/src/lib/services/root-property/ng-atomic-common-services-root-property.ts"],"sourcesContent":["import { isPlatformBrowser, isPlatformServer } from '@angular/common';\nimport { Directive, ElementRef, Injectable, PLATFORM_ID, effect, inject } from '@angular/core';\nimport { toObservable } from '@angular/core/rxjs-interop';\nimport { makeConfig, UIContext } from '@ng-atomic/common/services/ui';\nimport { MaterialCssVarsService } from 'angular-material-css-vars';\nimport { Observable, delay, filter, map, of } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class RootPropertyService {\n static readonly Config = makeConfig(() => {\n return (context) => {\n switch (context.breakpoint) {\n case 'xSmall': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '100vw',\n '--page-width-lv2': '100vw',\n '--page-width-lv3': '100vw',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'small':\n case 'medium': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '64px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw, 1600px) - 360px - var(--menu-width)), 360px)',\n '--page-width-lv3': 'max(calc(min(100vw, 1600px) - var(--menu-width)), 360px)',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'large': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw, 1600px) - var(--page-width-lv1) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv3': 'max(calc(min(100vw, 1600px) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n case 'xLarge': return {\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--surface-color': '#fff',\n '--on-surface-color': '#404040',\n '--background-color': '#fff',\n '--menu-width': '220px',\n '--page-width-lv1': '360px',\n '--page-width-lv2': 'max(calc(min(100vw) - var(--page-width-lv1) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv3': 'max(calc(min(100vw) - var(--menu-width)), var(--page-width-lv1))',\n '--page-width-lv4': '100vw',\n '--page-height-lv1': '100vh',\n };\n }\n };\n }, ['root', 'properties']);\n static provideColorSchemaA() {\n return RootPropertyService.Config.provide(() => {\n return (config) => ({\n ...config,\n '--primary-color': '#404040',\n '--on-primary-color': '#f0f0f0',\n '--accent-color': '#d8ab12',\n '--background-color': '#ffffff',\n '--on-background-color': '#404040',\n '--menu-background-color': '#404040',\n '--menu-on-background-color': '#f0f0f0',\n '--navigator-background-color': '#404040',\n '--navigator-on-background-color': '#f0f0f0',\n '--loading-primary-color': 'var(--accent-color)',\n '--background-primary-color': 'var(--primary-color)',\n '--background-on-primary-color': 'var(--on-primary-color)',\n '--table-background-color': 'var(--background-color)',\n '--table-on-background-color': 'var(--on-background-color)',\n '--selection-color': 'var(--background-color)',\n '--selection-background-color': 'var(--on-background-color)',\n });\n });\n }\n\n static provideColorSchema1 = RootPropertyService.provideColorSchemaA;\n static provideMenuWidthForIconButtonMenu() {\n return RootPropertyService.Config.provide(() => {\n const getMenuWidth = (context: UIContext) => {\n switch (context.breakpoint) {\n case 'xSmall': return '220px';\n case 'small':\n case 'medium':\n case 'large':\n case 'xLarge': return '64px';\n }\n }\n return (config, context) => ({\n ...config,\n '--menu-width': getMenuWidth(context),\n });\n });\n }\n\n readonly config = RootPropertyService.Config.inject();\n\n readonly platformId = inject(PLATFORM_ID);\n readonly matCssVar = inject(MaterialCssVarsService);\n\n constructor() {\n effect(() => {\n if (isPlatformBrowser(this.platformId)) {\n for (const [key, value] of Object.entries(this.config?.() ?? {})) {\n document.documentElement.style.setProperty(key, value);\n }\n }\n this.matCssVar.setPrimaryColor(this.config()['--primary-color']);\n this.matCssVar.setAccentColor(this.config()['--accent-color']);\n this.matCssVar.setWarnColor(this.config()['--warn-color']);\n this.matCssVar.setDarkTheme(false);\n });\n }\n}\n\n@Directive({ standalone: true, selector: '[atomicStyle]' })\nexport class NgAtomicStyleDirective {\n readonly #el = inject(ElementRef);\n readonly platformId = inject(PLATFORM_ID);\n\n constructor(private rootPropertyService: RootPropertyService) {\n effect(() => {\n for (const [key, value] of Object.entries(this.rootPropertyService.config?.() ?? {})) {\n this.#el.nativeElement.style.setProperty(key, value);\n }\n });\n }\n}\n\n@Injectable({providedIn: 'root'})\nexport class RootPropertyGuard {\n\treadonly properties = RootPropertyService.Config.inject();\n\treadonly properties$ = toObservable(this.properties);\n\treadonly platformId = inject(PLATFORM_ID);\n\n\tcanActivate(): Observable<boolean> {\n\t\tif (isPlatformServer(this.platformId)) return of(null);\t\n\t\treturn this.properties$.pipe(\n\t\t\tfilter(properties => properties['--background-color'] === '#f0f0f0'),\n\t\t\tdelay(500),\n\t\t\tmap(() => true),\n\t\t);\n\t}\n}\n","import { ENVIRONMENT_INITIALIZER, inject } from \"@angular/core\";\nimport { provideMaterialCssVars } from \"angular-material-css-vars\";\nimport { RootPropertyService } from \"./root-property.service\";\n\nexport function provideRootProperty() {\n return [\n {\n provide: ENVIRONMENT_INITIALIZER,\n useFactory: () => () => inject(RootPropertyService),\n multi: true,\n },\n provideMaterialCssVars({}),\n RootPropertyService.provideColorSchemaA(),\n ]\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAQa,mBAAmB,CAAA;AACd,IAAA,SAAA,IAAA,CAAA,MAAM,GAAG,UAAU,CAAC,MAAK;QACvC,OAAO,CAAC,OAAO,KAAI;AACjB,YAAA,QAAQ,OAAO,CAAC,UAAU;gBACxB,KAAK,QAAQ,EAAE,OAAO;AACpB,oBAAA,iBAAiB,EAAE,SAAS;AAC5B,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,iBAAiB,EAAE,MAAM;AACzB,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,oBAAoB,EAAE,MAAM;AAC5B,oBAAA,cAAc,EAAE,OAAO;AACvB,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,mBAAmB,EAAE,OAAO;iBAC7B,CAAC;AACF,gBAAA,KAAK,OAAO,CAAC;gBACb,KAAK,QAAQ,EAAE,OAAO;AACpB,oBAAA,iBAAiB,EAAE,SAAS;AAC5B,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,iBAAiB,EAAE,MAAM;AACzB,oBAAA,oBAAoB,EAAE,SAAS;AAC/B,oBAAA,oBAAoB,EAAE,MAAM;AAC5B,oBAAA,cAAc,EAAE,MAAM;AACtB,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,oBAAA,kBAAkB,EAAE,kEAAkE;AACtF,oBAAA,kBAAkB,EAAE,0DAA0D;AAC9E,oBAAA,kBAAkB,EAAE,OAAO;AAC3B,o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