@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/CHANGELOG.md +6 -0
- package/dist/hooks/useAttachments.es.js +38 -39
- package/dist/hooks/useAttachments.es.js.map +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useAttachments.tsx +10 -15
package/package.json
CHANGED
|
@@ -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,
|
|
9
|
-
const { blockAssets, updateAssetIdsFromKey } = useBlockAssets(appBridge);
|
|
10
|
-
const attachments = blockAssets?.[
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
34
|
+
await updateAssetIdsFromKey(attachmentKey, newAssetIds);
|
|
40
35
|
};
|
|
41
36
|
|
|
42
37
|
return {
|