@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,227 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import dynamic from "next/dynamic";
|
|
5
|
+
import { Clock, Eye, History, Save } from "lucide-react";
|
|
6
|
+
import { apiCall, apiCallOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
7
|
+
import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
|
|
8
|
+
import { surfaceRecordConflict } from "@open-mercato/ui/backend/conflicts";
|
|
9
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
10
|
+
import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
|
|
11
|
+
import { EmptyState } from "@open-mercato/ui/primitives/empty-state";
|
|
12
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
13
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@open-mercato/ui/primitives/dialog";
|
|
14
|
+
import { Input } from "@open-mercato/ui/primitives/input";
|
|
15
|
+
import { Label } from "@open-mercato/ui/primitives/label";
|
|
16
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
17
|
+
import { readArrayPayload } from "../documentUi.js";
|
|
18
|
+
import { resolveVersionRestoreCapability } from "./componentCapabilities.js";
|
|
19
|
+
import { restoreVersionWithCurrentContentToken } from "./restoreVersion.js";
|
|
20
|
+
import { normalizeVersion } from "./versionHistoryModel.js";
|
|
21
|
+
function VersionPreviewDialogLoading({ error, retry }) {
|
|
22
|
+
const t = useT();
|
|
23
|
+
const [open, setOpen] = React.useState(true);
|
|
24
|
+
if (!open) return null;
|
|
25
|
+
return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: (next) => {
|
|
26
|
+
if (!next) setOpen(false);
|
|
27
|
+
}, children: /* @__PURE__ */ jsxs(DialogContent, { size: "lg", dismissible: Boolean(error), children: [
|
|
28
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
29
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("documents.versions.actions.preview") }),
|
|
30
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: t("documents.versions.preview.loading") })
|
|
31
|
+
] }),
|
|
32
|
+
error ? /* @__PURE__ */ jsx(
|
|
33
|
+
ErrorMessage,
|
|
34
|
+
{
|
|
35
|
+
label: t("documents.versions.preview.error"),
|
|
36
|
+
action: /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: retry, children: t("documents.actions.retry") })
|
|
37
|
+
}
|
|
38
|
+
) : /* @__PURE__ */ jsx("div", { role: "status", "aria-live": "polite", children: /* @__PURE__ */ jsx(LoadingMessage, { label: t("documents.versions.preview.loading") }) })
|
|
39
|
+
] }) });
|
|
40
|
+
}
|
|
41
|
+
const VersionPreviewDialog = dynamic(
|
|
42
|
+
() => import("./VersionPreviewDialog.js").then((module) => module.VersionPreviewDialog),
|
|
43
|
+
{ ssr: false, loading: VersionPreviewDialogLoading }
|
|
44
|
+
);
|
|
45
|
+
import { resolveVersionRestoreCapability as resolveVersionRestoreCapability2 } from "./componentCapabilities.js";
|
|
46
|
+
import { normalizeVersion as normalizeVersion2 } from "./versionHistoryModel.js";
|
|
47
|
+
function VersionHistoryPanel({
|
|
48
|
+
documentId,
|
|
49
|
+
tier,
|
|
50
|
+
canRestore,
|
|
51
|
+
onRestored
|
|
52
|
+
}) {
|
|
53
|
+
const t = useT();
|
|
54
|
+
const mayRestore = resolveVersionRestoreCapability(canRestore, tier);
|
|
55
|
+
const labelInputId = React.useId();
|
|
56
|
+
const [state, setState] = React.useState({ status: "loading" });
|
|
57
|
+
const [label, setLabel] = React.useState("");
|
|
58
|
+
const [isCreating, setIsCreating] = React.useState(false);
|
|
59
|
+
const [restoringVersionId, setRestoringVersionId] = React.useState(null);
|
|
60
|
+
const [previewVersionId, setPreviewVersionId] = React.useState(null);
|
|
61
|
+
const restoreInFlight = React.useRef(false);
|
|
62
|
+
const reloadSequence = React.useRef(0);
|
|
63
|
+
const activeReload = React.useRef(null);
|
|
64
|
+
const activeDocumentId = React.useRef(null);
|
|
65
|
+
const currentDocumentIdRef = React.useRef(documentId);
|
|
66
|
+
currentDocumentIdRef.current = documentId;
|
|
67
|
+
const mutationContextId = `documents-versions:${documentId}`;
|
|
68
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: mutationContextId, blockedMessage: t("ui.forms.flash.saveBlocked") });
|
|
69
|
+
const reload = React.useCallback(async () => {
|
|
70
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
71
|
+
const reloadId = ++reloadSequence.current;
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
activeReload.current?.abort();
|
|
74
|
+
activeReload.current = controller;
|
|
75
|
+
const isCurrent = () => currentDocumentIdRef.current === documentId && reloadSequence.current === reloadId && !controller.signal.aborted;
|
|
76
|
+
const documentChanged = activeDocumentId.current !== documentId;
|
|
77
|
+
activeDocumentId.current = documentId;
|
|
78
|
+
setState((current) => !documentChanged && current.status === "ready" ? current : { status: "loading" });
|
|
79
|
+
try {
|
|
80
|
+
const call = await apiCall(
|
|
81
|
+
`/api/documents/${encodeURIComponent(documentId)}/versions`,
|
|
82
|
+
{ signal: controller.signal }
|
|
83
|
+
);
|
|
84
|
+
if (!isCurrent()) return;
|
|
85
|
+
if (!call.ok) return setState({ status: "error", message: t("documents.versions.error.load") });
|
|
86
|
+
setState({
|
|
87
|
+
status: "ready",
|
|
88
|
+
versions: readArrayPayload(call.result, "items", "data").map((version) => normalizeVersion(version, t("documents.users.unknown"))).filter((version) => version !== null)
|
|
89
|
+
});
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (!isCurrent()) return;
|
|
92
|
+
setState({ status: "error", message: error instanceof Error ? error.message : t("documents.versions.error.load") });
|
|
93
|
+
} finally {
|
|
94
|
+
if (activeReload.current === controller) activeReload.current = null;
|
|
95
|
+
}
|
|
96
|
+
}, [documentId, t]);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
void reload();
|
|
99
|
+
return () => {
|
|
100
|
+
reloadSequence.current += 1;
|
|
101
|
+
activeReload.current?.abort();
|
|
102
|
+
activeReload.current = null;
|
|
103
|
+
};
|
|
104
|
+
}, [reload]);
|
|
105
|
+
const handleSnapshot = React.useCallback(async () => {
|
|
106
|
+
if (!mayRestore) return;
|
|
107
|
+
setIsCreating(true);
|
|
108
|
+
const nextLabel = label.trim() || null;
|
|
109
|
+
try {
|
|
110
|
+
await runMutation({
|
|
111
|
+
operation: () => apiCallOrThrow(
|
|
112
|
+
`/api/documents/${encodeURIComponent(documentId)}/versions`,
|
|
113
|
+
{ method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ label: nextLabel }) },
|
|
114
|
+
{ errorMessage: t("documents.versions.error.save") }
|
|
115
|
+
),
|
|
116
|
+
context: { formId: mutationContextId, resourceKind: "documents.document_version", resourceId: documentId, retryLastMutation },
|
|
117
|
+
mutationPayload: { label: nextLabel }
|
|
118
|
+
});
|
|
119
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
120
|
+
setLabel("");
|
|
121
|
+
await reload();
|
|
122
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
123
|
+
flash(t("documents.versions.snapshot.created"), "success");
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
126
|
+
flash(error instanceof Error ? error.message : t("documents.versions.error.save"), "error");
|
|
127
|
+
} finally {
|
|
128
|
+
setIsCreating(false);
|
|
129
|
+
}
|
|
130
|
+
}, [documentId, label, mayRestore, mutationContextId, reload, retryLastMutation, runMutation, t]);
|
|
131
|
+
const handleRestore = React.useCallback(async (version) => {
|
|
132
|
+
if (!mayRestore || restoreInFlight.current) return;
|
|
133
|
+
restoreInFlight.current = true;
|
|
134
|
+
try {
|
|
135
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
136
|
+
setRestoringVersionId(version.id);
|
|
137
|
+
await runMutation({
|
|
138
|
+
operation: () => restoreVersionWithCurrentContentToken({
|
|
139
|
+
documentId,
|
|
140
|
+
versionId: version.id,
|
|
141
|
+
errorMessage: t("documents.versions.error.restore")
|
|
142
|
+
}),
|
|
143
|
+
context: { formId: mutationContextId, resourceKind: "documents.document_version", resourceId: version.id, retryLastMutation },
|
|
144
|
+
mutationPayload: { action: "restore", versionId: version.id }
|
|
145
|
+
});
|
|
146
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
147
|
+
await reload();
|
|
148
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
149
|
+
await onRestored?.();
|
|
150
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
151
|
+
setPreviewVersionId(null);
|
|
152
|
+
flash(t("documents.versions.restored"), "success");
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (currentDocumentIdRef.current !== documentId) return;
|
|
155
|
+
if (!surfaceRecordConflict(error, t, {
|
|
156
|
+
onRefresh: onRestored ? () => {
|
|
157
|
+
void Promise.resolve(onRestored()).catch((refreshError) => {
|
|
158
|
+
flash(refreshError instanceof Error ? refreshError.message : t("documents.versions.error.restore"), "error");
|
|
159
|
+
});
|
|
160
|
+
} : void 0
|
|
161
|
+
})) {
|
|
162
|
+
flash(error instanceof Error ? error.message : t("documents.versions.error.restore"), "error");
|
|
163
|
+
}
|
|
164
|
+
} finally {
|
|
165
|
+
restoreInFlight.current = false;
|
|
166
|
+
setRestoringVersionId(null);
|
|
167
|
+
}
|
|
168
|
+
}, [documentId, mayRestore, mutationContextId, onRestored, reload, retryLastMutation, runMutation, t]);
|
|
169
|
+
const versions = state.status === "ready" ? state.versions : [];
|
|
170
|
+
return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-4", children: [
|
|
171
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center gap-2", children: [
|
|
172
|
+
/* @__PURE__ */ jsx(History, { className: "size-4 text-muted-foreground", "aria-hidden": "true" }),
|
|
173
|
+
/* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold", children: t("documents.versions.title") })
|
|
174
|
+
] }),
|
|
175
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
176
|
+
mayRestore ? /* @__PURE__ */ jsxs("form", { className: "space-y-3 rounded-lg border border-border bg-muted/20 p-3", onSubmit: (event) => {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
void handleSnapshot();
|
|
179
|
+
}, onKeyDown: (event) => {
|
|
180
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
void handleSnapshot();
|
|
183
|
+
}
|
|
184
|
+
if (event.key === "Escape") setLabel("");
|
|
185
|
+
}, children: [
|
|
186
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: labelInputId, children: t("documents.versions.snapshot.labelPlaceholder") }),
|
|
187
|
+
/* @__PURE__ */ jsx(Input, { id: labelInputId, value: label, onChange: (event) => setLabel(event.target.value), placeholder: t("documents.versions.snapshot.labelPlaceholder"), disabled: isCreating }),
|
|
188
|
+
/* @__PURE__ */ jsxs(Button, { type: "submit", disabled: isCreating, children: [
|
|
189
|
+
/* @__PURE__ */ jsx(Save, {}),
|
|
190
|
+
t("documents.versions.actions.snapshot")
|
|
191
|
+
] })
|
|
192
|
+
] }) : null,
|
|
193
|
+
state.status === "loading" ? /* @__PURE__ */ jsx(LoadingMessage, { label: t("documents.versions.loading") }) : null,
|
|
194
|
+
state.status === "error" ? /* @__PURE__ */ jsx(
|
|
195
|
+
ErrorMessage,
|
|
196
|
+
{
|
|
197
|
+
label: state.message,
|
|
198
|
+
action: /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => void reload(), children: t("documents.actions.retry") })
|
|
199
|
+
}
|
|
200
|
+
) : null,
|
|
201
|
+
state.status === "ready" && versions.length === 0 ? /* @__PURE__ */ jsx(EmptyState, { size: "sm", variant: "subtle", title: t("documents.versions.empty"), icon: /* @__PURE__ */ jsx(History, { className: "size-5" }) }) : null,
|
|
202
|
+
versions.map((version) => /* @__PURE__ */ jsxs("article", { className: "space-y-3 rounded-lg border border-border bg-background p-3", children: [
|
|
203
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: version.label ?? t("documents.versions.snapshot.defaultLabel") }),
|
|
204
|
+
/* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
|
|
205
|
+
/* @__PURE__ */ jsx(Clock, { className: "size-3", "aria-hidden": "true" }),
|
|
206
|
+
new Date(version.createdAt).toLocaleString()
|
|
207
|
+
] }),
|
|
208
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: version.creatorLabel || t("documents.users.unknown") }),
|
|
209
|
+
/* @__PURE__ */ jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setPreviewVersionId(version.id), children: [
|
|
210
|
+
/* @__PURE__ */ jsx(Eye, {}),
|
|
211
|
+
t("documents.versions.actions.preview")
|
|
212
|
+
] })
|
|
213
|
+
] }, version.id))
|
|
214
|
+
] }),
|
|
215
|
+
previewVersionId ? /* @__PURE__ */ jsx(VersionPreviewDialog, { documentId, versionId: previewVersionId, canRestore: mayRestore, isRestoring: restoringVersionId !== null, onOpenChange: (open) => {
|
|
216
|
+
if (!open) setPreviewVersionId(null);
|
|
217
|
+
}, onRestore: handleRestore }) : null
|
|
218
|
+
] });
|
|
219
|
+
}
|
|
220
|
+
var VersionHistoryPanel_default = VersionHistoryPanel;
|
|
221
|
+
export {
|
|
222
|
+
VersionHistoryPanel,
|
|
223
|
+
VersionHistoryPanel_default as default,
|
|
224
|
+
normalizeVersion2 as normalizeVersion,
|
|
225
|
+
resolveVersionRestoreCapability2 as resolveVersionRestoreCapability
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=VersionHistoryPanel.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/documents/backend/documents/%5Bid%5D/VersionHistoryPanel.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport { Clock, Eye, History, Save } from 'lucide-react'\nimport { apiCall, apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { EmptyState } from '@open-mercato/ui/primitives/empty-state'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@open-mercato/ui/primitives/dialog'\nimport { Input } from '@open-mercato/ui/primitives/input'\nimport { Label } from '@open-mercato/ui/primitives/label'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { readArrayPayload } from '../documentUi'\nimport { resolveVersionRestoreCapability, type DocumentTier } from './componentCapabilities'\nimport { restoreVersionWithCurrentContentToken } from './restoreVersion'\nimport type { VersionPreview } from './VersionPreviewDialog'\nimport { normalizeVersion, type DocumentVersion } from './versionHistoryModel'\n\nfunction VersionPreviewDialogLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {\n const t = useT()\n // `next/dynamic` never forwards the caller's `onOpenChange` to a loading\n // shell, so own the dismissal here. Without it a chunk that fails for good\n // (a deploy invalidated it) traps the user in a modal Escape cannot close.\n const [open, setOpen] = React.useState(true)\n if (!open) return null\n return (\n <Dialog open onOpenChange={(next) => { if (!next) setOpen(false) }}>\n <DialogContent size=\"lg\" dismissible={Boolean(error)}>\n <DialogHeader>\n <DialogTitle>{t('documents.versions.actions.preview')}</DialogTitle>\n <DialogDescription>{t('documents.versions.preview.loading')}</DialogDescription>\n </DialogHeader>\n {error ? (\n <ErrorMessage\n label={t('documents.versions.preview.error')}\n action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n ) : (\n <div role=\"status\" aria-live=\"polite\"><LoadingMessage label={t('documents.versions.preview.loading')} /></div>\n )}\n </DialogContent>\n </Dialog>\n )\n}\n\nconst VersionPreviewDialog = dynamic(\n () => import('./VersionPreviewDialog').then((module) => module.VersionPreviewDialog),\n { ssr: false, loading: VersionPreviewDialogLoading },\n)\n\ntype VersionsState = { status: 'loading' } | { status: 'error'; message: string } | { status: 'ready'; versions: DocumentVersion[] }\ntype VersionHistoryPanelProps = {\n documentId: string\n /** Legacy compatibility; an explicit capability projection takes precedence. */\n tier?: DocumentTier\n canRestore?: boolean\n /**\n * Accepted for compatibility. Restore reads the content row's current\n * optimistic-lock token immediately before the request instead of relying\n * on a token observed at page load, which every own edit since invalidated.\n */\n contentUpdatedAt?: string | null\n onRestored?: () => void | Promise<void>\n}\n\nexport { resolveVersionRestoreCapability } from './componentCapabilities'\nexport { normalizeVersion } from './versionHistoryModel'\n\nexport function VersionHistoryPanel({\n documentId,\n tier,\n canRestore,\n onRestored,\n}: VersionHistoryPanelProps) {\n const t = useT()\n const mayRestore = resolveVersionRestoreCapability(canRestore, tier)\n const labelInputId = React.useId()\n const [state, setState] = React.useState<VersionsState>({ status: 'loading' })\n const [label, setLabel] = React.useState('')\n const [isCreating, setIsCreating] = React.useState(false)\n const [restoringVersionId, setRestoringVersionId] = React.useState<string | null>(null)\n const [previewVersionId, setPreviewVersionId] = React.useState<string | null>(null)\n const restoreInFlight = React.useRef(false)\n const reloadSequence = React.useRef(0)\n const activeReload = React.useRef<AbortController | null>(null)\n const activeDocumentId = React.useRef<string | null>(null)\n const currentDocumentIdRef = React.useRef(documentId)\n currentDocumentIdRef.current = documentId\n const mutationContextId = `documents-versions:${documentId}`\n const { runMutation, retryLastMutation } = useGuardedMutation<{\n formId: string\n resourceKind: string\n resourceId: string\n retryLastMutation: () => Promise<boolean>\n }>({ contextId: mutationContextId, blockedMessage: t('ui.forms.flash.saveBlocked') })\n\n const reload = React.useCallback(async () => {\n if (currentDocumentIdRef.current !== documentId) return\n const reloadId = ++reloadSequence.current\n const controller = new AbortController()\n activeReload.current?.abort()\n activeReload.current = controller\n const isCurrent = () => currentDocumentIdRef.current === documentId\n && reloadSequence.current === reloadId\n && !controller.signal.aborted\n const documentChanged = activeDocumentId.current !== documentId\n activeDocumentId.current = documentId\n setState((current) => !documentChanged && current.status === 'ready' ? current : { status: 'loading' })\n try {\n const call = await apiCall<unknown>(\n `/api/documents/${encodeURIComponent(documentId)}/versions`,\n { signal: controller.signal },\n )\n if (!isCurrent()) return\n if (!call.ok) return setState({ status: 'error', message: t('documents.versions.error.load') })\n setState({\n status: 'ready',\n versions: readArrayPayload(call.result, 'items', 'data')\n .map((version) => normalizeVersion(version, t('documents.users.unknown')))\n .filter((version): version is DocumentVersion => version !== null),\n })\n } catch (error) {\n if (!isCurrent()) return\n setState({ status: 'error', message: error instanceof Error ? error.message : t('documents.versions.error.load') })\n } finally {\n if (activeReload.current === controller) activeReload.current = null\n }\n }, [documentId, t])\n\n React.useEffect(() => {\n void reload()\n return () => {\n reloadSequence.current += 1\n activeReload.current?.abort()\n activeReload.current = null\n }\n }, [reload])\n\n const handleSnapshot = React.useCallback(async () => {\n if (!mayRestore) return\n setIsCreating(true)\n const nextLabel = label.trim() || null\n try {\n await runMutation({\n operation: () => apiCallOrThrow(\n `/api/documents/${encodeURIComponent(documentId)}/versions`,\n { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ label: nextLabel }) },\n { errorMessage: t('documents.versions.error.save') },\n ),\n context: { formId: mutationContextId, resourceKind: 'documents.document_version', resourceId: documentId, retryLastMutation },\n mutationPayload: { label: nextLabel },\n })\n if (currentDocumentIdRef.current !== documentId) return\n setLabel('')\n await reload()\n if (currentDocumentIdRef.current !== documentId) return\n flash(t('documents.versions.snapshot.created'), 'success')\n } catch (error) {\n if (currentDocumentIdRef.current !== documentId) return\n flash(error instanceof Error ? error.message : t('documents.versions.error.save'), 'error')\n } finally { setIsCreating(false) }\n }, [documentId, label, mayRestore, mutationContextId, reload, retryLastMutation, runMutation, t])\n\n const handleRestore = React.useCallback(async (version: VersionPreview) => {\n if (!mayRestore || restoreInFlight.current) return\n restoreInFlight.current = true\n try {\n if (currentDocumentIdRef.current !== documentId) return\n setRestoringVersionId(version.id)\n await runMutation({\n operation: () => restoreVersionWithCurrentContentToken({\n documentId,\n versionId: version.id,\n errorMessage: t('documents.versions.error.restore'),\n }),\n context: { formId: mutationContextId, resourceKind: 'documents.document_version', resourceId: version.id, retryLastMutation },\n mutationPayload: { action: 'restore', versionId: version.id },\n })\n if (currentDocumentIdRef.current !== documentId) return\n await reload()\n if (currentDocumentIdRef.current !== documentId) return\n await onRestored?.()\n if (currentDocumentIdRef.current !== documentId) return\n setPreviewVersionId(null)\n flash(t('documents.versions.restored'), 'success')\n } catch (error) {\n if (currentDocumentIdRef.current !== documentId) return\n if (!surfaceRecordConflict(error, t, {\n onRefresh: onRestored ? () => {\n void Promise.resolve(onRestored()).catch((refreshError) => {\n flash(refreshError instanceof Error ? refreshError.message : t('documents.versions.error.restore'), 'error')\n })\n } : undefined,\n })) {\n flash(error instanceof Error ? error.message : t('documents.versions.error.restore'), 'error')\n }\n } finally {\n restoreInFlight.current = false\n setRestoringVersionId(null)\n }\n }, [documentId, mayRestore, mutationContextId, onRestored, reload, retryLastMutation, runMutation, t])\n\n const versions = state.status === 'ready' ? state.versions : []\n return (\n <section className=\"rounded-lg border border-border bg-card p-4\">\n <div className=\"mb-4 flex items-center gap-2\"><History className=\"size-4 text-muted-foreground\" aria-hidden=\"true\" /><h2 className=\"text-sm font-semibold\">{t('documents.versions.title')}</h2></div>\n <div className=\"space-y-4\">\n {mayRestore ? (\n <form className=\"space-y-3 rounded-lg border border-border bg-muted/20 p-3\" onSubmit={(event) => { event.preventDefault(); void handleSnapshot() }} onKeyDown={(event) => {\n if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') { event.preventDefault(); void handleSnapshot() }\n if (event.key === 'Escape') setLabel('')\n }}>\n <Label htmlFor={labelInputId}>{t('documents.versions.snapshot.labelPlaceholder')}</Label>\n <Input id={labelInputId} value={label} onChange={(event) => setLabel(event.target.value)} placeholder={t('documents.versions.snapshot.labelPlaceholder')} disabled={isCreating} />\n <Button type=\"submit\" disabled={isCreating}><Save />{t('documents.versions.actions.snapshot')}</Button>\n </form>\n ) : null}\n {state.status === 'loading' ? <LoadingMessage label={t('documents.versions.loading')} /> : null}\n {state.status === 'error' ? (\n <ErrorMessage\n label={state.message}\n action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={() => void reload()}>{t('documents.actions.retry')}</Button>}\n />\n ) : null}\n {state.status === 'ready' && versions.length === 0 ? <EmptyState size=\"sm\" variant=\"subtle\" title={t('documents.versions.empty')} icon={<History className=\"size-5\" />} /> : null}\n {versions.map((version) => (\n <article key={version.id} className=\"space-y-3 rounded-lg border border-border bg-background p-3\">\n <p className=\"text-sm font-medium\">{version.label ?? t('documents.versions.snapshot.defaultLabel')}</p>\n <p className=\"flex items-center gap-2 text-xs text-muted-foreground\"><Clock className=\"size-3\" aria-hidden=\"true\" />{new Date(version.createdAt).toLocaleString()}</p>\n <p className=\"text-xs text-muted-foreground\">{version.creatorLabel || t('documents.users.unknown')}</p>\n <Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={() => setPreviewVersionId(version.id)}><Eye />{t('documents.versions.actions.preview')}</Button>\n </article>\n ))}\n </div>\n {previewVersionId ? <VersionPreviewDialog documentId={documentId} versionId={previewVersionId} canRestore={mayRestore} isRestoring={restoringVersionId !== null} onOpenChange={(open) => { if (!open) setPreviewVersionId(null) }} onRestore={handleRestore} /> : null}\n </section>\n )\n}\n\nexport default VersionHistoryPanel\n"],
|
|
5
|
+
"mappings": ";AAgCQ,SACE,KADF;AA9BR,YAAY,WAAW;AACvB,OAAO,aAAa;AACpB,SAAS,OAAO,KAAK,SAAS,YAAY;AAC1C,SAAS,SAAS,sBAAsB;AACxC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,aAAa;AACtB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,QAAQ,eAAe,mBAAmB,cAAc,mBAAmB;AACpF,SAAS,aA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A,KACpQ;AAEJ;AAEA,IAAO,8BAAQ;",
|
|
6
|
+
"names": ["resolveVersionRestoreCapability", "normalizeVersion"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { EditorContent, useEditor } from "@tiptap/react";
|
|
5
|
+
import { RotateCcw } from "lucide-react";
|
|
6
|
+
import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
|
|
7
|
+
import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
|
|
8
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
9
|
+
import {
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogDescription,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogHeader,
|
|
15
|
+
DialogTitle
|
|
16
|
+
} from "@open-mercato/ui/primitives/dialog";
|
|
17
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
18
|
+
import { cn } from "@open-mercato/shared/lib/utils";
|
|
19
|
+
import { getDocumentEditorExtensions } from "../../../lib/editorConfig.js";
|
|
20
|
+
import { firstSafeDocumentsDisplayLabel } from "../../../lib/displayLabels.js";
|
|
21
|
+
import { sanitizeDocumentVersionLabel } from "../../../lib/versionLabels.js";
|
|
22
|
+
import { readRecord, readString } from "../documentUi.js";
|
|
23
|
+
import { DOCUMENT_EDITOR_CONTENT_CLASS } from "./editorTypes.js";
|
|
24
|
+
function normalizeVersionPreview(payload, fallbackCreatorLabel) {
|
|
25
|
+
const root = readRecord(payload);
|
|
26
|
+
const record = readRecord(root?.item) ?? readRecord(root?.data) ?? root;
|
|
27
|
+
if (!record) return null;
|
|
28
|
+
const id = readString(record, "id");
|
|
29
|
+
const creatorLabel = firstSafeDocumentsDisplayLabel(
|
|
30
|
+
readString(record, "creatorLabel", "creator_label"),
|
|
31
|
+
fallbackCreatorLabel
|
|
32
|
+
);
|
|
33
|
+
const createdAt = readString(record, "createdAt", "created_at");
|
|
34
|
+
if (!id || !creatorLabel || !createdAt) return null;
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
creatorLabel,
|
|
38
|
+
createdAt,
|
|
39
|
+
label: sanitizeDocumentVersionLabel(readString(record, "label")),
|
|
40
|
+
contentHtml: readString(record, "contentHtml", "content_html") ?? ""
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function ReadOnlyVersion({ contentHtml, fallbackLabel }) {
|
|
44
|
+
const editor = useEditor({
|
|
45
|
+
extensions: getDocumentEditorExtensions({ entityRefFallbackLabel: fallbackLabel }),
|
|
46
|
+
content: contentHtml,
|
|
47
|
+
editable: false,
|
|
48
|
+
editorProps: { attributes: { class: "min-h-64 text-base leading-7 text-foreground focus-visible:outline-none" } }
|
|
49
|
+
}, [contentHtml]);
|
|
50
|
+
React.useEffect(() => {
|
|
51
|
+
editor?.commands.setContent(contentHtml);
|
|
52
|
+
}, [contentHtml, editor]);
|
|
53
|
+
return /* @__PURE__ */ jsx(EditorContent, { editor, className: cn(DOCUMENT_EDITOR_CONTENT_CLASS, "rounded-md border border-border bg-card p-4") });
|
|
54
|
+
}
|
|
55
|
+
function VersionPreviewDialog({
|
|
56
|
+
documentId,
|
|
57
|
+
versionId,
|
|
58
|
+
canRestore,
|
|
59
|
+
isRestoring,
|
|
60
|
+
onOpenChange,
|
|
61
|
+
onRestore
|
|
62
|
+
}) {
|
|
63
|
+
const t = useT();
|
|
64
|
+
const [preview, setPreview] = React.useState(null);
|
|
65
|
+
const [error, setError] = React.useState(null);
|
|
66
|
+
const [loading, setLoading] = React.useState(false);
|
|
67
|
+
const [loadAttempt, setLoadAttempt] = React.useState(0);
|
|
68
|
+
const [confirmingRestore, setConfirmingRestore] = React.useState(false);
|
|
69
|
+
const cancelRestoreRef = React.useRef(null);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
setConfirmingRestore(false);
|
|
72
|
+
if (!versionId) {
|
|
73
|
+
setPreview(null);
|
|
74
|
+
setError(null);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let active = true;
|
|
78
|
+
setLoading(true);
|
|
79
|
+
setError(null);
|
|
80
|
+
void apiCall(`/api/documents/${encodeURIComponent(documentId)}/versions/${encodeURIComponent(versionId)}`).then((call) => {
|
|
81
|
+
if (!active) return;
|
|
82
|
+
const next = call.ok ? normalizeVersionPreview(call.result, t("documents.users.unknown")) : null;
|
|
83
|
+
if (!next) setError(t("documents.versions.preview.error"));
|
|
84
|
+
setPreview(next);
|
|
85
|
+
}).catch(() => {
|
|
86
|
+
if (active) setError(t("documents.versions.preview.error"));
|
|
87
|
+
}).finally(() => {
|
|
88
|
+
if (active) setLoading(false);
|
|
89
|
+
});
|
|
90
|
+
return () => {
|
|
91
|
+
active = false;
|
|
92
|
+
};
|
|
93
|
+
}, [documentId, loadAttempt, t, versionId]);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (confirmingRestore) cancelRestoreRef.current?.focus();
|
|
96
|
+
}, [confirmingRestore]);
|
|
97
|
+
const requestRestore = React.useCallback(() => {
|
|
98
|
+
if (!canRestore || !preview || isRestoring) return;
|
|
99
|
+
setConfirmingRestore(true);
|
|
100
|
+
}, [canRestore, isRestoring, preview]);
|
|
101
|
+
const confirmRestore = React.useCallback(() => {
|
|
102
|
+
if (!canRestore || !preview || isRestoring) return;
|
|
103
|
+
void onRestore(preview);
|
|
104
|
+
}, [canRestore, isRestoring, onRestore, preview]);
|
|
105
|
+
const handleOpenChange = React.useCallback((open) => {
|
|
106
|
+
if (!open) setConfirmingRestore(false);
|
|
107
|
+
onOpenChange(open);
|
|
108
|
+
}, [onOpenChange]);
|
|
109
|
+
return /* @__PURE__ */ jsx(Dialog, { open: versionId !== null, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { size: "xl", onKeyDown: (event) => {
|
|
110
|
+
if (event.key === "Escape") {
|
|
111
|
+
if (confirmingRestore) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
event.stopPropagation();
|
|
114
|
+
if (!isRestoring) setConfirmingRestore(false);
|
|
115
|
+
} else {
|
|
116
|
+
onOpenChange(false);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter" && canRestore && preview && !isRestoring) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
if (confirmingRestore) confirmRestore();
|
|
122
|
+
else requestRestore();
|
|
123
|
+
}
|
|
124
|
+
}, children: [
|
|
125
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
126
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: confirmingRestore ? t("documents.versions.restore.confirmTitle") : preview?.label ?? t("documents.versions.preview.title") }),
|
|
127
|
+
/* @__PURE__ */ jsx(DialogDescription, { "aria-live": confirmingRestore ? "assertive" : void 0, children: confirmingRestore ? t("documents.versions.restore.confirmBody") : preview ? t("documents.versions.preview.description", { creator: preview.creatorLabel, date: new Date(preview.createdAt).toLocaleString() }) : t("documents.versions.preview.loading") })
|
|
128
|
+
] }),
|
|
129
|
+
!confirmingRestore && loading ? /* @__PURE__ */ jsx(LoadingMessage, { label: t("documents.versions.preview.loading") }) : null,
|
|
130
|
+
!confirmingRestore && error ? /* @__PURE__ */ jsx(
|
|
131
|
+
ErrorMessage,
|
|
132
|
+
{
|
|
133
|
+
label: error,
|
|
134
|
+
action: /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setLoadAttempt((current) => current + 1), children: t("documents.actions.retry") })
|
|
135
|
+
}
|
|
136
|
+
) : null,
|
|
137
|
+
!confirmingRestore && preview && !loading && !error ? /* @__PURE__ */ jsx(ReadOnlyVersion, { contentHtml: preview.contentHtml, fallbackLabel: t("documents.editor.entityRef.fallbackLabel") }) : null,
|
|
138
|
+
/* @__PURE__ */ jsx(DialogFooter, { children: confirmingRestore ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
139
|
+
/* @__PURE__ */ jsx(Button, { ref: cancelRestoreRef, type: "button", variant: "outline", onClick: () => setConfirmingRestore(false), disabled: isRestoring, children: t("documents.actions.cancel") }),
|
|
140
|
+
/* @__PURE__ */ jsxs(Button, { type: "button", onClick: confirmRestore, disabled: isRestoring, children: [
|
|
141
|
+
/* @__PURE__ */ jsx(RotateCcw, {}),
|
|
142
|
+
t("documents.versions.actions.restore")
|
|
143
|
+
] })
|
|
144
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
145
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => onOpenChange(false), children: t("documents.actions.close") }),
|
|
146
|
+
canRestore && preview ? /* @__PURE__ */ jsxs(Button, { type: "button", onClick: requestRestore, disabled: isRestoring, children: [
|
|
147
|
+
/* @__PURE__ */ jsx(RotateCcw, {}),
|
|
148
|
+
t("documents.versions.actions.restore")
|
|
149
|
+
] }) : null
|
|
150
|
+
] }) })
|
|
151
|
+
] }) });
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
VersionPreviewDialog,
|
|
155
|
+
normalizeVersionPreview
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=VersionPreviewDialog.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/documents/backend/documents/%5Bid%5D/VersionPreviewDialog.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { EditorContent, useEditor } from '@tiptap/react'\nimport { RotateCcw } from 'lucide-react'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '@open-mercato/ui/primitives/dialog'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport { getDocumentEditorExtensions } from '../../../lib/editorConfig'\nimport { firstSafeDocumentsDisplayLabel } from '../../../lib/displayLabels'\nimport { sanitizeDocumentVersionLabel } from '../../../lib/versionLabels'\nimport { readRecord, readString } from '../documentUi'\nimport { DOCUMENT_EDITOR_CONTENT_CLASS } from './editorTypes'\n\nexport type VersionPreview = {\n id: string\n label: string | null\n creatorLabel: string\n createdAt: string\n contentHtml: string\n}\n\ntype VersionPreviewDialogProps = {\n documentId: string\n versionId: string | null\n canRestore: boolean\n isRestoring: boolean\n onOpenChange: (open: boolean) => void\n onRestore: (version: VersionPreview) => void | Promise<void>\n}\n\nexport function normalizeVersionPreview(\n payload: unknown,\n fallbackCreatorLabel?: string,\n): VersionPreview | null {\n const root = readRecord(payload)\n const record = readRecord(root?.item) ?? readRecord(root?.data) ?? root\n if (!record) return null\n const id = readString(record, 'id')\n const creatorLabel = firstSafeDocumentsDisplayLabel(\n readString(record, 'creatorLabel', 'creator_label'),\n fallbackCreatorLabel,\n )\n const createdAt = readString(record, 'createdAt', 'created_at')\n if (!id || !creatorLabel || !createdAt) return null\n return {\n id,\n creatorLabel,\n createdAt,\n label: sanitizeDocumentVersionLabel(readString(record, 'label')),\n contentHtml: readString(record, 'contentHtml', 'content_html') ?? '',\n }\n}\n\nfunction ReadOnlyVersion({ contentHtml, fallbackLabel }: { contentHtml: string; fallbackLabel: string }) {\n const editor = useEditor({\n extensions: getDocumentEditorExtensions({ entityRefFallbackLabel: fallbackLabel }),\n content: contentHtml,\n editable: false,\n editorProps: { attributes: { class: 'min-h-64 text-base leading-7 text-foreground focus-visible:outline-none' } },\n }, [contentHtml])\n React.useEffect(() => { editor?.commands.setContent(contentHtml) }, [contentHtml, editor])\n // Share the live editor's typography so tables keep their grid lines and\n // headings/lists read the same in the preview as on the canvas.\n return <EditorContent editor={editor} className={cn(DOCUMENT_EDITOR_CONTENT_CLASS, 'rounded-md border border-border bg-card p-4')} />\n}\n\nexport function VersionPreviewDialog({\n documentId,\n versionId,\n canRestore,\n isRestoring,\n onOpenChange,\n onRestore,\n}: VersionPreviewDialogProps) {\n const t = useT()\n const [preview, setPreview] = React.useState<VersionPreview | null>(null)\n const [error, setError] = React.useState<string | null>(null)\n const [loading, setLoading] = React.useState(false)\n const [loadAttempt, setLoadAttempt] = React.useState(0)\n const [confirmingRestore, setConfirmingRestore] = React.useState(false)\n const cancelRestoreRef = React.useRef<HTMLButtonElement>(null)\n\n React.useEffect(() => {\n setConfirmingRestore(false)\n if (!versionId) { setPreview(null); setError(null); return }\n let active = true\n setLoading(true)\n setError(null)\n void apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}/versions/${encodeURIComponent(versionId)}`)\n .then((call) => {\n if (!active) return\n const next = call.ok\n ? normalizeVersionPreview(call.result, t('documents.users.unknown'))\n : null\n if (!next) setError(t('documents.versions.preview.error'))\n setPreview(next)\n })\n .catch(() => { if (active) setError(t('documents.versions.preview.error')) })\n .finally(() => { if (active) setLoading(false) })\n return () => { active = false }\n }, [documentId, loadAttempt, t, versionId])\n\n React.useEffect(() => {\n if (confirmingRestore) cancelRestoreRef.current?.focus()\n }, [confirmingRestore])\n\n const requestRestore = React.useCallback(() => {\n if (!canRestore || !preview || isRestoring) return\n setConfirmingRestore(true)\n }, [canRestore, isRestoring, preview])\n\n const confirmRestore = React.useCallback(() => {\n if (!canRestore || !preview || isRestoring) return\n void onRestore(preview)\n }, [canRestore, isRestoring, onRestore, preview])\n\n const handleOpenChange = React.useCallback((open: boolean) => {\n if (!open) setConfirmingRestore(false)\n onOpenChange(open)\n }, [onOpenChange])\n\n return (\n <Dialog open={versionId !== null} onOpenChange={handleOpenChange}>\n <DialogContent size=\"xl\" onKeyDown={(event) => {\n if (event.key === 'Escape') {\n if (confirmingRestore) {\n event.preventDefault()\n event.stopPropagation()\n if (!isRestoring) setConfirmingRestore(false)\n } else {\n onOpenChange(false)\n }\n }\n if ((event.metaKey || event.ctrlKey) && event.key === 'Enter' && canRestore && preview && !isRestoring) {\n event.preventDefault()\n if (confirmingRestore) confirmRestore()\n else requestRestore()\n }\n }}>\n <DialogHeader>\n <DialogTitle>\n {confirmingRestore\n ? t('documents.versions.restore.confirmTitle')\n : preview?.label ?? t('documents.versions.preview.title')}\n </DialogTitle>\n <DialogDescription aria-live={confirmingRestore ? 'assertive' : undefined}>\n {confirmingRestore\n ? t('documents.versions.restore.confirmBody')\n : preview\n ? t('documents.versions.preview.description', { creator: preview.creatorLabel, date: new Date(preview.createdAt).toLocaleString() })\n : t('documents.versions.preview.loading')}\n </DialogDescription>\n </DialogHeader>\n {!confirmingRestore && loading ? <LoadingMessage label={t('documents.versions.preview.loading')} /> : null}\n {!confirmingRestore && error ? (\n <ErrorMessage\n label={error}\n action={<Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={() => setLoadAttempt((current) => current + 1)}>{t('documents.actions.retry')}</Button>}\n />\n ) : null}\n {!confirmingRestore && preview && !loading && !error ? <ReadOnlyVersion contentHtml={preview.contentHtml} fallbackLabel={t('documents.editor.entityRef.fallbackLabel')} /> : null}\n <DialogFooter>\n {confirmingRestore ? (\n <>\n <Button ref={cancelRestoreRef} type=\"button\" variant=\"outline\" onClick={() => setConfirmingRestore(false)} disabled={isRestoring}>\n {t('documents.actions.cancel')}\n </Button>\n <Button type=\"button\" onClick={confirmRestore} disabled={isRestoring}>\n <RotateCcw />{t('documents.versions.actions.restore')}\n </Button>\n </>\n ) : (\n <>\n <Button type=\"button\" variant=\"outline\" onClick={() => onOpenChange(false)}>{t('documents.actions.close')}</Button>\n {canRestore && preview ? (\n <Button type=\"button\" onClick={requestRestore} disabled={isRestoring}>\n <RotateCcw />{t('documents.versions.actions.restore')}\n </Button>\n ) : null}\n </>\n )}\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA0ES,SAoGG,UApGH,KA4ED,YA5EC;AAxET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nchor, normalizeDocumentCommentAnchor } from "../../../lib/commentAnchors.js";
|
|
2
|
+
import {
|
|
3
|
+
firstSafeDocumentsDisplayLabel,
|
|
4
|
+
sanitizeDocumentsDisplayLabel
|
|
5
|
+
} from "../../../lib/displayLabels.js";
|
|
6
|
+
import { readArrayPayload, readBoolean, readRecord, readString } from "../documentUi.js";
|
|
7
|
+
const MENTION_WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
8
|
+
function isMentionTokenBoundary(body, index, tokenLength) {
|
|
9
|
+
const before = index > 0 ? body[index - 1] ?? "" : "";
|
|
10
|
+
const after = body[index + tokenLength] ?? "";
|
|
11
|
+
return !MENTION_WORD_CHARACTER.test(before) && !MENTION_WORD_CHARACTER.test(after);
|
|
12
|
+
}
|
|
13
|
+
function bodyContainsPendingMention(body, mention) {
|
|
14
|
+
const token = `@${mention.name}`;
|
|
15
|
+
let index = body.indexOf(token);
|
|
16
|
+
while (index >= 0) {
|
|
17
|
+
if (isMentionTokenBoundary(body, index, token.length)) return true;
|
|
18
|
+
index = body.indexOf(token, index + token.length);
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function removePendingMentionOccurrences(body, mention, pendingMentions) {
|
|
23
|
+
const token = `@${mention.name}`;
|
|
24
|
+
const extendingTokens = pendingMentions.map((candidate) => `@${candidate.name}`).filter((candidate) => candidate.length > token.length && candidate.startsWith(token)).sort((left, right) => right.length - left.length);
|
|
25
|
+
let result = "";
|
|
26
|
+
let cursor = 0;
|
|
27
|
+
while (cursor < body.length) {
|
|
28
|
+
const extending = extendingTokens.find((candidate) => body.startsWith(candidate, cursor) && isMentionTokenBoundary(body, cursor, candidate.length));
|
|
29
|
+
if (extending) {
|
|
30
|
+
result += extending;
|
|
31
|
+
cursor += extending.length;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (body.startsWith(token, cursor) && isMentionTokenBoundary(body, cursor, token.length)) {
|
|
35
|
+
cursor += token.length;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
result += body[cursor];
|
|
39
|
+
cursor += 1;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function readNullableString(record, ...keys) {
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
const value = record[key];
|
|
46
|
+
if (value === null) return null;
|
|
47
|
+
if (typeof value === "string" && value.trim().length > 0) return value;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function readAnchor(value) {
|
|
52
|
+
if (value === null || value === void 0) return null;
|
|
53
|
+
const normalized = normalizeDocumentCommentAnchor(value);
|
|
54
|
+
return isChangedDocumentCommentAnchor(normalized) ? "changed" : normalized;
|
|
55
|
+
}
|
|
56
|
+
function readMentions(value) {
|
|
57
|
+
if (!Array.isArray(value)) return [];
|
|
58
|
+
return value.flatMap((entry) => {
|
|
59
|
+
const record = readRecord(entry);
|
|
60
|
+
const userId = record ? readString(record, "userId", "user_id") : null;
|
|
61
|
+
return userId ? [{ userId: userId.toLowerCase() }] : [];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function normalizeComment(value) {
|
|
65
|
+
const record = readRecord(value);
|
|
66
|
+
if (!record) return null;
|
|
67
|
+
const id = readString(record, "id");
|
|
68
|
+
const documentId = readString(record, "documentId", "document_id");
|
|
69
|
+
const authorUserId = readString(record, "authorUserId", "author_user_id");
|
|
70
|
+
const createdAt = readString(record, "createdAt", "created_at");
|
|
71
|
+
const updatedAt = readString(record, "updatedAt", "updated_at");
|
|
72
|
+
if (!id || !documentId || !authorUserId || !createdAt || !updatedAt) return null;
|
|
73
|
+
const replies = Array.isArray(record.replies) ? record.replies.map(normalizeComment).filter((reply) => reply !== null) : [];
|
|
74
|
+
return {
|
|
75
|
+
id,
|
|
76
|
+
documentId,
|
|
77
|
+
parentCommentId: readNullableString(record, "parentCommentId", "parent_comment_id"),
|
|
78
|
+
authorUserId,
|
|
79
|
+
body: readString(record, "body") ?? "",
|
|
80
|
+
mentions: readMentions(record.mentions),
|
|
81
|
+
anchor: readAnchor(record.anchor),
|
|
82
|
+
resolvedAt: readNullableString(record, "resolvedAt", "resolved_at"),
|
|
83
|
+
resolvedByUserId: readNullableString(record, "resolvedByUserId", "resolved_by_user_id"),
|
|
84
|
+
createdAt,
|
|
85
|
+
updatedAt,
|
|
86
|
+
canResolve: readBoolean(record, "canResolve", "can_resolve") ?? false,
|
|
87
|
+
replies
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function readCommentItems(payload) {
|
|
91
|
+
return readArrayPayload(payload, "items", "data").map(normalizeComment).filter((comment) => comment !== null);
|
|
92
|
+
}
|
|
93
|
+
function readUserLabels(payload, fallbackLabel) {
|
|
94
|
+
const record = readRecord(payload);
|
|
95
|
+
const rawLabels = readRecord(record?.userLabels);
|
|
96
|
+
if (!rawLabels) return {};
|
|
97
|
+
const safeFallback = sanitizeDocumentsDisplayLabel(fallbackLabel);
|
|
98
|
+
const labels = {};
|
|
99
|
+
for (const [userId, value] of Object.entries(rawLabels)) {
|
|
100
|
+
const labelRecord = readRecord(value);
|
|
101
|
+
const label = labelRecord ? firstSafeDocumentsDisplayLabel(readString(labelRecord, "label"), safeFallback) : safeFallback;
|
|
102
|
+
const secondary = labelRecord ? sanitizeDocumentsDisplayLabel(readNullableString(labelRecord, "secondary")) : null;
|
|
103
|
+
if (label) labels[userId.toLowerCase()] = {
|
|
104
|
+
label,
|
|
105
|
+
secondary: secondary && secondary !== label ? secondary : null
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return labels;
|
|
109
|
+
}
|
|
110
|
+
function readWithoutAccess(payload) {
|
|
111
|
+
const record = readRecord(payload);
|
|
112
|
+
if (!record) return [];
|
|
113
|
+
if (Array.isArray(record.withoutAccessUsers)) {
|
|
114
|
+
return record.withoutAccessUsers.flatMap((value) => {
|
|
115
|
+
const user = readRecord(value);
|
|
116
|
+
const userId = user ? readString(user, "userId", "user_id", "id") : null;
|
|
117
|
+
if (!userId || !user) return [];
|
|
118
|
+
const label = sanitizeDocumentsDisplayLabel(readNullableString(user, "label"));
|
|
119
|
+
const secondary = sanitizeDocumentsDisplayLabel(readNullableString(user, "secondary"));
|
|
120
|
+
return [{
|
|
121
|
+
userId: userId.toLowerCase(),
|
|
122
|
+
label,
|
|
123
|
+
secondary: secondary && secondary !== label ? secondary : null
|
|
124
|
+
}];
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (!Array.isArray(record.withoutAccess)) return [];
|
|
128
|
+
return record.withoutAccess.flatMap((value) => typeof value === "string" ? [{
|
|
129
|
+
userId: value.toLowerCase(),
|
|
130
|
+
label: null,
|
|
131
|
+
secondary: null
|
|
132
|
+
}] : []);
|
|
133
|
+
}
|
|
134
|
+
function findCommentById(comments, commentId) {
|
|
135
|
+
for (const comment of comments) {
|
|
136
|
+
if (comment.id === commentId) return comment;
|
|
137
|
+
const reply = findCommentById(comment.replies, commentId);
|
|
138
|
+
if (reply) return reply;
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
bodyContainsPendingMention,
|
|
144
|
+
findCommentById,
|
|
145
|
+
readCommentItems,
|
|
146
|
+
readUserLabels,
|
|
147
|
+
readWithoutAccess,
|
|
148
|
+
removePendingMentionOccurrences
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=commentTypes.js.map
|