Skip to content

Optimize bundle size and npm package size #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/spectrum/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.nycrc
.vscode
Styles.md
dist
docs
example
test
webpack
lib/*
!lib/src/*
stats.json
2 changes: 1 addition & 1 deletion packages/spectrum/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@headwire/jsonforms-react-spectrum-renderers",
"version": "0.0.1-beta.0",
"version": "0.0.1-beta.1",
"description": "React Spectrum Renderer Set for JSONForms",
"repository": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers",
"bugs": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers/issues",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import {
ResolvedJsonFormsDispatch,
withJsonFormsArrayLayoutProps,
} from '@jsonforms/react';
import map from 'lodash/map';
import range from 'lodash/range';
import React, { useCallback, useState } from 'react';
import ListWithDetailMasterItem from './ListWithDetailMasterItem';
import merge from 'lodash/merge';
Expand Down Expand Up @@ -119,7 +117,7 @@ export const SpectrumListWithDetailRenderer = ({
<Flex direction='row'>
<Flex direction='column' marginY='size-200' marginEnd='size-200'>
{data > 0 ? (
map(range(data), (index) => (
Array.from(Array(data)).map((_, index) => (
<ListWithDetailMasterItem
index={index}
path={path}
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/cells/SpectrumBooleanCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
import { withJsonFormsCellProps } from '@jsonforms/react';
import { FunctionComponent } from 'react';
import { Checkbox } from '@adobe/react-spectrum';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { DimensionValue } from '@react-types/shared';

export const SpectrumBooleanCell: FunctionComponent<CellProps> = (
Expand Down
6 changes: 1 addition & 5 deletions packages/spectrum/src/complex/CombinatorProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
THE SOFTWARE.
*/
import React from 'react';
import { omit } from 'lodash';
import { Generate, JsonSchema, Layout, UISchemaElement } from '@jsonforms/core';
import { ResolvedJsonFormsDispatch } from '@jsonforms/react';

Expand All @@ -46,10 +45,7 @@ export class CombinatorProperties extends React.Component<
render() {
const { schema, combinatorKeyword, path } = this.props;

const otherProps: JsonSchema = omit(
schema,
combinatorKeyword
) as JsonSchema;
const { [combinatorKeyword]: _, ...otherProps } = schema
const foundUISchema: UISchemaElement = Generate.uiSchema(
otherProps,
'VerticalLayout'
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/complex/SpectrumObjectRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from '../util/isEmpty';
import startCase from 'lodash/startCase';
import {
findUISchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/complex/SpectrumOneOfRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
THE SOFTWARE.
*/
import React, { Key, useCallback, useState } from 'react';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from '../util/isEmpty';

import {
CombinatorProps,
Expand Down
84 changes: 37 additions & 47 deletions packages/spectrum/src/complex/SpectrumTableArrayControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
THE SOFTWARE.
*/
import React from 'react';
import fpfilter from 'lodash/fp/filter';
import fpmap from 'lodash/fp/map';
import fpflow from 'lodash/fp/flow';
import fpkeys from 'lodash/fp/keys';
import fpstartCase from 'lodash/fp/startCase';
import startCase from 'lodash/startCase';
import {
ArrayControlProps,
ControlElement,
Expand Down Expand Up @@ -137,11 +133,9 @@ class SpectrumTableArrayControl extends React.Component<
};

const headerColumns: JSX.Element[] = schema.properties
? fpflow(
fpkeys,
fpfilter((prop) => schema.properties[prop].type !== 'array'),
fpmap((prop) => <Column key={prop}>{fpstartCase(prop)}</Column>)
)(schema.properties)
? Object.keys(schema.properties)
.filter((prop) => schema.properties[prop].type !== 'array')
.map((prop) => <Column key={prop}>{startCase(prop)}</Column>)
: [<Column key='items'>Items</Column>];

const uioptions: UIOptions = {
Expand Down Expand Up @@ -205,44 +199,40 @@ class SpectrumTableArrayControl extends React.Component<
const childPath = Paths.compose(path, `${index}`);

const rowCells: JSX.Element[] = schema.properties
? fpflow(
fpkeys,
fpfilter(
(prop) => schema.properties[prop].type !== 'array'
),
fpmap((prop) => {
const childPropPath = Paths.compose(
childPath,
prop.toString()
);
? Object.keys(schema.properties)
.filter(prop => schema.properties[prop].type !== 'array')
.map(prop => {
const childPropPath = Paths.compose(
childPath,
prop.toString()
);

return (
<Cell key={childPropPath}>
<Flex direction='column' width='100%'>
<DispatchCell
schema={Resolve.schema(
schema,
`#/properties/${prop}`,
rootSchema
)}
uischema={createControlElement(prop)}
path={childPath + '.' + prop}
/>
<View
UNSAFE_style={UNSAFE_error}
isHidden={
getChildErrorMessage(childPropPath) === ''
}
>
<Text>
{getChildErrorMessage(childPropPath)}
</Text>
</View>
</Flex>
</Cell>
);
})
)(schema.properties)
return (
<Cell key={childPropPath}>
<Flex direction='column' width='100%'>
<DispatchCell
schema={Resolve.schema(
schema,
`#/properties/${prop}`,
rootSchema
)}
uischema={createControlElement(prop)}
path={childPath + '.' + prop}
/>
<View
UNSAFE_style={UNSAFE_error}
isHidden={
getChildErrorMessage(childPropPath) === ''
}
>
<Text>
{getChildErrorMessage(childPropPath)}
</Text>
</View>
</Flex>
</Cell>
);
})
: [
<Cell key={Paths.compose(childPath, index.toString())}>
<Flex direction='column' width='100%'>
Expand Down
3 changes: 1 addition & 2 deletions packages/spectrum/src/complex/array/SpectrumArrayControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import range from 'lodash/range';
import React, { useCallback, useState } from 'react';
import { ArrayControlProps, createDefaultValue } from '@jsonforms/core';
import { Button, Flex, Heading, Text, View } from '@adobe/react-spectrum';
Expand Down Expand Up @@ -70,7 +69,7 @@ export const SpectrumArrayControl = ({
</Flex>
<Flex direction='column' gap='size-100'>
{data && data.length ? (
range(0, data.length).map((index) => {
Array.from(Array(data.length)).map((_, index) => {
return (
<SpectrumArrayItem
index={index}
Expand Down
13 changes: 6 additions & 7 deletions packages/spectrum/src/complex/array/SpectrumArrayItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
import Delete from '@spectrum-icons/workflow/Delete';
import ChevronDown from '@spectrum-icons/workflow/ChevronDown';
import ChevronUp from '@spectrum-icons/workflow/ChevronUp';
import { find, omit } from 'lodash';

import './SpectrumArrayItem.css';

Expand Down Expand Up @@ -182,7 +181,7 @@ export const mapStateToSpectrumArrayItemProps = (
): StatePropsOfSpectrumArrayItem => {
const { schema, path, index, uischema } = ownProps;
const firstPrimitiveProp = schema.properties
? find(Object.keys(schema.properties), (propName: any) => {
? Object.keys(schema.properties).find((propName) => {
const prop = schema.properties[propName];
return (
prop.type === 'string' ||
Expand Down Expand Up @@ -230,11 +229,11 @@ export const withJsonFormsSpectrumArrayItemProps = (
(
prevProps: StatePropsOfSpectrumArrayItem,
nextProps: StatePropsOfSpectrumArrayItem
) =>
areEqual(
omit(prevProps, ['handleExpand', 'removeItem']),
omit(nextProps, ['handleExpand', 'removeItem'])
)
) => {
const { handleExpand: prevHandleExpand, removeItem: prevRemoveItem, ...restPrevProps } = prevProps
const { handleExpand: nextHandleExpand, removeItem: nextRemoveItem, ...restNextProps } = nextProps
return areEqual(restPrevProps, restNextProps)
}
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/controls/SpectrumBooleanControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
rankWith,
} from '@jsonforms/core';
import { withJsonFormsControlProps } from '@jsonforms/react';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from '../util/isEmpty';
import React from 'react';
import { SpectrumBooleanCell } from '../cells/CustomizableCells';

Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/layouts/SpectrumGroupLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from '../util/isEmpty';
import React, { FunctionComponent } from 'react';
import {
GroupLayout,
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/layouts/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from '../util/isEmpty';
import React from 'react';
import { JsonSchema, Layout } from '@jsonforms/core';
import { ResolvedJsonFormsDispatch, useJsonForms } from '@jsonforms/react';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps, computeLabel } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { SpectrumInputProps } from './index';
import { DimensionValue } from '@react-types/shared';
import { Flex } from '@adobe/react-spectrum';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputDateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import React from 'react';
import { DimensionValue } from '@react-types/shared';
import { CellProps, computeLabel } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { SpectrumInputProps } from './index';
import { Flex } from '@adobe/react-spectrum';
import { DatePicker, DatePickerLabel } from '../additional/DatePicker';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputEnum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { EnumCellProps, JsonSchema } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { SpectrumInputProps } from './index';
import { DimensionValue } from '@react-types/shared';
import { Item, Picker } from '@adobe/react-spectrum';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputInteger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { TextField } from '@adobe/react-spectrum';
import { SpectrumInputProps } from './index';
import { DimensionValue } from '@react-types/shared';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { TextField } from '@adobe/react-spectrum';
import { DimensionValue } from '@react-types/shared';
import { SpectrumInputProps } from './index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps, Formatted } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { TextField } from '@adobe/react-spectrum';
import { DimensionValue } from '@react-types/shared';
import { SpectrumInputProps } from './index';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { DimensionValue } from '@react-types/shared';
import { SpectrumInputProps } from './index';
import { Slider } from '@adobe/react-spectrum';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { TextField } from '@adobe/react-spectrum';
import { DimensionValue } from '@react-types/shared';
import { SpectrumInputProps } from './index';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { TextArea } from '@adobe/react-spectrum';
import { DimensionValue } from '@react-types/shared';
import { SpectrumInputProps } from './index';
Expand Down
2 changes: 1 addition & 1 deletion packages/spectrum/src/spectrum-control/InputTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
import React from 'react';
import { CellProps, computeLabel } from '@jsonforms/core';
import { merge } from 'lodash';
import merge from 'lodash/merge';
import { SpectrumInputProps } from './index';
import { DimensionValue } from '@react-types/shared';
import { Flex } from '@adobe/react-spectrum';
Expand Down
4 changes: 4 additions & 0 deletions packages/spectrum/src/util/isEmpty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty
export function isEmpty(obj: any) {
return [Object, Array].includes((obj || {}).constructor) && !Object.keys((obj || {})).length;
}