alchemy-widget 0.1.5 → 0.2.0
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 +426 -0
- package/bootstrap.js +6 -0
- package/controller/alchemy_widgets_controller.js +85 -9
- package/element/00-widget_base_element.js +154 -6
- package/element/05-widget_element.js +112 -19
- package/element/10-container_elements.js +15 -15
- package/element/11-alchemy_widgets_list_element.js +2 -2
- package/element/20-add_area_element.js +23 -23
- package/element/table_of_contents_element.js +104 -8
- package/element/widget_actionbar_element.js +92 -0
- package/element/widget_context_element.js +39 -23
- package/element/widget_toolbar_element.js +300 -38
- package/helper/widget_action.js +19 -18
- package/helper/widgets/00-widget.js +160 -37
- package/helper/widgets/01-container.js +12 -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 +195 -0
- package/helper/widgets/header.js +4 -4
- package/helper/widgets/markdown.js +17 -10
- package/helper/widgets/partial.js +215 -0
- package/helper/widgets/sourcecode.js +4 -4
- package/helper/widgets/table_of_contents.js +2 -2
- package/helper/widgets/text.js +14 -4
- package/helper/widgets_helper.js +26 -0
- package/package.json +4 -3
- package/view/elements/table_of_contents.hwk +23 -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
- package/assets/stylesheets/alchemy-widgets.scss +0 -258
|
@@ -16,6 +16,15 @@ const TableOfContents = Function.inherits('Alchemy.Element.App', 'TableOfContent
|
|
|
16
16
|
*/
|
|
17
17
|
TableOfContents.setTemplateFile('elements/table_of_contents');
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Set the actual tag name
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.2.0
|
|
24
|
+
* @version 0.2.0
|
|
25
|
+
*/
|
|
26
|
+
TableOfContents.setTagName('AL-TOC');
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* Set the content
|
|
21
30
|
*
|
|
@@ -84,7 +93,7 @@ TableOfContents.setAttribute('intersection-class');
|
|
|
84
93
|
*
|
|
85
94
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
86
95
|
* @since 0.1.2
|
|
87
|
-
* @version 0.
|
|
96
|
+
* @version 0.2.0
|
|
88
97
|
*/
|
|
89
98
|
TableOfContents.setProperty(function entries() {
|
|
90
99
|
|
|
@@ -105,7 +114,10 @@ TableOfContents.setProperty(function entries() {
|
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
if (wrapper) {
|
|
108
|
-
|
|
117
|
+
|
|
118
|
+
let current_level = null,
|
|
119
|
+
last_entry,
|
|
120
|
+
elements = wrapper.querySelectorAll(this.elements_selector || 'h1,h2'),
|
|
109
121
|
element,
|
|
110
122
|
title,
|
|
111
123
|
i;
|
|
@@ -124,7 +136,9 @@ TableOfContents.setProperty(function entries() {
|
|
|
124
136
|
}
|
|
125
137
|
}
|
|
126
138
|
|
|
127
|
-
let title_element
|
|
139
|
+
let title_element,
|
|
140
|
+
starts_level,
|
|
141
|
+
ends_level;
|
|
128
142
|
|
|
129
143
|
if (this.title_selector) {
|
|
130
144
|
title_element = element.querySelector(this.title_selector);
|
|
@@ -134,6 +148,25 @@ TableOfContents.setProperty(function entries() {
|
|
|
134
148
|
title_element = element;
|
|
135
149
|
}
|
|
136
150
|
|
|
151
|
+
if (element.nodeName[0] == 'H' && isFinite(element.nodeName[1])) {
|
|
152
|
+
let heading_level = +element.nodeName[1];
|
|
153
|
+
|
|
154
|
+
if (current_level == null) {
|
|
155
|
+
current_level = heading_level;
|
|
156
|
+
} else if (heading_level > current_level) {
|
|
157
|
+
current_level++;
|
|
158
|
+
starts_level = true;
|
|
159
|
+
} else if (heading_level == current_level && last_entry) {
|
|
160
|
+
last_entry.starts_level = false;
|
|
161
|
+
} else if (heading_level < current_level) {
|
|
162
|
+
current_level--;
|
|
163
|
+
|
|
164
|
+
if (last_entry) {
|
|
165
|
+
last_entry.ends_level = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
137
170
|
title = (title_element.toc_title || title_element.textContent || '').trim();
|
|
138
171
|
|
|
139
172
|
title = title.truncate(30);
|
|
@@ -143,11 +176,74 @@ TableOfContents.setProperty(function entries() {
|
|
|
143
176
|
continue;
|
|
144
177
|
}
|
|
145
178
|
|
|
146
|
-
|
|
147
|
-
id
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
179
|
+
last_entry = {
|
|
180
|
+
id : element.id,
|
|
181
|
+
level : current_level,
|
|
182
|
+
title : title,
|
|
183
|
+
element : element,
|
|
184
|
+
starts_level : starts_level,
|
|
185
|
+
ends_level : ends_level,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
result.push(last_entry);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let ended_level = false,
|
|
192
|
+
entries = result,
|
|
193
|
+
current_branch,
|
|
194
|
+
current_nodes = [];
|
|
195
|
+
|
|
196
|
+
result = current_nodes;
|
|
197
|
+
last_entry = null;
|
|
198
|
+
|
|
199
|
+
for (let entry of entries) {
|
|
200
|
+
|
|
201
|
+
if (ended_level) {
|
|
202
|
+
|
|
203
|
+
while (entry.level >= current_branch.level) {
|
|
204
|
+
current_branch = current_branch.parent;
|
|
205
|
+
current_nodes = current_branch?.children || result;
|
|
206
|
+
|
|
207
|
+
if (!current_branch) {
|
|
208
|
+
current_branch = result[result.length - 1];
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
ended_level = false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!current_branch) {
|
|
217
|
+
current_branch = entry;
|
|
218
|
+
} else {
|
|
219
|
+
entry.parent = current_branch;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (entry.starts_level) {
|
|
223
|
+
|
|
224
|
+
current_branch = last_entry;
|
|
225
|
+
|
|
226
|
+
if (!current_branch.children) {
|
|
227
|
+
current_branch.children = [];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
current_nodes = current_branch.children;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
current_nodes.push(entry);
|
|
234
|
+
|
|
235
|
+
if (entry.ends_level) {
|
|
236
|
+
ended_level = true;
|
|
237
|
+
current_branch = entry.parent;
|
|
238
|
+
current_nodes = current_branch.children || result;
|
|
239
|
+
|
|
240
|
+
if (!current_branch) {
|
|
241
|
+
current_branch = result[result.length - 1];
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
last_entry = entry;
|
|
151
247
|
}
|
|
152
248
|
}
|
|
153
249
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-widget-actionbar element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
*/
|
|
8
|
+
let Actionbar = Function.inherits('Alchemy.Element.Widget.Base', function WidgetActionbar() {
|
|
9
|
+
WidgetActionbar.super.call(this);
|
|
10
|
+
this.hidden = true;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Show the actions for the given widget
|
|
15
|
+
*
|
|
16
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
* @version 0.2.0
|
|
19
|
+
*
|
|
20
|
+
* @param {HTMLElement} widget
|
|
21
|
+
*/
|
|
22
|
+
Actionbar.setMethod(async function showWidgetActions(widget) {
|
|
23
|
+
|
|
24
|
+
if (!widget || !widget.instance) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const that = this;
|
|
29
|
+
|
|
30
|
+
let actions = await widget.instance.getActionbarActions();
|
|
31
|
+
|
|
32
|
+
// Clear all the old buttons
|
|
33
|
+
Hawkejs.removeChildren(this);
|
|
34
|
+
|
|
35
|
+
for (let action of actions) {
|
|
36
|
+
|
|
37
|
+
let button = this.createElement('button');
|
|
38
|
+
button.classList.add('aw-actionbar-button');
|
|
39
|
+
|
|
40
|
+
let content = action.getButtonContent();
|
|
41
|
+
|
|
42
|
+
if (!content) {
|
|
43
|
+
content = action.title;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof content == 'string') {
|
|
47
|
+
button.innerText = content;
|
|
48
|
+
} else if (content) {
|
|
49
|
+
if (Array.isArray(content)) {
|
|
50
|
+
for (let entry of content) {
|
|
51
|
+
button.append(entry);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
button.append(content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
button.setAttribute('title', action.title);
|
|
59
|
+
|
|
60
|
+
let is_selected = action.isAlreadySelected(widget);
|
|
61
|
+
|
|
62
|
+
if (is_selected) {
|
|
63
|
+
button.classList.add('aw-button-selected');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
button.addEventListener('click', function onClick(e) {
|
|
67
|
+
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
|
|
70
|
+
action.applyOnWidget(widget, that);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
this.append(button);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Close the actionbar
|
|
79
|
+
*
|
|
80
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
* @version 0.1.0
|
|
83
|
+
*/
|
|
84
|
+
Actionbar.setMethod(function close() {
|
|
85
|
+
this.hidden = true;
|
|
86
|
+
|
|
87
|
+
if (this.context_element && this.context_element.active_widget) {
|
|
88
|
+
this.context_element.active_widget.selectWidget();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.context_element = null;
|
|
92
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The al-widget-context element
|
|
3
3
|
*
|
|
4
4
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
5
|
* @since 0.1.0
|
|
6
|
-
* @version 0.
|
|
6
|
+
* @version 0.2.0
|
|
7
7
|
*/
|
|
8
|
-
let Awc = Function.inherits('Alchemy.Element.Widget.Base', function
|
|
9
|
-
|
|
8
|
+
let Awc = Function.inherits('Alchemy.Element.Widget.Base', function WidgetContext() {
|
|
9
|
+
WidgetContext.super.call(this);
|
|
10
10
|
|
|
11
|
-
this.innerHTML = `<button class="menu-button widget-button" title="Menu"><
|
|
11
|
+
this.innerHTML = `<button class="menu-button widget-button" title="Menu"><al-icon icon-name="grid"></al-icon></button>`;
|
|
12
12
|
this.hidden = true;
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -45,48 +45,64 @@ Awc.setMethod(function moveToWidget(widget) {
|
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* The given widget has been unselected
|
|
49
49
|
*
|
|
50
50
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
51
51
|
* @since 0.1.0
|
|
52
|
-
* @version 0.
|
|
52
|
+
* @version 0.2.0
|
|
53
53
|
*/
|
|
54
54
|
Awc.setMethod(function unselectedWidget(widget) {
|
|
55
55
|
|
|
56
56
|
this.hidden = true;
|
|
57
57
|
this.active_widget = null;
|
|
58
58
|
|
|
59
|
-
if (this.
|
|
60
|
-
this.
|
|
59
|
+
if (this.actionbar) {
|
|
60
|
+
this.actionbar.hidden = true;
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Force unselecting any widget
|
|
66
|
+
*
|
|
67
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
68
|
+
* @since 0.2.0
|
|
69
|
+
* @version 0.2.0
|
|
70
|
+
*/
|
|
71
|
+
Awc.setMethod(function forceUnselection() {
|
|
72
|
+
|
|
73
|
+
if (this.active_widget) {
|
|
74
|
+
this.active_widget.unselectWidget();
|
|
75
|
+
} else {
|
|
76
|
+
this.unselectedWidget();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Show the actionbar
|
|
66
82
|
*
|
|
67
83
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
68
84
|
* @since 0.1.0
|
|
69
|
-
* @version 0.
|
|
85
|
+
* @version 0.2.0
|
|
70
86
|
*/
|
|
71
|
-
Awc.setMethod(function
|
|
87
|
+
Awc.setMethod(function toggleActionbar() {
|
|
72
88
|
|
|
73
89
|
if (!this.active_widget) {
|
|
74
90
|
return;
|
|
75
91
|
}
|
|
76
92
|
|
|
77
|
-
if (!this.
|
|
78
|
-
this.
|
|
79
|
-
this.append(this.
|
|
93
|
+
if (!this.actionbar) {
|
|
94
|
+
this.actionbar = document.createElement('al-widget-actionbar');
|
|
95
|
+
this.append(this.actionbar);
|
|
80
96
|
}
|
|
81
97
|
|
|
82
|
-
if (this.
|
|
83
|
-
this.
|
|
98
|
+
if (this.actionbar.context_element == this && !this.actionbar.hidden) {
|
|
99
|
+
this.actionbar.close();
|
|
84
100
|
return;
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
103
|
+
this.actionbar.hidden = false;
|
|
104
|
+
this.actionbar.context_element = this;
|
|
105
|
+
this.actionbar.showWidgetActions(this.active_widget);
|
|
90
106
|
});
|
|
91
107
|
|
|
92
108
|
/**
|
|
@@ -94,7 +110,7 @@ Awc.setMethod(function toggleToolbar() {
|
|
|
94
110
|
*
|
|
95
111
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
96
112
|
* @since 0.1.0
|
|
97
|
-
* @version 0.
|
|
113
|
+
* @version 0.2.0
|
|
98
114
|
*/
|
|
99
115
|
Awc.setMethod(function introduced() {
|
|
100
116
|
|
|
@@ -110,7 +126,7 @@ Awc.setMethod(function introduced() {
|
|
|
110
126
|
return that.exitingWidget();
|
|
111
127
|
}
|
|
112
128
|
|
|
113
|
-
that.
|
|
129
|
+
that.toggleActionbar();
|
|
114
130
|
});
|
|
115
131
|
|
|
116
132
|
document.addEventListener('click', e => {
|
|
@@ -129,7 +145,7 @@ Awc.setMethod(function introduced() {
|
|
|
129
145
|
return;
|
|
130
146
|
}
|
|
131
147
|
|
|
132
|
-
return this.
|
|
148
|
+
return this.forceUnselection();
|
|
133
149
|
});
|
|
134
150
|
|
|
135
151
|
let update_scroll = () => {
|