@chobantonov/jsonforms-react-extended-renderers 0.0.0-stage → 0.1.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.
Files changed (193) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +17 -2
  3. package/lib/AgGridControlRenderer.impl-BO-Z1x0Y.js +2 -0
  4. package/lib/AgGridControlRenderer.impl-BO-Z1x0Y.js.map +1 -0
  5. package/lib/AgGridControlRenderer.impl-BZS8_ocu.mjs +429 -0
  6. package/lib/AgGridControlRenderer.impl-BZS8_ocu.mjs.map +1 -0
  7. package/lib/DynamicJSXRenderer-Cyw40Kz0.js +2 -0
  8. package/lib/DynamicJSXRenderer-Cyw40Kz0.js.map +1 -0
  9. package/lib/DynamicJSXRenderer-DyB3ZpZV.mjs +109 -0
  10. package/lib/DynamicJSXRenderer-DyB3ZpZV.mjs.map +1 -0
  11. package/lib/MarkupLabelRenderer.impl-CWfdcUuH.mjs +12 -0
  12. package/lib/MarkupLabelRenderer.impl-CWfdcUuH.mjs.map +1 -0
  13. package/lib/MarkupLabelRenderer.impl-DnuzIPQg.js +2 -0
  14. package/lib/MarkupLabelRenderer.impl-DnuzIPQg.js.map +1 -0
  15. package/lib/MonacoControlRenderer.impl-BwgLGNMK.js +3 -0
  16. package/lib/MonacoControlRenderer.impl-BwgLGNMK.js.map +1 -0
  17. package/lib/MonacoControlRenderer.impl-CyjMHbOd.mjs +186 -0
  18. package/lib/MonacoControlRenderer.impl-CyjMHbOd.mjs.map +1 -0
  19. package/lib/RactiveTemplate-7L44A38e.js +2 -0
  20. package/lib/RactiveTemplate-7L44A38e.js.map +1 -0
  21. package/lib/RactiveTemplate-Cat7CxUp.mjs +74 -0
  22. package/lib/RactiveTemplate-Cat7CxUp.mjs.map +1 -0
  23. package/lib/ajv-localizers.cjs.js +2 -0
  24. package/lib/ajv-localizers.cjs.js.map +1 -0
  25. package/lib/ajv-localizers.esm.js +7 -0
  26. package/lib/ajv-localizers.esm.js.map +1 -0
  27. package/lib/ajvI18n-2UTyJv5g.js +2 -0
  28. package/lib/ajvI18n-2UTyJv5g.js.map +1 -0
  29. package/lib/ajvI18n-DO8FFvx1.mjs +227 -0
  30. package/lib/ajvI18n-DO8FFvx1.mjs.map +1 -0
  31. package/lib/celTemplate-Cl0alaCz.js +3 -0
  32. package/lib/celTemplate-Cl0alaCz.js.map +1 -0
  33. package/lib/celTemplate-D_AGhaIL.mjs +137 -0
  34. package/lib/celTemplate-D_AGhaIL.mjs.map +1 -0
  35. package/lib/components/DynamicJSXRenderer.d.ts +7 -0
  36. package/lib/components/ExtendedJsonForms.d.ts +80 -0
  37. package/lib/components/GenericAdditionalProperties.d.ts +4 -0
  38. package/lib/components/InterpolatedText.d.ts +34 -0
  39. package/lib/components/RactiveTemplate.d.ts +37 -0
  40. package/lib/components/editorRendererTypes.d.ts +139 -0
  41. package/lib/components/elementRender.d.ts +15 -0
  42. package/lib/configNamespaces-BFclHtB8.mjs +1 -0
  43. package/lib/configNamespaces-sboXDudL.js +1 -0
  44. package/lib/core/ajv.d.ts +82 -0
  45. package/lib/core/ajvI18n/bg.d.ts +2 -0
  46. package/lib/core/ajvI18n/index.d.ts +118 -0
  47. package/lib/core/ajvI18n/localizers.d.ts +20 -0
  48. package/lib/core/dynamicDefaults.d.ts +34 -0
  49. package/lib/core/keywords.d.ts +24 -0
  50. package/lib/core/transform.d.ts +29 -0
  51. package/lib/core/uiSchema.d.ts +48 -0
  52. package/lib/elementRender-Dbp2e-Cc.js +2 -0
  53. package/lib/elementRender-Dbp2e-Cc.js.map +1 -0
  54. package/lib/elementRender-y8MK9CCE.mjs +5 -0
  55. package/lib/elementRender-y8MK9CCE.mjs.map +1 -0
  56. package/lib/index.d.ts +41 -0
  57. package/lib/jsonforms-react-extended.cjs.js +16 -0
  58. package/lib/jsonforms-react-extended.cjs.js.map +1 -0
  59. package/lib/jsonforms-react-extended.esm.js +2335 -0
  60. package/lib/jsonforms-react-extended.esm.js.map +1 -0
  61. package/lib/locale/bg.d.ts +14 -0
  62. package/lib/markdown-C_y73Q0w.mjs +123 -0
  63. package/lib/markdown-C_y73Q0w.mjs.map +1 -0
  64. package/lib/markdown-CuqtpGVd.js +2 -0
  65. package/lib/markdown-CuqtpGVd.js.map +1 -0
  66. package/lib/objectWithoutProperties-6zedhz76.js +2 -0
  67. package/lib/objectWithoutProperties-6zedhz76.js.map +1 -0
  68. package/lib/objectWithoutProperties-yjQMyZ0y.mjs +58 -0
  69. package/lib/objectWithoutProperties-yjQMyZ0y.mjs.map +1 -0
  70. package/lib/renderers/AgGridControlRenderer.d.ts +10 -0
  71. package/lib/renderers/AgGridControlRenderer.impl.d.ts +4 -0
  72. package/lib/renderers/ButtonRenderer.d.ts +83 -0
  73. package/lib/renderers/GenericMixedRenderer.d.ts +9 -0
  74. package/lib/renderers/HorizontalLayoutRenderer.d.ts +5 -0
  75. package/lib/renderers/ImageViewRenderer.d.ts +48 -0
  76. package/lib/renderers/LinkRenderer.d.ts +23 -0
  77. package/lib/renderers/MarkupLabelRenderer.d.ts +35 -0
  78. package/lib/renderers/MarkupLabelRenderer.impl.d.ts +17 -0
  79. package/lib/renderers/MonacoControlRenderer.d.ts +8 -0
  80. package/lib/renderers/MonacoControlRenderer.impl.d.ts +4 -0
  81. package/lib/renderers/RactiveTemplateLayoutRenderer.d.ts +6 -0
  82. package/lib/renderers/SeparatorRenderer.d.ts +17 -0
  83. package/lib/renderers/SlotRenderer.d.ts +5 -0
  84. package/lib/renderers/SpacerRenderer.d.ts +5 -0
  85. package/lib/renderers/SplitLayoutRenderer.d.ts +18 -0
  86. package/lib/renderers/TemplateLayoutRenderer.d.ts +13 -0
  87. package/lib/renderers/TemplateRenderer.d.ts +17 -0
  88. package/lib/renderers/TsxTemplateLayoutRenderer.d.ts +111 -0
  89. package/lib/renderers/index.d.ts +13 -0
  90. package/lib/renderers/templateEngines.d.ts +43 -0
  91. package/lib/util/actionContext.d.ts +23 -0
  92. package/lib/util/additionalErrors.d.ts +77 -0
  93. package/lib/util/celEnvironment.d.ts +23 -0
  94. package/lib/util/celTemplate.d.ts +47 -0
  95. package/lib/util/childNames.d.ts +46 -0
  96. package/lib/util/configNamespaces.d.ts +1 -0
  97. package/lib/util/cron.d.ts +122 -0
  98. package/lib/util/editorControls.d.ts +8 -0
  99. package/lib/util/editorDiagnostics.d.ts +56 -0
  100. package/lib/util/extendedControls.d.ts +4 -0
  101. package/lib/util/extendedLocale.d.ts +32 -0
  102. package/lib/util/fileFilterValue.d.ts +3 -0
  103. package/lib/util/formContext.d.ts +54 -0
  104. package/lib/util/gridColumns.d.ts +6 -0
  105. package/lib/util/horizontalLayout.d.ts +10 -0
  106. package/lib/util/i18nDefaults.d.ts +45 -0
  107. package/lib/util/interpolate.d.ts +105 -0
  108. package/lib/util/labelFilterValue.d.ts +2 -0
  109. package/lib/util/lazyControl.d.ts +36 -0
  110. package/lib/util/lazyTemplate.d.ts +18 -0
  111. package/lib/util/markdown.d.ts +55 -0
  112. package/lib/util/markdownEscape.d.ts +27 -0
  113. package/lib/util/markup.d.ts +74 -0
  114. package/lib/util/maskControls.d.ts +2 -0
  115. package/lib/util/templateLang.d.ts +87 -0
  116. package/lib/util/templateUrls.d.ts +40 -0
  117. package/lib/util/urlPolicy.d.ts +42 -0
  118. package/lib/util/useCronPicker.d.ts +24 -0
  119. package/lib/util/useDurationControl.d.ts +99 -0
  120. package/lib/util/useEditorAppearance.d.ts +21 -0
  121. package/lib/util/useExtendedTranslator.d.ts +10 -0
  122. package/lib/util/useMonacoShadowStyles.d.ts +2 -0
  123. package/package.json +110 -3
  124. package/src/components/DynamicJSXRenderer.tsx +274 -0
  125. package/src/components/ExtendedJsonForms.tsx +329 -0
  126. package/src/components/GenericAdditionalProperties.tsx +362 -0
  127. package/src/components/InterpolatedText.tsx +114 -0
  128. package/src/components/RactiveTemplate.tsx +161 -0
  129. package/src/components/editorRendererTypes.ts +135 -0
  130. package/src/components/elementRender.ts +15 -0
  131. package/src/core/ajv.ts +177 -0
  132. package/src/core/ajvI18n/bg.ts +203 -0
  133. package/src/core/ajvI18n/index.ts +267 -0
  134. package/src/core/ajvI18n/localizers.ts +25 -0
  135. package/src/core/dynamicDefaults.ts +170 -0
  136. package/src/core/keywords.ts +71 -0
  137. package/src/core/transform.ts +137 -0
  138. package/src/core/uiSchema.ts +53 -0
  139. package/src/index.tsx +196 -0
  140. package/src/locale/bg.ts +51 -0
  141. package/src/renderers/AgGridControlRenderer.impl.tsx +788 -0
  142. package/src/renderers/AgGridControlRenderer.tsx +24 -0
  143. package/src/renderers/ButtonRenderer.tsx +328 -0
  144. package/src/renderers/GenericMixedRenderer.tsx +224 -0
  145. package/src/renderers/HorizontalLayoutRenderer.tsx +93 -0
  146. package/src/renderers/ImageViewRenderer.tsx +328 -0
  147. package/src/renderers/LinkRenderer.tsx +92 -0
  148. package/src/renderers/MarkupLabelRenderer.impl.tsx +26 -0
  149. package/src/renderers/MarkupLabelRenderer.tsx +327 -0
  150. package/src/renderers/MonacoControlRenderer.impl.tsx +351 -0
  151. package/src/renderers/MonacoControlRenderer.tsx +24 -0
  152. package/src/renderers/RactiveTemplateLayoutRenderer.tsx +172 -0
  153. package/src/renderers/SeparatorRenderer.tsx +55 -0
  154. package/src/renderers/SlotRenderer.tsx +34 -0
  155. package/src/renderers/SpacerRenderer.tsx +69 -0
  156. package/src/renderers/SplitLayoutRenderer.tsx +220 -0
  157. package/src/renderers/TemplateLayoutRenderer.tsx +394 -0
  158. package/src/renderers/TemplateRenderer.tsx +71 -0
  159. package/src/renderers/TsxTemplateLayoutRenderer.tsx +258 -0
  160. package/src/renderers/index.ts +14 -0
  161. package/src/renderers/templateEngines.tsx +100 -0
  162. package/src/util/actionContext.ts +29 -0
  163. package/src/util/additionalErrors.tsx +391 -0
  164. package/src/util/celEnvironment.ts +300 -0
  165. package/src/util/celTemplate.ts +267 -0
  166. package/src/util/childNames.ts +135 -0
  167. package/src/util/configNamespaces.ts +6 -0
  168. package/src/util/cron.ts +433 -0
  169. package/src/util/editorControls.ts +58 -0
  170. package/src/util/editorDiagnostics.ts +103 -0
  171. package/src/util/extendedControls.ts +34 -0
  172. package/src/util/extendedLocale.ts +67 -0
  173. package/src/util/fileFilterValue.ts +28 -0
  174. package/src/util/formContext.ts +74 -0
  175. package/src/util/gridColumns.ts +80 -0
  176. package/src/util/horizontalLayout.ts +59 -0
  177. package/src/util/i18nDefaults.ts +80 -0
  178. package/src/util/interpolate.ts +218 -0
  179. package/src/util/labelFilterValue.ts +49 -0
  180. package/src/util/lazyControl.tsx +66 -0
  181. package/src/util/lazyTemplate.tsx +110 -0
  182. package/src/util/markdown.tsx +345 -0
  183. package/src/util/markdownEscape.ts +29 -0
  184. package/src/util/markup.ts +144 -0
  185. package/src/util/maskControls.ts +6 -0
  186. package/src/util/templateLang.ts +145 -0
  187. package/src/util/templateUrls.ts +274 -0
  188. package/src/util/urlPolicy.ts +115 -0
  189. package/src/util/useCronPicker.ts +102 -0
  190. package/src/util/useDurationControl.ts +272 -0
  191. package/src/util/useEditorAppearance.ts +86 -0
  192. package/src/util/useExtendedTranslator.ts +25 -0
  193. package/src/util/useMonacoShadowStyles.ts +47 -0
@@ -0,0 +1,172 @@
1
+ import { useDynamicExternal } from '@chobantonov/jsonforms-react-renderer-common/dynamic/DynamicUiProvider';
2
+ import { LayoutProps } from '@jsonforms/core';
3
+ import { JsonFormsDispatch, useJsonForms } from '@jsonforms/react';
4
+ import React, { useEffect, useMemo } from 'react';
5
+ import { createLazyTemplate } from '../util/lazyTemplate';
6
+ import type { RactiveTemplateProps } from '../components/RactiveTemplate';
7
+
8
+ /*
9
+ Ractive is ~100KB and is imported at module scope by the template component,
10
+ so it is fetched only when a `lang: "ractive"` element actually renders.
11
+ */
12
+ const RactiveTemplate = createLazyTemplate<RactiveTemplateProps>(
13
+ async () => (await import('../components/RactiveTemplate')).RactiveTemplate,
14
+ {
15
+ loading: 'template.loading',
16
+ error: 'template.loadError',
17
+ renderError: 'template.renderError',
18
+ },
19
+ );
20
+ import {
21
+ ractiveTransitionAttributes,
22
+ resolveChildNames,
23
+ useNamedChildren,
24
+ } from '../util/childNames';
25
+ import { buildFormContext } from '../util/formContext';
26
+ import { resolveUrlPolicy } from '../util/urlPolicy';
27
+ import {
28
+ TemplateLayoutElement,
29
+ resolveTemplateEngine,
30
+ } from '../util/templateLang';
31
+ import { TemplateDiagnostic } from './templateEngines';
32
+
33
+ /**
34
+ * The `lang: "ractive"` profile - the specification's default web profile, and
35
+ * the one the Svelte renderer family implements.
36
+ *
37
+ * Children are **partials**: `{{> body}}` renders the child named `body`.
38
+ * Ractive cannot host a React subtree, so each partial resolves to a
39
+ * placeholder element that React then portals the delegated renderer into. The
40
+ * partial registry is generated from the child names rather than authored, so
41
+ * a template never has to know about the placeholder attribute.
42
+ *
43
+ * The bindings are the ones the specification names: `data` (whole-form data),
44
+ * `errors` (core schema errors), `context`, `elements` and `translate`.
45
+ */
46
+
47
+ const SLOT_ATTR = 'data-jsonforms-slot';
48
+
49
+ export const RactiveTemplateLayoutRenderer = (
50
+ props: LayoutProps & { uischema: TemplateLayoutElement },
51
+ ) => {
52
+ const { uischema, schema, path, enabled, visible, renderers, cells, config } =
53
+ props;
54
+ const ctx = useJsonForms();
55
+ const external = useDynamicExternal();
56
+ const resolved = resolveTemplateEngine(uischema, config);
57
+
58
+ const { children, names, diagnostics } = useNamedChildren(uischema.elements);
59
+
60
+ const nameKey = JSON.stringify(names);
61
+
62
+ /*
63
+ Reported to the author rather than rendered: a child that cannot be
64
+ addressed is a mistake in the UI schema, and the person filling in the
65
+ form can do nothing about it. Same precedent as `Categorization`'s
66
+ `initial` (adjustment 10.5).
67
+ */
68
+ useEffect(() => {
69
+ for (const diagnostic of diagnostics) {
70
+ // oxlint-disable-next-line no-console
71
+ console.warn(diagnostic);
72
+ }
73
+ }, [diagnostics]);
74
+
75
+ /*
76
+ An attribute Ractive will eat as a transition directive. This profile
77
+ registers no transitions, so it does nothing except disappear - and
78
+ disappearing silently is how an hour goes missing.
79
+ */
80
+ const template = uischema.template ?? '';
81
+ useEffect(() => {
82
+ const eaten = ractiveTransitionAttributes(template);
83
+ if (eaten.length > 0) {
84
+ // oxlint-disable-next-line no-console
85
+ console.warn(
86
+ `template.ractiveTransitionAttribute: ${JSON.stringify(
87
+ eaten,
88
+ )} end in -in, -out or -in-out, which Ractive parses as transition directives. This profile registers no transitions, so they are dropped from the DOM. Rename them.`,
89
+ );
90
+ }
91
+ }, [template]);
92
+
93
+ /* One placeholder partial per child, so `{{> body}}` resolves. */
94
+ const partials = useMemo(() => {
95
+ const map: Record<string, string> = {};
96
+ for (const name of JSON.parse(nameKey) as (string | null)[]) {
97
+ if (name !== null) {
98
+ map[name] = `<div ${SLOT_ATTR}="${name}"></div>`;
99
+ }
100
+ }
101
+ return map;
102
+ }, [nameKey]);
103
+
104
+ const slots = useMemo(() => {
105
+ const map: Record<string, React.ReactNode> = {};
106
+ const childNames = resolveChildNames(children).names;
107
+ children.forEach((element, index) => {
108
+ const name = childNames[index];
109
+ if (name === undefined) {
110
+ return;
111
+ }
112
+ map[name] = (
113
+ <JsonFormsDispatch
114
+ uischema={element}
115
+ schema={schema}
116
+ path={path}
117
+ enabled={enabled}
118
+ renderers={renderers}
119
+ cells={cells}
120
+ />
121
+ );
122
+ });
123
+ return map;
124
+ }, [children, schema, path, enabled, renderers, cells]);
125
+
126
+ /*
127
+ Rebuilt whenever a binding changes; the template component turns that into
128
+ a keypath `set`, which is the surgical half. The object identity is the
129
+ signal, the values inside are what Ractive diffs.
130
+ */
131
+ const bindings = useMemo(
132
+ () => ({
133
+ data: ctx.core?.data,
134
+ errors: ctx.core?.errors,
135
+ context: buildFormContext({
136
+ ctx: ctx as any,
137
+ schema,
138
+ uischema,
139
+ external,
140
+ }),
141
+ elements: resolveChildNames(uischema.elements ?? [])
142
+ .names.filter((name): name is string => name !== undefined)
143
+ .map((name) => ({ name })),
144
+ translate: (key: string, fallback?: string) =>
145
+ ctx.i18n?.translate?.(key, fallback) ?? fallback ?? key,
146
+ }),
147
+ [ctx, schema, uischema, external],
148
+ );
149
+
150
+ if (visible === false) {
151
+ return null;
152
+ }
153
+ if (resolved.diagnostic) {
154
+ return (
155
+ <TemplateDiagnostic
156
+ uischema={uischema}
157
+ config={config}
158
+ visible={visible}
159
+ />
160
+ );
161
+ }
162
+
163
+ return (
164
+ <RactiveTemplate
165
+ template={template}
166
+ partials={partials}
167
+ data={bindings}
168
+ slots={slots}
169
+ urlPolicy={resolveUrlPolicy(config)}
170
+ />
171
+ );
172
+ };
@@ -0,0 +1,55 @@
1
+ import { LayoutProps, RankedTester, rankWith, uiTypeIs } from '@jsonforms/core';
2
+ import { withJsonFormsLayoutProps } from '@jsonforms/react';
3
+ import React from 'react';
4
+
5
+ export const separatorRendererTester: RankedTester = rankWith(
6
+ 1,
7
+ uiTypeIs('Separator'),
8
+ );
9
+
10
+ /**
11
+ * `Separator` - a static divider that reads and writes nothing.
12
+ *
13
+ * `options.vertical` is section 13's single orientation encoding, the same
14
+ * convention `vertical` follows everywhere else in this project. An `<hr>` has
15
+ * an implicit `separator` role whose default orientation is horizontal, so a
16
+ * vertical one has to say so: `aria-orientation` is what tells a screen reader
17
+ * the sections are side by side rather than stacked.
18
+ *
19
+ * The extent comes from the layout, as the specification requires - a vertical
20
+ * separator needs usable height from its context, and supplies none itself.
21
+ */
22
+ export const SeparatorRendererComponent = ({
23
+ uischema,
24
+ visible,
25
+ }: LayoutProps) => {
26
+ if (visible === false) {
27
+ return null;
28
+ }
29
+ const vertical =
30
+ (uischema as { options?: Record<string, unknown> }).options?.vertical ===
31
+ true;
32
+ return vertical ? (
33
+ <hr
34
+ aria-orientation='vertical'
35
+ data-separator='vertical'
36
+ style={{
37
+ // `height: 100%` alone collapses in a flex row, where the default
38
+ // `align-self: stretch` is what actually gives the rule its extent.
39
+ alignSelf: 'stretch',
40
+ width: 0,
41
+ height: 'auto',
42
+ margin: 0,
43
+ borderLeft: '1px solid currentColor',
44
+ borderTop: 0,
45
+ opacity: 0.3,
46
+ }}
47
+ />
48
+ ) : (
49
+ <hr aria-orientation='horizontal' data-separator='horizontal' />
50
+ );
51
+ };
52
+
53
+ export const SeparatorRenderer = withJsonFormsLayoutProps(
54
+ SeparatorRendererComponent,
55
+ );
@@ -0,0 +1,34 @@
1
+ import {
2
+ LayoutProps,
3
+ RankedTester,
4
+ UISchemaElement,
5
+ rankWith,
6
+ uiTypeIs,
7
+ } from '@jsonforms/core';
8
+ import { JsonFormsDispatch, withJsonFormsLayoutProps } from '@jsonforms/react';
9
+ import React from 'react';
10
+ import { NamedElement, TemplateSlotsContext } from './TemplateRenderer';
11
+
12
+ export const slotRendererTester: RankedTester = rankWith(2, uiTypeIs('Slot'));
13
+
14
+ export const SlotRendererComponent = (props: LayoutProps) => {
15
+ const slots = React.useContext(TemplateSlotsContext);
16
+ const element = props.uischema as NamedElement;
17
+ const fallback = element.elements?.[0];
18
+ const contents: UISchemaElement | undefined = element.name
19
+ ? (slots[element.name] ?? fallback)
20
+ : fallback;
21
+ if (!props.visible || !contents) return null;
22
+ return (
23
+ <JsonFormsDispatch
24
+ schema={props.schema}
25
+ uischema={contents}
26
+ path={props.path}
27
+ enabled={props.enabled}
28
+ renderers={props.renderers}
29
+ cells={props.cells}
30
+ />
31
+ );
32
+ };
33
+
34
+ export const SlotRenderer = withJsonFormsLayoutProps(SlotRendererComponent);
@@ -0,0 +1,69 @@
1
+ import { LayoutProps, RankedTester, rankWith, uiTypeIs } from '@jsonforms/core';
2
+ import { withJsonFormsLayoutProps } from '@jsonforms/react';
3
+ import React from 'react';
4
+
5
+ export const spacerRendererTester: RankedTester = rankWith(
6
+ 1,
7
+ uiTypeIs('Spacer'),
8
+ );
9
+
10
+ /**
11
+ * `{ "type": "Spacer", "size": 32 }` — intrinsic spacing, with no data binding.
12
+ *
13
+ * `size` is a top-level field. The axis follows the parent: width inside a
14
+ * HorizontalLayout, height inside a VerticalLayout or at the top level.
15
+ * `options.layout.weight` can allocate flexible space.
16
+ *
17
+ * "It defaults to 32 and uses the shared non-negative Dimension type (numeric
18
+ * values are CSS pixels on web)."
19
+ */
20
+ const DEFAULT_SIZE = 32;
21
+
22
+ const toCss = (value: number | string): string =>
23
+ typeof value === 'number' ? `${value}px` : value;
24
+
25
+ const resolveSize = (uischema: any): number | string => {
26
+ const candidate = uischema?.size;
27
+ if (typeof candidate === 'number' && Number.isFinite(candidate)) {
28
+ return Math.max(0, candidate);
29
+ }
30
+ if (typeof candidate === 'string' && candidate.trim().length > 0) {
31
+ return candidate;
32
+ }
33
+ return DEFAULT_SIZE;
34
+ };
35
+
36
+ export const SpacerRendererComponent = ({ uischema, visible }: LayoutProps) => {
37
+ const size = resolveSize(uischema);
38
+ const weight = (uischema as any)?.options?.layout?.weight;
39
+ const flexible =
40
+ typeof weight === 'number' && Number.isFinite(weight) && weight > 0;
41
+
42
+ if (!visible) {
43
+ return null;
44
+ }
45
+
46
+ /*
47
+ The axis follows the parent, but the parent applies it: a layout reads a
48
+ Spacer's top-level `size` and gives its slot a fixed main-axis basis -
49
+ width in a row, height in a column. That keeps this package free of any
50
+ dependency on a particular layout implementation.
51
+
52
+ What is left here is the standalone case the specification also covers:
53
+ "top-level `size` supplies intrinsic spacing independently of parent layout
54
+ support", where the axis falls back to height.
55
+ */
56
+ return (
57
+ <div
58
+ aria-hidden='true'
59
+ data-spacer
60
+ style={
61
+ flexible
62
+ ? { flex: `${weight} 1 0`, minWidth: 0, minHeight: 0 }
63
+ : { flexShrink: 0, height: toCss(size), width: '100%' }
64
+ }
65
+ />
66
+ );
67
+ };
68
+
69
+ export const SpacerRenderer = withJsonFormsLayoutProps(SpacerRendererComponent);
@@ -0,0 +1,220 @@
1
+ import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
2
+ import { useEffectiveElements } from '@chobantonov/jsonforms-react-renderer-common/layout/layoutContext';
3
+ import {
4
+ Layout,
5
+ LayoutProps,
6
+ RankedTester,
7
+ UISchemaElement,
8
+ and,
9
+ or,
10
+ rankWith,
11
+ uiTypeIs,
12
+ } from '@jsonforms/core';
13
+ import { JsonFormsDispatch, withJsonFormsLayoutProps } from '@jsonforms/react';
14
+ import React from 'react';
15
+
16
+ export const sharedSplitLayoutTester: RankedTester = rankWith(
17
+ 4,
18
+ and(
19
+ or(uiTypeIs('HorizontalLayout'), uiTypeIs('VerticalLayout')),
20
+ (ui) => String(ui.options?.variant ?? '').toLowerCase() === 'splitter',
21
+ ),
22
+ );
23
+
24
+ export const splitCssSize = (value: unknown): string | undefined =>
25
+ typeof value === 'number' && Number.isFinite(value) && value > 0
26
+ ? `${value}px`
27
+ : typeof value === 'string' && value.trim()
28
+ ? value.trim()
29
+ : undefined;
30
+
31
+ /**
32
+ * The initial share of each pane.
33
+ *
34
+ * "Initial sizes use normal sizing" - so a pane's `options.layout.weight`
35
+ * decides its share, exactly as it would in an ordinary layout, and equal
36
+ * shares are what Auto produces rather than a rule of their own.
37
+ *
38
+ * "Span SHOULD NOT be used" with a splitter, so it is ignored here; a pane
39
+ * asking for one falls back to Auto rather than being sized against a grid
40
+ * that a draggable pane does not have.
41
+ */
42
+ export const initialSplitSizes = (elements: UISchemaElement[]): number[] => {
43
+ const weights = elements.map((element) => {
44
+ const weight = (element as any)?.options?.layout?.weight;
45
+ return typeof weight === 'number' && Number.isFinite(weight) && weight > 0
46
+ ? weight
47
+ : 1;
48
+ });
49
+ const total = weights.reduce((sum, weight) => sum + weight, 0);
50
+ return weights.map((weight) => (weight / total) * 100);
51
+ };
52
+
53
+ export const SharedSplitLayout = (props: LayoutProps) => {
54
+ const t = useI18n();
55
+ const layout = props.uischema as Layout;
56
+ const horizontal = layout.type === 'HorizontalLayout';
57
+ /*
58
+ "Only effective visible UI-schema children participate. Hidden children
59
+ leave layout." A hidden pane used to keep its share and its separator.
60
+ */
61
+ const elements = useEffectiveElements(
62
+ layout.elements,
63
+ props.path,
64
+ props.config,
65
+ );
66
+ const count = elements.length;
67
+ const [stored, setSizes] = React.useState<number[]>([]);
68
+ const sizes = stored.length === count ? stored : initialSplitSizes(elements);
69
+ /* "`resizable` defaults true"; false disables dragging without hiding panes. */
70
+ const resizable =
71
+ ({ ...props.config, ...layout.options } as any).resizable !== false;
72
+ /*
73
+ "splitter+wrap unsupported". Panes divide a single axis and a separator
74
+ sits between neighbours, so there is no meaningful second row to wrap on
75
+ to. Reported rather than ignored, because the author asked for something
76
+ that will not happen.
77
+ */
78
+ const wrapRequested = (layout.options as any)?.wrap === true;
79
+ const drag = React.useRef<{
80
+ index: number;
81
+ start: number;
82
+ total: number;
83
+ sizes: number[];
84
+ }>();
85
+ const options = { ...props.config, ...layout.options };
86
+ const adjust = (index: number, delta: number, original = sizes) => {
87
+ const limited = Math.max(
88
+ 1 - original[index],
89
+ Math.min(original[index + 1] - 1, delta),
90
+ );
91
+ setSizes(
92
+ original.map((size, i) =>
93
+ i === index ? size + limited : i === index + 1 ? size - limited : size,
94
+ ),
95
+ );
96
+ };
97
+ if (!props.visible) return null;
98
+ return (
99
+ <div
100
+ {...(wrapRequested
101
+ ? {
102
+ 'data-layout-diagnostic':
103
+ '`wrap` is not supported together with the splitter variant; ignored.',
104
+ }
105
+ : {})}
106
+ style={{
107
+ display: 'flex',
108
+ flexDirection: horizontal ? 'row' : 'column',
109
+ width: '100%',
110
+ minWidth: 0,
111
+ height: horizontal
112
+ ? undefined
113
+ : (splitCssSize(options.height) ?? '20rem'),
114
+ minHeight: horizontal ? undefined : splitCssSize(options.minHeight),
115
+ }}
116
+ >
117
+ {elements.map((element, index) => (
118
+ <React.Fragment key={index}>
119
+ <div
120
+ /* See the antd splitter: padding outside the basis overflows. */
121
+ style={{
122
+ boxSizing: 'border-box',
123
+ flex: `${sizes[index]} 1 0`,
124
+ minWidth: 0,
125
+ minHeight: 0,
126
+ overflow: 'auto',
127
+ padding: 8,
128
+ }}
129
+ >
130
+ <JsonFormsDispatch
131
+ schema={props.schema}
132
+ uischema={element}
133
+ path={props.path}
134
+ enabled={props.enabled}
135
+ renderers={props.renderers}
136
+ cells={props.cells}
137
+ />
138
+ </div>
139
+ {index < count - 1 && (
140
+ <div
141
+ role='separator'
142
+ /*
143
+ "`resizable` defaults true." When false the separator still
144
+ marks the boundary - it is a real separator either way - but it
145
+ stops being focusable and stops responding to keys or pointers.
146
+ */
147
+ {...(resizable ? { tabIndex: 0 } : { 'aria-disabled': true })}
148
+ aria-label={t('layout.resizePane', { index: index + 1 })}
149
+ aria-orientation={horizontal ? 'vertical' : 'horizontal'}
150
+ aria-valuemin={1}
151
+ aria-valuemax={sizes[index] + sizes[index + 1] - 1}
152
+ aria-valuenow={Math.round(sizes[index])}
153
+ style={{
154
+ flex: '0 0 6px',
155
+ background: 'rgba(128,128,128,0.3)',
156
+ cursor: resizable
157
+ ? horizontal
158
+ ? 'col-resize'
159
+ : 'row-resize'
160
+ : 'default',
161
+ touchAction: 'none',
162
+ }}
163
+ onKeyDown={(event) => {
164
+ if (!resizable) return;
165
+ const delta =
166
+ event.key === (horizontal ? 'ArrowRight' : 'ArrowDown')
167
+ ? 2
168
+ : event.key === (horizontal ? 'ArrowLeft' : 'ArrowUp')
169
+ ? -2
170
+ : 0;
171
+ if (delta) {
172
+ event.preventDefault();
173
+ adjust(index, delta);
174
+ }
175
+ }}
176
+ onPointerDown={(event) => {
177
+ if (!resizable) return;
178
+ const rect =
179
+ event.currentTarget.parentElement!.getBoundingClientRect();
180
+ const total = horizontal ? rect.width : rect.height;
181
+ if (!total) return;
182
+ event.preventDefault();
183
+ drag.current = {
184
+ index,
185
+ start: horizontal ? event.clientX : event.clientY,
186
+ total,
187
+ sizes,
188
+ };
189
+ event.currentTarget.setPointerCapture(event.pointerId);
190
+ }}
191
+ onPointerMove={(event) => {
192
+ const current = drag.current;
193
+ if (current)
194
+ adjust(
195
+ current.index,
196
+ (((horizontal ? event.clientX : event.clientY) -
197
+ current.start) /
198
+ current.total) *
199
+ 100,
200
+ current.sizes,
201
+ );
202
+ }}
203
+ onPointerUp={() => {
204
+ drag.current = undefined;
205
+ }}
206
+ onPointerCancel={() => {
207
+ drag.current = undefined;
208
+ }}
209
+ onLostPointerCapture={() => {
210
+ drag.current = undefined;
211
+ }}
212
+ />
213
+ )}
214
+ </React.Fragment>
215
+ ))}
216
+ </div>
217
+ );
218
+ };
219
+ export const SharedSplitLayoutRenderer =
220
+ withJsonFormsLayoutProps(SharedSplitLayout);