Skip to content
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

refactor(core): resolve circular dependencies #2345

Merged
merged 1 commit into from
Jul 4, 2024
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
6 changes: 6 additions & 0 deletions packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ module.exports = {
ignore: ['^ava$'],
},
],
'import/no-cycle': [
'error',
{
ignoreExternal: true,
},
],
},
};
7 changes: 3 additions & 4 deletions packages/core/src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@

import type AJV from 'ajv';
import type { ErrorObject } from 'ajv';
import type { JsonSchema, UISchemaElement } from '../models';
import { JsonSchema, UISchemaElement } from '../models';
import { generateDefaultUISchema, generateJsonSchema } from '../generators';

import type { RankedTester } from '../testers';
import type { UISchemaTester, ValidationMode } from '../reducers';
import type { ErrorTranslator, Translator } from '../i18n';
import { RankedTester, UISchemaTester } from '../testers';
import { ErrorTranslator, Translator, ValidationMode } from '../store';

export const INIT = 'jsonforms/INIT' as const;
export const UPDATE_CORE = 'jsonforms/UPDATE_CORE' as const;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/generators/Generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
THE SOFTWARE.
*/

import { ControlElement, JsonSchema, UISchemaElement } from '../models';
import { generateJsonSchema } from './schema';
import { createControlElement, generateDefaultUISchema } from './uischema';
import type { ControlElement, JsonSchema, UISchemaElement } from '../';

export const Generate: {
// TODO fix @typescript-eslint/ban-types
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/generators/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import startCase from 'lodash/startCase';
import keys from 'lodash/keys';
import {
ControlElement,
isGroup,
isLayout,
JsonSchema,
LabelElement,
Layout,
UISchemaElement,
} from '../models';
import { deriveTypes, encode, resolveSchema } from '../util';
import { deriveTypes, encode, isGroup, isLayout, resolveSchema } from '../util';

/**
* Creates a new ILayout.
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/i18n/i18nUtil.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { ErrorObject } from 'ajv';
import { isInternationalized, Labelable, UISchemaElement } from '../models';
import { getControlPath } from '../reducers';
import { formatErrorMessage } from '../util';
import type { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
import { Labelable, UISchemaElement } from '../models';
import type { i18nJsonSchema, ErrorTranslator, Translator } from '../store';
import {
ArrayDefaultTranslation,
ArrayTranslations,
Expand All @@ -11,6 +9,11 @@ import {
CombinatorDefaultTranslation,
CombinatorTranslations,
} from './combinatorTranslations';
import {
formatErrorMessage,
getControlPath,
isInternationalized,
} from '../util';

export const getI18nKeyPrefixBySchema = (
schema: i18nJsonSchema | undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './i18nTypes';
export * from './i18nUtil';
export * from './arrayTranslations';
export * from './combinatorTranslations';
export * from './selectors';
export * from './i18nUtil';
67 changes: 67 additions & 0 deletions packages/core/src/i18n/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
The MIT License

Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import get from 'lodash/get';
import {
ErrorTranslator,
JsonFormsI18nState,
Translator,
JsonFormsState,
} from '../store';
import { defaultErrorTranslator, defaultTranslator } from './i18nUtil';

export const fetchLocale = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return undefined;
}
return state.locale;
};

export const fetchTranslator = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return defaultTranslator;
}
return state.translate;
};

export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
if (state === undefined) {
return defaultErrorTranslator;
}
return state.translateError;
};

export const getLocale = (state: JsonFormsState) =>
fetchLocale(get(state, 'jsonforms.i18n'));

export const getTranslator =
() =>
(state: JsonFormsState): Translator =>
fetchTranslator(get(state, 'jsonforms.i18n'));

export const getErrorTranslator =
() =>
(state: JsonFormsState): ErrorTranslator =>
fetchErrorTranslator(get(state, 'jsonforms.i18n'));
3 changes: 1 addition & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export * from './reducers';
export * from './testers';
export * as Test from './testers';
export * from './util';

export * from './Helpers';
export * from './store';
export * from './i18n';
export * from './mappers';
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@
*/

import isEmpty from 'lodash/isEmpty';
import {
getErrorTranslator,
getAjv,
getConfig,
getData,
getErrorAt,
getSchema,
getTranslator,
} from '../reducers';
import type { JsonFormsCellRendererRegistryEntry } from '../reducers';
import type { AnyAction, Dispatch } from './type';
import { Resolve } from './util';
import { isInherentlyEnabled, isVisible } from './runtime';
import { isVisible, Resolve } from '../util';
import {
DispatchPropsOfControl,
EnumOption,
Expand All @@ -47,9 +35,25 @@ import {
OwnPropsOfEnum,
StatePropsOfScopedRenderer,
} from './renderer';
import { getCombinedErrorMessage, getI18nKeyPrefix } from '../i18n';
import type { JsonFormsState } from '../store';
import {
getCombinedErrorMessage,
getErrorTranslator,
getI18nKeyPrefix,
getTranslator,
} from '../i18n';
import type { JsonSchema } from '../models';
import {
AnyAction,
Dispatch,
getAjv,
getConfig,
getData,
getErrorAt,
getSchema,
JsonFormsCellRendererRegistryEntry,
JsonFormsState,
} from '../store';
import { isInherentlyEnabled } from './util';

export interface OwnPropsOfCell extends OwnPropsOfControl {
data?: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
*/

import type { ControlElement, JsonSchema, UISchemaElement } from '../models';
import { findUISchema, JsonFormsUISchemaRegistryEntry } from '../reducers';
import { Resolve } from './util';
import { findUISchema } from '../reducers';
import { JsonFormsUISchemaRegistryEntry } from '../store';
import { Resolve } from '../util/util';

export interface CombinatorSubSchemaRenderInfo {
schema: JsonSchema;
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/mappers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
The MIT License

Copyright (c) 2024 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

export * from './renderer';
export * from './cell';
export * from './combinators';
export * from './util';
Loading
Loading