@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.
- package/LICENSE +22 -0
- package/README.md +17 -2
- package/lib/AgGridControlRenderer.impl-BO-Z1x0Y.js +2 -0
- package/lib/AgGridControlRenderer.impl-BO-Z1x0Y.js.map +1 -0
- package/lib/AgGridControlRenderer.impl-BZS8_ocu.mjs +429 -0
- package/lib/AgGridControlRenderer.impl-BZS8_ocu.mjs.map +1 -0
- package/lib/DynamicJSXRenderer-Cyw40Kz0.js +2 -0
- package/lib/DynamicJSXRenderer-Cyw40Kz0.js.map +1 -0
- package/lib/DynamicJSXRenderer-DyB3ZpZV.mjs +109 -0
- package/lib/DynamicJSXRenderer-DyB3ZpZV.mjs.map +1 -0
- package/lib/MarkupLabelRenderer.impl-CWfdcUuH.mjs +12 -0
- package/lib/MarkupLabelRenderer.impl-CWfdcUuH.mjs.map +1 -0
- package/lib/MarkupLabelRenderer.impl-DnuzIPQg.js +2 -0
- package/lib/MarkupLabelRenderer.impl-DnuzIPQg.js.map +1 -0
- package/lib/MonacoControlRenderer.impl-BwgLGNMK.js +3 -0
- package/lib/MonacoControlRenderer.impl-BwgLGNMK.js.map +1 -0
- package/lib/MonacoControlRenderer.impl-CyjMHbOd.mjs +186 -0
- package/lib/MonacoControlRenderer.impl-CyjMHbOd.mjs.map +1 -0
- package/lib/RactiveTemplate-7L44A38e.js +2 -0
- package/lib/RactiveTemplate-7L44A38e.js.map +1 -0
- package/lib/RactiveTemplate-Cat7CxUp.mjs +74 -0
- package/lib/RactiveTemplate-Cat7CxUp.mjs.map +1 -0
- package/lib/ajv-localizers.cjs.js +2 -0
- package/lib/ajv-localizers.cjs.js.map +1 -0
- package/lib/ajv-localizers.esm.js +7 -0
- package/lib/ajv-localizers.esm.js.map +1 -0
- package/lib/ajvI18n-2UTyJv5g.js +2 -0
- package/lib/ajvI18n-2UTyJv5g.js.map +1 -0
- package/lib/ajvI18n-DO8FFvx1.mjs +227 -0
- package/lib/ajvI18n-DO8FFvx1.mjs.map +1 -0
- package/lib/celTemplate-Cl0alaCz.js +3 -0
- package/lib/celTemplate-Cl0alaCz.js.map +1 -0
- package/lib/celTemplate-D_AGhaIL.mjs +137 -0
- package/lib/celTemplate-D_AGhaIL.mjs.map +1 -0
- package/lib/components/DynamicJSXRenderer.d.ts +7 -0
- package/lib/components/ExtendedJsonForms.d.ts +80 -0
- package/lib/components/GenericAdditionalProperties.d.ts +4 -0
- package/lib/components/InterpolatedText.d.ts +34 -0
- package/lib/components/RactiveTemplate.d.ts +37 -0
- package/lib/components/editorRendererTypes.d.ts +139 -0
- package/lib/components/elementRender.d.ts +15 -0
- package/lib/configNamespaces-BFclHtB8.mjs +1 -0
- package/lib/configNamespaces-sboXDudL.js +1 -0
- package/lib/core/ajv.d.ts +82 -0
- package/lib/core/ajvI18n/bg.d.ts +2 -0
- package/lib/core/ajvI18n/index.d.ts +118 -0
- package/lib/core/ajvI18n/localizers.d.ts +20 -0
- package/lib/core/dynamicDefaults.d.ts +34 -0
- package/lib/core/keywords.d.ts +24 -0
- package/lib/core/transform.d.ts +29 -0
- package/lib/core/uiSchema.d.ts +48 -0
- package/lib/elementRender-Dbp2e-Cc.js +2 -0
- package/lib/elementRender-Dbp2e-Cc.js.map +1 -0
- package/lib/elementRender-y8MK9CCE.mjs +5 -0
- package/lib/elementRender-y8MK9CCE.mjs.map +1 -0
- package/lib/index.d.ts +41 -0
- package/lib/jsonforms-react-extended.cjs.js +16 -0
- package/lib/jsonforms-react-extended.cjs.js.map +1 -0
- package/lib/jsonforms-react-extended.esm.js +2335 -0
- package/lib/jsonforms-react-extended.esm.js.map +1 -0
- package/lib/locale/bg.d.ts +14 -0
- package/lib/markdown-C_y73Q0w.mjs +123 -0
- package/lib/markdown-C_y73Q0w.mjs.map +1 -0
- package/lib/markdown-CuqtpGVd.js +2 -0
- package/lib/markdown-CuqtpGVd.js.map +1 -0
- package/lib/objectWithoutProperties-6zedhz76.js +2 -0
- package/lib/objectWithoutProperties-6zedhz76.js.map +1 -0
- package/lib/objectWithoutProperties-yjQMyZ0y.mjs +58 -0
- package/lib/objectWithoutProperties-yjQMyZ0y.mjs.map +1 -0
- package/lib/renderers/AgGridControlRenderer.d.ts +10 -0
- package/lib/renderers/AgGridControlRenderer.impl.d.ts +4 -0
- package/lib/renderers/ButtonRenderer.d.ts +83 -0
- package/lib/renderers/GenericMixedRenderer.d.ts +9 -0
- package/lib/renderers/HorizontalLayoutRenderer.d.ts +5 -0
- package/lib/renderers/ImageViewRenderer.d.ts +48 -0
- package/lib/renderers/LinkRenderer.d.ts +23 -0
- package/lib/renderers/MarkupLabelRenderer.d.ts +35 -0
- package/lib/renderers/MarkupLabelRenderer.impl.d.ts +17 -0
- package/lib/renderers/MonacoControlRenderer.d.ts +8 -0
- package/lib/renderers/MonacoControlRenderer.impl.d.ts +4 -0
- package/lib/renderers/RactiveTemplateLayoutRenderer.d.ts +6 -0
- package/lib/renderers/SeparatorRenderer.d.ts +17 -0
- package/lib/renderers/SlotRenderer.d.ts +5 -0
- package/lib/renderers/SpacerRenderer.d.ts +5 -0
- package/lib/renderers/SplitLayoutRenderer.d.ts +18 -0
- package/lib/renderers/TemplateLayoutRenderer.d.ts +13 -0
- package/lib/renderers/TemplateRenderer.d.ts +17 -0
- package/lib/renderers/TsxTemplateLayoutRenderer.d.ts +111 -0
- package/lib/renderers/index.d.ts +13 -0
- package/lib/renderers/templateEngines.d.ts +43 -0
- package/lib/util/actionContext.d.ts +23 -0
- package/lib/util/additionalErrors.d.ts +77 -0
- package/lib/util/celEnvironment.d.ts +23 -0
- package/lib/util/celTemplate.d.ts +47 -0
- package/lib/util/childNames.d.ts +46 -0
- package/lib/util/configNamespaces.d.ts +1 -0
- package/lib/util/cron.d.ts +122 -0
- package/lib/util/editorControls.d.ts +8 -0
- package/lib/util/editorDiagnostics.d.ts +56 -0
- package/lib/util/extendedControls.d.ts +4 -0
- package/lib/util/extendedLocale.d.ts +32 -0
- package/lib/util/fileFilterValue.d.ts +3 -0
- package/lib/util/formContext.d.ts +54 -0
- package/lib/util/gridColumns.d.ts +6 -0
- package/lib/util/horizontalLayout.d.ts +10 -0
- package/lib/util/i18nDefaults.d.ts +45 -0
- package/lib/util/interpolate.d.ts +105 -0
- package/lib/util/labelFilterValue.d.ts +2 -0
- package/lib/util/lazyControl.d.ts +36 -0
- package/lib/util/lazyTemplate.d.ts +18 -0
- package/lib/util/markdown.d.ts +55 -0
- package/lib/util/markdownEscape.d.ts +27 -0
- package/lib/util/markup.d.ts +74 -0
- package/lib/util/maskControls.d.ts +2 -0
- package/lib/util/templateLang.d.ts +87 -0
- package/lib/util/templateUrls.d.ts +40 -0
- package/lib/util/urlPolicy.d.ts +42 -0
- package/lib/util/useCronPicker.d.ts +24 -0
- package/lib/util/useDurationControl.d.ts +99 -0
- package/lib/util/useEditorAppearance.d.ts +21 -0
- package/lib/util/useExtendedTranslator.d.ts +10 -0
- package/lib/util/useMonacoShadowStyles.d.ts +2 -0
- package/package.json +110 -3
- package/src/components/DynamicJSXRenderer.tsx +274 -0
- package/src/components/ExtendedJsonForms.tsx +329 -0
- package/src/components/GenericAdditionalProperties.tsx +362 -0
- package/src/components/InterpolatedText.tsx +114 -0
- package/src/components/RactiveTemplate.tsx +161 -0
- package/src/components/editorRendererTypes.ts +135 -0
- package/src/components/elementRender.ts +15 -0
- package/src/core/ajv.ts +177 -0
- package/src/core/ajvI18n/bg.ts +203 -0
- package/src/core/ajvI18n/index.ts +267 -0
- package/src/core/ajvI18n/localizers.ts +25 -0
- package/src/core/dynamicDefaults.ts +170 -0
- package/src/core/keywords.ts +71 -0
- package/src/core/transform.ts +137 -0
- package/src/core/uiSchema.ts +53 -0
- package/src/index.tsx +196 -0
- package/src/locale/bg.ts +51 -0
- package/src/renderers/AgGridControlRenderer.impl.tsx +788 -0
- package/src/renderers/AgGridControlRenderer.tsx +24 -0
- package/src/renderers/ButtonRenderer.tsx +328 -0
- package/src/renderers/GenericMixedRenderer.tsx +224 -0
- package/src/renderers/HorizontalLayoutRenderer.tsx +93 -0
- package/src/renderers/ImageViewRenderer.tsx +328 -0
- package/src/renderers/LinkRenderer.tsx +92 -0
- package/src/renderers/MarkupLabelRenderer.impl.tsx +26 -0
- package/src/renderers/MarkupLabelRenderer.tsx +327 -0
- package/src/renderers/MonacoControlRenderer.impl.tsx +351 -0
- package/src/renderers/MonacoControlRenderer.tsx +24 -0
- package/src/renderers/RactiveTemplateLayoutRenderer.tsx +172 -0
- package/src/renderers/SeparatorRenderer.tsx +55 -0
- package/src/renderers/SlotRenderer.tsx +34 -0
- package/src/renderers/SpacerRenderer.tsx +69 -0
- package/src/renderers/SplitLayoutRenderer.tsx +220 -0
- package/src/renderers/TemplateLayoutRenderer.tsx +394 -0
- package/src/renderers/TemplateRenderer.tsx +71 -0
- package/src/renderers/TsxTemplateLayoutRenderer.tsx +258 -0
- package/src/renderers/index.ts +14 -0
- package/src/renderers/templateEngines.tsx +100 -0
- package/src/util/actionContext.ts +29 -0
- package/src/util/additionalErrors.tsx +391 -0
- package/src/util/celEnvironment.ts +300 -0
- package/src/util/celTemplate.ts +267 -0
- package/src/util/childNames.ts +135 -0
- package/src/util/configNamespaces.ts +6 -0
- package/src/util/cron.ts +433 -0
- package/src/util/editorControls.ts +58 -0
- package/src/util/editorDiagnostics.ts +103 -0
- package/src/util/extendedControls.ts +34 -0
- package/src/util/extendedLocale.ts +67 -0
- package/src/util/fileFilterValue.ts +28 -0
- package/src/util/formContext.ts +74 -0
- package/src/util/gridColumns.ts +80 -0
- package/src/util/horizontalLayout.ts +59 -0
- package/src/util/i18nDefaults.ts +80 -0
- package/src/util/interpolate.ts +218 -0
- package/src/util/labelFilterValue.ts +49 -0
- package/src/util/lazyControl.tsx +66 -0
- package/src/util/lazyTemplate.tsx +110 -0
- package/src/util/markdown.tsx +345 -0
- package/src/util/markdownEscape.ts +29 -0
- package/src/util/markup.ts +144 -0
- package/src/util/maskControls.ts +6 -0
- package/src/util/templateLang.ts +145 -0
- package/src/util/templateUrls.ts +274 -0
- package/src/util/urlPolicy.ts +115 -0
- package/src/util/useCronPicker.ts +102 -0
- package/src/util/useDurationControl.ts +272 -0
- package/src/util/useEditorAppearance.ts +86 -0
- package/src/util/useExtendedTranslator.ts +25 -0
- package/src/util/useMonacoShadowStyles.ts +47 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useDynamicElements,
|
|
3
|
+
useDynamicExternal,
|
|
4
|
+
} from '@chobantonov/jsonforms-react-renderer-common/dynamic/DynamicUiProvider';
|
|
5
|
+
import {
|
|
6
|
+
LayoutProps,
|
|
7
|
+
RankedTester,
|
|
8
|
+
rankWith,
|
|
9
|
+
UISchemaElement,
|
|
10
|
+
uiTypeIs,
|
|
11
|
+
} from '@jsonforms/core';
|
|
12
|
+
import { JsonFormsDispatch, useJsonForms } from '@jsonforms/react';
|
|
13
|
+
import React, { useEffect, useMemo } from 'react';
|
|
14
|
+
import { proxy } from 'valtio';
|
|
15
|
+
import { resolveChildNames } from '../util/childNames';
|
|
16
|
+
import { buildFormContext } from '../util/formContext';
|
|
17
|
+
import {
|
|
18
|
+
TemplateLayoutElement,
|
|
19
|
+
resolveTemplateEngine,
|
|
20
|
+
} from '../util/templateLang';
|
|
21
|
+
import { TemplateDiagnostic } from './templateEngines';
|
|
22
|
+
import { ElementRender } from '../components/elementRender';
|
|
23
|
+
import { createLazyTemplate } from '../util/lazyTemplate';
|
|
24
|
+
import { UrlPolicy, resolveUrlPolicy } from '../util/urlPolicy';
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
The JSX engine is behind its own chunk: `DynamicJSXRenderer` imports Sucrase
|
|
28
|
+
at module scope, and a form with no jsx template should not download a
|
|
29
|
+
compiler. Only the marker symbol is imported eagerly, which is why it lives
|
|
30
|
+
in a module of its own.
|
|
31
|
+
*/
|
|
32
|
+
const DynamicJSXRenderer = createLazyTemplate<{
|
|
33
|
+
jsxTemplate: string;
|
|
34
|
+
props: Record<string, unknown>;
|
|
35
|
+
urlPolicy: UrlPolicy;
|
|
36
|
+
}>(async () => (await import('../components/DynamicJSXRenderer')).default, {
|
|
37
|
+
loading: 'template.loading',
|
|
38
|
+
error: 'template.loadError',
|
|
39
|
+
renderError: 'template.renderError',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export interface TemplateLayoutProps extends LayoutProps {
|
|
43
|
+
uischema: TemplateLayoutElement;
|
|
44
|
+
components?: Record<string, React.ComponentType<any>>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type RenderableElementProps = Pick<
|
|
48
|
+
TemplateLayoutProps,
|
|
49
|
+
'schema' | 'enabled' | 'renderers' | 'cells'
|
|
50
|
+
> & {
|
|
51
|
+
path?: string;
|
|
52
|
+
uischema: UISchemaElement;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Default tester for a template layout.
|
|
57
|
+
* @type {RankedTester}
|
|
58
|
+
*/
|
|
59
|
+
export const templateRendererTester: RankedTester = rankWith(
|
|
60
|
+
1,
|
|
61
|
+
uiTypeIs('TemplateLayout'),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Default renderer for a template layout.
|
|
66
|
+
*/
|
|
67
|
+
const TemplateElementControl = React.memo(function TemplateElementControl(
|
|
68
|
+
props: RenderableElementProps,
|
|
69
|
+
) {
|
|
70
|
+
return <JsonFormsDispatch {...props} />;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const TemplateLayoutRenderer = ({
|
|
74
|
+
path,
|
|
75
|
+
enabled,
|
|
76
|
+
schema,
|
|
77
|
+
uischema,
|
|
78
|
+
visible,
|
|
79
|
+
renderers,
|
|
80
|
+
cells,
|
|
81
|
+
config,
|
|
82
|
+
components = {}, // Default to an empty object
|
|
83
|
+
}: TemplateLayoutProps) => {
|
|
84
|
+
/*
|
|
85
|
+
The `lang: "jsx"` profile. It compiles the template with Sucrase and
|
|
86
|
+
evaluates it through `new Function`, which the portable contract calls
|
|
87
|
+
string evaluation - so it runs only when the host has permitted it:
|
|
88
|
+
"String evaluation requires
|
|
89
|
+
jsonformsExtended.security.allowScriptEvaluation=true."
|
|
90
|
+
|
|
91
|
+
Reported rather than silently skipped, because a blank region where a
|
|
92
|
+
template should be is indistinguishable from a broken template.
|
|
93
|
+
*/
|
|
94
|
+
const engine = resolveTemplateEngine(uischema, config);
|
|
95
|
+
|
|
96
|
+
const template = uischema.template;
|
|
97
|
+
const effectiveChildren = useDynamicElements(
|
|
98
|
+
uischema.elements ?? [],
|
|
99
|
+
path ?? '',
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const { names: childNames, diagnostics: nameDiagnostics } = useMemo(
|
|
103
|
+
() => resolveChildNames(uischema.elements),
|
|
104
|
+
[uischema.elements],
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
for (const diagnostic of nameDiagnostics) {
|
|
109
|
+
// oxlint-disable-next-line no-console
|
|
110
|
+
console.warn(diagnostic);
|
|
111
|
+
}
|
|
112
|
+
}, [nameDiagnostics]);
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
The array a template receives as `elements`.
|
|
116
|
+
|
|
117
|
+
Its items are the **elements themselves**, not wrappers. A template may
|
|
118
|
+
render the whole array - `{elements}` mounts every child in order - so an
|
|
119
|
+
item has to be something the JSX engine's `createElement` can process,
|
|
120
|
+
which means the object carrying `[ElementRender]`. Returning
|
|
121
|
+
`{ element, name }` here instead made `{elements}` throw "Objects are not
|
|
122
|
+
valid as a React child", and the name belongs beside the array anyway
|
|
123
|
+
because `childNames` already holds it positionally.
|
|
124
|
+
*/
|
|
125
|
+
const namedElements = useMemo(() => {
|
|
126
|
+
const elements = effectiveChildren;
|
|
127
|
+
|
|
128
|
+
return elements.map((element, index) => {
|
|
129
|
+
/*
|
|
130
|
+
The name is computed, never written back. This used to do
|
|
131
|
+
`element.name = index.toString()`, which mutates the **authored** UI
|
|
132
|
+
schema - section 22 forbids that, and because JSON Forms holds one
|
|
133
|
+
element object, a second form sharing the same schema inherited the
|
|
134
|
+
first one's generated names.
|
|
135
|
+
*/
|
|
136
|
+
const name = childNames[index];
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
A child with no resolvable name is unaddressable, not unrenderable: it
|
|
140
|
+
still has a position, so `{elements}` must mount it. The renderable is
|
|
141
|
+
therefore keyed by something unique per position, and only a real name
|
|
142
|
+
reaches `elementsByName` below.
|
|
143
|
+
*/
|
|
144
|
+
const key = name ?? `\u0000unnamed:${index}`;
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
...element,
|
|
148
|
+
[ElementRender]: function TemplateElement() {
|
|
149
|
+
return (
|
|
150
|
+
<TemplateElementControl
|
|
151
|
+
key={key}
|
|
152
|
+
path={path}
|
|
153
|
+
schema={schema}
|
|
154
|
+
enabled={enabled}
|
|
155
|
+
renderers={renderers}
|
|
156
|
+
cells={cells}
|
|
157
|
+
uischema={element}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}, [cells, enabled, renderers, schema, effectiveChildren, childNames, path]);
|
|
164
|
+
|
|
165
|
+
const elementsByName = useMemo(() => {
|
|
166
|
+
const map: Record<string, any> = {};
|
|
167
|
+
namedElements.forEach((element, index) => {
|
|
168
|
+
const name = childNames[index];
|
|
169
|
+
if (name !== undefined) {
|
|
170
|
+
map[name] = element;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return map;
|
|
174
|
+
}, [namedElements, childNames]);
|
|
175
|
+
|
|
176
|
+
const proxyElements = useMemo(() => {
|
|
177
|
+
return new Proxy(namedElements, {
|
|
178
|
+
get(target, prop: string | symbol) {
|
|
179
|
+
if (typeof prop === 'string' && elementsByName[prop]) {
|
|
180
|
+
return elementsByName[prop];
|
|
181
|
+
}
|
|
182
|
+
return Reflect.get(target, prop);
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}, [namedElements, elementsByName]);
|
|
186
|
+
|
|
187
|
+
const ctx = useJsonForms();
|
|
188
|
+
const external = useDynamicExternal();
|
|
189
|
+
|
|
190
|
+
// Create a stable proxy that gets updated with new data
|
|
191
|
+
const [{ dataProxy, errorsProxy, additionalErrorsProxy }] = React.useState(
|
|
192
|
+
() => {
|
|
193
|
+
const dataProxy = proxy({ __val__: ctx.core?.data });
|
|
194
|
+
const errorsProxy = proxy({ __val__: ctx.core?.errors });
|
|
195
|
+
const additionalErrorsProxy = proxy({
|
|
196
|
+
__val__: ctx.core?.additionalErrors,
|
|
197
|
+
});
|
|
198
|
+
return { dataProxy, errorsProxy, additionalErrorsProxy };
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// Update proxies efficiently
|
|
203
|
+
useEffect(() => {
|
|
204
|
+
const updateProxy = (proxyTarget: any, newValue: any) => {
|
|
205
|
+
if (newValue === null || newValue === undefined) {
|
|
206
|
+
proxyTarget.__val__ = newValue;
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (proxyTarget.__val__ === null || proxyTarget.__val__ === undefined) {
|
|
211
|
+
proxyTarget.__val__ = newValue;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const deepMerge = (target: any, source: any) => {
|
|
216
|
+
if (source === null || source === undefined) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (Array.isArray(source)) {
|
|
221
|
+
if (!Array.isArray(target)) {
|
|
222
|
+
// Replace with new array if target isn't an array
|
|
223
|
+
return source;
|
|
224
|
+
}
|
|
225
|
+
// For arrays, properly merge without initially truncating
|
|
226
|
+
source.forEach((item: any, index: number) => {
|
|
227
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
228
|
+
// For objects in arrays, preserve existing object if it exists and is an object
|
|
229
|
+
if (
|
|
230
|
+
!target[index] ||
|
|
231
|
+
typeof target[index] !== 'object' ||
|
|
232
|
+
Array.isArray(target[index])
|
|
233
|
+
) {
|
|
234
|
+
target[index] = {};
|
|
235
|
+
}
|
|
236
|
+
const result = deepMerge(target[index], item);
|
|
237
|
+
if (result !== undefined) {
|
|
238
|
+
target[index] = result;
|
|
239
|
+
}
|
|
240
|
+
} else if (Array.isArray(item)) {
|
|
241
|
+
// For nested arrays, preserve existing array if it exists and is an array
|
|
242
|
+
if (!Array.isArray(target[index])) {
|
|
243
|
+
target[index] = [];
|
|
244
|
+
}
|
|
245
|
+
const result = deepMerge(target[index], item);
|
|
246
|
+
if (result !== undefined) {
|
|
247
|
+
target[index] = result;
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
// For primitives, just assign
|
|
251
|
+
target[index] = item;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Remove extra items from target array to match source length
|
|
256
|
+
if (target.length > source.length) {
|
|
257
|
+
target.splice(source.length);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (typeof source === 'object' && !Array.isArray(source)) {
|
|
263
|
+
if (typeof target !== 'object' || Array.isArray(target)) {
|
|
264
|
+
// Replace with new object if target isn't an object
|
|
265
|
+
return source;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
Object.keys(source).forEach((key) => {
|
|
269
|
+
if (
|
|
270
|
+
source[key] &&
|
|
271
|
+
typeof source[key] === 'object' &&
|
|
272
|
+
!Array.isArray(source[key])
|
|
273
|
+
) {
|
|
274
|
+
// Preserve existing object if it exists and is an object (not array)
|
|
275
|
+
if (
|
|
276
|
+
!target[key] ||
|
|
277
|
+
typeof target[key] !== 'object' ||
|
|
278
|
+
Array.isArray(target[key])
|
|
279
|
+
) {
|
|
280
|
+
target[key] = {};
|
|
281
|
+
}
|
|
282
|
+
const result = deepMerge(target[key], source[key]);
|
|
283
|
+
if (result !== undefined) {
|
|
284
|
+
target[key] = result;
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
target[key] = source[key];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// For primitives, just return the new value
|
|
294
|
+
return source;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const result = deepMerge(proxyTarget.__val__, newValue);
|
|
298
|
+
if (result !== undefined) {
|
|
299
|
+
proxyTarget.__val__ = result;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
updateProxy(dataProxy, ctx.core?.data);
|
|
304
|
+
updateProxy(errorsProxy, ctx.core?.errors);
|
|
305
|
+
updateProxy(additionalErrorsProxy, ctx.core?.additionalErrors);
|
|
306
|
+
}, [
|
|
307
|
+
ctx.core?.data,
|
|
308
|
+
ctx.core?.errors,
|
|
309
|
+
ctx.core?.additionalErrors,
|
|
310
|
+
dataProxy,
|
|
311
|
+
errorsProxy,
|
|
312
|
+
additionalErrorsProxy,
|
|
313
|
+
]);
|
|
314
|
+
|
|
315
|
+
const rendererProps = useMemo(
|
|
316
|
+
() => ({
|
|
317
|
+
elements: proxyElements,
|
|
318
|
+
schema: schema,
|
|
319
|
+
uischema: uischema,
|
|
320
|
+
data: dataProxy,
|
|
321
|
+
errors: errorsProxy,
|
|
322
|
+
additionalErrors: additionalErrorsProxy,
|
|
323
|
+
translate: ctx.i18n?.translate,
|
|
324
|
+
locale: ctx.i18n?.locale,
|
|
325
|
+
// Section 13's `context (extended FormContext)`, which this profile was
|
|
326
|
+
// not exposing at all. The flat `locale` stays for templates using it.
|
|
327
|
+
context: buildFormContext({
|
|
328
|
+
ctx: ctx as any,
|
|
329
|
+
schema,
|
|
330
|
+
uischema,
|
|
331
|
+
external,
|
|
332
|
+
}),
|
|
333
|
+
// Pass the generic components prop to the renderer
|
|
334
|
+
...components,
|
|
335
|
+
}),
|
|
336
|
+
[
|
|
337
|
+
proxyElements,
|
|
338
|
+
schema,
|
|
339
|
+
uischema,
|
|
340
|
+
dataProxy,
|
|
341
|
+
errorsProxy,
|
|
342
|
+
additionalErrorsProxy,
|
|
343
|
+
ctx,
|
|
344
|
+
components,
|
|
345
|
+
external,
|
|
346
|
+
],
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
if (!visible) return null;
|
|
350
|
+
|
|
351
|
+
// Dynamically destructure based on passed props
|
|
352
|
+
const destructuringAssignment = `const { ${Object.keys(rendererProps)
|
|
353
|
+
.filter((k) => !['data', 'errors', 'additionalErrors'].includes(k)) // remove these
|
|
354
|
+
.join(', ')} } = props;`;
|
|
355
|
+
|
|
356
|
+
const jsxTemplate = `
|
|
357
|
+
function Template(props) {
|
|
358
|
+
${destructuringAssignment}
|
|
359
|
+
|
|
360
|
+
const data = useTrackedSnapshot(props.data);
|
|
361
|
+
const errors = useTrackedSnapshot(props.errors);
|
|
362
|
+
const additionalErrors = useTrackedSnapshot(props.additionalErrors);
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<React.Fragment>
|
|
366
|
+
${template.replace(/<\s*\/\s*React\.Fragment\s*>/g, '')}
|
|
367
|
+
</React.Fragment>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
`;
|
|
371
|
+
|
|
372
|
+
if (engine.diagnostic) {
|
|
373
|
+
return (
|
|
374
|
+
<TemplateDiagnostic
|
|
375
|
+
uischema={uischema}
|
|
376
|
+
config={config}
|
|
377
|
+
visible={visible}
|
|
378
|
+
/>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return (
|
|
383
|
+
<DynamicJSXRenderer
|
|
384
|
+
jsxTemplate={jsxTemplate}
|
|
385
|
+
props={rendererProps}
|
|
386
|
+
/*
|
|
387
|
+
Section 12's policy, resolved from the form's config and handed to the
|
|
388
|
+
pragma. A template's `href={data.url}` is a URL-bearing value like any
|
|
389
|
+
other; it was the one that had never been checked.
|
|
390
|
+
*/
|
|
391
|
+
urlPolicy={resolveUrlPolicy(config)}
|
|
392
|
+
/>
|
|
393
|
+
);
|
|
394
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LayoutProps,
|
|
3
|
+
RankedTester,
|
|
4
|
+
UISchemaElement,
|
|
5
|
+
and,
|
|
6
|
+
rankWith,
|
|
7
|
+
uiTypeIs,
|
|
8
|
+
} from '@jsonforms/core';
|
|
9
|
+
import {
|
|
10
|
+
JsonFormsDispatch,
|
|
11
|
+
useJsonForms,
|
|
12
|
+
withJsonFormsLayoutProps,
|
|
13
|
+
} from '@jsonforms/react';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import type { ExtendedUISchemaElement } from '../core/uiSchema';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Kept as an alias so existing imports still resolve; the type itself is the
|
|
19
|
+
* project-wide one, since `name` belongs to every element rather than to
|
|
20
|
+
* templates. See `core/uiSchema`.
|
|
21
|
+
*/
|
|
22
|
+
export type NamedElement = ExtendedUISchemaElement & {
|
|
23
|
+
elements?: UISchemaElement[];
|
|
24
|
+
};
|
|
25
|
+
export type TemplateSlots = Record<string, UISchemaElement>;
|
|
26
|
+
export const TemplateSlotsContext = React.createContext<TemplateSlots>({});
|
|
27
|
+
|
|
28
|
+
export const hasTemplateName = (uischema: UISchemaElement): boolean =>
|
|
29
|
+
typeof (uischema as NamedElement).name === 'string';
|
|
30
|
+
|
|
31
|
+
export const namedTemplateTester: RankedTester = rankWith(
|
|
32
|
+
2,
|
|
33
|
+
and(uiTypeIs('Template'), hasTemplateName),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const TemplateRendererComponent = (props: LayoutProps) => {
|
|
37
|
+
const context = useJsonForms();
|
|
38
|
+
const inherited = React.useContext(TemplateSlotsContext);
|
|
39
|
+
const element = props.uischema as NamedElement;
|
|
40
|
+
const slots = React.useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
...inherited,
|
|
43
|
+
...(element.elements ?? []).reduce<TemplateSlots>((result, child) => {
|
|
44
|
+
const name = (child as NamedElement).name;
|
|
45
|
+
if (name) result[name] = child;
|
|
46
|
+
return result;
|
|
47
|
+
}, {}),
|
|
48
|
+
}),
|
|
49
|
+
[element.elements, inherited],
|
|
50
|
+
);
|
|
51
|
+
const template = context.uischemas?.find(
|
|
52
|
+
(entry) => (entry.uischema as NamedElement).name === element.name,
|
|
53
|
+
)?.uischema;
|
|
54
|
+
if (!props.visible || !template) return null;
|
|
55
|
+
return (
|
|
56
|
+
<TemplateSlotsContext.Provider value={slots}>
|
|
57
|
+
<JsonFormsDispatch
|
|
58
|
+
schema={props.schema}
|
|
59
|
+
uischema={template}
|
|
60
|
+
path={props.path}
|
|
61
|
+
enabled={props.enabled}
|
|
62
|
+
renderers={props.renderers}
|
|
63
|
+
cells={props.cells}
|
|
64
|
+
/>
|
|
65
|
+
</TemplateSlotsContext.Provider>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const TemplateRenderer = withJsonFormsLayoutProps(
|
|
70
|
+
TemplateRendererComponent,
|
|
71
|
+
);
|