From 7dd2ceba60c32c0565fe6f0a68d64512d4e7a202 Mon Sep 17 00:00:00 2001 From: Okiki Date: Thu, 16 Sep 2021 16:08:38 +0000 Subject: [PATCH] feat: add a new monaco-editor for resulting bundle * update docs --- README.md | 12 +++++ src/css/app.scss | 71 +++++++++++++++++++++++++++++ src/css/components/_monaco.scss | 43 +++++++++++++---- src/css/components/_navbar.scss | 70 ---------------------------- src/pug/components/product-hunt.pug | 11 +++-- src/pug/index.pug | 33 ++++++++------ src/ts/index.ts | 32 +++++++------ src/ts/modules/monaco.ts | 25 +++++++--- 8 files changed, 177 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index 9ac4fab..fce0b59 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,15 @@ If there is something I missed, a mistake, or a feature you would like added ple **bundle** uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) as the style of commit, and the [Commitizen CLI](http://commitizen.github.io/cz-cli/) to make commits easier. You can join the discussion on [github discussions](https://github.com/okikio/bundle/discussions). + +--- + +You can now use search queries in **bundle**, all you need to do is add this to the url +`?q={packages}&treeshake={methods to treeshake}` + +e.g. +You want `react`, `react-dom`, `vue`, and `@okikio/animate`, but only want the `Animate` and `toStr` methods exported from `@okikio/animate`. + +You would add this to the url [bundle.js.org/?q=react,react-dom,vue,@okikio/animate&treeshake=[*],[*],[*],[Animate,toStr]](https://bundle.js.org/?q=react,react-dom,vue,@okikio/animate&treeshake=[*],[*],[*],[Animate,toStr]) + +If you only want a couple packages and don't care to treeshake, then all you need is something like this, [bundle.js.org?q=react,react-dom,vue,@okikio/animate](https://bundle.js.org/?q=react,react-dom,vue,@okikio/animate) diff --git a/src/css/app.scss b/src/css/app.scss index 0eb3f93..041fd76 100644 --- a/src/css/app.scss +++ b/src/css/app.scss @@ -177,3 +177,74 @@ footer.footer { @apply p-5 align-middle sm:max-w-screen-md; } } + +#copy-input { + position: absolute; + top: -50px; + left: -50px; + opacity: 0; + // width: 1px; + // visibility: hidden; +} + +.navbar-toggle, +.theme-toggle, +.btn-icon { + @apply rounded-md; + @apply mr-1 w-10 h-10 text-blue-500 bg-gray-100 hover:bg-gray-200 active:bg-blue-200; + @apply dark:text-blue-400 dark:bg-quaternary; + @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; + @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; +} + +.btn-icon { + @apply bg-white hover:bg-gray-100 active:bg-blue-200; + @apply dark:text-blue-400 dark:bg-tertiary; + @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; + @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; +} + +.btn-highlight { + @apply rounded-md mr-1 inline-block; + @apply text-blue-500 bg-gray-100 hover:bg-gray-200 active:bg-blue-200; + @apply dark:text-blue-400 dark:bg-quaternary; + @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; + @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; +} + +.btn { + transition: opacity ease 0.25s; + @apply px-3 py-2 rounded-md no-underline hover:bg-gray-200; + @apply text-blue-600 dark:text-blue-400 dark:hover:bg-quaternary; + + &.active { + @apply bg-blue-700 text-white hover:bg-blue-500; + @apply dark:bg-blue-400 dark:text-black dark:hover:bg-blue-500; + } + + &:hover { + @apply bg-opacity-60; + } +} + +.btn-share { + @apply rounded-md ml-2; + @apply text-blue-500 bg-gray-100 hover:bg-gray-200; + @apply dark:text-blue-400 dark:bg-quaternary; + @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; + @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; +} + +.btn, +.navbar-toggle, +.theme-toggle { + @apply mr-1; +} + +.theme-toggle { + @apply rounded-md; + @apply w-10 h-10 text-blue-500 bg-gray-100 hover:bg-gray-200; + @apply dark:text-blue-400 dark:bg-quaternary; + @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; + @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; +} \ No newline at end of file diff --git a/src/css/components/_monaco.scss b/src/css/components/_monaco.scss index a8b9dcb..232aea0 100644 --- a/src/css/components/_monaco.scss +++ b/src/css/components/_monaco.scss @@ -1,21 +1,44 @@ -#app { +.flex-wrapper { + @apply gap-3 w-full relative pb-2 mb-8 container max-w-screen-xl; + display: grid; + grid-template-columns: auto; + grid-auto-flow: column; + grid-auto-rows: 1fr; + min-height: 400px - 56px; + resize: vertical; + overflow: hidden; + + @screen lt-md { + min-height: 350px - 56px; + } +} + +.app { @apply border border-gray-200 dark:border-transparent; @apply rounded-lg shadow-lg; - @apply bg-white relative block mb-8; + @apply bg-white relative block; padding-top: 15px; padding-bottom: 15px; - height: 400px - 56px; + height: 100%; - resize: vertical; + resize: horizontal; overflow: hidden; +} - @screen lt-md { - height: 350px - 56px; - } +.app#output { + // resize: vertical; + // height: 100%; } .push-to-side { - @apply flex align-middle py-2 justify-end; + @apply flex align-middle py-2 justify-end flex-1; + flex-wrap: nowrap; +} + +.push-to-side-overflow { + overflow-x: auto; + position: relative; + display: flex; } .file-size { @@ -23,7 +46,7 @@ @apply text-center flex justify-center items-center; @apply bg-gray-200 dark:bg-quaternary; @apply text-gray-500 dark:text-secondary; - min-width: theme("spacing.48"); + min-width: theme("spacing.40"); min-height: theme("spacing.12") } @@ -45,7 +68,7 @@ animation: spin 1s linear infinite; } -.dark #app { +.dark .app { background-color: #24292e; } diff --git a/src/css/components/_navbar.scss b/src/css/components/_navbar.scss index 7fd4f1a..a22b71e 100644 --- a/src/css/components/_navbar.scss +++ b/src/css/components/_navbar.scss @@ -121,76 +121,6 @@ } } -.navbar-toggle, -.theme-toggle, -.btn-icon { - @apply rounded-md; - @apply mr-1 w-10 h-10 text-blue-500 bg-gray-100 hover:bg-gray-200 active:bg-blue-200; - @apply dark:text-blue-400 dark:bg-quaternary; - @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; - @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; -} - -.btn-icon { - @apply bg-white hover:bg-gray-100 active:bg-blue-200; - @apply dark:text-blue-400 dark:bg-tertiary; - @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; - @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; -} - -.btn-highlight { - @apply rounded-md mr-1 inline-block; - @apply text-blue-500 bg-gray-100 hover:bg-gray-200 active:bg-blue-200; - @apply dark:text-blue-400 dark:bg-quaternary; - @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; - @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; -} - -.btn { - transition: opacity ease 0.25s; - @apply px-3 py-2 rounded-md no-underline hover:bg-gray-200; - @apply text-blue-600 dark:text-blue-400 dark:hover:bg-quaternary; - - &.active { - @apply bg-blue-700 text-white hover:bg-blue-500; - @apply dark:bg-blue-400 dark:text-black dark:hover:bg-blue-500; - } - - &:hover { - @apply bg-opacity-60; - } -} - -.btn-share { - @apply rounded-md ml-2; - @apply text-blue-500 bg-gray-100 hover:bg-gray-200; - @apply dark:text-blue-400 dark:bg-quaternary; - @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; - @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; -} - -#btn-share-input { - position: absolute; - top: -50px; - left: -50px; - // width: 1px; - // visibility: hidden; -} - -.btn, -.navbar-toggle, -.theme-toggle { - @apply mr-1; -} - -.theme-toggle { - @apply rounded-md; - @apply w-10 h-10 text-blue-500 bg-gray-100 hover:bg-gray-200; - @apply dark:text-blue-400 dark:bg-quaternary; - @apply dark:hover:bg-gray-800 dark:active:bg-gray-700; - @apply focus-visible:border-blue-600 focus-visible:ring-4 focus:rounded-md; -} - .navbar.shadow .to-top { @apply opacity-100; } \ No newline at end of file diff --git a/src/pug/components/product-hunt.pug b/src/pug/components/product-hunt.pug index 16e6bb4..498bc10 100644 --- a/src/pug/components/product-hunt.pug +++ b/src/pug/components/product-hunt.pug @@ -1,6 +1,7 @@ mixin product-hunt - a#product-hunt(href='https://www.producthunt.com/posts/bundle-6?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-bundle-6', target='_blank' rel="noopener")&attributes(attributes) - figure(width='250', height='54') - img.dark(src='https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=300568&theme=dark' alt="" loading="eager") - img(src='https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=300568&theme=light' alt="" loading="eager") - figcaption A link to bundle.js.org's Product Hunt page; a small public display of what bundle.js.org is all about \ No newline at end of file + #product-hunt&attributes(attributes) + a(href='https://www.producthunt.com/posts/bundle-6?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-bundle-6', target='_blank' rel="noopener") + figure(width='250', height='54') + img.dark(src='https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=300568&theme=dark' alt="" loading="eager") + img(src='https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=300568&theme=light' alt="" loading="eager") + figcaption A link to bundle.js.org's Product Hunt page; a small public display of what bundle.js.org is all about \ No newline at end of file diff --git a/src/pug/index.pug b/src/pug/index.pug index 8b4b0d6..f53a5a0 100644 --- a/src/pug/index.pug +++ b/src/pug/index.pug @@ -4,6 +4,8 @@ block preload link(rel="stylesheet", href="./js/monaco.min.css") block content + input(type="text" id="copy-input" tabindex="-1" aria-hidden="true") + .container header h1 bundle @@ -20,24 +22,29 @@ block content i.icon clear .search-results-container - - .push-to-side - #bundle-time - .flex.flex-1 - button.btn#run(type='button') Run - button.btn.btn-share#share(type='button') Share - input(type="text" id="btn-share-input" tabindex="-1" aria-hidden="true") - .file-size Wait... - #app + .push-to-side-overflow + .push-to-side + #bundle-time + .flex.flex-1 + button.btn#run(type='button') Run + button.btn.btn-share#share(type='button') Share + .file-size Wait... + .flex-wrapper + .app + .center-container + .loading + #editor + + .app#output .center-container .loading #editor - + .container +product-hunt.place-content-center - p * Check the console for error messages and bundled code. - p * Every 10 results the console will be cleared. - br + //- p * Check the console for error messages and bundled code. + //- p * Every 10 results the console will be cleared. + //- br p * Note: Treeshaking is available, but since esbuild and rollup doesn't have access to each packages package.json, it assumes that there are sideEffects. br diff --git a/src/ts/index.ts b/src/ts/index.ts index b37d674..42138f8 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -56,8 +56,9 @@ let bundleFromUrl = () => { } let editor: Editor.IStandaloneCodeEditor; +let output: Editor.IStandaloneCodeEditor; (async () => { - let loadingContainerEl = document.querySelector(".center-container"); + let loadingContainerEl = Array.from(document.querySelectorAll(".center-container")); let Fade = animate({ target: loadingContainerEl, opacity: [1, 0], @@ -69,13 +70,13 @@ let editor: Editor.IStandaloneCodeEditor; // Monaco Code Editor let Monaco = await import("./modules/monaco"); - editor = Monaco.build(); + [editor, output] = Monaco.build(); // Fade away the loading screen Fade.play(); await Fade; - loadingContainerEl?.remove(); + loadingContainerEl.forEach(x => x?.remove()); Fade.stop(); loadingContainerEl = null; @@ -93,10 +94,10 @@ let editor: Editor.IStandaloneCodeEditor; editor.onDidChangeModelContent(debounce((e) => { window.history.replaceState({}, '', generateShareLink()); - }, 300)) + }, 300)); const shareBtn = document.querySelector(".btn-share#share") as HTMLButtonElement; - const shareInput = document.querySelector("#btn-share-input") as HTMLInputElement; + const shareInput = document.querySelector("#copy-input") as HTMLInputElement; shareBtn?.addEventListener("click", () => { shareInput.value = generateShareLink(); shareInput.select(); @@ -200,16 +201,17 @@ BundleEvents.on({ count = 0; } - let splitInput = value.split("\n"); - console.groupCollapsed(`${size} =>`, `${splitInput[0]}${splitInput.length > 1 ? "\n..." : ""}`); - console.groupCollapsed("Input Code: "); - console.log(value); - console.groupEnd(); - console.groupCollapsed("Bundled Code: "); - console.log(content); - console.groupEnd(); - console.groupEnd(); - count++; + // let splitInput = value.split("\n"); + // console.groupCollapsed(`${size} =>`, `${splitInput[0]}${splitInput.length > 1 ? "\n..." : ""}`); + // console.groupCollapsed("Input Code: "); + // console.log(value); + // console.groupEnd(); + // console.groupCollapsed("Bundled Code: "); + // console.log(content); + // console.groupEnd(); + // console.groupEnd(); + // count++; + output?.setValue?.(content); bundleTime.textContent = `Bundled ${timeFormatter.format((Date.now() - start) / 1000, "seconds")}`; fileSizeEl.textContent = `` + size; diff --git a/src/ts/modules/monaco.ts b/src/ts/modules/monaco.ts index 294831c..c41486d 100644 --- a/src/ts/modules/monaco.ts +++ b/src/ts/modules/monaco.ts @@ -123,8 +123,11 @@ export const debounce = (func: Function, timeout = 300) => { }; export const build = () => { - let inputEl = document.querySelector("#editor") as HTMLElement; + let inputEl = document.querySelector(".app #editor") as HTMLElement; + let outputEl = document.querySelector(".app#output #editor") as HTMLElement; + let inputEditor: Editor.IStandaloneCodeEditor; + let outputEditor: Editor.IStandaloneCodeEditor; languages.typescript.typescriptDefaults.setDiagnosticsOptions({ noSemanticValidation: true, @@ -139,9 +142,12 @@ export const build = () => { "module": languages.typescript.ModuleKind.ES2015, "noEmit": true, "lib": [ - "esnext", - "dom", - "node" + "ES2021", + "DOM", + "DOM.Iterable", + "WebWorker", + "ESNEXT", + "NODE" ], "exclude": ["node_modules"], "resolveJsonModule": true, @@ -192,7 +198,7 @@ export const build = () => { // @ts-ignore Editor.defineTheme("light", GithubLight); - inputEditor = Editor.create(inputEl, { + let editorOpts = { value: initialValue, minimap: { enabled: false, @@ -211,11 +217,16 @@ export const build = () => { language: "typescript", lineNumbers: "on" - }); + }; + + inputEditor = Editor.create(inputEl, editorOpts as Editor.IStandaloneEditorConstructionOptions); + outputEditor = Editor.create(outputEl, Object.assign({}, editorOpts, { + value: `// Output` + }, ) as Editor.IStandaloneEditorConstructionOptions); document.addEventListener("theme-change", () => { Editor.setTheme(themeGet()); }); - return inputEditor; + return [inputEditor, outputEditor]; }; -- knotmirror 0.0.1