@flipdish/portal-library 7.10.2 → 7.10.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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),a=require("react"),l=require("@mui/material/styles"),r=require("@mui/material/Box"),s=require("@mui/material/Tab"),t=require("../../molecules/Modal/index.cjs.js"),i=require("../../molecules/Tabs/index.cjs.js"),n=require("@tanstack/react-query"),c=require("./LibraryTabContent/index.cjs.js"),o=require("./UploadTabContent/index.cjs.js");const u=l.styled(r)((({theme:e})=>({marginBottom:e.spacing(3)}))),d=new n.QueryClient;module.exports=({open:l,onClose:r,onSelect:b,orgId:m,brandId:p,multiSelect:y=!1})=>{const[C,j]=a.useState(new Map),[g,x]=a.useState("library"),[k,q]=a.useState([]);a.useEffect((()=>{l||(j(new Map),q([]))}),[l]);const v=a.useCallback((()=>{j(new Map),r()}),[r]),h=a.useCallback((()=>{const e=Array.from(C.values());b&&e.length>0&&b(e),j(new Map),r()}),[b,C,r]),f=a.useCallback((e=>{j((a=>{const l=a.has(e.id),r=new Map(a);return y?l?r.delete(e.id):r.set(e.id,e):l?r.clear():(r.clear(),r.set(e.id,e)),r}))}),[y]),S=a.useCallback((()=>{q([]),x("library")}),[]),M=a.useCallback((e=>{const a=e.map((e=>({file:e})));q((e=>[...e,...a]))}),[]),w=a.useCallback((e=>{q((a=>a.filter((a=>a.file!==e))))}),[]),I=a.useMemo((()=>{const e={label:"Cancel",onClick:v,variant:"secondary",tone:"neutral",id:"asset-manager-cancel"},a={library:[e,{label:"Select",onClick:h,variant:"primary",disabled:0===C.size,id:"asset-manager-select"}],upload:[e,{label:"Save",onClick:S,disabled:0===k.length,variant:"primary",id:"asset-manager-upload"}]};return a[g]??a.library}),[g,C.size,k.length,v,h,S]);return e.jsx(n.QueryClientProvider,{client:d,children:e.jsxs(t,{actions:I,onClose:v,open:l,size:"large",title:"library"===g?"Select Images":"Upload Images",children:[e.jsx(u,{children:e.jsxs(i,{fdKey:"asset-manager-tabs",onChange:(e,a)=>x(a),value:g,children:[e.jsx(s,{label:"Upload",value:"upload"}),e.jsx(s,{label:"Library",value:"library"})]})}),"library"===g?e.jsx(c,{brandId:p,enabled:l,onAssetClick:f,orgId:m,selectedAssets:C}):e.jsx(o,{files:k,onRemove:w,onUpload:M})]})})};
1
+ "use strict";var e=require("react/jsx-runtime"),a=require("react"),l=require("@mui/material/styles"),r=require("@mui/material/Box"),s=require("@mui/material/Tab"),i=require("../../molecules/Modal/index.cjs.js"),t=require("../../molecules/Tabs/index.cjs.js"),n=require("@tanstack/react-query"),c=require("./LibraryTabContent/index.cjs.js"),o=require("./UploadTabContent/index.cjs.js");const u=l.styled(r)((({theme:e})=>({marginBottom:e.spacing(3)}))),d=new n.QueryClient;module.exports=({open:l,onClose:r,onSelect:b,orgId:m,brandId:p,maxSelect:y=1})=>{const[C,j]=a.useState(new Map),[x,g]=a.useState("library"),[k,q]=a.useState([]);a.useEffect((()=>{l||(j(new Map),q([]))}),[l]);const v=a.useCallback((()=>{j(new Map),r()}),[r]),h=a.useCallback((()=>{const e=Array.from(C.values());b&&e.length>0&&b(e),j(new Map),r()}),[b,C,r]),f=a.useCallback((e=>{j((a=>{const l=a.has(e.id),r=new Map(a);return l?r.delete(e.id):1===y?(r.clear(),r.set(e.id,e)):r.size<y&&r.set(e.id,e),r}))}),[y]),S=a.useCallback((()=>{q([]),g("library")}),[]),M=a.useCallback((e=>{const a=e.map((e=>({file:e})));q((e=>[...e,...a]))}),[]),w=a.useCallback((e=>{q((a=>a.filter((a=>a.file!==e))))}),[]),I=a.useMemo((()=>{const e={label:"Cancel",onClick:v,variant:"secondary",tone:"neutral",id:"asset-manager-cancel"},a={library:[e,{label:"Select",onClick:h,variant:"primary",disabled:0===C.size,id:"asset-manager-select"}],upload:[e,{label:"Save",onClick:S,disabled:0===k.length,variant:"primary",id:"asset-manager-upload"}]};return a[x]??a.library}),[x,C.size,k.length,v,h,S]);return e.jsx(n.QueryClientProvider,{client:d,children:e.jsxs(i,{actions:I,onClose:v,open:l,size:"large",title:"library"===x?"Select Images":"Upload Images",children:[e.jsx(u,{children:e.jsxs(t,{fdKey:"asset-manager-tabs",onChange:(e,a)=>g(a),value:x,children:[e.jsx(s,{label:"Upload",value:"upload"}),e.jsx(s,{label:"Library",value:"library"})]})}),"library"===x?e.jsx(c,{brandId:p,enabled:l,onAssetClick:f,orgId:m,selectedAssets:C}):e.jsx(o,{files:k,onRemove:w,onUpload:M})]})})};
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../../../src/components/organisms/AssetManager/index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\n\nimport { styled } from '@mui/material/styles';\n\nimport Box from '@fd/components/atoms/Box';\nimport Tab from '@fd/components/atoms/Tab';\nimport Modal, { type ModalAction } from '@fd/components/molecules/Modal';\nimport Tabs from '@fd/components/molecules/Tabs';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport type { FileUploadState } from '../FileUpload';\nimport LibraryTabContent from './LibraryTabContent';\nimport type { Asset } from './types';\nimport UploadAssetContent from './UploadTabContent';\n\nconst StyledTabsContainer = styled(Box)(({ theme }) => ({\n marginBottom: theme.spacing(3),\n}));\n\n/**\n * Props for the AssetManager component.\n * Provides a modal interface for selecting images from a grid display.\n * It supports both single and multiple image selection modes.\n *\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n *\n * ```tsx\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n */\nexport interface AssetManagerProps {\n /** Whether the asset manager modal is open */\n open: boolean;\n /** Callback function when the modal is closed or cancelled */\n onClose: () => void;\n /** Callback function when assets are selected */\n onSelect?: (selectedAssets: Asset[]) => void;\n /**\n * Organization ID for fetching assets\n */\n orgId: string;\n /** Brand ID for fetching assets */\n brandId?: string;\n /** Whether multiple assets can be selected. Defaults to false */\n multiSelect?: boolean;\n}\n\n// Create a QueryClient instance for the AssetManager component\n// This allows the component to be used without requiring clients to wrap it in QueryClientProvider\nconst queryClient = new QueryClient();\n\n/**\n * AssetManager component used to select assets from the library or upload new assets.\n * Can manage assets at a organization or brand level.\n *\n * @example\n * ```tsx\n * <AssetManager\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * onSelect={(assets) => console.log(assets)}\n * orgId=\"org123\"\n * brandId=\"brand456\"\n * multiSelect={true}\n * />\n * ```\n */\nconst AssetManager: React.FC<AssetManagerProps> = ({\n open,\n onClose,\n onSelect,\n orgId,\n brandId,\n multiSelect = false,\n}) => {\n // Use Map for O(1) lookup performance and direct access to Asset objects\n const [selectedAssetsMap, setSelectedAssetsMap] = useState<Map<string, Asset>>(new Map());\n const [selectedTab, setSelectedTab] = useState<string>('library');\n const [uploadedFiles, setUploadedFiles] = useState<FileUploadState[]>([]);\n\n // Reset selection when modal opens/closes\n useEffect(() => {\n if (!open) {\n setSelectedAssetsMap(new Map());\n setUploadedFiles([]);\n }\n }, [open]);\n\n const handleCancel = useCallback((): void => {\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onClose]);\n\n const handleSelect = useCallback((): void => {\n const selectedAssets = Array.from(selectedAssetsMap.values());\n if (onSelect && selectedAssets.length > 0) {\n onSelect(selectedAssets);\n }\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onSelect, selectedAssetsMap, onClose]);\n\n // TODO: translate titles\n const getTitle = (): string => {\n switch (selectedTab) {\n case 'library':\n return 'Select Images';\n default:\n return 'Upload Images';\n }\n };\n\n const handleAssetClick = useCallback(\n (asset: Asset): void => {\n setSelectedAssetsMap((prevMap) => {\n const isSelected = prevMap.has(asset.id);\n const newMap = new Map(prevMap);\n\n if (multiSelect) {\n if (isSelected) {\n newMap.delete(asset.id);\n } else {\n newMap.set(asset.id, asset);\n }\n } else {\n // Single select: replace selection or clear if clicking same asset\n if (isSelected) {\n newMap.clear();\n } else {\n newMap.clear();\n newMap.set(asset.id, asset);\n }\n }\n\n return newMap;\n });\n },\n [multiSelect],\n );\n\n const handleSaveAssets = useCallback((): void => {\n // TODO: call Upload asset api\n setUploadedFiles([]);\n setSelectedTab('library');\n }, []);\n\n const handleUpload = useCallback((files: File[]): void => {\n // Add files with uploading state\n const newFiles: FileUploadState[] = files.map((file) => ({\n file,\n }));\n setUploadedFiles((prev) => [...prev, ...newFiles]);\n }, []);\n\n const handleRemove = useCallback((fileToRemove: File): void => {\n setUploadedFiles((prev) => prev.filter((fileState) => fileState.file !== fileToRemove));\n }, []);\n\n // Tab-specific action button configurations\n // TODO: translate button labels\n const actionButtons = useMemo<ModalAction[]>(() => {\n // Common cancel button configuration\n const cancelButton: ModalAction = {\n label: 'Cancel',\n onClick: handleCancel,\n variant: 'secondary',\n tone: 'neutral',\n id: 'asset-manager-cancel',\n };\n\n const tabActions: Record<string, ModalAction[]> = {\n library: [\n cancelButton,\n {\n label: 'Select',\n onClick: handleSelect,\n variant: 'primary',\n disabled: selectedAssetsMap.size === 0,\n id: 'asset-manager-select',\n },\n ],\n upload: [\n cancelButton,\n {\n label: 'Save',\n onClick: handleSaveAssets,\n disabled: uploadedFiles.length === 0,\n variant: 'primary',\n id: 'asset-manager-upload',\n },\n ],\n };\n\n return tabActions[selectedTab] ?? (tabActions['library'] as ModalAction[]);\n }, [\n selectedTab,\n selectedAssetsMap.size,\n uploadedFiles.length,\n handleCancel,\n handleSelect,\n handleSaveAssets,\n ]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <Modal actions={actionButtons} onClose={handleCancel} open={open} size=\"large\" title={getTitle()}>\n <StyledTabsContainer>\n <Tabs\n fdKey=\"asset-manager-tabs\"\n onChange={(_, value: string) => setSelectedTab(value)}\n value={selectedTab}\n >\n <Tab label=\"Upload\" value=\"upload\" />\n <Tab label=\"Library\" value=\"library\" />\n </Tabs>\n </StyledTabsContainer>\n {selectedTab === 'library' ? (\n <LibraryTabContent\n brandId={brandId}\n enabled={open}\n onAssetClick={handleAssetClick}\n orgId={orgId}\n selectedAssets={selectedAssetsMap}\n />\n ) : (\n <UploadAssetContent files={uploadedFiles} onRemove={handleRemove} onUpload={handleUpload} />\n )}\n </Modal>\n </QueryClientProvider>\n );\n};\n\nexport default AssetManager;\n"],"names":["StyledTabsContainer","styled","Box","theme","marginBottom","spacing","queryClient","QueryClient","open","onClose","onSelect","orgId","brandId","multiSelect","selectedAssetsMap","setSelectedAssetsMap","useState","Map","selectedTab","setSelectedTab","uploadedFiles","setUploadedFiles","useEffect","handleCancel","useCallback","handleSelect","selectedAssets","Array","from","values","length","handleAssetClick","asset","prevMap","isSelected","has","id","newMap","delete","set","clear","handleSaveAssets","handleUpload","files","newFiles","map","file","prev","handleRemove","fileToRemove","filter","fileState","actionButtons","useMemo","cancelButton","label","onClick","variant","tone","tabActions","library","disabled","size","upload","_jsx","QueryClientProvider","client","children","_jsxs","Modal","actions","title","Tabs","fdKey","onChange","_","value","Tab","LibraryTabContent","enabled","onAssetClick","UploadAssetContent","onRemove","onUpload"],"mappings":"gYAeA,MAAMA,EAAsBC,EAAAA,OAAOC,EAAPD,EAAY,EAAGE,YAAO,CAChDC,aAAcD,EAAME,QAAQ,OAgCxBC,EAAc,IAAIC,EAAAA,2BAkB0B,EAChDC,OACAC,UACAC,WACAC,QACAC,UACAC,eAAc,MAGd,MAAOC,EAAmBC,GAAwBC,EAAAA,SAA6B,IAAIC,MAC5EC,EAAaC,GAAkBH,EAAAA,SAAiB,YAChDI,EAAeC,GAAoBL,EAAAA,SAA4B,IAGtEM,EAAAA,WAAU,KACHd,IACHO,EAAqB,IAAIE,KACzBI,EAAiB,OAElB,CAACb,IAEJ,MAAMe,EAAeC,EAAAA,aAAY,KAC/BT,EAAqB,IAAIE,KACzBR,MACC,CAACA,IAEEgB,EAAeD,EAAAA,aAAY,KAC/B,MAAME,EAAiBC,MAAMC,KAAKd,EAAkBe,UAChDnB,GAAYgB,EAAeI,OAAS,GACtCpB,EAASgB,GAEXX,EAAqB,IAAIE,KAC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G,gBAEA,0BAkGP8C,EAAAA,IAAChE,EAAmB,CAAAmE,SAClBC,EAAAA,KAACI,EAAI,CACHC,MAAM,qBACNC,SAAU,CAACC,EAAGC,IAAkBzD,EAAeyD,GAC/CA,MAAO1D,EAAWiD,SAAA,CAElBH,MAACa,EAAG,CAACtB,MAAM,SAASqB,MAAM,WAC1BZ,EAAAA,IAACa,EAAG,CAACtB,MAAM,UAAUqB,MAAM,iBAGd,YAAhB1D,EACC8C,MAACc,EAAiB,CAChBlE,QAASA,EACTmE,QAASvE,EACTwE,aAAcjD,EACdpB,MAAOA,EACPe,eAAgBZ,IAGlBkD,MAACiB,EAAkB,CAACtC,MAAOvB,EAAe8D,SAAUlC,EAAcmC,SAAUzC"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../../../../src/components/organisms/AssetManager/index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\n\nimport { styled } from '@mui/material/styles';\n\nimport Box from '@fd/components/atoms/Box';\nimport Tab from '@fd/components/atoms/Tab';\nimport Modal, { type ModalAction } from '@fd/components/molecules/Modal';\nimport Tabs from '@fd/components/molecules/Tabs';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport type { FileUploadState } from '../FileUpload';\nimport LibraryTabContent from './LibraryTabContent';\nimport type { Asset } from './types';\nimport UploadAssetContent from './UploadTabContent';\n\nconst StyledTabsContainer = styled(Box)(({ theme }) => ({\n marginBottom: theme.spacing(3),\n}));\n\n/**\n * Props for the AssetManager component.\n * Provides a modal interface for selecting images from a grid display.\n * It supports both single and multiple image selection modes with configurable limits.\n *\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n *\n * ```tsx\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n */\nexport interface AssetManagerProps {\n /** Whether the asset manager modal is open */\n open: boolean;\n /** Callback function when the modal is closed or cancelled */\n onClose: () => void;\n /** Callback function when assets are selected */\n onSelect?: (selectedAssets: Asset[]) => void;\n /**\n * Organization ID for fetching assets\n */\n orgId: string;\n /** Brand ID for fetching assets */\n brandId?: string;\n /** Maximum number of assets that can be selected. Defaults to 1 */\n maxSelect?: number;\n}\n\n// Create a QueryClient instance for the AssetManager component\n// This allows the component to be used without requiring clients to wrap it in QueryClientProvider\nconst queryClient = new QueryClient();\n\n/**\n * AssetManager component used to select assets from the library or upload new assets.\n * Can manage assets at a organization or brand level.\n *\n * @example\n * ```tsx\n * <AssetManager\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * onSelect={(assets) => console.log(assets)}\n * orgId=\"org123\"\n * brandId=\"brand456\"\n * maxSelect={3}\n * />\n * ```\n */\nconst AssetManager: React.FC<AssetManagerProps> = ({\n open,\n onClose,\n onSelect,\n orgId,\n brandId,\n maxSelect = 1,\n}) => {\n // Use Map for O(1) lookup performance and direct access to Asset objects\n const [selectedAssetsMap, setSelectedAssetsMap] = useState<Map<string, Asset>>(new Map());\n const [selectedTab, setSelectedTab] = useState<string>('library');\n const [uploadedFiles, setUploadedFiles] = useState<FileUploadState[]>([]);\n\n // Reset selection when modal opens/closes\n useEffect(() => {\n if (!open) {\n setSelectedAssetsMap(new Map());\n setUploadedFiles([]);\n }\n }, [open]);\n\n const handleCancel = useCallback((): void => {\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onClose]);\n\n const handleSelect = useCallback((): void => {\n const selectedAssets = Array.from(selectedAssetsMap.values());\n if (onSelect && selectedAssets.length > 0) {\n onSelect(selectedAssets);\n }\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onSelect, selectedAssetsMap, onClose]);\n\n // TODO: translate titles\n const getTitle = (): string => {\n switch (selectedTab) {\n case 'library':\n return 'Select Images';\n default:\n return 'Upload Images';\n }\n };\n\n const handleAssetClick = useCallback(\n (asset: Asset): void => {\n setSelectedAssetsMap((prevMap) => {\n const isSelected = prevMap.has(asset.id);\n const newMap = new Map(prevMap);\n\n if (isSelected) {\n // Always allow deselecting an already selected asset\n newMap.delete(asset.id);\n } else if (maxSelect === 1) {\n // Single select mode: replace selection\n newMap.clear();\n newMap.set(asset.id, asset);\n } else if (newMap.size < maxSelect) {\n // Multi-select mode: add if under limit\n newMap.set(asset.id, asset);\n }\n // If at max limit and trying to select a new asset, do nothing\n return newMap;\n });\n },\n [maxSelect],\n );\n\n const handleSaveAssets = useCallback((): void => {\n // TODO: call Upload asset api\n setUploadedFiles([]);\n setSelectedTab('library');\n }, []);\n\n const handleUpload = useCallback((files: File[]): void => {\n // Add files with uploading state\n const newFiles: FileUploadState[] = files.map((file) => ({\n file,\n }));\n setUploadedFiles((prev) => [...prev, ...newFiles]);\n }, []);\n\n const handleRemove = useCallback((fileToRemove: File): void => {\n setUploadedFiles((prev) => prev.filter((fileState) => fileState.file !== fileToRemove));\n }, []);\n\n // Tab-specific action button configurations\n // TODO: translate button labels\n const actionButtons = useMemo<ModalAction[]>(() => {\n // Common cancel button configuration\n const cancelButton: ModalAction = {\n label: 'Cancel',\n onClick: handleCancel,\n variant: 'secondary',\n tone: 'neutral',\n id: 'asset-manager-cancel',\n };\n\n const tabActions: Record<string, ModalAction[]> = {\n library: [\n cancelButton,\n {\n label: 'Select',\n onClick: handleSelect,\n variant: 'primary',\n disabled: selectedAssetsMap.size === 0,\n id: 'asset-manager-select',\n },\n ],\n upload: [\n cancelButton,\n {\n label: 'Save',\n onClick: handleSaveAssets,\n disabled: uploadedFiles.length === 0,\n variant: 'primary',\n id: 'asset-manager-upload',\n },\n ],\n };\n\n return tabActions[selectedTab] ?? (tabActions['library'] as ModalAction[]);\n }, [\n selectedTab,\n selectedAssetsMap.size,\n uploadedFiles.length,\n handleCancel,\n handleSelect,\n handleSaveAssets,\n ]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <Modal actions={actionButtons} onClose={handleCancel} open={open} size=\"large\" title={getTitle()}>\n <StyledTabsContainer>\n <Tabs\n fdKey=\"asset-manager-tabs\"\n onChange={(_, value: string) => setSelectedTab(value)}\n value={selectedTab}\n >\n <Tab label=\"Upload\" value=\"upload\" />\n <Tab label=\"Library\" value=\"library\" />\n </Tabs>\n </StyledTabsContainer>\n {selectedTab === 'library' ? (\n <LibraryTabContent\n brandId={brandId}\n enabled={open}\n onAssetClick={handleAssetClick}\n orgId={orgId}\n selectedAssets={selectedAssetsMap}\n />\n ) : (\n <UploadAssetContent files={uploadedFiles} onRemove={handleRemove} onUpload={handleUpload} />\n )}\n </Modal>\n </QueryClientProvider>\n );\n};\n\nexport default AssetManager;\n"],"names":["StyledTabsContainer","styled","Box","theme","marginBottom","spacing","queryClient","QueryClient","open","onClose","onSelect","orgId","brandId","maxSelect","selectedAssetsMap","setSelectedAssetsMap","useState","Map","selectedTab","setSelectedTab","uploadedFiles","setUploadedFiles","useEffect","handleCancel","useCallback","handleSelect","selectedAssets","Array","from","values","length","handleAssetClick","asset","prevMap","isSelected","has","id","newMap","delete","clear","set","size","handleSaveAssets","handleUpload","files","newFiles","map","file","prev","handleRemove","fileToRemove","filter","fileState","actionButtons","useMemo","cancelButton","label","onClick","variant","tone","tabActions","library","disabled","upload","_jsx","QueryClientProvider","client","children","_jsxs","Modal","actions","title","Tabs","fdKey","onChange","_","value","Tab","LibraryTabContent","enabled","onAssetClick","UploadAssetContent","onRemove","onUpload"],"mappings":"gYAeA,MAAMA,EAAsBC,EAAAA,OAAOC,EAAPD,EAAY,EAAGE,YAAO,CAChDC,aAAcD,EAAME,QAAQ,OAgCxBC,EAAc,IAAIC,EAAAA,2BAkB0B,EAChDC,OACAC,UACAC,WACAC,QACAC,UACAC,YAAY,MAGZ,MAAOC,EAAmBC,GAAwBC,EAAAA,SAA6B,IAAIC,MAC5EC,EAAaC,GAAkBH,EAAAA,SAAiB,YAChDI,EAAeC,GAAoBL,EAAAA,SAA4B,IAGtEM,EAAAA,WAAU,KACHd,IACHO,EAAqB,IAAIE,KACzBI,EAAiB,OAElB,CAACb,IAEJ,MAAMe,EAAeC,EAAAA,aAAY,KAC/BT,EAAqB,IAAIE,KACzBR,MACC,CAACA,IAEEgB,EAAeD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mB,CAACC,OAAQ5D,EAAW6D,SACtCC,EAAAA,KAACC,EAAK,CAACC,QAASjB,EAAe5C,QAASc,EAAcf,KAAMA,EAAMiC,KAAK,QAAQ8B,MAhG1E,YADCrD,EAEG,gBAEA,0BA8FP8C,EAAAA,IAAChE,EAAmB,CAAAmE,SAClBC,EAAAA,KAACI,EAAI,CACHC,MAAM,qBACNC,SAAU,CAACC,EAAGC,IAAkBzD,EAAeyD,GAC/CA,MAAO1D,EAAWiD,SAAA,CAElBH,MAACa,EAAG,CAACrB,MAAM,SAASoB,MAAM,WAC1BZ,EAAAA,IAACa,EAAG,CAACrB,MAAM,UAAUoB,MAAM,iBAGd,YAAhB1D,EACC8C,MAACc,EAAiB,CAChBlE,QAASA,EACTmE,QAASvE,EACTwE,aAAcjD,EACdpB,MAAOA,EACPe,eAAgBZ,IAGlBkD,MAACiB,EAAkB,CAACrC,MAAOxB,EAAe8D,SAAUjC,EAAckC,SAAUxC"}
@@ -4,7 +4,7 @@ import { Asset } from './types/index.js';
4
4
  /**
5
5
  * Props for the AssetManager component.
6
6
  * Provides a modal interface for selecting images from a grid display.
7
- * It supports both single and multiple image selection modes.
7
+ * It supports both single and multiple image selection modes with configurable limits.
8
8
  *
9
9
  * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';
10
10
  *
@@ -24,8 +24,8 @@ interface AssetManagerProps {
24
24
  orgId: string;
25
25
  /** Brand ID for fetching assets */
26
26
  brandId?: string;
27
- /** Whether multiple assets can be selected. Defaults to false */
28
- multiSelect?: boolean;
27
+ /** Maximum number of assets that can be selected. Defaults to 1 */
28
+ maxSelect?: number;
29
29
  }
30
30
  /**
31
31
  * AssetManager component used to select assets from the library or upload new assets.
@@ -39,7 +39,7 @@ interface AssetManagerProps {
39
39
  * onSelect={(assets) => console.log(assets)}
40
40
  * orgId="org123"
41
41
  * brandId="brand456"
42
- * multiSelect={true}
42
+ * maxSelect={3}
43
43
  * />
44
44
  * ```
45
45
  */
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useState as r,useEffect as l,useCallback as t,useMemo as i}from"react";import{styled as n}from"@mui/material/styles";import o from"@mui/material/Box";import s from"@mui/material/Tab";import m from"../../molecules/Modal/index.js";import d from"../../molecules/Tabs/index.js";import{QueryClient as c,QueryClientProvider as p}from"@tanstack/react-query";import b from"./LibraryTabContent/index.js";import u from"./UploadTabContent/index.js";const f=n(o)((({theme:e})=>({marginBottom:e.spacing(3)}))),y=new c,g=({open:n,onClose:o,onSelect:c,orgId:g,brandId:h,multiSelect:C=!1})=>{const[v,x]=r(new Map),[w,I]=r("library"),[M,j]=r([]);l((()=>{n||(x(new Map),j([]))}),[n]);const k=t((()=>{x(new Map),o()}),[o]),S=t((()=>{const e=Array.from(v.values());c&&e.length>0&&c(e),x(new Map),o()}),[c,v,o]),T=t((e=>{x((a=>{const r=a.has(e.id),l=new Map(a);return C?r?l.delete(e.id):l.set(e.id,e):r?l.clear():(l.clear(),l.set(e.id,e)),l}))}),[C]),U=t((()=>{j([]),I("library")}),[]),z=t((e=>{const a=e.map((e=>({file:e})));j((e=>[...e,...a]))}),[]),A=t((e=>{j((a=>a.filter((a=>a.file!==e))))}),[]),B=i((()=>{const e={label:"Cancel",onClick:k,variant:"secondary",tone:"neutral",id:"asset-manager-cancel"},a={library:[e,{label:"Select",onClick:S,variant:"primary",disabled:0===v.size,id:"asset-manager-select"}],upload:[e,{label:"Save",onClick:U,disabled:0===M.length,variant:"primary",id:"asset-manager-upload"}]};return a[w]??a.library}),[w,v.size,M.length,k,S,U]);return e(p,{client:y,children:a(m,{actions:B,onClose:k,open:n,size:"large",title:"library"===w?"Select Images":"Upload Images",children:[e(f,{children:a(d,{fdKey:"asset-manager-tabs",onChange:(e,a)=>I(a),value:w,children:[e(s,{label:"Upload",value:"upload"}),e(s,{label:"Library",value:"library"})]})}),"library"===w?e(b,{brandId:h,enabled:n,onAssetClick:T,orgId:g,selectedAssets:v}):e(u,{files:M,onRemove:A,onUpload:z})]})})};export{g as default};
1
+ import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useState as r,useEffect as l,useCallback as t,useMemo as i}from"react";import{styled as n}from"@mui/material/styles";import o from"@mui/material/Box";import s from"@mui/material/Tab";import m from"../../molecules/Modal/index.js";import d from"../../molecules/Tabs/index.js";import{QueryClient as c,QueryClientProvider as p}from"@tanstack/react-query";import b from"./LibraryTabContent/index.js";import u from"./UploadTabContent/index.js";const f=n(o)((({theme:e})=>({marginBottom:e.spacing(3)}))),y=new c,g=({open:n,onClose:o,onSelect:c,orgId:g,brandId:h,maxSelect:C=1})=>{const[v,x]=r(new Map),[w,I]=r("library"),[M,j]=r([]);l((()=>{n||(x(new Map),j([]))}),[n]);const k=t((()=>{x(new Map),o()}),[o]),S=t((()=>{const e=Array.from(v.values());c&&e.length>0&&c(e),x(new Map),o()}),[c,v,o]),z=t((e=>{x((a=>{const r=a.has(e.id),l=new Map(a);return r?l.delete(e.id):1===C?(l.clear(),l.set(e.id,e)):l.size<C&&l.set(e.id,e),l}))}),[C]),T=t((()=>{j([]),I("library")}),[]),U=t((e=>{const a=e.map((e=>({file:e})));j((e=>[...e,...a]))}),[]),A=t((e=>{j((a=>a.filter((a=>a.file!==e))))}),[]),B=i((()=>{const e={label:"Cancel",onClick:k,variant:"secondary",tone:"neutral",id:"asset-manager-cancel"},a={library:[e,{label:"Select",onClick:S,variant:"primary",disabled:0===v.size,id:"asset-manager-select"}],upload:[e,{label:"Save",onClick:T,disabled:0===M.length,variant:"primary",id:"asset-manager-upload"}]};return a[w]??a.library}),[w,v.size,M.length,k,S,T]);return e(p,{client:y,children:a(m,{actions:B,onClose:k,open:n,size:"large",title:"library"===w?"Select Images":"Upload Images",children:[e(f,{children:a(d,{fdKey:"asset-manager-tabs",onChange:(e,a)=>I(a),value:w,children:[e(s,{label:"Upload",value:"upload"}),e(s,{label:"Library",value:"library"})]})}),"library"===w?e(b,{brandId:h,enabled:n,onAssetClick:z,orgId:g,selectedAssets:v}):e(u,{files:M,onRemove:A,onUpload:U})]})})};export{g as default};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/components/organisms/AssetManager/index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\n\nimport { styled } from '@mui/material/styles';\n\nimport Box from '@fd/components/atoms/Box';\nimport Tab from '@fd/components/atoms/Tab';\nimport Modal, { type ModalAction } from '@fd/components/molecules/Modal';\nimport Tabs from '@fd/components/molecules/Tabs';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport type { FileUploadState } from '../FileUpload';\nimport LibraryTabContent from './LibraryTabContent';\nimport type { Asset } from './types';\nimport UploadAssetContent from './UploadTabContent';\n\nconst StyledTabsContainer = styled(Box)(({ theme }) => ({\n marginBottom: theme.spacing(3),\n}));\n\n/**\n * Props for the AssetManager component.\n * Provides a modal interface for selecting images from a grid display.\n * It supports both single and multiple image selection modes.\n *\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n *\n * ```tsx\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n */\nexport interface AssetManagerProps {\n /** Whether the asset manager modal is open */\n open: boolean;\n /** Callback function when the modal is closed or cancelled */\n onClose: () => void;\n /** Callback function when assets are selected */\n onSelect?: (selectedAssets: Asset[]) => void;\n /**\n * Organization ID for fetching assets\n */\n orgId: string;\n /** Brand ID for fetching assets */\n brandId?: string;\n /** Whether multiple assets can be selected. Defaults to false */\n multiSelect?: boolean;\n}\n\n// Create a QueryClient instance for the AssetManager component\n// This allows the component to be used without requiring clients to wrap it in QueryClientProvider\nconst queryClient = new QueryClient();\n\n/**\n * AssetManager component used to select assets from the library or upload new assets.\n * Can manage assets at a organization or brand level.\n *\n * @example\n * ```tsx\n * <AssetManager\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * onSelect={(assets) => console.log(assets)}\n * orgId=\"org123\"\n * brandId=\"brand456\"\n * multiSelect={true}\n * />\n * ```\n */\nconst AssetManager: React.FC<AssetManagerProps> = ({\n open,\n onClose,\n onSelect,\n orgId,\n brandId,\n multiSelect = false,\n}) => {\n // Use Map for O(1) lookup performance and direct access to Asset objects\n const [selectedAssetsMap, setSelectedAssetsMap] = useState<Map<string, Asset>>(new Map());\n const [selectedTab, setSelectedTab] = useState<string>('library');\n const [uploadedFiles, setUploadedFiles] = useState<FileUploadState[]>([]);\n\n // Reset selection when modal opens/closes\n useEffect(() => {\n if (!open) {\n setSelectedAssetsMap(new Map());\n setUploadedFiles([]);\n }\n }, [open]);\n\n const handleCancel = useCallback((): void => {\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onClose]);\n\n const handleSelect = useCallback((): void => {\n const selectedAssets = Array.from(selectedAssetsMap.values());\n if (onSelect && selectedAssets.length > 0) {\n onSelect(selectedAssets);\n }\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onSelect, selectedAssetsMap, onClose]);\n\n // TODO: translate titles\n const getTitle = (): string => {\n switch (selectedTab) {\n case 'library':\n return 'Select Images';\n default:\n return 'Upload Images';\n }\n };\n\n const handleAssetClick = useCallback(\n (asset: Asset): void => {\n setSelectedAssetsMap((prevMap) => {\n const isSelected = prevMap.has(asset.id);\n const newMap = new Map(prevMap);\n\n if (multiSelect) {\n if (isSelected) {\n newMap.delete(asset.id);\n } else {\n newMap.set(asset.id, asset);\n }\n } else {\n // Single select: replace selection or clear if clicking same asset\n if (isSelected) {\n newMap.clear();\n } else {\n newMap.clear();\n newMap.set(asset.id, asset);\n }\n }\n\n return newMap;\n });\n },\n [multiSelect],\n );\n\n const handleSaveAssets = useCallback((): void => {\n // TODO: call Upload asset api\n setUploadedFiles([]);\n setSelectedTab('library');\n }, []);\n\n const handleUpload = useCallback((files: File[]): void => {\n // Add files with uploading state\n const newFiles: FileUploadState[] = files.map((file) => ({\n file,\n }));\n setUploadedFiles((prev) => [...prev, ...newFiles]);\n }, []);\n\n const handleRemove = useCallback((fileToRemove: File): void => {\n setUploadedFiles((prev) => prev.filter((fileState) => fileState.file !== fileToRemove));\n }, []);\n\n // Tab-specific action button configurations\n // TODO: translate button labels\n const actionButtons = useMemo<ModalAction[]>(() => {\n // Common cancel button configuration\n const cancelButton: ModalAction = {\n label: 'Cancel',\n onClick: handleCancel,\n variant: 'secondary',\n tone: 'neutral',\n id: 'asset-manager-cancel',\n };\n\n const tabActions: Record<string, ModalAction[]> = {\n library: [\n cancelButton,\n {\n label: 'Select',\n onClick: handleSelect,\n variant: 'primary',\n disabled: selectedAssetsMap.size === 0,\n id: 'asset-manager-select',\n },\n ],\n upload: [\n cancelButton,\n {\n label: 'Save',\n onClick: handleSaveAssets,\n disabled: uploadedFiles.length === 0,\n variant: 'primary',\n id: 'asset-manager-upload',\n },\n ],\n };\n\n return tabActions[selectedTab] ?? (tabActions['library'] as ModalAction[]);\n }, [\n selectedTab,\n selectedAssetsMap.size,\n uploadedFiles.length,\n handleCancel,\n handleSelect,\n handleSaveAssets,\n ]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <Modal actions={actionButtons} onClose={handleCancel} open={open} size=\"large\" title={getTitle()}>\n <StyledTabsContainer>\n <Tabs\n fdKey=\"asset-manager-tabs\"\n onChange={(_, value: string) => setSelectedTab(value)}\n value={selectedTab}\n >\n <Tab label=\"Upload\" value=\"upload\" />\n <Tab label=\"Library\" value=\"library\" />\n </Tabs>\n </StyledTabsContainer>\n {selectedTab === 'library' ? (\n <LibraryTabContent\n brandId={brandId}\n enabled={open}\n onAssetClick={handleAssetClick}\n orgId={orgId}\n selectedAssets={selectedAssetsMap}\n />\n ) : (\n <UploadAssetContent files={uploadedFiles} onRemove={handleRemove} onUpload={handleUpload} />\n )}\n </Modal>\n </QueryClientProvider>\n );\n};\n\nexport default AssetManager;\n"],"names":["StyledTabsContainer","styled","Box","theme","marginBottom","spacing","queryClient","QueryClient","AssetManager","open","onClose","onSelect","orgId","brandId","multiSelect","selectedAssetsMap","setSelectedAssetsMap","useState","Map","selectedTab","setSelectedTab","uploadedFiles","setUploadedFiles","useEffect","handleCancel","useCallback","handleSelect","selectedAssets","Array","from","values","length","handleAssetClick","asset","prevMap","isSelected","has","id","newMap","delete","set","clear","handleSaveAssets","handleUpload","files","newFiles","map","file","prev","handleRemove","fileToRemove","filter","fileState","actionButtons","useMemo","cancelButton","label","onClick","variant","tone","tabActions","library","disabled","size","upload","_jsx","QueryClientProvider","client","children","_jsxs","Modal","actions","title","Tabs","fdKey","onChange","_","value","Tab","LibraryTabContent","enabled","onAssetClick","UploadAssetContent","onRemove","onUpload"],"mappings":"+eAeA,MAAMA,EAAsBC,EAAOC,EAAPD,EAAY,EAAGE,YAAO,CAChDC,aAAcD,EAAME,QAAQ,OAgCxBC,EAAc,IAAIC,EAkBlBC,EAA4C,EAChDC,OACAC,UACAC,WACAC,QACAC,UACAC,eAAc,MAGd,MAAOC,EAAmBC,GAAwBC,EAA6B,IAAIC,MAC5EC,EAAaC,GAAkBH,EAAiB,YAChDI,EAAeC,GAAoBL,EAA4B,IAGtEM,GAAU,KACHd,IACHO,EAAqB,IAAIE,KACzBI,EAAiB,OAElB,CAACb,IAEJ,MAAMe,EAAeC,GAAY,KAC/BT,EAAqB,IAAIE,KACzBR,MACC,CAACA,IAEEgB,EAAeD,GAAY,KAC/B,MAAME,EAAiBC,MAAMC,KAAKd,EAAkBe,UAChDnB,GAAYgB,EAAeI,OAAS,GACtCpB,EAASgB,GAEXX,EAAqB,IAAIE,KACzBR,MACC,CAACC,EAAUI,EAAmBL,IAY3BsB,EAAmBP,GACtBQ,IACCjB,GAAsBkB,IACpB,MAAMC,EAAaD,EAAQE,IAAIH,EAAMI,IAC/BC,EAAS,IAAIpB,IAAIgB,GAkBvB,OAhBIpB,EACEqB,EACFG,EAAOC,OAAON,EAAMI,IAEpBC,EAAOE,IAAIP,EAAMI,GAAIJ,GAInBE,EACFG,EAAOG,SAEPH,EAAOG,QACPH,EAAOE,IAAIP,EAAMI,GAAIJ,IAIlBK,OAGX,CAACxB,IAGG4B,EAA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,CAACtC,MAAOvB,EAAe8D,SAAUlC,EAAcmC,SAAUzC"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/organisms/AssetManager/index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react';\n\nimport { styled } from '@mui/material/styles';\n\nimport Box from '@fd/components/atoms/Box';\nimport Tab from '@fd/components/atoms/Tab';\nimport Modal, { type ModalAction } from '@fd/components/molecules/Modal';\nimport Tabs from '@fd/components/molecules/Tabs';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport type { FileUploadState } from '../FileUpload';\nimport LibraryTabContent from './LibraryTabContent';\nimport type { Asset } from './types';\nimport UploadAssetContent from './UploadTabContent';\n\nconst StyledTabsContainer = styled(Box)(({ theme }) => ({\n marginBottom: theme.spacing(3),\n}));\n\n/**\n * Props for the AssetManager component.\n * Provides a modal interface for selecting images from a grid display.\n * It supports both single and multiple image selection modes with configurable limits.\n *\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n *\n * ```tsx\n * import AssetManager from '@flipdish/portal-library/components/organisms/AssetManager';\n */\nexport interface AssetManagerProps {\n /** Whether the asset manager modal is open */\n open: boolean;\n /** Callback function when the modal is closed or cancelled */\n onClose: () => void;\n /** Callback function when assets are selected */\n onSelect?: (selectedAssets: Asset[]) => void;\n /**\n * Organization ID for fetching assets\n */\n orgId: string;\n /** Brand ID for fetching assets */\n brandId?: string;\n /** Maximum number of assets that can be selected. Defaults to 1 */\n maxSelect?: number;\n}\n\n// Create a QueryClient instance for the AssetManager component\n// This allows the component to be used without requiring clients to wrap it in QueryClientProvider\nconst queryClient = new QueryClient();\n\n/**\n * AssetManager component used to select assets from the library or upload new assets.\n * Can manage assets at a organization or brand level.\n *\n * @example\n * ```tsx\n * <AssetManager\n * open={isOpen}\n * onClose={() => setIsOpen(false)}\n * onSelect={(assets) => console.log(assets)}\n * orgId=\"org123\"\n * brandId=\"brand456\"\n * maxSelect={3}\n * />\n * ```\n */\nconst AssetManager: React.FC<AssetManagerProps> = ({\n open,\n onClose,\n onSelect,\n orgId,\n brandId,\n maxSelect = 1,\n}) => {\n // Use Map for O(1) lookup performance and direct access to Asset objects\n const [selectedAssetsMap, setSelectedAssetsMap] = useState<Map<string, Asset>>(new Map());\n const [selectedTab, setSelectedTab] = useState<string>('library');\n const [uploadedFiles, setUploadedFiles] = useState<FileUploadState[]>([]);\n\n // Reset selection when modal opens/closes\n useEffect(() => {\n if (!open) {\n setSelectedAssetsMap(new Map());\n setUploadedFiles([]);\n }\n }, [open]);\n\n const handleCancel = useCallback((): void => {\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onClose]);\n\n const handleSelect = useCallback((): void => {\n const selectedAssets = Array.from(selectedAssetsMap.values());\n if (onSelect && selectedAssets.length > 0) {\n onSelect(selectedAssets);\n }\n setSelectedAssetsMap(new Map());\n onClose();\n }, [onSelect, selectedAssetsMap, onClose]);\n\n // TODO: translate titles\n const getTitle = (): string => {\n switch (selectedTab) {\n case 'library':\n return 'Select Images';\n default:\n return 'Upload Images';\n }\n };\n\n const handleAssetClick = useCallback(\n (asset: Asset): void => {\n setSelectedAssetsMap((prevMap) => {\n const isSelected = prevMap.has(asset.id);\n const newMap = new Map(prevMap);\n\n if (isSelected) {\n // Always allow deselecting an already selected asset\n newMap.delete(asset.id);\n } else if (maxSelect === 1) {\n // Single select mode: replace selection\n newMap.clear();\n newMap.set(asset.id, asset);\n } else if (newMap.size < maxSelect) {\n // Multi-select mode: add if under limit\n newMap.set(asset.id, asset);\n }\n // If at max limit and trying to select a new asset, do nothing\n return newMap;\n });\n },\n [maxSelect],\n );\n\n const handleSaveAssets = useCallback((): void => {\n // TODO: call Upload asset api\n setUploadedFiles([]);\n setSelectedTab('library');\n }, []);\n\n const handleUpload = useCallback((files: File[]): void => {\n // Add files with uploading state\n const newFiles: FileUploadState[] = files.map((file) => ({\n file,\n }));\n setUploadedFiles((prev) => [...prev, ...newFiles]);\n }, []);\n\n const handleRemove = useCallback((fileToRemove: File): void => {\n setUploadedFiles((prev) => prev.filter((fileState) => fileState.file !== fileToRemove));\n }, []);\n\n // Tab-specific action button configurations\n // TODO: translate button labels\n const actionButtons = useMemo<ModalAction[]>(() => {\n // Common cancel button configuration\n const cancelButton: ModalAction = {\n label: 'Cancel',\n onClick: handleCancel,\n variant: 'secondary',\n tone: 'neutral',\n id: 'asset-manager-cancel',\n };\n\n const tabActions: Record<string, ModalAction[]> = {\n library: [\n cancelButton,\n {\n label: 'Select',\n onClick: handleSelect,\n variant: 'primary',\n disabled: selectedAssetsMap.size === 0,\n id: 'asset-manager-select',\n },\n ],\n upload: [\n cancelButton,\n {\n label: 'Save',\n onClick: handleSaveAssets,\n disabled: uploadedFiles.length === 0,\n variant: 'primary',\n id: 'asset-manager-upload',\n },\n ],\n };\n\n return tabActions[selectedTab] ?? (tabActions['library'] as ModalAction[]);\n }, [\n selectedTab,\n selectedAssetsMap.size,\n uploadedFiles.length,\n handleCancel,\n handleSelect,\n handleSaveAssets,\n ]);\n\n return (\n <QueryClientProvider client={queryClient}>\n <Modal actions={actionButtons} onClose={handleCancel} open={open} size=\"large\" title={getTitle()}>\n <StyledTabsContainer>\n <Tabs\n fdKey=\"asset-manager-tabs\"\n onChange={(_, value: string) => setSelectedTab(value)}\n value={selectedTab}\n >\n <Tab label=\"Upload\" value=\"upload\" />\n <Tab label=\"Library\" value=\"library\" />\n </Tabs>\n </StyledTabsContainer>\n {selectedTab === 'library' ? (\n <LibraryTabContent\n brandId={brandId}\n enabled={open}\n onAssetClick={handleAssetClick}\n orgId={orgId}\n selectedAssets={selectedAssetsMap}\n />\n ) : (\n <UploadAssetContent files={uploadedFiles} onRemove={handleRemove} onUpload={handleUpload} />\n )}\n </Modal>\n </QueryClientProvider>\n );\n};\n\nexport default AssetManager;\n"],"names":["StyledTabsContainer","styled","Box","theme","marginBottom","spacing","queryClient","QueryClient","AssetManager","open","onClose","onSelect","orgId","brandId","maxSelect","selectedAssetsMap","setSelectedAssetsMap","useState","Map","selectedTab","setSelectedTab","uploadedFiles","setUploadedFiles","useEffect","handleCancel","useCallback","handleSelect","selectedAssets","Array","from","values","length","handleAssetClick","asset","prevMap","isSelected","has","id","newMap","delete","clear","set","size","handleSaveAssets","handleUpload","files","newFiles","map","file","prev","handleRemove","fileToRemove","filter","fileState","actionButtons","useMemo","cancelButton","label","onClick","variant","tone","tabActions","library","disabled","upload","_jsx","QueryClientProvider","client","children","_jsxs","Modal","actions","title","Tabs","fdKey","onChange","_","value","Tab","LibraryTabContent","enabled","onAssetClick","UploadAssetContent","onRemove","onUpload"],"mappings":"+eAeA,MAAMA,EAAsBC,EAAOC,EAAPD,EAAY,EAAGE,YAAO,CAChDC,aAAcD,EAAME,QAAQ,OAgCxBC,EAAc,IAAIC,EAkBlBC,EAA4C,EAChDC,OACAC,UACAC,WACAC,QACAC,UACAC,YAAY,MAGZ,MAAOC,EAAmBC,GAAwBC,EAA6B,IAAIC,MAC5EC,EAAaC,GAAkBH,EAAiB,YAChDI,EAAeC,GAAoBL,EAA4B,IAGtEM,GAAU,KACHd,IACHO,EAAqB,IAAIE,KACzBI,EAAiB,OAElB,CAACb,IAEJ,MAAMe,EAAeC,GAAY,KAC/BT,EAAqB,IAAIE,KACzBR,MACC,CAACA,IAEEgB,EAAeD,GAAY,KAC/B,MAAME,EAAiBC,MAAMC,KAAKd,EAAkBe,UAChDnB,GAAYgB,EAAeI,OAAS,GACtCpB,EAASgB,GAEXX,EAAqB,IAAIE,KACzBR,MACC,CAACC,EAAUI,EAAmBL,IAY3BsB,EAAmBP,GACtBQ,IACCjB,GAAsBkB,IACpB,MAAMC,EAAaD,EAAQE,IAAIH,EAAMI,IAC/BC,EAAS,IAAIpB,IAAIgB,GAcvB,OAZIC,EAEFG,EAAOC,OAAON,EAAMI,IACG,IAAdvB,GAETwB,EAAOE,QACPF,EAAOG,IAAIR,EAAMI,GAAIJ,IACZK,EAAOI,KAAO5B,GAEvBwB,EAAOG,IAAIR,EAAMI,GAAIJ,GAGhB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eAAgBZ,IAGlBkD,EAACiB,EAAkB,CAACrC,MAAOxB,EAAe8D,SAAUjC,EAAckC,SAAUxC"}
@@ -1,2 +1,2 @@
1
- "use strict";const t=(t,s)=>{if(!t)return;const e=s?`?brandId=${s}`:"";return`${(()=>{const t=window.location?.host?.includes("portal.flipdish.com"),s=window.location?.host?.includes("portal.flipdishdev.com");return t?"https://asset-management-service.portal.flipdish.com":s?"https://asset-management-service.portal.flipdishdev.com":"https://ci.asset-management-service.clients-ephemeral.flipdishdev.com"})()}/${t}/assets${e}`};exports.getAssets=async(s,e)=>{const i=t(s,e);if(!i)throw new Error("Organization ID is required to fetch assets");const o=await fetch(i,{method:"GET",credentials:"include"});if(!o.ok)throw new Error(`Failed to fetch assets: ${o.statusText}`);return await o.json()},exports.getAssetsKey="getAssets";
1
+ "use strict";const t=(t,s)=>{if(!t)return;const e=s?`?brandId=${s}`:"";return`${(()=>{const t=window.location?.host?.includes("portal.flipdish.com");return t?"https://asset-management-service.portal.flipdish.com":"https://asset-management-service.portal.flipdishdev.com"})()}/${t}/assets${e}`};exports.getAssets=async(s,e)=>{const r=t(s,e);if(!r)throw new Error("Organization ID is required to fetch assets");const o=await fetch(r,{method:"GET",credentials:"include"});if(!o.ok)throw new Error(`Failed to fetch assets: ${o.statusText}`);return await o.json()},exports.getAssetsKey="getAssets";
2
2
  //# sourceMappingURL=asset.service.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset.service.cjs.js","sources":["../../../../../src/components/organisms/AssetManager/services/asset.service.ts"],"sourcesContent":["import type { Asset } from '../types';\n\nexport const getAssetsKey = 'getAssets';\n\nconst PROD_API_URL = 'https://asset-management-service.portal.flipdish.com';\nconst STAGING_API_URL = 'https://asset-management-service.portal.flipdishdev.com';\nconst CI_API_URL = 'https://ci.asset-management-service.clients-ephemeral.flipdishdev.com';\n\n/**\n * Gets the asset management API base URL based on the current environment\n * @returns The appropriate API URL for the current environment\n */\nconst getAssetManagementApiUrl = (): string => {\n const isProd = window.location?.host?.includes('portal.flipdish.com');\n const isStaging = window.location?.host?.includes('portal.flipdishdev.com');\n\n if (isProd) {\n return PROD_API_URL;\n }\n\n if (isStaging) {\n return STAGING_API_URL;\n }\n\n // Default to CI/dev environment\n return CI_API_URL;\n};\n\n/**\n * Builds the complete API URL for fetching assets\n * @param orgId - Optional organization ID.\n * @param brandId - Optional brand ID.\n * @returns The complete API URL or undefined if no orgId available\n */\nconst buildApiUrl = (orgId: string, brandId?: string): string | undefined => {\n if (!orgId) return undefined;\n const brandIdQueryParam = brandId ? `?brandId=${brandId}` : '';\n const baseUrl = getAssetManagementApiUrl();\n return `${baseUrl}/${orgId}/assets${brandIdQueryParam}`;\n};\n\n/**\n * Fetches assets from the asset management service API\n * @param orgId - organization ID.\n * @param brandId - brand ID.\n * @returns Promise resolving to an array of assets\n */\nexport const getAssets = async (orgId: string, brandId?: string): Promise<Asset[]> => {\n const apiUrl = buildApiUrl(orgId, brandId);\n\n if (!apiUrl) {\n throw new Error('Organization ID is required to fetch assets');\n }\n\n const response = await fetch(apiUrl, {\n method: 'GET',\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch assets: ${response.statusText}`);\n }\n\n return (await response.json()) as Asset[];\n};\n"],"names":["buildApiUrl","orgId","brandId","brandIdQueryParam","isProd","window","location","host","includes","isStaging","getAssetManagementApiUrl","async","apiUrl","Error","response","fetch","method","credentials","ok","statusText","json"],"mappings":"aAEO,MAgCDA,EAAc,CAACC,EAAeC,KAClC,IAAKD,EAAO,OACZ,MAAME,EAAoBD,EAAU,YAAYA,IAAY,GAE5D,MAAO,GA1BwB,MAC/B,MAAME,EAASC,OAAOC,UAAUC,MAAMC,SAAS,uBACzCC,EAAYJ,OAAOC,UAAUC,MAAMC,SAAS,0BAElD,OAAIJ,EAZe,uDAgBfK,EAfkB,0DACL,yEA+BDC,MACKT,WAAeE,uBASbQ,MAAOV,EAAeC,KAC7C,MAAMU,EAASZ,EAAYC,EAAOC,GAElC,IAAKU,EACH,MAAM,IAAIC,MAAM,+CAGlB,MAAMC,QAAiBC,MAAMH,EAAQ,CACnCI,OAAQ,MACRC,YAAa,YAGf,IAAKH,EAASI,GACZ,MAAM,IAAIL,MAAM,2BAA2BC,EAASK,cAGtD,aAAcL,EAASM,6BA7DG"}
1
+ {"version":3,"file":"asset.service.cjs.js","sources":["../../../../../src/components/organisms/AssetManager/services/asset.service.ts"],"sourcesContent":["import type { Asset } from '../types';\n\nexport const getAssetsKey = 'getAssets';\n\nconst PROD_API_URL = 'https://asset-management-service.portal.flipdish.com';\nconst DEV_STAGING_API_URL = 'https://asset-management-service.portal.flipdishdev.com';\n\n/**\n * Gets the asset management API base URL based on the current environment\n * @returns The appropriate API URL for the current environment\n */\nconst getAssetManagementApiUrl = (): string => {\n const isProd = window.location?.host?.includes('portal.flipdish.com');\n\n if (isProd) {\n return PROD_API_URL;\n }\n\n return DEV_STAGING_API_URL;\n};\n\n/**\n * Builds the complete API URL for fetching assets\n * @param orgId - Optional organization ID.\n * @param brandId - Optional brand ID.\n * @returns The complete API URL or undefined if no orgId available\n */\nconst buildApiUrl = (orgId: string, brandId?: string): string | undefined => {\n if (!orgId) return undefined;\n const brandIdQueryParam = brandId ? `?brandId=${brandId}` : '';\n const baseUrl = getAssetManagementApiUrl();\n return `${baseUrl}/${orgId}/assets${brandIdQueryParam}`;\n};\n\n/**\n * Fetches assets from the asset management service API\n * @param orgId - organization ID.\n * @param brandId - brand ID.\n * @returns Promise resolving to an array of assets\n */\nexport const getAssets = async (orgId: string, brandId?: string): Promise<Asset[]> => {\n const apiUrl = buildApiUrl(orgId, brandId);\n\n if (!apiUrl) {\n throw new Error('Organization ID is required to fetch assets');\n }\n\n const response = await fetch(apiUrl, {\n method: 'GET',\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch assets: ${response.statusText}`);\n }\n\n return (await response.json()) as Asset[];\n};\n"],"names":["buildApiUrl","orgId","brandId","brandIdQueryParam","isProd","window","location","host","includes","getAssetManagementApiUrl","async","apiUrl","Error","response","fetch","method","credentials","ok","statusText","json"],"mappings":"aAEO,MAyBDA,EAAc,CAACC,EAAeC,KAClC,IAAKD,EAAO,OACZ,MAAME,EAAoBD,EAAU,YAAYA,IAAY,GAE5D,MAAO,GApBwB,MAC/B,MAAME,EAASC,OAAOC,UAAUC,MAAMC,SAAS,uBAE/C,OAAIJ,EAVe,uDACO,2DAyBVK,MACKR,WAAeE,uBASbO,MAAOT,EAAeC,KAC7C,MAAMS,EAASX,EAAYC,EAAOC,GAElC,IAAKS,EACH,MAAM,IAAIC,MAAM,+CAGlB,MAAMC,QAAiBC,MAAMH,EAAQ,CACnCI,OAAQ,MACRC,YAAa,YAGf,IAAKH,EAASI,GACZ,MAAM,IAAIL,MAAM,2BAA2BC,EAASK,cAGtD,aAAcL,EAASM,6BAtDG"}
@@ -1,2 +1,2 @@
1
- const t="getAssets",e=(t,e)=>{if(!t)return;const s=e?`?brandId=${e}`:"";return`${(()=>{const t=window.location?.host?.includes("portal.flipdish.com"),e=window.location?.host?.includes("portal.flipdishdev.com");return t?"https://asset-management-service.portal.flipdish.com":e?"https://asset-management-service.portal.flipdishdev.com":"https://ci.asset-management-service.clients-ephemeral.flipdishdev.com"})()}/${t}/assets${s}`},s=async(t,s)=>{const i=e(t,s);if(!i)throw new Error("Organization ID is required to fetch assets");const o=await fetch(i,{method:"GET",credentials:"include"});if(!o.ok)throw new Error(`Failed to fetch assets: ${o.statusText}`);return await o.json()};export{s as getAssets,t as getAssetsKey};
1
+ const t="getAssets",s=(t,s)=>{if(!t)return;const e=s?`?brandId=${s}`:"";return`${(()=>{const t=window.location?.host?.includes("portal.flipdish.com");return t?"https://asset-management-service.portal.flipdish.com":"https://asset-management-service.portal.flipdishdev.com"})()}/${t}/assets${e}`},e=async(t,e)=>{const r=s(t,e);if(!r)throw new Error("Organization ID is required to fetch assets");const o=await fetch(r,{method:"GET",credentials:"include"});if(!o.ok)throw new Error(`Failed to fetch assets: ${o.statusText}`);return await o.json()};export{e as getAssets,t as getAssetsKey};
2
2
  //# sourceMappingURL=asset.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset.service.js","sources":["../../../../../src/components/organisms/AssetManager/services/asset.service.ts"],"sourcesContent":["import type { Asset } from '../types';\n\nexport const getAssetsKey = 'getAssets';\n\nconst PROD_API_URL = 'https://asset-management-service.portal.flipdish.com';\nconst STAGING_API_URL = 'https://asset-management-service.portal.flipdishdev.com';\nconst CI_API_URL = 'https://ci.asset-management-service.clients-ephemeral.flipdishdev.com';\n\n/**\n * Gets the asset management API base URL based on the current environment\n * @returns The appropriate API URL for the current environment\n */\nconst getAssetManagementApiUrl = (): string => {\n const isProd = window.location?.host?.includes('portal.flipdish.com');\n const isStaging = window.location?.host?.includes('portal.flipdishdev.com');\n\n if (isProd) {\n return PROD_API_URL;\n }\n\n if (isStaging) {\n return STAGING_API_URL;\n }\n\n // Default to CI/dev environment\n return CI_API_URL;\n};\n\n/**\n * Builds the complete API URL for fetching assets\n * @param orgId - Optional organization ID.\n * @param brandId - Optional brand ID.\n * @returns The complete API URL or undefined if no orgId available\n */\nconst buildApiUrl = (orgId: string, brandId?: string): string | undefined => {\n if (!orgId) return undefined;\n const brandIdQueryParam = brandId ? `?brandId=${brandId}` : '';\n const baseUrl = getAssetManagementApiUrl();\n return `${baseUrl}/${orgId}/assets${brandIdQueryParam}`;\n};\n\n/**\n * Fetches assets from the asset management service API\n * @param orgId - organization ID.\n * @param brandId - brand ID.\n * @returns Promise resolving to an array of assets\n */\nexport const getAssets = async (orgId: string, brandId?: string): Promise<Asset[]> => {\n const apiUrl = buildApiUrl(orgId, brandId);\n\n if (!apiUrl) {\n throw new Error('Organization ID is required to fetch assets');\n }\n\n const response = await fetch(apiUrl, {\n method: 'GET',\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch assets: ${response.statusText}`);\n }\n\n return (await response.json()) as Asset[];\n};\n"],"names":["getAssetsKey","buildApiUrl","orgId","brandId","brandIdQueryParam","isProd","window","location","host","includes","isStaging","getAssetManagementApiUrl","getAssets","async","apiUrl","Error","response","fetch","method","credentials","ok","statusText","json"],"mappings":"AAEO,MAAMA,EAAe,YAgCtBC,EAAc,CAACC,EAAeC,KAClC,IAAKD,EAAO,OACZ,MAAME,EAAoBD,EAAU,YAAYA,IAAY,GAE5D,MAAO,GA1BwB,MAC/B,MAAME,EAASC,OAAOC,UAAUC,MAAMC,SAAS,uBACzCC,EAAYJ,OAAOC,UAAUC,MAAMC,SAAS,0BAElD,OAAIJ,EAZe,uDAgBfK,EAfkB,0DACL,yEA+BDC,MACKT,WAAeE,KASzBQ,EAAYC,MAAOX,EAAeC,KAC7C,MAAMW,EAASb,EAAYC,EAAOC,GAElC,IAAKW,EACH,MAAM,IAAIC,MAAM,+CAGlB,MAAMC,QAAiBC,MAAMH,EAAQ,CACnCI,OAAQ,MACRC,YAAa,YAGf,IAAKH,EAASI,GACZ,MAAM,IAAIL,MAAM,2BAA2BC,EAASK,cAGtD,aAAcL,EAASM"}
1
+ {"version":3,"file":"asset.service.js","sources":["../../../../../src/components/organisms/AssetManager/services/asset.service.ts"],"sourcesContent":["import type { Asset } from '../types';\n\nexport const getAssetsKey = 'getAssets';\n\nconst PROD_API_URL = 'https://asset-management-service.portal.flipdish.com';\nconst DEV_STAGING_API_URL = 'https://asset-management-service.portal.flipdishdev.com';\n\n/**\n * Gets the asset management API base URL based on the current environment\n * @returns The appropriate API URL for the current environment\n */\nconst getAssetManagementApiUrl = (): string => {\n const isProd = window.location?.host?.includes('portal.flipdish.com');\n\n if (isProd) {\n return PROD_API_URL;\n }\n\n return DEV_STAGING_API_URL;\n};\n\n/**\n * Builds the complete API URL for fetching assets\n * @param orgId - Optional organization ID.\n * @param brandId - Optional brand ID.\n * @returns The complete API URL or undefined if no orgId available\n */\nconst buildApiUrl = (orgId: string, brandId?: string): string | undefined => {\n if (!orgId) return undefined;\n const brandIdQueryParam = brandId ? `?brandId=${brandId}` : '';\n const baseUrl = getAssetManagementApiUrl();\n return `${baseUrl}/${orgId}/assets${brandIdQueryParam}`;\n};\n\n/**\n * Fetches assets from the asset management service API\n * @param orgId - organization ID.\n * @param brandId - brand ID.\n * @returns Promise resolving to an array of assets\n */\nexport const getAssets = async (orgId: string, brandId?: string): Promise<Asset[]> => {\n const apiUrl = buildApiUrl(orgId, brandId);\n\n if (!apiUrl) {\n throw new Error('Organization ID is required to fetch assets');\n }\n\n const response = await fetch(apiUrl, {\n method: 'GET',\n credentials: 'include',\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch assets: ${response.statusText}`);\n }\n\n return (await response.json()) as Asset[];\n};\n"],"names":["getAssetsKey","buildApiUrl","orgId","brandId","brandIdQueryParam","isProd","window","location","host","includes","getAssetManagementApiUrl","getAssets","async","apiUrl","Error","response","fetch","method","credentials","ok","statusText","json"],"mappings":"AAEO,MAAMA,EAAe,YAyBtBC,EAAc,CAACC,EAAeC,KAClC,IAAKD,EAAO,OACZ,MAAME,EAAoBD,EAAU,YAAYA,IAAY,GAE5D,MAAO,GApBwB,MAC/B,MAAME,EAASC,OAAOC,UAAUC,MAAMC,SAAS,uBAE/C,OAAIJ,EAVe,uDACO,2DAyBVK,MACKR,WAAeE,KASzBO,EAAYC,MAAOV,EAAeC,KAC7C,MAAMU,EAASZ,EAAYC,EAAOC,GAElC,IAAKU,EACH,MAAM,IAAIC,MAAM,+CAGlB,MAAMC,QAAiBC,MAAMH,EAAQ,CACnCI,OAAQ,MACRC,YAAa,YAGf,IAAKH,EAASI,GACZ,MAAM,IAAIL,MAAM,2BAA2BC,EAASK,cAGtD,aAAcL,EAASM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipdish/portal-library",
3
- "version": "7.10.2",
3
+ "version": "7.10.3",
4
4
  "files": [
5
5
  "dist"
6
6
  ],