@nookuio/iframe 0.5.0 → 0.7.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.
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * The path of the editor page which will be rendered in canvas
3
3
  */
4
- export declare const EDITOR_PAGE_PATH = "/__nooku/editor";
5
- export declare const COMPONENT_PREVIEW_PAGE_PATH = "/__nooku/component-preview";
4
+ export declare const EDITOR_PAGE_PATH = "/__nooku__/editor";
5
+ export declare const COMPONENT_PREVIEW_PAGE_PATH = "/__nooku__/component-preview";
6
+ export declare const VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = "/__nooku__/virtual-sfc-preview";
6
7
  export declare const IFRAME_SOURCE_NAME = "nooku-frame";
7
8
  export declare const EDITOR_SOURCE_NAME = "nooku-editor";
package/dist/constants.js CHANGED
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = void 0;
7
- const EDITOR_PAGE_PATH = exports.EDITOR_PAGE_PATH = `/__nooku/editor`;
8
- const COMPONENT_PREVIEW_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = `/__nooku/component-preview`;
6
+ exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.IFRAME_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = exports.EDITOR_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = void 0;
7
+ const EDITOR_PAGE_PATH = exports.EDITOR_PAGE_PATH = `/__nooku__/editor`;
8
+ const COMPONENT_PREVIEW_PAGE_PATH = exports.COMPONENT_PREVIEW_PAGE_PATH = `/__nooku__/component-preview`;
9
+ const VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = exports.VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = `/__nooku__/virtual-sfc-preview`;
9
10
  const IFRAME_SOURCE_NAME = exports.IFRAME_SOURCE_NAME = "nooku-frame";
10
11
  const EDITOR_SOURCE_NAME = exports.EDITOR_SOURCE_NAME = "nooku-editor";
@@ -1,4 +1,5 @@
1
- export const EDITOR_PAGE_PATH = `/__nooku/editor`;
2
- export const COMPONENT_PREVIEW_PAGE_PATH = `/__nooku/component-preview`;
1
+ export const EDITOR_PAGE_PATH = `/__nooku__/editor`;
2
+ export const COMPONENT_PREVIEW_PAGE_PATH = `/__nooku__/component-preview`;
3
+ export const VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH = `/__nooku__/virtual-sfc-preview`;
3
4
  export const IFRAME_SOURCE_NAME = "nooku-frame";
4
5
  export const EDITOR_SOURCE_NAME = "nooku-editor";
package/dist/editor.js CHANGED
@@ -7,6 +7,35 @@ exports.createEditorClient = createEditorClient;
7
7
  var _constants = require("./constants");
8
8
  var _createClient = require("./createClient");
9
9
  var _telejson = require("telejson");
10
+ function deserialize(data) {
11
+ const parsed = (0, _telejson.parse)(data, {
12
+ maxDepth: Infinity
13
+ });
14
+ const senitizeRefs = obj => {
15
+ if (Array.isArray(obj)) {
16
+ obj.forEach((item, index) => {
17
+ obj[index] = senitizeRefs(item);
18
+ });
19
+ } else if (obj && typeof obj === "object") {
20
+ if (obj.hasOwnProperty("__v_isRef")) {
21
+ const newObj = {
22
+ ...obj,
23
+ __v_isRef: "true",
24
+ // converted to string
25
+ value: obj.hasOwnProperty("value") && obj.value !== void 0 ? obj.value : obj._value ?? obj._rawValue
26
+ };
27
+ return newObj;
28
+ } else {
29
+ Object.keys(obj).forEach(key => {
30
+ obj[key] = senitizeRefs(obj[key]);
31
+ });
32
+ }
33
+ }
34
+ return obj;
35
+ };
36
+ const d = senitizeRefs(parsed);
37
+ return d;
38
+ }
10
39
  function createEditorClient(iframe) {
11
40
  let iframeElement;
12
41
  function getIframe() {
@@ -72,7 +101,7 @@ function createEditorClient(iframe) {
72
101
  handleRequest(event.data.request);
73
102
  });
74
103
  },
75
- deserialize: v => (0, _telejson.parse)(v),
104
+ deserialize,
76
105
  serialize: v => (0, _telejson.stringify)(v, {
77
106
  maxDepth: Infinity
78
107
  })
package/dist/editor.mjs CHANGED
@@ -1,6 +1,33 @@
1
1
  import { EDITOR_SOURCE_NAME, IFRAME_SOURCE_NAME } from "./constants.mjs";
2
2
  import { createClient } from "./createClient.mjs";
3
3
  import { stringify, parse } from "telejson";
4
+ function deserialize(data) {
5
+ const parsed = parse(data, { maxDepth: Infinity });
6
+ const senitizeRefs = (obj) => {
7
+ if (Array.isArray(obj)) {
8
+ obj.forEach((item, index) => {
9
+ obj[index] = senitizeRefs(item);
10
+ });
11
+ } else if (obj && typeof obj === "object") {
12
+ if (obj.hasOwnProperty("__v_isRef")) {
13
+ const newObj = {
14
+ ...obj,
15
+ __v_isRef: "true",
16
+ // converted to string
17
+ value: obj.hasOwnProperty("value") && obj.value !== void 0 ? obj.value : obj._value ?? obj._rawValue
18
+ };
19
+ return newObj;
20
+ } else {
21
+ Object.keys(obj).forEach((key) => {
22
+ obj[key] = senitizeRefs(obj[key]);
23
+ });
24
+ }
25
+ }
26
+ return obj;
27
+ };
28
+ const d = senitizeRefs(parsed);
29
+ return d;
30
+ }
4
31
  export function createEditorClient(iframe) {
5
32
  let iframeElement;
6
33
  function getIframe() {
@@ -60,7 +87,7 @@ export function createEditorClient(iframe) {
60
87
  handleRequest(event.data.request);
61
88
  });
62
89
  },
63
- deserialize: (v) => parse(v),
90
+ deserialize,
64
91
  serialize: (v) => stringify(v, { maxDepth: Infinity })
65
92
  }
66
93
  );
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './constants';
2
2
  export * from './types';
3
+ export * from './iframe';
4
+ export * from './editor';
package/dist/index.js CHANGED
@@ -24,4 +24,26 @@ Object.keys(_types).forEach(function (key) {
24
24
  return _types[key];
25
25
  }
26
26
  });
27
+ });
28
+ var _iframe = require("./iframe");
29
+ Object.keys(_iframe).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _iframe[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _iframe[key];
36
+ }
37
+ });
38
+ });
39
+ var _editor = require("./editor");
40
+ Object.keys(_editor).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _editor[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _editor[key];
47
+ }
48
+ });
27
49
  });
package/dist/index.mjs CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from "./constants.mjs";
2
2
  export * from "./types.mjs";
3
+ export * from "./iframe.mjs";
4
+ export * from "./editor.mjs";
package/dist/types.d.ts CHANGED
@@ -54,23 +54,25 @@ export interface CoreIframeEvents {
54
54
  }
55
55
  export interface VueIframeContext extends CoreIframeContext {
56
56
  navigateTo: (to: string) => void;
57
- getValue: (opts: {
57
+ getValue: (options: {
58
58
  code: string;
59
59
  path?: string;
60
60
  onTemplateContext?: boolean;
61
61
  context?: Record<string, any>;
62
62
  }) => any;
63
63
  getInstanceData: (path: string /** filepath path of the component */) => Record<string, any>;
64
- runCode: (opts: {
64
+ runCode: (options: {
65
65
  path?: string;
66
66
  code: string;
67
67
  onTemplateContext?: boolean;
68
68
  context?: Record<string, any>;
69
69
  }) => any;
70
- updatePreview?: (options: {
71
- path: string;
72
- code: string;
73
- }) => void;
70
+ /**
71
+ * For virtual SFC preview
72
+ *
73
+ * Works only on VIRTUAL_VUE_SFC_RENDERER_PAGE_PATH
74
+ */
75
+ updateVirtualSfcCode?: (path: string, code: string) => void;
74
76
  }
75
77
  export interface VueIframeEvents extends CoreIframeEvents {
76
78
  'route-change': (to: string) => void;
@@ -94,3 +96,27 @@ export interface ElementStyles extends ElementPosition {
94
96
  left: string;
95
97
  };
96
98
  }
99
+ export interface PageOptions {
100
+ path: string;
101
+ layout?: string | false;
102
+ injectTailwind?: boolean;
103
+ tailwindVersion?: 3 | 4;
104
+ /**
105
+ * Specifically for pages
106
+ *
107
+ * If true, the page will be rendered as a component
108
+ */
109
+ renderAsComponent?: boolean;
110
+ /**
111
+ * Page params
112
+ */
113
+ params?: Record<string, string>;
114
+ /**
115
+ * Component props
116
+ */
117
+ props?: Record<string, any>;
118
+ /**
119
+ * Specifically for virtual SFC renderer page
120
+ */
121
+ code?: string;
122
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nookuio/iframe",
3
3
  "description": "",
4
- "version": "0.5.0",
4
+ "version": "0.7.0",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "exports": {