@sheetxl/scripting-mui 0.8.0-beta.1 → 0.8.0-beta.11

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/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.1",
4
+ "version": "0.8.0-beta.11",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -9,13 +9,12 @@
9
9
  "types": "./types/index.d.ts",
10
10
  "browser": "./browser/esm/index.mjs",
11
11
  "node": "./node/esm/index.mjs",
12
- "import": "./browser/esm/index.mjs",
13
- "require": "./browser/cjs/index.cjs"
12
+ "default": "./browser/esm/index.mjs"
14
13
  }
15
14
  },
16
15
  "types": "./types/index.d.ts",
17
16
  "module": "./browser/esm/index.mjs",
18
- "main": "./browser/cjs/index.cjs",
17
+ "main": "./browser/esm/index.mjs",
19
18
  "sideEffects": [
20
19
  "*.css",
21
20
  "**/*.css"
@@ -38,13 +37,13 @@
38
37
  "automation"
39
38
  ],
40
39
  "dependencies": {
41
- "@sheetxl/react": "^0.8.0-beta.1",
42
- "@sheetxl/scripting-react": "^0.8.0-beta.1",
43
- "@sheetxl/sdk": "^0.8.0-beta.1",
44
- "@sheetxl/studio-mui": "^0.8.0-beta.1",
45
- "@sheetxl/utils": "^0.8.0-beta.1",
46
- "@sheetxl/utils-mui": "^0.8.0-beta.1",
47
- "@sheetxl/utils-react": "^0.8.0-beta.1",
40
+ "@sheetxl/react": "^0.8.0-beta.11",
41
+ "@sheetxl/scripting-react": "^0.8.0-beta.11",
42
+ "@sheetxl/sdk": "^0.8.0-beta.11",
43
+ "@sheetxl/studio-mui": "^0.8.0-beta.11",
44
+ "@sheetxl/utils": "^0.8.0-beta.11",
45
+ "@sheetxl/utils-mui": "^0.8.0-beta.11",
46
+ "@sheetxl/utils-react": "^0.8.0-beta.11",
48
47
  "clsx": "^2.1.1"
49
48
  },
50
49
  "peerDependencies": {
@@ -59,7 +58,7 @@
59
58
  "react-dom": "^19.0.0"
60
59
  },
61
60
  "devDependencies": {
62
- "@types/react": "^19.2.17",
63
- "@types/react-dom": "^19.2.3"
61
+ "@types/react": "^19.3.0",
62
+ "@types/react-dom": "^19.3.0"
64
63
  }
65
64
  }
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "insertFunction.fallbackLabel": "Funktion",
3
3
  "insertFunction.insertNamed": "{name} einfügen",
4
+ "insertScript.fallbackLabel": "Skript einfügen",
5
+ "insertScript.loadFailedRetry": "Vorlagen konnten nicht geladen werden. Erneut versuchen",
6
+ "insertScript.loading": "Wird geladen...",
4
7
  "runScript.executeNamed": "{name} ausführen",
5
8
  "runScript.fallbackLabel": "Makro",
6
9
  "templateSelect.blankSummary": "Mit einem leeren Skript beginnen.",
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "insertFunction.fallbackLabel": "Function",
3
3
  "insertFunction.insertNamed": "Insert {name}",
4
+ "insertScript.fallbackLabel": "Insert Script",
5
+ "insertScript.loadFailedRetry": "Couldn’t load templates. Retry",
6
+ "insertScript.loading": "Loading...",
4
7
  "runScript.executeNamed": "Execute {name}",
5
8
  "runScript.fallbackLabel": "Macro",
6
9
  "templateSelect.blankSummary": "Start with an empty script.",
@@ -2,7 +2,8 @@ import { default as React } from 'react';
2
2
  import { CommandPopupButtonProps } from '@sheetxl/utils-mui';
3
3
  export interface InsertScriptCommandButtonProps extends CommandPopupButtonProps {
4
4
  /**
5
- * Path to fetch directory scripts from.
5
+ * The script templates to read: a URL that serves `templates-scripting/contents.json`.
6
+ * @defaultValue {@link DEFAULT_SCRIPT_PATH}
6
7
  */
7
8
  scriptPath?: string;
8
9
  }
@@ -1,19 +1,25 @@
1
1
  import { default as React } from 'react';
2
2
  import { SxProps, Theme } from '@mui/system';
3
- import { DirectoryFile } from '../utils';
3
+ import { ScriptTemplate } from '../utils';
4
4
  export interface TemplateSelectPanelProps extends React.HTMLAttributes<HTMLDivElement> {
5
5
  /**
6
6
  * MUI SX props {@link https://mui.com/system/getting-started/the-sx-prop/}
7
7
  */
8
8
  sx?: SxProps<Theme>;
9
9
  /**
10
- * Path to fetch directory scripts from.
10
+ * The script templates to read: a URL that serves `templates-scripting/contents.json`.
11
+ * @defaultValue {@link DEFAULT_SCRIPT_PATH}
11
12
  */
12
13
  scriptPath?: string;
13
14
  /**
14
15
  * Called when a script button is clicked
15
16
  */
16
- onScriptSelect?: (file: DirectoryFile) => void;
17
+ onScriptSelect?: (file: ScriptTemplate) => void;
18
+ /**
19
+ * Disables every template, for scripts that cannot be changed.
20
+ * @defaultValue false
21
+ */
22
+ disabled?: boolean;
17
23
  /**
18
24
  * Additional class name
19
25
  */
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Where the script templates are read from when no `scriptPath` is given: the published
3
+ * `@sheetxl/templates-scripting` for this build's release channel.
4
+ */
5
+ export declare const DEFAULT_SCRIPT_PATH: string;
6
+ /** How a script template runs, which is also the icon it shows. */
7
+ export type ScriptTemplateIcon = 'formula' | 'macro' | 'autostart';
8
+ /** One script template, with its source loaded. */
9
+ export interface ScriptTemplate {
10
+ /** The template's path within the catalog (`add.ts`), or `null` for the blank template. */
11
+ path: string | null;
12
+ /** The display title. */
13
+ title: string;
14
+ summary?: string;
15
+ icon?: ScriptTemplateIcon;
16
+ /** The script source. */
17
+ content: string;
18
+ }
19
+ /**
20
+ * Load the script templates at `path`, sources included, in the catalog's order.
21
+ *
22
+ * @remarks
23
+ * Loaded once per `path` and shared by every caller. A template whose source does not load is left
24
+ * out; a catalog that cannot be found rejects.
25
+ */
26
+ export declare const loadScriptTemplates: (path?: string) => Promise<ScriptTemplate[]>;
27
+ //# sourceMappingURL=ScriptTemplates.d.ts.map
@@ -1,3 +1,2 @@
1
- export * from './Utils';
2
- export * from './FetchDirectory';
1
+ export * from './ScriptTemplates';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +0,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}`,"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,20 +0,0 @@
1
- export interface DirectoryFile<M = any> {
2
- /** `null` for a synthetic entry with no backing file (e.g. the "blank" template). */
3
- path: string | null;
4
- metadata?: M;
5
- content: string;
6
- }
7
- export interface DirectoryEntry<M = any> {
8
- path: string;
9
- metadata?: M;
10
- }
11
- /**
12
- * Fetches and loads 'virtual files' using fetch.
13
- *
14
- * @remarks
15
- * This function only works if there is a directory.json file at the directory path.
16
- *
17
- * @returns {Promise<DirectoryFile[]>} A promise that resolves to the content of the directory.
18
- */
19
- export declare const fetchDirectory: (directoryPath: string) => Promise<DirectoryFile[]>;
20
- //# sourceMappingURL=FetchDirectory.d.ts.map
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_SCRIPT_PATH = "https://unpkg.com/@sheetxl/scripting-templates/dist";
2
- //# sourceMappingURL=Utils.d.ts.map