@shopware-ag/meteor-component-library
Version:
The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).
408 lines (407 loc) • 11.9 kB
JavaScript
;
const vue = require("vue");
function renderSlotFragments(children) {
if (!children)
return [];
return children.flatMap((child) => {
if (child.type === vue.Fragment)
return renderSlotFragments(child.children);
return [child];
});
}
function computedEager(fn, options) {
var _a;
const result = vue.shallowRef();
vue.watchEffect(() => {
result.value = fn();
}, {
...options,
flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
});
return vue.readonly(result);
}
function tryOnScopeDispose(fn) {
if (vue.getCurrentScope()) {
vue.onScopeDispose(fn);
return true;
}
return false;
}
function createGlobalState(stateFactory) {
let initialized = false;
let state;
const scope = vue.effectScope(true);
return (...args) => {
if (!initialized) {
state = scope.run(() => stateFactory(...args));
initialized = true;
}
return state;
};
}
function createSharedComposable(composable) {
let subscribers = 0;
let state;
let scope;
const dispose = () => {
subscribers -= 1;
if (scope && subscribers <= 0) {
scope.stop();
state = void 0;
scope = void 0;
}
};
return (...args) => {
subscribers += 1;
if (!scope) {
scope = vue.effectScope(true);
state = scope.run(() => composable(...args));
}
tryOnScopeDispose(dispose);
return state;
};
}
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
const isDef = (val) => typeof val !== "undefined";
const toString = Object.prototype.toString;
const isObject = (val) => toString.call(val) === "[object Object]";
const isIOS = /* @__PURE__ */ getIsIOS();
function getIsIOS() {
var _a, _b;
return isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? void 0 : window.navigator) == null ? void 0 : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? void 0 : window.navigator.userAgent));
}
function getLifeCycleTarget(target) {
return target || vue.getCurrentInstance();
}
function toArray(value) {
return Array.isArray(value) ? value : [value];
}
function refAutoReset(defaultValue, afterMs = 1e4) {
return vue.customRef((track, trigger) => {
let value = vue.toValue(defaultValue);
let timer;
const resetAfter = () => setTimeout(() => {
value = vue.toValue(defaultValue);
trigger();
}, vue.toValue(afterMs));
tryOnScopeDispose(() => {
clearTimeout(timer);
});
return {
get() {
track();
return value;
},
set(newValue) {
value = newValue;
trigger();
clearTimeout(timer);
timer = resetAfter();
}
};
});
}
function tryOnBeforeUnmount(fn, target) {
const instance = getLifeCycleTarget(target);
if (instance)
vue.onBeforeUnmount(fn, target);
}
function watchImmediate(source, cb, options) {
return vue.watch(
source,
cb,
{
...options,
immediate: true
}
);
}
const defaultWindow = isClient ? window : void 0;
function unrefElement(elRef) {
var _a;
const plain = vue.toValue(elRef);
return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
}
function useEventListener(...args) {
const cleanups = [];
const cleanup = () => {
cleanups.forEach((fn) => fn());
cleanups.length = 0;
};
const register = (el, event, listener, options) => {
el.addEventListener(event, listener, options);
return () => el.removeEventListener(event, listener, options);
};
const firstParamTargets = vue.computed(() => {
const test = toArray(vue.toValue(args[0])).filter((e) => e != null);
return test.every((e) => typeof e !== "string") ? test : void 0;
});
const stopWatch = watchImmediate(
() => {
var _a, _b;
return [
(_b = (_a = firstParamTargets.value) == null ? void 0 : _a.map((e) => unrefElement(e))) != null ? _b : [defaultWindow].filter((e) => e != null),
toArray(vue.toValue(firstParamTargets.value ? args[1] : args[0])),
toArray(vue.unref(firstParamTargets.value ? args[2] : args[1])),
// @ts-expect-error - TypeScript gets the correct types, but somehow still complains
vue.toValue(firstParamTargets.value ? args[3] : args[2])
];
},
([raw_targets, raw_events, raw_listeners, raw_options]) => {
cleanup();
if (!(raw_targets == null ? void 0 : raw_targets.length) || !(raw_events == null ? void 0 : raw_events.length) || !(raw_listeners == null ? void 0 : raw_listeners.length))
return;
const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
cleanups.push(
...raw_targets.flatMap(
(el) => raw_events.flatMap(
(event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
)
)
);
},
{ flush: "post" }
);
const stop = () => {
stopWatch();
cleanup();
};
tryOnScopeDispose(cleanup);
return stop;
}
function useMounted() {
const isMounted = vue.shallowRef(false);
const instance = vue.getCurrentInstance();
if (instance) {
vue.onMounted(() => {
isMounted.value = true;
}, instance);
}
return isMounted;
}
function createKeyPredicate(keyFilter) {
if (typeof keyFilter === "function")
return keyFilter;
else if (typeof keyFilter === "string")
return (event) => event.key === keyFilter;
else if (Array.isArray(keyFilter))
return (event) => keyFilter.includes(event.key);
return () => true;
}
function onKeyStroke(...args) {
let key;
let handler;
let options = {};
if (args.length === 3) {
key = args[0];
handler = args[1];
options = args[2];
} else if (args.length === 2) {
if (typeof args[1] === "object") {
key = true;
handler = args[0];
options = args[1];
} else {
key = args[0];
handler = args[1];
}
} else {
key = true;
handler = args[0];
}
const {
target = defaultWindow,
eventName = "keydown",
passive = false,
dedupe = false
} = options;
const predicate = createKeyPredicate(key);
const listener = (e) => {
if (e.repeat && vue.toValue(dedupe))
return;
if (predicate(e))
handler(e);
};
return useEventListener(target, eventName, listener, passive);
}
function cloneFnJSON(source) {
return JSON.parse(JSON.stringify(source));
}
function useVModel(props, key, emit, options = {}) {
var _a, _b, _c;
const {
clone = false,
passive = false,
eventName,
deep = false,
defaultValue,
shouldEmit
} = options;
const vm = vue.getCurrentInstance();
const _emit = emit || (vm == null ? void 0 : vm.emit) || ((_a = vm == null ? void 0 : vm.$emit) == null ? void 0 : _a.bind(vm)) || ((_c = (_b = vm == null ? void 0 : vm.proxy) == null ? void 0 : _b.$emit) == null ? void 0 : _c.bind(vm == null ? void 0 : vm.proxy));
let event = eventName;
if (!key) {
key = "modelValue";
}
event = event || `update:${key.toString()}`;
const cloneFn = (val) => !clone ? val : typeof clone === "function" ? clone(val) : cloneFnJSON(val);
const getValue = () => isDef(props[key]) ? cloneFn(props[key]) : defaultValue;
const triggerEmit = (value) => {
if (shouldEmit) {
if (shouldEmit(value))
_emit(event, value);
} else {
_emit(event, value);
}
};
if (passive) {
const initialValue = getValue();
const proxy = vue.ref(initialValue);
let isUpdating = false;
vue.watch(
() => props[key],
(v) => {
if (!isUpdating) {
isUpdating = true;
proxy.value = cloneFn(v);
vue.nextTick(() => isUpdating = false);
}
}
);
vue.watch(
proxy,
(v) => {
if (!isUpdating && (v !== props[key] || deep))
triggerEmit(v);
},
{ deep }
);
return proxy;
} else {
return vue.computed({
get() {
return getValue();
},
set(value) {
triggerEmit(value);
}
});
}
}
function useForwardExpose() {
const instance = vue.getCurrentInstance();
const currentRef = vue.ref();
const currentElement = vue.computed(() => {
var _a, _b;
return ["#text", "#comment"].includes((_a = currentRef.value) == null ? void 0 : _a.$el.nodeName) ? (_b = currentRef.value) == null ? void 0 : _b.$el.nextElementSibling : unrefElement(currentRef);
});
const localExpose = Object.assign({}, instance.exposed);
const ret = {};
for (const key in instance.props)
Object.defineProperty(ret, key, {
enumerable: true,
configurable: true,
get: () => instance.props[key]
});
if (Object.keys(localExpose).length > 0)
for (const key in localExpose)
Object.defineProperty(ret, key, {
enumerable: true,
configurable: true,
get: () => localExpose[key]
});
Object.defineProperty(ret, "$el", {
enumerable: true,
configurable: true,
get: () => instance.vnode.el
});
instance.exposed = ret;
function forwardRef(ref$1) {
currentRef.value = ref$1;
if (!ref$1)
return;
Object.defineProperty(ret, "$el", {
enumerable: true,
configurable: true,
get: () => ref$1 instanceof Element ? ref$1 : ref$1.$el
});
instance.exposed = ret;
}
return {
forwardRef,
currentRef,
currentElement
};
}
const Slot = vue.defineComponent({
name: "PrimitiveSlot",
inheritAttrs: false,
setup(_, { attrs, slots }) {
return () => {
var _a;
if (!slots.default)
return null;
const children = renderSlotFragments(slots.default());
const firstNonCommentChildrenIndex = children.findIndex((child) => child.type !== vue.Comment);
if (firstNonCommentChildrenIndex === -1)
return children;
const firstNonCommentChildren = children[firstNonCommentChildrenIndex];
(_a = firstNonCommentChildren.props) == null ? true : delete _a.ref;
const mergedProps = firstNonCommentChildren.props ? vue.mergeProps(attrs, firstNonCommentChildren.props) : attrs;
const cloned = vue.cloneVNode({
...firstNonCommentChildren,
props: {}
}, mergedProps);
if (children.length === 1)
return cloned;
children[firstNonCommentChildrenIndex] = cloned;
return children;
};
}
});
const SELF_CLOSING_TAGS = [
"area",
"img",
"input"
];
const Primitive = vue.defineComponent({
name: "Primitive",
inheritAttrs: false,
props: {
asChild: {
type: Boolean,
default: false
},
as: {
type: [String, Object],
default: "div"
}
},
setup(props, { attrs, slots }) {
const asTag = props.asChild ? "template" : props.as;
if (typeof asTag === "string" && SELF_CLOSING_TAGS.includes(asTag))
return () => vue.h(asTag, attrs);
if (asTag !== "template")
return () => vue.h(props.as, attrs, { default: slots.default });
return () => vue.h(Slot, attrs, { default: slots.default });
}
});
exports.Primitive = Primitive;
exports.Slot = Slot;
exports.computedEager = computedEager;
exports.createGlobalState = createGlobalState;
exports.createSharedComposable = createSharedComposable;
exports.defaultWindow = defaultWindow;
exports.isClient = isClient;
exports.isIOS = isIOS;
exports.onKeyStroke = onKeyStroke;
exports.refAutoReset = refAutoReset;
exports.renderSlotFragments = renderSlotFragments;
exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
exports.unrefElement = unrefElement;
exports.useEventListener = useEventListener;
exports.useForwardExpose = useForwardExpose;
exports.useMounted = useMounted;
exports.useVModel = useVModel;
//# sourceMappingURL=Primitive-20a16e64.js.map