x-star-design 0.0.63 → 0.0.65

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,13 @@
1
+ import React from 'react';
2
+ interface AnchorTabProps {
3
+ items: {
4
+ key: string;
5
+ title: string;
6
+ icon: React.ReactNode;
7
+ children: React.ReactNode;
8
+ }[];
9
+ rootMargin?: string;
10
+ stickyOffset?: number;
11
+ }
12
+ declare const AnchorXTabs: ({ items, rootMargin, stickyOffset, }: AnchorTabProps) => React.JSX.Element;
13
+ export default AnchorXTabs;
@@ -0,0 +1,88 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import { useInViewport, useMemoizedFn } from 'ahooks';
4
+ import { Flex } from 'antd';
5
+ import { ConfigContext } from 'antd/es/config-provider';
6
+ import classNames from 'classnames';
7
+ import React, { useContext, useEffect, useRef, useState } from 'react';
8
+ import { hexToRgb } from "../utils/color";
9
+ import { prefix } from "../utils/global";
10
+ var AnchorXTabs = function AnchorXTabs(_ref) {
11
+ var _theme$token;
12
+ var items = _ref.items,
13
+ _ref$rootMargin = _ref.rootMargin,
14
+ rootMargin = _ref$rootMargin === void 0 ? '-50% 0px -50% 0px' : _ref$rootMargin,
15
+ _ref$stickyOffset = _ref.stickyOffset,
16
+ stickyOffset = _ref$stickyOffset === void 0 ? 64 : _ref$stickyOffset;
17
+ var colorThemeRef = useRef(null);
18
+ var _useContext = useContext(ConfigContext),
19
+ theme = _useContext.theme;
20
+ var _ref2 = (_theme$token = theme === null || theme === void 0 ? void 0 : theme.token) !== null && _theme$token !== void 0 ? _theme$token : {},
21
+ _ref2$colorPrimary = _ref2.colorPrimary,
22
+ colorPrimary = _ref2$colorPrimary === void 0 ? '#1990fe' : _ref2$colorPrimary;
23
+ useEffect(function () {
24
+ var _colorThemeRef$curren, _colorThemeRef$curren2;
25
+ // 设置主题色
26
+ (_colorThemeRef$curren = colorThemeRef.current) === null || _colorThemeRef$curren === void 0 ? void 0 : _colorThemeRef$curren.style.setProperty('--anchor-x-tabs-primary-color', colorPrimary);
27
+ (_colorThemeRef$curren2 = colorThemeRef.current) === null || _colorThemeRef$curren2 === void 0 ? void 0 : _colorThemeRef$curren2.style.setProperty('--anchor-x-tabs-secondary-color', hexToRgb(colorPrimary, 0.15));
28
+ }, [colorPrimary]);
29
+ var targetRef = useRef([]);
30
+ var _useState = useState(''),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ activeItem = _useState2[0],
33
+ setActiveItem = _useState2[1];
34
+ var callback = useMemoizedFn(function (entry) {
35
+ if (entry.isIntersecting) {
36
+ var key = entry.target.getAttribute('id');
37
+ setActiveItem(key);
38
+ }
39
+ });
40
+ var handleMenuClick = function handleMenuClick(key) {
41
+ var element = document.getElementById(key);
42
+ element === null || element === void 0 ? void 0 : element.scrollIntoView({
43
+ behavior: 'smooth',
44
+ block: 'center',
45
+ inline: 'nearest'
46
+ });
47
+ };
48
+ useInViewport(targetRef.current, {
49
+ callback: callback,
50
+ rootMargin: rootMargin
51
+ });
52
+ return /*#__PURE__*/React.createElement(Flex, {
53
+ "data-testid": "container",
54
+ gap: 30
55
+ }, /*#__PURE__*/React.createElement("div", {
56
+ ref: colorThemeRef,
57
+ className: "".concat(prefix, "-anchor-x-tabs")
58
+ }, /*#__PURE__*/React.createElement("div", {
59
+ style: {
60
+ position: 'sticky',
61
+ top: stickyOffset
62
+ }
63
+ }, items.map(function (item) {
64
+ var isActive = item.key === activeItem;
65
+ var anchorItemClassName = classNames("".concat(prefix, "-anchor-item"), _defineProperty({}, "".concat(prefix, "-active"), isActive));
66
+ return /*#__PURE__*/React.createElement("div", {
67
+ "data-testid": "anchor-x-tabs-".concat(item.key),
68
+ key: item.key,
69
+ className: anchorItemClassName,
70
+ onClick: function onClick() {
71
+ return handleMenuClick(item.key);
72
+ }
73
+ }, /*#__PURE__*/React.createElement("div", {
74
+ className: "".concat(prefix, "-icon")
75
+ }, item.icon), /*#__PURE__*/React.createElement("div", {
76
+ className: "".concat(prefix, "-title")
77
+ }, item.title));
78
+ }))), /*#__PURE__*/React.createElement("div", null, items.map(function (item, index) {
79
+ return /*#__PURE__*/React.createElement("div", {
80
+ key: item.key,
81
+ ref: function ref(el) {
82
+ return targetRef.current[index] = el;
83
+ },
84
+ id: item.key
85
+ }, item.children);
86
+ })));
87
+ };
88
+ export default AnchorXTabs;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as AcAnimation } from './ac-animation';
2
2
  export { default as Aliplayer } from './aliplayer';
3
3
  export type { AliplayerConfig, AliplayerInstance } from './aliplayer';
4
+ export { default as AnchorXTabs } from './anchor-x-tabs';
4
5
  export { default as CodeDetailModal } from './code-detail-modal';
5
6
  export { default as CodeMirrorWrapper } from './code-mirror-wrapper';
6
7
  export { LangId, Language, Theme } from './code-mirror-wrapper/define';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as AcAnimation } from "./ac-animation";
2
2
  export { default as Aliplayer } from "./aliplayer";
3
+ export { default as AnchorXTabs } from "./anchor-x-tabs";
3
4
  export { default as CodeDetailModal } from "./code-detail-modal";
4
5
  export { default as CodeMirrorWrapper } from "./code-mirror-wrapper";
5
6
  export { LangId, Language, Theme } from "./code-mirror-wrapper/define";
@@ -1,12 +1,13 @@
1
- import { InputNumberProps } from 'antd';
1
+ import type { InputNumberProps } from 'antd';
2
2
  import React from 'react';
3
3
  export interface InputNumbersValue {
4
4
  start?: string | number | null;
5
5
  end?: string | number | null;
6
6
  }
7
- interface InputNumbersProps extends Omit<InputNumberProps, 'value' | 'onChange'> {
7
+ interface InputNumbersProps extends Omit<InputNumberProps, 'defaultValue' | 'value' | 'onChange'> {
8
+ defaultValue?: InputNumbersValue;
8
9
  value?: InputNumbersValue;
9
10
  onChange?: (value: InputNumbersValue) => void;
10
11
  }
11
- declare const InputNumbers: ({ value, onChange, ...props }: InputNumbersProps) => React.JSX.Element;
12
+ declare const InputNumbers: ({ defaultValue, value, onChange, ...props }: InputNumbersProps) => React.JSX.Element;
12
13
  export default InputNumbers;
@@ -1,50 +1,56 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["value", "onChange"];
5
+ var _excluded = ["defaultValue", "value", "onChange"];
6
+ import { useUpdateEffect } from 'ahooks';
5
7
  import { InputNumber, Space } from 'antd';
6
8
  import React, { useState } from 'react';
7
9
  import ConfigProviderWrapper from "../config-provider-wrapper";
8
10
  var InputNumbers = function InputNumbers(_ref) {
9
- var value = _ref.value,
11
+ var _mergedValue$start, _mergedValue$end;
12
+ var defaultValue = _ref.defaultValue,
13
+ value = _ref.value,
10
14
  _onChange = _ref.onChange,
11
15
  props = _objectWithoutProperties(_ref, _excluded);
12
- var _useState = useState(value === null || value === void 0 ? void 0 : value.start),
16
+ var _useState = useState(value !== null && value !== void 0 ? value : defaultValue),
13
17
  _useState2 = _slicedToArray(_useState, 2),
14
- start = _useState2[0],
15
- setStart = _useState2[1];
16
- var _useState3 = useState(value === null || value === void 0 ? void 0 : value.end),
17
- _useState4 = _slicedToArray(_useState3, 2),
18
- end = _useState4[0],
19
- setEnd = _useState4[1];
18
+ innerValue = _useState2[0],
19
+ setInnerValue = _useState2[1];
20
+ var mergedValue = value !== undefined ? value : innerValue;
21
+ useUpdateEffect(function () {
22
+ if (value === undefined) {
23
+ setInnerValue(undefined);
24
+ }
25
+ }, [value]);
20
26
  return /*#__PURE__*/React.createElement(ConfigProviderWrapper, null, /*#__PURE__*/React.createElement(Space, {
21
- split: '-',
22
- align: "center"
27
+ align: "center",
28
+ split: "-"
23
29
  }, /*#__PURE__*/React.createElement(InputNumber, _extends({
24
30
  "data-testid": "start-input",
25
31
  min: 0,
26
32
  max: 100
27
33
  }, props, {
28
- value: (value === null || value === void 0 ? void 0 : value.start) || start,
34
+ value: mergedValue ? (_mergedValue$start = mergedValue.start) !== null && _mergedValue$start !== void 0 ? _mergedValue$start : '' : undefined,
29
35
  onChange: function onChange(v) {
30
- setStart(v);
31
- _onChange === null || _onChange === void 0 ? void 0 : _onChange({
32
- start: v,
33
- end: end
36
+ var newValue = _objectSpread(_objectSpread({}, mergedValue), {}, {
37
+ start: v
34
38
  });
39
+ setInnerValue(newValue);
40
+ _onChange === null || _onChange === void 0 ? void 0 : _onChange(newValue);
35
41
  }
36
42
  })), /*#__PURE__*/React.createElement(InputNumber, _extends({
37
43
  "data-testid": "end-input",
38
44
  min: 0,
39
- max: 100,
40
- value: (value === null || value === void 0 ? void 0 : value.end) || end
45
+ max: 100
41
46
  }, props, {
47
+ value: mergedValue ? (_mergedValue$end = mergedValue.end) !== null && _mergedValue$end !== void 0 ? _mergedValue$end : '' : undefined,
42
48
  onChange: function onChange(v) {
43
- setEnd(v);
44
- _onChange === null || _onChange === void 0 ? void 0 : _onChange({
45
- start: start,
49
+ var newValue = _objectSpread(_objectSpread({}, innerValue), {}, {
46
50
  end: v
47
51
  });
52
+ setInnerValue(newValue);
53
+ _onChange === null || _onChange === void 0 ? void 0 : _onChange(newValue);
48
54
  }
49
55
  }))));
50
56
  };
@@ -1,4 +1,39 @@
1
1
  @charset "UTF-8";
2
+ .x-star-design-anchor-x-tabs {
3
+ width: 120px;
4
+ background-color: var(--anchor-x-tabs-secondary-color);
5
+ }
6
+ .x-star-design-anchor-x-tabs .x-star-design-anchor-item {
7
+ min-height: 120px;
8
+ padding: 14px;
9
+ display: flex;
10
+ flex-direction: column;
11
+ align-items: center;
12
+ justify-content: center;
13
+ word-break: break-all;
14
+ font-size: 16px;
15
+ font-weight: 500;
16
+ color: #a5a5a5;
17
+ background-color: transparent;
18
+ cursor: pointer;
19
+ }
20
+ .x-star-design-anchor-x-tabs .x-star-design-anchor-item .x-star-design-icon {
21
+ font-size: 40px;
22
+ color: #a5a5a5;
23
+ }
24
+ .x-star-design-anchor-x-tabs .x-star-design-anchor-item .x-star-design-title {
25
+ text-align: center;
26
+ }
27
+ .x-star-design-anchor-x-tabs .x-star-design-active {
28
+ color: var(--anchor-x-tabs-primary-color);
29
+ background-color: #fff;
30
+ border-left: 6px solid var(--anchor-x-tabs-primary-color);
31
+ }
32
+ .x-star-design-anchor-x-tabs .x-star-design-active .x-star-design-icon {
33
+ font-size: 40px;
34
+ color: var(--anchor-x-tabs-primary-color);
35
+ }
36
+
2
37
  .x-star-design-codeDetailModal .x-star-design-codeCompileResult {
3
38
  padding: 10px 20px;
4
39
  background-color: #fafafa;
@@ -5,6 +5,7 @@ export declare enum Status {
5
5
  CheckerJudgementFailed = "Checker Judgement Failed",
6
6
  CompileError = "Compile Error",
7
7
  DangerousSyscall = "Dangerous Syscall",
8
+ Hidden = "Hidden",
8
9
  JudgeFailed = "Judge Failed",
9
10
  JudgementFailed = "Judgement Failed",
10
11
  MemoryLimitExceeded = "Memory Limit Exceeded",
@@ -16,7 +17,6 @@ export declare enum Status {
16
17
  Skipped = "Skipped",
17
18
  SpecialJudgeError = "Special Judge Error",
18
19
  TimeLimitExceeded = "Time Limit Exceeded",
19
- Unknown = "Unknown",
20
20
  WrongAnswer = "Wrong Answer"
21
21
  }
22
22
  interface SubmissionStatusProps {
@@ -9,6 +9,7 @@ export var Status = /*#__PURE__*/function (Status) {
9
9
  Status["CheckerJudgementFailed"] = "Checker Judgement Failed";
10
10
  Status["CompileError"] = "Compile Error";
11
11
  Status["DangerousSyscall"] = "Dangerous Syscall";
12
+ Status["Hidden"] = "Hidden";
12
13
  Status["JudgeFailed"] = "Judge Failed";
13
14
  Status["JudgementFailed"] = "Judgement Failed";
14
15
  Status["MemoryLimitExceeded"] = "Memory Limit Exceeded";
@@ -20,12 +21,11 @@ export var Status = /*#__PURE__*/function (Status) {
20
21
  Status["Skipped"] = "Skipped";
21
22
  Status["SpecialJudgeError"] = "Special Judge Error";
22
23
  Status["TimeLimitExceeded"] = "Time Limit Exceeded";
23
- Status["Unknown"] = "Unknown";
24
24
  Status["WrongAnswer"] = "Wrong Answer";
25
25
  return Status;
26
26
  }({});
27
- var scopeColor = new Map([[Status.Accepted, '#00ad07'], [Status.WrongAnswer, '#f44336'], [Status.TimeLimitExceeded, '#56A2F5'], [Status.CompileError, '#F5B13D'], [Status.RuntimeError, '#F56ED3'], [Status.MemoryLimitExceeded, '#9256F5'], [Status.Running, '#ffa500'], [Status.Abnormal, '#9256F5'], [Status.Pending, '#ffa500']]);
28
- var statusZh = new Map([[Status.Abnormal, ''], [Status.Accepted, '答案正确'], [Status.CheckerJudgementFailed, '代码检查失败'], [Status.CompileError, '编译错误'], [Status.DangerousSyscall, '危险系统调用'], [Status.JudgeFailed, '评测失败'], [Status.JudgementFailed, '评测失败'], [Status.MemoryLimitExceeded, '内存超限'], [Status.OutputLimitExceeded, '输出超限'], [Status.Pending, '排队'], [Status.PresentationError, '段错误'], [Status.Running, '运行'], [Status.RuntimeError, '运行出错'], [Status.Skipped, '忽略'], [Status.SpecialJudgeError, ''], [Status.TimeLimitExceeded, '运行超时'], [Status.Unknown, 'OI赛制提交结果不可见'], [Status.WrongAnswer, '答案错误']]);
27
+ var statusColor = new Map([[Status.Abnormal, '#8b008b'], [Status.Accepted, '#00ad07'], [Status.CheckerJudgementFailed, '#ff4500'], [Status.CompileError, '#f5b13d'], [Status.DangerousSyscall, '#ff69b4'], [Status.Hidden, '#808080'], [Status.JudgeFailed, '#2f4f4f'], [Status.JudgementFailed, '#4b0082'], [Status.MemoryLimitExceeded, '#9256f5'], [Status.OutputLimitExceeded, '#4682b4'], [Status.Pending, '#ffa500'], [Status.PresentationError, '#1e90ff'], [Status.Running, '#ff8c00'], [Status.RuntimeError, '#f56ed3'], [Status.Skipped, '#20b2aa'], [Status.SpecialJudgeError, '#ffd700'], [Status.TimeLimitExceeded, '#56a2f5'], [Status.WrongAnswer, '#f44336']]);
28
+ var statusZh = new Map([[Status.Abnormal, '评测异常'], [Status.Accepted, '评测通过'], [Status.CheckerJudgementFailed, '检查器评测失败'], [Status.CompileError, '编译错误'], [Status.DangerousSyscall, '危险系统调用'], [Status.Hidden, '结果隐藏'], [Status.JudgeFailed, '评测失败'], [Status.JudgementFailed, '评测失败'], [Status.MemoryLimitExceeded, '内存超限'], [Status.OutputLimitExceeded, '输出超限'], [Status.Pending, '等待'], [Status.PresentationError, '格式错误'], [Status.Running, '运行中'], [Status.RuntimeError, '运行时错误'], [Status.Skipped, '跳过'], [Status.SpecialJudgeError, '特判器错误'], [Status.TimeLimitExceeded, '时间超限'], [Status.WrongAnswer, '答案错误']]);
29
29
  var SubmissionStatus = function SubmissionStatus(_ref) {
30
30
  var className = _ref.className,
31
31
  style = _ref.style,
@@ -34,13 +34,13 @@ var SubmissionStatus = function SubmissionStatus(_ref) {
34
34
  var _useLocale = useLocale('CodeDetailModal'),
35
35
  locale = _useLocale.locale;
36
36
  return /*#__PURE__*/React.createElement(ConfigProviderWrapper, null, /*#__PURE__*/React.createElement(Tooltip, {
37
- title: locale === 'zh_CN' && (statusZh === null || statusZh === void 0 ? void 0 : statusZh.get(status))
37
+ title: locale === 'zh_CN' && statusZh.get(status)
38
38
  }, /*#__PURE__*/React.createElement("div", {
39
39
  "data-testid": 'submissionStatus',
40
40
  className: className,
41
41
  style: _objectSpread({
42
42
  fontWeight: 'bold',
43
- color: scopeColor.get(status),
43
+ color: statusColor.get(status),
44
44
  cursor: onClick ? 'pointer' : 'unset'
45
45
  }, style),
46
46
  onClick: onClick
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 将 16 进制颜色转换成 RGB
3
+ *
4
+ * @param hex 16 进制颜色
5
+ * @param alpha 透明度
6
+ * @returns RGB 颜色
7
+ */
8
+ export declare const hexToRgb: (hex: string, alpha: number) => string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 将 16 进制颜色转换成 RGB
3
+ *
4
+ * @param hex 16 进制颜色
5
+ * @param alpha 透明度
6
+ * @returns RGB 颜色
7
+ */
8
+ export var hexToRgb = function hexToRgb(hex, alpha) {
9
+ var r, g, b;
10
+ if (hex.length === 4) {
11
+ r = +"0x".concat(hex[1]).concat(hex[1]);
12
+ g = +"0x".concat(hex[2]).concat(hex[2]);
13
+ b = +"0x".concat(hex[3]).concat(hex[3]);
14
+ } else {
15
+ r = +"0x".concat(hex[1]).concat(hex[2]);
16
+ g = +"0x".concat(hex[3]).concat(hex[4]);
17
+ b = +"0x".concat(hex[5]).concat(hex[6]);
18
+ }
19
+ return "rgb(".concat(r, " ").concat(g, " ").concat(b, " / ").concat(alpha, ")");
20
+ };
@@ -7,24 +7,8 @@ import { ConfigContext } from 'antd/es/config-provider';
7
7
  import classNames from 'classnames';
8
8
  import React, { useContext, useEffect, useMemo, useRef } from 'react';
9
9
  import ConfigProviderWrapper from "../config-provider-wrapper";
10
+ import { hexToRgb } from "../utils/color";
10
11
  import { prefix } from "../utils/global";
11
-
12
- //hash颜色转换rgba
13
- function hexToRGBA(hex, alpha) {
14
- var r = '',
15
- g = '',
16
- b = '';
17
- if (hex.length === 4) {
18
- r = '0x' + hex[1] + hex[1];
19
- g = '0x' + hex[2] + hex[2];
20
- b = '0x' + hex[3] + hex[3];
21
- } else {
22
- r = '0x' + hex[1] + hex[2];
23
- g = '0x' + hex[3] + hex[4];
24
- b = '0x' + hex[5] + hex[6];
25
- }
26
- return "rgba(".concat(+r, ",").concat(+g, ",").concat(+b, ",").concat(alpha, ")");
27
- }
28
12
  var XTabs = function XTabs(_ref) {
29
13
  var _theme$token;
30
14
  var className = _ref.className,
@@ -38,9 +22,9 @@ var XTabs = function XTabs(_ref) {
38
22
  colorPrimary = _ref2$colorPrimary === void 0 ? '#1990fe' : _ref2$colorPrimary;
39
23
  useEffect(function () {
40
24
  var _colorThemeRef$curren, _colorThemeRef$curren2;
41
- //设置主题色
25
+ // 设置主题色
42
26
  (_colorThemeRef$curren = colorThemeRef.current) === null || _colorThemeRef$curren === void 0 ? void 0 : _colorThemeRef$curren.style.setProperty('--x-tabs-primary-color', colorPrimary);
43
- (_colorThemeRef$curren2 = colorThemeRef.current) === null || _colorThemeRef$curren2 === void 0 ? void 0 : _colorThemeRef$curren2.style.setProperty('--x-tabs-secondary-color', hexToRGBA(colorPrimary, 0.15));
27
+ (_colorThemeRef$curren2 = colorThemeRef.current) === null || _colorThemeRef$curren2 === void 0 ? void 0 : _colorThemeRef$curren2.style.setProperty('--x-tabs-secondary-color', hexToRgb(colorPrimary, 0.15));
44
28
  }, [colorPrimary]);
45
29
  var newItems = useMemo(function () {
46
30
  return items === null || items === void 0 ? void 0 : items.map(function (item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-star-design",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "A react component library developed by turingstar",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -57,7 +57,7 @@
57
57
  "@uiw/codemirror-theme-okaidia": "^4.21.9",
58
58
  "@uiw/codemirror-theme-vscode": "^4.21.9",
59
59
  "@uiw/react-codemirror": "^4.21.9",
60
- "ahooks": "^3.7.8",
60
+ "ahooks": "^3.8.0",
61
61
  "classnames": "^2.3.2",
62
62
  "randomcolor": "^0.6.2",
63
63
  "react-error-boundary": "^4.0.13",