{"version":3,"file":"CMSLibrary.DGPFfih1.mjs","names":[],"sources":["https:/cdn.feux.io/utils/CMSLibrary.ts","https:/framerusercontent.com/modules/Pbp9mrikgXz4lfKUoo2G/KX903QOF9BaQkDA33Ftl/CMSLibrary.js"],"sourcesContent":["export function getCollectionData(collectionList) {\n    let queryParent = null\n    if (collectionList?.props?.query) {\n        queryParent = collectionList\n    } else if (collectionList?.props?.children?.props?.query) {\n        queryParent = collectionList.props.children\n    } else if (collectionList?.props?.children?.props?.children?.props?.query) {\n        queryParent = collectionList.props.children.props.children\n    }\n    const query = queryParent?.props?.query\n    const from = query?.from\n    let collections = []\n    if (from) {\n        if (from.type === \"Collection\") {\n            collections.push(from)\n        } else if (from.type === \"LeftJoin\") {\n            processJoin(from.left, collections)\n            processJoin(from.right, collections)\n        }\n    }\n    const select = query?.select\n    if (collections.length > 1 && Array.isArray(select)) {\n        for (const field of select) {\n            if (\n                field.type == \"Identifier\" &&\n                field.name == \"id\" &&\n                !field.alias\n            ) {\n                const mainCollection = collections.find(\n                    (c) => c.alias == field.collection\n                )\n                if (mainCollection) {\n                    collections = [\n                        mainCollection,\n                        ...collections.filter((c) => c !== mainCollection),\n                    ]\n                }\n                break\n            }\n        }\n    }\n    const multiReferenceQueries = {}\n    const multiReferenceIdMap = {} // Get collections from multi-reference fields\n    if (Array.isArray(select)) {\n        for (const field of select) {\n            if (\n                field.type === \"FunctionCall\" &&\n                (field.functionName === \"ARRAY\" ||\n                    field.functionName === \"FLAT_ARRAY\") &&\n                Array.isArray(field.arguments)\n            ) {\n                for (const argument of field.arguments) {\n                    if (argument.from?.type === \"Collection\") {\n                        const alias = argument.from.alias\n                        let fieldId = alias\n                        const right = argument.where?.right\n                        if (\n                            right &&\n                            right.type === \"Identifier\" &&\n                            right.name\n                        ) {\n                            fieldId = right.name\n                        }\n                        collections.push({ ...argument.from, fieldId })\n                        multiReferenceIdMap[fieldId] = alias\n                        multiReferenceIdMap[alias] = alias\n                        multiReferenceQueries[alias] = argument\n                    }\n                }\n            }\n        }\n    }\n    let queryData = collections[0]?.data\n    const propertyControlsById = {}\n    const propertyControlsByTitle = {}\n    for (const collection of collections) {\n        const byId = {}\n        const byName = {}\n        propertyControlsById[collection.alias] = byId\n        propertyControlsByTitle[collection.alias] = byName\n        const propertyControls = collection.data?.propertyControls\n        for (const id of Object.keys(propertyControls)) {\n            const control = { id, ...propertyControls[id] }\n            byId[id] = control\n            byName[control.title] = control\n        }\n    } // Get children function\n    let childrenFunction = null\n    if (collectionList) {\n        const clpc = collectionList.props?.children\n        if (typeof clpc == \"function\") {\n            childrenFunction = clpc\n        } else if (typeof clpc?.props?.children == \"function\") {\n            childrenFunction = clpc.props.children\n        } else if (\n            typeof clpc?.props?.children?.props?.children == \"function\"\n        ) {\n            childrenFunction = clpc.props.children.props.children\n        }\n    }\n    return {\n        query,\n        queryParent,\n        queryData,\n        collections,\n        propertyControlsById,\n        propertyControlsByTitle,\n        childrenFunction,\n        multiReferenceQueries,\n        multiReferenceIdMap,\n    }\n}\nfunction processJoin(join, collections) {\n    if (join && typeof join === \"object\") {\n        if (join.type === \"Collection\") {\n            collections.push(join)\n        } else if (join.type === \"LeftJoin\") {\n            processJoin(join.left, collections)\n            processJoin(join.right, collections)\n        }\n    }\n} // field: { name: string, referenceFieldName: string }\nexport function addFieldsToSelect(\n    fields,\n    query,\n    propertyControlsByTitle,\n    collections\n) {\n    const select = Array.isArray(query?.select) ? [...query.select] : []\n    for (const field of fields) {\n        const selectItem = getSelectItemForField(\n            field.name,\n            field.referenceFieldName,\n            query,\n            propertyControlsByTitle,\n            collections,\n            select\n        )\n        if (selectItem) {\n            select.push(selectItem)\n        }\n    }\n    return select\n}\nexport function getSelectItemForField(\n    name,\n    referenceFieldName,\n    query,\n    propertyControlsByTitle,\n    collections,\n    select = null // When there is a select, check for a matching existing select item\n) {\n    // const mainAlias = query?.from?.alias || \"\"\n    const mainAlias = collections[0]?.alias || \"\"\n    const propertyControl = propertyControlsByTitle[mainAlias]?.[name]\n    if (!propertyControl) {\n        return null\n    }\n    const fieldId = propertyControl?.id\n    const alias = referenceFieldName ? fieldId : mainAlias\n    const referencedField = referenceFieldName\n        ? propertyControlsByTitle[fieldId]?.[referenceFieldName]\n        : null\n    if (select) {\n        let matchFound = false\n        for (const item of select) {\n            if (item.type === \"Identifier\") {\n                if (referenceFieldName) {\n                    if (\n                        referencedField &&\n                        item.alias === `${fieldId}.${referencedField.id}` &&\n                        item.collection === fieldId &&\n                        item.name === referencedField.id\n                    ) {\n                        matchFound = true\n                        break\n                    }\n                } else {\n                    if (item.name === fieldId && item.collection === alias) {\n                        matchFound = true\n                        break\n                    }\n                }\n            } else if (item.type === \"FunctionCall\") {\n                if (item.alias === fieldId) {\n                    matchFound = true\n                    break\n                }\n            }\n        }\n        if (matchFound) {\n            return null\n        }\n    }\n    if (referenceFieldName) {\n        if (referencedField) {\n            return {\n                alias: `${fieldId}.${referencedField.id}`,\n                collection: fieldId,\n                name: referencedField.id,\n                type: \"Identifier\",\n            }\n        }\n    } else {\n        return { collection: alias, name: fieldId, type: \"Identifier\" }\n    }\n}\n","export{getCollectionData,addFieldsToSelect,getSelectItemForField}from\"https://cdn.feux.io/utils/CMSLibrary.ts\";\nexport const __FramerMetadata__ = {\"exports\":{\"addFieldsToSelect\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getCollectionData\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"getSelectItemForField\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CMSLibrary.map"],"mappings":"oDAAA,SAAgB,EAAkB,EAAgB,CAC9C,IAAI,EAAc,KACd,GAAgB,OAAO,MACvB,EAAc,EACP,GAAgB,OAAO,UAAU,OAAO,MAC/C,EAAc,EAAe,MAAM,SAC5B,GAAgB,OAAO,UAAU,OAAO,UAAU,OAAO,QAChE,EAAc,EAAe,MAAM,S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