payload-canvas 0.6.3 → 0.6.5
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 -21
- package/README.md +3237 -3236
- package/dist/admin/aiKeyField.scss +58 -58
- package/dist/admin/diff/layoutDiff.scss +181 -181
- package/dist/admin/editor/assistant/assistant.scss +944 -944
- package/dist/admin/editor/classes/manager.scss +262 -262
- package/dist/admin/editor/comments/comments.scss +539 -539
- package/dist/admin/editor/dnd/dnd.scss +261 -261
- package/dist/admin/editor/editor.scss +2629 -2629
- package/dist/admin/editor/empty/empty.scss +92 -92
- package/dist/admin/editor/fields/fields.scss +778 -778
- package/dist/admin/editor/generate/generate.scss +276 -276
- package/dist/admin/editor/layout/layout.scss +240 -240
- package/dist/admin/editor/live/presence.scss +24 -24
- package/dist/admin/editor/locale/locale.scss +154 -154
- package/dist/admin/editor/media/media.scss +233 -233
- package/dist/admin/editor/menu/menu.scss +132 -132
- package/dist/admin/editor/motion/motion.scss +84 -84
- package/dist/admin/editor/sections/components.scss +238 -238
- package/dist/admin/editor/sections/variants.scss +90 -90
- package/dist/admin/editor/styles/ClassCss.js +3 -3
- package/dist/admin/editor/styles/classes.scss +381 -381
- package/dist/admin/editor/styles/styles.scss +1123 -1123
- package/dist/admin/editor/styles/tokens.js +2 -1
- package/dist/admin/editor/templates/templates.scss +654 -654
- package/dist/admin/editor/tooltip/tooltip.scss +39 -39
- package/dist/admin/editor/topbar/DocumentActions.js +1 -1
- package/dist/admin/editor/topbar/TopBar.js +2 -1
- package/dist/admin/editor/topbar/contentMode.scss +26 -26
- package/dist/admin/editor/topbar/screens/screens.scss +134 -134
- package/dist/admin/editor/topbar/settingsDrawer.scss +32 -32
- package/dist/admin/editor/topbar/tabTitle.d.ts +6 -0
- package/dist/admin/editor/topbar/tabTitle.js +9 -0
- package/dist/admin/editor/topbar/topbar.scss +645 -645
- package/dist/admin/editor/ui/controls.scss +320 -320
- package/dist/admin/forms/submissions.scss +197 -197
- package/dist/admin/layoutField.scss +69 -69
- package/dist/admin/templateConditions.scss +24 -24
- package/dist/ai/prompt.js +40 -40
- package/dist/blocks/client/marquee.js +14 -14
- package/dist/blocks/payload.js +13 -3
- package/dist/core/payloadBlocks.js +10 -1
- package/dist/core/responseError.d.ts +5 -0
- package/dist/core/responseError.js +8 -0
- package/dist/core/sections.d.ts +2 -0
- package/dist/core/sections.js +8 -0
- package/dist/css/index.d.ts +6 -0
- package/dist/css/index.js +40 -1
- package/dist/css/shared.js +2 -2
- package/dist/live/session.js +18 -0
- package/dist/live/storage.d.ts +5 -0
- package/dist/live/storage.js +20 -0
- package/dist/mcp/index.js +46 -19
- package/dist/mcp/shared.js +16 -16
- package/dist/plugin/index.d.ts +21 -1
- package/dist/plugin/index.js +46 -15
- package/dist/react/canvas/BuilderCanvas.js +76 -75
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +8 -7
- package/dist/theme/admin/fields.scss +363 -363
- package/package.json +1 -1
package/dist/plugin/index.d.ts
CHANGED
|
@@ -103,9 +103,16 @@ export type WebsiteBuilderOptions = {
|
|
|
103
103
|
* items have no `$url`. Each slug must be a collection of the config.
|
|
104
104
|
*/
|
|
105
105
|
listCollections?: string[];
|
|
106
|
+
/**
|
|
107
|
+
* The app's Tailwind CSS. Required in every mode, also when the builder edits a Payload blocks
|
|
108
|
+
* field: the canvas compiles Tailwind against the entry, and the editor reads its breakpoints and
|
|
109
|
+
* theme from it. Checked at startup: no `entry` stops the app with a message that says what to
|
|
110
|
+
* pass; an `@plugin` of the entry missing from `plugins` is logged as an error.
|
|
111
|
+
*/
|
|
106
112
|
css: {
|
|
107
113
|
/** Path to the app's Tailwind entry CSS, absolute or relative to process.cwd(). */
|
|
108
114
|
entry: string;
|
|
115
|
+
/** Every plugin the entry loads with `@plugin "<id>"`, by that id. */
|
|
109
116
|
plugins?: TailwindPlugins;
|
|
110
117
|
/**
|
|
111
118
|
* The font families the site really uses, by font variable name (`sans`, `heading`, `mono`, …).
|
|
@@ -126,7 +133,8 @@ export type WebsiteBuilderOptions = {
|
|
|
126
133
|
savedSections?: SavedSectionsOptions | false;
|
|
127
134
|
/**
|
|
128
135
|
* Live editing: every open editor and every AI agent (MCP) edits one shared in-memory session
|
|
129
|
-
* per document, and the server saves its draft about a second after the last change
|
|
136
|
+
* per document, and the server saves its draft about a second after the last change (only when
|
|
137
|
+
* the stored layout would change: a save that changes nothing makes no draft version). Sessions
|
|
130
138
|
* live in one app server process: with several servers, route each document to one server.
|
|
131
139
|
*/
|
|
132
140
|
live?: {
|
|
@@ -191,6 +199,18 @@ export declare const BUILDER_VIEW_KEY = "websiteBuilder";
|
|
|
191
199
|
export declare const BUILDER_VIEW_PATH = "/builder/:collection/:id";
|
|
192
200
|
/** Name of the hidden field that stores the generated CSS (`{ hash, css }`) for a layout field. */
|
|
193
201
|
export declare function cssFieldName(field: string): string;
|
|
202
|
+
/**
|
|
203
|
+
* The website builder plugin. Put it LAST in `plugins`: plugins such as SEO with `tabbedUI`
|
|
204
|
+
* move all fields into tabs, and the layout field must stay a top-level field.
|
|
205
|
+
*
|
|
206
|
+
* Editors open the builder full screen at `{admin}/builder/:collection/:id` (a root admin view
|
|
207
|
+
* without Payload's nav and header). The document's "Builder" tab and the layout field link there.
|
|
208
|
+
*/
|
|
209
|
+
/**
|
|
210
|
+
* `css` of websiteBuilder() as the compile needs it: the entry as an absolute path. Throws a
|
|
211
|
+
* message that says what to pass when `css.entry` is missing.
|
|
212
|
+
*/
|
|
213
|
+
export declare function resolveCssOptions(css: WebsiteBuilderOptions['css'] | undefined, cwd?: string): CssOptions;
|
|
194
214
|
export declare function websiteBuilder(options: WebsiteBuilderOptions): Plugin;
|
|
195
215
|
/** Name of the hidden virtual field that carries the builder's config for a Payload blocks field. */
|
|
196
216
|
export declare function builderConfigFieldName(field: string): string;
|
package/dist/plugin/index.js
CHANGED
|
@@ -8,9 +8,10 @@ import { checkSectionVariants, richTextFieldName, sectionsWithDefaultClassNames
|
|
|
8
8
|
import { bindingRelations, DEFAULT_TEMPLATES_SLUG, DOCUMENT_TEMPLATE_FIELD, TEMPLATE_TARGET_FIELD } from '../core/bindings.js';
|
|
9
9
|
import { localeSettingsOf } from '../core/locale.js';
|
|
10
10
|
import { resolveRegions } from '../core/regions.js';
|
|
11
|
+
import { sectionsThatFit } from '../core/sections.js';
|
|
11
12
|
import { decodePayloadBlocks, payloadBlocksProblems, payloadBlocksStorage } from '../core/payloadBlocks.js';
|
|
12
13
|
import { EMPTY_LAYOUT, } from '../core/types.js';
|
|
13
|
-
import { applyFontFamilies, getCanvasCssInput, getStyleTokens } from '../css/index.js';
|
|
14
|
+
import { applyFontFamilies, cssEntryProblems, getCanvasCssInput, getStyleTokens } from '../css/index.js';
|
|
14
15
|
import { DEFAULT_THEME_SLUG, THEME_CONFIG_KEY, THEME_PATH } from '../theme/config.js';
|
|
15
16
|
import { themeFontFamilies, themeOutput } from '../theme/css.js';
|
|
16
17
|
import { themeGlobal } from '../theme/global.js';
|
|
@@ -73,16 +74,32 @@ export function cssFieldName(field) {
|
|
|
73
74
|
* Editors open the builder full screen at `{admin}/builder/:collection/:id` (a root admin view
|
|
74
75
|
* without Payload's nav and header). The document's "Builder" tab and the layout field link there.
|
|
75
76
|
*/
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
/**
|
|
78
|
+
* `css` of websiteBuilder() as the compile needs it: the entry as an absolute path. Throws a
|
|
79
|
+
* message that says what to pass when `css.entry` is missing.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveCssOptions(css, cwd = process.cwd()) {
|
|
82
|
+
if (!css || typeof css !== 'object' || typeof css.entry !== 'string' || css.entry.trim() === '') {
|
|
83
|
+
throw new Error("[websiteBuilder] `css.entry` is missing. Pass the path to the app's Tailwind entry CSS, absolute or relative to the folder the app starts in, " +
|
|
84
|
+
"for example `css: { entry: 'src/app/globals.css' }`. Every builder needs it, also one that edits a Payload blocks field: " +
|
|
85
|
+
'the canvas compiles Tailwind against it, and the editor reads its breakpoints and theme from it. ' +
|
|
86
|
+
"When the entry has @plugin lines, pass those plugins too: `css: { entry, plugins: { '@tailwindcss/typography': typography } }`.");
|
|
87
|
+
}
|
|
88
|
+
if (css.plugins !== undefined && (css.plugins === null || typeof css.plugins !== 'object' || Array.isArray(css.plugins))) {
|
|
89
|
+
throw new Error("[websiteBuilder] `css.plugins` must be an object that maps each @plugin id of the CSS entry to the plugin, for example `{ '@tailwindcss/typography': typography }`.");
|
|
90
|
+
}
|
|
91
|
+
return { entry: path.resolve(cwd, css.entry), plugins: css.plugins };
|
|
92
|
+
}
|
|
93
|
+
/** A CSS endpoint's failure as a message the editor shows and the server logs, not a bare 500. */
|
|
94
|
+
function cssFailure(req, what, error) {
|
|
95
|
+
const message = `[websiteBuilder] ${what} could not be built: ${error instanceof Error ? error.message : String(error)}`;
|
|
96
|
+
req.payload.logger.error(message);
|
|
97
|
+
return Response.json({ error: message }, { status: 500, headers: { 'Cache-Control': 'no-store' } });
|
|
83
98
|
}
|
|
84
99
|
export function websiteBuilder(options) {
|
|
85
100
|
return (config) => {
|
|
101
|
+
// First: without the CSS entry nothing in the builder works.
|
|
102
|
+
const css = resolveCssOptions(options.css);
|
|
86
103
|
const apiRoute = config.routes?.api ?? '/api';
|
|
87
104
|
const canvasPath = options.canvasPath ?? '/builder-canvas';
|
|
88
105
|
const sourceCollections = config.collections ?? [];
|
|
@@ -270,10 +287,6 @@ export function websiteBuilder(options) {
|
|
|
270
287
|
const clientBlocks = toJsonSafe(blocks);
|
|
271
288
|
// Relationship targets of every collection, so the canvas resolves `<path>.$url` bindings.
|
|
272
289
|
const relations = bindingRelations(collections);
|
|
273
|
-
const css = {
|
|
274
|
-
entry: path.resolve(process.cwd(), options.css.entry),
|
|
275
|
-
plugins: options.css.plugins,
|
|
276
|
-
};
|
|
277
290
|
// Editable classes: a collection, a hidden global with the compiled stylesheet, endpoints.
|
|
278
291
|
const classes = resolveClasses(options.classes, { apiRoute, css, blocks, collections, globals: config.globals ?? [] });
|
|
279
292
|
// Comments on the canvas: a collection the editor reads and writes over REST.
|
|
@@ -501,8 +514,13 @@ export function websiteBuilder(options) {
|
|
|
501
514
|
if (!req.user)
|
|
502
515
|
return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
503
516
|
// With the theme's variables, so `bg-brand` works on the canvas. Not cached: a theme save changes it.
|
|
504
|
-
|
|
505
|
-
|
|
517
|
+
try {
|
|
518
|
+
const input = await getCanvasCssInput(await withThemeVariables(req.payload, css));
|
|
519
|
+
return Response.json(input, { headers: { 'Cache-Control': 'private, no-cache' } });
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
return cssFailure(req, 'The canvas CSS', error);
|
|
523
|
+
}
|
|
506
524
|
},
|
|
507
525
|
},
|
|
508
526
|
{
|
|
@@ -511,7 +529,13 @@ export function websiteBuilder(options) {
|
|
|
511
529
|
handler: async (req) => {
|
|
512
530
|
if (!req.user)
|
|
513
531
|
return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
514
|
-
|
|
532
|
+
let tokens;
|
|
533
|
+
try {
|
|
534
|
+
tokens = await themeStyleTokens(req.payload, css);
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
return cssFailure(req, 'The style tokens', error);
|
|
538
|
+
}
|
|
515
539
|
const custom = await Promise.resolve(options.css.fontFamilies?.(req.payload)).catch(() => undefined);
|
|
516
540
|
const families = { ...(await themeFamilies(req.payload)), ...custom };
|
|
517
541
|
const fonts = applyFontFamilies(tokens.fonts, families);
|
|
@@ -544,6 +568,13 @@ export function websiteBuilder(options) {
|
|
|
544
568
|
// …and when a Local API update ended, also a failed one without a transaction.
|
|
545
569
|
installLocalApiBoundary(payload, writeGate);
|
|
546
570
|
await config.onInit?.(payload);
|
|
571
|
+
// The CSS entry and its @plugin lines, checked once at startup: a plugin missing from
|
|
572
|
+
// `css.plugins` would otherwise fail only when the builder loads. Not awaited: startup does
|
|
573
|
+
// not wait for a Tailwind compile.
|
|
574
|
+
void cssEntryProblems(css).then((problems) => {
|
|
575
|
+
for (const problem of problems)
|
|
576
|
+
payload.logger.error(`[websiteBuilder] ${problem}`);
|
|
577
|
+
}, () => { });
|
|
547
578
|
// Save unsaved live edits when the server stops.
|
|
548
579
|
installShutdownFlush(live.sessions);
|
|
549
580
|
for (const [slug, field] of Object.entries(fieldNames)) {
|
|
@@ -3,6 +3,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
// Runs inside the canvas iframe. It renders the layout it gets from the admin editor and reports
|
|
4
4
|
// block and slot rectangles, the pointer and editor shortcuts back. It holds no selection or drop logic.
|
|
5
5
|
import { collectClasses, createId, findBlock, joinListItem, TEXT_LIST_ITEM_BLOCK, } from '../../core/index.js';
|
|
6
|
+
import { responseErrorMessage } from '../../core/responseError.js';
|
|
6
7
|
import { createCanvasCompiler } from '../../css/browser.js';
|
|
7
8
|
import { THEME_CHANNEL } from '../../theme/config.js';
|
|
8
9
|
import { classNamesOf, withoutClassNames } from '../../classes/shared.js';
|
|
@@ -32,78 +33,78 @@ import { withServerBlocks } from './serverComponents.js';
|
|
|
32
33
|
import { shareStructure } from './share.js';
|
|
33
34
|
import { ThumbnailCanvas } from './thumbnail/ThumbnailCanvas.js';
|
|
34
35
|
/** Editor-only styles: visible empty slots and dimmed hidden blocks. Never part of the site CSS. */
|
|
35
|
-
const EDITOR_CSS = `
|
|
36
|
-
[data-builder-root] { min-height: 100vh; display: flow-root; user-select: none; }
|
|
37
|
-
[data-slot-empty] {
|
|
38
|
-
min-height: 48px;
|
|
39
|
-
min-width: 48px;
|
|
40
|
-
border: 1px dashed rgb(0 0 0 / 0.2);
|
|
41
|
-
border-radius: 4px;
|
|
42
|
-
background: repeating-linear-gradient(45deg, rgb(0 0 0 / 0.03) 0 6px, transparent 6px 12px);
|
|
43
|
-
}
|
|
44
|
-
/* An empty slot with a description: the description, centered. */
|
|
45
|
-
[data-slot-empty][data-slot-hint] { display: grid; place-items: center; padding: 8px; }
|
|
46
|
-
[data-slot-empty][data-slot-hint]::before {
|
|
47
|
-
content: attr(data-slot-hint);
|
|
48
|
-
font: 12px/1.4 system-ui, sans-serif;
|
|
49
|
-
color: rgb(0 0 0 / 0.55);
|
|
50
|
-
text-align: center;
|
|
51
|
-
pointer-events: none;
|
|
52
|
-
}
|
|
53
|
-
[data-builder-hidden] { opacity: 0.35; }
|
|
54
|
-
/* Repeated collection list items (2nd, 3rd, …): shown dimmed, never selectable. A component's
|
|
55
|
-
blocks are not selectable either (the component is), but they show as on the site. */
|
|
56
|
-
[data-builder-repeat] { pointer-events: none; }
|
|
57
|
-
[data-builder-repeat]:not([data-builder-component]):not([data-builder-repeat] [data-builder-repeat]) { opacity: 0.6; }
|
|
58
|
-
[data-builder-empty-page] { min-height: 240px; }
|
|
59
|
-
/* The layout inside the page frame: the same box the canvas root gives a layout without a frame.
|
|
60
|
-
A frame that gives the box its own classes (\`<LayoutOutlet className>\`) styles it itself. */
|
|
61
|
-
[data-builder-layout]:not([class]) { display: flow-root; }
|
|
62
|
-
/* Fixed regions of the page frame: text and images edit in place, but they never drag. */
|
|
63
|
-
[data-builder-region] { user-select: none; }
|
|
64
|
-
/* Inline text editing. The admin overlay draws the editing outline. */
|
|
65
|
-
[data-builder-editing] { user-select: text; -webkit-user-select: text; cursor: text; outline: none; }
|
|
66
|
-
[data-builder-editing='lines'] { white-space: pre-wrap; }
|
|
67
|
-
[data-builder-editing][data-builder-blank]::before { content: attr(data-builder-hint); opacity: 0.4; pointer-events: none; }
|
|
68
|
-
/* Text that a double-click edits in place: a text cursor and a faint outline on hover. */
|
|
69
|
-
:is([data-builder-text], [data-builder-text-auto]):not([data-builder-editing]):hover {
|
|
70
|
-
cursor: text;
|
|
71
|
-
outline: 1px dashed color-mix(in srgb, currentColor 55%, transparent);
|
|
72
|
-
outline-offset: 2px;
|
|
73
|
-
}
|
|
74
|
-
.builder-lx-underline { text-decoration: underline; }
|
|
75
|
-
.builder-lx-strike { text-decoration: line-through; }
|
|
76
|
-
.builder-lx-underline-strike { text-decoration: underline line-through; }
|
|
77
|
-
[data-builder-passthrough] {
|
|
78
|
-
display: block;
|
|
79
|
-
margin: 0.5em 0;
|
|
80
|
-
padding: 6px 10px;
|
|
81
|
-
border: 1px dashed rgb(128 128 128 / 0.6);
|
|
82
|
-
border-radius: 4px;
|
|
83
|
-
font: 12px/1.4 system-ui, sans-serif;
|
|
84
|
-
opacity: 0.7;
|
|
85
|
-
user-select: none;
|
|
86
|
-
}
|
|
87
|
-
span[data-builder-passthrough] { display: inline-block; margin: 0 2px; padding: 0 6px; }
|
|
88
|
-
/* Smooth drag mode: the dragged block hides while a lifted copy follows the pointer. */
|
|
89
|
-
[data-builder-drag-source] { opacity: 0 !important; }
|
|
90
|
-
/* Blocks rendered on the server: a placeholder while the first render loads, and a short dim
|
|
91
|
-
(only when an update takes longer than 300 ms) while a newer one loads. */
|
|
92
|
-
[data-builder-server] {
|
|
93
|
-
font: 12px/1.4 system-ui, sans-serif;
|
|
94
|
-
color: rgb(0 0 0 / 0.5);
|
|
95
|
-
border: 1px dashed rgb(128 128 128 / 0.5);
|
|
96
|
-
border-radius: 4px;
|
|
97
|
-
}
|
|
98
|
-
[data-builder-server='loading'] {
|
|
99
|
-
min-height: 96px;
|
|
100
|
-
background: linear-gradient(90deg, rgb(0 0 0 / 0.03) 25%, rgb(0 0 0 / 0.07) 50%, rgb(0 0 0 / 0.03) 75%) 0 0 / 200% 100%;
|
|
101
|
-
animation: builder-server-loading 1.4s linear infinite;
|
|
102
|
-
}
|
|
103
|
-
[data-builder-server='error'] { color: rgb(180 30 30); border-color: rgb(180 30 30 / 0.5); }
|
|
104
|
-
[data-builder-loading] { opacity: 0.7; transition: opacity 0.2s ease 0.3s; }
|
|
105
|
-
@keyframes builder-server-loading { to { background-position: -200% 0; } }
|
|
106
|
-
@media (prefers-reduced-motion: reduce) { [data-builder-server='loading'] { animation: none; } }
|
|
36
|
+
const EDITOR_CSS = `
|
|
37
|
+
[data-builder-root] { min-height: 100vh; display: flow-root; user-select: none; }
|
|
38
|
+
[data-slot-empty] {
|
|
39
|
+
min-height: 48px;
|
|
40
|
+
min-width: 48px;
|
|
41
|
+
border: 1px dashed rgb(0 0 0 / 0.2);
|
|
42
|
+
border-radius: 4px;
|
|
43
|
+
background: repeating-linear-gradient(45deg, rgb(0 0 0 / 0.03) 0 6px, transparent 6px 12px);
|
|
44
|
+
}
|
|
45
|
+
/* An empty slot with a description: the description, centered. */
|
|
46
|
+
[data-slot-empty][data-slot-hint] { display: grid; place-items: center; padding: 8px; }
|
|
47
|
+
[data-slot-empty][data-slot-hint]::before {
|
|
48
|
+
content: attr(data-slot-hint);
|
|
49
|
+
font: 12px/1.4 system-ui, sans-serif;
|
|
50
|
+
color: rgb(0 0 0 / 0.55);
|
|
51
|
+
text-align: center;
|
|
52
|
+
pointer-events: none;
|
|
53
|
+
}
|
|
54
|
+
[data-builder-hidden] { opacity: 0.35; }
|
|
55
|
+
/* Repeated collection list items (2nd, 3rd, …): shown dimmed, never selectable. A component's
|
|
56
|
+
blocks are not selectable either (the component is), but they show as on the site. */
|
|
57
|
+
[data-builder-repeat] { pointer-events: none; }
|
|
58
|
+
[data-builder-repeat]:not([data-builder-component]):not([data-builder-repeat] [data-builder-repeat]) { opacity: 0.6; }
|
|
59
|
+
[data-builder-empty-page] { min-height: 240px; }
|
|
60
|
+
/* The layout inside the page frame: the same box the canvas root gives a layout without a frame.
|
|
61
|
+
A frame that gives the box its own classes (\`<LayoutOutlet className>\`) styles it itself. */
|
|
62
|
+
[data-builder-layout]:not([class]) { display: flow-root; }
|
|
63
|
+
/* Fixed regions of the page frame: text and images edit in place, but they never drag. */
|
|
64
|
+
[data-builder-region] { user-select: none; }
|
|
65
|
+
/* Inline text editing. The admin overlay draws the editing outline. */
|
|
66
|
+
[data-builder-editing] { user-select: text; -webkit-user-select: text; cursor: text; outline: none; }
|
|
67
|
+
[data-builder-editing='lines'] { white-space: pre-wrap; }
|
|
68
|
+
[data-builder-editing][data-builder-blank]::before { content: attr(data-builder-hint); opacity: 0.4; pointer-events: none; }
|
|
69
|
+
/* Text that a double-click edits in place: a text cursor and a faint outline on hover. */
|
|
70
|
+
:is([data-builder-text], [data-builder-text-auto]):not([data-builder-editing]):hover {
|
|
71
|
+
cursor: text;
|
|
72
|
+
outline: 1px dashed color-mix(in srgb, currentColor 55%, transparent);
|
|
73
|
+
outline-offset: 2px;
|
|
74
|
+
}
|
|
75
|
+
.builder-lx-underline { text-decoration: underline; }
|
|
76
|
+
.builder-lx-strike { text-decoration: line-through; }
|
|
77
|
+
.builder-lx-underline-strike { text-decoration: underline line-through; }
|
|
78
|
+
[data-builder-passthrough] {
|
|
79
|
+
display: block;
|
|
80
|
+
margin: 0.5em 0;
|
|
81
|
+
padding: 6px 10px;
|
|
82
|
+
border: 1px dashed rgb(128 128 128 / 0.6);
|
|
83
|
+
border-radius: 4px;
|
|
84
|
+
font: 12px/1.4 system-ui, sans-serif;
|
|
85
|
+
opacity: 0.7;
|
|
86
|
+
user-select: none;
|
|
87
|
+
}
|
|
88
|
+
span[data-builder-passthrough] { display: inline-block; margin: 0 2px; padding: 0 6px; }
|
|
89
|
+
/* Smooth drag mode: the dragged block hides while a lifted copy follows the pointer. */
|
|
90
|
+
[data-builder-drag-source] { opacity: 0 !important; }
|
|
91
|
+
/* Blocks rendered on the server: a placeholder while the first render loads, and a short dim
|
|
92
|
+
(only when an update takes longer than 300 ms) while a newer one loads. */
|
|
93
|
+
[data-builder-server] {
|
|
94
|
+
font: 12px/1.4 system-ui, sans-serif;
|
|
95
|
+
color: rgb(0 0 0 / 0.5);
|
|
96
|
+
border: 1px dashed rgb(128 128 128 / 0.5);
|
|
97
|
+
border-radius: 4px;
|
|
98
|
+
}
|
|
99
|
+
[data-builder-server='loading'] {
|
|
100
|
+
min-height: 96px;
|
|
101
|
+
background: linear-gradient(90deg, rgb(0 0 0 / 0.03) 25%, rgb(0 0 0 / 0.07) 50%, rgb(0 0 0 / 0.03) 75%) 0 0 / 200% 100%;
|
|
102
|
+
animation: builder-server-loading 1.4s linear infinite;
|
|
103
|
+
}
|
|
104
|
+
[data-builder-server='error'] { color: rgb(180 30 30); border-color: rgb(180 30 30 / 0.5); }
|
|
105
|
+
[data-builder-loading] { opacity: 0.7; transition: opacity 0.2s ease 0.3s; }
|
|
106
|
+
@keyframes builder-server-loading { to { background-position: -200% 0; } }
|
|
107
|
+
@media (prefers-reduced-motion: reduce) { [data-builder-server='loading'] { animation: none; } }
|
|
107
108
|
`;
|
|
108
109
|
/** Room kept above and below a block scrolled into view (the toolbar sits above it). */
|
|
109
110
|
const SCROLL_MARGIN = 48;
|
|
@@ -876,7 +877,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
876
877
|
fetch(endpoint, { credentials: 'include', cache: 'no-store' })
|
|
877
878
|
.then(async (res) => {
|
|
878
879
|
if (!res.ok)
|
|
879
|
-
throw new Error(
|
|
880
|
+
throw new Error(await responseErrorMessage(res));
|
|
880
881
|
const input = (await res.json());
|
|
881
882
|
if (!cancelled)
|
|
882
883
|
setCssInput(input);
|
|
@@ -885,7 +886,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
885
886
|
if (cancelled)
|
|
886
887
|
return;
|
|
887
888
|
setCompiler({ status: 'failed' });
|
|
888
|
-
send({ type: 'error', message: `Canvas CSS failed to load: ${String(error)}` });
|
|
889
|
+
send({ type: 'error', message: `Canvas CSS failed to load: ${error instanceof Error ? error.message : String(error)}` });
|
|
889
890
|
});
|
|
890
891
|
return () => {
|
|
891
892
|
cancelled = true;
|
|
@@ -912,7 +913,7 @@ function EditorCanvas({ blocks, components, plugins, resolveLink, server }) {
|
|
|
912
913
|
if (cancelled)
|
|
913
914
|
return;
|
|
914
915
|
setCompiler({ status: 'failed' });
|
|
915
|
-
send({ type: 'error', message: `Canvas CSS failed to load: ${String(error)}` });
|
|
916
|
+
send({ type: 'error', message: `Canvas CSS failed to load: ${error instanceof Error ? error.message : String(error)}` });
|
|
916
917
|
});
|
|
917
918
|
return () => {
|
|
918
919
|
cancelled = true;
|
|
@@ -4,6 +4,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
4
4
|
// uses to picture ready-made and saved sections. It renders one section at a time with the app's
|
|
5
5
|
// components, CSS and theme, and sends back a picture (see capture.ts).
|
|
6
6
|
import { collectClasses } from '../../../core/index.js';
|
|
7
|
+
import { responseErrorMessage } from '../../../core/responseError.js';
|
|
7
8
|
import { createCanvasCompiler } from '../../../css/browser.js';
|
|
8
9
|
import { compileClassSheet } from '../../../css/classes.js';
|
|
9
10
|
import { withoutClassNames } from '../../../classes/shared.js';
|
|
@@ -17,11 +18,11 @@ import { createServerBlocks } from '../serverBlocks.js';
|
|
|
17
18
|
import { withServerBlocks } from '../serverComponents.js';
|
|
18
19
|
import { captureElement } from './capture.js';
|
|
19
20
|
/** No scrollbar (it would narrow the page), hidden blocks left out, empty slots outlined. */
|
|
20
|
-
const THUMBNAIL_CSS = `
|
|
21
|
-
html { overflow: hidden; scrollbar-width: none; }
|
|
22
|
-
[data-builder-thumbnail] { display: flow-root; }
|
|
23
|
-
[data-builder-hidden] { display: none !important; }
|
|
24
|
-
[data-slot-empty] { border: 1px dashed rgb(128 128 128 / 0.35); border-radius: 4px; }
|
|
21
|
+
const THUMBNAIL_CSS = `
|
|
22
|
+
html { overflow: hidden; scrollbar-width: none; }
|
|
23
|
+
[data-builder-thumbnail] { display: flow-root; }
|
|
24
|
+
[data-builder-hidden] { display: none !important; }
|
|
25
|
+
[data-slot-empty] { border: 1px dashed rgb(128 128 128 / 0.35); border-radius: 4px; }
|
|
25
26
|
`;
|
|
26
27
|
/** Time for late layout (fonts, images with a size) before the picture. */
|
|
27
28
|
const SETTLE_MS = 40;
|
|
@@ -96,7 +97,7 @@ export function ThumbnailCanvas({ blocks, components, plugins, resolveLink, serv
|
|
|
96
97
|
const state = { cancelled: false, busy: false };
|
|
97
98
|
const input = fetch(init.cssEndpoint, { credentials: 'include' }).then(async (res) => {
|
|
98
99
|
if (!res.ok)
|
|
99
|
-
throw new Error(`Canvas CSS: ${
|
|
100
|
+
throw new Error(`Canvas CSS: ${await responseErrorMessage(res)}`);
|
|
100
101
|
return (await res.json());
|
|
101
102
|
});
|
|
102
103
|
const compiler = input.then((value) => createCanvasCompiler(value, pluginsRef.current));
|
|
@@ -113,7 +114,7 @@ export function ThumbnailCanvas({ blocks, components, plugins, resolveLink, serv
|
|
|
113
114
|
const stored = { version: 1, blocks: request.blocks };
|
|
114
115
|
const layout = await resolveCanvasLayout(stored, null, init.api, definitions, linkResolver);
|
|
115
116
|
const sheet = await classes;
|
|
116
|
-
const css = `${sheet.css}
|
|
117
|
+
const css = `${sheet.css}
|
|
117
118
|
${(await compiler).build(withoutClassNames(collectClasses(layout, definitions), new Set(sheet.names)))}`;
|
|
118
119
|
const done = new Promise((resolve) => {
|
|
119
120
|
rendered.current = resolve;
|