@streamscloud/embeddable 6.3.2 → 6.3.4-1757324363709

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.
@@ -3,6 +3,7 @@ import type { IPlayerItemsProvider } from '../../ui/player';
3
3
  export declare class InternalShortVideoPlayerProvider implements IPlayerItemsProvider<ShortVideoViewerModel> {
4
4
  initialData: IPlayerItemsProvider<ShortVideoViewerModel>['initialData'];
5
5
  private ids;
6
+ private idOrder;
6
7
  private initialId?;
7
8
  private graphql;
8
9
  private dataLoader;
@@ -4,21 +4,25 @@ import { CursorDataLoader } from '../../core/data-loaders';
4
4
  import { createLocalGQLClient } from '../../core/graphql';
5
5
  import { mapToShortVideoViewerModel } from '../short-video-viewer';
6
6
  import { GetShortVideosDocument } from './operations.generated';
7
+ const CHUNK_SIZE = 20;
7
8
  export class InternalShortVideoPlayerProvider {
8
9
  initialData;
9
10
  ids;
11
+ idOrder = new Map();
10
12
  initialId;
11
13
  graphql;
12
14
  dataLoader = new CursorDataLoader({
13
15
  loadPage: async (continuationToken) => {
16
+ const startIdIndex = continuationToken.value ? parseInt(continuationToken.value, 10) : 0;
17
+ const endIdIndex = Math.min(startIdIndex + CHUNK_SIZE, this.ids.length);
18
+ const idsChunk = this.ids.slice(startIdIndex, endIdIndex);
14
19
  try {
15
20
  const payload = await this.graphql
16
21
  .query(GetShortVideosDocument, {
17
22
  input: {
18
- limit: 20,
19
- continuationToken,
23
+ limit: idsChunk.length,
20
24
  filter: {
21
- ids: this.ids
25
+ ids: idsChunk
22
26
  }
23
27
  },
24
28
  image_scale: ImageScale.OriginalEncoded
@@ -28,9 +32,14 @@ export class InternalShortVideoPlayerProvider {
28
32
  if (!data) {
29
33
  return null;
30
34
  }
35
+ const items = data.items.map(mapToShortVideoViewerModel).sort((a, b) => {
36
+ const ia = this.idOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER;
37
+ const ib = this.idOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER;
38
+ return ia - ib;
39
+ });
31
40
  return {
32
- items: data.items.map(mapToShortVideoViewerModel),
33
- continuationToken: ContinuationToken.fromPayload(data.continuationToken)
41
+ items,
42
+ continuationToken: ContinuationToken.fromPayload(endIdIndex < this.ids.length ? endIdIndex.toString() : null)
34
43
  };
35
44
  }
36
45
  catch {
@@ -42,6 +51,7 @@ export class InternalShortVideoPlayerProvider {
42
51
  const { ids, graphqlOrigin, initiator, initialId } = input;
43
52
  this.graphql = createLocalGQLClient(graphqlOrigin, initiator ? { 'x-initiator': initiator } : undefined);
44
53
  this.ids = ids;
54
+ ids.forEach((id, idx) => this.idOrder.set(id, idx));
45
55
  this.initialId = initialId;
46
56
  this.initialData = { prefetchedItems: [], startIndex: 0 };
47
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/embeddable",
3
- "version": "6.3.2",
3
+ "version": "6.3.4-1757324363709",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,9 @@
11
11
  "dev": "vite dev --port 3010",
12
12
  "build": "svelte-package --tsconfig ./tsconfig.app.json && prettier --write --plugin prettier-plugin-svelte . && eslint --fix .",
13
13
  "build-publish": "npm run build && npm publish --access public",
14
+ "publish:prod": "npm run build && npm publish --access public --tag latest",
15
+ "version:dev": "node -e \"const fs=require('fs');const pkg=require('./package.json');const base=(pkg.version.includes('-')?pkg.version.split('-')[0]:pkg.version);pkg.version=base+'-'+Date.now();fs.writeFileSync('package.json',JSON.stringify(pkg,null,2)+'\\n');\"",
16
+ "publish:dev": "npm run build && npm run version:dev && npm publish --tag next && git checkout -- package.json",
14
17
  "pack": "npm run build && npm pack",
15
18
  "preview": "vite preview",
16
19
  "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json",