From 318592ba22b695c2996d9d2e6a793b299a36b274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Fri, 17 Dec 2021 13:49:45 +0100 Subject: [PATCH] demos: Add setup for plain js demos (#2288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add basic js demo * improve js demos * change demo button * fix js demos on build * add tailwind experiment * docs: replace tailwind demo Co-authored-by: Philipp Kühn --- demos/preview/Demo.vue | 2 +- demos/setup/js.ts | 11 +++ demos/src/Experiments/Tailwind/JS/index.html | 54 +++++++++++ demos/vite.config.ts | 99 ++++++++++++++++++-- docs/guide/styling.md | 9 +- 5 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 demos/setup/js.ts create mode 100644 demos/src/Experiments/Tailwind/JS/index.html diff --git a/demos/preview/Demo.vue b/demos/preview/Demo.vue index 453f7cbf..bb587cb8 100644 --- a/demos/preview/Demo.vue +++ b/demos/preview/Demo.vue @@ -114,7 +114,7 @@ export default { sources: {}, currentTab: null, currentFile: null, - tabOrder: ['React', 'Vue'], + tabOrder: ['React', 'Vue', 'JS'], debugJSON: null, showDebug: false, } diff --git a/demos/setup/js.ts b/demos/setup/js.ts new file mode 100644 index 00000000..5b0fc9d8 --- /dev/null +++ b/demos/setup/js.ts @@ -0,0 +1,11 @@ +import 'iframe-resizer/js/iframeResizer.contentWindow' +import { debug } from './helper' +import './style.scss' + +export default function init(name: string, source: any) { + // @ts-ignore + window.source = source + document.title = name + + debug() +} diff --git a/demos/src/Experiments/Tailwind/JS/index.html b/demos/src/Experiments/Tailwind/JS/index.html new file mode 100644 index 00000000..cfb3280c --- /dev/null +++ b/demos/src/Experiments/Tailwind/JS/index.html @@ -0,0 +1,54 @@ + + + + + +
+ + + diff --git a/demos/vite.config.ts b/demos/vite.config.ts index 81452c3b..f35cf1a6 100644 --- a/demos/vite.config.ts +++ b/demos/vite.config.ts @@ -39,6 +39,88 @@ export default defineConfig({ vue(), reactRefresh(), + { + name: 'html-transform', + transformIndexHtml: { + enforce: 'pre', + transform(html: string, context) { + const dir = dirname(context.path) + const data = dir.split('/') + const demoCategory = data[2] + const demoName = data[3] + + if (dir.endsWith('/JS')) { + return { + html: ` + + + + + + + + ${html} + + + + `, + tags: [], + } + } + + if (dir.endsWith('/Vue')) { + return { + html: ` + + + + + + + +
+ + + + `, + tags: [], + } + } + + if (dir.endsWith('/React')) { + return { + html: ` + + + + + + + +
+ + + + `, + tags: [], + } + } + }, + }, + }, + { name: 'raw', resolveId(id, importer) { @@ -97,13 +179,16 @@ export default defineConfig({ load(id) { if (id.startsWith('source!')) { const path = id.split('!!')[0].replace('source!', '') - const files = fg.sync(`${path}/**/*`, { - ignore: [ - '**/index.html', - '**/*.spec.js', - '**/*.spec.ts', - ], - }) + const ignore = [ + '**/*.spec.js', + '**/*.spec.ts', + ] + + if (!path.endsWith('/JS')) { + ignore.push('**/index.html') + } + + const files = fg.sync(`${path}/**/*`, { ignore }) .map(filePath => { const name = filePath.replace(`${path}/`, '') diff --git a/docs/guide/styling.md b/docs/guide/styling.md index 14feab3b..9d20c1c4 100644 --- a/docs/guide/styling.md +++ b/docs/guide/styling.md @@ -77,13 +77,7 @@ new Editor({ ### With Tailwind CSS The editor works fine with Tailwind CSS, too. Find an example that’s styled with the `@tailwindcss/typography` plugin below. - +https://embed.tiptap.dev/preview/Experiments/Tailwind ## Option 3: Customize the HTML Or you can customize the markup for extensions. The following example will make a custom bold extension that doesn’t render a `` tag, but a `` tag: @@ -108,4 +102,3 @@ new Editor({ ``` You should put your custom extensions in separate files, but I think you got the idea. -