1+ import { editorSymbol , skeletonSymbol , designerCabinSymbol } from './symbols' ;
2+ import {
3+ isFormEvent as innerIsFormEvent ,
4+ compatibleLegaoSchema as innerCompatibleLegaoSchema ,
5+ getNodeSchemaById as innerGetNodeSchemaById ,
6+ transactionManager ,
7+ } from '@alilc/lowcode-utils' ;
8+ import {
9+ isNodeSchema as innerIsNodeSchema ,
10+ NodeSchema ,
11+ TransitionType ,
12+ } from '@alilc/lowcode-types' ;
13+ import {
14+ SettingField ,
15+ isSettingField ,
16+ Designer ,
17+ TransformStage ,
18+ LiveEditing ,
19+ isDragNodeDataObject ,
20+ isDragNodeObject ,
21+ isDragAnyObject ,
22+ DragObjectType ,
23+ isNode ,
24+ isShaken ,
25+ contains ,
26+ LocationDetailType ,
27+ isLocationChildrenDetail ,
28+ ScrollTarget ,
29+ getConvertedExtraKey as innerGetConvertedExtraKey ,
30+ getOriginalExtraKey as innerGetOriginalExtraKey ,
31+ } from '@alilc/lowcode-designer' ;
32+ import {
33+ Skeleton as InnerSkeleton ,
34+ createSettingFieldView ,
35+ PopupContext ,
36+ PopupPipe ,
37+ Workbench as InnerWorkbench ,
38+ } from '@alilc/lowcode-editor-skeleton' ;
39+ import Dragon from './dragon' ;
40+ import {
41+ Editor ,
42+ Title as InnerTitle ,
43+ Tip as InnerTip ,
44+ shallowIntl ,
45+ createIntl as innerCreateIntl ,
46+ intl ,
47+ createSetterContent ,
48+ obx ,
49+ observable ,
50+ makeObservable ,
51+ untracked ,
52+ computed ,
53+ observer ,
54+ globalLocale ,
55+ } from '@alilc/lowcode-editor-core' ;
56+ import { ReactNode } from 'react' ;
57+
58+
59+ const getDesignerCabin = ( editor : Editor ) => {
60+ const designer = editor . get ( 'designer' ) as Designer ;
61+
62+ return {
63+ SettingField,
64+ isSettingField,
65+ dragon : Dragon . create ( designer . dragon ) ,
66+ TransformStage,
67+ LiveEditing,
68+ DragObjectType,
69+ isDragNodeDataObject,
70+ isNode,
71+ [ designerCabinSymbol ] : {
72+ isDragNodeObject,
73+ isDragAnyObject,
74+ isShaken,
75+ contains,
76+ LocationDetailType,
77+ isLocationChildrenDetail,
78+ ScrollTarget,
79+ isSettingField,
80+ TransformStage,
81+ SettingField,
82+ LiveEditing,
83+ DragObjectType,
84+ isDragNodeDataObject,
85+ isNode,
86+ } ,
87+ } ;
88+ } ;
89+
90+ const getSkeletonCabin = ( skeleton : InnerSkeleton ) => {
91+ return {
92+ createSettingFieldView,
93+ PopupContext,
94+ PopupPipe,
95+ Workbench : ( props : any ) => < InnerWorkbench { ...props } skeleton = { skeleton } /> , // hijack skeleton
96+ } ;
97+ } ;
98+
99+ class Utils {
100+ isNodeSchema ( data : any ) : data is NodeSchema {
101+ return innerIsNodeSchema ( data ) ;
102+ }
103+
104+ isFormEvent ( e : KeyboardEvent | MouseEvent ) : boolean {
105+ return innerIsFormEvent ( e ) ;
106+ }
107+
108+ compatibleLegaoSchema ( props : any ) : any {
109+ return innerCompatibleLegaoSchema ( props ) ;
110+ }
111+
112+ getNodeSchemaById ( schema : NodeSchema , nodeId : string ) : NodeSchema | undefined {
113+ return innerGetNodeSchemaById ( schema , nodeId ) ;
114+ }
115+
116+ getConvertedExtraKey ( key : string ) : string {
117+ return innerGetConvertedExtraKey ( key ) ;
118+ }
119+
120+ getOriginalExtraKey ( key : string ) : string {
121+ return innerGetOriginalExtraKey ( key ) ;
122+ }
123+
124+ executeTransaction ( fn : ( ) => void , type : TransitionType = TransitionType . REPAINT ) : void {
125+ transactionManager . executeTransaction ( fn , type ) ;
126+ }
127+
128+ createIntl ( instance : string | object ) : {
129+ intlNode ( id : string , params ?: object ) : ReactNode ;
130+ intl ( id : string , params ?: object ) : string ;
131+ getLocale ( ) : string ;
132+ setLocale ( locale : string ) : void ;
133+ } {
134+ return innerCreateIntl ( instance ) ;
135+ }
136+ }
137+
138+ export default class Common {
139+ private readonly [ editorSymbol ] : Editor ;
140+ private readonly [ skeletonSymbol ] : InnerSkeleton ;
141+ private readonly __designerCabin : any ;
142+ private readonly __skeletonCabin : any ;
143+ private readonly __editorCabin : any ;
144+ private readonly __utils : Utils ;
145+
146+ constructor ( editor : Editor , skeleton : InnerSkeleton ) {
147+ this [ editorSymbol ] = editor ;
148+ this [ skeletonSymbol ] = skeleton ;
149+ this . __designerCabin = getDesignerCabin ( this [ editorSymbol ] ) ;
150+ this . __skeletonCabin = getSkeletonCabin ( this [ skeletonSymbol ] ) ;
151+ this . __utils = new Utils ( ) ;
152+ }
153+
154+ get utils ( ) : any {
155+ return this . __utils ;
156+ }
157+
158+ get editorCabin ( ) : any {
159+ return {
160+ Title : InnerTitle ,
161+ Tip : InnerTip ,
162+ shallowIntl,
163+ createIntl : innerCreateIntl ,
164+ intl,
165+ createSetterContent,
166+ obx,
167+ observable,
168+ makeObservable,
169+ untracked,
170+ computed,
171+ observer,
172+ globalLocale,
173+ } ;
174+ }
175+
176+ get designerCabin ( ) : any {
177+ return this . __designerCabin ;
178+ }
179+
180+ get skeletonCabin ( ) : any {
181+ return this . __skeletonCabin ;
182+ }
183+ }
0 commit comments