@open-mercato/documents 0.9.1-develop.7574.1.837288eec1 → 0.10.0

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.
Files changed (97) hide show
  1. package/dist/contentSecurityPolicy.js +23 -0
  2. package/dist/contentSecurityPolicy.js.map +7 -0
  3. package/dist/modules/documents/api/[id]/comments/access-check/route.js +13 -6
  4. package/dist/modules/documents/api/[id]/comments/access-check/route.js.map +2 -2
  5. package/dist/modules/documents/api/[id]/comments/route.js +2 -0
  6. package/dist/modules/documents/api/[id]/comments/route.js.map +2 -2
  7. package/dist/modules/documents/api/[id]/content/route.js +2 -0
  8. package/dist/modules/documents/api/[id]/content/route.js.map +2 -2
  9. package/dist/modules/documents/api/[id]/route.js +3 -0
  10. package/dist/modules/documents/api/[id]/route.js.map +2 -2
  11. package/dist/modules/documents/api/[id]/shares/route.js +2 -0
  12. package/dist/modules/documents/api/[id]/shares/route.js.map +2 -2
  13. package/dist/modules/documents/api/[id]/versions/route.js +2 -0
  14. package/dist/modules/documents/api/[id]/versions/route.js.map +2 -2
  15. package/dist/modules/documents/api/_shared.js +10 -27
  16. package/dist/modules/documents/api/_shared.js.map +3 -3
  17. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js +3 -1
  18. package/dist/modules/documents/backend/documents/[id]/DocumentCanvas.js.map +2 -2
  19. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js +1 -1
  20. package/dist/modules/documents/backend/documents/[id]/DocumentEditorIsland.js.map +2 -2
  21. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js +15 -1
  22. package/dist/modules/documents/backend/documents/[id]/DocumentEditorSurface.js.map +2 -2
  23. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js +15 -1
  24. package/dist/modules/documents/backend/documents/[id]/DocumentPageClient.js.map +2 -2
  25. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js +20 -8
  26. package/dist/modules/documents/backend/documents/[id]/VersionHistoryPanel.js.map +2 -2
  27. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js +3 -0
  28. package/dist/modules/documents/backend/documents/[id]/VersionPreviewDialog.js.map +2 -2
  29. package/dist/modules/documents/backend/documents/[id]/editorTypes.js.map +2 -2
  30. package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js +46 -0
  31. package/dist/modules/documents/backend/documents/[id]/saveCollaborativeContent.js.map +7 -0
  32. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js +14 -6
  33. package/dist/modules/documents/backend/documents/[id]/useDocumentComments.js.map +2 -2
  34. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js +3 -0
  35. package/dist/modules/documents/backend/documents/[id]/useDocumentEditor.js.map +2 -2
  36. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js +3 -0
  37. package/dist/modules/documents/backend/documents/components/TemplateBodyEditor.js.map +2 -2
  38. package/dist/modules/documents/backend/documents/components/TemplatePreview.js +3 -0
  39. package/dist/modules/documents/backend/documents/components/TemplatePreview.js.map +2 -2
  40. package/dist/modules/documents/commands/comments.js +2 -2
  41. package/dist/modules/documents/commands/comments.js.map +2 -2
  42. package/dist/modules/documents/commands/folders.js +1 -0
  43. package/dist/modules/documents/commands/folders.js.map +2 -2
  44. package/dist/modules/documents/commands/interceptors.js +11 -0
  45. package/dist/modules/documents/commands/interceptors.js.map +2 -2
  46. package/dist/modules/documents/data/attachment-access.js +84 -0
  47. package/dist/modules/documents/data/attachment-access.js.map +7 -0
  48. package/dist/modules/documents/data/validators.js +11 -0
  49. package/dist/modules/documents/data/validators.js.map +2 -2
  50. package/dist/modules/documents/lib/actor.js +32 -0
  51. package/dist/modules/documents/lib/actor.js.map +7 -0
  52. package/dist/modules/documents/lib/collabMaterializer.js +52 -9
  53. package/dist/modules/documents/lib/collabMaterializer.js.map +2 -2
  54. package/dist/modules/documents/lib/collabPersistence.js +13 -0
  55. package/dist/modules/documents/lib/collabPersistence.js.map +7 -0
  56. package/dist/modules/documents/lib/permissions.js +35 -2
  57. package/dist/modules/documents/lib/permissions.js.map +2 -2
  58. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js +3 -2
  59. package/dist/modules/documents/widgets/injection/related-documents/widget.client.js.map +2 -2
  60. package/dist/modules/documents/widgets/injection-table.js +12 -3
  61. package/dist/modules/documents/widgets/injection-table.js.map +2 -2
  62. package/dist/server/documents-collab-server.js +74 -1
  63. package/dist/server/documents-collab-server.js.map +2 -2
  64. package/jest.config.cjs +1 -1
  65. package/package.json +37 -37
  66. package/server/documents-collab-server.ts +79 -0
  67. package/src/contentSecurityPolicy.ts +21 -0
  68. package/src/modules/documents/api/[id]/comments/access-check/route.ts +13 -6
  69. package/src/modules/documents/api/[id]/comments/route.ts +2 -0
  70. package/src/modules/documents/api/[id]/content/route.ts +2 -0
  71. package/src/modules/documents/api/[id]/route.ts +3 -0
  72. package/src/modules/documents/api/[id]/shares/route.ts +2 -0
  73. package/src/modules/documents/api/[id]/versions/route.ts +2 -0
  74. package/src/modules/documents/api/_shared.ts +10 -36
  75. package/src/modules/documents/backend/documents/[id]/DocumentCanvas.tsx +3 -1
  76. package/src/modules/documents/backend/documents/[id]/DocumentEditorIsland.tsx +4 -1
  77. package/src/modules/documents/backend/documents/[id]/DocumentEditorSurface.tsx +19 -1
  78. package/src/modules/documents/backend/documents/[id]/DocumentPageClient.tsx +14 -0
  79. package/src/modules/documents/backend/documents/[id]/VersionHistoryPanel.tsx +23 -8
  80. package/src/modules/documents/backend/documents/[id]/VersionPreviewDialog.tsx +3 -0
  81. package/src/modules/documents/backend/documents/[id]/editorTypes.ts +1 -0
  82. package/src/modules/documents/backend/documents/[id]/saveCollaborativeContent.ts +43 -0
  83. package/src/modules/documents/backend/documents/[id]/useDocumentComments.ts +17 -7
  84. package/src/modules/documents/backend/documents/[id]/useDocumentEditor.ts +3 -0
  85. package/src/modules/documents/backend/documents/components/TemplateBodyEditor.tsx +3 -0
  86. package/src/modules/documents/backend/documents/components/TemplatePreview.tsx +3 -0
  87. package/src/modules/documents/commands/comments.ts +2 -2
  88. package/src/modules/documents/commands/folders.ts +1 -3
  89. package/src/modules/documents/commands/interceptors.ts +11 -0
  90. package/src/modules/documents/data/attachment-access.ts +83 -0
  91. package/src/modules/documents/data/validators.ts +12 -0
  92. package/src/modules/documents/lib/actor.ts +39 -0
  93. package/src/modules/documents/lib/collabMaterializer.ts +62 -11
  94. package/src/modules/documents/lib/collabPersistence.ts +10 -0
  95. package/src/modules/documents/lib/permissions.ts +52 -0
  96. package/src/modules/documents/widgets/injection/related-documents/widget.client.tsx +3 -2
  97. package/src/modules/documents/widgets/injection-table.ts +17 -3
@@ -66,6 +66,17 @@ function DocumentPageClient({ documentId }) {
66
66
  const scrollVersionsIntoView = React.useRef(false);
67
67
  const [editorEpoch, setEditorEpoch] = React.useState(0);
68
68
  const [editor, setEditor] = React.useState(null);
69
+ const contentSaveRef = React.useRef(null);
70
+ const displayedDocumentId = state.status === "ready" ? state.document.id : null;
71
+ const registerContentSave = React.useCallback((save) => {
72
+ contentSaveRef.current = save && displayedDocumentId ? { documentId: displayedDocumentId, save } : null;
73
+ }, [displayedDocumentId]);
74
+ const saveBeforeSnapshot = React.useCallback(async () => {
75
+ const registered = contentSaveRef.current;
76
+ if (!registered || registered.documentId !== documentId) return false;
77
+ const saved = await registered.save();
78
+ return saved && contentSaveRef.current === registered;
79
+ }, [documentId]);
69
80
  const [commentFocusRequest, setCommentFocusRequest] = React.useState(null);
70
81
  const requestSequence = React.useRef(0);
71
82
  const mutationContextId = `documents-detail:${documentId}`;
@@ -112,6 +123,7 @@ function DocumentPageClient({ documentId }) {
112
123
  throw new Error(t("documents.editor.error.loadContent"));
113
124
  }
114
125
  const nextContent = contentCall.status === 404 ? { contentHtml: "", updatedAt: null } : normalizeDocumentContent(contentCall.result);
126
+ contentSaveRef.current = null;
115
127
  setState((current) => current.status === "ready" ? {
116
128
  ...current,
117
129
  content: nextContent
@@ -364,6 +376,7 @@ function DocumentPageClient({ documentId }) {
364
376
  documentUpdatedAt: document.updatedAt,
365
377
  readOnly: !capabilities.canEdit,
366
378
  onEditorReady: setEditor,
379
+ onSaveReady: registerContentSave,
367
380
  onContentConflict: handleContentConflict,
368
381
  onComment: capabilities.canComment ? (anchor) => setCommentFocusRequest((current) => ({ anchor, requestId: (current?.requestId ?? 0) + 1 })) : void 0,
369
382
  onTitleChange: (title, updatedAt) => setState((current) => current.status === "ready" ? {
@@ -400,7 +413,8 @@ function DocumentPageClient({ documentId }) {
400
413
  documentId: document.id,
401
414
  canRestore: capabilities.canEdit,
402
415
  contentUpdatedAt: content.updatedAt,
403
- onRestored: reloadEditor
416
+ onRestored: reloadEditor,
417
+ onBeforeSnapshot: saveBeforeSnapshot
404
418
  }
405
419
  )
406
420
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/documents/backend/documents/%5Bid%5D/DocumentPageClient.tsx"],
4
- "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Archive, ArchiveRestore, Bell, Copy, History, Star, Trash2 } from 'lucide-react'\nimport type { Editor } from '@tiptap/core'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { LoadingMessage, ErrorMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { apiCall, apiCallOrThrow, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { LinkButton } from '@open-mercato/ui/primitives/link-button'\nimport { SimpleTooltip } from '@open-mercato/ui/primitives/tooltip'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { ShareDialog } from '../components/ShareDialog'\nimport { normalizeDocumentContent, normalizeDocumentDetail, type DocumentContent, type DocumentDetail } from '../documentUi'\nimport { CommentsRail } from './CommentsRail'\nimport type { CommentAnchor } from './CommentAnchorNavigation'\nimport { ExportMenu } from './ExportMenu'\nimport { RelatedRecordsPanel } from './RelatedRecordsPanel'\nimport { DocumentNavigator } from './DocumentNavigator'\nimport { DocumentEditorErrorBoundary } from './DocumentEditorErrorBoundary'\nimport { VersionHistoryPanel } from './VersionHistoryPanel'\n\nfunction DocumentEditorLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {\n const t = useT()\n if (error) {\n return (\n <ErrorMessage\n label={t('documents.editor.error.load')}\n action={<Button type=\"button\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )\n }\n return <div role=\"status\" aria-live=\"polite\"><LoadingMessage label={t('documents.editor.loading')} /></div>\n}\n\nconst DocumentEditorIsland = dynamic(() => import('./DocumentEditorIsland'), { ssr: false, loading: DocumentEditorLoading })\n\nconst PANEL_REVEAL_OFFSET_PX = 16\n\nexport function revealPanelInScrollContainer(panel: HTMLElement): void {\n const behavior: ScrollBehavior = window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'\n let container = panel.parentElement\n while (container) {\n const overflowY = window.getComputedStyle(container).overflowY\n if ((overflowY === 'auto' || overflowY === 'scroll') && container.scrollHeight > container.clientHeight) {\n const offset = panel.getBoundingClientRect().top - container.getBoundingClientRect().top + container.scrollTop\n container.scrollTo({ top: Math.max(0, offset - PANEL_REVEAL_OFFSET_PX), behavior })\n return\n }\n container = container.parentElement\n }\n panel.scrollIntoView({ block: 'start', behavior })\n}\n\ntype CommentFocusRequest = { anchor: CommentAnchor; requestId: number }\ntype LoadState =\n | { status: 'loading' }\n | { status: 'notFound' }\n | { status: 'error'; message: string }\n | { status: 'ready'; document: DocumentDetail; content: DocumentContent }\n\nexport function DocumentPageClient({ documentId }: { documentId: string }) {\n const t = useT()\n const router = useRouter()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const [state, setState] = React.useState<LoadState>({ status: 'loading' })\n const [shareOpen, setShareOpen] = React.useState(false)\n const [showVersions, setShowVersions] = React.useState(false)\n const versionsPanelRef = React.useRef<HTMLDivElement | null>(null)\n const scrollVersionsIntoView = React.useRef(false)\n const [editorEpoch, setEditorEpoch] = React.useState(0)\n const [editor, setEditor] = React.useState<Editor | null>(null)\n const [commentFocusRequest, setCommentFocusRequest] = React.useState<CommentFocusRequest | null>(null)\n const requestSequence = React.useRef(0)\n const mutationContextId = `documents-detail:${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 loadDocument = React.useCallback(async () => {\n const requestId = ++requestSequence.current\n setState({ status: 'loading' })\n try {\n const [documentCall, contentCall] = await Promise.all([\n apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}`),\n apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}/content`),\n ])\n if (requestSequence.current !== requestId) return\n if (documentCall.status === 404) return setState({ status: 'notFound' })\n if (!documentCall.ok) return setState({ status: 'error', message: t('documents.editor.error.load') })\n if (!contentCall.ok && contentCall.status !== 404) {\n return setState({ status: 'error', message: t('documents.editor.error.loadContent') })\n }\n const document = normalizeDocumentDetail(documentCall.result)\n if (!document) return setState({ status: 'error', message: t('documents.editor.error.load') })\n setState({\n status: 'ready',\n document,\n content: contentCall.status === 404\n ? { contentHtml: '', updatedAt: null }\n : normalizeDocumentContent(contentCall.result),\n })\n } catch (error) {\n if (requestSequence.current !== requestId) return\n setState({ status: 'error', message: error instanceof Error ? error.message : t('documents.editor.error.load') })\n }\n }, [documentId, t])\n\n React.useEffect(() => {\n void loadDocument()\n return () => { requestSequence.current += 1 }\n }, [loadDocument])\n\n const reloadEditor = React.useCallback(async () => {\n const requestId = ++requestSequence.current\n const contentCall = await apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}/content`)\n if (requestSequence.current !== requestId) {\n throw new Error(t('documents.editor.error.loadContent'))\n }\n if (!contentCall.ok && contentCall.status !== 404) {\n throw new Error(t('documents.editor.error.loadContent'))\n }\n const nextContent = contentCall.status === 404\n ? { contentHtml: '', updatedAt: null }\n : normalizeDocumentContent(contentCall.result)\n setState((current) => current.status === 'ready' ? {\n ...current,\n content: nextContent,\n } : current)\n setEditor(null)\n setEditorEpoch((current) => current + 1)\n }, [documentId, t])\n\n const handleContentConflict = React.useCallback(() => {\n void reloadEditor().catch((error) => {\n flash(error instanceof Error ? error.message : t('documents.editor.error.loadContent'), 'error')\n })\n }, [reloadEditor, t])\n\n const retryEditorIsland = React.useCallback(() => {\n setEditor(null)\n setEditorEpoch((current) => current + 1)\n }, [])\n\n const toggleVersions = React.useCallback(() => {\n setShowVersions((value) => {\n scrollVersionsIntoView.current = !value\n return !value\n })\n }, [])\n\n // The versions panel mounts at the bottom of the side rail, below the fold on\n // a laptop screen, so opening it gave no visible feedback. Bring it to the\n // top of whichever container scrolls the rail (the sticky aside on wide\n // screens, the page otherwise) and hand it focus for keyboard users.\n React.useLayoutEffect(() => {\n if (!showVersions || !scrollVersionsIntoView.current) return\n scrollVersionsIntoView.current = false\n const panel = versionsPanelRef.current\n if (!panel) return\n revealPanelInScrollContainer(panel)\n panel.focus({ preventScroll: true })\n }, [showVersions])\n\n const setDocumentState = React.useCallback((mutate: (document: DocumentDetail) => DocumentDetail) => {\n setState((current) => current.status === 'ready'\n ? { ...current, document: mutate(current.document) }\n : current)\n }, [])\n\n const pendingToggles = React.useRef<Set<'favorite' | 'watch'>>(new Set())\n const runPersonalToggle = React.useCallback(async (\n kind: 'favorite' | 'watch',\n active: boolean,\n ) => {\n if (state.status !== 'ready' || pendingToggles.current.has(kind)) return\n pendingToggles.current.add(kind)\n const flag = kind === 'favorite' ? 'isFavorite' as const : 'isWatching' as const\n setDocumentState((document) => ({ ...document, [flag]: active }))\n try {\n await runMutation({\n operation: () => apiCallOrThrow(\n `/api/documents/${encodeURIComponent(documentId)}/${kind}`,\n { method: active ? 'POST' : 'DELETE' },\n ),\n context: {\n formId: mutationContextId,\n resourceKind: kind === 'favorite' ? 'documents.document_favorite' : 'documents.document_watcher',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { documentId, active },\n })\n } catch (error) {\n setDocumentState((document) => ({ ...document, [flag]: !active }))\n flash(error instanceof Error ? error.message : t('documents.editor.error.load'), 'error')\n } finally {\n pendingToggles.current.delete(kind)\n }\n }, [documentId, mutationContextId, retryLastMutation, runMutation, setDocumentState, state.status, t])\n\n const duplicating = React.useRef(false)\n const [isDuplicating, setIsDuplicating] = React.useState(false)\n const handleDuplicate = React.useCallback(async () => {\n if (state.status !== 'ready' || duplicating.current) return\n duplicating.current = true\n setIsDuplicating(true)\n try {\n const created = await runMutation({\n operation: () => apiCallOrThrow<{ id: string }>(\n `/api/documents/${encodeURIComponent(documentId)}/duplicate`,\n { method: 'POST', body: JSON.stringify({}), headers: { 'content-type': 'application/json' } },\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { action: 'duplicate', sourceDocumentId: documentId },\n })\n flash(t('documents.duplicate.success'), 'success')\n const createdId = created?.result?.id\n if (createdId) router.push(`/backend/documents/${encodeURIComponent(createdId)}`)\n } catch (error) {\n flash(error instanceof Error ? error.message : t('documents.duplicate.error'), 'error')\n } finally {\n duplicating.current = false\n setIsDuplicating(false)\n }\n }, [documentId, mutationContextId, retryLastMutation, router, runMutation, state.status, t])\n\n const handleArchiveToggle = React.useCallback(async () => {\n if (state.status !== 'ready' || !state.document.capabilities.canArchive) return\n const archived = state.document.archivedAt !== null\n const action = archived ? 'unarchive' : 'archive'\n try {\n await runMutation({\n operation: () => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(state.document.updatedAt),\n () => apiCallOrThrow(`/api/documents/${encodeURIComponent(documentId)}/${action}`, { method: 'POST' }),\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { action, documentId },\n })\n flash(t(archived ? 'documents.archive.success.unarchive' : 'documents.archive.success.archive'), 'success')\n await loadDocument()\n } catch (error) {\n if (!surfaceRecordConflict(error, t, { onRefresh: () => { void loadDocument() } })) {\n flash(error instanceof Error ? error.message : t('documents.archive.error'), 'error')\n }\n }\n }, [documentId, loadDocument, mutationContextId, retryLastMutation, runMutation, state, t])\n\n const handleDelete = React.useCallback(async () => {\n if (state.status !== 'ready' || !state.document.capabilities.canDelete) return\n const confirmed = await confirm({\n title: t('documents.list.confirmDelete', { title: state.document.title }),\n variant: 'destructive',\n })\n if (!confirmed) return\n try {\n await runMutation({\n operation: () => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(state.document.updatedAt),\n () => apiCallOrThrow(`/api/documents/${encodeURIComponent(documentId)}`, { method: 'DELETE' }),\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { id: documentId },\n })\n flash(t('documents.list.success.delete'), 'success')\n router.push('/backend/documents')\n } catch (error) {\n if (!surfaceRecordConflict(error, t, { onRefresh: () => { void loadDocument() } })) {\n flash(error instanceof Error ? error.message : t('documents.list.error.delete'), 'error')\n }\n }\n }, [confirm, documentId, loadDocument, mutationContextId, retryLastMutation, router, runMutation, state, t])\n\n if (state.status !== 'ready') {\n if (state.status === 'notFound') {\n return (\n <Page><PageBody>\n <RecordNotFoundState\n label={t('documents.editor.notFound')}\n backHref=\"/backend/documents\"\n backLabel={t('documents.actions.backToList')}\n />\n </PageBody></Page>\n )\n }\n const label = state.status === 'loading' ? t('documents.editor.loading') : state.message\n return (\n <Page><PageBody>\n {state.status === 'loading' ? <LoadingMessage label={label} /> : (\n <ErrorMessage label={label} action={(\n <div className=\"flex flex-wrap gap-2\">\n <Button type=\"button\" onClick={() => void loadDocument()}>{t('documents.actions.retry')}</Button>\n <LinkButton asChild variant=\"gray\"><Link href=\"/backend/documents\">{t('documents.actions.backToList')}</Link></LinkButton>\n </div>\n )} />\n )}\n </PageBody></Page>\n )\n }\n\n const { document, content } = state\n const capabilities = document.capabilities\n return (\n <Page>\n <PageHeader title={t('documents.nav.document')} actions={(\n <>\n <LinkButton asChild variant=\"gray\"><Link href=\"/backend/documents\">{t('documents.actions.backToList')}</Link></LinkButton>\n <SimpleTooltip content={t(document.isFavorite ? 'documents.actions.unfavorite' : 'documents.actions.favorite')} size=\"sm\">\n <IconButton\n type=\"button\"\n variant=\"outline\"\n size=\"lg\"\n onClick={() => void runPersonalToggle('favorite', !document.isFavorite)}\n aria-pressed={document.isFavorite}\n aria-label={t(document.isFavorite ? 'documents.actions.unfavorite' : 'documents.actions.favorite')}\n >\n <Star />\n </IconButton>\n </SimpleTooltip>\n <SimpleTooltip content={t(document.isWatching ? 'documents.actions.unwatch' : 'documents.actions.watch')} size=\"sm\">\n <IconButton\n type=\"button\"\n variant=\"outline\"\n size=\"lg\"\n onClick={() => void runPersonalToggle('watch', !document.isWatching)}\n aria-pressed={document.isWatching}\n aria-label={t(document.isWatching ? 'documents.actions.unwatch' : 'documents.actions.watch')}\n >\n <Bell />\n </IconButton>\n </SimpleTooltip>\n <Button type=\"button\" variant={showVersions ? 'secondary' : 'outline'} onClick={toggleVersions} aria-pressed={showVersions}>\n <History />{t('documents.actions.versions')}\n </Button>\n <ExportMenu documentId={document.id} editor={editor} />\n {capabilities.canDuplicate ? (\n <Button type=\"button\" variant=\"outline\" disabled={isDuplicating} onClick={() => void handleDuplicate()}>\n <Copy />{t('documents.actions.duplicate')}\n </Button>\n ) : null}\n {capabilities.canArchive ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleArchiveToggle()}>\n {document.archivedAt ? <ArchiveRestore /> : <Archive />}\n {t(document.archivedAt ? 'documents.actions.unarchive' : 'documents.actions.archive')}\n </Button>\n ) : null}\n {capabilities.canShare ? <Button type=\"button\" variant=\"outline\" onClick={() => setShareOpen(true)}>{t('documents.actions.share')}</Button> : null}\n {capabilities.canDelete ? <Button type=\"button\" variant=\"destructive\" onClick={() => void handleDelete()}><Trash2 />{t('documents.actions.delete')}</Button> : null}\n </>\n )} />\n <PageBody>\n {document.archivedAt ? (\n <div\n role=\"status\"\n className=\"mb-4 flex flex-wrap items-center justify-between gap-2 rounded-md border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\"\n >\n <span>{t('documents.archive.banner')}</span>\n {capabilities.canArchive ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleArchiveToggle()}>\n <ArchiveRestore />{t('documents.actions.unarchive')}\n </Button>\n ) : null}\n </div>\n ) : null}\n <div className=\"flex flex-col gap-4 xl:flex-row\">\n <div className=\"min-w-0 flex-1\">\n <DocumentEditorErrorBoundary\n resetKey={`${document.id}:${editorEpoch}`}\n onRetry={retryEditorIsland}\n fallback={(retry) => (\n <ErrorMessage\n label={t('documents.editor.error.load')}\n action={<Button type=\"button\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )}\n >\n <DocumentEditorIsland\n key={`${document.id}:${editorEpoch}`}\n documentId={document.id}\n title={document.title}\n initialContentHtml={content.contentHtml}\n contentUpdatedAt={content.updatedAt}\n documentUpdatedAt={document.updatedAt}\n readOnly={!capabilities.canEdit}\n onEditorReady={setEditor}\n onContentConflict={handleContentConflict}\n onComment={capabilities.canComment ? (anchor) => setCommentFocusRequest((current) => ({ anchor, requestId: (current?.requestId ?? 0) + 1 })) : undefined}\n onTitleChange={(title, updatedAt) => setState((current) => current.status === 'ready' ? {\n ...current,\n document: { ...current.document, title, updatedAt },\n } : current)}\n />\n </DocumentEditorErrorBoundary>\n </div>\n <aside className=\"space-y-4 xl:sticky xl:top-[calc(var(--topbar-height,0px)+1rem)] xl:max-h-[calc(100dvh-var(--topbar-height,0px)-2rem)] xl:w-80 xl:shrink-0 xl:self-start xl:overflow-y-auto\">\n <DocumentNavigator editor={editor} />\n <RelatedRecordsPanel documentId={document.id} canEdit={capabilities.canEdit} editor={editor} />\n <CommentsRail\n documentId={document.id}\n editor={editor}\n commentFocusRequest={commentFocusRequest}\n canComment={capabilities.canComment}\n canShare={capabilities.canShare}\n />\n {showVersions ? (\n <div\n ref={versionsPanelRef}\n tabIndex={-1}\n className=\"scroll-mt-4 rounded-md focus-visible:outline-none focus-visible:shadow-focus\"\n >\n <VersionHistoryPanel\n documentId={document.id}\n canRestore={capabilities.canEdit}\n contentUpdatedAt={content.updatedAt}\n onRestored={reloadEditor}\n />\n </div>\n ) : null}\n </aside>\n </div>\n </PageBody>\n {capabilities.canShare ? (\n <ShareDialog\n documentId={document.id}\n open={shareOpen}\n onOpenChange={setShareOpen}\n canManage={capabilities.canShare}\n />\n ) : null}\n {ConfirmDialogElement}\n </Page>\n )\n}\n\nexport default DocumentPageClient\n"],
5
- "mappings": ";AAqCgB,SAwSR,UAxSQ,KAyRJ,YAzRI;AAnChB,YAAY,WAAW;AACvB,OAAO,aAAa;AACpB,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,SAAS,gBAAgB,MAAM,MAAM,SAAS,MAAM,cAAc;AAE3E,SAAS,MAAM,UAAU,kBAAkB;AAC3C,SAAS,gBAAgB,cAAc,2BAA2B;AAClE,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,SAAS,gBAAgB,mCAAmC;AACrE,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AACtC,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAC5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AA,UAC7F;AAAA,YAAC;AAAA;AAAA,cACC,YAAY,SAAS;AAAA,cACrB;AAAA,cACA;AAAA,cACA,YAAY,aAAa;AAAA,cACzB,UAAU,aAAa;AAAA;AAAA,UACzB;AAAA,UACC,eACC;AAAA,YAAC;AAAA;AAAA,cACC,KAAK;AAAA,cACL,UAAU;AAAA,cACV,WAAU;AAAA,cAEV;AAAA,gBAAC;AAAA;AAAA,kBACC,YAAY,SAAS;AAAA,kBACrB,YAAY,aAAa;AAAA,kBACzB,kBAAkB,QAAQ;AAAA,kBAC1B,YAAY;AAAA;AAAA,cACd;AAAA;AAAA,UACF,IACE;AAAA,WACN;AAAA,SACF;AAAA,OACF;AAAA,IACC,aAAa,WACZ;AAAA,MAAC;AAAA;AAAA,QACC,YAAY,SAAS;AAAA,QACrB,MAAM;AAAA,QACN,cAAc;AAAA,QACd,WAAW,aAAa;AAAA;AAAA,IAC1B,IACE;AAAA,IACH;AAAA,KACH;AAEJ;AAEA,IAAO,6BAAQ;",
4
+ "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport dynamic from 'next/dynamic'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Archive, ArchiveRestore, Bell, Copy, History, Star, Trash2 } from 'lucide-react'\nimport type { Editor } from '@tiptap/core'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { LoadingMessage, ErrorMessage, RecordNotFoundState } from '@open-mercato/ui/backend/detail'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { apiCall, apiCallOrThrow, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { surfaceRecordConflict } from '@open-mercato/ui/backend/conflicts'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { IconButton } from '@open-mercato/ui/primitives/icon-button'\nimport { LinkButton } from '@open-mercato/ui/primitives/link-button'\nimport { SimpleTooltip } from '@open-mercato/ui/primitives/tooltip'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { ShareDialog } from '../components/ShareDialog'\nimport { normalizeDocumentContent, normalizeDocumentDetail, type DocumentContent, type DocumentDetail } from '../documentUi'\nimport { CommentsRail } from './CommentsRail'\nimport type { CommentAnchor } from './CommentAnchorNavigation'\nimport { ExportMenu } from './ExportMenu'\nimport { RelatedRecordsPanel } from './RelatedRecordsPanel'\nimport { DocumentNavigator } from './DocumentNavigator'\nimport { DocumentEditorErrorBoundary } from './DocumentEditorErrorBoundary'\nimport { VersionHistoryPanel } from './VersionHistoryPanel'\n\nfunction DocumentEditorLoading({ error, retry }: { error?: Error | null; retry?: () => void }) {\n const t = useT()\n if (error) {\n return (\n <ErrorMessage\n label={t('documents.editor.error.load')}\n action={<Button type=\"button\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )\n }\n return <div role=\"status\" aria-live=\"polite\"><LoadingMessage label={t('documents.editor.loading')} /></div>\n}\n\nconst DocumentEditorIsland = dynamic(() => import('./DocumentEditorIsland'), { ssr: false, loading: DocumentEditorLoading })\n\nconst PANEL_REVEAL_OFFSET_PX = 16\n\nexport function revealPanelInScrollContainer(panel: HTMLElement): void {\n const behavior: ScrollBehavior = window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'\n let container = panel.parentElement\n while (container) {\n const overflowY = window.getComputedStyle(container).overflowY\n if ((overflowY === 'auto' || overflowY === 'scroll') && container.scrollHeight > container.clientHeight) {\n const offset = panel.getBoundingClientRect().top - container.getBoundingClientRect().top + container.scrollTop\n container.scrollTo({ top: Math.max(0, offset - PANEL_REVEAL_OFFSET_PX), behavior })\n return\n }\n container = container.parentElement\n }\n panel.scrollIntoView({ block: 'start', behavior })\n}\n\ntype CommentFocusRequest = { anchor: CommentAnchor; requestId: number }\ntype LoadState =\n | { status: 'loading' }\n | { status: 'notFound' }\n | { status: 'error'; message: string }\n | { status: 'ready'; document: DocumentDetail; content: DocumentContent }\n\nexport function DocumentPageClient({ documentId }: { documentId: string }) {\n const t = useT()\n const router = useRouter()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const [state, setState] = React.useState<LoadState>({ status: 'loading' })\n const [shareOpen, setShareOpen] = React.useState(false)\n const [showVersions, setShowVersions] = React.useState(false)\n const versionsPanelRef = React.useRef<HTMLDivElement | null>(null)\n const scrollVersionsIntoView = React.useRef(false)\n const [editorEpoch, setEditorEpoch] = React.useState(0)\n const [editor, setEditor] = React.useState<Editor | null>(null)\n const contentSaveRef = React.useRef<{ documentId: string; save: () => Promise<boolean> } | null>(null)\n const displayedDocumentId = state.status === 'ready' ? state.document.id : null\n const registerContentSave = React.useCallback((save: (() => Promise<boolean>) | null) => {\n contentSaveRef.current = save && displayedDocumentId ? { documentId: displayedDocumentId, save } : null\n }, [displayedDocumentId])\n const saveBeforeSnapshot = React.useCallback(async () => {\n const registered = contentSaveRef.current\n if (!registered || registered.documentId !== documentId) return false\n const saved = await registered.save()\n return saved && contentSaveRef.current === registered\n }, [documentId])\n const [commentFocusRequest, setCommentFocusRequest] = React.useState<CommentFocusRequest | null>(null)\n const requestSequence = React.useRef(0)\n const mutationContextId = `documents-detail:${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 loadDocument = React.useCallback(async () => {\n const requestId = ++requestSequence.current\n setState({ status: 'loading' })\n try {\n const [documentCall, contentCall] = await Promise.all([\n apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}`),\n apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}/content`),\n ])\n if (requestSequence.current !== requestId) return\n if (documentCall.status === 404) return setState({ status: 'notFound' })\n if (!documentCall.ok) return setState({ status: 'error', message: t('documents.editor.error.load') })\n if (!contentCall.ok && contentCall.status !== 404) {\n return setState({ status: 'error', message: t('documents.editor.error.loadContent') })\n }\n const document = normalizeDocumentDetail(documentCall.result)\n if (!document) return setState({ status: 'error', message: t('documents.editor.error.load') })\n setState({\n status: 'ready',\n document,\n content: contentCall.status === 404\n ? { contentHtml: '', updatedAt: null }\n : normalizeDocumentContent(contentCall.result),\n })\n } catch (error) {\n if (requestSequence.current !== requestId) return\n setState({ status: 'error', message: error instanceof Error ? error.message : t('documents.editor.error.load') })\n }\n }, [documentId, t])\n\n React.useEffect(() => {\n void loadDocument()\n return () => { requestSequence.current += 1 }\n }, [loadDocument])\n\n const reloadEditor = React.useCallback(async () => {\n const requestId = ++requestSequence.current\n const contentCall = await apiCall<unknown>(`/api/documents/${encodeURIComponent(documentId)}/content`)\n if (requestSequence.current !== requestId) {\n throw new Error(t('documents.editor.error.loadContent'))\n }\n if (!contentCall.ok && contentCall.status !== 404) {\n throw new Error(t('documents.editor.error.loadContent'))\n }\n const nextContent = contentCall.status === 404\n ? { contentHtml: '', updatedAt: null }\n : normalizeDocumentContent(contentCall.result)\n contentSaveRef.current = null\n setState((current) => current.status === 'ready' ? {\n ...current,\n content: nextContent,\n } : current)\n setEditor(null)\n setEditorEpoch((current) => current + 1)\n }, [documentId, t])\n\n const handleContentConflict = React.useCallback(() => {\n void reloadEditor().catch((error) => {\n flash(error instanceof Error ? error.message : t('documents.editor.error.loadContent'), 'error')\n })\n }, [reloadEditor, t])\n\n const retryEditorIsland = React.useCallback(() => {\n setEditor(null)\n setEditorEpoch((current) => current + 1)\n }, [])\n\n const toggleVersions = React.useCallback(() => {\n setShowVersions((value) => {\n scrollVersionsIntoView.current = !value\n return !value\n })\n }, [])\n\n // The versions panel mounts at the bottom of the side rail, below the fold on\n // a laptop screen, so opening it gave no visible feedback. Bring it to the\n // top of whichever container scrolls the rail (the sticky aside on wide\n // screens, the page otherwise) and hand it focus for keyboard users.\n React.useLayoutEffect(() => {\n if (!showVersions || !scrollVersionsIntoView.current) return\n scrollVersionsIntoView.current = false\n const panel = versionsPanelRef.current\n if (!panel) return\n revealPanelInScrollContainer(panel)\n panel.focus({ preventScroll: true })\n }, [showVersions])\n\n const setDocumentState = React.useCallback((mutate: (document: DocumentDetail) => DocumentDetail) => {\n setState((current) => current.status === 'ready'\n ? { ...current, document: mutate(current.document) }\n : current)\n }, [])\n\n const pendingToggles = React.useRef<Set<'favorite' | 'watch'>>(new Set())\n const runPersonalToggle = React.useCallback(async (\n kind: 'favorite' | 'watch',\n active: boolean,\n ) => {\n if (state.status !== 'ready' || pendingToggles.current.has(kind)) return\n pendingToggles.current.add(kind)\n const flag = kind === 'favorite' ? 'isFavorite' as const : 'isWatching' as const\n setDocumentState((document) => ({ ...document, [flag]: active }))\n try {\n await runMutation({\n operation: () => apiCallOrThrow(\n `/api/documents/${encodeURIComponent(documentId)}/${kind}`,\n { method: active ? 'POST' : 'DELETE' },\n ),\n context: {\n formId: mutationContextId,\n resourceKind: kind === 'favorite' ? 'documents.document_favorite' : 'documents.document_watcher',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { documentId, active },\n })\n } catch (error) {\n setDocumentState((document) => ({ ...document, [flag]: !active }))\n flash(error instanceof Error ? error.message : t('documents.editor.error.load'), 'error')\n } finally {\n pendingToggles.current.delete(kind)\n }\n }, [documentId, mutationContextId, retryLastMutation, runMutation, setDocumentState, state.status, t])\n\n const duplicating = React.useRef(false)\n const [isDuplicating, setIsDuplicating] = React.useState(false)\n const handleDuplicate = React.useCallback(async () => {\n if (state.status !== 'ready' || duplicating.current) return\n duplicating.current = true\n setIsDuplicating(true)\n try {\n const created = await runMutation({\n operation: () => apiCallOrThrow<{ id: string }>(\n `/api/documents/${encodeURIComponent(documentId)}/duplicate`,\n { method: 'POST', body: JSON.stringify({}), headers: { 'content-type': 'application/json' } },\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { action: 'duplicate', sourceDocumentId: documentId },\n })\n flash(t('documents.duplicate.success'), 'success')\n const createdId = created?.result?.id\n if (createdId) router.push(`/backend/documents/${encodeURIComponent(createdId)}`)\n } catch (error) {\n flash(error instanceof Error ? error.message : t('documents.duplicate.error'), 'error')\n } finally {\n duplicating.current = false\n setIsDuplicating(false)\n }\n }, [documentId, mutationContextId, retryLastMutation, router, runMutation, state.status, t])\n\n const handleArchiveToggle = React.useCallback(async () => {\n if (state.status !== 'ready' || !state.document.capabilities.canArchive) return\n const archived = state.document.archivedAt !== null\n const action = archived ? 'unarchive' : 'archive'\n try {\n await runMutation({\n operation: () => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(state.document.updatedAt),\n () => apiCallOrThrow(`/api/documents/${encodeURIComponent(documentId)}/${action}`, { method: 'POST' }),\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { action, documentId },\n })\n flash(t(archived ? 'documents.archive.success.unarchive' : 'documents.archive.success.archive'), 'success')\n await loadDocument()\n } catch (error) {\n if (!surfaceRecordConflict(error, t, { onRefresh: () => { void loadDocument() } })) {\n flash(error instanceof Error ? error.message : t('documents.archive.error'), 'error')\n }\n }\n }, [documentId, loadDocument, mutationContextId, retryLastMutation, runMutation, state, t])\n\n const handleDelete = React.useCallback(async () => {\n if (state.status !== 'ready' || !state.document.capabilities.canDelete) return\n const confirmed = await confirm({\n title: t('documents.list.confirmDelete', { title: state.document.title }),\n variant: 'destructive',\n })\n if (!confirmed) return\n try {\n await runMutation({\n operation: () => withScopedApiRequestHeaders(\n buildOptimisticLockHeader(state.document.updatedAt),\n () => apiCallOrThrow(`/api/documents/${encodeURIComponent(documentId)}`, { method: 'DELETE' }),\n ),\n context: {\n formId: mutationContextId,\n resourceKind: 'documents.document',\n resourceId: documentId,\n retryLastMutation,\n },\n mutationPayload: { id: documentId },\n })\n flash(t('documents.list.success.delete'), 'success')\n router.push('/backend/documents')\n } catch (error) {\n if (!surfaceRecordConflict(error, t, { onRefresh: () => { void loadDocument() } })) {\n flash(error instanceof Error ? error.message : t('documents.list.error.delete'), 'error')\n }\n }\n }, [confirm, documentId, loadDocument, mutationContextId, retryLastMutation, router, runMutation, state, t])\n\n if (state.status !== 'ready') {\n if (state.status === 'notFound') {\n return (\n <Page><PageBody>\n <RecordNotFoundState\n label={t('documents.editor.notFound')}\n backHref=\"/backend/documents\"\n backLabel={t('documents.actions.backToList')}\n />\n </PageBody></Page>\n )\n }\n const label = state.status === 'loading' ? t('documents.editor.loading') : state.message\n return (\n <Page><PageBody>\n {state.status === 'loading' ? <LoadingMessage label={label} /> : (\n <ErrorMessage label={label} action={(\n <div className=\"flex flex-wrap gap-2\">\n <Button type=\"button\" onClick={() => void loadDocument()}>{t('documents.actions.retry')}</Button>\n <LinkButton asChild variant=\"gray\"><Link href=\"/backend/documents\">{t('documents.actions.backToList')}</Link></LinkButton>\n </div>\n )} />\n )}\n </PageBody></Page>\n )\n }\n\n const { document, content } = state\n const capabilities = document.capabilities\n return (\n <Page>\n <PageHeader title={t('documents.nav.document')} actions={(\n <>\n <LinkButton asChild variant=\"gray\"><Link href=\"/backend/documents\">{t('documents.actions.backToList')}</Link></LinkButton>\n <SimpleTooltip content={t(document.isFavorite ? 'documents.actions.unfavorite' : 'documents.actions.favorite')} size=\"sm\">\n <IconButton\n type=\"button\"\n variant=\"outline\"\n size=\"lg\"\n onClick={() => void runPersonalToggle('favorite', !document.isFavorite)}\n aria-pressed={document.isFavorite}\n aria-label={t(document.isFavorite ? 'documents.actions.unfavorite' : 'documents.actions.favorite')}\n >\n <Star />\n </IconButton>\n </SimpleTooltip>\n <SimpleTooltip content={t(document.isWatching ? 'documents.actions.unwatch' : 'documents.actions.watch')} size=\"sm\">\n <IconButton\n type=\"button\"\n variant=\"outline\"\n size=\"lg\"\n onClick={() => void runPersonalToggle('watch', !document.isWatching)}\n aria-pressed={document.isWatching}\n aria-label={t(document.isWatching ? 'documents.actions.unwatch' : 'documents.actions.watch')}\n >\n <Bell />\n </IconButton>\n </SimpleTooltip>\n <Button type=\"button\" variant={showVersions ? 'secondary' : 'outline'} onClick={toggleVersions} aria-pressed={showVersions}>\n <History />{t('documents.actions.versions')}\n </Button>\n <ExportMenu documentId={document.id} editor={editor} />\n {capabilities.canDuplicate ? (\n <Button type=\"button\" variant=\"outline\" disabled={isDuplicating} onClick={() => void handleDuplicate()}>\n <Copy />{t('documents.actions.duplicate')}\n </Button>\n ) : null}\n {capabilities.canArchive ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleArchiveToggle()}>\n {document.archivedAt ? <ArchiveRestore /> : <Archive />}\n {t(document.archivedAt ? 'documents.actions.unarchive' : 'documents.actions.archive')}\n </Button>\n ) : null}\n {capabilities.canShare ? <Button type=\"button\" variant=\"outline\" onClick={() => setShareOpen(true)}>{t('documents.actions.share')}</Button> : null}\n {capabilities.canDelete ? <Button type=\"button\" variant=\"destructive\" onClick={() => void handleDelete()}><Trash2 />{t('documents.actions.delete')}</Button> : null}\n </>\n )} />\n <PageBody>\n {document.archivedAt ? (\n <div\n role=\"status\"\n className=\"mb-4 flex flex-wrap items-center justify-between gap-2 rounded-md border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\"\n >\n <span>{t('documents.archive.banner')}</span>\n {capabilities.canArchive ? (\n <Button type=\"button\" variant=\"outline\" onClick={() => void handleArchiveToggle()}>\n <ArchiveRestore />{t('documents.actions.unarchive')}\n </Button>\n ) : null}\n </div>\n ) : null}\n <div className=\"flex flex-col gap-4 xl:flex-row\">\n <div className=\"min-w-0 flex-1\">\n <DocumentEditorErrorBoundary\n resetKey={`${document.id}:${editorEpoch}`}\n onRetry={retryEditorIsland}\n fallback={(retry) => (\n <ErrorMessage\n label={t('documents.editor.error.load')}\n action={<Button type=\"button\" variant=\"outline\" onClick={retry}>{t('documents.actions.retry')}</Button>}\n />\n )}\n >\n <DocumentEditorIsland\n key={`${document.id}:${editorEpoch}`}\n documentId={document.id}\n title={document.title}\n initialContentHtml={content.contentHtml}\n contentUpdatedAt={content.updatedAt}\n documentUpdatedAt={document.updatedAt}\n readOnly={!capabilities.canEdit}\n onEditorReady={setEditor}\n onSaveReady={registerContentSave}\n onContentConflict={handleContentConflict}\n onComment={capabilities.canComment ? (anchor) => setCommentFocusRequest((current) => ({ anchor, requestId: (current?.requestId ?? 0) + 1 })) : undefined}\n onTitleChange={(title, updatedAt) => setState((current) => current.status === 'ready' ? {\n ...current,\n document: { ...current.document, title, updatedAt },\n } : current)}\n />\n </DocumentEditorErrorBoundary>\n </div>\n <aside className=\"space-y-4 xl:sticky xl:top-[calc(var(--topbar-height,0px)+1rem)] xl:max-h-[calc(100dvh-var(--topbar-height,0px)-2rem)] xl:w-80 xl:shrink-0 xl:self-start xl:overflow-y-auto\">\n <DocumentNavigator editor={editor} />\n <RelatedRecordsPanel documentId={document.id} canEdit={capabilities.canEdit} editor={editor} />\n <CommentsRail\n documentId={document.id}\n editor={editor}\n commentFocusRequest={commentFocusRequest}\n canComment={capabilities.canComment}\n canShare={capabilities.canShare}\n />\n {showVersions ? (\n <div\n ref={versionsPanelRef}\n tabIndex={-1}\n className=\"scroll-mt-4 rounded-md focus-visible:outline-none focus-visible:shadow-focus\"\n >\n <VersionHistoryPanel\n documentId={document.id}\n canRestore={capabilities.canEdit}\n contentUpdatedAt={content.updatedAt}\n onRestored={reloadEditor}\n onBeforeSnapshot={saveBeforeSnapshot}\n />\n </div>\n ) : null}\n </aside>\n </div>\n </PageBody>\n {capabilities.canShare ? (\n <ShareDialog\n documentId={document.id}\n open={shareOpen}\n onOpenChange={setShareOpen}\n canManage={capabilities.canShare}\n />\n ) : null}\n {ConfirmDialogElement}\n </Page>\n )\n}\n\nexport default DocumentPageClient\n"],
5
+ "mappings": ";AAqCgB,SAoTR,UApTQ,KAqSJ,YArSI;AAnChB,YAAY,WAAW;AACvB,OAAO,aAAa;AACpB,OAAO,UAA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AAkB,QAAQ;AAAA,kBAC1B,YAAY;AAAA,kBACZ,kBAAkB;AAAA;AAAA,cACpB;AAAA;AAAA,UACF,IACE;AAAA,WACN;AAAA,SACF;AAAA,OACF;AAAA,IACC,aAAa,WACZ;AAAA,MAAC;AAAA;AAAA,QACC,YAAY,SAAS;AAAA,QACrB,MAAM;AAAA,QACN,cAAc;AAAA,QACd,WAAW,aAAa;AAAA;AAAA,IAC1B,IACE;AAAA,IACH;AAAA,KACH;AAEJ;AAEA,IAAO,6BAAQ;",
6
6
  "names": ["document"]
7
7
  }
@@ -48,7 +48,8 @@ function VersionHistoryPanel({
48
48
  documentId,
49
49
  tier,
50
50
  canRestore,
51
- onRestored
51
+ onRestored,
52
+ onBeforeSnapshot
52
53
  }) {
53
54
  const t = useT();
54
55
  const mayRestore = resolveVersionRestoreCapability(canRestore, tier);
@@ -59,6 +60,7 @@ function VersionHistoryPanel({
59
60
  const [restoringVersionId, setRestoringVersionId] = React.useState(null);
60
61
  const [previewVersionId, setPreviewVersionId] = React.useState(null);
61
62
  const restoreInFlight = React.useRef(false);
63
+ const snapshotInFlight = React.useRef(false);
62
64
  const reloadSequence = React.useRef(0);
63
65
  const activeReload = React.useRef(null);
64
66
  const activeDocumentId = React.useRef(null);
@@ -103,16 +105,25 @@ function VersionHistoryPanel({
103
105
  };
104
106
  }, [reload]);
105
107
  const handleSnapshot = React.useCallback(async () => {
106
- if (!mayRestore) return;
108
+ if (!mayRestore || snapshotInFlight.current) return;
109
+ snapshotInFlight.current = true;
107
110
  setIsCreating(true);
108
111
  const nextLabel = label.trim() || null;
109
112
  try {
110
113
  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
- ),
114
+ operation: async () => {
115
+ if (onBeforeSnapshot && !await onBeforeSnapshot()) {
116
+ throw new Error(t("documents.versions.error.save"));
117
+ }
118
+ if (currentDocumentIdRef.current !== documentId) {
119
+ throw new Error(t("documents.versions.error.save"));
120
+ }
121
+ return apiCallOrThrow(
122
+ `/api/documents/${encodeURIComponent(documentId)}/versions`,
123
+ { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ label: nextLabel }) },
124
+ { errorMessage: t("documents.versions.error.save") }
125
+ );
126
+ },
116
127
  context: { formId: mutationContextId, resourceKind: "documents.document_version", resourceId: documentId, retryLastMutation },
117
128
  mutationPayload: { label: nextLabel }
118
129
  });
@@ -125,9 +136,10 @@ function VersionHistoryPanel({
125
136
  if (currentDocumentIdRef.current !== documentId) return;
126
137
  flash(error instanceof Error ? error.message : t("documents.versions.error.save"), "error");
127
138
  } finally {
139
+ snapshotInFlight.current = false;
128
140
  setIsCreating(false);
129
141
  }
130
- }, [documentId, label, mayRestore, mutationContextId, reload, retryLastMutation, runMutation, t]);
142
+ }, [documentId, label, mayRestore, mutationContextId, onBeforeSnapshot, reload, retryLastMutation, runMutation, t]);
131
143
  const handleRestore = React.useCallback(async (version) => {
132
144
  if (!mayRestore || restoreInFlight.current) return;
133
145
  restoreInFlight.current = true;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,wBAAwB;AACjC,SAAS,uCAA0D;AACnE,SAAS,6CAA6C;AAEtD,SAAS,wBAA8C;AAEvD,SAAS,4BAA4B,EAAE,OAAO,MAAM,GAAiD;AACnG,QAAM,IAAI,KAAK;AAIf,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,IAAI;AAC3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,WAAU,SAAS,MAAM,KAAK,OAAO,GAAI,YAAE,yBAAyB,GAAE;AAAA;AAAA,MACxH,IACE;AAAA,MACH,MAAM,WAAW,WAAW,SAAS,WAAW,IAAI,oBAAC,cAAW,MAAK,MAAK,SAAQ,UAAS,OAAO,EAAE,0BAA0B,GAAG,MAAM,oBAAC,WAAQ,WAAU,UAAS,GAAI,IAAK;AAAA,MAC5K,SAAS,IAAI,CAAC,YACb,qBAAC,aAAyB,WAAU,+DAClC;AAAA,4BAAC,OAAE,WAAU,uBAAuB,kBAAQ,SAAS,EAAE,0CAA0C,GAAE;AAAA,QACnG,qBAAC,OAAE,WAAU,yDAAwD;AAAA,8BAAC,SAAM,WAAU,UAAS,eAAY,QAAO;AAAA,UAAG,IAAI,KAAK,QAAQ,SAAS,EAAE,eAAe;AAAA,WAAE;AAAA,QAClK,oBAAC,OAAE,WAAU,iCAAiC,kBAAQ,gBAAgB,EAAE,yBAAyB,GAAE;AAAA,QACnG,qBAAC,UAAO,MAAK,UAAS,MAAK,MAAK,SAAQ,WAAU,SAAS,MAAM,oBAAoB,QAAQ,EAAE,GAAG;AAAA,8BAAC,OAAI;AAAA,UAAG,EAAE,oCAAoC;AAAA,WAAE;AAAA,WAJtI,QAAQ,EAKtB,CACD;AAAA,OACH;AAAA,IACC,mBAAmB,oBAAC,wBAAqB,YAAwB,WAAW,kBAAkB,YAAY,YAAY,aAAa,uBAAuB,MAAM,cAAc,CAAC,SAAS;AAAE,UAAI,CAAC,KAAM,qBAAoB,IAAI;AAAA,IAAE,GAAG,WAAW,eAAe,IAAK;AAAA,KACpQ;AAEJ;AAEA,IAAO,8BAAQ;",
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 onBeforeSnapshot?: () => Promise<boolean>\n}\n\nexport { resolveVersionRestoreCapability } from './componentCapabilities'\nexport { normalizeVersion } from './versionHistoryModel'\n\nexport function VersionHistoryPanel({\n documentId,\n tier,\n canRestore,\n onRestored,\n onBeforeSnapshot,\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 snapshotInFlight = 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 || snapshotInFlight.current) return\n snapshotInFlight.current = true\n setIsCreating(true)\n const nextLabel = label.trim() || null\n try {\n await runMutation({\n operation: async () => {\n if (onBeforeSnapshot && !(await onBeforeSnapshot())) {\n throw new Error(t('documents.versions.error.save'))\n }\n if (currentDocumentIdRef.current !== documentId) {\n throw new Error(t('documents.versions.error.save'))\n }\n return 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 },\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 {\n snapshotInFlight.current = false\n setIsCreating(false)\n }\n }, [documentId, label, mayRestore, mutationContextId, onBeforeSnapshot, 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,sB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O;AAAA,UAAG,IAAI,KAAK,QAAQ,SAAS,EAAE,eAAe;AAAA,WAAE;AAAA,QAClK,oBAAC,OAAE,WAAU,iCAAiC,kBAAQ,gBAAgB,EAAE,yBAAyB,GAAE;AAAA,QACnG,qBAAC,UAAO,MAAK,UAAS,MAAK,MAAK,SAAQ,WAAU,SAAS,MAAM,oBAAoB,QAAQ,EAAE,GAAG;AAAA,8BAAC,OAAI;AAAA,UAAG,EAAE,oCAAoC;AAAA,WAAE;AAAA,WAJtI,QAAQ,EAKtB,CACD;AAAA,OACH;AAAA,IACC,mBAAmB,oBAAC,wBAAqB,YAAwB,WAAW,kBAAkB,YAAY,YAAY,aAAa,uBAAuB,MAAM,cAAc,CAAC,SAAS;AAAE,UAAI,CAAC,KAAM,qBAAoB,IAAI;AAAA,IAAE,GAAG,WAAW,eAAe,IAAK;AAAA,KACpQ;AAEJ;AAEA,IAAO,8BAAQ;",
6
6
  "names": ["resolveVersionRestoreCapability", "normalizeVersion"]
7
7
  }
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
+ import { useContentSecurityPolicyNonce } from "@open-mercato/ui/theme/ContentSecurityPolicyProvider";
4
5
  import { EditorContent, useEditor } from "@tiptap/react";
5
6
  import { RotateCcw } from "lucide-react";
6
7
  import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
@@ -41,7 +42,9 @@ function normalizeVersionPreview(payload, fallbackCreatorLabel) {
41
42
  };
42
43
  }
43
44
  function ReadOnlyVersion({ contentHtml, fallbackLabel }) {
45
+ const nonce = useContentSecurityPolicyNonce();
44
46
  const editor = useEditor({
47
+ injectNonce: nonce,
45
48
  extensions: getDocumentEditorExtensions({ entityRefFallbackLabel: fallbackLabel }),
46
49
  content: contentHtml,
47
50
  editable: false,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,YAAY,WAAW;AACvB,SAAS,eAAe,iBAAiB;AACzC,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,mCAAmC;AAC5C,SAAS,sCAAsC;AAC/C,SAAS,oCAAoC;AAC7C,SAAS,YAAY,kBAAkB;AACvC,SAAS,qCAAqC;AAmBvC,SAAS,wBACd,SACA,sBACuB;AACvB,QAAM,OAAO,WAAW,OAAO;AAC/B,QAAM,SAAS,WAAW,MAAM,IAAI,KAAK,WAAW,MAAM,IAAI,KAAK;AACnE,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,KAAK,WAAW,QAAQ,IAAI;AAClC,QAAM,eAAe;AAAA,IACnB,WAAW,QAAQ,gBAAgB,eAAe;AAAA,IAClD;AAAA,EACF;AACA,QAAM,YAAY,WAAW,QAAQ,aAAa,YAAY;AAC9D,MAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAW,QAAO;AAC/C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,6BAA6B,WAAW,QAAQ,OAAO,CAAC;AAAA,IAC/D,aAAa,WAAW,QAAQ,eAAe,cAAc,KAAK;AAAA,EACpE;AACF;AAEA,SAAS,gBAAg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S,MAAM,aAAa,KAAK,GAAI,YAAE,yBAAyB,GAAE;AAAA,MACzG,cAAc,UACb,qBAAC,UAAO,MAAK,UAAS,SAAS,gBAAgB,UAAU,aACvD;AAAA,4BAAC,aAAU;AAAA,QAAG,EAAE,oCAAoC;AAAA,SACtD,IACE;AAAA,OACN,GAEJ;AAAA,KACF,GACF;AAEJ;",
4
+ "sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { useContentSecurityPolicyNonce } from '@open-mercato/ui/theme/ContentSecurityPolicyProvider'\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 nonce = useContentSecurityPolicyNonce()\n const editor = useEditor({\n injectNonce: nonce,\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": ";AA6ES,SAoGG,UApGH,KA4ED,YA5EC;AA3ET,YAAY,WAAW;AACvB,SAAS,qCAAqC;AAC9C,SAAS,eAAe,iBAAiB;AACzC,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,mCAAmC;AAC5C,SAAS,sCAAsC;AAC/C,SAAS,oCAAoC;AAC7C,SAAS,YAAY,kBAAkB;AACvC,SAAS,qCAAqC;AAmBvC,SAAS,wBACd,SACA,sBACuB;AACvB,QAAM,OAAO,WAAW,OAAO;AAC/B,QAAM,SAAS,WAAW,MAAM,IAAI,KAAK,WAAW,MAAM,IAAI,KAAK;AACnE,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,KAAK,WAAW,QAAQ,IAAI;AAClC,QAAM,eAAe;AAAA,IACn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AAE,0CAA0C,GAAG,IAAK;AAAA,IAC7K,oBAAC,gBACE,8BACC,iCACE;AAAA,0BAAC,UAAO,KAAK,kBAAkB,MAAK,UAAS,SAAQ,WAAU,SAAS,MAAM,qBAAqB,KAAK,GAAG,UAAU,aAClH,YAAE,0BAA0B,GAC/B;AAAA,MACA,qBAAC,UAAO,MAAK,UAAS,SAAS,gBAAgB,UAAU,aACvD;AAAA,4BAAC,aAAU;AAAA,QAAG,EAAE,oCAAoC;AAAA,SACtD;AAAA,OACF,IAEA,iCACE;AAAA,0BAAC,UAAO,MAAK,UAAS,SAAQ,WAAU,SAAS,MAAM,aAAa,KAAK,GAAI,YAAE,yBAAyB,GAAE;AAAA,MACzG,cAAc,UACb,qBAAC,UAAO,MAAK,UAAS,SAAS,gBAAgB,UAAU,aACvD;AAAA,4BAAC,aAAU;AAAA,QAAG,EAAE,oCAAoC;AAAA,SACtD,IACE;AAAA,OACN,GAEJ;AAAA,KACF,GACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/documents/backend/documents/%5Bid%5D/editorTypes.ts"],
4
- "sourcesContent": ["import type { Editor } from '@tiptap/core'\nimport type { HocuspocusProvider } from '@hocuspocus/provider'\nimport type * as Y from 'yjs'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport type { CommentAnchor } from './CommentAnchorNavigation'\n\nexport type CollabTokenUser = { id: string; name: string; color: string }\nexport type CollabResources = { ydoc: Y.Doc; provider: HocuspocusProvider; user: CollabTokenUser }\nexport type PresenceUser = { key: string; name: string; color: string }\nexport type ConnectionStatus = 'connecting' | 'connected' | 'reconnecting' | 'offline'\nexport type EditorSelectionRange = { from: number; to: number }\nexport type EditorWordCount = { words: number; characters: number }\nexport type EditorMode = 'edit' | 'preview'\n\nexport type DocumentEditorIslandProps = {\n documentId: string\n title: string\n initialContentHtml: string\n contentUpdatedAt?: string | null\n documentUpdatedAt?: string | null\n readOnly: boolean\n onEditorReady?: (editor: Editor | null) => void\n onComment?: (anchor: CommentAnchor) => void\n onContentConflict?: () => void\n onTitleChange?: (title: string, updatedAt: string | null) => void\n}\n\nexport type CollabState =\n | { mode: 'connecting' }\n | { mode: 'fallback'; readOnly: boolean }\n | { mode: 'collab'; resources: CollabResources; connectionStatus: ConnectionStatus; presenceUsers: PresenceUser[]; serverReadOnly: boolean }\n\nexport function resolveEditorMode(readOnly: boolean, serverReadOnly: boolean, requested: EditorMode): EditorMode {\n return readOnly || serverReadOnly ? 'preview' : requested\n}\n\nexport function canCreateSelectionComment(input: {\n permissionReadOnly: boolean\n mode: EditorMode\n transport: 'collab' | 'fallback'\n hasCommentHandler: boolean\n}): boolean {\n if (!input.hasCommentHandler || input.transport !== 'collab') return false\n const effectiveReadOnly = input.permissionReadOnly || input.mode === 'preview'\n return !effectiveReadOnly || input.permissionReadOnly\n}\n\nexport function readRecord(value: unknown): Record<string, unknown> | null {\n return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : null\n}\n\nexport function readString(record: Record<string, unknown>, ...keys: string[]): string | null {\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'string' && value.trim()) return value\n }\n return null\n}\n\nexport function readNumber(record: Record<string, unknown>, ...keys: string[]): number | null {\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'number' && Number.isFinite(value)) return value\n }\n return null\n}\n\nexport const DOCUMENT_EDITOR_CONTENT_CLASS = cn(\n 'max-w-none text-foreground',\n '[&_.ProseMirror]:min-h-96 [&_.ProseMirror]:focus-visible:outline-none',\n '[&_.ProseMirror>*:first-child]:mt-0 [&_.ProseMirror>*:last-child]:mb-0',\n '[&_h1]:mb-4 [&_h1]:mt-8 [&_h1]:text-3xl [&_h1]:font-bold [&_h1]:leading-tight',\n '[&_h2]:mb-3 [&_h2]:mt-7 [&_h2]:text-2xl [&_h2]:font-semibold [&_h2]:leading-tight',\n '[&_h3]:mb-2 [&_h3]:mt-6 [&_h3]:text-xl [&_h3]:font-semibold',\n '[&_p]:my-4 [&_p]:leading-7 [&_ul]:my-4 [&_ul]:list-disc [&_ul]:pl-6',\n '[&_ol]:my-4 [&_ol]:list-decimal [&_ol]:pl-6 [&_li]:my-1',\n '[&_blockquote]:my-6 [&_blockquote]:border-l-4 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:italic',\n '[&_pre]:my-6 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-muted [&_pre]:p-4 [&_pre]:font-mono [&_pre]:text-sm',\n '[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-4',\n '[&_img]:my-6 [&_img]:h-auto [&_img]:max-w-full [&_img]:rounded-md',\n '[&_table]:my-6 [&_table]:w-full [&_table]:border-collapse',\n '[&_td]:border [&_td]:border-border [&_td]:px-3 [&_td]:py-2',\n '[&_th]:border [&_th]:border-border [&_th]:bg-muted [&_th]:px-3 [&_th]:py-2 [&_th]:text-left',\n)\n"],
5
- "mappings": "AAGA,SAAS,UAAU;AA6BZ,SAAS,kBAAkB,UAAmB,gBAAyB,WAAmC;AAC/G,SAAO,YAAY,iBAAiB,YAAY;AAClD;AAEO,SAAS,0BAA0B,OAK9B;AACV,MAAI,CAAC,MAAM,qBAAqB,MAAM,cAAc,SAAU,QAAO;AACrE,QAAM,oBAAoB,MAAM,sBAAsB,MAAM,SAAS;AACrE,SAAO,CAAC,qBAAqB,MAAM;AACrC;AAEO,SAAS,WAAW,OAAgD;AACzE,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAI,QAAmC;AAC1G;AAEO,SAAS,WAAW,WAAoC,MAA+B;AAC5F,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAG,QAAO;AAAA,EACxD;AACA,SAAO;AACT;AAEO,SAAS,WAAW,WAAoC,MAA+B;AAC5F,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,EAAG,QAAO;AAAA,EAClE;AACA,SAAO;AACT;AAEO,MAAM,gCAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
4
+ "sourcesContent": ["import type { Editor } from '@tiptap/core'\nimport type { HocuspocusProvider } from '@hocuspocus/provider'\nimport type * as Y from 'yjs'\nimport { cn } from '@open-mercato/shared/lib/utils'\nimport type { CommentAnchor } from './CommentAnchorNavigation'\n\nexport type CollabTokenUser = { id: string; name: string; color: string }\nexport type CollabResources = { ydoc: Y.Doc; provider: HocuspocusProvider; user: CollabTokenUser }\nexport type PresenceUser = { key: string; name: string; color: string }\nexport type ConnectionStatus = 'connecting' | 'connected' | 'reconnecting' | 'offline'\nexport type EditorSelectionRange = { from: number; to: number }\nexport type EditorWordCount = { words: number; characters: number }\nexport type EditorMode = 'edit' | 'preview'\n\nexport type DocumentEditorIslandProps = {\n documentId: string\n title: string\n initialContentHtml: string\n contentUpdatedAt?: string | null\n documentUpdatedAt?: string | null\n readOnly: boolean\n onEditorReady?: (editor: Editor | null) => void\n onSaveReady?: (save: (() => Promise<boolean>) | null) => void\n onComment?: (anchor: CommentAnchor) => void\n onContentConflict?: () => void\n onTitleChange?: (title: string, updatedAt: string | null) => void\n}\n\nexport type CollabState =\n | { mode: 'connecting' }\n | { mode: 'fallback'; readOnly: boolean }\n | { mode: 'collab'; resources: CollabResources; connectionStatus: ConnectionStatus; presenceUsers: PresenceUser[]; serverReadOnly: boolean }\n\nexport function resolveEditorMode(readOnly: boolean, serverReadOnly: boolean, requested: EditorMode): EditorMode {\n return readOnly || serverReadOnly ? 'preview' : requested\n}\n\nexport function canCreateSelectionComment(input: {\n permissionReadOnly: boolean\n mode: EditorMode\n transport: 'collab' | 'fallback'\n hasCommentHandler: boolean\n}): boolean {\n if (!input.hasCommentHandler || input.transport !== 'collab') return false\n const effectiveReadOnly = input.permissionReadOnly || input.mode === 'preview'\n return !effectiveReadOnly || input.permissionReadOnly\n}\n\nexport function readRecord(value: unknown): Record<string, unknown> | null {\n return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : null\n}\n\nexport function readString(record: Record<string, unknown>, ...keys: string[]): string | null {\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'string' && value.trim()) return value\n }\n return null\n}\n\nexport function readNumber(record: Record<string, unknown>, ...keys: string[]): number | null {\n for (const key of keys) {\n const value = record[key]\n if (typeof value === 'number' && Number.isFinite(value)) return value\n }\n return null\n}\n\nexport const DOCUMENT_EDITOR_CONTENT_CLASS = cn(\n 'max-w-none text-foreground',\n '[&_.ProseMirror]:min-h-96 [&_.ProseMirror]:focus-visible:outline-none',\n '[&_.ProseMirror>*:first-child]:mt-0 [&_.ProseMirror>*:last-child]:mb-0',\n '[&_h1]:mb-4 [&_h1]:mt-8 [&_h1]:text-3xl [&_h1]:font-bold [&_h1]:leading-tight',\n '[&_h2]:mb-3 [&_h2]:mt-7 [&_h2]:text-2xl [&_h2]:font-semibold [&_h2]:leading-tight',\n '[&_h3]:mb-2 [&_h3]:mt-6 [&_h3]:text-xl [&_h3]:font-semibold',\n '[&_p]:my-4 [&_p]:leading-7 [&_ul]:my-4 [&_ul]:list-disc [&_ul]:pl-6',\n '[&_ol]:my-4 [&_ol]:list-decimal [&_ol]:pl-6 [&_li]:my-1',\n '[&_blockquote]:my-6 [&_blockquote]:border-l-4 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:italic',\n '[&_pre]:my-6 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-muted [&_pre]:p-4 [&_pre]:font-mono [&_pre]:text-sm',\n '[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-4',\n '[&_img]:my-6 [&_img]:h-auto [&_img]:max-w-full [&_img]:rounded-md',\n '[&_table]:my-6 [&_table]:w-full [&_table]:border-collapse',\n '[&_td]:border [&_td]:border-border [&_td]:px-3 [&_td]:py-2',\n '[&_th]:border [&_th]:border-border [&_th]:bg-muted [&_th]:px-3 [&_th]:py-2 [&_th]:text-left',\n)\n"],
5
+ "mappings": "AAGA,SAAS,UAAU;AA8BZ,SAAS,kBAAkB,UAAmB,gBAAyB,WAAmC;AAC/G,SAAO,YAAY,iBAAiB,YAAY;AAClD;AAEO,SAAS,0BAA0B,OAK9B;AACV,MAAI,CAAC,MAAM,qBAAqB,MAAM,cAAc,SAAU,QAAO;AACrE,QAAM,oBAAoB,MAAM,sBAAsB,MAAM,SAAS;AACrE,SAAO,CAAC,qBAAqB,MAAM;AACrC;AAEO,SAAS,WAAW,OAAgD;AACzE,SAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAI,QAAmC;AAC1G;AAEO,SAAS,WAAW,WAAoC,MAA+B;AAC5F,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAG,QAAO;AAAA,EACxD;AACA,SAAO;AACT;AAEO,SAAS,WAAW,WAAoC,MAA+B;AAC5F,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,EAAG,QAAO;AAAA,EAClE;AACA,SAAO;AACT;AAEO,MAAM,gCAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,46 @@
1
+ import { collabContentSaveResponseSchema } from "../../../data/validators.js";
2
+ import { COLLAB_CONTENT_SAVE_TIMEOUT_MS } from "../../../lib/collabPersistence.js";
3
+ function saveCollaborativeContent(resources, signal) {
4
+ const { provider } = resources;
5
+ if (signal.aborted || !provider.synced || provider.configuration.websocketProvider.status !== "connected") {
6
+ return Promise.resolve(false);
7
+ }
8
+ const requestId = crypto.randomUUID();
9
+ return new Promise((resolve) => {
10
+ const finish = (saved) => {
11
+ clearTimeout(timer);
12
+ provider.off("stateless", onStateless);
13
+ provider.off("close", onFailure);
14
+ provider.off("disconnect", onFailure);
15
+ provider.off("destroy", onFailure);
16
+ signal.removeEventListener("abort", onFailure);
17
+ resolve(saved);
18
+ };
19
+ const onFailure = () => finish(false);
20
+ const onStateless = ({ payload }) => {
21
+ let value;
22
+ try {
23
+ value = JSON.parse(payload);
24
+ } catch {
25
+ return;
26
+ }
27
+ const response = collabContentSaveResponseSchema.safeParse(value);
28
+ if (response.success && response.data.requestId === requestId) finish(response.data.saved);
29
+ };
30
+ const timer = setTimeout(onFailure, COLLAB_CONTENT_SAVE_TIMEOUT_MS);
31
+ provider.on("stateless", onStateless);
32
+ provider.on("close", onFailure);
33
+ provider.on("disconnect", onFailure);
34
+ provider.on("destroy", onFailure);
35
+ signal.addEventListener("abort", onFailure, { once: true });
36
+ try {
37
+ provider.sendStateless(JSON.stringify({ type: "documents.content.save", requestId }));
38
+ } catch {
39
+ finish(false);
40
+ }
41
+ });
42
+ }
43
+ export {
44
+ saveCollaborativeContent
45
+ };
46
+ //# sourceMappingURL=saveCollaborativeContent.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/modules/documents/backend/documents/%5Bid%5D/saveCollaborativeContent.ts"],
4
+ "sourcesContent": ["import type { CollabResources } from './editorTypes'\nimport { collabContentSaveResponseSchema } from '../../../data/validators'\nimport { COLLAB_CONTENT_SAVE_TIMEOUT_MS } from '../../../lib/collabPersistence'\n\nexport function saveCollaborativeContent(\n resources: CollabResources,\n signal: AbortSignal,\n): Promise<boolean> {\n const { provider } = resources\n if (signal.aborted || !provider.synced || provider.configuration.websocketProvider.status !== 'connected') {\n return Promise.resolve(false)\n }\n const requestId = crypto.randomUUID()\n return new Promise<boolean>((resolve) => {\n const finish = (saved: boolean) => {\n clearTimeout(timer)\n provider.off('stateless', onStateless)\n provider.off('close', onFailure)\n provider.off('disconnect', onFailure)\n provider.off('destroy', onFailure)\n signal.removeEventListener('abort', onFailure)\n resolve(saved)\n }\n const onFailure = () => finish(false)\n const onStateless = ({ payload }: { payload: string }) => {\n let value: unknown\n try { value = JSON.parse(payload) } catch { return }\n const response = collabContentSaveResponseSchema.safeParse(value)\n if (response.success && response.data.requestId === requestId) finish(response.data.saved)\n }\n const timer = setTimeout(onFailure, COLLAB_CONTENT_SAVE_TIMEOUT_MS)\n provider.on('stateless', onStateless)\n provider.on('close', onFailure)\n provider.on('disconnect', onFailure)\n provider.on('destroy', onFailure)\n signal.addEventListener('abort', onFailure, { once: true })\n try {\n provider.sendStateless(JSON.stringify({ type: 'documents.content.save', requestId }))\n } catch {\n finish(false)\n }\n })\n}\n"],
5
+ "mappings": "AACA,SAAS,uCAAuC;AAChD,SAAS,sCAAsC;AAExC,SAAS,yBACd,WACA,QACkB;AAClB,QAAM,EAAE,SAAS,IAAI;AACrB,MAAI,OAAO,WAAW,CAAC,SAAS,UAAU,SAAS,cAAc,kBAAkB,WAAW,aAAa;AACzG,WAAO,QAAQ,QAAQ,KAAK;AAAA,EAC9B;AACA,QAAM,YAAY,OAAO,WAAW;AACpC,SAAO,IAAI,QAAiB,CAAC,YAAY;AACvC,UAAM,SAAS,CAAC,UAAmB;AACjC,mBAAa,KAAK;AAClB,eAAS,IAAI,aAAa,WAAW;AACrC,eAAS,IAAI,SAAS,SAAS;AAC/B,eAAS,IAAI,cAAc,SAAS;AACpC,eAAS,IAAI,WAAW,SAAS;AACjC,aAAO,oBAAoB,SAAS,SAAS;AAC7C,cAAQ,KAAK;AAAA,IACf;AACA,UAAM,YAAY,MAAM,OAAO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