Skip to content

Commit

Permalink
Add tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 4, 2022
1 parent a154d55 commit df9dabd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type grapesjs from 'grapesjs';
import FileSaver from 'file-saver';
import JSZip from 'jszip';

type Editor = grapesjs.Editor;

export type PluginOptions = {
/**
* Type id used to register the new storage.
Expand Down Expand Up @@ -31,7 +33,7 @@ export type PluginOptions = {
/**
* Use a function to generate the filename, eg. `filename: editor => 'my-file.zip',`
*/
filename?: (editor: grapesjs.Editor) => string,
filename?: (editor: Editor) => string,

/**
* Callback to execute once the export is completed
Expand Down Expand Up @@ -76,14 +78,14 @@ const plugin: grapesjs.Plugin<PluginOptions> = (editor, opts = {}) => {
addExportBtn: true,
btnLabel: 'Export to ZIP',
filenamePfx: 'grapesjs_template',
filename: null,
filename: undefined,
done: () => {},
onError: console.error,
root: {
css: {
'style.css': editor => editor.getCss(),
'style.css': (editor: Editor) => editor.getCss(),
},
'index.html': editor =>
'index.html': (editor: Editor) =>
`<!doctype html>
<html lang="en">
<head>
Expand All @@ -93,7 +95,7 @@ const plugin: grapesjs.Plugin<PluginOptions> = (editor, opts = {}) => {
<body>${editor.getHtml()}</body>
</html>`,
},
isBinary: null,
isBinary: undefined,
...opts,
};

Expand All @@ -104,6 +106,7 @@ const plugin: grapesjs.Plugin<PluginOptions> = (editor, opts = {}) => {
const onError = opts.onError || config.onError;
const root = opts.root || config.root;

// @ts-ignore
this.createDirectory(zip, root)
.then(async () => {
const content = await zip.generateAsync({ type: 'blob' });
Expand Down Expand Up @@ -144,9 +147,11 @@ const plugin: grapesjs.Plugin<PluginOptions> = (editor, opts = {}) => {
const typeOf = typeof content;

if (typeOf === 'string') {
// @ts-ignore
this.createFile(zip, name, content);
} else if (typeOf === 'object') {
const dirRoot = zip.folder(name);
// @ts-ignore
await this.createDirectory(dirRoot, content);
}
}
Expand All @@ -158,11 +163,12 @@ const plugin: grapesjs.Plugin<PluginOptions> = (editor, opts = {}) => {
// Add button inside export dialog
if (config.addExportBtn) {
const btnExp = document.createElement('button');
btnExp.innerHTML = config.btnLabel;
btnExp.innerHTML = config.btnLabel!;
btnExp.className = `${pfx}btn-prim`;

editor.on('run:export-template', () => {
editor.Modal.getContentEl().appendChild(btnExp);
const el = editor.Modal.getContentEl();
el?.appendChild(btnExp);
btnExp.onclick = () => {
editor.runCommand(commandName);
};
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./node_modules/grapesjs-cli/src/template/tsconfig.json",
"include": ["src"]
}

0 comments on commit df9dabd

Please sign in to comment.