@wordpress/upload-media
Version:
Core media upload logic.
8 lines (7 loc) • 7.92 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/store/private-selectors.ts"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport {\n\ttype BatchId,\n\tOperationType,\n\ttype QueueItem,\n\ttype QueueItemId,\n\ttype State,\n} from './types';\n\n/**\n * Returns all items currently being uploaded.\n *\n * @param state Upload state.\n *\n * @return Queue items.\n */\nexport function getAllItems( state: State ): QueueItem[] {\n\treturn state.queue;\n}\n\n/**\n * Returns a specific item given its unique ID.\n *\n * @param state Upload state.\n * @param id Item ID.\n *\n * @return Queue item.\n */\nexport function getItem(\n\tstate: State,\n\tid: QueueItemId\n): QueueItem | undefined {\n\treturn state.queue.find( ( item ) => item.id === id );\n}\n\n/**\n * Determines whether a batch has been successfully uploaded, given its unique ID.\n *\n * @param state Upload state.\n * @param batchId Batch ID.\n *\n * @return Whether a batch has been uploaded.\n */\nexport function isBatchUploaded( state: State, batchId: BatchId ): boolean {\n\tconst batchItems = state.queue.filter(\n\t\t( item ) => batchId === item.batchId\n\t);\n\treturn batchItems.length === 0;\n}\n\n/**\n * Determines whether uploading is currently paused.\n *\n * @param state Upload state.\n *\n * @return Whether uploading is currently paused.\n */\nexport function isPaused( state: State ): boolean {\n\treturn state.queueStatus === 'paused';\n}\n\n/**\n * Returns all cached blob URLs for a given item ID.\n *\n * @param state Upload state.\n * @param id Item ID\n *\n * @return List of blob URLs.\n */\nexport function getBlobUrls( state: State, id: QueueItemId ): string[] {\n\treturn state.blobUrls[ id ] || [];\n}\n\n/**\n * Returns the number of items currently uploading.\n *\n * @param state Upload state.\n *\n * @return Number of items currently uploading.\n */\nexport function getActiveUploadCount( state: State ): number {\n\treturn state.queue.filter(\n\t\t( item ) => item.currentOperation === OperationType.Upload\n\t).length;\n}\n\n/**\n * Returns items that are waiting for upload (next operation is Upload but not yet started).\n *\n * @param state Upload state.\n *\n * @return Items pending upload.\n */\nexport function getPendingUploads( state: State ): QueueItem[] {\n\treturn state.queue.filter( ( item ) => {\n\t\tconst nextOperation = Array.isArray( item.operations?.[ 0 ] )\n\t\t\t? item.operations[ 0 ][ 0 ]\n\t\t\t: item.operations?.[ 0 ];\n\t\treturn (\n\t\t\tnextOperation === OperationType.Upload &&\n\t\t\titem.currentOperation !== OperationType.Upload\n\t\t);\n\t} );\n}\n\n/**\n * Returns the number of items currently performing image processing operations.\n *\n * This counts items whose current operation is ResizeCrop or Rotate,\n * used to enforce the image processing concurrency limit.\n *\n * @param state Upload state.\n *\n * @return Number of items currently processing images.\n */\nexport function getActiveImageProcessingCount( state: State ): number {\n\treturn state.queue.filter(\n\t\t( item ) =>\n\t\t\titem.currentOperation === OperationType.ResizeCrop ||\n\t\t\titem.currentOperation === OperationType.Rotate\n\t).length;\n}\n\n/**\n * Returns the number of items currently performing video processing operations.\n *\n * This counts items whose current operation is TranscodeGif,\n * used to enforce the video processing concurrency limit (1 at a time).\n *\n * @param state Upload state.\n *\n * @return Number of items currently processing video.\n */\nexport function getActiveVideoProcessingCount( state: State ): number {\n\treturn state.queue.filter(\n\t\t( item ) => item.currentOperation === OperationType.TranscodeGif\n\t).length;\n}\n\n/**\n * Returns items waiting for image processing (next operation is ResizeCrop\n * or Rotate but not yet started).\n *\n * @param state Upload state.\n *\n * @return Items pending image processing.\n */\nexport function getPendingImageProcessing( state: State ): QueueItem[] {\n\treturn state.queue.filter( ( item ) => {\n\t\tconst nextOperation = Array.isArray( item.operations?.[ 0 ] )\n\t\t\t? item.operations[ 0 ][ 0 ]\n\t\t\t: item.operations?.[ 0 ];\n\t\treturn (\n\t\t\t( nextOperation === OperationType.ResizeCrop ||\n\t\t\t\tnextOperation === OperationType.Rotate ) &&\n\t\t\titem.currentOperation !== OperationType.ResizeCrop &&\n\t\t\titem.currentOperation !== OperationType.Rotate\n\t\t);\n\t} );\n}\n\n/**\n * Returns items waiting for video processing (next operation is TranscodeGif\n * but not yet started).\n *\n * @param state Upload state.\n *\n * @return Items pending video processing.\n */\nexport function getPendingVideoProcessing( state: State ): QueueItem[] {\n\treturn state.queue.filter( ( item ) => {\n\t\tconst nextOperation = Array.isArray( item.operations?.[ 0 ] )\n\t\t\t? item.operations[ 0 ][ 0 ]\n\t\t\t: item.operations?.[ 0 ];\n\t\treturn (\n\t\t\tnextOperation === OperationType.TranscodeGif &&\n\t\t\titem.currentOperation !== OperationType.TranscodeGif\n\t\t);\n\t} );\n}\n\n/**\n * Returns items that failed with an error.\n *\n * @param state Upload state.\n *\n * @return Failed items.\n */\nexport function getFailedItems( state: State ): QueueItem[] {\n\treturn state.queue.filter( ( item ) => item.error !== undefined );\n}\n\n/**\n * Returns true if any child items with the given parentId exist in the queue.\n *\n * @param state Upload state.\n * @param parentId Parent item ID.\n *\n * @return Whether any child items with the given parentId exist in the queue.\n */\nexport function hasPendingItemsByParentId(\n\tstate: State,\n\tparentId: QueueItemId\n): boolean {\n\treturn state.queue.some( ( item ) => item.parentId === parentId );\n}\n\n/**\n * Returns the progress of a specific item.\n *\n * @param state Upload state.\n * @param id Item ID.\n *\n * @return Progress value (0-100), or undefined if item not found.\n */\nexport function getItemProgress(\n\tstate: State,\n\tid: QueueItemId\n): number | undefined {\n\tconst item = state.queue.find( ( i ) => i.id === id );\n\treturn item?.progress;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAMO;AASA,SAAS,YAAa,OAA4B;AACxD,SAAO,MAAM;AACd;AAUO,SAAS,QACf,OACA,IACwB;AACxB,SAAO,MAAM,MAAM,KAAM,CAAE,SAAU,KAAK,OAAO,EAAG;AACrD;AAUO,SAAS,gBAAiB,OAAc,SAA4B;AAC1E,QAAM,aAAa,MAAM,MAAM;AAAA,IAC9B,CAAE,SAAU,YAAY,KAAK;AAAA,EAC9B;AACA,SAAO,WAAW,WAAW;AAC9B;A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