native-document 1.0.129 → 1.0.131

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.
@@ -1,17 +1,22 @@
1
1
  import BaseComponent from "../BaseComponent";
2
- import EventEmitter from "../../../src/core/utils/EventEmitter";
2
+ import DebugManager from "../../core/utils/debug-manager";
3
3
 
4
4
 
5
- export default function Badge(config = {}) {
5
+ export default function Badge(content, props = {}) {
6
6
  if(!(this instanceof Badge)) {
7
- return new Badge(config);
7
+ return new Badge(props);
8
8
  }
9
9
 
10
+ BaseComponent.call(this, props);
11
+
10
12
  this.$description = {
11
- style: null,
12
- shape: null,
13
- variant,
14
- ...config
13
+ style: 'filled',
14
+ borderRadiusType: 'pill',
15
+ variant: 'primary',
16
+ size: 'medium',
17
+ onClick: null,
18
+ content,
19
+ props
15
20
  };
16
21
  }
17
22
 
@@ -21,6 +26,20 @@ Badge.defaultTemplate = null;
21
26
 
22
27
  Badge.use = function(template) {};
23
28
 
29
+ Badge.preset = function(name, callback) {
30
+ if (Badge.prototype[name] || Badge[name]) {
31
+ DebugManager.warn(`Warning: the ${name} method already exists in Badge.`);
32
+ return;
33
+ }
34
+ Badge[name] = (content, props) => callback(new Badge(content, props));
35
+ };
36
+
37
+ Badge.presets = function(presets) {
38
+ for (const name in presets) {
39
+ Badge.preset(name, presets[name]);
40
+ }
41
+ };
42
+
24
43
  Badge.prototype.variant = function(variant) {
25
44
  this.$description.variant = variant;
26
45
  return this;
@@ -59,15 +78,21 @@ Badge.prototype.large = function() {
59
78
  };
60
79
 
61
80
  Badge.prototype.shape = function(shape) {
62
- this.$description.shape = shape;
81
+ this.$description.borderRadiusType = shape;
63
82
  return this;
64
83
  };
65
84
 
66
85
  Badge.prototype.rounded = function() {
67
- return this.shape('rounded');
86
+ this.$description.borderRadiusType = 'rounded';
87
+ return this;
68
88
  };
69
89
  Badge.prototype.pill = function() {
70
- return this.shape('pill');
90
+ this.$description.borderRadiusType = 'pill';
91
+ return this;
92
+ };
93
+ Badge.prototype.circle = function() {
94
+ this.$description.borderRadiusType = 'circle';
95
+ return this;
71
96
  };
72
97
 
73
98
  Badge.prototype.style = function(style) {
@@ -75,13 +100,16 @@ Badge.prototype.style = function(style) {
75
100
  return this;
76
101
  };
77
102
  Badge.prototype.outline = function() {
78
- return this.style('outline');
103
+ this.$description.style = 'outline';
104
+ return this;
79
105
  };
80
106
  Badge.prototype.filled = function() {
81
- return this.style('filled');
107
+ this.$description.style = 'filled';
108
+ return this;
82
109
  };
83
110
  Badge.prototype.bordered = function() {
84
- return this.style('bordered');
111
+ this.$description.style = 'bordered';
112
+ return this;
85
113
  };
86
114
 
87
115
  Badge.prototype.content = function(content) {
@@ -89,15 +117,7 @@ Badge.prototype.content = function(content) {
89
117
  return this;
90
118
  };
91
119
 
92
- Badge.prototype.clickable = function(handler) {};
93
-
94
-
95
- Badge.prototype.render = function(renderFn) {
96
- this.$description.render = renderFn;
120
+ Badge.prototype.onClick = function(handler) {
121
+ this.$description.onClick = handler;
97
122
  return this;
98
- };
99
-
100
- Badge.prototype.$build = function() {
101
-
102
- };
103
- Badge.prototype.toNdElement = function() {};
123
+ };
@@ -1,12 +1,11 @@
1
1
  import BaseComponent from "../BaseComponent";
2
- import { Button as NativeButton } from "../../../elements";
3
2
 
4
- export default function Button(label, config = {}) {
3
+ export default function Button(label, props = {}) {
5
4
  if(!(this instanceof Button)) {
6
- return new Button(label, config);
5
+ return new Button(label, props);
7
6
  }
8
7
 
9
- BaseComponent.call(this, config);
8
+ BaseComponent.call(this, props);
10
9
 
11
10
  this.$description = {
12
11
  label: label,
@@ -21,7 +20,7 @@ export default function Button(label, config = {}) {
21
20
  block: null,
22
21
  borderRadiusType: null,
23
22
  outline: null,
24
- ...config
23
+ props
25
24
  };
26
25
 
27
26
  this.$element = null;
@@ -37,6 +36,20 @@ Button.use = function(template = {}) {
37
36
 
38
37
  BaseComponent.extends(Button);
39
38
 
39
+ Button.preset = function(name, callback) {
40
+ if (Button.prototype[name] || Button[name]) {
41
+ console.warn(`Warning: the ${name} method already exist in Button.`);
42
+ return;
43
+ }
44
+ Button[name] = (label, props) => callback(new Button(label, props));
45
+ };
46
+
47
+ Button.presets = function(presets) {
48
+ for (const name in presets) {
49
+ Button.preset(name, presets[name]);
50
+ }
51
+ };
52
+
40
53
  Button.prototype.type = function(type) {
41
54
  this.$description.type = type;
42
55
  return this;
@@ -86,18 +99,19 @@ Button.prototype.medium = function() {
86
99
  return this.size('medium');
87
100
  };
88
101
 
89
- Button.prototype.icon = function(icon, iconPosition = 'left') {
102
+ Button.prototype.icon = function(icon, iconPosition = 'leading') {
90
103
  this.$description.icon = icon;
91
104
  this.$description.iconPosition = iconPosition;
92
105
  return this;
93
106
  };
94
107
 
95
- Button.prototype.iconAtLeft = function() {
96
- this.$description.iconPosition = 'left';
108
+ Button.prototype.iconAtLeading = function() {
109
+ this.$description.iconPosition = 'leading';
97
110
  return this;
98
111
  };
99
- Button.prototype.iconAtRight = function() {
100
- this.$description.iconPosition = 'right';
112
+
113
+ Button.prototype.iconAtTrailing = function() {
114
+ this.$description.iconPosition = 'trailing';
101
115
  return this;
102
116
  };
103
117
  Button.prototype.iconAtTop = function() {
@@ -138,16 +152,16 @@ Button.prototype.rounded = function() {
138
152
  this.$description.borderRadiusType = 'rounded';
139
153
  return this;
140
154
  };
141
- Button.prototype.circle = function() {
142
- this.$description.borderRadiusType = 'circle';
155
+ Button.prototype.pill = function() {
156
+ this.$description.borderRadiusType = 'pill';
143
157
  return this;
144
158
  };
145
- Button.prototype.pill = function() {
146
- this.$description.shape = 'circle';
159
+ Button.prototype.circle = function() {
160
+ this.$description.borderRadiusType = 'circle';
147
161
  return this;
148
162
  };
149
163
  Button.prototype.smooth = function() {
150
- this.$description.shape = 'smooth';
164
+ this.$description.borderRadiusType = 'smooth';
151
165
  return this;
152
166
  };
153
167
  Button.prototype.block = function() {
@@ -155,22 +169,6 @@ Button.prototype.block = function() {
155
169
  return this;
156
170
  };
157
171
 
158
- Button.prototype.$build = function() {
159
- if(this.$element) {
160
- return this.$element;
161
- }
162
- const renderFn = this.$description.render || Button.defaultTemplate;
163
-
164
- if(typeof renderFn === 'function') {
165
- this.$element = renderFn(this);
166
- }
167
- else {
168
- const props = {};
169
- this.$element = NativeButton(props, this.$description.label);
170
- }
171
- return this.$element;
172
- };
173
-
174
172
  Button.prototype.node = function() {
175
173
  return this.$build();
176
174
  };
@@ -1,16 +1,17 @@
1
1
  import BaseComponent from "../BaseComponent";
2
+ import DebugManager from "../../core/utils/debug-manager";
2
3
 
3
- export default function Divider(config = {}) {
4
+ export default function Divider(label, props = {}) {
4
5
  if(!(this instanceof Divider)) {
5
- return new Divider(config);
6
+ return new Divider(label, props);
6
7
  }
7
8
 
8
9
  this.$description = {
9
10
  orientation: 'horizontal',
10
11
  variant: 'solid',
11
- thickness: null,
12
- spacing: null,
13
- label: null,
12
+ thickness: 1,
13
+ spacing: 16,
14
+ label,
14
15
  labelPosition: 'center',
15
16
  color: null,
16
17
  render: null,
@@ -18,7 +19,7 @@ export default function Divider(config = {}) {
18
19
  indent: null,
19
20
  leading: null,
20
21
  trailing: null,
21
- ...config
22
+ props
22
23
  };
23
24
  }
24
25
 
@@ -30,6 +31,20 @@ Divider.use = function(template) {
30
31
  Divider.defaultTemplate = template.divider;
31
32
  };
32
33
 
34
+ Divider.preset = function(name, callback) {
35
+ if (Divider.prototype[name] || Divider[name]) {
36
+ DebugManager.warn(`Warning: the ${name} method already exists in Divider.`);
37
+ return;
38
+ }
39
+ Divider[name] = (label, props) => callback(new Divider(label, props));
40
+ };
41
+
42
+ Divider.presets = function(presets) {
43
+ for (const name in presets) {
44
+ Divider.preset(name, presets[name]);
45
+ }
46
+ };
47
+
33
48
  Divider.prototype.orientation = function(orientation) {
34
49
  this.$description.orientation = orientation;
35
50
  return this;
@@ -0,0 +1,27 @@
1
+ import Stack from "./Stack";
2
+ import DebugManager from "../../core/utils/debug-manager";
3
+
4
+ export default function HStack(content, props = {}) {
5
+ if (!(this instanceof HStack)) {
6
+ return new HStack(content, props);
7
+ }
8
+
9
+ Stack.call(this, content, props);
10
+ this.$description.orientation = 'horizontal';
11
+ }
12
+
13
+ Stack.extends(HStack);
14
+
15
+ HStack.preset = function(name, callback) {
16
+ if (HStack.prototype[name] || HStack[name]) {
17
+ DebugManager.warn(`Warning: the ${name} method already exists in HStack.`);
18
+ return;
19
+ }
20
+ HStack[name] = (content, props) => callback(new HStack(content, props));
21
+ };
22
+
23
+ HStack.presets = function(presets) {
24
+ for (const name in presets) {
25
+ HStack.preset(name, presets[name]);
26
+ }
27
+ };
@@ -0,0 +1,75 @@
1
+
2
+
3
+ import BaseComponent from "../BaseComponent";
4
+
5
+ export default function Stack(content, props = {}) {
6
+ if (!(this instanceof Stack)) {
7
+ return new Stack(content, props);
8
+ }
9
+
10
+ BaseComponent.call(this, props);
11
+
12
+ this.$description = {
13
+ orientation: 'horizontal',
14
+ content: content,
15
+ spacing: 0,
16
+ alignment: 'center',
17
+ justifyContent: 'start',
18
+ props
19
+ };
20
+ }
21
+
22
+ BaseComponent.extends(Stack);
23
+
24
+ Stack.prototype.wrap = function(enabled = true) {
25
+ this.$description.wrap = enabled;
26
+ return this;
27
+ };
28
+
29
+ Stack.prototype.spacing = function(value) {
30
+ this.$description.spacing = value;
31
+ return this;
32
+ };
33
+
34
+ Stack.prototype.alignLeading = function() {
35
+ this.$description.alignment = 'leading';
36
+ return this;
37
+ };
38
+ Stack.prototype.alignCenter = function() {
39
+ this.$description.alignment = 'center';
40
+ return this;
41
+ };
42
+ Stack.prototype.alignTrailing = function() {
43
+ this.$description.alignment = 'trailing';
44
+ return this;
45
+ };
46
+ Stack.prototype.alignStretch = function() {
47
+ this.$description.alignment = 'stretch';
48
+ return this;
49
+ };
50
+
51
+ Stack.prototype.justifyStart = function() {
52
+ this.$description.justifyContent = 'start';
53
+ return this;
54
+ };
55
+ Stack.prototype.justifyCenter = function() {
56
+ this.$description.justifyContent = 'center';
57
+ return this;
58
+ };
59
+ Stack.prototype.justifyEnd = function() {
60
+ this.$description.justifyContent = 'end';
61
+ return this;
62
+ };
63
+ Stack.prototype.justifyBetween = function() {
64
+ this.$description.justifyContent = 'between';
65
+ return this;
66
+ };
67
+ Stack.prototype.justifyAround = function() {
68
+ this.$description.justifyContent = 'around';
69
+ return this;
70
+ };
71
+
72
+ Stack.prototype.center = function() {
73
+ this.alignCenter().justifyCenter();
74
+ return this;
75
+ };
@@ -0,0 +1,26 @@
1
+ import Stack from "./Stack";
2
+ import DebugManager from "../../core/utils/debug-manager";
3
+
4
+
5
+ export default function VStack(content, props = {}) {
6
+ if (!(this instanceof VStack)) return new VStack(content, props);
7
+
8
+ Stack.call(this, content, props);
9
+ this.$description.orientation = 'vertical';
10
+ this.$description.alignment = 'leading';
11
+ }
12
+ Stack.extends(VStack);
13
+
14
+ VStack.preset = function(name, callback) {
15
+ if (VStack.prototype[name] || VStack[name]) {
16
+ DebugManager.warn(`Warning: the ${name} method already exists in VStack.`);
17
+ return;
18
+ }
19
+ VStack[name] = (content, props) => callback(new VStack(content, props));
20
+ };
21
+
22
+ VStack.presets = function(presets) {
23
+ for (const name in presets) {
24
+ VStack.preset(name, presets[name]);
25
+ }
26
+ };
@@ -0,0 +1,36 @@
1
+ import BaseComponent from "../BaseComponent";
2
+ import DebugManager from "../../core/utils/debug-manager";
3
+
4
+ export default function ZStack(content, props = {}) {
5
+ if (!(this instanceof ZStack)) {
6
+ return new ZStack(content, props);
7
+ }
8
+ BaseComponent.call(this, props);
9
+
10
+ this.$description = {
11
+ content: content,
12
+ alignment: 'center',
13
+ props
14
+ };
15
+ }
16
+
17
+ BaseComponent.extends(ZStack);
18
+
19
+ ZStack.preset = function(name, callback) {
20
+ if (ZStack.prototype[name] || ZStack[name]) {
21
+ DebugManager.warn(`Warning: the ${name} method already exists in ZStack.`);
22
+ return;
23
+ }
24
+ ZStack[name] = (content, props) => callback(new ZStack(content, props));
25
+ };
26
+
27
+ ZStack.presets = function(presets) {
28
+ for (const name in presets) {
29
+ ZStack.preset(name, presets[name]);
30
+ }
31
+ };
32
+
33
+ ZStack.prototype.alignment = function(align) {
34
+ this.$description.alignment = align;
35
+ return this;
36
+ };
@@ -0,0 +1,19 @@
1
+ import Stack from "./Stack";
2
+ import VStack from "./VStack";
3
+ import ZStack from "./ZStack";
4
+ import HStack from "./HStack";
5
+
6
+
7
+ const Row = HStack;
8
+ const Col = VStack;
9
+ const Overlay = ZStack;
10
+
11
+ export {
12
+ Stack,
13
+ HStack,
14
+ VStack,
15
+ ZStack,
16
+ Row,
17
+ Col,
18
+ Overlay
19
+ }
@@ -3,11 +3,13 @@ import EventEmitter from "../../../src/core/utils/EventEmitter";
3
3
  import HasItems from "../$traits/HasItems";
4
4
  import MenuDivider from "./MenuDivider";
5
5
  import MenuGroup from "./MenuGroup";
6
+ import MenuItem from "./MenuItem";
7
+ import MenuLink from "./MenuLink";
6
8
 
7
- export default function Menu(config = {}) {
9
+ export default function Menu(props = {}) {
8
10
 
9
11
  if(!(this instanceof Menu)) {
10
- return new Menu(config)
12
+ return new Menu(props)
11
13
  }
12
14
 
13
15
  this.$description = {
@@ -17,7 +19,7 @@ export default function Menu(config = {}) {
17
19
  closeOnSelect: true,
18
20
  keyboardLoop: true,
19
21
  active: null,
20
- ...config
22
+ props
21
23
  };
22
24
 
23
25
  }
@@ -89,10 +91,54 @@ Menu.prototype.separator = function() {
89
91
  return this.add(new MenuDivider());
90
92
  };
91
93
 
94
+
95
+ /**
96
+ * Adds an item to the collection
97
+ * @param {NdChild} label - The item to add
98
+ * @param {?NdChild} icon - The item to add
99
+ * @param {?Function} action - The item to add
100
+ * @param {?Function} configBuilder - The item to add
101
+ * @param {?*} props - The item to add
102
+ * @returns {HasItems}
103
+ */
104
+ Menu.prototype.item = function(label, icon, action, configBuilder, props = {}) {
105
+ const item = MenuItem();
106
+ item.icon(icon).label(label).onClick(action);
107
+ if(typeof configBuilder === 'function') {
108
+ configBuilder.length ? configBuilder(item) : this.trailing(item);
109
+ } else if(configBuilder) {
110
+ this.trailing(item);
111
+ }
112
+ this.$description.items.push(item);
113
+ return this;
114
+ };
115
+
116
+ /**
117
+ * Adds an item to the collection
118
+ * @param {NdChild} label - The item to add
119
+ * @param {?NdChild} icon - The item to add
120
+ * @param {?string|{to: string, params: ?*}} url - The item to add
121
+ * @param {?Function} configBuilder - The item to add
122
+ * @param {?*} props - The item to add
123
+ * @returns {HasItems}
124
+ */
125
+ Menu.prototype.link = function(label, icon, url, configBuilder, props = {}) {
126
+ const item = MenuLink(props);
127
+ item.icon(icon).label(label).action(url)
128
+ if(typeof configBuilder === 'function') {
129
+ configBuilder.length ? configBuilder(item) : this.trailing(item);
130
+ } else if(configBuilder) {
131
+ this.trailing(item);
132
+ }
133
+ this.$description.items.push(item);
134
+ return this;
135
+ };
136
+
92
137
  Menu.prototype.divider = Menu.prototype.separator;
93
138
 
94
- Menu.prototype.group = function(label, icon, builder) {
95
- const group = new MenuGroup({ label, icon});
139
+ Menu.prototype.group = function(label, icon, builder, props = {}) {
140
+ const group = new MenuGroup(label, props);
141
+ group.icon(icon);
96
142
  builder && builder(group);
97
143
  return this.add(group);
98
144
  };
@@ -1,11 +1,14 @@
1
1
  import BaseComponent from "../BaseComponent";
2
2
 
3
3
 
4
- export default function MenuDivider() {
4
+ export default function MenuDivider(props = {}) {
5
5
  if(!(this instanceof MenuDivider)) {
6
- return new MenuDivider();
6
+ return new MenuDivider(props);
7
7
  }
8
8
 
9
+ this.$description = {
10
+ props
11
+ };
9
12
  }
10
13
 
11
14
  BaseComponent.extends(MenuDivider);
@@ -14,9 +17,5 @@ BaseComponent.extends(MenuDivider);
14
17
  MenuDivider.defaultTemplate = null;
15
18
 
16
19
  MenuDivider.use = function(template) {
17
- MenuDivider.defaultTemplate = template.divider;
18
- };
19
-
20
- MenuDivider.prototype.$build = function() {
21
-
20
+ MenuDivider.defaultTemplate = template.menuDivider;
22
21
  };
@@ -3,9 +3,9 @@ import HasItems from "../$traits/HasItems";
3
3
  import MenuDivider from "./MenuDivider";
4
4
 
5
5
 
6
- export default function MenuGroup(label, config) {
6
+ export default function MenuGroup(label, props) {
7
7
  if(!(this instanceof MenuGroup)) {
8
- return new MenuGroup(label, config);
8
+ return new MenuGroup(label, props);
9
9
  }
10
10
 
11
11
  this.$description = {
@@ -13,8 +13,8 @@ export default function MenuGroup(label, config) {
13
13
  data: null,
14
14
  items: [],
15
15
  render: null,
16
- ...config
17
- }
16
+ props
17
+ };
18
18
  }
19
19
 
20
20
  MenuGroup.defaultTemplate = null;
@@ -4,9 +4,9 @@ import MenuDivider from "./MenuDivider";
4
4
  import MenuGroup from "./MenuGroup";
5
5
 
6
6
 
7
- export default function MenuItem(config = {}) {
7
+ export default function MenuItem(props = {}) {
8
8
  if(!(this instanceof MenuItem)) {
9
- return new MenuItem(config);
9
+ return new MenuItem(props);
10
10
  }
11
11
 
12
12
  this.$description = {
@@ -21,7 +21,7 @@ export default function MenuItem(config = {}) {
21
21
  data: null,
22
22
  render: null,
23
23
  trailing: null,
24
- ...config
24
+ props
25
25
  };
26
26
 
27
27
  }
@@ -1,11 +1,11 @@
1
1
  import MenuItem from "./MenuItem";
2
2
 
3
3
 
4
- export default function MenuLink(config) {
4
+ export default function MenuLink(props = {}) {
5
5
  if(!(this instanceof MenuLink)) {
6
- return new MenuLink(config);
6
+ return new MenuLink(props);
7
7
  }
8
- MenuItem.call(this, config);
8
+ MenuItem.call(this, props);
9
9
  }
10
10
 
11
11
  MenuLink.prototype = Object.create(MenuItem.prototype);
@@ -2,11 +2,13 @@ import Menu from "./Menu";
2
2
  import MenuItem from "./MenuItem";
3
3
  import MenuGroup from "./MenuGroup";
4
4
  import MenuDivider from "./MenuDivider";
5
+ import MenuLink from "./MenuLink";
5
6
 
6
7
 
7
8
  export {
8
9
  Menu,
9
10
  MenuItem,
10
11
  MenuGroup,
11
- MenuDivider
12
+ MenuDivider,
13
+ MenuLink
12
14
  };