@datocms/astro 0.1.13 → 0.2.1
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 +50 -38
- package/package.json +63 -50
- package/src/Image/Image.astro +14 -22
- package/src/Image/README.md +124 -0
- package/src/Image/buildSrcSet.ts +9 -16
- package/src/Image/index.ts +3 -1
- package/src/Image/types.ts +2 -2
- package/src/QueryListener/QueryListener.astro +56 -0
- package/src/QueryListener/README.md +67 -0
- package/src/QueryListener/index.ts +4 -0
- package/src/QueryListener/types.ts +12 -0
- package/src/Seo/README.md +57 -0
- package/src/Seo/Seo.astro +2 -2
- package/src/Seo/index.ts +3 -3
- package/src/Seo/renderMetaTagsToString.tsx +1 -3
- package/src/Seo/types.ts +9 -20
- package/src/StructuredText/Node.astro +15 -26
- package/src/StructuredText/README.md +42 -96
- package/src/StructuredText/StructuredText.astro +4 -6
- package/src/StructuredText/index.ts +2 -2
- package/src/StructuredText/nodes/Blockquote.astro +1 -1
- package/src/StructuredText/nodes/Code.astro +3 -3
- package/src/StructuredText/nodes/Heading.astro +1 -1
- package/src/StructuredText/nodes/Link.astro +3 -3
- package/src/StructuredText/nodes/List.astro +2 -2
- package/src/StructuredText/nodes/ListItem.astro +1 -1
- package/src/StructuredText/nodes/Paragraph.astro +1 -1
- package/src/StructuredText/nodes/Root.astro +1 -1
- package/src/StructuredText/nodes/Span.astro +8 -8
- package/src/StructuredText/nodes/ThematicBreak.astro +1 -1
- package/src/StructuredText/types.ts +1 -1
- package/src/StructuredText/utils.ts +71 -73
- package/src/index.ts +4 -0
- package/src/VideoPlayer/VideoPlayer.astro +0 -30
- package/src/VideoPlayer/index.ts +0 -2
- package/src/VideoPlayer/types.ts +0 -72
- package/src/VideoPlayer/utils.ts +0 -50
- package/src/useVideoPlayer/index.ts +0 -55
|
@@ -1,92 +1,90 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} from
|
|
2
|
+
type Block,
|
|
3
|
+
type InlineItem,
|
|
4
|
+
type ItemLink,
|
|
5
|
+
type Node,
|
|
6
|
+
RenderError,
|
|
7
|
+
type StructuredText,
|
|
8
|
+
isBlock,
|
|
9
|
+
isBlockquote,
|
|
10
|
+
isCode,
|
|
11
|
+
isHeading,
|
|
12
|
+
isInlineItem,
|
|
13
|
+
isItemLink,
|
|
14
|
+
isLink,
|
|
15
|
+
isList,
|
|
16
|
+
isListItem,
|
|
17
|
+
isParagraph,
|
|
18
|
+
isRoot,
|
|
19
|
+
isSpan,
|
|
20
|
+
isThematicBreak,
|
|
21
|
+
} from 'datocms-structured-text-utils';
|
|
22
22
|
|
|
23
|
-
import Blockquote from
|
|
24
|
-
import Code from
|
|
25
|
-
import Heading from
|
|
26
|
-
import Link from
|
|
27
|
-
import List from
|
|
28
|
-
import ListItem from
|
|
29
|
-
import Paragraph from
|
|
30
|
-
import Root from
|
|
31
|
-
import Span from
|
|
32
|
-
import ThematicBreak from
|
|
23
|
+
import Blockquote from './nodes/Blockquote.astro';
|
|
24
|
+
import Code from './nodes/Code.astro';
|
|
25
|
+
import Heading from './nodes/Heading.astro';
|
|
26
|
+
import Link from './nodes/Link.astro';
|
|
27
|
+
import List from './nodes/List.astro';
|
|
28
|
+
import ListItem from './nodes/ListItem.astro';
|
|
29
|
+
import Paragraph from './nodes/Paragraph.astro';
|
|
30
|
+
import Root from './nodes/Root.astro';
|
|
31
|
+
import Span from './nodes/Span.astro';
|
|
32
|
+
import ThematicBreak from './nodes/ThematicBreak.astro';
|
|
33
33
|
|
|
34
|
-
import type { PredicateComponentTuple } from
|
|
34
|
+
import type { PredicateComponentTuple } from './types';
|
|
35
35
|
|
|
36
36
|
export const defaultComponents: PredicateComponentTuple[] = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
[isParagraph, Paragraph],
|
|
38
|
+
[isRoot, Root],
|
|
39
|
+
[isSpan, Span],
|
|
40
|
+
[isLink, Link],
|
|
41
|
+
[isList, List],
|
|
42
|
+
[isHeading, Heading],
|
|
43
|
+
[isBlockquote, Blockquote],
|
|
44
|
+
[isListItem, ListItem],
|
|
45
|
+
[isThematicBreak, ThematicBreak],
|
|
46
|
+
[isCode, Code],
|
|
47
47
|
];
|
|
48
48
|
|
|
49
49
|
export const throwRenderErrorForMissingComponent = (node: Node) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
if (isInlineItem(node)) {
|
|
51
|
+
throw new RenderError(
|
|
52
|
+
`The Structured Text document contains an 'inlineItem' node, but no component for rendering is specified!`,
|
|
53
|
+
node,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (isItemLink(node)) {
|
|
58
|
+
throw new RenderError(
|
|
59
|
+
`The Structured Text document contains an 'itemLink' node, but no component for rendering is specified!`,
|
|
60
|
+
node,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (isBlock(node)) {
|
|
65
|
+
throw new RenderError(
|
|
66
|
+
`The Structured Text document contains a 'block' node, but no component for rendering is specified!`,
|
|
67
|
+
node,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const throwRenderErrorForMissingBlock = (node: Block) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
throw new RenderError(
|
|
74
|
+
`The Structured Text document contains a 'block' node, but cannot find a record with ID ${node.item} inside data.blocks!`,
|
|
75
|
+
node,
|
|
76
|
+
);
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export const throwRenderErrorForMissingLink = (node: ItemLink | InlineItem) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
throw new RenderError(
|
|
81
|
+
`The Structured Text document contains an 'itemLink' node, but cannot find a record with ID ${node.item} inside data.links!`,
|
|
82
|
+
node,
|
|
83
|
+
);
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
export const findBlock = (node: Block, blocks: StructuredText[
|
|
87
|
-
|
|
86
|
+
export const findBlock = (node: Block, blocks: StructuredText['blocks']) =>
|
|
87
|
+
(blocks || []).find(({ id }) => id === node.item);
|
|
88
88
|
|
|
89
|
-
export const findLink = (
|
|
90
|
-
|
|
91
|
-
links: StructuredText["links"],
|
|
92
|
-
) => (links || []).find(({ id }) => id === node.item);
|
|
89
|
+
export const findLink = (node: ItemLink | InlineItem, links: StructuredText['links']) =>
|
|
90
|
+
(links || []).find(({ id }) => id === node.item);
|
package/src/index.ts
ADDED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { VideoPlayerProps } from "./types";
|
|
3
|
-
import { useVideoPlayer } from "../useVideoPlayer";
|
|
4
|
-
import { toNativeProps } from "./utils";
|
|
5
|
-
|
|
6
|
-
interface Props extends VideoPlayerProps {}
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
data,
|
|
10
|
-
disableCookies = true,
|
|
11
|
-
preload = "metadata",
|
|
12
|
-
...otherProps
|
|
13
|
-
} = Astro.props;
|
|
14
|
-
|
|
15
|
-
const computedProps = {
|
|
16
|
-
...useVideoPlayer({ data }),
|
|
17
|
-
disableCookies,
|
|
18
|
-
preload,
|
|
19
|
-
};
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<mux-player
|
|
23
|
-
stream-type="on-demand"
|
|
24
|
-
{...toNativeProps(computedProps)}
|
|
25
|
-
{...toNativeProps(otherProps)}
|
|
26
|
-
></mux-player>
|
|
27
|
-
|
|
28
|
-
<script>
|
|
29
|
-
import "@mux/mux-player";
|
|
30
|
-
</script>
|
package/src/VideoPlayer/index.ts
DELETED
package/src/VideoPlayer/types.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { MuxMediaProps } from "@mux/playback-core";
|
|
2
|
-
import type { JSX } from 'astro/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
type StyleAttribute = JSX.HTMLAttributes["style"];
|
|
5
|
-
|
|
6
|
-
type Maybe<T> = T | null;
|
|
7
|
-
|
|
8
|
-
export type Video = {
|
|
9
|
-
/** Title attribute (`title`) for the video */
|
|
10
|
-
title?: Maybe<string>;
|
|
11
|
-
/** The height of the video */
|
|
12
|
-
height?: Maybe<number>;
|
|
13
|
-
/** The width of the video */
|
|
14
|
-
width?: Maybe<number>;
|
|
15
|
-
/** The MUX playback ID */
|
|
16
|
-
muxPlaybackId?: Maybe<string>;
|
|
17
|
-
/** The MUX playback ID */
|
|
18
|
-
playbackId?: Maybe<string>;
|
|
19
|
-
/** A data: URI containing a blurhash for the video */
|
|
20
|
-
blurUpThumb?: Maybe<string>;
|
|
21
|
-
/** Other data can be passed, but they have no effect on rendering the player */
|
|
22
|
-
// biome-ignore lint/suspicious/noExplicitAny: we intentionally want to allow to add any other value to this video object
|
|
23
|
-
[k: string]: any;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Extracted from mux-player-react
|
|
27
|
-
|
|
28
|
-
type VideoApiAttributes = {
|
|
29
|
-
currentTime: number;
|
|
30
|
-
volume: number;
|
|
31
|
-
paused: boolean;
|
|
32
|
-
src: string | null;
|
|
33
|
-
poster: string;
|
|
34
|
-
playbackRate: number;
|
|
35
|
-
playsInline: boolean;
|
|
36
|
-
preload: string;
|
|
37
|
-
crossOrigin: string;
|
|
38
|
-
autoPlay: boolean | string;
|
|
39
|
-
loop: boolean;
|
|
40
|
-
muted: boolean;
|
|
41
|
-
class?: string;
|
|
42
|
-
style?: StyleAttribute;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Extracted from mux-player-react
|
|
46
|
-
|
|
47
|
-
export type MuxPlayerProps = Partial<MuxMediaProps> & Partial<VideoApiAttributes> & {
|
|
48
|
-
hotkeys?: string;
|
|
49
|
-
nohotkeys?: boolean;
|
|
50
|
-
defaultHiddenCaptions?: boolean;
|
|
51
|
-
forwardSeekOffset?: number;
|
|
52
|
-
backwardSeekOffset?: number;
|
|
53
|
-
metadataVideoId?: string;
|
|
54
|
-
metadataVideoTitle?: string;
|
|
55
|
-
metadataViewerUserId?: string;
|
|
56
|
-
primaryColor?: string;
|
|
57
|
-
secondaryColor?: string;
|
|
58
|
-
accentColor?: string;
|
|
59
|
-
placeholder?: string;
|
|
60
|
-
playbackRates?: number[];
|
|
61
|
-
defaultShowRemainingTime?: boolean;
|
|
62
|
-
defaultDuration?: number;
|
|
63
|
-
noVolumePref?: boolean;
|
|
64
|
-
thumbnailTime?: number;
|
|
65
|
-
title?: string;
|
|
66
|
-
theme?: string;
|
|
67
|
-
themeProps?: { [k: string]: any };
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type VideoPlayerProps = MuxPlayerProps & {
|
|
71
|
-
data: Video;
|
|
72
|
-
};
|
package/src/VideoPlayer/utils.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Adapted from mux-player-react
|
|
2
|
-
|
|
3
|
-
const ReactPropToAttrNameMap = {
|
|
4
|
-
crossOrigin: 'crossorigin',
|
|
5
|
-
viewBox: 'viewBox',
|
|
6
|
-
playsInline: 'playsinline',
|
|
7
|
-
autoPlay: 'autoplay',
|
|
8
|
-
playbackRate: 'playbackrate',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
type KeyTypes = string | number | symbol;
|
|
12
|
-
type Maybe<T> = T | null | undefined;
|
|
13
|
-
|
|
14
|
-
const isNil = (x: unknown): x is null | undefined => x === undefined;
|
|
15
|
-
|
|
16
|
-
// Type Guard to determine if a given key is actually a key of some object of type T
|
|
17
|
-
export const isKeyOf = <T extends {} = any>(k: KeyTypes, o: Maybe<T>): k is keyof T => {
|
|
18
|
-
if (isNil(o)) return false;
|
|
19
|
-
return k in o;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const toKebabCase = (string: string) => string.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
23
|
-
|
|
24
|
-
const toNativeAttrName = (propName: string, propValue: any): string | undefined => {
|
|
25
|
-
if (typeof propValue === 'boolean' && !propValue) return undefined;
|
|
26
|
-
if (isKeyOf(propName, ReactPropToAttrNameMap)) return ReactPropToAttrNameMap[propName];
|
|
27
|
-
if (propValue === undefined) return undefined;
|
|
28
|
-
if (/[A-Z]/.test(propName)) return toKebabCase(propName);
|
|
29
|
-
return propName;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const toNativeAttrValue = (propValue: any, propName: string) => {
|
|
33
|
-
if (typeof propValue === 'boolean') return '';
|
|
34
|
-
return propValue;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const toNativeProps = (props = {}) => {
|
|
38
|
-
return Object.entries(props).reduce<{ [k: string]: string }>((transformedProps, [propName, propValue]) => {
|
|
39
|
-
const attrName = toNativeAttrName(propName, propValue);
|
|
40
|
-
|
|
41
|
-
// prop was stripped. Don't add.
|
|
42
|
-
if (!attrName) {
|
|
43
|
-
return transformedProps;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const attrValue = toNativeAttrValue(propValue, propName);
|
|
47
|
-
transformedProps[attrName] = attrValue;
|
|
48
|
-
return transformedProps;
|
|
49
|
-
}, {});
|
|
50
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { MuxPlayerProps, Video } from "../VideoPlayer/types";
|
|
2
|
-
|
|
3
|
-
type Maybe<T> = T | null;
|
|
4
|
-
type Possibly<T> = Maybe<T> | undefined;
|
|
5
|
-
|
|
6
|
-
function computedTitle(title: Possibly<string>): MuxPlayerProps {
|
|
7
|
-
return title ? { title } : {};
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
function computedPlaybackId(
|
|
11
|
-
muxPlaybackId: Possibly<string>,
|
|
12
|
-
playbackId: Possibly<string>,
|
|
13
|
-
): MuxPlayerProps {
|
|
14
|
-
if (!(muxPlaybackId || playbackId)) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return { playbackId: `${muxPlaybackId || playbackId}` };
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function computedStyle(width: Possibly<number>, height: Possibly<number>): MuxPlayerProps {
|
|
22
|
-
if (!(width && height)) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
style: {
|
|
28
|
-
aspectRatio: `${width} / ${height}`,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function computedPlaceholder(blurUpThumb: Possibly<string>): MuxPlayerProps {
|
|
34
|
-
return blurUpThumb ? { placeholder: blurUpThumb } : {};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type UseVideoPlayerArgs = {
|
|
38
|
-
data?: Video;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export function useVideoPlayer({
|
|
42
|
-
data,
|
|
43
|
-
}: UseVideoPlayerArgs): MuxPlayerProps {
|
|
44
|
-
const { title, width, height, playbackId, muxPlaybackId, blurUpThumb } =
|
|
45
|
-
data || {};
|
|
46
|
-
|
|
47
|
-
if (data === undefined) return {};
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
...(computedTitle(title) || {}),
|
|
51
|
-
...(computedPlaybackId(muxPlaybackId, playbackId) || {}),
|
|
52
|
-
...(computedStyle(width, height) || {}),
|
|
53
|
-
...(computedPlaceholder(blurUpThumb) || {}),
|
|
54
|
-
};
|
|
55
|
-
};
|