@react-typed-forms/schemas 11.5.5 → 11.6.1
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 +97 -8
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +2 -1
- package/lib/schemaInterface.d.ts +2 -0
- 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
|
@@ -1273,7 +1273,13 @@ function cc(n) {
|
|
|
1273
1273
|
}
|
|
1274
1274
|
|
|
1275
1275
|
var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
1276
|
-
function DefaultSchemaInterface() {
|
|
1276
|
+
function DefaultSchemaInterface(boolStrings) {
|
|
1277
|
+
if (boolStrings === void 0) {
|
|
1278
|
+
boolStrings = ["No", "Yes"];
|
|
1279
|
+
}
|
|
1280
|
+
this.boolStrings = void 0;
|
|
1281
|
+
this.boolStrings = boolStrings;
|
|
1282
|
+
}
|
|
1277
1283
|
var _proto = DefaultSchemaInterface.prototype;
|
|
1278
1284
|
_proto.getOptions = function getOptions(_ref) {
|
|
1279
1285
|
var options = _ref.options;
|
|
@@ -1294,6 +1300,8 @@ var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
|
1294
1300
|
return new Date(value).toLocaleDateString();
|
|
1295
1301
|
case exports.FieldType.Date:
|
|
1296
1302
|
return new Date(value).toLocaleDateString();
|
|
1303
|
+
case exports.FieldType.Bool:
|
|
1304
|
+
return this.boolStrings[value ? 1 : 0];
|
|
1297
1305
|
default:
|
|
1298
1306
|
return value != null ? value.toString() : undefined;
|
|
1299
1307
|
}
|
|
@@ -1660,7 +1668,8 @@ function renderControlLayout(props) {
|
|
|
1660
1668
|
style = props.style,
|
|
1661
1669
|
labelText = props.labelText,
|
|
1662
1670
|
parentContext = props.parentContext,
|
|
1663
|
-
useChildVisibility = props.useChildVisibility
|
|
1671
|
+
useChildVisibility = props.useChildVisibility,
|
|
1672
|
+
designMode = props.designMode;
|
|
1664
1673
|
if (isDataControlDefinition(c)) {
|
|
1665
1674
|
return renderData(c);
|
|
1666
1675
|
}
|
|
@@ -1685,7 +1694,8 @@ function renderControlLayout(props) {
|
|
|
1685
1694
|
},
|
|
1686
1695
|
className: cc(c.styleClass),
|
|
1687
1696
|
useChildVisibility: useChildVisibility,
|
|
1688
|
-
style: style
|
|
1697
|
+
style: style,
|
|
1698
|
+
designMode: designMode
|
|
1689
1699
|
}),
|
|
1690
1700
|
label: {
|
|
1691
1701
|
label: (_labelText$value = labelText == null ? void 0 : labelText.value) != null ? _labelText$value : c.title,
|
|
@@ -1768,6 +1778,14 @@ function layoutKeyForPlacement(pos) {
|
|
|
1768
1778
|
return "labelEnd";
|
|
1769
1779
|
}
|
|
1770
1780
|
}
|
|
1781
|
+
function wrapLayout(wrap) {
|
|
1782
|
+
return function (rl) {
|
|
1783
|
+
var orig = rl.wrapLayout;
|
|
1784
|
+
rl.wrapLayout = function (x) {
|
|
1785
|
+
return wrap(orig(x));
|
|
1786
|
+
};
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1771
1789
|
function appendMarkupAt(pos, markup) {
|
|
1772
1790
|
return appendMarkup(layoutKeyForPlacement(pos), markup);
|
|
1773
1791
|
}
|
|
@@ -1787,7 +1805,10 @@ function renderLayoutParts(props, renderer) {
|
|
|
1787
1805
|
children: children,
|
|
1788
1806
|
errorControl: errorControl,
|
|
1789
1807
|
style: style,
|
|
1790
|
-
className: cc(className)
|
|
1808
|
+
className: cc(className),
|
|
1809
|
+
wrapLayout: function wrapLayout(x) {
|
|
1810
|
+
return x;
|
|
1811
|
+
}
|
|
1791
1812
|
};
|
|
1792
1813
|
(adornments != null ? adornments : []).sort(function (a, b) {
|
|
1793
1814
|
return a.priority - b.priority;
|
|
@@ -1822,6 +1843,9 @@ function applyArrayLengthRestrictions(_ref7, disable) {
|
|
|
1822
1843
|
function isIconAdornment(a) {
|
|
1823
1844
|
return a.type === exports.ControlAdornmentType.Icon;
|
|
1824
1845
|
}
|
|
1846
|
+
function isAccordionAdornment(a) {
|
|
1847
|
+
return a.type === exports.ControlAdornmentType.Accordion;
|
|
1848
|
+
}
|
|
1825
1849
|
function createLayoutRenderer(render, options) {
|
|
1826
1850
|
return _extends({
|
|
1827
1851
|
type: "layout",
|
|
@@ -1912,6 +1936,13 @@ var defaultTailwindTheme = {
|
|
|
1912
1936
|
selectOptions: {
|
|
1913
1937
|
emptyText: "<select>"
|
|
1914
1938
|
}
|
|
1939
|
+
},
|
|
1940
|
+
adornment: {
|
|
1941
|
+
accordion: {
|
|
1942
|
+
className: "flex items-center gap-2 my-2",
|
|
1943
|
+
togglerOpenClass: "fa fa-chevron-up",
|
|
1944
|
+
togglerClosedClass: "fa fa-chevron-down"
|
|
1945
|
+
}
|
|
1915
1946
|
}
|
|
1916
1947
|
};
|
|
1917
1948
|
|
|
@@ -2389,6 +2420,47 @@ function createCheckboxRenderer(options) {
|
|
|
2389
2420
|
});
|
|
2390
2421
|
}
|
|
2391
2422
|
|
|
2423
|
+
function DefaultAccordion(_ref) {
|
|
2424
|
+
var _effect = core.useComponentTracking();
|
|
2425
|
+
try {
|
|
2426
|
+
var children = _ref.children,
|
|
2427
|
+
accordion = _ref.accordion,
|
|
2428
|
+
contentStyle = _ref.contentStyle,
|
|
2429
|
+
contentClassName = _ref.contentClassName,
|
|
2430
|
+
designMode = _ref.designMode,
|
|
2431
|
+
togglerOpenClass = _ref.togglerOpenClass,
|
|
2432
|
+
togglerClosedClass = _ref.togglerClosedClass,
|
|
2433
|
+
className = _ref.className,
|
|
2434
|
+
_ref$renderTitle = _ref.renderTitle,
|
|
2435
|
+
renderTitle = _ref$renderTitle === void 0 ? function (x) {
|
|
2436
|
+
return /*#__PURE__*/React__default["default"].createElement("span", null, x);
|
|
2437
|
+
} : _ref$renderTitle,
|
|
2438
|
+
renderToggler = _ref.renderToggler;
|
|
2439
|
+
var open = core.useControl(!!accordion.defaultExpanded);
|
|
2440
|
+
var isOpen = open.value;
|
|
2441
|
+
var fullContentStyle = isOpen || designMode ? contentStyle : _extends({}, contentStyle, {
|
|
2442
|
+
display: "none"
|
|
2443
|
+
});
|
|
2444
|
+
var toggler = renderToggler ? renderToggler(open) : /*#__PURE__*/React__default["default"].createElement("button", {
|
|
2445
|
+
onClick: function onClick() {
|
|
2446
|
+
return open.setValue(function (x) {
|
|
2447
|
+
return !x;
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
}, /*#__PURE__*/React__default["default"].createElement("i", {
|
|
2451
|
+
className: clsx__default["default"](isOpen ? togglerOpenClass : togglerClosedClass)
|
|
2452
|
+
}));
|
|
2453
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2454
|
+
className: className
|
|
2455
|
+
}, renderTitle(accordion.title, open), toggler), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2456
|
+
style: fullContentStyle,
|
|
2457
|
+
className: contentClassName
|
|
2458
|
+
}, children));
|
|
2459
|
+
} finally {
|
|
2460
|
+
_effect();
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2392
2464
|
function createButtonActionRenderer(actionId, options) {
|
|
2393
2465
|
if (options === void 0) {
|
|
2394
2466
|
options = {};
|
|
@@ -2556,10 +2628,14 @@ function createDefaultDataRenderer(options) {
|
|
|
2556
2628
|
});
|
|
2557
2629
|
}
|
|
2558
2630
|
function createDefaultAdornmentRenderer(options) {
|
|
2631
|
+
if (options === void 0) {
|
|
2632
|
+
options = {};
|
|
2633
|
+
}
|
|
2559
2634
|
return {
|
|
2560
2635
|
type: "adornment",
|
|
2561
2636
|
render: function render(_ref6) {
|
|
2562
|
-
var adornment = _ref6.adornment
|
|
2637
|
+
var adornment = _ref6.adornment,
|
|
2638
|
+
designMode = _ref6.designMode;
|
|
2563
2639
|
return {
|
|
2564
2640
|
apply: function apply(rl) {
|
|
2565
2641
|
if (isIconAdornment(adornment)) {
|
|
@@ -2568,6 +2644,17 @@ function createDefaultAdornmentRenderer(options) {
|
|
|
2568
2644
|
className: adornment.iconClass
|
|
2569
2645
|
}))(rl);
|
|
2570
2646
|
}
|
|
2647
|
+
if (isAccordionAdornment(adornment)) {
|
|
2648
|
+
return wrapLayout(function (x) {
|
|
2649
|
+
return /*#__PURE__*/React__default["default"].createElement(DefaultAccordion, _extends({
|
|
2650
|
+
children: x,
|
|
2651
|
+
accordion: adornment,
|
|
2652
|
+
contentStyle: rl.style,
|
|
2653
|
+
contentClassName: rl.className,
|
|
2654
|
+
designMode: designMode
|
|
2655
|
+
}, options.accordion));
|
|
2656
|
+
})(rl);
|
|
2657
|
+
}
|
|
2571
2658
|
},
|
|
2572
2659
|
priority: 0,
|
|
2573
2660
|
adornment: adornment
|
|
@@ -2584,9 +2671,9 @@ function createDefaultLayoutRenderer(options) {
|
|
|
2584
2671
|
className: rendererClass(props.className, options.className)
|
|
2585
2672
|
}), renderers);
|
|
2586
2673
|
return {
|
|
2587
|
-
children: /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2674
|
+
children: layout.wrapLayout( /*#__PURE__*/React__default["default"].createElement(DefaultLayout, _extends({
|
|
2588
2675
|
layout: layout
|
|
2589
|
-
}, options)),
|
|
2676
|
+
}, options))),
|
|
2590
2677
|
className: layout.className,
|
|
2591
2678
|
style: layout.style,
|
|
2592
2679
|
divRef: function divRef(e) {
|
|
@@ -2628,7 +2715,7 @@ function createDefaultRenderers(options) {
|
|
|
2628
2715
|
array: createDefaultArrayRenderer(options.array),
|
|
2629
2716
|
group: createDefaultGroupRenderer(options.group),
|
|
2630
2717
|
label: createDefaultLabelRenderer(options.label),
|
|
2631
|
-
adornment: createDefaultAdornmentRenderer(),
|
|
2718
|
+
adornment: createDefaultAdornmentRenderer(options.adornment),
|
|
2632
2719
|
renderLayout: createDefaultLayoutRenderer(options.layout),
|
|
2633
2720
|
visibility: createDefaultVisibilityRenderer()
|
|
2634
2721
|
};
|
|
@@ -2885,6 +2972,7 @@ exports.hasOptions = hasOptions;
|
|
|
2885
2972
|
exports.hideDisplayOnly = hideDisplayOnly;
|
|
2886
2973
|
exports.htmlDisplayControl = htmlDisplayControl;
|
|
2887
2974
|
exports.intField = intField;
|
|
2975
|
+
exports.isAccordionAdornment = isAccordionAdornment;
|
|
2888
2976
|
exports.isActionControlsDefinition = isActionControlsDefinition;
|
|
2889
2977
|
exports.isCompoundField = isCompoundField;
|
|
2890
2978
|
exports.isControlDisabled = isControlDisabled;
|
|
@@ -2946,6 +3034,7 @@ exports.visitControlDataArray = visitControlDataArray;
|
|
|
2946
3034
|
exports.visitControlDefinition = visitControlDefinition;
|
|
2947
3035
|
exports.watchControlLookup = watchControlLookup;
|
|
2948
3036
|
exports.withScalarOptions = withScalarOptions;
|
|
3037
|
+
exports.wrapLayout = wrapLayout;
|
|
2949
3038
|
exports.wrapMarkup = wrapMarkup;
|
|
2950
3039
|
exports.wrapMarkupAt = wrapMarkupAt;
|
|
2951
3040
|
//# sourceMappingURL=index.js.map
|