alchemy-widget 0.2.5 → 0.2.6

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,9 @@
1
+ ## 0.2.6 (2023-02-26)
2
+
3
+ * Replace *EasyMDE* markdown editor with *Toast editor*
4
+ * Implement the `valueHasContent` method
5
+ * Make sure widgets keep a link to the `conduit` instance
6
+
1
7
  ## 0.2.5 (2023-02-11)
2
8
 
3
9
  * Add `code_type` field to the `Sourcecode` widget
@@ -428,4 +428,20 @@ al-toc {
428
428
 
429
429
  .aw-hidden {
430
430
  opacity: 0.8;
431
+ }
432
+
433
+ al-widget[type="markdown"] {
434
+ .markdown-editor-container {
435
+ background: white;
436
+ }
437
+
438
+ .ProseMirror {
439
+ font-size: 1.1rem;
440
+ --default-font-family: "Roboto", sans-serif;
441
+ font-family: var(--font-family, var(--default-font-family));
442
+ }
443
+
444
+ .toastui-editor-toolbar .toastui-editor-md-tab-container .toastui-editor-tabs {
445
+ display: none;
446
+ }
431
447
  }
@@ -528,7 +528,7 @@ Widget.setStatic(function unDry(obj, custom_method, whenDone) {
528
528
  *
529
529
  * @author Jelle De Loecker <jelle@elevenways.be>
530
530
  * @since 0.1.0
531
- * @version 0.1.0
531
+ * @version 0.2.6
532
532
  *
533
533
  * @param {String} type The typeof widget to create
534
534
  * @param {Object} config The optional config object
@@ -546,6 +546,10 @@ Widget.setMethod(function createChildWidget(type, config) {
546
546
  // Create the instance
547
547
  let instance = new WidgetClass(config);
548
548
 
549
+ if (this.conduit) {
550
+ instance.conduit = this.conduit;
551
+ }
552
+
549
553
  // Set the parent instance!
550
554
  instance.parent_instance = this;
551
555
 
@@ -582,12 +586,16 @@ Widget.setMethod(function toDry() {
582
586
  *
583
587
  * @author Jelle De Loecker <jelle@elevenways.be>
584
588
  * @since 0.1.0
585
- * @version 0.2.0
589
+ * @version 0.2.6
586
590
  *
587
591
  * @return {Array}
588
592
  */
589
593
  Widget.setMethod(async function getActionbarActions() {
590
594
 
595
+ if (!this.constructor.actions) {
596
+ return [];
597
+ }
598
+
591
599
  let sorted = this.constructor.actions.getSorted(),
592
600
  result = [],
593
601
  action;
@@ -1008,4 +1016,41 @@ Widget.setMethod(function getHandle() {
1008
1016
  }
1009
1017
 
1010
1018
  return element;
1019
+ });
1020
+
1021
+ /**
1022
+ * See if the given value is considered not-empty for this widget
1023
+ *
1024
+ * @author Jelle De Loecker <jelle@elevenways.be>
1025
+ * @since 0.2.6
1026
+ * @version 0.2.6
1027
+ *
1028
+ * @return {Boolean}
1029
+ */
1030
+ Widget.setMethod(function valueHasContent(value) {
1031
+
1032
+ if (!value || typeof value != 'object') {
1033
+ return false;
1034
+ }
1035
+
1036
+ let entry,
1037
+ key;
1038
+
1039
+ for (key in value) {
1040
+ entry = value[key];
1041
+
1042
+ if (entry) {
1043
+ if (Array.isArray(entry) && entry.length) {
1044
+ return true;
1045
+ }
1046
+
1047
+ if (entry === '') {
1048
+ continue;
1049
+ }
1050
+
1051
+ return true;
1052
+ }
1053
+ }
1054
+
1055
+ return false;
1011
1056
  });
@@ -52,21 +52,35 @@ Markdown.setMethod(function populateWidget() {
52
52
  *
53
53
  * @author Jelle De Loecker <jelle@elevenways.be>
54
54
  * @since 0.1.0
55
- * @version 0.2.0
55
+ * @version 0.2.6
56
56
  */
57
57
  Markdown.setMethod(async function _startEditor() {
58
58
 
59
59
  Hawkejs.removeChildren(this.widget);
60
60
 
61
- hawkejs.scene.enableStyle('https://unpkg.com/easymde/dist/easymde.min.css');
62
- await hawkejs.require('https://unpkg.com/easymde/dist/easymde.min.js');
61
+ hawkejs.scene.enableStyle('https://uicdn.toast.com/editor/latest/toastui-editor.min.css');
62
+ await hawkejs.require('https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js');
63
63
 
64
- let element = this.createElement('textarea');
64
+ const Editor = toastui.Editor
65
+
66
+ let element = this.createElement('div');
67
+ element.classList.add('markdown-editor-container');
65
68
  this.widget.append(element);
66
- element.value = this.config.markdown || '';
67
69
 
68
- const easyMDE = new EasyMDE({element});
69
- this.easy_mde = easyMDE;
70
+ const editor = new Editor({
71
+ el : element,
72
+ height : '900px',
73
+ initialEditType : 'markdown',
74
+ previewStyle : 'vertical',
75
+ usageStatistics : false,
76
+ autofocus : false,
77
+ previewStyle : 'global',
78
+ hideModeSwitch : true,
79
+ initialEditType : 'markdown',
80
+ });
81
+
82
+ this.toast_editor = editor;
83
+ editor.setMarkdown(this.config.markdown || '');
70
84
  });
71
85
 
72
86
  /**
@@ -74,12 +88,19 @@ Markdown.setMethod(async function _startEditor() {
74
88
  *
75
89
  * @author Jelle De Loecker <jelle@elevenways.be>
76
90
  * @since 0.1.0
77
- * @version 0.2.2
91
+ * @version 0.2.6
78
92
  */
79
93
  Markdown.setMethod(function _stopEditor() {
80
94
 
81
95
  Hawkejs.removeChildren(this.widget);
82
- this.easy_mde = null;
96
+
97
+ if (this.toast_editor) {
98
+ try {
99
+ this.toast_editor.destroy();
100
+ } catch (err) {}
101
+ }
102
+
103
+ this.toast_editor = null;
83
104
 
84
105
  return this.loadWidget();
85
106
  });
@@ -89,7 +110,7 @@ Markdown.setMethod(function _stopEditor() {
89
110
  *
90
111
  * @author Jelle De Loecker <jelle@elevenways.be>
91
112
  * @since 0.1.0
92
- * @version 0.2.0
113
+ * @version 0.2.6
93
114
  *
94
115
  * @return {Object}
95
116
  */
@@ -97,8 +118,8 @@ Markdown.setMethod(function syncConfig() {
97
118
 
98
119
  let value = '';
99
120
 
100
- if (this.easy_mde) {
101
- value = this.easy_mde.value();
121
+ if (this.toast_editor) {
122
+ value = this.toast_editor.getMarkdown();
102
123
  }
103
124
 
104
125
  this.config.markdown = value;
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @author Jelle De Loecker <jelle@elevenways.be>
7
7
  * @since 0.1.0
8
- * @version 0.1.0
8
+ * @version 0.2.6
9
9
  */
10
10
  const WidgetField = Function.inherits('Alchemy.Field.Schema', function Widget(schema, name, options) {
11
11
 
@@ -17,12 +17,15 @@ const WidgetField = Function.inherits('Alchemy.Field.Schema', function Widget(sc
17
17
  options.type = 'text';
18
18
  }
19
19
 
20
+ // Already set the options (they'll be changed by the super call too though)
21
+ this.options = options;
22
+
20
23
  // A custom schema should NOT be passed to this class, this class uses
21
24
  // a fixed schema that should not be altered.
22
25
  // But because that's exactly what happens when cloning (like preparing
23
26
  // the data to be sent to Hawkejs) we have to allow it anyway
24
27
  if (!options.schema) {
25
- let WidgetClass = Classes.Alchemy.Widget.Widget.getMember(options.type),
28
+ let WidgetClass = this.widget_class,
26
29
  sub_schema = WidgetClass.schema.clone();
27
30
 
28
31
  options.schema = sub_schema;
@@ -31,6 +34,24 @@ const WidgetField = Function.inherits('Alchemy.Field.Schema', function Widget(sc
31
34
  Widget.super.call(this, schema, name, options);
32
35
  });
33
36
 
37
+ /**
38
+ * Get the constructor of the widget class
39
+ *
40
+ * @author Jelle De Loecker <jelle@elevenways.be>
41
+ * @since 0.2.6
42
+ * @version 0.2.6
43
+ *
44
+ * @type {Function}
45
+ */
46
+ WidgetField.setProperty(function widget_class() {
47
+
48
+ if (!this.options?.type) {
49
+ return;
50
+ }
51
+
52
+ return Classes.Alchemy.Widget.Widget.getMember(this.options.type)
53
+ });
54
+
34
55
  /**
35
56
  * Cast the given value to this field's type
36
57
  *
@@ -75,3 +96,33 @@ WidgetField.setMethod(function toDry() {
75
96
 
76
97
  return {value};
77
98
  });
99
+
100
+ /**
101
+ * See if the given value is considered not-empty for this field
102
+ *
103
+ * @author Jelle De Loecker <jelle@elevenways.be>
104
+ * @since 0.2.6
105
+ * @version 0.2.6
106
+ *
107
+ * @param {Mixed} value
108
+ *
109
+ * @return {Boolean}
110
+ */
111
+ WidgetField.setMethod(function valueHasContent(value) {
112
+
113
+ if (!value) {
114
+ return false;
115
+ }
116
+
117
+ let constructor = this.widget_class;
118
+
119
+ if (!constructor) {
120
+ return true;
121
+ }
122
+
123
+ value = this.cast(value);
124
+
125
+ let instance = new constructor();
126
+
127
+ return instance.valueHasContent(value);
128
+ });
@@ -36,4 +36,28 @@ const WidgetsField = Function.inherits('Alchemy.Field.Schema', function Widgets(
36
36
  WidgetsField.setMethod(function getOptionsForDrying() {
37
37
  let {schema, ...options} = this.options;
38
38
  return options;
39
+ });
40
+
41
+ /**
42
+ * See if the given value is considered not-empty for this field
43
+ *
44
+ * @author Jelle De Loecker <jelle@elevenways.be>
45
+ * @since 0.2.6
46
+ * @version 0.2.6
47
+ *
48
+ * @param {Mixed} value
49
+ *
50
+ * @return {Boolean}
51
+ */
52
+ WidgetsField.setMethod(function valueHasContent(value) {
53
+
54
+ if (!value) {
55
+ return false;
56
+ }
57
+
58
+ if (!value.widgets?.length) {
59
+ return false;
60
+ }
61
+
62
+ return true;
39
63
  });
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.5",
4
+ "version": "0.2.6",
5
5
  "author": "Jelle De Loecker <jelle@elevenways.be>",
6
6
  "keywords": [
7
7
  "alchemy",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "peerDependencies": {
13
13
  "alchemymvc" : ">=1.2.0",
14
- "alchemy-form": "~0.2.1"
14
+ "alchemy-form": "~0.2.4"
15
15
  },
16
16
  "repository": "11ways/alchemy-widget",
17
17
  "license": "MIT",