@algoux/standard-ranklist-renderer-component-react 0.5.0
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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/DefaultSolutionModal.d.ts +12 -0
- package/dist/DefaultUserModal.d.ts +13 -0
- package/dist/MarkerLabel.d.ts +9 -0
- package/dist/Modal.d.ts +16 -0
- package/dist/ProgressBar.d.ts +48 -0
- package/dist/Ranklist.d.ts +51 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1014 -0
- package/dist/internal/ProblemHeaderCell.d.ts +8 -0
- package/dist/internal/SolutionResultLabel.d.ts +5 -0
- package/dist/internal/SolutionTable.d.ts +5 -0
- package/dist/internal/StatusCell.d.ts +13 -0
- package/dist/internal/UserCell.d.ts +14 -0
- package/dist/internal/UserModalContent.d.ts +9 -0
- package/dist/main.d.ts +9 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 algoUX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @algoux/standard-ranklist-renderer-component-react
|
|
2
|
+
|
|
3
|
+
React components for rendering Standard Ranklist data.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @algoux/standard-ranklist
|
|
9
|
+
npm i -S @algoux/standard-ranklist-renderer-component-react @algoux/standard-ranklist-renderer-component-core @algoux/standard-ranklist-renderer-component-styles
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Main Exports
|
|
13
|
+
|
|
14
|
+
- `Ranklist`
|
|
15
|
+
- `ProgressBar`
|
|
16
|
+
- `Modal`
|
|
17
|
+
- `DefaultUserModal`
|
|
18
|
+
- `DefaultSolutionModal`
|
|
19
|
+
- `MarkerLabel`
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Import the shared stylesheet once in your app entry. `Ranklist` expects a static ranklist, so convert an SRK ranklist before rendering. User/status cell clicks are emitted as semantic payloads; use those payloads to open the default modals or your own UI.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useMemo, useState } from 'react';
|
|
27
|
+
import { convertToStaticRanklist } from '@algoux/standard-ranklist-renderer-component-core';
|
|
28
|
+
import {
|
|
29
|
+
DefaultSolutionModal,
|
|
30
|
+
DefaultUserModal,
|
|
31
|
+
ProgressBar,
|
|
32
|
+
Ranklist,
|
|
33
|
+
type SolutionClickPayload,
|
|
34
|
+
type UserClickPayload,
|
|
35
|
+
} from '@algoux/standard-ranklist-renderer-component-react';
|
|
36
|
+
import '@algoux/standard-ranklist-renderer-component-styles';
|
|
37
|
+
|
|
38
|
+
function Board({ ranklist }) {
|
|
39
|
+
const staticRanklist = useMemo(() => convertToStaticRanklist(ranklist), [ranklist]);
|
|
40
|
+
const [activeUser, setActiveUser] = useState<UserClickPayload | null>(null);
|
|
41
|
+
const [activeSolution, setActiveSolution] = useState<SolutionClickPayload | null>(null);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<ProgressBar data={ranklist} enableTimeTravel onTimeTravel={(time) => console.log(time)} />
|
|
46
|
+
<Ranklist
|
|
47
|
+
data={staticRanklist}
|
|
48
|
+
stripedRows
|
|
49
|
+
onUserClick={(payload) => {
|
|
50
|
+
setActiveUser(payload);
|
|
51
|
+
setActiveSolution(null);
|
|
52
|
+
}}
|
|
53
|
+
onSolutionClick={(payload) => {
|
|
54
|
+
setActiveSolution(payload);
|
|
55
|
+
setActiveUser(null);
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
<DefaultUserModal
|
|
59
|
+
open={!!activeUser}
|
|
60
|
+
user={activeUser?.user}
|
|
61
|
+
markers={staticRanklist.markers}
|
|
62
|
+
onClose={() => setActiveUser(null)}
|
|
63
|
+
/>
|
|
64
|
+
<DefaultSolutionModal
|
|
65
|
+
open={!!activeSolution}
|
|
66
|
+
user={activeSolution?.user}
|
|
67
|
+
problem={activeSolution?.problem}
|
|
68
|
+
problemIndex={activeSolution?.problemIndex || 0}
|
|
69
|
+
solutions={activeSolution?.solutions || []}
|
|
70
|
+
onClose={() => setActiveSolution(null)}
|
|
71
|
+
/>
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Use `Modal` directly when you want custom modal content. `Ranklist` also accepts `parts` such as `userCell` and `statusCell` when you need to replace selected table cells while keeping the rest of the renderer.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type * as srk from '@algoux/standard-ranklist';
|
|
3
|
+
import { type ModalProps } from './Modal';
|
|
4
|
+
export interface DefaultSolutionModalProps extends Pick<ModalProps, 'open' | 'onClose' | 'rootClassName' | 'wrapClassName' | 'style'> {
|
|
5
|
+
user?: srk.User | null;
|
|
6
|
+
problem?: srk.Problem;
|
|
7
|
+
problemIndex: number;
|
|
8
|
+
solutions: srk.Solution[];
|
|
9
|
+
title?: ReactNode;
|
|
10
|
+
width?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function DefaultSolutionModal({ open, user, problem, problemIndex, solutions, title, width, onClose, rootClassName, wrapClassName, style, }: DefaultSolutionModalProps): JSX.Element | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type * as srk from '@algoux/standard-ranklist';
|
|
3
|
+
import { EnumTheme } from '@algoux/standard-ranklist-utils';
|
|
4
|
+
import { type ModalProps } from './Modal';
|
|
5
|
+
export interface DefaultUserModalProps extends Pick<ModalProps, 'open' | 'onClose' | 'rootClassName' | 'wrapClassName' | 'style'> {
|
|
6
|
+
user?: srk.User | null;
|
|
7
|
+
markers?: srk.Marker[];
|
|
8
|
+
theme?: EnumTheme;
|
|
9
|
+
title?: ReactNode;
|
|
10
|
+
width?: number;
|
|
11
|
+
formatSrkAssetUrl?: (url: string, field: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare function DefaultUserModal({ open, user, markers, theme, title, width, formatSrkAssetUrl, onClose, rootClassName, wrapClassName, style, }: DefaultUserModalProps): JSX.Element | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as srk from '@algoux/standard-ranklist';
|
|
2
|
+
import { EnumTheme } from '@algoux/standard-ranklist-utils';
|
|
3
|
+
export interface MarkerLabelProps {
|
|
4
|
+
marker: srk.Marker;
|
|
5
|
+
theme: EnumTheme;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
}
|
|
9
|
+
export declare function MarkerLabel(props: MarkerLabelProps): JSX.Element | null;
|
package/dist/Modal.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare type ModalCloseReason = 'mask' | 'close-button' | 'escape';
|
|
3
|
+
export interface ModalProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
title?: React.ReactNode;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
width?: number;
|
|
8
|
+
rootClassName?: string;
|
|
9
|
+
wrapClassName?: string;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
destroyOnClose?: boolean;
|
|
12
|
+
closeOnEsc?: boolean;
|
|
13
|
+
closeOnMaskClick?: boolean;
|
|
14
|
+
onClose?: (event: React.SyntheticEvent | Event, reason: ModalCloseReason) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function Modal({ open, title, children, width, rootClassName, wrapClassName, style, destroyOnClose, closeOnEsc, closeOnMaskClick, onClose, }: ModalProps): JSX.Element | null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type * as srk from '@algoux/standard-ranklist';
|
|
3
|
+
export interface ProgressBarProps {
|
|
4
|
+
data: srk.Ranklist;
|
|
5
|
+
/** Whether to enable time travel. */
|
|
6
|
+
enableTimeTravel?: boolean;
|
|
7
|
+
/** Whether to enable live progress bar. */
|
|
8
|
+
live?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Used for correct time diff in live mode, calculated by `localTime - serverTime` in ms.
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
td?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Called when time travel is entered and the time slider is moved.
|
|
16
|
+
* @param time The selected time in ms. `null` if time travel is exited.
|
|
17
|
+
*/
|
|
18
|
+
onTimeTravel?(time: number | null): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
interface State {
|
|
21
|
+
localTime: number;
|
|
22
|
+
inTimeMachine: boolean;
|
|
23
|
+
timeTravelIsChanging: boolean;
|
|
24
|
+
timeTravelCurrentValue: number;
|
|
25
|
+
timeTravelValue: number | null;
|
|
26
|
+
isMounted: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare class ProgressBar extends React.Component<ProgressBarProps, State> {
|
|
29
|
+
private liveInterval;
|
|
30
|
+
static getDurationMinutes(contest: srk.Contest): number;
|
|
31
|
+
static getMaxAvailableMinutes(contest: srk.Contest, localTime: number, td?: number): number;
|
|
32
|
+
constructor(props: ProgressBarProps);
|
|
33
|
+
get durationMinutes(): number;
|
|
34
|
+
get maxAvailableMinutes(): number;
|
|
35
|
+
get isEnded(): boolean;
|
|
36
|
+
componentDidMount(): void;
|
|
37
|
+
componentDidUpdate(prevProps: ProgressBarProps): void;
|
|
38
|
+
componentWillUnmount(): void;
|
|
39
|
+
handleProgressTimer: () => void;
|
|
40
|
+
handleTimeTravelChange: (value: number) => void;
|
|
41
|
+
beginTimeTravel: () => void;
|
|
42
|
+
handleSliderChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
43
|
+
commitTimeTravel: () => void;
|
|
44
|
+
handleSliderKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
45
|
+
handleSliderKeyUp: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
46
|
+
render(): JSX.Element;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type * as srk from '@algoux/standard-ranklist';
|
|
3
|
+
import { EnumTheme } from '@algoux/standard-ranklist-utils';
|
|
4
|
+
import type { RankValue, SolutionClickPayload, StaticRanklist, UserClickPayload } from '@algoux/standard-ranklist-renderer-component-core';
|
|
5
|
+
import type { ProblemHeaderCellProps } from './internal/ProblemHeaderCell';
|
|
6
|
+
import type { StatusCellProps } from './internal/StatusCell';
|
|
7
|
+
import type { UserCellProps } from './internal/UserCell';
|
|
8
|
+
export type { RankValue, StaticRanklist } from '@algoux/standard-ranklist-renderer-component-core';
|
|
9
|
+
export type { ProblemHeaderCellProps } from './internal/ProblemHeaderCell';
|
|
10
|
+
export type { StatusCellProps } from './internal/StatusCell';
|
|
11
|
+
export type { UserCellProps } from './internal/UserCell';
|
|
12
|
+
export interface RanklistComponents {
|
|
13
|
+
problemHeaderCell: React.ComponentType<ProblemHeaderCellProps>;
|
|
14
|
+
userCell: React.ComponentType<UserCellProps>;
|
|
15
|
+
statusCell: React.ComponentType<StatusCellProps>;
|
|
16
|
+
}
|
|
17
|
+
export interface RanklistProps {
|
|
18
|
+
data: StaticRanklist;
|
|
19
|
+
/**
|
|
20
|
+
* Theme
|
|
21
|
+
* @defaultValue 'light'
|
|
22
|
+
*/
|
|
23
|
+
theme?: EnumTheme;
|
|
24
|
+
/**
|
|
25
|
+
* Enable border between rows in the table.
|
|
26
|
+
* @defaultValue false
|
|
27
|
+
*/
|
|
28
|
+
borderedRows?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Enable striped rows style in the table.
|
|
31
|
+
* @defaultValue false
|
|
32
|
+
*/
|
|
33
|
+
stripedRows?: boolean;
|
|
34
|
+
formatSrkAssetUrl?: (url: string, field: string) => string;
|
|
35
|
+
onUserClick?: (payload: UserClickPayload) => void | Promise<void>;
|
|
36
|
+
onSolutionClick?: (payload: SolutionClickPayload) => void | Promise<void>;
|
|
37
|
+
components?: Partial<RanklistComponents>;
|
|
38
|
+
}
|
|
39
|
+
interface State {
|
|
40
|
+
marker: string;
|
|
41
|
+
error: string | null;
|
|
42
|
+
}
|
|
43
|
+
export declare class Ranklist extends React.Component<RanklistProps, State> {
|
|
44
|
+
static defaultProps: Partial<RanklistProps>;
|
|
45
|
+
constructor(props: RanklistProps);
|
|
46
|
+
genExternalLink(link: string, children: React.ReactNode): JSX.Element;
|
|
47
|
+
formatSrkAssetUrl: (url: string, field: string) => string;
|
|
48
|
+
renderContestBanner: () => JSX.Element | null;
|
|
49
|
+
renderSingleSeriesBody: (rk: RankValue, series: srk.RankSeries, row: srk.RanklistRow) => JSX.Element;
|
|
50
|
+
render(): JSX.Element;
|
|
51
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";var H=Object.defineProperty;var J=(e,s,t)=>s in e?H(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t;var b=(e,s,t)=>(J(e,typeof s!="symbol"?s+"":s,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("@algoux/standard-ranklist-renderer-component-styles");var W=require("classnames"),Y=require("react"),d=require("@algoux/standard-ranklist-utils"),u=require("@algoux/standard-ranklist-renderer-component-core"),G=require("react-dom");function U(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var M=U(W),k=U(Y),Q=U(G),P={exports:{}},E={};/** @license React v16.14.0
|
|
2
|
+
* react-jsx-runtime.production.min.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/var X=k.default,B=60103;E.Fragment=60107;if(typeof Symbol=="function"&&Symbol.for){var L=Symbol.for;B=L("react.element"),E.Fragment=L("react.fragment")}var Z=X.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ee=Object.prototype.hasOwnProperty,te={key:!0,ref:!0,__self:!0,__source:!0};function j(e,s,t){var a,n={},i=null,l=null;t!==void 0&&(i=""+t),s.key!==void 0&&(i=""+s.key),s.ref!==void 0&&(l=s.ref);for(a in s)ee.call(s,a)&&!te.hasOwnProperty(a)&&(n[a]=s[a]);if(e&&e.defaultProps)for(a in s=e.defaultProps,s)n[a]===void 0&&(n[a]=s[a]);return{$$typeof:B,type:e,key:i,ref:l,props:n,_owner:Z.current}}E.jsx=j;E.jsxs=j;P.exports=E;const r=P.exports.jsx,h=P.exports.jsxs,D=P.exports.Fragment;function re({problem:e,index:s,theme:t}){const a=e.alias?e.alias:d.numberToAlphabet(s),n=e.statistics,i=n?`${n.accepted} / ${n.submitted} (${n.submitted?(n.accepted/n.submitted*100).toFixed(1):0}%)`:"",l=h(D,{children:[r("span",{className:"srk--display-block",children:a}),n?r("span",{title:i,className:"srk--display-block srk-problem-stats",children:n.accepted}):null]}),o=e.link?r("a",{href:e.link,target:"_blank",rel:"noopener noreferrer",style:{color:"unset"},children:l}):l;return r("th",{className:"srk--nowrap srk-problem-header",style:{backgroundImage:u.getProblemHeaderBackgroundImage(e.style,t)},children:o},e.alias||d.resolveText(e.title))}function se({status:e,problem:s,problemIndex:t,user:a,row:n,rowIndex:i,ranklist:l,onSolutionClick:o}){const c=(s==null?void 0:s.alias)||d.resolveText(s==null?void 0:s.title)||t,T=d.resolveText(s==null?void 0:s.title)||null,m=[...e.solutions||[]].reverse(),g=m.length>0&&!!o,N=M.default("srk-prest-status-block srk--text-center srk--nowrap",{"srk--cursor-pointer":g}),v=g?y=>{y.preventDefault(),u.captureModalTriggerPointFromMouseEvent(y.nativeEvent,{source:"status-cell",context:{rowIndex:i,problemIndex:t,problemAlias:(s==null?void 0:s.alias)||null,problemTitle:T,userId:a.id||null}}),o==null||o({user:a,row:n,rowIndex:i,problemIndex:t,problem:s,status:e,solutions:m,ranklist:l})}:void 0;return e.result==="FB"?r("td",{onClick:v,className:M.default(N,"srk-prest-status-block-fb"),children:O(e)},c):e.result==="AC"?r("td",{onClick:v,className:M.default(N,"srk-prest-status-block-accepted"),children:O(e)},c):e.result==="?"?r("td",{onClick:v,className:M.default(N,"srk-prest-status-block-frozen"),children:e.tries},c):e.result==="RJ"?r("td",{onClick:v,className:M.default(N,"srk-prest-status-block-failed"),children:e.tries},c):r("td",{},c)}function O(e){const s=u.getAcceptedStatusDetails(e);return typeof e.score=="number"?h(D,{children:[r("span",{className:"srk-prest-status-block-score",children:e.score}),r("span",{className:"srk-prest-status-block-score-details",children:s})]}):r(D,{children:s})}function ae({user:e,row:s,rowIndex:t,ranklist:a,markers:n=[],theme:i,formatSrkAssetUrl:l,onUserClick:o}){const c=d.resolveUserMarkers(e,n),T=c.map(f=>u.getMarkerPresentation(f,i)),m=d.resolveText(e.name);return r("td",{className:M.default("srk--text-left srk--nowrap srk-user-cell",{"srk--cursor-pointer":!!o}),title:"",onClick:f=>{f.preventDefault(),u.captureModalTriggerPointFromMouseEvent(f.nativeEvent,{source:"user-cell",context:{rowIndex:t,userId:e.id||null,userName:m}}),o==null||o({user:e,row:s,rowIndex:t,ranklist:a})},children:h("div",{className:"srk-user-cell-content",children:[e.avatar&&r("div",{className:"srk-user-avatar",children:r("img",{src:l(e.avatar,"user.avatar"),alt:"User Avatar"})}),h("div",{className:"srk-user-body",children:[h("div",{className:"srk-user-name-row",children:[r("span",{className:"srk-user-name-text",title:m,children:m}),r("span",{className:"srk-marker-dot-group",children:T.map((f,g)=>r("span",{className:M.default("srk-marker srk-marker-dot srk--c-tooltip",f.className),style:f.style,"data-tooltip":d.resolveText(c[g].label)},c[g].id))})]}),!!e.organization&&r("p",{className:"srk-user-secondary-text srk--text-ellipsis",title:"",children:d.resolveText(e.organization)})]})]})})}class z extends k.default.Component{constructor(t){super(t);b(this,"formatSrkAssetUrl",(t,a)=>u.resolveSrkAssetUrl(t,a,this.props.formatSrkAssetUrl));b(this,"renderContestBanner",()=>{const t=this.props.data.contest.banner;if(!t)return null;let a="",n="";typeof t=="string"?a=t:(a=t.image,n=t.link);const i=r("img",{src:this.formatSrkAssetUrl(a,"contest.banner"),alt:"Contest Banner",className:"srk--full-width"});return n?this.genExternalLink(n,i):i});b(this,"renderSingleSeriesBody",(t,a,n)=>{const i=this.props.theme,l=t.rank?t.rank:n.user.official===!1?"\uFF0A":"",c=((a.segments||[])[t.segmentIndex||t.segmentIndex===0?t.segmentIndex:-1]||{}).style;let T="",m={[d.EnumTheme.light]:void 0,[d.EnumTheme.dark]:void 0},f={[d.EnumTheme.light]:void 0,[d.EnumTheme.dark]:void 0};if(typeof c=="string")T=`srk-preset-series-segment-${c}`;else if(c){const g=d.resolveStyle(c);m=g.textColor,f=g.backgroundColor}return r("td",{className:M.default("srk--text-right srk--nowrap",T),style:{color:m[i],backgroundColor:f[i]},children:l},a.title)});this.state={marker:"all",error:null}}genExternalLink(t,a){return r("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{color:"unset"},children:a})}render(){var y,w,C;const{error:t}=this.state;if(t)return r("div",{children:h("div",{className:"srk-error",children:[h("pre",{children:["Error: ",t]}),r("p",{children:"Please wait for data correction or refresh page"})]})});const{data:a,borderedRows:n,stripedRows:i}=this.props,{type:l,version:o,problems:c,series:T,rows:m}=a,f=((y=this.props.components)==null?void 0:y.problemHeaderCell)||re,g=((w=this.props.components)==null?void 0:w.userCell)||ae,N=((C=this.props.components)==null?void 0:C.statusCell)||se;if(l!=="general")return h("div",{children:['srk type "',l,'" is not supported']});if(!u.caniuse(o))return h("div",{children:['srk version "',o,'" is not supported (current supported: ',u.srkSupportedVersions,")"]});const v=u.shouldShowTimeColumn(m);return r(D,{children:r("div",{className:"srk-common-table srk-main",children:h("table",{className:M.default({"srk-table-row-bordered":n,"srk-table-row-striped":i}),children:[r("thead",{children:h("tr",{children:[T.map(p=>r("th",{className:"srk-series-header srk--text-right srk--nowrap",children:p.title},p.title)),r("th",{className:"srk--text-left srk--nowrap",children:"Name"}),r("th",{className:"srk--nowrap",children:"Score"}),v&&r("th",{className:"srk--nowrap",children:"Time"}),c.map((p,A)=>r(f,{problem:p,index:A,theme:this.props.theme},p.alias||d.resolveText(p.title)))]})}),r("tbody",{children:m.map((p,A)=>{p.rankValues||console.warn("Rank values is not provided, you may need to pass static ranklist data generated by `convertToStaticRanklist()`");const _=p.rankValues||T.map(R=>({rank:null,segmentIndex:null}));return h("tr",{children:[_.map((R,S)=>this.renderSingleSeriesBody(R,T[S],p)),r(g,{user:p.user,row:p,rowIndex:A,ranklist:a,markers:a.markers,theme:this.props.theme,formatSrkAssetUrl:this.formatSrkAssetUrl,onUserClick:this.props.onUserClick}),r("td",{className:"srk--text-right srk--nowrap",children:p.score.value}),v&&r("td",{className:"srk--text-right srk--nowrap",children:p.score.time?d.formatTimeDuration(p.score.time,"min",Math.floor):"-"}),p.statuses.map((R,S)=>r(N,{status:R,problem:c[S],problemIndex:S,user:p.user,row:p,rowIndex:A,ranklist:a,onSolutionClick:this.props.onSolutionClick},(c[S]||{}).alias||d.resolveText((c[S]||{}).title)||S))]},p.user.id||d.resolveText(p.user.name))})})]})})})}}b(z,"defaultProps",{theme:d.EnumTheme.light,borderedRows:!1,stripedRows:!1});class I extends k.default.Component{constructor(t){super(t);b(this,"liveInterval");b(this,"handleProgressTimer",()=>{const t=Date.now();this.setState({localTime:t}),this.isEnded&&window.clearInterval(this.liveInterval)});b(this,"handleTimeTravelChange",t=>{var n,i;let a=t>=this.durationMinutes||t>=this.maxAvailableMinutes;(i=(n=this.props).onTimeTravel)==null||i.call(n,a?null:t*60*1e3),this.setState({inTimeMachine:!a,timeTravelValue:a?null:t*60*1e3,timeTravelIsChanging:!1})});b(this,"beginTimeTravel",()=>{this.setState({timeTravelIsChanging:!0,inTimeMachine:!0})});b(this,"handleSliderChange",t=>{this.setState({timeTravelCurrentValue:Number(t.target.value)})});b(this,"commitTimeTravel",()=>{this.handleTimeTravelChange(this.state.timeTravelCurrentValue)});b(this,"handleSliderKeyDown",t=>{["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(t.key)&&this.beginTimeTravel()});b(this,"handleSliderKeyUp",t=>{["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(t.key)&&this.commitTimeTravel()});const a=Date.now();this.state={localTime:a,inTimeMachine:!1,timeTravelIsChanging:!1,timeTravelCurrentValue:I.getMaxAvailableMinutes(t.data.contest,a,t.td),timeTravelValue:null,isMounted:!1}}static getDurationMinutes(t){return u.getProgressDurationMinutes(t)}static getMaxAvailableMinutes(t,a,n){return u.getProgressMaxAvailableMinutes(t,a,n)}get durationMinutes(){return I.getDurationMinutes(this.props.data.contest)}get maxAvailableMinutes(){return I.getMaxAvailableMinutes(this.props.data.contest,this.state.localTime,this.props.td)}get isEnded(){return u.isProgressEnded(this.props.data.contest,this.state.localTime,this.props.td)}componentDidMount(){this.props.live&&(this.liveInterval=window.setInterval(()=>{this.handleProgressTimer()},1e3)),this.setState({isMounted:!0})}componentDidUpdate(t){var a,n,i,l,o,c;!this.props.live&&t.live&&this.liveInterval&&window.clearInterval(this.liveInterval),this.props.live&&!t.live&&(this.liveInterval=window.setInterval(()=>{this.handleProgressTimer()},1e3)),!this.state.timeTravelIsChanging&&this.state.timeTravelCurrentValue!==this.maxAvailableMinutes&&this.state.timeTravelValue===null&&this.setState({timeTravelCurrentValue:this.maxAvailableMinutes}),JSON.stringify((n=(a=this.props.data)==null?void 0:a.contest)==null?void 0:n.title)!==JSON.stringify((l=(i=t.data)==null?void 0:i.contest)==null?void 0:l.title)&&(this.setState({timeTravelIsChanging:!1,timeTravelCurrentValue:this.maxAvailableMinutes,timeTravelValue:null,inTimeMachine:!1}),(c=(o=this.props).onTimeTravel)==null||c.call(o,null))}componentWillUnmount(){this.liveInterval&&window.clearInterval(this.liveInterval)}render(){const{data:t,enableTimeTravel:a=!1,live:n=!1,td:i=0}=this.props,l=this.state.inTimeMachine,o=u.getProgressMetrics(t,this.state.localTime,i,this.state.timeTravelCurrentValue,l);return h("div",{className:"srk-progress-bar-container",children:[h("div",{className:"srk-progress-bar",children:[h("div",{className:"srk-progress-bar-body",children:[r("div",{className:"srk-progress-bar-segment srk-progress-bar-normal",style:{width:`${o.frozenBreakpoint*100}%`},children:r("div",{className:"srk-progress-bar-fill",style:{width:`${o.normalInnerPercent}%`}})}),r("div",{className:"srk-progress-bar-segment srk-progress-bar-frozen",style:{width:`${(1-o.frozenBreakpoint)*100}%`},children:r("div",{className:"srk-progress-bar-fill",style:{width:`${o.frozenInnerPercent}%`}})})]}),a&&o.supportRegen&&this.state.isMounted&&h("div",{className:"srk-progress-slider-layer",children:[this.state.timeTravelIsChanging&&r("div",{className:"srk-progress-slider-tooltip",style:{left:`${this.durationMinutes?this.state.timeTravelCurrentValue/this.durationMinutes*100:0}%`},children:d.secToTimeStr(this.state.timeTravelCurrentValue*60)}),r("input",{"aria-label":"Time Travel",className:"srk-progress-slider",max:this.durationMinutes,min:0,onBlur:()=>{this.state.timeTravelIsChanging&&this.commitTimeTravel()},onChange:this.handleSliderChange,onKeyDown:this.handleSliderKeyDown,onKeyUp:this.handleSliderKeyUp,onMouseDown:this.beginTimeTravel,onMouseUp:this.commitTimeTravel,onTouchEnd:this.commitTimeTravel,onTouchStart:this.beginTimeTravel,step:1,title:d.secToTimeStr(this.state.timeTravelCurrentValue*60),type:"range",value:this.state.timeTravelCurrentValue})]})]}),h("div",{className:"srk-progress-secondary-area",children:[h("div",{className:"srk-progress-secondary-area-left",style:n||l?{}:{display:"none"},children:["Elapsed: ",d.secToTimeStr(Math.round(o.elapsed/1e3))]}),r("div",{className:"srk-progress-secondary-area-center",children:this.state.inTimeMachine?r("div",{className:"srk-progress-time-machine-status",children:r("div",{className:"srk-progress-time-machine-text",children:"Time Travel Mode"})}):n&&!this.isEnded?r("div",{className:"srk-progress-live-text",children:"Live"}):r("div",{style:{visibility:"hidden"},children:"SRK"})}),h("div",{className:"srk-progress-secondary-area-right",style:n||l?{}:{display:"none"},children:["Remaining: ",d.secToTimeStr(Math.round(o.remaining/1e3))]})]})]})}}function K(e){if(!e.marker)return null;const{marker:s,theme:t}=e,a=u.getMarkerPresentation(s,t);return r("span",{className:M.default(a.className,e.className),style:{...a.style,...e.style},children:d.resolveText(s.label)})}let ne=0;const le=typeof window=="undefined"?k.default.useEffect:k.default.useLayoutEffect;function V({open:e,title:s,children:t,width:a,rootClassName:n,wrapClassName:i,style:l,destroyOnClose:o=!0,closeOnEsc:c=!0,closeOnMaskClick:T=!0,onClose:m}){const f=k.default.useRef(`srk-modal-title-${++ne}`),g=k.default.useRef(null),N=k.default.useRef(null),v=k.default.useRef(null),y=k.default.useRef(null),[w,C]=k.default.useState(e||!o),[p,A]=k.default.useState(e?"pre-open":"closing"),[_,R]=k.default.useState({x:0,y:0});k.default.useEffect(()=>{u.ensureModalInteractionTracker()},[]),k.default.useEffect(()=>()=>{N.current!==null&&window.clearTimeout(N.current),v.current!==null&&window.clearTimeout(v.current),u.unregisterModalFocusScope(y.current),y.current=null},[]),k.default.useEffect(()=>{if(N.current!==null&&(window.clearTimeout(N.current),N.current=null),v.current!==null&&(window.clearTimeout(v.current),v.current=null),e){C(!0),R({x:0,y:0}),A("pre-open");return}A("closing"),o&&w&&typeof window!="undefined"&&(N.current=window.setTimeout(()=>{C(!1)},u.MODAL_ANIMATION_DURATION_MS))},[o,w,e]),k.default.useEffect(()=>{if(!e||!w||p!=="pre-open")return;const x=u.resolveModalTransformOrigin(g.current);return R(x.origin),v.current=window.setTimeout(()=>{A("opening"),v.current=null},0),()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)}},[p,w,e]);const S=e||o&&w;k.default.useEffect(()=>{if(!!S)return u.lockModalBodyScroll(),()=>{u.unlockModalBodyScroll()}},[S]);const F=k.default.useCallback(x=>{c&&(m==null||m(x,"escape"))},[c,m]);if(le(()=>{if(e&&w){y.current=u.registerModalFocusScope(g.current,{onEscape:c?F:void 0});return}!e&&y.current!==null&&(u.unregisterModalFocusScope(y.current),y.current=null)},[c,F,w,e]),!w&&o)return null;const q={...l,width:a?`${a}px`:l==null?void 0:l.width,["--srk-modal-origin-x"]:`${_.x}px`,["--srk-modal-origin-y"]:`${_.y}px`,["--srk-modal-max-width"]:a?`${a}px`:typeof(l==null?void 0:l.width)=="string"?l.width:void 0},$=h("div",{className:M.default("srk-modal-root",u.SRK_ANIMATED_MODAL_ROOT_CLASS,"srk-react-modal-root",n),"data-srk-modal-state":p,children:[r("div",{className:"srk-modal-mask"}),r("div",{className:M.default("srk-modal-wrap",i),tabIndex:-1,onMouseDown:x=>{T&&x.target===x.currentTarget&&(m==null||m(x,"mask"))},children:r("div",{"aria-labelledby":s?f.current:void 0,"aria-modal":"true",className:"srk-modal","data-srk-modal-panel":"true",ref:g,role:"dialog",style:q,tabIndex:-1,children:h("div",{className:"srk-modal-content",children:[r("button",{"aria-label":"Close",className:"srk-modal-close",type:"button",onClick:x=>m==null?void 0:m(x,"close-button"),children:r("span",{className:"srk-modal-close-x"})}),s!==void 0&&r("div",{className:"srk-modal-header",children:r("div",{className:"srk-modal-title",id:f.current,children:s})}),r("div",{className:"srk-modal-body",children:t})]})})})]});return typeof document=="undefined"?$:Q.default.createPortal($,document.body)}function ie({user:e,userMarkers:s,theme:t,formatSrkAssetUrl:a}){const n=!!e.teamMembers&&e.teamMembers.length>0;return h("div",{className:"srk-user-modal-info",children:[r("h3",{className:"srk-user-modal-info-user-name",children:d.resolveText(e.name)}),!!e.organization&&r("p",{className:"srk-user-modal-info-user-second-name",children:d.resolveText(e.organization)}),h("div",{className:"srk-user-modal-info-labels",children:[r("span",{className:"srk-user-modal-info-labels-label srk-user-modal-info-labels-label-preset-general",children:e.official===!1?"\uFF0A \u975E\u6B63\u5F0F\u53C2\u52A0\u8005":"\u6B63\u5F0F\u53C2\u52A0\u8005"}),s.map((i,l)=>r(K,{marker:i,theme:t,className:"srk-user-modal-info-labels-label"},l))]}),n&&r("div",{className:"srk-user-modal-info-team-members",children:e.teamMembers.map((i,l)=>h("span",{children:[l>0&&r("span",{className:"srk-user-modal-info-team-members-slash",children:" / "}),r("span",{children:d.resolveText(i.name)})]},d.resolveText(i.name)))}),e.photo&&r("div",{className:"srk-user-modal-info-photo",children:r("img",{src:a(e.photo,"user.photo"),alt:"User portrait",className:"srk-user-modal-info-photo-img"})})]})}function oe({open:e,user:s,markers:t=[],theme:a=d.EnumTheme.light,title:n="User Info",width:i=420,formatSrkAssetUrl:l,onClose:o,rootClassName:c="srk-general-modal-root",wrapClassName:T="srk-user-modal",style:m}){const[f,g]=k.default.useState(s||null);return k.default.useEffect(()=>{s&&g(s)},[s]),f?r(V,{open:e,onClose:o,rootClassName:c,style:m,title:n,width:i,wrapClassName:T,children:r(ie,{user:f,userMarkers:d.resolveUserMarkers(f,t),theme:a,formatSrkAssetUrl:(N,v)=>u.resolveSrkAssetUrl(N,v,l)})}):null}function ce({result:e}){const s=u.getSolutionResultMeta(e);return r("span",{className:M.default("srk-solution-result-text",s.className),children:s.label})}function de({solutions:e}){return h("table",{className:"srk-common-table srk-solutions-table",children:[r("thead",{children:h("tr",{children:[r("th",{className:"srk--text-left",children:"Result"}),r("th",{className:"srk--text-right",children:"Time"})]})}),r("tbody",{children:e.map((s,t)=>h("tr",{children:[r("td",{children:r(ce,{result:s.result})}),r("td",{className:"srk--text-right",children:u.formatSolutionTimestamp(s)})]},`${s.result}_${s.time[0]}_${t}`))})]})}function ue({open:e,user:s,problem:t,problemIndex:a,solutions:n,title:i,width:l=320,onClose:o,rootClassName:c="srk-general-modal-root",wrapClassName:T="srk-solutions-modal",style:m}){const[f,g]=k.default.useState(s?{user:s,problem:t,problemIndex:a,solutions:n}:null);return k.default.useEffect(()=>{s&&g({user:s,problem:t,problemIndex:a,solutions:n})},[t,a,n,s]),f?r(V,{open:e,onClose:o,rootClassName:c,style:m,title:i||u.getSolutionModalTitle(f.problemIndex,f.user),width:l,wrapClassName:T,children:r(de,{solutions:f.solutions})}):null}Object.defineProperty(exports,"convertToStaticRanklist",{enumerable:!0,get:function(){return d.convertToStaticRanklist}});Object.defineProperty(exports,"caniuse",{enumerable:!0,get:function(){return u.caniuse}});Object.defineProperty(exports,"srkSupportedVersions",{enumerable:!0,get:function(){return u.srkSupportedVersions}});exports.DefaultSolutionModal=ue;exports.DefaultUserModal=oe;exports.MarkerLabel=K;exports.Modal=V;exports.ProgressBar=I;exports.Ranklist=z;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './main';
|