@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,297 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { colorMode, colorModePreference, ColorModePreference } from '../screens/settings/color-mode-dropdown';
|
|
3
|
+
import { Router } from '../components/router';
|
|
4
|
+
import { useObservable, usePromise } from '../hooks';
|
|
5
|
+
import { isDesktop, loadGlobals, me, windowWidth as windowWidthObs } from '../globals';
|
|
6
|
+
import { loadAllRoutes } from '../ui-router/routes-loader';
|
|
7
|
+
import { SetupUser } from '../screens/setup-user';
|
|
8
|
+
import * as layoutVars from '../layout-vars';
|
|
9
|
+
import { LeftBarContent } from './left-bar-content';
|
|
10
|
+
import { RightBarContent } from './right-bar-content';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export function ThreeBarLayout(props: { colorMode?: ColorModePreference }) {
|
|
14
|
+
const loaded = usePromise(async () => {
|
|
15
|
+
await loadGlobals().then(() => console.log('Globals loaded'));
|
|
16
|
+
await loadAllRoutes().then(() => console.log('Routes loaded'));
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!loaded) return false;
|
|
21
|
+
document.getElementById('appLoadingDiv')?.remove();
|
|
22
|
+
|
|
23
|
+
if (me.name === me.userId) {
|
|
24
|
+
return <SetupUser />
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
colorModePreference(props.colorMode);
|
|
28
|
+
// colorModePreference('auto');
|
|
29
|
+
return <_ThreeBarLayout />;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _ThreeBarLayout() {
|
|
33
|
+
|
|
34
|
+
const [_colorMode] = useObservable(colorMode);
|
|
35
|
+
const sidebarColorClass = _colorMode === 'light' ? 'bg-dark-subtle' : 'bg-dark-subtle';
|
|
36
|
+
const collapseButtonClass = _colorMode === 'light' ? 'btn-outline-dark' : 'btn-outline-secondary';
|
|
37
|
+
|
|
38
|
+
const [windowWidth] = useObservable(windowWidthObs);
|
|
39
|
+
useObservable(isDesktop);
|
|
40
|
+
const isMobile = !isDesktop();
|
|
41
|
+
|
|
42
|
+
const [leftBarWidth, setLeftBarWidth] = useObservable(layoutVars.leftBarWidth);
|
|
43
|
+
const [rightBarWidth, setRightBarWidth] = useObservable(layoutVars.rightBarWidth);
|
|
44
|
+
|
|
45
|
+
const [leftBarCollapsed, setLeftBarCollapsed] = useObservable(layoutVars.leftBarCollapsed);
|
|
46
|
+
const [rightBarCollapsed, setRightBarCollapsed] = useObservable(layoutVars.rightBarCollapsed);
|
|
47
|
+
|
|
48
|
+
const [prevLeftWidth, setPrevLeftWidth] = useObservable(layoutVars.leftBarWidthPrev);
|
|
49
|
+
const [prevRightWidth, setPrevRightWidth] = useObservable(layoutVars.rightBarWidthPrev);
|
|
50
|
+
|
|
51
|
+
const [leftOffcanvasVisible, setLeftOffcanvasVisible] = useState(false);
|
|
52
|
+
const [rightOffcanvasVisible, setRightOffcanvasVisible] = useState(false);
|
|
53
|
+
|
|
54
|
+
const [isResizingLeft, setIsResizingLeft] = useState(false);
|
|
55
|
+
const [isResizingRight, setIsResizingRight] = useState(false);
|
|
56
|
+
|
|
57
|
+
// Mouse event handlers for resizing (desktop only).
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
60
|
+
if (isResizingLeft) {
|
|
61
|
+
const newWidth = e.clientX;
|
|
62
|
+
if (newWidth >= 200 && newWidth <= windowWidth - 80) {
|
|
63
|
+
setLeftBarWidth(newWidth);
|
|
64
|
+
}
|
|
65
|
+
// Prevent text selection while dragging.
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
}
|
|
68
|
+
if (isResizingRight) {
|
|
69
|
+
const newWidth = window.innerWidth - e.clientX;
|
|
70
|
+
if (newWidth >= 200 && newWidth <= windowWidth - 80) {
|
|
71
|
+
setRightBarWidth(newWidth);
|
|
72
|
+
}
|
|
73
|
+
// Prevent text selection while dragging.
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleMouseUp = () => {
|
|
79
|
+
if (isResizingLeft) setIsResizingLeft(false);
|
|
80
|
+
if (isResizingRight) setIsResizingRight(false);
|
|
81
|
+
// Re-enable text selection once resizing is done.
|
|
82
|
+
document.body.style.userSelect = '';
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
86
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
87
|
+
return () => {
|
|
88
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
89
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
90
|
+
};
|
|
91
|
+
}, [isResizingLeft, isResizingRight, windowWidth]);
|
|
92
|
+
|
|
93
|
+
// Function to close both offcanvas panels.
|
|
94
|
+
const closeOffcanvas = () => {
|
|
95
|
+
setLeftOffcanvasVisible(false);
|
|
96
|
+
setRightOffcanvasVisible(false);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Toggle function for collapsing/expanding the right sidebar (desktop only).
|
|
100
|
+
const toggleRightSidebarCollapse = () => {
|
|
101
|
+
if (!rightBarCollapsed) {
|
|
102
|
+
// Save the current width and collapse to 50px.
|
|
103
|
+
setPrevRightWidth(rightBarWidth);
|
|
104
|
+
setRightBarWidth(50);
|
|
105
|
+
setRightBarCollapsed(true);
|
|
106
|
+
} else {
|
|
107
|
+
// Restore the previous width.
|
|
108
|
+
setRightBarWidth(prevRightWidth);
|
|
109
|
+
setRightBarCollapsed(false);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Toggle function for collapsing/expanding the left sidebar (desktop only).
|
|
114
|
+
const toggleLeftSidebarCollapse = () => {
|
|
115
|
+
if (!leftBarCollapsed) {
|
|
116
|
+
// Save the current width and collapse to 50px.
|
|
117
|
+
setPrevLeftWidth(leftBarWidth);
|
|
118
|
+
setLeftBarWidth(50);
|
|
119
|
+
setLeftBarCollapsed(true);
|
|
120
|
+
} else {
|
|
121
|
+
// Restore the previous width.
|
|
122
|
+
setLeftBarWidth(prevLeftWidth);
|
|
123
|
+
setLeftBarCollapsed(false);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<>
|
|
129
|
+
<div className="d-flex" style={{ height: '100vh', overflow: 'hidden' }}>
|
|
130
|
+
{/* Left Sidebar (Desktop only) */}
|
|
131
|
+
{!isMobile && (
|
|
132
|
+
<div
|
|
133
|
+
className={`position-relative ${sidebarColorClass}`}
|
|
134
|
+
style={{
|
|
135
|
+
width: leftBarWidth,
|
|
136
|
+
transition: 'width 0.3s',
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
{/* Sidebar Header with toggle button */}
|
|
140
|
+
<LeftBarContent collapsed={leftBarCollapsed} toggleCollapsed={toggleLeftSidebarCollapse} />
|
|
141
|
+
{/* <div className="p-2" hidden={leftBarCollapsed}>
|
|
142
|
+
<LeftBarExpandedContent />;
|
|
143
|
+
</div> */}
|
|
144
|
+
{/* Resizing handle for left sidebar: render only when not collapsed */}
|
|
145
|
+
{!leftBarCollapsed && (
|
|
146
|
+
<div
|
|
147
|
+
className="position-absolute top-0 end-0 h-100"
|
|
148
|
+
style={{
|
|
149
|
+
width: '5px',
|
|
150
|
+
cursor: 'col-resize',
|
|
151
|
+
backgroundColor: 'rgba(0,0,0,0.2)',
|
|
152
|
+
}}
|
|
153
|
+
onMouseDown={(e) => {
|
|
154
|
+
setIsResizingLeft(true);
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
document.body.style.userSelect = 'none';
|
|
157
|
+
}}
|
|
158
|
+
></div>
|
|
159
|
+
)}
|
|
160
|
+
</div>
|
|
161
|
+
)}
|
|
162
|
+
|
|
163
|
+
{/* Main Content Area with Top Bar */}
|
|
164
|
+
<div
|
|
165
|
+
className="flex-grow-1 d-flex flex-column position-relative"
|
|
166
|
+
style={{ minWidth: 0, width: `${windowWidth - leftBarWidth - rightBarWidth}px` }} // prevents content inside from changing the width
|
|
167
|
+
>
|
|
168
|
+
{/* Top Bar */}
|
|
169
|
+
<div className="d-flex align-items-center justify-content-between border-bottom p-2">
|
|
170
|
+
{isMobile && (
|
|
171
|
+
<button
|
|
172
|
+
className={`btn btn-sm ${collapseButtonClass}`}
|
|
173
|
+
onClick={() => setLeftOffcanvasVisible(true)}
|
|
174
|
+
>
|
|
175
|
+
<i
|
|
176
|
+
className={`bi bi-chevron-double-right`}
|
|
177
|
+
title={rightBarCollapsed ? 'Expand Left Sidebar' : 'Collapse Left Sidebar'}
|
|
178
|
+
></i>
|
|
179
|
+
</button>
|
|
180
|
+
)}
|
|
181
|
+
|
|
182
|
+
<h4 className="m-0 mx-auto">
|
|
183
|
+
tabs up here
|
|
184
|
+
</h4>
|
|
185
|
+
|
|
186
|
+
</div>
|
|
187
|
+
{/* Main content below the top bar */}
|
|
188
|
+
<div
|
|
189
|
+
className="flex-grow-1 overflow-auto"
|
|
190
|
+
style={{ maxHeight: 'calc(100vh - 160px)' }}
|
|
191
|
+
>
|
|
192
|
+
<Router />
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
{/* Right Sidebar open/close toggle */}
|
|
197
|
+
<button
|
|
198
|
+
className={`btn btn-sm ${collapseButtonClass} float-end`}
|
|
199
|
+
onClick={() => {
|
|
200
|
+
if (isMobile) setRightOffcanvasVisible(!rightOffcanvasVisible);
|
|
201
|
+
else toggleRightSidebarCollapse();
|
|
202
|
+
}}
|
|
203
|
+
style={{ zIndex: 20000, position: 'absolute',
|
|
204
|
+
top: '8px', right: '8px', //marginLeft: '20px',
|
|
205
|
+
...(!rightBarCollapsed || rightOffcanvasVisible ? { top: '10px', right: '20px' } : {}),
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
<i
|
|
209
|
+
className={`bi ${!rightBarCollapsed || rightOffcanvasVisible ? 'bi-chevron-double-right' : 'bi-chevron-double-left'}`}
|
|
210
|
+
title={rightBarCollapsed ? 'Expand Right Sidebar' : 'Collapse Right Sidebar'}
|
|
211
|
+
></i>
|
|
212
|
+
</button>
|
|
213
|
+
|
|
214
|
+
{/* Desktop Right Sidebar */}
|
|
215
|
+
{!isMobile && (
|
|
216
|
+
<div
|
|
217
|
+
className={`position-relative ${sidebarColorClass}`}
|
|
218
|
+
style={{
|
|
219
|
+
width: rightBarWidth,
|
|
220
|
+
transition: 'width 0.3s',
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<div className="ps-1" hidden={rightBarCollapsed}>
|
|
224
|
+
<RightBarContent />
|
|
225
|
+
</div>
|
|
226
|
+
{/* Resizing handle for right sidebar: render only when not collapsed */}
|
|
227
|
+
{!rightBarCollapsed && (
|
|
228
|
+
<div
|
|
229
|
+
className="position-absolute top-0 start-0 h-100"
|
|
230
|
+
style={{
|
|
231
|
+
width: '5px',
|
|
232
|
+
cursor: 'col-resize',
|
|
233
|
+
backgroundColor: 'rgba(0,0,0,0.2)',
|
|
234
|
+
}}
|
|
235
|
+
onMouseDown={(e) => {
|
|
236
|
+
setIsResizingRight(true);
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
document.body.style.userSelect = 'none';
|
|
239
|
+
}}
|
|
240
|
+
></div>
|
|
241
|
+
)}
|
|
242
|
+
</div>
|
|
243
|
+
)}
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
{/* Backdrop for Offcanvas */}
|
|
247
|
+
{(leftOffcanvasVisible || rightOffcanvasVisible) && (
|
|
248
|
+
<div
|
|
249
|
+
className="offcanvas-backdrop fade show"
|
|
250
|
+
onClick={closeOffcanvas}
|
|
251
|
+
style={{
|
|
252
|
+
position: 'fixed',
|
|
253
|
+
top: 0,
|
|
254
|
+
left: 0,
|
|
255
|
+
width: '100%',
|
|
256
|
+
height: '100%',
|
|
257
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
258
|
+
zIndex: 1040,
|
|
259
|
+
}}
|
|
260
|
+
></div>
|
|
261
|
+
)}
|
|
262
|
+
|
|
263
|
+
{/* Mobile Offcanvas Components */}
|
|
264
|
+
{isMobile && (
|
|
265
|
+
<>
|
|
266
|
+
{/* Left Offcanvas */}
|
|
267
|
+
<div
|
|
268
|
+
className={`offcanvas offcanvas-start ${leftOffcanvasVisible ? 'show' : ''
|
|
269
|
+
} ${sidebarColorClass}`}
|
|
270
|
+
tabIndex={-1}
|
|
271
|
+
style={{
|
|
272
|
+
// visibility: leftOffcanvasVisible ? 'visible' : 'hidden',
|
|
273
|
+
width: (windowWidth < 400 ? windowWidth - 50 : 300) + 'px',
|
|
274
|
+
zIndex: 1050,
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
<LeftBarContent collapsed={leftBarCollapsed && !isMobile} toggleCollapsed={() => setLeftOffcanvasVisible(false)} />
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
{/* Right Offcanvas */}
|
|
281
|
+
<div
|
|
282
|
+
className={`offcanvas offcanvas-end ${rightOffcanvasVisible ? 'show' : ''
|
|
283
|
+
} ${sidebarColorClass}`}
|
|
284
|
+
tabIndex={-1}
|
|
285
|
+
style={{
|
|
286
|
+
visibility: rightOffcanvasVisible ? 'visible' : 'hidden',
|
|
287
|
+
width: '100%',
|
|
288
|
+
zIndex: 1050,
|
|
289
|
+
}}
|
|
290
|
+
>
|
|
291
|
+
<RightBarContent />
|
|
292
|
+
</div>
|
|
293
|
+
</>
|
|
294
|
+
)}
|
|
295
|
+
</>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { FieldType, newid, getAllTables, getIconClassName } from "@peers-app/peers-sdk";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ListScreen } from "../components/list-screen";
|
|
5
|
+
import { mainContentPath } from "../globals";
|
|
6
|
+
import { registerInternalPeersUI } from "../ui-router/ui-loader";
|
|
7
|
+
|
|
8
|
+
const propsSchema = z.object({
|
|
9
|
+
// items: zodAnyObject.array().describe('Items to display in the list'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
type IProps = z.infer<typeof propsSchema>;
|
|
13
|
+
|
|
14
|
+
export const DefaultListScreen = (props: IProps) => {
|
|
15
|
+
const path = mainContentPath().toLowerCase().trim().split('?')[0].split('#').pop()?.split('/')[0] || '';
|
|
16
|
+
const fuzzyTableName = ({
|
|
17
|
+
variables: 'persistent_vars',
|
|
18
|
+
"events": 'peer_event_types',
|
|
19
|
+
}[path] || path).replace(/[_-]/g, '').trim();
|
|
20
|
+
|
|
21
|
+
const allTables = getAllTables();
|
|
22
|
+
const tableName = Object.keys(allTables).find(t => t.toLowerCase().replace(/[_-]/g, '').trim() === fuzzyTableName);
|
|
23
|
+
const table = allTables[tableName || ''];
|
|
24
|
+
if (!table) {
|
|
25
|
+
return (
|
|
26
|
+
<div className="m-4">
|
|
27
|
+
Table not found for path: "{path}"
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const idField = table.metaData.fields.find(f => f.name === table.metaData.primaryKeyName);
|
|
32
|
+
if (!idField) {
|
|
33
|
+
throw new Error('No primary key field found for table');
|
|
34
|
+
}
|
|
35
|
+
const nameField = table.metaData.fields.find(f => f.name === 'name') ||
|
|
36
|
+
table.metaData.fields.find(f => f.name === 'title') ||
|
|
37
|
+
table.metaData.fields.find(f => f.type === FieldType.string);
|
|
38
|
+
if (!nameField) {
|
|
39
|
+
throw new Error('No name field found to create new record with');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<ListScreen
|
|
44
|
+
key={path}
|
|
45
|
+
{...{
|
|
46
|
+
table,
|
|
47
|
+
sortBy: [`-${idField.name}`],
|
|
48
|
+
newRecord: async (text: string) => {
|
|
49
|
+
text = text.trim().replace(/\s+/g, '_');
|
|
50
|
+
let item = table.initRecord({
|
|
51
|
+
[idField.name]: newid(),
|
|
52
|
+
[nameField?.name]: text,
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
item = await table.insert(item);
|
|
56
|
+
mainContentPath(`${path}/${item[idField.name]}`);
|
|
57
|
+
return item;
|
|
58
|
+
},
|
|
59
|
+
renderItem: (item: Record<string, any>) => {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
key={item[idField.name]}
|
|
63
|
+
className='container-fluid pb-4'
|
|
64
|
+
>
|
|
65
|
+
<i className={getIconClassName(table)}></i>
|
|
66
|
+
<a href={`#${path}/${item[idField.name]}`}>
|
|
67
|
+
{item.name || '<empty-name>'}
|
|
68
|
+
</a>
|
|
69
|
+
<div style={{ paddingLeft: '20px' }}>
|
|
70
|
+
{/* <MarkdownWithMentions content={item.description || ''} /> */}
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
)
|
|
74
|
+
},
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
registerInternalPeersUI({
|
|
81
|
+
peersUIId: '00m5fql0x5v48vyrk5bllzdrr',
|
|
82
|
+
component: DefaultListScreen,
|
|
83
|
+
routes: [
|
|
84
|
+
{
|
|
85
|
+
// KnowledgeValue with PeerType: Note
|
|
86
|
+
isMatch: (props, context) => context.path.split('/').length === 1,
|
|
87
|
+
uiEditMode: 'view',
|
|
88
|
+
uiCategory: 'screen',
|
|
89
|
+
uiSubcategory: 'list',
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { computed, IDoc, IKnowledgeValue, knowledgeValueSchema, Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { MarkdownEditorInline } from "../components/markdown-editor/editor-inline";
|
|
5
|
+
import { registerInternalPeersUI } from "../ui-router/ui-loader";
|
|
6
|
+
|
|
7
|
+
interface IProps {
|
|
8
|
+
markdown: Observable<string>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const FullScreenMarkdownEditor = (props: IProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<MarkdownEditorInline
|
|
14
|
+
value={props.markdown}
|
|
15
|
+
maxHeight={'calc(100vh - 160px)'}
|
|
16
|
+
autoFocus
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
registerInternalPeersUI({
|
|
22
|
+
peersUIId: '00m4rof6uwka5kfi6t7rav8t3',
|
|
23
|
+
component: (props: { knowledgeValue: IDoc<IKnowledgeValue> }) => {
|
|
24
|
+
const doc = props.knowledgeValue;
|
|
25
|
+
const markdown = computed({
|
|
26
|
+
read: () => doc.value?.body || '',
|
|
27
|
+
write: (value: string) => {
|
|
28
|
+
doc.value.body = value;
|
|
29
|
+
doc.qs.value.notifySubscribers();
|
|
30
|
+
doc.q(doc.q() + 1);
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
return (
|
|
34
|
+
<FullScreenMarkdownEditor
|
|
35
|
+
key={doc.knowledgeValueId}
|
|
36
|
+
markdown={markdown as any}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
propsSchema: z.object({
|
|
41
|
+
knowledgeValue: knowledgeValueSchema as any, // TODO fix this
|
|
42
|
+
}),
|
|
43
|
+
routes: [
|
|
44
|
+
{
|
|
45
|
+
// KnowledgeValue with PeerType: Note
|
|
46
|
+
isMatch: (props, context) => props.knowledgeValue?.peerTypeId === '00m3g0ntcop3mrh6ynuzgekiy',
|
|
47
|
+
uiEditMode: 'edit',
|
|
48
|
+
uiCategory: 'details',
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { debounceByArgs, IPackage, IPeersPackageRoutes, observable, Packages, rpcServerCalls } from "@peers-app/peers-sdk";
|
|
2
|
+
import "../ui-defaults";
|
|
3
|
+
|
|
4
|
+
export const allPackages = observable<IPackage[]>([]);
|
|
5
|
+
export const allRoutesLoaded = observable(false);
|
|
6
|
+
|
|
7
|
+
Packages().dataChanged.subscribe(async evt => {
|
|
8
|
+
if (!allRoutesLoaded()) return;
|
|
9
|
+
const _allPackages = allPackages();
|
|
10
|
+
if (evt.op === 'insert') {
|
|
11
|
+
_allPackages.push(evt.dataObject);
|
|
12
|
+
} else if (evt.op === 'delete') {
|
|
13
|
+
let idx = allPackages().findIndex(p => p.packageId === evt.dataObject.packageId);
|
|
14
|
+
if (idx >= 0) {
|
|
15
|
+
_allPackages.splice(idx, 1);
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
let idx = allPackages().findIndex(p => p.packageId === evt.dataObject.packageId);
|
|
19
|
+
if (idx >= 0) {
|
|
20
|
+
_allPackages[idx] = evt.dataObject;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
allPackages([..._allPackages]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const loadAllRoutes = async () => {
|
|
27
|
+
if (allRoutesLoaded()) return;
|
|
28
|
+
// Filter packages that have UI bundles (routesBundleFileId or uiBundleFileId)
|
|
29
|
+
let packagesWithUI = await Packages().list({
|
|
30
|
+
disabled: { $ne: true },
|
|
31
|
+
routesBundleFileId: { $exists: true },
|
|
32
|
+
});
|
|
33
|
+
allPackages(packagesWithUI);
|
|
34
|
+
await Promise.all(
|
|
35
|
+
packagesWithUI.map(pkg => loadRoutesBundle(pkg))
|
|
36
|
+
);
|
|
37
|
+
allRoutesLoaded(true);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const routeLoadingPromises: Record<string, Promise<any>> = {};
|
|
42
|
+
function loadRoutesBundle(pkg: IPackage, forceRefresh?: boolean): Promise<any> {
|
|
43
|
+
// Dynamically import the bundle
|
|
44
|
+
let importPromise: Promise<any> = routeLoadingPromises[pkg.packageId];
|
|
45
|
+
if (!importPromise || forceRefresh) {
|
|
46
|
+
console.log(`loading routes bundle for ${pkg.name}`);
|
|
47
|
+
// just importing the module (running it) should be registering all of the package UIs with the Peers App runtime
|
|
48
|
+
|
|
49
|
+
importPromise = (async () => {
|
|
50
|
+
try {
|
|
51
|
+
while (!(window as any).registerPeersUIRoute) {
|
|
52
|
+
console.log(`waiting for registerPeersUIRoute to be defined on the window object`);
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
54
|
+
}
|
|
55
|
+
let bundleCode = '';
|
|
56
|
+
if (pkg.routesBundleFileId) {
|
|
57
|
+
bundleCode = await rpcServerCalls.getFileContents(pkg.routesBundleFileId);
|
|
58
|
+
}
|
|
59
|
+
if (bundleCode) {
|
|
60
|
+
const exportRoutes = (peerRoutes: IPeersPackageRoutes) => {
|
|
61
|
+
peerRoutes.routes.forEach(route => {
|
|
62
|
+
// TODO maybe add package that this came from
|
|
63
|
+
(window as any).registerPeersUIRoute(route);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const bundleFunction = new Function('exportRoutes', bundleCode);
|
|
68
|
+
bundleFunction(exportRoutes);
|
|
69
|
+
|
|
70
|
+
return {};
|
|
71
|
+
} else {
|
|
72
|
+
console.warn(`Routes bundle file not found for ${pkg.name} (fileId: ${pkg.routesBundleFileId})`);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error(`Error while loading routes bundle for ${pkg.name}`, err);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
|
|
81
|
+
routeLoadingPromises[pkg.packageId] = importPromise;
|
|
82
|
+
}
|
|
83
|
+
return importPromise;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const reloadPackage = debounceByArgs(async (packageId: string) => {
|
|
87
|
+
const pkg = await Packages().get(packageId);
|
|
88
|
+
if (pkg) {
|
|
89
|
+
await loadRoutesBundle(pkg, true);
|
|
90
|
+
}
|
|
91
|
+
}, 200)
|
|
92
|
+
|
|
93
|
+
Packages().dataChanged.subscribe(evt => {
|
|
94
|
+
const pkg = evt.dataObject;
|
|
95
|
+
const loadingPromise = routeLoadingPromises[pkg.packageId];
|
|
96
|
+
if (!loadingPromise) return;
|
|
97
|
+
reloadPackage(pkg.packageId);
|
|
98
|
+
})
|