@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,279 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import * as status from '@hydrooj/common/status';
|
|
3
|
+
import { findFileSync, getAlphabeticId } from '@hydrooj/utils/lib/utils';
|
|
4
|
+
import {
|
|
5
|
+
avatar, Context, difficultyAlgorithm, fs, PERM, PRIV, Service, STATUS, yaml,
|
|
6
|
+
} from 'hydrooj';
|
|
7
|
+
import { cac } from 'cac';
|
|
8
|
+
import { convert } from 'html-to-text';
|
|
9
|
+
import jsesc from 'jsesc';
|
|
10
|
+
import nunjucks from 'nunjucks';
|
|
11
|
+
import markdown from './markdown';
|
|
12
|
+
import { ensureTag, xss } from './markdown-it-xss';
|
|
13
|
+
import * as misc from './misc';
|
|
14
|
+
|
|
15
|
+
const argv = cac().parse();
|
|
16
|
+
|
|
17
|
+
let { template } = argv.options;
|
|
18
|
+
if (!template || typeof template !== 'string') template = findFileSync('@hydrooj/ui-default/templates');
|
|
19
|
+
else template = findFileSync(template);
|
|
20
|
+
|
|
21
|
+
const replacer = (s) => (k, v) => {
|
|
22
|
+
if (k.startsWith('_') && k !== '_id') return undefined;
|
|
23
|
+
if (typeof v === 'bigint') return `BigInt::${v.toString()}`;
|
|
24
|
+
if (v && typeof v === 'object' && 'serialize' in v && typeof v.serialize === 'function') return v.serialize(s);
|
|
25
|
+
return v;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
async function getFiles(folder: string, base = ''): Promise<string[]> {
|
|
29
|
+
const files: string[] = [];
|
|
30
|
+
const f = await fs.readdir(folder);
|
|
31
|
+
for (const i of f) {
|
|
32
|
+
if ((await fs.stat(path.join(folder, i))).isDirectory()) {
|
|
33
|
+
files.push(...await getFiles(path.join(folder, i), path.join(base, i)));
|
|
34
|
+
} else files.push(path.join(base, i));
|
|
35
|
+
}
|
|
36
|
+
return files.map((item) => item.replace(/\\/g, '/'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function locateFile(basePath: string, filenames: string[]) {
|
|
40
|
+
for (const i of filenames) {
|
|
41
|
+
const p = path.resolve(basePath, i);
|
|
42
|
+
if (fs.existsSync(p)) return p;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
nunjucks.runtime.memberLookup = function memberLookup(obj, val) {
|
|
49
|
+
if ((obj || {})._original) obj = obj._original;
|
|
50
|
+
if (obj === undefined || obj === null) return undefined;
|
|
51
|
+
if (typeof obj[val] === 'function') {
|
|
52
|
+
const fn = function (...args) {
|
|
53
|
+
return obj[val].call(obj, ...args); // eslint-disable-line no-useless-call
|
|
54
|
+
};
|
|
55
|
+
fn._original = obj[val];
|
|
56
|
+
return fn;
|
|
57
|
+
}
|
|
58
|
+
return obj[val];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
class Nunjucks extends nunjucks.Environment {
|
|
62
|
+
constructor(Loader: any) {
|
|
63
|
+
super(new Loader(), { autoescape: true, trimBlocks: true });
|
|
64
|
+
this.addFilter('await', async (promise, callback) => {
|
|
65
|
+
try {
|
|
66
|
+
const result = await promise;
|
|
67
|
+
callback(null, result);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
callback(error);
|
|
70
|
+
}
|
|
71
|
+
}, true);
|
|
72
|
+
this.addFilter('json', (self, s) => (self ? JSON.stringify(self, replacer(s)) : ''));
|
|
73
|
+
this.addFilter('parseYaml', (self) => yaml.load(self));
|
|
74
|
+
this.addFilter('dumpYaml', (self) => yaml.dump(self));
|
|
75
|
+
this.addFilter('assign', (self, data) => Object.assign(self, data));
|
|
76
|
+
this.addFilter('markdown', (self) => ensureTag(markdown.render(self)));
|
|
77
|
+
this.addFilter('markdownInline', (self) => ensureTag(markdown.renderInline(self)));
|
|
78
|
+
this.addFilter('ansi', (self) => misc.ansiToHtml(self));
|
|
79
|
+
this.addFilter('base64_encode', (s) => Buffer.from(s).toString('base64'));
|
|
80
|
+
this.addFilter('base64_decode', (s) => Buffer.from(s, 'base64').toString());
|
|
81
|
+
this.addFilter('jsesc', (self) => jsesc(self, { isScriptContext: true }));
|
|
82
|
+
this.addFilter('bitand', (self, val) => self & val);
|
|
83
|
+
this.addFilter('toString', (self, s) => (typeof self === 'string' ? self : JSON.stringify(self, replacer(s))));
|
|
84
|
+
this.addFilter('content', (content, language, html) => {
|
|
85
|
+
let s: any = '';
|
|
86
|
+
try {
|
|
87
|
+
s = JSON.parse(content);
|
|
88
|
+
} catch {
|
|
89
|
+
s = content;
|
|
90
|
+
}
|
|
91
|
+
if (typeof s === 'object') {
|
|
92
|
+
const langs = Object.keys(s);
|
|
93
|
+
const f = langs.filter((i) => i.startsWith(language));
|
|
94
|
+
if (s[language]) s = s[language];
|
|
95
|
+
else if (f.length) s = s[f[0]];
|
|
96
|
+
else s = s[langs[0]];
|
|
97
|
+
}
|
|
98
|
+
return ensureTag(html ? xss.process(s) : markdown.render(s));
|
|
99
|
+
});
|
|
100
|
+
this.addFilter('problemPreview', (html) => {
|
|
101
|
+
const res = convert(html, {
|
|
102
|
+
selectors: [
|
|
103
|
+
{ selector: 'math', format: 'skip' },
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
return res.split('\n').map((i) => i.trim()).join('\n').replace(/\n+/g, '\n');
|
|
107
|
+
});
|
|
108
|
+
this.addFilter('contentLang', (content) => {
|
|
109
|
+
let s: any = '';
|
|
110
|
+
try {
|
|
111
|
+
s = JSON.parse(content);
|
|
112
|
+
} catch {
|
|
113
|
+
s = content;
|
|
114
|
+
}
|
|
115
|
+
if (typeof s === 'object') return Object.keys(s);
|
|
116
|
+
return [];
|
|
117
|
+
});
|
|
118
|
+
this.addFilter('log', (self) => {
|
|
119
|
+
console.log(self);
|
|
120
|
+
return self;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// eslint-disable-next-line no-eval
|
|
124
|
+
this.addGlobal('eval', eval);
|
|
125
|
+
this.addGlobal('Date', Date);
|
|
126
|
+
this.addGlobal('Object', Object);
|
|
127
|
+
this.addGlobal('String', String);
|
|
128
|
+
this.addGlobal('Array', Array);
|
|
129
|
+
this.addGlobal('Math', Math);
|
|
130
|
+
this.addGlobal('process', process);
|
|
131
|
+
this.addGlobal('global', global);
|
|
132
|
+
this.addGlobal('typeof', (o) => typeof o);
|
|
133
|
+
this.addGlobal('instanceof', (a, b) => a instanceof b);
|
|
134
|
+
this.addGlobal('paginate', misc.paginate);
|
|
135
|
+
this.addGlobal('size', misc.size);
|
|
136
|
+
this.addGlobal('utils', { status, getAlphabeticId, buildQueryString: misc.buildQueryString });
|
|
137
|
+
this.addGlobal('avatarUrl', avatar);
|
|
138
|
+
this.addGlobal('formatSeconds', misc.formatSeconds);
|
|
139
|
+
this.addGlobal('model', global.Hydro.model);
|
|
140
|
+
this.addGlobal('lib', { difficulty: difficultyAlgorithm });
|
|
141
|
+
this.addGlobal('ui', global.Hydro.ui);
|
|
142
|
+
this.addGlobal('isIE', (str) => {
|
|
143
|
+
if (!str) return false;
|
|
144
|
+
if (['MSIE', 'rv:11.0'].some((i) => str.includes(i))) return true;
|
|
145
|
+
if (str.includes('Chrome/') && +str.split('Chrome/')[1].split('.')[0] < 60) return true;
|
|
146
|
+
return false;
|
|
147
|
+
});
|
|
148
|
+
this.addGlobal('set', (obj, key, val) => {
|
|
149
|
+
if (val !== undefined) obj[key] = val;
|
|
150
|
+
else Object.assign(obj, key);
|
|
151
|
+
return '';
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const platformIconMap = { 'mac os': 'mac' };
|
|
155
|
+
const supportedPlatformIcons = ['android', 'chromeos', 'ios', 'linux', 'mac', 'mobile', 'windows'];
|
|
156
|
+
this.addGlobal('platformIcon', (platform) => {
|
|
157
|
+
const key = platformIconMap[platform?.toLowerCase()] || platform?.toLowerCase();
|
|
158
|
+
if (supportedPlatformIcons.includes(key)) return key;
|
|
159
|
+
return 'unknown';
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class TemplateService extends Service {
|
|
165
|
+
static inject = ['server'];
|
|
166
|
+
|
|
167
|
+
registry: Record<string, string> = {};
|
|
168
|
+
|
|
169
|
+
constructor(public ctx: Context) {
|
|
170
|
+
super(ctx, 'template');
|
|
171
|
+
const that = this;
|
|
172
|
+
ctx.on('handler/create', async (h) => {
|
|
173
|
+
h.user = h.context.HydroContext.user as any;
|
|
174
|
+
h.domain = h.context.HydroContext.domain as any;
|
|
175
|
+
h.translate = h.translate.bind(h);
|
|
176
|
+
h.url = h.url.bind(h);
|
|
177
|
+
h.ctx = h.ctx.extend({ domain: h.domain });
|
|
178
|
+
h.renderHTML = ((orig) => function (name: string, args: Record<string, any>) {
|
|
179
|
+
const s = name.split('.');
|
|
180
|
+
let templateName = `${s[0]}.${args.domainId}.${s[1]}`;
|
|
181
|
+
if (!that.registry[templateName]) templateName = name;
|
|
182
|
+
return orig(templateName, args);
|
|
183
|
+
})(h.renderHTML).bind(h);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
class Loader extends nunjucks.Loader {
|
|
187
|
+
getSource(name) {
|
|
188
|
+
const src = that.registry[name];
|
|
189
|
+
const ref = that.registry[`${name}.source`];
|
|
190
|
+
if (!process.env.DEV) {
|
|
191
|
+
if (!src) throw new Error(`Cannot get template ${name}`);
|
|
192
|
+
return {
|
|
193
|
+
src,
|
|
194
|
+
path: name,
|
|
195
|
+
noCache: false,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
let fullpath: string | null = null;
|
|
199
|
+
const p = path.resolve(template, name);
|
|
200
|
+
if (fs.existsSync(p)) fullpath = p;
|
|
201
|
+
if (!fullpath && ref && fs.existsSync(ref)) fullpath = ref;
|
|
202
|
+
if (!fullpath) {
|
|
203
|
+
if (src) {
|
|
204
|
+
return {
|
|
205
|
+
src,
|
|
206
|
+
path: name,
|
|
207
|
+
noCache: true,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
throw new Error(`Cannot get template ${name}`);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
src: fs.readFileSync(fullpath, 'utf-8'),
|
|
214
|
+
path: fullpath,
|
|
215
|
+
noCache: true,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const env = new Nunjucks(Loader);
|
|
221
|
+
env.addGlobal('findSubModule', (prefix) => Object.keys(that.registry).filter((n) => n.startsWith(prefix)));
|
|
222
|
+
env.addGlobal('templateExists', (name) => !!that.registry[name]);
|
|
223
|
+
|
|
224
|
+
const render = (name: string, state: any) => new Promise<string>((resolve, reject) => {
|
|
225
|
+
const start = Date.now();
|
|
226
|
+
env.render(name, {
|
|
227
|
+
page_name: name.split('.')[0],
|
|
228
|
+
...state,
|
|
229
|
+
formatJudgeTexts: (texts) => texts.map((text) => {
|
|
230
|
+
if (typeof text === 'string') return text;
|
|
231
|
+
return state._(text.message).format(...text.params || []) + ((process.env.DEV && text.stack) ? `\n${text.stack}` : '');
|
|
232
|
+
}).join('\n'),
|
|
233
|
+
datetimeSpan: (arg0, arg1, arg2) => misc.datetimeSpan(arg0, arg1, arg2, state.handler.user?.timeZone),
|
|
234
|
+
ctx: state.handler?.ctx,
|
|
235
|
+
perm: PERM,
|
|
236
|
+
PRIV,
|
|
237
|
+
STATUS,
|
|
238
|
+
UiContext: state.handler?.UiContext || {},
|
|
239
|
+
}, (err, res) => {
|
|
240
|
+
const end = Date.now();
|
|
241
|
+
if (end - start > 5000) console.error(`Render of ${name} took ${end - start}ms`);
|
|
242
|
+
if (err) reject(err);
|
|
243
|
+
else resolve(res || '');
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
ctx.server.registerRenderer('ui-default', {
|
|
248
|
+
name: 'ui-default',
|
|
249
|
+
output: 'html',
|
|
250
|
+
accept: [],
|
|
251
|
+
asFallback: true,
|
|
252
|
+
priority: 1,
|
|
253
|
+
render: (name, args, context) => render(name, { ...context, ...args }),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async [Service.init]() {
|
|
258
|
+
const pending = Object.values(global.addons);
|
|
259
|
+
const logger = this.ctx.logger('template');
|
|
260
|
+
for (const i of pending) {
|
|
261
|
+
const p = locateFile(i as string, ['template', 'templates']);
|
|
262
|
+
if (p && (await fs.stat(p)).isDirectory()) {
|
|
263
|
+
try {
|
|
264
|
+
const files = await getFiles(p);
|
|
265
|
+
for (const file of files) {
|
|
266
|
+
const l = path.resolve(p, file);
|
|
267
|
+
this.registry[file] = await fs.readFile(l, 'utf-8');
|
|
268
|
+
if (process.env.DEV) this.registry[`${file}.source`] = l;
|
|
269
|
+
}
|
|
270
|
+
logger.info('Template init: %s', i);
|
|
271
|
+
} catch (e) {
|
|
272
|
+
this.ctx.injectUI('Notification', 'Template load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION);
|
|
273
|
+
logger.error('Template Load Fail: %s', i);
|
|
274
|
+
logger.error(e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
package/breakpoints.json
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
|
|
3
|
+
let removalChecker = null;
|
|
4
|
+
const res = [];
|
|
5
|
+
|
|
6
|
+
function checkResources() {
|
|
7
|
+
for (let i = res.length - 1; i >= 0; --i) {
|
|
8
|
+
if (res[i].detached || !document.body.contains(res[i].$dom[0])) {
|
|
9
|
+
if (!res[i].detached) res[i].detach();
|
|
10
|
+
res.splice(i, 1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (res.length === 0) {
|
|
14
|
+
clearInterval(removalChecker);
|
|
15
|
+
removalChecker = null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function monitorResource(resource) {
|
|
20
|
+
res.push(resource);
|
|
21
|
+
if (removalChecker === null) {
|
|
22
|
+
removalChecker = setInterval(checkResources, 500);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default class DOMAttachedObject {
|
|
27
|
+
static uniqueIdCounter = 0;
|
|
28
|
+
static DOMAttachKey: string;
|
|
29
|
+
static DOMAttachSelector: string;
|
|
30
|
+
static DOMDetachSelector: string;
|
|
31
|
+
// FIXME should be JQuery<HTMLElement>, but typings for $.transition() wasn't found
|
|
32
|
+
$dom: any;
|
|
33
|
+
id: number;
|
|
34
|
+
detached: boolean;
|
|
35
|
+
eventNS: string;
|
|
36
|
+
|
|
37
|
+
static get($obj) {
|
|
38
|
+
const key = this.DOMAttachKey;
|
|
39
|
+
return $obj.data(key);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static getOrConstruct<T = DOMAttachedObject>($obj, ...args): T {
|
|
43
|
+
const $singleObj = $obj.eq(0);
|
|
44
|
+
const key = this.DOMAttachKey;
|
|
45
|
+
const Protoclass = this as any;
|
|
46
|
+
const instance = this.get($singleObj);
|
|
47
|
+
if (instance !== undefined) return instance;
|
|
48
|
+
const newInstance = new Protoclass($singleObj, ...args);
|
|
49
|
+
// $dom may be updated in constructor so that we use $dom instead
|
|
50
|
+
// of $singleObj here.
|
|
51
|
+
if (!newInstance.$dom) return null;
|
|
52
|
+
newInstance.$dom.data(key, newInstance);
|
|
53
|
+
return newInstance;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static attachAll(container: Document | HTMLElement = document.body, ...args) {
|
|
57
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
58
|
+
if (!this.DOMAttachSelector) {
|
|
59
|
+
throw new Error("'DOMAttachSelector' should be specified");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
63
|
+
console.time(`DOMAttachedObject[${this.DOMAttachKey}]: attachAll`);
|
|
64
|
+
}
|
|
65
|
+
$(container)
|
|
66
|
+
.find(this.DOMAttachSelector)
|
|
67
|
+
.addBack(this.DOMAttachSelector)
|
|
68
|
+
.get()
|
|
69
|
+
.forEach((element) => this.getOrConstruct($(element), ...args));
|
|
70
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
71
|
+
console.timeEnd(`DOMAttachedObject[${this.DOMAttachKey}]: attachAll`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static detachAll(container: Document | HTMLElement = document.body) {
|
|
76
|
+
const selector = this.DOMDetachSelector || this.DOMAttachSelector;
|
|
77
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
78
|
+
if (!selector) {
|
|
79
|
+
throw new Error("'DOMDetachSelector' or 'DOMAttachSelector' should be specified");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
83
|
+
console.time(`DOMAttachedObject[${this.DOMAttachKey}]: detachAll`);
|
|
84
|
+
}
|
|
85
|
+
$(container)
|
|
86
|
+
.find(selector)
|
|
87
|
+
.addBack(selector)
|
|
88
|
+
.get()
|
|
89
|
+
.forEach((element) => {
|
|
90
|
+
const instance = this.get($(element));
|
|
91
|
+
if (instance) {
|
|
92
|
+
instance.detach();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
96
|
+
console.timeEnd(`DOMAttachedObject[${this.DOMAttachKey}]: detachAll`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static registerLifeCycleHooks(attach = true) {
|
|
101
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
102
|
+
if (!this.DOMAttachSelector) {
|
|
103
|
+
throw new Error("'DOMAttachSelector' should be specified");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
$(document).on('vjContentNew', (e) => this.attachAll(e.target));
|
|
107
|
+
$(document).on('vjContentRemove', (e) => this.detachAll(e.target));
|
|
108
|
+
if (attach) {
|
|
109
|
+
this.attachAll();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
detach() {
|
|
114
|
+
if ((this.constructor as any).DOMAttachKey) {
|
|
115
|
+
this.$dom.removeData((this.constructor as any).DOMAttachKey);
|
|
116
|
+
}
|
|
117
|
+
this.detached = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
constructor($dom: JQuery<HTMLElement>, monitorDetach = false) {
|
|
121
|
+
if ($dom == null) return null;
|
|
122
|
+
this.$dom = $dom;
|
|
123
|
+
this.id = ++DOMAttachedObject.uniqueIdCounter;
|
|
124
|
+
this.eventNS = `vj4obj_${this.id}`;
|
|
125
|
+
this.detached = false;
|
|
126
|
+
if (monitorDetach) monitorResource(this);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
2
|
+
import AssignSelectAutoCompleteFC from './components/AssignSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
export default class AssignSelectAutoComplete<Multi extends boolean> extends AutoComplete {
|
|
5
|
+
static DOMAttachKey = 'ucwAssignSelectAutoCompleteInstance';
|
|
6
|
+
|
|
7
|
+
constructor($dom, options: AutoCompleteOptions<Multi> = {}) {
|
|
8
|
+
super($dom, {
|
|
9
|
+
classes: 'assign-select',
|
|
10
|
+
component: AssignSelectAutoCompleteFC,
|
|
11
|
+
props: {
|
|
12
|
+
multi: true,
|
|
13
|
+
height: 'auto',
|
|
14
|
+
},
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
value(): string {
|
|
20
|
+
return this.ref?.getSelectedItemKeys().join(',') ?? this.$dom.val();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CustomSelectAutoComplete as CustomSelectAutoCompleteFC } from '@hydrooj/components';
|
|
2
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
3
|
+
|
|
4
|
+
interface CustomSelectOptions {
|
|
5
|
+
data: any[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class CustomSelectAutoComplete<Multi extends boolean> extends AutoComplete<CustomSelectOptions> {
|
|
9
|
+
static DOMAttachKey = 'ucwCustomSelectAutoCompleteInstance';
|
|
10
|
+
|
|
11
|
+
constructor($dom, options: CustomSelectOptions & AutoCompleteOptions<Multi>) {
|
|
12
|
+
super($dom, {
|
|
13
|
+
classes: 'custom-select',
|
|
14
|
+
component: CustomSelectAutoCompleteFC,
|
|
15
|
+
props: {
|
|
16
|
+
data: options.data,
|
|
17
|
+
multi: options.multi,
|
|
18
|
+
height: 'auto',
|
|
19
|
+
},
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
2
|
+
import DomainSelectAutoCompleteFC from './components/DomainSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
export default class DomainSelectAutoComplete<Multi extends boolean> extends AutoComplete {
|
|
5
|
+
static DOMAttachKey = 'ucwDomainSelectAutoCompleteInstance';
|
|
6
|
+
|
|
7
|
+
constructor($dom, options: AutoCompleteOptions<Multi> = {}) {
|
|
8
|
+
super($dom, {
|
|
9
|
+
classes: 'domain-select',
|
|
10
|
+
component: DomainSelectAutoCompleteFC,
|
|
11
|
+
props: {
|
|
12
|
+
multi: options.multi,
|
|
13
|
+
height: '34px',
|
|
14
|
+
},
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
2
|
+
import FileSelectAutoCompleteFC from './components/FileSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
interface FileSelectOptions {
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class FileSelectAutoComplete<Multi extends boolean> extends AutoComplete<FileSelectOptions> {
|
|
12
|
+
static DOMAttachKey = 'ucwFileSelectAutoCompleteInstance';
|
|
13
|
+
|
|
14
|
+
constructor($dom, options: FileSelectOptions & AutoCompleteOptions<Multi>) {
|
|
15
|
+
super($dom, {
|
|
16
|
+
classes: 'file-select',
|
|
17
|
+
component: FileSelectAutoCompleteFC,
|
|
18
|
+
props: {
|
|
19
|
+
data: options.data,
|
|
20
|
+
multi: options.multi,
|
|
21
|
+
height: 'auto',
|
|
22
|
+
},
|
|
23
|
+
...options,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
2
|
+
import LanguageSelectAutoCompleteFC from './components/LanguageSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
interface LanguageSelectOptions {
|
|
5
|
+
multi?: boolean;
|
|
6
|
+
withAuto?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default class LanguageSelectAutoComplete<Multi extends boolean> extends AutoComplete<LanguageSelectOptions> {
|
|
10
|
+
static DOMAttachKey = 'ucwLanguageSelectAutoCompleteInstance';
|
|
11
|
+
|
|
12
|
+
constructor($dom, options: LanguageSelectOptions & AutoCompleteOptions<Multi>) {
|
|
13
|
+
super($dom, {
|
|
14
|
+
classes: 'language-select',
|
|
15
|
+
component: LanguageSelectAutoCompleteFC,
|
|
16
|
+
props: {
|
|
17
|
+
multi: options.multi,
|
|
18
|
+
withAuto: options.withAuto,
|
|
19
|
+
height: 'auto',
|
|
20
|
+
},
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import AutoComplete from '.';
|
|
2
|
+
import ProblemSelectAutoCompleteFC from './components/ProblemSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
export default class ProblemSelectAutoComplete extends AutoComplete {
|
|
5
|
+
static DOMAttachKey = 'ucwProblemSelectAutoCompleteInstance';
|
|
6
|
+
|
|
7
|
+
constructor($dom, options) {
|
|
8
|
+
super($dom, {
|
|
9
|
+
classes: 'problem-select',
|
|
10
|
+
component: ProblemSelectAutoCompleteFC,
|
|
11
|
+
props: {
|
|
12
|
+
multi: options.multi,
|
|
13
|
+
height: 'auto',
|
|
14
|
+
},
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AutoComplete, { AutoCompleteOptions } from '.';
|
|
2
|
+
import UserSelectAutoCompleteFC from './components/UserSelectAutoComplete';
|
|
3
|
+
|
|
4
|
+
export default class UserSelectAutoComplete<Multi extends boolean> extends AutoComplete {
|
|
5
|
+
static DOMAttachKey = 'ucwUserSelectAutoCompleteInstance';
|
|
6
|
+
|
|
7
|
+
constructor($dom, options: AutoCompleteOptions<Multi> = {}) {
|
|
8
|
+
super($dom, {
|
|
9
|
+
classes: 'user-select',
|
|
10
|
+
component: UserSelectAutoCompleteFC,
|
|
11
|
+
props: {
|
|
12
|
+
multi: options.multi,
|
|
13
|
+
height: 'auto',
|
|
14
|
+
},
|
|
15
|
+
...options,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
value(): Multi extends true ? number[] : string {
|
|
20
|
+
if (this.options.multi) return this.ref?.getSelectedItemKeys().map((i) => +i) ?? this.$dom.val();
|
|
21
|
+
return this.ref?.getSelectedItems()[0] ?? null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AutoComplete, AutoCompleteHandle, AutoCompleteProps } from '@hydrooj/components';
|
|
2
|
+
import type { GDoc, Udoc } from 'hydrooj/src/interface';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React, { forwardRef } from 'react';
|
|
5
|
+
import { api } from 'vj/utils';
|
|
6
|
+
|
|
7
|
+
interface AssignItem {
|
|
8
|
+
type: 'user' | 'group';
|
|
9
|
+
key: string;
|
|
10
|
+
name: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
uids?: number[];
|
|
14
|
+
invalid?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const toUserItem = (user: Udoc): AssignItem => ({
|
|
18
|
+
type: 'user',
|
|
19
|
+
key: user._id.toString(),
|
|
20
|
+
name: user.uname,
|
|
21
|
+
displayName: user.displayName,
|
|
22
|
+
avatarUrl: user.avatarUrl,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const toGroupItem = (group: GDoc): AssignItem => ({
|
|
26
|
+
type: 'group',
|
|
27
|
+
key: group.name,
|
|
28
|
+
name: group.name,
|
|
29
|
+
uids: group.uids,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const AssignSelectAutoComplete = forwardRef<AutoCompleteHandle<AssignItem>, AutoCompleteProps<AssignItem>>((props, ref) => (
|
|
33
|
+
<AutoComplete<AssignItem>
|
|
34
|
+
ref={ref as any}
|
|
35
|
+
cacheKey="assign"
|
|
36
|
+
queryItems={async (query) => {
|
|
37
|
+
const [users, groups] = await Promise.all([
|
|
38
|
+
api('users', { search: query }, ['_id', 'uname', 'displayName', 'avatarUrl']),
|
|
39
|
+
api('groups', { search: query }, ['name', 'uids']),
|
|
40
|
+
]);
|
|
41
|
+
const userItems: AssignItem[] = users.map((user: Udoc) => toUserItem(user));
|
|
42
|
+
const groupItems: AssignItem[] = groups.map((group: GDoc) => toGroupItem(group));
|
|
43
|
+
return [...groupItems, ...userItems];
|
|
44
|
+
}}
|
|
45
|
+
fetchItems={async (keys) => {
|
|
46
|
+
const isUserId = (k: string) => /^-?[0-9]+$/.test(k);
|
|
47
|
+
const userIds = keys.filter((k) => isUserId(k));
|
|
48
|
+
const groupNames = keys.filter((k) => !isUserId(k));
|
|
49
|
+
|
|
50
|
+
const [users, groups]: [Udoc[], GDoc[]] = await Promise.all([
|
|
51
|
+
userIds.length > 0 ? api('users', { auto: userIds }, ['_id', 'uname', 'displayName']) : [],
|
|
52
|
+
groupNames.length > 0 ? api('groups', { names: groupNames }, ['name', 'uids']) : [],
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const userItems: AssignItem[] = users.map((user: Udoc) => toUserItem(user));
|
|
56
|
+
const groupItems: AssignItem[] = keys
|
|
57
|
+
.filter((key) => !isUserId(key))
|
|
58
|
+
.map((key) => {
|
|
59
|
+
const group = groups.find((g) => g.name === key);
|
|
60
|
+
return group ? toGroupItem(group) : { type: 'group', key, name: key, invalid: true };
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return [...groupItems, ...userItems];
|
|
64
|
+
}}
|
|
65
|
+
itemText={(item) => {
|
|
66
|
+
if (item.type === 'group') {
|
|
67
|
+
if (item.invalid) return `${item.name} (invalid)`;
|
|
68
|
+
return `${item.name} (${item.uids?.length || 0} users)`;
|
|
69
|
+
}
|
|
70
|
+
return item.name + (item.displayName ? ` (${item.displayName})` : '');
|
|
71
|
+
}}
|
|
72
|
+
itemKey={(item) => item.key}
|
|
73
|
+
renderItem={(item) => (
|
|
74
|
+
<div className="media">
|
|
75
|
+
{item.type === 'user' && (
|
|
76
|
+
<div className="media__left medium">
|
|
77
|
+
<img className="small user-profile-avatar" alt="" src={item.avatarUrl} width="30" height="30" />
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
<div className="media__body medium">
|
|
81
|
+
<div className="assign-select__name">
|
|
82
|
+
{item.name}{item.type === 'user' && item.displayName && ` (${item.displayName})`}
|
|
83
|
+
</div>
|
|
84
|
+
<div className="assign-select__desc">
|
|
85
|
+
{item.type === 'group' ? `Group • ${item.uids?.length || 0} users` : `User • UID = ${item.key}`}
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
{...{
|
|
91
|
+
width: '100%',
|
|
92
|
+
height: 'auto',
|
|
93
|
+
listStyle: {},
|
|
94
|
+
multi: true,
|
|
95
|
+
selectedKeys: [],
|
|
96
|
+
allowEmptyQuery: false,
|
|
97
|
+
freeSolo: false,
|
|
98
|
+
freeSoloConverter: (input) => input,
|
|
99
|
+
...props,
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
));
|
|
103
|
+
|
|
104
|
+
AssignSelectAutoComplete.propTypes = {
|
|
105
|
+
width: PropTypes.string,
|
|
106
|
+
height: PropTypes.string,
|
|
107
|
+
listStyle: PropTypes.object,
|
|
108
|
+
onChange: PropTypes.func.isRequired,
|
|
109
|
+
multi: PropTypes.bool,
|
|
110
|
+
selectedKeys: PropTypes.arrayOf(PropTypes.string),
|
|
111
|
+
allowEmptyQuery: PropTypes.bool,
|
|
112
|
+
freeSolo: PropTypes.bool,
|
|
113
|
+
freeSoloConverter: PropTypes.func,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
AssignSelectAutoComplete.displayName = 'AssignSelectAutoComplete';
|
|
117
|
+
|
|
118
|
+
export default AssignSelectAutoComplete;
|