@lowdefy/block-dev 4.0.0-alpha.28 → 4.0.0-alpha.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/block-dev",
3
- "version": "4.0.0-alpha.28",
3
+ "version": "4.0.0-alpha.29",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Block Development Tools",
6
6
  "homepage": "https://lowdefy.com",
@@ -31,15 +31,14 @@
31
31
  "dist/*"
32
32
  ],
33
33
  "scripts": {
34
- "build": "yarn swc",
34
+ "build": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
35
35
  "clean": "rm -rf dist",
36
- "prepare": "yarn build",
37
- "swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start"
36
+ "prepublishOnly": "pnpm build"
38
37
  },
39
38
  "dependencies": {
40
39
  "@emotion/jest": "11.9.1",
41
- "@lowdefy/block-utils": "4.0.0-alpha.28",
42
- "@lowdefy/helpers": "4.0.0-alpha.28",
40
+ "@lowdefy/block-utils": "4.0.0-alpha.29",
41
+ "@lowdefy/helpers": "4.0.0-alpha.29",
43
42
  "@testing-library/dom": "8.13.0",
44
43
  "@testing-library/react": "13.3.0",
45
44
  "@testing-library/user-event": "14.2.0",
@@ -58,5 +57,5 @@
58
57
  "publishConfig": {
59
58
  "access": "public"
60
59
  },
61
- "gitHead": "d0bad6be18362c0ceea1c18239c61bba0ba59300"
60
+ "gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
62
61
  }
@@ -1,30 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import React from 'react';
16
- const BlockSchemaErrors = ({ schemaErrors })=>{
17
- if (!schemaErrors || schemaErrors.length === 0) return '';
18
- return /*#__PURE__*/ React.createElement("div", {
19
- style: {
20
- padding: 10,
21
- fontSize: '0.8rem',
22
- border: '1px solid red',
23
- background: '#fBB',
24
- width: '100%'
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
- };
30
- export default BlockSchemaErrors;
package/dist/index.js DELETED
@@ -1,22 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import BlockSchemaErrors from './BlockSchemaErrors.js';
16
- import mockBlock from './mockBlock.js';
17
- import runBlockSchemaTests from './runBlockSchemaTests.js';
18
- import runMockMethodTests from './runMockMethodTests.js';
19
- import runMockRenderTests from './runMockRenderTests.js';
20
- import runRenderTests from './runRenderTests.js';
21
- import stubBlockProps from './stubBlockProps.js';
22
- export { BlockSchemaErrors, mockBlock, runBlockSchemaTests, runMockMethodTests, runMockRenderTests, runRenderTests, stubBlockProps };
package/dist/mockBlock.js DELETED
@@ -1,97 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import { makeCssClass } from '@lowdefy/block-utils';
16
- import stubBlockProps from './stubBlockProps.js';
17
- const mockBlock = ({ meta , schema })=>{
18
- const mockMath = Object.create(global.Math);
19
- mockMath.random = ()=>0.5;
20
- global.Math = mockMath;
21
- const moveItemDown = jest.fn();
22
- const moveItemUp = jest.fn();
23
- const pushItem = jest.fn();
24
- const registerEvent = jest.fn();
25
- const registerMethod = jest.fn();
26
- const removeItem = jest.fn();
27
- const setValue = jest.fn();
28
- const triggerEvent = jest.fn();
29
- const unshiftItem = jest.fn();
30
- const methods = {
31
- makeCssClass,
32
- moveItemDown,
33
- moveItemUp,
34
- pushItem,
35
- registerEvent,
36
- registerMethod,
37
- removeItem,
38
- setValue,
39
- triggerEvent,
40
- unshiftItem
41
- };
42
- const before = ()=>{
43
- triggerEvent.mockReset();
44
- moveItemDown.mockReset();
45
- moveItemUp.mockReset();
46
- pushItem.mockReset();
47
- registerMethod.mockReset();
48
- registerEvent.mockReset();
49
- removeItem.mockReset();
50
- setValue.mockReset();
51
- unshiftItem.mockReset();
52
- // for antd from:
53
- // https://github.com/ant-design/ant-design/blob/master/tests/setup.js
54
- // ref: https://github.com/ant-design/ant-design/issues/18774
55
- if (!window.matchMedia) {
56
- Object.defineProperty(window, 'matchMedia', {
57
- writable: true,
58
- value: jest.fn().mockImplementation((query)=>({
59
- matches: false,
60
- media: query.includes('max-width'),
61
- onchange: null,
62
- addListener: jest.fn(),
63
- removeListener: jest.fn(),
64
- addEventListener: jest.fn(),
65
- removeEventListener: jest.fn(),
66
- dispatchEvent: jest.fn()
67
- }))
68
- });
69
- }
70
- if (typeof window !== 'undefined') {
71
- window.resizeTo = (width, height)=>{
72
- window.innerWidth = width || window.innerWidth;
73
- window.innerHeight = height || window.innerHeight;
74
- window.dispatchEvent(new Event('resize'));
75
- };
76
- window.scrollTo = ()=>{};
77
- // Fix css-animation or rc-motion deps on these
78
- // https://github.com/react-component/motion/blob/9c04ef1a210a4f3246c9becba6e33ea945e00669/src/util/motion.ts#L27-L35
79
- // https://github.com/yiminghe/css-animation/blob/a5986d73fd7dfce75665337f39b91483d63a4c8c/src/Event.js#L44
80
- window.AnimationEvent = window.AnimationEvent || (()=>{});
81
- window.TransitionEvent = window.TransitionEvent || (()=>{});
82
- }
83
- };
84
- const getProps = (block)=>{
85
- return stubBlockProps({
86
- block,
87
- meta,
88
- schema
89
- });
90
- };
91
- return {
92
- before,
93
- methods,
94
- getProps
95
- };
96
- };
97
- export default mockBlock;
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import schemaTest from './schemaTest.js';
16
- const runBlockSchemaTests = ({ examples , schema })=>{
17
- const validate = schemaTest(schema);
18
- examples.forEach((block)=>{
19
- test(`Test Schema ${block.id}`, ()=>{
20
- const valid = validate(block);
21
- expect(valid).toMatchSnapshot();
22
- expect(validate.errors).toMatchSnapshot();
23
- });
24
- });
25
- };
26
- export default runBlockSchemaTests;
@@ -1,86 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- /*
16
- Copyright 2020-2022 Lowdefy, Inc
17
-
18
- Licensed under the Apache License, Version 2.0 (the "License");
19
- you may not use this file except in compliance with the License.
20
- You may obtain a copy of the License at
21
-
22
- http://www.apache.org/licenses/LICENSE-2.0
23
-
24
- Unless required by applicable law or agreed to in writing, software
25
- distributed under the License is distributed on an "AS IS" BASIS,
26
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- See the License for the specific language governing permissions and
28
- limitations under the License.
29
- */ import React from 'react';
30
- import { type } from '@lowdefy/helpers';
31
- import { render, screen } from '@testing-library/react';
32
- import userEvent from '@testing-library/user-event';
33
- import mockBlock from './mockBlock.js';
34
- const runMockMethodTests = ({ Block: Block1 , examples , mocks , schema , testConfig })=>{
35
- const meta = Block1.meta;
36
- const { before , methods , getProps } = mockBlock({
37
- meta,
38
- schema
39
- });
40
- beforeEach(()=>{
41
- before();
42
- });
43
- const values = meta.values ? [
44
- type.enforceType(meta.valueType, null),
45
- ...meta.values
46
- ] : [
47
- type.enforceType(meta.valueType, null)
48
- ];
49
- examples.forEach((ex)=>{
50
- values.forEach((value, v)=>{
51
- if (testConfig && testConfig.methods) {
52
- testConfig.methods.forEach((method)=>{
53
- mocks.forEach((mock)=>{
54
- test(`Mock for method: ${JSON.stringify(method)} - ${ex.id} - value[${v}] - ${mock.name}`, async ()=>{
55
- const mockFns = await mock.getMockFns();
56
- const Block = await mock.getBlock();
57
- const Shell = ()=>{
58
- const props = getProps(ex);
59
- props.methods = {
60
- ...methods,
61
- registerMethod: props.methods.registerMethod
62
- };
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
- }));
72
- };
73
- const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
74
- expect(container.firstChild).toMatchSnapshot();
75
- userEvent.click(screen.getByTestId('btn_method'));
76
- mockFns.forEach((mockFn)=>{
77
- expect(mockFn.mock.calls).toMatchSnapshot();
78
- });
79
- });
80
- });
81
- });
82
- }
83
- });
84
- });
85
- };
86
- export default runMockMethodTests;
@@ -1,85 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- /*
16
- Copyright 2020-2022 Lowdefy, Inc
17
-
18
- Licensed under the Apache License, Version 2.0 (the "License");
19
- you may not use this file except in compliance with the License.
20
- You may obtain a copy of the License at
21
-
22
- http://www.apache.org/licenses/LICENSE-2.0
23
-
24
- Unless required by applicable law or agreed to in writing, software
25
- distributed under the License is distributed on an "AS IS" BASIS,
26
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- See the License for the specific language governing permissions and
28
- limitations under the License.
29
- */ import React from 'react';
30
- import { type } from '@lowdefy/helpers';
31
- import { render, waitFor } from '@testing-library/react';
32
- import mockBlock from './mockBlock.js';
33
- const runMockRenderTests = ({ Block: Block1 , examples , logger , mocks , reset =()=>null , schema , testConfig , })=>{
34
- const { before , getProps } = mockBlock({
35
- meta: Block1.meta,
36
- logger,
37
- schema
38
- });
39
- const makeCssClass = jest.fn();
40
- const makeCssImp = (style, op)=>JSON.stringify({
41
- style,
42
- options: op
43
- });
44
- beforeEach(async ()=>{
45
- await reset();
46
- before();
47
- makeCssClass.mockReset();
48
- makeCssClass.mockImplementation(makeCssImp);
49
- });
50
- examples.forEach((ex)=>{
51
- const values = [
52
- type.enforceType(Block1.meta.valueType, null)
53
- ];
54
- if (!type.isNone(ex.value)) {
55
- values.push(ex.value);
56
- }
57
- if (type.isArray(testConfig.values)) {
58
- values.push(...testConfig.values);
59
- }
60
- values.forEach((value, v)=>{
61
- mocks.forEach((mock)=>{
62
- test(`Mock render - ${ex.id} - value[${v}] - ${mock.name}`, async ()=>{
63
- const mockFns = await mock.getMockFns();
64
- const Block = await mock.getBlock();
65
- const Shell = ()=>{
66
- const props = getProps(ex);
67
- return /*#__PURE__*/ React.createElement(Block, _extends({}, props, {
68
- methods: {
69
- ...props.methods,
70
- makeCssClass
71
- },
72
- value: value
73
- }));
74
- };
75
- const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
76
- await waitFor(()=>expect(container.firstChild).toMatchSnapshot());
77
- mockFns.forEach((mockFn)=>{
78
- expect(mockFn.mock.calls).toMatchSnapshot();
79
- });
80
- });
81
- });
82
- });
83
- });
84
- };
85
- export default runMockRenderTests;
@@ -1,92 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source){
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- /*
16
- Copyright 2020-2022 Lowdefy, Inc
17
-
18
- Licensed under the Apache License, Version 2.0 (the "License");
19
- you may not use this file except in compliance with the License.
20
- You may obtain a copy of the License at
21
-
22
- http://www.apache.org/licenses/LICENSE-2.0
23
-
24
- Unless required by applicable law or agreed to in writing, software
25
- distributed under the License is distributed on an "AS IS" BASIS,
26
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- See the License for the specific language governing permissions and
28
- limitations under the License.
29
- */ import React from 'react';
30
- import { render, waitFor } from '@testing-library/react';
31
- import { type } from '@lowdefy/helpers';
32
- import mockBlock from './mockBlock.js';
33
- const runRenderTests = ({ Block , examples , logger , reset =()=>null , schema , testConfig , validationsExamples , })=>{
34
- const { before , methods , getProps } = mockBlock({
35
- meta: Block.meta,
36
- logger,
37
- schema
38
- });
39
- beforeEach(()=>{
40
- reset();
41
- before();
42
- });
43
- examples.forEach((ex)=>{
44
- const values = [
45
- type.enforceType(Block.meta.valueType, null)
46
- ];
47
- if (!type.isNone(ex.value)) {
48
- values.push(ex.value);
49
- }
50
- if (type.isArray(testConfig.values)) {
51
- values.push(...testConfig.values);
52
- }
53
- values.forEach((value, v)=>{
54
- test(`Render ${ex.id} - value[${v}]`, async ()=>{
55
- // create shell to setup react hooks with getProps before render;
56
- const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
57
- value: value,
58
- methods: methods
59
- }));
60
- const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
61
- await waitFor(()=>expect(container.firstChild).toMatchSnapshot());
62
- });
63
- if (testConfig && testConfig.validation) {
64
- (validationsExamples || []).map((validationEx)=>{
65
- test(`Render validation.status = ${validationEx.status} ${ex.id} - value[${v}]`, async ()=>{
66
- // create shell to setup react hooks with getProps before render;
67
- const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
68
- value: value,
69
- methods: methods,
70
- validation: validationEx
71
- }));
72
- const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
73
- await waitFor(()=>expect(container.firstChild).toMatchSnapshot());
74
- });
75
- });
76
- }
77
- if (testConfig && testConfig.required) {
78
- test(`Render required = true ${ex.id} - value[${v}]`, async ()=>{
79
- // create shell to setup react hooks with getProps before render;
80
- const Shell = ()=>/*#__PURE__*/ React.createElement(Block, _extends({}, getProps(ex), {
81
- value: value,
82
- methods: methods,
83
- required: true
84
- }));
85
- const { container } = render(/*#__PURE__*/ React.createElement(Shell, null));
86
- await waitFor(()=>expect(container.firstChild).toMatchSnapshot());
87
- });
88
- }
89
- });
90
- });
91
- };
92
- export default runRenderTests;
@@ -1,60 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import Ajv from 'ajv';
16
- import AjvErrors from 'ajv-errors';
17
- import { blockSchema } from '@lowdefy/block-utils';
18
- const testSchemaProperties = {
19
- value: {},
20
- methods: {
21
- type: 'object'
22
- },
23
- schemaErrors: {},
24
- eventLog: {
25
- type: 'array'
26
- },
27
- pageId: {
28
- type: 'string'
29
- },
30
- blockId: {
31
- type: 'string'
32
- },
33
- content: {
34
- type: 'object'
35
- },
36
- list: {
37
- type: 'array'
38
- }
39
- };
40
- const initAjv = (options)=>{
41
- const ajv = new Ajv({
42
- allErrors: true,
43
- strict: false,
44
- ...options
45
- });
46
- AjvErrors(ajv, options);
47
- return ajv;
48
- };
49
- const ajvInstance = initAjv();
50
- const sch = JSON.parse(JSON.stringify(blockSchema));
51
- const schemaTest = (schema)=>{
52
- sch.properties = {
53
- ...sch.properties,
54
- ...schema.properties.properties,
55
- ...testSchemaProperties
56
- };
57
- sch.additionalProperties = true;
58
- return ajvInstance.compile(sch);
59
- };
60
- export default schemaTest;
@@ -1,130 +0,0 @@
1
- /*
2
- Copyright 2020-2022 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */ import React, { useState } from 'react';
16
- import { type } from '@lowdefy/helpers';
17
- import { makeCssClass, createIcon } from '@lowdefy/block-utils';
18
- import schemaTest from './schemaTest.js';
19
- const validate = {};
20
- const Icons = {
21
- AiIcon: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
22
- "data-testid": "AiIcon",
23
- onClick: onClick
24
- }, "ICON PROPS: ", JSON.stringify(props)),
25
- AiOutlineExclamationCircle: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
26
- "data-testid": "AiOutlineExclamationCircle",
27
- onClick: onClick
28
- }, "ICON PROPS: ", JSON.stringify(props)),
29
- AiOutlineLoading3Quarters: ({ onClick , ...props })=>/*#__PURE__*/ React.createElement("svg", {
30
- "data-testid": "AiOutlineLoading3Quarters",
31
- onClick: onClick
32
- }, "ICON PROPS: ", JSON.stringify(props)),
33
- ErrorIcon: ()=>{
34
- throw new Error('ErrorIcon');
35
- }
36
- };
37
- const IconComponent = createIcon(Icons);
38
- const stubBlockProps = ({ block , meta , logger =()=>null , initialValue , schema })=>{
39
- const [value, setState] = useState(type.enforceType(meta.valueType, block.value || initialValue));
40
- const setValue = (val)=>{
41
- setState(type.enforceType(meta.valueType, val));
42
- };
43
- let log = alert;
44
- if (logger) log = logger;
45
- // evaluate block schema
46
- if (!validate[block.type]) {
47
- try {
48
- validate[block.type] = schemaTest(schema);
49
- } catch (error) {
50
- throw new Error(`Schema error in ${block.type} - ${error.message}`);
51
- }
52
- }
53
- block.schemaErrors = !validate[block.type](block);
54
- if (block.schemaErrors) block.schemaErrors = validate[block.type].errors;
55
- // block defaults
56
- block.blockId = block.id;
57
- if (meta.category === 'list' || meta.category === 'container' || meta.category === 'context') {
58
- if (!block.areas) block.areas = {};
59
- if (!block.areas.content) block.areas.content = {};
60
- if (block.blocks) block.areas.content.blocks = block.blocks;
61
- }
62
- block.events = block.events || {};
63
- block.eventLog = [];
64
- block.components = {
65
- Icon: IconComponent,
66
- Link: ({ id , children , onClick , ...props })=>/*#__PURE__*/ React.createElement("a", {
67
- "data-testid": id,
68
- onClick: onClick
69
- }, "LINK PROPS:", JSON.stringify(props), " - CHILDREN: ", children('default_title'))
70
- };
71
- // mock default block methods
72
- block.methods = {
73
- makeCssClass,
74
- registerEvent: ({ name , actions })=>{
75
- block.events[name] = actions;
76
- return;
77
- },
78
- registerMethod: (method, methodFn)=>{
79
- block.methods[method] = methodFn;
80
- return;
81
- },
82
- triggerEvent: (event)=>block.eventLog.unshift(event)
83
- };
84
- // block category defaults
85
- if (meta.category === 'list') {
86
- block.list = [];
87
- (block.areas.content.blocks || []).forEach((bl, i)=>{
88
- block.list.push({
89
- content: ()=>/*#__PURE__*/ React.createElement("div", {
90
- "data-testid": `list-${i}-${bl.id}`,
91
- key: bl.id,
92
- style: {
93
- border: '1px solid red',
94
- padding: 10
95
- }
96
- }, bl.id)
97
- });
98
- });
99
- block.methods = {
100
- pushItem: ()=>log('List pushItem'),
101
- unshiftItem: ()=>log('List unshiftItem'),
102
- removeItem: (i)=>log(`List removeItem ${i}`),
103
- moveItemDown: (i)=>log(`List moveItemDown ${i}`),
104
- moveItemUp: (i)=>log(`List moveItemUp ${i}`),
105
- ...block.methods
106
- };
107
- }
108
- if (meta.category === 'container') {
109
- block.content = {};
110
- Object.keys(block.areas).forEach((key)=>{
111
- block.content[key] = ()=>/*#__PURE__*/ React.createElement("div", {
112
- "data-testid": `area-${key}`,
113
- key: key,
114
- style: {
115
- border: '1px solid red',
116
- padding: 10
117
- }
118
- }, key);
119
- });
120
- }
121
- if (meta.category === 'input') {
122
- block.methods = {
123
- setValue,
124
- ...block.methods
125
- };
126
- block.value = value;
127
- }
128
- return block;
129
- };
130
- export default stubBlockProps;