@jaetask/toolkit 0.1.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/LICENSE +2 -0
- package/README.md +48 -76
- package/dist/app/review/InlineMarkdown.d.ts +20 -0
- package/dist/app/review/InlineMarkdown.d.ts.map +1 -0
- package/dist/app/review/InlineMarkdown.js +68 -0
- package/dist/app/review/InlineMarkdown.js.map +1 -0
- package/dist/app/review/index.d.ts +2 -0
- package/dist/app/review/index.d.ts.map +1 -0
- package/dist/app/review/index.js +3 -0
- package/dist/app/review/index.js.map +1 -0
- package/dist/collab-ui/AgentPresenceChip.d.ts +8 -0
- package/dist/collab-ui/AgentPresenceChip.d.ts.map +1 -0
- package/dist/collab-ui/AgentPresenceChip.js +42 -0
- package/dist/collab-ui/AgentPresenceChip.js.map +1 -0
- package/dist/collab-ui/LiveCursorOverlay.d.ts +17 -0
- package/dist/collab-ui/LiveCursorOverlay.d.ts.map +1 -0
- package/dist/collab-ui/LiveCursorOverlay.js +108 -0
- package/dist/collab-ui/LiveCursorOverlay.js.map +1 -0
- package/dist/collab-ui/PresenceBar.d.ts +17 -0
- package/dist/collab-ui/PresenceBar.d.ts.map +1 -0
- package/dist/collab-ui/PresenceBar.js +173 -0
- package/dist/collab-ui/PresenceBar.js.map +1 -0
- package/dist/collab-ui/RecentEditHighlights.d.ts +12 -0
- package/dist/collab-ui/RecentEditHighlights.d.ts.map +1 -0
- package/dist/collab-ui/RecentEditHighlights.js +128 -0
- package/dist/collab-ui/RecentEditHighlights.js.map +1 -0
- package/dist/collab-ui/RemoteSelectionRings.d.ts +15 -0
- package/dist/collab-ui/RemoteSelectionRings.d.ts.map +1 -0
- package/dist/collab-ui/RemoteSelectionRings.js +108 -0
- package/dist/collab-ui/RemoteSelectionRings.js.map +1 -0
- package/dist/collab-ui/agent-identity.d.ts +9 -0
- package/dist/collab-ui/agent-identity.d.ts.map +1 -0
- package/dist/collab-ui/agent-identity.js +8 -0
- package/dist/collab-ui/agent-identity.js.map +1 -0
- package/dist/collab-ui/index.d.ts +9 -0
- package/dist/collab-ui/index.d.ts.map +1 -0
- package/dist/collab-ui/index.js +9 -0
- package/dist/collab-ui/index.js.map +1 -0
- package/dist/collab-ui/lead-client.d.ts +3 -0
- package/dist/collab-ui/lead-client.d.ts.map +1 -0
- package/dist/collab-ui/lead-client.js +32 -0
- package/dist/collab-ui/lead-client.js.map +1 -0
- package/dist/collab-ui/types.d.ts +48 -0
- package/dist/collab-ui/types.d.ts.map +1 -0
- package/dist/collab-ui/types.js +52 -0
- package/dist/collab-ui/types.js.map +1 -0
- package/dist/design-system/components.d.ts +58 -0
- package/dist/design-system/components.d.ts.map +1 -0
- package/dist/design-system/components.js +79 -0
- package/dist/design-system/components.js.map +1 -0
- package/dist/design-system/context.d.ts +11 -0
- package/dist/design-system/context.d.ts.map +1 -0
- package/dist/design-system/context.js +17 -0
- package/dist/design-system/context.js.map +1 -0
- package/dist/design-system/default-adapter.d.ts +3 -0
- package/dist/design-system/default-adapter.d.ts.map +1 -0
- package/dist/design-system/default-adapter.js +229 -0
- package/dist/design-system/default-adapter.js.map +1 -0
- package/dist/design-system/definition.d.ts +9 -0
- package/dist/design-system/definition.d.ts.map +1 -0
- package/dist/design-system/definition.js +4 -0
- package/dist/design-system/definition.js.map +1 -0
- package/dist/design-system/error-boundary.d.ts +18 -0
- package/dist/design-system/error-boundary.d.ts.map +1 -0
- package/dist/design-system/error-boundary.js +16 -0
- package/dist/design-system/error-boundary.js.map +1 -0
- package/dist/design-system/index.d.ts +8 -0
- package/dist/design-system/index.d.ts.map +1 -0
- package/dist/design-system/index.js +8 -0
- package/dist/design-system/index.js.map +1 -0
- package/dist/design-system/theme.d.ts +29 -0
- package/dist/design-system/theme.d.ts.map +1 -0
- package/dist/design-system/theme.js +95 -0
- package/dist/design-system/theme.js.map +1 -0
- package/dist/design-system/types.d.ts +288 -0
- package/dist/design-system/types.d.ts.map +1 -0
- package/dist/design-system/types.js +2 -0
- package/dist/design-system/types.js.map +1 -0
- package/dist/editor/BubbleToolbar.d.ts +18 -0
- package/dist/editor/BubbleToolbar.d.ts.map +1 -0
- package/dist/editor/BubbleToolbar.js +160 -0
- package/dist/editor/BubbleToolbar.js.map +1 -0
- package/dist/editor/CodeBlockNode.d.ts +25 -0
- package/dist/editor/CodeBlockNode.d.ts.map +1 -0
- package/dist/editor/CodeBlockNode.js +112 -0
- package/dist/editor/CodeBlockNode.js.map +1 -0
- package/dist/editor/DragHandle.d.ts +40 -0
- package/dist/editor/DragHandle.d.ts.map +1 -0
- package/dist/editor/DragHandle.js +983 -0
- package/dist/editor/DragHandle.js.map +1 -0
- package/dist/editor/ImageExtension.d.ts +15 -0
- package/dist/editor/ImageExtension.d.ts.map +1 -0
- package/dist/editor/ImageExtension.js +182 -0
- package/dist/editor/ImageExtension.js.map +1 -0
- package/dist/editor/RegistryBlockContext.d.ts +72 -0
- package/dist/editor/RegistryBlockContext.d.ts.map +1 -0
- package/dist/editor/RegistryBlockContext.js +10 -0
- package/dist/editor/RegistryBlockContext.js.map +1 -0
- package/dist/editor/RegistryBlockNode.d.ts +36 -0
- package/dist/editor/RegistryBlockNode.d.ts.map +1 -0
- package/dist/editor/RegistryBlockNode.js +343 -0
- package/dist/editor/RegistryBlockNode.js.map +1 -0
- package/dist/editor/RichMarkdownEditor.d.ts +18 -0
- package/dist/editor/RichMarkdownEditor.d.ts.map +1 -0
- package/dist/editor/RichMarkdownEditor.js +11 -0
- package/dist/editor/RichMarkdownEditor.js.map +1 -0
- package/dist/editor/RunId.d.ts +4 -0
- package/dist/editor/RunId.d.ts.map +1 -0
- package/dist/editor/RunId.js +33 -0
- package/dist/editor/RunId.js.map +1 -0
- package/dist/editor/SharedRichEditor.d.ts +57 -0
- package/dist/editor/SharedRichEditor.d.ts.map +1 -0
- package/dist/editor/SharedRichEditor.js +155 -0
- package/dist/editor/SharedRichEditor.js.map +1 -0
- package/dist/editor/SlashCommandMenu.d.ts +25 -0
- package/dist/editor/SlashCommandMenu.d.ts.map +1 -0
- package/dist/editor/SlashCommandMenu.js +254 -0
- package/dist/editor/SlashCommandMenu.js.map +1 -0
- package/dist/editor/TaskListPaste.d.ts +4 -0
- package/dist/editor/TaskListPaste.d.ts.map +1 -0
- package/dist/editor/TaskListPaste.js +131 -0
- package/dist/editor/TaskListPaste.js.map +1 -0
- package/dist/editor/extensions.d.ts +42 -0
- package/dist/editor/extensions.d.ts.map +1 -0
- package/dist/editor/extensions.js +173 -0
- package/dist/editor/extensions.js.map +1 -0
- package/dist/editor/gfmDoc.d.ts +4 -0
- package/dist/editor/gfmDoc.d.ts.map +1 -0
- package/dist/editor/gfmDoc.js +37 -0
- package/dist/editor/gfmDoc.js.map +1 -0
- package/dist/editor/index.d.ts +17 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +16 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/registrySlashCommands.d.ts +20 -0
- package/dist/editor/registrySlashCommands.d.ts.map +1 -0
- package/dist/editor/registrySlashCommands.js +40 -0
- package/dist/editor/registrySlashCommands.js.map +1 -0
- package/dist/editor/surgical-apply.d.ts +46 -0
- package/dist/editor/surgical-apply.d.ts.map +1 -0
- package/dist/editor/surgical-apply.js +286 -0
- package/dist/editor/surgical-apply.js.map +1 -0
- package/dist/editor/useCollabReconcile.d.ts +94 -0
- package/dist/editor/useCollabReconcile.d.ts.map +1 -0
- package/dist/editor/useCollabReconcile.js +879 -0
- package/dist/editor/useCollabReconcile.js.map +1 -0
- package/dist/editor.css +628 -0
- package/dist/fonts/OFL.txt +93 -0
- package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/dist/forms.d.ts +70 -0
- package/dist/forms.js +56 -0
- package/dist/forms.js.map +1 -0
- package/dist/guard.d.ts +2 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +33 -6
- package/dist/guard.js.map +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +16 -0
- package/dist/hooks/use-mobile.js.map +1 -0
- package/dist/hooks/use-toast.d.ts +45 -0
- package/dist/hooks/use-toast.d.ts.map +1 -0
- package/dist/hooks/use-toast.js +125 -0
- package/dist/hooks/use-toast.js.map +1 -0
- package/dist/icons/ResourceIcon.d.ts +14 -0
- package/dist/icons/ResourceIcon.d.ts.map +1 -0
- package/dist/icons/ResourceIcon.js +43 -0
- package/dist/icons/ResourceIcon.js.map +1 -0
- package/dist/icons/ResourceIconPicker.d.ts +57 -0
- package/dist/icons/ResourceIconPicker.d.ts.map +1 -0
- package/dist/icons/ResourceIconPicker.js +388 -0
- package/dist/icons/ResourceIconPicker.js.map +1 -0
- package/dist/icons/catalog.d.ts +17 -0
- package/dist/icons/catalog.d.ts.map +1 -0
- package/dist/icons/catalog.js +114 -0
- package/dist/icons/catalog.js.map +1 -0
- package/dist/icons/emoji-catalog.d.ts +12 -0
- package/dist/icons/emoji-catalog.d.ts.map +1 -0
- package/dist/icons/emoji-catalog.js +58 -0
- package/dist/icons/emoji-catalog.js.map +1 -0
- package/dist/icons/icon-colors.d.ts +3 -0
- package/dist/icons/icon-colors.d.ts.map +1 -0
- package/dist/icons/icon-colors.js +12 -0
- package/dist/icons/icon-colors.js.map +1 -0
- package/dist/icons/index.d.ts +5 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +5 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/icons/recents.d.ts +6 -0
- package/dist/icons/recents.d.ts.map +1 -0
- package/dist/icons/recents.js +23 -0
- package/dist/icons/recents.js.map +1 -0
- package/dist/icons/server.d.ts +7 -0
- package/dist/icons/server.d.ts.map +1 -0
- package/dist/icons/server.js +25 -0
- package/dist/icons/server.js.map +1 -0
- package/dist/icons/tabler-catalog-data.d.ts +31 -0
- package/dist/icons/tabler-catalog-data.d.ts.map +1 -0
- package/dist/icons/tabler-catalog-data.js +30121 -0
- package/dist/icons/tabler-catalog-data.js.map +1 -0
- package/dist/icons/tabler-chunk-loaders.d.ts +30 -0
- package/dist/icons/tabler-chunk-loaders.d.ts.map +1 -0
- package/dist/icons/tabler-chunk-loaders.js +29 -0
- package/dist/icons/tabler-chunk-loaders.js.map +1 -0
- package/dist/icons/tabler-chunks/a.d.ts +450 -0
- package/dist/icons/tabler-chunks/a.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/a.js +450 -0
- package/dist/icons/tabler-chunks/a.js.map +1 -0
- package/dist/icons/tabler-chunks/b.d.ts +849 -0
- package/dist/icons/tabler-chunks/b.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/b.js +849 -0
- package/dist/icons/tabler-chunks/b.js.map +1 -0
- package/dist/icons/tabler-chunks/c.d.ts +922 -0
- package/dist/icons/tabler-chunks/c.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/c.js +922 -0
- package/dist/icons/tabler-chunks/c.js.map +1 -0
- package/dist/icons/tabler-chunks/d.d.ts +380 -0
- package/dist/icons/tabler-chunks/d.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/d.js +380 -0
- package/dist/icons/tabler-chunks/d.js.map +1 -0
- package/dist/icons/tabler-chunks/e.d.ts +112 -0
- package/dist/icons/tabler-chunks/e.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/e.js +112 -0
- package/dist/icons/tabler-chunks/e.js.map +1 -0
- package/dist/icons/tabler-chunks/f.d.ts +341 -0
- package/dist/icons/tabler-chunks/f.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/f.js +341 -0
- package/dist/icons/tabler-chunks/f.js.map +1 -0
- package/dist/icons/tabler-chunks/g.d.ts +101 -0
- package/dist/icons/tabler-chunks/g.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/g.js +101 -0
- package/dist/icons/tabler-chunks/g.js.map +1 -0
- package/dist/icons/tabler-chunks/h.d.ts +276 -0
- package/dist/icons/tabler-chunks/h.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/h.js +276 -0
- package/dist/icons/tabler-chunks/h.js.map +1 -0
- package/dist/icons/tabler-chunks/i.d.ts +79 -0
- package/dist/icons/tabler-chunks/i.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/i.js +79 -0
- package/dist/icons/tabler-chunks/i.js.map +1 -0
- package/dist/icons/tabler-chunks/j.d.ts +17 -0
- package/dist/icons/tabler-chunks/j.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/j.js +17 -0
- package/dist/icons/tabler-chunks/j.js.map +1 -0
- package/dist/icons/tabler-chunks/k.d.ts +25 -0
- package/dist/icons/tabler-chunks/k.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/k.js +25 -0
- package/dist/icons/tabler-chunks/k.js.map +1 -0
- package/dist/icons/tabler-chunks/l.d.ts +298 -0
- package/dist/icons/tabler-chunks/l.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/l.js +298 -0
- package/dist/icons/tabler-chunks/l.js.map +1 -0
- package/dist/icons/tabler-chunks/m.d.ts +413 -0
- package/dist/icons/tabler-chunks/m.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/m.js +413 -0
- package/dist/icons/tabler-chunks/m.js.map +1 -0
- package/dist/icons/tabler-chunks/n.d.ts +174 -0
- package/dist/icons/tabler-chunks/n.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/n.js +174 -0
- package/dist/icons/tabler-chunks/n.js.map +1 -0
- package/dist/icons/tabler-chunks/o.d.ts +31 -0
- package/dist/icons/tabler-chunks/o.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/o.js +31 -0
- package/dist/icons/tabler-chunks/o.js.map +1 -0
- package/dist/icons/tabler-chunks/p.d.ts +374 -0
- package/dist/icons/tabler-chunks/p.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/p.js +374 -0
- package/dist/icons/tabler-chunks/p.js.map +1 -0
- package/dist/icons/tabler-chunks/q.d.ts +14 -0
- package/dist/icons/tabler-chunks/q.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/q.js +14 -0
- package/dist/icons/tabler-chunks/q.js.map +1 -0
- package/dist/icons/tabler-chunks/r.d.ts +183 -0
- package/dist/icons/tabler-chunks/r.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/r.js +183 -0
- package/dist/icons/tabler-chunks/r.js.map +1 -0
- package/dist/icons/tabler-chunks/s.d.ts +656 -0
- package/dist/icons/tabler-chunks/s.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/s.js +656 -0
- package/dist/icons/tabler-chunks/s.js.map +1 -0
- package/dist/icons/tabler-chunks/t.d.ts +242 -0
- package/dist/icons/tabler-chunks/t.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/t.js +242 -0
- package/dist/icons/tabler-chunks/t.js.map +1 -0
- package/dist/icons/tabler-chunks/u.d.ts +62 -0
- package/dist/icons/tabler-chunks/u.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/u.js +62 -0
- package/dist/icons/tabler-chunks/u.js.map +1 -0
- package/dist/icons/tabler-chunks/v.d.ts +60 -0
- package/dist/icons/tabler-chunks/v.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/v.js +60 -0
- package/dist/icons/tabler-chunks/v.js.map +1 -0
- package/dist/icons/tabler-chunks/w.d.ts +115 -0
- package/dist/icons/tabler-chunks/w.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/w.js +115 -0
- package/dist/icons/tabler-chunks/w.js.map +1 -0
- package/dist/icons/tabler-chunks/x.d.ts +18 -0
- package/dist/icons/tabler-chunks/x.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/x.js +18 -0
- package/dist/icons/tabler-chunks/x.js.map +1 -0
- package/dist/icons/tabler-chunks/y.d.ts +7 -0
- package/dist/icons/tabler-chunks/y.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/y.js +3 -0
- package/dist/icons/tabler-chunks/y.js.map +1 -0
- package/dist/icons/tabler-chunks/z.d.ts +51 -0
- package/dist/icons/tabler-chunks/z.d.ts.map +1 -0
- package/dist/icons/tabler-chunks/z.js +51 -0
- package/dist/icons/tabler-chunks/z.js.map +1 -0
- package/dist/icons/tabler-groups.d.ts +30 -0
- package/dist/icons/tabler-groups.d.ts.map +1 -0
- package/dist/icons/tabler-groups.js +65 -0
- package/dist/icons/tabler-groups.js.map +1 -0
- package/dist/icons/types.d.ts +25 -0
- package/dist/icons/types.d.ts.map +1 -0
- package/dist/icons/types.js +2 -0
- package/dist/icons/types.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/page.d.ts +19 -5
- package/dist/page.js +26 -8
- package/dist/page.js.map +1 -1
- package/dist/parts.d.ts +83 -0
- package/dist/parts.js +78 -0
- package/dist/parts.js.map +1 -0
- package/dist/provider.d.ts +15 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +62 -0
- package/dist/provider.js.map +1 -0
- package/dist/shell.d.ts +25 -6
- package/dist/shell.js +96 -10
- package/dist/shell.js.map +1 -1
- package/dist/styles.css +344 -652
- package/dist/suite/controls.d.ts +8 -0
- package/dist/suite/controls.d.ts.map +1 -0
- package/dist/suite/controls.js +12 -0
- package/dist/suite/controls.js.map +1 -0
- package/dist/suite/due-picker.d.ts +24 -0
- package/dist/suite/due-picker.d.ts.map +1 -0
- package/dist/suite/due-picker.js +100 -0
- package/dist/suite/due-picker.js.map +1 -0
- package/dist/suite/due.d.ts +6 -0
- package/dist/suite/due.d.ts.map +1 -0
- package/dist/suite/due.js +58 -0
- package/dist/suite/due.js.map +1 -0
- package/dist/suite/emoji.d.ts +34 -0
- package/dist/suite/emoji.d.ts.map +1 -0
- package/dist/suite/emoji.js +643 -0
- package/dist/suite/emoji.js.map +1 -0
- package/dist/suite/files.d.ts +29 -0
- package/dist/suite/files.d.ts.map +1 -0
- package/dist/suite/files.js +46 -0
- package/dist/suite/files.js.map +1 -0
- package/dist/suite/forms.d.ts +32 -0
- package/dist/suite/forms.d.ts.map +1 -0
- package/dist/suite/forms.js +29 -0
- package/dist/suite/forms.js.map +1 -0
- package/dist/suite/index.d.ts +16 -0
- package/dist/suite/index.d.ts.map +1 -0
- package/dist/suite/index.js +18 -0
- package/dist/suite/index.js.map +1 -0
- package/dist/suite/link.d.ts +23 -0
- package/dist/suite/link.d.ts.map +1 -0
- package/dist/suite/link.js +45 -0
- package/dist/suite/link.js.map +1 -0
- package/dist/suite/links.d.ts +25 -0
- package/dist/suite/links.d.ts.map +1 -0
- package/dist/suite/links.js +69 -0
- package/dist/suite/links.js.map +1 -0
- package/dist/suite/markdown.d.ts +6 -0
- package/dist/suite/markdown.d.ts.map +1 -0
- package/dist/suite/markdown.js +64 -0
- package/dist/suite/markdown.js.map +1 -0
- package/dist/suite/page.d.ts +99 -0
- package/dist/suite/page.d.ts.map +1 -0
- package/dist/suite/page.js +92 -0
- package/dist/suite/page.js.map +1 -0
- package/dist/suite/parts.d.ts +67 -0
- package/dist/suite/parts.d.ts.map +1 -0
- package/dist/suite/parts.js +68 -0
- package/dist/suite/parts.js.map +1 -0
- package/dist/suite/pickers.d.ts +40 -0
- package/dist/suite/pickers.d.ts.map +1 -0
- package/dist/suite/pickers.js +87 -0
- package/dist/suite/pickers.js.map +1 -0
- package/dist/suite/project-appearance.d.ts +7 -0
- package/dist/suite/project-appearance.d.ts.map +1 -0
- package/dist/suite/project-appearance.js +45 -0
- package/dist/suite/project-appearance.js.map +1 -0
- package/dist/suite/project-icon.d.ts +26 -0
- package/dist/suite/project-icon.d.ts.map +1 -0
- package/dist/suite/project-icon.js +58 -0
- package/dist/suite/project-icon.js.map +1 -0
- package/dist/suite/shell.d.ts +89 -0
- package/dist/suite/shell.d.ts.map +1 -0
- package/dist/suite/shell.js +156 -0
- package/dist/suite/shell.js.map +1 -0
- package/dist/suite/suite.css +1146 -0
- package/dist/suite/views.d.ts +30 -0
- package/dist/suite/views.d.ts.map +1 -0
- package/dist/suite/views.js +20 -0
- package/dist/suite/views.js.map +1 -0
- package/dist/theme/resource-icons.css +23 -0
- package/dist/theme/suite-theme.css +97 -0
- package/dist/ui/accordion.d.ts +8 -0
- package/dist/ui/accordion.d.ts.map +1 -0
- package/dist/ui/accordion.js +14 -0
- package/dist/ui/accordion.js.map +1 -0
- package/dist/ui/alert-dialog.d.ts +24 -0
- package/dist/ui/alert-dialog.d.ts.map +1 -0
- package/dist/ui/alert-dialog.js +31 -0
- package/dist/ui/alert-dialog.js.map +1 -0
- package/dist/ui/alert.d.ts +9 -0
- package/dist/ui/alert.d.ts.map +1 -0
- package/dist/ui/alert.js +23 -0
- package/dist/ui/alert.js.map +1 -0
- package/dist/ui/aspect-ratio.d.ts +4 -0
- package/dist/ui/aspect-ratio.d.ts.map +1 -0
- package/dist/ui/aspect-ratio.js +4 -0
- package/dist/ui/aspect-ratio.js.map +1 -0
- package/dist/ui/avatar.d.ts +7 -0
- package/dist/ui/avatar.d.ts.map +1 -0
- package/dist/ui/avatar.js +12 -0
- package/dist/ui/avatar.js.map +1 -0
- package/dist/ui/badge.d.ts +10 -0
- package/dist/ui/badge.d.ts.map +1 -0
- package/dist/ui/badge.js +21 -0
- package/dist/ui/badge.js.map +1 -0
- package/dist/ui/breadcrumb.d.ts +20 -0
- package/dist/ui/breadcrumb.d.ts.map +1 -0
- package/dist/ui/breadcrumb.js +24 -0
- package/dist/ui/breadcrumb.js.map +1 -0
- package/dist/ui/button-group.d.ts +15 -0
- package/dist/ui/button-group.d.ts.map +1 -0
- package/dist/ui/button-group.js +30 -0
- package/dist/ui/button-group.js.map +1 -0
- package/dist/ui/button.d.ts +17 -0
- package/dist/ui/button.d.ts.map +1 -0
- package/dist/ui/button.js +89 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/calendar.d.ts +9 -0
- package/dist/ui/calendar.d.ts.map +1 -0
- package/dist/ui/calendar.js +74 -0
- package/dist/ui/calendar.js.map +1 -0
- package/dist/ui/card.d.ts +9 -0
- package/dist/ui/card.d.ts.map +1 -0
- package/dist/ui/card.js +17 -0
- package/dist/ui/card.js.map +1 -0
- package/dist/ui/carousel.d.ts +19 -0
- package/dist/ui/carousel.d.ts.map +1 -0
- package/dist/ui/carousel.js +99 -0
- package/dist/ui/carousel.js.map +1 -0
- package/dist/ui/chart.d.ts +80 -0
- package/dist/ui/chart.d.ts.map +1 -0
- package/dist/ui/chart.js +129 -0
- package/dist/ui/chart.js.map +1 -0
- package/dist/ui/checkbox.d.ts +5 -0
- package/dist/ui/checkbox.d.ts.map +1 -0
- package/dist/ui/checkbox.js +9 -0
- package/dist/ui/checkbox.js.map +1 -0
- package/dist/ui/collapsible.d.ts +6 -0
- package/dist/ui/collapsible.d.ts.map +1 -0
- package/dist/ui/collapsible.js +6 -0
- package/dist/ui/collapsible.js.map +1 -0
- package/dist/ui/command.d.ts +90 -0
- package/dist/ui/command.d.ts.map +1 -0
- package/dist/ui/command.js +35 -0
- package/dist/ui/command.js.map +1 -0
- package/dist/ui/context-menu.d.ts +28 -0
- package/dist/ui/context-menu.d.ts.map +1 -0
- package/dist/ui/context-menu.js +34 -0
- package/dist/ui/context-menu.js.map +1 -0
- package/dist/ui/cube-loader.d.ts +8 -0
- package/dist/ui/cube-loader.d.ts.map +1 -0
- package/dist/ui/cube-loader.js +45 -0
- package/dist/ui/cube-loader.js.map +1 -0
- package/dist/ui/date-picker.d.ts +9 -0
- package/dist/ui/date-picker.d.ts.map +1 -0
- package/dist/ui/date-picker.js +20 -0
- package/dist/ui/date-picker.js.map +1 -0
- package/dist/ui/dialog.d.ts +32 -0
- package/dist/ui/dialog.d.ts.map +1 -0
- package/dist/ui/dialog.js +26 -0
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/drawer.d.ts +35 -0
- package/dist/ui/drawer.d.ts.map +1 -0
- package/dist/ui/drawer.js +25 -0
- package/dist/ui/drawer.js.map +1 -0
- package/dist/ui/dropdown-menu.d.ts +34 -0
- package/dist/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/ui/dropdown-menu.js +42 -0
- package/dist/ui/dropdown-menu.js.map +1 -0
- package/dist/ui/empty.d.ts +13 -0
- package/dist/ui/empty.d.ts.map +1 -0
- package/dist/ui/empty.js +34 -0
- package/dist/ui/empty.js.map +1 -0
- package/dist/ui/filter-trigger.d.ts +9 -0
- package/dist/ui/filter-trigger.d.ts.map +1 -0
- package/dist/ui/filter-trigger.js +6 -0
- package/dist/ui/filter-trigger.js.map +1 -0
- package/dist/ui/form.d.ts +26 -0
- package/dist/ui/form.d.ts.map +1 -0
- package/dist/ui/form.js +63 -0
- package/dist/ui/form.js.map +1 -0
- package/dist/ui/hover-card.d.ts +7 -0
- package/dist/ui/hover-card.d.ts.map +1 -0
- package/dist/ui/hover-card.js +10 -0
- package/dist/ui/hover-card.js.map +1 -0
- package/dist/ui/index.d.ts +60 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +60 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/input-group.d.ts +21 -0
- package/dist/ui/input-group.d.ts.map +1 -0
- package/dist/ui/input-group.js +59 -0
- package/dist/ui/input-group.js.map +1 -0
- package/dist/ui/input-otp.d.ts +37 -0
- package/dist/ui/input-otp.d.ts.map +1 -0
- package/dist/ui/input-otp.js +19 -0
- package/dist/ui/input-otp.js.map +1 -0
- package/dist/ui/input.d.ts +7 -0
- package/dist/ui/input.d.ts.map +1 -0
- package/dist/ui/input.js +9 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/ui/item.d.ts +24 -0
- package/dist/ui/item.d.ts.map +1 -0
- package/dist/ui/item.js +67 -0
- package/dist/ui/item.js.map +1 -0
- package/dist/ui/kbd.d.ts +5 -0
- package/dist/ui/kbd.d.ts.map +1 -0
- package/dist/ui/kbd.js +10 -0
- package/dist/ui/kbd.js.map +1 -0
- package/dist/ui/label.d.ts +6 -0
- package/dist/ui/label.d.ts.map +1 -0
- package/dist/ui/label.js +10 -0
- package/dist/ui/label.js.map +1 -0
- package/dist/ui/logo.d.ts +7 -0
- package/dist/ui/logo.d.ts.map +1 -0
- package/dist/ui/logo.js +9 -0
- package/dist/ui/logo.js.map +1 -0
- package/dist/ui/menubar.d.ts +29 -0
- package/dist/ui/menubar.d.ts.map +1 -0
- package/dist/ui/menubar.js +36 -0
- package/dist/ui/menubar.js.map +1 -0
- package/dist/ui/navigation-menu.d.ts +13 -0
- package/dist/ui/navigation-menu.d.ts.map +1 -0
- package/dist/ui/navigation-menu.js +25 -0
- package/dist/ui/navigation-menu.js.map +1 -0
- package/dist/ui/pagination.d.ts +29 -0
- package/dist/ui/pagination.d.ts.map +1 -0
- package/dist/ui/pagination.js +24 -0
- package/dist/ui/pagination.js.map +1 -0
- package/dist/ui/pointer-lock.d.ts +2 -0
- package/dist/ui/pointer-lock.d.ts.map +1 -0
- package/dist/ui/pointer-lock.js +11 -0
- package/dist/ui/pointer-lock.js.map +1 -0
- package/dist/ui/popover.d.ts +11 -0
- package/dist/ui/popover.d.ts.map +1 -0
- package/dist/ui/popover.js +16 -0
- package/dist/ui/popover.js.map +1 -0
- package/dist/ui/progress.d.ts +5 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +16 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/radio-group.d.ts +6 -0
- package/dist/ui/radio-group.d.ts.map +1 -0
- package/dist/ui/radio-group.js +15 -0
- package/dist/ui/radio-group.js.map +1 -0
- package/dist/ui/resizable.d.ts +10 -0
- package/dist/ui/resizable.d.ts.map +1 -0
- package/dist/ui/resizable.js +9 -0
- package/dist/ui/resizable.js.map +1 -0
- package/dist/ui/scroll-area.d.ts +6 -0
- package/dist/ui/scroll-area.d.ts.map +1 -0
- package/dist/ui/scroll-area.js +12 -0
- package/dist/ui/scroll-area.js.map +1 -0
- package/dist/ui/select.d.ts +18 -0
- package/dist/ui/select.d.ts.map +1 -0
- package/dist/ui/select.js +27 -0
- package/dist/ui/select.js.map +1 -0
- package/dist/ui/separator.d.ts +5 -0
- package/dist/ui/separator.d.ts.map +1 -0
- package/dist/ui/separator.js +8 -0
- package/dist/ui/separator.js.map +1 -0
- package/dist/ui/sheet.d.ts +29 -0
- package/dist/ui/sheet.d.ts.map +1 -0
- package/dist/ui/sheet.js +37 -0
- package/dist/ui/sheet.js.map +1 -0
- package/dist/ui/sidebar.d.ts +73 -0
- package/dist/ui/sidebar.d.ts.map +1 -0
- package/dist/ui/sidebar.js +216 -0
- package/dist/ui/sidebar.js.map +1 -0
- package/dist/ui/skeleton.d.ts +3 -0
- package/dist/ui/skeleton.d.ts.map +1 -0
- package/dist/ui/skeleton.js +7 -0
- package/dist/ui/skeleton.js.map +1 -0
- package/dist/ui/slider.d.ts +5 -0
- package/dist/ui/slider.d.ts.map +1 -0
- package/dist/ui/slider.js +16 -0
- package/dist/ui/slider.js.map +1 -0
- package/dist/ui/sonner.d.ts +5 -0
- package/dist/ui/sonner.d.ts.map +1 -0
- package/dist/ui/sonner.js +25 -0
- package/dist/ui/sonner.js.map +1 -0
- package/dist/ui/spinner.d.ts +3 -0
- package/dist/ui/spinner.d.ts.map +1 -0
- package/dist/ui/spinner.js +6 -0
- package/dist/ui/spinner.js.map +1 -0
- package/dist/ui/switch.d.ts +7 -0
- package/dist/ui/switch.d.ts.map +1 -0
- package/dist/ui/switch.js +8 -0
- package/dist/ui/switch.js.map +1 -0
- package/dist/ui/table.d.ts +11 -0
- package/dist/ui/table.d.ts.map +1 -0
- package/dist/ui/table.js +21 -0
- package/dist/ui/table.js.map +1 -0
- package/dist/ui/tabs.d.ts +8 -0
- package/dist/ui/tabs.d.ts.map +1 -0
- package/dist/ui/tabs.js +13 -0
- package/dist/ui/tabs.js.map +1 -0
- package/dist/ui/textarea.d.ts +6 -0
- package/dist/ui/textarea.d.ts.map +1 -0
- package/dist/ui/textarea.js +9 -0
- package/dist/ui/textarea.js.map +1 -0
- package/dist/ui/toast.d.ts +16 -0
- package/dist/ui/toast.d.ts.map +1 -0
- package/dist/ui/toast.js +34 -0
- package/dist/ui/toast.js.map +1 -0
- package/dist/ui/toaster.d.ts +2 -0
- package/dist/ui/toaster.d.ts.map +1 -0
- package/dist/ui/toaster.js +10 -0
- package/dist/ui/toaster.js.map +1 -0
- package/dist/ui/toggle-group.d.ts +13 -0
- package/dist/ui/toggle-group.d.ts.map +1 -0
- package/dist/ui/toggle-group.js +21 -0
- package/dist/ui/toggle-group.js.map +1 -0
- package/dist/ui/toggle.d.ts +13 -0
- package/dist/ui/toggle.d.ts.map +1 -0
- package/dist/ui/toggle.js +26 -0
- package/dist/ui/toggle.js.map +1 -0
- package/dist/ui/tooltip.d.ts +11 -0
- package/dist/ui/tooltip.d.ts.map +1 -0
- package/dist/ui/tooltip.js +18 -0
- package/dist/ui/tooltip.js.map +1 -0
- package/dist/ui/use-toast.d.ts +3 -0
- package/dist/ui/use-toast.d.ts.map +1 -0
- package/dist/ui/use-toast.js +3 -0
- package/dist/ui/use-toast.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/utils.js.map +1 -0
- package/package.json +186 -14
- package/skills/ux-flow/SKILL.md +6 -3
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
import { isChangeOrigin } from "@tiptap/extension-collaboration";
|
|
2
|
+
import { ySyncPluginKey } from "@tiptap/y-tiptap";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { applyUpdate } from "yjs";
|
|
5
|
+
import { AGENT_CLIENT_ID, isReconcileLeadClient } from "../collab-ui/index.js";
|
|
6
|
+
import { RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION, applyDocSurgically, defaultParseValue, reconcileDocAgainstBase, } from "./surgical-apply.js";
|
|
7
|
+
export { RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION };
|
|
8
|
+
export function isRemoteCollaborativeTransaction(transaction) {
|
|
9
|
+
return (isChangeOrigin(transaction) &&
|
|
10
|
+
!transaction.getMeta(ySyncPluginKey)?.isUndoRedoOperation);
|
|
11
|
+
}
|
|
12
|
+
export function applyAuthoritativeInitialSeed(ydoc, state, initialNodes) {
|
|
13
|
+
const fragment = ydoc.getXmlFragment("default");
|
|
14
|
+
ydoc.transact(() => {
|
|
15
|
+
for (const { node, serialized } of initialNodes) {
|
|
16
|
+
if (node.toString() !== serialized)
|
|
17
|
+
continue;
|
|
18
|
+
const index = fragment.toArray().indexOf(node);
|
|
19
|
+
if (index !== -1)
|
|
20
|
+
fragment.delete(index, 1);
|
|
21
|
+
}
|
|
22
|
+
applyUpdate(ydoc, state, "authoritative-initial-seed");
|
|
23
|
+
}, "authoritative-initial-seed");
|
|
24
|
+
}
|
|
25
|
+
export function getEditorMarkdown(editor) {
|
|
26
|
+
const markdownStorage = editor.storage;
|
|
27
|
+
return markdownStorage.markdown?.getMarkdown?.() ?? "";
|
|
28
|
+
}
|
|
29
|
+
const EMITTED_RING_MAX = 16;
|
|
30
|
+
const PEER_SETTLE_MS = 2500;
|
|
31
|
+
// A non-lead client leaves a newer snapshot to the lead; if the lead has not
|
|
32
|
+
// converged the doc by then (it never refetched), adopt it rather than keep a
|
|
33
|
+
// Yjs doc that disagrees with SQL until the next reload drops unsaved text.
|
|
34
|
+
const LEAD_FAILOVER_MS = PEER_SETTLE_MS * 2;
|
|
35
|
+
const CATCH_UP_ATTEMPTS = 3;
|
|
36
|
+
const CATCH_UP_RETRY_MS = 2000;
|
|
37
|
+
function pushEmittedRing(ring, value) {
|
|
38
|
+
if (!value)
|
|
39
|
+
return;
|
|
40
|
+
if (ring[ring.length - 1] === value)
|
|
41
|
+
return;
|
|
42
|
+
const dupe = ring.indexOf(value);
|
|
43
|
+
if (dupe !== -1)
|
|
44
|
+
ring.splice(dupe, 1);
|
|
45
|
+
ring.push(value);
|
|
46
|
+
if (ring.length > EMITTED_RING_MAX)
|
|
47
|
+
ring.shift();
|
|
48
|
+
}
|
|
49
|
+
function defaultShouldSeed({ currentMarkdown, fragmentLength, }) {
|
|
50
|
+
return fragmentLength === 0 || !currentMarkdown.trim();
|
|
51
|
+
}
|
|
52
|
+
function defaultSetContent(editor, value, options) {
|
|
53
|
+
if (options.addToHistory === false) {
|
|
54
|
+
editor
|
|
55
|
+
.chain()
|
|
56
|
+
.command(({ tr }) => {
|
|
57
|
+
tr.setMeta("addToHistory", false);
|
|
58
|
+
return true;
|
|
59
|
+
})
|
|
60
|
+
.setContent(value, { emitUpdate: options.emitUpdate })
|
|
61
|
+
.run();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
editor.commands.setContent(value);
|
|
65
|
+
}
|
|
66
|
+
function defaultIsEditorFocused(editor) {
|
|
67
|
+
return editor.isFocused;
|
|
68
|
+
}
|
|
69
|
+
export function useCollabReconcile({ editor, ydoc = null, collabSynced = true, awareness = null, value, contentUpdatedAt, contentRevision, compareContentRevisions, acknowledgedLocalSnapshot, collabContentRevision, requestCollabSync, onBaseAwareReconcile, onRemoteSnapshotChange, requestInitialSeed, quietSeedEditability = false, onInitialSeedError, overlapPolicy = "conflict", editable, isEditorFocused = defaultIsEditorFocused, getMarkdown = getEditorMarkdown, isEditorClean, setContent = defaultSetContent, parseValue, normalizeValue = (v) => v, shouldSeed = defaultShouldSeed, initialAppliedUpdatedAt, }) {
|
|
70
|
+
const collab = !!ydoc;
|
|
71
|
+
const collabBackedSnapshot = Boolean(collab && contentRevision && collabContentRevision === contentRevision);
|
|
72
|
+
const isSettingContentRef = useRef(false);
|
|
73
|
+
const lastEmittedRef = useRef("");
|
|
74
|
+
const lastRegisteredLocalEmissionRef = useRef(null);
|
|
75
|
+
const recentEmittedRef = useRef([]);
|
|
76
|
+
const lastTypedAtRef = useRef(0);
|
|
77
|
+
const lastAppliedValueRef = useRef(null);
|
|
78
|
+
const lastAppliedSerializedRef = useRef(null);
|
|
79
|
+
const lastAppliedUpdatedAtRef = useRef(initialAppliedUpdatedAt !== undefined
|
|
80
|
+
? initialAppliedUpdatedAt
|
|
81
|
+
: (contentUpdatedAt ?? null));
|
|
82
|
+
const authoritativeBaseRef = useRef(contentRevision ? { value, revision: contentRevision } : null);
|
|
83
|
+
const reportedConflictRevisionRef = useRef(null);
|
|
84
|
+
const reconcileCallbacksRef = useRef({
|
|
85
|
+
getMarkdown,
|
|
86
|
+
setContent,
|
|
87
|
+
parseValue,
|
|
88
|
+
normalizeValue,
|
|
89
|
+
isEditorFocused,
|
|
90
|
+
isEditorClean,
|
|
91
|
+
onBaseAwareReconcile,
|
|
92
|
+
onRemoteSnapshotChange,
|
|
93
|
+
});
|
|
94
|
+
reconcileCallbacksRef.current = {
|
|
95
|
+
getMarkdown,
|
|
96
|
+
setContent,
|
|
97
|
+
parseValue,
|
|
98
|
+
normalizeValue,
|
|
99
|
+
isEditorFocused,
|
|
100
|
+
isEditorClean,
|
|
101
|
+
onBaseAwareReconcile,
|
|
102
|
+
onRemoteSnapshotChange,
|
|
103
|
+
};
|
|
104
|
+
const acknowledgedLocalSnapshotRef = useRef(null);
|
|
105
|
+
const latestObservedUpdatedAtRef = useRef(contentUpdatedAt ?? null);
|
|
106
|
+
const latestObservedRevisionRef = useRef(contentRevision ?? null);
|
|
107
|
+
const acknowledgementBaseRollbackRef = useRef(null);
|
|
108
|
+
const acknowledgedCollabRef = useRef(null);
|
|
109
|
+
const [pendingCollabSnapshot, setPendingCollabSnapshot] = useState(null);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!collabBackedSnapshot || !ydoc || !contentRevision)
|
|
112
|
+
return;
|
|
113
|
+
if (acknowledgedCollabRef.current?.ydoc === ydoc &&
|
|
114
|
+
acknowledgedCollabRef.current.revision === contentRevision)
|
|
115
|
+
return;
|
|
116
|
+
setPendingCollabSnapshot((pending) => pending?.ydoc === ydoc && pending.revision === contentRevision
|
|
117
|
+
? pending
|
|
118
|
+
: {
|
|
119
|
+
ydoc,
|
|
120
|
+
revision: contentRevision,
|
|
121
|
+
value,
|
|
122
|
+
updatedAt: contentUpdatedAt,
|
|
123
|
+
});
|
|
124
|
+
}, [collabBackedSnapshot, ydoc, contentRevision, value, contentUpdatedAt]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!pendingCollabSnapshot ||
|
|
127
|
+
!requestCollabSync ||
|
|
128
|
+
pendingCollabSnapshot.ydoc !== ydoc)
|
|
129
|
+
return;
|
|
130
|
+
let cancelled = false;
|
|
131
|
+
let retry;
|
|
132
|
+
const sync = async () => {
|
|
133
|
+
const result = await requestCollabSync().catch(() => ({
|
|
134
|
+
status: "failed",
|
|
135
|
+
}));
|
|
136
|
+
if (cancelled)
|
|
137
|
+
return;
|
|
138
|
+
if (result.status !== "synced") {
|
|
139
|
+
retry = setTimeout(() => void sync(), 2000);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
authoritativeBaseRef.current = {
|
|
143
|
+
value: pendingCollabSnapshot.value,
|
|
144
|
+
revision: pendingCollabSnapshot.revision,
|
|
145
|
+
};
|
|
146
|
+
reportedConflictRevisionRef.current = null;
|
|
147
|
+
if (pendingCollabSnapshot.updatedAt)
|
|
148
|
+
lastAppliedUpdatedAtRef.current = pendingCollabSnapshot.updatedAt;
|
|
149
|
+
acknowledgedCollabRef.current = pendingCollabSnapshot;
|
|
150
|
+
setPendingCollabSnapshot(null);
|
|
151
|
+
};
|
|
152
|
+
void sync();
|
|
153
|
+
return () => {
|
|
154
|
+
cancelled = true;
|
|
155
|
+
if (retry)
|
|
156
|
+
clearTimeout(retry);
|
|
157
|
+
};
|
|
158
|
+
}, [pendingCollabSnapshot, requestCollabSync, ydoc]);
|
|
159
|
+
const [isLeadClient, setIsLeadClient] = useState(true);
|
|
160
|
+
const seedLead = requestInitialSeed ? true : isLeadClient;
|
|
161
|
+
const peerCountRef = useRef(0);
|
|
162
|
+
const emptySnapshotDecisionPendingRef = useRef(false);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!collab || !awareness || !ydoc) {
|
|
165
|
+
setIsLeadClient(true);
|
|
166
|
+
peerCountRef.current = 0;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const update = () => {
|
|
170
|
+
setIsLeadClient(isReconcileLeadClient(awareness, ydoc.clientID));
|
|
171
|
+
let peers = 0;
|
|
172
|
+
awareness.getStates().forEach((state, clientId) => {
|
|
173
|
+
if (clientId === ydoc.clientID)
|
|
174
|
+
return;
|
|
175
|
+
if (clientId === AGENT_CLIENT_ID)
|
|
176
|
+
return;
|
|
177
|
+
const s = state;
|
|
178
|
+
if (s?.canFlushDocument === false)
|
|
179
|
+
return;
|
|
180
|
+
if (s && s.user && s.visible !== false)
|
|
181
|
+
peers += 1;
|
|
182
|
+
});
|
|
183
|
+
peerCountRef.current = peers;
|
|
184
|
+
};
|
|
185
|
+
update();
|
|
186
|
+
awareness.on("change", update);
|
|
187
|
+
document.addEventListener("visibilitychange", update);
|
|
188
|
+
return () => {
|
|
189
|
+
awareness.off("change", update);
|
|
190
|
+
document.removeEventListener("visibilitychange", update);
|
|
191
|
+
};
|
|
192
|
+
}, [collab, awareness, ydoc]);
|
|
193
|
+
const seededRef = useRef(false);
|
|
194
|
+
const [seeded, setSeeded] = useState(false);
|
|
195
|
+
const markSeeded = () => {
|
|
196
|
+
seededRef.current = true;
|
|
197
|
+
if (requestInitialSeed)
|
|
198
|
+
setSeeded(true);
|
|
199
|
+
};
|
|
200
|
+
const [initialSeedFailed, setInitialSeedFailed] = useState(false);
|
|
201
|
+
const [initialSeedRetry, setInitialSeedRetry] = useState(0);
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
if (!collab || !editor || editor.isDestroyed || !ydoc)
|
|
204
|
+
return;
|
|
205
|
+
if (seededRef.current)
|
|
206
|
+
return;
|
|
207
|
+
if (!collabSynced)
|
|
208
|
+
return;
|
|
209
|
+
if (collabBackedSnapshot) {
|
|
210
|
+
markSeeded();
|
|
211
|
+
if (requestInitialSeed)
|
|
212
|
+
editor.setEditable(editable, !quietSeedEditability);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (contentRevision) {
|
|
216
|
+
authoritativeBaseRef.current = { value, revision: contentRevision };
|
|
217
|
+
reportedConflictRevisionRef.current = null;
|
|
218
|
+
}
|
|
219
|
+
if (!value.trim()) {
|
|
220
|
+
markSeeded();
|
|
221
|
+
const fragment = ydoc.getXmlFragment("default");
|
|
222
|
+
const currentMarkdown = getMarkdown(editor);
|
|
223
|
+
if (fragment.length === 0 && !currentMarkdown.trim())
|
|
224
|
+
return;
|
|
225
|
+
emptySnapshotDecisionPendingRef.current = true;
|
|
226
|
+
let cancelled = false;
|
|
227
|
+
const adoptTimer = setTimeout(() => {
|
|
228
|
+
if (cancelled || editor.isDestroyed)
|
|
229
|
+
return;
|
|
230
|
+
const projectedMarkdown = getMarkdown(editor);
|
|
231
|
+
const isOwnFreshEdit = projectedMarkdown.trim() &&
|
|
232
|
+
(projectedMarkdown === lastEmittedRef.current ||
|
|
233
|
+
recentEmittedRef.current.includes(projectedMarkdown));
|
|
234
|
+
if (projectedMarkdown.trim() &&
|
|
235
|
+
(peerCountRef.current > 0 || isOwnFreshEdit)) {
|
|
236
|
+
lastAppliedValueRef.current = value;
|
|
237
|
+
lastAppliedSerializedRef.current = projectedMarkdown;
|
|
238
|
+
if (contentUpdatedAt) {
|
|
239
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
emptySnapshotDecisionPendingRef.current = false;
|
|
243
|
+
}, awareness ? PEER_SETTLE_MS : 0);
|
|
244
|
+
return () => {
|
|
245
|
+
cancelled = true;
|
|
246
|
+
clearTimeout(adoptTimer);
|
|
247
|
+
emptySnapshotDecisionPendingRef.current = false;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (!seedLead) {
|
|
251
|
+
const releaseTimer = setTimeout(() => {
|
|
252
|
+
markSeeded();
|
|
253
|
+
}, 0);
|
|
254
|
+
return () => clearTimeout(releaseTimer);
|
|
255
|
+
}
|
|
256
|
+
let cancelled = false;
|
|
257
|
+
let retryTimer = null;
|
|
258
|
+
let retryDelayMs = 1000;
|
|
259
|
+
const seedTimer = setTimeout(() => {
|
|
260
|
+
if (cancelled || editor.isDestroyed)
|
|
261
|
+
return;
|
|
262
|
+
const fragment = ydoc.getXmlFragment("default");
|
|
263
|
+
const currentMarkdown = getMarkdown(editor);
|
|
264
|
+
if (!shouldSeed({
|
|
265
|
+
value,
|
|
266
|
+
currentMarkdown,
|
|
267
|
+
fragmentLength: fragment.length,
|
|
268
|
+
})) {
|
|
269
|
+
markSeeded();
|
|
270
|
+
if (requestInitialSeed)
|
|
271
|
+
editor.setEditable(editable, !quietSeedEditability);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (requestInitialSeed) {
|
|
275
|
+
editor.setEditable(false, !quietSeedEditability);
|
|
276
|
+
const initialNodes = fragment.toArray().map((node) => ({
|
|
277
|
+
node,
|
|
278
|
+
serialized: node.toString(),
|
|
279
|
+
}));
|
|
280
|
+
const claim = () => {
|
|
281
|
+
void requestInitialSeed(editor, value)
|
|
282
|
+
.then((state) => {
|
|
283
|
+
if (cancelled || editor.isDestroyed)
|
|
284
|
+
return;
|
|
285
|
+
isSettingContentRef.current = true;
|
|
286
|
+
try {
|
|
287
|
+
applyAuthoritativeInitialSeed(ydoc, state, initialNodes);
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
isSettingContentRef.current = false;
|
|
291
|
+
}
|
|
292
|
+
const serialized = getMarkdown(editor);
|
|
293
|
+
lastEmittedRef.current = serialized;
|
|
294
|
+
pushEmittedRing(recentEmittedRef.current, serialized);
|
|
295
|
+
lastAppliedValueRef.current = value;
|
|
296
|
+
lastAppliedSerializedRef.current = serialized;
|
|
297
|
+
if (contentUpdatedAt)
|
|
298
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
299
|
+
markSeeded();
|
|
300
|
+
setInitialSeedFailed(false);
|
|
301
|
+
editor.setEditable(editable, !quietSeedEditability);
|
|
302
|
+
})
|
|
303
|
+
.catch((error) => {
|
|
304
|
+
if (cancelled || editor.isDestroyed)
|
|
305
|
+
return;
|
|
306
|
+
onInitialSeedError?.(error);
|
|
307
|
+
const status = error && typeof error === "object" && "status" in error
|
|
308
|
+
? error.status
|
|
309
|
+
: undefined;
|
|
310
|
+
if (typeof status === "number" &&
|
|
311
|
+
status >= 400 &&
|
|
312
|
+
status < 500 &&
|
|
313
|
+
status !== 408 &&
|
|
314
|
+
status !== 429) {
|
|
315
|
+
setInitialSeedFailed(true);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
retryTimer = setTimeout(claim, retryDelayMs);
|
|
319
|
+
retryDelayMs = Math.min(retryDelayMs * 2, 8000);
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
claim();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
isSettingContentRef.current = true;
|
|
326
|
+
try {
|
|
327
|
+
setContent(editor, value, {});
|
|
328
|
+
}
|
|
329
|
+
finally {
|
|
330
|
+
isSettingContentRef.current = false;
|
|
331
|
+
}
|
|
332
|
+
const serialized = getMarkdown(editor);
|
|
333
|
+
lastEmittedRef.current = serialized;
|
|
334
|
+
pushEmittedRing(recentEmittedRef.current, serialized);
|
|
335
|
+
lastAppliedValueRef.current = value;
|
|
336
|
+
lastAppliedSerializedRef.current = serialized;
|
|
337
|
+
if (contentUpdatedAt)
|
|
338
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
339
|
+
markSeeded();
|
|
340
|
+
}, 0);
|
|
341
|
+
return () => {
|
|
342
|
+
cancelled = true;
|
|
343
|
+
clearTimeout(seedTimer);
|
|
344
|
+
if (retryTimer)
|
|
345
|
+
clearTimeout(retryTimer);
|
|
346
|
+
if (requestInitialSeed && !editor.isDestroyed)
|
|
347
|
+
editor.setEditable(editable, !quietSeedEditability);
|
|
348
|
+
};
|
|
349
|
+
}, [
|
|
350
|
+
collab,
|
|
351
|
+
collabSynced,
|
|
352
|
+
editor,
|
|
353
|
+
ydoc,
|
|
354
|
+
value,
|
|
355
|
+
seedLead,
|
|
356
|
+
requestInitialSeed,
|
|
357
|
+
onInitialSeedError,
|
|
358
|
+
editable,
|
|
359
|
+
contentUpdatedAt,
|
|
360
|
+
contentRevision,
|
|
361
|
+
getMarkdown,
|
|
362
|
+
setContent,
|
|
363
|
+
shouldSeed,
|
|
364
|
+
collabBackedSnapshot,
|
|
365
|
+
initialSeedRetry,
|
|
366
|
+
]);
|
|
367
|
+
const syncedBeforeAdoptRef = useRef(null);
|
|
368
|
+
const peerReconcileWaitRef = useRef(null);
|
|
369
|
+
useEffect(() => {
|
|
370
|
+
if (!editor || editor.isDestroyed) {
|
|
371
|
+
peerReconcileWaitRef.current = null;
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const previousWait = peerReconcileWaitRef.current;
|
|
375
|
+
if (!previousWait ||
|
|
376
|
+
previousWait.editor !== editor ||
|
|
377
|
+
previousWait.ydoc !== ydoc ||
|
|
378
|
+
previousWait.value !== value ||
|
|
379
|
+
previousWait.contentUpdatedAt !== contentUpdatedAt ||
|
|
380
|
+
previousWait.contentRevision !== contentRevision ||
|
|
381
|
+
previousWait.collabSynced !== collabSynced ||
|
|
382
|
+
previousWait.isLeadClient !== isLeadClient ||
|
|
383
|
+
previousWait.editable !== editable) {
|
|
384
|
+
peerReconcileWaitRef.current = {
|
|
385
|
+
editor,
|
|
386
|
+
ydoc,
|
|
387
|
+
value,
|
|
388
|
+
contentUpdatedAt,
|
|
389
|
+
contentRevision,
|
|
390
|
+
collabSynced,
|
|
391
|
+
isLeadClient,
|
|
392
|
+
editable,
|
|
393
|
+
deadline: null,
|
|
394
|
+
leadDeadline: null,
|
|
395
|
+
catchUpFailures: 0,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const peerWait = peerReconcileWaitRef.current;
|
|
399
|
+
let cancelled = false;
|
|
400
|
+
let retry = null;
|
|
401
|
+
const apply = (deferred = false) => {
|
|
402
|
+
if (cancelled || editor.isDestroyed)
|
|
403
|
+
return;
|
|
404
|
+
const callbacks = reconcileCallbacksRef.current;
|
|
405
|
+
if (contentUpdatedAt) {
|
|
406
|
+
const rollback = acknowledgementBaseRollbackRef.current;
|
|
407
|
+
const conflictsWithAcceptedAcknowledgement = contentRevision &&
|
|
408
|
+
rollback?.updatedAt === contentUpdatedAt &&
|
|
409
|
+
rollback.acknowledgementRevision !== contentRevision;
|
|
410
|
+
if (conflictsWithAcceptedAcknowledgement) {
|
|
411
|
+
const order = compareContentRevisions?.(contentRevision, rollback.acknowledgementRevision);
|
|
412
|
+
if (order !== undefined && order !== null && order <= 0) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (authoritativeBaseRef.current?.revision ===
|
|
416
|
+
rollback.acknowledgementRevision) {
|
|
417
|
+
authoritativeBaseRef.current = rollback.base;
|
|
418
|
+
}
|
|
419
|
+
acknowledgementBaseRollbackRef.current = null;
|
|
420
|
+
latestObservedUpdatedAtRef.current = contentUpdatedAt;
|
|
421
|
+
latestObservedRevisionRef.current = contentRevision;
|
|
422
|
+
}
|
|
423
|
+
else if (!latestObservedUpdatedAtRef.current ||
|
|
424
|
+
contentUpdatedAt > latestObservedUpdatedAtRef.current) {
|
|
425
|
+
latestObservedUpdatedAtRef.current = contentUpdatedAt;
|
|
426
|
+
latestObservedRevisionRef.current = contentRevision ?? null;
|
|
427
|
+
acknowledgementBaseRollbackRef.current = null;
|
|
428
|
+
}
|
|
429
|
+
else if (contentUpdatedAt === latestObservedUpdatedAtRef.current &&
|
|
430
|
+
contentRevision &&
|
|
431
|
+
latestObservedRevisionRef.current !== contentRevision) {
|
|
432
|
+
const order = latestObservedRevisionRef.current
|
|
433
|
+
? compareContentRevisions?.(contentRevision, latestObservedRevisionRef.current)
|
|
434
|
+
: null;
|
|
435
|
+
if (order !== undefined && order !== null && order <= 0) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
latestObservedRevisionRef.current =
|
|
439
|
+
order !== undefined && order !== null ? contentRevision : null;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
let rejectedMatchingAcknowledgement = false;
|
|
443
|
+
if (acknowledgedLocalSnapshot) {
|
|
444
|
+
const acceptedAcknowledgement = acknowledgedLocalSnapshotRef.current;
|
|
445
|
+
const acknowledgementIsNewestAccepted = !acceptedAcknowledgement ||
|
|
446
|
+
acknowledgedLocalSnapshot.sequence > acceptedAcknowledgement.sequence;
|
|
447
|
+
const acknowledgementRevisionOrder = acknowledgedLocalSnapshot.updatedAt ===
|
|
448
|
+
latestObservedUpdatedAtRef.current &&
|
|
449
|
+
latestObservedRevisionRef.current
|
|
450
|
+
? compareContentRevisions?.(acknowledgedLocalSnapshot.revision, latestObservedRevisionRef.current)
|
|
451
|
+
: null;
|
|
452
|
+
const acknowledgementIsNotSuperseded = !latestObservedUpdatedAtRef.current ||
|
|
453
|
+
acknowledgedLocalSnapshot.updatedAt >
|
|
454
|
+
latestObservedUpdatedAtRef.current ||
|
|
455
|
+
(acknowledgedLocalSnapshot.updatedAt ===
|
|
456
|
+
latestObservedUpdatedAtRef.current &&
|
|
457
|
+
(latestObservedRevisionRef.current ===
|
|
458
|
+
acknowledgedLocalSnapshot.revision ||
|
|
459
|
+
acknowledgementRevisionOrder === undefined ||
|
|
460
|
+
acknowledgementRevisionOrder === null ||
|
|
461
|
+
acknowledgementRevisionOrder >= 0));
|
|
462
|
+
if (acknowledgementIsNewestAccepted && acknowledgementIsNotSuperseded) {
|
|
463
|
+
acknowledgedLocalSnapshotRef.current = acknowledgedLocalSnapshot;
|
|
464
|
+
const existingRollback = acknowledgementBaseRollbackRef.current;
|
|
465
|
+
if (existingRollback?.acknowledgementRevision !==
|
|
466
|
+
acknowledgedLocalSnapshot.revision ||
|
|
467
|
+
existingRollback.updatedAt !== acknowledgedLocalSnapshot.updatedAt) {
|
|
468
|
+
acknowledgementBaseRollbackRef.current = {
|
|
469
|
+
acknowledgementRevision: acknowledgedLocalSnapshot.revision,
|
|
470
|
+
updatedAt: acknowledgedLocalSnapshot.updatedAt,
|
|
471
|
+
base: authoritativeBaseRef.current,
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
authoritativeBaseRef.current = {
|
|
475
|
+
value: acknowledgedLocalSnapshot.value,
|
|
476
|
+
revision: acknowledgedLocalSnapshot.revision,
|
|
477
|
+
};
|
|
478
|
+
if (acknowledgedLocalSnapshot.updatedAt ===
|
|
479
|
+
latestObservedUpdatedAtRef.current &&
|
|
480
|
+
acknowledgementRevisionOrder !== undefined &&
|
|
481
|
+
acknowledgementRevisionOrder !== null &&
|
|
482
|
+
acknowledgementRevisionOrder > 0) {
|
|
483
|
+
latestObservedRevisionRef.current =
|
|
484
|
+
acknowledgedLocalSnapshot.revision;
|
|
485
|
+
}
|
|
486
|
+
if (!lastAppliedUpdatedAtRef.current ||
|
|
487
|
+
acknowledgedLocalSnapshot.updatedAt >
|
|
488
|
+
lastAppliedUpdatedAtRef.current) {
|
|
489
|
+
lastAppliedUpdatedAtRef.current =
|
|
490
|
+
acknowledgedLocalSnapshot.updatedAt;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (contentRevision === acknowledgedLocalSnapshot.revision &&
|
|
494
|
+
value === acknowledgedLocalSnapshot.value) {
|
|
495
|
+
rejectedMatchingAcknowledgement = true;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (rejectedMatchingAcknowledgement)
|
|
499
|
+
return;
|
|
500
|
+
const acknowledged = acknowledgedLocalSnapshotRef.current;
|
|
501
|
+
if (acknowledged &&
|
|
502
|
+
contentRevision === acknowledged.revision &&
|
|
503
|
+
value === acknowledged.value) {
|
|
504
|
+
const acknowledgementWasSuperseded = latestObservedUpdatedAtRef.current !== null &&
|
|
505
|
+
(acknowledged.updatedAt < latestObservedUpdatedAtRef.current ||
|
|
506
|
+
(acknowledged.updatedAt === latestObservedUpdatedAtRef.current &&
|
|
507
|
+
latestObservedRevisionRef.current !== acknowledged.revision));
|
|
508
|
+
if (!acknowledgementWasSuperseded) {
|
|
509
|
+
authoritativeBaseRef.current = {
|
|
510
|
+
value: acknowledged.value,
|
|
511
|
+
revision: acknowledged.revision,
|
|
512
|
+
};
|
|
513
|
+
if (!lastAppliedUpdatedAtRef.current ||
|
|
514
|
+
acknowledged.updatedAt > lastAppliedUpdatedAtRef.current) {
|
|
515
|
+
lastAppliedUpdatedAtRef.current = acknowledged.updatedAt;
|
|
516
|
+
}
|
|
517
|
+
reportedConflictRevisionRef.current = null;
|
|
518
|
+
}
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (acknowledged &&
|
|
522
|
+
contentUpdatedAt &&
|
|
523
|
+
contentUpdatedAt < acknowledged.updatedAt) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (collab && !collabSynced) {
|
|
527
|
+
retry = setTimeout(() => apply(deferred), 300);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (collab && !seededRef.current) {
|
|
531
|
+
retry = setTimeout(() => apply(deferred), 25);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (collab && emptySnapshotDecisionPendingRef.current) {
|
|
535
|
+
retry = setTimeout(() => apply(deferred), 50);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (collabBackedSnapshot ||
|
|
539
|
+
(collab && pendingCollabSnapshot?.ydoc === ydoc)) {
|
|
540
|
+
peerWait.deadline = null;
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
const currentMarkdown = callbacks.getMarkdown(editor);
|
|
544
|
+
const normalizedValue = callbacks.normalizeValue(value);
|
|
545
|
+
const editorUnchangedSinceApply = lastAppliedSerializedRef.current !== null &&
|
|
546
|
+
currentMarkdown === lastAppliedSerializedRef.current;
|
|
547
|
+
const editorFocused = callbacks.isEditorFocused(editor);
|
|
548
|
+
const typingRecently = editorFocused && Date.now() - lastTypedAtRef.current < 1500;
|
|
549
|
+
if (currentMarkdown === normalizedValue ||
|
|
550
|
+
(typingRecently &&
|
|
551
|
+
!contentRevision &&
|
|
552
|
+
(value === lastEmittedRef.current ||
|
|
553
|
+
recentEmittedRef.current.includes(value) ||
|
|
554
|
+
recentEmittedRef.current.includes(normalizedValue))) ||
|
|
555
|
+
(editorUnchangedSinceApply &&
|
|
556
|
+
(value === lastAppliedValueRef.current ||
|
|
557
|
+
normalizedValue === lastAppliedSerializedRef.current))) {
|
|
558
|
+
peerWait.deadline = null;
|
|
559
|
+
if (currentMarkdown === normalizedValue) {
|
|
560
|
+
lastAppliedValueRef.current = value;
|
|
561
|
+
lastAppliedSerializedRef.current = currentMarkdown;
|
|
562
|
+
}
|
|
563
|
+
if (contentRevision) {
|
|
564
|
+
authoritativeBaseRef.current = { value, revision: contentRevision };
|
|
565
|
+
reportedConflictRevisionRef.current = null;
|
|
566
|
+
}
|
|
567
|
+
if (contentUpdatedAt) {
|
|
568
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
569
|
+
}
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const revisionChangedAtSameTimestamp = !!contentRevision &&
|
|
573
|
+
!!authoritativeBaseRef.current &&
|
|
574
|
+
contentRevision !== authoritativeBaseRef.current.revision &&
|
|
575
|
+
!!contentUpdatedAt &&
|
|
576
|
+
contentUpdatedAt === lastAppliedUpdatedAtRef.current;
|
|
577
|
+
// A parent that derives `value` and `contentUpdatedAt` separately can
|
|
578
|
+
// render the new timestamp next to the old value first. That render
|
|
579
|
+
// marks the timestamp applied, so the new value that follows it would
|
|
580
|
+
// never be adopted.
|
|
581
|
+
const valueChangedAtSameTimestamp = !contentRevision &&
|
|
582
|
+
!!contentUpdatedAt &&
|
|
583
|
+
contentUpdatedAt === lastAppliedUpdatedAtRef.current &&
|
|
584
|
+
lastAppliedValueRef.current !== null &&
|
|
585
|
+
value !== lastAppliedValueRef.current;
|
|
586
|
+
const externalNewer = revisionChangedAtSameTimestamp ||
|
|
587
|
+
valueChangedAtSameTimestamp ||
|
|
588
|
+
!lastAppliedUpdatedAtRef.current ||
|
|
589
|
+
!contentUpdatedAt ||
|
|
590
|
+
contentUpdatedAt > lastAppliedUpdatedAtRef.current;
|
|
591
|
+
if (collab && !isLeadClient) {
|
|
592
|
+
peerWait.deadline = null;
|
|
593
|
+
if (!externalNewer) {
|
|
594
|
+
peerWait.leadDeadline = null;
|
|
595
|
+
if (contentUpdatedAt) {
|
|
596
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
597
|
+
}
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
peerWait.leadDeadline ??= Date.now() + LEAD_FAILOVER_MS;
|
|
601
|
+
const leadRemaining = peerWait.leadDeadline - Date.now();
|
|
602
|
+
if (leadRemaining > 0) {
|
|
603
|
+
retry = setTimeout(() => apply(deferred), leadRemaining);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
// A live doc that moved on since the last snapshot holds typing the
|
|
607
|
+
// snapshot predates (a peer's save lags the Yjs state); adopting it
|
|
608
|
+
// would delete that text for every peer. SQL catches up on the next save.
|
|
609
|
+
if (!editorUnchangedSinceApply) {
|
|
610
|
+
peerWait.leadDeadline = null;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (typingRecently) {
|
|
615
|
+
if (externalNewer) {
|
|
616
|
+
retry = setTimeout(() => apply(deferred), 700);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
peerWait.deadline = null;
|
|
620
|
+
}
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const hasAppliedSnapshot = lastAppliedSerializedRef.current !== null;
|
|
624
|
+
const currentIsRegisteredLocalEmission = lastRegisteredLocalEmissionRef.current !== null &&
|
|
625
|
+
currentMarkdown === lastRegisteredLocalEmissionRef.current;
|
|
626
|
+
if (!externalNewer &&
|
|
627
|
+
(editorFocused ||
|
|
628
|
+
hasAppliedSnapshot ||
|
|
629
|
+
currentIsRegisteredLocalEmission)) {
|
|
630
|
+
peerWait.deadline = null;
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
// A snapshot another writer saved can reach this tab before the Yjs
|
|
634
|
+
// updates that carry the same text (a collab poll lags the action poll,
|
|
635
|
+
// and a save's merged answer lags neither), and applying it first
|
|
636
|
+
// inserts that text a second time when they land. Only a collab-backed
|
|
637
|
+
// revision, returned above, is known to be in the Yjs doc already.
|
|
638
|
+
const snapshotKey = `${contentRevision ?? ""}@${contentUpdatedAt ?? ""}`;
|
|
639
|
+
if (collab &&
|
|
640
|
+
externalNewer &&
|
|
641
|
+
requestCollabSync &&
|
|
642
|
+
syncedBeforeAdoptRef.current !== snapshotKey) {
|
|
643
|
+
// The update a failed catch-up missed may only be late, so the
|
|
644
|
+
// catch-up retries first. Past that, adopting without it is the
|
|
645
|
+
// behavior before this step existed, so the sync degrades to it,
|
|
646
|
+
// loudly.
|
|
647
|
+
const caughtUp = (status, error) => {
|
|
648
|
+
if (status !== "synced") {
|
|
649
|
+
if (++peerWait.catchUpFailures < CATCH_UP_ATTEMPTS) {
|
|
650
|
+
if (!cancelled)
|
|
651
|
+
retry = setTimeout(() => apply(deferred), CATCH_UP_RETRY_MS);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
console.warn(`Adopting a saved snapshot without a live sync (${status})`, ...(error === undefined ? [] : [error]));
|
|
655
|
+
}
|
|
656
|
+
syncedBeforeAdoptRef.current = snapshotKey;
|
|
657
|
+
if (!cancelled)
|
|
658
|
+
apply(deferred);
|
|
659
|
+
};
|
|
660
|
+
void requestCollabSync().then((result) => caughtUp(result.status), (error) => caughtUp("failed", error));
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (collab &&
|
|
664
|
+
externalNewer &&
|
|
665
|
+
!deferred &&
|
|
666
|
+
peerCountRef.current > 0 &&
|
|
667
|
+
!(authoritativeBaseRef.current !== null &&
|
|
668
|
+
callbacks.normalizeValue(authoritativeBaseRef.current.value) ===
|
|
669
|
+
currentMarkdown &&
|
|
670
|
+
callbacks.isEditorClean?.(currentMarkdown))) {
|
|
671
|
+
peerWait.deadline ??= Date.now() + PEER_SETTLE_MS;
|
|
672
|
+
const remaining = peerWait.deadline - Date.now();
|
|
673
|
+
if (remaining > 0) {
|
|
674
|
+
retry = setTimeout(() => apply(true), remaining);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const applyTimer = setTimeout(() => {
|
|
679
|
+
if (cancelled || editor.isDestroyed)
|
|
680
|
+
return;
|
|
681
|
+
const scheduledCallbacks = reconcileCallbacksRef.current;
|
|
682
|
+
peerWait.deadline = null;
|
|
683
|
+
const beforeMarkdown = scheduledCallbacks.getMarkdown(editor);
|
|
684
|
+
const normalized = scheduledCallbacks.normalizeValue(value);
|
|
685
|
+
const unchangedSinceApply = lastAppliedSerializedRef.current !== null &&
|
|
686
|
+
beforeMarkdown === lastAppliedSerializedRef.current;
|
|
687
|
+
if (beforeMarkdown === normalized ||
|
|
688
|
+
(unchangedSinceApply &&
|
|
689
|
+
normalized === lastAppliedSerializedRef.current)) {
|
|
690
|
+
lastAppliedValueRef.current = value;
|
|
691
|
+
lastAppliedSerializedRef.current = beforeMarkdown;
|
|
692
|
+
if (contentRevision) {
|
|
693
|
+
authoritativeBaseRef.current = { value, revision: contentRevision };
|
|
694
|
+
reportedConflictRevisionRef.current = null;
|
|
695
|
+
}
|
|
696
|
+
if (contentUpdatedAt) {
|
|
697
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
698
|
+
}
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
isSettingContentRef.current = true;
|
|
702
|
+
const authoritativeBase = authoritativeBaseRef.current;
|
|
703
|
+
if (contentRevision &&
|
|
704
|
+
scheduledCallbacks.onBaseAwareReconcile &&
|
|
705
|
+
authoritativeBase &&
|
|
706
|
+
authoritativeBase.revision !== contentRevision) {
|
|
707
|
+
const parse = scheduledCallbacks.parseValue === false
|
|
708
|
+
? null
|
|
709
|
+
: (scheduledCallbacks.parseValue ?? defaultParseValue);
|
|
710
|
+
const baseDoc = parse?.(editor, authoritativeBase.value) ?? null;
|
|
711
|
+
const serverDoc = parse?.(editor, value) ?? null;
|
|
712
|
+
if (!baseDoc || !serverDoc) {
|
|
713
|
+
isSettingContentRef.current = false;
|
|
714
|
+
if (reportedConflictRevisionRef.current !== contentRevision) {
|
|
715
|
+
reportedConflictRevisionRef.current = contentRevision;
|
|
716
|
+
scheduledCallbacks.onBaseAwareReconcile({
|
|
717
|
+
status: "failed",
|
|
718
|
+
content: beforeMarkdown,
|
|
719
|
+
serverContent: value,
|
|
720
|
+
baseRevision: authoritativeBase.revision,
|
|
721
|
+
serverRevision: contentRevision,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const reconciled = reconcileDocAgainstBase(editor, baseDoc, serverDoc, { overlapPolicy });
|
|
727
|
+
if (reconciled.status === "conflict" ||
|
|
728
|
+
reconciled.status === "failed") {
|
|
729
|
+
isSettingContentRef.current = false;
|
|
730
|
+
if (reportedConflictRevisionRef.current !== contentRevision) {
|
|
731
|
+
reportedConflictRevisionRef.current = contentRevision;
|
|
732
|
+
scheduledCallbacks.onBaseAwareReconcile({
|
|
733
|
+
status: reconciled.status,
|
|
734
|
+
content: beforeMarkdown,
|
|
735
|
+
serverContent: value,
|
|
736
|
+
baseRevision: authoritativeBase.revision,
|
|
737
|
+
serverRevision: contentRevision,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const merged = scheduledCallbacks.getMarkdown(editor);
|
|
743
|
+
isSettingContentRef.current = false;
|
|
744
|
+
authoritativeBaseRef.current = { value, revision: contentRevision };
|
|
745
|
+
reportedConflictRevisionRef.current = null;
|
|
746
|
+
lastEmittedRef.current = merged;
|
|
747
|
+
pushEmittedRing(recentEmittedRef.current, merged);
|
|
748
|
+
lastAppliedValueRef.current = value;
|
|
749
|
+
lastAppliedSerializedRef.current = merged;
|
|
750
|
+
if (contentUpdatedAt)
|
|
751
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
752
|
+
if (merged !== beforeMarkdown)
|
|
753
|
+
scheduledCallbacks.onRemoteSnapshotChange?.(merged);
|
|
754
|
+
if (merged !== normalized) {
|
|
755
|
+
scheduledCallbacks.onBaseAwareReconcile({
|
|
756
|
+
status: "merged",
|
|
757
|
+
content: merged,
|
|
758
|
+
serverContent: value,
|
|
759
|
+
baseRevision: authoritativeBase.revision,
|
|
760
|
+
serverRevision: contentRevision,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
let appliedSurgically = false;
|
|
766
|
+
if (scheduledCallbacks.parseValue !== false) {
|
|
767
|
+
const parse = scheduledCallbacks.parseValue ?? defaultParseValue;
|
|
768
|
+
const parsedDoc = parse(editor, value);
|
|
769
|
+
if (parsedDoc) {
|
|
770
|
+
const result = applyDocSurgically(editor, parsedDoc);
|
|
771
|
+
appliedSurgically = result === "applied" || result === "noop";
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
if (!appliedSurgically) {
|
|
775
|
+
scheduledCallbacks.setContent(editor, value, {
|
|
776
|
+
emitUpdate: false,
|
|
777
|
+
addToHistory: false,
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
isSettingContentRef.current = false;
|
|
781
|
+
const serialized = scheduledCallbacks.getMarkdown(editor);
|
|
782
|
+
lastEmittedRef.current = serialized;
|
|
783
|
+
pushEmittedRing(recentEmittedRef.current, serialized);
|
|
784
|
+
lastAppliedValueRef.current = value;
|
|
785
|
+
lastAppliedSerializedRef.current = serialized;
|
|
786
|
+
if (contentRevision) {
|
|
787
|
+
authoritativeBaseRef.current = { value, revision: contentRevision };
|
|
788
|
+
reportedConflictRevisionRef.current = null;
|
|
789
|
+
}
|
|
790
|
+
if (contentUpdatedAt) {
|
|
791
|
+
lastAppliedUpdatedAtRef.current = contentUpdatedAt;
|
|
792
|
+
}
|
|
793
|
+
if (serialized !== beforeMarkdown) {
|
|
794
|
+
scheduledCallbacks.onRemoteSnapshotChange?.(serialized);
|
|
795
|
+
}
|
|
796
|
+
}, 0);
|
|
797
|
+
retry = applyTimer;
|
|
798
|
+
};
|
|
799
|
+
apply();
|
|
800
|
+
return () => {
|
|
801
|
+
cancelled = true;
|
|
802
|
+
if (retry)
|
|
803
|
+
clearTimeout(retry);
|
|
804
|
+
};
|
|
805
|
+
}, [
|
|
806
|
+
contentUpdatedAt,
|
|
807
|
+
contentRevision,
|
|
808
|
+
compareContentRevisions,
|
|
809
|
+
acknowledgedLocalSnapshot,
|
|
810
|
+
editor,
|
|
811
|
+
ydoc,
|
|
812
|
+
editable,
|
|
813
|
+
value,
|
|
814
|
+
collab,
|
|
815
|
+
collabSynced,
|
|
816
|
+
isLeadClient,
|
|
817
|
+
overlapPolicy,
|
|
818
|
+
collabBackedSnapshot,
|
|
819
|
+
pendingCollabSnapshot,
|
|
820
|
+
requestCollabSync,
|
|
821
|
+
]);
|
|
822
|
+
const shouldIgnoreUpdate = (transaction) => {
|
|
823
|
+
if (!editable || isSettingContentRef.current)
|
|
824
|
+
return true;
|
|
825
|
+
if (collab && !seededRef.current) {
|
|
826
|
+
const firstSyncedEmptyUserEdit = collabSynced &&
|
|
827
|
+
!value.trim() &&
|
|
828
|
+
transaction.docChanged &&
|
|
829
|
+
Boolean(transaction.getMeta("uiEvent")) &&
|
|
830
|
+
!isChangeOrigin(transaction);
|
|
831
|
+
if (!firstSyncedEmptyUserEdit)
|
|
832
|
+
return true;
|
|
833
|
+
seededRef.current = true;
|
|
834
|
+
}
|
|
835
|
+
if (transaction.getMeta(RICH_MARKDOWN_PROGRAMMATIC_TRANSACTION)) {
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
if (collab && transaction && isRemoteCollaborativeTransaction(transaction))
|
|
839
|
+
return true;
|
|
840
|
+
lastTypedAtRef.current = Date.now();
|
|
841
|
+
return false;
|
|
842
|
+
};
|
|
843
|
+
const reportRemoteUpdate = (transaction) => {
|
|
844
|
+
if (!collab ||
|
|
845
|
+
!collabSynced ||
|
|
846
|
+
!seededRef.current ||
|
|
847
|
+
!editor ||
|
|
848
|
+
editor.isDestroyed ||
|
|
849
|
+
isSettingContentRef.current ||
|
|
850
|
+
!transaction.docChanged ||
|
|
851
|
+
!isChangeOrigin(transaction) ||
|
|
852
|
+
transaction.getMeta(ySyncPluginKey)?.isUndoRedoOperation) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
onRemoteSnapshotChange?.(getMarkdown(editor));
|
|
856
|
+
};
|
|
857
|
+
const registerEmitted = (markdown) => {
|
|
858
|
+
if (collab && !markdown.trim())
|
|
859
|
+
return false;
|
|
860
|
+
lastEmittedRef.current = markdown;
|
|
861
|
+
pushEmittedRing(recentEmittedRef.current, markdown);
|
|
862
|
+
lastRegisteredLocalEmissionRef.current = markdown;
|
|
863
|
+
return true;
|
|
864
|
+
};
|
|
865
|
+
return {
|
|
866
|
+
collab,
|
|
867
|
+
initialSeedFailed,
|
|
868
|
+
initialSeedPending: Boolean(requestInitialSeed) && collab && !seeded,
|
|
869
|
+
retryInitialSeed: () => {
|
|
870
|
+
setInitialSeedFailed(false);
|
|
871
|
+
setInitialSeedRetry((retry) => retry + 1);
|
|
872
|
+
},
|
|
873
|
+
isSettingContentRef,
|
|
874
|
+
shouldIgnoreUpdate,
|
|
875
|
+
reportRemoteUpdate,
|
|
876
|
+
registerEmitted,
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
//# sourceMappingURL=useCollabReconcile.js.map
|