trotl-filter 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.
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var React = require('react');
6
4
  var reactDom = require('react-dom');
7
5
 
@@ -24,6 +22,16 @@ function _interopNamespaceDefault(e) {
24
22
 
25
23
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
24
 
25
+ function _extends$1() {
26
+ return _extends$1 = Object.assign ? Object.assign.bind() : function (n) {
27
+ for (var e = 1; e < arguments.length; e++) {
28
+ var t = arguments[e];
29
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
30
+ }
31
+ return n;
32
+ }, _extends$1.apply(null, arguments);
33
+ }
34
+
27
35
  function _typeof(o) {
28
36
  "@babel/helpers - typeof";
29
37
 
@@ -1570,6 +1578,10 @@ var createCache = function createCache(options) {
1570
1578
  return cache;
1571
1579
  };
1572
1580
 
1581
+ function getDefaultExportFromCjs (x) {
1582
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1583
+ }
1584
+
1573
1585
  var reactIs = {exports: {}};
1574
1586
 
1575
1587
  var reactIs_production_min = {};
@@ -6997,11 +7009,75 @@ const MultiSelectDropdown = ({
6997
7009
  onChange,
6998
7010
  theme = "light",
6999
7011
  placeholder = "Select...",
7000
- maxVisible = 1,
7001
7012
  required = false,
7002
- closeMenuOnSelect = false
7013
+ closeMenuOnSelect = false,
7014
+ pushUrlParamObj = false,
7015
+ // pushUrlParamObj={"ids"}
7016
+ addItem = undefined
7003
7017
  }) => {
7004
7018
  const containerRef = React.useRef(null);
7019
+ const [maxVisible, setMaxVisible] = React.useState(1);
7020
+ React.useEffect(() => {
7021
+ if (!containerRef.current) return;
7022
+ const containerWidth = containerRef.current.offsetWidth || 200;
7023
+ // Estimate average tag width (adjust as needed for your style)
7024
+ const avgTagWidth = 90; // px, tweak for your font/size
7025
+ const calculated = Math.max(1, Math.floor((containerWidth - 40) / avgTagWidth));
7026
+ setMaxVisible(calculated);
7027
+ // Optionally, recalculate on window resize:
7028
+ const handleResize = () => {
7029
+ const w = containerRef.current.offsetWidth || 200;
7030
+ setMaxVisible(Math.max(1, Math.floor((w - 40) / avgTagWidth)));
7031
+ };
7032
+ window.addEventListener("resize", handleResize);
7033
+ return () => window.removeEventListener("resize", handleResize);
7034
+ }, []);
7035
+
7036
+ // On mount, read from URL param if present and set values by matching with options
7037
+ React.useEffect(() => {
7038
+ if (!pushUrlParamObj || !options || options.length === 0) return;
7039
+ const readFromUrl = () => {
7040
+ const params = new URLSearchParams(window.location.search);
7041
+ const urlVal = params.get(pushUrlParamObj);
7042
+ if (urlVal) {
7043
+ if (isMulti) {
7044
+ const urlValues = urlVal.split(",").filter(Boolean);
7045
+ const matchedValues = urlValues.map(v => {
7046
+ const found = options.find(opt => String(opt.value) === String(v));
7047
+ return found ? found.value : null;
7048
+ }).filter(v => v !== null);
7049
+ if (matchedValues.length > 0 && JSON.stringify(matchedValues) !== JSON.stringify(selected)) {
7050
+ onChange?.(matchedValues);
7051
+ }
7052
+ } else {
7053
+ const found = options.find(opt => String(opt.value) === String(urlVal));
7054
+ if (found && (!selected || selected[0] !== found.value)) {
7055
+ onChange?.([found.value]);
7056
+ }
7057
+ }
7058
+ }
7059
+ };
7060
+ readFromUrl();
7061
+ window.addEventListener("popstate", readFromUrl);
7062
+ // Listen for pushState/replaceState (programmatic changes)
7063
+ const patchHistory = type => {
7064
+ const orig = window.history[type];
7065
+ window.history[type] = function () {
7066
+ const rv = orig.apply(this, arguments);
7067
+ window.dispatchEvent(new Event(type));
7068
+ return rv;
7069
+ };
7070
+ };
7071
+ patchHistory('pushState');
7072
+ patchHistory('replaceState');
7073
+ window.addEventListener('pushState', readFromUrl);
7074
+ window.addEventListener('replaceState', readFromUrl);
7075
+ return () => {
7076
+ window.removeEventListener("popstate", readFromUrl);
7077
+ window.removeEventListener('pushState', readFromUrl);
7078
+ window.removeEventListener('replaceState', readFromUrl);
7079
+ };
7080
+ }, [pushUrlParamObj, isMulti, options, selected, onChange]);
7005
7081
  const selectedOptions = React.useMemo(() => {
7006
7082
  if (isMulti) {
7007
7083
  return options.filter(opt => selected.includes(opt.value));
@@ -7009,13 +7085,94 @@ const MultiSelectDropdown = ({
7009
7085
  return options.find(opt => opt.value === selected[0]) || null;
7010
7086
  }
7011
7087
  }, [selected, options, isMulti]);
7088
+ const setUrlParam = value => {
7089
+ if (!pushUrlParamObj) return;
7090
+ const url = new URL(window.location);
7091
+ if (!value) {
7092
+ url.searchParams.delete(pushUrlParamObj);
7093
+ } else {
7094
+ url.searchParams.set(pushUrlParamObj, value);
7095
+ }
7096
+ window.history.replaceState({}, "", url);
7097
+ };
7098
+
7099
+ // For custom input: track input value and show add button as inline option
7100
+ const [inputValue, setInputValue] = React.useState("");
7101
+ const inputExists = React.useMemo(() => {
7102
+ return options.some(opt => String(opt.label).toLowerCase() === inputValue.trim().toLowerCase());
7103
+ }, [inputValue, options]);
7104
+
7105
+ // Add special option for +Add if inputValue is non-empty and not in options
7106
+ const menuOptions = React.useMemo(() => {
7107
+ if (inputValue && !inputExists && typeof addItem === 'function') {
7108
+ return [...options, {
7109
+ label: `+ Add "${inputValue.trim()}"`,
7110
+ value: '__add_new__',
7111
+ __isAddNew: true
7112
+ }];
7113
+ }
7114
+ return options;
7115
+ }, [options, inputValue, inputExists, addItem]);
7116
+ const handleAddNew = () => {
7117
+ if (!inputValue.trim()) return;
7118
+ const newLabel = inputValue.trim();
7119
+ // Prevent duplicate by value or label (case-insensitive)
7120
+ const exists = options.some(opt => String(opt.value).toLowerCase() === newLabel.toLowerCase() || String(opt.label).toLowerCase() === newLabel.toLowerCase());
7121
+ if (exists) {
7122
+ setInputValue("");
7123
+ return;
7124
+ }
7125
+ const newOption = {
7126
+ label: newLabel,
7127
+ value: newLabel
7128
+ };
7129
+ if (typeof addItem === 'function') {
7130
+ addItem(newOption);
7131
+ // return;
7132
+ }
7133
+ if (isMulti) {
7134
+ onChange([...(selected || []), newOption.value]);
7135
+ if (pushUrlParamObj) setUrlParam([...(selected || []), newOption.value].join(","));
7136
+ } else {
7137
+ onChange([newOption.value]);
7138
+ if (pushUrlParamObj) setUrlParam(newOption.value);
7139
+ }
7140
+ setInputValue("");
7141
+ };
7142
+
7143
+ // Custom Option to handle +Add
7144
+ const Option = props => {
7145
+ if (props.data.__isAddNew) {
7146
+ return /*#__PURE__*/React.createElement("div", _extends$1({}, props.innerProps, {
7147
+ style: {
7148
+ padding: '8px 12px',
7149
+ cursor: 'pointer',
7150
+ color: '#1677ff',
7151
+ fontWeight: 500,
7152
+ background: props.isFocused ? '#e6f4ff' : '#fff'
7153
+ },
7154
+ onMouseDown: e => {
7155
+ e.preventDefault();
7156
+ handleAddNew();
7157
+ props.selectOption(props.data);
7158
+ }
7159
+ }), props.data.label);
7160
+ }
7161
+ return /*#__PURE__*/React.createElement(components.Option, props);
7162
+ };
7012
7163
  const handleChange = selectedItems => {
7013
7164
  if (isMulti) {
7014
7165
  const values = selectedItems ? selectedItems.map(item => item.value) : [];
7015
7166
  onChange(values);
7167
+ if (pushUrlParamObj) {
7168
+ setUrlParam(values.length ? values.join(",") : "");
7169
+ }
7016
7170
  } else {
7017
7171
  const value = selectedItems ? [selectedItems.value] : [];
7018
7172
  onChange(value);
7173
+ if (pushUrlParamObj) {
7174
+ setUrlParam(value.length ? value[0] : "");
7175
+ }
7019
7176
  }
7020
7177
  };
7021
7178
  const MultiValue = props => {
@@ -7025,9 +7182,13 @@ const MultiSelectDropdown = ({
7025
7182
  } = props;
7026
7183
  const allSelected = getValue();
7027
7184
  const hiddenCount = allSelected.length - maxVisible;
7185
+
7186
+ // Only render visible tags
7028
7187
  if (index < maxVisible) {
7029
7188
  return /*#__PURE__*/React.createElement(components.MultiValue, props);
7030
7189
  }
7190
+
7191
+ // Only render +N for the first hidden slot
7031
7192
  if (index === maxVisible && hiddenCount > 0) {
7032
7193
  const hiddenLabels = allSelected.slice(maxVisible).map(opt => opt.label).join(", ");
7033
7194
  return /*#__PURE__*/React.createElement("div", {
@@ -7037,13 +7198,17 @@ const MultiSelectDropdown = ({
7037
7198
  backgroundColor: theme === "dark" ? "#333" : "#e0e0e0",
7038
7199
  color: theme === "dark" ? "#eee" : "#333",
7039
7200
  borderRadius: 4,
7040
- padding: "0 6px",
7041
- fontSize: "0.8em",
7042
- alignSelf: "center",
7201
+ padding: "2px 8px",
7202
+ fontSize: "0.85em",
7203
+ display: "inline-flex",
7204
+ alignItems: "center",
7205
+ marginLeft: 4,
7043
7206
  cursor: "default"
7044
7207
  }
7045
7208
  }, "+", hiddenCount);
7046
7209
  }
7210
+
7211
+ // Don't render anything for other hidden tags
7047
7212
  return null;
7048
7213
  };
7049
7214
  const selectStyle = {
@@ -7105,6 +7270,11 @@ const MultiSelectDropdown = ({
7105
7270
  menuPortal: base => ({
7106
7271
  ...base,
7107
7272
  zIndex: 999999
7273
+ }),
7274
+ valueContainer: base => ({
7275
+ ...base,
7276
+ flexWrap: "nowrap",
7277
+ overflow: "hidden"
7108
7278
  })
7109
7279
  };
7110
7280
  const showRequiredError = required && (!selected || selected.length === 0);
@@ -7116,417 +7286,2951 @@ const MultiSelectDropdown = ({
7116
7286
  className: showRequiredError ? "select-required-error" : ""
7117
7287
  }, /*#__PURE__*/React.createElement(StateManagedSelect$1, {
7118
7288
  isMulti: isMulti,
7119
- options: options,
7289
+ options: menuOptions,
7120
7290
  value: selectedOptions,
7121
- onChange: handleChange,
7291
+ onChange: (val, action) => {
7292
+ // If user selects the +Add option, handle it
7293
+ if (action && action.action === 'select-option' && val && val.length && val[val.length - 1]?.__isAddNew) {
7294
+ handleAddNew();
7295
+ return;
7296
+ }
7297
+ handleChange(val);
7298
+ },
7122
7299
  placeholder: placeholder,
7123
7300
  styles: selectStyle,
7124
7301
  components: {
7125
- MultiValue
7302
+ MultiValue,
7303
+ Option
7126
7304
  },
7127
7305
  menuPortalTarget: document.body,
7128
7306
  closeMenuOnSelect: closeMenuOnSelect,
7129
- "aria-required": required // ✅ Accessibility hint
7307
+ "aria-required": required,
7308
+ inputValue: inputValue,
7309
+ onInputChange: (val, action) => {
7310
+ if (action.action === "input-change") setInputValue(val);
7311
+ }
7130
7312
  }), showRequiredError && /*#__PURE__*/React.createElement("div", {
7131
7313
  className: "error-text"
7132
7314
  }, "This field is required."));
7133
7315
  };
7134
7316
 
7135
- const Modal = ({
7136
- isOpen,
7137
- title = 'Confirm',
7138
- children,
7139
- onConfirm,
7140
- onCancel,
7141
- confirmLabel = 'Confirm',
7142
- cancelLabel = 'Cancel',
7143
- showCancel = false,
7144
- showConfirm = false,
7145
- closeOnEscape = true,
7146
- closeOnOutsideClick = true
7317
+ // import "src/style/DebounceSelect.css";
7318
+
7319
+ const DebounceSelect = ({
7320
+ label,
7321
+ fetchOptions,
7322
+ onSelect,
7323
+ placeholder = "Type to search...",
7324
+ debounceDelay = 300,
7325
+ required = false,
7326
+ disabled = false,
7327
+ objValue,
7328
+ style,
7329
+ isMulti = false,
7330
+ pushUrlParamObj = false,
7331
+ addItem = undefined,
7332
+ fetchAll = true
7147
7333
  }) => {
7334
+ const [input, setInput] = React.useState("");
7335
+ const [options, setOptions] = React.useState([]);
7336
+ const [loading, setLoading] = React.useState(false);
7337
+ const [open, setOpen] = React.useState(false);
7338
+ const [selectedItems, setSelectedItems] = React.useState(isMulti ? objValue ?? [] : objValue ? [objValue] : []);
7339
+
7340
+ // Auto-update selectedItems when URL param changes
7341
+ // useEffect(() => {
7342
+ // if (!pushUrlParamObj) return;
7343
+ // const syncFromUrl = () => {
7344
+ // const params = new URLSearchParams(window.location.search);
7345
+ // const urlVal = params.get(pushUrlParamObj);
7346
+ // if (urlVal) {
7347
+ // if (isMulti) {
7348
+ // const urlValues = urlVal.split(",").filter(Boolean);
7349
+ // // Only update if different
7350
+ // if (JSON.stringify(urlValues) !== JSON.stringify(selectedItems.map(i => i.value))) {
7351
+ // // We don't have labels, so just update values
7352
+ // setSelectedItems(urlValues.map(v => ({ value: v, label: v })));
7353
+ // onSelect?.(urlValues.map(v => ({ value: v, label: v })));
7354
+ // }
7355
+ // } else {
7356
+ // if (!selectedItems[0] || selectedItems[0].value !== urlVal) {
7357
+ // setSelectedItems([{ value: urlVal, label: urlVal }]);
7358
+ // onSelect?.({ value: urlVal, label: urlVal });
7359
+ // }
7360
+ // }
7361
+ // } else {
7362
+ // if (selectedItems.length > 0) {
7363
+ // setSelectedItems([]);
7364
+ // onSelect?.(isMulti ? [] : null);
7365
+ // }
7366
+ // }
7367
+ // };
7368
+ // syncFromUrl();
7369
+ // window.addEventListener("popstate", syncFromUrl);
7370
+ // // Listen for pushState/replaceState (programmatic changes)
7371
+ // const patchHistory = (type) => {
7372
+ // const orig = window.history[type];
7373
+ // window.history[type] = function() {
7374
+ // const rv = orig.apply(this, arguments);
7375
+ // window.dispatchEvent(new Event(type));
7376
+ // return rv;
7377
+ // };
7378
+ // };
7379
+ // patchHistory('pushState');
7380
+ // patchHistory('replaceState');
7381
+ // window.addEventListener('pushState', syncFromUrl);
7382
+ // window.addEventListener('replaceState', syncFromUrl);
7383
+ // return () => {
7384
+ // window.removeEventListener("popstate", syncFromUrl);
7385
+ // window.removeEventListener('pushState', syncFromUrl);
7386
+ // window.removeEventListener('replaceState', syncFromUrl);
7387
+ // };
7388
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
7389
+ // }, [pushUrlParamObj, isMulti, selectedItems, onSelect]);
7390
+
7391
+ const timeoutRef = React.useRef(null);
7148
7392
  React.useEffect(() => {
7149
- const handleKey = e => {
7150
- if (e.key === 'Escape' && closeOnEscape) {
7151
- onCancel?.();
7393
+ if (!input) {
7394
+ setOptions([]);
7395
+ return;
7396
+ }
7397
+ setLoading(true);
7398
+ clearTimeout(timeoutRef.current);
7399
+ timeoutRef.current = setTimeout(async () => {
7400
+ try {
7401
+ // If fetchAll is true and input is '...', fetch all options
7402
+ // If fetchAll is false, '...' will be treated as regular search
7403
+ const query = fetchAll && input === "..." ? "" : input;
7404
+ const results = await fetchOptions(query);
7405
+ setOptions(results);
7406
+ } catch (err) {
7407
+ console.error("Failed to fetch options", err);
7408
+ setOptions([]);
7409
+ } finally {
7410
+ setLoading(false);
7152
7411
  }
7153
- };
7154
- document.addEventListener('keydown', handleKey);
7155
- return () => document.removeEventListener('keydown', handleKey);
7156
- }, [closeOnEscape, onCancel]);
7157
- if (!isOpen) return null;
7158
- return /*#__PURE__*/React.createElement("div", {
7159
- className: "modal-overlay",
7160
- onClick: closeOnOutsideClick ? onCancel : undefined
7161
- }, /*#__PURE__*/React.createElement("div", {
7162
- className: "modal-box",
7163
- onClick: e => e.stopPropagation()
7164
- }, /*#__PURE__*/React.createElement("h3", {
7165
- className: "modal-title"
7166
- }, title), /*#__PURE__*/React.createElement("div", {
7167
- className: "modal-content"
7168
- }, children), /*#__PURE__*/React.createElement("div", {
7169
- className: "modal-actions"
7170
- }, showCancel && /*#__PURE__*/React.createElement("button", {
7171
- className: "basic-button cancel",
7172
- onClick: onCancel
7173
- }, cancelLabel), showConfirm && /*#__PURE__*/React.createElement("button", {
7174
- className: "basic-button confirm",
7175
- onClick: onConfirm
7176
- }, confirmLabel))));
7177
- };
7178
-
7179
- const Filters = ({
7180
- title,
7181
- config = [],
7182
- onChange,
7183
- onAction,
7184
- userRole = [],
7185
- onExport,
7186
- hideResetSearchButton,
7187
- urSearchParams = false,
7188
- extraSearchTerm,
7189
- theme = "light"
7190
- }) => {
7191
- // const { theme, internalSort, context } = useAuth();
7192
-
7193
- // console.log(extraSearchTerm)
7194
- // Simple translation stub: return mapped key or the key itself.
7195
- const _translations = {
7196
- showFilters: 'showFilters',
7197
- hideFilters: 'hideFilters',
7198
- resetSorting: 'resetSorting',
7199
- resetSearching: 'resetSearching',
7200
- role: 'role',
7201
- confirmTitle: 'confirmTitle',
7202
- confirm: 'confirm',
7203
- cancel: 'cancel',
7204
- confirmUnknown: 'confirmUnknown'
7412
+ }, debounceDelay);
7413
+ return () => clearTimeout(timeoutRef.current);
7414
+ }, [input, fetchOptions, debounceDelay, fetchAll]);
7415
+ const setUrlParam = value => {
7416
+ const url = new URL(window.location);
7417
+ if (value === null || value === undefined || value === "") {
7418
+ url.searchParams.delete(pushUrlParamObj);
7419
+ } else {
7420
+ url.searchParams.set(pushUrlParamObj, value);
7421
+ }
7422
+ window.history.replaceState({}, "", url);
7205
7423
  };
7206
-
7207
- // t(key) returns the translation (here same as key). Calling t() with no args
7208
- // returns an empty string to avoid accidentally rendering the translations object.
7209
- const t = key => {
7210
- if (typeof key === 'undefined' || key === null) return '';
7211
- return _translations[key] ?? key;
7424
+ const handleSelect = (value, labelValue) => {
7425
+ if (isMulti) {
7426
+ const newItem = {
7427
+ value,
7428
+ label: labelValue
7429
+ };
7430
+ const updated = selectedItems.some(item => item.value === value) ? selectedItems : [...selectedItems, newItem];
7431
+ setSelectedItems(updated);
7432
+ onSelect(updated);
7433
+ setInput("");
7434
+ if (pushUrlParamObj) {
7435
+ setUrlParam(updated.map(item => item.value).join(","));
7436
+ }
7437
+ } else {
7438
+ const single = {
7439
+ value,
7440
+ label: labelValue
7441
+ };
7442
+ setSelectedItems([single]);
7443
+ onSelect(single);
7444
+ setInput(labelValue);
7445
+ if (pushUrlParamObj) {
7446
+ setUrlParam(value);
7447
+ }
7448
+ }
7449
+ setOpen(false);
7450
+ };
7451
+ const removeItem = value => {
7452
+ const updated = selectedItems.filter(item => item.value !== value);
7453
+ setSelectedItems(updated);
7454
+ onSelect(updated);
7455
+ if (pushUrlParamObj) {
7456
+ setUrlParam(updated.length ? updated.map(item => item.value).join(",") : "");
7457
+ }
7212
7458
  };
7213
- const [sorting, setSorting] = React.useState(null);
7214
- const [collapsed, setCollapsed] = React.useState(() => {
7215
- const stored = localStorage.getItem('filtersCollapsed');
7216
- return stored === 'true';
7217
- });
7218
- const [modalState, setModalState] = React.useState({
7219
- isOpen: false,
7220
- label: '',
7221
- key: '',
7222
- onConfirm: null
7223
- });
7224
- React.useEffect(() => {
7225
- localStorage.setItem('filtersCollapsed', collapsed);
7226
- }, [collapsed]);
7227
7459
 
7228
- // useEffect(() => {
7229
- // setSorting(internalSort)
7230
- // }, [internalSort]);
7460
+ // Check if input value exists in options
7461
+ const inputExists = input.trim() && options.some(opt => String(opt.label).toLowerCase() === input.trim().toLowerCase() || String(opt.value).toLowerCase() === input.trim().toLowerCase());
7462
+ const handleAddNew = () => {
7463
+ if (!input.trim()) return;
7464
+ const newOption = {
7465
+ label: input.trim(),
7466
+ value: input.trim()
7467
+ };
7468
+ if (typeof addItem === 'function') {
7469
+ addItem(newOption);
7470
+ }
7471
+ handleSelect(newOption.value, newOption.label);
7472
+ };
7231
7473
 
7232
- const handleReset = () => {
7233
- config.forEach(item => {
7234
- if (item.type !== 'button' && item.type !== 'icon') {
7235
- onChange?.(item.key, item.defaultValue || '');
7474
+ // Handle double-click to fetch all when fetchAll is false
7475
+ const handleDoubleClick = async () => {
7476
+ if (!fetchAll && !disabled) {
7477
+ setLoading(true);
7478
+ setOpen(true);
7479
+ try {
7480
+ const results = await fetchOptions("");
7481
+ setOptions(results);
7482
+ } catch (err) {
7483
+ console.error("Failed to fetch options", err);
7484
+ setOptions([]);
7485
+ } finally {
7486
+ setLoading(false);
7236
7487
  }
7237
- });
7238
- localStorage.removeItem('adminFilters');
7239
- window.history.replaceState({}, '', window.location.pathname);
7488
+ }
7240
7489
  };
7241
- React.useEffect(() => {
7242
- const urlParams = new URLSearchParams(window.location.search);
7243
- const savedFilters = localStorage.getItem('adminFilters');
7244
- const initial = savedFilters ? JSON.parse(savedFilters) : {};
7245
- urlParams.forEach((value, key) => {
7246
- if (key === 'roles') {
7247
- initial[key] = urlParams.getAll('roles');
7248
- } else {
7249
- initial[key] = value;
7490
+ return /*#__PURE__*/React.createElement("div", {
7491
+ style: {
7492
+ position: 'relative'
7493
+ }
7494
+ }, label && /*#__PURE__*/React.createElement("label", null, label, required && ' *'), isMulti && /*#__PURE__*/React.createElement("div", {
7495
+ className: "multi-selected-tags"
7496
+ }, selectedItems.map(({
7497
+ label,
7498
+ value
7499
+ }) => /*#__PURE__*/React.createElement("span", {
7500
+ key: value,
7501
+ className: "tag"
7502
+ }, label, /*#__PURE__*/React.createElement("button", {
7503
+ type: "button",
7504
+ onClick: () => removeItem(value)
7505
+ }, "\xD7")))), /*#__PURE__*/React.createElement("div", {
7506
+ style: {
7507
+ position: 'relative',
7508
+ display: 'flex',
7509
+ alignItems: 'center'
7510
+ }
7511
+ }, /*#__PURE__*/React.createElement("input", {
7512
+ className: "basic-input",
7513
+ type: "text",
7514
+ value: isMulti ? input : open ? input : selectedItems.length > 0 ? selectedItems[0].label : input,
7515
+ onChange: e => {
7516
+ setInput(e.target.value);
7517
+ setOpen(true);
7518
+ },
7519
+ placeholder: placeholder,
7520
+ onFocus: () => setOpen(true),
7521
+ onBlur: () => setTimeout(() => setOpen(false), 200),
7522
+ onDoubleClick: handleDoubleClick,
7523
+ disabled: disabled,
7524
+ style: style
7525
+ }), (input || !isMulti && selectedItems.length > 0) && !disabled && /*#__PURE__*/React.createElement("button", {
7526
+ type: "button",
7527
+ "aria-label": "Clear",
7528
+ style: {
7529
+ position: 'absolute',
7530
+ right: 6,
7531
+ background: 'none',
7532
+ border: 'none',
7533
+ cursor: 'pointer',
7534
+ fontSize: '1.2em',
7535
+ color: '#888',
7536
+ padding: 0,
7537
+ lineHeight: 1
7538
+ },
7539
+ onMouseDown: e => {
7540
+ e.preventDefault();
7541
+ setInput("");
7542
+ if (isMulti) ; else {
7543
+ setSelectedItems([]);
7544
+ onSelect(null);
7545
+ if (pushUrlParamObj) setUrlParam("");
7250
7546
  }
7251
- });
7252
- Object.entries(initial).forEach(([key, value]) => {
7253
- onChange?.(key, value);
7254
- });
7255
- }, []);
7547
+ },
7548
+ tabIndex: -1
7549
+ }, "\xD7")), open && /*#__PURE__*/React.createElement("div", {
7550
+ className: "basic-input-dropdown-menu"
7551
+ }, loading ? /*#__PURE__*/React.createElement("div", {
7552
+ className: "loading-dropdown-item"
7553
+ }, "Loading...") : options?.length > 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, options.map(({
7554
+ label,
7555
+ value
7556
+ }) => /*#__PURE__*/React.createElement("div", {
7557
+ key: value,
7558
+ className: "basic-input-dropdown-item",
7559
+ onMouseDown: () => handleSelect(value, label)
7560
+ }, label)), input.trim() && !inputExists && typeof addItem === 'function' && /*#__PURE__*/React.createElement("div", {
7561
+ className: "basic-input-dropdown-item",
7562
+ style: {
7563
+ color: '#1677ff',
7564
+ fontWeight: 500
7565
+ },
7566
+ onMouseDown: handleAddNew
7567
+ }, "+ Add \"", input.trim(), "\"")) : input.trim() && !loading && typeof addItem === 'function' ? /*#__PURE__*/React.createElement("div", {
7568
+ className: "basic-input-dropdown-item",
7569
+ style: {
7570
+ color: '#1677ff',
7571
+ fontWeight: 500
7572
+ },
7573
+ onMouseDown: handleAddNew
7574
+ }, "+ Add \"", input.trim(), "\"") : /*#__PURE__*/React.createElement("div", {
7575
+ className: "no-results-dropdown-item"
7576
+ }, "No results")));
7577
+ };
7578
+
7579
+ function SearchInput({
7580
+ pushUrlParamObj = null,
7581
+ ...props
7582
+ }) {
7583
+ const key = pushUrlParamObj || "search";
7584
+ const [value, setValue] = React.useState("");
7585
+
7586
+ // On mount, read the URL param and set value
7256
7587
  React.useEffect(() => {
7257
- const savedFilters = localStorage.getItem('adminFilters');
7258
- if (savedFilters) {
7259
- const parsed = JSON.parse(savedFilters);
7260
- Object.entries(parsed).forEach(([key, value]) => {
7261
- onChange?.(key, value);
7262
- });
7588
+ const params = new URLSearchParams(window.location.search);
7589
+ const urlValue = params.get(key) || "";
7590
+ setValue(urlValue);
7591
+
7592
+ // Listen for popstate (browser navigation)
7593
+ const onPopState = () => {
7594
+ const params = new URLSearchParams(window.location.search);
7595
+ setValue(params.get(key) || "");
7596
+ };
7597
+ window.addEventListener("popstate", onPopState);
7598
+ return () => window.removeEventListener("popstate", onPopState);
7599
+ }, [key]);
7600
+ const setUrlParam = val => {
7601
+ const params = new URLSearchParams(window.location.search);
7602
+ if (val && val.length > 0) {
7603
+ params.set(key, val);
7604
+ } else {
7605
+ params.delete(key);
7263
7606
  }
7264
- }, []);
7265
- React.useEffect(() => {
7266
- const currentValues = {};
7267
- config.forEach(item => {
7268
- if (item.type !== 'button' && item.type !== 'icon') {
7269
- currentValues[item.key] = item.value;
7270
- }
7271
- });
7272
- localStorage.setItem('adminFilters', JSON.stringify(currentValues));
7273
- }, [config]);
7274
- const openConfirmModal = (label, key, actionFn) => {
7275
- setModalState({
7276
- isOpen: true,
7277
- label,
7278
- key,
7279
- onConfirm: () => {
7280
- actionFn(key);
7281
- setModalState({
7282
- isOpen: false,
7283
- label: '',
7284
- key: '',
7285
- onConfirm: null
7286
- });
7287
- }
7288
- });
7607
+ const newUrl = window.location.pathname + (params.toString() ? "?" + params.toString() : "");
7608
+ window.history.replaceState({}, "", newUrl);
7289
7609
  };
7290
- const closeModal = () => {
7291
- setModalState({
7292
- isOpen: false,
7293
- label: '',
7294
- key: '',
7295
- onConfirm: null
7296
- });
7610
+ const handleChange = e => {
7611
+ const newValue = e.target.value;
7612
+ setValue(newValue);
7613
+ setUrlParam(newValue);
7297
7614
  };
7298
- const sortingLocalStorage = localStorage.getItem("tableSort");
7615
+ const handleClear = () => {
7616
+ setValue("");
7617
+ setUrlParam("");
7618
+ };
7619
+ return /*#__PURE__*/React.createElement("div", {
7620
+ title: "tooltip",
7621
+ style: {
7622
+ position: "relative",
7623
+ display: "inline-block",
7624
+ height: "34px",
7625
+ verticalAlign: "middle"
7626
+ }
7627
+ }, /*#__PURE__*/React.createElement("input", _extends$1({
7628
+ className: "basic-input",
7629
+ value: value,
7630
+ style: {
7631
+ marginBottom: "10px",
7632
+ padding: "5px",
7633
+ width: "200px",
7634
+ paddingRight: value ? "24px" : undefined,
7635
+ height: "100%",
7636
+ boxSizing: "border-box"
7637
+ },
7638
+ onChange: handleChange
7639
+ }, props)), value && /*#__PURE__*/React.createElement("span", {
7640
+ onClick: handleClear,
7641
+ title: "Clear search",
7642
+ style: {
7643
+ position: "absolute",
7644
+ right: "10px",
7645
+ top: "50%",
7646
+ transform: "translateY(-50%)",
7647
+ cursor: "pointer",
7648
+ fontSize: "14px",
7649
+ color: "#000000ff",
7650
+ lineHeight: "1"
7651
+ }
7652
+ }, "\u2716"));
7653
+ }
7654
+
7655
+ /*
7656
+ Reusable IconInput component
7657
+ Props:
7658
+ icon: ReactNode or string to render
7659
+ title: tooltip text
7660
+ ariaLabel: accessible label (falls back to title or stringified icon)
7661
+ onClick: callback fired after internal URL logic (receives event & active state)
7662
+ size: number (px) for square hit area
7663
+ disabled: boolean
7664
+ className, style: customization
7665
+ pushUrlParamObj: string | false -> if provided, component will write to that URL param
7666
+ pushValue: value written to param when activated (default '1')
7667
+ toggle: boolean -> if true acts like a toggle, else just sets param
7668
+ multiUrlList: boolean -> if true treats param as comma-separated list; clicking toggles pushValue in list
7669
+ activeColor: color when active
7670
+ inactiveColor: color when inactive
7671
+ */
7299
7672
 
7300
- // When urSearchParams is enabled, keep the URL search param `search`
7301
- // in sync with the extraSearchTerm prop without reloading the page.
7302
- // When urSearchParams is enabled, keep the URL search param `search`
7303
- // in sync with the extraSearchTerm prop without reloading the page.
7304
- React.useEffect(() => {
7305
- if (!urSearchParams) return;
7306
- try {
7307
- const url = new URL(window.location.href);
7308
- if (extraSearchTerm && String(extraSearchTerm).length > 0) {
7309
- url.searchParams.set('search', String(extraSearchTerm));
7310
- } else {
7311
- url.searchParams.delete('search');
7312
- }
7313
- window.history.replaceState({}, '', url.toString());
7314
- } catch (e) {
7315
- // fallback: do nothing if URL constructor fails (very unlikely in browsers)
7673
+ function IconInput({
7674
+ icon,
7675
+ title,
7676
+ ariaLabel,
7677
+ onClick,
7678
+ size = 32,
7679
+ disabled = false,
7680
+ className = "",
7681
+ style = {},
7682
+ pushUrlParamObj = false,
7683
+ pushValue = "1",
7684
+ toggle = true,
7685
+ multiUrlList = false,
7686
+ activeColor = "#1d4ed8",
7687
+ inactiveColor = "#555",
7688
+ onAction = null
7689
+ }) {
7690
+ const paramKey = pushUrlParamObj || null;
7691
+ const [active, setActive] = React.useState(() => {
7692
+ if (!paramKey) return false;
7693
+ const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : '');
7694
+ const raw = params.get(paramKey);
7695
+ if (!raw) return false;
7696
+ if (multiUrlList) {
7697
+ const arr = raw.split(',').filter(Boolean);
7698
+ return arr.includes(String(pushValue));
7316
7699
  }
7317
- }, [urSearchParams, extraSearchTerm]);
7700
+ return raw === String(pushValue);
7701
+ });
7318
7702
 
7319
- // Clear MultiSelectDropdown values if extraSearchTerm is set (input search used)
7703
+ // Auto-update active state when URL param changes
7320
7704
  React.useEffect(() => {
7321
- if (!extraSearchTerm || !urSearchParams) return;
7322
- // Find all multiselect filters and clear them
7323
- config.forEach(item => {
7324
- if (item.type === 'multiselect' && item.value && item.value.length > 0) {
7325
- onChange?.(item.key, item.isMulti ? [] : '');
7705
+ if (!paramKey) return;
7706
+ const syncFromUrl = () => {
7707
+ const params = new URLSearchParams(window.location.search);
7708
+ const raw = params.get(paramKey);
7709
+ let nextActive = false;
7710
+ if (raw) {
7711
+ if (multiUrlList) {
7712
+ const arr = raw.split(',').filter(Boolean);
7713
+ nextActive = arr.includes(String(pushValue));
7714
+ } else {
7715
+ nextActive = raw === String(pushValue);
7716
+ }
7717
+ }
7718
+ setActive(nextActive);
7719
+ };
7720
+ syncFromUrl();
7721
+ window.addEventListener("popstate", syncFromUrl);
7722
+ // Listen for pushState/replaceState (programmatic changes)
7723
+ const patchHistory = type => {
7724
+ const orig = window.history[type];
7725
+ window.history[type] = function () {
7726
+ const rv = orig.apply(this, arguments);
7727
+ window.dispatchEvent(new Event(type));
7728
+ return rv;
7729
+ };
7730
+ };
7731
+ patchHistory('pushState');
7732
+ patchHistory('replaceState');
7733
+ window.addEventListener('pushState', syncFromUrl);
7734
+ window.addEventListener('replaceState', syncFromUrl);
7735
+ return () => {
7736
+ window.removeEventListener("popstate", syncFromUrl);
7737
+ window.removeEventListener('pushState', syncFromUrl);
7738
+ window.removeEventListener('replaceState', syncFromUrl);
7739
+ };
7740
+ // eslint-disable-next-line react-hooks/exhaustive-deps
7741
+ }, [paramKey, multiUrlList, pushValue]);
7742
+
7743
+ // (Removed effect-based initialization; using lazy useState instead to satisfy lint rule.)
7744
+
7745
+ const updateUrl = React.useCallback(nextActive => {
7746
+ if (!paramKey) return;
7747
+ const params = new URLSearchParams(window.location.search);
7748
+ const current = params.get(paramKey);
7749
+ if (multiUrlList) {
7750
+ let list = current ? current.split(",").filter(Boolean) : [];
7751
+ const idx = list.indexOf(String(pushValue));
7752
+ if (nextActive) {
7753
+ if (idx === -1) list.push(String(pushValue));
7754
+ } else {
7755
+ if (idx !== -1) list.splice(idx, 1);
7756
+ }
7757
+ if (list.length === 0) {
7758
+ params.delete(paramKey);
7759
+ } else {
7760
+ params.set(paramKey, list.join(","));
7761
+ }
7762
+ } else {
7763
+ if (nextActive) {
7764
+ params.set(paramKey, String(pushValue));
7765
+ } else {
7766
+ if (toggle) {
7767
+ params.delete(paramKey);
7768
+ } else {
7769
+ // If not toggle, leave value as-is (or could clear)
7770
+ params.delete(paramKey);
7771
+ }
7326
7772
  }
7327
- });
7328
- }, [extraSearchTerm, urSearchParams]);
7329
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
7330
- className: "filters-wrapper"
7331
- }, /*#__PURE__*/React.createElement("div", {
7332
- className: "filters-header"
7333
- }, /*#__PURE__*/React.createElement("div", {
7334
- className: "filters-title"
7335
- }, title), /*#__PURE__*/React.createElement("button", {
7336
- className: "basic-button",
7337
- onClick: () => setCollapsed(prev => !prev)
7338
- }, collapsed ? ' ' + t("showFilters") : ' ' + t("hideFilters")), sortingLocalStorage && /*#__PURE__*/React.createElement("button", {
7339
- className: "basic-button confirm",
7340
- onClick: () => {
7341
- setSorting(false);
7342
- context("resetSortingTrigger", true);
7343
- localStorage.removeItem("tableSort");
7344
- window.dispatchEvent(new Event("storageUpdated"));
7345
- }
7346
- }, t("resetSorting") + " " + (sorting || "")), !hideResetSearchButton && /*#__PURE__*/React.createElement("button", {
7347
- className: "basic-button",
7348
- onClick: handleReset
7349
- }, t("resetSearching"))), !collapsed && /*#__PURE__*/React.createElement("div", {
7350
- className: "filters-container"
7351
- }, config.map((item, index) => {
7352
- const tooltip = item.tooltip || '';
7353
- const roleAllowed = !item.role || userRole.some(r => item.role.includes(r));
7354
- if (!roleAllowed) return null;
7355
- switch (item.type) {
7356
- case 'group':
7357
- return /*#__PURE__*/React.createElement("div", {
7358
- key: index,
7359
- className: "button-group",
7360
- title: item.label
7361
- }, item.buttons.map((btn, i) => {
7362
- const actionFn = btn.onAction || onAction;
7363
- if (!actionFn) return null;
7364
- const handleClick = () => {
7365
- if (btn.confirm) {
7366
- openConfirmModal(btn.label, btn.key, actionFn);
7367
- } else {
7368
- actionFn(btn.key);
7369
- }
7370
- };
7371
- return /*#__PURE__*/React.createElement("button", {
7372
- className: "basic-button",
7373
- key: i,
7374
- onClick: handleClick,
7375
- title: btn.tooltip || btn.label
7376
- }, t(btn.label));
7377
- }));
7378
- case 'input':
7379
- return /*#__PURE__*/React.createElement("div", {
7380
- key: index,
7381
- className: "filter-input-wrapper",
7382
- title: tooltip
7383
- }, /*#__PURE__*/React.createElement("input", {
7384
- className: "basic-input",
7385
- type: "search",
7386
- placeholder: item.placeholder || '',
7387
- value: item.value || '',
7388
- onChange: e => {
7389
- // If input search is used, clear all multiselects
7390
- if (urSearchParams && e.target.value) {
7391
- config.forEach(f => {
7392
- if (f.type === 'multiselect' && f.value && f.value.length > 0) {
7393
- onChange?.(f.key, f.isMulti ? [] : '');
7394
- }
7395
- });
7396
- }
7397
- onChange?.(item.key, e.target.value);
7398
- }
7399
- }));
7400
- case 'select':
7401
- return /*#__PURE__*/React.createElement("select", {
7402
- key: index,
7403
- value: item.value || '',
7404
- onChange: e => onChange?.(item.key, e.target.value),
7405
- className: "filter-select",
7406
- title: tooltip
7407
- }, item.options?.map((opt, i) => /*#__PURE__*/React.createElement("option", {
7408
- key: i,
7409
- value: opt.value
7410
- }, opt.label)));
7411
- case 'multiselect':
7412
- return /*#__PURE__*/React.createElement("div", {
7413
- key: index,
7414
- className: "filter-multiselect",
7415
- title: tooltip
7416
- }, /*#__PURE__*/React.createElement(MultiSelectDropdown, {
7417
- label: item.label || t("role"),
7418
- selected: Array.isArray(item.value) ? item.value : item.value ? [item.value] : [],
7419
- onChange: newValues => {
7420
- // If multiselect is used, clear all input search fields
7421
- if (urSearchParams && newValues && newValues.length > 0) {
7422
- config.forEach(f => {
7423
- if (f.type === 'input' && f.value && f.value.length > 0) {
7424
- onChange?.(f.key, '');
7425
- }
7426
- });
7427
- }
7428
- onChange?.(item.key, item.isMulti ? newValues : newValues[0] || "");
7429
- if (urSearchParams) {
7430
- try {
7431
- const url = new URL(window.location.href);
7432
- // Combine all selected values from all MultiSelectDropdowns
7433
- let allSelected = [];
7434
- config.forEach(f => {
7435
- if (f.type === 'multiselect') {
7436
- // Skip the current item being changed, we'll use newValues for it
7437
- if (f.key === item.key) {
7438
- if (Array.isArray(newValues) && newValues.length > 0) {
7439
- allSelected = allSelected.concat(newValues);
7440
- } else if (newValues && !Array.isArray(newValues)) {
7441
- allSelected.push(newValues);
7442
- }
7443
- } else if (f.value) {
7444
- // For other multiselects, use their current value
7445
- if (Array.isArray(f.value)) {
7446
- allSelected = allSelected.concat(f.value);
7447
- } else if (f.value) {
7448
- allSelected.push(f.value);
7449
- }
7450
- }
7451
- }
7452
- });
7453
- // Filter out empty/null/undefined values
7454
- allSelected = allSelected.filter(v => v !== undefined && v !== null && v !== '');
7455
- const joined = allSelected.join(",");
7456
- if (joined && joined.length > 0) {
7457
- url.searchParams.set('search', joined);
7458
- } else {
7459
- url.searchParams.delete('search');
7460
- }
7461
- window.history.replaceState({}, '', url.toString());
7462
- } catch (e) {
7463
- // ignore
7464
- }
7465
- }
7466
- },
7467
- required: item.required,
7468
- isMulti: item.isMulti,
7469
- theme: theme,
7470
- fetchOptions: item.fetchOptions,
7471
- options: item.options
7472
- }));
7473
- case 'date':
7474
- return /*#__PURE__*/React.createElement("div", {
7475
- key: index,
7476
- className: "filter-date",
7477
- title: tooltip
7478
- }, /*#__PURE__*/React.createElement("input", {
7479
- className: "basic-input",
7480
- type: item.addTime ? 'datetime-local' : 'date',
7481
- value: item.value || '',
7482
- onChange: e => onChange?.(item.key, e.target.value)
7483
- }), item.value && /*#__PURE__*/React.createElement("span", {
7484
- className: "date-clear",
7485
- onClick: () => onChange?.(item.key, ''),
7486
- title: "Clear date"
7487
- }, "\u2716\uFE0F"));
7488
- case 'button':
7489
- return /*#__PURE__*/React.createElement("button", {
7490
- style: item?.style,
7491
- className: "basic-button",
7492
- key: index,
7493
- onClick: () => {
7494
- const actionFn = item.onAction || onAction;
7495
- if (!actionFn) return;
7496
- if (item.confirm) {
7497
- openConfirmModal(item.label, item.key, actionFn);
7498
- } else {
7499
- actionFn(item.key);
7500
- }
7501
- },
7502
- title: tooltip
7503
- }, t(item.label));
7504
- case 'icon':
7505
- return /*#__PURE__*/React.createElement("span", {
7506
- key: index,
7507
- className: `filter-icon ${item.className || ''}`,
7508
- style: item.style,
7509
- onClick: () => onAction?.(item.key),
7510
- title: tooltip
7511
- }, item.icon);
7512
- default:
7513
- return null;
7514
7773
  }
7515
- }))), /*#__PURE__*/React.createElement(Modal, {
7516
- isOpen: modalState.isOpen,
7517
- title: t("confirmTitle") || "Confirm",
7518
- onCancel: closeModal,
7519
- onConfirm: modalState.onConfirm,
7520
- showCancel: true,
7521
- showConfirm: true,
7522
- confirmLabel: t("confirm") || "Confirm",
7523
- cancelLabel: t("cancel") || "Cancel"
7524
- }, t("confirmUnknown"), " ", modalState.label, "?"));
7525
- };
7774
+ const newUrl = window.location.pathname + (params.toString() ? `?${params.toString()}` : "");
7775
+ window.history.replaceState({}, "", newUrl);
7776
+ }, [paramKey, multiUrlList, pushValue, toggle]);
7777
+ const handleActivate = e => {
7778
+ if (disabled) return;
7779
+ let nextActive = active;
7780
+ if (toggle || multiUrlList) {
7781
+ nextActive = !active;
7782
+ } else {
7783
+ nextActive = true; // one-shot set
7784
+ }
7785
+ setActive(nextActive);
7786
+ updateUrl(nextActive);
7787
+ onClick?.(e, nextActive);
7788
+ };
7789
+ const handleKey = e => {
7790
+ if (disabled) return;
7791
+ if (e.key === "Enter" || e.key === " ") {
7792
+ e.preventDefault();
7793
+ handleActivate(e);
7794
+ }
7795
+ };
7796
+ const label = ariaLabel || title || (typeof icon === "string" ? icon : "icon button");
7797
+ const baseStyle = {
7798
+ display: "inline-flex",
7799
+ alignItems: "center",
7800
+ justifyContent: "center",
7801
+ width: size,
7802
+ height: size,
7803
+ fontSize: Math.floor(size * 0.6),
7804
+ lineHeight: 1,
7805
+ cursor: disabled ? "not-allowed" : "pointer",
7806
+ userSelect: "none",
7807
+ borderRadius: 6,
7808
+ border: "1px solid #ccc",
7809
+ background: active ? "#e0f2fe" : "#f5f5f5",
7810
+ color: active ? activeColor : inactiveColor,
7811
+ transition: "background 120ms, color 120ms, box-shadow 120ms",
7812
+ boxShadow: active ? "0 0 0 2px rgba(29,78,216,0.3)" : "none",
7813
+ ...style
7814
+ };
7815
+ return /*#__PURE__*/React.createElement("span", {
7816
+ role: "button",
7817
+ "aria-label": label,
7818
+ "aria-pressed": toggle || multiUrlList ? active : undefined,
7819
+ tabIndex: disabled ? -1 : 0,
7820
+ title: title,
7821
+ onClick: onAction,
7822
+ onKeyDown: handleKey,
7823
+ className: `icon-input ${className}`.trim(),
7824
+ style: baseStyle,
7825
+ "data-active": active ? "true" : "false"
7826
+ }, icon);
7827
+ }
7828
+
7829
+ var propTypes = {exports: {}};
7830
+
7831
+ /*
7832
+ object-assign
7833
+ (c) Sindre Sorhus
7834
+ @license MIT
7835
+ */
7836
+
7837
+ var objectAssign;
7838
+ var hasRequiredObjectAssign;
7839
+
7840
+ function requireObjectAssign () {
7841
+ if (hasRequiredObjectAssign) return objectAssign;
7842
+ hasRequiredObjectAssign = 1;
7843
+ /* eslint-disable no-unused-vars */
7844
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
7845
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
7846
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
7847
+
7848
+ function toObject(val) {
7849
+ if (val === null || val === undefined) {
7850
+ throw new TypeError('Object.assign cannot be called with null or undefined');
7851
+ }
7852
+
7853
+ return Object(val);
7854
+ }
7855
+
7856
+ function shouldUseNative() {
7857
+ try {
7858
+ if (!Object.assign) {
7859
+ return false;
7860
+ }
7861
+
7862
+ // Detect buggy property enumeration order in older V8 versions.
7863
+
7864
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
7865
+ var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
7866
+ test1[5] = 'de';
7867
+ if (Object.getOwnPropertyNames(test1)[0] === '5') {
7868
+ return false;
7869
+ }
7870
+
7871
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
7872
+ var test2 = {};
7873
+ for (var i = 0; i < 10; i++) {
7874
+ test2['_' + String.fromCharCode(i)] = i;
7875
+ }
7876
+ var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
7877
+ return test2[n];
7878
+ });
7879
+ if (order2.join('') !== '0123456789') {
7880
+ return false;
7881
+ }
7882
+
7883
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
7884
+ var test3 = {};
7885
+ 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
7886
+ test3[letter] = letter;
7887
+ });
7888
+ if (Object.keys(Object.assign({}, test3)).join('') !==
7889
+ 'abcdefghijklmnopqrst') {
7890
+ return false;
7891
+ }
7892
+
7893
+ return true;
7894
+ } catch (err) {
7895
+ // We don't expect any of the above to throw, but better to be safe.
7896
+ return false;
7897
+ }
7898
+ }
7899
+
7900
+ objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
7901
+ var from;
7902
+ var to = toObject(target);
7903
+ var symbols;
7904
+
7905
+ for (var s = 1; s < arguments.length; s++) {
7906
+ from = Object(arguments[s]);
7907
+
7908
+ for (var key in from) {
7909
+ if (hasOwnProperty.call(from, key)) {
7910
+ to[key] = from[key];
7911
+ }
7912
+ }
7913
+
7914
+ if (getOwnPropertySymbols) {
7915
+ symbols = getOwnPropertySymbols(from);
7916
+ for (var i = 0; i < symbols.length; i++) {
7917
+ if (propIsEnumerable.call(from, symbols[i])) {
7918
+ to[symbols[i]] = from[symbols[i]];
7919
+ }
7920
+ }
7921
+ }
7922
+ }
7923
+
7924
+ return to;
7925
+ };
7926
+ return objectAssign;
7927
+ }
7928
+
7929
+ /**
7930
+ * Copyright (c) 2013-present, Facebook, Inc.
7931
+ *
7932
+ * This source code is licensed under the MIT license found in the
7933
+ * LICENSE file in the root directory of this source tree.
7934
+ */
7935
+
7936
+ var ReactPropTypesSecret_1;
7937
+ var hasRequiredReactPropTypesSecret;
7938
+
7939
+ function requireReactPropTypesSecret () {
7940
+ if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
7941
+ hasRequiredReactPropTypesSecret = 1;
7942
+
7943
+ var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
7944
+
7945
+ ReactPropTypesSecret_1 = ReactPropTypesSecret;
7946
+ return ReactPropTypesSecret_1;
7947
+ }
7948
+
7949
+ var has;
7950
+ var hasRequiredHas;
7951
+
7952
+ function requireHas () {
7953
+ if (hasRequiredHas) return has;
7954
+ hasRequiredHas = 1;
7955
+ has = Function.call.bind(Object.prototype.hasOwnProperty);
7956
+ return has;
7957
+ }
7958
+
7959
+ /**
7960
+ * Copyright (c) 2013-present, Facebook, Inc.
7961
+ *
7962
+ * This source code is licensed under the MIT license found in the
7963
+ * LICENSE file in the root directory of this source tree.
7964
+ */
7965
+
7966
+ var checkPropTypes_1;
7967
+ var hasRequiredCheckPropTypes;
7968
+
7969
+ function requireCheckPropTypes () {
7970
+ if (hasRequiredCheckPropTypes) return checkPropTypes_1;
7971
+ hasRequiredCheckPropTypes = 1;
7972
+
7973
+ var printWarning = function() {};
7974
+
7975
+ if (process.env.NODE_ENV !== 'production') {
7976
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
7977
+ var loggedTypeFailures = {};
7978
+ var has = /*@__PURE__*/ requireHas();
7979
+
7980
+ printWarning = function(text) {
7981
+ var message = 'Warning: ' + text;
7982
+ if (typeof console !== 'undefined') {
7983
+ console.error(message);
7984
+ }
7985
+ try {
7986
+ // --- Welcome to debugging React ---
7987
+ // This error was thrown as a convenience so that you can use this stack
7988
+ // to find the callsite that caused this warning to fire.
7989
+ throw new Error(message);
7990
+ } catch (x) { /**/ }
7991
+ };
7992
+ }
7993
+
7994
+ /**
7995
+ * Assert that the values match with the type specs.
7996
+ * Error messages are memorized and will only be shown once.
7997
+ *
7998
+ * @param {object} typeSpecs Map of name to a ReactPropType
7999
+ * @param {object} values Runtime values that need to be type-checked
8000
+ * @param {string} location e.g. "prop", "context", "child context"
8001
+ * @param {string} componentName Name of the component for error messages.
8002
+ * @param {?Function} getStack Returns the component stack.
8003
+ * @private
8004
+ */
8005
+ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
8006
+ if (process.env.NODE_ENV !== 'production') {
8007
+ for (var typeSpecName in typeSpecs) {
8008
+ if (has(typeSpecs, typeSpecName)) {
8009
+ var error;
8010
+ // Prop type validation may throw. In case they do, we don't want to
8011
+ // fail the render phase where it didn't fail before. So we log it.
8012
+ // After these have been cleaned up, we'll let them throw.
8013
+ try {
8014
+ // This is intentionally an invariant that gets caught. It's the same
8015
+ // behavior as without this statement except with a better message.
8016
+ if (typeof typeSpecs[typeSpecName] !== 'function') {
8017
+ var err = Error(
8018
+ (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
8019
+ 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
8020
+ 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
8021
+ );
8022
+ err.name = 'Invariant Violation';
8023
+ throw err;
8024
+ }
8025
+ error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
8026
+ } catch (ex) {
8027
+ error = ex;
8028
+ }
8029
+ if (error && !(error instanceof Error)) {
8030
+ printWarning(
8031
+ (componentName || 'React class') + ': type specification of ' +
8032
+ location + ' `' + typeSpecName + '` is invalid; the type checker ' +
8033
+ 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
8034
+ 'You may have forgotten to pass an argument to the type checker ' +
8035
+ 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
8036
+ 'shape all require an argument).'
8037
+ );
8038
+ }
8039
+ if (error instanceof Error && !(error.message in loggedTypeFailures)) {
8040
+ // Only monitor this failure once because there tends to be a lot of the
8041
+ // same error.
8042
+ loggedTypeFailures[error.message] = true;
8043
+
8044
+ var stack = getStack ? getStack() : '';
8045
+
8046
+ printWarning(
8047
+ 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
8048
+ );
8049
+ }
8050
+ }
8051
+ }
8052
+ }
8053
+ }
7526
8054
 
7527
- // src/index.js
7528
- // if you want named import
8055
+ /**
8056
+ * Resets warning cache when testing.
8057
+ *
8058
+ * @private
8059
+ */
8060
+ checkPropTypes.resetWarningCache = function() {
8061
+ if (process.env.NODE_ENV !== 'production') {
8062
+ loggedTypeFailures = {};
8063
+ }
8064
+ };
8065
+
8066
+ checkPropTypes_1 = checkPropTypes;
8067
+ return checkPropTypes_1;
8068
+ }
8069
+
8070
+ /**
8071
+ * Copyright (c) 2013-present, Facebook, Inc.
8072
+ *
8073
+ * This source code is licensed under the MIT license found in the
8074
+ * LICENSE file in the root directory of this source tree.
8075
+ */
8076
+
8077
+ var factoryWithTypeCheckers;
8078
+ var hasRequiredFactoryWithTypeCheckers;
8079
+
8080
+ function requireFactoryWithTypeCheckers () {
8081
+ if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
8082
+ hasRequiredFactoryWithTypeCheckers = 1;
8083
+
8084
+ var ReactIs = requireReactIs();
8085
+ var assign = requireObjectAssign();
8086
+
8087
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
8088
+ var has = /*@__PURE__*/ requireHas();
8089
+ var checkPropTypes = /*@__PURE__*/ requireCheckPropTypes();
8090
+
8091
+ var printWarning = function() {};
8092
+
8093
+ if (process.env.NODE_ENV !== 'production') {
8094
+ printWarning = function(text) {
8095
+ var message = 'Warning: ' + text;
8096
+ if (typeof console !== 'undefined') {
8097
+ console.error(message);
8098
+ }
8099
+ try {
8100
+ // --- Welcome to debugging React ---
8101
+ // This error was thrown as a convenience so that you can use this stack
8102
+ // to find the callsite that caused this warning to fire.
8103
+ throw new Error(message);
8104
+ } catch (x) {}
8105
+ };
8106
+ }
8107
+
8108
+ function emptyFunctionThatReturnsNull() {
8109
+ return null;
8110
+ }
8111
+
8112
+ factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
8113
+ /* global Symbol */
8114
+ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
8115
+ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
8116
+
8117
+ /**
8118
+ * Returns the iterator method function contained on the iterable object.
8119
+ *
8120
+ * Be sure to invoke the function with the iterable as context:
8121
+ *
8122
+ * var iteratorFn = getIteratorFn(myIterable);
8123
+ * if (iteratorFn) {
8124
+ * var iterator = iteratorFn.call(myIterable);
8125
+ * ...
8126
+ * }
8127
+ *
8128
+ * @param {?object} maybeIterable
8129
+ * @return {?function}
8130
+ */
8131
+ function getIteratorFn(maybeIterable) {
8132
+ var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
8133
+ if (typeof iteratorFn === 'function') {
8134
+ return iteratorFn;
8135
+ }
8136
+ }
8137
+
8138
+ /**
8139
+ * Collection of methods that allow declaration and validation of props that are
8140
+ * supplied to React components. Example usage:
8141
+ *
8142
+ * var Props = require('ReactPropTypes');
8143
+ * var MyArticle = React.createClass({
8144
+ * propTypes: {
8145
+ * // An optional string prop named "description".
8146
+ * description: Props.string,
8147
+ *
8148
+ * // A required enum prop named "category".
8149
+ * category: Props.oneOf(['News','Photos']).isRequired,
8150
+ *
8151
+ * // A prop named "dialog" that requires an instance of Dialog.
8152
+ * dialog: Props.instanceOf(Dialog).isRequired
8153
+ * },
8154
+ * render: function() { ... }
8155
+ * });
8156
+ *
8157
+ * A more formal specification of how these methods are used:
8158
+ *
8159
+ * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
8160
+ * decl := ReactPropTypes.{type}(.isRequired)?
8161
+ *
8162
+ * Each and every declaration produces a function with the same signature. This
8163
+ * allows the creation of custom validation functions. For example:
8164
+ *
8165
+ * var MyLink = React.createClass({
8166
+ * propTypes: {
8167
+ * // An optional string or URI prop named "href".
8168
+ * href: function(props, propName, componentName) {
8169
+ * var propValue = props[propName];
8170
+ * if (propValue != null && typeof propValue !== 'string' &&
8171
+ * !(propValue instanceof URI)) {
8172
+ * return new Error(
8173
+ * 'Expected a string or an URI for ' + propName + ' in ' +
8174
+ * componentName
8175
+ * );
8176
+ * }
8177
+ * }
8178
+ * },
8179
+ * render: function() {...}
8180
+ * });
8181
+ *
8182
+ * @internal
8183
+ */
8184
+
8185
+ var ANONYMOUS = '<<anonymous>>';
8186
+
8187
+ // Important!
8188
+ // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
8189
+ var ReactPropTypes = {
8190
+ array: createPrimitiveTypeChecker('array'),
8191
+ bigint: createPrimitiveTypeChecker('bigint'),
8192
+ bool: createPrimitiveTypeChecker('boolean'),
8193
+ func: createPrimitiveTypeChecker('function'),
8194
+ number: createPrimitiveTypeChecker('number'),
8195
+ object: createPrimitiveTypeChecker('object'),
8196
+ string: createPrimitiveTypeChecker('string'),
8197
+ symbol: createPrimitiveTypeChecker('symbol'),
8198
+
8199
+ any: createAnyTypeChecker(),
8200
+ arrayOf: createArrayOfTypeChecker,
8201
+ element: createElementTypeChecker(),
8202
+ elementType: createElementTypeTypeChecker(),
8203
+ instanceOf: createInstanceTypeChecker,
8204
+ node: createNodeChecker(),
8205
+ objectOf: createObjectOfTypeChecker,
8206
+ oneOf: createEnumTypeChecker,
8207
+ oneOfType: createUnionTypeChecker,
8208
+ shape: createShapeTypeChecker,
8209
+ exact: createStrictShapeTypeChecker,
8210
+ };
8211
+
8212
+ /**
8213
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
8214
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
8215
+ */
8216
+ /*eslint-disable no-self-compare*/
8217
+ function is(x, y) {
8218
+ // SameValue algorithm
8219
+ if (x === y) {
8220
+ // Steps 1-5, 7-10
8221
+ // Steps 6.b-6.e: +0 != -0
8222
+ return x !== 0 || 1 / x === 1 / y;
8223
+ } else {
8224
+ // Step 6.a: NaN == NaN
8225
+ return x !== x && y !== y;
8226
+ }
8227
+ }
8228
+ /*eslint-enable no-self-compare*/
8229
+
8230
+ /**
8231
+ * We use an Error-like object for backward compatibility as people may call
8232
+ * PropTypes directly and inspect their output. However, we don't use real
8233
+ * Errors anymore. We don't inspect their stack anyway, and creating them
8234
+ * is prohibitively expensive if they are created too often, such as what
8235
+ * happens in oneOfType() for any type before the one that matched.
8236
+ */
8237
+ function PropTypeError(message, data) {
8238
+ this.message = message;
8239
+ this.data = data && typeof data === 'object' ? data: {};
8240
+ this.stack = '';
8241
+ }
8242
+ // Make `instanceof Error` still work for returned errors.
8243
+ PropTypeError.prototype = Error.prototype;
8244
+
8245
+ function createChainableTypeChecker(validate) {
8246
+ if (process.env.NODE_ENV !== 'production') {
8247
+ var manualPropTypeCallCache = {};
8248
+ var manualPropTypeWarningCount = 0;
8249
+ }
8250
+ function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
8251
+ componentName = componentName || ANONYMOUS;
8252
+ propFullName = propFullName || propName;
8253
+
8254
+ if (secret !== ReactPropTypesSecret) {
8255
+ if (throwOnDirectAccess) {
8256
+ // New behavior only for users of `prop-types` package
8257
+ var err = new Error(
8258
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
8259
+ 'Use `PropTypes.checkPropTypes()` to call them. ' +
8260
+ 'Read more at http://fb.me/use-check-prop-types'
8261
+ );
8262
+ err.name = 'Invariant Violation';
8263
+ throw err;
8264
+ } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
8265
+ // Old behavior for people using React.PropTypes
8266
+ var cacheKey = componentName + ':' + propName;
8267
+ if (
8268
+ !manualPropTypeCallCache[cacheKey] &&
8269
+ // Avoid spamming the console because they are often not actionable except for lib authors
8270
+ manualPropTypeWarningCount < 3
8271
+ ) {
8272
+ printWarning(
8273
+ 'You are manually calling a React.PropTypes validation ' +
8274
+ 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
8275
+ 'and will throw in the standalone `prop-types` package. ' +
8276
+ 'You may be seeing this warning due to a third-party PropTypes ' +
8277
+ 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
8278
+ );
8279
+ manualPropTypeCallCache[cacheKey] = true;
8280
+ manualPropTypeWarningCount++;
8281
+ }
8282
+ }
8283
+ }
8284
+ if (props[propName] == null) {
8285
+ if (isRequired) {
8286
+ if (props[propName] === null) {
8287
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
8288
+ }
8289
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
8290
+ }
8291
+ return null;
8292
+ } else {
8293
+ return validate(props, propName, componentName, location, propFullName);
8294
+ }
8295
+ }
8296
+
8297
+ var chainedCheckType = checkType.bind(null, false);
8298
+ chainedCheckType.isRequired = checkType.bind(null, true);
8299
+
8300
+ return chainedCheckType;
8301
+ }
8302
+
8303
+ function createPrimitiveTypeChecker(expectedType) {
8304
+ function validate(props, propName, componentName, location, propFullName, secret) {
8305
+ var propValue = props[propName];
8306
+ var propType = getPropType(propValue);
8307
+ if (propType !== expectedType) {
8308
+ // `propValue` being instance of, say, date/regexp, pass the 'object'
8309
+ // check, but we can offer a more precise error message here rather than
8310
+ // 'of type `object`'.
8311
+ var preciseType = getPreciseType(propValue);
8312
+
8313
+ return new PropTypeError(
8314
+ 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
8315
+ {expectedType: expectedType}
8316
+ );
8317
+ }
8318
+ return null;
8319
+ }
8320
+ return createChainableTypeChecker(validate);
8321
+ }
8322
+
8323
+ function createAnyTypeChecker() {
8324
+ return createChainableTypeChecker(emptyFunctionThatReturnsNull);
8325
+ }
8326
+
8327
+ function createArrayOfTypeChecker(typeChecker) {
8328
+ function validate(props, propName, componentName, location, propFullName) {
8329
+ if (typeof typeChecker !== 'function') {
8330
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
8331
+ }
8332
+ var propValue = props[propName];
8333
+ if (!Array.isArray(propValue)) {
8334
+ var propType = getPropType(propValue);
8335
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
8336
+ }
8337
+ for (var i = 0; i < propValue.length; i++) {
8338
+ var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
8339
+ if (error instanceof Error) {
8340
+ return error;
8341
+ }
8342
+ }
8343
+ return null;
8344
+ }
8345
+ return createChainableTypeChecker(validate);
8346
+ }
8347
+
8348
+ function createElementTypeChecker() {
8349
+ function validate(props, propName, componentName, location, propFullName) {
8350
+ var propValue = props[propName];
8351
+ if (!isValidElement(propValue)) {
8352
+ var propType = getPropType(propValue);
8353
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
8354
+ }
8355
+ return null;
8356
+ }
8357
+ return createChainableTypeChecker(validate);
8358
+ }
8359
+
8360
+ function createElementTypeTypeChecker() {
8361
+ function validate(props, propName, componentName, location, propFullName) {
8362
+ var propValue = props[propName];
8363
+ if (!ReactIs.isValidElementType(propValue)) {
8364
+ var propType = getPropType(propValue);
8365
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
8366
+ }
8367
+ return null;
8368
+ }
8369
+ return createChainableTypeChecker(validate);
8370
+ }
8371
+
8372
+ function createInstanceTypeChecker(expectedClass) {
8373
+ function validate(props, propName, componentName, location, propFullName) {
8374
+ if (!(props[propName] instanceof expectedClass)) {
8375
+ var expectedClassName = expectedClass.name || ANONYMOUS;
8376
+ var actualClassName = getClassName(props[propName]);
8377
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
8378
+ }
8379
+ return null;
8380
+ }
8381
+ return createChainableTypeChecker(validate);
8382
+ }
8383
+
8384
+ function createEnumTypeChecker(expectedValues) {
8385
+ if (!Array.isArray(expectedValues)) {
8386
+ if (process.env.NODE_ENV !== 'production') {
8387
+ if (arguments.length > 1) {
8388
+ printWarning(
8389
+ 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
8390
+ 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
8391
+ );
8392
+ } else {
8393
+ printWarning('Invalid argument supplied to oneOf, expected an array.');
8394
+ }
8395
+ }
8396
+ return emptyFunctionThatReturnsNull;
8397
+ }
8398
+
8399
+ function validate(props, propName, componentName, location, propFullName) {
8400
+ var propValue = props[propName];
8401
+ for (var i = 0; i < expectedValues.length; i++) {
8402
+ if (is(propValue, expectedValues[i])) {
8403
+ return null;
8404
+ }
8405
+ }
8406
+
8407
+ var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
8408
+ var type = getPreciseType(value);
8409
+ if (type === 'symbol') {
8410
+ return String(value);
8411
+ }
8412
+ return value;
8413
+ });
8414
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
8415
+ }
8416
+ return createChainableTypeChecker(validate);
8417
+ }
8418
+
8419
+ function createObjectOfTypeChecker(typeChecker) {
8420
+ function validate(props, propName, componentName, location, propFullName) {
8421
+ if (typeof typeChecker !== 'function') {
8422
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
8423
+ }
8424
+ var propValue = props[propName];
8425
+ var propType = getPropType(propValue);
8426
+ if (propType !== 'object') {
8427
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
8428
+ }
8429
+ for (var key in propValue) {
8430
+ if (has(propValue, key)) {
8431
+ var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
8432
+ if (error instanceof Error) {
8433
+ return error;
8434
+ }
8435
+ }
8436
+ }
8437
+ return null;
8438
+ }
8439
+ return createChainableTypeChecker(validate);
8440
+ }
8441
+
8442
+ function createUnionTypeChecker(arrayOfTypeCheckers) {
8443
+ if (!Array.isArray(arrayOfTypeCheckers)) {
8444
+ process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
8445
+ return emptyFunctionThatReturnsNull;
8446
+ }
8447
+
8448
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
8449
+ var checker = arrayOfTypeCheckers[i];
8450
+ if (typeof checker !== 'function') {
8451
+ printWarning(
8452
+ 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
8453
+ 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
8454
+ );
8455
+ return emptyFunctionThatReturnsNull;
8456
+ }
8457
+ }
8458
+
8459
+ function validate(props, propName, componentName, location, propFullName) {
8460
+ var expectedTypes = [];
8461
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
8462
+ var checker = arrayOfTypeCheckers[i];
8463
+ var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
8464
+ if (checkerResult == null) {
8465
+ return null;
8466
+ }
8467
+ if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
8468
+ expectedTypes.push(checkerResult.data.expectedType);
8469
+ }
8470
+ }
8471
+ var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
8472
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
8473
+ }
8474
+ return createChainableTypeChecker(validate);
8475
+ }
8476
+
8477
+ function createNodeChecker() {
8478
+ function validate(props, propName, componentName, location, propFullName) {
8479
+ if (!isNode(props[propName])) {
8480
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
8481
+ }
8482
+ return null;
8483
+ }
8484
+ return createChainableTypeChecker(validate);
8485
+ }
8486
+
8487
+ function invalidValidatorError(componentName, location, propFullName, key, type) {
8488
+ return new PropTypeError(
8489
+ (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
8490
+ 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
8491
+ );
8492
+ }
8493
+
8494
+ function createShapeTypeChecker(shapeTypes) {
8495
+ function validate(props, propName, componentName, location, propFullName) {
8496
+ var propValue = props[propName];
8497
+ var propType = getPropType(propValue);
8498
+ if (propType !== 'object') {
8499
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
8500
+ }
8501
+ for (var key in shapeTypes) {
8502
+ var checker = shapeTypes[key];
8503
+ if (typeof checker !== 'function') {
8504
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
8505
+ }
8506
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
8507
+ if (error) {
8508
+ return error;
8509
+ }
8510
+ }
8511
+ return null;
8512
+ }
8513
+ return createChainableTypeChecker(validate);
8514
+ }
8515
+
8516
+ function createStrictShapeTypeChecker(shapeTypes) {
8517
+ function validate(props, propName, componentName, location, propFullName) {
8518
+ var propValue = props[propName];
8519
+ var propType = getPropType(propValue);
8520
+ if (propType !== 'object') {
8521
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
8522
+ }
8523
+ // We need to check all keys in case some are required but missing from props.
8524
+ var allKeys = assign({}, props[propName], shapeTypes);
8525
+ for (var key in allKeys) {
8526
+ var checker = shapeTypes[key];
8527
+ if (has(shapeTypes, key) && typeof checker !== 'function') {
8528
+ return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
8529
+ }
8530
+ if (!checker) {
8531
+ return new PropTypeError(
8532
+ 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
8533
+ '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
8534
+ '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
8535
+ );
8536
+ }
8537
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
8538
+ if (error) {
8539
+ return error;
8540
+ }
8541
+ }
8542
+ return null;
8543
+ }
8544
+
8545
+ return createChainableTypeChecker(validate);
8546
+ }
8547
+
8548
+ function isNode(propValue) {
8549
+ switch (typeof propValue) {
8550
+ case 'number':
8551
+ case 'string':
8552
+ case 'undefined':
8553
+ return true;
8554
+ case 'boolean':
8555
+ return !propValue;
8556
+ case 'object':
8557
+ if (Array.isArray(propValue)) {
8558
+ return propValue.every(isNode);
8559
+ }
8560
+ if (propValue === null || isValidElement(propValue)) {
8561
+ return true;
8562
+ }
8563
+
8564
+ var iteratorFn = getIteratorFn(propValue);
8565
+ if (iteratorFn) {
8566
+ var iterator = iteratorFn.call(propValue);
8567
+ var step;
8568
+ if (iteratorFn !== propValue.entries) {
8569
+ while (!(step = iterator.next()).done) {
8570
+ if (!isNode(step.value)) {
8571
+ return false;
8572
+ }
8573
+ }
8574
+ } else {
8575
+ // Iterator will provide entry [k,v] tuples rather than values.
8576
+ while (!(step = iterator.next()).done) {
8577
+ var entry = step.value;
8578
+ if (entry) {
8579
+ if (!isNode(entry[1])) {
8580
+ return false;
8581
+ }
8582
+ }
8583
+ }
8584
+ }
8585
+ } else {
8586
+ return false;
8587
+ }
8588
+
8589
+ return true;
8590
+ default:
8591
+ return false;
8592
+ }
8593
+ }
8594
+
8595
+ function isSymbol(propType, propValue) {
8596
+ // Native Symbol.
8597
+ if (propType === 'symbol') {
8598
+ return true;
8599
+ }
8600
+
8601
+ // falsy value can't be a Symbol
8602
+ if (!propValue) {
8603
+ return false;
8604
+ }
8605
+
8606
+ // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
8607
+ if (propValue['@@toStringTag'] === 'Symbol') {
8608
+ return true;
8609
+ }
8610
+
8611
+ // Fallback for non-spec compliant Symbols which are polyfilled.
8612
+ if (typeof Symbol === 'function' && propValue instanceof Symbol) {
8613
+ return true;
8614
+ }
8615
+
8616
+ return false;
8617
+ }
8618
+
8619
+ // Equivalent of `typeof` but with special handling for array and regexp.
8620
+ function getPropType(propValue) {
8621
+ var propType = typeof propValue;
8622
+ if (Array.isArray(propValue)) {
8623
+ return 'array';
8624
+ }
8625
+ if (propValue instanceof RegExp) {
8626
+ // Old webkits (at least until Android 4.0) return 'function' rather than
8627
+ // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
8628
+ // passes PropTypes.object.
8629
+ return 'object';
8630
+ }
8631
+ if (isSymbol(propType, propValue)) {
8632
+ return 'symbol';
8633
+ }
8634
+ return propType;
8635
+ }
8636
+
8637
+ // This handles more types than `getPropType`. Only used for error messages.
8638
+ // See `createPrimitiveTypeChecker`.
8639
+ function getPreciseType(propValue) {
8640
+ if (typeof propValue === 'undefined' || propValue === null) {
8641
+ return '' + propValue;
8642
+ }
8643
+ var propType = getPropType(propValue);
8644
+ if (propType === 'object') {
8645
+ if (propValue instanceof Date) {
8646
+ return 'date';
8647
+ } else if (propValue instanceof RegExp) {
8648
+ return 'regexp';
8649
+ }
8650
+ }
8651
+ return propType;
8652
+ }
8653
+
8654
+ // Returns a string that is postfixed to a warning about an invalid type.
8655
+ // For example, "undefined" or "of type array"
8656
+ function getPostfixForTypeWarning(value) {
8657
+ var type = getPreciseType(value);
8658
+ switch (type) {
8659
+ case 'array':
8660
+ case 'object':
8661
+ return 'an ' + type;
8662
+ case 'boolean':
8663
+ case 'date':
8664
+ case 'regexp':
8665
+ return 'a ' + type;
8666
+ default:
8667
+ return type;
8668
+ }
8669
+ }
8670
+
8671
+ // Returns class name of the object, if any.
8672
+ function getClassName(propValue) {
8673
+ if (!propValue.constructor || !propValue.constructor.name) {
8674
+ return ANONYMOUS;
8675
+ }
8676
+ return propValue.constructor.name;
8677
+ }
8678
+
8679
+ ReactPropTypes.checkPropTypes = checkPropTypes;
8680
+ ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
8681
+ ReactPropTypes.PropTypes = ReactPropTypes;
8682
+
8683
+ return ReactPropTypes;
8684
+ };
8685
+ return factoryWithTypeCheckers;
8686
+ }
8687
+
8688
+ /**
8689
+ * Copyright (c) 2013-present, Facebook, Inc.
8690
+ *
8691
+ * This source code is licensed under the MIT license found in the
8692
+ * LICENSE file in the root directory of this source tree.
8693
+ */
8694
+
8695
+ var factoryWithThrowingShims;
8696
+ var hasRequiredFactoryWithThrowingShims;
8697
+
8698
+ function requireFactoryWithThrowingShims () {
8699
+ if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
8700
+ hasRequiredFactoryWithThrowingShims = 1;
8701
+
8702
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
8703
+
8704
+ function emptyFunction() {}
8705
+ function emptyFunctionWithReset() {}
8706
+ emptyFunctionWithReset.resetWarningCache = emptyFunction;
8707
+
8708
+ factoryWithThrowingShims = function() {
8709
+ function shim(props, propName, componentName, location, propFullName, secret) {
8710
+ if (secret === ReactPropTypesSecret) {
8711
+ // It is still safe when called from React.
8712
+ return;
8713
+ }
8714
+ var err = new Error(
8715
+ 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
8716
+ 'Use PropTypes.checkPropTypes() to call them. ' +
8717
+ 'Read more at http://fb.me/use-check-prop-types'
8718
+ );
8719
+ err.name = 'Invariant Violation';
8720
+ throw err;
8721
+ } shim.isRequired = shim;
8722
+ function getShim() {
8723
+ return shim;
8724
+ } // Important!
8725
+ // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
8726
+ var ReactPropTypes = {
8727
+ array: shim,
8728
+ bigint: shim,
8729
+ bool: shim,
8730
+ func: shim,
8731
+ number: shim,
8732
+ object: shim,
8733
+ string: shim,
8734
+ symbol: shim,
8735
+
8736
+ any: shim,
8737
+ arrayOf: getShim,
8738
+ element: shim,
8739
+ elementType: shim,
8740
+ instanceOf: getShim,
8741
+ node: shim,
8742
+ objectOf: getShim,
8743
+ oneOf: getShim,
8744
+ oneOfType: getShim,
8745
+ shape: getShim,
8746
+ exact: getShim,
8747
+
8748
+ checkPropTypes: emptyFunctionWithReset,
8749
+ resetWarningCache: emptyFunction
8750
+ };
8751
+
8752
+ ReactPropTypes.PropTypes = ReactPropTypes;
8753
+
8754
+ return ReactPropTypes;
8755
+ };
8756
+ return factoryWithThrowingShims;
8757
+ }
8758
+
8759
+ /**
8760
+ * Copyright (c) 2013-present, Facebook, Inc.
8761
+ *
8762
+ * This source code is licensed under the MIT license found in the
8763
+ * LICENSE file in the root directory of this source tree.
8764
+ */
8765
+
8766
+ var hasRequiredPropTypes;
8767
+
8768
+ function requirePropTypes () {
8769
+ if (hasRequiredPropTypes) return propTypes.exports;
8770
+ hasRequiredPropTypes = 1;
8771
+ if (process.env.NODE_ENV !== 'production') {
8772
+ var ReactIs = requireReactIs();
8773
+
8774
+ // By explicitly using `prop-types` you are opting into new development behavior.
8775
+ // http://fb.me/prop-types-in-prod
8776
+ var throwOnDirectAccess = true;
8777
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
8778
+ } else {
8779
+ // By explicitly using `prop-types` you are opting into new production behavior.
8780
+ // http://fb.me/prop-types-in-prod
8781
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithThrowingShims()();
8782
+ }
8783
+ return propTypes.exports;
8784
+ }
8785
+
8786
+ var propTypesExports = /*@__PURE__*/ requirePropTypes();
8787
+ var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
8788
+
8789
+ /**
8790
+ * DateTimeInput (redesigned) - matches RangePicker visual style with dropdown panel.
8791
+ * Features:
8792
+ * - Single date (and optional time) selection via custom calendar popup
8793
+ * - URL param sync (stores timestamp) same as RangePicker
8794
+ * - Dynamic dropdown positioning (prevents overflow like RangePicker)
8795
+ * - Clear & OK footer actions
8796
+ */
8797
+ function DateTimeInput({
8798
+ pushUrlParamObj = false,
8799
+ value: controlledValue,
8800
+ onChange,
8801
+ time = false,
8802
+ timeStart,
8803
+ timezone,
8804
+ timeFormat,
8805
+ dateFormat,
8806
+ placeholder = "Select date",
8807
+ disabled = false,
8808
+ className = "",
8809
+ style = {},
8810
+ predefinedRanges = ["today", "yesterday"],
8811
+ ...rest
8812
+ }) {
8813
+ const paramKey = pushUrlParamObj || null;
8814
+
8815
+ // Helper: convert timestamp (number|string) to internal input string
8816
+ const toInputString = React.useCallback(ts => {
8817
+ if (!ts) return "";
8818
+ const d = new Date(Number(ts));
8819
+ if (isNaN(d.getTime())) return "";
8820
+ const yyyy = d.getFullYear();
8821
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
8822
+ const dd = String(d.getDate()).padStart(2, '0');
8823
+ if (time) {
8824
+ const hh = String(d.getHours()).padStart(2, '0');
8825
+ const min = String(d.getMinutes()).padStart(2, '0');
8826
+ return `${yyyy}-${mm}-${dd}T${hh}:${min}`;
8827
+ }
8828
+ return `${yyyy}-${mm}-${dd}`;
8829
+ }, [time]);
8830
+
8831
+ // Initial value
8832
+ const [value, setValue] = React.useState(() => {
8833
+ if (typeof controlledValue !== "undefined") return controlledValue;
8834
+ if (!paramKey) {
8835
+ let d = new Date();
8836
+ if (time && timeStart) {
8837
+ const [h, m] = timeStart.split(":");
8838
+ d.setHours(Number(h), Number(m), 0, 0);
8839
+ }
8840
+ return toInputString(d.getTime());
8841
+ }
8842
+ const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : '');
8843
+ const urlVal = params.get(paramKey);
8844
+ if (urlVal) return toInputString(urlVal);
8845
+ let d = new Date();
8846
+ if (time && timeStart) {
8847
+ const [h, m] = timeStart.split(":");
8848
+ d.setHours(Number(h), Number(m), 0, 0);
8849
+ }
8850
+ return toInputString(d.getTime());
8851
+ });
8852
+
8853
+ // Dropdown state & positioning
8854
+ const [open, setOpen] = React.useState(false);
8855
+ const dropdownRef = React.useRef(null);
8856
+ const [dropdownPosition, setDropdownPosition] = React.useState({
8857
+ left: 0,
8858
+ top: "110%"
8859
+ });
8860
+
8861
+ // Predefined single-date shortcuts
8862
+ const normalizeLabel = lbl => String(lbl).toLowerCase();
8863
+ const createPredefinedItem = React.useCallback(item => {
8864
+ if (typeof item === 'number') {
8865
+ // number => N days ago
8866
+ return {
8867
+ key: `daysago_${item}`,
8868
+ label: `-${item}d`,
8869
+ getDate: () => {
8870
+ const d = new Date();
8871
+ d.setHours(0, 0, 0, 0);
8872
+ d.setDate(d.getDate() - item);
8873
+ return d;
8874
+ }
8875
+ };
8876
+ }
8877
+ const str = normalizeLabel(item);
8878
+ if (str === 'today') {
8879
+ return {
8880
+ key: 'today',
8881
+ label: 'Today',
8882
+ getDate: () => {
8883
+ const d = new Date();
8884
+ d.setHours(0, 0, 0, 0);
8885
+ return d;
8886
+ }
8887
+ };
8888
+ }
8889
+ if (str === 'yesterday') {
8890
+ return {
8891
+ key: 'yesterday',
8892
+ label: 'Yesterday',
8893
+ getDate: () => {
8894
+ const d = new Date();
8895
+ d.setHours(0, 0, 0, 0);
8896
+ d.setDate(d.getDate() - 1);
8897
+ return d;
8898
+ }
8899
+ };
8900
+ }
8901
+ if (str === 'lastweek') {
8902
+ return {
8903
+ key: 'lastweek',
8904
+ label: 'Last week (Mon)',
8905
+ getDate: () => {
8906
+ // Monday of previous week
8907
+ const d = new Date();
8908
+ d.setHours(0, 0, 0, 0);
8909
+ const day = d.getDay(); // 0 Sun..6 Sat
8910
+ const mondayOffset = day === 0 ? -6 : 1 - day; // days to monday this week
8911
+ d.setDate(d.getDate() + mondayOffset - 7); // previous week's Monday
8912
+ return d;
8913
+ }
8914
+ };
8915
+ }
8916
+ if (str === 'lastmonth') {
8917
+ return {
8918
+ key: 'lastmonth',
8919
+ label: 'First day last month',
8920
+ getDate: () => {
8921
+ const d = new Date();
8922
+ d.setHours(0, 0, 0, 0);
8923
+ d.setMonth(d.getMonth() - 1, 1);
8924
+ return d;
8925
+ }
8926
+ };
8927
+ }
8928
+ if (str === 'thismonth') {
8929
+ return {
8930
+ key: 'thismonth',
8931
+ label: 'First day this month',
8932
+ getDate: () => {
8933
+ const d = new Date();
8934
+ d.setHours(0, 0, 0, 0);
8935
+ d.setDate(1);
8936
+ return d;
8937
+ }
8938
+ };
8939
+ }
8940
+ if (str === 'lastyear') {
8941
+ return {
8942
+ key: 'lastyear',
8943
+ label: 'Jan 1 last year',
8944
+ getDate: () => {
8945
+ const d = new Date();
8946
+ d.setHours(0, 0, 0, 0);
8947
+ d.setFullYear(d.getFullYear() - 1, 0, 1);
8948
+ return d;
8949
+ }
8950
+ };
8951
+ }
8952
+ return {
8953
+ key: str,
8954
+ label: item,
8955
+ getDate: () => {
8956
+ const d = new Date();
8957
+ d.setHours(0, 0, 0, 0);
8958
+ return d;
8959
+ }
8960
+ };
8961
+ }, []);
8962
+ const PREDEFINED = React.useMemo(() => predefinedRanges.map(createPredefinedItem), [predefinedRanges, createPredefinedItem]);
8963
+ const [selectedPredefined, setSelectedPredefined] = React.useState("");
8964
+ React.useEffect(() => {
8965
+ if (open && dropdownRef.current) {
8966
+ const rect = dropdownRef.current.getBoundingClientRect();
8967
+ const viewportWidth = window.innerWidth;
8968
+ const viewportHeight = window.innerHeight;
8969
+ const newPosition = {
8970
+ left: '0',
8971
+ top: '110%'
8972
+ };
8973
+ if (rect.right > viewportWidth - 10) newPosition.right = 0, delete newPosition.left; // align right
8974
+ if (rect.bottom > viewportHeight - 10) newPosition.top = 'auto', newPosition.bottom = '110%';
8975
+ setDropdownPosition(newPosition);
8976
+ }
8977
+ }, [open]);
8978
+
8979
+ // Calendar month state (always show month of selected value; allow navigation)
8980
+ const selectedDate = React.useMemo(() => value ? new Date(value) : null, [value]);
8981
+ const [monthCursor, setMonthCursor] = React.useState(() => {
8982
+ const d = selectedDate || new Date();
8983
+ return new Date(d.getFullYear(), d.getMonth(), 1, 0, 0, 0, 0);
8984
+ });
8985
+ // Keep monthCursor in sync when selected date changes externally
8986
+ React.useEffect(() => {
8987
+ if (selectedDate) {
8988
+ setMonthCursor(new Date(selectedDate.getFullYear(), selectedDate.getMonth(), 1));
8989
+ }
8990
+ // Match predefined
8991
+ if (selectedDate) {
8992
+ const ts = selectedDate.getTime();
8993
+ for (let i = 0; i < PREDEFINED.length; i++) {
8994
+ const d = PREDEFINED[i].getDate();
8995
+ if (d.getTime() === ts) {
8996
+ setSelectedPredefined(String(i));
8997
+ return;
8998
+ }
8999
+ }
9000
+ setSelectedPredefined("");
9001
+ } else {
9002
+ setSelectedPredefined("");
9003
+ }
9004
+ }, [value, selectedDate, PREDEFINED]);
9005
+
9006
+ // Build calendar days (6 weeks grid)
9007
+ const buildDays = () => {
9008
+ const startOfMonth = new Date(monthCursor.getFullYear(), monthCursor.getMonth(), 1);
9009
+ const dayOfWeek = startOfMonth.getDay(); // 0 Sun ... 6 Sat
9010
+ // We start at Sunday of the week containing the 1st
9011
+ const firstGridDate = new Date(startOfMonth);
9012
+ firstGridDate.setDate(startOfMonth.getDate() - dayOfWeek);
9013
+ const days = [];
9014
+ for (let i = 0; i < 42; i++) {
9015
+ // 6 weeks
9016
+ const d = new Date(firstGridDate);
9017
+ d.setDate(firstGridDate.getDate() + i);
9018
+ days.push(d);
9019
+ }
9020
+ return days;
9021
+ };
9022
+ const days = buildDays();
9023
+
9024
+ // Update URL param
9025
+ const setUrlParam = React.useCallback(val => {
9026
+ if (!paramKey) return;
9027
+ const params = new URLSearchParams(window.location.search);
9028
+ let ts = val;
9029
+ if (val && typeof val === "string" && !/^[0-9]+$/.test(val)) {
9030
+ const d = new Date(val);
9031
+ ts = d.getTime();
9032
+ }
9033
+ if (ts && String(ts).length > 0 && !isNaN(Number(ts))) params.set(paramKey, String(ts));else params.delete(paramKey);
9034
+ const newUrl = window.location.pathname + (params.toString() ? `?${params.toString()}` : "");
9035
+ window.history.replaceState({}, "", newUrl);
9036
+ }, [paramKey]);
9037
+
9038
+ // Sync from URL
9039
+ React.useEffect(() => {
9040
+ if (!paramKey || typeof controlledValue !== 'undefined') return;
9041
+ const syncFromUrl = () => {
9042
+ const params = new URLSearchParams(window.location.search);
9043
+ const urlVal = params.get(paramKey);
9044
+ if (urlVal) {
9045
+ const str = toInputString(urlVal);
9046
+ setValue(prev => prev !== str ? str : prev);
9047
+ if (onChange && str !== controlledValue) onChange(urlVal);
9048
+ }
9049
+ };
9050
+ syncFromUrl();
9051
+ window.addEventListener('popstate', syncFromUrl);
9052
+ const patchHistory = type => {
9053
+ const orig = window.history[type];
9054
+ window.history[type] = function () {
9055
+ const rv = orig.apply(this, arguments);
9056
+ window.dispatchEvent(new Event(type));
9057
+ return rv;
9058
+ };
9059
+ };
9060
+ patchHistory('pushState');
9061
+ patchHistory('replaceState');
9062
+ window.addEventListener('pushState', syncFromUrl);
9063
+ window.addEventListener('replaceState', syncFromUrl);
9064
+ return () => {
9065
+ window.removeEventListener('popstate', syncFromUrl);
9066
+ window.removeEventListener('pushState', syncFromUrl);
9067
+ window.removeEventListener('replaceState', syncFromUrl);
9068
+ };
9069
+ }, [paramKey, controlledValue, onChange, toInputString]);
9070
+
9071
+ // Controlled value sync
9072
+ React.useEffect(() => {
9073
+ if (typeof controlledValue !== 'undefined') setValue(controlledValue);
9074
+ }, [controlledValue]);
9075
+
9076
+ // Formatting display (similar to RangePicker)
9077
+ const formatDisplay = () => {
9078
+ if (!value) return "";
9079
+ const d = new Date(value);
9080
+ if (isNaN(d.getTime())) return "";
9081
+ const actualDateFormat = dateFormat || (time ? "YYYY-MM-DD" : "DD-MM-YYYY");
9082
+ const yyyy = d.getFullYear();
9083
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
9084
+ const dd = String(d.getDate()).padStart(2, '0');
9085
+ let dateStr = actualDateFormat.replace('YYYY', yyyy).replace('MM', mm).replace('DD', dd);
9086
+ if (time) {
9087
+ const actualTimeFormat = timeFormat || 'HH:mm';
9088
+ const hh = String(d.getHours()).padStart(2, '0');
9089
+ const min = String(d.getMinutes()).padStart(2, '0');
9090
+ const timeStr = actualTimeFormat.replace('HH', hh).replace('mm', min);
9091
+ return `${dateStr} ${timeStr}`;
9092
+ }
9093
+ return dateStr;
9094
+ };
9095
+ const applySelection = d => {
9096
+ const dt = new Date(d);
9097
+ if (time && timeStart && !value) {
9098
+ // apply timeStart if initial selection
9099
+ const [h, m] = timeStart.split(":");
9100
+ dt.setHours(Number(h), Number(m), 0, 0);
9101
+ }
9102
+ const str = toInputString(dt.getTime());
9103
+ if (typeof controlledValue === 'undefined') setValue(str);
9104
+ setUrlParam(str);
9105
+ onChange?.(str);
9106
+ };
9107
+ const handlePredefinedClick = idx => {
9108
+ const item = PREDEFINED[idx];
9109
+ const d = item.getDate();
9110
+ if (time && timeStart) {
9111
+ const [h, m] = (timeStart || "00:00").split(":");
9112
+ d.setHours(Number(h), Number(m), 0, 0);
9113
+ }
9114
+ applySelection(d);
9115
+ setSelectedPredefined(String(idx));
9116
+ };
9117
+ const handleDayClick = day => {
9118
+ applySelection(day);
9119
+ };
9120
+ const handleTimeChange = e => {
9121
+ const t = e.target.value; // HH:mm
9122
+ if (!value) return;
9123
+ const d = new Date(value);
9124
+ const [h, m] = t.split(":");
9125
+ d.setHours(Number(h), Number(m), 0, 0);
9126
+ const str = toInputString(d.getTime());
9127
+ if (typeof controlledValue === 'undefined') setValue(str);
9128
+ setUrlParam(str);
9129
+ onChange?.(str);
9130
+ };
9131
+ const handleClear = () => {
9132
+ if (typeof controlledValue === 'undefined') setValue("");
9133
+ setUrlParam("");
9134
+ onChange?.("");
9135
+ };
9136
+
9137
+ // Outside click close
9138
+ React.useEffect(() => {
9139
+ if (!open) return;
9140
+ const onClick = e => {
9141
+ if (!e.target.closest('.datetime-input-dropdown')) setOpen(false);
9142
+ };
9143
+ window.addEventListener('mousedown', onClick);
9144
+ return () => window.removeEventListener('mousedown', onClick);
9145
+ }, [open]);
9146
+ return /*#__PURE__*/React.createElement("div", _extends$1({
9147
+ className: `datetime-input-wrapper ${className}`,
9148
+ style: {
9149
+ position: 'relative',
9150
+ display: 'inline-block',
9151
+ ...style
9152
+ }
9153
+ }, rest), /*#__PURE__*/React.createElement("div", {
9154
+ className: "basic-input",
9155
+ onClick: () => !disabled && setOpen(o => !o),
9156
+ style: {
9157
+ cursor: disabled ? 'not-allowed' : 'pointer',
9158
+ padding: '6px 8px',
9159
+ minWidth: 180,
9160
+ userSelect: 'none',
9161
+ position: 'relative'
9162
+ },
9163
+ "data-timestart": timeStart || undefined,
9164
+ "data-timezone": timezone || undefined,
9165
+ "data-timeformat": timeFormat || undefined,
9166
+ "data-dateformat": dateFormat || undefined
9167
+ }, formatDisplay() || placeholder, value && /*#__PURE__*/React.createElement("span", {
9168
+ onClick: e => {
9169
+ e.stopPropagation();
9170
+ handleClear();
9171
+ },
9172
+ title: "Clear date",
9173
+ style: {
9174
+ position: 'absolute',
9175
+ right: 8,
9176
+ top: '50%',
9177
+ transform: 'translateY(-50%)',
9178
+ fontSize: 12,
9179
+ cursor: 'pointer'
9180
+ }
9181
+ }, "\u2716")), open && /*#__PURE__*/React.createElement("div", {
9182
+ ref: dropdownRef,
9183
+ className: "datetime-input-dropdown range-picker-dropdown" // reuse class for styling consistency
9184
+ ,
9185
+ style: {
9186
+ position: 'absolute',
9187
+ zIndex: 50,
9188
+ background: '#fff',
9189
+ border: '1px solid #d9d9d9',
9190
+ borderRadius: 4,
9191
+ boxShadow: '0 2px 8px rgba(0,0,0,0.15)',
9192
+ padding: 12,
9193
+ width: 320,
9194
+ ...dropdownPosition
9195
+ }
9196
+ }, PREDEFINED.length > 0 && /*#__PURE__*/React.createElement("div", {
9197
+ style: {
9198
+ display: 'flex',
9199
+ flexWrap: 'wrap',
9200
+ gap: 6,
9201
+ marginBottom: 8
9202
+ }
9203
+ }, PREDEFINED.map((p, i) => {
9204
+ const active = selectedPredefined === String(i);
9205
+ return /*#__PURE__*/React.createElement("button", {
9206
+ key: p.key,
9207
+ type: "button",
9208
+ onClick: () => handlePredefinedClick(i),
9209
+ className: "basic-btn",
9210
+ style: {
9211
+ padding: '4px 8px',
9212
+ fontSize: 12,
9213
+ background: active ? '#1677ff' : '#fff',
9214
+ color: active ? '#fff' : '#000',
9215
+ border: active ? '1px solid #1677ff' : '1px solid #d9d9d9'
9216
+ }
9217
+ }, p.label);
9218
+ })), /*#__PURE__*/React.createElement("div", {
9219
+ style: {
9220
+ display: 'flex',
9221
+ justifyContent: 'space-between',
9222
+ alignItems: 'center',
9223
+ marginBottom: 8
9224
+ }
9225
+ }, /*#__PURE__*/React.createElement("button", {
9226
+ type: "button",
9227
+ className: "basic-btn",
9228
+ onClick: () => setMonthCursor(new Date(monthCursor.getFullYear(), monthCursor.getMonth() - 1, 1))
9229
+ }, "\u2039"), /*#__PURE__*/React.createElement("div", {
9230
+ style: {
9231
+ fontWeight: 600
9232
+ }
9233
+ }, monthCursor.toLocaleString(undefined, {
9234
+ month: 'long'
9235
+ }), " ", monthCursor.getFullYear()), /*#__PURE__*/React.createElement("button", {
9236
+ type: "button",
9237
+ className: "basic-btn",
9238
+ onClick: () => setMonthCursor(new Date(monthCursor.getFullYear(), monthCursor.getMonth() + 1, 1))
9239
+ }, "\u203A")), /*#__PURE__*/React.createElement("div", {
9240
+ style: {
9241
+ display: 'grid',
9242
+ gridTemplateColumns: 'repeat(7, 1fr)',
9243
+ fontSize: 12,
9244
+ marginBottom: 4,
9245
+ opacity: 0.8
9246
+ }
9247
+ }, ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(d => /*#__PURE__*/React.createElement("div", {
9248
+ key: d,
9249
+ style: {
9250
+ textAlign: 'center'
9251
+ }
9252
+ }, d))), /*#__PURE__*/React.createElement("div", {
9253
+ style: {
9254
+ display: 'grid',
9255
+ gridTemplateColumns: 'repeat(7, 1fr)',
9256
+ gap: 2
9257
+ }
9258
+ }, days.map(d => {
9259
+ const isCurrentMonth = d.getMonth() === monthCursor.getMonth();
9260
+ const isSelected = selectedDate && d.getFullYear() === selectedDate.getFullYear() && d.getMonth() === selectedDate.getMonth() && d.getDate() === selectedDate.getDate();
9261
+ const isToday = (() => {
9262
+ const t = new Date();
9263
+ return t.getFullYear() === d.getFullYear() && t.getMonth() === d.getMonth() && t.getDate() === d.getDate();
9264
+ })();
9265
+ return /*#__PURE__*/React.createElement("div", {
9266
+ key: d.toISOString(),
9267
+ onClick: () => handleDayClick(d),
9268
+ style: {
9269
+ textAlign: 'center',
9270
+ padding: '6px 0',
9271
+ cursor: 'pointer',
9272
+ fontSize: 12,
9273
+ borderRadius: 4,
9274
+ background: isSelected ? '#1677ff' : isToday ? '#e6f4ff' : 'transparent',
9275
+ color: isSelected ? '#fff' : isCurrentMonth ? '#000' : '#aaa',
9276
+ border: isSelected ? '1px solid #1677ff' : '1px solid transparent'
9277
+ }
9278
+ }, d.getDate());
9279
+ })), time && /*#__PURE__*/React.createElement("div", {
9280
+ style: {
9281
+ marginTop: 10
9282
+ }
9283
+ }, /*#__PURE__*/React.createElement("label", {
9284
+ style: {
9285
+ fontSize: 12,
9286
+ display: 'block',
9287
+ marginBottom: 4
9288
+ }
9289
+ }, "Time:"), /*#__PURE__*/React.createElement("input", {
9290
+ type: "time",
9291
+ value: (() => {
9292
+ if (!value) return '';
9293
+ const d = new Date(value);
9294
+ const hh = String(d.getHours()).padStart(2, '0');
9295
+ const mm = String(d.getMinutes()).padStart(2, '0');
9296
+ return `${hh}:${mm}`;
9297
+ })(),
9298
+ onChange: handleTimeChange,
9299
+ className: "basic-input",
9300
+ style: {
9301
+ width: '100%'
9302
+ }
9303
+ })), /*#__PURE__*/React.createElement("div", {
9304
+ style: {
9305
+ display: 'flex',
9306
+ justifyContent: 'space-between',
9307
+ alignItems: 'center',
9308
+ marginTop: 12
9309
+ }
9310
+ }, /*#__PURE__*/React.createElement("div", {
9311
+ style: {
9312
+ display: 'flex',
9313
+ gap: 8
9314
+ }
9315
+ }, /*#__PURE__*/React.createElement("button", {
9316
+ type: "button",
9317
+ className: "basic-btn",
9318
+ onClick: () => {
9319
+ handleClear();
9320
+ }
9321
+ }, "Clear"), /*#__PURE__*/React.createElement("button", {
9322
+ type: "button",
9323
+ className: "basic-btn",
9324
+ onClick: () => {
9325
+ setOpen(false);
9326
+ }
9327
+ }, "OK")), /*#__PURE__*/React.createElement("button", {
9328
+ type: "button",
9329
+ className: "basic-btn",
9330
+ onClick: () => {
9331
+ handlePredefinedClick(PREDEFINED.findIndex(p => p.key === 'today'));
9332
+ }
9333
+ }, "Today"))));
9334
+ }
9335
+ DateTimeInput.propTypes = {
9336
+ pushUrlParamObj: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
9337
+ value: PropTypes.string,
9338
+ onChange: PropTypes.func,
9339
+ time: PropTypes.bool,
9340
+ timeStart: PropTypes.string,
9341
+ timezone: PropTypes.string,
9342
+ timeFormat: PropTypes.string,
9343
+ dateFormat: PropTypes.string,
9344
+ placeholder: PropTypes.string,
9345
+ disabled: PropTypes.bool,
9346
+ className: PropTypes.string,
9347
+ style: PropTypes.object,
9348
+ predefinedRanges: PropTypes.array
9349
+ };
9350
+
9351
+ /**
9352
+ * CalendarRangePicker - Custom calendar UI for selecting date ranges
9353
+ * Props:
9354
+ * startDate: Date | null
9355
+ * endDate: Date | null
9356
+ * onChange: (startDate, endDate) => void
9357
+ * time: boolean - if true, show time selectors
9358
+ * timeStart, timeEnd: default times for start/end
9359
+ */
9360
+ function CalendarRangePicker({
9361
+ startDate,
9362
+ endDate,
9363
+ onChange,
9364
+ time = false,
9365
+ timeStart = "00:00",
9366
+ timeEnd = "23:59"
9367
+ }) {
9368
+ // Current view months (show 2 months)
9369
+ const [leftMonth, setLeftMonth] = React.useState(() => {
9370
+ const d = startDate ? new Date(startDate) : new Date();
9371
+ return new Date(d.getFullYear(), d.getMonth(), 1);
9372
+ });
9373
+ const rightMonth = new Date(leftMonth.getFullYear(), leftMonth.getMonth() + 1, 1);
9374
+
9375
+ // Update leftMonth when startDate changes (e.g., when selecting predefined ranges)
9376
+ React.useEffect(() => {
9377
+ if (startDate) {
9378
+ const d = new Date(startDate);
9379
+ setLeftMonth(new Date(d.getFullYear(), d.getMonth(), 1));
9380
+ }
9381
+ }, [startDate]);
9382
+
9383
+ // Hover state for preview
9384
+ const [hoverDate, setHoverDate] = React.useState(null);
9385
+
9386
+ // Navigate months
9387
+ const prevMonth = () => setLeftMonth(new Date(leftMonth.getFullYear(), leftMonth.getMonth() - 1, 1));
9388
+ const nextMonth = () => setLeftMonth(new Date(leftMonth.getFullYear(), leftMonth.getMonth() + 1, 1));
9389
+
9390
+ // Handle date click
9391
+ const handleDateClick = date => {
9392
+ const d = new Date(date);
9393
+ if (time && startDate && timeStart) {
9394
+ const [h, m] = timeStart.split(":");
9395
+ d.setHours(Number(h), Number(m), 0, 0);
9396
+ }
9397
+ if (!startDate || startDate && endDate) {
9398
+ // Start new range
9399
+ onChange(d, null);
9400
+ } else {
9401
+ // Complete range
9402
+ if (d < startDate) {
9403
+ onChange(d, startDate);
9404
+ } else {
9405
+ const endD = new Date(d);
9406
+ if (time && timeEnd) {
9407
+ const [h, m] = timeEnd.split(":");
9408
+ endD.setHours(Number(h), Number(m), 59, 999);
9409
+ }
9410
+ onChange(startDate, endD);
9411
+ }
9412
+ }
9413
+ };
9414
+
9415
+ // Check if date is in range
9416
+ const isInRange = date => {
9417
+ if (!startDate) return false;
9418
+ const check = endDate || hoverDate;
9419
+ if (!check) return false;
9420
+ const d = new Date(date).setHours(0, 0, 0, 0);
9421
+ const s = new Date(startDate).setHours(0, 0, 0, 0);
9422
+ const e = new Date(check).setHours(0, 0, 0, 0);
9423
+ return d >= Math.min(s, e) && d <= Math.max(s, e);
9424
+ };
9425
+ const isStartDate = date => {
9426
+ if (!startDate) return false;
9427
+ return new Date(date).setHours(0, 0, 0, 0) === new Date(startDate).setHours(0, 0, 0, 0);
9428
+ };
9429
+ const isEndDate = date => {
9430
+ if (!endDate) return false;
9431
+ return new Date(date).setHours(0, 0, 0, 0) === new Date(endDate).setHours(0, 0, 0, 0);
9432
+ };
9433
+ const isToday = date => {
9434
+ const today = new Date();
9435
+ return date.getDate() === today.getDate() && date.getMonth() === today.getMonth() && date.getFullYear() === today.getFullYear();
9436
+ };
9437
+
9438
+ // Render a single month
9439
+ const renderMonth = month => {
9440
+ const year = month.getFullYear();
9441
+ const monthIdx = month.getMonth();
9442
+ const firstDay = new Date(year, monthIdx, 1);
9443
+ const lastDay = new Date(year, monthIdx + 1, 0);
9444
+ const startWeekday = firstDay.getDay(); // 0 = Sunday
9445
+ const daysInMonth = lastDay.getDate();
9446
+ const days = [];
9447
+ // Padding days from previous month
9448
+ const prevMonthLastDay = new Date(year, monthIdx, 0).getDate();
9449
+ for (let i = startWeekday - 1; i >= 0; i--) {
9450
+ days.push({
9451
+ date: new Date(year, monthIdx - 1, prevMonthLastDay - i),
9452
+ otherMonth: true
9453
+ });
9454
+ }
9455
+ // Current month days
9456
+ for (let d = 1; d <= daysInMonth; d++) {
9457
+ days.push({
9458
+ date: new Date(year, monthIdx, d),
9459
+ otherMonth: false
9460
+ });
9461
+ }
9462
+ // Padding days from next month
9463
+ const remaining = 42 - days.length; // 6 rows * 7 days
9464
+ for (let d = 1; d <= remaining; d++) {
9465
+ days.push({
9466
+ date: new Date(year, monthIdx + 1, d),
9467
+ otherMonth: true
9468
+ });
9469
+ }
9470
+ return /*#__PURE__*/React.createElement("div", {
9471
+ style: {
9472
+ flex: 1,
9473
+ padding: "0 8px"
9474
+ }
9475
+ }, /*#__PURE__*/React.createElement("div", {
9476
+ style: {
9477
+ textAlign: "center",
9478
+ fontWeight: "bold",
9479
+ marginBottom: 12,
9480
+ fontSize: 14
9481
+ }
9482
+ }, month.toLocaleDateString("en-US", {
9483
+ month: "short",
9484
+ year: "numeric"
9485
+ })), /*#__PURE__*/React.createElement("div", {
9486
+ style: {
9487
+ display: "grid",
9488
+ gridTemplateColumns: "repeat(7, 1fr)",
9489
+ gap: 2
9490
+ }
9491
+ }, ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"].map(day => /*#__PURE__*/React.createElement("div", {
9492
+ key: day,
9493
+ style: {
9494
+ textAlign: "center",
9495
+ fontSize: 11,
9496
+ color: "#666",
9497
+ fontWeight: 600,
9498
+ padding: "4px 0"
9499
+ }
9500
+ }, day)), days.map(({
9501
+ date,
9502
+ otherMonth
9503
+ }, idx) => {
9504
+ const inRange = isInRange(date);
9505
+ const isStart = isStartDate(date);
9506
+ const isEnd = isEndDate(date);
9507
+ const isCurrentDay = isToday(date);
9508
+ return /*#__PURE__*/React.createElement("div", {
9509
+ key: idx,
9510
+ onClick: () => !otherMonth && handleDateClick(date),
9511
+ onMouseEnter: () => !otherMonth && setHoverDate(date),
9512
+ style: {
9513
+ textAlign: "center",
9514
+ padding: "8px 4px",
9515
+ fontSize: 13,
9516
+ cursor: otherMonth ? "default" : "pointer",
9517
+ color: otherMonth ? "#ccc" : isStart || isEnd ? "#fff" : isCurrentDay ? "#1d4ed8" : "#333",
9518
+ fontWeight: isStart || isEnd || isCurrentDay ? "600" : "normal",
9519
+ background: isStart || isEnd ? "#1d4ed8" : inRange ? "#e0f2fe" : "transparent",
9520
+ borderRadius: isStart || isEnd ? "50%" : inRange ? 0 : 4,
9521
+ border: isCurrentDay && !isStart && !isEnd ? "1px solid #1d4ed8" : "none",
9522
+ userSelect: "none",
9523
+ transition: "all 0.15s ease"
9524
+ },
9525
+ onMouseOver: e => {
9526
+ if (!otherMonth && !isStart && !isEnd) {
9527
+ e.currentTarget.style.background = inRange ? "#bfdbfe" : "#f3f4f6";
9528
+ }
9529
+ },
9530
+ onMouseOut: e => {
9531
+ if (!otherMonth && !isStart && !isEnd) {
9532
+ e.currentTarget.style.background = inRange ? "#e0f2fe" : "transparent";
9533
+ }
9534
+ }
9535
+ }, date.getDate());
9536
+ })));
9537
+ };
9538
+ return /*#__PURE__*/React.createElement("div", {
9539
+ style: {
9540
+ minWidth: 560
9541
+ }
9542
+ }, /*#__PURE__*/React.createElement("div", {
9543
+ style: {
9544
+ display: "flex",
9545
+ justifyContent: "space-between",
9546
+ alignItems: "center",
9547
+ marginBottom: 16
9548
+ }
9549
+ }, /*#__PURE__*/React.createElement("button", {
9550
+ onClick: prevMonth,
9551
+ style: {
9552
+ background: "none",
9553
+ border: "none",
9554
+ fontSize: 20,
9555
+ cursor: "pointer",
9556
+ padding: "4px 8px",
9557
+ color: "#333"
9558
+ }
9559
+ }, "\u2039\u2039"), /*#__PURE__*/React.createElement("div", {
9560
+ style: {
9561
+ fontWeight: "600",
9562
+ fontSize: 14,
9563
+ color: "#333"
9564
+ }
9565
+ }, leftMonth.toLocaleDateString("en-US", {
9566
+ month: "long",
9567
+ year: "numeric"
9568
+ }), " \u2013 ", rightMonth.toLocaleDateString("en-US", {
9569
+ month: "long",
9570
+ year: "numeric"
9571
+ })), /*#__PURE__*/React.createElement("button", {
9572
+ onClick: nextMonth,
9573
+ style: {
9574
+ background: "none",
9575
+ border: "none",
9576
+ fontSize: 20,
9577
+ cursor: "pointer",
9578
+ padding: "4px 8px",
9579
+ color: "#333"
9580
+ }
9581
+ }, "\u203A\u203A")), /*#__PURE__*/React.createElement("div", {
9582
+ style: {
9583
+ display: "flex",
9584
+ gap: 16
9585
+ },
9586
+ onMouseLeave: () => setHoverDate(null)
9587
+ }, renderMonth(leftMonth), renderMonth(rightMonth)));
9588
+ }
9589
+ CalendarRangePicker.propTypes = {
9590
+ startDate: PropTypes.instanceOf(Date),
9591
+ endDate: PropTypes.instanceOf(Date),
9592
+ onChange: PropTypes.func.isRequired,
9593
+ time: PropTypes.bool,
9594
+ timeStart: PropTypes.string,
9595
+ timeEnd: PropTypes.string
9596
+ };
9597
+
9598
+ /**
9599
+ * RangePicker - a reusable date or datetime-local range picker with URL param sync
9600
+ * Props:
9601
+ * pushUrlParamObj: string | false - URL param key to sync value (will store as start~end)
9602
+ * value: [start, end] controlled value (optional)
9603
+ * onChange: ([start, end]) => void (optional)
9604
+ * time: boolean - if true, use datetime-local, else date
9605
+ * timeStart: string (for default start time, e.g. "00:00")
9606
+ * timeEnd: string (for default end time, e.g. "23:59")
9607
+ * timezone, timeFormat, dateFormat, placeholder, required, disabled, className, style, min, max, ...rest
9608
+ */
9609
+ // Helper to get date string in yyyy-MM-dd or yyyy-MM-ddTHH:mm
9610
+ function formatDate(date, time = false) {
9611
+ const yyyy = date.getFullYear();
9612
+ const mm = String(date.getMonth() + 1).padStart(2, '0');
9613
+ const dd = String(date.getDate()).padStart(2, '0');
9614
+ if (time) {
9615
+ const hh = String(date.getHours()).padStart(2, '0');
9616
+ const min = String(date.getMinutes()).padStart(2, '0');
9617
+ return `${yyyy}-${mm}-${dd}T${hh}:${min}`;
9618
+ }
9619
+ return `${yyyy}-${mm}-${dd}`;
9620
+ }
9621
+ const PREDEFINED_RANGES = [{
9622
+ label: 'Today',
9623
+ getRange: time => {
9624
+ const now = new Date();
9625
+ const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
9626
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
9627
+ return [formatDate(start, time), formatDate(end, time)];
9628
+ }
9629
+ }, {
9630
+ label: 'This week',
9631
+ getRange: time => {
9632
+ const now = new Date();
9633
+ const day = now.getDay() || 7;
9634
+ const start = new Date(now);
9635
+ start.setDate(now.getDate() - day + 1);
9636
+ start.setHours(0, 0, 0, 0);
9637
+ const end = new Date(start);
9638
+ end.setDate(start.getDate() + 6);
9639
+ end.setHours(23, 59, 59, 999);
9640
+ return [formatDate(start, time), formatDate(end, time)];
9641
+ }
9642
+ }, {
9643
+ label: 'Last 7 days',
9644
+ getRange: time => {
9645
+ const now = new Date();
9646
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
9647
+ const start = new Date(end);
9648
+ start.setDate(end.getDate() - 6);
9649
+ start.setHours(0, 0, 0, 0);
9650
+ return [formatDate(start, time), formatDate(end, time)];
9651
+ }
9652
+ }, {
9653
+ label: 'This month',
9654
+ getRange: time => {
9655
+ const now = new Date();
9656
+ const start = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0, 0);
9657
+ const end = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
9658
+ return [formatDate(start, time), formatDate(end, time)];
9659
+ }
9660
+ }, {
9661
+ label: 'Last 30 days',
9662
+ getRange: time => {
9663
+ const now = new Date();
9664
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
9665
+ const start = new Date(end);
9666
+ start.setDate(end.getDate() - 29);
9667
+ start.setHours(0, 0, 0, 0);
9668
+ return [formatDate(start, time), formatDate(end, time)];
9669
+ }
9670
+ }];
9671
+
9672
+ // Helper to create predefined range from simple format
9673
+ const createRangeFromSimple = (item, time) => {
9674
+ // If it's a number, treat as "last N days"
9675
+ if (typeof item === 'number') {
9676
+ return {
9677
+ label: `Last ${item} days`,
9678
+ getRange: time => {
9679
+ const now = new Date();
9680
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
9681
+ const start = new Date(end);
9682
+ start.setDate(end.getDate() - (item - 1));
9683
+ start.setHours(0, 0, 0, 0);
9684
+ return [formatDate(start, time), formatDate(end, time)];
9685
+ }
9686
+ };
9687
+ }
9688
+
9689
+ // If it's a string, map to predefined functions
9690
+ const lowerItem = item.toLowerCase();
9691
+ const rangeMap = {
9692
+ 'today': {
9693
+ label: 'Today',
9694
+ getRange: time => {
9695
+ const now = new Date();
9696
+ const start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
9697
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
9698
+ return [formatDate(start, time), formatDate(end, time)];
9699
+ }
9700
+ },
9701
+ 'yesterday': {
9702
+ label: 'Yesterday',
9703
+ getRange: time => {
9704
+ const now = new Date();
9705
+ const start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0, 0);
9706
+ const end = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 23, 59, 59, 999);
9707
+ return [formatDate(start, time), formatDate(end, time)];
9708
+ }
9709
+ },
9710
+ 'thisweek': {
9711
+ label: 'This week',
9712
+ getRange: time => {
9713
+ const now = new Date();
9714
+ const day = now.getDay() || 7;
9715
+ const start = new Date(now);
9716
+ start.setDate(now.getDate() - day + 1);
9717
+ start.setHours(0, 0, 0, 0);
9718
+ const end = new Date(start);
9719
+ end.setDate(start.getDate() + 6);
9720
+ end.setHours(23, 59, 59, 999);
9721
+ return [formatDate(start, time), formatDate(end, time)];
9722
+ }
9723
+ },
9724
+ 'lastweek': {
9725
+ label: 'Last week',
9726
+ getRange: time => {
9727
+ const now = new Date();
9728
+ const day = now.getDay() || 7;
9729
+ const start = new Date(now);
9730
+ start.setDate(now.getDate() - day - 6);
9731
+ start.setHours(0, 0, 0, 0);
9732
+ const end = new Date(start);
9733
+ end.setDate(start.getDate() + 6);
9734
+ end.setHours(23, 59, 59, 999);
9735
+ return [formatDate(start, time), formatDate(end, time)];
9736
+ }
9737
+ },
9738
+ 'thismonth': {
9739
+ label: 'This month',
9740
+ getRange: time => {
9741
+ const now = new Date();
9742
+ const start = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0, 0);
9743
+ const end = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
9744
+ return [formatDate(start, time), formatDate(end, time)];
9745
+ }
9746
+ },
9747
+ 'lastmonth': {
9748
+ label: 'Last month',
9749
+ getRange: time => {
9750
+ const now = new Date();
9751
+ const start = new Date(now.getFullYear(), now.getMonth() - 1, 1, 0, 0, 0, 0);
9752
+ const end = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999);
9753
+ return [formatDate(start, time), formatDate(end, time)];
9754
+ }
9755
+ },
9756
+ 'thisyear': {
9757
+ label: 'This year',
9758
+ getRange: time => {
9759
+ const now = new Date();
9760
+ const start = new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0);
9761
+ const end = new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
9762
+ return [formatDate(start, time), formatDate(end, time)];
9763
+ }
9764
+ },
9765
+ 'lastyear': {
9766
+ label: 'Last year',
9767
+ getRange: time => {
9768
+ const now = new Date();
9769
+ const start = new Date(now.getFullYear() - 1, 0, 1, 0, 0, 0, 0);
9770
+ const end = new Date(now.getFullYear() - 1, 11, 31, 23, 59, 59, 999);
9771
+ return [formatDate(start, time), formatDate(end, time)];
9772
+ }
9773
+ }
9774
+ };
9775
+ return rangeMap[lowerItem] || null;
9776
+ };
9777
+ function RangePicker({
9778
+ pushUrlParamObj = false,
9779
+ value: controlledValue,
9780
+ onChange,
9781
+ time = false,
9782
+ timeStart,
9783
+ timeEnd,
9784
+ timezone,
9785
+ timeFormat,
9786
+ dateFormat,
9787
+ placeholder = "",
9788
+ required = false,
9789
+ disabled = false,
9790
+ className = "",
9791
+ style = {},
9792
+ min,
9793
+ max,
9794
+ predefinedRanges = PREDEFINED_RANGES,
9795
+ ...rest
9796
+ }) {
9797
+ const paramKey = pushUrlParamObj || null;
9798
+
9799
+ // Convert simple predefinedRanges to full format
9800
+ const processedRanges = Array.isArray(predefinedRanges) ? predefinedRanges.map(item => {
9801
+ // If it's already an object with label and getRange, use it as-is
9802
+ if (typeof item === 'object' && item.label && item.getRange) {
9803
+ return item;
9804
+ }
9805
+ // Otherwise, convert from simple format
9806
+ return createRangeFromSimple(item);
9807
+ }).filter(Boolean) : [];
9808
+
9809
+ // Helper to format default value
9810
+ const getDefault = which => {
9811
+ if (time) {
9812
+ const today = new Date();
9813
+ const yyyy = today.getFullYear();
9814
+ const mm = String(today.getMonth() + 1).padStart(2, '0');
9815
+ const dd = String(today.getDate()).padStart(2, '0');
9816
+ if (which === 'start' && timeStart) return `${yyyy}-${mm}-${dd}T${timeStart}`;
9817
+ if (which === 'end' && timeEnd) return `${yyyy}-${mm}-${dd}T${timeEnd}`;
9818
+ // fallback to now
9819
+ const now = new Date();
9820
+ const hh = String(now.getHours()).padStart(2, '0');
9821
+ const min = String(now.getMinutes()).padStart(2, '0');
9822
+ return `${yyyy}-${mm}-${dd}T${hh}:${min}`;
9823
+ }
9824
+ return "";
9825
+ };
9826
+ // Initial state
9827
+ const toInputString = ts => {
9828
+ if (!ts) return "";
9829
+ const d = new Date(Number(ts));
9830
+ if (isNaN(d.getTime())) return "";
9831
+ if (time) {
9832
+ const yyyy = d.getFullYear();
9833
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
9834
+ const dd = String(d.getDate()).padStart(2, '0');
9835
+ const hh = String(d.getHours()).padStart(2, '0');
9836
+ const min = String(d.getMinutes()).padStart(2, '0');
9837
+ return `${yyyy}-${mm}-${dd}T${hh}:${min}`;
9838
+ } else {
9839
+ const yyyy = d.getFullYear();
9840
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
9841
+ const dd = String(d.getDate()).padStart(2, '0');
9842
+ return `${yyyy}-${mm}-${dd}`;
9843
+ }
9844
+ };
9845
+ const [range, setRange] = React.useState(() => {
9846
+ if (controlledValue && Array.isArray(controlledValue)) return controlledValue;
9847
+ if (!paramKey) return [getDefault('start'), getDefault('end')];
9848
+ const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : '');
9849
+ const urlVal = params.get(paramKey);
9850
+ if (urlVal && urlVal.includes('~')) {
9851
+ const [start, end] = urlVal.split('~');
9852
+ return [toInputString(start), toInputString(end)];
9853
+ }
9854
+ return [getDefault('start'), getDefault('end')];
9855
+ });
9856
+ // Track selected predefined range
9857
+ const [selectedRange, setSelectedRange] = React.useState(() => {
9858
+ // Initialize with matching predefined range if any
9859
+ if (!paramKey) return "";
9860
+ const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : '');
9861
+ const urlVal = params.get(paramKey);
9862
+ if (urlVal && urlVal.includes('~')) {
9863
+ const [start, end] = urlVal.split('~');
9864
+ // Check if this matches any predefined range
9865
+ for (let i = 0; i < PREDEFINED_RANGES.length; ++i) {
9866
+ const [pStart, pEnd] = PREDEFINED_RANGES[i].getRange(time);
9867
+ if (new Date(pStart).getTime() === Number(start) && new Date(pEnd).getTime() === Number(end)) {
9868
+ return String(i);
9869
+ }
9870
+ }
9871
+ }
9872
+ return "";
9873
+ });
9874
+
9875
+ // Helper to check if a range matches a predefined range
9876
+ const findMatchingPredefined = (start, end) => {
9877
+ for (let i = 0; i < PREDEFINED_RANGES.length; ++i) {
9878
+ const [pStart, pEnd] = PREDEFINED_RANGES[i].getRange(time);
9879
+ // Compare as timestamps for precision
9880
+ if (new Date(pStart).getTime() === new Date(start).getTime() && new Date(pEnd).getTime() === new Date(end).getTime()) {
9881
+ return String(i);
9882
+ }
9883
+ }
9884
+ return "";
9885
+ };
9886
+
9887
+ // Sync with URL param on mount and popstate
9888
+ React.useEffect(() => {
9889
+ if (!paramKey || controlledValue && Array.isArray(controlledValue)) return;
9890
+ const syncFromUrl = () => {
9891
+ const params = new URLSearchParams(window.location.search);
9892
+ const urlVal = params.get(paramKey);
9893
+ if (urlVal && urlVal.includes('~')) {
9894
+ const [start, end] = urlVal.split('~');
9895
+ setRange(prev => prev[0] !== toInputString(start) || prev[1] !== toInputString(end) ? [toInputString(start), toInputString(end)] : prev);
9896
+ if (onChange && (range[0] !== toInputString(start) || range[1] !== toInputString(end))) onChange([start, end]);
9897
+ // Set dropdown if matches predefined
9898
+ const matchIdx = findMatchingPredefined(Number(start), Number(end));
9899
+ setSelectedRange(matchIdx);
9900
+ } else {
9901
+ setSelectedRange("");
9902
+ }
9903
+ };
9904
+ syncFromUrl();
9905
+ window.addEventListener("popstate", syncFromUrl);
9906
+ // Listen for pushState/replaceState (programmatic changes)
9907
+ const patchHistory = type => {
9908
+ const orig = window.history[type];
9909
+ window.history[type] = function () {
9910
+ const rv = orig.apply(this, arguments);
9911
+ window.dispatchEvent(new Event(type));
9912
+ return rv;
9913
+ };
9914
+ };
9915
+ patchHistory('pushState');
9916
+ patchHistory('replaceState');
9917
+ window.addEventListener('pushState', syncFromUrl);
9918
+ window.addEventListener('replaceState', syncFromUrl);
9919
+ return () => {
9920
+ window.removeEventListener("popstate", syncFromUrl);
9921
+ window.removeEventListener('pushState', syncFromUrl);
9922
+ window.removeEventListener('replaceState', syncFromUrl);
9923
+ };
9924
+ }, [paramKey, onChange]);
9925
+
9926
+ // If controlled, update local value when prop changes
9927
+ React.useEffect(() => {
9928
+ if (controlledValue && Array.isArray(controlledValue)) setRange(controlledValue);
9929
+ }, [controlledValue]);
9930
+
9931
+ // Update URL param
9932
+ const setUrlParam = React.useCallback(vals => {
9933
+ if (!paramKey) return;
9934
+ const params = new URLSearchParams(window.location.search);
9935
+ // Convert input strings to timestamps
9936
+ const toTs = v => {
9937
+ if (!v) return "";
9938
+ if (/^[0-9]+$/.test(v)) return v;
9939
+ const d = new Date(v);
9940
+ return d.getTime();
9941
+ };
9942
+ if (vals[0] && vals[1]) {
9943
+ params.set(paramKey, `${toTs(vals[0])}~${toTs(vals[1])}`);
9944
+ } else {
9945
+ params.delete(paramKey);
9946
+ }
9947
+ const newUrl = window.location.pathname + (params.toString() ? `?${params.toString()}` : "");
9948
+ window.history.replaceState({}, "", newUrl);
9949
+ }, [paramKey]);
9950
+ const handleClear = () => {
9951
+ if (!controlledValue) setRange(["", ""]);
9952
+ setUrlParam(["", ""]);
9953
+ onChange?.(["", ""]);
9954
+ };
9955
+
9956
+ // Show/hide dropdown for range selection
9957
+ const [dropdownOpen, setDropdownOpen] = React.useState(false);
9958
+ const [dropdownPosition, setDropdownPosition] = React.useState({
9959
+ top: "110%",
9960
+ left: 0,
9961
+ right: 'auto'
9962
+ });
9963
+
9964
+ // Calculate dropdown position to prevent overflow
9965
+ const dropdownRef = React.useRef(null);
9966
+ React.useEffect(() => {
9967
+ if (!dropdownOpen || !dropdownRef.current) return;
9968
+ const dropdown = dropdownRef.current;
9969
+ const rect = dropdown.getBoundingClientRect();
9970
+ const viewportWidth = window.innerWidth;
9971
+ const viewportHeight = window.innerHeight;
9972
+ let newPosition = {
9973
+ top: "110%",
9974
+ left: 0,
9975
+ right: 'auto'
9976
+ };
9977
+
9978
+ // Check if dropdown goes beyond right edge
9979
+ if (rect.right > viewportWidth - 10) {
9980
+ newPosition.right = 0;
9981
+ newPosition.left = 'auto';
9982
+ }
9983
+
9984
+ // Check if dropdown goes beyond bottom edge
9985
+ if (rect.bottom > viewportHeight - 10) {
9986
+ newPosition.top = 'auto';
9987
+ newPosition.bottom = "110%";
9988
+ }
9989
+ setDropdownPosition(newPosition);
9990
+ }, [dropdownOpen]);
9991
+
9992
+ // Format range for display using dateFormat and timeFormat props
9993
+ const formatDisplay = () => {
9994
+ if (!range[0] && !range[1]) return {
9995
+ start: "",
9996
+ end: ""
9997
+ };
9998
+ const fmt = v => {
9999
+ if (!v) return "";
10000
+ const d = new Date(v);
10001
+ if (isNaN(d.getTime())) return "";
10002
+
10003
+ // Parse dateFormat (default: DD-MM-YYYY)
10004
+ const actualDateFormat = dateFormat || (time ? "YYYY-MM-DD" : "DD-MM-YYYY");
10005
+ const yyyy = d.getFullYear();
10006
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
10007
+ const dd = String(d.getDate()).padStart(2, '0');
10008
+ let dateStr = actualDateFormat.replace('YYYY', yyyy).replace('MM', mm).replace('DD', dd);
10009
+ if (time) {
10010
+ // Parse timeFormat (default: HH:mm)
10011
+ const actualTimeFormat = timeFormat || "HH:mm";
10012
+ const hh = String(d.getHours()).padStart(2, '0');
10013
+ const min = String(d.getMinutes()).padStart(2, '0');
10014
+ const timeStr = actualTimeFormat.replace('HH', hh).replace('mm', min);
10015
+ return `${dateStr} ${timeStr}`;
10016
+ }
10017
+ return dateStr;
10018
+ };
10019
+ return {
10020
+ start: fmt(range[0]),
10021
+ end: fmt(range[1])
10022
+ };
10023
+ };
10024
+ // Close dropdown on outside click
10025
+ React.useEffect(() => {
10026
+ if (!dropdownOpen) return;
10027
+ const onClick = e => {
10028
+ if (!e.target.closest('.range-picker-dropdown')) setDropdownOpen(false);
10029
+ };
10030
+ window.addEventListener('mousedown', onClick);
10031
+ return () => window.removeEventListener('mousedown', onClick);
10032
+ }, [dropdownOpen]);
10033
+ return /*#__PURE__*/React.createElement("div", {
10034
+ style: {
10035
+ position: "relative",
10036
+ display: "inline-flex",
10037
+ gap: 4,
10038
+ ...style
10039
+ },
10040
+ className: className
10041
+ }, /*#__PURE__*/React.createElement("div", {
10042
+ style: {
10043
+ position: "relative",
10044
+ flex: 1
10045
+ }
10046
+ }, /*#__PURE__*/React.createElement("div", {
10047
+ className: "basic-input",
10048
+ onClick: () => setDropdownOpen(!dropdownOpen),
10049
+ style: {
10050
+ cursor: "pointer",
10051
+ background: dropdownOpen ? "#f0f8ff" : "#fff",
10052
+ height: 34,
10053
+ minHeight: 34,
10054
+ width: 280,
10055
+ border: '1px solid #ccc',
10056
+ borderRadius: 2,
10057
+ display: 'flex',
10058
+ alignItems: 'center',
10059
+ padding: '0 32px 0 8px',
10060
+ position: 'relative',
10061
+ fontSize: 14
10062
+ }
10063
+ }, /*#__PURE__*/React.createElement("span", {
10064
+ style: {
10065
+ color: formatDisplay().start ? '#333' : '#999',
10066
+ flex: 1
10067
+ }
10068
+ }, formatDisplay().start || 'Start date'), /*#__PURE__*/React.createElement("span", {
10069
+ style: {
10070
+ padding: '0 8px',
10071
+ color: '#999'
10072
+ }
10073
+ }, "\u2192"), /*#__PURE__*/React.createElement("span", {
10074
+ style: {
10075
+ color: formatDisplay().end ? '#333' : '#999',
10076
+ flex: 1
10077
+ }
10078
+ }, formatDisplay().end || 'End date'), /*#__PURE__*/React.createElement("span", {
10079
+ style: {
10080
+ position: 'absolute',
10081
+ right: 8,
10082
+ top: '50%',
10083
+ transform: 'translateY(-51%)',
10084
+ fontSize: 16,
10085
+ color: '#666'
10086
+ }
10087
+ }, "\uD83D\uDCC5")), dropdownOpen && /*#__PURE__*/React.createElement("div", {
10088
+ ref: dropdownRef,
10089
+ className: "range-picker-dropdown",
10090
+ style: {
10091
+ position: "absolute",
10092
+ ...dropdownPosition,
10093
+ background: "#fff",
10094
+ border: "1px solid #ccc",
10095
+ borderRadius: 4,
10096
+ boxShadow: "0 2px 8px rgba(0,0,0,0.08)",
10097
+ padding: 12,
10098
+ zIndex: 1000,
10099
+ minWidth: 260
10100
+ }
10101
+ }, /*#__PURE__*/React.createElement(CalendarRangePicker, {
10102
+ startDate: range[0] ? new Date(range[0]) : null,
10103
+ endDate: range[1] ? new Date(range[1]) : null,
10104
+ onChange: (start, end) => {
10105
+ const toStr = d => {
10106
+ if (!d) return "";
10107
+ if (time) {
10108
+ const yyyy = d.getFullYear();
10109
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
10110
+ const dd = String(d.getDate()).padStart(2, '0');
10111
+ const hh = String(d.getHours()).padStart(2, '0');
10112
+ const min = String(d.getMinutes()).padStart(2, '0');
10113
+ return `${yyyy}-${mm}-${dd}T${hh}:${min}`;
10114
+ } else {
10115
+ const yyyy = d.getFullYear();
10116
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
10117
+ const dd = String(d.getDate()).padStart(2, '0');
10118
+ return `${yyyy}-${mm}-${dd}`;
10119
+ }
10120
+ };
10121
+ const newRange = [toStr(start), toStr(end)];
10122
+ if (!controlledValue) setRange(newRange);
10123
+ setUrlParam(newRange);
10124
+ onChange?.(newRange);
10125
+ },
10126
+ time: time,
10127
+ timeStart: timeStart,
10128
+ timeEnd: timeEnd
10129
+ }), processedRanges && processedRanges.length > 0 && /*#__PURE__*/React.createElement("div", {
10130
+ style: {
10131
+ marginTop: 12,
10132
+ paddingTop: 12,
10133
+ borderTop: '1px solid #e5e7eb',
10134
+ display: 'flex',
10135
+ gap: 6,
10136
+ flexWrap: 'wrap'
10137
+ }
10138
+ }, processedRanges.map((r, i) => {
10139
+ const isActive = selectedRange === String(i);
10140
+ return /*#__PURE__*/React.createElement("button", {
10141
+ key: r.label,
10142
+ type: "button",
10143
+ onClick: () => {
10144
+ const {
10145
+ getRange
10146
+ } = r;
10147
+ const newRange = getRange(time);
10148
+ if (!controlledValue) setRange(newRange);
10149
+ setUrlParam(newRange);
10150
+ setSelectedRange(String(i));
10151
+ onChange?.(newRange);
10152
+ },
10153
+ style: {
10154
+ padding: '4px 12px',
10155
+ border: isActive ? '1px solid #1d4ed8' : '1px solid #d1d5db',
10156
+ background: isActive ? '#e0f2fe' : '#fff',
10157
+ color: isActive ? '#1d4ed8' : '#333',
10158
+ borderRadius: 4,
10159
+ cursor: 'pointer',
10160
+ fontSize: 12,
10161
+ fontWeight: isActive ? 500 : 400,
10162
+ transition: 'all 0.15s ease'
10163
+ }
10164
+ }, r.label);
10165
+ })), /*#__PURE__*/React.createElement("div", {
10166
+ style: {
10167
+ marginTop: 12,
10168
+ textAlign: 'right',
10169
+ borderTop: '1px solid #e5e7eb',
10170
+ paddingTop: 12
10171
+ }
10172
+ }, /*#__PURE__*/React.createElement("button", {
10173
+ type: "button",
10174
+ onClick: handleClear,
10175
+ style: {
10176
+ marginRight: 8,
10177
+ padding: '6px 16px',
10178
+ border: '1px solid #d1d5db',
10179
+ background: '#fff',
10180
+ borderRadius: 4,
10181
+ cursor: 'pointer',
10182
+ fontSize: 13
10183
+ }
10184
+ }, "Clear"), /*#__PURE__*/React.createElement("button", {
10185
+ type: "button",
10186
+ onClick: () => setDropdownOpen(false),
10187
+ style: {
10188
+ padding: '6px 16px',
10189
+ border: 'none',
10190
+ background: '#1d4ed8',
10191
+ color: '#fff',
10192
+ borderRadius: 4,
10193
+ cursor: 'pointer',
10194
+ fontSize: 13,
10195
+ fontWeight: 500
10196
+ }
10197
+ }, "OK")))));
10198
+ }
10199
+ RangePicker.propTypes = {
10200
+ pushUrlParamObj: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
10201
+ value: PropTypes.arrayOf(PropTypes.string),
10202
+ onChange: PropTypes.func,
10203
+ time: PropTypes.bool,
10204
+ timeStart: PropTypes.string,
10205
+ timeEnd: PropTypes.string,
10206
+ timezone: PropTypes.string,
10207
+ timeFormat: PropTypes.string,
10208
+ dateFormat: PropTypes.string,
10209
+ placeholder: PropTypes.string,
10210
+ required: PropTypes.bool,
10211
+ disabled: PropTypes.bool,
10212
+ className: PropTypes.string,
10213
+ style: PropTypes.object,
10214
+ min: PropTypes.string,
10215
+ max: PropTypes.string,
10216
+ predefinedRanges: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string,
10217
+ // e.g., "today", "yesterday", "lastweek"
10218
+ PropTypes.number,
10219
+ // e.g., 7, 30 (last N days)
10220
+ PropTypes.shape({
10221
+ label: PropTypes.string.isRequired,
10222
+ getRange: PropTypes.func.isRequired
10223
+ })])), PropTypes.arrayOf(PropTypes.shape({
10224
+ label: PropTypes.string.isRequired,
10225
+ getRange: PropTypes.func.isRequired
10226
+ }))])
10227
+ };
7529
10228
 
7530
- exports.Filter = Filters;
7531
- exports.default = Filters;
10229
+ exports.CalendarRangePicker = CalendarRangePicker;
10230
+ exports.DateTimeInput = DateTimeInput;
10231
+ exports.DebounceSelect = DebounceSelect;
10232
+ exports.IconInput = IconInput;
10233
+ exports.MultiSelectDropdown = MultiSelectDropdown;
10234
+ exports.RangePicker = RangePicker;
10235
+ exports.SearchInput = SearchInput;
7532
10236
  //# sourceMappingURL=index.cjs.js.map