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.
74 lines
2.5 KiB
74 lines
2.5 KiB
'use strict';
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
var vue = require('vue');
|
|
require('./collection2.js');
|
|
require('./collection-item.js');
|
|
var collection_vue_vue_type_script_lang = require('./collection.vue_vue_type_script_lang.js');
|
|
var collectionItem_vue_vue_type_script_lang = require('./collection-item.vue_vue_type_script_lang.js');
|
|
|
|
const COLLECTION_ITEM_SIGN = `data-el-collection-item`;
|
|
const createCollectionWithScope = (name) => {
|
|
const COLLECTION_NAME = `El${name}Collection`;
|
|
const COLLECTION_ITEM_NAME = `${COLLECTION_NAME}Item`;
|
|
const COLLECTION_INJECTION_KEY = Symbol(COLLECTION_NAME);
|
|
const COLLECTION_ITEM_INJECTION_KEY = Symbol(COLLECTION_ITEM_NAME);
|
|
const ElCollection = {
|
|
...collection_vue_vue_type_script_lang["default"],
|
|
name: COLLECTION_NAME,
|
|
setup() {
|
|
const collectionRef = vue.ref(null);
|
|
const itemMap = /* @__PURE__ */ new Map();
|
|
const getItems = () => {
|
|
const collectionEl = vue.unref(collectionRef);
|
|
if (!collectionEl)
|
|
return [];
|
|
const orderedNodes = Array.from(collectionEl.querySelectorAll(`[${COLLECTION_ITEM_SIGN}]`));
|
|
const items = [...itemMap.values()];
|
|
const orderedItems = items.sort((a, b) => orderedNodes.indexOf(a.ref) - orderedNodes.indexOf(b.ref));
|
|
return orderedItems;
|
|
};
|
|
vue.provide(COLLECTION_INJECTION_KEY, {
|
|
itemMap,
|
|
getItems,
|
|
collectionRef
|
|
});
|
|
}
|
|
};
|
|
const ElCollectionItem = {
|
|
...collectionItem_vue_vue_type_script_lang["default"],
|
|
name: COLLECTION_ITEM_NAME,
|
|
setup(_, { attrs }) {
|
|
const collectionItemRef = vue.ref(null);
|
|
const collectionInjection = vue.inject(COLLECTION_INJECTION_KEY, void 0);
|
|
vue.provide(COLLECTION_ITEM_INJECTION_KEY, {
|
|
collectionItemRef
|
|
});
|
|
vue.onMounted(() => {
|
|
const collectionItemEl = vue.unref(collectionItemRef);
|
|
if (collectionItemEl) {
|
|
collectionInjection.itemMap.set(collectionItemEl, {
|
|
ref: collectionItemEl,
|
|
...attrs
|
|
});
|
|
}
|
|
});
|
|
vue.onBeforeUnmount(() => {
|
|
const collectionItemEl = vue.unref(collectionItemRef);
|
|
collectionInjection.itemMap.delete(collectionItemEl);
|
|
});
|
|
}
|
|
};
|
|
return {
|
|
COLLECTION_INJECTION_KEY,
|
|
COLLECTION_ITEM_INJECTION_KEY,
|
|
ElCollection,
|
|
ElCollectionItem
|
|
};
|
|
};
|
|
|
|
exports.COLLECTION_ITEM_SIGN = COLLECTION_ITEM_SIGN;
|
|
exports.createCollectionWithScope = createCollectionWithScope;
|
|
//# sourceMappingURL=collection.js.map
|