next-anvil 0.3.1 → 0.3.3
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/dist/components/fields/DateField.d.ts +1 -1
- package/dist/components/fields/EmailField.d.ts +1 -1
- package/dist/components/fields/FieldWrapper.d.ts +1 -1
- package/dist/components/fields/NumberField.d.ts +1 -1
- package/dist/components/fields/SelectField.d.ts +1 -1
- package/dist/components/fields/TextField.d.ts +1 -1
- package/dist/components/fields/TextareaField.d.ts +1 -1
- package/package.json +3 -4
- package/dist/components/AnvilForm.d.ts +0 -14
- package/dist/components/AnvilForm.d.ts.map +0 -1
- package/dist/components/AnvilForm.js +0 -68
- package/dist/components/AnvilForm.js.map +0 -1
- package/dist/components/index.d.ts +0 -6
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -24
- package/dist/components/index.js.map +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides consistent label, error display, and styling
|
|
4
4
|
*/
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
|
-
import { FieldSize } from "
|
|
6
|
+
import { FieldSize } from "../../lib/fields/types";
|
|
7
7
|
interface FieldWrapperProps {
|
|
8
8
|
fieldId: string;
|
|
9
9
|
label?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NumberField - Number input field component
|
|
3
3
|
*/
|
|
4
|
-
import type { NumberFieldSchema } from "
|
|
4
|
+
import type { NumberFieldSchema } from "../../lib/fields/number";
|
|
5
5
|
interface NumberFieldProps {
|
|
6
6
|
fieldName: string;
|
|
7
7
|
fieldSchema: NumberFieldSchema;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SelectField - Select dropdown field component
|
|
3
3
|
*/
|
|
4
|
-
import type { SelectFieldSchema } from "
|
|
4
|
+
import type { SelectFieldSchema } from "../../lib/fields/select";
|
|
5
5
|
interface SelectFieldProps {
|
|
6
6
|
fieldName: string;
|
|
7
7
|
fieldSchema: SelectFieldSchema;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TextareaField - Textarea field component
|
|
3
3
|
*/
|
|
4
|
-
import type { TextareaFieldSchema } from "
|
|
4
|
+
import type { TextareaFieldSchema } from "../../lib/fields/textarea";
|
|
5
5
|
interface TextareaFieldProps {
|
|
6
6
|
fieldName: string;
|
|
7
7
|
fieldSchema: TextareaFieldSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-anvil",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "CLI tool for the Anvil framework - a Next.js framework for creating admin dashboards",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Juan Sanchez <juan.sanchez@stallionstudios.net>",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"LICENSE"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "tsc && tsc -p tsconfig.bin.json && node scripts/postbuild.js",
|
|
26
|
+
"build": "tsc && tsc-alias && tsc -p tsconfig.bin.json && tsc-alias -p tsconfig.bin.json && node scripts/postbuild.js",
|
|
27
27
|
"prepublishOnly": "npm run build",
|
|
28
28
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
29
29
|
},
|
|
@@ -37,9 +37,7 @@
|
|
|
37
37
|
"prisma"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"bcryptjs": "^3.0.3",
|
|
41
40
|
"commander": "^14.0.2",
|
|
42
|
-
"dotenv": "^16.4.5",
|
|
43
41
|
"pluralize-esm": "^9.0.5"
|
|
44
42
|
},
|
|
45
43
|
"peerDependencies": {
|
|
@@ -53,6 +51,7 @@
|
|
|
53
51
|
"postcss": "^8.5.6",
|
|
54
52
|
"postcss-cli": "^11.0.1",
|
|
55
53
|
"tailwindcss": "^4.1.18",
|
|
54
|
+
"tsc-alias": "^1.8.16",
|
|
56
55
|
"tsx": "^4.7.0",
|
|
57
56
|
"typescript": "^5.0.0"
|
|
58
57
|
},
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FormSchema } from "@/lib/form";
|
|
2
|
-
interface AnvilFormProps {
|
|
3
|
-
schema: FormSchema;
|
|
4
|
-
initialData?: Record<string, any>;
|
|
5
|
-
onSubmit: (data: Record<string, any>) => Promise<void>;
|
|
6
|
-
onCancel?: () => void;
|
|
7
|
-
submitting?: boolean;
|
|
8
|
-
errors?: Record<string, string>;
|
|
9
|
-
submitLabel?: string;
|
|
10
|
-
cancelLabel?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function AnvilForm({ schema, initialData, onSubmit, onCancel, submitting: externalSubmitting, errors: externalErrors, submitLabel, cancelLabel, }: AnvilFormProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=AnvilForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnvilForm.d.ts","sourceRoot":"","sources":["../../src/components/AnvilForm.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAUxC,UAAU,cAAc;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,WAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,cAAmB,EAC3B,WAAoB,EACpB,WAAsB,GACvB,EAAE,cAAc,2CAmJhB"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AnvilForm = AnvilForm;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const fields_1 = require("./fields");
|
|
8
|
-
function AnvilForm({ schema, initialData = {}, onSubmit, onCancel, submitting: externalSubmitting, errors: externalErrors = {}, submitLabel = "Save", cancelLabel = "Cancel", }) {
|
|
9
|
-
const [formData, setFormData] = (0, react_1.useState)(initialData);
|
|
10
|
-
const [internalSubmitting, setInternalSubmitting] = (0, react_1.useState)(false);
|
|
11
|
-
const [internalErrors, setInternalErrors] = (0, react_1.useState)({});
|
|
12
|
-
const submitting = externalSubmitting ?? internalSubmitting;
|
|
13
|
-
const errors = { ...internalErrors, ...externalErrors };
|
|
14
|
-
async function handleSubmit(e) {
|
|
15
|
-
e.preventDefault();
|
|
16
|
-
setInternalSubmitting(true);
|
|
17
|
-
setInternalErrors({});
|
|
18
|
-
try {
|
|
19
|
-
await onSubmit(formData);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
const errorMap = {};
|
|
23
|
-
if (error.field) {
|
|
24
|
-
errorMap[error.field] = error.message;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
errorMap._general = error.message || "An error occurred";
|
|
28
|
-
}
|
|
29
|
-
setInternalErrors(errorMap);
|
|
30
|
-
}
|
|
31
|
-
finally {
|
|
32
|
-
setInternalSubmitting(false);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function renderField(fieldName, fieldSchema, value) {
|
|
36
|
-
// Skip hidden fields in form rendering
|
|
37
|
-
if (fieldSchema.type === "hidden") {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const fieldError = errors[fieldName];
|
|
41
|
-
const isDisabled = submitting || fieldSchema.readOnly;
|
|
42
|
-
const commonProps = {
|
|
43
|
-
fieldName,
|
|
44
|
-
fieldSchema: fieldSchema,
|
|
45
|
-
value,
|
|
46
|
-
error: fieldError,
|
|
47
|
-
disabled: isDisabled,
|
|
48
|
-
};
|
|
49
|
-
switch (fieldSchema.type) {
|
|
50
|
-
case "text":
|
|
51
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.TextField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
52
|
-
case "email":
|
|
53
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.EmailField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
54
|
-
case "select":
|
|
55
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.SelectField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
56
|
-
case "date":
|
|
57
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.DateField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
58
|
-
case "number":
|
|
59
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.NumberField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
60
|
-
case "textarea":
|
|
61
|
-
return ((0, jsx_runtime_1.jsx)(fields_1.TextareaField, { ...commonProps, onChange: (val) => setFormData({ ...formData, [fieldName]: val }) }, fieldName));
|
|
62
|
-
default:
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return ((0, jsx_runtime_1.jsxs)("form", { onSubmit: handleSubmit, className: "bg-white shadow rounded-lg p-6", children: [errors._general && ((0, jsx_runtime_1.jsxs)("div", { className: "mb-6 p-4 bg-red-50 border border-red-200 rounded-md text-red-700", children: [(0, jsx_runtime_1.jsx)("p", { className: "font-medium", children: "Error" }), (0, jsx_runtime_1.jsx)("p", { className: "text-sm mt-1", children: errors._general })] })), (0, jsx_runtime_1.jsx)("div", { className: "grid grid-cols-4 gap-6", children: Object.entries(schema.fields || {}).map(([fieldName, fieldSchema]) => renderField(fieldName, fieldSchema, formData[fieldName])) }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-8 flex gap-3 border-t border-gray-200 pt-6", children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: submitting, className: "px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors", children: submitting ? "Saving..." : submitLabel }), onCancel && ((0, jsx_runtime_1.jsx)("button", { type: "button", onClick: onCancel, disabled: submitting, className: "px-4 py-2 bg-gray-200 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-300 disabled:opacity-50 transition-colors", children: cancelLabel }))] })] }));
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=AnvilForm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnvilForm.js","sourceRoot":"","sources":["../../src/components/AnvilForm.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAyBb,8BA4JC;;AAnLD,iCAAiC;AAGjC,qCAOkB;AAalB,SAAgB,SAAS,CAAC,EACxB,MAAM,EACN,WAAW,GAAG,EAAE,EAChB,QAAQ,EACR,QAAQ,EACR,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,cAAc,GAAG,EAAE,EAC3B,WAAW,GAAG,MAAM,EACpB,WAAW,GAAG,QAAQ,GACP;IACf,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAsB,WAAW,CAAC,CAAC;IAC3E,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,IAAA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;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,UAAU,CAAC"}
|
package/dist/components/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Anvil Components - Main export file
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AnvilForm = void 0;
|
|
21
|
-
var AnvilForm_1 = require("./AnvilForm");
|
|
22
|
-
Object.defineProperty(exports, "AnvilForm", { enumerable: true, get: function () { return AnvilForm_1.AnvilForm; } });
|
|
23
|
-
__exportStar(require("./fields"), exports);
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,2CAAyB"}
|