# Advanced The advanced widget category consists of the following widgets: * [Code Sandbox](#code-sandbox) * [File Import](#file-import) * [Iframe](#iframe) ## Code Sandbox The Code Sandbox widget is a secure sandbox for you to implement your own custom widget to extend the functionality of Slate. You are able to build your own custom visualizations, take advantage of third-party JavaScript libraries, or build advanced workflow interactions. You can define the rendering, the widget model, and the event interactions so that your widget integrates with the rest of your application. External JavaScript libraries can be loaded into a folder in your Project and referenced in your widget. :::callout{theme="warning" title="Debugging custom widget code is not supported"} The Code Sandbox widget unlocks advanced, custom development capabilities within your Slate application. Implementing custom functionality through the Code Sandbox widget should be done with a clear understanding of the technical complexity involved and long-term maintenance required for successful development. Widget development is at your own discretion and risk; support is not provided for debugging custom code. ::: ### Summary of interaction A summary of interaction with Slate and functions that can be used can be found below: ![image](../../../assets/df0e2ab9419c8de0ad04bd9276ffb9786c3310570ff6b9169b32309748dc1863.webp) ### JavaScript tab This tab has the fields for the JavaScript, as well as any JavaScript libraries you might wish to load. ![image](../../../assets/22a08a4961939e464d1af46f33a69ad6cb351ecdef9199330af8a29c5ed259cf.webp) #### JavaScript This is a string of JavaScript that will get executed when the widget loads. Making any change to this JavaScript will cause the entire widget to reload. The JavaScript in this field will be executed after the JavaScript from the libraries field. See the [JavaScript libraries](#javascript-libraries) section for instructions on loading third party libraries. Do not use Handlebars in the JavaScript field. We recommend that you pass in data using `SlateFunctions` through the JavaScript tab to interact with [state](#state) in the interaction tab. :::callout{theme="warning" title="Network requests must be proxied through Queries"} Network requests and references (for example, the usage of `fetch`) are not supported in the Code Sandbox for JavaScript, [JavaScript libraries](#javascript-libraries), or [HTML](#html). Any network requests must be proxied to configured [Queries](../concepts-queries/index.md) via `SlateFunctions`. ::: **Available functions** The following native functions can be invoked to interact with Slate specific functionality. These functions allow you to interact with the rest of the Slate application through the use of events, actions, and state changes. The functions are exposed to the JavaScript running within the widget. More information and examples can be found below. * [SlateFunctions.onAction](#onaction) * [SlateFunctions.watch](#watch) * [SlateFunctions.getState](#getstate) * [SlateFunctions.setState](#setstate) * [SlateFunctions.triggerEvent](#triggerevent) #### JavaScript libraries This is an array of Project paths which will be downloaded and then executed in order within the widget, or an array of URLs that is allowed by both CORS and CSP policy (where you can mix and match). Downloading will use the browser, so the URL must be allowed by the CORS and CSP policy. If you wish to host libraries within Foundry, you can either host them in Blobster and use the cookie-authenticated APIs or put the script in the asset server. Making changes to this field will cause the entire widget to reload and refresh. (The libraries can themselves invoke the `SlateFunctions` to allow them to interact with the Slate-specific functionality). :::callout{theme="warning"} Imported JavaScript libraries must assign their functionality to a globally available scope to be referenced via the JavaScript tab (such as being bundled as a UMD module, or explicitly assigning functionality to the `window`). ::: ##### Example To use the d3.min.js library, download it from `https://d3js.org/d3.v5.min.js` and save it to a Foundry directory by dragging-and-dropping the file. Once the file is uploaded, copy its Project path and paste it into the library array. `["/Users/admin/d3.min.js"]` You can alternatively use the RID for the resource. For example: `["ri.blobster.main.code.7a4a12a8-e9f5-46ef-8008-5c3f4bbd4abc"]` You can obtain the Project path/RID for a resource by looking at its file's directory. Alternatively, you can right-click on the file once while in its folder and copy the Location / RID. ### HTML/CSS tab ![image](../../../assets/2628e0e27ca4a4e3dbfa59be3124ef4f654c7bf46f80b8bec3b5c90965bc9b3a.webp) #### HTML This is a string of HTML that will get rendered when the widget loads. :::callout{theme="warning"} Do not use Handlebars here. The HTML tag ` tags is refactored out and placed into the JavaScript section. * Use Slate functions for your interactions: * Pass any data you need into the custom Code Sandbox from Slate using `SlateFunctions.getState`. * To convey an interaction within the widget to the rest of Slate, you can tag `SlateFunctions.triggerEvent` to the function. * To have the widget respond to an Action emanating from the rest of Slate, you can tag `SlateFunctions.onAction` to the function. *** ## File Import The File Import widget enables users to upload files which can then be referenced and processed in the Slate application. This allows applications to incorporate file-based data and functionality directly within Slate. ### Properties |Attribute |Description |Type |Required |Changed By | |--- |--- |--- |--- |--- | |buttonCssClasses |CSS classes to apply to the browse button |string\[] |Yes |Direct Edit | |buttonText |The text of the browse button |string |Yes |Direct Edit | |message |The message to display in the upload pane |string |Yes |Direct Edit | |fileNames |The names of the files that the user imported |string\[] |Yes |User Interaction | |fileTypes |The MIME types of the files that the user imported |string\[] |Yes |User Interaction | |fileContents |The user's imported files as binary strings |string\[] |Yes |User Interaction | |fileDataUrls |The user's imported files as base64-encoded data URLs |string\[] |Yes |User Interaction | *** ## Iframe The following tables offer usage details about the properties available to iframe widgets. Several examples follow the tables. :::callout{theme="warning"} If you are embedding something that is loaded via workspace, you need to add `?embedded=true` to the end of the URL ::: ### Properties |Attribute |Description |Type |Required |Changed By | |--- |--- |--- |--- |--- | |uri |The iframe src URI |string |No |Direct Edit | **Actions** | Action Name | Description | | - | - | | sendMessage | Triggering this Action causes the widget to send a message to the inner iframe in the format of `{ source: ‘slate-iframe-action’, message: {…}}`. | | reload | Triggering this Action reloads the iframe. | **Events** | Event Name | Description | | - | - | | getMessage | This event is triggered when the widget’s inner iframe post message to Slate is in the format of `{ target: ‘slate-iframe-event’, message: {…}}`. |