Skip to content

Commit d82399d

Browse files
add alt image support for disable broken image symbol; add config to disable detection for view only canvas build - for vanilla
1 parent ad6eafd commit d82399d

16 files changed

Lines changed: 124 additions & 47 deletions

File tree

editor/scaffolds/canvas/canvas.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function VisualContentArea({ fileid }: { fileid: string }) {
4949
}}
5050
>
5151
<Canvas
52+
key={selectedPage}
5253
selectedNodes={selectedNodes.filter(Boolean)}
5354
highlightedLayer={highlightedLayer}
5455
onSelectNode={(node) => {

editor/scaffolds/preview/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ export function Preview({
3535
name: __target.name,
3636
entry: __target,
3737
};
38-
const build_config = {
38+
const build_config: config.BuildConfiguration = {
3939
...config.default_build_configuration,
4040
disable_components: true,
41+
disable_detection: true,
42+
disable_flags_support: true,
4143
};
4244

4345
// ----- for preview -----
@@ -95,8 +97,7 @@ export function Preview({
9597
<VanillaRunner
9698
key={preview.scaffold.raw}
9799
style={{
98-
borderRadius: 4,
99-
boxShadow: "0px 0px 48px #00000020",
100+
borderRadius: 1,
100101
}}
101102
source={preview.scaffold.raw}
102103
width="100%"

packages/builder-config-preset/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export const vanilla_presets = {
5858
vanilla_default: <config.VanillaFrameworkConfig>{
5959
framework: Framework.vanilla,
6060
language: Language.html,
61+
imgage_alt: {
62+
no_alt: true,
63+
},
6164
},
6265
};
6366

packages/builder-config/configure/build-config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export interface BuildConfiguration {
1515
* @default false
1616
*/
1717
disable_components?: boolean;
18+
19+
/**
20+
* if disabled(true), we won't use detection for buttons, icons, and other widgets.
21+
* @default false
22+
*/
23+
disable_detection?: boolean;
24+
25+
/**
26+
* if disabled(true), we won't read flags annotations.
27+
* @default false
28+
*/
29+
disable_flags_support?: boolean;
1830
}
1931

2032
export const default_build_configuration: BuildConfiguration = {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { Language } from "@grida/builder-platform-types";
22
import type { ReactFrameworkConfig } from "../framework-react";
3+
import type { VanillaFrameworkConfig } from "../framework-vanilla";
34

45
export type FrameworkConfig =
56
| ReactFrameworkConfig
67
| FlutterFrameworkConfig
78
| VanillaFrameworkConfig;
89

910
export type { ReactFrameworkConfig };
11+
export type { VanillaFrameworkConfig };
1012

1113
export interface FlutterFrameworkConfig {
1214
framework: "flutter";
1315
language: Language.dart;
1416
}
15-
16-
export interface VanillaFrameworkConfig {
17-
framework: "vanilla";
18-
language: Language.html;
19-
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import { Language } from "@grida/builder-platform-types";
12
import { ComponentOutput } from "../output";
2-
3+
import type { WebImgAltConfig } from "../platform-web/web-img-alt";
34
export interface VanillaComponentOutput extends ComponentOutput {}
5+
6+
export interface VanillaFrameworkConfig {
7+
framework: "vanilla";
8+
language: Language.html;
9+
imgage_alt: WebImgAltConfig;
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface WebImgAltConfig {
2+
/**
3+
* if no alt set to true, the alt will be removed from image (web) wich will no longer show broken image.
4+
*/
5+
no_alt?: boolean;
6+
}

packages/builder-web-core/widgets-native/html-image/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ImageElement extends SelfClosingContainer {
2828
super({ key });
2929
assert(src !== undefined, "ImageElement requires src");
3030
this.src = src;
31-
this.alt = alt || `image of ${key.name}`;
31+
this.alt = alt;
3232
this.width = width;
3333
this.height = height;
3434
}
@@ -44,19 +44,19 @@ export class ImageElement extends SelfClosingContainer {
4444
}
4545

4646
jsxConfig(): StylableJSXElementConfig {
47+
const attributes = [
48+
this.src &&
49+
new JSXAttribute(
50+
"src",
51+
new StringLiteral(this.src || image_smallest_fallback_source_base_64)
52+
),
53+
!!!this.alt && new JSXAttribute("alt", new StringLiteral(this.alt)),
54+
];
55+
4756
return <StylableJSXElementConfig>{
4857
type: "tag-and-attr",
4958
tag: JSX.identifier("img"),
50-
attributes: [
51-
this.src &&
52-
new JSXAttribute(
53-
"src",
54-
new StringLiteral(
55-
this.src || image_smallest_fallback_source_base_64
56-
)
57-
),
58-
this.alt && new JSXAttribute("alt", new StringLiteral(this.alt)),
59-
],
59+
attributes: attributes,
6060
};
6161
}
6262
}

packages/builder-web-react/react-styled-component-widget/from-reusable-widget-tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function finalizeReactReusable_StyledComponents__Experimental({
3232

3333
const token = hanlde(tree);
3434
console.log("from-reusable-widget-tree::token", { token, tree });
35-
const webwi = buildWebWidgetFromTokens(token);
35+
const webwi = buildWebWidgetFromTokens(token, {});
3636
console.log("from-reusable-widget-tree::web-widget", webwi);
3737
const builder = new ReactStyledComponentsBuilder({
3838
entry: webwi,

packages/designto-code/universal/design-to-code.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
} from "@code-features/assets";
1111
import { BaseImageRepositories } from "@design-sdk/core/assets-repository";
1212
import { k } from "@web-builder/core";
13-
import { default_tokenizer_config } from "@designto/token/config";
13+
import {
14+
default_tokenizer_config,
15+
TokenizerConfig,
16+
} from "@designto/token/config";
1417
import { default_build_configuration } from "@designto/config";
1518
import { reusable } from "@code-features/component";
1619
import assert from "assert";
@@ -52,7 +55,10 @@ export async function designToCode({
5255
}
5356

5457
// post token processing
55-
let tokenizer_config = { ...default_tokenizer_config, id: input.id };
58+
let tokenizer_config: TokenizerConfig = {
59+
...default_tokenizer_config,
60+
id: input.id,
61+
};
5662
if (build_config.force_root_widget_fixed_size_no_scroll) {
5763
tokenizer_config.custom_wrapping_provider = (w, n, d) => {
5864
if (n.id === input.entry.id) {
@@ -64,6 +70,15 @@ export async function designToCode({
6470
return false;
6571
};
6672
}
73+
74+
if (build_config.disable_detection) {
75+
tokenizer_config.disable_detection = true;
76+
}
77+
78+
if (build_config.disable_flags_support) {
79+
tokenizer_config.disable_flags_support = true;
80+
}
81+
6782
const vanilla_token = tokenize(input.entry, tokenizer_config);
6883

6984
// post token processing for componentization
@@ -236,7 +251,10 @@ export async function designToVanilla({
236251
vanilla_config: config.VanillaFrameworkConfig;
237252
asset_config?: AssetsConfig;
238253
}): Promise<output.ICodeOutput> {
239-
const vanillawidget = tovanilla.buildVanillaWidget(input.widget);
254+
const vanillawidget = tovanilla.buildVanillaWidget(
255+
input.widget,
256+
vanilla_config
257+
);
240258
const res = tovanilla.buildVanillaFile(vanillawidget);
241259

242260
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)