101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name2 in all)
|
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var stdin_exports = {};
|
|
__export(stdin_exports, {
|
|
default: () => stdin_default
|
|
});
|
|
module.exports = __toCommonJS(stdin_exports);
|
|
var import_vue = require("vue");
|
|
var import_utils = require("../utils");
|
|
var import_Swipe = require("../swipe/Swipe");
|
|
var import_use = require("@vant/use");
|
|
var import_use_expose = require("../composables/use-expose");
|
|
const [name, bem] = (0, import_utils.createNamespace)("swipe-item");
|
|
var stdin_default = (0, import_vue.defineComponent)({
|
|
name,
|
|
setup(props, {
|
|
slots
|
|
}) {
|
|
let rendered;
|
|
const state = (0, import_vue.reactive)({
|
|
offset: 0,
|
|
inited: false,
|
|
mounted: false
|
|
});
|
|
const {
|
|
parent,
|
|
index
|
|
} = (0, import_use.useParent)(import_Swipe.SWIPE_KEY);
|
|
if (!parent) {
|
|
if (process.env.NODE_ENV !== "production") {
|
|
console.error("[Vant] <SwipeItem> must be a child component of <Swipe>.");
|
|
}
|
|
return;
|
|
}
|
|
const style = (0, import_vue.computed)(() => {
|
|
const style2 = {};
|
|
const {
|
|
vertical
|
|
} = parent.props;
|
|
if (parent.size.value) {
|
|
style2[vertical ? "height" : "width"] = `${parent.size.value}px`;
|
|
}
|
|
if (state.offset) {
|
|
style2.transform = `translate${vertical ? "Y" : "X"}(${state.offset}px)`;
|
|
}
|
|
return style2;
|
|
});
|
|
const shouldRender = (0, import_vue.computed)(() => {
|
|
const {
|
|
loop,
|
|
lazyRender
|
|
} = parent.props;
|
|
if (!lazyRender || rendered) {
|
|
return true;
|
|
}
|
|
if (!state.mounted) {
|
|
return false;
|
|
}
|
|
const active = parent.activeIndicator.value;
|
|
const maxActive = parent.count.value - 1;
|
|
const prevActive = active === 0 && loop ? maxActive : active - 1;
|
|
const nextActive = active === maxActive && loop ? 0 : active + 1;
|
|
rendered = index.value === active || index.value === prevActive || index.value === nextActive;
|
|
return rendered;
|
|
});
|
|
const setOffset = (offset) => {
|
|
state.offset = offset;
|
|
};
|
|
(0, import_vue.onMounted)(() => {
|
|
(0, import_vue.nextTick)(() => {
|
|
state.mounted = true;
|
|
});
|
|
});
|
|
(0, import_use_expose.useExpose)({
|
|
setOffset
|
|
});
|
|
return () => {
|
|
var _a;
|
|
return (0, import_vue.createVNode)("div", {
|
|
"class": bem(),
|
|
"style": style.value
|
|
}, [shouldRender.value ? (_a = slots.default) == null ? void 0 : _a.call(slots) : null]);
|
|
};
|
|
}
|
|
});
|