@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,328 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import {
|
|
3
|
+
JsonSchema,
|
|
4
|
+
LayoutProps,
|
|
5
|
+
RankedTester,
|
|
6
|
+
Resolve,
|
|
7
|
+
UISchemaElement,
|
|
8
|
+
composePaths,
|
|
9
|
+
rankWith,
|
|
10
|
+
toDataPath,
|
|
11
|
+
uiTypeIs,
|
|
12
|
+
} from '@jsonforms/core';
|
|
13
|
+
import { useJsonForms, withJsonFormsLayoutProps } from '@jsonforms/react';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { isAllowedImageUrl, resolveUrlPolicy } from '../util/urlPolicy';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `ImageView` - a display-only image, sourced directly or from the data.
|
|
19
|
+
*
|
|
20
|
+
* Section 13 puts `src`, `scope` and `alt` at the **top level** of the
|
|
21
|
+
* element, not in `options`. At least one of `src` and `scope` must be
|
|
22
|
+
* supplied, and the two are not interchangeable fallbacks for one another: a
|
|
23
|
+
* defined `src` wins outright, *including the empty string*, which is how an
|
|
24
|
+
* author says "no image here" without removing the element.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export const imageViewRendererTester: RankedTester = rankWith(
|
|
28
|
+
1,
|
|
29
|
+
uiTypeIs('ImageView'),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export type ImageViewElement = UISchemaElement & {
|
|
33
|
+
type: 'ImageView';
|
|
34
|
+
src?: string;
|
|
35
|
+
scope?: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Stable machine-readable codes, per section 21. */
|
|
40
|
+
export type ImageViewDiagnosticCode =
|
|
41
|
+
| 'image.noSource'
|
|
42
|
+
| 'image.missingAlt'
|
|
43
|
+
| 'image.scopeNotString'
|
|
44
|
+
| 'image.nonStringSource'
|
|
45
|
+
| 'image.urlRefused';
|
|
46
|
+
|
|
47
|
+
export interface ImageViewDiagnostic {
|
|
48
|
+
code: ImageViewDiagnosticCode;
|
|
49
|
+
severity: 'warning' | 'error';
|
|
50
|
+
message: string;
|
|
51
|
+
values?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether a scoped schema permits a string.
|
|
56
|
+
*
|
|
57
|
+
* An untyped schema permits anything, so it passes. A `type` that is an array
|
|
58
|
+
* passes if `string` is among its members - `["string", "null"]` is a normal
|
|
59
|
+
* way to spell an optional image.
|
|
60
|
+
*/
|
|
61
|
+
const permitsString = (schema: JsonSchema | undefined): boolean => {
|
|
62
|
+
if (schema === undefined) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const type = (schema as { type?: unknown }).type;
|
|
66
|
+
if (type === undefined) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return Array.isArray(type) ? type.includes('string') : type === 'string';
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export interface ResolvedImageView {
|
|
73
|
+
/** The URL to render, or undefined for "show no image". */
|
|
74
|
+
src?: string;
|
|
75
|
+
alt: string;
|
|
76
|
+
diagnostics: ImageViewDiagnostic[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The whole of section 13's source resolution, with no React in it.
|
|
81
|
+
*
|
|
82
|
+
* Kept separate from the component because the precedence is the part worth
|
|
83
|
+
* testing directly: which of `src` and `scope` wins, when an empty value is a
|
|
84
|
+
* deliberate blank rather than a missing one, and which failures are silent.
|
|
85
|
+
*/
|
|
86
|
+
export const resolveImageView = (
|
|
87
|
+
element: ImageViewElement,
|
|
88
|
+
args: {
|
|
89
|
+
schema?: JsonSchema;
|
|
90
|
+
rootSchema?: JsonSchema;
|
|
91
|
+
data?: unknown;
|
|
92
|
+
path?: string;
|
|
93
|
+
config?: unknown;
|
|
94
|
+
},
|
|
95
|
+
): ResolvedImageView => {
|
|
96
|
+
const diagnostics: ImageViewDiagnostic[] = [];
|
|
97
|
+
const src = element.src;
|
|
98
|
+
const altField = element.alt;
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
`alt` is required, and `alt: ""` is the documented way to mark an image
|
|
102
|
+
decorative. Defaulting a missing one to `""` silently declares every image
|
|
103
|
+
decorative, so the omission is reported - but the image still renders,
|
|
104
|
+
since withholding content over a missing annotation helps nobody.
|
|
105
|
+
*/
|
|
106
|
+
if (altField === undefined) {
|
|
107
|
+
diagnostics.push({
|
|
108
|
+
code: 'image.missingAlt',
|
|
109
|
+
severity: 'warning',
|
|
110
|
+
message:
|
|
111
|
+
'ImageView requires a top-level `alt`. Use `alt: ""` to mark the image decorative.',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const alt = altField ?? '';
|
|
115
|
+
|
|
116
|
+
const policy = resolveUrlPolicy(args.config);
|
|
117
|
+
const checkUrl = (candidate: string): string | undefined => {
|
|
118
|
+
if (candidate === '') {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!isAllowedImageUrl(candidate, policy)) {
|
|
122
|
+
diagnostics.push({
|
|
123
|
+
code: 'image.urlRefused',
|
|
124
|
+
severity: 'error',
|
|
125
|
+
message:
|
|
126
|
+
'The image source is blocked by the configured URL policy. Use an allowed image URL or adjust the image URL policy.',
|
|
127
|
+
});
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return candidate;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
A defined `src` is the source, full stop. The specification is explicit
|
|
135
|
+
that an invalid one "does not silently fall through to scope" - falling
|
|
136
|
+
through would show a different image than the one the author named.
|
|
137
|
+
*/
|
|
138
|
+
if (src !== undefined) {
|
|
139
|
+
return { src: checkUrl(src), alt, diagnostics };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (element.scope === undefined) {
|
|
143
|
+
diagnostics.push({
|
|
144
|
+
code: 'image.noSource',
|
|
145
|
+
severity: 'error',
|
|
146
|
+
message: 'ImageView requires at least one of `src` and `scope`.',
|
|
147
|
+
});
|
|
148
|
+
return { alt, diagnostics };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const scopedSchema = Resolve.schema(
|
|
152
|
+
args.schema ?? (args.rootSchema as JsonSchema),
|
|
153
|
+
element.scope,
|
|
154
|
+
args.rootSchema as JsonSchema,
|
|
155
|
+
);
|
|
156
|
+
if (!permitsString(scopedSchema)) {
|
|
157
|
+
diagnostics.push({
|
|
158
|
+
code: 'image.scopeNotString',
|
|
159
|
+
severity: 'error',
|
|
160
|
+
message: `The schema at ${element.scope} does not permit strings.`,
|
|
161
|
+
values: { scope: element.scope },
|
|
162
|
+
});
|
|
163
|
+
return { alt, diagnostics };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Control scope semantics, so an ImageView inside an array item resolves
|
|
167
|
+
// against that item rather than the root.
|
|
168
|
+
const dataPath = composePaths(args.path ?? '', toDataPath(element.scope));
|
|
169
|
+
const value = Resolve.data(args.data, dataPath);
|
|
170
|
+
|
|
171
|
+
// "Empty or missing source data displays no image" - not an error; the
|
|
172
|
+
// property simply has not been filled in yet.
|
|
173
|
+
if (value === undefined || value === null || value === '') {
|
|
174
|
+
return { alt, diagnostics };
|
|
175
|
+
}
|
|
176
|
+
if (typeof value !== 'string') {
|
|
177
|
+
diagnostics.push({
|
|
178
|
+
code: 'image.nonStringSource',
|
|
179
|
+
severity: 'error',
|
|
180
|
+
message: `The value at ${
|
|
181
|
+
element.scope
|
|
182
|
+
} is a ${typeof value}, not a URL string.`,
|
|
183
|
+
values: { scope: element.scope, type: typeof value },
|
|
184
|
+
});
|
|
185
|
+
return { alt, diagnostics };
|
|
186
|
+
}
|
|
187
|
+
return { src: checkUrl(value), alt, diagnostics };
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const DIAGNOSTIC_STYLE: React.CSSProperties = {
|
|
191
|
+
border: '1px solid currentColor',
|
|
192
|
+
borderRadius: 4,
|
|
193
|
+
padding: '0.5rem 0.75rem',
|
|
194
|
+
boxSizing: 'border-box',
|
|
195
|
+
minWidth: 0,
|
|
196
|
+
maxWidth: '100%',
|
|
197
|
+
display: 'flex',
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
gap: '0.5rem',
|
|
200
|
+
overflowWrap: 'anywhere',
|
|
201
|
+
fontSize: '0.85rem',
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const ImageDiagnostic = ({
|
|
205
|
+
diagnostic,
|
|
206
|
+
}: {
|
|
207
|
+
diagnostic: ImageViewDiagnostic;
|
|
208
|
+
}) => {
|
|
209
|
+
const t = useI18n();
|
|
210
|
+
const [open, setOpen] = React.useState(false);
|
|
211
|
+
const id = React.useId();
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
role='alert'
|
|
215
|
+
data-image-diagnostic={diagnostic.code}
|
|
216
|
+
style={DIAGNOSTIC_STYLE}
|
|
217
|
+
>
|
|
218
|
+
<span
|
|
219
|
+
style={{ position: 'relative', display: 'inline-flex', flexShrink: 0 }}
|
|
220
|
+
onMouseEnter={() => setOpen(true)}
|
|
221
|
+
onMouseLeave={() => setOpen(false)}
|
|
222
|
+
>
|
|
223
|
+
<button
|
|
224
|
+
type='button'
|
|
225
|
+
aria-label={t('image.warningDetails')}
|
|
226
|
+
aria-describedby={open ? id : undefined}
|
|
227
|
+
onFocus={() => setOpen(true)}
|
|
228
|
+
onBlur={() => setOpen(false)}
|
|
229
|
+
onClick={() => setOpen(true)}
|
|
230
|
+
onKeyDown={(event) => {
|
|
231
|
+
if (event.key === 'Escape') setOpen(false);
|
|
232
|
+
}}
|
|
233
|
+
style={{
|
|
234
|
+
display: 'inline-flex',
|
|
235
|
+
padding: 0,
|
|
236
|
+
border: 0,
|
|
237
|
+
background: 'transparent',
|
|
238
|
+
color: 'inherit',
|
|
239
|
+
cursor: 'help',
|
|
240
|
+
}}
|
|
241
|
+
>
|
|
242
|
+
<svg
|
|
243
|
+
width='18'
|
|
244
|
+
height='18'
|
|
245
|
+
viewBox='0 0 24 24'
|
|
246
|
+
fill='none'
|
|
247
|
+
stroke='currentColor'
|
|
248
|
+
strokeWidth='1.75'
|
|
249
|
+
aria-hidden='true'
|
|
250
|
+
>
|
|
251
|
+
<path d='M12 3 2 21h20L12 3Z' />
|
|
252
|
+
<path d='M12 9v5' />
|
|
253
|
+
<circle cx='12' cy='17' r='.75' />
|
|
254
|
+
</svg>
|
|
255
|
+
</button>
|
|
256
|
+
{open && (
|
|
257
|
+
<span
|
|
258
|
+
id={id}
|
|
259
|
+
role='tooltip'
|
|
260
|
+
style={{
|
|
261
|
+
position: 'absolute',
|
|
262
|
+
top: '100%',
|
|
263
|
+
left: 0,
|
|
264
|
+
zIndex: 10,
|
|
265
|
+
width: 'min(22rem, 70vw)',
|
|
266
|
+
boxSizing: 'border-box',
|
|
267
|
+
padding: '0.5rem 0.75rem',
|
|
268
|
+
background: 'Canvas',
|
|
269
|
+
color: 'CanvasText',
|
|
270
|
+
border: '1px solid currentColor',
|
|
271
|
+
borderRadius: 4,
|
|
272
|
+
overflowWrap: 'anywhere',
|
|
273
|
+
fontWeight: 'normal',
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
{t(diagnostic.code, diagnostic.values)}
|
|
277
|
+
</span>
|
|
278
|
+
)}
|
|
279
|
+
</span>
|
|
280
|
+
<span>
|
|
281
|
+
{diagnostic.code === 'image.urlRefused'
|
|
282
|
+
? t('image.blocked')
|
|
283
|
+
: t('image.configurationWarning')}
|
|
284
|
+
</span>
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export const ImageViewRendererComponent = ({
|
|
290
|
+
config,
|
|
291
|
+
uischema,
|
|
292
|
+
schema,
|
|
293
|
+
path,
|
|
294
|
+
visible,
|
|
295
|
+
}: LayoutProps) => {
|
|
296
|
+
const ctx = useJsonForms();
|
|
297
|
+
const element = uischema as ImageViewElement;
|
|
298
|
+
const resolved = resolveImageView(element, {
|
|
299
|
+
schema,
|
|
300
|
+
rootSchema: ctx.core?.schema,
|
|
301
|
+
data: ctx.core?.data,
|
|
302
|
+
path,
|
|
303
|
+
config,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
if (visible === false) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<>
|
|
312
|
+
{resolved.src !== undefined && (
|
|
313
|
+
<img
|
|
314
|
+
src={resolved.src}
|
|
315
|
+
alt={resolved.alt}
|
|
316
|
+
style={{ maxWidth: '100%', height: 'auto' }}
|
|
317
|
+
/>
|
|
318
|
+
)}
|
|
319
|
+
{resolved.diagnostics.map((diagnostic) => (
|
|
320
|
+
<ImageDiagnostic key={diagnostic.code} diagnostic={diagnostic} />
|
|
321
|
+
))}
|
|
322
|
+
</>
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
export const ImageViewRenderer = withJsonFormsLayoutProps(
|
|
327
|
+
ImageViewRendererComponent,
|
|
328
|
+
);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LayoutProps,
|
|
3
|
+
RankedTester,
|
|
4
|
+
UISchemaElement,
|
|
5
|
+
deriveLabelForUISchemaElement,
|
|
6
|
+
rankWith,
|
|
7
|
+
uiTypeIs,
|
|
8
|
+
} from '@jsonforms/core';
|
|
9
|
+
import {
|
|
10
|
+
TranslateProps,
|
|
11
|
+
withJsonFormsLayoutProps,
|
|
12
|
+
withTranslateProps,
|
|
13
|
+
} from '@jsonforms/react';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { isAllowedUrl, resolveUrlPolicy } from '../util/urlPolicy';
|
|
16
|
+
|
|
17
|
+
export type LinkElement = UISchemaElement & {
|
|
18
|
+
type: 'Link';
|
|
19
|
+
label?: string;
|
|
20
|
+
href?: string;
|
|
21
|
+
target?: '_self' | '_blank' | '_parent' | '_top';
|
|
22
|
+
rel?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const linkRendererTester: RankedTester = rankWith(1, uiTypeIs('Link'));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `rel` for a link, given its target.
|
|
29
|
+
*
|
|
30
|
+
* `target="_blank"` hands the opened page a `window.opener` reference to this
|
|
31
|
+
* one unless `noopener` is set, which lets it navigate the form away. The
|
|
32
|
+
* specification makes `noopener` a MUST and `noreferrer` a SHOULD. An
|
|
33
|
+
* author-supplied `rel` is kept and these are added to it rather than
|
|
34
|
+
* replacing it.
|
|
35
|
+
*/
|
|
36
|
+
export const linkRel = (
|
|
37
|
+
target: string | undefined,
|
|
38
|
+
rel: string | undefined,
|
|
39
|
+
): string | undefined => {
|
|
40
|
+
const tokens = (rel ?? '').split(/\s+/).filter(Boolean);
|
|
41
|
+
if (target === '_blank') {
|
|
42
|
+
for (const required of ['noopener', 'noreferrer']) {
|
|
43
|
+
if (!tokens.includes(required)) {
|
|
44
|
+
tokens.push(required);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return tokens.length > 0 ? tokens.join(' ') : undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const LinkRendererComponent = ({
|
|
52
|
+
uischema,
|
|
53
|
+
visible,
|
|
54
|
+
config,
|
|
55
|
+
t,
|
|
56
|
+
}: LayoutProps & TranslateProps) => {
|
|
57
|
+
const element = uischema as LinkElement;
|
|
58
|
+
if (!visible) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
// A Link has no scope, so - like a Group or a Category - only an explicit
|
|
62
|
+
// `i18n` prefix can give it a translation key. Falling back to the href
|
|
63
|
+
// keeps an unlabelled link readable rather than rendering nothing.
|
|
64
|
+
const label =
|
|
65
|
+
deriveLabelForUISchemaElement(element, t) ?? element.label ?? element.href;
|
|
66
|
+
const href = element.href;
|
|
67
|
+
const navigable =
|
|
68
|
+
typeof href === 'string' &&
|
|
69
|
+
href !== '' &&
|
|
70
|
+
isAllowedUrl(href, resolveUrlPolicy(config));
|
|
71
|
+
|
|
72
|
+
if (!navigable) {
|
|
73
|
+
// Section 13: an empty href renders plain, non-navigating semantics rather
|
|
74
|
+
// than inventing a destination. A URL the policy refuses is treated the
|
|
75
|
+
// same way - the text stays visible, but it does not become a link.
|
|
76
|
+
return <span data-link-inert>{label}</span>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<a
|
|
81
|
+
href={href}
|
|
82
|
+
target={element.target}
|
|
83
|
+
rel={linkRel(element.target, element.rel)}
|
|
84
|
+
>
|
|
85
|
+
{label}
|
|
86
|
+
</a>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const LinkRenderer = withTranslateProps(
|
|
91
|
+
withJsonFormsLayoutProps(LinkRendererComponent),
|
|
92
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MarkdownProfile, renderMarkdown } from '../util/markdown';
|
|
3
|
+
import { UrlPolicy } from '../util/urlPolicy';
|
|
4
|
+
|
|
5
|
+
export interface MarkdownTextProps {
|
|
6
|
+
text: string;
|
|
7
|
+
profile: MarkdownProfile;
|
|
8
|
+
urlPolicy: UrlPolicy;
|
|
9
|
+
onRefusedUrl?: (href: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The half of the markup label that needs the parser.
|
|
14
|
+
*
|
|
15
|
+
* Split into its own module so `import('./MarkupLabelRenderer.impl')` gives
|
|
16
|
+
* the bundler a seam: a form with no Markdown label never downloads
|
|
17
|
+
* markdown-it.
|
|
18
|
+
*/
|
|
19
|
+
export const MarkdownText = ({
|
|
20
|
+
text,
|
|
21
|
+
profile,
|
|
22
|
+
urlPolicy,
|
|
23
|
+
onRefusedUrl,
|
|
24
|
+
}: MarkdownTextProps) => (
|
|
25
|
+
<>{renderMarkdown(text, { profile, urlPolicy, onRefusedUrl })}</>
|
|
26
|
+
);
|