@sheetxl/scripting-mui 0.8.0-beta.6 → 0.8.0-beta.7
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 +1 -1
- package/browser/esm/index.mjs +64 -63
- package/node/esm/index.mjs +114 -113
- package/package.json +8 -8
- package/types/src/utils/Utils.d.ts +1 -1
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}`,"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)};
|
|
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/sdk"),_=require("@sheetxl/utils"),v=require("@sheetxl/scripting-react");function y(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=y(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function b(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=y(e))&&(r&&(r+=` `),r+=t);return r}var x={"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:S}=d.Command,C=!1;function w(){C||(C=!0,S.registerFromManifest(`@sheetxl/scripting-mui`,{}.url,{messages:x}))}w();var T=(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})}));T.displayName=`RunScriptPopupPanel`;var E=(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)(T,{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})})),D=/^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/.exec(g.VERSION)?.[1],O=`https://unpkg.com/@sheetxl/templates-scripting${D?`@${D}`:``}/dist`,k=(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},A=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(` `))},j=async e=>{let t=k(e,`./manifest.json`),n=await fetch(t);if(!n.ok)throw new _.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 _.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=k(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:A(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)},M={marginRight:`4px`},N=`1em`,P=(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:N,style:M}):c===`macro`?(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptMacro`,size:N,style:M}):(0,m.jsx)(d.DynamicIcon,{iconKey:`ScriptAutoRun`,size:N,style:M}),(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})]})})}),F=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{groupKey:n,disabled:r,scriptPath:i=O,...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 j(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)(P,{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})})),I=(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)(F,{...t})})})]})})},[]),...r})}));I.displayName=`ScriptEditorToolbar`,w();var L=(0,o.memo)((0,o.forwardRef)((e,t)=>{let{scriptPath:n=O,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)(),[g,v]=(0,o.useState)([]),[y,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 j(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 _.ChainedError||console.error(`Error loading scripts:`,e)}finally{v(e),x(!1)}})()},[n,h]),y)return(0,m.jsx)(u.Box,{className:b(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:b(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:b(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:g.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]})}));L.displayName=`TemplateSelectPanel`;var R=(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)(),[_,y]=(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)(I,{})}),[g]),P=(0,o.useMemo)(()=>(0,m.jsx)(u.Box,{className:b(`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]),F=(0,o.useMemo)(()=>(0,m.jsxs)(u.Box,{className:b(`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)(v.ScriptEditor,{ref:D,loadingPanel:M,readOnly:a,frame:s,scripts:p,autoFocus:l,onStatusChange:E,darkMode:g.palette.mode===`dark`,...i})}),P]}),[g,N,P,_,M,a,i,l,c,s,E]),R=(0,o.useMemo)(()=>{let e;return w===null?M:(w.source===null&&(e=(0,m.jsx)(L,{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:b(`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:F}),e]})}))},[N,F,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=>{y(!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,y(!1)),h?.onBlur?.(e)},children:R})}));R.displayName=`ScriptWorkspace`;var{FocusActivation:z,CommandScopeProvider:B,CommandAnchorProvider:V,useCommandScope:H}=d.Command,U={scopeName:`scriptEditor`},W=({children:e})=>{let t=H(),n=(0,o.useRef)(null);return t?(0,m.jsx)(B,{spec:U,elementRef:n,region:!0,children:(0,m.jsx)(G,{paneRef:n,children:e})}):e},G=({paneRef:e,children:t})=>{let n=H(),r=(0,o.useMemo)(()=>n?new z(n.getRoot(),n):null,[n]);return r?(0,m.jsxs)(V,{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},K=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)(W,{children:(0,m.jsx)(R,{ref:i,readOnly:o?.getScripts().isReadOnly()??!1,frame:r,scripts:o?.getScripts(),...a})})},q=(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)(E,{...n})]}):null});q.displayName=`RunScriptContribution`,w();var J=(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})}));J.displayName=`InsertFunctionPopupPanel`;var Y=(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)(J,{disabled:n,groupKey:r,...e});return(0,f.defaultCreatePopupPanel)({...e,children:t})},[n,r]),label:a?.getLabel?.(),tooltip:a?.getDescription?.(),icon:`FormulaCustom`,...i})}));Y.displayName=`InsertFunctionContribution`,exports.InsertScriptCommandButton=F,exports.RunScriptCommandButton=E,exports.ScriptEditorToolbar=I,exports.ScriptTaskPane=K,exports.ScriptWorkspace=R,exports.ScriptingPlugin=()=>{(0,v.ScriptingReactPlugin)(),d.DefaultIconService.register(`plugin-scripts`,{icons:{}}),p.DefaultTaskPaneRegistry.registerTaskPane({key:`scriptEditor`,getTitle:()=>`Script (Typescript)`,getIcon:()=>`ScriptRun`,component:K,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(q,{...e})},!0),d.DefaultCommandButtonRegistry.register({key:`scripting.runScript.view`,contributions:{viewToolbar:{order:10}},render:e=>o.default.createElement(q,{...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(Y,{...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.8.0-beta.
|
|
2
|
+
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.7
|
|
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.
|
|
@@ -10,23 +10,24 @@ import { Command as g, CommandButtonType as _, DefaultCommandButtonRegistry as v
|
|
|
10
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
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
|
-
import { alpha as
|
|
13
|
+
import { alpha as te } from "@mui/system";
|
|
14
|
+
import { VERSION as H } from "@sheetxl/sdk";
|
|
14
15
|
import { ChainedError as U } from "@sheetxl/utils";
|
|
15
|
-
import { ScriptEditor as
|
|
16
|
-
function
|
|
16
|
+
import { ScriptEditor as ne, ScriptingReactPlugin as re } from "@sheetxl/scripting-react";
|
|
17
|
+
function ie(e) {
|
|
17
18
|
var t, n, r = "";
|
|
18
19
|
if (typeof e == "string" || typeof e == "number") r += e;
|
|
19
20
|
else if (typeof e == "object") if (Array.isArray(e)) {
|
|
20
21
|
var i = e.length;
|
|
21
|
-
for (t = 0; t < i; t++) e[t] && (n =
|
|
22
|
+
for (t = 0; t < i; t++) e[t] && (n = ie(e[t])) && (r && (r += " "), r += n);
|
|
22
23
|
} else for (n in e) e[n] && (r && (r += " "), r += n);
|
|
23
24
|
return r;
|
|
24
25
|
}
|
|
25
26
|
function W() {
|
|
26
|
-
for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t =
|
|
27
|
+
for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = ie(e)) && (r && (r += " "), r += t);
|
|
27
28
|
return r;
|
|
28
29
|
}
|
|
29
|
-
var
|
|
30
|
+
var ae = {
|
|
30
31
|
"insertFunction.fallbackLabel": "Function",
|
|
31
32
|
"insertFunction.insertNamed": "Insert {name}",
|
|
32
33
|
"insertScript.fallbackLabel": "Insert Script",
|
|
@@ -41,12 +42,12 @@ var ie = {
|
|
|
41
42
|
"templateSelect.loadFailed": "Failed to load scripts",
|
|
42
43
|
"templateSelect.title": "Script Template",
|
|
43
44
|
"templateSelect.untitled": "Untitled"
|
|
44
|
-
}, { DefaultCommandCatalogService:
|
|
45
|
-
function
|
|
46
|
-
|
|
45
|
+
}, { DefaultCommandCatalogService: oe } = g, se = !1;
|
|
46
|
+
function G() {
|
|
47
|
+
se || (se = !0, oe.registerFromManifest("@sheetxl/scripting-mui", import.meta.url, { messages: ae }));
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
var
|
|
49
|
+
G();
|
|
50
|
+
var ce = r(n((e, n) => {
|
|
50
51
|
let { groupKey: r, ...i } = e, o = R(), s = D(), [c, d] = l([]), [f, p] = l(!1);
|
|
51
52
|
a(() => {
|
|
52
53
|
let e = o?.getScripts();
|
|
@@ -97,14 +98,14 @@ var q = r(n((e, n) => {
|
|
|
97
98
|
children: v
|
|
98
99
|
});
|
|
99
100
|
}));
|
|
100
|
-
|
|
101
|
-
var
|
|
101
|
+
ce.displayName = "RunScriptPopupPanel";
|
|
102
|
+
var K = r(n((e, t) => {
|
|
102
103
|
let { groupKey: n, disabled: r, ...a } = e, o = T(["showScriptEditor"])[0], s = w("scriptsOptions");
|
|
103
104
|
return B(k, {
|
|
104
105
|
ref: t,
|
|
105
106
|
disabled: r,
|
|
106
107
|
createPopupPanel: i((e) => {
|
|
107
|
-
let t = B(
|
|
108
|
+
let t = B(ce, {
|
|
108
109
|
disabled: r,
|
|
109
110
|
groupKey: n,
|
|
110
111
|
...e
|
|
@@ -120,19 +121,19 @@ var J = r(n((e, t) => {
|
|
|
120
121
|
quickCommand: "showScriptEditor",
|
|
121
122
|
...a
|
|
122
123
|
});
|
|
123
|
-
})),
|
|
124
|
+
})), le = /^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/.exec(H)?.[1], q = `https://unpkg.com/@sheetxl/templates-scripting${le ? `@${le}` : ""}/dist`, J = (e, t) => {
|
|
124
125
|
try {
|
|
125
126
|
return new URL(t).href;
|
|
126
127
|
} catch {}
|
|
127
128
|
if (t.startsWith("/") || /^[a-zA-Z]:/.test(t)) return t;
|
|
128
129
|
let n = e.startsWith("http") ? e : `file:///${e.replace(/\\/g, "/")}`;
|
|
129
130
|
return n.endsWith("/") || (n += "/"), new URL(t, n).href;
|
|
130
|
-
},
|
|
131
|
+
}, ue = (e) => {
|
|
131
132
|
if (e.metadata?.name) return e.metadata.name;
|
|
132
133
|
let t = (e.path.split("/").pop() || "").replace(/\.[^/.]+$/, "");
|
|
133
134
|
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(" "));
|
|
134
|
-
},
|
|
135
|
-
let t =
|
|
135
|
+
}, de = async (e) => {
|
|
136
|
+
let t = J(e, "./manifest.json"), n = await fetch(t);
|
|
136
137
|
if (!n.ok) throw new U(`Failed to retrieve directory at '${e}': ${n.statusText}`);
|
|
137
138
|
let r = await n.text();
|
|
138
139
|
if (r.trim().toLowerCase().startsWith("<!doctype html") || r.trim().toLowerCase().startsWith("<html")) throw new U(`Failed to retrieve directory at '${e}'`);
|
|
@@ -144,11 +145,11 @@ var J = r(n((e, t) => {
|
|
|
144
145
|
}
|
|
145
146
|
let a = i.map(async (t) => {
|
|
146
147
|
try {
|
|
147
|
-
let n =
|
|
148
|
+
let n = J(e, t.path), r = await fetch(n);
|
|
148
149
|
if (!r.ok) throw Error(`Failed to fetch file at '${t.path}': ${r.statusText}`);
|
|
149
150
|
let i = await r.text(), a = t.metadata;
|
|
150
151
|
return a?.title || (a = {
|
|
151
|
-
title:
|
|
152
|
+
title: ue(t),
|
|
152
153
|
...a
|
|
153
154
|
}), {
|
|
154
155
|
path: t.path,
|
|
@@ -161,7 +162,7 @@ var J = r(n((e, t) => {
|
|
|
161
162
|
return null;
|
|
162
163
|
});
|
|
163
164
|
return (await Promise.all(a)).filter((e) => e !== null);
|
|
164
|
-
}, Y = { marginRight: "4px" }, X = "1em",
|
|
165
|
+
}, Y = { marginRight: "4px" }, X = "1em", fe = r((e) => {
|
|
165
166
|
let { disabled: t, snippet: n, description: r, handleInsert: i, sx: a, ...o } = e, s, c = n.metadata?.icon;
|
|
166
167
|
return s = B(b, c === "formula" ? {
|
|
167
168
|
iconKey: "ScriptFormula",
|
|
@@ -208,7 +209,7 @@ var J = r(n((e, t) => {
|
|
|
208
209
|
variant: "caption",
|
|
209
210
|
component: "div",
|
|
210
211
|
sx: {
|
|
211
|
-
color: (e) =>
|
|
212
|
+
color: (e) => te(e.palette.text.secondary ?? e.palette.text.primary, .6),
|
|
212
213
|
overflow: "hidden",
|
|
213
214
|
textOverflow: "ellipsis"
|
|
214
215
|
},
|
|
@@ -216,12 +217,12 @@ var J = r(n((e, t) => {
|
|
|
216
217
|
})]
|
|
217
218
|
})
|
|
218
219
|
});
|
|
219
|
-
}),
|
|
220
|
-
let { groupKey: r, disabled: o, scriptPath: s =
|
|
220
|
+
}), pe = r(n((e, n) => {
|
|
221
|
+
let { groupKey: r, disabled: o, scriptPath: s = q, ...c } = e, d = D(), [f, p] = l([]), [m, h] = l(!0), [g] = T(["insertScript"]), v = o || (g?.disabled() ?? !1);
|
|
221
222
|
a(() => {
|
|
222
223
|
(async () => {
|
|
223
224
|
try {
|
|
224
|
-
let e = await
|
|
225
|
+
let e = await de(s);
|
|
225
226
|
p(e);
|
|
226
227
|
} catch {} finally {
|
|
227
228
|
h(!1);
|
|
@@ -239,7 +240,7 @@ var J = r(n((e, t) => {
|
|
|
239
240
|
}, i = [];
|
|
240
241
|
for (let e = 0; e < f.length; e++) {
|
|
241
242
|
let t = f[e];
|
|
242
|
-
t && i.push(B(
|
|
243
|
+
t && i.push(B(fe, {
|
|
243
244
|
handleInsert: r,
|
|
244
245
|
snippet: t
|
|
245
246
|
}, t.path));
|
|
@@ -315,7 +316,7 @@ var J = r(n((e, t) => {
|
|
|
315
316
|
B("div", { style: { flex: "1 1 100%" } }),
|
|
316
317
|
B("div", { children: B(N, {
|
|
317
318
|
style: {},
|
|
318
|
-
children: B(
|
|
319
|
+
children: B(pe, { ...t })
|
|
319
320
|
}) })
|
|
320
321
|
]
|
|
321
322
|
}) });
|
|
@@ -323,9 +324,9 @@ var J = r(n((e, t) => {
|
|
|
323
324
|
...r
|
|
324
325
|
});
|
|
325
326
|
}));
|
|
326
|
-
Z.displayName = "ScriptEditorToolbar",
|
|
327
|
-
var
|
|
328
|
-
let { scriptPath: n =
|
|
327
|
+
Z.displayName = "ScriptEditorToolbar", G();
|
|
328
|
+
var me = r(n((e, t) => {
|
|
329
|
+
let { scriptPath: n = q, 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);
|
|
329
330
|
if (a(() => {
|
|
330
331
|
(async () => {
|
|
331
332
|
let e = [{
|
|
@@ -338,7 +339,7 @@ var fe = r(n((e, t) => {
|
|
|
338
339
|
}];
|
|
339
340
|
try {
|
|
340
341
|
C(!0), T(null);
|
|
341
|
-
let t = await
|
|
342
|
+
let t = await de(n);
|
|
342
343
|
for (let n = 0; n < t.length; n++) {
|
|
343
344
|
let r = t[n];
|
|
344
345
|
r && e.push(r);
|
|
@@ -504,7 +505,7 @@ var fe = r(n((e, t) => {
|
|
|
504
505
|
}), E]
|
|
505
506
|
});
|
|
506
507
|
}));
|
|
507
|
-
|
|
508
|
+
me.displayName = "TemplateSelectPanel";
|
|
508
509
|
var Q = r(n((e, t) => {
|
|
509
510
|
let { className: n, sx: r, propsScriptEditor: s, readOnly: d = !1, frame: f, autoFocusSel: g, autoFocus: _ = !0, scripts: v, ...y } = e, b = h(), [x, S] = l(!1), w = c(!1), [T, D] = l({
|
|
510
511
|
message: "Loading",
|
|
@@ -649,7 +650,7 @@ var Q = r(n((e, t) => {
|
|
|
649
650
|
position: "relative",
|
|
650
651
|
boxSizing: "border-box"
|
|
651
652
|
},
|
|
652
|
-
children: B(
|
|
653
|
+
children: B(ne, {
|
|
653
654
|
ref: j,
|
|
654
655
|
loadingPanel: I,
|
|
655
656
|
readOnly: d,
|
|
@@ -675,9 +676,9 @@ var Q = r(n((e, t) => {
|
|
|
675
676
|
g,
|
|
676
677
|
f,
|
|
677
678
|
A
|
|
678
|
-
]),
|
|
679
|
+
]), te = o(() => {
|
|
679
680
|
let e;
|
|
680
|
-
return O === null ? I : (O.source === null && (e = B(
|
|
681
|
+
return O === null ? I : (O.source === null && (e = B(me, {
|
|
681
682
|
sx: {
|
|
682
683
|
display: "flex",
|
|
683
684
|
flex: "1 1 100%",
|
|
@@ -733,7 +734,7 @@ var Q = r(n((e, t) => {
|
|
|
733
734
|
O,
|
|
734
735
|
I,
|
|
735
736
|
d
|
|
736
|
-
]),
|
|
737
|
+
]), H = E(t, () => ({
|
|
737
738
|
isScriptWorkspaceElement: () => !0,
|
|
738
739
|
focus: (e) => {
|
|
739
740
|
F(e);
|
|
@@ -747,32 +748,32 @@ var Q = r(n((e, t) => {
|
|
|
747
748
|
position: "relative",
|
|
748
749
|
...r
|
|
749
750
|
},
|
|
750
|
-
ref:
|
|
751
|
+
ref: H,
|
|
751
752
|
...y,
|
|
752
753
|
onFocus: (e) => {
|
|
753
|
-
S(!0), w.current = !0,
|
|
754
|
+
S(!0), w.current = !0, H.current?.contains(e.target) && e.target !== H.current && N(e.target), e.relatedTarget && !P.current && (P.current = e.relatedTarget), y?.onFocus?.(e);
|
|
754
755
|
},
|
|
755
756
|
onBlur: (e) => {
|
|
756
|
-
|
|
757
|
+
H?.current?.contains(e.relatedTarget) || H?.current === e.relatedTarget || (P.current = null, w.current = !1, S(!1)), y?.onBlur?.(e);
|
|
757
758
|
},
|
|
758
|
-
children:
|
|
759
|
+
children: te
|
|
759
760
|
});
|
|
760
761
|
}));
|
|
761
762
|
Q.displayName = "ScriptWorkspace";
|
|
762
|
-
var { FocusActivation:
|
|
763
|
-
let t =
|
|
764
|
-
return t ? B(
|
|
765
|
-
spec:
|
|
763
|
+
var { FocusActivation: he, CommandScopeProvider: ge, CommandAnchorProvider: _e, useCommandScope: ve } = g, ye = { scopeName: "scriptEditor" }, be = ({ children: e }) => {
|
|
764
|
+
let t = ve(), n = c(null);
|
|
765
|
+
return t ? B(ge, {
|
|
766
|
+
spec: ye,
|
|
766
767
|
elementRef: n,
|
|
767
768
|
region: !0,
|
|
768
|
-
children: B(
|
|
769
|
+
children: B(xe, {
|
|
769
770
|
paneRef: n,
|
|
770
771
|
children: e
|
|
771
772
|
})
|
|
772
773
|
}) : e;
|
|
773
|
-
},
|
|
774
|
-
let n =
|
|
775
|
-
return r ? V(
|
|
774
|
+
}, xe = ({ paneRef: e, children: t }) => {
|
|
775
|
+
let n = ve(), r = o(() => n ? new he(n.getRoot(), n) : null, [n]);
|
|
776
|
+
return r ? V(_e, {
|
|
776
777
|
tracker: r,
|
|
777
778
|
keyBindings: !1,
|
|
778
779
|
debounce: 100,
|
|
@@ -784,9 +785,9 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he,
|
|
|
784
785
|
children: t
|
|
785
786
|
})]
|
|
786
787
|
}) : t;
|
|
787
|
-
},
|
|
788
|
+
}, Se = (e) => {
|
|
788
789
|
let { model: t, entryKey: n, frame: r, ref: i, ...a } = e, o = R() ?? t;
|
|
789
|
-
return L(o, ["onProtectionChange"]), B(
|
|
790
|
+
return L(o, ["onProtectionChange"]), B(be, { children: B(Q, {
|
|
790
791
|
ref: i,
|
|
791
792
|
readOnly: o?.getScripts().isReadOnly() ?? !1,
|
|
792
793
|
frame: r,
|
|
@@ -815,10 +816,10 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he,
|
|
|
815
816
|
c,
|
|
816
817
|
o,
|
|
817
818
|
r
|
|
818
|
-
]), u ? V(z, { children: [B(j, {}), B(
|
|
819
|
+
]), u ? V(z, { children: [B(j, {}), B(K, { ...n })] }) : null;
|
|
819
820
|
});
|
|
820
|
-
$.displayName = "RunScriptContribution",
|
|
821
|
-
var
|
|
821
|
+
$.displayName = "RunScriptContribution", G();
|
|
822
|
+
var Ce = r(n((e, n) => {
|
|
822
823
|
let { ...r } = e, i = R(), o = D(), [s, c] = l([]);
|
|
823
824
|
a(() => {
|
|
824
825
|
let e = i?.getScripts();
|
|
@@ -875,14 +876,14 @@ var xe = r(n((e, n) => {
|
|
|
875
876
|
children: m
|
|
876
877
|
});
|
|
877
878
|
}));
|
|
878
|
-
|
|
879
|
-
var
|
|
879
|
+
Ce.displayName = "InsertFunctionPopupPanel";
|
|
880
|
+
var we = r(n((e, t) => {
|
|
880
881
|
let { disabled: n, groupKey: r, ...a } = e, o = w("customFunctionOptions");
|
|
881
882
|
return B(k, {
|
|
882
883
|
ref: t,
|
|
883
884
|
disabled: n,
|
|
884
885
|
createPopupPanel: i((e) => {
|
|
885
|
-
let t = B(
|
|
886
|
+
let t = B(Ce, {
|
|
886
887
|
disabled: n,
|
|
887
888
|
groupKey: r,
|
|
888
889
|
...e
|
|
@@ -898,13 +899,13 @@ var Se = r(n((e, t) => {
|
|
|
898
899
|
...a
|
|
899
900
|
});
|
|
900
901
|
}));
|
|
901
|
-
|
|
902
|
-
var
|
|
903
|
-
|
|
902
|
+
we.displayName = "InsertFunctionContribution";
|
|
903
|
+
var Te = () => {
|
|
904
|
+
re(), y.register("plugin-scripts", { icons: {} }), F.registerTaskPane({
|
|
904
905
|
key: "scriptEditor",
|
|
905
906
|
getTitle: () => "Script (Typescript)",
|
|
906
907
|
getIcon: () => "ScriptRun",
|
|
907
|
-
component:
|
|
908
|
+
component: Se,
|
|
908
909
|
keepMounted: !0
|
|
909
910
|
}, !0), v.register({ key: "scriptsOptions" }, !0), v.register({ key: "customFunctionOptions" }, !0), v.register({
|
|
910
911
|
key: "scripting.runScript.home",
|
|
@@ -924,7 +925,7 @@ var Ce = () => {
|
|
|
924
925
|
anchor: "formulaCategory.web",
|
|
925
926
|
order: 1
|
|
926
927
|
} },
|
|
927
|
-
render: (t) => e.createElement(
|
|
928
|
+
render: (t) => e.createElement(we, { ...t })
|
|
928
929
|
}, !0);
|
|
929
930
|
};
|
|
930
|
-
export {
|
|
931
|
+
export { pe as InsertScriptCommandButton, K as RunScriptCommandButton, Z as ScriptEditorToolbar, Se as ScriptTaskPane, Q as ScriptWorkspace, Te as ScriptingPlugin };
|
package/node/esm/index.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.
|
|
2
|
+
* @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.7
|
|
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.
|
|
6
6
|
*/
|
|
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
|
-
import { Box as p, Button as m, CircularProgress as u, Paper as h, Typography as f, useTheme as
|
|
10
|
-
import { Command as
|
|
11
|
-
import { AnimatedLoadingPanel as D, CommandButton as I, CommandPopupButton as L, CommandToolbar as P, ExhibitDivider as
|
|
12
|
-
import { DefaultTaskPaneRegistry as
|
|
9
|
+
import { Box as p, Button as m, CircularProgress as u, Paper as h, Typography as f, useTheme as x } from "@mui/material";
|
|
10
|
+
import { Command as g, 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 $, ExhibitMenuItem as E, OverflowPalette as R, defaultCreatePopupPanel as z } from "@sheetxl/utils-mui";
|
|
12
|
+
import { DefaultTaskPaneRegistry as A, InputClipboardInjector as B, useModelSync as O, 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
|
-
import {
|
|
15
|
+
import { VERSION as q } from "@sheetxl/sdk";
|
|
16
|
+
import { ChainedError as Z } from "@sheetxl/utils";
|
|
16
17
|
import { ScriptEditor as G, ScriptingReactPlugin as J } from "@sheetxl/scripting-react";
|
|
17
|
-
var
|
|
18
|
+
var _ = {
|
|
18
19
|
"insertFunction.fallbackLabel": "Function",
|
|
19
20
|
"insertFunction.insertNamed": "Insert {name}",
|
|
20
21
|
"insertScript.fallbackLabel": "Insert Script",
|
|
@@ -29,12 +30,12 @@ var Z = {
|
|
|
29
30
|
"templateSelect.loadFailed": "Failed to load scripts",
|
|
30
31
|
"templateSelect.title": "Script Template",
|
|
31
32
|
"templateSelect.untitled": "Untitled"
|
|
32
|
-
}, { DefaultCommandCatalogService:
|
|
33
|
-
function
|
|
34
|
-
|
|
33
|
+
}, { DefaultCommandCatalogService: Q } = g, V = !1;
|
|
34
|
+
function X() {
|
|
35
|
+
V || (V = !0, Q.registerFromManifest("@sheetxl/scripting-mui", import.meta.url, { messages: _ }));
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
var
|
|
37
|
+
X();
|
|
38
|
+
var Y = n(r((e, r) => {
|
|
38
39
|
const { groupKey: n, ...i } = e, a = M(), l = K(), [s, d] = c([]), [m, u] = c(!1);
|
|
39
40
|
o(() => {
|
|
40
41
|
const e = a?.getScripts();
|
|
@@ -49,8 +50,8 @@ var X = n(r((e, r) => {
|
|
|
49
50
|
variant: y.Menuitem,
|
|
50
51
|
groupKey: "scriptsOptions",
|
|
51
52
|
shortcut: void 0
|
|
52
|
-
}, f = [],
|
|
53
|
-
for (let e = 0; e <
|
|
53
|
+
}, f = [], x = s ? s.length : 0;
|
|
54
|
+
for (let e = 0; e < x; e++) {
|
|
54
55
|
const t = s[e];
|
|
55
56
|
f.push(j(I, {
|
|
56
57
|
...h,
|
|
@@ -61,7 +62,7 @@ var X = n(r((e, r) => {
|
|
|
61
62
|
label: t.getName() ?? l("runScript.fallbackLabel")
|
|
62
63
|
}, `macro-${t.getName()}-${e}`));
|
|
63
64
|
}
|
|
64
|
-
const
|
|
65
|
+
const g = H(p, {
|
|
65
66
|
ref: r,
|
|
66
67
|
sx: {
|
|
67
68
|
display: "flex",
|
|
@@ -75,7 +76,7 @@ var X = n(r((e, r) => {
|
|
|
75
76
|
flex: "1 1 100%"
|
|
76
77
|
},
|
|
77
78
|
children: f
|
|
78
|
-
}), j(
|
|
79
|
+
}), j($, { orientation: "horizontal" })] }) : null, t(I, {
|
|
79
80
|
...h,
|
|
80
81
|
key: "show-editor",
|
|
81
82
|
commandKey: "showScriptEditor"
|
|
@@ -83,17 +84,17 @@ var X = n(r((e, r) => {
|
|
|
83
84
|
});
|
|
84
85
|
return z({
|
|
85
86
|
...i,
|
|
86
|
-
children:
|
|
87
|
+
children: g
|
|
87
88
|
});
|
|
88
89
|
}));
|
|
89
|
-
|
|
90
|
-
var
|
|
90
|
+
Y.displayName = "RunScriptPopupPanel";
|
|
91
|
+
var ee = n(r((e, t) => {
|
|
91
92
|
const { groupKey: r, disabled: n, ...o } = e, a = N(["showScriptEditor"])[0], l = F("scriptsOptions");
|
|
92
93
|
return j(L, {
|
|
93
94
|
ref: t,
|
|
94
95
|
disabled: n,
|
|
95
96
|
createPopupPanel: i((e) => {
|
|
96
|
-
const t = j(
|
|
97
|
+
const t = j(Y, {
|
|
97
98
|
disabled: n,
|
|
98
99
|
groupKey: r,
|
|
99
100
|
...e
|
|
@@ -109,22 +110,22 @@ var Y = n(r((e, t) => {
|
|
|
109
110
|
quickCommand: "showScriptEditor",
|
|
110
111
|
...o
|
|
111
112
|
});
|
|
112
|
-
})),
|
|
113
|
+
})), te = /^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/.exec(q)?.[1], re = `https://unpkg.com/@sheetxl/templates-scripting${te ? `@${te}` : ""}/dist`, ne = (e, t) => {
|
|
113
114
|
try {
|
|
114
115
|
return new URL(t).href;
|
|
115
116
|
} catch {}
|
|
116
117
|
if (t.startsWith("/") || /^[a-zA-Z]:/.test(t)) return t;
|
|
117
118
|
let r = e.startsWith("http") ? e : `file:///${e.replace(/\\/g, "/")}`;
|
|
118
119
|
return r.endsWith("/") || (r += "/"), new URL(t, r).href;
|
|
119
|
-
},
|
|
120
|
+
}, ie = (e) => {
|
|
120
121
|
if (e.metadata?.name) return e.metadata.name;
|
|
121
122
|
let t = (e.path.split("/").pop() || "").replace(/\.[^/.]+$/, "");
|
|
122
123
|
return "formula" === e.metadata?.icon ? 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(" "));
|
|
123
|
-
},
|
|
124
|
-
const t =
|
|
125
|
-
if (!r.ok) throw new
|
|
124
|
+
}, oe = async (e) => {
|
|
125
|
+
const t = ne(e, "./manifest.json"), r = await fetch(t);
|
|
126
|
+
if (!r.ok) throw new Z(`Failed to retrieve directory at '${e}': ${r.statusText}`);
|
|
126
127
|
const n = await r.text();
|
|
127
|
-
if (n.trim().toLowerCase().startsWith("<!doctype html") || n.trim().toLowerCase().startsWith("<html")) throw new
|
|
128
|
+
if (n.trim().toLowerCase().startsWith("<!doctype html") || n.trim().toLowerCase().startsWith("<html")) throw new Z(`Failed to retrieve directory at '${e}'`);
|
|
128
129
|
let i;
|
|
129
130
|
try {
|
|
130
131
|
i = JSON.parse(n);
|
|
@@ -133,12 +134,12 @@ var Y = n(r((e, t) => {
|
|
|
133
134
|
}
|
|
134
135
|
const o = i.map(async (t) => {
|
|
135
136
|
try {
|
|
136
|
-
const r =
|
|
137
|
+
const r = ne(e, t.path), n = await fetch(r);
|
|
137
138
|
if (!n.ok) throw new Error(`Failed to fetch file at '${t.path}': ${n.statusText}`);
|
|
138
139
|
const i = await n.text();
|
|
139
140
|
let o = t.metadata;
|
|
140
141
|
return o?.title || (o = {
|
|
141
|
-
title:
|
|
142
|
+
title: ie(t),
|
|
142
143
|
...o
|
|
143
144
|
}), {
|
|
144
145
|
path: t.path,
|
|
@@ -151,23 +152,23 @@ var Y = n(r((e, t) => {
|
|
|
151
152
|
return null;
|
|
152
153
|
});
|
|
153
154
|
return (await Promise.all(o)).filter((e) => null !== e);
|
|
154
|
-
},
|
|
155
|
+
}, ae = { marginRight: "4px" }, le = "1em", se = n((e) => {
|
|
155
156
|
const { disabled: t, snippet: r, description: n, handleInsert: i, sx: o, ...a } = e;
|
|
156
157
|
let l;
|
|
157
158
|
const s = r.metadata?.icon;
|
|
158
159
|
return l = j(v, "formula" === s ? {
|
|
159
160
|
iconKey: "ScriptFormula",
|
|
160
|
-
size:
|
|
161
|
-
style:
|
|
161
|
+
size: le,
|
|
162
|
+
style: ae
|
|
162
163
|
} : "macro" === s ? {
|
|
163
164
|
iconKey: "ScriptMacro",
|
|
164
|
-
size:
|
|
165
|
-
style:
|
|
165
|
+
size: le,
|
|
166
|
+
style: ae
|
|
166
167
|
} : {
|
|
167
168
|
iconKey: "ScriptAutoRun",
|
|
168
|
-
size:
|
|
169
|
-
style:
|
|
170
|
-
}), j(
|
|
169
|
+
size: le,
|
|
170
|
+
style: ae
|
|
171
|
+
}), j(E, {
|
|
171
172
|
sx: {
|
|
172
173
|
maxWidth: "460px",
|
|
173
174
|
display: "flex",
|
|
@@ -208,12 +209,12 @@ var Y = n(r((e, t) => {
|
|
|
208
209
|
})]
|
|
209
210
|
})
|
|
210
211
|
});
|
|
211
|
-
}),
|
|
212
|
-
const { groupKey: n, disabled: a, scriptPath: l =
|
|
212
|
+
}), ce = n(r((e, r) => {
|
|
213
|
+
const { groupKey: n, disabled: a, scriptPath: l = re, ...s } = e, d = K(), [m, u] = c([]), [h, f] = c(!0), [x] = N(["insertScript"]), g = a || (x?.disabled() ?? !1);
|
|
213
214
|
o(() => {
|
|
214
215
|
(async () => {
|
|
215
216
|
try {
|
|
216
|
-
const e = await
|
|
217
|
+
const e = await oe(l);
|
|
217
218
|
u(e);
|
|
218
219
|
} catch (e) {} finally {
|
|
219
220
|
f(!1);
|
|
@@ -225,13 +226,13 @@ var Y = n(r((e, t) => {
|
|
|
225
226
|
const r = {
|
|
226
227
|
variant: y.Menuitem,
|
|
227
228
|
groupKey: "scriptsOptions",
|
|
228
|
-
disabled:
|
|
229
|
+
disabled: g
|
|
229
230
|
}, n = (t) => {
|
|
230
|
-
|
|
231
|
+
x?.execute(t.content), e.closeFloat?.();
|
|
231
232
|
}, i = [];
|
|
232
233
|
for (let e = 0; e < m.length; e++) {
|
|
233
234
|
const t = m[e];
|
|
234
|
-
t && i.push(j(
|
|
235
|
+
t && i.push(j(se, {
|
|
235
236
|
handleInsert: n,
|
|
236
237
|
snippet: t
|
|
237
238
|
}, t.path));
|
|
@@ -250,7 +251,7 @@ var Y = n(r((e, t) => {
|
|
|
250
251
|
flex: "1 1 100%"
|
|
251
252
|
},
|
|
252
253
|
children: i
|
|
253
|
-
}), j(
|
|
254
|
+
}), j($, { orientation: "horizontal" })] }) : null,
|
|
254
255
|
t(I, {
|
|
255
256
|
...r,
|
|
256
257
|
key: "showKeyboardShortcuts",
|
|
@@ -268,23 +269,23 @@ var Y = n(r((e, t) => {
|
|
|
268
269
|
children: o
|
|
269
270
|
});
|
|
270
271
|
}, [
|
|
271
|
-
|
|
272
|
+
g,
|
|
272
273
|
n,
|
|
273
274
|
h,
|
|
274
|
-
|
|
275
|
+
x,
|
|
275
276
|
d
|
|
276
277
|
]);
|
|
277
278
|
return j(L, {
|
|
278
279
|
ref: r,
|
|
279
|
-
disabled:
|
|
280
|
+
disabled: g,
|
|
280
281
|
groupKey: n,
|
|
281
|
-
label:
|
|
282
|
-
tooltip:
|
|
282
|
+
label: x?.getLabel(n) ?? d("insertScript.fallbackLabel"),
|
|
283
|
+
tooltip: x?.getDescription(),
|
|
283
284
|
createPopupPanel: S,
|
|
284
|
-
icon:
|
|
285
|
+
icon: x?.getIcon() ?? "ScriptInsert",
|
|
285
286
|
...s
|
|
286
287
|
});
|
|
287
|
-
})),
|
|
288
|
+
})), de = n(r((e, t) => {
|
|
288
289
|
const { propsCommandButton: r, ...n } = e;
|
|
289
290
|
return j(P, {
|
|
290
291
|
ref: t,
|
|
@@ -307,7 +308,7 @@ var Y = n(r((e, t) => {
|
|
|
307
308
|
j("div", { style: { flex: "1 1 100%" } }),
|
|
308
309
|
j("div", { children: j(R, {
|
|
309
310
|
style: {},
|
|
310
|
-
children: j(
|
|
311
|
+
children: j(ce, { ...t })
|
|
311
312
|
}) })
|
|
312
313
|
]
|
|
313
314
|
}) });
|
|
@@ -315,9 +316,9 @@ var Y = n(r((e, t) => {
|
|
|
315
316
|
...n
|
|
316
317
|
});
|
|
317
318
|
}));
|
|
318
|
-
|
|
319
|
-
var
|
|
320
|
-
const { scriptPath: r =
|
|
319
|
+
de.displayName = "ScriptEditorToolbar", X();
|
|
320
|
+
var pe = n(r((e, t) => {
|
|
321
|
+
const { scriptPath: r = re, onScriptSelect: n, disabled: i = !1, sx: a = k.EmptyCssProperties, className: l, buttonMinWidth: s = 210, buttonMinHeight: h = 80, gap: x = 12, ...g } = e, y = K(), [S, b] = c([]), [w, C] = c(!0), [F, N] = c(null);
|
|
321
322
|
if (o(() => {
|
|
322
323
|
(async () => {
|
|
323
324
|
const e = [{
|
|
@@ -330,20 +331,20 @@ var ce = n(r((e, t) => {
|
|
|
330
331
|
}];
|
|
331
332
|
try {
|
|
332
333
|
C(!0), N(null);
|
|
333
|
-
const t = await
|
|
334
|
+
const t = await oe(r);
|
|
334
335
|
for (let r = 0; r < t.length; r++) {
|
|
335
336
|
const n = t[r];
|
|
336
337
|
n && e.push(n);
|
|
337
338
|
}
|
|
338
339
|
} catch (e) {
|
|
339
|
-
N(e instanceof Error ? e.message : y("templateSelect.loadFailed")), e instanceof
|
|
340
|
+
N(e instanceof Error ? e.message : y("templateSelect.loadFailed")), e instanceof Z || console.error("Error loading scripts:", e);
|
|
340
341
|
} finally {
|
|
341
342
|
b(e), C(!1);
|
|
342
343
|
}
|
|
343
344
|
})();
|
|
344
345
|
}, [r, y]), w) return j(p, {
|
|
345
346
|
className: d(l, "script-select"),
|
|
346
|
-
...
|
|
347
|
+
...g,
|
|
347
348
|
sx: [{
|
|
348
349
|
display: "flex",
|
|
349
350
|
justifyContent: "center",
|
|
@@ -358,7 +359,7 @@ var ce = n(r((e, t) => {
|
|
|
358
359
|
let T = null;
|
|
359
360
|
F && (T = H(p, {
|
|
360
361
|
className: d(l, "script-select", "error-results"),
|
|
361
|
-
...
|
|
362
|
+
...g,
|
|
362
363
|
sx: [{
|
|
363
364
|
display: "flex",
|
|
364
365
|
justifyContent: "center",
|
|
@@ -405,7 +406,7 @@ var ce = n(r((e, t) => {
|
|
|
405
406
|
zIndex: 1e3,
|
|
406
407
|
...a
|
|
407
408
|
},
|
|
408
|
-
...
|
|
409
|
+
...g,
|
|
409
410
|
children: [H(p, {
|
|
410
411
|
className: "script-select-content",
|
|
411
412
|
sx: {
|
|
@@ -437,7 +438,7 @@ var ce = n(r((e, t) => {
|
|
|
437
438
|
sx: {
|
|
438
439
|
display: "grid",
|
|
439
440
|
gridTemplateColumns: `repeat(auto-fill, minmax(${s}px, 1fr))`,
|
|
440
|
-
gap: `${
|
|
441
|
+
gap: `${x}px`,
|
|
441
442
|
padding: 2,
|
|
442
443
|
paddingLeft: "0px",
|
|
443
444
|
paddingRight: "0px"
|
|
@@ -496,9 +497,9 @@ var ce = n(r((e, t) => {
|
|
|
496
497
|
}), T]
|
|
497
498
|
});
|
|
498
499
|
}));
|
|
499
|
-
|
|
500
|
-
var
|
|
501
|
-
const { className: r, sx: n, propsScriptEditor: l, readOnly: m = !1, frame: u, autoFocusSel:
|
|
500
|
+
pe.displayName = "TemplateSelectPanel";
|
|
501
|
+
var me = n(r((e, t) => {
|
|
502
|
+
const { className: r, sx: n, propsScriptEditor: l, readOnly: m = !1, frame: u, autoFocusSel: g, autoFocus: y = !0, scripts: S, ...b } = e, v = x(), [w, k] = c(!1), F = s(!1), [N, K] = c({
|
|
502
503
|
message: "Loading",
|
|
503
504
|
cursor: "",
|
|
504
505
|
dirty: !1
|
|
@@ -519,18 +520,18 @@ var de = n(r((e, t) => {
|
|
|
519
520
|
...t,
|
|
520
521
|
...e
|
|
521
522
|
}));
|
|
522
|
-
}, []),
|
|
523
|
-
if (
|
|
524
|
-
if (
|
|
525
|
-
const t =
|
|
523
|
+
}, []), $ = s(null), [E, R] = c(null), z = s(null), A = C((e) => {
|
|
524
|
+
if (E) return E.focus(e), !0;
|
|
525
|
+
if (g) {
|
|
526
|
+
const t = $.current?.querySelectorAll?.(g);
|
|
526
527
|
if (t && t.length > 0) return t[0]?.focus?.(e), !0;
|
|
527
528
|
}
|
|
528
|
-
return
|
|
529
|
+
return $.current?.focus?.(e), !1;
|
|
529
530
|
}, [
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
E,
|
|
532
|
+
g,
|
|
532
533
|
y
|
|
533
|
-
]),
|
|
534
|
+
]), B = a(() => j(D, {
|
|
534
535
|
transitionDelay: "160ms",
|
|
535
536
|
style: {
|
|
536
537
|
position: "absolute",
|
|
@@ -538,7 +539,7 @@ var de = n(r((e, t) => {
|
|
|
538
539
|
height: "100%"
|
|
539
540
|
},
|
|
540
541
|
transparentBackground: !1
|
|
541
|
-
}), []),
|
|
542
|
+
}), []), O = a(() => j(h, {
|
|
542
543
|
elevation: 1,
|
|
543
544
|
tabIndex: 0,
|
|
544
545
|
sx: {
|
|
@@ -551,7 +552,7 @@ var de = n(r((e, t) => {
|
|
|
551
552
|
marginTop: (e) => e.spacing(1),
|
|
552
553
|
marginBottom: (e) => e.spacing(1)
|
|
553
554
|
},
|
|
554
|
-
children: j(
|
|
555
|
+
children: j(de, {})
|
|
555
556
|
}), [v]), M = a(() => j(p, {
|
|
556
557
|
className: d("script-status-panel", "status-panel"),
|
|
557
558
|
sx: {
|
|
@@ -631,7 +632,7 @@ var de = n(r((e, t) => {
|
|
|
631
632
|
boxSizing: "border-box"
|
|
632
633
|
},
|
|
633
634
|
children: [
|
|
634
|
-
|
|
635
|
+
O,
|
|
635
636
|
j(p, {
|
|
636
637
|
sx: {
|
|
637
638
|
display: "flex",
|
|
@@ -642,8 +643,8 @@ var de = n(r((e, t) => {
|
|
|
642
643
|
boxSizing: "border-box"
|
|
643
644
|
},
|
|
644
645
|
children: j(G, {
|
|
645
|
-
ref:
|
|
646
|
-
loadingPanel:
|
|
646
|
+
ref: $,
|
|
647
|
+
loadingPanel: B,
|
|
647
648
|
readOnly: m,
|
|
648
649
|
frame: u,
|
|
649
650
|
scripts: S,
|
|
@@ -657,19 +658,19 @@ var de = n(r((e, t) => {
|
|
|
657
658
|
]
|
|
658
659
|
}), [
|
|
659
660
|
v,
|
|
660
|
-
|
|
661
|
+
O,
|
|
661
662
|
M,
|
|
662
663
|
w,
|
|
663
|
-
|
|
664
|
+
B,
|
|
664
665
|
m,
|
|
665
666
|
l,
|
|
666
667
|
y,
|
|
667
|
-
|
|
668
|
+
g,
|
|
668
669
|
u,
|
|
669
670
|
P
|
|
670
671
|
]), U = a(() => {
|
|
671
672
|
let e;
|
|
672
|
-
return null === I ?
|
|
673
|
+
return null === I ? B : (null === I.source && (e = j(pe, {
|
|
673
674
|
sx: {
|
|
674
675
|
display: "flex",
|
|
675
676
|
flex: "1 1 100%",
|
|
@@ -682,7 +683,7 @@ var de = n(r((e, t) => {
|
|
|
682
683
|
},
|
|
683
684
|
disabled: m,
|
|
684
685
|
onScriptSelect: (e) => {
|
|
685
|
-
|
|
686
|
+
$.current?.insertSnippet(e.content), L({ source: e.content ?? "" }), requestAnimationFrame(() => $.current?.focus());
|
|
686
687
|
}
|
|
687
688
|
})), j(p, {
|
|
688
689
|
tabIndex: 0,
|
|
@@ -698,7 +699,7 @@ var de = n(r((e, t) => {
|
|
|
698
699
|
outline: "none"
|
|
699
700
|
},
|
|
700
701
|
onPointerDown: (e) => {
|
|
701
|
-
e.isDefaultPrevented() ||
|
|
702
|
+
e.isDefaultPrevented() || $.current?.focus();
|
|
702
703
|
},
|
|
703
704
|
children: H(p, {
|
|
704
705
|
sx: {
|
|
@@ -719,16 +720,16 @@ var de = n(r((e, t) => {
|
|
|
719
720
|
})
|
|
720
721
|
}));
|
|
721
722
|
}, [
|
|
722
|
-
|
|
723
|
+
O,
|
|
723
724
|
W,
|
|
724
725
|
r,
|
|
725
726
|
I,
|
|
726
|
-
|
|
727
|
+
B,
|
|
727
728
|
m
|
|
728
729
|
]), q = T(t, () => ({
|
|
729
730
|
isScriptWorkspaceElement: () => !0,
|
|
730
731
|
focus: (e) => {
|
|
731
|
-
|
|
732
|
+
A(e);
|
|
732
733
|
}
|
|
733
734
|
}), []);
|
|
734
735
|
return j(p, {
|
|
@@ -750,42 +751,42 @@ var de = n(r((e, t) => {
|
|
|
750
751
|
children: U
|
|
751
752
|
});
|
|
752
753
|
}));
|
|
753
|
-
|
|
754
|
-
var { FocusActivation:
|
|
755
|
-
const t =
|
|
756
|
-
return t ? j(
|
|
757
|
-
spec:
|
|
754
|
+
me.displayName = "ScriptWorkspace";
|
|
755
|
+
var { FocusActivation: ue, CommandScopeProvider: he, CommandAnchorProvider: fe, useCommandScope: xe } = g, ge = { scopeName: "scriptEditor" }, ye = ({ children: e }) => {
|
|
756
|
+
const t = xe(), r = s(null);
|
|
757
|
+
return t ? j(he, {
|
|
758
|
+
spec: ge,
|
|
758
759
|
elementRef: r,
|
|
759
760
|
region: !0,
|
|
760
|
-
children: j(
|
|
761
|
+
children: j(Se, {
|
|
761
762
|
paneRef: r,
|
|
762
763
|
children: e
|
|
763
764
|
})
|
|
764
765
|
}) : e;
|
|
765
|
-
},
|
|
766
|
-
const r =
|
|
767
|
-
return n ? H(
|
|
766
|
+
}, Se = ({ paneRef: e, children: t }) => {
|
|
767
|
+
const r = xe(), n = a(() => r ? new ue(r.getRoot(), r) : null, [r]);
|
|
768
|
+
return n ? H(fe, {
|
|
768
769
|
tracker: n,
|
|
769
770
|
keyBindings: !1,
|
|
770
771
|
debounce: 100,
|
|
771
772
|
elementRef: e,
|
|
772
|
-
children: [j(
|
|
773
|
+
children: [j(B, {}), j("div", {
|
|
773
774
|
className: "script-editor-pane",
|
|
774
775
|
style: { display: "contents" },
|
|
775
776
|
ref: e,
|
|
776
777
|
children: t
|
|
777
778
|
})]
|
|
778
779
|
}) : t;
|
|
779
|
-
},
|
|
780
|
+
}, be = (e) => {
|
|
780
781
|
const { model: t, entryKey: r, frame: n, ref: i, ...o } = e, a = M() ?? t;
|
|
781
|
-
return
|
|
782
|
+
return O(a, ["onProtectionChange"]), j(ye, { children: j(me, {
|
|
782
783
|
ref: i,
|
|
783
784
|
readOnly: a?.getScripts().isReadOnly() ?? !1,
|
|
784
785
|
frame: n,
|
|
785
786
|
scripts: a?.getScripts(),
|
|
786
787
|
...o
|
|
787
788
|
}) });
|
|
788
|
-
},
|
|
789
|
+
}, ve = n((e) => {
|
|
789
790
|
const { alwaysShow: t = !1, ...r } = e, [n, i] = l((e) => e + 1, 0), [a] = N(["showScriptEditor"], { onChange: () => i() }), s = M(), [d, p] = c(t);
|
|
790
791
|
return o(() => {
|
|
791
792
|
if (t) return void p(!0);
|
|
@@ -807,10 +808,10 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: ue,
|
|
|
807
808
|
s,
|
|
808
809
|
a,
|
|
809
810
|
n
|
|
810
|
-
]), d ? H(W, { children: [j(
|
|
811
|
+
]), d ? H(W, { children: [j($, {}), j(ee, { ...r })] }) : null;
|
|
811
812
|
});
|
|
812
|
-
|
|
813
|
-
var
|
|
813
|
+
ve.displayName = "RunScriptContribution", X();
|
|
814
|
+
var we = n(r((e, r) => {
|
|
814
815
|
const { ...n } = e, i = M(), a = K(), [l, s] = c([]);
|
|
815
816
|
o(() => {
|
|
816
817
|
const e = i?.getScripts();
|
|
@@ -857,7 +858,7 @@ var be = n(r((e, r) => {
|
|
|
857
858
|
flex: "1 1 100%"
|
|
858
859
|
},
|
|
859
860
|
children: m
|
|
860
|
-
}), j(
|
|
861
|
+
}), j($, { orientation: "horizontal" })] }) : null, t(I, {
|
|
861
862
|
...d,
|
|
862
863
|
key: "show-editor",
|
|
863
864
|
commandKey: "showScriptEditor"
|
|
@@ -868,14 +869,14 @@ var be = n(r((e, r) => {
|
|
|
868
869
|
children: h
|
|
869
870
|
});
|
|
870
871
|
}));
|
|
871
|
-
|
|
872
|
-
var
|
|
872
|
+
we.displayName = "InsertFunctionPopupPanel";
|
|
873
|
+
var ke = n(r((e, t) => {
|
|
873
874
|
const { disabled: r, groupKey: n, ...o } = e, a = F("customFunctionOptions");
|
|
874
875
|
return j(L, {
|
|
875
876
|
ref: t,
|
|
876
877
|
disabled: r,
|
|
877
878
|
createPopupPanel: i((e) => {
|
|
878
|
-
const t = j(
|
|
879
|
+
const t = j(we, {
|
|
879
880
|
disabled: r,
|
|
880
881
|
groupKey: n,
|
|
881
882
|
...e
|
|
@@ -891,22 +892,22 @@ var ve = n(r((e, t) => {
|
|
|
891
892
|
...o
|
|
892
893
|
});
|
|
893
894
|
}));
|
|
894
|
-
|
|
895
|
-
var
|
|
896
|
-
J(), b.register("plugin-scripts", { icons: {} }),
|
|
895
|
+
ke.displayName = "InsertFunctionContribution";
|
|
896
|
+
var Ce = () => {
|
|
897
|
+
J(), b.register("plugin-scripts", { icons: {} }), A.registerTaskPane({
|
|
897
898
|
key: "scriptEditor",
|
|
898
899
|
getTitle: () => "Script (Typescript)",
|
|
899
900
|
getIcon: () => "ScriptRun",
|
|
900
|
-
component:
|
|
901
|
+
component: be,
|
|
901
902
|
keepMounted: !0
|
|
902
903
|
}, !0), S.register({ key: "scriptsOptions" }, !0), S.register({ key: "customFunctionOptions" }, !0), S.register({
|
|
903
904
|
key: "scripting.runScript.home",
|
|
904
905
|
contributions: { homeToolbar: {} },
|
|
905
|
-
render: (t) => e.createElement(
|
|
906
|
+
render: (t) => e.createElement(ve, { ...t })
|
|
906
907
|
}, !0), S.register({
|
|
907
908
|
key: "scripting.runScript.view",
|
|
908
909
|
contributions: { viewToolbar: { order: 10 } },
|
|
909
|
-
render: (t) => e.createElement(
|
|
910
|
+
render: (t) => e.createElement(ve, {
|
|
910
911
|
...t,
|
|
911
912
|
groupKey: "view",
|
|
912
913
|
alwaysShow: !0
|
|
@@ -917,7 +918,7 @@ var we = () => {
|
|
|
917
918
|
anchor: "formulaCategory.web",
|
|
918
919
|
order: 1
|
|
919
920
|
} },
|
|
920
|
-
render: (t) => e.createElement(
|
|
921
|
+
render: (t) => e.createElement(ke, { ...t })
|
|
921
922
|
}, !0);
|
|
922
923
|
};
|
|
923
|
-
export {
|
|
924
|
+
export { ce as InsertScriptCommandButton, ee as RunScriptCommandButton, de as ScriptEditorToolbar, be as ScriptTaskPane, me as ScriptWorkspace, Ce 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.8.0-beta.
|
|
4
|
+
"version": "0.8.0-beta.7",
|
|
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.8.0-beta.
|
|
42
|
-
"@sheetxl/scripting-react": "^0.8.0-beta.
|
|
43
|
-
"@sheetxl/sdk": "^0.8.0-beta.
|
|
44
|
-
"@sheetxl/studio-mui": "^0.8.0-beta.
|
|
45
|
-
"@sheetxl/utils": "^0.8.0-beta.
|
|
46
|
-
"@sheetxl/utils-mui": "^0.8.0-beta.
|
|
47
|
-
"@sheetxl/utils-react": "^0.8.0-beta.
|
|
41
|
+
"@sheetxl/react": "^0.8.0-beta.7",
|
|
42
|
+
"@sheetxl/scripting-react": "^0.8.0-beta.7",
|
|
43
|
+
"@sheetxl/sdk": "^0.8.0-beta.7",
|
|
44
|
+
"@sheetxl/studio-mui": "^0.8.0-beta.7",
|
|
45
|
+
"@sheetxl/utils": "^0.8.0-beta.7",
|
|
46
|
+
"@sheetxl/utils-mui": "^0.8.0-beta.7",
|
|
47
|
+
"@sheetxl/utils-react": "^0.8.0-beta.7",
|
|
48
48
|
"clsx": "^2.1.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_SCRIPT_PATH
|
|
1
|
+
export declare const DEFAULT_SCRIPT_PATH: string;
|
|
2
2
|
//# sourceMappingURL=Utils.d.ts.map
|