@open-mercato/documents 0.6.8-develop.7016.1.4ed7b1e49d
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 +88 -0
- package/build.mjs +23 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/dist/modules/documents/acl.js +15 -0
- package/dist/modules/documents/acl.js.map +7 -0
- package/dist/modules/documents/api/[id]/archive/route.js +116 -0
- package/dist/modules/documents/api/[id]/archive/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js +155 -0
- package/dist/modules/documents/api/[id]/attachments/[attachmentId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/attachments/route.js +153 -0
- package/dist/modules/documents/api/[id]/attachments/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/collab-token/route.js +180 -0
- package/dist/modules/documents/api/[id]/collab-token/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js +86 -0
- package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/comments/route.js +387 -0
- package/dist/modules/documents/api/[id]/comments/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/content/route.js +143 -0
- package/dist/modules/documents/api/[id]/content/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/duplicate/route.js +200 -0
- package/dist/modules/documents/api/[id]/duplicate/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/export/route.js +421 -0
- package/dist/modules/documents/api/[id]/export/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/favorite/route.js +96 -0
- package/dist/modules/documents/api/[id]/favorite/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/links/[linkId]/route.js +85 -0
- package/dist/modules/documents/api/[id]/links/[linkId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/links/route.js +257 -0
- package/dist/modules/documents/api/[id]/links/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/principals/route.js +299 -0
- package/dist/modules/documents/api/[id]/principals/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/route.js +246 -0
- package/dist/modules/documents/api/[id]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/shares/route.js +335 -0
- package/dist/modules/documents/api/[id]/shares/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/unarchive/route.js +39 -0
- package/dist/modules/documents/api/[id]/unarchive/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js +133 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/restore/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/route.js +93 -0
- package/dist/modules/documents/api/[id]/versions/[versionId]/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/versions/route.js +193 -0
- package/dist/modules/documents/api/[id]/versions/route.js.map +7 -0
- package/dist/modules/documents/api/[id]/watch/route.js +97 -0
- package/dist/modules/documents/api/[id]/watch/route.js.map +7 -0
- package/dist/modules/documents/api/_commands.js +34 -0
- package/dist/modules/documents/api/_commands.js.map +7 -0
- package/dist/modules/documents/api/_shared.js +490 -0
- package/dist/modules/documents/api/_shared.js.map +7 -0
- package/dist/modules/documents/api/folders/route.js +256 -0
- package/dist/modules/documents/api/folders/route.js.map +7 -0
- package/dist/modules/documents/api/instantiate/route.js +108 -0
- package/dist/modules/documents/api/instantiate/route.js.map +7 -0
- package/dist/modules/documents/api/route.js +322 -0
- package/dist/modules/documents/api/route.js.map +7 -0
- package/dist/modules/documents/api/templates/[templateId]/preview/route.js +94 -0
- package/dist/modules/documents/api/templates/[templateId]/preview/route.js.map +7 -0
- package/dist/modules/documents/api/templates/[templateId]/route.js +82 -0
- package/dist/modules/documents/api/templates/[templateId]/route.js.map +7 -0
- package/dist/modules/documents/api/templates/route.js +344 -0
- package/dist/modules/documents/api/templates/route.js.map +7 -0
- package/dist/modules/documents/backend/documents/DocumentsPageClient.js +160 -0
- package/dist/modules/documents/backend/documents/DocumentsPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/DocumentsTable.js +143 -0
- package/dist/modules/documents/backend/documents/DocumentsTable.js.map +7 -0
- package/dist/modules/documents/backend/documents/FolderDialog.js +55 -0
- package/dist/modules/documents/backend/documents/FolderDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/FolderTree.js +40 -0
- package/dist/modules/documents/backend/documents/FolderTree.js.map +7 -0
- package/dist/modules/documents/backend/documents/MoveDocumentDialog.js +64 -0
- package/dist/modules/documents/backend/documents/MoveDocumentDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js +77 -0
- package/dist/modules/documents/backend/documents/[id]/CommentAnchorNavigation.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentComposer.js +126 -0
- package/dist/modules/documents/backend/documents/[id]/CommentComposer.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js +88 -0
- package/dist/modules/documents/backend/documents/[id]/CommentThreadList.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/CommentsRail.js +123 -0
- package/dist/modules/documents/backend/documents/[id]/CommentsRail.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +91 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js +27 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +50 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +168 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js +129 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentNavigator.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +429 -0
- package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js +68 -0
- package/dist/modules/documents/backend/documents/[id]/EditorColorTools.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js +69 -0
- package/dist/modules/documents/backend/documents/[id]/EditorStatusPresence.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js +151 -0
- package/dist/modules/documents/backend/documents/[id]/EditorToolbar.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/ExportMenu.js +121 -0
- package/dist/modules/documents/backend/documents/[id]/ExportMenu.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/MentionPicker.js +114 -0
- package/dist/modules/documents/backend/documents/[id]/MentionPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/OutlinePane.js +70 -0
- package/dist/modules/documents/backend/documents/[id]/OutlinePane.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js +157 -0
- package/dist/modules/documents/backend/documents/[id]/RecordFieldsDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js +266 -0
- package/dist/modules/documents/backend/documents/[id]/RelatedRecordsPanel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +227 -0
- package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +157 -0
- package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/commentTypes.js +150 -0
- package/dist/modules/documents/backend/documents/[id]/commentTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js +13 -0
- package/dist/modules/documents/backend/documents/[id]/componentCapabilities.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/documentPagination.js +295 -0
- package/dist/modules/documents/backend/documents/[id]/documentPagination.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js +81 -0
- package/dist/modules/documents/backend/documents/[id]/editorPresenceStyles.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js +52 -0
- package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/page.js +10 -0
- package/dist/modules/documents/backend/documents/[id]/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/page.meta.js +16 -0
- package/dist/modules/documents/backend/documents/[id]/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js +38 -0
- package/dist/modules/documents/backend/documents/[id]/relatedRecordModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/restoreVersion.js +33 -0
- package/dist/modules/documents/backend/documents/[id]/restoreVersion.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js +392 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentCollaboration.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +253 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +149 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js +82 -0
- package/dist/modules/documents/backend/documents/[id]/useDocumentTitle.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js +144 -0
- package/dist/modules/documents/backend/documents/[id]/useEditorInsertions.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js +237 -0
- package/dist/modules/documents/backend/documents/[id]/useFallbackContentPersistence.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js +216 -0
- package/dist/modules/documents/backend/documents/[id]/useMentionPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js +25 -0
- package/dist/modules/documents/backend/documents/[id]/versionHistoryModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/EntityPicker.js +156 -0
- package/dist/modules/documents/backend/documents/components/EntityPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/EntityPickerResults.js +46 -0
- package/dist/modules/documents/backend/documents/components/EntityPickerResults.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js +127 -0
- package/dist/modules/documents/backend/documents/components/NewFromTemplateDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/PrincipalPicker.js +84 -0
- package/dist/modules/documents/backend/documents/components/PrincipalPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialog.js +77 -0
- package/dist/modules/documents/backend/documents/components/ShareDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js +93 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogAddForm.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogList.js +82 -0
- package/dist/modules/documents/backend/documents/components/ShareDialogList.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +96 -0
- package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js +169 -0
- package/dist/modules/documents/backend/documents/components/TemplateEditorDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js +38 -0
- package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js +69 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotFields.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js +71 -0
- package/dist/modules/documents/backend/documents/components/TemplateSlotsEditor.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/principalPickerModel.js +63 -0
- package/dist/modules/documents/backend/documents/components/principalPickerModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/shareDialogModel.js +68 -0
- package/dist/modules/documents/backend/documents/components/shareDialogModel.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/templateUi.js +89 -0
- package/dist/modules/documents/backend/documents/components/templateUi.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js +30 -0
- package/dist/modules/documents/backend/documents/components/useAvailableEntityRegistry.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useEntitySearch.js +191 -0
- package/dist/modules/documents/backend/documents/components/useEntitySearch.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js +221 -0
- package/dist/modules/documents/backend/documents/components/usePrincipalPicker.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useShareDialog.js +236 -0
- package/dist/modules/documents/backend/documents/components/useShareDialog.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useTemplateDetail.js +49 -0
- package/dist/modules/documents/backend/documents/components/useTemplateDetail.js.map +7 -0
- package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js +234 -0
- package/dist/modules/documents/backend/documents/components/useTemplateInstantiation.js.map +7 -0
- package/dist/modules/documents/backend/documents/documentUi.js +106 -0
- package/dist/modules/documents/backend/documents/documentUi.js.map +7 -0
- package/dist/modules/documents/backend/documents/documentsListTypes.js +132 -0
- package/dist/modules/documents/backend/documents/documentsListTypes.js.map +7 -0
- package/dist/modules/documents/backend/documents/page.js +9 -0
- package/dist/modules/documents/backend/documents/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/page.meta.js +26 -0
- package/dist/modules/documents/backend/documents/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js +91 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesPageClient.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesTable.js +58 -0
- package/dist/modules/documents/backend/documents/templates/TemplatesTable.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/page.js +9 -0
- package/dist/modules/documents/backend/documents/templates/page.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/page.meta.js +34 -0
- package/dist/modules/documents/backend/documents/templates/page.meta.js.map +7 -0
- package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js +139 -0
- package/dist/modules/documents/backend/documents/templates/useTemplatesPage.js.map +7 -0
- package/dist/modules/documents/backend/documents/useDocumentsList.js +314 -0
- package/dist/modules/documents/backend/documents/useDocumentsList.js.map +7 -0
- package/dist/modules/documents/ce.js +8 -0
- package/dist/modules/documents/ce.js.map +7 -0
- package/dist/modules/documents/commands/aggregate.js +99 -0
- package/dist/modules/documents/commands/aggregate.js.map +7 -0
- package/dist/modules/documents/commands/attachments.js +252 -0
- package/dist/modules/documents/commands/attachments.js.map +7 -0
- package/dist/modules/documents/commands/comments.js +782 -0
- package/dist/modules/documents/commands/comments.js.map +7 -0
- package/dist/modules/documents/commands/content.js +238 -0
- package/dist/modules/documents/commands/content.js.map +7 -0
- package/dist/modules/documents/commands/document-crud.js +505 -0
- package/dist/modules/documents/commands/document-crud.js.map +7 -0
- package/dist/modules/documents/commands/documents.js +473 -0
- package/dist/modules/documents/commands/documents.js.map +7 -0
- package/dist/modules/documents/commands/duplicate.js +640 -0
- package/dist/modules/documents/commands/duplicate.js.map +7 -0
- package/dist/modules/documents/commands/favorites.js +150 -0
- package/dist/modules/documents/commands/favorites.js.map +7 -0
- package/dist/modules/documents/commands/folders.js +420 -0
- package/dist/modules/documents/commands/folders.js.map +7 -0
- package/dist/modules/documents/commands/index.js +64 -0
- package/dist/modules/documents/commands/index.js.map +7 -0
- package/dist/modules/documents/commands/interceptors.js +300 -0
- package/dist/modules/documents/commands/interceptors.js.map +7 -0
- package/dist/modules/documents/commands/lifecycle.js +249 -0
- package/dist/modules/documents/commands/lifecycle.js.map +7 -0
- package/dist/modules/documents/commands/links.js +410 -0
- package/dist/modules/documents/commands/links.js.map +7 -0
- package/dist/modules/documents/commands/mutation-helpers.js +42 -0
- package/dist/modules/documents/commands/mutation-helpers.js.map +7 -0
- package/dist/modules/documents/commands/projection-types.js +1 -0
- package/dist/modules/documents/commands/projection-types.js.map +7 -0
- package/dist/modules/documents/commands/shared.js +143 -0
- package/dist/modules/documents/commands/shared.js.map +7 -0
- package/dist/modules/documents/commands/shares.js +527 -0
- package/dist/modules/documents/commands/shares.js.map +7 -0
- package/dist/modules/documents/commands/side-effects.js +103 -0
- package/dist/modules/documents/commands/side-effects.js.map +7 -0
- package/dist/modules/documents/commands/templates.js +461 -0
- package/dist/modules/documents/commands/templates.js.map +7 -0
- package/dist/modules/documents/commands/versions.js +432 -0
- package/dist/modules/documents/commands/versions.js.map +7 -0
- package/dist/modules/documents/commands/watchers.js +164 -0
- package/dist/modules/documents/commands/watchers.js.map +7 -0
- package/dist/modules/documents/data/entities.js +653 -0
- package/dist/modules/documents/data/entities.js.map +7 -0
- package/dist/modules/documents/data/extensions.js +44 -0
- package/dist/modules/documents/data/extensions.js.map +7 -0
- package/dist/modules/documents/data/validators.js +219 -0
- package/dist/modules/documents/data/validators.js.map +7 -0
- package/dist/modules/documents/di.js +35 -0
- package/dist/modules/documents/di.js.map +7 -0
- package/dist/modules/documents/encryption.js +12 -0
- package/dist/modules/documents/encryption.js.map +7 -0
- package/dist/modules/documents/events.js +27 -0
- package/dist/modules/documents/events.js.map +7 -0
- package/dist/modules/documents/index.js +19 -0
- package/dist/modules/documents/index.js.map +7 -0
- package/dist/modules/documents/lib/attachmentServicePort.js +30 -0
- package/dist/modules/documents/lib/attachmentServicePort.js.map +7 -0
- package/dist/modules/documents/lib/capabilities.js +32 -0
- package/dist/modules/documents/lib/capabilities.js.map +7 -0
- package/dist/modules/documents/lib/collabCloseEvents.js +17 -0
- package/dist/modules/documents/lib/collabCloseEvents.js.map +7 -0
- package/dist/modules/documents/lib/collabEndpoint.js +22 -0
- package/dist/modules/documents/lib/collabEndpoint.js.map +7 -0
- package/dist/modules/documents/lib/collabMaterializer.js +107 -0
- package/dist/modules/documents/lib/collabMaterializer.js.map +7 -0
- package/dist/modules/documents/lib/collabToken.js +120 -0
- package/dist/modules/documents/lib/collabToken.js.map +7 -0
- package/dist/modules/documents/lib/collaborationAwareness.js +68 -0
- package/dist/modules/documents/lib/collaborationAwareness.js.map +7 -0
- package/dist/modules/documents/lib/commentAnchors.js +15 -0
- package/dist/modules/documents/lib/commentAnchors.js.map +7 -0
- package/dist/modules/documents/lib/constants.js +25 -0
- package/dist/modules/documents/lib/constants.js.map +7 -0
- package/dist/modules/documents/lib/contentService.js +248 -0
- package/dist/modules/documents/lib/contentService.js.map +7 -0
- package/dist/modules/documents/lib/displayLabels.js +23 -0
- package/dist/modules/documents/lib/displayLabels.js.map +7 -0
- package/dist/modules/documents/lib/docxRenderer.js +601 -0
- package/dist/modules/documents/lib/docxRenderer.js.map +7 -0
- package/dist/modules/documents/lib/duplicateContent.js +22 -0
- package/dist/modules/documents/lib/duplicateContent.js.map +7 -0
- package/dist/modules/documents/lib/editorConfig.js +287 -0
- package/dist/modules/documents/lib/editorConfig.js.map +7 -0
- package/dist/modules/documents/lib/entityLinks.js +148 -0
- package/dist/modules/documents/lib/entityLinks.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistry.js +258 -0
- package/dist/modules/documents/lib/entityRegistry.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistry.server.js +189 -0
- package/dist/modules/documents/lib/entityRegistry.server.js.map +7 -0
- package/dist/modules/documents/lib/entityRegistryAvailability.server.js +9 -0
- package/dist/modules/documents/lib/entityRegistryAvailability.server.js.map +7 -0
- package/dist/modules/documents/lib/entitySuggestion.js +50 -0
- package/dist/modules/documents/lib/entitySuggestion.js.map +7 -0
- package/dist/modules/documents/lib/favorites.js +22 -0
- package/dist/modules/documents/lib/favorites.js.map +7 -0
- package/dist/modules/documents/lib/folderHierarchySerialization.js +19 -0
- package/dist/modules/documents/lib/folderHierarchySerialization.js.map +7 -0
- package/dist/modules/documents/lib/historyLimits.js +100 -0
- package/dist/modules/documents/lib/historyLimits.js.map +7 -0
- package/dist/modules/documents/lib/historyPolicy.js +14 -0
- package/dist/modules/documents/lib/historyPolicy.js.map +7 -0
- package/dist/modules/documents/lib/organizationAccess.js +17 -0
- package/dist/modules/documents/lib/organizationAccess.js.map +7 -0
- package/dist/modules/documents/lib/pdfHtml.js +62 -0
- package/dist/modules/documents/lib/pdfHtml.js.map +7 -0
- package/dist/modules/documents/lib/pdfRenderer.js +284 -0
- package/dist/modules/documents/lib/pdfRenderer.js.map +7 -0
- package/dist/modules/documents/lib/permissions.js +222 -0
- package/dist/modules/documents/lib/permissions.js.map +7 -0
- package/dist/modules/documents/lib/platformServices.js +35 -0
- package/dist/modules/documents/lib/platformServices.js.map +7 -0
- package/dist/modules/documents/lib/recordFieldInsertion.js +58 -0
- package/dist/modules/documents/lib/recordFieldInsertion.js.map +7 -0
- package/dist/modules/documents/lib/requestBody.js +80 -0
- package/dist/modules/documents/lib/requestBody.js.map +7 -0
- package/dist/modules/documents/lib/resourceLimits.js +62 -0
- package/dist/modules/documents/lib/resourceLimits.js.map +7 -0
- package/dist/modules/documents/lib/shareCounts.js +25 -0
- package/dist/modules/documents/lib/shareCounts.js.map +7 -0
- package/dist/modules/documents/lib/templateFill.js +84 -0
- package/dist/modules/documents/lib/templateFill.js.map +7 -0
- package/dist/modules/documents/lib/templateInstantiation.js +147 -0
- package/dist/modules/documents/lib/templateInstantiation.js.map +7 -0
- package/dist/modules/documents/lib/templatePreviewDigest.js +82 -0
- package/dist/modules/documents/lib/templatePreviewDigest.js.map +7 -0
- package/dist/modules/documents/lib/templateSeeds.js +201 -0
- package/dist/modules/documents/lib/templateSeeds.js.map +7 -0
- package/dist/modules/documents/lib/userLabels.js +37 -0
- package/dist/modules/documents/lib/userLabels.js.map +7 -0
- package/dist/modules/documents/lib/versionContent.js +131 -0
- package/dist/modules/documents/lib/versionContent.js.map +7 -0
- package/dist/modules/documents/lib/versionLabels.js +12 -0
- package/dist/modules/documents/lib/versionLabels.js.map +7 -0
- package/dist/modules/documents/lib/versioning.js +14 -0
- package/dist/modules/documents/lib/versioning.js.map +7 -0
- package/dist/modules/documents/lib/visibility.js +422 -0
- package/dist/modules/documents/lib/visibility.js.map +7 -0
- package/dist/modules/documents/lib/watchers.js +106 -0
- package/dist/modules/documents/lib/watchers.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260708163836_documents.js +44 -0
- package/dist/modules/documents/migrations/Migration20260708163836_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260709164720_documents.js +17 -0
- package/dist/modules/documents/migrations/Migration20260709164720_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260710002318_documents.js +32 -0
- package/dist/modules/documents/migrations/Migration20260710002318_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260710071003_documents.js +13 -0
- package/dist/modules/documents/migrations/Migration20260710071003_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260712120000_documents.js +13 -0
- package/dist/modules/documents/migrations/Migration20260712120000_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260712183000_documents.js +14 -0
- package/dist/modules/documents/migrations/Migration20260712183000_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260713092156_documents.js +29 -0
- package/dist/modules/documents/migrations/Migration20260713092156_documents.js.map +7 -0
- package/dist/modules/documents/migrations/Migration20260717000000_documents.js +37 -0
- package/dist/modules/documents/migrations/Migration20260717000000_documents.js.map +7 -0
- package/dist/modules/documents/notifications.js +47 -0
- package/dist/modules/documents/notifications.js.map +7 -0
- package/dist/modules/documents/search.js +101 -0
- package/dist/modules/documents/search.js.map +7 -0
- package/dist/modules/documents/setup.js +19 -0
- package/dist/modules/documents/setup.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js +214 -0
- package/dist/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/context.js +84 -0
- package/dist/modules/documents/widgets/injection/related-documents/context.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js +98 -0
- package/dist/modules/documents/widgets/injection/related-documents/useRelatedDocuments.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +83 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +7 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.js +19 -0
- package/dist/modules/documents/widgets/injection/related-documents/widget.js.map +7 -0
- package/dist/modules/documents/widgets/injection-table.js +21 -0
- package/dist/modules/documents/widgets/injection-table.js.map +7 -0
- package/dist/server/documents-collab-server.js +2260 -0
- package/dist/server/documents-collab-server.js.map +7 -0
- package/generated/entities/document/index.ts +12 -0
- package/generated/entities/document_attachment/index.ts +9 -0
- package/generated/entities/document_comment/index.ts +14 -0
- package/generated/entities/document_content/index.ts +11 -0
- package/generated/entities/document_entity_link/index.ts +19 -0
- package/generated/entities/document_favorite/index.ts +7 -0
- package/generated/entities/document_folder/index.ts +9 -0
- package/generated/entities/document_share/index.ts +11 -0
- package/generated/entities/document_template/index.ts +13 -0
- package/generated/entities/document_version/index.ts +9 -0
- package/generated/entities/document_watcher/index.ts +7 -0
- package/generated/entities.ids.generated.ts +21 -0
- package/generated/entity-fields-registry.ts +151 -0
- package/jest.config.cjs +34 -0
- package/package.json +149 -0
- package/server/documents-collab-server.ts +3416 -0
- package/src/index.ts +1 -0
- package/src/modules/documents/acl.ts +11 -0
- package/src/modules/documents/api/[id]/archive/route.ts +132 -0
- package/src/modules/documents/api/[id]/attachments/[attachmentId]/route.ts +166 -0
- package/src/modules/documents/api/[id]/attachments/route.ts +173 -0
- package/src/modules/documents/api/[id]/collab-token/route.ts +203 -0
- package/src/modules/documents/api/[id]/comments/access-check/route.ts +96 -0
- package/src/modules/documents/api/[id]/comments/route.ts +442 -0
- package/src/modules/documents/api/[id]/content/route.ts +156 -0
- package/src/modules/documents/api/[id]/duplicate/route.ts +231 -0
- package/src/modules/documents/api/[id]/export/route.ts +535 -0
- package/src/modules/documents/api/[id]/favorite/route.ts +110 -0
- package/src/modules/documents/api/[id]/links/[linkId]/route.ts +92 -0
- package/src/modules/documents/api/[id]/links/route.ts +301 -0
- package/src/modules/documents/api/[id]/principals/route.ts +375 -0
- package/src/modules/documents/api/[id]/route.ts +267 -0
- package/src/modules/documents/api/[id]/shares/route.ts +372 -0
- package/src/modules/documents/api/[id]/unarchive/route.ts +42 -0
- package/src/modules/documents/api/[id]/versions/[versionId]/restore/route.ts +152 -0
- package/src/modules/documents/api/[id]/versions/[versionId]/route.ts +100 -0
- package/src/modules/documents/api/[id]/versions/route.ts +207 -0
- package/src/modules/documents/api/[id]/watch/route.ts +111 -0
- package/src/modules/documents/api/_commands.ts +53 -0
- package/src/modules/documents/api/_shared.ts +676 -0
- package/src/modules/documents/api/folders/route.ts +287 -0
- package/src/modules/documents/api/instantiate/route.ts +114 -0
- package/src/modules/documents/api/route.ts +362 -0
- package/src/modules/documents/api/templates/[templateId]/preview/route.ts +97 -0
- package/src/modules/documents/api/templates/[templateId]/route.ts +92 -0
- package/src/modules/documents/api/templates/route.ts +370 -0
- package/src/modules/documents/backend/documents/DocumentsPageClient.tsx +150 -0
- package/src/modules/documents/backend/documents/DocumentsTable.tsx +168 -0
- package/src/modules/documents/backend/documents/FolderDialog.tsx +62 -0
- package/src/modules/documents/backend/documents/FolderTree.tsx +72 -0
- package/src/modules/documents/backend/documents/MoveDocumentDialog.tsx +70 -0
- package/src/modules/documents/backend/documents/[id]/CommentAnchorNavigation.ts +88 -0
- package/src/modules/documents/backend/documents/[id]/CommentComposer.tsx +136 -0
- package/src/modules/documents/backend/documents/[id]/CommentThreadList.tsx +131 -0
- package/src/modules/documents/backend/documents/[id]/CommentsRail.tsx +138 -0
- package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +111 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorErrorBoundary.tsx +39 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +50 -0
- package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +162 -0
- package/src/modules/documents/backend/documents/[id]/DocumentNavigator.tsx +129 -0
- package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +463 -0
- package/src/modules/documents/backend/documents/[id]/EditorColorTools.tsx +71 -0
- package/src/modules/documents/backend/documents/[id]/EditorStatusPresence.tsx +78 -0
- package/src/modules/documents/backend/documents/[id]/EditorToolbar.tsx +108 -0
- package/src/modules/documents/backend/documents/[id]/ExportMenu.tsx +144 -0
- package/src/modules/documents/backend/documents/[id]/MentionPicker.tsx +137 -0
- package/src/modules/documents/backend/documents/[id]/OutlinePane.tsx +98 -0
- package/src/modules/documents/backend/documents/[id]/RecordFieldsDialog.tsx +185 -0
- package/src/modules/documents/backend/documents/[id]/RelatedRecordsPanel.tsx +320 -0
- package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +244 -0
- package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +197 -0
- package/src/modules/documents/backend/documents/[id]/commentTypes.ts +192 -0
- package/src/modules/documents/backend/documents/[id]/componentCapabilities.ts +17 -0
- package/src/modules/documents/backend/documents/[id]/documentPagination.ts +352 -0
- package/src/modules/documents/backend/documents/[id]/editorPresenceStyles.ts +77 -0
- package/src/modules/documents/backend/documents/[id]/editorTypes.ts +84 -0
- package/src/modules/documents/backend/documents/[id]/page.meta.ts +12 -0
- package/src/modules/documents/backend/documents/[id]/page.tsx +6 -0
- package/src/modules/documents/backend/documents/[id]/relatedRecordModel.ts +49 -0
- package/src/modules/documents/backend/documents/[id]/restoreVersion.ts +49 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentCollaboration.ts +458 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +286 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +157 -0
- package/src/modules/documents/backend/documents/[id]/useDocumentTitle.ts +77 -0
- package/src/modules/documents/backend/documents/[id]/useEditorInsertions.ts +147 -0
- package/src/modules/documents/backend/documents/[id]/useFallbackContentPersistence.ts +277 -0
- package/src/modules/documents/backend/documents/[id]/useMentionPicker.ts +259 -0
- package/src/modules/documents/backend/documents/[id]/versionHistoryModel.ts +29 -0
- package/src/modules/documents/backend/documents/components/EntityPicker.tsx +171 -0
- package/src/modules/documents/backend/documents/components/EntityPickerResults.tsx +64 -0
- package/src/modules/documents/backend/documents/components/NewFromTemplateDialog.tsx +136 -0
- package/src/modules/documents/backend/documents/components/PrincipalPicker.tsx +90 -0
- package/src/modules/documents/backend/documents/components/ShareDialog.tsx +88 -0
- package/src/modules/documents/backend/documents/components/ShareDialogAddForm.tsx +113 -0
- package/src/modules/documents/backend/documents/components/ShareDialogList.tsx +117 -0
- package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +96 -0
- package/src/modules/documents/backend/documents/components/TemplateEditorDialog.tsx +171 -0
- package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +43 -0
- package/src/modules/documents/backend/documents/components/TemplateSlotFields.tsx +72 -0
- package/src/modules/documents/backend/documents/components/TemplateSlotsEditor.tsx +72 -0
- package/src/modules/documents/backend/documents/components/principalPickerModel.ts +86 -0
- package/src/modules/documents/backend/documents/components/shareDialogModel.ts +94 -0
- package/src/modules/documents/backend/documents/components/templateUi.ts +128 -0
- package/src/modules/documents/backend/documents/components/useAvailableEntityRegistry.ts +43 -0
- package/src/modules/documents/backend/documents/components/useEntitySearch.ts +197 -0
- package/src/modules/documents/backend/documents/components/usePrincipalPicker.ts +165 -0
- package/src/modules/documents/backend/documents/components/useShareDialog.ts +267 -0
- package/src/modules/documents/backend/documents/components/useTemplateDetail.ts +54 -0
- package/src/modules/documents/backend/documents/components/useTemplateInstantiation.ts +252 -0
- package/src/modules/documents/backend/documents/documentUi.ts +134 -0
- package/src/modules/documents/backend/documents/documentsListTypes.ts +163 -0
- package/src/modules/documents/backend/documents/page.meta.ts +24 -0
- package/src/modules/documents/backend/documents/page.tsx +5 -0
- package/src/modules/documents/backend/documents/templates/TemplatesPageClient.tsx +93 -0
- package/src/modules/documents/backend/documents/templates/TemplatesTable.tsx +71 -0
- package/src/modules/documents/backend/documents/templates/page.meta.ts +32 -0
- package/src/modules/documents/backend/documents/templates/page.tsx +5 -0
- package/src/modules/documents/backend/documents/templates/useTemplatesPage.tsx +148 -0
- package/src/modules/documents/backend/documents/useDocumentsList.tsx +305 -0
- package/src/modules/documents/ce.ts +6 -0
- package/src/modules/documents/commands/aggregate.ts +128 -0
- package/src/modules/documents/commands/attachments.ts +309 -0
- package/src/modules/documents/commands/comments.ts +966 -0
- package/src/modules/documents/commands/content.ts +294 -0
- package/src/modules/documents/commands/document-crud.ts +609 -0
- package/src/modules/documents/commands/documents.ts +581 -0
- package/src/modules/documents/commands/duplicate.ts +772 -0
- package/src/modules/documents/commands/favorites.ts +171 -0
- package/src/modules/documents/commands/folders.ts +506 -0
- package/src/modules/documents/commands/index.ts +33 -0
- package/src/modules/documents/commands/interceptors.ts +402 -0
- package/src/modules/documents/commands/lifecycle.ts +333 -0
- package/src/modules/documents/commands/links.ts +486 -0
- package/src/modules/documents/commands/mutation-helpers.ts +48 -0
- package/src/modules/documents/commands/projection-types.ts +77 -0
- package/src/modules/documents/commands/shared.ts +219 -0
- package/src/modules/documents/commands/shares.ts +612 -0
- package/src/modules/documents/commands/side-effects.ts +130 -0
- package/src/modules/documents/commands/templates.ts +522 -0
- package/src/modules/documents/commands/versions.ts +537 -0
- package/src/modules/documents/commands/watchers.ts +181 -0
- package/src/modules/documents/data/entities.ts +631 -0
- package/src/modules/documents/data/extensions.ts +42 -0
- package/src/modules/documents/data/validators.ts +248 -0
- package/src/modules/documents/di.ts +33 -0
- package/src/modules/documents/encryption.ts +14 -0
- package/src/modules/documents/events.ts +23 -0
- package/src/modules/documents/i18n/.hardcoded-allowlist.json +9 -0
- package/src/modules/documents/i18n/de.json +522 -0
- package/src/modules/documents/i18n/en.json +522 -0
- package/src/modules/documents/i18n/es.json +522 -0
- package/src/modules/documents/i18n/ko.json +522 -0
- package/src/modules/documents/i18n/pl.json +522 -0
- package/src/modules/documents/index.ts +17 -0
- package/src/modules/documents/lib/attachmentServicePort.ts +94 -0
- package/src/modules/documents/lib/capabilities.ts +57 -0
- package/src/modules/documents/lib/collabCloseEvents.ts +26 -0
- package/src/modules/documents/lib/collabEndpoint.ts +43 -0
- package/src/modules/documents/lib/collabMaterializer.ts +140 -0
- package/src/modules/documents/lib/collabToken.ts +170 -0
- package/src/modules/documents/lib/collaborationAwareness.ts +102 -0
- package/src/modules/documents/lib/commentAnchors.ts +19 -0
- package/src/modules/documents/lib/constants.ts +39 -0
- package/src/modules/documents/lib/contentService.ts +340 -0
- package/src/modules/documents/lib/displayLabels.ts +31 -0
- package/src/modules/documents/lib/docxRenderer.ts +685 -0
- package/src/modules/documents/lib/duplicateContent.ts +32 -0
- package/src/modules/documents/lib/editorConfig.ts +371 -0
- package/src/modules/documents/lib/entityLinks.ts +250 -0
- package/src/modules/documents/lib/entityRegistry.server.ts +267 -0
- package/src/modules/documents/lib/entityRegistry.ts +345 -0
- package/src/modules/documents/lib/entityRegistryAvailability.server.ts +19 -0
- package/src/modules/documents/lib/entitySuggestion.ts +61 -0
- package/src/modules/documents/lib/favorites.ts +35 -0
- package/src/modules/documents/lib/folderHierarchySerialization.ts +34 -0
- package/src/modules/documents/lib/historyLimits.ts +154 -0
- package/src/modules/documents/lib/historyPolicy.ts +7 -0
- package/src/modules/documents/lib/organizationAccess.ts +44 -0
- package/src/modules/documents/lib/pdfHtml.ts +65 -0
- package/src/modules/documents/lib/pdfRenderer.ts +367 -0
- package/src/modules/documents/lib/permissions.ts +299 -0
- package/src/modules/documents/lib/platformServices.ts +70 -0
- package/src/modules/documents/lib/recordFieldInsertion.ts +72 -0
- package/src/modules/documents/lib/requestBody.ts +97 -0
- package/src/modules/documents/lib/resourceLimits.ts +94 -0
- package/src/modules/documents/lib/shareCounts.ts +44 -0
- package/src/modules/documents/lib/templateFill.ts +138 -0
- package/src/modules/documents/lib/templateInstantiation.ts +206 -0
- package/src/modules/documents/lib/templatePreviewDigest.ts +122 -0
- package/src/modules/documents/lib/templateSeeds.ts +248 -0
- package/src/modules/documents/lib/userLabels.ts +58 -0
- package/src/modules/documents/lib/versionContent.ts +163 -0
- package/src/modules/documents/lib/versionLabels.ts +9 -0
- package/src/modules/documents/lib/versioning.ts +29 -0
- package/src/modules/documents/lib/visibility.ts +610 -0
- package/src/modules/documents/lib/watchers.ts +129 -0
- package/src/modules/documents/migrations/.snapshot-open-mercato.json +2892 -0
- package/src/modules/documents/migrations/Migration20260708163836_documents.ts +50 -0
- package/src/modules/documents/migrations/Migration20260709164720_documents.ts +19 -0
- package/src/modules/documents/migrations/Migration20260710002318_documents.ts +35 -0
- package/src/modules/documents/migrations/Migration20260710071003_documents.ts +13 -0
- package/src/modules/documents/migrations/Migration20260712120000_documents.ts +13 -0
- package/src/modules/documents/migrations/Migration20260712183000_documents.ts +12 -0
- package/src/modules/documents/migrations/Migration20260713092156_documents.ts +43 -0
- package/src/modules/documents/migrations/Migration20260717000000_documents.ts +40 -0
- package/src/modules/documents/notifications.ts +45 -0
- package/src/modules/documents/search.ts +118 -0
- package/src/modules/documents/setup.ts +19 -0
- package/src/modules/documents/widgets/injection/related-documents/LinkDocumentDialog.tsx +224 -0
- package/src/modules/documents/widgets/injection/related-documents/context.ts +101 -0
- package/src/modules/documents/widgets/injection/related-documents/useRelatedDocuments.ts +112 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +76 -0
- package/src/modules/documents/widgets/injection/related-documents/widget.ts +19 -0
- package/src/modules/documents/widgets/injection-table.ts +20 -0
- package/tsconfig.json +9 -0
- package/watch.mjs +6 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Link2, Search } from 'lucide-react'
|
|
5
|
+
import { apiCall, apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
|
|
6
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
7
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
8
|
+
import { ErrorMessage, LoadingMessage } from '@open-mercato/ui/backend/detail'
|
|
9
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
10
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'
|
|
11
|
+
import { Input } from '@open-mercato/ui/primitives/input'
|
|
12
|
+
import { Label } from '@open-mercato/ui/primitives/label'
|
|
13
|
+
import { useDialogKeyHandler } from '@open-mercato/ui/hooks/useDialogKeyHandler'
|
|
14
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
15
|
+
import { readNumber, readRecord } from '../../../backend/documents/documentUi'
|
|
16
|
+
import { normalizeDocuments, type DocumentRow } from '../../../backend/documents/documentsListTypes'
|
|
17
|
+
import type { RelatedDocumentContext } from './context'
|
|
18
|
+
import { OPTIONAL_HEADERS } from './useRelatedDocuments'
|
|
19
|
+
|
|
20
|
+
const SEARCH_PAGE_SIZE = 20
|
|
21
|
+
const MAX_SEARCH_PAGES = 5
|
|
22
|
+
|
|
23
|
+
function buildSearchContext(open: boolean, target: RelatedDocumentContext, query: string): string {
|
|
24
|
+
return JSON.stringify([open, target.entityType, target.entityId, query.trim()])
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function loadEditableDocuments(
|
|
28
|
+
search: string,
|
|
29
|
+
signal: AbortSignal,
|
|
30
|
+
unknownOwner: string,
|
|
31
|
+
): Promise<{ ok: boolean; rows: DocumentRow[] }> {
|
|
32
|
+
const editable: DocumentRow[] = []
|
|
33
|
+
for (let page = 1; page <= MAX_SEARCH_PAGES; page += 1) {
|
|
34
|
+
const params = new URLSearchParams({ search, page: String(page), pageSize: String(SEARCH_PAGE_SIZE) })
|
|
35
|
+
const call = await apiCall<unknown>(
|
|
36
|
+
`/api/documents?${params.toString()}`,
|
|
37
|
+
{ headers: OPTIONAL_HEADERS, signal },
|
|
38
|
+
{ fallback: { items: [] } },
|
|
39
|
+
)
|
|
40
|
+
if (!call.ok) return { ok: false, rows: [] }
|
|
41
|
+
const pageRows = normalizeDocuments(call.result, [], unknownOwner)
|
|
42
|
+
editable.push(...pageRows.filter((row) => row.capabilities.canEdit))
|
|
43
|
+
if (editable.length > 0 || pageRows.length === 0) break
|
|
44
|
+
const totalPages = readNumber(readRecord(call.result) ?? {}, 'totalPages', 'total_pages') ?? page
|
|
45
|
+
if (page >= totalPages) break
|
|
46
|
+
}
|
|
47
|
+
return { ok: true, rows: editable }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function LinkDocumentDialog({ open, target, onOpenChange, onLinked }: {
|
|
51
|
+
open: boolean
|
|
52
|
+
target: RelatedDocumentContext
|
|
53
|
+
onOpenChange: (open: boolean) => void
|
|
54
|
+
onLinked: () => void
|
|
55
|
+
}) {
|
|
56
|
+
const t = useT()
|
|
57
|
+
const inputId = React.useId()
|
|
58
|
+
const request = React.useRef(0)
|
|
59
|
+
const activeRequest = React.useRef<AbortController | null>(null)
|
|
60
|
+
const activeSearchContext = React.useRef('')
|
|
61
|
+
const resultSearchContext = React.useRef<string | null>(null)
|
|
62
|
+
const [query, setQuery] = React.useState('')
|
|
63
|
+
const [rows, setRows] = React.useState<DocumentRow[]>([])
|
|
64
|
+
const [loading, setLoading] = React.useState(false)
|
|
65
|
+
const [errorSearchContext, setErrorSearchContext] = React.useState<string | null>(null)
|
|
66
|
+
const [retryToken, setRetryToken] = React.useState(0)
|
|
67
|
+
const [activeRowId, setActiveRowId] = React.useState<string | null>(null)
|
|
68
|
+
const currentSearchContext = buildSearchContext(open, target, query)
|
|
69
|
+
activeSearchContext.current = currentSearchContext
|
|
70
|
+
const mutationContextId = `documents-related-widget:${target.entityType}:${target.entityId}`
|
|
71
|
+
const { runMutation, retryLastMutation } = useGuardedMutation<{
|
|
72
|
+
formId: string; resourceKind: string; resourceId: string; retryLastMutation: () => Promise<boolean>
|
|
73
|
+
}>({ contextId: mutationContextId, blockedMessage: t('ui.forms.flash.saveBlocked') })
|
|
74
|
+
|
|
75
|
+
const invalidateSearch = React.useCallback(() => {
|
|
76
|
+
request.current += 1
|
|
77
|
+
activeRequest.current?.abort()
|
|
78
|
+
activeRequest.current = null
|
|
79
|
+
resultSearchContext.current = null
|
|
80
|
+
setRows([])
|
|
81
|
+
setActiveRowId(null)
|
|
82
|
+
setLoading(false)
|
|
83
|
+
setErrorSearchContext(null)
|
|
84
|
+
}, [])
|
|
85
|
+
|
|
86
|
+
const changeQuery = React.useCallback((nextQuery: string) => {
|
|
87
|
+
activeSearchContext.current = buildSearchContext(open, target, nextQuery)
|
|
88
|
+
invalidateSearch()
|
|
89
|
+
setQuery(nextQuery)
|
|
90
|
+
}, [invalidateSearch, open, target.entityId, target.entityType, target.href, target.label])
|
|
91
|
+
|
|
92
|
+
const handleOpenChange = React.useCallback((nextOpen: boolean) => {
|
|
93
|
+
if (!nextOpen) {
|
|
94
|
+
activeSearchContext.current = buildSearchContext(false, target, '')
|
|
95
|
+
invalidateSearch()
|
|
96
|
+
setQuery('')
|
|
97
|
+
}
|
|
98
|
+
onOpenChange(nextOpen)
|
|
99
|
+
}, [invalidateSearch, onOpenChange, target.entityId, target.entityType, target.href, target.label])
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
invalidateSearch()
|
|
103
|
+
if (!open) { setQuery(''); return }
|
|
104
|
+
const search = query.trim()
|
|
105
|
+
if (!search) return
|
|
106
|
+
const timer = window.setTimeout(() => {
|
|
107
|
+
const requestId = ++request.current
|
|
108
|
+
const requestContext = buildSearchContext(true, target, search)
|
|
109
|
+
const controller = new AbortController()
|
|
110
|
+
activeRequest.current?.abort()
|
|
111
|
+
activeRequest.current = controller
|
|
112
|
+
resultSearchContext.current = null
|
|
113
|
+
setRows([])
|
|
114
|
+
setLoading(true)
|
|
115
|
+
setErrorSearchContext(null)
|
|
116
|
+
void loadEditableDocuments(search, controller.signal, t('documents.list.unknownOwner'))
|
|
117
|
+
.then((result) => {
|
|
118
|
+
if (request.current !== requestId || activeSearchContext.current !== requestContext) return
|
|
119
|
+
resultSearchContext.current = requestContext
|
|
120
|
+
if (!result.ok) {
|
|
121
|
+
setRows([])
|
|
122
|
+
setActiveRowId(null)
|
|
123
|
+
setErrorSearchContext(requestContext)
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
setRows(result.rows)
|
|
127
|
+
setActiveRowId(result.rows[0]?.id ?? null)
|
|
128
|
+
})
|
|
129
|
+
.catch(() => {
|
|
130
|
+
if (!controller.signal.aborted && request.current === requestId && activeSearchContext.current === requestContext) {
|
|
131
|
+
resultSearchContext.current = requestContext
|
|
132
|
+
setRows([])
|
|
133
|
+
setActiveRowId(null)
|
|
134
|
+
setErrorSearchContext(requestContext)
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
.finally(() => {
|
|
138
|
+
if (request.current === requestId) {
|
|
139
|
+
if (activeRequest.current === controller) activeRequest.current = null
|
|
140
|
+
setLoading(false)
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
}, 250)
|
|
144
|
+
return () => window.clearTimeout(timer)
|
|
145
|
+
}, [invalidateSearch, open, query, retryToken, t, target.entityId, target.entityType, target.href, target.label])
|
|
146
|
+
|
|
147
|
+
React.useEffect(() => () => { activeRequest.current?.abort() }, [])
|
|
148
|
+
|
|
149
|
+
const linkDocument = React.useCallback(async (row: DocumentRow) => {
|
|
150
|
+
if (resultSearchContext.current === null || resultSearchContext.current !== activeSearchContext.current) return
|
|
151
|
+
try {
|
|
152
|
+
await runMutation({
|
|
153
|
+
operation: () => apiCallOrThrow(
|
|
154
|
+
`/api/documents/${encodeURIComponent(row.id)}/links`,
|
|
155
|
+
{
|
|
156
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
157
|
+
body: JSON.stringify({ entityType: target.entityType, entityId: target.entityId, label: target.label, href: target.href, source: 'related-panel' }),
|
|
158
|
+
},
|
|
159
|
+
{ errorMessage: t('documents.relatedDocuments.error.link') },
|
|
160
|
+
),
|
|
161
|
+
context: { formId: mutationContextId, resourceKind: 'documents.document_entity_link', resourceId: row.id, retryLastMutation },
|
|
162
|
+
mutationPayload: { documentId: row.id, entityType: target.entityType },
|
|
163
|
+
})
|
|
164
|
+
flash(t('documents.relatedDocuments.success.link'), 'success')
|
|
165
|
+
handleOpenChange(false)
|
|
166
|
+
onLinked()
|
|
167
|
+
} catch (error) { flash(error instanceof Error ? error.message : t('documents.relatedDocuments.error.link'), 'error') }
|
|
168
|
+
}, [handleOpenChange, mutationContextId, onLinked, retryLastMutation, runMutation, t, target.entityId, target.entityType, target.href, target.label])
|
|
169
|
+
|
|
170
|
+
const hasCurrentResults = resultSearchContext.current !== null && resultSearchContext.current === currentSearchContext
|
|
171
|
+
const hasCurrentError = errorSearchContext !== null && errorSearchContext === currentSearchContext
|
|
172
|
+
const visibleRows = hasCurrentResults ? rows : []
|
|
173
|
+
const retrySearch = React.useCallback(() => {
|
|
174
|
+
if (!open || !query.trim()) return
|
|
175
|
+
invalidateSearch()
|
|
176
|
+
setRetryToken((token) => token + 1)
|
|
177
|
+
}, [invalidateSearch, open, query])
|
|
178
|
+
const confirmActiveRow = React.useCallback(() => {
|
|
179
|
+
const row = visibleRows.find((candidate) => candidate.id === activeRowId) ?? visibleRows[0]
|
|
180
|
+
if (row) void linkDocument(row)
|
|
181
|
+
}, [activeRowId, linkDocument, visibleRows])
|
|
182
|
+
const dialogKeyDown = useDialogKeyHandler({
|
|
183
|
+
onConfirm: confirmActiveRow,
|
|
184
|
+
onCancel: () => handleOpenChange(false),
|
|
185
|
+
disabled: loading || visibleRows.length === 0,
|
|
186
|
+
})
|
|
187
|
+
const handleDialogKeyDown = React.useCallback((event: React.KeyboardEvent) => {
|
|
188
|
+
dialogKeyDown(event)
|
|
189
|
+
if (event.defaultPrevented || visibleRows.length === 0) return
|
|
190
|
+
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return
|
|
191
|
+
event.preventDefault()
|
|
192
|
+
const currentIndex = visibleRows.findIndex((row) => row.id === activeRowId)
|
|
193
|
+
const offset = event.key === 'ArrowDown' ? 1 : -1
|
|
194
|
+
const nextIndex = currentIndex < 0
|
|
195
|
+
? 0
|
|
196
|
+
: (currentIndex + offset + visibleRows.length) % visibleRows.length
|
|
197
|
+
setActiveRowId(visibleRows[nextIndex]?.id ?? null)
|
|
198
|
+
}, [activeRowId, dialogKeyDown, visibleRows])
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
202
|
+
<DialogContent size="lg" onKeyDown={handleDialogKeyDown}>
|
|
203
|
+
<DialogHeader><DialogTitle>{t('documents.relatedDocuments.linkDialog.title')}</DialogTitle><DialogDescription>{t('documents.relatedDocuments.linkDialog.description')}</DialogDescription></DialogHeader>
|
|
204
|
+
<div className="space-y-3">
|
|
205
|
+
<div className="space-y-2"><Label htmlFor={inputId}>{t('documents.relatedDocuments.linkDialog.searchLabel')}</Label><Input id={inputId} value={query} onChange={(event) => changeQuery(event.target.value)} leftIcon={<Search />} placeholder={t('documents.relatedDocuments.linkDialog.searchPlaceholder')} /></div>
|
|
206
|
+
{loading ? <LoadingMessage label={t('documents.relatedDocuments.loading')} /> : null}
|
|
207
|
+
{!loading && hasCurrentError ? (
|
|
208
|
+
<ErrorMessage
|
|
209
|
+
label={t('documents.relatedDocuments.linkDialog.error')}
|
|
210
|
+
action={<Button type="button" size="sm" variant="outline" onClick={retrySearch}>{t('documents.actions.retry')}</Button>}
|
|
211
|
+
/>
|
|
212
|
+
) : null}
|
|
213
|
+
{!loading && !hasCurrentError && query.trim() && hasCurrentResults && visibleRows.length === 0 ? <p className="rounded-md border border-border bg-muted/20 p-3 text-sm text-muted-foreground">{t('documents.relatedDocuments.linkDialog.empty')}</p> : null}
|
|
214
|
+
{!loading && visibleRows.length > 0 ? <div className="max-h-72 space-y-2 overflow-y-auto">{visibleRows.map((row) => (
|
|
215
|
+
<Button key={row.id} type="button" variant={activeRowId === row.id ? 'secondary' : 'outline'} aria-current={activeRowId === row.id ? 'true' : undefined} className="h-auto w-full justify-between p-3 text-left" onFocus={() => setActiveRowId(row.id)} onClick={() => { void linkDocument(row) }}>
|
|
216
|
+
<span className="min-w-0"><span className="block truncate font-medium">{row.title}</span><span className="block truncate text-xs text-muted-foreground">{row.ownerLabel}</span></span><Link2 />
|
|
217
|
+
</Button>
|
|
218
|
+
))}</div> : null}
|
|
219
|
+
</div>
|
|
220
|
+
<DialogFooter><Button type="button" variant="outline" onClick={() => handleOpenChange(false)}>{t('documents.actions.cancel')}</Button></DialogFooter>
|
|
221
|
+
</DialogContent>
|
|
222
|
+
</Dialog>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getEntityRegistryEntry, type DocumentEntityType } from '../../../lib/entityRegistry'
|
|
2
|
+
import { sanitizeDocumentsDisplayLabel } from '../../../lib/displayLabels'
|
|
3
|
+
import type { CollectionCapabilities } from '../../../backend/documents/documentsListTypes'
|
|
4
|
+
|
|
5
|
+
export type RelatedDocumentContext = {
|
|
6
|
+
entityType: DocumentEntityType
|
|
7
|
+
entityId: string
|
|
8
|
+
label: string | null
|
|
9
|
+
href: string
|
|
10
|
+
values: Record<string, string>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
14
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function text(value: Record<string, unknown> | null, ...keys: string[]): string | null {
|
|
18
|
+
if (!value) return null
|
|
19
|
+
for (const key of keys) {
|
|
20
|
+
const candidate = value[key]
|
|
21
|
+
if (typeof candidate === 'string' && candidate.trim()) return candidate.trim()
|
|
22
|
+
}
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function displayText(value: Record<string, unknown> | null, ...keys: string[]): string | null {
|
|
27
|
+
if (!value) return null
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
const candidate = sanitizeDocumentsDisplayLabel(value[key])
|
|
30
|
+
if (candidate) return candidate
|
|
31
|
+
}
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function nested(value: Record<string, unknown> | null, key: string): Record<string, unknown> | null {
|
|
36
|
+
return value ? record(value[key]) : null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function contextType(context: Record<string, unknown>): DocumentEntityType | null {
|
|
40
|
+
const resourceKind = text(context, 'resourceKind', 'resource_kind')
|
|
41
|
+
if (resourceKind === 'customers.person') return 'customer-person'
|
|
42
|
+
if (resourceKind === 'customers.company') return 'customer-company'
|
|
43
|
+
if (resourceKind === 'customers.deal') return 'deal'
|
|
44
|
+
if (resourceKind === 'catalog.product') return 'product'
|
|
45
|
+
const kind = text(context, 'kind')
|
|
46
|
+
if (kind === 'quote') return 'quote'
|
|
47
|
+
if (kind === 'order') return 'sales-order'
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function contextItem(type: DocumentEntityType, data: Record<string, unknown> | null): Record<string, unknown> | null {
|
|
52
|
+
return nested(data, type === 'customer-person' ? 'person' : type === 'customer-company' ? 'company' : type === 'deal' ? 'deal' : 'record') ?? data
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function contextLabel(type: DocumentEntityType, item: Record<string, unknown> | null): string | null {
|
|
56
|
+
if (type === 'customer-person') {
|
|
57
|
+
const direct = displayText(item, 'displayName', 'display_name', 'name', 'fullName', 'full_name', 'email')
|
|
58
|
+
if (direct) return direct
|
|
59
|
+
const parts = [displayText(item, 'firstName', 'first_name'), displayText(item, 'lastName', 'last_name')].filter(Boolean)
|
|
60
|
+
return sanitizeDocumentsDisplayLabel(parts.length ? parts.join(' ') : null)
|
|
61
|
+
}
|
|
62
|
+
if (type === 'customer-company') return displayText(item, 'displayName', 'display_name', 'name', 'legalName', 'legal_name', 'email')
|
|
63
|
+
if (type === 'deal' || type === 'product') return displayText(item, 'title', 'name')
|
|
64
|
+
if (type === 'quote') return displayText(item, 'quoteNumber', 'quote_number', 'number', 'title')
|
|
65
|
+
if (type === 'sales-order') return displayText(item, 'orderNumber', 'order_number', 'number', 'title')
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function resolveRelatedDocumentContext(contextValue: unknown, dataValue?: unknown): RelatedDocumentContext | null {
|
|
70
|
+
const context = record(contextValue)
|
|
71
|
+
if (!context) return null
|
|
72
|
+
const type = contextType(context)
|
|
73
|
+
if (!type) return null
|
|
74
|
+
const hostRecord = record(context.record)
|
|
75
|
+
const data = record(dataValue) ?? record(context.data) ?? hostRecord
|
|
76
|
+
const explicitContextId = text(context, 'resourceId', 'resource_id', 'recordId', 'record_id')
|
|
77
|
+
const entityId = explicitContextId ?? text(hostRecord, 'id') ?? text(data, 'id')
|
|
78
|
+
// Some edit hosts keep the id outside their form values, so CrudForm's generic
|
|
79
|
+
// operation heuristic still reports "create" while version history supplies a
|
|
80
|
+
// stable resource id. Treat that explicit host identity as authoritative, but
|
|
81
|
+
// keep genuine create forms (which have no context id) hidden.
|
|
82
|
+
if (text(context, 'operation') === 'create' && !explicitContextId) return null
|
|
83
|
+
if (!entityId) return null
|
|
84
|
+
const entry = getEntityRegistryEntry(type)
|
|
85
|
+
if (!entry) return null
|
|
86
|
+
const item = contextItem(type, data)
|
|
87
|
+
const label = contextLabel(type, item)
|
|
88
|
+
const href = entry.resolveHref({ id: entityId, label: label ?? '' })
|
|
89
|
+
const values = Object.fromEntries(entry.tokenFields.flatMap((field) => {
|
|
90
|
+
const value = item ? field.extract(item) : null
|
|
91
|
+
return value === null ? [] : [[field.field, value]]
|
|
92
|
+
}))
|
|
93
|
+
return href ? { entityType: type, entityId, label, href, values } : null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function resolveRelatedDocumentActions(capabilities: CollectionCapabilities, disabled: boolean) {
|
|
97
|
+
return {
|
|
98
|
+
canLink: !disabled && capabilities.canLinkDocuments,
|
|
99
|
+
canCreate: !disabled && capabilities.canInstantiateTemplate,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
|
|
5
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import {
|
|
7
|
+
EMPTY_COLLECTION_CAPABILITIES,
|
|
8
|
+
normalizeCollectionCapabilities,
|
|
9
|
+
normalizeDocuments,
|
|
10
|
+
type CollectionCapabilities,
|
|
11
|
+
type DocumentRow,
|
|
12
|
+
} from '../../../backend/documents/documentsListTypes'
|
|
13
|
+
import type { RelatedDocumentContext } from './context'
|
|
14
|
+
|
|
15
|
+
type State = {
|
|
16
|
+
context: string | null
|
|
17
|
+
status: 'loading' | 'ready' | 'error' | 'hidden'
|
|
18
|
+
items: DocumentRow[]
|
|
19
|
+
capabilities: CollectionCapabilities
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const OPTIONAL_HEADERS = {
|
|
23
|
+
'x-om-forbidden-redirect': '0',
|
|
24
|
+
'x-om-unauthorized-redirect': '0',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function buildTargetContext(target: RelatedDocumentContext | null): string | null {
|
|
28
|
+
return target ? JSON.stringify([target.entityType, target.entityId]) : null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function emptyState(context: string | null, status: State['status']): State {
|
|
32
|
+
return { context, status, items: [], capabilities: EMPTY_COLLECTION_CAPABILITIES }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useRelatedDocuments(target: RelatedDocumentContext | null) {
|
|
36
|
+
const t = useT()
|
|
37
|
+
const request = React.useRef(0)
|
|
38
|
+
const activeRequest = React.useRef<AbortController | null>(null)
|
|
39
|
+
const targetContext = buildTargetContext(target)
|
|
40
|
+
const activeContext = React.useRef<string | null>(targetContext)
|
|
41
|
+
activeContext.current = targetContext
|
|
42
|
+
const [state, setState] = React.useState<State>(() => emptyState(targetContext, target ? 'loading' : 'hidden'))
|
|
43
|
+
const [reload, setReload] = React.useState(0)
|
|
44
|
+
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
activeRequest.current?.abort()
|
|
47
|
+
activeRequest.current = null
|
|
48
|
+
if (!target || !targetContext) {
|
|
49
|
+
request.current += 1
|
|
50
|
+
setState(emptyState(null, 'hidden'))
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
const requestId = ++request.current
|
|
54
|
+
const requestContext = targetContext
|
|
55
|
+
const controller = new AbortController()
|
|
56
|
+
activeRequest.current = controller
|
|
57
|
+
const params = new URLSearchParams({
|
|
58
|
+
entityType: target.entityType,
|
|
59
|
+
entityId: target.entityId,
|
|
60
|
+
page: '1',
|
|
61
|
+
pageSize: '10',
|
|
62
|
+
})
|
|
63
|
+
setState(emptyState(requestContext, 'loading'))
|
|
64
|
+
void apiCall<unknown>(
|
|
65
|
+
`/api/documents?${params.toString()}`,
|
|
66
|
+
{ headers: OPTIONAL_HEADERS, signal: controller.signal },
|
|
67
|
+
{ fallback: { items: [] } },
|
|
68
|
+
).then((call) => {
|
|
69
|
+
if (request.current !== requestId || activeContext.current !== requestContext) return
|
|
70
|
+
if (call.status === 401 || call.status === 403 || call.status === 404) {
|
|
71
|
+
setState(emptyState(requestContext, 'hidden'))
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
if (!call.ok) { setState(emptyState(requestContext, 'error')); return }
|
|
75
|
+
setState({
|
|
76
|
+
context: requestContext,
|
|
77
|
+
status: 'ready',
|
|
78
|
+
items: normalizeDocuments(call.result, [], t('documents.list.unknownOwner')),
|
|
79
|
+
capabilities: normalizeCollectionCapabilities(call.result),
|
|
80
|
+
})
|
|
81
|
+
}).catch(() => {
|
|
82
|
+
if (!controller.signal.aborted && request.current === requestId && activeContext.current === requestContext) {
|
|
83
|
+
setState(emptyState(requestContext, 'error'))
|
|
84
|
+
}
|
|
85
|
+
}).finally(() => {
|
|
86
|
+
if (activeRequest.current === controller) activeRequest.current = null
|
|
87
|
+
})
|
|
88
|
+
return () => {
|
|
89
|
+
request.current += 1
|
|
90
|
+
controller.abort()
|
|
91
|
+
if (activeRequest.current === controller) activeRequest.current = null
|
|
92
|
+
}
|
|
93
|
+
}, [reload, t, targetContext])
|
|
94
|
+
|
|
95
|
+
React.useEffect(() => () => { activeRequest.current?.abort() }, [])
|
|
96
|
+
|
|
97
|
+
const visibleState = state.context === targetContext
|
|
98
|
+
? state
|
|
99
|
+
: emptyState(targetContext, targetContext ? 'loading' : 'hidden')
|
|
100
|
+
|
|
101
|
+
const retry = React.useCallback(() => {
|
|
102
|
+
request.current += 1
|
|
103
|
+
activeRequest.current?.abort()
|
|
104
|
+
activeRequest.current = null
|
|
105
|
+
setState(emptyState(targetContext, targetContext ? 'loading' : 'hidden'))
|
|
106
|
+
setReload((value) => value + 1)
|
|
107
|
+
}, [targetContext])
|
|
108
|
+
|
|
109
|
+
return { ...visibleState, retry }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { OPTIONAL_HEADERS }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import dynamic from 'next/dynamic'
|
|
5
|
+
import Link from 'next/link'
|
|
6
|
+
import { ExternalLink, FilePlus2, Link2 } from 'lucide-react'
|
|
7
|
+
import type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'
|
|
8
|
+
import { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'
|
|
9
|
+
import { SectionHeader } from '@open-mercato/ui/backend/SectionHeader'
|
|
10
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
11
|
+
import { LinkButton } from '@open-mercato/ui/primitives/link-button'
|
|
12
|
+
import { EmptyState } from '@open-mercato/ui/primitives/empty-state'
|
|
13
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
14
|
+
import { formatDateTime } from '../../../backend/documents/documentUi'
|
|
15
|
+
import { LinkDocumentDialog } from './LinkDocumentDialog'
|
|
16
|
+
import { resolveRelatedDocumentActions, resolveRelatedDocumentContext } from './context'
|
|
17
|
+
import { useRelatedDocuments } from './useRelatedDocuments'
|
|
18
|
+
|
|
19
|
+
function NewFromTemplateDialogLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {
|
|
20
|
+
const t = useT()
|
|
21
|
+
if (error) {
|
|
22
|
+
return (
|
|
23
|
+
<ErrorMessage
|
|
24
|
+
label={t('documents.templates.instantiate.error.load')}
|
|
25
|
+
action={<Button type="button" size="sm" variant="outline" onClick={retry}>{t('documents.actions.retry')}</Button>}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
return (
|
|
30
|
+
<div role="status" aria-live="polite">
|
|
31
|
+
<LoadingMessage label={t('documents.templates.instantiate.loading')} />
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const NewFromTemplateDialog = dynamic(
|
|
37
|
+
() => import('../../../backend/documents/components/NewFromTemplateDialog').then((module) => module.NewFromTemplateDialog),
|
|
38
|
+
{ ssr: false, loading: NewFromTemplateDialogLoading },
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
export default function RelatedDocumentsWidget({ context, data, disabled }: InjectionWidgetComponentProps<Record<string, unknown>, Record<string, unknown>>) {
|
|
42
|
+
const t = useT()
|
|
43
|
+
const target = React.useMemo(() => resolveRelatedDocumentContext(context, data), [context, data])
|
|
44
|
+
const related = useRelatedDocuments(target)
|
|
45
|
+
const [linkOpen, setLinkOpen] = React.useState(false)
|
|
46
|
+
const [createOpen, setCreateOpen] = React.useState(false)
|
|
47
|
+
if (!target || related.status === 'hidden') return null
|
|
48
|
+
const label = target.label ?? t('documents.relatedDocuments.recordFallback')
|
|
49
|
+
const actions = resolveRelatedDocumentActions(related.capabilities, Boolean(disabled))
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<section className="rounded-lg border border-border bg-card p-4">
|
|
53
|
+
<SectionHeader
|
|
54
|
+
title={t('documents.relatedDocuments.title')}
|
|
55
|
+
count={related.items.length}
|
|
56
|
+
action={actions.canLink || actions.canCreate ? <>
|
|
57
|
+
{actions.canLink ? <Button type="button" size="sm" variant="outline" onClick={() => setLinkOpen(true)}><Link2 />{t('documents.relatedDocuments.actions.link')}</Button> : null}
|
|
58
|
+
{actions.canCreate ? <Button type="button" size="sm" onClick={() => setCreateOpen(true)}><FilePlus2 />{t('documents.relatedDocuments.actions.create')}</Button> : null}
|
|
59
|
+
</> : undefined}
|
|
60
|
+
/>
|
|
61
|
+
<div className="mt-4">
|
|
62
|
+
{related.status === 'loading' ? <LoadingMessage label={t('documents.relatedDocuments.loading')} /> : null}
|
|
63
|
+
{related.status === 'error' ? <ErrorMessage label={t('documents.relatedDocuments.error.load')} action={<Button type="button" size="sm" variant="outline" onClick={related.retry}>{t('documents.actions.retry')}</Button>} /> : null}
|
|
64
|
+
{related.status === 'ready' && related.items.length === 0 ? <EmptyState size="sm" variant="subtle" title={t('documents.relatedDocuments.empty')} icon={<Link2 className="size-5" />} /> : null}
|
|
65
|
+
{related.status === 'ready' && related.items.length > 0 ? <div className="space-y-2">{related.items.map((row) => (
|
|
66
|
+
<div key={row.id} className="flex flex-wrap items-center justify-between gap-3 rounded-md border border-border p-3">
|
|
67
|
+
<div className="min-w-0"><Link className="block truncate text-sm font-medium hover:underline focus-visible:underline focus-visible:outline-none" href={`/backend/documents/${row.id}`}>{row.title}</Link><p className="truncate text-xs text-muted-foreground">{t('documents.relatedDocuments.meta', { owner: row.ownerLabel, updated: formatDateTime(row.updatedAt, t('documents.relatedDocuments.unknownDate')) })}</p></div>
|
|
68
|
+
<LinkButton asChild size="sm" variant="gray"><Link href={`/backend/documents/${row.id}`}><ExternalLink />{t('documents.actions.open')}</Link></LinkButton>
|
|
69
|
+
</div>
|
|
70
|
+
))}</div> : null}
|
|
71
|
+
</div>
|
|
72
|
+
{actions.canLink && linkOpen ? <LinkDocumentDialog open target={{ ...target, label }} onOpenChange={setLinkOpen} onLinked={related.retry} /> : null}
|
|
73
|
+
{actions.canCreate && createOpen ? <NewFromTemplateDialog open onOpenChange={setCreateOpen} presetContext={{ entityType: target.entityType, entityId: target.entityId, label, values: target.values }} /> : null}
|
|
74
|
+
</section>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import dynamic from 'next/dynamic'
|
|
2
|
+
import type { InjectionWidgetModule } from '@open-mercato/shared/modules/widgets/injection'
|
|
3
|
+
|
|
4
|
+
const RelatedDocumentsWidget = dynamic(() => import('./widget.client'))
|
|
5
|
+
|
|
6
|
+
const widget: InjectionWidgetModule<Record<string, unknown>, Record<string, unknown>> = {
|
|
7
|
+
metadata: {
|
|
8
|
+
id: 'documents.injection.related-documents',
|
|
9
|
+
title: 'Related documents',
|
|
10
|
+
description: 'Lists and creates documents related to the current record.',
|
|
11
|
+
features: ['documents.view'],
|
|
12
|
+
requiredModules: ['documents'],
|
|
13
|
+
priority: 80,
|
|
14
|
+
enabled: true,
|
|
15
|
+
},
|
|
16
|
+
Widget: RelatedDocumentsWidget,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default widget
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModuleInjectionTable } from '@open-mercato/shared/modules/widgets/injection'
|
|
2
|
+
|
|
3
|
+
const relatedDocuments = {
|
|
4
|
+
widgetId: 'documents.injection.related-documents',
|
|
5
|
+
kind: 'stack' as const,
|
|
6
|
+
priority: 80,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const injectionTable: ModuleInjectionTable = {
|
|
10
|
+
'detail:customers.person:footer': [relatedDocuments],
|
|
11
|
+
'customers.person.detail:details': [relatedDocuments],
|
|
12
|
+
'detail:customers.company:footer': [relatedDocuments],
|
|
13
|
+
'customers.company.detail:details': [relatedDocuments],
|
|
14
|
+
'detail:customers.deal:footer': [relatedDocuments],
|
|
15
|
+
'sales.document.detail.quote:details': [relatedDocuments],
|
|
16
|
+
'sales.document.detail.order:details': [relatedDocuments],
|
|
17
|
+
'crud-form:catalog.product': [relatedDocuments],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default injectionTable
|
package/tsconfig.json
ADDED