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

New flags support h1 - h6 element preference, explicit width/height declaration flags #106

Merged
merged 25 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6960f86
update flag docs placement
softmarshmallow Dec 29, 2021
165ed07
update ci scripts for flags docs gen
softmarshmallow Dec 30, 2021
68753b9
(doc) add h1-h6 flags docs
softmarshmallow Dec 30, 2021
9679558
(doc) artwork flag docs
softmarshmallow Dec 30, 2021
545358d
(doc) w&h flags docs
softmarshmallow Dec 30, 2021
818ee2b
add h1~h6 flag definition & parsing with alias keys
softmarshmallow Dec 30, 2021
00383af
split flag parsing & type declarations
softmarshmallow Dec 30, 2021
10ebba1
add h1 - h6 element tagging support for html based web frameworks wi…
softmarshmallow Dec 30, 2021
aea9c22
add meta to h1-h6 docs (stage info)
softmarshmallow Dec 30, 2021
0dcce07
add mimic heading level parsing safety for flags
softmarshmallow Dec 30, 2021
c45109d
fix build error;
softmarshmallow Dec 30, 2021
a1ce56a
add `span` and `p` support wih flags - text element preference flag a…
softmarshmallow Dec 30, 2021
827d0f4
add flags proposal docs (as-br, as-char, as-text-group, as-nbsp)
softmarshmallow Dec 30, 2021
be8c1e4
(mimic) fix build issue
softmarshmallow Dec 30, 2021
040077d
(docs/proposal) update docs for advanced in-line min-max value assign…
softmarshmallow Dec 30, 2021
1635101
improve docs
softmarshmallow Dec 30, 2021
e83e980
update alias ex/import
softmarshmallow Dec 30, 2021
5ea5147
grouping alias, using flag-parser's alias option
softmarshmallow Dec 30, 2021
ec21bf3
remove export of secondary alias keys
softmarshmallow Dec 30, 2021
2bfc127
add types support for flags (internal)
softmarshmallow Dec 30, 2021
1688d16
update widgets wh type to have dynamic length, not static number by d…
softmarshmallow Dec 30, 2021
bd20fbe
initially add support for wh declaration flag. (multiple flags not su…
softmarshmallow Dec 30, 2021
558704a
add multiple inline wh flag declaration merging
softmarshmallow Dec 31, 2021
6020248
add final wh min max support - add property to web widgets
softmarshmallow Dec 31, 2021
cefa0df
add `--fix-width` and `--fix-height` flag support
softmarshmallow Dec 31, 2021
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
5 changes: 5 additions & 0 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: run pre-deploy (build docs and more)
run: |
chmod +x ./scripts/docs-deploy/pre-deploy.sh
./scripts/docs-deploy/pre-deploy.sh
shell: bash
- name: copy docs to gridaco/grida.co
uses: DevOpenWRT-Router/github-action-push-to-another-repository@main
env:
Expand Down
7 changes: 7 additions & 0 deletions docs/flags/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Learn more at scripts/docs-copy/flags-api-docs.js
# custom
----ignore.md
---custom.md

# flags api docs
--*.md
5 changes: 5 additions & 0 deletions docs/flags/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Flags Documentation directory.

Go to [Index](./index.md)

## Flags Api references are copied from support-flags package via script - `/scripts/docs-copy/flags-api-docs.sh`
File renamed without changes.
2 changes: 1 addition & 1 deletion externals/design-sdk
2 changes: 1 addition & 1 deletion externals/reflect-core
14 changes: 10 additions & 4 deletions packages/builder-web-core/widget-core/widget-with-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ export abstract class WidgetWithStyle
IWHStyleWidget,
IPositionedWidget,
IBoxShadowWidget,
IEdgeInsetsWidget {
width?: number;
height?: number;
IEdgeInsetsWidget
{
width?: DimensionLength;
height?: DimensionLength;
minWidth?: DimensionLength;
minHeight?: DimensionLength;
maxWidth?: DimensionLength;
maxHeight?: DimensionLength;

constraint?: {
left?: DimensionLength;
Expand Down Expand Up @@ -90,7 +95,8 @@ export abstract class WidgetWithStyle
*/
export abstract class MultiChildWidgetWithStyle
extends WidgetWithStyle
implements IWidgetWithStyle, IMultiChildJsxWidget {
implements IWidgetWithStyle, IMultiChildJsxWidget
{
readonly children: Array<JsxWidget> = [];

constructor({ key }: { key: WidgetKey }) {
Expand Down
29 changes: 24 additions & 5 deletions packages/builder-web-core/widgets-native/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Border,
BorderRadiusManifest,
BoxShadowManifest,
DimensionLength,
} from "@reflect-ui/core";
import { Background } from "@reflect-ui/core/lib/background";
import * as css from "@web-builder/styles";
Expand All @@ -21,16 +22,28 @@ export class Container extends StylableJsxWidget {
key: WidgetKey;
x?: number;
y?: number;
width?: number;
height?: number;

width?: DimensionLength;
height?: DimensionLength;
minWidth?: DimensionLength;
maxWidth?: DimensionLength;
minHeight?: DimensionLength;
maxHeight?: DimensionLength;

background?: Background;
borderRadius?: BorderRadiusManifest;
boxShadow?: BoxShadowManifest[];
border?: Border;
}) {
super(p);

this.width = p.width;
this.height = p.height;
this.minWidth = p.minWidth;
this.maxWidth = p.maxWidth;
this.minHeight = p.minHeight;
this.maxHeight = p.maxHeight;

this.x = p.x;
this.y = p.y;
this.background = p.background;
Expand All @@ -41,8 +54,13 @@ export class Container extends StylableJsxWidget {

styleData(): CSSProperties {
return {
width: css.px(this.width),
height: css.px(this.height),
width: css.length(this.width),
height: css.length(this.height),
"min-width": css.length(this.minWidth),
"max-width": css.length(this.maxWidth),
"min-height": css.length(this.minHeight),
"max-height": css.length(this.maxHeight),

"box-shadow": css.boxshadow(...(this.boxShadow ?? [])),
...css.background(this.background),
...css.border(this.border),
Expand All @@ -59,6 +77,7 @@ export class Container extends StylableJsxWidget {

export abstract class SelfClosingContainer
extends Container
implements Omit<Container, "children"> {
implements Omit<Container, "children">
{
readonly children?: undefined;
}
33 changes: 25 additions & 8 deletions packages/builder-web-core/widgets-native/flex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@ export class Flex extends MultiChildWidget implements CssMinHeightMixin {

borderRadius?: BorderRadiusManifest;
border?: Border;

minWidth?: DimensionLength;
maxWidth?: DimensionLength;
minHeight?: DimensionLength;
maxHeight?: DimensionLength;

flexWrap?: FlexWrap;

constructor(
p: IFlexManifest<StylableJsxWidget> & {
// direction: "row" | "column";
key: WidgetKey;
width?: number;
height?: number;
width?: DimensionLength;
height?: DimensionLength;
minWidth?: DimensionLength;
maxWidth?: DimensionLength;
minHeight?: DimensionLength;
maxHeight?: DimensionLength;
mainAxisAlignment?: MainAxisAlignment;
mainAxisSize?: MainAxisSize;
crossAxisAlignment?: CrossAxisAlignment;
Expand All @@ -74,6 +82,11 @@ export class Flex extends MultiChildWidget implements CssMinHeightMixin {
this.width = p.width;
this.height = p.height;

this.minWidth = p.minWidth;
this.maxWidth = p.maxWidth;
this.minHeight = p.minHeight;
this.maxHeight = p.maxHeight;

// flex related
this.direction = p.direction;
this.itemSpacing = p.itemSpacing;
Expand All @@ -94,7 +107,6 @@ export class Flex extends MultiChildWidget implements CssMinHeightMixin {

// css only
this.overflow = p.overflow;
this.minHeight = p.minHeight;
this.flexWrap = p.flexWrap;
}

Expand All @@ -119,7 +131,12 @@ export class Flex extends MultiChildWidget implements CssMinHeightMixin {
...css.border(this.border),
...css.borderRadius(this.borderRadius),
...flexsizing({ ...this }),
"min-height": css.minHeight(this.minHeight),

"min-width": css.length(this.minWidth),
"max-width": css.length(this.maxWidth),
"min-height": css.length(this.minHeight),
"max-height": css.length(this.maxHeight),

...css.background(this.background),
"box-sizing": (this.padding && "border-box") || undefined,
...css.padding(this.padding),
Expand All @@ -146,8 +163,8 @@ function flexsizing({
}: {
direction: Axis;
mainAxisSize?: MainAxisSize;
width?: number;
height?: number;
width?: DimensionLength;
height?: DimensionLength;
flex?: number;
}): CSSProperties {
switch (mainAxisSize) {
Expand All @@ -163,8 +180,8 @@ function flexsizing({
case Axis.vertical:
return {
flex: "none",
width: width && css.px(width),
height: height && css.px(height),
width: width && css.length(width),
height: height && css.length(height),
};
}
}
Expand Down
15 changes: 7 additions & 8 deletions packages/builder-web-core/widgets-native/html-svg/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StylableJsxWidget } from "@web-builder/core/widget-tree/widget";
import { CSSProperties } from "@coli.codes/css";
import { JSXElementConfig, StylableJSXElementConfig, WidgetKey } from "../..";
import { px, color } from "@web-builder/styles";
import { StylableJSXElementConfig, WidgetKey } from "../..";
import * as css from "@web-builder/styles";
import {
JSX,
JSXAttribute,
Expand All @@ -10,7 +10,6 @@ import {
JSXIdentifier,
JSXOpeningElement,
JSXSelfClosingElement,
Snippet,
StringLiteral,
} from "coli";
import { Color, GradientType } from "@reflect-ui/core";
Expand Down Expand Up @@ -110,7 +109,7 @@ export class SvgElement extends StylableJsxWidget {
} else {
switch (this.fill.type) {
case "solid-color": {
return [path_with_fill(color(this.fill as Color))];
return [path_with_fill(css.color(this.fill as Color))];
}
case "graphics": {
console.error("graphics fill for svg not supported.");
Expand All @@ -127,7 +126,7 @@ export class SvgElement extends StylableJsxWidget {
new JSXAttribute("offset", new StringLiteral(`${stop}%`)),
new JSXAttribute(
"style",
new StringLiteral(`stop-color: ${color(c)}`)
new StringLiteral(`stop-color: ${css.color(c)}`)
),
],
});
Expand Down Expand Up @@ -194,9 +193,9 @@ export class SvgElement extends StylableJsxWidget {
};
}
return {
width: px(this.width),
height: px(this.height),
color: color(this.color),
width: css.length(this.width),
height: css.length(this.height),
color: css.color(this.color),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { JSXElementConfig, StylableJSXElementConfig, WidgetKey } from "../..";
import {
TextDataWidget,
TextChildWidget,
StylableJsxWidget,
} from "@web-builder/core";
import { StylableJSXElementConfig, WidgetKey } from "../..";
import { TextDataWidget, TextChildWidget } from "@web-builder/core";
import * as core from "@reflect-ui/core";
import { TextOverflow } from "@reflect-ui/core";
import { TextOverflow, WebTextElement } from "@reflect-ui/core";
import { CSSProperties } from "@coli.codes/css";
import { JSX } from "coli";
import { RGBA } from "@reflect-ui/core";
import * as css from "@web-builder/styles";
import { Dynamic } from "@reflect-ui/core/lib/_utility-types";

/**
* Html Text Representative.
*
* You can select wich element to render with `elementPreference`. - choose between h1 ~ h6, p, span, etc.
*/
export class Text extends TextChildWidget {
_type: "Text";

Expand All @@ -23,6 +24,9 @@ export class Text extends TextChildWidget {
width?: number;
height?: number;

// experimental
elementPreference?: WebTextElement;

constructor(p: {
key: WidgetKey;
data: string;
Expand All @@ -31,6 +35,7 @@ export class Text extends TextChildWidget {
textAlign: core.TextAlign;
width?: number;
height?: number;
elementPreference?: WebTextElement;
}) {
super(p);

Expand All @@ -41,6 +46,9 @@ export class Text extends TextChildWidget {
this.textAlign = p.textAlign;
this.width = p.width;
this.height = p.height;

// experimental
this.elementPreference = p.elementPreference;
}

textData() {
Expand All @@ -54,7 +62,7 @@ export class Text extends TextChildWidget {
let textStyle: any = {
// text style
// ------------------------------------------
color: css.color((this.textStyle.color as any) as RGBA),
color: css.color(this.textStyle.color as any as RGBA),
"text-overflow": this.overflow,
"font-size": css.px(this.textStyle.fontSize),
"font-family": css.fontFamily(this.textStyle.fontFamily),
Expand All @@ -78,7 +86,16 @@ export class Text extends TextChildWidget {
jsxConfig(): StylableJSXElementConfig {
return <StylableJSXElementConfig>{
type: "tag-and-attr",
tag: JSX.identifier("span"),
tag: JSX.identifier(__get_dedicated_element_tag(this.elementPreference)),
};
}
}

const __default_element_tag = "span";
const __get_dedicated_element_tag = (t?: WebTextElement | undefined) => {
if (t) {
return t;
} else {
return __default_element_tag;
}
};
2 changes: 1 addition & 1 deletion packages/builder-web-core/widgets-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from "./container";
export * from "./row";
export * from "./flex";
export * from "./stack";
export * from "./html-text-span";
export * from "./html-text-element";
export * from "./html-svg";
export * from "./html-image";
export * from "./error-widget";
Expand Down
Loading