@teach-in/react 1.5.0 → 1.6.0

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 (92) hide show
  1. package/dist/{chunk-2UHA3DYG.mjs → chunk-6BWSC6ZH.mjs} +3 -10
  2. package/dist/chunk-7WIZONLU.mjs +81 -0
  3. package/dist/chunk-ALGSVEUS.mjs +1 -0
  4. package/dist/chunk-BHOCYKBI.mjs +81 -0
  5. package/dist/{chunk-VXYV37IM.mjs → chunk-C5FQB2UN.mjs} +16 -8
  6. package/dist/{chunk-CKJ5U5Q4.mjs → chunk-DEKPRZIQ.mjs} +1 -1
  7. package/dist/chunk-GEPCSZCU.mjs +71 -0
  8. package/dist/chunk-VDPROXMN.mjs +57 -0
  9. package/dist/{chunk-R46SWVWL.mjs → chunk-ZK6VZMUJ.mjs} +1 -1
  10. package/dist/index.js +487 -248
  11. package/dist/index.mjs +189 -181
  12. package/dist/ui/data/index.js +56 -7
  13. package/dist/ui/data/index.mjs +10 -8
  14. package/dist/ui/data/user/index.js +51 -2
  15. package/dist/ui/data/user/index.mjs +3 -1
  16. package/dist/ui/data/user/user.d.ts +24 -2
  17. package/dist/ui/data/user/user.js +52 -2
  18. package/dist/ui/data/user/user.mjs +4 -1
  19. package/dist/ui/feedback/index.mjs +12 -12
  20. package/dist/ui/feedback/progress/index.mjs +3 -3
  21. package/dist/ui/form/index.js +76 -18
  22. package/dist/ui/form/index.mjs +24 -19
  23. package/dist/ui/form/rhf/fields/autocomplete-field.mjs +19 -14
  24. package/dist/ui/form/rhf/fields/checkbox-field.mjs +19 -14
  25. package/dist/ui/form/rhf/fields/date-picker-field.mjs +19 -14
  26. package/dist/ui/form/rhf/fields/email-field.js +58 -3
  27. package/dist/ui/form/rhf/fields/email-field.mjs +20 -15
  28. package/dist/ui/form/rhf/fields/index.js +76 -18
  29. package/dist/ui/form/rhf/fields/index.mjs +21 -16
  30. package/dist/ui/form/rhf/fields/input-field.mjs +19 -14
  31. package/dist/ui/form/rhf/fields/radio-field.mjs +19 -14
  32. package/dist/ui/form/rhf/fields/search-field.mjs +19 -14
  33. package/dist/ui/form/rhf/fields/select-field.js +18 -15
  34. package/dist/ui/form/rhf/fields/select-field.mjs +20 -15
  35. package/dist/ui/form/rhf/fields/switch-field.mjs +19 -14
  36. package/dist/ui/form/rhf/fields/text-field.mjs +19 -14
  37. package/dist/ui/form/rhf/fields/textarea-field.mjs +19 -14
  38. package/dist/ui/form/rhf/index.js +76 -18
  39. package/dist/ui/form/rhf/index.mjs +21 -16
  40. package/dist/ui/format/index.mjs +6 -6
  41. package/dist/ui/index.js +487 -248
  42. package/dist/ui/index.mjs +189 -181
  43. package/dist/ui/inputs/checkbox/index.mjs +3 -3
  44. package/dist/ui/inputs/email/email.js +58 -3
  45. package/dist/ui/inputs/email/email.mjs +1 -1
  46. package/dist/ui/inputs/email/index.js +58 -3
  47. package/dist/ui/inputs/email/index.mjs +1 -1
  48. package/dist/ui/inputs/index.d.ts +1 -0
  49. package/dist/ui/inputs/index.js +273 -67
  50. package/dist/ui/inputs/index.mjs +36 -26
  51. package/dist/ui/inputs/number/index.d.ts +1 -0
  52. package/dist/ui/inputs/number/index.js +218 -0
  53. package/dist/ui/inputs/number/index.mjs +12 -0
  54. package/dist/ui/inputs/number/number.d.ts +12 -0
  55. package/dist/ui/inputs/number/number.js +219 -0
  56. package/dist/ui/inputs/number/number.mjs +13 -0
  57. package/dist/ui/inputs/number/use-number.d.ts +20 -0
  58. package/dist/ui/inputs/number/use-number.js +104 -0
  59. package/dist/ui/inputs/number/use-number.mjs +7 -0
  60. package/dist/ui/inputs/radio/index.mjs +3 -3
  61. package/dist/ui/inputs/select/index.d.ts +1 -1
  62. package/dist/ui/inputs/select/index.js +23 -17
  63. package/dist/ui/inputs/select/index.mjs +8 -4
  64. package/dist/ui/inputs/select/select.d.ts +11 -22
  65. package/dist/ui/inputs/select/select.js +23 -17
  66. package/dist/ui/inputs/select/select.mjs +8 -4
  67. package/dist/ui/inputs/select/use-select.d.ts +0 -1
  68. package/dist/ui/inputs/select/use-select.js +2 -9
  69. package/dist/ui/inputs/select/use-select.mjs +1 -1
  70. package/dist/ui/inputs/switch/index.mjs +3 -3
  71. package/dist/ui/layout/container/container.mjs +88 -85
  72. package/dist/ui/layout/container/index.mjs +88 -85
  73. package/dist/ui/layout/index.js +7 -7
  74. package/dist/ui/layout/index.mjs +95 -92
  75. package/dist/ui/layout/page/index.mjs +6 -6
  76. package/dist/ui/layout/page/page-loading.mjs +5 -5
  77. package/dist/ui/layout/page/section-loading.mjs +5 -5
  78. package/dist/ui/navigation/index.mjs +5 -5
  79. package/dist/ui/overlays/index.mjs +4 -4
  80. package/dist/ui/provider/index.mjs +5 -5
  81. package/dist/ui/provider/ui-provider.mjs +5 -5
  82. package/dist/ui/surface/index.mjs +1 -1
  83. package/dist/ui/theme/colors/index.mjs +1 -1
  84. package/dist/ui/theme/colors.mjs +1 -1
  85. package/dist/ui/theme/index.mjs +1 -1
  86. package/dist/ui/theme/theme.d.ts +2 -1
  87. package/dist/ui/theme/theme.mjs +1 -1
  88. package/package.json +13 -9
  89. package/LICENSE +0 -21
  90. package/dist/chunk-46SKVFMZ.mjs +0 -16
  91. package/dist/chunk-XHCXM5MU.mjs +0 -14
  92. /package/dist/{chunk-UQAG7TKJ.mjs → chunk-37MCHF7U.mjs} +0 -0
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/ui/inputs/select/use-select.ts
4
- import { useCallback, useMemo, useState } from "react";
4
+ import { useCallback, useMemo } from "react";
5
5
  function useSelect({
6
6
  value,
7
7
  onChange,
@@ -10,24 +10,17 @@ function useSelect({
10
10
  isClearable = true
11
11
  }) {
12
12
  const isMultiple = selectionMode === "multiple";
13
- const [internalValue, setInternalValue] = useState(
14
- isMultiple ? [] : null
15
- );
16
- const isControlled = value !== void 0;
17
- const currentValue = isControlled ? value : internalValue;
13
+ const currentValue = value != null ? value : isMultiple ? [] : null;
18
14
  const hasValue = currentValue != null && (Array.isArray(currentValue) ? currentValue.length > 0 : currentValue !== "");
19
15
  const handleChange = useCallback(
20
16
  (newValue) => {
21
- if (!isControlled) {
22
- setInternalValue(newValue);
23
- }
24
17
  if (isMultiple) {
25
18
  onChange == null ? void 0 : onChange(newValue);
26
19
  } else {
27
20
  onChange == null ? void 0 : onChange(newValue);
28
21
  }
29
22
  },
30
- [isControlled, onChange, isMultiple]
23
+ [onChange, isMultiple]
31
24
  );
32
25
  const handleClear = useCallback(() => {
33
26
  onClear == null ? void 0 : onClear();
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ // src/ui/inputs/number/use-number.ts
4
+ import { NumberParser } from "@internationalized/number";
5
+ import { useCallback, useMemo, useRef } from "react";
6
+ function normalizeNumberValue(value) {
7
+ if (value == null || Number.isNaN(value)) {
8
+ return null;
9
+ }
10
+ return value;
11
+ }
12
+ function useNumber({
13
+ locale,
14
+ value,
15
+ onChange,
16
+ onValueChange,
17
+ onClear,
18
+ isReadOnly,
19
+ isClearable = true,
20
+ ref
21
+ }) {
22
+ const inputRef = useRef(null);
23
+ const currentValue = normalizeNumberValue(value);
24
+ const hasValue = currentValue !== null;
25
+ const currentLocale = locale != null ? locale : Intl.NumberFormat().resolvedOptions().locale;
26
+ const numberParser = useMemo(() => new NumberParser(currentLocale), [currentLocale]);
27
+ const emitValueChange = useCallback(
28
+ (newValue) => {
29
+ onValueChange == null ? void 0 : onValueChange(newValue);
30
+ onChange == null ? void 0 : onChange(newValue);
31
+ },
32
+ [onChange, onValueChange]
33
+ );
34
+ const handleValueChange = useCallback(
35
+ (incomingValue) => {
36
+ let newValue = null;
37
+ if (incomingValue === null) {
38
+ newValue = null;
39
+ } else if (typeof incomingValue === "number") {
40
+ newValue = Number.isNaN(incomingValue) ? null : incomingValue;
41
+ } else {
42
+ const rawValue = incomingValue.target.value;
43
+ newValue = rawValue === "" ? null : numberParser.parse(rawValue);
44
+ newValue = Number.isNaN(newValue) ? null : newValue;
45
+ }
46
+ emitValueChange(newValue);
47
+ },
48
+ [emitValueChange, numberParser]
49
+ );
50
+ const handleClear = useCallback(() => {
51
+ var _a;
52
+ onClear == null ? void 0 : onClear();
53
+ emitValueChange(null);
54
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
55
+ }, [emitValueChange, onClear]);
56
+ const mergedRef = useCallback(
57
+ (node) => {
58
+ inputRef.current = node;
59
+ if (typeof ref === "function") {
60
+ ref(node);
61
+ } else if (ref) {
62
+ ref.current = node;
63
+ }
64
+ },
65
+ [ref]
66
+ );
67
+ const showClearButton = hasValue && !isReadOnly && isClearable;
68
+ return {
69
+ inputRef,
70
+ currentValue,
71
+ hasValue,
72
+ handleValueChange,
73
+ handleClear,
74
+ mergedRef,
75
+ showClearButton
76
+ };
77
+ }
78
+
79
+ export {
80
+ useNumber
81
+ };
@@ -0,0 +1 @@
1
+ "use client";
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ import {
3
+ useNumber
4
+ } from "./chunk-7WIZONLU.mjs";
5
+ import {
6
+ ClearButton
7
+ } from "./chunk-TUIN5YJW.mjs";
8
+ import {
9
+ cn
10
+ } from "./chunk-LOMRTWX5.mjs";
11
+
12
+ // src/ui/inputs/number/number.tsx
13
+ import React from "react";
14
+ import { NumberInput as HeroUINumberInput } from "@heroui/number-input";
15
+ import { tv } from "tailwind-variants";
16
+ import { jsx, jsxs } from "react/jsx-runtime";
17
+ var inputWrapperVariants = tv({
18
+ variants: {
19
+ variant: {
20
+ flat: "",
21
+ underlined: "",
22
+ bordered: "border-1",
23
+ faded: "border-1"
24
+ }
25
+ }
26
+ });
27
+ var Number = React.forwardRef(
28
+ ({
29
+ locale,
30
+ value,
31
+ onChange,
32
+ onValueChange,
33
+ onClear,
34
+ variant,
35
+ classNames,
36
+ endContent,
37
+ isReadOnly,
38
+ isClearable,
39
+ ...props
40
+ }, ref) => {
41
+ const { currentValue, handleValueChange, handleClear, mergedRef, showClearButton } = useNumber({
42
+ locale,
43
+ value,
44
+ onChange,
45
+ onValueChange,
46
+ onClear,
47
+ isReadOnly,
48
+ isClearable,
49
+ ref
50
+ });
51
+ const normalizedValue = currentValue === null ? globalThis.Number.NaN : currentValue;
52
+ return /* @__PURE__ */ jsx(
53
+ HeroUINumberInput,
54
+ {
55
+ ref: mergedRef,
56
+ classNames: {
57
+ ...classNames,
58
+ inputWrapper: cn(inputWrapperVariants({ variant }), classNames == null ? void 0 : classNames.inputWrapper),
59
+ innerWrapper: cn("group", classNames == null ? void 0 : classNames.innerWrapper)
60
+ },
61
+ endContent: (endContent || showClearButton) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
62
+ endContent,
63
+ showClearButton && /* @__PURE__ */ jsx(ClearButton, { onClear: handleClear })
64
+ ] }),
65
+ inputMode: "decimal",
66
+ isReadOnly,
67
+ value: normalizedValue,
68
+ variant,
69
+ onChange: handleValueChange,
70
+ ...props
71
+ }
72
+ );
73
+ }
74
+ );
75
+ Number.displayName = "TeachInUI.Number";
76
+ var NumberInput = Number;
77
+
78
+ export {
79
+ Number,
80
+ NumberInput
81
+ };
@@ -1,10 +1,13 @@
1
1
  "use client";
2
2
  import {
3
3
  useSelect
4
- } from "./chunk-2UHA3DYG.mjs";
4
+ } from "./chunk-6BWSC6ZH.mjs";
5
5
  import {
6
6
  ClearButton
7
7
  } from "./chunk-TUIN5YJW.mjs";
8
+ import {
9
+ cn
10
+ } from "./chunk-LOMRTWX5.mjs";
8
11
 
9
12
  // src/ui/inputs/select/select.tsx
10
13
  import React from "react";
@@ -24,9 +27,11 @@ var selectWrapperVariants = tv({
24
27
  var Select = React.forwardRef(
25
28
  ({
26
29
  value,
27
- defaultSelectedKeys,
28
30
  items,
31
+ children,
32
+ selectedKeys: selectedKeysProp,
29
33
  onChange,
34
+ onSelectionChange,
30
35
  selectionMode,
31
36
  onClear,
32
37
  variant,
@@ -35,6 +40,8 @@ var Select = React.forwardRef(
35
40
  isClearable,
36
41
  ...props
37
42
  }, ref) => {
43
+ const usesExternalSelectionControl = selectedKeysProp !== void 0 || onSelectionChange !== void 0;
44
+ const selectChildren = children != null ? children : (item) => /* @__PURE__ */ jsx(HeroUISelectItem, { children: item.label }, item.key);
38
45
  const { selectedKeys, handleSelectionChange, handleClear, showClearButton } = useSelect({
39
46
  value,
40
47
  onChange,
@@ -48,27 +55,28 @@ var Select = React.forwardRef(
48
55
  ref,
49
56
  classNames: {
50
57
  ...classNames,
51
- trigger: selectWrapperVariants({ variant }),
58
+ trigger: cn(selectWrapperVariants({ variant }), classNames == null ? void 0 : classNames.trigger),
52
59
  innerWrapper: "group"
53
60
  },
54
- defaultSelectedKeys,
55
61
  endContent: (endContent || showClearButton) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
56
62
  endContent,
57
63
  showClearButton && /* @__PURE__ */ jsx(ClearButton, { onClear: handleClear })
58
64
  ] }),
59
65
  items,
60
- selectedKeys,
66
+ selectedKeys: usesExternalSelectionControl ? selectedKeysProp : selectedKeys,
61
67
  selectionMode,
62
68
  variant,
63
- onSelectionChange: handleSelectionChange,
69
+ onSelectionChange: usesExternalSelectionControl ? onSelectionChange : handleSelectionChange,
64
70
  ...props,
65
- children: (item) => /* @__PURE__ */ jsx(HeroUISelectItem, { children: item.label }, item.key)
71
+ children: selectChildren
66
72
  }
67
73
  );
68
74
  }
69
75
  );
70
76
  Select.displayName = "TeachInUI.Select";
77
+ var SelectItem = HeroUISelectItem;
71
78
 
72
79
  export {
73
- Select
80
+ Select,
81
+ SelectItem
74
82
  };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  Select
4
- } from "./chunk-VXYV37IM.mjs";
4
+ } from "./chunk-C5FQB2UN.mjs";
5
5
 
6
6
  // src/ui/form/rhf/fields/select-field.tsx
7
7
  import { Controller, useFormContext } from "react-hook-form";
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import {
3
+ Input
4
+ } from "./chunk-MCQGBAUS.mjs";
5
+
6
+ // src/ui/inputs/email/email.tsx
7
+ import React from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ var EMAIL_REGEX = /^(?!\.)(?!.*\.\.)[A-Za-zА-Яа-яЁё0-9._+%-]+(?<!\.)@(?:(?:[A-Za-zА-Яа-яЁё0-9](?:[A-Za-zА-Яа-яЁё0-9-]*[A-Za-zА-Яа-яЁё0-9])?)\.)+[A-Za-zА-Яа-яЁё]{2,}$/u;
10
+ var DEFAULT_ERROR_MESSAGE = "\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 email";
11
+ var defaultValidateEmail = (value) => {
12
+ if (!value) {
13
+ return;
14
+ }
15
+ return EMAIL_REGEX.test(value) ? true : DEFAULT_ERROR_MESSAGE;
16
+ };
17
+ function getValidationMessage(result) {
18
+ if (typeof result === "string") {
19
+ return result;
20
+ }
21
+ if (Array.isArray(result)) {
22
+ return result.join(" ");
23
+ }
24
+ return;
25
+ }
26
+ var Email = React.forwardRef(
27
+ ({
28
+ defaultValue,
29
+ errorMessage,
30
+ isInvalid,
31
+ onValueChange,
32
+ validate = defaultValidateEmail,
33
+ value,
34
+ ...props
35
+ }, ref) => {
36
+ const [internalValue, setInternalValue] = React.useState(defaultValue != null ? defaultValue : "");
37
+ const isControlled = value !== void 0;
38
+ const currentValue = isControlled ? value : internalValue;
39
+ const handleValueChange = React.useCallback(
40
+ (nextValue) => {
41
+ if (!isControlled) {
42
+ setInternalValue(nextValue);
43
+ }
44
+ onValueChange == null ? void 0 : onValueChange(nextValue);
45
+ },
46
+ [isControlled, onValueChange]
47
+ );
48
+ const validationMessage = getValidationMessage(validate(currentValue != null ? currentValue : ""));
49
+ const resolvedErrorMessage = errorMessage != null ? errorMessage : validationMessage;
50
+ const resolvedIsInvalid = isInvalid != null ? isInvalid : Boolean(validationMessage);
51
+ return /* @__PURE__ */ jsx(
52
+ Input,
53
+ {
54
+ ref,
55
+ autoComplete: "email",
56
+ errorMessage: resolvedErrorMessage,
57
+ isInvalid: resolvedIsInvalid,
58
+ type: "email",
59
+ validate,
60
+ value: currentValue,
61
+ onValueChange: handleValueChange,
62
+ ...props
63
+ }
64
+ );
65
+ }
66
+ );
67
+ Email.displayName = "TeachInUI.Email";
68
+
69
+ export {
70
+ Email
71
+ };
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import {
3
+ cn
4
+ } from "./chunk-LOMRTWX5.mjs";
5
+
6
+ // src/ui/data/user/user.tsx
7
+ import React from "react";
8
+ import { User as HeroUIUser } from "@heroui/user";
9
+ import { Image } from "@heroui/image";
10
+ import { tv } from "tailwind-variants";
11
+ import { jsx } from "react/jsx-runtime";
12
+ function getNameInitials(fullName) {
13
+ const normalizedFullName = fullName.trim();
14
+ const parts = normalizedFullName.split(" ").filter((part) => part.length > 0);
15
+ if (parts.length >= 2) {
16
+ return parts[0][0].toUpperCase() + parts[1][0].toUpperCase();
17
+ }
18
+ return normalizedFullName.slice(0, 2).toUpperCase();
19
+ }
20
+ var userVariants = tv({
21
+ base: "flex items-start gap-2 hyphens-auto",
22
+ variants: {
23
+ direction: {
24
+ row: "flex-row",
25
+ column: "flex-col items-center"
26
+ }
27
+ },
28
+ defaultVariants: {
29
+ direction: "row"
30
+ }
31
+ });
32
+ var User = React.forwardRef(
33
+ ({ name, avatarProps, className, direction = "row", ...props }, ref) => {
34
+ var _a, _b;
35
+ return /* @__PURE__ */ jsx(
36
+ HeroUIUser,
37
+ {
38
+ ref,
39
+ avatarProps: {
40
+ ...avatarProps,
41
+ className: cn("shrink-0", avatarProps == null ? void 0 : avatarProps.className),
42
+ name: (_a = avatarProps == null ? void 0 : avatarProps.name) != null ? _a : getNameInitials(name),
43
+ ImgComponent: Image,
44
+ showFallback: (_b = avatarProps == null ? void 0 : avatarProps.showFallback) != null ? _b : true
45
+ },
46
+ className: userVariants({ direction, className }),
47
+ name,
48
+ ...props
49
+ }
50
+ );
51
+ }
52
+ );
53
+ User.displayName = "TeachInUI.User";
54
+
55
+ export {
56
+ User
57
+ };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  Email
4
- } from "./chunk-46SKVFMZ.mjs";
4
+ } from "./chunk-GEPCSZCU.mjs";
5
5
 
6
6
  // src/ui/form/rhf/fields/email-field.tsx
7
7
  import { Controller, useFormContext } from "react-hook-form";