@markupai/sidebar-adapter 1.4.0 → 1.5.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/README.md +134 -15
- package/asyncapi.json +120 -19
- package/dist/adapters/pluginAdapter.d.ts +4 -4
- package/dist/adapters/pluginAdapter.d.ts.map +1 -1
- package/dist/adapters/sidebarAdapter.d.ts +12 -1
- package/dist/adapters/sidebarAdapter.d.ts.map +1 -1
- package/dist/ipc/call-signatures.d.ts +30 -6
- package/dist/ipc/call-signatures.d.ts.map +1 -1
- package/dist/ipc/plugin-ipc-adapter.d.ts +4 -4
- package/dist/ipc/plugin-ipc-adapter.d.ts.map +1 -1
- package/dist/ipc/sidebar-ipc-adapter.d.ts +12 -1
- package/dist/ipc/sidebar-ipc-adapter.d.ts.map +1 -1
- package/dist/main.js +118 -105
- package/dist/main.umd.cjs +5 -5
- package/dist/types/common.d.ts +30 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/pluginInterface.d.ts +21 -6
- package/dist/types/pluginInterface.d.ts.map +1 -1
- package/dist/types/sidebarInterface.d.ts +22 -1
- package/dist/types/sidebarInterface.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -13,14 +13,15 @@ var oe = /* @__PURE__ */ (function(e) {
|
|
|
13
13
|
dialogClosingScript: void 0,
|
|
14
14
|
useCheckPreviewDialog: !1,
|
|
15
15
|
supportCheckSelection: !0,
|
|
16
|
-
multiAgent: !1
|
|
16
|
+
multiAgent: !1,
|
|
17
|
+
multiDocument: !1
|
|
17
18
|
}, ce = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), de = (e) => {
|
|
18
19
|
if (typeof e != "object" || e === null) return !1;
|
|
19
20
|
const t = e;
|
|
20
21
|
return typeof t.id != "string" || t.id.length === 0 || typeof t.label != "string" ? !1 : t.type === "boolean" ? typeof t.default == "boolean" : t.type === "enum" ? typeof t.default != "string" || !Array.isArray(t.options) || t.options.length === 0 ? !1 : t.options.every((i) => {
|
|
21
22
|
if (typeof i != "object" || i === null) return !1;
|
|
22
|
-
const
|
|
23
|
-
return typeof
|
|
23
|
+
const n = i;
|
|
24
|
+
return typeof n.value == "string" && typeof n.label == "string";
|
|
24
25
|
}) : !1;
|
|
25
26
|
}, O = class T extends Error {
|
|
26
27
|
name = "TextLookupError";
|
|
@@ -33,8 +34,8 @@ function ge(e) {
|
|
|
33
34
|
}
|
|
34
35
|
var P = { TextLookupError: (e) => new O(e) };
|
|
35
36
|
function U(e) {
|
|
36
|
-
const t = e.message ?? "", i = e.name,
|
|
37
|
-
return
|
|
37
|
+
const t = e.message ?? "", i = e.name, n = typeof i == "string" && i in P ? P[i] : void 0;
|
|
38
|
+
return n ? n(t, e) : Object.assign(new Error(t), i ? { name: i } : {});
|
|
38
39
|
}
|
|
39
40
|
var D = ":", x = /^[a-z][a-z0-9-]*$/;
|
|
40
41
|
function pe(e) {
|
|
@@ -42,11 +43,11 @@ function pe(e) {
|
|
|
42
43
|
return t <= 0 || t === e.length - 1 ? !1 : x.test(e.slice(0, t));
|
|
43
44
|
}
|
|
44
45
|
function ue(e, t) {
|
|
45
|
-
const i = e.trim().toLowerCase(),
|
|
46
|
+
const i = e.trim().toLowerCase(), n = t.trim();
|
|
46
47
|
if (!x.test(i)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
return
|
|
48
|
+
if (n.length === 0) throw new Error("Invalid document reference: the document id is empty.");
|
|
49
|
+
const r = `${i}${D}`;
|
|
50
|
+
return n.startsWith(r) ? n : `${r}${n}`;
|
|
50
51
|
}
|
|
51
52
|
var H = class extends Promise {
|
|
52
53
|
static get [Symbol.species]() {
|
|
@@ -57,8 +58,8 @@ var H = class extends Promise {
|
|
|
57
58
|
constructor(e = () => {
|
|
58
59
|
}) {
|
|
59
60
|
let t, i;
|
|
60
|
-
super((
|
|
61
|
-
t =
|
|
61
|
+
super((n, r) => {
|
|
62
|
+
t = n, i = r, e(n, r);
|
|
62
63
|
}), this.resolve = t, this.reject = i;
|
|
63
64
|
}
|
|
64
65
|
}, $ = { timeout: 1e4 };
|
|
@@ -91,23 +92,23 @@ var L = class {
|
|
|
91
92
|
return this.callWithOptions(e, {}, ...t);
|
|
92
93
|
}
|
|
93
94
|
callWithOptions(e, t, ...i) {
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
95
|
+
const n = this.currentID++, r = new H(), a = t.timeout ?? this.config.timeout, o = setTimeout(() => {
|
|
96
|
+
if (n in this.promisesByID) {
|
|
96
97
|
const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);
|
|
97
|
-
|
|
98
|
+
r.reject(l), Reflect.deleteProperty(this.promisesByID, n);
|
|
98
99
|
}
|
|
99
100
|
}, a);
|
|
100
|
-
this.promisesByID[
|
|
101
|
-
promise:
|
|
101
|
+
this.promisesByID[n] = {
|
|
102
|
+
promise: r,
|
|
102
103
|
timeoutId: o
|
|
103
104
|
};
|
|
104
105
|
const s = {
|
|
105
106
|
type: "call",
|
|
106
|
-
id:
|
|
107
|
+
id: n,
|
|
107
108
|
name: e,
|
|
108
109
|
data: i
|
|
109
110
|
};
|
|
110
|
-
return this.postMessage(s),
|
|
111
|
+
return this.postMessage(s), r;
|
|
111
112
|
}
|
|
112
113
|
receive(e, t) {
|
|
113
114
|
this.receiversByName[e] = t;
|
|
@@ -130,7 +131,7 @@ var L = class {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
async handleCall(e) {
|
|
133
|
-
const { id: t, name: i, data:
|
|
134
|
+
const { id: t, name: i, data: n } = e;
|
|
134
135
|
if (!(i in this.receiversByName)) {
|
|
135
136
|
const a = /* @__PURE__ */ new Error(`No receiver registered for: ${i}`), o = JSON.stringify({
|
|
136
137
|
message: a.message,
|
|
@@ -144,10 +145,10 @@ var L = class {
|
|
|
144
145
|
});
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
|
-
const
|
|
148
|
+
const r = this.receiversByName[i];
|
|
148
149
|
try {
|
|
149
|
-
if (!Array.isArray(
|
|
150
|
-
const a = await
|
|
150
|
+
if (!Array.isArray(n)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);
|
|
151
|
+
const a = await r(...n), o = {
|
|
151
152
|
type: "response",
|
|
152
153
|
id: t,
|
|
153
154
|
name: i,
|
|
@@ -167,20 +168,20 @@ var L = class {
|
|
|
167
168
|
handleResponse(e) {
|
|
168
169
|
const { id: t } = e;
|
|
169
170
|
if (t in this.promisesByID) {
|
|
170
|
-
const { promise: i, timeoutId:
|
|
171
|
-
clearTimeout(
|
|
171
|
+
const { promise: i, timeoutId: n } = this.promisesByID[t];
|
|
172
|
+
clearTimeout(n), i.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
handleError(e) {
|
|
175
176
|
const { id: t, errorJSON: i } = e;
|
|
176
177
|
if (t in this.promisesByID) {
|
|
177
|
-
const { promise:
|
|
178
|
-
clearTimeout(
|
|
178
|
+
const { promise: n, timeoutId: r } = this.promisesByID[t];
|
|
179
|
+
clearTimeout(r);
|
|
179
180
|
try {
|
|
180
181
|
const a = U(JSON.parse(i));
|
|
181
|
-
|
|
182
|
+
n.reject(a);
|
|
182
183
|
} catch {
|
|
183
|
-
|
|
184
|
+
n.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
|
|
184
185
|
}
|
|
185
186
|
Reflect.deleteProperty(this.promisesByID, t);
|
|
186
187
|
}
|
|
@@ -195,8 +196,8 @@ var L = class {
|
|
|
195
196
|
sidebar;
|
|
196
197
|
targetOrigin;
|
|
197
198
|
constructor(e, t, i = "*") {
|
|
198
|
-
this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new L((
|
|
199
|
-
window.parent.postMessage(
|
|
199
|
+
this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new L((n) => {
|
|
200
|
+
window.parent.postMessage(n, this.targetOrigin);
|
|
200
201
|
}, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
|
|
201
202
|
}
|
|
202
203
|
handleMessage = (e) => {
|
|
@@ -212,8 +213,8 @@ var L = class {
|
|
|
212
213
|
}
|
|
213
214
|
if (this.sidebar.activateAgenticIssue) {
|
|
214
215
|
const e = this.sidebar.activateAgenticIssue;
|
|
215
|
-
this.ipc.receive("activateAgenticIssue", async (t) => {
|
|
216
|
-
await e(t);
|
|
216
|
+
this.ipc.receive("activateAgenticIssue", async (t, i) => {
|
|
217
|
+
await e(t, typeof i == "string" ? i : null);
|
|
217
218
|
});
|
|
218
219
|
}
|
|
219
220
|
if (this.sidebar.invalidateAgenticIssue) {
|
|
@@ -244,6 +245,12 @@ var L = class {
|
|
|
244
245
|
const e = this.sidebar.getIntegrationSettings;
|
|
245
246
|
this.ipc.receive("getIntegrationSettings", async () => await e());
|
|
246
247
|
}
|
|
248
|
+
if (this.sidebar.onActiveDocumentChanged) {
|
|
249
|
+
const e = this.sidebar.onActiveDocumentChanged;
|
|
250
|
+
this.ipc.receive("onActiveDocumentChanged", async (t) => {
|
|
251
|
+
await e(t);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
247
254
|
}
|
|
248
255
|
async getInitConfig() {
|
|
249
256
|
return await this.ipc.call("getInitConfig");
|
|
@@ -254,14 +261,14 @@ var L = class {
|
|
|
254
261
|
async getSelectedContent(e) {
|
|
255
262
|
return this.ipc.callWithOptions("getSelectedContent", e ?? {});
|
|
256
263
|
}
|
|
257
|
-
async replaceContent(e, t) {
|
|
258
|
-
await this.ipc.call("replaceContent", e, t);
|
|
264
|
+
async replaceContent(e, t, i = null) {
|
|
265
|
+
await this.ipc.call("replaceContent", e, t, i);
|
|
259
266
|
}
|
|
260
|
-
async selectContent(e) {
|
|
261
|
-
await this.ipc.call("selectContent", e);
|
|
267
|
+
async selectContent(e, t = null) {
|
|
268
|
+
await this.ipc.call("selectContent", e, t);
|
|
262
269
|
}
|
|
263
|
-
async showDialog(e, t, i,
|
|
264
|
-
await this.ipc.call("showDialog", e, t, i,
|
|
270
|
+
async showDialog(e, t, i, n) {
|
|
271
|
+
await this.ipc.call("showDialog", e, t, i, n);
|
|
265
272
|
}
|
|
266
273
|
async closeDialog() {
|
|
267
274
|
await this.ipc.call("closeDialog");
|
|
@@ -269,11 +276,11 @@ var L = class {
|
|
|
269
276
|
async replaceMultipleContents(e) {
|
|
270
277
|
await this.ipc.call("replaceMultipleContents", e);
|
|
271
278
|
}
|
|
272
|
-
async onAgenticAgentResults(e, t) {
|
|
273
|
-
await this.ipc.call("onAgenticAgentResults", e, t);
|
|
279
|
+
async onAgenticAgentResults(e, t, i = null) {
|
|
280
|
+
await this.ipc.call("onAgenticAgentResults", e, t, i);
|
|
274
281
|
}
|
|
275
|
-
async onAgenticStreamComplete() {
|
|
276
|
-
await this.ipc.call("onAgenticStreamComplete");
|
|
282
|
+
async onAgenticStreamComplete(e = null) {
|
|
283
|
+
await this.ipc.call("onAgenticStreamComplete", e);
|
|
277
284
|
}
|
|
278
285
|
async onAgenticIssueStatusChanged(e, t, i) {
|
|
279
286
|
await this.ipc.call("onAgenticIssueStatusChanged", e, t, i);
|
|
@@ -323,14 +330,14 @@ var L = class {
|
|
|
323
330
|
async getSelectedContent(e) {
|
|
324
331
|
return await this.ipcAdapter.getSelectedContent(e);
|
|
325
332
|
}
|
|
326
|
-
async replaceContent(e, t) {
|
|
327
|
-
await this.ipcAdapter.replaceContent(e, t);
|
|
333
|
+
async replaceContent(e, t, i = null) {
|
|
334
|
+
await this.ipcAdapter.replaceContent(e, t, i);
|
|
328
335
|
}
|
|
329
|
-
async selectContent(e) {
|
|
330
|
-
await this.ipcAdapter.selectContent(e);
|
|
336
|
+
async selectContent(e, t = null) {
|
|
337
|
+
await this.ipcAdapter.selectContent(e, t);
|
|
331
338
|
}
|
|
332
|
-
async showDialog(e, t, i,
|
|
333
|
-
await this.ipcAdapter.showDialog(e, t, i,
|
|
339
|
+
async showDialog(e, t, i, n) {
|
|
340
|
+
await this.ipcAdapter.showDialog(e, t, i, n);
|
|
334
341
|
}
|
|
335
342
|
async closeDialog() {
|
|
336
343
|
await this.ipcAdapter.closeDialog();
|
|
@@ -338,11 +345,11 @@ var L = class {
|
|
|
338
345
|
async replaceMultipleContents(e) {
|
|
339
346
|
await this.ipcAdapter.replaceMultipleContents(e);
|
|
340
347
|
}
|
|
341
|
-
onAgenticAgentResults(e, t) {
|
|
342
|
-
return this.ipcAdapter.onAgenticAgentResults(e, t);
|
|
348
|
+
onAgenticAgentResults(e, t, i = null) {
|
|
349
|
+
return this.ipcAdapter.onAgenticAgentResults(e, t, i);
|
|
343
350
|
}
|
|
344
|
-
onAgenticStreamComplete() {
|
|
345
|
-
return this.ipcAdapter.onAgenticStreamComplete();
|
|
351
|
+
onAgenticStreamComplete(e = null) {
|
|
352
|
+
return this.ipcAdapter.onAgenticStreamComplete(e);
|
|
346
353
|
}
|
|
347
354
|
onAgenticIssueStatusChanged(e, t, i) {
|
|
348
355
|
return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, i);
|
|
@@ -371,41 +378,41 @@ var L = class {
|
|
|
371
378
|
iframe;
|
|
372
379
|
window;
|
|
373
380
|
targetOrigin;
|
|
374
|
-
constructor(e, t, i,
|
|
375
|
-
this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin =
|
|
381
|
+
constructor(e, t, i, n, r = "*") {
|
|
382
|
+
this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin = r, this.ipc = new L((a) => {
|
|
376
383
|
this.iframe.contentWindow?.postMessage(a, this.targetOrigin);
|
|
377
|
-
},
|
|
384
|
+
}, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
|
|
378
385
|
}
|
|
379
386
|
handleMessage = (e) => {
|
|
380
387
|
const t = this.window.location.origin, i = this.targetOrigin;
|
|
381
388
|
e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
|
|
382
389
|
};
|
|
383
390
|
registerReceivers() {
|
|
384
|
-
if (this.ipc.receive("getInitConfig", async () => await this.plugin.getInitConfig()), this.ipc.receive("getContent", async () => await this.plugin.getContent()), this.ipc.receive("getSelectedContent", async () => await this.plugin.getSelectedContent()), this.ipc.receive("replaceContent", async (e, t) => {
|
|
385
|
-
await this.plugin.replaceContent(e, t);
|
|
386
|
-
}), this.ipc.receive("selectContent", async (e) => {
|
|
387
|
-
await this.plugin.selectContent(e);
|
|
388
|
-
}), this.ipc.receive("showDialog", async (e, t, i,
|
|
391
|
+
if (this.ipc.receive("getInitConfig", async () => await this.plugin.getInitConfig()), this.ipc.receive("getContent", async () => await this.plugin.getContent()), this.ipc.receive("getSelectedContent", async () => await this.plugin.getSelectedContent()), this.ipc.receive("replaceContent", async (e, t, i) => {
|
|
392
|
+
await this.plugin.replaceContent(e, t, typeof i == "string" ? i : null);
|
|
393
|
+
}), this.ipc.receive("selectContent", async (e, t) => {
|
|
394
|
+
await this.plugin.selectContent(e, typeof t == "string" ? t : null);
|
|
395
|
+
}), this.ipc.receive("showDialog", async (e, t, i, n) => {
|
|
389
396
|
if (!this.plugin.showDialog) throw new Error("SidebarIPCAdapter: host does not implement showDialog");
|
|
390
|
-
await this.plugin.showDialog(e, t, i,
|
|
397
|
+
await this.plugin.showDialog(e, t, i, n);
|
|
391
398
|
}), this.ipc.receive("closeDialog", async () => {
|
|
392
399
|
if (!this.plugin.closeDialog) throw new Error("SidebarIPCAdapter: host does not implement closeDialog");
|
|
393
400
|
await this.plugin.closeDialog();
|
|
394
401
|
}), this.ipc.receive("replaceMultipleContents", async (e) => {
|
|
395
402
|
await this.plugin.replaceMultipleContents(e);
|
|
396
|
-
}), this.ipc.receive("onAgenticAgentResults", async (e, t) => {
|
|
403
|
+
}), this.ipc.receive("onAgenticAgentResults", async (e, t, i) => {
|
|
397
404
|
if (!Array.isArray(t))
|
|
398
405
|
return;
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
}), this.ipc.receive("onAgenticStreamComplete", async () => {
|
|
402
|
-
const
|
|
403
|
-
|
|
406
|
+
const n = this.plugin.onAgenticAgentResults;
|
|
407
|
+
n && await n(e, t, typeof i == "string" ? i : null);
|
|
408
|
+
}), this.ipc.receive("onAgenticStreamComplete", async (e) => {
|
|
409
|
+
const t = this.plugin.onAgenticStreamComplete;
|
|
410
|
+
t && await t(typeof e == "string" ? e : null);
|
|
404
411
|
}), this.ipc.receive("onAgenticIssueStatusChanged", async (e, t, i) => {
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
412
|
+
const n = this.plugin.onAgenticIssueStatusChanged;
|
|
413
|
+
if (n && !(t !== "active" && t !== "resolved" && t !== "dismissed" || i !== "user" && i !== "host"))
|
|
407
414
|
try {
|
|
408
|
-
await
|
|
415
|
+
await n(e, t, i);
|
|
409
416
|
} catch {
|
|
410
417
|
}
|
|
411
418
|
}), this.plugin.openAuthUrl) {
|
|
@@ -427,8 +434,8 @@ var L = class {
|
|
|
427
434
|
});
|
|
428
435
|
}
|
|
429
436
|
}
|
|
430
|
-
async activateAgenticIssue(e) {
|
|
431
|
-
await this.ipc.call("activateAgenticIssue", e);
|
|
437
|
+
async activateAgenticIssue(e, t = null) {
|
|
438
|
+
await this.ipc.call("activateAgenticIssue", e, t);
|
|
432
439
|
}
|
|
433
440
|
async invalidateAgenticIssue(e) {
|
|
434
441
|
await this.ipc.call("invalidateAgenticIssue", e);
|
|
@@ -448,6 +455,9 @@ var L = class {
|
|
|
448
455
|
async getIntegrationSettings() {
|
|
449
456
|
return await this.ipc.call("getIntegrationSettings");
|
|
450
457
|
}
|
|
458
|
+
async notifyActiveDocumentChanged(e) {
|
|
459
|
+
await this.ipc.call("onActiveDocumentChanged", e);
|
|
460
|
+
}
|
|
451
461
|
configure(e) {
|
|
452
462
|
this.ipc.configure(e);
|
|
453
463
|
}
|
|
@@ -465,8 +475,8 @@ var L = class {
|
|
|
465
475
|
async notifyPluginStatus(e, t) {
|
|
466
476
|
await this.ipcAdapter.notifyPluginStatus(e, t);
|
|
467
477
|
}
|
|
468
|
-
async activateAgenticIssue(e) {
|
|
469
|
-
await this.ipcAdapter.activateAgenticIssue(e);
|
|
478
|
+
async activateAgenticIssue(e, t = null) {
|
|
479
|
+
await this.ipcAdapter.activateAgenticIssue(e, t);
|
|
470
480
|
}
|
|
471
481
|
async invalidateAgenticIssue(e) {
|
|
472
482
|
await this.ipcAdapter.invalidateAgenticIssue(e);
|
|
@@ -483,6 +493,9 @@ var L = class {
|
|
|
483
493
|
async getIntegrationSettings() {
|
|
484
494
|
return await this.ipcAdapter.getIntegrationSettings();
|
|
485
495
|
}
|
|
496
|
+
async notifyActiveDocumentChanged(e) {
|
|
497
|
+
await this.ipcAdapter.notifyActiveDocumentChanged(e);
|
|
498
|
+
}
|
|
486
499
|
configure(e) {
|
|
487
500
|
this.ipcAdapter.configure(e);
|
|
488
501
|
}
|
|
@@ -615,14 +628,14 @@ var L = class {
|
|
|
615
628
|
i.id = E, i.textContent = Y, t.head.appendChild(i);
|
|
616
629
|
}, X = 8e3, K = 12e3, q = (e, t, i = {}) => {
|
|
617
630
|
V(e.ownerDocument);
|
|
618
|
-
const { sidebarUrl:
|
|
619
|
-
if (
|
|
631
|
+
const { sidebarUrl: n, targetOrigin: r, timeoutMs: a = X, retryIntervalMs: o = K, messageListenWindow: s } = i, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => n ?? t.src, N = () => {
|
|
632
|
+
if (r) return r;
|
|
620
633
|
try {
|
|
621
634
|
return new URL(p()).origin;
|
|
622
635
|
} catch {
|
|
623
636
|
return "*";
|
|
624
637
|
}
|
|
625
|
-
}, { overlay: y, button:
|
|
638
|
+
}, { overlay: y, button: v } = J();
|
|
626
639
|
e.appendChild(y);
|
|
627
640
|
let u = !1, h, d;
|
|
628
641
|
const g = (c) => {
|
|
@@ -631,13 +644,13 @@ var L = class {
|
|
|
631
644
|
g(!1);
|
|
632
645
|
const f = () => {
|
|
633
646
|
h && (globalThis.clearTimeout(h), h = void 0);
|
|
634
|
-
},
|
|
647
|
+
}, I = () => {
|
|
635
648
|
f(), h = globalThis.setTimeout(() => {
|
|
636
649
|
u || g(!0);
|
|
637
650
|
}, a);
|
|
638
651
|
}, A = (c) => {
|
|
639
652
|
const m = c?.preserveOverlay ?? !0;
|
|
640
|
-
u = !1, m || g(!1), t.src = p(),
|
|
653
|
+
u = !1, m || g(!1), t.src = p(), I();
|
|
641
654
|
}, B = () => {
|
|
642
655
|
d || o <= 0 || (d = globalThis.setInterval(() => {
|
|
643
656
|
u || A({ preserveOverlay: !0 });
|
|
@@ -653,8 +666,8 @@ var L = class {
|
|
|
653
666
|
}, S = () => {
|
|
654
667
|
A();
|
|
655
668
|
};
|
|
656
|
-
return
|
|
657
|
-
f(), C(), t.removeEventListener("error", w), l.removeEventListener("message", b),
|
|
669
|
+
return v.addEventListener("click", S), t.addEventListener("error", w), l.addEventListener("message", b), I(), B(), () => {
|
|
670
|
+
f(), C(), t.removeEventListener("error", w), l.removeEventListener("message", b), v.removeEventListener("click", S), y.remove();
|
|
658
671
|
};
|
|
659
672
|
}, Z = "Markup AI Sidebar", Q = "clipboard-read; clipboard-write", fe = "markupai.sidebarNextGen.overrideUrl", me = "https://sidebar.markup.ai/";
|
|
660
673
|
function ye(e) {
|
|
@@ -665,19 +678,19 @@ function ye(e) {
|
|
|
665
678
|
}
|
|
666
679
|
}
|
|
667
680
|
var ee = "markupai.sidebarNextGen.authOverride";
|
|
668
|
-
function
|
|
681
|
+
function ve(e, t) {
|
|
669
682
|
if (!t) return e;
|
|
670
683
|
try {
|
|
671
684
|
if (!("localStorage" in globalThis)) return e;
|
|
672
685
|
const i = globalThis.localStorage.getItem(ee)?.trim();
|
|
673
686
|
if (!i) return e;
|
|
674
|
-
const
|
|
675
|
-
return
|
|
687
|
+
const n = JSON.parse(i);
|
|
688
|
+
return n !== null && typeof n == "object" && "type" in n && (n.type === "mediation" || n.type === "popup") ? n : e;
|
|
676
689
|
} catch {
|
|
677
690
|
return e;
|
|
678
691
|
}
|
|
679
692
|
}
|
|
680
|
-
function
|
|
693
|
+
function Ie(e, t) {
|
|
681
694
|
try {
|
|
682
695
|
return new URL(e).origin;
|
|
683
696
|
} catch (i) {
|
|
@@ -695,8 +708,8 @@ function te(e) {
|
|
|
695
708
|
removeMountedIframe: null
|
|
696
709
|
};
|
|
697
710
|
if (i === void 0) throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
|
|
698
|
-
const { container:
|
|
699
|
-
return o.title = Z, o.src =
|
|
711
|
+
const { container: n, src: r, allow: a = Q } = i, o = document.createElement("iframe");
|
|
712
|
+
return o.title = Z, o.src = r, a && o.setAttribute("allow", a), n.appendChild(o), {
|
|
700
713
|
iframe: o,
|
|
701
714
|
removeMountedIframe: () => {
|
|
702
715
|
o.remove();
|
|
@@ -704,9 +717,9 @@ function te(e) {
|
|
|
704
717
|
};
|
|
705
718
|
}
|
|
706
719
|
function Ce(e) {
|
|
707
|
-
const { plugin: t, loadOverlayContainer: i, loadOverlayOptions:
|
|
720
|
+
const { plugin: t, loadOverlayContainer: i, loadOverlayOptions: n, adapterOptions: r } = e, { iframe: a, removeMountedIframe: o } = te(e), s = i !== void 0 ? q(i, a, n ?? {}) : null;
|
|
708
721
|
if (t !== void 0) {
|
|
709
|
-
const l = new W(t, a,
|
|
722
|
+
const l = new W(t, a, r);
|
|
710
723
|
return {
|
|
711
724
|
iframe: a,
|
|
712
725
|
adapter: l,
|
|
@@ -759,30 +772,30 @@ var be = k();
|
|
|
759
772
|
function ie(e) {
|
|
760
773
|
return e instanceof Document ? e : e.ownerDocument;
|
|
761
774
|
}
|
|
762
|
-
function
|
|
775
|
+
function ne(e, t, i) {
|
|
763
776
|
if (!t || e.getElementById(R)) return;
|
|
764
|
-
const
|
|
765
|
-
|
|
777
|
+
const n = e.createElement("style");
|
|
778
|
+
n.id = R, n.textContent = k(i), e.head.appendChild(n);
|
|
766
779
|
}
|
|
767
780
|
function we(e) {
|
|
768
|
-
const { root: t = typeof document < "u" ? document : void 0, containerId: i = M, includeDefaultStyles:
|
|
781
|
+
const { root: t = typeof document < "u" ? document : void 0, containerId: i = M, includeDefaultStyles: n = !0 } = e ?? {};
|
|
769
782
|
if (t === void 0) throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
const a = t instanceof Document ?
|
|
783
|
+
const r = ie(t);
|
|
784
|
+
ne(r, n, i);
|
|
785
|
+
const a = t instanceof Document ? r.getElementById(i) : t.querySelector(`#${_(i)}`);
|
|
773
786
|
if (a instanceof HTMLElement && (t instanceof Document || t.contains(a))) return a;
|
|
774
787
|
if (!(t instanceof Document)) {
|
|
775
|
-
const s =
|
|
788
|
+
const s = r.createElement("div");
|
|
776
789
|
return s.id = i, t.appendChild(s), s;
|
|
777
790
|
}
|
|
778
|
-
const o =
|
|
779
|
-
return o.id = i,
|
|
791
|
+
const o = r.createElement("div");
|
|
792
|
+
return o.id = i, r.body.appendChild(o), o;
|
|
780
793
|
}
|
|
781
|
-
function
|
|
794
|
+
function re() {
|
|
782
795
|
return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
|
|
783
796
|
}
|
|
784
797
|
function Se(e) {
|
|
785
|
-
const { title: t = "Markup AI Sidebar", headInnerHtml: i = "", includePluginHostHead:
|
|
798
|
+
const { title: t = "Markup AI Sidebar", headInnerHtml: i = "", includePluginHostHead: n = !1, bodyScriptsHtml: r, htmlLang: a = "en", htmlAttrs: o = `lang="${a}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [n ? re() : "", i].filter((p) => p.trim().length > 0).join(`
|
|
786
799
|
`);
|
|
787
800
|
return `<!DOCTYPE html>
|
|
788
801
|
<html ${o}>
|
|
@@ -793,7 +806,7 @@ function Se(e) {
|
|
|
793
806
|
${l}` : ""}
|
|
794
807
|
</head>
|
|
795
808
|
<body ${s}>
|
|
796
|
-
${
|
|
809
|
+
${r}
|
|
797
810
|
</body>
|
|
798
811
|
</html>
|
|
799
812
|
`;
|
|
@@ -824,10 +837,10 @@ export {
|
|
|
824
837
|
ue as buildDocumentReference,
|
|
825
838
|
Se as buildSidebarHostHtmlDocument,
|
|
826
839
|
k as buildSidebarHostShellCss,
|
|
827
|
-
|
|
840
|
+
re as buildSidebarPluginHostHeadInnerHtml,
|
|
828
841
|
Ce as createSidebarHost,
|
|
829
842
|
we as ensureSidebarHostShell,
|
|
830
|
-
|
|
843
|
+
ve as getAuthConfigWithOverride,
|
|
831
844
|
ye as getSidebarBaseUrlWithOverride,
|
|
832
845
|
P as ipcErrorReconstructors,
|
|
833
846
|
pe as isDocumentReference,
|
|
@@ -836,5 +849,5 @@ export {
|
|
|
836
849
|
ge as isTextLookupError,
|
|
837
850
|
U as reconstructError,
|
|
838
851
|
q as setupSidebarLoadOverlay,
|
|
839
|
-
|
|
852
|
+
Ie as sidebarPostMessageTargetOrigin
|
|
840
853
|
};
|
package/dist/main.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(n,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(n=typeof globalThis<"u"?globalThis:n||self,g(n.main={}))})(this,function(n){Object.defineProperty(n,Symbol.toStringTag,{value:"Module"});var g=(function(e){return e.TEXT_PLAIN="text/plain",e.TEXT_MARKDOWN="text/markdown",e.TEXT_HTML="text/html",e.APPLICATION_DITA_XML="application/dita+xml",e})({}),K=["text/plain","text/markdown","text/html","application/dita+xml"],X={integrationName:"unknown",integrationVersion:"unknown",integrationId:"markupai-sidebar-app",hideBanner:!1,dialogClosingScript:void 0,useCheckPreviewDialog:!1,supportCheckSelection:!0,multiAgent:!1},q=e=>typeof e!="object"||e===null?!1:Array.isArray(e.fields),Z=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return typeof t.id!="string"||t.id.length===0||typeof t.label!="string"?!1:t.type==="boolean"?typeof t.default=="boolean":t.type==="enum"?typeof t.default!="string"||!Array.isArray(t.options)||t.options.length===0?!1:t.options.every(i=>{if(typeof i!="object"||i===null)return!1;const r=i;return typeof r.value=="string"&&typeof r.label=="string"}):!1},A=class V extends Error{name="TextLookupError";constructor(t){super(t),Object.setPrototypeOf(this,V.prototype)}};function Q(e){return e instanceof A}var v={TextLookupError:e=>new A(e)};function E(e){const t=e.message??"",i=e.name,r=typeof i=="string"&&i in v?v[i]:void 0;return r?r(t,e):Object.assign(new Error(t),i?{name:i}:{})}var P=":",R=/^[a-z][a-z0-9-]*$/;function ee(e){const t=e.indexOf(P);return t<=0||t===e.length-1?!1:R.test(e.slice(0,t))}function te(e,t){const i=e.trim().toLowerCase(),r=t.trim();if(!R.test(i))throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);if(r.length===0)throw new Error("Invalid document reference: the document id is empty.");const a=`${i}${P}`;return r.startsWith(a)?r:`${a}${r}`}var T=class extends Promise{static get[Symbol.species](){return Promise}resolve;reject;constructor(e=()=>{}){let t,i;super((r,a)=>{t=r,i=a,e(r,a)}),this.resolve=t,this.reject=i}},O={timeout:1e4};function ie(e){const t=JSON.stringify(e,Object.getOwnPropertyNames(e)),i=JSON.parse(t);return i.message===void 0||i.message===""?JSON.stringify({message:e instanceof Error?e.message:String(e),name:e instanceof Error?e.name:void 0}):t}var C=class{promisesByID={};receiversByName={};currentID=0;config;postMessage;constructor(e,t){this.postMessage=e,this.config={...O,...t}}configure(e){this.config={...this.config,...e}}call(e,...t){return this.callWithOptions(e,{},...t)}callWithOptions(e,t,...i){const r=this.currentID++,a=new T,o=t.timeout??this.config.timeout,s=setTimeout(()=>{if(r in this.promisesByID){const c=new Error(`IPC call timeout: "${e}" did not respond within ${String(o)}ms`);a.reject(c),Reflect.deleteProperty(this.promisesByID,r)}},o);this.promisesByID[r]={promise:a,timeoutId:s};const l={type:"call",id:r,name:e,data:i};return this.postMessage(l),a}receive(e,t){this.receiversByName[e]=t}ignore(e){delete this.receiversByName[e]}async handleMessage(e){switch(e.type){case"call":await this.handleCall(e);break;case"response":this.handleResponse(e);break;case"error":this.handleError(e);break;default:}}async handleCall(e){const{id:t,name:i,data:r}=e;if(!(i in this.receiversByName)){const o=new Error(`No receiver registered for: ${i}`),s=JSON.stringify({message:o.message,name:o.name});this.postMessage({type:"error",id:t,name:i,errorJSON:s});return}const a=this.receiversByName[i];try{if(!Array.isArray(r))throw new TypeError(`IPC: Expected array of arguments but got ${typeof r}`);const o=await a(...r),s={type:"response",id:t,name:i,data:o};this.postMessage(s)}catch(o){const s={type:"error",id:t,name:i,errorJSON:ie(o)};this.postMessage(s)}}handleResponse(e){const{id:t}=e;if(t in this.promisesByID){const{promise:i,timeoutId:r}=this.promisesByID[t];clearTimeout(r),i.resolve(e.data),Reflect.deleteProperty(this.promisesByID,t)}}handleError(e){const{id:t,errorJSON:i}=e;if(t in this.promisesByID){const{promise:r,timeoutId:a}=this.promisesByID[t];clearTimeout(a);try{const o=E(JSON.parse(i));r.reject(o)}catch{r.reject(new Error("Failed to parse error from IPC"))}Reflect.deleteProperty(this.promisesByID,t)}}destroy(){for(const{promise:e,timeoutId:t}of Object.values(this.promisesByID))clearTimeout(t),e.reject(new Error("IPC destroyed"));this.promisesByID={},this.receiversByName={}}},D=class{ipc;sidebar;targetOrigin;constructor(e,t,i="*"){this.sidebar=e||{},this.targetOrigin=i,this.ipc=new C(r=>{window.parent.postMessage(r,this.targetOrigin)},t),window.addEventListener("message",this.handleMessage),this.registerReceivers()}handleMessage=e=>{const t=globalThis.window.location.origin,i=this.targetOrigin;e.origin!==t&&(i!=="*"&&e.origin!==i||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.sidebar.onPluginStatusChange){const e=this.sidebar.onPluginStatusChange;this.ipc.receive("onPluginStatusChange",async(t,i)=>{await e(t,i)})}if(this.sidebar.activateAgenticIssue){const e=this.sidebar.activateAgenticIssue;this.ipc.receive("activateAgenticIssue",async t=>{await e(t)})}if(this.sidebar.invalidateAgenticIssue){const e=this.sidebar.invalidateAgenticIssue;this.ipc.receive("invalidateAgenticIssue",async t=>{await e(t)})}if(this.sidebar.markAgenticIssueResolved){const e=this.sidebar.markAgenticIssueResolved;this.ipc.receive("markAgenticIssueResolved",async t=>{await e(t)})}if(this.sidebar.restoreAgenticIssue){const e=this.sidebar.restoreAgenticIssue;this.ipc.receive("restoreAgenticIssue",async t=>{await e(t)})}if(this.sidebar.applyIntegrationSettings){const e=this.sidebar.applyIntegrationSettings;this.ipc.receive("applyIntegrationSettings",async t=>{await e(t)})}if(this.sidebar.getIntegrationSettings){const e=this.sidebar.getIntegrationSettings;this.ipc.receive("getIntegrationSettings",async()=>await e())}}async getInitConfig(){return await this.ipc.call("getInitConfig")}async getContent(e){return this.ipc.callWithOptions("getContent",e??{})}async getSelectedContent(e){return this.ipc.callWithOptions("getSelectedContent",e??{})}async replaceContent(e,t){await this.ipc.call("replaceContent",e,t)}async selectContent(e){await this.ipc.call("selectContent",e)}async showDialog(e,t,i,r){await this.ipc.call("showDialog",e,t,i,r)}async closeDialog(){await this.ipc.call("closeDialog")}async replaceMultipleContents(e){await this.ipc.call("replaceMultipleContents",e)}async onAgenticAgentResults(e,t){await this.ipc.call("onAgenticAgentResults",e,t)}async onAgenticStreamComplete(){await this.ipc.call("onAgenticStreamComplete")}async onAgenticIssueStatusChanged(e,t,i){await this.ipc.call("onAgenticIssueStatusChanged",e,t,i)}async openAuthUrl(e){await this.ipc.call("openAuthUrl",e)}async copyToClipboard(e){await this.ipc.call("copyToClipboard",e)}async onIntegrationSettingsChange(e,t){await this.ipc.call("onIntegrationSettingsChange",e,t)}configure(e){this.ipc.configure(e)}setTargetOrigin(e){if(!e||typeof e!="string")throw new Error("Invalid targetOrigin: must be a non-empty string");try{const t=new URL(e);if(!["http:","https:"].includes(t.protocol)||!t.host)throw new Error("Invalid targetOrigin: protocol must be http or https and must have a host")}catch{throw new Error("Invalid targetOrigin: must be a valid origin (e.g., https://example.com)")}this.targetOrigin=e}getTargetOrigin(){return this.targetOrigin}destroy(){window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},re=class{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new D(e,t,i)}destroy(){this.ipcAdapter.destroy()}async getInitConfig(){return await this.ipcAdapter.getInitConfig()}async getContent(e){return await this.ipcAdapter.getContent(e)}async getSelectedContent(e){return await this.ipcAdapter.getSelectedContent(e)}async replaceContent(e,t){await this.ipcAdapter.replaceContent(e,t)}async selectContent(e){await this.ipcAdapter.selectContent(e)}async showDialog(e,t,i,r){await this.ipcAdapter.showDialog(e,t,i,r)}async closeDialog(){await this.ipcAdapter.closeDialog()}async replaceMultipleContents(e){await this.ipcAdapter.replaceMultipleContents(e)}onAgenticAgentResults(e,t){return this.ipcAdapter.onAgenticAgentResults(e,t)}onAgenticStreamComplete(){return this.ipcAdapter.onAgenticStreamComplete()}onAgenticIssueStatusChanged(e,t,i){return this.ipcAdapter.onAgenticIssueStatusChanged(e,t,i)}openAuthUrl(e){return this.ipcAdapter.openAuthUrl(e)}copyToClipboard(e){return this.ipcAdapter.copyToClipboard(e)}onIntegrationSettingsChange(e,t){return this.ipcAdapter.onIntegrationSettingsChange(e,t)}configure(e){this.ipcAdapter.configure(e)}setTargetOrigin(e){this.ipcAdapter.setTargetOrigin(e)}getTargetOrigin(){return this.ipcAdapter.getTargetOrigin()}},_=class{ipc;plugin;iframe;window;targetOrigin;constructor(e,t,i,r,a="*"){this.plugin=e,this.iframe=t,this.window=i??window,this.targetOrigin=a,this.ipc=new C(o=>{this.iframe.contentWindow?.postMessage(o,this.targetOrigin)},r),this.window.addEventListener("message",this.handleMessage,!1),this.registerReceivers()}handleMessage=e=>{const t=this.window.location.origin,i=this.targetOrigin;e.origin!==t&&(i!=="*"&&e.origin!==i||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.ipc.receive("getInitConfig",async()=>await this.plugin.getInitConfig()),this.ipc.receive("getContent",async()=>await this.plugin.getContent()),this.ipc.receive("getSelectedContent",async()=>await this.plugin.getSelectedContent()),this.ipc.receive("replaceContent",async(e,t)=>{await this.plugin.replaceContent(e,t)}),this.ipc.receive("selectContent",async e=>{await this.plugin.selectContent(e)}),this.ipc.receive("showDialog",async(e,t,i,r)=>{if(!this.plugin.showDialog)throw new Error("SidebarIPCAdapter: host does not implement showDialog");await this.plugin.showDialog(e,t,i,r)}),this.ipc.receive("closeDialog",async()=>{if(!this.plugin.closeDialog)throw new Error("SidebarIPCAdapter: host does not implement closeDialog");await this.plugin.closeDialog()}),this.ipc.receive("replaceMultipleContents",async e=>{await this.plugin.replaceMultipleContents(e)}),this.ipc.receive("onAgenticAgentResults",async(e,t)=>{if(!Array.isArray(t))return;const i=this.plugin.onAgenticAgentResults;i&&await i(e,t)}),this.ipc.receive("onAgenticStreamComplete",async()=>{const e=this.plugin.onAgenticStreamComplete;e&&await e()}),this.ipc.receive("onAgenticIssueStatusChanged",async(e,t,i)=>{const r=this.plugin.onAgenticIssueStatusChanged;if(r&&!(t!=="active"&&t!=="resolved"&&t!=="dismissed"||i!=="user"&&i!=="host"))try{await r(e,t,i)}catch{}}),this.plugin.openAuthUrl){const e=this.plugin.openAuthUrl;this.ipc.receive("openAuthUrl",async t=>{await e(t)})}if(this.plugin.copyToClipboard){const e=this.plugin.copyToClipboard;this.ipc.receive("copyToClipboard",async t=>{await e(t)})}if(this.plugin.onIntegrationSettingsChange){const e=this.plugin.onIntegrationSettingsChange;this.ipc.receive("onIntegrationSettingsChange",async(t,i)=>{await e(t,i)})}}async activateAgenticIssue(e){await this.ipc.call("activateAgenticIssue",e)}async invalidateAgenticIssue(e){await this.ipc.call("invalidateAgenticIssue",e)}async markAgenticIssueResolved(e){await this.ipc.call("markAgenticIssueResolved",e)}async restoreAgenticIssue(e){await this.ipc.call("restoreAgenticIssue",e)}async notifyPluginStatus(e,t){await this.ipc.call("onPluginStatusChange",e,t)}async applyIntegrationSettings(e){await this.ipc.call("applyIntegrationSettings",e)}async getIntegrationSettings(){return await this.ipc.call("getIntegrationSettings")}configure(e){this.ipc.configure(e)}destroy(){this.window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},L=class{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new _(e,t,i?.win,i?.config,i?.targetOrigin)}destroy(){this.ipcAdapter.destroy()}async notifyPluginStatus(e,t){await this.ipcAdapter.notifyPluginStatus(e,t)}async activateAgenticIssue(e){await this.ipcAdapter.activateAgenticIssue(e)}async invalidateAgenticIssue(e){await this.ipcAdapter.invalidateAgenticIssue(e)}async markAgenticIssueResolved(e){await this.ipcAdapter.markAgenticIssueResolved(e)}async restoreAgenticIssue(e){await this.ipcAdapter.restoreAgenticIssue(e)}async applyIntegrationSettings(e){await this.ipcAdapter.applyIntegrationSettings(e)}async getIntegrationSettings(){return await this.ipcAdapter.getIntegrationSettings()}configure(e){this.ipcAdapter.configure(e)}},ne=`
|
|
1
|
+
(function(r,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(r=typeof globalThis<"u"?globalThis:r||self,g(r.main={}))})(this,function(r){Object.defineProperty(r,Symbol.toStringTag,{value:"Module"});var g=(function(e){return e.TEXT_PLAIN="text/plain",e.TEXT_MARKDOWN="text/markdown",e.TEXT_HTML="text/html",e.APPLICATION_DITA_XML="application/dita+xml",e})({}),K=["text/plain","text/markdown","text/html","application/dita+xml"],X={integrationName:"unknown",integrationVersion:"unknown",integrationId:"markupai-sidebar-app",hideBanner:!1,dialogClosingScript:void 0,useCheckPreviewDialog:!1,supportCheckSelection:!0,multiAgent:!1,multiDocument:!1},q=e=>typeof e!="object"||e===null?!1:Array.isArray(e.fields),Z=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return typeof t.id!="string"||t.id.length===0||typeof t.label!="string"?!1:t.type==="boolean"?typeof t.default=="boolean":t.type==="enum"?typeof t.default!="string"||!Array.isArray(t.options)||t.options.length===0?!1:t.options.every(i=>{if(typeof i!="object"||i===null)return!1;const n=i;return typeof n.value=="string"&&typeof n.label=="string"}):!1},A=class V extends Error{name="TextLookupError";constructor(t){super(t),Object.setPrototypeOf(this,V.prototype)}};function Q(e){return e instanceof A}var v={TextLookupError:e=>new A(e)};function E(e){const t=e.message??"",i=e.name,n=typeof i=="string"&&i in v?v[i]:void 0;return n?n(t,e):Object.assign(new Error(t),i?{name:i}:{})}var P=":",R=/^[a-z][a-z0-9-]*$/;function ee(e){const t=e.indexOf(P);return t<=0||t===e.length-1?!1:R.test(e.slice(0,t))}function te(e,t){const i=e.trim().toLowerCase(),n=t.trim();if(!R.test(i))throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);if(n.length===0)throw new Error("Invalid document reference: the document id is empty.");const a=`${i}${P}`;return n.startsWith(a)?n:`${a}${n}`}var T=class extends Promise{static get[Symbol.species](){return Promise}resolve;reject;constructor(e=()=>{}){let t,i;super((n,a)=>{t=n,i=a,e(n,a)}),this.resolve=t,this.reject=i}},D={timeout:1e4};function ie(e){const t=JSON.stringify(e,Object.getOwnPropertyNames(e)),i=JSON.parse(t);return i.message===void 0||i.message===""?JSON.stringify({message:e instanceof Error?e.message:String(e),name:e instanceof Error?e.name:void 0}):t}var C=class{promisesByID={};receiversByName={};currentID=0;config;postMessage;constructor(e,t){this.postMessage=e,this.config={...D,...t}}configure(e){this.config={...this.config,...e}}call(e,...t){return this.callWithOptions(e,{},...t)}callWithOptions(e,t,...i){const n=this.currentID++,a=new T,o=t.timeout??this.config.timeout,s=setTimeout(()=>{if(n in this.promisesByID){const c=new Error(`IPC call timeout: "${e}" did not respond within ${String(o)}ms`);a.reject(c),Reflect.deleteProperty(this.promisesByID,n)}},o);this.promisesByID[n]={promise:a,timeoutId:s};const l={type:"call",id:n,name:e,data:i};return this.postMessage(l),a}receive(e,t){this.receiversByName[e]=t}ignore(e){delete this.receiversByName[e]}async handleMessage(e){switch(e.type){case"call":await this.handleCall(e);break;case"response":this.handleResponse(e);break;case"error":this.handleError(e);break;default:}}async handleCall(e){const{id:t,name:i,data:n}=e;if(!(i in this.receiversByName)){const o=new Error(`No receiver registered for: ${i}`),s=JSON.stringify({message:o.message,name:o.name});this.postMessage({type:"error",id:t,name:i,errorJSON:s});return}const a=this.receiversByName[i];try{if(!Array.isArray(n))throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);const o=await a(...n),s={type:"response",id:t,name:i,data:o};this.postMessage(s)}catch(o){const s={type:"error",id:t,name:i,errorJSON:ie(o)};this.postMessage(s)}}handleResponse(e){const{id:t}=e;if(t in this.promisesByID){const{promise:i,timeoutId:n}=this.promisesByID[t];clearTimeout(n),i.resolve(e.data),Reflect.deleteProperty(this.promisesByID,t)}}handleError(e){const{id:t,errorJSON:i}=e;if(t in this.promisesByID){const{promise:n,timeoutId:a}=this.promisesByID[t];clearTimeout(a);try{const o=E(JSON.parse(i));n.reject(o)}catch{n.reject(new Error("Failed to parse error from IPC"))}Reflect.deleteProperty(this.promisesByID,t)}}destroy(){for(const{promise:e,timeoutId:t}of Object.values(this.promisesByID))clearTimeout(t),e.reject(new Error("IPC destroyed"));this.promisesByID={},this.receiversByName={}}},O=class{ipc;sidebar;targetOrigin;constructor(e,t,i="*"){this.sidebar=e||{},this.targetOrigin=i,this.ipc=new C(n=>{window.parent.postMessage(n,this.targetOrigin)},t),window.addEventListener("message",this.handleMessage),this.registerReceivers()}handleMessage=e=>{const t=globalThis.window.location.origin,i=this.targetOrigin;e.origin!==t&&(i!=="*"&&e.origin!==i||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.sidebar.onPluginStatusChange){const e=this.sidebar.onPluginStatusChange;this.ipc.receive("onPluginStatusChange",async(t,i)=>{await e(t,i)})}if(this.sidebar.activateAgenticIssue){const e=this.sidebar.activateAgenticIssue;this.ipc.receive("activateAgenticIssue",async(t,i)=>{await e(t,typeof i=="string"?i:null)})}if(this.sidebar.invalidateAgenticIssue){const e=this.sidebar.invalidateAgenticIssue;this.ipc.receive("invalidateAgenticIssue",async t=>{await e(t)})}if(this.sidebar.markAgenticIssueResolved){const e=this.sidebar.markAgenticIssueResolved;this.ipc.receive("markAgenticIssueResolved",async t=>{await e(t)})}if(this.sidebar.restoreAgenticIssue){const e=this.sidebar.restoreAgenticIssue;this.ipc.receive("restoreAgenticIssue",async t=>{await e(t)})}if(this.sidebar.applyIntegrationSettings){const e=this.sidebar.applyIntegrationSettings;this.ipc.receive("applyIntegrationSettings",async t=>{await e(t)})}if(this.sidebar.getIntegrationSettings){const e=this.sidebar.getIntegrationSettings;this.ipc.receive("getIntegrationSettings",async()=>await e())}if(this.sidebar.onActiveDocumentChanged){const e=this.sidebar.onActiveDocumentChanged;this.ipc.receive("onActiveDocumentChanged",async t=>{await e(t)})}}async getInitConfig(){return await this.ipc.call("getInitConfig")}async getContent(e){return this.ipc.callWithOptions("getContent",e??{})}async getSelectedContent(e){return this.ipc.callWithOptions("getSelectedContent",e??{})}async replaceContent(e,t,i=null){await this.ipc.call("replaceContent",e,t,i)}async selectContent(e,t=null){await this.ipc.call("selectContent",e,t)}async showDialog(e,t,i,n){await this.ipc.call("showDialog",e,t,i,n)}async closeDialog(){await this.ipc.call("closeDialog")}async replaceMultipleContents(e){await this.ipc.call("replaceMultipleContents",e)}async onAgenticAgentResults(e,t,i=null){await this.ipc.call("onAgenticAgentResults",e,t,i)}async onAgenticStreamComplete(e=null){await this.ipc.call("onAgenticStreamComplete",e)}async onAgenticIssueStatusChanged(e,t,i){await this.ipc.call("onAgenticIssueStatusChanged",e,t,i)}async openAuthUrl(e){await this.ipc.call("openAuthUrl",e)}async copyToClipboard(e){await this.ipc.call("copyToClipboard",e)}async onIntegrationSettingsChange(e,t){await this.ipc.call("onIntegrationSettingsChange",e,t)}configure(e){this.ipc.configure(e)}setTargetOrigin(e){if(!e||typeof e!="string")throw new Error("Invalid targetOrigin: must be a non-empty string");try{const t=new URL(e);if(!["http:","https:"].includes(t.protocol)||!t.host)throw new Error("Invalid targetOrigin: protocol must be http or https and must have a host")}catch{throw new Error("Invalid targetOrigin: must be a valid origin (e.g., https://example.com)")}this.targetOrigin=e}getTargetOrigin(){return this.targetOrigin}destroy(){window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},ne=class{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new O(e,t,i)}destroy(){this.ipcAdapter.destroy()}async getInitConfig(){return await this.ipcAdapter.getInitConfig()}async getContent(e){return await this.ipcAdapter.getContent(e)}async getSelectedContent(e){return await this.ipcAdapter.getSelectedContent(e)}async replaceContent(e,t,i=null){await this.ipcAdapter.replaceContent(e,t,i)}async selectContent(e,t=null){await this.ipcAdapter.selectContent(e,t)}async showDialog(e,t,i,n){await this.ipcAdapter.showDialog(e,t,i,n)}async closeDialog(){await this.ipcAdapter.closeDialog()}async replaceMultipleContents(e){await this.ipcAdapter.replaceMultipleContents(e)}onAgenticAgentResults(e,t,i=null){return this.ipcAdapter.onAgenticAgentResults(e,t,i)}onAgenticStreamComplete(e=null){return this.ipcAdapter.onAgenticStreamComplete(e)}onAgenticIssueStatusChanged(e,t,i){return this.ipcAdapter.onAgenticIssueStatusChanged(e,t,i)}openAuthUrl(e){return this.ipcAdapter.openAuthUrl(e)}copyToClipboard(e){return this.ipcAdapter.copyToClipboard(e)}onIntegrationSettingsChange(e,t){return this.ipcAdapter.onIntegrationSettingsChange(e,t)}configure(e){this.ipcAdapter.configure(e)}setTargetOrigin(e){this.ipcAdapter.setTargetOrigin(e)}getTargetOrigin(){return this.ipcAdapter.getTargetOrigin()}},_=class{ipc;plugin;iframe;window;targetOrigin;constructor(e,t,i,n,a="*"){this.plugin=e,this.iframe=t,this.window=i??window,this.targetOrigin=a,this.ipc=new C(o=>{this.iframe.contentWindow?.postMessage(o,this.targetOrigin)},n),this.window.addEventListener("message",this.handleMessage,!1),this.registerReceivers()}handleMessage=e=>{const t=this.window.location.origin,i=this.targetOrigin;e.origin!==t&&(i!=="*"&&e.origin!==i||e.data&&typeof e.data=="object"&&this.ipc.handleMessage(e.data))};registerReceivers(){if(this.ipc.receive("getInitConfig",async()=>await this.plugin.getInitConfig()),this.ipc.receive("getContent",async()=>await this.plugin.getContent()),this.ipc.receive("getSelectedContent",async()=>await this.plugin.getSelectedContent()),this.ipc.receive("replaceContent",async(e,t,i)=>{await this.plugin.replaceContent(e,t,typeof i=="string"?i:null)}),this.ipc.receive("selectContent",async(e,t)=>{await this.plugin.selectContent(e,typeof t=="string"?t:null)}),this.ipc.receive("showDialog",async(e,t,i,n)=>{if(!this.plugin.showDialog)throw new Error("SidebarIPCAdapter: host does not implement showDialog");await this.plugin.showDialog(e,t,i,n)}),this.ipc.receive("closeDialog",async()=>{if(!this.plugin.closeDialog)throw new Error("SidebarIPCAdapter: host does not implement closeDialog");await this.plugin.closeDialog()}),this.ipc.receive("replaceMultipleContents",async e=>{await this.plugin.replaceMultipleContents(e)}),this.ipc.receive("onAgenticAgentResults",async(e,t,i)=>{if(!Array.isArray(t))return;const n=this.plugin.onAgenticAgentResults;n&&await n(e,t,typeof i=="string"?i:null)}),this.ipc.receive("onAgenticStreamComplete",async e=>{const t=this.plugin.onAgenticStreamComplete;t&&await t(typeof e=="string"?e:null)}),this.ipc.receive("onAgenticIssueStatusChanged",async(e,t,i)=>{const n=this.plugin.onAgenticIssueStatusChanged;if(n&&!(t!=="active"&&t!=="resolved"&&t!=="dismissed"||i!=="user"&&i!=="host"))try{await n(e,t,i)}catch{}}),this.plugin.openAuthUrl){const e=this.plugin.openAuthUrl;this.ipc.receive("openAuthUrl",async t=>{await e(t)})}if(this.plugin.copyToClipboard){const e=this.plugin.copyToClipboard;this.ipc.receive("copyToClipboard",async t=>{await e(t)})}if(this.plugin.onIntegrationSettingsChange){const e=this.plugin.onIntegrationSettingsChange;this.ipc.receive("onIntegrationSettingsChange",async(t,i)=>{await e(t,i)})}}async activateAgenticIssue(e,t=null){await this.ipc.call("activateAgenticIssue",e,t)}async invalidateAgenticIssue(e){await this.ipc.call("invalidateAgenticIssue",e)}async markAgenticIssueResolved(e){await this.ipc.call("markAgenticIssueResolved",e)}async restoreAgenticIssue(e){await this.ipc.call("restoreAgenticIssue",e)}async notifyPluginStatus(e,t){await this.ipc.call("onPluginStatusChange",e,t)}async applyIntegrationSettings(e){await this.ipc.call("applyIntegrationSettings",e)}async getIntegrationSettings(){return await this.ipc.call("getIntegrationSettings")}async notifyActiveDocumentChanged(e){await this.ipc.call("onActiveDocumentChanged",e)}configure(e){this.ipc.configure(e)}destroy(){this.window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}},L=class{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new _(e,t,i?.win,i?.config,i?.targetOrigin)}destroy(){this.ipcAdapter.destroy()}async notifyPluginStatus(e,t){await this.ipcAdapter.notifyPluginStatus(e,t)}async activateAgenticIssue(e,t=null){await this.ipcAdapter.activateAgenticIssue(e,t)}async invalidateAgenticIssue(e){await this.ipcAdapter.invalidateAgenticIssue(e)}async markAgenticIssueResolved(e){await this.ipcAdapter.markAgenticIssueResolved(e)}async restoreAgenticIssue(e){await this.ipcAdapter.restoreAgenticIssue(e)}async applyIntegrationSettings(e){await this.ipcAdapter.applyIntegrationSettings(e)}async getIntegrationSettings(){return await this.ipcAdapter.getIntegrationSettings()}async notifyActiveDocumentChanged(e){await this.ipcAdapter.notifyActiveDocumentChanged(e)}configure(e){this.ipcAdapter.configure(e)}},re=`
|
|
2
2
|
<div class="sidebar-load-overlay-card">
|
|
3
3
|
<div class="sidebar-load-overlay-title">Sidebar failed to load</div>
|
|
4
4
|
<div class="sidebar-load-overlay-description">Check your connection or try again.</div>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<span>Retry</span>
|
|
20
20
|
</button>
|
|
21
21
|
</div>
|
|
22
|
-
`,ae=()=>{const e=document.createElement("div");e.className="sidebar-load-overlay",e.style.display="none",e.innerHTML=
|
|
22
|
+
`,ae=()=>{const e=document.createElement("div");e.className="sidebar-load-overlay",e.style.display="none",e.innerHTML=re;const t=e.querySelector(".sidebar-load-overlay-button");if(!t)throw new Error("Missing retry button in load overlay template.");return{overlay:e,button:t}},M="markupai-sidebar-load-overlay-styles",oe=`
|
|
23
23
|
:root {
|
|
24
24
|
--background: #f5f5f4;
|
|
25
25
|
--foreground: #333332;
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
box-shadow: 0 0 0 2px
|
|
112
112
|
color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
|
|
113
113
|
}
|
|
114
|
-
`,se=e=>{const t=e??document;if(t.getElementById(M))return;const i=t.createElement("style");i.id=M,i.textContent=oe,t.head.appendChild(i)},le=8e3,ce=12e3,k=(e,t,i={})=>{se(e.ownerDocument);const{sidebarUrl:
|
|
114
|
+
`,se=e=>{const t=e??document;if(t.getElementById(M))return;const i=t.createElement("style");i.id=M,i.textContent=oe,t.head.appendChild(i)},le=8e3,ce=12e3,k=(e,t,i={})=>{se(e.ownerDocument);const{sidebarUrl:n,targetOrigin:a,timeoutMs:o=le,retryIntervalMs:s=ce,messageListenWindow:l}=i,c=l??(typeof globalThis.window<"u"?globalThis.window:globalThis),h=()=>n??t.src,we=()=>{if(a)return a;try{return new URL(h()).origin}catch{return"*"}},{overlay:w,button:j}=ae();e.appendChild(w);let f=!1,m,u;const p=d=>{w.style.display=d?"flex":"none"};p(!1);const I=()=>{m&&(globalThis.clearTimeout(m),m=void 0)},$=()=>{I(),m=globalThis.setTimeout(()=>{f||p(!0)},o)},W=d=>{const y=d?.preserveOverlay??!0;f=!1,y||p(!1),t.src=h(),$()},Ee=()=>{u||s<=0||(u=globalThis.setInterval(()=>{f||W({preserveOverlay:!0})},s))},G=()=>{u&&(globalThis.clearInterval(u),u=void 0)},z=d=>{if(!t.contentWindow||d.source!==t.contentWindow)return;const y=we();y!=="*"&&d.origin!==y||(f=!0,I(),G(),p(!1))},J=()=>{I(),p(!0)},Y=()=>{W()};return j.addEventListener("click",Y),t.addEventListener("error",J),c.addEventListener("message",z),$(),Ee(),()=>{I(),G(),t.removeEventListener("error",J),c.removeEventListener("message",z),j.removeEventListener("click",Y),w.remove()}},N="Markup AI Sidebar",H="clipboard-read; clipboard-write",de="markupai.sidebarNextGen.overrideUrl",ge="https://sidebar.markup.ai/";function ue(e){try{return"localStorage"in globalThis&&globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim()||e}catch{return e}}var U="markupai.sidebarNextGen.authOverride";function pe(e,t){if(!t)return e;try{if(!("localStorage"in globalThis))return e;const i=globalThis.localStorage.getItem(U)?.trim();if(!i)return e;const n=JSON.parse(i);return n!==null&&typeof n=="object"&&"type"in n&&(n.type==="mediation"||n.type==="popup")?n:e}catch{return e}}function he(e,t){try{return new URL(e).origin}catch(i){return t?.onInvalidUrl?.(e,i),"*"}}function fe(e,t="Expected SidebarAdapter from createSidebarHost"){if(e.adapter===null)throw new Error(t)}function me(e){const{iframe:t,iframeMount:i}=e;if(t!==void 0&&i!==void 0)throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");if(t!==void 0)return{iframe:t,removeMountedIframe:null};if(i===void 0)throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");const{container:n,src:a,allow:o=H}=i,s=document.createElement("iframe");return s.title=N,s.src=a,o&&s.setAttribute("allow",o),n.appendChild(s),{iframe:s,removeMountedIframe:()=>{s.remove()}}}function Ie(e){const{plugin:t,loadOverlayContainer:i,loadOverlayOptions:n,adapterOptions:a}=e,{iframe:o,removeMountedIframe:s}=me(e),l=i!==void 0?k(i,o,n??{}):null;if(t!==void 0){const c=new L(t,o,a);return{iframe:o,adapter:c,destroy:()=>{l?.(),c.destroy(),s?.()}}}return{iframe:o,adapter:null,destroy:()=>{l?.(),s?.()}}}var b="sidebarContainer",B="markupai-sidebar-host-shell-styles";function x(e){if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(e);if(!/^[a-zA-Z_][\w-]*$/.test(e))throw new Error(String.raw`sidebar host shell: containerId must match /^[a-zA-Z_][\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(e)})`);return e}function S(e=b){const t=x(e);return`
|
|
115
115
|
html {
|
|
116
116
|
height: 100%;
|
|
117
117
|
}
|
|
@@ -133,7 +133,7 @@ body {
|
|
|
133
133
|
margin: 0;
|
|
134
134
|
display: block;
|
|
135
135
|
}
|
|
136
|
-
`.trim()}var ye=S();function Ae(e){return e instanceof Document?e:e.ownerDocument}function ve(e,t,i){if(!t||e.getElementById(B))return;const
|
|
136
|
+
`.trim()}var ye=S();function Ae(e){return e instanceof Document?e:e.ownerDocument}function ve(e,t,i){if(!t||e.getElementById(B))return;const n=e.createElement("style");n.id=B,n.textContent=S(i),e.head.appendChild(n)}function Ce(e){const{root:t=typeof document<"u"?document:void 0,containerId:i=b,includeDefaultStyles:n=!0}=e??{};if(t===void 0)throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");const a=Ae(t);ve(a,n,i);const o=t instanceof Document?a.getElementById(i):t.querySelector(`#${x(i)}`);if(o instanceof HTMLElement&&(t instanceof Document||t.contains(o)))return o;if(!(t instanceof Document)){const l=a.createElement("div");return l.id=i,t.appendChild(l),l}const s=a.createElement("div");return s.id=i,a.body.appendChild(s),s}function F(){return' <meta name="viewport" content="width=device-width, initial-scale=1.0" />'}function be(e){const{title:t="Markup AI Sidebar",headInnerHtml:i="",includePluginHostHead:n=!1,bodyScriptsHtml:a,htmlLang:o="en",htmlAttrs:s=`lang="${o}" style="height:100%"`,bodyAttrs:l='style="height:100%;margin:0"'}=e,c=[n?F():"",i].filter(h=>h.trim().length>0).join(`
|
|
137
137
|
`);return`<!DOCTYPE html>
|
|
138
138
|
<html ${s}>
|
|
139
139
|
<head>
|
|
@@ -146,4 +146,4 @@ ${c}`:""}
|
|
|
146
146
|
${a}
|
|
147
147
|
</body>
|
|
148
148
|
</html>
|
|
149
|
-
`}function Se(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}
|
|
149
|
+
`}function Se(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}r.AUTH_CONFIG_OVERRIDE_STORAGE_KEY=U,r.DEFAULT_IPC_CONFIG=D,r.DEFAULT_SIDEBAR_CONFIG=X,r.DeferredPromise=T,r.IPCCore=C,r.MimeType=g,r.PluginAdapter=ne,r.PluginIPCAdapter=O,r.SIDEBAR_DEFAULT_PRODUCTION_BASE_URL=ge,r.SIDEBAR_HOST_CONTAINER_ID=b,r.SIDEBAR_HOST_SHELL_CSS=ye,r.SIDEBAR_IFRAME_DEFAULT_ALLOW=H,r.SIDEBAR_IFRAME_DEFAULT_TITLE=N,r.SIDEBAR_URL_OVERRIDE_STORAGE_KEY=de,r.SidebarAdapter=L,r.SidebarIPCAdapter=_,r.TEXT_MIME_TYPES=K,r.TextLookupError=A,r.assertSidebarHostAdapter=fe,r.buildDocumentReference=te,r.buildSidebarHostHtmlDocument=be,r.buildSidebarHostShellCss=S,r.buildSidebarPluginHostHeadInnerHtml=F,r.createSidebarHost=Ie,r.ensureSidebarHostShell=Ce,r.getAuthConfigWithOverride=pe,r.getSidebarBaseUrlWithOverride=ue,r.ipcErrorReconstructors=v,r.isDocumentReference=ee,r.isIntegrationSettingField=Z,r.isIntegrationSettingsSchema=q,r.isTextLookupError=Q,r.reconstructError=E,r.setupSidebarLoadOverlay=k,r.sidebarPostMessageTargetOrigin=he});
|