@json-to-office/jto 6.3.0 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/client/assets/{HomePage-Dzm2MeID.js → HomePage-DdKO7Rz8.js} +4 -4
- package/dist/client/assets/{HomePage-Dzm2MeID.js.map → HomePage-DdKO7Rz8.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-DOp1sE3p.js → JsonEditorPage-CIB7kfUW.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-DOp1sE3p.js.map → JsonEditorPage-CIB7kfUW.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-Bc9nyqNY.js → MonacoPluginProvider-Cql9aylS.js} +5 -5
- package/dist/client/assets/{MonacoPluginProvider-Bc9nyqNY.js.map → MonacoPluginProvider-Cql9aylS.js.map} +1 -1
- package/dist/client/assets/{_virtual_jto-plugin-type-libs-Pc3DyHoX.js → _virtual_jto-plugin-type-libs-BJgH7I8Z.js} +75 -21
- package/dist/client/assets/{_virtual_jto-plugin-type-libs-Pc3DyHoX.js.map → _virtual_jto-plugin-type-libs-BJgH7I8Z.js.map} +1 -1
- package/dist/client/assets/_virtual_jto-sandbox-runtime-BFXK15tx.js +2 -0
- package/dist/client/assets/_virtual_jto-sandbox-runtime-BFXK15tx.js.map +1 -0
- package/dist/client/assets/{editor-BJWDd3uK.js → editor-Dl0mPZWB.js} +2 -2
- package/dist/client/assets/{editor-BJWDd3uK.js.map → editor-Dl0mPZWB.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-FLZpeDZL.js → editor-monaco-json-BWLlWM6o.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-FLZpeDZL.js.map → editor-monaco-json-BWLlWM6o.js.map} +1 -1
- package/dist/client/assets/index-1Vg-Jg2R.js +27 -0
- package/dist/client/assets/index-1Vg-Jg2R.js.map +1 -0
- package/dist/client/assets/{index-D5Xrk4Ze.js → index-Db2WFiF0.js} +2 -2
- package/dist/client/assets/{index-D5Xrk4Ze.js.map → index-Db2WFiF0.js.map} +1 -1
- package/dist/client/assets/{preview-C4ynYVMZ.js → preview-BXysnPth.js} +2 -2
- package/dist/client/assets/{preview-C4ynYVMZ.js.map → preview-BXysnPth.js.map} +1 -1
- package/dist/client/assets/{useQualityAnalysis-kUkZB_mW.js → useQualityAnalysis-Dr3UHxyN.js} +2 -2
- package/dist/client/assets/{useQualityAnalysis-kUkZB_mW.js.map → useQualityAnalysis-Dr3UHxyN.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +10 -10
- package/dist/client/assets/_virtual_jto-sandbox-runtime-DUgi1ipv.js +0 -2
- package/dist/client/assets/_virtual_jto-sandbox-runtime-DUgi1ipv.js.map +0 -1
- package/dist/client/assets/index-D6Nfjrjh.js +0 -27
- package/dist/client/assets/index-D6Nfjrjh.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_virtual_jto-sandbox-runtime-BFXK15tx.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as W,r as u,j as t}from"./react-vendor-BmQ2Ko_D.js";import{g as Nt,c as St,V as Ut,a as Kt,E as bn}from"./editor-monaco-json-
|
|
1
|
+
import{c as W,r as u,j as t}from"./react-vendor-BmQ2Ko_D.js";import{g as Nt,c as St,V as Ut,a as Kt,E as bn}from"./editor-monaco-json-BWLlWM6o.js";import{i as Jt,h as ye,t as Wt,v as He,F as Z,c as _,e as Ee,f as Te,g as Re,o as yn,u as jn,S as kt}from"./index-1Vg-Jg2R.js";import Qt,{DiffEditor as Cn}from"./monaco-editor-DJsdM0WK.js";import{a as ue,f as je,g as dt,u as be,P as wn,B as rt,p as vn,n as ot,o as Nn,q as Sn,r as kn,t as En,w as Tn,b as qt,d as Rn,x as Mn,y as An,T as Dn,z as Ln}from"./MonacoPluginProvider-Cql9aylS.js";import{B as Me,d as Xt}from"./index-Db2WFiF0.js";import{I as _e,S as Ce,a as we,b as ve,c as Ne,d as he,e as Pn,t as On,B as at,D as In,f as _n,g as zn,h as Fn,i as $n,j as Vn,k as Yt,l as Hn,T as Bn,m as Gn,u as Un,n as Kn,Q as Jn,o as Wn}from"./HomePage-DdKO7Rz8.js";import{r as pe,i as Zt,n as mt,u as en,I as Ue,c as Et,E as ge,C as Tt,G as ft,a as Qn,b as ie,H as ne,d as ze,e as qn,Q as de,D as tn,g as ce,P as Xn,F as pt,f as Ge,h as Se,M as it,j as Xe,S as Ae,k as Yn,t as Zn,l as es,s as nn,m as ts,o as ns,p as sn,q as Ke,v as ss,w as rs,x as os,y as as,z as Rt,T as is,A as ls,B as cs,J as us,K as ds,L as ms,N as fs,O as ps,R as Mt,U as hs,V as gs,W as xs}from"./useQualityAnalysis-Dr3UHxyN.js";import{ad as bs,ae as ys,af as js,ag as rn}from"./radix-ui-BzbaiLpZ.js";import{a8 as Cs,X as on,a as ht,a9 as ws,T as vs,aa as Ns,O as an,e as At,_ as Ss,x as gt,B as Je,h as ks,y as Es,t as Ts,v as Rs,ab as Ms,ac as As}from"./ui-vendor-BsAtAN16.js";import{u as Dt}from"./state-vendor-Cq67_JbF.js";import"./query-vendor--rhYD8mC.js";const Ds={initWith:function(e){const n=document.createElement("div"),s=e.editor.create(n),r=s.constructor.name,a=s.getModel().constructor.name;return{isInstanceValid:function(c){return c.constructor.name===r},isModelValid:function(c){return c.constructor.name===a},isRangesValid:function(c){return Array.isArray(c)?c.every(function(d){return typeof d=="object"&&d.constructor.name==="Object"?!(!d.hasOwnProperty("range")||!Array.isArray(d.range)||d.range.length!==4||!d.range.every(f=>f>0&&parseInt(f)===f)||d.hasOwnProperty("allowMultiline")&&typeof d.allowMultiline!="boolean"||d.hasOwnProperty("label")&&typeof d.label!="string"||d.hasOwnProperty("validate")&&typeof d.validate!="function"):!1}):!1}}}},$e=function(e,n,s){return"The value for the "+n+" should be of type "+(Array.isArray(e)?e.join(" | "):e)+". "+(s||"")},Ye=function(){const e=function(o,l){return typeof o!="object"||o===null?this.freeze?Object.freeze(o):o:o instanceof Date?this.freeze?Object.freeze(new Date(o)):new Date(o):l.call(this,o)},n=function(o,l){const c=Object.keys(o),d=new Array(c.length);for(let f=0;f<c.length;f++)d[c[f]]=e.call(this,o[c[f]],l);return d},s=function(o){return e.call(this,o,function(l){if(Array.isArray(l))return n.call(this,l,s);const c={};for(let d in l)!this.withProto&&Object.hasOwnProperty.call(l,d)===!1||(c[d]=e.call(this,l[d],s));return c})},r=function(){const o=function(c){const d=["withProto","freeze"];this[c]=d.reduce((function(f,m){return(f[m]=c>=this[m])&&(c-=this[m]),f}).bind(this),{})},l=Object.create(Object.defineProperties({},{withProto:{value:1},freeze:{value:2}}));for(let c=0;c<=3;c++)o.call(l,c);return l}(),a={withProto:s.bind(r[1]),andFreeze:s.bind(r[2]),withProtoAndFreeze:s.bind(r[3])},i=s.bind(r[0]);for(let o in a)Object.defineProperty(i,o,{enumerable:!1,writable:!1,configurable:!1,value:a[o]});return i}(),Lt={SINGLE_LINE_HIGHLIGHT_CLASS:"editableArea--single-line",MULTI_LINE_HIGHLIGHT_CLASS:"editableArea--multi-line"},Ls=function(e,n,s){const r=s.Range,a=function(h,C){const b=h.range,S=C.range;if(b[0]<S[0]||b[0]===S[0]&&b[3]<S[1])return-1},i=function(h,C){const b=C.split(`
|
|
2
2
|
`),S=b.length,E=[];return h.forEach(function(M,P){if(M===0)throw new Error("Range values cannot be zero");switch(P){case 0:{if(M<0)throw new Error("Start Line of Range cannot be negative");if(M>S)throw new Error("Provided Start Line("+M+") is out of bounds. Max Lines in content is "+S);E[P]=M}break;case 1:{let z=M;const H=E[0],B=b[H-1].length;if(z<0){if(z=B-Math.abs(z),z<0)throw new Error("Provided Start Column("+M+") is out of bounds. Max Column in line "+H+" is "+B)}else if(z>B+1)throw new Error("Provided Start Column("+M+") is out of bounds. Max Column in line "+H+" is "+B);E[P]=z}break;case 2:{let z=M;if(z<0){if(z=S-Math.abs(M),z<0)throw new Error("Provided End Line("+M+") is out of bounds. Max Lines in content is "+S);z<E[0]&&console.warn("Provided End Line("+M+") is less than the start Line, the Restriction may not behave as expected")}else if(M>S)throw new Error("Provided End Line("+M+") is out of bounds. Max Lines in content is "+S);E[P]=z}break;case 3:{let z=M;const H=E[2],B=b[H-1].length;if(z<0){if(z=B-Math.abs(z),z<0)throw new Error("Provided End Column("+M+") is out of bounds. Max Column in line "+H+" is "+B)}else if(z>B+1)throw new Error("Provided Start Column("+M+") is out of bounds. Max Column in line "+H+" is "+B);E[P]=z}break}}),E};let o=Ye(n).sort(a);const l=function(h){const C=e.getValue();h.forEach(function(b,S){const E=i(b.range,C),M=E[0],P=E[1],z=E[2],H=E[3];b._originalRange=E.slice(),b.range=new r(M,P,z,H),b.index=S,b.allowMultiline||(b.allowMultiline=r.spansMultipleLines(b.range)),b.label||(b.label=`[${M},${P} -> ${z}${H}]`)})},c=function(){return o.reduce(function(h,C){return h[C.label]={allowMultiline:C.allowMultiline||!1,index:C.index,range:Object.assign({},C.range),originalRange:C._originalRange.slice()},h},{})},d=function(){return o.reduce(function(h,C){return h[C.label]=e.getValueInRange(C.range),h},{})},f=function(h,C){if(typeof h=="object"&&!Array.isArray(h)){C=typeof C=="boolean"?C:!1;const b=o.reduce(function(S,E){return E.label&&(S[E.label]=E),S},{});for(let S in h){const E=b[S];if(E){const M=h[S];if(L(E,M))throw new Error("Multiline change is not allowed for "+S);const P=Ye(E.range);if(P.endLine=P.startLine+M.split(`
|
|
3
3
|
`).length-1,P.endColumn=M.split(`
|
|
4
4
|
`).pop().length,T(E,M,P))throw new Error("Change is invalidated by validate function of "+S);e.applyEdits([{forceMoveMarkers:!!C,range:E.range,text:M}])}else console.error("No restriction found for "+S)}}else throw new Error("Value must be an object")},m=function(){return e._restrictionChangeListener.dispose(),window.removeEventListener("error",O),delete e.editInRestrictedArea,delete e.disposeRestrictions,delete e.getValueInEditableRanges,delete e.updateValueInEditableRanges,delete e.updateRestrictions,delete e.getCurrentEditableRanges,delete e.toggleHighlightOfEditableAreas,delete e._hasHighlight,delete e._isRestrictedModel,delete e._isCursorAtCheckPoint,delete e._currentCursorPositions,delete e._editableRangeChangeListener,delete e._restrictionChangeListener,delete e._oldDecorations,delete e._oldDecorationsSource,e},x=function(h){h.some(function(C){const b=C.lineNumber,S=C.column,E=o.length;for(let M=0;M<E;M++){const P=o[M].range;if(P.startLineNumber===b&&P.startColumn===S||P.endLineNumber===b&&P.endColumn===S)return e.pushStackElement(),!0}})},y=function(h){typeof h=="function"&&e._editableRangeChangeListener.push(h)},p=function(h,C){const b=c();e._editableRangeChangeListener.forEach(function(S){S.call(e,h,C,b)})},j=function(){return Promise.resolve().then(function(){e.editInRestrictedArea=!0,e.undo(),e.editInRestrictedArea=!1,e._hasHighlight&&e._oldDecorationsSource&&(e.deltaDecorations(e._oldDecorations,e._oldDecorationsSource),e._oldDecorationsSource.forEach(function(h){h.range=e.getDecorationRange(h.id)}))})},v=function(h,C,b,S,E,M){let P=C.endLineNumber,z=C.endColumn;h.prevRange=C,h.range=C.setEndPosition(b,S);const H=o.length;let B=E.length;const G=S-z,Y=b-P,ee=e._currentCursorPositions||[],me=ee.length;if(B!==me&&(E=E.filter(function(K){const U=K.range;for(let g=0;g<me;g++){const k=ee[g];if(U.startLineNumber===k.startLineNumber&&U.endLineNumber===k.endLineNumber&&U.startColumn===k.startColumn&&U.endColumn===k.endColumn)return!0}return!1}),B=E.length),Y!==0){for(let K=h.index+1;K<H;K++){const U=o[K],g=U.range;P===g.startLineNumber&&(g.startColumn+=G),P===g.endLineNumber&&(g.endColumn+=G),g.startLineNumber+=Y,g.endLineNumber+=Y,U.range=g}for(let K=M+1;K<B;K++){const U=E[K],g=U.range,k=g.toString(),N=rangeMap[k];delete rangeMap[k],P===g.startLineNumber&&(g.startColumn+=G),P===g.endLineNumber&&(g.endColumn+=G),g.startLineNumber+=Y,g.endLineNumber+=Y,U.range=g,rangeMap[g.toString()]=N}}else{for(let K=h.index+1;K<H;K++){const U=o[K],g=U.range;if(g.startLineNumber>P)break;g.startColumn+=G,g.endColumn+=G,U.range=g}for(let K=M+1;K<B;K++){const U=E[K],g=U.range,k=g.toString(),N=rangeMap[k];if(delete rangeMap[k],g.startLineNumber>P){rangeMap[g.toString()]=N;break}else g.startColumn+=G,g.endColumn+=G,U.range=g,rangeMap[g.toString()]=N}}},A=function(h,C){const b={},S=h.range;return h.text===""?b.isDeletion=!0:S.startLineNumber===S.endLineNumber&&S.startColumn===S.endColumn?b.isAddition=!0:b.isReplacement=!0,b.startLineOfRange=S.startLineNumber===C.startLineNumber,b.startColumnOfRange=S.startColumn===C.startColumn,b.endLineOfRange=S.endLineNumber===C.endLineNumber,b.endColumnOfRange=S.endColumn===C.endColumn,b.middleLineOfRange=!b.startLineOfRange&&!b.endLineOfRange,C.startLineNumber===C.endLineNumber?b.rangeIsSingleLine=!0:b.rangeIsMultiLine=!0,b},D=function(h){o=Ye(h).sort(a),l(o)},V=function(h){if(e._hasHighlight)e.deltaDecorations(e._oldDecorations,[]),delete e._oldDecorations,delete e._oldDecorationsSource,e._hasHighlight=!1;else{const C=h.cssClassForSingleLine||Lt.SINGLE_LINE_HIGHLIGHT_CLASS,b=h.cssClassForMultiLine||Lt.MULTI_LINE_HIGHLIGHT_CLASS,S=o.map(function(E){const M={range:E.range,options:{className:E.allowMultiline?b:C}};return E.label&&(M.hoverMessage=E.label),M});e._oldDecorations=e.deltaDecorations([],S),e._oldDecorationsSource=S.map(function(E,M){return Object.assign({},E,{id:e._oldDecorations[M]})}),e._hasHighlight=!0}},O=function(){console.debug("handler for unhandled promise rejection")},se=function(h){for(let C in h){const b=h[C];b.range=b.prevRange}},L=function(h,C){return!h.allowMultiline&&C.includes(`
|
|
@@ -13,4 +13,4 @@ import{c as W,r as u,j as t}from"./react-vendor-BmQ2Ko_D.js";import{g as Nt,c as
|
|
|
13
13
|
`));u.useEffect(()=>{i||c(s.join(`
|
|
14
14
|
`))},[i,s]);const d=kn(l),f=n&&s.length>0,m=n?s.length===0?"Network on, no hosts listed":`Network: ${s.join(", ")}`:"Network off";return t.jsxs(bt,{open:i,onOpenChange:o,children:[t.jsx(yt,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":m,title:m,className:_("flex h-7 cursor-pointer items-center gap-1.5 rounded-sm px-1.5 text-xs","transition-colors hover:bg-muted/60","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none",f?"text-foreground":"text-muted-foreground"),children:[t.jsx(As,{className:"size-3.5","aria-hidden":"true"}),t.jsx("span",{className:"hidden sm:inline",children:"Network"}),f&&t.jsx(at,{variant:"outline",className:"h-4 px-1 font-mono text-[10px] tabular-nums",children:s.length}),n&&s.length===0&&t.jsx("span",{className:"text-[10px] text-amber-600 dark:text-amber-500",children:"no hosts"})]})}),t.jsxs(We,{align:"end",className:"w-80 space-y-3",children:[t.jsxs("label",{htmlFor:`plugin-network-${e}`,className:"flex cursor-pointer items-center justify-between gap-2",children:[t.jsx("span",{className:"text-sm font-medium",children:"Allow network"}),t.jsx(Yt,{id:`plugin-network-${e}`,checked:n,onCheckedChange:r,"aria-label":"Allow network access"})]}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Off: ",t.jsx("code",{children:"fetch"}),", ",t.jsx("code",{children:"XMLHttpRequest"}),","," ",t.jsx("code",{children:"WebSocket"})," and ",t.jsx("code",{children:"EventSource"})," throw inside the sandbox. On: only the hosts below are reachable — everything else is refused by the browser, not by the plugin."]}),n&&t.jsxs(t.Fragment,{children:[t.jsx(Bn,{value:l,onChange:x=>c(x.target.value),onBlur:()=>a(d.origins),spellCheck:!1,rows:3,"aria-label":"Hosts this plugin may call",placeholder:`api.open-meteo.com
|
|
15
15
|
geocoding-api.open-meteo.com`,className:"font-mono text-xs"}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["One host per line. ",t.jsx("code",{children:"https"})," is assumed;"," ",t.jsx("code",{children:"*.example.com"})," matches subdomains."]}),d.errors.length>0&&t.jsx("ul",{className:"space-y-0.5 text-xs text-destructive",children:d.errors.map(x=>t.jsx("li",{children:x},x))}),d.errors.length===0&&d.origins.length===0&&t.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-500",children:"Nothing listed, so nothing is reachable."})]})]})]})}function Ur({name:e,value:n,saveDocumentDebounceWait:s}){const r=u.useRef(null),{resolvedTheme:a}=Jt(),i=ue(w=>w.saveDocument),o=ue(w=>w.closeDocument),{registerEditor:l,unregisterEditor:c,setActiveEditor:d}=ye(),f=be(w=>{var h;return(h=w.records[e])==null?void 0:h.diagnostics}),m=u.useRef(null),[x,y]=u.useState(n),p=u.useRef(Xt(w=>{m.current=w,i(e,w)},s)),[j,v]=u.useState(!0),[A,D]=u.useState(!1),V=u.useRef(!1),O=u.useMemo(()=>(f??[]).map(w=>({path:w.source==="typescript"?"":w.source,message:w.message,code:w.source,severity:w.severity,...w.line!==void 0?{startLineNumber:w.line,startColumn:w.column,endLineNumber:w.endLine,endColumn:w.endColumn}:{}})),[f]);u.useEffect(()=>{O.length>0&&!V.current&&(v(!0),D(!1)),O.length===0&&(V.current=!1)},[O.length]);const se=u.useCallback(w=>{Wt(w),En(w)},[]),L=u.useCallback(()=>{p.current.flush()},[]),T=u.useCallback((w,h)=>{r.current=w,l(e,w,h,void 0,void 0,L),d(e);const C=()=>{const b=w.getValue();p.current.cancel(),m.current=b,i(e,b)};w.addCommand(h.KeyMod.CtrlCmd|h.KeyCode.KeyS,C),w.addCommand(h.KeyMod.CtrlCmd|h.KeyCode.KeyW,()=>{C(),o(e)}),w.addCommand(h.KeyMod.Shift|h.KeyMod.Alt|h.KeyCode.KeyF,()=>{var b;(b=w.getAction("editor.action.formatDocument"))==null||b.run()})},[o,L,e,l,i,d]);u.useEffect(()=>{const w=p.current;return()=>{w.flush(),c(e)}},[e,c]),u.useEffect(()=>{var h;if(n===m.current)return;const w=(h=r.current)==null?void 0:h.getModel();w&&w.getValue()!==n&&w.setValue(n),y(n)},[n]);const $=u.useCallback(w=>{const h=r.current;!h||!w.startLineNumber||(h.setPosition({lineNumber:w.startLineNumber,column:w.startColumn??1}),h.revealLineInCenter(w.startLineNumber),h.focus())},[]);return t.jsxs("div",{className:"flex h-full flex-col",children:[t.jsx(Br,{docName:e,text:n}),t.jsxs("div",{className:"relative min-h-0 flex-1",children:[t.jsx(Qt,{height:"100%",defaultLanguage:"typescript",path:Tn(e),value:x,theme:He(a),beforeMount:se,onMount:T,keepCurrentModel:!0,onChange:w=>{w!==void 0&&p.current(w)},options:{lineNumbers:"on",glyphMargin:!0,folding:!0,lineDecorationsWidth:5,lineNumbersMinChars:3,renderValidationDecorations:"on",quickSuggestions:{other:!0,comments:!1,strings:!0},acceptSuggestionOnCommitCharacter:!0,acceptSuggestionOnEnter:"on",autoIndent:"advanced",formatOnType:!0,formatOnPaste:!0,automaticLayout:!0,minimap:{enabled:!1},scrollBeyondLastLine:!0,tabSize:2,wordWrap:"off"}}),t.jsx("div",{className:"absolute top-0 right-0",children:t.jsx(Ut,{errors:O,onClick:()=>{v(!0),D(!1)}})}),j&&O.length>0&&t.jsx(Kt,{errors:O,isMinimized:A,onToggleMinimize:()=>D(w=>!w),onErrorClick:$,onClose:()=>{v(!1),V.current=!0},className:"z-40"})]})]})}const Kr=W.memo(Ur);function Jr({name:e,text:n,buildError:s,saveDocumentDebounceWait:r,documentType:a}){const{saveDocument:i}=ue(f=>f),{updateTheme:o}=qt(f=>f),l=W.useMemo(()=>Xt(o,r),[o,r]);W.useEffect(()=>()=>{l.flush()},[l]);const c=W.useCallback(f=>{i(e,f),a==="application/json+theme"&&(console.log("TabContent: Theme document change detected, debouncing update",{documentName:e,debounceWait:r}),l(e,f))},[e,i,l,a,r]),d=W.useMemo(()=>({name:e,type:"application/json",text:n,mtime:new Date,ctime:new Date,atime:new Date}),[e,n]);return t.jsx(Gn,{value:e,className:"mt-0 h-full p-0",tabIndex:-1,children:a==="application/json+theme"?t.jsx($r,{document:d,onChange:c}):a==="application/typescript+plugin"?t.jsx(Kr,{name:e,value:n,saveDocumentDebounceWait:r}):t.jsx(bn,{name:e,value:n,saveDocumentDebounceWait:r})})}const Wr=W.memo(Jr);function Qr({openTabs:e,documents:n,buildErrors:s,saveDocumentDebounceWait:r}){const{documentTypes:a}=ue(i=>i);return e.map(i=>n.find(o=>o.name===i)).filter(i=>i!==void 0).map(i=>{const o=a[i.name]||"application/json+report";return t.jsx(Wr,{name:i.name,text:i.text,buildError:s[i.name],saveDocumentDebounceWait:r,documentType:o},i.name)})}const qr=W.memo(Qr);class Xr extends Error{constructor(n,s,r){super(n),this.lastError=s,this.attempts=r,this.name="RetryError"}}async function Yr(e,n={}){const{maxRetries:s=3,initialDelay:r=1e3,maxDelay:a=3e4,backoffFactor:i=2,onRetry:o,shouldRetry:l=()=>!0,signal:c}=n;let d;for(let f=0;f<=s;f++)try{if(c!=null&&c.aborted)throw new Error("Operation cancelled");return await e()}catch(m){if(d=m instanceof Error?m:new Error(String(m)),f===s)break;if(!l(d))throw d;const y=Math.min(r*Math.pow(i,f),a)*(.5+Math.random()*.5);o&&o(d,f+1),await new Promise(p=>{const j=setTimeout(p,y);c&&c.addEventListener("abort",()=>{clearTimeout(j),p(void 0)},{once:!0})})}throw new Xr(`Failed after ${s+1} attempts`,d,s+1)}const Bt={networkErrors:e=>["NetworkError","Failed to fetch","ERR_NETWORK","ECONNREFUSED","ETIMEDOUT","ENOTFOUND","fetch failed"].some(s=>e.message.includes(s)||e.name.includes(s)),httpStatusCodes:e=>n=>{var s;return(s=n.response)!=null&&s.status?e.includes(n.response.status):!1},temporaryErrors:e=>["EBUSY","EAGAIN","temporarily unavailable","too many requests","rate limit"].some(s=>e.message.toLowerCase().includes(s.toLowerCase())),combine:(...e)=>n=>e.some(s=>s(n))},Zr="Body text in the normal style, with **bold**, *italic* and `mono` runs beside plain words so weight and the mono role read next to each other. A second sentence gives the line spacing and paragraph spacing room to show.",eo={primary:"Headings and the strongest brand colour",secondary:"Supporting brand colour",accent:"Highlights and emphasis",text:"Body text",textPrimary:"Primary text",textSecondary:"Secondary text",textMuted:"Captions and muted text",text2:"Secondary text and captions",background:"Page background",backgroundPrimary:"Primary surface",backgroundSecondary:"Alternate surface",background2:"Alternate surface and rules",border:"Rules and borders",borderPrimary:"Primary rules",borderSecondary:"Subtle rules",accent4:"Chart series 4",accent5:"Chart series 5",accent6:"Chart series 6"};function xn(e){return e?us(e):[]}function Gt(e,n){const s=e==null?void 0:e.styles;return!!s&&typeof s=="object"&&n in s}function to(e,n){const s=xn(n),r=[];return r.push(Gt(n,"title")?{name:"paragraph",props:{text:"Theme specimen",themeStyle:"title"}}:{name:"heading",props:{text:"Theme specimen",level:1}}),Gt(n,"subtitle")?r.push({name:"paragraph",props:{text:`Every named style, colour and font of "${e}", on one page.`,themeStyle:"subtitle"}}):r.push({name:"paragraph",props:{text:`Every named style, colour and font of "${e}", on one page.`}}),r.push({name:"heading",props:{text:"Heading 1 — Typography",level:1}},{name:"paragraph",props:{text:Zr}},{name:"heading",props:{text:"Heading 2 — Structure",level:2}},{name:"paragraph",props:{text:"A second paragraph under a second-level heading, so the spacing before and after headings can be judged against running text."}},{name:"heading",props:{text:"Heading 3 — Detail",level:3}},{name:"list",props:{items:["Primary carries the headings","Secondary supports it","Accent marks emphasis"]}},{name:"divider",props:{}},{name:"heading",props:{text:"Figures",level:2}},{name:"statistic",props:{number:"42%",description:"A statistic: the number in the heading font, the caption below it"}}),s.length>0&&r.push({name:"heading",props:{text:"Colours",level:2}},{name:"table",props:{columns:[{header:{content:"Token"},cells:s.map(a=>({content:a}))},{header:{content:"Swatch"},cells:s.map(a=>({content:" ",backgroundColor:a}))},{header:{content:"Role"},cells:s.map(a=>({content:eo[a]??""}))}]}}),{name:"docx",props:{theme:e,metadata:{title:`${e} sample`,author:"json-to-office playground",description:`Sample rendered in the "${e}" theme`}},children:[{name:"section",props:{},children:r}]}}function no(e,n){const s=xn(n),r=(i,o,l,c,d,f)=>({name:"text",props:{text:i,style:o,x:l,y:c,w:d,h:f}}),a=[{name:"slide",props:{meta:{title:"Title"}},children:[r("Theme specimen","title",.5,1.6,9,1.2),r(`Named styles, colours and fonts of "${e}"`,"subtitle",.5,2.9,9,.8)]},{name:"slide",props:{meta:{title:"Typography"}},children:[r("Typography","heading1",.5,.4,9,.8),r("Heading 2 — the section style","heading2",.5,1.3,9,.6),r("Heading 3 — the detail style","heading3",.5,1.95,9,.5),r("Body text in the body style. It runs long enough to wrap onto a second line, so the line spacing and the body size can be judged against the headings above it.","body",.5,2.55,9,1.4),r("Caption — the smallest voice on the slide","caption",.5,4.1,9,.4)]}];if(s.length>0){const o=[];s.forEach((l,c)=>{const d=c%6,f=Math.floor(c/6),m=.5+d*1.5,x=1.3+f*1.6;o.push({name:"shape",props:{type:"rect",x:m,y:x,w:1.3,h:.9,fill:{color:l}}},r(l,"caption",m,x+.95,1.3,.4))}),a.push({name:"slide",props:{meta:{title:"Colours"}},children:[r("Colours","heading1",.5,.4,9,.8),...o]})}return a.push({name:"slide",props:{meta:{title:"Chart and table"}},children:[r("Chart and table","heading1",.5,.4,9,.8),{name:"chart",props:{type:"bar",x:.5,y:1.3,w:4.6,h:3.6,showLegend:!0,data:[{name:"Revenue",labels:["Q1","Q2","Q3","Q4"],values:[120,132,145,160]},{name:"Cost",labels:["Q1","Q2","Q3","Q4"],values:[80,84,91,95]},{name:"Margin",labels:["Q1","Q2","Q3","Q4"],values:[40,48,54,65]}]}},{name:"table",props:{x:5.4,y:1.3,w:4.1,headerRow:!0,rows:[[{text:"Metric"},{text:"Value"}],[{text:"Revenue"},{text:"$4.2M"}],[{text:"Users"},{text:"12,847"}],[{text:"Retention"},{text:"94%"}]]}}]}),{name:"pptx",props:{title:`${e} sample`,theme:e},children:a}}function so(e){return`Sample · ${e}`}function ro(e){return e.startsWith("Sample · ")}function oo(e,n,s){return e==="docx"?to(n,s):no(n,s)}function ao(){const e=Rn(g=>g.setOutput),n=u.useContext(Mn),s=u.useContext(An),r=u.useContext(Dn),a=je(g=>g.saveDocumentDebounceWait),{openTabs:i,activeTab:o,setActiveTab:l,documents:c,buildErrors:d,setBuildError:f,documentTypes:m}=ue(Dt(g=>({openTabs:g.openTabs,activeTab:g.activeTab,setActiveTab:g.setActiveTab,documents:g.documents,buildErrors:g.buildErrors,setBuildError:g.setBuildError,documentTypes:g.documentTypes}))),{customThemes:x}=qt(Dt(g=>({customThemes:g.customThemes}))),{generatePresentation:y,cancelGeneration:p}=Un(),j=je(g=>g.qualityProfileIds),v=ds(j),A=je(g=>g.qualityGate),D=je(g=>{var k;return(k=g.qualityPolicies)==null?void 0:k[Z]}),V=u.useMemo(()=>ms(v,A,D),[v,A,D]),{analyze:O,cancel:se}=fs(),L=u.useRef(new Map),T=u.useRef(new Map),$=u.useRef(null),w=u.useRef(""),h=u.useRef(new Map),C=u.useCallback(()=>{w.current=`cancelled-${Date.now()}`;for(const g of T.current.values())clearTimeout(g);T.current.clear(),$.current&&(clearTimeout($.current),$.current=null);for(const g of L.current.values())g.abort();L.current.clear(),p(),e({isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0})},[p,e]);u.useEffect(()=>{e({cancelGeneration:C})},[C,e]);const b=u.useCallback(g=>{const N=(h.current.get(g)||0)+1;return h.current.set(g,N),N},[]),S=u.useMemo(()=>{const g=Object.entries(x).map(([k,N])=>{let R=0;return N.lastModified&&(N.lastModified instanceof Date?R=N.lastModified.getTime():typeof N.lastModified=="string"&&(R=new Date(N.lastModified).getTime())),{key:k,name:N.name,content:N.content,valid:N.valid,lastModified:R}});return JSON.stringify(g)},[x]),E=u.useMemo(()=>{const g={};return Object.values(x).forEach(k=>{k.valid&&k.parsed&&(g[k.name]=k.parsed)}),g},[S]),M=u.useCallback(()=>{const g={},{customThemes:k}=r.getState();return Object.values(k).forEach(N=>{N.valid&&N.parsed&&(g[N.name]=N.parsed)}),g},[r]),P=u.useCallback(async(g,k,N)=>{if(!g||!y)return;const R=L.current.get(g.name);R&&(R.abort(),L.current.delete(g.name));const F=k?null:new AbortController,I=k||F.signal;F&&L.current.set(g.name,F);const te=`${g.name}-${Date.now()}-${Math.random()}`,fe=b(g.name);w.current=te;const q={id:te,docName:g.name,doc:g,signal:I,timestamp:Date.now(),qualityTicket:gs()};await H.current(q,fe,N)},[y,e,b]),z=u.useCallback(async(g,k,N)=>{var X;const{doc:R,signal:F,id:I,qualityTicket:te}=g,fe=Q=>xs(n.getState().quality,te)?{}:{quality:Q};if(w.current!==I){console.log("Skipping outdated build request for:",R.name),e({isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0});return}e({globalError:void 0,isGenerating:!0,generationStartedAt:Date.now(),generationProgress:{stage:"parsing",message:"Validating JSON structure..."}});const q=(Q,re)=>{if(F.aborted||w.current!==I)return;if((h.current.get(R.name)||0)!==k){console.log("Document version changed, aborting build"),F.dispatchEvent(new Event("abort"));return}e({isGenerating:!0,generationProgress:{stage:Q,message:re}})};try{const Q=M();console.log("Editor: Using themes for document build",{docName:R.name,freshThemeCount:Object.keys(Q).length,freshThemeNames:Object.keys(Q),memoizedCount:Object.keys(E).length,requestId:I}),q("parsing","Expanding plugins...");const re=await Kn(R.text,{customThemes:Q,signal:F});if(ro(R.name)||(G.current=null),F.aborted||w.current!==I){e({isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0});return}const J=await Yr(async()=>{if(F.aborted)throw new Error("Build cancelled");return await y(R.name,re.text,Q,q,{...N,...V?{quality:V}:{}})},{maxRetries:2,initialDelay:500,shouldRetry:oe=>oe.message.includes("cancelled")||oe.message.includes("JSON")||oe.message.includes("parse")||oe.message.includes("syntax")?!1:Bt.combine(Bt.temporaryErrors,ae=>ae.message.includes("Worker")||ae.message.includes("Proxy"))(oe),onRetry:(oe,ae)=>{console.log(`Retrying presentation generation (attempt ${ae}):`,oe.message),e({isGenerating:!0,generationProgress:{stage:"parsing",message:`Retrying generation (attempt ${ae})...`}})},signal:F});if(F.aborted||w.current!==I){console.log("Build cancelled for:",R.name),e({isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0});return}if(J&&typeof J=="object"&&"name"in J&&"text"in J&&"blob"in J){console.log("Editor: Build completed",{docName:J.name,blobSize:(X=J.blob)==null?void 0:X.size,timestamp:Date.now(),requestId:I,version:k});const{findings:oe,others:ae}=ps(J.warnings);e({name:J.name,text:J.text,blob:J.blob,renderer:J.renderer,globalError:void 0,isGenerating:!1,isPreviewStale:!1,generationProgress:void 0,generationStartedAt:void 0,lastBuiltSequence:n.getState().editSequence,cacheStatus:J.cacheStatus,cacheHitRate:J.cacheHitRate,warnings:[...re.warnings,...ae],...fe({findings:oe,counts:Mt(oe),...v?{profileId:v}:{},documentName:R.name,seq:te,source:"generate",analyzedAt:Date.now()})}),f(J.name,void 0)}}catch(Q){if(F.aborted||w.current!==I){console.log("Build cancelled with error for:",R.name),e({isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0});return}const re=Q instanceof Error?Q.message:String(Q),J=Q instanceof Jn?hs(Q.quality):null;e({globalError:re,isGenerating:!1,generationProgress:void 0,generationStartedAt:void 0,...J?fe({findings:J,counts:Mt(J),...v?{profileId:v}:{},documentName:R.name,seq:te,blocked:!0,source:"generate",analyzedAt:Date.now(),gateError:re}):{}}),f(R.name,re)}finally{L.current.delete(R.name)}},[y,M,V,v,e,f,n]),H=u.useRef(z);u.useEffect(()=>{H.current=z});const B=u.useRef(null),G=u.useRef(null);u.useEffect(()=>{console.log("Editor: Document rebuild effect triggered",{activeTab:o});const g=c.find(R=>R.name===o),k=m[o]||"application/json+report";k==="application/json+report"&&g&&(B.current=o);const N=T.current.get(o);return N&&(clearTimeout(N),T.current.delete(o)),g&&k==="application/json+report"?n.getState().isGenerating||e({isPreviewStale:!0}):g&&k!=="application/json+report"&&p(),()=>{const R=T.current.get(o);R&&(clearTimeout(R),T.current.delete(o))}},[c,o,e,m,P,p]),u.useEffect(()=>{const g=c.find(N=>N.name===o),k=m[o]||"application/json+report";if(!g||k!=="application/json+report"){se(),e({quality:null});return}return O(o,g.text),se},[o,O,se,c,m,e]);const Y=u.useMemo(()=>{var N;const g=new Map,k=c.find(R=>R.name===o);if(k&&m[k.name]==="application/json+report")try{const F=(N=JSON.parse(k.text).props)==null?void 0:N.theme;typeof F=="string"&&Object.values(x).some(te=>te.name===F&&te.valid)&&g.set(k.name,F)}catch{}return g},[o,c,m,x]);u.useEffect(()=>(console.log("Editor: Setting up theme change listener",{documentCount:c.length,dependencyCount:Y.size,dependencies:Array.from(Y.entries()),customThemes:Object.entries(x).map(([k,N])=>({key:k,name:N.name,valid:N.valid}))}),Ln.onThemeChange(k=>{console.log("Editor: Theme change detected",{event:k,dependencies:Array.from(Y.entries()),activeTab:o,customThemes:Object.entries(x).map(([R,F])=>({key:R,name:F.name,valid:F.valid}))});const N=[];if(Y.forEach((R,F)=>{if(R===k.themeName){const I=c.find(te=>te.name===F);I&&N.push(I)}}),console.log("Editor: Documents using changed theme",{themeName:k.themeName,documentCount:N.length,documentNames:N.map(R=>R.name)}),N.length===0){console.log("Editor: No documents use this theme, skipping rebuild");return}n.getState().isGenerating||e({isPreviewStale:!0})})),[Y,c,P,b,o,e]);const ee=u.useRef(P);u.useEffect(()=>{ee.current=P});const me=u.useRef(b);u.useEffect(()=>{me.current=b}),u.useEffect(()=>{const g=()=>{var fe;e({isGenerating:!0});let k=!1;const N=ye.getState().getActiveEditor();if(N&&!s.getState().pendingDiffs[N.documentName]){const X=N.toStorageValue(N.editor.getValue());s.getState().saveDocument(N.documentName,X)}const{documents:R,documentTypes:F}=s.getState();for(const q of R)if(F[q.name]==="application/json+theme"){const X=ye.getState().getEditor(q.name);if(X){const Q=X.toStorageValue(X.editor.getValue()),re=r.getState().customThemes[q.name];(!re||re.content!==Q)&&(r.getState().updateTheme(q.name,Q),k=!0)}}else if(F[q.name]==="application/typescript+plugin"){const X=ye.getState().getEditor(q.name);if(X){(fe=X.flushPendingSave)==null||fe.call(X);const Q=X.toStorageValue(X.editor.getValue());Q!==q.text&&s.getState().saveDocument(q.name,Q)}}ot.flush();const I=s.getState().activeTab,te=T.current.get(I);te&&(clearTimeout(te),T.current.delete(I)),$.current&&clearTimeout($.current),$.current=setTimeout(async()=>{$.current=null,await ot.whenIdle();const{documents:q,activeTab:X,documentTypes:Q}=s.getState();let re=X;const J=Q[X]||"application/json+report";if(J!=="application/json+report"){const ae=G.current;if(ae&&J==="application/json+theme"&&ae.themeDocName===X){U.current(X);return}if(B.current)re=B.current;else{e({isGenerating:!1});return}}const oe=q.find(ae=>ae.name===re);if(oe){const ae=s.getState().pendingDiffs[re],qe=ye.getState().getEditor(re),vt=ae?{...oe,text:ae.modified}:qe?{...oe,text:qe.toStorageValue(qe.editor.getValue())}:oe;me.current(vt.name),ee.current(vt,void 0,k?{bypassCache:!0}:void 0)}else e({isGenerating:!1})},150)};return window.addEventListener("preview:flushAndBuild",g),()=>{window.removeEventListener("preview:flushAndBuild",g),$.current&&clearTimeout($.current)}},[e,s,r]);const K=u.useCallback(g=>{const{documents:k}=s.getState(),N=k.find(q=>q.name===g);if(!N){e({isGenerating:!1});return}let R,F=null,I=null;try{R=JSON.parse(N.text),F=dt(R)}catch(q){I=q instanceof Error?q.message:"Invalid JSON"}if(!F){e({isGenerating:!1,globalError:I?`The theme is not valid JSON: ${I}`:"The theme has no name"});return}const te=so(F),fe=JSON.stringify(oo(Z,F,R),null,2);G.current={themeDocName:g},e({isGenerating:!0}),me.current(te),ee.current({name:te,text:fe},void 0,{bypassCache:!0})},[s,e]),U=u.useRef(K);return u.useEffect(()=>{U.current=K}),u.useEffect(()=>{const g=k=>{const N=k.detail;N!=null&&N.themeDocName&&U.current(N.themeDocName)};return window.addEventListener("preview:buildSpecimen",g),()=>window.removeEventListener("preview:buildSpecimen",g)},[]),u.useEffect(()=>{const g=()=>{n.getState().isGenerating||e({isPreviewStale:!0})};return window.addEventListener(rt,g),()=>window.removeEventListener(rt,g)},[n,e]),u.useEffect(()=>()=>{L.current.forEach(g=>g.abort()),L.current.clear(),T.current.forEach(g=>clearTimeout(g)),T.current.clear(),p()},[p]),i.length?t.jsx(Wn,{value:o,onValueChange:l,className:"h-full",children:t.jsx(qr,{openTabs:i,documents:c,buildErrors:d,saveDocumentDebounceWait:a})}):t.jsx("div",{className:"flex flex-col text-muted-foreground h-full items-center justify-center",children:c!=null&&c.length?"Open a document...":"Create a new document..."})}const jo=u.memo(ao);export{jo as Editor};
|
|
16
|
-
//# sourceMappingURL=editor-
|
|
16
|
+
//# sourceMappingURL=editor-Dl0mPZWB.js.map
|