@cntrl-site/sdk-nextjs 0.12.9 → 0.14.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.
Files changed (30) hide show
  1. package/lib/components/Item.js +15 -4
  2. package/lib/components/items/CustomItem.js +18 -1
  3. package/lib/components/items/ImageItem.js +13 -0
  4. package/lib/components/items/RectangleItem.js +13 -0
  5. package/lib/components/items/RichTextItem.js +16 -2
  6. package/lib/components/items/VideoItem.js +13 -0
  7. package/lib/components/items/VimeoEmbed.js +42 -17
  8. package/lib/components/items/YoutubeEmbed.js +58 -13
  9. package/lib/components/useItemPosition.js +3 -17
  10. package/lib/utils/HoverStyles/HoverStyles.js +67 -0
  11. package/lib/utils/Youtube/YouTubeIframeApiLoader.js +53 -0
  12. package/lib/utils/Youtube/YoutubeIframeApi.js +12 -0
  13. package/lib/utils/Youtube/useYouTubeIframeApi.js +14 -0
  14. package/lib/utils/getItemTopStyle.js +18 -0
  15. package/package.json +4 -2
  16. package/src/components/Item.tsx +15 -5
  17. package/src/components/items/CustomItem.tsx +20 -2
  18. package/src/components/items/ImageItem.tsx +16 -2
  19. package/src/components/items/RectangleItem.tsx +14 -1
  20. package/src/components/items/RichTextItem.tsx +18 -4
  21. package/src/components/items/VideoItem.tsx +14 -1
  22. package/src/components/items/VimeoEmbed.tsx +58 -31
  23. package/src/components/items/YoutubeEmbed.tsx +59 -21
  24. package/src/components/useItemPosition.ts +1 -13
  25. package/src/utils/HoverStyles/HoverStyles.ts +74 -0
  26. package/src/utils/Youtube/YouTubeIframeApiLoader.ts +58 -0
  27. package/src/utils/Youtube/YoutubeIframeApi.ts +101 -0
  28. package/src/utils/Youtube/useYouTubeIframeApi.ts +12 -0
  29. package/src/utils/getItemTopStyle.ts +14 -0
  30. package/.idea/inspectionProfiles/Project_Default.xml +0 -15
@@ -0,0 +1,101 @@
1
+ export interface YT {
2
+ Player: YTPlayerConstructor;
3
+ }
4
+
5
+ export interface YTPlayerConstructor {
6
+ new(container: string | Element, params: YTPlayerParams): YTPlayer;
7
+ }
8
+
9
+ export interface YTEvent<Data> {
10
+ target: YTPlayer;
11
+ data: Data;
12
+ }
13
+
14
+ type YTBool = 0 | 1 | '0' | '1';
15
+
16
+ export interface YTPlayerParams {
17
+ width?: string | number;
18
+ height?: string | number;
19
+ videoId?: string;
20
+ playerVars?: Partial<{
21
+ autoplay: YTBool;
22
+ cc_lang_pref: string;
23
+ cc_load_policy: YTBool;
24
+ color: string;
25
+ controls: YTBool;
26
+ disablekb: YTBool;
27
+ enablejsapi: YTBool;
28
+ end: number | string;
29
+ fs: YTBool;
30
+ hl: string;
31
+ iv_load_policy: 1 | 3 | '1' | '3';
32
+ list: string;
33
+ listType: 'playlist' | 'user_uploads';
34
+ loop: YTBool;
35
+ origin: string;
36
+ playlist: string;
37
+ playsinline: YTBool;
38
+ rel: YTBool;
39
+ start: number | string;
40
+ widget_referrer: string;
41
+ }>;
42
+ events?: Partial<{
43
+ onReady: (event: YTEvent<void>) => void;
44
+ onStateChange: (event: YTEvent<YTPlayerState>) => void;
45
+ }>
46
+ }
47
+
48
+ export enum YTPlayerState {
49
+ Unstarted = -1,
50
+ Ended = 0,
51
+ Playing = 1,
52
+ Paused = 2,
53
+ Buffering = 3,
54
+ VideoCued = 5
55
+ }
56
+
57
+ export interface YTPlayer {
58
+ loadVideoById(videoId: string, startSeconds?: number): void;
59
+ loadVideoById(params: {
60
+ videoId: string;
61
+ startSeconds?: number;
62
+ endSeconds?: number;
63
+ }): void;
64
+
65
+ loadVideoByUrl(mediaContentUrl: string, startSeconds?: number): void;
66
+ loadVideoByUrl(params: {
67
+ mediaContentUrl: string;
68
+ startSeconds?: number;
69
+ endSeconds?: number;
70
+ }): void;
71
+
72
+ playVideo(): void;
73
+ pauseVideo(): void;
74
+ stopVideo(): void;
75
+ seekTo(seconds: number, allowSeekAhead: boolean): void;
76
+
77
+ mute(): void;
78
+ unMute(): void;
79
+ isMuted(): void;
80
+ setVolume(volume: number): void;
81
+ getVolume(): void;
82
+ setSize(width: number, height: number): void;
83
+ setLoop(loopPlaylists: boolean): void;
84
+
85
+ getVideoLoadedFraction(): number;
86
+ getPlayerState(): YTPlayerState;
87
+
88
+ getDuration(): number; // in seconds
89
+ getVideoUrl(): string;
90
+ getVideoEmbedCode(): string;
91
+
92
+ getIframe(): HTMLIFrameElement | undefined;
93
+ destroy(): void;
94
+ }
95
+
96
+ declare global {
97
+ interface Window {
98
+ YT?: YT;
99
+ onYouTubeIframeAPIReady?: () => void;
100
+ }
101
+ }
@@ -0,0 +1,12 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { YT } from './YoutubeIframeApi';
3
+ import { YouTubeIframeApiLoader } from './YouTubeIframeApiLoader';
4
+
5
+ export function useYouTubeIframeApi(): YT | undefined {
6
+ const [YT, setYT] = useState<YT | undefined>(undefined);
7
+ useEffect(() => {
8
+ const loader = YouTubeIframeApiLoader.create();
9
+ loader.getApi().then((YT) => setYT(YT));
10
+ }, []);
11
+ return YT;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { AnchorSide } from '@cntrl-site/sdk';
2
+
3
+ export function getItemTopStyle(top: number, anchorSide?: AnchorSide) {
4
+ const defaultValue = `${top * 100}vw`;
5
+ if (!anchorSide) return defaultValue;
6
+ switch (anchorSide) {
7
+ case AnchorSide.Top:
8
+ return defaultValue;
9
+ case AnchorSide.Center:
10
+ return `calc(50% + ${top * 100}vw)`;
11
+ case AnchorSide.Bottom:
12
+ return `calc(100% + ${top * 100}vw)`;
13
+ }
14
+ }
@@ -1,15 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
5
- <option name="myValues">
6
- <value>
7
- <list size="1">
8
- <item index="0" class="java.lang.String" itemvalue="jsx" />
9
- </list>
10
- </value>
11
- </option>
12
- <option name="myCustomValuesEnabled" value="true" />
13
- </inspection_tool>
14
- </profile>
15
- </component>