├── .gitignore ├── README.md ├── docs └── tasks-in-priority.html ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── src ├── App.css ├── App.js ├── App.test.js ├── common │ └── utils.js ├── components │ ├── CodeGenerator.js │ ├── CodeViewer.js │ ├── Declarator.js │ └── ErrorDisplayer.js ├── core │ ├── generator.js │ └── validator.js ├── index.css ├── index.js ├── logo.svg ├── registerServiceWorker.js └── validator.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # antd-form-code-generator 2 | Live link: [Play here](http://antd-form.surge.sh/) 3 | 4 | ### Philosophy 5 | antd-form-code-generator is a code generator using JSON schemas. This tool is not intended to be used inside a project’s code to generate form at runtime, rather at development time to automate form code generation for long forms. 6 | 7 | Using it at the development time rather than runtime, gives you the ability to give the form a custom UI layout and stylings. It’s main power lies in its ablility to make updates to the code using just the schema which gives you more visibility on the changes and gain more confidence on the code for the repeated and frequent changes. 8 | 9 | The code generated is very specific to the antd library. If your project is not using antd as your UI library, this tool might not be for that project. 10 | 11 | The tool doesnt generate a form component rather just the fields inside a `` which can be simply pasted inside the `
` tag. This gives you the ability to provide any other props such as submit handler or `className` 12 | 13 | It also gives you the ability to focus on the fields rather than the form component as a whole. One another benefit this approach provides is: you can divide the fields of a very long form into small logical components using the tool itself so, you focus on small peices of code rather than the big form component. 14 | 15 | The main purpose to build this tool is to avoid writing the same form code again and again in a project where a lot of forms are required. Also in case of the updation of these forms, you only have to focus on updating the JSON schema which is less cumbersome as compared to the form code iteself, thus reducing the chances of error in every update. 16 | 17 | ### JSON schema 18 | ```json 19 | [ 20 | { 21 | "field": { 22 | "type": "Select", 23 | "props": {}, 24 | "options": { 25 | "varName": "genders", 26 | "labelKey": "label", 27 | "valueKey": "value" 28 | } 29 | }, 30 | "label": "E-mail", 31 | "validations": [ 32 | { 33 | "type": "email", 34 | "message": "Please type a valid email" 35 | }, 36 | { 37 | "required": true, 38 | "message": "Please provide an email" 39 | } 40 | ], 41 | "valuePropName": "userEmail" 42 | }, 43 | { 44 | "field": { 45 | "type": "Checkbox", 46 | "props": {} 47 | }, 48 | "label": "E-mail", 49 | "validations": [ 50 | { 51 | "type": "email", 52 | "message": "Please type a valid email" 53 | }, 54 | { 55 | "required": true, 56 | "message": "Please provide an email" 57 | } 58 | ], 59 | "valuePropName": "userEmail" 60 | }, 61 | { 62 | "field": "Input", 63 | "label": "Name", 64 | "validations": [ 65 | { 66 | "required": true, 67 | "message": "Please provide an email" 68 | } 69 | ], 70 | "valuePropName": "userName" 71 | }, 72 | { 73 | "field": { 74 | "type": "Input", 75 | "props": { 76 | "prefix": "$" 77 | } 78 | }, 79 | "label": "Name", 80 | "validations": [ 81 | { 82 | "required": true, 83 | "message": "Please provide an email" 84 | } 85 | ], 86 | "valuePropName": "userName" 87 | } 88 | ] 89 | ``` 90 | 91 | 92 | ### JSON schema validator config 93 | You can look at the config for JSON validator [here](http://jsoneditoronline.org/?id=4b6df9ceb3c348aa93debf3780405a7e) 94 | 95 | ### Have and issues? Want a new feature? 96 | In case of any bugor feature request, feel free to create a issue in the repo. 97 | 98 | ### Contributing 99 | This project is bootstrapped using create-react-app so, you can simple clone it and follow: 100 | 101 | 1. `yarn` => To install dependencies 102 | 2. `yarn start` => To start the dev server 103 | -------------------------------------------------------------------------------- /docs/tasks-in-priority.html: -------------------------------------------------------------------------------- 1 |
Tasks in priority 
  •  Fix styling of listen on repeat 
  •  Apply to atleast 2 companies - 2hrs
  •  Finish assignments upto sorting class - 4-6hrs
  •  Update the YouTube player repo(Resolve the only issue) - 1hr
  •  Deploy of whatever is remaining in Acadview’s work
  •  Verify and plan on the document shared by Varun
  •  Make a new resume according to Neena
  •  Take up the course on Maybe Data type JS
  •  Follow up on Jay on the application
  •  Signup for codementor as a mentor
  •  GOAL: Become a core member in one of the reputable JS frameworks
  •  Next issue on devtools highlighter 
  •  Next lebab as babel plugin
  •  Full course on using react with redux and react Router. 
  •  Cheat sheet for you dont know JS
  •  Ramp up on react navigation. 
  •  Create a mock for the personal website
  •  Learn react Router v4 using the docs and the articles I found 
  •  Learn css grids 
  •  Learn css flexbox
  •  Create a document for commonly faced interview questions and their answers 
  •  Story spinner in react 
  •  Compliance new module on ops side
  •  Evaluator side changes for assignments
  •  Misc. pages data
  •  Send resume to Himanshu
  •  Send resume to Jay
  •  Reply to Jay for remote work: 
Hi Jay,
Thanks for providing the job description. Looks like a good fit and at the same a great opportunity to learn and grow.
 
I can be a good fit for the role and benefit the organisation because of the following things: 
 
  1. Working as a Frontend Lead in a growing EdTech startup helped me learn how to responsibly deliver with little to no guidance. I have set up the whole architecture and set up processes for the people to come over the time.
  1. I have worked in an environment where we met only for important dicussions and worked remotly for almost all of the times. This has provided me a great experience in remote work.
  1. Working in a remote job helped me learn about how to manage my time and how to prioritize tasks efficiently.
  1. I love open feedbacks since they help me to improve and at the same time maintain a right direction. And the best thing about regular feedbacks is that you can improve then and there. 
  1. While working in an EdTech startup I have taught multiple courses and mentored a lot of students.
  1. I love exploring what’s new and trying them. This pushed me into doing open source. I have been working in converting lebab (the utility that converts ES5 to ES6) into babel plugins. The repo is available here: https://github.com/rajatvijay/lebab-as-babel-plugins
 
 

TimeTable

  1. 5-6 => 6.006 video(lecture + recitation)
  1. 6-7 => Assignments(only one hour though)
  1. 7-10 => Current project
  1. 10-11 => Shower + Breakfast
  1. 11-2 => Current Project
  1. 2-3 => Lunch
  1. 3-4 => Geeks for Geeks algorithm in JS (2 algorithms every day)
  1. 4-6 => Current Project
  1. 6-8 => Gym + Later
 
Every Sunday: Write up an article
Every Tuesday: Publish that article 
Current Project: React v3 course from Brian Holt
Current Week: 14 May-20 May
Every Saturday: Apply for jobs(5)
-------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "antd-form-code-generator", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "ajv": "^6.5.3", 7 | "antd": "^3.7.3", 8 | "brace": "^0.11.1", 9 | "prettier": "^1.13.5", 10 | "react": "^16.4.1", 11 | "react-ace": "^6.1.4", 12 | "react-copy-to-clipboard": "^5.0.1", 13 | "react-dom": "^16.4.1", 14 | "react-scripts": "1.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test --env=jsdom", 20 | "eject": "react-scripts eject", 21 | "deploy": "yarn build && surge --domain antd-form.surge.sh" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajatvijay/antd-form-code-generator/785b06c6b1c7383b61d6a68d7d3a64d6601e3efb/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 23 | Antd form code generator 24 | 25 | 26 | 27 | 30 |
31 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 80px; 8 | } 9 | 10 | .App-header { 11 | background-color: #222; 12 | height: 150px; 13 | padding: 20px; 14 | color: white; 15 | } 16 | 17 | .App-title { 18 | font-size: 1.5em; 19 | } 20 | 21 | .App-intro { 22 | font-size: large; 23 | } 24 | 25 | @keyframes App-logo-spin { 26 | from { transform: rotate(0deg); } 27 | to { transform: rotate(360deg); } 28 | } 29 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import CodeGenerator from './components/CodeGenerator'; 3 | 4 | const App = props => ; 5 | 6 | export default App; 7 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/common/utils.js: -------------------------------------------------------------------------------- 1 | export const pipe = (inputs, ...args) => { 2 | try { 3 | return args.reduce((output, f) => { 4 | output = f(...output); 5 | return [output]; 6 | }, inputs); 7 | } catch (err) { 8 | console.log(err); 9 | throw new Error("Pipe Error"); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /src/components/CodeGenerator.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Declarator from "./Declarator"; 3 | import CodeViewer from "./CodeViewer"; 4 | import Generator from "../core/generator"; 5 | import { Row, Col, Button, message } from "antd"; 6 | import { CopyToClipboard } from "react-copy-to-clipboard"; 7 | import ErrorDisplay from "./ErrorDisplayer"; 8 | 9 | class CodeGenerator extends Component { 10 | state = { 11 | formCode: "", 12 | errors: [] 13 | }; 14 | 15 | // onDeclarationsChanged = declarations => { 16 | // const formCode = Generator(declarations); 17 | // this.setState({ declarations, formCode }); 18 | // }; 19 | 20 | generateFormCode = declarations => { 21 | const { isValid, errors, code: formCode } = Generator(declarations); 22 | 23 | if (isValid) { 24 | return this.setState({ formCode }); 25 | } 26 | 27 | window.scrollTo({ 28 | top: 10000000000, // Some randomly big number 29 | behavior: "smooth" 30 | }); 31 | return this.setState({ errors }); 32 | }; 33 | 34 | render() { 35 | const { declarations, formCode, errors } = this.state; 36 | return ( 37 |
38 |

46 | Antd react form code generator 47 |

48 | 49 | 50 | 55 | 56 | 57 |
63 | 64 |
65 | {formCode ? ( 66 | message.success("Copied!")} 69 | > 70 | 73 | 74 | ) : null} 75 | 76 |
77 | 78 |
79 | ); 80 | } 81 | } 82 | 83 | export default CodeGenerator; 84 | -------------------------------------------------------------------------------- /src/components/CodeViewer.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import AceEditor from "react-ace"; 3 | import brace from "brace"; // eslint-disable-line no-unused-vars 4 | 5 | import "brace/mode/jsx"; 6 | import "brace/theme/github"; 7 | 8 | const CodeViewer = props => ( 9 | 29 | ); 30 | 31 | export default CodeViewer; 32 | -------------------------------------------------------------------------------- /src/components/Declarator.js: -------------------------------------------------------------------------------- 1 | import React, { Component, Fragment } from "react"; 2 | import { Button } from "antd"; 3 | import AceEditor from "react-ace"; 4 | import brace from "brace"; // eslint-disable-line no-unused-vars 5 | 6 | import "brace/mode/json"; 7 | import "brace/theme/github"; 8 | 9 | const initailDeclarations = JSON.stringify( 10 | [ 11 | { 12 | field: { 13 | type: "Select", 14 | props: {}, 15 | options: { 16 | varName: "genders", 17 | labelKey: "label", 18 | valueKey: "value" 19 | } 20 | }, 21 | label: "E-mail", 22 | validations: [ 23 | { 24 | type: "email", 25 | message: "Please type a valid email" 26 | }, 27 | { 28 | required: true, 29 | message: "Please provide an email" 30 | } 31 | ], 32 | valuePropName: "userEmail" 33 | }, 34 | { 35 | field: { 36 | type: "Checkbox", 37 | props: {} 38 | }, 39 | label: "E-mail", 40 | validations: [ 41 | { 42 | type: "email", 43 | message: "Please type a valid email" 44 | }, 45 | { 46 | required: true, 47 | message: "Please provide an email" 48 | } 49 | ], 50 | valuePropName: "userEmail" 51 | }, 52 | { 53 | field: "Input", 54 | label: "Name", 55 | validations: [ 56 | { 57 | required: true, 58 | message: "Please provide an email" 59 | } 60 | ], 61 | valuePropName: "userName" 62 | }, 63 | { 64 | field: { 65 | type: "Input", 66 | props: { 67 | prefix: "$" 68 | } 69 | }, 70 | label: "Name", 71 | validations: [ 72 | { 73 | required: true, 74 | message: "Please provide an email" 75 | } 76 | ], 77 | valuePropName: "userName" 78 | } 79 | ], 80 | null, 81 | 2 82 | ); 83 | class Declarator extends Component { 84 | state = { 85 | declarations: initailDeclarations 86 | }; 87 | // handleChange = e => this.props.onChange (e.target.value); 88 | 89 | handleChange = newValue => { 90 | this.setState({ declarations: newValue }); 91 | }; 92 | 93 | generate = () => { 94 | const declarations = this.state; 95 | this.props.generate( 96 | JSON.parse(declarations.declarations.replace(/\n/g, "")) 97 | ); 98 | }; 99 | 100 | render() { 101 | const { declarations } = this.state; 102 | return ( 103 | 104 | 124 | 131 | 132 | ); 133 | } 134 | } 135 | 136 | export default Declarator; 137 | -------------------------------------------------------------------------------- /src/components/ErrorDisplayer.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Table } from "antd"; 3 | 4 | const columns = [ 5 | { 6 | title: "Error Key", 7 | dataIndex: "dataPath", 8 | key: "dataPath" 9 | }, 10 | { 11 | title: "Error Message", 12 | dataIndex: "message", 13 | key: "message" 14 | } 15 | ]; 16 | 17 | class ErrorDisplay extends Component { 18 | render() { 19 | return ( 20 |
27 | {this.props.errors && this.props.errors.length ? ( 28 | 33 | ) : ( 34 |
Error will appear here
35 | )} 36 | 37 | ); 38 | } 39 | } 40 | 41 | export default ErrorDisplay; 42 | -------------------------------------------------------------------------------- /src/core/generator.js: -------------------------------------------------------------------------------- 1 | import prettier from "prettier/standalone"; 2 | import plugins from "prettier/parser-babylon"; 3 | import { pipe } from "../common/utils"; 4 | import { validateSchema } from "./validator"; 5 | 6 | const fieldGenerator = ({ field, label }) => { 7 | if (typeof field === "object") { 8 | const { type, props, options } = field; 9 | 10 | const propsStr = props 11 | ? Object.keys(props) 12 | .map(p => `${p}="${props[p]}"`) 13 | .join(" ") 14 | : ""; 15 | 16 | if (type === "Select") { 17 | return `<${type} ${propsStr}>{${ 18 | options.varName 19 | }.map(o => )}`; 22 | } 23 | 24 | if (type === "Input") { 25 | return `<${type} ${propsStr} />`; 26 | } 27 | 28 | if (type === "Checkbox") { 29 | return `<${type} ${propsStr}>${label}`; 30 | } 31 | } 32 | return `<${field} />`; 33 | }; 34 | 35 | const generator = declarations => { 36 | const formItems = declarations.map(d => { 37 | return `\n{/** ${d.label} Field */} 38 | 39 | {getFieldDecorator ('${d.valuePropName}', { 40 | ${d.initialValue ? `initialValue: ${d.initialValue},` : ``} 41 | rules: ${JSON.stringify(d.validations)}, 42 | }) (${fieldGenerator(d)})} 43 | `; 44 | }); 45 | return formItems; 46 | }; 47 | 48 | const commentWrapper = codeItems => 49 | `${codeItems.join("\n\n")}`; 50 | 51 | const formatCode = codeString => 52 | prettier.format(codeString, { parser: "babylon", plugins: [plugins] }); 53 | 54 | const wrapper = declarations => { 55 | const { status: isValid, errors } = validateSchema(declarations); 56 | 57 | let code; 58 | if (isValid) { 59 | code = pipe( 60 | [declarations], 61 | generator, 62 | commentWrapper, 63 | formatCode 64 | )[0]; 65 | } 66 | 67 | return { isValid, errors, code }; 68 | }; 69 | 70 | export default wrapper; 71 | -------------------------------------------------------------------------------- /src/core/validator.js: -------------------------------------------------------------------------------- 1 | import Ajv from "ajv"; 2 | 3 | // TODO: Break the validator in parts using the dependency keyword 4 | const VALIDATOR_SCHEMA = { 5 | type: "array", 6 | title: "Antd form code schema", 7 | description: "Schema to generate antd lib specific form code", 8 | minItems: 1, 9 | items: { 10 | type: "object", 11 | properties: { 12 | field: { 13 | if: { type: "string" }, 14 | then: { enum: ["Input"] }, 15 | else: { 16 | type: "object", 17 | properties: { 18 | type: { 19 | type: "string", 20 | enum: ["Select", "Input", "Checkbox"] 21 | }, 22 | props: { 23 | type: "object", 24 | patternProperties: { 25 | "[sS]*": { 26 | anyOf: [{ type: "string" }, { type: "number" }] 27 | } 28 | } 29 | }, 30 | options: { 31 | type: "object", 32 | properties: { 33 | varName: { 34 | type: "string" 35 | }, 36 | labelKey: { 37 | type: "string" 38 | }, 39 | valueKey: { 40 | type: "string" 41 | } 42 | }, 43 | required: ["varName"] 44 | } 45 | }, 46 | required: ["type"] 47 | } 48 | }, 49 | label: { 50 | type: "string" 51 | }, 52 | validations: { 53 | type: "array", 54 | minItems: 1, 55 | items: { 56 | type: "object", 57 | properties: { 58 | message: { type: "string" }, 59 | enums: { type: "string" }, 60 | len: { type: "number" }, 61 | max: { type: "number" }, 62 | min: { type: "number" }, 63 | pattern: { type: "string" }, 64 | required: { type: "boolean" }, 65 | type: { 66 | type: "string", 67 | enum: [ 68 | "string", 69 | "number", 70 | "boolean", 71 | "method", 72 | "regexp", 73 | "integer", 74 | "float", 75 | "array", 76 | "object", 77 | "enum", 78 | "date", 79 | "url", 80 | "hex", 81 | "email" 82 | ] 83 | } 84 | }, 85 | required: ["message"] 86 | } 87 | }, 88 | valuePropName: { 89 | type: "string" 90 | } 91 | }, 92 | required: ["field", "label", "valuePropName"] 93 | } 94 | }; 95 | 96 | export const validateSchema = data => { 97 | const ajv = new Ajv(); // options can be passed, e.g. {allErrors: true} 98 | const validate = ajv.compile(VALIDATOR_SCHEMA); 99 | const isValid = validate(data); 100 | 101 | let returnVal; 102 | if (!isValid) { 103 | returnVal = { 104 | status: false, 105 | errors: validate.errors 106 | }; 107 | } else { 108 | returnVal = { 109 | status: true 110 | }; 111 | } 112 | 113 | return returnVal; 114 | }; 115 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import "~antd/dist/antd.css"; 2 | 3 | body { 4 | margin: 0; 5 | padding: 0; 6 | font-family: sans-serif; 7 | } 8 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' + 44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ' 45 | ); 46 | }); 47 | } else { 48 | // Is not local host. Just register service worker 49 | registerValidSW(swUrl); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | installingWorker.onstatechange = () => { 62 | if (installingWorker.state === 'installed') { 63 | if (navigator.serviceWorker.controller) { 64 | // At this point, the old content will have been purged and 65 | // the fresh content will have been added to the cache. 66 | // It's the perfect time to display a "New content is 67 | // available; please refresh." message in your web app. 68 | console.log('New content is available; please refresh.'); 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.'); 74 | } 75 | } 76 | }; 77 | }; 78 | }) 79 | .catch(error => { 80 | console.error('Error during service worker registration:', error); 81 | }); 82 | } 83 | 84 | function checkValidServiceWorker(swUrl) { 85 | // Check if the service worker can be found. If it can't reload the page. 86 | fetch(swUrl) 87 | .then(response => { 88 | // Ensure service worker exists, and that we really are getting a JS file. 89 | if ( 90 | response.status === 404 || 91 | response.headers.get('content-type').indexOf('javascript') === -1 92 | ) { 93 | // No service worker found. Probably a different app. Reload the page. 94 | navigator.serviceWorker.ready.then(registration => { 95 | registration.unregister().then(() => { 96 | window.location.reload(); 97 | }); 98 | }); 99 | } else { 100 | // Service worker found. Proceed as normal. 101 | registerValidSW(swUrl); 102 | } 103 | }) 104 | .catch(() => { 105 | console.log( 106 | 'No internet connection found. App is running in offline mode.' 107 | ); 108 | }); 109 | } 110 | 111 | export function unregister() { 112 | if ('serviceWorker' in navigator) { 113 | navigator.serviceWorker.ready.then(registration => { 114 | registration.unregister(); 115 | }); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/validator.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajatvijay/antd-form-code-generator/785b06c6b1c7383b61d6a68d7d3a64d6601e3efb/src/validator.js --------------------------------------------------------------------------------