@yimoka/designable-playground 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/demo/components/Alert/index.d.ts +4 -0
- package/dist/demo/components/Alert/index.js +41 -0
- package/dist/demo/components/ArrayCards/index.d.ts +17 -0
- package/dist/demo/components/ArrayCards/index.js +62 -0
- package/dist/demo/components/ArrayList/index.d.ts +25 -0
- package/dist/demo/components/ArrayList/index.js +143 -0
- package/dist/demo/components/ArrayTable/index.d.ts +39 -0
- package/dist/demo/components/ArrayTable/index.js +247 -0
- package/dist/demo/components/AutoComplete/index.d.ts +4 -0
- package/dist/demo/components/AutoComplete/index.js +52 -0
- package/dist/demo/components/Avatar/index.d.ts +4 -0
- package/dist/demo/components/Avatar/index.js +34 -0
- package/dist/demo/components/Badge/index.d.ts +4 -0
- package/dist/demo/components/Badge/index.js +35 -0
- package/dist/demo/components/Button/index.d.ts +4 -0
- package/dist/demo/components/Button/index.js +86 -0
- package/dist/demo/components/Card/index.d.ts +4 -0
- package/dist/demo/components/Card/index.js +72 -0
- package/dist/demo/components/Carousel/index.d.ts +4 -0
- package/dist/demo/components/Carousel/index.js +33 -0
- package/dist/demo/components/Cascader/index.d.ts +4 -0
- package/dist/demo/components/Cascader/index.js +60 -0
- package/dist/demo/components/Checkbox/index.d.ts +8 -0
- package/dist/demo/components/Checkbox/index.js +55 -0
- package/dist/demo/components/ColorPicker/index.d.ts +4 -0
- package/dist/demo/components/ColorPicker/index.js +38 -0
- package/dist/demo/components/DatePicker/index.d.ts +4 -0
- package/dist/demo/components/DatePicker/index.js +61 -0
- package/dist/demo/components/DateRangePicker/index.d.ts +4 -0
- package/dist/demo/components/DateRangePicker/index.js +58 -0
- package/dist/demo/components/Divider/index.d.ts +4 -0
- package/dist/demo/components/Divider/index.js +39 -0
- package/dist/demo/components/Empty/index.d.ts +4 -0
- package/dist/demo/components/Empty/index.js +29 -0
- package/dist/demo/components/Flex/index.d.ts +4 -0
- package/dist/demo/components/Flex/index.js +51 -0
- package/dist/demo/components/Form/index.d.ts +21 -0
- package/dist/demo/components/Form/index.js +116 -0
- package/dist/demo/components/FormCollapse/index.d.ts +28 -0
- package/dist/demo/components/FormCollapse/index.js +164 -0
- package/dist/demo/components/FormGrid/index.d.ts +22 -0
- package/dist/demo/components/FormGrid/index.js +134 -0
- package/dist/demo/components/FormItem/index.d.ts +14 -0
- package/dist/demo/components/FormItem/index.js +33 -0
- package/dist/demo/components/FormLayout/index.d.ts +26 -0
- package/dist/demo/components/FormLayout/index.js +260 -0
- package/dist/demo/components/FormTab/index.d.ts +15 -0
- package/dist/demo/components/FormTab/index.js +186 -0
- package/dist/demo/components/GridCol/index.d.ts +4 -0
- package/dist/demo/components/GridCol/index.js +53 -0
- package/dist/demo/components/GridRow/index.d.ts +4 -0
- package/dist/demo/components/GridRow/index.js +70 -0
- package/dist/demo/components/HTMLContent/index.d.ts +4 -0
- package/dist/demo/components/HTMLContent/index.js +34 -0
- package/dist/demo/components/I18nEditor/index.d.ts +8 -0
- package/dist/demo/components/I18nEditor/index.js +64 -0
- package/dist/demo/components/Image/index.d.ts +4 -0
- package/dist/demo/components/Image/index.js +36 -0
- package/dist/demo/components/Input/index.d.ts +4 -0
- package/dist/demo/components/Input/index.js +36 -0
- package/dist/demo/components/InputSearch/index.d.ts +4 -0
- package/dist/demo/components/InputSearch/index.js +40 -0
- package/dist/demo/components/Link/index.d.ts +4 -0
- package/dist/demo/components/Link/index.js +37 -0
- package/dist/demo/components/Mentions/index.d.ts +4 -0
- package/dist/demo/components/Mentions/index.js +41 -0
- package/dist/demo/components/NumberPicker/index.d.ts +6 -0
- package/dist/demo/components/NumberPicker/index.js +63 -0
- package/dist/demo/components/ObjectContainer/index.d.ts +14 -0
- package/dist/demo/components/ObjectContainer/index.js +46 -0
- package/dist/demo/components/Password/index.d.ts +6 -0
- package/dist/demo/components/Password/index.js +44 -0
- package/dist/demo/components/QRCode/index.d.ts +4 -0
- package/dist/demo/components/QRCode/index.js +34 -0
- package/dist/demo/components/Radio/index.d.ts +6 -0
- package/dist/demo/components/Radio/index.js +49 -0
- package/dist/demo/components/Rate/index.d.ts +6 -0
- package/dist/demo/components/Rate/index.js +43 -0
- package/dist/demo/components/Search/index.d.ts +4 -0
- package/dist/demo/components/Search/index.js +42 -0
- package/dist/demo/components/SearchSelect/index.d.ts +4 -0
- package/dist/demo/components/SearchSelect/index.js +53 -0
- package/dist/demo/components/Select/index.d.ts +4 -0
- package/dist/demo/components/Select/index.js +59 -0
- package/dist/demo/components/Slider/index.d.ts +6 -0
- package/dist/demo/components/Slider/index.js +61 -0
- package/dist/demo/components/Space/index.d.ts +9 -0
- package/dist/demo/components/Space/index.js +61 -0
- package/dist/demo/components/Statistic/index.d.ts +4 -0
- package/dist/demo/components/Statistic/index.js +33 -0
- package/dist/demo/components/Switch/index.d.ts +4 -0
- package/dist/demo/components/Switch/index.js +49 -0
- package/dist/demo/components/Tabs/index.d.ts +10 -0
- package/dist/demo/components/Tabs/index.js +181 -0
- package/dist/demo/components/Tag/index.d.ts +4 -0
- package/dist/demo/components/Tag/index.js +33 -0
- package/dist/demo/components/Text/index.d.ts +11 -0
- package/dist/demo/components/Text/index.js +64 -0
- package/dist/demo/components/TextArea/index.d.ts +6 -0
- package/dist/demo/components/TextArea/index.js +43 -0
- package/dist/demo/components/TimePicker/index.d.ts +4 -0
- package/dist/demo/components/TimePicker/index.js +69 -0
- package/dist/demo/components/TimeRangePicker/index.d.ts +4 -0
- package/dist/demo/components/TimeRangePicker/index.js +68 -0
- package/dist/demo/components/Transfer/index.d.ts +6 -0
- package/dist/demo/components/Transfer/index.js +59 -0
- package/dist/demo/components/TreeSelect/index.d.ts +4 -0
- package/dist/demo/components/TreeSelect/index.js +63 -0
- package/dist/demo/components/Upload/index.d.ts +8 -0
- package/dist/demo/components/Upload/index.js +64 -0
- package/dist/demo/components/index.d.ts +55 -0
- package/dist/demo/components/index.js +55 -0
- package/dist/demo/components/shared.d.ts +143 -0
- package/dist/demo/components/shared.js +315 -0
- package/dist/src/Playground.d.ts +3 -0
- package/dist/src/Playground.js +304 -0
- package/dist/src/antd/AntdPlayground.d.ts +16 -0
- package/dist/src/antd/AntdPlayground.js +136 -0
- package/dist/src/antd/index.d.ts +1 -0
- package/dist/src/antd/index.js +1 -0
- package/dist/src/context.d.ts +4 -0
- package/dist/src/context.js +13 -0
- package/dist/src/examples/index.d.ts +267 -0
- package/dist/src/examples/index.js +824 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/remoteSchemaAdapter.d.ts +53 -0
- package/dist/src/hooks/remoteSchemaAdapter.js +262 -0
- package/dist/src/hooks/usePlayground.d.ts +38 -0
- package/dist/src/hooks/usePlayground.js +642 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.d.ts +135 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.js +736 -0
- package/dist/src/hooks/useSchemaEditorDraft.d.ts +4 -0
- package/dist/src/hooks/useSchemaEditorDraft.js +44 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +14 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.d.ts +59 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.js +161 -0
- package/dist/src/layouts/PlaygroundLayout/index.d.ts +7 -0
- package/dist/src/layouts/PlaygroundLayout/index.js +443 -0
- package/dist/src/layouts/index.d.ts +1 -0
- package/dist/src/layouts/index.js +1 -0
- package/dist/src/panels/CompositePanel/index.d.ts +6 -0
- package/dist/src/panels/CompositePanel/index.js +139 -0
- package/dist/src/panels/ToolbarPanel/index.d.ts +3 -0
- package/dist/src/panels/ToolbarPanel/index.js +24 -0
- package/dist/src/panels/index.d.ts +2 -0
- package/dist/src/panels/index.js +2 -0
- package/dist/src/presets/antd.d.ts +19 -0
- package/dist/src/presets/antd.js +112 -0
- package/dist/src/presets/index.d.ts +4 -0
- package/dist/src/presets/index.js +3 -0
- package/dist/src/presets/runtime-array-helpers.d.ts +8 -0
- package/dist/src/presets/runtime-array-helpers.js +147 -0
- package/dist/src/presets/runtime-component-props.d.ts +3 -0
- package/dist/src/presets/runtime-component-props.js +5 -0
- package/dist/src/presets/runtime-components.d.ts +5 -0
- package/dist/src/presets/runtime-components.js +419 -0
- package/dist/src/presets/runtime-form-components.d.ts +9 -0
- package/dist/src/presets/runtime-form-components.js +94 -0
- package/dist/src/presets/scenario-catalog.d.ts +6 -0
- package/dist/src/presets/scenario-catalog.js +128 -0
- package/dist/src/presets/scenarios.d.ts +52 -0
- package/dist/src/presets/scenarios.js +603 -0
- package/dist/src/runtime/actions.d.ts +19 -0
- package/dist/src/runtime/actions.js +307 -0
- package/dist/src/runtime/contracts.d.ts +149 -0
- package/dist/src/runtime/contracts.js +1 -0
- package/dist/src/runtime/document-bindings.d.ts +3 -0
- package/dist/src/runtime/document-bindings.js +101 -0
- package/dist/src/runtime/document-core.d.ts +57 -0
- package/dist/src/runtime/document-core.js +379 -0
- package/dist/src/runtime/document-entity.d.ts +12 -0
- package/dist/src/runtime/document-entity.js +351 -0
- package/dist/src/runtime/document-expressions.d.ts +35 -0
- package/dist/src/runtime/document-expressions.js +346 -0
- package/dist/src/runtime/document-security.d.ts +34 -0
- package/dist/src/runtime/document-security.js +538 -0
- package/dist/src/runtime/document.d.ts +16 -0
- package/dist/src/runtime/document.js +212 -0
- package/dist/src/runtime/environment.d.ts +16 -0
- package/dist/src/runtime/environment.js +76 -0
- package/dist/src/runtime/i18n-schema.d.ts +36 -0
- package/dist/src/runtime/i18n-schema.js +338 -0
- package/dist/src/runtime/i18n.d.ts +25 -0
- package/dist/src/runtime/i18n.js +447 -0
- package/dist/src/runtime/index.d.ts +8 -0
- package/dist/src/runtime/index.js +8 -0
- package/dist/src/runtime/navigation.d.ts +5 -0
- package/dist/src/runtime/navigation.js +43 -0
- package/dist/src/runtime/playground.d.ts +30 -0
- package/dist/src/runtime/playground.js +243 -0
- package/dist/src/runtime/preview-boundaries.d.ts +13 -0
- package/dist/src/runtime/preview-boundaries.js +43 -0
- package/dist/src/runtime/preview.d.ts +44 -0
- package/dist/src/runtime/preview.js +574 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.d.ts +10 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.js +21 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.d.ts +15 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.js +65 -0
- package/dist/src/runtime/templates.d.ts +1560 -0
- package/dist/src/runtime/templates.js +508 -0
- package/dist/src/runtime/website-contact-template.d.ts +1 -0
- package/dist/src/runtime/website-contact-template.js +66 -0
- package/dist/src/runtime/website-template-shared.d.ts +14 -0
- package/dist/src/runtime/website-template-shared.js +210 -0
- package/dist/src/runtime/website-templates.d.ts +5 -0
- package/dist/src/runtime/website-templates.js +976 -0
- package/dist/src/shared/clipboard.d.ts +4 -0
- package/dist/src/shared/clipboard.js +56 -0
- package/dist/src/shared/componentRegistry.d.ts +133 -0
- package/dist/src/shared/componentRegistry.js +381 -0
- package/dist/src/shared/formilyCompatibility.d.ts +8 -0
- package/dist/src/shared/formilyCompatibility.js +40 -0
- package/dist/src/shared/index.d.ts +6 -0
- package/dist/src/shared/index.js +6 -0
- package/dist/src/shared/productionAcceptance.d.ts +63 -0
- package/dist/src/shared/productionAcceptance.js +201 -0
- package/dist/src/shared/schema-options.d.ts +16 -0
- package/dist/src/shared/schema-options.js +138 -0
- package/dist/src/shared/schema.d.ts +63 -0
- package/dist/src/shared/schema.js +627 -0
- package/dist/src/shared/styleSecurity.d.ts +2 -0
- package/dist/src/shared/styleSecurity.js +35 -0
- package/dist/src/transformers/formily.d.ts +34 -0
- package/dist/src/transformers/formily.js +943 -0
- package/dist/src/transformers/index.d.ts +1 -0
- package/dist/src/transformers/index.js +1 -0
- package/dist/src/types.d.ts +186 -0
- package/dist/src/types.js +1 -0
- package/dist/src/widgets/ActionsWidget/index.d.ts +3 -0
- package/dist/src/widgets/ActionsWidget/index.js +10 -0
- package/dist/src/widgets/ComponentTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/ComponentTreeWidget/index.js +333 -0
- package/dist/src/widgets/NodeActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/NodeActionsWidget/index.js +125 -0
- package/dist/src/widgets/OutlineTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/OutlineTreeWidget/index.js +432 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.d.ts +32 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.js +79 -0
- package/dist/src/widgets/PreviewWidget/index.d.ts +2 -0
- package/dist/src/widgets/PreviewWidget/index.js +1566 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.d.ts +18 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.js +356 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.d.ts +18 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.js +438 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.d.ts +39 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.js +475 -0
- package/dist/src/widgets/ResourceWidget/index.d.ts +3 -0
- package/dist/src/widgets/ResourceWidget/index.js +491 -0
- package/dist/src/widgets/SchemaCodeView/index.d.ts +7 -0
- package/dist/src/widgets/SchemaCodeView/index.js +225 -0
- package/dist/src/widgets/SchemaEditorWidget/index.d.ts +10 -0
- package/dist/src/widgets/SchemaEditorWidget/index.js +484 -0
- package/dist/src/widgets/SettingsPanelWidget/index.d.ts +3 -0
- package/dist/src/widgets/SettingsPanelWidget/index.js +190 -0
- package/dist/src/widgets/StorageActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/StorageActionsWidget/index.js +284 -0
- package/dist/src/widgets/index.d.ts +13 -0
- package/dist/src/widgets/index.js +13 -0
- package/package.json +100 -4
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { DEFAULT_FORMILY_COMPONENT_NAME_ALIASES } from "../shared/formilyCompatibility.js";
|
|
2
|
+
import { decodeJsonPointerSegment, FORMILY_SCHEMA_ARRAY_CHILD_KEYS, FORMILY_SCHEMA_RECORD_CHILD_KEYS, FORMILY_SCHEMA_SINGLE_CHILD_KEYS, UNSAFE_SCHEMA_OBJECT_KEYS, validateSchemaSecurity, visitFormilySchemaNodes, } from "../shared/schema.js";
|
|
3
|
+
import { validateRuntimeDataBindingNode, validateRuntimeI18nFieldMap, } from "./document-bindings.js";
|
|
4
|
+
import { DATA_BINDING_MANUAL_KEYS, RUNTIME_UPLOAD_NETWORK_KEYS, RUNTIME_SEARCH_REQUEST_PROP_KEYS, RUNTIME_NAVIGATION_PROP_KEYS, isObjectRecord, pushRuntimeIssue, validateRuntimeRequestConfig, } from "./document-core.js";
|
|
5
|
+
import { isRuntimeSchemaExpression, validateRuntimeStaticComponentNames, RUNTIME_AUTO_NETWORK_PROP_KEYS, RUNTIME_COMPONENT_AUTO_NETWORK_PROP_KEYS, RUNTIME_FIELD_VALUE_AUTO_NETWORK_COMPONENTS, RUNTIME_REACTION_FIELD_VALUE_KEYS, RUNTIME_SAFE_NATIVE_COMPONENT_TAGS, RUNTIME_COMPONENT_CALLABLE_EXPRESSION_PROP_PATHS, RUNTIME_COMPONENT_CALLABLE_EXPRESSION_PROP_KEY_PATHS, RUNTIME_DECORATOR_CALLABLE_EXPRESSION_PROP_PATHS, RUNTIME_DECORATOR_CALLABLE_EXPRESSION_PROP_KEY_PATHS, RUNTIME_SCHEMA_CALLABLE_EXPRESSION_KEYS, RUNTIME_STYLE_PROP_TREE_KEYS, findRuntimeSchemaExpressionPaths, findRuntimeDirectExpressionPaths, findRuntimeNonEmptyStringKeyPaths, findRuntimeCallableKeyExpressionPaths, validateRuntimeCallablePropPaths, validateRuntimeCallablePropKeyPaths, validateRuntimeExpressionCapabilities, } from "./document-expressions.js";
|
|
6
|
+
import { isSafeRuntimeNavigationHref, isSafeRuntimeNavigationPing, resolveRuntimeNavigationHref, } from "./navigation.js";
|
|
7
|
+
export const findUnsafeRuntimeHtmlPath = (value, path) => {
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
for (const [index, item] of value.entries()) {
|
|
10
|
+
const unsafePath = findUnsafeRuntimeHtmlPath(item, `${path}[${index}]`);
|
|
11
|
+
if (unsafePath)
|
|
12
|
+
return unsafePath;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (!isObjectRecord(value))
|
|
17
|
+
return undefined;
|
|
18
|
+
for (const [key, item] of Object.entries(value)) {
|
|
19
|
+
const itemPath = `${path}.${key}`;
|
|
20
|
+
if (key === 'dangerouslySetInnerHTML' || key === '__html')
|
|
21
|
+
return itemPath;
|
|
22
|
+
const unsafePath = findUnsafeRuntimeHtmlPath(item, itemPath);
|
|
23
|
+
if (unsafePath)
|
|
24
|
+
return unsafePath;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
28
|
+
export const findRuntimeAutoNetworkExpressionPaths = (value, path, inStyleTree = false, componentPropKeys) => {
|
|
29
|
+
const paths = [];
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
value.forEach((item, index) => {
|
|
32
|
+
paths.push(...findRuntimeAutoNetworkExpressionPaths(item, `${path}[${index}]`, inStyleTree, componentPropKeys));
|
|
33
|
+
});
|
|
34
|
+
return paths;
|
|
35
|
+
}
|
|
36
|
+
if (!isObjectRecord(value))
|
|
37
|
+
return paths;
|
|
38
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
39
|
+
const itemPath = `${path}.${key}`;
|
|
40
|
+
const nextInStyleTree = inStyleTree || RUNTIME_STYLE_PROP_TREE_KEYS.has(key);
|
|
41
|
+
if (typeof item === 'string'
|
|
42
|
+
&& isRuntimeSchemaExpression(item)
|
|
43
|
+
&& (nextInStyleTree
|
|
44
|
+
|| RUNTIME_AUTO_NETWORK_PROP_KEYS.has(key)
|
|
45
|
+
|| componentPropKeys?.has(key))) {
|
|
46
|
+
paths.push(itemPath);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
paths.push(...findRuntimeAutoNetworkExpressionPaths(item, itemPath, nextInStyleTree, componentPropKeys));
|
|
50
|
+
});
|
|
51
|
+
return paths;
|
|
52
|
+
};
|
|
53
|
+
export const findRuntimeReactionSchemaPatches = (value, path) => {
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
return value.flatMap((item, index) => (findRuntimeReactionSchemaPatches(item, `${path}[${index}]`)));
|
|
56
|
+
}
|
|
57
|
+
if (!isObjectRecord(value))
|
|
58
|
+
return [];
|
|
59
|
+
return ['fulfill', 'otherwise'].flatMap((branchName) => {
|
|
60
|
+
const branch = value[branchName];
|
|
61
|
+
if (!isObjectRecord(branch) || !Object.prototype.hasOwnProperty.call(branch, 'schema')) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return [{
|
|
65
|
+
path: `${path}.${branchName}.schema`,
|
|
66
|
+
state: branch.state,
|
|
67
|
+
statePath: `${path}.${branchName}.state`,
|
|
68
|
+
value: branch.schema,
|
|
69
|
+
}];
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
export const findRuntimeReactionStateBranches = (value, path) => {
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
return value.flatMap((item, index) => (findRuntimeReactionStateBranches(item, `${path}[${index}]`)));
|
|
75
|
+
}
|
|
76
|
+
if (!isObjectRecord(value))
|
|
77
|
+
return [];
|
|
78
|
+
return ['fulfill', 'otherwise'].flatMap((branchName) => {
|
|
79
|
+
const branch = value[branchName];
|
|
80
|
+
if (!isObjectRecord(branch) || !isObjectRecord(branch.state))
|
|
81
|
+
return [];
|
|
82
|
+
return [{
|
|
83
|
+
schema: branch.schema,
|
|
84
|
+
state: branch.state,
|
|
85
|
+
statePath: `${path}.${branchName}.state`,
|
|
86
|
+
}];
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
export const resolveRuntimeLocalSchemaReference = (schemaRoot, reference) => {
|
|
90
|
+
if (reference === '#')
|
|
91
|
+
return isObjectRecord(schemaRoot) ? schemaRoot : undefined;
|
|
92
|
+
if (!reference.startsWith('#/'))
|
|
93
|
+
return undefined;
|
|
94
|
+
let current = schemaRoot;
|
|
95
|
+
for (const rawSegment of reference.slice(2).split('/')) {
|
|
96
|
+
const segment = decodeJsonPointerSegment(rawSegment);
|
|
97
|
+
if (segment === undefined || UNSAFE_SCHEMA_OBJECT_KEYS.has(segment))
|
|
98
|
+
return undefined;
|
|
99
|
+
if (Array.isArray(current)) {
|
|
100
|
+
if (!/^(?:0|[1-9]\d*)$/u.test(segment))
|
|
101
|
+
return undefined;
|
|
102
|
+
current = current[Number(segment)];
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!isObjectRecord(current) || !Object.prototype.hasOwnProperty.call(current, segment)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
current = current[segment];
|
|
109
|
+
}
|
|
110
|
+
return isObjectRecord(current) ? current : undefined;
|
|
111
|
+
};
|
|
112
|
+
export const normalizeRuntimeComponentAuditName = (componentName) => (componentName === undefined
|
|
113
|
+
? undefined
|
|
114
|
+
: (DEFAULT_FORMILY_COMPONENT_NAME_ALIASES[componentName] ?? componentName));
|
|
115
|
+
export const resolveRuntimeReferencedSchemaAuditName = (schemaRoot, node, propertyName, visited) => {
|
|
116
|
+
if (Object.prototype.hasOwnProperty.call(node, propertyName)) {
|
|
117
|
+
const declaredName = node[propertyName];
|
|
118
|
+
return {
|
|
119
|
+
declared: true,
|
|
120
|
+
name: typeof declaredName === 'string' ? declaredName : undefined,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (visited.has(node))
|
|
124
|
+
return { declared: false };
|
|
125
|
+
visited.add(node);
|
|
126
|
+
const reference = node.$ref;
|
|
127
|
+
if (typeof reference !== 'string')
|
|
128
|
+
return { declared: false };
|
|
129
|
+
const referencedNode = resolveRuntimeLocalSchemaReference(schemaRoot, reference);
|
|
130
|
+
if (!referencedNode)
|
|
131
|
+
return { declared: false };
|
|
132
|
+
return resolveRuntimeReferencedSchemaAuditName(schemaRoot, referencedNode, propertyName, visited);
|
|
133
|
+
};
|
|
134
|
+
export const resolveRuntimeSchemaAuditName = (schemaRoot, node, propertyName, inheritedName, allowInherited) => {
|
|
135
|
+
const resolution = resolveRuntimeReferencedSchemaAuditName(schemaRoot, node, propertyName, new Set());
|
|
136
|
+
if (resolution.declared) {
|
|
137
|
+
return propertyName === 'x-component'
|
|
138
|
+
? normalizeRuntimeComponentAuditName(resolution.name)
|
|
139
|
+
: resolution.name;
|
|
140
|
+
}
|
|
141
|
+
if (!allowInherited)
|
|
142
|
+
return undefined;
|
|
143
|
+
return propertyName === 'x-component'
|
|
144
|
+
? normalizeRuntimeComponentAuditName(inheritedName)
|
|
145
|
+
: inheritedName;
|
|
146
|
+
};
|
|
147
|
+
export const mergeRuntimeSchemaPatch = (base, patch) => {
|
|
148
|
+
if (!isObjectRecord(base) || !isObjectRecord(patch))
|
|
149
|
+
return patch;
|
|
150
|
+
const merged = { ...base };
|
|
151
|
+
Object.entries(patch).forEach(([key, patchValue]) => {
|
|
152
|
+
merged[key] = mergeRuntimeSchemaPatch(base[key], patchValue);
|
|
153
|
+
});
|
|
154
|
+
return merged;
|
|
155
|
+
};
|
|
156
|
+
export const resolveRuntimeSchemaAuditNode = (schemaRoot, node, visited = new Set()) => {
|
|
157
|
+
if (visited.has(node))
|
|
158
|
+
return node;
|
|
159
|
+
visited.add(node);
|
|
160
|
+
const reference = node.$ref;
|
|
161
|
+
if (typeof reference !== 'string')
|
|
162
|
+
return node;
|
|
163
|
+
const referencedNode = resolveRuntimeLocalSchemaReference(schemaRoot, reference);
|
|
164
|
+
if (!referencedNode)
|
|
165
|
+
return node;
|
|
166
|
+
const resolvedReference = resolveRuntimeSchemaAuditNode(schemaRoot, referencedNode, visited);
|
|
167
|
+
const mergedNode = mergeRuntimeSchemaPatch(resolvedReference, node);
|
|
168
|
+
return isObjectRecord(mergedNode) ? mergedNode : node;
|
|
169
|
+
};
|
|
170
|
+
export const findRuntimeReactionFieldValueExpressionPaths = (value, path) => {
|
|
171
|
+
if (Array.isArray(value)) {
|
|
172
|
+
return value.flatMap((item, index) => (findRuntimeReactionFieldValueExpressionPaths(item, `${path}[${index}]`)));
|
|
173
|
+
}
|
|
174
|
+
if (!isObjectRecord(value))
|
|
175
|
+
return [];
|
|
176
|
+
return ['fulfill', 'otherwise'].flatMap((branchName) => {
|
|
177
|
+
const branch = value[branchName];
|
|
178
|
+
if (!isObjectRecord(branch))
|
|
179
|
+
return [];
|
|
180
|
+
const { state } = branch;
|
|
181
|
+
if (!isObjectRecord(state))
|
|
182
|
+
return [];
|
|
183
|
+
return [...RUNTIME_REACTION_FIELD_VALUE_KEYS].flatMap((key) => {
|
|
184
|
+
if (!Object.prototype.hasOwnProperty.call(state, key))
|
|
185
|
+
return [];
|
|
186
|
+
return findRuntimeSchemaExpressionPaths(state[key], `${path}.${branchName}.state.${key}`);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
export const findRuntimeReactionValidatorExpressionPaths = (value, path) => {
|
|
191
|
+
if (Array.isArray(value)) {
|
|
192
|
+
return value.flatMap((item, index) => (findRuntimeReactionValidatorExpressionPaths(item, `${path}[${index}]`)));
|
|
193
|
+
}
|
|
194
|
+
if (!isObjectRecord(value))
|
|
195
|
+
return [];
|
|
196
|
+
return ['fulfill', 'otherwise'].flatMap((branchName) => {
|
|
197
|
+
const branch = value[branchName];
|
|
198
|
+
if (!isObjectRecord(branch))
|
|
199
|
+
return [];
|
|
200
|
+
const { state } = branch;
|
|
201
|
+
if (!isObjectRecord(state))
|
|
202
|
+
return [];
|
|
203
|
+
const { validator } = state;
|
|
204
|
+
const validatorPath = `${path}.${branchName}.state.validator`;
|
|
205
|
+
return [...new Set([
|
|
206
|
+
...findRuntimeDirectExpressionPaths(validator, validatorPath),
|
|
207
|
+
...findRuntimeCallableKeyExpressionPaths(validator, validatorPath, RUNTIME_SCHEMA_CALLABLE_EXPRESSION_KEYS),
|
|
208
|
+
])];
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
export const createRuntimeSchemaNodeAuditSnapshot = (node) => {
|
|
212
|
+
const snapshot = { ...node };
|
|
213
|
+
[
|
|
214
|
+
...FORMILY_SCHEMA_RECORD_CHILD_KEYS,
|
|
215
|
+
...FORMILY_SCHEMA_SINGLE_CHILD_KEYS,
|
|
216
|
+
...FORMILY_SCHEMA_ARRAY_CHILD_KEYS,
|
|
217
|
+
'items',
|
|
218
|
+
'x-reactions',
|
|
219
|
+
].forEach((key) => {
|
|
220
|
+
delete snapshot[key];
|
|
221
|
+
});
|
|
222
|
+
return snapshot;
|
|
223
|
+
};
|
|
224
|
+
export const validateRuntimeComponentSecurity = (value, issues, path, inheritedContext) => {
|
|
225
|
+
const schemaRoot = inheritedContext?.schemaRoot ?? value;
|
|
226
|
+
validateRuntimeExpressionCapabilities(value, issues, path);
|
|
227
|
+
validateSchemaSecurity(value, path).forEach((issue) => {
|
|
228
|
+
if (issue.code !== 'risky_expression')
|
|
229
|
+
return;
|
|
230
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', issue.path, 'Runtime 表达式不允许访问浏览器全局对象或动态执行能力');
|
|
231
|
+
});
|
|
232
|
+
visitFormilySchemaNodes(value, path, ({ node, path: nodePath }) => {
|
|
233
|
+
const isRootNode = nodePath === path;
|
|
234
|
+
const auditNode = resolveRuntimeSchemaAuditNode(schemaRoot, node);
|
|
235
|
+
const componentName = resolveRuntimeSchemaAuditName(schemaRoot, auditNode, 'x-component', inheritedContext?.componentName, isRootNode);
|
|
236
|
+
const decoratorName = resolveRuntimeSchemaAuditName(schemaRoot, auditNode, 'x-decorator', inheritedContext?.decoratorName, isRootNode);
|
|
237
|
+
const reactions = auditNode['x-reactions'];
|
|
238
|
+
findRuntimeDirectExpressionPaths(reactions, `${nodePath}.x-reactions`).forEach((reactionPath) => {
|
|
239
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', reactionPath, 'Runtime v1 不允许 x-reactions 直接执行表达式函数,请使用声明式 reactions 对象');
|
|
240
|
+
});
|
|
241
|
+
findRuntimeNonEmptyStringKeyPaths(reactions, `${nodePath}.x-reactions`, new Set(['run'])).forEach((reactionPath) => {
|
|
242
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', reactionPath, 'Runtime v1 不允许 x-reactions.run 执行脚本,请使用声明式状态映射');
|
|
243
|
+
});
|
|
244
|
+
findRuntimeReactionSchemaPatches(reactions, `${nodePath}.x-reactions`).forEach((patch) => {
|
|
245
|
+
validateRuntimeStaticComponentNames(patch.value, issues, patch.path);
|
|
246
|
+
validateRuntimeComponentSecurity(patch.value, issues, patch.path, {
|
|
247
|
+
componentName,
|
|
248
|
+
decoratorName,
|
|
249
|
+
schemaRoot,
|
|
250
|
+
});
|
|
251
|
+
if (!isObjectRecord(patch.value))
|
|
252
|
+
return;
|
|
253
|
+
const mergedNode = mergeRuntimeSchemaPatch(auditNode, patch.value);
|
|
254
|
+
if (!isObjectRecord(mergedNode))
|
|
255
|
+
return;
|
|
256
|
+
const mergedComponentName = resolveRuntimeSchemaAuditName(schemaRoot, mergedNode, 'x-component', componentName, true);
|
|
257
|
+
const mergedDecoratorName = resolveRuntimeSchemaAuditName(schemaRoot, mergedNode, 'x-decorator', decoratorName, true);
|
|
258
|
+
if (mergedComponentName !== componentName
|
|
259
|
+
|| mergedDecoratorName !== decoratorName) {
|
|
260
|
+
validateRuntimeComponentSecurity(createRuntimeSchemaNodeAuditSnapshot(mergedNode), issues, patch.path, {
|
|
261
|
+
componentName: mergedComponentName,
|
|
262
|
+
decoratorName: mergedDecoratorName,
|
|
263
|
+
schemaRoot,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const reactionState = patch.state;
|
|
267
|
+
if (mergedComponentName
|
|
268
|
+
&& RUNTIME_FIELD_VALUE_AUTO_NETWORK_COMPONENTS.has(mergedComponentName)
|
|
269
|
+
&& isObjectRecord(reactionState)) {
|
|
270
|
+
RUNTIME_REACTION_FIELD_VALUE_KEYS.forEach((key) => {
|
|
271
|
+
if (!Object.prototype.hasOwnProperty.call(reactionState, key))
|
|
272
|
+
return;
|
|
273
|
+
findRuntimeSchemaExpressionPaths(reactionState[key], `${patch.statePath}.${key}`).forEach((sinkPath) => {
|
|
274
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', sinkPath, 'Runtime 数据表达式不能作为资源组件字段值触发浏览器自动联网');
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
findRuntimeReactionStateBranches(reactions, `${nodePath}.x-reactions`).forEach((branch) => {
|
|
280
|
+
const effectiveNode = branch.schema === undefined
|
|
281
|
+
? auditNode
|
|
282
|
+
: mergeRuntimeSchemaPatch(auditNode, branch.schema);
|
|
283
|
+
if (!isObjectRecord(effectiveNode))
|
|
284
|
+
return;
|
|
285
|
+
const effectiveComponentName = resolveRuntimeSchemaAuditName(schemaRoot, effectiveNode, 'x-component', componentName, true);
|
|
286
|
+
const effectiveDecoratorName = resolveRuntimeSchemaAuditName(schemaRoot, effectiveNode, 'x-decorator', decoratorName, true);
|
|
287
|
+
const resolveReactionStateName = (statePropertyName, schemaPropertyName, fallbackName) => {
|
|
288
|
+
if (!Object.prototype.hasOwnProperty.call(branch.state, statePropertyName)) {
|
|
289
|
+
return fallbackName;
|
|
290
|
+
}
|
|
291
|
+
const stateValue = branch.state[statePropertyName];
|
|
292
|
+
const declaredName = Array.isArray(stateValue) ? stateValue[0] : stateValue;
|
|
293
|
+
if (typeof declaredName !== 'string' || isRuntimeSchemaExpression(declaredName)) {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
return resolveRuntimeSchemaAuditName(schemaRoot, { [schemaPropertyName]: declaredName }, schemaPropertyName, fallbackName, true);
|
|
297
|
+
};
|
|
298
|
+
const reactionComponentName = resolveReactionStateName('component', 'x-component', effectiveComponentName);
|
|
299
|
+
const reactionDecoratorName = resolveReactionStateName('decorator', 'x-decorator', effectiveDecoratorName);
|
|
300
|
+
['component', 'decorator'].forEach((statePropertyName) => {
|
|
301
|
+
if (!Object.prototype.hasOwnProperty.call(branch.state, statePropertyName))
|
|
302
|
+
return;
|
|
303
|
+
const stateValue = branch.state[statePropertyName];
|
|
304
|
+
const tupleName = Array.isArray(stateValue) && typeof stateValue[0] === 'string'
|
|
305
|
+
? stateValue[0]
|
|
306
|
+
: undefined;
|
|
307
|
+
const tupleProps = Array.isArray(stateValue) && isObjectRecord(stateValue[1])
|
|
308
|
+
? stateValue[1]
|
|
309
|
+
: undefined;
|
|
310
|
+
if (tupleName && tupleProps) {
|
|
311
|
+
const tuplePropsPath = `${branch.statePath}.${statePropertyName}[1]`;
|
|
312
|
+
const schemaNameProperty = statePropertyName === 'component'
|
|
313
|
+
? 'x-component'
|
|
314
|
+
: 'x-decorator';
|
|
315
|
+
const schemaPropsProperty = statePropertyName === 'component'
|
|
316
|
+
? 'x-component-props'
|
|
317
|
+
: 'x-decorator-props';
|
|
318
|
+
const syntheticNode = {
|
|
319
|
+
...(statePropertyName === 'component' && effectiveDecoratorName
|
|
320
|
+
? { 'x-decorator': effectiveDecoratorName }
|
|
321
|
+
: {}),
|
|
322
|
+
...(statePropertyName === 'decorator' && effectiveComponentName
|
|
323
|
+
? { 'x-component': effectiveComponentName }
|
|
324
|
+
: {}),
|
|
325
|
+
[schemaNameProperty]: tupleName,
|
|
326
|
+
[schemaPropsProperty]: tupleProps,
|
|
327
|
+
};
|
|
328
|
+
const tupleIssues = [];
|
|
329
|
+
validateRuntimeComponentSecurity(syntheticNode, tupleIssues, tuplePropsPath, { schemaRoot: syntheticNode });
|
|
330
|
+
const syntheticPropsPath = `${tuplePropsPath}.${schemaPropsProperty}`;
|
|
331
|
+
tupleIssues.forEach((issue) => {
|
|
332
|
+
let issuePath = issue.path;
|
|
333
|
+
if (issue.path === syntheticPropsPath) {
|
|
334
|
+
issuePath = tuplePropsPath;
|
|
335
|
+
}
|
|
336
|
+
else if (issue.path.startsWith(`${syntheticPropsPath}.`)) {
|
|
337
|
+
issuePath = `${tuplePropsPath}${issue.path.slice(syntheticPropsPath.length)}`;
|
|
338
|
+
}
|
|
339
|
+
issues.push({
|
|
340
|
+
...issue,
|
|
341
|
+
path: issuePath,
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
findRuntimeSchemaExpressionPaths(stateValue, `${branch.statePath}.${statePropertyName}`).forEach((expressionPath) => {
|
|
346
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime reaction state 不允许通过表达式注入组件或装饰器');
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
[
|
|
350
|
+
['componentProps', 'x-component-props'],
|
|
351
|
+
['decoratorProps', 'x-decorator-props'],
|
|
352
|
+
].forEach(([statePropertyName, schemaPropertyName]) => {
|
|
353
|
+
const stateIdentityPropertyName = statePropertyName === 'componentProps'
|
|
354
|
+
? 'component'
|
|
355
|
+
: 'decorator';
|
|
356
|
+
const dynamicPropsValue = branch.state[statePropertyName];
|
|
357
|
+
const dynamicPropsPath = `${branch.statePath}.${statePropertyName}`;
|
|
358
|
+
if (!isObjectRecord(dynamicPropsValue)) {
|
|
359
|
+
findRuntimeSchemaExpressionPaths(dynamicPropsValue, dynamicPropsPath).forEach((expressionPath) => {
|
|
360
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime reaction state 不允许通过整体表达式注入组件或装饰器属性');
|
|
361
|
+
});
|
|
362
|
+
if (Object.prototype.hasOwnProperty.call(branch.state, statePropertyName)
|
|
363
|
+
|| !Object.prototype.hasOwnProperty.call(branch.state, stateIdentityPropertyName))
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const dynamicProps = isObjectRecord(dynamicPropsValue) ? dynamicPropsValue : {};
|
|
367
|
+
const staticProps = effectiveNode[schemaPropertyName];
|
|
368
|
+
const stateIdentity = branch.state[stateIdentityPropertyName];
|
|
369
|
+
const tupleProps = Array.isArray(stateIdentity) && isObjectRecord(stateIdentity[1])
|
|
370
|
+
? stateIdentity[1]
|
|
371
|
+
: {};
|
|
372
|
+
const propsAfterTuple = mergeRuntimeSchemaPatch(isObjectRecord(staticProps) ? staticProps : {}, tupleProps);
|
|
373
|
+
const mergedProps = mergeRuntimeSchemaPatch(isObjectRecord(propsAfterTuple) ? propsAfterTuple : {}, dynamicProps);
|
|
374
|
+
const mergedRuntimeProps = isObjectRecord(mergedProps)
|
|
375
|
+
? mergedProps
|
|
376
|
+
: dynamicProps;
|
|
377
|
+
const syntheticNode = {
|
|
378
|
+
...(reactionComponentName ? { 'x-component': reactionComponentName } : {}),
|
|
379
|
+
...(reactionDecoratorName ? { 'x-decorator': reactionDecoratorName } : {}),
|
|
380
|
+
[schemaPropertyName]: mergedRuntimeProps,
|
|
381
|
+
};
|
|
382
|
+
const dynamicIssues = [];
|
|
383
|
+
validateRuntimeComponentSecurity(syntheticNode, dynamicIssues, dynamicPropsPath, { schemaRoot: syntheticNode });
|
|
384
|
+
if (statePropertyName === 'componentProps') {
|
|
385
|
+
if (reactionComponentName === 'I18nEditor'
|
|
386
|
+
&& Object.prototype.hasOwnProperty.call(dynamicProps, 'fieldMap')) {
|
|
387
|
+
validateRuntimeI18nFieldMap(mergedRuntimeProps.fieldMap, dynamicIssues, `${dynamicPropsPath}.fieldMap`);
|
|
388
|
+
}
|
|
389
|
+
const dynamicBindingKeys = new Set([
|
|
390
|
+
'dataKey',
|
|
391
|
+
...(reactionComponentName
|
|
392
|
+
? (DATA_BINDING_MANUAL_KEYS[reactionComponentName] ?? [])
|
|
393
|
+
: []),
|
|
394
|
+
]);
|
|
395
|
+
const affectsDataBinding = [...dynamicBindingKeys].some(key => (Object.prototype.hasOwnProperty.call(dynamicProps, key)));
|
|
396
|
+
if (affectsDataBinding) {
|
|
397
|
+
const dataBindingAuditNode = {
|
|
398
|
+
...createRuntimeSchemaNodeAuditSnapshot(effectiveNode),
|
|
399
|
+
...(reactionComponentName ? { 'x-component': reactionComponentName } : {}),
|
|
400
|
+
'x-component-props': mergedRuntimeProps,
|
|
401
|
+
};
|
|
402
|
+
const dataBindingIssues = [];
|
|
403
|
+
validateRuntimeDataBindingNode(dataBindingAuditNode, dataBindingIssues, dynamicPropsPath, reactionComponentName);
|
|
404
|
+
dataBindingIssues.forEach((issue) => {
|
|
405
|
+
if (issue.code === 'invalid-data-key'
|
|
406
|
+
&& !Object.prototype.hasOwnProperty.call(dynamicProps, 'dataKey'))
|
|
407
|
+
return;
|
|
408
|
+
dynamicIssues.push(issue);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const syntheticPropsPath = `${dynamicPropsPath}.${schemaPropertyName}`;
|
|
413
|
+
dynamicIssues.forEach((issue) => {
|
|
414
|
+
let issuePath = issue.path;
|
|
415
|
+
if (issue.path === syntheticPropsPath) {
|
|
416
|
+
issuePath = dynamicPropsPath;
|
|
417
|
+
}
|
|
418
|
+
else if (issue.path.startsWith(`${syntheticPropsPath}.`)) {
|
|
419
|
+
issuePath = `${dynamicPropsPath}${issue.path.slice(syntheticPropsPath.length)}`;
|
|
420
|
+
}
|
|
421
|
+
issues.push({
|
|
422
|
+
...issue,
|
|
423
|
+
path: issuePath,
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
if (componentName
|
|
429
|
+
&& RUNTIME_FIELD_VALUE_AUTO_NETWORK_COMPONENTS.has(componentName)) {
|
|
430
|
+
const fieldValueExpressionPaths = [
|
|
431
|
+
...findRuntimeSchemaExpressionPaths(auditNode.default, `${nodePath}.default`),
|
|
432
|
+
...findRuntimeReactionFieldValueExpressionPaths(reactions, `${nodePath}.x-reactions`),
|
|
433
|
+
];
|
|
434
|
+
fieldValueExpressionPaths.forEach((sinkPath) => {
|
|
435
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', sinkPath, 'Runtime 数据表达式不能作为资源组件字段值触发浏览器自动联网');
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
['x-component-props', 'x-decorator-props'].forEach((propertyName) => {
|
|
439
|
+
const runtimeProps = auditNode[propertyName];
|
|
440
|
+
if (!isObjectRecord(runtimeProps))
|
|
441
|
+
return;
|
|
442
|
+
const runtimePropsPath = `${nodePath}.${propertyName}`;
|
|
443
|
+
const unsafeHtmlPath = findUnsafeRuntimeHtmlPath(runtimeProps, runtimePropsPath);
|
|
444
|
+
if (unsafeHtmlPath) {
|
|
445
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', unsafeHtmlPath, 'Runtime 组件或装饰器属性不允许 dangerouslySetInnerHTML 或 __html 原始 HTML');
|
|
446
|
+
}
|
|
447
|
+
const componentPropKeys = propertyName === 'x-component-props' && componentName
|
|
448
|
+
? RUNTIME_COMPONENT_AUTO_NETWORK_PROP_KEYS[componentName]
|
|
449
|
+
: undefined;
|
|
450
|
+
findRuntimeAutoNetworkExpressionPaths(runtimeProps, runtimePropsPath, false, componentPropKeys).forEach((sinkPath) => {
|
|
451
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', sinkPath, 'Runtime 数据表达式不能用于浏览器自动联网的资源或 CSS 属性');
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
const validatorConfig = auditNode['x-validator'];
|
|
455
|
+
const validatorExpressionPaths = new Set([
|
|
456
|
+
...findRuntimeDirectExpressionPaths(validatorConfig, `${nodePath}.x-validator`),
|
|
457
|
+
...findRuntimeCallableKeyExpressionPaths(validatorConfig, `${nodePath}.x-validator`, RUNTIME_SCHEMA_CALLABLE_EXPRESSION_KEYS),
|
|
458
|
+
]);
|
|
459
|
+
validatorExpressionPaths.forEach((expressionPath) => {
|
|
460
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime v1 表达式只允许无调用、无赋值的数据读取,事件能力必须由受信组件提供');
|
|
461
|
+
});
|
|
462
|
+
findRuntimeReactionValidatorExpressionPaths(reactions, `${nodePath}.x-reactions`).forEach((expressionPath) => {
|
|
463
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime v1 表达式只允许无调用、无赋值的数据读取,事件能力必须由受信组件提供');
|
|
464
|
+
});
|
|
465
|
+
const decoratorProps = auditNode['x-decorator-props'];
|
|
466
|
+
if (decoratorName && isObjectRecord(decoratorProps)) {
|
|
467
|
+
validateRuntimeCallablePropPaths(decoratorProps, RUNTIME_DECORATOR_CALLABLE_EXPRESSION_PROP_PATHS[decoratorName], `${nodePath}.x-decorator-props`, issues);
|
|
468
|
+
validateRuntimeCallablePropKeyPaths(decoratorProps, RUNTIME_DECORATOR_CALLABLE_EXPRESSION_PROP_KEY_PATHS[decoratorName], `${nodePath}.x-decorator-props`, issues);
|
|
469
|
+
if (decoratorName === 'FormItem') {
|
|
470
|
+
findRuntimeDirectExpressionPaths(decoratorProps.rules, `${nodePath}.x-decorator-props.rules`).forEach((expressionPath) => {
|
|
471
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime v1 表达式只允许无调用、无赋值的数据读取,事件能力必须由受信组件提供');
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const componentProps = auditNode['x-component-props'];
|
|
476
|
+
if (!isObjectRecord(componentProps))
|
|
477
|
+
return;
|
|
478
|
+
if (componentName) {
|
|
479
|
+
if (componentName === 'I18nEditor') {
|
|
480
|
+
['inSchema', 'outSchema'].forEach((propertyName) => {
|
|
481
|
+
if (!Object.prototype.hasOwnProperty.call(componentProps, propertyName))
|
|
482
|
+
return;
|
|
483
|
+
const nestedSchema = componentProps[propertyName];
|
|
484
|
+
const nestedSchemaPath = `${nodePath}.x-component-props.${propertyName}`;
|
|
485
|
+
validateRuntimeStaticComponentNames(nestedSchema, issues, nestedSchemaPath);
|
|
486
|
+
validateRuntimeComponentSecurity(nestedSchema, issues, nestedSchemaPath);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (Object.prototype.hasOwnProperty.call(componentProps, 'component')) {
|
|
490
|
+
const { component } = componentProps;
|
|
491
|
+
if (component !== false
|
|
492
|
+
&& !(typeof component === 'string'
|
|
493
|
+
&& (isRuntimeSchemaExpression(component)
|
|
494
|
+
|| RUNTIME_SAFE_NATIVE_COMPONENT_TAGS.has(component)))) {
|
|
495
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${nodePath}.x-component-props.component`, 'Runtime component 只允许 false 或安全的原生布局标签');
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
validateRuntimeCallablePropPaths(componentProps, RUNTIME_COMPONENT_CALLABLE_EXPRESSION_PROP_PATHS[componentName], `${nodePath}.x-component-props`, issues);
|
|
499
|
+
validateRuntimeCallablePropKeyPaths(componentProps, RUNTIME_COMPONENT_CALLABLE_EXPRESSION_PROP_KEY_PATHS[componentName], `${nodePath}.x-component-props`, issues);
|
|
500
|
+
RUNTIME_NAVIGATION_PROP_KEYS[componentName]?.forEach((propertyName) => {
|
|
501
|
+
if (!Object.prototype.hasOwnProperty.call(componentProps, propertyName))
|
|
502
|
+
return;
|
|
503
|
+
const navigationValue = componentProps[propertyName];
|
|
504
|
+
const navigationPath = `${nodePath}.x-component-props.${propertyName}`;
|
|
505
|
+
const navigationExpressionPaths = findRuntimeSchemaExpressionPaths(navigationValue, navigationPath);
|
|
506
|
+
if (navigationExpressionPaths.length > 0) {
|
|
507
|
+
navigationExpressionPaths.forEach((expressionPath) => {
|
|
508
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', expressionPath, 'Runtime 导航地址不允许使用数据表达式');
|
|
509
|
+
});
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const navigationIsSafe = propertyName === 'ping'
|
|
513
|
+
? isSafeRuntimeNavigationPing(navigationValue)
|
|
514
|
+
: isSafeRuntimeNavigationHref(resolveRuntimeNavigationHref(navigationValue));
|
|
515
|
+
if (navigationIsSafe)
|
|
516
|
+
return;
|
|
517
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', navigationPath, 'Runtime 导航只允许相对地址或 http、https、mailto、tel 协议');
|
|
518
|
+
});
|
|
519
|
+
RUNTIME_SEARCH_REQUEST_PROP_KEYS[componentName]?.forEach((propertyName) => {
|
|
520
|
+
if (!Object.prototype.hasOwnProperty.call(componentProps, propertyName))
|
|
521
|
+
return;
|
|
522
|
+
if (componentName === 'SearchSelect'
|
|
523
|
+
&& propertyName === 'labelAPI'
|
|
524
|
+
&& typeof componentProps[propertyName] === 'boolean') {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
validateRuntimeRequestConfig(componentProps[propertyName], issues, `${nodePath}.x-component-props.${propertyName}`);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (componentName !== 'Upload')
|
|
531
|
+
return;
|
|
532
|
+
RUNTIME_UPLOAD_NETWORK_KEYS.forEach((key) => {
|
|
533
|
+
if (!Object.prototype.hasOwnProperty.call(componentProps, key))
|
|
534
|
+
return;
|
|
535
|
+
pushRuntimeIssue(issues, 'runtime-unsafe-request-config', `${nodePath}.x-component-props.${key}`, `Runtime Upload v1 不允许 ${key},网络上传必须由宿主受信能力接管`);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RUNTIME_DOCUMENT_SIDECAR_PROP } from "../shared/schema.js";
|
|
2
|
+
import type { IFormilySchemaInput } from "../transformers/index.js";
|
|
3
|
+
import type { ISchemaTransformer } from "../types.js";
|
|
4
|
+
import type { RuntimeAPIRequestConfigV1, RuntimeDictConfigV1, RuntimeDocumentMetadataV1, RuntimeDocumentV1, RuntimeEntityConfigV1, RuntimeStoreConfigV1 } from "./contracts.js";
|
|
5
|
+
import type { IRuntimeDocumentValidationResult, IRuntimeEnvironmentScopeValidationResult } from "./document-core.js";
|
|
6
|
+
export { RuntimeDocumentValidationError, } from "./document-core.js";
|
|
7
|
+
export type { IRuntimeDocumentValidationIssue, IRuntimeDocumentValidationResult, IRuntimeEnvironmentScopeValidationResult, } from "./document-core.js";
|
|
8
|
+
export { isAllowedRuntimeDataKeyPath } from "./document-expressions.js";
|
|
9
|
+
export { createRuntimeEntitySchemaRoot } from "./document-entity.js";
|
|
10
|
+
export declare const isRuntimeDocumentCandidate: (value: unknown) => boolean;
|
|
11
|
+
export declare const validateRuntimeDocument: (value: unknown) => IRuntimeDocumentValidationResult;
|
|
12
|
+
export declare const validateRuntimeEnvironmentScope: (value: unknown) => IRuntimeEnvironmentScopeValidationResult;
|
|
13
|
+
export declare const assertRuntimeDocument: (value: unknown) => RuntimeDocumentV1;
|
|
14
|
+
export declare const createRuntimeDocumentTransformer: (baseTransformer: ISchemaTransformer<IFormilySchemaInput>) => ISchemaTransformer<RuntimeDocumentV1>;
|
|
15
|
+
export { RUNTIME_DOCUMENT_SIDECAR_PROP };
|
|
16
|
+
export type { RuntimeAPIRequestConfigV1, RuntimeDictConfigV1, RuntimeDocumentMetadataV1, RuntimeEntityConfigV1, RuntimeStoreConfigV1, };
|