@nuasite/cms 0.1.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/README.md +237 -0
- package/dist/src/build-processor.d.ts +20 -0
- package/dist/src/build-processor.d.ts.map +1 -0
- package/dist/src/collection-scanner.d.ts +6 -0
- package/dist/src/collection-scanner.d.ts.map +1 -0
- package/dist/src/component-registry.d.ts +63 -0
- package/dist/src/component-registry.d.ts.map +1 -0
- package/dist/src/config.d.ts +24 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/dev-middleware.d.ts +20 -0
- package/dist/src/dev-middleware.d.ts.map +1 -0
- package/dist/src/editor/ai.d.ts +60 -0
- package/dist/src/editor/ai.d.ts.map +1 -0
- package/dist/src/editor/api.d.ts +140 -0
- package/dist/src/editor/api.d.ts.map +1 -0
- package/dist/src/editor/color-utils.d.ts +106 -0
- package/dist/src/editor/color-utils.d.ts.map +1 -0
- package/dist/src/editor/components/ai-chat.d.ts +11 -0
- package/dist/src/editor/components/ai-chat.d.ts.map +1 -0
- package/dist/src/editor/components/ai-tooltip.d.ts +12 -0
- package/dist/src/editor/components/ai-tooltip.d.ts.map +1 -0
- package/dist/src/editor/components/attribute-editor.d.ts +5 -0
- package/dist/src/editor/components/attribute-editor.d.ts.map +1 -0
- package/dist/src/editor/components/block-editor.d.ts +12 -0
- package/dist/src/editor/components/block-editor.d.ts.map +1 -0
- package/dist/src/editor/components/collections-browser.d.ts +2 -0
- package/dist/src/editor/components/collections-browser.d.ts.map +1 -0
- package/dist/src/editor/components/color-toolbar.d.ts +12 -0
- package/dist/src/editor/components/color-toolbar.d.ts.map +1 -0
- package/dist/src/editor/components/confirm-dialog.d.ts +2 -0
- package/dist/src/editor/components/confirm-dialog.d.ts.map +1 -0
- package/dist/src/editor/components/create-page-modal.d.ts +2 -0
- package/dist/src/editor/components/create-page-modal.d.ts.map +1 -0
- package/dist/src/editor/components/editable-highlights.d.ts +9 -0
- package/dist/src/editor/components/editable-highlights.d.ts.map +1 -0
- package/dist/src/editor/components/error-boundary.d.ts +32 -0
- package/dist/src/editor/components/error-boundary.d.ts.map +1 -0
- package/dist/src/editor/components/fields.d.ts +75 -0
- package/dist/src/editor/components/fields.d.ts.map +1 -0
- package/dist/src/editor/components/frontmatter-fields.d.ts +29 -0
- package/dist/src/editor/components/frontmatter-fields.d.ts.map +1 -0
- package/dist/src/editor/components/highlight-overlay.d.ts +64 -0
- package/dist/src/editor/components/highlight-overlay.d.ts.map +1 -0
- package/dist/src/editor/components/image-overlay.d.ts +12 -0
- package/dist/src/editor/components/image-overlay.d.ts.map +1 -0
- package/dist/src/editor/components/markdown-editor-overlay.d.ts +6 -0
- package/dist/src/editor/components/markdown-editor-overlay.d.ts.map +1 -0
- package/dist/src/editor/components/markdown-inline-editor.d.ts +10 -0
- package/dist/src/editor/components/markdown-inline-editor.d.ts.map +1 -0
- package/dist/src/editor/components/media-library.d.ts +2 -0
- package/dist/src/editor/components/media-library.d.ts.map +1 -0
- package/dist/src/editor/components/outline.d.ts +21 -0
- package/dist/src/editor/components/outline.d.ts.map +1 -0
- package/dist/src/editor/components/redirect-countdown.d.ts +2 -0
- package/dist/src/editor/components/redirect-countdown.d.ts.map +1 -0
- package/dist/src/editor/components/seo-editor.d.ts +2 -0
- package/dist/src/editor/components/seo-editor.d.ts.map +1 -0
- package/dist/src/editor/components/text-style-toolbar.d.ts +8 -0
- package/dist/src/editor/components/text-style-toolbar.d.ts.map +1 -0
- package/dist/src/editor/components/toast/toast-container.d.ts +7 -0
- package/dist/src/editor/components/toast/toast-container.d.ts.map +1 -0
- package/dist/src/editor/components/toast/toast.d.ts +7 -0
- package/dist/src/editor/components/toast/toast.d.ts.map +1 -0
- package/dist/src/editor/components/toast/types.d.ts +7 -0
- package/dist/src/editor/components/toast/types.d.ts.map +1 -0
- package/dist/src/editor/components/toolbar.d.ts +21 -0
- package/dist/src/editor/components/toolbar.d.ts.map +1 -0
- package/dist/src/editor/config.d.ts +4 -0
- package/dist/src/editor/config.d.ts.map +1 -0
- package/dist/src/editor/constants.d.ts +101 -0
- package/dist/src/editor/constants.d.ts.map +1 -0
- package/dist/src/editor/context.d.ts +14 -0
- package/dist/src/editor/context.d.ts.map +1 -0
- package/dist/src/editor/dom.d.ts +77 -0
- package/dist/src/editor/dom.d.ts.map +1 -0
- package/dist/src/editor/editor.d.ts +64 -0
- package/dist/src/editor/editor.d.ts.map +1 -0
- package/dist/src/editor/history.d.ts +20 -0
- package/dist/src/editor/history.d.ts.map +1 -0
- package/dist/src/editor/hooks/index.d.ts +14 -0
- package/dist/src/editor/hooks/index.d.ts.map +1 -0
- package/dist/src/editor/hooks/useAIHandlers.d.ts +22 -0
- package/dist/src/editor/hooks/useAIHandlers.d.ts.map +1 -0
- package/dist/src/editor/hooks/useBlockEditorHandlers.d.ts +18 -0
- package/dist/src/editor/hooks/useBlockEditorHandlers.d.ts.map +1 -0
- package/dist/src/editor/hooks/useElementDetection.d.ts +26 -0
- package/dist/src/editor/hooks/useElementDetection.d.ts.map +1 -0
- package/dist/src/editor/hooks/useImageHoverDetection.d.ts +12 -0
- package/dist/src/editor/hooks/useImageHoverDetection.d.ts.map +1 -0
- package/dist/src/editor/hooks/useTextSelection.d.ts +23 -0
- package/dist/src/editor/hooks/useTextSelection.d.ts.map +1 -0
- package/dist/src/editor/hooks/useTooltipState.d.ts +19 -0
- package/dist/src/editor/hooks/useTooltipState.d.ts.map +1 -0
- package/dist/src/editor/hooks/utils.d.ts +32 -0
- package/dist/src/editor/hooks/utils.d.ts.map +1 -0
- package/dist/src/editor/index.d.ts +12 -0
- package/dist/src/editor/index.d.ts.map +1 -0
- package/dist/src/editor/lib/cn.d.ts +3 -0
- package/dist/src/editor/lib/cn.d.ts.map +1 -0
- package/dist/src/editor/manifest.d.ts +19 -0
- package/dist/src/editor/manifest.d.ts.map +1 -0
- package/dist/src/editor/markdown-api.d.ts +36 -0
- package/dist/src/editor/markdown-api.d.ts.map +1 -0
- package/dist/src/editor/signals.d.ts +242 -0
- package/dist/src/editor/signals.d.ts.map +1 -0
- package/dist/src/editor/storage.d.ts +27 -0
- package/dist/src/editor/storage.d.ts.map +1 -0
- package/dist/src/editor/text-styling.d.ts +350 -0
- package/dist/src/editor/text-styling.d.ts.map +1 -0
- package/dist/src/editor/themes.d.ts +38 -0
- package/dist/src/editor/themes.d.ts.map +1 -0
- package/dist/src/editor/types.d.ts +454 -0
- package/dist/src/editor/types.d.ts.map +1 -0
- package/dist/src/error-collector.d.ts +56 -0
- package/dist/src/error-collector.d.ts.map +1 -0
- package/dist/src/handlers/component-ops.d.ts +34 -0
- package/dist/src/handlers/component-ops.d.ts.map +1 -0
- package/dist/src/handlers/markdown-ops.d.ts +41 -0
- package/dist/src/handlers/markdown-ops.d.ts.map +1 -0
- package/dist/src/handlers/request-utils.d.ts +20 -0
- package/dist/src/handlers/request-utils.d.ts.map +1 -0
- package/dist/src/handlers/source-writer.d.ts +51 -0
- package/dist/src/handlers/source-writer.d.ts.map +1 -0
- package/dist/src/html-processor.d.ts +63 -0
- package/dist/src/html-processor.d.ts.map +1 -0
- package/dist/src/index.d.ts +41 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/manifest-writer.d.ts +111 -0
- package/dist/src/manifest-writer.d.ts.map +1 -0
- package/dist/src/media/contember.d.ts +15 -0
- package/dist/src/media/contember.d.ts.map +1 -0
- package/dist/src/media/local.d.ts +9 -0
- package/dist/src/media/local.d.ts.map +1 -0
- package/dist/src/media/s3.d.ts +12 -0
- package/dist/src/media/s3.d.ts.map +1 -0
- package/dist/src/media/types.d.ts +40 -0
- package/dist/src/media/types.d.ts.map +1 -0
- package/dist/src/preview-generator.d.ts +19 -0
- package/dist/src/preview-generator.d.ts.map +1 -0
- package/dist/src/seo-processor.d.ts +23 -0
- package/dist/src/seo-processor.d.ts.map +1 -0
- package/dist/src/source-finder/ast-extractors.d.ts +35 -0
- package/dist/src/source-finder/ast-extractors.d.ts.map +1 -0
- package/dist/src/source-finder/ast-parser.d.ts +16 -0
- package/dist/src/source-finder/ast-parser.d.ts.map +1 -0
- package/dist/src/source-finder/cache.d.ts +18 -0
- package/dist/src/source-finder/cache.d.ts.map +1 -0
- package/dist/src/source-finder/collection-finder.d.ts +29 -0
- package/dist/src/source-finder/collection-finder.d.ts.map +1 -0
- package/dist/src/source-finder/cross-file-tracker.d.ts +39 -0
- package/dist/src/source-finder/cross-file-tracker.d.ts.map +1 -0
- package/dist/src/source-finder/element-finder.d.ts +42 -0
- package/dist/src/source-finder/element-finder.d.ts.map +1 -0
- package/dist/src/source-finder/image-finder.d.ts +24 -0
- package/dist/src/source-finder/image-finder.d.ts.map +1 -0
- package/dist/src/source-finder/index.d.ts +9 -0
- package/dist/src/source-finder/index.d.ts.map +1 -0
- package/dist/src/source-finder/search-index.d.ts +27 -0
- package/dist/src/source-finder/search-index.d.ts.map +1 -0
- package/dist/src/source-finder/snippet-utils.d.ts +90 -0
- package/dist/src/source-finder/snippet-utils.d.ts.map +1 -0
- package/dist/src/source-finder/source-lookup.d.ts +16 -0
- package/dist/src/source-finder/source-lookup.d.ts.map +1 -0
- package/dist/src/source-finder/types.d.ts +167 -0
- package/dist/src/source-finder/types.d.ts.map +1 -0
- package/dist/src/source-finder/variable-extraction.d.ts +37 -0
- package/dist/src/source-finder/variable-extraction.d.ts.map +1 -0
- package/dist/src/tailwind-colors.d.ts +54 -0
- package/dist/src/tailwind-colors.d.ts.map +1 -0
- package/dist/src/tsconfig.tsbuildinfo +1 -0
- package/dist/src/types.d.ts +367 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils.d.ts +61 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/vite-plugin.d.ts +14 -0
- package/dist/src/vite-plugin.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +80 -0
- package/src/build-processor.ts +784 -0
- package/src/collection-scanner.ts +304 -0
- package/src/component-registry.ts +393 -0
- package/src/config.ts +74 -0
- package/src/dev-middleware.ts +525 -0
- package/src/dist/src/tsconfig.tsbuildinfo +1 -0
- package/src/editor/ai.ts +185 -0
- package/src/editor/api.ts +513 -0
- package/src/editor/color-utils.ts +556 -0
- package/src/editor/components/ai-chat.tsx +632 -0
- package/src/editor/components/ai-tooltip.tsx +179 -0
- package/src/editor/components/attribute-editor.tsx +596 -0
- package/src/editor/components/block-editor.tsx +546 -0
- package/src/editor/components/collections-browser.tsx +248 -0
- package/src/editor/components/color-toolbar.tsx +314 -0
- package/src/editor/components/confirm-dialog.tsx +69 -0
- package/src/editor/components/create-page-modal.tsx +163 -0
- package/src/editor/components/editable-highlights.tsx +260 -0
- package/src/editor/components/error-boundary.tsx +87 -0
- package/src/editor/components/fields.tsx +387 -0
- package/src/editor/components/frontmatter-fields.tsx +469 -0
- package/src/editor/components/highlight-overlay.ts +229 -0
- package/src/editor/components/image-overlay.tsx +230 -0
- package/src/editor/components/markdown-editor-overlay.tsx +505 -0
- package/src/editor/components/markdown-inline-editor.tsx +780 -0
- package/src/editor/components/media-library.tsx +297 -0
- package/src/editor/components/outline.tsx +402 -0
- package/src/editor/components/redirect-countdown.tsx +45 -0
- package/src/editor/components/seo-editor.tsx +498 -0
- package/src/editor/components/text-style-toolbar.tsx +362 -0
- package/src/editor/components/toast/toast-container.tsx +15 -0
- package/src/editor/components/toast/toast.tsx +49 -0
- package/src/editor/components/toast/types.ts +7 -0
- package/src/editor/components/toolbar.tsx +366 -0
- package/src/editor/config.ts +12 -0
- package/src/editor/constants.ts +106 -0
- package/src/editor/context.tsx +38 -0
- package/src/editor/dom.ts +357 -0
- package/src/editor/editor.ts +1510 -0
- package/src/editor/env.d.ts +4 -0
- package/src/editor/history.ts +355 -0
- package/src/editor/hooks/index.ts +19 -0
- package/src/editor/hooks/useAIHandlers.ts +345 -0
- package/src/editor/hooks/useBlockEditorHandlers.ts +206 -0
- package/src/editor/hooks/useElementDetection.ts +284 -0
- package/src/editor/hooks/useImageHoverDetection.ts +102 -0
- package/src/editor/hooks/useTextSelection.ts +187 -0
- package/src/editor/hooks/useTooltipState.ts +126 -0
- package/src/editor/hooks/utils.ts +101 -0
- package/src/editor/index.tsx +481 -0
- package/src/editor/lib/cn.ts +4 -0
- package/src/editor/manifest.ts +25 -0
- package/src/editor/markdown-api.ts +209 -0
- package/src/editor/signals.ts +1351 -0
- package/src/editor/storage.ts +266 -0
- package/src/editor/styles.css +465 -0
- package/src/editor/text-styling.ts +773 -0
- package/src/editor/themes.ts +210 -0
- package/src/editor/types.ts +591 -0
- package/src/error-collector.ts +106 -0
- package/src/handlers/component-ops.ts +463 -0
- package/src/handlers/markdown-ops.ts +202 -0
- package/src/handlers/request-utils.ts +151 -0
- package/src/handlers/source-writer.ts +649 -0
- package/src/html-processor.ts +1108 -0
- package/src/index.ts +284 -0
- package/src/manifest-writer.ts +371 -0
- package/src/media/contember.ts +84 -0
- package/src/media/local.ts +114 -0
- package/src/media/s3.ts +133 -0
- package/src/media/types.ts +33 -0
- package/src/preview-generator.ts +293 -0
- package/src/seo-processor.ts +567 -0
- package/src/source-finder/ast-extractors.ts +185 -0
- package/src/source-finder/ast-parser.ts +150 -0
- package/src/source-finder/cache.ts +76 -0
- package/src/source-finder/collection-finder.ts +335 -0
- package/src/source-finder/cross-file-tracker.ts +741 -0
- package/src/source-finder/element-finder.ts +387 -0
- package/src/source-finder/image-finder.ts +283 -0
- package/src/source-finder/index.ts +37 -0
- package/src/source-finder/search-index.ts +525 -0
- package/src/source-finder/snippet-utils.ts +668 -0
- package/src/source-finder/source-lookup.ts +200 -0
- package/src/source-finder/types.ts +210 -0
- package/src/source-finder/variable-extraction.ts +406 -0
- package/src/tailwind-colors.ts +874 -0
- package/src/tsconfig.json +25 -0
- package/src/types.ts +406 -0
- package/src/utils.ts +186 -0
- package/src/vite-plugin.ts +42 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'preact/hooks'
|
|
2
|
+
import { Z_INDEX } from '../constants'
|
|
3
|
+
import * as signals from '../signals'
|
|
4
|
+
|
|
5
|
+
export interface ImageOverlayProps {
|
|
6
|
+
visible: boolean
|
|
7
|
+
rect: DOMRect | null
|
|
8
|
+
element: HTMLImageElement | null
|
|
9
|
+
cmsId: string | null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Shadow DOM-based image overlay component.
|
|
14
|
+
* Shows a clickable overlay on image elements to guide users to replace images.
|
|
15
|
+
*/
|
|
16
|
+
export function ImageOverlay({ visible, rect, element, cmsId }: ImageOverlayProps) {
|
|
17
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
18
|
+
const shadowRootRef = useRef<ShadowRoot | null>(null)
|
|
19
|
+
const overlayRef = useRef<HTMLDivElement | null>(null)
|
|
20
|
+
|
|
21
|
+
// Initialize Shadow DOM once
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (containerRef.current && !shadowRootRef.current) {
|
|
24
|
+
shadowRootRef.current = containerRef.current.attachShadow({ mode: 'open' })
|
|
25
|
+
|
|
26
|
+
// Create styles
|
|
27
|
+
const style = document.createElement('style')
|
|
28
|
+
style.textContent = `
|
|
29
|
+
:host {
|
|
30
|
+
position: fixed;
|
|
31
|
+
top: 0;
|
|
32
|
+
left: 0;
|
|
33
|
+
pointer-events: none;
|
|
34
|
+
z-index: ${Z_INDEX.HIGHLIGHT};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.image-overlay {
|
|
38
|
+
position: fixed;
|
|
39
|
+
box-sizing: border-box;
|
|
40
|
+
transition: all 150ms ease;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
pointer-events: auto;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
background: rgba(26, 26, 26, 0.7);
|
|
47
|
+
border: 2px solid rgba(255, 255, 255, 0.1);
|
|
48
|
+
border-radius: 16px;
|
|
49
|
+
backdrop-filter: blur(4px);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.image-overlay.hidden {
|
|
53
|
+
opacity: 0;
|
|
54
|
+
pointer-events: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.image-overlay.visible {
|
|
58
|
+
opacity: 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.image-overlay:hover {
|
|
62
|
+
background: rgba(26, 26, 26, 0.85);
|
|
63
|
+
border-color: rgba(223, 255, 64, 0.5);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.overlay-content {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
align-items: center;
|
|
70
|
+
gap: 10px;
|
|
71
|
+
color: white;
|
|
72
|
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.overlay-icon {
|
|
76
|
+
width: 32px;
|
|
77
|
+
height: 32px;
|
|
78
|
+
fill: currentColor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.overlay-text {
|
|
82
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
|
83
|
+
font-size: 13px;
|
|
84
|
+
font-weight: 500;
|
|
85
|
+
background: rgba(255, 255, 255, 0.1);
|
|
86
|
+
padding: 8px 16px;
|
|
87
|
+
border-radius: 9999px;
|
|
88
|
+
}
|
|
89
|
+
`
|
|
90
|
+
|
|
91
|
+
overlayRef.current = document.createElement('div')
|
|
92
|
+
overlayRef.current.className = 'image-overlay hidden'
|
|
93
|
+
overlayRef.current.innerHTML = `
|
|
94
|
+
<div class="overlay-content">
|
|
95
|
+
<svg class="overlay-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
96
|
+
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
|
|
97
|
+
</svg>
|
|
98
|
+
<span class="overlay-text">Change image</span>
|
|
99
|
+
</div>
|
|
100
|
+
`
|
|
101
|
+
|
|
102
|
+
shadowRootRef.current.appendChild(style)
|
|
103
|
+
shadowRootRef.current.appendChild(overlayRef.current)
|
|
104
|
+
}
|
|
105
|
+
}, [])
|
|
106
|
+
|
|
107
|
+
// Handle click on overlay
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!overlayRef.current) return
|
|
110
|
+
|
|
111
|
+
const handleClick = (e: MouseEvent) => {
|
|
112
|
+
if (!element || !cmsId) return
|
|
113
|
+
|
|
114
|
+
// Check if there's an editable text element at this position that should take precedence
|
|
115
|
+
// This allows clicking on text that's positioned over images
|
|
116
|
+
const elementsAtPoint = document.elementsFromPoint(e.clientX, e.clientY)
|
|
117
|
+
for (const el of elementsAtPoint) {
|
|
118
|
+
// If we hit the image first, capture the click for the overlay
|
|
119
|
+
if (el === element) break
|
|
120
|
+
|
|
121
|
+
// If there's a contentEditable element above the image, forward the click to it
|
|
122
|
+
if (el instanceof HTMLElement && el.contentEditable === 'true') {
|
|
123
|
+
e.preventDefault()
|
|
124
|
+
e.stopPropagation()
|
|
125
|
+
// Focus the element and place cursor at click position
|
|
126
|
+
el.focus()
|
|
127
|
+
// Try to place cursor at the click position using caretPositionFromPoint
|
|
128
|
+
const caretPos = document.caretPositionFromPoint?.(e.clientX, e.clientY)
|
|
129
|
+
?? (document as { caretRangeFromPoint?: (x: number, y: number) => Range | null }).caretRangeFromPoint?.(e.clientX, e.clientY)
|
|
130
|
+
if (caretPos) {
|
|
131
|
+
const selection = window.getSelection()
|
|
132
|
+
if (selection) {
|
|
133
|
+
selection.removeAllRanges()
|
|
134
|
+
const range = document.createRange()
|
|
135
|
+
if ('offsetNode' in caretPos) {
|
|
136
|
+
// caretPositionFromPoint result
|
|
137
|
+
range.setStart(caretPos.offsetNode, caretPos.offset)
|
|
138
|
+
} else {
|
|
139
|
+
// caretRangeFromPoint result (Range)
|
|
140
|
+
range.setStart(caretPos.startContainer, caretPos.startOffset)
|
|
141
|
+
}
|
|
142
|
+
range.collapse(true)
|
|
143
|
+
selection.addRange(range)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
e.preventDefault()
|
|
151
|
+
e.stopPropagation()
|
|
152
|
+
|
|
153
|
+
// Open media library with callback to replace the image
|
|
154
|
+
signals.openMediaLibraryWithCallback((url: string, alt: string) => {
|
|
155
|
+
// Track the change BEFORE modifying element.src
|
|
156
|
+
const currentChange = signals.getPendingImageChange(cmsId)
|
|
157
|
+
const originalSrc = currentChange?.originalSrc ?? element.getAttribute('src') ?? element.src
|
|
158
|
+
const originalAlt = currentChange?.originalAlt ?? element.alt ?? ''
|
|
159
|
+
const originalSrcSet = currentChange?.originalSrcSet ?? element.getAttribute('srcset') ?? ''
|
|
160
|
+
const isDirty = url !== originalSrc
|
|
161
|
+
|
|
162
|
+
// Update the image element
|
|
163
|
+
element.src = url
|
|
164
|
+
// Clear srcset so browser uses the new src
|
|
165
|
+
element.removeAttribute('srcset')
|
|
166
|
+
if (alt) {
|
|
167
|
+
element.alt = alt
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (currentChange) {
|
|
171
|
+
signals.updatePendingImageChange(cmsId, (change) => ({
|
|
172
|
+
...change,
|
|
173
|
+
newSrc: url,
|
|
174
|
+
newAlt: alt || change.originalAlt,
|
|
175
|
+
isDirty,
|
|
176
|
+
}))
|
|
177
|
+
} else {
|
|
178
|
+
// Create pending change if it doesn't exist
|
|
179
|
+
signals.setPendingImageChange(cmsId, {
|
|
180
|
+
element,
|
|
181
|
+
originalSrc,
|
|
182
|
+
newSrc: url,
|
|
183
|
+
originalAlt,
|
|
184
|
+
newAlt: alt || originalAlt,
|
|
185
|
+
originalSrcSet,
|
|
186
|
+
isDirty,
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
overlayRef.current.addEventListener('click', handleClick)
|
|
193
|
+
return () => {
|
|
194
|
+
overlayRef.current?.removeEventListener('click', handleClick)
|
|
195
|
+
}
|
|
196
|
+
}, [element, cmsId])
|
|
197
|
+
|
|
198
|
+
// Update overlay visibility and position
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
if (!overlayRef.current) return
|
|
201
|
+
|
|
202
|
+
if (!visible || !rect) {
|
|
203
|
+
overlayRef.current.className = 'image-overlay hidden'
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
overlayRef.current.className = 'image-overlay visible'
|
|
208
|
+
|
|
209
|
+
// Position the overlay to cover the image
|
|
210
|
+
overlayRef.current.style.left = `${rect.left}px`
|
|
211
|
+
overlayRef.current.style.top = `${rect.top}px`
|
|
212
|
+
overlayRef.current.style.width = `${rect.width}px`
|
|
213
|
+
overlayRef.current.style.height = `${rect.height}px`
|
|
214
|
+
}, [visible, rect])
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div
|
|
218
|
+
ref={containerRef}
|
|
219
|
+
style={{
|
|
220
|
+
position: 'fixed',
|
|
221
|
+
top: 0,
|
|
222
|
+
left: 0,
|
|
223
|
+
width: 0,
|
|
224
|
+
height: 0,
|
|
225
|
+
pointerEvents: 'none',
|
|
226
|
+
zIndex: Z_INDEX.HIGHLIGHT,
|
|
227
|
+
}}
|
|
228
|
+
/>
|
|
229
|
+
)
|
|
230
|
+
}
|