@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,32 @@
|
|
|
1
|
+
import { ExtendedI18nKey } from './i18nDefaults';
|
|
2
|
+
/**
|
|
3
|
+
* Locale bundles for this package's **own** strings - the grid's "Add row",
|
|
4
|
+
* the editor's loading and maximize labels, the colour and duration prompts.
|
|
5
|
+
*
|
|
6
|
+
* `extendedI18nDefaults` is one table of English, so those stayed English
|
|
7
|
+
* however `i18n.locale` moved unless the form's catalog carried every key.
|
|
8
|
+
* The antd package has the same mechanism (`rendererLocale.ts`) over its own
|
|
9
|
+
* key space; the two are separate because neither package depends on the
|
|
10
|
+
* other, and each owns the keys it draws.
|
|
11
|
+
*
|
|
12
|
+
* The lookup is synchronous rather than a set of `import()` loaders: these
|
|
13
|
+
* strings are on screen as soon as a renderer mounts, so loading them
|
|
14
|
+
* asynchronously would show English and then swap it out.
|
|
15
|
+
*/
|
|
16
|
+
export type ExtendedLocaleCatalog = Partial<Record<ExtendedI18nKey, string>>;
|
|
17
|
+
/** `en` is present and empty on purpose: English *is* the defaults table. */
|
|
18
|
+
export declare const defaultExtendedLocales: Record<string, ExtendedLocaleCatalog>;
|
|
19
|
+
/** Replaces the supported set wholesale. */
|
|
20
|
+
export declare const setExtendedLocales: (next: Record<string, ExtendedLocaleCatalog>) => void;
|
|
21
|
+
export declare const getExtendedLocales: () => Record<string, ExtendedLocaleCatalog>;
|
|
22
|
+
/** Adds or replaces one language, leaving the others alone. */
|
|
23
|
+
export declare const registerExtendedLocale: (locale: string, catalog: ExtendedLocaleCatalog) => void;
|
|
24
|
+
/** The catalog for a locale, falling back to its language (`de-AT` -> `de`). */
|
|
25
|
+
export declare const resolveExtendedLocale: (locale: string | undefined) => ExtendedLocaleCatalog | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* What a key reads as before the form's own catalog is consulted.
|
|
28
|
+
*
|
|
29
|
+
* Handed to the translator as its *default message*, so the form's catalog
|
|
30
|
+
* still wins where it has the key.
|
|
31
|
+
*/
|
|
32
|
+
export declare const extendedDefault: (locale: string | undefined, key: ExtendedI18nKey) => string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { JsonSchema, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
/**
|
|
3
|
+
* The `context` binding every template profile exposes.
|
|
4
|
+
*
|
|
5
|
+
* Section 3 declares the shape, and section 13 says the Ractive profile
|
|
6
|
+
* "exposes data…, errors…, **context (extended FormContext)**, elements, and
|
|
7
|
+
* translate", adding that "context may expose additionalErrors and
|
|
8
|
+
* application capabilities".
|
|
9
|
+
*
|
|
10
|
+
* All three profiles used to pass something different and smaller - the JSX
|
|
11
|
+
* engine a flat `locale` and no `context` at all, Ractive a `context` holding
|
|
12
|
+
* only `{ locale }`. So `readonly` was unreachable from a template, which
|
|
13
|
+
* matters as soon as a template draws its own widget: **readonly and disabled
|
|
14
|
+
* are different states**, and a widget that wants to render as text rather
|
|
15
|
+
* than as a greyed-out input has to be able to tell them apart.
|
|
16
|
+
*/
|
|
17
|
+
export interface FormContext {
|
|
18
|
+
external?: Readonly<Record<string, unknown>>;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
config?: unknown;
|
|
21
|
+
readonly?: boolean;
|
|
22
|
+
locale?: string;
|
|
23
|
+
translate?: unknown;
|
|
24
|
+
data?: unknown;
|
|
25
|
+
schema?: JsonSchema;
|
|
26
|
+
uischema?: UISchemaElement;
|
|
27
|
+
errors?: unknown[];
|
|
28
|
+
additionalErrors?: unknown[];
|
|
29
|
+
fireActionEvent?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface FormContextSources {
|
|
32
|
+
external?: Readonly<Record<string, unknown>>;
|
|
33
|
+
/** `useJsonForms()`. */
|
|
34
|
+
ctx: {
|
|
35
|
+
core?: {
|
|
36
|
+
data?: unknown;
|
|
37
|
+
schema?: JsonSchema;
|
|
38
|
+
errors?: unknown[];
|
|
39
|
+
additionalErrors?: unknown[];
|
|
40
|
+
};
|
|
41
|
+
i18n?: {
|
|
42
|
+
locale?: string;
|
|
43
|
+
translate?: unknown;
|
|
44
|
+
};
|
|
45
|
+
readonly?: boolean;
|
|
46
|
+
config?: unknown;
|
|
47
|
+
};
|
|
48
|
+
/** The schema at this element's path, which is narrower than the root. */
|
|
49
|
+
schema?: JsonSchema;
|
|
50
|
+
uischema?: UISchemaElement;
|
|
51
|
+
/** The host's action handler, where one is registered. */
|
|
52
|
+
fireActionEvent?: unknown;
|
|
53
|
+
}
|
|
54
|
+
export declare const buildFormContext: ({ ctx, schema, uischema, fireActionEvent, external, }: FormContextSources) => FormContext;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ColDef, ColGroupDef } from 'ag-grid-community';
|
|
2
|
+
import type { JsonSchema } from '@jsonforms/core';
|
|
3
|
+
import { type TableColumnDefinition } from '@chobantonov/jsonforms-react-renderer-common/collections/tableColumns';
|
|
4
|
+
type GridColumn = ColDef | ColGroupDef;
|
|
5
|
+
export declare function resolveGridColumns(columns: ColDef[], portable: TableColumnDefinition[] | undefined, nativeDefinitions: GridColumn[] | undefined, items: JsonSchema | undefined, cellOptions: Record<string, Record<string, unknown>>, hideRequiredAsterisk: boolean): GridColumn[];
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export declare const HORIZONTAL_COLUMNS = 16;
|
|
3
|
+
export declare const isValidColumns: (value: unknown) => boolean;
|
|
4
|
+
/** Allocate direct, visible children without changing their UI schemas. */
|
|
5
|
+
export declare const horizontalLayoutWidths: (values: readonly unknown[], gap?: string) => {
|
|
6
|
+
row: number;
|
|
7
|
+
columns: number;
|
|
8
|
+
style: CSSProperties;
|
|
9
|
+
diagnostic: string | undefined;
|
|
10
|
+
}[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default messages for strings this package renders. Every one goes through the
|
|
3
|
+
* JSON Forms translator, so a host can override any of them per locale.
|
|
4
|
+
*/
|
|
5
|
+
export declare const extendedI18nDefaults: {
|
|
6
|
+
'array.addRow': string;
|
|
7
|
+
'array.removeSelected': string;
|
|
8
|
+
'grid.loading': string;
|
|
9
|
+
'grid.loadError': string;
|
|
10
|
+
'editor.loading': string;
|
|
11
|
+
'editor.loadError': string;
|
|
12
|
+
'editor.maximize': string;
|
|
13
|
+
'editor.restore': string;
|
|
14
|
+
'editor.invalidJson': string;
|
|
15
|
+
'editor.languageErrors': string;
|
|
16
|
+
'editor.languageError': string;
|
|
17
|
+
'editor.chooseColor': string;
|
|
18
|
+
'editor.chooseDuration': string;
|
|
19
|
+
'color.placeholder.hex': string;
|
|
20
|
+
'color.placeholder.hex3': string;
|
|
21
|
+
'color.placeholder.rgb': string;
|
|
22
|
+
'color.placeholder.hsb': string;
|
|
23
|
+
'color.hex3Transparency': string;
|
|
24
|
+
'additionalProperties.add': string;
|
|
25
|
+
'additionalProperties.addLabel': string;
|
|
26
|
+
'additionalProperties.addTo': string;
|
|
27
|
+
'additionalProperties.namePlaceholder': string;
|
|
28
|
+
'additionalProperties.rename': string;
|
|
29
|
+
'additionalProperties.renameNamed': string;
|
|
30
|
+
'additionalProperties.save': string;
|
|
31
|
+
'additionalProperties.cancel': string;
|
|
32
|
+
'additionalProperties.delete': string;
|
|
33
|
+
'additionalProperties.nameTaken': string;
|
|
34
|
+
'additionalProperties.nameInvalid': string;
|
|
35
|
+
'additionalProperties.namePattern': string;
|
|
36
|
+
'template.loading': string;
|
|
37
|
+
'template.loadError': string;
|
|
38
|
+
'template.renderError': string;
|
|
39
|
+
'editor.ariaLabel': string;
|
|
40
|
+
'duration.invalid': string;
|
|
41
|
+
'markup.markdownDisabled': string;
|
|
42
|
+
'markup.unsupported': string;
|
|
43
|
+
'markup.interpolationFailed': string;
|
|
44
|
+
};
|
|
45
|
+
export type ExtendedI18nKey = keyof typeof extendedI18nDefaults;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The template grammar, and what an expression is allowed to see.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately free of any CEL import. Splitting a template is pure string
|
|
5
|
+
* work, and doing it here means two things: the grammar can be tested without
|
|
6
|
+
* the evaluator, and a label whose text turns out to contain **no**
|
|
7
|
+
* placeholders never downloads one.
|
|
8
|
+
*/
|
|
9
|
+
/** One piece of a split template. */
|
|
10
|
+
export type TemplateSegment = {
|
|
11
|
+
kind: 'literal';
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'expression';
|
|
15
|
+
source: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Splits a template into literals and expressions.
|
|
19
|
+
*
|
|
20
|
+
* The grammar is section 11.4's, unchanged, because a second convention in
|
|
21
|
+
* the same document is the thing worth avoiding: a **single** `{` opens a
|
|
22
|
+
* placeholder, `{{` emits a literal `{`, and `}}` emits a literal `}`.
|
|
23
|
+
*
|
|
24
|
+
* This is inverted from Mustache and friends, so `{{data.firstName}}` is
|
|
25
|
+
* literal text rather than a binding. That trap is the reason
|
|
26
|
+
* {@link looksLikeMustache} exists.
|
|
27
|
+
*
|
|
28
|
+
* The scan is quote-aware: a `}` inside a quoted string does not close the
|
|
29
|
+
* placeholder, so `{data.m['}']}` is one expression rather than a truncated
|
|
30
|
+
* one. Quotes are tracked only to find the closing brace - what is inside
|
|
31
|
+
* them is the evaluator's business.
|
|
32
|
+
*
|
|
33
|
+
* An unterminated placeholder is returned as a literal, so the author sees
|
|
34
|
+
* their source text rather than losing the rest of the line.
|
|
35
|
+
*/
|
|
36
|
+
export declare const splitTemplate: (text: string) => TemplateSegment[];
|
|
37
|
+
/** Whether a split template has anything to evaluate. */
|
|
38
|
+
export declare const hasExpressions: (segments: TemplateSegment[]) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the text looks like it expected Mustache's convention.
|
|
41
|
+
*
|
|
42
|
+
* `{{data.firstName}}` splits into the literal `{data.firstName}` - correct
|
|
43
|
+
* per the grammar, and almost certainly not what the author meant. Section
|
|
44
|
+
* 11.4 asks an implementation to warn about exactly this shape.
|
|
45
|
+
*/
|
|
46
|
+
export declare const looksLikeMustache: (text: string) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the host permits an expression to read the form's data.
|
|
49
|
+
*
|
|
50
|
+
* Section 12's gate, and it defaults **closed** like the others - unlike the
|
|
51
|
+
* Markdown gate, which opens a parser rather than a reader. What this opens
|
|
52
|
+
* is exactly what section 11 calls dynamic resolution: values out of the
|
|
53
|
+
* form's data and the host's context, into the UI.
|
|
54
|
+
*/
|
|
55
|
+
export declare const dynamicValuesEnabled: (config: unknown) => boolean;
|
|
56
|
+
/** The namespaces that only dynamic resolution may expose. */
|
|
57
|
+
export declare const DYNAMIC_NAMESPACES: string[];
|
|
58
|
+
export interface NamespaceScopeInput {
|
|
59
|
+
data?: unknown;
|
|
60
|
+
item?: unknown;
|
|
61
|
+
locale?: string;
|
|
62
|
+
config?: unknown;
|
|
63
|
+
context?: unknown;
|
|
64
|
+
dynamicAllowed: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* What a **`textParams` value** may reference.
|
|
68
|
+
*
|
|
69
|
+
* This is the only place the form's data is reachable. A parameter's value is
|
|
70
|
+
* the right-hand side of a declaration the author wrote in the UI schema, and
|
|
71
|
+
* the UI schema is where knowledge of the data model belongs.
|
|
72
|
+
*
|
|
73
|
+
* The four namespaces appear only when the gate is open, so a parameter that
|
|
74
|
+
* reaches for `data` while it is shut fails with an unknown identifier rather
|
|
75
|
+
* than quietly resolving.
|
|
76
|
+
*/
|
|
77
|
+
export declare const buildNamespaceScope: (input: NamespaceScopeInput) => Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Names the text scope keeps for itself.
|
|
80
|
+
*
|
|
81
|
+
* `locale` lets a message choose a word by language without a parameter for
|
|
82
|
+
* it. A `textParams` entry of the same name would silently do nothing, so it
|
|
83
|
+
* is reported rather than dropped - see {@link reservedParamNames}.
|
|
84
|
+
*/
|
|
85
|
+
export declare const RESERVED_TEXT_NAMES: string[];
|
|
86
|
+
/**
|
|
87
|
+
* What the **text** may reference: the declared parameters, and nothing else.
|
|
88
|
+
*
|
|
89
|
+
* Deliberately **not** the namespaces. A translated string that reads
|
|
90
|
+
* `{data.customerName}` couples the catalog to the schema: renaming a field
|
|
91
|
+
* invalidates every translation of every language, and a translator is shown
|
|
92
|
+
* a data path instead of a name for the thing. Restricting the text to
|
|
93
|
+
* declared parameters is what makes `You are subscribed to {product}.` the
|
|
94
|
+
* unit of translation.
|
|
95
|
+
*
|
|
96
|
+
* Expressions still work here, over those parameters. That is what keeps a
|
|
97
|
+
* plural in the catalog where each language can write its own
|
|
98
|
+
* (`{seats == 1 ? "seat" : "seats"}`) rather than in the UI schema where only
|
|
99
|
+
* the authoring language can.
|
|
100
|
+
*/
|
|
101
|
+
export declare const buildTextScope: (params: Record<string, unknown>, locale: string | undefined) => Record<string, unknown>;
|
|
102
|
+
/** `textParams` entries that collide with a reserved name, so they can be reported. */
|
|
103
|
+
export declare const reservedParamNames: (textParams: Record<string, unknown> | undefined) => string[];
|
|
104
|
+
/** Whether an element asks for interpolation at all. */
|
|
105
|
+
export declare const wantsInterpolation: (options: Record<string, unknown> | undefined) => boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Resolve the authored Label text without exposing data beyond the Label's own gates. */
|
|
2
|
+
export declare const labelFilterValue: (label: any, data: unknown, item: unknown, config: unknown, locale?: string, translate?: (key: string, fallback?: string) => string | undefined) => string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ControlProps } from '@jsonforms/core';
|
|
3
|
+
import { EditorRendererComponents } from '../components/editorRendererTypes';
|
|
4
|
+
import { ExtendedI18nKey } from './i18nDefaults';
|
|
5
|
+
/**
|
|
6
|
+
* Suspense has no error path of its own, so a boundary catches import
|
|
7
|
+
* failures.
|
|
8
|
+
*
|
|
9
|
+
* Exported because every lazily-loaded renderer needs one, not only the ones
|
|
10
|
+
* built by `createLazyControl`. Without it a chunk that fails to arrive - an
|
|
11
|
+
* offline reload, a stale hash after a deploy - throws past Suspense and
|
|
12
|
+
* takes the whole form down rather than degrading to whatever the caller
|
|
13
|
+
* chose as a fallback.
|
|
14
|
+
*/
|
|
15
|
+
export declare class LoadBoundary extends React.Component<React.PropsWithChildren<{
|
|
16
|
+
fallback: React.ReactNode;
|
|
17
|
+
}>, {
|
|
18
|
+
failed: boolean;
|
|
19
|
+
}> {
|
|
20
|
+
state: {
|
|
21
|
+
failed: boolean;
|
|
22
|
+
};
|
|
23
|
+
static getDerivedStateFromError(): {
|
|
24
|
+
failed: boolean;
|
|
25
|
+
};
|
|
26
|
+
render(): React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Defers a renderer's heavy dependency until the control is actually rendered.
|
|
30
|
+
* The import lives behind React.lazy so bundlers split it into its own chunk -
|
|
31
|
+
* a form with no code editor or data grid never downloads them.
|
|
32
|
+
*/
|
|
33
|
+
export declare const createLazyControl: (load: () => Promise<React.ComponentType<ControlProps>>, components: EditorRendererComponents, labels: {
|
|
34
|
+
loading: ExtendedI18nKey;
|
|
35
|
+
error: ExtendedI18nKey;
|
|
36
|
+
}) => React.ComponentType<ControlProps>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExtendedI18nKey } from './i18nDefaults';
|
|
3
|
+
/**
|
|
4
|
+
* Translation **keys**, not text.
|
|
5
|
+
*
|
|
6
|
+
* The labels are chosen where `createLazyTemplate` is called, which is module
|
|
7
|
+
* scope - no hook can run there, and text fixed at module scope is text that
|
|
8
|
+
* cannot follow the locale. Naming the keys here and translating them inside
|
|
9
|
+
* the component is what lets these three strings be translated at all.
|
|
10
|
+
*/
|
|
11
|
+
export interface LazyTemplateLabels {
|
|
12
|
+
loading: ExtendedI18nKey;
|
|
13
|
+
/** Shown when the engine's chunk itself could not be fetched. */
|
|
14
|
+
error: ExtendedI18nKey;
|
|
15
|
+
/** Shown when the engine loaded and the template then threw. */
|
|
16
|
+
renderError?: ExtendedI18nKey;
|
|
17
|
+
}
|
|
18
|
+
export declare const createLazyTemplate: <P extends object>(load: () => Promise<React.ComponentType<P>>, labels: LazyTemplateLabels) => React.ComponentType<P>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type MarkdownIt as MarkdownItInstance } from 'markdown-it';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { UrlPolicy } from './urlPolicy';
|
|
4
|
+
export { escapeMarkdown } from './markdownEscape';
|
|
5
|
+
/**
|
|
6
|
+
* The Markdown profiles of specification section 10, rendered to React.
|
|
7
|
+
*
|
|
8
|
+
* ## Why a token stream rather than HTML
|
|
9
|
+
*
|
|
10
|
+
* Section 10 requires that Markdown output be sanitized **after** parsing.
|
|
11
|
+
* `md.render()` returns an HTML string, which would have to be injected with
|
|
12
|
+
* `dangerouslySetInnerHTML` and therefore sanitized first by some other
|
|
13
|
+
* library. `md.parse()` returns a token stream instead, and walking that into
|
|
14
|
+
* React elements means **no HTML string is ever produced**: there is nothing
|
|
15
|
+
* unsanitized to sanitize, no sanitizer in the dependency chain to be
|
|
16
|
+
* misconfigured, and the set of elements that can reach the page is the
|
|
17
|
+
* allowlist below rather than whatever the sanitizer was talked into.
|
|
18
|
+
*
|
|
19
|
+
* ## Why rules are disabled rather than output filtered
|
|
20
|
+
*
|
|
21
|
+
* Basic excludes headings, images, tables, blockquotes and fenced code.
|
|
22
|
+
* Disabling the **rule** means `# Title` renders as the literal text
|
|
23
|
+
* `# Title`, which is what a profile that excludes headings should do.
|
|
24
|
+
* Filtering the output instead would consume the `#` and silently promote the
|
|
25
|
+
* text to a paragraph, leaving an author to wonder where their heading went.
|
|
26
|
+
*
|
|
27
|
+
* Disabling a rule is not the same as escaping the text, and one case shows
|
|
28
|
+
* it: with `fence` off, a ``` block is claimed by the inline backtick rule
|
|
29
|
+
* and comes out as inline code. Nothing is lost - the code is still the
|
|
30
|
+
* content - but the construct degrades to its nearest supported neighbour
|
|
31
|
+
* rather than to literal backticks.
|
|
32
|
+
*
|
|
33
|
+
* `html: false` means the parser never emits a raw-HTML token at all, so the
|
|
34
|
+
* excluded raw HTML is excluded by construction rather than by a later pass.
|
|
35
|
+
*/
|
|
36
|
+
export type MarkdownProfile = 'basic' | 'extended';
|
|
37
|
+
/**
|
|
38
|
+
* `linkify` is off: turning a bare URL into a link is in neither profile, and
|
|
39
|
+
* it would route text the author never marked up through the URL policy.
|
|
40
|
+
*
|
|
41
|
+
* `breaks` is off because a single newline is not a line break in Markdown;
|
|
42
|
+
* the profile's "line breaks" are the two-space and backslash forms, which
|
|
43
|
+
* `hardbreak` carries.
|
|
44
|
+
*/
|
|
45
|
+
export declare const markdownParser: (profile?: MarkdownProfile) => MarkdownItInstance;
|
|
46
|
+
export interface MarkdownContext {
|
|
47
|
+
profile?: MarkdownProfile;
|
|
48
|
+
urlPolicy?: UrlPolicy;
|
|
49
|
+
/** Called for a link the policy refuses, so the caller can diagnose it. */
|
|
50
|
+
onRefusedUrl?: (href: string) => void;
|
|
51
|
+
}
|
|
52
|
+
/** Parses and renders, in the requested profile. */
|
|
53
|
+
export declare const renderMarkdown: (markdown: string, context?: MarkdownContext) => React.ReactNode[];
|
|
54
|
+
/** Visible text using the same Markdown profile as the renderer. */
|
|
55
|
+
export declare const markdownPlainText: (source: string, profile: MarkdownProfile) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escaping a substituted value so it cannot introduce Markdown.
|
|
3
|
+
*
|
|
4
|
+
* A module of its own, with no dependencies, because of **where** it is
|
|
5
|
+
* needed. The interpolation path has to escape values before handing them to
|
|
6
|
+
* the parser, but a label that interpolates without asking for Markdown must
|
|
7
|
+
* not download a parser. Leaving this in `markdown.tsx` - which imports
|
|
8
|
+
* markdown-it - would have put the parser in the interpolation chunk, which
|
|
9
|
+
* is exactly the coupling the lazy split exists to avoid.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Escapes every character that could start a Markdown construct.
|
|
13
|
+
*
|
|
14
|
+
* Section 9: "Markdown substitutions are escaped before parsing." The order
|
|
15
|
+
* is interpolate -> escape -> parse, and swapping the last two makes the
|
|
16
|
+
* escaping pointless - by then the link already exists.
|
|
17
|
+
*
|
|
18
|
+
* Applied to **substituted values only**, never to the whole template: the
|
|
19
|
+
* author's own `**bold**` in the surrounding text has to keep working, and
|
|
20
|
+
* escaping the finished string would kill it.
|
|
21
|
+
*
|
|
22
|
+
* `<` and `>` are deliberately absent. Raw HTML is not a Markdown construct
|
|
23
|
+
* here - the parser runs with `html: false`, and the result is rendered as
|
|
24
|
+
* React text nodes, which React escapes. Adding them would put visible
|
|
25
|
+
* backslashes in front of ordinary punctuation for no gain.
|
|
26
|
+
*/
|
|
27
|
+
export declare const escapeMarkdown: (text: string) => string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolving what a text element should do with its text.
|
|
3
|
+
*
|
|
4
|
+
* Two independent requests, and either one is enough to take the element away
|
|
5
|
+
* from the plain renderer:
|
|
6
|
+
*
|
|
7
|
+
* - `options.markup: "markdown"` asks for the restricted Markdown profile.
|
|
8
|
+
* - `options.interpolate: true` asks for message formatting.
|
|
9
|
+
*
|
|
10
|
+
* With neither, the ordinary label renderer keeps the element - there is
|
|
11
|
+
* nothing here it would do differently, and replacing it would change how
|
|
12
|
+
* every existing form draws its labels.
|
|
13
|
+
*/
|
|
14
|
+
/** The `markup` values the model defines. */
|
|
15
|
+
export type Markup = 'plain' | 'markdown';
|
|
16
|
+
export type MarkupDiagnostic =
|
|
17
|
+
/** `markup: "markdown"` while the host has the profile switched off. */
|
|
18
|
+
'markdownDisabled'
|
|
19
|
+
/** A `markup` value this implementation does not know. */
|
|
20
|
+
| 'markupUnsupported';
|
|
21
|
+
export interface MarkupRequest {
|
|
22
|
+
/** Whether Markdown should actually be parsed. */
|
|
23
|
+
markdown: boolean;
|
|
24
|
+
/** Whether the text should be run through message formatting. */
|
|
25
|
+
interpolate: boolean;
|
|
26
|
+
/** Wrap the result in the UI library's own typography components. */
|
|
27
|
+
typography: boolean;
|
|
28
|
+
/** Set when the request cannot be honoured; see `MarkupDiagnostic`. */
|
|
29
|
+
diagnostic?: MarkupDiagnostic;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether the host permits Markdown at all.
|
|
33
|
+
*
|
|
34
|
+
* Defaults to **true**, which the recommended configuration states and which
|
|
35
|
+
* differs from the other extension gates. Those gate something that executes;
|
|
36
|
+
* this gates a parser that cannot execute anything, and the profile already
|
|
37
|
+
* excludes raw HTML, images and embedded content.
|
|
38
|
+
*/
|
|
39
|
+
export declare const markdownEnabled: (config: unknown) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Which Markdown profile the host has selected.
|
|
42
|
+
*
|
|
43
|
+
* `basic` unless the host says otherwise, and an unrecognized value falls back
|
|
44
|
+
* to `basic` rather than being reported: a profile name is a host setting, not
|
|
45
|
+
* an authored one, so there is no author on the page to tell about it, and the
|
|
46
|
+
* safe direction for an unknown one is the smaller grammar.
|
|
47
|
+
*/
|
|
48
|
+
export declare const markdownProfile: (config: unknown) => "basic" | "extended";
|
|
49
|
+
/**
|
|
50
|
+
* Whether to wrap rendered text in the UI library's typography components.
|
|
51
|
+
*
|
|
52
|
+
* Element option first, then the namespaced default, then **true**. It is
|
|
53
|
+
* switchable because those components carry their own margins, which can
|
|
54
|
+
* fight a form's own spacing - the same collision a non-zero column gap
|
|
55
|
+
* produces.
|
|
56
|
+
*/
|
|
57
|
+
export declare const typographyEnabled: (options: Record<string, unknown> | undefined, config: unknown) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* What this element is asking for, and whether it can have it.
|
|
60
|
+
*
|
|
61
|
+
* A refused Markdown request keeps `interpolate`: the two are independent, and
|
|
62
|
+
* switching the profile off is not a reason to stop formatting a message.
|
|
63
|
+
*/
|
|
64
|
+
export declare const resolveMarkup: (options: Record<string, unknown> | undefined, config: unknown) => MarkupRequest;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the extended renderer should take this element at all.
|
|
67
|
+
*
|
|
68
|
+
* Deliberately reads the **requested** markup rather than the resolved one: an
|
|
69
|
+
* element asking for Markdown that the host has switched off still belongs
|
|
70
|
+
* here, because the refusal has to be reported. Leaving it to the plain
|
|
71
|
+
* renderer would render the source silently, which is the failure this
|
|
72
|
+
* diagnostic exists to prevent.
|
|
73
|
+
*/
|
|
74
|
+
export declare const wantsMarkup: (options: Record<string, unknown> | undefined) => boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Layout, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
import type { ExtendedUISchemaElement } from '../core/uiSchema';
|
|
3
|
+
/**
|
|
4
|
+
* Which engine renders a `TemplateLayout`, and whether it is allowed to run.
|
|
5
|
+
*
|
|
6
|
+
* "optional top-level `lang` selects the engine. Resolve the language from
|
|
7
|
+
* explicit lang, then the configured default, then ractive for the
|
|
8
|
+
* default web profile. Keep that existing config name."
|
|
9
|
+
*
|
|
10
|
+
* `defaultTemplateLang` is read from `config.jsonformsExtended`.
|
|
11
|
+
*/
|
|
12
|
+
/** The engines this renderer set implements. */
|
|
13
|
+
export declare const TEMPLATE_LANGS: readonly ["ractive", "jsx"];
|
|
14
|
+
export type TemplateLang = (typeof TEMPLATE_LANGS)[number];
|
|
15
|
+
/**
|
|
16
|
+
* A `TemplateLayout` element.
|
|
17
|
+
*
|
|
18
|
+
* `lang` is **not** narrowed to {@link TemplateLang}, and that is deliberate.
|
|
19
|
+
* The specification requires an unknown language to be *diagnosed* rather than
|
|
20
|
+
* refused - "unknown or unsupported languages must be diagnosed rather than
|
|
21
|
+
* interpreted as another engine" - and it names `vue` as a profile a web
|
|
22
|
+
* renderer set need not implement. A closed union would make the diagnostic
|
|
23
|
+
* path unauthorable: `lang: "handlebars"` would not compile, so the case the
|
|
24
|
+
* renderer exists to report could never be written down.
|
|
25
|
+
*
|
|
26
|
+
* `TemplateLang | (string & {})` keeps editor completion for the two engines
|
|
27
|
+
* this set implements while still accepting any string.
|
|
28
|
+
*/
|
|
29
|
+
export type TemplateLayoutElement = Omit<Layout, 'elements'> & {
|
|
30
|
+
type: 'TemplateLayout';
|
|
31
|
+
/** The template source. Required by section 13. */
|
|
32
|
+
template: string;
|
|
33
|
+
/** `ractive`, `jsx`, or anything else - which is diagnosed, not rejected. */
|
|
34
|
+
lang?: TemplateLang | (string & NonNullable<unknown>);
|
|
35
|
+
/** Lets a registered `Template` resolve this element by name. */
|
|
36
|
+
name?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Children; a named one is addressable from the template.
|
|
39
|
+
*
|
|
40
|
+
* Section 13: "each named child is available as a partial that mounts its
|
|
41
|
+
* delegated renderer". The names come from the project's own element type,
|
|
42
|
+
* since core declares none.
|
|
43
|
+
*/
|
|
44
|
+
elements: ExtendedUISchemaElement[];
|
|
45
|
+
};
|
|
46
|
+
export interface ResolvedTemplateLang {
|
|
47
|
+
/** The engine to use, or undefined when the request cannot be honoured. */
|
|
48
|
+
lang?: TemplateLang;
|
|
49
|
+
/** What was asked for, when it is not a language this set implements. */
|
|
50
|
+
requested?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Why nothing will render. `unsupported` is a language this set does not
|
|
53
|
+
* implement; `evaluation-disabled` is a supported one the host has not
|
|
54
|
+
* permitted.
|
|
55
|
+
*/
|
|
56
|
+
diagnostic?: 'unsupported' | 'evaluation-disabled';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether the host permits compiling strings into executable code.
|
|
60
|
+
*
|
|
61
|
+
* "String evaluation requires
|
|
62
|
+
* `jsonformsExtended.security.allowScriptEvaluation=true`… Enabling string
|
|
63
|
+
* evaluation means the host treats the UI schema as trusted executable code."
|
|
64
|
+
*
|
|
65
|
+
* **Both** engines need it. JSX is compiled and handed to `new Function`;
|
|
66
|
+
* Ractive compiles each `{{ }}` expression the same way. Neither is a sandbox,
|
|
67
|
+
* and the default is therefore off.
|
|
68
|
+
*/
|
|
69
|
+
export declare const allowsScriptEvaluation: (config: unknown) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The engine for one element, or a diagnostic saying why there is none.
|
|
72
|
+
*
|
|
73
|
+
* "Unknown or unsupported languages must be diagnosed rather than interpreted
|
|
74
|
+
* as another engine" - so an unrecognized `lang` does **not** fall back to the
|
|
75
|
+
* default. Falling back is what turns a typo into a form that renders the
|
|
76
|
+
* wrong thing and says nothing.
|
|
77
|
+
*/
|
|
78
|
+
export declare const resolveTemplateLang: (uischema: UISchemaElement | undefined, config: unknown) => ResolvedTemplateLang;
|
|
79
|
+
/**
|
|
80
|
+
* The same resolution, plus the security gate, for a renderer about to run.
|
|
81
|
+
*
|
|
82
|
+
* Kept separate from {@link resolveTemplateLang} because the **testers** must
|
|
83
|
+
* not consult it: a disabled host still needs the element to select a renderer,
|
|
84
|
+
* so that renderer can report why nothing is shown. A tester returning `-1`
|
|
85
|
+
* would leave the element unhandled and silent.
|
|
86
|
+
*/
|
|
87
|
+
export declare const resolveTemplateEngine: (uischema: UISchemaElement | undefined, config: unknown) => ResolvedTemplateLang;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { UrlPolicy } from './urlPolicy';
|
|
2
|
+
/**
|
|
3
|
+
* The URL policy, applied to whatever a **template** produced.
|
|
4
|
+
*
|
|
5
|
+
* Section 12 makes the policy a MUST for "every URL-bearing value", and the
|
|
6
|
+
* `Link` and `ImageView` renderers have always honoured it. A template did
|
|
7
|
+
* not: `<a href={data.url}>` put the value straight into the anchor, so a
|
|
8
|
+
* `javascript:` URL arriving in form data became a working script the moment
|
|
9
|
+
* somebody clicked it. Text interpolation was never the hole - React escapes
|
|
10
|
+
* it - which is exactly why this one survived.
|
|
11
|
+
*
|
|
12
|
+
* The check belongs **below the engine**, not in it: there are three engines
|
|
13
|
+
* and no reason for each to learn the policy separately.
|
|
14
|
+
*
|
|
15
|
+
* **A refused URL drops the attribute, not the element.** An `<a>` without an
|
|
16
|
+
* `href` is text that cannot navigate; an `<img>` without a `src` shows its
|
|
17
|
+
* `alt`. Removing the element instead would make a hostile value indistinguishable
|
|
18
|
+
* from a missing one, and section 19 asks for honest rendering of bad data.
|
|
19
|
+
*/
|
|
20
|
+
/** Stable code, so a host can grep for it. */
|
|
21
|
+
export declare const URL_REFUSED_DIAGNOSTIC = "template.urlRefused";
|
|
22
|
+
/**
|
|
23
|
+
* Props with every refused URL removed.
|
|
24
|
+
*
|
|
25
|
+
* Returns the **same object** when nothing was refused, so the common path
|
|
26
|
+
* allocates nothing and React's identity checks are unaffected.
|
|
27
|
+
*/
|
|
28
|
+
export declare const sanitizeUrlProps: (type: unknown, props: Record<string, unknown> | null | undefined, policy?: UrlPolicy, onRefused?: (message: string) => void) => Record<string, unknown> | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The same policy, applied to a DOM subtree an engine rendered itself.
|
|
31
|
+
*
|
|
32
|
+
* Ractive owns its subtree and offers no hook for a bound attribute value, so
|
|
33
|
+
* this runs immediately after it renders. That is a real difference from the
|
|
34
|
+
* JSX profile, where the check happens *before* the element exists: here the
|
|
35
|
+
* attribute is briefly present, so a `src` may already have started loading
|
|
36
|
+
* even though it is removed in the same task. `javascript:` in an `href` -
|
|
37
|
+
* the case that actually executes attacker code - needs a click, and is gone
|
|
38
|
+
* long before one can arrive.
|
|
39
|
+
*/
|
|
40
|
+
export declare const sanitizeUrlAttributes: (root: Element | null | undefined, policy?: UrlPolicy, onRefused?: (message: string) => void) => number;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which URLs a URL-bearing element may navigate to or load.
|
|
3
|
+
*
|
|
4
|
+
* Section 12 of the specification makes this a MUST for every URL-bearing
|
|
5
|
+
* value - `Link.href`, `ImageView.src`, Markdown links and images - and fixes
|
|
6
|
+
* the defaults below for when no configuration is supplied.
|
|
7
|
+
*/
|
|
8
|
+
export interface UrlPolicy {
|
|
9
|
+
allowedSchemes: string[];
|
|
10
|
+
allowRelative: boolean;
|
|
11
|
+
allowImageDataUrls: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const defaultUrlPolicy: UrlPolicy;
|
|
14
|
+
/** Reads `config.jsonformsExtended.security.urlPolicy`, filling in defaults. */
|
|
15
|
+
export declare const resolveUrlPolicy: (config: unknown) => UrlPolicy;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a URL may be used, under the supplied policy.
|
|
18
|
+
*
|
|
19
|
+
* A URL with no scheme is relative and governed by `allowRelative`. A URL with
|
|
20
|
+
* a scheme must name one the policy allows - so `javascript:`, `data:` and
|
|
21
|
+
* `vbscript:` are refused by default rather than being rendered into an
|
|
22
|
+
* anchor. Protocol-relative `//host/path` counts as absolute, because it
|
|
23
|
+
* inherits the page's scheme and can leave the origin.
|
|
24
|
+
*
|
|
25
|
+
* Leading control characters and whitespace are stripped before the test:
|
|
26
|
+
* `java\\nscript:alert(1)` is a scheme, and browsers treat it as one.
|
|
27
|
+
*/
|
|
28
|
+
export declare const isAllowedUrl: (url: unknown, policy?: UrlPolicy) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a URL may be **loaded as an image**.
|
|
31
|
+
*
|
|
32
|
+
* Same policy as {@link isAllowedUrl}, plus `allowImageDataUrls`: a
|
|
33
|
+
* `data:image/...` URL is a reasonable way to inline a small asset, and is
|
|
34
|
+
* nothing like a `data:text/html` document handed to a link. The flag only
|
|
35
|
+
* opens inline *images* - a `data:` URL of any other media type stays refused
|
|
36
|
+
* whatever it is used for, so turning this on cannot become a way to smuggle
|
|
37
|
+
* a document in.
|
|
38
|
+
*
|
|
39
|
+
* It is off by default, because an inline payload bypasses whatever CSP
|
|
40
|
+
* `img-src` allow-list the host maintains.
|
|
41
|
+
*/
|
|
42
|
+
export declare const isAllowedImageUrl: (url: unknown, policy?: UrlPolicy) => boolean;
|