@yimingliao/cms 0.0.98 → 0.0.100

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.
@@ -6,7 +6,7 @@ import * as _tanstack_query_core from '@tanstack/query-core';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
  import { c as createVerifyAction, a as createSignInAction, b as createVerifyEmailAction, d as createEmailUnverifiedAction, e as createForgotPasswordAction, f as createResetPasswordAction, g as createChangePasswordAction } from '../create-reset-password-action-D6aTuuqO.js';
8
8
  import * as React$1 from 'react';
9
- import { ReactNode, ComponentProps, HTMLAttributes, InputHTMLAttributes } from 'react';
9
+ import { ReactNode, ComponentProps, HTMLAttributes, InputHTMLAttributes, Dispatch, SetStateAction } from 'react';
10
10
  import { LucideIcon } from 'lucide-react';
11
11
  import { B as ButtonProps$1, L as LabelProps } from '../label-BF4qxS03.js';
12
12
  import { ClassValue } from 'clsx';
@@ -368,9 +368,14 @@ interface ButtonProps extends ButtonProps$1, UIStates {
368
368
  }
369
369
  declare function Button({ icon, href, openNewTab, isDisabled, isLoading, children, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
370
370
 
371
- interface InputProps<T extends FormData = FormData> extends ComponentProps<"input">, FormFieldController<T> {
371
+ interface ReturnButtonProps extends ButtonProps {
372
+ useIcon?: boolean;
373
+ useConfirm?: boolean;
374
+ replace?: boolean;
375
+ pushToParent?: boolean;
376
+ replaceParent?: boolean;
372
377
  }
373
- declare function Input<T extends FormData = FormData>({ fieldName, setFormData, isLoading, isDisabled, isError, className, children, ...props }: InputProps<T>): react_jsx_runtime.JSX.Element;
378
+ declare function ReturnButton({ icon, useIcon, useConfirm, href, replace, pushToParent, replaceParent, className, children, ...props }: ReturnButtonProps): react_jsx_runtime.JSX.Element;
374
379
 
375
380
  interface PageHeaderProps {
376
381
  titleProps?: PageHeaderTitleProps;
@@ -420,6 +425,11 @@ declare function MainFields({ className, children, ...props }: ComponentProps<"d
420
425
 
421
426
  declare function SideFields({ className, children, ...props }: ComponentProps<"div">): react_jsx_runtime.JSX.Element;
422
427
 
428
+ interface InputProps<T extends FormData = FormData> extends ComponentProps<"input">, FormFieldController<T> {
429
+ inputGroupClassName?: string;
430
+ }
431
+ declare function Input<T extends FormData = FormData>({ fieldName, setFormData, isLoading, isDisabled, isError, className, inputGroupClassName, children, ...props }: InputProps<T>): react_jsx_runtime.JSX.Element;
432
+
423
433
  declare function PasswordInput<T extends FormData = FormData>({ ...props }: InputProps<T>): react_jsx_runtime.JSX.Element;
424
434
 
425
435
  interface CheckboxProps<T extends FormData = FormData> extends InputHTMLAttributes<HTMLInputElement>, FormFieldController<T> {
@@ -427,6 +437,22 @@ interface CheckboxProps<T extends FormData = FormData> extends InputHTMLAttribut
427
437
  }
428
438
  declare function Checkbox<T extends FormData = FormData>({ fieldName, formData, setFormData, isLoading, isDisabled, isDisplay, className, ...props }: CheckboxProps<T>): react_jsx_runtime.JSX.Element;
429
439
 
440
+ interface TextareaProps<T extends FormData = FormData> extends ComponentProps<"textarea">, FormFieldController<T> {
441
+ }
442
+ declare function Textarea<T extends FormData = FormData>({ fieldName, setFormData, isLoading, isDisabled, isError, ...props }: TextareaProps<T>): react_jsx_runtime.JSX.Element;
443
+
444
+ interface ArrayInputProps<T extends FormData = FormData> extends ComponentProps<"textarea">, FormFieldController<T> {
445
+ isResizable?: boolean;
446
+ errors: string[];
447
+ }
448
+ declare function ArrayInput<T extends FormData = FormData>({ formData, fieldName, setFormData, isLoading, isDisabled, isResizable, errors, placeholder, ...props }: ArrayInputProps<T>): react_jsx_runtime.JSX.Element;
449
+
450
+ interface SearchInputProps extends InputProps {
451
+ searchString: string;
452
+ setSearchString: Dispatch<SetStateAction<string>>;
453
+ }
454
+ declare function SearchInput({ searchString, setSearchString, isLoading, isDisabled, ...props }: SearchInputProps): react_jsx_runtime.JSX.Element;
455
+
430
456
  /**
431
457
  * [Auth] sign-in
432
458
  *
@@ -503,4 +529,4 @@ declare const cn: (...inputs: ClassValue[]) => string;
503
529
 
504
530
  declare function useDeviceInfo(): DeviceInfo | null;
505
531
 
506
- export { AdminProvider, Button, type ButtonProps, Checkbox, Field, FieldBody, FieldsContainer, Form, Input, type InputProps, MainFields, PageHeader, PasswordInput, type ShowToastOption, SideFields, cn, createAdminInitializer, createChangePasswordPage, createEmailUnverifiedPage, createForgotPasswordPage, createRequestInterceptor, createResetPasswordPage, createResponseInterceptor, createSignInPage, createSmartFetch, createUseCommand, createUseQuery, createVerifyEmailPage, handleToast, useAdmin, useDeviceInfo };
532
+ export { AdminProvider, ArrayInput, Button, type ButtonProps, Checkbox, Field, FieldBody, FieldsContainer, Form, Input, type InputProps, MainFields, PageHeader, PasswordInput, ReturnButton, SearchInput, type ShowToastOption, SideFields, Textarea, cn, createAdminInitializer, createChangePasswordPage, createEmailUnverifiedPage, createForgotPasswordPage, createRequestInterceptor, createResetPasswordPage, createResponseInterceptor, createSignInPage, createSmartFetch, createUseCommand, createUseQuery, createVerifyEmailPage, handleToast, useAdmin, useDeviceInfo };
@@ -1,12 +1,12 @@
1
- import { Button, Spinner, InputGroup, InputGroupAddon, InputGroupInput, cn, Separator, Label, InputGroupButton, useDeviceInfo, Card, CardHeader, CardTitle, CardContent, useCountdown, CardDescription, useParentPathname, isConfirm } from '../chunk-FLKUBNE4.js';
1
+ import { Button, Spinner, useParentPathname, cn, Separator, Label, InputGroup, InputGroupAddon, InputGroupInput, InputGroupButton, Textarea, useDeviceInfo, Card, CardHeader, CardTitle, CardContent, useCountdown, CardDescription, isConfirm } from '../chunk-FLKUBNE4.js';
2
2
  export { cn, useDeviceInfo } from '../chunk-FLKUBNE4.js';
3
3
  import { ensureArray } from '../chunk-OAENV763.js';
4
4
  import { toast } from 'sonner';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import { useMutation, useQuery } from '@tanstack/react-query';
7
- import { createContext, useState, useContext, useEffect, createElement } from 'react';
7
+ import { createContext, useState, useContext, useEffect, createElement, useRef } from 'react';
8
8
  import { useTranslator } from 'intor/react';
9
- import { Files, Asterisk, Eye, EyeOff, Mail, Trash2, CopyCheck, CopyX, FileSymlink, FileX, FilePlus, FilePen, File, FileStack, FolderSearch, Lock, FolderCog, FileSpreadsheet, Undo2 } from 'lucide-react';
9
+ import { Undo2, Files, Asterisk, Eye, EyeOff, CircleX, CirclePlus, Search, Mail, Trash2, CopyCheck, CopyX, FileSymlink, FileX, FilePlus, FilePen, File, FileStack, FolderSearch, Lock, FolderCog, FileSpreadsheet } from 'lucide-react';
10
10
  import { useRouter, useSearchParams } from 'next/navigation';
11
11
  import Link from 'next/link';
12
12
 
@@ -297,36 +297,6 @@ function Button2({
297
297
  }
298
298
  );
299
299
  }
300
- function Input({
301
- // form context
302
- fieldName,
303
- setFormData,
304
- // ui states
305
- isLoading = false,
306
- isDisabled = false,
307
- isError = false,
308
- // base
309
- className,
310
- children,
311
- ...props
312
- }) {
313
- return /* @__PURE__ */ jsxs(InputGroup, { "data-disabled": isDisabled || isLoading, className: "h-10", children: [
314
- isLoading ? /* @__PURE__ */ jsx(InputGroupAddon, { children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx(
315
- InputGroupInput,
316
- {
317
- disabled: isDisabled || isLoading,
318
- "aria-invalid": isError,
319
- onChange: (e) => {
320
- if (!setFormData || !fieldName) return;
321
- setFormData((p) => ({ ...p, [fieldName]: e.target.value }));
322
- },
323
- className: cn("h-10", className),
324
- ...props
325
- }
326
- ),
327
- children
328
- ] });
329
- }
330
300
  function ReturnButton({
331
301
  icon,
332
302
  useIcon = true,
@@ -733,6 +703,44 @@ function SideFields({
733
703
  }
734
704
  );
735
705
  }
706
+ function Input({
707
+ // form context
708
+ fieldName,
709
+ setFormData,
710
+ // ui states
711
+ isLoading = false,
712
+ isDisabled = false,
713
+ isError = false,
714
+ // base
715
+ className,
716
+ inputGroupClassName,
717
+ children,
718
+ ...props
719
+ }) {
720
+ return /* @__PURE__ */ jsxs(
721
+ InputGroup,
722
+ {
723
+ "data-disabled": isDisabled || isLoading,
724
+ className: cn("h-10", inputGroupClassName),
725
+ children: [
726
+ isLoading ? /* @__PURE__ */ jsx(InputGroupAddon, { children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx(
727
+ InputGroupInput,
728
+ {
729
+ disabled: isDisabled || isLoading,
730
+ "aria-invalid": isError,
731
+ onChange: (e) => {
732
+ if (!setFormData || !fieldName) return;
733
+ setFormData((p) => ({ ...p, [fieldName]: e.target.value }));
734
+ },
735
+ className: cn("h-10", className),
736
+ ...props
737
+ }
738
+ ),
739
+ children
740
+ ]
741
+ }
742
+ );
743
+ }
736
744
  function PasswordInput({
737
745
  ...props
738
746
  }) {
@@ -818,6 +826,163 @@ function Checkbox({
818
826
  }
819
827
  );
820
828
  }
829
+ function Textarea2({
830
+ // form context
831
+ fieldName,
832
+ setFormData,
833
+ // ui states
834
+ isLoading = false,
835
+ isDisabled = false,
836
+ isError = false,
837
+ // base
838
+ ...props
839
+ }) {
840
+ isDisabled = isDisabled || isLoading;
841
+ const textareaRef = useRef(null);
842
+ const resetHeight = (element) => {
843
+ element.style.height = "40px";
844
+ element.style.height = `${element.scrollHeight + 2}px`;
845
+ };
846
+ useEffect(() => {
847
+ if (!textareaRef.current) return;
848
+ resetHeight(textareaRef.current);
849
+ }, [props.value, isLoading]);
850
+ return /* @__PURE__ */ jsx(Fragment, { children: isLoading ? /* @__PURE__ */ jsx(InputGroup, { "data-disabled": isDisabled, className: "h-10", children: /* @__PURE__ */ jsx(InputGroupAddon, { children: /* @__PURE__ */ jsx(Spinner, {}) }) }) : /* @__PURE__ */ jsx(
851
+ Textarea,
852
+ {
853
+ ref: textareaRef,
854
+ disabled: isDisabled,
855
+ "aria-invalid": isError,
856
+ value: isLoading ? "" : props.value,
857
+ onChange: (e) => {
858
+ resetHeight(e.target);
859
+ if (!setFormData || !fieldName) return;
860
+ setFormData((p) => ({ ...p, [fieldName]: e.target.value }));
861
+ },
862
+ ...props
863
+ }
864
+ ) });
865
+ }
866
+ function ArrayInput({
867
+ // form context
868
+ formData,
869
+ fieldName,
870
+ setFormData,
871
+ // ui states
872
+ isLoading = false,
873
+ isDisabled = false,
874
+ isResizable = false,
875
+ errors,
876
+ // base
877
+ placeholder = "",
878
+ ...props
879
+ }) {
880
+ isDisabled = isDisabled || isLoading;
881
+ const rawValue = formData?.[fieldName ?? ""];
882
+ const values = Array.isArray(rawValue) && rawValue.length > 0 ? rawValue.map(String) : [""];
883
+ const errorIndexes = new Set(
884
+ errors.filter((e) => e.startsWith(fieldName ?? "")).map((e) => e.split(".").pop()).map(Number)
885
+ );
886
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: values.map((value, index) => {
887
+ const isError = errorIndexes.has(index);
888
+ return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
889
+ /* @__PURE__ */ jsxs("div", { className: "flex-center absolute top-0 left-0 z-10 h-full", children: [
890
+ /* @__PURE__ */ jsx("span", { className: "min-w-10 pl-0.5 text-center text-sm opacity-50", children: Array.isArray(rawValue) && rawValue.length === 0 ? "0" : index + 1 }),
891
+ /* @__PURE__ */ jsx(Separator, { orientation: "vertical" })
892
+ ] }),
893
+ /* @__PURE__ */ jsx(
894
+ Textarea2,
895
+ {
896
+ disabled: isDisabled,
897
+ placeholder: isLoading ? "" : placeholder,
898
+ value,
899
+ onChange: (e) => {
900
+ if (!setFormData || !fieldName) return;
901
+ const copy = [...values];
902
+ copy[index] = e.target.value;
903
+ setFormData((p) => ({ ...p, [fieldName]: copy }));
904
+ },
905
+ onKeyDown: (e) => {
906
+ if (e.key === "Enter" && !isResizable) {
907
+ e.preventDefault();
908
+ }
909
+ },
910
+ isError,
911
+ className: cn("pr-20 pl-13", !isResizable && "resize-none"),
912
+ ...props
913
+ }
914
+ ),
915
+ /* @__PURE__ */ jsxs("div", { className: "flex-center absolute top-1 right-1 gap-1", children: [
916
+ /* @__PURE__ */ jsx(
917
+ Button2,
918
+ {
919
+ variant: "outline",
920
+ type: "button",
921
+ size: "icon-sm",
922
+ className: "rounded-sm",
923
+ onClick: () => {
924
+ if (!setFormData || !fieldName) return;
925
+ const copy = values.filter((_, i) => i !== index);
926
+ setFormData((p) => ({ ...p, [fieldName]: copy }));
927
+ },
928
+ children: /* @__PURE__ */ jsx(CircleX, { className: "text-destructive" })
929
+ }
930
+ ),
931
+ /* @__PURE__ */ jsx(
932
+ Button2,
933
+ {
934
+ variant: "outline",
935
+ type: "button",
936
+ size: "icon-sm",
937
+ className: "rounded-sm",
938
+ onClick: () => {
939
+ if (!setFormData || !fieldName) return;
940
+ const copy = [...values];
941
+ copy.splice(index + 1, 0, "");
942
+ setFormData((p) => ({ ...p, [fieldName]: copy }));
943
+ },
944
+ children: /* @__PURE__ */ jsx(CirclePlus, { className: "text-success" })
945
+ }
946
+ )
947
+ ] })
948
+ ] }, index);
949
+ }) });
950
+ }
951
+ function SearchInput({
952
+ searchString = "",
953
+ setSearchString,
954
+ isLoading = false,
955
+ isDisabled = false,
956
+ ...props
957
+ }) {
958
+ const { t } = useTranslator();
959
+ const isComposingRef = useRef(false);
960
+ const [inputValue, setInputValue] = useState(searchString);
961
+ const handleCompositionEnd = (e) => {
962
+ isComposingRef.current = false;
963
+ setInputValue(e.currentTarget.value);
964
+ setSearchString(e.currentTarget.value);
965
+ };
966
+ const handleChange = (e) => {
967
+ setInputValue(e.target.value);
968
+ if (!isComposingRef.current) setSearchString(e.target.value);
969
+ };
970
+ return /* @__PURE__ */ jsx("div", { className: "relative size-full", children: /* @__PURE__ */ jsx(
971
+ Input,
972
+ {
973
+ isDisabled,
974
+ placeholder: isLoading ? "" : t("ui.search.text"),
975
+ autoComplete: "off",
976
+ value: inputValue,
977
+ onChange: handleChange,
978
+ onCompositionStart: () => isComposingRef.current = true,
979
+ onCompositionEnd: handleCompositionEnd,
980
+ className: "w-full pr-9",
981
+ ...props,
982
+ children: /* @__PURE__ */ jsx(InputGroupAddon, { align: "inline-end", children: isLoading ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(Search, {}) })
983
+ }
984
+ ) });
985
+ }
821
986
 
822
987
  // src/constants/keys/auth.ts
823
988
  var AUTH_KEYS = {
@@ -1295,4 +1460,4 @@ function createChangePasswordPage({
1295
1460
  };
1296
1461
  }
1297
1462
 
1298
- export { AdminProvider, Button2 as Button, Checkbox, Field, FieldBody, FieldsContainer, Form, Input, MainFields, PageHeader, PasswordInput, SideFields, createAdminInitializer, createChangePasswordPage, createEmailUnverifiedPage, createForgotPasswordPage, createRequestInterceptor, createResetPasswordPage, createResponseInterceptor, createSignInPage, createSmartFetch, createUseCommand, createUseQuery, createVerifyEmailPage, handleToast, useAdmin };
1463
+ export { AdminProvider, ArrayInput, Button2 as Button, Checkbox, Field, FieldBody, FieldsContainer, Form, Input, MainFields, PageHeader, PasswordInput, ReturnButton, SearchInput, SideFields, Textarea2 as Textarea, createAdminInitializer, createChangePasswordPage, createEmailUnverifiedPage, createForgotPasswordPage, createRequestInterceptor, createResetPasswordPage, createResponseInterceptor, createSignInPage, createSmartFetch, createUseCommand, createUseQuery, createVerifyEmailPage, handleToast, useAdmin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yimingliao/cms",
3
- "version": "0.0.98",
3
+ "version": "0.0.100",
4
4
  "author": "Yiming Liao",
5
5
  "license": "MIT",
6
6
  "type": "module",