alchemy-form 0.2.4 → 0.2.5

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,7 @@
1
+ ## 0.2.5 (2023-04-20)
2
+
3
+ * Add more configuration to `al-code-input`
4
+
1
5
  ## 0.2.4 (2023-02-26)
2
6
 
3
7
  * Don't look for a field when the path is not specified
@@ -16,12 +16,57 @@ const CodeInput = Function.inherits('Alchemy.Element.Form.Base', 'CodeInput');
16
16
  */
17
17
  CodeInput.setTemplateFile('form/elements/code_input');
18
18
 
19
+ /**
20
+ * Line number info
21
+ *
22
+ * @author Jelle De Loecker <jelle@elevenways.be>
23
+ * @since 0.2.5
24
+ * @version 0.2.5
25
+ */
26
+ CodeInput.setAttribute('show-line-numbers', {type: 'boolean', default: true});
27
+
28
+ /**
29
+ * The ace mode to use
30
+ *
31
+ * @author Jelle De Loecker <jelle@elevenways.be>
32
+ * @since 0.2.5
33
+ * @version 0.2.5
34
+ */
35
+ CodeInput.setAttribute('language-mode');
36
+
37
+ /**
38
+ * The theme to use
39
+ *
40
+ * @author Jelle De Loecker <jelle@elevenways.be>
41
+ * @since 0.2.5
42
+ * @version 0.2.5
43
+ */
44
+ CodeInput.setAttribute('color-theme');
45
+
46
+ /**
47
+ * The minimum number of lines to show (height)
48
+ *
49
+ * @author Jelle De Loecker <jelle@elevenways.be>
50
+ * @since 0.2.5
51
+ * @version 0.2.5
52
+ */
53
+ CodeInput.setAttribute('min-lines', {type: 'number'});
54
+
55
+ /**
56
+ * The maximum number of lines to show (height)
57
+ *
58
+ * @author Jelle De Loecker <jelle@elevenways.be>
59
+ * @since 0.2.5
60
+ * @version 0.2.5
61
+ */
62
+ CodeInput.setAttribute('max-lines', {type: 'number'});
63
+
19
64
  /**
20
65
  * Get/set the value
21
66
  *
22
67
  * @author Jelle De Loecker <jelle@elevenways.be>
23
68
  * @since 0.1.0
24
- * @version 0.1.0
69
+ * @version 0.2.5
25
70
  */
26
71
  CodeInput.setProperty(function value(value) {
27
72
 
@@ -34,6 +79,11 @@ CodeInput.setProperty(function value(value) {
34
79
  if (editor_el) {
35
80
  return editor_el.textContent;
36
81
  }
82
+
83
+ if (this.assigned_data.value) {
84
+ return this.assigned_data.value;
85
+ }
86
+
37
87
  }, function setValue(value) {
38
88
 
39
89
  if (this._editor) {
@@ -51,6 +101,7 @@ CodeInput.setProperty(function value(value) {
51
101
  return editor_el.textContent = value;
52
102
  }
53
103
 
104
+ this.assigned_data.value = value;
54
105
  });
55
106
 
56
107
  /**
@@ -58,7 +109,7 @@ CodeInput.setProperty(function value(value) {
58
109
  *
59
110
  * @author Jelle De Loecker <jelle@elevenways.be>
60
111
  * @since 0.1.0
61
- * @version 0.1.10
112
+ * @version 0.2.5
62
113
  */
63
114
  CodeInput.setMethod(async function introduced() {
64
115
 
@@ -68,7 +119,20 @@ CodeInput.setMethod(async function introduced() {
68
119
 
69
120
  editor_el.hidden = false;
70
121
 
71
- let editor = ace.edit(editor_el);
122
+ let theme = this.color_theme || 'ace/theme/tomorrow_night_eighties';
123
+
124
+ if (!theme.startsWith('ace/theme')) {
125
+ theme = 'ace/theme/' + theme;
126
+ }
127
+
128
+ let options = {
129
+ showLineNumbers : this.show_line_numbers,
130
+ minLines : this.minLines || 4,
131
+ maxLines : this.maxLines || 50,
132
+ theme : theme,
133
+ };
134
+
135
+ let editor = ace.edit(editor_el, options);
72
136
 
73
137
  editor.session.setUseWrapMode(true);
74
138
  editor.setFontSize(16);
@@ -88,5 +152,17 @@ CodeInput.setMethod(async function introduced() {
88
152
  editor.session.setMode(mode);
89
153
  }
90
154
 
155
+ if (this.assigned_data.value) {
156
+ editor.setValue(this.assigned_data.value, -1);
157
+ }
158
+
159
+ if (this.language_mode) {
160
+ try {
161
+ editor.session.setMode('ace/mode/' + this.language_mode);
162
+ } catch (err) {
163
+ // Ignore
164
+ }
165
+ }
166
+
91
167
  this._editor = editor;
92
168
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "alchemy-form",
3
3
  "description": "Form plugin for Alchemy",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "https://github.com/11ways/alchemy-form.git"