{"version":3,"file":"block-link-statuses.CafYItwP.js","sources":["../../../../../../../../packages/builder-oem/src/components/embedded-link/block-link-statuses.ts"],"sourcesContent":["/**\n * This feature provides a store and utilities for managing the statutes of blocks on the page.\n * It is needed for showing/hiding elements in components which have children or other blocks inside.\n * For example:\n * - There is Tabs component with some component inside.\n * - This component has links which are all invalid so we want to hide this component entirely.\n * - But when we hide this component then we need to hide the tab which contains this component because it will be empty otherwise.\n * - We can mark this component as invalid via `setBlockLinkStatus` which will update `blockLinkStatusesStore` store.\n * - And in Tabs component we can check if it's children are invalid so we can hide the tab.\n */\nimport { get, writable } from 'svelte/store';\n\ntype BlockLinkStatus = {\n\tblockId: string;\n\tinvalid: boolean;\n};\n\nexport type BlockLinkStatuses = BlockLinkStatus[];\n\nexport const blockLinkStatusesStore = writable<BlockLinkStatuses>([]);\n\n/**\n * Sets the status of a block.\n *\n * @param options - The options for setting the block link status.\n * @param options.blockId - The ID of the block.\n * @param options.invalid - The invalid status of the block.\n */\nexport const setBlockLinkStatus = ({ blockId, invalid }: BlockLinkStatus) => {\n\tconst blocks = get(blockLinkStatusesStore);\n\tconst block = blocks.find((block) => block.blockId === blockId);\n\n\tif (!block) {\n\t\tblockLinkStatusesStore.update((links) => [\n\t\t\t...links,\n\t\t\t{\n\t\t\t\tblockId,\n\t\t\t\tinvalid,\n\t\t\t},\n\t\t]);\n\t} else {\n\t\tif (block.invalid === invalid) return;\n\n\t\tblockLinkStatusesStore.update((blocks) =>\n\t\t\tblocks.map((block) => (block.blockId === blockId ? { ...block, invalid } : block))\n\t\t);\n\t}\n};\n\n/**\n * Checks if the block status is invalid for the given block ID.\n * @param blockLinkStatuses - The array of block link statuses.\n * @param blockId - The ID of the block to check.\n * @returns A boolean indicating whether the block status is invalid.\n */\nexport const isBlockStatusInvalid = (blockLinkStatuses: BlockLinkStatuses, blockId: string) => {\n\tconst block = blockLinkStatuses.find((block) => block.blockId === blockId);\n\n\treturn block?.invalid ?? false;\n};\n\n/**\n * Resets the block link statuses.\n * It is needed to reset the store on URL change because blocks id are unique per page.\n */\nexport const resetBlockLinkStatuses = () => {\n\tblockLinkStatusesStore.set([]);\n};\n"],"names":["blockLinkStatusesStore","writable","setBlockLinkStatus","blockId","invalid","block","get","links","blocks","isBlockStatusInvalid","blockLinkStatuses","resetBlockLinkStatuses"],"mappings":"oFAmBa,MAAAA,EAAyBC,EAA4B,EAAE,EASvDC,EAAqB,CAAC,CAAE,QAAAC,EAAS,QAAAC,KAA+B,CAE5E,MAAMC,EADSC,EAAIN,CAAsB,EACpB,KAAMK,GAAUA,EAAM,UAAYF,CAAO,EAE9D,GAAI,CAACE,EACmBL,EAAA,OAAQO,GAAU,CACxC,GAAGA,EACH,CACC,QAAAJ,EACA,QAAAC,CACD,CAAA,CACA,MACK,CACF,GAAAC,EAAM,UAAYD,EAAS,OAERJ,EAAA,OAAQQ,GAC9BA,EAAO,IAAKH,GAAWA,EAAM,UAAYF,EAAU,CAAE,GAAGE,EAAO,QAAAD,CAAA,EAAYC,CAAM,CAAA,CAEnF,CACD,EAQaI,EAAuB,CAACC,EAAsCP,IAAoB,CAC9F,MAAME,EAAQK,EAAkB,KAAML,GAAUA,EAAM,UAAYF,CAAO,EAEzE,OAAOE,GAAA,YAAAA,EAAO,UAAW,EAC1B,EAMaM,EAAyB,IAAM,CACpBX,EAAA,IAAI,CAAA,CAAE,CAC9B"}