@themarioga/grid-editor 9.1.0 → 9.1.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 +16 -0
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.esm.js +91 -45
- package/dist/grideditor.js +91 -45
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/plugins/grideditor.inline-style.esm.js +28 -15
- package/dist/plugins/grideditor.inline-style.js +28 -15
- package/dist/plugins/grideditor.inline-style.min.js +4 -4
- package/dist/plugins/grideditor.inline-style.min.js.map +3 -3
- package/package.json +1 -1
- package/src/js/grideditor.js +102 -49
- package/src/js/inline-style/drawerflow.js +35 -14
package/package.json
CHANGED
package/src/js/grideditor.js
CHANGED
|
@@ -1138,8 +1138,21 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1138
1138
|
|
|
1139
1139
|
var signal = { signal: lifetime.signal };
|
|
1140
1140
|
|
|
1141
|
-
// Make controls fixed on scroll
|
|
1142
|
-
|
|
1141
|
+
// Make controls fixed on scroll. Once a frame, after the
|
|
1142
|
+
// layout: a scroll also comes when the page changes height - a
|
|
1143
|
+
// getHtml takes every drawer off and puts it back - and read
|
|
1144
|
+
// there and then, the toolbar's position laid the page out again
|
|
1145
|
+
var scrollFrame = null;
|
|
1146
|
+
window.addEventListener('scroll', function() {
|
|
1147
|
+
if (scrollFrame !== null) { return; }
|
|
1148
|
+
scrollFrame = window.requestAnimationFrame(function() {
|
|
1149
|
+
scrollFrame = null;
|
|
1150
|
+
if (!destroyed && mainControls) { onScroll(); }
|
|
1151
|
+
});
|
|
1152
|
+
}, signal);
|
|
1153
|
+
lifetime.signal.addEventListener('abort', function() {
|
|
1154
|
+
if (scrollFrame !== null) { window.cancelAnimationFrame(scrollFrame); }
|
|
1155
|
+
});
|
|
1143
1156
|
|
|
1144
1157
|
/* A click on the host's plain content offers to make it a text */
|
|
1145
1158
|
dom.delegate(canvas, 'click', '.ge-content', onContentClick, signal);
|
|
@@ -2505,26 +2518,35 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2505
2518
|
}
|
|
2506
2519
|
|
|
2507
2520
|
/**
|
|
2508
|
-
* A copy of the canvas, and the way from each of
|
|
2509
|
-
* the one it was copied from.
|
|
2510
|
-
*
|
|
2521
|
+
* A copy of the canvas without its drawers, and the way from each of
|
|
2522
|
+
* its elements back to the one it was copied from.
|
|
2523
|
+
*
|
|
2524
|
+
* Copied node by node rather than cloned whole: the drawers are most
|
|
2525
|
+
* of the canvas while it is edited, and a snapshot only took them off
|
|
2526
|
+
* again. A template is the one node a shallow clone leaves empty, so
|
|
2527
|
+
* it goes whole.
|
|
2511
2528
|
*/
|
|
2512
2529
|
function copyCanvas() {
|
|
2513
|
-
var copy = canvas.cloneNode(true);
|
|
2514
2530
|
var toLive = new Map();
|
|
2515
2531
|
var toCopy = new Map();
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2532
|
+
|
|
2533
|
+
function copyNode(live) {
|
|
2534
|
+
var copied = live.cloneNode(live.nodeName === 'TEMPLATE');
|
|
2535
|
+
if (live.nodeType !== 1) { return copied; }
|
|
2536
|
+
|
|
2537
|
+
toLive.set(copied, live);
|
|
2538
|
+
toCopy.set(live, copied);
|
|
2539
|
+
if (live.nodeName === 'TEMPLATE') { return copied; }
|
|
2540
|
+
|
|
2541
|
+
for (var child = live.firstChild; child; child = child.nextSibling) {
|
|
2542
|
+
if (child.nodeType === 1 && dom.hasClass(child, 'ge-tools-drawer')) { continue; }
|
|
2543
|
+
copied.appendChild(copyNode(child));
|
|
2544
|
+
}
|
|
2545
|
+
return copied;
|
|
2526
2546
|
}
|
|
2527
2547
|
|
|
2548
|
+
var copy = copyNode(canvas);
|
|
2549
|
+
|
|
2528
2550
|
return {
|
|
2529
2551
|
root: copy,
|
|
2530
2552
|
liveOf: function(node) { return toLive.get(node) || null; },
|
|
@@ -4127,15 +4149,13 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4127
4149
|
|
|
4128
4150
|
function flush() {
|
|
4129
4151
|
frame = null;
|
|
4130
|
-
var drawers = Array.from(due)
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
drawerResizes.unobserve(drawer);
|
|
4135
|
-
return;
|
|
4136
|
-
}
|
|
4137
|
-
fitDrawer(drawer);
|
|
4152
|
+
var drawers = Array.from(due).filter(function(drawer) {
|
|
4153
|
+
if (drawer.isConnected) { return true; }
|
|
4154
|
+
drawerResizes.unobserve(drawer);
|
|
4155
|
+
return false;
|
|
4138
4156
|
});
|
|
4157
|
+
due.clear();
|
|
4158
|
+
fitDrawers(drawers);
|
|
4139
4159
|
}
|
|
4140
4160
|
|
|
4141
4161
|
var drawerResizes = new window.ResizeObserver(function(entries) {
|
|
@@ -4178,40 +4198,73 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
4178
4198
|
});
|
|
4179
4199
|
}
|
|
4180
4200
|
|
|
4181
|
-
/**
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4201
|
+
/**
|
|
4202
|
+
* Hide the tools that don't fit on each drawer's line, from the end,
|
|
4203
|
+
* behind its more tool.
|
|
4204
|
+
*
|
|
4205
|
+
* All the drawers at once, in phases - every write, then every read -
|
|
4206
|
+
* so the page is laid out three times however many drawers there
|
|
4207
|
+
* are: a drawer at a time, each measure laid out the whole page
|
|
4208
|
+
* again, and a canvas of a few hundred drawers took seconds. One
|
|
4209
|
+
* measure of a drawer is enough: its tools are on one line, aligned
|
|
4210
|
+
* left, so hiding the last ones or making room for the more tool at
|
|
4211
|
+
* the end moves none of the others.
|
|
4212
|
+
*/
|
|
4213
|
+
function fitDrawers(drawers) {
|
|
4214
|
+
// Every tool back on the one line
|
|
4215
|
+
var fits = drawers.map(function(drawer) {
|
|
4216
|
+
var fit = {
|
|
4217
|
+
drawer: drawer,
|
|
4218
|
+
tools: dom.children(drawer, 'a').filter(function(tool) { return !dom.hasClass(tool, 'ge-drawer-more'); }),
|
|
4219
|
+
expanded: dom.hasClass(drawer, 'ge-drawer-expanded'),
|
|
4220
|
+
};
|
|
4221
|
+
dom.removeClass(drawer, 'ge-drawer-overflow ge-drawer-expanded');
|
|
4222
|
+
fit.tools.forEach(function(tool) { dom.removeClass(tool, 'ge-tool-overflow'); });
|
|
4223
|
+
return fit;
|
|
4224
|
+
});
|
|
4191
4225
|
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4226
|
+
// Where each tool ends, and whether any ends past the drawer's room
|
|
4227
|
+
var over = fits.filter(function(fit) {
|
|
4228
|
+
fit.rights = fit.tools.map(function(tool) {
|
|
4229
|
+
var rects = tool.getClientRects();
|
|
4230
|
+
return rects.length ? rects[0].right : null;
|
|
4196
4231
|
});
|
|
4197
|
-
|
|
4232
|
+
return overflows(fit, roomOf(fit.drawer));
|
|
4233
|
+
});
|
|
4198
4234
|
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
}
|
|
4235
|
+
// The more tool takes its room at the end, and the tools that
|
|
4236
|
+
// still end past it are hidden, from the last
|
|
4237
|
+
over.forEach(function(fit) { dom.addClass(fit.drawer, 'ge-drawer-overflow'); });
|
|
4238
|
+
over.forEach(function(fit) { fit.room = roomOf(fit.drawer); });
|
|
4239
|
+
over.forEach(function(fit) {
|
|
4240
|
+
for (var i = fit.tools.length - 1; i >= 0 && overflows(fit, fit.room, i); i--) {
|
|
4241
|
+
dom.addClass(fit.tools[i], 'ge-tool-overflow');
|
|
4242
|
+
}
|
|
4243
|
+
if (!dom.child(fit.drawer, '.ge-drawer-more')) {
|
|
4244
|
+
createTool(fit.drawer, t('tool.more'), 'ge-drawer-more', 'bi bi-three-dots', function() {
|
|
4245
|
+
dom.toggleClass(fit.drawer, 'ge-drawer-expanded');
|
|
4246
|
+
});
|
|
4247
|
+
}
|
|
4202
4248
|
|
|
4203
|
-
|
|
4249
|
+
// Unfolded it stays, while there is something to unfold
|
|
4250
|
+
dom.toggleClass(fit.drawer, 'ge-drawer-expanded', fit.expanded);
|
|
4251
|
+
});
|
|
4204
4252
|
}
|
|
4205
4253
|
|
|
4206
|
-
|
|
4254
|
+
/** Where a drawer's tools have to end: its right edge, inside its border and padding. */
|
|
4255
|
+
function roomOf(drawer) {
|
|
4207
4256
|
var style = window.getComputedStyle(drawer);
|
|
4208
|
-
|
|
4257
|
+
return drawer.getBoundingClientRect().right -
|
|
4209
4258
|
parseFloat(style.borderRightWidth) - parseFloat(style.paddingRight);
|
|
4259
|
+
}
|
|
4210
4260
|
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4261
|
+
/** Whether any of a drawer's tools up to `last` ends past `room`. */
|
|
4262
|
+
function overflows(fit, room, last) {
|
|
4263
|
+
last = last === undefined ? fit.rights.length - 1 : last;
|
|
4264
|
+
for (var i = 0; i <= last; i++) {
|
|
4265
|
+
if (fit.rights[i] !== null && fit.rights[i] > room + 0.5) { return true; }
|
|
4266
|
+
}
|
|
4267
|
+
return false;
|
|
4215
4268
|
}
|
|
4216
4269
|
|
|
4217
4270
|
/**
|
|
@@ -55,13 +55,20 @@ export function drawerflowPart(ge) {
|
|
|
55
55
|
return !(dom.hasClass(node, 'row') && style.flexDirection === 'row' && style.flexWrap === 'wrap');
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
/** The room a drawer takes above its node's content. */
|
|
59
|
+
function roomOf(drawer) {
|
|
60
|
+
return Math.ceil(drawer.offsetHeight) + GAP;
|
|
61
|
+
}
|
|
60
62
|
|
|
63
|
+
function place(node, room) {
|
|
61
64
|
rule(room);
|
|
62
65
|
node.setAttribute(OUT_ATTR, String(room));
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
function measure(node, drawer) {
|
|
69
|
+
place(node, roomOf(drawer));
|
|
70
|
+
}
|
|
71
|
+
|
|
65
72
|
/** A drawer that grows - its tools wrap, its settings unfold - takes more room. */
|
|
66
73
|
function watch(drawer) {
|
|
67
74
|
if (typeof ResizeObserver === 'undefined') { return; }
|
|
@@ -77,22 +84,36 @@ export function drawerflowPart(ge) {
|
|
|
77
84
|
observer.observe(drawer);
|
|
78
85
|
}
|
|
79
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Every read, then every write: a node at a time, each read laid out the
|
|
89
|
+
* whole page again after the last node's write, which on a large canvas
|
|
90
|
+
* took longer than everything else a refresh does.
|
|
91
|
+
*/
|
|
80
92
|
function mark(scope) {
|
|
81
|
-
dom.selfAndAll(scope, NODES).
|
|
93
|
+
var nodes = dom.selfAndAll(scope, NODES).map(function(node) {
|
|
82
94
|
var drawer = dom.child(node, '.ge-tools-drawer');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
dom.
|
|
91
|
-
|
|
92
|
-
dom.
|
|
93
|
-
|
|
95
|
+
return drawer ? { node: node, drawer: drawer, out: laysOut(node) } : null;
|
|
96
|
+
}).filter(Boolean);
|
|
97
|
+
|
|
98
|
+
var out = nodes.filter(function(entry) { return entry.out; });
|
|
99
|
+
|
|
100
|
+
nodes.forEach(function(entry) {
|
|
101
|
+
if (entry.out) {
|
|
102
|
+
dom.addClass(entry.node, OUT_CLASS);
|
|
103
|
+
} else if (dom.hasClass(entry.node, OUT_CLASS)) {
|
|
104
|
+
dom.removeClass(entry.node, OUT_CLASS);
|
|
105
|
+
entry.node.removeAttribute(OUT_ATTR);
|
|
106
|
+
dom.dropEmptyClass(entry.node);
|
|
107
|
+
if (observer) { observer.unobserve(entry.drawer); }
|
|
94
108
|
}
|
|
95
109
|
});
|
|
110
|
+
|
|
111
|
+
// Out of the flow its drawer is as wide as the node, and may wrap
|
|
112
|
+
out.forEach(function(entry) { entry.room = roomOf(entry.drawer); });
|
|
113
|
+
out.forEach(function(entry) {
|
|
114
|
+
place(entry.node, entry.room);
|
|
115
|
+
watch(entry.drawer);
|
|
116
|
+
});
|
|
96
117
|
}
|
|
97
118
|
|
|
98
119
|
function unmarkNodes(root) {
|