collection.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
  2. require("../../../_virtual/_rolldown/runtime.js");
  3. const require_collection = require("./collection2.js");
  4. const require_collection_item = require("./collection-item.js");
  5. let vue = require("vue");
  6. //#region ../../packages/components/collection/src/collection.ts
  7. const COLLECTION_ITEM_SIGN = `data-el-collection-item`;
  8. const createCollectionWithScope = (name) => {
  9. const COLLECTION_NAME = `El${name}Collection`;
  10. const COLLECTION_ITEM_NAME = `${COLLECTION_NAME}Item`;
  11. const COLLECTION_INJECTION_KEY = Symbol(COLLECTION_NAME);
  12. const COLLECTION_ITEM_INJECTION_KEY = Symbol(COLLECTION_ITEM_NAME);
  13. return {
  14. COLLECTION_INJECTION_KEY,
  15. COLLECTION_ITEM_INJECTION_KEY,
  16. ElCollection: Object.assign({}, require_collection.default, {
  17. name: COLLECTION_NAME,
  18. setup() {
  19. const collectionRef = (0, vue.ref)();
  20. const itemMap = /* @__PURE__ */ new Map();
  21. const getItems = (() => {
  22. const collectionEl = (0, vue.unref)(collectionRef);
  23. if (!collectionEl) return [];
  24. const orderedNodes = Array.from(collectionEl.querySelectorAll(`[${COLLECTION_ITEM_SIGN}]`));
  25. return [...itemMap.values()].sort((a, b) => orderedNodes.indexOf(a.ref) - orderedNodes.indexOf(b.ref));
  26. });
  27. (0, vue.provide)(COLLECTION_INJECTION_KEY, {
  28. itemMap,
  29. getItems,
  30. collectionRef
  31. });
  32. }
  33. }),
  34. ElCollectionItem: Object.assign({}, require_collection_item.default, {
  35. name: COLLECTION_ITEM_NAME,
  36. setup(_, { attrs }) {
  37. const collectionItemRef = (0, vue.ref)();
  38. const collectionInjection = (0, vue.inject)(COLLECTION_INJECTION_KEY, void 0);
  39. (0, vue.provide)(COLLECTION_ITEM_INJECTION_KEY, { collectionItemRef });
  40. (0, vue.onMounted)(() => {
  41. const collectionItemEl = (0, vue.unref)(collectionItemRef);
  42. if (collectionItemEl) collectionInjection.itemMap.set(collectionItemEl, {
  43. ref: collectionItemEl,
  44. ...attrs
  45. });
  46. });
  47. (0, vue.onBeforeUnmount)(() => {
  48. const collectionItemEl = (0, vue.unref)(collectionItemRef);
  49. collectionInjection.itemMap.delete(collectionItemEl);
  50. });
  51. }
  52. })
  53. };
  54. };
  55. //#endregion
  56. exports.COLLECTION_ITEM_SIGN = COLLECTION_ITEM_SIGN;
  57. exports.createCollectionWithScope = createCollectionWithScope;
  58. //# sourceMappingURL=collection.js.map