From 38703bbe2a4258b5ad7828bf04c46d3f0e8d355c Mon Sep 17 00:00:00 2001 From: Sami Jaber Date: Tue, 21 May 2024 10:48:40 -0400 Subject: [PATCH 1/3] init playground options --- packages/docs/src/components/code-rotator.tsx | 6 +- .../docs/src/components/options-modal.tsx | 110 ++++++++++++++++++ packages/docs/src/routes/playground/index.tsx | 92 +++++++++------ packages/docs/src/services/compile.ts | 63 +++------- 4 files changed, 190 insertions(+), 81 deletions(-) create mode 100644 packages/docs/src/components/options-modal.tsx diff --git a/packages/docs/src/components/code-rotator.tsx b/packages/docs/src/components/code-rotator.tsx index 1da2eda97c..26ed461708 100644 --- a/packages/docs/src/components/code-rotator.tsx +++ b/packages/docs/src/components/code-rotator.tsx @@ -245,7 +245,11 @@ export const CodeRotator = component$((props: { class: ClassList }) => { const compileAll = $(async (code: string) => { await Promise.allSettled( frameworkExamples.map(async (framework) => { - const output = await compile(code, framework as OutputFramework, 'jsx'); + const output = await compile({ + code, + output: framework as OutputFramework, + inputSyntax: 'jsx' + }); (outputs as any)[framework] = output.replace( /\n?\n?import { useStore } from "..";\n?/g, '', diff --git a/packages/docs/src/components/options-modal.tsx b/packages/docs/src/components/options-modal.tsx new file mode 100644 index 0000000000..b3c51d1dd9 --- /dev/null +++ b/packages/docs/src/components/options-modal.tsx @@ -0,0 +1,110 @@ +import { ToVueOptions } from '@builder.io/mitosis'; +import { $, Signal, component$, useSignal, useVisibleTask$ } from '@builder.io/qwik'; +import { OutputFramework } from '~/services/compile'; +import Select from './select'; + +type Option = {name: keyof O} & ({ + type: 'boolean'; + default: boolean +} | { + type: 'enum'; + enum: Array; + default: string; +}); + +const DEFAULT_OPTIONS: Option[] = [{ + name: 'typescript', + type: 'boolean', + default: true +}] + +type Dictionary = { + [index: string]: T +} +type Options = Dictionary + +export const getDefaultOptions = (target: OutputFramework) => { + const opts = getOptions(target) + const opt: Options = {} + + for (const o of opts) { + opt[o.name] = o.default + } + + return opt +} + + +const _getOptions = (target:OutputFramework) => { + switch (target) { + case 'vue': + const o: Array> = [{ + name: 'casing', + type: 'enum', + enum: ['pascal', 'kebab'], + default: 'pascal' + }, + { + name: 'api', + type: 'enum', + enum: ['options', 'composition'], + default: 'composition' + }] + + return o + + + default: + return [] + } +} +const getOptions = (target:OutputFramework) => { + return [ + ...DEFAULT_OPTIONS, + ..._getOptions(target) + ] +} + +export default component$( + ({options, target}: { options: Options, target:Signal }) => { + const showModal = useSignal(true); + + useVisibleTask$(() => { + if (target.value === 'angular') { + showModal.value = false + } + }) + + + + return ( +
+ + + {showModal.value &&
+

{target.value} settings.

+ +
+ {getOptions(target.value).map(option => { + console.log('consuming option: ', {option, options}); + + return
+
{option.name}
+
{option.type === 'boolean' ?
{ + console.log('before: ', options.value); + + options[option.name] = !options[option.name] + + console.log('after: ', options.value); + })} >
: (outputOneFramework.value = framework)} + onChange$={(framework: any) => { + outputOneFramework.value = framework; + Object.assign(optionsOne, getDefaultOptions(framework)) + }} options={outputs} - /> + />
)}
@@ -284,20 +303,27 @@ export default component$(() => {
)}
-
+
{visible.value && ( // Workaround weird bug where this doesn't render correctly // server side +
+ +