@innovastudio/contentbuilder 1.5.224 → 1.5.225
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/package.json +1 -1
- package/public/contentbuilder/contentbuilder.css +112 -7
- package/public/contentbuilder/contentbuilder.esm.js +477 -56
- package/public/contentbuilder/contentbuilder.min.js +5 -5
- package/public/contentbuilder/lang/en.js +3 -0
- package/public/contentbuilder/lang/fr.js +3 -0
- package/readme.txt +7 -1
|
@@ -9,6 +9,17 @@ function snippetInCategory(item, cat) {
|
|
|
9
9
|
|
|
10
10
|
// Snippets browser — renders directly in the editor's [data-cb-ui] modal (no iframe).
|
|
11
11
|
// Data is already loaded in the parent window by loadSnippets() as opts.snippetJSON.
|
|
12
|
+
// How many of the first categories show as tabs at this dialog width. The rest
|
|
13
|
+
// are reached from the All Categories list, which appears only when some are left.
|
|
14
|
+
const tabsForWidth = width => {
|
|
15
|
+
if (width > 1212) return 7;
|
|
16
|
+
if (width > 1070) return 6;
|
|
17
|
+
if (width > 940) return 5;
|
|
18
|
+
if (width > 700) return 4;
|
|
19
|
+
if (width > 555) return 3;
|
|
20
|
+
if (width > 415) return 2;
|
|
21
|
+
return 1;
|
|
22
|
+
};
|
|
12
23
|
class Snippets {
|
|
13
24
|
constructor(builder) {
|
|
14
25
|
this.builder = builder;
|
|
@@ -49,11 +60,137 @@ class Snippets {
|
|
|
49
60
|
const gridEl = modal.querySelector('.snippet-grid');
|
|
50
61
|
if (!tabsEl || !gridEl) return;
|
|
51
62
|
const cats = builder.opts.snippetCategories; // [[id,'Label'], …]
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
const content = modal.querySelector('.is-modal-content');
|
|
64
|
+
const allBtn = modal.querySelector('.snippet-cats-all');
|
|
65
|
+
const menu = modal.querySelector('.snippet-cats-menu');
|
|
66
|
+
const hasCat = (list, catId) => list.some(([id]) => id + '' === catId);
|
|
67
|
+
let current = builder.opts.defaultSnippetCategory + '';
|
|
68
|
+
let extra = null; // a category outside the row, shown as one more tab once picked
|
|
69
|
+
let tabCount = tabsForWidth(content.clientWidth);
|
|
70
|
+
let tabsScroll = null;
|
|
71
|
+
const renderTabs = () => {
|
|
72
|
+
const row = cats.slice(0, tabCount);
|
|
73
|
+
if (!hasCat(row, current)) extra = cats.find(([id]) => id + '' === current) || null;else if (extra && hasCat(row, extra[0] + '')) extra = null;
|
|
74
|
+
tabsEl.innerHTML = (extra ? row.concat([extra]) : row).map(([id, label]) => {
|
|
75
|
+
const on = id + '' === current;
|
|
76
|
+
return `<button type="button" role="tab" data-tab="${id}" aria-selected="${on ? 'true' : 'false'}" tabindex="${on ? '0' : '-1'}">${util.out(label)}</button>`;
|
|
77
|
+
}).join('');
|
|
78
|
+
|
|
79
|
+
// Shared, accessible tab kit (arrow keys, roving tabindex).
|
|
80
|
+
this.dom.accessibleTabs(tabsEl, tabId => {
|
|
81
|
+
current = tabId;
|
|
82
|
+
renderGrid(tabId);
|
|
83
|
+
});
|
|
84
|
+
allBtn.hidden = cats.length <= tabCount;
|
|
85
|
+
if (tabsScroll) tabsScroll.update();
|
|
86
|
+
};
|
|
87
|
+
const closeMenu = () => {
|
|
88
|
+
menu.hidden = true;
|
|
89
|
+
allBtn.setAttribute('aria-expanded', 'false');
|
|
90
|
+
};
|
|
91
|
+
const openMenu = () => {
|
|
92
|
+
menu.innerHTML = cats.map(([id, label]) => {
|
|
93
|
+
const on = id + '' === current;
|
|
94
|
+
return `<button type="button" data-cat="${id}"${on ? ' aria-current="true"' : ''}>${util.out(label)}</button>`;
|
|
95
|
+
}).join('');
|
|
96
|
+
menu.hidden = false;
|
|
97
|
+
allBtn.setAttribute('aria-expanded', 'true');
|
|
98
|
+
const box = content.getBoundingClientRect();
|
|
99
|
+
const btn = allBtn.getBoundingClientRect();
|
|
100
|
+
const top = btn.bottom - box.top + 4;
|
|
101
|
+
menu.style.top = top + 'px';
|
|
102
|
+
menu.style.maxHeight = box.height - top - 12 + 'px';
|
|
103
|
+
menu.style.left = Math.max(12, Math.min(btn.left - box.left, box.width - menu.offsetWidth - 12)) + 'px';
|
|
104
|
+
builder.toolbarKeys.openPanel(menu, {
|
|
105
|
+
label: util.out('All Categories'),
|
|
106
|
+
close: closeMenu
|
|
107
|
+
});
|
|
108
|
+
menu._opener = allBtn;
|
|
109
|
+
const selected = menu.querySelector('[aria-current]');
|
|
110
|
+
if (selected) selected.focus({
|
|
111
|
+
preventScroll: true
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// render() runs on every open: drop the previous open's listeners.
|
|
116
|
+
if (modal._snippetCatsCleanup) modal._snippetCatsCleanup();
|
|
117
|
+
const listeners = new AbortController();
|
|
118
|
+
const resize = new ResizeObserver(() => {
|
|
119
|
+
const count = tabsForWidth(content.clientWidth);
|
|
120
|
+
if (count === tabCount) return;
|
|
121
|
+
tabCount = count;
|
|
122
|
+
closeMenu();
|
|
123
|
+
const hadFocus = tabsEl.contains(document.activeElement);
|
|
124
|
+
renderTabs();
|
|
125
|
+
if (hadFocus) tabsEl.querySelector('[aria-selected="true"]').focus({
|
|
126
|
+
preventScroll: true
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
resize.observe(content);
|
|
130
|
+
modal._snippetCatsCleanup = () => {
|
|
131
|
+
listeners.abort();
|
|
132
|
+
resize.disconnect();
|
|
133
|
+
};
|
|
134
|
+
allBtn.addEventListener('click', () => {
|
|
135
|
+
if (menu.hidden) openMenu();else closeMenu();
|
|
136
|
+
}, {
|
|
137
|
+
signal: listeners.signal
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Keep Tab inside the dialog. The stops change with the category, so they
|
|
141
|
+
// are read on each press; the ones recorded when the dialog opened are stale.
|
|
142
|
+
modal.addEventListener('keydown', e => {
|
|
143
|
+
if (e.key !== 'Tab' || !menu.hidden) return;
|
|
144
|
+
e.stopPropagation();
|
|
145
|
+
const stops = Array.from(modal.querySelectorAll('button, [tabindex]')).filter(el => el.tabIndex === 0 && el.offsetParent !== null);
|
|
146
|
+
const i = stops.indexOf(document.activeElement);
|
|
147
|
+
let to = null;
|
|
148
|
+
if (e.shiftKey && i <= 0) to = stops[stops.length - 1];else if (!e.shiftKey && i === stops.length - 1) to = stops[0];
|
|
149
|
+
if (to) {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
to.focus();
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
capture: true,
|
|
155
|
+
signal: listeners.signal
|
|
156
|
+
});
|
|
157
|
+
allBtn.addEventListener('keydown', e => {
|
|
158
|
+
if (e.key !== 'ArrowDown' || !menu.hidden) return;
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
openMenu();
|
|
161
|
+
}, {
|
|
162
|
+
signal: listeners.signal
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// The list reads down its columns, so Up and Down step through it. Left,
|
|
166
|
+
// Right, Home, End, Tab and Escape come from the shared panel keys.
|
|
167
|
+
menu.addEventListener('keydown', e => {
|
|
168
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
const items = Array.from(menu.querySelectorAll('[data-cat]'));
|
|
171
|
+
const step = e.key === 'ArrowDown' ? 1 : -1;
|
|
172
|
+
items[(items.indexOf(document.activeElement) + step + items.length) % items.length].focus();
|
|
173
|
+
}, {
|
|
174
|
+
signal: listeners.signal
|
|
175
|
+
});
|
|
176
|
+
menu.addEventListener('click', e => {
|
|
177
|
+
const item = e.target.closest('[data-cat]');
|
|
178
|
+
if (!item) return;
|
|
179
|
+
current = item.getAttribute('data-cat');
|
|
180
|
+
closeMenu();
|
|
181
|
+
renderTabs();
|
|
182
|
+
renderGrid(current);
|
|
183
|
+
tabsEl.querySelector('[aria-selected="true"]').focus({
|
|
184
|
+
preventScroll: true
|
|
185
|
+
});
|
|
186
|
+
}, {
|
|
187
|
+
signal: listeners.signal
|
|
188
|
+
});
|
|
189
|
+
modal.addEventListener('click', e => {
|
|
190
|
+
if (!menu.hidden && !menu.contains(e.target) && !allBtn.contains(e.target)) closeMenu();
|
|
191
|
+
}, {
|
|
192
|
+
signal: listeners.signal
|
|
193
|
+
});
|
|
57
194
|
const renderGrid = catId => {
|
|
58
195
|
catId = catId + '';
|
|
59
196
|
gridEl.innerHTML = '';
|
|
@@ -77,11 +214,10 @@ class Snippets {
|
|
|
77
214
|
gridEl.appendChild(frag);
|
|
78
215
|
gridEl.scrollTop = 0;
|
|
79
216
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.dom.
|
|
83
|
-
|
|
84
|
-
renderGrid(defaultCat);
|
|
217
|
+
closeMenu();
|
|
218
|
+
renderTabs();
|
|
219
|
+
tabsScroll = this.dom.scrollableTabs(modal.querySelector('.cb-tabs-scroller'));
|
|
220
|
+
renderGrid(current);
|
|
85
221
|
}
|
|
86
222
|
addSnippet(snippetid) {
|
|
87
223
|
const builder = this.builder;
|
|
@@ -7692,6 +7828,7 @@ class Util {
|
|
|
7692
7828
|
selection.removeAllRanges();
|
|
7693
7829
|
selection.addRange(range);
|
|
7694
7830
|
element.click();
|
|
7831
|
+
if (this.isEmbed(element)) this.repositionToolsUntilSettled(element);
|
|
7695
7832
|
}
|
|
7696
7833
|
} catch (e) {
|
|
7697
7834
|
// Do Nothing
|
|
@@ -7779,6 +7916,7 @@ class Util {
|
|
|
7779
7916
|
selection.removeAllRanges();
|
|
7780
7917
|
selection.addRange(range);
|
|
7781
7918
|
element.click();
|
|
7919
|
+
if (this.isEmbed(element)) this.repositionToolsUntilSettled(element);
|
|
7782
7920
|
}
|
|
7783
7921
|
} catch (e) {
|
|
7784
7922
|
// Do Nothing
|
|
@@ -7831,48 +7969,9 @@ class Util {
|
|
|
7831
7969
|
clearInterval(checkLoad);
|
|
7832
7970
|
}
|
|
7833
7971
|
}, 30);
|
|
7834
|
-
} else if (
|
|
7835
|
-
// A plugin/module or media embed (map / YouTube / video) renders
|
|
7836
|
-
// and lays out asynchronously AFTER this insert returns: the
|
|
7837
|
-
// plugin fills/replaces the frame (DOM change), a <video>/iframe
|
|
7838
|
-
// takes its size (resize), siblings reflow. The tool positioned
|
|
7839
|
-
// now is stale, and the plugin may REPLACE the inserted node so
|
|
7840
|
-
// anything tied to `newelement` breaks. Instead of guessing a
|
|
7841
|
-
// delay, react to the actual layout events on the PERSISTENT
|
|
7842
|
-
// container and reposition via the live activeElement until they
|
|
7843
|
-
// settle (debounced), then stop.
|
|
7972
|
+
} else if (this.isEmbed(newelement)) {
|
|
7844
7973
|
newelement.click();
|
|
7845
|
-
|
|
7846
|
-
const _cwin = _cont && _cont.ownerDocument.defaultView || this.builder.win || window;
|
|
7847
|
-
if (_cont && (_cwin.ResizeObserver || _cwin.MutationObserver)) {
|
|
7848
|
-
let _ro, _mo, _quiet;
|
|
7849
|
-
const _stop = () => {
|
|
7850
|
-
if (_ro) _ro.disconnect();
|
|
7851
|
-
if (_mo) _mo.disconnect();
|
|
7852
|
-
clearTimeout(_quiet);
|
|
7853
|
-
};
|
|
7854
|
-
const _bump = () => {
|
|
7855
|
-
if (this.builder.activeElement && this.builder.elmTool && this.builder.elmTool.repositionElementTool) {
|
|
7856
|
-
this.builder.elmTool.repositionElementTool();
|
|
7857
|
-
}
|
|
7858
|
-
clearTimeout(_quiet);
|
|
7859
|
-
_quiet = setTimeout(_stop, 300); // settled: 300ms with no further layout events
|
|
7860
|
-
};
|
|
7861
|
-
|
|
7862
|
-
if (_cwin.ResizeObserver) {
|
|
7863
|
-
_ro = new _cwin.ResizeObserver(_bump);
|
|
7864
|
-
_ro.observe(_cont);
|
|
7865
|
-
}
|
|
7866
|
-
if (_cwin.MutationObserver) {
|
|
7867
|
-
_mo = new _cwin.MutationObserver(_bump);
|
|
7868
|
-
_mo.observe(_cont, {
|
|
7869
|
-
childList: true,
|
|
7870
|
-
subtree: true
|
|
7871
|
-
});
|
|
7872
|
-
}
|
|
7873
|
-
_bump(); // initial position + arm the settle timer
|
|
7874
|
-
setTimeout(_stop, 3000); // hard safety cap
|
|
7875
|
-
}
|
|
7974
|
+
this.repositionToolsUntilSettled(newelement);
|
|
7876
7975
|
} else {
|
|
7877
7976
|
// newelement.click();
|
|
7878
7977
|
|
|
@@ -7925,6 +8024,50 @@ class Util {
|
|
|
7925
8024
|
}, 400);
|
|
7926
8025
|
}
|
|
7927
8026
|
|
|
8027
|
+
// A plugin/module or media embed (map / YouTube / video).
|
|
8028
|
+
isEmbed(element) {
|
|
8029
|
+
return element.hasAttribute('data-cb-type') || element.tagName.toLowerCase() === 'video' || !!element.querySelector('iframe, video, [data-cb-type]');
|
|
8030
|
+
}
|
|
8031
|
+
|
|
8032
|
+
// An embed renders and lays out asynchronously AFTER its insert returns: the
|
|
8033
|
+
// plugin fills/replaces the frame (DOM change), a <video>/iframe takes its size
|
|
8034
|
+
// (resize), siblings reflow. A tool positioned now is stale, and the plugin may
|
|
8035
|
+
// REPLACE the inserted node so anything tied to it breaks. Instead of guessing
|
|
8036
|
+
// a delay, react to the actual layout events on the PERSISTENT container and
|
|
8037
|
+
// reposition via the live activeElement until they settle (debounced), then stop.
|
|
8038
|
+
repositionToolsUntilSettled(inserted) {
|
|
8039
|
+
const cont = inserted.closest('.is-container') || inserted.parentNode;
|
|
8040
|
+
const cwin = cont && cont.ownerDocument.defaultView || this.builder.win || window;
|
|
8041
|
+
if (!cont || !(cwin.ResizeObserver || cwin.MutationObserver)) return;
|
|
8042
|
+
let ro, mo, quiet;
|
|
8043
|
+
const stop = () => {
|
|
8044
|
+
if (ro) ro.disconnect();
|
|
8045
|
+
if (mo) mo.disconnect();
|
|
8046
|
+
clearTimeout(quiet);
|
|
8047
|
+
};
|
|
8048
|
+
const bump = () => {
|
|
8049
|
+
if (this.builder.activeElement && this.builder.elmTool && this.builder.elmTool.repositionElementTool) {
|
|
8050
|
+
this.builder.elmTool.repositionElementTool();
|
|
8051
|
+
}
|
|
8052
|
+
clearTimeout(quiet);
|
|
8053
|
+
quiet = setTimeout(stop, 300); // settled: 300ms with no further layout events
|
|
8054
|
+
};
|
|
8055
|
+
|
|
8056
|
+
if (cwin.ResizeObserver) {
|
|
8057
|
+
ro = new cwin.ResizeObserver(bump);
|
|
8058
|
+
ro.observe(cont);
|
|
8059
|
+
}
|
|
8060
|
+
if (cwin.MutationObserver) {
|
|
8061
|
+
mo = new cwin.MutationObserver(bump);
|
|
8062
|
+
mo.observe(cont, {
|
|
8063
|
+
childList: true,
|
|
8064
|
+
subtree: true
|
|
8065
|
+
});
|
|
8066
|
+
}
|
|
8067
|
+
bump(); // initial position + arm the settle timer
|
|
8068
|
+
setTimeout(stop, 3000); // hard safety cap
|
|
8069
|
+
}
|
|
8070
|
+
|
|
7928
8071
|
// https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro
|
|
7929
8072
|
htmlToElement(html) {
|
|
7930
8073
|
var template = document.createElement('template');
|
|
@@ -17041,7 +17184,7 @@ class HtmlUtil {
|
|
|
17041
17184
|
});
|
|
17042
17185
|
});
|
|
17043
17186
|
let elms;
|
|
17044
|
-
elms = tmp.querySelectorAll('.sortable-chosen, .sortable-ghost, .elm-active, .icon-active, .elm-inspected, .cell-active, .row-active, .row-outline, .is-builder, [data-cb-nohighlight]');
|
|
17187
|
+
elms = tmp.querySelectorAll('.sortable-chosen, .sortable-ghost, .elm-active, .icon-active, .elm-inspected, .cell-active, .row-active, .row-outline, .row-marked, .is-builder, [data-cb-nohighlight]');
|
|
17045
17188
|
elms.forEach(elm => {
|
|
17046
17189
|
elm.removeAttribute('data-cb-nohighlight');
|
|
17047
17190
|
elm.classList.remove('sortable-chosen');
|
|
@@ -17052,6 +17195,7 @@ class HtmlUtil {
|
|
|
17052
17195
|
elm.classList.remove('cell-active');
|
|
17053
17196
|
elm.classList.remove('row-active');
|
|
17054
17197
|
elm.classList.remove('row-outline');
|
|
17198
|
+
elm.classList.remove('row-marked');
|
|
17055
17199
|
elm.classList.remove('is-builder');
|
|
17056
17200
|
});
|
|
17057
17201
|
elms = tmp.querySelectorAll('[data-click], [contenteditable], [draggridoutline], [between-blocks-left], [between-blocks-center], [hideelementhighlight], [data-module-active], [draggable], [aria-keyshortcuts], [aria-describedby], [data-cb-panel]');
|
|
@@ -76716,6 +76860,25 @@ class ContentStuff {
|
|
|
76716
76860
|
.is-builder .row-active:not([data-protected]).row-outline {
|
|
76717
76861
|
outline: 1px solid rgba(132, 132, 132, 0.2);
|
|
76718
76862
|
}
|
|
76863
|
+
.is-builder .row-marked:not([data-protected]) {
|
|
76864
|
+
z-index: 1;
|
|
76865
|
+
}
|
|
76866
|
+
.is-builder .row-marked:not([data-protected])::after {
|
|
76867
|
+
content: '';
|
|
76868
|
+
position: absolute;
|
|
76869
|
+
inset: 0;
|
|
76870
|
+
z-index: 10;
|
|
76871
|
+
background-color: #a9c4e442;
|
|
76872
|
+
pointer-events: none;
|
|
76873
|
+
}
|
|
76874
|
+
.cb-block-band {
|
|
76875
|
+
position: fixed;
|
|
76876
|
+
z-index: 10000;
|
|
76877
|
+
box-sizing: border-box;
|
|
76878
|
+
border: 1px solid #c2e2ff;
|
|
76879
|
+
background-color: #a9c4e442;
|
|
76880
|
+
pointer-events: none;
|
|
76881
|
+
}
|
|
76719
76882
|
.is-builder .row-active:not([data-protected]):not(.row-outline) > div.cell-active {
|
|
76720
76883
|
outline: none;
|
|
76721
76884
|
}
|
|
@@ -77781,6 +77944,257 @@ class ContentStuff {
|
|
|
77781
77944
|
}
|
|
77782
77945
|
}
|
|
77783
77946
|
|
|
77947
|
+
/*
|
|
77948
|
+
Drag from the empty area around a container to select its blocks, then press
|
|
77949
|
+
Delete to remove them. Mouse only. The look follows the canvas selection.
|
|
77950
|
+
|
|
77951
|
+
The selection is its own mark (.row-marked), separate from the active block, and
|
|
77952
|
+
works with no active block at all. A press there changes nothing until the mouse
|
|
77953
|
+
moves, so a plain click behaves exactly as it always has.
|
|
77954
|
+
*/
|
|
77955
|
+
|
|
77956
|
+
const MARK = 'row-marked';
|
|
77957
|
+
const START_DISTANCE = 4;
|
|
77958
|
+
const SCROLL_EDGE = 40;
|
|
77959
|
+
const SCROLL_STEP = 14;
|
|
77960
|
+
const MODIFIER_KEYS = ['Shift', 'Control', 'Alt', 'Meta'];
|
|
77961
|
+
class BlockSelect {
|
|
77962
|
+
constructor(builder) {
|
|
77963
|
+
this.builder = builder;
|
|
77964
|
+
this.doc = builder.doc;
|
|
77965
|
+
this.win = builder.win;
|
|
77966
|
+
this.press = null;
|
|
77967
|
+
this.band = null;
|
|
77968
|
+
this.container = null;
|
|
77969
|
+
this.scrollFrame = null;
|
|
77970
|
+
this.onPress = this.onPress.bind(this);
|
|
77971
|
+
this.onPressOutside = this.onPressOutside.bind(this);
|
|
77972
|
+
this.onMove = this.onMove.bind(this);
|
|
77973
|
+
this.onMouseMove = this.onMouseMove.bind(this);
|
|
77974
|
+
this.clearSelection = this.clearSelection.bind(this);
|
|
77975
|
+
this.autoScroll = this.autoScroll.bind(this);
|
|
77976
|
+
this.onRelease = this.onRelease.bind(this);
|
|
77977
|
+
this.onKeydown = this.onKeydown.bind(this);
|
|
77978
|
+
this.doc.addEventListener('pointerdown', this.onPress, true);
|
|
77979
|
+
this.doc.addEventListener('keydown', this.onKeydown, true);
|
|
77980
|
+
|
|
77981
|
+
// The editor can live in an iframe: its page around the frame counts too.
|
|
77982
|
+
if (this.doc !== document) {
|
|
77983
|
+
document.addEventListener('pointerdown', this.onPressOutside, true);
|
|
77984
|
+
document.addEventListener('keydown', this.onKeydown, true);
|
|
77985
|
+
}
|
|
77986
|
+
}
|
|
77987
|
+
onPress(e) {
|
|
77988
|
+
this.clear();
|
|
77989
|
+
const builder = this.builder;
|
|
77990
|
+
if (builder.canvas && !builder.isContentBox) return; // freeform has its own selection
|
|
77991
|
+
if (e.pointerType !== 'mouse' || e.button !== 0) return;
|
|
77992
|
+
if (e.shiftKey || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
77993
|
+
const container = this.containerBeside(e);
|
|
77994
|
+
if (!container) return;
|
|
77995
|
+
const selection = this.win.getSelection();
|
|
77996
|
+
this.press = {
|
|
77997
|
+
container,
|
|
77998
|
+
pointerId: e.pointerId,
|
|
77999
|
+
startX: e.clientX,
|
|
78000
|
+
startY: e.clientY + this.win.pageYOffset,
|
|
78001
|
+
x: e.clientX,
|
|
78002
|
+
y: e.clientY,
|
|
78003
|
+
range: selection.rangeCount ? selection.getRangeAt(0).cloneRange() : null
|
|
78004
|
+
};
|
|
78005
|
+
this.doc.addEventListener('pointermove', this.onMove, true);
|
|
78006
|
+
this.doc.addEventListener('mousemove', this.onMouseMove, true);
|
|
78007
|
+
this.doc.addEventListener('pointerup', this.onRelease, true);
|
|
78008
|
+
this.doc.addEventListener('pointercancel', this.onRelease, true);
|
|
78009
|
+
}
|
|
78010
|
+
|
|
78011
|
+
// Cancelling the move stops the browser extending a text selection from the press.
|
|
78012
|
+
onMouseMove(e) {
|
|
78013
|
+
if (this.band) e.preventDefault();
|
|
78014
|
+
}
|
|
78015
|
+
onPressOutside() {
|
|
78016
|
+
this.clear();
|
|
78017
|
+
}
|
|
78018
|
+
|
|
78019
|
+
// The container nearest the press, which must be outside it: at its side, above
|
|
78020
|
+
// or below. The pressed element must be one
|
|
78021
|
+
// that holds the container (the page or a wrapper), never something of the host
|
|
78022
|
+
// page that merely sits beside it. A section's bare background layer also counts:
|
|
78023
|
+
// it fills the section behind the container rather than around it.
|
|
78024
|
+
containerBeside(e) {
|
|
78025
|
+
const target = e.target;
|
|
78026
|
+
|
|
78027
|
+
// The container's own padding, above or below its blocks.
|
|
78028
|
+
if (target.matches(this.builder.opts.container) && !target.closest('[data-top-locked], [data-bottom-locked], .is-block')) return target;
|
|
78029
|
+
const area = target.matches('.is-overlay, .is-overlay-bg') ? target.closest('.is-box') : target;
|
|
78030
|
+
if (!area) return null;
|
|
78031
|
+
const containers = this.doc.querySelectorAll(this.builder.opts.container);
|
|
78032
|
+
let nearest = null;
|
|
78033
|
+
let nearestDistance = Infinity;
|
|
78034
|
+
for (let i = 0; i < containers.length; i++) {
|
|
78035
|
+
const container = containers[i];
|
|
78036
|
+
if (target === container || !area.contains(container)) continue;
|
|
78037
|
+
if (container.closest('[data-top-locked], [data-bottom-locked], .is-block')) continue;
|
|
78038
|
+
const rect = container.getBoundingClientRect();
|
|
78039
|
+
const inside = e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom;
|
|
78040
|
+
if (inside) continue;
|
|
78041
|
+
const distance = Math.max(rect.top - e.clientY, e.clientY - rect.bottom, 0);
|
|
78042
|
+
if (distance < nearestDistance) {
|
|
78043
|
+
nearest = container;
|
|
78044
|
+
nearestDistance = distance;
|
|
78045
|
+
}
|
|
78046
|
+
}
|
|
78047
|
+
return nearest;
|
|
78048
|
+
}
|
|
78049
|
+
onMove(e) {
|
|
78050
|
+
const press = this.press;
|
|
78051
|
+
if (!press) return;
|
|
78052
|
+
press.x = e.clientX;
|
|
78053
|
+
press.y = e.clientY;
|
|
78054
|
+
if (!this.band) {
|
|
78055
|
+
const distance = Math.max(Math.abs(e.clientX - press.startX), Math.abs(e.clientY + this.win.pageYOffset - press.startY));
|
|
78056
|
+
if (distance < START_DISTANCE) return;
|
|
78057
|
+
this.begin();
|
|
78058
|
+
}
|
|
78059
|
+
this.update();
|
|
78060
|
+
}
|
|
78061
|
+
begin() {
|
|
78062
|
+
const press = this.press;
|
|
78063
|
+
this.container = press.container;
|
|
78064
|
+
this.band = this.doc.createElement('div');
|
|
78065
|
+
this.band.className = 'cb-block-band';
|
|
78066
|
+
this.doc.body.appendChild(this.band);
|
|
78067
|
+
try {
|
|
78068
|
+
this.doc.documentElement.setPointerCapture(press.pointerId);
|
|
78069
|
+
} catch (err) {/* the pointer is already gone */}
|
|
78070
|
+
this.doc.addEventListener('selectionchange', this.clearSelection);
|
|
78071
|
+
this.clearSelection();
|
|
78072
|
+
this.scrollFrame = this.win.requestAnimationFrame(this.autoScroll);
|
|
78073
|
+
}
|
|
78074
|
+
|
|
78075
|
+
// A caret or text selection left in place would be extended by the drag, so
|
|
78076
|
+
// there is none until the release puts back what the user had.
|
|
78077
|
+
clearSelection() {
|
|
78078
|
+
const selection = this.win.getSelection();
|
|
78079
|
+
if (selection.rangeCount) selection.removeAllRanges();
|
|
78080
|
+
}
|
|
78081
|
+
restoreSelection() {
|
|
78082
|
+
const range = this.press.range;
|
|
78083
|
+
this.clearSelection();
|
|
78084
|
+
if (range) this.win.getSelection().addRange(range.cloneRange());
|
|
78085
|
+
}
|
|
78086
|
+
update() {
|
|
78087
|
+
const press = this.press;
|
|
78088
|
+
const startY = press.startY - this.win.pageYOffset;
|
|
78089
|
+
const left = Math.min(press.startX, press.x);
|
|
78090
|
+
const top = Math.min(startY, press.y);
|
|
78091
|
+
const right = Math.max(press.startX, press.x);
|
|
78092
|
+
const bottom = Math.max(startY, press.y);
|
|
78093
|
+
this.band.style.left = left + 'px';
|
|
78094
|
+
this.band.style.top = top + 'px';
|
|
78095
|
+
this.band.style.width = right - left + 'px';
|
|
78096
|
+
this.band.style.height = bottom - top + 'px';
|
|
78097
|
+
this.selectableRows().forEach(row => {
|
|
78098
|
+
const rect = row.getBoundingClientRect();
|
|
78099
|
+
const touched = rect.left < right && rect.right > left && rect.top < bottom && rect.bottom > top;
|
|
78100
|
+
row.classList.toggle(MARK, touched);
|
|
78101
|
+
});
|
|
78102
|
+
}
|
|
78103
|
+
selectableRows() {
|
|
78104
|
+
return Array.from(this.container.children).filter(row => {
|
|
78105
|
+
return row.tagName === 'DIV' && !row.matches('.row-add-initial, .dummy-space, [data-protected]');
|
|
78106
|
+
});
|
|
78107
|
+
}
|
|
78108
|
+
autoScroll() {
|
|
78109
|
+
if (!this.band) return;
|
|
78110
|
+
const y = this.press.y;
|
|
78111
|
+
let step = 0;
|
|
78112
|
+
if (y < SCROLL_EDGE) step = -SCROLL_STEP;else if (y > this.win.innerHeight - SCROLL_EDGE) step = SCROLL_STEP;
|
|
78113
|
+
if (step) {
|
|
78114
|
+
this.win.scrollBy(0, step);
|
|
78115
|
+
this.update();
|
|
78116
|
+
}
|
|
78117
|
+
this.scrollFrame = this.win.requestAnimationFrame(this.autoScroll);
|
|
78118
|
+
}
|
|
78119
|
+
onRelease() {
|
|
78120
|
+
this.doc.removeEventListener('pointermove', this.onMove, true);
|
|
78121
|
+
this.doc.removeEventListener('mousemove', this.onMouseMove, true);
|
|
78122
|
+
this.doc.removeEventListener('pointerup', this.onRelease, true);
|
|
78123
|
+
this.doc.removeEventListener('pointercancel', this.onRelease, true);
|
|
78124
|
+
if (this.band) {
|
|
78125
|
+
this.endBand();
|
|
78126
|
+
this.restoreSelection();
|
|
78127
|
+
|
|
78128
|
+
// The click ending a drag is not a click on the page.
|
|
78129
|
+
const stopClick = e => e.stopPropagation();
|
|
78130
|
+
this.win.addEventListener('click', stopClick, true);
|
|
78131
|
+
this.win.setTimeout(() => this.win.removeEventListener('click', stopClick, true), 0);
|
|
78132
|
+
}
|
|
78133
|
+
this.press = null;
|
|
78134
|
+
}
|
|
78135
|
+
endBand() {
|
|
78136
|
+
this.win.cancelAnimationFrame(this.scrollFrame);
|
|
78137
|
+
this.doc.removeEventListener('selectionchange', this.clearSelection);
|
|
78138
|
+
this.band.remove();
|
|
78139
|
+
this.band = null;
|
|
78140
|
+
}
|
|
78141
|
+
onKeydown(e) {
|
|
78142
|
+
const rows = this.markedRows();
|
|
78143
|
+
if (!rows.length || MODIFIER_KEYS.includes(e.key)) return;
|
|
78144
|
+
const plain = !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
78145
|
+
if (plain && (e.key === 'Delete' || e.key === 'Backspace')) {
|
|
78146
|
+
e.preventDefault();
|
|
78147
|
+
e.stopPropagation();
|
|
78148
|
+
this.removeRows(rows);
|
|
78149
|
+
return;
|
|
78150
|
+
}
|
|
78151
|
+
this.clear();
|
|
78152
|
+
if (e.key === 'Escape') {
|
|
78153
|
+
e.preventDefault();
|
|
78154
|
+
e.stopPropagation();
|
|
78155
|
+
}
|
|
78156
|
+
}
|
|
78157
|
+
markedRows() {
|
|
78158
|
+
if (!this.container) return [];
|
|
78159
|
+
return Array.from(this.container.querySelectorAll(':scope > .' + MARK));
|
|
78160
|
+
}
|
|
78161
|
+
clear() {
|
|
78162
|
+
this.markedRows().forEach(row => row.classList.remove(MARK));
|
|
78163
|
+
}
|
|
78164
|
+
removeRows(rows) {
|
|
78165
|
+
const builder = this.builder;
|
|
78166
|
+
const util = builder.util;
|
|
78167
|
+
const activeRemoved = rows.some(row => row.classList.contains('row-active'));
|
|
78168
|
+
this.clear();
|
|
78169
|
+
builder.uo.saveForUndo();
|
|
78170
|
+
rows.forEach(row => row.parentNode.removeChild(row));
|
|
78171
|
+
util.checkEmpty();
|
|
78172
|
+
if (activeRemoved) util.clearActiveCell();
|
|
78173
|
+
builder.opts.onChange();
|
|
78174
|
+
|
|
78175
|
+
// Same as the row tool's Delete: its tools and the panel were about that block.
|
|
78176
|
+
if (activeRemoved) {
|
|
78177
|
+
util.clearControls();
|
|
78178
|
+
util.clearModals();
|
|
78179
|
+
if (builder.onSelectChange) builder.onSelectChange();
|
|
78180
|
+
}
|
|
78181
|
+
}
|
|
78182
|
+
destroy() {
|
|
78183
|
+
this.doc.removeEventListener('pointerdown', this.onPress, true);
|
|
78184
|
+
this.doc.removeEventListener('keydown', this.onKeydown, true);
|
|
78185
|
+
this.doc.removeEventListener('pointermove', this.onMove, true);
|
|
78186
|
+
this.doc.removeEventListener('mousemove', this.onMouseMove, true);
|
|
78187
|
+
this.doc.removeEventListener('pointerup', this.onRelease, true);
|
|
78188
|
+
this.doc.removeEventListener('pointercancel', this.onRelease, true);
|
|
78189
|
+
if (this.doc !== document) {
|
|
78190
|
+
document.removeEventListener('pointerdown', this.onPressOutside, true);
|
|
78191
|
+
document.removeEventListener('keydown', this.onKeydown, true);
|
|
78192
|
+
}
|
|
78193
|
+
if (this.band) this.endBand();
|
|
78194
|
+
this.clear();
|
|
78195
|
+
}
|
|
78196
|
+
}
|
|
78197
|
+
|
|
77784
78198
|
class MediaPicker {
|
|
77785
78199
|
constructor(builder) {
|
|
77786
78200
|
this.builder = builder;
|
|
@@ -95570,6 +95984,8 @@ class ContentBuilder {
|
|
|
95570
95984
|
this.toolbarKeys = new ToolbarKeys(this); // Keyboard access to the tool strips
|
|
95571
95985
|
|
|
95572
95986
|
this._rowTool = new RowTool(this);
|
|
95987
|
+
this.blockSelect = new BlockSelect(this); // Drag from the side margin to select blocks
|
|
95988
|
+
|
|
95573
95989
|
this.livePreview = new LivePreview(this);
|
|
95574
95990
|
this.mediaPicker = new MediaPicker(this);
|
|
95575
95991
|
|
|
@@ -95661,11 +96077,15 @@ class ContentBuilder {
|
|
|
95661
96077
|
<div class="is-modal-bar">
|
|
95662
96078
|
<button class="is-modal-close" title="${util.out('Close')}" tabindex="-1" aria-label="${util.out('Close')}">✕</button>
|
|
95663
96079
|
</div>
|
|
95664
|
-
<div class="
|
|
95665
|
-
<div class="cb-tabs
|
|
95666
|
-
|
|
95667
|
-
|
|
96080
|
+
<div class="snippet-cats-bar">
|
|
96081
|
+
<div class="cb-tabs-scroller snippet-cats">
|
|
96082
|
+
<div class="cb-tabs cb-tabs-scroll" role="tablist" aria-label="${util.out('Snippets')}"></div>
|
|
96083
|
+
<button type="button" class="cb-tabs-arrow cb-tabs-arrow--prev" aria-hidden="true" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 18l-6-6 6-6"/></svg></button>
|
|
96084
|
+
<button type="button" class="cb-tabs-arrow cb-tabs-arrow--next" aria-hidden="true" tabindex="-1"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg></button>
|
|
96085
|
+
</div>
|
|
96086
|
+
<button type="button" class="snippet-cats-all" aria-haspopup="dialog" aria-expanded="false" hidden>${util.out('All Categories')}<svg aria-hidden="true"><use xlink:href="#icon-chevron-down"></use></svg></button>
|
|
95668
96087
|
</div>
|
|
96088
|
+
<div class="snippet-cats-menu" role="dialog" hidden></div>
|
|
95669
96089
|
<ul class="snippet-grid"></ul>
|
|
95670
96090
|
</div>
|
|
95671
96091
|
</div>
|
|
@@ -98440,6 +98860,7 @@ class ContentBuilder {
|
|
|
98440
98860
|
const linkStyle = document.head.querySelector('#_snippet_style');
|
|
98441
98861
|
if (linkStyle) linkStyle.remove();
|
|
98442
98862
|
if (this.eb) this.eb.destroy();
|
|
98863
|
+
if (this.blockSelect) this.blockSelect.destroy();
|
|
98443
98864
|
if (this.codeElement) this.codeElement.destroy();
|
|
98444
98865
|
if (this.letak) {
|
|
98445
98866
|
this.letak.destroy();
|