core: common directory for packages (#114)

This commit is contained in:
Ayo 2022-10-21 14:05:23 +02:00
parent b96e3383dc
commit 4fd6f33fe9
13 changed files with 92 additions and 39 deletions

29
package-lock.json generated
View file

@ -13,7 +13,8 @@
"packages/validator", "packages/validator",
"apps/demo", "apps/demo",
"apps/docs", "apps/docs",
"apps/landing-page" "apps/landing-page",
"packages/common"
] ]
}, },
"apps/demo": { "apps/demo": {
@ -2821,6 +2822,10 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/common": {
"resolved": "packages/common",
"link": true
},
"node_modules/common-ancestor-path": { "node_modules/common-ancestor-path": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz", "resolved": "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz",
@ -10466,10 +10471,18 @@
"url": "https://github.com/sponsors/wooorm" "url": "https://github.com/sponsors/wooorm"
} }
}, },
"packages/common": {
"version": "0.0.0",
"license": "MIT",
"devDependencies": {}
},
"packages/form": { "packages/form": {
"name": "@astro-reactive/form", "name": "@astro-reactive/form",
"version": "0.4.6", "version": "0.4.6",
"license": "MIT", "license": "MIT",
"dependencies": {
"common": "file:packages/common"
},
"devDependencies": { "devDependencies": {
"@types/chai": "^4.3.3", "@types/chai": "^4.3.3",
"@types/eslint": "^8.4.6", "@types/eslint": "^8.4.6",
@ -10493,6 +10506,11 @@
"astro": "^1.5.0" "astro": "^1.5.0"
} }
}, },
"packages/form/node_modules/common": {
"resolved": "packages/form/packages/common",
"link": true
},
"packages/form/packages/common": {},
"packages/validator": { "packages/validator": {
"name": "@astro-reactive/validator", "name": "@astro-reactive/validator",
"version": "0.0.5", "version": "0.0.5",
@ -10716,6 +10734,7 @@
"astro": "^1.5.0", "astro": "^1.5.0",
"astro-component-tester": "^0.6.0", "astro-component-tester": "^0.6.0",
"chai": "^4.3.6", "chai": "^4.3.6",
"common": "file:packages/common",
"eslint": "^8.23.1", "eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
@ -10723,6 +10742,11 @@
"prettier": "^2.7.1", "prettier": "^2.7.1",
"prettier-plugin-astro": "^0.5.4", "prettier-plugin-astro": "^0.5.4",
"typescript": "^4.8.3" "typescript": "^4.8.3"
},
"dependencies": {
"common": {
"version": "file:packages/form/packages/common"
}
} }
}, },
"@astro-reactive/validator": { "@astro-reactive/validator": {
@ -12640,6 +12664,9 @@
"integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==",
"dev": true "dev": true
}, },
"common": {
"version": "file:packages/common"
},
"common-ancestor-path": { "common-ancestor-path": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz", "resolved": "https://registry.npmjs.org/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz",

View file

@ -34,6 +34,7 @@
"packages/validator", "packages/validator",
"apps/demo", "apps/demo",
"apps/docs", "apps/docs",
"apps/landing-page" "apps/landing-page",
"packages/common"
] ]
} }

View file

@ -0,0 +1,20 @@
{
"name": "common",
"version": "0.0.0",
"description": "Common code for Astro Reactive Packages",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ayoayco/astro-reactive-library.git"
},
"author": "Ayo Ayco",
"license": "MIT",
"bugs": {
"url": "https://github.com/ayoayco/astro-reactive-library/issues"
},
"homepage": "https://github.com/ayoayco/astro-reactive-library#readme"
}

View file

@ -1,5 +1,5 @@
/** /**
* ControlType - determines the type of form control * `ControlType` determines the type of form control
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
*/ */
export type ControlType = export type ControlType =

View file

@ -0,0 +1 @@
export * from "./control.types";

View file

@ -1,4 +1,4 @@
/** @type {import("@types/eslint").Linter.Config} */ /** @type {import("@types/eslint").Linter.Config} */
module.exports = { module.exports = {
extends: '../configs/.eslintrc.cjs', extends: '../common/configs/.eslintrc.cjs',
}; };

View file

@ -20,38 +20,40 @@ const formName = Array.isArray(form) ? null : form?.name || null;
{ {
Array.isArray(form) Array.isArray(form)
? form?.map((group) => <FieldSet showValidationHints={showValidationHints} group={group} />) ? form?.map((group) => <FieldSet showValidationHints={showValidationHints} group={group} />)
: form?.controls.map((control) => ( : form?.controls.map((control) =>
control.type === "radio" ? control.type === 'radio' ? (
(
[ [
(<Field showValidationHints={showValidationHints} control={control} showOnlyLabel={true} />), <Field
showValidationHints={showValidationHints}
control={control}
showOnlyLabel={true}
/>,
...(control as Radio)?.value?.map((v: string | RadioOption) => ( ...(control as Radio)?.value?.map((v: string | RadioOption) => (
<Field <Field
showValidationHints={showValidationHints} showValidationHints={showValidationHints}
control={ control={
(typeof v === "string") ? typeof v === 'string'
new FormControl({ ? new FormControl({
name: control.name, name: control.name,
type: "radio", type: 'radio',
id: control.name + v, id: control.name + v,
label: v, label: v,
value: v value: v,
}) : })
new FormControl({ : new FormControl({
name: control.name, name: control.name,
type: "radio", type: 'radio',
id: control.name + v.label, id: control.name + v.label,
...(v as RadioOption) ...(v as RadioOption),
}) })
} }
/> />
)) )),
] ]
) : ) : (
(
<Field showValidationHints={showValidationHints} control={control} /> <Field showValidationHints={showValidationHints} control={control} />
) )
)) )
} }
{ {
submitControl && ( submitControl && (

View file

@ -1,4 +1,4 @@
import type { ControlConfig, ControlType, RadioOption } from './form-control-types'; import type { ControlConfig, ControlType, RadioOption } from 'common/types';
export class FormControl { export class FormControl {
private _name = ''; private _name = '';

View file

@ -1,4 +1,4 @@
import type { ControlConfig } from './form-control-types'; import type { ControlConfig } from 'common/types';
import { FormControl } from './form-control'; import { FormControl } from './form-control';
export class FormGroup { export class FormGroup {

View file

@ -1,3 +1,2 @@
export * from './form-control'; export * from './form-control';
export * from './form-group'; export * from './form-group';
export * from './form-control-types';

View file

@ -54,5 +54,8 @@
"peerDependencies": { "peerDependencies": {
"astro": "^1.5.0" "astro": "^1.5.0"
}, },
"dependencies": {
"common": "file:packages/common"
},
"license": "MIT" "license": "MIT"
} }

View file

@ -1,4 +1,4 @@
/** @type {import("@types/eslint").Linter.Config} */ /** @type {import("@types/eslint").Linter.Config} */
module.exports = { module.exports = {
extends: '../configs/.eslintrc.cjs', extends: '../common/configs/.eslintrc.cjs',
}; };