@nookuio/iframe 1.0.2 → 1.0.4

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/iframe.js CHANGED
@@ -7,19 +7,19 @@ exports.createVueIframeClient = createVueIframeClient;
7
7
  var _constants = require("./constants");
8
8
  var _rpc = require("@nookuio/rpc");
9
9
  var _telejson = require("telejson");
10
- function u(c, a) {
10
+ function m(c, a) {
11
11
  return `[data-node-id="${a}"][data-node-path="${c}"]`;
12
12
  }
13
- function y(c, a) {
13
+ function g(c, a) {
14
14
  const n = document.querySelectorAll(c);
15
15
  if (!n?.length) return;
16
16
  const t = Array.from(n).map(d => {
17
- const o = d.getBoundingClientRect(),
17
+ const r = d.getBoundingClientRect(),
18
18
  s = {
19
- width: o.width,
20
- height: o.height,
21
- top: o.top,
22
- left: o.left
19
+ width: r.width,
20
+ height: r.height,
21
+ top: r.top,
22
+ left: r.left
23
23
  };
24
24
  if (!a) return s;
25
25
  const i = window.getComputedStyle(d) ?? {};
@@ -45,33 +45,33 @@ function C(c) {
45
45
  id: t
46
46
  }) {
47
47
  if (!n || t === void 0) return;
48
- const d = u(n, t),
49
- o = document.querySelector(d);
50
- if (!o) return;
51
- o.style.outline = "none", o.setAttribute("spellcheck", "false"), o.setAttribute("contenteditable", "true");
48
+ const d = m(n, t),
49
+ r = document.querySelector(d);
50
+ if (!r) return;
51
+ r.style.outline = "none", r.setAttribute("spellcheck", "false"), r.setAttribute("contenteditable", "true");
52
52
  const s = l => {
53
53
  const e = l.target;
54
54
  if (!e) return;
55
- const r = e.innerText;
56
- o.removeAttribute("contenteditable"), c?.onTextUpdate?.({
55
+ const o = e.innerText;
56
+ r.removeAttribute("contenteditable"), c?.onTextUpdate?.({
57
57
  path: n,
58
58
  id: t,
59
- content: r
60
- }), o.removeEventListener("blur", s), o.removeEventListener("keydown", i), o.blur();
59
+ content: o
60
+ }), r.removeEventListener("blur", s), r.removeEventListener("keydown", i), r.blur();
61
61
  },
62
62
  i = l => {
63
63
  l.key === "Enter" && (l.stopPropagation(), l.preventDefault(), s(l));
64
64
  };
65
- o.addEventListener("keydown", i), o.addEventListener("blur", s), o.focus();
65
+ r.addEventListener("keydown", i), r.addEventListener("blur", s), r.focus();
66
66
  },
67
67
  async getHoveredElement({
68
68
  path: n,
69
69
  id: t,
70
70
  x: d,
71
- y: o
71
+ y: r
72
72
  }) {
73
- if (n) if (d !== void 0 && o !== void 0) {
74
- let s = document.elementFromPoint(d, o);
73
+ if (n) if (d !== void 0 && r !== void 0) {
74
+ let s = document.elementFromPoint(d, r);
75
75
  if (!s) return;
76
76
  let i = s.getAttribute("data-node-path");
77
77
  if (i !== n) {
@@ -80,16 +80,16 @@ function C(c) {
80
80
  }
81
81
  const l = s.getAttribute("data-node-id");
82
82
  if (!l) return;
83
- const e = u(n, l),
84
- r = y(e, !1);
85
- return r ? {
83
+ const e = m(n, l),
84
+ o = g(e, !1);
85
+ return o ? {
86
86
  id: l,
87
87
  path: n,
88
- data: r
88
+ data: o
89
89
  } : void 0;
90
90
  } else {
91
- const s = u(n, t),
92
- i = y(s, !1);
91
+ const s = m(n, t),
92
+ i = g(s, !1);
93
93
  return i ? {
94
94
  id: t,
95
95
  path: n,
@@ -97,17 +97,19 @@ function C(c) {
97
97
  } : void 0;
98
98
  }
99
99
  },
100
- getPageHeight: a,
100
+ async getPageHeight() {
101
+ return await a();
102
+ },
101
103
  async getSelectedElement({
102
104
  path: n,
103
105
  id: t
104
106
  }) {
105
- const d = u(n, t),
106
- o = y(d, !0);
107
- if (o) return {
107
+ const d = m(n, t),
108
+ r = g(d, !0);
109
+ if (r) return {
108
110
  path: n,
109
111
  id: t,
110
- data: o
112
+ data: r
111
113
  };
112
114
  },
113
115
  setTheme(n) {
@@ -123,8 +125,21 @@ function createVueIframeClient(c, a) {
123
125
  const n = new Map();
124
126
  window.addEventListener("message", async e => {
125
127
  if (typeof e.data != "object" || e.data.source !== _constants.EDITOR_SOURCE_NAME || e.data.type === "event" || !e.data.response) return;
126
- const r = n.get(e.data.response.id);
127
- r && (n.delete(e.data.response.id), r(e.data.response));
128
+ const o = n.get(e.data.response.id);
129
+ o && (n.delete(e.data.response.id), o(e.data.response));
130
+ }), window.addEventListener("keydown", e => {
131
+ if (!t) return;
132
+ const o = document.activeElement,
133
+ u = o?.isContentEditable || o?.tagName === "INPUT" || o?.tagName === "TEXTAREA";
134
+ t.emit("keydown", {
135
+ key: e.key,
136
+ ctrlKey: e.ctrlKey,
137
+ shiftKey: e.shiftKey,
138
+ altKey: e.altKey,
139
+ metaKey: e.metaKey,
140
+ repeat: e.repeat,
141
+ inputFocused: u
142
+ });
128
143
  });
129
144
  const t = (0, _rpc.createClient)({
130
145
  ...C({
@@ -134,20 +149,20 @@ function createVueIframeClient(c, a) {
134
149
  ...c
135
150
  }, {
136
151
  handle(e) {
137
- window.addEventListener("message", async r => {
138
- if (typeof r.data != "object" || r.data.source !== _constants.EDITOR_SOURCE_NAME || r.data.type === "event" || !r.data.request) return;
139
- const m = await e(r.data.request);
152
+ window.addEventListener("message", async o => {
153
+ if (typeof o.data != "object" || o.data.source !== _constants.EDITOR_SOURCE_NAME || o.data.type === "event" || !o.data.request) return;
154
+ const u = await e(o.data.request);
140
155
  window.parent.postMessage({
141
156
  source: _constants.IFRAME_SOURCE_NAME,
142
- response: m
157
+ response: u
143
158
  }, "*");
144
159
  });
145
160
  },
146
161
  invoke(e) {
147
- return new Promise((r, m) => {
148
- const E = setTimeout(() => m(new Error("Request timed out")), 5e3);
162
+ return new Promise((o, u) => {
163
+ const E = setTimeout(() => u(new Error("Request timed out")), 5e3);
149
164
  n.set(e.id, p => {
150
- clearTimeout(E), r(p);
165
+ clearTimeout(E), o(p);
151
166
  }), window.parent.postMessage({
152
167
  source: _constants.IFRAME_SOURCE_NAME,
153
168
  request: e
@@ -162,8 +177,8 @@ function createVueIframeClient(c, a) {
162
177
  }, "*");
163
178
  },
164
179
  handleEvent(e) {
165
- window.addEventListener("message", r => {
166
- typeof r.data == "object" && (r.data.source !== _constants.EDITOR_SOURCE_NAME || r.data.type !== "event" || !r.data.request || e(r.data.request));
180
+ window.addEventListener("message", o => {
181
+ typeof o.data == "object" && (o.data.source !== _constants.EDITOR_SOURCE_NAME || o.data.type !== "event" || !o.data.request || e(o.data.request));
167
182
  });
168
183
  },
169
184
  destroy() {
@@ -176,13 +191,13 @@ function createVueIframeClient(c, a) {
176
191
  timeout: 5e3
177
192
  }),
178
193
  d = a?.disableDefaultConsole ? void 0 : console.log.bind(console),
179
- o = a?.disableDefaultConsole ? void 0 : console.warn.bind(console),
194
+ r = a?.disableDefaultConsole ? void 0 : console.warn.bind(console),
180
195
  s = a?.disableDefaultConsole ? void 0 : console.error.bind(console),
181
196
  i = a?.disableDefaultConsole ? void 0 : console.info.bind(console);
182
197
  return console.log = (...e) => {
183
198
  t.emit("console", "log", e), d?.(...e);
184
199
  }, console.warn = (...e) => {
185
- o?.(...e);
200
+ r?.(...e);
186
201
  }, console.error = (...e) => {
187
202
  t.emit("console", "error", e), s?.(...e);
188
203
  }, console.info = (...e) => {
package/dist/iframe.mjs CHANGED
@@ -1,18 +1,18 @@
1
- import { EDITOR_SOURCE_NAME as f, IFRAME_SOURCE_NAME as g } from "./constants.mjs";
1
+ import { EDITOR_SOURCE_NAME as f, IFRAME_SOURCE_NAME as y } from "./constants.mjs";
2
2
  import { createClient as b } from "@nookuio/rpc";
3
- import { stringify as h, parse as w } from "telejson";
4
- function u(c, a) {
3
+ import { stringify as w, parse as h } from "telejson";
4
+ function m(c, a) {
5
5
  return `[data-node-id="${a}"][data-node-path="${c}"]`;
6
6
  }
7
- function y(c, a) {
7
+ function g(c, a) {
8
8
  const n = document.querySelectorAll(c);
9
9
  if (!n?.length) return;
10
10
  const t = Array.from(n).map((d) => {
11
- const o = d.getBoundingClientRect(), s = {
12
- width: o.width,
13
- height: o.height,
14
- top: o.top,
15
- left: o.left
11
+ const r = d.getBoundingClientRect(), s = {
12
+ width: r.width,
13
+ height: r.height,
14
+ top: r.top,
15
+ left: r.left
16
16
  };
17
17
  if (!a) return s;
18
18
  const i = window.getComputedStyle(d) ?? {};
@@ -36,23 +36,23 @@ function C(c) {
36
36
  return {
37
37
  async editText({ path: n, id: t }) {
38
38
  if (!n || t === void 0) return;
39
- const d = u(n, t), o = document.querySelector(d);
40
- if (!o) return;
41
- o.style.outline = "none", o.setAttribute("spellcheck", "false"), o.setAttribute("contenteditable", "true");
39
+ const d = m(n, t), r = document.querySelector(d);
40
+ if (!r) return;
41
+ r.style.outline = "none", r.setAttribute("spellcheck", "false"), r.setAttribute("contenteditable", "true");
42
42
  const s = (l) => {
43
43
  const e = l.target;
44
44
  if (!e) return;
45
- const r = e.innerText;
46
- o.removeAttribute("contenteditable"), c?.onTextUpdate?.({ path: n, id: t, content: r }), o.removeEventListener("blur", s), o.removeEventListener("keydown", i), o.blur();
45
+ const o = e.innerText;
46
+ r.removeAttribute("contenteditable"), c?.onTextUpdate?.({ path: n, id: t, content: o }), r.removeEventListener("blur", s), r.removeEventListener("keydown", i), r.blur();
47
47
  }, i = (l) => {
48
48
  l.key === "Enter" && (l.stopPropagation(), l.preventDefault(), s(l));
49
49
  };
50
- o.addEventListener("keydown", i), o.addEventListener("blur", s), o.focus();
50
+ r.addEventListener("keydown", i), r.addEventListener("blur", s), r.focus();
51
51
  },
52
- async getHoveredElement({ path: n, id: t, x: d, y: o }) {
52
+ async getHoveredElement({ path: n, id: t, x: d, y: r }) {
53
53
  if (n)
54
- if (d !== void 0 && o !== void 0) {
55
- let s = document.elementFromPoint(d, o);
54
+ if (d !== void 0 && r !== void 0) {
55
+ let s = document.elementFromPoint(d, r);
56
56
  if (!s) return;
57
57
  let i = s.getAttribute("data-node-path");
58
58
  if (i !== n) {
@@ -62,14 +62,14 @@ function C(c) {
62
62
  }
63
63
  const l = s.getAttribute("data-node-id");
64
64
  if (!l) return;
65
- const e = u(n, l), r = y(e, !1);
66
- return r ? {
65
+ const e = m(n, l), o = g(e, !1);
66
+ return o ? {
67
67
  id: l,
68
68
  path: n,
69
- data: r
69
+ data: o
70
70
  } : void 0;
71
71
  } else {
72
- const s = u(n, t), i = y(s, !1);
72
+ const s = m(n, t), i = g(s, !1);
73
73
  return i ? {
74
74
  id: t,
75
75
  path: n,
@@ -77,14 +77,16 @@ function C(c) {
77
77
  } : void 0;
78
78
  }
79
79
  },
80
- getPageHeight: a,
80
+ async getPageHeight() {
81
+ return await a();
82
+ },
81
83
  async getSelectedElement({ path: n, id: t }) {
82
- const d = u(n, t), o = y(d, !0);
83
- if (o)
84
+ const d = m(n, t), r = g(d, !0);
85
+ if (r)
84
86
  return {
85
87
  path: n,
86
88
  id: t,
87
- data: o
89
+ data: r
88
90
  };
89
91
  },
90
92
  setTheme(n) {
@@ -122,8 +124,20 @@ export function createVueIframeClient(c, a) {
122
124
  const n = /* @__PURE__ */ new Map();
123
125
  window.addEventListener("message", async (e) => {
124
126
  if (typeof e.data != "object" || e.data.source !== f || e.data.type === "event" || !e.data.response) return;
125
- const r = n.get(e.data.response.id);
126
- r && (n.delete(e.data.response.id), r(e.data.response));
127
+ const o = n.get(e.data.response.id);
128
+ o && (n.delete(e.data.response.id), o(e.data.response));
129
+ }), window.addEventListener("keydown", (e) => {
130
+ if (!t) return;
131
+ const o = document.activeElement, u = o?.isContentEditable || o?.tagName === "INPUT" || o?.tagName === "TEXTAREA";
132
+ t.emit("keydown", {
133
+ key: e.key,
134
+ ctrlKey: e.ctrlKey,
135
+ shiftKey: e.shiftKey,
136
+ altKey: e.altKey,
137
+ metaKey: e.metaKey,
138
+ repeat: e.repeat,
139
+ inputFocused: u
140
+ });
127
141
  });
128
142
  const t = b(
129
143
  {
@@ -135,40 +149,40 @@ export function createVueIframeClient(c, a) {
135
149
  },
136
150
  {
137
151
  handle(e) {
138
- window.addEventListener("message", async (r) => {
139
- if (typeof r.data != "object" || r.data.source !== f || r.data.type === "event" || !r.data.request) return;
140
- const m = await e(r.data.request);
141
- window.parent.postMessage({ source: g, response: m }, "*");
152
+ window.addEventListener("message", async (o) => {
153
+ if (typeof o.data != "object" || o.data.source !== f || o.data.type === "event" || !o.data.request) return;
154
+ const u = await e(o.data.request);
155
+ window.parent.postMessage({ source: y, response: u }, "*");
142
156
  });
143
157
  },
144
158
  invoke(e) {
145
- return new Promise((r, m) => {
146
- const E = setTimeout(() => m(new Error("Request timed out")), 5e3);
159
+ return new Promise((o, u) => {
160
+ const E = setTimeout(() => u(new Error("Request timed out")), 5e3);
147
161
  n.set(e.id, (p) => {
148
- clearTimeout(E), r(p);
149
- }), window.parent.postMessage({ source: g, request: e }, "*");
162
+ clearTimeout(E), o(p);
163
+ }), window.parent.postMessage({ source: y, request: e }, "*");
150
164
  });
151
165
  },
152
166
  emit(e) {
153
- window.parent.postMessage({ source: g, type: "event", request: e }, "*");
167
+ window.parent.postMessage({ source: y, type: "event", request: e }, "*");
154
168
  },
155
169
  handleEvent(e) {
156
- window.addEventListener("message", (r) => {
157
- typeof r.data == "object" && (r.data.source !== f || r.data.type !== "event" || !r.data.request || e(r.data.request));
170
+ window.addEventListener("message", (o) => {
171
+ typeof o.data == "object" && (o.data.source !== f || o.data.type !== "event" || !o.data.request || e(o.data.request));
158
172
  });
159
173
  },
160
174
  destroy() {
161
175
  n.clear();
162
176
  },
163
- deserialize: (e) => w(e),
164
- serialize: (e) => h(e, { maxDepth: 1 / 0 }),
177
+ deserialize: (e) => h(e),
178
+ serialize: (e) => w(e, { maxDepth: 1 / 0 }),
165
179
  timeout: 5e3
166
180
  }
167
- ), d = a?.disableDefaultConsole ? void 0 : console.log.bind(console), o = a?.disableDefaultConsole ? void 0 : console.warn.bind(console), s = a?.disableDefaultConsole ? void 0 : console.error.bind(console), i = a?.disableDefaultConsole ? void 0 : console.info.bind(console);
181
+ ), d = a?.disableDefaultConsole ? void 0 : console.log.bind(console), r = a?.disableDefaultConsole ? void 0 : console.warn.bind(console), s = a?.disableDefaultConsole ? void 0 : console.error.bind(console), i = a?.disableDefaultConsole ? void 0 : console.info.bind(console);
168
182
  return console.log = (...e) => {
169
183
  t.emit("console", "log", e), d?.(...e);
170
184
  }, console.warn = (...e) => {
171
- o?.(...e);
185
+ r?.(...e);
172
186
  }, console.error = (...e) => {
173
187
  t.emit("console", "error", e), s?.(...e);
174
188
  }, console.info = (...e) => {
package/dist/types.d.ts CHANGED
@@ -53,6 +53,16 @@ export interface CoreIframeEvents extends RpcEvents {
53
53
  id: string;
54
54
  content: string;
55
55
  }) => void;
56
+ keydown: (event: {
57
+ key: string;
58
+ ctrlKey: boolean;
59
+ shiftKey: boolean;
60
+ altKey: boolean;
61
+ metaKey: boolean;
62
+ repeat: boolean;
63
+ /** Is `true` if the focused element is an input, textarea, or contenteditable element */
64
+ inputFocused: boolean;
65
+ }) => void;
56
66
  }
57
67
  export interface VueIframeContext extends Omit<CoreIframeContext, 'updateCode'> {
58
68
  navigateTo: (to: string) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nookuio/iframe",
3
3
  "description": "",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "exports": {