onekijs-ui 1.0.4 → 1.0.6

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 (39) hide show
  1. package/dist/components/datetime/FormDatePicker.d.ts +28 -0
  2. package/dist/components/datetime/FormDateRangePicker.d.ts +28 -0
  3. package/dist/components/datetime/FormDateTimePicker.d.ts +21 -0
  4. package/dist/components/datetime/FormDateTimeRangePicker.d.ts +21 -0
  5. package/dist/components/datetime/hooks/useDateAdapter.d.ts +4 -0
  6. package/dist/components/datetime/hooks/useDateRangeAdapter.d.ts +5 -0
  7. package/dist/components/datetime/hooks/useTimestampAdapter.d.ts +8 -0
  8. package/dist/components/datetime/hooks/useTimestampRangeAdapter.d.ts +17 -2
  9. package/dist/components/datetime/index.d.ts +8 -8
  10. package/dist/components/datetime/typings.d.ts +55 -9
  11. package/dist/components/select/SelectService.d.ts +3 -3
  12. package/dist/components/wizard/WizardModal.d.ts +2 -2
  13. package/dist/components/wizard/index.d.ts +2 -2
  14. package/dist/index.d.ts +73 -70
  15. package/dist/index.js +2290 -2102
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.module.js +2284 -2104
  18. package/dist/index.module.js.map +1 -1
  19. package/package.json +3 -3
  20. package/src/components/button/components/DropdownButtonComponent.tsx +6 -3
  21. package/src/components/datetime/FormDatePicker.tsx +79 -0
  22. package/src/components/datetime/FormDateRangePicker.tsx +79 -0
  23. package/src/components/datetime/FormDateTimePicker.tsx +43 -0
  24. package/src/components/datetime/FormDateTimeRangePicker.tsx +38 -0
  25. package/src/components/datetime/components/DatePickerComponent.tsx +8 -4
  26. package/src/components/datetime/components/DateRangePickerComponent.tsx +8 -4
  27. package/src/components/datetime/components/DateTimePickerComponent.tsx +8 -4
  28. package/src/components/datetime/components/DateTimeRangePickerComponent.tsx +8 -4
  29. package/src/components/datetime/components/TimeComponent.tsx +3 -0
  30. package/src/components/datetime/components/TimeRangeComponent.tsx +4 -2
  31. package/src/components/datetime/components/TimeSelectorComponent.tsx +5 -4
  32. package/src/components/datetime/components/TimeSelectorPartComponent.tsx +16 -1
  33. package/src/components/datetime/hooks/useDateAdapter.ts +14 -0
  34. package/src/components/datetime/hooks/useDateRangeAdapter.ts +11 -11
  35. package/src/components/datetime/hooks/useTimestampAdapter.ts +37 -0
  36. package/src/components/datetime/hooks/useTimestampRangeAdapter.ts +15 -26
  37. package/src/components/datetime/style.ts +14 -3
  38. package/src/components/datetime/typings.ts +66 -10
  39. package/src/index.ts +96 -130
package/dist/index.js CHANGED
@@ -1692,8 +1692,9 @@ const DropdownButtonComponent = ({ animationTimeout = 100, attachDropdownToBody
1692
1692
  const classNames = addClassname('o-button-dropdown', className);
1693
1693
  const ref = React.useRef(null);
1694
1694
  const [Dropdown, triggerRef] = useDropdown();
1695
- useClickOutside(ref, () => onCollapse && onCollapse());
1696
- return (jsxRuntimeExports.jsxs("span", { ref: ref, children: [jsxRuntimeExports.jsxs(Button, { ...buttonProps, className: classNames, onClick: onClick ? undefined : open ? onCollapse : onDrop, ref: triggerRef, children: [jsxRuntimeExports.jsx("span", { className: "o-button-dropdown-content", onClick: onClick, children: children }), jsxRuntimeExports.jsx("span", { className: "o-button-dropdown-icon", children: jsxRuntimeExports.jsx(TogglerIcon, { width: "16px", height: "16px", open: open, closeArrowPosition: "s", openArrowPosition: "n", onClick: onClick ? (open ? onCollapse : onDrop) : undefined }) })] }), jsxRuntimeExports.jsx(Dropdown, { attachToBody: attachDropdownToBody, skidding: skidding, distance: distance, onUpdate: onUpdate, onDropStart: onDropStart, onDropping: onDropping, onDropDone: onDropDone, onCollapseStart: onCollapseStart, onCollapseDone: onCollapseDone, onCollapsing: onCollapsing, widthModifier: widthModifier, zIndex: zIndex, open: open, placement: placement, animationTimeout: animationTimeout, children: listElement })] }));
1695
+ const dropdownRef = React.useRef(null);
1696
+ useClickOutside([ref, dropdownRef], () => onCollapse && onCollapse());
1697
+ return (jsxRuntimeExports.jsxs("span", { ref: ref, children: [jsxRuntimeExports.jsxs(Button, { ...buttonProps, className: classNames, onClick: onClick ? undefined : open ? onCollapse : onDrop, ref: triggerRef, children: [jsxRuntimeExports.jsx("span", { className: "o-button-dropdown-content", onClick: onClick, children: children }), jsxRuntimeExports.jsx("span", { className: "o-button-dropdown-icon", children: jsxRuntimeExports.jsx(TogglerIcon, { width: "16px", height: "16px", open: open, closeArrowPosition: "s", openArrowPosition: "n", onClick: onClick ? (open ? onCollapse : onDrop) : undefined }) })] }), jsxRuntimeExports.jsx(Dropdown, { attachToBody: attachDropdownToBody, skidding: skidding, distance: distance, onUpdate: onUpdate, onDropStart: onDropStart, onDropping: onDropping, onDropDone: onDropDone, onCollapseStart: onCollapseStart, onCollapseDone: onCollapseDone, onCollapsing: onCollapsing, widthModifier: widthModifier, zIndex: zIndex, open: open, placement: placement, animationTimeout: animationTimeout, children: jsxRuntimeExports.jsx("div", { ref: dropdownRef, children: listElement }) })] }));
1697
1698
  };
1698
1699
 
1699
1700
  const DropdownButton = styled(DropdownButtonComponent) `
@@ -2096,25 +2097,6 @@ const Card = styled(CardComponent) `
2096
2097
  ${cardStyle}
2097
2098
  `;
2098
2099
 
2099
- const titlelize = (value) => {
2100
- return value
2101
- .split('_')
2102
- .map((v) => onekijsFramework.ucfirst(v))
2103
- .join(' ');
2104
- };
2105
-
2106
- const FormCardDisplayerComponent = (displayerProps) => {
2107
- const total = Object.values(displayerProps.children ?? {}).length;
2108
- return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-displayer-card', displayerProps.className), children: [jsxRuntimeExports.jsx("div", { className: "o-displayer-card-title", children: displayerProps.name }), Object.values(displayerProps.children ?? {}).map((field, index) => {
2109
- const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
2110
- return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format }));
2111
- })] }));
2112
- };
2113
-
2114
- const FormCardDisplayer = styled(FormCardDisplayerComponent) `
2115
- ${formCardDisplayerStyle}
2116
- `;
2117
-
2118
2100
  const getIconDivProps = (props) => {
2119
2101
  const { color, marginRight, marginLeft, ...result } = props;
2120
2102
  return result;
@@ -2308,15 +2290,25 @@ const Alert = styled(AlertComponent) `
2308
2290
  ${alertStyle}
2309
2291
  `;
2310
2292
 
2311
- const FormCard = ({ name, help, children, visible, disabled, ...cardProps }) => {
2293
+ const FormBlockDisplayerComponent = (displayerProps) => {
2294
+ const total = Object.values(displayerProps.children ?? {}).length;
2295
+ return (jsxRuntimeExports.jsx("div", { className: addClassname('o-displayer-block', displayerProps.className), children: Object.values(displayerProps.children ?? {}).map((field, index) => {
2296
+ const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
2297
+ return React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format });
2298
+ }) }));
2299
+ };
2300
+
2301
+ const FormBlockDisplayer = styled(FormBlockDisplayerComponent) `
2302
+ `;
2303
+
2304
+ const FormBlock = ({ name, help, children, visible, disabled, className }) => {
2312
2305
  const decorator = onekijsFramework.useFormDecorator(name, {
2313
2306
  Displayer: (displayerProps) => {
2314
- return (jsxRuntimeExports.jsx(FormCardDisplayer, { ...displayerProps, name: typeof cardProps.title === 'string' ? cardProps.title : titlelize(name) }));
2307
+ return jsxRuntimeExports.jsx(FormBlockDisplayer, { ...displayerProps });
2315
2308
  },
2316
2309
  visible,
2317
2310
  disabled,
2318
2311
  });
2319
- const form = onekijsFramework.useForm();
2320
2312
  const metadata = onekijsFramework.useFormMetadata(decorator.name);
2321
2313
  const fieldContainer = onekijsFramework.useFieldContainer({
2322
2314
  container: name,
@@ -2358,28 +2350,37 @@ const FormCard = ({ name, help, children, visible, disabled, ...cardProps }) =>
2358
2350
  if (metadata.visible === false) {
2359
2351
  return null;
2360
2352
  }
2361
- return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Card, { ...cardProps, open: !metadata.disabled, onToggle: () => (metadata.disabled ? form.enable(decorator.name) : form.disable(decorator.name)), children: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [help && (jsxRuntimeExports.jsx(Alert, { kind: "info", size: "small", marginBottom: "2xl", children: help })), children] }) }) }));
2353
+ return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsxs("div", { className: addClassname('o-form-block', className), children: [help && (jsxRuntimeExports.jsx(Alert, { kind: "info", size: "small", marginBottom: "2xl", children: help })), children] }) }));
2362
2354
  };
2363
2355
 
2364
- const FormBlockDisplayerComponent = (displayerProps) => {
2356
+ const titlelize = (value) => {
2357
+ return value
2358
+ .split('_')
2359
+ .map((v) => onekijsFramework.ucfirst(v))
2360
+ .join(' ');
2361
+ };
2362
+
2363
+ const FormCardDisplayerComponent = (displayerProps) => {
2365
2364
  const total = Object.values(displayerProps.children ?? {}).length;
2366
- return (jsxRuntimeExports.jsx("div", { className: addClassname('o-displayer-block', displayerProps.className), children: Object.values(displayerProps.children ?? {}).map((field, index) => {
2367
- const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
2368
- return React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format });
2369
- }) }));
2365
+ return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-displayer-card', displayerProps.className), children: [jsxRuntimeExports.jsx("div", { className: "o-displayer-card-title", children: displayerProps.name }), Object.values(displayerProps.children ?? {}).map((field, index) => {
2366
+ const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
2367
+ return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format }));
2368
+ })] }));
2370
2369
  };
2371
2370
 
2372
- const FormBlockDisplayer = styled(FormBlockDisplayerComponent) `
2371
+ const FormCardDisplayer = styled(FormCardDisplayerComponent) `
2372
+ ${formCardDisplayerStyle}
2373
2373
  `;
2374
2374
 
2375
- const FormBlock = ({ name, help, children, visible, disabled, className }) => {
2375
+ const FormCard = ({ name, help, children, visible, disabled, ...cardProps }) => {
2376
2376
  const decorator = onekijsFramework.useFormDecorator(name, {
2377
2377
  Displayer: (displayerProps) => {
2378
- return jsxRuntimeExports.jsx(FormBlockDisplayer, { ...displayerProps });
2378
+ return (jsxRuntimeExports.jsx(FormCardDisplayer, { ...displayerProps, name: typeof cardProps.title === 'string' ? cardProps.title : titlelize(name) }));
2379
2379
  },
2380
2380
  visible,
2381
2381
  disabled,
2382
2382
  });
2383
+ const form = onekijsFramework.useForm();
2383
2384
  const metadata = onekijsFramework.useFormMetadata(decorator.name);
2384
2385
  const fieldContainer = onekijsFramework.useFieldContainer({
2385
2386
  container: name,
@@ -2421,7 +2422,7 @@ const FormBlock = ({ name, help, children, visible, disabled, className }) => {
2421
2422
  if (metadata.visible === false) {
2422
2423
  return null;
2423
2424
  }
2424
- return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsxs("div", { className: addClassname('o-form-block', className), children: [help && (jsxRuntimeExports.jsx(Alert, { kind: "info", size: "small", marginBottom: "2xl", children: help })), children] }) }));
2425
+ return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Card, { ...cardProps, open: !metadata.disabled, onToggle: () => (metadata.disabled ? form.enable(decorator.name) : form.disable(decorator.name)), children: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [help && (jsxRuntimeExports.jsx(Alert, { kind: "info", size: "small", marginBottom: "2xl", children: help })), children] }) }) }));
2425
2426
  };
2426
2427
 
2427
2428
  const CheckboxComponent = ({ label, className = '', onChange, value = false, bordered = true, status, ...checkboxProps }) => {
@@ -3048,6 +3049,76 @@ const FormCheckbox = React.memo((props) => {
3048
3049
  });
3049
3050
  FormCheckbox.displayName = 'FormCheckbox';
3050
3051
 
3052
+ const contextMenuStyle = () => {
3053
+ return styled.css `
3054
+ ${preflight()}
3055
+ ${zIndex(9999)}
3056
+ `;
3057
+ };
3058
+
3059
+ const ContextMenuComponent = ({ refElement, className, children, offsetX = 0, offsetY = 0 }) => {
3060
+ const [visible, setVisible] = React.useState(false);
3061
+ const { floatingStyles, refs } = react.useFloating({
3062
+ placement: 'bottom-start',
3063
+ middleware: [react.offset({ crossAxis: offsetX, mainAxis: offsetY }), react.flip(), react.shift()],
3064
+ whileElementsMounted: react.autoUpdate,
3065
+ });
3066
+ // Handle the right-click event
3067
+ const handleContextMenu = React.useCallback((e) => {
3068
+ e.preventDefault(); // Prevent the browser's default context menu
3069
+ const x = e.clientX;
3070
+ const y = e.clientY;
3071
+ // Define a VirtualElement object that implements getBoundingClientRect
3072
+ const newVirtualElement = {
3073
+ getBoundingClientRect: () => ({
3074
+ width: 0,
3075
+ height: 0,
3076
+ top: y,
3077
+ right: x,
3078
+ bottom: y,
3079
+ left: x,
3080
+ x: x,
3081
+ y: y,
3082
+ toJSON: () => { },
3083
+ }),
3084
+ };
3085
+ refs.setPositionReference(newVirtualElement);
3086
+ setVisible(true);
3087
+ }, []);
3088
+ // Close the menu on left click or scroll
3089
+ React.useEffect(() => {
3090
+ const closeMenu = () => setVisible(false);
3091
+ window.addEventListener('click', closeMenu);
3092
+ window.addEventListener('scroll', closeMenu);
3093
+ if (refElement instanceof HTMLElement) {
3094
+ refElement.addEventListener('contextmenu', handleContextMenu);
3095
+ }
3096
+ else if (refElement.current !== null) {
3097
+ refElement.current.addEventListener('contextmenu', handleContextMenu);
3098
+ }
3099
+ return () => {
3100
+ window.removeEventListener('click', closeMenu);
3101
+ window.removeEventListener('scroll', closeMenu);
3102
+ if (refElement instanceof HTMLElement) {
3103
+ refElement.removeEventListener('contextmenu', handleContextMenu);
3104
+ }
3105
+ else if (refElement.current !== null) {
3106
+ refElement.current.removeEventListener('contextmenu', handleContextMenu);
3107
+ }
3108
+ };
3109
+ }, []);
3110
+ if (visible) {
3111
+ return (jsxRuntimeExports.jsx("div", { ref: refs.setFloating, className: addClassname('o-context-menu', className), style: {
3112
+ ...floatingStyles,
3113
+ }, children: children }));
3114
+ }
3115
+ return null;
3116
+ };
3117
+
3118
+ const ContextMenu = styled(ContextMenuComponent) `
3119
+ ${contextMenuStyle}
3120
+ `;
3121
+
3051
3122
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3052
3123
  const DashboardServiceContext = React.createContext(null);
3053
3124
  const useDashboardService = () => {
@@ -4620,24 +4691,6 @@ const useDashboardController = () => {
4620
4691
  return service;
4621
4692
  };
4622
4693
 
4623
- const RefreshIconComponent = (props) => {
4624
- return (jsxRuntimeExports.jsx("div", { ...getIconDivProps(props), children: jsxRuntimeExports.jsx("svg", { className: "o-icon-refresh-svg", stroke: "currentColor", fill: "none", strokeWidth: "2", viewBox: "0 0 24 24", "aria-hidden": "true", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" }) }) }));
4625
- };
4626
- var RefreshIcon = styled(RefreshIconComponent) `
4627
- ${({ width = '16px', height = '16px', color: cssColor = 'inherit', marginLeft: ml = '0', marginRight: mr = '0', }) => styled.css `
4628
- width: ${width};
4629
- height: ${height};
4630
- ${marginLeft(ml)}
4631
- ${marginRight(mr)}
4632
- ${display('flex')};
4633
- ${alignItems('center')};
4634
- ${color(cssColor)}
4635
- .o-icon-refresh-svg {
4636
- display: inline-block;
4637
- }
4638
- `}
4639
- `;
4640
-
4641
4694
  const useDashboardHorizontalPanel = (area) => {
4642
4695
  const state = React.useContext(DashboardStateContext);
4643
4696
  return area === 'header' ? state.header : state.footer;
@@ -4651,76 +4704,6 @@ const useDashoardBodyPanel = () => {
4651
4704
  return state.body;
4652
4705
  };
4653
4706
 
4654
- const contextMenuStyle = () => {
4655
- return styled.css `
4656
- ${preflight()}
4657
- ${zIndex(9999)}
4658
- `;
4659
- };
4660
-
4661
- const ContextMenuComponent = ({ refElement, className, children, offsetX = 0, offsetY = 0 }) => {
4662
- const [visible, setVisible] = React.useState(false);
4663
- const { floatingStyles, refs } = react.useFloating({
4664
- placement: 'bottom-start',
4665
- middleware: [react.offset({ crossAxis: offsetX, mainAxis: offsetY }), react.flip(), react.shift()],
4666
- whileElementsMounted: react.autoUpdate,
4667
- });
4668
- // Handle the right-click event
4669
- const handleContextMenu = React.useCallback((e) => {
4670
- e.preventDefault(); // Prevent the browser's default context menu
4671
- const x = e.clientX;
4672
- const y = e.clientY;
4673
- // Define a VirtualElement object that implements getBoundingClientRect
4674
- const newVirtualElement = {
4675
- getBoundingClientRect: () => ({
4676
- width: 0,
4677
- height: 0,
4678
- top: y,
4679
- right: x,
4680
- bottom: y,
4681
- left: x,
4682
- x: x,
4683
- y: y,
4684
- toJSON: () => { },
4685
- }),
4686
- };
4687
- refs.setPositionReference(newVirtualElement);
4688
- setVisible(true);
4689
- }, []);
4690
- // Close the menu on left click or scroll
4691
- React.useEffect(() => {
4692
- const closeMenu = () => setVisible(false);
4693
- window.addEventListener('click', closeMenu);
4694
- window.addEventListener('scroll', closeMenu);
4695
- if (refElement instanceof HTMLElement) {
4696
- refElement.addEventListener('contextmenu', handleContextMenu);
4697
- }
4698
- else if (refElement.current !== null) {
4699
- refElement.current.addEventListener('contextmenu', handleContextMenu);
4700
- }
4701
- return () => {
4702
- window.removeEventListener('click', closeMenu);
4703
- window.removeEventListener('scroll', closeMenu);
4704
- if (refElement instanceof HTMLElement) {
4705
- refElement.removeEventListener('contextmenu', handleContextMenu);
4706
- }
4707
- else if (refElement.current !== null) {
4708
- refElement.current.removeEventListener('contextmenu', handleContextMenu);
4709
- }
4710
- };
4711
- }, []);
4712
- if (visible) {
4713
- return (jsxRuntimeExports.jsx("div", { ref: refs.setFloating, className: addClassname('o-context-menu', className), style: {
4714
- ...floatingStyles,
4715
- }, children: children }));
4716
- }
4717
- return null;
4718
- };
4719
-
4720
- const ContextMenu = styled(ContextMenuComponent) `
4721
- ${contextMenuStyle}
4722
- `;
4723
-
4724
4707
  const IconComponent$8 = ({ className, onClick }) => {
4725
4708
  return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsxs("svg", { className: "o-icon-close-all-svg", viewBox: "0 0 16 16", xmlns: "http://www.w3.org/2000/svg", children: [jsxRuntimeExports.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M8.621 8.086l-.707-.707L6.5 8.793 5.086 7.379l-.707.707L5.793 9.5l-1.414 1.414.707.707L6.5 10.207l1.414 1.414.707-.707L7.207 9.5l1.414-1.414z" }), jsxRuntimeExports.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M5 3l1-1h7l1 1v7l-1 1h-2v2l-1 1H3l-1-1V6l1-1h2V3zm1 2h4l1 1v4h2V3H6v2zm4 1H3v7h7V6z" })] }) }));
4726
4709
  };
@@ -4797,6 +4780,24 @@ var FolderIcon = styled(IconComponent$5) `
4797
4780
  `}
4798
4781
  `;
4799
4782
 
4783
+ const RefreshIconComponent = (props) => {
4784
+ return (jsxRuntimeExports.jsx("div", { ...getIconDivProps(props), children: jsxRuntimeExports.jsx("svg", { className: "o-icon-refresh-svg", stroke: "currentColor", fill: "none", strokeWidth: "2", viewBox: "0 0 24 24", "aria-hidden": "true", xmlns: "http://www.w3.org/2000/svg", children: jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" }) }) }));
4785
+ };
4786
+ var RefreshIcon = styled(RefreshIconComponent) `
4787
+ ${({ width = '16px', height = '16px', color: cssColor = 'inherit', marginLeft: ml = '0', marginRight: mr = '0', }) => styled.css `
4788
+ width: ${width};
4789
+ height: ${height};
4790
+ ${marginLeft(ml)}
4791
+ ${marginRight(mr)}
4792
+ ${display('flex')};
4793
+ ${alignItems('center')};
4794
+ ${color(cssColor)}
4795
+ .o-icon-refresh-svg {
4796
+ display: inline-block;
4797
+ }
4798
+ `}
4799
+ `;
4800
+
4800
4801
  const IconComponent$4 = ({ className, onClick }) => {
4801
4802
  return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsx("svg", { className: "o-icon-search-svg", viewBox: "0 0 118.783 118.783", children: jsxRuntimeExports.jsx("path", { d: "M115.97,101.597L88.661,74.286c4.64-7.387,7.333-16.118,7.333-25.488c0-26.509-21.49-47.996-47.998-47.996\n\t\tS0,22.289,0,48.798c0,26.51,21.487,47.995,47.996,47.995c10.197,0,19.642-3.188,27.414-8.605l26.984,26.986\n\t\tc1.875,1.873,4.333,2.806,6.788,2.806c2.458,0,4.913-0.933,6.791-2.806C119.72,111.423,119.72,105.347,115.97,101.597z\n\t\t M47.996,81.243c-17.917,0-32.443-14.525-32.443-32.443s14.526-32.444,32.443-32.444c17.918,0,32.443,14.526,32.443,32.444\n\t\tS65.914,81.243,47.996,81.243z" }) }) }));
4802
4803
  };
@@ -8356,16 +8357,6 @@ const FormAutoComplete = (props) => {
8356
8357
  return (jsxRuntimeExports.jsx(FormSelect$1, { NotFoundComponent: null, IconComponent: null, autoCompleteAdapter: adapter, openOnFocus: true, ...props, mode: "autocomplete", autoCompleteSearch: false, validateValue: false, searchable: true, clickable: false }));
8357
8358
  };
8358
8359
 
8359
- class DefaultSelectBroker extends onekijsFramework.DefaultCollectionBroker {
8360
- defaultValue;
8361
- setDefaultValue(defaultValue, subscriberId) {
8362
- if (subscriberId === undefined) {
8363
- this.defaultValue = defaultValue;
8364
- }
8365
- this._getSubscribers(subscriberId).forEach((s) => s.setDefaultValue(defaultValue));
8366
- }
8367
- }
8368
-
8369
8360
  const useTreeInitialState = (dataSource, options) => {
8370
8361
  return onekijsFramework.useCollectionInitialState(dataSource, options);
8371
8362
  };
@@ -9500,11 +9491,21 @@ const TreeSelectComponent = (props) => {
9500
9491
  TreeSelectComponent.displayName = 'TreeSelectComponent';
9501
9492
  var TreeSelectComponent$1 = React.memo(TreeSelectComponent);
9502
9493
 
9503
- const TreeSelect = styled(TreeSelectComponent$1) `
9504
- ${selectStyle}
9505
- `;
9506
-
9507
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9494
+ class DefaultSelectBroker extends onekijsFramework.DefaultCollectionBroker {
9495
+ defaultValue;
9496
+ setDefaultValue(defaultValue, subscriberId) {
9497
+ if (subscriberId === undefined) {
9498
+ this.defaultValue = defaultValue;
9499
+ }
9500
+ this._getSubscribers(subscriberId).forEach((s) => s.setDefaultValue(defaultValue));
9501
+ }
9502
+ }
9503
+
9504
+ const TreeSelect = styled(TreeSelectComponent$1) `
9505
+ ${selectStyle}
9506
+ `;
9507
+
9508
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9508
9509
  const TabsServiceContext = React.createContext(null);
9509
9510
  const useTabsService = () => {
9510
9511
  return React.useContext(TabsServiceContext);
@@ -11067,221 +11068,6 @@ const useFormTableContext = () => {
11067
11068
  return React.useContext(DefaultFormTableContext);
11068
11069
  };
11069
11070
 
11070
- const DefaultDeleteRowComponent = ({ rowIndex }) => {
11071
- const form = onekijsFramework.useForm();
11072
- const { tableName, onRemove } = useFormTableContext();
11073
- const removeRow = () => {
11074
- const row = form.getValue(`${tableName}.${rowIndex}`);
11075
- if (onRemove) {
11076
- onRemove(form, row, rowIndex);
11077
- }
11078
- else {
11079
- form.remove(tableName, rowIndex);
11080
- }
11081
- };
11082
- const metadata = onekijsFramework.useFormMetadata(tableName);
11083
- let disabled = false;
11084
- if (metadata.disabled || metadata.readOnly || (metadata.editable === false && form.config.reconfigure)) {
11085
- disabled = true;
11086
- }
11087
- return (jsxRuntimeExports.jsx("div", { className: `o-form-table-remove${disabled ? ' o-form-table-remove-disabled' : ''}`, onClick: removeRow, children: jsxRuntimeExports.jsx(RemoveIcon$1, { width: "14px", height: "14px" }) }));
11088
- };
11089
- const DefaultSelectRowComponent = ({ item }) => {
11090
- const { onSelect } = useFormTableContext();
11091
- const selected = item?.selected;
11092
- const toggle = (selected) => onSelect(item, selected);
11093
- return jsxRuntimeExports.jsx(Checkbox, { value: selected || false, onChange: toggle });
11094
- };
11095
- const FooterComponent = () => {
11096
- const form = onekijsFramework.useForm();
11097
- const { tableName, addLabel, maxLength, onAdd } = useFormTableContext();
11098
- const isSingleColumnTable = useTableColumns().find((c) => c.id === '');
11099
- const addRow = (e) => {
11100
- e.preventDefault();
11101
- onAdd(isSingleColumnTable ? undefined : {});
11102
- };
11103
- const currentSize = (form.getValue(tableName) || []).length;
11104
- if (maxLength !== undefined && currentSize >= maxLength)
11105
- return null;
11106
- return (jsxRuntimeExports.jsxs("div", { className: "o-form-table-add", onClick: addRow, children: [jsxRuntimeExports.jsx(TogglerIcon, { open: false, model: "plus", color: "currentColor" }), jsxRuntimeExports.jsx("span", { children: addLabel })] }));
11107
- };
11108
- const CheckAllComponent = () => {
11109
- const form = onekijsFramework.useForm();
11110
- const { tableName } = useFormTableContext();
11111
- const fieldValue = onekijsFramework.useValue(tableName);
11112
- const tableService = useTableService();
11113
- const isAllChecked = Array.isArray(fieldValue) && Array.isArray(fieldValue) && fieldValue.length > 0;
11114
- const toggle = (selected) => {
11115
- if (selected) {
11116
- const items = tableService.items.map((item) => item?.data).filter((data) => data !== undefined);
11117
- form.setValue(tableName, items);
11118
- }
11119
- else {
11120
- form.setValue(tableName, []);
11121
- }
11122
- };
11123
- return jsxRuntimeExports.jsx(Checkbox, { className: "o-form-table-check-all", value: isAllChecked, onChange: toggle });
11124
- };
11125
- const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, onAdd, onChange, onRemove, className, name, format = 'auto', required, minLength, maxLength, showAddButton = true, DeleteRowComponent = DefaultDeleteRowComponent, SelectRowComponent = DefaultSelectRowComponent, ...props }) => {
11126
- const form = onekijsFramework.useForm();
11127
- const field = form.fields[name];
11128
- if (field) {
11129
- const validators = field.validators;
11130
- const minlengthValidator = (validators.minLength || validators.min);
11131
- if (minlengthValidator) {
11132
- minLength = minlengthValidator.length;
11133
- }
11134
- const maxlengthValidator = (validators.maxLength || validators.max);
11135
- if (maxlengthValidator) {
11136
- maxLength = maxlengthValidator.length;
11137
- }
11138
- }
11139
- const id = React.useId();
11140
- const tableService = controller.asService();
11141
- const formatRef = onekijsFramework.useLazyRef(() => {
11142
- if (format === 'auto') {
11143
- return value && value.length > 0 && typeof value[0] !== 'object' ? 'id' : 'object';
11144
- }
11145
- return format;
11146
- });
11147
- const [mounted, setMounted] = React.useState(false);
11148
- const formTableContext = onekijsFramework.useLazyRef(() => {
11149
- const onSelect = (item, selected) => {
11150
- const getId = (v) => {
11151
- return formatRef.current === 'id' ? v : v.id;
11152
- };
11153
- const currentValues = form.getValue(name, []);
11154
- const value = formatRef.current === 'id' ? item.id : item.data;
11155
- if (selected) {
11156
- onChange && onChange([value].concat(currentValues));
11157
- }
11158
- else {
11159
- onChange && onChange(currentValues.filter((v) => getId(v) !== getId(value)));
11160
- }
11161
- };
11162
- if (!onAdd) {
11163
- onAdd = (initialValue) => {
11164
- formTableContext.current.editable = true;
11165
- form.add(name, initialValue);
11166
- };
11167
- }
11168
- return { tableName: name, onSelect, onAdd, onRemove, addLabel, required, minLength, maxLength };
11169
- });
11170
- // listen on value change from the form
11171
- // for the initial value in the table controller
11172
- // delay the rendering of the table until the value has been set in the controller
11173
- React.useEffect(() => {
11174
- const watch = [name];
11175
- const listener = (value) => {
11176
- if (tableService.dataSource) {
11177
- tableService.setSelected('value', value || []);
11178
- }
11179
- else if (value !== undefined) {
11180
- tableService.setData(value);
11181
- }
11182
- };
11183
- form.onValueChange(id, listener, watch);
11184
- listener(value);
11185
- setMounted(true);
11186
- return () => {
11187
- form.offValueChange(id);
11188
- };
11189
- // eslint-disable-next-line react-hooks/exhaustive-deps
11190
- }, []);
11191
- React.useEffect(() => {
11192
- if (tableService.dataSource) {
11193
- tableService.addColumn({
11194
- id: 'system.select',
11195
- width: '50px',
11196
- filterable: false,
11197
- sortable: false,
11198
- CellComponent: SelectRowComponent,
11199
- TitleComponent: () => jsxRuntimeExports.jsx(CheckAllComponent, {}),
11200
- }, 0);
11201
- }
11202
- else {
11203
- tableService.addColumn({
11204
- id: 'system.insert',
11205
- width: '50px',
11206
- filterable: false,
11207
- sortable: false,
11208
- CellComponent: DeleteRowComponent,
11209
- className: 'o-form-table-remove-cell',
11210
- }, 0);
11211
- }
11212
- }, [tableService]);
11213
- if (!mounted)
11214
- return null;
11215
- return (jsxRuntimeExports.jsx(DefaultFormTableContext.Provider, { value: formTableContext.current, children: jsxRuntimeExports.jsx(ControllerTableComponent, { controller: controller, className: addClassname('o-form-table', className), FooterComponent: tableService.dataSource ? undefined : FooterComponent, footer: tableService.dataSource || !showAddButton || props.disabled ? false : true, NotFoundComponent: null, ...props }) }));
11216
- });
11217
- FormTableComponent.displayName = 'FormTable';
11218
-
11219
- const FormTableItemDisplayer = ({ value, columns, first, last, className, format, name, index, }) => {
11220
- const userColumns = columns.filter((c) => !c.id.startsWith('system.'));
11221
- const monoColumnTable = userColumns.length === 1 && !userColumns[0].id;
11222
- const classNames = monoColumnTable
11223
- ? 'o-form-mono-column-table-item-displayer'
11224
- : `o-form-table-item-displayer${first ? ' o-form-table-item-displayer-first' : ''}${last ? ' o-form-table-item-displayer-last' : ''}`;
11225
- return (jsxRuntimeExports.jsx("div", { className: addClassname(classNames, className), children: userColumns.map((column, colIndex) => {
11226
- const Displayer = column.Displayer;
11227
- if (Displayer) {
11228
- return (jsxRuntimeExports.jsx(Displayer, { column: column, firstRow: first, lastRow: last, rowIndex: index, firstCol: colIndex === 0, lastCol: colIndex === columns.length - 1, colIndex: colIndex, format: format, value: value, rowName: name }, `col-${colIndex}`));
11229
- }
11230
- return null;
11231
- }) }));
11232
- };
11233
-
11234
- const FormTableValueDisplayer = ({ name, columns, value, format, className }) => {
11235
- if (!Array.isArray(value))
11236
- return null;
11237
- return (jsxRuntimeExports.jsx("div", { className: addClassname('o-form-table-displayer-value', className), children: value.map((v, index) => (jsxRuntimeExports.jsx(FormTableItemDisplayer, { value: v, columns: columns, first: index === 0, last: index === value.length - 1, format: format === 'csv' ? 'csv' : 'form_summary_table', name: `${name}.${index}`, index: index }, `item-${index}`))) }));
11238
- };
11239
- var FormTableValueDisplayer$1 = styled(FormTableValueDisplayer) `
11240
- .o-form-table-item-displayer {
11241
- ${borderBottomColor('primary')}
11242
- ${borderBottomStyle('solid')}
11243
- ${borderBottomWidth('1px')}
11244
- ${paddingY('sm')}
11245
- &.o-form-table-item-displayer-last {
11246
- ${paddingBottom(0)}
11247
- ${borderBottomWidth(0)}
11248
- }
11249
- &.o-form-table-item-displayer-first {
11250
- ${paddingTop(0)}
11251
- }
11252
- }
11253
- `;
11254
-
11255
- const StyledFormTableComponent = styled(FormTableComponent) `
11256
- ${tableStyle}
11257
- `;
11258
- const FormTable = React.memo((props) => {
11259
- let defaultValue = props.defaultValue;
11260
- if (defaultValue === undefined) {
11261
- let minLength = (props.minLength ?? props.min) || 0;
11262
- if (props.required && minLength < 1) {
11263
- minLength = 1;
11264
- }
11265
- const isSingleColumnTable = props.controller.columns.find((c) => c.id === '');
11266
- defaultValue = minLength > 0 ? Array(minLength).fill(isSingleColumnTable ? undefined : {}) : [];
11267
- }
11268
- const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({
11269
- defaultValue,
11270
- Displayer: (displayerProps) => {
11271
- const form = onekijsFramework.useForm();
11272
- let value = form.getValue(displayerProps.name) ?? [];
11273
- const ValueDisplayer = props.ValueDisplayer ?? FormTableValueDisplayer$1;
11274
- return (jsxRuntimeExports.jsx(FieldDisplayer, { label: displayerProps.label ?? titlelize(displayerProps.name), help: props.help, first: displayerProps.first, last: displayerProps.last, value: jsxRuntimeExports.jsx(ValueDisplayer, { name: displayerProps.name, value: value, columns: props.controller.columns, format: displayerProps.format }), format: displayerProps.format }));
11275
- },
11276
- }, props));
11277
- const fieldContainer = onekijsFramework.useFieldContainer({
11278
- container: props.name,
11279
- });
11280
- const Component = props.FieldComponent || StyledFormTableComponent;
11281
- return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Component, { ...fieldComponentProps, name: props.name, required: props.required, minLength: props.minLength ?? props.min, maxLength: props.maxLength ?? props.max }) }) }));
11282
- });
11283
- FormTable.displayName = 'FormTable';
11284
-
11285
11071
  const CheckboxCellComponent = (options) => {
11286
11072
  const CheckboxCellComponent = ({ item, column, rowIndex }) => {
11287
11073
  const { tableName, editable } = useFormTableContext();
@@ -11696,18 +11482,233 @@ const textareaColumn = (id, options) => {
11696
11482
  });
11697
11483
  };
11698
11484
 
11699
- const useCheckboxColumn = (id, options) => {
11700
- const column = onekijsFramework.useLazyRef(() => {
11701
- return checkboxColumn(id, options);
11702
- });
11703
- return column.current;
11485
+ const FormTableItemDisplayer = ({ value, columns, first, last, className, format, name, index, }) => {
11486
+ const userColumns = columns.filter((c) => !c.id.startsWith('system.'));
11487
+ const monoColumnTable = userColumns.length === 1 && !userColumns[0].id;
11488
+ const classNames = monoColumnTable
11489
+ ? 'o-form-mono-column-table-item-displayer'
11490
+ : `o-form-table-item-displayer${first ? ' o-form-table-item-displayer-first' : ''}${last ? ' o-form-table-item-displayer-last' : ''}`;
11491
+ return (jsxRuntimeExports.jsx("div", { className: addClassname(classNames, className), children: userColumns.map((column, colIndex) => {
11492
+ const Displayer = column.Displayer;
11493
+ if (Displayer) {
11494
+ return (jsxRuntimeExports.jsx(Displayer, { column: column, firstRow: first, lastRow: last, rowIndex: index, firstCol: colIndex === 0, lastCol: colIndex === columns.length - 1, colIndex: colIndex, format: format, value: value, rowName: name }, `col-${colIndex}`));
11495
+ }
11496
+ return null;
11497
+ }) }));
11704
11498
  };
11705
11499
 
11706
- const useColumns = (columns) => {
11707
- const ref = React.useRef(columns);
11708
- return ref.current;
11500
+ const FormTableValueDisplayer = ({ name, columns, value, format, className }) => {
11501
+ if (!Array.isArray(value))
11502
+ return null;
11503
+ return (jsxRuntimeExports.jsx("div", { className: addClassname('o-form-table-displayer-value', className), children: value.map((v, index) => (jsxRuntimeExports.jsx(FormTableItemDisplayer, { value: v, columns: columns, first: index === 0, last: index === value.length - 1, format: format === 'csv' ? 'csv' : 'form_summary_table', name: `${name}.${index}`, index: index }, `item-${index}`))) }));
11709
11504
  };
11710
-
11505
+ var FormTableValueDisplayer$1 = styled(FormTableValueDisplayer) `
11506
+ .o-form-table-item-displayer {
11507
+ ${borderBottomColor('primary')}
11508
+ ${borderBottomStyle('solid')}
11509
+ ${borderBottomWidth('1px')}
11510
+ ${paddingY('sm')}
11511
+ &.o-form-table-item-displayer-last {
11512
+ ${paddingBottom(0)}
11513
+ ${borderBottomWidth(0)}
11514
+ }
11515
+ &.o-form-table-item-displayer-first {
11516
+ ${paddingTop(0)}
11517
+ }
11518
+ }
11519
+ `;
11520
+
11521
+ const DefaultDeleteRowComponent = ({ rowIndex }) => {
11522
+ const form = onekijsFramework.useForm();
11523
+ const { tableName, onRemove } = useFormTableContext();
11524
+ const removeRow = () => {
11525
+ const row = form.getValue(`${tableName}.${rowIndex}`);
11526
+ if (onRemove) {
11527
+ onRemove(form, row, rowIndex);
11528
+ }
11529
+ else {
11530
+ form.remove(tableName, rowIndex);
11531
+ }
11532
+ };
11533
+ const metadata = onekijsFramework.useFormMetadata(tableName);
11534
+ let disabled = false;
11535
+ if (metadata.disabled || metadata.readOnly || (metadata.editable === false && form.config.reconfigure)) {
11536
+ disabled = true;
11537
+ }
11538
+ return (jsxRuntimeExports.jsx("div", { className: `o-form-table-remove${disabled ? ' o-form-table-remove-disabled' : ''}`, onClick: removeRow, children: jsxRuntimeExports.jsx(RemoveIcon$1, { width: "14px", height: "14px" }) }));
11539
+ };
11540
+ const DefaultSelectRowComponent = ({ item }) => {
11541
+ const { onSelect } = useFormTableContext();
11542
+ const selected = item?.selected;
11543
+ const toggle = (selected) => onSelect(item, selected);
11544
+ return jsxRuntimeExports.jsx(Checkbox, { value: selected || false, onChange: toggle });
11545
+ };
11546
+ const FooterComponent = () => {
11547
+ const form = onekijsFramework.useForm();
11548
+ const { tableName, addLabel, maxLength, onAdd } = useFormTableContext();
11549
+ const isSingleColumnTable = useTableColumns().find((c) => c.id === '');
11550
+ const addRow = (e) => {
11551
+ e.preventDefault();
11552
+ onAdd(isSingleColumnTable ? undefined : {});
11553
+ };
11554
+ const currentSize = (form.getValue(tableName) || []).length;
11555
+ if (maxLength !== undefined && currentSize >= maxLength)
11556
+ return null;
11557
+ return (jsxRuntimeExports.jsxs("div", { className: "o-form-table-add", onClick: addRow, children: [jsxRuntimeExports.jsx(TogglerIcon, { open: false, model: "plus", color: "currentColor" }), jsxRuntimeExports.jsx("span", { children: addLabel })] }));
11558
+ };
11559
+ const CheckAllComponent = () => {
11560
+ const form = onekijsFramework.useForm();
11561
+ const { tableName } = useFormTableContext();
11562
+ const fieldValue = onekijsFramework.useValue(tableName);
11563
+ const tableService = useTableService();
11564
+ const isAllChecked = Array.isArray(fieldValue) && Array.isArray(fieldValue) && fieldValue.length > 0;
11565
+ const toggle = (selected) => {
11566
+ if (selected) {
11567
+ const items = tableService.items.map((item) => item?.data).filter((data) => data !== undefined);
11568
+ form.setValue(tableName, items);
11569
+ }
11570
+ else {
11571
+ form.setValue(tableName, []);
11572
+ }
11573
+ };
11574
+ return jsxRuntimeExports.jsx(Checkbox, { className: "o-form-table-check-all", value: isAllChecked, onChange: toggle });
11575
+ };
11576
+ const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, onAdd, onChange, onRemove, className, name, format = 'auto', required, minLength, maxLength, showAddButton = true, DeleteRowComponent = DefaultDeleteRowComponent, SelectRowComponent = DefaultSelectRowComponent, ...props }) => {
11577
+ const form = onekijsFramework.useForm();
11578
+ const field = form.fields[name];
11579
+ if (field) {
11580
+ const validators = field.validators;
11581
+ const minlengthValidator = (validators.minLength || validators.min);
11582
+ if (minlengthValidator) {
11583
+ minLength = minlengthValidator.length;
11584
+ }
11585
+ const maxlengthValidator = (validators.maxLength || validators.max);
11586
+ if (maxlengthValidator) {
11587
+ maxLength = maxlengthValidator.length;
11588
+ }
11589
+ }
11590
+ const id = React.useId();
11591
+ const tableService = controller.asService();
11592
+ const formatRef = onekijsFramework.useLazyRef(() => {
11593
+ if (format === 'auto') {
11594
+ return value && value.length > 0 && typeof value[0] !== 'object' ? 'id' : 'object';
11595
+ }
11596
+ return format;
11597
+ });
11598
+ const [mounted, setMounted] = React.useState(false);
11599
+ const formTableContext = onekijsFramework.useLazyRef(() => {
11600
+ const onSelect = (item, selected) => {
11601
+ const getId = (v) => {
11602
+ return formatRef.current === 'id' ? v : v.id;
11603
+ };
11604
+ const currentValues = form.getValue(name, []);
11605
+ const value = formatRef.current === 'id' ? item.id : item.data;
11606
+ if (selected) {
11607
+ onChange && onChange([value].concat(currentValues));
11608
+ }
11609
+ else {
11610
+ onChange && onChange(currentValues.filter((v) => getId(v) !== getId(value)));
11611
+ }
11612
+ };
11613
+ if (!onAdd) {
11614
+ onAdd = (initialValue) => {
11615
+ formTableContext.current.editable = true;
11616
+ form.add(name, initialValue);
11617
+ };
11618
+ }
11619
+ return { tableName: name, onSelect, onAdd, onRemove, addLabel, required, minLength, maxLength };
11620
+ });
11621
+ // listen on value change from the form
11622
+ // for the initial value in the table controller
11623
+ // delay the rendering of the table until the value has been set in the controller
11624
+ React.useEffect(() => {
11625
+ const watch = [name];
11626
+ const listener = (value) => {
11627
+ if (tableService.dataSource) {
11628
+ tableService.setSelected('value', value || []);
11629
+ }
11630
+ else if (value !== undefined) {
11631
+ tableService.setData(value);
11632
+ }
11633
+ };
11634
+ form.onValueChange(id, listener, watch);
11635
+ listener(value);
11636
+ setMounted(true);
11637
+ return () => {
11638
+ form.offValueChange(id);
11639
+ };
11640
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11641
+ }, []);
11642
+ React.useEffect(() => {
11643
+ if (tableService.dataSource) {
11644
+ tableService.addColumn({
11645
+ id: 'system.select',
11646
+ width: '50px',
11647
+ filterable: false,
11648
+ sortable: false,
11649
+ CellComponent: SelectRowComponent,
11650
+ TitleComponent: () => jsxRuntimeExports.jsx(CheckAllComponent, {}),
11651
+ }, 0);
11652
+ }
11653
+ else {
11654
+ tableService.addColumn({
11655
+ id: 'system.insert',
11656
+ width: '50px',
11657
+ filterable: false,
11658
+ sortable: false,
11659
+ CellComponent: DeleteRowComponent,
11660
+ className: 'o-form-table-remove-cell',
11661
+ }, 0);
11662
+ }
11663
+ }, [tableService]);
11664
+ if (!mounted)
11665
+ return null;
11666
+ return (jsxRuntimeExports.jsx(DefaultFormTableContext.Provider, { value: formTableContext.current, children: jsxRuntimeExports.jsx(ControllerTableComponent, { controller: controller, className: addClassname('o-form-table', className), FooterComponent: tableService.dataSource ? undefined : FooterComponent, footer: tableService.dataSource || !showAddButton || props.disabled ? false : true, NotFoundComponent: null, ...props }) }));
11667
+ });
11668
+ FormTableComponent.displayName = 'FormTable';
11669
+
11670
+ const StyledFormTableComponent = styled(FormTableComponent) `
11671
+ ${tableStyle}
11672
+ `;
11673
+ const FormTable = React.memo((props) => {
11674
+ let defaultValue = props.defaultValue;
11675
+ if (defaultValue === undefined) {
11676
+ let minLength = (props.minLength ?? props.min) || 0;
11677
+ if (props.required && minLength < 1) {
11678
+ minLength = 1;
11679
+ }
11680
+ const isSingleColumnTable = props.controller.columns.find((c) => c.id === '');
11681
+ defaultValue = minLength > 0 ? Array(minLength).fill(isSingleColumnTable ? undefined : {}) : [];
11682
+ }
11683
+ const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({
11684
+ defaultValue,
11685
+ Displayer: (displayerProps) => {
11686
+ const form = onekijsFramework.useForm();
11687
+ let value = form.getValue(displayerProps.name) ?? [];
11688
+ const ValueDisplayer = props.ValueDisplayer ?? FormTableValueDisplayer$1;
11689
+ return (jsxRuntimeExports.jsx(FieldDisplayer, { label: displayerProps.label ?? titlelize(displayerProps.name), help: props.help, first: displayerProps.first, last: displayerProps.last, value: jsxRuntimeExports.jsx(ValueDisplayer, { name: displayerProps.name, value: value, columns: props.controller.columns, format: displayerProps.format }), format: displayerProps.format }));
11690
+ },
11691
+ }, props));
11692
+ const fieldContainer = onekijsFramework.useFieldContainer({
11693
+ container: props.name,
11694
+ });
11695
+ const Component = props.FieldComponent || StyledFormTableComponent;
11696
+ return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Component, { ...fieldComponentProps, name: props.name, required: props.required, minLength: props.minLength ?? props.min, maxLength: props.maxLength ?? props.max }) }) }));
11697
+ });
11698
+ FormTable.displayName = 'FormTable';
11699
+
11700
+ const useCheckboxColumn = (id, options) => {
11701
+ const column = onekijsFramework.useLazyRef(() => {
11702
+ return checkboxColumn(id, options);
11703
+ });
11704
+ return column.current;
11705
+ };
11706
+
11707
+ const useColumns = (columns) => {
11708
+ const ref = React.useRef(columns);
11709
+ return ref.current;
11710
+ };
11711
+
11711
11712
  const useEnumColumn = (id, options) => {
11712
11713
  const column = onekijsFramework.useLazyRef(() => {
11713
11714
  return enumColumn(id, options);
@@ -11743,1957 +11744,2136 @@ const useSelectColumn = (id, options) => {
11743
11744
  return column.current;
11744
11745
  };
11745
11746
 
11746
- const useTextColumn = (id, options) => {
11747
+ const useTextareaColumn = (id, options) => {
11747
11748
  const column = onekijsFramework.useLazyRef(() => {
11748
- return textColumn(id, options);
11749
+ return textareaColumn(id, options);
11749
11750
  });
11750
11751
  return column.current;
11751
11752
  };
11752
11753
 
11753
- const useTextareaColumn = (id, options) => {
11754
+ const useTextColumn = (id, options) => {
11754
11755
  const column = onekijsFramework.useLazyRef(() => {
11755
- return textareaColumn(id, options);
11756
+ return textColumn(id, options);
11756
11757
  });
11757
11758
  return column.current;
11758
11759
  };
11759
11760
 
11760
- const TagComponent = ({ className, children, onClick, icon }) => {
11761
- return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-tag', className), onClick: onClick, children: [icon && jsxRuntimeExports.jsx("span", { className: "o-tag-icon", children: icon }), children] }));
11762
- };
11761
+ const columnCount = cssProperty('column-count');
11762
+ const columnFill = cssProperty('column-fill');
11763
+ const columnRule = cssProperty('column-rule');
11764
+ const columnRuleColor = cssProperty(null, colorFormatter('column-rule-color'));
11765
+ const columnRuleStyle = cssProperty('column-rule-style');
11766
+ const columnRuleWidth = cssProperty('column-rule-width', pxFormatter);
11767
+ const columnSpan = cssProperty('column-span');
11768
+ const columnWidth = cssProperty('column-width', pxFormatter);
11769
+ const columns = cssProperty('columns');
11770
+ const grid = cssProperty('grid');
11771
+ const gridAutoColumns = cssProperty('grid-auto-columns');
11772
+ const gridAutoFlow = cssProperty('grid-auto-flow');
11773
+ const gridAutoRows = cssProperty('grid-auto-rows');
11774
+ const gridColumn = cssProperty('grid-column');
11775
+ const gridColumnEnd = cssProperty('grid-column-start');
11776
+ const gridColumnGap = columnGap;
11777
+ const gridColumnStart = cssProperty('grid-column-start');
11778
+ const gridGap = gap;
11779
+ const gridRow = cssProperty('grid-row');
11780
+ const gridRowEnd = cssProperty('grid-row-end');
11781
+ const gridRowGap = rowGap;
11782
+ const gridRowStart = cssProperty('grid-row-start');
11783
+ const gridTemplate = cssProperty('grid-template');
11784
+ const gridTemplateAreas = cssProperty('grid-template-areas');
11785
+ const gridTemplateColumns = cssProperty('grid-template-columns');
11786
+ const gridTemplateRows = cssProperty('grid-template-rows');
11763
11787
 
11764
- const tagStyle = ({ theme, kind, bgColor = 'primary', fontColor = 'white', size = 'small', onClick, marginBottom: mb = 0, marginLeft: ml = 0, marginRight: mr = 0, marginTop: mt = 0, }) => {
11765
- let fSize = 'sm';
11766
- let lHeight = 'md';
11767
- let pX = 'md';
11768
- let radius = 'sm';
11769
- const pt = '2xs';
11770
- if (size === 'small') {
11771
- fSize = 'xs';
11772
- lHeight = 'xs';
11773
- radius = 'xs';
11774
- pX = 'sm';
11775
- }
11776
- if (size === 'large') {
11777
- fSize = 'md';
11778
- lHeight = 'lg';
11779
- }
11788
+ const datePickerStyle = () => {
11780
11789
  return styled.css `
11781
- ${display('inline-flex')}
11782
- ${alignItems('center')}
11783
- ${backgroundColor(kind ? theme.buttons[kind].bgColor : bgColor)}
11784
- ${marginLeft(ml)}
11785
- ${marginRight(mr)}
11786
- ${marginBottom(mb)}
11787
- ${marginTop(mt)}
11788
- ${lineHeight(lHeight)}
11789
- ${paddingX(pX)}
11790
- ${paddingTop(pt)}
11791
- ${color(kind ? theme.buttons[kind].color : fontColor)}
11792
- ${fontSize(fSize)}
11793
- ${cursor(onClick ? 'pointer' : 'inherit')}
11794
- ${borderRadius(radius)}
11795
- .o-tag-icon {
11796
- ${marginRight('xs')}
11797
- ${display('inline-flex')}
11790
+ .o-calendar {
11791
+ ${width('300px')}
11792
+ }
11793
+ .o-calendar-month {
11794
+ ${display('flex')}
11798
11795
  ${alignItems('center')}
11796
+ ${marginBottom('md')}
11797
+ ${columnGap('sm')}
11799
11798
  }
11800
- `;
11801
- };
11802
-
11803
- const Tag = styled(TagComponent) `
11804
- ${tagStyle}
11805
- `;
11806
11799
 
11807
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11808
- const WizardServiceContext = React.createContext(null);
11809
- const useWizardService = () => {
11810
- return React.useContext(WizardServiceContext);
11811
- };
11800
+ .o-calendar-select-month {
11801
+ ${width(24)}
11802
+ }
11812
11803
 
11813
- const WizardStateContext = React.createContext(null);
11814
- const useWizardState = () => {
11815
- return React.useContext(WizardStateContext);
11816
- };
11804
+ .o-calendar-select-year {
11805
+ ${width(12)}
11806
+ }
11817
11807
 
11818
- const StepTitleContent = ({ member, index }) => {
11819
- return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [member.icon, jsxRuntimeExports.jsxs("span", { className: "o-step-title", children: [index, ". ", `${member.title}`] })] }));
11820
- };
11808
+ .o-calendar-day-container {
11809
+ ${display('grid')}
11810
+ ${color('light')}
11811
+ ${gridTemplateColumns('repeat(7, 1fr)')}
11812
+ grid-template-rows: repeat(7, min(30px));
11813
+ ${rowGap('5px')}
11814
+ ${columnGap('5px')}
11815
+ }
11816
+ .o-calendar-day-title {
11817
+ ${display('flex')}
11818
+ ${alignItems('center')}
11819
+ ${justifyContent('center')}
11820
+ ${color('dark')}
11821
+ }
11822
+ .o-calendar-day {
11823
+ ${display('flex')}
11824
+ ${alignItems('center')}
11825
+ ${justifyContent('center')}
11826
+ ${cursor('pointer')}
11827
+ ${borderRadius('md')}
11821
11828
 
11822
- const StepTitle = (props) => {
11823
- const { member, onActivate, TitleContentComponent = StepTitleContent } = props;
11824
- return (jsxRuntimeExports.jsx("div", { className: `o-step${member.active ? ' o-step-active' : ' o-step-inactive'}${member.disabled ? ' o-step-disabled' : ' o-step-enabled'}${member.visible ? ' o-step-visible' : ' o-step-hidden'}${member.touched || member.touching ? ' o-step-touched' : ' o-step-untouched'}${member.success ? ' o-step-success' : ''}${member.touchingWarning || (member.touched && member.warning) ? ' o-step-warning' : ''}${member.touchingError || (member.touched && member.error) ? ' o-step-error' : ''}${member.loading ? ' o-step-loading' : ''}`, onClick: () => onActivate(member), children: jsxRuntimeExports.jsx(TitleContentComponent, { ...props }) }));
11825
- };
11829
+ &:hover {
11830
+ ${backgroundColor('darkest')}
11831
+ ${color('white')}
11832
+ }
11833
+ }
11834
+ .o-calendar-day-in-month {
11835
+ ${color('darkest')}
11836
+ ${backgroundColor('lighter')}
11837
+ }
11838
+ .o-calendar-day-current {
11839
+ ${borderColor('darker')}
11840
+ ${borderWidth('2px')}
11841
+ ${borderStyle('solid')}
11842
+ ${fontWeight('medium')}
11843
+ }
11826
11844
 
11827
- const WizardContainer = ({ cancelLabel = 'Cancel', className, children, doneLabel = 'Submit', nextLabel = 'Next', onCancel, onDone, previousLabel = 'Previous', title, stepSize = 3, TitleComponent = StepTitle, TitleContentComponent, forwardOnly = true, hasSummaryStep = false, reviewLabel = 'Review and Submit', }) => {
11828
- const classNames = addClassname('o-wizard', className);
11829
- const state = useWizardState();
11830
- const service = useWizardService();
11831
- const lastStepUid = service.getLastStep()?.uid;
11832
- const activate = React.useCallback((step) => {
11833
- if (!step || step.disabled || (!step.touched && !step.touching))
11834
- return;
11835
- if (!step.active) {
11836
- service.activate(step.uid);
11837
- }
11838
- }, [service]);
11839
- const errorRef = React.useRef([]);
11840
- errorRef.current = [];
11841
- const indexRef = React.useRef(0);
11842
- indexRef.current = 0;
11843
- return (jsxRuntimeExports.jsxs(Row, { className: classNames, children: [jsxRuntimeExports.jsxs(Col, { size: stepSize, className: "o-wizard-step-panel", children: [title && jsxRuntimeExports.jsx("div", { className: "o-wizard-title", children: title }), state.members.map((step) => {
11844
- if (step.visible) {
11845
- indexRef.current++;
11846
- }
11847
- else {
11848
- return null;
11849
- }
11850
- if (step.error !== undefined) {
11851
- errorRef.current.push({
11852
- stepIndex: indexRef.current,
11853
- stepTitle: step.title,
11854
- errorMessage: step.error,
11855
- });
11856
- }
11857
- return (jsxRuntimeExports.jsx(TitleComponent, { member: step, onActivate: activate, index: indexRef.current, TitleContentComponent: TitleContentComponent }, `step-title-${step.uid}`));
11858
- })] }), jsxRuntimeExports.jsxs(Col, { size: (12 - stepSize), className: "o-wizard-content-panel", children: [jsxRuntimeExports.jsx("div", { className: "o-wizard-content", children: children }), jsxRuntimeExports.jsxs("div", { className: "o-wizard-control", children: [onCancel && (jsxRuntimeExports.jsx(Button, { kind: "primary", pattern: "flat", className: "o-wizard-control-button", type: "button", onClick: () => onCancel(), children: cancelLabel })), !service.isFirstStep() && (jsxRuntimeExports.jsx(Button, { kind: "primary", pattern: "outline", className: "o-wizard-control-button", onClick: () => service.previous(), type: "button", children: previousLabel })), !service.isLastStep() && (jsxRuntimeExports.jsx(Button, { kind: service.isCurrentStepInVisibleError() ? 'danger' : 'primary', pattern: "solid", className: "o-wizard-control-button", disabled: service.isCurrentStepInVisibleError(), onClick: () => service.next(), type: "button", children: nextLabel })), (service.isLastStep() || !forwardOnly) && (jsxRuntimeExports.jsx(SubmitButton, { kind: errorRef.current.length > 0 ? 'danger' : 'success', pattern: "solid", className: "o-wizard-control-button", disabled: errorRef.current.length > 0, onClick: hasSummaryStep && !service.isLastStep() && lastStepUid ? () => service.activate(lastStepUid) : onDone, type: "button", showErrors: true, children: hasSummaryStep && !service.isLastStep() ? reviewLabel : doneLabel }))] })] })] }));
11859
- };
11845
+ .o-calendar-day-in-range {
11846
+ ${backgroundColor('lightblue')}
11847
+ ${borderRadius('none')}
11848
+ ${color('white')}
11849
+ }
11860
11850
 
11861
- const ControlledWizardComponent = ({ Component = WizardContainer, controller, ...props }) => {
11862
- return (jsxRuntimeExports.jsx(WizardServiceContext.Provider, { value: controller, children: jsxRuntimeExports.jsx(WizardStateContext.Provider, { value: controller.state, children: jsxRuntimeExports.jsx(Component, { ...props }) }) }));
11863
- };
11851
+ .o-calendar-day-in-range-transient {
11852
+ ${backgroundColor('dark')}
11853
+ ${borderRadius('none')}
11854
+ ${color('white')}
11855
+ }
11864
11856
 
11865
- exports.WizardService = class WizardService extends TabsService {
11866
- activateNext() {
11867
- const nextStep = this.getNextStep();
11868
- if (nextStep) {
11869
- this.activate(nextStep.uid);
11870
- }
11857
+ .o-calendar-day-start-range,
11858
+ .o-calendar-day-start-range-transient {
11859
+ ${borderTopRightRadius('none')}
11860
+ ${borderBottomRightRadius('none')}
11871
11861
  }
11872
- activatePrevious() {
11873
- const previousStep = this.getPreviousStep();
11874
- if (previousStep) {
11875
- this.activate(previousStep.uid);
11876
- }
11862
+
11863
+ .o-calendar-day-end-range,
11864
+ .o-calendar-day-end-range-transient {
11865
+ ${borderTopLeftRadius('none')}
11866
+ ${borderBottomLeftRadius('none')}
11877
11867
  }
11878
- getCurrentStep() {
11879
- return this.state.members[this.getCurrentActiveIndex()];
11868
+
11869
+ .o-datepicker-dropdown-content {
11870
+ ${borderRadius('sm')}
11871
+ ${borderTopLeftRadius(0)}
11872
+ ${borderTopRightRadius(0)}
11873
+ ${boxShadow('lg')}
11874
+ ${zIndex(2000)}
11875
+ ${backgroundColor('white')}
11876
+ ${borderWidth(1)}
11877
+ ${borderColor('light')}
11878
+ ${marginTop('-1px')}
11879
+ ${padding('lg')}
11880
+ ${userSelect('none')}
11881
+ ${display('flex')}
11880
11882
  }
11881
- getNextStep() {
11882
- for (let i = this.getCurrentActiveIndex() + 1; i < this.state.members.length; i++) {
11883
- const step = this.state.members[i];
11884
- if (step && step.visible && !step.disabled) {
11885
- return step;
11886
- }
11883
+
11884
+ .o-datepicker-active {
11885
+ .o-calendar-day-active {
11886
+ ${color('white')}
11887
+ ${backgroundColor('primary')}
11888
+ ${fontWeight('medium')}
11889
+ &.o-calendar-day-end-range-transient {
11890
+ ${backgroundColor('darkest')}
11891
+ &.o-calendar-day-start-range {
11892
+ ${backgroundColor('primary')}
11893
+ }
11887
11894
  }
11888
- return undefined;
11889
- }
11890
- getLastStep() {
11891
- return this.state.members.filter((m) => m.visible && !m.disabled).slice(-1)[0];
11892
- }
11893
- getPreviousStep() {
11894
- for (let i = this.getCurrentActiveIndex() - 1; i >= 0; i--) {
11895
- const step = this.state.members[i];
11896
- if (step && step.visible && !step.disabled) {
11897
- return step;
11898
- }
11895
+ &.o-calendar-day-start-range-transient {
11896
+ ${backgroundColor('darkest')}
11899
11897
  }
11900
- return undefined;
11898
+ }
11901
11899
  }
11902
- isFirstStep() {
11903
- if (this.state.active) {
11904
- return this.state.members.filter((m) => m.visible)[0]?.uid === this.state.active;
11905
- }
11906
- return false;
11900
+
11901
+ .o-datepicker-input {
11902
+ input:read-only {
11903
+ ${cursor('pointer')}
11904
+ }
11907
11905
  }
11908
- isLastStep() {
11909
- if (this.state.active) {
11910
- return this.state.members.filter((m) => m.visible && !m.disabled).slice(-1)[0]?.uid === this.state.active;
11911
- }
11912
- return false;
11906
+
11907
+ .o-datepicker-icon {
11908
+ ${cursor('pointer')}
11909
+ ${display('flex')}
11910
+ ${alignItems('center')}
11913
11911
  }
11914
- isCurrentStepInError() {
11915
- if (this.state.active) {
11916
- const currentStep = this.getMember(this.state.active);
11917
- return currentStep?.error !== undefined;
11918
- }
11919
- return false;
11912
+
11913
+ .o-datepicker-remover {
11914
+ ${cursor('pointer')}
11915
+ ${color('light')}
11916
+ ${fontFamily('Arial')}
11917
+ ${paddingX('sm')}
11918
+ ${userSelect('none')}
11920
11919
  }
11921
- isCurrentStepInVisibleError() {
11922
- if (this.state.active) {
11923
- const currentStep = this.getMember(this.state.active);
11924
- return currentStep?.touchingError !== undefined;
11925
- }
11926
- return false;
11920
+
11921
+ .o-toggler-icon {
11922
+ ${cursor('pointer')}
11923
+ ${color('primary')}
11927
11924
  }
11928
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11929
- *done() {
11930
- yield this.setSubmitting(true);
11931
- if (this.state.onDone) {
11932
- yield this.state.onDone();
11933
- }
11934
- yield this.setSubmitting(false);
11935
- }
11936
- next() {
11937
- if (this.isCurrentStepInError()) {
11938
- const currentStep = this.getCurrentStep();
11939
- if (currentStep) {
11940
- this.touched(currentStep.uid);
11941
- }
11942
- }
11943
- else {
11944
- let result = true;
11945
- if (this.state.onNext) {
11946
- result = this.state.onNext(this.getCurrentStep(), this.getNextStep());
11947
- }
11948
- if (result) {
11949
- this.activateNext();
11950
- }
11951
- }
11952
- }
11953
- previous() {
11954
- let result = true;
11955
- if (this.state.onPrevious) {
11956
- result = this.state.onPrevious(this.getCurrentStep(), this.getPreviousStep());
11957
- }
11958
- if (result) {
11959
- this.activatePrevious();
11960
- }
11961
- }
11962
- setSubmitting(submitting) {
11963
- this.state.submitting = submitting;
11964
- }
11965
- };
11966
- __decorate([
11967
- onekijsFramework.reducer,
11968
- __metadata("design:type", Function),
11969
- __metadata("design:paramtypes", []),
11970
- __metadata("design:returntype", void 0)
11971
- ], exports.WizardService.prototype, "activateNext", null);
11972
- __decorate([
11973
- onekijsFramework.reducer,
11974
- __metadata("design:type", Function),
11975
- __metadata("design:paramtypes", []),
11976
- __metadata("design:returntype", void 0)
11977
- ], exports.WizardService.prototype, "activatePrevious", null);
11978
- __decorate([
11979
- onekijsFramework.saga(onekijsFramework.SagaEffect.Leading)
11980
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11981
- ,
11982
- __metadata("design:type", Function),
11983
- __metadata("design:paramtypes", []),
11984
- __metadata("design:returntype", void 0)
11985
- ], exports.WizardService.prototype, "done", null);
11986
- __decorate([
11987
- onekijsFramework.reducer,
11988
- __metadata("design:type", Function),
11989
- __metadata("design:paramtypes", []),
11990
- __metadata("design:returntype", void 0)
11991
- ], exports.WizardService.prototype, "next", null);
11992
- __decorate([
11993
- onekijsFramework.reducer,
11994
- __metadata("design:type", Function),
11995
- __metadata("design:paramtypes", []),
11996
- __metadata("design:returntype", void 0)
11997
- ], exports.WizardService.prototype, "previous", null);
11998
- __decorate([
11999
- onekijsFramework.reducer,
12000
- __metadata("design:type", Function),
12001
- __metadata("design:paramtypes", [Boolean]),
12002
- __metadata("design:returntype", void 0)
12003
- ], exports.WizardService.prototype, "setSubmitting", null);
12004
- exports.WizardService = __decorate([
12005
- onekijsFramework.service
12006
- ], exports.WizardService);
12007
-
12008
- const useWizardController = ({ animate = 300, forwardOnly = true, onCancel, onDone, onNext, onPrevious, }) => {
12009
- const [_, service] = onekijsFramework.useService(exports.WizardService, {
12010
- members: [],
12011
- membersIndex: {},
12012
- animate,
12013
- forwardOnly,
12014
- onCancel,
12015
- onDone,
12016
- onNext,
12017
- onPrevious,
12018
- });
12019
- return service;
12020
- };
12021
11925
 
12022
- const UncontrolledWizardComponent = (props) => {
12023
- const controller = useWizardController(props);
12024
- return jsxRuntimeExports.jsx(ControlledWizardComponent, { ...props, controller: controller });
12025
- };
11926
+ .o-time-selector-part-icon-disabled {
11927
+ .o-toggler-icon {
11928
+ ${cursor('not-allowed')}
11929
+ ${color('light')}
11930
+ }
11931
+ }
12026
11932
 
12027
- const WizardComponent = (props) => {
12028
- if (props.controller) {
12029
- return jsxRuntimeExports.jsx(ControlledWizardComponent, { ...props, controller: props.controller });
11933
+ .o-time-container {
11934
+ ${marginLeft('3xl')}
11935
+ ${display('flex')}
11936
+ ${alignItems('center')}
11937
+ ${height('full')}
11938
+ .o-time-separator {
11939
+ ${marginX('lg')}
11940
+ }
12030
11941
  }
12031
- else {
12032
- return jsxRuntimeExports.jsx(UncontrolledWizardComponent, { ...props });
11942
+
11943
+ .o-time-selector-part-header {
11944
+ ${fontWeight('medium')}
11945
+ ${backgroundColor('lightest')}
11946
+ ${paddingX('sm')}
11947
+ ${whiteSpace('nowrap')}
12033
11948
  }
12034
- };
12035
11949
 
12036
- const wizardStyle = ({ layout = 'vertical', theme, inModal }) => {
12037
- const t = theme.wizard;
12038
- const stepBorderWidthFn = layout === 'horizontal' ? borderBottomWidth : borderLeftWidth;
12039
- const stepBorderStyleFn = layout === 'horizontal' ? borderBottomStyle : borderLeftStyle;
12040
- const stepBorderColorFn = layout === 'horizontal' ? borderBottomColor : borderLeftColor;
12041
- const wizardBorderWidthFn = layout === 'horizontal' ? borderBottomWidth : borderRightWidth;
12042
- const wizardBorderStyleFn = layout === 'horizontal' ? borderBottomStyle : borderRightStyle;
12043
- const wizardBorderColorFn = layout === 'horizontal' ? borderBottomColor : borderRightColor;
12044
- return styled.css `
12045
- ${display('flex')}
12046
- ${flexDirection(layout === 'horizontal' ? 'column' : 'row')}
12047
- .o-wizard-step-panel {
11950
+ .o-time-selector {
12048
11951
  ${display('flex')}
12049
- ${flexDirection(layout === 'horizontal' ? 'row' : 'column')}
12050
- ${alignItems(layout === 'horizontal' ? 'flex-end' : 'stretch')}
12051
- ${wizardBorderStyleFn(inModal ? t.modalStepsBorderStyle : t.stepsBorderStyle)}
12052
- ${wizardBorderWidthFn(inModal ? t.modalStepsBorderWidth : t.stepsBorderWidth)}
12053
- ${wizardBorderColorFn(inModal ? t.modalStepsBorderColor : t.stepsBorderColor)}
12054
- ${paddingRight(t.stepsPaddingRight)}
12055
- ${paddingTop(t.stepsPaddingTop)}
12056
- ${paddingLeft(t.stepsPaddingLeft)}
12057
- ${paddingBottom(t.stepsPaddingBottom)}
12058
- ${backgroundColor(inModal ? t.modalStepsBgColor : t.stepsBgColor)}
11952
+ ${alignItems('center')}
12059
11953
  }
12060
11954
 
12061
- .o-step {
12062
- ${paddingRight(t.paddingRight)}
12063
- ${paddingTop(t.paddingTop)}
12064
- ${paddingLeft(t.paddingLeft)}
12065
- ${paddingBottom(t.paddingBottom)}
12066
- ${stepBorderStyleFn(t.borderStyle)}
12067
- ${stepBorderWidthFn(t.borderWidth)}
12068
- ${stepBorderColorFn(t.borderColor)}
12069
- ${fontWeight(t.fontWeight)}
12070
- ${fontSize(t.fontSize)}
12071
- ${color(t.fontColor)}
11955
+ .o-time-edge-title {
11956
+ ${fontWeight('bold')}
11957
+ ${marginBottom('xs')}
11958
+ ${borderBottomWidth('1px')}
11959
+ ${borderBottomColor('lighter')}
11960
+ ${borderBottomStyle('solid')}
11961
+ ${textTransform('uppercase')}
11962
+ ${color('primary')}
12072
11963
  }
12073
11964
 
12074
- .o-step-active {
12075
- ${stepBorderColorFn(t.activeBorderColor)}
12076
- ${color(t.activeFontColor)}
12077
- ${fontWeight(t.activeFontWeight)}
12078
- ${fontSize(t.activeFontSize)}
12079
- ${backgroundColor(t.activeBgColor)}
12080
- &.o-step-enabled {
12081
- ${cursor('default')}
12082
- }
11965
+ .o-time-edge-empty {
11966
+ ${color('dark')}
11967
+ ${fontStyle('italic')}
11968
+ ${marginTop('md')}
11969
+ }
12083
11970
 
12084
- &.o-step-warning {
12085
- ${stepBorderColorFn(t.warningBorderColor)}
12086
- ${color(t.warningFontColor)}
12087
- ${backgroundColor(t.warningBgColor)}
12088
- }
12089
- &.o-step-error {
12090
- ${stepBorderColorFn(t.errorBorderColor)}
12091
- ${color(t.errorFontColor)}
12092
- ${backgroundColor(t.errorBgColor)}
12093
- }
11971
+ .o-time-edge-date-container {
11972
+ ${width('150px')}
12094
11973
  }
12095
11974
 
12096
- .o-step-inactive {
12097
- &.o-step-success,
12098
- &.o-step-touched {
12099
- ${stepBorderColorFn(t.successBorderColor)}
12100
- ${color(t.successFontColor)}
12101
- }
12102
- &.o-step-warning {
12103
- ${stepBorderColorFn(t.warningBorderColor)}
12104
- ${color(t.warningFontColor)}
12105
- }
12106
- &.o-step-error {
12107
- ${stepBorderColorFn(t.errorBorderColor)}
12108
- ${color(t.errorFontColor)}
11975
+ .o-time-edge-date {
11976
+ ${fontWeight('medium')}
11977
+ ${backgroundColor('lightest')}
11978
+ ${paddingX('sm')}
11979
+ ${marginRight('md')}
11980
+ ${whiteSpace('nowrap')}
11981
+ }
11982
+
11983
+ .o-time-container-range {
11984
+ ${marginLeft('3xl')}
11985
+ ${display('flex')}
11986
+ ${justifyContent('center')}
11987
+ ${height('full')}
11988
+ ${flexDirection('column')}
11989
+ ${gap('xl')}
11990
+ .o-time-separator {
11991
+ ${marginX('sm')}
12109
11992
  }
12110
11993
  }
12111
11994
 
12112
- .o-step-enabled {
12113
- ${cursor(t.cursor)}
11995
+ .o-time-edge-content {
11996
+ ${display('flex')}
11997
+ ${alignItems('center')}
12114
11998
  }
12115
11999
 
12116
- .o-step-disabled,
12117
- .o-step-untouched {
12118
- ${cursor('default')}
12119
- ${stepBorderColorFn(t.disabledBorderColor)}
12120
- ${color(t.disabledFontColor)}
12121
- ${fontWeight(t.disabledFontWeight)}
12122
- ${fontSize(t.disabledFontSize)}
12123
- ${backgroundColor(t.disabledBgColor)}
12000
+ .o-time-separator {
12001
+ ${fontWeight('bold')}
12124
12002
  }
12125
12003
 
12126
- .o-step-disabled {
12127
- ${cursor('not-allowed')}
12128
- ${textDecoration('line-through')}
12004
+ .o-time-input {
12005
+ ${width(10)}
12006
+ .o-input-field {
12007
+ ${textAlign('center')}
12008
+ }
12129
12009
  }
12130
12010
 
12131
- .o-wizard-content-panel {
12011
+ .o-time-selector-part {
12132
12012
  ${display('flex')}
12133
12013
  ${flexDirection('column')}
12014
+ ${alignItems('center')}
12134
12015
  }
12135
12016
 
12136
- .o-wizard-content {
12137
- ${flexGrow(1)}
12138
- ${padding('lg')}
12139
- ${paddingBottom(0)}
12140
- ${paddingRight('3xl')}
12017
+ .o-time-selector-part-large.o-toggler-icon-container {
12018
+ ${marginY('md')}
12141
12019
  }
12142
12020
 
12143
- .o-wizard-control {
12144
- ${display('flex')}
12145
- ${justifyContent('flex-end')}
12146
- ${padding('lg')}
12021
+ .o-quick-time-range-container {
12022
+ ${paddingRight('2xl')}
12023
+ ${marginTop('2xl')}
12024
+ ${marginX('md')}
12147
12025
  }
12148
12026
 
12149
- .o-wizard-control-button {
12150
- ${marginLeft('sm')}
12151
- }
12152
-
12153
- .o-wizard-title {
12154
- ${fontSize('2xl')}
12155
- ${fontWeight('light')}
12156
- ${color('black')}
12157
- ${lineHeight('4xl')}
12158
- ${paddingBottom('md')}
12027
+ .o-quick-time-range-title {
12028
+ ${fontWeight('bold')}
12159
12029
  }
12160
12030
 
12161
- .o-step-content-title {
12162
- ${fontSize('2xl')}
12163
- ${fontWeight('light')}
12164
- ${color('black')}
12165
- ${lineHeight('4xl')}
12166
- ${paddingBottom('md')}
12031
+ .o-quick-time-range {
12032
+ ${cursor('pointer')}
12033
+ ${fontWeight('medium')}
12034
+ ${color('primary')}
12035
+ &.o-quick-time-range-selected {
12036
+ ${cursor('auto')}
12037
+ ${fontWeight('bold')}
12038
+ ${color('pink')}
12039
+ }
12167
12040
  }
12168
12041
  `;
12169
12042
  };
12170
- const wizardModalStyle = () => {
12171
- return styled.css ``;
12043
+
12044
+ const months = [
12045
+ 'January',
12046
+ 'February',
12047
+ 'March',
12048
+ 'April',
12049
+ 'May',
12050
+ 'June',
12051
+ 'July',
12052
+ 'August',
12053
+ 'September',
12054
+ 'October',
12055
+ 'November',
12056
+ 'December',
12057
+ ];
12058
+ const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
12059
+ const isValidDate = (value) => {
12060
+ if (!value)
12061
+ return false;
12062
+ return /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/.test(value);
12172
12063
  };
12173
- const wizardSummaryStyle = () => {
12174
- return styled.css `
12175
- .o-accordion-panel {
12176
- ${paddingBottom('md')}
12177
- }
12178
- .o-accordion-panel-title {
12179
- ${backgroundColor('lighter')}
12180
- }
12181
- .o-accordion-content {
12182
- ${paddingX('sm')}
12183
- ${paddingBottom('sm')}
12184
- }
12185
- `;
12064
+ const isValidTime = (value) => {
12065
+ if (!value)
12066
+ return false;
12067
+ return /^(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])$/.test(value);
12186
12068
  };
12187
-
12188
- const Wizard = styled(WizardComponent) `
12189
- ${wizardStyle}
12190
- `;
12191
-
12192
- const WizardModalComponent = ({ title, doneLabel = 'Submit', ...props }) => {
12193
- return (jsxRuntimeExports.jsx(Modal, { ...props, children: jsxRuntimeExports.jsx(Wizard, { ...props, title: title, doneLabel: doneLabel, inModal: true }) }));
12069
+ const isValidMinuteOrSecond = (value) => {
12070
+ if (!value)
12071
+ return false;
12072
+ return /^(0?|[1-5])[0-9]$/.test(value);
12073
+ };
12074
+ const isValidHour = (value) => {
12075
+ if (!value)
12076
+ return false;
12077
+ return /^(2[0-3]|0?[0-9]|1[0-9])$/.test(value);
12194
12078
  };
12195
12079
 
12196
- const WizardModal = styled(WizardModalComponent) `
12197
- ${wizardModalStyle}
12080
+ const IconComponent$1 = ({ className, onClick }) => {
12081
+ return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsxs("svg", { className: "o-icon-calendar-svg", viewBox: "0 0 512 512", children: [jsxRuntimeExports.jsx("rect", { x: "48", y: "80", width: "416", height: "384", rx: "48", fill: "none", stroke: "currentColor", strokeLinejoin: "round", strokeWidth: "32" }), jsxRuntimeExports.jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "32", d: "M128 48v32M384 48v32M464 160H48M304 260l43.42-32H352v168M191.87 306.63c9.11 0 25.79-4.28 36.72-15.47a37.9 37.9 0 0011.13-27.26c0-26.12-22.59-39.9-47.89-39.9-21.4 0-33.52 11.61-37.85 18.93M149 374.16c4.88 8.27 19.71 25.84 43.88 25.84 28.59 0 52.12-15.94 52.12-43.82 0-12.62-3.66-24-11.58-32.07-12.36-12.64-31.25-17.48-41.55-17.48" })] }) }));
12082
+ };
12083
+ var CalendarIcon = styled(IconComponent$1) `
12084
+ ${({ width, height, color: cssColor = 'inherit', marginLeft: ml = '0', marginRight: mr = '0' }) => styled.css `
12085
+ width: ${width};
12086
+ height: ${height};
12087
+ ${marginLeft(ml)}
12088
+ ${marginRight(mr)}
12089
+ ${display('flex')};
12090
+ ${alignItems('center')};
12091
+ ${color(cssColor)}
12092
+ .o-icon-calendar-svg {
12093
+ display: inline-block;
12094
+ stroke-width: 0;
12095
+ stroke: currentColor;
12096
+ fill: currentColor;
12097
+ }
12098
+ `}
12198
12099
  `;
12199
12100
 
12200
- const useStep = (props) => {
12201
- const service = useWizardService();
12202
- const state = useWizardState();
12203
- const step = state.members[state.membersIndex[props.uid]];
12204
- React.useEffect(() => {
12205
- if (step === undefined) {
12206
- service.initMember(Object.assign({ uid: props.uid }, props));
12207
- }
12208
- }, [props, service, step]);
12209
- return step;
12101
+ const DefaultDatePickerContext = React.createContext(null);
12102
+ const useDatePickerContext = () => {
12103
+ return React.useContext(DefaultDatePickerContext);
12210
12104
  };
12211
12105
 
12212
- const WizardSummaryComponent = ({ className }) => {
12213
- const form = onekijsFramework.useForm();
12214
- const tree = Object.values(form.getDisplayerTree());
12215
- return (jsxRuntimeExports.jsx(Accordion, { className: className, children: tree.map((field, index) => {
12216
- const Displayer = field.Displayer || onekijsFramework.DefaultDisplayer;
12217
- return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === tree.length - 1, format: "form_summary" }));
12218
- }) }));
12106
+ const dateToString = (d) => {
12107
+ if (typeof d === 'function') {
12108
+ d = d();
12109
+ }
12110
+ if (typeof d === 'string') {
12111
+ d = new Date(d);
12112
+ }
12113
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
12219
12114
  };
12220
-
12221
- const WizardSummary = styled(WizardSummaryComponent) `
12222
- ${wizardSummaryStyle}
12223
- `;
12224
-
12225
- const Step = ({ title, active = false, disabled = false, visible = true, closable = false, children, icon, uid, optional = false, showTitle = true, className, onTouch, help, }) => {
12226
- const { animate, forwardOnly } = useWizardState();
12227
- const stepRef = React.useRef(null);
12228
- const step = useStep({
12229
- title,
12230
- active,
12231
- disabled,
12232
- visible,
12233
- closable,
12234
- icon,
12235
- loading: false,
12236
- optional,
12237
- touched: !forwardOnly,
12238
- touching: !forwardOnly,
12239
- uid: uid === undefined ? title : uid,
12240
- });
12241
- const touched = step?.touched;
12242
- const onEnter = () => {
12243
- const node = stepRef.current;
12244
- if (!node)
12245
- return;
12246
- node.style.opacity = '0';
12247
- };
12248
- const onEntering = () => {
12249
- const node = stepRef.current;
12250
- if (!node)
12251
- return;
12252
- setTimeout(() => {
12253
- node.style.opacity = '1';
12254
- node.style.transition = `opacity ${animate}ms ease-in-out`;
12255
- }, 0);
12256
- };
12257
- React.useEffect(() => {
12258
- if (touched && onTouch) {
12259
- onTouch();
12260
- }
12261
- }, [touched, onTouch]);
12262
- if (!step || !step.active) {
12115
+ const toDateRange = (value, label) => {
12116
+ if (value) {
12117
+ const [from, to] = value.trim().split(/ to\s*/);
12118
+ return {
12119
+ from: from && from.trim() ? from.trim() : null,
12120
+ to: to && to.trim() ? to.trim() : null,
12121
+ label,
12122
+ };
12123
+ }
12124
+ else {
12263
12125
  return null;
12264
12126
  }
12265
- return (jsxRuntimeExports.jsx(reactTransitionGroup.CSSTransition, { in: true, nodeRef: stepRef, timeout: animate, appear: true, onEnter: onEnter, onEntering: onEntering, children: jsxRuntimeExports.jsxs("div", { ref: stepRef, className: addClassname('o-step-content', className), children: [showTitle && jsxRuntimeExports.jsx("div", { className: "o-step-content-title", children: title }), help && (jsxRuntimeExports.jsx(Alert, { kind: "info", marginBottom: "lg", children: help })), children] }) }));
12266
12127
  };
12267
-
12268
- const FormStep = ({ name, disabled = false, visible = true, ...stepProps }) => {
12269
- const decorator = onekijsFramework.useFormDecorator(name, {
12270
- Displayer: (displayerProps) => {
12271
- const total = Object.values(displayerProps.children ?? {}).length;
12272
- return (jsxRuntimeExports.jsx(AccordionPanel, { title: stepProps.title, initialActive: displayerProps.index === 0, initialExpand: displayerProps.index === 0, children: Object.values(displayerProps.children ?? {}).map((field, index) => {
12273
- const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
12274
- return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format }));
12275
- }) }));
12276
- },
12277
- });
12278
- const metadata = onekijsFramework.useFormMetadata(decorator.name);
12279
- const service = useWizardService();
12280
- const fieldContainer = onekijsFramework.useFieldContainer({
12281
- container: name,
12282
- onValidationChange: (touchedValidation, allValidation) => {
12283
- service.onValidationChange(name, touchedValidation, allValidation);
12284
- },
12285
- });
12286
- const { touchAllFields, hide, show, disable, enable } = fieldContainer;
12287
- const initializedRef = React.useRef(false);
12288
- React.useEffect(() => {
12289
- const visible = metadata.visible ?? true;
12290
- const disabled = metadata.disabled ?? false;
12291
- if (!visible) {
12292
- if (disabled) {
12293
- service.disable(name);
12294
- disable();
12295
- }
12296
- else {
12297
- service.enable(name);
12298
- if (initializedRef.current === true) {
12299
- // we only use the enable method if this is a change and not a initialization
12300
- enable();
12301
- }
12128
+ const qr = (quickRange) => {
12129
+ return {
12130
+ label: quickRange,
12131
+ from: () => {
12132
+ const d = new Date();
12133
+ switch (quickRange) {
12134
+ case 'Last hour':
12135
+ d.setHours(d.getHours() - 1);
12136
+ break;
12137
+ case 'Last day':
12138
+ d.setDate(d.getDate() - 1);
12139
+ break;
12140
+ case 'Last week':
12141
+ d.setDate(d.getDate() - 7);
12142
+ break;
12143
+ case 'Last month':
12144
+ d.setMonth(d.getMonth() - 1);
12145
+ break;
12146
+ case 'Last year':
12147
+ d.setFullYear(d.getFullYear() - 1);
12148
+ break;
12302
12149
  }
12303
- service.hide(name);
12304
- hide();
12150
+ return d;
12151
+ },
12152
+ to: () => new Date(),
12153
+ };
12154
+ };
12155
+ const defaultQuickRanges = () => {
12156
+ return ['Last hour', 'Last day', 'Last week', 'Last month', 'Last year'].reduce((accumulator, label) => {
12157
+ const quickRange = qr(label);
12158
+ if (quickRange) {
12159
+ accumulator[label] = quickRange;
12305
12160
  }
12306
- else {
12307
- service.show(name);
12308
- if (initializedRef.current === true) {
12309
- // we only use the show method if this is a change and not a initialization
12310
- show();
12311
- }
12312
- if (disabled) {
12313
- service.disable(name);
12314
- disable();
12315
- }
12316
- else {
12317
- service.enable(name);
12318
- if (initializedRef.current === true) {
12319
- // we only use the enable method if this is a change and not a initialization
12320
- enable();
12321
- }
12322
- }
12323
- }
12324
- initializedRef.current = true;
12325
- }, [name, metadata.visible, metadata.disabled]);
12326
- // useEffect(() => {
12327
- // if (!visible) {
12328
- // if (disabled) {
12329
- // disable();
12330
- // } else {
12331
- // enable();
12332
- // }
12333
- // hide();
12334
- // } else {
12335
- // show();
12336
- // if (disabled) {
12337
- // disable();
12338
- // } else {
12339
- // enable();
12340
- // }
12341
- // }
12342
- // }, [visible, disabled, hide, show, disable, enable]);
12343
- return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Step, { ...stepProps, uid: name, onTouch: touchAllFields }) }));
12161
+ return accumulator;
12162
+ }, {});
12344
12163
  };
12345
-
12346
- const sliderStyle = () => {
12347
- return styled.css ``;
12164
+ const findQuickRangeLabel = (quickRanges, dateRange) => {
12165
+ if (!quickRanges || !dateRange)
12166
+ return;
12167
+ const dr = typeof dateRange === 'string' ? toDateRange(dateRange) : dateRange;
12168
+ if (dr === null)
12169
+ return;
12170
+ if (!dr.from || !dr.to)
12171
+ return;
12172
+ return Object.keys(quickRanges).find((label) => {
12173
+ return dr.from === quickRanges[label].from && dr.to === quickRanges[label].to;
12174
+ });
12348
12175
  };
12349
-
12350
- const SliderComponent = () => {
12351
- return null;
12176
+ const isSameDay = (date1, date2) => {
12177
+ return (date1.getFullYear() === date2.getFullYear() &&
12178
+ date1.getMonth() === date2.getMonth() &&
12179
+ date1.getDate() === date2.getDate());
12352
12180
  };
12353
12181
 
12354
- const Resizer = styled(SliderComponent) `
12355
- ${sliderStyle}
12356
- `;
12357
-
12358
- const columnCount = cssProperty('column-count');
12359
- const columnFill = cssProperty('column-fill');
12360
- const columnRule = cssProperty('column-rule');
12361
- const columnRuleColor = cssProperty(null, colorFormatter('column-rule-color'));
12362
- const columnRuleStyle = cssProperty('column-rule-style');
12363
- const columnRuleWidth = cssProperty('column-rule-width', pxFormatter);
12364
- const columnSpan = cssProperty('column-span');
12365
- const columnWidth = cssProperty('column-width', pxFormatter);
12366
- const columns = cssProperty('columns');
12367
- const grid = cssProperty('grid');
12368
- const gridAutoColumns = cssProperty('grid-auto-columns');
12369
- const gridAutoFlow = cssProperty('grid-auto-flow');
12370
- const gridAutoRows = cssProperty('grid-auto-rows');
12371
- const gridColumn = cssProperty('grid-column');
12372
- const gridColumnEnd = cssProperty('grid-column-start');
12373
- const gridColumnGap = columnGap;
12374
- const gridColumnStart = cssProperty('grid-column-start');
12375
- const gridGap = gap;
12376
- const gridRow = cssProperty('grid-row');
12377
- const gridRowEnd = cssProperty('grid-row-end');
12378
- const gridRowGap = rowGap;
12379
- const gridRowStart = cssProperty('grid-row-start');
12380
- const gridTemplate = cssProperty('grid-template');
12381
- const gridTemplateAreas = cssProperty('grid-template-areas');
12382
- const gridTemplateColumns = cssProperty('grid-template-columns');
12383
- const gridTemplateRows = cssProperty('grid-template-rows');
12384
-
12385
- const datePickerStyle = () => {
12386
- return styled.css `
12387
- .o-calendar {
12388
- ${width('300px')}
12389
- }
12390
- .o-calendar-month {
12391
- ${display('flex')}
12392
- ${alignItems('center')}
12393
- ${marginBottom('md')}
12394
- ${columnGap('sm')}
12395
- }
12396
-
12397
- .o-calendar-select-month {
12398
- ${width(24)}
12399
- }
12400
-
12401
- .o-calendar-select-year {
12402
- ${width(12)}
12182
+ const isCurrent = (d, year, month, day) => {
12183
+ return d.getFullYear() === year && d.getMonth() === month && d.getDate() === day;
12184
+ };
12185
+ const isActive = (date) => {
12186
+ return date.year !== undefined && date.month !== undefined && date.year !== undefined;
12187
+ };
12188
+ const inRange = (year, month, day, from, to) => {
12189
+ let fromDate;
12190
+ if (from.year !== undefined && from.month !== undefined && from.day !== undefined) {
12191
+ fromDate = new Date(`${from.year}-${from.month.padStart(2, '0')}-${String(from.day).padStart(2, '0')}`);
12403
12192
  }
12404
-
12405
- .o-calendar-day-container {
12406
- ${display('grid')}
12407
- ${color('light')}
12408
- ${gridTemplateColumns('repeat(7, 1fr)')}
12409
- grid-template-rows: repeat(7, min(30px));
12410
- ${rowGap('5px')}
12411
- ${columnGap('5px')}
12193
+ else {
12194
+ return false;
12412
12195
  }
12413
- .o-calendar-day-title {
12414
- ${display('flex')}
12415
- ${alignItems('center')}
12416
- ${justifyContent('center')}
12417
- ${color('dark')}
12196
+ let toDate;
12197
+ if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12198
+ toDate = new Date(`${to.year}-${to.month.padStart(2, '0')}-${String(to.day).padStart(2, '0')}`);
12418
12199
  }
12419
- .o-calendar-day {
12420
- ${display('flex')}
12421
- ${alignItems('center')}
12422
- ${justifyContent('center')}
12423
- ${cursor('pointer')}
12424
- ${borderRadius('md')}
12425
-
12426
- &:hover {
12427
- ${backgroundColor('darkest')}
12428
- ${color('white')}
12429
- }
12200
+ else {
12201
+ return false;
12430
12202
  }
12431
- .o-calendar-day-in-month {
12432
- ${color('darkest')}
12433
- ${backgroundColor('lighter')}
12203
+ let currentDate = new Date(`${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`);
12204
+ return (currentDate > fromDate && currentDate < toDate) || (currentDate < fromDate && currentDate > toDate);
12205
+ };
12206
+ const isInversedDate = (from, to) => {
12207
+ if (!isActive(from) || !isActive(to)) {
12208
+ return false;
12434
12209
  }
12435
- .o-calendar-day-current {
12436
- ${borderColor('darker')}
12437
- ${borderWidth('2px')}
12438
- ${borderStyle('solid')}
12439
- ${fontWeight('medium')}
12210
+ const fromDate = new Date(`${from.year}-${String(from.month ?? 0 + 1).padStart(2, '0')}-${String(from.day).padStart(2, '0')}`);
12211
+ const toDate = new Date(`${to.year}-${String(to.month ?? 0 + 1).padStart(2, '0')}-${String(to.day).padStart(2, '0')}`);
12212
+ return fromDate > toDate;
12213
+ };
12214
+ function getMonth(candidate, defaultValue) {
12215
+ if (typeof candidate === 'string') {
12216
+ candidate = parseInt(candidate) - 1;
12440
12217
  }
12441
-
12442
- .o-calendar-day-in-range {
12443
- ${backgroundColor('lightblue')}
12444
- ${borderRadius('none')}
12445
- ${color('white')}
12218
+ if (candidate === undefined || isNaN(candidate) || candidate < 0 || candidate > 11) {
12219
+ return defaultValue;
12446
12220
  }
12447
-
12448
- .o-calendar-day-in-range-transient {
12449
- ${backgroundColor('dark')}
12450
- ${borderRadius('none')}
12451
- ${color('white')}
12221
+ return candidate;
12222
+ }
12223
+ function getYear(candidate, min, max, defaultValue) {
12224
+ if (typeof candidate === 'string') {
12225
+ candidate = parseInt(candidate);
12452
12226
  }
12453
-
12454
- .o-calendar-day-start-range,
12455
- .o-calendar-day-start-range-transient {
12456
- ${borderTopRightRadius('none')}
12457
- ${borderBottomRightRadius('none')}
12227
+ if (candidate === undefined || isNaN(candidate) || candidate < min || candidate > max) {
12228
+ return defaultValue;
12458
12229
  }
12459
-
12460
- .o-calendar-day-end-range,
12461
- .o-calendar-day-end-range-transient {
12462
- ${borderTopLeftRadius('none')}
12463
- ${borderBottomLeftRadius('none')}
12230
+ return candidate;
12231
+ }
12232
+ const defaultMinDate = new Date();
12233
+ defaultMinDate.setFullYear(1900);
12234
+ const defaultMaxDate = new Date();
12235
+ defaultMaxDate.setFullYear(2100);
12236
+ const CalendarComponent = ({ from, to, type, minDate = defaultMinDate, maxDate = defaultMaxDate, nextSelectEdge, className, onChange, }) => {
12237
+ const maxYear = maxDate.getFullYear();
12238
+ const minYear = minDate.getFullYear();
12239
+ const years = React.useRef([...Array(maxYear).keys()].slice(minYear));
12240
+ const d = new Date();
12241
+ const lastExternalFromMonth = React.useRef(from['month']);
12242
+ const lastExternalFromYear = React.useRef(from['year']);
12243
+ const lastExternalToMonth = React.useRef(to['month']);
12244
+ const lastExternalToYear = React.useRef(to['year']);
12245
+ const fromMonth = getMonth(from['month']);
12246
+ const fromYear = getYear(from['year'], minYear, maxYear);
12247
+ const fromDay = from['day'] === undefined ? undefined : parseInt(`${from['day']}`);
12248
+ const [internalTo, setInternalTo] = React.useState({});
12249
+ let transientTo = false;
12250
+ let toMonth, toYear, toDay;
12251
+ let isInversed = false;
12252
+ if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12253
+ toMonth = getMonth(to.month);
12254
+ toYear = getYear(to.year, minYear, maxYear);
12255
+ toDay = parseInt(`${to.day}`);
12464
12256
  }
12465
-
12466
- .o-datepicker-dropdown-content {
12467
- ${borderRadius('sm')}
12468
- ${borderTopLeftRadius(0)}
12469
- ${borderTopRightRadius(0)}
12470
- ${boxShadow('lg')}
12471
- ${zIndex(2000)}
12472
- ${backgroundColor('white')}
12473
- ${borderWidth(1)}
12474
- ${borderColor('light')}
12475
- ${marginTop('-1px')}
12476
- ${padding('lg')}
12477
- ${userSelect('none')}
12478
- ${display('flex')}
12257
+ else {
12258
+ toMonth = getMonth(internalTo.month);
12259
+ toYear = getYear(internalTo.year, minYear, maxYear);
12260
+ toDay = parseInt(`${internalTo.day}`);
12261
+ transientTo = true;
12262
+ isInversed = isInversedDate(from, internalTo);
12479
12263
  }
12480
-
12481
- .o-datepicker-active {
12482
- .o-calendar-day-active {
12483
- ${color('white')}
12484
- ${backgroundColor('primary')}
12485
- ${fontWeight('medium')}
12486
- &.o-calendar-day-end-range-transient {
12487
- ${backgroundColor('darkest')}
12488
- &.o-calendar-day-start-range {
12489
- ${backgroundColor('primary')}
12490
- }
12491
- }
12492
- &.o-calendar-day-start-range-transient {
12493
- ${backgroundColor('darkest')}
12264
+ const [currentMonth, setCurrentMonth] = React.useState(getMonth(from['month'], d.getMonth()));
12265
+ const [currentYear, setCurrentYear] = React.useState(getYear(from['year'], minYear, maxYear, d.getFullYear()));
12266
+ const firstDayOfExternalFromMonth = fromMonth && fromYear ? new Date(`${fromYear}-${String(getMonth(fromMonth + 1)).padStart(2, '0')}-01`) : undefined;
12267
+ const firstDayOfExternalToMonth = toMonth && toYear ? new Date(`${toYear}-${String(toMonth + 1).padStart(2, '0')}-01`) : undefined;
12268
+ const firstDayOfCurrentMonth = new Date(`${currentYear}-${String(currentMonth + 1).padStart(2, '0')}-01`);
12269
+ const lastDayOfPreviousMonth = new Date(firstDayOfCurrentMonth);
12270
+ lastDayOfPreviousMonth.setDate(lastDayOfPreviousMonth.getDate() - 1);
12271
+ const lastDayOfCurrentMonth = new Date(firstDayOfCurrentMonth);
12272
+ lastDayOfCurrentMonth.setMonth(lastDayOfCurrentMonth.getMonth() + 1);
12273
+ lastDayOfCurrentMonth.setDate(lastDayOfCurrentMonth.getDate() - 1);
12274
+ const firstDayOfNextMonth = new Date(firstDayOfCurrentMonth);
12275
+ firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
12276
+ let calendarDays = firstDayOfCurrentMonth.getDate() === 0 || firstDayOfCurrentMonth.getDay() === 0
12277
+ ? []
12278
+ : [...Array(lastDayOfPreviousMonth.getDate() + 1).keys()].slice(-firstDayOfCurrentMonth.getDay()).map((n) => {
12279
+ const startRange = fromDay === n &&
12280
+ lastDayOfPreviousMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12281
+ lastDayOfPreviousMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12282
+ const endRange = toDay === n &&
12283
+ lastDayOfPreviousMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12284
+ lastDayOfPreviousMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12285
+ return {
12286
+ day: n,
12287
+ active: startRange || endRange,
12288
+ current: isCurrent(d, lastDayOfPreviousMonth.getFullYear(), lastDayOfPreviousMonth.getMonth(), n),
12289
+ month: lastDayOfPreviousMonth.getMonth(),
12290
+ year: lastDayOfPreviousMonth.getFullYear(),
12291
+ startRange: startRange && type.range,
12292
+ endRange: isActive(from) && endRange && type.range,
12293
+ inRange: type.range &&
12294
+ inRange(lastDayOfPreviousMonth.getFullYear(), lastDayOfPreviousMonth.getMonth(), n, from, transientTo ? internalTo : to),
12295
+ };
12296
+ });
12297
+ calendarDays = calendarDays.concat([...Array(lastDayOfCurrentMonth.getDate() + 1).keys()].slice(1).map((n) => {
12298
+ const startRange = fromDay === n &&
12299
+ lastDayOfCurrentMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12300
+ lastDayOfCurrentMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12301
+ const endRange = toDay === n &&
12302
+ lastDayOfCurrentMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12303
+ lastDayOfCurrentMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12304
+ return {
12305
+ day: n,
12306
+ active: startRange || endRange,
12307
+ current: isCurrent(d, lastDayOfCurrentMonth.getFullYear(), lastDayOfCurrentMonth.getMonth(), n),
12308
+ month: lastDayOfCurrentMonth.getMonth(),
12309
+ year: lastDayOfCurrentMonth.getFullYear(),
12310
+ startRange: startRange && type.range,
12311
+ endRange: isActive(from) && endRange && type.range,
12312
+ inRange: type.range &&
12313
+ inRange(lastDayOfCurrentMonth.getFullYear(), lastDayOfCurrentMonth.getMonth(), n, from, transientTo ? internalTo : to),
12314
+ };
12315
+ }));
12316
+ calendarDays = calendarDays.concat(lastDayOfCurrentMonth.getDay() === 6
12317
+ ? []
12318
+ : [...Array(6 - lastDayOfCurrentMonth.getDay() + 1).keys()].slice(1).map((n) => {
12319
+ const startRange = fromDay === n &&
12320
+ firstDayOfNextMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12321
+ firstDayOfNextMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12322
+ const endRange = toDay === n &&
12323
+ firstDayOfNextMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12324
+ firstDayOfNextMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12325
+ return {
12326
+ day: n,
12327
+ active: startRange || endRange,
12328
+ current: isCurrent(d, firstDayOfNextMonth.getFullYear(), firstDayOfNextMonth.getMonth(), n),
12329
+ month: firstDayOfNextMonth.getMonth(),
12330
+ year: firstDayOfNextMonth.getFullYear(),
12331
+ startRange: startRange && type.range,
12332
+ endRange: isActive(from) && endRange && type.range,
12333
+ inRange: type.range &&
12334
+ inRange(firstDayOfNextMonth.getFullYear(), firstDayOfNextMonth.getMonth(), n, from, transientTo ? internalTo : to),
12335
+ };
12336
+ }));
12337
+ React.useEffect(() => {
12338
+ if (type.range && to['month'] !== lastExternalToMonth.current) {
12339
+ // the user has changed the toMonth from the input field
12340
+ // we move the calendar to this month if it's a valid month
12341
+ lastExternalToMonth.current = to['month'];
12342
+ setCurrentMonth(getMonth(to['month'], currentMonth));
12494
12343
  }
12495
- }
12496
- }
12497
-
12498
- .o-datepicker-input {
12499
- input:read-only {
12500
- ${cursor('pointer')}
12501
- }
12502
- }
12503
-
12504
- .o-datepicker-icon {
12505
- ${cursor('pointer')}
12506
- ${display('flex')}
12507
- ${alignItems('center')}
12508
- }
12344
+ if (type.range && to['year'] !== lastExternalToYear.current) {
12345
+ // the user has changed the toYear from the input field
12346
+ // we move the calendar to this year if it's a valid year
12347
+ lastExternalToYear.current = to['year'];
12348
+ setCurrentYear(getYear(to['year'], minYear, maxYear, currentYear));
12349
+ }
12350
+ if (from['month'] !== lastExternalFromMonth.current) {
12351
+ // the user has changed the fromMonth from the input field
12352
+ // we move the calendar to this month if it's a valid month
12353
+ lastExternalFromMonth.current = from['month'];
12354
+ setCurrentMonth(getMonth(from['month'], currentMonth));
12355
+ }
12356
+ if (from['year'] !== lastExternalFromYear.current) {
12357
+ // the user has changed the fromYear from the input field
12358
+ // we move the calendar to this year if it's a valid year
12359
+ lastExternalFromYear.current = from['year'];
12360
+ setCurrentYear(getYear(from['year'], minYear, maxYear, currentYear));
12361
+ }
12362
+ });
12363
+ return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-calendar-container', className), children: [jsxRuntimeExports.jsxs("div", { className: "o-calendar-month", children: [jsxRuntimeExports.jsx(TogglerIcon, { width: "20px", closeArrowPosition: "w", onClick: () => {
12364
+ if (fromMonth === 0) {
12365
+ setCurrentMonth(11);
12366
+ setCurrentYear(currentYear - 1);
12367
+ }
12368
+ else {
12369
+ setCurrentMonth(currentMonth - 1);
12370
+ }
12371
+ } }, "previous"), jsxRuntimeExports.jsx(Select, { dataSource: months, nullable: false, value: months[currentMonth], className: "o-calendar-select-month", size: "small", onChange: (value) => setCurrentMonth(months.indexOf(`${value}`)) }, "month"), jsxRuntimeExports.jsx(Select, { dataSource: years.current, value: currentYear, nullable: false, className: "o-calendar-select-year", size: "small", onChange: (value) => setCurrentYear(parseInt(`${value}`)) }, "year"), jsxRuntimeExports.jsx(TogglerIcon, { width: "20px", closeArrowPosition: "e", onClick: () => {
12372
+ if (fromMonth === 11) {
12373
+ setCurrentMonth(0);
12374
+ setCurrentYear(currentYear + 1);
12375
+ }
12376
+ else {
12377
+ setCurrentMonth(currentMonth + 1);
12378
+ }
12379
+ } }, "next")] }), jsxRuntimeExports.jsxs("div", { className: "o-calendar-day-container", children: [days.map((day) => (jsxRuntimeExports.jsx("div", { className: "o-calendar-day-title", children: day.substring(0, 2) }, `${day}`))), calendarDays.map((calendarDay, index) => (jsxRuntimeExports.jsx("div", { className: `o-calendar-day${calendarDay.endRange
12380
+ ? ` o-calendar-day-${isInversed ? 'start' : 'end'}-range${transientTo ? '-transient' : ''}`
12381
+ : ''}${calendarDay.startRange ? ` o-calendar-day-${isInversed ? 'end' : 'start'}-range` : ''}${calendarDay.active ? ' o-calendar-day-active' : ''}${calendarDay.inRange ? ` o-calendar-day-in-range${transientTo ? '-transient' : ''}` : ''}${calendarDay.month === currentMonth ? ' o-calendar-day-in-month' : ''}${calendarDay.current ? ' o-calendar-day-current' : ''}`, onClick: () => {
12382
+ const nextDateString = `${calendarDay.year}-${String(calendarDay.month + 1).padStart(2, '0')}-${String(calendarDay.day).padStart(2, '0')}`;
12383
+ if (type.range && from.year !== undefined && from.month !== undefined && from.day !== undefined) {
12384
+ // It's a date range and not the first selection
12385
+ // We must determine if it's a change for the from or the to
12386
+ const fromDateString = `${from.year}-${from.month.padStart(2, '0')}-${String(from.day).padStart(2, '0')}`;
12387
+ const fromDate = new Date(fromDateString);
12388
+ let endDate = undefined;
12389
+ let endDateString = undefined;
12390
+ if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12391
+ // it's not the second click
12392
+ endDateString = `${to.year}-${to.month.padStart(2, '0')}-${String(to.day).padStart(2, '0')}`;
12393
+ endDate = new Date(endDateString);
12394
+ }
12395
+ const nextDate = new Date(nextDateString);
12396
+ if (endDate) {
12397
+ // case when we click on the same day than the fromDate
12398
+ if (isSameDay(fromDate, nextDate)) {
12399
+ if (nextDate <= fromDate) {
12400
+ onChange(nextDateString, fromDateString);
12401
+ }
12402
+ else {
12403
+ onChange(fromDateString, nextDateString);
12404
+ }
12405
+ }
12406
+ // case when we click on the same day than the endDate
12407
+ else if (isSameDay(endDate, nextDate)) {
12408
+ if (nextDate <= endDate) {
12409
+ onChange(nextDateString, endDateString);
12410
+ }
12411
+ else {
12412
+ onChange(endDateString, nextDateString);
12413
+ }
12414
+ }
12415
+ else if (nextDate <= fromDate) {
12416
+ onChange(nextDateString, endDateString);
12417
+ }
12418
+ else if (nextDate >= endDate) {
12419
+ onChange(fromDateString, nextDateString);
12420
+ }
12421
+ else if (nextSelectEdge === 'from') {
12422
+ onChange(nextDateString, endDateString);
12423
+ }
12424
+ else {
12425
+ onChange(fromDateString, nextDateString);
12426
+ }
12427
+ }
12428
+ else if (nextDate <= fromDate) {
12429
+ onChange(nextDateString, fromDateString);
12430
+ }
12431
+ else {
12432
+ onChange(fromDateString, nextDateString);
12433
+ }
12434
+ }
12435
+ else {
12436
+ // we assume that it's not a range or the first selection of the range
12437
+ onChange(nextDateString);
12438
+ }
12439
+ }, onMouseEnter: () => {
12440
+ if (transientTo) {
12441
+ setInternalTo({
12442
+ year: `${calendarDay.year}`,
12443
+ month: String(calendarDay.month + 1).padStart(2, '0'),
12444
+ day: String(calendarDay.day).padStart(2, '0'),
12445
+ });
12446
+ }
12447
+ }, children: calendarDay.day }, `${fromDay}-${index}`)))] })] }));
12448
+ };
12509
12449
 
12510
- .o-datepicker-remover {
12511
- ${cursor('pointer')}
12512
- ${color('light')}
12513
- ${fontFamily('Arial')}
12514
- ${paddingX('sm')}
12515
- ${userSelect('none')}
12516
- }
12450
+ const QuickTimeRangeComponent = ({ quickRanges, onChange, currentQuickRangeLabel, }) => {
12451
+ return (jsxRuntimeExports.jsxs("div", { className: "o-quick-time-range-container", children: [jsxRuntimeExports.jsx("div", { className: "o-quick-time-range-title", children: "Quick select" }), Object.keys(quickRanges).map((quickRangeLabel, index) => {
12452
+ return (jsxRuntimeExports.jsx("div", { className: `o-quick-time-range${currentQuickRangeLabel === quickRangeLabel ? ' o-quick-time-range-selected' : ''}`, onClick: () => onChange(quickRangeLabel), children: quickRangeLabel }, `qr-${index}`));
12453
+ })] }));
12454
+ };
12517
12455
 
12518
- .o-toggler-icon {
12519
- ${cursor('pointer')}
12520
- ${color('primary')}
12456
+ const getNextValue = (value, max, type) => {
12457
+ const valueInt = parseInt(`${value}`);
12458
+ let result = 0;
12459
+ if (type === 'next') {
12460
+ if (isNaN(valueInt) || valueInt === max) {
12461
+ result = 0;
12462
+ }
12463
+ else {
12464
+ result = valueInt + 1;
12465
+ }
12521
12466
  }
12522
-
12523
- .o-time-selector-part-icon-disabled {
12524
- .o-toggler-icon {
12525
- ${cursor('not-allowed')}
12526
- ${color('light')}
12527
- }
12467
+ else if (type === 'previous') {
12468
+ if (isNaN(valueInt)) {
12469
+ result = 0;
12470
+ }
12471
+ else if (valueInt === 0) {
12472
+ result = max;
12473
+ }
12474
+ else {
12475
+ result = valueInt - 1;
12476
+ }
12528
12477
  }
12529
-
12530
- .o-time-container {
12531
- ${marginLeft('xl')}
12532
- .o-time-separator {
12533
- ${marginX('lg')}
12534
- }
12535
- }
12536
-
12537
- .o-time-selector {
12538
- ${display('flex')}
12539
- ${alignItems('center')}
12478
+ return String(result).padStart(2, '0');
12479
+ };
12480
+ const isMin = (value, _type) => {
12481
+ return parseInt(`${value}`) === 0;
12482
+ };
12483
+ const isMax = (value, type) => {
12484
+ return type === 'hour' ? parseInt(`${value}`) === 23 : parseInt(`${value}`) === 59;
12485
+ };
12486
+ const headerValue = (type) => {
12487
+ switch (type) {
12488
+ case 'hour':
12489
+ return 'HH';
12490
+ case 'minute':
12491
+ return 'MM';
12492
+ case 'second':
12493
+ return 'SS';
12494
+ default:
12495
+ return '';
12540
12496
  }
12497
+ };
12498
+ const TimeSelectorPartComponent = ({ onChange, type, value, size = 'large', displayHeaders = false, }) => {
12499
+ const onValueChange = (e) => {
12500
+ let value = e.target.value;
12501
+ if (type === 'minute' && (value === '' || isValidMinuteOrSecond(value))) {
12502
+ onChange(value);
12503
+ }
12504
+ else if (type === 'second' && (value === '' || isValidMinuteOrSecond(value))) {
12505
+ onChange(value);
12506
+ }
12507
+ else if (type === 'hour' && (value === '' || isValidHour(value))) {
12508
+ onChange(value);
12509
+ }
12510
+ };
12511
+ return (jsxRuntimeExports.jsxs("div", { className: `o-time-selector-part o-time-selector-part-${size} o-time-${type}`, children: [displayHeaders && jsxRuntimeExports.jsx("div", { className: "o-time-selector-part-header", children: headerValue(type) }), jsxRuntimeExports.jsx(TogglerIcon, { className: isMin(value) ? 'o-time-selector-part-icon-disabled' : undefined, width: "20px", closeArrowPosition: "n", onClick: () => {
12512
+ if (!isMin(value)) {
12513
+ onChange(getNextValue(value, type === 'hour' ? 23 : 59, 'previous'));
12514
+ }
12515
+ } }, "previous"), jsxRuntimeExports.jsx(Input, { className: "o-time-input", value: value, size: size, selectOnFocus: true, onChange: onValueChange }, "value"), jsxRuntimeExports.jsx(TogglerIcon, { className: isMax(value, type) ? 'o-time-selector-part-icon-disabled' : undefined, width: "20px", closeArrowPosition: "s", onClick: () => {
12516
+ if (!isMax(value, type)) {
12517
+ onChange(getNextValue(value, type === 'hour' ? 23 : 59, 'next'));
12518
+ }
12519
+ } }, "next")] }));
12520
+ };
12541
12521
 
12542
- .o-time-edge-title {
12543
- ${fontWeight('bold')}
12544
- ${marginBottom('xs')}
12545
- ${borderBottomWidth('1px')}
12546
- ${borderBottomColor('lighter')}
12547
- ${borderBottomStyle('solid')}
12548
- ${textTransform('uppercase')}
12549
- ${color('primary')}
12522
+ const getValue = (candidate, max, defaultValue) => {
12523
+ if (typeof candidate === 'string') {
12524
+ candidate = parseInt(candidate);
12550
12525
  }
12551
-
12552
- .o-time-edge-empty {
12553
- ${color('dark')}
12554
- ${fontStyle('italic')}
12555
- ${marginTop('md')}
12526
+ if (candidate === undefined || isNaN(candidate) || candidate < 0 || candidate > max) {
12527
+ return defaultValue;
12556
12528
  }
12529
+ return candidate;
12530
+ };
12531
+ const TimeSelectorComponent = ({ value, onChange, size, edge, displayHours, displayMinutes, displaySeconds, displayHeaders, }) => {
12532
+ const d = new Date();
12533
+ const hourInt = getValue(value.hour, 23, displayHours ? d.getHours() : 0);
12534
+ const minuteInt = getValue(value.minute, 59, displayMinutes ? d.getMinutes() : 0);
12535
+ const secondInt = getValue(value.second, 59, displaySeconds ? d.getSeconds() : 0);
12536
+ const [internalHour, setInternalHour] = React.useState(String(hourInt).padStart(2, '0'));
12537
+ const [internalMinute, setInternalMinute] = React.useState(String(minuteInt).padStart(2, '0'));
12538
+ const [internalSecond, setInternalSecond] = React.useState(String(secondInt).padStart(2, '0'));
12539
+ const hour = internalHour === '' ? '' : parseInt(internalHour) === hourInt ? internalHour : hourInt;
12540
+ const minute = internalMinute === '' ? '' : parseInt(internalMinute) === minuteInt ? internalMinute : minuteInt;
12541
+ const second = internalSecond === '' ? '' : parseInt(internalSecond) === secondInt ? internalSecond : secondInt;
12542
+ const onChangeHour = React.useCallback((value) => {
12543
+ setInternalHour(value);
12544
+ if (value !== '') {
12545
+ onChange(`${String(value || 0).padStart(2, '0')}:${String(minute || 0).padStart(2, '0')}:${String(second || 0).padStart(2, '0')}`, edge);
12546
+ }
12547
+ }, [minute, second, onChange]);
12548
+ const onChangeMinute = React.useCallback((value) => {
12549
+ setInternalMinute(value);
12550
+ if (value !== '') {
12551
+ onChange(`${String(hour || 0).padStart(2, '0')}:${String(value || 0).padStart(2, '0')}:${String(second || 0).padStart(2, '0')}`, edge);
12552
+ }
12553
+ }, [hour, second, onChange]);
12554
+ const onChangeSecond = React.useCallback((value) => {
12555
+ setInternalSecond(value);
12556
+ if (value !== '') {
12557
+ onChange(`${String(hour || 0).padStart(2, '0')}:${String(minute || 0).padStart(2, '0')}:${String(value || 0).padStart(2, '0')}`, edge);
12558
+ }
12559
+ }, [hour, minute, onChange]);
12560
+ return (jsxRuntimeExports.jsxs("div", { className: "o-time-selector", children: [displayHours && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "hour", value: hour, onChange: onChangeHour, size: size, displayHeaders: displayHeaders }, "hour")), displayHours && (displayMinutes || displaySeconds) && (jsxRuntimeExports.jsx("span", { className: "o-time-separator", children: ":" }, "sep1")), displayMinutes && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "minute", value: minute, onChange: onChangeMinute, size: size, displayHeaders: displayHeaders }, "minute")), displaySeconds && (displayHours || displayMinutes) && (jsxRuntimeExports.jsx("span", { className: "o-time-separator", children: ":" }, "sep2")), displaySeconds && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "second", value: second, onChange: onChangeSecond, size: size, displayHeaders: displayHeaders }, "second"))] }));
12561
+ };
12557
12562
 
12558
- .o-time-edge-date-container {
12559
- ${width('150px')}
12563
+ const TimeRangeComponent = ({ edge, onChange, value, displayHours, displayMinutes, displaySeconds, displayHeaders, }) => {
12564
+ const valid = isValidDate(`${value.day}-${value.month}-${value.year}`);
12565
+ let d;
12566
+ if (valid) {
12567
+ d = new Date(`${value.year}-${value.month}-${value.day}`);
12560
12568
  }
12569
+ const label = edge === 'to' ? 'an end' : 'a start';
12570
+ return (jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx("div", { className: "o-time-edge-title", children: onekijsFramework.ucfirst(edge) }, "title"), !valid && (jsxRuntimeExports.jsxs("div", { className: "o-time-edge-empty", children: ["Please select ", label, " date for the period"] }, "empty")), valid && d && (jsxRuntimeExports.jsxs("div", { className: "o-time-edge-content", children: [jsxRuntimeExports.jsx("div", { className: "o-time-edge-date-container", children: jsxRuntimeExports.jsx("span", { className: "o-time-edge-date", children: d.toUTCString().split(' ', 4).join(' ') }) }, "date"), jsxRuntimeExports.jsx(TimeSelectorComponent, { value: value, onChange: onChange, size: "small", edge: edge, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds, displayHeaders: displayHeaders }, "selector")] }, "content"))] }));
12571
+ };
12561
12572
 
12562
- .o-time-edge-date {
12563
- ${fontWeight('medium')}
12564
- ${backgroundColor('lightest')}
12565
- ${paddingX('sm')}
12566
- ${marginRight('md')}
12567
- ${whiteSpace('nowrap')}
12573
+ const TimeComponent = ({ from, to, type, className, onChange, displayHours, displayMinutes, displaySeconds, }) => {
12574
+ if (type['range'] && type['date']) {
12575
+ return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-time-container-range', className), children: [jsxRuntimeExports.jsx(TimeRangeComponent, { type: type, value: from, edge: "from", onChange: onChange, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds, displayHeaders: false }), jsxRuntimeExports.jsx(TimeRangeComponent, { type: type, value: to, edge: "to", onChange: onChange, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds, displayHeaders: false })] }));
12568
12576
  }
12577
+ return (jsxRuntimeExports.jsx("div", { className: addClassname('o-time-container', className), children: jsxRuntimeExports.jsx(TimeSelectorComponent, { value: from, onChange: onChange, size: "large", edge: "from", displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds, displayHeaders: true }, "selector") }));
12578
+ };
12569
12579
 
12570
- .o-time-container-range {
12571
- ${marginLeft('3xl')}
12572
- ${marginTop('2xl')}
12573
- ${display('flex')}
12574
- ${flexDirection('column')}
12575
- ${gap('xl')}
12576
- .o-time-separator {
12577
- ${marginX('sm')}
12578
- }
12580
+ const IconComponent = () => {
12581
+ const { nullable, setOpen, onChange, open } = useDatePickerContext();
12582
+ return (jsxRuntimeExports.jsxs("span", { className: "o-datepicker-icon", children: [nullable && (jsxRuntimeExports.jsx("div", { className: "o-datepicker-remover", onClick: () => {
12583
+ onChange(null);
12584
+ setOpen(false);
12585
+ }, children: "\u2716" })), jsxRuntimeExports.jsx(CalendarIcon, { width: "20px", height: "20px", color: "primary", marginRight: "sm", onClick: () => setOpen(!open) })] }));
12586
+ };
12587
+ const parseDate = (value) => {
12588
+ let date, time, year, month, day, hour, minute, second = undefined;
12589
+ if (value) {
12590
+ [date, time] = value.trim().split(' ');
12591
+ [year, month, day] = date ? date.split('-') : [undefined, undefined, undefined];
12592
+ [hour, minute, second] = time ? time.split(':') : [undefined, undefined, undefined];
12579
12593
  }
12580
-
12581
- .o-time-edge-content {
12582
- ${display('flex')}
12583
- ${alignItems('center')}
12594
+ return { date, time, year, month, day, hour, minute, second };
12595
+ };
12596
+ const isValidValue = (value, type) => {
12597
+ const isValidDate = (value) => {
12598
+ const d = new Date(value);
12599
+ return !isNaN(d);
12600
+ };
12601
+ if (!value)
12602
+ return true;
12603
+ if (type.range) {
12604
+ const [from, to] = value.split(' to ');
12605
+ if (!from || !to)
12606
+ return false;
12607
+ return isValidDate(from) && isValidDate(to);
12584
12608
  }
12585
-
12586
- .o-time-separator {
12587
- ${fontWeight('bold')}
12609
+ else {
12610
+ return isValidDate(value);
12588
12611
  }
12589
-
12590
- .o-time-input {
12591
- ${width(10)}
12592
- .o-input-field {
12593
- ${textAlign('center')}
12594
- }
12612
+ };
12613
+ const isSameDate = (d1, d2, type) => {
12614
+ const isSameDate = (d1, d2) => {
12615
+ if (!d1 && !d2)
12616
+ return true;
12617
+ if (!d1 || !d2)
12618
+ return false;
12619
+ const date1 = new Date(`${d1}`);
12620
+ const date2 = new Date(`${d2}`);
12621
+ if (isNaN(date1) || isNaN(date2)) {
12622
+ return false;
12623
+ }
12624
+ return date1.toString() === date2.toString();
12625
+ };
12626
+ if (d1 === null && d2 === null)
12627
+ return true;
12628
+ if (!d1 || !d2)
12629
+ return false;
12630
+ if (type.range) {
12631
+ const [from1, to1] = d1.split(' to ');
12632
+ const [from2, to2] = d2.split(' to ');
12633
+ return isSameDate(from1, from2) && isSameDate(to1, to2);
12595
12634
  }
12596
-
12597
- .o-time-selector-part {
12598
- ${display('flex')}
12599
- ${flexDirection('column')}
12600
- ${alignItems('center')}
12635
+ else {
12636
+ return isSameDate(d1, d2);
12601
12637
  }
12602
-
12603
- .o-time-selector-part-large.o-toggler-icon-container {
12604
- ${marginY('md')}
12638
+ };
12639
+ const formatDate = (type, fromDate, fromTime, toDate, toTime) => {
12640
+ const format = (date, time) => {
12641
+ let result = '';
12642
+ if (type.date) {
12643
+ result += `${date || ''}`;
12644
+ }
12645
+ if (type.time) {
12646
+ if (type.date && date) {
12647
+ result += ` ${time || '00:00:00'}`;
12648
+ }
12649
+ else if (type.date && time) {
12650
+ result += ` ${time}`;
12651
+ }
12652
+ else if (time) {
12653
+ result += time;
12654
+ }
12655
+ }
12656
+ return result;
12657
+ };
12658
+ let result = format(fromDate, fromTime);
12659
+ if (type.range) {
12660
+ result += ` to ${format(toDate, toTime)}`;
12605
12661
  }
12606
-
12607
- .o-quick-time-range-container {
12608
- ${paddingRight('2xl')}
12609
- ${marginTop('2xl')}
12610
- ${marginX('md')}
12662
+ return result;
12663
+ };
12664
+ const PickerComponent = ({ animationMs = 100, attachDropdownToBody = true, autoFocus, className, closeOnQuickSelect = true, combo = false, disabled, dropdownWidthModifier = 'min', label, nullable = false, onBlur: forwardBlur, onChange: forwardChange, onFocus: forwardFocus, openOnFocus = false, placeholder, placement = 'bottom-start', quickRanges, type, displayHours = true, displayMinutes = true, displaySeconds = true, value: externalValue, }) => {
12665
+ const containerRef = React.useRef(null);
12666
+ const stateRef = React.useRef({});
12667
+ const dropdownRef = React.useRef(null);
12668
+ const lastExternalValueRef = React.useRef(undefined);
12669
+ const currentValueRef = React.useRef(null);
12670
+ const [open, setOpen] = React.useState(false);
12671
+ const [focus, setFocus] = React.useState(false);
12672
+ const [Dropdown, triggerRef] = useDropdown();
12673
+ const [internalValue, setInternalValue] = React.useState(null);
12674
+ let value = internalValue ? internalValue : externalValue;
12675
+ if (currentValueRef.current !== value && isSameDate(currentValueRef.current, value, type)) {
12676
+ value = currentValueRef.current;
12611
12677
  }
12612
-
12613
- .o-quick-time-range-title {
12614
- ${fontWeight('bold')}
12678
+ const [fromString, toString] = value ? value.split(/ to\s*/) : [];
12679
+ const validFromRef = React.useRef(undefined);
12680
+ const validToRef = React.useRef(undefined);
12681
+ if (!fromString || /\s*/.test(fromString)) {
12682
+ validFromRef.current = undefined;
12615
12683
  }
12616
-
12617
- .o-quick-time-range {
12618
- ${cursor('pointer')}
12619
- ${fontWeight('medium')}
12620
- ${color('primary')}
12621
- &.o-quick-time-range-selected {
12622
- ${cursor('auto')}
12623
- ${fontWeight('bold')}
12624
- ${color('pink')}
12625
- }
12684
+ if (!toString || /\s*/.test(toString)) {
12685
+ validToRef.current = undefined;
12626
12686
  }
12627
- `;
12628
- };
12629
-
12630
- const months = [
12631
- 'January',
12632
- 'February',
12633
- 'March',
12634
- 'April',
12635
- 'May',
12636
- 'June',
12637
- 'July',
12638
- 'August',
12639
- 'September',
12640
- 'October',
12641
- 'November',
12642
- 'December',
12643
- ];
12644
- const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
12645
- const isValidDate = (value) => {
12646
- if (!value)
12647
- return false;
12648
- return /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/.test(value);
12649
- };
12650
- const isValidTime = (value) => {
12651
- if (!value)
12652
- return false;
12653
- return /^(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])$/.test(value);
12654
- };
12655
- const isValidMinuteOrSecond = (value) => {
12656
- if (!value)
12657
- return false;
12658
- return /^(0?|[1-5])[0-9]$/.test(value);
12659
- };
12660
- const isValidHour = (value) => {
12661
- if (!value)
12662
- return false;
12663
- return /^(2[0-3]|0?[0-9]|1[0-9])$/.test(value);
12687
+ // this setting is used to detect if the user changes the from or the to
12688
+ const nextSelectEdgeRef = React.useRef('to');
12689
+ const from = parseDate(fromString?.trim());
12690
+ const previousFrom = parseDate(validFromRef.current);
12691
+ if (!type['date'] || !isValidDate(`${from['day']}-${from['month']}-${from['year']}`)) {
12692
+ from.year = previousFrom.year;
12693
+ from.month = previousFrom.month;
12694
+ from.day = previousFrom.day;
12695
+ from.date = previousFrom.date;
12696
+ }
12697
+ if (type['date'] && isValidDate(`${from['day']}-${from['month']}-${from['year']}`)) {
12698
+ validFromRef.current = `${from['year']}-${from['month']}-${from['day']}`;
12699
+ }
12700
+ if (!type['time'] || !isValidTime(from['time'])) {
12701
+ from.hour = previousFrom.hour;
12702
+ from.minute = previousFrom.minute;
12703
+ from.second = previousFrom.second;
12704
+ from.time = previousFrom.time;
12705
+ }
12706
+ if (type['time'] && isValidTime(`${from['time']}`)) {
12707
+ if (validFromRef.current === undefined) {
12708
+ validFromRef.current = '';
12709
+ }
12710
+ if (type['date']) {
12711
+ validFromRef.current += ' ';
12712
+ }
12713
+ validFromRef.current += `${from['time']}`;
12714
+ }
12715
+ const to = parseDate(toString?.trim());
12716
+ const previousTo = parseDate(validToRef.current);
12717
+ if (!type['date'] || !isValidDate(`${to['day']}-${to['month']}-${to['year']}`)) {
12718
+ to.year = previousTo.year;
12719
+ to.month = previousTo.month;
12720
+ to.day = previousTo.day;
12721
+ to.date = previousTo.date;
12722
+ }
12723
+ if (type['date'] && isValidDate(`${to['day']}-${to['month']}-${to['year']}`)) {
12724
+ validToRef.current = `${to['year']}-${to['month']}-${to['day']}`;
12725
+ }
12726
+ if (!type['time'] || !isValidTime(to['time'])) {
12727
+ to.hour = previousTo.hour;
12728
+ to.minute = previousTo.minute;
12729
+ to.second = previousTo.second;
12730
+ to.time = previousTo.time;
12731
+ }
12732
+ if (type['time'] && isValidTime(`${to['time']}`)) {
12733
+ if (validToRef.current === undefined) {
12734
+ validToRef.current = '';
12735
+ }
12736
+ if (type['date']) {
12737
+ validToRef.current += ' ';
12738
+ }
12739
+ validToRef.current += `${to['time']}`;
12740
+ }
12741
+ const id = React.useId();
12742
+ const onFocus = React.useCallback(() => {
12743
+ if (!focus) {
12744
+ setFocus(true);
12745
+ if (openOnFocus && !open) {
12746
+ setOpen(true);
12747
+ }
12748
+ if (forwardFocus) {
12749
+ forwardFocus();
12750
+ }
12751
+ }
12752
+ }, [focus, forwardFocus, openOnFocus, open]);
12753
+ const onBlur = React.useCallback(() => {
12754
+ if (!stateRef.current.keepFocus) {
12755
+ if (open) {
12756
+ setOpen(false);
12757
+ }
12758
+ if (focus) {
12759
+ setFocus(false);
12760
+ if (forwardBlur) {
12761
+ forwardBlur();
12762
+ }
12763
+ }
12764
+ }
12765
+ }, [open, forwardBlur, setOpen, focus]);
12766
+ const onChange = React.useCallback((nextValue, label) => {
12767
+ currentValueRef.current = nextValue;
12768
+ // check if the nextValue is a valid value
12769
+ // if it's not a valid value, we keep it internally
12770
+ if (forwardChange && isValidValue(nextValue, type)) {
12771
+ setInternalValue(null);
12772
+ forwardChange(nextValue, label);
12773
+ }
12774
+ else {
12775
+ setInternalValue(nextValue);
12776
+ }
12777
+ }, [forwardChange, setInternalValue, type]);
12778
+ const onChangeDate = (fromDate, toDate) => {
12779
+ if (fromDate === undefined) {
12780
+ fromDate = from['date'];
12781
+ }
12782
+ if (toDate === undefined) {
12783
+ toDate = to['date'];
12784
+ }
12785
+ if (fromDate !== from['date']) {
12786
+ nextSelectEdgeRef.current = 'to';
12787
+ }
12788
+ else {
12789
+ nextSelectEdgeRef.current = 'from';
12790
+ }
12791
+ onChange(formatDate(type, fromDate, from['time'], toDate, to['time']));
12792
+ };
12793
+ const removeLabel = () => {
12794
+ onChangeDate();
12795
+ };
12796
+ const onChangeTime = (nextTime, edge) => {
12797
+ if (edge === 'from') {
12798
+ onChange(formatDate(type, from['date'], nextTime, to['date'], to['time']));
12799
+ }
12800
+ else {
12801
+ onChange(formatDate(type, from['date'], from['time'], to['date'], nextTime));
12802
+ }
12803
+ };
12804
+ const onChangeQuickRange = (quickRangeLabel) => {
12805
+ if (quickRanges) {
12806
+ const quickRange = quickRanges[quickRangeLabel];
12807
+ if (quickRange) {
12808
+ onChange(`${quickRange.from} to ${quickRange.to}`, quickRangeLabel);
12809
+ }
12810
+ if (closeOnQuickSelect) {
12811
+ setOpen(false);
12812
+ }
12813
+ }
12814
+ };
12815
+ const onOpen = React.useCallback(() => {
12816
+ onekijsFramework.eventLocks.lock('escape', id);
12817
+ }, [id]);
12818
+ const onClosed = React.useCallback(() => {
12819
+ onekijsFramework.eventLocks.unlock('escape', id);
12820
+ if (lastExternalValueRef.current !== undefined) {
12821
+ setInternalValue(null);
12822
+ }
12823
+ }, [id]);
12824
+ useClickOutside([containerRef, dropdownRef], onBlur);
12825
+ useFocusOutside([containerRef, dropdownRef], onBlur);
12826
+ const context = React.useMemo(() => {
12827
+ return {
12828
+ open,
12829
+ setOpen,
12830
+ triggerRef,
12831
+ nullable,
12832
+ onChange,
12833
+ };
12834
+ }, [open, setOpen, triggerRef, nullable, onChange]);
12835
+ React.useEffect(() => {
12836
+ if (forwardChange &&
12837
+ lastExternalValueRef.current !== undefined &&
12838
+ externalValue !== undefined &&
12839
+ externalValue !== lastExternalValueRef.current) {
12840
+ // case when we block the onChange due to a wrong internal value
12841
+ // and the value is changed from the exterior (not due to change done internally)
12842
+ setInternalValue(null);
12843
+ }
12844
+ lastExternalValueRef.current = externalValue;
12845
+ });
12846
+ return (jsxRuntimeExports.jsx(DefaultDatePickerContext.Provider, { value: context, children: jsxRuntimeExports.jsxs("div", { className: addClassname('o-datepicker', className), ref: containerRef, onMouseDown: () => (stateRef.current.keepFocus = true), onMouseUp: () => (stateRef.current.keepFocus = false), children: [jsxRuntimeExports.jsx(Dropdown, { attachToBody: attachDropdownToBody, open: open, distance: 0, animationTimeout: animationMs, onDropStart: onOpen, onCollapseDone: onClosed, placement: placement, widthModifier: dropdownWidthModifier, className: className, zIndex: attachDropdownToBody ? 2000 : undefined, children: jsxRuntimeExports.jsxs("div", { ref: dropdownRef, className: `o-datepicker-dropdown-content${type['range'] ? ' o-datepicker-range' : ''}${validFromRef.current !== undefined ? ' o-datepicker-active' : ''}`, children: [type['range'] && quickRanges && Object.keys(quickRanges).length > 0 && (jsxRuntimeExports.jsx(QuickTimeRangeComponent, { quickRanges: quickRanges, onChange: onChangeQuickRange, currentQuickRangeLabel: label }, "quick_range")), type['date'] && (jsxRuntimeExports.jsx("div", { className: "o-calendar", children: jsxRuntimeExports.jsx(CalendarComponent, { from: from, to: to, type: type, onChange: onChangeDate, nextSelectEdge: nextSelectEdgeRef.current }) }, "calendar")), type['time'] && (jsxRuntimeExports.jsx("div", { className: "o-time", children: jsxRuntimeExports.jsx(TimeComponent, { from: from, to: to, type: type, onChange: onChangeTime, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds }) }, "time"))] }) }), jsxRuntimeExports.jsx("span", { ref: triggerRef, children: jsxRuntimeExports.jsx(Input, { className: "o-datepicker-input", placeholder: placeholder, onChange: (e) => onChange(e.target.value), value: label ? label : !value ? '' : value, onFocus: onFocus, onBlur: onBlur, autoFocus: autoFocus, disabled: disabled, SuffixComponent: IconComponent, readOnly: !combo, onClick: () => {
12847
+ if (!open) {
12848
+ setOpen(true);
12849
+ }
12850
+ else if (combo) {
12851
+ removeLabel();
12852
+ }
12853
+ else {
12854
+ setOpen(false);
12855
+ }
12856
+ } }) }, "input")] }) }));
12664
12857
  };
12665
12858
 
12666
- const IconComponent$1 = ({ className, onClick }) => {
12667
- return (jsxRuntimeExports.jsx("div", { className: className, onClick: onClick, children: jsxRuntimeExports.jsxs("svg", { className: "o-icon-calendar-svg", viewBox: "0 0 512 512", children: [jsxRuntimeExports.jsx("rect", { x: "48", y: "80", width: "416", height: "384", rx: "48", fill: "none", stroke: "currentColor", strokeLinejoin: "round", strokeWidth: "32" }), jsxRuntimeExports.jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "32", d: "M128 48v32M384 48v32M464 160H48M304 260l43.42-32H352v168M191.87 306.63c9.11 0 25.79-4.28 36.72-15.47a37.9 37.9 0 0011.13-27.26c0-26.12-22.59-39.9-47.89-39.9-21.4 0-33.52 11.61-37.85 18.93M149 374.16c4.88 8.27 19.71 25.84 43.88 25.84 28.59 0 52.12-15.94 52.12-43.82 0-12.62-3.66-24-11.58-32.07-12.36-12.64-31.25-17.48-41.55-17.48" })] }) }));
12859
+ const toTimestamp = (date, format) => {
12860
+ if (!date)
12861
+ return null;
12862
+ const d = new Date(date);
12863
+ if (isNaN(d))
12864
+ return null;
12865
+ const timestamp = d.getTime();
12866
+ return format === 'milliseconds' ? timestamp : Math.floor(timestamp / 1000);
12668
12867
  };
12669
- var CalendarIcon = styled(IconComponent$1) `
12670
- ${({ width, height, color: cssColor = 'inherit', marginLeft: ml = '0', marginRight: mr = '0' }) => styled.css `
12671
- width: ${width};
12672
- height: ${height};
12673
- ${marginLeft(ml)}
12674
- ${marginRight(mr)}
12675
- ${display('flex')};
12676
- ${alignItems('center')};
12677
- ${color(cssColor)}
12678
- .o-icon-calendar-svg {
12679
- display: inline-block;
12680
- stroke-width: 0;
12681
- stroke: currentColor;
12682
- fill: currentColor;
12868
+ const fromTimestamp = (timestamp, format) => {
12869
+ if (timestamp === null || timestamp === undefined)
12870
+ return null;
12871
+ if (format === 'seconds') {
12872
+ timestamp = timestamp * 1000;
12683
12873
  }
12684
- `}
12685
- `;
12874
+ const d = new Date(timestamp);
12875
+ if (isNaN(d))
12876
+ return null;
12877
+ return dateToString(d);
12878
+ };
12879
+ const timestampAdapter = (format = 'milliseconds') => ({
12880
+ fromDate: (date) => toTimestamp(date, format),
12881
+ toDate: (value) => fromTimestamp(value, format),
12882
+ });
12883
+ const timestampMilliSecondAdapter = timestampAdapter('milliseconds');
12686
12884
 
12687
- const DefaultDatePickerContext = React.createContext(null);
12688
- const useDatePickerContext = () => {
12689
- return React.useContext(DefaultDatePickerContext);
12885
+ const dateAdapter = {
12886
+ fromDate: (date) => date === null ? null : new Date(date),
12887
+ toDate: (value) => !value ? null : dateToString(value),
12690
12888
  };
12691
12889
 
12692
- const dateToString = (d) => {
12693
- if (typeof d === 'function') {
12694
- d = d();
12695
- }
12696
- if (typeof d === 'string') {
12697
- d = new Date(d);
12698
- }
12699
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
12890
+ const type$5 = {
12891
+ date: true,
12892
+ time: false,
12893
+ range: false,
12700
12894
  };
12701
- const toDateRange = (value, label) => {
12702
- if (value) {
12703
- const [from, to] = value.trim().split(/ to\s*/);
12895
+ const DatePickerComponent = (props) => {
12896
+ const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
12897
+ const _adapter = adapter === 'timestamp' ? timestampMilliSecondAdapter : adapter === 'date' ? dateAdapter : adapter;
12898
+ const onChange = forwardChange
12899
+ ? (value) => {
12900
+ if (value === null || !_adapter) {
12901
+ forwardChange(value);
12902
+ }
12903
+ else {
12904
+ forwardChange(_adapter.fromDate(value));
12905
+ }
12906
+ }
12907
+ : undefined;
12908
+ let value = externalValue
12909
+ ? _adapter
12910
+ ? _adapter.toDate(externalValue)
12911
+ : externalValue
12912
+ : null;
12913
+ return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$5 });
12914
+ };
12915
+
12916
+ const timestampRangeAdapter = (format = 'milliseconds') => ({
12917
+ fromDateRange: (range) => {
12704
12918
  return {
12705
- from: from && from.trim() ? from.trim() : null,
12706
- to: to && to.trim() ? to.trim() : null,
12707
- label,
12919
+ from: toTimestamp(range.from, format),
12920
+ to: toTimestamp(range.to, format),
12921
+ label: range.label,
12708
12922
  };
12709
- }
12710
- else {
12711
- return null;
12712
- }
12713
- };
12714
- const qr = (quickRange) => {
12715
- return {
12716
- label: quickRange,
12717
- from: () => {
12718
- const d = new Date();
12719
- switch (quickRange) {
12720
- case 'Last hour':
12721
- d.setHours(d.getHours() - 1);
12722
- break;
12723
- case 'Last day':
12724
- d.setDate(d.getDate() - 1);
12725
- break;
12726
- case 'Last week':
12727
- d.setDate(d.getDate() - 7);
12728
- break;
12729
- case 'Last month':
12730
- d.setMonth(d.getMonth() - 1);
12731
- break;
12732
- case 'Last year':
12733
- d.setFullYear(d.getFullYear() - 1);
12734
- break;
12923
+ },
12924
+ toDateRange: (value) => {
12925
+ return {
12926
+ from: fromTimestamp(value.from, format),
12927
+ to: fromTimestamp(value.to, format),
12928
+ label: value.label,
12929
+ };
12930
+ },
12931
+ });
12932
+ const timestampSecondRangeAdapter = timestampRangeAdapter('seconds');
12933
+ const timestampMilliSecondRangeAdapter = timestampRangeAdapter('milliseconds');
12934
+ const useTimestampRangeAdapter = (format = 'milliseconds') => {
12935
+ const ref = React.useRef(timestampRangeAdapter(format));
12936
+ return ref.current;
12937
+ };
12938
+
12939
+ const dateRangeAdapter = {
12940
+ fromDateRange: (range) => {
12941
+ return {
12942
+ from: range?.from === null ? null : new Date(range.from),
12943
+ to: range?.to === null ? null : new Date(range.to),
12944
+ label: range?.label,
12945
+ };
12946
+ },
12947
+ toDateRange: (value) => {
12948
+ return {
12949
+ from: !value?.from ? null : dateToString(value.from),
12950
+ to: !value?.to ? null : dateToString(value.to),
12951
+ label: value?.label,
12952
+ };
12953
+ },
12954
+ };
12955
+ const useDateRangeAdapter = () => {
12956
+ return dateRangeAdapter;
12957
+ };
12958
+
12959
+ const type$4 = {
12960
+ date: true,
12961
+ time: false,
12962
+ range: true,
12963
+ };
12964
+ const DateRangePickerComponent = (props) => {
12965
+ const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
12966
+ const _adapter = adapter === 'timestamp' ? timestampMilliSecondRangeAdapter : adapter === 'date' ? dateRangeAdapter : adapter;
12967
+ const onChange = forwardChange
12968
+ ? (value, label) => {
12969
+ const dateRange = toDateRange(value, label);
12970
+ if (dateRange === null || !_adapter) {
12971
+ forwardChange(dateRange);
12735
12972
  }
12736
- return d;
12737
- },
12738
- to: () => new Date(),
12739
- };
12973
+ else {
12974
+ forwardChange(_adapter.fromDateRange(dateRange));
12975
+ }
12976
+ }
12977
+ : undefined;
12978
+ let value = null;
12979
+ let valueLabel;
12980
+ if (externalValue) {
12981
+ if (_adapter) {
12982
+ const { from, to, label } = _adapter.toDateRange(externalValue);
12983
+ value = `${from || ''} to ${to || ''}`;
12984
+ valueLabel = label;
12985
+ }
12986
+ else {
12987
+ value = `${externalValue.from || ''} to ${externalValue.to || ''}`;
12988
+ valueLabel = externalValue.label;
12989
+ }
12990
+ }
12991
+ return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$4, label: valueLabel });
12740
12992
  };
12741
- const defaultQuickRanges = () => {
12742
- return ['Last hour', 'Last day', 'Last week', 'Last month', 'Last year'].reduce((accumulator, label) => {
12743
- const quickRange = qr(label);
12744
- if (quickRange) {
12745
- accumulator[label] = quickRange;
12993
+
12994
+ const type$3 = {
12995
+ date: true,
12996
+ time: true,
12997
+ range: false,
12998
+ };
12999
+ const DateTimePickerComponent = (props) => {
13000
+ const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13001
+ const _adapter = adapter === 'timestamp' ? timestampMilliSecondAdapter : adapter === 'date' ? dateAdapter : adapter;
13002
+ const onChange = forwardChange
13003
+ ? (value) => {
13004
+ if (value === null || !_adapter) {
13005
+ forwardChange(value);
13006
+ }
13007
+ else {
13008
+ forwardChange(_adapter.fromDate(value));
13009
+ }
12746
13010
  }
12747
- return accumulator;
12748
- }, {});
13011
+ : undefined;
13012
+ let value = externalValue
13013
+ ? _adapter
13014
+ ? _adapter.toDate(externalValue)
13015
+ : externalValue
13016
+ : null;
13017
+ return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$3 });
12749
13018
  };
12750
- const findQuickRangeLabel = (quickRanges, dateRange) => {
12751
- if (!quickRanges || !dateRange)
12752
- return;
12753
- const dr = typeof dateRange === 'string' ? toDateRange(dateRange) : dateRange;
12754
- if (dr === null)
12755
- return;
12756
- if (!dr.from || !dr.to)
12757
- return;
12758
- return Object.keys(quickRanges).find((label) => {
12759
- return dr.from === quickRanges[label].from && dr.to === quickRanges[label].to;
12760
- });
13019
+
13020
+ const type$2 = {
13021
+ date: true,
13022
+ time: true,
13023
+ range: true,
12761
13024
  };
12762
- const isSameDay = (date1, date2) => {
12763
- return (date1.getFullYear() === date2.getFullYear() &&
12764
- date1.getMonth() === date2.getMonth() &&
12765
- date1.getDate() === date2.getDate());
13025
+ const DateTimeRangePickerComponent = (props) => {
13026
+ const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13027
+ const _adapter = adapter === 'timestamp' ? timestampMilliSecondRangeAdapter : adapter === 'date' ? dateRangeAdapter : adapter;
13028
+ const onChange = forwardChange
13029
+ ? (value, label) => {
13030
+ const dateRange = toDateRange(value, label);
13031
+ if (dateRange === null || !_adapter) {
13032
+ forwardChange(dateRange);
13033
+ }
13034
+ else {
13035
+ forwardChange(_adapter.fromDateRange(dateRange));
13036
+ }
13037
+ }
13038
+ : undefined;
13039
+ let value = null;
13040
+ let valueLabel;
13041
+ if (externalValue) {
13042
+ if (_adapter) {
13043
+ const { from, to, label } = _adapter.toDateRange(externalValue);
13044
+ value = `${from || ''} to ${to || ''}`;
13045
+ valueLabel = label;
13046
+ }
13047
+ else {
13048
+ value = `${externalValue.from || ''} to ${externalValue.to || ''}`;
13049
+ valueLabel = externalValue.label;
13050
+ }
13051
+ }
13052
+ return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$2, label: valueLabel });
12766
13053
  };
12767
13054
 
12768
- const isCurrent = (d, year, month, day) => {
12769
- return d.getFullYear() === year && d.getMonth() === month && d.getDate() === day;
13055
+ const type$1 = {
13056
+ date: false,
13057
+ time: true,
13058
+ range: false,
12770
13059
  };
12771
- const isActive = (date) => {
12772
- return date.year !== undefined && date.month !== undefined && date.year !== undefined;
13060
+ const TimePickerComponent = (props) => {
13061
+ return jsxRuntimeExports.jsx(PickerComponent, { ...props, type: type$1 });
12773
13062
  };
12774
- const inRange = (year, month, day, from, to) => {
12775
- let fromDate;
12776
- if (from.year !== undefined && from.month !== undefined && from.day !== undefined) {
12777
- fromDate = new Date(`${from.year}-${from.month.padStart(2, '0')}-${String(from.day).padStart(2, '0')}`);
12778
- }
12779
- else {
12780
- return false;
12781
- }
12782
- let toDate;
12783
- if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12784
- toDate = new Date(`${to.year}-${to.month.padStart(2, '0')}-${String(to.day).padStart(2, '0')}`);
12785
- }
12786
- else {
12787
- return false;
12788
- }
12789
- let currentDate = new Date(`${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`);
12790
- return (currentDate > fromDate && currentDate < toDate) || (currentDate < fromDate && currentDate > toDate);
13063
+
13064
+ const type = {
13065
+ date: false,
13066
+ time: true,
13067
+ range: true,
12791
13068
  };
12792
- const isInversedDate = (from, to) => {
12793
- if (!isActive(from) || !isActive(to)) {
12794
- return false;
12795
- }
12796
- const fromDate = new Date(`${from.year}-${String(from.month ?? 0 + 1).padStart(2, '0')}-${String(from.day).padStart(2, '0')}`);
12797
- const toDate = new Date(`${to.year}-${String(to.month ?? 0 + 1).padStart(2, '0')}-${String(to.day).padStart(2, '0')}`);
12798
- return fromDate > toDate;
13069
+ const TimeRangePickerComponent = (props) => {
13070
+ return jsxRuntimeExports.jsx(PickerComponent, { ...props, type: type });
12799
13071
  };
12800
- function getMonth(candidate, defaultValue) {
12801
- if (typeof candidate === 'string') {
12802
- candidate = parseInt(candidate) - 1;
12803
- }
12804
- if (candidate === undefined || isNaN(candidate) || candidate < 0 || candidate > 11) {
12805
- return defaultValue;
12806
- }
12807
- return candidate;
12808
- }
12809
- function getYear(candidate, min, max, defaultValue) {
12810
- if (typeof candidate === 'string') {
12811
- candidate = parseInt(candidate);
12812
- }
12813
- if (candidate === undefined || isNaN(candidate) || candidate < min || candidate > max) {
12814
- return defaultValue;
12815
- }
12816
- return candidate;
12817
- }
12818
- const defaultMinDate = new Date();
12819
- defaultMinDate.setFullYear(1900);
12820
- const defaultMaxDate = new Date();
12821
- defaultMaxDate.setFullYear(2100);
12822
- const CalendarComponent = ({ from, to, type, minDate = defaultMinDate, maxDate = defaultMaxDate, nextSelectEdge, className, onChange, }) => {
12823
- const maxYear = maxDate.getFullYear();
12824
- const minYear = minDate.getFullYear();
12825
- const years = React.useRef([...Array(maxYear).keys()].slice(minYear));
12826
- const d = new Date();
12827
- const lastExternalFromMonth = React.useRef(from['month']);
12828
- const lastExternalFromYear = React.useRef(from['year']);
12829
- const lastExternalToMonth = React.useRef(to['month']);
12830
- const lastExternalToYear = React.useRef(to['year']);
12831
- const fromMonth = getMonth(from['month']);
12832
- const fromYear = getYear(from['year'], minYear, maxYear);
12833
- const fromDay = from['day'] === undefined ? undefined : parseInt(`${from['day']}`);
12834
- const [internalTo, setInternalTo] = React.useState({});
12835
- let transientTo = false;
12836
- let toMonth, toYear, toDay;
12837
- let isInversed = false;
12838
- if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12839
- toMonth = getMonth(to.month);
12840
- toYear = getYear(to.year, minYear, maxYear);
12841
- toDay = parseInt(`${to.day}`);
12842
- }
12843
- else {
12844
- toMonth = getMonth(internalTo.month);
12845
- toYear = getYear(internalTo.year, minYear, maxYear);
12846
- toDay = parseInt(`${internalTo.day}`);
12847
- transientTo = true;
12848
- isInversed = isInversedDate(from, internalTo);
12849
- }
12850
- const [currentMonth, setCurrentMonth] = React.useState(getMonth(from['month'], d.getMonth()));
12851
- const [currentYear, setCurrentYear] = React.useState(getYear(from['year'], minYear, maxYear, d.getFullYear()));
12852
- const firstDayOfExternalFromMonth = fromMonth && fromYear ? new Date(`${fromYear}-${String(getMonth(fromMonth + 1)).padStart(2, '0')}-01`) : undefined;
12853
- const firstDayOfExternalToMonth = toMonth && toYear ? new Date(`${toYear}-${String(toMonth + 1).padStart(2, '0')}-01`) : undefined;
12854
- const firstDayOfCurrentMonth = new Date(`${currentYear}-${String(currentMonth + 1).padStart(2, '0')}-01`);
12855
- const lastDayOfPreviousMonth = new Date(firstDayOfCurrentMonth);
12856
- lastDayOfPreviousMonth.setDate(lastDayOfPreviousMonth.getDate() - 1);
12857
- const lastDayOfCurrentMonth = new Date(firstDayOfCurrentMonth);
12858
- lastDayOfCurrentMonth.setMonth(lastDayOfCurrentMonth.getMonth() + 1);
12859
- lastDayOfCurrentMonth.setDate(lastDayOfCurrentMonth.getDate() - 1);
12860
- const firstDayOfNextMonth = new Date(firstDayOfCurrentMonth);
12861
- firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
12862
- let calendarDays = firstDayOfCurrentMonth.getDate() === 0 || firstDayOfCurrentMonth.getDay() === 0
12863
- ? []
12864
- : [...Array(lastDayOfPreviousMonth.getDate() + 1).keys()].slice(-firstDayOfCurrentMonth.getDay()).map((n) => {
12865
- const startRange = fromDay === n &&
12866
- lastDayOfPreviousMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12867
- lastDayOfPreviousMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12868
- const endRange = toDay === n &&
12869
- lastDayOfPreviousMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12870
- lastDayOfPreviousMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12871
- return {
12872
- day: n,
12873
- active: startRange || endRange,
12874
- current: isCurrent(d, lastDayOfPreviousMonth.getFullYear(), lastDayOfPreviousMonth.getMonth(), n),
12875
- month: lastDayOfPreviousMonth.getMonth(),
12876
- year: lastDayOfPreviousMonth.getFullYear(),
12877
- startRange: startRange && type.range,
12878
- endRange: isActive(from) && endRange && type.range,
12879
- inRange: type.range &&
12880
- inRange(lastDayOfPreviousMonth.getFullYear(), lastDayOfPreviousMonth.getMonth(), n, from, transientTo ? internalTo : to),
13072
+
13073
+ const DatePicker = styled(DatePickerComponent) `
13074
+ ${datePickerStyle}
13075
+ `;
13076
+ const DateRangePicker = styled(DateRangePickerComponent) `
13077
+ ${datePickerStyle}
13078
+ `;
13079
+ const DateTimePicker = styled(DateTimePickerComponent) `
13080
+ ${datePickerStyle}
13081
+ `;
13082
+ const DateTimeRangePicker = styled(DateTimeRangePickerComponent) `
13083
+ ${datePickerStyle}
13084
+ `;
13085
+ const TimePicker = styled(TimePickerComponent) `
13086
+ ${datePickerStyle}
13087
+ `;
13088
+ const TimeRangePicker = styled(TimeRangePickerComponent) `
13089
+ ${datePickerStyle}
13090
+ `;
13091
+
13092
+ const FormDateValueDisplayer = ({ value }) => {
13093
+ return jsxRuntimeExports.jsx("span", { className: "o-date-picker-displayer-value", children: value ?? '' });
13094
+ };
13095
+ const formDateDisplayerProps = (props) => ({
13096
+ defaultValue: props.defaultValue === undefined ? null : props.defaultValue,
13097
+ isUndefined: props.isUndefined === undefined ? (value) => value === undefined || value === null : props.isUndefined,
13098
+ Displayer: props.Displayer === undefined
13099
+ ? (displayerProps) => {
13100
+ const form = onekijsFramework.useForm();
13101
+ let value = form.getValue(displayerProps.name) ?? null;
13102
+ const ValueDisplayer = props.ValueDisplayer ?? FormDateValueDisplayer;
13103
+ const adapter = props.adapter === 'timestamp'
13104
+ ? timestampMilliSecondAdapter
13105
+ : props.adapter === 'date'
13106
+ ? dateAdapter
13107
+ : props.adapter;
13108
+ if (adapter) {
13109
+ value = adapter.toDate(value);
13110
+ }
13111
+ return (jsxRuntimeExports.jsx(FieldDisplayer, { label: displayerProps.label ?? titlelize(displayerProps.name), help: props.help, first: displayerProps.first, last: displayerProps.last, value: jsxRuntimeExports.jsx(ValueDisplayer, { value: value }), format: displayerProps.format }));
13112
+ }
13113
+ : props.Displayer,
13114
+ });
13115
+ /**
13116
+ * `<FormDatePicker/>` is a DataPicker component designed to be managed by a Form.
13117
+ * It must therefore be a nested component of a Form
13118
+ *
13119
+ * Some properties are handled entirely by a form controller.
13120
+ * * value
13121
+ * * onChange
13122
+ * * onFocus
13123
+ * * onBlur
13124
+ * * validations
13125
+ * * visibility
13126
+ * * disabled
13127
+ * The value is synchronized in both directions (it can be modified manually by the user or by the controller).
13128
+ *
13129
+ * @group Form
13130
+ * @category Components
13131
+ */
13132
+ const FormDatePicker = React.memo((props) => {
13133
+ const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({}, props, formDateDisplayerProps(props)));
13134
+ return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(DatePicker, { ...fieldComponentProps }) }));
13135
+ });
13136
+ FormDatePicker.displayName = 'FormDatePicker';
13137
+
13138
+ const FormDateRangeValueDisplayer = ({ value }) => {
13139
+ return jsxRuntimeExports.jsx("span", { className: "o-date-picker-range-displayer-value", children: value ? `${value.from} - ${value.to}` : '' });
13140
+ };
13141
+ const formDateRangeDisplayerProps = (props) => ({
13142
+ defaultValue: props.defaultValue === undefined ? null : props.defaultValue,
13143
+ isUndefined: props.isUndefined === undefined ? (value) => value === undefined || value === null : props.isUndefined,
13144
+ Displayer: props.Displayer === undefined
13145
+ ? (displayerProps) => {
13146
+ const form = onekijsFramework.useForm();
13147
+ let value = form.getValue(displayerProps.name) ?? null;
13148
+ const ValueDisplayer = props.ValueDisplayer ?? FormDateRangeValueDisplayer;
13149
+ const adapter = props.adapter === 'timestamp'
13150
+ ? timestampMilliSecondRangeAdapter
13151
+ : props.adapter === 'date'
13152
+ ? dateRangeAdapter
13153
+ : props.adapter;
13154
+ if (adapter) {
13155
+ value = adapter.toDateRange(value);
13156
+ }
13157
+ return (jsxRuntimeExports.jsx(FieldDisplayer, { label: displayerProps.label ?? titlelize(displayerProps.name), help: props.help, first: displayerProps.first, last: displayerProps.last, value: jsxRuntimeExports.jsx(ValueDisplayer, { value: value }), format: displayerProps.format }));
13158
+ }
13159
+ : props.Displayer,
13160
+ });
13161
+ /**
13162
+ * `<FormDateRangePicker/>` is a DataPicker component designed to be managed by a Form.
13163
+ * It must therefore be a nested component of a Form
13164
+ *
13165
+ * Some properties are handled entirely by a form controller.
13166
+ * * value
13167
+ * * onChange
13168
+ * * onFocus
13169
+ * * onBlur
13170
+ * * validations
13171
+ * * visibility
13172
+ * * disabled
13173
+ * The value is synchronized in both directions (it can be modified manually by the user or by the controller).
13174
+ *
13175
+ * @group Form
13176
+ * @category Components
13177
+ */
13178
+ const FormDateRangePicker = React.memo((props) => {
13179
+ const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({}, props, formDateRangeDisplayerProps(props)));
13180
+ return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(DateRangePicker, { ...fieldComponentProps }) }));
13181
+ });
13182
+ FormDateRangePicker.displayName = 'FormDateRangePicker';
13183
+
13184
+ /**
13185
+ * `<FormDateTimePicker/>` is a DataTimePicker component designed to be managed by a Form.
13186
+ * It must therefore be a nested component of a Form
13187
+ *
13188
+ * Some properties are handled entirely by a form controller.
13189
+ * * value
13190
+ * * onChange
13191
+ * * onFocus
13192
+ * * onBlur
13193
+ * * validations
13194
+ * * visibility
13195
+ * * disabled
13196
+ * The value is synchronized in both directions (it can be modified manually by the user or by the controller).
13197
+ *
13198
+ * @group Form
13199
+ * @category Components
13200
+ */
13201
+ const FormDateTimePicker = React.memo((props) => {
13202
+ const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({}, props, formDateDisplayerProps(props)));
13203
+ return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(DateTimePicker, { ...fieldComponentProps }) }));
13204
+ });
13205
+ FormDateTimePicker.displayName = 'FormDateTimePicker';
13206
+
13207
+ /**
13208
+ * `<FormDateTimeRangePicker/>` is a DataTimeRangePicker component designed to be managed by a Form.
13209
+ * It must therefore be a nested component of a Form
13210
+ *
13211
+ * Some properties are handled entirely by a form controller.
13212
+ * * value
13213
+ * * onChange
13214
+ * * onFocus
13215
+ * * onBlur
13216
+ * * validations
13217
+ * * visibility
13218
+ * * disabled
13219
+ * The value is synchronized in both directions (it can be modified manually by the user or by the controller).
13220
+ *
13221
+ * @group Form
13222
+ * @category Components
13223
+ */
13224
+ const FormDateTimeRangePicker = React.memo((props) => {
13225
+ const [fieldLayoutProps, fieldComponentProps] = useFieldLayout(Object.assign({}, props, formDateRangeDisplayerProps(props)));
13226
+ return (jsxRuntimeExports.jsx(FieldLayout, { ...fieldLayoutProps, required: props.required, children: jsxRuntimeExports.jsx(DateTimeRangePicker, { ...fieldComponentProps }) }));
13227
+ });
13228
+ FormDateTimeRangePicker.displayName = 'FormDateTimeRangePicker';
13229
+
13230
+ const useQuickRanges = (ranges) => {
13231
+ const result = onekijsFramework.useLazyRef(() => {
13232
+ if (!Array.isArray(ranges)) {
13233
+ ranges = [ranges];
13234
+ }
13235
+ const quickRanges = ranges.reduce((accumulator, range) => {
13236
+ if (typeof range === 'string') {
13237
+ if (range === 'all') {
13238
+ accumulator = Object.assign(accumulator, defaultQuickRanges());
13239
+ }
13240
+ else {
13241
+ const dateRange = qr(range);
13242
+ if (dateRange !== null) {
13243
+ accumulator[range] = dateRange;
13244
+ }
13245
+ }
13246
+ }
13247
+ else {
13248
+ accumulator[range.label] = range;
13249
+ }
13250
+ return accumulator;
13251
+ }, {});
13252
+ const target = Object.keys(quickRanges).reduce((accumulator, label) => {
13253
+ accumulator[label] = {
13254
+ from: null,
13255
+ to: null,
13256
+ label,
12881
13257
  };
12882
- });
12883
- calendarDays = calendarDays.concat([...Array(lastDayOfCurrentMonth.getDate() + 1).keys()].slice(1).map((n) => {
12884
- const startRange = fromDay === n &&
12885
- lastDayOfCurrentMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12886
- lastDayOfCurrentMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12887
- const endRange = toDay === n &&
12888
- lastDayOfCurrentMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12889
- lastDayOfCurrentMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12890
- return {
12891
- day: n,
12892
- active: startRange || endRange,
12893
- current: isCurrent(d, lastDayOfCurrentMonth.getFullYear(), lastDayOfCurrentMonth.getMonth(), n),
12894
- month: lastDayOfCurrentMonth.getMonth(),
12895
- year: lastDayOfCurrentMonth.getFullYear(),
12896
- startRange: startRange && type.range,
12897
- endRange: isActive(from) && endRange && type.range,
12898
- inRange: type.range &&
12899
- inRange(lastDayOfCurrentMonth.getFullYear(), lastDayOfCurrentMonth.getMonth(), n, from, transientTo ? internalTo : to),
13258
+ return accumulator;
13259
+ }, {});
13260
+ const handler = {
13261
+ get: function (_, prop) {
13262
+ if (typeof prop === 'string') {
13263
+ const quickRange = quickRanges[prop];
13264
+ if (quickRange) {
13265
+ return {
13266
+ from: dateToString(quickRange.from),
13267
+ to: dateToString(quickRange.to),
13268
+ label: quickRange.label,
13269
+ };
13270
+ }
13271
+ }
13272
+ return undefined;
13273
+ },
12900
13274
  };
12901
- }));
12902
- calendarDays = calendarDays.concat(lastDayOfCurrentMonth.getDay() === 6
12903
- ? []
12904
- : [...Array(6 - lastDayOfCurrentMonth.getDay() + 1).keys()].slice(1).map((n) => {
12905
- const startRange = fromDay === n &&
12906
- firstDayOfNextMonth.getMonth() === firstDayOfExternalFromMonth?.getMonth() &&
12907
- firstDayOfNextMonth.getFullYear() === firstDayOfExternalFromMonth?.getFullYear();
12908
- const endRange = toDay === n &&
12909
- firstDayOfNextMonth.getMonth() === firstDayOfExternalToMonth?.getMonth() &&
12910
- firstDayOfNextMonth.getFullYear() === firstDayOfExternalToMonth?.getFullYear();
12911
- return {
12912
- day: n,
12913
- active: startRange || endRange,
12914
- current: isCurrent(d, firstDayOfNextMonth.getFullYear(), firstDayOfNextMonth.getMonth(), n),
12915
- month: firstDayOfNextMonth.getMonth(),
12916
- year: firstDayOfNextMonth.getFullYear(),
12917
- startRange: startRange && type.range,
12918
- endRange: isActive(from) && endRange && type.range,
12919
- inRange: type.range &&
12920
- inRange(firstDayOfNextMonth.getFullYear(), firstDayOfNextMonth.getMonth(), n, from, transientTo ? internalTo : to),
12921
- };
12922
- }));
12923
- React.useEffect(() => {
12924
- if (type.range && to['month'] !== lastExternalToMonth.current) {
12925
- // the user has changed the toMonth from the input field
12926
- // we move the calendar to this month if it's a valid month
12927
- lastExternalToMonth.current = to['month'];
12928
- setCurrentMonth(getMonth(to['month'], currentMonth));
12929
- }
12930
- if (type.range && to['year'] !== lastExternalToYear.current) {
12931
- // the user has changed the toYear from the input field
12932
- // we move the calendar to this year if it's a valid year
12933
- lastExternalToYear.current = to['year'];
12934
- setCurrentYear(getYear(to['year'], minYear, maxYear, currentYear));
12935
- }
12936
- if (from['month'] !== lastExternalFromMonth.current) {
12937
- // the user has changed the fromMonth from the input field
12938
- // we move the calendar to this month if it's a valid month
12939
- lastExternalFromMonth.current = from['month'];
12940
- setCurrentMonth(getMonth(from['month'], currentMonth));
12941
- }
12942
- if (from['year'] !== lastExternalFromYear.current) {
12943
- // the user has changed the fromYear from the input field
12944
- // we move the calendar to this year if it's a valid year
12945
- lastExternalFromYear.current = from['year'];
12946
- setCurrentYear(getYear(from['year'], minYear, maxYear, currentYear));
12947
- }
13275
+ return new Proxy(target, handler);
12948
13276
  });
12949
- return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-calendar-container', className), children: [jsxRuntimeExports.jsxs("div", { className: "o-calendar-month", children: [jsxRuntimeExports.jsx(TogglerIcon, { width: "20px", closeArrowPosition: "w", onClick: () => {
12950
- if (fromMonth === 0) {
12951
- setCurrentMonth(11);
12952
- setCurrentYear(currentYear - 1);
12953
- }
12954
- else {
12955
- setCurrentMonth(currentMonth - 1);
12956
- }
12957
- } }, "previous"), jsxRuntimeExports.jsx(Select, { dataSource: months, nullable: false, value: months[currentMonth], className: "o-calendar-select-month", size: "small", onChange: (value) => setCurrentMonth(months.indexOf(`${value}`)) }, "month"), jsxRuntimeExports.jsx(Select, { dataSource: years.current, value: currentYear, nullable: false, className: "o-calendar-select-year", size: "small", onChange: (value) => setCurrentYear(parseInt(`${value}`)) }, "year"), jsxRuntimeExports.jsx(TogglerIcon, { width: "20px", closeArrowPosition: "e", onClick: () => {
12958
- if (fromMonth === 11) {
12959
- setCurrentMonth(0);
12960
- setCurrentYear(currentYear + 1);
12961
- }
12962
- else {
12963
- setCurrentMonth(currentMonth + 1);
12964
- }
12965
- } }, "next")] }), jsxRuntimeExports.jsxs("div", { className: "o-calendar-day-container", children: [days.map((day) => (jsxRuntimeExports.jsx("div", { className: "o-calendar-day-title", children: day.substring(0, 2) }, `${day}`))), calendarDays.map((calendarDay, index) => (jsxRuntimeExports.jsx("div", { className: `o-calendar-day${calendarDay.endRange
12966
- ? ` o-calendar-day-${isInversed ? 'start' : 'end'}-range${transientTo ? '-transient' : ''}`
12967
- : ''}${calendarDay.startRange ? ` o-calendar-day-${isInversed ? 'end' : 'start'}-range` : ''}${calendarDay.active ? ' o-calendar-day-active' : ''}${calendarDay.inRange ? ` o-calendar-day-in-range${transientTo ? '-transient' : ''}` : ''}${calendarDay.month === currentMonth ? ' o-calendar-day-in-month' : ''}${calendarDay.current ? ' o-calendar-day-current' : ''}`, onClick: () => {
12968
- const nextDateString = `${calendarDay.year}-${String(calendarDay.month + 1).padStart(2, '0')}-${String(calendarDay.day).padStart(2, '0')}`;
12969
- if (type.range && from.year !== undefined && from.month !== undefined && from.day !== undefined) {
12970
- // It's a date range and not the first selection
12971
- // We must determine if it's a change for the from or the to
12972
- const fromDateString = `${from.year}-${from.month.padStart(2, '0')}-${String(from.day).padStart(2, '0')}`;
12973
- const fromDate = new Date(fromDateString);
12974
- let endDate = undefined;
12975
- let endDateString = undefined;
12976
- if (to.year !== undefined && to.month !== undefined && to.day !== undefined) {
12977
- // it's not the second click
12978
- endDateString = `${to.year}-${to.month.padStart(2, '0')}-${String(to.day).padStart(2, '0')}`;
12979
- endDate = new Date(endDateString);
12980
- }
12981
- const nextDate = new Date(nextDateString);
12982
- if (endDate) {
12983
- // case when we click on the same day than the fromDate
12984
- if (isSameDay(fromDate, nextDate)) {
12985
- if (nextDate <= fromDate) {
12986
- onChange(nextDateString, fromDateString);
12987
- }
12988
- else {
12989
- onChange(fromDateString, nextDateString);
12990
- }
12991
- }
12992
- // case when we click on the same day than the endDate
12993
- else if (isSameDay(endDate, nextDate)) {
12994
- if (nextDate <= endDate) {
12995
- onChange(nextDateString, endDateString);
12996
- }
12997
- else {
12998
- onChange(endDateString, nextDateString);
12999
- }
13000
- }
13001
- else if (nextDate <= fromDate) {
13002
- onChange(nextDateString, endDateString);
13003
- }
13004
- else if (nextDate >= endDate) {
13005
- onChange(fromDateString, nextDateString);
13006
- }
13007
- else if (nextSelectEdge === 'from') {
13008
- onChange(nextDateString, endDateString);
13009
- }
13010
- else {
13011
- onChange(fromDateString, nextDateString);
13012
- }
13013
- }
13014
- else if (nextDate <= fromDate) {
13015
- onChange(nextDateString, fromDateString);
13016
- }
13017
- else {
13018
- onChange(fromDateString, nextDateString);
13019
- }
13020
- }
13021
- else {
13022
- // we assume that it's not a range or the first selection of the range
13023
- onChange(nextDateString);
13024
- }
13025
- }, onMouseEnter: () => {
13026
- if (transientTo) {
13027
- setInternalTo({
13028
- year: `${calendarDay.year}`,
13029
- month: String(calendarDay.month + 1).padStart(2, '0'),
13030
- day: String(calendarDay.day).padStart(2, '0'),
13031
- });
13032
- }
13033
- }, children: calendarDay.day }, `${fromDay}-${index}`)))] })] }));
13277
+ return result.current;
13278
+ };
13279
+
13280
+ const SliderComponent = () => {
13281
+ return null;
13282
+ };
13283
+
13284
+ const sliderStyle = () => {
13285
+ return styled.css ``;
13286
+ };
13287
+
13288
+ const Resizer = styled(SliderComponent) `
13289
+ ${sliderStyle}
13290
+ `;
13291
+
13292
+ const TagComponent = ({ className, children, onClick, icon }) => {
13293
+ return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-tag', className), onClick: onClick, children: [icon && jsxRuntimeExports.jsx("span", { className: "o-tag-icon", children: icon }), children] }));
13294
+ };
13295
+
13296
+ const tagStyle = ({ theme, kind, bgColor = 'primary', fontColor = 'white', size = 'small', onClick, marginBottom: mb = 0, marginLeft: ml = 0, marginRight: mr = 0, marginTop: mt = 0, }) => {
13297
+ let fSize = 'sm';
13298
+ let lHeight = 'md';
13299
+ let pX = 'md';
13300
+ let radius = 'sm';
13301
+ const pt = '2xs';
13302
+ if (size === 'small') {
13303
+ fSize = 'xs';
13304
+ lHeight = 'xs';
13305
+ radius = 'xs';
13306
+ pX = 'sm';
13307
+ }
13308
+ if (size === 'large') {
13309
+ fSize = 'md';
13310
+ lHeight = 'lg';
13311
+ }
13312
+ return styled.css `
13313
+ ${display('inline-flex')}
13314
+ ${alignItems('center')}
13315
+ ${backgroundColor(kind ? theme.buttons[kind].bgColor : bgColor)}
13316
+ ${marginLeft(ml)}
13317
+ ${marginRight(mr)}
13318
+ ${marginBottom(mb)}
13319
+ ${marginTop(mt)}
13320
+ ${lineHeight(lHeight)}
13321
+ ${paddingX(pX)}
13322
+ ${paddingTop(pt)}
13323
+ ${color(kind ? theme.buttons[kind].color : fontColor)}
13324
+ ${fontSize(fSize)}
13325
+ ${cursor(onClick ? 'pointer' : 'inherit')}
13326
+ ${borderRadius(radius)}
13327
+ .o-tag-icon {
13328
+ ${marginRight('xs')}
13329
+ ${display('inline-flex')}
13330
+ ${alignItems('center')}
13331
+ }
13332
+ `;
13034
13333
  };
13035
13334
 
13036
- const QuickTimeRangeComponent = ({ quickRanges, onChange, currentQuickRangeLabel, }) => {
13037
- return (jsxRuntimeExports.jsxs("div", { className: "o-quick-time-range-container", children: [jsxRuntimeExports.jsx("div", { className: "o-quick-time-range-title", children: "Quick select" }), Object.keys(quickRanges).map((quickRangeLabel, index) => {
13038
- return (jsxRuntimeExports.jsx("div", { className: `o-quick-time-range${currentQuickRangeLabel === quickRangeLabel ? ' o-quick-time-range-selected' : ''}`, onClick: () => onChange(quickRangeLabel), children: quickRangeLabel }, `qr-${index}`));
13039
- })] }));
13335
+ const Tag = styled(TagComponent) `
13336
+ ${tagStyle}
13337
+ `;
13338
+
13339
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13340
+ const WizardServiceContext = React.createContext(null);
13341
+ const useWizardService = () => {
13342
+ return React.useContext(WizardServiceContext);
13040
13343
  };
13041
13344
 
13042
- const getNextValue = (value, max, type) => {
13043
- const valueInt = parseInt(`${value}`);
13044
- let result = 0;
13045
- if (type === 'next') {
13046
- if (isNaN(valueInt) || valueInt === max) {
13047
- result = 0;
13345
+ const WizardStateContext = React.createContext(null);
13346
+ const useWizardState = () => {
13347
+ return React.useContext(WizardStateContext);
13348
+ };
13349
+
13350
+ const StepTitleContent = ({ member, index }) => {
13351
+ return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [member.icon, jsxRuntimeExports.jsxs("span", { className: "o-step-title", children: [index, ". ", `${member.title}`] })] }));
13352
+ };
13353
+
13354
+ const StepTitle = (props) => {
13355
+ const { member, onActivate, TitleContentComponent = StepTitleContent } = props;
13356
+ return (jsxRuntimeExports.jsx("div", { className: `o-step${member.active ? ' o-step-active' : ' o-step-inactive'}${member.disabled ? ' o-step-disabled' : ' o-step-enabled'}${member.visible ? ' o-step-visible' : ' o-step-hidden'}${member.touched || member.touching ? ' o-step-touched' : ' o-step-untouched'}${member.success ? ' o-step-success' : ''}${member.touchingWarning || (member.touched && member.warning) ? ' o-step-warning' : ''}${member.touchingError || (member.touched && member.error) ? ' o-step-error' : ''}${member.loading ? ' o-step-loading' : ''}`, onClick: () => onActivate(member), children: jsxRuntimeExports.jsx(TitleContentComponent, { ...props }) }));
13357
+ };
13358
+
13359
+ const WizardContainer = ({ cancelLabel = 'Cancel', className, children, doneLabel = 'Submit', nextLabel = 'Next', onCancel, onDone, previousLabel = 'Previous', title, stepSize = 3, TitleComponent = StepTitle, TitleContentComponent, forwardOnly = true, hasSummaryStep = false, reviewLabel = 'Review and Submit', }) => {
13360
+ const classNames = addClassname('o-wizard', className);
13361
+ const state = useWizardState();
13362
+ const service = useWizardService();
13363
+ const lastStepUid = service.getLastStep()?.uid;
13364
+ const activate = React.useCallback((step) => {
13365
+ if (!step || step.disabled || (!step.touched && !step.touching))
13366
+ return;
13367
+ if (!step.active) {
13368
+ service.activate(step.uid);
13048
13369
  }
13049
- else {
13050
- result = valueInt + 1;
13370
+ }, [service]);
13371
+ const errorRef = React.useRef([]);
13372
+ errorRef.current = [];
13373
+ const indexRef = React.useRef(0);
13374
+ indexRef.current = 0;
13375
+ return (jsxRuntimeExports.jsxs(Row, { className: classNames, children: [jsxRuntimeExports.jsxs(Col, { size: stepSize, className: "o-wizard-step-panel", children: [title && jsxRuntimeExports.jsx("div", { className: "o-wizard-title", children: title }), state.members.map((step) => {
13376
+ if (step.visible) {
13377
+ indexRef.current++;
13378
+ }
13379
+ else {
13380
+ return null;
13381
+ }
13382
+ if (step.error !== undefined) {
13383
+ errorRef.current.push({
13384
+ stepIndex: indexRef.current,
13385
+ stepTitle: step.title,
13386
+ errorMessage: step.error,
13387
+ });
13388
+ }
13389
+ return (jsxRuntimeExports.jsx(TitleComponent, { member: step, onActivate: activate, index: indexRef.current, TitleContentComponent: TitleContentComponent }, `step-title-${step.uid}`));
13390
+ })] }), jsxRuntimeExports.jsxs(Col, { size: (12 - stepSize), className: "o-wizard-content-panel", children: [jsxRuntimeExports.jsx("div", { className: "o-wizard-content", children: children }), jsxRuntimeExports.jsxs("div", { className: "o-wizard-control", children: [onCancel && (jsxRuntimeExports.jsx(Button, { kind: "primary", pattern: "flat", className: "o-wizard-control-button", type: "button", onClick: () => onCancel(), children: cancelLabel })), !service.isFirstStep() && (jsxRuntimeExports.jsx(Button, { kind: "primary", pattern: "outline", className: "o-wizard-control-button", onClick: () => service.previous(), type: "button", children: previousLabel })), !service.isLastStep() && (jsxRuntimeExports.jsx(Button, { kind: service.isCurrentStepInVisibleError() ? 'danger' : 'primary', pattern: "solid", className: "o-wizard-control-button", disabled: service.isCurrentStepInVisibleError(), onClick: () => service.next(), type: "button", children: nextLabel })), (service.isLastStep() || !forwardOnly) && (jsxRuntimeExports.jsx(SubmitButton, { kind: errorRef.current.length > 0 ? 'danger' : 'success', pattern: "solid", className: "o-wizard-control-button", disabled: errorRef.current.length > 0, onClick: hasSummaryStep && !service.isLastStep() && lastStepUid ? () => service.activate(lastStepUid) : onDone, type: "button", showErrors: true, children: hasSummaryStep && !service.isLastStep() ? reviewLabel : doneLabel }))] })] })] }));
13391
+ };
13392
+
13393
+ const ControlledWizardComponent = ({ Component = WizardContainer, controller, ...props }) => {
13394
+ return (jsxRuntimeExports.jsx(WizardServiceContext.Provider, { value: controller, children: jsxRuntimeExports.jsx(WizardStateContext.Provider, { value: controller.state, children: jsxRuntimeExports.jsx(Component, { ...props }) }) }));
13395
+ };
13396
+
13397
+ exports.WizardService = class WizardService extends TabsService {
13398
+ activateNext() {
13399
+ const nextStep = this.getNextStep();
13400
+ if (nextStep) {
13401
+ this.activate(nextStep.uid);
13051
13402
  }
13052
13403
  }
13053
- else if (type === 'previous') {
13054
- if (isNaN(valueInt)) {
13055
- result = 0;
13404
+ activatePrevious() {
13405
+ const previousStep = this.getPreviousStep();
13406
+ if (previousStep) {
13407
+ this.activate(previousStep.uid);
13056
13408
  }
13057
- else if (valueInt === 0) {
13058
- result = max;
13409
+ }
13410
+ getCurrentStep() {
13411
+ return this.state.members[this.getCurrentActiveIndex()];
13412
+ }
13413
+ getNextStep() {
13414
+ for (let i = this.getCurrentActiveIndex() + 1; i < this.state.members.length; i++) {
13415
+ const step = this.state.members[i];
13416
+ if (step && step.visible && !step.disabled) {
13417
+ return step;
13418
+ }
13059
13419
  }
13060
- else {
13061
- result = valueInt - 1;
13420
+ return undefined;
13421
+ }
13422
+ getLastStep() {
13423
+ return this.state.members.filter((m) => m.visible && !m.disabled).slice(-1)[0];
13424
+ }
13425
+ getPreviousStep() {
13426
+ for (let i = this.getCurrentActiveIndex() - 1; i >= 0; i--) {
13427
+ const step = this.state.members[i];
13428
+ if (step && step.visible && !step.disabled) {
13429
+ return step;
13430
+ }
13062
13431
  }
13432
+ return undefined;
13063
13433
  }
13064
- return String(result).padStart(2, '0');
13065
- };
13066
- const isMin = (value, _type) => {
13067
- return parseInt(`${value}`) === 0;
13068
- };
13069
- const isMax = (value, type) => {
13070
- return type === 'hour' ? parseInt(`${value}`) === 23 : parseInt(`${value}`) === 59;
13071
- };
13072
- const TimeSelectorPartComponent = ({ onChange, type, value, size = 'large', }) => {
13073
- const onValueChange = (e) => {
13074
- let value = e.target.value;
13075
- if (type === 'minute' && (value === '' || isValidMinuteOrSecond(value))) {
13076
- onChange(value);
13434
+ isFirstStep() {
13435
+ if (this.state.active) {
13436
+ return this.state.members.filter((m) => m.visible)[0]?.uid === this.state.active;
13077
13437
  }
13078
- else if (type === 'second' && (value === '' || isValidMinuteOrSecond(value))) {
13079
- onChange(value);
13438
+ return false;
13439
+ }
13440
+ isLastStep() {
13441
+ if (this.state.active) {
13442
+ return this.state.members.filter((m) => m.visible && !m.disabled).slice(-1)[0]?.uid === this.state.active;
13080
13443
  }
13081
- else if (type === 'hour' && (value === '' || isValidHour(value))) {
13082
- onChange(value);
13444
+ return false;
13445
+ }
13446
+ isCurrentStepInError() {
13447
+ if (this.state.active) {
13448
+ const currentStep = this.getMember(this.state.active);
13449
+ return currentStep?.error !== undefined;
13083
13450
  }
13084
- };
13085
- return (jsxRuntimeExports.jsxs("div", { className: `o-time-selector-part o-time-selector-part-${size} o-time-${type}`, children: [jsxRuntimeExports.jsx(TogglerIcon, { className: isMin(value) ? 'o-time-selector-part-icon-disabled' : undefined, width: "20px", closeArrowPosition: "n", onClick: () => {
13086
- if (!isMin(value)) {
13087
- onChange(getNextValue(value, type === 'hour' ? 23 : 59, 'previous'));
13088
- }
13089
- } }, "previous"), jsxRuntimeExports.jsx(Input, { className: "o-time-input", value: value, size: size, selectOnFocus: true, onChange: onValueChange }, "value"), jsxRuntimeExports.jsx(TogglerIcon, { className: isMax(value, type) ? 'o-time-selector-part-icon-disabled' : undefined, width: "20px", closeArrowPosition: "s", onClick: () => {
13090
- if (!isMax(value, type)) {
13091
- onChange(getNextValue(value, type === 'hour' ? 23 : 59, 'next'));
13092
- }
13093
- } }, "next")] }));
13094
- };
13095
-
13096
- const getValue = (candidate, max, defaultValue) => {
13097
- if (typeof candidate === 'string') {
13098
- candidate = parseInt(candidate);
13451
+ return false;
13099
13452
  }
13100
- if (candidate === undefined || isNaN(candidate) || candidate < 0 || candidate > max) {
13101
- return defaultValue;
13453
+ isCurrentStepInVisibleError() {
13454
+ if (this.state.active) {
13455
+ const currentStep = this.getMember(this.state.active);
13456
+ return currentStep?.touchingError !== undefined;
13457
+ }
13458
+ return false;
13102
13459
  }
13103
- return candidate;
13104
- };
13105
- const TimeSelectorComponent = ({ value, onChange, size, edge, displayHours, displayMinutes, displaySeconds, }) => {
13106
- const d = new Date();
13107
- const hourInt = getValue(value.hour, 23, displayHours ? d.getHours() : 0);
13108
- const minuteInt = getValue(value.minute, 59, displayMinutes ? d.getMinutes() : 0);
13109
- const secondInt = getValue(value.second, 59, displaySeconds ? d.getSeconds() : 0);
13110
- const [internalHour, setInternalHour] = React.useState(String(hourInt).padStart(2, '0'));
13111
- const [internalMinute, setInternalMinute] = React.useState(String(minuteInt).padStart(2, '0'));
13112
- const [internalSecond, setInternalSecond] = React.useState(String(secondInt).padStart(2, '0'));
13113
- const hour = internalHour === '' ? '' : parseInt(internalHour) === hourInt ? internalHour : hourInt;
13114
- const minute = internalMinute === '' ? '' : parseInt(internalMinute) === minuteInt ? internalMinute : minuteInt;
13115
- const second = internalSecond === '' ? '' : parseInt(internalSecond) === secondInt ? internalSecond : secondInt;
13116
- const onChangeHour = React.useCallback((value) => {
13117
- setInternalHour(value);
13118
- if (value !== '') {
13119
- onChange(`${String(value || 0).padStart(2, '0')}:${String(minute || 0).padStart(2, '0')}:${String(second || 0).padStart(2, '0')}`, edge);
13460
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
13461
+ *done() {
13462
+ yield this.setSubmitting(true);
13463
+ if (this.state.onDone) {
13464
+ yield this.state.onDone();
13120
13465
  }
13121
- }, [minute, second, onChange]);
13122
- const onChangeMinute = React.useCallback((value) => {
13123
- setInternalMinute(value);
13124
- if (value !== '') {
13125
- onChange(`${String(hour || 0).padStart(2, '0')}:${String(value || 0).padStart(2, '0')}:${String(second || 0).padStart(2, '0')}`, edge);
13466
+ yield this.setSubmitting(false);
13467
+ }
13468
+ next() {
13469
+ if (this.isCurrentStepInError()) {
13470
+ const currentStep = this.getCurrentStep();
13471
+ if (currentStep) {
13472
+ this.touched(currentStep.uid);
13473
+ }
13126
13474
  }
13127
- }, [hour, second, onChange]);
13128
- const onChangeSecond = React.useCallback((value) => {
13129
- setInternalSecond(value);
13130
- if (value !== '') {
13131
- onChange(`${String(hour || 0).padStart(2, '0')}:${String(minute || 0).padStart(2, '0')}:${String(value || 0).padStart(2, '0')}`, edge);
13475
+ else {
13476
+ let result = true;
13477
+ if (this.state.onNext) {
13478
+ result = this.state.onNext(this.getCurrentStep(), this.getNextStep());
13479
+ }
13480
+ if (result) {
13481
+ this.activateNext();
13482
+ }
13132
13483
  }
13133
- }, [hour, minute, onChange]);
13134
- return (jsxRuntimeExports.jsxs("div", { className: "o-time-selector", children: [displayHours && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "hour", value: hour, onChange: onChangeHour, size: size }, "hour")), displayHours && (displayMinutes || displaySeconds) && (jsxRuntimeExports.jsx("span", { className: "o-time-separator", children: ":" }, "sep1")), displayMinutes && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "minute", value: minute, onChange: onChangeMinute, size: size }, "minute")), displaySeconds && (displayHours || displayMinutes) && (jsxRuntimeExports.jsx("span", { className: "o-time-separator", children: ":" }, "sep2")), displaySeconds && (jsxRuntimeExports.jsx(TimeSelectorPartComponent, { type: "second", value: second, onChange: onChangeSecond, size: size }, "second"))] }));
13484
+ }
13485
+ previous() {
13486
+ let result = true;
13487
+ if (this.state.onPrevious) {
13488
+ result = this.state.onPrevious(this.getCurrentStep(), this.getPreviousStep());
13489
+ }
13490
+ if (result) {
13491
+ this.activatePrevious();
13492
+ }
13493
+ }
13494
+ setSubmitting(submitting) {
13495
+ this.state.submitting = submitting;
13496
+ }
13135
13497
  };
13498
+ __decorate([
13499
+ onekijsFramework.reducer,
13500
+ __metadata("design:type", Function),
13501
+ __metadata("design:paramtypes", []),
13502
+ __metadata("design:returntype", void 0)
13503
+ ], exports.WizardService.prototype, "activateNext", null);
13504
+ __decorate([
13505
+ onekijsFramework.reducer,
13506
+ __metadata("design:type", Function),
13507
+ __metadata("design:paramtypes", []),
13508
+ __metadata("design:returntype", void 0)
13509
+ ], exports.WizardService.prototype, "activatePrevious", null);
13510
+ __decorate([
13511
+ onekijsFramework.saga(onekijsFramework.SagaEffect.Leading)
13512
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
13513
+ ,
13514
+ __metadata("design:type", Function),
13515
+ __metadata("design:paramtypes", []),
13516
+ __metadata("design:returntype", void 0)
13517
+ ], exports.WizardService.prototype, "done", null);
13518
+ __decorate([
13519
+ onekijsFramework.reducer,
13520
+ __metadata("design:type", Function),
13521
+ __metadata("design:paramtypes", []),
13522
+ __metadata("design:returntype", void 0)
13523
+ ], exports.WizardService.prototype, "next", null);
13524
+ __decorate([
13525
+ onekijsFramework.reducer,
13526
+ __metadata("design:type", Function),
13527
+ __metadata("design:paramtypes", []),
13528
+ __metadata("design:returntype", void 0)
13529
+ ], exports.WizardService.prototype, "previous", null);
13530
+ __decorate([
13531
+ onekijsFramework.reducer,
13532
+ __metadata("design:type", Function),
13533
+ __metadata("design:paramtypes", [Boolean]),
13534
+ __metadata("design:returntype", void 0)
13535
+ ], exports.WizardService.prototype, "setSubmitting", null);
13536
+ exports.WizardService = __decorate([
13537
+ onekijsFramework.service
13538
+ ], exports.WizardService);
13136
13539
 
13137
- const TimeRangeComponent = ({ edge, onChange, value, displayHours, displayMinutes, displaySeconds, }) => {
13138
- const valid = isValidDate(`${value.day}-${value.month}-${value.year}`);
13139
- let d;
13140
- if (valid) {
13141
- d = new Date(`${value.year}-${value.month}-${value.day}`);
13142
- }
13143
- const label = edge === 'to' ? 'an end' : 'a start';
13144
- return (jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx("div", { className: "o-time-edge-title", children: onekijsFramework.ucfirst(edge) }, "title"), !valid && (jsxRuntimeExports.jsxs("div", { className: "o-time-edge-empty", children: ["Please select ", label, " date for the period"] }, "empty")), valid && d && (jsxRuntimeExports.jsxs("div", { className: "o-time-edge-content", children: [jsxRuntimeExports.jsx("div", { className: "o-time-edge-date-container", children: jsxRuntimeExports.jsx("span", { className: "o-time-edge-date", children: d.toUTCString().split(' ', 4).join(' ') }) }, "date"), jsxRuntimeExports.jsx(TimeSelectorComponent, { value: value, onChange: onChange, size: "small", edge: edge, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds }, "selector")] }, "content"))] }));
13540
+ const useWizardController = ({ animate = 300, forwardOnly = true, onCancel, onDone, onNext, onPrevious, }) => {
13541
+ const [_, service] = onekijsFramework.useService(exports.WizardService, {
13542
+ members: [],
13543
+ membersIndex: {},
13544
+ animate,
13545
+ forwardOnly,
13546
+ onCancel,
13547
+ onDone,
13548
+ onNext,
13549
+ onPrevious,
13550
+ });
13551
+ return service;
13145
13552
  };
13146
13553
 
13147
- const TimeComponent = ({ from, to, type, className, onChange, displayHours, displayMinutes, displaySeconds, }) => {
13148
- if (type['range'] && type['date']) {
13149
- return (jsxRuntimeExports.jsxs("div", { className: addClassname('o-time-container-range', className), children: [jsxRuntimeExports.jsx(TimeRangeComponent, { type: type, value: from, edge: "from", onChange: onChange, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds }), jsxRuntimeExports.jsx(TimeRangeComponent, { type: type, value: to, edge: "to", onChange: onChange, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds })] }));
13150
- }
13151
- return (jsxRuntimeExports.jsx("div", { className: addClassname('o-time-container', className), children: jsxRuntimeExports.jsx(TimeSelectorComponent, { value: from, onChange: onChange, size: "large", edge: "from", displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds }, "selector") }));
13554
+ const UncontrolledWizardComponent = (props) => {
13555
+ const controller = useWizardController(props);
13556
+ return jsxRuntimeExports.jsx(ControlledWizardComponent, { ...props, controller: controller });
13152
13557
  };
13153
13558
 
13154
- const IconComponent = () => {
13155
- const { nullable, setOpen, onChange, open } = useDatePickerContext();
13156
- return (jsxRuntimeExports.jsxs("span", { className: "o-datepicker-icon", children: [nullable && (jsxRuntimeExports.jsx("div", { className: "o-datepicker-remover", onClick: () => {
13157
- onChange(null);
13158
- setOpen(false);
13159
- }, children: "\u2716" })), jsxRuntimeExports.jsx(CalendarIcon, { width: "20px", height: "20px", color: "primary", marginRight: "sm", onClick: () => setOpen(!open) })] }));
13160
- };
13161
- const parseDate = (value) => {
13162
- let date, time, year, month, day, hour, minute, second = undefined;
13163
- if (value) {
13164
- [date, time] = value.trim().split(' ');
13165
- [year, month, day] = date ? date.split('-') : [undefined, undefined, undefined];
13166
- [hour, minute, second] = time ? time.split(':') : [undefined, undefined, undefined];
13167
- }
13168
- return { date, time, year, month, day, hour, minute, second };
13169
- };
13170
- const isValidValue = (value, type) => {
13171
- const isValidDate = (value) => {
13172
- const d = new Date(value);
13173
- return !isNaN(d);
13174
- };
13175
- if (!value)
13176
- return true;
13177
- if (type.range) {
13178
- const [from, to] = value.split(' to ');
13179
- if (!from || !to)
13180
- return false;
13181
- return isValidDate(from) && isValidDate(to);
13559
+ const WizardComponent = (props) => {
13560
+ if (props.controller) {
13561
+ return jsxRuntimeExports.jsx(ControlledWizardComponent, { ...props, controller: props.controller });
13182
13562
  }
13183
13563
  else {
13184
- return isValidDate(value);
13564
+ return jsxRuntimeExports.jsx(UncontrolledWizardComponent, { ...props });
13185
13565
  }
13186
13566
  };
13187
- const isSameDate = (d1, d2, type) => {
13188
- const isSameDate = (d1, d2) => {
13189
- if (!d1 && !d2)
13190
- return true;
13191
- if (!d1 || !d2)
13192
- return false;
13193
- const date1 = new Date(`${d1}`);
13194
- const date2 = new Date(`${d2}`);
13195
- if (isNaN(date1) || isNaN(date2)) {
13196
- return false;
13197
- }
13198
- return date1.toString() === date2.toString();
13199
- };
13200
- if (d1 === null && d2 === null)
13201
- return true;
13202
- if (!d1 || !d2)
13203
- return false;
13204
- if (type.range) {
13205
- const [from1, to1] = d1.split(' to ');
13206
- const [from2, to2] = d2.split(' to ');
13207
- return isSameDate(from1, from2) && isSameDate(to1, to2);
13567
+
13568
+ const wizardStyle = ({ layout = 'vertical', theme, inModal }) => {
13569
+ const t = theme.wizard;
13570
+ const stepBorderWidthFn = layout === 'horizontal' ? borderBottomWidth : borderLeftWidth;
13571
+ const stepBorderStyleFn = layout === 'horizontal' ? borderBottomStyle : borderLeftStyle;
13572
+ const stepBorderColorFn = layout === 'horizontal' ? borderBottomColor : borderLeftColor;
13573
+ const wizardBorderWidthFn = layout === 'horizontal' ? borderBottomWidth : borderRightWidth;
13574
+ const wizardBorderStyleFn = layout === 'horizontal' ? borderBottomStyle : borderRightStyle;
13575
+ const wizardBorderColorFn = layout === 'horizontal' ? borderBottomColor : borderRightColor;
13576
+ return styled.css `
13577
+ ${display('flex')}
13578
+ ${flexDirection(layout === 'horizontal' ? 'column' : 'row')}
13579
+ .o-wizard-step-panel {
13580
+ ${display('flex')}
13581
+ ${flexDirection(layout === 'horizontal' ? 'row' : 'column')}
13582
+ ${alignItems(layout === 'horizontal' ? 'flex-end' : 'stretch')}
13583
+ ${wizardBorderStyleFn(inModal ? t.modalStepsBorderStyle : t.stepsBorderStyle)}
13584
+ ${wizardBorderWidthFn(inModal ? t.modalStepsBorderWidth : t.stepsBorderWidth)}
13585
+ ${wizardBorderColorFn(inModal ? t.modalStepsBorderColor : t.stepsBorderColor)}
13586
+ ${paddingRight(t.stepsPaddingRight)}
13587
+ ${paddingTop(t.stepsPaddingTop)}
13588
+ ${paddingLeft(t.stepsPaddingLeft)}
13589
+ ${paddingBottom(t.stepsPaddingBottom)}
13590
+ ${backgroundColor(inModal ? t.modalStepsBgColor : t.stepsBgColor)}
13208
13591
  }
13209
- else {
13210
- return isSameDate(d1, d2);
13592
+
13593
+ .o-step {
13594
+ ${paddingRight(t.paddingRight)}
13595
+ ${paddingTop(t.paddingTop)}
13596
+ ${paddingLeft(t.paddingLeft)}
13597
+ ${paddingBottom(t.paddingBottom)}
13598
+ ${stepBorderStyleFn(t.borderStyle)}
13599
+ ${stepBorderWidthFn(t.borderWidth)}
13600
+ ${stepBorderColorFn(t.borderColor)}
13601
+ ${fontWeight(t.fontWeight)}
13602
+ ${fontSize(t.fontSize)}
13603
+ ${color(t.fontColor)}
13211
13604
  }
13212
- };
13213
- const formatDate = (type, fromDate, fromTime, toDate, toTime) => {
13214
- const format = (date, time) => {
13215
- let result = '';
13216
- if (type.date) {
13217
- result += `${date || ''}`;
13218
- }
13219
- if (type.time) {
13220
- if (type.date && date) {
13221
- result += ` ${time || '00:00:00'}`;
13222
- }
13223
- else if (type.date && time) {
13224
- result += ` ${time}`;
13225
- }
13226
- else if (time) {
13227
- result += time;
13228
- }
13229
- }
13230
- return result;
13231
- };
13232
- let result = format(fromDate, fromTime);
13233
- if (type.range) {
13234
- result += ` to ${format(toDate, toTime)}`;
13605
+
13606
+ .o-step-active {
13607
+ ${stepBorderColorFn(t.activeBorderColor)}
13608
+ ${color(t.activeFontColor)}
13609
+ ${fontWeight(t.activeFontWeight)}
13610
+ ${fontSize(t.activeFontSize)}
13611
+ ${backgroundColor(t.activeBgColor)}
13612
+ &.o-step-enabled {
13613
+ ${cursor('default')}
13614
+ }
13615
+
13616
+ &.o-step-warning {
13617
+ ${stepBorderColorFn(t.warningBorderColor)}
13618
+ ${color(t.warningFontColor)}
13619
+ ${backgroundColor(t.warningBgColor)}
13620
+ }
13621
+ &.o-step-error {
13622
+ ${stepBorderColorFn(t.errorBorderColor)}
13623
+ ${color(t.errorFontColor)}
13624
+ ${backgroundColor(t.errorBgColor)}
13625
+ }
13235
13626
  }
13236
- return result;
13237
- };
13238
- const PickerComponent = ({ animationMs = 100, attachDropdownToBody = true, autoFocus, className, closeOnQuickSelect = true, combo = false, disabled, dropdownWidthModifier = 'min', label, nullable = false, onBlur: forwardBlur, onChange: forwardChange, onFocus: forwardFocus, openOnFocus = false, placeholder, placement = 'bottom-start', quickRanges, type, displayHours = true, displayMinutes = true, displaySeconds = true, value: externalValue, }) => {
13239
- const containerRef = React.useRef(null);
13240
- const stateRef = React.useRef({});
13241
- const dropdownRef = React.useRef(null);
13242
- const lastExternalValueRef = React.useRef(undefined);
13243
- const currentValueRef = React.useRef(null);
13244
- const [open, setOpen] = React.useState(false);
13245
- const [focus, setFocus] = React.useState(false);
13246
- const [Dropdown, triggerRef] = useDropdown();
13247
- const [internalValue, setInternalValue] = React.useState(null);
13248
- let value = internalValue ? internalValue : externalValue;
13249
- if (currentValueRef.current !== value && isSameDate(currentValueRef.current, value, type)) {
13250
- value = currentValueRef.current;
13627
+
13628
+ .o-step-inactive {
13629
+ &.o-step-success,
13630
+ &.o-step-touched {
13631
+ ${stepBorderColorFn(t.successBorderColor)}
13632
+ ${color(t.successFontColor)}
13633
+ }
13634
+ &.o-step-warning {
13635
+ ${stepBorderColorFn(t.warningBorderColor)}
13636
+ ${color(t.warningFontColor)}
13637
+ }
13638
+ &.o-step-error {
13639
+ ${stepBorderColorFn(t.errorBorderColor)}
13640
+ ${color(t.errorFontColor)}
13641
+ }
13251
13642
  }
13252
- const [fromString, toString] = value ? value.split(/ to\s*/) : [];
13253
- const validFromRef = React.useRef(undefined);
13254
- const validToRef = React.useRef(undefined);
13255
- if (!fromString || /\s*/.test(fromString)) {
13256
- validFromRef.current = undefined;
13643
+
13644
+ .o-step-enabled {
13645
+ ${cursor(t.cursor)}
13257
13646
  }
13258
- if (!toString || /\s*/.test(toString)) {
13259
- validToRef.current = undefined;
13647
+
13648
+ .o-step-disabled,
13649
+ .o-step-untouched {
13650
+ ${cursor('default')}
13651
+ ${stepBorderColorFn(t.disabledBorderColor)}
13652
+ ${color(t.disabledFontColor)}
13653
+ ${fontWeight(t.disabledFontWeight)}
13654
+ ${fontSize(t.disabledFontSize)}
13655
+ ${backgroundColor(t.disabledBgColor)}
13260
13656
  }
13261
- // this setting is used to detect if the user changes the from or the to
13262
- const nextSelectEdgeRef = React.useRef('to');
13263
- const from = parseDate(fromString?.trim());
13264
- const previousFrom = parseDate(validFromRef.current);
13265
- if (!type['date'] || !isValidDate(`${from['day']}-${from['month']}-${from['year']}`)) {
13266
- from.year = previousFrom.year;
13267
- from.month = previousFrom.month;
13268
- from.day = previousFrom.day;
13269
- from.date = previousFrom.date;
13657
+
13658
+ .o-step-disabled {
13659
+ ${cursor('not-allowed')}
13660
+ ${textDecoration('line-through')}
13270
13661
  }
13271
- if (type['date'] && isValidDate(`${from['day']}-${from['month']}-${from['year']}`)) {
13272
- validFromRef.current = `${from['year']}-${from['month']}-${from['day']}`;
13662
+
13663
+ .o-wizard-content-panel {
13664
+ ${display('flex')}
13665
+ ${flexDirection('column')}
13666
+ }
13667
+
13668
+ .o-wizard-content {
13669
+ ${flexGrow(1)}
13670
+ ${padding('lg')}
13671
+ ${paddingBottom(0)}
13672
+ ${paddingRight('3xl')}
13673
+ }
13674
+
13675
+ .o-wizard-control {
13676
+ ${display('flex')}
13677
+ ${justifyContent('flex-end')}
13678
+ ${padding('lg')}
13273
13679
  }
13274
- if (!type['time'] || !isValidTime(from['time'])) {
13275
- from.hour = previousFrom.hour;
13276
- from.minute = previousFrom.minute;
13277
- from.second = previousFrom.second;
13278
- from.time = previousFrom.time;
13680
+
13681
+ .o-wizard-control-button {
13682
+ ${marginLeft('sm')}
13279
13683
  }
13280
- if (type['time'] && isValidTime(`${from['time']}`)) {
13281
- if (validFromRef.current === undefined) {
13282
- validFromRef.current = '';
13283
- }
13284
- if (type['date']) {
13285
- validFromRef.current += ' ';
13286
- }
13287
- validFromRef.current += `${from['time']}`;
13684
+
13685
+ .o-wizard-title {
13686
+ ${fontSize('2xl')}
13687
+ ${fontWeight('light')}
13688
+ ${color('black')}
13689
+ ${lineHeight('4xl')}
13690
+ ${paddingBottom('md')}
13288
13691
  }
13289
- const to = parseDate(toString?.trim());
13290
- const previousTo = parseDate(validToRef.current);
13291
- if (!type['date'] || !isValidDate(`${to['day']}-${to['month']}-${to['year']}`)) {
13292
- to.year = previousTo.year;
13293
- to.month = previousTo.month;
13294
- to.day = previousTo.day;
13295
- to.date = previousTo.date;
13692
+
13693
+ .o-step-content-title {
13694
+ ${fontSize('2xl')}
13695
+ ${fontWeight('light')}
13696
+ ${color('black')}
13697
+ ${lineHeight('4xl')}
13698
+ ${paddingBottom('md')}
13296
13699
  }
13297
- if (type['date'] && isValidDate(`${to['day']}-${to['month']}-${to['year']}`)) {
13298
- validToRef.current = `${to['year']}-${to['month']}-${to['day']}`;
13700
+ `;
13701
+ };
13702
+ const wizardModalStyle = () => {
13703
+ return styled.css ``;
13704
+ };
13705
+ const wizardSummaryStyle = () => {
13706
+ return styled.css `
13707
+ .o-accordion-panel {
13708
+ ${paddingBottom('md')}
13299
13709
  }
13300
- if (!type['time'] || !isValidTime(to['time'])) {
13301
- to.hour = previousTo.hour;
13302
- to.minute = previousTo.minute;
13303
- to.second = previousTo.second;
13304
- to.time = previousTo.time;
13710
+ .o-accordion-panel-title {
13711
+ ${backgroundColor('lighter')}
13305
13712
  }
13306
- if (type['time'] && isValidTime(`${to['time']}`)) {
13307
- if (validToRef.current === undefined) {
13308
- validToRef.current = '';
13309
- }
13310
- if (type['date']) {
13311
- validToRef.current += ' ';
13312
- }
13313
- validToRef.current += `${to['time']}`;
13713
+ .o-accordion-content {
13714
+ ${paddingX('sm')}
13715
+ ${paddingBottom('sm')}
13314
13716
  }
13315
- const id = React.useId();
13316
- const onFocus = React.useCallback(() => {
13317
- if (!focus) {
13318
- setFocus(true);
13319
- if (openOnFocus && !open) {
13320
- setOpen(true);
13321
- }
13322
- if (forwardFocus) {
13323
- forwardFocus();
13324
- }
13325
- }
13326
- }, [focus, forwardFocus, openOnFocus, open]);
13327
- const onBlur = React.useCallback(() => {
13328
- if (!stateRef.current.keepFocus) {
13329
- if (open) {
13330
- setOpen(false);
13331
- }
13332
- if (focus) {
13333
- setFocus(false);
13334
- if (forwardBlur) {
13335
- forwardBlur();
13336
- }
13337
- }
13338
- }
13339
- }, [open, forwardBlur, setOpen, focus]);
13340
- const onChange = React.useCallback((nextValue, label) => {
13341
- currentValueRef.current = nextValue;
13342
- // check if the nextValue is a valid value
13343
- // if it's not a valid value, we keep it internally
13344
- if (forwardChange && isValidValue(nextValue, type)) {
13345
- setInternalValue(null);
13346
- forwardChange(nextValue, label);
13347
- }
13348
- else {
13349
- setInternalValue(nextValue);
13350
- }
13351
- }, [forwardChange, setInternalValue, type]);
13352
- const onChangeDate = (fromDate, toDate) => {
13353
- if (fromDate === undefined) {
13354
- fromDate = from['date'];
13355
- }
13356
- if (toDate === undefined) {
13357
- toDate = to['date'];
13358
- }
13359
- if (fromDate !== from['date']) {
13360
- nextSelectEdgeRef.current = 'to';
13361
- }
13362
- else {
13363
- nextSelectEdgeRef.current = 'from';
13364
- }
13365
- onChange(formatDate(type, fromDate, from['time'], toDate, to['time']));
13366
- };
13367
- const removeLabel = () => {
13368
- onChangeDate();
13369
- };
13370
- const onChangeTime = (nextTime, edge) => {
13371
- if (edge === 'from') {
13372
- onChange(formatDate(type, from['date'], nextTime, to['date'], to['time']));
13373
- }
13374
- else {
13375
- onChange(formatDate(type, from['date'], from['time'], to['date'], nextTime));
13376
- }
13377
- };
13378
- const onChangeQuickRange = (quickRangeLabel) => {
13379
- if (quickRanges) {
13380
- const quickRange = quickRanges[quickRangeLabel];
13381
- if (quickRange) {
13382
- onChange(`${quickRange.from} to ${quickRange.to}`, quickRangeLabel);
13383
- }
13384
- if (closeOnQuickSelect) {
13385
- setOpen(false);
13386
- }
13387
- }
13388
- };
13389
- const onOpen = React.useCallback(() => {
13390
- onekijsFramework.eventLocks.lock('escape', id);
13391
- }, [id]);
13392
- const onClosed = React.useCallback(() => {
13393
- onekijsFramework.eventLocks.unlock('escape', id);
13394
- if (lastExternalValueRef.current !== undefined) {
13395
- setInternalValue(null);
13396
- }
13397
- }, [id]);
13398
- useClickOutside([containerRef, dropdownRef], onBlur);
13399
- useFocusOutside([containerRef, dropdownRef], onBlur);
13400
- const context = React.useMemo(() => {
13401
- return {
13402
- open,
13403
- setOpen,
13404
- triggerRef,
13405
- nullable,
13406
- onChange,
13407
- };
13408
- }, [open, setOpen, triggerRef, nullable, onChange]);
13409
- React.useEffect(() => {
13410
- if (forwardChange &&
13411
- lastExternalValueRef.current !== undefined &&
13412
- externalValue !== undefined &&
13413
- externalValue !== lastExternalValueRef.current) {
13414
- // case when we block the onChange due to a wrong internal value
13415
- // and the value is changed from the exterior (not due to change done internally)
13416
- setInternalValue(null);
13417
- }
13418
- lastExternalValueRef.current = externalValue;
13419
- });
13420
- return (jsxRuntimeExports.jsx(DefaultDatePickerContext.Provider, { value: context, children: jsxRuntimeExports.jsxs("div", { className: addClassname('o-datepicker', className), ref: containerRef, onMouseDown: () => (stateRef.current.keepFocus = true), onMouseUp: () => (stateRef.current.keepFocus = false), children: [jsxRuntimeExports.jsx(Dropdown, { attachToBody: attachDropdownToBody, open: open, distance: 0, animationTimeout: animationMs, onDropStart: onOpen, onCollapseDone: onClosed, placement: placement, widthModifier: dropdownWidthModifier, className: className, zIndex: attachDropdownToBody ? 2000 : undefined, children: jsxRuntimeExports.jsxs("div", { ref: dropdownRef, className: `o-datepicker-dropdown-content${type['range'] ? ' o-datepicker-range' : ''}${validFromRef.current !== undefined ? ' o-datepicker-active' : ''}`, children: [type['range'] && quickRanges && Object.keys(quickRanges).length > 0 && (jsxRuntimeExports.jsx(QuickTimeRangeComponent, { quickRanges: quickRanges, onChange: onChangeQuickRange, currentQuickRangeLabel: label }, "quick_range")), type['date'] && (jsxRuntimeExports.jsx("div", { className: "o-calendar", children: jsxRuntimeExports.jsx(CalendarComponent, { from: from, to: to, type: type, onChange: onChangeDate, nextSelectEdge: nextSelectEdgeRef.current }) }, "calendar")), type['time'] && (jsxRuntimeExports.jsx("div", { className: "o-time", children: jsxRuntimeExports.jsx(TimeComponent, { from: from, to: to, type: type, onChange: onChangeTime, displayHours: displayHours, displayMinutes: displayMinutes, displaySeconds: displaySeconds }) }, "time"))] }) }), jsxRuntimeExports.jsx("span", { ref: triggerRef, children: jsxRuntimeExports.jsx(Input, { className: "o-datepicker-input", placeholder: placeholder, onChange: (e) => onChange(e.target.value), value: label ? label : !value ? '' : value, onFocus: onFocus, onBlur: onBlur, autoFocus: autoFocus, disabled: disabled, SuffixComponent: IconComponent, readOnly: !combo, onClick: () => {
13421
- if (!open) {
13422
- setOpen(true);
13423
- }
13424
- else if (combo) {
13425
- removeLabel();
13426
- }
13427
- else {
13428
- setOpen(false);
13429
- }
13430
- } }) }, "input")] }) }));
13717
+ `;
13431
13718
  };
13432
13719
 
13433
- const type$5 = {
13434
- date: true,
13435
- time: false,
13436
- range: false,
13437
- };
13438
- const DatePickerComponent = (props) => {
13439
- const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13440
- const onChange = forwardChange
13441
- ? (value) => {
13442
- if (value === null || !adapter) {
13443
- forwardChange(value);
13444
- }
13445
- else {
13446
- forwardChange(adapter.fromDate(value));
13447
- }
13720
+ const Wizard = styled(WizardComponent) `
13721
+ ${wizardStyle}
13722
+ `;
13723
+
13724
+ const useStep = (props) => {
13725
+ const service = useWizardService();
13726
+ const state = useWizardState();
13727
+ const step = state.members[state.membersIndex[props.uid]];
13728
+ React.useEffect(() => {
13729
+ if (step === undefined) {
13730
+ service.initMember(Object.assign({ uid: props.uid }, props));
13448
13731
  }
13449
- : undefined;
13450
- let value = externalValue
13451
- ? adapter
13452
- ? adapter.toDate(externalValue)
13453
- : externalValue
13454
- : null;
13455
- return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$5 });
13732
+ }, [props, service, step]);
13733
+ return step;
13456
13734
  };
13457
13735
 
13458
- const type$4 = {
13459
- date: true,
13460
- time: false,
13461
- range: true,
13462
- };
13463
- const DateRangePickerComponent = (props) => {
13464
- const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13465
- const onChange = forwardChange
13466
- ? (value, label) => {
13467
- const dateRange = toDateRange(value, label);
13468
- if (dateRange === null || !adapter) {
13469
- forwardChange(dateRange);
13470
- }
13471
- else {
13472
- forwardChange(adapter.fromDateRange(dateRange));
13473
- }
13474
- }
13475
- : undefined;
13476
- let value = null;
13477
- let valueLabel;
13478
- if (externalValue) {
13479
- if (adapter) {
13480
- const { from, to, label } = adapter.toDateRange(externalValue);
13481
- value = `${from || ''} to ${to || ''}`;
13482
- valueLabel = label;
13483
- }
13484
- else {
13485
- value = `${externalValue.from || ''} to ${externalValue.to || ''}`;
13486
- valueLabel = externalValue.label;
13736
+ const Step = ({ title, active = false, disabled = false, visible = true, closable = false, children, icon, uid, optional = false, showTitle = true, className, onTouch, help, }) => {
13737
+ const { animate, forwardOnly } = useWizardState();
13738
+ const stepRef = React.useRef(null);
13739
+ const step = useStep({
13740
+ title,
13741
+ active,
13742
+ disabled,
13743
+ visible,
13744
+ closable,
13745
+ icon,
13746
+ loading: false,
13747
+ optional,
13748
+ touched: !forwardOnly,
13749
+ touching: !forwardOnly,
13750
+ uid: uid === undefined ? title : uid,
13751
+ });
13752
+ const touched = step?.touched;
13753
+ const onEnter = () => {
13754
+ const node = stepRef.current;
13755
+ if (!node)
13756
+ return;
13757
+ node.style.opacity = '0';
13758
+ };
13759
+ const onEntering = () => {
13760
+ const node = stepRef.current;
13761
+ if (!node)
13762
+ return;
13763
+ setTimeout(() => {
13764
+ node.style.opacity = '1';
13765
+ node.style.transition = `opacity ${animate}ms ease-in-out`;
13766
+ }, 0);
13767
+ };
13768
+ React.useEffect(() => {
13769
+ if (touched && onTouch) {
13770
+ onTouch();
13487
13771
  }
13772
+ }, [touched, onTouch]);
13773
+ if (!step || !step.active) {
13774
+ return null;
13488
13775
  }
13489
- return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$4, label: valueLabel });
13776
+ return (jsxRuntimeExports.jsx(reactTransitionGroup.CSSTransition, { in: true, nodeRef: stepRef, timeout: animate, appear: true, onEnter: onEnter, onEntering: onEntering, children: jsxRuntimeExports.jsxs("div", { ref: stepRef, className: addClassname('o-step-content', className), children: [showTitle && jsxRuntimeExports.jsx("div", { className: "o-step-content-title", children: title }), help && (jsxRuntimeExports.jsx(Alert, { kind: "info", marginBottom: "lg", children: help })), children] }) }));
13490
13777
  };
13491
13778
 
13492
- const type$3 = {
13493
- date: true,
13494
- time: true,
13495
- range: false,
13496
- };
13497
- const DateTimePickerComponent = (props) => {
13498
- const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13499
- const onChange = forwardChange
13500
- ? (value) => {
13501
- if (value === null || !adapter) {
13502
- forwardChange(value);
13779
+ const FormStep = ({ name, disabled = false, visible = true, ...stepProps }) => {
13780
+ const decorator = onekijsFramework.useFormDecorator(name, {
13781
+ Displayer: (displayerProps) => {
13782
+ const total = Object.values(displayerProps.children ?? {}).length;
13783
+ return (jsxRuntimeExports.jsx(AccordionPanel, { title: stepProps.title, initialActive: displayerProps.index === 0, initialExpand: displayerProps.index === 0, children: Object.values(displayerProps.children ?? {}).map((field, index) => {
13784
+ const Displayer = field.Displayer ?? onekijsFramework.DefaultDisplayer;
13785
+ return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === total - 1, format: displayerProps.format }));
13786
+ }) }));
13787
+ },
13788
+ });
13789
+ const metadata = onekijsFramework.useFormMetadata(decorator.name);
13790
+ const service = useWizardService();
13791
+ const fieldContainer = onekijsFramework.useFieldContainer({
13792
+ container: name,
13793
+ onValidationChange: (touchedValidation, allValidation) => {
13794
+ service.onValidationChange(name, touchedValidation, allValidation);
13795
+ },
13796
+ });
13797
+ const { touchAllFields, hide, show, disable, enable } = fieldContainer;
13798
+ const initializedRef = React.useRef(false);
13799
+ React.useEffect(() => {
13800
+ const visible = metadata.visible ?? true;
13801
+ const disabled = metadata.disabled ?? false;
13802
+ if (!visible) {
13803
+ if (disabled) {
13804
+ service.disable(name);
13805
+ disable();
13503
13806
  }
13504
13807
  else {
13505
- forwardChange(adapter.fromDate(value));
13808
+ service.enable(name);
13809
+ if (initializedRef.current === true) {
13810
+ // we only use the enable method if this is a change and not a initialization
13811
+ enable();
13812
+ }
13506
13813
  }
13814
+ service.hide(name);
13815
+ hide();
13507
13816
  }
13508
- : undefined;
13509
- let value = externalValue
13510
- ? adapter
13511
- ? adapter.toDate(externalValue)
13512
- : externalValue
13513
- : null;
13514
- return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$3 });
13515
- };
13516
-
13517
- const type$2 = {
13518
- date: true,
13519
- time: true,
13520
- range: true,
13521
- };
13522
- const DateTimeRangePickerComponent = (props) => {
13523
- const { onChange: forwardChange, value: externalValue, adapter, ...datePickerProps } = props;
13524
- const onChange = forwardChange
13525
- ? (value, label) => {
13526
- const dateRange = toDateRange(value, label);
13527
- if (dateRange === null || !adapter) {
13528
- forwardChange(dateRange);
13817
+ else {
13818
+ service.show(name);
13819
+ if (initializedRef.current === true) {
13820
+ // we only use the show method if this is a change and not a initialization
13821
+ show();
13822
+ }
13823
+ if (disabled) {
13824
+ service.disable(name);
13825
+ disable();
13529
13826
  }
13530
13827
  else {
13531
- forwardChange(adapter.fromDateRange(dateRange));
13828
+ service.enable(name);
13829
+ if (initializedRef.current === true) {
13830
+ // we only use the enable method if this is a change and not a initialization
13831
+ enable();
13832
+ }
13532
13833
  }
13533
13834
  }
13534
- : undefined;
13535
- let value = null;
13536
- let valueLabel;
13537
- if (externalValue) {
13538
- if (adapter) {
13539
- const { from, to, label } = adapter.toDateRange(externalValue);
13540
- value = `${from || ''} to ${to || ''}`;
13541
- valueLabel = label;
13542
- }
13543
- else {
13544
- value = `${externalValue.from || ''} to ${externalValue.to || ''}`;
13545
- valueLabel = externalValue.label;
13546
- }
13547
- }
13548
- return jsxRuntimeExports.jsx(PickerComponent, { ...datePickerProps, value: value, onChange: onChange, type: type$2, label: valueLabel });
13835
+ initializedRef.current = true;
13836
+ }, [name, metadata.visible, metadata.disabled]);
13837
+ // useEffect(() => {
13838
+ // if (!visible) {
13839
+ // if (disabled) {
13840
+ // disable();
13841
+ // } else {
13842
+ // enable();
13843
+ // }
13844
+ // hide();
13845
+ // } else {
13846
+ // show();
13847
+ // if (disabled) {
13848
+ // disable();
13849
+ // } else {
13850
+ // enable();
13851
+ // }
13852
+ // }
13853
+ // }, [visible, disabled, hide, show, disable, enable]);
13854
+ return (jsxRuntimeExports.jsx(onekijsFramework.FormContext.Provider, { value: fieldContainer.context, children: jsxRuntimeExports.jsx(Step, { ...stepProps, uid: name, onTouch: touchAllFields }) }));
13549
13855
  };
13550
13856
 
13551
- const type$1 = {
13552
- date: false,
13553
- time: true,
13554
- range: false,
13555
- };
13556
- const TimePickerComponent = (props) => {
13557
- return jsxRuntimeExports.jsx(PickerComponent, { ...props, type: type$1 });
13857
+ const WizardModalComponent = ({ title, doneLabel = 'Submit', ...props }) => {
13858
+ return (jsxRuntimeExports.jsx(Modal, { ...props, children: jsxRuntimeExports.jsx(Wizard, { ...props, title: title, doneLabel: doneLabel, inModal: true }) }));
13558
13859
  };
13559
13860
 
13560
- const type = {
13561
- date: false,
13562
- time: true,
13563
- range: true,
13564
- };
13565
- const TimeRangePickerComponent = (props) => {
13566
- return jsxRuntimeExports.jsx(PickerComponent, { ...props, type: type });
13861
+ const WizardSummaryComponent = ({ className }) => {
13862
+ const form = onekijsFramework.useForm();
13863
+ const tree = Object.values(form.getDisplayerTree());
13864
+ return (jsxRuntimeExports.jsx(Accordion, { className: className, children: tree.map((field, index) => {
13865
+ const Displayer = field.Displayer || onekijsFramework.DefaultDisplayer;
13866
+ return (React.createElement(Displayer, { ...field, index: index, key: `field-${index}`, first: index === 0, last: index === tree.length - 1, format: "form_summary" }));
13867
+ }) }));
13567
13868
  };
13568
13869
 
13569
- const DatePicker = styled(DatePickerComponent) `
13570
- ${datePickerStyle}
13571
- `;
13572
- const DateRangePicker = styled(DateRangePickerComponent) `
13573
- ${datePickerStyle}
13574
- `;
13575
- const DateTimePicker = styled(DateTimePickerComponent) `
13576
- ${datePickerStyle}
13577
- `;
13578
- const DateTimeRangePicker = styled(DateTimeRangePickerComponent) `
13579
- ${datePickerStyle}
13580
- `;
13581
- const TimePicker = styled(TimePickerComponent) `
13582
- ${datePickerStyle}
13583
- `;
13584
- const TimeRangePicker = styled(TimeRangePickerComponent) `
13585
- ${datePickerStyle}
13870
+ const WizardModal = styled(WizardModalComponent) `
13871
+ ${wizardModalStyle}
13586
13872
  `;
13587
13873
 
13588
- const useQuickRanges = (ranges) => {
13589
- const result = onekijsFramework.useLazyRef(() => {
13590
- if (!Array.isArray(ranges)) {
13591
- ranges = [ranges];
13592
- }
13593
- const quickRanges = ranges.reduce((accumulator, range) => {
13594
- if (typeof range === 'string') {
13595
- if (range === 'all') {
13596
- accumulator = Object.assign(accumulator, defaultQuickRanges());
13597
- }
13598
- else {
13599
- const dateRange = qr(range);
13600
- if (dateRange !== null) {
13601
- accumulator[range] = dateRange;
13602
- }
13603
- }
13604
- }
13605
- else {
13606
- accumulator[range.label] = range;
13607
- }
13608
- return accumulator;
13609
- }, {});
13610
- const target = Object.keys(quickRanges).reduce((accumulator, label) => {
13611
- accumulator[label] = {
13612
- from: null,
13613
- to: null,
13614
- label,
13615
- };
13616
- return accumulator;
13617
- }, {});
13618
- const handler = {
13619
- get: function (_, prop) {
13620
- if (typeof prop === 'string') {
13621
- const quickRange = quickRanges[prop];
13622
- if (quickRange) {
13623
- return {
13624
- from: dateToString(quickRange.from),
13625
- to: dateToString(quickRange.to),
13626
- label: quickRange.label,
13627
- };
13628
- }
13629
- }
13630
- return undefined;
13631
- },
13632
- };
13633
- return new Proxy(target, handler);
13634
- });
13635
- return result.current;
13636
- };
13637
-
13638
- const useDateRangeAdapter = () => {
13639
- const ref = React.useRef({
13640
- fromDateRange: (range) => {
13641
- return {
13642
- from: range.from === null ? null : new Date(range.from),
13643
- to: range.to === null ? null : new Date(range.to),
13644
- label: range.label,
13645
- };
13646
- },
13647
- toDateRange: (value) => {
13648
- return {
13649
- from: !value.from ? null : dateToString(value.from),
13650
- to: !value.to ? null : dateToString(value.to),
13651
- label: value.label,
13652
- };
13653
- },
13654
- });
13655
- return ref.current;
13656
- };
13657
-
13658
- const useTimestampRangeAdapter = (format = 'milliseconds') => {
13659
- const toTimestamp = (date) => {
13660
- if (!date)
13661
- return null;
13662
- const d = new Date(date);
13663
- if (isNaN(d))
13664
- return null;
13665
- const timestamp = d.getTime();
13666
- return format === 'milliseconds' ? timestamp : Math.floor(timestamp / 1000);
13667
- };
13668
- const fromTimestamp = (timestamp) => {
13669
- if (timestamp === null || timestamp === undefined)
13670
- return null;
13671
- if (format === 'seconds') {
13672
- timestamp = timestamp * 1000;
13673
- }
13674
- const d = new Date(timestamp);
13675
- if (isNaN(d))
13676
- return null;
13677
- return dateToString(d);
13678
- };
13679
- const ref = React.useRef({
13680
- fromDateRange: (range) => {
13681
- return {
13682
- from: toTimestamp(range.from),
13683
- to: toTimestamp(range.to),
13684
- label: range.label,
13685
- };
13686
- },
13687
- toDateRange: (value) => {
13688
- return {
13689
- from: fromTimestamp(value.from),
13690
- to: fromTimestamp(value.to),
13691
- label: value.label,
13692
- };
13693
- },
13694
- });
13695
- return ref.current;
13696
- };
13874
+ const WizardSummary = styled(WizardSummaryComponent) `
13875
+ ${wizardSummaryStyle}
13876
+ `;
13697
13877
 
13698
13878
  const animation = cssProperty('animation');
13699
13879
  const animationDelay = cssProperty('animation-delay');
@@ -14646,6 +14826,10 @@ exports.FormBlock = FormBlock;
14646
14826
  exports.FormCard = FormCard;
14647
14827
  exports.FormCardDisplayer = FormCardDisplayer;
14648
14828
  exports.FormCheckbox = FormCheckbox;
14829
+ exports.FormDatePicker = FormDatePicker;
14830
+ exports.FormDateRangePicker = FormDateRangePicker;
14831
+ exports.FormDateTimePicker = FormDateTimePicker;
14832
+ exports.FormDateTimeRangePicker = FormDateTimeRangePicker;
14649
14833
  exports.FormInput = FormInput;
14650
14834
  exports.FormSelect = FormSelect$1;
14651
14835
  exports.FormStep = FormStep;
@@ -14841,6 +15025,7 @@ exports.cursor = cursor;
14841
15025
  exports.darken = darken;
14842
15026
  exports.dashboardOverlayStyle = dashboardOverlayStyle;
14843
15027
  exports.datePickerStyle = datePickerStyle;
15028
+ exports.dateRangeAdapter = dateRangeAdapter;
14844
15029
  exports.dateToString = dateToString;
14845
15030
  exports.defaultCellSerializer = defaultCellSerializer;
14846
15031
  exports.defaultQuickRanges = defaultQuickRanges;
@@ -15022,6 +15207,9 @@ exports.textUnderlinePosition = textUnderlinePosition;
15022
15207
  exports.textareaColumn = textareaColumn;
15023
15208
  exports.themeFormatter = themeFormatter;
15024
15209
  exports.timerStyle = timerStyle;
15210
+ exports.timestampMilliSecondRangeAdapter = timestampMilliSecondRangeAdapter;
15211
+ exports.timestampRangeAdapter = timestampRangeAdapter;
15212
+ exports.timestampSecondRangeAdapter = timestampSecondRangeAdapter;
15025
15213
  exports.titlelize = titlelize;
15026
15214
  exports.toCss = toCss;
15027
15215
  exports.toDateRange = toDateRange;