alchemy-widget 0.2.2 → 0.2.3

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.2.3 (2023-01-23)
2
+
3
+ * Fix `List` widgets not having their content saved
4
+ * Fix more issues with saving to the database
5
+
1
6
  ## 0.2.2 (2022-12-23)
2
7
 
3
8
  * Fix widgets not being populated properly
@@ -225,7 +225,7 @@ AlchemyWidgets.setAction(async function uploadImage(conduit) {
225
225
  id : result._id,
226
226
  };
227
227
 
228
- let default_path = alchemy.routeUrl('Media::image', params);
228
+ let default_path = alchemy.routeUrl('MediaFile#image', params);
229
229
  let url = RURL.parse(default_path);
230
230
 
231
231
  let path_800 = url.clone();
@@ -389,6 +389,22 @@ Widget.setMethod(function getContextButton() {
389
389
  return button;
390
390
  });
391
391
 
392
+ /**
393
+ * Get a list of elements that could be child widgets
394
+ *
395
+ * @author Jelle De Loecker <jelle@elevenways.be>
396
+ * @since 0.2.3
397
+ * @version 0.2.3
398
+ */
399
+ Widget.setMethod(function getPossibleWidgetChildren() {
400
+
401
+ if (this.instance && typeof this.instance.getPossibleWidgetChildren == 'function') {
402
+ return this.instance.getPossibleWidgetChildren();
403
+ }
404
+
405
+ return this.children;
406
+ });
407
+
392
408
  /**
393
409
  * Show the config button
394
410
  *
@@ -139,19 +139,20 @@ AlchemyWidgets.setMethod(function applyValue(value) {
139
139
  *
140
140
  * @author Jelle De Loecker <jelle@elevenways.be>
141
141
  * @since 0.1.0
142
- * @version 0.1.0
142
+ * @version 0.2.3
143
143
  *
144
144
  * @return {Array}
145
145
  */
146
146
  AlchemyWidgets.setMethod(function getWidgetsConfig() {
147
147
 
148
- let widgets = [],
148
+ let children = this.getPossibleWidgetChildren(),
149
+ widgets = [],
149
150
  child,
150
151
  temp,
151
152
  i;
152
153
 
153
- for (i = 0; i < this.children.length; i++) {
154
- child = this.children[i];
154
+ for (i = 0; i < children.length; i++) {
155
+ child = children[i];
155
156
 
156
157
  if (child instanceof Classes.Alchemy.Element.Widget.Base) {
157
158
  temp = child.value;
@@ -11,6 +11,18 @@
11
11
  */
12
12
  const List = Function.inherits('Alchemy.Widget.Container', 'List');
13
13
 
14
+ /**
15
+ * Get a list of elements that could be child widgets
16
+ *
17
+ * @author Jelle De Loecker <jelle@elevenways.be>
18
+ * @since 0.2.3
19
+ * @version 0.2.3
20
+ */
21
+ List.setMethod(function getPossibleWidgetChildren() {
22
+ let children = this.widget.querySelectorAll(':scope > ul > li > *');
23
+ return children;
24
+ });
25
+
14
26
  /**
15
27
  * Dummy populate method
16
28
  *
@@ -57,7 +57,7 @@ Partial.constitute(function prepareSchema() {
57
57
  let contents = this.createSchema();
58
58
 
59
59
  contents.addField('name', 'String');
60
- contents.addField('content', 'Widgets');
60
+ contents.addField('contents', 'Widgets');
61
61
 
62
62
  this.schema.addField('contents', contents, {array: true});
63
63
  });
@@ -87,7 +87,26 @@ Partial.setMethod(async function populateWidget() {
87
87
 
88
88
  if (this.config?.contents?.length) {
89
89
  for (let entry of this.config.contents) {
90
- variables[entry.name] = entry.contents;
90
+
91
+ let actual_contents;
92
+
93
+ if (entry.contents) {
94
+ if (entry.contents.config) {
95
+ actual_contents = entry.contents.config;
96
+ } else if (entry.contents.widgets) {
97
+ actual_contents = entry.contents.widgets;
98
+
99
+ let type = actual_contents?.[0]?.type;
100
+
101
+ if (type == 'container' || type == 'row') {
102
+ actual_contents = actual_contents[0].config?.widgets;
103
+ } else {
104
+ actual_contents = actual_contents[0];
105
+ }
106
+ }
107
+ }
108
+
109
+ variables[entry.name] = actual_contents;
91
110
  }
92
111
  }
93
112
 
@@ -180,7 +199,7 @@ Partial.setMethod(function _stopEditor() {
180
199
  *
181
200
  * @author Jelle De Loecker <jelle@elevenways.be>
182
201
  * @since 0.1.6
183
- * @version 0.1.6
202
+ * @version 0.2.3
184
203
  *
185
204
  * @return {Object}
186
205
  */
@@ -206,7 +225,23 @@ Partial.setMethod(function syncConfig() {
206
225
  contents.push(widget_config);
207
226
  }
208
227
 
209
- widget_config.contents = sub_widget.value;
228
+ let value = sub_widget.value,
229
+ widget_contents;
230
+
231
+ if (value?.widgets) {
232
+ widget_contents = {
233
+ widgets : [{
234
+ type : 'row',
235
+ config : value,
236
+ }]
237
+ };
238
+ } else {
239
+ widget_contents = {
240
+ widgets: Array.cast(value)
241
+ };
242
+ }
243
+
244
+ widget_config.contents = widget_contents;
210
245
  }
211
246
 
212
247
  return this.config;
@@ -52,4 +52,26 @@ WidgetField.setMethod(function cast(value, to_datasource) {
52
52
  }
53
53
 
54
54
  return value;
55
- });
55
+ });
56
+
57
+ /**
58
+ * Convert to JSON
59
+ *
60
+ * @author Jelle De Loecker <jelle@elevenways.be>
61
+ * @since 0.2.3
62
+ * @version 0.2.3
63
+ *
64
+ * @return {Object}
65
+ */
66
+ WidgetField.setMethod(function toDry() {
67
+
68
+ let {schema, ...options} = this.options;
69
+
70
+ let value = {
71
+ schema : this.schema,
72
+ name : this.name,
73
+ options : options,
74
+ };
75
+
76
+ return {value};
77
+ });
@@ -22,4 +22,18 @@ const WidgetsField = Function.inherits('Alchemy.Field.Schema', function Widgets(
22
22
  }
23
23
 
24
24
  Widgets.super.call(this, schema, name, options);
25
+ });
26
+
27
+ /**
28
+ * Get the client-side options
29
+ *
30
+ * @author Jelle De Loecker <jelle@develry.be>
31
+ * @since 0.2.3
32
+ * @version 0.2.3
33
+ *
34
+ * @return {Object}
35
+ */
36
+ WidgetsField.setMethod(function getOptionsForDrying() {
37
+ let {schema, ...options} = this.options;
38
+ return options;
25
39
  });
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.2.2",
4
+ "version": "0.2.3",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",