@react-typed-forms/schemas 11.5.4 → 11.6.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/components/DefaultAccordion.d.ts +15 -0
- package/lib/controlRender.d.ts +12 -4
- package/lib/createDefaultRenderers.d.ts +8 -0
- package/lib/index.js +91 -14
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +2 -1
- package/lib/tailwind.d.ts +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { CSSProperties, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { AccordionAdornment } from "../types";
|
|
3
|
+
import { Control } from "@react-typed-forms/core";
|
|
4
|
+
export declare function DefaultAccordion({ children, accordion, contentStyle, contentClassName, designMode, togglerOpenClass, togglerClosedClass, className, renderTitle, renderToggler, }: {
|
|
5
|
+
children: ReactElement;
|
|
6
|
+
accordion: Partial<AccordionAdornment>;
|
|
7
|
+
contentStyle?: CSSProperties;
|
|
8
|
+
contentClassName?: string;
|
|
9
|
+
designMode?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
togglerOpenClass?: string;
|
|
12
|
+
togglerClosedClass?: string;
|
|
13
|
+
renderTitle?: (title: string | undefined, current: Control<boolean>) => ReactNode;
|
|
14
|
+
renderToggler?: (current: Control<boolean>) => ReactNode;
|
|
15
|
+
}): React.JSX.Element;
|
package/lib/controlRender.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties, FC, Key, ReactNode } from "react";
|
|
1
|
+
import React, { CSSProperties, FC, Key, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { Control } from "@react-typed-forms/core";
|
|
3
3
|
import { AdornmentPlacement, ControlAdornment, ControlDefinition, DataControlDefinition, DisplayData, FieldOption, GroupRenderOptions, RenderOptions, SchemaField, SchemaInterface } from "./types";
|
|
4
4
|
import { ControlDataContext, JsonPath } from "./util";
|
|
@@ -16,6 +16,7 @@ export interface FormRenderer {
|
|
|
16
16
|
}
|
|
17
17
|
export interface AdornmentProps {
|
|
18
18
|
adornment: ControlAdornment;
|
|
19
|
+
designMode?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare const AppendAdornmentPriority = 0;
|
|
21
22
|
export declare const WrapAdornmentPriority = 1000;
|
|
@@ -49,6 +50,7 @@ export interface RenderedLayout {
|
|
|
49
50
|
errorControl?: Control<any>;
|
|
50
51
|
className?: string;
|
|
51
52
|
style?: React.CSSProperties;
|
|
53
|
+
wrapLayout: (layout: ReactElement) => ReactElement;
|
|
52
54
|
}
|
|
53
55
|
export interface RenderedControl {
|
|
54
56
|
children: ReactNode;
|
|
@@ -96,6 +98,7 @@ export interface ParentRendererProps {
|
|
|
96
98
|
dataContext: ControlDataContext;
|
|
97
99
|
parentContext: ControlDataContext;
|
|
98
100
|
useChildVisibility: ChildVisibilityFunc;
|
|
101
|
+
designMode?: boolean;
|
|
99
102
|
}
|
|
100
103
|
export interface GroupRendererProps extends ParentRendererProps {
|
|
101
104
|
definition: ControlDefinition;
|
|
@@ -144,6 +147,7 @@ export interface DataControlProps {
|
|
|
144
147
|
allowedOptions?: Control<any[] | undefined>;
|
|
145
148
|
useChildVisibility: ChildVisibilityFunc;
|
|
146
149
|
schemaInterface?: SchemaInterface;
|
|
150
|
+
designMode?: boolean;
|
|
147
151
|
}
|
|
148
152
|
export type CreateDataProps = (controlProps: DataControlProps) => DataRendererProps;
|
|
149
153
|
export interface ControlRenderOptions extends FormContextOptions {
|
|
@@ -191,11 +195,14 @@ export interface RenderControlProps {
|
|
|
191
195
|
useChildVisibility: ChildVisibilityFunc;
|
|
192
196
|
actionOnClick?: (actionId: string, actionData: any) => () => void;
|
|
193
197
|
schemaInterface?: SchemaInterface;
|
|
198
|
+
designMode?: boolean;
|
|
194
199
|
}
|
|
195
200
|
export declare function renderControlLayout(props: RenderControlProps): ControlLayoutProps;
|
|
196
|
-
|
|
197
|
-
export declare function
|
|
198
|
-
export declare function
|
|
201
|
+
type MarkupKeys = keyof Omit<RenderedLayout, "errorControl" | "style" | "className" | "wrapLayout">;
|
|
202
|
+
export declare function appendMarkup(k: MarkupKeys, markup: ReactNode): (layout: RenderedLayout) => void;
|
|
203
|
+
export declare function wrapMarkup(k: MarkupKeys, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
|
|
204
|
+
export declare function layoutKeyForPlacement(pos: AdornmentPlacement): MarkupKeys;
|
|
205
|
+
export declare function wrapLayout(wrap: (layout: ReactElement) => ReactElement): (renderedLayout: RenderedLayout) => void;
|
|
199
206
|
export declare function appendMarkupAt(pos: AdornmentPlacement, markup: ReactNode): (layout: RenderedLayout) => void;
|
|
200
207
|
export declare function wrapMarkupAt(pos: AdornmentPlacement, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
|
|
201
208
|
export declare function renderLayoutParts(props: ControlLayoutProps, renderer: FormRenderer): RenderedLayout;
|
|
@@ -204,3 +211,4 @@ export declare function applyArrayLengthRestrictions({ arrayControl, min, max, a
|
|
|
204
211
|
addDisabled: boolean;
|
|
205
212
|
removeDisabled: boolean;
|
|
206
213
|
};
|
|
214
|
+
export {};
|
|
@@ -4,6 +4,7 @@ import { ActionRendererRegistration, AdornmentRendererRegistration, DataRenderer
|
|
|
4
4
|
import { CSSProperties, ReactElement, ReactNode } from "react";
|
|
5
5
|
import { FieldOption, GridRenderer } from "./types";
|
|
6
6
|
import { SelectRendererOptions } from "./components/SelectDataRenderer";
|
|
7
|
+
import { Control } from "@react-typed-forms/core";
|
|
7
8
|
import { DefaultArrayRendererOptions } from "./components/DefaultArrayRenderer";
|
|
8
9
|
import { CheckRendererOptions } from "./components/CheckRenderer";
|
|
9
10
|
export interface DefaultRendererOptions {
|
|
@@ -49,6 +50,13 @@ interface DefaultDataRendererOptions {
|
|
|
49
50
|
}
|
|
50
51
|
export declare function createDefaultDataRenderer(options?: DefaultDataRendererOptions): DataRendererRegistration;
|
|
51
52
|
export interface DefaultAdornmentRendererOptions {
|
|
53
|
+
accordion?: {
|
|
54
|
+
className?: string;
|
|
55
|
+
togglerOpenClass?: string;
|
|
56
|
+
togglerClosedClass?: string;
|
|
57
|
+
renderTitle?: (title: string | undefined, current: Control<boolean>) => ReactNode;
|
|
58
|
+
renderToggler?: (current: Control<boolean>) => ReactNode;
|
|
59
|
+
};
|
|
52
60
|
}
|
|
53
61
|
export declare function createDefaultAdornmentRenderer(options?: DefaultAdornmentRendererOptions): AdornmentRendererRegistration;
|
|
54
62
|
interface DefaultLabelRendererOptions {
|
package/lib/index.js
CHANGED
|
@@ -1241,13 +1241,9 @@ function useValidationHook(definition, field) {
|
|
|
1241
1241
|
}
|
|
1242
1242
|
function useJsonataValidator(control, context, expr, hidden, i) {
|
|
1243
1243
|
var errorMsg = useJsonataExpression(expr.expression, context);
|
|
1244
|
-
core.
|
|
1245
|
-
return
|
|
1246
|
-
},
|
|
1247
|
-
var hidden = _ref2[0],
|
|
1248
|
-
msg = _ref2[1];
|
|
1249
|
-
return control.setError("jsonata" + i, !hidden ? msg : null);
|
|
1250
|
-
}, true);
|
|
1244
|
+
core.useValidator(control, function () {
|
|
1245
|
+
return !hidden ? errorMsg.value : null;
|
|
1246
|
+
}, "jsonata" + i);
|
|
1251
1247
|
}
|
|
1252
1248
|
function useDateValidator(control, dv, i) {
|
|
1253
1249
|
var comparisonDate;
|
|
@@ -1664,7 +1660,8 @@ function renderControlLayout(props) {
|
|
|
1664
1660
|
style = props.style,
|
|
1665
1661
|
labelText = props.labelText,
|
|
1666
1662
|
parentContext = props.parentContext,
|
|
1667
|
-
useChildVisibility = props.useChildVisibility
|
|
1663
|
+
useChildVisibility = props.useChildVisibility,
|
|
1664
|
+
designMode = props.designMode;
|
|
1668
1665
|
if (isDataControlDefinition(c)) {
|
|
1669
1666
|
return renderData(c);
|
|
1670
1667
|
}
|
|
@@ -1689,7 +1686,8 @@ function renderControlLayout(props) {
|
|
|
1689
1686
|
},
|
|
1690
1687
|
className: cc(c.styleClass),
|
|
1691
1688
|
useChildVisibility: useChildVisibility,
|
|
1692
|
-
style: style
|
|
1689
|
+
style: style,
|
|
1690
|
+
designMode: designMode
|
|
1693
1691
|
}),
|
|
1694
1692
|
label: {
|
|
1695
1693
|
label: (_labelText$value = labelText == null ? void 0 : labelText.value) != null ? _labelText$value : c.title,
|
|
@@ -1772,6 +1770,14 @@ function layoutKeyForPlacement(pos) {
|
|
|
1772
1770
|
return "labelEnd";
|
|
1773
1771
|
}
|
|
1774
1772
|
}
|
|
1773
|
+
function wrapLayout(wrap) {
|
|
1774
|
+
return function (rl) {
|
|
1775
|
+
var orig = rl.wrapLayout;
|
|
1776
|
+
rl.wrapLayout = function (x) {
|
|
1777
|
+
return wrap(orig(x));
|
|
1778
|
+
};
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1775
1781
|
function appendMarkupAt(pos, markup) {
|
|
1776
1782
|
return appendMarkup(layoutKeyForPlacement(pos), markup);
|
|
1777
1783
|
}
|
|
@@ -1791,7 +1797,10 @@ function renderLayoutParts(props, renderer) {
|
|
|
1791
1797
|
children: children,
|
|
1792
1798
|
errorControl: errorControl,
|
|
1793
1799
|
style: style,
|
|
1794
|
-
className: cc(className)
|
|
1800
|
+
className: cc(className),
|
|
1801
|
+
wrapLayout: function wrapLayout(x) {
|
|
1802
|
+
return x;
|
|
1803
|
+
}
|
|
1795
1804
|
};
|
|
1796
1805
|
(adornments != null ? adornments : []).sort(function (a, b) {
|
|
1797
1806
|
return a.priority - b.priority;
|
|
@@ -1826,6 +1835,9 @@ function applyArrayLengthRestrictions(_ref7, disable) {
|
|
|
1826
1835
|
function isIconAdornment(a) {
|
|
1827
1836
|
return a.type === exports.ControlAdornmentType.Icon;
|
|
1828
1837
|
}
|
|
1838
|
+
function isAccordionAdornment(a) {
|
|
1839
|
+
return a.type === exports.ControlAdornmentType.Accordion;
|
|
1840
|
+
}
|
|
1829
1841
|
function createLayoutRenderer(render, options) {
|
|
1830
1842
|
return _extends({
|
|
1831
1843
|
type: "layout",
|
|
@@ -1916,6 +1928,13 @@ var defaultTailwindTheme = {
|
|
|
1916
1928
|
selectOptions: {
|
|
1917
1929
|
emptyText: "<select>"
|
|
1918
1930
|
}
|
|
1931
|
+
},
|
|
1932
|
+
adornment: {
|
|
1933
|
+
accordion: {
|
|
1934
|
+
className: "flex items-center gap-2 my-2",
|
|
1935
|
+
togglerOpenClass: "fa fa-chevron-up",
|
|
1936
|
+
togglerClosedClass: "fa fa-chevron-down"
|
|
1937
|
+
}
|
|
1919
1938
|
}
|
|
1920
1939
|
};
|
|
1921
1940
|
|
|
@@ -2393,6 +2412,47 @@ function createCheckboxRenderer(options) {
|
|
|
2393
2412
|
});
|
|
2394
2413
|
}
|
|
2395
2414
|
|
|
2415
|
+
function DefaultAccordion(_ref) {
|
|
2416
|
+
var _effect = core.useComponentTracking();
|
|
2417
|
+
try {
|
|
2418
|
+
var children = _ref.children,
|
|
2419
|
+
accordion = _ref.accordion,
|
|
2420
|
+
contentStyle = _ref.contentStyle,
|
|
2421
|
+
contentClassName = _ref.contentClassName,
|
|
2422
|
+
designMode = _ref.designMode,
|
|
2423
|
+
togglerOpenClass = _ref.togglerOpenClass,
|
|
2424
|
+
togglerClosedClass = _ref.togglerClosedClass,
|
|
2425
|
+
className = _ref.className,
|
|
2426
|
+
_ref$renderTitle = _ref.renderTitle,
|
|
2427
|
+
renderTitle = _ref$renderTitle === void 0 ? function (x) {
|
|
2428
|
+
return /*#__PURE__*/React__default["default"].createElement("span", null, x);
|
|
2429
|
+
} : _ref$renderTitle,
|
|
2430
|
+
renderToggler = _ref.renderToggler;
|
|
2431
|
+
var open = core.useControl(!!accordion.defaultExpanded);
|
|
2432
|
+
var isOpen = open.value;
|
|
2433
|
+
var fullContentStyle = isOpen || designMode ? contentStyle : _extends({}, contentStyle, {
|
|
2434
|
+
display: "none"
|
|
2435
|
+
});
|
|
2436
|
+
var toggler = renderToggler ? renderToggler(open) : /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2437
|
+
onClick: function onClick() {
|
|
2438
|
+
return open.setValue(function (x) {
|
|
2439
|
+
return !x;
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
}, /*#__PURE__*/React__default["default"].createElement("i", {
|
|
2443
|
+
className: clsx__default["default"](isOpen ? togglerOpenClass : togglerClosedClass)
|
|
2444
|
+
}));
|
|
2445
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2446
|
+
className: className
|
|
2447
|
+
}, renderTitle(accordion.title, open), toggler), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2448
|
+
style: fullContentStyle,
|
|
2449
|
+
className: contentClassName
|
|
2450
|
+
}, children));
|
|
2451
|
+
} finally {
|
|
2452
|
+
_effect();
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2396
2456
|
function createButtonActionRenderer(actionId, options) {
|
|
2397
2457
|
if (options === void 0) {
|
|
2398
2458
|
options = {};
|
|
@@ -2560,10 +2620,14 @@ function createDefaultDataRenderer(options) {
|
|
|
2560
2620
|
});
|
|
2561
2621
|
}
|
|
2562
2622
|
function createDefaultAdornmentRenderer(options) {
|
|
2623
|
+
if (options === void 0) {
|
|
2624
|
+
options = {};
|
|
2625
|
+
}
|
|
2563
2626
|
return {
|
|
2564
2627
|
type: "adornment",
|
|
2565
2628
|
render: function render(_ref6) {
|
|
2566
|
-
var adornment = _ref6.adornment
|
|
2629
|
+
var adornment = _ref6.adornment,
|
|
2630
|
+
designMode = _ref6.designMode;
|
|
2567
2631
|
return {
|
|
2568
2632
|
apply: function apply(rl) {
|
|
2569
2633
|
if (isIconAdornment(adornment)) {
|
|
@@ -2572,6 +2636,17 @@ function createDefaultAdornmentRenderer(options) {
|
|
|
2572
2636
|
className: adornment.iconClass
|
|
2573
2637
|
}))(rl);
|
|
2574
2638
|
}
|
|
2639
|
+
if (isAccordionAdornment(adornment)) {
|
|
2640
|
+
return wrapLayout(function (x) {
|
|
2641
|
+
return /*#__PURE__*/React__default["default"].createElement(DefaultAccordion, _extends({
|
|
2642
|
+
children: x,
|
|
2643
|
+
accordion: adornment,
|
|
2644
|
+
contentStyle: rl.style,
|
|
2645
|
+
contentClassName: rl.className,
|
|
2646
|
+
designMode: designMode
|
|
2647
|
+
}, options.accordion));
|
|
2648
|
+
})(rl);
|
|
2649
|
+
}
|
|
2575
2650
|
},
|
|
2576
2651
|
priority: 0,
|
|
2577
2652
|
adornment: adornment
|
|
@@ -2588,9 +2663,9 @@ function createDefaultLayoutRenderer(options) {
|
|
|
2588
2663
|
className: rendererClass(props.className, options.className)
|
|
2589
2664
|
}), renderers);
|
|
2590
2665
|
return {
|
|
2591
|
-
children: /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2666
|
+
children: layout.wrapLayout( /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2592
2667
|
layout: layout
|
|
2593
|
-
}, options)),
|
|
2668
|
+
}, options))),
|
|
2594
2669
|
className: layout.className,
|
|
2595
2670
|
style: layout.style,
|
|
2596
2671
|
divRef: function divRef(e) {
|
|
@@ -2632,7 +2707,7 @@ function createDefaultRenderers(options) {
|
|
|
2632
2707
|
array: createDefaultArrayRenderer(options.array),
|
|
2633
2708
|
group: createDefaultGroupRenderer(options.group),
|
|
2634
2709
|
label: createDefaultLabelRenderer(options.label),
|
|
2635
|
-
adornment: createDefaultAdornmentRenderer(),
|
|
2710
|
+
adornment: createDefaultAdornmentRenderer(options.adornment),
|
|
2636
2711
|
renderLayout: createDefaultLayoutRenderer(options.layout),
|
|
2637
2712
|
visibility: createDefaultVisibilityRenderer()
|
|
2638
2713
|
};
|
|
@@ -2889,6 +2964,7 @@ exports.hasOptions = hasOptions;
|
|
|
2889
2964
|
exports.hideDisplayOnly = hideDisplayOnly;
|
|
2890
2965
|
exports.htmlDisplayControl = htmlDisplayControl;
|
|
2891
2966
|
exports.intField = intField;
|
|
2967
|
+
exports.isAccordionAdornment = isAccordionAdornment;
|
|
2892
2968
|
exports.isActionControlsDefinition = isActionControlsDefinition;
|
|
2893
2969
|
exports.isCompoundField = isCompoundField;
|
|
2894
2970
|
exports.isControlDisabled = isControlDisabled;
|
|
@@ -2950,6 +3026,7 @@ exports.visitControlDataArray = visitControlDataArray;
|
|
|
2950
3026
|
exports.visitControlDefinition = visitControlDefinition;
|
|
2951
3027
|
exports.watchControlLookup = watchControlLookup;
|
|
2952
3028
|
exports.withScalarOptions = withScalarOptions;
|
|
3029
|
+
exports.wrapLayout = wrapLayout;
|
|
2953
3030
|
exports.wrapMarkup = wrapMarkup;
|
|
2954
3031
|
exports.wrapMarkupAt = wrapMarkupAt;
|
|
2955
3032
|
//# sourceMappingURL=index.js.map
|