@shzlx/ui-default 4.58.2
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/README.md +5 -0
- package/api.ts +61 -0
- package/backendlib/builder.ts +182 -0
- package/backendlib/markdown-it-imsize.ts +235 -0
- package/backendlib/markdown-it-katex.ts +139 -0
- package/backendlib/markdown-it-media.ts +163 -0
- package/backendlib/markdown-it-xss.ts +200 -0
- package/backendlib/markdown.js +64 -0
- package/backendlib/misc.ts +54 -0
- package/backendlib/template.ts +279 -0
- package/breakpoints.json +5 -0
- package/components/DOMAttachedObject.ts +128 -0
- package/components/autocomplete/AssignSelectAutoComplete.tsx +22 -0
- package/components/autocomplete/CustomSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/DomainSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/FileSelectAutoComplete.tsx +26 -0
- package/components/autocomplete/LanguageSelectAutoComplete.tsx +24 -0
- package/components/autocomplete/ProblemSelectAutoComplete.tsx +18 -0
- package/components/autocomplete/UserSelectAutoComplete.tsx +23 -0
- package/components/autocomplete/components/AssignSelectAutoComplete.tsx +118 -0
- package/components/autocomplete/components/DomainSelectAutoComplete.tsx +53 -0
- package/components/autocomplete/components/FileSelectAutoComplete.tsx +50 -0
- package/components/autocomplete/components/LanguageSelectAutoComplete.tsx +48 -0
- package/components/autocomplete/components/ProblemSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/components/UserSelectAutoComplete.tsx +54 -0
- package/components/autocomplete/domainselectautocomplete.page.styl +6 -0
- package/components/autocomplete/index.tsx +110 -0
- package/components/autocomplete/problemselectautocomplete.page.styl +6 -0
- package/components/autocomplete/userselectautocomplete.page.styl +6 -0
- package/components/browser-update.page.ts +27 -0
- package/components/calendar/calendar.page.styl +129 -0
- package/components/calendar/index.js +367 -0
- package/components/clipboard.page.ts +23 -0
- package/components/contest/contest.page.styl +119 -0
- package/components/contest/contest.page.ts +23 -0
- package/components/contest/contest_sidebar.page.styl +21 -0
- package/components/contest/problem-contest-bg.png +0 -0
- package/components/contest/problem-contest-bg@2x.png +0 -0
- package/components/customFont.page.tsx +90 -0
- package/components/datepicker/datepicker.page.tsx +94 -0
- package/components/dialog/DomDialog.ts +145 -0
- package/components/dialog/dialog.page.styl +40 -0
- package/components/dialog/index.tsx +285 -0
- package/components/discussion/CommentBox.js +103 -0
- package/components/discussion/collapsible.page.styl +40 -0
- package/components/discussion/collapsible.page.tsx +62 -0
- package/components/discussion/comments.page.styl +142 -0
- package/components/discussion/comments.page.tsx +192 -0
- package/components/discussion/discussion.page.styl +17 -0
- package/components/discussion/history.page.tsx +81 -0
- package/components/discussion/reaction.page.styl +30 -0
- package/components/discussion/reaction.page.tsx +103 -0
- package/components/drop/drop.page.styl +40 -0
- package/components/dropdown/Dropdown.js +50 -0
- package/components/dropdown/dropdown.page.styl +33 -0
- package/components/dropdown/dropdown.page.ts +8 -0
- package/components/editor/cmeditor.page.ts +23 -0
- package/components/editor/cmeditor.styl +10 -0
- package/components/editor/index.tsx +293 -0
- package/components/editor/mdeditor.ts +60 -0
- package/components/editor/textareaHandler.ts +29 -0
- package/components/footer/footer.page.styl +94 -0
- package/components/footer/footer.page.ts +26 -0
- package/components/form/button.page.default.styl +59 -0
- package/components/form/button.page.styl +36 -0
- package/components/form/checkbox.page.styl +89 -0
- package/components/form/form.page.styl +200 -0
- package/components/form/form.page.ts +20 -0
- package/components/form/multiSelectCheckbox.page.js +46 -0
- package/components/form/radiobox.page.styl +62 -0
- package/components/form/select.page.styl +29 -0
- package/components/form/textbox.page.styl +79 -0
- package/components/form/textbox.page.ts +21 -0
- package/components/form/var.inc.styl +14 -0
- package/components/header/header.page.styl +79 -0
- package/components/highlighter/code-example.js +111 -0
- package/components/highlighter/highlighter.page.styl +99 -0
- package/components/highlighter/highlighter.page.ts +72 -0
- package/components/highlighter/meta.js +15 -0
- package/components/highlighter/prismjs.js +122 -0
- package/components/hint.page.styl +9 -0
- package/components/hint.ts +19 -0
- package/components/hitokoto/index.page.js +21 -0
- package/components/hotkey/hotkey.page.js +83 -0
- package/components/katex/katex.page.js +26 -0
- package/components/katex/katex.page.styl +2 -0
- package/components/languageselect.tsx +94 -0
- package/components/loader/loader.page.styl +40 -0
- package/components/mantine.page.tsx +39 -0
- package/components/marker/Marker.js +192 -0
- package/components/marker/MarkerReactive.js +55 -0
- package/components/marker/marker.page.js +8 -0
- package/components/marker/marker.page.styl +57 -0
- package/components/media/media.page.js +46 -0
- package/components/menu/menu-heading.page.js +28 -0
- package/components/menu/menu.page.js +18 -0
- package/components/menu/menu.page.styl +68 -0
- package/components/message/index.page.ts +166 -0
- package/components/message/worker.ts +110 -0
- package/components/messagepad/DialogueListItem.page.styl +28 -0
- package/components/messagepad/DialogueListItemComponent.jsx +39 -0
- package/components/messagepad/Message.page.styl +64 -0
- package/components/messagepad/MessageComponent.jsx +33 -0
- package/components/messagepad/MessagePad.page.styl +99 -0
- package/components/messagepad/MessagePadDialogueContentContainer.jsx +104 -0
- package/components/messagepad/MessagePadDialogueListContainer.jsx +49 -0
- package/components/messagepad/MessagePadInputContainer.jsx +100 -0
- package/components/messagepad/index.jsx +49 -0
- package/components/messagepad/reducers/activeId.ts +36 -0
- package/components/messagepad/reducers/dialogues.js +53 -0
- package/components/messagepad/reducers/index.ts +14 -0
- package/components/messagepad/reducers/inputs.js +43 -0
- package/components/messagepad/reducers/isPosting.ts +49 -0
- package/components/monaco/index.ts +178 -0
- package/components/monaco/languages/markdown.ts +97 -0
- package/components/monaco/languages/typescript.ts +45 -0
- package/components/monaco/languages/yaml.ts +22 -0
- package/components/monaco/loader.ts +96 -0
- package/components/monaco/monaco.styl +30 -0
- package/components/monaco/nls.js +31 -0
- package/components/monaco/schema/problemconfig.ts +123 -0
- package/components/navigation/hamburgers.page.styl +87 -0
- package/components/navigation/nav-logo-small_dark.png +0 -0
- package/components/navigation/navigation.page.js +203 -0
- package/components/navigation/navigation.page.styl +211 -0
- package/components/notification/index.ts +105 -0
- package/components/notification/notification.page.js +14 -0
- package/components/notification/notification.page.styl +84 -0
- package/components/nprogress.page.styl +50 -0
- package/components/omnisearch/index.page.tsx +124 -0
- package/components/omnisearch/omnibar.page.styl +138 -0
- package/components/pager/pager.page.styl +57 -0
- package/components/preview/preview.page.ts +187 -0
- package/components/problem/create.page.js +12 -0
- package/components/problem/list.page.js +9 -0
- package/components/problem/rp.page.styl +4 -0
- package/components/problem/tag.page.styl +84 -0
- package/components/problemconfig/BasicForm.tsx +92 -0
- package/components/problemconfig/ProblemConfigEditor.tsx +170 -0
- package/components/problemconfig/ProblemConfigForm.tsx +140 -0
- package/components/problemconfig/ProblemConfigTree.tsx +163 -0
- package/components/problemconfig/ProblemType.tsx +165 -0
- package/components/problemconfig/index.tsx +91 -0
- package/components/problemconfig/reducer/config.ts +173 -0
- package/components/problemconfig/reducer/index.ts +11 -0
- package/components/problemconfig/reducer/testdata.ts +16 -0
- package/components/problemconfig/tree/AddTestcase.tsx +137 -0
- package/components/problemconfig/tree/SelectionManager.tsx +140 -0
- package/components/problemconfig/tree/SubtaskSettings.tsx +180 -0
- package/components/problemconfig/tree/Testcase.tsx +98 -0
- package/components/profile/backgrounds/1.jpg +0 -0
- package/components/profile/backgrounds/10.jpg +0 -0
- package/components/profile/backgrounds/11.jpg +0 -0
- package/components/profile/backgrounds/12.jpg +0 -0
- package/components/profile/backgrounds/13.jpg +0 -0
- package/components/profile/backgrounds/14.jpg +0 -0
- package/components/profile/backgrounds/15.jpg +0 -0
- package/components/profile/backgrounds/16.jpg +0 -0
- package/components/profile/backgrounds/17.jpg +0 -0
- package/components/profile/backgrounds/18.jpg +0 -0
- package/components/profile/backgrounds/19.jpg +0 -0
- package/components/profile/backgrounds/2.jpg +0 -0
- package/components/profile/backgrounds/20.jpg +0 -0
- package/components/profile/backgrounds/21.jpg +0 -0
- package/components/profile/backgrounds/3.jpg +0 -0
- package/components/profile/backgrounds/4.jpg +0 -0
- package/components/profile/backgrounds/5.jpg +0 -0
- package/components/profile/backgrounds/6.jpg +0 -0
- package/components/profile/backgrounds/7.jpg +0 -0
- package/components/profile/backgrounds/8.jpg +0 -0
- package/components/profile/backgrounds/9.jpg +0 -0
- package/components/profile/backgrounds/gen_thumbnails.sh +7 -0
- package/components/profile/backgrounds/thumbnail/1.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/10.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/11.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/12.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/13.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/14.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/15.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/16.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/17.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/18.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/19.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/2.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/20.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/21.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/3.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/4.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/5.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/6.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/7.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/8.jpg +0 -0
- package/components/profile/backgrounds/thumbnail/9.jpg +0 -0
- package/components/profile/profile.page.styl +23 -0
- package/components/react/DomComponent.tsx +14 -0
- package/components/react/IconComponent.tsx +20 -0
- package/components/record/record.page.styl +26 -0
- package/components/rotator/index.js +75 -0
- package/components/rotator/rotator.page.styl +20 -0
- package/components/scratchpad/DataInput.page.styl +17 -0
- package/components/scratchpad/DataInputComponent.jsx +45 -0
- package/components/scratchpad/Editor.page.styl +13 -0
- package/components/scratchpad/Panel.page.styl +18 -0
- package/components/scratchpad/PanelButton.page.styl +15 -0
- package/components/scratchpad/PanelButtonComponent.jsx +19 -0
- package/components/scratchpad/PanelComponent.jsx +25 -0
- package/components/scratchpad/ScratchpadEditorContainer.tsx +137 -0
- package/components/scratchpad/ScratchpadPretestContainer.jsx +57 -0
- package/components/scratchpad/ScratchpadRecordsContainer.jsx +45 -0
- package/components/scratchpad/ScratchpadRecordsRowContainer.jsx +83 -0
- package/components/scratchpad/ScratchpadSettings.tsx +48 -0
- package/components/scratchpad/ScratchpadToolbarContainer.jsx +190 -0
- package/components/scratchpad/Tab.page.styl +24 -0
- package/components/scratchpad/Toolbar.page.styl +53 -0
- package/components/scratchpad/ToolbarComponent.jsx +85 -0
- package/components/scratchpad/index.tsx +132 -0
- package/components/scratchpad/reducers/editor.ts +24 -0
- package/components/scratchpad/reducers/index.ts +17 -0
- package/components/scratchpad/reducers/pretest.ts +34 -0
- package/components/scratchpad/reducers/records.ts +40 -0
- package/components/scratchpad/reducers/state.ts +10 -0
- package/components/scratchpad/reducers/ui.ts +152 -0
- package/components/scratchpad/scratchpad.page.styl +55 -0
- package/components/scratchpad/var.inc.styl +2 -0
- package/components/selectUser.tsx +16 -0
- package/components/signin/signInDialog.page.js +84 -0
- package/components/signin/signin_dialog.page.styl +57 -0
- package/components/smoothscroll/smoothscroll.page.js +44 -0
- package/components/socket/index.ts +68 -0
- package/components/star/star.page.styl +20 -0
- package/components/star/star.page.ts +58 -0
- package/components/sticky/sticky.page.js +66 -0
- package/components/tab/Tab.js +168 -0
- package/components/tab/tab.page.js +9 -0
- package/components/tab/tab.page.styl +105 -0
- package/components/tab/var.inc.styl +3 -0
- package/components/table/StyledTable.js +51 -0
- package/components/table/styledTable.page.js +8 -0
- package/components/table/table.page.styl +73 -0
- package/components/time/time.page.js +47 -0
- package/components/tooltip/Tooltip.js +49 -0
- package/components/tooltip/tooltip.page.js +29 -0
- package/components/tooltip/tooltip.page.styl +69 -0
- package/components/training/training.page.styl +25 -0
- package/components/upload.tsx +103 -0
- package/components/vote/vote.page.js +43 -0
- package/components/zipDownloader/index.ts +157 -0
- package/constant/domain.js +21 -0
- package/constant/message.js +5 -0
- package/constant/record.js +52 -0
- package/context.ts +11 -0
- package/entry.js +72 -0
- package/hydro.ts +112 -0
- package/index.ts +226 -0
- package/lazyload.ts +69 -0
- package/locales/en.yaml +71 -0
- package/locales/ko.yaml +823 -0
- package/locales/zh.yaml +1137 -0
- package/locales/zh_TW.yaml +1133 -0
- package/misc/Page.ts +49 -0
- package/misc/PageLoader.js +31 -0
- package/misc/float.styl +14 -0
- package/misc/grid.styl +1048 -0
- package/misc/immersive-background.jpg +0 -0
- package/misc/immersive-background@2x.jpg +0 -0
- package/misc/immersive.styl +23 -0
- package/misc/nothing.styl +13 -0
- package/misc/puzzled_twd2.svg +1 -0
- package/misc/section.styl +105 -0
- package/misc/slideout.styl +46 -0
- package/misc/structure.styl +158 -0
- package/misc/textalign.styl +11 -0
- package/misc/typography.styl +485 -0
- package/package.json +148 -0
- package/polyfill.ts +90 -0
- package/postcss.config.js +15 -0
- package/sentry.ts +26 -0
- package/service-worker.ts +265 -0
- package/setting.yaml +98 -0
- package/templates/about.html +14 -0
- package/templates/bsod.html +35 -0
- package/templates/components/comments_discussion.html +165 -0
- package/templates/components/comments_solution.html +171 -0
- package/templates/components/contest.html +12 -0
- package/templates/components/form.html +214 -0
- package/templates/components/home.html +20 -0
- package/templates/components/homework.html +8 -0
- package/templates/components/md_hint.html +39 -0
- package/templates/components/noscript_note.html +15 -0
- package/templates/components/nothing.html +6 -0
- package/templates/components/paginator.html +25 -0
- package/templates/components/problem.html +33 -0
- package/templates/components/record.html +21 -0
- package/templates/components/sidemenu.html +11 -0
- package/templates/components/user.html +49 -0
- package/templates/contest_balloon.html +48 -0
- package/templates/contest_clarification.html +103 -0
- package/templates/contest_detail.html +56 -0
- package/templates/contest_edit.html +259 -0
- package/templates/contest_main.html +146 -0
- package/templates/contest_manage.html +80 -0
- package/templates/contest_print.html +27 -0
- package/templates/contest_problemlist.html +231 -0
- package/templates/contest_scoreboard.html +46 -0
- package/templates/contest_scoreboard_download_html.html +71 -0
- package/templates/contest_user.html +47 -0
- package/templates/discussion_create.html +28 -0
- package/templates/discussion_detail.html +149 -0
- package/templates/discussion_edit.html +30 -0
- package/templates/discussion_main_or_node.html +47 -0
- package/templates/domain_base.html +26 -0
- package/templates/domain_create.html +55 -0
- package/templates/domain_dashboard.html +45 -0
- package/templates/domain_edit.html +6 -0
- package/templates/domain_group.html +51 -0
- package/templates/domain_join.html +47 -0
- package/templates/domain_join_applications.html +67 -0
- package/templates/domain_permission.html +66 -0
- package/templates/domain_role.html +71 -0
- package/templates/domain_user.html +86 -0
- package/templates/domain_user_raw.html +5 -0
- package/templates/error.html +25 -0
- package/templates/home_domain.html +64 -0
- package/templates/home_files.html +16 -0
- package/templates/home_messages.html +9 -0
- package/templates/home_security.html +224 -0
- package/templates/home_settings.html +21 -0
- package/templates/homework_detail.html +82 -0
- package/templates/homework_edit.html +138 -0
- package/templates/homework_files.html +24 -0
- package/templates/homework_main.html +76 -0
- package/templates/layout/basic.html +27 -0
- package/templates/layout/home_base.html +13 -0
- package/templates/layout/html5.html +74 -0
- package/templates/layout/immersive.html +22 -0
- package/templates/layout/mail.html +31 -0
- package/templates/layout/simple.html +4 -0
- package/templates/layout/wiki_base.html +16 -0
- package/templates/main.html +22 -0
- package/templates/manage_base.html +24 -0
- package/templates/manage_config.html +6 -0
- package/templates/manage_dashboard.html +27 -0
- package/templates/manage_script.html +56 -0
- package/templates/manage_setting.html +6 -0
- package/templates/manage_user_import.html +23 -0
- package/templates/manage_user_priv.html +76 -0
- package/templates/partials/category.html +19 -0
- package/templates/partials/contest.html +3 -0
- package/templates/partials/contest_balloon.html +37 -0
- package/templates/partials/contest_sidebar.html +150 -0
- package/templates/partials/contest_sidebar_management.html +56 -0
- package/templates/partials/contest_user.html +19 -0
- package/templates/partials/discussion_edit_form.html +45 -0
- package/templates/partials/discussion_list.html +50 -0
- package/templates/partials/discussion_nodes_widget.html +17 -0
- package/templates/partials/files.html +49 -0
- package/templates/partials/footer.html +108 -0
- package/templates/partials/hamburger.html +7 -0
- package/templates/partials/header_mobile.html +12 -0
- package/templates/partials/homepage/bulletin.html +7 -0
- package/templates/partials/homepage/contest.html +48 -0
- package/templates/partials/homepage/discussion.html +13 -0
- package/templates/partials/homepage/discussion_nodes.html +4 -0
- package/templates/partials/homepage/error.html +5 -0
- package/templates/partials/homepage/hitokoto.html +6 -0
- package/templates/partials/homepage/homework.html +45 -0
- package/templates/partials/homepage/problem_search.html +13 -0
- package/templates/partials/homepage/ranking.html +39 -0
- package/templates/partials/homepage/recent_problems.html +17 -0
- package/templates/partials/homepage/starred_problems.html +15 -0
- package/templates/partials/homepage/suggestion.html +34 -0
- package/templates/partials/homepage/training.html +50 -0
- package/templates/partials/homework.html +3 -0
- package/templates/partials/homework_default_penalty_rules.yaml +6 -0
- package/templates/partials/homework_sidebar.html +93 -0
- package/templates/partials/login_dialog.html +56 -0
- package/templates/partials/manage_user_priv.html +78 -0
- package/templates/partials/nav.html +138 -0
- package/templates/partials/problem-sidebar-information.html +25 -0
- package/templates/partials/problem.html +2 -0
- package/templates/partials/problem_category_dialog.html +43 -0
- package/templates/partials/problem_default.md +26 -0
- package/templates/partials/problem_description.html +33 -0
- package/templates/partials/problem_files.html +63 -0
- package/templates/partials/problem_list.html +68 -0
- package/templates/partials/problem_lucky.html +10 -0
- package/templates/partials/problem_sidebar.html +14 -0
- package/templates/partials/problem_sidebar_contest.html +43 -0
- package/templates/partials/problem_sidebar_homework.html +42 -0
- package/templates/partials/problem_sidebar_normal.html +152 -0
- package/templates/partials/problem_stat.html +3 -0
- package/templates/partials/scoreboard.html +79 -0
- package/templates/partials/setting.html +92 -0
- package/templates/partials/training_default.json +14 -0
- package/templates/partials/training_detail.html +153 -0
- package/templates/partials/user.html +2 -0
- package/templates/partials/user_detail/activity.html +18 -0
- package/templates/partials/user_detail/solution.html +29 -0
- package/templates/problem_config.html +39 -0
- package/templates/problem_detail.html +150 -0
- package/templates/problem_edit.html +111 -0
- package/templates/problem_files.html +91 -0
- package/templates/problem_hack.html +41 -0
- package/templates/problem_import.html +58 -0
- package/templates/problem_main.html +100 -0
- package/templates/problem_solution.html +55 -0
- package/templates/problem_statistics.html +96 -0
- package/templates/problem_submit.html +40 -0
- package/templates/ranking.html +81 -0
- package/templates/record_detail.html +134 -0
- package/templates/record_detail_status.html +93 -0
- package/templates/record_detail_summary.html +19 -0
- package/templates/record_main.html +142 -0
- package/templates/record_main_tr.html +35 -0
- package/templates/status.html +75 -0
- package/templates/training_detail.html +120 -0
- package/templates/training_edit.html +68 -0
- package/templates/training_files.html +64 -0
- package/templates/training_main.html +107 -0
- package/templates/user_changemail_mail.html +6 -0
- package/templates/user_changemail_mail_sent.html +9 -0
- package/templates/user_delete_pending.html +10 -0
- package/templates/user_detail.html +181 -0
- package/templates/user_login.html +46 -0
- package/templates/user_logout.html +13 -0
- package/templates/user_lostpass.html +27 -0
- package/templates/user_lostpass_mail.html +6 -0
- package/templates/user_lostpass_mail_sent.html +9 -0
- package/templates/user_lostpass_with_code.html +29 -0
- package/templates/user_register.html +22 -0
- package/templates/user_register_mail.html +6 -0
- package/templates/user_register_mail_sent.html +9 -0
- package/templates/user_register_with_code.html +35 -0
- package/templates/user_sudo.html +54 -0
- package/templates/user_sudo_redirect.html +18 -0
- package/templates/wiki_help.html +189 -0
- package/theme/bp6-compat.css +48 -0
- package/theme/dark.styl +397 -0
- package/theme/default.js +33 -0
- package/typed.d.ts +20 -0
- package/utils/base.ts +209 -0
- package/utils/base64.js +104 -0
- package/utils/db.ts +32 -0
- package/utils/index.ts +73 -0
- package/utils/loadReactRedux.ts +32 -0
- package/utils/mediaQuery.ts +13 -0
- package/utils/pjax.js +148 -0
- package/utils/slide.ts +57 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Button, Tabs } from '@mantine/core';
|
|
2
|
+
import { Allotment } from 'allotment';
|
|
3
|
+
import { ContextMenuProvider } from 'mantine-contextmenu';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useSelector, useStore } from 'react-redux';
|
|
6
|
+
import { confirm } from 'vj/components/dialog/index';
|
|
7
|
+
import { i18n } from 'vj/utils';
|
|
8
|
+
import ProblemConfigEditor from './ProblemConfigEditor';
|
|
9
|
+
import ProblemConfigForm from './ProblemConfigForm';
|
|
10
|
+
import { ProblemConfigTree } from './ProblemConfigTree';
|
|
11
|
+
import { RootState } from './reducer';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
onSave: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function ProblemConfig(props: Props) {
|
|
18
|
+
const [selected, setSelected] = React.useState('basic');
|
|
19
|
+
const [container, setContainer] = React.useState<HTMLDivElement | null>(null);
|
|
20
|
+
const [tabs, setTabs] = React.useState<HTMLDivElement | null>(null);
|
|
21
|
+
const [editor, setEditor] = React.useState<any>(null);
|
|
22
|
+
const store = useStore<RootState>();
|
|
23
|
+
const valid = useSelector((state: RootState) => state.config.__valid);
|
|
24
|
+
const errors = useSelector((state: RootState) => state.config.__errors, (a, b) => JSON.stringify(a) === JSON.stringify(b));
|
|
25
|
+
|
|
26
|
+
const handleSave = React.useCallback(async () => {
|
|
27
|
+
if (valid) props.onSave();
|
|
28
|
+
else if (await confirm(i18n('Errors detected in the config. Confirm save?'))) props.onSave();
|
|
29
|
+
}, [valid, props.onSave]);
|
|
30
|
+
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
if (!container) return () => { };
|
|
33
|
+
container.style.height ||= '600px';
|
|
34
|
+
const callback = () => {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
const target = Math.max(container.clientHeight, tabs?.clientHeight || 0);
|
|
37
|
+
container.style.height = `${target}px`;
|
|
38
|
+
if (editor) editor.layout();
|
|
39
|
+
}, 50);
|
|
40
|
+
};
|
|
41
|
+
const dispose = store.subscribe(callback);
|
|
42
|
+
window.addEventListener('resize', callback);
|
|
43
|
+
return () => {
|
|
44
|
+
dispose();
|
|
45
|
+
window.removeEventListener('resize', callback);
|
|
46
|
+
};
|
|
47
|
+
}, [container, tabs, store]);
|
|
48
|
+
|
|
49
|
+
return <ContextMenuProvider>
|
|
50
|
+
<div ref={setContainer}>
|
|
51
|
+
<Allotment
|
|
52
|
+
defaultSizes={[2, 3]}
|
|
53
|
+
className="problem-config-allotment">
|
|
54
|
+
<Allotment.Pane>
|
|
55
|
+
<div style={{ height: '100%', overflow: 'auto' }}>
|
|
56
|
+
<ProblemConfigEditor ref={setEditor} />
|
|
57
|
+
</div>
|
|
58
|
+
</Allotment.Pane>
|
|
59
|
+
<Allotment.Pane>
|
|
60
|
+
<Tabs
|
|
61
|
+
ref={setTabs}
|
|
62
|
+
value={valid ? selected : 'errors'}
|
|
63
|
+
keepMounted={false}
|
|
64
|
+
style={{ paddingLeft: 20 }}
|
|
65
|
+
onChange={(t) => (t !== 'errors' && t && setSelected(t.toString()))}
|
|
66
|
+
>
|
|
67
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
|
|
68
|
+
<Tabs.List>
|
|
69
|
+
<Tabs.Tab value="basic" disabled={!valid}>{i18n('Basic')}</Tabs.Tab>
|
|
70
|
+
<Tabs.Tab value="subtasks" disabled={!valid}>{i18n('Subtasks')}</Tabs.Tab>
|
|
71
|
+
<Tabs.Tab value="errors" disabled={valid}>{errors.length ? `Errors(${errors.length})` : 'No Errors'}</Tabs.Tab>
|
|
72
|
+
</Tabs.List>
|
|
73
|
+
<Button onClick={handleSave}>
|
|
74
|
+
{i18n('Save')}
|
|
75
|
+
</Button>
|
|
76
|
+
</div>
|
|
77
|
+
<Tabs.Panel value="basic">
|
|
78
|
+
<ProblemConfigForm />
|
|
79
|
+
</Tabs.Panel>
|
|
80
|
+
<Tabs.Panel value="subtasks">
|
|
81
|
+
<ProblemConfigTree />
|
|
82
|
+
</Tabs.Panel>
|
|
83
|
+
<Tabs.Panel value="errors">
|
|
84
|
+
<div>{errors.map((i) => (<pre key={i}>{i}</pre>))}</div>
|
|
85
|
+
</Tabs.Panel>
|
|
86
|
+
</Tabs>
|
|
87
|
+
</Allotment.Pane>
|
|
88
|
+
</Allotment>
|
|
89
|
+
</div>
|
|
90
|
+
</ContextMenuProvider>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { parseMemoryMB, parseTimeMS, sortFiles } from '@hydrooj/utils/lib/common';
|
|
2
|
+
import type { ProblemConfigFile, TestCaseConfig } from 'hydrooj/src/interface';
|
|
3
|
+
import Ajv from 'ajv';
|
|
4
|
+
import yaml from 'js-yaml';
|
|
5
|
+
import { cloneDeep } from 'lodash';
|
|
6
|
+
import schema from '../../monaco/schema/problemconfig';
|
|
7
|
+
|
|
8
|
+
type State = ProblemConfigFile & {
|
|
9
|
+
__loaded: boolean;
|
|
10
|
+
__valid: boolean;
|
|
11
|
+
__errors: string[];
|
|
12
|
+
__cases: TestCaseConfig[];
|
|
13
|
+
};
|
|
14
|
+
const ajv = new Ajv();
|
|
15
|
+
const validate = ajv.compile(schema);
|
|
16
|
+
|
|
17
|
+
export default function reducer(state = {
|
|
18
|
+
type: 'default', __loaded: false, __valid: false, __errors: [], __cases: [], subtasks: [],
|
|
19
|
+
} as State, action: any = {}): State {
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case 'CONFIG_LOAD_FULFILLED': {
|
|
22
|
+
const c = { ...state, __loaded: true };
|
|
23
|
+
try {
|
|
24
|
+
let data = yaml.load(action.payload.config) as any;
|
|
25
|
+
if (typeof data !== 'object') data = { subtasks: [] };
|
|
26
|
+
else data.subtasks ||= [];
|
|
27
|
+
if (!validate(data)) {
|
|
28
|
+
Object.assign(c, data);
|
|
29
|
+
c.__errors = validate.errors.map((i) => `${i.instancePath}: ${i.message}`);
|
|
30
|
+
return c;
|
|
31
|
+
}
|
|
32
|
+
const subtasks = (data as any).subtasks;
|
|
33
|
+
for (const subtask of subtasks) {
|
|
34
|
+
if (typeof subtask.id !== 'number') {
|
|
35
|
+
for (let i = 1; ; i++) {
|
|
36
|
+
if (!subtasks.find((s) => s.id === i)) {
|
|
37
|
+
subtask.id = i;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Object.assign(c, data);
|
|
44
|
+
c.__valid = true;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
c.__errors.push(e.message);
|
|
47
|
+
}
|
|
48
|
+
return c;
|
|
49
|
+
}
|
|
50
|
+
case 'CONFIG_FORM_UPDATE': {
|
|
51
|
+
const next = { ...state, [action.key]: action.value };
|
|
52
|
+
if (action.key === 'score' && action.value) next.score = +next.score;
|
|
53
|
+
if (action.key === 'checker_type' && action.value === 'other') next.checker_type = 'syzoj';
|
|
54
|
+
if (!action.value || (action.value instanceof Array && !action.value.join(''))) delete next[action.key];
|
|
55
|
+
return next;
|
|
56
|
+
}
|
|
57
|
+
case 'CONFIG_CODE_UPDATE': {
|
|
58
|
+
try {
|
|
59
|
+
const data = yaml.load(action.payload);
|
|
60
|
+
if (!validate(data)) {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
__valid: false,
|
|
64
|
+
__errors: validate.errors.map((i) => `${i.instancePath}: ${i.message}`),
|
|
65
|
+
__loaded: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...state, ...data as object, __valid: true, __errors: [], __loaded: true,
|
|
70
|
+
};
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return {
|
|
73
|
+
...state, __valid: false, __errors: [e.message], __loaded: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
case 'CONFIG_AUTOCASES_UPDATE': {
|
|
78
|
+
const next = { ...state };
|
|
79
|
+
const { subtasks } = action;
|
|
80
|
+
for (const subtask of subtasks) {
|
|
81
|
+
if (subtask.time === parseTimeMS(state.time || '1s')) delete subtask.time;
|
|
82
|
+
if (subtask.memory === parseMemoryMB(state.memory || '256m')) delete subtask.memory;
|
|
83
|
+
if (subtask.time) subtask.time += 'ms';
|
|
84
|
+
if (subtask.memory) subtask.memory += 'MB';
|
|
85
|
+
if (typeof subtask.id !== 'number') {
|
|
86
|
+
for (let i = 1; ; i++) {
|
|
87
|
+
if (!subtasks.find((s) => s.id === s)) {
|
|
88
|
+
subtask.id = i;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (subtasks.length === 0) next.subtasks = [];
|
|
95
|
+
else {
|
|
96
|
+
next.subtasks = subtasks.map((subtask) => (
|
|
97
|
+
{ ...subtask, ...{ cases: subtask.cases.map((i) => ({ input: i.input, output: i.output })) } }));
|
|
98
|
+
}
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
case 'problemconfig/updateFileIO': {
|
|
102
|
+
const n = { ...state, filename: action.filename };
|
|
103
|
+
if (!n.filename) delete n.filename;
|
|
104
|
+
return n;
|
|
105
|
+
}
|
|
106
|
+
case 'problemconfig/updateGlobalConfig': {
|
|
107
|
+
const n = { ...state, time: action.time, memory: action.memory };
|
|
108
|
+
if (!n.time) delete n.time;
|
|
109
|
+
if (!n.memory) delete n.memory;
|
|
110
|
+
return n;
|
|
111
|
+
}
|
|
112
|
+
case 'problemconfig/addSubtask': {
|
|
113
|
+
const subtasks = cloneDeep(state.subtasks);
|
|
114
|
+
subtasks.push({
|
|
115
|
+
cases: [],
|
|
116
|
+
score: 0,
|
|
117
|
+
id: Object.keys(subtasks).map((i) => subtasks[i].id).reduce((a, b) => Math.max(+a, +b), 0) + 1,
|
|
118
|
+
});
|
|
119
|
+
return { ...state, subtasks };
|
|
120
|
+
}
|
|
121
|
+
case 'problemconfig/updateSubtaskConfig': {
|
|
122
|
+
if (!state.subtasks.find((i) => i.id === action.id)) return state;
|
|
123
|
+
const subtask = { ...state.subtasks.find((i) => i.id === action.id) };
|
|
124
|
+
const subtasks = [...state.subtasks];
|
|
125
|
+
subtasks.splice(state.subtasks.findIndex((i) => i.id === action.id), 1, subtask);
|
|
126
|
+
if (action.payload.time) subtask.time = action.payload.time;
|
|
127
|
+
if (action.payload.memory) subtask.memory = action.payload.memory;
|
|
128
|
+
if (action.payload.score) subtask.score = +action.payload.score || 0;
|
|
129
|
+
if (action.payload.if) subtask.if = action.payload.if;
|
|
130
|
+
if (action.payload.type) subtask.type = action.payload.type;
|
|
131
|
+
if (!subtask.time) delete subtask.time;
|
|
132
|
+
if (!subtask.memory) delete subtask.memory;
|
|
133
|
+
return { ...state, subtasks };
|
|
134
|
+
}
|
|
135
|
+
case 'problemconfig/addTestcases': {
|
|
136
|
+
return { ...state, __cases: sortFiles([...state.__cases, ...action.cases], 'input') };
|
|
137
|
+
}
|
|
138
|
+
case 'problemconfig/moveTestcases': {
|
|
139
|
+
const testcases = action.payload.cases;
|
|
140
|
+
const subtasks = cloneDeep(state.subtasks);
|
|
141
|
+
const targetCases = action.payload.target === -1
|
|
142
|
+
? state.__cases
|
|
143
|
+
: (subtasks.find((s) => s.id === action.payload.target)?.cases || []);
|
|
144
|
+
const toAdd = testcases.filter((tc) => !targetCases.find((j) => j.input === tc.input && j.output === tc.output));
|
|
145
|
+
const __cases = action.payload.source === -1
|
|
146
|
+
? state.__cases.filter((i) => !testcases.find((j) => i.input === j.input && i.output === j.output))
|
|
147
|
+
: action.payload.target === -1
|
|
148
|
+
? sortFiles([...state.__cases, ...toAdd], 'input')
|
|
149
|
+
: state.__cases;
|
|
150
|
+
for (const key in subtasks) {
|
|
151
|
+
const subtask = subtasks[key];
|
|
152
|
+
if (subtask.id === action.payload.source) {
|
|
153
|
+
subtask.cases = subtask.cases.filter((i) => !testcases.find((j) => i.input === j.input && i.output === j.output));
|
|
154
|
+
} else if (subtask.id === action.payload.target) {
|
|
155
|
+
subtask.cases = sortFiles([...subtask.cases, ...toAdd], 'input');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { ...state, subtasks, __cases };
|
|
159
|
+
}
|
|
160
|
+
case 'problemconfig/delTestcases': {
|
|
161
|
+
const testcases = action.cases;
|
|
162
|
+
return { ...state, __cases: state.__cases.filter((i) => !testcases.find((j) => i.input === j.input && i.output === j.output)) };
|
|
163
|
+
}
|
|
164
|
+
case 'problemconfig/deleteSubtask': {
|
|
165
|
+
const currentCases = state.subtasks.find((i) => i.id === action.id)?.cases || [];
|
|
166
|
+
const subtasks = state.subtasks.filter((i) => i.id !== action.id);
|
|
167
|
+
const add = currentCases.filter((i) => !subtasks.find((j) => j.cases.find((k) => k.input === i.input && k.output === i.output)));
|
|
168
|
+
return { ...state, subtasks, __cases: sortFiles([...state.__cases, ...add], 'input') };
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
return state;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import config from './config';
|
|
3
|
+
import testdata from './testdata';
|
|
4
|
+
|
|
5
|
+
const reducer = combineReducers({
|
|
6
|
+
config,
|
|
7
|
+
testdata,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default reducer;
|
|
11
|
+
export type RootState = ReturnType<typeof reducer>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function reducer(state = [], action: any = {}) {
|
|
2
|
+
switch (action.type) {
|
|
3
|
+
case 'CONFIG_LOAD_FULFILLED': {
|
|
4
|
+
return state.concat(action.payload.testdata);
|
|
5
|
+
}
|
|
6
|
+
case 'CONFIG_DELETE_TESTDATA': {
|
|
7
|
+
const next = state.filter((i) => i.name !== action.value[0]);
|
|
8
|
+
return next;
|
|
9
|
+
}
|
|
10
|
+
case 'CONFIG_ADD_TESTDATA': {
|
|
11
|
+
return state.concat([action.value]);
|
|
12
|
+
}
|
|
13
|
+
default:
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { readSubtasksFromFiles } from '@hydrooj/common';
|
|
2
|
+
import { Button, Modal, Text } from '@mantine/core';
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
|
+
import { useSelector, useStore } from 'react-redux';
|
|
5
|
+
import { i18n } from 'vj/utils';
|
|
6
|
+
import FileSelectAutoComplete from '../../autocomplete/components/FileSelectAutoComplete';
|
|
7
|
+
import { RootState } from '../reducer';
|
|
8
|
+
|
|
9
|
+
export function AddTestcase() {
|
|
10
|
+
const [open, setOpen] = React.useState(false);
|
|
11
|
+
const [input, setInput] = React.useState('');
|
|
12
|
+
const [output, setOutput] = React.useState('');
|
|
13
|
+
const [valid, setValid] = React.useState(false);
|
|
14
|
+
const [autoInput, setAutoInput] = React.useState(true);
|
|
15
|
+
const [autoOutput, setAutoOutput] = React.useState(true);
|
|
16
|
+
const testdata = useSelector((state: RootState) => state.testdata);
|
|
17
|
+
const store = useStore<RootState>();
|
|
18
|
+
const refInput = useRef(null);
|
|
19
|
+
const refOutput = useRef(null);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const inputValid = testdata.find((i) => i.name === input);
|
|
23
|
+
if (input) setAutoInput(false);
|
|
24
|
+
else setAutoInput(true);
|
|
25
|
+
setValid(inputValid);
|
|
26
|
+
if (inputValid && autoOutput) {
|
|
27
|
+
const filename = input.substring(0, input.lastIndexOf('.'));
|
|
28
|
+
let outputFile = '';
|
|
29
|
+
if (testdata.find((i) => i.name === `${filename}.out`)) outputFile = `${filename}.out`;
|
|
30
|
+
else if (testdata.find((i) => i.name === `${filename}.ans`)) outputFile = `${filename}.ans`;
|
|
31
|
+
if (outputFile) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
refOutput.current!.setSelectedItems([outputFile]);
|
|
34
|
+
setOutput(outputFile);
|
|
35
|
+
setAutoOutput(true);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, [input]);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const outputValid = testdata.find((i) => i.name === output);
|
|
42
|
+
if (output) setAutoOutput(false);
|
|
43
|
+
else setAutoOutput(true);
|
|
44
|
+
setValid(outputValid);
|
|
45
|
+
if (outputValid && autoInput) {
|
|
46
|
+
const filename = output.substring(0, output.lastIndexOf('.'));
|
|
47
|
+
if (testdata.find((i) => i.name === `${filename}.in`)) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
refInput.current!.setSelectedItems([`${filename}.in`]);
|
|
50
|
+
setInput(`${filename}.in`);
|
|
51
|
+
setAutoInput(true);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [output]);
|
|
55
|
+
|
|
56
|
+
function onConfirm() {
|
|
57
|
+
store.dispatch({
|
|
58
|
+
type: 'problemconfig/addTestcases',
|
|
59
|
+
cases: [{ input, output }],
|
|
60
|
+
});
|
|
61
|
+
setOpen(false);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function auto() {
|
|
65
|
+
const state = store.getState();
|
|
66
|
+
const subtasks = readSubtasksFromFiles(state.testdata.map((i) => i.name), {});
|
|
67
|
+
const current = state.config.subtasks.flatMap((i) => i.cases).concat(state.config.__cases);
|
|
68
|
+
const pending = [];
|
|
69
|
+
for (const c of subtasks.flatMap((s) => s.cases)) {
|
|
70
|
+
if (!current.find((i) => i.input === c.input && i.output === c.output)) {
|
|
71
|
+
pending.push({
|
|
72
|
+
input: c.input,
|
|
73
|
+
output: c.output,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
store.dispatch({
|
|
78
|
+
type: 'problemconfig/addTestcases',
|
|
79
|
+
cases: pending,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (<>
|
|
84
|
+
<div
|
|
85
|
+
style={{ cursor: 'pointer', padding: '6px 0' }}
|
|
86
|
+
onClick={auto}
|
|
87
|
+
>
|
|
88
|
+
<Text><i className="icon icon-wrench" /> {i18n('Auto detect')}</Text>
|
|
89
|
+
</div>
|
|
90
|
+
<div
|
|
91
|
+
style={{ cursor: 'pointer', padding: '6px 0' }}
|
|
92
|
+
onClick={() => {
|
|
93
|
+
setInput('');
|
|
94
|
+
setOutput('');
|
|
95
|
+
setAutoInput(true);
|
|
96
|
+
setAutoOutput(true);
|
|
97
|
+
setOpen(true);
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<Text><i className="icon icon-add" /> {i18n('Add testcase')}</Text>
|
|
101
|
+
</div>
|
|
102
|
+
<Modal
|
|
103
|
+
opened={open}
|
|
104
|
+
onClose={() => setOpen(false)}
|
|
105
|
+
title={i18n('Add testcase')}
|
|
106
|
+
styles={{ body: { overflow: 'visible' }, content: { overflow: 'visible' } }}
|
|
107
|
+
>
|
|
108
|
+
<div className="row" style={{ overflow: 'visible' }}>
|
|
109
|
+
<div className="columns medium-6" style={{ overflow: 'visible' }}>
|
|
110
|
+
<FileSelectAutoComplete
|
|
111
|
+
ref={refInput}
|
|
112
|
+
data={testdata}
|
|
113
|
+
label="Input"
|
|
114
|
+
width="100%"
|
|
115
|
+
onChange={(e) => setInput(e)}
|
|
116
|
+
placeholder={i18n('Input')}
|
|
117
|
+
value={input || ''}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
<div className="columns medium-6" style={{ overflow: 'visible' }}>
|
|
121
|
+
<FileSelectAutoComplete
|
|
122
|
+
ref={refOutput}
|
|
123
|
+
data={testdata}
|
|
124
|
+
label="Output"
|
|
125
|
+
width="100%"
|
|
126
|
+
onChange={(e) => setOutput(e)}
|
|
127
|
+
placeholder={i18n('Output')}
|
|
128
|
+
value={output || ''}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: 12 }}>
|
|
133
|
+
<Button onClick={onConfirm} disabled={!valid}> {i18n('Save')}</Button>
|
|
134
|
+
</div>
|
|
135
|
+
</Modal>
|
|
136
|
+
</>);
|
|
137
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSelector } from 'react-redux';
|
|
3
|
+
import { RootState } from '../reducer';
|
|
4
|
+
import { TestcaseGroup } from './Testcase';
|
|
5
|
+
|
|
6
|
+
interface SelectionManagerProps {
|
|
7
|
+
subtaskId: number;
|
|
8
|
+
subtaskIds: number[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function collide(rect1: any, rect2: any): boolean {
|
|
12
|
+
if ('getBoundingClientRect' in rect1) rect1 = rect1.getBoundingClientRect();
|
|
13
|
+
if ('getBoundingClientRect' in rect2) rect2 = rect2.getBoundingClientRect();
|
|
14
|
+
const maxX = Math.max(rect1.x + rect1.width, rect2.x + rect2.width);
|
|
15
|
+
const maxY = Math.max(rect1.y + rect1.height, rect2.y + rect2.height);
|
|
16
|
+
const minX = Math.min(rect1.x, rect2.x);
|
|
17
|
+
const minY = Math.min(rect1.y, rect2.y);
|
|
18
|
+
return maxX - minX <= rect1.width + rect2.width && maxY - minY <= rect1.height + rect2.height;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function SelectionManager(props: SelectionManagerProps) {
|
|
22
|
+
const { subtaskIds, subtaskId } = props;
|
|
23
|
+
const cases = useSelector((state: RootState) => (subtaskId === -1
|
|
24
|
+
? state.config.__cases || []
|
|
25
|
+
: state.config.subtasks.find((i) => i.id === subtaskId).cases || []));
|
|
26
|
+
// Don't need to trigger a re-render for this property change
|
|
27
|
+
const pos = React.useMemo(() => ({
|
|
28
|
+
x: 0, y: 0, endX: 0, endY: 0,
|
|
29
|
+
}), []);
|
|
30
|
+
const [start, setStart] = React.useState(0);
|
|
31
|
+
const [end, setEnd] = React.useState(0);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
setStart(0);
|
|
34
|
+
setEnd(0);
|
|
35
|
+
}, [JSON.stringify(cases)]);
|
|
36
|
+
|
|
37
|
+
const selecting = React.useRef(false);
|
|
38
|
+
|
|
39
|
+
const handleMouseDown = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
|
40
|
+
pos.x = event.pageX;
|
|
41
|
+
pos.y = event.pageY;
|
|
42
|
+
// Check if clicking on a selected testcase (let drag handle it)
|
|
43
|
+
if ((event.target as HTMLElement).closest?.('[data-selected="true"]')) return;
|
|
44
|
+
selecting.current = true;
|
|
45
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
46
|
+
document.body.addEventListener('mousemove', handleMouseMove);
|
|
47
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
48
|
+
document.body.addEventListener('mouseup', handleMouseUp);
|
|
49
|
+
$('body').css('cursor', 'crosshair')
|
|
50
|
+
.append('<div id="divSelectArea" style="position:absolute;background-color:#e073d4;"></div>');
|
|
51
|
+
$('#divSelectArea').css({
|
|
52
|
+
top: event.pageY,
|
|
53
|
+
left: event.pageX,
|
|
54
|
+
zIndex: 9999999,
|
|
55
|
+
}).fadeTo(12, 0.2);
|
|
56
|
+
}, [JSON.stringify(cases)]);
|
|
57
|
+
const handleMouseMove = React.useCallback((event) => {
|
|
58
|
+
if (!selecting.current) return;
|
|
59
|
+
pos.endX = event.pageX;
|
|
60
|
+
pos.endY = event.pageY;
|
|
61
|
+
$('#divSelectArea').css({
|
|
62
|
+
top: Math.min(event.pageY, pos.y),
|
|
63
|
+
left: Math.min(event.pageX, pos.x),
|
|
64
|
+
height: Math.abs(event.pageY - pos.y),
|
|
65
|
+
width: Math.abs(event.pageX - pos.x),
|
|
66
|
+
});
|
|
67
|
+
}, [JSON.stringify(cases)]);
|
|
68
|
+
const cleanupSelection = React.useCallback(() => {
|
|
69
|
+
selecting.current = false;
|
|
70
|
+
document.body.removeEventListener('mousemove', handleMouseMove);
|
|
71
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
72
|
+
document.body.removeEventListener('mouseup', handleMouseUp);
|
|
73
|
+
$('#divSelectArea').remove();
|
|
74
|
+
$('body').css('cursor', 'default');
|
|
75
|
+
pos.x = pos.y = pos.endX = pos.endY = 0;
|
|
76
|
+
}, [JSON.stringify(cases)]);
|
|
77
|
+
const handleMouseUp = React.useCallback(() => {
|
|
78
|
+
if (!selecting.current) {
|
|
79
|
+
cleanupSelection();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const caseEntries = Array.from($(`[data-subtaskid="${subtaskId}"]`));
|
|
83
|
+
const selected = [];
|
|
84
|
+
for (let i = 0; i < caseEntries.length; i += 1) {
|
|
85
|
+
if (collide(caseEntries[i], $('#divSelectArea')[0])) {
|
|
86
|
+
selected.push(cases.indexOf(cases.find((c) => c.input === caseEntries[i].dataset.index)));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const sorted = selected.sort((a, b) => a - b);
|
|
90
|
+
cleanupSelection();
|
|
91
|
+
if (!sorted.length) return;
|
|
92
|
+
setStart(sorted[0]);
|
|
93
|
+
setEnd(sorted[selected.length - 1] + 1);
|
|
94
|
+
}, [JSON.stringify(cases)]);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
{end > start && cases.slice(0, start).map((c, id) => (
|
|
99
|
+
<TestcaseGroup
|
|
100
|
+
subtaskId={subtaskId}
|
|
101
|
+
cases={[c]}
|
|
102
|
+
key={`${c.input}@${id}`}
|
|
103
|
+
selected={false}
|
|
104
|
+
subtaskIds={subtaskIds}
|
|
105
|
+
index={id}
|
|
106
|
+
onMouseDown={handleMouseDown}
|
|
107
|
+
onClick={() => {
|
|
108
|
+
setStart(id);
|
|
109
|
+
setEnd(id + 1);
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
))}
|
|
113
|
+
{start <= end && (
|
|
114
|
+
<TestcaseGroup
|
|
115
|
+
cases={cases.slice(start, end)}
|
|
116
|
+
subtaskId={subtaskId}
|
|
117
|
+
subtaskIds={subtaskIds}
|
|
118
|
+
onMouseDown={handleMouseDown}
|
|
119
|
+
selected={true}
|
|
120
|
+
index={start}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
{end < cases.length && cases.slice(end).map((c, id) => (
|
|
124
|
+
<TestcaseGroup
|
|
125
|
+
subtaskId={subtaskId}
|
|
126
|
+
cases={[c]}
|
|
127
|
+
key={`${c.input}@${id}`}
|
|
128
|
+
subtaskIds={subtaskIds}
|
|
129
|
+
selected={false}
|
|
130
|
+
onMouseDown={handleMouseDown}
|
|
131
|
+
index={id + end}
|
|
132
|
+
onClick={() => {
|
|
133
|
+
setStart(id + end);
|
|
134
|
+
setEnd(id + end + 1);
|
|
135
|
+
}}
|
|
136
|
+
/>
|
|
137
|
+
))}
|
|
138
|
+
</>
|
|
139
|
+
);
|
|
140
|
+
}
|