alchemy-widget 0.2.1 → 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,12 @@
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
+
6
+ ## 0.2.2 (2022-12-23)
7
+
8
+ * Fix widgets not being populated properly
9
+
1
10
  ## 0.2.1 (2022-12-23)
2
11
 
3
12
  * Add a `-first` modifier class to the first visible entry of a table-of-contents element
@@ -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();
@@ -215,7 +215,7 @@ Widget.setMethod(function getValueFromRecord(record) {
215
215
  *
216
216
  * @author Jelle De Loecker <jelle@elevenways.be>
217
217
  * @since 0.1.5
218
- * @version 0.1.6
218
+ * @version 0.2.1
219
219
  */
220
220
  Widget.setMethod(function applyValue(value) {
221
221
 
@@ -255,7 +255,7 @@ Widget.setMethod(function applyValue(value) {
255
255
  }
256
256
 
257
257
  this.instance.config = config;
258
- let promise = this.instance.populateWidget();
258
+ let promise = this.instance.loadWidget();
259
259
 
260
260
  if (promise) {
261
261
  this.delayAssemble(promise);
@@ -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;
@@ -627,7 +627,7 @@ Widget.setMethod(function _createWidgetElement() {
627
627
  *
628
628
  * @author Jelle De Loecker <jelle@elevenways.be>
629
629
  * @since 0.1.0
630
- * @version 0.1.0
630
+ * @version 0.2.2
631
631
  *
632
632
  * @return {HTMLElement}
633
633
  */
@@ -641,14 +641,41 @@ Widget.setMethod(function _createPopulatedWidgetElement() {
641
641
 
642
642
  this.widget = element;
643
643
 
644
- // See if it can be populated
645
- if (typeof this.populateWidget == 'function') {
646
- this.populateWidget(element);
647
- }
644
+ this.loadWidget();
648
645
 
649
646
  return element;
650
647
  });
651
648
 
649
+ /**
650
+ * Load the widget element: populate it & finalize it
651
+ *
652
+ * @author Jelle De Loecker <jelle@elevenways.be>
653
+ * @since 0.2.2
654
+ * @version 0.2.2
655
+ *
656
+ * @return {Promise|null}
657
+ */
658
+ Widget.setMethod(function loadWidget() {
659
+
660
+ let populate = this.populateWidget();
661
+
662
+ if (Pledge.isThenable(populate)) {
663
+ let pledge = new Pledge();
664
+
665
+ Pledge.done(populate, (err, result) => {
666
+
667
+ if (err) {
668
+ pledge.reject(err);
669
+ }
670
+
671
+ pledge.resolve(this.finalizePopulatedWidget());
672
+ });
673
+
674
+ return pledge;
675
+ } else {
676
+ return this.finalizePopulatedWidget();
677
+ }
678
+ });
652
679
 
653
680
  /**
654
681
  * Populate the actual widget
@@ -826,14 +853,13 @@ Widget.setMethod(function stopEditor() {
826
853
  *
827
854
  * @author Jelle De Loecker <jelle@elevenways.be>
828
855
  * @since 0.1.0
829
- * @version 0.2.1
856
+ * @version 0.2.2
830
857
  */
831
858
  Widget.setMethod(async function rerender() {
832
859
 
833
860
  Hawkejs.removeChildren(this.widget);
834
861
 
835
- await this.populateWidget();
836
- await this.finalizePopulatedWidget();
862
+ await this.loadWidget();
837
863
 
838
864
  if (this.editing) {
839
865
  this.startEditor();
@@ -38,12 +38,10 @@ Container.constitute(function prepareSchema() {
38
38
  *
39
39
  * @author Jelle De Loecker <jelle@elevenways.be>
40
40
  * @since 0.1.0
41
- * @version 0.1.0
42
- *
43
- * @return {HTMLElement}
41
+ * @version 0.2.2
44
42
  */
45
43
  Container.setMethod(function initContainer() {
46
- this.populateWidget();
44
+ return this.loadWidget();
47
45
  });
48
46
 
49
47
  /**
@@ -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
  *
@@ -178,7 +178,7 @@ Tabs.setMethod(function _startEditor() {
178
178
  *
179
179
  * @author Jelle De Loecker <jelle@elevenways.be>
180
180
  * @since 0.2.0
181
- * @version 0.2.0
181
+ * @version 0.2.2
182
182
  */
183
183
  Tabs.setMethod(function _stopEditor() {
184
184
 
@@ -189,5 +189,5 @@ Tabs.setMethod(function _stopEditor() {
189
189
  sub_widget.stopEditor();
190
190
  }
191
191
 
192
- this.populateWidget();
192
+ this.loadWidget();
193
193
  });
@@ -74,14 +74,14 @@ Markdown.setMethod(async function _startEditor() {
74
74
  *
75
75
  * @author Jelle De Loecker <jelle@elevenways.be>
76
76
  * @since 0.1.0
77
- * @version 0.1.0
77
+ * @version 0.2.2
78
78
  */
79
79
  Markdown.setMethod(function _stopEditor() {
80
80
 
81
81
  Hawkejs.removeChildren(this.widget);
82
82
  this.easy_mde = null;
83
83
 
84
- this.populateWidget();
84
+ return this.loadWidget();
85
85
  });
86
86
 
87
87
  /**
@@ -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
 
@@ -161,7 +180,7 @@ Partial.setMethod(function _startEditor() {
161
180
  *
162
181
  * @author Jelle De Loecker <jelle@elevenways.be>
163
182
  * @since 0.1.6
164
- * @version 0.1.6
183
+ * @version 0.2.2
165
184
  */
166
185
  Partial.setMethod(function _stopEditor() {
167
186
 
@@ -172,7 +191,7 @@ Partial.setMethod(function _stopEditor() {
172
191
  sub_widget.stopEditor();
173
192
  }
174
193
 
175
- this.populateWidget();
194
+ return this.loadWidget();
176
195
  });
177
196
 
178
197
  /**
@@ -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;
@@ -80,13 +80,13 @@ Sourcecode.setMethod(function _startEditor() {
80
80
  *
81
81
  * @author Jelle De Loecker <jelle@elevenways.be>
82
82
  * @since 0.1.0
83
- * @version 0.1.0
83
+ * @version 0.2.2
84
84
  */
85
85
  Sourcecode.setMethod(function _stopEditor() {
86
86
 
87
87
  Hawkejs.removeChildren(this.widget);
88
88
 
89
- this.populateWidget();
89
+ return this.loadWidget();
90
90
  });
91
91
 
92
92
  /**
@@ -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.1",
4
+ "version": "0.2.3",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",