You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.1 KiB

1 month ago
  1. {"ast":null,"code":"import { ref, provide, inject, onMounted, unref, onBeforeUnmount } from 'vue';\nimport Collection from './collection2.mjs';\nimport CollectionItem from './collection-item.mjs';\nconst COLLECTION_ITEM_SIGN = `data-el-collection-item`;\nconst createCollectionWithScope = name => {\n const COLLECTION_NAME = `El${name}Collection`;\n const COLLECTION_ITEM_NAME = `${COLLECTION_NAME}Item`;\n const COLLECTION_INJECTION_KEY = Symbol(COLLECTION_NAME);\n const COLLECTION_ITEM_INJECTION_KEY = Symbol(COLLECTION_ITEM_NAME);\n const ElCollection = {\n ...Collection,\n name: COLLECTION_NAME,\n setup() {\n const collectionRef = ref(null);\n const itemMap = /* @__PURE__ */new Map();\n const getItems = () => {\n const collectionEl = unref(collectionRef);\n if (!collectionEl) return [];\n const orderedNodes = Array.from(collectionEl.querySelectorAll(`[${COLLECTION_ITEM_SIGN}]`));\n const items = [...itemMap.values()];\n return items.sort((a, b) => orderedNodes.indexOf(a.ref) - orderedNodes.indexOf(b.ref));\n };\n provide(COLLECTION_INJECTION_KEY, {\n itemMap,\n getItems,\n collectionRef\n });\n }\n };\n const ElCollectionItem = {\n ...CollectionItem,\n name: COLLECTION_ITEM_NAME,\n setup(_, {\n attrs\n }) {\n const collectionItemRef = ref(null);\n const collectionInjection = inject(COLLECTION_INJECTION_KEY, void 0);\n provide(COLLECTION_ITEM_INJECTION_KEY, {\n collectionItemRef\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 onBeforeUnmount(() => {\n const collectionItemEl = unref(collectionItemRef);\n collectionInjection.itemMap.delete(collectionItemEl);\n });\n }\n };\n return {\n COLLECTION_INJECTION_KEY,\n COLLECTION_ITEM_INJECTION_KEY,\n ElCollection,\n ElCollectionItem\n };\n};\nexport { COLLECTION_ITEM_SIGN, createCollectionWithScope };","map":{"version":3,"names":["COLLECTION_ITEM_SIGN","createCollectionWithScope","name","COLLECTION_NAME","COLLECTION_ITEM_NAME","COLLECTION_INJECTION_KEY","Symbol","COLLECTION_ITEM_INJECTION_KEY","ElCollection","Collection","setup","collectionRef","ref","itemMap","Map","getItems","collectionEl","unref","orderedNodes","Array","from","querySelectorAll","items","values","sort","a","b","indexOf","provide","ElCollectionItem","CollectionItem","_","attrs","collectionItemRef","collectionInjection","inject","onMounted","collectionItemEl","set","onBeforeUnmount","delete"],"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<ElCollectionInjectionContext> =\n Symbol(COLLECTION_NAME)\n const COLLECTION_ITEM_INJECTION_KEY: InjectionKey<ElCollectionItemInjectionContext> =\n Symbol(COLLECTION_ITEM_NAME)\n\n const ElCollection = {\n ...Collection,\n name: COLLECTION_NAME,\n setup() {\n const collectionRef = ref<HTMLElement | null>(null)\n const itemMap: ElCollectionInjectionContext['itemMap'] = new Map()\n const getItems = () => {\n const collectionEl = unref(collectionRef)\n\n if (!collect