@prenta/admin 0.95.1 → 0.96.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/CHANGELOG.md +22 -0
- package/dist/__tests__/styles/responsive-layer.test.js +2 -2
- package/dist/__tests__/styles/responsive-layer.test.js.map +1 -1
- package/dist/__tests__/views/canvas-surface-shared.test.d.ts +2 -0
- package/dist/__tests__/views/canvas-surface-shared.test.d.ts.map +1 -0
- package/dist/__tests__/views/canvas-surface-shared.test.js +53 -0
- package/dist/__tests__/views/canvas-surface-shared.test.js.map +1 -0
- package/dist/__tests__/views/post-section-editor.test.js +41 -0
- package/dist/__tests__/views/post-section-editor.test.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/views/page-editor/CanvasSurface.d.ts +55 -0
- package/dist/views/page-editor/CanvasSurface.d.ts.map +1 -0
- package/dist/views/page-editor/CanvasSurface.js +94 -0
- package/dist/views/page-editor/CanvasSurface.js.map +1 -0
- package/dist/views/page-editor/EditorCanvas.d.ts +5 -28
- package/dist/views/page-editor/EditorCanvas.d.ts.map +1 -1
- package/dist/views/page-editor/EditorCanvas.js +17 -79
- package/dist/views/page-editor/EditorCanvas.js.map +1 -1
- package/dist/views/post-editor/PostEditorCanvas.d.ts +16 -5
- package/dist/views/post-editor/PostEditorCanvas.d.ts.map +1 -1
- package/dist/views/post-editor/PostEditorCanvas.js +16 -47
- package/dist/views/post-editor/PostEditorCanvas.js.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.js +82 -22
- package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/styles/responsive-layer.test.ts +2 -2
- package/src/__tests__/views/canvas-surface-shared.test.ts +61 -0
- package/src/__tests__/views/post-section-editor.test.tsx +62 -0
- package/src/views/page-editor/CanvasSurface.tsx +171 -0
- package/src/views/page-editor/EditorCanvas.tsx +46 -144
- package/src/views/post-editor/PostEditorCanvas.tsx +54 -74
- package/src/views/post-editor/PostSectionEditor.tsx +180 -81
- package/dist/components/EditorSeoAside.d.ts +0 -23
- package/dist/components/EditorSeoAside.d.ts.map +0 -1
- package/dist/components/EditorSeoAside.js +0 -21
- package/dist/components/EditorSeoAside.js.map +0 -1
- package/src/components/EditorSeoAside.tsx +0 -68
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type BreakpointId, type Zoom } from '../../lib/breakpoints.js';
|
|
2
|
+
export interface CanvasSurfaceProps {
|
|
3
|
+
breakpoint: BreakpointId;
|
|
4
|
+
zoom?: Zoom;
|
|
5
|
+
/**
|
|
6
|
+
* Reports the measured scale so the header's zoom chip can show a real
|
|
7
|
+
* percentage. Only the canvas knows the available width, so the number has
|
|
8
|
+
* to travel up rather than being recomputed by the header.
|
|
9
|
+
*/
|
|
10
|
+
onScaleChange?: (scale: number) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Reports the canvas surface element, so the reflow guard can clone it. The
|
|
13
|
+
* guard needs the real element rather than a `document.querySelector`, which
|
|
14
|
+
* would also match the site-preview frame's canvas when that is mounted.
|
|
15
|
+
*/
|
|
16
|
+
onCanvasElement?: (el: HTMLElement | null) => void;
|
|
17
|
+
/** Tips, notices, or the review bar — rendered above the meta line. */
|
|
18
|
+
chrome?: React.ReactNode;
|
|
19
|
+
/** The page itself. Rendered inside the scaled, container-queried surface. */
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The scaled preview surface, shared by the page and post editors.
|
|
24
|
+
*
|
|
25
|
+
* The canvas renders at the breakpoint's **real CSS width** and is scaled down
|
|
26
|
+
* with a transform. Combined with `container-type: inline-size`, that makes the
|
|
27
|
+
* page reflow against its own width — the same container queries that style the
|
|
28
|
+
* live page decide the layout. A max-width clamp cannot do this: it yields a
|
|
29
|
+
* narrow desktop layout rather than the mobile one.
|
|
30
|
+
*
|
|
31
|
+
* Extracted because the arithmetic was being maintained in two places and got
|
|
32
|
+
* it wrong in one of them (see the `clientWidth - 48` entry in
|
|
33
|
+
* docs/page-builder-handoff-followups.md). The editors differ only in what
|
|
34
|
+
* they put INSIDE the surface — the post editor renders a header above its
|
|
35
|
+
* sections — and not at all in how it is measured, sized or scaled.
|
|
36
|
+
*
|
|
37
|
+
* Two measurement rules, both learned the hard way:
|
|
38
|
+
*
|
|
39
|
+
* 1. Available width comes from a **zero-height sentinel** rendered as the
|
|
40
|
+
* panel's first child, not from `panel.clientWidth - padding`. The two
|
|
41
|
+
* disagree once a scrollbar appears or the host scales the preview, and
|
|
42
|
+
* the padding arithmetic silently rots whenever the gutter changes.
|
|
43
|
+
* 2. Both measurements are re-taken on **every render**, not only from the
|
|
44
|
+
* ResizeObserver. Page height changes with every text edit, image swap and
|
|
45
|
+
* show/hide — none of which resize the observed elements. The observer
|
|
46
|
+
* exists for later window resizes; its first callback is not a substitute.
|
|
47
|
+
*/
|
|
48
|
+
export declare function CanvasSurface({ breakpoint, zoom, onScaleChange, onCanvasElement, chrome, children, }: CanvasSurfaceProps): import("react/jsx-runtime").JSX.Element;
|
|
49
|
+
/** The scroll container both editors wrap their surface in. */
|
|
50
|
+
export declare function CanvasScroll({ children }: {
|
|
51
|
+
children: React.ReactNode;
|
|
52
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
/** Registers section DOM nodes so the canvas can scroll one into view. */
|
|
54
|
+
export declare function useSectionRefs(selectedId: string | null): (id: string, el: HTMLElement | null) => void;
|
|
55
|
+
//# sourceMappingURL=CanvasSurface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasSurface.d.ts","sourceRoot":"","sources":["../../../src/views/page-editor/CanvasSurface.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA2B,KAAK,YAAY,EAAE,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAEhG,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,YAAY,CAAA;IACxB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;IAClD,uEAAuE;IACvE,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,IAAY,EACZ,aAAa,EACb,eAAe,EACf,MAAM,EACN,QAAQ,GACT,EAAE,kBAAkB,2CAoFpB;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAMvE;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,QAGjB,MAAM,MAAM,WAAW,GAAG,IAAI,UAWpE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { CanvasMetaLine } from './CanvasMetaLine.js';
|
|
5
|
+
import { fitScale, getBreakpoint } from '../../lib/breakpoints.js';
|
|
6
|
+
/**
|
|
7
|
+
* The scaled preview surface, shared by the page and post editors.
|
|
8
|
+
*
|
|
9
|
+
* The canvas renders at the breakpoint's **real CSS width** and is scaled down
|
|
10
|
+
* with a transform. Combined with `container-type: inline-size`, that makes the
|
|
11
|
+
* page reflow against its own width — the same container queries that style the
|
|
12
|
+
* live page decide the layout. A max-width clamp cannot do this: it yields a
|
|
13
|
+
* narrow desktop layout rather than the mobile one.
|
|
14
|
+
*
|
|
15
|
+
* Extracted because the arithmetic was being maintained in two places and got
|
|
16
|
+
* it wrong in one of them (see the `clientWidth - 48` entry in
|
|
17
|
+
* docs/page-builder-handoff-followups.md). The editors differ only in what
|
|
18
|
+
* they put INSIDE the surface — the post editor renders a header above its
|
|
19
|
+
* sections — and not at all in how it is measured, sized or scaled.
|
|
20
|
+
*
|
|
21
|
+
* Two measurement rules, both learned the hard way:
|
|
22
|
+
*
|
|
23
|
+
* 1. Available width comes from a **zero-height sentinel** rendered as the
|
|
24
|
+
* panel's first child, not from `panel.clientWidth - padding`. The two
|
|
25
|
+
* disagree once a scrollbar appears or the host scales the preview, and
|
|
26
|
+
* the padding arithmetic silently rots whenever the gutter changes.
|
|
27
|
+
* 2. Both measurements are re-taken on **every render**, not only from the
|
|
28
|
+
* ResizeObserver. Page height changes with every text edit, image swap and
|
|
29
|
+
* show/hide — none of which resize the observed elements. The observer
|
|
30
|
+
* exists for later window resizes; its first callback is not a substitute.
|
|
31
|
+
*/
|
|
32
|
+
export function CanvasSurface({ breakpoint, zoom = 'fit', onScaleChange, onCanvasElement, chrome, children, }) {
|
|
33
|
+
const bp = getBreakpoint(breakpoint);
|
|
34
|
+
const sentinelRef = useRef(null);
|
|
35
|
+
const surfaceRef = useRef(null);
|
|
36
|
+
const [available, setAvailable] = useState(0);
|
|
37
|
+
const [pageHeight, setPageHeight] = useState(0);
|
|
38
|
+
// No dependency array: page height changes on edits that resize nothing the
|
|
39
|
+
// observer watches. Both setters bail when the value is unchanged, so this
|
|
40
|
+
// settles after one extra pass instead of looping.
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
const measure = () => {
|
|
43
|
+
const sentinelWidth = sentinelRef.current?.offsetWidth ?? 0;
|
|
44
|
+
if (sentinelWidth > 0)
|
|
45
|
+
setAvailable((prev) => (prev === sentinelWidth ? prev : sentinelWidth));
|
|
46
|
+
const height = surfaceRef.current?.offsetHeight ?? 0;
|
|
47
|
+
if (height > 0)
|
|
48
|
+
setPageHeight((prev) => (prev === height ? prev : height));
|
|
49
|
+
};
|
|
50
|
+
measure();
|
|
51
|
+
const ro = new ResizeObserver(measure);
|
|
52
|
+
if (sentinelRef.current)
|
|
53
|
+
ro.observe(sentinelRef.current);
|
|
54
|
+
if (surfaceRef.current)
|
|
55
|
+
ro.observe(surfaceRef.current);
|
|
56
|
+
return () => ro.disconnect();
|
|
57
|
+
});
|
|
58
|
+
const scale = fitScale(available, bp.width, zoom);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
onScaleChange?.(scale);
|
|
61
|
+
}, [scale, onScaleChange]);
|
|
62
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-0" }), chrome, _jsx(CanvasMetaLine, { breakpoint: bp, pageHeight: pageHeight, scale: scale }), _jsx("div", { className: "prenta-canvas-fit mx-auto block", style: {
|
|
63
|
+
width: Math.round(bp.width * scale),
|
|
64
|
+
height: pageHeight ? Math.round(pageHeight * scale) : undefined,
|
|
65
|
+
}, children: _jsx("div", { ref: (el) => {
|
|
66
|
+
surfaceRef.current = el;
|
|
67
|
+
onCanvasElement?.(el);
|
|
68
|
+
}, className: "prenta-canvas border-border bg-card origin-top-left overflow-hidden rounded-lg text-left shadow-[0_2px_20px_rgba(0,0,0,0.12)] motion-safe:transition-[width,transform] motion-safe:duration-(--mo-slow) motion-safe:ease-(--ease)", style: {
|
|
69
|
+
width: bp.width,
|
|
70
|
+
transform: `scale(${scale})`,
|
|
71
|
+
transformOrigin: 'top left',
|
|
72
|
+
}, children: children }) })] }));
|
|
73
|
+
}
|
|
74
|
+
/** The scroll container both editors wrap their surface in. */
|
|
75
|
+
export function CanvasScroll({ children }) {
|
|
76
|
+
return (_jsx("div", { className: "prenta-canvas-scroll bg-muted h-full overflow-auto px-6 pt-4.5 pb-10 text-center", children: children }));
|
|
77
|
+
}
|
|
78
|
+
/** Registers section DOM nodes so the canvas can scroll one into view. */
|
|
79
|
+
export function useSectionRefs(selectedId) {
|
|
80
|
+
const sectionRefs = useRef(new Map());
|
|
81
|
+
const registerRef = useCallback((id, el) => {
|
|
82
|
+
if (el)
|
|
83
|
+
sectionRefs.current.set(id, el);
|
|
84
|
+
else
|
|
85
|
+
sectionRefs.current.delete(id);
|
|
86
|
+
}, []);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!selectedId)
|
|
89
|
+
return;
|
|
90
|
+
sectionRefs.current.get(selectedId)?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
91
|
+
}, [selectedId]);
|
|
92
|
+
return registerRef;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=CanvasSurface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasSurface.js","sourceRoot":"","sources":["../../../src/views/page-editor/CanvasSurface.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAgC,MAAM,0BAA0B,CAAA;AAuBhG;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,UAAU,EACV,IAAI,GAAG,KAAK,EACZ,aAAa,EACb,eAAe,EACf,MAAM,EACN,QAAQ,GACW;IACnB,MAAM,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC,CAAA;IACpC,MAAM,WAAW,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAChD,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAE/C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC7C,MAAM,CAAC,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C,CAAA;;YAClC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU;YAAE,OAAM;QACvB,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;IAC/F,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BreakpointId, Zoom } from '../../lib/breakpoints.js';
|
|
2
2
|
import type { PageSection } from '../../lib/page-editor-service.js';
|
|
3
3
|
interface EditorCanvasProps {
|
|
4
4
|
sections: PageSection[];
|
|
@@ -6,17 +6,7 @@ interface EditorCanvasProps {
|
|
|
6
6
|
breakpoint: BreakpointId;
|
|
7
7
|
zoom?: Zoom;
|
|
8
8
|
onSelect: (id: string) => void;
|
|
9
|
-
/**
|
|
10
|
-
* Reports the measured scale so the header's zoom chip can show a real
|
|
11
|
-
* percentage. Only the canvas knows the available width, so the number has
|
|
12
|
-
* to travel up rather than being recomputed by the header.
|
|
13
|
-
*/
|
|
14
9
|
onScaleChange?: (scale: number) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Reports the canvas surface element, so the reflow guard can clone it. The
|
|
17
|
-
* guard needs the real element rather than a `document.querySelector`, which
|
|
18
|
-
* would also match the site-preview frame's canvas when that is mounted.
|
|
19
|
-
*/
|
|
20
10
|
onCanvasElement?: (el: HTMLElement | null) => void;
|
|
21
11
|
/** Section types rendered as placeholders — shows the "Structure view" notice. */
|
|
22
12
|
structuralTypes?: string[];
|
|
@@ -36,24 +26,11 @@ interface EditorCanvasProps {
|
|
|
36
26
|
reviewBar?: React.ReactNode;
|
|
37
27
|
}
|
|
38
28
|
/**
|
|
39
|
-
* The preview canvas.
|
|
40
|
-
*
|
|
41
|
-
* The canvas renders at the breakpoint's **real CSS width** and is scaled down
|
|
42
|
-
* with a transform. Combined with `container-type: inline-size`, that makes the
|
|
43
|
-
* page reflow against its own width — the same container queries that style the
|
|
44
|
-
* live page decide the layout. A max-width clamp cannot do this: it yields a
|
|
45
|
-
* narrow desktop layout rather than the mobile one.
|
|
46
|
-
*
|
|
47
|
-
* Two measurement rules, both learned the hard way:
|
|
29
|
+
* The page editor's preview canvas.
|
|
48
30
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* the padding arithmetic silently rots whenever the gutter changes.
|
|
53
|
-
* 2. Both measurements are re-taken on **every render**, not only from the
|
|
54
|
-
* ResizeObserver. Page height changes with every text edit, image swap and
|
|
55
|
-
* show/hide — none of which resize the observed elements. The observer
|
|
56
|
-
* exists for later window resizes; its first callback is not a substitute.
|
|
31
|
+
* Measurement, scaling and the fit box live in {@link CanvasSurface}, shared
|
|
32
|
+
* with the post editor. What is left here is what is genuinely page-specific:
|
|
33
|
+
* which chrome sits above the canvas, and what goes inside it.
|
|
57
34
|
*/
|
|
58
35
|
export declare function EditorCanvas({ sections, selectedId, breakpoint, zoom, onSelect, onScaleChange, onCanvasElement, structuralTypes, sitePreviewAvailable, reviewing, changedSectionIds, reviewBar, }: EditorCanvasProps): import("react/jsx-runtime").JSX.Element;
|
|
59
36
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCanvas.d.ts","sourceRoot":"","sources":["../../../src/views/page-editor/EditorCanvas.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorCanvas.d.ts","sourceRoot":"","sources":["../../../src/views/page-editor/EditorCanvas.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAInE,UAAU,iBAAiB;IACzB,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,UAAU,EAAE,YAAY,CAAA;IACxB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;IAClD,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IACvC;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,UAAU,EACV,UAAU,EACV,IAAY,EACZ,QAAQ,EACR,aAAa,EACb,eAAe,EACf,eAAoB,EACpB,oBAA4B,EAC5B,SAAiB,EACjB,iBAAiB,EACjB,SAAS,GACV,EAAE,iBAAiB,2CAqDnB"}
|
|
@@ -1,92 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
4
3
|
import { LayoutTemplate } from 'lucide-react';
|
|
5
4
|
import { CanvasEditTip } from '../../components/CanvasEditTip.js';
|
|
6
|
-
import {
|
|
7
|
-
import { fitScale, getBreakpoint } from '../../lib/breakpoints.js';
|
|
5
|
+
import { CanvasScroll, CanvasSurface, useSectionRefs } from './CanvasSurface.js';
|
|
8
6
|
import { SectionRenderer } from './sections/index.js';
|
|
9
7
|
import { StructureNotice } from './StructureNotice.js';
|
|
10
8
|
/**
|
|
11
|
-
* The preview canvas.
|
|
9
|
+
* The page editor's preview canvas.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
14
|
-
* with
|
|
15
|
-
*
|
|
16
|
-
* live page decide the layout. A max-width clamp cannot do this: it yields a
|
|
17
|
-
* narrow desktop layout rather than the mobile one.
|
|
18
|
-
*
|
|
19
|
-
* Two measurement rules, both learned the hard way:
|
|
20
|
-
*
|
|
21
|
-
* 1. Available width comes from a **zero-height sentinel** rendered as the
|
|
22
|
-
* panel's first child, not from `panel.clientWidth - padding`. The two
|
|
23
|
-
* disagree once a scrollbar appears or the host scales the preview, and
|
|
24
|
-
* the padding arithmetic silently rots whenever the gutter changes.
|
|
25
|
-
* 2. Both measurements are re-taken on **every render**, not only from the
|
|
26
|
-
* ResizeObserver. Page height changes with every text edit, image swap and
|
|
27
|
-
* show/hide — none of which resize the observed elements. The observer
|
|
28
|
-
* exists for later window resizes; its first callback is not a substitute.
|
|
11
|
+
* Measurement, scaling and the fit box live in {@link CanvasSurface}, shared
|
|
12
|
+
* with the post editor. What is left here is what is genuinely page-specific:
|
|
13
|
+
* which chrome sits above the canvas, and what goes inside it.
|
|
29
14
|
*/
|
|
30
15
|
export function EditorCanvas({ sections, selectedId, breakpoint, zoom = 'fit', onSelect, onScaleChange, onCanvasElement, structuralTypes = [], sitePreviewAvailable = false, reviewing = false, changedSectionIds, reviewBar, }) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// No dependency array: page height changes on edits that resize nothing the
|
|
44
|
-
// observer watches. Both setters bail when the value is unchanged, so this
|
|
45
|
-
// settles after one extra pass instead of looping.
|
|
46
|
-
useLayoutEffect(() => {
|
|
47
|
-
const measure = () => {
|
|
48
|
-
const sentinelWidth = sentinelRef.current?.offsetWidth ?? 0;
|
|
49
|
-
if (sentinelWidth > 0)
|
|
50
|
-
setAvailable((prev) => (prev === sentinelWidth ? prev : sentinelWidth));
|
|
51
|
-
const height = surfaceRef.current?.offsetHeight ?? 0;
|
|
52
|
-
if (height > 0)
|
|
53
|
-
setPageHeight((prev) => (prev === height ? prev : height));
|
|
54
|
-
};
|
|
55
|
-
measure();
|
|
56
|
-
const ro = new ResizeObserver(measure);
|
|
57
|
-
if (sentinelRef.current)
|
|
58
|
-
ro.observe(sentinelRef.current);
|
|
59
|
-
if (surfaceRef.current)
|
|
60
|
-
ro.observe(surfaceRef.current);
|
|
61
|
-
return () => ro.disconnect();
|
|
62
|
-
});
|
|
63
|
-
// Scroll the selected section into view within the canvas.
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if (!selectedId)
|
|
66
|
-
return;
|
|
67
|
-
const el = sectionRefs.current.get(selectedId);
|
|
68
|
-
if (el)
|
|
69
|
-
el.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
70
|
-
}, [selectedId]);
|
|
71
|
-
const scale = fitScale(available, bp.width, zoom);
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
onScaleChange?.(scale);
|
|
74
|
-
}, [scale, onScaleChange]);
|
|
75
|
-
return (_jsxs("div", { className: "prenta-canvas-scroll bg-muted h-full overflow-auto px-6 pt-4.5 pb-10 text-center", children: [_jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-0" }), sections.length === 0 ? (_jsx(EmptyCanvas, {})) : (_jsxs(_Fragment, { children: [reviewing ? (reviewBar) : (_jsxs(_Fragment, { children: [_jsx(CanvasEditTip, {}), _jsx(StructureNotice, { structuralTypes: structuralTypes, sitePreviewAvailable: sitePreviewAvailable })] })), _jsx(CanvasMetaLine, { breakpoint: bp, pageHeight: pageHeight, scale: scale }), _jsx("div", { className: "prenta-canvas-fit mx-auto block", style: {
|
|
76
|
-
width: Math.round(bp.width * scale),
|
|
77
|
-
height: pageHeight ? Math.round(pageHeight * scale) : undefined,
|
|
78
|
-
}, children: _jsx("div", { ref: (el) => {
|
|
79
|
-
surfaceRef.current = el;
|
|
80
|
-
onCanvasElement?.(el);
|
|
81
|
-
},
|
|
82
|
-
// `prenta-canvas` carries `container-type: inline-size` (theme.css)
|
|
83
|
-
// — that is what makes the `@pv-*` steps in the section renderers
|
|
84
|
-
// resolve against the simulated width instead of the viewport.
|
|
85
|
-
className: "prenta-canvas border-border bg-card origin-top-left overflow-hidden rounded-lg text-left shadow-[0_2px_20px_rgba(0,0,0,0.12)] motion-safe:transition-[width,transform] motion-safe:duration-(--mo-slow) motion-safe:ease-(--ease)", style: {
|
|
86
|
-
width: bp.width,
|
|
87
|
-
transform: `scale(${scale})`,
|
|
88
|
-
transformOrigin: 'top left',
|
|
89
|
-
}, children: sections.map((section) => (_jsx(SectionRenderer, { section: section, editable: true, reviewing: reviewing, changed: changedSectionIds?.has(section.id) ?? false, selected: section.id === selectedId, onSelect: onSelect, registerRef: registerRef }, section.id))) }) })] }))] }));
|
|
16
|
+
const registerRef = useSectionRefs(selectedId);
|
|
17
|
+
// A design-owned page always ships the template's sections, so an empty
|
|
18
|
+
// canvas means the template resolved to nothing — a configuration problem,
|
|
19
|
+
// not a page to scale and measure.
|
|
20
|
+
if (sections.length === 0) {
|
|
21
|
+
return (_jsx(CanvasScroll, { children: _jsx(EmptyCanvas, {}) }));
|
|
22
|
+
}
|
|
23
|
+
return (_jsx(CanvasScroll, { children: _jsx(CanvasSurface, { breakpoint: breakpoint, zoom: zoom, onScaleChange: onScaleChange, onCanvasElement: onCanvasElement, chrome:
|
|
24
|
+
// The review bar REPLACES the editing chrome rather than joining it:
|
|
25
|
+
// a tip about clicking sections to edit them is actively wrong while
|
|
26
|
+
// the canvas is showing a version you cannot edit.
|
|
27
|
+
reviewing ? (reviewBar) : (_jsxs(_Fragment, { children: [_jsx(CanvasEditTip, {}), _jsx(StructureNotice, { structuralTypes: structuralTypes, sitePreviewAvailable: sitePreviewAvailable })] })), children: sections.map((section) => (_jsx(SectionRenderer, { section: section, editable: true, reviewing: reviewing, changed: changedSectionIds?.has(section.id) ?? false, selected: section.id === selectedId, onSelect: onSelect, registerRef: registerRef }, section.id))) }) }));
|
|
90
28
|
}
|
|
91
29
|
/**
|
|
92
30
|
* Design-owned pages always ship the template's sections, so an empty canvas
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorCanvas.js","sourceRoot":"","sources":["../../../src/views/page-editor/EditorCanvas.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"EditorCanvas.js","sourceRoot":"","sources":["../../../src/views/page-editor/EditorCanvas.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGhF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AA4BtD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,QAAQ,EACR,UAAU,EACV,UAAU,EACV,IAAI,GAAG,KAAK,EACZ,QAAQ,EACR,aAAa,EACb,eAAe,EACf,eAAe,GAAG,EAAE,EACpB,oBAAoB,GAAG,KAAK,EAC5B,SAAS,GAAG,KAAK,EACjB,iBAAiB,EACjB,SAAS,GACS;IAClB,MAAM,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC,CAAA;IAE9C,wEAAwE;IACxE,2EAA2E;IAC3E,mCAAmC;IACnC,IAAI,QAAQ,CA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|
1
2
|
import type { PageSection, PostHeaderConfig } from '../../lib/post-editor-service.js';
|
|
2
3
|
import { type PostRenderContext } from '../page-editor/sections/index.js';
|
|
3
4
|
import { type ViewportId } from '../page-editor/viewports.js';
|
|
@@ -7,7 +8,10 @@ interface PostEditorCanvasProps {
|
|
|
7
8
|
context: PostRenderContext;
|
|
8
9
|
selectedId: string | null;
|
|
9
10
|
viewport: ViewportId;
|
|
11
|
+
zoom?: Zoom;
|
|
10
12
|
onSelect: (id: string) => void;
|
|
13
|
+
onScaleChange?: (scale: number) => void;
|
|
14
|
+
onCanvasElement?: (el: HTMLElement | null) => void;
|
|
11
15
|
/** Add-section CTA on the empty canvas. Omitted by design-owned editors. */
|
|
12
16
|
onAddSection?: () => void;
|
|
13
17
|
/** Section types rendered as placeholders — shows the "Structure view" notice. */
|
|
@@ -16,11 +20,18 @@ interface PostEditorCanvasProps {
|
|
|
16
20
|
sitePreviewAvailable?: boolean;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
|
-
* Post preview canvas.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* Post preview canvas.
|
|
24
|
+
*
|
|
25
|
+
* Shares {@link CanvasSurface} with the page editor, so measurement, scaling,
|
|
26
|
+
* the fit box and the meta line are one implementation rather than two. What is
|
|
27
|
+
* post-specific is what goes inside: the post header renders above the body
|
|
28
|
+
* sections, so the editor shows the full layout — header regions plus sections
|
|
29
|
+
* — exactly as it will ship.
|
|
30
|
+
*
|
|
31
|
+
* Before this shared surface the post canvas derived its width from
|
|
32
|
+
* `container.clientWidth - 48`, which disagrees with the canvas's own metrics
|
|
33
|
+
* once a scrollbar appears, and it had no breakpoint/scale readout at all.
|
|
23
34
|
*/
|
|
24
|
-
export declare function PostEditorCanvas({ sections, header, context, selectedId, viewport, onSelect, onAddSection, structuralTypes, sitePreviewAvailable, }: PostEditorCanvasProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function PostEditorCanvas({ sections, header, context, selectedId, viewport, zoom, onSelect, onScaleChange, onCanvasElement, onAddSection, structuralTypes, sitePreviewAvailable, }: PostEditorCanvasProps): import("react/jsx-runtime").JSX.Element;
|
|
25
36
|
export {};
|
|
26
37
|
//# sourceMappingURL=PostEditorCanvas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostEditorCanvas.d.ts","sourceRoot":"","sources":["../../../src/views/post-editor/PostEditorCanvas.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PostEditorCanvas.d.ts","sourceRoot":"","sources":["../../../src/views/post-editor/PostEditorCanvas.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AAErF,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAE1F,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAG7D,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,MAAM,EAAE,gBAAgB,CAAA;IACxB,OAAO,EAAE,iBAAiB,CAAA;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,QAAQ,EAAE,UAAU,CAAA;IACpB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACvC,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;IAClD,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,QAAQ,EACR,IAAY,EACZ,QAAQ,EACR,aAAa,EACb,eAAe,EACf,YAAY,EACZ,eAAoB,EACpB,oBAA4B,GAC7B,EAAE,qBAAqB,2CAuCvB"}
|
|
@@ -1,58 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { FileText, Plus } from 'lucide-react';
|
|
5
4
|
import { CanvasEditTip } from '../../components/CanvasEditTip.js';
|
|
5
|
+
import { CanvasScroll, CanvasSurface, useSectionRefs } from '../page-editor/CanvasSurface.js';
|
|
6
6
|
import { SectionRenderer } from '../page-editor/sections/index.js';
|
|
7
7
|
import { StructureNotice } from '../page-editor/StructureNotice.js';
|
|
8
|
-
import { getViewport } from '../page-editor/viewports.js';
|
|
9
8
|
import { PostHeader } from './PostHeader.js';
|
|
10
9
|
/**
|
|
11
|
-
* Post preview canvas.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* Post preview canvas.
|
|
11
|
+
*
|
|
12
|
+
* Shares {@link CanvasSurface} with the page editor, so measurement, scaling,
|
|
13
|
+
* the fit box and the meta line are one implementation rather than two. What is
|
|
14
|
+
* post-specific is what goes inside: the post header renders above the body
|
|
15
|
+
* sections, so the editor shows the full layout — header regions plus sections
|
|
16
|
+
* — exactly as it will ship.
|
|
17
|
+
*
|
|
18
|
+
* Before this shared surface the post canvas derived its width from
|
|
19
|
+
* `container.clientWidth - 48`, which disagrees with the canvas's own metrics
|
|
20
|
+
* once a scrollbar appears, and it had no breakpoint/scale readout at all.
|
|
15
21
|
*/
|
|
16
|
-
export function PostEditorCanvas({ sections, header, context, selectedId, viewport, onSelect, onAddSection, structuralTypes = [], sitePreviewAvailable = false, }) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const surfaceRef = useRef(null);
|
|
20
|
-
const sectionRefs = useRef(new Map());
|
|
21
|
-
const [scale, setScale] = useState(1);
|
|
22
|
-
const [surfaceHeight, setSurfaceHeight] = useState(null);
|
|
23
|
-
const registerRef = useCallback((id, el) => {
|
|
24
|
-
if (el)
|
|
25
|
-
sectionRefs.current.set(id, el);
|
|
26
|
-
else
|
|
27
|
-
sectionRefs.current.delete(id);
|
|
28
|
-
}, []);
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
const container = containerRef.current;
|
|
31
|
-
if (!container)
|
|
32
|
-
return;
|
|
33
|
-
const recompute = () => {
|
|
34
|
-
const available = container.clientWidth - 48;
|
|
35
|
-
const next = Math.min(1, available / vp.width);
|
|
36
|
-
setScale(next > 0 ? next : 1);
|
|
37
|
-
if (surfaceRef.current) {
|
|
38
|
-
setSurfaceHeight(surfaceRef.current.offsetHeight * (next > 0 ? next : 1));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
recompute();
|
|
42
|
-
const ro = new ResizeObserver(recompute);
|
|
43
|
-
ro.observe(container);
|
|
44
|
-
if (surfaceRef.current)
|
|
45
|
-
ro.observe(surfaceRef.current);
|
|
46
|
-
return () => ro.disconnect();
|
|
47
|
-
}, [vp.width, sections, header, context]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (!selectedId)
|
|
50
|
-
return;
|
|
51
|
-
const el = sectionRefs.current.get(selectedId);
|
|
52
|
-
if (el)
|
|
53
|
-
el.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
54
|
-
}, [selectedId]);
|
|
55
|
-
return (_jsxs("div", { ref: containerRef, className: "bg-muted h-full overflow-auto p-6", children: [sections.length > 0 && _jsx(CanvasEditTip, {}), _jsx(StructureNotice, { structuralTypes: structuralTypes, sitePreviewAvailable: sitePreviewAvailable }), _jsx("div", { className: "mx-auto", style: { width: vp.width * scale, height: surfaceHeight ?? undefined }, children: _jsxs("div", { ref: surfaceRef, className: "prenta-canvas border-border bg-card origin-top overflow-hidden rounded-xl border shadow-sm", style: { width: vp.width, transform: `scale(${scale})`, transformOrigin: 'top left' }, children: [_jsx(PostHeader, { config: header, context: context }), sections.length === 0 ? (_jsx(EmptyBody, { onAddSection: onAddSection })) : (sections.map((section) => (_jsx(SectionRenderer, { section: section, context: context, editable: true, selected: section.id === selectedId, onSelect: onSelect, registerRef: registerRef }, section.id))))] }) })] }));
|
|
22
|
+
export function PostEditorCanvas({ sections, header, context, selectedId, viewport, zoom = 'fit', onSelect, onScaleChange, onCanvasElement, onAddSection, structuralTypes = [], sitePreviewAvailable = false, }) {
|
|
23
|
+
const registerRef = useSectionRefs(selectedId);
|
|
24
|
+
return (_jsx(CanvasScroll, { children: _jsxs(CanvasSurface, { breakpoint: viewport, zoom: zoom, onScaleChange: onScaleChange, onCanvasElement: onCanvasElement, chrome: _jsxs(_Fragment, { children: [sections.length > 0 && _jsx(CanvasEditTip, {}), _jsx(StructureNotice, { structuralTypes: structuralTypes, sitePreviewAvailable: sitePreviewAvailable })] }), children: [_jsx(PostHeader, { config: header, context: context }), sections.length === 0 ? (_jsx(EmptyBody, { onAddSection: onAddSection })) : (sections.map((section) => (_jsx(SectionRenderer, { section: section, context: context, editable: true, selected: section.id === selectedId, onSelect: onSelect, registerRef: registerRef }, section.id))))] }) }));
|
|
56
25
|
}
|
|
57
26
|
function EmptyBody({ onAddSection }) {
|
|
58
27
|
// This block sits inside the fixed-white preview surface, so the neutral
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostEditorCanvas.js","sourceRoot":"","sources":["../../../src/views/post-editor/PostEditorCanvas.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,
|
|
1
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AAI,CAC1C,CAAC,CAAC,CAAC,CACF,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACxB,KAAC,eAAe,IAEd,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,QAAQ,QACR,QAAQ,EAAE,OAAO,CAAC,EAAE,KAAK,UAAU,EACnC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,IANnB,OAAO,CAAC,EAAE,CAOf,CACH,CAAC,CACH,IACa,GACH,CAChB,CAAA;AACH,CAAC;AAED,SAAS,SAAS,CAAC,EAAE,YAAY,EAAiC;IAChE,yEAAyE;IACzE,2EAA2E;IAC3E,4EAA4E;IAC5E,4EAA4E;IAC5E,wEAAwE;IACxE,gEAAgE;IAChE,OAAO,CACL,eAAK,SAAS,EAAC,iGAAiG,aAC9G,eAAM,SAAS,EAAC,kEAAkE,YAChF,KAAC,QAAQ,IAAC,SAAS,EAAC,+BAA+B,wBAAe,GAC7D,EACP,YAAG,SAAS,EAAC,+BAA+B,YACzC,YAAY;oBACX,CAAC,CAAC,wNAAwN;oBAC1N,CAAC,CAAC,2LAA2L,GAC7L,EACH,YAAY,IAAI,CACf,kBACE,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,YAAY,EACrB,SAAS,EAAC,kJAAkJ,aAE5J,KAAC,IAAI,IAAC,SAAS,EAAC,SAAS,wBAAe,mBAEjC,CACV,IACG,CACP,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostSectionEditor.d.ts","sourceRoot":"","sources":["../../../src/views/post-editor/PostSectionEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PostSectionEditor.d.ts","sourceRoot":"","sources":["../../../src/views/post-editor/PostSectionEditor.tsx"],"names":[],"mappings":"AAwDA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE5E,8DAA8D;AAC9D,UAAU,YAAY;I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