@nuasite/cms 0.11.0 → 0.12.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/dist/editor.js +4903 -4880
- package/package.json +1 -1
- package/src/editor/index.tsx +38 -1
- package/src/handlers/source-writer.ts +12 -0
package/package.json
CHANGED
package/src/editor/index.tsx
CHANGED
|
@@ -135,7 +135,44 @@ const CmsUI = () => {
|
|
|
135
135
|
}
|
|
136
136
|
}, [])
|
|
137
137
|
|
|
138
|
-
// Send
|
|
138
|
+
// Send select-mode click selection to parent window via postMessage
|
|
139
|
+
const prevSelectModeRef = useRef<string | null>(null)
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const selected = signals.selectModeElement.value
|
|
142
|
+
const id = selected?.id ?? null
|
|
143
|
+
if (id === prevSelectModeRef.current) return
|
|
144
|
+
prevSelectModeRef.current = id
|
|
145
|
+
|
|
146
|
+
if (selected) {
|
|
147
|
+
const manifestData = signals.manifest.value
|
|
148
|
+
const isComponent = selected.type === 'component'
|
|
149
|
+
const cmsId = isComponent ? null : selected.id
|
|
150
|
+
const componentId = isComponent ? selected.id : selected.element.getAttribute('data-cms-component-id') ?? undefined
|
|
151
|
+
const entry = cmsId ? manifestData.entries[cmsId] : undefined
|
|
152
|
+
const instance = componentId ? manifestData.components?.[componentId] : undefined
|
|
153
|
+
const rect = selected.element.getBoundingClientRect()
|
|
154
|
+
|
|
155
|
+
const msg: CmsElementSelectedMessage = {
|
|
156
|
+
type: 'cms-element-selected',
|
|
157
|
+
element: buildSelectedElement({
|
|
158
|
+
cmsId,
|
|
159
|
+
isComponent,
|
|
160
|
+
componentName: isComponent ? selected.label : undefined,
|
|
161
|
+
componentId,
|
|
162
|
+
tagName: selected.element.tagName.toLowerCase(),
|
|
163
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
164
|
+
entry,
|
|
165
|
+
instance,
|
|
166
|
+
}),
|
|
167
|
+
}
|
|
168
|
+
postToParent(msg)
|
|
169
|
+
} else {
|
|
170
|
+
const msg: CmsElementDeselectedMessage = { type: 'cms-element-deselected' }
|
|
171
|
+
postToParent(msg)
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
// Send hovered element info to parent window via postMessage (when inside an iframe)
|
|
139
176
|
const prevOutlineRef = useRef<{ cmsId: string | null; isComponent: boolean }>({ cmsId: null, isComponent: false })
|
|
140
177
|
useEffect(() => {
|
|
141
178
|
const prev = prevOutlineRef.current
|
|
@@ -532,6 +532,18 @@ export function applyTextChange(
|
|
|
532
532
|
const updatedSnippet = sourceSnippet.replace(resolvedOriginal, resolvedNewText)
|
|
533
533
|
|
|
534
534
|
if (updatedSnippet === sourceSnippet) {
|
|
535
|
+
// Try with <br> tag normalization (browser normalizes <br /> to <br>)
|
|
536
|
+
const brNorm = (s: string) => s.replace(/<br\s*\/?>/gi, '<br>')
|
|
537
|
+
if (brNorm(sourceSnippet).includes(brNorm(resolvedOriginal))) {
|
|
538
|
+
const parts = resolvedOriginal.split(/<br\s*\/?>/gi)
|
|
539
|
+
const regexStr = parts.map((p) => escapeRegExp(p)).join('<br\\s*\\/?>')
|
|
540
|
+
const brRegex = new RegExp(regexStr)
|
|
541
|
+
const updatedWithBr = sourceSnippet.replace(brRegex, resolvedNewText)
|
|
542
|
+
if (updatedWithBr !== sourceSnippet) {
|
|
543
|
+
return { success: true, content: content.replace(sourceSnippet, updatedWithBr) }
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
535
547
|
// resolvedOriginal wasn't found in snippet - try HTML entity handling
|
|
536
548
|
const matchedText = findTextInSnippet(sourceSnippet, resolvedOriginal)
|
|
537
549
|
if (matchedText) {
|