@choice-ui/react 2.0.0 → 2.0.2

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 (53) hide show
  1. package/dist/components/button/dist/index.d.ts +2 -9
  2. package/dist/components/button/dist/index.js +45 -19
  3. package/dist/components/checkbox/dist/index.d.ts +10 -1
  4. package/dist/components/checkbox/dist/index.js +49 -5
  5. package/dist/components/code-block/dist/index.d.ts +11 -14
  6. package/dist/components/code-block/dist/index.js +120 -93
  7. package/dist/components/colors/dist/index.d.ts +39 -6
  8. package/dist/components/colors/src/color-image-paint/color-image-paint.js +2 -2
  9. package/dist/components/dropdown/dist/index.d.ts +6 -0
  10. package/dist/components/dropdown/dist/index.js +20 -10
  11. package/dist/components/emoji-picker/dist/index.d.ts +30 -1
  12. package/dist/components/emoji-picker/dist/index.js +148 -44
  13. package/dist/components/form/src/adapters/range-adapter.js +2 -2
  14. package/dist/components/icon-button/dist/index.d.ts +1 -1
  15. package/dist/components/icon-button/dist/index.js +39 -0
  16. package/dist/components/list/dist/index.d.ts +1 -1
  17. package/dist/components/md-render/dist/index.d.ts +2 -1
  18. package/dist/components/md-render/dist/index.js +5 -9
  19. package/dist/components/md-render/src/components/markdown-block.d.ts +3 -0
  20. package/dist/components/md-render/src/md-render.js +4 -0
  21. package/dist/components/md-render/src/types.d.ts +3 -0
  22. package/dist/components/menus/dist/index.d.ts +5 -0
  23. package/dist/components/menus/dist/index.js +32 -3
  24. package/dist/components/modal/dist/index.js +2 -2
  25. package/dist/components/notifications/dist/index.d.ts +1 -5
  26. package/dist/components/numeric-input/dist/index.d.ts +27 -10
  27. package/dist/components/numeric-input/dist/index.js +132 -34
  28. package/dist/components/numeric-input/src/hooks/use-input-interactions.d.ts +3 -1
  29. package/dist/components/numeric-input/src/hooks/use-input-interactions.js +7 -3
  30. package/dist/components/numeric-input/src/hooks/use-numeric-input.js +15 -4
  31. package/dist/components/numeric-input/src/numeric-input.js +5 -4
  32. package/dist/components/numeric-input/src/utils/value-comparator.js +1 -5
  33. package/dist/components/panel/dist/index.d.ts +16 -16
  34. package/dist/components/picture-preview/dist/index.d.ts +5 -0
  35. package/dist/components/picture-preview/dist/index.js +287 -140
  36. package/dist/components/popover/dist/index.d.ts +5 -0
  37. package/dist/components/popover/dist/index.js +21 -2
  38. package/dist/components/radio/dist/index.d.ts +9 -1
  39. package/dist/components/radio/dist/index.js +50 -6
  40. package/dist/components/range/dist/index.d.ts +276 -20
  41. package/dist/components/range/dist/index.js +1030 -602
  42. package/dist/components/scroll-area/dist/index.d.ts +4 -27
  43. package/dist/components/scroll-area/dist/index.js +96 -123
  44. package/dist/components/separator/dist/index.d.ts +1 -8
  45. package/dist/components/splitter/dist/index.d.ts +1 -1
  46. package/dist/components/text-field/dist/index.d.ts +2 -3
  47. package/dist/components/text-field/dist/index.js +4 -19
  48. package/dist/components/textarea/dist/index.js +3 -1
  49. package/dist/components/toast/dist/index.d.ts +274 -0
  50. package/dist/components/tooltip/dist/index.d.ts +2 -0
  51. package/dist/components/tooltip/dist/index.js +23 -5
  52. package/dist/components/virtual-select/dist/index.d.ts +48 -0
  53. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { useRef } from "react";
2
2
  import { useEventCallback } from "usehooks-ts";
3
3
  import { dealWithNumericInputValue } from "../utils/numeric-value-processor.js";
4
- import { isExpressionInput, compareNumberResults } from "../utils/value-comparator.js";
4
+ import { compareNumberResults } from "../utils/value-comparator.js";
5
5
  function useInputInteractions({
6
6
  inputRef,
7
7
  displayValue,
@@ -12,6 +12,7 @@ function useInputInteractions({
12
12
  min,
13
13
  max,
14
14
  decimal,
15
+ defaultValue,
15
16
  disabled,
16
17
  readOnly,
17
18
  innerValue,
@@ -19,11 +20,14 @@ function useInputInteractions({
19
20
  updateValue,
20
21
  getCurrentStep,
21
22
  onChange,
23
+ onRawInputEditingChange,
22
24
  onEmpty,
23
25
  value
24
26
  }) {
25
27
  const initialValueRef = useRef("");
28
+ const outputShapeSource = value ?? defaultValue;
26
29
  const handleInputChange = useEventCallback((e) => {
30
+ onRawInputEditingChange == null ? void 0 : onRawInputEditingChange(true);
27
31
  setDisplayValue(e.target.value);
28
32
  });
29
33
  const handleInputFocus = useEventCallback((e) => {
@@ -32,6 +36,7 @@ function useInputInteractions({
32
36
  e.target.select();
33
37
  });
34
38
  const handleInputBlur = useEventCallback(() => {
39
+ onRawInputEditingChange == null ? void 0 : onRawInputEditingChange(false);
35
40
  setIsFocused(false);
36
41
  if (disabled || readOnly) return;
37
42
  try {
@@ -42,7 +47,6 @@ function useInputInteractions({
42
47
  min,
43
48
  decimal
44
49
  });
45
- const isExpressionInputValue = isExpressionInput(displayValue, valuePre);
46
50
  const isSameValue = compareNumberResults(innerValue, valuePre);
47
51
  if (isSameValue) {
48
52
  setDisplayValue(valuePre.string);
@@ -51,7 +55,7 @@ function useInputInteractions({
51
55
  }
52
56
  setValue(valuePre);
53
57
  onChange == null ? void 0 : onChange(
54
- typeof value === "string" ? valuePre.string : typeof value === "number" ? valuePre.array[0] : Array.isArray(value) ? valuePre.array : valuePre.object,
58
+ typeof outputShapeSource === "string" ? valuePre.string : typeof outputShapeSource === "number" ? valuePre.array[0] : Array.isArray(outputShapeSource) ? valuePre.array : valuePre.object,
55
59
  valuePre
56
60
  );
57
61
  setDisplayValue(valuePre.string);
@@ -30,6 +30,7 @@ function useNumericInput(props) {
30
30
  const dragHasChangedRef = useRef(false);
31
31
  const dragEndValueRef = useRef(void 0);
32
32
  const dragEndDetailRef = useRef(void 0);
33
+ const hasPendingRawInputRef = useRef(false);
33
34
  const [isFocused, setIsFocused] = useState(false);
34
35
  const [displayValue, setDisplayValue] = useState("");
35
36
  const { shiftPressed, metaPressed } = useModifierKeys(disabled);
@@ -47,13 +48,16 @@ function useNumericInput(props) {
47
48
  defaultValue: defaultValuePre,
48
49
  allowEmpty: true
49
50
  });
51
+ const outputShapeSource = value ?? defaultValue;
50
52
  const mapResultToOutputValue = useCallback(
51
- (result) => typeof value === "string" ? result.string : typeof value === "number" ? result.array[0] : Array.isArray(value) ? result.array : result.object,
52
- [value]
53
+ (result) => typeof outputShapeSource === "string" ? result.string : typeof outputShapeSource === "number" ? result.array[0] : Array.isArray(outputShapeSource) ? result.array : result.object,
54
+ [outputShapeSource]
53
55
  );
54
56
  useEffect(() => {
55
57
  if (!innerValue) {
56
- setDisplayValue("");
58
+ if (!hasPendingRawInputRef.current) {
59
+ setDisplayValue("");
60
+ }
57
61
  return;
58
62
  }
59
63
  const valuePre2 = dealWithNumericInputValue({
@@ -66,11 +70,14 @@ function useNumericInput(props) {
66
70
  if (JSON.stringify(valuePre2.object) !== JSON.stringify(innerValue.object)) {
67
71
  setValue(valuePre2);
68
72
  }
69
- setDisplayValue(valuePre2.string);
73
+ if (!hasPendingRawInputRef.current) {
74
+ setDisplayValue(valuePre2.string);
75
+ }
70
76
  }, [innerValue, expression, max, min, decimal, setValue]);
71
77
  const updateValue = useCallback(
72
78
  (updateFn, options) => {
73
79
  if (disabled || readOnly) return;
80
+ hasPendingRawInputRef.current = false;
74
81
  setValue((prev) => {
75
82
  if (!prev) {
76
83
  const initialValue = dealWithNumericInputValue({
@@ -134,6 +141,7 @@ function useNumericInput(props) {
134
141
  min,
135
142
  max,
136
143
  decimal,
144
+ defaultValue,
137
145
  disabled,
138
146
  readOnly,
139
147
  innerValue,
@@ -141,6 +149,9 @@ function useNumericInput(props) {
141
149
  updateValue,
142
150
  getCurrentStep,
143
151
  onChange,
152
+ onRawInputEditingChange: (editing) => {
153
+ hasPendingRawInputRef.current = editing;
154
+ },
144
155
  onEmpty,
145
156
  value
146
157
  });
@@ -67,6 +67,7 @@ const NumericInputBase = forwardRef((props, ref) => {
67
67
  });
68
68
  const { disableScrollProps } = useDisableScroll({ ref: inputRef });
69
69
  const [isFocused, setIsFocused] = useState(false);
70
+ const mergedFocused = focused || isFocused;
70
71
  const handleFocus = useEventCallback((e) => {
71
72
  var _a;
72
73
  onIsEditingChange == null ? void 0 : onIsEditingChange(true);
@@ -89,7 +90,7 @@ const NumericInputBase = forwardRef((props, ref) => {
89
90
  disabled,
90
91
  readOnly,
91
92
  selected,
92
- focused,
93
+ focused: mergedFocused,
93
94
  handlerPressed,
94
95
  // Configuration
95
96
  min,
@@ -116,7 +117,7 @@ const NumericInputBase = forwardRef((props, ref) => {
116
117
  disabled,
117
118
  readOnly,
118
119
  selected,
119
- focused,
120
+ mergedFocused,
120
121
  handlerPressed,
121
122
  min,
122
123
  max,
@@ -169,7 +170,7 @@ const NumericInputBase = forwardRef((props, ref) => {
169
170
  variant,
170
171
  size,
171
172
  selected: selected || handlerPressed,
172
- focused,
173
+ focused: mergedFocused,
173
174
  disabled,
174
175
  prefixElement: !!prefixNode,
175
176
  suffixElement: !!suffixNode,
@@ -212,7 +213,7 @@ const NumericInputBase = forwardRef((props, ref) => {
212
213
  variableNode && cloneElement(variableNode, { hasPrefixElement: !!prefixNode }),
213
214
  actionPromptNode && cloneElement(actionPromptNode),
214
215
  suffixNode && cloneElement(suffixNode, { position: "suffix" }),
215
- tooltip && !isFocused && /* @__PURE__ */ jsx(Tooltip, { ...tooltip, children: /* @__PURE__ */ jsx(
216
+ tooltip && !mergedFocused && /* @__PURE__ */ jsx(Tooltip, { ...tooltip, children: /* @__PURE__ */ jsx(
216
217
  "span",
217
218
  {
218
219
  tabIndex: -1,
@@ -21,12 +21,8 @@ function compareNumberResults(result1, result2) {
21
21
  const isSameObject = compareNumericObjects(result1.object, result2.object);
22
22
  return isSameArray || isSameObject;
23
23
  }
24
- function isExpressionInput(displayValue, processedValue) {
25
- return displayValue !== processedValue.string;
26
- }
27
24
  export {
28
25
  compareNumberResults,
29
26
  compareNumericArrays,
30
- compareNumericObjects,
31
- isExpressionInput
27
+ compareNumericObjects
32
28
  };
@@ -11,20 +11,20 @@ interface PanelRowProps extends Omit<HTMLProps<HTMLFieldSetElement>, "title"> {
11
11
  * @default "single"
12
12
  * @description
13
13
  * - `single`: `columns`: 1fr | `areas`: "label" "input" | `rows`: auto minmax(2rem, auto)
14
- * - `two-columns`: `columns`: 1fr 1fr | `areas`: "label label" "left right" | `rows`: auto minmax(2rem, auto)
14
+ * - `two-columns`: `columns`: 1fr 1fr | `areas`: "label-1 label-2" "input-1 input-2" | `rows`: auto minmax(2rem, auto)
15
15
  * - `one-label-one-input`: `columns`: 8fr 20fr | `areas`: "label input" | `rows`: 2rem
16
- * - `one-label-one-input-one-icon`: `columns`: 8fr 20fr 2rem | `areas`: "label input icon" | `rows`: 2rem
17
- * - `one-label-two-input`: `columns`: 8fr 1fr 1fr | `areas`: "label left right" | `rows`: 2rem
18
- * - `one-icon-one-input`: `columns`: 2rem 1fr | `areas`: "icon input" | `rows`: 2rem
19
- * - `one-input-one-icon`: `columns`: 1fr 2rem | `areas`: "input icon" | `rows`: 2rem
20
- * - `one-input-two-icon`: `columns`: 1fr 1fr 2rem | `areas`: "input left icon" "input right icon" | `rows`: 2rem
21
- * - `two-input-two-icon`: `columns`: 1fr 1fr 2rem | `areas`: "left icon right icon" | `rows`: 2rem
22
- * - `two-input-one-icon`: `columns`: 2rem 1fr 1fr | `areas`: "icon left right" | `rows`: 2rem
23
- * - `one-icon-one-input-two-icon`: `columns`: 2rem 1fr 2rem | `areas`: "icon input icon" | `rows`: 2rem
24
- * - `two-input-one-icon-double-row`: `columns`: 1fr 1fr 2rem | `areas`: "left icon right icon" | `rows`: 2rem 2rem
25
- * - `one-icon-one-input-two-icon-double-row`: `columns`: 2rem 1fr 2rem | `areas`: "icon input icon" | `rows`: 2rem 2rem
16
+ * - `one-label-one-input-one-icon`: `columns`: 8fr 20fr 1.5rem | `areas`: "label input icon" | `rows`: 2rem
17
+ * - `one-label-two-input`: `columns`: 8fr 10fr 10fr | `areas`: "label input-1 input-2" | `rows`: 2rem
18
+ * - `one-icon-one-input`: `columns`: 1.5rem 1fr | `areas`: ". label" "icon input" | `rows`: auto minmax(2rem, auto)
19
+ * - `one-input-one-icon`: `columns`: 1fr 1.5rem | `areas`: "label label" "input icon" | `rows`: auto minmax(2rem, auto)
20
+ * - `one-input-two-icon`: `columns`: 1fr 0.5rem 1.5rem 0.25rem 1.5rem | `areas`: "label . . . ." "input . icon-1 . icon-2" | `rows`: auto minmax(2rem, auto)
21
+ * - `two-input-two-icon`: `columns`: minmax(76px, 1fr) 0.5rem 1fr 0.5rem 1.5rem 0.25rem 1.5rem | `areas`: "label-1 label-1 label-2 label-2 . . ." "input-1 . input-2 . icon-1 . icon-2" | `rows`: auto minmax(2rem, auto)
22
+ * - `two-input-one-icon`: `columns`: 1fr 1fr 1.5rem | `areas`: "label-1 label-2 label-2" "input-1 input-2 icon" | `rows`: auto minmax(2rem, auto)
23
+ * - `one-icon-one-input-one-icon`: `columns`: 1.5rem 0.5rem 1fr 0.5rem 1.5rem | `areas`: "label label label label label" "icon-1 . input . icon-2" | `rows`: auto minmax(2rem, auto)
24
+ * - `one-icon-one-input-two-icon`: `columns`: 1.5rem 0.5rem 1fr 0.5rem 1.5rem 0.25rem 1.5rem | `areas`: "label label label label label label label" "icon-1 . input . icon-2 . icon-3" | `rows`: auto minmax(2rem, auto)
25
+ * - `two-input-one-icon-double-row`: `columns`: 1fr 1fr 1.5rem | `areas`: "label-1 label-2 ." "input-1 input-3 icon-1" "input-2 input-3 icon-2" | `rows`: auto 2rem 2rem
26
26
  */
27
- type?: "single" | "two-columns" | "one-label-one-input" | "one-label-one-input-one-icon" | "one-label-two-input" | "one-icon-one-input" | "one-input-one-icon" | "one-input-two-icon" | "two-input-two-icon" | "two-input-one-icon" | "one-icon-one-input-two-icon" | "two-input-one-icon-double-row";
27
+ type?: "single" | "two-columns" | "one-label-one-input" | "one-label-one-input-one-icon" | "one-label-two-input" | "one-icon-one-input" | "one-input-one-icon" | "one-input-two-icon" | "two-input-two-icon" | "two-input-one-icon" | "one-icon-one-input-one-icon" | "one-icon-one-input-two-icon" | "two-input-one-icon-double-row";
28
28
  }
29
29
  declare const PanelRow: react.ForwardRefExoticComponent<Omit<PanelRowProps, "ref"> & react.RefAttributes<HTMLFieldSetElement>>;
30
30
 
@@ -83,8 +83,8 @@ declare const SortablePaneContext: react__default.Context<SortablePaneContextVal
83
83
  declare const useSortablePane: () => SortablePaneContextValue;
84
84
 
85
85
  interface PanelSortableProps<T extends SortableItem> {
86
- children: react__default.ReactNode;
87
86
  className?: string;
87
+ children: react__default.ReactNode;
88
88
  data: T[];
89
89
  onDrop: (position: "top" | "bottom" | null, id: string, newIndex: number) => void;
90
90
  onSelectedIdChange: (id: string | null) => void;
@@ -129,12 +129,12 @@ interface PanelProps extends Omit<HTMLProps<HTMLDivElement>, "title"> {
129
129
  showLabels?: boolean;
130
130
  triggerRef?: React.RefObject<HTMLDivElement>;
131
131
  }
132
- declare const PanelContent: ({ children, collapsible, title, otherChildren, }: {
132
+ declare const PanelContent: react.NamedExoticComponent<{
133
133
  children: React.ReactNode;
134
134
  collapsible?: boolean;
135
135
  otherChildren: React.ReactNode[];
136
136
  title: React.ReactNode;
137
- }) => react_jsx_runtime.JSX.Element;
137
+ }>;
138
138
  interface PanelComponentProps extends React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<HTMLDivElement>> {
139
139
  Content: typeof PanelContent;
140
140
  Label: typeof PanelLabel;
@@ -149,4 +149,4 @@ interface PanelComponentProps extends React.ForwardRefExoticComponent<PanelProps
149
149
  declare const PanelBase: react.ForwardRefExoticComponent<Omit<PanelProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
150
150
  declare const Panel: PanelComponentProps;
151
151
 
152
- export { Panel, PanelBase, PanelContext, PanelLabel, PanelPreviewer, PanelRow, PanelRowLabel, PanelRowManyIcon, type PanelRowManyIconItem, type PanelRowManyIconProps, type PanelRowProps, PanelSortable, PanelSortableRow, PanelTitle, type SortableItem, SortablePaneContext, type SortablePaneContextValue, SortableRowDataContext, type SortableRowDataContextValue, usePanelContext, useSortablePane, useSortableRowItem };
152
+ export { Panel, PanelBase, PanelContext, type PanelContextType, PanelLabel, PanelPreviewer, PanelRow, PanelRowLabel, PanelRowManyIcon, type PanelRowManyIconItem, type PanelRowManyIconProps, type PanelRowProps, PanelSortable, PanelSortableRow, PanelTitle, type SortableItem, SortablePaneContext, type SortablePaneContextValue, SortableRowDataContext, type SortableRowDataContextValue, usePanelContext, useSortablePane, useSortableRowItem };
@@ -14,6 +14,11 @@ interface PicturePreviewProps extends HTMLProps<HTMLDivElement> {
14
14
  fileName?: string;
15
15
  onClose?: () => void;
16
16
  src: string;
17
+ control?: {
18
+ enable?: boolean;
19
+ position?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
20
+ show?: "always" | "hover";
21
+ };
17
22
  }
18
23
  declare const PicturePreview: react.ForwardRefExoticComponent<Omit<PicturePreviewProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
19
24