@mittwald/flow-remote-react-renderer 0.2.0-alpha.253 → 0.2.0-alpha.254
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/js/components/Form.mjs +26 -11
- package/dist/js/components/Form.mjs.map +1 -1
- package/dist/js/components/lib/prepareFormData.mjs +25 -0
- package/dist/js/components/lib/prepareFormData.mjs.map +1 -0
- package/dist/types/components/Form.d.ts +8 -2
- package/dist/types/components/Form.d.ts.map +1 -1
- package/dist/types/components/lib/prepareFormData.d.ts +2 -0
- package/dist/types/components/lib/prepareFormData.d.ts.map +1 -0
- package/package.json +8 -6
- package/dist/js/components/lib/getFormDataObject.mjs +0 -26
- package/dist/js/components/lib/getFormDataObject.mjs.map +0 -1
- package/dist/types/components/lib/getFormDataObject.d.ts +0 -4
- package/dist/types/components/lib/getFormDataObject.d.ts.map +0 -1
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
/* */
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
const Form =
|
|
4
|
+
import "react";
|
|
5
|
+
import { prepareFormData } from "./lib/prepareFormData.mjs";
|
|
6
|
+
const Form = (props) => {
|
|
7
7
|
const {
|
|
8
|
-
action:
|
|
8
|
+
action: onActionFromProps,
|
|
9
9
|
onSubmit: onSubmitFromProps,
|
|
10
|
+
ref,
|
|
10
11
|
...rest
|
|
11
12
|
} = props;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
13
|
+
const onSubmit = async (event) => {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
const resolvedData = await prepareFormData(
|
|
16
|
+
new FormData(event.currentTarget)
|
|
17
|
+
);
|
|
18
|
+
await (onSubmitFromProps == null ? void 0 : onSubmitFromProps(resolvedData));
|
|
19
|
+
};
|
|
20
|
+
const onAction = async (formData) => {
|
|
21
|
+
const resolvedFormData = await prepareFormData(formData);
|
|
22
|
+
await (onActionFromProps == null ? void 0 : onActionFromProps(resolvedFormData));
|
|
23
|
+
};
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
"form",
|
|
26
|
+
{
|
|
27
|
+
...rest,
|
|
28
|
+
ref,
|
|
29
|
+
action: onActionFromProps ? onAction : void 0,
|
|
30
|
+
onSubmit: onSubmitFromProps ? onSubmit : void 0
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
};
|
|
19
34
|
export {
|
|
20
35
|
Form
|
|
21
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.mjs","sources":["../../../src/components/Form.tsx"],"sourcesContent":["import {\n type FC,\n type FormEvent,\n type
|
|
1
|
+
{"version":3,"file":"Form.mjs","sources":["../../../src/components/Form.tsx"],"sourcesContent":["import {\n type FC,\n type FormEvent,\n type PropsWithChildren,\n type RefObject,\n} from \"react\";\nimport React from \"react\";\nimport { prepareFormData } from \"@/components/lib/prepareFormData\";\n\ntype FormProps = {\n action?: (data: FormData) => void | Promise<void>;\n onSubmit?: (data: FormData) => void | Promise<void>;\n ref?: RefObject<HTMLFormElement>;\n} & PropsWithChildren;\n\nexport const Form: FC<FormProps> = (props) => {\n const {\n action: onActionFromProps,\n onSubmit: onSubmitFromProps,\n ref,\n ...rest\n } = props;\n\n const onSubmit = async (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n const resolvedData = await prepareFormData(\n new FormData(event.currentTarget),\n );\n await onSubmitFromProps?.(resolvedData);\n };\n\n const onAction = async (formData: FormData) => {\n const resolvedFormData = await prepareFormData(formData);\n await onActionFromProps?.(resolvedFormData);\n };\n\n return (\n <form\n {...rest}\n ref={ref}\n action={onActionFromProps ? onAction : undefined}\n onSubmit={onSubmitFromProps ? onSubmit : undefined}\n />\n );\n};\n"],"names":[],"mappings":";;;AAea,MAAA,OAAsB,CAAC,UAAU;AACtC,QAAA;AAAA,IACJ,QAAQ;AAAA,IACR,UAAU;AAAA,IACV;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEE,QAAA,WAAW,OAAO,UAAsC;AAC5D,UAAM,eAAe;AACrB,UAAM,eAAe,MAAM;AAAA,MACzB,IAAI,SAAS,MAAM,aAAa;AAAA,IAClC;AACA,WAAM,uDAAoB;AAAA,EAC5B;AAEM,QAAA,WAAW,OAAO,aAAuB;AACvC,UAAA,mBAAmB,MAAM,gBAAgB,QAAQ;AACvD,WAAM,uDAAoB;AAAA,EAC5B;AAGE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA,QAAQ,oBAAoB,WAAW;AAAA,MACvC,UAAU,oBAAoB,WAAW;AAAA,IAAA;AAAA,EAC3C;AAEJ;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
/* */
|
|
3
|
+
import { addAwaitedArrayBuffer } from "@mittwald/flow-core";
|
|
4
|
+
const prepareFormData = async (formData) => {
|
|
5
|
+
const preparedFormData = new FormData();
|
|
6
|
+
for (const [fieldName, value] of formData) {
|
|
7
|
+
const preparedValue = value;
|
|
8
|
+
if (preparedValue instanceof File) {
|
|
9
|
+
if (!preparedValue.name || preparedValue.size <= 0) {
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
await addAwaitedArrayBuffer(preparedValue);
|
|
13
|
+
}
|
|
14
|
+
if (preparedFormData.has(fieldName)) {
|
|
15
|
+
preparedFormData.append(fieldName, preparedValue);
|
|
16
|
+
} else {
|
|
17
|
+
preparedFormData.set(fieldName, preparedValue);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return preparedFormData;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
prepareFormData
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=prepareFormData.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareFormData.mjs","sources":["../../../../src/components/lib/prepareFormData.ts"],"sourcesContent":["import { addAwaitedArrayBuffer } from \"@mittwald/flow-core\";\n\nexport const prepareFormData = async (\n formData: FormData,\n): Promise<FormData> => {\n const preparedFormData = new FormData();\n for (const [fieldName, value] of formData) {\n const preparedValue = value;\n if (preparedValue instanceof File) {\n if (!preparedValue.name || preparedValue.size <= 0) {\n break;\n }\n\n await addAwaitedArrayBuffer(preparedValue);\n }\n\n if (preparedFormData.has(fieldName)) {\n preparedFormData.append(fieldName, preparedValue);\n } else {\n preparedFormData.set(fieldName, preparedValue);\n }\n }\n\n return preparedFormData;\n};\n"],"names":[],"mappings":";AAEa,MAAA,kBAAkB,OAC7B,aACsB;AAChB,QAAA,mBAAmB,IAAI,SAAS;AACtC,aAAW,CAAC,WAAW,KAAK,KAAK,UAAU;AACzC,UAAM,gBAAgB;AACtB,QAAI,yBAAyB,MAAM;AACjC,UAAI,CAAC,cAAc,QAAQ,cAAc,QAAQ,GAAG;AAClD;AAAA,MAAA;AAGF,YAAM,sBAAsB,aAAa;AAAA,IAAA;AAGvC,QAAA,iBAAiB,IAAI,SAAS,GAAG;AAClB,uBAAA,OAAO,WAAW,aAAa;AAAA,IAAA,OAC3C;AACY,uBAAA,IAAI,WAAW,aAAa;AAAA,IAAA;AAAA,EAC/C;AAGK,SAAA;AACT;"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
|
|
1
|
+
import { FC, PropsWithChildren, RefObject } from 'react';
|
|
2
|
+
type FormProps = {
|
|
3
|
+
action?: (data: FormData) => void | Promise<void>;
|
|
4
|
+
onSubmit?: (data: FormData) => void | Promise<void>;
|
|
5
|
+
ref?: RefObject<HTMLFormElement>;
|
|
6
|
+
} & PropsWithChildren;
|
|
7
|
+
export declare const Form: FC<FormProps>;
|
|
8
|
+
export {};
|
|
3
9
|
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAAE,EAEP,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,GAAG,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC;CAClC,GAAG,iBAAiB,CAAC;AAEtB,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CA6B9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareFormData.d.ts","sourceRoot":"","sources":["../../../../src/components/lib/prepareFormData.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAC1B,UAAU,QAAQ,KACjB,OAAO,CAAC,QAAQ,CAoBlB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-remote-react-renderer",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.254",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React rendering for Flow Remote Elements",
|
|
6
6
|
"homepage": "https://mittwald.github.io/flow",
|
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
"test:compile": "tsc --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mittwald/ext-bridge": "0.2.0-alpha.
|
|
32
|
-
"@mittwald/flow-
|
|
33
|
-
"@mittwald/flow-remote-
|
|
31
|
+
"@mittwald/ext-bridge": "0.2.0-alpha.254",
|
|
32
|
+
"@mittwald/flow-core": "",
|
|
33
|
+
"@mittwald/flow-remote-core": "0.2.0-alpha.254",
|
|
34
|
+
"@mittwald/flow-remote-elements": "0.2.0-alpha.254",
|
|
34
35
|
"@mittwald/react-use-promise": "^3.0.4",
|
|
35
36
|
"@mittwald/remote-dom-react": "1.2.2-mittwald.10",
|
|
36
37
|
"@types/react": "^19.1.6",
|
|
@@ -39,7 +40,8 @@
|
|
|
39
40
|
"remeda": "^2.22.3"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@mittwald/flow-
|
|
43
|
+
"@mittwald/flow-core": "",
|
|
44
|
+
"@mittwald/flow-react-components": "0.2.0-alpha.254",
|
|
43
45
|
"@mittwald/typescript-config": "",
|
|
44
46
|
"@types/node": "^22.15.23",
|
|
45
47
|
"nx": "^20.8.2",
|
|
@@ -67,5 +69,5 @@
|
|
|
67
69
|
"optional": true
|
|
68
70
|
}
|
|
69
71
|
},
|
|
70
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "ba87c4e8b8392c3c58afa3aed5606e960496596b"
|
|
71
73
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
/* */
|
|
3
|
-
const getFormDataObject = (formData) => Object.fromEntries(Array.from(formData.entries()));
|
|
4
|
-
const getFormDataObjectFromEvent = (element) => {
|
|
5
|
-
const form = new FormData(element.currentTarget);
|
|
6
|
-
const formKeys = form.keys().toArray();
|
|
7
|
-
const data = Object.fromEntries(form);
|
|
8
|
-
[...element.currentTarget.elements].filter(
|
|
9
|
-
(element2) => element2 && "name" in element2 && typeof element2.name === "string" && formKeys.includes(element2.name)
|
|
10
|
-
).filter(
|
|
11
|
-
(matchingElement) => matchingElement instanceof HTMLInputElement && matchingElement.type === "file" || matchingElement instanceof HTMLSelectElement
|
|
12
|
-
).forEach((matchingFileElement) => {
|
|
13
|
-
const fieldName = matchingFileElement.name;
|
|
14
|
-
if (matchingFileElement instanceof HTMLInputElement) {
|
|
15
|
-
data[fieldName] = matchingFileElement.files ?? new FileList();
|
|
16
|
-
} else {
|
|
17
|
-
data[fieldName] = matchingFileElement.value;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return data;
|
|
21
|
-
};
|
|
22
|
-
export {
|
|
23
|
-
getFormDataObject,
|
|
24
|
-
getFormDataObjectFromEvent
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=getFormDataObject.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFormDataObject.mjs","sources":["../../../../src/components/lib/getFormDataObject.ts"],"sourcesContent":["import type { FormEvent } from \"react\";\n\nexport const getFormDataObject = (\n formData: FormData,\n): Record<string, unknown> =>\n Object.fromEntries(Array.from(formData.entries()));\n\nexport const getFormDataObjectFromEvent = (\n element: FormEvent<HTMLFormElement>,\n): Record<string, unknown> => {\n const form = new FormData(element.currentTarget);\n const formKeys = form.keys().toArray();\n const data: Record<string, unknown> = Object.fromEntries(form);\n\n // file and select elements with multiple values are not correctly returned\n // by getValues over FormData so we handle them by our self\n [...element.currentTarget.elements]\n .filter(\n (element) =>\n element &&\n \"name\" in element &&\n typeof element.name === \"string\" &&\n formKeys.includes(element.name),\n )\n .filter(\n (\n matchingElement,\n ): matchingElement is HTMLInputElement | HTMLSelectElement =>\n (matchingElement instanceof HTMLInputElement &&\n matchingElement.type === \"file\") ||\n matchingElement instanceof HTMLSelectElement,\n )\n .forEach((matchingFileElement) => {\n const fieldName = matchingFileElement.name;\n if (matchingFileElement instanceof HTMLInputElement) {\n data[fieldName] = matchingFileElement.files ?? new FileList();\n } else {\n data[fieldName] = matchingFileElement.value;\n }\n });\n\n return data;\n};\n"],"names":["element"],"mappings":"AAEa,MAAA,oBAAoB,CAC/B,aAEA,OAAO,YAAY,MAAM,KAAK,SAAS,SAAS,CAAC;AAEtC,MAAA,6BAA6B,CACxC,YAC4B;AAC5B,QAAM,OAAO,IAAI,SAAS,QAAQ,aAAa;AAC/C,QAAM,WAAW,KAAK,KAAK,EAAE,QAAQ;AAC/B,QAAA,OAAgC,OAAO,YAAY,IAAI;AAI7D,GAAC,GAAG,QAAQ,cAAc,QAAQ,EAC/B;AAAA,IACC,CAACA,aACCA,YACA,UAAUA,YACV,OAAOA,SAAQ,SAAS,YACxB,SAAS,SAASA,SAAQ,IAAI;AAAA,EAAA,EAEjC;AAAA,IACC,CACE,oBAEC,2BAA2B,oBAC1B,gBAAgB,SAAS,UAC3B,2BAA2B;AAAA,EAAA,EAE9B,QAAQ,CAAC,wBAAwB;AAChC,UAAM,YAAY,oBAAoB;AACtC,QAAI,+BAA+B,kBAAkB;AACnD,WAAK,SAAS,IAAI,oBAAoB,SAAS,IAAI,SAAS;AAAA,IAAA,OACvD;AACA,WAAA,SAAS,IAAI,oBAAoB;AAAA,IAAA;AAAA,EACxC,CACD;AAEI,SAAA;AACT;"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { FormEvent } from 'react';
|
|
2
|
-
export declare const getFormDataObject: (formData: FormData) => Record<string, unknown>;
|
|
3
|
-
export declare const getFormDataObjectFromEvent: (element: FormEvent<HTMLFormElement>) => Record<string, unknown>;
|
|
4
|
-
//# sourceMappingURL=getFormDataObject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFormDataObject.d.ts","sourceRoot":"","sources":["../../../../src/components/lib/getFormDataObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,eAAO,MAAM,iBAAiB,GAC5B,UAAU,QAAQ,KACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAC2B,CAAC;AAErD,eAAO,MAAM,0BAA0B,GACrC,SAAS,SAAS,CAAC,eAAe,CAAC,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAiCxB,CAAC"}
|