@lowdefy/block-dev 4.0.0-alpha.1 → 4.0.0-alpha.12
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/BlockSchemaErrors.js +7 -64
- package/dist/index.js +1 -1
- package/dist/mockBlock.js +5 -9
- package/dist/runBlockSchemaTests.js +1 -1
- package/dist/runMockMethodTests.js +29 -23
- package/dist/runMockRenderTests.js +33 -17
- package/dist/runRenderTests.js +32 -25
- package/dist/schemaTest.js +3 -5
- package/dist/stubBlockProps.js +30 -36
- package/package.json +12 -12
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
/*
|
|
3
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
3
|
|
|
5
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
you may not use this file except in compliance with the License.
|
|
@@ -16,73 +15,17 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
16
15
|
*/ import React from 'react';
|
|
17
16
|
const BlockSchemaErrors = ({ schemaErrors })=>{
|
|
18
17
|
if (!schemaErrors || schemaErrors.length === 0) return '';
|
|
19
|
-
return(/*#__PURE__*/
|
|
18
|
+
return(/*#__PURE__*/ React.createElement("div", {
|
|
20
19
|
style: {
|
|
21
20
|
padding: 10,
|
|
22
21
|
fontSize: '0.8rem',
|
|
23
22
|
border: '1px solid red',
|
|
24
23
|
background: '#fBB',
|
|
25
24
|
width: '100%'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
}),
|
|
33
|
-
schemaErrors.map((error, i)=>/*#__PURE__*/ _jsxs("div", {
|
|
34
|
-
children: [
|
|
35
|
-
/*#__PURE__*/ _jsx("br", {
|
|
36
|
-
}),
|
|
37
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
38
|
-
children: [
|
|
39
|
-
/*#__PURE__*/ _jsx("b", {
|
|
40
|
-
children: "keyword:"
|
|
41
|
-
}),
|
|
42
|
-
" ",
|
|
43
|
-
error.keyword
|
|
44
|
-
]
|
|
45
|
-
}),
|
|
46
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
47
|
-
children: [
|
|
48
|
-
/*#__PURE__*/ _jsx("b", {
|
|
49
|
-
children: "message:"
|
|
50
|
-
}),
|
|
51
|
-
" ",
|
|
52
|
-
error.message
|
|
53
|
-
]
|
|
54
|
-
}),
|
|
55
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
56
|
-
children: [
|
|
57
|
-
/*#__PURE__*/ _jsx("b", {
|
|
58
|
-
children: "params:"
|
|
59
|
-
}),
|
|
60
|
-
" ",
|
|
61
|
-
JSON.stringify(error.params)
|
|
62
|
-
]
|
|
63
|
-
}),
|
|
64
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
65
|
-
children: [
|
|
66
|
-
/*#__PURE__*/ _jsx("b", {
|
|
67
|
-
children: "dataPath:"
|
|
68
|
-
}),
|
|
69
|
-
" ",
|
|
70
|
-
error.dataPath
|
|
71
|
-
]
|
|
72
|
-
}),
|
|
73
|
-
/*#__PURE__*/ _jsxs("div", {
|
|
74
|
-
children: [
|
|
75
|
-
/*#__PURE__*/ _jsx("b", {
|
|
76
|
-
children: "schemaPath:"
|
|
77
|
-
}),
|
|
78
|
-
" ",
|
|
79
|
-
error.schemaPath
|
|
80
|
-
]
|
|
81
|
-
})
|
|
82
|
-
]
|
|
83
|
-
}, i)
|
|
84
|
-
)
|
|
85
|
-
]
|
|
86
|
-
}));
|
|
25
|
+
}
|
|
26
|
+
}, /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "Schema Errors")), schemaErrors.map((error, i)=>/*#__PURE__*/ React.createElement("div", {
|
|
27
|
+
key: i
|
|
28
|
+
}, /*#__PURE__*/ React.createElement("br", null), /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "keyword:"), " ", error.keyword), /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "message:"), " ", error.message), /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "params:"), " ", JSON.stringify(error.params)), /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "dataPath:"), " ", error.dataPath), /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement("b", null, "schemaPath:"), " ", error.schemaPath))
|
|
29
|
+
)));
|
|
87
30
|
};
|
|
88
31
|
export default BlockSchemaErrors;
|
package/dist/index.js
CHANGED
package/dist/mockBlock.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { makeCssClass } from '@lowdefy/block-utils';
|
|
16
16
|
import stubBlockProps from './stubBlockProps.js';
|
|
17
|
-
const mockBlock = ({ meta ,
|
|
17
|
+
const mockBlock = ({ meta , schema })=>{
|
|
18
18
|
const mockMath = Object.create(global.Math);
|
|
19
19
|
mockMath.random = ()=>0.5
|
|
20
20
|
;
|
|
@@ -75,22 +75,18 @@ const mockBlock = ({ meta , logger , schema })=>{
|
|
|
75
75
|
window.innerHeight = height || window.innerHeight;
|
|
76
76
|
window.dispatchEvent(new Event('resize'));
|
|
77
77
|
};
|
|
78
|
-
window.scrollTo = ()=>{
|
|
79
|
-
};
|
|
78
|
+
window.scrollTo = ()=>{};
|
|
80
79
|
// Fix css-animation or rc-motion deps on these
|
|
81
80
|
// https://github.com/react-component/motion/blob/9c04ef1a210a4f3246c9becba6e33ea945e00669/src/util/motion.ts#L27-L35
|
|
82
81
|
// https://github.com/yiminghe/css-animation/blob/a5986d73fd7dfce75665337f39b91483d63a4c8c/src/Event.js#L44
|
|
83
|
-
window.AnimationEvent = window.AnimationEvent || (()=>{
|
|
84
|
-
});
|
|
85
|
-
window.TransitionEvent = window.TransitionEvent || (()=>{
|
|
86
|
-
});
|
|
82
|
+
window.AnimationEvent = window.AnimationEvent || (()=>{});
|
|
83
|
+
window.TransitionEvent = window.TransitionEvent || (()=>{});
|
|
87
84
|
}
|
|
88
85
|
};
|
|
89
86
|
const getProps = (block)=>{
|
|
90
87
|
return stubBlockProps({
|
|
91
88
|
block,
|
|
92
89
|
meta,
|
|
93
|
-
logger,
|
|
94
90
|
schema
|
|
95
91
|
});
|
|
96
92
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
1
|
/*
|
|
3
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
3
|
|
|
5
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
you may not use this file except in compliance with the License.
|
|
@@ -18,10 +17,24 @@ import { type } from '@lowdefy/helpers';
|
|
|
18
17
|
import { render, screen } from '@testing-library/react';
|
|
19
18
|
import userEvent from '@testing-library/user-event';
|
|
20
19
|
import mockBlock from './mockBlock.js';
|
|
21
|
-
|
|
20
|
+
function _extends() {
|
|
21
|
+
_extends = Object.assign || function(target) {
|
|
22
|
+
for(var i = 1; i < arguments.length; i++){
|
|
23
|
+
var source = arguments[i];
|
|
24
|
+
for(var key in source){
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
26
|
+
target[key] = source[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
return _extends.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
const runMockMethodTests = ({ Block: Block1 , examples , mocks , schema , testConfig })=>{
|
|
35
|
+
const meta = Block1.meta;
|
|
22
36
|
const { before , methods , getProps } = mockBlock({
|
|
23
37
|
meta,
|
|
24
|
-
logger,
|
|
25
38
|
schema
|
|
26
39
|
});
|
|
27
40
|
beforeEach(()=>{
|
|
@@ -35,8 +48,8 @@ const runMockMethodTests = ({ examples , logger , meta , mocks , schema , tests
|
|
|
35
48
|
];
|
|
36
49
|
examples.forEach((ex)=>{
|
|
37
50
|
values.forEach((value, v)=>{
|
|
38
|
-
if (
|
|
39
|
-
|
|
51
|
+
if (testConfig && testConfig.methods) {
|
|
52
|
+
testConfig.methods.forEach((method)=>{
|
|
40
53
|
mocks.forEach((mock)=>{
|
|
41
54
|
test(`Mock for method: ${JSON.stringify(method)} - ${ex.id} - value[${v}] - ${mock.name}`, async ()=>{
|
|
42
55
|
const mockFns = await mock.getMockFns();
|
|
@@ -47,24 +60,17 @@ const runMockMethodTests = ({ examples , logger , meta , mocks , schema , tests
|
|
|
47
60
|
...methods,
|
|
48
61
|
registerMethod: props.methods.registerMethod
|
|
49
62
|
};
|
|
50
|
-
return(/*#__PURE__*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
props.methods[method.name](method.args);
|
|
60
|
-
},
|
|
61
|
-
"data-testid": "btn_method"
|
|
62
|
-
})
|
|
63
|
-
]
|
|
64
|
-
}));
|
|
63
|
+
return(/*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Block, _extends({}, props, {
|
|
64
|
+
value: value
|
|
65
|
+
})), /*#__PURE__*/ React.createElement("button", {
|
|
66
|
+
id: `${ex.id}_button`,
|
|
67
|
+
onClick: ()=>{
|
|
68
|
+
props.methods[method.name](method.args);
|
|
69
|
+
},
|
|
70
|
+
"data-testid": "btn_method"
|
|
71
|
+
})));
|
|
65
72
|
};
|
|
66
|
-
const { container } = render(/*#__PURE__*/
|
|
67
|
-
}));
|
|
73
|
+
const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
|
|
68
74
|
expect(container.firstChild).toMatchSnapshot();
|
|
69
75
|
userEvent.click(screen.getByTestId('btn_method'));
|
|
70
76
|
mockFns.forEach((mockFn)=>{
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
/*
|
|
3
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
3
|
|
|
5
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,12 +14,26 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
15
14
|
limitations under the License.
|
|
16
15
|
*/ import React from 'react';
|
|
17
16
|
import { type } from '@lowdefy/helpers';
|
|
18
|
-
import { render } from '@testing-library/react';
|
|
17
|
+
import { render, waitFor } from '@testing-library/react';
|
|
19
18
|
import mockBlock from './mockBlock.js';
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
function _extends() {
|
|
20
|
+
_extends = Object.assign || function(target) {
|
|
21
|
+
for(var i = 1; i < arguments.length; i++){
|
|
22
|
+
var source = arguments[i];
|
|
23
|
+
for(var key in source){
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
25
|
+
target[key] = source[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
return _extends.apply(this, arguments);
|
|
32
|
+
}
|
|
33
|
+
const runMockRenderTests = ({ Block: Block1 , examples , logger , mocks , reset =()=>null
|
|
34
|
+
, schema , testConfig , })=>{
|
|
22
35
|
const { before , getProps } = mockBlock({
|
|
23
|
-
meta,
|
|
36
|
+
meta: Block1.meta,
|
|
24
37
|
logger,
|
|
25
38
|
schema
|
|
26
39
|
});
|
|
@@ -36,13 +49,16 @@ const runMockRenderTests = ({ examples , logger , meta , mocks , reset =()=>null
|
|
|
36
49
|
makeCssClass.mockReset();
|
|
37
50
|
makeCssClass.mockImplementation(makeCssImp);
|
|
38
51
|
});
|
|
39
|
-
const values = meta.values ? [
|
|
40
|
-
type.enforceType(meta.valueType, null),
|
|
41
|
-
...meta.values
|
|
42
|
-
] : [
|
|
43
|
-
type.enforceType(meta.valueType, null)
|
|
44
|
-
];
|
|
45
52
|
examples.forEach((ex)=>{
|
|
53
|
+
const values = [
|
|
54
|
+
type.enforceType(Block1.meta.valueType, null)
|
|
55
|
+
];
|
|
56
|
+
if (!type.isNone(ex.value)) {
|
|
57
|
+
values.push(ex.value);
|
|
58
|
+
}
|
|
59
|
+
if (type.isArray(testConfig.values)) {
|
|
60
|
+
values.push(...testConfig.values);
|
|
61
|
+
}
|
|
46
62
|
values.forEach((value, v)=>{
|
|
47
63
|
mocks.forEach((mock)=>{
|
|
48
64
|
test(`Mock render - ${ex.id} - value[${v}] - ${mock.name}`, async ()=>{
|
|
@@ -50,17 +66,17 @@ const runMockRenderTests = ({ examples , logger , meta , mocks , reset =()=>null
|
|
|
50
66
|
const Block = await mock.getBlock();
|
|
51
67
|
const Shell = ()=>{
|
|
52
68
|
const props = getProps(ex);
|
|
53
|
-
return(/*#__PURE__*/
|
|
54
|
-
...props,
|
|
69
|
+
return(/*#__PURE__*/ React.createElement(Block, _extends({}, props, {
|
|
55
70
|
methods: {
|
|
56
71
|
...props.methods,
|
|
57
72
|
makeCssClass
|
|
58
73
|
},
|
|
59
74
|
value: value
|
|
60
|
-
}));
|
|
75
|
+
})));
|
|
61
76
|
};
|
|
62
|
-
render(/*#__PURE__*/
|
|
63
|
-
|
|
77
|
+
const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
|
|
78
|
+
await waitFor(()=>expect(container.firstChild).toMatchSnapshot()
|
|
79
|
+
);
|
|
64
80
|
mockFns.forEach((mockFn)=>{
|
|
65
81
|
expect(mockFn.mock.calls).toMatchSnapshot();
|
|
66
82
|
});
|
package/dist/runRenderTests.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
/*
|
|
3
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
3
|
|
|
5
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,10 +16,24 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
17
16
|
import { render, waitFor } from '@testing-library/react';
|
|
18
17
|
import { type } from '@lowdefy/helpers';
|
|
19
18
|
import mockBlock from './mockBlock.js';
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
function _extends() {
|
|
20
|
+
_extends = Object.assign || function(target) {
|
|
21
|
+
for(var i = 1; i < arguments.length; i++){
|
|
22
|
+
var source = arguments[i];
|
|
23
|
+
for(var key in source){
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
25
|
+
target[key] = source[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
return _extends.apply(this, arguments);
|
|
32
|
+
}
|
|
33
|
+
const runRenderTests = ({ Block , examples , logger , reset =()=>null
|
|
34
|
+
, schema , testConfig , validationsExamples , })=>{
|
|
22
35
|
const { before , methods , getProps } = mockBlock({
|
|
23
|
-
meta,
|
|
36
|
+
meta: Block.meta,
|
|
24
37
|
logger,
|
|
25
38
|
schema
|
|
26
39
|
});
|
|
@@ -30,58 +43,52 @@ const runRenderTests = ({ Block , examples , logger , meta , reset =()=>null
|
|
|
30
43
|
});
|
|
31
44
|
examples.forEach((ex)=>{
|
|
32
45
|
const values = [
|
|
33
|
-
type.enforceType(meta.valueType, null)
|
|
46
|
+
type.enforceType(Block.meta.valueType, null)
|
|
34
47
|
];
|
|
35
48
|
if (!type.isNone(ex.value)) {
|
|
36
49
|
values.push(ex.value);
|
|
37
50
|
}
|
|
38
|
-
if (type.isArray(
|
|
39
|
-
values.push(...
|
|
51
|
+
if (type.isArray(testConfig.values)) {
|
|
52
|
+
values.push(...testConfig.values);
|
|
40
53
|
}
|
|
41
54
|
values.forEach((value, v)=>{
|
|
42
55
|
test(`Render ${ex.id} - value[${v}]`, async ()=>{
|
|
43
56
|
// create shell to setup react hooks with getProps before render;
|
|
44
|
-
const Shell = ()=>/*#__PURE__*/
|
|
45
|
-
...getProps(ex),
|
|
57
|
+
const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
|
|
46
58
|
value: value,
|
|
47
59
|
methods: methods
|
|
48
|
-
})
|
|
60
|
+
}))
|
|
49
61
|
;
|
|
50
|
-
const { container } = render(/*#__PURE__*/
|
|
51
|
-
}));
|
|
62
|
+
const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
|
|
52
63
|
await waitFor(()=>expect(container.firstChild).toMatchSnapshot()
|
|
53
64
|
);
|
|
54
65
|
});
|
|
55
|
-
if (
|
|
66
|
+
if (testConfig && testConfig.validation) {
|
|
56
67
|
(validationsExamples || []).map((validationEx)=>{
|
|
57
68
|
test(`Render validation.status = ${validationEx.status} ${ex.id} - value[${v}]`, async ()=>{
|
|
58
69
|
// create shell to setup react hooks with getProps before render;
|
|
59
|
-
const Shell = ()=>/*#__PURE__*/
|
|
60
|
-
...getProps(ex),
|
|
70
|
+
const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
|
|
61
71
|
value: value,
|
|
62
72
|
methods: methods,
|
|
63
73
|
validation: validationEx
|
|
64
|
-
})
|
|
74
|
+
}))
|
|
65
75
|
;
|
|
66
|
-
const { container } = render(/*#__PURE__*/
|
|
67
|
-
}));
|
|
76
|
+
const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
|
|
68
77
|
await waitFor(()=>expect(container.firstChild).toMatchSnapshot()
|
|
69
78
|
);
|
|
70
79
|
});
|
|
71
80
|
});
|
|
72
81
|
}
|
|
73
|
-
if (
|
|
82
|
+
if (testConfig && testConfig.required) {
|
|
74
83
|
test(`Render required = true ${ex.id} - value[${v}]`, async ()=>{
|
|
75
84
|
// create shell to setup react hooks with getProps before render;
|
|
76
|
-
const Shell = ()=>/*#__PURE__*/
|
|
77
|
-
...getProps(ex),
|
|
85
|
+
const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
|
|
78
86
|
value: value,
|
|
79
87
|
methods: methods,
|
|
80
88
|
required: true
|
|
81
|
-
})
|
|
89
|
+
}))
|
|
82
90
|
;
|
|
83
|
-
const { container } = render(/*#__PURE__*/
|
|
84
|
-
}));
|
|
91
|
+
const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
|
|
85
92
|
await waitFor(()=>expect(container.firstChild).toMatchSnapshot()
|
|
86
93
|
);
|
|
87
94
|
});
|
package/dist/schemaTest.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -16,13 +16,11 @@
|
|
|
16
16
|
import AjvErrors from 'ajv-errors';
|
|
17
17
|
import { blockSchema } from '@lowdefy/block-utils';
|
|
18
18
|
const testSchemaProperties = {
|
|
19
|
-
value: {
|
|
20
|
-
},
|
|
19
|
+
value: {},
|
|
21
20
|
methods: {
|
|
22
21
|
type: 'object'
|
|
23
22
|
},
|
|
24
|
-
schemaErrors: {
|
|
25
|
-
},
|
|
23
|
+
schemaErrors: {},
|
|
26
24
|
eventLog: {
|
|
27
25
|
type: 'array'
|
|
28
26
|
},
|
package/dist/stubBlockProps.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
/*
|
|
3
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
3
|
|
|
5
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,30 +16,30 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
17
16
|
import { type } from '@lowdefy/helpers';
|
|
18
17
|
import { makeCssClass, createIcon } from '@lowdefy/block-utils';
|
|
19
18
|
import schemaTest from './schemaTest.js';
|
|
20
|
-
const validate = {
|
|
21
|
-
};
|
|
19
|
+
const validate = {};
|
|
22
20
|
const Icons = {
|
|
23
|
-
AiIcon: (props)=>/*#__PURE__*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
21
|
+
AiIcon: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
|
|
22
|
+
"data-testid": "AiIcon",
|
|
23
|
+
onClick: onClick
|
|
24
|
+
}, "ICON PROPS: ", JSON.stringify(props))
|
|
27
25
|
,
|
|
28
|
-
AiOutlineExclamationCircle: (props)=>/*#__PURE__*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
26
|
+
AiOutlineExclamationCircle: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
|
|
27
|
+
"data-testid": "AiOutlineExclamationCircle",
|
|
28
|
+
onClick: onClick
|
|
29
|
+
}, "ICON PROPS: ", JSON.stringify(props))
|
|
32
30
|
,
|
|
33
|
-
AiOutlineLoading3Quarters: (props)=>/*#__PURE__*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
31
|
+
AiOutlineLoading3Quarters: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
|
|
32
|
+
"data-testid": "AiOutlineLoading3Quarters",
|
|
33
|
+
onClick: onClick
|
|
34
|
+
}, "ICON PROPS: ", JSON.stringify(props))
|
|
37
35
|
,
|
|
38
36
|
ErrorIcon: ()=>{
|
|
39
37
|
throw new Error('ErrorIcon');
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
const IconComponent = createIcon(Icons);
|
|
43
|
-
const stubBlockProps = ({ block , meta , logger
|
|
41
|
+
const stubBlockProps = ({ block , meta , logger =()=>null
|
|
42
|
+
, initialValue , schema })=>{
|
|
44
43
|
const [value, setState] = useState(type.enforceType(meta.valueType, block.value || initialValue));
|
|
45
44
|
const setValue = (val)=>{
|
|
46
45
|
setState(type.enforceType(meta.valueType, val));
|
|
@@ -60,22 +59,18 @@ const stubBlockProps = ({ block , meta , logger , initialValue , schema })=>{
|
|
|
60
59
|
// block defaults
|
|
61
60
|
block.blockId = block.id;
|
|
62
61
|
if (meta.category === 'list' || meta.category === 'container' || meta.category === 'context') {
|
|
63
|
-
if (!block.areas) block.areas = {
|
|
64
|
-
};
|
|
65
|
-
if (!block.areas.content) block.areas.content = {
|
|
66
|
-
};
|
|
62
|
+
if (!block.areas) block.areas = {};
|
|
63
|
+
if (!block.areas.content) block.areas.content = {};
|
|
67
64
|
if (block.blocks) block.areas.content.blocks = block.blocks;
|
|
68
65
|
}
|
|
69
|
-
block.events = block.events || {
|
|
70
|
-
};
|
|
66
|
+
block.events = block.events || {};
|
|
71
67
|
block.eventLog = [];
|
|
72
68
|
block.components = {
|
|
73
69
|
Icon: IconComponent,
|
|
74
|
-
Link: (props)=>/*#__PURE__*/
|
|
75
|
-
"data-testid":
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
70
|
+
Link: ({ id , children , onClick , ...props })=>/*#__PURE__*/ React.createElement("a", {
|
|
71
|
+
"data-testid": id,
|
|
72
|
+
onClick: onClick
|
|
73
|
+
}, "LINK PROPS:", JSON.stringify(props), " - CHILDREN: ", children('default_title'))
|
|
79
74
|
};
|
|
80
75
|
// mock default block methods
|
|
81
76
|
block.methods = {
|
|
@@ -95,13 +90,13 @@ const stubBlockProps = ({ block , meta , logger , initialValue , schema })=>{
|
|
|
95
90
|
block.list = [];
|
|
96
91
|
(block.areas.content.blocks || []).forEach((bl, i)=>{
|
|
97
92
|
block.list.push({
|
|
98
|
-
content: ()=>/*#__PURE__*/
|
|
93
|
+
content: ()=>/*#__PURE__*/ React.createElement("div", {
|
|
99
94
|
"data-testid": `list-${i}-${bl.id}`,
|
|
95
|
+
key: bl.id,
|
|
100
96
|
style: {
|
|
101
97
|
border: '1px solid red',
|
|
102
98
|
padding: 10
|
|
103
|
-
}
|
|
104
|
-
children: bl.id
|
|
99
|
+
}
|
|
105
100
|
}, bl.id)
|
|
106
101
|
});
|
|
107
102
|
});
|
|
@@ -120,16 +115,15 @@ const stubBlockProps = ({ block , meta , logger , initialValue , schema })=>{
|
|
|
120
115
|
};
|
|
121
116
|
}
|
|
122
117
|
if (meta.category === 'container') {
|
|
123
|
-
block.content = {
|
|
124
|
-
};
|
|
118
|
+
block.content = {};
|
|
125
119
|
Object.keys(block.areas).forEach((key)=>{
|
|
126
|
-
block.content[key] = ()=>/*#__PURE__*/
|
|
120
|
+
block.content[key] = ()=>/*#__PURE__*/ React.createElement("div", {
|
|
127
121
|
"data-testid": `area-${key}`,
|
|
122
|
+
key: key,
|
|
128
123
|
style: {
|
|
129
124
|
border: '1px solid red',
|
|
130
125
|
padding: 10
|
|
131
|
-
}
|
|
132
|
-
children: key
|
|
126
|
+
}
|
|
133
127
|
}, key)
|
|
134
128
|
;
|
|
135
129
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/block-dev",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.12",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy Block Development Tools",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@emotion/jest": "11.
|
|
41
|
-
"@lowdefy/block-utils": "4.0.0-alpha.
|
|
42
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
43
|
-
"@testing-library/dom": "8.
|
|
40
|
+
"@emotion/jest": "11.7.1",
|
|
41
|
+
"@lowdefy/block-utils": "4.0.0-alpha.12",
|
|
42
|
+
"@lowdefy/helpers": "4.0.0-alpha.12",
|
|
43
|
+
"@testing-library/dom": "8.11.3",
|
|
44
44
|
"@testing-library/react": "13.0.0-alpha.4",
|
|
45
45
|
"@testing-library/user-event": "14.0.0-alpha.14",
|
|
46
|
-
"ajv": "8.
|
|
46
|
+
"ajv": "8.9.0",
|
|
47
47
|
"ajv-errors": "3.0.0",
|
|
48
|
-
"jest": "27.
|
|
48
|
+
"jest": "27.5.1",
|
|
49
49
|
"jest-serializer-html": "7.1.0",
|
|
50
|
-
"react": "
|
|
51
|
-
"react-dom": "
|
|
50
|
+
"react": "17.0.2",
|
|
51
|
+
"react-dom": "17.0.2",
|
|
52
52
|
"yaml-loader": "0.6.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@swc/cli": "0.1.
|
|
56
|
-
"@swc/core": "1.2.
|
|
55
|
+
"@swc/cli": "0.1.55",
|
|
56
|
+
"@swc/core": "1.2.135"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "41b6138a81bee7da362dad06345bc9f87b2c2133"
|
|
62
62
|
}
|