├── .eslintrc ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── dist ├── index.d.ts ├── index.esm.js ├── index.esm.js.map ├── index.js └── index.js.map ├── json.d.ts ├── package.json ├── rollup.config.js ├── src └── index.ts └── tsconfig.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "browser": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parser": "typescript-eslint-parser", 8 | "parserOptions": { 9 | "ecmaVersion": 2018 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .localized 3 | node_modules 4 | .vscode 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Geoffrey Goodman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plunker SDK 2 | 3 | A set of tools for interacting with the Plunker platform that allow you to: 4 | 5 | 1. Generate dynamic embedded Plunks and show these in target frames or mount these in target DOM elements. 6 | 7 | ## Usage 8 | 9 | Mount the embedded view of Plunker inside the 'embed' element with custom files, title and tags 10 | 11 | ```js 12 | import { showDynamicEmbed } from '@plnkr/sdk'; 13 | 14 | // Generate the files for the dynamic plunk. This could easily 15 | // be generated on the fly by your application. 16 | const files = [ 17 | { 18 | pathname: 'index.html', 19 | content: '

Hello world

', 20 | }, 21 | ]; 22 | 23 | showDynamicEmbed( 24 | { 25 | files, 26 | title: 'Hello world example', 27 | tags: ['hello', 'world'], 28 | }, 29 | { 30 | deferRun: true, // Don't immediately run the preview 31 | show: ['index.html', 'preview'], // Open the index file and preview panes 32 | parentEl: 'embed', // Mount the embed in the #embed element 33 | } 34 | ); 35 | ``` 36 | 37 | Open the embedded view of Plunker in a new window with custom files, title and tags 38 | 39 | ```js 40 | import { showDynamicEmbed } from '@plnkr/sdk'; 41 | 42 | // Generate the files for the dynamic plunk. This could easily 43 | // be generated on the fly by your application. 44 | const files = [ 45 | { 46 | pathname: 'index.html', 47 | content: '

Hello world

', 48 | }, 49 | ]; 50 | 51 | showDynamicEmbed( 52 | { 53 | files, 54 | title: 'Hello world example', 55 | tags: ['hello', 'world'], 56 | }, 57 | { 58 | deferRun: true, // Don't immediately run the preview 59 | show: ['index.html', 'preview'], // Open the index file and preview panes 60 | target: '_blank', // Mount the embed in the #embed element 61 | } 62 | ); 63 | ``` 64 | 65 | ## API 66 | 67 | ### `showDynamicEditor(projectSpec, options)` 68 | 69 | Create an embedded Plunk whose content is dynamically generated and either mount it to a DOM element or open it in a new or existing iframe / window where: 70 | 71 | * `projectSpec` - An object having the following properties: 72 | * `files` - An array of objects having the following properties: 73 | * `pathname` - The full path of the file. 74 | * `content` - The file's content. 75 | * `encoding` - (optional) The format in which the content is encoded (utf8 / base64). 76 | * `title` - (optional) The suggested title for the Plunk. 77 | * `tags` - (optional) An array of suggested string tags for the Plunk. 78 | * `options` - (optional) An object having the following properties: 79 | * `editorUrl` - (optional) The string url of the instance of the Plunker editor. This is useful for local testing. 80 | * `parentEl` - (optional) The string element id or the DOM element in which the embed should be mounted. This is useful for generating dynamic embeds that will be shown on the same page. This option is incompatible with the `target` option. 81 | * `preview` - (optional) A string representing the file that should be loaded in the default preview pane instead of using Plunker's own heuristics. 82 | * `show` - (optional) An array of strings representing panes to show. These strings can be pathnames (or partial pathnames, in which the best fuzzy match will be chosen) or the string `'preview'` to show the preview pane. These panes will be opened in the order of the array from left to right. 83 | * `sidebar` - (optional) The sidebar pane to show by default. Can be the string `'tree'` for the file tree or `'config'` for the configuration pane. 84 | * `target` - (optional) The target frame in which the embed should be displayed. This can be the `name` of an `