@ng-formworks/material 15.2.7

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.
Files changed (44) hide show
  1. package/README.md +133 -0
  2. package/assets/material-design-themes.scss +71 -0
  3. package/karma.conf.js +46 -0
  4. package/ng-package.json +13 -0
  5. package/package.json +49 -0
  6. package/src/lib/flexlayout-replacement-styles.scss +95 -0
  7. package/src/lib/material-design-cssframework.ts +20 -0
  8. package/src/lib/material-design-framework.component.html +13 -0
  9. package/src/lib/material-design-framework.component.scss +58 -0
  10. package/src/lib/material-design-framework.component.spec.ts +39 -0
  11. package/src/lib/material-design-framework.component.ts +143 -0
  12. package/src/lib/material-design-framework.module.ts +81 -0
  13. package/src/lib/material-design-themes.scss +71 -0
  14. package/src/lib/material-design.framework.ts +83 -0
  15. package/src/lib/tailwind-output.scss +622 -0
  16. package/src/lib/widgets/flex-layout-root.component.html +4 -0
  17. package/src/lib/widgets/flex-layout-root.component.ts +52 -0
  18. package/src/lib/widgets/flex-layout-section.component.ts +216 -0
  19. package/src/lib/widgets/material-add-reference.component.ts +56 -0
  20. package/src/lib/widgets/material-button-group.component.ts +68 -0
  21. package/src/lib/widgets/material-button.component.ts +66 -0
  22. package/src/lib/widgets/material-checkbox.component.ts +112 -0
  23. package/src/lib/widgets/material-checkboxes.component.ts +108 -0
  24. package/src/lib/widgets/material-chip-list.component.ts +35 -0
  25. package/src/lib/widgets/material-datepicker.component.ts +89 -0
  26. package/src/lib/widgets/material-file.component.ts +35 -0
  27. package/src/lib/widgets/material-input.component.ts +97 -0
  28. package/src/lib/widgets/material-number.component.ts +95 -0
  29. package/src/lib/widgets/material-one-of.component.ts +35 -0
  30. package/src/lib/widgets/material-radios.component.ts +91 -0
  31. package/src/lib/widgets/material-select.component.ts +118 -0
  32. package/src/lib/widgets/material-slider.component.ts +65 -0
  33. package/src/lib/widgets/material-stepper.component.ts +35 -0
  34. package/src/lib/widgets/material-tabs.component.ts +72 -0
  35. package/src/lib/widgets/material-textarea.component.ts +88 -0
  36. package/src/lib/widgets/public_api.ts +54 -0
  37. package/src/public_api.ts +9 -0
  38. package/src/test.ts +17 -0
  39. package/tailwind-input.css +3 -0
  40. package/tailwind.config.js +12 -0
  41. package/tsconfig.lib.json +25 -0
  42. package/tsconfig.lib.prod.json +9 -0
  43. package/tsconfig.spec.json +17 -0
  44. package/tslint.json +11 -0
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @ng-formworks/material
2
+
3
+ This module is a dependency of the [ng-formworks project][npm_core_ver] and is meant to work as a framework installation module for using Angular Material Design in the forms.
4
+
5
+ ## Getting started
6
+
7
+ If you are unfamiliar with with the ng-formworks project, it is highly recommended to
8
+ first have a look at the [@ng-formworks pages][npm_core_ver] for examples, demos, options and documentation.
9
+
10
+ ```shell
11
+ npm install @ng-formworks/core@latest @ng-formworks/cssframework@latest @ng-formworks/material@latest
12
+ ```
13
+
14
+ With YARN, run the following:
15
+
16
+ ```shell
17
+ yarn add @ng-formworks/core@latest @ng-formworks/cssframework@latest @ng-formworks/material@latest
18
+ ```
19
+
20
+ include the themes scss in your applications sass file(typically "styles.scss" under "src" folder -see angular docs for more details)
21
+ ```scss
22
+ @import "node_modules/@ng-formworks/material/assets/material-design-themes.scss";
23
+ ```
24
+
25
+ Then import `MaterialDesignFrameworkModule` in your main application module if you want to use `material-angular` UI, like this:
26
+
27
+ ```javascript
28
+ import { BrowserModule } from '@angular/platform-browser';
29
+ import { NgModule } from '@angular/core';
30
+
31
+ import { MaterialDesignFrameworkModule } from '@ng-formworks/material';
32
+
33
+ import { AppComponent } from './app.component';
34
+
35
+ @NgModule({
36
+ declarations: [ AppComponent ],
37
+ imports: [
38
+ MaterialDesignFrameworkModule
39
+ ],
40
+ providers: [],
41
+ bootstrap: [ AppComponent ]
42
+ })
43
+ export class AppModule { }
44
+ ```
45
+
46
+ For basic use, after loading JsonSchemaFormModule as described above, to display a form in your Angular component, simply add the following to your component's template:
47
+
48
+ ```html
49
+ <json-schema-form
50
+ loadExternalAssets="true"
51
+ [schema]="yourJsonSchema"
52
+ framework="material-design"
53
+ [theme]="yourTheme"
54
+ (onSubmit)="yourOnSubmitFn($event)">
55
+ </json-schema-form>
56
+ ```
57
+
58
+ Where `schema` is a valid JSON schema object, and `onSubmit` calls a function to process the submitted JSON form data. If you don't already have your own schemas, you can find a bunch of samples to test with in the `demo/assets/example-schemas` folder, as described above.
59
+
60
+ `framework` is for the template you want to use, the default value is `no-framwork`. The possible values are:
61
+
62
+
63
+ * `material-design` for Material Design.
64
+ * `bootstrap-3` for Bootstrap 3 (if installed).
65
+ * `bootstrap-4` for Bootstrap 4 (if installed).
66
+ * `bootstrap-5` for Bootstrap 5.(if installed).
67
+ * `daisyui` for DaisyUi (if installed).
68
+ * `no-framework` for (plain HTML).
69
+
70
+ `theme` is for the framework theme you want to use.
71
+ The possible values for this framework are:
72
+
73
+ * `material_default` for the default theme.
74
+ * `indigo-pink` for the indigo & pink theme.
75
+ * `purple-green` for the purple & green theme.
76
+ * `deeppurple-amber` for the deep purple & amber theme.
77
+ * `pink-bluegrey` for the pink & blue-grey theme.
78
+
79
+ the list of available themes can also be gotten using the
80
+ FrameworkLibraryService(found in '@ng-formworks/core'):
81
+ ```typescript
82
+ getFrameworkThemes()
83
+ ```
84
+ method
85
+
86
+ ## Custom theming
87
+
88
+ Custom theming can be achieved in the following way:
89
+
90
+ Adding a new theme:
91
+ the first step will be to create the entire theme (see the specific frameworks underlying documentation for how this can be done), then add the theme as
92
+ a css class
93
+
94
+ ```sass
95
+ .material_custom {
96
+ @include mat.core-color($custom-pink-theme);
97
+ @include mat.all-component-colors($custom-pink-theme);
98
+ @include mat.button-color($custom-pink-theme);
99
+ }
100
+
101
+ ```
102
+ after making the css available, the theme will need to be registered using the
103
+ FrameworkLibraryService(found in '@ng-formworks/core'):
104
+ for example
105
+
106
+ ```typescript
107
+ constructor(
108
+ .
109
+ private frameworkLibrary: FrameworkLibraryService,
110
+ .
111
+ .
112
+ ) {
113
+
114
+ frameworkLibrary.registerTheme({name:'material_custom',text:'Material custom theme'})
115
+
116
+ }
117
+
118
+ ```
119
+
120
+ ## Code scaffolding
121
+
122
+ Run `ng generate component component-name --project @ng-formworks/material` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project @ng-formworks/material`.
123
+ > Note: Don't forget to add `--project @ng-formworks/material` or else it will be added to the default project in your `angular.json` file.
124
+
125
+ ## Build
126
+
127
+ Run `ng build @ng-formworks/material` to build the project. The build artifacts will be stored in the `dist/` directory.
128
+
129
+ ## Running unit tests
130
+
131
+ Run `ng test @ng-formworks/material` to execute the unit tests via [Karma](https://karma-runner.github.io).
132
+
133
+ [npm_core_ver]:https://www.npmjs.com/package/@ng-formworks/core
@@ -0,0 +1,71 @@
1
+ /* see https://material.angular.io/guide/theming */
2
+
3
+ @use '@angular/material' as mat;
4
+ @include mat.core();
5
+ $indigo-primary: mat.define-palette(mat.$indigo-palette, 500);
6
+ $green-accent: mat.define-palette(mat.$green-palette, A200, A100, A400);
7
+ $red-warn: mat.define-palette(mat.$red-palette);
8
+ $pink-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
9
+ $deep-purple-primary: mat.define-palette(mat.$deep-purple-palette, 500);
10
+ $amber-accent: mat.define-palette(mat.$amber-palette, A200, A100, A400);
11
+ $pink-primary: mat.define-palette(mat.$pink-palette, 500);
12
+ $bluegrey-accent: mat.define-palette(mat.$blue-grey-palette, A200, A100, A400);
13
+ $typography:mat.define-typography-config();
14
+ $density:0;
15
+
16
+ /*Palettes (primary, accent, warn)-indigo, pink, red */
17
+
18
+ $indigo-pink-primary: $indigo-primary;
19
+ $indigo-pink-accent: $pink-accent;
20
+ $indigo-pink-warn: $red-warn;
21
+ $indigo-pink-theme: mat.define-light-theme(( color: ( primary: $indigo-pink-primary, accent: $indigo-pink-accent, warn:$indigo-pink-warn), typography: $typography, density: $density));
22
+ .indigo-pink {
23
+ @include mat.core-theme($indigo-pink-theme);
24
+ @include mat.all-component-themes($indigo-pink-theme);
25
+ @include mat.button-color($indigo-pink-theme);
26
+ }
27
+
28
+
29
+ /*Palettes (primary, accent, warn)-purple, green, red */
30
+
31
+ $purple-green-primary: $indigo-primary;
32
+ $purple-green-accent: $green-accent;
33
+ $purple-green-warn: $red-warn;
34
+ $purple-green-theme: mat.define-dark-theme(( color: ( primary: $purple-green-primary, accent: $purple-green-accent, warn:$purple-green-warn)));
35
+ .purple-green {
36
+ @include mat.core-color($purple-green-theme);
37
+ @include mat.all-component-colors($purple-green-theme);
38
+ @include mat.button-color($purple-green-theme);
39
+ }
40
+
41
+
42
+ /*Palettes (primary, accent, warn)-deep-purple, amber, red */
43
+
44
+ $deeppurple-amber-primary: $deep-purple-primary;
45
+ $deeppurple-amber-accent: $amber-accent;
46
+ $deeppurple-amber-warn: $red-warn;
47
+ $deeppurple-amber-theme: mat.define-light-theme(( color: ( primary: $deeppurple-amber-primary, accent: $deeppurple-amber-accent, warn:$deeppurple-amber-warn)));
48
+ .deeppurple-amber {
49
+ @include mat.core-color($deeppurple-amber-theme);
50
+ @include mat.all-component-colors($deeppurple-amber-theme);
51
+ @include mat.button-color($deeppurple-amber-theme);
52
+ }
53
+
54
+
55
+ /*Palettes (primary, accent, warn)-pink, blue-grey, red */
56
+
57
+ $pink-bluegrey-primary: $pink-primary;
58
+ $pink-bluegrey-accent: $bluegrey-accent;
59
+ $pink-bluegrey-warn: $red-warn;
60
+ $pink-bluegrey-theme: mat.define-dark-theme(( color: ( primary: $pink-bluegrey-primary, accent: $pink-bluegrey-accent, warn:$pink-bluegrey-warn)));
61
+ .pink-bluegrey {
62
+ @include mat.core-color($pink-bluegrey-theme);
63
+ @include mat.all-component-colors($pink-bluegrey-theme);
64
+ @include mat.button-color($pink-bluegrey-theme);
65
+ }
66
+
67
+ .material_default {
68
+ @include mat.core-color($indigo-pink-theme);
69
+ @include mat.all-component-colors($indigo-pink-theme);
70
+ @include mat.button-color($indigo-pink-theme);
71
+ }
package/karma.conf.js ADDED
@@ -0,0 +1,46 @@
1
+ // Karma configuration file, see link for more information
2
+ // https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ basePath: '',
7
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+ plugins: [
9
+ require('karma-jasmine'),
10
+ require('karma-chrome-launcher'),
11
+ require('karma-jasmine-html-reporter'),
12
+ require('karma-coverage'),
13
+ require('@angular-devkit/build-angular/plugins/karma'),
14
+ ],
15
+ client: {
16
+ clearContext: false, // leave Jasmine Spec Runner output visible in browser
17
+ },
18
+ coverageReporter: {
19
+ dir: require('path').join(__dirname, '../../coverage/ajsf-material'),
20
+ reporters: [
21
+ {
22
+ type: 'html',
23
+ },
24
+ {
25
+ type: 'lcov',
26
+ },
27
+ {
28
+ type: 'text-summary',
29
+ },
30
+ ],
31
+ },
32
+ reporters: ['progress', 'kjhtml'],
33
+ port: 9876,
34
+ colors: true,
35
+ logLevel: config.LOG_INFO,
36
+ autoWatch: true,
37
+ singleRun: false,
38
+ browsers: ['Chrome', 'ChromeHeadlessCI'],
39
+ customLaunchers: {
40
+ ChromeHeadlessCI: {
41
+ base: 'ChromeHeadless',
42
+ flags: ['--no-sandbox'],
43
+ },
44
+ },
45
+ });
46
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/@ng-formworks/material",
4
+ "lib": {
5
+ "entryFile": "src/public_api.ts"
6
+ },
7
+ "assets": ["./assets"],
8
+ "allowedNonPeerDependencies": [
9
+ "lodash-es",
10
+ "@ng-formworks/core",
11
+ "@ng-formworks/cssframework"
12
+ ]
13
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ng-formworks/material",
3
+ "version": "15.2.7",
4
+ "description": "Angular ng-formworks - JSON Schema Form builder using Angular Material UI",
5
+ "author": "https://github.com/zahmo/ng-formworks/graphs/contributors",
6
+ "keywords": [
7
+ "Angular",
8
+ "ng",
9
+ "Angular15",
10
+ "Angular 15",
11
+ "Angular16",
12
+ "Angular 16",
13
+ "Angular17",
14
+ "Angular 17",
15
+ "ng15",
16
+ "ng16",
17
+ "ng17",
18
+ "JSON Schema",
19
+ "form",
20
+ "forms",
21
+ "form builder",
22
+ "form themes",
23
+ "material",
24
+ "angular material",
25
+ "material design",
26
+ "ajsf",
27
+ "ng-formworks",
28
+ "angular json schema form"
29
+ ],
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/zahmo/ng-formworks"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/zahmo/ng-formworks/issues"
37
+ },
38
+ "private": false,
39
+ "dependencies": {
40
+ "lodash-es": "~4.17.21",
41
+ "@ng-formworks/core": "~15.2.7",
42
+ "@ng-formworks/cssframework": "~15.2.7",
43
+ "tslib": "^2.0.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@angular/material": ">=15.0.0",
47
+ "@angular/cdk": ">=15.0.0"
48
+ }
49
+ }
@@ -0,0 +1,95 @@
1
+ /* style sheet created to help replace angular flex-layout package
2
+ which is out of maintenance
3
+ see-https://github.com/angular/flex-layout
4
+ adapted from
5
+ https://github.com/angular/flex-layout/issues/1433
6
+ https://github.com/angular/flex-layout/issues/1433#issue-1508899434
7
+ */
8
+
9
+ [fxLayout] {
10
+ box-sizing: border-box;
11
+ display: flex;
12
+ }
13
+
14
+ [fxLayout="row wrap"] {
15
+ flex-flow: row wrap;
16
+ }
17
+
18
+ [fxLayout="row"] {
19
+ flex-direction: row;
20
+ }
21
+
22
+ [fxLayout="column"] {
23
+ flex-direction: column;
24
+ }
25
+
26
+ [fxLayoutAlign="center center"] {
27
+ display: flex;
28
+ place-content: center;
29
+ align-items: center;
30
+ }
31
+
32
+ [fxLayoutAlign="start center"] {
33
+ display: flex;
34
+ place-content: center flex-start;
35
+ align-items: center;
36
+ }
37
+
38
+ [fxLayoutAlign="start start"] {
39
+ display: flex;
40
+ place-content: flex-start flex-start;
41
+ align-items: center;
42
+ }
43
+
44
+ [fxLayoutAlign="end center"] {
45
+ display: flex;
46
+ place-content: center flex-end;
47
+ align-items: center;
48
+ }
49
+
50
+ [fxFlex] {
51
+ box-sizing: border-box;
52
+ display: flex;
53
+ flex: 1 1 100%;
54
+ }
55
+
56
+ [fxFlex="none"] {
57
+ flex: none;
58
+ }
59
+
60
+ @media only screen and (min-width: 960px) {
61
+ [fxFlex-gt-sm="50"] {
62
+ flex: 1 1 50% !important;
63
+ box-sizing: border-box;
64
+ max-width: 50% !important;
65
+ }
66
+ [fxFlex-gt-sm="33"] {
67
+ flex: 1 1 33% !important;
68
+ box-sizing: border-box;
69
+ max-width: 33% !important;
70
+ }
71
+ }
72
+
73
+ [fxFlex="33"] {
74
+ flex: 1 1 33%;
75
+ box-sizing: border-box;
76
+ max-width: 33%;
77
+ }
78
+
79
+ [fxFlex="67"] {
80
+ flex: 1 1 67%;
81
+ box-sizing: border-box;
82
+ max-width: 67%;
83
+ }
84
+
85
+ @mixin flex {
86
+ @for $i from 0 through 20 {
87
+ [fxFlex="#{$i*5}"] {
88
+ flex: 1 1 $i*5%;
89
+ box-sizing: border-box;
90
+ max-width: $i*5%;
91
+ }
92
+ }
93
+ }
94
+
95
+ @include flex;
@@ -0,0 +1,20 @@
1
+
2
+ export const cssFrameworkCfgMaterialDesign:any={
3
+ "name": "material-design",
4
+ "text":"Material Design",
5
+ "scripts": [],
6
+ "stylesheets": [
7
+ '//fonts.googleapis.com/icon?family=Material+Icons',
8
+ '//fonts.googleapis.com/css?family=Roboto:300,400,500,700',
9
+ ],
10
+ "widgetstyles": {
11
+ "__themes__": [
12
+ {"name":"material_default","text":"Default Theme"},
13
+ {"name":"indigo-pink","text":"Indigo & Pink"},
14
+ {"name":"purple-green","text":"Purple & Green"},
15
+ {"name":"deeppurple-amber","text":"Deep Purple & Amber"},
16
+ {"name":"pink-bluegrey","text":"Pink & Blue-Grey"}
17
+ ]
18
+ }
19
+ }
20
+
@@ -0,0 +1,13 @@
1
+ <div [class]="theme">
2
+ <div class="mat-app-background">
3
+
4
+ <div [class.array-item]="widgetLayoutNode?.arrayItem && widgetLayoutNode?.type !== '$ref'" [orderable]="isOrderable" [dataIndex]="dataIndex" [layoutIndex]="layoutIndex" [layoutNode]="widgetLayoutNode">
5
+ <svg *ngIf="showRemoveButton" xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 24 24" class="close-button" (click)="removeItem()">
6
+ <path
7
+ d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"/>
8
+ </svg>
9
+ <select-widget-widget [dataIndex]="dataIndex" [layoutIndex]="layoutIndex" [layoutNode]="widgetLayoutNode"></select-widget-widget>
10
+ </div>
11
+ <div class="spacer" *ngIf="widgetLayoutNode?.arrayItem && widgetLayoutNode?.type !== '$ref'"></div>
12
+ </div>
13
+ </div>
@@ -0,0 +1,58 @@
1
+ .array-item {
2
+ border-radius: 2px;
3
+ box-shadow: 0 3px 1px -2px rgba(0, 0, 0, .2), 0 2px 2px 0 rgba(0, 0, 0, .14), 0 1px 5px 0 rgba(0, 0, 0, .12);
4
+ padding: 6px;
5
+ position: relative;
6
+ transition: all 280ms cubic-bezier(.4, 0, .2, 1);
7
+ }
8
+
9
+ .close-button {
10
+ cursor: pointer;
11
+ position: absolute;
12
+ top: 6px;
13
+ right: 6px;
14
+ fill: rgba(0, 0, 0, .4);
15
+ visibility: hidden;
16
+ z-index: 500;
17
+ }
18
+
19
+ .close-button:hover {
20
+ fill: rgba(0, 0, 0, .8);
21
+ }
22
+
23
+ .array-item:hover>.close-button {
24
+ visibility: visible;
25
+ }
26
+
27
+ .spacer {
28
+ margin: 6px 0;
29
+ }
30
+
31
+ [draggable=true]:hover {
32
+ box-shadow: 0 5px 5px -3px rgba(0, 0, 0, .2), 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12);
33
+ cursor: move;
34
+ z-index: 10;
35
+ }
36
+
37
+ [draggable=true].drag-target-top {
38
+ box-shadow: 0 -2px 0 #000;
39
+ position: relative;
40
+ z-index: 20;
41
+ }
42
+
43
+ [draggable=true].drag-target-bottom {
44
+ box-shadow: 0 2px 0 #000;
45
+ position: relative;
46
+ z-index: 20;
47
+ }
48
+
49
+
50
+ /*
51
+ .purple-green {
52
+ @import './material-design-themes.scss';
53
+ }
54
+ */
55
+
56
+ @import './material-design-themes.scss';
57
+ @import './flexlayout-replacement-styles.scss';
58
+ @import './tailwind-output.scss';
@@ -0,0 +1,39 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3
+ import {
4
+ JsonSchemaFormModule,
5
+ JsonSchemaFormService,
6
+ WidgetLibraryModule
7
+ } from '@ng-formworks/core';
8
+ import { MaterialDesignFrameworkComponent } from './material-design-framework.component';
9
+
10
+ describe('FwBootstrap4Component', () => {
11
+ let component: MaterialDesignFrameworkComponent;
12
+ let fixture: ComponentFixture<MaterialDesignFrameworkComponent>;
13
+
14
+ beforeEach(waitForAsync(() => {
15
+ TestBed.configureTestingModule({
16
+ imports: [
17
+ JsonSchemaFormModule,
18
+ CommonModule,
19
+ WidgetLibraryModule,
20
+ ],
21
+ declarations: [MaterialDesignFrameworkComponent],
22
+ providers: [JsonSchemaFormService]
23
+ })
24
+ .compileComponents();
25
+ }));
26
+
27
+ beforeEach(() => {
28
+ fixture = TestBed.createComponent(MaterialDesignFrameworkComponent);
29
+ component = fixture.componentInstance;
30
+ component.layoutNode = { options: {} };
31
+ component.layoutIndex = [];
32
+ component.dataIndex = [];
33
+ fixture.detectChanges();
34
+ });
35
+
36
+ it('should create', () => {
37
+ expect(component).toBeTruthy();
38
+ });
39
+ });
@@ -0,0 +1,143 @@
1
+ import { ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
2
+ import { FrameworkLibraryService, JsonSchemaFormService, isDefined } from '@ng-formworks/core';
3
+ import { CssframeworkService } from '@ng-formworks/cssframework';
4
+ import cloneDeep from 'lodash/cloneDeep';
5
+ import { Subscription } from 'rxjs';
6
+ import { cssFrameworkCfgMaterialDesign } from './material-design-cssframework';
7
+
8
+ @Component({
9
+ // tslint:disable-next-line:component-selector
10
+ selector: 'material-design-framework',
11
+ templateUrl: './material-design-framework.component.html',
12
+ styleUrls: ['./material-design-framework.component.scss'],
13
+ //changeDetection:ChangeDetectionStrategy.OnPush
14
+ })
15
+ export class MaterialDesignFrameworkComponent implements OnInit, OnChanges ,OnDestroy {
16
+ frameworkInitialized = false;
17
+ inputType: string;
18
+ options: any; // Options used in this framework
19
+ widgetLayoutNode: any; // layoutNode passed to child widget
20
+ widgetOptions: any; // Options passed to child widget
21
+ formControl: any = null;
22
+ parentArray: any = null;
23
+ isOrderable = false;
24
+ dynamicTitle: string = null;
25
+ @Input() layoutNode: any;
26
+ @Input() layoutIndex: number[];
27
+ @Input() dataIndex: number[];
28
+
29
+ theme:string="material-default-theme";
30
+ frameworkThemeSubs:Subscription;
31
+ constructor(
32
+ private changeDetector: ChangeDetectorRef,
33
+ private jsf: JsonSchemaFormService,
34
+ public jsfFLService:FrameworkLibraryService,
35
+ public cssFWService:CssframeworkService
36
+ ) {
37
+ let activeFramework:any=this.jsfFLService.activeFramework;
38
+ let fwcfg=activeFramework.config||{};
39
+ let defaultTheme=cssFrameworkCfgMaterialDesign.widgetstyles?.__themes__[0];
40
+ let defaultThemeName=cssFWService.activeRequestedTheme||defaultTheme.name;
41
+ this.theme=this.options?.theme|| defaultThemeName;
42
+ this.frameworkThemeSubs= cssFWService.frameworkTheme$.subscribe(newTheme=>{
43
+ this.theme=newTheme;
44
+ })
45
+
46
+
47
+ }
48
+ ngOnDestroy(): void {
49
+ this.frameworkThemeSubs.unsubscribe();
50
+ this.frameworkThemeSubs=null;
51
+ }
52
+
53
+ get showRemoveButton(): boolean {
54
+ if (!this.layoutNode || !this.widgetOptions.removable ||
55
+ this.widgetOptions.readonly || this.layoutNode.type === '$ref'
56
+ ) {
57
+ return false;
58
+ }
59
+ if (this.layoutNode.recursiveReference) {
60
+ return true;
61
+ }
62
+ if (!this.layoutNode.arrayItem || !this.parentArray) {
63
+ return false;
64
+ }
65
+ // If array length <= minItems, don't allow removing any items
66
+ return this.parentArray.items.length - 1 <= this.parentArray.options.minItems ? false :
67
+ // For removable list items, allow removing any item
68
+ this.layoutNode.arrayItemType === 'list' ? true :
69
+ // For removable tuple items, only allow removing last item in list
70
+ this.layoutIndex[this.layoutIndex.length - 1] === this.parentArray.items.length - 2;
71
+ }
72
+
73
+ ngOnInit() {
74
+ this.initializeFramework();
75
+ }
76
+
77
+ ngOnChanges() {
78
+ if (!this.frameworkInitialized) {
79
+ this.initializeFramework();
80
+ }
81
+ if (this.dynamicTitle) {
82
+ this.updateTitle();
83
+ }
84
+ }
85
+
86
+ initializeFramework() {
87
+ if (this.layoutNode) {
88
+ this.options = cloneDeep(this.layoutNode.options || {});
89
+ this.widgetLayoutNode = {
90
+ ...this.layoutNode,
91
+ options: cloneDeep(this.layoutNode.options || {})
92
+ };
93
+ this.widgetOptions = this.widgetLayoutNode.options;
94
+ this.formControl = this.jsf.getFormControl(this);
95
+
96
+ if (
97
+ isDefined(this.widgetOptions.minimum) &&
98
+ isDefined(this.widgetOptions.maximum) &&
99
+ this.widgetOptions.multipleOf >= 1
100
+ ) {
101
+ this.layoutNode.type = 'range';
102
+ }
103
+
104
+ if (
105
+ !['$ref', 'advancedfieldset', 'authfieldset', 'button', 'card',
106
+ 'checkbox', 'expansion-panel', 'help', 'message', 'msg', 'section',
107
+ 'submit', 'tabarray', 'tabs'].includes(this.layoutNode.type) &&
108
+ /{{.+?}}/.test(this.widgetOptions.title || '')
109
+ ) {
110
+ this.dynamicTitle = this.widgetOptions.title;
111
+ this.updateTitle();
112
+ }
113
+
114
+ if (this.layoutNode.arrayItem && this.layoutNode.type !== '$ref') {
115
+ this.parentArray = this.jsf.getParentNode(this);
116
+ if (this.parentArray) {
117
+ this.isOrderable =
118
+ this.parentArray.type.slice(0, 3) !== 'tab' &&
119
+ this.layoutNode.arrayItemType === 'list' &&
120
+ !this.widgetOptions.readonly &&
121
+ this.parentArray.options.orderable;
122
+ }
123
+ }
124
+
125
+ this.frameworkInitialized = true;
126
+ } else {
127
+ this.options = {};
128
+ }
129
+ }
130
+
131
+ updateTitle() {
132
+ this.widgetLayoutNode.options.title = this.jsf.parseText(
133
+ this.dynamicTitle,
134
+ this.jsf.getFormControlValue(this),
135
+ this.jsf.getFormControlGroup(this).value,
136
+ this.dataIndex[this.dataIndex.length - 1]
137
+ );
138
+ }
139
+
140
+ removeItem() {
141
+ this.jsf.removeItem(this);
142
+ }
143
+ }