Skip to content

Commit 187e63e

Browse files
committed
Move frameworks’ HTML and CSS inline to avoid Meteor bug importing Angular2 library templates.
1 parent 766f3a3 commit 187e63e

File tree

79 files changed

+494
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+494
-503
lines changed

.gitignore

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1+
# Generated
2+
compiled
3+
dist
4+
docs
5+
16
# Node
2-
node_modules/*
3-
dist/*
4-
docs/*
7+
node_modules
58
npm-debug.log
69

7-
# TypeScript
8-
*.js
9-
!./index.js
10-
!./systemjs.config.js
11-
*.map
12-
*.d.ts
13-
!./typings/*.ts
14-
15-
# JetBrains
10+
# IDE
1611
.idea
1712
.project
1813
.settings
1914
.idea/*
2015
*.iml
16+
*.swp
2117

22-
# Windows
18+
# OS
2319
Thumbs.db
2420
Desktop.ini
25-
26-
# Mac
2721
.DS_Store
28-
**/.DS_Store

.npmignore

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1+
# Development
2+
compiled
3+
dist/playground
4+
docs
5+
src
6+
7+
# TypeScript
8+
tsconfig.json
9+
tslint.json
10+
typedoc.json
11+
typings.json
12+
typings
13+
*.ts
14+
!*.d.ts
15+
116
# Node
2-
node_modules/*
3-
# dist/*
4-
docs/*
17+
node_modules
518
npm-debug.log
619

7-
# Include compiled TypeScript files in NPM bundle
8-
# *.js
9-
# !index.js
10-
# !systemjs.config.js
11-
# *.map
12-
# *.d.ts
13-
# !typings/*.ts
14-
15-
# JetBrains
20+
# IDE
1621
.idea
1722
.project
1823
.settings
1924
.idea/*
2025
*.iml
26+
*.swp
2127

22-
# Windows
28+
# OS
2329
Thumbs.db
2430
Desktop.ini
25-
26-
# Mac
2731
.DS_Store
28-
**/.DS_Store

README.md

+49-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Angular 2 JSON Schema Form
22

3+
[![npm version](https://badge.fury.io/js/angular2-json-schema-form.svg)](https://www.npmjs.com/package/angular2-json-schema-form) [![MIT Licence](https://img.shields.io/github/license/dschnelldavis/angular2-json-schema-form.svg)](https://opensource.org/licenses/mit-license.php)
4+
35
A [JSON Schema](http://json-schema.org) Form builder for Angular 2, similar to, and mostly API compatible with,
46

57
* [JSON Schema Form](https://github.com/json-schema-form)'s [Angular Schema Form](http://schemaform.io) for [Angular 1](https://angularjs.org) ([examples](http://schemaform.io/examples/bootstrap-example.html))
@@ -12,7 +14,7 @@ Note: This is a personal proof-of-concept project, and is NOT currently affiliat
1214

1315
### To install from GitHub and play with the examples
1416

15-
The [GitHub](https://github.com) version of Angular 2 JSON Schema Form includes an example playground with over 70 different JSON Schemas (including all examples used by each of the three libraries listed above), and the ability to quickly view any example formatted using Bootstrap 3 or Material Design (or without formatting, which works, but is usually pretty ugly).
17+
The [GitHub](https://github.com) version of Angular 2 JSON Schema Form includes an example playground with over 70 different JSON Schemas (including all examples used by each of the three libraries listed above), and the ability to quickly view any example formatted using Bootstrap 3 or Material Design (or without formatting, which is functional, but usually pretty ugly).
1618

1719
To install both the library and the example playground, clone `https://github.com/dschnelldavis/angular2-json-schema-form.git` with your favorite git program, or enter the following in your terminal:
1820

@@ -30,42 +32,58 @@ All the source code is in the `/src` folder. Inside that folder, you will find t
3032
* `library` contains the Angular 2 JSON Schema Form library.
3133
* `playground` contains the example playground.
3234
* `playground/examples` contains the JSON Schema examples.
33-
* `frameworks` contains the widget library (described below).
34-
* `widgets` contains the framework library.
35+
* `frameworks` contains the framework library (described below).
36+
* `widgets` contains the widget library.
3537

3638
If you want additional documentation describing the individual functions used in this library, run `npm run docs` to generate TypeDoc documentation, and then look in the newly generated `/docs` folder.
3739

3840
### To install from NPM and use in your own project
3941

40-
If, after playing with the examples, you decide this library is functional enough to use in your own project, you can install it from [NPM](https://www.npmjs.com) with:
42+
If, after playing with the examples, you decide this library is functional enough to use in your own project, you can install it from [NPM](https://www.npmjs.com) by running the following from your terminal:
4143

4244
```
4345
npm install angular2-json-schema-form -save
4446
```
4547

46-
Then add these two lines to your main application module:
48+
Then add this line to your main application module:
4749
```javascript
48-
import { ReactiveFormsModule } from '@angular/forms';
4950
import { JsonSchemaFormModule } from 'angular2-json-schema-form';
5051
```
5152

52-
And finally, add `'ReactiveFormsModule'` and `'JsonSchemaFormModule'` to the 'imports' array in your @NgModule declaration.
53+
And finally, add `JsonSchemaFormModule` to the `imports` array in your @NgModule declaration.
54+
55+
Your final app.module.ts should look something like this:
56+
57+
```javascript
58+
import { NgModule } from '@angular/core';
59+
import { BrowserModule } from '@angular/platform-browser';
60+
61+
import { JsonSchemaFormModule } from 'angular2-json-schema-form';
62+
63+
import { AppComponent } from './app.component';
64+
65+
@NgModule({
66+
imports: [ BrowserModule, JsonSchemaFormModule ],
67+
declarations: [ AppComponent ],
68+
bootstrap: [ AppComponent ]
69+
})
70+
export class AppModule { }
71+
```
5372

5473
Also, if you use SystemJS, you will also need to make the following changes to your systemjs.config.js file.
5574

56-
Add three lines to the 'map' section:
75+
Add these three lines to the 'map' section:
5776
```javascript
5877
'angular2-json-schema-form': 'npm:angular2-json-schema-form',
59-
'ajv': 'npm:ajv/dist/ajv.min.js',
60-
'lodash': 'npm:lodash/lodash.min.js',
78+
'ajv': 'npm:ajv/dist/ajv.min.js',
79+
'lodash': 'npm:lodash/lodash.min.js',
6180
```
6281

63-
And add one line to the 'packages' section:
82+
And add this line to the 'packages' section:
6483
```javascript
65-
'angular2-json-schema-form': { main: './index.js', defaultExtension: 'js' },
84+
'angular2-json-schema-form': { main: './dist/index.js', defaultExtension: 'js' },
6685
```
6786

68-
6987
(For a complete example of how to install and use the library, clone the GitHub repository and look at how the library is imported into the example playground.)
7088

7189
## Using Angular 2 JSON Schema Form
@@ -81,17 +99,17 @@ For basic use, after loading the JsonSchemaFormModule as described above, to add
8199
</json-schema-form>
82100
```
83101

84-
Where the 'schema' input is a valid JSON schema object (either v3 or v4), and the 'onSubmit' output is a function that will be called when the form is submitted, with the results of the form as a JSON object.
102+
Where the `schema` input is a valid JSON schema object (either v3 or v4), and the `onSubmit` output is a function that will be called when the form is submitted, with the results of the form as a JSON object.
85103

86104
### Advanced use
87105

88106
For more advanced cases, you may also provide three additional inputs:
89107

90-
* 'layout' with a custom form layout (see Angular Schema Form's [form definitions](https://github.com/json-schema-form/angular-schema-form/blob/master/docs/index.md#form-definitions) for information about how to construct a form layout)
91-
* 'data' to populate the form with defaults or previously submitted values, and
92-
* 'options' to set any global options for the form.
108+
* `layout` with a custom form layout (see Angular Schema Form's [form definitions](https://github.com/json-schema-form/angular-schema-form/blob/master/docs/index.md#form-definitions) for information about how to construct a form layout)
109+
* `data` to populate the form with defaults or previously submitted values, and
110+
* `options` to set any global options for the form.
93111

94-
If you want more detailed output, you may provide additional functions for 'onChanges' to read the form values in real time (including before the completed form has been submitted) and you may implement your own custom validation from the boolean 'isValid' or the detailed 'validationErrors' outputs.
112+
If you want more detailed output, you may provide additional functions for `onChanges` to read the form values in real time (including before the completed form has been submitted) and you may implement your own custom validation from the boolean `isValid` or the detailed `validationErrors` outputs.
95113

96114
Here is an example:
97115

@@ -108,14 +126,14 @@ Here is an example:
108126
</json-schema-form>
109127
```
110128

111-
Alternately, you may also combine all your inputs into one compound object and include it as a 'form' input, like so:
129+
Alternately, you may also combine all your inputs into one compound object and include it as a `form` input, like so:
112130

113131
```javascript
114132
let yourCompoundInputObject = {
115-
schema: {...}, // required
116-
layout: [...], // optional
117-
data: {...}, // optional
118-
options: {...} // optional
133+
schema: {...}, // required
134+
layout: [...], // optional
135+
data: {...}, // optional
136+
options: {...} // optional
119137
}
120138
```
121139

@@ -167,7 +185,7 @@ import { WidgetLibraryService } from 'angular2-json-schema-form';
167185
import { YourInputWidgetComponent } from './your-input-widget.component';
168186
import { YourCustomWidgetComponent } from './your-custom-widget.component';
169187
...
170-
constructor(private widgetLibrary: WidgetLibraryService) {}
188+
constructor(private widgetLibrary: WidgetLibraryService) { }
171189
...
172190
// Replace existing 'input' widget:
173191
widgetLibrary.registerWidget('input', YourInputWidgetComponent);
@@ -184,26 +202,26 @@ To change the active framework, load the `FrameworkLibraryService` and call `set
184202
```javascript
185203
import { FrameworkLibraryService } from 'angular2-json-schema-form';
186204
...
187-
constructor(private frameworkLibrary: FrameworkLibraryService) {}
205+
constructor(private frameworkLibrary: FrameworkLibraryService) { }
188206
...
189207
let yourCustomFramework = {
190208
framework: YourFrameworkComponent, // required
191-
widgets: { 'your-widget-name': YourWidgetComponent }, // optional
192-
stylesheets: [ '//url-to-your-external-style-sheet' ], // optional
193-
scripts: [ '//url-to-your-external-script' ] // optional
209+
widgets: { 'your-widget-name': YourWidgetComponent }, // optional
210+
stylesheets: [ '//url-to-your-external-style-sheet' ], // optional
211+
scripts: [ '//url-to-your-external-script' ] // optional
194212
}
195213
frameworkLibrary.setFramework(yourCustomFramework);
196214
```
197215

198-
The value of the required 'framework' key is an Angular 2 component which will be called to format each widget before it is displayed. The optional 'widgets' object contains any custom widgets which will override or supplement the built-in widgets, and the 'stylesheets' and 'scripts' arrays contain URLs to any supplemental external style sheets and JavaScript libraries to load.
216+
The value of the required `framework` key is an Angular 2 component which will be called to format each widget before it is displayed. The optional `widgets` object contains any custom widgets which will override or supplement the built-in widgets, and the `stylesheets` and `scripts` arrays contain URLs to any supplemental external style sheets and JavaScript libraries to load.
199217

200-
The two built-in frameworks (both in the `/src/frameworks` folder) demonstrate different strategies for how frameworks can style form elements. The Bootstrap 3 framework is very lightweight and includes no additional widgets (though it does load some external stylesheets and scripts) and works entirely by adding styles to the default widgets. In contrast, the Material Design framework makes much more drastic changes, and uses the [Material Design for Angular 2](https://github.com/angular/material2) library (which must be loaded separately in the Angular 2 application module) to replace most of the default form control widgets with custom widgets from that library.
218+
The two built-in frameworks (both in the `/src/frameworks` folder) demonstrate different strategies for how frameworks can style form elements. The Bootstrap 3 framework is very lightweight and includes no additional widgets (though it does load some external stylesheets and scripts) and works entirely by adding styles to the default widgets. In contrast, the Material Design framework makes much more drastic changes, and uses the [Material Design for Angular 2](https://github.com/angular/material2) library to replace most of the default form control widgets with custom widgets from that library.
201219

202220
## Contributions and future development
203221

204222
I wrote this library because I needed a JSON Schema Form builder to use in a large Angular 2 project I am currently working on. Though I found excellent libraries for Angular 1, React, and jQuery (all linked above), I could not find anything similar for Angular 2—so I wrote this library to fill that gap.
205223

206-
The current version is mostly functional, and even includes a few enhancements not available in some other libraries, such as supporting less common JSON Schema features like 'oneOf', 'allOf', and '$ref' links (including circular links). However, it still has several bugs, such as not dynamically enabling and disabling conditionally required fields inside objects, and is very fragile because it does not yet include any testing framework at all.
224+
The current version is mostly functional, and even includes a few enhancements not available in some other libraries, such as supporting less common JSON Schema features like `oneOf`, `allOf`, and `$ref` links (including circular links). However, it still has several bugs, such as not dynamically enabling and disabling conditionally required fields inside objects, and is very fragile because it does not yet include any testing framework at all.
207225

208226
So if you find this library useful, I encourage you to fork it and send back pull requests for any improvements you make. (I would _love_ some tests...) You are also welcome to submit bug reports, however, as I am just a single busy developer, I can't guarantee how long it might take to fix any individual bugs. So if you want a change or fix to be implemented quickly, your best bet is to do it yourself and send a pull request.
209227

index.ts

-5
This file was deleted.

package.json

+50-43
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,70 @@
11
{
22
"name": "angular2-json-schema-form",
3+
"version": "0.3.0-alpha.1",
4+
"author": {
5+
"name": "dschnelldavis",
6+
"email": "[email protected]"
7+
},
38
"description": "Angular 2 JSON Schema Form builder",
4-
"author": "David Schnell-Davis",
59
"keywords": [
610
"Angular 2",
711
"JSON Schema",
812
"Form builder"
913
],
1014
"license": "MIT",
11-
"version": "0.2.0-alpha.1",
12-
"scripts": {
13-
"start": "npm run cleandist && npm run syncassets && tsc && concurrently \"tsc -w\" \"lite-server\" \"npm run watchassets\" ",
14-
"lint": "tslint src/**/*.ts",
15-
"test": "tsc && karma start",
16-
"postinstall": "typings install",
17-
"prepublish": "tsc",
18-
"tsc": "tsc",
19-
"typings": "typings",
20-
"docs": "typedoc --options typedoc.json index.ts",
21-
"cleandist": "rm -rf dist/*",
22-
"syncassets": "rsync -ar --include='*.css' --include='*.html' --include='*.json' --include='*/' --exclude='*' ./src/ ./dist/src/",
23-
"watchassets": "onchange 'src/**/*.css' 'src/**/*.html' 'src/**/*.json' -e 'dist/src/*' -v -- rsync -ar --include='*.css' --include='*.html' --include='*.json' --include='*/' --exclude='*' --delete ./src/ ./dist/src/"
24-
},
2515
"repository": {
2616
"type": "git",
2717
"url": "https://github.com/dschnelldavis/angular2-json-schema-form"
2818
},
2919
"bugs": {
3020
"url": "https://github.com/dschnelldavis/angular2-json-schema-form/issues"
3121
},
32-
"main": "./dist/src/library/json-schema-form.module.js",
33-
"types": "./dist/src/library/json-schema-form.module.d.ts",
22+
"files": [
23+
"dist/"
24+
],
25+
"main": "dist/library/json-schema-form.module.js",
26+
"typings": "dist/library/json-schema-form.module.d.ts",
27+
"scripts": {
28+
"clean:dist": "rimraf compiled && rimraf dist",
29+
"clean:all": "npm run clean:dist && rimraf node_modules && npm cache clean",
30+
"prepublish": "npm run clean:dist && ./node_modules/.bin/ngc && rimraf compiled && rimraf dist/playground",
31+
"lint": "tslint src/**/*.ts",
32+
"test": "tsc && karma start",
33+
"ngc": "./node_modules/.bin/ngc",
34+
"tsc": "tsc",
35+
"typings": "typings",
36+
"docs": "typedoc --options typedoc.json src/index.ts",
37+
"start": "npm run clean:dist && npm run syncassets && tsc && concurrently \"tsc -w\" \"lite-server\" \"npm run watchassets\" ",
38+
"syncassets": "rsync -ar --include='*.css' --include='*.html' --include='*.json' --include='*/' --exclude='*' ./src/ ./dist/",
39+
"watchassets": "onchange 'src/**/*.css' 'src/**/*.html' 'src/**/*.json' -e 'dist/*' -v -- rsync -ar --include='*.css' --include='*.html' --include='*.json' --include='*/' --exclude='*' --delete ./src/ ./dist/"
40+
},
3441
"dependencies": {
35-
"@angular/common": "~2.2.4",
36-
"@angular/compiler": "~2.2.4",
37-
"@angular/core": "~2.2.4",
38-
"@angular/forms": "~2.2.4",
39-
"@angular/http": "~2.2.4",
40-
"@angular/material": "^2.0.0-alpha.11-3",
41-
"@angular/platform-browser": "~2.2.4",
42-
"@angular/platform-browser-dynamic": "~2.2.4",
43-
"@angular/router": "~3.2.4",
44-
"ajv": "^4.7.7",
45-
"bootstrap": "^3.3.7",
46-
"brace": "^0.8.0",
47-
"buffer": "^5.0.0",
48-
"core-js": "^2.4.1",
49-
"lodash": "^4.17.2",
50-
"ng2-bootstrap": "^1.1.16",
51-
"reflect-metadata": "^0.1.8",
52-
"rxjs": "5.0.0-beta.12",
53-
"systemjs": "0.19.38",
54-
"zone.js": "~0.6.25"
42+
"@angular/common": "^2.0.0",
43+
"@angular/compiler": "^2.0.0",
44+
"@angular/core": "^2.0.0",
45+
"@angular/forms": "^2.0.0",
46+
"@angular/material": "2.0.0-alpha.11-3",
47+
"@angular/platform-browser": "^2.0.0",
48+
"@angular/platform-browser-dynamic": "^2.0.0",
49+
"ajv": "^4.7.0",
50+
"lodash": "^4.17.0"
5551
},
5652
"devDependencies": {
57-
"@types/ace": "0.0.32",
58-
"@types/ajv": "0.0.3",
53+
"@angular/compiler-cli": "^2.0.0",
54+
"@angular/http": "^2.0.0",
55+
"@angular/platform-server": "^2.0.0",
56+
"@angular/router": "^3.0.0",
57+
"@types/ace": "^0.0.32",
58+
"@types/ajv": "^0.0.5",
5959
"@types/jasmine": "^2.5.38",
6060
"@types/lodash": "^4.14.42",
6161
"@types/node": "^6.0.51",
62+
"brace": "^0.9.1",
63+
"buffer": "^5.0.0",
6264
"canonical-path": "0.0.2",
6365
"codelyzer": "2.0.0-beta.3",
6466
"concurrently": "^3.0.0",
67+
"core-js": "^2.4.1",
6568
"http-server": "^0.9.0",
6669
"jasmine-core": "~2.5.2",
6770
"karma": "^1.3.0",
@@ -72,11 +75,15 @@
7275
"karma-jasmine-html-reporter": "^0.2.2",
7376
"lite-server": "^2.2.2",
7477
"onchange": "^3.2.0",
75-
"protractor": "^3.3.0",
78+
"protractor": "^4.0.13",
79+
"reflect-metadata": "^0.1.8",
7680
"rimraf": "^2.5.4",
77-
"tslint": "^4.0.2",
81+
"rxjs": "5.0.0-rc.4",
82+
"systemjs": "^0.19.41",
83+
"tslint": "~4.0.2",
7884
"typedoc": "^0.5.1",
79-
"typescript": "^2.1.4",
80-
"typings": "^1.3.1"
85+
"typescript": "~2.0.10",
86+
"typings": "^1.3.1",
87+
"zone.js": "~0.7.2"
8188
}
8289
}

0 commit comments

Comments
 (0)