@elcrm/form 0.0.66 → 0.0.67
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/fields/Date.js +36 -36
- package/dist/fields/Select.js +13 -13
- package/dist/index.js +22 -24
- package/dist/package.js +2 -2
- package/package.json +2 -2
- package/dist/loadBaseStyles.d.ts +0 -2
- package/dist/loadBaseStyles.js +0 -9
package/dist/fields/Date.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import e from "../styles/Field.module.js";
|
|
2
|
-
import t from "../
|
|
3
|
-
import n from "../
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import t from "../core/Field.js";
|
|
3
|
+
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
+
import { isEmptyTextLike as r } from "./visibility.js";
|
|
5
|
+
import i from "../styles/Form.module.js";
|
|
6
6
|
import a from "react";
|
|
7
7
|
import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
8
|
import { createPortal as l } from "react-dom";
|
|
@@ -26,8 +26,8 @@ function f(e, t, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return r;
|
|
28
28
|
}
|
|
29
|
-
function p({ label:
|
|
30
|
-
let E = a.useCallback((e) => e == null ? /* @__PURE__ */ new Date() : e instanceof Date || typeof e == "string" || typeof e == "number" ? e : /* @__PURE__ */ new Date(), []), { value: D, version: O } =
|
|
29
|
+
function p({ label: i = "", error: u, hidden: d = !1, className: f, placeholder: p, disabled: h = !1, onValue: g, max: v, min: y, form: b, icon: x, name: S = "", value: C, after: w = "", before: T = "" }) {
|
|
30
|
+
let E = a.useCallback((e) => e == null ? /* @__PURE__ */ new Date() : e instanceof Date || typeof e == "string" || typeof e == "number" ? e : /* @__PURE__ */ new Date(), []), { value: D, version: O } = n(b, S, C), [k, A] = a.useState(E(D)), j = a.useRef({
|
|
31
31
|
x: 0,
|
|
32
32
|
y: 0,
|
|
33
33
|
b: 0
|
|
@@ -55,10 +55,10 @@ function p({ label: t = "", error: u, hidden: d = !1, className: f, placeholder:
|
|
|
55
55
|
}, N(!0);
|
|
56
56
|
}, I = {};
|
|
57
57
|
p && (I.placeholder = p);
|
|
58
|
-
let L = D == null || D === "" || typeof D == "string" &&
|
|
59
|
-
return d && L ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(o, { children: [x ? x() : /* @__PURE__ */ c(
|
|
58
|
+
let L = D == null || D === "" || typeof D == "string" && r(D);
|
|
59
|
+
return d && L ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(o, { children: [x ? x() : /* @__PURE__ */ c(t, {
|
|
60
60
|
type: "date",
|
|
61
|
-
label:
|
|
61
|
+
label: i,
|
|
62
62
|
error: u,
|
|
63
63
|
element_blok: { className: [f || ""] },
|
|
64
64
|
element_input: {
|
|
@@ -76,7 +76,7 @@ function p({ label: t = "", error: u, hidden: d = !1, className: f, placeholder:
|
|
|
76
76
|
role: "button",
|
|
77
77
|
"aria-haspopup": "dialog",
|
|
78
78
|
"aria-expanded": M,
|
|
79
|
-
"aria-label":
|
|
79
|
+
"aria-label": i || p || "Дата",
|
|
80
80
|
"data-edit": h ? void 0 : "true",
|
|
81
81
|
...I,
|
|
82
82
|
style: { cursor: h ? "not-allowed" : "pointer" },
|
|
@@ -95,7 +95,7 @@ function p({ label: t = "", error: u, hidden: d = !1, className: f, placeholder:
|
|
|
95
95
|
}, (/* @__PURE__ */ new Date()).getTime()), document.body)] });
|
|
96
96
|
}
|
|
97
97
|
p.displayName = "DateField";
|
|
98
|
-
var m = ({ date: e, onValue:
|
|
98
|
+
var m = ({ date: e, onValue: t, position: n, max: r, min: l, className: p, onOpen: m }) => {
|
|
99
99
|
let _ = /* @__PURE__ */ new Date(), v = new Date(e), y = {
|
|
100
100
|
y: _.getFullYear(),
|
|
101
101
|
d: _.getDate(),
|
|
@@ -107,7 +107,7 @@ var m = ({ date: e, onValue: n, position: r, max: i, min: l, className: p, onOpe
|
|
|
107
107
|
}, [x, S] = a.useState({
|
|
108
108
|
y: b.y,
|
|
109
109
|
m: b.m
|
|
110
|
-
}), [C, w] = a.useState("days"), [T, E] = a.useState(() => f(b.y - 5, l,
|
|
110
|
+
}), [C, w] = a.useState("days"), [T, E] = a.useState(() => f(b.y - 5, l, r)), D = (e) => {
|
|
111
111
|
let t = e.getDay();
|
|
112
112
|
return t === 0 && (t = 7), t - 1;
|
|
113
113
|
}, O = [
|
|
@@ -128,23 +128,23 @@ var m = ({ date: e, onValue: n, position: r, max: i, min: l, className: p, onOpe
|
|
|
128
128
|
}, P = () => {
|
|
129
129
|
V(x.m - 1, x.y);
|
|
130
130
|
}, F = () => {
|
|
131
|
-
C === "days" ? P() : C === "months" ? V(x.m, x.y - 1) : E((e) => f(e - 12, l,
|
|
131
|
+
C === "days" ? P() : C === "months" ? V(x.m, x.y - 1) : E((e) => f(e - 12, l, r));
|
|
132
132
|
}, I = () => {
|
|
133
|
-
C === "days" ? N() : C === "months" ? V(x.m, x.y + 1) : E((e) => f(e + 12, l,
|
|
133
|
+
C === "days" ? N() : C === "months" ? V(x.m, x.y + 1) : E((e) => f(e + 12, l, r));
|
|
134
134
|
}, L = (e) => {
|
|
135
|
-
e.stopPropagation(), E(f(x.y - 5, l,
|
|
135
|
+
e.stopPropagation(), E(f(x.y - 5, l, r)), w("years");
|
|
136
136
|
}, R = (e) => {
|
|
137
|
-
u(x.y, e, l,
|
|
137
|
+
u(x.y, e, l, r) && (S({
|
|
138
138
|
y: x.y,
|
|
139
139
|
m: e
|
|
140
140
|
}), w("days"));
|
|
141
141
|
}, z = (e) => {
|
|
142
|
-
d(e, l,
|
|
142
|
+
d(e, l, r) && (S({
|
|
143
143
|
y: e,
|
|
144
144
|
m: x.m
|
|
145
145
|
}), w("days"));
|
|
146
146
|
}, B = (e) => {
|
|
147
|
-
|
|
147
|
+
t(x.y + "-" + g(2, x.m) + "-" + g(2, e)), M();
|
|
148
148
|
}, V = (e, t) => {
|
|
149
149
|
t = e > 12 ? t + 1 : e < 1 ? t - 1 : t, e = e > 12 ? 1 : e < 1 ? 12 : e, S({
|
|
150
150
|
y: t,
|
|
@@ -152,13 +152,13 @@ var m = ({ date: e, onValue: n, position: r, max: i, min: l, className: p, onOpe
|
|
|
152
152
|
});
|
|
153
153
|
}, H = (e) => y.y === x.y && y.m === x.m && y.d === e ? { "data-active": "true" } : {}, U = (e) => b.y === x.y && b.m === x.m && b.d === e ? { "data-current": "true" } : {}, W = (e) => {
|
|
154
154
|
let t = !0;
|
|
155
|
-
return
|
|
156
|
-
}, G = window.innerHeight -
|
|
155
|
+
return r && r.getTime() < new Date(x.y, x.m - 1, e).getTime() && (t = !1), l && l.getTime() > new Date(x.y, x.m - 1, e).getTime() && (t = !1), t;
|
|
156
|
+
}, G = window.innerHeight - n.b < 360 ? Math.max(8, n.y - 360) : n.b, K = window.innerWidth - n.x < 270 ? n.x - 246 : n.x;
|
|
157
157
|
return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s("div", {
|
|
158
|
-
className:
|
|
158
|
+
className: i.o,
|
|
159
159
|
onClick: () => M()
|
|
160
160
|
}), /* @__PURE__ */ c("div", {
|
|
161
|
-
className: [
|
|
161
|
+
className: [i.c, p && p + "-backdrop"].join(" "),
|
|
162
162
|
style: {
|
|
163
163
|
top: G + "px",
|
|
164
164
|
left: K + "px"
|
|
@@ -180,14 +180,14 @@ var m = ({ date: e, onValue: n, position: r, max: i, min: l, className: p, onOpe
|
|
|
180
180
|
})
|
|
181
181
|
}),
|
|
182
182
|
/* @__PURE__ */ c("h2", { children: [/* @__PURE__ */ s("span", {
|
|
183
|
-
className:
|
|
183
|
+
className: i.dateHeaderMonth,
|
|
184
184
|
onClick: (e) => {
|
|
185
185
|
e.stopPropagation(), w(C === "years" ? "months" : C === "months" ? "days" : "months");
|
|
186
186
|
},
|
|
187
187
|
title: C === "years" ? "К списку месяцев" : C === "months" ? "К календарю" : "Выбрать месяц",
|
|
188
188
|
children: h(x.m).name
|
|
189
189
|
}), /* @__PURE__ */ s("span", {
|
|
190
|
-
className:
|
|
190
|
+
className: i.dateHeaderYear,
|
|
191
191
|
onClick: (e) => {
|
|
192
192
|
e.stopPropagation(), C === "years" ? w("days") : L(e);
|
|
193
193
|
},
|
|
@@ -223,28 +223,28 @@ var m = ({ date: e, onValue: n, position: r, max: i, min: l, className: p, onOpe
|
|
|
223
223
|
}),
|
|
224
224
|
C === "months" && /* @__PURE__ */ s("div", {
|
|
225
225
|
"grid-month": "",
|
|
226
|
-
children: Array.from({ length: 12 }, (e,
|
|
227
|
-
let
|
|
226
|
+
children: Array.from({ length: 12 }, (e, t) => {
|
|
227
|
+
let n = t + 1, a = u(x.y, n, l, r), o = y.y === x.y && y.m === n ? { "data-active": "true" } : {}, c = b.y === x.y && b.m === n ? { "data-current": "true" } : {};
|
|
228
228
|
return /* @__PURE__ */ s("b", {
|
|
229
|
-
className: a ? "" :
|
|
229
|
+
className: a ? "" : i.dateHeaderDisabled,
|
|
230
230
|
...o,
|
|
231
231
|
...c,
|
|
232
|
-
onClick: () => a && R(
|
|
233
|
-
children: h(
|
|
234
|
-
},
|
|
232
|
+
onClick: () => a && R(n),
|
|
233
|
+
children: h(n).abc
|
|
234
|
+
}, n);
|
|
235
235
|
})
|
|
236
236
|
}),
|
|
237
237
|
C === "years" && /* @__PURE__ */ s("div", {
|
|
238
238
|
"grid-month": "",
|
|
239
|
-
children: Array.from({ length: 12 }, (e,
|
|
240
|
-
let
|
|
239
|
+
children: Array.from({ length: 12 }, (e, t) => {
|
|
240
|
+
let n = T + t, a = d(n, l, r), o = y.y === n ? { "data-active": "true" } : {}, c = b.y === n ? { "data-current": "true" } : {};
|
|
241
241
|
return /* @__PURE__ */ s("b", {
|
|
242
|
-
className: a ? "" :
|
|
242
|
+
className: a ? "" : i.dateHeaderDisabled,
|
|
243
243
|
...o,
|
|
244
244
|
...c,
|
|
245
|
-
onClick: () => a && z(
|
|
246
|
-
children:
|
|
247
|
-
},
|
|
245
|
+
onClick: () => a && z(n),
|
|
246
|
+
children: n
|
|
247
|
+
}, n);
|
|
248
248
|
})
|
|
249
249
|
})
|
|
250
250
|
]
|
package/dist/fields/Select.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import e from "../
|
|
2
|
-
import t from "../
|
|
3
|
-
import
|
|
1
|
+
import e from "../core/Field.js";
|
|
2
|
+
import { useFormFieldState as t } from "../hooks/use.js";
|
|
3
|
+
import n from "../styles/Select.module.js";
|
|
4
4
|
import r from "react";
|
|
5
5
|
import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
6
|
import { createPortal as s } from "react-dom";
|
|
7
7
|
//#region src/lib/fields/Select.tsx
|
|
8
8
|
function c({ value: c = 0, form: u, onValue: d, name: f = "", placeholder: p = "", label: m, error: h, hidden: g = !1, disabled: _ = !1, className: v, after: y = "", before: b = "", options: x, order: S }) {
|
|
9
|
-
let [C, w] = r.useState(!1), [T, E] = r.useState(0), [D, O] = r.useState(null), k = r.useId(), { value: A } =
|
|
9
|
+
let [C, w] = r.useState(!1), [T, E] = r.useState(0), [D, O] = r.useState(null), k = r.useId(), { value: A } = t(u, f, c ?? 0), j = Number(A), M = [];
|
|
10
10
|
x && (M = Array.isArray(x) ? x.map((e) => ({
|
|
11
11
|
id: e.id ?? e.i ?? 0,
|
|
12
12
|
label: e.n || "",
|
|
@@ -64,13 +64,13 @@ function c({ value: c = 0, form: u, onValue: d, name: f = "", placeholder: p = "
|
|
|
64
64
|
}, B = {};
|
|
65
65
|
p && (B.placeholder = p);
|
|
66
66
|
let V = j === 0 || P(j) === void 0;
|
|
67
|
-
return g && V ? "" : /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ o(
|
|
67
|
+
return g && V ? "" : /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ o(e, {
|
|
68
68
|
type: "select",
|
|
69
69
|
label: m,
|
|
70
70
|
element_blok: { className: [v || ""] },
|
|
71
71
|
error: h,
|
|
72
72
|
element_input: {
|
|
73
|
-
className: [
|
|
73
|
+
className: [n.f],
|
|
74
74
|
props: {
|
|
75
75
|
onClick: R,
|
|
76
76
|
onKeyDown: z,
|
|
@@ -104,19 +104,19 @@ function c({ value: c = 0, form: u, onValue: d, name: f = "", placeholder: p = "
|
|
|
104
104
|
}), document.body)] });
|
|
105
105
|
}
|
|
106
106
|
c.displayName = "SelectField";
|
|
107
|
-
var l = ({ onValue:
|
|
108
|
-
if (!
|
|
107
|
+
var l = ({ onValue: e, parent: t, className: r, items: s, setOpen: c, listId: l, activeIndex: d, currentValue: f }) => {
|
|
108
|
+
if (!t) return null;
|
|
109
109
|
let p = () => {
|
|
110
110
|
c(!1);
|
|
111
|
-
}, m = (
|
|
112
|
-
c(!1), t
|
|
113
|
-
}, h = window.innerHeight -
|
|
111
|
+
}, m = (t) => {
|
|
112
|
+
c(!1), e(t);
|
|
113
|
+
}, h = window.innerHeight - t.bottom < 306 ? Math.max(6, t.top - 300 - 6) : Math.min(window.innerHeight - 300 - 6, t.bottom + 6), g = Math.max(t.width, 260), _ = Math.min(Math.max(6, t.left), window.innerWidth - g - 6);
|
|
114
114
|
return /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a("div", {
|
|
115
|
-
className:
|
|
115
|
+
className: n.o,
|
|
116
116
|
onClick: p,
|
|
117
117
|
"aria-hidden": !0
|
|
118
118
|
}), /* @__PURE__ */ a("div", {
|
|
119
|
-
className: [
|
|
119
|
+
className: [n.l, r].filter((e) => e !== void 0).join(" "),
|
|
120
120
|
style: {
|
|
121
121
|
top: h + "px",
|
|
122
122
|
left: _ + "px",
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "./
|
|
3
|
-
import
|
|
4
|
-
import a from "./
|
|
5
|
-
import
|
|
6
|
-
import s from "./fields/
|
|
7
|
-
import c from "./fields/
|
|
8
|
-
import l from "./fields/
|
|
9
|
-
import u from "./fields/
|
|
10
|
-
import d from "./
|
|
11
|
-
import
|
|
12
|
-
import p from "./fields/
|
|
13
|
-
import m from "./fields/
|
|
14
|
-
import h from "./fields/
|
|
15
|
-
import g from "./fields/
|
|
16
|
-
import _ from "./fields/
|
|
17
|
-
import v from "./fields/
|
|
18
|
-
import y from "./
|
|
19
|
-
import { Form as b } from "./Form.js";
|
|
1
|
+
import e from "./package.js";
|
|
2
|
+
import { useForm as t, useFormField as n, useFormFieldState as r } from "./hooks/use.js";
|
|
3
|
+
import i from "./fields/Range.js";
|
|
4
|
+
import { asEditableClipboard as a } from "./events/onEvent.js";
|
|
5
|
+
import o from "./fields/Money.js";
|
|
6
|
+
import s from "./fields/Mask.js";
|
|
7
|
+
import c from "./fields/Date.js";
|
|
8
|
+
import l from "./fields/Time.js";
|
|
9
|
+
import u from "./fields/Textarea.js";
|
|
10
|
+
import { useFormInit as d } from "./FormInitContext.js";
|
|
11
|
+
import f from "./fields/Phone.js";
|
|
12
|
+
import p from "./fields/Input.js";
|
|
13
|
+
import m from "./fields/Numeric.js";
|
|
14
|
+
import h from "./fields/Options.js";
|
|
15
|
+
import g from "./fields/Select.js";
|
|
16
|
+
import _ from "./fields/Modal.js";
|
|
17
|
+
import v from "./fields/Password.js";
|
|
18
|
+
import { Form as y } from "./Form.js";
|
|
20
19
|
//#region src/lib/index.ts
|
|
21
|
-
|
|
22
|
-
function x() {
|
|
20
|
+
function b() {
|
|
23
21
|
return typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof self < "u" ? self : {};
|
|
24
22
|
}
|
|
25
|
-
var
|
|
26
|
-
|
|
23
|
+
var x = b();
|
|
24
|
+
x.elcrm ||= {}, Object.assign(x.elcrm, { form: e.version });
|
|
27
25
|
//#endregion
|
|
28
|
-
export {
|
|
26
|
+
export { c as DateField, y as Form, s as MaskField, _ as ModalField, o as MoneyField, m as NumberField, h as OptionsField, v as PasswordField, f as PhoneField, i as ProgressField, i as RangeField, g as SelectField, p as StringField, u as TextareaField, l as TimeField, a as asEditableClipboard, t as useForm, n as useFormField, r as useFormFieldState, d as useFormInit };
|
package/dist/package.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var e = {
|
|
2
2
|
name: "@elcrm/form",
|
|
3
|
-
version: "0.0.
|
|
3
|
+
version: "0.0.67",
|
|
4
4
|
description: "React-компоненты полей формы и хук useForm для elCRM: текст, даты, маски, деньги, селект, связка с формой по имени поля (tree-shakeable ESM).",
|
|
5
5
|
type: "module",
|
|
6
6
|
author: "MaSkal <dev@elcrm.online>",
|
|
@@ -72,7 +72,7 @@ var e = {
|
|
|
72
72
|
},
|
|
73
73
|
scripts: {
|
|
74
74
|
dev: "vite --config test/vite.config.ts",
|
|
75
|
-
build: "vite build && node scripts/merge-dist-css.mjs && vite build --config vite.umd.config.ts",
|
|
75
|
+
build: "vite build && node scripts/merge-dist-css.mjs && node scripts/inject-style-import.mjs && vite build --config vite.umd.config.ts",
|
|
76
76
|
test: "vitest run",
|
|
77
77
|
"test:watch": "vitest",
|
|
78
78
|
"test:build": "vite build --config test/vite.config.ts",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elcrm/form",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
4
4
|
"description": "React-компоненты полей формы и хук useForm для elCRM: текст, даты, маски, деньги, селект, связка с формой по имени поля (tree-shakeable ESM).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MaSkal <dev@elcrm.online>",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"dev": "vite --config test/vite.config.ts",
|
|
78
|
-
"build": "vite build && node scripts/merge-dist-css.mjs && vite build --config vite.umd.config.ts",
|
|
78
|
+
"build": "vite build && node scripts/merge-dist-css.mjs && node scripts/inject-style-import.mjs && vite build --config vite.umd.config.ts",
|
|
79
79
|
"test": "vitest run",
|
|
80
80
|
"test:watch": "vitest",
|
|
81
81
|
"test:build": "vite build --config test/vite.config.ts",
|
package/dist/loadBaseStyles.d.ts
DELETED
package/dist/loadBaseStyles.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import e from "./styles/Field.module.js";
|
|
2
|
-
import t from "./styles/Form.module.js";
|
|
3
|
-
import n from "./styles/Select.module.js";
|
|
4
|
-
//#region src/lib/loadBaseStyles.ts
|
|
5
|
-
function r() {
|
|
6
|
-
return e.l, t.o, n.f, !0;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { r as markBaseStylesLoaded };
|