@react-typed-forms/schemas 11.5.5 → 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 +88 -7
- 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
|
@@ -1660,7 +1660,8 @@ function renderControlLayout(props) {
|
|
|
1660
1660
|
style = props.style,
|
|
1661
1661
|
labelText = props.labelText,
|
|
1662
1662
|
parentContext = props.parentContext,
|
|
1663
|
-
useChildVisibility = props.useChildVisibility
|
|
1663
|
+
useChildVisibility = props.useChildVisibility,
|
|
1664
|
+
designMode = props.designMode;
|
|
1664
1665
|
if (isDataControlDefinition(c)) {
|
|
1665
1666
|
return renderData(c);
|
|
1666
1667
|
}
|
|
@@ -1685,7 +1686,8 @@ function renderControlLayout(props) {
|
|
|
1685
1686
|
},
|
|
1686
1687
|
className: cc(c.styleClass),
|
|
1687
1688
|
useChildVisibility: useChildVisibility,
|
|
1688
|
-
style: style
|
|
1689
|
+
style: style,
|
|
1690
|
+
designMode: designMode
|
|
1689
1691
|
}),
|
|
1690
1692
|
label: {
|
|
1691
1693
|
label: (_labelText$value = labelText == null ? void 0 : labelText.value) != null ? _labelText$value : c.title,
|
|
@@ -1768,6 +1770,14 @@ function layoutKeyForPlacement(pos) {
|
|
|
1768
1770
|
return "labelEnd";
|
|
1769
1771
|
}
|
|
1770
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
|
+
}
|
|
1771
1781
|
function appendMarkupAt(pos, markup) {
|
|
1772
1782
|
return appendMarkup(layoutKeyForPlacement(pos), markup);
|
|
1773
1783
|
}
|
|
@@ -1787,7 +1797,10 @@ function renderLayoutParts(props, renderer) {
|
|
|
1787
1797
|
children: children,
|
|
1788
1798
|
errorControl: errorControl,
|
|
1789
1799
|
style: style,
|
|
1790
|
-
className: cc(className)
|
|
1800
|
+
className: cc(className),
|
|
1801
|
+
wrapLayout: function wrapLayout(x) {
|
|
1802
|
+
return x;
|
|
1803
|
+
}
|
|
1791
1804
|
};
|
|
1792
1805
|
(adornments != null ? adornments : []).sort(function (a, b) {
|
|
1793
1806
|
return a.priority - b.priority;
|
|
@@ -1822,6 +1835,9 @@ function applyArrayLengthRestrictions(_ref7, disable) {
|
|
|
1822
1835
|
function isIconAdornment(a) {
|
|
1823
1836
|
return a.type === exports.ControlAdornmentType.Icon;
|
|
1824
1837
|
}
|
|
1838
|
+
function isAccordionAdornment(a) {
|
|
1839
|
+
return a.type === exports.ControlAdornmentType.Accordion;
|
|
1840
|
+
}
|
|
1825
1841
|
function createLayoutRenderer(render, options) {
|
|
1826
1842
|
return _extends({
|
|
1827
1843
|
type: "layout",
|
|
@@ -1912,6 +1928,13 @@ var defaultTailwindTheme = {
|
|
|
1912
1928
|
selectOptions: {
|
|
1913
1929
|
emptyText: "<select>"
|
|
1914
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
|
+
}
|
|
1915
1938
|
}
|
|
1916
1939
|
};
|
|
1917
1940
|
|
|
@@ -2389,6 +2412,47 @@ function createCheckboxRenderer(options) {
|
|
|
2389
2412
|
});
|
|
2390
2413
|
}
|
|
2391
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
|
+
|
|
2392
2456
|
function createButtonActionRenderer(actionId, options) {
|
|
2393
2457
|
if (options === void 0) {
|
|
2394
2458
|
options = {};
|
|
@@ -2556,10 +2620,14 @@ function createDefaultDataRenderer(options) {
|
|
|
2556
2620
|
});
|
|
2557
2621
|
}
|
|
2558
2622
|
function createDefaultAdornmentRenderer(options) {
|
|
2623
|
+
if (options === void 0) {
|
|
2624
|
+
options = {};
|
|
2625
|
+
}
|
|
2559
2626
|
return {
|
|
2560
2627
|
type: "adornment",
|
|
2561
2628
|
render: function render(_ref6) {
|
|
2562
|
-
var adornment = _ref6.adornment
|
|
2629
|
+
var adornment = _ref6.adornment,
|
|
2630
|
+
designMode = _ref6.designMode;
|
|
2563
2631
|
return {
|
|
2564
2632
|
apply: function apply(rl) {
|
|
2565
2633
|
if (isIconAdornment(adornment)) {
|
|
@@ -2568,6 +2636,17 @@ function createDefaultAdornmentRenderer(options) {
|
|
|
2568
2636
|
className: adornment.iconClass
|
|
2569
2637
|
}))(rl);
|
|
2570
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
|
+
}
|
|
2571
2650
|
},
|
|
2572
2651
|
priority: 0,
|
|
2573
2652
|
adornment: adornment
|
|
@@ -2584,9 +2663,9 @@ function createDefaultLayoutRenderer(options) {
|
|
|
2584
2663
|
className: rendererClass(props.className, options.className)
|
|
2585
2664
|
}), renderers);
|
|
2586
2665
|
return {
|
|
2587
|
-
children: /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2666
|
+
children: layout.wrapLayout( /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2588
2667
|
layout: layout
|
|
2589
|
-
}, options)),
|
|
2668
|
+
}, options))),
|
|
2590
2669
|
className: layout.className,
|
|
2591
2670
|
style: layout.style,
|
|
2592
2671
|
divRef: function divRef(e) {
|
|
@@ -2628,7 +2707,7 @@ function createDefaultRenderers(options) {
|
|
|
2628
2707
|
array: createDefaultArrayRenderer(options.array),
|
|
2629
2708
|
group: createDefaultGroupRenderer(options.group),
|
|
2630
2709
|
label: createDefaultLabelRenderer(options.label),
|
|
2631
|
-
adornment: createDefaultAdornmentRenderer(),
|
|
2710
|
+
adornment: createDefaultAdornmentRenderer(options.adornment),
|
|
2632
2711
|
renderLayout: createDefaultLayoutRenderer(options.layout),
|
|
2633
2712
|
visibility: createDefaultVisibilityRenderer()
|
|
2634
2713
|
};
|
|
@@ -2885,6 +2964,7 @@ exports.hasOptions = hasOptions;
|
|
|
2885
2964
|
exports.hideDisplayOnly = hideDisplayOnly;
|
|
2886
2965
|
exports.htmlDisplayControl = htmlDisplayControl;
|
|
2887
2966
|
exports.intField = intField;
|
|
2967
|
+
exports.isAccordionAdornment = isAccordionAdornment;
|
|
2888
2968
|
exports.isActionControlsDefinition = isActionControlsDefinition;
|
|
2889
2969
|
exports.isCompoundField = isCompoundField;
|
|
2890
2970
|
exports.isControlDisabled = isControlDisabled;
|
|
@@ -2946,6 +3026,7 @@ exports.visitControlDataArray = visitControlDataArray;
|
|
|
2946
3026
|
exports.visitControlDefinition = visitControlDefinition;
|
|
2947
3027
|
exports.watchControlLookup = watchControlLookup;
|
|
2948
3028
|
exports.withScalarOptions = withScalarOptions;
|
|
3029
|
+
exports.wrapLayout = wrapLayout;
|
|
2949
3030
|
exports.wrapMarkup = wrapMarkup;
|
|
2950
3031
|
exports.wrapMarkupAt = wrapMarkupAt;
|
|
2951
3032
|
//# sourceMappingURL=index.js.map
|