Skip to content

Commit

Permalink
Move logic out of index files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoker committed Jun 25, 2021
1 parent 148c39c commit 90ed9f1
Show file tree
Hide file tree
Showing 41 changed files with 1,498 additions and 1,218 deletions.
38 changes: 38 additions & 0 deletions packages/core/src/Helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
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 { convertToValidClassName, createLabelDescriptionFrom } from './util';
import { ControlElement, JsonSchema, LabelDescription } from './models';

export const Helpers: {
createLabelDescriptionFrom(
withLabel: ControlElement,
schema: JsonSchema
): LabelDescription;
convertToValidClassName(s: string): string;
} = {
createLabelDescriptionFrom,
convertToValidClassName
};
335 changes: 335 additions & 0 deletions packages/core/src/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,335 @@
/*
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 AJV, { ErrorObject } from 'ajv';
import { JsonSchema, UISchemaElement } from '../models';
import { generateDefaultUISchema, generateJsonSchema } from '../generators';

import { RankedTester } from '../testers';
import { UISchemaTester, ValidationMode } from '../reducers';

export const INIT: 'jsonforms/INIT' = 'jsonforms/INIT';
export const UPDATE_CORE: 'jsonforms/UPDATE_CORE' = `jsonforms/UPDATE_CORE`;
export const SET_AJV: 'jsonforms/SET_AJV' = 'jsonforms/SET_AJV';
export const UPDATE_DATA: 'jsonforms/UPDATE' = 'jsonforms/UPDATE';
export const UPDATE_ERRORS: 'jsonforms/UPDATE_ERRORS' =
'jsonforms/UPDATE_ERRORS';
export const VALIDATE: 'jsonforms/VALIDATE' = 'jsonforms/VALIDATE';
export const ADD_RENDERER: 'jsonforms/ADD_RENDERER' = 'jsonforms/ADD_RENDERER';
export const REMOVE_RENDERER: 'jsonforms/REMOVE_RENDERER' =
'jsonforms/REMOVE_RENDERER';
export const ADD_CELL: 'jsonforms/ADD_CELL' = 'jsonforms/ADD_CELL';
export const REMOVE_CELL: 'jsonforms/REMOVE_CELL' = 'jsonforms/REMOVE_CELL';
export const SET_CONFIG: 'jsonforms/SET_CONFIG' = 'jsonforms/SET_CONFIG';
export const ADD_UI_SCHEMA: 'jsonforms/ADD_UI_SCHEMA' = `jsonforms/ADD_UI_SCHEMA`;
export const REMOVE_UI_SCHEMA: 'jsonforms/REMOVE_UI_SCHEMA' = `jsonforms/REMOVE_UI_SCHEMA`;
export const SET_SCHEMA: 'jsonforms/SET_SCHEMA' = `jsonforms/SET_SCHEMA`;
export const SET_UISCHEMA: 'jsonforms/SET_UISCHEMA' = `jsonforms/SET_UISCHEMA`;
export const SET_VALIDATION_MODE: 'jsonforms/SET_VALIDATION_MODE' =
'jsonforms/SET_VALIDATION_MODE';

export const SET_LOCALE: 'jsonforms/SET_LOCALE' = `jsonforms/SET_LOCALE`;
export const SET_LOCALIZED_SCHEMAS: 'jsonforms/SET_LOCALIZED_SCHEMAS' =
'jsonforms/SET_LOCALIZED_SCHEMAS';
export const SET_LOCALIZED_UISCHEMAS: 'jsonforms/SET_LOCALIZED_UISCHEMAS' =
'jsonforms/SET_LOCALIZED_UISCHEMAS';

export const ADD_DEFAULT_DATA: 'jsonforms/ADD_DEFAULT_DATA' = `jsonforms/ADD_DEFAULT_DATA`;
export const REMOVE_DEFAULT_DATA: 'jsonforms/REMOVE_DEFAULT_DATA' = `jsonforms/REMOVE_DEFAULT_DATA`;

export type CoreActions =
| InitAction
| UpdateCoreAction
| UpdateAction
| UpdateErrorsAction
| SetAjvAction
| SetSchemaAction
| SetUISchemaAction
| SetValidationModeAction;

export interface UpdateAction {
type: 'jsonforms/UPDATE';
path: string;
updater(existingData?: any): any;
}

export interface UpdateErrorsAction {
type: 'jsonforms/UPDATE_ERRORS';
errors: ErrorObject[];
}

export interface InitAction {
type: 'jsonforms/INIT';
data: any;
schema: JsonSchema;
uischema: UISchemaElement;
options?: InitActionOptions | AJV.Ajv;
}

export interface UpdateCoreAction {
type: 'jsonforms/UPDATE_CORE';
data?: any;
schema?: JsonSchema;
uischema?: UISchemaElement;
options?: InitActionOptions | AJV.Ajv;
}

export interface InitActionOptions {
ajv?: AJV.Ajv;
validationMode?: ValidationMode;
}

export interface SetValidationModeAction {
type: 'jsonforms/SET_VALIDATION_MODE'
validationMode: ValidationMode
}

export const init = (
data: any,
schema: JsonSchema = generateJsonSchema(data),
uischema?: UISchemaElement,
options?: InitActionOptions | AJV.Ajv
) => ({
type: INIT,
data,
schema,
uischema:
typeof uischema === 'object' ? uischema : generateDefaultUISchema(schema),
options
});

export const updateCore = (
data: any,
schema: JsonSchema,
uischema?: UISchemaElement,
options?: AJV.Ajv | InitActionOptions
): UpdateCoreAction => ({
type: UPDATE_CORE,
data,
schema,
uischema,
options
});

export interface RegisterDefaultDataAction {
type: 'jsonforms/ADD_DEFAULT_DATA';
schemaPath: string;
data: any;
}

export const registerDefaultData = (schemaPath: string, data: any) => ({
type: ADD_DEFAULT_DATA,
schemaPath,
data
});

export interface UnregisterDefaultDataAction {
type: 'jsonforms/REMOVE_DEFAULT_DATA';
schemaPath: string;
}

export const unregisterDefaultData = (schemaPath: string) => ({
type: REMOVE_DEFAULT_DATA,
schemaPath
});

export interface SetAjvAction {
type: 'jsonforms/SET_AJV';
ajv: AJV.Ajv;
}

export const setAjv = (ajv: AJV.Ajv) => ({
type: SET_AJV,
ajv
});

export const update = (
path: string,
updater: (existingData: any) => any
): UpdateAction => ({
type: UPDATE_DATA,
path,
updater
});

export const updateErrors = (errors: ErrorObject[]): UpdateErrorsAction => ({
type: UPDATE_ERRORS,
errors
});

export interface AddRendererAction {
type: 'jsonforms/ADD_RENDERER';
tester: RankedTester;
renderer: any;
}

export const registerRenderer = (tester: RankedTester, renderer: any) => ({
type: ADD_RENDERER,
tester,
renderer
});

export interface AddCellRendererAction {
type: 'jsonforms/ADD_CELL';
tester: RankedTester;
cell: any;
}

export const registerCell = (tester: RankedTester, cell: any) => ({
type: ADD_CELL,
tester,
cell
});

export interface RemoveCellRendererAction {
type: 'jsonforms/REMOVE_CELL';
tester: RankedTester;
cell: any;
}

export const unregisterCell = (tester: RankedTester, cell: any) => ({
type: REMOVE_CELL,
tester,
cell
});

export interface RemoveRendererAction {
type: 'jsonforms/REMOVE_RENDERER';
tester: RankedTester;
renderer: any;
}

export const unregisterRenderer = (tester: RankedTester, renderer: any) => ({
type: REMOVE_RENDERER,
tester,
renderer
});

export interface SetConfigAction {
type: 'jsonforms/SET_CONFIG';
config: any;
}

export const setConfig = (config: any): SetConfigAction => ({
type: SET_CONFIG,
config
});

export const setValidationMode = (validationMode: ValidationMode): SetValidationModeAction => ({
type: SET_VALIDATION_MODE,
validationMode
})

export type UISchemaActions = AddUISchemaAction | RemoveUISchemaAction;

export interface AddUISchemaAction {
type: 'jsonforms/ADD_UI_SCHEMA';
tester: UISchemaTester;
uischema: UISchemaElement;
}

export const registerUISchema = (
tester: UISchemaTester,
uischema: UISchemaElement
): AddUISchemaAction => {
return {
type: ADD_UI_SCHEMA,
tester,
uischema
};
};

export interface RemoveUISchemaAction {
type: 'jsonforms/REMOVE_UI_SCHEMA';
tester: UISchemaTester;
}

export const unregisterUISchema = (
tester: UISchemaTester
): RemoveUISchemaAction => {
return {
type: REMOVE_UI_SCHEMA,
tester
};
};

export type LocaleActions =
| SetLocaleAction
| SetLocalizedSchemasAction
| SetLocalizedUISchemasAction;

export interface SetLocaleAction {
type: 'jsonforms/SET_LOCALE';
locale: string;
}

export const setLocale = (locale: string): SetLocaleAction => ({
type: SET_LOCALE,
locale
});

export interface SetLocalizedSchemasAction {
type: 'jsonforms/SET_LOCALIZED_SCHEMAS';
localizedSchemas: Map<string, JsonSchema>;
}

export const setLocalizedSchemas = (
localizedSchemas: Map<string, JsonSchema>
): SetLocalizedSchemasAction => ({
type: SET_LOCALIZED_SCHEMAS,
localizedSchemas
});

export interface SetSchemaAction {
type: 'jsonforms/SET_SCHEMA';
schema: JsonSchema;
}

export const setSchema = (schema: JsonSchema): SetSchemaAction => ({
type: SET_SCHEMA,
schema
});

export interface SetLocalizedUISchemasAction {
type: 'jsonforms/SET_LOCALIZED_UISCHEMAS';
localizedUISchemas: Map<string, UISchemaElement>;
}

export const setLocalizedUISchemas = (
localizedUISchemas: Map<string, UISchemaElement>
): SetLocalizedUISchemasAction => ({
type: SET_LOCALIZED_UISCHEMAS,
localizedUISchemas
});

export interface SetUISchemaAction {
type: 'jsonforms/SET_UISCHEMA';
uischema: UISchemaElement;
}

export const setUISchema = (uischema: UISchemaElement): SetUISchemaAction => ({
type: SET_UISCHEMA,
uischema
});
Loading

0 comments on commit 90ed9f1

Please sign in to comment.