Merge pull request #107 from lowdefy/blockDefaults

change to blockDefaultProps and stubBlockProps
This commit is contained in:
Gervwyk 2020-10-30 17:38:51 +02:00 committed by GitHub
commit 3616c336f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 213 additions and 438 deletions

22
.pnp.js generated
View File

@ -3660,8 +3660,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["identity-obj-proxy", "npm:3.0.0"],
["jest", "npm:26.6.1"],
["js-yaml", "npm:3.14.0"],
["less", "npm:3.12.2"],
["less-loader", "virtual:22157ea722f8d6428f1fcf0a6f7f6c7d6b902d9c785256c60a65fe6cd0db76ebccc7c1457ee047df0ba6909ff018e300c4f4957a60f5b670089810dfc417af9b#npm:7.0.2"],
["path-browserify", "npm:1.0.1"],
["process", "npm:0.11.10"],
["react", "npm:17.0.1"],
@ -15140,26 +15138,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]
]],
["less-loader", [
["virtual:22157ea722f8d6428f1fcf0a6f7f6c7d6b902d9c785256c60a65fe6cd0db76ebccc7c1457ee047df0ba6909ff018e300c4f4957a60f5b670089810dfc417af9b#npm:7.0.2", {
"packageLocation": "./.yarn/$$virtual/less-loader-virtual-aaf864cf4e/0/cache/less-loader-npm-7.0.2-e98973222a-e9e294a02e.zip/node_modules/less-loader/",
"packageDependencies": [
["less-loader", "virtual:22157ea722f8d6428f1fcf0a6f7f6c7d6b902d9c785256c60a65fe6cd0db76ebccc7c1457ee047df0ba6909ff018e300c4f4957a60f5b670089810dfc417af9b#npm:7.0.2"],
["@types/less", null],
["@types/webpack", null],
["klona", "npm:2.0.4"],
["less", "npm:3.12.2"],
["loader-utils", "npm:2.0.0"],
["schema-utils", "npm:3.0.0"],
["webpack", "virtual:22157ea722f8d6428f1fcf0a6f7f6c7d6b902d9c785256c60a65fe6cd0db76ebccc7c1457ee047df0ba6909ff018e300c4f4957a60f5b670089810dfc417af9b#npm:5.3.2"]
],
"packagePeers": [
"@types/less",
"@types/webpack",
"less",
"webpack"
],
"linkType": "HARD",
}],
["virtual:54dfdd95092c538917b1daf717721dd3beca716f0768958f8123e1439693d909b26a74c88b3fb65b402559e626be2accab32554fb8a3874e699047fe18793f5e#npm:7.0.2", {
"packageLocation": "./.yarn/$$virtual/less-loader-virtual-a9ca0ffaf5/0/cache/less-loader-npm-7.0.2-e98973222a-e9e294a02e.zip/node_modules/less-loader/",
"packageDependencies": [

View File

@ -16,17 +16,15 @@
import React from 'react';
import { render } from 'react-dom';
import {
IconSpinner,
Skeleton,
SkeletonAvatar,
SkeletonButton,
SkeletonInput,
SkeletonParagraph,
Spinner,
makeCssClass,
ErrorBoundary,
} from '../src';
import IconSpinner from '../src/Spinner/IconSpinner';
import Spinner from '../src/Spinner/Spinner';
import Skeleton from '../src/Skeleton/Skeleton';
import SkeletonAvatar from '../src/Skeleton/SkeletonAvatar';
import SkeletonButton from '../src/Skeleton/SkeletonButton';
import SkeletonInput from '../src/Skeleton/SkeletonInput';
import SkeletonParagraph from '../src/Skeleton/SkeletonParagraph';
import makeCssClass from '../src/makeCssClass';
import ErrorBoundary from '../src/ErrorBoundary';
import IconSpinnerEx from './examples/IconSpinner.yaml';
import SkeletonEx from './examples/Skeleton.yaml';
import SkeletonAvatarEx from './examples/SkeletonAvatar.yaml';

View File

@ -1,6 +1,6 @@
{
"name": "@lowdefy/block-tools",
"version": "1.0.1-alpha.9",
"version": "1.0.1-alpha.13",
"licence": "Apache-2.0",
"description": "Lowdefy Block Tools",
"homepage": "https://lowdefy.com",
@ -64,8 +64,6 @@
"identity-obj-proxy": "3.0.0",
"jest": "26.6.1",
"js-yaml": "3.14.0",
"less": "3.12.2",
"less-loader": "7.0.2",
"path-browserify": "1.0.1",
"process": "0.11.10",
"react": "17.0.1",

View File

@ -15,11 +15,10 @@
*/
import React from 'react';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import './Skeleton.css';
const Skeleton = (props) => {
const { properties, methods } = blockDefaults(props);
const Skeleton = ({ properties, methods }) => {
return (
<div
className={'skeleton ' + methods.makeCssClass(properties.style)}
@ -28,4 +27,6 @@ const Skeleton = (props) => {
);
};
Skeleton.defaultProps = blockDefaultProps;
export default Skeleton;

View File

@ -16,11 +16,10 @@
import React from 'react';
import { type } from '@lowdefy/helpers';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import Skeleton from './Skeleton';
const SkeletonAvatar = (props) => {
const { properties, methods } = blockDefaults(props);
const SkeletonAvatar = ({ properties, methods }) => {
let size = properties.size || 32;
if (type.isString(size)) {
switch (properties.size) {
@ -46,4 +45,6 @@ const SkeletonAvatar = (props) => {
);
};
SkeletonAvatar.defaultProps = blockDefaultProps;
export default SkeletonAvatar;

View File

@ -15,11 +15,10 @@
*/
import React from 'react';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import Skeleton from './Skeleton';
const SkeletonButton = (props) => {
const { properties, methods } = blockDefaults(props);
const SkeletonButton = ({ properties, methods }) => {
let height = properties.height || 32;
switch (properties.size) {
case 'small':
@ -43,4 +42,6 @@ const SkeletonButton = (props) => {
);
};
SkeletonButton.defaultProps = blockDefaultProps;
export default SkeletonButton;

View File

@ -15,11 +15,10 @@
*/
import React from 'react';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import Skeleton from './Skeleton';
const SkeletonInput = (props) => {
const { properties, methods } = blockDefaults(props);
const SkeletonInput = ({ properties, methods }) => {
let inputHeight;
switch (properties.size) {
case 'small':
@ -54,4 +53,6 @@ const SkeletonInput = (props) => {
);
};
SkeletonInput.defaultProps = blockDefaultProps;
export default SkeletonInput;

View File

@ -15,11 +15,10 @@
*/
import React from 'react';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import Skeleton from './Skeleton';
const SkeletonParagraph = (props) => {
const { properties, methods } = blockDefaults(props);
const SkeletonParagraph = ({ properties, methods }) => {
const lines = [...Array(properties.lines || 4).keys()];
return (
<div style={{ width: properties.width || '100%' }}>
@ -38,4 +37,6 @@ const SkeletonParagraph = (props) => {
);
};
SkeletonParagraph.defaultProps = blockDefaultProps;
export default SkeletonParagraph;

View File

@ -16,12 +16,10 @@
import React from 'react';
import { type } from '@lowdefy/helpers';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
import './IconSpinner.css';
const IconSpinner = (props) => {
const { properties, methods } = blockDefaults(props);
const IconSpinner = ({ properties, methods }) => {
let size = properties.size || 20;
if (type.isString(size)) {
switch (properties.size) {
@ -63,4 +61,6 @@ const IconSpinner = (props) => {
);
};
IconSpinner.defaultProps = blockDefaultProps;
export default IconSpinner;

View File

@ -16,10 +16,9 @@
import React from 'react';
import LogoSpinner from './LogoSpinner';
import blockDefaults from '../blockDefaults';
import blockDefaultProps from '../blockDefaultProps';
const Loading = (props) => {
const { properties, methods } = blockDefaults(props);
const Spinner = ({ properties, methods }) => {
return (
<div
className={methods.makeCssClass({
@ -52,4 +51,6 @@ const Loading = (props) => {
);
};
export default Loading;
Spinner.defaultProps = blockDefaultProps;
export default Spinner;

View File

@ -0,0 +1,36 @@
/*
Copyright 2020 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import makeCssClass from './makeCssClass';
const blockDefaultProps = {
actions: {},
blockId: 'undefined_id',
content: {},
list: [],
menus: [],
methods: {
callAction: () => undefined,
registerAction: () => undefined,
registerMethod: () => undefined,
makeCssClass: makeCssClass,
},
properties: {},
user: {},
validate: [],
};
export default blockDefaultProps;

View File

@ -0,0 +1,58 @@
/*
Copyright 2020 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import blockDefaultProps from './blockDefaultProps';
import makeCssClass from './makeCssClass';
const makeCssImp = (style, op) => JSON.stringify({ style, options: op });
jest.mock('./makeCssClass', () => {
const makeCssClass = jest.fn();
return { default: makeCssClass, __esModule: true };
});
beforeEach(() => {
makeCssClass.mockReset();
makeCssClass.mockImplementation(makeCssImp);
});
test('default', () => {
expect(blockDefaultProps).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "undefined_id",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [MockFunction],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('call default methods', () => {
expect(blockDefaultProps.methods.callAction()).toEqual(undefined);
expect(blockDefaultProps.methods.registerAction()).toEqual(undefined);
expect(blockDefaultProps.methods.registerMethod()).toEqual(undefined);
expect(blockDefaultProps.methods.makeCssClass({ a: 1 })).toEqual('{"style":{"a":1}}');
});

View File

@ -1,42 +0,0 @@
/*
Copyright 2020 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import makeCssClass from './makeCssClass';
const noMethod = () => undefined;
const defaultMethods = (methods) => ({
makeCssClass,
callAction: methods.callAction || noMethod,
registerAction: methods.registerAction || noMethod,
registerMethod: methods.registerMethod || noMethod,
...methods,
});
const blockDefaults = (props = {}) => ({
...props,
actions: props.actions || {},
blockId: props.id || props.blockId || 'undefined_id',
content: props.content || {},
list: props.list || [],
menus: props.menus || [],
methods: defaultMethods(props.methods || {}),
properties: props.properties || {},
user: props.user || {},
validate: props.validate || [],
});
export default blockDefaults;

View File

@ -1,231 +0,0 @@
/*
Copyright 2020 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import blockDefaults from './blockDefaults';
test('default', () => {
expect(blockDefaults()).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "undefined_id",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('default with id', () => {
const props = { id: 'id' };
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "id",
"content": Object {},
"id": "id",
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('default with blockId', () => {
const props = { blockId: 'blockId' };
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "blockId",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('default with blockId and id', () => {
const props = { id: 'id', blockId: 'blockId' };
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "id",
"content": Object {},
"id": "id",
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('with values', () => {
const props = {
actions: { actions: 1 },
Components: { Components: 1 },
content: { content: 1 },
list: { list: 1 },
menus: ['menus'],
properties: { properties: 1 },
user: { user: 1 },
validate: ['validate'],
};
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"Components": Object {
"Components": 1,
},
"actions": Object {
"actions": 1,
},
"blockId": "undefined_id",
"content": Object {
"content": 1,
},
"list": Object {
"list": 1,
},
"menus": Array [
"menus",
],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {
"properties": 1,
},
"user": Object {
"user": 1,
},
"validate": Array [
"validate",
],
}
`);
});
test('with no methods', () => {
const props = {
methods: {},
};
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "undefined_id",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('with methods', () => {
const props = {
methods: {
callAction: 'callAction',
registerAction: 'registerAction',
registerMethod: 'registerMethod',
},
};
expect(blockDefaults(props)).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "undefined_id",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": "callAction",
"makeCssClass": [Function],
"registerAction": "registerAction",
"registerMethod": "registerMethod",
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
});
test('call default methods', () => {
const res = blockDefaults();
expect(res).toMatchInlineSnapshot(`
Object {
"actions": Object {},
"blockId": "undefined_id",
"content": Object {},
"list": Array [],
"menus": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
"properties": Object {},
"user": Object {},
"validate": Array [],
}
`);
expect(res.methods.callAction()).toEqual(undefined);
expect(res.methods.registerAction()).toEqual(undefined);
expect(res.methods.registerMethod()).toEqual(undefined);
});

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import blockDefaults from './blockDefaults';
import blockDefaultProps from './blockDefaultProps';
import BlockSchemaErrors from './BlockSchemaErrors';
import ErrorBoundary from './ErrorBoundary';
import IconSpinner from './Spinner/IconSpinner';
@ -22,7 +22,6 @@ import Loading from './Loading';
import makeCssClass from './makeCssClass.js';
import mediaToCssObject from './mediaToCssObject.js';
import mockBlock from './mockBlock';
import mockBlockProps from './mockBlockProps';
import runBlockSchemaTests from './runBlockSchemaTests';
import runRenderTests from './runRenderTests';
import Skeleton from './Skeleton/Skeleton';
@ -31,10 +30,11 @@ import SkeletonButton from './Skeleton/SkeletonButton';
import SkeletonInput from './Skeleton/SkeletonInput';
import SkeletonParagraph from './Skeleton/SkeletonParagraph';
import Spinner from './Spinner/Spinner';
import stubBlockProps from './stubBlockProps';
import useRunAfterUpdate from './useRunAfterUpdate';
export {
blockDefaults,
blockDefaultProps,
BlockSchemaErrors,
ErrorBoundary,
IconSpinner,
@ -42,7 +42,6 @@ export {
makeCssClass,
mediaToCssObject,
mockBlock,
mockBlockProps,
runBlockSchemaTests,
runRenderTests,
Skeleton,
@ -51,5 +50,6 @@ export {
SkeletonInput,
SkeletonParagraph,
Spinner,
stubBlockProps,
useRunAfterUpdate,
};

View File

@ -14,17 +14,9 @@
limitations under the License.
*/
import { unmountComponentAtNode } from 'react-dom';
import mockBlockProps from './mockBlockProps';
import blockDefaults from './blockDefaults';
import stubBlockProps from './stubBlockProps';
const mockBlock = ({ meta, logger }) => {
// mock Match.random to generate consistent ids
const mockMath = Object.create(global.Math);
mockMath.random = () => 0.123456789;
global.Math = mockMath;
let container = {};
const callAction = jest.fn();
const makeCssClass = jest.fn();
const moveItemDown = jest.fn();
@ -46,18 +38,7 @@ const mockBlock = ({ meta, logger }) => {
unshiftItem,
};
const makeCssImp = (style, op) => JSON.stringify({ style, options: op });
let nodeMock = {};
let renderOptions = {
createNodeMock: () => nodeMock,
};
const before = () => {
// clear all keys in note mock but keep object pointer
Object.keys(nodeMock).forEach((key) => {
delete nodeMock[key];
});
container.div = document.createElement('div');
document.body.appendChild(container.div);
callAction.mockReset();
makeCssClass.mockReset();
makeCssClass.mockImplementation(makeCssImp);
@ -69,13 +50,14 @@ const mockBlock = ({ meta, logger }) => {
setValue.mockReset();
unshiftItem.mockReset();
};
const after = () => {
unmountComponentAtNode(container.div);
container.div.remove();
container.div = null;
const getProps = (block) => {
const props = stubBlockProps({ block, meta, logger });
return {
...props,
methods,
};
};
const getProps = (block) => blockDefaults(mockBlockProps({ block, meta, logger }));
return { after, before, container, methods, getProps, renderOptions, nodeMock };
return { before, methods, getProps };
};
export default mockBlock;

View File

@ -19,10 +19,9 @@ import renderer from 'react-test-renderer';
import mockBlock from './mockBlock';
const runRenderTests = ({ examples, Block, meta, logger }) => {
const { after, before, methods, getProps } = mockBlock({ meta, logger });
const { before, methods, getProps } = mockBlock({ meta, logger });
beforeEach(before);
afterEach(after);
examples.forEach((ex) => {
test(`Render ${ex.id}`, () => {

View File

@ -18,6 +18,7 @@ import React, { useState } from 'react';
import Ajv from 'ajv';
import AjvErrors from 'ajv-errors';
import { type } from '@lowdefy/helpers';
import makeCssClass from './makeCssClass';
import blockSchema from './blockSchema.json';
const initAjv = (options) => {
@ -27,7 +28,7 @@ const initAjv = (options) => {
};
const ajvInstance = initAjv();
const mockBlockProps = ({ block, meta, logger }) => {
const stubBlockProps = ({ block, meta, logger }) => {
const [value, setState] = useState(type.enforceType(meta.valueType, null));
const setValue = (val) => {
setState(type.enforceType(meta.valueType, val));
@ -48,12 +49,13 @@ const mockBlockProps = ({ block, meta, logger }) => {
if (!block.areas.content) block.areas.content = {};
if (block.blocks) block.areas.content.blocks = block.blocks;
}
if (!block.methods) block.methods = {};
// mock default block methods
block.methods = {
callAction: (action) => log(JSON.stringify(action, null, 2)),
registerAction: (action) => log(JSON.stringify(action, null, 2)),
registerMethod: (method) => log(JSON.stringify(method, null, 2)),
...block.methods,
makeCssClass,
};
// block category defaults
@ -98,4 +100,4 @@ const mockBlockProps = ({ block, meta, logger }) => {
return block;
};
export default mockBlockProps;
export default stubBlockProps;

View File

@ -15,7 +15,7 @@
*/
import { useState } from 'react';
import mockBlockProps from './mockBlockProps';
import stubBlockProps from './stubBlockProps';
jest.mock('react', () => {
const React = {
@ -42,12 +42,13 @@ test('basic display', () => {
const meta = {
category: 'display',
};
expect(mockBlockProps({ block, meta })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta })).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -68,14 +69,14 @@ test('basic display with methods', () => {
const meta = {
category: 'display',
};
const res = mockBlockProps({ block, meta });
const res = stubBlockProps({ block, meta });
expect(res).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"fn": "test",
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -108,12 +109,13 @@ test('basic input', () => {
const meta = {
category: 'input',
};
expect(mockBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
"setValue": [Function],
@ -134,13 +136,14 @@ test('input setState', () => {
category: 'input',
valueType: 'string',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
"setValue": [Function],
@ -162,7 +165,7 @@ test('basic container', () => {
const meta = {
category: 'container',
};
expect(mockBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
Object {
"areas": Object {
"content": Object {},
@ -174,6 +177,7 @@ test('basic container', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -191,7 +195,7 @@ test('basic context', () => {
const meta = {
category: 'context',
};
expect(mockBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
Object {
"areas": Object {
"content": Object {},
@ -203,6 +207,7 @@ test('basic context', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -220,7 +225,7 @@ test('basic list', () => {
const meta = {
category: 'list',
};
expect(mockBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta, logger })).toMatchInlineSnapshot(`
Object {
"areas": Object {
"content": Object {},
@ -230,6 +235,7 @@ test('basic list', () => {
"list": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"moveItemDown": [Function],
"moveItemUp": [Function],
"pushItem": [Function],
@ -252,7 +258,7 @@ test('list methods', () => {
const meta = {
category: 'list',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -263,6 +269,7 @@ test('list methods', () => {
"list": Array [],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"moveItemDown": [Function],
"moveItemUp": [Function],
"pushItem": [Function],
@ -297,7 +304,7 @@ test('blocks container', () => {
const meta = {
category: 'container',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -323,6 +330,7 @@ test('blocks container', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -358,7 +366,7 @@ test('blocks areas container', () => {
category: 'container',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -384,6 +392,7 @@ test('blocks areas container', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -412,7 +421,7 @@ test('areas container', () => {
const meta = {
category: 'container',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -432,6 +441,7 @@ test('areas container', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -460,7 +470,7 @@ test('areas context', () => {
const meta = {
category: 'context',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -480,6 +490,7 @@ test('areas context', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -508,7 +519,7 @@ test('areas list', () => {
const meta = {
category: 'list',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"areas": Object {
@ -530,6 +541,7 @@ test('areas list', () => {
],
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"moveItemDown": [Function],
"moveItemUp": [Function],
"pushItem": [Function],
@ -561,7 +573,7 @@ test('actions display', () => {
const meta = {
category: 'display',
};
const res = mockBlockProps({ block, meta, logger });
const res = stubBlockProps({ block, meta, logger });
expect(res).toMatchInlineSnapshot(`
Object {
"actions": Object {
@ -576,6 +588,7 @@ test('actions display', () => {
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -611,12 +624,13 @@ test('provide schema errors', () => {
},
},
};
expect(mockBlockProps({ block, meta })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta })).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},
@ -634,12 +648,13 @@ test('provide schema errors', () => {
mistake: 1,
},
};
expect(mockBlockProps({ block, meta })).toMatchInlineSnapshot(`
expect(stubBlockProps({ block, meta })).toMatchInlineSnapshot(`
Object {
"blockId": "a",
"id": "a",
"methods": Object {
"callAction": [Function],
"makeCssClass": [Function],
"registerAction": [Function],
"registerMethod": [Function],
},

View File

@ -1,7 +1,6 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './demo/index.js',
@ -19,6 +18,7 @@ module.exports = {
},
fallback: { buffer: false },
},
module: {
rules: [
// TODO: FIXME: do NOT webpack 5 support with this
@ -53,38 +53,10 @@ module.exports = {
},
],
},
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: {
modifyVars: {
'@primary-color': '#697a8c',
'@link-color': '#1890ff',
'@layout-header-background': '#30383f',
'@layout-sider-background': '#30383f',
'@menu-dark-submenu-bg': '#21262b',
},
javascriptEnabled: true,
},
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
new webpack.ProvidePlugin({ process: ['process'] }),
new HtmlWebpackPlugin({
template: './public/index.html',
}),

View File

@ -44,7 +44,7 @@
"version:major": "yarn version major -d"
},
"dependencies": {
"@lowdefy/block-tools": "1.0.1-alpha.9",
"@lowdefy/block-tools": "1.0.1-alpha.13",
"@lowdefy/helpers": "1.1.0",
"@lowdefy/node-utils": "1.0.0",
"apollo-server-express": "2.18.2",

View File

@ -40,6 +40,7 @@
"version:major": "yarn version major -d"
},
"dependencies": {
"@lowdefy/block-tools": "1.0.1-alpha.13",
"@lowdefy/helpers": "1.1.0",
"antd": "4.4.2",
"react": "17.0.1",
@ -50,7 +51,7 @@
"@babel/core": "7.12.3",
"@babel/preset-env": "7.12.1",
"@babel/preset-react": "7.12.1",
"@lowdefy/block-tools": "1.0.1-alpha.9",
"@lowdefy/block-tools": "1.0.1-alpha.13",
"babel-jest": "26.6.1",
"babel-loader": "8.1.0",
"babel-plugin-import": "1.13.1",

View File

@ -17,6 +17,7 @@
import React from 'react';
import { Row } from 'antd';
import gutterSetup from './gutterSetup.js';
import { blockDefaultProps } from '@lowdefy/block-tools';
const Area = ({ area, areaStyle, children, highlightBorders, id, makeCssClass }) => (
<Row
@ -37,4 +38,6 @@ const Area = ({ area, areaStyle, children, highlightBorders, id, makeCssClass })
</Row>
);
Area.defaultProps = blockDefaultProps;
export default Area;

View File

@ -17,6 +17,7 @@
import React from 'react';
import { Col } from 'antd';
import deriveLayout from './deriveLayout.js';
import { blockDefaultProps } from '@lowdefy/block-tools';
const alignSelf = (align) => {
if (align === 'bottom') {
@ -54,4 +55,6 @@ const BlockLayout = ({ id, blockStyle, children, highlightBorders, layout, makeC
);
};
BlockLayout.defaultProps = blockDefaultProps;
export default BlockLayout;

View File

@ -42,7 +42,7 @@
"@apollo/link-context": "2.0.0-beta.3",
"@apollo/link-error": "2.0.0-beta.3",
"@apollo/link-retry": "2.0.0-beta.3",
"@lowdefy/block-tools": "1.0.1-alpha.9",
"@lowdefy/block-tools": "1.0.1-alpha.13",
"@lowdefy/engine": "0.0.0-alpha.1",
"@lowdefy/helpers": "1.1.0",
"@lowdefy/layout": "1.0.0",

View File

@ -16,19 +16,17 @@
import React from 'react';
import { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
import { blockDefaults, makeCssClass } from '@lowdefy/block-tools';
import { makeCssClass } from '@lowdefy/block-tools';
import Block from './Block';
const ConnectedArea = blockDefaults(Area);
const Container = ({ block, Blocks, Component, context, pageId, rootContext }) => {
const content = {};
// eslint-disable-next-line prefer-destructuring
const areas = Blocks.subBlocks[block.id][0].areas;
Object.keys(areas).forEach((areaKey) => {
content[areaKey] = (areaStyle) => (
<ConnectedArea
<Area
id={`ar-${block.blockId}-${areaKey}`}
key={`ar-${block.blockId}-${areaKey}`}
area={layoutParamsToArea({
@ -50,7 +48,7 @@ const Container = ({ block, Blocks, Component, context, pageId, rootContext }) =
rootContext={rootContext}
/>
))}
</ConnectedArea>
</Area>
);
});
return (

View File

@ -14,8 +14,11 @@
limitations under the License.
*/
import { blockDefaults } from '@lowdefy/block-tools';
import { blockDefaultProps } from '@lowdefy/block-tools';
const Defaults = ({ Component, render }) => render(blockDefaults(Component));
const Defaults = ({ Component, render }) => {
Component.defaultProps = blockDefaultProps;
return render(Component);
};
export default Defaults;

View File

@ -16,19 +16,17 @@
import React from 'react';
import { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
import { blockDefaults, makeCssClass } from '@lowdefy/block-tools';
import { makeCssClass } from '@lowdefy/block-tools';
import Block from './Block';
const ConnectedArea = blockDefaults(Area);
const List = ({ block, Blocks, Component, context, pageId, rootContext }) => {
const content = {};
const contentList = [];
Blocks.subBlocks[block.id].forEach((SBlock) => {
Object.keys(SBlock.areas).forEach((areaKey) => {
content[areaKey] = (areaStyle) => (
<ConnectedArea
<Area
id={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
key={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
area={layoutParamsToArea({
@ -50,7 +48,7 @@ const List = ({ block, Blocks, Component, context, pageId, rootContext }) => {
rootContext={rootContext}
/>
))}
</ConnectedArea>
</Area>
);
});
contentList.push({ ...content });

View File

@ -33,7 +33,7 @@
"version:major": "yarn version major -d"
},
"dependencies": {
"@lowdefy/block-tools": "1.0.1-alpha.9",
"@lowdefy/block-tools": "1.0.1-alpha.13",
"@lowdefy/graphql": "0.0.0-alpha.1",
"apollo-server-express": "2.18.2",
"express": "4.17.1",

View File

@ -2794,7 +2794,7 @@ __metadata:
languageName: node
linkType: hard
"@lowdefy/block-tools@1.0.1-alpha.9, @lowdefy/block-tools@workspace:packages/blockTools":
"@lowdefy/block-tools@1.0.1-alpha.13, @lowdefy/block-tools@workspace:packages/blockTools":
version: 0.0.0-use.local
resolution: "@lowdefy/block-tools@workspace:packages/blockTools"
dependencies:
@ -2818,8 +2818,6 @@ __metadata:
identity-obj-proxy: 3.0.0
jest: 26.6.1
js-yaml: 3.14.0
less: 3.12.2
less-loader: 7.0.2
path-browserify: 1.0.1
process: 0.11.10
react: 17.0.1
@ -2868,7 +2866,7 @@ __metadata:
"@babel/core": 7.12.3
"@babel/preset-env": 7.12.1
"@babel/preset-react": 7.12.1
"@lowdefy/block-tools": 1.0.1-alpha.9
"@lowdefy/block-tools": 1.0.1-alpha.13
"@lowdefy/helpers": 1.1.0
"@lowdefy/node-utils": 1.0.0
apollo-server-express: 2.18.2
@ -3014,7 +3012,7 @@ __metadata:
"@babel/core": 7.12.3
"@babel/preset-env": 7.12.1
"@babel/preset-react": 7.12.1
"@lowdefy/block-tools": 1.0.1-alpha.9
"@lowdefy/block-tools": 1.0.1-alpha.13
"@lowdefy/helpers": 1.1.0
antd: 4.4.2
babel-jest: 26.6.1
@ -3119,7 +3117,7 @@ __metadata:
"@apollo/link-retry": 2.0.0-beta.3
"@babel/core": 7.12.3
"@babel/preset-react": 7.12.1
"@lowdefy/block-tools": 1.0.1-alpha.9
"@lowdefy/block-tools": 1.0.1-alpha.13
"@lowdefy/engine": 0.0.0-alpha.1
"@lowdefy/helpers": 1.1.0
"@lowdefy/layout": 1.0.0
@ -3148,7 +3146,7 @@ __metadata:
dependencies:
"@babel/core": 7.12.3
"@babel/preset-react": 7.12.1
"@lowdefy/block-tools": 1.0.1-alpha.9
"@lowdefy/block-tools": 1.0.1-alpha.13
"@lowdefy/graphql": 0.0.0-alpha.1
apollo-server-express: 2.18.2
babel-loader: 8.1.0