@builder.io/mitosis 0.0.50-6 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/__tests__/angular.test.js +6 -0
- package/dist/src/__tests__/builder.test.js +5 -1
- package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdate.raw.jsx +13 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/multiple-onUpdateWithDeps.raw.jsx +19 -0
- package/dist/src/__tests__/data/blocks/onUpdateWithDeps.raw.jsx +6 -3
- package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component-with-children.raw.jsx +15 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/self-referencing-component.raw.jsx +12 -0
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.d.ts +6 -0
- package/dist/src/__tests__/data/blocks/shadow-dom.raw.jsx +54 -0
- package/dist/src/__tests__/data/blocks/slot.raw.d.ts +5 -0
- package/dist/src/__tests__/data/blocks/slot.raw.jsx +6 -0
- package/dist/src/__tests__/data/blocks/stamped-io.raw.jsx +8 -0
- package/dist/src/__tests__/data/blocks/styles.raw.d.ts +1 -0
- package/dist/src/__tests__/data/blocks/styles.raw.jsx +10 -0
- package/dist/src/__tests__/data/context/simple.context.lite.d.ts +8 -1
- package/dist/src/__tests__/html.test.js +6 -0
- package/dist/src/__tests__/qwik.directive.test.d.ts +1 -0
- package/dist/src/__tests__/qwik.directive.test.js +107 -0
- package/dist/src/__tests__/qwik.test.js +256 -128
- package/dist/src/__tests__/react-native.test.js +12 -0
- package/dist/src/__tests__/react.test.js +12 -0
- package/dist/src/__tests__/svelte.test.js +24 -0
- package/dist/src/__tests__/vue.test.js +12 -0
- package/dist/src/__tests__/webcomponent.test.d.ts +1 -0
- package/dist/src/__tests__/webcomponent.test.js +12 -0
- package/dist/src/constants/html_tags.d.ts +1 -0
- package/dist/src/constants/html_tags.js +119 -0
- package/dist/src/generators/angular.js +7 -4
- package/dist/src/generators/context/react copy.d.ts +8 -0
- package/dist/src/generators/context/react copy.js +28 -0
- package/dist/src/generators/context/solid.d.ts +8 -0
- package/dist/src/generators/context/solid.js +28 -0
- package/dist/src/generators/context/svelte.d.ts +8 -0
- package/dist/src/generators/context/svelte.js +28 -0
- package/dist/src/generators/helpers/context.d.ts +2 -0
- package/dist/src/generators/helpers/context.js +8 -0
- package/dist/src/generators/html.js +20 -14
- package/dist/src/generators/mitosis.js +4 -3
- package/dist/src/generators/qwik/component.js +26 -5
- package/dist/src/generators/qwik/directives.d.ts +14 -5
- package/dist/src/generators/qwik/directives.js +32 -25
- package/dist/src/generators/qwik/handlers.js +3 -4
- package/dist/src/generators/qwik/jsx.js +17 -5
- package/dist/src/generators/qwik/src-generator.d.ts +0 -9
- package/dist/src/generators/qwik/src-generator.js +93 -101
- package/dist/src/generators/qwik/styles.js +8 -11
- package/dist/src/generators/react.js +9 -8
- package/dist/src/generators/solid.js +82 -8
- package/dist/src/generators/stencil/generate.js +5 -3
- package/dist/src/generators/stencil/index.js +5 -1
- package/dist/src/generators/svelte.d.ts +9 -1
- package/dist/src/generators/svelte.js +175 -76
- package/dist/src/generators/vue.d.ts +1 -1
- package/dist/src/generators/vue.js +86 -10
- package/dist/src/helpers/babel-transform copy.d.ts +8 -0
- package/dist/src/helpers/babel-transform copy.js +138 -0
- package/dist/src/helpers/babel-transform.d.ts +4 -7
- package/dist/src/helpers/babel-transform.js +18 -2
- package/dist/src/helpers/babel-transform.test.d.ts +1 -0
- package/dist/src/helpers/babel-transform.test.js +7 -0
- package/dist/src/helpers/create-mitosis-component.js +1 -1
- package/dist/src/helpers/get-state-object-string.js +2 -1
- package/dist/src/helpers/map-refs.js +22 -9
- package/dist/src/helpers/parsers.d.ts +8 -0
- package/dist/src/helpers/parsers.js +66 -0
- package/dist/src/helpers/render-imports.d.ts +2 -4
- package/dist/src/helpers/render-imports.js +32 -14
- package/dist/src/index.d.ts +10 -5
- package/dist/src/index.js +11 -5
- package/dist/src/parsers/builder.d.ts +16 -50
- package/dist/src/parsers/builder.js +22 -40
- package/dist/src/parsers/context.js +5 -1
- package/dist/src/parsers/jsx.d.ts +7 -0
- package/dist/src/parsers/jsx.js +27 -5
- package/dist/src/parsers/liquid.js +5 -1
- package/dist/src/plugins/compile-away-builder-components.js +5 -1
- package/dist/src/symbols/symbol-processor.js +3 -3
- package/dist/src/targets.d.ts +1 -1
- package/dist/src/types/mitosis-component.d.ts +8 -3
- package/dist/test/qwik/Accordion/high.jsx +0 -1
- package/dist/test/qwik/Accordion/low.jsx +171 -65
- package/dist/test/qwik/Accordion/med.jsx +9 -10
- package/dist/test/qwik/For/high.jsx +0 -1
- package/dist/test/qwik/For/low.jsx +25 -58
- package/dist/test/qwik/For/med.jsx +9 -10
- package/dist/test/qwik/Image/high.js +9 -1
- package/dist/test/qwik/Image/low.js +0 -42
- package/dist/test/qwik/Image/med.js +149 -12
- package/dist/test/qwik/Image.slow/high.js +9 -1
- package/dist/test/qwik/Image.slow/low.js +0 -42
- package/dist/test/qwik/Image.slow/med.js +149 -12
- package/dist/{src/types/generators.d.ts → test/qwik/bindings/high.cjs} +0 -0
- package/dist/test/qwik/bindings/low.cjs +33 -0
- package/dist/test/qwik/bindings/med.cjs +12 -0
- package/dist/test/qwik/button/high.js +1 -13
- package/dist/test/qwik/button/low.js +8 -40
- package/dist/test/qwik/button/med.js +36 -11
- package/dist/test/qwik/component/bindings/high.jsx +0 -1
- package/dist/test/qwik/component/bindings/low.jsx +26 -71
- package/dist/test/qwik/component/bindings/med.jsx +48 -39
- package/dist/test/qwik/component/component/inputs/high.cjsx +9 -0
- package/dist/test/qwik/component/component/inputs/low.cjsx +0 -0
- package/dist/test/qwik/component/component/inputs/med.cjsx +65 -0
- package/dist/test/qwik/hello_world/stylesheet/high.jsx +0 -1
- package/dist/test/qwik/hello_world/stylesheet/low.jsx +6 -27
- package/dist/test/qwik/hello_world/stylesheet/med.jsx +9 -10
- package/dist/test/qwik/page-with-symbol/high.js +0 -1
- package/dist/test/qwik/page-with-symbol/low.js +15 -52
- package/dist/test/qwik/page-with-symbol/med.js +9 -10
- package/dist/test/qwik/show-hide/high.jsx +9 -0
- package/dist/test/qwik/show-hide/low.jsx +0 -0
- package/dist/test/qwik/show-hide/med.jsx +174 -0
- package/dist/test/qwik/svg/high.js +0 -1
- package/dist/test/qwik/svg/low.js +9 -35
- package/dist/test/qwik/svg/med.js +9 -10
- package/dist/test/qwik/todo/Todo.cjs/high.cjs +4 -39
- package/dist/test/qwik/todo/Todo.cjs/low.cjs +0 -1
- package/dist/test/qwik/todo/Todo.cjs/med.cjs +38 -61
- package/dist/test/qwik/todo/Todo.js/high.js +22 -5
- package/dist/test/qwik/todo/Todo.js/med.js +45 -1
- package/dist/test/qwik/todo/Todo.tsx/high.tsx +4 -39
- package/dist/test/qwik/todo/Todo.tsx/low.tsx +0 -1
- package/dist/test/qwik/todo/Todo.tsx/med.tsx +31 -34
- package/dist/test/qwik/todos/Todo.tsx/high.tsx +0 -12
- package/dist/test/qwik/todos/Todo.tsx/low.tsx +18 -25
- package/dist/test/qwik/todos/Todo.tsx/med.tsx +8 -10
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -22
- package/dist/src/__tests__/data/blocks/onMount-onUnMount.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/onMount-onUnMount.jsx +0 -13
- package/dist/src/__tests__/data/blocks/onMount.d.ts +0 -1
- package/dist/src/__tests__/data/blocks/onMount.jsx +0 -13
- package/dist/src/types/generators.js +0 -1
|
@@ -3,10 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var angular_1 = require("../generators/angular");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
5
|
var onUpdate = require('./data/blocks/onUpdate.raw');
|
|
6
|
+
var slot = require('./data/blocks/slot.raw');
|
|
6
7
|
describe('Angular', function () {
|
|
7
8
|
test('onUpdate', function () {
|
|
8
9
|
var component = (0, jsx_1.parseJsx)(onUpdate);
|
|
9
10
|
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
10
11
|
expect(output).toMatchSnapshot();
|
|
11
12
|
});
|
|
13
|
+
test('ng-content', function () {
|
|
14
|
+
var component = (0, jsx_1.parseJsx)(slot);
|
|
15
|
+
var output = (0, angular_1.componentToAngular)()({ component: component });
|
|
16
|
+
expect(output).toMatchSnapshot();
|
|
17
|
+
});
|
|
12
18
|
});
|
|
@@ -5,7 +5,11 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
5
5
|
};
|
|
6
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
7
|
if (k2 === undefined) k2 = k;
|
|
8
|
-
Object.
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
9
13
|
}) : (function(o, m, k, k2) {
|
|
10
14
|
if (k2 === undefined) k2 = k;
|
|
11
15
|
o[k2] = m[k];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MultipleOnUpdate(): JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MultipleOnUpdate() {
|
|
5
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
6
|
+
console.log('Runs on every update/rerender');
|
|
7
|
+
});
|
|
8
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
9
|
+
console.log('Runs on every update/rerender as well');
|
|
10
|
+
});
|
|
11
|
+
return <div />;
|
|
12
|
+
}
|
|
13
|
+
exports.default = MultipleOnUpdate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MultipleOnUpdateWithDeps(): JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MultipleOnUpdateWithDeps() {
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
a: 'a',
|
|
7
|
+
b: 'b',
|
|
8
|
+
c: 'c',
|
|
9
|
+
d: 'd',
|
|
10
|
+
});
|
|
11
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
12
|
+
console.log('Runs when a or b changes', state.a, state.b);
|
|
13
|
+
}, [state.a, state.b]);
|
|
14
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
15
|
+
console.log('Runs when c or d changes', state.c, state.d);
|
|
16
|
+
}, [state.c, state.d]);
|
|
17
|
+
return <div />;
|
|
18
|
+
}
|
|
19
|
+
exports.default = MultipleOnUpdateWithDeps;
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
4
|
function OnUpdateWithDeps() {
|
|
5
|
-
var
|
|
5
|
+
var state = (0, mitosis_1.useState)({
|
|
6
|
+
a: 'a',
|
|
7
|
+
b: 'b',
|
|
8
|
+
});
|
|
6
9
|
(0, mitosis_1.onUpdate)(function () {
|
|
7
|
-
console.log('Runs when a or b changes');
|
|
8
|
-
}, [a, b]);
|
|
10
|
+
console.log('Runs when a or b changes', state.a, state.b);
|
|
11
|
+
}, [state.a, state.b]);
|
|
9
12
|
return <div />;
|
|
10
13
|
}
|
|
11
14
|
exports.default = OnUpdateWithDeps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MyComponent(props: any): JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MyComponent(props) {
|
|
5
|
+
return (<div>
|
|
6
|
+
{props.name}
|
|
7
|
+
{props.children}
|
|
8
|
+
<mitosis_1.Show when={props.name === 'Batman'}>
|
|
9
|
+
<MyComponent name={'Bruce'}>
|
|
10
|
+
<div>Wayne</div>
|
|
11
|
+
</MyComponent>
|
|
12
|
+
</mitosis_1.Show>
|
|
13
|
+
</div>);
|
|
14
|
+
}
|
|
15
|
+
exports.default = MyComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MyComponent(props: any): JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function MyComponent(props) {
|
|
5
|
+
return (<div>
|
|
6
|
+
{props.name}
|
|
7
|
+
<mitosis_1.Show when={props.name === 'Batman'}>
|
|
8
|
+
<MyComponent name={'Bruce Wayne'}/>
|
|
9
|
+
</mitosis_1.Show>
|
|
10
|
+
</div>);
|
|
11
|
+
}
|
|
12
|
+
exports.default = MyComponent;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
(0, mitosis_1.useMetadata)({ isAttachedToShadowDom: true });
|
|
5
|
+
function SmileReviews(props) {
|
|
6
|
+
var state = (0, mitosis_1.useState)({
|
|
7
|
+
reviews: [],
|
|
8
|
+
name: 'test',
|
|
9
|
+
showReviewPrompt: false,
|
|
10
|
+
});
|
|
11
|
+
// TODO: allow async function here
|
|
12
|
+
(0, mitosis_1.onMount)(function () {
|
|
13
|
+
fetch("https://stamped.io/api/widget/reviews?storeUrl=builder-io.myshopify.com&apiKey=".concat(props.apiKey || 'pubkey-8bbDq7W6w4sB3OWeM1HUy2s47702hM', "&productId=").concat(props.productId || '2410511106127'))
|
|
14
|
+
.then(function (res) { return res.json(); })
|
|
15
|
+
.then(function (data) {
|
|
16
|
+
state.reviews = data.data;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return (<div data-user={state.name}>
|
|
20
|
+
<button onClick={function () { return (state.showReviewPrompt = true); }}>
|
|
21
|
+
Write a review
|
|
22
|
+
</button>
|
|
23
|
+
<mitosis_1.Show when={state.showReviewPrompt}>
|
|
24
|
+
<input placeholder="Email"/>
|
|
25
|
+
|
|
26
|
+
<input css={{ display: 'block' }} placeholder="Title"/>
|
|
27
|
+
|
|
28
|
+
<textarea css={{ display: 'block' }} placeholder="How was your experience?"/>
|
|
29
|
+
<button css={{ display: 'block' }} onClick={function () {
|
|
30
|
+
state.showReviewPrompt = false;
|
|
31
|
+
}}>
|
|
32
|
+
Submit
|
|
33
|
+
</button>
|
|
34
|
+
</mitosis_1.Show>
|
|
35
|
+
<mitosis_1.For each={state.reviews}>
|
|
36
|
+
{function (review, index) { return (<div $name="Review" key={review.id} css={{
|
|
37
|
+
margin: '10px',
|
|
38
|
+
padding: '10px',
|
|
39
|
+
background: 'white',
|
|
40
|
+
display: 'flex',
|
|
41
|
+
borderRadius: '5px',
|
|
42
|
+
boxShadow: '0 2px 5px rgba(0, 0, 0, 0.1)',
|
|
43
|
+
}}>
|
|
44
|
+
<img css={{ height: '30px', width: '30px', marginRight: '10px' }} src={review.avatar}/>
|
|
45
|
+
<div class={state.showReviewPrompt ? 'bg-primary' : 'bg-secondary'}>
|
|
46
|
+
<div>N: {index}</div>
|
|
47
|
+
<div>{review.author}</div>
|
|
48
|
+
<div>{review.reviewMessage}</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>); }}
|
|
51
|
+
</mitosis_1.For>
|
|
52
|
+
</div>);
|
|
53
|
+
}
|
|
54
|
+
exports.default = SmileReviews;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var lodash_2 = require("lodash");
|
|
4
6
|
function SmileReviews(props) {
|
|
5
7
|
var state = (0, mitosis_1.useState)({
|
|
6
8
|
reviews: [],
|
|
7
9
|
name: 'test',
|
|
8
10
|
showReviewPrompt: false,
|
|
11
|
+
kebabCaseValue: function () {
|
|
12
|
+
return (0, lodash_1.kebabCase)('testThat');
|
|
13
|
+
},
|
|
14
|
+
snakeCaseValue: function () {
|
|
15
|
+
return (0, lodash_2.snakeCase)('testThis');
|
|
16
|
+
},
|
|
9
17
|
});
|
|
10
18
|
// TODO: allow async function here
|
|
11
19
|
(0, mitosis_1.onMount)(function () {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function OnUpdate(): JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var mitosis_1 = require("@builder.io/mitosis");
|
|
4
|
+
function OnUpdate() {
|
|
5
|
+
(0, mitosis_1.onUpdate)(function () {
|
|
6
|
+
console.log('Runs on every update/rerender');
|
|
7
|
+
});
|
|
8
|
+
return <div />;
|
|
9
|
+
}
|
|
10
|
+
exports.default = OnUpdate;
|
|
@@ -3,10 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var html_1 = require("../generators/html");
|
|
4
4
|
var jsx_1 = require("../parsers/jsx");
|
|
5
5
|
var stamped = require('./data/blocks/stamped-io.raw');
|
|
6
|
+
var shadowDom = require('./data/blocks/shadow-dom.raw');
|
|
6
7
|
describe('Html', function () {
|
|
7
8
|
test('Stamped', function () {
|
|
8
9
|
var component = (0, jsx_1.parseJsx)(stamped);
|
|
9
10
|
var html = (0, html_1.componentToHtml)()({ component: component });
|
|
10
11
|
expect(html).toMatchSnapshot();
|
|
11
12
|
});
|
|
13
|
+
test('Shadow DOM', function () {
|
|
14
|
+
var component = (0, jsx_1.parseJsx)(shadowDom);
|
|
15
|
+
var html = (0, html_1.componentToHtml)()({ component: component });
|
|
16
|
+
expect(html).toMatchSnapshot();
|
|
17
|
+
});
|
|
12
18
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var directives_1 = require("../generators/qwik/directives");
|
|
4
|
+
describe('qwik directives', function () {
|
|
5
|
+
var partial = expect.objectContaining;
|
|
6
|
+
beforeEach(function () {
|
|
7
|
+
global.h = mockH;
|
|
8
|
+
});
|
|
9
|
+
afterEach(function () { return (global.h = undefined); });
|
|
10
|
+
describe('Image', function () {
|
|
11
|
+
test('altText', function () {
|
|
12
|
+
expect((0, directives_1.Image)({ altText: 'foo', image: 'http://some.url' }).children[0][0]).toEqual(partial({
|
|
13
|
+
tag: 'img',
|
|
14
|
+
props: partial({ src: 'http://some.url', alt: 'foo' }),
|
|
15
|
+
}));
|
|
16
|
+
expect((0, directives_1.Image)({ image: 'http://some.url' }).children[0][0]).toEqual(partial({
|
|
17
|
+
tag: 'img',
|
|
18
|
+
props: partial({ src: 'http://some.url', role: 'presentation' }),
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
test('builder-pixel is eager', function () {
|
|
22
|
+
expect((0, directives_1.Image)({
|
|
23
|
+
builderBlock: { id: 'builder-pixel-foo' },
|
|
24
|
+
image: 'http://some.url',
|
|
25
|
+
}).children[0][0]).toEqual(partial({
|
|
26
|
+
tag: 'img',
|
|
27
|
+
props: partial({ loading: 'eager' }),
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
test('images are lazy loaded', function () {
|
|
31
|
+
expect((0, directives_1.Image)({
|
|
32
|
+
image: 'http://some.url',
|
|
33
|
+
}).children[0][0]).toEqual(partial({
|
|
34
|
+
tag: 'img',
|
|
35
|
+
props: partial({ loading: 'lazy' }),
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
test('builder.io URLs are served using webp', function () {
|
|
39
|
+
expect(find('source', (0, directives_1.Image)({
|
|
40
|
+
image: 'http://foo.builder.io/foo',
|
|
41
|
+
}))).toEqual(partial({
|
|
42
|
+
tag: 'source',
|
|
43
|
+
props: partial({
|
|
44
|
+
srcset: srcSet('http://foo.builder.io/foo?format=webp'),
|
|
45
|
+
type: 'image/webp',
|
|
46
|
+
}),
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
test('maxWidth is added to the srcs', function () {
|
|
50
|
+
expect(find('source', (0, directives_1.Image)({
|
|
51
|
+
image: 'http://foo.builder.io/foo',
|
|
52
|
+
srcsetSizes: '1234 456',
|
|
53
|
+
}))).toEqual(partial({
|
|
54
|
+
tag: 'source',
|
|
55
|
+
props: partial({
|
|
56
|
+
srcset: srcSet('http://foo.builder.io/foo?format=webp', '1234 456'),
|
|
57
|
+
type: 'image/webp',
|
|
58
|
+
}),
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
test('anchor should wrap in <a>', function () {
|
|
62
|
+
expect(find('a', (0, directives_1.Image)({
|
|
63
|
+
image: 'http://some.url',
|
|
64
|
+
href: 'my-url',
|
|
65
|
+
}))).toEqual(partial({
|
|
66
|
+
tag: 'a',
|
|
67
|
+
props: partial({ href: 'my-url' }),
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
function find(tag, jsx) {
|
|
73
|
+
if (tag == jsx.tag)
|
|
74
|
+
return jsx;
|
|
75
|
+
return findInChildren(tag, jsx.children);
|
|
76
|
+
function findInChildren(tag, jsxs) {
|
|
77
|
+
var value = undefined;
|
|
78
|
+
for (var i = 0; i < jsxs.length; i++) {
|
|
79
|
+
var jsx_1 = jsxs[i];
|
|
80
|
+
if (Array.isArray(jsx_1)) {
|
|
81
|
+
value = findInChildren(tag, jsx_1);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
value = find(tag, jsx_1);
|
|
85
|
+
}
|
|
86
|
+
if (value)
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var mockH = function (tag, props, children) { return ({
|
|
93
|
+
tag: tag,
|
|
94
|
+
props: props,
|
|
95
|
+
children: children,
|
|
96
|
+
}); };
|
|
97
|
+
function srcSet(url, additionalSizes) {
|
|
98
|
+
if (additionalSizes === void 0) { additionalSizes = ''; }
|
|
99
|
+
return ['100', '200', '400', '800', '1200', '1600', '2000']
|
|
100
|
+
.concat(additionalSizes ? additionalSizes.split(' ') : [])
|
|
101
|
+
.map(function (size) {
|
|
102
|
+
var parsedUrl = new URL(url);
|
|
103
|
+
parsedUrl.searchParams.set('width', size);
|
|
104
|
+
return "".concat(parsedUrl, " ").concat(size, "w");
|
|
105
|
+
})
|
|
106
|
+
.join(', ');
|
|
107
|
+
}
|