@oceanbase/ui 1.0.0-alpha.18 → 1.0.0-alpha.19

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.
@@ -7,7 +7,9 @@ import React, { useMemo, useImperativeHandle, forwardRef } from 'react';
7
7
  import classNames from 'classnames';
8
8
  import { Input } from '@oceanbase/design';
9
9
  import { useSegmentedInput } from "./hooks/useSegmentedInput";
10
+ import { useAutoWidthInput } from "./hooks/useAutoWidthInput";
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
13
  var EditableDateTimeInput = /*#__PURE__*/forwardRef(function (props, ref) {
12
14
  var value = props.value,
13
15
  onChange = props.onChange,
@@ -84,6 +86,14 @@ var EditableDateTimeInput = /*#__PURE__*/forwardRef(function (props, ref) {
84
86
  handleKeyDown = _useSegmentedInput.handleKeyDown,
85
87
  hasPastedValue = _useSegmentedInput.hasPastedValue,
86
88
  confirmPastedValue = _useSegmentedInput.confirmPastedValue;
89
+ var _useAutoWidthInput = useAutoWidthInput({
90
+ inputRef: inputRef,
91
+ value: displayValue,
92
+ minWidth: 80,
93
+ extraWidth: isCn ? 26 : 0
94
+ }),
95
+ sizerRef = _useAutoWidthInput.sizerRef,
96
+ inputWidth = _useAutoWidthInput.inputWidth;
87
97
 
88
98
  // 暴露方法给父组件
89
99
  useImperativeHandle(ref, function () {
@@ -92,11 +102,18 @@ var EditableDateTimeInput = /*#__PURE__*/forwardRef(function (props, ref) {
92
102
  confirmPastedValue: confirmPastedValue
93
103
  };
94
104
  });
95
- return /*#__PURE__*/_jsx("div", {
105
+ return /*#__PURE__*/_jsxs("div", {
96
106
  className: classNames("".concat(prefixCls, "-range-editable"), className, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-range-editable-focused"), isEditing), "".concat(prefixCls, "-range-editable-disabled"), disabled)),
97
- children: /*#__PURE__*/_jsx(Input, {
107
+ children: [/*#__PURE__*/_jsx("span", {
108
+ ref: sizerRef,
109
+ className: "".concat(prefixCls, "-range-editable-sizer"),
110
+ "aria-hidden": true
111
+ }), /*#__PURE__*/_jsx(Input, {
98
112
  ref: inputRef,
99
113
  className: "".concat(prefixCls, "-range-editable-input"),
114
+ style: {
115
+ width: inputWidth
116
+ },
100
117
  value: displayValue,
101
118
  readOnly: true,
102
119
  disabled: disabled,
@@ -105,7 +122,7 @@ var EditableDateTimeInput = /*#__PURE__*/forwardRef(function (props, ref) {
105
122
  onDoubleClick: handleDoubleClick,
106
123
  onBlur: handleBlur,
107
124
  onKeyDown: handleKeyDown
108
- })
125
+ })]
109
126
  });
110
127
  });
111
128
  EditableDateTimeInput.displayName = 'EditableDateTimeInput';
@@ -211,7 +211,7 @@ var InternalPickerPanel = function InternalPickerPanel(props) {
211
211
  }],
212
212
  children: /*#__PURE__*/_jsx(DatePicker, {
213
213
  format: {
214
- format: 'YYYY-MM-DD',
214
+ format: DATE_FORMAT,
215
215
  type: 'mask'
216
216
  },
217
217
  style: {
@@ -287,7 +287,7 @@ var InternalPickerPanel = function InternalPickerPanel(props) {
287
287
  }],
288
288
  children: /*#__PURE__*/_jsx(DatePicker, {
289
289
  format: {
290
- format: 'YYYY-MM-DD',
290
+ format: DATE_FORMAT,
291
291
  type: 'mask'
292
292
  },
293
293
  style: {
@@ -1,2 +1,4 @@
1
1
  export { useSegmentedInput } from './useSegmentedInput';
2
+ export { useAutoWidthInput } from './useAutoWidthInput';
2
3
  export type { UseSegmentedInputOptions, UseSegmentedInputReturn } from './useSegmentedInput';
4
+ export type { UseAutoWidthInputOptions, UseAutoWidthInputReturn } from './useAutoWidthInput';
@@ -1 +1,2 @@
1
- export { useSegmentedInput } from "./useSegmentedInput";
1
+ export { useSegmentedInput } from "./useSegmentedInput";
2
+ export { useAutoWidthInput } from "./useAutoWidthInput";
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import type { InputRef } from '@oceanbase/design';
3
+ export interface UseAutoWidthInputOptions {
4
+ inputRef: React.RefObject<InputRef>;
5
+ value: string;
6
+ minWidth?: number;
7
+ extraWidth?: number;
8
+ }
9
+ export interface UseAutoWidthInputReturn {
10
+ inputWidth: number;
11
+ sizerRef: React.RefObject<HTMLSpanElement>;
12
+ }
13
+ export declare const useAutoWidthInput: (options: UseAutoWidthInputOptions) => UseAutoWidthInputReturn;
@@ -0,0 +1,44 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useLayoutEffect, useRef, useState } from 'react';
8
+ var getHorizontalSpacing = function getHorizontalSpacing(computedStyle) {
9
+ return (parseFloat(computedStyle.paddingLeft) || 0) + (parseFloat(computedStyle.paddingRight) || 0) + (parseFloat(computedStyle.borderLeftWidth) || 0) + (parseFloat(computedStyle.borderRightWidth) || 0);
10
+ };
11
+ var getSizingValue = function getSizingValue(value) {
12
+ return value ? value.replace(/\d/g, '0') : "\xA0";
13
+ };
14
+ export var useAutoWidthInput = function useAutoWidthInput(options) {
15
+ var inputRef = options.inputRef,
16
+ value = options.value,
17
+ _options$minWidth = options.minWidth,
18
+ minWidth = _options$minWidth === void 0 ? 80 : _options$minWidth,
19
+ _options$extraWidth = options.extraWidth,
20
+ extraWidth = _options$extraWidth === void 0 ? 0 : _options$extraWidth;
21
+ var sizerRef = useRef(null);
22
+ var _useState = useState(minWidth),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ inputWidth = _useState2[0],
25
+ setInputWidth = _useState2[1];
26
+ useLayoutEffect(function () {
27
+ var _inputRef$current;
28
+ var nativeInput = (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.input;
29
+ var sizer = sizerRef.current;
30
+ if (!nativeInput || !sizer) {
31
+ return;
32
+ }
33
+ var computedStyle = window.getComputedStyle(nativeInput);
34
+ sizer.style.font = computedStyle.font;
35
+ sizer.style.letterSpacing = computedStyle.letterSpacing;
36
+ sizer.style.fontVariantNumeric = computedStyle.fontVariantNumeric;
37
+ sizer.textContent = getSizingValue(value);
38
+ setInputWidth(Math.max(minWidth, Math.ceil(sizer.getBoundingClientRect().width + getHorizontalSpacing(computedStyle) + extraWidth)));
39
+ }, [extraWidth, inputRef, minWidth, value]);
40
+ return {
41
+ inputWidth: inputWidth,
42
+ sizerRef: sizerRef
43
+ };
44
+ };
@@ -128,6 +128,7 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
128
128
  display: 'inline-flex',
129
129
  alignItems: 'center'
130
130
  }), "".concat(componentCls, "-range-editable"), {
131
+ position: 'relative',
131
132
  display: 'inline-flex',
132
133
  alignItems: 'center',
133
134
  cursor: 'text',
@@ -135,10 +136,21 @@ export var genDateRangerStyle = function genDateRangerStyle(token) {
135
136
  cursor: 'not-allowed',
136
137
  opacity: 0.6
137
138
  }
138
- }), _defineProperty(_ref, "".concat(componentCls, "-range-editable-input"), {
139
- width: 310,
139
+ }), _defineProperty(_defineProperty(_ref, "".concat(componentCls, "-range-editable-sizer"), {
140
+ position: 'absolute',
141
+ top: 0,
142
+ left: 0,
143
+ height: 0,
144
+ overflow: 'hidden',
145
+ whiteSpace: 'pre',
146
+ visibility: 'hidden',
147
+ pointerEvents: 'none'
148
+ }), "".concat(componentCls, "-range-editable-input"), {
149
+ minWidth: 80,
150
+ maxWidth: '100%',
140
151
  cursor: 'text',
141
152
  caretColor: 'transparent',
153
+ fontVariantNumeric: 'tabular-nums',
142
154
  '&:focus, &:focus-within': _defineProperty({}, "".concat(antCls, "-input"), {
143
155
  caretColor: token.colorPrimary
144
156
  })
@@ -28,7 +28,7 @@ export declare const THEME_DARK = "dark";
28
28
  export declare const THEME_LIGHT = "light";
29
29
  declare const ThemeTypes: ["dark", "light"];
30
30
  export type ThemeType = (typeof ThemeTypes)[number];
31
- declare const supportedLanguages: ("css" | "json" | "jsx" | "tsx" | "ruby" | "javascript" | "typescript" | "groovy" | "java" | "python" | "bash" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity")[];
31
+ declare const supportedLanguages: ("ruby" | "css" | "json" | "jsx" | "tsx" | "javascript" | "typescript" | "groovy" | "java" | "python" | "bash" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity")[];
32
32
  export type LanguageType = (typeof supportedLanguages)[number] | 'html';
33
33
  export interface HighlightProps extends LocaleWrapperProps {
34
34
  /**
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _classnames = _interopRequireDefault(require("classnames"));
9
9
  var _design = require("@oceanbase/design");
10
10
  var _useSegmentedInput = require("./hooks/useSegmentedInput");
11
+ var _useAutoWidthInput = require("./hooks/useAutoWidthInput");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -85,20 +86,36 @@ const EditableDateTimeInput = /*#__PURE__*/(0, _react.forwardRef)((props, ref) =
85
86
  onClick,
86
87
  open
87
88
  });
89
+ const {
90
+ sizerRef,
91
+ inputWidth
92
+ } = (0, _useAutoWidthInput.useAutoWidthInput)({
93
+ inputRef,
94
+ value: displayValue,
95
+ minWidth: 80,
96
+ extraWidth: isCn ? 26 : 0
97
+ });
88
98
 
89
99
  // 暴露方法给父组件
90
100
  (0, _react.useImperativeHandle)(ref, () => ({
91
101
  hasPastedValue,
92
102
  confirmPastedValue
93
103
  }));
94
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
104
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
95
105
  className: (0, _classnames.default)(`${prefixCls}-range-editable`, className, {
96
106
  [`${prefixCls}-range-editable-focused`]: isEditing,
97
107
  [`${prefixCls}-range-editable-disabled`]: disabled
98
108
  }),
99
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.Input, {
109
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
110
+ ref: sizerRef,
111
+ className: `${prefixCls}-range-editable-sizer`,
112
+ "aria-hidden": true
113
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.Input, {
100
114
  ref: inputRef,
101
115
  className: `${prefixCls}-range-editable-input`,
116
+ style: {
117
+ width: inputWidth
118
+ },
102
119
  value: displayValue,
103
120
  readOnly: true,
104
121
  disabled: disabled,
@@ -107,7 +124,7 @@ const EditableDateTimeInput = /*#__PURE__*/(0, _react.forwardRef)((props, ref) =
107
124
  onDoubleClick: handleDoubleClick,
108
125
  onBlur: handleBlur,
109
126
  onKeyDown: handleKeyDown
110
- })
127
+ })]
111
128
  });
112
129
  });
113
130
  EditableDateTimeInput.displayName = 'EditableDateTimeInput';
@@ -171,7 +171,7 @@ const InternalPickerPanel = props => {
171
171
  }],
172
172
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.DatePicker, {
173
173
  format: {
174
- format: 'YYYY-MM-DD',
174
+ format: DATE_FORMAT,
175
175
  type: 'mask'
176
176
  },
177
177
  style: {
@@ -243,7 +243,7 @@ const InternalPickerPanel = props => {
243
243
  }],
244
244
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_design.DatePicker, {
245
245
  format: {
246
- format: 'YYYY-MM-DD',
246
+ format: DATE_FORMAT,
247
247
  type: 'mask'
248
248
  },
249
249
  style: {
@@ -1,2 +1,4 @@
1
1
  export { useSegmentedInput } from './useSegmentedInput';
2
+ export { useAutoWidthInput } from './useAutoWidthInput';
2
3
  export type { UseSegmentedInputOptions, UseSegmentedInputReturn } from './useSegmentedInput';
4
+ export type { UseAutoWidthInputOptions, UseAutoWidthInputReturn } from './useAutoWidthInput';
@@ -3,10 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "useAutoWidthInput", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useAutoWidthInput.useAutoWidthInput;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "useSegmentedInput", {
7
13
  enumerable: true,
8
14
  get: function () {
9
15
  return _useSegmentedInput.useSegmentedInput;
10
16
  }
11
17
  });
12
- var _useSegmentedInput = require("./useSegmentedInput");
18
+ var _useSegmentedInput = require("./useSegmentedInput");
19
+ var _useAutoWidthInput = require("./useAutoWidthInput");
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import type { InputRef } from '@oceanbase/design';
3
+ export interface UseAutoWidthInputOptions {
4
+ inputRef: React.RefObject<InputRef>;
5
+ value: string;
6
+ minWidth?: number;
7
+ extraWidth?: number;
8
+ }
9
+ export interface UseAutoWidthInputReturn {
10
+ inputWidth: number;
11
+ sizerRef: React.RefObject<HTMLSpanElement>;
12
+ }
13
+ export declare const useAutoWidthInput: (options: UseAutoWidthInputOptions) => UseAutoWidthInputReturn;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAutoWidthInput = void 0;
7
+ var _react = require("react");
8
+ const getHorizontalSpacing = computedStyle => (parseFloat(computedStyle.paddingLeft) || 0) + (parseFloat(computedStyle.paddingRight) || 0) + (parseFloat(computedStyle.borderLeftWidth) || 0) + (parseFloat(computedStyle.borderRightWidth) || 0);
9
+ const getSizingValue = value => value ? value.replace(/\d/g, '0') : '\u00a0';
10
+ const useAutoWidthInput = options => {
11
+ const {
12
+ inputRef,
13
+ value,
14
+ minWidth = 80,
15
+ extraWidth = 0
16
+ } = options;
17
+ const sizerRef = (0, _react.useRef)(null);
18
+ const [inputWidth, setInputWidth] = (0, _react.useState)(minWidth);
19
+ (0, _react.useLayoutEffect)(() => {
20
+ const nativeInput = inputRef.current?.input;
21
+ const sizer = sizerRef.current;
22
+ if (!nativeInput || !sizer) {
23
+ return;
24
+ }
25
+ const computedStyle = window.getComputedStyle(nativeInput);
26
+ sizer.style.font = computedStyle.font;
27
+ sizer.style.letterSpacing = computedStyle.letterSpacing;
28
+ sizer.style.fontVariantNumeric = computedStyle.fontVariantNumeric;
29
+ sizer.textContent = getSizingValue(value);
30
+ setInputWidth(Math.max(minWidth, Math.ceil(sizer.getBoundingClientRect().width + getHorizontalSpacing(computedStyle) + extraWidth)));
31
+ }, [extraWidth, inputRef, minWidth, value]);
32
+ return {
33
+ inputWidth,
34
+ sizerRef
35
+ };
36
+ };
37
+ exports.useAutoWidthInput = useAutoWidthInput;
@@ -181,6 +181,7 @@ const genDateRangerStyle = token => {
181
181
  alignItems: 'center'
182
182
  },
183
183
  [`${componentCls}-range-editable`]: {
184
+ position: 'relative',
184
185
  display: 'inline-flex',
185
186
  alignItems: 'center',
186
187
  cursor: 'text',
@@ -189,10 +190,22 @@ const genDateRangerStyle = token => {
189
190
  opacity: 0.6
190
191
  }
191
192
  },
193
+ [`${componentCls}-range-editable-sizer`]: {
194
+ position: 'absolute',
195
+ top: 0,
196
+ left: 0,
197
+ height: 0,
198
+ overflow: 'hidden',
199
+ whiteSpace: 'pre',
200
+ visibility: 'hidden',
201
+ pointerEvents: 'none'
202
+ },
192
203
  [`${componentCls}-range-editable-input`]: {
193
- width: 310,
204
+ minWidth: 80,
205
+ maxWidth: '100%',
194
206
  cursor: 'text',
195
207
  caretColor: 'transparent',
208
+ fontVariantNumeric: 'tabular-nums',
196
209
  '&:focus, &:focus-within': {
197
210
  [`${antCls}-input`]: {
198
211
  caretColor: token.colorPrimary
@@ -28,7 +28,7 @@ export declare const THEME_DARK = "dark";
28
28
  export declare const THEME_LIGHT = "light";
29
29
  declare const ThemeTypes: ["dark", "light"];
30
30
  export type ThemeType = (typeof ThemeTypes)[number];
31
- declare const supportedLanguages: ("css" | "json" | "jsx" | "tsx" | "ruby" | "javascript" | "typescript" | "groovy" | "java" | "python" | "bash" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity")[];
31
+ declare const supportedLanguages: ("ruby" | "css" | "json" | "jsx" | "tsx" | "javascript" | "typescript" | "groovy" | "java" | "python" | "bash" | "cpp" | "http" | "markdown" | "nginx" | "sql" | "xml" | "dockerfile" | "go" | "yaml" | "solidity")[];
32
32
  export type LanguageType = (typeof supportedLanguages)[number] | 'html';
33
33
  export interface HighlightProps extends LocaleWrapperProps {
34
34
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/ui",
3
- "version": "1.0.0-alpha.18",
3
+ "version": "1.0.0-alpha.19",
4
4
  "description": "The UI library based on OceanBase Design",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -38,7 +38,7 @@
38
38
  "@ant-design/cssinjs": "^1.24.0",
39
39
  "@ant-design/pro-components": "^2.8.10",
40
40
  "@inline-svg-unique-id/react": "^1.2.3",
41
- "@oceanbase/design": "^1.0.0-alpha.18",
41
+ "@oceanbase/design": "^1.0.0-alpha.19",
42
42
  "@oceanbase/icons": "^1.0.0-alpha.1",
43
43
  "@oceanbase/util": "^1.0.0-alpha.2",
44
44
  "ahooks": "^2.10.14",
@@ -67,5 +67,5 @@
67
67
  "react": ">=16.9.0",
68
68
  "react-dom": ">=16.9.0"
69
69
  },
70
- "gitHead": "fc43201ca1a59d2d8d54d0fece7fbb9dba9f7eb9"
70
+ "gitHead": "cd07946b96147dadd8dd0604a2bcac1a3a9464b3"
71
71
  }