@akanjs/ui 0.9.10 → 0.9.12

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/Field.d.ts CHANGED
@@ -26,8 +26,8 @@ export declare const Field: {
26
26
  Price: import("react").MemoExoticComponent<({ label, desc, labelClassName, className, value, onChange, placeholder, nullable, disabled, minlength, maxlength, transform, validate, onPressEnter, inputClassName, inputStyleType, }: PriceProps) => import("react/jsx-runtime").JSX.Element>;
27
27
  TextArea: import("react").MemoExoticComponent<({ label, desc, labelClassName, className, value, onChange, placeholder, nullable, disabled, rows, minlength, maxlength, transform, validate, onPressEnter, cache, inputClassName, }: TextAreaProps) => import("react/jsx-runtime").JSX.Element>;
28
28
  Switch: ({ label, desc, labelClassName, className, value, onChange, disabled, inputClassName, onDesc, offDesc, }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
29
- ToggleSelect: <I extends string | number | boolean | null>({ className, labelClassName, label, desc, model, field, items, value, validate, onChange, nullable, disabled, btnClassName, }: ToggleSelectProps<I>) => import("react/jsx-runtime").JSX.Element;
30
- MultiToggleSelect: <I extends string | number | boolean>({ className, labelClassName, label, desc, model, field, items, value, minlength, maxlength, validate, onChange, disabled, }: MultiToggleSelectProps<I>) => import("react/jsx-runtime").JSX.Element;
29
+ ToggleSelect: <I extends string>({ className, labelClassName, label, desc, model, field, items, value, validate, onChange, nullable, disabled, btnClassName, }: ToggleSelectProps<I>) => import("react/jsx-runtime").JSX.Element;
30
+ MultiToggleSelect: <I>({ className, labelClassName, label, desc, model, field, items, value, minlength, maxlength, validate, onChange, disabled, }: MultiToggleSelectProps<I>) => import("react/jsx-runtime").JSX.Element;
31
31
  TextList: ({ label, desc, labelClassName, className, value, onChange, placeholder, disabled, transform, minlength, maxlength, minTextlength, maxTextlength, cache, validate, inputClassName, }: TextListProps) => import("react/jsx-runtime").JSX.Element;
32
32
  Tags: ({ label, desc, labelClassName, className, value, onChange, placeholder, disabled, transform, minlength, maxlength, minTextlength, maxTextlength, validate, inputClassName, }: TagsProps) => import("react/jsx-runtime").JSX.Element;
33
33
  Date: <Nullable extends boolean>({ className, labelClassName, nullable, label, desc, value, min, max, onChange, showTime, dateClassName, }: DateProps<Nullable>) => import("react/jsx-runtime").JSX.Element;
@@ -148,14 +148,14 @@ interface ToggleSelectProps<I> {
148
148
  label: string;
149
149
  value: I;
150
150
  }[] | readonly I[] | I[] | Enum<I>;
151
- value: I;
151
+ value: I | null;
152
152
  nullable?: boolean;
153
153
  disabled?: boolean;
154
154
  validate?: (value: I) => boolean | string;
155
155
  onChange: (value: I) => void;
156
156
  btnClassName?: string;
157
157
  }
158
- interface MultiToggleSelectProps<I extends string | number | boolean> {
158
+ interface MultiToggleSelectProps<I> {
159
159
  className?: string;
160
160
  labelClassName?: string;
161
161
  label?: string;
package/Select.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import { Enum } from "@akanjs/base";
2
2
  import { ReactNode } from "react";
3
- interface LabelOption<T> {
3
+ type Options<T> = T[] | {
4
4
  label: string | boolean | number;
5
5
  value: T;
6
- }
7
- type Options<T> = T[] | LabelOption<T>[] | Enum<T>;
8
- interface SelectProps<T extends string | number | boolean | null | undefined, Multiple extends boolean = false, Searchable extends boolean = false, Option extends Options<T> = Options<T>> {
6
+ }[] | Enum<T>;
7
+ interface SelectProps<T, Multiple extends boolean = false, Searchable extends boolean = false> {
9
8
  label?: string;
10
9
  desc?: string;
11
10
  labelClassName?: string;
12
11
  className?: string;
13
- value: Multiple extends true ? T[] : T;
14
- options: Searchable extends true ? (T extends string ? Option : LabelOption<T>[]) : Option;
12
+ value: Multiple extends true ? T[] : T | null;
13
+ options: Searchable extends true ? T extends string ? Options<T> : {
14
+ label: string | boolean | number;
15
+ value: T;
16
+ }[] : Options<T>;
15
17
  multiple?: Multiple;
16
18
  searchable?: Searchable;
17
19
  placeholder?: string;
@@ -21,10 +23,10 @@ interface SelectProps<T extends string | number | boolean | null | undefined, Mu
21
23
  nullable?: boolean;
22
24
  disabled?: boolean;
23
25
  onOpen?: () => void;
24
- onChange: Multiple extends true ? (value: T[], prev: T[]) => void : (value: T, prev: T) => void;
26
+ onChange: Multiple extends true ? (value: T[], prev: T[]) => void : (value: T | undefined, prev: T | undefined) => void;
25
27
  onSearch?: (text: string) => void;
26
28
  renderOption?: (value: T) => ReactNode;
27
29
  renderSelected?: (value: T) => ReactNode;
28
30
  }
29
- export declare const Select: <T extends string | number | boolean | null | undefined, Multiple extends boolean = false, Searchable extends boolean = false, Option extends Options<T> = Options<T>>({ label, desc, labelClassName, className, value, options, nullable, disabled, multiple, searchable, placeholder, selectClassName, selectorClassName, selectedClassName, onOpen, onChange, onSearch, renderOption, renderSelected, }: SelectProps<T, Multiple, Searchable, Option>) => import("react/jsx-runtime").JSX.Element;
31
+ export declare const Select: <T, Multiple extends boolean = false, Searchable extends boolean = false>({ label, desc, labelClassName, className, value, options, nullable, disabled, multiple, searchable, placeholder, selectClassName, selectorClassName, selectedClassName, onOpen, onChange, onSearch, renderOption, renderSelected, }: SelectProps<T, Multiple, Searchable>) => import("react/jsx-runtime").JSX.Element;
30
32
  export {};
package/ToggleSelect.d.ts CHANGED
@@ -1,18 +1,18 @@
1
- interface ToggleSelectProps<I extends string | number | boolean | null> {
1
+ interface ToggleSelectProps {
2
2
  className?: string;
3
3
  btnClassName?: string;
4
4
  items: string[] | {
5
5
  label: string;
6
- value: I;
6
+ value: string;
7
7
  }[];
8
- value: I;
8
+ value: string | null;
9
9
  nullable: boolean;
10
- validate: (value: I) => boolean | string;
11
- onChange: (value: I, idx: number) => void;
10
+ validate: (value: string) => boolean | string;
11
+ onChange: (value: string, idx: number) => void;
12
12
  disabled?: boolean;
13
13
  }
14
14
  export declare const ToggleSelect: {
15
- <I extends string | number | boolean | null>({ className, btnClassName, items, nullable, validate, value, onChange, disabled, }: ToggleSelectProps<I>): import("react/jsx-runtime").JSX.Element;
15
+ ({ className, btnClassName, items, nullable, validate, value, onChange, disabled, }: ToggleSelectProps): import("react/jsx-runtime").JSX.Element;
16
16
  Multi: ({ className, btnClassName, items, nullable, validate, value, onChange, disabled }: MultiProps) => import("react/jsx-runtime").JSX.Element;
17
17
  };
18
18
  interface MultiProps {
@@ -223,11 +223,11 @@ const SelectIDWithRef = ({ queryArgMeta, value, onChange }) => {
223
223
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
224
  import_Select.Select,
225
225
  {
226
- value,
227
226
  options: modelList.map((model) => ({
228
227
  label: renderOption(model),
229
228
  value: model.id
230
229
  })),
230
+ value,
231
231
  onChange: (value2) => {
232
232
  onChange(value2);
233
233
  }
package/cjs/Field.js CHANGED
@@ -990,33 +990,26 @@ const Parent = ({
990
990
  desc,
991
991
  labelClassName,
992
992
  selectClassName,
993
- value: value?.id ?? null,
993
+ value: value?.id,
994
994
  searchable: true,
995
995
  options: modelList.map((model) => {
996
996
  const render = renderOption(model);
997
997
  return { label: typeof render === "string" ? render : model.id, value: model.id };
998
998
  }),
999
999
  renderOption: (modelId) => {
1000
- if (!modelId)
1001
- return null;
1002
1000
  const model = modelList.get(modelId);
1003
1001
  if (!model)
1004
1002
  return null;
1005
1003
  return renderOption(model);
1006
1004
  },
1007
1005
  renderSelected: (modelId) => {
1008
- if (!modelId)
1009
- return null;
1010
1006
  const model = modelList.get(modelId);
1011
1007
  if (!model)
1012
1008
  return null;
1013
1009
  return renderSelected(model);
1014
1010
  },
1015
1011
  onChange: (modelId) => {
1016
- if (modelId)
1017
- onChange(modelList.get(modelId) ?? null);
1018
- else
1019
- onChange(null);
1012
+ onChange(modelList.get(modelId));
1020
1013
  },
1021
1014
  onOpen: () => {
1022
1015
  if (!disabled)
@@ -1079,16 +1072,12 @@ const ParentId = ({
1079
1072
  return { label: typeof label2 === "string" ? label2 : model.id, value: model.id };
1080
1073
  }),
1081
1074
  renderOption: (renderId) => {
1082
- if (!renderId)
1083
- return null;
1084
1075
  const model = modelList.get(renderId);
1085
1076
  if (!model)
1086
1077
  return null;
1087
1078
  return renderOption?.(model) ?? null;
1088
1079
  },
1089
1080
  renderSelected: (renderId) => {
1090
- if (!renderId)
1091
- return null;
1092
1081
  const model = modelList.get(renderId);
1093
1082
  if (!model)
1094
1083
  return null;
@@ -1099,10 +1088,7 @@ const ParentId = ({
1099
1088
  void storeDo[namesOfSlice.initModel](...initArgs ?? []);
1100
1089
  },
1101
1090
  onChange: (modelId) => {
1102
- if (modelId)
1103
- onChange(modelId, modelList.get(modelId));
1104
- else
1105
- onChange(null, null);
1091
+ onChange(modelId, modelList.get(modelId));
1106
1092
  },
1107
1093
  onSearch
1108
1094
  }
package/cjs/Select.js CHANGED
@@ -53,10 +53,7 @@ const Select = ({
53
53
  const { l } = (0, import_next.usePage)();
54
54
  const [isOpen, setIsOpen] = (0, import_react.useState)(false);
55
55
  const labeledOptions = (0, import_react.useMemo)(
56
- () => options instanceof import_base.Enum ? options.values.map((v) => ({
57
- label: typeof v === "string" ? v : typeof v === "object" ? JSON.stringify(v) : String(v),
58
- value: v
59
- })) : options[0]?.label && options[0]?.value ? options : options.map((v) => ({ label: v, value: v })),
56
+ () => options instanceof import_base.Enum ? options.values.map((v) => ({ label: v, value: v })) : options[0]?.label && options[0]?.value ? options : options.map((v) => ({ label: v, value: v })),
60
57
  [options]
61
58
  );
62
59
  const [selectedValues, setSelectedValues] = (0, import_react.useState)(multiple ? value : [value]);
package/cjs/System/CSR.js CHANGED
@@ -64,7 +64,7 @@ const CSRProvider = ({
64
64
  return { lang };
65
65
  },
66
66
  render: ({ lang }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
67
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Client.Client.Wrapper, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
67
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Client.Client.Wrapper, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
68
68
  CSRWrapper,
69
69
  {
70
70
  className,
@@ -74,7 +74,11 @@ const CSRProvider = ({
74
74
  fonts,
75
75
  prefix,
76
76
  layoutStyle,
77
- children
77
+ children: [
78
+ children,
79
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Client.Client.Inner, {}),
80
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CSRInner, {})
81
+ ]
78
82
  }
79
83
  ) }),
80
84
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -86,8 +90,6 @@ const CSRProvider = ({
86
90
  fetchMe,
87
91
  fetchSelf,
88
92
  render: ({ mePromise, selfPromise }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
89
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Client.Client.Inner, {}),
90
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CSRInner, {}),
91
93
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
94
  import_Client.Client.Bridge,
93
95
  {
@@ -34,8 +34,8 @@ const ToggleSelect = ({
34
34
  disabled
35
35
  }) => {
36
36
  const { l } = (0, import_next.usePage)();
37
- const validateResult = value ? validate(value) : false;
38
- const invalidMessage = value === null || typeof value === "string" && !value.length || validateResult === true ? null : validateResult === false ? l("util.invalidValueError") : validateResult;
37
+ const validateResult = validate(value ?? "");
38
+ const invalidMessage = !value?.length || validateResult === true ? null : validateResult === false ? l("util.invalidValueError") : validateResult;
39
39
  const options = items.map(
40
40
  (item) => typeof item === "string" ? { label: item, value: item } : item
41
41
  );
@@ -209,11 +209,11 @@ const SelectIDWithRef = ({ queryArgMeta, value, onChange }) => {
209
209
  /* @__PURE__ */ jsx(
210
210
  Select,
211
211
  {
212
- value,
213
212
  options: modelList.map((model) => ({
214
213
  label: renderOption(model),
215
214
  value: model.id
216
215
  })),
216
+ value,
217
217
  onChange: (value2) => {
218
218
  onChange(value2);
219
219
  }
package/esm/Field.js CHANGED
@@ -968,33 +968,26 @@ const Parent = ({
968
968
  desc,
969
969
  labelClassName,
970
970
  selectClassName,
971
- value: value?.id ?? null,
971
+ value: value?.id,
972
972
  searchable: true,
973
973
  options: modelList.map((model) => {
974
974
  const render = renderOption(model);
975
975
  return { label: typeof render === "string" ? render : model.id, value: model.id };
976
976
  }),
977
977
  renderOption: (modelId) => {
978
- if (!modelId)
979
- return null;
980
978
  const model = modelList.get(modelId);
981
979
  if (!model)
982
980
  return null;
983
981
  return renderOption(model);
984
982
  },
985
983
  renderSelected: (modelId) => {
986
- if (!modelId)
987
- return null;
988
984
  const model = modelList.get(modelId);
989
985
  if (!model)
990
986
  return null;
991
987
  return renderSelected(model);
992
988
  },
993
989
  onChange: (modelId) => {
994
- if (modelId)
995
- onChange(modelList.get(modelId) ?? null);
996
- else
997
- onChange(null);
990
+ onChange(modelList.get(modelId));
998
991
  },
999
992
  onOpen: () => {
1000
993
  if (!disabled)
@@ -1057,16 +1050,12 @@ const ParentId = ({
1057
1050
  return { label: typeof label2 === "string" ? label2 : model.id, value: model.id };
1058
1051
  }),
1059
1052
  renderOption: (renderId) => {
1060
- if (!renderId)
1061
- return null;
1062
1053
  const model = modelList.get(renderId);
1063
1054
  if (!model)
1064
1055
  return null;
1065
1056
  return renderOption?.(model) ?? null;
1066
1057
  },
1067
1058
  renderSelected: (renderId) => {
1068
- if (!renderId)
1069
- return null;
1070
1059
  const model = modelList.get(renderId);
1071
1060
  if (!model)
1072
1061
  return null;
@@ -1077,10 +1066,7 @@ const ParentId = ({
1077
1066
  void storeDo[namesOfSlice.initModel](...initArgs ?? []);
1078
1067
  },
1079
1068
  onChange: (modelId) => {
1080
- if (modelId)
1081
- onChange(modelId, modelList.get(modelId));
1082
- else
1083
- onChange(null, null);
1069
+ onChange(modelId, modelList.get(modelId));
1084
1070
  },
1085
1071
  onSearch
1086
1072
  }
package/esm/Select.js CHANGED
@@ -31,10 +31,7 @@ const Select = ({
31
31
  const { l } = usePage();
32
32
  const [isOpen, setIsOpen] = useState(false);
33
33
  const labeledOptions = useMemo(
34
- () => options instanceof Enum ? options.values.map((v) => ({
35
- label: typeof v === "string" ? v : typeof v === "object" ? JSON.stringify(v) : String(v),
36
- value: v
37
- })) : options[0]?.label && options[0]?.value ? options : options.map((v) => ({ label: v, value: v })),
34
+ () => options instanceof Enum ? options.values.map((v) => ({ label: v, value: v })) : options[0]?.label && options[0]?.value ? options : options.map((v) => ({ label: v, value: v })),
38
35
  [options]
39
36
  );
40
37
  const [selectedValues, setSelectedValues] = useState(multiple ? value : [value]);
package/esm/System/CSR.js CHANGED
@@ -41,7 +41,7 @@ const CSRProvider = ({
41
41
  return { lang };
42
42
  },
43
43
  render: ({ lang }) => /* @__PURE__ */ jsxs(Fragment, { children: [
44
- /* @__PURE__ */ jsx(Client.Wrapper, { theme, children: /* @__PURE__ */ jsx(
44
+ /* @__PURE__ */ jsx(Client.Wrapper, { theme, children: /* @__PURE__ */ jsxs(
45
45
  CSRWrapper,
46
46
  {
47
47
  className,
@@ -51,7 +51,11 @@ const CSRProvider = ({
51
51
  fonts,
52
52
  prefix,
53
53
  layoutStyle,
54
- children
54
+ children: [
55
+ children,
56
+ /* @__PURE__ */ jsx(Client.Inner, {}),
57
+ /* @__PURE__ */ jsx(CSRInner, {})
58
+ ]
55
59
  }
56
60
  ) }),
57
61
  /* @__PURE__ */ jsx(
@@ -63,8 +67,6 @@ const CSRProvider = ({
63
67
  fetchMe,
64
68
  fetchSelf,
65
69
  render: ({ mePromise, selfPromise }) => /* @__PURE__ */ jsxs(Fragment, { children: [
66
- /* @__PURE__ */ jsx(Client.Inner, {}),
67
- /* @__PURE__ */ jsx(CSRInner, {}),
68
70
  /* @__PURE__ */ jsx(
69
71
  Client.Bridge,
70
72
  {
@@ -12,8 +12,8 @@ const ToggleSelect = ({
12
12
  disabled
13
13
  }) => {
14
14
  const { l } = usePage();
15
- const validateResult = value ? validate(value) : false;
16
- const invalidMessage = value === null || typeof value === "string" && !value.length || validateResult === true ? null : validateResult === false ? l("util.invalidValueError") : validateResult;
15
+ const validateResult = validate(value ?? "");
16
+ const invalidMessage = !value?.length || validateResult === true ? null : validateResult === false ? l("util.invalidValueError") : validateResult;
17
17
  const options = items.map(
18
18
  (item) => typeof item === "string" ? { label: item, value: item } : item
19
19
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/ui",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"