@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,100 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { connect } from 'react-redux';
|
|
5
|
+
import Icon from 'vj/components/react/IconComponent';
|
|
6
|
+
import { request } from 'vj/utils';
|
|
7
|
+
|
|
8
|
+
const mapStateToProps = (state) => ({
|
|
9
|
+
activeId: state.activeId,
|
|
10
|
+
isPosting: state.activeId !== null
|
|
11
|
+
? state.isPosting[state.activeId]
|
|
12
|
+
: false,
|
|
13
|
+
inputValue: state.activeId !== null
|
|
14
|
+
? state.inputs[state.activeId]
|
|
15
|
+
: '',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const mapDispatchToProps = (dispatch) => ({
|
|
19
|
+
handleChange(id, value) {
|
|
20
|
+
if (id === null) return;
|
|
21
|
+
dispatch({
|
|
22
|
+
type: 'DIALOGUES_INPUT_CHANGED',
|
|
23
|
+
payload: value,
|
|
24
|
+
meta: {
|
|
25
|
+
dialogueId: id,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
postSend(uid, value) {
|
|
30
|
+
const req = request.post('', {
|
|
31
|
+
operation: 'send',
|
|
32
|
+
uid,
|
|
33
|
+
content: value,
|
|
34
|
+
});
|
|
35
|
+
dispatch({
|
|
36
|
+
type: 'DIALOGUES_POST_SEND',
|
|
37
|
+
payload: req,
|
|
38
|
+
meta: {
|
|
39
|
+
dialogueId: uid,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default connect(mapStateToProps, mapDispatchToProps)(class MessagePadInputContainer extends React.PureComponent {
|
|
46
|
+
static contextTypes = {
|
|
47
|
+
store: PropTypes.object,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
componentDidUpdate(prevProps) {
|
|
51
|
+
this.focusInput = (
|
|
52
|
+
this.props.activeId !== prevProps.activeId
|
|
53
|
+
|| (prevProps.isPosting !== this.props.isPosting && this.props.isPosting === false)
|
|
54
|
+
);
|
|
55
|
+
if (this.focusInput) {
|
|
56
|
+
const { scrollX, scrollY } = window;
|
|
57
|
+
this.state.ref?.focus();
|
|
58
|
+
window.scrollTo(scrollX, scrollY);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
handleKeyDown(ev) {
|
|
63
|
+
if (ev.keyCode === 13 && (ev.ctrlKey || ev.metaKey)) {
|
|
64
|
+
this.submit();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
submit() {
|
|
69
|
+
this.props.postSend(
|
|
70
|
+
this.props.activeId,
|
|
71
|
+
this.props.inputValue,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
const cn = classNames('messagepad__input', {
|
|
77
|
+
visible: this.props.activeId !== null,
|
|
78
|
+
});
|
|
79
|
+
return (
|
|
80
|
+
<div className={cn}>
|
|
81
|
+
<div className="messagepad__textarea-container">
|
|
82
|
+
<textarea
|
|
83
|
+
ref={(ref) => this.setState({ ...this.state, ref })}
|
|
84
|
+
data-markdown
|
|
85
|
+
disabled={this.props.isPosting}
|
|
86
|
+
value={this.props.inputValue}
|
|
87
|
+
onKeyDown={(ev) => this.handleKeyDown(ev)}
|
|
88
|
+
onChange={(ev) => this.props.handleChange(this.props.activeId, ev.target.value)}
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
<button
|
|
92
|
+
disabled={!this.props.inputValue.trim().length || this.props.isPosting}
|
|
93
|
+
onClick={() => this.submit()}
|
|
94
|
+
>
|
|
95
|
+
<Icon name="send" />
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { connect } from 'react-redux';
|
|
4
|
+
import Icon from 'vj/components/react/IconComponent';
|
|
5
|
+
import { i18n, request } from 'vj/utils';
|
|
6
|
+
import MessagePadDialogueContent from './MessagePadDialogueContentContainer';
|
|
7
|
+
import MessagePadDialogueList from './MessagePadDialogueListContainer';
|
|
8
|
+
import MessagePadInput from './MessagePadInputContainer';
|
|
9
|
+
|
|
10
|
+
const mapDispatchToProps = (dispatch) => ({
|
|
11
|
+
loadDialogues() {
|
|
12
|
+
dispatch({
|
|
13
|
+
type: 'DIALOGUES_LOAD_DIALOGUES',
|
|
14
|
+
payload: request.get('', { _: Date.now() }),
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default connect(null, mapDispatchToProps)(class MessagePadContainer extends React.PureComponent {
|
|
20
|
+
static propTypes = {
|
|
21
|
+
onAdd: PropTypes.func.isRequired,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
componentDidMount() {
|
|
25
|
+
this.props.loadDialogues();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
return (
|
|
30
|
+
<div className="messagepad clearfix">
|
|
31
|
+
<div className="messagepad__sidebar">
|
|
32
|
+
<div className="section__header">
|
|
33
|
+
<button
|
|
34
|
+
onClick={() => this.props.onAdd()}
|
|
35
|
+
className="primary rounded button"
|
|
36
|
+
>
|
|
37
|
+
<Icon name="add" />
|
|
38
|
+
{' '}
|
|
39
|
+
{i18n('New')}
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
<MessagePadDialogueList />
|
|
43
|
+
</div>
|
|
44
|
+
<MessagePadDialogueContent />
|
|
45
|
+
<MessagePadInput />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import 'jquery.easing';
|
|
2
|
+
|
|
3
|
+
import $ from 'jquery';
|
|
4
|
+
|
|
5
|
+
function scrollToViewport() {
|
|
6
|
+
const BOUND_TOP = 60;
|
|
7
|
+
const BOUND_BOTTOM = 20;
|
|
8
|
+
const node = $('.messagepad')[0];
|
|
9
|
+
if (node.offsetHeight + BOUND_TOP + BOUND_BOTTOM < window.innerHeight) {
|
|
10
|
+
const rect = node.getBoundingClientRect();
|
|
11
|
+
const rectBody = document.body.getBoundingClientRect();
|
|
12
|
+
let targetScrollTop = null;
|
|
13
|
+
if (rect.top < BOUND_TOP) {
|
|
14
|
+
targetScrollTop = rect.top - rectBody.top - BOUND_TOP;
|
|
15
|
+
} else if (rect.top + node.offsetHeight > window.innerHeight) {
|
|
16
|
+
targetScrollTop = rect.top - rectBody.top + node.offsetHeight + BOUND_BOTTOM - window.innerHeight;
|
|
17
|
+
}
|
|
18
|
+
if (targetScrollTop !== null) {
|
|
19
|
+
$('html, body').stop().animate({ scrollTop: targetScrollTop }, 200, 'easeOutCubic');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function reducer(state = null, action: any = {}) {
|
|
25
|
+
switch (action.type) {
|
|
26
|
+
case 'DIALOGUES_SWITCH_TO': {
|
|
27
|
+
scrollToViewport();
|
|
28
|
+
return action.payload;
|
|
29
|
+
}
|
|
30
|
+
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
|
31
|
+
return action.meta.dialogueId;
|
|
32
|
+
}
|
|
33
|
+
default:
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
3
|
+
export default function reducer(state = {}, action = {}) {
|
|
4
|
+
switch (action.type) {
|
|
5
|
+
case 'DIALOGUES_LOAD_DIALOGUES_FULFILLED': {
|
|
6
|
+
const { messages } = action.payload;
|
|
7
|
+
return { ...state, ..._.keyBy(messages, 'udoc._id') };
|
|
8
|
+
}
|
|
9
|
+
case 'DIALOGUES_CREATE': {
|
|
10
|
+
const { user } = action.payload;
|
|
11
|
+
if (state[user._id]) return state;
|
|
12
|
+
return {
|
|
13
|
+
...state,
|
|
14
|
+
[user._id]: {
|
|
15
|
+
_id: user._id,
|
|
16
|
+
udoc: { ...user },
|
|
17
|
+
messages: [],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
|
22
|
+
const id = action.meta.dialogueId;
|
|
23
|
+
const { mdoc } = action.payload;
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
[id]: {
|
|
27
|
+
...state[id],
|
|
28
|
+
messages: [
|
|
29
|
+
...state[id].messages,
|
|
30
|
+
mdoc,
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
case 'DIALOGUES_MESSAGE_PUSH': {
|
|
36
|
+
const { mdoc, udoc } = action.payload;
|
|
37
|
+
const to = mdoc.from === UserContext._id ? mdoc.to : mdoc.from;
|
|
38
|
+
return {
|
|
39
|
+
...state,
|
|
40
|
+
[to]: {
|
|
41
|
+
...state[to],
|
|
42
|
+
udoc,
|
|
43
|
+
messages: [
|
|
44
|
+
...state[to]?.messages || [],
|
|
45
|
+
mdoc,
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import activeId from './activeId';
|
|
3
|
+
import dialogues from './dialogues';
|
|
4
|
+
import inputs from './inputs';
|
|
5
|
+
import isPosting from './isPosting';
|
|
6
|
+
|
|
7
|
+
const reducer = combineReducers({
|
|
8
|
+
activeId,
|
|
9
|
+
dialogues,
|
|
10
|
+
inputs,
|
|
11
|
+
isPosting,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export default reducer;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
3
|
+
export default function reducer(state = {}, action = {}) {
|
|
4
|
+
switch (action.type) {
|
|
5
|
+
case 'DIALOGUES_LOAD_DIALOGUES_FULFILLED': {
|
|
6
|
+
const dialogues = action.payload.messages;
|
|
7
|
+
return { ...state, ..._.fromPairs(_.map(dialogues, (d) => [d._id, ''])) };
|
|
8
|
+
}
|
|
9
|
+
case 'DIALOGUES_CREATE': {
|
|
10
|
+
const { user } = action.payload;
|
|
11
|
+
return {
|
|
12
|
+
...state,
|
|
13
|
+
[user._id]: '',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
case 'DIALOGUES_INPUT_CHANGED': {
|
|
17
|
+
const id = action.meta.dialogueId;
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
[id]: action.payload,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
|
24
|
+
const id = action.meta.dialogueId;
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
[id]: '',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'DIALOGUES_MESSAGE_PUSH': {
|
|
31
|
+
const { udoc } = action.payload;
|
|
32
|
+
if (!state[udoc._id]) {
|
|
33
|
+
return {
|
|
34
|
+
...state,
|
|
35
|
+
[udoc._id]: '',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
return state;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Notification from 'vj/components/notification';
|
|
3
|
+
|
|
4
|
+
export default function reducer(state = {}, action: any = {}) {
|
|
5
|
+
switch (action.type) {
|
|
6
|
+
case 'DIALOGUES_LOAD_DIALOGUES_FULFILLED': {
|
|
7
|
+
const dialogues = action.payload.messages;
|
|
8
|
+
return { ...state, ..._.fromPairs(_.map(dialogues, (d) => [d._id, false])) };
|
|
9
|
+
}
|
|
10
|
+
case 'DIALOGUES_CREATE': {
|
|
11
|
+
const { user } = action.payload;
|
|
12
|
+
return {
|
|
13
|
+
...state,
|
|
14
|
+
[user._id]: false,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
case 'DIALOGUES_POST_SEND_PENDING': {
|
|
18
|
+
const id = action.meta.dialogueId;
|
|
19
|
+
return {
|
|
20
|
+
...state,
|
|
21
|
+
[id]: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
case 'DIALOGUES_POST_SEND_REJECTED': {
|
|
25
|
+
Notification.error(action.payload.message);
|
|
26
|
+
const id = action.meta.dialogueId;
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
[id]: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
|
33
|
+
const id = action.meta.dialogueId;
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
[id]: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case 'DIALOGUES_MESSAGE_PUSH': {
|
|
40
|
+
const { udoc } = action.payload;
|
|
41
|
+
return {
|
|
42
|
+
...state,
|
|
43
|
+
[udoc._id]: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import './monaco.styl';
|
|
2
|
+
|
|
3
|
+
import $ from 'jquery';
|
|
4
|
+
import { EditorAction, registerEditorAction } from 'monaco-editor/esm/vs/editor/browser/editorExtensions';
|
|
5
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
6
|
+
import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput';
|
|
7
|
+
import list from 'monaco-themes/themes/themelist.json';
|
|
8
|
+
import { nanoid } from 'nanoid';
|
|
9
|
+
import { i18n, request } from 'vj/utils';
|
|
10
|
+
|
|
11
|
+
export { renderMarkdown } from 'monaco-editor/esm/vs/base/browser/markdownRenderer';
|
|
12
|
+
|
|
13
|
+
export default monaco;
|
|
14
|
+
export const customOptions: monaco.editor.IStandaloneDiffEditorConstructionOptions = JSON.parse(localStorage.getItem('editor.config') || '{}');
|
|
15
|
+
export function saveCustomOptions() {
|
|
16
|
+
localStorage.setItem('editor.config', JSON.stringify(customOptions));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const loaded = {};
|
|
20
|
+
async function fetchTheme(id: string, label: string) {
|
|
21
|
+
if (loaded[id]) return;
|
|
22
|
+
const res = await fetch(`${UiContext.cdn_prefix}monaco/themes/${label}.json`);
|
|
23
|
+
const data = await res.json();
|
|
24
|
+
monaco.editor.defineTheme(id, data);
|
|
25
|
+
loaded[id] = true;
|
|
26
|
+
}
|
|
27
|
+
export const loadThemePromise = customOptions.theme
|
|
28
|
+
? fetchTheme(customOptions.theme, list[customOptions.theme])
|
|
29
|
+
: Promise.resolve();
|
|
30
|
+
|
|
31
|
+
// 这破烂 monaco 能不能给个 typings 啊
|
|
32
|
+
// 我翻源码真的很累的好吧
|
|
33
|
+
class ChangeThemeAction extends EditorAction {
|
|
34
|
+
constructor() {
|
|
35
|
+
super({
|
|
36
|
+
id: 'hydro.changeEditorTheme',
|
|
37
|
+
label: i18n('Change Theme'),
|
|
38
|
+
alias: 'Change Theme',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async run(accessor, editor: monaco.editor.IStandaloneCodeEditor) {
|
|
43
|
+
const items = Object.keys(list).map((key) => ({
|
|
44
|
+
label: list[key],
|
|
45
|
+
command: key,
|
|
46
|
+
}));
|
|
47
|
+
const quickInputService = accessor.get(IQuickInputService);
|
|
48
|
+
const oldTheme = (editor as any)._themeService._theme;
|
|
49
|
+
let focus = '';
|
|
50
|
+
const selected = await quickInputService.pick(items, {
|
|
51
|
+
canPickMany: false,
|
|
52
|
+
async onDidFocus(item) {
|
|
53
|
+
focus = item.command;
|
|
54
|
+
await fetchTheme(item.command, item.label);
|
|
55
|
+
if (focus === item.command) monaco.editor.setTheme(item.command);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
if (!selected) {
|
|
59
|
+
const themeId = oldTheme.type ? `${oldTheme.base}-${oldTheme.type}` : oldTheme.id;
|
|
60
|
+
return monaco.editor.setTheme(themeId);
|
|
61
|
+
}
|
|
62
|
+
await fetchTheme(selected.command, selected.label);
|
|
63
|
+
customOptions.theme = selected.command;
|
|
64
|
+
saveCustomOptions();
|
|
65
|
+
return monaco.editor.setTheme(selected.command);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
registerEditorAction(ChangeThemeAction);
|
|
70
|
+
|
|
71
|
+
const pagename = document.documentElement.getAttribute('data-page');
|
|
72
|
+
const isProblemPage = ['problem_create', 'problem_edit'].includes(pagename);
|
|
73
|
+
const isProblemEdit = pagename === 'problem_edit';
|
|
74
|
+
function handlePasteEvent(editor: monaco.editor.IStandaloneCodeEditor) {
|
|
75
|
+
window.addEventListener('paste', (ev: ClipboardEvent) => {
|
|
76
|
+
if (!editor.hasTextFocus()) return;
|
|
77
|
+
const selection = editor.getSelection();
|
|
78
|
+
const { items } = ev.clipboardData;
|
|
79
|
+
let wrapper = ['', ''];
|
|
80
|
+
let ext;
|
|
81
|
+
const matches = items[0].type.match(/^image\/(png|jpg|jpeg|gif)$/i);
|
|
82
|
+
if (matches) {
|
|
83
|
+
wrapper = [''];
|
|
84
|
+
[, ext] = matches;
|
|
85
|
+
} else if (items[0].type === 'application/x-zip-compressed') {
|
|
86
|
+
wrapper = ['[file](', ')'];
|
|
87
|
+
ext = 'zip';
|
|
88
|
+
}
|
|
89
|
+
if (!ext) return;
|
|
90
|
+
ev.preventDefault();
|
|
91
|
+
ev.stopPropagation();
|
|
92
|
+
const filename = `${nanoid()}.${ext}`;
|
|
93
|
+
const data = new FormData();
|
|
94
|
+
data.append('filename', filename);
|
|
95
|
+
data.append('file', items[0].getAsFile());
|
|
96
|
+
data.append('operation', 'upload_file');
|
|
97
|
+
if (isProblemEdit) data.append('type', 'additional_file');
|
|
98
|
+
let range: monaco.Range = null;
|
|
99
|
+
editor.executeEdits('', [{
|
|
100
|
+
range: new monaco.Range(selection.endLineNumber, selection.endColumn, selection.endLineNumber, selection.endColumn),
|
|
101
|
+
text: `}) `,
|
|
102
|
+
}], (inverseOp) => { range = inverseOp[0].range; return null; });
|
|
103
|
+
editor.setPosition(editor.getSelection().getEndPosition());
|
|
104
|
+
|
|
105
|
+
function updateText(text: string) {
|
|
106
|
+
const pos = editor.getSelection();
|
|
107
|
+
const rangeBefore = range;
|
|
108
|
+
editor.executeEdits('', [{ range, text: `${wrapper[0]}${text}${wrapper[1]} ` }], (inverseOp) => {
|
|
109
|
+
range = inverseOp[0].range;
|
|
110
|
+
if (pos.endLineNumber !== pos.startLineNumber || pos.endLineNumber !== range.endLineNumber) return null;
|
|
111
|
+
const delta = rangeBefore.endColumn - range.endColumn;
|
|
112
|
+
editor.setPosition(new monaco.Position(pos.endLineNumber, pos.endColumn - delta));
|
|
113
|
+
return null;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
let progress = 0;
|
|
117
|
+
request.postFile(isProblemEdit ? './files' : '/file', data, {
|
|
118
|
+
xhr() {
|
|
119
|
+
const xhr = new XMLHttpRequest();
|
|
120
|
+
xhr.upload.addEventListener('loadstart', () => updateText(i18n('Uploading...')));
|
|
121
|
+
xhr.upload.addEventListener('progress', (e) => {
|
|
122
|
+
if (!e.lengthComputable) return;
|
|
123
|
+
const percentComplete = Math.round((e.loaded / e.total) * 100);
|
|
124
|
+
if (percentComplete === progress) return;
|
|
125
|
+
progress = percentComplete;
|
|
126
|
+
updateText(`${i18n('Uploading...')} ${percentComplete}%`);
|
|
127
|
+
}, false);
|
|
128
|
+
return xhr;
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
.then(() => updateText(`${isProblemPage ? 'file://' : `/file/${UserContext._id}/`}${filename}`))
|
|
132
|
+
.catch((e) => {
|
|
133
|
+
console.error(e);
|
|
134
|
+
updateText(`${i18n('Upload Failed')}: ${e.message}`);
|
|
135
|
+
});
|
|
136
|
+
}, { capture: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function registerAction(
|
|
140
|
+
editor: monaco.editor.IStandaloneCodeEditor,
|
|
141
|
+
model: monaco.editor.IModel,
|
|
142
|
+
element?,
|
|
143
|
+
) {
|
|
144
|
+
if (element) {
|
|
145
|
+
editor.addAction({
|
|
146
|
+
id: 'hydro.submitForm',
|
|
147
|
+
label: 'Submit',
|
|
148
|
+
keybindings: [
|
|
149
|
+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
|
|
150
|
+
monaco.KeyMod.WinCtrl | monaco.KeyCode.Enter,
|
|
151
|
+
],
|
|
152
|
+
run: () => {
|
|
153
|
+
const form = $(element).closest('form');
|
|
154
|
+
if (form.find('[data-default-submit]').length) form.find('[data-default-submit]').click();
|
|
155
|
+
else form.submit();
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyP, () => {
|
|
160
|
+
editor.getAction('editor.action.quickCommand').run();
|
|
161
|
+
});
|
|
162
|
+
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
|
|
163
|
+
const action = editor.getAction('editor.action.format') || editor.getAction('editor.action.formatDocument');
|
|
164
|
+
if (action) action.run();
|
|
165
|
+
});
|
|
166
|
+
editor.onDidChangeConfiguration(() => {
|
|
167
|
+
const current = editor.getOption(monaco.editor.EditorOptions.fontSize.id);
|
|
168
|
+
customOptions.fontSize = current;
|
|
169
|
+
saveCustomOptions();
|
|
170
|
+
});
|
|
171
|
+
if (model.getLanguageId() === 'markdown') {
|
|
172
|
+
const suggestWidget = (editor.getContribution('editor.contrib.suggestController') as any).widget?.value;
|
|
173
|
+
if (suggestWidget?._setDetailsVisible) suggestWidget._setDetailsVisible(true);
|
|
174
|
+
handlePasteEvent(editor);
|
|
175
|
+
}
|
|
176
|
+
if (!customOptions.theme) return null;
|
|
177
|
+
return loadThemePromise.then(() => editor.updateOptions({ theme: customOptions.theme }));
|
|
178
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import keyword from 'emojis-keywords';
|
|
2
|
+
import list from 'emojis-list';
|
|
3
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
4
|
+
import qface from 'qface';
|
|
5
|
+
import { api } from 'vj/utils';
|
|
6
|
+
|
|
7
|
+
function emoji(range) {
|
|
8
|
+
return keyword.map((i, index) => ({
|
|
9
|
+
label: `${list[index]} ${i}`,
|
|
10
|
+
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
11
|
+
documentation: i,
|
|
12
|
+
insertText: list[index],
|
|
13
|
+
range,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function qqEmoji(range) {
|
|
18
|
+
return qface.data.flatMap((i) => {
|
|
19
|
+
const url = qface.getUrl(i.QSid, 'https://koishi.js.org/QFace');
|
|
20
|
+
return [i.QDes.substring(1), ...(i.Input || [])].map((input) => ({
|
|
21
|
+
label: `/${input}`,
|
|
22
|
+
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
23
|
+
documentation: { value: ``, isTrusted: true },
|
|
24
|
+
insertText: `![${i.Input ? i.Input[0] : i.QDes.substring(1)}](${url} =32x32) `,
|
|
25
|
+
range,
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
monaco.editor.registerCommand('hydro.openUserPage', (accesser, uid) => {
|
|
31
|
+
window.open(`/user/${uid}`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
monaco.languages.registerCodeLensProvider('markdown', {
|
|
35
|
+
async provideCodeLenses(model) {
|
|
36
|
+
const users = model.findMatches('\\[\\]\\(/user/(\\d+)\\)', true, true, true, null, true);
|
|
37
|
+
if (!users.length) {
|
|
38
|
+
return {
|
|
39
|
+
lenses: [],
|
|
40
|
+
dispose: () => { },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const data = await api('users', { ids: users.map((i) => +i.matches[1]) }, ['_id', 'uname']);
|
|
44
|
+
return {
|
|
45
|
+
lenses: users.map((i, index) => ({
|
|
46
|
+
range: i.range,
|
|
47
|
+
id: `${index}.${i.matches[1]}`,
|
|
48
|
+
command: {
|
|
49
|
+
id: 'hydro.openUserPage',
|
|
50
|
+
arguments: [i.matches[1]],
|
|
51
|
+
title: `@${data.find((doc) => doc._id.toString() === i.matches[1])?.uname || i.matches[1]}`,
|
|
52
|
+
},
|
|
53
|
+
})),
|
|
54
|
+
dispose: () => { },
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
resolveCodeLens(model, codeLens) {
|
|
58
|
+
return codeLens;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
monaco.languages.registerCompletionItemProvider('markdown', {
|
|
63
|
+
async provideCompletionItems(model, position) {
|
|
64
|
+
const word = model.getWordAtPosition(position);
|
|
65
|
+
if (word.word.length < 2) return { suggestions: [] };
|
|
66
|
+
const prefix = model.getValueInRange({
|
|
67
|
+
startLineNumber: position.lineNumber,
|
|
68
|
+
endLineNumber: position.lineNumber,
|
|
69
|
+
startColumn: word.startColumn - 1,
|
|
70
|
+
endColumn: word.startColumn,
|
|
71
|
+
});
|
|
72
|
+
if (![':', '/', '@'].includes(prefix)) return { suggestions: [] };
|
|
73
|
+
const range = {
|
|
74
|
+
startLineNumber: position.lineNumber,
|
|
75
|
+
endLineNumber: position.lineNumber,
|
|
76
|
+
startColumn: word.startColumn - 1,
|
|
77
|
+
endColumn: word.endColumn,
|
|
78
|
+
};
|
|
79
|
+
if (prefix === '@') {
|
|
80
|
+
const users = await api('users', { search: word.word }, ['_id', 'uname']);
|
|
81
|
+
return {
|
|
82
|
+
suggestions: users.map((i) => ({
|
|
83
|
+
label: { label: `@${i.uname}`, description: `UID=${i._id}` },
|
|
84
|
+
kind: monaco.languages.CompletionItemKind.Property,
|
|
85
|
+
documentation: { value: `[](#loader) })`, isTrusted: true },
|
|
86
|
+
insertText: `@[](/user/${i._id}) `,
|
|
87
|
+
range,
|
|
88
|
+
sortText: i.priv === 0 ? '0' : '1',
|
|
89
|
+
tags: i.priv === 0 ? [1] : [],
|
|
90
|
+
})),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
suggestions: prefix === ':' ? emoji(range) : qqEmoji(range),
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
2
|
+
|
|
3
|
+
const types = require.context('@types/node/', true, /\.d\.ts$/, 'lazy-once');
|
|
4
|
+
|
|
5
|
+
const diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions = {
|
|
6
|
+
noSemanticValidation: false,
|
|
7
|
+
noSyntaxValidation: false,
|
|
8
|
+
noSuggestionDiagnostics: true,
|
|
9
|
+
};
|
|
10
|
+
const compilerOptions: monaco.languages.typescript.CompilerOptions = {
|
|
11
|
+
target: monaco.languages.typescript.ScriptTarget.ES2020,
|
|
12
|
+
module: monaco.languages.typescript.ModuleKind.ESNext,
|
|
13
|
+
allowNonTsExtensions: true,
|
|
14
|
+
};
|
|
15
|
+
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions(diagnosticsOptions);
|
|
16
|
+
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions(diagnosticsOptions);
|
|
17
|
+
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions);
|
|
18
|
+
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(compilerOptions);
|
|
19
|
+
const libSource = [
|
|
20
|
+
'declare function readline(): string;',
|
|
21
|
+
'declare function print(content: string): void;',
|
|
22
|
+
].join('\n');
|
|
23
|
+
const libUri = 'ts:filename/basic.d.ts';
|
|
24
|
+
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
|
|
25
|
+
monaco.editor.createModel(libSource, 'typescript', monaco.Uri.parse(libUri));
|
|
26
|
+
const modules = [];
|
|
27
|
+
|
|
28
|
+
export async function loadTypes() {
|
|
29
|
+
for (const key of types.keys()) {
|
|
30
|
+
if (!key.startsWith('.')) continue;
|
|
31
|
+
const m = await types(key);
|
|
32
|
+
const val = m.replace('declare var require: NodeRequire;', '');
|
|
33
|
+
if (val.includes('declare module ')) {
|
|
34
|
+
modules.push(val.toString().split('declare module \'')[1].split('\'')[0]);
|
|
35
|
+
}
|
|
36
|
+
const uri = `ts:node/${key.split('./')[1]}`;
|
|
37
|
+
monaco.languages.typescript.javascriptDefaults.addExtraLib(val, uri);
|
|
38
|
+
monaco.editor.createModel(val, 'typescript', monaco.Uri.parse(uri));
|
|
39
|
+
}
|
|
40
|
+
let val = 'declare var require:';
|
|
41
|
+
for (const m of modules) val += `((id:'${m}')=>(typeof import('${m}')))&`;
|
|
42
|
+
val += '((id:string)=>any)';
|
|
43
|
+
monaco.languages.typescript.javascriptDefaults.addExtraLib(val, 'ts:node/require.d.ts');
|
|
44
|
+
monaco.editor.createModel(val, 'typescript', monaco.Uri.parse('ts:node/require.d.ts'));
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
|
2
|
+
import { configureMonacoYaml } from 'monaco-yaml';
|
|
3
|
+
import problemConfigSchema from '../schema/problemconfig';
|
|
4
|
+
|
|
5
|
+
configureMonacoYaml(monaco, {
|
|
6
|
+
validate: true,
|
|
7
|
+
enableSchemaRequest: true,
|
|
8
|
+
hover: true,
|
|
9
|
+
completion: true,
|
|
10
|
+
format: false,
|
|
11
|
+
schemas: [
|
|
12
|
+
{
|
|
13
|
+
uri: 'https://hydro.js.org/schema/problemConfig.json',
|
|
14
|
+
fileMatch: ['hydro://problem/file/config.yaml'],
|
|
15
|
+
schema: problemConfigSchema as any,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
uri: new URL('/manage/config/schema.json', window.location.href).toString(),
|
|
19
|
+
fileMatch: ['hydro://system/setting.yaml'],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|