Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of customEventsHandler #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release history for vue-svg-pan-zoom

v2.2.0 2023-12-13

- add support of customEventsHandler prop (tasiot)

v2.1.0 2022-06-10

- fix bug preventing to mount svgpanzoom (GH#16, KrosFire)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Currently the `SvgPanZoom` component only works with a `svg` child -- `embed` wo
| minZoom | `0.5` |
| maxZoom | `10` |
| refreshRate | `auto` |
| customEventsHandler | `null` |

| event | arguments |
| ------------------------- | ---------------------------------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion dist/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions dist/types/SvgPanZoom.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export interface Props {
contain?: boolean;
center?: boolean;
refreshRate?: number | "auto";
customEventsHandler?: CustomEventsHandler;
}
export interface CustomEventsHandler {
haltEventListeners?: Array<string>;
init: (options: object) => void;
destroy: () => void;
}
export interface Events {
(event: 'beforeZoom', oldScale: number, newScale: number): void;
Expand Down Expand Up @@ -115,6 +121,10 @@ declare const _default: import("vue").DefineComponent<{
type: PropType<Number | "auto">;
default: string;
};
customEventsHandler: {
type: ObjectConstructor;
default: null;
};
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
beforeZoom: (oldScale: number, newScale: number) => void;
} & {
Expand Down Expand Up @@ -186,6 +196,10 @@ declare const _default: import("vue").DefineComponent<{
type: PropType<Number | "auto">;
default: string;
};
customEventsHandler: {
type: ObjectConstructor;
default: null;
};
}>> & {
onBeforeZoom?: ((oldScale: number, newScale: number) => any) | undefined;
onOnZoom?: ((newScale: number) => any) | undefined;
Expand All @@ -209,5 +223,6 @@ declare const _default: import("vue").DefineComponent<{
contain: boolean;
center: boolean;
refreshRate: Number | "auto";
customEventsHandler: Record<string, any>;
}>;
export default _default;
28 changes: 20 additions & 8 deletions dist/vue-svg-pan-zoom.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
}
});
var SvgPanZoomThumbnail = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-093287c4"]]);
var SvgPanZoom_vue_vue_type_style_index_0_lang = /* @__PURE__ */ (() => ".svg-pan-zoom{position:relative}\n")();
var SvgPanZoom_vue_vue_type_style_index_0_lang = /* @__PURE__ */ (() => ".svg-pan-zoom{position:relative}.svg-pan-zoom__default{width:100%;height:100%}\n")();
const _hoisted_1 = { class: "svg-pan-zoom" };
const _sfc_main = defineComponent({
__name: "SvgPanZoom",
Expand Down Expand Up @@ -1413,11 +1413,16 @@ const _sfc_main = defineComponent({
refreshRate: {
type: [Number, String],
default: "auto"
},
customEventsHandler: {
type: Object,
default: null
}
},
emits: ["beforeZoom", "onZoom", "beforePan", "onPan", "onUpdatedCTM", "created", "thumbnailCreated"],
setup(__props, { emit }) {
const props = __props;
const defaultSlot = ref(null);
const slots = useSlots();
const options = ref({});
Object.keys(props).filter((k) => props[k] !== void 0).forEach((k) => {
Expand All @@ -1427,11 +1432,12 @@ const _sfc_main = defineComponent({
});
const spz = ref(null);
const getSvgSelector = (instance) => {
if (instance.el && instance.el.tagName === "svg")
return instance.el;
if (!instance.children || !Array.isArray(instance.children))
if (instance && instance.tagName === "svg")
return instance;
const children = Array.from(instance.children);
if (!children)
return false;
for (const child of instance.children) {
for (const child of children) {
const selector = getSvgSelector(child);
if (selector)
return selector;
Expand All @@ -1441,17 +1447,23 @@ const _sfc_main = defineComponent({
onMounted(() => {
options.value.onZoom = (newScale) => emit("onZoom", newScale);
options.value.onPan = (newPan) => emit("onPan", newPan);
if (!slots["default"])
if (!(slots["default"] && defaultSlot.value))
return;
const selector = getSvgSelector(slots["default"]()[0]);
const selector = getSvgSelector(defaultSlot.value);
if (!selector)
return;
spz.value = svgPanZoom_1(selector, options.value);
emit("created", spz.value);
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
renderSlot(_ctx.$slots, "default"),
createElementVNode("div", {
class: "svg-pan-zoom__default",
ref_key: "defaultSlot",
ref: defaultSlot
}, [
renderSlot(_ctx.$slots, "default")
], 512),
!!_ctx.$slots.thumbnail && !!spz.value ? (openBlock(), createBlock(SvgPanZoomThumbnail, {
key: 0,
onThumbnailCreated: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("thumbnailCreated", $event)),
Expand Down
8 changes: 4 additions & 4 deletions dist/vue-svg-pan-zoom.umd.js

Large diffs are not rendered by default.

Loading