Skip to content

Commit

Permalink
fix: objectprop circular reference
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Feb 11, 2020
1 parent 87efdcb commit ba2ee3b
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion core/editors/src/editors/ArrayEditor/ArrayEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent } from 'react';
import { ComponentControlArray } from '@component-controls/specification';
import { Textarea } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

export interface ArrayEditorProps extends PropertyControlProps {
prop: ComponentControlArray;
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/BooleanEditor/BooleanEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { ComponentControlBoolean } from '@component-controls/specification';
import { Toggle } from '../../components/Toggle/Toggle';
import { FlexContainer } from '../../components/FlexContainer/FlexContainer';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

export interface BooleanEditorProps extends PropertyControlProps {
prop: ComponentControlBoolean;
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/ButtonEditor/ButtonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PropertyControlProps,
PropertyEditor,
PropertyOnClick,
} from '../../types';
} from '../types';

export interface ButtonEditorProps extends PropertyControlProps {
prop: ComponentControlButton;
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/ColorEditor/ColorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { SketchPicker, ColorResult } from 'react-color';
import { ComponentControlColor } from '@component-controls/specification';
import { Button, Box } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

export interface ColorEditorProps extends PropertyControlProps {
prop: ComponentControlColor;
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/DateEditor/DateEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent, RefObject } from 'react';
import { ComponentControlDate } from '@component-controls/specification';
import { Input, Box } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

const formatDate = (date: Date | undefined) => {
if (date) {
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/FilesEditor/FilesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FileReader } from 'global';
import React, { ChangeEvent } from 'react';
import { ComponentControlFiles } from '@component-controls/specification';
import { Input } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

function fileReaderPromise(file: File) {
return new Promise<string>(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/NumberEditor/NumberEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, ChangeEvent } from 'react';
import { ComponentControlNumber } from '@component-controls/specification';
import { Input, Box, BoxProps } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

export interface NumberEditorProps extends PropertyControlProps {
prop: ComponentControlNumber;
Expand Down
15 changes: 12 additions & 3 deletions core/editors/src/editors/ObjectEditor/ObjectEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React, { FC } from 'react';
import { Button, Box } from 'theme-ui';
import {
ControlTypes,
ComponentControl,
ComponentControlObject,
} from '@component-controls/specification';
import { mergeControlValues, getControlValues } from '@component-controls/core';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';
import { FlexContainer } from '../../components/FlexContainer/FlexContainer';
import { Popover } from '../../components/Popover/Popover';

import { getPropertyEditor } from '../../prop-factory';
import { PropertyEditors } from '../PropertyEditors';

export interface ObjectEditorProps extends PropertyControlProps {
prop: ComponentControlObject;
Expand Down Expand Up @@ -56,7 +57,7 @@ export const ObjectEditor: PropertyEditor<ObjectEditorProps> = ({
return {
name: key,
prop: childProp,
node: getPropertyEditor(childProp.type),
node: AllPropertyEditors[childProp.type],
};
})
.filter(p => p && p.node);
Expand Down Expand Up @@ -102,3 +103,11 @@ export const ObjectEditor: PropertyEditor<ObjectEditorProps> = ({
</Popover>
);
};

// avoid circular reference problem
export const AllPropertyEditors: {
[name in ControlTypes]: PropertyEditor;
} = {
...PropertyEditors,
[ControlTypes.OBJECT]: ObjectEditor,
};
2 changes: 1 addition & 1 deletion core/editors/src/editors/ObjectEditor/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { ObjectEditor } from './ObjectEditor';
export { ObjectEditor, AllPropertyEditors } from './ObjectEditor';
2 changes: 1 addition & 1 deletion core/editors/src/editors/OptionsEditor/CheckboxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ChangeEvent } from 'react';
import styled from '@emotion/styled';
import { ComponentControlOptions } from '@component-controls/specification';
import { normalizeOptions, NormalizedOption } from './utils';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

interface CheckboxEditorProps extends PropertyControlProps {
prop: ComponentControlOptions;
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/OptionsEditor/OptionsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactSelect from 'react-select';
import styled from '@emotion/styled';
import { ComponentControlOptions } from '@component-controls/specification';
import { normalizeOptions } from './utils';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

import { RadiosEditor } from './RadiosEditor';
import { CheckboxEditor } from './CheckboxEditor';
Expand Down
2 changes: 1 addition & 1 deletion core/editors/src/editors/OptionsEditor/RadiosEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import styled from '@emotion/styled';
import { ComponentControlOptions } from '@component-controls/specification';
import { normalizeOptions, NormalizedOption } from './utils';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

interface RadiosEditorProps extends PropertyControlProps {
prop: ComponentControlOptions;
Expand Down
25 changes: 25 additions & 0 deletions core/editors/src/editors/PropertyEditors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ControlTypes } from '@component-controls/specification';
import { TextEditor } from './TextEditor';
import { NumberEditor } from './NumberEditor';

import { BooleanEditor } from './BooleanEditor';
import { OptionsEditor } from './OptionsEditor';

import { DateEditor } from './DateEditor';
import { ColorEditor } from './ColorEditor';
import { ButtonEditor } from './ButtonEditor';

import { ArrayEditor } from './ArrayEditor';
import { FilesEditor } from './FilesEditor';

export const PropertyEditors = {
[ControlTypes.TEXT]: TextEditor,
[ControlTypes.NUMBER]: NumberEditor,
[ControlTypes.BOOLEAN]: BooleanEditor,
[ControlTypes.OPTIONS]: OptionsEditor,
[ControlTypes.DATE]: DateEditor,
[ControlTypes.COLOR]: ColorEditor,
[ControlTypes.BUTTON]: ButtonEditor,
[ControlTypes.ARRAY]: ArrayEditor,
[ControlTypes.FILES]: FilesEditor,
};
2 changes: 1 addition & 1 deletion core/editors/src/editors/TextEditor/TextEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ChangeEvent } from 'react';
import { ComponentControlText } from '@component-controls/specification';
import { Input, Textarea } from 'theme-ui';
import { PropertyControlProps, PropertyEditor } from '../../types';
import { PropertyControlProps, PropertyEditor } from '../types';

export interface TextEditorProps extends PropertyControlProps {
prop: ComponentControlText;
Expand Down
7 changes: 7 additions & 0 deletions core/editors/src/editors/prop-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ControlTypes } from '@component-controls/specification';
import { PropertyEditor } from './types';

import { AllPropertyEditors } from './ObjectEditor';

export const getPropertyEditor = (type: ControlTypes): PropertyEditor =>
AllPropertyEditors[type];
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@component-controls/core';

import { Tab, Tabs, TabList, TabPanel } from '../../components/Tabs/Tabs';
import { ControlsEditorsTableProps } from '../../types';
import { ControlsEditorsTableProps } from '../../editors/types';
import { ActionBar } from '../../components/ActionBar/ActionBar';

import { PropertyEditorRow } from './PropEditorRow';
Expand Down
4 changes: 2 additions & 2 deletions core/editors/src/forms/ControlsTable/PropEditorRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
import styled from '@emotion/styled';
import { LoadedComponentControl } from '@component-controls/core';

import { getPropertyEditor } from '../../prop-factory';
import { getPropertyEditor } from '../../editors/prop-factory';
import { FlexContainer } from '../../components/FlexContainer/FlexContainer';
import { PropertyEditor } from '../../types';
import { PropertyEditor } from '../../editors/types';

const StyledTR = styled.tr<{}>(({ theme }) => ({
//@ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions core/editors/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './prop-factory';
export * from './types';
export * from './editors/prop-factory';
export * from './editors/types';
export * from './forms/ControlsTable/ControlEditorsTable';
export { FlexContainer } from './components/FlexContainer/FlexContainer';
33 changes: 0 additions & 33 deletions core/editors/src/prop-factory.ts

This file was deleted.

0 comments on commit ba2ee3b

Please sign in to comment.