8ce53850fd58c426ed1be149b6b679a2e3fef2ca
[sdc/sdc-workflow-designer.git] /
1 /* tslint:disable:array-type member-access variable-name typedef
2  only-arrow-functions directive-class-suffix component-class-suffix
3  component-selector one-variable-per-declaration
4  no-attribute-parameter-decorator*/
5 import {ConnectionPositionPair} from './index';
6
7 export const POSITION_MAP: any = {
8   'top': {
9         originX: 'center',
10         originY: 'top',
11         overlayX: 'center',
12         overlayY: 'bottom'
13   },
14   'topCenter': {
15         originX: 'center',
16         originY: 'top',
17         overlayX: 'center',
18         overlayY: 'bottom'
19   },
20   'topLeft':
21                 {originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom'},
22   'topRight':
23                 {originX: 'end', originY: 'top', overlayX: 'end', overlayY: 'bottom'},
24   'right': {
25         originX: 'end',
26         originY: 'center',
27         overlayX: 'start',
28         overlayY: 'center',
29   },
30   'rightTop': {
31         originX: 'end',
32         originY: 'top',
33         overlayX: 'start',
34         overlayY: 'top',
35   },
36   'rightBottom': {
37         originX: 'end',
38         originY: 'bottom',
39         overlayX: 'start',
40         overlayY: 'bottom',
41   },
42   'bottom': {
43         originX: 'center',
44         originY: 'bottom',
45         overlayX: 'center',
46         overlayY: 'top',
47   },
48   'bottomCenter': {
49         originX: 'center',
50         originY: 'bottom',
51         overlayX: 'center',
52         overlayY: 'top',
53   },
54   'bottomLeft': {
55         originX: 'start',
56         originY: 'bottom',
57         overlayX: 'start',
58         overlayY: 'top',
59   },
60   'bottomRight': {
61         originX: 'end',
62         originY: 'bottom',
63         overlayX: 'end',
64         overlayY: 'top',
65   },
66   'left': {
67         originX: 'start',
68         originY: 'center',
69         overlayX: 'end',
70         overlayY: 'center',
71   },
72   'leftTop': {
73         originX: 'start',
74         originY: 'top',
75         overlayX: 'end',
76         overlayY: 'top',
77   },
78   'leftBottom': {
79         originX: 'start',
80         originY: 'bottom',
81         overlayX: 'end',
82         overlayY: 'bottom',
83   },
84 };
85 export const DEFAULT_4_POSITIONS = _objectValues([
86   POSITION_MAP['top'], POSITION_MAP['right'], POSITION_MAP['bottom'],
87   POSITION_MAP['left']
88 ]);
89 export const DEFAULT_DROPDOWN_POSITIONS =
90         _objectValues([POSITION_MAP['bottomLeft'], POSITION_MAP['topLeft']]);
91 export const DEFAULT_DATEPICKER_POSITIONS = [
92   {
93         originX: 'start',
94         originY: 'top',
95         overlayX: 'start',
96         overlayY: 'top',
97   },
98   {
99         originX: 'start',
100         originY: 'bottom',
101         overlayX: 'start',
102         overlayY: 'bottom',
103   }
104 ] as ConnectionPositionPair[];
105
106 function arrayMap(array: any, iteratee: any) {
107   let index = -1;
108   const length = array === null ? 0 : array.length, result = Array(length);
109
110   while (++index < length) {
111         result[index] = iteratee(array[index], index, array);
112   }
113   return result;
114 }
115
116 function baseValues(object: any, props: any) {
117   return arrayMap(props, function(key: any) {
118         return object[key];
119   });
120 }
121
122 function _objectValues(object: any) {
123   return object === null ? [] : baseValues(object, Object.keys(object));
124 }