{"version":3,"file":"collection2.mjs","sources":["../../../../../../packages/components/collection/src/collection.ts"],"sourcesContent":["import { inject, onBeforeUnmount, onMounted, provide, ref, unref } from 'vue'\nimport Collection from './collection.vue'\nimport CollectionItem from './collection-item.vue'\n\nimport type { InjectionKey } from 'vue'\nimport type { SetupContext } from '@vue/runtime-core'\nimport type {\n ElCollectionInjectionContext,\n ElCollectionItemInjectionContext,\n} from './tokens'\n\nexport const COLLECTION_ITEM_SIGN = `data-el-collection-item`\n\n// Make sure the first letter of name is capitalized\nexport const createCollectionWithScope = (name: string) => {\n const COLLECTION_NAME = `El${name}Collection`\n const COLLECTION_ITEM_NAME = `${COLLECTION_NAME}Item`\n const COLLECTION_INJECTION_KEY: InjectionKey =\n Symbol(COLLECTION_NAME)\n const COLLECTION_ITEM_INJECTION_KEY: InjectionKey =\n Symbol(COLLECTION_ITEM_NAME)\n\n const ElCollection = {\n ...Collection,\n name: COLLECTION_NAME,\n setup() {\n const collectionRef = ref(null)\n const itemMap: ElCollectionInjectionContext['itemMap'] = new Map()\n const getItems = () => {\n const collectionEl = unref(collectionRef)\n\n if (!collectionEl) return []\n const orderedNodes = Array.from(\n collectionEl.querySelectorAll(`[${COLLECTION_ITEM_SIGN}]`)\n )\n\n const items = [...itemMap.values()]\n\n return items.sort(\n (a, b) => orderedNodes.indexOf(a.ref!) - orderedNodes.indexOf(b.ref!)\n )\n }\n\n provide(COLLECTION_INJECTION_KEY, {\n itemMap,\n getItems,\n collectionRef,\n })\n },\n }\n\n const ElCollectionItem = {\n ...CollectionItem,\n name: COLLECTION_ITEM_NAME,\n setup(_: unknown, { attrs }: SetupContext) {\n const collectionItemRef = ref(null)\n const collectionInjection = inject(COLLECTION_INJECTION_KEY, undefined)!\n\n provide(COLLECTION_ITEM_INJECTION_KEY, {\n collectionItemRef,\n })\n\n onMounted(() => {\n const collectionItemEl = unref(collectionItemRef)\n if (collectionItemEl) {\n collectionInjection.itemMap.set(collectionItemEl, {\n ref: collectionItemEl,\n ...attrs,\n })\n }\n })\n\n onBeforeUnmount(() => {\n const collectionItemEl = unref(collectionItemRef)!\n collectionInjection.itemMap.delete(collectionItemEl)\n })\n },\n }\n\n return {\n COLLECTION_INJECTION_KEY,\n COLLECTION_ITEM_INJECTION_KEY,\n ElCollection,\n ElCollectionItem,\n }\n}\n"],"names":[],"mappings":";;;;AAGY,MAAC,oBAAoB,GAAG,CAAC,uBAAuB,EAAE;AAClD,MAAC,yBAAyB,GAAG,CAAC,IAAI,KAAK;AACnD,EAAE,MAAM,eAAe,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AAChD,EAAE,MAAM,oBAAoB,GAAG,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;AACxD,EAAE,MAAM,wBAAwB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC3D,EAAE,MAAM,6BAA6B,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACrE,EAAE,MAAM,YAAY,GAAG;AACvB,IAAI,GAAG,UAAU;AACjB,IAAI,IAAI,EAAE,eAAe;AACzB,IAAI,KAAK,GAAG;AACZ,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,MAAM,MAAM,OAAO,mBAAmB,IAAI,GAAG,EAAE,CAAC;AAChD,MAAM,MAAM,QAAQ,GAAG,MAAM;AAC7B,QAAQ,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC;AAClD,QAAQ,IAAI,CAAC,YAAY;AACzB,UAAU,OAAO,EAAE,CAAC;AACpB,QAAQ,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpG,QAAQ,MAAM,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5C,QAAQ,OAAO,KAAK,CAAC,IA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