@flowgram-vue/type-editor 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/dist/index.cjs +0 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/src/components/index.ts +8 -0
- package/src/components/type-editor/columns/index.ts +404 -0
- package/src/components/type-editor/common.ts +44 -0
- package/src/components/type-editor/formatter/index.ts +44 -0
- package/src/components/type-editor/hooks/active-pos.ts +20 -0
- package/src/components/type-editor/hooks/disabled.ts +22 -0
- package/src/components/type-editor/hooks/formatter-value.ts +53 -0
- package/src/components/type-editor/hooks/index.ts +8 -0
- package/src/components/type-editor/index.ts +9 -0
- package/src/components/type-editor/mode/declare-assign.ts +102 -0
- package/src/components/type-editor/mode/index.ts +15 -0
- package/src/components/type-editor/mode/type-definition.ts +46 -0
- package/src/components/type-editor/table.vue +293 -0
- package/src/components/type-editor/type-editor.vue +107 -0
- package/src/components/type-editor/type.ts +142 -0
- package/src/components/type-editor/utils.ts +173 -0
- package/src/components/type-selector/index.ts +51 -0
- package/src/components/type-selector/type-selector.vue +100 -0
- package/src/contexts/index.ts +106 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +15 -0
- package/src/json-schema-exports.ts +18 -0
- package/src/preset/index.ts +6 -0
- package/src/preset/object-type-editor.vue +91 -0
- package/src/services/clipboard-service.ts +93 -0
- package/src/services/index.ts +11 -0
- package/src/services/shortcut-service.ts +9 -0
- package/src/services/type-editor-service.ts +396 -0
- package/src/services/type-operation-service.ts +99 -0
- package/src/services/type-registry-manager.ts +14 -0
- package/src/services/utils.ts +28 -0
- package/src/styles.css +235 -0
- package/src/type-registry/array.ts +18 -0
- package/src/type-registry/boolean.ts +30 -0
- package/src/type-registry/index.ts +22 -0
- package/src/type-registry/integer.ts +24 -0
- package/src/type-registry/number.ts +23 -0
- package/src/type-registry/object.ts +13 -0
- package/src/type-registry/string.ts +21 -0
- package/src/types/index.ts +7 -0
- package/src/types/registry.ts +52 -0
- package/src/types/type-editor.ts +150 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/monitor-data/index.ts +7 -0
- package/src/utils/monitor-data/monitor-data.ts +43 -0
- package/src/utils/monitor-data/use-monitor-data.ts +29 -0
- package/src/utils/registry-adapter.ts +83 -0
- package/src/utils/toast.ts +16 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { h } from 'vue';
|
|
7
|
+
import { IJsonSchema } from '@flowgram-vue/json-schema';
|
|
8
|
+
|
|
9
|
+
import { TypeEditorRegistry } from '../types';
|
|
10
|
+
import { TypeEditorRegistryManager } from '../services/type-registry-manager';
|
|
11
|
+
|
|
12
|
+
export const registryFormatter = <TypeSchema extends Partial<IJsonSchema>>(
|
|
13
|
+
registry: Partial<TypeEditorRegistry<TypeSchema>>,
|
|
14
|
+
manager: TypeEditorRegistryManager<TypeSchema>
|
|
15
|
+
): Partial<TypeEditorRegistry<TypeSchema>> => {
|
|
16
|
+
const res: Record<string, unknown> = {
|
|
17
|
+
...registry,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const apiMap: Record<string, string> = {
|
|
21
|
+
getItemTypes: 'getSupportedItemTypes',
|
|
22
|
+
getIJsonSchemaByStringValue: 'getTypeSchemaByStringValue',
|
|
23
|
+
getStringValue: 'getStringValueByTypeSchema',
|
|
24
|
+
getIJsonSchemaProperties: 'getTypeSchemaProperties',
|
|
25
|
+
getIJsonSchemaPropertiesParent: 'getPropertiesParent',
|
|
26
|
+
getChildrenExtraJsonPaths: 'getJsonPaths',
|
|
27
|
+
getDefaultIJsonSchema: 'getDefaultSchema',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Object.keys(apiMap).forEach((api) => {
|
|
31
|
+
if (res[api]) {
|
|
32
|
+
res[apiMap[api]] = res[api];
|
|
33
|
+
}
|
|
34
|
+
if (res[apiMap[api]]) {
|
|
35
|
+
res[api] = res[apiMap[api]];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...res,
|
|
41
|
+
getDisplayLabel: (type: IJsonSchema) =>
|
|
42
|
+
h('span', { class: 'fg-type-label' }, [
|
|
43
|
+
manager?.getDisplayIcon(type as TypeSchema),
|
|
44
|
+
h('span', { class: 'fg-type-label-text' }, manager.getComplexText(type as TypeSchema)),
|
|
45
|
+
]),
|
|
46
|
+
getIJsonSchemaDeepField: (type: TypeSchema) => manager.getTypeSchemaDeepChildField(type),
|
|
47
|
+
} as unknown as TypeEditorRegistry<TypeSchema>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
interface ITypeDefinitionManager<TypeSchema extends Partial<IJsonSchema>> {
|
|
51
|
+
getDefinitionByIJsonSchema: (
|
|
52
|
+
typeSchema?: TypeSchema
|
|
53
|
+
) => TypeEditorRegistry<TypeSchema> | undefined;
|
|
54
|
+
getAllTypeDefinitions: () => TypeEditorRegistry<TypeSchema>[];
|
|
55
|
+
getDefinitionByType: (type: string) => TypeEditorRegistry<TypeSchema> | undefined;
|
|
56
|
+
getUndefinedIJsonSchema: () => TypeSchema;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ITypeDefinitionAdapter<TypeSchema extends Partial<IJsonSchema>> {
|
|
60
|
+
typeDefinitionManager: ITypeDefinitionManager<TypeSchema>;
|
|
61
|
+
utils: {
|
|
62
|
+
getComposedLabel: (type: TypeSchema) => string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const getTypeDefinitionAdapter = <TypeSchema extends Partial<IJsonSchema>>(
|
|
67
|
+
manager: TypeEditorRegistryManager<TypeSchema>
|
|
68
|
+
): ITypeDefinitionAdapter<TypeSchema> => {
|
|
69
|
+
const typeDefinitionManager: ITypeDefinitionManager<TypeSchema> = {
|
|
70
|
+
getDefinitionByIJsonSchema: (typeSchema?: TypeSchema) =>
|
|
71
|
+
typeSchema ? manager.getTypeBySchema(typeSchema) : undefined,
|
|
72
|
+
getAllTypeDefinitions: () => manager.getTypeRegistriesWithParentType(),
|
|
73
|
+
getDefinitionByType: (type) => manager.getTypeByName(type),
|
|
74
|
+
getUndefinedIJsonSchema: () => manager.getTypeByName('unknown')!.getDefaultSchema(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
typeDefinitionManager,
|
|
79
|
+
utils: {
|
|
80
|
+
getComposedLabel: (type: TypeSchema) => manager.getComplexText(type),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function toast(message: string, level: 'success' | 'warning' | 'error' = 'success'): void {
|
|
7
|
+
if (typeof document === 'undefined') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const el = document.createElement('div');
|
|
11
|
+
el.className = `fg-type-toast fg-type-toast--${level}`;
|
|
12
|
+
el.textContent = message;
|
|
13
|
+
el.setAttribute('role', 'status');
|
|
14
|
+
document.body.appendChild(el);
|
|
15
|
+
window.setTimeout(() => el.remove(), 1800);
|
|
16
|
+
}
|