Skip to content

Commit 6e30736

Browse files
authored
Merge pull request #93 from headwirecom/feature/optimize-bundle
Optimize bundle size and npm package size
2 parents 03bfec6 + c1c98bc commit 6e30736

24 files changed

+78
-81
lines changed

packages/spectrum/.npmignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.nycrc
2+
.vscode
3+
Styles.md
4+
dist
5+
docs
6+
example
7+
test
8+
webpack
9+
lib/*
10+
!lib/src/*
11+
stats.json

packages/spectrum/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@headwire/jsonforms-react-spectrum-renderers",
3-
"version": "0.0.1-beta.0",
3+
"version": "0.0.1-beta.1",
44
"description": "React Spectrum Renderer Set for JSONForms",
55
"repository": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers",
66
"bugs": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers/issues",

packages/spectrum/src/additional/SpectrumListWithDetailRenderer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import {
4343
ResolvedJsonFormsDispatch,
4444
withJsonFormsArrayLayoutProps,
4545
} from '@jsonforms/react';
46-
import map from 'lodash/map';
47-
import range from 'lodash/range';
4846
import React, { useCallback, useState } from 'react';
4947
import ListWithDetailMasterItem from './ListWithDetailMasterItem';
5048
import merge from 'lodash/merge';
@@ -119,7 +117,7 @@ export const SpectrumListWithDetailRenderer = ({
119117
<Flex direction='row'>
120118
<Flex direction='column' marginY='size-200' marginEnd='size-200'>
121119
{data > 0 ? (
122-
map(range(data), (index) => (
120+
Array.from(Array(data)).map((_, index) => (
123121
<ListWithDetailMasterItem
124122
index={index}
125123
path={path}

packages/spectrum/src/cells/SpectrumBooleanCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
import { withJsonFormsCellProps } from '@jsonforms/react';
3636
import { FunctionComponent } from 'react';
3737
import { Checkbox } from '@adobe/react-spectrum';
38-
import { merge } from 'lodash';
38+
import merge from 'lodash/merge';
3939
import { DimensionValue } from '@react-types/shared';
4040

4141
export const SpectrumBooleanCell: FunctionComponent<CellProps> = (

packages/spectrum/src/complex/CombinatorProperties.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
THE SOFTWARE.
2727
*/
2828
import React from 'react';
29-
import { omit } from 'lodash';
3029
import { Generate, JsonSchema, Layout, UISchemaElement } from '@jsonforms/core';
3130
import { ResolvedJsonFormsDispatch } from '@jsonforms/react';
3231

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

49-
const otherProps: JsonSchema = omit(
50-
schema,
51-
combinatorKeyword
52-
) as JsonSchema;
48+
const { [combinatorKeyword]: _, ...otherProps } = schema
5349
const foundUISchema: UISchemaElement = Generate.uiSchema(
5450
otherProps,
5551
'VerticalLayout'

packages/spectrum/src/complex/SpectrumObjectRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2626
THE SOFTWARE.
2727
*/
28-
import isEmpty from 'lodash/isEmpty';
28+
import { isEmpty } from '../util/isEmpty';
2929
import startCase from 'lodash/startCase';
3030
import {
3131
findUISchema,

packages/spectrum/src/complex/SpectrumOneOfRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
THE SOFTWARE.
2727
*/
2828
import React, { Key, useCallback, useState } from 'react';
29-
import isEmpty from 'lodash/isEmpty';
29+
import { isEmpty } from '../util/isEmpty';
3030

3131
import {
3232
CombinatorProps,

packages/spectrum/src/complex/SpectrumTableArrayControl.tsx

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
THE SOFTWARE.
2727
*/
2828
import React from 'react';
29-
import fpfilter from 'lodash/fp/filter';
30-
import fpmap from 'lodash/fp/map';
31-
import fpflow from 'lodash/fp/flow';
32-
import fpkeys from 'lodash/fp/keys';
33-
import fpstartCase from 'lodash/fp/startCase';
29+
import startCase from 'lodash/startCase';
3430
import {
3531
ArrayControlProps,
3632
ControlElement,
@@ -137,11 +133,9 @@ class SpectrumTableArrayControl extends React.Component<
137133
};
138134

139135
const headerColumns: JSX.Element[] = schema.properties
140-
? fpflow(
141-
fpkeys,
142-
fpfilter((prop) => schema.properties[prop].type !== 'array'),
143-
fpmap((prop) => <Column key={prop}>{fpstartCase(prop)}</Column>)
144-
)(schema.properties)
136+
? Object.keys(schema.properties)
137+
.filter((prop) => schema.properties[prop].type !== 'array')
138+
.map((prop) => <Column key={prop}>{startCase(prop)}</Column>)
145139
: [<Column key='items'>Items</Column>];
146140

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

207201
const rowCells: JSX.Element[] = schema.properties
208-
? fpflow(
209-
fpkeys,
210-
fpfilter(
211-
(prop) => schema.properties[prop].type !== 'array'
212-
),
213-
fpmap((prop) => {
214-
const childPropPath = Paths.compose(
215-
childPath,
216-
prop.toString()
217-
);
202+
? Object.keys(schema.properties)
203+
.filter(prop => schema.properties[prop].type !== 'array')
204+
.map(prop => {
205+
const childPropPath = Paths.compose(
206+
childPath,
207+
prop.toString()
208+
);
218209

219-
return (
220-
<Cell key={childPropPath}>
221-
<Flex direction='column' width='100%'>
222-
<DispatchCell
223-
schema={Resolve.schema(
224-
schema,
225-
`#/properties/${prop}`,
226-
rootSchema
227-
)}
228-
uischema={createControlElement(prop)}
229-
path={childPath + '.' + prop}
230-
/>
231-
<View
232-
UNSAFE_style={UNSAFE_error}
233-
isHidden={
234-
getChildErrorMessage(childPropPath) === ''
235-
}
236-
>
237-
<Text>
238-
{getChildErrorMessage(childPropPath)}
239-
</Text>
240-
</View>
241-
</Flex>
242-
</Cell>
243-
);
244-
})
245-
)(schema.properties)
210+
return (
211+
<Cell key={childPropPath}>
212+
<Flex direction='column' width='100%'>
213+
<DispatchCell
214+
schema={Resolve.schema(
215+
schema,
216+
`#/properties/${prop}`,
217+
rootSchema
218+
)}
219+
uischema={createControlElement(prop)}
220+
path={childPath + '.' + prop}
221+
/>
222+
<View
223+
UNSAFE_style={UNSAFE_error}
224+
isHidden={
225+
getChildErrorMessage(childPropPath) === ''
226+
}
227+
>
228+
<Text>
229+
{getChildErrorMessage(childPropPath)}
230+
</Text>
231+
</View>
232+
</Flex>
233+
</Cell>
234+
);
235+
})
246236
: [
247237
<Cell key={Paths.compose(childPath, index.toString())}>
248238
<Flex direction='column' width='100%'>

packages/spectrum/src/complex/array/SpectrumArrayControl.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2626
THE SOFTWARE.
2727
*/
28-
import range from 'lodash/range';
2928
import React, { useCallback, useState } from 'react';
3029
import { ArrayControlProps, createDefaultValue } from '@jsonforms/core';
3130
import { Button, Flex, Heading, Text, View } from '@adobe/react-spectrum';
@@ -70,7 +69,7 @@ export const SpectrumArrayControl = ({
7069
</Flex>
7170
<Flex direction='column' gap='size-100'>
7271
{data && data.length ? (
73-
range(0, data.length).map((index) => {
72+
Array.from(Array(data.length)).map((_, index) => {
7473
return (
7574
<SpectrumArrayItem
7675
index={index}

packages/spectrum/src/complex/array/SpectrumArrayItem.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import {
5858
import Delete from '@spectrum-icons/workflow/Delete';
5959
import ChevronDown from '@spectrum-icons/workflow/ChevronDown';
6060
import ChevronUp from '@spectrum-icons/workflow/ChevronUp';
61-
import { find, omit } from 'lodash';
6261

6362
import './SpectrumArrayItem.css';
6463

@@ -182,7 +181,7 @@ export const mapStateToSpectrumArrayItemProps = (
182181
): StatePropsOfSpectrumArrayItem => {
183182
const { schema, path, index, uischema } = ownProps;
184183
const firstPrimitiveProp = schema.properties
185-
? find(Object.keys(schema.properties), (propName: any) => {
184+
? Object.keys(schema.properties).find((propName) => {
186185
const prop = schema.properties[propName];
187186
return (
188187
prop.type === 'string' ||
@@ -230,11 +229,11 @@ export const withJsonFormsSpectrumArrayItemProps = (
230229
(
231230
prevProps: StatePropsOfSpectrumArrayItem,
232231
nextProps: StatePropsOfSpectrumArrayItem
233-
) =>
234-
areEqual(
235-
omit(prevProps, ['handleExpand', 'removeItem']),
236-
omit(nextProps, ['handleExpand', 'removeItem'])
237-
)
232+
) => {
233+
const { handleExpand: prevHandleExpand, removeItem: prevRemoveItem, ...restPrevProps } = prevProps
234+
const { handleExpand: nextHandleExpand, removeItem: nextRemoveItem, ...restNextProps } = nextProps
235+
return areEqual(restPrevProps, restNextProps)
236+
}
238237
)
239238
)
240239
);

packages/spectrum/src/controls/SpectrumBooleanControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
rankWith,
3333
} from '@jsonforms/core';
3434
import { withJsonFormsControlProps } from '@jsonforms/react';
35-
import isEmpty from 'lodash/isEmpty';
35+
import { isEmpty } from '../util/isEmpty';
3636
import React from 'react';
3737
import { SpectrumBooleanCell } from '../cells/CustomizableCells';
3838

packages/spectrum/src/layouts/SpectrumGroupLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2626
THE SOFTWARE.
2727
*/
28-
import isEmpty from 'lodash/isEmpty';
28+
import { isEmpty } from '../util/isEmpty';
2929
import React, { FunctionComponent } from 'react';
3030
import {
3131
GroupLayout,

packages/spectrum/src/layouts/util.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2626
THE SOFTWARE.
2727
*/
28-
import isEmpty from 'lodash/isEmpty';
28+
import { isEmpty } from '../util/isEmpty';
2929
import React from 'react';
3030
import { JsonSchema, Layout } from '@jsonforms/core';
3131
import { ResolvedJsonFormsDispatch, useJsonForms } from '@jsonforms/react';

packages/spectrum/src/spectrum-control/InputDate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps, computeLabel } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { SpectrumInputProps } from './index';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { Flex } from '@adobe/react-spectrum';

packages/spectrum/src/spectrum-control/InputDateTime.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import React from 'react';
2626
import { DimensionValue } from '@react-types/shared';
2727
import { CellProps, computeLabel } from '@jsonforms/core';
28-
import { merge } from 'lodash';
28+
import merge from 'lodash/merge';
2929
import { SpectrumInputProps } from './index';
3030
import { Flex } from '@adobe/react-spectrum';
3131
import { DatePicker, DatePickerLabel } from '../additional/DatePicker';

packages/spectrum/src/spectrum-control/InputEnum.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { EnumCellProps, JsonSchema } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { SpectrumInputProps } from './index';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { Item, Picker } from '@adobe/react-spectrum';

packages/spectrum/src/spectrum-control/InputInteger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { TextField } from '@adobe/react-spectrum';
2929
import { SpectrumInputProps } from './index';
3030
import { DimensionValue } from '@react-types/shared';

packages/spectrum/src/spectrum-control/InputNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { TextField } from '@adobe/react-spectrum';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { SpectrumInputProps } from './index';

packages/spectrum/src/spectrum-control/InputNumberFormatted.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps, Formatted } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { TextField } from '@adobe/react-spectrum';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { SpectrumInputProps } from './index';

packages/spectrum/src/spectrum-control/InputSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { DimensionValue } from '@react-types/shared';
2929
import { SpectrumInputProps } from './index';
3030
import { Slider } from '@adobe/react-spectrum';

packages/spectrum/src/spectrum-control/InputText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { TextField } from '@adobe/react-spectrum';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { SpectrumInputProps } from './index';

packages/spectrum/src/spectrum-control/InputTextArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { TextArea } from '@adobe/react-spectrum';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { SpectrumInputProps } from './index';

packages/spectrum/src/spectrum-control/InputTime.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
import React from 'react';
2626
import { CellProps, computeLabel } from '@jsonforms/core';
27-
import { merge } from 'lodash';
27+
import merge from 'lodash/merge';
2828
import { SpectrumInputProps } from './index';
2929
import { DimensionValue } from '@react-types/shared';
3030
import { Flex } from '@adobe/react-spectrum';

packages/spectrum/src/util/isEmpty.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isempty
2+
export function isEmpty(obj: any) {
3+
return [Object, Array].includes((obj || {}).constructor) && !Object.keys((obj || {})).length;
4+
}

0 commit comments

Comments
 (0)