@asanchez-sa/abby 0.0.0-stage → 0.1.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/README.md +245 -2
- package/dist/_virtual/_rolldown/runtime.js +26 -0
- package/dist/agents/approvals.d.ts +46 -0
- package/dist/agents/approvals.js +58 -0
- package/dist/agents/changes.d.ts +21 -0
- package/dist/agents/changes.js +21 -0
- package/dist/agents/hooks.d.ts +20 -0
- package/dist/agents/hooks.js +58 -0
- package/dist/agents/index.d.ts +11 -0
- package/dist/agents/index.js +9 -0
- package/dist/agents/run-tool.d.ts +44 -0
- package/dist/agents/run-tool.js +79 -0
- package/dist/agents/ui-sdk.d.ts +5 -0
- package/dist/agents/ui-sdk.js +3 -0
- package/dist/behaviors/canvas/index.d.ts +2 -0
- package/dist/behaviors/canvas/index.js +1 -0
- package/dist/behaviors/canvas/ui-sdk.d.ts +2 -0
- package/dist/behaviors/canvas/ui-sdk.js +1 -0
- package/dist/behaviors/drag-and-drop/index.d.ts +2 -0
- package/dist/behaviors/drag-and-drop/index.js +1 -0
- package/dist/behaviors/drag-and-drop/ui-sdk.d.ts +2 -0
- package/dist/behaviors/drag-and-drop/ui-sdk.js +1 -0
- package/dist/behaviors/dragging/index.d.ts +2 -0
- package/dist/behaviors/dragging/index.js +1 -0
- package/dist/behaviors/dragging/ui-sdk.d.ts +2 -0
- package/dist/behaviors/dragging/ui-sdk.js +1 -0
- package/dist/behaviors/focus/index.d.ts +2 -0
- package/dist/behaviors/focus/index.js +1 -0
- package/dist/behaviors/focus/ui-sdk.d.ts +2 -0
- package/dist/behaviors/focus/ui-sdk.js +1 -0
- package/dist/behaviors/lists/index.d.ts +3 -0
- package/dist/behaviors/lists/index.js +3 -0
- package/dist/behaviors/lists/ui-sdk.d.ts +3 -0
- package/dist/behaviors/lists/ui-sdk.js +3 -0
- package/dist/behaviors/popups/index.d.ts +3 -0
- package/dist/behaviors/popups/index.js +3 -0
- package/dist/behaviors/popups/ui-sdk.d.ts +3 -0
- package/dist/behaviors/popups/ui-sdk.js +3 -0
- package/dist/behaviors/preferences/index.d.ts +3 -0
- package/dist/behaviors/preferences/index.js +3 -0
- package/dist/behaviors/preferences/ui-sdk.d.ts +3 -0
- package/dist/behaviors/preferences/ui-sdk.js +3 -0
- package/dist/behaviors/selection/index.d.ts +3 -0
- package/dist/behaviors/selection/index.js +3 -0
- package/dist/behaviors/selection/indicator.d.ts +13 -0
- package/dist/behaviors/selection/indicator.js +20 -0
- package/dist/behaviors/selection/ui-sdk.d.ts +2 -0
- package/dist/behaviors/selection/ui-sdk.js +1 -0
- package/dist/behaviors/transitions/index.d.ts +3 -0
- package/dist/behaviors/transitions/index.js +3 -0
- package/dist/behaviors/transitions/ui-sdk.d.ts +3 -0
- package/dist/behaviors/transitions/ui-sdk.js +3 -0
- package/dist/behaviors/trees/index.d.ts +2 -0
- package/dist/behaviors/trees/index.js +1 -0
- package/dist/behaviors/trees/ui-sdk.d.ts +2 -0
- package/dist/behaviors/trees/ui-sdk.js +1 -0
- package/dist/components/accordion/accordion.d.ts +13 -0
- package/dist/components/accordion/accordion.js +165 -0
- package/dist/components/alert/alert.d.ts +13 -0
- package/dist/components/alert/alert.js +131 -0
- package/dist/components/alert-dialog/alert-dialog.d.ts +15 -0
- package/dist/components/alert-dialog/alert-dialog.js +257 -0
- package/dist/components/aspect-ratio/aspect-ratio.d.ts +7 -0
- package/dist/components/aspect-ratio/aspect-ratio.js +57 -0
- package/dist/components/attachment/attachment.d.ts +48 -0
- package/dist/components/attachment/attachment.js +372 -0
- package/dist/components/autocomplete/autocomplete.d.ts +32 -0
- package/dist/components/autocomplete/autocomplete.js +466 -0
- package/dist/components/avatar/avatar.d.ts +6 -0
- package/dist/components/avatar/avatar.js +100 -0
- package/dist/components/avatar-group/avatar-group.d.ts +9 -0
- package/dist/components/avatar-group/avatar-group.js +75 -0
- package/dist/components/badge/badge.d.ts +15 -0
- package/dist/components/badge/badge.js +31 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +24 -0
- package/dist/components/breadcrumb/breadcrumb.js +279 -0
- package/dist/components/bubble/bubble.d.ts +26 -0
- package/dist/components/bubble/bubble.js +173 -0
- package/dist/components/button/button.d.ts +18 -0
- package/dist/components/button/button.js +91 -0
- package/dist/components/button-group/button-group.d.ts +15 -0
- package/dist/components/button-group/button-group.js +71 -0
- package/dist/components/calendar/calendar.d.ts +29 -0
- package/dist/components/calendar/calendar.js +453 -0
- package/dist/components/card/card.d.ts +14 -0
- package/dist/components/card/card.js +213 -0
- package/dist/components/carousel/carousel.d.ts +16 -0
- package/dist/components/carousel/carousel.js +364 -0
- package/dist/components/chain-of-thought/chain-of-thought.d.ts +72 -0
- package/dist/components/chain-of-thought/chain-of-thought.js +491 -0
- package/dist/components/chat/chat.d.ts +48 -0
- package/dist/components/chat/chat.js +207 -0
- package/dist/components/checkbox/checkbox.d.ts +10 -0
- package/dist/components/checkbox/checkbox.js +118 -0
- package/dist/components/checkpoint/checkpoint.d.ts +24 -0
- package/dist/components/checkpoint/checkpoint.js +178 -0
- package/dist/components/choice-cards/choice-cards.d.ts +38 -0
- package/dist/components/choice-cards/choice-cards.js +255 -0
- package/dist/components/code-block/code-block.d.ts +58 -0
- package/dist/components/code-block/code-block.js +506 -0
- package/dist/components/code-block/highlighter.js +96 -0
- package/dist/components/code-block/use-highlighted-code.d.ts +11 -0
- package/dist/components/code-block/use-highlighted-code.js +54 -0
- package/dist/components/collapsible/collapsible.d.ts +10 -0
- package/dist/components/collapsible/collapsible.js +92 -0
- package/dist/components/color-picker/color-picker.d.ts +17 -0
- package/dist/components/color-picker/color-picker.js +395 -0
- package/dist/components/combobox/combobox.d.ts +54 -0
- package/dist/components/combobox/combobox.js +683 -0
- package/dist/components/command/command.d.ts +23 -0
- package/dist/components/command/command.js +373 -0
- package/dist/components/command-dock/command-dock.d.ts +118 -0
- package/dist/components/command-dock/command-dock.js +944 -0
- package/dist/components/confirmation/confirmation.d.ts +58 -0
- package/dist/components/confirmation/confirmation.js +181 -0
- package/dist/components/context/context.d.ts +82 -0
- package/dist/components/context/context.js +490 -0
- package/dist/components/date-input/date-input.d.ts +16 -0
- package/dist/components/date-input/date-input.js +89 -0
- package/dist/components/date-picker/date-picker.d.ts +28 -0
- package/dist/components/date-picker/date-picker.js +361 -0
- package/dist/components/dialog/dialog.d.ts +14 -0
- package/dist/components/dialog/dialog.js +261 -0
- package/dist/components/drawer/drawer.d.ts +16 -0
- package/dist/components/drawer/drawer.js +309 -0
- package/dist/components/empty/empty.d.ts +18 -0
- package/dist/components/empty/empty.js +192 -0
- package/dist/components/field/field.d.ts +15 -0
- package/dist/components/field/field.js +261 -0
- package/dist/components/file-input/file-input.d.ts +12 -0
- package/dist/components/file-input/file-input.js +216 -0
- package/dist/components/file-tree/file-tree.d.ts +45 -0
- package/dist/components/file-tree/file-tree.js +283 -0
- package/dist/components/hover-card/hover-card.d.ts +10 -0
- package/dist/components/hover-card/hover-card.js +118 -0
- package/dist/components/icon/icon.d.ts +14 -0
- package/dist/components/icon/icon.js +60 -0
- package/dist/components/image-cropper/image-cropper.d.ts +15 -0
- package/dist/components/image-cropper/image-cropper.js +334 -0
- package/dist/components/inline-citation/inline-citation.d.ts +46 -0
- package/dist/components/inline-citation/inline-citation.js +269 -0
- package/dist/components/input/input.d.ts +9 -0
- package/dist/components/input/input.js +43 -0
- package/dist/components/input-group/input-group.d.ts +42 -0
- package/dist/components/input-group/input-group.js +192 -0
- package/dist/components/item/item.d.ts +32 -0
- package/dist/components/item/item.js +394 -0
- package/dist/components/kbd/kbd.d.ts +9 -0
- package/dist/components/kbd/kbd.js +75 -0
- package/dist/components/label/label.d.ts +6 -0
- package/dist/components/label/label.js +40 -0
- package/dist/components/link/link.d.ts +21 -0
- package/dist/components/link/link.js +126 -0
- package/dist/components/listbox/listbox.d.ts +20 -0
- package/dist/components/listbox/listbox.js +199 -0
- package/dist/components/marker/marker.d.ts +11 -0
- package/dist/components/marker/marker.js +88 -0
- package/dist/components/menu/menu.d.ts +38 -0
- package/dist/components/menu/menu.js +553 -0
- package/dist/components/menubar/menubar.d.ts +9 -0
- package/dist/components/menubar/menubar.js +47 -0
- package/dist/components/message/message.d.ts +44 -0
- package/dist/components/message/message.js +328 -0
- package/dist/components/message-scroller/message-scroller.d.ts +111 -0
- package/dist/components/message-scroller/message-scroller.js +957 -0
- package/dist/components/meter/meter.d.ts +8 -0
- package/dist/components/meter/meter.js +162 -0
- package/dist/components/model-selector/model-selector.d.ts +155 -0
- package/dist/components/model-selector/model-selector.js +905 -0
- package/dist/components/native-select/native-select.d.ts +27 -0
- package/dist/components/native-select/native-select.js +226 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts +29 -0
- package/dist/components/navigation-menu/navigation-menu.js +318 -0
- package/dist/components/not-label.js +9 -0
- package/dist/components/note-editor/blocks.d.ts +22 -0
- package/dist/components/note-editor/blocks.js +245 -0
- package/dist/components/note-editor/diff.d.ts +19 -0
- package/dist/components/note-editor/diff.js +64 -0
- package/dist/components/note-editor/editor.js +249 -0
- package/dist/components/note-editor/note-editor.d.ts +109 -0
- package/dist/components/note-editor/note-editor.js +954 -0
- package/dist/components/note-editor/parts/comments.d.ts +24 -0
- package/dist/components/note-editor/parts/comments.js +337 -0
- package/dist/components/note-editor/parts/header.d.ts +25 -0
- package/dist/components/note-editor/parts/header.js +263 -0
- package/dist/components/note-editor/parts/history.d.ts +56 -0
- package/dist/components/note-editor/parts/history.js +409 -0
- package/dist/components/note-editor/parts/presence.d.ts +31 -0
- package/dist/components/note-editor/parts/presence.js +140 -0
- package/dist/components/note-editor/parts/suggestions.d.ts +45 -0
- package/dist/components/note-editor/parts/suggestions.js +316 -0
- package/dist/components/note-editor/parts/toolbar.d.ts +38 -0
- package/dist/components/note-editor/parts/toolbar.js +687 -0
- package/dist/components/note-editor/people.d.ts +84 -0
- package/dist/components/note-editor/people.js +276 -0
- package/dist/components/note-editor/person.d.ts +11 -0
- package/dist/components/note-editor/person.js +15 -0
- package/dist/components/note-place/note-place.d.ts +42 -0
- package/dist/components/note-place/note-place.js +256 -0
- package/dist/components/note-status/note-status.d.ts +59 -0
- package/dist/components/note-status/note-status.js +380 -0
- package/dist/components/number-input/number-input.d.ts +12 -0
- package/dist/components/number-input/number-input.js +252 -0
- package/dist/components/otp-input/otp-input.d.ts +12 -0
- package/dist/components/otp-input/otp-input.js +136 -0
- package/dist/components/pagination/pagination.d.ts +23 -0
- package/dist/components/pagination/pagination.js +218 -0
- package/dist/components/password-input/password-input.d.ts +11 -0
- package/dist/components/password-input/password-input.js +117 -0
- package/dist/components/plan/plan.d.ts +51 -0
- package/dist/components/plan/plan.js +320 -0
- package/dist/components/popover/popover.d.ts +16 -0
- package/dist/components/popover/popover.js +268 -0
- package/dist/components/preferences/preferences.d.ts +5 -0
- package/dist/components/preferences/preferences.js +18 -0
- package/dist/components/progress/progress.d.ts +8 -0
- package/dist/components/progress/progress.js +162 -0
- package/dist/components/prompt-input/prompt-input.d.ts +247 -0
- package/dist/components/prompt-input/prompt-input.js +1367 -0
- package/dist/components/questionnaire/questionnaire.d.ts +174 -0
- package/dist/components/questionnaire/questionnaire.js +1628 -0
- package/dist/components/queue/queue.d.ts +82 -0
- package/dist/components/queue/queue.js +471 -0
- package/dist/components/radio/radio.d.ts +7 -0
- package/dist/components/radio/radio.js +101 -0
- package/dist/components/rating/rating.d.ts +10 -0
- package/dist/components/rating/rating.js +95 -0
- package/dist/components/reasoning/reasoning.d.ts +50 -0
- package/dist/components/reasoning/reasoning.js +233 -0
- package/dist/components/resizable/resizable.d.ts +6 -0
- package/dist/components/resizable/resizable.js +100 -0
- package/dist/components/scroll-area/scroll-area.d.ts +17 -0
- package/dist/components/scroll-area/scroll-area.js +211 -0
- package/dist/components/segmented-control/segmented-control.d.ts +16 -0
- package/dist/components/segmented-control/segmented-control.js +142 -0
- package/dist/components/select/select.d.ts +43 -0
- package/dist/components/select/select.js +577 -0
- package/dist/components/separator/separator.d.ts +4 -0
- package/dist/components/separator/separator.js +38 -0
- package/dist/components/sheet/sheet.d.ts +24 -0
- package/dist/components/sheet/sheet.js +330 -0
- package/dist/components/sidebar/sidebar.d.ts +138 -0
- package/dist/components/sidebar/sidebar.js +1374 -0
- package/dist/components/skeleton/skeleton.d.ts +4 -0
- package/dist/components/skeleton/skeleton.js +40 -0
- package/dist/components/slider/slider.d.ts +9 -0
- package/dist/components/slider/slider.js +193 -0
- package/dist/components/sources/sources.d.ts +35 -0
- package/dist/components/sources/sources.js +209 -0
- package/dist/components/spinner/spinner.d.ts +11 -0
- package/dist/components/spinner/spinner.js +59 -0
- package/dist/components/stack-trace/parse-stack-trace.d.ts +21 -0
- package/dist/components/stack-trace/parse-stack-trace.js +61 -0
- package/dist/components/stack-trace/stack-trace.d.ts +79 -0
- package/dist/components/stack-trace/stack-trace.js +434 -0
- package/dist/components/subagent/subagent.d.ts +71 -0
- package/dist/components/subagent/subagent.js +450 -0
- package/dist/components/suggestion/suggestion.d.ts +21 -0
- package/dist/components/suggestion/suggestion.js +130 -0
- package/dist/components/switch/switch.d.ts +6 -0
- package/dist/components/switch/switch.js +70 -0
- package/dist/components/table/table.d.ts +19 -0
- package/dist/components/table/table.js +284 -0
- package/dist/components/table-of-contents/spy.js +84 -0
- package/dist/components/table-of-contents/table-of-contents.d.ts +92 -0
- package/dist/components/table-of-contents/table-of-contents.js +787 -0
- package/dist/components/tabs/tabs.d.ts +25 -0
- package/dist/components/tabs/tabs.js +273 -0
- package/dist/components/task/task.d.ts +40 -0
- package/dist/components/task/task.js +262 -0
- package/dist/components/terminal/terminal.d.ts +82 -0
- package/dist/components/terminal/terminal.js +457 -0
- package/dist/components/test-results/test-results.d.ts +127 -0
- package/dist/components/test-results/test-results.js +687 -0
- package/dist/components/textarea/textarea.d.ts +8 -0
- package/dist/components/textarea/textarea.js +43 -0
- package/dist/components/time-input/time-input.d.ts +7 -0
- package/dist/components/time-input/time-input.js +82 -0
- package/dist/components/timeline/timeline.d.ts +19 -0
- package/dist/components/timeline/timeline.js +247 -0
- package/dist/components/toast/toast.d.ts +12 -0
- package/dist/components/toast/toast.js +285 -0
- package/dist/components/toggle/toggle.d.ts +15 -0
- package/dist/components/toggle/toggle.js +137 -0
- package/dist/components/token-input/token-input.d.ts +7 -0
- package/dist/components/token-input/token-input.js +117 -0
- package/dist/components/tool/tool.d.ts +66 -0
- package/dist/components/tool/tool.js +413 -0
- package/dist/components/toolbar/toolbar.d.ts +91 -0
- package/dist/components/toolbar/toolbar.js +655 -0
- package/dist/components/tooltip/tooltip.d.ts +8 -0
- package/dist/components/tooltip/tooltip.js +97 -0
- package/dist/components/trace/trace.d.ts +31 -0
- package/dist/components/trace/trace.js +309 -0
- package/dist/components/tree/tree.d.ts +13 -0
- package/dist/components/tree/tree.js +258 -0
- package/dist/components/trigger-menu/trigger-menu.d.ts +30 -0
- package/dist/components/trigger-menu/trigger-menu.js +352 -0
- package/dist/components/usage/usage.d.ts +132 -0
- package/dist/components/usage/usage.js +1368 -0
- package/dist/components/waterfall/waterfall.d.ts +20 -0
- package/dist/components/waterfall/waterfall.js +360 -0
- package/dist/components/week-strip/week-strip.d.ts +177 -0
- package/dist/components/week-strip/week-strip.js +1081 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +27 -0
- package/dist/core/ui-sdk.d.ts +3 -0
- package/dist/core/ui-sdk.js +3 -0
- package/dist/core/use-primitive-state.d.ts +14 -0
- package/dist/core/use-primitive-state.js +25 -0
- package/dist/styles/LICENSE-shadcn.md +21 -0
- package/dist/styles/color-scheme.css +32 -0
- package/dist/styles/components.css +303 -0
- package/dist/styles/index.css +41 -0
- package/dist/styles/tokens.css +474 -0
- package/dist/styles/typeset/shadcn.css +506 -0
- package/dist/styles/typeset.css +70 -0
- package/dist/styles/utilities.css +555 -0
- package/dist/tools/observe/index.d.ts +2 -0
- package/dist/tools/observe/index.js +3 -0
- package/dist/tools/observe/ui-sdk.d.ts +1 -0
- package/dist/tools/observe/ui-sdk.js +2 -0
- package/dist/tools/testing/check-agent.d.ts +28 -0
- package/dist/tools/testing/check-agent.js +42 -0
- package/dist/tools/testing/index.d.ts +4 -0
- package/dist/tools/testing/index.js +4 -0
- package/dist/tools/testing/ui-sdk.d.ts +1 -0
- package/dist/tools/testing/ui-sdk.js +2 -0
- package/dist/utilities/cn/index.d.ts +12 -0
- package/dist/utilities/cn/index.js +47 -0
- package/dist/utilities/color/index.d.ts +2 -0
- package/dist/utilities/color/index.js +3 -0
- package/dist/utilities/color/ui-sdk.d.ts +1 -0
- package/dist/utilities/color/ui-sdk.js +2 -0
- package/dist/utilities/date/index.d.ts +2 -0
- package/dist/utilities/date/index.js +6 -0
- package/dist/utilities/date/ui-sdk.d.ts +1 -0
- package/dist/utilities/date/ui-sdk.js +2 -0
- package/dist/utilities/image/index.d.ts +2 -0
- package/dist/utilities/image/index.js +3 -0
- package/dist/utilities/image/ui-sdk.d.ts +1 -0
- package/dist/utilities/image/ui-sdk.js +2 -0
- package/dist/utilities/mobile/index.d.ts +2 -0
- package/dist/utilities/mobile/index.js +1 -0
- package/dist/utilities/mobile/ui-sdk.d.ts +2 -0
- package/dist/utilities/mobile/ui-sdk.js +1 -0
- package/dist/utilities/number/index.d.ts +2 -0
- package/dist/utilities/number/index.js +3 -0
- package/dist/utilities/number/ui-sdk.d.ts +1 -0
- package/dist/utilities/number/ui-sdk.js +2 -0
- package/dist/utilities/platform/index.d.ts +3 -0
- package/dist/utilities/platform/index.js +14 -0
- package/dist/utilities/platform/ui-sdk.d.ts +3 -0
- package/dist/utilities/platform/ui-sdk.js +3 -0
- package/dist/utilities/storage/index.d.ts +2 -0
- package/dist/utilities/storage/index.js +1 -0
- package/dist/utilities/storage/ui-sdk.d.ts +2 -0
- package/dist/utilities/storage/ui-sdk.js +1 -0
- package/dist/utilities/text/index.d.ts +3 -0
- package/dist/utilities/text/index.js +3 -0
- package/dist/utilities/text/ui-sdk.d.ts +3 -0
- package/dist/utilities/text/ui-sdk.js +3 -0
- package/package.json +192 -4
- package/skills/agent-ready-ui/SKILL.md +229 -0
- package/skills/blocks/SKILL.md +262 -0
- package/skills/compose-screens/SKILL.md +354 -0
- package/skills/note-editor/SKILL.md +493 -0
- package/skills/note-status/SKILL.md +295 -0
- package/skills/setup/SKILL.md +136 -0
- package/skills/theming/SKILL.md +216 -0
- package/src/blocks/notes/adapters.ts +77 -0
- package/src/blocks/notes/data.ts +508 -0
- package/src/blocks/notes/notes-block.tsx +244 -0
- package/src/blocks/notes/parts/home.tsx +219 -0
- package/src/blocks/notes/parts/no-access.tsx +84 -0
- package/src/blocks/notes/parts/note-screen.tsx +412 -0
- package/src/blocks/notes/parts/notes-sidebar.tsx +277 -0
- package/src/blocks/notes/parts/panels.tsx +393 -0
- package/src/blocks/notes/parts/place.ts +15 -0
- package/src/blocks/notes/parts/review-dialog.tsx +159 -0
- package/src/blocks/notes/parts/share.tsx +172 -0
- package/src/blocks/notes/texts.ts +135 -0
- package/src/blocks/shell/adapters.ts +69 -0
- package/src/blocks/shell/data.ts +281 -0
- package/src/blocks/shell/parts/compose.tsx +292 -0
- package/src/blocks/shell/parts/home.tsx +203 -0
- package/src/blocks/shell/parts/marks.tsx +144 -0
- package/src/blocks/shell/parts/rail.tsx +166 -0
- package/src/blocks/shell/parts/rooms-column.tsx +326 -0
- package/src/blocks/shell/shell-block.tsx +210 -0
- package/src/blocks/shell/texts.ts +80 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// src/components/note-editor/blocks.ts
|
|
2
|
+
const noteBlockTypes = [
|
|
3
|
+
"paragraph",
|
|
4
|
+
"heading-1",
|
|
5
|
+
"heading-2",
|
|
6
|
+
"heading-3",
|
|
7
|
+
"bulleted",
|
|
8
|
+
"numbered",
|
|
9
|
+
"todo",
|
|
10
|
+
"quote",
|
|
11
|
+
"code",
|
|
12
|
+
"divider"
|
|
13
|
+
];
|
|
14
|
+
const listTypes = /* @__PURE__ */ new Set([
|
|
15
|
+
"bulleted",
|
|
16
|
+
"numbered",
|
|
17
|
+
"todo"
|
|
18
|
+
]);
|
|
19
|
+
const isListBlock = (type) => listTypes.has(type);
|
|
20
|
+
const isNoteBlockType = (type) => noteBlockTypes.includes(type);
|
|
21
|
+
let counter = 0;
|
|
22
|
+
const newBlockId = () => globalThis.crypto?.randomUUID?.() ?? `block-${Date.now().toString(36)}-${(counter++).toString(36)}`;
|
|
23
|
+
function plainText(content) {
|
|
24
|
+
return (content ?? []).map((node) => node.type === "text" ? node.text ?? "" : node.type === "hardBreak" ? "\n" : plainText(node.content)).join("");
|
|
25
|
+
}
|
|
26
|
+
function idOf(node) {
|
|
27
|
+
const id = node.attrs?.id;
|
|
28
|
+
return typeof id === "string" && id ? id : newBlockId();
|
|
29
|
+
}
|
|
30
|
+
function paragraphsText(nodes, inline) {
|
|
31
|
+
return (nodes ?? []).filter((node) => node.type === "paragraph").map((node) => inline.serialize(node.content)).join("\n");
|
|
32
|
+
}
|
|
33
|
+
function listItemsToBlocks(list, depth, inline, out) {
|
|
34
|
+
const type = list.type === "orderedList" ? "numbered" : list.type === "taskList" ? "todo" : "bulleted";
|
|
35
|
+
for (const item of list.content ?? []) {
|
|
36
|
+
const children = item.content ?? [];
|
|
37
|
+
const block = {
|
|
38
|
+
id: idOf(item),
|
|
39
|
+
type,
|
|
40
|
+
text: paragraphsText(children, inline)
|
|
41
|
+
};
|
|
42
|
+
if (depth > 0) block.indent = depth;
|
|
43
|
+
if (type === "todo") block.checked = Boolean(item.attrs?.checked);
|
|
44
|
+
out.push(block);
|
|
45
|
+
for (const child of children) if (child.type === "bulletList" || child.type === "orderedList" || child.type === "taskList") listItemsToBlocks(child, depth + 1, inline, out);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Reads the editor's document as blocks. */
|
|
49
|
+
function docToBlocks(doc, inline) {
|
|
50
|
+
const blocks = [];
|
|
51
|
+
for (const node of doc.content ?? []) switch (node.type) {
|
|
52
|
+
case "paragraph":
|
|
53
|
+
blocks.push({
|
|
54
|
+
id: idOf(node),
|
|
55
|
+
type: "paragraph",
|
|
56
|
+
text: inline.serialize(node.content)
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
case "heading": {
|
|
60
|
+
const level = Math.min(Math.max(Number(node.attrs?.level) || 1, 1), 3);
|
|
61
|
+
blocks.push({
|
|
62
|
+
id: idOf(node),
|
|
63
|
+
type: `heading-${level}`,
|
|
64
|
+
text: inline.serialize(node.content)
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "blockquote":
|
|
69
|
+
blocks.push({
|
|
70
|
+
id: idOf(node),
|
|
71
|
+
type: "quote",
|
|
72
|
+
text: paragraphsText(node.content, inline)
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
case "codeBlock": {
|
|
76
|
+
const block = {
|
|
77
|
+
id: idOf(node),
|
|
78
|
+
type: "code",
|
|
79
|
+
text: plainText(node.content)
|
|
80
|
+
};
|
|
81
|
+
if (node.attrs?.language) block.language = String(node.attrs.language);
|
|
82
|
+
blocks.push(block);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case "horizontalRule":
|
|
86
|
+
blocks.push({
|
|
87
|
+
id: idOf(node),
|
|
88
|
+
type: "divider",
|
|
89
|
+
text: ""
|
|
90
|
+
});
|
|
91
|
+
break;
|
|
92
|
+
case "bulletList":
|
|
93
|
+
case "orderedList":
|
|
94
|
+
case "taskList": listItemsToBlocks(node, 0, inline, blocks);
|
|
95
|
+
}
|
|
96
|
+
return blocks;
|
|
97
|
+
}
|
|
98
|
+
function paragraphs(text, inline) {
|
|
99
|
+
const content = inline.parse(text);
|
|
100
|
+
return [content.length ? {
|
|
101
|
+
type: "paragraph",
|
|
102
|
+
content
|
|
103
|
+
} : { type: "paragraph" }];
|
|
104
|
+
}
|
|
105
|
+
function itemOf(block, inline) {
|
|
106
|
+
return block.type === "todo" ? {
|
|
107
|
+
type: "taskItem",
|
|
108
|
+
attrs: {
|
|
109
|
+
id: block.id,
|
|
110
|
+
checked: Boolean(block.checked)
|
|
111
|
+
},
|
|
112
|
+
content: paragraphs(block.text, inline)
|
|
113
|
+
} : {
|
|
114
|
+
type: "listItem",
|
|
115
|
+
attrs: { id: block.id },
|
|
116
|
+
content: paragraphs(block.text, inline)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const listNodeOf = (type) => type === "numbered" ? "orderedList" : type === "todo" ? "taskList" : "bulletList";
|
|
120
|
+
/** Builds one list from `start`, nesting deeper items under the item before them. */
|
|
121
|
+
function listFrom(blocks, start, depth, inline) {
|
|
122
|
+
const type = blocks[start].type;
|
|
123
|
+
const items = [];
|
|
124
|
+
let index = start;
|
|
125
|
+
while (index < blocks.length) {
|
|
126
|
+
const block = blocks[index];
|
|
127
|
+
const indent = block.indent ?? 0;
|
|
128
|
+
if (!isListBlock(block.type) || indent < depth) break;
|
|
129
|
+
if (indent > depth && items.length > 0) {
|
|
130
|
+
const [nested, next] = listFrom(blocks, index, indent, inline);
|
|
131
|
+
items.at(-1).content.push(nested);
|
|
132
|
+
index = next;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (block.type !== type) break;
|
|
136
|
+
items.push(itemOf(block, inline));
|
|
137
|
+
index++;
|
|
138
|
+
}
|
|
139
|
+
return [{
|
|
140
|
+
type: listNodeOf(type),
|
|
141
|
+
content: items
|
|
142
|
+
}, index];
|
|
143
|
+
}
|
|
144
|
+
/** Writes blocks as the editor's document. */
|
|
145
|
+
function blocksToDoc(blocks, inline) {
|
|
146
|
+
const content = [];
|
|
147
|
+
let index = 0;
|
|
148
|
+
while (index < blocks.length) {
|
|
149
|
+
const block = blocks[index];
|
|
150
|
+
if (isListBlock(block.type)) {
|
|
151
|
+
const [list, next] = listFrom(blocks, index, block.indent ?? 0, inline);
|
|
152
|
+
content.push(list);
|
|
153
|
+
index = next;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
switch (block.type) {
|
|
157
|
+
case "paragraph":
|
|
158
|
+
content.push({
|
|
159
|
+
...paragraphs(block.text, inline)[0],
|
|
160
|
+
attrs: { id: block.id }
|
|
161
|
+
});
|
|
162
|
+
break;
|
|
163
|
+
case "heading-1":
|
|
164
|
+
case "heading-2":
|
|
165
|
+
case "heading-3": {
|
|
166
|
+
const inner = inline.parse(block.text.replace(/\n/g, " "));
|
|
167
|
+
content.push({
|
|
168
|
+
type: "heading",
|
|
169
|
+
attrs: {
|
|
170
|
+
id: block.id,
|
|
171
|
+
level: Number(block.type.at(-1))
|
|
172
|
+
},
|
|
173
|
+
...inner.length ? { content: inner } : {}
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "quote":
|
|
178
|
+
content.push({
|
|
179
|
+
type: "blockquote",
|
|
180
|
+
attrs: { id: block.id },
|
|
181
|
+
content: paragraphs(block.text, inline)
|
|
182
|
+
});
|
|
183
|
+
break;
|
|
184
|
+
case "code":
|
|
185
|
+
content.push({
|
|
186
|
+
type: "codeBlock",
|
|
187
|
+
attrs: {
|
|
188
|
+
id: block.id,
|
|
189
|
+
language: block.language ?? null
|
|
190
|
+
},
|
|
191
|
+
...block.text ? { content: [{
|
|
192
|
+
type: "text",
|
|
193
|
+
text: block.text
|
|
194
|
+
}] } : {}
|
|
195
|
+
});
|
|
196
|
+
break;
|
|
197
|
+
case "divider": content.push({
|
|
198
|
+
type: "horizontalRule",
|
|
199
|
+
attrs: { id: block.id }
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
index++;
|
|
203
|
+
}
|
|
204
|
+
if (content.length === 0) content.push({ type: "paragraph" });
|
|
205
|
+
return {
|
|
206
|
+
type: "doc",
|
|
207
|
+
content
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function sameFields(block, input) {
|
|
211
|
+
const keys = Object.keys(block);
|
|
212
|
+
return keys.length === Object.keys(input).length && keys.every((key) => block[key] === input[key]);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Fills in what a block left out and keeps indents reachable: a list item sits
|
|
216
|
+
* at most one level under the block before it, and other blocks don't indent.
|
|
217
|
+
*/
|
|
218
|
+
function normalizeBlocks(blocks) {
|
|
219
|
+
const out = [];
|
|
220
|
+
const seen = /* @__PURE__ */ new Set();
|
|
221
|
+
for (const input of blocks) {
|
|
222
|
+
const type = input.type ?? "paragraph";
|
|
223
|
+
if (!isNoteBlockType(type)) throw new Error(`"${String(type)}" isn't a block type. Use one of: ${noteBlockTypes.join(", ")}.`);
|
|
224
|
+
let id = typeof input.id === "string" && input.id ? input.id : newBlockId();
|
|
225
|
+
if (seen.has(id)) id = newBlockId();
|
|
226
|
+
seen.add(id);
|
|
227
|
+
const block = {
|
|
228
|
+
id,
|
|
229
|
+
type,
|
|
230
|
+
text: type === "divider" ? "" : String(input.text ?? "")
|
|
231
|
+
};
|
|
232
|
+
if (isListBlock(type)) {
|
|
233
|
+
const previous = out.at(-1);
|
|
234
|
+
const ceiling = previous && isListBlock(previous.type) ? (previous.indent ?? 0) + 1 : 0;
|
|
235
|
+
const indent = Math.min(Math.max(Math.trunc(Number(input.indent) || 0), 0), ceiling);
|
|
236
|
+
if (indent > 0) block.indent = indent;
|
|
237
|
+
}
|
|
238
|
+
if (type === "todo") block.checked = Boolean(input.checked);
|
|
239
|
+
if (type === "code" && input.language) block.language = String(input.language);
|
|
240
|
+
out.push(sameFields(block, input) ? input : block);
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
const sameBlocks = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
245
|
+
export { blocksToDoc, docToBlocks, isNoteBlockType, newBlockId, normalizeBlocks, noteBlockTypes, sameBlocks };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NoteBlock, NoteBlockInput } from "./blocks.js";
|
|
2
|
+
/** How a block changed: `changed` is the new text of a block whose old text shows as `removed` before it. */
|
|
3
|
+
type NoteChange = "added" | "removed" | "changed";
|
|
4
|
+
type NoteDiff = {
|
|
5
|
+
/** Both versions in one note: every block of the newer one, with the removed ones back in place. */
|
|
6
|
+
blocks: NoteBlock[];
|
|
7
|
+
/** How each block in `blocks` changed, by id. Pass it to `NoteEditor`'s `changes`. */
|
|
8
|
+
changes: Record<string, NoteChange>;
|
|
9
|
+
/** Blocks added, the new text of changed ones included. */
|
|
10
|
+
added: number;
|
|
11
|
+
/** Blocks removed, the old text of changed ones included. */
|
|
12
|
+
removed: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Compares two versions of a note: show the result in a read-only
|
|
16
|
+
* `NoteEditor`, with `value={diff.blocks}` and `changes={diff.changes}`.
|
|
17
|
+
*/
|
|
18
|
+
declare function diffNotes(before: readonly NoteBlockInput[], after: readonly NoteBlockInput[]): NoteDiff;
|
|
19
|
+
export { type NoteChange, type NoteDiff, diffNotes };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { normalizeBlocks } from "./blocks.js";
|
|
2
|
+
// src/components/note-editor/diff.ts
|
|
3
|
+
/** The id a removed copy of a changed block takes, so it doesn't clash with the new one. */
|
|
4
|
+
const removedId = (id) => `${id}~removed`;
|
|
5
|
+
const same = (a, b) => a.type === b.type && a.text === b.text && Boolean(a.checked) === Boolean(b.checked) && (a.indent ?? 0) === (b.indent ?? 0);
|
|
6
|
+
/**
|
|
7
|
+
* Compares two versions of a note: show the result in a read-only
|
|
8
|
+
* `NoteEditor`, with `value={diff.blocks}` and `changes={diff.changes}`.
|
|
9
|
+
*/
|
|
10
|
+
function diffNotes(before, after) {
|
|
11
|
+
const old = normalizeBlocks(before);
|
|
12
|
+
const now = normalizeBlocks(after);
|
|
13
|
+
const kept = new Set(now.map((block) => block.id));
|
|
14
|
+
const oldIndex = new Map(old.map((block, index) => [block.id, index]));
|
|
15
|
+
const blocks = [];
|
|
16
|
+
const changes = {};
|
|
17
|
+
let added = 0;
|
|
18
|
+
let removed = 0;
|
|
19
|
+
let next = 0;
|
|
20
|
+
const removeUpTo = (end) => {
|
|
21
|
+
for (; next < end; next++) {
|
|
22
|
+
const block = old[next];
|
|
23
|
+
if (kept.has(block.id)) continue;
|
|
24
|
+
blocks.push(block);
|
|
25
|
+
changes[block.id] = "removed";
|
|
26
|
+
removed++;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
for (const block of now) {
|
|
30
|
+
const index = oldIndex.get(block.id);
|
|
31
|
+
if (index === void 0) {
|
|
32
|
+
blocks.push(block);
|
|
33
|
+
changes[block.id] = "added";
|
|
34
|
+
added++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (index >= next) {
|
|
38
|
+
removeUpTo(index);
|
|
39
|
+
next = index + 1;
|
|
40
|
+
}
|
|
41
|
+
const was = old[index];
|
|
42
|
+
if (same(was, block)) {
|
|
43
|
+
blocks.push(block);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const copy = {
|
|
47
|
+
...was,
|
|
48
|
+
id: removedId(was.id)
|
|
49
|
+
};
|
|
50
|
+
blocks.push(copy, block);
|
|
51
|
+
changes[copy.id] = "removed";
|
|
52
|
+
changes[block.id] = "changed";
|
|
53
|
+
removed++;
|
|
54
|
+
added++;
|
|
55
|
+
}
|
|
56
|
+
removeUpTo(old.length);
|
|
57
|
+
return {
|
|
58
|
+
blocks,
|
|
59
|
+
changes,
|
|
60
|
+
added,
|
|
61
|
+
removed
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export { diffNotes };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
3
|
+
import { closeHistory } from "@tiptap/pm/history";
|
|
4
|
+
import { ReplaceAroundStep, ReplaceStep } from "@tiptap/pm/transform";
|
|
5
|
+
// src/components/note-editor/editor.ts
|
|
6
|
+
/** Marks a transaction a person didn't make: an agent's change or a refused edit undone. */
|
|
7
|
+
const REMOTE = "abbyNoteRemote";
|
|
8
|
+
/** A hard break reads as a line break, any other inline leaf as a token, one character each. */
|
|
9
|
+
const leafText = (node) => node.type.name === "hardBreak" ? "\n" : "";
|
|
10
|
+
/** The href a mention's link carries, so the person's id survives in the block's Markdown. */
|
|
11
|
+
const mentionHref = (value) => `mention:${value}`;
|
|
12
|
+
/**
|
|
13
|
+
* Runs `change` as its own undo step: typing just before or just after it,
|
|
14
|
+
* which the history would otherwise join to it, stays a separate step.
|
|
15
|
+
*/
|
|
16
|
+
function asOneStep(editor, change) {
|
|
17
|
+
const seal = () => editor.view.dispatch(closeHistory(editor.state.tr));
|
|
18
|
+
seal();
|
|
19
|
+
const result = change();
|
|
20
|
+
seal();
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
const adapters = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
/**
|
|
25
|
+
* Lets ui-sdk's Trigger Menu read and write the editor. Text offsets are
|
|
26
|
+
* ProseMirror positions: inside a block each character is one position, and
|
|
27
|
+
* the block's start reads as a line break, so a trigger can start a block.
|
|
28
|
+
*/
|
|
29
|
+
function noteAdapter(editor) {
|
|
30
|
+
const known = adapters.get(editor);
|
|
31
|
+
if (known) return known;
|
|
32
|
+
const adapter = {
|
|
33
|
+
get element() {
|
|
34
|
+
return editor.isDestroyed ? void 0 : editor.view.dom;
|
|
35
|
+
},
|
|
36
|
+
textBefore(length) {
|
|
37
|
+
if (editor.isDestroyed) return null;
|
|
38
|
+
const { $head } = editor.state.selection;
|
|
39
|
+
if (!$head.parent.isTextblock || $head.parent.type.spec.code) return null;
|
|
40
|
+
const blockStart = $head.start();
|
|
41
|
+
const from = Math.max(blockStart, $head.pos - length);
|
|
42
|
+
const text = editor.state.doc.textBetween(from, $head.pos, "\n", leafText);
|
|
43
|
+
return from === blockStart ? {
|
|
44
|
+
text: `\n${text}`,
|
|
45
|
+
offset: from - 1
|
|
46
|
+
} : {
|
|
47
|
+
text,
|
|
48
|
+
offset: from
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
selection() {
|
|
52
|
+
if (editor.isDestroyed || !editor.isFocused) return null;
|
|
53
|
+
const { from, to } = editor.state.selection;
|
|
54
|
+
return {
|
|
55
|
+
start: from,
|
|
56
|
+
end: to
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
rectAt(offset) {
|
|
60
|
+
if (editor.isDestroyed) return null;
|
|
61
|
+
try {
|
|
62
|
+
const size = editor.state.doc.content.size;
|
|
63
|
+
const box = editor.view.coordsAtPos(Math.min(Math.max(offset, 0), size));
|
|
64
|
+
return {
|
|
65
|
+
x: box.left,
|
|
66
|
+
y: box.top,
|
|
67
|
+
width: Math.max(0, box.right - box.left),
|
|
68
|
+
height: box.bottom - box.top
|
|
69
|
+
};
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
replace(range, content) {
|
|
75
|
+
const { state } = editor;
|
|
76
|
+
const tr = state.tr;
|
|
77
|
+
let end;
|
|
78
|
+
if (typeof content === "string") {
|
|
79
|
+
tr.insertText(content, range.start, range.end);
|
|
80
|
+
end = range.start + content.length;
|
|
81
|
+
} else {
|
|
82
|
+
const link = state.schema.marks.link;
|
|
83
|
+
const marks = link ? [link.create({ href: mentionHref(content.value) })] : [];
|
|
84
|
+
tr.replaceWith(range.start, range.end, state.schema.text(content.label, marks));
|
|
85
|
+
tr.insert(range.start + content.label.length, state.schema.text(" "));
|
|
86
|
+
end = range.start + content.label.length + 1;
|
|
87
|
+
}
|
|
88
|
+
tr.setSelection(TextSelection.create(tr.doc, end)).scrollIntoView();
|
|
89
|
+
asOneStep(editor, () => editor.view.dispatch(tr));
|
|
90
|
+
},
|
|
91
|
+
subscribe(listener) {
|
|
92
|
+
const onTransaction = ({ transaction }) => {
|
|
93
|
+
if (!transaction.docChanged) {
|
|
94
|
+
if (transaction.selectionSet) listener({ type: "selection" });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const user = !transaction.getMeta(REMOTE);
|
|
98
|
+
for (const step of transaction.steps) if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
|
|
99
|
+
const { content } = step.slice;
|
|
100
|
+
listener({
|
|
101
|
+
type: "input",
|
|
102
|
+
inserted: content.textBetween(0, content.size, "\n", leafText),
|
|
103
|
+
range: {
|
|
104
|
+
start: step.from,
|
|
105
|
+
end: step.to
|
|
106
|
+
},
|
|
107
|
+
user
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const onSelection = () => listener({ type: "selection" });
|
|
112
|
+
const onCompositionStart = () => listener({ type: "compositionstart" });
|
|
113
|
+
const onCompositionEnd = () => listener({ type: "compositionend" });
|
|
114
|
+
editor.on("transaction", onTransaction);
|
|
115
|
+
editor.on("focus", onSelection);
|
|
116
|
+
editor.on("blur", onSelection);
|
|
117
|
+
const dom = editor.view.dom;
|
|
118
|
+
dom.addEventListener("compositionstart", onCompositionStart);
|
|
119
|
+
dom.addEventListener("compositionend", onCompositionEnd);
|
|
120
|
+
return () => {
|
|
121
|
+
editor.off("transaction", onTransaction);
|
|
122
|
+
editor.off("focus", onSelection);
|
|
123
|
+
editor.off("blur", onSelection);
|
|
124
|
+
dom.removeEventListener("compositionstart", onCompositionStart);
|
|
125
|
+
dom.removeEventListener("compositionend", onCompositionEnd);
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
composing: () => !editor.isDestroyed && editor.view.composing,
|
|
129
|
+
tokens: true
|
|
130
|
+
};
|
|
131
|
+
adapters.set(editor, adapter);
|
|
132
|
+
return adapter;
|
|
133
|
+
}
|
|
134
|
+
/** The type of the block the selection starts in. */
|
|
135
|
+
function blockTypeAt(editor) {
|
|
136
|
+
const { $from } = editor.state.selection;
|
|
137
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
138
|
+
const node = $from.node(depth);
|
|
139
|
+
switch (node.type.name) {
|
|
140
|
+
case "taskList": return "todo";
|
|
141
|
+
case "orderedList": return "numbered";
|
|
142
|
+
case "bulletList": return "bulleted";
|
|
143
|
+
case "blockquote": return "quote";
|
|
144
|
+
case "codeBlock": return "code";
|
|
145
|
+
case "heading": return `heading-${Math.min(Math.max(Number(node.attrs.level) || 1, 1), 3)}`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return "paragraph";
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Turns the block the selection is in into `type`, as one undo step. With
|
|
152
|
+
* `range`, deletes it first, like the `/` and the query that chose the type.
|
|
153
|
+
*/
|
|
154
|
+
function setBlockType(editor, type, range, focus = true) {
|
|
155
|
+
if (focus) editor.view.focus();
|
|
156
|
+
let chain = focus ? editor.chain().focus() : editor.chain();
|
|
157
|
+
if (range) chain = chain.deleteRange(range);
|
|
158
|
+
if (type === "divider") return asOneStep(editor, () => chain.setHorizontalRule().run());
|
|
159
|
+
chain = chain.clearNodes();
|
|
160
|
+
const run = () => {
|
|
161
|
+
switch (type) {
|
|
162
|
+
case "paragraph": return chain.setParagraph().run();
|
|
163
|
+
case "heading-1":
|
|
164
|
+
case "heading-2":
|
|
165
|
+
case "heading-3": return chain.setHeading({ level: Number(type.at(-1)) }).run();
|
|
166
|
+
case "bulleted": return chain.toggleBulletList().run();
|
|
167
|
+
case "numbered": return chain.toggleOrderedList().run();
|
|
168
|
+
case "todo": return chain.toggleTaskList().run();
|
|
169
|
+
case "quote": return chain.setBlockquote().run();
|
|
170
|
+
case "code": return chain.setCodeBlock().run();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return asOneStep(editor, run);
|
|
174
|
+
}
|
|
175
|
+
/** Moves focus into the note now, not a frame later as Tiptap's `focus` does. */
|
|
176
|
+
function focusEditor(editor, position) {
|
|
177
|
+
if (editor.isDestroyed) return;
|
|
178
|
+
editor.view.focus();
|
|
179
|
+
editor.commands.focus(position ?? null);
|
|
180
|
+
}
|
|
181
|
+
function selectionSnapshot(editor) {
|
|
182
|
+
const { selection } = editor.state;
|
|
183
|
+
const block = blockTypeAt(editor);
|
|
184
|
+
return {
|
|
185
|
+
formattable: editor.isEditable && !selection.empty && selection instanceof TextSelection && block !== "code",
|
|
186
|
+
from: selection.from,
|
|
187
|
+
to: selection.to,
|
|
188
|
+
focused: editor.isFocused,
|
|
189
|
+
block,
|
|
190
|
+
marks: {
|
|
191
|
+
bold: editor.isActive("bold"),
|
|
192
|
+
italic: editor.isActive("italic"),
|
|
193
|
+
underline: editor.isActive("underline"),
|
|
194
|
+
strike: editor.isActive("strike"),
|
|
195
|
+
code: editor.isActive("code")
|
|
196
|
+
},
|
|
197
|
+
link: editor.getAttributes("link").href ?? null
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const selectionStores = /* @__PURE__ */ new WeakMap();
|
|
201
|
+
/** The selection as a store React can read: one snapshot per change. */
|
|
202
|
+
function selectionStore(editor) {
|
|
203
|
+
const known = selectionStores.get(editor);
|
|
204
|
+
if (known) return known;
|
|
205
|
+
let snapshot = selectionSnapshot(editor);
|
|
206
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
207
|
+
let blurred;
|
|
208
|
+
const publish = () => {
|
|
209
|
+
if (editor.isDestroyed) return;
|
|
210
|
+
snapshot = selectionSnapshot(editor);
|
|
211
|
+
listeners.forEach((listener) => listener());
|
|
212
|
+
};
|
|
213
|
+
const refresh = (event) => {
|
|
214
|
+
if (editor.isDestroyed) return;
|
|
215
|
+
const tr = event?.transaction;
|
|
216
|
+
if (tr && !tr.docChanged && !tr.selectionSet && !tr.storedMarksSet) return;
|
|
217
|
+
if (snapshot.focused && !editor.isFocused) {
|
|
218
|
+
clearTimeout(blurred);
|
|
219
|
+
blurred = setTimeout(publish, 0);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
publish();
|
|
223
|
+
};
|
|
224
|
+
const refocus = () => refresh();
|
|
225
|
+
const store = {
|
|
226
|
+
subscribe(listener) {
|
|
227
|
+
if (listeners.size === 0) {
|
|
228
|
+
editor.on("transaction", refresh);
|
|
229
|
+
editor.on("focus", refocus);
|
|
230
|
+
editor.on("blur", refocus);
|
|
231
|
+
snapshot = selectionSnapshot(editor);
|
|
232
|
+
}
|
|
233
|
+
listeners.add(listener);
|
|
234
|
+
return () => {
|
|
235
|
+
listeners.delete(listener);
|
|
236
|
+
if (listeners.size > 0) return;
|
|
237
|
+
clearTimeout(blurred);
|
|
238
|
+
editor.off("transaction", refresh);
|
|
239
|
+
editor.off("focus", refocus);
|
|
240
|
+
editor.off("blur", refocus);
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
get: () => snapshot
|
|
244
|
+
};
|
|
245
|
+
selectionStores.set(editor, store);
|
|
246
|
+
return store;
|
|
247
|
+
}
|
|
248
|
+
const NoteEditorContext = createContext(null);
|
|
249
|
+
export { NoteEditorContext, REMOTE, asOneStep, blockTypeAt, focusEditor, mentionHref, noteAdapter, selectionStore, setBlockType };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ChangeDetails } from "../../core/ui-sdk.js";
|
|
2
|
+
import "../../core/index.js";
|
|
3
|
+
import { IconSvgElement } from "../icon/icon.js";
|
|
4
|
+
import { TriggerItemsLoader, TriggerMenuContent, TriggerMenuData } from "../trigger-menu/trigger-menu.js";
|
|
5
|
+
import { NoteBlock, NoteBlockInput, NoteBlockType, noteBlockTypes } from "./blocks.js";
|
|
6
|
+
import { NoteChange, NoteDiff, diffNotes } from "./diff.js";
|
|
7
|
+
import { NotePerson } from "./person.js";
|
|
8
|
+
import { NoteActionDetails, NoteComment, NoteCommentAnchor, NoteCommentMessage, NoteCursor, NotePresence, NoteSuggestion } from "./people.js";
|
|
9
|
+
import { NoteEditorHistory, NoteEditorHistoryDay, NoteEditorHistoryDayProps, NoteEditorHistoryEvent, NoteEditorHistoryEventAction, NoteEditorHistoryEventDetail, NoteEditorHistoryEventProps, NoteEditorHistoryEventQuote, NoteEditorHistoryEventTitle, NoteEditorHistoryEventTitleProps, NoteEditorHistoryProps } from "./parts/history.js";
|
|
10
|
+
import { NoteEditorAssistantMark, NoteEditorSuggestion, NoteEditorSuggestionLabels, NoteEditorSuggestionProps, NoteEditorSuggestions, NoteEditorSuggestionsProps } from "./parts/suggestions.js";
|
|
11
|
+
import { NoteEditorComments, NoteEditorCommentsLabels, NoteEditorCommentsProps } from "./parts/comments.js";
|
|
12
|
+
import { NoteEditorHeader, NoteEditorMeta, NoteEditorMetaMark, NoteEditorTemplate, NoteEditorTemplateProps, NoteEditorTemplates, NoteEditorTitle, NoteEditorTitleProps } from "./parts/header.js";
|
|
13
|
+
import { NoteEditorBanner, NoteEditorBannerProps, NoteEditorPresence, NoteEditorPresenceProps } from "./parts/presence.js";
|
|
14
|
+
import { NoteEditorToolbar, NoteEditorToolbarLabels, NoteEditorToolbarProps } from "./parts/toolbar.js";
|
|
15
|
+
import { ComponentProps, ReactNode } from "react";
|
|
16
|
+
import { Editor } from "@tiptap/core";
|
|
17
|
+
type NoteEditorValueChangeReason = "input-change" | "imperative" | "block-insert" | "block-update" | "block-remove";
|
|
18
|
+
type NoteEditorOptions = {
|
|
19
|
+
/** The note's blocks. Pass it to control them. */
|
|
20
|
+
value?: NoteBlock[];
|
|
21
|
+
/** The blocks it starts with, when uncontrolled. */
|
|
22
|
+
defaultValue?: NoteBlock[];
|
|
23
|
+
/** Runs when typing or an agent wants to change the blocks. `details.cancel()` refuses it. */
|
|
24
|
+
onValueChange?: (value: NoteBlock[], details: ChangeDetails<NoteEditorValueChangeReason>) => void;
|
|
25
|
+
/** Shown on the empty line the caret is on. */
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
/** Shows the note without letting anyone edit it. */
|
|
28
|
+
readOnly?: boolean;
|
|
29
|
+
/** The threads on the note's text. A resolved one keeps no mark. */
|
|
30
|
+
comments?: readonly NoteComment[];
|
|
31
|
+
/** Starts a thread on some text. Without it, the toolbar has no Comment button and an agent can't comment. */
|
|
32
|
+
onComment?: (anchor: NoteCommentAnchor, details: NoteActionDetails) => void;
|
|
33
|
+
/** Runs when someone replies in a thread. */
|
|
34
|
+
onCommentReply?: (commentId: string, text: string, details: NoteActionDetails) => void;
|
|
35
|
+
/** Runs when someone resolves a thread. */
|
|
36
|
+
onCommentResolve?: (commentId: string, details: NoteActionDetails) => void;
|
|
37
|
+
};
|
|
38
|
+
type NoteEditorContentProps = {
|
|
39
|
+
label?: string;
|
|
40
|
+
todoLabel?: (text: string, checked: boolean) => string;
|
|
41
|
+
onEditor?: (editor: Editor | null) => void;
|
|
42
|
+
onCursor?: (cursor: NoteCursor | null) => void;
|
|
43
|
+
};
|
|
44
|
+
/** A choice in the `/` menu: a block type, or an action of the app's own. */
|
|
45
|
+
type NoteEditorCommand = {
|
|
46
|
+
/** A block type turns the block into it; any other value goes to `onCommand`. */
|
|
47
|
+
value: string;
|
|
48
|
+
label: string;
|
|
49
|
+
/** More words that find it, like `h1` for a heading. */
|
|
50
|
+
keywords?: string[];
|
|
51
|
+
icon?: IconSvgElement;
|
|
52
|
+
};
|
|
53
|
+
/** The `/` menu's block types, in English. Map over them to translate or add your own. */
|
|
54
|
+
declare const noteEditorCommands: NoteEditorCommand[];
|
|
55
|
+
type NoteEditorCommandDetails = {
|
|
56
|
+
/** The block the `/` was typed in, now without the `/` and the query. */
|
|
57
|
+
blockId: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
type NoteEditorProps = Omit<ComponentProps<"div">, "defaultValue" | "children"> & NoteEditorOptions & {
|
|
60
|
+
/** The note's accessible name, for people using screen readers and for agents. */
|
|
61
|
+
label?: string;
|
|
62
|
+
/** The `/` menu's choices. `noteEditorCommands` by default. */
|
|
63
|
+
commands?: NoteEditorCommand[];
|
|
64
|
+
/** Runs when a `/` choice that isn't a block type is chosen. */
|
|
65
|
+
onCommand?: (value: string, details: NoteEditorCommandDetails) => void;
|
|
66
|
+
/** Who `@` suggests, as data or a loader. Without it, `@` is plain text. */
|
|
67
|
+
mentions?: TriggerMenuData<string> | TriggerItemsLoader<string>;
|
|
68
|
+
/** The other people in the note, and where each one is. abby draws them; the app syncs them. */
|
|
69
|
+
presence?: readonly NotePresence[];
|
|
70
|
+
/** Runs when your caret moves, so the app can show it to the others; null once the note loses focus. */
|
|
71
|
+
onCursorChange?: (cursor: NoteCursor | null) => void;
|
|
72
|
+
/**
|
|
73
|
+
* What the assistant or an agent proposes, each drawn under its block. It
|
|
74
|
+
* never writes into the note: apply it through `value` on Accept.
|
|
75
|
+
*/
|
|
76
|
+
suggestions?: readonly NoteSuggestion[];
|
|
77
|
+
/** Runs on a suggestion's Accept. An agent's press needs the person's yes (`data-agent-confirm`). */
|
|
78
|
+
onSuggestionAccept?: (suggestion: NoteSuggestion, details: NoteActionDetails) => void;
|
|
79
|
+
/** Runs on a suggestion's Discard. */
|
|
80
|
+
onSuggestionDiscard?: (suggestion: NoteSuggestion, details: NoteActionDetails) => void;
|
|
81
|
+
/** Runs on a stale suggestion's Redo. Without it, a stale one only offers Discard. */
|
|
82
|
+
onSuggestionRedo?: (suggestion: NoteSuggestion, details: NoteActionDetails) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Marks blocks as added, removed or changed, to show a version of the
|
|
85
|
+
* note against another: pass `diffNotes(before, after)`'s `changes`, with
|
|
86
|
+
* its `blocks` as the value, in a read-only note.
|
|
87
|
+
*/
|
|
88
|
+
changes?: Readonly<Record<string, NoteChange>>;
|
|
89
|
+
/** What a screen reader hears before a marked block. "Added" and "Removed" by default. */
|
|
90
|
+
changeLabels?: {
|
|
91
|
+
added: string;
|
|
92
|
+
removed: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The editor's parts. By default `NoteEditorContent`, `NoteEditorMenu`,
|
|
96
|
+
* `NoteEditorToolbar`, `NoteEditorComments` and `NoteEditorSuggestions`.
|
|
97
|
+
*/
|
|
98
|
+
children?: ReactNode;
|
|
99
|
+
};
|
|
100
|
+
declare function NoteEditor({ value, defaultValue, onValueChange, placeholder, readOnly, label, commands, onCommand, mentions, presence, onCursorChange, comments, onComment, onCommentReply, onCommentResolve, suggestions, onSuggestionAccept, onSuggestionDiscard, onSuggestionRedo, changes, changeLabels, className, children, ...props }: NoteEditorProps): import("react").JSX.Element;
|
|
101
|
+
type NoteEditorContentElementProps = Omit<ComponentProps<"div">, "children"> & Omit<NoteEditorContentProps, "onEditor">;
|
|
102
|
+
/** Where the note is written. `NoteEditor` renders one when it has no children. */
|
|
103
|
+
declare function NoteEditorContent({ label, todoLabel, className, ...props }: NoteEditorContentElementProps): import("react").JSX.Element | null;
|
|
104
|
+
/**
|
|
105
|
+
* The `/` and `@` suggestions, at the caret. `NoteEditor` renders one when it
|
|
106
|
+
* has no children; render it yourself next to `NoteEditorContent` otherwise.
|
|
107
|
+
*/
|
|
108
|
+
declare function NoteEditorMenu({ className, children, ...props }: ComponentProps<typeof TriggerMenuContent>): import("react").JSX.Element;
|
|
109
|
+
export { type NoteActionDetails, type NoteBlock, type NoteBlockInput, type NoteBlockType, type NoteChange, type NoteComment, type NoteCommentAnchor, type NoteCommentMessage, type NoteCursor, type NoteDiff, NoteEditor, NoteEditorAssistantMark, NoteEditorBanner, type NoteEditorBannerProps, type NoteEditorCommand, type NoteEditorCommandDetails, NoteEditorComments, type NoteEditorCommentsLabels, type NoteEditorCommentsProps, NoteEditorContent, type NoteEditorContentElementProps as NoteEditorContentProps, NoteEditorHeader, NoteEditorHistory, NoteEditorHistoryDay, type NoteEditorHistoryDayProps, NoteEditorHistoryEvent, NoteEditorHistoryEventAction, NoteEditorHistoryEventDetail, type NoteEditorHistoryEventProps, NoteEditorHistoryEventQuote, NoteEditorHistoryEventTitle, type NoteEditorHistoryEventTitleProps, type NoteEditorHistoryProps, NoteEditorMenu, NoteEditorMeta, NoteEditorMetaMark, NoteEditorPresence, type NoteEditorPresenceProps, type NoteEditorProps, NoteEditorSuggestion, type NoteEditorSuggestionLabels, type NoteEditorSuggestionProps, NoteEditorSuggestions, type NoteEditorSuggestionsProps, NoteEditorTemplate, type NoteEditorTemplateProps, NoteEditorTemplates, NoteEditorTitle, type NoteEditorTitleProps, NoteEditorToolbar, type NoteEditorToolbarLabels, type NoteEditorToolbarProps, type NoteEditorValueChangeReason, type NotePerson, type NotePresence, type NoteSuggestion, diffNotes, noteBlockTypes, noteEditorCommands };
|