@yappkit/front-module-map 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ import { defineComponent as e, inject as t, onUnmounted as n, toRefs as r, watch as i } from "vue";
2
+ var a = class {
3
+ constructor({ unwatchFn: e, trackedIn: t = null }) {
4
+ this.overlay = null, this.watching = {
5
+ options: !1,
6
+ layers: !1
7
+ }, this.unwatchFn = e, this.trackedIn = t;
8
+ }
9
+ destroy() {
10
+ if (this.trackedIn) {
11
+ let e = this.trackedIn.indexOf(this);
12
+ e !== -1 && this.trackedIn.splice(e, 1), this.trackedIn = null;
13
+ }
14
+ for (let e of this.unwatchFn) e();
15
+ this.unwatchFn = [], this.overlay &&= (this._detach(), null);
16
+ }
17
+ watchOptions(e, t = {}) {
18
+ if (!this.overlay) throw Error("overlay should be set");
19
+ if (this.watching.options) {
20
+ console.warn(`No need to call ${this.constructor.name}.watchOptions(). options are already being watched`);
21
+ return;
22
+ }
23
+ this.watching.options = !0;
24
+ let n = i(e, () => {
25
+ this.overlay.setProps({ ...e.value });
26
+ }, {
27
+ immediate: !0,
28
+ deep: !0,
29
+ ...t
30
+ });
31
+ this.unwatchFn.push(n);
32
+ }
33
+ watchLayers(e, t = {}) {
34
+ if (!this.overlay) throw Error("overlay should be set");
35
+ if (this.watching.layers) {
36
+ console.warn(`No need to call ${this.constructor.name}.watchLayers(). layers are already being watched`);
37
+ return;
38
+ }
39
+ this.watching.layers = !0;
40
+ let n = i(e, () => {
41
+ this.overlay.setProps({ layers: e.value });
42
+ }, {
43
+ immediate: !0,
44
+ ...t
45
+ });
46
+ this.unwatchFn.push(n);
47
+ }
48
+ }, o = (i) => e((e, { emit: a }) => {
49
+ let { options: o, layers: s } = r(e), c = t(i);
50
+ if (!c || !c.value) throw Error("map should exist");
51
+ let l = null, u = !1;
52
+ return c.value.setDeckGLOverlay(o.value).then((e) => {
53
+ if (u) {
54
+ e.destroy();
55
+ return;
56
+ }
57
+ l = e, e.watchOptions(o, o.value.watchOptionsOptions), e.watchLayers(s, o.value.watchLayersOptions), a("loaded", e);
58
+ }).catch((e) => {
59
+ u || a("error", e);
60
+ }), n(() => {
61
+ u = !0, l?.destroy();
62
+ }), () => {};
63
+ }, {
64
+ props: {
65
+ options: {
66
+ type: Object,
67
+ default: () => ({})
68
+ },
69
+ layers: {
70
+ type: Array,
71
+ default: () => []
72
+ }
73
+ },
74
+ emits: ["loaded", "error"]
75
+ });
76
+ export { a as DeckGLOverlay, o as makeDeckGLOverlayComponent };
@@ -1,111 +1,112 @@
1
- import { defineComponent as y, ref as d, toRefs as g, shallowRef as w, provide as l, computed as k, h as v, onMounted as L, onUnmounted as M, watch as h } from "vue";
2
- class D {
3
- constructor() {
4
- this.deckgl = null, this.map = null, this.watching = { options: !1, layers: !1 }, this.unwatchFn = [];
5
- }
6
- watchOptions(e, a = {}) {
7
- if (!this.map)
8
- throw new Error("map should be set");
9
- if (this.watching.options) {
10
- console.warn("No need to call DeckGLMap.watchOptions(). options are already being watched");
11
- return;
12
- }
13
- this.watching.options = !0;
14
- const t = h(e, () => {
15
- this.map.setProps({ ...e.value });
16
- }, {
17
- immediate: !0,
18
- deep: !0,
19
- ...a
20
- });
21
- this.unwatchFn.push(t);
22
- }
23
- watchLayers(e, a = {}) {
24
- if (!this.map)
25
- throw new Error("map should be set");
26
- if (this.watching.layers) {
27
- console.warn("No need to call DeckGLMap.watchLayers(). layers are already being watched");
28
- return;
29
- }
30
- this.watching.layers = !0;
31
- const t = h(e, () => {
32
- this.map.setProps({ layers: e.value });
33
- }, {
34
- immediate: !0,
35
- ...a
36
- });
37
- this.unwatchFn.push(t);
38
- }
39
- }
40
- class G {
41
- constructor(e) {
42
- this.deckgl = null;
43
- }
44
- get Map() {
45
- return y(
46
- (e, { emit: a, attrs: t, slots: c }) => {
47
- const n = d(null), { options: o, layers: i } = g(e), r = w(null);
48
- l("deckGLMap", r);
49
- const u = w([]);
50
- l("deckGLPrependLayers", u);
51
- const f = k(() => [
52
- ...u.value,
53
- ...i.value
54
- ]);
55
- this.createMap(n, o.value).then((s) => {
56
- r.value = s, s.watchOptions(o, o.value.watchOptionsOptions), s.watchLayers(f, o.value.watchLayersOptions), a("loaded", s);
57
- });
58
- const p = d([]);
59
- return l("deckGLAppendVNodeFn", p), () => [v("div", { ...t, ref: n }, r.value ? c : []), p.value.map((s) => s())];
60
- },
61
- {
62
- props: {
63
- options: {
64
- type: Object,
65
- default: () => ({})
66
- },
67
- layers: {
68
- type: Array,
69
- default: () => []
70
- }
71
- },
72
- emits: ["loaded"]
73
- }
74
- );
75
- }
76
- async loadDeckGL() {
77
- if (!this.deckgl) {
78
- const { Deck: e } = await import("deck.gl");
79
- this.deckgl = { Deck: e };
80
- }
81
- }
82
- async createMap(e, a = {}) {
83
- const t = new D(), c = () => {
84
- for (const n of t.unwatchFn)
85
- n();
86
- t.unwatchFn = [], t.map && (t.map.finalize(), t.map = null);
87
- };
88
- return new Promise((n, o) => {
89
- L(async () => {
90
- await this.loadDeckGL();
91
- const i = () => {
92
- if (!e.value)
93
- throw new Error("Missing HTML element");
94
- const r = h(e, () => {
95
- e.value || (c(), r());
96
- });
97
- t.deckgl = this.deckgl, t.map = new this.deckgl.Deck({
98
- parent: e.value,
99
- ...a
100
- }), n(t);
101
- };
102
- a.onMounted ? a.onMounted(i) : i();
103
- }), M(() => {
104
- c();
105
- });
106
- });
107
- }
108
- }
109
- export {
110
- G as default
1
+ import { computed as e, defineComponent as t, h as n, onMounted as r, onUnmounted as i, provide as a, ref as o, shallowRef as s, toRefs as c, watch as l } from "vue";
2
+ var u = class {
3
+ constructor() {
4
+ this.map = null, this.watching = {
5
+ options: !1,
6
+ layers: !1
7
+ }, this.unwatchFn = [];
8
+ }
9
+ watchOptions(e, t = {}) {
10
+ if (!this.map) throw Error("map should be set");
11
+ if (this.watching.options) {
12
+ console.warn("No need to call DeckGLMap.watchOptions(). options are already being watched");
13
+ return;
14
+ }
15
+ this.watching.options = !0;
16
+ let n = l(e, () => {
17
+ this.map.setProps({ ...e.value });
18
+ }, {
19
+ immediate: !0,
20
+ deep: !0,
21
+ ...t
22
+ });
23
+ this.unwatchFn.push(n);
24
+ }
25
+ watchLayers(e, t = {}) {
26
+ if (!this.map) throw Error("map should be set");
27
+ if (this.watching.layers) {
28
+ console.warn("No need to call DeckGLMap.watchLayers(). layers are already being watched");
29
+ return;
30
+ }
31
+ this.watching.layers = !0;
32
+ let n = l(e, () => {
33
+ this.map.setProps({ layers: e.value });
34
+ }, {
35
+ immediate: !0,
36
+ ...t
37
+ });
38
+ this.unwatchFn.push(n);
39
+ }
40
+ }, d = class {
41
+ constructor() {
42
+ this.deckgl = null, this._MapComponent = null;
43
+ }
44
+ get Map() {
45
+ return this._MapComponent ??= t((t, { emit: r, attrs: i, slots: l }) => {
46
+ let u = o(null), { options: d, layers: f } = c(t), p = s(null);
47
+ a("deckGLMap", p);
48
+ let m = s([]);
49
+ a("deckGLPrependLayers", m);
50
+ let h = e(() => [...m.value, ...f.value]);
51
+ this.createMap(u, d.value).then((e) => {
52
+ p.value = e, e.watchOptions(d, d.value.watchOptionsOptions), e.watchLayers(h, d.value.watchLayersOptions), r("loaded", e);
53
+ }).catch((e) => {
54
+ e?.code !== "MAP_UNMOUNTED" && r("error", e);
55
+ });
56
+ let g = o([]);
57
+ return a("deckGLAppendVNodeFn", g), () => [n("div", {
58
+ ...i,
59
+ ref: u
60
+ }, p.value ? l : []), g.value.map((e) => e())];
61
+ }, {
62
+ props: {
63
+ options: {
64
+ type: Object,
65
+ default: () => ({})
66
+ },
67
+ layers: {
68
+ type: Array,
69
+ default: () => []
70
+ }
71
+ },
72
+ emits: ["loaded", "error"]
73
+ }), this._MapComponent;
74
+ }
75
+ async loadDeckGL() {
76
+ if (!this.deckgl) {
77
+ let { Deck: e } = await import("@deck.gl/core");
78
+ this.deckgl = { Deck: e };
79
+ }
80
+ }
81
+ async createMap(e, t = {}) {
82
+ let n = new u(), a = () => {
83
+ for (let e of n.unwatchFn) e();
84
+ n.unwatchFn = [], n.map &&= (n.map.finalize(), null);
85
+ };
86
+ return new Promise((o, s) => {
87
+ r(() => {
88
+ let r = () => {
89
+ if (!e.value) {
90
+ let e = /* @__PURE__ */ Error("Missing HTML element");
91
+ throw s(e), e;
92
+ }
93
+ let r = l(e, () => {
94
+ e.value || (a(), r());
95
+ });
96
+ n.map = new this.deckgl.Deck({
97
+ parent: e.value,
98
+ ...t
99
+ }), o(n);
100
+ };
101
+ (async () => {
102
+ await this.loadDeckGL(), t.onMounted ? t.onMounted(r) : r();
103
+ })().catch(s);
104
+ }), i(() => {
105
+ a();
106
+ let e = /* @__PURE__ */ Error("Map unmounted before load");
107
+ e.code = "MAP_UNMOUNTED", s(e);
108
+ });
109
+ });
110
+ }
111
111
  };
112
+ export { d as default };