@markupai/sidebar-adapter 0.0.23

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.
@@ -0,0 +1,149 @@
1
+ (function(o,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(o=typeof globalThis<"u"?globalThis:o||self,g(o.main={}))})(this,(function(o){"use strict";var g=(r=>(r.TEXT_PLAIN="text/plain",r.TEXT_MARKDOWN="text/markdown",r.TEXT_HTML="text/html",r.APPLICATION_DITA_XML="application/dita+xml",r))(g||{});const z=["text/plain","text/markdown","text/html","application/dita+xml"],G={integrationName:"unknown",integrationVersion:"unknown",integrationId:"markupai-sidebar-app",hideBanner:!1,dialogClosingScript:void 0,useCheckPreviewDialog:!1,supportCheckSelection:!0};class p extends Error{name="TextLookupError";constructor(e){super(e),Object.setPrototypeOf(this,p.prototype)}}function X(r){return r instanceof p}const S={TextLookupError:r=>new p(r)};function C(r){const e=r.message??"",t=r.name,i=typeof t=="string"&&t in S?S[t]:void 0;return i?i(e,r):Object.assign(new Error(e),t?{name:t}:{})}const T=()=>{};class O{_promise;[Symbol.toStringTag]="Promise";resolve=T;reject=T;constructor(){this._promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}then(e,t){return this._promise.then(e,t)}catch(e){return this._promise.catch(e)}finally(e){return this._promise.finally(e)}}const D={timeout:1e4};class E{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++,s=new O,a=t.timeout??this.config.timeout,c=setTimeout(()=>{if(n in this.promisesByID){const d=new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);s.reject(d),Reflect.deleteProperty(this.promisesByID,n)}},a);this.promisesByID[n]={promise:s,timeoutId:c};const l={type:"call",id:n,name:e,data:i};return this.postMessage(l),s}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}}async handleCall(e){const{id:t,name:i,data:n}=e;if(i in this.receiversByName){const s=this.receiversByName[i];try{if(!Array.isArray(n))throw new Error(`IPC: Expected array of arguments but got ${typeof n}`);const a=await s(...n),c={type:"response",id:t,name:i,data:a};this.postMessage(c)}catch(a){let c=JSON.stringify(a,Object.getOwnPropertyNames(a));const l=JSON.parse(c);(l.message===void 0||l.message==="")&&(c=JSON.stringify({message:a instanceof Error?a.message:String(a),name:a instanceof Error?a.name:void 0}));const d={type:"error",id:t,name:i,errorJSON:c};this.postMessage(d)}}else{const s=new Error(`No receiver registered for: ${i}`),a=JSON.stringify({message:s.message,name:s.name}),c={type:"error",id:t,name:i,errorJSON:a};this.postMessage(c)}}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:s}=this.promisesByID[t];clearTimeout(s);try{const a=JSON.parse(i),c=C(a);n.reject(c)}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={}}}class _{ipc;sidebar;targetOrigin;constructor(e,t,i="*"){this.sidebar=e||{},this.targetOrigin=i,this.ipc=new E(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=>{await e(t)})}if(this.sidebar.activateAgenticIssue){const e=this.sidebar.activateAgenticIssue;this.ipc.receive("activateAgenticIssue",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){await this.ipc.call("replaceContent",e,t,i)}async selectContent(e,t){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){await this.ipc.call("onAgenticAgentResults",e,t)}async onAgenticStreamComplete(){await this.ipc.call("onAgenticStreamComplete")}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()}}class V{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new _(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){await this.ipcAdapter.replaceContent(e,t,i)}async selectContent(e,t){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){return this.ipcAdapter.onAgenticAgentResults(e,t)}onAgenticStreamComplete(){return this.ipcAdapter.onAgenticStreamComplete()}configure(e){this.ipcAdapter.configure(e)}setTargetOrigin(e){this.ipcAdapter.setTargetOrigin(e)}getTargetOrigin(){return this.ipcAdapter.getTargetOrigin()}}class L{ipc;plugin;iframe;window;targetOrigin;constructor(e,t,i,n,s="*"){this.plugin=e,this.iframe=t,this.window=i??window,this.targetOrigin=s,this.ipc=new E(a=>{this.iframe.contentWindow?.postMessage(a,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(){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,i)}),this.ipc.receive("selectContent",async(e,t)=>{await this.plugin.selectContent(e,t)}),this.ipc.receive("showDialog",async(e,t,i,n)=>{await this.plugin.showDialog(e,t,i,n)}),this.ipc.receive("closeDialog",async()=>{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()})}async activateAgenticIssue(e){await this.ipc.call("activateAgenticIssue",e)}async notifyPluginStatus(e){await this.ipc.call("onPluginStatusChange",e)}configure(e){this.ipc.configure(e)}destroy(){this.window.removeEventListener("message",this.handleMessage),this.ipc.destroy()}}class M{ipcAdapter;constructor(e,t,i){this.ipcAdapter=new L(e,t,i?.win,i?.config,i?.targetOrigin)}destroy(){this.ipcAdapter.destroy()}async notifyPluginStatus(e){await this.ipcAdapter.notifyPluginStatus(e)}async activateAgenticIssue(e){await this.ipcAdapter.activateAgenticIssue(e)}configure(e){this.ipcAdapter.configure(e)}}const q=`
2
+ <div class="sidebar-load-overlay-card">
3
+ <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
4
+ <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
5
+ <button type="button" class="sidebar-load-overlay-button">
6
+ <svg
7
+ class="sidebar-load-overlay-button-icon"
8
+ viewBox="0 0 24 24"
9
+ fill="none"
10
+ stroke="currentColor"
11
+ stroke-width="1.5"
12
+ stroke-linecap="round"
13
+ stroke-linejoin="round"
14
+ aria-hidden="true"
15
+ focusable="false"
16
+ >
17
+ <path d="M20 12a8 8 0 1 1-2.34-5.66M20 4v6h-6" />
18
+ </svg>
19
+ <span>Retry</span>
20
+ </button>
21
+ </div>
22
+ `,K=()=>{const r=document.createElement("div");r.className="sidebar-load-overlay",r.style.display="none",r.innerHTML=q;const e=r.querySelector(".sidebar-load-overlay-button");if(!e)throw new Error("Missing retry button in load overlay template.");return{overlay:r,button:e}},R="markupai-sidebar-load-overlay-styles",Z=`
23
+ :root {
24
+ --background: #f5f5f4;
25
+ --foreground: #333332;
26
+ --muted-foreground: #78716c;
27
+ --accent: #ef4640;
28
+ --accent-foreground: #fafaf9;
29
+ --border: #d6d3d1;
30
+ --card: #fafaf9;
31
+ --card-foreground: #1c1917;
32
+ --overlay: color-mix(in srgb, var(--background) 90%, transparent);
33
+ --overlay-foreground: var(--foreground);
34
+ }
35
+
36
+ .sidebar-load-overlay {
37
+ position: absolute;
38
+ inset: 0;
39
+ z-index: 10;
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ padding: 0 24px;
44
+ text-align: center;
45
+ font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
46
+ sans-serif;
47
+ line-height: 1.4;
48
+ -webkit-font-smoothing: antialiased;
49
+ background: var(--overlay, rgba(245, 245, 244, 0.9));
50
+ color: var(--overlay-foreground, #333332);
51
+ }
52
+
53
+ .sidebar-load-overlay-card {
54
+ display: flex;
55
+ max-width: 260px;
56
+ flex-direction: column;
57
+ gap: 12px;
58
+ border-radius: 12px;
59
+ border: 1px solid var(--border, #d6d3d1);
60
+ background: var(--card, #fafaf9);
61
+ color: var(--card-foreground, #1c1917);
62
+ padding: 20px 16px;
63
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
64
+ }
65
+
66
+ .sidebar-load-overlay-title {
67
+ font-size: 13px;
68
+ font-weight: 600;
69
+ line-height: 1.4;
70
+ }
71
+
72
+ .sidebar-load-overlay-description {
73
+ font-size: 12px;
74
+ line-height: 1.4;
75
+ color: var(--muted-foreground, #78716c);
76
+ }
77
+
78
+ .sidebar-load-overlay-button {
79
+ border-radius: 8px;
80
+ border: 1px solid var(--accent, #ef4640);
81
+ background: var(--accent, #ef4640);
82
+ color: var(--accent-foreground, #fafaf9);
83
+ cursor: pointer;
84
+ padding: 8px 12px;
85
+ font-size: 12px;
86
+ font-weight: 600;
87
+ line-height: 1.2;
88
+ font-family: inherit;
89
+ display: inline-flex;
90
+ align-items: center;
91
+ justify-content: center;
92
+ gap: 6px;
93
+ transition:
94
+ background 0.15s ease,
95
+ border-color 0.15s ease,
96
+ color 0.15s ease;
97
+ }
98
+
99
+ .sidebar-load-overlay-button-icon {
100
+ height: 14px;
101
+ width: 14px;
102
+ }
103
+
104
+ .sidebar-load-overlay-button:hover {
105
+ background: color-mix(in srgb, var(--accent, #ef4640) 85%, #000);
106
+ border-color: color-mix(in srgb, var(--accent, #ef4640) 85%, #000);
107
+ }
108
+
109
+ .sidebar-load-overlay-button:focus-visible {
110
+ outline: none;
111
+ box-shadow: 0 0 0 2px
112
+ color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
113
+ }
114
+ `,Q=()=>{if(document.getElementById(R))return;const r=document.createElement("style");r.id=R,r.textContent=Z,document.head.appendChild(r)},ee=8e3,te=12e3,P=(r,e,t={})=>{Q();const{sidebarUrl:i,targetOrigin:n,timeoutMs:s=ee,retryIntervalMs:a=te}=t,c=()=>i??e.src,l=()=>{if(n)return n;try{return new URL(c()).origin}catch{return"*"}},{overlay:d,button:m}=K();r.appendChild(d);let y=!1,v,h;const f=u=>{d.style.display=u?"flex":"none"};f(!1);const b=()=>{v&&(globalThis.clearTimeout(v),v=void 0)},F=()=>{b(),v=globalThis.setTimeout(()=>{y||f(!0)},s)},j=u=>{const w=u?.preserveOverlay??!0;y=!1,w||f(!1),e.src=c(),F()},he=()=>{h||a<=0||(h=globalThis.setInterval(()=>{y||j({preserveOverlay:!0})},a))},$=()=>{h&&(globalThis.clearInterval(h),h=void 0)},W=u=>{if(!e.contentWindow||u.source!==e.contentWindow)return;const w=l();w!=="*"&&u.origin!==w||(y=!0,b(),$(),f(!1))},J=()=>{b(),f(!0)},Y=()=>{j()};return m.addEventListener("click",Y),e.addEventListener("error",J),globalThis.addEventListener("message",W),F(),he(),()=>{b(),$(),e.removeEventListener("error",J),globalThis.removeEventListener("message",W),m.removeEventListener("click",Y),d.remove()}},B="Markup AI Sidebar",k="clipboard-read; clipboard-write",H="markupai.sidebarNextGen.overrideUrl",re="https://sidebar.markup.ai/";function ie(r){try{return typeof globalThis.localStorage>"u"?r:globalThis.localStorage.getItem(H)?.trim()||r}catch{return r}}function ne(r,e){try{return new URL(r).origin}catch(t){return e?.onInvalidUrl?.(r,t),"*"}}function ae(r,e="Expected SidebarAdapter from createSidebarHost"){if(r.adapter===null)throw new Error(e)}function oe(r){const{iframe:e,iframeMount:t}=r;if(e!==void 0&&t!==void 0)throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");if(e!==void 0)return{iframe:e,removeMountedIframe:null};if(t===void 0)throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");const{container:i,src:n,allow:s=k}=t,a=document.createElement("iframe");return a.title=B,a.src=n,s&&a.setAttribute("allow",s),i.appendChild(a),{iframe:a,removeMountedIframe:()=>{a.remove()}}}function se(r){const{plugin:e,loadOverlayContainer:t,loadOverlayOptions:i,adapterOptions:n}=r,{iframe:s,removeMountedIframe:a}=oe(r),c=t!==void 0?P(t,s,i??{}):null;if(e!==void 0){const l=new M(e,s,n);return{iframe:s,adapter:l,destroy:()=>{c?.(),l.destroy(),a?.()}}}return{iframe:s,adapter:null,destroy:()=>{c?.(),a?.()}}}const A="sidebarContainer",N="markupai-sidebar-host-shell-styles";function x(r){if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(r);if(!/^[a-zA-Z_][\w-]*$/.test(r))throw new Error(`sidebar host shell: containerId must match /^[a-zA-Z_][\\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(r)})`);return r}function I(r=A){const e=x(r);return`
115
+ html {
116
+ height: 100%;
117
+ }
118
+ body {
119
+ height: 100%;
120
+ margin: 0;
121
+ }
122
+ #${e} {
123
+ height: 100%;
124
+ box-sizing: border-box;
125
+ position: relative;
126
+ }
127
+ #${e} iframe {
128
+ width: 100%;
129
+ height: 100%;
130
+ border: 0;
131
+ background: #fff;
132
+ padding: 0;
133
+ margin: 0;
134
+ display: block;
135
+ }
136
+ `.trim()}const ce=I();function le(r){return r instanceof Document?r:r.ownerDocument}function de(r,e,t){if(!e||r.getElementById(N))return;const i=r.createElement("style");i.id=N,i.textContent=I(t),r.head.appendChild(i)}function ge(r){const{root:e=typeof document<"u"?document:void 0,containerId:t=A,includeDefaultStyles:i=!0}=r??{};if(e===void 0)throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");const n=le(e);de(n,i,t);const s=e instanceof Document?n.getElementById(t):e.querySelector(`#${x(t)}`);if(s instanceof HTMLElement&&(e instanceof Document||e.contains(s)))return s;if(!(e instanceof Document)){const c=n.createElement("div");return c.id=t,e.appendChild(c),c}const a=n.createElement("div");return a.id=t,n.body.appendChild(a),a}function U(){return' <meta name="viewport" content="width=device-width, initial-scale=1.0" />'}function ue(r){const{title:e="Markup AI Sidebar",headInnerHtml:t="",includePluginHostHead:i=!1,bodyScriptsHtml:n,htmlLang:s="en",htmlAttrs:a=`lang="${s}" style="height:100%"`,bodyAttrs:c='style="height:100%;margin:0"'}=r,d=[i?U():"",t].filter(m=>m.trim().length>0).join(`
137
+ `);return`<!DOCTYPE html>
138
+ <html ${a}>
139
+ <head>
140
+ <base target="_top" />
141
+ <meta charset="UTF-8" />
142
+ <title>${pe(e)}</title>${d?`
143
+ ${d}`:""}
144
+ </head>
145
+ <body ${c}>
146
+ ${n}
147
+ </body>
148
+ </html>
149
+ `}function pe(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}o.DEFAULT_IPC_CONFIG=D,o.DEFAULT_SIDEBAR_CONFIG=G,o.DeferredPromise=O,o.IPCCore=E,o.MimeType=g,o.PluginAdapter=V,o.PluginIPCAdapter=_,o.SIDEBAR_DEFAULT_PRODUCTION_BASE_URL=re,o.SIDEBAR_HOST_CONTAINER_ID=A,o.SIDEBAR_HOST_SHELL_CSS=ce,o.SIDEBAR_IFRAME_DEFAULT_ALLOW=k,o.SIDEBAR_IFRAME_DEFAULT_TITLE=B,o.SIDEBAR_URL_OVERRIDE_STORAGE_KEY=H,o.SidebarAdapter=M,o.SidebarIPCAdapter=L,o.TEXT_MIME_TYPES=z,o.TextLookupError=p,o.assertSidebarHostAdapter=ae,o.buildSidebarHostHtmlDocument=ue,o.buildSidebarHostShellCss=I,o.buildSidebarPluginHostHeadInnerHtml=U,o.createSidebarHost=se,o.ensureSidebarHostShell=ge,o.getSidebarBaseUrlWithOverride=ie,o.ipcErrorReconstructors=S,o.isTextLookupError=X,o.reconstructError=C,o.setupSidebarLoadOverlay=P,o.sidebarPostMessageTargetOrigin=ne,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@markupai/sidebar-adapter",
3
+ "version": "0.0.23",
4
+ "description": "Adapter package for MarkupAI Sidebar integration",
5
+ "keywords": [
6
+ "markupai",
7
+ "sidebar",
8
+ "adapter",
9
+ "integration"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/markupai/markupai-sidebar.git",
14
+ "directory": "packages/adapter"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./dist/main.d.ts",
19
+ "import": "./dist/main.js",
20
+ "require": "./dist/main.umd.cjs"
21
+ },
22
+ "main": "./dist/main.umd.cjs",
23
+ "module": "./dist/main.js",
24
+ "types": "./dist/main.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc --project tsconfig.build.json && vite build",
30
+ "dev": "vite",
31
+ "format:check": "prettier --check .",
32
+ "format:fix": "prettier --write .",
33
+ "lint:check": "eslint .",
34
+ "lint:fix": "eslint --fix .",
35
+ "test": "vitest run",
36
+ "test:coverage": "vitest run --coverage",
37
+ "test:watch": "vitest",
38
+ "type-check": "tsc --project tsconfig.json --noEmit"
39
+ },
40
+ "devDependencies": {
41
+ "vite-plugin-dts": "4.5.4"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }