@peers-app/peers-ui 0.0.14
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/.github/README.md +52 -0
- package/.github/workflows/publish.yml +45 -0
- package/babel.config.js +7 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.js +54 -0
- package/dist/command-palette/command-palette-ui.d.ts +2 -0
- package/dist/command-palette/command-palette-ui.js +192 -0
- package/dist/command-palette/command-palette.d.ts +23 -0
- package/dist/command-palette/command-palette.js +371 -0
- package/dist/components/checkbox.d.ts +7 -0
- package/dist/components/checkbox.js +20 -0
- package/dist/components/group-switcher.d.ts +6 -0
- package/dist/components/group-switcher.js +301 -0
- package/dist/components/input-date.d.ts +7 -0
- package/dist/components/input-date.js +19 -0
- package/dist/components/input-datetime.d.ts +7 -0
- package/dist/components/input-datetime.js +35 -0
- package/dist/components/input-number.d.ts +9 -0
- package/dist/components/input-number.js +87 -0
- package/dist/components/input.d.ts +7 -0
- package/dist/components/input.js +20 -0
- package/dist/components/io-schema-values.d.ts +15 -0
- package/dist/components/io-schema-values.js +105 -0
- package/dist/components/io-schema.d.ts +13 -0
- package/dist/components/io-schema.js +163 -0
- package/dist/components/lazy-list.d.ts +13 -0
- package/dist/components/lazy-list.js +91 -0
- package/dist/components/lazy-sortable-list.d.ts +29 -0
- package/dist/components/lazy-sortable-list.js +12 -0
- package/dist/components/left-bar.d.ts +3 -0
- package/dist/components/left-bar.js +130 -0
- package/dist/components/list-screen.d.ts +16 -0
- package/dist/components/list-screen.js +100 -0
- package/dist/components/loading-indicator.d.ts +2 -0
- package/dist/components/loading-indicator.js +12 -0
- package/dist/components/main-content-container.d.ts +2 -0
- package/dist/components/main-content-container.js +90 -0
- package/dist/components/markdown-editor/autolink-plugin.d.ts +2 -0
- package/dist/components/markdown-editor/autolink-plugin.js +29 -0
- package/dist/components/markdown-editor/editor-inline.d.ts +3 -0
- package/dist/components/markdown-editor/editor-inline.js +13 -0
- package/dist/components/markdown-editor/editor.d.ts +18 -0
- package/dist/components/markdown-editor/editor.js +143 -0
- package/dist/components/markdown-editor/markdown-plugin.d.ts +9 -0
- package/dist/components/markdown-editor/markdown-plugin.js +194 -0
- package/dist/components/markdown-editor/mention-node.d.ts +21 -0
- package/dist/components/markdown-editor/mention-node.js +160 -0
- package/dist/components/markdown-editor/mentions-plugin.d.ts +7 -0
- package/dist/components/markdown-editor/mentions-plugin.js +268 -0
- package/dist/components/markdown-editor/theme.d.ts +46 -0
- package/dist/components/markdown-editor/theme.js +48 -0
- package/dist/components/markdown-editor/toolbar.d.ts +10 -0
- package/dist/components/markdown-editor/toolbar.js +112 -0
- package/dist/components/markdown-with-mentions.d.ts +4 -0
- package/dist/components/markdown-with-mentions.js +140 -0
- package/dist/components/message-logs/message-logs.d.ts +6 -0
- package/dist/components/message-logs/message-logs.js +307 -0
- package/dist/components/messages/avatar.d.ts +10 -0
- package/dist/components/messages/avatar.js +65 -0
- package/dist/components/messages/channel-message-list.d.ts +14 -0
- package/dist/components/messages/channel-message-list.js +158 -0
- package/dist/components/messages/channel-view.d.ts +6 -0
- package/dist/components/messages/channel-view.js +82 -0
- package/dist/components/messages/message-compose.d.ts +11 -0
- package/dist/components/messages/message-compose.js +152 -0
- package/dist/components/messages/message-display.d.ts +10 -0
- package/dist/components/messages/message-display.js +152 -0
- package/dist/components/messages/thread-message-list.d.ts +11 -0
- package/dist/components/messages/thread-message-list.js +122 -0
- package/dist/components/messages/thread-view.d.ts +6 -0
- package/dist/components/messages/thread-view.js +174 -0
- package/dist/components/off-canvas.d.ts +13 -0
- package/dist/components/off-canvas.js +89 -0
- package/dist/components/router.d.ts +6 -0
- package/dist/components/router.js +240 -0
- package/dist/components/save-button.d.ts +13 -0
- package/dist/components/save-button.js +75 -0
- package/dist/components/sortable-list.d.ts +36 -0
- package/dist/components/sortable-list.js +77 -0
- package/dist/components/tabs.d.ts +11 -0
- package/dist/components/tabs.js +69 -0
- package/dist/components/text-list-editor.tsx/text-list-editor.d.ts +6 -0
- package/dist/components/text-list-editor.tsx/text-list-editor.js +13 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/components/tooltip.js +20 -0
- package/dist/components/top-bar.d.ts +2 -0
- package/dist/components/top-bar.js +51 -0
- package/dist/components/typeahead/mentions-plugin.d.ts +7 -0
- package/dist/components/typeahead/mentions-plugin.js +203 -0
- package/dist/components/typeahead/typeahead-editor.d.ts +15 -0
- package/dist/components/typeahead/typeahead-editor.js +134 -0
- package/dist/components/typeahead/typeahead.d.ts +12 -0
- package/dist/components/typeahead/typeahead.js +94 -0
- package/dist/components/typeahead.d.ts +22 -0
- package/dist/components/typeahead.js +270 -0
- package/dist/globals.d.ts +29 -0
- package/dist/globals.js +148 -0
- package/dist/hooks.d.ts +34 -0
- package/dist/hooks.js +137 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/layout-vars.d.ts +6 -0
- package/dist/layout-vars.js +10 -0
- package/dist/mention-configs.d.ts +18 -0
- package/dist/mention-configs.js +149 -0
- package/dist/screens/assistants/assistant-config.d.ts +5 -0
- package/dist/screens/assistants/assistant-config.js +52 -0
- package/dist/screens/assistants/assistant-details.d.ts +4 -0
- package/dist/screens/assistants/assistant-details.js +85 -0
- package/dist/screens/assistants/assistant-info.d.ts +6 -0
- package/dist/screens/assistants/assistant-info.js +28 -0
- package/dist/screens/assistants/assistant-list.d.ts +2 -0
- package/dist/screens/assistants/assistant-list.js +114 -0
- package/dist/screens/assistants/assistant-tools.d.ts +5 -0
- package/dist/screens/assistants/assistant-tools.js +38 -0
- package/dist/screens/contacts/contact-details.d.ts +6 -0
- package/dist/screens/contacts/contact-details.js +100 -0
- package/dist/screens/contacts/contact-list.d.ts +2 -0
- package/dist/screens/contacts/contact-list.js +213 -0
- package/dist/screens/contacts/index.d.ts +4 -0
- package/dist/screens/contacts/index.js +21 -0
- package/dist/screens/events/cron.d.ts +3 -0
- package/dist/screens/events/cron.js +77 -0
- package/dist/screens/events/event-details.d.ts +6 -0
- package/dist/screens/events/event-details.js +112 -0
- package/dist/screens/events/event-handlers.d.ts +7 -0
- package/dist/screens/events/event-handlers.js +84 -0
- package/dist/screens/events/event-info.d.ts +5 -0
- package/dist/screens/events/event-info.js +19 -0
- package/dist/screens/events/event-list.d.ts +2 -0
- package/dist/screens/events/event-list.js +107 -0
- package/dist/screens/events/event-schedule.d.ts +5 -0
- package/dist/screens/events/event-schedule.js +124 -0
- package/dist/screens/groups/group-details.d.ts +6 -0
- package/dist/screens/groups/group-details.js +218 -0
- package/dist/screens/groups/group-list.d.ts +2 -0
- package/dist/screens/groups/group-list.js +275 -0
- package/dist/screens/groups/group-members.d.ts +8 -0
- package/dist/screens/groups/group-members.js +315 -0
- package/dist/screens/groups/index.d.ts +6 -0
- package/dist/screens/groups/index.js +23 -0
- package/dist/screens/knowledge/knowledge-frame-details.bk.d.ts +6 -0
- package/dist/screens/knowledge/knowledge-frame-details.bk.js +84 -0
- package/dist/screens/knowledge/knowledge-frame-details.d.ts +8 -0
- package/dist/screens/knowledge/knowledge-frame-details.js +143 -0
- package/dist/screens/knowledge/knowledge-frame-list.d.ts +2 -0
- package/dist/screens/knowledge/knowledge-frame-list.js +45 -0
- package/dist/screens/knowledge/knowledge-value-details.d.ts +6 -0
- package/dist/screens/knowledge/knowledge-value-details.js +150 -0
- package/dist/screens/knowledge/knowledge-value-list-item.d.ts +5 -0
- package/dist/screens/knowledge/knowledge-value-list-item.js +39 -0
- package/dist/screens/knowledge/knowledge-value-list.d.ts +3 -0
- package/dist/screens/knowledge/knowledge-value-list.js +123 -0
- package/dist/screens/packages/package-details.d.ts +6 -0
- package/dist/screens/packages/package-details.js +82 -0
- package/dist/screens/packages/package-info.d.ts +5 -0
- package/dist/screens/packages/package-info.js +42 -0
- package/dist/screens/packages/package-list.d.ts +2 -0
- package/dist/screens/packages/package-list.js +182 -0
- package/dist/screens/packages/package-new-local.d.ts +2 -0
- package/dist/screens/packages/package-new-local.js +82 -0
- package/dist/screens/peer-types/peer-type-details.d.ts +10 -0
- package/dist/screens/peer-types/peer-type-details.js +126 -0
- package/dist/screens/peer-types/peer-type-list.d.ts +2 -0
- package/dist/screens/peer-types/peer-type-list.js +57 -0
- package/dist/screens/predicates/predicate-details.d.ts +6 -0
- package/dist/screens/predicates/predicate-details.js +103 -0
- package/dist/screens/predicates/predicate-list.d.ts +2 -0
- package/dist/screens/predicates/predicate-list.js +46 -0
- package/dist/screens/profile.d.ts +2 -0
- package/dist/screens/profile.js +66 -0
- package/dist/screens/search/global-search.d.ts +2 -0
- package/dist/screens/search/global-search.js +186 -0
- package/dist/screens/settings/color-mode-dropdown.d.ts +6 -0
- package/dist/screens/settings/color-mode-dropdown.js +63 -0
- package/dist/screens/settings/settings-page.d.ts +2 -0
- package/dist/screens/settings/settings-page.js +49 -0
- package/dist/screens/setup-user.d.ts +2 -0
- package/dist/screens/setup-user.js +270 -0
- package/dist/screens/tools/tool-code.d.ts +5 -0
- package/dist/screens/tools/tool-code.js +32 -0
- package/dist/screens/tools/tool-details.d.ts +6 -0
- package/dist/screens/tools/tool-details.js +68 -0
- package/dist/screens/tools/tool-info.d.ts +5 -0
- package/dist/screens/tools/tool-info.js +74 -0
- package/dist/screens/tools/tool-list.d.ts +2 -0
- package/dist/screens/tools/tool-list.js +123 -0
- package/dist/screens/tools/tool-schema.d.ts +5 -0
- package/dist/screens/tools/tool-schema.js +30 -0
- package/dist/screens/tools/tool-test-details.d.ts +4 -0
- package/dist/screens/tools/tool-test-details.js +54 -0
- package/dist/screens/tools/tool-test-list.d.ts +4 -0
- package/dist/screens/tools/tool-test-list.js +82 -0
- package/dist/screens/variables/variable-details.d.ts +6 -0
- package/dist/screens/variables/variable-details.js +140 -0
- package/dist/screens/variables/variable-list.d.ts +2 -0
- package/dist/screens/variables/variable-list.js +58 -0
- package/dist/screens/workflows/workflow-details.d.ts +6 -0
- package/dist/screens/workflows/workflow-details.js +122 -0
- package/dist/screens/workflows/workflow-info.d.ts +5 -0
- package/dist/screens/workflows/workflow-info.js +18 -0
- package/dist/screens/workflows/workflow-instructions.d.ts +5 -0
- package/dist/screens/workflows/workflow-instructions.js +118 -0
- package/dist/screens/workflows/workflow-list.d.ts +2 -0
- package/dist/screens/workflows/workflow-list.js +109 -0
- package/dist/screens/workflows/workflow-subscriptions.d.ts +6 -0
- package/dist/screens/workflows/workflow-subscriptions.js +81 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +31 -0
- package/dist/system-apps/assistants.app.d.ts +2 -0
- package/dist/system-apps/assistants.app.js +8 -0
- package/dist/system-apps/contacts.app.d.ts +2 -0
- package/dist/system-apps/contacts.app.js +9 -0
- package/dist/system-apps/events.app.d.ts +2 -0
- package/dist/system-apps/events.app.js +8 -0
- package/dist/system-apps/groups.app.d.ts +2 -0
- package/dist/system-apps/groups.app.js +9 -0
- package/dist/system-apps/index.d.ts +19 -0
- package/dist/system-apps/index.js +90 -0
- package/dist/system-apps/knowledge-frames.app.d.ts +2 -0
- package/dist/system-apps/knowledge-frames.app.js +9 -0
- package/dist/system-apps/knowledge-values.app.d.ts +2 -0
- package/dist/system-apps/knowledge-values.app.js +9 -0
- package/dist/system-apps/packages.app.d.ts +2 -0
- package/dist/system-apps/packages.app.js +8 -0
- package/dist/system-apps/predicates.app.d.ts +2 -0
- package/dist/system-apps/predicates.app.js +8 -0
- package/dist/system-apps/profile.app.d.ts +2 -0
- package/dist/system-apps/profile.app.js +8 -0
- package/dist/system-apps/search.app.d.ts +2 -0
- package/dist/system-apps/search.app.js +9 -0
- package/dist/system-apps/settings.app.d.ts +2 -0
- package/dist/system-apps/settings.app.js +8 -0
- package/dist/system-apps/threads.app.d.ts +2 -0
- package/dist/system-apps/threads.app.js +8 -0
- package/dist/system-apps/tools.app.d.ts +2 -0
- package/dist/system-apps/tools.app.js +8 -0
- package/dist/system-apps/types.app.d.ts +2 -0
- package/dist/system-apps/types.app.js +8 -0
- package/dist/system-apps/variables.app.d.ts +2 -0
- package/dist/system-apps/variables.app.js +8 -0
- package/dist/system-apps/workflows.app.d.ts +2 -0
- package/dist/system-apps/workflows.app.js +8 -0
- package/dist/tabs-layout/tabs-layout.d.ts +5 -0
- package/dist/tabs-layout/tabs-layout.js +374 -0
- package/dist/tabs-layout/tabs-state.d.ts +26 -0
- package/dist/tabs-layout/tabs-state.js +239 -0
- package/dist/three-bar-layout/left-bar-content.d.ts +7 -0
- package/dist/three-bar-layout/left-bar-content.js +151 -0
- package/dist/three-bar-layout/right-bar-content.d.ts +2 -0
- package/dist/three-bar-layout/right-bar-content.js +64 -0
- package/dist/three-bar-layout/three-bar-layout.d.ts +5 -0
- package/dist/three-bar-layout/three-bar-layout.js +218 -0
- package/dist/ui-defaults/index.d.ts +2 -0
- package/dist/ui-defaults/index.js +4 -0
- package/dist/ui-defaults/list-screen.d.ts +6 -0
- package/dist/ui-defaults/list-screen.js +74 -0
- package/dist/ui-defaults/notes-editor.d.ts +7 -0
- package/dist/ui-defaults/notes-editor.js +41 -0
- package/dist/ui-router/routes-loader.d.ts +25 -0
- package/dist/ui-router/routes-loader.js +97 -0
- package/dist/ui-router/ui-loader.d.ts +18 -0
- package/dist/ui-router/ui-loader.js +481 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +250 -0
- package/docs/conversation-tab.md +201 -0
- package/docs/getting-started.md +284 -0
- package/docs/knowledge.md +187 -0
- package/docs/tabs-ui.md +696 -0
- package/docs/user-contacts-ui.md +384 -0
- package/jest.config.js +25 -0
- package/package.json +109 -0
- package/src/app.tsx +59 -0
- package/src/command-palette/command-palette-ui.tsx +264 -0
- package/src/command-palette/command-palette.ts +364 -0
- package/src/components/checkbox.tsx +22 -0
- package/src/components/group-switcher.tsx +469 -0
- package/src/components/input-date.tsx +28 -0
- package/src/components/input-datetime.tsx +41 -0
- package/src/components/input-number.tsx +67 -0
- package/src/components/input.tsx +22 -0
- package/src/components/io-schema-values.tsx +122 -0
- package/src/components/io-schema.tsx +234 -0
- package/src/components/lazy-list.tsx +98 -0
- package/src/components/lazy-sortable-list.tsx +51 -0
- package/src/components/left-bar.tsx +264 -0
- package/src/components/list-screen.tsx +105 -0
- package/src/components/loading-indicator.tsx +9 -0
- package/src/components/main-content-container.tsx +76 -0
- package/src/components/markdown-editor/autolink-plugin.tsx +36 -0
- package/src/components/markdown-editor/editor-inline.tsx +10 -0
- package/src/components/markdown-editor/editor.tsx +152 -0
- package/src/components/markdown-editor/markdown-plugin.tsx +224 -0
- package/src/components/markdown-editor/mention-node.ts +199 -0
- package/src/components/markdown-editor/mentions-plugin.tsx +356 -0
- package/src/components/markdown-editor/theme.ts +47 -0
- package/src/components/markdown-editor/toolbar.tsx +263 -0
- package/src/components/markdown-with-mentions.tsx +183 -0
- package/src/components/message-logs/message-logs.tsx +406 -0
- package/src/components/messages/avatar.tsx +95 -0
- package/src/components/messages/channel-message-list.tsx +177 -0
- package/src/components/messages/channel-view.tsx +74 -0
- package/src/components/messages/message-compose.tsx +162 -0
- package/src/components/messages/message-display.tsx +217 -0
- package/src/components/messages/thread-message-list.tsx +126 -0
- package/src/components/messages/thread-view.tsx +214 -0
- package/src/components/off-canvas.tsx +83 -0
- package/src/components/router.tsx +224 -0
- package/src/components/save-button.tsx +109 -0
- package/src/components/sortable-list.tsx +102 -0
- package/src/components/tabs.tsx +70 -0
- package/src/components/text-list-editor.tsx/text-list-editor.tsx +13 -0
- package/src/components/tooltip.tsx +50 -0
- package/src/components/top-bar.tsx +119 -0
- package/src/components/typeahead/mentions-plugin.tsx +265 -0
- package/src/components/typeahead/typeahead-editor.tsx +140 -0
- package/src/components/typeahead/typeahead.tsx +77 -0
- package/src/components/typeahead.tsx +359 -0
- package/src/globals.tsx +162 -0
- package/src/hooks.ts +144 -0
- package/src/index.tsx +8 -0
- package/src/layout-vars.ts +8 -0
- package/src/mention-configs.ts +166 -0
- package/src/screens/assistants/assistant-config.tsx +80 -0
- package/src/screens/assistants/assistant-details.tsx +77 -0
- package/src/screens/assistants/assistant-info.tsx +45 -0
- package/src/screens/assistants/assistant-list.tsx +115 -0
- package/src/screens/assistants/assistant-tools.tsx +61 -0
- package/src/screens/contacts/contact-details.tsx +175 -0
- package/src/screens/contacts/contact-list.tsx +251 -0
- package/src/screens/contacts/index.ts +6 -0
- package/src/screens/events/cron.ts +74 -0
- package/src/screens/events/event-details.tsx +117 -0
- package/src/screens/events/event-handlers.tsx +61 -0
- package/src/screens/events/event-info.tsx +29 -0
- package/src/screens/events/event-list.tsx +104 -0
- package/src/screens/events/event-schedule.tsx +130 -0
- package/src/screens/groups/group-details.tsx +306 -0
- package/src/screens/groups/group-list.tsx +366 -0
- package/src/screens/groups/group-members.tsx +455 -0
- package/src/screens/groups/index.ts +9 -0
- package/src/screens/knowledge/knowledge-frame-details.bk.tsx +160 -0
- package/src/screens/knowledge/knowledge-frame-details.tsx +176 -0
- package/src/screens/knowledge/knowledge-frame-list.tsx +49 -0
- package/src/screens/knowledge/knowledge-value-details.tsx +181 -0
- package/src/screens/knowledge/knowledge-value-list-item.tsx +48 -0
- package/src/screens/knowledge/knowledge-value-list.tsx +131 -0
- package/src/screens/packages/package-details.tsx +117 -0
- package/src/screens/packages/package-info.tsx +83 -0
- package/src/screens/packages/package-list.tsx +191 -0
- package/src/screens/packages/package-new-local.tsx +93 -0
- package/src/screens/peer-types/peer-type-details.tsx +162 -0
- package/src/screens/peer-types/peer-type-list.tsx +74 -0
- package/src/screens/predicates/predicate-details.tsx +125 -0
- package/src/screens/predicates/predicate-list.tsx +50 -0
- package/src/screens/profile.tsx +68 -0
- package/src/screens/search/global-search.tsx +274 -0
- package/src/screens/settings/color-mode-dropdown.tsx +57 -0
- package/src/screens/settings/settings-page.tsx +76 -0
- package/src/screens/setup-user.tsx +367 -0
- package/src/screens/tools/tool-code.tsx +35 -0
- package/src/screens/tools/tool-details.tsx +101 -0
- package/src/screens/tools/tool-info.tsx +60 -0
- package/src/screens/tools/tool-list.tsx +121 -0
- package/src/screens/tools/tool-schema.tsx +42 -0
- package/src/screens/tools/tool-test-details.tsx +100 -0
- package/src/screens/tools/tool-test-list.tsx +74 -0
- package/src/screens/variables/variable-details.tsx +183 -0
- package/src/screens/variables/variable-list.tsx +74 -0
- package/src/screens/workflows/workflow-details.tsx +130 -0
- package/src/screens/workflows/workflow-info.tsx +29 -0
- package/src/screens/workflows/workflow-instructions.tsx +127 -0
- package/src/screens/workflows/workflow-list.tsx +107 -0
- package/src/screens/workflows/workflow-subscriptions.tsx +58 -0
- package/src/setupTests.ts +32 -0
- package/src/system-apps/assistants.app.ts +7 -0
- package/src/system-apps/contacts.app.ts +8 -0
- package/src/system-apps/events.app.ts +7 -0
- package/src/system-apps/groups.app.ts +8 -0
- package/src/system-apps/index.ts +79 -0
- package/src/system-apps/knowledge-frames.app.ts +8 -0
- package/src/system-apps/knowledge-values.app.ts +8 -0
- package/src/system-apps/packages.app.ts +7 -0
- package/src/system-apps/predicates.app.ts +7 -0
- package/src/system-apps/profile.app.ts +7 -0
- package/src/system-apps/search.app.ts +8 -0
- package/src/system-apps/settings.app.ts +7 -0
- package/src/system-apps/threads.app.ts +7 -0
- package/src/system-apps/tools.app.ts +7 -0
- package/src/system-apps/types.app.ts +7 -0
- package/src/system-apps/variables.app.ts +7 -0
- package/src/system-apps/workflows.app.ts +7 -0
- package/src/tabs-layout/tabs-layout.tsx +672 -0
- package/src/tabs-layout/tabs-state.ts +269 -0
- package/src/three-bar-layout/left-bar-content.tsx +202 -0
- package/src/three-bar-layout/right-bar-content.tsx +67 -0
- package/src/three-bar-layout/three-bar-layout.tsx +297 -0
- package/src/ui-defaults/index.ts +3 -0
- package/src/ui-defaults/list-screen.tsx +92 -0
- package/src/ui-defaults/notes-editor.tsx +51 -0
- package/src/ui-router/routes-loader.ts +98 -0
- package/src/ui-router/ui-loader.tsx +497 -0
- package/src/utils.ts +266 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { getMe, getUserContext, Groups, IGroup, newid, newKeys, TrustLevel, UserContext, Users } from "@peers-app/peers-sdk";
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { usePromise } from '../hooks';
|
|
4
|
+
|
|
5
|
+
interface GroupSwitcherProps {
|
|
6
|
+
colorMode: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function GroupSwitcher({ colorMode }: GroupSwitcherProps) {
|
|
10
|
+
const [showDropdown, setShowDropdown] = useState(false);
|
|
11
|
+
const [showCreateModal, setShowCreateModal] = useState(false);
|
|
12
|
+
const [allGroups, setAllGroups] = useState<IGroup[]>([]);
|
|
13
|
+
|
|
14
|
+
const userContext = usePromise(getUserContext);
|
|
15
|
+
|
|
16
|
+
// Load groups from user context
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!userContext) return;
|
|
19
|
+
|
|
20
|
+
const loadGroups = async () => {
|
|
21
|
+
const groupsTable = Groups(userContext.userDataContext);
|
|
22
|
+
const groupsList = await groupsTable.list({ disabled: { $ne: true } });
|
|
23
|
+
setAllGroups(groupsList);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
loadGroups();
|
|
27
|
+
}, [userContext]);
|
|
28
|
+
|
|
29
|
+
// Use useMemo to recompute currentGroup when either currentGroupId or allGroups changes
|
|
30
|
+
const currentGroup = React.useMemo(() => {
|
|
31
|
+
const currentGroupId = userContext?.currentlyActiveGroupId();
|
|
32
|
+
if (!currentGroupId) return null;
|
|
33
|
+
return allGroups.find((g: IGroup) => g.groupId === currentGroupId) || null;
|
|
34
|
+
}, [allGroups, userContext?.currentlyActiveGroupId()]);
|
|
35
|
+
|
|
36
|
+
const handleGroupSelect = (group: IGroup | null) => {
|
|
37
|
+
if (!userContext) return;
|
|
38
|
+
|
|
39
|
+
// Set the active group through user context
|
|
40
|
+
userContext.currentlyActiveGroupId(group?.groupId || '');
|
|
41
|
+
setShowDropdown(false);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const handleCreateClick = () => {
|
|
45
|
+
setShowDropdown(false);
|
|
46
|
+
setShowCreateModal(true);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getGroupIcon = (group: IGroup | null | undefined) => {
|
|
50
|
+
if (!group) return 'bi-person-fill'; // Personal group icon
|
|
51
|
+
return group.iconClassName || 'bi-people-fill';
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getGroupName = (group: IGroup | null | undefined) => {
|
|
55
|
+
if (!group) return 'Personal';
|
|
56
|
+
return group.name;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const isDark = colorMode === 'dark';
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<div className="dropdown">
|
|
64
|
+
<button
|
|
65
|
+
className="btn btn-sm me-2 d-flex align-items-center"
|
|
66
|
+
onClick={() => setShowDropdown(!showDropdown)}
|
|
67
|
+
title={`Current group: ${getGroupName(currentGroup)}`}
|
|
68
|
+
style={{
|
|
69
|
+
padding: '4px 8px',
|
|
70
|
+
fontSize: '12px',
|
|
71
|
+
borderRadius: '6px',
|
|
72
|
+
border: 'none',
|
|
73
|
+
background: 'transparent',
|
|
74
|
+
color: isDark ? '#adb5bd' : '#6c757d'
|
|
75
|
+
}}
|
|
76
|
+
onMouseEnter={(e) => {
|
|
77
|
+
e.currentTarget.style.backgroundColor = isDark ? '#495057' : '#f8f9fa';
|
|
78
|
+
e.currentTarget.style.color = isDark ? '#ffffff' : '#0d6efd';
|
|
79
|
+
}}
|
|
80
|
+
onMouseLeave={(e) => {
|
|
81
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
82
|
+
e.currentTarget.style.color = isDark ? '#adb5bd' : '#6c757d';
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<i className={`${getGroupIcon(currentGroup)} me-1`} style={{ fontSize: '14px' }} />
|
|
86
|
+
<span className="text-truncate" style={{ maxWidth: '80px' }}>
|
|
87
|
+
{getGroupName(currentGroup)}
|
|
88
|
+
</span>
|
|
89
|
+
<i className="bi-chevron-down ms-1" style={{ fontSize: '10px' }} />
|
|
90
|
+
</button>
|
|
91
|
+
|
|
92
|
+
{showDropdown && (
|
|
93
|
+
<div
|
|
94
|
+
className={`dropdown-menu show position-absolute ${isDark ? 'dropdown-menu-dark' : ''}`}
|
|
95
|
+
style={{
|
|
96
|
+
left: 0,
|
|
97
|
+
top: '100%',
|
|
98
|
+
zIndex: 1000,
|
|
99
|
+
minWidth: '200px',
|
|
100
|
+
maxHeight: '300px',
|
|
101
|
+
overflowY: 'auto'
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
{/* Personal Group */}
|
|
105
|
+
<div
|
|
106
|
+
className={`dropdown-item d-flex align-items-center ${!currentGroup ? 'active' : ''}`}
|
|
107
|
+
style={{ cursor: 'pointer' }}
|
|
108
|
+
onClick={() => handleGroupSelect(null)}
|
|
109
|
+
>
|
|
110
|
+
<i className="bi-person-fill me-2" />
|
|
111
|
+
<span>Personal</span>
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
{/* Divider */}
|
|
115
|
+
{allGroups.length > 0 && (
|
|
116
|
+
<div className="dropdown-divider" />
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
{/* Group List */}
|
|
120
|
+
{allGroups
|
|
121
|
+
.filter((g: IGroup) => !g.disabled)
|
|
122
|
+
.map((group: IGroup) => (
|
|
123
|
+
<div
|
|
124
|
+
key={group.groupId}
|
|
125
|
+
className={`dropdown-item d-flex align-items-center ${currentGroup?.groupId === group.groupId ? 'active' : ''}`}
|
|
126
|
+
style={{ cursor: 'pointer' }}
|
|
127
|
+
onClick={() => handleGroupSelect(group)}
|
|
128
|
+
>
|
|
129
|
+
<i className={`${getGroupIcon(group)} me-2`} />
|
|
130
|
+
<span className="text-truncate">{group.name}</span>
|
|
131
|
+
</div>
|
|
132
|
+
))}
|
|
133
|
+
|
|
134
|
+
{/* Create New Group */}
|
|
135
|
+
<div className="dropdown-divider" />
|
|
136
|
+
<div
|
|
137
|
+
className="dropdown-item d-flex align-items-center"
|
|
138
|
+
style={{ cursor: 'pointer' }}
|
|
139
|
+
onClick={handleCreateClick}
|
|
140
|
+
>
|
|
141
|
+
<i className="bi-plus-circle me-2" />
|
|
142
|
+
<span>Create Group</span>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
)}
|
|
146
|
+
|
|
147
|
+
{/* Backdrop to close dropdown */}
|
|
148
|
+
{showDropdown && (
|
|
149
|
+
<div
|
|
150
|
+
className="position-fixed w-100 h-100"
|
|
151
|
+
style={{ top: 0, left: 0, zIndex: 999 }}
|
|
152
|
+
onClick={() => setShowDropdown(false)}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
{/* Create Group Modal */}
|
|
158
|
+
{showCreateModal && userContext && (
|
|
159
|
+
<CreateGroupModal
|
|
160
|
+
colorMode={colorMode}
|
|
161
|
+
userContext={userContext}
|
|
162
|
+
onClose={() => setShowCreateModal(false)}
|
|
163
|
+
onGroupCreated={async (groupId: string) => {
|
|
164
|
+
// Refresh groups list
|
|
165
|
+
const groupsTable = Groups(userContext.userDataContext);
|
|
166
|
+
const groupsList = await groupsTable.list({ disabled: { $ne: true } });
|
|
167
|
+
setAllGroups(groupsList);
|
|
168
|
+
|
|
169
|
+
// Switch to new group
|
|
170
|
+
userContext.currentlyActiveGroupId(groupId);
|
|
171
|
+
setShowCreateModal(false);
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
175
|
+
</>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface CreateGroupModalProps {
|
|
180
|
+
colorMode: string;
|
|
181
|
+
userContext: UserContext;
|
|
182
|
+
onClose: () => void;
|
|
183
|
+
onGroupCreated: (groupId: string) => void;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated }: CreateGroupModalProps) {
|
|
187
|
+
const [groupName, setGroupName] = useState('');
|
|
188
|
+
const [iconClassName, setIconClassName] = useState('bi-people-fill');
|
|
189
|
+
const [description, setDescription] = useState('');
|
|
190
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
191
|
+
const [error, setError] = useState<string | null>(null);
|
|
192
|
+
|
|
193
|
+
const isDark = colorMode === 'dark';
|
|
194
|
+
|
|
195
|
+
const handleCreate = async () => {
|
|
196
|
+
// Validate
|
|
197
|
+
const trimmedName = groupName.trim();
|
|
198
|
+
if (!trimmedName) {
|
|
199
|
+
setError('Group name is required');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (trimmedName.length > 100) {
|
|
204
|
+
setError('Group name must be 100 characters or less');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
setIsCreating(true);
|
|
209
|
+
setError(null);
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
const groupId = newid();
|
|
213
|
+
const me = await getMe();
|
|
214
|
+
|
|
215
|
+
// Generate cryptographic keys for the group
|
|
216
|
+
const groupKeys = newKeys();
|
|
217
|
+
|
|
218
|
+
// Create group data context
|
|
219
|
+
const groupDataContext = userContext.getDataContext(groupId);
|
|
220
|
+
|
|
221
|
+
// Store groupKeys.secretKey securely for this group
|
|
222
|
+
const persistentVarsTable = userContext.userDataContext.tableContainer.getTableByName('PersistentVars');
|
|
223
|
+
const groupSecretKeyVarName = 'groupSecretKey_' + groupDataContext.dataContextId;
|
|
224
|
+
await persistentVarsTable.save({
|
|
225
|
+
persistentVarId: newid(),
|
|
226
|
+
name: groupSecretKeyVarName,
|
|
227
|
+
scope: 'groupUser',
|
|
228
|
+
isSecret: true,
|
|
229
|
+
value: { value: groupKeys.secretKey },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Add current user to the group's users table as trusted
|
|
233
|
+
await Users(groupDataContext).save({
|
|
234
|
+
...me,
|
|
235
|
+
trustLevel: TrustLevel.Trusted
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Create group in both user's and group's context
|
|
239
|
+
const groupsTable = Groups(userContext.userDataContext);
|
|
240
|
+
const newGroup = await groupsTable.save({
|
|
241
|
+
groupId,
|
|
242
|
+
name: trimmedName,
|
|
243
|
+
description: description.trim(),
|
|
244
|
+
iconClassName: iconClassName.trim() || 'bi-people-fill',
|
|
245
|
+
founderUserId: me.userId,
|
|
246
|
+
disabled: false,
|
|
247
|
+
publicKey: groupKeys.publicKey,
|
|
248
|
+
publicBoxKey: groupKeys.publicBoxKey,
|
|
249
|
+
signature: '', // Will be signed by save()
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
await Groups(groupDataContext).save(newGroup);
|
|
253
|
+
|
|
254
|
+
// Notify parent
|
|
255
|
+
onGroupCreated(newGroup.groupId);
|
|
256
|
+
} catch (err: any) {
|
|
257
|
+
console.error('Failed to create group:', err);
|
|
258
|
+
setError(err.message || 'Failed to create group. Please try again.');
|
|
259
|
+
setIsCreating(false);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
264
|
+
if (e.key === 'Enter' && !e.shiftKey && groupName.trim()) {
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
handleCreate();
|
|
267
|
+
} else if (e.key === 'Escape') {
|
|
268
|
+
onClose();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div
|
|
274
|
+
className="position-fixed w-100 h-100 d-flex align-items-start justify-content-center"
|
|
275
|
+
style={{
|
|
276
|
+
top: 0,
|
|
277
|
+
left: 0,
|
|
278
|
+
zIndex: 1050,
|
|
279
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
280
|
+
backdropFilter: 'blur(4px)',
|
|
281
|
+
paddingTop: '10vh'
|
|
282
|
+
}}
|
|
283
|
+
onClick={(e) => {
|
|
284
|
+
if (e.target === e.currentTarget) {
|
|
285
|
+
onClose();
|
|
286
|
+
}
|
|
287
|
+
}}
|
|
288
|
+
>
|
|
289
|
+
<div
|
|
290
|
+
className={`${isDark ? 'bg-dark text-light' : 'bg-white text-dark'}`}
|
|
291
|
+
style={{
|
|
292
|
+
width: '90%',
|
|
293
|
+
maxWidth: '500px',
|
|
294
|
+
borderRadius: '12px',
|
|
295
|
+
boxShadow: isDark
|
|
296
|
+
? '0 20px 40px rgba(0, 0, 0, 0.5)'
|
|
297
|
+
: '0 20px 40px rgba(0, 0, 0, 0.1)',
|
|
298
|
+
border: isDark ? '1px solid #495057' : '1px solid #dee2e6',
|
|
299
|
+
overflow: 'hidden'
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
{/* Header */}
|
|
303
|
+
<div
|
|
304
|
+
className="p-3 border-bottom d-flex align-items-center justify-content-between"
|
|
305
|
+
style={{
|
|
306
|
+
borderBottomColor: isDark ? '#495057' : '#dee2e6'
|
|
307
|
+
}}
|
|
308
|
+
>
|
|
309
|
+
<div className="d-flex align-items-center">
|
|
310
|
+
<i className="bi-people-fill me-2" style={{ fontSize: '20px' }} />
|
|
311
|
+
<h6 className="mb-0">Create New Group</h6>
|
|
312
|
+
</div>
|
|
313
|
+
<button
|
|
314
|
+
className="btn btn-sm p-0"
|
|
315
|
+
style={{
|
|
316
|
+
border: 'none',
|
|
317
|
+
background: 'none',
|
|
318
|
+
fontSize: '24px',
|
|
319
|
+
lineHeight: '1',
|
|
320
|
+
opacity: 0.6
|
|
321
|
+
}}
|
|
322
|
+
onClick={onClose}
|
|
323
|
+
disabled={isCreating}
|
|
324
|
+
onMouseEnter={(e) => e.currentTarget.style.opacity = '1'}
|
|
325
|
+
onMouseLeave={(e) => e.currentTarget.style.opacity = '0.6'}
|
|
326
|
+
>
|
|
327
|
+
<i className="bi-x" />
|
|
328
|
+
</button>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
{/* Body */}
|
|
332
|
+
<div className="p-3">
|
|
333
|
+
{/* Error Alert */}
|
|
334
|
+
{error && (
|
|
335
|
+
<div className="alert alert-danger py-2 px-3 mb-3" style={{ fontSize: '14px' }}>
|
|
336
|
+
<i className="bi-exclamation-triangle me-2" />
|
|
337
|
+
{error}
|
|
338
|
+
</div>
|
|
339
|
+
)}
|
|
340
|
+
|
|
341
|
+
{/* Group Name */}
|
|
342
|
+
<div className="mb-3">
|
|
343
|
+
<label className="form-label small mb-1">
|
|
344
|
+
Group Name <span className="text-danger">*</span>
|
|
345
|
+
</label>
|
|
346
|
+
<input
|
|
347
|
+
type="text"
|
|
348
|
+
className={`form-control ${isDark ? 'bg-dark text-light border-secondary' : ''}`}
|
|
349
|
+
placeholder="Enter group name"
|
|
350
|
+
value={groupName}
|
|
351
|
+
onChange={(e) => {
|
|
352
|
+
setGroupName(e.target.value);
|
|
353
|
+
setError(null);
|
|
354
|
+
}}
|
|
355
|
+
onKeyDown={handleKeyDown}
|
|
356
|
+
autoFocus
|
|
357
|
+
disabled={isCreating}
|
|
358
|
+
maxLength={100}
|
|
359
|
+
style={{
|
|
360
|
+
fontSize: '14px',
|
|
361
|
+
backgroundColor: isDark ? '#343a40' : '#ffffff'
|
|
362
|
+
}}
|
|
363
|
+
/>
|
|
364
|
+
<small className="text-muted" style={{ fontSize: '11px' }}>
|
|
365
|
+
{groupName.length}/100 characters
|
|
366
|
+
</small>
|
|
367
|
+
</div>
|
|
368
|
+
|
|
369
|
+
{/* Icon Class Name */}
|
|
370
|
+
<div className="mb-3">
|
|
371
|
+
<label className="form-label small mb-1">Icon</label>
|
|
372
|
+
<div className="input-group">
|
|
373
|
+
<span
|
|
374
|
+
className={`input-group-text ${isDark ? 'bg-dark text-light border-secondary' : ''}`}
|
|
375
|
+
style={{ backgroundColor: isDark ? '#343a40' : undefined }}
|
|
376
|
+
>
|
|
377
|
+
<i className={iconClassName || 'bi-people-fill'} />
|
|
378
|
+
</span>
|
|
379
|
+
<input
|
|
380
|
+
type="text"
|
|
381
|
+
className={`form-control ${isDark ? 'bg-dark text-light border-secondary' : ''}`}
|
|
382
|
+
placeholder="bi-people-fill"
|
|
383
|
+
value={iconClassName}
|
|
384
|
+
onChange={(e) => setIconClassName(e.target.value)}
|
|
385
|
+
onKeyDown={handleKeyDown}
|
|
386
|
+
disabled={isCreating}
|
|
387
|
+
style={{
|
|
388
|
+
fontSize: '14px',
|
|
389
|
+
backgroundColor: isDark ? '#343a40' : '#ffffff'
|
|
390
|
+
}}
|
|
391
|
+
/>
|
|
392
|
+
</div>
|
|
393
|
+
<small className="text-muted" style={{ fontSize: '11px' }}>
|
|
394
|
+
Bootstrap icon class name (e.g., bi-star-fill, bi-house-fill)
|
|
395
|
+
</small>
|
|
396
|
+
</div>
|
|
397
|
+
|
|
398
|
+
{/* Description */}
|
|
399
|
+
<div className="mb-3">
|
|
400
|
+
<label className="form-label small mb-1">Description (optional)</label>
|
|
401
|
+
<textarea
|
|
402
|
+
className={`form-control ${isDark ? 'bg-dark text-light border-secondary' : ''}`}
|
|
403
|
+
placeholder="Enter group description"
|
|
404
|
+
value={description}
|
|
405
|
+
onChange={(e) => setDescription(e.target.value)}
|
|
406
|
+
disabled={isCreating}
|
|
407
|
+
rows={3}
|
|
408
|
+
maxLength={500}
|
|
409
|
+
style={{
|
|
410
|
+
fontSize: '14px',
|
|
411
|
+
backgroundColor: isDark ? '#343a40' : '#ffffff',
|
|
412
|
+
resize: 'none'
|
|
413
|
+
}}
|
|
414
|
+
/>
|
|
415
|
+
<small className="text-muted" style={{ fontSize: '11px' }}>
|
|
416
|
+
{description.length}/500 characters
|
|
417
|
+
</small>
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
{/* Footer */}
|
|
422
|
+
<div
|
|
423
|
+
className="p-3 border-top d-flex justify-content-end gap-2"
|
|
424
|
+
style={{
|
|
425
|
+
borderTopColor: isDark ? '#495057' : '#dee2e6'
|
|
426
|
+
}}
|
|
427
|
+
>
|
|
428
|
+
<button
|
|
429
|
+
className={`btn btn-sm ${isDark ? 'btn-outline-light' : 'btn-outline-secondary'}`}
|
|
430
|
+
onClick={onClose}
|
|
431
|
+
disabled={isCreating}
|
|
432
|
+
style={{ minWidth: '80px' }}
|
|
433
|
+
>
|
|
434
|
+
Cancel
|
|
435
|
+
</button>
|
|
436
|
+
<button
|
|
437
|
+
className="btn btn-sm btn-primary"
|
|
438
|
+
onClick={handleCreate}
|
|
439
|
+
disabled={isCreating || !groupName.trim()}
|
|
440
|
+
style={{ minWidth: '80px' }}
|
|
441
|
+
>
|
|
442
|
+
{isCreating ? (
|
|
443
|
+
<>
|
|
444
|
+
<span className="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true" />
|
|
445
|
+
Creating...
|
|
446
|
+
</>
|
|
447
|
+
) : (
|
|
448
|
+
<>
|
|
449
|
+
<i className="bi-plus-circle me-1" />
|
|
450
|
+
Create
|
|
451
|
+
</>
|
|
452
|
+
)}
|
|
453
|
+
</button>
|
|
454
|
+
</div>
|
|
455
|
+
|
|
456
|
+
{/* Keyboard Shortcuts Helper */}
|
|
457
|
+
<div
|
|
458
|
+
className={`px-3 py-2 small text-muted border-top`}
|
|
459
|
+
style={{
|
|
460
|
+
borderTopColor: isDark ? '#495057' : '#dee2e6',
|
|
461
|
+
fontSize: '11px'
|
|
462
|
+
}}
|
|
463
|
+
>
|
|
464
|
+
<kbd className="small">↵</kbd> to create • <kbd className="small">esc</kbd> to cancel
|
|
465
|
+
</div>
|
|
466
|
+
</div>
|
|
467
|
+
</div>
|
|
468
|
+
);
|
|
469
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import { Observable } from "@peers-app/peers-sdk";
|
|
4
|
+
import { useObservable } from "../hooks";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface IProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
8
|
+
date: Observable<Date | undefined> | Date | undefined
|
|
9
|
+
}
|
|
10
|
+
export const InputDate = (props: IProps) => {
|
|
11
|
+
|
|
12
|
+
const [date, setDate] = useObservable<Date | undefined>(props.date);
|
|
13
|
+
|
|
14
|
+
const inputProps = { ...props };
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
delete inputProps.date;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<input
|
|
20
|
+
{...inputProps}
|
|
21
|
+
type='date'
|
|
22
|
+
value={date?.toISOString?.().substring(0, 10) ?? ''}
|
|
23
|
+
onChange={evt => {
|
|
24
|
+
setDate(evt.currentTarget.value ? moment(new Date(evt.currentTarget.value)).startOf('day').add(1, 'day').toDate() : undefined)
|
|
25
|
+
}}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useObservable } from "../hooks";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface IProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
7
|
+
datetime: Observable<Date | undefined> | Date | undefined
|
|
8
|
+
}
|
|
9
|
+
export const InputDatetime = (props: IProps) => {
|
|
10
|
+
|
|
11
|
+
const [datetime, setDatetime] = useObservable<Date | undefined>(props.datetime);
|
|
12
|
+
|
|
13
|
+
const inputProps = { ...props };
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
delete inputProps.datetime;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<input
|
|
19
|
+
{...inputProps}
|
|
20
|
+
type='datetime-local'
|
|
21
|
+
value={(() => {
|
|
22
|
+
if (!datetime) return;
|
|
23
|
+
if (String(datetime) === 'Invalid Date') return;
|
|
24
|
+
return datetime.toISOString?.()?.substring(0, 16);
|
|
25
|
+
})()}
|
|
26
|
+
onChange={e => {
|
|
27
|
+
let value = e.target.value;
|
|
28
|
+
if (value) {
|
|
29
|
+
value += (new Date()).toISOString().substring(value.length);
|
|
30
|
+
const dt = new Date(value);
|
|
31
|
+
if (String(dt) !== 'Invalid Date') {
|
|
32
|
+
setDatetime(new Date(value));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
setDatetime(undefined);
|
|
37
|
+
if (props.onChange) props.onChange(e);
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _, { isNumber } from 'lodash';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { formatMoney, unwrapObservable } from "@peers-app/peers-sdk";
|
|
4
|
+
import { useObservable } from '../hooks';
|
|
5
|
+
|
|
6
|
+
interface IProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
7
|
+
value: any
|
|
8
|
+
format?: 'money'
|
|
9
|
+
precision?: number
|
|
10
|
+
refPassthrough?: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function InputNumber(props: IProps) {
|
|
14
|
+
let { format, precision, refPassthrough } = props;
|
|
15
|
+
if (!_.isNumber(precision)) {
|
|
16
|
+
precision = 2;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let propsPassthrough = { ...props };
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
['value', 'format', 'precision', 'refPassthrough'].forEach(name => (delete propsPassthrough[name]));
|
|
22
|
+
|
|
23
|
+
const [value, setValue] = useObservable(props.value);
|
|
24
|
+
|
|
25
|
+
let [displayValue, setDisplayValue] = useState<string>(() => {
|
|
26
|
+
if (isNaN(Number(value)) || value === null || String(value).trim() === '') {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
if (format === 'money') {
|
|
30
|
+
return formatMoney(Number(unwrapObservable(props.value)), precision);
|
|
31
|
+
}
|
|
32
|
+
return String(value);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function onChange(evt: React.ChangeEvent<HTMLInputElement>) {
|
|
37
|
+
let _value: any = evt.target.value;
|
|
38
|
+
setDisplayValue(_value);
|
|
39
|
+
// convert blank to null
|
|
40
|
+
if (String(_value).trim() === '') {
|
|
41
|
+
setValue(null);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_value = _value.replace(/\$/g, '');
|
|
46
|
+
_value = Number(_value);
|
|
47
|
+
if (isNumber(_value) && !isNaN(_value)) {
|
|
48
|
+
setValue(_value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onBlur(evt: React.FocusEvent<HTMLInputElement>) {
|
|
53
|
+
if (format === 'money' && !isNaN(Number(value)) && value !== null && String(value).trim() !== '') {
|
|
54
|
+
const fmtMoney = formatMoney(value, precision);
|
|
55
|
+
setDisplayValue(fmtMoney);
|
|
56
|
+
} else if (value === null) {
|
|
57
|
+
setDisplayValue('');
|
|
58
|
+
} else {
|
|
59
|
+
setDisplayValue(String(value));
|
|
60
|
+
}
|
|
61
|
+
// todo if not money format precision and set display
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<input {...propsPassthrough} ref={refPassthrough} value={displayValue} onChange={onChange} onBlur={onBlur} />
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useObservable } from '../hooks';
|
|
3
|
+
|
|
4
|
+
interface IProps extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
5
|
+
value: any,
|
|
6
|
+
type?: React.HTMLInputTypeAttribute
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Input(props: IProps) {
|
|
10
|
+
const [value, setValue] = useObservable(props.value);
|
|
11
|
+
const type = props.type ?? (typeof value);
|
|
12
|
+
function onChange(evt: React.ChangeEvent<HTMLInputElement>) {
|
|
13
|
+
let _value: any = evt.target.value;
|
|
14
|
+
if (type === 'number') {
|
|
15
|
+
_value = Number(_value);
|
|
16
|
+
}
|
|
17
|
+
setValue(_value);
|
|
18
|
+
}
|
|
19
|
+
return (
|
|
20
|
+
<input onChange={onChange} type={type} {...props} value={value} />
|
|
21
|
+
)
|
|
22
|
+
}
|