Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Archived] Initial Svelte JS support #164

Draft
wants to merge 4 commits into
base: archive-at-2023-12-for-grida-main-repo-editor-migration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
62 changes: 62 additions & 0 deletions packages/builder-config/framework-svelte/svelte-config-styling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
///
/// this configuration is work-in-progress.
///

export type SvelteStylingOption =
| SvelteStyleFragment
| SvelteInlineCssOption
| SvelteCssInJsOption;

type SvelteInlineCssOption =
| SvelteInlineCssWithHtmlStandard
| SvelteInlineCssWithStyleDirective;

type SvelteCssInJsOption = SvelteEmotionCSS;

interface SvelteEmotionCSS {}

/**
* inline css styling in svelte with html standard way.
*
* e.g. 👇
* ```html
* <div style="background: black"></div>
* ```
*/
export interface SvelteInlineCssWithHtmlStandard {
type: "inline-css-standard";
}

/**
*
* e.g. 👇
* ```html
* <div
* style:position="absolute"
* style:top={position === 'absolute' ? '20px' : null}
* style:pointer-events={pointerEvents ? null : 'none'}
* ></div>
* ```
*
* Learn more - [svelte style directive RFC](https://github.com/sveltejs/rfcs/blob/master/text/0008-style-directives.md)
*/
export interface SvelteInlineCssWithStyleDirective {
type: "inline-css-with-style-directive";
}

/**
* styling using standard scoped css under <style> tag in svelte.
*
* e.g. 👇
* ```html
* <p style="color: {color}; --opacity: {bgOpacity};">This is a paragraph.</p>
* <style>
* p {
* font-family: "Comic Sans MS", cursive;
* background: rgba(255, 62, 0, var(--opacity));
* }
* </style>
* ```
*/
// TODO: give a better clear name
export interface SvelteStyleFragment {}
4 changes: 4 additions & 0 deletions packages/builder-web-svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@web-builder/svelte",
"version": "0.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
NoStyleJSXElementConfig,
StyledComponentJSXElementConfig,
} from "@web-builder/styled";
import { JSXChildLike } from "coli";
import { JSX, JSXChildLike, Snippet } from "coli";
import { StylesRepository } from "@web-builder/core/builders";
import { create_duplication_reduction_map } from "@web-builder/styled";
import { buildCSSStyleData, CSSProperties } from "@coli.codes/css";
Expand Down Expand Up @@ -181,7 +181,7 @@ export class HtmlIdCssModuleBuilder {

const final = html_render({
css: this.partStyles(),
body: strfied_body,
body: this.partBody(),
});

return final;
Expand Down Expand Up @@ -223,20 +223,24 @@ function injectIdToJsx(jsx: JSXElementLike, id: string) {
}
}

const html_render = ({ css, body }: { css: string; body: string }) => {
const html_render = ({ css, body }: { css: string; body: JSXChildLike }) => {
const indenter = (s: string, tabs: number = 0) =>
s.replace(/\n/g, "\n" + "\t".repeat(tabs));
return `<!DOCTYPE html>
<html>
<head>
<style>
${indenter(css, 3)}
</style>
</head>
<body>
${indenter(body, 2)}
</body>
</html>`;

const html = JSX.html({
children: [
JSX.head(
// style
JSX.style(Snippet.fromStatic(indenter(css, 3)) as any)
),
// body
JSX.body(body),
],
});

return stringfy(html.make(), {
language: "jsx", // use jsx for html also.
});
};

/**
Expand Down