@nookuio/iframe 0.9.9 → 1.0.0-beta.1
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/drag-drop/dragDropManager.d.ts +101 -0
- package/dist/drag-drop/dragDropManager.js +204 -0
- package/dist/drag-drop/dragDropManager.mjs +183 -0
- package/dist/drag-drop/index.d.ts +3 -0
- package/dist/drag-drop/index.js +38 -0
- package/dist/drag-drop/index.mjs +3 -0
- package/dist/drag-drop/types.d.ts +80 -0
- package/dist/drag-drop/types.js +1 -0
- package/dist/drag-drop/types.mjs +0 -0
- package/dist/drag-drop/utils.d.ts +41 -0
- package/dist/drag-drop/utils.js +93 -0
- package/dist/drag-drop/utils.mjs +68 -0
- package/dist/editor.d.ts +1 -7
- package/dist/editor.js +2 -2
- package/dist/editor.mjs +1 -1
- package/dist/iframe.d.ts +2 -8
- package/dist/iframe.js +90 -64
- package/dist/iframe.mjs +93 -66
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/index.mjs +1 -0
- package/dist/types.d.ts +67 -3
- package/package.json +4 -3
- package/dist/createClient.d.ts +0 -51
- package/dist/createClient.js +0 -118
- package/dist/createClient.mjs +0 -114
package/dist/iframe.mjs
CHANGED
|
@@ -1,78 +1,88 @@
|
|
|
1
|
-
import { EDITOR_SOURCE_NAME as
|
|
2
|
-
import { createClient as C } from "
|
|
3
|
-
import { stringify as
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { EDITOR_SOURCE_NAME as b, IFRAME_SOURCE_NAME as w } from "./constants.mjs";
|
|
2
|
+
import { createClient as C } from "@nookuio/rpc";
|
|
3
|
+
import { stringify as D, parse as v } from "telejson";
|
|
4
|
+
import { DragDropManager as L } from "./drag-drop/dragDropManager.mjs";
|
|
5
|
+
function p(m, l) {
|
|
6
|
+
return `[data-node-id="${l}"][data-node-path="${m}"]`;
|
|
6
7
|
}
|
|
7
|
-
function h(
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
width:
|
|
13
|
-
height:
|
|
14
|
-
top:
|
|
15
|
-
left:
|
|
8
|
+
function h(m, l) {
|
|
9
|
+
const d = document.querySelectorAll(m);
|
|
10
|
+
if (!d?.length) return;
|
|
11
|
+
const r = Array.from(d).map((f) => {
|
|
12
|
+
const c = f.getBoundingClientRect(), g = {
|
|
13
|
+
width: c.width,
|
|
14
|
+
height: c.height,
|
|
15
|
+
top: c.top,
|
|
16
|
+
left: c.left
|
|
16
17
|
};
|
|
17
18
|
if (!l) return g;
|
|
18
|
-
const
|
|
19
|
+
const u = window.getComputedStyle(f) ?? {};
|
|
19
20
|
return {
|
|
20
21
|
...g,
|
|
21
22
|
padding: {
|
|
22
|
-
top:
|
|
23
|
-
right:
|
|
24
|
-
bottom:
|
|
25
|
-
left:
|
|
23
|
+
top: u.paddingTop,
|
|
24
|
+
right: u.paddingRight,
|
|
25
|
+
bottom: u.paddingBottom,
|
|
26
|
+
left: u.paddingLeft
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
});
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
30
|
+
if (r?.length)
|
|
31
|
+
return r.length === 1 ? r[0] : r;
|
|
31
32
|
}
|
|
32
|
-
export function createVueIframeClient(
|
|
33
|
-
const
|
|
33
|
+
export function createVueIframeClient(m, l) {
|
|
34
|
+
const d = new L();
|
|
35
|
+
d.setCallbacks({
|
|
36
|
+
onDragStart: (e) => {
|
|
37
|
+
r.emit("drag-start", e);
|
|
38
|
+
},
|
|
39
|
+
onDragEnd: (e) => {
|
|
40
|
+
r.emit("drag-end", e);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const r = C(
|
|
34
44
|
{
|
|
35
|
-
...
|
|
45
|
+
...m,
|
|
36
46
|
async editText({ path: e, id: t }) {
|
|
37
47
|
if (!e || t === void 0) return;
|
|
38
|
-
const
|
|
48
|
+
const a = p(e, t), n = document.querySelector(a);
|
|
39
49
|
if (!n) return;
|
|
40
50
|
n.style.outline = "none", n.setAttribute("spellcheck", "false"), n.setAttribute("contenteditable", "true");
|
|
41
|
-
const o = (
|
|
42
|
-
const E =
|
|
51
|
+
const o = (i) => {
|
|
52
|
+
const E = i.target;
|
|
43
53
|
if (!E) return;
|
|
44
54
|
const y = E.innerText;
|
|
45
|
-
n.removeAttribute("contenteditable"),
|
|
46
|
-
},
|
|
47
|
-
|
|
55
|
+
n.removeAttribute("contenteditable"), r.emit("text-update", { path: e, id: t, content: y }), n.removeEventListener("blur", o), n.removeEventListener("keydown", s), n.blur();
|
|
56
|
+
}, s = (i) => {
|
|
57
|
+
i.key === "Enter" && (i.stopPropagation(), i.preventDefault(), o(i));
|
|
48
58
|
};
|
|
49
|
-
n.addEventListener("keydown",
|
|
59
|
+
n.addEventListener("keydown", s), n.addEventListener("blur", o), n.focus();
|
|
50
60
|
},
|
|
51
|
-
async getHoveredElement({ path: e, id: t, x:
|
|
61
|
+
async getHoveredElement({ path: e, id: t, x: a, y: n }) {
|
|
52
62
|
if (e)
|
|
53
|
-
if (
|
|
54
|
-
let o = document.elementFromPoint(
|
|
63
|
+
if (a !== void 0 && n !== void 0) {
|
|
64
|
+
let o = document.elementFromPoint(a, n);
|
|
55
65
|
if (!o) return;
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
66
|
+
let s = o.getAttribute("data-node-path");
|
|
67
|
+
if (s !== e) {
|
|
58
68
|
if (!o.parentElement) return;
|
|
59
|
-
for (; o.parentElement &&
|
|
60
|
-
o = o.parentElement,
|
|
69
|
+
for (; o.parentElement && s !== e; )
|
|
70
|
+
o = o.parentElement, s = o.getAttribute("data-node-path");
|
|
61
71
|
}
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const E =
|
|
72
|
+
const i = o.getAttribute("data-node-id");
|
|
73
|
+
if (!i) return;
|
|
74
|
+
const E = p(e, i), y = h(E, !1);
|
|
65
75
|
return y ? {
|
|
66
|
-
id:
|
|
76
|
+
id: i,
|
|
67
77
|
path: e,
|
|
68
78
|
data: y
|
|
69
79
|
} : void 0;
|
|
70
80
|
} else {
|
|
71
|
-
const o =
|
|
72
|
-
return
|
|
81
|
+
const o = p(e, t), s = h(o, !1);
|
|
82
|
+
return s ? {
|
|
73
83
|
id: t,
|
|
74
84
|
path: e,
|
|
75
|
-
data:
|
|
85
|
+
data: s
|
|
76
86
|
} : void 0;
|
|
77
87
|
}
|
|
78
88
|
},
|
|
@@ -80,7 +90,7 @@ export function createVueIframeClient(c, l) {
|
|
|
80
90
|
return document.body.scrollHeight > 0 ? document.body.scrollHeight : document.documentElement.scrollHeight;
|
|
81
91
|
},
|
|
82
92
|
async getSelectedElement({ path: e, id: t }) {
|
|
83
|
-
const
|
|
93
|
+
const a = p(e, t), n = h(a, !0);
|
|
84
94
|
if (n)
|
|
85
95
|
return {
|
|
86
96
|
path: e,
|
|
@@ -88,8 +98,25 @@ export function createVueIframeClient(c, l) {
|
|
|
88
98
|
data: n
|
|
89
99
|
};
|
|
90
100
|
},
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
setTheme(e) {
|
|
102
|
+
const t = document.querySelector("body");
|
|
103
|
+
e === "dark" ? (document.documentElement.classList.remove("light"), document.documentElement.classList.add("dark"), t && (t.classList.remove("light"), t.classList.add("dark"))) : (document.documentElement.classList.remove("dark"), document.documentElement.classList.add("light"), t && (t.classList.remove("dark"), t.classList.add("light")));
|
|
104
|
+
},
|
|
105
|
+
// Drag and drop methods
|
|
106
|
+
async startDrag(e) {
|
|
107
|
+
return d.startDrag(e);
|
|
108
|
+
},
|
|
109
|
+
async updateDragPosition(e) {
|
|
110
|
+
return d.updateDragPosition(e);
|
|
111
|
+
},
|
|
112
|
+
async endDrag(e) {
|
|
113
|
+
return d.endDrag(e);
|
|
114
|
+
},
|
|
115
|
+
async getDropZones(e) {
|
|
116
|
+
return d.getDropZones(e);
|
|
117
|
+
},
|
|
118
|
+
async highlightDropZone(e) {
|
|
119
|
+
return d.highlightDropZone(e);
|
|
93
120
|
}
|
|
94
121
|
// updateElementClass({ className, id, path }) {
|
|
95
122
|
// const selector = getSelector(path, id);
|
|
@@ -117,18 +144,18 @@ export function createVueIframeClient(c, l) {
|
|
|
117
144
|
{
|
|
118
145
|
handle(e) {
|
|
119
146
|
window.addEventListener("message", async (t) => {
|
|
120
|
-
if (typeof t.data != "object" || t.data.source !==
|
|
121
|
-
const
|
|
122
|
-
window.parent.postMessage({ source: w, response:
|
|
147
|
+
if (typeof t.data != "object" || t.data.source !== b || t.data.type === "event" || !t.data.request) return;
|
|
148
|
+
const a = await e(t.data.request);
|
|
149
|
+
window.parent.postMessage({ source: w, response: a }, "*");
|
|
123
150
|
});
|
|
124
151
|
},
|
|
125
152
|
invoke(e) {
|
|
126
|
-
return new Promise((t,
|
|
153
|
+
return new Promise((t, a) => {
|
|
127
154
|
const n = setTimeout(() => {
|
|
128
|
-
window.removeEventListener("message", o),
|
|
155
|
+
window.removeEventListener("message", o), a(new Error("Request timed out"));
|
|
129
156
|
}, 5e3);
|
|
130
|
-
function o(
|
|
131
|
-
typeof
|
|
157
|
+
function o(s) {
|
|
158
|
+
typeof s.data == "object" && (s.data.source !== b || !s.data.response || s.data.response.id === e.id && (clearTimeout(n), window.removeEventListener("message", o), t(s.data.response)));
|
|
132
159
|
}
|
|
133
160
|
window.parent.postMessage({ source: w, request: e }, "*"), window.addEventListener("message", o);
|
|
134
161
|
});
|
|
@@ -138,23 +165,23 @@ export function createVueIframeClient(c, l) {
|
|
|
138
165
|
},
|
|
139
166
|
handleEvent(e) {
|
|
140
167
|
window.addEventListener("message", (t) => {
|
|
141
|
-
typeof t.data == "object" && (t.data.source !==
|
|
168
|
+
typeof t.data == "object" && (t.data.source !== b || t.data.type !== "event" || !t.data.request || e(t.data.request));
|
|
142
169
|
});
|
|
143
170
|
},
|
|
144
|
-
deserialize: (e) =>
|
|
145
|
-
serialize: (e) =>
|
|
171
|
+
deserialize: (e) => v(e),
|
|
172
|
+
serialize: (e) => D(e, { maxDepth: 1 / 0 })
|
|
146
173
|
}
|
|
147
|
-
),
|
|
174
|
+
), f = l?.disableDefaultConsole ? void 0 : console.log.bind(console), c = l?.disableDefaultConsole ? void 0 : console.warn.bind(console), g = l?.disableDefaultConsole ? void 0 : console.error.bind(console), u = l?.disableDefaultConsole ? void 0 : console.info.bind(console);
|
|
148
175
|
return console.log = (...e) => {
|
|
149
|
-
|
|
176
|
+
r.emit("console", "log", e), f?.(...e);
|
|
150
177
|
}, console.warn = (...e) => {
|
|
151
|
-
|
|
178
|
+
c?.(...e);
|
|
152
179
|
}, console.error = (...e) => {
|
|
153
|
-
|
|
180
|
+
r.emit("console", "error", e), g?.(...e);
|
|
154
181
|
}, console.info = (...e) => {
|
|
155
|
-
|
|
156
|
-
}, window.addEventListener("resize", async () =>
|
|
157
|
-
async () =>
|
|
182
|
+
r.emit("console", "info", e), u?.(...e);
|
|
183
|
+
}, window.addEventListener("resize", async () => r.emit("resize", await r.$context.getPageHeight())), new MutationObserver(
|
|
184
|
+
async () => r.emit("resize", await r.$context.getPageHeight())
|
|
158
185
|
).observe(document.body, {
|
|
159
186
|
childList: !0,
|
|
160
187
|
// observe direct children additions/removals
|
|
@@ -164,5 +191,5 @@ export function createVueIframeClient(c, l) {
|
|
|
164
191
|
// observe attribute changes (like style, class)
|
|
165
192
|
characterData: !0
|
|
166
193
|
// observe text changes
|
|
167
|
-
}),
|
|
194
|
+
}), r.emit("ready"), r;
|
|
168
195
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -46,4 +46,15 @@ Object.keys(_editor).forEach(function (key) {
|
|
|
46
46
|
return _editor[key];
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
+
});
|
|
50
|
+
var _dragDrop = require("./drag-drop");
|
|
51
|
+
Object.keys(_dragDrop).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _dragDrop[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _dragDrop[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
49
60
|
});
|
package/dist/index.mjs
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RpcEvents } from '@nookuio/rpc';
|
|
1
2
|
export interface EventRequest {
|
|
2
3
|
eventName: string;
|
|
3
4
|
args: any[];
|
|
@@ -16,7 +17,7 @@ export interface ContextResponse {
|
|
|
16
17
|
result: any;
|
|
17
18
|
}
|
|
18
19
|
export interface CoreIframeContext {
|
|
19
|
-
|
|
20
|
+
setTheme: (theme: 'dark' | 'light') => void;
|
|
20
21
|
getHoveredElement: (options: {
|
|
21
22
|
path: string;
|
|
22
23
|
id?: string;
|
|
@@ -40,8 +41,49 @@ export interface CoreIframeContext {
|
|
|
40
41
|
path: string;
|
|
41
42
|
id: string;
|
|
42
43
|
}) => void;
|
|
44
|
+
startDrag: (options: {
|
|
45
|
+
elementId: string;
|
|
46
|
+
path: string;
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}) => Promise<{
|
|
50
|
+
dragId: string;
|
|
51
|
+
}>;
|
|
52
|
+
updateDragPosition: (options: {
|
|
53
|
+
dragId: string;
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
endDrag: (options: {
|
|
58
|
+
dragId: string;
|
|
59
|
+
canceled?: boolean;
|
|
60
|
+
}) => Promise<{
|
|
61
|
+
dropped: boolean;
|
|
62
|
+
targetId?: string;
|
|
63
|
+
targetPath?: string;
|
|
64
|
+
insertIndex?: number;
|
|
65
|
+
}>;
|
|
66
|
+
getDropZones: (options: {
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
}) => Promise<Array<{
|
|
70
|
+
elementId: string;
|
|
71
|
+
path: string;
|
|
72
|
+
rect: {
|
|
73
|
+
top: number;
|
|
74
|
+
left: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
};
|
|
78
|
+
canDrop: boolean;
|
|
79
|
+
}>>;
|
|
80
|
+
highlightDropZone: (options: {
|
|
81
|
+
elementId?: string;
|
|
82
|
+
path?: string;
|
|
83
|
+
clear?: boolean;
|
|
84
|
+
}) => Promise<void>;
|
|
43
85
|
}
|
|
44
|
-
export interface CoreIframeEvents {
|
|
86
|
+
export interface CoreIframeEvents extends RpcEvents {
|
|
45
87
|
ready: () => void;
|
|
46
88
|
resize: (height: number) => void;
|
|
47
89
|
console: (type: 'log' | 'error' | 'info' | 'warn', message: any[]) => void;
|
|
@@ -50,10 +92,32 @@ export interface CoreIframeEvents {
|
|
|
50
92
|
id: string;
|
|
51
93
|
content: string;
|
|
52
94
|
}) => void;
|
|
95
|
+
'drag-start': (data: {
|
|
96
|
+
elementId: string;
|
|
97
|
+
path: string;
|
|
98
|
+
}) => void;
|
|
99
|
+
'drag-end': (data: {
|
|
100
|
+
dropped: boolean;
|
|
101
|
+
targetId?: string;
|
|
102
|
+
targetPath?: string;
|
|
103
|
+
insertIndex?: number;
|
|
104
|
+
}) => void;
|
|
53
105
|
}
|
|
54
106
|
export interface VueIframeContext extends CoreIframeContext {
|
|
55
107
|
navigateTo: (to: string) => void;
|
|
108
|
+
getValue: (options: {
|
|
109
|
+
code: string;
|
|
110
|
+
path?: string;
|
|
111
|
+
onTemplateContext?: boolean;
|
|
112
|
+
context?: Record<string, any>;
|
|
113
|
+
}) => any;
|
|
56
114
|
getInstanceData: (path: string /** filepath path of the component */) => Record<string, any>;
|
|
115
|
+
runCode: (options: {
|
|
116
|
+
path?: string;
|
|
117
|
+
code: string;
|
|
118
|
+
onTemplateContext?: boolean;
|
|
119
|
+
context?: Record<string, any>;
|
|
120
|
+
}) => any;
|
|
57
121
|
/**
|
|
58
122
|
* For virtual SFC preview
|
|
59
123
|
*
|
|
@@ -67,7 +131,7 @@ export interface VueIframeEvents extends CoreIframeEvents {
|
|
|
67
131
|
}
|
|
68
132
|
export interface EditorContext {
|
|
69
133
|
}
|
|
70
|
-
export interface EditorEvents {
|
|
134
|
+
export interface EditorEvents extends RpcEvents {
|
|
71
135
|
}
|
|
72
136
|
export interface ElementPosition {
|
|
73
137
|
top: number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nookuio/iframe",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"exports": {
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"telejson": "7.2.0"
|
|
33
|
+
"telejson": "7.2.0",
|
|
34
|
+
"@nookuio/rpc": "1.0.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {},
|
|
36
37
|
"keywords": [],
|
|
@@ -38,6 +39,6 @@
|
|
|
38
39
|
"license": "ISC",
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "unbuild",
|
|
41
|
-
"release": "pnpm publish --no-git-checks --access public"
|
|
42
|
+
"release": "pnpm build && pnpm publish --no-git-checks --access public"
|
|
42
43
|
}
|
|
43
44
|
}
|
package/dist/createClient.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ContextRequest, ContextResponse, EventRequest } from './types';
|
|
2
|
-
type ArgumentsType<T> = T extends (...args: infer A) => any ? A : never;
|
|
3
|
-
type ClientReturnBase<R, L, RE, LE> = {
|
|
4
|
-
[K in keyof R]: R[K] extends (...args: any[]) => any ? (...args: Parameters<R[K]>) => Promise<Awaited<ReturnType<R[K]>>> : R[K] extends any[] ? Promise<R[K]> : R[K] extends object ? ClientReturnBase<R[K], L, RE, LE> : Promise<R[K]>;
|
|
5
|
-
};
|
|
6
|
-
type ClientReturn<R, L, RE, LE> = ClientReturnBase<R, L, RE, LE> & {
|
|
7
|
-
$context: L;
|
|
8
|
-
on: <E extends keyof RE>(eventName: E, listener: (...args: ArgumentsType<RE[E]>) => void) => void;
|
|
9
|
-
off: <E extends keyof RE>(eventName: E, listener: (...args: ArgumentsType<RE[E]>) => void) => void;
|
|
10
|
-
emit: <E extends keyof LE>(eventName: E, ...args: ArgumentsType<LE[E]>) => void;
|
|
11
|
-
removeAllListeners: () => void;
|
|
12
|
-
};
|
|
13
|
-
interface ClientOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Function to send requests to the remote process
|
|
16
|
-
*
|
|
17
|
-
* Should return a ContextResponse
|
|
18
|
-
*/
|
|
19
|
-
invoke: (request: ContextRequest) => Promise<ContextResponse>;
|
|
20
|
-
/**
|
|
21
|
-
* Function to handle incoming requests from the remote process
|
|
22
|
-
*
|
|
23
|
-
* Will be called only once at the start of the client
|
|
24
|
-
*/
|
|
25
|
-
handle: (handler: (request: ContextRequest) => Promise<ContextResponse>) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Function to emit events to the remote process
|
|
28
|
-
*/
|
|
29
|
-
emit: (request: EventRequest) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Function to handle events from the remote process
|
|
32
|
-
*
|
|
33
|
-
* Will be called only once at the start of the client
|
|
34
|
-
*/
|
|
35
|
-
handleEvent: (handleRequest: (request: EventRequest) => void) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Custom function to serialize data
|
|
38
|
-
*
|
|
39
|
-
* by default it uses JSON.stringify
|
|
40
|
-
*/
|
|
41
|
-
serialize?: (data: any) => any;
|
|
42
|
-
/**
|
|
43
|
-
* Custom function to deserialize data
|
|
44
|
-
*
|
|
45
|
-
* by default it uses JSON.parse
|
|
46
|
-
*/
|
|
47
|
-
deserialize?: (data: any) => any;
|
|
48
|
-
}
|
|
49
|
-
type Context = Record<string, any>;
|
|
50
|
-
export declare function createClient<R extends Context, L extends Context, RE, LE>(localCtx: L, options: ClientOptions): ClientReturn<R, L, RE, LE>;
|
|
51
|
-
export {};
|
package/dist/createClient.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createClient = createClient;
|
|
7
|
-
function createClient(y, l) {
|
|
8
|
-
const {
|
|
9
|
-
invoke: c,
|
|
10
|
-
handle: f,
|
|
11
|
-
emit: o,
|
|
12
|
-
handleEvent: d,
|
|
13
|
-
serialize: x,
|
|
14
|
-
deserialize: v
|
|
15
|
-
} = l;
|
|
16
|
-
function g(e) {
|
|
17
|
-
try {
|
|
18
|
-
return x ? x(e) : JSON.stringify(e);
|
|
19
|
-
} catch {
|
|
20
|
-
return e;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function R(e) {
|
|
24
|
-
try {
|
|
25
|
-
return v ? v(e) : JSON.parse(e);
|
|
26
|
-
} catch {
|
|
27
|
-
return e;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const u = new Map();
|
|
31
|
-
f(async e => {
|
|
32
|
-
const n = p(y, e.key || "");
|
|
33
|
-
if (n === void 0) return {
|
|
34
|
-
type: "response",
|
|
35
|
-
id: e.id,
|
|
36
|
-
key: e.key,
|
|
37
|
-
result: void 0
|
|
38
|
-
};
|
|
39
|
-
let r = e.args ? R(e.args) : [];
|
|
40
|
-
Array.isArray(r) || (r = [r]);
|
|
41
|
-
const s = typeof n == "function" ? await n(...r) : n;
|
|
42
|
-
return {
|
|
43
|
-
type: "response",
|
|
44
|
-
id: e.id,
|
|
45
|
-
key: e.key,
|
|
46
|
-
result: g(s)
|
|
47
|
-
};
|
|
48
|
-
}), d(e => {
|
|
49
|
-
const n = u.get(e.eventName);
|
|
50
|
-
if (!n?.length) return;
|
|
51
|
-
let r = e.args ? R(e.args) : [];
|
|
52
|
-
Array.isArray(r) || (r = [r]), n.forEach(s => s(...r));
|
|
53
|
-
});
|
|
54
|
-
const E = new Map();
|
|
55
|
-
function m(e) {
|
|
56
|
-
const n = e.join(".");
|
|
57
|
-
if (E.has(n)) return E.get(n);
|
|
58
|
-
const r = async (...i) => {
|
|
59
|
-
const t = {
|
|
60
|
-
type: "request",
|
|
61
|
-
id: `${n}-${Date.now()}-${Math.random()}`,
|
|
62
|
-
key: n,
|
|
63
|
-
args: g(i)
|
|
64
|
-
},
|
|
65
|
-
a = await c(t);
|
|
66
|
-
return R(a.result);
|
|
67
|
-
},
|
|
68
|
-
s = new Proxy(r, {
|
|
69
|
-
get(i, t) {
|
|
70
|
-
if (t === "then") {
|
|
71
|
-
const a = i();
|
|
72
|
-
return a.then.bind(a);
|
|
73
|
-
}
|
|
74
|
-
if (t === "catch" || t === "finally") {
|
|
75
|
-
const a = i();
|
|
76
|
-
return a[t].bind(a);
|
|
77
|
-
}
|
|
78
|
-
return m([...e, t]);
|
|
79
|
-
},
|
|
80
|
-
apply(i, t, a) {
|
|
81
|
-
return i.apply(t, a);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return E.set(n, s), s;
|
|
85
|
-
}
|
|
86
|
-
return new Proxy({}, {
|
|
87
|
-
get(e, n) {
|
|
88
|
-
if (n === "$context") return y;
|
|
89
|
-
if (n === "on") return (s, i) => {
|
|
90
|
-
const t = u.get(s);
|
|
91
|
-
if (!t) {
|
|
92
|
-
u.set(s, [i]);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
t.push(i);
|
|
96
|
-
};
|
|
97
|
-
if (n === "off") return (s, i) => {
|
|
98
|
-
const t = u.get(s)?.indexOf(i);
|
|
99
|
-
t === -1 || t === void 0 || u.get(s)?.splice(t, 1);
|
|
100
|
-
};
|
|
101
|
-
if (n === "emit") return (s, ...i) => {
|
|
102
|
-
o({
|
|
103
|
-
eventName: s,
|
|
104
|
-
args: g(i)
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
if (n === "removeAllListeners") return () => u.clear();
|
|
108
|
-
if (typeof n != "symbol") return m([n]);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function p(y, l, c) {
|
|
113
|
-
if (!y || typeof y != "object") return c;
|
|
114
|
-
const f = Array.isArray(l) ? l : l.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
|
|
115
|
-
let o = y;
|
|
116
|
-
for (const d of f) if (o != null && typeof o == "object" && d in o) o = o[d];else return c;
|
|
117
|
-
return o;
|
|
118
|
-
}
|
package/dist/createClient.mjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
export function createClient(y, l) {
|
|
2
|
-
const { invoke: c, handle: f, emit: o, handleEvent: d, serialize: x, deserialize: v } = l;
|
|
3
|
-
function g(e) {
|
|
4
|
-
try {
|
|
5
|
-
return x ? x(e) : JSON.stringify(e);
|
|
6
|
-
} catch {
|
|
7
|
-
return e;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function R(e) {
|
|
11
|
-
try {
|
|
12
|
-
return v ? v(e) : JSON.parse(e);
|
|
13
|
-
} catch {
|
|
14
|
-
return e;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
const u = /* @__PURE__ */ new Map();
|
|
18
|
-
f(async (e) => {
|
|
19
|
-
const n = p(y, e.key || "");
|
|
20
|
-
if (n === void 0)
|
|
21
|
-
return {
|
|
22
|
-
type: "response",
|
|
23
|
-
id: e.id,
|
|
24
|
-
key: e.key,
|
|
25
|
-
result: void 0
|
|
26
|
-
};
|
|
27
|
-
let r = e.args ? R(e.args) : [];
|
|
28
|
-
Array.isArray(r) || (r = [r]);
|
|
29
|
-
const s = typeof n == "function" ? await n(...r) : n;
|
|
30
|
-
return {
|
|
31
|
-
type: "response",
|
|
32
|
-
id: e.id,
|
|
33
|
-
key: e.key,
|
|
34
|
-
result: g(s)
|
|
35
|
-
};
|
|
36
|
-
}), d((e) => {
|
|
37
|
-
const n = u.get(e.eventName);
|
|
38
|
-
if (!n?.length) return;
|
|
39
|
-
let r = e.args ? R(e.args) : [];
|
|
40
|
-
Array.isArray(r) || (r = [r]), n.forEach((s) => s(...r));
|
|
41
|
-
});
|
|
42
|
-
const E = /* @__PURE__ */ new Map();
|
|
43
|
-
function m(e) {
|
|
44
|
-
const n = e.join(".");
|
|
45
|
-
if (E.has(n))
|
|
46
|
-
return E.get(n);
|
|
47
|
-
const r = async (...i) => {
|
|
48
|
-
const t = {
|
|
49
|
-
type: "request",
|
|
50
|
-
id: `${n}-${Date.now()}-${Math.random()}`,
|
|
51
|
-
// More robust ID
|
|
52
|
-
key: n,
|
|
53
|
-
args: g(i)
|
|
54
|
-
}, a = await c(t);
|
|
55
|
-
return R(a.result);
|
|
56
|
-
}, s = new Proxy(r, {
|
|
57
|
-
get(i, t) {
|
|
58
|
-
if (t === "then") {
|
|
59
|
-
const a = i();
|
|
60
|
-
return a.then.bind(a);
|
|
61
|
-
}
|
|
62
|
-
if (t === "catch" || t === "finally") {
|
|
63
|
-
const a = i();
|
|
64
|
-
return a[t].bind(a);
|
|
65
|
-
}
|
|
66
|
-
return m([...e, t]);
|
|
67
|
-
},
|
|
68
|
-
apply(i, t, a) {
|
|
69
|
-
return i.apply(t, a);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return E.set(n, s), s;
|
|
73
|
-
}
|
|
74
|
-
return new Proxy(
|
|
75
|
-
{},
|
|
76
|
-
{
|
|
77
|
-
get(e, n) {
|
|
78
|
-
if (n === "$context") return y;
|
|
79
|
-
if (n === "on")
|
|
80
|
-
return (s, i) => {
|
|
81
|
-
const t = u.get(s);
|
|
82
|
-
if (!t) {
|
|
83
|
-
u.set(s, [i]);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
t.push(i);
|
|
87
|
-
};
|
|
88
|
-
if (n === "off")
|
|
89
|
-
return (s, i) => {
|
|
90
|
-
const t = u.get(s)?.indexOf(i);
|
|
91
|
-
t === -1 || t === void 0 || u.get(s)?.splice(t, 1);
|
|
92
|
-
};
|
|
93
|
-
if (n === "emit")
|
|
94
|
-
return (s, ...i) => {
|
|
95
|
-
o({ eventName: s, args: g(i) });
|
|
96
|
-
};
|
|
97
|
-
if (n === "removeAllListeners") return () => u.clear();
|
|
98
|
-
if (typeof n != "symbol")
|
|
99
|
-
return m([n]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
function p(y, l, c) {
|
|
105
|
-
if (!y || typeof y != "object") return c;
|
|
106
|
-
const f = Array.isArray(l) ? l : l.replace(/\[(\d+)]/g, ".$1").replace(/\["([^"]+)"\]/g, ".$1").replace(/\['([^']+)'\]/g, ".$1").split(".").filter(Boolean);
|
|
107
|
-
let o = y;
|
|
108
|
-
for (const d of f)
|
|
109
|
-
if (o != null && typeof o == "object" && d in o)
|
|
110
|
-
o = o[d];
|
|
111
|
-
else
|
|
112
|
-
return c;
|
|
113
|
-
return o;
|
|
114
|
-
}
|