create-starlight-cms 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/bin/index.js +147 -0
- package/package.json +46 -0
- package/template/.nvmrc +1 -0
- package/template/LICENSE +21 -0
- package/template/README.md +68 -0
- package/template/THIRD_PARTY_NOTICES.md +12 -0
- package/template/_gitignore +14 -0
- package/template/astro.config.mjs +26 -0
- package/template/migrations/0001_schema.sql +73 -0
- package/template/migrations/0002_publish_delivery.sql +16 -0
- package/template/package-lock.json.template +9123 -0
- package/template/package.json +89 -0
- package/template/scripts/build-admin.mjs +38 -0
- package/template/scripts/check-linux-bindings.mjs +18 -0
- package/template/scripts/dev.mjs +94 -0
- package/template/src/admin/admin.scss +182 -0
- package/template/src/admin/app.ts +130 -0
- package/template/src/admin/client.tsx +684 -0
- package/template/src/admin/components/tiptap-extension/node-background-extension.ts +150 -0
- package/template/src/admin/components/tiptap-icons/align-center-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/align-justify-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/align-left-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/align-right-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/arrow-left-icon.tsx +24 -0
- package/template/src/admin/components/tiptap-icons/arrow-right-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/ban-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/blockquote-icon.tsx +44 -0
- package/template/src/admin/components/tiptap-icons/bold-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/case-sensitive-icon.tsx +32 -0
- package/template/src/admin/components/tiptap-icons/check-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/chevron-down-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/chevron-up-icon.tsx +22 -0
- package/template/src/admin/components/tiptap-icons/close-icon.tsx +24 -0
- package/template/src/admin/components/tiptap-icons/code-block-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/code2-icon.tsx +32 -0
- package/template/src/admin/components/tiptap-icons/corner-down-left-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/external-link-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/heading-five-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/heading-four-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/heading-icon.tsx +24 -0
- package/template/src/admin/components/tiptap-icons/heading-one-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/heading-six-icon.tsx +30 -0
- package/template/src/admin/components/tiptap-icons/heading-three-icon.tsx +36 -0
- package/template/src/admin/components/tiptap-icons/heading-two-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/highlighter-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/image-plus-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/italic-icon.tsx +24 -0
- package/template/src/admin/components/tiptap-icons/link-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/list-icon.tsx +56 -0
- package/template/src/admin/components/tiptap-icons/list-ordered-icon.tsx +56 -0
- package/template/src/admin/components/tiptap-icons/list-todo-icon.tsx +50 -0
- package/template/src/admin/components/tiptap-icons/moon-star-icon.tsx +30 -0
- package/template/src/admin/components/tiptap-icons/redo2-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/search-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/strike-icon.tsx +28 -0
- package/template/src/admin/components/tiptap-icons/subscript-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/sun-icon.tsx +58 -0
- package/template/src/admin/components/tiptap-icons/superscript-icon.tsx +38 -0
- package/template/src/admin/components/tiptap-icons/trash-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/underline-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/undo2-icon.tsx +26 -0
- package/template/src/admin/components/tiptap-icons/whole-word-icon.tsx +36 -0
- package/template/src/admin/components/tiptap-node/blockquote-node/blockquote-node.scss +37 -0
- package/template/src/admin/components/tiptap-node/code-block-node/code-block-node.scss +54 -0
- package/template/src/admin/components/tiptap-node/heading-node/heading-node.scss +45 -0
- package/template/src/admin/components/tiptap-node/horizontal-rule-node/horizontal-rule-node-extension.ts +14 -0
- package/template/src/admin/components/tiptap-node/horizontal-rule-node/horizontal-rule-node.scss +25 -0
- package/template/src/admin/components/tiptap-node/image-node/image-node.scss +35 -0
- package/template/src/admin/components/tiptap-node/image-upload-node/image-upload-node-extension.ts +161 -0
- package/template/src/admin/components/tiptap-node/image-upload-node/image-upload-node.scss +249 -0
- package/template/src/admin/components/tiptap-node/image-upload-node/image-upload-node.tsx +554 -0
- package/template/src/admin/components/tiptap-node/image-upload-node/index.tsx +1 -0
- package/template/src/admin/components/tiptap-node/list-node/list-node.scss +208 -0
- package/template/src/admin/components/tiptap-node/paragraph-node/paragraph-node.scss +217 -0
- package/template/src/admin/components/tiptap-templates/simple/NOTICE.md +14 -0
- package/template/src/admin/components/tiptap-templates/simple/data/content.json +477 -0
- package/template/src/admin/components/tiptap-templates/simple/simple-editor.scss +97 -0
- package/template/src/admin/components/tiptap-templates/simple/simple-editor.tsx +348 -0
- package/template/src/admin/components/tiptap-templates/simple/theme-toggle.tsx +44 -0
- package/template/src/admin/components/tiptap-ui/blockquote-button/blockquote-button.tsx +122 -0
- package/template/src/admin/components/tiptap-ui/blockquote-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/blockquote-button/use-blockquote.ts +273 -0
- package/template/src/admin/components/tiptap-ui/code-block-button/code-block-button.tsx +122 -0
- package/template/src/admin/components/tiptap-ui/code-block-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/code-block-button/use-code-block.ts +283 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-button/color-highlight-button.scss +49 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-button/color-highlight-button.tsx +170 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-button/use-color-highlight.ts +380 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-popover/color-highlight-popover.tsx +231 -0
- package/template/src/admin/components/tiptap-ui/color-highlight-popover/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui/heading-button/heading-button.tsx +124 -0
- package/template/src/admin/components/tiptap-ui/heading-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/heading-button/use-heading.ts +348 -0
- package/template/src/admin/components/tiptap-ui/heading-dropdown-menu/heading-dropdown-menu.tsx +128 -0
- package/template/src/admin/components/tiptap-ui/heading-dropdown-menu/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/heading-dropdown-menu/use-heading-dropdown-menu.ts +132 -0
- package/template/src/admin/components/tiptap-ui/image-upload-button/image-upload-button.tsx +130 -0
- package/template/src/admin/components/tiptap-ui/image-upload-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/image-upload-button/use-image-upload.ts +197 -0
- package/template/src/admin/components/tiptap-ui/link-popover/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/link-popover/link-popover.scss +16 -0
- package/template/src/admin/components/tiptap-ui/link-popover/link-popover.tsx +315 -0
- package/template/src/admin/components/tiptap-ui/link-popover/use-link-popover.ts +297 -0
- package/template/src/admin/components/tiptap-ui/list-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/list-button/list-button.tsx +120 -0
- package/template/src/admin/components/tiptap-ui/list-button/use-list.ts +353 -0
- package/template/src/admin/components/tiptap-ui/list-dropdown-menu/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/list-dropdown-menu/list-dropdown-menu.tsx +126 -0
- package/template/src/admin/components/tiptap-ui/list-dropdown-menu/use-list-dropdown-menu.ts +220 -0
- package/template/src/admin/components/tiptap-ui/mark-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/mark-button/mark-button.tsx +122 -0
- package/template/src/admin/components/tiptap-ui/mark-button/use-mark.ts +219 -0
- package/template/src/admin/components/tiptap-ui/search-and-replace/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/search-and-replace/search-and-replace.scss +300 -0
- package/template/src/admin/components/tiptap-ui/search-and-replace/search-and-replace.tsx +718 -0
- package/template/src/admin/components/tiptap-ui/search-and-replace/use-search-and-replace.ts +528 -0
- package/template/src/admin/components/tiptap-ui/text-align-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/text-align-button/text-align-button.tsx +144 -0
- package/template/src/admin/components/tiptap-ui/text-align-button/use-text-align.ts +237 -0
- package/template/src/admin/components/tiptap-ui/undo-redo-button/index.tsx +2 -0
- package/template/src/admin/components/tiptap-ui/undo-redo-button/undo-redo-button.tsx +125 -0
- package/template/src/admin/components/tiptap-ui/undo-redo-button/use-undo-redo.ts +200 -0
- package/template/src/admin/components/tiptap-ui-primitive/badge/badge-colors.scss +395 -0
- package/template/src/admin/components/tiptap-ui-primitive/badge/badge-group.scss +16 -0
- package/template/src/admin/components/tiptap-ui-primitive/badge/badge.scss +99 -0
- package/template/src/admin/components/tiptap-ui-primitive/badge/badge.tsx +44 -0
- package/template/src/admin/components/tiptap-ui-primitive/badge/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/button/button-colors.scss +613 -0
- package/template/src/admin/components/tiptap-ui-primitive/button/button.scss +390 -0
- package/template/src/admin/components/tiptap-ui-primitive/button/button.tsx +158 -0
- package/template/src/admin/components/tiptap-ui-primitive/button/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/button-group/button-group.scss +89 -0
- package/template/src/admin/components/tiptap-ui-primitive/button-group/button-group.tsx +72 -0
- package/template/src/admin/components/tiptap-ui-primitive/button-group/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/card/card.scss +74 -0
- package/template/src/admin/components/tiptap-ui-primitive/card/card.tsx +79 -0
- package/template/src/admin/components/tiptap-ui-primitive/card/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.scss +152 -0
- package/template/src/admin/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.tsx +262 -0
- package/template/src/admin/components/tiptap-ui-primitive/dropdown-menu/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/input/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/input/input.scss +41 -0
- package/template/src/admin/components/tiptap-ui-primitive/input/input.tsx +22 -0
- package/template/src/admin/components/tiptap-ui-primitive/input-group/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/input-group/input-group.scss +225 -0
- package/template/src/admin/components/tiptap-ui-primitive/input-group/input-group.tsx +135 -0
- package/template/src/admin/components/tiptap-ui-primitive/popover/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/popover/popover.scss +64 -0
- package/template/src/admin/components/tiptap-ui-primitive/popover/popover.tsx +35 -0
- package/template/src/admin/components/tiptap-ui-primitive/separator/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/separator/separator.scss +23 -0
- package/template/src/admin/components/tiptap-ui-primitive/separator/separator.tsx +28 -0
- package/template/src/admin/components/tiptap-ui-primitive/spacer/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/spacer/spacer.tsx +24 -0
- package/template/src/admin/components/tiptap-ui-primitive/switch/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/switch/switch.scss +86 -0
- package/template/src/admin/components/tiptap-ui-primitive/switch/switch.tsx +29 -0
- package/template/src/admin/components/tiptap-ui-primitive/textarea/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/textarea/textarea.scss +42 -0
- package/template/src/admin/components/tiptap-ui-primitive/textarea/textarea.tsx +16 -0
- package/template/src/admin/components/tiptap-ui-primitive/toolbar/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/toolbar/toolbar.scss +98 -0
- package/template/src/admin/components/tiptap-ui-primitive/toolbar/toolbar.tsx +203 -0
- package/template/src/admin/components/tiptap-ui-primitive/tooltip/index.tsx +1 -0
- package/template/src/admin/components/tiptap-ui-primitive/tooltip/tooltip.scss +43 -0
- package/template/src/admin/components/tiptap-ui-primitive/tooltip/tooltip.tsx +241 -0
- package/template/src/admin/hooks/use-composed-ref.ts +46 -0
- package/template/src/admin/hooks/use-cursor-visibility.ts +69 -0
- package/template/src/admin/hooks/use-element-rect.ts +166 -0
- package/template/src/admin/hooks/use-is-breakpoint.ts +35 -0
- package/template/src/admin/hooks/use-menu-navigation.ts +204 -0
- package/template/src/admin/hooks/use-scrolling.ts +75 -0
- package/template/src/admin/hooks/use-throttled-callback.ts +48 -0
- package/template/src/admin/hooks/use-tiptap-editor.ts +69 -0
- package/template/src/admin/hooks/use-unmount.ts +21 -0
- package/template/src/admin/hooks/use-window-size.ts +93 -0
- package/template/src/admin/html.ts +17 -0
- package/template/src/admin/lib/tiptap-utils.ts +652 -0
- package/template/src/admin/navigation-tree.tsx +82 -0
- package/template/src/admin/preview.ts +73 -0
- package/template/src/admin/styles/_cms-theme.scss +58 -0
- package/template/src/admin/styles/_keyframe-animations.scss +91 -0
- package/template/src/admin/styles/_variables.scss +298 -0
- package/template/src/assets/favicon.svg +1 -0
- package/template/src/assets/logo.svg +1 -0
- package/template/src/astro-env.d.ts +1 -0
- package/template/src/content.config.ts +12 -0
- package/template/src/db/bootstrap.ts +36 -0
- package/template/src/db/client.ts +7 -0
- package/template/src/db/schema.ts +45 -0
- package/template/src/documents/service.ts +178 -0
- package/template/src/documents/validation.ts +9 -0
- package/template/src/env.ts +9 -0
- package/template/src/index.ts +10 -0
- package/template/src/locales.ts +10 -0
- package/template/src/media/service.ts +120 -0
- package/template/src/navigation/service.ts +171 -0
- package/template/src/pages/[locale]/cms-preview-shell.astro +12 -0
- package/template/src/pages/cms-preview-shell.astro +5 -0
- package/template/src/publish/deploy-hook.ts +42 -0
- package/template/src/publish/record.ts +20 -0
- package/template/src/publish/service.ts +135 -0
- package/template/src/scss.d.ts +5 -0
- package/template/src/site.config.ts +7 -0
- package/template/src/sql.d.ts +4 -0
- package/template/src/starlight/cms-origin.ts +4 -0
- package/template/src/starlight/loader.ts +21 -0
- package/template/src/starlight/preview-render.ts +162 -0
- package/template/src/starlight/preview-shell.astro +14 -0
- package/template/src/starlight/render.ts +59 -0
- package/template/src/starlight/schema.ts +34 -0
- package/template/src/starlight/sidebar.ts +35 -0
- package/template/src/starlight/snapshot.ts +47 -0
- package/template/src/starlight/source.ts +26 -0
- package/template/src/starlight/tiptap.ts +29 -0
- package/template/src/styles/starlight.css +12 -0
- package/template/test-files/content.test.template.ts +82 -0
- package/template/test-files/deploy-hook.test.template.ts +32 -0
- package/template/test-files/media.test.template.ts +39 -0
- package/template/test-files/publishing.integration.test.template.ts +156 -0
- package/template/tsconfig.admin.json +18 -0
- package/template/tsconfig.json +23 -0
- package/template/worker-configuration.d.ts +15389 -0
- package/template/wrangler.jsonc +26 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--tt-textarea-placeholder: var(--tt-gray-light-a-400);
|
|
3
|
+
--tt-textarea-border: var(--tt-gray-light-a-200);
|
|
4
|
+
--tt-textarea-border-focus: var(--tt-gray-light-a-300);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.dark {
|
|
8
|
+
--tt-textarea-placeholder: var(--tt-gray-dark-a-400);
|
|
9
|
+
--tt-textarea-border: var(--tt-gray-dark-a-200);
|
|
10
|
+
--tt-textarea-border-focus: var(--tt-gray-dark-a-300);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tiptap-textarea {
|
|
14
|
+
display: flex;
|
|
15
|
+
width: 100%;
|
|
16
|
+
min-height: 4rem;
|
|
17
|
+
padding: 0.5rem 0.625rem;
|
|
18
|
+
border-radius: 0.5rem;
|
|
19
|
+
border: 1px solid var(--tt-textarea-border);
|
|
20
|
+
background: transparent;
|
|
21
|
+
font-size: 1rem;
|
|
22
|
+
field-sizing: content;
|
|
23
|
+
outline: none;
|
|
24
|
+
transition:
|
|
25
|
+
color,
|
|
26
|
+
background-color,
|
|
27
|
+
border-color 150ms;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.tiptap-textarea::placeholder {
|
|
31
|
+
color: var(--tt-textarea-placeholder);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.tiptap-textarea:focus-visible {
|
|
35
|
+
border-color: var(--tt-textarea-border-focus);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@media (min-width: 768px) {
|
|
39
|
+
.tiptap-textarea {
|
|
40
|
+
font-size: 0.875rem;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/tiptap-utils"
|
|
4
|
+
import "./textarea.scss"
|
|
5
|
+
|
|
6
|
+
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
7
|
+
return (
|
|
8
|
+
<textarea
|
|
9
|
+
data-slot="textarea"
|
|
10
|
+
className={cn("textarea", className)}
|
|
11
|
+
{...props}
|
|
12
|
+
/>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { Textarea }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./toolbar"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--tt-toolbar-height: 2.75rem;
|
|
3
|
+
--tt-safe-area-bottom: env(safe-area-inset-bottom, 0px);
|
|
4
|
+
--tt-toolbar-bg-color: var(--white);
|
|
5
|
+
--tt-toolbar-border-color: var(--tt-gray-light-a-100);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.dark {
|
|
9
|
+
--tt-toolbar-bg-color: var(--black);
|
|
10
|
+
--tt-toolbar-border-color: var(--tt-gray-dark-a-50);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tiptap-toolbar {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 0.25rem;
|
|
17
|
+
|
|
18
|
+
&-group {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
gap: 0.125rem;
|
|
22
|
+
|
|
23
|
+
&:empty {
|
|
24
|
+
display: none;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:empty + .tiptap-separator,
|
|
28
|
+
.tiptap-separator + &:empty {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&[data-variant="fixed"] {
|
|
34
|
+
position: sticky;
|
|
35
|
+
top: 0;
|
|
36
|
+
z-index: 50;
|
|
37
|
+
width: 100%;
|
|
38
|
+
min-height: var(--tt-toolbar-height);
|
|
39
|
+
background: var(--tt-toolbar-bg-color);
|
|
40
|
+
border-bottom: 1px solid var(--tt-toolbar-border-color);
|
|
41
|
+
padding: 0 0.5rem;
|
|
42
|
+
overflow-x: auto;
|
|
43
|
+
overscroll-behavior-x: contain;
|
|
44
|
+
-webkit-overflow-scrolling: touch;
|
|
45
|
+
scrollbar-width: none;
|
|
46
|
+
-ms-overflow-style: none;
|
|
47
|
+
|
|
48
|
+
&::-webkit-scrollbar {
|
|
49
|
+
display: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (max-width: 480px) {
|
|
53
|
+
position: absolute;
|
|
54
|
+
top: auto;
|
|
55
|
+
height: calc(var(--tt-toolbar-height) + var(--tt-safe-area-bottom));
|
|
56
|
+
border-top: 1px solid var(--tt-toolbar-border-color);
|
|
57
|
+
border-bottom: none;
|
|
58
|
+
padding: 0 0.5rem var(--tt-safe-area-bottom);
|
|
59
|
+
flex-wrap: nowrap;
|
|
60
|
+
justify-content: flex-start;
|
|
61
|
+
|
|
62
|
+
.tiptap-toolbar-group {
|
|
63
|
+
flex: 0 0 auto;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&[data-variant="floating"] {
|
|
69
|
+
--tt-toolbar-padding: 0.125rem;
|
|
70
|
+
--tt-toolbar-border-width: 1px;
|
|
71
|
+
|
|
72
|
+
padding: 0.188rem;
|
|
73
|
+
border-radius: calc(
|
|
74
|
+
var(--tt-toolbar-padding) + var(--tt-radius-lg) +
|
|
75
|
+
var(--tt-toolbar-border-width)
|
|
76
|
+
);
|
|
77
|
+
border: var(--tt-toolbar-border-width) solid var(--tt-toolbar-border-color);
|
|
78
|
+
background-color: var(--tt-toolbar-bg-color);
|
|
79
|
+
box-shadow: var(--tt-shadow-elevated-md);
|
|
80
|
+
outline: none;
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
|
|
83
|
+
&[data-plain="true"] {
|
|
84
|
+
padding: 0;
|
|
85
|
+
border-radius: 0;
|
|
86
|
+
border: none;
|
|
87
|
+
box-shadow: none;
|
|
88
|
+
background-color: transparent;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@media screen and (max-width: 480px) {
|
|
92
|
+
width: 100%;
|
|
93
|
+
border-radius: 0;
|
|
94
|
+
border: none;
|
|
95
|
+
box-shadow: none;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from "react"
|
|
2
|
+
import { Separator } from "@/components/tiptap-ui-primitive/separator"
|
|
3
|
+
import "@/components/tiptap-ui-primitive/toolbar/toolbar.scss"
|
|
4
|
+
import { cn } from "@/lib/tiptap-utils"
|
|
5
|
+
import { useMenuNavigation } from "@/hooks/use-menu-navigation"
|
|
6
|
+
import { useComposedRef } from "@/hooks/use-composed-ref"
|
|
7
|
+
|
|
8
|
+
type BaseProps = React.HTMLAttributes<HTMLDivElement>
|
|
9
|
+
|
|
10
|
+
interface ToolbarProps extends BaseProps {
|
|
11
|
+
variant?: "floating" | "fixed"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const useToolbarNavigation = (
|
|
15
|
+
toolbarRef: React.RefObject<HTMLDivElement | null>
|
|
16
|
+
) => {
|
|
17
|
+
const [items, setItems] = useState<HTMLElement[]>([])
|
|
18
|
+
const initialContainerTabIndexRef = useRef<number | null | undefined>(
|
|
19
|
+
undefined
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const collectItems = useCallback(() => {
|
|
23
|
+
if (!toolbarRef.current) return []
|
|
24
|
+
return Array.from(
|
|
25
|
+
toolbarRef.current.querySelectorAll<HTMLElement>(
|
|
26
|
+
'button:not([disabled]), [role="button"]:not([disabled]), [tabindex="0"]:not([disabled])'
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
}, [toolbarRef])
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const toolbar = toolbarRef.current
|
|
33
|
+
if (!toolbar) return
|
|
34
|
+
|
|
35
|
+
if (initialContainerTabIndexRef.current === undefined) {
|
|
36
|
+
initialContainerTabIndexRef.current =
|
|
37
|
+
toolbar.hasAttribute("tabindex") && toolbar.tabIndex >= 0
|
|
38
|
+
? toolbar.tabIndex
|
|
39
|
+
: null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const updateItems = () => setItems(collectItems())
|
|
43
|
+
|
|
44
|
+
updateItems()
|
|
45
|
+
const observer = new MutationObserver(updateItems)
|
|
46
|
+
observer.observe(toolbar, {
|
|
47
|
+
childList: true,
|
|
48
|
+
subtree: true,
|
|
49
|
+
attributes: true,
|
|
50
|
+
attributeFilter: ["disabled"],
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return () => observer.disconnect()
|
|
54
|
+
}, [collectItems, toolbarRef])
|
|
55
|
+
|
|
56
|
+
const { selectedIndex, setSelectedIndex } = useMenuNavigation<HTMLElement>({
|
|
57
|
+
containerRef: toolbarRef,
|
|
58
|
+
items,
|
|
59
|
+
orientation: "horizontal",
|
|
60
|
+
onSelect: (el) => el.click(),
|
|
61
|
+
autoSelectFirstItem: false,
|
|
62
|
+
loopOnTab: false,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const toolbar = toolbarRef.current
|
|
67
|
+
if (!toolbar) return
|
|
68
|
+
|
|
69
|
+
const handleFocus = (e: FocusEvent) => {
|
|
70
|
+
const target = e.target as HTMLElement
|
|
71
|
+
if (toolbar.contains(target)) {
|
|
72
|
+
target.setAttribute("data-focus-visible", "true")
|
|
73
|
+
const itemIndex = items.indexOf(target)
|
|
74
|
+
if (itemIndex >= 0) setSelectedIndex(itemIndex)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const handleBlur = (e: FocusEvent) => {
|
|
79
|
+
const target = e.target as HTMLElement
|
|
80
|
+
if (toolbar.contains(target)) target.removeAttribute("data-focus-visible")
|
|
81
|
+
|
|
82
|
+
const nextTarget = e.relatedTarget
|
|
83
|
+
const NodeConstructor = toolbar.ownerDocument.defaultView?.Node
|
|
84
|
+
const leavesToolbar =
|
|
85
|
+
!nextTarget ||
|
|
86
|
+
!NodeConstructor ||
|
|
87
|
+
!(nextTarget instanceof NodeConstructor) ||
|
|
88
|
+
!toolbar.contains(nextTarget)
|
|
89
|
+
|
|
90
|
+
if (leavesToolbar && initialContainerTabIndexRef.current != null) {
|
|
91
|
+
queueMicrotask(() => {
|
|
92
|
+
if (
|
|
93
|
+
toolbar.isConnected &&
|
|
94
|
+
!toolbar.contains(toolbar.ownerDocument.activeElement)
|
|
95
|
+
) {
|
|
96
|
+
toolbar.tabIndex = initialContainerTabIndexRef.current!
|
|
97
|
+
setSelectedIndex(-1)
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
toolbar.addEventListener("focus", handleFocus, true)
|
|
104
|
+
toolbar.addEventListener("blur", handleBlur, true)
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
toolbar.removeEventListener("focus", handleFocus, true)
|
|
108
|
+
toolbar.removeEventListener("blur", handleBlur, true)
|
|
109
|
+
}
|
|
110
|
+
}, [items, setSelectedIndex, toolbarRef])
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!items.length) return
|
|
114
|
+
|
|
115
|
+
const toolbar = toolbarRef.current
|
|
116
|
+
if (!toolbar) return
|
|
117
|
+
|
|
118
|
+
const initialContainerTabIndex = initialContainerTabIndexRef.current
|
|
119
|
+
const currentIndex = selectedIndex ?? -1
|
|
120
|
+
|
|
121
|
+
if (initialContainerTabIndex != null) {
|
|
122
|
+
items.forEach((item) => {
|
|
123
|
+
item.tabIndex = -1
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (currentIndex >= 0 && items[currentIndex]) {
|
|
127
|
+
toolbar.tabIndex = -1
|
|
128
|
+
if (toolbar.contains(toolbar.ownerDocument.activeElement)) {
|
|
129
|
+
items[currentIndex].focus()
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
toolbar.tabIndex = initialContainerTabIndex
|
|
133
|
+
}
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const existingTabStop = items.findIndex((item) => item.tabIndex === 0)
|
|
138
|
+
const activeIndex =
|
|
139
|
+
currentIndex >= 0 && items[currentIndex]
|
|
140
|
+
? currentIndex
|
|
141
|
+
: existingTabStop >= 0
|
|
142
|
+
? existingTabStop
|
|
143
|
+
: 0
|
|
144
|
+
|
|
145
|
+
items.forEach((item, index) => {
|
|
146
|
+
item.tabIndex = index === activeIndex ? 0 : -1
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// Only restore focus while it is inside the toolbar. The item list also
|
|
150
|
+
// refreshes when focus legitimately lives elsewhere (e.g. a popover
|
|
151
|
+
// opened from the toolbar autofocused its input), and stealing focus
|
|
152
|
+
// back would dismiss such overlays.
|
|
153
|
+
if (
|
|
154
|
+
currentIndex >= 0 &&
|
|
155
|
+
toolbar.contains(toolbar.ownerDocument.activeElement)
|
|
156
|
+
) {
|
|
157
|
+
items[activeIndex]?.focus()
|
|
158
|
+
}
|
|
159
|
+
}, [selectedIndex, items, toolbarRef])
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const Toolbar = forwardRef<HTMLDivElement, ToolbarProps>(
|
|
163
|
+
({ children, className, variant = "fixed", ...props }, ref) => {
|
|
164
|
+
const toolbarRef = useRef<HTMLDivElement>(null)
|
|
165
|
+
const composedRef = useComposedRef(toolbarRef, ref)
|
|
166
|
+
useToolbarNavigation(toolbarRef)
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
ref={composedRef}
|
|
171
|
+
role="toolbar"
|
|
172
|
+
aria-label="toolbar"
|
|
173
|
+
data-variant={variant}
|
|
174
|
+
className={cn("tiptap-toolbar", className)}
|
|
175
|
+
{...props}
|
|
176
|
+
>
|
|
177
|
+
{children}
|
|
178
|
+
</div>
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
Toolbar.displayName = "Toolbar"
|
|
183
|
+
|
|
184
|
+
export const ToolbarGroup = forwardRef<HTMLDivElement, BaseProps>(
|
|
185
|
+
({ children, className, ...props }, ref) => (
|
|
186
|
+
<div
|
|
187
|
+
ref={ref}
|
|
188
|
+
role="group"
|
|
189
|
+
className={cn("tiptap-toolbar-group", className)}
|
|
190
|
+
{...props}
|
|
191
|
+
>
|
|
192
|
+
{children}
|
|
193
|
+
</div>
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
ToolbarGroup.displayName = "ToolbarGroup"
|
|
197
|
+
|
|
198
|
+
export const ToolbarSeparator = forwardRef<HTMLDivElement, BaseProps>(
|
|
199
|
+
({ ...props }, ref) => (
|
|
200
|
+
<Separator ref={ref} orientation="vertical" decorative {...props} />
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
ToolbarSeparator.displayName = "ToolbarSeparator"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tooltip"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.tiptap-tooltip {
|
|
2
|
+
--tt-tooltip-bg: var(--tt-gray-light-900);
|
|
3
|
+
--tt-tooltip-text: var(--white);
|
|
4
|
+
--tt-kbd: var(--tt-gray-dark-a-400);
|
|
5
|
+
|
|
6
|
+
.dark & {
|
|
7
|
+
--tt-tooltip-bg: var(--white);
|
|
8
|
+
--tt-tooltip-text: var(--tt-gray-light-600);
|
|
9
|
+
--tt-kbd: var(--tt-gray-light-a-400);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tiptap-tooltip {
|
|
14
|
+
z-index: 50;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
border-radius: var(--tt-radius-md, 0.375rem);
|
|
17
|
+
background-color: var(--tt-tooltip-bg);
|
|
18
|
+
padding: 0.375rem 0.5rem;
|
|
19
|
+
font-size: 0.75rem;
|
|
20
|
+
font-weight: 500;
|
|
21
|
+
color: var(--tt-tooltip-text);
|
|
22
|
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
|
23
|
+
text-align: center;
|
|
24
|
+
|
|
25
|
+
kbd {
|
|
26
|
+
display: inline-block;
|
|
27
|
+
text-align: center;
|
|
28
|
+
vertical-align: baseline;
|
|
29
|
+
font-family:
|
|
30
|
+
ui-sans-serif,
|
|
31
|
+
system-ui,
|
|
32
|
+
-apple-system,
|
|
33
|
+
BlinkMacSystemFont,
|
|
34
|
+
"Segoe UI",
|
|
35
|
+
Roboto,
|
|
36
|
+
"Helvetica Neue",
|
|
37
|
+
Arial,
|
|
38
|
+
"Noto Sans",
|
|
39
|
+
sans-serif;
|
|
40
|
+
text-transform: capitalize;
|
|
41
|
+
color: var(--tt-kbd);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
cloneElement,
|
|
5
|
+
createContext,
|
|
6
|
+
forwardRef,
|
|
7
|
+
isValidElement,
|
|
8
|
+
useContext,
|
|
9
|
+
useMemo,
|
|
10
|
+
useState,
|
|
11
|
+
version,
|
|
12
|
+
} from "react"
|
|
13
|
+
import {
|
|
14
|
+
useFloating,
|
|
15
|
+
autoUpdate,
|
|
16
|
+
offset,
|
|
17
|
+
flip,
|
|
18
|
+
shift,
|
|
19
|
+
useHover,
|
|
20
|
+
useFocus,
|
|
21
|
+
useDismiss,
|
|
22
|
+
useRole,
|
|
23
|
+
useInteractions,
|
|
24
|
+
useMergeRefs,
|
|
25
|
+
FloatingPortal,
|
|
26
|
+
type Placement,
|
|
27
|
+
type UseFloatingReturn,
|
|
28
|
+
type ReferenceType,
|
|
29
|
+
FloatingDelayGroup,
|
|
30
|
+
} from "@floating-ui/react"
|
|
31
|
+
import "@/components/tiptap-ui-primitive/tooltip/tooltip.scss"
|
|
32
|
+
|
|
33
|
+
interface TooltipProviderProps {
|
|
34
|
+
children: React.ReactNode
|
|
35
|
+
initialOpen?: boolean
|
|
36
|
+
placement?: Placement
|
|
37
|
+
open?: boolean
|
|
38
|
+
onOpenChange?: (open: boolean) => void
|
|
39
|
+
delay?: number
|
|
40
|
+
closeDelay?: number
|
|
41
|
+
timeout?: number
|
|
42
|
+
useDelayGroup?: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface TooltipTriggerProps extends Omit<
|
|
46
|
+
React.HTMLProps<HTMLElement>,
|
|
47
|
+
"ref"
|
|
48
|
+
> {
|
|
49
|
+
asChild?: boolean
|
|
50
|
+
children: React.ReactNode
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface TooltipContentProps extends Omit<
|
|
54
|
+
React.HTMLProps<HTMLDivElement>,
|
|
55
|
+
"ref"
|
|
56
|
+
> {
|
|
57
|
+
children?: React.ReactNode
|
|
58
|
+
portal?: boolean
|
|
59
|
+
portalProps?: Omit<React.ComponentProps<typeof FloatingPortal>, "children">
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface TooltipContextValue extends UseFloatingReturn<ReferenceType> {
|
|
63
|
+
open: boolean
|
|
64
|
+
setOpen: (open: boolean) => void
|
|
65
|
+
getReferenceProps: (
|
|
66
|
+
userProps?: React.HTMLProps<HTMLElement>
|
|
67
|
+
) => Record<string, unknown>
|
|
68
|
+
getFloatingProps: (
|
|
69
|
+
userProps?: React.HTMLProps<HTMLDivElement>
|
|
70
|
+
) => Record<string, unknown>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function useTooltip({
|
|
74
|
+
initialOpen = false,
|
|
75
|
+
placement = "top",
|
|
76
|
+
open: controlledOpen,
|
|
77
|
+
onOpenChange: setControlledOpen,
|
|
78
|
+
delay = 600,
|
|
79
|
+
closeDelay = 0,
|
|
80
|
+
}: Omit<TooltipProviderProps, "children"> = {}) {
|
|
81
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState<boolean>(initialOpen)
|
|
82
|
+
|
|
83
|
+
const open = controlledOpen ?? uncontrolledOpen
|
|
84
|
+
const setOpen = setControlledOpen ?? setUncontrolledOpen
|
|
85
|
+
|
|
86
|
+
const data = useFloating({
|
|
87
|
+
placement,
|
|
88
|
+
open,
|
|
89
|
+
onOpenChange: setOpen,
|
|
90
|
+
whileElementsMounted: autoUpdate,
|
|
91
|
+
middleware: [
|
|
92
|
+
offset(4),
|
|
93
|
+
flip({
|
|
94
|
+
crossAxis: placement.includes("-"),
|
|
95
|
+
fallbackAxisSideDirection: "start",
|
|
96
|
+
padding: 4,
|
|
97
|
+
}),
|
|
98
|
+
shift({ padding: 4 }),
|
|
99
|
+
],
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const context = data.context
|
|
103
|
+
|
|
104
|
+
const hover = useHover(context, {
|
|
105
|
+
mouseOnly: true,
|
|
106
|
+
move: false,
|
|
107
|
+
restMs: delay,
|
|
108
|
+
enabled: controlledOpen == null,
|
|
109
|
+
delay: {
|
|
110
|
+
close: closeDelay,
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
const focus = useFocus(context, {
|
|
114
|
+
enabled: controlledOpen == null,
|
|
115
|
+
})
|
|
116
|
+
const dismiss = useDismiss(context)
|
|
117
|
+
const role = useRole(context, { role: "tooltip" })
|
|
118
|
+
|
|
119
|
+
const interactions = useInteractions([hover, focus, dismiss, role])
|
|
120
|
+
|
|
121
|
+
return useMemo(
|
|
122
|
+
() => ({
|
|
123
|
+
open,
|
|
124
|
+
setOpen,
|
|
125
|
+
...interactions,
|
|
126
|
+
...data,
|
|
127
|
+
}),
|
|
128
|
+
[open, setOpen, interactions, data]
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const TooltipContext = createContext<TooltipContextValue | null>(null)
|
|
133
|
+
|
|
134
|
+
function useTooltipContext() {
|
|
135
|
+
const context = useContext(TooltipContext)
|
|
136
|
+
|
|
137
|
+
if (context == null) {
|
|
138
|
+
throw new Error("Tooltip components must be wrapped in <TooltipProvider />")
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return context
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function Tooltip({ children, ...props }: TooltipProviderProps) {
|
|
145
|
+
const tooltip = useTooltip(props)
|
|
146
|
+
|
|
147
|
+
if (!props.useDelayGroup) {
|
|
148
|
+
return (
|
|
149
|
+
<TooltipContext.Provider value={tooltip}>
|
|
150
|
+
{children}
|
|
151
|
+
</TooltipContext.Provider>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<FloatingDelayGroup
|
|
157
|
+
delay={{ open: props.delay ?? 0, close: props.closeDelay ?? 0 }}
|
|
158
|
+
timeoutMs={props.timeout}
|
|
159
|
+
>
|
|
160
|
+
<TooltipContext.Provider value={tooltip}>
|
|
161
|
+
{children}
|
|
162
|
+
</TooltipContext.Provider>
|
|
163
|
+
</FloatingDelayGroup>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const TooltipTrigger = forwardRef<HTMLElement, TooltipTriggerProps>(
|
|
168
|
+
function TooltipTrigger({ children, asChild = false, ...props }, propRef) {
|
|
169
|
+
const context = useTooltipContext()
|
|
170
|
+
const childrenRef = isValidElement(children)
|
|
171
|
+
? parseInt(version, 10) >= 19
|
|
172
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
|
+
(children as { props: { ref?: React.Ref<any> } }).props.ref
|
|
174
|
+
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
+
(children as any).ref
|
|
176
|
+
: undefined
|
|
177
|
+
const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef])
|
|
178
|
+
|
|
179
|
+
if (asChild && isValidElement(children)) {
|
|
180
|
+
const dataAttributes = {
|
|
181
|
+
"data-tooltip-state": context.open ? "open" : "closed",
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return cloneElement(
|
|
185
|
+
children,
|
|
186
|
+
context.getReferenceProps({
|
|
187
|
+
ref,
|
|
188
|
+
...props,
|
|
189
|
+
...(typeof children.props === "object" ? children.props : {}),
|
|
190
|
+
...dataAttributes,
|
|
191
|
+
})
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<button
|
|
197
|
+
ref={ref}
|
|
198
|
+
data-tooltip-state={context.open ? "open" : "closed"}
|
|
199
|
+
{...context.getReferenceProps(props)}
|
|
200
|
+
>
|
|
201
|
+
{children}
|
|
202
|
+
</button>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
export const TooltipContent = forwardRef<HTMLDivElement, TooltipContentProps>(
|
|
208
|
+
function TooltipContent(
|
|
209
|
+
{ style, children, portal = true, portalProps = {}, ...props },
|
|
210
|
+
propRef
|
|
211
|
+
) {
|
|
212
|
+
const context = useTooltipContext()
|
|
213
|
+
const ref = useMergeRefs([context.refs.setFloating, propRef])
|
|
214
|
+
|
|
215
|
+
if (!context.open) return null
|
|
216
|
+
|
|
217
|
+
const content = (
|
|
218
|
+
<div
|
|
219
|
+
ref={ref}
|
|
220
|
+
style={{
|
|
221
|
+
...context.floatingStyles,
|
|
222
|
+
...style,
|
|
223
|
+
}}
|
|
224
|
+
{...context.getFloatingProps(props)}
|
|
225
|
+
className="tiptap-tooltip"
|
|
226
|
+
>
|
|
227
|
+
{children}
|
|
228
|
+
</div>
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
if (portal) {
|
|
232
|
+
return <FloatingPortal {...portalProps}>{content}</FloatingPortal>
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return content
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
Tooltip.displayName = "Tooltip"
|
|
240
|
+
TooltipTrigger.displayName = "TooltipTrigger"
|
|
241
|
+
TooltipContent.displayName = "TooltipContent"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useRef } from "react"
|
|
4
|
+
|
|
5
|
+
// basically Exclude<React.ClassAttributes<T>["ref"], string>
|
|
6
|
+
type UserRef<T> =
|
|
7
|
+
((instance: T | null) => void) | React.RefObject<T | null> | null | undefined
|
|
8
|
+
|
|
9
|
+
const updateRef = <T>(ref: NonNullable<UserRef<T>>, value: T | null) => {
|
|
10
|
+
if (typeof ref === "function") {
|
|
11
|
+
ref(value)
|
|
12
|
+
} else if (ref && typeof ref === "object" && "current" in ref) {
|
|
13
|
+
// Safe assignment without MutableRefObject
|
|
14
|
+
const mutableRef = ref as { current: T | null }
|
|
15
|
+
mutableRef.current = value
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useComposedRef = <T extends HTMLElement>(
|
|
20
|
+
libRef: React.RefObject<T | null>,
|
|
21
|
+
userRef: UserRef<T>
|
|
22
|
+
) => {
|
|
23
|
+
const prevUserRef = useRef<UserRef<T>>(null)
|
|
24
|
+
|
|
25
|
+
return useCallback(
|
|
26
|
+
(instance: T | null) => {
|
|
27
|
+
if (libRef && "current" in libRef) {
|
|
28
|
+
const mutableLibRef = libRef as { current: T | null }
|
|
29
|
+
mutableLibRef.current = instance
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (prevUserRef.current) {
|
|
33
|
+
updateRef(prevUserRef.current, null)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
prevUserRef.current = userRef
|
|
37
|
+
|
|
38
|
+
if (userRef) {
|
|
39
|
+
updateRef(userRef, instance)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
[libRef, userRef]
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default useComposedRef
|