formeact 0.0.2 → 0.0.4
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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
export async function loadJson(name) {
|
|
4
|
+
const file = await fs.readFile(process.cwd() + "/src/assets/" + name + ".json", "utf-8");
|
|
5
|
+
return JSON.parse(file);
|
|
6
|
+
}
|
|
7
|
+
export async function loadForm(name) {
|
|
8
|
+
if (!name)
|
|
9
|
+
throw new Error("Form not found");
|
|
10
|
+
try {
|
|
11
|
+
return loadJson(`forms/${name}`);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
throw new Error(`Couldn't load form ${name}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { cn } from "@bouko/style";
|
|
5
|
-
import Image from "next/image";
|
|
6
5
|
import Placeholder from "../../assets/icons/cover.png";
|
|
7
6
|
import Camera from "../../assets/icons/camera.svg";
|
|
8
7
|
export function ImageUploader({ style, placeholder, value, update, disabled = false }) {
|
|
@@ -23,7 +22,7 @@ export function ImageUploader({ style, placeholder, value, update, disabled = fa
|
|
|
23
22
|
return;
|
|
24
23
|
update?.(file);
|
|
25
24
|
};
|
|
26
|
-
return (_jsxs("div", { className: cn(styles.container, style), onClick: uploadFile, children: [_jsx("input", { type: "file", className: "hidden", onChange: handleFileChange, ref: ref }), _jsx(
|
|
25
|
+
return (_jsxs("div", { className: cn(styles.container, style), onClick: uploadFile, children: [_jsx("input", { type: "file", className: "hidden", onChange: handleFileChange, ref: ref }), _jsx("img", { src: preview || placeholder || Placeholder, className: "top-0 left-0 w-full h-full", alt: "Image Uploader" }), _jsx("div", { className: "flex justify-center items-center w-full h-full z-10 opacity-0 hover:opacity-50 bg-background-light/80 duration-200 cursor-pointer", children: _jsx(Camera, { className: "text-xl text-primary-light" }) })] }));
|
|
27
26
|
}
|
|
28
27
|
const styles = {
|
|
29
28
|
container: "relative shrink-0 border border-border rounded-md overflow-hidden",
|
package/dist/core/hooks.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FormControls } from "@bouko/form";
|
|
2
1
|
import type { JsonMap } from "@bouko/ts";
|
|
3
2
|
/**
|
|
4
3
|
* React hook for managing form state with type-safety
|
|
@@ -14,6 +13,11 @@ import type { JsonMap } from "@bouko/ts";
|
|
|
14
13
|
* @param {Partial<T>} init - The initial form data.
|
|
15
14
|
* @returns {FormControls} Utils to control the form.
|
|
16
15
|
**/
|
|
16
|
+
type FormControls<T, K extends keyof T> = {
|
|
17
|
+
data: Partial<T>;
|
|
18
|
+
update: (id: K, x: T[K]) => void;
|
|
19
|
+
clear: () => void;
|
|
20
|
+
};
|
|
17
21
|
type JsonMapWithFiles = {
|
|
18
22
|
[key: string]: JsonValueWithFile | JsonValueWithFile[];
|
|
19
23
|
};
|
package/dist/core/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "formeact",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@bouko/next": "^1.6.6",
|
|
25
24
|
"@bouko/notify": "^0.1.8",
|
|
26
25
|
"@bouko/react": "^2.6.6",
|
|
27
26
|
"@bouko/style": "^0.1.7",
|