Socket
Socket
Sign inDemoInstall

@jsonforms/core

Package Overview
Dependencies
Maintainers
6
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsonforms/core - npm Package Compare versions

Comparing version 3.0.0-beta.5 to 3.0.0-rc.0

docs/interfaces/labelable.html

13

lib/i18n/i18nUtil.d.ts
import { ErrorObject } from 'ajv';
import { UISchemaElement } from '../models';
import { Labelable, UISchemaElement } from '../models';
import { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
export declare const getI18nKeyPrefixBySchema: (schema: i18nJsonSchema | undefined, uischema: UISchemaElement | undefined) => string | undefined;
export declare const getI18nKeyPrefixBySchema: (schema: i18nJsonSchema | undefined, uischema: unknown | undefined) => string | undefined;
/**

@@ -10,4 +10,4 @@ * Transforms a given path to a prefix which can be used for i18n keys.

export declare const transformPathToI18nPrefix: (path: string) => string;
export declare const getI18nKeyPrefix: (schema: i18nJsonSchema | undefined, uischema: UISchemaElement | undefined, path: string | undefined) => string | undefined;
export declare const getI18nKey: (schema: i18nJsonSchema | undefined, uischema: UISchemaElement | undefined, path: string | undefined, key: string) => string | undefined;
export declare const getI18nKeyPrefix: (schema: i18nJsonSchema | undefined, uischema: unknown | undefined, path: string | undefined) => string;
export declare const getI18nKey: (schema: i18nJsonSchema | undefined, uischema: unknown | undefined, path: string | undefined, key: string) => string;
export declare const defaultTranslator: Translator;

@@ -20,1 +20,6 @@ export declare const defaultErrorTranslator: ErrorTranslator;

export declare const getCombinedErrorMessage: (errors: ErrorObject[], et: ErrorTranslator, t: Translator, schema?: i18nJsonSchema, uischema?: UISchemaElement, path?: string) => string;
/**
* This can be used to internationalize the label of the given Labelable (e.g. UI Schema elements).
* This should not be used for controls as there we have additional context in the form of the JSON Schema available.
*/
export declare const deriveLabelForUISchemaElement: (uischema: Labelable<boolean>, t: Translator) => string | undefined;

@@ -25,3 +25,3 @@ import { JsonSchema } from './jsonSchema';

*/
export interface Lableable<T = string> {
export interface Labelable<T = string> {
/**

@@ -35,3 +35,3 @@ * Label for UI schema element.

*/
export interface Labeled<T = string> extends Lableable<T> {
export interface Labeled<T = string> extends Labelable<T> {
label: string | T;

@@ -162,3 +162,3 @@ }

*/
export interface GroupLayout extends Layout, Lableable {
export interface GroupLayout extends Layout, Labelable {
type: 'Group';

@@ -182,3 +182,3 @@ }

*/
export interface LabelElement extends UISchemaElement {
export interface LabelElement extends UISchemaElement, Internationalizable {
type: 'Label';

@@ -194,3 +194,3 @@ /**

*/
export interface ControlElement extends UISchemaElement, Scoped, Lableable<string | boolean | LabelDescription>, Internationalizable {
export interface ControlElement extends UISchemaElement, Scoped, Labelable<string | boolean | LabelDescription>, Internationalizable {
type: 'Control';

@@ -222,3 +222,3 @@ }

export declare const isScoped: (obj: unknown) => obj is Scoped;
export declare const isLabelable: (obj: unknown) => obj is Lableable<string>;
export declare const isLabeled: (obj: unknown) => obj is Labeled<string>;
export declare const isLabelable: (obj: unknown) => obj is Labelable<string>;
export declare const isLabeled: <T = never>(obj: unknown) => obj is Labeled<T>;
import { JsonFormsI18nState } from '../i18n';
import { I18nActions } from '../actions';
import { Reducer } from '../util';
export declare const defaultJsonFormsI18nState: JsonFormsI18nState;
export declare const defaultJsonFormsI18nState: Required<JsonFormsI18nState>;
export declare const i18nReducer: Reducer<JsonFormsI18nState, I18nActions>;

@@ -6,0 +6,0 @@ export declare const fetchLocale: (state?: JsonFormsI18nState) => string;

@@ -12,7 +12,16 @@ import { Categorization, ControlElement, JsonSchema, UISchemaElement } from '../models';

*/
export declare type Tester = (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => boolean;
export declare type Tester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
/**
* A ranked tester associates a tester with a number.
*/
export declare type RankedTester = (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => number;
export declare type RankedTester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
/**
* Additional context given to a tester in addition to UISchema and JsonSchema.
*/
export interface TesterContext {
/** The root JsonSchema of the form. Can be used to resolve references. */
rootSchema: JsonSchema;
/** The form wide configuration object given to JsonForms. */
config: any;
}
export declare const isControl: (uischema: any) => uischema is ControlElement;

@@ -101,4 +110,4 @@ /**

*/
export declare const rankWith: (rank: number, tester: Tester) => (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => number;
export declare const withIncreasedRank: (by: number, rankedTester: RankedTester) => (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => number;
export declare const rankWith: (rank: number, tester: Tester) => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
export declare const withIncreasedRank: (by: number, rankedTester: RankedTester) => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
/**

@@ -178,3 +187,3 @@ * Default tester for boolean.

export declare const isObjectArrayControl: Tester;
export declare const isObjectArrayWithNesting: (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => boolean;
export declare const isObjectArrayWithNesting: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
/**

@@ -199,3 +208,3 @@ * Synonym for isObjectArrayControl

* Tests whether the given UI schema is of type Control, if the schema
* is of type string and has option format
* is of type integer and has option format
* @type {Tester}

@@ -202,0 +211,0 @@ */

@@ -1,2 +0,2 @@

import { ControlElement, JsonSchema, UISchemaElement } from '../models';
import { ControlElement, JsonSchema, LabelElement, UISchemaElement } from '../models';
import { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry } from '../reducers';

@@ -85,2 +85,5 @@ import { JsonFormsUISchemaRegistryEntry } from '../reducers';

}
export interface OwnPropsOfLabel extends OwnPropsOfRenderer {
uischema?: LabelElement;
}
export interface OwnPropsOfEnum {

@@ -206,2 +209,3 @@ options?: EnumOption[];

direction: 'row' | 'column';
label?: string;
}

@@ -353,2 +357,3 @@ export interface LayoutProps extends StatePropsOfLayout {

rootSchema: JsonSchema;
config: any;
}

@@ -402,1 +407,13 @@ export interface JsonFormsProps extends StatePropsOfJsonFormsRenderer {

}
export interface StatePropsOfLabel extends StatePropsOfRenderer {
text?: string;
}
export interface LabelProps extends StatePropsOfLabel {
}
export declare const mapStateToLabelProps: (state: JsonFormsState, props: OwnPropsOfLabel) => {
text: string;
visible: boolean;
config: any;
renderers: JsonFormsRendererRegistryEntry[];
cells: JsonFormsCellRendererRegistryEntry[];
};
{
"name": "@jsonforms/core",
"version": "3.0.0-beta.5",
"version": "3.0.0-rc.0",
"description": "Core module of JSON Forms",

@@ -91,3 +91,3 @@ "repository": "https://github.com/eclipsesource/jsonforms",

},
"gitHead": "b66023cf081e56baa3194ac3d6658e23fd267bf9"
"gitHead": "5ef030e8b3f91bcdc3e6b8d232a0b191bf1195ce"
}
import { ErrorObject } from 'ajv';
import { isInternationalized, UISchemaElement } from '../models';
import { isInternationalized, Labelable, UISchemaElement } from '../models';
import { getControlPath } from '../reducers';

@@ -9,3 +9,3 @@ import { formatErrorMessage } from '../util';

schema: i18nJsonSchema | undefined,
uischema: UISchemaElement | undefined
uischema: unknown | undefined
): string | undefined => {

@@ -22,3 +22,3 @@ if (isInternationalized(uischema)) {

*/
export const transformPathToI18nPrefix = (path: string) => {
export const transformPathToI18nPrefix = (path: string): string => {
return (

@@ -34,5 +34,5 @@ path

schema: i18nJsonSchema | undefined,
uischema: UISchemaElement | undefined,
uischema: unknown | undefined,
path: string | undefined
): string | undefined => {
): string => {
return (

@@ -46,6 +46,6 @@ getI18nKeyPrefixBySchema(schema, uischema) ??

schema: i18nJsonSchema | undefined,
uischema: UISchemaElement | undefined,
uischema: unknown | undefined,
path: string | undefined,
key: string
): string | undefined => {
): string => {
return `${getI18nKeyPrefix(schema, uischema, path)}.${key}`;

@@ -113,1 +113,18 @@ };

};
/**
* This can be used to internationalize the label of the given Labelable (e.g. UI Schema elements).
* This should not be used for controls as there we have additional context in the form of the JSON Schema available.
*/
export const deriveLabelForUISchemaElement = (uischema: Labelable<boolean>, t: Translator): string | undefined => {
if (uischema.label === false) {
return undefined;
}
if ((uischema.label === undefined || uischema.label === null || uischema.label === true) && !isInternationalized(uischema)) {
return undefined;
}
const stringifiedLabel = typeof uischema.label === 'string' ? uischema.label : JSON.stringify(uischema.label);
const i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
const i18nKey = typeof i18nKeyPrefix === 'string' ? `${i18nKeyPrefix}.label` : stringifiedLabel;
return t(i18nKey, stringifiedLabel, { uischema: uischema });
}

@@ -53,3 +53,3 @@ /*

*/
export interface Lableable<T = string> {
export interface Labelable<T = string> {
/**

@@ -64,3 +64,3 @@ * Label for UI schema element.

*/
export interface Labeled<T = string> extends Lableable<T> {
export interface Labeled<T = string> extends Labelable<T> {
label: string | T;

@@ -212,3 +212,3 @@ }

*/
export interface GroupLayout extends Layout, Lableable {
export interface GroupLayout extends Layout, Labelable {
type: 'Group';

@@ -234,3 +234,3 @@ }

*/
export interface LabelElement extends UISchemaElement {
export interface LabelElement extends UISchemaElement, Internationalizable {
type: 'Label';

@@ -247,3 +247,3 @@ /**

*/
export interface ControlElement extends UISchemaElement, Scoped, Lableable<string | boolean | LabelDescription>, Internationalizable {
export interface ControlElement extends UISchemaElement, Scoped, Labelable<string | boolean | LabelDescription>, Internationalizable {
type: 'Control';

@@ -288,6 +288,6 @@ }

export const isLabelable = (obj: unknown): obj is Lableable =>
export const isLabelable = (obj: unknown): obj is Labelable =>
obj && typeof obj === 'object';
export const isLabeled = (obj: unknown): obj is Labeled =>
isLabelable(obj) && ['string', 'object'].includes(typeof obj.label);
export const isLabeled = <T = never>(obj: unknown): obj is Labeled<T> =>
isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);

@@ -30,3 +30,3 @@ /*

export const defaultJsonFormsI18nState: JsonFormsI18nState = {
export const defaultJsonFormsI18nState: Required<JsonFormsI18nState> = {
locale: 'en',

@@ -33,0 +33,0 @@ translate: defaultTranslator,

@@ -52,3 +52,3 @@ /*

*/
export type Tester = (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema) => boolean;
export type Tester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;

@@ -61,5 +61,15 @@ /**

schema: JsonSchema,
rootSchema: JsonSchema
context: TesterContext
) => number;
/**
* Additional context given to a tester in addition to UISchema and JsonSchema.
*/
export interface TesterContext {
/** The root JsonSchema of the form. Can be used to resolve references. */
rootSchema: JsonSchema;
/** The form wide configuration object given to JsonForms. */
config: any;
}
export const isControl = (uischema: any): uischema is ControlElement =>

@@ -80,3 +90,3 @@ !isEmpty(uischema) && uischema.scope !== undefined;

predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean
): Tester => (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema): boolean => {
): Tester => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext): boolean => {
if (isEmpty(uischema) || !isControl(uischema)) {

@@ -94,3 +104,3 @@ return false;

if (hasType(schema, 'object')) {
currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
currentDataSchema = resolveSchema(schema, schemaPath, context?.rootSchema);
}

@@ -101,3 +111,3 @@ if (currentDataSchema === undefined) {

return predicate(currentDataSchema, rootSchema);
return predicate(currentDataSchema, context?.rootSchema);
};

@@ -108,3 +118,3 @@

predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean
): Tester => (uischema: UISchemaElement, schema: JsonSchema, rootSchema: JsonSchema): boolean => {
): Tester => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext): boolean => {
if (isEmpty(uischema) || !isControl(uischema)) {

@@ -116,3 +126,3 @@ return false;

if (hasType(schema, 'object')) {
currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
currentDataSchema = resolveSchema(schema, schemaPath, context?.rootSchema);
}

@@ -125,3 +135,3 @@ currentDataSchema = get(currentDataSchema, subPath);

return predicate(currentDataSchema, rootSchema);
return predicate(currentDataSchema, context?.rootSchema);
};

@@ -229,4 +239,4 @@

schema: JsonSchema,
rootSchema: JsonSchema
) => testers.reduce((acc, tester) => acc && tester(uischema, schema, rootSchema), true);
context: TesterContext
) => testers.reduce((acc, tester) => acc && tester(uischema, schema, context), true);

@@ -241,4 +251,4 @@ /**

schema: JsonSchema,
rootSchema: JsonSchema
) => testers.reduce((acc, tester) => acc || tester(uischema, schema, rootSchema), false);
context: TesterContext
) => testers.reduce((acc, tester) => acc || tester(uischema, schema, context), false);
/**

@@ -254,5 +264,5 @@ * Create a ranked tester that will associate a number with a given tester, if the

schema: JsonSchema,
rootSchema: JsonSchema
context: TesterContext
): number => {
if (tester(uischema, schema, rootSchema)) {
if (tester(uischema, schema, context)) {
return rank;

@@ -267,5 +277,5 @@ }

schema: JsonSchema,
rootSchema: JsonSchema
context: TesterContext
): number => {
const rank = rankedTester(uischema, schema, rootSchema);
const rank = rankedTester(uischema, schema, context);
if (rank === NOT_APPLICABLE) {

@@ -453,9 +463,9 @@ return NOT_APPLICABLE;

schema: JsonSchema,
rootSchema: JsonSchema
context: TesterContext
): boolean => {
if (!uiTypeIs('Control')(uischema, schema, rootSchema)) {
if (!uiTypeIs('Control')(uischema, schema, context)) {
return false;
}
const schemaPath = (uischema as ControlElement).scope;
const resolvedSchema = resolveSchema(schema, schemaPath, rootSchema ?? schema);
const resolvedSchema = resolveSchema(schema, schemaPath, context?.rootSchema ?? schema);
let objectDepth = 0;

@@ -482,3 +492,3 @@ if (resolvedSchema !== undefined && resolvedSchema.items !== undefined) {

return false;
}, rootSchema)
}, context?.rootSchema)
) {

@@ -549,3 +559,3 @@ return true;

* Tests whether the given UI schema is of type Control, if the schema
* is of type string and has option format
* is of type integer and has option format
* @type {Tester}

@@ -584,4 +594,4 @@ */

schema: JsonSchema,
rootSchema: JsonSchema
context: TesterContext
) => !tester(uischema, schema, rootSchema);
) => !tester(uischema, schema, context);

@@ -27,3 +27,3 @@ /*

import get from 'lodash/get';
import { ControlElement, JsonSchema, UISchemaElement } from '../models';
import { ControlElement, isLabelable, JsonSchema, LabelElement, UISchemaElement } from '../models';
import find from 'lodash/find';

@@ -36,3 +36,2 @@ import {

import {
findUISchema,
getAjv,

@@ -62,3 +61,3 @@ getCells,

import { JsonFormsState } from '../store';
import { getCombinedErrorMessage, getI18nKey, getI18nKeyPrefix, Translator } from '../i18n';
import { deriveLabelForUISchemaElement, getCombinedErrorMessage, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, Translator } from '../i18n';

@@ -261,2 +260,6 @@ const isRequired = (

export interface OwnPropsOfLabel extends OwnPropsOfRenderer {
uischema?: LabelElement;
}
export interface OwnPropsOfEnum {

@@ -405,2 +408,3 @@ options?: EnumOption[];

direction: 'row' | 'column';
label?: string;
}

@@ -865,2 +869,6 @@

// some layouts have labels which might need to be translated
const t = getTranslator()(state);
const label = isLabelable(uischema) ? deriveLabelForUISchemaElement(uischema, t) : undefined;
return {

@@ -877,3 +885,4 @@ ...layoutDefaultProps,

direction: ownProps.direction ?? getDirection(uischema),
config
config,
label
};

@@ -889,2 +898,3 @@ };

rootSchema: JsonSchema;
config: any;
}

@@ -898,26 +908,11 @@

): StatePropsOfJsonFormsRenderer => {
let uischema = ownProps.uischema;
if (uischema === undefined) {
if (ownProps.schema) {
uischema = findUISchema(
state.jsonforms.uischemas,
ownProps.schema,
undefined,
ownProps.path,
undefined,
undefined,
state.jsonforms.core.schema
);
} else {
uischema = getUiSchema(state);
}
}
return {
renderers: ownProps.renderers || get(state.jsonforms, 'renderers') || [],
cells: ownProps.cells || get(state.jsonforms, 'cells') || [],
renderers: ownProps.renderers || get(state.jsonforms, 'renderers'),
cells: ownProps.cells || get(state.jsonforms, 'cells'),
schema: ownProps.schema || getSchema(state),
rootSchema: getSchema(state),
uischema: uischema,
path: ownProps.path
uischema: ownProps.uischema || getUiSchema(state),
path: ownProps.path,
enabled: ownProps.enabled,
config: getConfig(state)
};

@@ -1076,1 +1071,33 @@ };

DispatchPropsOfArrayControl {}
export interface StatePropsOfLabel extends StatePropsOfRenderer {
text?: string;
}
export interface LabelProps extends StatePropsOfLabel{
}
export const mapStateToLabelProps = (
state: JsonFormsState,
props: OwnPropsOfLabel
) => {
const { uischema } = props;
const visible: boolean =
props.visible === undefined || hasShowRule(uischema)
? isVisible(props.uischema, getData(state), props.path, getAjv(state))
: props.visible;
const text = uischema.text;
const t = getTranslator()(state);
const i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
const i18nKey = i18nKeyPrefix ? `${i18nKeyPrefix}.text` : text ?? '';
const i18nText = t(i18nKey, text, { uischema });
return {
text: i18nText,
visible,
config: getConfig(state),
renderers: props.renderers || getRenderers(state),
cells: props.cells || getCells(state),
}
}

@@ -49,3 +49,4 @@ /*

uiTypeIs,
isOneOfEnumControl
isOneOfEnumControl,
TesterContext
} from '../src/testers';

@@ -61,2 +62,5 @@ import {

const createTesterContext =
(rootSchema: JsonSchema, config?: any): TesterContext => ({ rootSchema, config });
test.beforeEach(t => {

@@ -80,4 +84,5 @@ t.context.uischema = {

};
t.true(schemaTypeIs('string')(uischema, schema, schema));
t.false(schemaTypeIs('integer')(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.true(schemaTypeIs('string')(uischema, schema, testerContext));
t.false(schemaTypeIs('integer')(uischema, schema, testerContext));
});

@@ -96,3 +101,4 @@

};
t.false(schemaTypeIs('integer')(label, schema, schema));
const testerContext = createTesterContext(schema);
t.false(schemaTypeIs('integer')(label, schema, testerContext));
});

@@ -111,3 +117,4 @@

};
t.false(schemaTypeIs('string')(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.false(schemaTypeIs('string')(uischema, schema, testerContext));
});

@@ -126,4 +133,5 @@

};
t.true(schemaTypeIs('string')(uischema, schema, schema));
t.true(schemaTypeIs('integer')(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.true(schemaTypeIs('string')(uischema, schema, testerContext));
t.true(schemaTypeIs('integer')(uischema, schema, testerContext));
});

@@ -145,3 +153,4 @@

};
t.true(formatIs('date-time')(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.true(formatIs('date-time')(uischema, schema, testerContext));
});

@@ -193,4 +202,5 @@

};
const testerContext = createTesterContext(schema);
t.true(
schemaMatches(subSchema => subSchema.type === 'string')(uischema, schema, schema)
schemaMatches(subSchema => subSchema.type === 'string')(uischema, schema, testerContext)
);

@@ -209,4 +219,5 @@ });

};
const testerContext = createTesterContext(schema);
t.true(
schemaMatches(subSchema => subSchema.type === 'string')(uischema, schema, schema)
schemaMatches(subSchema => subSchema.type === 'string')(uischema, schema, testerContext)
);

@@ -226,3 +237,4 @@ });

};
t.false(schemaMatches(() => false)(label, schema, schema));
const testerContext = createTesterContext(schema);
t.false(schemaMatches(() => false)(label, schema, testerContext));
});

@@ -241,3 +253,4 @@

};
t.false(schemaMatches(() => false)(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.false(schemaMatches(() => false)(uischema, schema, testerContext));
});

@@ -288,3 +301,4 @@

};
t.true(and(schemaTypeIs('string'), scopeEndIs('foo'))(uischema, schema, schema));
const testerContext = createTesterContext(schema);
t.true(and(schemaTypeIs('string'), scopeEndIs('foo'))(uischema, schema, testerContext));
});

@@ -303,4 +317,5 @@

};
const testerContext = createTesterContext(schema);
t.true(
or(schemaTypeIs('integer'), optionIs('slider', true))(uischema, schema, schema)
or(schemaTypeIs('integer'), optionIs('slider', true))(uischema, schema, testerContext)
);

@@ -324,3 +339,3 @@ });

t.true(
isPrimitiveArrayControl(control, schema, schema),
isPrimitiveArrayControl(control, schema, createTesterContext(schema)),
`Primitive array tester was not triggered for 'integer' schema type`

@@ -339,3 +354,3 @@ );

t.true(
isPrimitiveArrayControl(control, schemaWithRefs, schemaWithRefs),
isPrimitiveArrayControl(control, schemaWithRefs, createTesterContext(schemaWithRefs)),
`Primitive array tester was not triggered for 'integer' schema type with refs`

@@ -353,3 +368,3 @@ );

t.false(
isPrimitiveArrayControl(control, objectSchema, objectSchema),
isPrimitiveArrayControl(control, objectSchema, createTesterContext(objectSchema)),
`Primitive array tester was not triggered for 'object' schema type`

@@ -420,3 +435,3 @@ );

};
t.true(isObjectArrayControl(control, schema, schema));
t.true(isObjectArrayControl(control, schema, createTesterContext(schema)));
const schema_noType: JsonSchema = {

@@ -436,3 +451,3 @@ type: 'object',

};
t.true(isObjectArrayControl(control, schema_noType, schema_noType));
t.true(isObjectArrayControl(control, schema_noType, createTesterContext(schema_noType)));
const schema_innerAllOf: JsonSchema = {

@@ -460,3 +475,3 @@ type: 'object',

};
t.true(isObjectArrayControl(control, schema_innerAllOf, schema_innerAllOf));
t.true(isObjectArrayControl(control, schema_innerAllOf, createTesterContext(schema_innerAllOf)));

@@ -483,3 +498,4 @@ const schemaWithRefs = {

}
t.true(isObjectArrayControl(control, schemaWithRefs, schemaWithRefs));
const testerContext = createTesterContext(schemaWithRefs);
t.true(isObjectArrayControl(control, schemaWithRefs, testerContext));
});

@@ -824,3 +840,3 @@

t.true(isObjectArrayWithNesting(uischema, nestedSchema3, undefined));
t.true(isObjectArrayWithNesting(uischema, nestedSchemaWithRef, nestedSchemaWithRef));
t.true(isObjectArrayWithNesting(uischema, nestedSchemaWithRef, createTesterContext(nestedSchemaWithRef)));

@@ -896,3 +912,4 @@ t.false(isObjectArrayWithNesting(uischemaOptions.default, schema, undefined));

}
t.true(isOneOfEnumControl(control, schemaWithRefs, schemaWithRefs));
const testerContext = createTesterContext(schemaWithRefs);
t.true(isOneOfEnumControl(control, schemaWithRefs, testerContext));
});

@@ -35,6 +35,5 @@ /*

import { CoreActions, init, setValidationMode, update, UpdateAction, UPDATE_DATA } from '../../src/actions/actions';
import { ControlElement, RuleEffect, UISchemaElement } from '../../src/models/uischema';
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
import { ControlElement, LabelElement, RuleEffect, UISchemaElement } from '../../src/models/uischema';
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
import { clearAllIds } from '../../src/util/ids';
import { generateDefaultUISchema } from '../../src/generators/uischema';
import { JsonSchema } from '../../src/models/jsonSchema';

@@ -499,3 +498,3 @@ import { rankWith } from '../../src/testers/testers';

test(`mapStateToDispatchRendererProps should generate UI schema given ownProps schema`, t => {
test(`mapStateToJsonFormsRendererProps should use registered UI schema given ownProps schema`, t => {
const store = mockStore(createState(coreUISchema));

@@ -512,6 +511,6 @@ const schema = {

const props = mapStateToJsonFormsRendererProps(store.getState(), { schema });
t.deepEqual(props.uischema, generateDefaultUISchema(schema));
t.deepEqual(props.uischema, coreUISchema);
});
test(`mapStateToDispatchRendererProps should use registered UI schema given no ownProps`, t => {
test(`mapStateToJsonFormsRendererProps should use registered UI schema given no ownProps`, t => {
const store = mockStore(createState(coreUISchema));

@@ -522,3 +521,3 @@ const props = mapStateToJsonFormsRendererProps(store.getState(), {});

test(`mapStateToDispatchRendererProps should use UI schema if given via ownProps`, t => {
test(`mapStateToJsonFormsRendererProps should use UI schema if given via ownProps`, t => {
const store = mockStore(createState(coreUISchema));

@@ -1737,1 +1736,100 @@ const schema = {

});
test('mapStateToLabelProps - i18n - should not crash without i18n', t => {
const labelUISchema : LabelElement = {
type: 'Label',
text: 'foo',
i18n: 'bar'
}
const ownProps = {
uischema: labelUISchema
};
const state: JsonFormsState = createState(labelUISchema);
state.jsonforms.i18n = undefined;
const props = mapStateToLabelProps(state, ownProps);
t.is(props.text, 'foo');
});
test('mapStateToLabelProps - i18n - default translation has no effect', t => {
const labelUISchema : LabelElement = {
type: 'Label',
text: 'foo',
i18n: 'bar'
}
const ownProps = {
uischema: labelUISchema
};
const state: JsonFormsState = createState(labelUISchema);
state.jsonforms.i18n = defaultJsonFormsI18nState;
const props = mapStateToLabelProps(state, ownProps);
t.is(props.text, 'foo');
});
test('mapStateToLabelProps - i18n - default key translation', t => {
const labelUISchema : LabelElement = {
type: 'Label',
text: 'foo'
}
const ownProps = {
uischema: labelUISchema
};
const state: JsonFormsState = createState(labelUISchema);
state.jsonforms.i18n = defaultJsonFormsI18nState;
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
switch(key){
case 'foo': return 'my message';
default: return defaultMessage;
}
}
const props = mapStateToLabelProps(state, ownProps);
t.is(props.text, 'my message');
});
test('mapStateToLabelProps - i18n - default message translation', t => {
const labelUISchema : LabelElement = {
type: 'Label',
text: 'foo',
i18n: 'bar'
}
const ownProps = {
uischema: labelUISchema
};
const state: JsonFormsState = createState(labelUISchema);
state.jsonforms.i18n = defaultJsonFormsI18nState;
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
switch(defaultMessage){
case 'foo': return 'my message';
default: return defaultMessage;
}
}
const props = mapStateToLabelProps(state, ownProps);
t.is(props.text, 'my message');
});
test('mapStateToLabelProps - i18n - i18n key translation', t => {
const labelUISchema : LabelElement = {
type: 'Label',
text: 'foo',
i18n: 'bar'
}
const ownProps = {
uischema: labelUISchema
};
const state: JsonFormsState = createState(labelUISchema);
state.jsonforms.i18n = defaultJsonFormsI18nState;
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined): string | undefined => {
switch(key){
case 'bar.text': return 'my message';
default: return defaultMessage;
}
}
const props = mapStateToLabelProps(state, ownProps);
t.is(props.text, 'my message');
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc