@nookuio/vue 1.0.4 → 1.0.7

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.
package/dist/index.js CHANGED
@@ -16,29 +16,28 @@ var _helpers = require("./runtime/utils/helpers");
16
16
  var _utils = require("./runtime/utils");
17
17
  var _iframe = require("@nookuio/iframe");
18
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
- function a(t, r, n) {
20
- const o = typeof t == "string" ? document.querySelector(t) : t;
21
- if (!o) {
22
- const u = typeof t == "string" ? `Failed to mount app: mount target selector "${t}" returned null.` : "Failed to mount app to the target element";
23
- console.warn(u);
19
+ function a(t, i, e, r) {
20
+ const p = typeof t == "string" ? document.querySelector(t) : t;
21
+ if (!p) {
22
+ const m = typeof t == "string" ? `Failed to mount app: mount target selector "${t}" returned null.` : "Failed to mount app to the target element";
23
+ console.warn(m);
24
24
  return;
25
25
  }
26
- const i = (0, _vue.createVNode)(r, n || {});
27
- return (0, _vue.render)(i, o), i.component;
26
+ const o = (0, _vue.h)(i, e || {});
27
+ return o.appContext = r?._context || o.appContext, (0, _vue.render)(o, p), o.component;
28
28
  }
29
29
  const g = {
30
- install(t, r) {
31
- process.env.DEV && (window === void 0 || !(0, _helpers.isInsideEditor)() || window.location.pathname === _iframe.EDITOR_PAGE_PATH && (t.mount = function (n) {
32
- t._component = {
33
- render() {
34
- return (0, _vue.h)(_vue.Suspense, {}, {
35
- default: () => (0, _vue.h)(_ComponentPreview.default),
36
- fallback: () => (0, _vue.h)("div", "Loading...")
37
- });
38
- }
39
- };
40
- const o = a(n, t._component);
41
- return (0, _utils.initializeClient)(t), o?.proxy;
30
+ install(t, i) {
31
+ process.env.DEV && (window === void 0 || !(0, _helpers.isInsideEditor)() || window.location.pathname === _iframe.EDITOR_PAGE_PATH && (t._component = {
32
+ render() {
33
+ return (0, _vue.h)(_vue.Suspense, {}, {
34
+ default: () => (0, _vue.h)(_ComponentPreview.default),
35
+ fallback: () => (0, _vue.h)("div", "Loading...")
36
+ });
37
+ }
38
+ }, t.mount = function (e) {
39
+ const r = a(e, t._component, void 0, t);
40
+ return (0, _utils.initializeClient)(t), r?.proxy;
42
41
  }));
43
42
  }
44
43
  };
package/dist/index.mjs CHANGED
@@ -1,36 +1,35 @@
1
- import { createVNode as p, h as e, render as d, Suspense as f } from "vue";
2
- import m from "./runtime/components/ComponentPreview.vue";
1
+ import { h as n, render as d, Suspense as f } from "vue";
2
+ import u from "./runtime/components/ComponentPreview.vue";
3
3
  import { isInsideEditor as l } from "./runtime/utils/helpers.mjs";
4
4
  import { initializeClient as s } from "./runtime/utils/index.mjs";
5
5
  import { EDITOR_PAGE_PATH as c } from "@nookuio/iframe";
6
- export { m as ComponentPreview };
7
- function a(t, r, n) {
8
- const o = typeof t == "string" ? document.querySelector(t) : t;
9
- if (!o) {
10
- const u = typeof t == "string" ? `Failed to mount app: mount target selector "${t}" returned null.` : "Failed to mount app to the target element";
11
- console.warn(u);
6
+ export { u as ComponentPreview };
7
+ function a(t, i, e, r) {
8
+ const p = typeof t == "string" ? document.querySelector(t) : t;
9
+ if (!p) {
10
+ const m = typeof t == "string" ? `Failed to mount app: mount target selector "${t}" returned null.` : "Failed to mount app to the target element";
11
+ console.warn(m);
12
12
  return;
13
13
  }
14
- const i = p(r, n || {});
15
- return d(i, o), i.component;
14
+ const o = n(i, e || {});
15
+ return o.appContext = r?._context || o.appContext, d(o, p), o.component;
16
16
  }
17
17
  const g = {
18
- install(t, r) {
19
- import.meta.env.DEV && (window === void 0 || !l() || window.location.pathname === c && (t.mount = function(n) {
20
- t._component = {
21
- render() {
22
- return e(
23
- f,
24
- {},
25
- {
26
- default: () => e(m),
27
- fallback: () => e("div", "Loading...")
28
- }
29
- );
30
- }
31
- };
32
- const o = a(n, t._component);
33
- return s(t), o?.proxy;
18
+ install(t, i) {
19
+ import.meta.env.DEV && (window === void 0 || !l() || window.location.pathname === c && (t._component = {
20
+ render() {
21
+ return n(
22
+ f,
23
+ {},
24
+ {
25
+ default: () => n(u),
26
+ fallback: () => n("div", "Loading...")
27
+ }
28
+ );
29
+ }
30
+ }, t.mount = function(e) {
31
+ const r = a(e, t._component, void 0, t);
32
+ return s(t), r?.proxy;
34
33
  }));
35
34
  }
36
35
  };
@@ -6,28 +6,66 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useVueComponent = useVueComponent;
7
7
  var _vue = require("vue");
8
8
  var _utils = require("../utils");
9
- function useVueComponent(r, l) {
10
- const o = (0, _vue.shallowRef)(),
11
- t = (0, _vue.shallowRef)(),
12
- e = (0, _vue.shallowRef)(!1);
13
- async function f() {
14
- e.value = !0;
15
- const [u, a] = await (0, _utils.trySafe)(() => (0, _utils.importVueComponentFromPath)(r.value, (0, _vue.toValue)(l)), 5e3);
16
- if (a) {
17
- t.value = a, o.value = null, e.value = !1;
9
+ var _helpers = require("../utils/helpers");
10
+ function g(e) {
11
+ if (import.meta.server || !e) return;
12
+ const o = (0, _helpers.debounce)(() => {
13
+ const n = (0, _helpers.getInstanceState)(e);
14
+ window.__nooku__.emit("instance-data-update", n);
15
+ }, 500);
16
+ window.__nooku__ = {
17
+ ...(window.__nooku__ || {}),
18
+ getInstanceData: () => (0, _helpers.getInstanceState)(e)
19
+ };
20
+ let t;
21
+ return e.asyncDep && typeof e.asyncDep.then == "function" ? e.asyncDep.then(n => {
22
+ t = (0, _vue.watch)([() => n, () => e.devtoolsRawSetupState], o, {
23
+ deep: !0,
24
+ immediate: !0
25
+ });
26
+ }) : t = (0, _vue.watch)(() => e.devtoolsRawSetupState, o, {
27
+ deep: !0,
28
+ immediate: !0
29
+ }), () => t?.();
30
+ }
31
+ function useVueComponent(e, o) {
32
+ const t = (0, _vue.shallowRef)(),
33
+ n = (0, _vue.shallowRef)(),
34
+ r = (0, _vue.shallowRef)(!1);
35
+ async function s() {
36
+ r.value = !0;
37
+ const [i, d] = await (0, _utils.trySafe)(() => (0, _utils.importVueComponentFromPath)(e.value, (0, _vue.toValue)(o)), 5e3);
38
+ if (d) {
39
+ n.value = d, t.value = null, r.value = !1;
18
40
  return;
19
41
  }
20
- if (!u) {
21
- t.value = new Error(`Failed to load component from path: ${r}`), o.value = null, e.value = !1;
42
+ if (!i) {
43
+ n.value = new Error(`Failed to load component from path: ${e}`), t.value = null, r.value = !1;
22
44
  return;
23
45
  }
24
- t.value = null, o.value = u, e.value = !1;
46
+ n.value = null, t.value = (0, _vue.defineComponent)({
47
+ name: "NookuEditorPreview",
48
+ setup(c, {
49
+ attrs: v,
50
+ slots: y
51
+ }) {
52
+ const f = (0, _vue.shallowRef)(null);
53
+ let p;
54
+ return (0, _vue.watch)(f, l => {
55
+ p?.(), l && (p = g(l.$ || l));
56
+ }), () => (0, _vue.h)(i, {
57
+ ref: f,
58
+ ...v,
59
+ ...c
60
+ }, y);
61
+ }
62
+ }), r.value = !1;
25
63
  }
26
- return (0, _vue.watch)([() => r.value, l], f, {
64
+ return (0, _vue.watch)([() => e.value, o], s, {
27
65
  immediate: !0
28
66
  }), {
29
- component: o,
30
- error: t,
31
- isLoading: e
67
+ component: t,
68
+ error: n,
69
+ isLoading: r
32
70
  };
33
71
  }
@@ -1,23 +1,54 @@
1
- import { watch as m, shallowRef as n, toValue as i } from "vue";
2
- import { trySafe as s, importVueComponentFromPath as p } from "../utils/index.mjs";
3
- export function useVueComponent(r, l) {
4
- const o = n(), t = n(), e = n(!1);
5
- async function f() {
6
- e.value = !0;
7
- const [u, a] = await s(() => p(r.value, i(l)), 5e3);
8
- if (a) {
9
- t.value = a, o.value = null, e.value = !1;
1
+ import { watch as u, shallowRef as a, toValue as _, defineComponent as w, h } from "vue";
2
+ import { trySafe as C, importVueComponentFromPath as R } from "../utils/index.mjs";
3
+ import { debounce as S, getInstanceState as m } from "../utils/helpers.mjs";
4
+ function g(e) {
5
+ if (import.meta.server || !e) return;
6
+ const o = S(() => {
7
+ const n = m(e);
8
+ window.__nooku__.emit("instance-data-update", n);
9
+ }, 500);
10
+ window.__nooku__ = {
11
+ ...window.__nooku__ || {},
12
+ getInstanceData: () => m(e)
13
+ };
14
+ let t;
15
+ return e.asyncDep && typeof e.asyncDep.then == "function" ? e.asyncDep.then((n) => {
16
+ t = u([() => n, () => e.devtoolsRawSetupState], o, {
17
+ deep: !0,
18
+ immediate: !0
19
+ });
20
+ }) : t = u(() => e.devtoolsRawSetupState, o, {
21
+ deep: !0,
22
+ immediate: !0
23
+ }), () => t?.();
24
+ }
25
+ export function useVueComponent(e, o) {
26
+ const t = a(), n = a(), r = a(!1);
27
+ async function s() {
28
+ r.value = !0;
29
+ const [i, d] = await C(() => R(e.value, _(o)), 5e3);
30
+ if (d) {
31
+ n.value = d, t.value = null, r.value = !1;
10
32
  return;
11
33
  }
12
- if (!u) {
13
- t.value = new Error(`Failed to load component from path: ${r}`), o.value = null, e.value = !1;
34
+ if (!i) {
35
+ n.value = new Error(`Failed to load component from path: ${e}`), t.value = null, r.value = !1;
14
36
  return;
15
37
  }
16
- t.value = null, o.value = u, e.value = !1;
38
+ n.value = null, t.value = w({
39
+ name: "NookuEditorPreview",
40
+ setup(c, { attrs: v, slots: y }) {
41
+ const f = a(null);
42
+ let p;
43
+ return u(f, (l) => {
44
+ p?.(), l && (p = g(l.$ || l));
45
+ }), () => h(i, { ref: f, ...v, ...c }, y);
46
+ }
47
+ }), r.value = !1;
17
48
  }
18
- return m([() => r.value, l], f, { immediate: !0 }), {
19
- component: o,
20
- error: t,
21
- isLoading: e
49
+ return u([() => e.value, o], s, { immediate: !0 }), {
50
+ component: t,
51
+ error: n,
52
+ isLoading: r
22
53
  };
23
54
  }
@@ -2,4 +2,6 @@ import type { App } from 'vue';
2
2
  /**
3
3
  * Initialize the communication between the editor and the iframe
4
4
  */
5
- export declare function initializeClient(app: App): any;
5
+ export declare function initializeClient(app: App, { navigateTo: customNavigateTo }?: {
6
+ navigateTo?: (url: string) => void;
7
+ }): any;
@@ -4,58 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.initializeClient = initializeClient;
7
- var _vue = require("vue");
8
- var _helpers = require("./helpers");
9
7
  var _iframe = require("@nookuio/iframe/iframe");
10
- var _useQuery = require("../composables/useQuery");
11
- const d = new Map();
12
- function initializeClient(t) {
13
- const i = (0, _useQuery.getQuery)(),
14
- o = (0, _vue.computed)(() => i.path || ""),
15
- r = (0, _iframe.createVueIframeClient)({
16
- getInstanceData(e) {
17
- const n = d.get(e);
18
- return n ? (0, _helpers.getInstanceState)(n) : {};
19
- },
20
- navigateTo(e) {
21
- e && e && I(e);
22
- },
23
- updateCode(e, n) {}
24
- }, {
25
- disableDefaultConsole: !1
26
- });
27
- return t.config.errorHandler = e => {
28
- r.emit("console", "error", [e?.stack]);
29
- }, t.mixin({
30
- created() {
31
- const e = this.$options.__file?.replace(/\\/g, "/") || "";
32
- if (!e || e.includes("node_modules")) return;
33
- const n = (0, _vue.computed)(() => o.value === e),
34
- s = this.$;
35
- d.set(e, s);
36
- let a;
37
- async function f() {
38
- const c = (0, _helpers.getInstanceState)(s);
39
- r?.emit("instance-data-update", c);
40
- }
41
- const m = (0, _helpers.debounce)(() => f(), 500);
42
- (0, _vue.watch)(n, c => {
43
- c ? a = (0, _vue.watch)(() => s.devtoolsRawSetupState, m, {
44
- deep: !0,
45
- immediate: !0
46
- }) : a && (a?.(), a = void 0);
47
- }, {
48
- immediate: !0
49
- });
8
+ function initializeClient(i, {
9
+ navigateTo: n
10
+ } = {}) {
11
+ const t = (0, _iframe.createVueIframeClient)({
12
+ getInstanceData() {
13
+ return window?.__nooku__?.getInstanceData() || {};
50
14
  },
51
- beforeUnmount() {
52
- const e = this.$options.__file?.replace(/\\/g, "/") || "";
53
- !e || e.includes("node_modules") || o.value !== e && d.delete(e);
54
- }
55
- }), r;
15
+ navigateTo(e) {
16
+ e && (n && typeof n == "function" ? n(e) : r(e));
17
+ },
18
+ updateCode() {}
19
+ }, {
20
+ disableDefaultConsole: !1
21
+ });
22
+ return i.config.errorHandler = e => {
23
+ t.emit("console", "error", [e?.stack]);
24
+ }, window.__nooku__ = {
25
+ ...(window.__nooku__ || {}),
26
+ emit: (e, ...a) => t.emit(e, ...a)
27
+ }, t;
56
28
  }
57
- function I(t, i = {}) {
58
- return new Promise(o => {
59
- i.replace ? history.replaceState({}, "", t) : history.pushState({}, "", t), window.dispatchEvent(new Event("popstate")), o();
29
+ function r(i, n = {}) {
30
+ return new Promise(t => {
31
+ n.replace ? history.replaceState({}, "", i) : history.pushState({}, "", i), window.dispatchEvent(new Event("popstate")), t();
60
32
  });
61
33
  }
@@ -1,56 +1,29 @@
1
- import { computed as u, watch as l } from "vue";
2
- import { debounce as h, getInstanceState as p } from "./helpers.mjs";
3
- import { createVueIframeClient as g } from "@nookuio/iframe/iframe";
4
- import { getQuery as v } from "../composables/useQuery.mjs";
5
- const d = /* @__PURE__ */ new Map();
6
- export function initializeClient(t) {
7
- const i = v(), o = u(() => i.path || ""), r = g(
1
+ import { createVueIframeClient as o } from "@nookuio/iframe/iframe";
2
+ export function initializeClient(i, {
3
+ navigateTo: n
4
+ } = {}) {
5
+ const t = o(
8
6
  {
9
- getInstanceData(e) {
10
- const n = d.get(e);
11
- return n ? p(n) : {};
7
+ getInstanceData() {
8
+ return window?.__nooku__?.getInstanceData() || {};
12
9
  },
13
10
  navigateTo(e) {
14
- e && e && I(e);
11
+ e && (n && typeof n == "function" ? n(e) : r(e));
15
12
  },
16
- updateCode(e, n) {
13
+ updateCode() {
17
14
  }
18
15
  },
19
16
  { disableDefaultConsole: !1 }
20
17
  );
21
- return t.config.errorHandler = (e) => {
22
- r.emit("console", "error", [e?.stack]);
23
- }, t.mixin({
24
- created() {
25
- const e = this.$options.__file?.replace(/\\/g, "/") || "";
26
- if (!e || e.includes("node_modules")) return;
27
- const n = u(() => o.value === e), s = this.$;
28
- d.set(e, s);
29
- let a;
30
- async function f() {
31
- const c = p(s);
32
- r?.emit("instance-data-update", c);
33
- }
34
- const m = h(() => f(), 500);
35
- l(
36
- n,
37
- (c) => {
38
- c ? a = l(() => s.devtoolsRawSetupState, m, {
39
- deep: !0,
40
- immediate: !0
41
- }) : a && (a?.(), a = void 0);
42
- },
43
- { immediate: !0 }
44
- );
45
- },
46
- beforeUnmount() {
47
- const e = this.$options.__file?.replace(/\\/g, "/") || "";
48
- !e || e.includes("node_modules") || o.value !== e && d.delete(e);
49
- }
50
- }), r;
18
+ return i.config.errorHandler = (e) => {
19
+ t.emit("console", "error", [e?.stack]);
20
+ }, window.__nooku__ = {
21
+ ...window.__nooku__ || {},
22
+ emit: (e, ...a) => t.emit(e, ...a)
23
+ }, t;
51
24
  }
52
- function I(t, i = {}) {
53
- return new Promise((o) => {
54
- i.replace ? history.replaceState({}, "", t) : history.pushState({}, "", t), window.dispatchEvent(new Event("popstate")), o();
25
+ function r(i, n = {}) {
26
+ return new Promise((t) => {
27
+ n.replace ? history.replaceState({}, "", i) : history.pushState({}, "", i), window.dispatchEvent(new Event("popstate")), t();
55
28
  });
56
29
  }
@@ -1,4 +1,4 @@
1
1
  import type { ComponentInternalInstance } from 'vue';
2
2
  export declare function isInsideEditor(): boolean;
3
3
  export declare function debounce(cb: Function, delay?: number): (...args: any[]) => void;
4
- export declare function getInstanceState(instance: ComponentInternalInstance | undefined, onTemplate?: boolean): Record<string, any>;
4
+ export declare function getInstanceState(instance: ComponentInternalInstance | undefined, unwrapRefs?: boolean): Record<string, any>;
@@ -7,7 +7,7 @@ exports.debounce = debounce;
7
7
  exports.getInstanceState = getInstanceState;
8
8
  exports.isInsideEditor = isInsideEditor;
9
9
  function isInsideEditor() {
10
- return !import.meta.client || window === void 0 ? !1 : !!(window.parent && window.location !== window.parent.location || window.top !== window.self);
10
+ return import.meta.server || window === void 0 ? !1 : !!(window.parent && window.location !== window.parent.location || window.top !== window.self);
11
11
  }
12
12
  function debounce(e, t = 500) {
13
13
  let n;
@@ -29,9 +29,9 @@ function s(e, t) {
29
29
  function getInstanceState(e, t) {
30
30
  if (!e) return {};
31
31
  const n = {};
32
- return Object.entries(e.props).forEach(([o, r]) => {
32
+ return Object.entries(e.props || {}).forEach(([o, r]) => {
33
33
  n[o] = r;
34
- }), Object.entries(e.devtoolsRawSetupState ?? e.setupState).forEach(([o, r]) => {
34
+ }), Object.entries(e.devtoolsRawSetupState ?? e.setupState ?? {}).forEach(([o, r]) => {
35
35
  const a = s(r, t);
36
36
  n[o] = a;
37
37
  }), n;
@@ -1,5 +1,5 @@
1
1
  export function isInsideEditor() {
2
- return !import.meta.client || window === void 0 ? !1 : !!(window.parent && window.location !== window.parent.location || window.top !== window.self);
2
+ return import.meta.server || window === void 0 ? !1 : !!(window.parent && window.location !== window.parent.location || window.top !== window.self);
3
3
  }
4
4
  export function debounce(e, t = 500) {
5
5
  let n;
@@ -21,9 +21,9 @@ function s(e, t) {
21
21
  export function getInstanceState(e, t) {
22
22
  if (!e) return {};
23
23
  const n = {};
24
- return Object.entries(e.props).forEach(([o, r]) => {
24
+ return Object.entries(e.props || {}).forEach(([o, r]) => {
25
25
  n[o] = r;
26
- }), Object.entries(e.devtoolsRawSetupState ?? e.setupState).forEach(([o, r]) => {
26
+ }), Object.entries(e.devtoolsRawSetupState ?? e.setupState ?? {}).forEach(([o, r]) => {
27
27
  const a = s(r, t);
28
28
  n[o] = a;
29
29
  }), n;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nookuio/vue",
3
3
  "description": "",
4
- "version": "1.0.4",
4
+ "version": "1.0.7",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "exports": {