• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16const fs = require('fs');
17const path = require('path');
18import ts from 'typescript';
19
20const COMPONENTS = 'components';
21const FORM_COMPONENTS = 'form_components';
22export const COMPONENT_MAP: any = {};
23export const FORM_MAP: any = {};
24
25export let COMMON_ATTRS: Set<string> = new Set([]);
26
27(function readComponents() {
28  const componentPath: Map<string, string> = new Map([
29    [`${COMPONENTS}`, `../${COMPONENTS}`],
30    [`${FORM_COMPONENTS}`, `../${FORM_COMPONENTS}`]
31  ]);
32  for (const [id, relPath] of componentPath.entries()) {
33    const componentsFile: string = path.join(__dirname, relPath);
34    const files: string[] = fs.readdirSync(componentsFile);
35    files.forEach(function(item) {
36      const fPath: string = path.join(componentsFile, item);
37      const json: any = require(fPath);
38      const stat: any = fs.statSync(fPath);
39      if (stat.isFile()) {
40        if (json.name) {
41          const compName: string = json.name;
42          delete json.name;
43          if (id === COMPONENTS) {
44            COMPONENT_MAP[compName] = json;
45          } else if (id === FORM_COMPONENTS) {
46            FORM_MAP[compName] = json;
47          }
48        } else {
49          if (id === COMPONENTS) {
50            COMMON_ATTRS = new Set(json.attrs);
51          }
52        }
53      }
54    });
55  }
56})();
57
58const TRANSITION_COMMON_ATTRS: Set<string> = new Set([
59  'slide', 'translate', 'scale', 'opacity'
60]);
61export const GESTURE_ATTRS: Set<string> = new Set([
62  'gesture', 'parallelGesture', 'priorityGesture'
63]);
64
65export const ID_ATTRS: Map<string, Map<string, string | number>> = new Map();
66
67export const forbiddenUseStateType: Set<string> = new Set(['Scroller', 'SwiperScroller',
68  'VideoController', 'WebController', 'CustomDialogController', 'SwiperController',
69  'TabsController', 'CalendarController', 'AbilityController', 'XComponentController',
70  'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData', 'Path2D',
71  'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'PatternLockController',
72  'TextAreaController', 'TextInputController', 'TextTimerController', 'SearchController', 'RichEditorController'
73]);
74
75const FOREACH_ATTRIBUTE = ['onMove'];
76export const INNER_COMPONENT_NAMES: Set<string> = new Set();
77export const NO_DEBUG_LINE_COMPONENT: Set<string> = new Set();
78export const BUILDIN_CONTAINER_COMPONENT: Set<string> = new Set();
79export const COMPONENT_SYSTEMAPI_NAMES: Set<string> = new Set();
80export const BUILDIN_STYLE_NAMES: Set<string> = new Set([
81  ...COMMON_ATTRS, ...GESTURE_ATTRS, ...TRANSITION_COMMON_ATTRS, ...FOREACH_ATTRIBUTE
82]);
83export const AUTOMIC_COMPONENT: Set<string> = new Set();
84export const SINGLE_CHILD_COMPONENT: Set<string> = new Set();
85export const SPECIFIC_CHILD_COMPONENT: Map<string, Set<string>> = new Map();
86export const SPECIFIC_PARENT_COMPONENT: Map<string, Set<string>> = new Map();
87export const GESTURE_TYPE_NAMES: Set<string> = new Set([
88  'TapGesture', 'LongPressGesture', 'PanGesture', 'PinchGesture', 'RotationGesture', 'GestureGroup',
89  'SwipeGesture'
90]);
91export const CUSTOM_BUILDER_METHOD: Set<string> = new Set();
92export const INNER_CUSTOM_LOCALBUILDER_METHOD: Set<string> = new Set();
93export const INNER_STYLE_FUNCTION: Map<string, ts.Block> = new Map();
94export const GLOBAL_STYLE_FUNCTION: Map<string, ts.Block> = new Map();
95
96export interface ExtendParamterInterfance {
97  attribute: string,
98  parameterCount: number
99}
100export const EXTEND_ATTRIBUTE: Map<string, Set<string>> = new Map();
101export const STYLES_ATTRIBUTE: Set<string> = new Set();
102
103export const INTERFACE_NODE_SET: Set<ts.InterfaceDeclaration> = new Set();
104
105export const INNER_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
106export const GLOBAL_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
107
108export const JS_BIND_COMPONENTS: Set<string> = new Set([
109  'ForEach', 'LazyForEach', ...GESTURE_TYPE_NAMES, 'Gesture',
110  'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController',
111  'TabsController', 'CalendarController', 'AbilityController', 'VideoController', 'WebController',
112  'XComponentController', 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData',
113  'Path2D', 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'DatePickerDialog',
114  'TextPickerDialog', 'AlertDialog', 'ContextMenu', 'ActionSheet', 'PatternLockController',
115  'TimePickerDialog', 'CalendarPickerDialog'
116]);
117
118export const NEEDPOP_COMPONENT: Set<string> = new Set(['Blank', 'Search']);
119
120export const CUSTOM_BUILDER_PROPERTIES: Set<string> = new Set(['background', 'bindPopup', 'bindMenu', 'bindContextMenu', 'title',
121  'menus', 'toolBar', 'tabBar', 'onDragStart', 'onItemDragStart', 'swipeAction', 'bindContentCover', 'bindSheet',
122  'navDestination', 'overlay', 'toolbarConfiguration', 'customKeyboard', 'bindSelectionMenu', 'description',
123  'showUnit', 'customKeyboard', 'create', 'addBuilderSpan', 'dragPreview', 'accessibilityVirtualNode']);
124export const CUSTOM_BUILDER_PROPERTIES_WITHOUTKEY: Set<string> = new Set(['showUnit', 'create']);
125export const CUSTOM_BUILDER_CONSTRUCTORS: Set<string> = new Set(['MenuItem', 'MenuItemGroup', 'Refresh', 'WaterFlow', 'Radio', 'Checkbox']);
126
127(function initComponent() {
128  Object.keys(COMPONENT_MAP).forEach((componentName) => {
129    INNER_COMPONENT_NAMES.add(componentName);
130    JS_BIND_COMPONENTS.add(componentName);
131    if (!COMPONENT_MAP[componentName].atomic) {
132      BUILDIN_CONTAINER_COMPONENT.add(componentName);
133    } else {
134      AUTOMIC_COMPONENT.add(componentName);
135    }
136    if (COMPONENT_MAP[componentName].single) {
137      SINGLE_CHILD_COMPONENT.add(componentName);
138    }
139    if (COMPONENT_MAP[componentName].children) {
140      SPECIFIC_CHILD_COMPONENT.set(componentName,
141        new Set([...COMPONENT_MAP[componentName].children]));
142    }
143    if (COMPONENT_MAP[componentName].attrs && COMPONENT_MAP[componentName].attrs.length) {
144      COMPONENT_MAP[componentName].attrs.forEach((item: string) => {
145        BUILDIN_STYLE_NAMES.add(item);
146      });
147      if (COMPONENT_MAP[componentName].systemApi) {
148        COMPONENT_MAP[componentName].attrs.forEach((item: string) => {
149          COMPONENT_SYSTEMAPI_NAMES.add(item);
150        });
151      }
152    }
153    if (COMPONENT_MAP[componentName].noDebugLine) {
154      NO_DEBUG_LINE_COMPONENT.add(componentName);
155    }
156    if (COMPONENT_MAP[componentName].parents) {
157      SPECIFIC_PARENT_COMPONENT.set(componentName,
158        new Set([...COMPONENT_MAP[componentName].parents]));
159    }
160  });
161})();
162
163export function resetComponentMap(): void {
164  ID_ATTRS.clear();
165  EXTEND_ATTRIBUTE.clear();
166  STYLES_ATTRIBUTE.clear();
167}
168