@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.
@@ -1,8 +1,8 @@
1
1
  import e from "../styles/Field.module.js";
2
- import t from "../styles/Form.module.js";
3
- import n from "../core/Field.js";
4
- import { useFormFieldState as r } from "../hooks/use.js";
5
- import { isEmptyTextLike as i } from "./visibility.js";
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: t = "", 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 } = r(b, S, C), [k, A] = a.useState(E(D)), j = a.useRef({
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" && i(D);
59
- return d && L ? /* @__PURE__ */ s(o, {}) : /* @__PURE__ */ c(o, { children: [x ? x() : /* @__PURE__ */ c(n, {
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: t,
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": t || p || "Дата",
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: n, position: r, max: i, min: l, className: p, onOpen: m }) => {
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, i)), D = (e) => {
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, i));
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, i));
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, i)), w("years");
135
+ e.stopPropagation(), E(f(x.y - 5, l, r)), w("years");
136
136
  }, R = (e) => {
137
- u(x.y, e, l, i) && (S({
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, i) && (S({
142
+ d(e, l, r) && (S({
143
143
  y: e,
144
144
  m: x.m
145
145
  }), w("days"));
146
146
  }, B = (e) => {
147
- n(x.y + "-" + g(2, x.m) + "-" + g(2, e)), M();
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 i && i.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 - r.b < 360 ? Math.max(8, r.y - 360) : r.b, K = window.innerWidth - r.x < 270 ? r.x - 246 : r.x;
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: t.o,
158
+ className: i.o,
159
159
  onClick: () => M()
160
160
  }), /* @__PURE__ */ c("div", {
161
- className: [t.c, p && p + "-backdrop"].join(" "),
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: t.dateHeaderMonth,
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: t.dateHeaderYear,
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, n) => {
227
- let r = n + 1, a = u(x.y, r, l, i), o = y.y === x.y && y.m === r ? { "data-active": "true" } : {}, c = b.y === x.y && b.m === r ? { "data-current": "true" } : {};
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 ? "" : t.dateHeaderDisabled,
229
+ className: a ? "" : i.dateHeaderDisabled,
230
230
  ...o,
231
231
  ...c,
232
- onClick: () => a && R(r),
233
- children: h(r).abc
234
- }, r);
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, n) => {
240
- let r = T + n, a = d(r, l, i), o = y.y === r ? { "data-active": "true" } : {}, c = b.y === r ? { "data-current": "true" } : {};
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 ? "" : t.dateHeaderDisabled,
242
+ className: a ? "" : i.dateHeaderDisabled,
243
243
  ...o,
244
244
  ...c,
245
- onClick: () => a && z(r),
246
- children: r
247
- }, r);
245
+ onClick: () => a && z(n),
246
+ children: n
247
+ }, n);
248
248
  })
249
249
  })
250
250
  ]
@@ -1,12 +1,12 @@
1
- import e from "../styles/Select.module.js";
2
- import t from "../core/Field.js";
3
- import { useFormFieldState as n } from "../hooks/use.js";
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 } = n(u, f, c ?? 0), j = Number(A), M = [];
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(t, {
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: [e.f],
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: t, parent: n, className: r, items: s, setOpen: c, listId: l, activeIndex: d, currentValue: f }) => {
108
- if (!n) return null;
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 = (e) => {
112
- c(!1), t(e);
113
- }, h = window.innerHeight - n.bottom < 306 ? Math.max(6, n.top - 300 - 6) : Math.min(window.innerHeight - 300 - 6, n.bottom + 6), g = Math.max(n.width, 260), _ = Math.min(Math.max(6, n.left), window.innerWidth - g - 6);
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: e.o,
115
+ className: n.o,
116
116
  onClick: p,
117
117
  "aria-hidden": !0
118
118
  }), /* @__PURE__ */ a("div", {
119
- className: [e.l, r].filter((e) => e !== void 0).join(" "),
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 { markBaseStylesLoaded as e } from "./loadBaseStyles.js";
2
- import t from "./package.js";
3
- import { useForm as n, useFormField as r, useFormFieldState as i } from "./hooks/use.js";
4
- import a from "./fields/Range.js";
5
- import { asEditableClipboard as o } from "./events/onEvent.js";
6
- import s from "./fields/Money.js";
7
- import c from "./fields/Mask.js";
8
- import l from "./fields/Date.js";
9
- import u from "./fields/Time.js";
10
- import d from "./fields/Textarea.js";
11
- import { useFormInit as f } from "./FormInitContext.js";
12
- import p from "./fields/Phone.js";
13
- import m from "./fields/Input.js";
14
- import h from "./fields/Numeric.js";
15
- import g from "./fields/Options.js";
16
- import _ from "./fields/Select.js";
17
- import v from "./fields/Modal.js";
18
- import y from "./fields/Password.js";
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
- e();
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 S = x();
26
- S.elcrm ||= {}, Object.assign(S.elcrm, { form: t.version });
23
+ var x = b();
24
+ x.elcrm ||= {}, Object.assign(x.elcrm, { form: e.version });
27
25
  //#endregion
28
- export { l as DateField, b as Form, c as MaskField, v as ModalField, s as MoneyField, h as NumberField, g as OptionsField, y as PasswordField, p as PhoneField, a as ProgressField, a as RangeField, _ as SelectField, m as StringField, d as TextareaField, u as TimeField, o as asEditableClipboard, n as useForm, r as useFormField, i as useFormFieldState, f as useFormInit };
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.66",
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.66",
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",
@@ -1,2 +0,0 @@
1
- /** Вызывается из `index.ts` при загрузке пакета с корня */
2
- export declare function markBaseStylesLoaded(): true;
@@ -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 };