alchemy-widget 0.1.3 → 0.1.4

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.4 (2022-06-23)
2
+
3
+ * Use `he-context-menu` element to show widgets to add
4
+ * Add widget actions to move across container boundaries
5
+
1
6
  ## 0.1.3 (2022-03-21)
2
7
 
3
8
  * Catch and print errors when appending a widget to a container
@@ -11,7 +11,7 @@ alchemy-widgets-column {
11
11
  }
12
12
 
13
13
  > * {
14
- flex: 1;
14
+ flex: 10;
15
15
  }
16
16
  }
17
17
 
@@ -53,7 +53,7 @@ alchemy-widgets {
53
53
 
54
54
  alchemy-widgets-row {
55
55
  flex-flow: row;
56
- flex: 1 1 auto;
56
+ flex: 10 10 auto;
57
57
 
58
58
  &.aw-editing {
59
59
  padding-right: 5rem;
@@ -91,7 +91,7 @@ alchemy-widgets-column > alchemy-widgets-column,
91
91
  }
92
92
 
93
93
  alchemy-widgets-column {
94
- flex: 1 1 auto;
94
+ flex: 10 10 auto;
95
95
  }
96
96
 
97
97
  alchemy-widgets-column,
@@ -149,8 +149,8 @@ alchemy-widget-add-area {
149
149
  display: flex;
150
150
  align-content: center;
151
151
  min-height: 26px;
152
- min-width: 26px;
153
152
  align-items: center;
153
+ text-transform: uppercase;
154
154
 
155
155
  &:hover {
156
156
  color: #388ae5;
@@ -42,9 +42,89 @@ Base.setAssignedProperty('instance');
42
42
  *
43
43
  * @author Jelle De Loecker <jelle@elevenways.be>
44
44
  * @since 0.1.0
45
- * @version 0.1.0
45
+ * @version 0.1.4
46
+ */
47
+ Base.setProperty(function parent_container() {
48
+
49
+ let container,
50
+ current = this.parentElement;
51
+
52
+ while (current) {
53
+ if (current.is_container) {
54
+ container = current;
55
+ break;
56
+ }
57
+
58
+ current = current.parentElement;
59
+ }
60
+
61
+ return container;
62
+ });
63
+
64
+ /**
65
+ * The next container across container boundaries
66
+ *
67
+ * @author Jelle De Loecker <jelle@elevenways.be>
68
+ * @since 0.1.4
69
+ * @version 0.1.4
70
+ */
71
+ Base.setProperty(function next_container() {
72
+ return this.getSiblingContainer('next');
73
+ });
74
+
75
+ /**
76
+ * The previous container across container boundaries
77
+ *
78
+ * @author Jelle De Loecker <jelle@elevenways.be>
79
+ * @since 0.1.4
80
+ * @version 0.1.4
46
81
  */
47
- Base.setProperty('parent_container');
82
+ Base.setProperty(function previous_container() {
83
+ return this.getSiblingContainer('previous');
84
+ });
85
+
86
+ /**
87
+ * Get a sibling container
88
+ *
89
+ * @author Jelle De Loecker <jelle@elevenways.be>
90
+ * @since 0.1.4
91
+ * @version 0.1.4
92
+ */
93
+ Base.setMethod(function getSiblingContainer(type) {
94
+ let property;
95
+
96
+ if (type == 'next') {
97
+ property = 'nextElementSibling';
98
+ } else if (type == 'previous') {
99
+ property = 'previousElementSibling';
100
+ } else {
101
+ return false;
102
+ }
103
+
104
+ if (!this[property] && !this.parent_container) {
105
+ return;
106
+ }
107
+
108
+ let next = this[property];
109
+
110
+ if (next) {
111
+ if (next.is_container) {
112
+ return next;
113
+ }
114
+
115
+ if (next.tagName != 'ALCHEMY-WIDGET-ADD-AREA') {
116
+ return false;
117
+ }
118
+ }
119
+
120
+ next = this.parent_container[property];
121
+
122
+ if (next && next.is_container) {
123
+ return next;
124
+ }
125
+
126
+ return false;
127
+ });
48
128
 
49
129
  /**
50
130
  * Look for a context variable
@@ -32,6 +32,15 @@ AlchemyWidgets.setStatic('custom_element_prefix', 'alchemy-widgets');
32
32
  */
33
33
  AlchemyWidgets.setProperty('add_edit_event_listeners', false);
34
34
 
35
+ /**
36
+ * Indicate this is a container
37
+ *
38
+ * @author Jelle De Loecker <jelle@elevenways.be>
39
+ * @since 0.1.4
40
+ * @version 0.1.4
41
+ */
42
+ AlchemyWidgets.setProperty('is_container', true);
43
+
35
44
  /**
36
45
  * Context variables
37
46
  *
@@ -206,9 +215,6 @@ AlchemyWidgets.setMethod(function addWidget(type, config) {
206
215
  // Get the actual widget HTML element
207
216
  let element = instance.element;
208
217
 
209
- // Make the element know what its parent container is
210
- element.parent_container = this;
211
-
212
218
  this._appendWidgetElement(element);
213
219
 
214
220
  element.value = config;
@@ -26,11 +26,9 @@ let AddArea = Function.inherits('Alchemy.Element.Widget.Base', function AlchemyW
26
26
  * @since 0.1.0
27
27
  * @version 0.1.0
28
28
  */
29
- AddArea.setMethod(function showTypes() {
29
+ AddArea.setMethod(function showTypes(event) {
30
30
 
31
- let that = this,
32
- types_element = this.querySelector('.widget-types'),
33
- widgets = alchemy.getClassGroup('widgets');
31
+ let that = this;
34
32
 
35
33
  let context_button = document.querySelector('alchemy-widget-context');
36
34
 
@@ -38,31 +36,25 @@ AddArea.setMethod(function showTypes() {
38
36
  context_button.unselectedWidget();
39
37
  }
40
38
 
41
- this.classList.add('show-types');
39
+ let context = this.createElement('he-context-menu');
42
40
 
43
- Hawkejs.removeChildren(types_element);
41
+ let widgets = Object.values(alchemy.getClassGroup('widgets')).sortByPath(1, 'title');
44
42
 
45
- for (let key in widgets) {
43
+ for (let widget of widgets) {
46
44
 
47
- if (key == 'container') {
45
+ if (widget.type_name == 'container') {
48
46
  continue;
49
47
  }
50
48
 
51
- let widget = widgets[key];
52
-
53
- let button = this.createElement('button');
54
- button.setAttribute('data-type', key);
55
- button.textContent = widget.title;
56
-
57
- button.addEventListener('click', function onClick(e) {
58
- e.preventDefault();
59
- that.classList.remove('show-types');
60
-
61
- that.parentElement.addWidget(key);
49
+ context.addEntry({
50
+ title : widget.title,
51
+ icon : null,
52
+ }, e => {
53
+ that.parentElement.addWidget(widget.type_name);
62
54
  });
63
-
64
- types_element.append(button);
65
55
  }
56
+
57
+ context.show(event);
66
58
  });
67
59
 
68
60
  /**
@@ -107,7 +99,7 @@ AddArea.setMethod(function introduced() {
107
99
 
108
100
  add_button.addEventListener('click', function onClick(e) {
109
101
  e.preventDefault();
110
- that.showTypes();
102
+ that.showTypes(e);
111
103
  });
112
104
 
113
105
  let context_button = this.querySelector('.menu-button');
@@ -38,6 +38,7 @@ Toolbar.setMethod(function showWidgetActions(widget) {
38
38
  button.classList.add('aw-toolbar-button');
39
39
 
40
40
  button.innerHTML = action.getButtonHTML();
41
+ button.setAttribute('title', action.title);
41
42
 
42
43
  let is_selected = action.isAlreadySelected(widget);
43
44
 
@@ -107,12 +107,16 @@ Widget.constitute(function prepareSchema() {
107
107
 
108
108
  // Extra classnames for the wrapper
109
109
  this.schema.addField('wrapper_class_names', 'String', {
110
+ title : 'Wrapper CSS classes',
111
+ description : 'Configure extra CSS classes to the wrapper `alchemy-widget` element',
110
112
  array: true,
111
113
  widget_config_editable: true,
112
114
  });
113
115
 
114
116
  // Classnames for the inserted element (if any)
115
117
  this.schema.addField('main_class_names', 'String', {
118
+ title : 'Main CSS classes',
119
+ description : 'Configure extra CSS classes for the main inserted element',
116
120
  array: true,
117
121
  });
118
122
 
@@ -179,6 +183,47 @@ Widget.constitute(function prepareSchema() {
179
183
 
180
184
  move_right.setIcon('gg-arrow-right');
181
185
 
186
+ // The move-in-left action
187
+ let move_in_left = this.createAction('move-in-left', 'Move in left');
188
+
189
+ move_in_left.close_toolbar = true;
190
+
191
+ move_in_left.setHandler(function moveLeftAction(widget_el, handle) {
192
+ // Hawkejs custom element method!
193
+ let container = handle.previous_container;
194
+
195
+ if (container) {
196
+ container.append(handle);
197
+ }
198
+ });
199
+
200
+ move_in_left.setTester(function moveLeftTest(widget_el, handle) {
201
+ return !!handle.previous_container;
202
+ });
203
+
204
+ move_in_left.setIcon('gg-arrow-left');
205
+
206
+ // The move-in-right action
207
+ let move_in_right = this.createAction('move-in-right', 'Move in right');
208
+
209
+ move_in_right.close_toolbar = true;
210
+
211
+ move_in_right.setHandler(function moveRightAction(widget_el, handle) {
212
+ // Hawkejs custom element method!
213
+ let container = handle.next_container;
214
+
215
+ if (container) {
216
+ container.prepend(handle);
217
+ }
218
+ });
219
+
220
+ move_in_right.setTester(function moveRightTest(widget_el, handle) {
221
+ console.log('Right test of:', handle)
222
+ return !!handle.next_container;
223
+ });
224
+
225
+ move_in_right.setIcon('gg-arrow-right');
226
+
182
227
  let css_class = this.createAction('css-class', 'CSS Class');
183
228
 
184
229
  css_class.setHandler(function setCssClass(widget_el, handle) {
@@ -212,11 +257,11 @@ Widget.setStatic(function createSchema() {
212
257
  *
213
258
  * @author Jelle De Loecker <jelle@elevenways.be>
214
259
  * @since 0.1.0
215
- * @version 0.1.0
260
+ * @version 0.1.4
216
261
  */
217
- Widget.setStatic(function createAction(name) {
262
+ Widget.setStatic(function createAction(name, title) {
218
263
 
219
- let action = new Classes.Alchemy.Widget.Action(name);
264
+ let action = new Classes.Alchemy.Widget.Action(name, title || name.titleize());
220
265
 
221
266
  this.actions.set(name, action);
222
267
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "alchemy-widget",
3
3
  "description": "The widget plugin for the AlchemyMVC",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",