@oceanbase/ui 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
@@ -0,0 +1,427 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ import { useRef, useCallback, useState, useMemo } from 'react';
13
+ import dayjs from 'dayjs';
14
+ import moment from 'moment';
15
+
16
+ // 日期时间段的类型定义
17
+
18
+ // 分隔符
19
+ var RANGE_SEPARATOR = ' ~ ';
20
+
21
+ // 段落配置表
22
+ var SEGMENT_CONFIG = {
23
+ YYYY: {
24
+ type: 'year',
25
+ length: 4,
26
+ min: 1900,
27
+ max: 2100
28
+ },
29
+ MM: {
30
+ type: 'month',
31
+ length: 2,
32
+ min: 1,
33
+ max: 12
34
+ },
35
+ DD: {
36
+ type: 'day',
37
+ length: 2,
38
+ min: 1,
39
+ max: 31
40
+ },
41
+ HH: {
42
+ type: 'hour',
43
+ length: 2,
44
+ min: 0,
45
+ max: 23
46
+ },
47
+ mm: {
48
+ type: 'minute',
49
+ length: 2,
50
+ min: 0,
51
+ max: 59
52
+ },
53
+ ss: {
54
+ type: 'second',
55
+ length: 2,
56
+ min: 0,
57
+ max: 59
58
+ }
59
+ };
60
+
61
+ // 解析单个日期时间字符串的段落 - 根据 format 动态计算
62
+ var parseDateTimeSegments = function parseDateTimeSegments(format, dateValue, rangeType, offset) {
63
+ if (!dateValue) return [];
64
+ var segments = [];
65
+ var patterns = ['YYYY', 'MM', 'DD', 'HH', 'mm', 'ss'];
66
+ for (var _i = 0, _patterns = patterns; _i < _patterns.length; _i++) {
67
+ var pattern = _patterns[_i];
68
+ var formatIndex = format.indexOf(pattern);
69
+ if (formatIndex === -1) continue;
70
+ var config = SEGMENT_CONFIG[pattern];
71
+ var valueStart = formatIndex;
72
+ var valueEnd = formatIndex + config.length;
73
+ segments.push({
74
+ type: config.type,
75
+ range: rangeType,
76
+ start: offset + valueStart,
77
+ end: offset + valueEnd,
78
+ value: dateValue.substring(valueStart, valueEnd),
79
+ min: config.min,
80
+ max: config.max,
81
+ padLength: config.length
82
+ });
83
+ }
84
+ segments.sort(function (a, b) {
85
+ return a.start - b.start;
86
+ });
87
+ return segments;
88
+ };
89
+
90
+ // 根据光标位置找到当前段落
91
+ var findSegmentByPosition = function findSegmentByPosition(segments, position) {
92
+ var _iterator = _createForOfIteratorHelper(segments),
93
+ _step;
94
+ try {
95
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
96
+ var segment = _step.value;
97
+ if (position >= segment.start && position <= segment.end) {
98
+ return segment;
99
+ }
100
+ }
101
+ } catch (err) {
102
+ _iterator.e(err);
103
+ } finally {
104
+ _iterator.f();
105
+ }
106
+ var minDistance = Infinity;
107
+ var closestSegment = null;
108
+ var _iterator2 = _createForOfIteratorHelper(segments),
109
+ _step2;
110
+ try {
111
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
112
+ var _segment = _step2.value;
113
+ var distance = Math.min(Math.abs(position - _segment.start), Math.abs(position - _segment.end));
114
+ if (distance < minDistance) {
115
+ minDistance = distance;
116
+ closestSegment = _segment;
117
+ }
118
+ }
119
+ } catch (err) {
120
+ _iterator2.e(err);
121
+ } finally {
122
+ _iterator2.f();
123
+ }
124
+ return closestSegment;
125
+ };
126
+
127
+ // 获取下一个段落
128
+ var getNextSegment = function getNextSegment(segments, currentSegment) {
129
+ var currentIndex = segments.findIndex(function (s) {
130
+ return s.range === currentSegment.range && s.type === currentSegment.type;
131
+ });
132
+ if (currentIndex < segments.length - 1) {
133
+ return segments[currentIndex + 1];
134
+ }
135
+ return null;
136
+ };
137
+
138
+ // 获取上一个段落
139
+ var getPrevSegment = function getPrevSegment(segments, currentSegment) {
140
+ var currentIndex = segments.findIndex(function (s) {
141
+ return s.range === currentSegment.range && s.type === currentSegment.type;
142
+ });
143
+ if (currentIndex > 0) {
144
+ return segments[currentIndex - 1];
145
+ }
146
+ return null;
147
+ };
148
+ export var useSegmentedInput = function useSegmentedInput(options) {
149
+ var value = options.value,
150
+ onChange = options.onChange,
151
+ format = options.format,
152
+ baseFormat = options.baseFormat,
153
+ _options$isMoment = options.isMoment,
154
+ isMoment = _options$isMoment === void 0 ? false : _options$isMoment,
155
+ _options$isCn = options.isCn,
156
+ isCn = _options$isCn === void 0 ? true : _options$isCn,
157
+ onClick = options.onClick;
158
+ var inputRef = useRef(null);
159
+ var _useState = useState(false),
160
+ _useState2 = _slicedToArray(_useState, 2),
161
+ isEditing = _useState2[0],
162
+ setIsEditing = _useState2[1];
163
+ var _useState3 = useState(''),
164
+ _useState4 = _slicedToArray(_useState3, 2),
165
+ inputBuffer = _useState4[0],
166
+ setInputBuffer = _useState4[1];
167
+ var _useState5 = useState(null),
168
+ _useState6 = _slicedToArray(_useState5, 2),
169
+ currentSegmentKey = _useState6[0],
170
+ setCurrentSegmentKey = _useState6[1];
171
+
172
+ // 格式化日期值为字符串
173
+ var formatValue = useCallback(function (v) {
174
+ var includeTimezone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
175
+ if (!v) return '';
176
+ var formatToUse = includeTimezone ? format : baseFormat;
177
+ return v.format(formatToUse);
178
+ }, [format, baseFormat]);
179
+
180
+ // 开始时间不包含时区后缀,结束时间包含
181
+ var startValue = useMemo(function () {
182
+ return formatValue((value === null || value === void 0 ? void 0 : value[0]) || null, false);
183
+ }, [value, formatValue]);
184
+ var endValue = useMemo(function () {
185
+ return formatValue((value === null || value === void 0 ? void 0 : value[1]) || null, true);
186
+ }, [value, formatValue]);
187
+
188
+ // 合并后的显示值
189
+ var displayValue = useMemo(function () {
190
+ if (!startValue && !endValue) return '';
191
+ return "".concat(startValue).concat(RANGE_SEPARATOR).concat(endValue);
192
+ }, [startValue, endValue]);
193
+
194
+ // 解析所有段落
195
+ var allSegments = useMemo(function () {
196
+ var startSegments = parseDateTimeSegments(baseFormat, startValue, 'start', 0);
197
+ var endOffset = startValue.length + RANGE_SEPARATOR.length;
198
+ var endSegments = parseDateTimeSegments(format, endValue, 'end', endOffset);
199
+ return [].concat(_toConsumableArray(startSegments), _toConsumableArray(endSegments));
200
+ }, [baseFormat, format, startValue, endValue]);
201
+
202
+ // 动态获取当前段落
203
+ var currentSegment = useMemo(function () {
204
+ if (!currentSegmentKey) return null;
205
+ return allSegments.find(function (s) {
206
+ return "".concat(s.range, "-").concat(s.type) === currentSegmentKey;
207
+ }) || null;
208
+ }, [currentSegmentKey, allSegments]);
209
+
210
+ // 创建新的日期对象
211
+ var createDate = useCallback(function (dateStr, rangeType) {
212
+ var formatToUse = rangeType === 'start' ? baseFormat : format;
213
+ if (isMoment) {
214
+ return moment(dateStr, formatToUse);
215
+ }
216
+ return dayjs(dateStr, formatToUse);
217
+ }, [isMoment, format, baseFormat]);
218
+
219
+ // 更新日期值
220
+ var updateValue = useCallback(function (segment, newSegmentValue) {
221
+ var which = segment.range;
222
+ var currentDateValue = which === 'start' ? startValue : endValue;
223
+ var paddedValue = newSegmentValue.padStart(segment.padLength, '0');
224
+ var baseOffset = which === 'start' ? 0 : startValue.length + RANGE_SEPARATOR.length;
225
+ var localStart = segment.start - baseOffset;
226
+ var localEnd = segment.end - baseOffset;
227
+ var newDateValue = currentDateValue.substring(0, localStart) + paddedValue + currentDateValue.substring(localEnd);
228
+ var newDate = createDate(newDateValue, which);
229
+ if (newDate.isValid()) {
230
+ var newRange = which === 'start' ? [newDate, (value === null || value === void 0 ? void 0 : value[1]) || newDate] : [(value === null || value === void 0 ? void 0 : value[0]) || newDate, newDate];
231
+ onChange === null || onChange === void 0 || onChange(newRange);
232
+ }
233
+ }, [startValue, endValue, value, onChange, createDate]);
234
+
235
+ // 选中指定段落
236
+ var selectSegment = useCallback(function (segment) {
237
+ if (inputRef.current) {
238
+ var _inputRef$current;
239
+ inputRef.current.focus();
240
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || (_inputRef$current = _inputRef$current.input) === null || _inputRef$current === void 0 || _inputRef$current.setSelectionRange(segment.start, segment.end);
241
+ setCurrentSegmentKey("".concat(segment.range, "-").concat(segment.type));
242
+ setInputBuffer('');
243
+ }
244
+ }, []);
245
+
246
+ // 处理单击事件
247
+ var handleClick = useCallback(function (e) {
248
+ var _inputRef$current2;
249
+ e.stopPropagation();
250
+ setIsEditing(true);
251
+ onClick === null || onClick === void 0 || onClick();
252
+ var cursorPos = ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || (_inputRef$current2 = _inputRef$current2.input) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.selectionStart) || 0;
253
+ var segment = findSegmentByPosition(allSegments, cursorPos);
254
+ if (segment) {
255
+ selectSegment(segment);
256
+ }
257
+ }, [allSegments, selectSegment, onClick]);
258
+
259
+ // 处理双击事件
260
+ var handleDoubleClick = useCallback(function (e) {
261
+ var _inputRef$current3;
262
+ e.stopPropagation();
263
+ e.preventDefault();
264
+ setIsEditing(true);
265
+ setCurrentSegmentKey(null);
266
+ (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 || (_inputRef$current3 = _inputRef$current3.input) === null || _inputRef$current3 === void 0 || _inputRef$current3.select();
267
+ }, []);
268
+
269
+ // 处理键盘输入
270
+ var handleKeyDown = useCallback(function (e) {
271
+ if (!currentSegment) return;
272
+ var key = e.key;
273
+
274
+ // 处理数字输入
275
+ if (/^\d$/.test(key)) {
276
+ e.preventDefault();
277
+ var newBuffer = inputBuffer + key;
278
+ setInputBuffer(newBuffer);
279
+ var numValue = parseInt(newBuffer, 10);
280
+ var shouldJump = newBuffer.length >= currentSegment.padLength || numValue * 10 > currentSegment.max;
281
+ if (shouldJump) {
282
+ var clampedValue = Math.max(currentSegment.min, Math.min(currentSegment.max, numValue));
283
+ updateValue(currentSegment, String(clampedValue));
284
+ var nextSegment = getNextSegment(allSegments, currentSegment);
285
+ if (nextSegment) {
286
+ setTimeout(function () {
287
+ return selectSegment(nextSegment);
288
+ }, 0);
289
+ }
290
+ } else {
291
+ updateValue(currentSegment, newBuffer);
292
+ }
293
+ return;
294
+ }
295
+
296
+ // 处理左右箭头
297
+ if (key === 'ArrowLeft') {
298
+ e.preventDefault();
299
+ var prevSegment = getPrevSegment(allSegments, currentSegment);
300
+ if (prevSegment) {
301
+ selectSegment(prevSegment);
302
+ }
303
+ return;
304
+ }
305
+ if (key === 'ArrowRight') {
306
+ e.preventDefault();
307
+ var _nextSegment = getNextSegment(allSegments, currentSegment);
308
+ if (_nextSegment) {
309
+ selectSegment(_nextSegment);
310
+ }
311
+ return;
312
+ }
313
+
314
+ // 处理上下箭头调整数值
315
+ if (key === 'ArrowUp' || key === 'ArrowDown') {
316
+ e.preventDefault();
317
+ var currentNum = parseInt(currentSegment.value, 10);
318
+ var delta = key === 'ArrowUp' ? 1 : -1;
319
+ var newNum = currentNum + delta;
320
+ if (newNum > currentSegment.max) {
321
+ newNum = currentSegment.min;
322
+ } else if (newNum < currentSegment.min) {
323
+ newNum = currentSegment.max;
324
+ }
325
+ updateValue(currentSegment, String(newNum));
326
+ setTimeout(function () {
327
+ var _inputRef$current4;
328
+ if ((_inputRef$current4 = inputRef.current) !== null && _inputRef$current4 !== void 0 && _inputRef$current4.input && currentSegment) {
329
+ inputRef.current.input.setSelectionRange(currentSegment.start, currentSegment.end);
330
+ }
331
+ }, 0);
332
+ return;
333
+ }
334
+
335
+ // 处理 Tab 键
336
+ if (key === 'Tab') {
337
+ var _nextSegment2 = e.shiftKey ? getPrevSegment(allSegments, currentSegment) : getNextSegment(allSegments, currentSegment);
338
+ if (_nextSegment2) {
339
+ e.preventDefault();
340
+ selectSegment(_nextSegment2);
341
+ }
342
+ return;
343
+ }
344
+
345
+ // 阻止删除和其他非法输入
346
+ if (key === 'Backspace' || key === 'Delete' || !e.ctrlKey && !e.metaKey && key.length === 1 && !/\d/.test(key)) {
347
+ e.preventDefault();
348
+ return;
349
+ }
350
+ }, [currentSegment, inputBuffer, allSegments, selectSegment, updateValue]);
351
+
352
+ // 处理失焦事件
353
+ var handleBlur = useCallback(function (e) {
354
+ if (currentSegment && inputBuffer) {
355
+ var numValue = parseInt(inputBuffer, 10);
356
+ var clampedValue = Math.max(currentSegment.min, Math.min(currentSegment.max, numValue));
357
+ updateValue(currentSegment, String(clampedValue));
358
+ }
359
+ setIsEditing(false);
360
+ setCurrentSegmentKey(null);
361
+ setInputBuffer('');
362
+ }, [currentSegment, inputBuffer, updateValue]);
363
+
364
+ // 处理粘贴事件
365
+ var handlePaste = useCallback(function (e) {
366
+ e.preventDefault();
367
+ var pastedText = e.clipboardData.getData('text').trim();
368
+ if (!pastedText) return;
369
+ var separators = [' ~ ', '~', ' - ', ' – ', ' — '];
370
+ var startStr = '';
371
+ var endStr = '';
372
+ for (var _i2 = 0, _separators = separators; _i2 < _separators.length; _i2++) {
373
+ var sep = _separators[_i2];
374
+ if (pastedText.includes(sep)) {
375
+ var parts = pastedText.split(sep);
376
+ if (parts.length === 2) {
377
+ startStr = parts[0].trim();
378
+ endStr = parts[1].trim();
379
+ break;
380
+ }
381
+ }
382
+ }
383
+ if (!startStr && !endStr) {
384
+ startStr = pastedText;
385
+ endStr = pastedText;
386
+ }
387
+ var formats = ['YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm', 'YYYY/MM/DD HH:mm:ss', 'YYYY/MM/DD HH:mm', 'MM/DD/YYYY HH:mm:ss', 'MM/DD/YYYY HH:mm', 'YYYY-MM-DD', 'YYYY/MM/DD', 'MM/DD/YYYY'];
388
+ var parsedStart = null;
389
+ var parsedEnd = null;
390
+ for (var _i3 = 0, _formats = formats; _i3 < _formats.length; _i3++) {
391
+ var fmt = _formats[_i3];
392
+ var tryStart = isMoment ? moment(startStr, fmt, true) : dayjs(startStr, fmt, true);
393
+ if (tryStart.isValid()) {
394
+ parsedStart = tryStart;
395
+ break;
396
+ }
397
+ }
398
+ for (var _i4 = 0, _formats2 = formats; _i4 < _formats2.length; _i4++) {
399
+ var _fmt = _formats2[_i4];
400
+ var tryEnd = isMoment ? moment(endStr, _fmt, true) : dayjs(endStr, _fmt, true);
401
+ if (tryEnd.isValid()) {
402
+ parsedEnd = tryEnd;
403
+ break;
404
+ }
405
+ }
406
+ if (parsedStart && parsedEnd) {
407
+ onChange === null || onChange === void 0 || onChange([parsedStart, parsedEnd]);
408
+ } else if (parsedStart) {
409
+ onChange === null || onChange === void 0 || onChange([parsedStart, (value === null || value === void 0 ? void 0 : value[1]) || parsedStart]);
410
+ } else if (parsedEnd) {
411
+ onChange === null || onChange === void 0 || onChange([(value === null || value === void 0 ? void 0 : value[0]) || parsedEnd, parsedEnd]);
412
+ }
413
+ }, [isMoment, onChange, value]);
414
+ return {
415
+ inputRef: inputRef,
416
+ isEditing: isEditing,
417
+ displayValue: displayValue,
418
+ currentSegment: currentSegment,
419
+ allSegments: allSegments,
420
+ handleClick: handleClick,
421
+ handleDoubleClick: handleDoubleClick,
422
+ handleKeyDown: handleKeyDown,
423
+ handleBlur: handleBlur,
424
+ handlePaste: handlePaste
425
+ };
426
+ };
427
+ export default useSegmentedInput;
@@ -12,7 +12,7 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
12
12
  colorTextSecondary = token.colorTextSecondary,
13
13
  colorFillSecondary = token.colorFillSecondary,
14
14
  colorFill = token.colorFill;
15
- return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(componentCls), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
15
+ return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(componentCls), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
16
16
  cursor: 'pointer'
17
17
  }, "".concat(componentCls, "-wrapper"), _defineProperty(_defineProperty({
18
18
  backgroundColor: colorBgContainer,
@@ -116,6 +116,24 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
116
116
  '&:hover': {
117
117
  backgroundColor: "".concat(colorFill, " !important")
118
118
  }
119
+ }), "".concat(componentCls, "-editable-wrapper"), {
120
+ display: 'inline-flex',
121
+ alignItems: 'center'
122
+ }), "".concat(componentCls, "-range-editable"), {
123
+ display: 'inline-flex',
124
+ alignItems: 'center',
125
+ cursor: 'text',
126
+ '&-disabled': {
127
+ cursor: 'not-allowed',
128
+ opacity: 0.6
129
+ }
130
+ }), "".concat(componentCls, "-range-editable-input"), {
131
+ width: 290,
132
+ cursor: 'text',
133
+ caretColor: 'transparent',
134
+ '&:focus, &:focus-within': _defineProperty({}, "".concat(antCls, "-input"), {
135
+ caretColor: token.colorPrimary
136
+ })
119
137
  });
120
138
  };
121
139
  export default (function (prefixCls) {
@@ -38,32 +38,49 @@ var DocDialogComp = function DocDialogComp(props) {
38
38
  embedConfig = _props$embedConfig === void 0 ? {} : _props$embedConfig,
39
39
  _props$normalConfig = props.normalConfig,
40
40
  normalConfig = _props$normalConfig === void 0 ? {} : _props$normalConfig;
41
- var _useState = useState(document.body.clientHeight),
41
+ // Avoid SSR issue: only read document/window on client (e.g. Next.js)
42
+ var _useState = useState(0),
42
43
  _useState2 = _slicedToArray(_useState, 2),
43
44
  clientHeight = _useState2[0],
44
45
  setClientHeight = _useState2[1];
45
- var _useState3 = useState(document.body.clientWidth),
46
+ var _useState3 = useState(0),
46
47
  _useState4 = _slicedToArray(_useState3, 2),
47
48
  clientWidth = _useState4[0],
48
49
  setClientWidth = _useState4[1];
49
- var location = window.location;
50
+ var _useState5 = useState(null),
51
+ _useState6 = _slicedToArray(_useState5, 2),
52
+ location = _useState6[0],
53
+ setLocation = _useState6[1];
54
+ useEffect(function () {
55
+ if (typeof window !== 'undefined') {
56
+ setClientHeight(window.document.body.clientHeight);
57
+ setClientWidth(window.document.body.clientWidth);
58
+ setLocation({
59
+ pathname: window.location.pathname
60
+ });
61
+ }
62
+ }, []);
50
63
  var currentLink = useMemo(function () {
51
- var _link$;
52
- var pathname = location.pathname;
64
+ var _location$pathname, _link$;
65
+ var pathname = (_location$pathname = location === null || location === void 0 ? void 0 : location.pathname) !== null && _location$pathname !== void 0 ? _location$pathname : '';
53
66
  var link = Object.entries(docUrls).find(function (set) {
54
67
  return pathname.indexOf(set[0]) > -1;
55
68
  });
56
69
  return (_link$ = link === null || link === void 0 ? void 0 : link[1]) !== null && _link$ !== void 0 ? _link$ : fallbackUrl;
57
70
  }, [location, docUrls, fallbackUrl]);
58
71
  var handleResize = debounce(function () {
59
- setClientWidth(document.body.clientWidth);
60
- setClientHeight(document.body.clientHeight);
72
+ if (typeof window !== 'undefined') {
73
+ setClientWidth(window.document.body.clientWidth);
74
+ setClientHeight(window.document.body.clientHeight);
75
+ }
61
76
  }, 300);
62
77
  useEffect(function () {
78
+ if (typeof window === 'undefined') return;
63
79
  window.addEventListener('resize', handleResize);
64
80
  return function () {
65
81
  window.removeEventListener('resize', handleResize);
66
82
  };
83
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- register resize listener once on mount
67
84
  }, []);
68
85
  var DialogProps = useMemo(function () {
69
86
  var maxDialogHeight = clientHeight - defautTop;
@@ -29,10 +29,22 @@ export default (function (props) {
29
29
  _useState4 = _slicedToArray(_useState3, 2),
30
30
  menus = _useState4[0],
31
31
  setMenus = _useState4[1];
32
- var location = window.location;
32
+ // Avoid SSR issue: only read window.location on client (e.g. Next.js)
33
+ var _useState5 = useState(null),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ location = _useState6[0],
36
+ setLocation = _useState6[1];
37
+ useEffect(function () {
38
+ if (typeof window !== 'undefined') {
39
+ setLocation({
40
+ pathname: window.location.pathname
41
+ });
42
+ }
43
+ }, []);
33
44
  var navigate = useNavigate();
34
45
  var preProcess = useCallback(function (list) {
35
- var pathname = location.pathname;
46
+ var _location$pathname;
47
+ var pathname = (_location$pathname = location === null || location === void 0 ? void 0 : location.pathname) !== null && _location$pathname !== void 0 ? _location$pathname : '';
36
48
  try {
37
49
  for (var i = 0; i < list.length; i++) {
38
50
  var _list$i = list[i],
@@ -6,6 +6,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
6
6
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
8
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
15
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
16
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
17
  import { useUniqueInlineId } from '@inline-svg-unique-id/react';
@@ -13,7 +19,7 @@ import { ArrowLeftOutlined, SyncOutlined } from '@oceanbase/icons';
13
19
  import { PageContainer as AntPageContainer } from '@ant-design/pro-components';
14
20
  import classNames from 'classnames';
15
21
  import { isObject } from 'lodash';
16
- import React, { useContext } from 'react';
22
+ import React, { useContext, useEffect, useState } from 'react';
17
23
  import { Button, ConfigProvider, Divider, Space, Tooltip, theme } from '@oceanbase/design';
18
24
  import { useSize } from 'ahooks';
19
25
  import LocaleWrapper from "../locale/LocaleWrapper";
@@ -54,7 +60,7 @@ var DocumentIcon = function DocumentIcon(_ref) {
54
60
  });
55
61
  };
56
62
  var PageContainer = function PageContainer(_ref2) {
57
- var _window, _restProps$style;
63
+ var _restProps$style;
58
64
  var customizePrefixCls = _ref2.prefixCls,
59
65
  className = _ref2.className,
60
66
  titleProp = _ref2.title,
@@ -81,8 +87,19 @@ var PageContainer = function PageContainer(_ref2) {
81
87
  var _theme$useToken = theme.useToken(),
82
88
  token = _theme$useToken.token;
83
89
 
90
+ // Avoid SSR issue: only get container element on client (e.g. Next.js)
91
+ var _useState = useState(null),
92
+ _useState2 = _slicedToArray(_useState, 2),
93
+ containerEl = _useState2[0],
94
+ setContainerEl = _useState2[1];
95
+ useEffect(function () {
96
+ if (typeof window !== 'undefined' && window.document) {
97
+ setContainerEl(window.document.querySelector(".".concat(prefixCls)));
98
+ }
99
+ }, [prefixCls]);
100
+
84
101
  // TODO: PageContainer should support ref to get the width of the container
85
- var size = useSize((_window = window) === null || _window === void 0 || (_window = _window.document) === null || _window === void 0 ? void 0 : _window.querySelector(".".concat(prefixCls)));
102
+ var size = useSize(containerEl);
86
103
  var width = size === null || size === void 0 ? void 0 : size.width;
87
104
  var maxWidthValue = (_restProps$style = restProps.style) === null || _restProps$style === void 0 ? void 0 : _restProps$style.maxWidth;
88
105
  var maxWidth = typeof maxWidthValue === 'number' ? maxWidthValue : maxWidthValue !== null && maxWidthValue !== void 0 && maxWidthValue.includes('px') ? parseInt(maxWidthValue) : undefined;
@@ -7,7 +7,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
7
7
  import { genComponentStyleHook } from "../../_util/genComponentStyleHook";
8
8
  import { genFooterToolbarStyle } from "../../FooterToolbar/style";
9
9
  export var genPageContainerStyle = function genPageContainerStyle(token) {
10
- var _$concat$concat;
10
+ var _$concat$concat$conca;
11
11
  var antCls = token.antCls,
12
12
  proComponentsCls = token.proComponentsCls,
13
13
  componentCls = token.componentCls,
@@ -20,13 +20,13 @@ export var genPageContainerStyle = function genPageContainerStyle(token) {
20
20
  backgroundColor: colorBgLayout
21
21
  }, "".concat(proComponentsCls, "-grid-content"), {
22
22
  minHeight: 'auto'
23
- }), "".concat(componentCls, "-warp-page-header,").concat(componentCls, "-wrap-page-header"), (_$concat$concat = {
23
+ }), "".concat(antCls, "-page-header").concat(componentCls, "-warp-page-header, ").concat(antCls, "-page-header").concat(componentCls, "-wrap-page-header"), (_$concat$concat$conca = {
24
24
  // 减小内容区左右两侧间距
25
- paddingInlineStart: "".concat(token.paddingXL, "px !important"),
26
- paddingInlineEnd: "".concat(token.paddingXL, "px !important"),
27
- paddingBlockStart: "".concat(paddingLG, "px !important"),
28
- paddingBlockEnd: "".concat(padding, "px !important")
29
- }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_$concat$concat, "".concat(antCls, "-page-header-breadcrumb"), {
25
+ paddingInlineStart: "".concat(token.paddingXL, "px"),
26
+ paddingInlineEnd: "".concat(token.paddingXL, "px"),
27
+ paddingBlockStart: "".concat(paddingLG, "px"),
28
+ paddingBlockEnd: "".concat(padding, "px")
29
+ }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_$concat$concat$conca, "".concat(antCls, "-page-header-breadcrumb"), {
30
30
  // overwritten pro-components style
31
31
  paddingBlockStart: 0
32
32
  }), "".concat(antCls, "-page-header-heading"), {
@@ -61,7 +61,7 @@ export var genPageContainerStyle = function genPageContainerStyle(token) {
61
61
  marginBlock: 0
62
62
  }), "".concat(antCls, "-page-header-heading-extra"), {
63
63
  marginBlock: 0
64
- }), _defineProperty(_$concat$concat, "".concat(antCls, "-page-header-footer"), _defineProperty({
64
+ }), _defineProperty(_$concat$concat$conca, "".concat(antCls, "-page-header-footer"), _defineProperty({
65
65
  marginBlockStart: 0
66
66
  }, "".concat(antCls, "-tabs-top > ").concat(antCls, "-tabs-nav::before"), {
67
67
  borderBottom: "1px solid ".concat(token.colorBorderSecondary)
@@ -60,7 +60,9 @@ var SideTip = function SideTip(props) {
60
60
  var getLocalStorageKey = useCallback(function (localId) {
61
61
  return ["".concat(prefixCls, "-hide"), localId].join('-');
62
62
  }, [prefixCls]);
63
- var _useState = useState(hideable ? defaultHide === undefined ? window.localStorage.getItem(getLocalStorageKey(id)) === 'true' : !!defaultHide : false),
63
+
64
+ // Avoid SSR issue: same initial value on server and client, then sync from localStorage in useEffect
65
+ var _useState = useState(hideable ? !!defaultHide : false),
64
66
  _useState2 = _slicedToArray(_useState, 2),
65
67
  hide = _useState2[0],
66
68
  setHide = _useState2[1];
@@ -69,6 +71,13 @@ var SideTip = function SideTip(props) {
69
71
  hovered = _useState4[0],
70
72
  setHovered = _useState4[1];
71
73
  useEffect(function () {
74
+ if (typeof window === 'undefined' || !hideable) return;
75
+ if (defaultHide === undefined) {
76
+ setHide(window.localStorage.getItem(getLocalStorageKey(id)) === 'true');
77
+ }
78
+ }, [hideable, defaultHide, id, getLocalStorageKey]);
79
+ useEffect(function () {
80
+ if (typeof window === 'undefined') return;
72
81
  if (hide) {
73
82
  window.localStorage.setItem(getLocalStorageKey(id), 'true');
74
83
  } else {