@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,51 @@
|
|
|
1
|
+
import 'sticky-kit/dist/sticky-kit';
|
|
2
|
+
|
|
3
|
+
import $ from 'jquery';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import responsiveCutoff from 'vj/breakpoints.json';
|
|
6
|
+
import DOMAttachedObject from 'vj/components/DOMAttachedObject';
|
|
7
|
+
import { isBelow } from 'vj/utils/mediaQuery';
|
|
8
|
+
|
|
9
|
+
const navHeight = isBelow(responsiveCutoff.mobile)
|
|
10
|
+
? 0
|
|
11
|
+
: $('.nav').height();
|
|
12
|
+
|
|
13
|
+
export default class StyledTable extends DOMAttachedObject {
|
|
14
|
+
static DOMAttachKey = 'vjStyledTableInstance';
|
|
15
|
+
|
|
16
|
+
static DOMAttachSelector = '.data-table';
|
|
17
|
+
|
|
18
|
+
constructor($dom) {
|
|
19
|
+
if ($dom.closest('.section__body').length === 0) {
|
|
20
|
+
super(null);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
super($dom);
|
|
25
|
+
|
|
26
|
+
this.$container = $('<div>').addClass('section__table-container');
|
|
27
|
+
this.$container.insertBefore(this.$dom);
|
|
28
|
+
|
|
29
|
+
this.$header = $('<table>');
|
|
30
|
+
this.$header.attr('class', `${this.$dom.attr('class')} section__table-header`);
|
|
31
|
+
|
|
32
|
+
this.$container
|
|
33
|
+
.append(this.$header)
|
|
34
|
+
.append(this.$dom);
|
|
35
|
+
|
|
36
|
+
this.$header.empty();
|
|
37
|
+
this.$dom.children('colgroup').clone().appendTo(this.$header);
|
|
38
|
+
this.$dom.children('thead').appendTo(this.$header);
|
|
39
|
+
|
|
40
|
+
const stickyOptions = {
|
|
41
|
+
parent: this.$container,
|
|
42
|
+
offset_top: navHeight,
|
|
43
|
+
};
|
|
44
|
+
_.defer(() => this.$header.stick_in_parent(stickyOptions));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
detach() {
|
|
48
|
+
super.detach();
|
|
49
|
+
this.$header.trigger('sticky_kit:detach');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.data-table
|
|
2
|
+
width: 100%
|
|
3
|
+
table-layout: fixed
|
|
4
|
+
white-space: nowrap
|
|
5
|
+
font-size: rem($font-size-small)
|
|
6
|
+
font-weight: normal
|
|
7
|
+
|
|
8
|
+
th
|
|
9
|
+
font-size: rem($font-size-secondary)
|
|
10
|
+
|
|
11
|
+
tr
|
|
12
|
+
border-top: 1px solid $table-border-color
|
|
13
|
+
border-bottom: 1px solid $table-border-color
|
|
14
|
+
|
|
15
|
+
&:nth-child(even)
|
|
16
|
+
background: $table-alternate-bg-color
|
|
17
|
+
|
|
18
|
+
&.highlight
|
|
19
|
+
background: lighten($highlight-color, 85%)
|
|
20
|
+
|
|
21
|
+
&.is--full-row tr
|
|
22
|
+
cursor: pointer
|
|
23
|
+
|
|
24
|
+
&:hover
|
|
25
|
+
background: lighten($primary-color, 85%)
|
|
26
|
+
|
|
27
|
+
thead > tr
|
|
28
|
+
color: #888
|
|
29
|
+
border-top: 0
|
|
30
|
+
border-bottom: 1px solid $table-border-color
|
|
31
|
+
|
|
32
|
+
td, th
|
|
33
|
+
white-space: nowrap
|
|
34
|
+
overflow: hidden
|
|
35
|
+
text-overflow: ellipsis
|
|
36
|
+
line-height: rem($table-lh)
|
|
37
|
+
|
|
38
|
+
td
|
|
39
|
+
padding: rem(5px $table-padding-h)
|
|
40
|
+
|
|
41
|
+
th
|
|
42
|
+
padding: rem(13px $table-padding-h)
|
|
43
|
+
|
|
44
|
+
.empty-row
|
|
45
|
+
color: #AAA
|
|
46
|
+
font-size: rem($font-size-small)
|
|
47
|
+
|
|
48
|
+
.section__table-container
|
|
49
|
+
overflow: hidden
|
|
50
|
+
overflow-x: auto
|
|
51
|
+
|
|
52
|
+
.section__table-header
|
|
53
|
+
background: $table-header-bg-color
|
|
54
|
+
box-shadow: $table-header-shadow
|
|
55
|
+
position: relative
|
|
56
|
+
z-index: 100
|
|
57
|
+
transition: box-shadow .2s linear
|
|
58
|
+
|
|
59
|
+
thead > tr
|
|
60
|
+
border-bottom: 0
|
|
61
|
+
|
|
62
|
+
&.is_stuck
|
|
63
|
+
box-shadow: $table-header-shadow-floating
|
|
64
|
+
|
|
65
|
+
.section__table-container,
|
|
66
|
+
.section__body
|
|
67
|
+
& > .data-table
|
|
68
|
+
td, th
|
|
69
|
+
&:first-child
|
|
70
|
+
padding-left: rem($section-gap-h)
|
|
71
|
+
|
|
72
|
+
&:last-child
|
|
73
|
+
padding-right: rem($section-gap-h)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
import * as timeago from 'timeago.js';
|
|
3
|
+
import { AutoloadPage } from 'vj/misc/Page';
|
|
4
|
+
import { i18n } from 'vj/utils';
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const locales = require.context('timeago.js/lib/lang', false, /\.js$/);
|
|
8
|
+
let locale;
|
|
9
|
+
try {
|
|
10
|
+
locale = locales(`./${i18n('timeago_locale')}.js`).default;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
locale = locales('./en_US.js').default;
|
|
13
|
+
}
|
|
14
|
+
timeago.register(i18n('timeago_locale'), locale);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error(`Cannot register timeago locale: ${i18n('timeago_locale')}`);
|
|
17
|
+
}
|
|
18
|
+
function runRelativeTime($container) {
|
|
19
|
+
$container.find('span.time.relative[data-timestamp]').get().forEach((element) => {
|
|
20
|
+
const $element = $(element);
|
|
21
|
+
if ($element.attr('data-has-timeago') !== undefined) return;
|
|
22
|
+
$element.attr('data-tooltip', $element.text());
|
|
23
|
+
$element.attr('datetime', ($element.attr('data-timestamp') || 0) * 1000);
|
|
24
|
+
$element.attr('data-has-timeago', '1');
|
|
25
|
+
timeago.render(element, i18n('timeago_locale'));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function cancelRelativeTime($container) {
|
|
30
|
+
$container.find('span.time.relative[data-timestamp]').get().forEach((element) => {
|
|
31
|
+
const $element = $(element);
|
|
32
|
+
if ($element.attr('data-has-timeago') === undefined) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
$element.removeAttr('data-has-timeago');
|
|
36
|
+
timeago.cancel(element);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const relativeTimePage = new AutoloadPage('relativeTimePage', () => {
|
|
41
|
+
if (!UserContext.showTimeAgo) return;
|
|
42
|
+
runRelativeTime($('body'));
|
|
43
|
+
$(document).on('vjContentNew', (e) => runRelativeTime($(e.target)));
|
|
44
|
+
$(document).on('vjContentRemove', (e) => cancelRelativeTime($(e.target)));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export default relativeTimePage;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Drop from 'tether-drop';
|
|
3
|
+
import DOMAttachedObject from 'vj/components/DOMAttachedObject';
|
|
4
|
+
|
|
5
|
+
export default class Tooltip extends DOMAttachedObject {
|
|
6
|
+
static DOMAttachKey = 'vjTooltipInstance';
|
|
7
|
+
|
|
8
|
+
constructor($dom, options = {}) {
|
|
9
|
+
super($dom, true);
|
|
10
|
+
this.dropRemoved = false;
|
|
11
|
+
this.drop = new Drop({
|
|
12
|
+
target: $dom[0],
|
|
13
|
+
classes: 'tooltip',
|
|
14
|
+
position: options.position || 'top center',
|
|
15
|
+
openOn: 'hover',
|
|
16
|
+
constrainToWindow: true,
|
|
17
|
+
constrainToScrollParent: false,
|
|
18
|
+
content: $dom.attr('data-tooltip'),
|
|
19
|
+
});
|
|
20
|
+
this.isOpen = false;
|
|
21
|
+
this.drop.on('open', this.onOpen, this);
|
|
22
|
+
this.drop.on('close', this.onClose, this);
|
|
23
|
+
this.delayDetach = _.debounce(this.detach.bind(this), 200);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onOpen() {
|
|
27
|
+
this.delayDetach.cancel();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onClose() {
|
|
31
|
+
this.delayDetach();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
detach() {
|
|
35
|
+
if (this.detached) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
super.detach();
|
|
39
|
+
this.drop.destroy();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
close() {
|
|
43
|
+
this.drop.close();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
open() {
|
|
47
|
+
this.drop.open();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
import { AutoloadPage } from 'vj/misc/Page';
|
|
3
|
+
import Tooltip from './Tooltip';
|
|
4
|
+
|
|
5
|
+
function getClosestTooltipElement(element) {
|
|
6
|
+
const MAX_DEPTH = 3;
|
|
7
|
+
for (let i = 0, e = element; i < MAX_DEPTH && e !== null && e !== document; e = e.parentNode, i++) {
|
|
8
|
+
if (e.getAttribute('data-tooltip')) {
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const tooltipPage = new AutoloadPage('tooltipPage', () => {
|
|
16
|
+
$(document).on('mouseover', (e) => {
|
|
17
|
+
const element = getClosestTooltipElement(e.target);
|
|
18
|
+
if (!element) return;
|
|
19
|
+
const $element = $(element);
|
|
20
|
+
const options = {};
|
|
21
|
+
if ($element.attr('data-tooltip-pos')) {
|
|
22
|
+
options.position = $element.attr('data-tooltip-pos');
|
|
23
|
+
}
|
|
24
|
+
const tooltip = Tooltip.getOrConstruct($element, options);
|
|
25
|
+
tooltip.open();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default tooltipPage;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
.tooltip
|
|
2
|
+
|
|
3
|
+
&.drop-element
|
|
4
|
+
pointer-events: none
|
|
5
|
+
|
|
6
|
+
.drop-content
|
|
7
|
+
transition: transform .1s ease-in-out
|
|
8
|
+
background: #333
|
|
9
|
+
color: #fff
|
|
10
|
+
font-size: rem($font-size-small)
|
|
11
|
+
padding: .7em 0.9em
|
|
12
|
+
max-width: rem(250px)
|
|
13
|
+
box-shadow: 1px 1px 4px rgba(#000, 0.3)
|
|
14
|
+
line-height: 1
|
|
15
|
+
position: relative
|
|
16
|
+
|
|
17
|
+
&:before
|
|
18
|
+
content: ''
|
|
19
|
+
display: block
|
|
20
|
+
position: absolute
|
|
21
|
+
width: 0
|
|
22
|
+
height: 0
|
|
23
|
+
border: rem(6px) solid transparent
|
|
24
|
+
pointer-events: none
|
|
25
|
+
|
|
26
|
+
&.drop-after-open
|
|
27
|
+
transition-delay: .4s
|
|
28
|
+
|
|
29
|
+
.drop-content
|
|
30
|
+
transition-delay: .4s
|
|
31
|
+
|
|
32
|
+
// Transitions
|
|
33
|
+
&.drop-element-attached-bottom.drop-element-attached-center .drop-content
|
|
34
|
+
transform: scale(0.9) translate(0, 5px) translateZ(0)
|
|
35
|
+
&.drop-element-attached-bottom.drop-element-attached-left .drop-content
|
|
36
|
+
transform: scale(0.9) translate(5px, 5px) translateZ(0)
|
|
37
|
+
&.drop-element-attached-bottom.drop-element-attached-right .drop-content
|
|
38
|
+
transform: scale(0.9) translate(-5px, 5px) translateZ(0)
|
|
39
|
+
&.drop-element-attached-top.drop-element-attached-center .drop-content
|
|
40
|
+
transform: scale(0.9) translate(0, -5px) translateZ(0)
|
|
41
|
+
&.drop-element-attached-top.drop-element-attached-left .drop-content
|
|
42
|
+
transform: scale(0.9) translate(5px, -5px) translateZ(0)
|
|
43
|
+
&.drop-element-attached-top.drop-element-attached-right .drop-content
|
|
44
|
+
transform: scale(0.9) translate(-5px, -5px) translateZ(0)
|
|
45
|
+
&.drop-after-open .drop-content
|
|
46
|
+
transform: scale(1) translateZ(0) !important
|
|
47
|
+
|
|
48
|
+
// Triangle Borders
|
|
49
|
+
&.drop-element-attached-bottom .drop-content
|
|
50
|
+
bottom: rem(10px)
|
|
51
|
+
&:before
|
|
52
|
+
border-top-color: #333
|
|
53
|
+
&.drop-element-attached-top .drop-content
|
|
54
|
+
top: rem(10px)
|
|
55
|
+
&:before
|
|
56
|
+
border-bottom-color: #333
|
|
57
|
+
|
|
58
|
+
// Triangle Positions
|
|
59
|
+
&.drop-element-attached-bottom .drop-content:before
|
|
60
|
+
bottom: rem(-12px)
|
|
61
|
+
&.drop-element-attached-top .drop-content:before
|
|
62
|
+
top: rem(-12px)
|
|
63
|
+
&.drop-element-attached-center .drop-content:before
|
|
64
|
+
margin-left: rem(-6px)
|
|
65
|
+
left: 50%
|
|
66
|
+
&.drop-element-attached-left .drop-content:before
|
|
67
|
+
left: 0
|
|
68
|
+
&.drop-element-attached-right .drop-content:before
|
|
69
|
+
right: 0
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.training-status--icon
|
|
2
|
+
display: inline-block
|
|
3
|
+
width: 1.15em
|
|
4
|
+
for key, value in $training-status-icon
|
|
5
|
+
&.{key}:before
|
|
6
|
+
content: value
|
|
7
|
+
color: $training-status-color[key]
|
|
8
|
+
|
|
9
|
+
.training-status--text
|
|
10
|
+
for key, value in $training-status-color
|
|
11
|
+
&.{key}
|
|
12
|
+
color: value
|
|
13
|
+
|
|
14
|
+
.training-section-status--icon
|
|
15
|
+
display: inline-block
|
|
16
|
+
width: 1.15em
|
|
17
|
+
for key, value in $training-section-status-icon
|
|
18
|
+
&.{key}:before
|
|
19
|
+
content: value
|
|
20
|
+
color: $training-status-color[key]
|
|
21
|
+
|
|
22
|
+
.training-section-status--text
|
|
23
|
+
for key, value in $training-section-status-color
|
|
24
|
+
&.{key}
|
|
25
|
+
color: value
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { MantineProvider, Progress } from '@mantine/core';
|
|
2
|
+
import $ from 'jquery';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Dialog } from 'vj/components/dialog/index';
|
|
5
|
+
import Notification from 'vj/components/notification';
|
|
6
|
+
import {
|
|
7
|
+
delay, i18n, pjax, request, tpl,
|
|
8
|
+
} from 'vj/utils';
|
|
9
|
+
|
|
10
|
+
function onBeforeUnload(e) {
|
|
11
|
+
e.returnValue = '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface UploadOptions {
|
|
15
|
+
type?: string;
|
|
16
|
+
pjax?: boolean;
|
|
17
|
+
sidebar?: boolean;
|
|
18
|
+
singleFileUploadCallback?: (file: File) => any;
|
|
19
|
+
filenameCallback?: (file: File) => string;
|
|
20
|
+
}
|
|
21
|
+
export default async function uploadFiles(endpoint = '', files: File[] | FileList = [], options: UploadOptions = {}) {
|
|
22
|
+
let fileLabel = '';
|
|
23
|
+
let uploadLabel = '';
|
|
24
|
+
let fileProgress = 0;
|
|
25
|
+
let uploadProgress = 0;
|
|
26
|
+
let render = () => { };
|
|
27
|
+
|
|
28
|
+
function ProgressDialog() {
|
|
29
|
+
const [, setRender] = React.useState(0);
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
render = () => setRender((r) => r + 1);
|
|
32
|
+
}, []);
|
|
33
|
+
return <MantineProvider>
|
|
34
|
+
<div
|
|
35
|
+
style={{
|
|
36
|
+
textAlign: 'center', marginBottom: '5px', color: 'gray', fontSize: 'small',
|
|
37
|
+
}}
|
|
38
|
+
>{uploadLabel}</div>
|
|
39
|
+
<Progress value={uploadProgress} />
|
|
40
|
+
<div
|
|
41
|
+
style={{
|
|
42
|
+
textAlign: 'center', margin: '5px 0', color: 'gray', fontSize: 'small',
|
|
43
|
+
}}
|
|
44
|
+
>{fileLabel}</div>
|
|
45
|
+
<Progress value={fileProgress} />
|
|
46
|
+
</MantineProvider>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const dialog = new Dialog({
|
|
50
|
+
$body: $(tpl(<ProgressDialog />, true)),
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
Notification.info(i18n('Uploading files...'));
|
|
54
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
55
|
+
dialog.open();
|
|
56
|
+
for (const i in files) {
|
|
57
|
+
if (Number.isNaN(+i)) continue;
|
|
58
|
+
const file = files[i];
|
|
59
|
+
const data = new FormData();
|
|
60
|
+
data.append('filename', options.filenameCallback?.(file) || file.name);
|
|
61
|
+
data.append('file', file);
|
|
62
|
+
if (options.type) data.append('type', options.type);
|
|
63
|
+
data.append('operation', 'upload_file');
|
|
64
|
+
await request.postFile(endpoint, data, {
|
|
65
|
+
xhr() { // eslint-disable-line
|
|
66
|
+
const xhr = new XMLHttpRequest();
|
|
67
|
+
xhr.upload.addEventListener('loadstart', () => {
|
|
68
|
+
uploadLabel = `[${+i + 1}/${files.length}] ${file.name} `;
|
|
69
|
+
uploadProgress = Math.round((+i + 1) / files.length * 100);
|
|
70
|
+
fileLabel = i18n('Uploading... ({0}%)', 0);
|
|
71
|
+
fileProgress = 0;
|
|
72
|
+
render();
|
|
73
|
+
});
|
|
74
|
+
xhr.upload.addEventListener('progress', (e) => {
|
|
75
|
+
if (e.lengthComputable) {
|
|
76
|
+
const percentComplete = Math.round((e.loaded / e.total) * 100);
|
|
77
|
+
if (percentComplete === 100) fileLabel = i18n('Processing...');
|
|
78
|
+
else fileLabel = i18n('Uploading... ({0}%)', percentComplete);
|
|
79
|
+
fileProgress = percentComplete;
|
|
80
|
+
render();
|
|
81
|
+
}
|
|
82
|
+
}, false);
|
|
83
|
+
return xhr;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
await options.singleFileUploadCallback?.(file);
|
|
87
|
+
}
|
|
88
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
89
|
+
Notification.success(i18n('File uploaded successfully.'));
|
|
90
|
+
if (options.pjax) {
|
|
91
|
+
let params = '';
|
|
92
|
+
if (options.type) params += `?d=${encodeURIComponent(options.type)}`;
|
|
93
|
+
if (options.sidebar) params += `${params ? '&' : '?'}sidebar=true`;
|
|
94
|
+
await pjax.request({ push: false, url: `${endpoint}${params || ''}` });
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.error(e);
|
|
98
|
+
Notification.error(i18n('File upload failed: {0}', e.toString()));
|
|
99
|
+
} finally {
|
|
100
|
+
await delay(500);
|
|
101
|
+
dialog.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
import Notification from 'vj/components/notification';
|
|
3
|
+
import Rotator from 'vj/components/rotator';
|
|
4
|
+
import { AutoloadPage } from 'vj/misc/Page';
|
|
5
|
+
import { request } from 'vj/utils';
|
|
6
|
+
|
|
7
|
+
function setVoteState($container, value, status) {
|
|
8
|
+
const $num = $container.find('.vote-number');
|
|
9
|
+
Rotator.get($num).setValue(value);
|
|
10
|
+
$container.find('.vote-button').removeClass('active');
|
|
11
|
+
if (status === 1) {
|
|
12
|
+
$container.find('.upvote').addClass('active');
|
|
13
|
+
} else if (status === -1) {
|
|
14
|
+
$container.find('.downvote').addClass('active');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function applyRotator(element) {
|
|
19
|
+
Rotator.getOrConstruct($(element));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const votePage = new AutoloadPage('votePage', () => {
|
|
23
|
+
$('.vote-number.rotator--enabled').get().forEach((element) => applyRotator(element));
|
|
24
|
+
$(document).on('click', '.vote-button', (ev) => {
|
|
25
|
+
const $button = $(ev.currentTarget);
|
|
26
|
+
const $container = $button.closest('.vote');
|
|
27
|
+
const $form = $button.closest('form');
|
|
28
|
+
request
|
|
29
|
+
.post($form.attr('action'), {
|
|
30
|
+
operation: $button.attr('value'),
|
|
31
|
+
psid: $form.find('input[name="psid"]').val(),
|
|
32
|
+
})
|
|
33
|
+
.then((data) => {
|
|
34
|
+
setVoteState($container, data.vote, data.user_vote);
|
|
35
|
+
})
|
|
36
|
+
.catch((e) => {
|
|
37
|
+
Notification.error(`Failed to vote: ${e.message}`);
|
|
38
|
+
});
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export default votePage;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { sleep } from '@hydrooj/utils/lib/common';
|
|
2
|
+
import { dump } from 'js-yaml';
|
|
3
|
+
import PQueue from 'p-queue';
|
|
4
|
+
import streamsaver from 'streamsaver';
|
|
5
|
+
import Notification from 'vj/components/notification';
|
|
6
|
+
import {
|
|
7
|
+
api, createZipStream, i18n, pipeStream, request,
|
|
8
|
+
} from 'vj/utils';
|
|
9
|
+
import { ctx } from '../../context';
|
|
10
|
+
|
|
11
|
+
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
|
|
12
|
+
function onBeforeUnload(e) {
|
|
13
|
+
if (isBeforeUnloadTriggeredByLibrary) {
|
|
14
|
+
isBeforeUnloadTriggeredByLibrary = false;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
e.returnValue = '';
|
|
18
|
+
}
|
|
19
|
+
streamsaver.mitm = `${window.isSecureContext ? '' : 'https://hydro.ac'}/streamsaver/mitm.html`;
|
|
20
|
+
|
|
21
|
+
const waitForWritableStream = window.WritableStream
|
|
22
|
+
? Promise.resolve()
|
|
23
|
+
: import('web-streams-polyfill').then(({ WritableStream }) => {
|
|
24
|
+
window.WritableStream = WritableStream as any;
|
|
25
|
+
streamsaver.WritableStream = window.WritableStream;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export default async function download(filename, targets) {
|
|
29
|
+
await waitForWritableStream;
|
|
30
|
+
const fileStream = streamsaver.createWriteStream(filename);
|
|
31
|
+
const queue = new PQueue({ concurrency: 5 });
|
|
32
|
+
const abortCallbackReceiver: any = {};
|
|
33
|
+
function stopDownload() { abortCallbackReceiver.abort?.(); }
|
|
34
|
+
let i = 0;
|
|
35
|
+
async function downloadFile(target, retry = 5) {
|
|
36
|
+
try {
|
|
37
|
+
let stream;
|
|
38
|
+
if (target.url) {
|
|
39
|
+
const response = await fetch(target.url);
|
|
40
|
+
if (!response.ok) throw response.statusText;
|
|
41
|
+
stream = response.body;
|
|
42
|
+
} else {
|
|
43
|
+
stream = new Blob([target.content]).stream();
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
name: target.filename,
|
|
47
|
+
stream,
|
|
48
|
+
};
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (retry) {
|
|
51
|
+
Notification.warn(i18n('Download Error: {0} {1}, retry in 3 secs...', [target.filename, e.toString()]));
|
|
52
|
+
await sleep(3000);
|
|
53
|
+
return await downloadFile(target, retry - 1);
|
|
54
|
+
}
|
|
55
|
+
window.captureException?.(e);
|
|
56
|
+
stopDownload();
|
|
57
|
+
Notification.error(i18n('Download Error: {0} {1}', [target.filename, e.toString()]));
|
|
58
|
+
}
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
const handles = [];
|
|
62
|
+
for (const target of targets) {
|
|
63
|
+
handles.push(queue.add(() => downloadFile(target)));
|
|
64
|
+
}
|
|
65
|
+
queue.start();
|
|
66
|
+
const zipStream = createZipStream({
|
|
67
|
+
// eslint-disable-next-line consistent-return
|
|
68
|
+
async pull(ctrl) {
|
|
69
|
+
if (!handles[i]) return ctrl.close();
|
|
70
|
+
const { name, stream } = await handles[i];
|
|
71
|
+
i++;
|
|
72
|
+
ctrl.enqueue({
|
|
73
|
+
name,
|
|
74
|
+
stream: () => stream,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
window.addEventListener('unload', stopDownload);
|
|
79
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
80
|
+
await pipeStream(zipStream, fileStream, abortCallbackReceiver);
|
|
81
|
+
window.removeEventListener('unload', stopDownload);
|
|
82
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare module '../../api' {
|
|
86
|
+
interface EventMap {
|
|
87
|
+
'problemset/download': (pids: number[], name: string, targets: { filename: string, url?: string, content?: string }[]) => void;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function downloadProblemSet(pids, name = 'Export') {
|
|
92
|
+
Notification.info(i18n('Downloading...'));
|
|
93
|
+
const targets: { filename: string, url?: string, content?: string }[] = [];
|
|
94
|
+
try {
|
|
95
|
+
await ctx.serial('problemset/download', pids, name, targets);
|
|
96
|
+
for (const pid of pids) {
|
|
97
|
+
const pdoc = await api('problem', { id: +pid }, {
|
|
98
|
+
pid: 1,
|
|
99
|
+
owner: 1,
|
|
100
|
+
title: 1,
|
|
101
|
+
content: 1,
|
|
102
|
+
tag: 1,
|
|
103
|
+
nSubmit: 1,
|
|
104
|
+
nAccept: 1,
|
|
105
|
+
data: {
|
|
106
|
+
name: 1,
|
|
107
|
+
},
|
|
108
|
+
additional_file: {
|
|
109
|
+
name: 1,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
targets.push({
|
|
113
|
+
filename: `${pid}/problem.yaml`,
|
|
114
|
+
content: dump({
|
|
115
|
+
pid: pdoc.pid,
|
|
116
|
+
owner: pdoc.owner,
|
|
117
|
+
title: pdoc.title,
|
|
118
|
+
tag: pdoc.tag,
|
|
119
|
+
nSubmit: pdoc.nSubmit,
|
|
120
|
+
nAccept: pdoc.nAccept,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
const c = JSON.parse(pdoc.content);
|
|
125
|
+
if (c instanceof Array || typeof c === 'string') throw new Error('Invalid content');
|
|
126
|
+
for (const key of Object.keys(c)) {
|
|
127
|
+
targets.push({
|
|
128
|
+
filename: `${pid}/problem_${key}.md`,
|
|
129
|
+
content: typeof c[key] === 'string' ? c[key] : JSON.stringify(c[key]),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
targets.push({
|
|
134
|
+
filename: `${pid}/problem.md`,
|
|
135
|
+
content: pdoc.content,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
let { links } = await request.post(
|
|
139
|
+
`/d/${UiContext.domainId}/p/${pid}/files`,
|
|
140
|
+
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' },
|
|
141
|
+
);
|
|
142
|
+
for (const filename of Object.keys(links)) {
|
|
143
|
+
targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] });
|
|
144
|
+
}
|
|
145
|
+
({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, {
|
|
146
|
+
operation: 'get_links', files: (pdoc.additional_file || []).map((i) => i.name), type: 'additional_file',
|
|
147
|
+
}));
|
|
148
|
+
for (const filename of Object.keys(links)) {
|
|
149
|
+
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await download(`${name}.zip`, targets);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
window.captureException?.(e);
|
|
155
|
+
Notification.error(`${e.message} ${e.params?.[0]}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const JOIN_METHOD_NONE = 0;
|
|
2
|
+
export const JOIN_METHOD_ALL = 1;
|
|
3
|
+
export const JOIN_METHOD_CODE = 2;
|
|
4
|
+
export const JOIN_METHOD_RANGE = {
|
|
5
|
+
[JOIN_METHOD_NONE]: 'No user is allowed to join this domain',
|
|
6
|
+
[JOIN_METHOD_ALL]: 'Any user is allowed to join this domain',
|
|
7
|
+
[JOIN_METHOD_CODE]: 'Any user is allowed to join this domain with an invitation code',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const JOIN_EXPIRATION_KEEP_CURRENT = 0;
|
|
11
|
+
export const JOIN_EXPIRATION_UNLIMITED = -1;
|
|
12
|
+
|
|
13
|
+
export const JOIN_EXPIRATION_RANGE = {
|
|
14
|
+
[JOIN_EXPIRATION_KEEP_CURRENT]: 'Keep current expiration',
|
|
15
|
+
3: 'In 3 hours',
|
|
16
|
+
24: 'In 1 day',
|
|
17
|
+
[24 * 3]: 'In 3 days',
|
|
18
|
+
[24 * 7]: 'In 1 week',
|
|
19
|
+
[24 * 30]: 'In 1 month',
|
|
20
|
+
[JOIN_EXPIRATION_UNLIMITED]: 'Never expire',
|
|
21
|
+
};
|