@geekapps/silo-elements-nextjs 0.2.47 → 0.2.49

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.
@@ -9,7 +9,13 @@ type SourceProps = {
9
9
  default?: boolean;
10
10
  };
11
11
  type CaptionsProps = {
12
- src: string;
12
+ src?: string;
13
+ data?: Array<{
14
+ src: string;
15
+ srclang: string;
16
+ label: string;
17
+ default?: boolean;
18
+ }>;
13
19
  };
14
20
  type ThumbnailProps = {
15
21
  src: string;
@@ -43,22 +43,33 @@ function Video({
43
43
  const [captions, setCaptions] = useState([]);
44
44
  const [poster, setPoster] = useState(void 0);
45
45
  useEffect(() => {
46
+ function applyResolved(data) {
47
+ const resolved = data.map((c, i) => ({ ...c, default: c.default ?? i === 0 }));
48
+ setCaptions(resolved);
49
+ const defaultTrack = resolved.find((c) => c.default);
50
+ if (defaultTrack) {
51
+ setSubtitleMode(defaultTrack.srclang);
52
+ setSubtitleStyle((st) => ({ ...st, track: defaultTrack.srclang }));
53
+ }
54
+ }
55
+ if (parsed.captionsData) {
56
+ applyResolved(parsed.captionsData);
57
+ return;
58
+ }
46
59
  if (!parsed.captionsSrc) {
47
60
  setCaptions([]);
48
61
  return;
49
62
  }
50
63
  let cancelled = false;
51
64
  fetch(parsed.captionsSrc, { cache: "no-store" }).then((r) => r.json()).then((data) => {
52
- if (!cancelled && Array.isArray(data)) {
53
- setCaptions(data.map((c, i) => ({ ...c, default: i === 0 })));
54
- }
65
+ if (!cancelled && Array.isArray(data)) applyResolved(data);
55
66
  }).catch(() => {
56
67
  if (!cancelled) setCaptions([]);
57
68
  });
58
69
  return () => {
59
70
  cancelled = true;
60
71
  };
61
- }, [parsed.captionsSrc]);
72
+ }, [parsed.captionsSrc, parsed.captionsData]);
62
73
  useEffect(() => {
63
74
  if (!parsed.thumbnailSrc) {
64
75
  setPoster(void 0);
@@ -182,12 +193,6 @@ function Video({
182
193
  setSubtitleMode(initialSubtitleMode);
183
194
  }
184
195
  }, [subtitleMode, captions, initialSubtitleMode]);
185
- useEffect(() => {
186
- if (subtitleMode === "off" && initialSubtitleMode !== "off") {
187
- setSubtitleMode(initialSubtitleMode);
188
- setSubtitleStyle((st) => ({ ...st, track: initialSubtitleMode }));
189
- }
190
- }, [initialSubtitleMode]);
191
196
  useEffect(() => {
192
197
  const video = videoRef.current;
193
198
  if (!video) return;
@@ -1630,7 +1635,11 @@ function parseVideoChildren(children) {
1630
1635
  }
1631
1636
  if (child.type === Captions || name === "SiloCaptions") {
1632
1637
  const element = child;
1633
- parsed.captionsSrc = element.props.src;
1638
+ if (element.props.data) {
1639
+ parsed.captionsData = element.props.data;
1640
+ } else if (element.props.src) {
1641
+ parsed.captionsSrc = element.props.src;
1642
+ }
1634
1643
  }
1635
1644
  if (child.type === VideoThumbnail || name === "SiloVideoThumbnail") {
1636
1645
  const element = child;