alchemy-widget 0.2.5 → 0.2.7

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.
@@ -52,21 +52,17 @@ 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.7
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');
63
-
64
- let element = this.createElement('textarea');
65
- this.widget.append(element);
66
- element.value = this.config.markdown || '';
67
-
68
- const easyMDE = new EasyMDE({element});
69
- this.easy_mde = easyMDE;
61
+ if (this.use_toast) {
62
+ this._startToastEditor();
63
+ } else {
64
+ this._startCodeEditor();
65
+ }
70
66
  });
71
67
 
72
68
  /**
@@ -74,22 +70,99 @@ Markdown.setMethod(async function _startEditor() {
74
70
  *
75
71
  * @author Jelle De Loecker <jelle@elevenways.be>
76
72
  * @since 0.1.0
77
- * @version 0.2.2
73
+ * @version 0.2.7
78
74
  */
79
75
  Markdown.setMethod(function _stopEditor() {
80
76
 
81
77
  Hawkejs.removeChildren(this.widget);
82
- this.easy_mde = null;
78
+
79
+ if (this.use_toast) {
80
+ this._startToastEditor();
81
+ }
83
82
 
84
83
  return this.loadWidget();
85
84
  });
86
85
 
86
+ /**
87
+ * Start the code editor
88
+ *
89
+ * @author Jelle De Loecker <jelle@elevenways.be>
90
+ * @since 0.2.7
91
+ * @version 0.2.7
92
+ */
93
+ Markdown.setMethod(async function _startCodeEditor() {
94
+
95
+ let element = this.createElement('div');
96
+ element.classList.add('markdown-editor-container');
97
+ this.widget.append(element);
98
+
99
+ let code_input = this.createElement('al-code-input');
100
+ code_input.show_line_numbers = false;
101
+ element.append(code_input);
102
+
103
+ code_input.value = this.config.markdown || '';
104
+
105
+ this.code_input = code_input;
106
+ });
107
+
108
+ /**
109
+ * Start the toast editor
110
+ *
111
+ * @author Jelle De Loecker <jelle@elevenways.be>
112
+ * @since 0.2.7
113
+ * @version 0.2.7
114
+ */
115
+ Markdown.setMethod(async function _startToastEditor() {
116
+
117
+ hawkejs.scene.enableStyle('https://uicdn.toast.com/editor/latest/toastui-editor.min.css');
118
+ await hawkejs.require('https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js');
119
+
120
+ const Editor = toastui.Editor
121
+
122
+ let element = this.createElement('div');
123
+ element.classList.add('markdown-editor-container');
124
+ this.widget.append(element);
125
+
126
+ const editor = new Editor({
127
+ el : element,
128
+ height : '600px',
129
+ initialEditType : 'markdown',
130
+ previewStyle : 'vertical',
131
+ usageStatistics : false,
132
+ autofocus : false,
133
+ previewStyle : 'global',
134
+ hideModeSwitch : true,
135
+ initialEditType : 'markdown',
136
+ });
137
+
138
+ this.toast_editor = editor;
139
+ editor.setMarkdown(this.config.markdown || '');
140
+ });
141
+
142
+ /**
143
+ * Stop the toast editor
144
+ *
145
+ * @author Jelle De Loecker <jelle@elevenways.be>
146
+ * @since 0.2.7
147
+ * @version 0.2.7
148
+ */
149
+ Markdown.setMethod(function _stopToastEditor() {
150
+
151
+ if (this.toast_editor) {
152
+ try {
153
+ this.toast_editor.destroy();
154
+ } catch (err) {}
155
+ }
156
+
157
+ this.toast_editor = null;
158
+ });
159
+
87
160
  /**
88
161
  * Get the config of this widget
89
162
  *
90
163
  * @author Jelle De Loecker <jelle@elevenways.be>
91
164
  * @since 0.1.0
92
- * @version 0.2.0
165
+ * @version 0.2.7
93
166
  *
94
167
  * @return {Object}
95
168
  */
@@ -97,8 +170,10 @@ Markdown.setMethod(function syncConfig() {
97
170
 
98
171
  let value = '';
99
172
 
100
- if (this.easy_mde) {
101
- value = this.easy_mde.value();
173
+ if (this.toast_editor) {
174
+ value = this.toast_editor.getMarkdown();
175
+ } else if (this.code_input) {
176
+ value = this.code_input.value;
102
177
  }
103
178
 
104
179
  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
  });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Add a method to the conduit class to set the toolbar manager
3
+ *
4
+ * @author Jelle De Loecker <jelle@elevenways.be>
5
+ * @since 0.2.7
6
+ * @version 0.2.7
7
+ *
8
+ * @param {Alchemy.Document} document_or_model
9
+ */
10
+ Classes.Alchemy.Conduit.Conduit.setMethod(function setToolbarInfo(document_or_model, scenario = 'frontend') {
11
+ try {
12
+ _setToolbarInfo.call(this, document_or_model, scenario);
13
+ } catch (err) {
14
+ console.error('Error setting toolbar info', err);
15
+ }
16
+ });
17
+
18
+ /**
19
+ * Add a method to the conduit class to set the toolbar manager
20
+ *
21
+ * @author Jelle De Loecker <jelle@elevenways.be>
22
+ * @since 0.2.7
23
+ * @version 0.2.7
24
+ *
25
+ * @param {Alchemy.Document} document_or_model
26
+ */
27
+ function _setToolbarInfo(document_or_model, scenario = 'frontend') {
28
+
29
+ if (!this.hasPermission('alchemy.widgets.toolbar')) {
30
+ return;
31
+ }
32
+
33
+ let manager = Classes.Alchemy.Widget.EditorToolbarManager.create(this);
34
+ manager.scenario = scenario;
35
+
36
+ this.set('toolbar_manager', manager);
37
+ this.expose('toolbar_manager', manager);
38
+
39
+ let document_watcher,
40
+ document,
41
+ model;
42
+
43
+ if (document_or_model) {
44
+ if (document_or_model instanceof Classes.Alchemy.Document.Document) {
45
+ document = document_or_model;
46
+ } else {
47
+ model = document_or_model;
48
+ }
49
+ }
50
+
51
+ document_watcher = manager.setDocument(document);
52
+
53
+ if (document) {
54
+ manager.setModel(document.$model_name);
55
+ document_watcher.addWatcher(this);
56
+
57
+ this.set('edit_model_name', document.$model_name);
58
+ this.set('edit_model_pk', document.$pk);
59
+ } else if (model) {
60
+ manager.setModel(model.model_name);
61
+ this.set('edit_model_name', model.model_name);
62
+ } else {
63
+ manager.setModel(null);
64
+ }
65
+ };
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.7",
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",
@@ -0,0 +1,3 @@
1
+ <div data-he-slot="left"></div>
2
+ <div data-he-slot="center"></div>
3
+ <div data-he-slot="right"></div>
@@ -0,0 +1,5 @@
1
+ <div class="bubble-representation">
2
+ <span class="first-letter">
3
+ {{ self.first_letter }}
4
+ </span>
5
+ </div>
@@ -46,4 +46,10 @@
46
46
  <al-icon icon-style="duotone" icon-name="display-code"></al-icon>
47
47
  {%t "go-to-backend" %}
48
48
  </a>
49
- {% /if %}
49
+ {% /if %}
50
+
51
+ <al-user-avatar-group
52
+ class="watchers"
53
+ ></al-user-avatar-group>
54
+
55
+ <div data-area="buttons"></div>