alchemy-widget 0.1.6 → 0.2.1
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 +29 -0
- package/assets/stylesheets/{alchemy-widgets.scss → alchemy_widgets.scss} +169 -54
- package/bootstrap.js +101 -2
- package/controller/alchemy_widgets_controller.js +64 -0
- package/element/00-widget_base_element.js +105 -4
- package/element/05-widget_element.js +33 -21
- package/element/10-container_elements.js +27 -32
- package/element/11-alchemy_widgets_list_element.js +2 -2
- package/element/20-add_area_element.js +22 -22
- package/element/table_of_contents_element.js +144 -11
- package/element/widget_actionbar_element.js +92 -0
- package/element/widget_context_element.js +39 -23
- package/element/widget_toolbar_element.js +295 -50
- package/helper/widget_action.js +10 -10
- package/helper/widgets/00-widget.js +244 -27
- package/helper/widgets/01-container.js +29 -7
- package/helper/widgets/05-list.js +1 -1
- package/helper/widgets/alchemy_field_widget.js +112 -0
- package/helper/widgets/alchemy_form_widget.js +183 -0
- package/helper/widgets/alchemy_table_widget.js +71 -0
- package/helper/widgets/alchemy_tabs_widget.js +193 -0
- package/helper/widgets/hawkejs_template.js +60 -0
- package/helper/widgets/header.js +8 -10
- package/helper/widgets/html.js +52 -3
- package/helper/widgets/markdown.js +18 -13
- package/helper/widgets/partial.js +1 -3
- package/helper/widgets/sourcecode.js +5 -7
- package/helper/widgets/table_of_contents.js +2 -4
- package/helper/widgets/text.js +15 -15
- package/helper/widgets_helper.js +26 -0
- package/package.json +3 -2
- package/view/elements/table_of_contents.hwk +33 -9
- package/view/form/inputs/edit/widget.hwk +2 -2
- package/view/form/inputs/edit/widgets.hwk +2 -2
- package/view/widget/elements/al_widget_toolbar.hwk +49 -0
- package/view/widget/widget_config.hwk +7 -4
- package/assets/stylesheets/alchemy-widget-symbols.scss +0 -191
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Form Widget class
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} data
|
|
11
|
+
*/
|
|
12
|
+
const AlchemyForm = Function.inherits('Alchemy.Widget', 'AlchemyForm');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prepare the schema
|
|
16
|
+
*
|
|
17
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
18
|
+
* @since 0.1.12
|
|
19
|
+
* @version 0.1.12
|
|
20
|
+
*/
|
|
21
|
+
AlchemyForm.constitute(function prepareSchema() {
|
|
22
|
+
|
|
23
|
+
this.setAddChecker(function(widget_element) {
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Populate the widget
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
* @version 0.2.0
|
|
34
|
+
*/
|
|
35
|
+
AlchemyForm.setMethod(function populateWidget() {
|
|
36
|
+
|
|
37
|
+
let config = this.config,
|
|
38
|
+
form = this.createElement('al-form');
|
|
39
|
+
|
|
40
|
+
let col_el = this.createElement('al-widgets-column'),
|
|
41
|
+
col = col_el.instance;
|
|
42
|
+
|
|
43
|
+
col.parent_instance = this;
|
|
44
|
+
|
|
45
|
+
form.classList.add('al-widgets-container');
|
|
46
|
+
|
|
47
|
+
if (config.purpose) {
|
|
48
|
+
form.purpose = config.purpose;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (config.mode) {
|
|
52
|
+
form.mode = config.mode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this.config && this.config.widgets) {
|
|
56
|
+
let widgets = this.config.widgets.slice(0),
|
|
57
|
+
widget,
|
|
58
|
+
i;
|
|
59
|
+
|
|
60
|
+
for (i = 0; i < widgets.length; i++) {
|
|
61
|
+
widget = widgets[i];
|
|
62
|
+
|
|
63
|
+
if (widget.type == 'alchemy_field') {
|
|
64
|
+
widget = Object.assign({}, widget);
|
|
65
|
+
widget.config = Object.assign({}, widget.config);
|
|
66
|
+
widget.config.alchemy_form = form;
|
|
67
|
+
widgets[i] = widget;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
col.widget.value = widgets;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let record = this.element.getContextVariable('record');
|
|
75
|
+
|
|
76
|
+
if (record) {
|
|
77
|
+
form.document = record;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (config.model) {
|
|
81
|
+
form.model = config.model;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (config.view_type) {
|
|
85
|
+
form.view_type = config.view_type;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
form.append(col.widget);
|
|
89
|
+
|
|
90
|
+
this.element.append(form);
|
|
91
|
+
|
|
92
|
+
let violations = this.element.getContextVariable('form_violations');
|
|
93
|
+
|
|
94
|
+
if (violations) {
|
|
95
|
+
form.showError(violations);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the nested column
|
|
101
|
+
*
|
|
102
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
103
|
+
* @since 0.1.0
|
|
104
|
+
* @version 0.2.0
|
|
105
|
+
*/
|
|
106
|
+
AlchemyForm.setMethod(function getNestedColumn(widget) {
|
|
107
|
+
|
|
108
|
+
if (!widget) {
|
|
109
|
+
widget = this.widget;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!widget) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let col = widget.querySelector('al-form > al-widgets-column');
|
|
117
|
+
|
|
118
|
+
return col;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Start the editor
|
|
123
|
+
*
|
|
124
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
125
|
+
* @since 0.1.0
|
|
126
|
+
* @version 0.1.0
|
|
127
|
+
*/
|
|
128
|
+
AlchemyForm.setMethod(function _startEditor() {
|
|
129
|
+
|
|
130
|
+
let col = this.getNestedColumn();
|
|
131
|
+
|
|
132
|
+
if (!col) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
col.startEditor();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Stop the editor
|
|
141
|
+
*
|
|
142
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
143
|
+
* @since 0.1.0
|
|
144
|
+
* @version 0.1.0
|
|
145
|
+
*/
|
|
146
|
+
AlchemyForm.setMethod(function _stopEditor() {
|
|
147
|
+
|
|
148
|
+
let col = this.getNestedColumn();
|
|
149
|
+
|
|
150
|
+
if (!col) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
col.stopEditor();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get the config of this widget
|
|
159
|
+
*
|
|
160
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
161
|
+
* @since 0.1.0
|
|
162
|
+
* @version 0.1.0
|
|
163
|
+
*
|
|
164
|
+
* @return {Object}
|
|
165
|
+
*/
|
|
166
|
+
AlchemyForm.setMethod(function syncConfig() {
|
|
167
|
+
|
|
168
|
+
let config = this.config;
|
|
169
|
+
|
|
170
|
+
if (!config) {
|
|
171
|
+
config = this.config = {};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let col = this.getNestedColumn();
|
|
175
|
+
|
|
176
|
+
if (col) {
|
|
177
|
+
config.widgets = col.instance.syncConfig();
|
|
178
|
+
} else {
|
|
179
|
+
config.widgets = [];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return this.config;
|
|
183
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Table Widget class
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} data
|
|
11
|
+
*/
|
|
12
|
+
const AlchemyTable = Function.inherits('Alchemy.Widget', 'AlchemyTable');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prepare the schema
|
|
16
|
+
*
|
|
17
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
18
|
+
* @since 0.1.12
|
|
19
|
+
* @version 0.1.12
|
|
20
|
+
*/
|
|
21
|
+
AlchemyTable.constitute(function prepareSchema() {
|
|
22
|
+
|
|
23
|
+
this.setAddChecker(function(widget_element) {
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Populate the widget
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
* @version 0.2.0
|
|
34
|
+
*/
|
|
35
|
+
AlchemyTable.setMethod(function populateWidget() {
|
|
36
|
+
|
|
37
|
+
let table = this.createElement('al-table'),
|
|
38
|
+
config = this.config;
|
|
39
|
+
|
|
40
|
+
if (config.id) {
|
|
41
|
+
table.id = config.id;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Always enable the actions?
|
|
45
|
+
table.has_actions = true;
|
|
46
|
+
|
|
47
|
+
if (config.fieldset) {
|
|
48
|
+
table.fieldset = config.fieldset;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (config.page_size) {
|
|
52
|
+
table.page_size = config.page_size;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (config.show_filters) {
|
|
56
|
+
table.show_filters = config.show_filters;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (config.recordsource) {
|
|
60
|
+
table.recordsource = config.recordsource;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (config.use_url_pagination) {
|
|
64
|
+
table.use_url_pagination = config.use_url_pagination;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
table.purpose = config.purpose || 'view';
|
|
68
|
+
table.mode = config.mode || 'inline';
|
|
69
|
+
|
|
70
|
+
this.element.append(table);
|
|
71
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Widget Tabs class
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.2.0
|
|
8
|
+
* @version 0.2.0
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} data
|
|
11
|
+
*/
|
|
12
|
+
const Tabs = Function.inherits('Alchemy.Widget', 'AlchemyTabs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prepare the schema
|
|
16
|
+
*
|
|
17
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
18
|
+
* @since 0.2.0
|
|
19
|
+
* @version 0.2.0
|
|
20
|
+
*/
|
|
21
|
+
Tabs.constitute(function prepareSchema() {
|
|
22
|
+
|
|
23
|
+
let tab_entry = alchemy.createSchema();
|
|
24
|
+
|
|
25
|
+
tab_entry.addField('name', 'String', {
|
|
26
|
+
title : 'Tab Name',
|
|
27
|
+
description : 'Used as the Tab\'s ID',
|
|
28
|
+
widget_config_editable : true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
tab_entry.addField('title', 'String', {
|
|
32
|
+
title : 'Tab Title',
|
|
33
|
+
description : 'Used in the navigation menu',
|
|
34
|
+
widget_config_editable : true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
tab_entry.addField('icon', 'String', {
|
|
38
|
+
title : 'Tab Icon',
|
|
39
|
+
description : 'Optional icon to use in the navigation menu',
|
|
40
|
+
widget_config_editable : true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
tab_entry.addField('contents', 'Widgets', {
|
|
44
|
+
widget_config_editable : false,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.schema.addField('tabs', tab_entry, {
|
|
48
|
+
widget_config_editable : true,
|
|
49
|
+
array: true,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the config of this widget
|
|
55
|
+
*
|
|
56
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
57
|
+
* @since 0.2.0
|
|
58
|
+
* @version 0.2.0
|
|
59
|
+
*
|
|
60
|
+
* @return {Object}
|
|
61
|
+
*/
|
|
62
|
+
Tabs.setMethod(function syncConfig() {
|
|
63
|
+
|
|
64
|
+
const config = this.config || {},
|
|
65
|
+
tabs = config.tabs || [],
|
|
66
|
+
widgets = this.getSubWidgets();
|
|
67
|
+
|
|
68
|
+
for (let tab_config of tabs) {
|
|
69
|
+
|
|
70
|
+
if (!tab_config.name) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let widget = widgets[tab_config.name];
|
|
75
|
+
|
|
76
|
+
tab_config.contents = widget?.value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.config;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Populate the widget
|
|
85
|
+
*
|
|
86
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
87
|
+
* @since 0.2.0
|
|
88
|
+
* @version 0.2.0
|
|
89
|
+
*
|
|
90
|
+
* @param {HTMLElement} widget
|
|
91
|
+
*/
|
|
92
|
+
Tabs.setMethod(function populateWidget() {
|
|
93
|
+
|
|
94
|
+
const config = this.config || {},
|
|
95
|
+
tabs = config.tabs || [];
|
|
96
|
+
|
|
97
|
+
let wrapper = this.createElement('al-tab-context'),
|
|
98
|
+
tablist = this.createElement('al-tab-list');
|
|
99
|
+
|
|
100
|
+
wrapper.append(tablist);
|
|
101
|
+
|
|
102
|
+
for (let tab_config of tabs) {
|
|
103
|
+
|
|
104
|
+
if (!tab_config?.name) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let tab_button = this.createElement('al-tab-button');
|
|
109
|
+
tab_button.tab_name = tab_config.name;
|
|
110
|
+
tab_button.id = 'tab-' + tab_config.name;
|
|
111
|
+
|
|
112
|
+
if (tab_config.icon) {
|
|
113
|
+
let ico = this.createElement('al-icon');
|
|
114
|
+
ico.icon_name = tab_config.icon;
|
|
115
|
+
tab_button.append(ico);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let span = this.createElement('span');
|
|
119
|
+
span.textContent = tab_config.title;
|
|
120
|
+
tab_button.append(span);
|
|
121
|
+
|
|
122
|
+
tablist.append(tab_button);
|
|
123
|
+
|
|
124
|
+
let tab_content = this.createElement('al-tab-panel');
|
|
125
|
+
tab_content.tab_name = tab_config.name;
|
|
126
|
+
wrapper.append(tab_content);
|
|
127
|
+
|
|
128
|
+
let widgets = this.createElement('al-widgets');
|
|
129
|
+
widgets.value = tab_config.contents;
|
|
130
|
+
widgets.setAttribute('data-tab-name', tab_config.name);
|
|
131
|
+
|
|
132
|
+
tab_content.append(widgets);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Hawkejs.replaceChildren(this.widget, wrapper);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get all the sub widgets
|
|
140
|
+
*
|
|
141
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
142
|
+
* @since 0.2.0
|
|
143
|
+
* @version 0.2.0
|
|
144
|
+
*
|
|
145
|
+
* @return {Object}
|
|
146
|
+
*/
|
|
147
|
+
Tabs.setMethod(function getSubWidgets() {
|
|
148
|
+
|
|
149
|
+
let elements = this.widget.queryAllNotNested('al-widgets[data-tab-name]'),
|
|
150
|
+
result = {};
|
|
151
|
+
|
|
152
|
+
for (let element of elements) {
|
|
153
|
+
result[element.dataset.tabName] = element;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return result;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Start the editor
|
|
161
|
+
*
|
|
162
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
163
|
+
* @since 0.2.0
|
|
164
|
+
* @version 0.2.0
|
|
165
|
+
*/
|
|
166
|
+
Tabs.setMethod(function _startEditor() {
|
|
167
|
+
|
|
168
|
+
let sub_widgets = this.getSubWidgets();
|
|
169
|
+
|
|
170
|
+
for (let name in sub_widgets) {
|
|
171
|
+
let sub_widget = sub_widgets[name];
|
|
172
|
+
sub_widget.startEditor();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Stop the editor
|
|
178
|
+
*
|
|
179
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
180
|
+
* @since 0.2.0
|
|
181
|
+
* @version 0.2.0
|
|
182
|
+
*/
|
|
183
|
+
Tabs.setMethod(function _stopEditor() {
|
|
184
|
+
|
|
185
|
+
let sub_widgets = this.getSubWidgets();
|
|
186
|
+
|
|
187
|
+
for (let name in sub_widgets) {
|
|
188
|
+
let sub_widget = sub_widgets[name];
|
|
189
|
+
sub_widget.stopEditor();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.populateWidget();
|
|
193
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Widget Template class
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.2.1
|
|
8
|
+
* @version 0.2.1
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} data
|
|
11
|
+
*/
|
|
12
|
+
const Template = Function.inherits('Alchemy.Widget.Sourcecode', 'HawkejsTemplate');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Populate the widget
|
|
16
|
+
*
|
|
17
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
18
|
+
* @since 0.2.1
|
|
19
|
+
* @version 0.2.1
|
|
20
|
+
*
|
|
21
|
+
* @param {HTMLElement} widget
|
|
22
|
+
*/
|
|
23
|
+
Template.setMethod(async function populateWidget() {
|
|
24
|
+
|
|
25
|
+
let input = this.config.sourcecode;
|
|
26
|
+
|
|
27
|
+
if (input) {
|
|
28
|
+
input = input.trim();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Hawkejs.removeChildren(this.widget);
|
|
32
|
+
|
|
33
|
+
if (input) {
|
|
34
|
+
|
|
35
|
+
let hawkejs = this.hawkejs_renderer.hawkejs,
|
|
36
|
+
hash = Object.checksum(input),
|
|
37
|
+
name = 'interpret_' + hash,
|
|
38
|
+
fnc;
|
|
39
|
+
|
|
40
|
+
if (hawkejs.templates[name]) {
|
|
41
|
+
fnc = hawkejs.templates[name];
|
|
42
|
+
} else {
|
|
43
|
+
fnc = hawkejs.compile({
|
|
44
|
+
template_name : name,
|
|
45
|
+
template : input
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let variables = {};
|
|
50
|
+
let placeholder = this.hawkejs_renderer.addSubtemplate(fnc, {print: false}, variables);
|
|
51
|
+
|
|
52
|
+
// If the widget is already part of the DOM,
|
|
53
|
+
// it's being edited and we need to manually kickstart the renderer
|
|
54
|
+
if (Blast.isBrowser && document.body.contains(this.widget)) {
|
|
55
|
+
await placeholder.getContent();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.widget.append(placeholder);
|
|
59
|
+
}
|
|
60
|
+
});
|
package/helper/widgets/header.js
CHANGED
|
@@ -43,7 +43,7 @@ Header.constitute(function addActions() {
|
|
|
43
43
|
for (let level of levels) {
|
|
44
44
|
let level_action = this.createAction('make-level-' + level, 'Level ' + level);
|
|
45
45
|
|
|
46
|
-
level_action.setHandler(function setLevelAction(widget, handle,
|
|
46
|
+
level_action.setHandler(function setLevelAction(widget, handle, actionbar) {
|
|
47
47
|
|
|
48
48
|
let content = widget.querySelector(query);
|
|
49
49
|
|
|
@@ -54,8 +54,8 @@ Header.constitute(function addActions() {
|
|
|
54
54
|
widget.instance.config.level = level;
|
|
55
55
|
widget.instance.rerender();
|
|
56
56
|
|
|
57
|
-
// Rerender the
|
|
58
|
-
|
|
57
|
+
// Rerender the actionbar
|
|
58
|
+
actionbar.showWidgetActions(widget);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
level_action.setIcon({html: '<span class="aw-header-h">H</span><span class="aw-header-level">' + level + '</span>'});
|
|
@@ -78,18 +78,18 @@ Header.constitute(function addActions() {
|
|
|
78
78
|
*
|
|
79
79
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
80
80
|
* @since 0.1.0
|
|
81
|
-
* @version 0.1
|
|
81
|
+
* @version 0.2.1
|
|
82
82
|
*
|
|
83
83
|
* @return {Object}
|
|
84
84
|
*/
|
|
85
85
|
Header.setMethod(function syncConfig() {
|
|
86
86
|
|
|
87
|
-
let header = this.widget.
|
|
87
|
+
let header = this.widget.querySelector('h1, h2, h3, h4, h5'),
|
|
88
88
|
content = '',
|
|
89
89
|
level = 1;
|
|
90
90
|
|
|
91
91
|
if (header) {
|
|
92
|
-
content = header.
|
|
92
|
+
content = header.textContent;
|
|
93
93
|
level = parseInt(header.tagName[1]);
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -104,7 +104,7 @@ Header.setMethod(function syncConfig() {
|
|
|
104
104
|
*
|
|
105
105
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
106
106
|
* @since 0.1.0
|
|
107
|
-
* @version 0.1
|
|
107
|
+
* @version 0.2.1
|
|
108
108
|
*
|
|
109
109
|
* @param {HTMLElement} widget
|
|
110
110
|
*/
|
|
@@ -113,11 +113,9 @@ Header.setMethod(function populateWidget() {
|
|
|
113
113
|
let level = this.config.level || 1;
|
|
114
114
|
|
|
115
115
|
let header = this.createElement('h' + level);
|
|
116
|
-
header.
|
|
116
|
+
header.textContent = this.config.content || 'header level ' + level;
|
|
117
117
|
|
|
118
118
|
this.widget.append(header);
|
|
119
|
-
|
|
120
|
-
populateWidget.super.call(this);
|
|
121
119
|
});
|
|
122
120
|
|
|
123
121
|
/**
|
package/helper/widgets/html.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
/**
|
|
2
3
|
* The Widget HTML class
|
|
3
4
|
*
|
|
@@ -23,19 +24,67 @@ Html.constitute(function prepareSchema() {
|
|
|
23
24
|
this.schema.addField('html', 'Html');
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Start the editor
|
|
29
|
+
*
|
|
30
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
31
|
+
* @since 0.2.1
|
|
32
|
+
* @version 0.2.1
|
|
33
|
+
*/
|
|
34
|
+
Html.setMethod(async function _startEditor() {
|
|
35
|
+
|
|
36
|
+
if (this.ckeditor) {
|
|
37
|
+
this.ckeditor.destroy();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let ckeditor_path = hawkejs.scene.exposed.ckeditor_path;
|
|
41
|
+
|
|
42
|
+
if (!ckeditor_path) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await hawkejs.require(ckeditor_path);
|
|
47
|
+
|
|
48
|
+
const options = {
|
|
49
|
+
toolbar: hawkejs.scene.exposed.ckeditor_toolbar,
|
|
50
|
+
updateSourceElementOnDestroy: true,
|
|
51
|
+
removePlugins: ['Markdown'],
|
|
52
|
+
simpleUpload: {
|
|
53
|
+
uploadUrl: alchemy.routeUrl('AlchemyWidgets#uploadImage'),
|
|
54
|
+
withCredentials: true,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let editor = await InlineEditor.create(this.widget, options);
|
|
59
|
+
|
|
60
|
+
this.ckeditor = editor;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Stop the editor
|
|
65
|
+
*
|
|
66
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
67
|
+
* @since 0.2.1
|
|
68
|
+
* @version 0.2.1
|
|
69
|
+
*/
|
|
70
|
+
Html.setMethod(function _stopEditor() {
|
|
71
|
+
if (this.ckeditor) {
|
|
72
|
+
this.ckeditor.destroy();
|
|
73
|
+
this.ckeditor = null;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
26
77
|
/**
|
|
27
78
|
* Populate the widget
|
|
28
79
|
*
|
|
29
80
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
30
81
|
* @since 0.1.0
|
|
31
|
-
* @version 0.1
|
|
82
|
+
* @version 0.2.1
|
|
32
83
|
*
|
|
33
84
|
* @param {HTMLElement} widget
|
|
34
85
|
*/
|
|
35
86
|
Html.setMethod(function populateWidget() {
|
|
36
87
|
this.widget.innerHTML = this.config.html;
|
|
37
|
-
|
|
38
|
-
populateWidget.super.call(this);
|
|
39
88
|
});
|
|
40
89
|
|
|
41
90
|
/**
|
|
@@ -28,14 +28,12 @@ Markdown.constitute(function prepareSchema() {
|
|
|
28
28
|
*
|
|
29
29
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
30
30
|
* @since 0.1.0
|
|
31
|
-
* @version 0.1
|
|
31
|
+
* @version 0.2.1
|
|
32
32
|
*
|
|
33
33
|
* @param {HTMLElement} widget
|
|
34
34
|
*/
|
|
35
35
|
Markdown.setMethod(function populateWidget() {
|
|
36
36
|
|
|
37
|
-
populateWidget.super.call(this);
|
|
38
|
-
|
|
39
37
|
let source = this.config.markdown || '';
|
|
40
38
|
|
|
41
39
|
if (!source) {
|
|
@@ -54,17 +52,21 @@ Markdown.setMethod(function populateWidget() {
|
|
|
54
52
|
*
|
|
55
53
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
56
54
|
* @since 0.1.0
|
|
57
|
-
* @version 0.
|
|
55
|
+
* @version 0.2.0
|
|
58
56
|
*/
|
|
59
|
-
Markdown.setMethod(function _startEditor() {
|
|
57
|
+
Markdown.setMethod(async function _startEditor() {
|
|
60
58
|
|
|
61
59
|
Hawkejs.removeChildren(this.widget);
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//area.value = this.config.markdown || '';
|
|
61
|
+
hawkejs.scene.enableStyle('https://unpkg.com/easymde/dist/easymde.min.css');
|
|
62
|
+
await hawkejs.require('https://unpkg.com/easymde/dist/easymde.min.js');
|
|
66
63
|
|
|
67
|
-
this.
|
|
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;
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -77,6 +79,7 @@ Markdown.setMethod(function _startEditor() {
|
|
|
77
79
|
Markdown.setMethod(function _stopEditor() {
|
|
78
80
|
|
|
79
81
|
Hawkejs.removeChildren(this.widget);
|
|
82
|
+
this.easy_mde = null;
|
|
80
83
|
|
|
81
84
|
this.populateWidget();
|
|
82
85
|
});
|
|
@@ -86,17 +89,19 @@ Markdown.setMethod(function _stopEditor() {
|
|
|
86
89
|
*
|
|
87
90
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
88
91
|
* @since 0.1.0
|
|
89
|
-
* @version 0.
|
|
92
|
+
* @version 0.2.0
|
|
90
93
|
*
|
|
91
94
|
* @return {Object}
|
|
92
95
|
*/
|
|
93
96
|
Markdown.setMethod(function syncConfig() {
|
|
94
97
|
|
|
95
|
-
let
|
|
98
|
+
let value = '';
|
|
96
99
|
|
|
97
|
-
if (
|
|
98
|
-
|
|
100
|
+
if (this.easy_mde) {
|
|
101
|
+
value = this.easy_mde.value();
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
this.config.markdown = value;
|
|
105
|
+
|
|
101
106
|
return this.config;
|
|
102
107
|
});
|