@@ -20,18 +20,21 @@ const commands = editor.Commands;
20
20
21
21
- [ add] [ 2 ]
22
22
- [ get] [ 3 ]
23
- - [ has] [ 4 ]
24
- - [ run] [ 5 ]
25
- - [ stop] [ 6 ]
23
+ - [ getAll] [ 4 ]
24
+ - [ has] [ 5 ]
25
+ - [ run] [ 6 ]
26
+ - [ stop] [ 7 ]
27
+ - [ isActive] [ 8 ]
28
+ - [ getActive] [ 9 ]
26
29
27
30
## add
28
31
29
32
Add new command to the collection
30
33
31
34
### Parameters
32
35
33
- - ` id ` ** [ string] [ 7 ] ** Command's ID
34
- - ` command ` ** ([ Object] [ 8 ] \| [ Function] [ 9 ] )** Object representing your command,
36
+ - ` id ` ** [ string] [ 10 ] ** Command's ID
37
+ - ` command ` ** ([ Object] [ 11 ] \| [ Function] [ 12 ] )** Object representing your command,
35
38
By passing just a function it's intended as a stateless command
36
39
(just like passing an object with only ` run ` method).
37
40
@@ -57,7 +60,7 @@ Get command by ID
57
60
58
61
### Parameters
59
62
60
- - ` id ` ** [ string] [ 7 ] ** Command's ID
63
+ - ` id ` ** [ string] [ 10 ] ** Command's ID
61
64
62
65
### Examples
63
66
@@ -66,26 +69,32 @@ var myCommand = commands.get('myCommand');
66
69
myCommand .run ();
67
70
```
68
71
69
- Returns ** [ Object] [ 8 ] ** Object representing the command
72
+ Returns ** [ Object] [ 11 ] ** Object representing the command
70
73
71
74
## has
72
75
73
76
Check if command exists
74
77
75
78
### Parameters
76
79
77
- - ` id ` ** [ string] [ 7 ] ** Command's ID
80
+ - ` id ` ** [ string] [ 10 ] ** Command's ID
78
81
79
- Returns ** [ Boolean] [ 10 ] **
82
+ Returns ** [ Boolean] [ 13 ] **
83
+
84
+ ## getAll
85
+
86
+ Get an object containing all the commands
87
+
88
+ Returns ** [ Object] [ 11 ] **
80
89
81
90
## run
82
91
83
92
Execute the command
84
93
85
94
### Parameters
86
95
87
- - ` id ` ** [ String] [ 7 ] ** Command ID
88
- - ` options ` ** [ Object] [ 8 ] ** Options (optional, default ` {} ` )
96
+ - ` id ` ** [ String] [ 10 ] ** Command ID
97
+ - ` options ` ** [ Object] [ 11 ] ** Options (optional, default ` {} ` )
89
98
90
99
### Examples
91
100
@@ -101,8 +110,8 @@ Stop the command
101
110
102
111
### Parameters
103
112
104
- - ` id ` ** [ String] [ 7 ] ** Command ID
105
- - ` options ` ** [ Object] [ 8 ] ** Options (optional, default ` {} ` )
113
+ - ` id ` ** [ String] [ 10 ] ** Command ID
114
+ - ` options ` ** [ Object] [ 11 ] ** Options (optional, default ` {} ` )
106
115
107
116
### Examples
108
117
@@ -112,22 +121,65 @@ commands.stop('myCommand', { someOption: 1 });
112
121
113
122
Returns ** any** The return is defined by the command
114
123
124
+ ## isActive
125
+
126
+ Check if the command is active. You activate commands with ` run `
127
+ and disable them with ` stop ` . If the command was created without ` stop `
128
+ method it can't be registered as active
129
+
130
+ ### Parameters
131
+
132
+ - ` id ` ** [ String] [ 10 ] ** Command id
133
+
134
+ ### Examples
135
+
136
+ ``` javascript
137
+ const cId = ' some-command' ;
138
+ commands .run (cId);
139
+ commands .isActive (cId);
140
+ // -> true
141
+ commands .stop (cId);
142
+ commands .isActive (cId);
143
+ // -> false
144
+ ```
145
+
146
+ Returns ** [ Boolean] [ 13 ] **
147
+
148
+ ## getActive
149
+
150
+ Get all active commands
151
+
152
+ ### Examples
153
+
154
+ ``` javascript
155
+ console .log (commands .getActive ());
156
+ // -> { someCommand: itsLastReturn, anotherOne: ... };
157
+ ```
158
+
159
+ Returns ** [ Object] [ 11 ] **
160
+
115
161
[ 1 ] : https://github.com/artf/grapesjs/blob/master/src/commands/config/config.js
116
162
117
163
[ 2 ] : #add
118
164
119
165
[ 3 ] : #get
120
166
121
- [ 4 ] : #has
167
+ [ 4 ] : #getall
168
+
169
+ [ 5 ] : #has
170
+
171
+ [ 6 ] : #run
172
+
173
+ [ 7 ] : #stop
122
174
123
- [ 5 ] : #run
175
+ [ 8 ] : #isactive
124
176
125
- [ 6 ] : #stop
177
+ [ 9 ] : #getactive
126
178
127
- [ 7 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
179
+ [ 10 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
128
180
129
- [ 8 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
181
+ [ 11 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
130
182
131
- [ 9 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
183
+ [ 12 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
132
184
133
- [ 10 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
185
+ [ 13 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
0 commit comments