@elcrm/form 0.0.63 → 0.0.65

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.
Files changed (94) hide show
  1. package/README.md +139 -0
  2. package/dist/Form.d.ts +20 -0
  3. package/dist/Form.js +11 -0
  4. package/dist/FormInitContext.d.ts +25 -0
  5. package/dist/FormInitContext.js +20 -0
  6. package/dist/assets/styles/Field.module.css +1 -0
  7. package/dist/assets/styles/Form.module.css +1 -0
  8. package/dist/assets/styles/Select.module.css +1 -0
  9. package/dist/core/Field.d.ts +19 -0
  10. package/dist/core/Field.js +33 -0
  11. package/dist/events/onEvent.d.ts +55 -0
  12. package/dist/events/onEvent.js +67 -0
  13. package/dist/fields/Date.d.ts +13 -0
  14. package/dist/fields/Date.js +352 -0
  15. package/dist/fields/Input.d.ts +12 -0
  16. package/dist/fields/Input.js +127 -0
  17. package/dist/fields/Mask.d.ts +9 -0
  18. package/dist/fields/Mask.js +101 -0
  19. package/dist/fields/Modal.d.ts +25 -0
  20. package/dist/fields/Modal.js +62 -0
  21. package/dist/fields/Money.d.ts +14 -0
  22. package/dist/fields/Money.js +100 -0
  23. package/dist/fields/Numeric.d.ts +9 -0
  24. package/dist/fields/Numeric.js +73 -0
  25. package/dist/fields/Options.d.ts +32 -0
  26. package/dist/fields/Options.js +69 -0
  27. package/dist/fields/Password.d.ts +6 -0
  28. package/dist/fields/Password.js +153 -0
  29. package/dist/fields/Phone.d.ts +7 -0
  30. package/dist/fields/Phone.js +112 -0
  31. package/dist/fields/Range.d.ts +16 -0
  32. package/dist/fields/Range.js +103 -0
  33. package/dist/fields/Select.d.ts +21 -0
  34. package/dist/fields/Select.js +146 -0
  35. package/dist/fields/Textarea.d.ts +7 -0
  36. package/dist/fields/Textarea.js +52 -0
  37. package/dist/fields/Time.d.ts +26 -0
  38. package/dist/fields/Time.js +254 -0
  39. package/dist/fields/type.d.ts +77 -0
  40. package/dist/fields/visibility.d.ts +6 -0
  41. package/dist/fields/visibility.js +6 -0
  42. package/dist/hooks/use.d.ts +41 -0
  43. package/dist/hooks/use.js +57 -0
  44. package/dist/index.d.ts +26 -2
  45. package/dist/index.js +26 -0
  46. package/dist/mask/MaskPhone.d.ts +8 -0
  47. package/dist/mask/MaskPhone.js +1384 -0
  48. package/dist/package.js +96 -0
  49. package/dist/styles/Field.module.js +22 -0
  50. package/dist/styles/Form.module.js +12 -0
  51. package/dist/styles/Select.module.js +8 -0
  52. package/package.json +72 -11
  53. package/src/lib/styles/Field.module.scss +315 -0
  54. package/src/lib/styles/Form.module.scss +313 -0
  55. package/src/lib/styles/Select.module.scss +90 -0
  56. package/src/lib/styles/dark.css +47 -0
  57. package/src/lib/styles/light.css +51 -0
  58. package/dist/index.css +0 -1
  59. package/dist/index.es.js +0 -5045
  60. package/dist/index.umd.js +0 -89
  61. package/dist/src/lib/Captcha.d.ts +0 -1
  62. package/dist/src/lib/Check.d.ts +0 -13
  63. package/dist/src/lib/Code.d.ts +0 -22
  64. package/dist/src/lib/Color.d.ts +0 -22
  65. package/dist/src/lib/Field.d.ts +0 -13
  66. package/dist/src/lib/Files.d.ts +0 -20
  67. package/dist/src/lib/Generator.d.ts +0 -1
  68. package/dist/src/lib/Group.d.ts +0 -21
  69. package/dist/src/lib/Image.d.ts +0 -22
  70. package/dist/src/lib/Init.d.ts +0 -1
  71. package/dist/src/lib/MaskPhone.d.ts +0 -2
  72. package/dist/src/lib/Message.d.ts +0 -15
  73. package/dist/src/lib/Money.d.ts +0 -22
  74. package/dist/src/lib/Month.d.ts +0 -18
  75. package/dist/src/lib/Palette.d.ts +0 -9
  76. package/dist/src/lib/Progress.d.ts +0 -9
  77. package/dist/src/lib/Toogle.d.ts +0 -8
  78. package/dist/src/lib/Users.d.ts +0 -1
  79. package/dist/src/lib/_Time.d.ts +0 -0
  80. package/dist/src/lib/fields/Date.d.ts +0 -18
  81. package/dist/src/lib/fields/Input.d.ts +0 -27
  82. package/dist/src/lib/fields/Mask.d.ts +0 -19
  83. package/dist/src/lib/fields/Modal.d.ts +0 -19
  84. package/dist/src/lib/fields/Numeric.d.ts +0 -6
  85. package/dist/src/lib/fields/Options.d.ts +0 -22
  86. package/dist/src/lib/fields/Password.d.ts +0 -23
  87. package/dist/src/lib/fields/Phone.d.ts +0 -21
  88. package/dist/src/lib/fields/Select copy.d.ts +0 -23
  89. package/dist/src/lib/fields/Select.d.ts +0 -28
  90. package/dist/src/lib/fields/Textarea.d.ts +0 -23
  91. package/dist/src/lib/fields/type.d.ts +0 -30
  92. package/dist/src/lib/index.d.ts +0 -16
  93. package/dist/src/lib/onEvent.d.ts +0 -2
  94. package/dist/src/lib/use.d.ts +0 -10
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Проверка «пустого» значения для режима **`hidden`**:
3
+ * при **`hidden === true`** поле не рендерится только если значение пустое.
4
+ */
5
+ /** Строки и необработанный ввод (в т.ч. `contentEditable`) */
6
+ export declare function isEmptyTextLike(value: unknown): boolean;
@@ -0,0 +1,6 @@
1
+ //#region src/lib/fields/visibility.ts
2
+ function e(e) {
3
+ return e == null ? !0 : typeof e == "string" ? e.trim() === "" : !1;
4
+ }
5
+ //#endregion
6
+ export { e as isEmptyTextLike };
@@ -0,0 +1,41 @@
1
+ import { default as React } from 'react';
2
+ /** Значения формы: только через getValues() / getValue — не мутируйте ссылку снаружи */
3
+ export type FormValues = Record<string, unknown>;
4
+ type FormChange = {
5
+ name?: string;
6
+ value?: unknown;
7
+ };
8
+ type Listener = () => void;
9
+ export type UseFormApi = {
10
+ valuesRef: React.MutableRefObject<FormValues>;
11
+ onValue: (payload: FormChange) => void;
12
+ setValue: (payload: FormChange) => void;
13
+ setValues: (nextValues: FormValues) => void;
14
+ /** Неглубокая копия текущих значений (защита от случайной мутации снаружи) */
15
+ getValues: () => FormValues;
16
+ getValue: (name: string, fallback?: unknown) => unknown;
17
+ getVersion: (name: string) => number;
18
+ reset: (nextValues?: FormValues) => void;
19
+ subscribe: (name: string, listener: Listener) => () => void;
20
+ };
21
+ /**
22
+ * useForm — сборщик значений полей. Подписки по имени поля (гранулярные ререндеры).
23
+ *
24
+ * Чтение: form.getValue("name"), form.getValues()
25
+ * Запись без ререндера: form.onValue({ name, value })
26
+ * Запись с уведомлением подписчиков поля: form.setValue({ name, value })
27
+ */
28
+ export declare function useForm(initialValues?: FormValues): UseFormApi;
29
+ /**
30
+ * Подписка на одно поле формы: актуальное значение + версия (для key у contentEditable и т.п.).
31
+ * Поля используют внутри себя; снаружи обычно достаточно передать form + name.
32
+ */
33
+ /** Результат хука подписки на поле (значение + версия для key) */
34
+ export type UseFormFieldStateResult = {
35
+ value: unknown;
36
+ version: number;
37
+ };
38
+ export declare function useFormFieldState(form: UseFormApi | undefined, name: string, fallback: unknown): UseFormFieldStateResult;
39
+ /** Подписка только на значение (без поля-компонента), например внешняя логика превью */
40
+ export declare function useFormField(form: UseFormApi, name: string, fallback?: unknown): unknown;
41
+ export {};
@@ -0,0 +1,57 @@
1
+ import e from "react";
2
+ //#region src/lib/hooks/use.ts
3
+ var t = (e, t) => Object.is(e, t);
4
+ function n(n = {}) {
5
+ let r = e.useRef({ ...n }), i = e.useRef({}), a = e.useRef({}), o = e.useCallback((e) => {
6
+ let t = i.current[e];
7
+ t && t.forEach((e) => e());
8
+ }, []), s = e.useCallback((e) => {
9
+ a.current[e] = (a.current[e] || 0) + 1;
10
+ }, []), c = e.useCallback((e) => {
11
+ !e || !e.name || (r.current[e.name] = e.value);
12
+ }, []), l = e.useCallback((e) => {
13
+ let n = r.current, i = new Set([...Object.keys(n), ...Object.keys(e)]), a = { ...e };
14
+ r.current = a, i.forEach((e) => {
15
+ let r = n[e], i = a[e];
16
+ t(r, i) || (s(e), o(e));
17
+ });
18
+ }, [s, o]), u = e.useCallback((e) => {
19
+ !e || !e.name || (r.current[e.name] = e.value, s(e.name), o(e.name));
20
+ }, [s, o]), d = e.useCallback((e = n) => {
21
+ let i = r.current, a = new Set([...Object.keys(i), ...Object.keys(e)]);
22
+ r.current = { ...e }, a.forEach((e) => {
23
+ let n = i[e], a = r.current[e];
24
+ t(n, a) || (s(e), o(e));
25
+ });
26
+ }, [
27
+ n,
28
+ s,
29
+ o
30
+ ]), f = e.useCallback(() => ({ ...r.current }), []), p = e.useCallback((e, t) => r.current[e] ?? t, []), m = e.useCallback((e) => a.current[e] || 0, []), h = e.useCallback((e, t) => (i.current[e] || (i.current[e] = /* @__PURE__ */ new Set()), i.current[e].add(t), () => {
31
+ i.current[e]?.delete(t), i.current[e]?.size === 0 && delete i.current[e];
32
+ }), []), g = e.useRef(null);
33
+ return g.current ||= {}, Object.assign(g.current, {
34
+ valuesRef: r,
35
+ getValues: f,
36
+ setValues: l,
37
+ setValue: u,
38
+ onValue: c,
39
+ reset: d,
40
+ getValue: p,
41
+ getVersion: m,
42
+ subscribe: h
43
+ }), g.current;
44
+ }
45
+ function r(t, n, r) {
46
+ let i = e.useCallback((e) => !t || !n ? () => {} : t.subscribe(n, e), [t, n]), a = e.useCallback(() => !t || !n ? 0 : t.getVersion(n), [t, n]), o = e.useSyncExternalStore(i, a, a);
47
+ return {
48
+ value: t && n ? t.getValue(n, r) : r,
49
+ version: o
50
+ };
51
+ }
52
+ function i(e, t, n = "") {
53
+ let { value: i } = r(e, t, n);
54
+ return i;
55
+ }
56
+ //#endregion
57
+ export { n as useForm, i as useFormField, r as useFormFieldState };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,26 @@
1
- export * from './src/lib/index'
2
- export {}
1
+ export { default as RangeField } from './fields/Range';
2
+ /** @deprecated используйте `RangeField` */
3
+ export { ProgressField } from './fields/Range';
4
+ export { default as MoneyField } from './fields/Money';
5
+ export { default as MaskField } from './fields/Mask';
6
+ export { default as DateField } from './fields/Date';
7
+ export { default as TimeField } from './fields/Time';
8
+ export { default as TextareaField } from './fields/Textarea';
9
+ export { default as PhoneField } from './fields/Phone';
10
+ export { default as StringField } from './fields/Input';
11
+ export { default as NumberField } from './fields/Numeric';
12
+ export { default as OptionsField } from './fields/Options';
13
+ export { default as SelectField } from './fields/Select';
14
+ export { default as ModalField } from './fields/Modal';
15
+ export { default as PasswordField } from './fields/Password';
16
+ export { useForm, useFormField, useFormFieldState } from './hooks/use';
17
+ export type { TInput, TValue, TPasswordField, TFieldFormBindings, TFieldPresentation, } from './fields/type';
18
+ export type { TRange, TProgress } from './fields/Range';
19
+ export type { TTime } from './fields/Time';
20
+ export type { FormValues, UseFormApi, UseFormFieldStateResult, } from './hooks/use';
21
+ export type { EditableFieldTarget, EditableClipboardEvent, } from './events/onEvent';
22
+ export { asEditableClipboard } from './events/onEvent';
23
+ export { Form } from './Form';
24
+ export type { FormInitProps, TModalOpenPayload } from './Form';
25
+ export { useFormInit } from './FormInitContext';
26
+ export type { FormInitContextValue } from './FormInitContext';
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
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";
19
+ //#region src/lib/index.ts
20
+ function b() {
21
+ return typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof self < "u" ? self : {};
22
+ }
23
+ var x = b();
24
+ x.elcrm ||= {}, Object.assign(x.elcrm, { form: e.version });
25
+ //#endregion
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 };
@@ -0,0 +1,8 @@
1
+ type TMaskPhoneItem = {
2
+ name: string;
3
+ dial_code: string;
4
+ code: string;
5
+ mask: string;
6
+ };
7
+ declare const _default: Readonly<Record<string, TMaskPhoneItem>>;
8
+ export default _default;