payload-canvas 0.6.2 → 0.6.3
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 +1 -0
- package/dist/blocks/defaults.js +17 -1
- package/dist/react/components/AutoplayVideo.d.ts +3 -1
- package/dist/react/components/AutoplayVideo.js +4 -3
- package/dist/react/components/Video.d.ts +1 -0
- package/dist/react/components/Video.js +13 -2
- package/dist/react/components/videoPlayback.d.ts +13 -0
- package/dist/react/components/videoPlayback.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1070,6 +1070,7 @@ export const blocks = [...defaultBlocks({ linkCollections: ['pages'] }), pricing
|
|
|
1070
1070
|
- Autoplay respects reduced motion. A `<video>` never gets the `autoplay` attribute. On the site a small client component starts it after mount, and only when the visitor does not ask for less motion (`prefers-reduced-motion: reduce`). Otherwise the video shows its poster and stays paused. A change of that setting plays or pauses it. Its JavaScript loads only on pages with an autoplaying video. Without JavaScript the video stays on its poster. A YouTube or Vimeo embed cannot check the setting: the player decides.
|
|
1071
1071
|
- On the canvas and in section thumbnails an autoplaying video stays paused on its poster, and an embed does not autoplay, so editing stays calm.
|
|
1072
1072
|
- The poster's focal point (`focalX`, `focalY`) sets `object-position` on the video, with the image block's rule: Payload's default 50/50 leaves the crop to the classes (`object-top`).
|
|
1073
|
+
- **Phone video** (`phoneVideo`, an upload, or `phoneUrl`, a video file link): a smaller copy that screens up to 767 px wide load instead (`<source media="(max-width: 767px)">`). Use an upright crop with the poster's framing: the poster's `object-position` applies to it too. To keep the framing, cut a crop of width `W` from a source of width `S` at `x = focalX% × (S − W)`. The browser picks the file once, when the page loads.
|
|
1073
1074
|
- A hero background video: in a stack with `relative isolate`, a `video` first with `autoplay`, `muted`, `loop`, `decorative`, `priority` and a `poster`, and the classes `absolute inset-0 -z-10 size-full object-cover`.
|
|
1074
1075
|
- `heading`: `accent`, words of the text to highlight. They render as `<em>`. Style them with classes on the heading, for example `[&_em]:text-primary [&_em]:not-italic`.
|
|
1075
1076
|
- `stack`: `as` (the inspector's **Tag**) also takes `ol`, `ul`, `li`, `dl`, `dt`, `dd`, `figure` and `figcaption`, for lists, term lists and captions. It takes no `p` or `span`: those cannot hold block children such as a heading.
|
package/dist/blocks/defaults.js
CHANGED
|
@@ -27,6 +27,7 @@ export function listCollectionField(slugs, args) {
|
|
|
27
27
|
: { name: 'collection', type: 'text', label: args.label, ...required, ...admin };
|
|
28
28
|
}
|
|
29
29
|
const PICKED_HELP = 'Shows only these, in this order.';
|
|
30
|
+
const PHONE_VIDEO_HELP = 'Optional. A smaller copy, such as an upright crop, that screens up to 767 px wide load instead. Keep the framing of the poster.';
|
|
30
31
|
/** The collection list's picked documents: a relationship to `slugs`, or ids as text when there are none. */
|
|
31
32
|
export function pickedDocumentsField(slugs) {
|
|
32
33
|
if (!slugs || slugs.length === 0) {
|
|
@@ -450,6 +451,20 @@ export function defaultBlocks(options) {
|
|
|
450
451
|
},
|
|
451
452
|
custom: { ai: { description: 'A YouTube or Vimeo link, or a direct link to a video file.' } },
|
|
452
453
|
},
|
|
454
|
+
{
|
|
455
|
+
name: 'phoneVideo',
|
|
456
|
+
type: 'upload',
|
|
457
|
+
label: 'Phone video',
|
|
458
|
+
relationTo: mediaCollection,
|
|
459
|
+
admin: { ...when('source', 'upload'), description: PHONE_VIDEO_HELP },
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: 'phoneUrl',
|
|
463
|
+
type: 'text',
|
|
464
|
+
label: 'Phone video link',
|
|
465
|
+
admin: { ...when('source', 'url'), placeholder: 'A video file', description: PHONE_VIDEO_HELP },
|
|
466
|
+
custom: { ai: { description: 'Optional. A direct link to a smaller video file that screens up to 767 px wide load instead.' } },
|
|
467
|
+
},
|
|
453
468
|
{ name: 'poster', type: 'upload', label: 'Poster image', relationTo: mediaCollection },
|
|
454
469
|
{
|
|
455
470
|
name: 'autoplay',
|
|
@@ -484,7 +499,8 @@ export function defaultBlocks(options) {
|
|
|
484
499
|
'see the poster). For a background video behind a hero: put the video first in a stack with "relative isolate", ' +
|
|
485
500
|
'set "autoplay", "muted", "loop" and "decorative": true (aria-hidden, no controls, no tab stop), "priority": ' +
|
|
486
501
|
'true when it is the first thing on the page (preload="auto", the poster preloads with high fetch priority), ' +
|
|
487
|
-
'a "poster", and className "absolute inset-0 -z-10 size-full object-cover".'
|
|
502
|
+
'a "poster", and className "absolute inset-0 -z-10 size-full object-cover". Optional "phoneVideo" (upload) or ' +
|
|
503
|
+
'"phoneUrl" (a video file link): a smaller copy, for example an upright crop, that screens up to 767 px wide load instead.',
|
|
488
504
|
example: {
|
|
489
505
|
type: 'video',
|
|
490
506
|
props: { source: 'url', url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', controls: true },
|
|
@@ -4,6 +4,8 @@ export type AutoplayVideoProps = {
|
|
|
4
4
|
attributes: Record<string, string | number>;
|
|
5
5
|
className?: string;
|
|
6
6
|
src: string;
|
|
7
|
+
/** A smaller copy for phones (`PHONE_MEDIA`). */
|
|
8
|
+
phoneSrc?: string;
|
|
7
9
|
poster?: string;
|
|
8
10
|
loop: boolean;
|
|
9
11
|
muted: boolean;
|
|
@@ -17,4 +19,4 @@ export type AutoplayVideoProps = {
|
|
|
17
19
|
* shows the poster and stays paused. A change of that setting plays or pauses it. A browser that
|
|
18
20
|
* refuses to play (an unmuted video) keeps the poster too.
|
|
19
21
|
*/
|
|
20
|
-
export declare function AutoplayVideo({ attributes, className, src, poster, loop, muted, controls, preload, style }: AutoplayVideoProps): import("react").JSX.Element;
|
|
22
|
+
export declare function AutoplayVideo({ attributes, className, src, phoneSrc, poster, loop, muted, controls, preload, style }: AutoplayVideoProps): import("react").JSX.Element;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import { useCanvasMode } from '../render/canvasMode.js';
|
|
5
|
-
import { REDUCED_MOTION, startsPlaying } from './videoPlayback.js';
|
|
5
|
+
import { REDUCED_MOTION, startsPlaying, videoSources } from './videoPlayback.js';
|
|
6
6
|
/**
|
|
7
7
|
* An autoplaying `<video>` that starts from script after mount, not with the `autoplay` attribute,
|
|
8
8
|
* so it can ask first: it plays only when the visitor does not ask for less motion. Otherwise it
|
|
9
9
|
* shows the poster and stays paused. A change of that setting plays or pauses it. A browser that
|
|
10
10
|
* refuses to play (an unmuted video) keeps the poster too.
|
|
11
11
|
*/
|
|
12
|
-
export function AutoplayVideo({ attributes, className, src, poster, loop, muted, controls, preload, style }) {
|
|
12
|
+
export function AutoplayVideo({ attributes, className, src, phoneSrc, poster, loop, muted, controls, preload, style }) {
|
|
13
13
|
const ref = useRef(null);
|
|
14
14
|
const canvas = useCanvasMode() !== 'site';
|
|
15
15
|
useEffect(() => {
|
|
@@ -30,5 +30,6 @@ export function AutoplayVideo({ attributes, className, src, poster, loop, muted,
|
|
|
30
30
|
query.addEventListener('change', sync);
|
|
31
31
|
return () => query.removeEventListener('change', sync);
|
|
32
32
|
}, [canvas, muted]);
|
|
33
|
-
|
|
33
|
+
const sources = videoSources(src, phoneSrc);
|
|
34
|
+
return (_jsx("video", { ref: ref, ...attributes, className: className, src: sources.length ? undefined : src, poster: poster, loop: loop, muted: muted, controls: controls, playsInline: true, preload: preload, style: style, children: sources.map((source) => (_jsx("source", { media: source.media, src: source.src }, source.src))) }));
|
|
34
35
|
}
|
|
@@ -10,5 +10,6 @@ import type { BlockComponentProps } from '../render/types.js';
|
|
|
10
10
|
* - `priority` (Load first): `preload="auto"`, and the poster preloads with high fetch priority.
|
|
11
11
|
* - The poster's focal point sets `object-position`, with the image block's rule (`focalStyle`).
|
|
12
12
|
* - `decorative`: `aria-hidden="true"`, no controls, no tab stop. For a background video.
|
|
13
|
+
* - A phone video (`phoneVideo` or `phoneUrl`, a file): screens up to 767 px wide load it instead.
|
|
13
14
|
*/
|
|
14
15
|
export declare function Video({ props, className, attributes, mode, canvasMode }: BlockComponentProps): import("react").JSX.Element | null;
|
|
@@ -4,7 +4,7 @@ import { focalStyle, isDoc } from './Image.js';
|
|
|
4
4
|
// The script that starts an autoplaying video loads only on pages that render one.
|
|
5
5
|
import { AutoplayVideo } from './lazy.js';
|
|
6
6
|
import { PlaceholderBox } from './placeholder.js';
|
|
7
|
-
import { decorativeAttributes, videoPreload, videoSettingsOf } from './videoPlayback.js';
|
|
7
|
+
import { decorativeAttributes, videoPreload, videoSettingsOf, videoSources } from './videoPlayback.js';
|
|
8
8
|
import { isPlayableVideoUrl, parseVideoUrl } from './videoUrl.js';
|
|
9
9
|
/** Classes that already give the element a height. Without one, an embed gets a 16:9 ratio. */
|
|
10
10
|
const SIZE_CLASS = /(^|\s|:)(aspect-|h-|size-|min-h-)/;
|
|
@@ -39,6 +39,7 @@ function InvalidUrl({ attributes, className }) {
|
|
|
39
39
|
* - `priority` (Load first): `preload="auto"`, and the poster preloads with high fetch priority.
|
|
40
40
|
* - The poster's focal point sets `object-position`, with the image block's rule (`focalStyle`).
|
|
41
41
|
* - `decorative`: `aria-hidden="true"`, no controls, no tab stop. For a background video.
|
|
42
|
+
* - A phone video (`phoneVideo` or `phoneUrl`, a file): screens up to 767 px wide load it instead.
|
|
42
43
|
*/
|
|
43
44
|
export function Video({ props, className, attributes, mode, canvasMode }) {
|
|
44
45
|
const canvas = mode === 'canvas' || canvasMode !== undefined;
|
|
@@ -51,6 +52,8 @@ export function Video({ props, className, attributes, mode, canvasMode }) {
|
|
|
51
52
|
// A missing source means the default ("upload"), unless only a URL is set.
|
|
52
53
|
const fromUrl = props.source === 'url' || (props.source == null && props.video == null && typeof props.url === 'string');
|
|
53
54
|
let src = null;
|
|
55
|
+
// A smaller copy for phones: a video file link, or an upload. A YouTube or Vimeo link does not count.
|
|
56
|
+
let phoneSrc;
|
|
54
57
|
if (fromUrl) {
|
|
55
58
|
const url = typeof props.url === 'string' ? props.url : '';
|
|
56
59
|
// A URL that cannot play: nothing on the site, a message on the canvas.
|
|
@@ -67,9 +70,15 @@ export function Video({ props, className, attributes, mode, canvasMode }) {
|
|
|
67
70
|
return (_jsx("iframe", { ...attributes, ...hidden, className: className, src: embed.embedUrl, title: embed.kind === 'youtube' ? 'YouTube video' : 'Vimeo video', allow: "accelerometer; autoplay; clipboard-write; encrypted-media; fullscreen; gyroscope; picture-in-picture; web-share", allowFullScreen: true, loading: settings.priority ? 'eager' : 'lazy', referrerPolicy: "strict-origin-when-cross-origin", style: style }));
|
|
68
71
|
}
|
|
69
72
|
src = embed?.src ?? null;
|
|
73
|
+
const phoneUrl = typeof props.phoneUrl === 'string' ? props.phoneUrl.trim() : '';
|
|
74
|
+
const phone = phoneUrl && isPlayableVideoUrl(phoneUrl) ? parseVideoUrl(phoneUrl, options) : null;
|
|
75
|
+
if (phone?.kind === 'file')
|
|
76
|
+
phoneSrc = phone.src;
|
|
70
77
|
}
|
|
71
78
|
else if (isDoc(props.video)) {
|
|
72
79
|
src = props.video.url;
|
|
80
|
+
if (isDoc(props.phoneVideo) && typeof props.phoneVideo.url === 'string')
|
|
81
|
+
phoneSrc = props.phoneVideo.url;
|
|
73
82
|
}
|
|
74
83
|
if (!src) {
|
|
75
84
|
if (mode !== 'canvas')
|
|
@@ -83,6 +92,7 @@ export function Video({ props, className, attributes, mode, canvasMode }) {
|
|
|
83
92
|
attributes: { ...attributes, ...hidden },
|
|
84
93
|
className,
|
|
85
94
|
src,
|
|
95
|
+
phoneSrc,
|
|
86
96
|
poster,
|
|
87
97
|
loop: options.loop,
|
|
88
98
|
muted: options.muted,
|
|
@@ -92,5 +102,6 @@ export function Video({ props, className, attributes, mode, canvasMode }) {
|
|
|
92
102
|
};
|
|
93
103
|
if (options.autoplay)
|
|
94
104
|
return _jsx(AutoplayVideo, { ...video });
|
|
95
|
-
|
|
105
|
+
const sources = videoSources(src, phoneSrc);
|
|
106
|
+
return (_jsx("video", { ...video.attributes, className: className, src: sources.length ? undefined : src, poster: poster, loop: video.loop, muted: video.muted, controls: video.controls, playsInline: true, preload: video.preload, style: video.style, children: sources.map((source) => (_jsx("source", { media: source.media, src: source.src }, source.src))) }));
|
|
96
107
|
}
|
|
@@ -23,6 +23,19 @@ export declare function startsPlaying(args: {
|
|
|
23
23
|
}): boolean;
|
|
24
24
|
/** The `preload` attribute: the whole video for a video that loads first, else only its metadata. */
|
|
25
25
|
export declare function videoPreload(priority: boolean): 'auto' | 'metadata';
|
|
26
|
+
/** Screens up to 767 px wide (below Tailwind's `md`) load the phone video, when the block has one. */
|
|
27
|
+
export declare const PHONE_MEDIA = "(max-width: 767px)";
|
|
28
|
+
/** One `<source>` of a video. */
|
|
29
|
+
export type VideoSource = {
|
|
30
|
+
src: string;
|
|
31
|
+
media?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The `<source>` list of a video with a phone copy: the phone copy first, for narrow screens, then
|
|
35
|
+
* the main file. Without a phone copy the list is empty and the `<video>` keeps its `src`.
|
|
36
|
+
* The browser picks a source once, when the video loads; a later resize does not switch it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function videoSources(src: string, phoneSrc?: string): VideoSource[];
|
|
26
39
|
/** The attributes that take a decorative video out of the accessibility tree and the tab order. */
|
|
27
40
|
export declare function decorativeAttributes(decorative: boolean): {
|
|
28
41
|
'aria-hidden'?: 'true';
|
|
@@ -27,6 +27,16 @@ export function startsPlaying(args) {
|
|
|
27
27
|
export function videoPreload(priority) {
|
|
28
28
|
return priority ? 'auto' : 'metadata';
|
|
29
29
|
}
|
|
30
|
+
/** Screens up to 767 px wide (below Tailwind's `md`) load the phone video, when the block has one. */
|
|
31
|
+
export const PHONE_MEDIA = '(max-width: 767px)';
|
|
32
|
+
/**
|
|
33
|
+
* The `<source>` list of a video with a phone copy: the phone copy first, for narrow screens, then
|
|
34
|
+
* the main file. Without a phone copy the list is empty and the `<video>` keeps its `src`.
|
|
35
|
+
* The browser picks a source once, when the video loads; a later resize does not switch it.
|
|
36
|
+
*/
|
|
37
|
+
export function videoSources(src, phoneSrc) {
|
|
38
|
+
return phoneSrc ? [{ src: phoneSrc, media: PHONE_MEDIA }, { src }] : [];
|
|
39
|
+
}
|
|
30
40
|
/** The attributes that take a decorative video out of the accessibility tree and the tab order. */
|
|
31
41
|
export function decorativeAttributes(decorative) {
|
|
32
42
|
return decorative ? { 'aria-hidden': 'true', tabIndex: -1 } : {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload-canvas",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Payload Canvas: a visual drag-and-drop website builder for Payload CMS 3. Nested layout blocks, Tailwind styling, sections, templates, live AI editing over MCP, and the React renderer for your site.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|