@react-typed-forms/schemas 10.3.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/controlRender.d.ts +4 -0
- package/lib/hooks.d.ts +1 -0
- package/lib/index.js +18 -4
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +3 -1
- package/package.json +1 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ export interface DataRendererProps extends ParentRendererProps {
|
|
|
117
117
|
export interface ActionRendererProps {
|
|
118
118
|
actionId: string;
|
|
119
119
|
actionText: string;
|
|
120
|
+
actionData?: any;
|
|
120
121
|
onClick: () => void;
|
|
121
122
|
className?: string;
|
|
122
123
|
style?: React.CSSProperties;
|
|
@@ -146,6 +147,7 @@ export interface DataControlProps {
|
|
|
146
147
|
export type CreateDataProps = (controlProps: DataControlProps) => DataRendererProps;
|
|
147
148
|
export interface ControlRenderOptions extends FormContextOptions {
|
|
148
149
|
useDataHook?: (c: ControlDefinition) => CreateDataProps;
|
|
150
|
+
actionOnClick?: (actionId: string, actionData: any) => () => void;
|
|
149
151
|
useEvalExpressionHook?: UseEvalExpressionHook;
|
|
150
152
|
clearHidden?: boolean;
|
|
151
153
|
schemaInterface?: SchemaInterface;
|
|
@@ -184,7 +186,9 @@ export interface RenderControlProps {
|
|
|
184
186
|
displayControl?: Control<string | undefined>;
|
|
185
187
|
style?: React.CSSProperties;
|
|
186
188
|
allowedOptions?: Control<any[] | undefined>;
|
|
189
|
+
actionDataControl?: Control<any | undefined | null>;
|
|
187
190
|
useChildVisibility: ChildVisibilityFunc;
|
|
191
|
+
actionOnClick?: (actionId: string, actionData: any) => () => void;
|
|
188
192
|
}
|
|
189
193
|
export declare function renderControlLayout(props: RenderControlProps): ControlLayoutProps;
|
|
190
194
|
export declare function appendMarkup(k: keyof Omit<RenderedLayout, "errorControl" | "style" | "className">, markup: ReactNode): (layout: RenderedLayout) => void;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export declare function useEvalDynamicHook(definition: ControlDefinition, type:
|
|
|
18
18
|
export declare function matchesType(context: ControlDataContext, types?: string[] | null): boolean | undefined;
|
|
19
19
|
export declare function hideDisplayOnly(context: ControlDataContext, field: SchemaField, definition: ControlDefinition, schemaInterface: SchemaInterface): boolean | undefined;
|
|
20
20
|
export declare function useJsonataExpression(jExpr: string, dataContext: DataContext, bindings?: () => Record<string, any>): Control<any>;
|
|
21
|
+
export declare function useEvalActionHook(useExpr: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<string | null>;
|
|
21
22
|
export declare function useEvalLabelText(useExpr: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<string | null>;
|
package/lib/index.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.DynamicPropertyType = void 0;
|
|
|
41
41
|
DynamicPropertyType["LayoutStyle"] = "LayoutStyle";
|
|
42
42
|
DynamicPropertyType["AllowedOptions"] = "AllowedOptions";
|
|
43
43
|
DynamicPropertyType["Label"] = "Label";
|
|
44
|
+
DynamicPropertyType["ActionData"] = "ActionData";
|
|
44
45
|
})(exports.DynamicPropertyType || (exports.DynamicPropertyType = {}));
|
|
45
46
|
exports.ExpressionType = void 0;
|
|
46
47
|
(function (ExpressionType) {
|
|
@@ -1107,6 +1108,12 @@ function useJsonataExpression(jExpr, dataContext, bindings) {
|
|
|
1107
1108
|
}, [compiledExpr]);
|
|
1108
1109
|
return control;
|
|
1109
1110
|
}
|
|
1111
|
+
function useEvalActionHook(useExpr, definition) {
|
|
1112
|
+
var dynamicValue = useEvalDynamicHook(definition, exports.DynamicPropertyType.ActionData, useExpr);
|
|
1113
|
+
return makeDynamicPropertyHook(dynamicValue, function () {
|
|
1114
|
+
return core.useControl(null);
|
|
1115
|
+
}, undefined);
|
|
1116
|
+
}
|
|
1110
1117
|
function useEvalLabelText(useExpr, definition) {
|
|
1111
1118
|
var dynamicValue = useEvalDynamicHook(definition, exports.DynamicPropertyType.Label, useExpr);
|
|
1112
1119
|
return makeDynamicPropertyHook(dynamicValue, function () {
|
|
@@ -1276,6 +1283,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1276
1283
|
disabledControl: useEvalDisabledHook(useExpr, definition),
|
|
1277
1284
|
allowedOptions: useEvalAllowedOptionsHook(useExpr, definition),
|
|
1278
1285
|
labelText: useEvalLabelText(useExpr, definition),
|
|
1286
|
+
actionData: useEvalActionHook(useExpr, definition),
|
|
1279
1287
|
customStyle: useEvalStyleHook(useExpr, exports.DynamicPropertyType.Style, definition),
|
|
1280
1288
|
layoutStyle: useEvalStyleHook(useExpr, exports.DynamicPropertyType.LayoutStyle, definition),
|
|
1281
1289
|
displayControl: useEvalDisplayHook(useExpr, definition)
|
|
@@ -1316,7 +1324,8 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1316
1324
|
labelText = _dynamicHooks.labelText,
|
|
1317
1325
|
customStyle = _dynamicHooks.customStyle,
|
|
1318
1326
|
allowedOptions = _dynamicHooks.allowedOptions,
|
|
1319
|
-
defaultValueControl = _dynamicHooks.defaultValueControl
|
|
1327
|
+
defaultValueControl = _dynamicHooks.defaultValueControl,
|
|
1328
|
+
actionData = _dynamicHooks.actionData;
|
|
1320
1329
|
var visible = visibleControl.current.value;
|
|
1321
1330
|
var visibility = core.useControl(function () {
|
|
1322
1331
|
return visible != null ? {
|
|
@@ -1410,6 +1419,8 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1410
1419
|
displayControl: displayControl,
|
|
1411
1420
|
style: customStyle.value,
|
|
1412
1421
|
allowedOptions: allowedOptions,
|
|
1422
|
+
actionDataControl: actionData,
|
|
1423
|
+
actionOnClick: _options.actionOnClick,
|
|
1413
1424
|
useChildVisibility: function useChildVisibility(childDef, context) {
|
|
1414
1425
|
var schemaField = lookupSchemaField(childDef, (context != null ? context : controlDataContext).fields);
|
|
1415
1426
|
return useEvalVisibilityHook(useExpr, childDef, schemaField);
|
|
@@ -1593,12 +1604,14 @@ function renderControlLayout(props) {
|
|
|
1593
1604
|
};
|
|
1594
1605
|
}
|
|
1595
1606
|
if (isActionControlsDefinition(c)) {
|
|
1596
|
-
var _ref5, _labelText$value2;
|
|
1607
|
+
var _props$actionDataCont, _props$actionDataCont2, _ref5, _labelText$value2, _props$actionOnClick;
|
|
1608
|
+
var actionData = (_props$actionDataCont = (_props$actionDataCont2 = props.actionDataControl) == null ? void 0 : _props$actionDataCont2.value) != null ? _props$actionDataCont : c.actionData;
|
|
1597
1609
|
return {
|
|
1598
1610
|
children: renderer.renderAction({
|
|
1599
1611
|
actionText: (_ref5 = (_labelText$value2 = labelText == null ? void 0 : labelText.value) != null ? _labelText$value2 : c.title) != null ? _ref5 : c.actionId,
|
|
1600
1612
|
actionId: c.actionId,
|
|
1601
|
-
|
|
1613
|
+
actionData: actionData,
|
|
1614
|
+
onClick: (_props$actionOnClick = props.actionOnClick == null ? void 0 : props.actionOnClick(c.actionId, actionData)) != null ? _props$actionOnClick : function () {},
|
|
1602
1615
|
className: cc(c.styleClass),
|
|
1603
1616
|
style: style
|
|
1604
1617
|
})
|
|
@@ -2555,7 +2568,7 @@ function createFormRenderer(customRenderers, defaultRenderers) {
|
|
|
2555
2568
|
var options = hasOptions(props);
|
|
2556
2569
|
var renderer = (_dataRegistrations$fi = dataRegistrations.find(function (x) {
|
|
2557
2570
|
var _x$collection, _field$collection, _x$options;
|
|
2558
|
-
return ((_x$collection = x.collection) != null ? _x$collection : false) === (props.elementIndex == null && ((_field$collection = field.collection) != null ? _field$collection : false)) && ((_x$options = x.options) != null ? _x$options : false) === options && (x.schemaType && isOneOf(x.schemaType, field.type) || x.renderType && isOneOf(x.renderType, renderType) || x.match && x.match(props));
|
|
2571
|
+
return ((_x$collection = x.collection) != null ? _x$collection : false) === (props.elementIndex == null && ((_field$collection = field.collection) != null ? _field$collection : false)) && ((_x$options = x.options) != null ? _x$options : false) === options && (x.schemaType && renderType == exports.DataRenderType.Standard && isOneOf(x.schemaType, field.type) || x.renderType && isOneOf(x.renderType, renderType) || x.match && x.match(props));
|
|
2559
2572
|
})) != null ? _dataRegistrations$fi : defaultRenderers.data;
|
|
2560
2573
|
var result = renderer.render(props, formRenderers);
|
|
2561
2574
|
if (typeof result === "function") return result;
|
|
@@ -2781,6 +2794,7 @@ exports.toDepString = toDepString;
|
|
|
2781
2794
|
exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
|
|
2782
2795
|
exports.useControlRenderer = useControlRenderer;
|
|
2783
2796
|
exports.useDynamicHooks = useDynamicHooks;
|
|
2797
|
+
exports.useEvalActionHook = useEvalActionHook;
|
|
2784
2798
|
exports.useEvalAllowedOptionsHook = useEvalAllowedOptionsHook;
|
|
2785
2799
|
exports.useEvalDefaultValueHook = useEvalDefaultValueHook;
|
|
2786
2800
|
exports.useEvalDisabledHook = useEvalDisabledHook;
|