@frontify/guideline-blocks-settings 0.31.2 → 0.31.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontify/guideline-blocks-settings",
3
- "version": "0.31.2",
3
+ "version": "0.31.3",
4
4
  "description": "Provides types and helpers for the guideline block development",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.umd.js",
@@ -5,24 +5,19 @@ import { type ReactNode, createContext, useContext } from 'react';
5
5
 
6
6
  import { type BlockProps } from '../index';
7
7
 
8
- export const useAttachments = (appBridge: AppBridgeBlock, assetId: string) => {
9
- const { blockAssets, updateAssetIdsFromKey } = useBlockAssets(appBridge);
10
- const attachments = blockAssets?.[assetId] || [];
8
+ export const useAttachments = (appBridge: AppBridgeBlock, attachmentKey: string) => {
9
+ const { blockAssets, addAssetIdsToKey, deleteAssetIdsFromKey, updateAssetIdsFromKey } = useBlockAssets(appBridge);
10
+ const attachments = blockAssets?.[attachmentKey] || [];
11
11
 
12
12
  const onAttachmentsAdd = async (newAssets: Asset[]) => {
13
- const newAssetIds = attachments.map((attachment) => attachment.id);
14
- for (const asset of newAssets) {
15
- newAssetIds.push(asset.id);
16
- }
17
- await updateAssetIdsFromKey(assetId, newAssetIds);
13
+ await addAssetIdsToKey(
14
+ attachmentKey,
15
+ newAssets.map((asset) => asset.id),
16
+ );
18
17
  };
19
18
 
20
19
  const onAttachmentDelete = async (assetToDelete: Asset) => {
21
- const newAssetIds = attachments
22
- .filter((attachment) => attachment.id !== assetToDelete.id)
23
- .map((attachment) => attachment.id);
24
-
25
- await updateAssetIdsFromKey(assetId, newAssetIds);
20
+ await deleteAssetIdsFromKey(attachmentKey, [assetToDelete.id]);
26
21
  };
27
22
 
28
23
  const onAttachmentReplace = async (attachmentToReplace: Asset, newAsset: Asset) => {
@@ -30,13 +25,13 @@ export const useAttachments = (appBridge: AppBridgeBlock, assetId: string) => {
30
25
  attachment.id === attachmentToReplace.id ? newAsset.id : attachment.id,
31
26
  );
32
27
 
33
- await updateAssetIdsFromKey(assetId, newAssetIds);
28
+ await updateAssetIdsFromKey(attachmentKey, newAssetIds);
34
29
  };
35
30
 
36
31
  const onAttachmentsSorted = async (assets: Asset[]) => {
37
32
  const newAssetIds = assets.map((asset) => asset.id);
38
33
 
39
- await updateAssetIdsFromKey(assetId, newAssetIds);
34
+ await updateAssetIdsFromKey(attachmentKey, newAssetIds);
40
35
  };
41
36
 
42
37
  return {