@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,25 @@
|
|
|
1
|
+
import { type I18nEditorProps } from '@yimoka/antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { RuntimeDocumentV1, RuntimeLanguageCatalogItem } from "./contracts.js";
|
|
4
|
+
import { type IRuntimeI18nDiagnostic } from "./i18n-schema.js";
|
|
5
|
+
export { createRuntimeI18nSchemas, resolveRuntimeLanguageSource, validateRuntimeI18nConfig, } from "./i18n-schema.js";
|
|
6
|
+
export type { IResolveRuntimeLanguageSourceOptions, IRuntimeI18nDiagnostic, IRuntimeI18nSchemaGenerationResult, IRuntimeLanguageSourceResolution, } from "./i18n-schema.js";
|
|
7
|
+
export interface IRuntimeI18nConfirmRequest {
|
|
8
|
+
kind: 'disable' | 'regenerate-schema';
|
|
9
|
+
message: string;
|
|
10
|
+
title: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IRuntimeI18nSettingsPanelProps {
|
|
13
|
+
confirmAction?: (request: IRuntimeI18nConfirmRequest) => boolean | Promise<boolean>;
|
|
14
|
+
document: RuntimeDocumentV1;
|
|
15
|
+
languageCatalog?: RuntimeLanguageCatalogItem[];
|
|
16
|
+
onDraftValidityChange?: (valid: boolean) => void;
|
|
17
|
+
onDocumentChange: (document: RuntimeDocumentV1) => void;
|
|
18
|
+
resetKey?: React.Key;
|
|
19
|
+
}
|
|
20
|
+
export interface IRuntimeI18nEditorProps extends Omit<I18nEditorProps, 'fieldMap' | 'langAPI'> {
|
|
21
|
+
fieldMap?: Record<string, string>;
|
|
22
|
+
onDiagnostic?: (diagnostic: IRuntimeI18nDiagnostic) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare const RuntimeI18nSettingsPanel: (props: IRuntimeI18nSettingsPanelProps) => React.JSX.Element;
|
|
25
|
+
export declare const RuntimeI18nEditor: ({ config: _config, fieldMap, onDiagnostic, readOnly, store, ...props }: IRuntimeI18nEditorProps) => React.JSX.Element;
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useExpressionScope, useField, } from '@formily/react';
|
|
4
|
+
import { Alert as RuntimeAlert, I18nEditor, } from '@yimoka/antd';
|
|
5
|
+
import { runAPI, } from '@yimoka/store';
|
|
6
|
+
import { Alert, AutoComplete, Button, Checkbox, Flex, Modal, Select, Space, Switch, Typography, } from 'antd';
|
|
7
|
+
import { cloneDeep } from 'lodash-es';
|
|
8
|
+
import { useEffect, useMemo, useRef, useState, } from 'react';
|
|
9
|
+
import { isSafeSchemaObjectKey } from "../shared/schema.js";
|
|
10
|
+
import { createRuntimeEntitySchemaRoot, validateRuntimeDocument, } from "./document.js";
|
|
11
|
+
import { createI18nDiagnostic, createRuntimeI18nSchemas, isObjectRecord, normalizeRuntimeLanguageCatalog, resolveRuntimeLanguageSource, RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID, stringifyNormalizedJson, } from "./i18n-schema.js";
|
|
12
|
+
import { RuntimeJsonEditor } from "./settings/RuntimeJsonEditor.js";
|
|
13
|
+
export { createRuntimeI18nSchemas, resolveRuntimeLanguageSource, validateRuntimeI18nConfig, } from "./i18n-schema.js";
|
|
14
|
+
const createMappingRows = (document) => {
|
|
15
|
+
const entries = Object.entries(document.entityConfig?.i18nFieldMap ?? {});
|
|
16
|
+
if (!entries.length) {
|
|
17
|
+
return [{
|
|
18
|
+
id: 'i18n-map-0',
|
|
19
|
+
sourceField: '',
|
|
20
|
+
targetField: '',
|
|
21
|
+
}];
|
|
22
|
+
}
|
|
23
|
+
return entries.map(([sourceField, targetField], index) => ({
|
|
24
|
+
id: `i18n-map-${index}`,
|
|
25
|
+
sourceField,
|
|
26
|
+
targetField,
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
const createMappingFingerprint = (document) => (stringifyNormalizedJson(document.entityConfig?.i18nFieldMap ?? {}));
|
|
30
|
+
const createAdvancedSchemaFingerprint = (document) => (stringifyNormalizedJson({
|
|
31
|
+
input: document.entityConfig?.i18nInSchema,
|
|
32
|
+
output: document.entityConfig?.i18nOutSchema,
|
|
33
|
+
}));
|
|
34
|
+
const createLanguageSourceFingerprint = (document) => (stringifyNormalizedJson(document.entityConfig?.i18nLangAPI));
|
|
35
|
+
const createI18nConfigurationFingerprint = (document) => (stringifyNormalizedJson({
|
|
36
|
+
fieldMap: document.entityConfig?.i18nFieldMap,
|
|
37
|
+
input: document.entityConfig?.i18nInSchema,
|
|
38
|
+
langAPI: document.entityConfig?.i18nLangAPI,
|
|
39
|
+
output: document.entityConfig?.i18nOutSchema,
|
|
40
|
+
}));
|
|
41
|
+
const validateMappingRows = (rows) => {
|
|
42
|
+
const sourceFields = new Set();
|
|
43
|
+
const targetFields = new Set();
|
|
44
|
+
const fieldMap = {};
|
|
45
|
+
for (const row of rows) {
|
|
46
|
+
const sourceField = row.sourceField.trim();
|
|
47
|
+
const targetField = row.targetField.trim();
|
|
48
|
+
if (!sourceField
|
|
49
|
+
|| !targetField
|
|
50
|
+
|| !isSafeSchemaObjectKey(sourceField)
|
|
51
|
+
|| !isSafeSchemaObjectKey(targetField)
|
|
52
|
+
|| sourceFields.has(sourceField)
|
|
53
|
+
|| targetFields.has(targetField)) {
|
|
54
|
+
return {
|
|
55
|
+
message: 'invalid-i18n-field-map: 两侧字段必须安全、非空且分别唯一',
|
|
56
|
+
valid: false,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
sourceFields.add(sourceField);
|
|
60
|
+
targetFields.add(targetField);
|
|
61
|
+
fieldMap[sourceField] = targetField;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
fieldMap,
|
|
65
|
+
valid: Object.keys(fieldMap).length > 0,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const createDocumentWithEntityConfig = (document) => {
|
|
69
|
+
const nextDocument = cloneDeep(document);
|
|
70
|
+
nextDocument.entityConfig = {
|
|
71
|
+
...nextDocument.entityConfig,
|
|
72
|
+
};
|
|
73
|
+
return nextDocument;
|
|
74
|
+
};
|
|
75
|
+
const emitValidRuntimeDocument = (document, onDocumentChange) => {
|
|
76
|
+
const result = validateRuntimeDocument(document);
|
|
77
|
+
if (!result.valid || !result.document) {
|
|
78
|
+
return result.issues
|
|
79
|
+
.map(issue => `${issue.code}: ${issue.message}`)
|
|
80
|
+
.join(';');
|
|
81
|
+
}
|
|
82
|
+
onDocumentChange(result.document);
|
|
83
|
+
return undefined;
|
|
84
|
+
};
|
|
85
|
+
const formatSchemaJson = (schema) => (schema ? JSON.stringify(schema, null, 2) : '');
|
|
86
|
+
const parseOptionalSchemaJson = (value) => {
|
|
87
|
+
if (!value.trim())
|
|
88
|
+
return undefined;
|
|
89
|
+
return JSON.parse(value);
|
|
90
|
+
};
|
|
91
|
+
const defaultConfirmAction = (request) => new Promise((resolve) => {
|
|
92
|
+
Modal.confirm({
|
|
93
|
+
content: request.message,
|
|
94
|
+
title: request.title,
|
|
95
|
+
onCancel: () => resolve(false),
|
|
96
|
+
onOk: () => resolve(true),
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
const hasAdvancedI18nSchema = (document, generated) => {
|
|
100
|
+
const currentInput = document.entityConfig?.i18nInSchema;
|
|
101
|
+
const currentOutput = document.entityConfig?.i18nOutSchema;
|
|
102
|
+
if (!currentInput && !currentOutput)
|
|
103
|
+
return false;
|
|
104
|
+
return stringifyNormalizedJson(currentInput) !== stringifyNormalizedJson(generated.inputSchema)
|
|
105
|
+
|| stringifyNormalizedJson(currentOutput) !== stringifyNormalizedJson(generated.outputSchema);
|
|
106
|
+
};
|
|
107
|
+
const createRuntimeI18nStoreAPI = (langAPI, store) => {
|
|
108
|
+
if (!langAPI)
|
|
109
|
+
return false;
|
|
110
|
+
if (typeof langAPI === 'function')
|
|
111
|
+
return langAPI;
|
|
112
|
+
if (!store?.apiExecutor)
|
|
113
|
+
return false;
|
|
114
|
+
const normalizedLangAPI = {
|
|
115
|
+
...langAPI,
|
|
116
|
+
params: {
|
|
117
|
+
...(langAPI.params ?? {}),
|
|
118
|
+
name: langAPI.params?.name ?? 'i18nLanguageOptions',
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
return async (params) => runAPI(normalizedLangAPI, store.apiExecutor, params);
|
|
122
|
+
};
|
|
123
|
+
const RuntimeI18nSettingsPanelContent = ({ confirmAction = defaultConfirmAction, document, languageCatalog = [], onDraftValidityChange, onDocumentChange, }) => {
|
|
124
|
+
const documentRef = useRef(document);
|
|
125
|
+
const mountedRef = useRef(false);
|
|
126
|
+
const confirmationGenerationRef = useRef(0);
|
|
127
|
+
const mappingFingerprintRef = useRef(createMappingFingerprint(document));
|
|
128
|
+
const advancedSchemaFingerprintRef = useRef(createAdvancedSchemaFingerprint(document));
|
|
129
|
+
const languageSourceFingerprintRef = useRef(createLanguageSourceFingerprint(document));
|
|
130
|
+
const [mappingRows, setMappingRows] = useState(() => createMappingRows(document));
|
|
131
|
+
const [mappingError, setMappingError] = useState();
|
|
132
|
+
const [schemaError, setSchemaError] = useState();
|
|
133
|
+
const [languageError, setLanguageError] = useState();
|
|
134
|
+
const [enabledDraft, setEnabledDraft] = useState(() => Object.keys(document.entityConfig?.i18nFieldMap ?? {}).length > 0);
|
|
135
|
+
const [selectedSchemaFields, setSelectedSchemaFields] = useState(() => [...new Set(Object.values(document.entityConfig?.i18nFieldMap ?? {}))]);
|
|
136
|
+
const selectedSchemaFieldsRef = useRef(selectedSchemaFields);
|
|
137
|
+
const mappingRowSequenceRef = useRef(Math.max(0, mappingRows.length - 1));
|
|
138
|
+
const [inputSchemaJson, setInputSchemaJson] = useState(() => formatSchemaJson(document.entityConfig?.i18nInSchema));
|
|
139
|
+
const [outputSchemaJson, setOutputSchemaJson] = useState(() => formatSchemaJson(document.entityConfig?.i18nOutSchema));
|
|
140
|
+
const [languageSourceJson, setLanguageSourceJson] = useState(() => (document.entityConfig?.i18nLangAPI
|
|
141
|
+
? JSON.stringify(document.entityConfig.i18nLangAPI, null, 2)
|
|
142
|
+
: ''));
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
mountedRef.current = true;
|
|
145
|
+
confirmationGenerationRef.current += 1;
|
|
146
|
+
return () => {
|
|
147
|
+
mountedRef.current = false;
|
|
148
|
+
confirmationGenerationRef.current += 1;
|
|
149
|
+
};
|
|
150
|
+
}, []);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
onDraftValidityChange?.(!mappingError && !schemaError && !languageError);
|
|
153
|
+
}, [languageError, mappingError, onDraftValidityChange, schemaError]);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
documentRef.current = document;
|
|
156
|
+
const nextFingerprint = createMappingFingerprint(document);
|
|
157
|
+
if (nextFingerprint !== mappingFingerprintRef.current) {
|
|
158
|
+
mappingFingerprintRef.current = nextFingerprint;
|
|
159
|
+
const nextRows = createMappingRows(document);
|
|
160
|
+
mappingRowSequenceRef.current = Math.max(0, nextRows.length - 1);
|
|
161
|
+
setMappingRows(nextRows);
|
|
162
|
+
setMappingError(undefined);
|
|
163
|
+
setEnabledDraft(Object.keys(document.entityConfig?.i18nFieldMap ?? {}).length > 0);
|
|
164
|
+
const nextSelectedSchemaFields = [
|
|
165
|
+
...new Set(Object.values(document.entityConfig?.i18nFieldMap ?? {})),
|
|
166
|
+
];
|
|
167
|
+
selectedSchemaFieldsRef.current = nextSelectedSchemaFields;
|
|
168
|
+
setSelectedSchemaFields(nextSelectedSchemaFields);
|
|
169
|
+
}
|
|
170
|
+
const nextAdvancedFingerprint = createAdvancedSchemaFingerprint(document);
|
|
171
|
+
if (nextAdvancedFingerprint !== advancedSchemaFingerprintRef.current) {
|
|
172
|
+
advancedSchemaFingerprintRef.current = nextAdvancedFingerprint;
|
|
173
|
+
setInputSchemaJson(formatSchemaJson(document.entityConfig?.i18nInSchema));
|
|
174
|
+
setOutputSchemaJson(formatSchemaJson(document.entityConfig?.i18nOutSchema));
|
|
175
|
+
setSchemaError(undefined);
|
|
176
|
+
}
|
|
177
|
+
const nextLanguageFingerprint = createLanguageSourceFingerprint(document);
|
|
178
|
+
if (nextLanguageFingerprint !== languageSourceFingerprintRef.current) {
|
|
179
|
+
languageSourceFingerprintRef.current = nextLanguageFingerprint;
|
|
180
|
+
setLanguageSourceJson(document.entityConfig?.i18nLangAPI
|
|
181
|
+
? JSON.stringify(document.entityConfig.i18nLangAPI, null, 2)
|
|
182
|
+
: '');
|
|
183
|
+
setLanguageError(undefined);
|
|
184
|
+
}
|
|
185
|
+
}, [document]);
|
|
186
|
+
const languageResolution = useMemo(() => resolveRuntimeLanguageSource({
|
|
187
|
+
document,
|
|
188
|
+
languageCatalog: normalizeRuntimeLanguageCatalog(languageCatalog).items,
|
|
189
|
+
}), [document, languageCatalog]);
|
|
190
|
+
const normalizedLanguageCatalog = useMemo(() => normalizeRuntimeLanguageCatalog(languageCatalog), [languageCatalog]);
|
|
191
|
+
const effectiveEntitySchema = useMemo(() => createRuntimeEntitySchemaRoot(document.schema, document.entityConfig, document.store), [document.entityConfig, document.schema, document.store]);
|
|
192
|
+
const configurableI18nSchema = document.entityConfig?.i18nInSchema
|
|
193
|
+
?? effectiveEntitySchema;
|
|
194
|
+
const targetFieldOptions = useMemo(() => Object.entries(configurableI18nSchema.properties ?? {}).map(([value, schema]) => ({
|
|
195
|
+
label: typeof schema.title === 'string' ? `${schema.title} (${value})` : value,
|
|
196
|
+
value,
|
|
197
|
+
})), [configurableI18nSchema.properties]);
|
|
198
|
+
const sourceFieldOptions = useMemo(() => {
|
|
199
|
+
const store = isObjectRecord(document.store) ? document.store : {};
|
|
200
|
+
const defaultValues = isObjectRecord(store.defaultValues) ? store.defaultValues : {};
|
|
201
|
+
return Object.keys(defaultValues).map(value => ({ label: value, value }));
|
|
202
|
+
}, [document.store]);
|
|
203
|
+
const commitMappingRows = (nextRows) => {
|
|
204
|
+
const result = validateMappingRows(nextRows);
|
|
205
|
+
setMappingError(result.message);
|
|
206
|
+
if (!result.valid || !result.fieldMap) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const nextDocument = createDocumentWithEntityConfig(documentRef.current);
|
|
210
|
+
nextDocument.entityConfig.i18nFieldMap = result.fieldMap;
|
|
211
|
+
const error = emitValidRuntimeDocument(nextDocument, onDocumentChange);
|
|
212
|
+
if (!error) {
|
|
213
|
+
mappingFingerprintRef.current = stringifyNormalizedJson(result.fieldMap);
|
|
214
|
+
}
|
|
215
|
+
setMappingError(error);
|
|
216
|
+
};
|
|
217
|
+
const updateMappingRow = (id, key, value) => {
|
|
218
|
+
const nextRows = mappingRows.map(row => (row.id === id ? { ...row, [key]: value } : row));
|
|
219
|
+
setMappingRows(nextRows);
|
|
220
|
+
commitMappingRows(nextRows);
|
|
221
|
+
};
|
|
222
|
+
const removeMappingRow = (id) => {
|
|
223
|
+
const remainingRows = mappingRows.filter(row => row.id !== id);
|
|
224
|
+
if (!remainingRows.length) {
|
|
225
|
+
void toggleI18n(false);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
setMappingRows(remainingRows);
|
|
229
|
+
commitMappingRows(remainingRows);
|
|
230
|
+
};
|
|
231
|
+
const addMappingRow = () => {
|
|
232
|
+
mappingRowSequenceRef.current += 1;
|
|
233
|
+
const nextRows = [
|
|
234
|
+
...mappingRows,
|
|
235
|
+
{
|
|
236
|
+
id: `i18n-map-${mappingRowSequenceRef.current}`,
|
|
237
|
+
sourceField: '',
|
|
238
|
+
targetField: '',
|
|
239
|
+
},
|
|
240
|
+
];
|
|
241
|
+
setMappingRows(nextRows);
|
|
242
|
+
commitMappingRows(nextRows);
|
|
243
|
+
};
|
|
244
|
+
const toggleI18n = async (checked) => {
|
|
245
|
+
if (checked) {
|
|
246
|
+
setEnabledDraft(true);
|
|
247
|
+
commitMappingRows(mappingRows);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const confirmationBaseline = createI18nConfigurationFingerprint(documentRef.current);
|
|
251
|
+
const confirmationGeneration = confirmationGenerationRef.current;
|
|
252
|
+
let confirmed = false;
|
|
253
|
+
try {
|
|
254
|
+
confirmed = await confirmAction({
|
|
255
|
+
kind: 'disable',
|
|
256
|
+
message: '关闭后只删除四个多语言配置字段,Store 中已有翻译值会保留。',
|
|
257
|
+
title: '确认关闭多语言配置?',
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (!mountedRef.current || confirmationGenerationRef.current !== confirmationGeneration) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
setMappingError(`runtime-i18n-confirm-failed: ${String(error)}`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (!mountedRef.current || confirmationGenerationRef.current !== confirmationGeneration) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (!confirmed)
|
|
271
|
+
return;
|
|
272
|
+
if (confirmationBaseline !== createI18nConfigurationFingerprint(documentRef.current)) {
|
|
273
|
+
setMappingError('runtime-i18n-confirm-stale: 确认期间多语言配置已变化,请重新关闭并确认');
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const nextDocument = createDocumentWithEntityConfig(documentRef.current);
|
|
277
|
+
delete nextDocument.entityConfig.i18nFieldMap;
|
|
278
|
+
delete nextDocument.entityConfig.i18nInSchema;
|
|
279
|
+
delete nextDocument.entityConfig.i18nOutSchema;
|
|
280
|
+
delete nextDocument.entityConfig.i18nLangAPI;
|
|
281
|
+
const error = emitValidRuntimeDocument(nextDocument, onDocumentChange);
|
|
282
|
+
if (!error) {
|
|
283
|
+
setEnabledDraft(false);
|
|
284
|
+
}
|
|
285
|
+
setMappingError(error);
|
|
286
|
+
};
|
|
287
|
+
const generateSchemas = async () => {
|
|
288
|
+
const generated = createRuntimeI18nSchemas(document, selectedSchemaFieldsRef.current);
|
|
289
|
+
if (!generated.valid || !generated.inputSchema || !generated.outputSchema) {
|
|
290
|
+
setSchemaError(generated.diagnostics
|
|
291
|
+
.map(diagnostic => `${diagnostic.code}: ${diagnostic.message}`)
|
|
292
|
+
.join(';')
|
|
293
|
+
|| '未选择可生成的顶层字段');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const requiresConfirmation = hasAdvancedI18nSchema(document, generated);
|
|
297
|
+
const confirmationSchemaBaseline = requiresConfirmation
|
|
298
|
+
? stringifyNormalizedJson({
|
|
299
|
+
input: document.entityConfig?.i18nInSchema,
|
|
300
|
+
output: document.entityConfig?.i18nOutSchema,
|
|
301
|
+
})
|
|
302
|
+
: undefined;
|
|
303
|
+
if (requiresConfirmation) {
|
|
304
|
+
const confirmationGeneration = confirmationGenerationRef.current;
|
|
305
|
+
let confirmed = false;
|
|
306
|
+
try {
|
|
307
|
+
confirmed = await confirmAction({
|
|
308
|
+
kind: 'regenerate-schema',
|
|
309
|
+
message: '自动生成会覆盖当前高级输入/输出 Schema。',
|
|
310
|
+
title: '确认重新生成多语言 Schema?',
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
if (!mountedRef.current || confirmationGenerationRef.current !== confirmationGeneration) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
setSchemaError(`runtime-i18n-confirm-failed: ${String(error)}`);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (!mountedRef.current || confirmationGenerationRef.current !== confirmationGeneration) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!confirmed)
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (confirmationSchemaBaseline !== undefined
|
|
327
|
+
&& confirmationSchemaBaseline !== stringifyNormalizedJson({
|
|
328
|
+
input: documentRef.current.entityConfig?.i18nInSchema,
|
|
329
|
+
output: documentRef.current.entityConfig?.i18nOutSchema,
|
|
330
|
+
})) {
|
|
331
|
+
setSchemaError('runtime-i18n-confirm-stale: 确认期间高级多语言 Schema 已变化,请重新生成并确认');
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const latestGenerated = createRuntimeI18nSchemas(documentRef.current, selectedSchemaFieldsRef.current);
|
|
335
|
+
if (!latestGenerated.valid
|
|
336
|
+
|| !latestGenerated.inputSchema
|
|
337
|
+
|| !latestGenerated.outputSchema) {
|
|
338
|
+
setSchemaError(latestGenerated.diagnostics
|
|
339
|
+
.map(diagnostic => `${diagnostic.code}: ${diagnostic.message}`)
|
|
340
|
+
.join(';')
|
|
341
|
+
|| '确认期间文档已变化,当前字段无法生成 Schema');
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const nextDocument = createDocumentWithEntityConfig(documentRef.current);
|
|
345
|
+
nextDocument.entityConfig.i18nInSchema = latestGenerated.inputSchema;
|
|
346
|
+
nextDocument.entityConfig.i18nOutSchema = latestGenerated.outputSchema;
|
|
347
|
+
const error = emitValidRuntimeDocument(nextDocument, onDocumentChange);
|
|
348
|
+
if (!error) {
|
|
349
|
+
setInputSchemaJson(formatSchemaJson(latestGenerated.inputSchema));
|
|
350
|
+
setOutputSchemaJson(formatSchemaJson(latestGenerated.outputSchema));
|
|
351
|
+
}
|
|
352
|
+
setSchemaError(error);
|
|
353
|
+
};
|
|
354
|
+
const applyAdvancedSchemas = () => {
|
|
355
|
+
try {
|
|
356
|
+
const nextDocument = createDocumentWithEntityConfig(document);
|
|
357
|
+
const inputSchema = parseOptionalSchemaJson(inputSchemaJson);
|
|
358
|
+
const outputSchema = parseOptionalSchemaJson(outputSchemaJson);
|
|
359
|
+
if (inputSchema)
|
|
360
|
+
nextDocument.entityConfig.i18nInSchema = inputSchema;
|
|
361
|
+
else
|
|
362
|
+
delete nextDocument.entityConfig.i18nInSchema;
|
|
363
|
+
if (outputSchema)
|
|
364
|
+
nextDocument.entityConfig.i18nOutSchema = outputSchema;
|
|
365
|
+
else
|
|
366
|
+
delete nextDocument.entityConfig.i18nOutSchema;
|
|
367
|
+
setSchemaError(emitValidRuntimeDocument(nextDocument, onDocumentChange));
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
setSchemaError(`invalid-runtime-document: ${String(error)}`);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
const selectLanguageCatalog = (catalogId) => {
|
|
374
|
+
const item = normalizedLanguageCatalog.items.find(candidate => candidate.id === catalogId);
|
|
375
|
+
if (!item)
|
|
376
|
+
return;
|
|
377
|
+
const nextDocument = createDocumentWithEntityConfig(document);
|
|
378
|
+
nextDocument.entityConfig.i18nLangAPI = cloneDeep(item.langAPI);
|
|
379
|
+
const error = emitValidRuntimeDocument(nextDocument, onDocumentChange);
|
|
380
|
+
if (!error) {
|
|
381
|
+
setLanguageSourceJson(JSON.stringify(item.langAPI, null, 2));
|
|
382
|
+
}
|
|
383
|
+
setLanguageError(error);
|
|
384
|
+
};
|
|
385
|
+
const applyLanguageSourceJson = () => {
|
|
386
|
+
try {
|
|
387
|
+
const nextDocument = createDocumentWithEntityConfig(document);
|
|
388
|
+
if (languageSourceJson.trim()) {
|
|
389
|
+
nextDocument.entityConfig.i18nLangAPI = JSON.parse(languageSourceJson);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
delete nextDocument.entityConfig.i18nLangAPI;
|
|
393
|
+
}
|
|
394
|
+
setLanguageError(emitValidRuntimeDocument(nextDocument, onDocumentChange));
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
setLanguageError(`runtime-unsafe-request-config: ${String(error)}`);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
return (_jsxs(Space, { orientation: "vertical", size: "middle", style: { width: '100%' }, children: [_jsxs(Flex, { align: "center", justify: "space-between", children: [_jsx(Typography.Text, { strong: true, children: "\u591A\u8BED\u8A00" }), _jsx(Switch, { "aria-label": "\u542F\u7528\u591A\u8BED\u8A00", checked: enabledDraft, onChange: (checked) => {
|
|
401
|
+
void toggleI18n(checked);
|
|
402
|
+
} })] }), enabledDraft && (_jsxs(_Fragment, { children: [_jsxs("div", { children: [_jsx(Typography.Text, { strong: true, children: "1. \u914D\u7F6E\u591A\u8BED\u8A00\u5B57\u6BB5" }), _jsx(Typography.Paragraph, { style: { margin: '4px 0 0' }, type: "secondary", children: "\u5DE6\u4FA7\u662F Store \u4E2D\u6309\u8BED\u8A00\u4FDD\u5B58\u7684\u5BF9\u8C61\u5B57\u6BB5\uFF0C\u53F3\u4FA7\u662F\u6BCF\u79CD\u8BED\u8A00\u5B9E\u9645\u663E\u793A\u548C\u8F93\u5165\u7684\u4E1A\u52A1\u5B57\u6BB5\u3002" })] }), mappingRows.map(row => (_jsxs(Flex, { wrap: true, align: "center", gap: "small", children: [_jsx(AutoComplete, { "aria-label": "\u591A\u8BED\u8A00\u503C\u5B57\u6BB5", options: sourceFieldOptions, placeholder: "\u591A\u8BED\u8A00\u503C\u5B57\u6BB5", style: { flex: 1, minWidth: 180 }, value: row.sourceField, onChange: value => updateMappingRow(row.id, 'sourceField', value) }), _jsx(AutoComplete, { "aria-label": "\u5355\u8BED\u8A00\u5B57\u6BB5", options: targetFieldOptions, placeholder: "\u5355\u8BED\u8A00\u5B57\u6BB5", style: { flex: 1, minWidth: 180 }, value: row.targetField, onChange: value => updateMappingRow(row.id, 'targetField', value) }), _jsx(Button, { danger: true, onClick: () => removeMappingRow(row.id), children: "\u5220\u9664" })] }, row.id))), _jsx(Button, { onClick: addMappingRow, children: "\u65B0\u589E\u6620\u5C04" }), mappingError && _jsx(Alert, { showIcon: true, title: mappingError, type: "error" }), _jsxs("div", { children: [_jsx(Typography.Text, { strong: true, children: "2. \u914D\u7F6E\u6BCF\u79CD\u8BED\u8A00\u7684\u8F93\u5165\u4E0E\u5C55\u793A" }), _jsx(Typography.Paragraph, { style: { margin: '4px 0 0' }, type: "secondary", children: "\u52FE\u9009\u5B57\u6BB5\u540E\u81EA\u52A8\u751F\u6210\u8F93\u5165/\u53EA\u8BFB Schema\uFF1B\u9884\u89C8\u4E2D\u7684 I18nEditor \u4F1A\u4E3A\u6BCF\u79CD\u8BED\u8A00\u590D\u7528\u8FD9\u5957\u5B57\u6BB5\u7ED3\u6784\u3002" })] }), _jsx(Checkbox.Group, { options: targetFieldOptions, value: selectedSchemaFields, onChange: (values) => {
|
|
403
|
+
const nextSelectedSchemaFields = values.map(String);
|
|
404
|
+
selectedSchemaFieldsRef.current = nextSelectedSchemaFields;
|
|
405
|
+
setSelectedSchemaFields(nextSelectedSchemaFields);
|
|
406
|
+
} }), _jsx(Button, { onClick: () => void generateSchemas(), children: "\u81EA\u52A8\u751F\u6210 Schema" }), _jsx(RuntimeJsonEditor, { ariaLabel: "\u8F93\u5165 Schema JSON", height: 220, value: inputSchemaJson, onChange: setInputSchemaJson }), _jsx(RuntimeJsonEditor, { ariaLabel: "\u8F93\u51FA Schema JSON", height: 220, value: outputSchemaJson, onChange: setOutputSchemaJson }), _jsx(Button, { onClick: applyAdvancedSchemas, children: "\u5E94\u7528\u9AD8\u7EA7 JSON" }), schemaError && _jsx(Alert, { showIcon: true, title: schemaError, type: "error" }), _jsxs("div", { children: [_jsx(Typography.Text, { strong: true, children: "3. \u9009\u62E9\u53EF\u7F16\u8F91\u8BED\u8A00" }), _jsx(Typography.Paragraph, { style: { margin: '4px 0 0' }, type: "secondary", children: "\u8BED\u8A00\u5217\u8868\u7531\u5BBF\u4E3B\u76EE\u5F55\u63D0\u4F9B\uFF1B\u751F\u4EA7\u9875\u9762\u53EA\u4FDD\u5B58\u8BF7\u6C42\u914D\u7F6E\uFF0C\u4E0D\u7EE7\u627F\u672A\u6388\u6743\u7684\u9ED8\u8BA4\u4E1A\u52A1\u5730\u5740\u3002" })] }), normalizedLanguageCatalog.error && (_jsx(Alert, { showIcon: true, title: normalizedLanguageCatalog.error, type: "error" })), _jsx(Select, { "aria-label": "\u8BED\u8A00\u76EE\u5F55", notFoundContent: "\u5BBF\u4E3B\u672A\u63D0\u4F9B\u53EF\u9009\u9879", options: [
|
|
407
|
+
...normalizedLanguageCatalog.items.map(item => ({
|
|
408
|
+
label: item.label,
|
|
409
|
+
value: item.id,
|
|
410
|
+
})),
|
|
411
|
+
...(!languageResolution.catalogId && document.entityConfig?.i18nLangAPI
|
|
412
|
+
? [{
|
|
413
|
+
label: '自定义语言源',
|
|
414
|
+
value: RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID,
|
|
415
|
+
disabled: true,
|
|
416
|
+
}]
|
|
417
|
+
: []),
|
|
418
|
+
], placeholder: "\u5BBF\u4E3B\u672A\u63D0\u4F9B\u53EF\u9009\u9879", style: { width: '100%' }, value: languageResolution.catalogId ?? (document.entityConfig?.i18nLangAPI
|
|
419
|
+
? RUNTIME_CUSTOM_LANGUAGE_CATALOG_ID
|
|
420
|
+
: undefined), onChange: selectLanguageCatalog }), _jsx(RuntimeJsonEditor, { ariaLabel: "\u8BED\u8A00\u6E90 JSON", height: 180, value: languageSourceJson, onChange: setLanguageSourceJson }), _jsx(Button, { onClick: applyLanguageSourceJson, children: "\u5E94\u7528\u8BED\u8A00\u6E90 JSON" }), languageResolution.diagnostics.map(diagnostic => (_jsx(Alert, { showIcon: true, title: `${diagnostic.code}: ${diagnostic.message}`, type: "warning" }, diagnostic.code))), languageError && _jsx(Alert, { showIcon: true, title: languageError, type: "error" })] }))] }));
|
|
421
|
+
};
|
|
422
|
+
export const RuntimeI18nSettingsPanel = (props) => (_createElement(RuntimeI18nSettingsPanelContent, { ...props, key: props.resetKey }));
|
|
423
|
+
export const RuntimeI18nEditor = ({ config: _config, fieldMap, onDiagnostic, readOnly, store, ...props }) => {
|
|
424
|
+
const field = useField();
|
|
425
|
+
const scope = useExpressionScope();
|
|
426
|
+
const scopeConfig = scope?.$config;
|
|
427
|
+
const explicitLanguageSource = scopeConfig?.i18nLangAPI;
|
|
428
|
+
const scopeFieldMap = useMemo(() => Object.fromEntries(Object.entries(scopeConfig?.i18nFieldMap ?? {})
|
|
429
|
+
.map(([sourceField, targetField]) => [
|
|
430
|
+
String(sourceField),
|
|
431
|
+
String(targetField),
|
|
432
|
+
])), [scopeConfig?.i18nFieldMap]);
|
|
433
|
+
const resolvedStore = store ?? scope?.$store;
|
|
434
|
+
const resolvedLanguageAPI = useMemo(() => createRuntimeI18nStoreAPI(explicitLanguageSource, resolvedStore), [explicitLanguageSource, resolvedStore]);
|
|
435
|
+
const diagnostic = useMemo(() => (explicitLanguageSource
|
|
436
|
+
? undefined
|
|
437
|
+
: createI18nDiagnostic('missing-i18n-language-source', '$config.i18nLangAPI', '缺少显式语言源,已禁用 I18nEditor 的默认业务请求')), [explicitLanguageSource]);
|
|
438
|
+
const fieldForcesReadOnly = Boolean(field?.readOnly
|
|
439
|
+
|| field?.disabled
|
|
440
|
+
|| field?.pattern === 'readPretty'
|
|
441
|
+
|| field?.pattern === 'disabled');
|
|
442
|
+
useEffect(() => {
|
|
443
|
+
if (diagnostic)
|
|
444
|
+
onDiagnostic?.(diagnostic);
|
|
445
|
+
}, [diagnostic, onDiagnostic]);
|
|
446
|
+
return (_jsxs(_Fragment, { children: [diagnostic && (_jsx(RuntimeAlert, { showIcon: true, title: `${diagnostic.code}: ${diagnostic.message}`, type: "warning" })), _jsx(I18nEditor, { ...props, config: scopeConfig, fieldMap: fieldMap ?? scopeFieldMap, langAPI: resolvedLanguageAPI, readOnly: fieldForcesReadOnly ? true : readOnly, store: resolvedStore })] }));
|
|
447
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const resolveRuntimeNavigationHref: (value: unknown) => string;
|
|
2
|
+
export declare const isSafeRuntimeNavigationHref: (href: string) => boolean;
|
|
3
|
+
export declare const isSafeRuntimeNavigationPing: (value: unknown) => value is string;
|
|
4
|
+
export declare const sanitizeRuntimeNavigationHref: (value: unknown) => string;
|
|
5
|
+
export declare const sanitizeRuntimeNavigationPing: (value: unknown) => string | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const RUNTIME_NAVIGATION_SCHEME_PATTERN = /^([a-z][a-z\d+.-]*):/i;
|
|
2
|
+
const RUNTIME_NAVIGATION_ALLOWED_SCHEMES = new Set([
|
|
3
|
+
'http',
|
|
4
|
+
'https',
|
|
5
|
+
'mailto',
|
|
6
|
+
'tel',
|
|
7
|
+
]);
|
|
8
|
+
const hasRuntimeNavigationControlCharacter = (value) => (Array.from(value).some((character) => {
|
|
9
|
+
const code = character.charCodeAt(0);
|
|
10
|
+
return code <= 31 || code === 127;
|
|
11
|
+
}));
|
|
12
|
+
export const resolveRuntimeNavigationHref = (value) => {
|
|
13
|
+
if (typeof value === 'string')
|
|
14
|
+
return value;
|
|
15
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
16
|
+
return '';
|
|
17
|
+
const record = value;
|
|
18
|
+
return ['pathname', 'search', 'hash']
|
|
19
|
+
.map(key => (typeof record[key] === 'string' ? record[key] : ''))
|
|
20
|
+
.join('');
|
|
21
|
+
};
|
|
22
|
+
export const isSafeRuntimeNavigationHref = (href) => {
|
|
23
|
+
if (href.trim() !== href || hasRuntimeNavigationControlCharacter(href))
|
|
24
|
+
return false;
|
|
25
|
+
if (href.startsWith('//') || href.includes('\\'))
|
|
26
|
+
return false;
|
|
27
|
+
const scheme = href.match(RUNTIME_NAVIGATION_SCHEME_PATTERN)?.[1]?.toLowerCase();
|
|
28
|
+
return !scheme || RUNTIME_NAVIGATION_ALLOWED_SCHEMES.has(scheme);
|
|
29
|
+
};
|
|
30
|
+
export const isSafeRuntimeNavigationPing = (value) => {
|
|
31
|
+
if (typeof value !== 'string')
|
|
32
|
+
return false;
|
|
33
|
+
if (!value)
|
|
34
|
+
return true;
|
|
35
|
+
if (value.trim() !== value)
|
|
36
|
+
return false;
|
|
37
|
+
return value.split(/\s+/u).every(isSafeRuntimeNavigationHref);
|
|
38
|
+
};
|
|
39
|
+
export const sanitizeRuntimeNavigationHref = (value) => {
|
|
40
|
+
const href = resolveRuntimeNavigationHref(value);
|
|
41
|
+
return isSafeRuntimeNavigationHref(href) ? href : '';
|
|
42
|
+
};
|
|
43
|
+
export const sanitizeRuntimeNavigationPing = (value) => (isSafeRuntimeNavigationPing(value) ? value : undefined);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type IAntdPlaygroundProps } from "../antd/index.js";
|
|
3
|
+
import type { IPlaygroundApi, IPlaygroundErrorContext, IPlaygroundSchemaChangeContext } from "../types.js";
|
|
4
|
+
import type { IPlaygroundScenarioPreset, RuntimeDocumentV1, RuntimeEnvironment } from "./contracts.js";
|
|
5
|
+
import type { ReadonlyRuntimeDocumentV1, ReadonlyTemplateDescriptorV1 } from "./templates.js";
|
|
6
|
+
export interface IRuntimePlaygroundApi extends Omit<IPlaygroundApi<RuntimeDocumentV1>, 'getSchema' | 'importDesign' | 'setSchema'> {
|
|
7
|
+
getSchema: () => RuntimeDocumentV1;
|
|
8
|
+
importDesign: (schema: string | ReadonlyRuntimeDocumentV1) => boolean;
|
|
9
|
+
setSchema: (schema: ReadonlyRuntimeDocumentV1, options?: {
|
|
10
|
+
snapshotType?: string;
|
|
11
|
+
}) => boolean;
|
|
12
|
+
}
|
|
13
|
+
type RuntimeAntdBaseProps = Omit<IAntdPlaygroundProps<RuntimeDocumentV1>, 'PreviewRenderer' | 'actions' | 'initialSchema' | 'onReady' | 'onSchemaChange' | 'scenarioPreset' | 'schema' | 'settingsPanel' | 'transformer'>;
|
|
14
|
+
export interface IAntdRuntimePlaygroundProps extends RuntimeAntdBaseProps {
|
|
15
|
+
actions?: React.ReactNode;
|
|
16
|
+
environment?: RuntimeEnvironment;
|
|
17
|
+
initialSchema?: ReadonlyRuntimeDocumentV1;
|
|
18
|
+
onReady?: (api: IRuntimePlaygroundApi) => void | (() => void);
|
|
19
|
+
onSchemaChange?: (schema: RuntimeDocumentV1, context: IPlaygroundSchemaChangeContext) => void;
|
|
20
|
+
scenarioPreset?: IPlaygroundScenarioPreset<RuntimeDocumentV1>;
|
|
21
|
+
schema?: ReadonlyRuntimeDocumentV1;
|
|
22
|
+
templates?: readonly ReadonlyTemplateDescriptorV1[];
|
|
23
|
+
}
|
|
24
|
+
export declare const createRuntimePlaygroundApi: (api: IPlaygroundApi<RuntimeDocumentV1>, onError?: (error: unknown, context: IPlaygroundErrorContext) => void) => IRuntimePlaygroundApi;
|
|
25
|
+
export declare const normalizeRuntimeDataCatalog: (dataCatalog: RuntimeEnvironment["dataCatalog"]) => import("@yimoka/designable-antd").IDataBindingCatalogItem[] | undefined;
|
|
26
|
+
export declare const AntdRuntimePlayground: {
|
|
27
|
+
({ actions, environment, initialSchema, onError, onReady, onSchemaChange, scenarioPreset, scenarioValidationResources, schema, templates, ...props }: IAntdRuntimePlaygroundProps): React.JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
export {};
|