@fairys/valtio-form-basic 0.0.8

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,125 @@
1
+ import { createContext, useContext, useMemo, useRef } from "react";
2
+ import clsx from "clsx";
3
+ import { proxy, useSnapshot } from "valtio";
4
+ class FairysValtioFormLayoutInstance {
5
+ state = proxy({
6
+ colCount: 1,
7
+ errorLayout: 'right-bottom',
8
+ labelMode: 'between',
9
+ borderedType: 'bottom'
10
+ });
11
+ updated = (options = {})=>{
12
+ const keys = Object.keys(options);
13
+ for(let index = 0; index < keys.length; index++){
14
+ const key = keys[index];
15
+ this.state[key] = options[key];
16
+ }
17
+ };
18
+ }
19
+ const useFairysValtioFormLayoutInstance = (instance)=>{
20
+ const ref = useRef();
21
+ if (!ref.current) if (instance) ref.current = instance;
22
+ else ref.current = new FairysValtioFormLayoutInstance();
23
+ return ref.current;
24
+ };
25
+ const FairysValtioFormLayoutContext = /*#__PURE__*/ createContext(new FairysValtioFormLayoutInstance());
26
+ const useFairysValtioFormLayoutContext = ()=>{
27
+ const instance = useContext(FairysValtioFormLayoutContext);
28
+ const state = useSnapshot(instance.state);
29
+ return [
30
+ state,
31
+ instance
32
+ ];
33
+ };
34
+ function useFairysValtioFormLayoutAttrs(props) {
35
+ const formLayoutInstance = useFairysValtioFormLayoutInstance();
36
+ const [state] = useFairysValtioFormLayoutContext();
37
+ const parent_colCount = state.colCount || 1;
38
+ const parent_errorLayout = state.errorLayout || 'right-bottom';
39
+ const parent_labelMode = state.labelMode || 'between';
40
+ const parent_formItemClassName = state.formItemClassName;
41
+ const parent_formItemStyle = state.formItemStyle;
42
+ const parent_formItemLabelClassName = state.formItemLabelClassName;
43
+ const parent_formItemLabelStyle = state.formItemLabelStyle;
44
+ const parent_formItemBodyClassName = state.formItemBodyClassName;
45
+ const parent_formItemBodyStyle = state.formItemBodyStyle;
46
+ const parent_borderedType = state.borderedType || 'bottom';
47
+ const { colCount = parent_colCount, errorLayout = parent_errorLayout, labelMode = parent_labelMode, formItemClassName = parent_formItemClassName, formItemStyle = parent_formItemStyle, formItemLabelClassName = parent_formItemLabelClassName, formItemLabelStyle = parent_formItemLabelStyle, formItemBodyClassName = parent_formItemBodyClassName, formItemBodyStyle = parent_formItemBodyStyle, borderedType = parent_borderedType, lastItemBordered = true, gap, isAllColSpan = false, className, style, headerClassName, headerStyle, bodyClassName, bodyStyle, bordered, boxShadow } = props;
48
+ useMemo(()=>formLayoutInstance.updated({
49
+ colCount,
50
+ errorLayout,
51
+ labelMode,
52
+ formItemClassName,
53
+ formItemStyle,
54
+ formItemLabelClassName,
55
+ formItemLabelStyle,
56
+ formItemBodyClassName,
57
+ formItemBodyStyle,
58
+ borderedType
59
+ }), [
60
+ colCount,
61
+ errorLayout,
62
+ labelMode,
63
+ formItemClassName,
64
+ formItemStyle,
65
+ formItemLabelClassName,
66
+ formItemLabelStyle,
67
+ formItemBodyClassName,
68
+ formItemBodyStyle,
69
+ borderedType
70
+ ]);
71
+ const layoutCls = useMemo(()=>clsx("fairys-valtio-form-layout fairystaroform__text-_zkh1_12px_zhk2_ fairystaroform__w-full fairystaroform__box-border fairystaroform__rounded-md", {
72
+ 'fairys-valtio-form-layout-all-col-span': isAllColSpan,
73
+ 'fairys-taro-form-valtio-layout-box-shadow': boxShadow,
74
+ 'fairystaroform__border fairystaroform__border-solid fairystaroform__border-gray-200': bordered,
75
+ 'fairys-valtio-form-layout-last-item-no-border': !lastItemBordered
76
+ }, className), [
77
+ className,
78
+ isAllColSpan,
79
+ bordered,
80
+ boxShadow,
81
+ lastItemBordered
82
+ ]);
83
+ const headerCls = useMemo(()=>clsx("fairys-valtio-form-layout-header fairystaroform__flex fairystaroform__justify-between fairystaroform__items-center fairystaroform__flex-row fairystaroform__py-_zkh1_12px_zhk2_ fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200 fairystaroform__box-border", {
84
+ 'fairystaroform__px-_zkh1_8px_zhk2_': bordered || boxShadow,
85
+ 'fairystaroform__px-_zkh1_4px_zhk2_': !bordered && !boxShadow
86
+ }, headerClassName), [
87
+ headerClassName,
88
+ bordered,
89
+ boxShadow
90
+ ]);
91
+ const headerTitleCls = useMemo(()=>clsx("fairys-valtio-form-layout-header-title fairystaroform__text-_zkh1_14px_zhk2_ fairystaroform__font-bold fairystaroform__box-border"), []);
92
+ const headerExtraCls = useMemo(()=>clsx("fairys-valtio-form-layout-header-extra fairystaroform__box-border"), []);
93
+ const body_base = useMemo(()=>clsx('fairys-valtio-form-layout-body fairystaroform__px-_zkh1_8px_zhk2_ fairystaroform__w-full fairystaroform__grid fairystaroform__gap-_zkh1_2px_zhk2_ fairystaroform__box-border', bodyClassName), [
94
+ bodyClassName
95
+ ]);
96
+ const styleBase = useMemo(()=>{
97
+ const css = {};
98
+ if ('string' == typeof gap) css.gap = gap;
99
+ if ('number' == typeof gap) css.gap = `${gap}px`;
100
+ if (colCount) css.gridTemplateColumns = `repeat(${colCount}, auto)`;
101
+ return css;
102
+ }, [
103
+ colCount,
104
+ gap
105
+ ]);
106
+ return {
107
+ colCount,
108
+ errorLayout,
109
+ labelMode,
110
+ borderedType,
111
+ formLayoutInstance,
112
+ layoutName: layoutCls,
113
+ layoutStyle: style,
114
+ headerName: headerCls,
115
+ headerStyle: headerStyle,
116
+ headerTitleName: headerTitleCls,
117
+ headerExtraName: headerExtraCls,
118
+ bodyName: body_base,
119
+ bodyStyle: {
120
+ ...styleBase,
121
+ ...bodyStyle
122
+ }
123
+ };
124
+ }
125
+ export { FairysValtioFormLayoutContext, FairysValtioFormLayoutInstance, useFairysValtioFormLayoutAttrs, useFairysValtioFormLayoutContext, useFairysValtioFormLayoutInstance };
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './form/instance';
2
+ export * from './form/layout';
3
+ export * from './form/form';
4
+ export * from './form/form.item';
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./form/instance/index.js";
2
+ export * from "./form/layout.js";
3
+ export * from "./form/form.js";
4
+ export * from "./form/form.item.js";
@@ -0,0 +1,4 @@
1
+ export type MObject<T> = {
2
+ [K in keyof T]: T[K];
3
+ };
4
+ export type MakeFieldRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
File without changes
@@ -0,0 +1,266 @@
1
+ *, :before, :after, ::backdrop {
2
+ --un-rotate: 0;
3
+ --un-rotate-x: 0;
4
+ --un-rotate-y: 0;
5
+ --un-rotate-z: 0;
6
+ --un-scale-x: 1;
7
+ --un-scale-y: 1;
8
+ --un-scale-z: 1;
9
+ --un-skew-x: 0;
10
+ --un-skew-y: 0;
11
+ --un-translate-x: 0;
12
+ --un-translate-y: 0;
13
+ --un-translate-z: 0;
14
+ --un-pan-x: ;
15
+ --un-pan-y: ;
16
+ --un-pinch-zoom: ;
17
+ --un-scroll-snap-strictness: proximity;
18
+ --un-ordinal: ;
19
+ --un-slashed-zero: ;
20
+ --un-numeric-figure: ;
21
+ --un-numeric-spacing: ;
22
+ --un-numeric-fraction: ;
23
+ --un-border-spacing-x: 0;
24
+ --un-border-spacing-y: 0;
25
+ --un-ring-offset-shadow: 0 0 #0000;
26
+ --un-ring-shadow: 0 0 #0000;
27
+ --un-shadow-inset: ;
28
+ --un-shadow: 0 0 #0000;
29
+ --un-ring-inset: ;
30
+ --un-ring-offset-width: 0px;
31
+ --un-ring-offset-color: #fff;
32
+ --un-ring-width: 0px;
33
+ --un-ring-color: #93c5fd80;
34
+ --un-blur: ;
35
+ --un-brightness: ;
36
+ --un-contrast: ;
37
+ --un-drop-shadow: ;
38
+ --un-grayscale: ;
39
+ --un-hue-rotate: ;
40
+ --un-invert: ;
41
+ --un-saturate: ;
42
+ --un-sepia: ;
43
+ --un-backdrop-blur: ;
44
+ --un-backdrop-brightness: ;
45
+ --un-backdrop-contrast: ;
46
+ --un-backdrop-grayscale: ;
47
+ --un-backdrop-hue-rotate: ;
48
+ --un-backdrop-invert: ;
49
+ --un-backdrop-opacity: ;
50
+ --un-backdrop-saturate: ;
51
+ --un-backdrop-sepia: ;
52
+ }
53
+
54
+ .fairystaroform__absolute {
55
+ position: absolute;
56
+ }
57
+
58
+ .fairystaroform__relative {
59
+ position: relative;
60
+ }
61
+
62
+ .fairystaroform__bottom-_zkh1_-14px_zhk2_ {
63
+ bottom: -14px;
64
+ }
65
+
66
+ .fairystaroform__left-0 {
67
+ left: 0;
68
+ }
69
+
70
+ .fairystaroform__right-0 {
71
+ right: 0;
72
+ }
73
+
74
+ .fairystaroform__top-_zkh1_-14px_zhk2_ {
75
+ top: -14px;
76
+ }
77
+
78
+ .fairystaroform__z-10 {
79
+ z-index: 10;
80
+ }
81
+
82
+ .fairystaroform__grid {
83
+ display: grid;
84
+ }
85
+
86
+ .fairystaroform__box-border {
87
+ box-sizing: border-box;
88
+ }
89
+
90
+ .fairystaroform__h-full {
91
+ height: 100%;
92
+ }
93
+
94
+ .fairystaroform__w-full {
95
+ width: 100%;
96
+ }
97
+
98
+ .fairystaroform__flex {
99
+ display: flex;
100
+ }
101
+
102
+ .fairystaroform__flex-1 {
103
+ flex: 1;
104
+ }
105
+
106
+ .fairystaroform__flex-row {
107
+ flex-direction: row;
108
+ }
109
+
110
+ .fairystaroform__flex-col {
111
+ flex-direction: column;
112
+ }
113
+
114
+ .fairystaroform__items-center {
115
+ align-items: center;
116
+ }
117
+
118
+ .fairystaroform__justify-start {
119
+ justify-content: flex-start;
120
+ }
121
+
122
+ .fairystaroform__justify-end {
123
+ justify-content: flex-end;
124
+ }
125
+
126
+ .fairystaroform__justify-center {
127
+ justify-content: center;
128
+ }
129
+
130
+ .fairystaroform__justify-between {
131
+ justify-content: space-between;
132
+ }
133
+
134
+ .fairystaroform__gap-_zkh1_2px_zhk2_ {
135
+ gap: 2px;
136
+ }
137
+
138
+ .fairystaroform__gap-_zkh1_4px_zhk2_ {
139
+ gap: 4px;
140
+ }
141
+
142
+ .fairystaroform__gap-_zkh1_8px_zhk2_ {
143
+ gap: 8px;
144
+ }
145
+
146
+ .fairystaroform__break-all {
147
+ word-break: break-all;
148
+ }
149
+
150
+ .fairystaroform__border {
151
+ border-width: 1px;
152
+ }
153
+
154
+ .fairystaroform__border-b {
155
+ border-bottom-width: 1px;
156
+ }
157
+
158
+ .fairystaroform__border-gray-200 {
159
+ --un-border-opacity: 1;
160
+ border-color: rgb(229 231 235 / var(--un-border-opacity));
161
+ }
162
+
163
+ .fairystaroform__border-b-gray-200 {
164
+ --un-border-opacity: 1;
165
+ --un-border-bottom-opacity: var(--un-border-opacity);
166
+ border-bottom-color: rgb(229 231 235 / var(--un-border-bottom-opacity));
167
+ }
168
+
169
+ .fairystaroform__rounded-md {
170
+ border-radius: .375rem;
171
+ }
172
+
173
+ .fairystaroform__border-solid {
174
+ border-style: solid;
175
+ }
176
+
177
+ .fairystaroform__border-b-solid {
178
+ border-bottom-style: solid;
179
+ }
180
+
181
+ .fairystaroform__p-_zkh1_4px_zhk2_ {
182
+ padding: 4px;
183
+ }
184
+
185
+ .fairystaroform__px-_zkh1_4px_zhk2_ {
186
+ padding-left: 4px;
187
+ padding-right: 4px;
188
+ }
189
+
190
+ .fairystaroform__px-_zkh1_8px_zhk2_ {
191
+ padding-left: 8px;
192
+ padding-right: 8px;
193
+ }
194
+
195
+ .fairystaroform__py-_zkh1_12px_zhk2_ {
196
+ padding-top: 12px;
197
+ padding-bottom: 12px;
198
+ }
199
+
200
+ .fairystaroform__text-left {
201
+ text-align: left;
202
+ }
203
+
204
+ .fairystaroform__text-right {
205
+ text-align: right;
206
+ }
207
+
208
+ .fairystaroform__text-_zkh1_10px_zhk2_ {
209
+ font-size: 10px;
210
+ }
211
+
212
+ .fairystaroform__text-_zkh1_12px_zhk2_ {
213
+ font-size: 12px;
214
+ }
215
+
216
+ .fairystaroform__text-_zkh1_14px_zhk2_ {
217
+ font-size: 14px;
218
+ }
219
+
220
+ .fairystaroform__text-gray-800 {
221
+ --un-text-opacity: 1;
222
+ color: rgb(31 41 55 / var(--un-text-opacity));
223
+ }
224
+
225
+ .fairystaroform__text-red {
226
+ --un-text-opacity: 1;
227
+ color: rgb(248 113 113 / var(--un-text-opacity));
228
+ }
229
+
230
+ .fairystaroform__font-bold {
231
+ font-weight: 700;
232
+ }
233
+
234
+ .fairys-valtio-form-item-label.show-colon:after {
235
+ content: ":";
236
+ text-align: center;
237
+ margin: 0;
238
+ box-sizing: border-box;
239
+ margin-inline: .1rem;
240
+ display: inline-block;
241
+ }
242
+
243
+ .fairys-valtio-form-item-label.required:before {
244
+ content: "*";
245
+ color: red;
246
+ box-sizing: border-box;
247
+ margin-inline-end: .2rem;
248
+ display: inline-block;
249
+ }
250
+
251
+ .fairys-valtio-form-layout.fairys-form-layout-all-col-span {
252
+ grid-column: 1 / -1;
253
+ }
254
+
255
+ .fairys-valtio-form-layout.fairys-form-layout-box-shadow {
256
+ box-shadow: 0 6px 16px -8px #00000014, 0 9px 28px #0000000d, 0 12px 48px 16px #00000008;
257
+ }
258
+
259
+ .fairys-valtio-form-layout + .fairys-valtio-form-layout {
260
+ margin-top: 12px;
261
+ }
262
+
263
+ .fairys-valtio-form-layout-last-item-no-border > .fairys-valtio-form-layout-body > .fairys-valtio-form-item:last-child, .fairys-valtio-form-layout-last-item-no-border > .fairys-valtio-form-layout-body > .fairys-valtio-form-item:last-child > .fairys-valtio-form-item-container > .fairys-valtio-form-item-body {
264
+ border-bottom: 0;
265
+ }
266
+
package/lib/index.js ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "./form/form.item": function(module) {
4
+ module.exports = require("./form/form.item.js");
5
+ },
6
+ "./form/form": function(module) {
7
+ module.exports = require("./form/form.js");
8
+ },
9
+ "./form/instance": function(module) {
10
+ module.exports = require("./form/instance/index.js");
11
+ },
12
+ "./form/layout": function(module) {
13
+ module.exports = require("./form/layout.js");
14
+ }
15
+ };
16
+ var __webpack_module_cache__ = {};
17
+ function __webpack_require__(moduleId) {
18
+ var cachedModule = __webpack_module_cache__[moduleId];
19
+ if (void 0 !== cachedModule) return cachedModule.exports;
20
+ var module = __webpack_module_cache__[moduleId] = {
21
+ exports: {}
22
+ };
23
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
24
+ return module.exports;
25
+ }
26
+ (()=>{
27
+ __webpack_require__.n = (module)=>{
28
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
29
+ __webpack_require__.d(getter, {
30
+ a: getter
31
+ });
32
+ return getter;
33
+ };
34
+ })();
35
+ (()=>{
36
+ __webpack_require__.d = (exports1, definition)=>{
37
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
38
+ enumerable: true,
39
+ get: definition[key]
40
+ });
41
+ };
42
+ })();
43
+ (()=>{
44
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
45
+ })();
46
+ (()=>{
47
+ __webpack_require__.r = (exports1)=>{
48
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
49
+ value: 'Module'
50
+ });
51
+ Object.defineProperty(exports1, '__esModule', {
52
+ value: true
53
+ });
54
+ };
55
+ })();
56
+ var __webpack_exports__ = {};
57
+ (()=>{
58
+ __webpack_require__.r(__webpack_exports__);
59
+ var _form_instance__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./form/instance");
60
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
61
+ for(var __WEBPACK_IMPORT_KEY__ in _form_instance__WEBPACK_IMPORTED_MODULE_0__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
62
+ return _form_instance__WEBPACK_IMPORTED_MODULE_0__[key];
63
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
64
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
65
+ var _form_layout__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./form/layout");
66
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
67
+ for(var __WEBPACK_IMPORT_KEY__ in _form_layout__WEBPACK_IMPORTED_MODULE_1__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
68
+ return _form_layout__WEBPACK_IMPORTED_MODULE_1__[key];
69
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
70
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
71
+ var _form_form__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./form/form");
72
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
73
+ for(var __WEBPACK_IMPORT_KEY__ in _form_form__WEBPACK_IMPORTED_MODULE_2__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
74
+ return _form_form__WEBPACK_IMPORTED_MODULE_2__[key];
75
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
76
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
77
+ var _form_form_item__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./form/form.item");
78
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
79
+ for(var __WEBPACK_IMPORT_KEY__ in _form_form_item__WEBPACK_IMPORTED_MODULE_3__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
80
+ return _form_form_item__WEBPACK_IMPORTED_MODULE_3__[key];
81
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
82
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
83
+ })();
84
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
85
+ Object.defineProperty(exports, '__esModule', {
86
+ value: true
87
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@fairys/valtio-form-basic",
3
+ "author": "SunLxy <1011771396@qq.com>",
4
+ "description": "使用 valtio 实现的表单基础库, 使其更加便捷,同时支持`PC`、`H5`、`Taro`,同时也更加灵活。",
5
+ "homepage": "https://github.com/autumn-fairy-tales/fairys-taro-react",
6
+ "version": "0.0.8",
7
+ "main": "lib/index.js",
8
+ "types": "esm/index.d.ts",
9
+ "module": "esm/index.js",
10
+ "license": "ISC",
11
+ "scripts": {
12
+ "build": "carefrees-rslib build --config=./rslib.config.ts",
13
+ "watch": "carefrees-rslib build --watch --config=./rslib.config.ts"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/autumn-fairy-tales/fairys-taro-react.git",
21
+ "directory": "packages/valtio-form-basic"
22
+ },
23
+ "files": [
24
+ "src",
25
+ "esm"
26
+ ],
27
+ "dependencies": {
28
+ "@nutui/nutui-react-taro": "^3.0.18",
29
+ "async-validator": "~4.2.5",
30
+ "clsx": "2.1.1",
31
+ "fast-copy": "~4.0.2",
32
+ "valtio": "~2.1.5"
33
+ },
34
+ "devDependencies": {
35
+ "@types/react": "~18.2.21",
36
+ "react": "^18.0.0"
37
+ }
38
+ }