@nookuio/iframe 0.6.0 → 0.8.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.
- package/dist/createClient.js +14 -3
- package/dist/createClient.mjs +14 -2
- package/dist/editor.js +30 -1
- package/dist/editor.mjs +28 -1
- package/dist/types.d.ts +24 -0
- package/package.json +1 -1
package/dist/createClient.js
CHANGED
|
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createClient = createClient;
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
7
|
function createClient(localCtx, options) {
|
|
10
8
|
const {
|
|
11
9
|
invoke,
|
|
@@ -31,7 +29,7 @@ function createClient(localCtx, options) {
|
|
|
31
29
|
}
|
|
32
30
|
const listenersCollection = /* @__PURE__ */new Map();
|
|
33
31
|
handle(async request => {
|
|
34
|
-
const value =
|
|
32
|
+
const value = get(localCtx, request.key);
|
|
35
33
|
if (value === void 0) return {
|
|
36
34
|
type: "response",
|
|
37
35
|
id: request.id,
|
|
@@ -125,4 +123,17 @@ function createClient(localCtx, options) {
|
|
|
125
123
|
}
|
|
126
124
|
});
|
|
127
125
|
return rootProxy;
|
|
126
|
+
}
|
|
127
|
+
function get(obj, path, defaultValue) {
|
|
128
|
+
if (!obj || typeof obj !== "object") return defaultValue;
|
|
129
|
+
const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
|
|
130
|
+
let result = obj;
|
|
131
|
+
for (const key of pathArray) {
|
|
132
|
+
if (result != null && typeof result === "object" && key in result) {
|
|
133
|
+
result = result[key];
|
|
134
|
+
} else {
|
|
135
|
+
return defaultValue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
128
139
|
}
|
package/dist/createClient.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
1
|
export function createClient(localCtx, options) {
|
|
3
2
|
const { invoke, handle, emit, handleEvent, serialize: _serialize, deserialize: _deserialize } = options;
|
|
4
3
|
function serialize(data) {
|
|
@@ -17,7 +16,7 @@ export function createClient(localCtx, options) {
|
|
|
17
16
|
}
|
|
18
17
|
const listenersCollection = /* @__PURE__ */ new Map();
|
|
19
18
|
handle(async (request) => {
|
|
20
|
-
const value =
|
|
19
|
+
const value = get(localCtx, request.key);
|
|
21
20
|
if (value === void 0)
|
|
22
21
|
return {
|
|
23
22
|
type: "response",
|
|
@@ -113,3 +112,16 @@ export function createClient(localCtx, options) {
|
|
|
113
112
|
);
|
|
114
113
|
return rootProxy;
|
|
115
114
|
}
|
|
115
|
+
function get(obj, path, defaultValue) {
|
|
116
|
+
if (!obj || typeof obj !== "object") return defaultValue;
|
|
117
|
+
const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
|
|
118
|
+
let result = obj;
|
|
119
|
+
for (const key of pathArray) {
|
|
120
|
+
if (result != null && typeof result === "object" && key in result) {
|
|
121
|
+
result = result[key];
|
|
122
|
+
} else {
|
|
123
|
+
return defaultValue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
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
|
|
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
|
|
90
|
+
deserialize,
|
|
64
91
|
serialize: (v) => stringify(v, { maxDepth: Infinity })
|
|
65
92
|
}
|
|
66
93
|
);
|
package/dist/types.d.ts
CHANGED
|
@@ -96,3 +96,27 @@ export interface ElementStyles extends ElementPosition {
|
|
|
96
96
|
left: string;
|
|
97
97
|
};
|
|
98
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
|
+
}
|