@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,166 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import { InfoDialog } from 'vj/components/dialog';
|
|
3
|
+
import VjNotification from 'vj/components/notification/index';
|
|
4
|
+
import {
|
|
5
|
+
FLAG_ALERT, FLAG_I18N, FLAG_INFO, FLAG_RICHTEXT,
|
|
6
|
+
} from 'vj/constant/message';
|
|
7
|
+
import { AutoloadPage } from 'vj/misc/Page';
|
|
8
|
+
import { i18n, tpl } from 'vj/utils';
|
|
9
|
+
import Sock from '../socket';
|
|
10
|
+
|
|
11
|
+
let previous: VjNotification;
|
|
12
|
+
const processI18n = (msg) => {
|
|
13
|
+
if (msg.mdoc.flag & FLAG_I18N) {
|
|
14
|
+
try {
|
|
15
|
+
msg.mdoc.content = JSON.parse(msg.mdoc.content);
|
|
16
|
+
if (msg.mdoc.content.url) msg.mdoc.url = msg.mdoc.content.url;
|
|
17
|
+
if (msg.mdoc.content.avatar) msg.mdoc.avatar = msg.mdoc.content.avatar;
|
|
18
|
+
msg.mdoc.content = i18n(msg.mdoc.content.message, ...msg.mdoc.content.params);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
msg.mdoc.content = i18n(msg.mdoc.content);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return msg;
|
|
24
|
+
};
|
|
25
|
+
const onmessage = (msg) => {
|
|
26
|
+
console.log('Received message', msg);
|
|
27
|
+
msg = processI18n(msg);
|
|
28
|
+
if (msg.mdoc.flag & FLAG_ALERT) {
|
|
29
|
+
// Is alert
|
|
30
|
+
new InfoDialog({
|
|
31
|
+
cancelByClickingBack: false,
|
|
32
|
+
$body: tpl`
|
|
33
|
+
<div class="typo">
|
|
34
|
+
${{ templateRaw: true, html: i18n('Message from {0}:', `<div data-user>${msg.mdoc.from}</div>`) }}
|
|
35
|
+
<p>${i18n(msg.mdoc.content)}</p>
|
|
36
|
+
</div>`,
|
|
37
|
+
}).open();
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (msg.mdoc.flag & FLAG_INFO) {
|
|
41
|
+
if (previous) previous.hide();
|
|
42
|
+
previous = new VjNotification({
|
|
43
|
+
message: msg.mdoc.content,
|
|
44
|
+
duration: 3000,
|
|
45
|
+
});
|
|
46
|
+
previous.show();
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (document.hidden) return false;
|
|
50
|
+
// Is message
|
|
51
|
+
new VjNotification({
|
|
52
|
+
...(msg.udoc._id === 1)
|
|
53
|
+
? {
|
|
54
|
+
type: 'info',
|
|
55
|
+
message: msg.mdoc.flag & FLAG_RICHTEXT ? i18n('You received a system message, click here to view.') : msg.mdoc.content,
|
|
56
|
+
...(msg.mdoc.avatar ? { avatar: msg.mdoc.avatar } : {}),
|
|
57
|
+
} : {
|
|
58
|
+
title: msg.udoc.uname,
|
|
59
|
+
avatar: msg.udoc.avatarUrl,
|
|
60
|
+
message: msg.mdoc.content,
|
|
61
|
+
},
|
|
62
|
+
duration: 15000,
|
|
63
|
+
action: () => window.open(msg.mdoc.url ? msg.mdoc.url : `/home/messages?uid=${msg.udoc._id}`, '_blank'),
|
|
64
|
+
}).show();
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const initWorkerMode = (endpoint) => {
|
|
69
|
+
console.log('Messages: using SharedWorker');
|
|
70
|
+
const worker = new SharedWorker(new URL('./worker.ts', import.meta.url), { name: 'HydroMessagesWorker' });
|
|
71
|
+
worker.port.start();
|
|
72
|
+
window.addEventListener('beforeunload', () => {
|
|
73
|
+
worker.port.postMessage({ type: 'unload' });
|
|
74
|
+
});
|
|
75
|
+
worker.port.postMessage({ type: 'conn', path: endpoint, cookie: document.cookie });
|
|
76
|
+
worker.port.onmessage = async (message) => {
|
|
77
|
+
if (process.env.NODE_ENV !== 'production') console.log('onmessage: ', message);
|
|
78
|
+
const { payload, type } = message.data;
|
|
79
|
+
if (type === 'message') {
|
|
80
|
+
if (onmessage(payload)) worker.port.postMessage({ type: 'ack', id: payload.mdoc._id });
|
|
81
|
+
} else if (type === 'i18n') {
|
|
82
|
+
worker.port.postMessage({ type: 'ack', id: `${payload.mdoc._id}-i18n`, payload: processI18n(payload) });
|
|
83
|
+
} else if (type === 'open-page') {
|
|
84
|
+
console.log('opening page');
|
|
85
|
+
window.open('/home/messages');
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const messagePage = new AutoloadPage('messagePage', (pagename) => {
|
|
91
|
+
if (pagename === 'home_messages' || !UserContext._id) return;
|
|
92
|
+
if (UserContext.unreadMsg) {
|
|
93
|
+
new VjNotification({
|
|
94
|
+
type: 'info',
|
|
95
|
+
message: i18n(`You have ${UserContext.unreadMsg > 1 ? 'new messages' : 'a new message'}.`),
|
|
96
|
+
duration: 5000,
|
|
97
|
+
action: () => window.open('/home/messages', '_blank'),
|
|
98
|
+
}).show();
|
|
99
|
+
}
|
|
100
|
+
const url = new URL(`${UiContext.ws_prefix}websocket`, window.location.href);
|
|
101
|
+
const endpoint = url.toString().replace('http', 'ws');
|
|
102
|
+
if (window.SharedWorker) {
|
|
103
|
+
try {
|
|
104
|
+
initWorkerMode(endpoint);
|
|
105
|
+
return;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error('SharedWorker init fail: ', e.message);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!window.BroadcastChannel) {
|
|
111
|
+
console.error('BoardcastChannel not supported');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log('Messages: using BroadcastChannel');
|
|
116
|
+
let isMaster = false;
|
|
117
|
+
const selfId = nanoid();
|
|
118
|
+
const channel = new BroadcastChannel('hydro-messages');
|
|
119
|
+
const pages = JSON.parse(localStorage.getItem('pages') || '[]') as string[];
|
|
120
|
+
pages.push(selfId);
|
|
121
|
+
pages.sort();
|
|
122
|
+
localStorage.setItem('pages', JSON.stringify(pages));
|
|
123
|
+
|
|
124
|
+
window.onunload = () => {
|
|
125
|
+
const c = JSON.parse(localStorage.getItem('pages') || '[]') as string[];
|
|
126
|
+
localStorage.setItem('pages', JSON.stringify(c.filter((i) => i !== selfId)));
|
|
127
|
+
if (!isMaster) return;
|
|
128
|
+
localStorage.removeItem('page.master');
|
|
129
|
+
channel.postMessage({ type: 'master' });
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
function asMaster() {
|
|
133
|
+
console.log('init as master');
|
|
134
|
+
isMaster = true;
|
|
135
|
+
localStorage.setItem('page.master', selfId);
|
|
136
|
+
const masterChannel = new BroadcastChannel('hydro-messages');
|
|
137
|
+
const sock = new Sock(endpoint);
|
|
138
|
+
sock.onopen = () => {
|
|
139
|
+
sock.send(JSON.stringify({
|
|
140
|
+
operation: 'subscribe',
|
|
141
|
+
request_id: Math.random().toString(16).substring(2),
|
|
142
|
+
credential: document.cookie.split('sid=')[1].split(';')[0],
|
|
143
|
+
channels: ['message'],
|
|
144
|
+
}));
|
|
145
|
+
};
|
|
146
|
+
sock.onmessage = async (message) => {
|
|
147
|
+
const payload = JSON.parse(message.data);
|
|
148
|
+
if (payload.operation === 'event') {
|
|
149
|
+
masterChannel.postMessage({ type: 'message', payload: payload.payload });
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
channel.onmessage = (msg) => {
|
|
155
|
+
if (msg.data.type === 'message' && !document.hidden) {
|
|
156
|
+
onmessage(msg.data.payload);
|
|
157
|
+
}
|
|
158
|
+
if (msg.data.type === 'master') {
|
|
159
|
+
const c = JSON.parse(localStorage.getItem('pages') || '[]') as string[];
|
|
160
|
+
if (c[0] === selfId) asMaster();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
if (!localStorage.getItem('page.master')) asMaster();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export default messagePage;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference no-default-lib="true" />
|
|
2
|
+
/// <reference lib="webworker" />
|
|
3
|
+
import ReconnectingWebsocket from 'reconnecting-websocket';
|
|
4
|
+
import { FLAG_I18N, FLAG_INFO } from 'vj/constant/message';
|
|
5
|
+
declare const self: SharedWorkerGlobalScope;
|
|
6
|
+
|
|
7
|
+
console.log('SharedWorker init');
|
|
8
|
+
|
|
9
|
+
let conn: ReconnectingWebsocket;
|
|
10
|
+
let lcookie: string;
|
|
11
|
+
const ports: Set<MessagePort> = new Set();
|
|
12
|
+
interface RequestInitSharedConnPayload {
|
|
13
|
+
type: 'conn';
|
|
14
|
+
cookie: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
interface RequestAckPayload {
|
|
18
|
+
type: 'ack';
|
|
19
|
+
id: string;
|
|
20
|
+
payload?: any;
|
|
21
|
+
}
|
|
22
|
+
interface RequestUnloadPayload {
|
|
23
|
+
type: 'unload';
|
|
24
|
+
}
|
|
25
|
+
type RequestPayload = RequestInitSharedConnPayload | RequestAckPayload | RequestUnloadPayload;
|
|
26
|
+
const ack = {};
|
|
27
|
+
|
|
28
|
+
function broadcastMsg(message: any) {
|
|
29
|
+
for (const p of ports) p.postMessage(message);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function onMessage(message: any) {
|
|
33
|
+
broadcastMsg({ type: 'message', payload: message });
|
|
34
|
+
let acked = false;
|
|
35
|
+
let payload = message;
|
|
36
|
+
ack[message.mdoc._id] = () => { acked = true; };
|
|
37
|
+
ack[`${message.mdoc._id}-i18n`] = (v) => { payload = v; };
|
|
38
|
+
if (message.mdoc.flag & FLAG_I18N) broadcastMsg({ type: 'i18n', payload: message });
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
delete ack[message.mdoc._id];
|
|
41
|
+
delete ack[`${message.mdoc._id}-i18n`];
|
|
42
|
+
if (acked) return;
|
|
43
|
+
if (message.mdoc.flag & FLAG_INFO) return;
|
|
44
|
+
if (Notification?.permission !== 'granted') {
|
|
45
|
+
console.log('Notification permission denied');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log('Sending as system notification');
|
|
49
|
+
// eslint-disable-next-line no-new
|
|
50
|
+
new Notification(
|
|
51
|
+
payload.udoc._id === 1 ? payload.mdoc.content.split('\n')[0] : payload.udoc.uname || 'Hydro Notification',
|
|
52
|
+
payload.udoc._id === 1 ? {
|
|
53
|
+
tag: `notification-${payload.mdoc._id}`,
|
|
54
|
+
icon: payload.mdoc.avatar || '/android-chrome-192x192.png',
|
|
55
|
+
body: payload.mdoc.content.split('\n').slice(1).join('\n'),
|
|
56
|
+
} : {
|
|
57
|
+
tag: `message-${payload.mdoc._id}`,
|
|
58
|
+
icon: payload.udoc.avatarUrl || '/android-chrome-192x192.png',
|
|
59
|
+
body: payload.mdoc.content,
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
}, 3000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function initConn(path: string, port: MessagePort, cookie: any) {
|
|
66
|
+
ports.add(port);
|
|
67
|
+
console.log('Init connection');
|
|
68
|
+
lcookie = cookie.split('sid=')[1].split(';')[0];
|
|
69
|
+
if (conn) return;
|
|
70
|
+
const url = new URL(path, location.origin);
|
|
71
|
+
conn = new ReconnectingWebsocket(url.toString().replace('http', 'ws'));
|
|
72
|
+
conn.onopen = () => {
|
|
73
|
+
console.log('Connected');
|
|
74
|
+
broadcastMsg({ type: 'open' });
|
|
75
|
+
conn.send(JSON.stringify({
|
|
76
|
+
operation: 'subscribe',
|
|
77
|
+
request_id: Math.random().toString(16).substring(2),
|
|
78
|
+
credential: lcookie,
|
|
79
|
+
channels: ['message'],
|
|
80
|
+
}));
|
|
81
|
+
};
|
|
82
|
+
conn.onerror = () => broadcastMsg({ type: 'error' });
|
|
83
|
+
conn.onclose = (ev) => broadcastMsg({ type: 'close', error: ev.reason });
|
|
84
|
+
conn.onmessage = (message) => {
|
|
85
|
+
if (process.env.NODE_ENV !== 'production') console.log('SharedWorker.port.onmessage: ', message);
|
|
86
|
+
if (message.data === 'ping') {
|
|
87
|
+
conn.send('pong');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const payload = JSON.parse(message.data);
|
|
91
|
+
if (['PermissionError', 'PrivilegeError'].includes(payload.error)) {
|
|
92
|
+
broadcastMsg({ type: 'close', error: payload.error });
|
|
93
|
+
conn.close();
|
|
94
|
+
} else if (payload.operation === 'event') {
|
|
95
|
+
onMessage(payload.payload);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
self.onconnect = function (e) {
|
|
101
|
+
const port = e.ports[0];
|
|
102
|
+
|
|
103
|
+
port.addEventListener('message', (msg: { data: RequestPayload }) => {
|
|
104
|
+
if (msg.data.type === 'conn') initConn(msg.data.path, port, msg.data.cookie);
|
|
105
|
+
if (msg.data.type === 'ack') ack[msg.data.id]?.(msg.data.payload);
|
|
106
|
+
if (msg.data.type === 'unload') ports.delete(port);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
port.start();
|
|
110
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
$stripe-width = 2px
|
|
2
|
+
|
|
3
|
+
.messagepad__list-item
|
|
4
|
+
display: block
|
|
5
|
+
padding: rem(20px $section-gap-h 20px ($section-gap-h - $stripe-width))
|
|
6
|
+
border-left: $stripe-width solid transparent
|
|
7
|
+
cursor: pointer
|
|
8
|
+
transition: border-color .1s linear, background-color .1s linear
|
|
9
|
+
overflow: hidden
|
|
10
|
+
text-overflow: ellipsis
|
|
11
|
+
|
|
12
|
+
&:hover
|
|
13
|
+
border-color: #DDD
|
|
14
|
+
background: #F4F4F4
|
|
15
|
+
text-decoration: none
|
|
16
|
+
|
|
17
|
+
&.active
|
|
18
|
+
border-color: $secondary-color
|
|
19
|
+
background: rgba($secondary-color, 0.07)
|
|
20
|
+
|
|
21
|
+
.messagepad__desc
|
|
22
|
+
font-size: rem($font-size-small)
|
|
23
|
+
color: #888
|
|
24
|
+
max-height: 2em
|
|
25
|
+
margin-top: rem(5px)
|
|
26
|
+
overflow: hidden
|
|
27
|
+
text-overflow: ellipsis
|
|
28
|
+
word-wrap()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
export default function DialogueListItemComponent(props) {
|
|
5
|
+
const {
|
|
6
|
+
userName,
|
|
7
|
+
summary,
|
|
8
|
+
faceUrl,
|
|
9
|
+
active,
|
|
10
|
+
onClick,
|
|
11
|
+
className,
|
|
12
|
+
...rest
|
|
13
|
+
} = props;
|
|
14
|
+
const cn = classNames(className, 'messagepad__list-item media', {
|
|
15
|
+
active,
|
|
16
|
+
});
|
|
17
|
+
return (
|
|
18
|
+
<li {...rest}>
|
|
19
|
+
<a className={cn} onClick={onClick}>
|
|
20
|
+
<div className="media__left middle">
|
|
21
|
+
<img src={faceUrl} alt="avatar" width="50" height="50" className="medium user-profile-avatar" />
|
|
22
|
+
</div>
|
|
23
|
+
<div className="media__body middle">
|
|
24
|
+
<h3 className="messagepad__username">{userName}</h3>
|
|
25
|
+
<div className="messagepad__desc">{summary}</div>
|
|
26
|
+
</div>
|
|
27
|
+
</a>
|
|
28
|
+
</li>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
DialogueListItemComponent.propTypes = {
|
|
33
|
+
userName: PropTypes.string.isRequired,
|
|
34
|
+
summary: PropTypes.string.isRequired,
|
|
35
|
+
faceUrl: PropTypes.string.isRequired,
|
|
36
|
+
active: PropTypes.bool,
|
|
37
|
+
onClick: PropTypes.func,
|
|
38
|
+
className: PropTypes.string,
|
|
39
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
$corner-size = 10px
|
|
2
|
+
|
|
3
|
+
.messagepad__message
|
|
4
|
+
overflow: hidden
|
|
5
|
+
display: flex
|
|
6
|
+
margin-bottom: rem(30px)
|
|
7
|
+
|
|
8
|
+
&:last-child
|
|
9
|
+
margin-bottom: 0
|
|
10
|
+
|
|
11
|
+
&.side--self
|
|
12
|
+
justify-content: flex-end
|
|
13
|
+
|
|
14
|
+
.messagepad__message__body
|
|
15
|
+
font-size: rem($font-size-secondary)
|
|
16
|
+
line-height: 1.5
|
|
17
|
+
padding: rem(15px)
|
|
18
|
+
margin-bottom: rem(8px)
|
|
19
|
+
position: relative
|
|
20
|
+
min-width: rem(100px)
|
|
21
|
+
white-space: pre-wrap
|
|
22
|
+
word-wrap()
|
|
23
|
+
|
|
24
|
+
time
|
|
25
|
+
opacity: 0.6
|
|
26
|
+
font-size: rem($font-size-small)
|
|
27
|
+
|
|
28
|
+
&:after
|
|
29
|
+
position: absolute
|
|
30
|
+
width: 0
|
|
31
|
+
height: 0
|
|
32
|
+
content: ''
|
|
33
|
+
top: 0
|
|
34
|
+
|
|
35
|
+
.side--other
|
|
36
|
+
.messagepad__message__body
|
|
37
|
+
margin-left: rem($corner-size + 10px)
|
|
38
|
+
background: $primary-color
|
|
39
|
+
color: #FFF
|
|
40
|
+
order: 1
|
|
41
|
+
|
|
42
|
+
&:after
|
|
43
|
+
left: rem(-($corner-size))
|
|
44
|
+
border-top: $corner-size solid $primary-color
|
|
45
|
+
border-right: 0 solid transparent
|
|
46
|
+
border-bottom: 0 solid transparent
|
|
47
|
+
border-left: $corner-size solid transparent
|
|
48
|
+
|
|
49
|
+
.side--self
|
|
50
|
+
.messagepad__message__body
|
|
51
|
+
margin-right: rem($corner-size + 10px)
|
|
52
|
+
background: #F0F0F0
|
|
53
|
+
color: #222
|
|
54
|
+
order: -1
|
|
55
|
+
|
|
56
|
+
time
|
|
57
|
+
text-align: right
|
|
58
|
+
|
|
59
|
+
&:after
|
|
60
|
+
right: rem(-($corner-size))
|
|
61
|
+
border-top: $corner-size solid #F0F0F0
|
|
62
|
+
border-right: $corner-size solid transparent
|
|
63
|
+
border-bottom: 0 solid transparent
|
|
64
|
+
border-left: 0 solid transparent
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
export default function MessageComponent(props) {
|
|
5
|
+
const {
|
|
6
|
+
faceUrl,
|
|
7
|
+
isSelf,
|
|
8
|
+
className,
|
|
9
|
+
children,
|
|
10
|
+
...rest
|
|
11
|
+
} = props;
|
|
12
|
+
const cn = classNames(className, 'messagepad__message', {
|
|
13
|
+
'side--self': isSelf,
|
|
14
|
+
'side--other': !isSelf,
|
|
15
|
+
});
|
|
16
|
+
return (
|
|
17
|
+
<li {...rest} className={cn}>
|
|
18
|
+
<div className="messagepad__message__avatar">
|
|
19
|
+
<img src={faceUrl} alt="avatar" width="50" height="50" className="medium user-profile-avatar" />
|
|
20
|
+
</div>
|
|
21
|
+
<div className="messagepad__message__body">
|
|
22
|
+
{children}
|
|
23
|
+
</div>
|
|
24
|
+
</li>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
MessageComponent.propTypes = {
|
|
29
|
+
isSelf: PropTypes.bool,
|
|
30
|
+
faceUrl: PropTypes.string.isRequired,
|
|
31
|
+
className: PropTypes.string,
|
|
32
|
+
children: PropTypes.node,
|
|
33
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
$list-height = 500px
|
|
2
|
+
$sidebar-width = 250px
|
|
3
|
+
$input-height = 80px
|
|
4
|
+
$input-padding = 10px
|
|
5
|
+
$send-button-width = 50px
|
|
6
|
+
|
|
7
|
+
#messagePad
|
|
8
|
+
min-height: rem($list-height)
|
|
9
|
+
position: relative
|
|
10
|
+
|
|
11
|
+
.messagepad
|
|
12
|
+
position: relative
|
|
13
|
+
|
|
14
|
+
.messagepad__sidebar
|
|
15
|
+
border-right: 1px solid #EEE
|
|
16
|
+
float: left
|
|
17
|
+
width: rem($sidebar-width)
|
|
18
|
+
|
|
19
|
+
.messagepad__list
|
|
20
|
+
overflow: auto
|
|
21
|
+
height: rem($list-height)
|
|
22
|
+
|
|
23
|
+
.messagepad__header
|
|
24
|
+
position: absolute
|
|
25
|
+
left: rem($sidebar-width)
|
|
26
|
+
right: 0
|
|
27
|
+
top: 0
|
|
28
|
+
height: rem(30px)
|
|
29
|
+
padding: rem(5px)
|
|
30
|
+
text-align: center
|
|
31
|
+
border-bottom: 1px solid #eee;
|
|
32
|
+
|
|
33
|
+
.messagepad__content
|
|
34
|
+
position: absolute
|
|
35
|
+
left: rem($sidebar-width)
|
|
36
|
+
right: 0
|
|
37
|
+
top: rem(30px)
|
|
38
|
+
bottom: rem($input-height)
|
|
39
|
+
overflow: auto
|
|
40
|
+
padding: rem(30px)
|
|
41
|
+
|
|
42
|
+
.messagepad__input
|
|
43
|
+
display: none
|
|
44
|
+
position: absolute
|
|
45
|
+
left: rem($sidebar-width)
|
|
46
|
+
right: 0
|
|
47
|
+
bottom: 0
|
|
48
|
+
height: $input-height
|
|
49
|
+
border-top: 1px solid #EEE
|
|
50
|
+
|
|
51
|
+
&.visible
|
|
52
|
+
display: block
|
|
53
|
+
|
|
54
|
+
button
|
|
55
|
+
display: block
|
|
56
|
+
appearance: none
|
|
57
|
+
position: absolute
|
|
58
|
+
right: 0
|
|
59
|
+
width: rem($send-button-width)
|
|
60
|
+
top: 0
|
|
61
|
+
height: 100%
|
|
62
|
+
border: 0
|
|
63
|
+
background: none
|
|
64
|
+
text-align: center
|
|
65
|
+
line-height: rem($input-height)
|
|
66
|
+
font-size: rem($font-size-icon)
|
|
67
|
+
transition: background-color .1s, color .1s, opacity .1s
|
|
68
|
+
transition-timing-function: linear
|
|
69
|
+
outline: 0
|
|
70
|
+
|
|
71
|
+
&:enabled
|
|
72
|
+
cursor: pointer
|
|
73
|
+
background-color: $primary-color
|
|
74
|
+
color: #FFF
|
|
75
|
+
|
|
76
|
+
&:hover
|
|
77
|
+
background-color: lighten($primary-color, 10%)
|
|
78
|
+
|
|
79
|
+
&:disabled
|
|
80
|
+
color: $text-1-color
|
|
81
|
+
opacity: 0.3
|
|
82
|
+
|
|
83
|
+
.messagepad__textarea-container
|
|
84
|
+
position: absolute
|
|
85
|
+
left: rem($input-padding)
|
|
86
|
+
right: rem($send-button-width + $input-padding)
|
|
87
|
+
top: rem($input-padding)
|
|
88
|
+
bottom: rem($input-padding)
|
|
89
|
+
|
|
90
|
+
textarea
|
|
91
|
+
display: block
|
|
92
|
+
border: 0
|
|
93
|
+
background: none
|
|
94
|
+
padding: 0
|
|
95
|
+
width: 100%
|
|
96
|
+
height: 100%
|
|
97
|
+
font-size: rem($font-size-secondary)
|
|
98
|
+
resize: none
|
|
99
|
+
outline: 0
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import 'jquery.easing';
|
|
2
|
+
|
|
3
|
+
import $ from 'jquery';
|
|
4
|
+
import moment from 'moment';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { connect } from 'react-redux';
|
|
7
|
+
import TimeAgo from 'timeago-react';
|
|
8
|
+
import { i18n, mongoId } from 'vj/utils';
|
|
9
|
+
import Message from './MessageComponent';
|
|
10
|
+
|
|
11
|
+
const mapStateToProps = (state) => ({
|
|
12
|
+
activeId: state.activeId,
|
|
13
|
+
item: state.activeId !== null
|
|
14
|
+
? state.dialogues[state.activeId]
|
|
15
|
+
: null,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default connect(mapStateToProps)(class MessagePadDialogueContentContainer extends React.PureComponent {
|
|
19
|
+
componentDidUpdate(prevProps) {
|
|
20
|
+
const node = this.state.ref;
|
|
21
|
+
|
|
22
|
+
if (this.props.activeId !== prevProps.activeId) {
|
|
23
|
+
this.scrollToBottom = true;
|
|
24
|
+
this.scrollWithAnimation = false;
|
|
25
|
+
} else if (Math.abs(node.scrollTop + node.offsetHeight - node.scrollHeight) < 200) {
|
|
26
|
+
this.scrollToBottom = true;
|
|
27
|
+
this.scrollWithAnimation = true;
|
|
28
|
+
} else this.scrollToBottom = false;
|
|
29
|
+
|
|
30
|
+
if (!node) return;
|
|
31
|
+
if (this.scrollToBottom) {
|
|
32
|
+
const targetScrollTop = node.scrollHeight - node.offsetHeight;
|
|
33
|
+
if (this.scrollWithAnimation) {
|
|
34
|
+
$(node).stop().animate({ scrollTop: targetScrollTop }, 200, 'easeOutCubic');
|
|
35
|
+
} else {
|
|
36
|
+
node.scrollTop = targetScrollTop;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
renderContent(msg) {
|
|
42
|
+
// TODO: FLAG_RICHTEXT
|
|
43
|
+
if (msg.from === 1) {
|
|
44
|
+
// Is system message
|
|
45
|
+
try {
|
|
46
|
+
const data = JSON.parse(msg.content);
|
|
47
|
+
const str = i18n(data.message).replace(/\{([^{}]+)\}/g, (match, key) => `%placeholder%${key}%placeholder%`);
|
|
48
|
+
const arr = str.split('%placeholder%');
|
|
49
|
+
data.params ||= {};
|
|
50
|
+
for (let i = 1; i < arr.length; i += 2) {
|
|
51
|
+
if (arr[i].endsWith(':link')) {
|
|
52
|
+
const link = data.params[arr[i].split(':link')[0]];
|
|
53
|
+
if (!link) continue;
|
|
54
|
+
arr[i] = <a style={{ color: 'wheat' }} href={link} key={i} target="_blank" rel="noreferrer">{link}</a>;
|
|
55
|
+
} else {
|
|
56
|
+
arr[i] = <span style={{ color: 'wheat' }} key={i}>{data.params[arr[i]]}</span>;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return arr;
|
|
60
|
+
} catch (e) { }
|
|
61
|
+
return i18n(msg.content);
|
|
62
|
+
}
|
|
63
|
+
return msg.content;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
renderInner() {
|
|
67
|
+
if (this.props.activeId === null) return [];
|
|
68
|
+
const sorted = this.props.item.messages
|
|
69
|
+
.sort((msg1, msg2) => mongoId(msg1._id).timestamp - mongoId(msg2._id).timestamp);
|
|
70
|
+
return sorted.map((msg) => (
|
|
71
|
+
<Message
|
|
72
|
+
key={msg._id}
|
|
73
|
+
isSelf={msg.from === UserContext._id}
|
|
74
|
+
faceUrl={
|
|
75
|
+
msg.from === UserContext._id
|
|
76
|
+
? UserContext.avatarUrl
|
|
77
|
+
: this.props.item.udoc.avatarUrl
|
|
78
|
+
}
|
|
79
|
+
>
|
|
80
|
+
<div>{this.renderContent(msg)}</div>
|
|
81
|
+
<time data-tooltip={moment(mongoId(msg._id).timestamp * 1000).format('YYYY-MM-DD HH:mm:ss')}>
|
|
82
|
+
<TimeAgo datetime={mongoId(msg._id).timestamp * 1000} locale={i18n('timeago_locale')} />
|
|
83
|
+
</time>
|
|
84
|
+
</Message>
|
|
85
|
+
));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
render() {
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<div className="messagepad__header">
|
|
92
|
+
{this.props.item && (
|
|
93
|
+
<a className="messagepad__content__header__title" href={`/user/${this.props.item.udoc._id}`}>
|
|
94
|
+
{`${this.props.item.udoc.uname}(UID: ${this.props.item.udoc._id})`}
|
|
95
|
+
</a>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
98
|
+
<ol className="messagepad__content" style={{ overscrollBehavior: 'contain' }} ref={(ref) => { this.setState({ ...this.state, ref }); }}>
|
|
99
|
+
{this.renderInner()}
|
|
100
|
+
</ol>
|
|
101
|
+
</>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { connect } from 'react-redux';
|
|
4
|
+
import { i18n } from 'vj/utils';
|
|
5
|
+
import ListItem from './DialogueListItemComponent';
|
|
6
|
+
|
|
7
|
+
const mapStateToProps = (state) => ({
|
|
8
|
+
activeId: state.activeId,
|
|
9
|
+
dialogues: state.dialogues,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const mapDispatchToProps = (dispatch) => ({
|
|
13
|
+
handleClick(id) {
|
|
14
|
+
dispatch({
|
|
15
|
+
type: 'DIALOGUES_SWITCH_TO',
|
|
16
|
+
payload: id,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default connect(mapStateToProps, mapDispatchToProps)(class MessagePadDialogueListContainer extends React.PureComponent {
|
|
22
|
+
render() {
|
|
23
|
+
const orderedDialogues = _.orderBy(
|
|
24
|
+
_.values(this.props.dialogues),
|
|
25
|
+
(dialogue) => (_.maxBy(dialogue.messages, '_id')
|
|
26
|
+
? _.maxBy(dialogue.messages, '_id')._id
|
|
27
|
+
: Number.POSITIVE_INFINITY),
|
|
28
|
+
'desc',
|
|
29
|
+
);
|
|
30
|
+
return (
|
|
31
|
+
<ol className="messagepad__list" style={{ overscrollBehavior: 'contain' }}>
|
|
32
|
+
{_.map(orderedDialogues, (dialogue) => (
|
|
33
|
+
<ListItem
|
|
34
|
+
key={dialogue._id}
|
|
35
|
+
userName={dialogue.udoc.uname}
|
|
36
|
+
summary={dialogue.messages.length
|
|
37
|
+
? (_.maxBy(dialogue.messages, '_id').flag & 4)
|
|
38
|
+
? i18n('[Richtext message]')
|
|
39
|
+
: _.maxBy(dialogue.messages, '_id').content
|
|
40
|
+
: ''}
|
|
41
|
+
faceUrl={dialogue.udoc.avatarUrl}
|
|
42
|
+
active={dialogue._id === this.props.activeId}
|
|
43
|
+
onClick={() => this.props.handleClick(dialogue._id)}
|
|
44
|
+
/>
|
|
45
|
+
))}
|
|
46
|
+
</ol>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
});
|