@jsonforms/vue
Advanced tools
Comparing version 2.5.1-alpha.1 to 2.5.1-beta.0
@@ -1,4 +0,4 @@ | ||
import { defineComponent, openBlock, createBlock, inject, ref, watch, onBeforeMount, onUnmounted, resolveDynamicComponent, resolveComponent } from 'vue'; | ||
import { defineComponent, openBlock, createBlock, inject, ref, computed, onBeforeMount, onUnmounted, resolveDynamicComponent, resolveComponent } from 'vue'; | ||
import maxBy from 'lodash/maxBy'; | ||
import { createId, removeId, mapDispatchToControlProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToEnumControlProps, mapStateToOneOfEnumControlProps, mapDispatchToArrayControlProps, mapStateToArrayControlProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToOneOfProps, mapStateToCellProps, defaultMapStateToEnumCellProps, mapStateToDispatchCellProps, mapStateToLayoutProps, mapStateToArrayLayoutProps, mapStateToMasterListItemProps, mapStateToJsonFormsRendererProps, Generate, configReducer, Actions, coreReducer } from '@jsonforms/core'; | ||
import { createId, removeId, mapDispatchToControlProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToEnumControlProps, mapStateToOneOfEnumControlProps, mapDispatchToArrayControlProps, mapStateToArrayControlProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToOneOfProps, mapStateToLayoutProps, mapStateToArrayLayoutProps, mapStateToMasterListItemProps, mapStateToJsonFormsRendererProps, mapStateToCellProps, defaultMapStateToEnumCellProps, mapStateToDispatchCellProps, Generate, configReducer, Actions, coreReducer } from '@jsonforms/core'; | ||
@@ -106,35 +106,2 @@ function _typeof(obj) { | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var script$3 = defineComponent({ | ||
@@ -226,104 +193,3 @@ name: 'unknown-renderer' | ||
}; | ||
var controlInit = function controlInit() { | ||
return { | ||
data: null, | ||
description: null, | ||
errors: null, | ||
label: null, | ||
visible: null, | ||
enabled: null, | ||
id: null, | ||
path: null, | ||
required: null, | ||
uischema: null, | ||
schema: null, | ||
config: null, | ||
cells: null, | ||
rootSchema: null | ||
}; | ||
}; | ||
var controlWithDetailInit = function controlWithDetailInit() { | ||
return _objectSpread2(_objectSpread2({}, controlInit()), {}, { | ||
uischemas: null | ||
}); | ||
}; | ||
var arrayControlInit = function arrayControlInit() { | ||
return _objectSpread2(_objectSpread2({}, controlWithDetailInit()), {}, { | ||
childErrors: null, | ||
renderers: null, | ||
cells: null | ||
}); | ||
}; | ||
var arrayLayoutInit = function arrayLayoutInit() { | ||
return _objectSpread2(_objectSpread2({}, controlWithDetailInit()), {}, { | ||
minItems: null, | ||
renderers: null, | ||
cells: null | ||
}); | ||
}; | ||
var enumControlInit = function enumControlInit() { | ||
return _objectSpread2(_objectSpread2({}, controlInit()), {}, { | ||
options: null | ||
}); | ||
}; | ||
var combinatorControlInit = function combinatorControlInit() { | ||
return _objectSpread2(_objectSpread2({}, controlWithDetailInit()), {}, { | ||
indexOfFittingSchema: null | ||
}); | ||
}; | ||
var layoutInit = function layoutInit() { | ||
return { | ||
renderers: null, | ||
cells: null, | ||
visible: null, | ||
enabled: null, | ||
path: null, | ||
data: null, | ||
uischema: null, | ||
schema: null, | ||
direction: null | ||
}; | ||
}; | ||
var rendererInit = function rendererInit() { | ||
return { | ||
renderers: null, | ||
cells: null, | ||
schema: null, | ||
rootSchema: null, | ||
uischema: null, | ||
path: null | ||
}; | ||
}; | ||
var masterListItemInit = function masterListItemInit() { | ||
return { | ||
index: null, | ||
selected: null, | ||
path: null, | ||
schema: null, | ||
childLabel: null | ||
}; | ||
}; | ||
var cellInit = function cellInit() { | ||
return { | ||
data: null, | ||
visible: null, | ||
enabled: null, | ||
id: null, | ||
path: null, | ||
errors: null, | ||
isValid: null, | ||
schema: null, | ||
uischema: null, | ||
config: null, | ||
rootSchema: null, | ||
renderers: null, | ||
cells: null | ||
}; | ||
}; | ||
var enumCellInit = function enumCellInit() { | ||
return _objectSpread2(_objectSpread2({}, cellInit()), {}, { | ||
options: null | ||
}); | ||
}; | ||
function useControl(props, stateInit, stateMap, dispatchMap) { | ||
function useControl(props, stateMap, dispatchMap) { | ||
var jsonforms = inject('jsonforms'); | ||
@@ -336,19 +202,9 @@ var dispatch = inject('dispatch'); | ||
var control = ref(stateInit()); | ||
var updateControl = function updateControl(jsonforms, props) { | ||
var _control$value$id; | ||
Object.assign(control.value, stateMap({ | ||
var id = ref(undefined); | ||
var control = computed(function () { | ||
return _objectSpread2(_objectSpread2({}, stateMap({ | ||
jsonforms: jsonforms | ||
}, _objectSpread2(_objectSpread2({}, props), {}, { | ||
id: (_control$value$id = control.value.id) !== null && _control$value$id !== void 0 ? _control$value$id : undefined | ||
}))); | ||
}; | ||
updateControl(jsonforms, props); | ||
watch(function () { | ||
return [].concat(_toConsumableArray(Object.values(jsonforms)), [props]); | ||
}, function () { | ||
updateControl(jsonforms, props); | ||
}, props)), {}, { | ||
id: id.value | ||
}); | ||
}); | ||
@@ -358,8 +214,9 @@ var dispatchMethods = dispatchMap === null || dispatchMap === void 0 ? void 0 : dispatchMap(dispatch); | ||
if (control.value.uischema.scope) { | ||
control.value.id = createId(control.value.uischema.scope); | ||
id.value = createId(control.value.uischema.scope); | ||
} | ||
}); | ||
onUnmounted(function () { | ||
if (control.value.id) { | ||
removeId(control.value.id); | ||
if (id.value) { | ||
removeId(id.value); | ||
id.value = undefined; | ||
} | ||
@@ -380,3 +237,3 @@ }); | ||
var useJsonFormsControl = function useJsonFormsControl(props) { | ||
return useControl(props, controlInit, mapStateToControlProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToControlProps, mapDispatchToControlProps); | ||
}; | ||
@@ -392,3 +249,3 @@ /** | ||
var useJsonFormsControlWithDetail = function useJsonFormsControlWithDetail(props) { | ||
return useControl(props, controlWithDetailInit, mapStateToControlWithDetailProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToControlWithDetailProps, mapDispatchToControlProps); | ||
}; | ||
@@ -403,3 +260,3 @@ /** | ||
var useJsonFormsEnumControl = function useJsonFormsEnumControl(props) { | ||
return useControl(props, enumControlInit, mapStateToEnumControlProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToEnumControlProps, mapDispatchToControlProps); | ||
}; | ||
@@ -415,3 +272,3 @@ /** | ||
var useJsonFormsOneOfEnumControl = function useJsonFormsOneOfEnumControl(props) { | ||
return useControl(props, enumControlInit, mapStateToOneOfEnumControlProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToOneOfEnumControlProps, mapDispatchToControlProps); | ||
}; | ||
@@ -426,3 +283,3 @@ /** | ||
var useJsonFormsArrayControl = function useJsonFormsArrayControl(props) { | ||
return useControl(props, arrayControlInit, mapStateToArrayControlProps, mapDispatchToArrayControlProps); | ||
return useControl(props, mapStateToArrayControlProps, mapDispatchToArrayControlProps); | ||
}; | ||
@@ -437,3 +294,3 @@ /** | ||
var useJsonFormsAllOfControl = function useJsonFormsAllOfControl(props) { | ||
return useControl(props, combinatorControlInit, mapStateToAllOfProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToAllOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -448,3 +305,3 @@ /** | ||
var useJsonFormsAnyOfControl = function useJsonFormsAnyOfControl(props) { | ||
return useControl(props, combinatorControlInit, mapStateToAnyOfProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToAnyOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -459,3 +316,3 @@ /** | ||
var useJsonFormsOneOfControl = function useJsonFormsOneOfControl(props) { | ||
return useControl(props, combinatorControlInit, mapStateToOneOfProps, mapDispatchToControlProps); | ||
return useControl(props, mapStateToOneOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -469,3 +326,3 @@ /** | ||
var useJsonFormsLayout = function useJsonFormsLayout(props) { | ||
var _useControl = useControl(props, layoutInit, mapStateToLayoutProps), | ||
var _useControl = useControl(props, mapStateToLayoutProps), | ||
control = _useControl.control, | ||
@@ -486,3 +343,3 @@ other = _objectWithoutProperties(_useControl, ["control"]); | ||
var useJsonFormsArrayLayout = function useJsonFormsArrayLayout(props) { | ||
var _useControl2 = useControl(props, arrayLayoutInit, mapStateToArrayLayoutProps), | ||
var _useControl2 = useControl(props, mapStateToArrayLayoutProps), | ||
control = _useControl2.control, | ||
@@ -504,3 +361,3 @@ other = _objectWithoutProperties(_useControl2, ["control"]); | ||
var useJsonFormsMasterListItem = function useJsonFormsMasterListItem(props) { | ||
var _useControl3 = useControl(props, masterListItemInit, mapStateToMasterListItemProps), | ||
var _useControl3 = useControl(props, mapStateToMasterListItemProps), | ||
control = _useControl3.control, | ||
@@ -529,32 +386,25 @@ other = _objectWithoutProperties(_useControl3, ["control"]); | ||
var renderer = ref(rendererInit()); | ||
var resolver = { | ||
refResolver: null | ||
}; | ||
var updateRenderer = function updateRenderer(jsonforms, props) { | ||
var _mapStateToJsonFormsR = mapStateToJsonFormsRendererProps({ | ||
var rawProps = computed(function () { | ||
return mapStateToJsonFormsRendererProps({ | ||
jsonforms: jsonforms | ||
}, props), | ||
refResolver = _mapStateToJsonFormsR.refResolver, | ||
other = _objectWithoutProperties(_mapStateToJsonFormsR, ["refResolver"]); | ||
}, props); | ||
}); | ||
var refResolver = computed(function () { | ||
return rawProps.value.refResolver; | ||
}); | ||
var rootSchema = computed(function () { | ||
return rawProps.value.rootSchema; | ||
}); | ||
var renderer = computed(function () { | ||
var _rawProps$value = rawProps.value; | ||
_rawProps$value.refResolver; | ||
_rawProps$value.rootSchema; | ||
var rest = _objectWithoutProperties(_rawProps$value, ["refResolver", "rootSchema"]); | ||
Object.assign(renderer.value, other); | ||
resolver.refResolver = refResolver; | ||
}; | ||
updateRenderer(jsonforms, props); | ||
watch(function () { | ||
return [].concat(_toConsumableArray(Object.values(jsonforms)), [props]); | ||
}, function () { | ||
updateRenderer(jsonforms, props); | ||
return rest; | ||
}); | ||
var refResolver = function refResolver(schema) { | ||
return resolver.refResolver(schema); | ||
}; | ||
return { | ||
renderer: renderer, | ||
refResolver: refResolver | ||
refResolver: refResolver, | ||
rootSchema: rootSchema | ||
}; | ||
@@ -571,3 +421,3 @@ }; | ||
var useJsonFormsCell = function useJsonFormsCell(props) { | ||
var _useControl4 = useControl(props, cellInit, mapStateToCellProps, mapDispatchToControlProps), | ||
var _useControl4 = useControl(props, mapStateToCellProps, mapDispatchToControlProps), | ||
control = _useControl4.control, | ||
@@ -589,3 +439,3 @@ other = _objectWithoutProperties(_useControl4, ["control"]); | ||
var useJsonFormsEnumCell = function useJsonFormsEnumCell(props) { | ||
var _useControl5 = useControl(props, enumCellInit, defaultMapStateToEnumCellProps, mapDispatchToControlProps), | ||
var _useControl5 = useControl(props, defaultMapStateToEnumCellProps, mapDispatchToControlProps), | ||
control = _useControl5.control, | ||
@@ -607,3 +457,3 @@ other = _objectWithoutProperties(_useControl5, ["control"]); | ||
var useJsonFormsDispatchCell = function useJsonFormsDispatchCell(props) { | ||
var _useControl6 = useControl(props, cellInit, mapStateToDispatchCellProps, mapDispatchToControlProps), | ||
var _useControl6 = useControl(props, mapStateToDispatchCellProps, mapDispatchToControlProps), | ||
control = _useControl6.control, | ||
@@ -864,3 +714,3 @@ other = _objectWithoutProperties(_useControl6, ["control"]); | ||
export { script$1 as DispatchCell, script$2 as DispatchRenderer, script as JsonForms, script$3 as UnknownRenderer, arrayControlInit, arrayLayoutInit, cellInit, combinatorControlInit, controlInit, controlWithDetailInit, enumCellInit, enumControlInit, layoutInit, masterListItemInit, masterListItemProps, rendererInit, rendererProps, useControl, useJsonFormsAllOfControl, useJsonFormsAnyOfControl, useJsonFormsArrayControl, useJsonFormsArrayLayout, useJsonFormsCell, useJsonFormsControl, useJsonFormsControlWithDetail, useJsonFormsDispatchCell, useJsonFormsEnumCell, useJsonFormsEnumControl, useJsonFormsLayout, useJsonFormsMasterListItem, useJsonFormsOneOfControl, useJsonFormsOneOfEnumControl, useJsonFormsRenderer }; | ||
export { script$1 as DispatchCell, script$2 as DispatchRenderer, script as JsonForms, script$3 as UnknownRenderer, masterListItemProps, rendererProps, useControl, useJsonFormsAllOfControl, useJsonFormsAnyOfControl, useJsonFormsArrayControl, useJsonFormsArrayLayout, useJsonFormsCell, useJsonFormsControl, useJsonFormsControlWithDetail, useJsonFormsDispatchCell, useJsonFormsEnumCell, useJsonFormsEnumControl, useJsonFormsLayout, useJsonFormsMasterListItem, useJsonFormsOneOfControl, useJsonFormsOneOfEnumControl, useJsonFormsRenderer }; | ||
//# sourceMappingURL=jsonforms-vue.js.map |
@@ -30,14 +30,14 @@ declare const _default: import("vue").DefineComponent<{ | ||
}, { | ||
renderer: { | ||
renderer: import("vue").ComputedRef<{ | ||
uischema: import("@jsonforms/core").UISchemaElement; | ||
schema: import("@jsonforms/core").JsonSchema; | ||
uischema: import("@jsonforms/core").UISchemaElement; | ||
enabled: boolean; | ||
visible: boolean; | ||
path: string; | ||
enabled: boolean; | ||
renderers: import("@jsonforms/core").JsonFormsRendererRegistryEntry[]; | ||
cells: import("@jsonforms/core").JsonFormsCellRendererRegistryEntry[]; | ||
rootSchema: import("@jsonforms/core").JsonSchema; | ||
visible: boolean; | ||
uischemas: import("@jsonforms/core").JsonFormsUISchemaRegistryEntry[]; | ||
}; | ||
refResolver: (schema: any) => any; | ||
}>; | ||
refResolver: import("vue").ComputedRef<any>; | ||
rootSchema: import("vue").ComputedRef<import("@jsonforms/core").JsonSchema>; | ||
}, unknown, { | ||
@@ -44,0 +44,0 @@ determinedRenderer(): any; |
@@ -83,175 +83,9 @@ import { ControlElement, Dispatch, Layout, JsonSchema, UISchemaElement, CoreActions, JsonFormsState, OwnPropsOfMasterListItem, JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry } from '@jsonforms/core'; | ||
} | ||
export declare type Nullable<T> = { | ||
[P in keyof T]: P | null; | ||
}; | ||
export declare const controlInit: () => { | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
cells: null; | ||
rootSchema: null; | ||
}; | ||
export declare const controlWithDetailInit: () => { | ||
uischemas: null; | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
cells: null; | ||
rootSchema: null; | ||
}; | ||
export declare const arrayControlInit: () => { | ||
childErrors: null; | ||
renderers: null; | ||
cells: null; | ||
uischemas: null; | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
rootSchema: null; | ||
}; | ||
export declare const arrayLayoutInit: () => { | ||
minItems: null; | ||
renderers: null; | ||
cells: null; | ||
uischemas: null; | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
rootSchema: null; | ||
}; | ||
export declare const enumControlInit: () => { | ||
options: null; | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
cells: null; | ||
rootSchema: null; | ||
}; | ||
export declare const combinatorControlInit: () => { | ||
indexOfFittingSchema: null; | ||
uischemas: null; | ||
data: null; | ||
description: null; | ||
errors: null; | ||
label: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
required: null; | ||
uischema: null; | ||
schema: null; | ||
config: null; | ||
cells: null; | ||
rootSchema: null; | ||
}; | ||
export declare const layoutInit: () => { | ||
renderers: null; | ||
cells: null; | ||
visible: null; | ||
enabled: null; | ||
path: null; | ||
data: null; | ||
uischema: null; | ||
schema: null; | ||
direction: null; | ||
}; | ||
export declare const rendererInit: () => { | ||
renderers: null; | ||
cells: null; | ||
schema: null; | ||
rootSchema: null; | ||
uischema: null; | ||
path: null; | ||
}; | ||
export declare const masterListItemInit: () => { | ||
index: null; | ||
selected: null; | ||
path: null; | ||
schema: null; | ||
childLabel: null; | ||
}; | ||
export declare const cellInit: () => { | ||
data: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
errors: null; | ||
isValid: null; | ||
schema: null; | ||
uischema: null; | ||
config: null; | ||
rootSchema: null; | ||
renderers: null; | ||
cells: null; | ||
}; | ||
export declare const enumCellInit: () => { | ||
options: null; | ||
data: null; | ||
visible: null; | ||
enabled: null; | ||
id: null; | ||
path: null; | ||
errors: null; | ||
isValid: null; | ||
schema: null; | ||
uischema: null; | ||
config: null; | ||
rootSchema: null; | ||
renderers: null; | ||
cells: null; | ||
}; | ||
export declare type Required<T> = T extends object ? { | ||
[P in keyof T]-?: NonNullable<T[P]>; | ||
} : T; | ||
export declare function useControl<R, D, P>(props: P, stateInit: () => Nullable<R>, stateMap: (state: JsonFormsState, props: P) => R): { | ||
export declare function useControl<R, D, P extends {}>(props: P, stateMap: (state: JsonFormsState, props: P) => R): { | ||
control: Required<R>; | ||
}; | ||
export declare function useControl<R, D, P>(props: P, stateInit: () => Nullable<R>, stateMap: (state: JsonFormsState, props: P) => R, dispatchMap: (dispatch: Dispatch<CoreActions>) => D): { | ||
export declare function useControl<R, D, P extends {}>(props: P, stateMap: (state: JsonFormsState, props: P) => R, dispatchMap: (dispatch: Dispatch<CoreActions>) => D): { | ||
control: Required<R>; | ||
@@ -525,6 +359,6 @@ } & D; | ||
item: { | ||
schema: JsonSchema; | ||
path: string; | ||
index: number; | ||
selected: boolean; | ||
path: string; | ||
schema: JsonSchema; | ||
}; | ||
@@ -540,6 +374,4 @@ }; | ||
export declare const useJsonFormsRenderer: (props: RendererProps<UISchemaElement>) => { | ||
renderer: { | ||
cells: JsonFormsCellRendererRegistryEntry[]; | ||
renderer: import("vue").ComputedRef<{ | ||
uischema: UISchemaElement; | ||
rootSchema: JsonSchema; | ||
schema: JsonSchema; | ||
@@ -550,5 +382,7 @@ enabled: boolean; | ||
renderers: JsonFormsRendererRegistryEntry[]; | ||
cells: JsonFormsCellRendererRegistryEntry[]; | ||
uischemas: import("@jsonforms/core").JsonFormsUISchemaRegistryEntry[]; | ||
}; | ||
refResolver: (schema: any) => any; | ||
}>; | ||
refResolver: import("vue").ComputedRef<any>; | ||
rootSchema: import("vue").ComputedRef<JsonSchema>; | ||
}; | ||
@@ -555,0 +389,0 @@ /** |
{ | ||
"name": "@jsonforms/vue", | ||
"version": "2.5.1-alpha.1", | ||
"version": "2.5.1-beta.0", | ||
"description": "Vue 3 module of JSON Forms", | ||
@@ -50,3 +50,3 @@ "repository": "https://github.com/eclipsesource/jsonforms", | ||
"@babel/preset-typescript": "^7.9.0", | ||
"@jsonforms/core": "^2.5.1-alpha.1", | ||
"@jsonforms/core": "^2.5.1-beta.0", | ||
"@rollup/plugin-alias": "^2.2.0", | ||
@@ -73,3 +73,3 @@ "@types/jest": "^24.0.23", | ||
}, | ||
"gitHead": "e16e5086de06d9b7cbade89d07b0a5e6879eb57e" | ||
"gitHead": "f1e520c5193765c71b5a4095c7a38e30702509b6" | ||
} |
@@ -24,3 +24,2 @@ import { | ||
mapStateToJsonFormsRendererProps, | ||
StatePropsOfJsonFormsRenderer, | ||
mapStateToArrayLayoutProps, | ||
@@ -32,2 +31,3 @@ mapStateToCellProps, | ||
mapStateToDispatchCellProps, | ||
StatePropsOfJsonFormsRenderer, | ||
createId, | ||
@@ -38,7 +38,7 @@ removeId | ||
CompType, | ||
computed, | ||
inject, | ||
onBeforeMount, | ||
onUnmounted, | ||
ref, | ||
watch, | ||
ref | ||
} from '../config'; | ||
@@ -143,102 +143,2 @@ | ||
export type Nullable<T> = { | ||
[P in keyof T]: P | null; | ||
}; | ||
export const controlInit = () => ({ | ||
data: null, | ||
description: null, | ||
errors: null, | ||
label: null, | ||
visible: null, | ||
enabled: null, | ||
id: null, | ||
path: null, | ||
required: null, | ||
uischema: null, | ||
schema: null, | ||
config: null, | ||
cells: null, | ||
rootSchema: null | ||
}); | ||
export const controlWithDetailInit = () => ({ | ||
...controlInit(), | ||
uischemas: null | ||
}); | ||
export const arrayControlInit = () => ({ | ||
...controlWithDetailInit(), | ||
childErrors: null, | ||
renderers: null, | ||
cells: null | ||
}); | ||
export const arrayLayoutInit = () => ({ | ||
...controlWithDetailInit(), | ||
minItems: null, | ||
renderers: null, | ||
cells: null | ||
}); | ||
export const enumControlInit = () => ({ | ||
...controlInit(), | ||
options: null | ||
}); | ||
export const combinatorControlInit = () => ({ | ||
...controlWithDetailInit(), | ||
indexOfFittingSchema: null | ||
}); | ||
export const layoutInit = () => ({ | ||
renderers: null, | ||
cells: null, | ||
visible: null, | ||
enabled: null, | ||
path: null, | ||
data: null, | ||
uischema: null, | ||
schema: null, | ||
direction: null | ||
}); | ||
export const rendererInit = () => ({ | ||
renderers: null, | ||
cells: null, | ||
schema: null, | ||
rootSchema: null, | ||
uischema: null, | ||
path: null | ||
}); | ||
export const masterListItemInit = () => ({ | ||
index: null, | ||
selected: null, | ||
path: null, | ||
schema: null, | ||
childLabel: null | ||
}); | ||
export const cellInit = () => ({ | ||
data: null, | ||
visible: null, | ||
enabled: null, | ||
id: null, | ||
path: null, | ||
errors: null, | ||
isValid: null, | ||
schema: null, | ||
uischema: null, | ||
config: null, | ||
rootSchema: null, | ||
renderers: null, | ||
cells: null | ||
}); | ||
export const enumCellInit = () => ({ | ||
...cellInit(), | ||
options: null | ||
}); | ||
export type Required<T> = T extends object | ||
@@ -248,16 +148,13 @@ ? { [P in keyof T]-?: NonNullable<T[P]> } | ||
export function useControl<R, D, P>( | ||
export function useControl<R, D, P extends {}>( | ||
props: P, | ||
stateInit: () => Nullable<R>, | ||
stateMap: (state: JsonFormsState, props: P) => R | ||
): { control: Required<R> }; | ||
export function useControl<R, D, P>( | ||
export function useControl<R, D, P extends {}>( | ||
props: P, | ||
stateInit: () => Nullable<R>, | ||
stateMap: (state: JsonFormsState, props: P) => R, | ||
dispatchMap: (dispatch: Dispatch<CoreActions>) => D | ||
): { control: Required<R> } & D; | ||
export function useControl<R, D, P>( | ||
export function useControl<R, D, P extends {}>( | ||
props: P, | ||
stateInit: () => Nullable<R>, | ||
stateMap: (state: JsonFormsState, props: P) => R, | ||
@@ -273,16 +170,7 @@ dispatchMap?: (dispatch: Dispatch<CoreActions>) => D | ||
const control = ref<Nullable<R>>(stateInit()); | ||
const updateControl = (jsonforms: JsonFormsSubStates, props: P) => { | ||
Object.assign( | ||
control.value, | ||
stateMap({ jsonforms }, { ...props, id: control.value.id ?? undefined }) | ||
); | ||
}; | ||
updateControl(jsonforms, props); | ||
watch( | ||
() => [...Object.values(jsonforms), props], | ||
() => { | ||
updateControl(jsonforms, props); | ||
} | ||
); | ||
const id = ref<string | undefined>(undefined); | ||
const control = computed(() => ({ | ||
...stateMap({ jsonforms }, props), | ||
id: id.value | ||
})); | ||
@@ -292,4 +180,4 @@ const dispatchMethods = dispatchMap?.(dispatch); | ||
onBeforeMount(() => { | ||
if (control.value.uischema.scope) { | ||
control.value.id = createId(control.value.uischema.scope); | ||
if ((control.value as any).uischema.scope) { | ||
id.value = createId((control.value as any).uischema.scope); | ||
} | ||
@@ -299,4 +187,5 @@ }); | ||
onUnmounted(() => { | ||
if (control.value.id) { | ||
removeId(control.value.id); | ||
if (id.value) { | ||
removeId(id.value); | ||
id.value = undefined; | ||
} | ||
@@ -319,8 +208,3 @@ }); | ||
export const useJsonFormsControl = (props: ControlProps) => { | ||
return useControl( | ||
props, | ||
controlInit, | ||
mapStateToControlProps, | ||
mapDispatchToControlProps | ||
); | ||
return useControl(props, mapStateToControlProps, mapDispatchToControlProps); | ||
}; | ||
@@ -338,3 +222,2 @@ | ||
props, | ||
controlWithDetailInit, | ||
mapStateToControlWithDetailProps, | ||
@@ -354,3 +237,2 @@ mapDispatchToControlProps | ||
props, | ||
enumControlInit, | ||
mapStateToEnumControlProps, | ||
@@ -371,3 +253,2 @@ mapDispatchToControlProps | ||
props, | ||
enumControlInit, | ||
mapStateToOneOfEnumControlProps, | ||
@@ -387,3 +268,2 @@ mapDispatchToControlProps | ||
props, | ||
arrayControlInit, | ||
mapStateToArrayControlProps, | ||
@@ -401,8 +281,3 @@ mapDispatchToArrayControlProps | ||
export const useJsonFormsAllOfControl = (props: ControlProps) => { | ||
return useControl( | ||
props, | ||
combinatorControlInit, | ||
mapStateToAllOfProps, | ||
mapDispatchToControlProps | ||
); | ||
return useControl(props, mapStateToAllOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -417,8 +292,3 @@ | ||
export const useJsonFormsAnyOfControl = (props: ControlProps) => { | ||
return useControl( | ||
props, | ||
combinatorControlInit, | ||
mapStateToAnyOfProps, | ||
mapDispatchToControlProps | ||
); | ||
return useControl(props, mapStateToAnyOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -433,8 +303,3 @@ | ||
export const useJsonFormsOneOfControl = (props: ControlProps) => { | ||
return useControl( | ||
props, | ||
combinatorControlInit, | ||
mapStateToOneOfProps, | ||
mapDispatchToControlProps | ||
); | ||
return useControl(props, mapStateToOneOfProps, mapDispatchToControlProps); | ||
}; | ||
@@ -452,7 +317,3 @@ | ||
export const useJsonFormsLayout = (props: LayoutProps) => { | ||
const { control, ...other } = useControl( | ||
props, | ||
layoutInit, | ||
mapStateToLayoutProps | ||
); | ||
const { control, ...other } = useControl(props, mapStateToLayoutProps); | ||
return { layout: control, ...other }; | ||
@@ -468,7 +329,3 @@ }; | ||
export const useJsonFormsArrayLayout = (props: ControlProps) => { | ||
const { control, ...other } = useControl( | ||
props, | ||
arrayLayoutInit, | ||
mapStateToArrayLayoutProps | ||
); | ||
const { control, ...other } = useControl(props, mapStateToArrayLayoutProps); | ||
return { layout: control, ...other }; | ||
@@ -489,3 +346,3 @@ }; | ||
OwnPropsOfMasterListItem | ||
>(props, masterListItemInit, mapStateToMasterListItemProps); | ||
>(props, mapStateToMasterListItemProps); | ||
return { item: control, ...other }; | ||
@@ -509,37 +366,21 @@ }; | ||
const renderer = ref< | ||
Nullable<Omit<StatePropsOfJsonFormsRenderer, 'refResolver'>> | ||
>(rendererInit()); | ||
const resolver = { refResolver: null }; | ||
const updateRenderer = ( | ||
jsonforms: JsonFormsSubStates, | ||
props: RendererProps | ||
) => { | ||
const { refResolver, ...other } = mapStateToJsonFormsRendererProps( | ||
{ jsonforms }, | ||
props | ||
); | ||
Object.assign(renderer.value, other); | ||
resolver.refResolver = refResolver; | ||
}; | ||
updateRenderer(jsonforms, props); | ||
watch( | ||
() => [...Object.values(jsonforms), props], | ||
() => { | ||
updateRenderer(jsonforms, props); | ||
} | ||
const rawProps = computed( | ||
() => | ||
mapStateToJsonFormsRendererProps( | ||
{ jsonforms }, | ||
props | ||
) as Required<StatePropsOfJsonFormsRenderer> | ||
); | ||
const refResolver = (schema: any) => | ||
(resolver as Pick< | ||
StatePropsOfJsonFormsRenderer, | ||
'refResolver' | ||
>).refResolver(schema); | ||
const refResolver = computed(() => rawProps.value.refResolver); | ||
const rootSchema = computed(() => rawProps.value.rootSchema); | ||
const renderer = computed(() => { | ||
const { refResolver, rootSchema, ...rest} = rawProps.value; | ||
return rest; | ||
}); | ||
return { | ||
renderer: (renderer as unknown) as Required< | ||
Omit<StatePropsOfJsonFormsRenderer, 'refResolver'> | ||
>, | ||
refResolver | ||
renderer, | ||
refResolver, | ||
rootSchema | ||
}; | ||
@@ -558,3 +399,2 @@ }; | ||
props, | ||
cellInit, | ||
mapStateToCellProps, | ||
@@ -576,3 +416,2 @@ mapDispatchToControlProps | ||
props, | ||
enumCellInit, | ||
defaultMapStateToEnumCellProps, | ||
@@ -594,3 +433,2 @@ mapDispatchToControlProps | ||
props, | ||
cellInit, | ||
mapStateToDispatchCellProps, | ||
@@ -597,0 +435,0 @@ mapDispatchToControlProps |
Sorry, the diff of this file is not supported yet
120774
1733