• 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(): void {
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  'ArcSwiperController'
74]);
75
76const FOREACH_ATTRIBUTE = ['onMove'];
77export const INNER_COMPONENT_NAMES: Set<string> = new Set();
78export const NO_DEBUG_LINE_COMPONENT: Set<string> = new Set();
79export const BUILDIN_CONTAINER_COMPONENT: Set<string> = new Set();
80export const COMPONENT_SYSTEMAPI_NAMES: Set<string> = new Set();
81export const BUILDIN_STYLE_NAMES: Set<string> = new Set([
82  ...COMMON_ATTRS, ...GESTURE_ATTRS, ...TRANSITION_COMMON_ATTRS, ...FOREACH_ATTRIBUTE
83]);
84export const AUTOMIC_COMPONENT: Set<string> = new Set();
85export const SINGLE_CHILD_COMPONENT: Set<string> = new Set();
86export const SPECIFIC_CHILD_COMPONENT: Map<string, Set<string>> = new Map();
87export const SPECIFIC_PARENT_COMPONENT: Map<string, Set<string>> = new Map();
88export const GESTURE_TYPE_NAMES: Set<string> = new Set([
89  'TapGesture', 'LongPressGesture', 'PanGesture', 'PinchGesture', 'RotationGesture', 'GestureGroup',
90  'SwipeGesture'
91]);
92export const CUSTOM_BUILDER_METHOD: Set<string> = new Set();
93export const INNER_CUSTOM_LOCALBUILDER_METHOD: Set<string> = new Set();
94export const INNER_STYLE_FUNCTION: Map<string, ts.Block> = new Map();
95export const GLOBAL_STYLE_FUNCTION: Map<string, ts.Block> = new Map();
96
97export interface ExtendParamterInterfance {
98  attribute: string,
99  parameterCount: number
100}
101export const EXTEND_ATTRIBUTE: Map<string, Set<string>> = new Map();
102export const STYLES_ATTRIBUTE: Set<string> = new Set();
103
104export const INTERFACE_NODE_SET: Set<ts.InterfaceDeclaration> = new Set();
105
106export const INNER_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
107export const GLOBAL_CUSTOM_BUILDER_METHOD: Set<string> = new Set();
108
109export const JS_BIND_COMPONENTS: Set<string> = new Set([
110  'ForEach', 'LazyForEach', ...GESTURE_TYPE_NAMES, 'Gesture',
111  'PanGestureOption', 'CustomDialogController', 'Storage', 'Scroller', 'SwiperController',
112  'TabsController', 'CalendarController', 'AbilityController', 'VideoController', 'WebController',
113  'XComponentController', 'CanvasRenderingContext2D', 'CanvasGradient', 'ImageBitmap', 'ImageData',
114  'Path2D', 'RenderingContextSettings', 'OffscreenCanvasRenderingContext2D', 'DatePickerDialog',
115  'TextPickerDialog', 'AlertDialog', 'ContextMenu', 'ActionSheet', 'PatternLockController',
116  'TimePickerDialog', 'CalendarPickerDialog', 'ArcSwiperController'
117]);
118
119export const NEEDPOP_COMPONENT: Set<string> = new Set(['Blank', 'Search']);
120
121export const CUSTOM_BUILDER_PROPERTIES: Set<string> = new Set(['background', 'bindPopup', 'bindMenu', 'bindContextMenu', 'title',
122  'menus', 'toolBar', 'tabBar', 'onDragStart', 'onItemDragStart', 'swipeAction', 'bindContentCover', 'bindSheet',
123  'navDestination', 'overlay', 'toolbarConfiguration', 'customKeyboard', 'bindSelectionMenu', 'description',
124  'showUnit', 'customKeyboard', 'create', 'addBuilderSpan', 'dragPreview', 'accessibilityVirtualNode']);
125export const CUSTOM_BUILDER_PROPERTIES_WITHOUTKEY: Set<string> = new Set(['showUnit', 'create']);
126export const CUSTOM_BUILDER_CONSTRUCTORS: Set<string> = new Set(['MenuItem', 'MenuItemGroup', 'Refresh', 'WaterFlow', 'Radio', 'Checkbox']);
127
128(function initComponent() {
129  Object.keys(COMPONENT_MAP).forEach((componentName) => {
130    INNER_COMPONENT_NAMES.add(componentName);
131    JS_BIND_COMPONENTS.add(componentName);
132    if (!COMPONENT_MAP[componentName].atomic) {
133      BUILDIN_CONTAINER_COMPONENT.add(componentName);
134    } else {
135      AUTOMIC_COMPONENT.add(componentName);
136    }
137    if (COMPONENT_MAP[componentName].single) {
138      SINGLE_CHILD_COMPONENT.add(componentName);
139    }
140    if (COMPONENT_MAP[componentName].children) {
141      SPECIFIC_CHILD_COMPONENT.set(componentName,
142        new Set([...COMPONENT_MAP[componentName].children]));
143    }
144    if (COMPONENT_MAP[componentName].attrs && COMPONENT_MAP[componentName].attrs.length) {
145      COMPONENT_MAP[componentName].attrs.forEach((item: string) => {
146        BUILDIN_STYLE_NAMES.add(item);
147      });
148      if (COMPONENT_MAP[componentName].systemApi) {
149        COMPONENT_MAP[componentName].attrs.forEach((item: string) => {
150          COMPONENT_SYSTEMAPI_NAMES.add(item);
151        });
152      }
153    }
154    if (COMPONENT_MAP[componentName].noDebugLine) {
155      NO_DEBUG_LINE_COMPONENT.add(componentName);
156    }
157    if (COMPONENT_MAP[componentName].parents) {
158      SPECIFIC_PARENT_COMPONENT.set(componentName,
159        new Set([...COMPONENT_MAP[componentName].parents]));
160    }
161  });
162})();
163
164export function resetComponentMap(): void {
165  ID_ATTRS.clear();
166  EXTEND_ATTRIBUTE.clear();
167  STYLES_ATTRIBUTE.clear();
168}
169