@sheetxl/scripting-mui 0.7.28-beta.4 → 0.8.0-beta.2
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/browser/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty;let o=require("react");var s,c=1,l=(s=o)==null?{}:e(i(s));o=((e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c,l=r(i),u=0,d=l.length;u<d;u++)c=l[u],a.call(e,c)||c===o||t(e,c,{get:(e=>i[e]).bind(null,c),enumerable:!(s=n(i,c))||s.enumerable});return e})(!c&&s&&s.__esModule?l:t(l,`default`,{value:s,enumerable:!0}),s);let u=require("@mui/material"),d=require("@sheetxl/utils-react"),f=require("@sheetxl/utils-mui"),p=require("@sheetxl/react"),m=require("react/jsx-runtime"),h=require("@mui/system"),g=require("@sheetxl/utils"),_=require("@sheetxl/scripting-react");function v(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=v(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function y(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=v(e))&&(r&&(r+=` `),r+=t);return r}var b={"insertFunction.fallbackLabel":`Function`,"insertFunction.insertNamed":`Insert {name}`,"runScript.executeNamed":`Execute {name}`,"runScript.fallbackLabel":`Macro`,"templateSelect.blankSummary":`Start with an empty script.`,"templateSelect.blankTitle":`Blank Template...`,"templateSelect.errorTitle":`Error loading Templates`,"templateSelect.intro":`Choose from a template to provide a starting point to automate tasks or create user defined functions.`,"templateSelect.intro2":`Templates provide a foundation to customize and meet your specific needs.`,"templateSelect.loadFailed":`Failed to load scripts`,"templateSelect.title":`Script Template`,"templateSelect.untitled":`Untitled`},{DefaultCommandCatalogService:x}=d.Command,S=!1;function C(){S||(S=!0,x.registerFromManifest(`@sheetxl/scripting-mui`,{}.url,{messages:b}))}C();var w=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,...r}=e,i=(0,p.useWorkbook)(),a=(0,d.useTranslator)(),[s,c]=(0,o.useState)([]),[l,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=i?.getScripts();e&&(async()=>{h(!0);let t=await e.searchFunctions({type:`macro`});c(t),h(!1)})()},[i]);let g={variant:d.CommandButtonType.Menuitem,groupKey:`scriptsOptions`,shortcut:void 0},_=[],v=s?s.length:0;for(let e=0;e<v;e++){let t=s[e];_.push((0,m.jsx)(f.CommandButton,{...g,commandKey:`executeScript`,commandState:{declaration:t},propsTooltip:{description:a(`runScript.executeNamed`,{name:t.getName()??a(`runScript.fallbackLabel`)})},icon:(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`}),label:t.getName()??a(`runScript.fallbackLabel`)},`macro-${t.getName()}-${e}`))}let y=(0,m.jsxs)(u.Box,{ref:t,sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[_.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:_}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...g,key:`show-editor`,commandKey:`showScriptEditor`})]});return(0,f.defaultCreatePopupPanel)({...r,children:y})}));w.displayName=`RunScriptPopupPanel`;var T=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,disabled:r,...i}=e,a=(0,d.useCommands)([`showScriptEditor`])[0],s=(0,d.useCommandButtonEntry)(`scriptsOptions`);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:r,createPopupPanel:(0,o.useCallback)(e=>{let t=(0,m.jsx)(w,{disabled:r,groupKey:n,...e});return(0,f.defaultCreatePopupPanel)({...e,children:t})},[r,n]),selected:a?.getState(),label:s?.getLabel?.(),tooltip:s?.getDescription?.(),quickCommand:`showScriptEditor`,...i})})),E=`https://unpkg.com/@sheetxl/scripting-templates/dist`,D=(e,t)=>{try{return new URL(t).href}catch{}if(t.startsWith(`/`)||/^[a-zA-Z]:/.test(t))return t;let n=e.startsWith(`http`)?e:`file:///${e.replace(/\\/g,`/`)}`;return n.endsWith(`/`)||(n+=`/`),new URL(t,n).href},O=e=>{if(e.metadata?.name)return e.metadata.name;let t=(e.path.split(`/`).pop()||``).replace(/\.[^/.]+$/,``);return e.metadata?.icon===`formula`?t.toUpperCase():(t=t.replace(/([a-z])([A-Z])/g,`$1 $2`),t.replace(/[-_]/g,` `).trim().split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `))},k=async e=>{let t=D(e,`./manifest.json`),n=await fetch(t);if(!n.ok)throw new g.ChainedError(`Failed to retrieve directory at '${e}': ${n.statusText}`);let r=await n.text();if(r.trim().toLowerCase().startsWith(`<!doctype html`)||r.trim().toLowerCase().startsWith(`<html`))throw new g.ChainedError(`Failed to retrieve directory at '${e}'`);let i;try{i=JSON.parse(r)}catch(e){throw Error(`Failed to parse directory: ${e.message}. Ensure the file is valid JSON.`)}let a=i.map(async t=>{try{let n=D(e,t.path),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch file at '${t.path}': ${r.statusText}`);let i=await r.text(),a=t.metadata;return a?.title||(a={title:O(t),...a}),{path:t.path,content:i,metadata:a}}catch(e){console.error(e.message)}return null});return(await Promise.all(a)).filter(e=>e!==null)},A={marginRight:`4px`},j=`1em`,M=(0,o.memo)(e=>{let{disabled:t,snippet:n,description:r,handleInsert:i,sx:a,...o}=e,s,c=n.metadata?.icon;return s=c===`formula`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptFormula`,size:j,style:A}):c===`macro`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`,size:j,style:A}):(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptAutoRun`,size:j,style:A}),(0,m.jsx)(f.ExhibitMenuItem,{sx:{maxWidth:`460px`,display:`flex`,"*":{lineHeight:`1.2`},...a},disabled:t,icon:s,onMouseDown:e=>{e.button===0&&e.preventDefault()},onMouseUp:e=>{e.button===0&&i(n)},onKeyDown:e=>{e.keyCode!==d.KeyCodes.Enter&&e.keyCode!==d.KeyCodes.Space||i(n)},...o,children:(0,m.jsxs)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`},children:[(0,m.jsx)(u.Typography,{component:`div`,children:n.metadata?.title??n.path}),(0,m.jsx)(u.Typography,{variant:`caption`,component:`div`,sx:{color:e=>(0,h.alpha)(e.palette.text.secondary??e.palette.text.primary,.6),overflow:`hidden`,textOverflow:`ellipsis`},children:n.metadata?.summary})]})})}),N=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,disabled:r,scriptPath:i=E,...a}=e,[s,c]=(0,o.useState)([]),[l,p]=(0,o.useState)(!0),[h]=(0,d.useCommands)([`insertScript`]);(0,o.useEffect)(()=>{(async()=>{try{let e=await k(i);c(e)}catch{}finally{p(!1)}})()},[i]);let g=(0,o.useCallback)(e=>{if(l)return(0,m.jsx)(`div`,{children:`Loading...`});let t={variant:d.CommandButtonType.Menuitem,groupKey:`scriptsOptions`,disabled:r},n=t=>{h?.execute(t.content),e.closeFloat?.()},i=[];for(let e=0;e<s.length;e++){let t=s[e];t&&i.push((0,m.jsx)(M,{handleInsert:n,snippet:t},t.path))}let a=(0,m.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[i.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:i}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...t,key:`showKeyboardShortcuts`,commandKey:`showKeyboardShortcuts`}),(0,o.createElement)(f.CommandButton,{...t,key:`scriptingHelp`,commandKey:`scriptingHelp`})]});return(0,f.defaultCreatePopupPanel)({...e,children:a})},[r,n,l,h]);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:r,groupKey:n,label:h?.getLabel(n)??`Insert Script`,tooltip:h?.getDescription(),createPopupPanel:g,icon:h?.getIcon()??`ScriptInsert`,...a})})),P=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{propsCommandButton:n,...r}=e;return(0,m.jsx)(f.CommandToolbar,{ref:t,propsCommandButton:n,renderToolbarPalette:(0,d.useCallbackRef)(e=>{let{propsCommandButton:t,propsCommandPopup:n}=e;return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(`div`,{style:{display:`flex`,flex:`1 1 100%`},children:[(0,m.jsx)(`div`,{children:(0,m.jsx)(f.OverflowPalette,{style:{},children:(0,m.jsx)(f.CommandButton,{...t,commandKey:`saveScripts`})})}),(0,m.jsx)(`div`,{style:{flex:`1 1 100%`}}),(0,m.jsx)(`div`,{children:(0,m.jsx)(f.OverflowPalette,{style:{},children:(0,m.jsx)(N,{...t})})})]})})},[]),...r})}));P.displayName=`ScriptEditorToolbar`,C();var F=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{scriptPath:n=E,onScriptSelect:r,sx:i=d.ReactUtils.EmptyCssProperties,className:a,buttonMinWidth:s=210,buttonMinHeight:c=80,gap:l=12,...p}=e,h=(0,d.useTranslator)(),[_,v]=(0,o.useState)([]),[b,x]=(0,o.useState)(!0),[S,C]=(0,o.useState)(null);if((0,o.useEffect)(()=>{(async()=>{let e=[{path:null,metadata:{title:h(`templateSelect.blankTitle`),summary:h(`templateSelect.blankSummary`)},content:``}];try{x(!0),C(null);let t=await k(n);for(let n=0;n<t.length;n++){let r=t[n];r&&e.push(r)}}catch(e){C(e instanceof Error?e.message:h(`templateSelect.loadFailed`)),e instanceof g.ChainedError||console.error(`Error loading scripts:`,e)}finally{v(e),x(!1)}})()},[n,h]),b)return(0,m.jsx)(u.Box,{className:y(a,`script-select`),...p,sx:[{display:`flex`,justifyContent:`center`,alignItems:`center`,height:`100%`,background:e=>e.palette.background.paper,zIndex:1e3,backgroundImage:f.raisedSurface,...Array.isArray(i)?{}:i},...Array.isArray(i)?i:[]],children:(0,m.jsx)(u.CircularProgress,{})});let w=null;S&&(w=(0,m.jsxs)(u.Box,{className:y(a,`script-select`,`error-results`),...p,sx:[{display:`flex`,justifyContent:`center`,alignItems:`center`,background:e=>e.palette.error.light,flex:`0`,zIndex:1e3,flexDirection:`column`,padding:e=>e.spacing(1),border:e=>`1px solid ${e.palette.error.main}`,borderBottomLeftRadius:1,borderBottomRightRadius:1,backgroundImage:f.raisedSurface},...Array.isArray(i)?i:[i]],children:[(0,m.jsx)(u.Typography,{color:`error`,variant:`h6`,component:`div`,gutterBottom:!0,children:h(`templateSelect.errorTitle`)}),(0,m.jsx)(u.Typography,{color:`error`,component:`div`,children:S})]}));let T=e=>{let t=e.metadata?.icon;return t===`macro`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`,size:`1em`}):t===`formula`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptFormula`,size:`1em`}):t===`autostart`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptAutoRun`,size:`1em`}):null};return(0,m.jsxs)(u.Box,{ref:t,className:y(a,`script-select`),sx:{background:e=>e.palette.background.paper,zIndex:1e3,backgroundImage:f.raisedSurface,...i},...p,children:[(0,m.jsxs)(u.Box,{className:`script-select-content`,sx:{p:3,overflow:`auto`,flex:`1 1 auto`},children:[(0,m.jsx)(u.Typography,{variant:`h6`,gutterBottom:!0,children:h(`templateSelect.title`)}),(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,gutterBottom:!0,sx:{color:`text.secondary`},children:h(`templateSelect.intro`)}),(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,gutterBottom:!0,sx:{color:`text.secondary`},children:h(`templateSelect.intro2`)}),(0,m.jsx)(u.Box,{sx:{display:`grid`,gridTemplateColumns:`repeat(auto-fill, minmax(${s}px, 1fr))`,gap:`${l}px`,padding:2,paddingLeft:`0px`,paddingRight:`0px`},children:_.map((e,t)=>(0,m.jsxs)(u.Button,{variant:`outlined`,sx:{minWidth:s,minHeight:c,display:`flex`,flexDirection:`column`,justifyContent:`flex-start`,alignItems:`flex-start`,textAlign:`left`,padding:2,textTransform:`none`,overflow:`hidden`,...t===0&&{borderStyle:`dashed`,marginBottom:`8px`},...t===1&&{gridColumn:`1`}},onClick:()=>r?.(e),children:[(0,m.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`row`,justifyContent:`space-between`,alignItems:`center`,width:`100%`,marginBottom:.5},children:[(0,m.jsx)(u.Typography,{variant:`subtitle2`,component:`div`,children:e.metadata?.title||e.path?.split(`/`).pop()?.replace(/\.\w+$/,``)||h(`templateSelect.untitled`)}),T(e)]}),e.metadata?.summary&&(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,sx:{color:`text.secondary`,overflow:`hidden`,display:`flex`,flexDirection:`column`,textOverflow:`ellipsis`,alignItems:`flex-start`},children:e.metadata.summary})]},`${e.path}-${t}`))})]}),w]})}));F.displayName=`TemplateSelectPanel`;var I=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{className:n,sx:r,propsScriptEditor:i,readOnly:a=!1,frame:s,autoFocusSel:c,autoFocus:l=!0,scripts:p,...h}=e,g=(0,u.useTheme)(),[v,b]=(0,o.useState)(!1),x=(0,o.useRef)(!1),[S,C]=(0,o.useState)({message:`Loading`,cursor:``,dirty:!1}),[w,T]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!1;return T(null),async function(){if(p&&(await p.start(),!e)){let e=p.getModules().getItems()[0]?.getSource();T({source:e||null})}}(),()=>{e=!0}},[p]);let E=(0,o.useCallback)(e=>{C(t=>({...t,...e}))},[]),D=(0,o.useRef)(null),[O,k]=(0,o.useState)(null),A=(0,o.useRef)(null),j=(0,d.useCallbackRef)(e=>{if(O)return O.focus(e),!0;if(c){let t=D.current?.querySelectorAll?.(c);if(t&&t.length>0)return t[0]?.focus?.(e),!0}return D.current?.focus?.(e),!1},[O,c,l]),M=(0,o.useMemo)(()=>(0,m.jsx)(f.AnimatedLoadingPanel,{transitionDelay:`160ms`,style:{position:`absolute`,width:`100%`,height:`100%`},transparentBackground:!1}),[]),N=(0,o.useMemo)(()=>(0,m.jsx)(u.Paper,{elevation:1,tabIndex:0,sx:{display:`flex`,alignItems:`center`,userSelect:`none`,flexGrow:1,marginLeft:e=>e.spacing(.5),marginRight:e=>e.spacing(.5),marginTop:e=>e.spacing(1),marginBottom:e=>e.spacing(1)},children:(0,m.jsx)(P,{})}),[g]),I=(0,o.useMemo)(()=>(0,m.jsx)(u.Box,{className:y(`script-status-panel`,`status-panel`),sx:{display:`flex`,alignItems:`stretch`,flexDirection:`row`,flex:`0`,paddingLeft:`12px`,paddingRight:`12px`,gap:`8px`,paddingTop:`1px`,minHeight:`calc(1em + 8px)`,margin:0,borderTop:`solid 1px ${g.palette.divider}`},children:(0,m.jsxs)(`div`,{style:{flex:`1 1 100%`,display:`flex`,alignItems:`center`,flexDirection:`row`,justifyContent:`center`},children:[(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`1 1 100%`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.message}),(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`none`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.dirty?`Unsaved`:``}),(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`none`,marginLeft:`8px`,minWidth:`90px`,display:`flex`,justifyContent:`end`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.cursor})]})}),[S]),L=(0,o.useMemo)(()=>(0,m.jsxs)(u.Box,{className:y(`script-editor-content`),sx:{display:`flex`,flex:`1 1 100%`,width:`100%`,flexDirection:`column`,boxSizing:`border-box`},children:[N,(0,m.jsx)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,width:`100%`,flexDirection:`row`,position:`relative`,boxSizing:`border-box`},children:(0,m.jsx)(_.ScriptEditor,{ref:D,loadingPanel:M,readOnly:a,frame:s,scripts:p,autoFocus:l,onStatusChange:E,darkMode:g.palette.mode===`dark`,...i})}),I]}),[g,N,I,v,M,a,i,l,c,s,E]),R=(0,o.useMemo)(()=>{let e;return w===null?M:(w.source===null&&(e=(0,m.jsx)(F,{sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`,position:`absolute`,boxSizing:`border-box`,width:`100%`,height:`100%`},onScriptSelect:e=>{D.current?.insertSnippet(e.content),T({source:e.content??``}),requestAnimationFrame(()=>D.current?.focus())}})),(0,m.jsx)(u.Box,{tabIndex:0,className:y(`script-workspace`,n),sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`,alignItems:`stretch`,userSelect:`none`,flexGrow:0,outline:`none`},onPointerDown:e=>{e.isDefaultPrevented()||D.current?.focus()},children:(0,m.jsxs)(u.Box,{sx:{flex:`1 1 100%`,position:`relative`,display:`flex`},children:[(0,m.jsx)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,minWidth:0,minHeight:0,visibility:e?`hidden`:`visible`},children:L}),e]})}))},[N,L,n,w,M]),z=(0,d.useImperativeElement)(t,()=>({isScriptWorkspaceElement:()=>!0,focus:e=>{j(e)}}),[]);return(0,m.jsx)(u.Box,{sx:{display:`flex`,flexDirection:`row`,flex:`1 1 100%`,position:`relative`,...r},ref:z,...h,onFocus:e=>{b(!0),x.current=!0,z.current?.contains(e.target)&&e.target!==z.current&&k(e.target),e.relatedTarget&&!A.current&&(A.current=e.relatedTarget),h?.onFocus?.(e)},onBlur:e=>{z?.current?.contains(e.relatedTarget)||z?.current===e.relatedTarget||(A.current=null,x.current=!1,b(!1)),h?.onBlur?.(e)},children:R})}));I.displayName=`ScriptWorkspace`;var{FocusActivation:L,CommandScopeProvider:R,CommandAnchorProvider:z,useCommandScope:B}=d.Command,V={scopeName:`scriptEditor`},H=({children:e})=>{let t=B(),n=(0,o.useRef)(null);return t?(0,m.jsx)(R,{spec:V,elementRef:n,region:!0,children:(0,m.jsx)(U,{paneRef:n,children:e})}):e},U=({paneRef:e,children:t})=>{let n=B(),r=(0,o.useMemo)(()=>n?new L(n.getRoot(),n):null,[n]);return r?(0,m.jsxs)(z,{tracker:r,keyBindings:!1,debounce:100,elementRef:e,children:[(0,m.jsx)(p.InputClipboardInjector,{}),(0,m.jsx)(`div`,{className:`script-editor-pane`,style:{display:`contents`},ref:e,children:t})]}):t},W=e=>{let{model:t,entryKey:n,frame:r,ref:i,...a}=e;return(0,m.jsx)(H,{children:(0,m.jsx)(I,{ref:i,readOnly:!1,frame:r,scripts:((0,p.useWorkbook)()??t)?.getScripts(),...a})})},G=(0,o.memo)(e=>{let{alwaysShow:t=!1,...n}=e,[r,i]=(0,o.useReducer)(e=>e+1,0),[a]=(0,d.useCommands)([`showScriptEditor`],{onChange:()=>i()}),s=(0,p.useWorkbook)(),[c,l]=(0,o.useState)(t);return(0,o.useEffect)(()=>{if(t)return void l(!0);let e=s?.getScripts();if(!e||!a)return void l(!1);let n=async()=>{let t=!1;a.getState()||(t=((await e.searchFunctions({type:`macro`}))?.length??0)>0),l(t||!!a.getState())};n();let r=e.addListeners({onChange:()=>{n()}});return()=>{r()}},[t,s,a,r]),c?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(f.ExhibitDivider,{}),(0,m.jsx)(T,{...n})]}):null});G.displayName=`RunScriptContribution`,C();var K=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{...n}=e,r=(0,p.useWorkbook)(),i=(0,d.useTranslator)(),[a,s]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=r?.getScripts();if(!e)return;let t=!1,n=async()=>{let n=await e.searchFunctions({type:`formula`});t||s(n)};n();let i=e.addListeners({onChange:()=>{n()}});return()=>{t=!0,i()}},[r]);let c={variant:d.CommandButtonType.Menuitem,shortcut:void 0},l=[],h=a?a.length:0;for(let e=0;e<h;e++){let t=a[e];l.push((0,m.jsx)(f.CommandButton,{...c,commandKey:`insertFunction`,commandState:t,propsTooltip:{description:i(`insertFunction.insertNamed`,{name:t.getName()??i(`insertFunction.fallbackLabel`)})},icon:(0,m.jsx)(d.DynamicIcon,{iconKey:`FormulaCustom`}),label:t.getName()??i(`insertFunction.fallbackLabel`)},`function-${t.getName()}-${e}`))}let g=(0,m.jsxs)(u.Box,{ref:t,sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[l.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:l}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...c,key:`show-editor`,commandKey:`showScriptEditor`})]});return(0,f.defaultCreatePopupPanel)({...n,children:g})}));K.displayName=`InsertFunctionPopupPanel`;var q=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{disabled:n,groupKey:r,...i}=e,a=(0,d.useCommandButtonEntry)(`customFunctionOptions`);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:n,createPopupPanel:(0,o.useCallback)(e=>{let t=(0,m.jsx)(K,{disabled:n,groupKey:r,...e});return(0,f.defaultCreatePopupPanel)({...e,children:t})},[n,r]),label:a?.getLabel?.(),tooltip:a?.getDescription?.(),icon:`FormulaCustom`,...i})}));q.displayName=`InsertFunctionContribution`,exports.InsertScriptCommandButton=N,exports.RunScriptCommandButton=T,exports.ScriptEditorToolbar=P,exports.ScriptTaskPane=W,exports.ScriptWorkspace=I,exports.ScriptingPlugin=()=>{(0,_.ScriptingReactPlugin)(),d.DefaultIconService.register(`plugin-scripts`,{icons:{}}),p.DefaultTaskPaneRegistry.registerTaskPane({key:`scriptEditor`,getTitle:()=>`Script (Typescript)`,getIcon:()=>`ScriptRun`,component:W,keepMounted:!0},!0),d.DefaultCommandButtonRegistry.register({key:`scriptsOptions`},!0),d.DefaultCommandButtonRegistry.register({key:`customFunctionOptions`},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.runScript.home`,contributions:{homeToolbar:{}},render:e=>o.default.createElement(G,{...e})},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.runScript.view`,contributions:{viewToolbar:{order:10}},render:e=>o.default.createElement(G,{...e,groupKey:`view`,alwaysShow:!0})},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.insertFunction.formula`,contributions:{formulaToolbar:{anchor:`formulaCategory.web`,order:1}},render:e=>o.default.createElement(q,{...e})},!0)};
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty;let o=require("react");var s,c=1,l=(s=o)==null?{}:e(i(s));o=((e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c,l=r(i),u=0,d=l.length;u<d;u++)c=l[u],a.call(e,c)||c===o||t(e,c,{get:(e=>i[e]).bind(null,c),enumerable:!(s=n(i,c))||s.enumerable});return e})(!c&&s&&s.__esModule?l:t(l,`default`,{value:s,enumerable:!0}),s);let u=require("@mui/material"),d=require("@sheetxl/utils-react"),f=require("@sheetxl/utils-mui"),p=require("@sheetxl/react"),m=require("react/jsx-runtime"),h=require("@mui/system"),g=require("@sheetxl/utils"),_=require("@sheetxl/scripting-react");function v(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=v(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function y(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=v(e))&&(r&&(r+=` `),r+=t);return r}var b={"insertFunction.fallbackLabel":`Function`,"insertFunction.insertNamed":`Insert {name}`,"insertScript.fallbackLabel":`Insert Script`,"insertScript.loading":`Loading...`,"runScript.executeNamed":`Execute {name}`,"runScript.fallbackLabel":`Macro`,"templateSelect.blankSummary":`Start with an empty script.`,"templateSelect.blankTitle":`Blank Template...`,"templateSelect.errorTitle":`Error loading Templates`,"templateSelect.intro":`Choose from a template to provide a starting point to automate tasks or create user defined functions.`,"templateSelect.intro2":`Templates provide a foundation to customize and meet your specific needs.`,"templateSelect.loadFailed":`Failed to load scripts`,"templateSelect.title":`Script Template`,"templateSelect.untitled":`Untitled`},{DefaultCommandCatalogService:x}=d.Command,S=!1;function C(){S||(S=!0,x.registerFromManifest(`@sheetxl/scripting-mui`,{}.url,{messages:b}))}C();var w=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,...r}=e,i=(0,p.useWorkbook)(),a=(0,d.useTranslator)(),[s,c]=(0,o.useState)([]),[l,h]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=i?.getScripts();e&&(async()=>{h(!0);let t=await e.searchFunctions({type:`macro`});c(t),h(!1)})()},[i]);let g={variant:d.CommandButtonType.Menuitem,groupKey:`scriptsOptions`,shortcut:void 0},_=[],v=s?s.length:0;for(let e=0;e<v;e++){let t=s[e];_.push((0,m.jsx)(f.CommandButton,{...g,commandKey:`executeScript`,commandState:{declaration:t},propsTooltip:{description:a(`runScript.executeNamed`,{name:t.getName()??a(`runScript.fallbackLabel`)})},icon:(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`}),label:t.getName()??a(`runScript.fallbackLabel`)},`macro-${t.getName()}-${e}`))}let y=(0,m.jsxs)(u.Box,{ref:t,sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[_.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:_}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...g,key:`show-editor`,commandKey:`showScriptEditor`})]});return(0,f.defaultCreatePopupPanel)({...r,children:y})}));w.displayName=`RunScriptPopupPanel`;var T=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,disabled:r,...i}=e,a=(0,d.useCommands)([`showScriptEditor`])[0],s=(0,d.useCommandButtonEntry)(`scriptsOptions`);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:r,createPopupPanel:(0,o.useCallback)(e=>{let t=(0,m.jsx)(w,{disabled:r,groupKey:n,...e});return(0,f.defaultCreatePopupPanel)({...e,children:t})},[r,n]),selected:a?.getState(),label:s?.getLabel?.(),tooltip:s?.getDescription?.(),quickCommand:`showScriptEditor`,...i})})),E=`https://unpkg.com/@sheetxl/scripting-templates/dist`,D=(e,t)=>{try{return new URL(t).href}catch{}if(t.startsWith(`/`)||/^[a-zA-Z]:/.test(t))return t;let n=e.startsWith(`http`)?e:`file:///${e.replace(/\\/g,`/`)}`;return n.endsWith(`/`)||(n+=`/`),new URL(t,n).href},O=e=>{if(e.metadata?.name)return e.metadata.name;let t=(e.path.split(`/`).pop()||``).replace(/\.[^/.]+$/,``);return e.metadata?.icon===`formula`?t.toUpperCase():(t=t.replace(/([a-z])([A-Z])/g,`$1 $2`),t.replace(/[-_]/g,` `).trim().split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `))},k=async e=>{let t=D(e,`./manifest.json`),n=await fetch(t);if(!n.ok)throw new g.ChainedError(`Failed to retrieve directory at '${e}': ${n.statusText}`);let r=await n.text();if(r.trim().toLowerCase().startsWith(`<!doctype html`)||r.trim().toLowerCase().startsWith(`<html`))throw new g.ChainedError(`Failed to retrieve directory at '${e}'`);let i;try{i=JSON.parse(r)}catch(e){throw Error(`Failed to parse directory: ${e.message}. Ensure the file is valid JSON.`)}let a=i.map(async t=>{try{let n=D(e,t.path),r=await fetch(n);if(!r.ok)throw Error(`Failed to fetch file at '${t.path}': ${r.statusText}`);let i=await r.text(),a=t.metadata;return a?.title||(a={title:O(t),...a}),{path:t.path,content:i,metadata:a}}catch(e){console.error(e.message)}return null});return(await Promise.all(a)).filter(e=>e!==null)},A={marginRight:`4px`},j=`1em`,M=(0,o.memo)(e=>{let{disabled:t,snippet:n,description:r,handleInsert:i,sx:a,...o}=e,s,c=n.metadata?.icon;return s=c===`formula`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptFormula`,size:j,style:A}):c===`macro`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`,size:j,style:A}):(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptAutoRun`,size:j,style:A}),(0,m.jsx)(f.ExhibitMenuItem,{sx:{maxWidth:`460px`,display:`flex`,"*":{lineHeight:`1.2`},...a},disabled:t,icon:s,onMouseDown:e=>{e.button===0&&e.preventDefault()},onMouseUp:e=>{e.button===0&&i(n)},onKeyDown:e=>{e.keyCode!==d.KeyCodes.Enter&&e.keyCode!==d.KeyCodes.Space||i(n)},...o,children:(0,m.jsxs)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`},children:[(0,m.jsx)(u.Typography,{component:`div`,children:n.metadata?.title??n.path}),(0,m.jsx)(u.Typography,{variant:`caption`,component:`div`,sx:{color:e=>(0,h.alpha)(e.palette.text.secondary??e.palette.text.primary,.6),overflow:`hidden`,textOverflow:`ellipsis`},children:n.metadata?.summary})]})})}),N=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,disabled:r,scriptPath:i=E,...a}=e,s=(0,d.useTranslator)(),[c,l]=(0,o.useState)([]),[p,h]=(0,o.useState)(!0),[g]=(0,d.useCommands)([`insertScript`]),_=r||(g?.disabled()??!1);(0,o.useEffect)(()=>{(async()=>{try{let e=await k(i);l(e)}catch{}finally{h(!1)}})()},[i]);let v=(0,o.useCallback)(e=>{if(p)return(0,m.jsx)(`div`,{children:s(`insertScript.loading`)});let t={variant:d.CommandButtonType.Menuitem,groupKey:`scriptsOptions`,disabled:_},n=t=>{g?.execute(t.content),e.closeFloat?.()},r=[];for(let e=0;e<c.length;e++){let t=c[e];t&&r.push((0,m.jsx)(M,{handleInsert:n,snippet:t},t.path))}let i=(0,m.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[r.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:r}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...t,key:`showKeyboardShortcuts`,commandKey:`showKeyboardShortcuts`}),(0,o.createElement)(f.CommandButton,{...t,key:`scriptingHelp`,commandKey:`scriptingHelp`})]});return(0,f.defaultCreatePopupPanel)({...e,children:i})},[_,n,p,g,s]);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:_,groupKey:n,label:g?.getLabel(n)??s(`insertScript.fallbackLabel`),tooltip:g?.getDescription(),createPopupPanel:v,icon:g?.getIcon()??`ScriptInsert`,...a})})),P=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{propsCommandButton:n,...r}=e;return(0,m.jsx)(f.CommandToolbar,{ref:t,propsCommandButton:n,renderToolbarPalette:(0,d.useCallbackRef)(e=>{let{propsCommandButton:t,propsCommandPopup:n}=e;return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(`div`,{style:{display:`flex`,flex:`1 1 100%`},children:[(0,m.jsx)(`div`,{children:(0,m.jsx)(f.OverflowPalette,{style:{},children:(0,m.jsx)(f.CommandButton,{...t,commandKey:`saveScripts`})})}),(0,m.jsx)(`div`,{style:{flex:`1 1 100%`}}),(0,m.jsx)(`div`,{children:(0,m.jsx)(f.OverflowPalette,{style:{},children:(0,m.jsx)(N,{...t})})})]})})},[]),...r})}));P.displayName=`ScriptEditorToolbar`,C();var F=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{scriptPath:n=E,onScriptSelect:r,disabled:i=!1,sx:a=d.ReactUtils.EmptyCssProperties,className:s,buttonMinWidth:c=210,buttonMinHeight:l=80,gap:f=12,...p}=e,h=(0,d.useTranslator)(),[_,v]=(0,o.useState)([]),[b,x]=(0,o.useState)(!0),[S,C]=(0,o.useState)(null);if((0,o.useEffect)(()=>{(async()=>{let e=[{path:null,metadata:{title:h(`templateSelect.blankTitle`),summary:h(`templateSelect.blankSummary`)},content:``}];try{x(!0),C(null);let t=await k(n);for(let n=0;n<t.length;n++){let r=t[n];r&&e.push(r)}}catch(e){C(e instanceof Error?e.message:h(`templateSelect.loadFailed`)),e instanceof g.ChainedError||console.error(`Error loading scripts:`,e)}finally{v(e),x(!1)}})()},[n,h]),b)return(0,m.jsx)(u.Box,{className:y(s,`script-select`),...p,sx:[{display:`flex`,justifyContent:`center`,alignItems:`center`,height:`100%`,background:e=>e.palette.background.paper,zIndex:1e3,...Array.isArray(a)?{}:a},...Array.isArray(a)?a:[]],children:(0,m.jsx)(u.CircularProgress,{})});let w=null;S&&(w=(0,m.jsxs)(u.Box,{className:y(s,`script-select`,`error-results`),...p,sx:[{display:`flex`,justifyContent:`center`,alignItems:`center`,background:e=>e.palette.error.light,flex:`0`,zIndex:1e3,flexDirection:`column`,padding:e=>e.spacing(1),border:e=>`1px solid ${e.palette.error.main}`,borderBottomLeftRadius:1,borderBottomRightRadius:1},...Array.isArray(a)?a:[a]],children:[(0,m.jsx)(u.Typography,{color:`error`,variant:`h6`,component:`div`,gutterBottom:!0,children:h(`templateSelect.errorTitle`)}),(0,m.jsx)(u.Typography,{color:`error`,component:`div`,children:S})]}));let T=e=>{let t=e.metadata?.icon;return t===`macro`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`,size:`1em`}):t===`formula`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptFormula`,size:`1em`}):t===`autostart`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptAutoRun`,size:`1em`}):null};return(0,m.jsxs)(u.Box,{ref:t,className:y(s,`script-select`),sx:{background:e=>e.palette.background.paper,zIndex:1e3,...a},...p,children:[(0,m.jsxs)(u.Box,{className:`script-select-content`,sx:{p:3,overflow:`auto`,flex:`1 1 auto`},children:[(0,m.jsx)(u.Typography,{variant:`h6`,gutterBottom:!0,children:h(`templateSelect.title`)}),(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,gutterBottom:!0,sx:{color:`text.secondary`},children:h(`templateSelect.intro`)}),(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,gutterBottom:!0,sx:{color:`text.secondary`},children:h(`templateSelect.intro2`)}),(0,m.jsx)(u.Box,{sx:{display:`grid`,gridTemplateColumns:`repeat(auto-fill, minmax(${c}px, 1fr))`,gap:`${f}px`,padding:2,paddingLeft:`0px`,paddingRight:`0px`},children:_.map((e,t)=>(0,m.jsxs)(u.Button,{variant:`outlined`,disabled:i,sx:{minWidth:c,minHeight:l,display:`flex`,flexDirection:`column`,justifyContent:`flex-start`,alignItems:`flex-start`,textAlign:`left`,padding:2,textTransform:`none`,overflow:`hidden`,...t===0&&{borderStyle:`dashed`,marginBottom:`8px`},...t===1&&{gridColumn:`1`}},onClick:()=>r?.(e),children:[(0,m.jsxs)(u.Box,{sx:{display:`flex`,flexDirection:`row`,justifyContent:`space-between`,alignItems:`center`,width:`100%`,marginBottom:.5},children:[(0,m.jsx)(u.Typography,{variant:`subtitle2`,component:`div`,children:e.metadata?.title||e.path?.split(`/`).pop()?.replace(/\.\w+$/,``)||h(`templateSelect.untitled`)}),T(e)]}),e.metadata?.summary&&(0,m.jsx)(u.Typography,{variant:`body2`,component:`div`,sx:{color:`text.secondary`,overflow:`hidden`,display:`flex`,flexDirection:`column`,textOverflow:`ellipsis`,alignItems:`flex-start`},children:e.metadata.summary})]},`${e.path}-${t}`))})]}),w]})}));F.displayName=`TemplateSelectPanel`;var I=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{className:n,sx:r,propsScriptEditor:i,readOnly:a=!1,frame:s,autoFocusSel:c,autoFocus:l=!0,scripts:p,...h}=e,g=(0,u.useTheme)(),[v,b]=(0,o.useState)(!1),x=(0,o.useRef)(!1),[S,C]=(0,o.useState)({message:`Loading`,cursor:``,dirty:!1}),[w,T]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=!1;return T(null),async function(){if(p&&(await p.start(),!e)){let e=p.getModules().getItems()[0]?.getSource();T({source:e||null})}}(),()=>{e=!0}},[p]);let E=(0,o.useCallback)(e=>{C(t=>({...t,...e}))},[]),D=(0,o.useRef)(null),[O,k]=(0,o.useState)(null),A=(0,o.useRef)(null),j=(0,d.useCallbackRef)(e=>{if(O)return O.focus(e),!0;if(c){let t=D.current?.querySelectorAll?.(c);if(t&&t.length>0)return t[0]?.focus?.(e),!0}return D.current?.focus?.(e),!1},[O,c,l]),M=(0,o.useMemo)(()=>(0,m.jsx)(f.AnimatedLoadingPanel,{transitionDelay:`160ms`,style:{position:`absolute`,width:`100%`,height:`100%`},transparentBackground:!1}),[]),N=(0,o.useMemo)(()=>(0,m.jsx)(u.Paper,{elevation:1,tabIndex:0,sx:{display:`flex`,alignItems:`center`,userSelect:`none`,flexGrow:1,marginLeft:e=>e.spacing(.5),marginRight:e=>e.spacing(.5),marginTop:e=>e.spacing(1),marginBottom:e=>e.spacing(1)},children:(0,m.jsx)(P,{})}),[g]),I=(0,o.useMemo)(()=>(0,m.jsx)(u.Box,{className:y(`script-status-panel`,`status-panel`),sx:{display:`flex`,alignItems:`stretch`,flexDirection:`row`,flex:`0`,paddingLeft:`12px`,paddingRight:`12px`,gap:`8px`,paddingTop:`1px`,minHeight:`calc(1em + 8px)`,margin:0,borderTop:`solid 1px ${g.palette.divider}`},children:(0,m.jsxs)(`div`,{style:{flex:`1 1 100%`,display:`flex`,alignItems:`center`,flexDirection:`row`,justifyContent:`center`},children:[(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`1 1 100%`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.message}),(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`none`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.dirty?`Unsaved`:``}),(0,m.jsx)(u.Typography,{component:`div`,sx:{userSelect:`none`,whiteSpace:`pre`,overflow:`hidden`,textOverflow:`ellipsis`,flex:`none`,marginLeft:`8px`,minWidth:`90px`,display:`flex`,justifyContent:`end`,color:e=>e.palette.text.secondary},variant:`caption`,children:S.cursor})]})}),[S]),L=(0,o.useMemo)(()=>(0,m.jsxs)(u.Box,{className:y(`script-editor-content`),sx:{display:`flex`,flex:`1 1 100%`,width:`100%`,flexDirection:`column`,boxSizing:`border-box`},children:[N,(0,m.jsx)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,width:`100%`,flexDirection:`row`,position:`relative`,boxSizing:`border-box`},children:(0,m.jsx)(_.ScriptEditor,{ref:D,loadingPanel:M,readOnly:a,frame:s,scripts:p,autoFocus:l,onStatusChange:E,darkMode:g.palette.mode===`dark`,...i})}),I]}),[g,N,I,v,M,a,i,l,c,s,E]),R=(0,o.useMemo)(()=>{let e;return w===null?M:(w.source===null&&(e=(0,m.jsx)(F,{sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`,position:`absolute`,boxSizing:`border-box`,width:`100%`,height:`100%`},disabled:a,onScriptSelect:e=>{D.current?.insertSnippet(e.content),T({source:e.content??``}),requestAnimationFrame(()=>D.current?.focus())}})),(0,m.jsx)(u.Box,{tabIndex:0,className:y(`script-workspace`,n),sx:{display:`flex`,flex:`1 1 100%`,flexDirection:`column`,overflow:`hidden`,alignItems:`stretch`,userSelect:`none`,flexGrow:0,outline:`none`},onPointerDown:e=>{e.isDefaultPrevented()||D.current?.focus()},children:(0,m.jsxs)(u.Box,{sx:{flex:`1 1 100%`,position:`relative`,display:`flex`},children:[(0,m.jsx)(u.Box,{sx:{display:`flex`,flex:`1 1 100%`,minWidth:0,minHeight:0,visibility:e?`hidden`:`visible`},children:L}),e]})}))},[N,L,n,w,M,a]),z=(0,d.useImperativeElement)(t,()=>({isScriptWorkspaceElement:()=>!0,focus:e=>{j(e)}}),[]);return(0,m.jsx)(u.Box,{sx:{display:`flex`,flexDirection:`row`,flex:`1 1 100%`,position:`relative`,...r},ref:z,...h,onFocus:e=>{b(!0),x.current=!0,z.current?.contains(e.target)&&e.target!==z.current&&k(e.target),e.relatedTarget&&!A.current&&(A.current=e.relatedTarget),h?.onFocus?.(e)},onBlur:e=>{z?.current?.contains(e.relatedTarget)||z?.current===e.relatedTarget||(A.current=null,x.current=!1,b(!1)),h?.onBlur?.(e)},children:R})}));I.displayName=`ScriptWorkspace`;var{FocusActivation:L,CommandScopeProvider:R,CommandAnchorProvider:z,useCommandScope:B}=d.Command,V={scopeName:`scriptEditor`},H=({children:e})=>{let t=B(),n=(0,o.useRef)(null);return t?(0,m.jsx)(R,{spec:V,elementRef:n,region:!0,children:(0,m.jsx)(U,{paneRef:n,children:e})}):e},U=({paneRef:e,children:t})=>{let n=B(),r=(0,o.useMemo)(()=>n?new L(n.getRoot(),n):null,[n]);return r?(0,m.jsxs)(z,{tracker:r,keyBindings:!1,debounce:100,elementRef:e,children:[(0,m.jsx)(p.InputClipboardInjector,{}),(0,m.jsx)(`div`,{className:`script-editor-pane`,style:{display:`contents`},ref:e,children:t})]}):t},W=e=>{let{model:t,entryKey:n,frame:r,ref:i,...a}=e,o=(0,p.useWorkbook)()??t;return(0,p.useModelSync)(o,[`onProtectionChange`]),(0,m.jsx)(H,{children:(0,m.jsx)(I,{ref:i,readOnly:o?.getScripts().isReadOnly()??!1,frame:r,scripts:o?.getScripts(),...a})})},G=(0,o.memo)(e=>{let{alwaysShow:t=!1,...n}=e,[r,i]=(0,o.useReducer)(e=>e+1,0),[a]=(0,d.useCommands)([`showScriptEditor`],{onChange:()=>i()}),s=(0,p.useWorkbook)(),[c,l]=(0,o.useState)(t);return(0,o.useEffect)(()=>{if(t)return void l(!0);let e=s?.getScripts();if(!e||!a)return void l(!1);let n=async()=>{let t=!1;a.getState()||(t=((await e.searchFunctions({type:`macro`}))?.length??0)>0),l(t||!!a.getState())};n();let r=e.addListeners({onChange:()=>{n()}});return()=>{r()}},[t,s,a,r]),c?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(f.ExhibitDivider,{}),(0,m.jsx)(T,{...n})]}):null});G.displayName=`RunScriptContribution`,C();var K=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{...n}=e,r=(0,p.useWorkbook)(),i=(0,d.useTranslator)(),[a,s]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=r?.getScripts();if(!e)return;let t=!1,n=async()=>{let n=await e.searchFunctions({type:`formula`});t||s(n)};n();let i=e.addListeners({onChange:()=>{n()}});return()=>{t=!0,i()}},[r]);let c={variant:d.CommandButtonType.Menuitem,shortcut:void 0},l=[],h=a?a.length:0;for(let e=0;e<h;e++){let t=a[e];l.push((0,m.jsx)(f.CommandButton,{...c,commandKey:`insertFunction`,commandState:t,propsTooltip:{description:i(`insertFunction.insertNamed`,{name:t.getName()??i(`insertFunction.fallbackLabel`)})},icon:(0,m.jsx)(d.DynamicIcon,{iconKey:`FormulaCustom`}),label:t.getName()??i(`insertFunction.fallbackLabel`)},`function-${t.getName()}-${e}`))}let g=(0,m.jsxs)(u.Box,{ref:t,sx:{display:`flex`,flexDirection:`column`,flex:`1 1 100%`,overflow:`hidden`},children:[l.length>0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(u.Box,{sx:{overflow:`auto`,flex:`1 1 100%`},children:l}),(0,m.jsx)(f.ExhibitDivider,{orientation:`horizontal`})]}):null,(0,o.createElement)(f.CommandButton,{...c,key:`show-editor`,commandKey:`showScriptEditor`})]});return(0,f.defaultCreatePopupPanel)({...n,children:g})}));K.displayName=`InsertFunctionPopupPanel`;var q=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{disabled:n,groupKey:r,...i}=e,a=(0,d.useCommandButtonEntry)(`customFunctionOptions`);return(0,m.jsx)(f.CommandPopupButton,{ref:t,disabled:n,createPopupPanel:(0,o.useCallback)(e=>{let t=(0,m.jsx)(K,{disabled:n,groupKey:r,...e});return(0,f.defaultCreatePopupPanel)({...e,children:t})},[n,r]),label:a?.getLabel?.(),tooltip:a?.getDescription?.(),icon:`FormulaCustom`,...i})}));q.displayName=`InsertFunctionContribution`,exports.InsertScriptCommandButton=N,exports.RunScriptCommandButton=T,exports.ScriptEditorToolbar=P,exports.ScriptTaskPane=W,exports.ScriptWorkspace=I,exports.ScriptingPlugin=()=>{(0,_.ScriptingReactPlugin)(),d.DefaultIconService.register(`plugin-scripts`,{icons:{}}),p.DefaultTaskPaneRegistry.registerTaskPane({key:`scriptEditor`,getTitle:()=>`Script (Typescript)`,getIcon:()=>`ScriptRun`,component:W,keepMounted:!0},!0),d.DefaultCommandButtonRegistry.register({key:`scriptsOptions`},!0),d.DefaultCommandButtonRegistry.register({key:`customFunctionOptions`},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.runScript.home`,contributions:{homeToolbar:{}},render:e=>o.default.createElement(G,{...e})},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.runScript.view`,contributions:{viewToolbar:{order:10}},render:e=>o.default.createElement(G,{...e,groupKey:`view`,alwaysShow:!0})},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.insertFunction.formula`,contributions:{formulaToolbar:{anchor:`formulaCategory.web`,order:1}},render:e=>o.default.createElement(q,{...e})},!0)};
|
package/browser/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.
|
|
2
|
+
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.2
|
|
3
3
|
*
|
|
4
4
|
* (C) 2026-present SheetXL Inc. & Michael T. Ford
|
|
5
5
|
* License: The license can be found at https://www.sheetxl.com/license.
|
|
@@ -7,28 +7,30 @@
|
|
|
7
7
|
import e, { createElement as t, forwardRef as n, memo as r, useCallback as i, useEffect as a, useMemo as o, useReducer as s, useRef as c, useState as l } from "react";
|
|
8
8
|
import { Box as u, Button as d, CircularProgress as f, Paper as p, Typography as m, useTheme as h } from "@mui/material";
|
|
9
9
|
import { Command as g, CommandButtonType as _, DefaultCommandButtonRegistry as v, DefaultIconService as y, DynamicIcon as b, KeyCodes as x, ReactUtils as S, useCallbackRef as C, useCommandButtonEntry as w, useCommands as T, useImperativeElement as E, useTranslator as D } from "@sheetxl/utils-react";
|
|
10
|
-
import { AnimatedLoadingPanel as ee, CommandButton as O, CommandPopupButton as k, CommandToolbar as A, ExhibitDivider as j, ExhibitMenuItem as M, OverflowPalette as N, defaultCreatePopupPanel as P
|
|
11
|
-
import { DefaultTaskPaneRegistry as
|
|
10
|
+
import { AnimatedLoadingPanel as ee, CommandButton as O, CommandPopupButton as k, CommandToolbar as A, ExhibitDivider as j, ExhibitMenuItem as M, OverflowPalette as N, defaultCreatePopupPanel as P } from "@sheetxl/utils-mui";
|
|
11
|
+
import { DefaultTaskPaneRegistry as F, InputClipboardInjector as I, useModelSync as L, useWorkbook as R } from "@sheetxl/react";
|
|
12
12
|
import { Fragment as z, jsx as B, jsxs as V } from "react/jsx-runtime";
|
|
13
13
|
import { alpha as H } from "@mui/system";
|
|
14
14
|
import { ChainedError as U } from "@sheetxl/utils";
|
|
15
15
|
import { ScriptEditor as te, ScriptingReactPlugin as ne } from "@sheetxl/scripting-react";
|
|
16
|
-
function
|
|
16
|
+
function re(e) {
|
|
17
17
|
var t, n, r = "";
|
|
18
18
|
if (typeof e == "string" || typeof e == "number") r += e;
|
|
19
19
|
else if (typeof e == "object") if (Array.isArray(e)) {
|
|
20
20
|
var i = e.length;
|
|
21
|
-
for (t = 0; t < i; t++) e[t] && (n =
|
|
21
|
+
for (t = 0; t < i; t++) e[t] && (n = re(e[t])) && (r && (r += " "), r += n);
|
|
22
22
|
} else for (n in e) e[n] && (r && (r += " "), r += n);
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t =
|
|
25
|
+
function W() {
|
|
26
|
+
for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = re(e)) && (r && (r += " "), r += t);
|
|
27
27
|
return r;
|
|
28
28
|
}
|
|
29
|
-
var
|
|
29
|
+
var ie = {
|
|
30
30
|
"insertFunction.fallbackLabel": "Function",
|
|
31
31
|
"insertFunction.insertNamed": "Insert {name}",
|
|
32
|
+
"insertScript.fallbackLabel": "Insert Script",
|
|
33
|
+
"insertScript.loading": "Loading...",
|
|
32
34
|
"runScript.executeNamed": "Execute {name}",
|
|
33
35
|
"runScript.fallbackLabel": "Macro",
|
|
34
36
|
"templateSelect.blankSummary": "Start with an empty script.",
|
|
@@ -39,12 +41,12 @@ var re = {
|
|
|
39
41
|
"templateSelect.loadFailed": "Failed to load scripts",
|
|
40
42
|
"templateSelect.title": "Script Template",
|
|
41
43
|
"templateSelect.untitled": "Untitled"
|
|
42
|
-
}, { DefaultCommandCatalogService:
|
|
43
|
-
function
|
|
44
|
-
|
|
44
|
+
}, { DefaultCommandCatalogService: ae } = g, G = !1;
|
|
45
|
+
function K() {
|
|
46
|
+
G || (G = !0, ae.registerFromManifest("@sheetxl/scripting-mui", import.meta.url, { messages: ie }));
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
+
K();
|
|
49
|
+
var q = r(n((e, n) => {
|
|
48
50
|
let { groupKey: r, ...i } = e, o = R(), s = D(), [c, d] = l([]), [f, p] = l(!1);
|
|
49
51
|
a(() => {
|
|
50
52
|
let e = o?.getScripts();
|
|
@@ -95,14 +97,14 @@ var J = r(n((e, n) => {
|
|
|
95
97
|
children: v
|
|
96
98
|
});
|
|
97
99
|
}));
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
+
q.displayName = "RunScriptPopupPanel";
|
|
101
|
+
var J = r(n((e, t) => {
|
|
100
102
|
let { groupKey: n, disabled: r, ...a } = e, o = T(["showScriptEditor"])[0], s = w("scriptsOptions");
|
|
101
103
|
return B(k, {
|
|
102
104
|
ref: t,
|
|
103
105
|
disabled: r,
|
|
104
106
|
createPopupPanel: i((e) => {
|
|
105
|
-
let t = B(
|
|
107
|
+
let t = B(q, {
|
|
106
108
|
disabled: r,
|
|
107
109
|
groupKey: n,
|
|
108
110
|
...e
|
|
@@ -215,28 +217,28 @@ var ae = r(n((e, t) => {
|
|
|
215
217
|
})
|
|
216
218
|
});
|
|
217
219
|
}), de = r(n((e, n) => {
|
|
218
|
-
let { groupKey: r, disabled: o, scriptPath: s = oe, ...c } = e,
|
|
220
|
+
let { groupKey: r, disabled: o, scriptPath: s = oe, ...c } = e, d = D(), [f, p] = l([]), [m, h] = l(!0), [g] = T(["insertScript"]), v = o || (g?.disabled() ?? !1);
|
|
219
221
|
a(() => {
|
|
220
222
|
(async () => {
|
|
221
223
|
try {
|
|
222
224
|
let e = await le(s);
|
|
223
|
-
|
|
225
|
+
p(e);
|
|
224
226
|
} catch {} finally {
|
|
225
|
-
|
|
227
|
+
h(!1);
|
|
226
228
|
}
|
|
227
229
|
})();
|
|
228
230
|
}, [s]);
|
|
229
|
-
let
|
|
230
|
-
if (
|
|
231
|
+
let y = i((e) => {
|
|
232
|
+
if (m) return B("div", { children: d("insertScript.loading") });
|
|
231
233
|
let n = {
|
|
232
234
|
variant: _.Menuitem,
|
|
233
235
|
groupKey: "scriptsOptions",
|
|
234
|
-
disabled:
|
|
236
|
+
disabled: v
|
|
235
237
|
}, r = (t) => {
|
|
236
|
-
|
|
238
|
+
g?.execute(t.content), e.closeFloat?.();
|
|
237
239
|
}, i = [];
|
|
238
|
-
for (let e = 0; e <
|
|
239
|
-
let t =
|
|
240
|
+
for (let e = 0; e < f.length; e++) {
|
|
241
|
+
let t = f[e];
|
|
240
242
|
t && i.push(B(ue, {
|
|
241
243
|
handleInsert: r,
|
|
242
244
|
snippet: t
|
|
@@ -274,19 +276,20 @@ var ae = r(n((e, t) => {
|
|
|
274
276
|
children: a
|
|
275
277
|
});
|
|
276
278
|
}, [
|
|
277
|
-
|
|
279
|
+
v,
|
|
278
280
|
r,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
m,
|
|
282
|
+
g,
|
|
283
|
+
d
|
|
281
284
|
]);
|
|
282
285
|
return B(k, {
|
|
283
286
|
ref: n,
|
|
284
|
-
disabled:
|
|
287
|
+
disabled: v,
|
|
285
288
|
groupKey: r,
|
|
286
|
-
label:
|
|
287
|
-
tooltip:
|
|
288
|
-
createPopupPanel:
|
|
289
|
-
icon:
|
|
289
|
+
label: g?.getLabel(r) ?? d("insertScript.fallbackLabel"),
|
|
290
|
+
tooltip: g?.getDescription(),
|
|
291
|
+
createPopupPanel: y,
|
|
292
|
+
icon: g?.getIcon() ?? "ScriptInsert",
|
|
290
293
|
...c
|
|
291
294
|
});
|
|
292
295
|
})), Z = r(n((e, t) => {
|
|
@@ -320,35 +323,35 @@ var ae = r(n((e, t) => {
|
|
|
320
323
|
...r
|
|
321
324
|
});
|
|
322
325
|
}));
|
|
323
|
-
Z.displayName = "ScriptEditorToolbar",
|
|
326
|
+
Z.displayName = "ScriptEditorToolbar", K();
|
|
324
327
|
var fe = r(n((e, t) => {
|
|
325
|
-
let { scriptPath: n = oe, onScriptSelect: r,
|
|
328
|
+
let { scriptPath: n = oe, onScriptSelect: r, disabled: i = !1, sx: o = S.EmptyCssProperties, className: s, buttonMinWidth: c = 210, buttonMinHeight: p = 80, gap: h = 12, ...g } = e, _ = D(), [v, y] = l([]), [x, C] = l(!0), [w, T] = l(null);
|
|
326
329
|
if (a(() => {
|
|
327
330
|
(async () => {
|
|
328
331
|
let e = [{
|
|
329
332
|
path: null,
|
|
330
333
|
metadata: {
|
|
331
|
-
title:
|
|
332
|
-
summary:
|
|
334
|
+
title: _("templateSelect.blankTitle"),
|
|
335
|
+
summary: _("templateSelect.blankSummary")
|
|
333
336
|
},
|
|
334
337
|
content: ""
|
|
335
338
|
}];
|
|
336
339
|
try {
|
|
337
|
-
|
|
340
|
+
C(!0), T(null);
|
|
338
341
|
let t = await le(n);
|
|
339
342
|
for (let n = 0; n < t.length; n++) {
|
|
340
343
|
let r = t[n];
|
|
341
344
|
r && e.push(r);
|
|
342
345
|
}
|
|
343
346
|
} catch (e) {
|
|
344
|
-
|
|
347
|
+
T(e instanceof Error ? e.message : _("templateSelect.loadFailed")), e instanceof U || console.error("Error loading scripts:", e);
|
|
345
348
|
} finally {
|
|
346
|
-
|
|
349
|
+
y(e), C(!1);
|
|
347
350
|
}
|
|
348
351
|
})();
|
|
349
|
-
}, [n,
|
|
350
|
-
className:
|
|
351
|
-
...
|
|
352
|
+
}, [n, _]), x) return B(u, {
|
|
353
|
+
className: W(s, "script-select"),
|
|
354
|
+
...g,
|
|
352
355
|
sx: [{
|
|
353
356
|
display: "flex",
|
|
354
357
|
justifyContent: "center",
|
|
@@ -356,15 +359,14 @@ var fe = r(n((e, t) => {
|
|
|
356
359
|
height: "100%",
|
|
357
360
|
background: (e) => e.palette.background.paper,
|
|
358
361
|
zIndex: 1e3,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}, ...Array.isArray(i) ? i : []],
|
|
362
|
+
...Array.isArray(o) ? {} : o
|
|
363
|
+
}, ...Array.isArray(o) ? o : []],
|
|
362
364
|
children: B(f, {})
|
|
363
365
|
});
|
|
364
|
-
let
|
|
365
|
-
|
|
366
|
-
className:
|
|
367
|
-
...
|
|
366
|
+
let E = null;
|
|
367
|
+
w && (E = V(u, {
|
|
368
|
+
className: W(s, "script-select", "error-results"),
|
|
369
|
+
...g,
|
|
368
370
|
sx: [{
|
|
369
371
|
display: "flex",
|
|
370
372
|
justifyContent: "center",
|
|
@@ -376,22 +378,21 @@ var fe = r(n((e, t) => {
|
|
|
376
378
|
padding: (e) => e.spacing(1),
|
|
377
379
|
border: (e) => `1px solid ${e.palette.error.main}`,
|
|
378
380
|
borderBottomLeftRadius: 1,
|
|
379
|
-
borderBottomRightRadius: 1
|
|
380
|
-
|
|
381
|
-
}, ...Array.isArray(i) ? i : [i]],
|
|
381
|
+
borderBottomRightRadius: 1
|
|
382
|
+
}, ...Array.isArray(o) ? o : [o]],
|
|
382
383
|
children: [B(m, {
|
|
383
384
|
color: "error",
|
|
384
385
|
variant: "h6",
|
|
385
386
|
component: "div",
|
|
386
387
|
gutterBottom: !0,
|
|
387
|
-
children:
|
|
388
|
+
children: _("templateSelect.errorTitle")
|
|
388
389
|
}), B(m, {
|
|
389
390
|
color: "error",
|
|
390
391
|
component: "div",
|
|
391
|
-
children:
|
|
392
|
+
children: w
|
|
392
393
|
})]
|
|
393
394
|
}));
|
|
394
|
-
let
|
|
395
|
+
let ee = (e) => {
|
|
395
396
|
let t = e.metadata?.icon;
|
|
396
397
|
return t === "macro" ? B(b, {
|
|
397
398
|
iconKey: "ScriptMacro",
|
|
@@ -406,14 +407,13 @@ var fe = r(n((e, t) => {
|
|
|
406
407
|
};
|
|
407
408
|
return V(u, {
|
|
408
409
|
ref: t,
|
|
409
|
-
className:
|
|
410
|
+
className: W(s, "script-select"),
|
|
410
411
|
sx: {
|
|
411
412
|
background: (e) => e.palette.background.paper,
|
|
412
413
|
zIndex: 1e3,
|
|
413
|
-
|
|
414
|
-
...i
|
|
414
|
+
...o
|
|
415
415
|
},
|
|
416
|
-
...
|
|
416
|
+
...g,
|
|
417
417
|
children: [V(u, {
|
|
418
418
|
className: "script-select-content",
|
|
419
419
|
sx: {
|
|
@@ -425,36 +425,37 @@ var fe = r(n((e, t) => {
|
|
|
425
425
|
B(m, {
|
|
426
426
|
variant: "h6",
|
|
427
427
|
gutterBottom: !0,
|
|
428
|
-
children:
|
|
428
|
+
children: _("templateSelect.title")
|
|
429
429
|
}),
|
|
430
430
|
B(m, {
|
|
431
431
|
variant: "body2",
|
|
432
432
|
component: "div",
|
|
433
433
|
gutterBottom: !0,
|
|
434
434
|
sx: { color: "text.secondary" },
|
|
435
|
-
children:
|
|
435
|
+
children: _("templateSelect.intro")
|
|
436
436
|
}),
|
|
437
437
|
B(m, {
|
|
438
438
|
variant: "body2",
|
|
439
439
|
component: "div",
|
|
440
440
|
gutterBottom: !0,
|
|
441
441
|
sx: { color: "text.secondary" },
|
|
442
|
-
children:
|
|
442
|
+
children: _("templateSelect.intro2")
|
|
443
443
|
}),
|
|
444
444
|
B(u, {
|
|
445
445
|
sx: {
|
|
446
446
|
display: "grid",
|
|
447
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${
|
|
448
|
-
gap: `${
|
|
447
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${c}px, 1fr))`,
|
|
448
|
+
gap: `${h}px`,
|
|
449
449
|
padding: 2,
|
|
450
450
|
paddingLeft: "0px",
|
|
451
451
|
paddingRight: "0px"
|
|
452
452
|
},
|
|
453
|
-
children:
|
|
453
|
+
children: v.map((e, t) => V(d, {
|
|
454
454
|
variant: "outlined",
|
|
455
|
+
disabled: i,
|
|
455
456
|
sx: {
|
|
456
|
-
minWidth:
|
|
457
|
-
minHeight:
|
|
457
|
+
minWidth: c,
|
|
458
|
+
minHeight: p,
|
|
458
459
|
display: "flex",
|
|
459
460
|
flexDirection: "column",
|
|
460
461
|
justifyContent: "flex-start",
|
|
@@ -482,8 +483,8 @@ var fe = r(n((e, t) => {
|
|
|
482
483
|
children: [B(m, {
|
|
483
484
|
variant: "subtitle2",
|
|
484
485
|
component: "div",
|
|
485
|
-
children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") ||
|
|
486
|
-
}),
|
|
486
|
+
children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") || _("templateSelect.untitled")
|
|
487
|
+
}), ee(e)]
|
|
487
488
|
}), e.metadata?.summary && B(m, {
|
|
488
489
|
variant: "body2",
|
|
489
490
|
component: "div",
|
|
@@ -500,7 +501,7 @@ var fe = r(n((e, t) => {
|
|
|
500
501
|
}, `${e.path}-${t}`))
|
|
501
502
|
})
|
|
502
503
|
]
|
|
503
|
-
}),
|
|
504
|
+
}), E]
|
|
504
505
|
});
|
|
505
506
|
}));
|
|
506
507
|
fe.displayName = "TemplateSelectPanel";
|
|
@@ -560,7 +561,7 @@ var Q = r(n((e, t) => {
|
|
|
560
561
|
},
|
|
561
562
|
children: B(Z, {})
|
|
562
563
|
}), [b]), R = o(() => B(u, {
|
|
563
|
-
className:
|
|
564
|
+
className: W("script-status-panel", "status-panel"),
|
|
564
565
|
sx: {
|
|
565
566
|
display: "flex",
|
|
566
567
|
alignItems: "stretch",
|
|
@@ -629,7 +630,7 @@ var Q = r(n((e, t) => {
|
|
|
629
630
|
]
|
|
630
631
|
})
|
|
631
632
|
}), [T]), z = o(() => V(u, {
|
|
632
|
-
className:
|
|
633
|
+
className: W("script-editor-content"),
|
|
633
634
|
sx: {
|
|
634
635
|
display: "flex",
|
|
635
636
|
flex: "1 1 100%",
|
|
@@ -687,12 +688,13 @@ var Q = r(n((e, t) => {
|
|
|
687
688
|
width: "100%",
|
|
688
689
|
height: "100%"
|
|
689
690
|
},
|
|
691
|
+
disabled: d,
|
|
690
692
|
onScriptSelect: (e) => {
|
|
691
693
|
j.current?.insertSnippet(e.content), k({ source: e.content ?? "" }), requestAnimationFrame(() => j.current?.focus());
|
|
692
694
|
}
|
|
693
695
|
})), B(u, {
|
|
694
696
|
tabIndex: 0,
|
|
695
|
-
className:
|
|
697
|
+
className: W("script-workspace", n),
|
|
696
698
|
sx: {
|
|
697
699
|
display: "flex",
|
|
698
700
|
flex: "1 1 100%",
|
|
@@ -729,7 +731,8 @@ var Q = r(n((e, t) => {
|
|
|
729
731
|
z,
|
|
730
732
|
n,
|
|
731
733
|
O,
|
|
732
|
-
I
|
|
734
|
+
I,
|
|
735
|
+
d
|
|
733
736
|
]), U = E(t, () => ({
|
|
734
737
|
isScriptWorkspaceElement: () => !0,
|
|
735
738
|
focus: (e) => {
|
|
@@ -774,7 +777,7 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he,
|
|
|
774
777
|
keyBindings: !1,
|
|
775
778
|
debounce: 100,
|
|
776
779
|
elementRef: e,
|
|
777
|
-
children: [B(
|
|
780
|
+
children: [B(I, {}), B("div", {
|
|
778
781
|
className: "script-editor-pane",
|
|
779
782
|
style: { display: "contents" },
|
|
780
783
|
ref: e,
|
|
@@ -782,12 +785,12 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he,
|
|
|
782
785
|
})]
|
|
783
786
|
}) : t;
|
|
784
787
|
}, be = (e) => {
|
|
785
|
-
let { model: t, entryKey: n, frame: r, ref: i, ...a } = e;
|
|
786
|
-
return B(ve, { children: B(Q, {
|
|
788
|
+
let { model: t, entryKey: n, frame: r, ref: i, ...a } = e, o = R() ?? t;
|
|
789
|
+
return L(o, ["onProtectionChange"]), B(ve, { children: B(Q, {
|
|
787
790
|
ref: i,
|
|
788
|
-
readOnly: !1,
|
|
791
|
+
readOnly: o?.getScripts().isReadOnly() ?? !1,
|
|
789
792
|
frame: r,
|
|
790
|
-
scripts:
|
|
793
|
+
scripts: o?.getScripts(),
|
|
791
794
|
...a
|
|
792
795
|
}) });
|
|
793
796
|
}, $ = r((e) => {
|
|
@@ -812,9 +815,9 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he,
|
|
|
812
815
|
c,
|
|
813
816
|
o,
|
|
814
817
|
r
|
|
815
|
-
]), u ? V(z, { children: [B(j, {}), B(
|
|
818
|
+
]), u ? V(z, { children: [B(j, {}), B(J, { ...n })] }) : null;
|
|
816
819
|
});
|
|
817
|
-
$.displayName = "RunScriptContribution",
|
|
820
|
+
$.displayName = "RunScriptContribution", K();
|
|
818
821
|
var xe = r(n((e, n) => {
|
|
819
822
|
let { ...r } = e, i = R(), o = D(), [s, c] = l([]);
|
|
820
823
|
a(() => {
|
|
@@ -897,7 +900,7 @@ var Se = r(n((e, t) => {
|
|
|
897
900
|
}));
|
|
898
901
|
Se.displayName = "InsertFunctionContribution";
|
|
899
902
|
var Ce = () => {
|
|
900
|
-
ne(), y.register("plugin-scripts", { icons: {} }),
|
|
903
|
+
ne(), y.register("plugin-scripts", { icons: {} }), F.registerTaskPane({
|
|
901
904
|
key: "scriptEditor",
|
|
902
905
|
getTitle: () => "Script (Typescript)",
|
|
903
906
|
getIcon: () => "ScriptRun",
|
|
@@ -924,4 +927,4 @@ var Ce = () => {
|
|
|
924
927
|
render: (t) => e.createElement(Se, { ...t })
|
|
925
928
|
}, !0);
|
|
926
929
|
};
|
|
927
|
-
export { de as InsertScriptCommandButton,
|
|
930
|
+
export { de as InsertScriptCommandButton, J as RunScriptCommandButton, Z as ScriptEditorToolbar, be as ScriptTaskPane, Q as ScriptWorkspace, Ce as ScriptingPlugin };
|
package/node/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.
|
|
2
|
+
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.2
|
|
3
3
|
*
|
|
4
4
|
* (C) 2026-present SheetXL Inc. & Michael T. Ford
|
|
5
5
|
* License: The license can be found at https://www.sheetxl.com/license.
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
import e, { createElement as t, forwardRef as r, memo as n, useCallback as i, useEffect as o, useMemo as a, useReducer as l, useRef as s, useState as c } from "react";
|
|
8
8
|
import d from "clsx";
|
|
9
9
|
import { Box as p, Button as m, CircularProgress as u, Paper as h, Typography as f, useTheme as g } from "@mui/material";
|
|
10
|
-
import { Command as x, CommandButtonType as y, DefaultCommandButtonRegistry as S, DefaultIconService as
|
|
11
|
-
import { AnimatedLoadingPanel as
|
|
12
|
-
import { DefaultTaskPaneRegistry as
|
|
10
|
+
import { Command as x, CommandButtonType as y, DefaultCommandButtonRegistry as S, DefaultIconService as b, DynamicIcon as v, KeyCodes as w, ReactUtils as k, useCallbackRef as C, useCommandButtonEntry as F, useCommands as N, useImperativeElement as T, useTranslator as K } from "@sheetxl/utils-react";
|
|
11
|
+
import { AnimatedLoadingPanel as D, CommandButton as I, CommandPopupButton as L, CommandToolbar as P, ExhibitDivider as E, ExhibitMenuItem as $, OverflowPalette as R, defaultCreatePopupPanel as z } from "@sheetxl/utils-mui";
|
|
12
|
+
import { DefaultTaskPaneRegistry as B, InputClipboardInjector as O, useModelSync as A, useWorkbook as M } from "@sheetxl/react";
|
|
13
13
|
import { Fragment as W, jsx as j, jsxs as H } from "react/jsx-runtime";
|
|
14
14
|
import { alpha as U } from "@mui/system";
|
|
15
15
|
import { ChainedError as q } from "@sheetxl/utils";
|
|
@@ -17,6 +17,8 @@ import { ScriptEditor as G, ScriptingReactPlugin as J } from "@sheetxl/scripting
|
|
|
17
17
|
var Z = {
|
|
18
18
|
"insertFunction.fallbackLabel": "Function",
|
|
19
19
|
"insertFunction.insertNamed": "Insert {name}",
|
|
20
|
+
"insertScript.fallbackLabel": "Insert Script",
|
|
21
|
+
"insertScript.loading": "Loading...",
|
|
20
22
|
"runScript.executeNamed": "Execute {name}",
|
|
21
23
|
"runScript.fallbackLabel": "Macro",
|
|
22
24
|
"templateSelect.blankSummary": "Start with an empty script.",
|
|
@@ -50,12 +52,12 @@ var X = n(r((e, r) => {
|
|
|
50
52
|
}, f = [], g = s ? s.length : 0;
|
|
51
53
|
for (let e = 0; e < g; e++) {
|
|
52
54
|
const t = s[e];
|
|
53
|
-
f.push(j(
|
|
55
|
+
f.push(j(I, {
|
|
54
56
|
...h,
|
|
55
57
|
commandKey: "executeScript",
|
|
56
58
|
commandState: { declaration: t },
|
|
57
59
|
propsTooltip: { description: l("runScript.executeNamed", { name: t.getName() ?? l("runScript.fallbackLabel") }) },
|
|
58
|
-
icon: j(
|
|
60
|
+
icon: j(v, { iconKey: "ScriptMacro" }),
|
|
59
61
|
label: t.getName() ?? l("runScript.fallbackLabel")
|
|
60
62
|
}, `macro-${t.getName()}-${e}`));
|
|
61
63
|
}
|
|
@@ -73,7 +75,7 @@ var X = n(r((e, r) => {
|
|
|
73
75
|
flex: "1 1 100%"
|
|
74
76
|
},
|
|
75
77
|
children: f
|
|
76
|
-
}), j(
|
|
78
|
+
}), j(E, { orientation: "horizontal" })] }) : null, t(I, {
|
|
77
79
|
...h,
|
|
78
80
|
key: "show-editor",
|
|
79
81
|
commandKey: "showScriptEditor"
|
|
@@ -87,7 +89,7 @@ var X = n(r((e, r) => {
|
|
|
87
89
|
X.displayName = "RunScriptPopupPanel";
|
|
88
90
|
var Y = n(r((e, t) => {
|
|
89
91
|
const { groupKey: r, disabled: n, ...o } = e, a = N(["showScriptEditor"])[0], l = F("scriptsOptions");
|
|
90
|
-
return j(
|
|
92
|
+
return j(L, {
|
|
91
93
|
ref: t,
|
|
92
94
|
disabled: n,
|
|
93
95
|
createPopupPanel: i((e) => {
|
|
@@ -153,7 +155,7 @@ var Y = n(r((e, t) => {
|
|
|
153
155
|
const { disabled: t, snippet: r, description: n, handleInsert: i, sx: o, ...a } = e;
|
|
154
156
|
let l;
|
|
155
157
|
const s = r.metadata?.icon;
|
|
156
|
-
return l = j(
|
|
158
|
+
return l = j(v, "formula" === s ? {
|
|
157
159
|
iconKey: "ScriptFormula",
|
|
158
160
|
size: oe,
|
|
159
161
|
style: ie
|
|
@@ -207,28 +209,28 @@ var Y = n(r((e, t) => {
|
|
|
207
209
|
})
|
|
208
210
|
});
|
|
209
211
|
}), le = n(r((e, r) => {
|
|
210
|
-
const { groupKey: n, disabled: a, scriptPath: l = ee, ...s } = e,
|
|
212
|
+
const { groupKey: n, disabled: a, scriptPath: l = ee, ...s } = e, d = K(), [m, u] = c([]), [h, f] = c(!0), [g] = N(["insertScript"]), x = a || (g?.disabled() ?? !1);
|
|
211
213
|
o(() => {
|
|
212
214
|
(async () => {
|
|
213
215
|
try {
|
|
214
216
|
const e = await ne(l);
|
|
215
|
-
|
|
217
|
+
u(e);
|
|
216
218
|
} catch (e) {} finally {
|
|
217
|
-
|
|
219
|
+
f(!1);
|
|
218
220
|
}
|
|
219
221
|
})();
|
|
220
222
|
}, [l]);
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
+
const S = i((e) => {
|
|
224
|
+
if (h) return j("div", { children: d("insertScript.loading") });
|
|
223
225
|
const r = {
|
|
224
226
|
variant: y.Menuitem,
|
|
225
227
|
groupKey: "scriptsOptions",
|
|
226
|
-
disabled:
|
|
228
|
+
disabled: x
|
|
227
229
|
}, n = (t) => {
|
|
228
|
-
|
|
230
|
+
g?.execute(t.content), e.closeFloat?.();
|
|
229
231
|
}, i = [];
|
|
230
|
-
for (let e = 0; e <
|
|
231
|
-
const t =
|
|
232
|
+
for (let e = 0; e < m.length; e++) {
|
|
233
|
+
const t = m[e];
|
|
232
234
|
t && i.push(j(ae, {
|
|
233
235
|
handleInsert: n,
|
|
234
236
|
snippet: t
|
|
@@ -248,13 +250,13 @@ var Y = n(r((e, t) => {
|
|
|
248
250
|
flex: "1 1 100%"
|
|
249
251
|
},
|
|
250
252
|
children: i
|
|
251
|
-
}), j(
|
|
252
|
-
t(
|
|
253
|
+
}), j(E, { orientation: "horizontal" })] }) : null,
|
|
254
|
+
t(I, {
|
|
253
255
|
...r,
|
|
254
256
|
key: "showKeyboardShortcuts",
|
|
255
257
|
commandKey: "showKeyboardShortcuts"
|
|
256
258
|
}),
|
|
257
|
-
t(
|
|
259
|
+
t(I, {
|
|
258
260
|
...r,
|
|
259
261
|
key: "scriptingHelp",
|
|
260
262
|
commandKey: "scriptingHelp"
|
|
@@ -266,24 +268,25 @@ var Y = n(r((e, t) => {
|
|
|
266
268
|
children: o
|
|
267
269
|
});
|
|
268
270
|
}, [
|
|
269
|
-
|
|
271
|
+
x,
|
|
270
272
|
n,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
h,
|
|
274
|
+
g,
|
|
275
|
+
d
|
|
273
276
|
]);
|
|
274
|
-
return j(
|
|
277
|
+
return j(L, {
|
|
275
278
|
ref: r,
|
|
276
|
-
disabled:
|
|
279
|
+
disabled: x,
|
|
277
280
|
groupKey: n,
|
|
278
|
-
label:
|
|
279
|
-
tooltip:
|
|
280
|
-
createPopupPanel:
|
|
281
|
-
icon:
|
|
281
|
+
label: g?.getLabel(n) ?? d("insertScript.fallbackLabel"),
|
|
282
|
+
tooltip: g?.getDescription(),
|
|
283
|
+
createPopupPanel: S,
|
|
284
|
+
icon: g?.getIcon() ?? "ScriptInsert",
|
|
282
285
|
...s
|
|
283
286
|
});
|
|
284
287
|
})), se = n(r((e, t) => {
|
|
285
288
|
const { propsCommandButton: r, ...n } = e;
|
|
286
|
-
return j(
|
|
289
|
+
return j(P, {
|
|
287
290
|
ref: t,
|
|
288
291
|
propsCommandButton: r,
|
|
289
292
|
renderToolbarPalette: C((e) => {
|
|
@@ -296,7 +299,7 @@ var Y = n(r((e, t) => {
|
|
|
296
299
|
children: [
|
|
297
300
|
j("div", { children: j(R, {
|
|
298
301
|
style: {},
|
|
299
|
-
children: j(
|
|
302
|
+
children: j(I, {
|
|
300
303
|
...t,
|
|
301
304
|
commandKey: "saveScripts"
|
|
302
305
|
})
|
|
@@ -314,33 +317,33 @@ var Y = n(r((e, t) => {
|
|
|
314
317
|
}));
|
|
315
318
|
se.displayName = "ScriptEditorToolbar", V();
|
|
316
319
|
var ce = n(r((e, t) => {
|
|
317
|
-
const { scriptPath: r = ee, onScriptSelect: n,
|
|
320
|
+
const { scriptPath: r = ee, onScriptSelect: n, disabled: i = !1, sx: a = k.EmptyCssProperties, className: l, buttonMinWidth: s = 210, buttonMinHeight: h = 80, gap: g = 12, ...x } = e, y = K(), [S, b] = c([]), [w, C] = c(!0), [F, N] = c(null);
|
|
318
321
|
if (o(() => {
|
|
319
322
|
(async () => {
|
|
320
323
|
const e = [{
|
|
321
324
|
path: null,
|
|
322
325
|
metadata: {
|
|
323
|
-
title:
|
|
324
|
-
summary:
|
|
326
|
+
title: y("templateSelect.blankTitle"),
|
|
327
|
+
summary: y("templateSelect.blankSummary")
|
|
325
328
|
},
|
|
326
329
|
content: ""
|
|
327
330
|
}];
|
|
328
331
|
try {
|
|
329
|
-
|
|
332
|
+
C(!0), N(null);
|
|
330
333
|
const t = await ne(r);
|
|
331
334
|
for (let r = 0; r < t.length; r++) {
|
|
332
335
|
const n = t[r];
|
|
333
336
|
n && e.push(n);
|
|
334
337
|
}
|
|
335
338
|
} catch (e) {
|
|
336
|
-
|
|
339
|
+
N(e instanceof Error ? e.message : y("templateSelect.loadFailed")), e instanceof q || console.error("Error loading scripts:", e);
|
|
337
340
|
} finally {
|
|
338
|
-
|
|
341
|
+
b(e), C(!1);
|
|
339
342
|
}
|
|
340
343
|
})();
|
|
341
|
-
}, [r,
|
|
342
|
-
className: d(
|
|
343
|
-
...
|
|
344
|
+
}, [r, y]), w) return j(p, {
|
|
345
|
+
className: d(l, "script-select"),
|
|
346
|
+
...x,
|
|
344
347
|
sx: [{
|
|
345
348
|
display: "flex",
|
|
346
349
|
justifyContent: "center",
|
|
@@ -348,15 +351,14 @@ var ce = n(r((e, t) => {
|
|
|
348
351
|
height: "100%",
|
|
349
352
|
background: (e) => e.palette.background.paper,
|
|
350
353
|
zIndex: 1e3,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}, ...Array.isArray(i) ? i : []],
|
|
354
|
+
...Array.isArray(a) ? {} : a
|
|
355
|
+
}, ...Array.isArray(a) ? a : []],
|
|
354
356
|
children: j(u, {})
|
|
355
357
|
});
|
|
356
|
-
let
|
|
357
|
-
|
|
358
|
-
className: d(
|
|
359
|
-
...
|
|
358
|
+
let T = null;
|
|
359
|
+
F && (T = H(p, {
|
|
360
|
+
className: d(l, "script-select", "error-results"),
|
|
361
|
+
...x,
|
|
360
362
|
sx: [{
|
|
361
363
|
display: "flex",
|
|
362
364
|
justifyContent: "center",
|
|
@@ -368,44 +370,42 @@ var ce = n(r((e, t) => {
|
|
|
368
370
|
padding: (e) => e.spacing(1),
|
|
369
371
|
border: (e) => `1px solid ${e.palette.error.main}`,
|
|
370
372
|
borderBottomLeftRadius: 1,
|
|
371
|
-
borderBottomRightRadius: 1
|
|
372
|
-
|
|
373
|
-
}, ...Array.isArray(i) ? i : [i]],
|
|
373
|
+
borderBottomRightRadius: 1
|
|
374
|
+
}, ...Array.isArray(a) ? a : [a]],
|
|
374
375
|
children: [j(f, {
|
|
375
376
|
color: "error",
|
|
376
377
|
variant: "h6",
|
|
377
378
|
component: "div",
|
|
378
379
|
gutterBottom: !0,
|
|
379
|
-
children:
|
|
380
|
+
children: y("templateSelect.errorTitle")
|
|
380
381
|
}), j(f, {
|
|
381
382
|
color: "error",
|
|
382
383
|
component: "div",
|
|
383
|
-
children:
|
|
384
|
+
children: F
|
|
384
385
|
})]
|
|
385
386
|
}));
|
|
386
|
-
const
|
|
387
|
+
const D = (e) => {
|
|
387
388
|
const t = e.metadata?.icon;
|
|
388
|
-
return "macro" === t ? j(
|
|
389
|
+
return "macro" === t ? j(v, {
|
|
389
390
|
iconKey: "ScriptMacro",
|
|
390
391
|
size: "1em"
|
|
391
|
-
}) : "formula" === t ? j(
|
|
392
|
+
}) : "formula" === t ? j(v, {
|
|
392
393
|
iconKey: "ScriptFormula",
|
|
393
394
|
size: "1em"
|
|
394
|
-
}) : "autostart" === t ? j(
|
|
395
|
+
}) : "autostart" === t ? j(v, {
|
|
395
396
|
iconKey: "ScriptAutoRun",
|
|
396
397
|
size: "1em"
|
|
397
398
|
}) : null;
|
|
398
399
|
};
|
|
399
400
|
return H(p, {
|
|
400
401
|
ref: t,
|
|
401
|
-
className: d(
|
|
402
|
+
className: d(l, "script-select"),
|
|
402
403
|
sx: {
|
|
403
404
|
background: (e) => e.palette.background.paper,
|
|
404
405
|
zIndex: 1e3,
|
|
405
|
-
|
|
406
|
-
...i
|
|
406
|
+
...a
|
|
407
407
|
},
|
|
408
|
-
...
|
|
408
|
+
...x,
|
|
409
409
|
children: [H(p, {
|
|
410
410
|
className: "script-select-content",
|
|
411
411
|
sx: {
|
|
@@ -417,36 +417,37 @@ var ce = n(r((e, t) => {
|
|
|
417
417
|
j(f, {
|
|
418
418
|
variant: "h6",
|
|
419
419
|
gutterBottom: !0,
|
|
420
|
-
children:
|
|
420
|
+
children: y("templateSelect.title")
|
|
421
421
|
}),
|
|
422
422
|
j(f, {
|
|
423
423
|
variant: "body2",
|
|
424
424
|
component: "div",
|
|
425
425
|
gutterBottom: !0,
|
|
426
426
|
sx: { color: "text.secondary" },
|
|
427
|
-
children:
|
|
427
|
+
children: y("templateSelect.intro")
|
|
428
428
|
}),
|
|
429
429
|
j(f, {
|
|
430
430
|
variant: "body2",
|
|
431
431
|
component: "div",
|
|
432
432
|
gutterBottom: !0,
|
|
433
433
|
sx: { color: "text.secondary" },
|
|
434
|
-
children:
|
|
434
|
+
children: y("templateSelect.intro2")
|
|
435
435
|
}),
|
|
436
436
|
j(p, {
|
|
437
437
|
sx: {
|
|
438
438
|
display: "grid",
|
|
439
|
-
gridTemplateColumns: `repeat(auto-fill, minmax(${
|
|
440
|
-
gap: `${
|
|
439
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${s}px, 1fr))`,
|
|
440
|
+
gap: `${g}px`,
|
|
441
441
|
padding: 2,
|
|
442
442
|
paddingLeft: "0px",
|
|
443
443
|
paddingRight: "0px"
|
|
444
444
|
},
|
|
445
|
-
children:
|
|
445
|
+
children: S.map((e, t) => H(m, {
|
|
446
446
|
variant: "outlined",
|
|
447
|
+
disabled: i,
|
|
447
448
|
sx: {
|
|
448
|
-
minWidth:
|
|
449
|
-
minHeight:
|
|
449
|
+
minWidth: s,
|
|
450
|
+
minHeight: h,
|
|
450
451
|
display: "flex",
|
|
451
452
|
flexDirection: "column",
|
|
452
453
|
justifyContent: "flex-start",
|
|
@@ -474,8 +475,8 @@ var ce = n(r((e, t) => {
|
|
|
474
475
|
children: [j(f, {
|
|
475
476
|
variant: "subtitle2",
|
|
476
477
|
component: "div",
|
|
477
|
-
children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") ||
|
|
478
|
-
}),
|
|
478
|
+
children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") || y("templateSelect.untitled")
|
|
479
|
+
}), D(e)]
|
|
479
480
|
}), e.metadata?.summary && j(f, {
|
|
480
481
|
variant: "body2",
|
|
481
482
|
component: "div",
|
|
@@ -492,44 +493,44 @@ var ce = n(r((e, t) => {
|
|
|
492
493
|
}, `${e.path}-${t}`))
|
|
493
494
|
})
|
|
494
495
|
]
|
|
495
|
-
}),
|
|
496
|
+
}), T]
|
|
496
497
|
});
|
|
497
498
|
}));
|
|
498
499
|
ce.displayName = "TemplateSelectPanel";
|
|
499
500
|
var de = n(r((e, t) => {
|
|
500
|
-
const { className: r, sx: n, propsScriptEditor: l, readOnly: m = !1, frame: u, autoFocusSel: x, autoFocus: y = !0, scripts: S, ...
|
|
501
|
+
const { className: r, sx: n, propsScriptEditor: l, readOnly: m = !1, frame: u, autoFocusSel: x, autoFocus: y = !0, scripts: S, ...b } = e, v = g(), [w, k] = c(!1), F = s(!1), [N, K] = c({
|
|
501
502
|
message: "Loading",
|
|
502
503
|
cursor: "",
|
|
503
504
|
dirty: !1
|
|
504
|
-
}), [
|
|
505
|
+
}), [I, L] = c(null);
|
|
505
506
|
o(() => {
|
|
506
507
|
let e = !1;
|
|
507
|
-
return
|
|
508
|
+
return L(null), async function() {
|
|
508
509
|
if (S && (await S.start(), !e)) {
|
|
509
510
|
const e = S.getModules().getItems()[0]?.getSource();
|
|
510
|
-
|
|
511
|
+
L({ source: e || null });
|
|
511
512
|
}
|
|
512
513
|
}(), () => {
|
|
513
514
|
e = !0;
|
|
514
515
|
};
|
|
515
516
|
}, [S]);
|
|
516
|
-
const
|
|
517
|
+
const P = i((e) => {
|
|
517
518
|
K((t) => ({
|
|
518
519
|
...t,
|
|
519
520
|
...e
|
|
520
521
|
}));
|
|
521
|
-
}, []),
|
|
522
|
+
}, []), E = s(null), [$, R] = c(null), z = s(null), B = C((e) => {
|
|
522
523
|
if ($) return $.focus(e), !0;
|
|
523
524
|
if (x) {
|
|
524
|
-
const t =
|
|
525
|
+
const t = E.current?.querySelectorAll?.(x);
|
|
525
526
|
if (t && t.length > 0) return t[0]?.focus?.(e), !0;
|
|
526
527
|
}
|
|
527
|
-
return
|
|
528
|
+
return E.current?.focus?.(e), !1;
|
|
528
529
|
}, [
|
|
529
530
|
$,
|
|
530
531
|
x,
|
|
531
532
|
y
|
|
532
|
-
]),
|
|
533
|
+
]), O = a(() => j(D, {
|
|
533
534
|
transitionDelay: "160ms",
|
|
534
535
|
style: {
|
|
535
536
|
position: "absolute",
|
|
@@ -537,7 +538,7 @@ var de = n(r((e, t) => {
|
|
|
537
538
|
height: "100%"
|
|
538
539
|
},
|
|
539
540
|
transparentBackground: !1
|
|
540
|
-
}), []),
|
|
541
|
+
}), []), A = a(() => j(h, {
|
|
541
542
|
elevation: 1,
|
|
542
543
|
tabIndex: 0,
|
|
543
544
|
sx: {
|
|
@@ -551,7 +552,7 @@ var de = n(r((e, t) => {
|
|
|
551
552
|
marginBottom: (e) => e.spacing(1)
|
|
552
553
|
},
|
|
553
554
|
children: j(se, {})
|
|
554
|
-
}), [
|
|
555
|
+
}), [v]), M = a(() => j(p, {
|
|
555
556
|
className: d("script-status-panel", "status-panel"),
|
|
556
557
|
sx: {
|
|
557
558
|
display: "flex",
|
|
@@ -564,7 +565,7 @@ var de = n(r((e, t) => {
|
|
|
564
565
|
paddingTop: "1px",
|
|
565
566
|
minHeight: "calc(1em + 8px)",
|
|
566
567
|
margin: 0,
|
|
567
|
-
borderTop: `solid 1px ${
|
|
568
|
+
borderTop: `solid 1px ${v.palette.divider}`
|
|
568
569
|
},
|
|
569
570
|
children: H("div", {
|
|
570
571
|
style: {
|
|
@@ -630,7 +631,7 @@ var de = n(r((e, t) => {
|
|
|
630
631
|
boxSizing: "border-box"
|
|
631
632
|
},
|
|
632
633
|
children: [
|
|
633
|
-
|
|
634
|
+
A,
|
|
634
635
|
j(p, {
|
|
635
636
|
sx: {
|
|
636
637
|
display: "flex",
|
|
@@ -641,34 +642,34 @@ var de = n(r((e, t) => {
|
|
|
641
642
|
boxSizing: "border-box"
|
|
642
643
|
},
|
|
643
644
|
children: j(G, {
|
|
644
|
-
ref:
|
|
645
|
-
loadingPanel:
|
|
645
|
+
ref: E,
|
|
646
|
+
loadingPanel: O,
|
|
646
647
|
readOnly: m,
|
|
647
648
|
frame: u,
|
|
648
649
|
scripts: S,
|
|
649
650
|
autoFocus: y,
|
|
650
|
-
onStatusChange:
|
|
651
|
-
darkMode: "dark" ===
|
|
651
|
+
onStatusChange: P,
|
|
652
|
+
darkMode: "dark" === v.palette.mode,
|
|
652
653
|
...l
|
|
653
654
|
})
|
|
654
655
|
}),
|
|
655
656
|
M
|
|
656
657
|
]
|
|
657
658
|
}), [
|
|
658
|
-
|
|
659
|
-
|
|
659
|
+
v,
|
|
660
|
+
A,
|
|
660
661
|
M,
|
|
661
662
|
w,
|
|
662
|
-
|
|
663
|
+
O,
|
|
663
664
|
m,
|
|
664
665
|
l,
|
|
665
666
|
y,
|
|
666
667
|
x,
|
|
667
668
|
u,
|
|
668
|
-
|
|
669
|
+
P
|
|
669
670
|
]), U = a(() => {
|
|
670
671
|
let e;
|
|
671
|
-
return null ===
|
|
672
|
+
return null === I ? O : (null === I.source && (e = j(ce, {
|
|
672
673
|
sx: {
|
|
673
674
|
display: "flex",
|
|
674
675
|
flex: "1 1 100%",
|
|
@@ -679,8 +680,9 @@ var de = n(r((e, t) => {
|
|
|
679
680
|
width: "100%",
|
|
680
681
|
height: "100%"
|
|
681
682
|
},
|
|
683
|
+
disabled: m,
|
|
682
684
|
onScriptSelect: (e) => {
|
|
683
|
-
|
|
685
|
+
E.current?.insertSnippet(e.content), L({ source: e.content ?? "" }), requestAnimationFrame(() => E.current?.focus());
|
|
684
686
|
}
|
|
685
687
|
})), j(p, {
|
|
686
688
|
tabIndex: 0,
|
|
@@ -696,7 +698,7 @@ var de = n(r((e, t) => {
|
|
|
696
698
|
outline: "none"
|
|
697
699
|
},
|
|
698
700
|
onPointerDown: (e) => {
|
|
699
|
-
e.isDefaultPrevented() ||
|
|
701
|
+
e.isDefaultPrevented() || E.current?.focus();
|
|
700
702
|
},
|
|
701
703
|
children: H(p, {
|
|
702
704
|
sx: {
|
|
@@ -717,11 +719,12 @@ var de = n(r((e, t) => {
|
|
|
717
719
|
})
|
|
718
720
|
}));
|
|
719
721
|
}, [
|
|
720
|
-
|
|
722
|
+
A,
|
|
721
723
|
W,
|
|
722
724
|
r,
|
|
723
|
-
|
|
724
|
-
|
|
725
|
+
I,
|
|
726
|
+
O,
|
|
727
|
+
m
|
|
725
728
|
]), q = T(t, () => ({
|
|
726
729
|
isScriptWorkspaceElement: () => !0,
|
|
727
730
|
focus: (e) => {
|
|
@@ -737,12 +740,12 @@ var de = n(r((e, t) => {
|
|
|
737
740
|
...n
|
|
738
741
|
},
|
|
739
742
|
ref: q,
|
|
740
|
-
...
|
|
743
|
+
...b,
|
|
741
744
|
onFocus: (e) => {
|
|
742
|
-
k(!0), F.current = !0, q.current?.contains(e.target) && e.target !== q.current && R(e.target), e.relatedTarget && !z.current && (z.current = e.relatedTarget),
|
|
745
|
+
k(!0), F.current = !0, q.current?.contains(e.target) && e.target !== q.current && R(e.target), e.relatedTarget && !z.current && (z.current = e.relatedTarget), b?.onFocus?.(e);
|
|
743
746
|
},
|
|
744
747
|
onBlur: (e) => {
|
|
745
|
-
q?.current?.contains(e.relatedTarget) || q?.current === e.relatedTarget || (z.current = null, F.current = !1, k(!1)),
|
|
748
|
+
q?.current?.contains(e.relatedTarget) || q?.current === e.relatedTarget || (z.current = null, F.current = !1, k(!1)), b?.onBlur?.(e);
|
|
746
749
|
},
|
|
747
750
|
children: U
|
|
748
751
|
});
|
|
@@ -774,12 +777,12 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: ue,
|
|
|
774
777
|
})]
|
|
775
778
|
}) : t;
|
|
776
779
|
}, ye = (e) => {
|
|
777
|
-
const { model: t, entryKey: r, frame: n, ref: i, ...o } = e;
|
|
778
|
-
return j(ge, { children: j(de, {
|
|
780
|
+
const { model: t, entryKey: r, frame: n, ref: i, ...o } = e, a = M() ?? t;
|
|
781
|
+
return A(a, ["onProtectionChange"]), j(ge, { children: j(de, {
|
|
779
782
|
ref: i,
|
|
780
|
-
readOnly: !1,
|
|
783
|
+
readOnly: a?.getScripts().isReadOnly() ?? !1,
|
|
781
784
|
frame: n,
|
|
782
|
-
scripts:
|
|
785
|
+
scripts: a?.getScripts(),
|
|
783
786
|
...o
|
|
784
787
|
}) });
|
|
785
788
|
}, Se = n((e) => {
|
|
@@ -804,10 +807,10 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: ue,
|
|
|
804
807
|
s,
|
|
805
808
|
a,
|
|
806
809
|
n
|
|
807
|
-
]), d ? H(W, { children: [j(
|
|
810
|
+
]), d ? H(W, { children: [j(E, {}), j(Y, { ...r })] }) : null;
|
|
808
811
|
});
|
|
809
812
|
Se.displayName = "RunScriptContribution", V();
|
|
810
|
-
var
|
|
813
|
+
var be = n(r((e, r) => {
|
|
811
814
|
const { ...n } = e, i = M(), a = K(), [l, s] = c([]);
|
|
812
815
|
o(() => {
|
|
813
816
|
const e = i?.getScripts();
|
|
@@ -831,12 +834,12 @@ var ve = n(r((e, r) => {
|
|
|
831
834
|
}, m = [], u = l ? l.length : 0;
|
|
832
835
|
for (let e = 0; e < u; e++) {
|
|
833
836
|
const t = l[e];
|
|
834
|
-
m.push(j(
|
|
837
|
+
m.push(j(I, {
|
|
835
838
|
...d,
|
|
836
839
|
commandKey: "insertFunction",
|
|
837
840
|
commandState: t,
|
|
838
841
|
propsTooltip: { description: a("insertFunction.insertNamed", { name: t.getName() ?? a("insertFunction.fallbackLabel") }) },
|
|
839
|
-
icon: j(
|
|
842
|
+
icon: j(v, { iconKey: "FormulaCustom" }),
|
|
840
843
|
label: t.getName() ?? a("insertFunction.fallbackLabel")
|
|
841
844
|
}, `function-${t.getName()}-${e}`));
|
|
842
845
|
}
|
|
@@ -854,7 +857,7 @@ var ve = n(r((e, r) => {
|
|
|
854
857
|
flex: "1 1 100%"
|
|
855
858
|
},
|
|
856
859
|
children: m
|
|
857
|
-
}), j(
|
|
860
|
+
}), j(E, { orientation: "horizontal" })] }) : null, t(I, {
|
|
858
861
|
...d,
|
|
859
862
|
key: "show-editor",
|
|
860
863
|
commandKey: "showScriptEditor"
|
|
@@ -865,14 +868,14 @@ var ve = n(r((e, r) => {
|
|
|
865
868
|
children: h
|
|
866
869
|
});
|
|
867
870
|
}));
|
|
868
|
-
|
|
869
|
-
var
|
|
871
|
+
be.displayName = "InsertFunctionPopupPanel";
|
|
872
|
+
var ve = n(r((e, t) => {
|
|
870
873
|
const { disabled: r, groupKey: n, ...o } = e, a = F("customFunctionOptions");
|
|
871
|
-
return j(
|
|
874
|
+
return j(L, {
|
|
872
875
|
ref: t,
|
|
873
876
|
disabled: r,
|
|
874
877
|
createPopupPanel: i((e) => {
|
|
875
|
-
const t = j(
|
|
878
|
+
const t = j(be, {
|
|
876
879
|
disabled: r,
|
|
877
880
|
groupKey: n,
|
|
878
881
|
...e
|
|
@@ -888,9 +891,9 @@ var be = n(r((e, t) => {
|
|
|
888
891
|
...o
|
|
889
892
|
});
|
|
890
893
|
}));
|
|
891
|
-
|
|
894
|
+
ve.displayName = "InsertFunctionContribution";
|
|
892
895
|
var we = () => {
|
|
893
|
-
J(),
|
|
896
|
+
J(), b.register("plugin-scripts", { icons: {} }), B.registerTaskPane({
|
|
894
897
|
key: "scriptEditor",
|
|
895
898
|
getTitle: () => "Script (Typescript)",
|
|
896
899
|
getIcon: () => "ScriptRun",
|
|
@@ -914,7 +917,7 @@ var we = () => {
|
|
|
914
917
|
anchor: "formulaCategory.web",
|
|
915
918
|
order: 1
|
|
916
919
|
} },
|
|
917
|
-
render: (t) => e.createElement(
|
|
920
|
+
render: (t) => e.createElement(ve, { ...t })
|
|
918
921
|
}, !0);
|
|
919
922
|
};
|
|
920
923
|
export { le as InsertScriptCommandButton, Y as RunScriptCommandButton, se as ScriptEditorToolbar, ye as ScriptTaskPane, de as ScriptWorkspace, we as ScriptingPlugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheetxl/scripting-mui",
|
|
3
3
|
"description": "Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0-beta.2",
|
|
5
5
|
"license": "SEE LICENSE IN <LICENSE>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"automation"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@sheetxl/react": "^0.
|
|
42
|
-
"@sheetxl/scripting-react": "^0.
|
|
43
|
-
"@sheetxl/sdk": "^0.
|
|
44
|
-
"@sheetxl/studio-mui": "^0.
|
|
45
|
-
"@sheetxl/utils": "^0.
|
|
46
|
-
"@sheetxl/utils-mui": "^0.
|
|
47
|
-
"@sheetxl/utils-react": "^0.
|
|
41
|
+
"@sheetxl/react": "^0.8.0-beta.2",
|
|
42
|
+
"@sheetxl/scripting-react": "^0.8.0-beta.2",
|
|
43
|
+
"@sheetxl/sdk": "^0.8.0-beta.2",
|
|
44
|
+
"@sheetxl/studio-mui": "^0.8.0-beta.2",
|
|
45
|
+
"@sheetxl/utils": "^0.8.0-beta.2",
|
|
46
|
+
"@sheetxl/utils-mui": "^0.8.0-beta.2",
|
|
47
|
+
"@sheetxl/utils-react": "^0.8.0-beta.2",
|
|
48
48
|
"clsx": "^2.1.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"insertFunction.fallbackLabel": "Funktion",
|
|
3
3
|
"insertFunction.insertNamed": "{name} einfügen",
|
|
4
|
+
"insertScript.fallbackLabel": "Skript einfügen",
|
|
5
|
+
"insertScript.loading": "Wird geladen...",
|
|
4
6
|
"runScript.executeNamed": "{name} ausführen",
|
|
5
7
|
"runScript.fallbackLabel": "Makro",
|
|
6
8
|
"templateSelect.blankSummary": "Mit einem leeren Skript beginnen.",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"insertFunction.fallbackLabel": "Function",
|
|
3
3
|
"insertFunction.insertNamed": "Insert {name}",
|
|
4
|
+
"insertScript.fallbackLabel": "Insert Script",
|
|
5
|
+
"insertScript.loading": "Loading...",
|
|
4
6
|
"runScript.executeNamed": "Execute {name}",
|
|
5
7
|
"runScript.fallbackLabel": "Macro",
|
|
6
8
|
"templateSelect.blankSummary": "Start with an empty script.",
|
|
@@ -14,6 +14,11 @@ export interface TemplateSelectPanelProps extends React.HTMLAttributes<HTMLDivEl
|
|
|
14
14
|
* Called when a script button is clicked
|
|
15
15
|
*/
|
|
16
16
|
onScriptSelect?: (file: DirectoryFile) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Disables every template, for scripts that cannot be changed.
|
|
19
|
+
* @defaultValue false
|
|
20
|
+
*/
|
|
21
|
+
disabled?: boolean;
|
|
17
22
|
/**
|
|
18
23
|
* Additional class name
|
|
19
24
|
*/
|