@geekapps/silo-elements-nextjs 0.2.48 → 0.2.50

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/dist/index.js CHANGED
@@ -1169,29 +1169,39 @@ function Video({
1169
1169
  const parsed = useMemo(() => parseVideoChildren(children), [children]);
1170
1170
  const [captions, setCaptions] = useState([]);
1171
1171
  const [poster, setPoster] = useState(void 0);
1172
+ const captionsSourceRef = useRef("");
1172
1173
  useEffect(() => {
1173
- if (!parsed.captionsSrc) {
1174
- setCaptions([]);
1175
- return;
1176
- }
1177
- let cancelled = false;
1178
- fetch(parsed.captionsSrc, { cache: "no-store" }).then((r) => r.json()).then((data) => {
1179
- if (!cancelled && Array.isArray(data)) {
1180
- const resolved = data.map((c, i) => ({ ...c, default: i === 0 }));
1181
- setCaptions(resolved);
1174
+ const sourceKey = parsed.captionsSrc ?? parsed.captionsData?.[0]?.srclang ?? "";
1175
+ function applyResolved(data) {
1176
+ const resolved = data.map((c, i) => ({ ...c, default: c.default ?? i === 0 }));
1177
+ setCaptions(resolved);
1178
+ if (captionsSourceRef.current !== sourceKey) {
1179
+ captionsSourceRef.current = sourceKey;
1182
1180
  const defaultTrack = resolved.find((c) => c.default);
1183
1181
  if (defaultTrack) {
1184
1182
  setSubtitleMode(defaultTrack.srclang);
1185
1183
  setSubtitleStyle((st) => ({ ...st, track: defaultTrack.srclang }));
1186
1184
  }
1187
1185
  }
1186
+ }
1187
+ if (parsed.captionsData) {
1188
+ applyResolved(parsed.captionsData);
1189
+ return;
1190
+ }
1191
+ if (!parsed.captionsSrc) {
1192
+ setCaptions([]);
1193
+ return;
1194
+ }
1195
+ let cancelled = false;
1196
+ fetch(parsed.captionsSrc, { cache: "no-store" }).then((r) => r.json()).then((data) => {
1197
+ if (!cancelled && Array.isArray(data)) applyResolved(data);
1188
1198
  }).catch(() => {
1189
1199
  if (!cancelled) setCaptions([]);
1190
1200
  });
1191
1201
  return () => {
1192
1202
  cancelled = true;
1193
1203
  };
1194
- }, [parsed.captionsSrc]);
1204
+ }, [parsed.captionsSrc, parsed.captionsData]);
1195
1205
  useEffect(() => {
1196
1206
  if (!parsed.thumbnailSrc) {
1197
1207
  setPoster(void 0);
@@ -2757,7 +2767,11 @@ function parseVideoChildren(children) {
2757
2767
  }
2758
2768
  if (child.type === Captions || name === "SiloCaptions") {
2759
2769
  const element = child;
2760
- parsed.captionsSrc = element.props.src;
2770
+ if (element.props.data) {
2771
+ parsed.captionsData = element.props.data;
2772
+ } else if (element.props.src) {
2773
+ parsed.captionsSrc = element.props.src;
2774
+ }
2761
2775
  }
2762
2776
  if (child.type === VideoThumbnail || name === "SiloVideoThumbnail") {
2763
2777
  const element = child;