@themarioga/grid-editor 9.0.0-beta.2 → 9.0.0-beta.3
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 +14 -0
- package/README.md +52 -0
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.d.ts +38 -0
- package/dist/grideditor.esm.js +33 -2
- package/dist/grideditor.js +33 -2
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/locales/grideditor.es.esm.js +2 -0
- package/dist/locales/grideditor.es.js +2 -0
- package/dist/locales/grideditor.es.min.js +1 -1
- package/dist/locales/grideditor.es.min.js.map +2 -2
- package/dist/plugins/grideditor.history.esm.js +360 -0
- package/dist/plugins/grideditor.history.js +365 -0
- package/dist/plugins/grideditor.history.min.js +1 -0
- package/dist/plugins/grideditor.history.min.js.map +7 -0
- package/docs/events.md +3 -0
- package/docs/locale-keys.md +11 -0
- package/docs/plugins.md +8 -1
- package/example/clipboard.html +22 -0
- package/example/history.html +94 -0
- package/example/index.html +8 -0
- package/package.json +1 -1
- package/src/js/grideditor.js +30 -1
- package/src/js/locales/grideditor.es.js +2 -0
- package/src/js/plugins/grideditor.history.js +367 -0
- package/types/grideditor.d.ts +38 -0
package/dist/grideditor.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ export interface GridEditorOptions {
|
|
|
180
180
|
autosave?: AutosaveOptions;
|
|
181
181
|
/** The clipboard plugin. `shortcuts`: Ctrl+C and Ctrl+V on the node selected or the target; default active_target. */
|
|
182
182
|
clipboard?: { shortcuts?: boolean };
|
|
183
|
+
/** The history plugin: undo and redo. */
|
|
184
|
+
history?: HistoryOptions;
|
|
183
185
|
custom_filter?: CustomFilter | CustomFilter[] | '';
|
|
184
186
|
valid_col_sizes?: ColumnSize[];
|
|
185
187
|
valid_col_offsets?: number[];
|
|
@@ -222,6 +224,18 @@ export interface AutosaveOptions {
|
|
|
222
224
|
maxAge?: number | null;
|
|
223
225
|
}
|
|
224
226
|
|
|
227
|
+
/** The history plugin's options. */
|
|
228
|
+
export interface HistoryOptions {
|
|
229
|
+
/** Ctrl+Z, and Ctrl+Y or Ctrl+Shift+Z (⌘ on a Mac). Default true. */
|
|
230
|
+
shortcuts?: boolean;
|
|
231
|
+
/** The undo and redo buttons on the right of the toolbar. Default true. */
|
|
232
|
+
buttons?: boolean;
|
|
233
|
+
/** The steps that can be undone. Default 50. */
|
|
234
|
+
max?: number;
|
|
235
|
+
/** Milliseconds after the last change that make a step. Default 500. */
|
|
236
|
+
delay?: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
225
239
|
/** A draft the autosave plugin kept. */
|
|
226
240
|
export interface AutosaveDraft {
|
|
227
241
|
html: string;
|
|
@@ -252,6 +266,19 @@ export interface AutosaveErrorPayload {
|
|
|
252
266
|
error: unknown;
|
|
253
267
|
}
|
|
254
268
|
|
|
269
|
+
export interface HistoryPayload {
|
|
270
|
+
canvas: HTMLElement;
|
|
271
|
+
/** The markup the canvas went to. */
|
|
272
|
+
html: string;
|
|
273
|
+
source: 'shortcut' | 'tool' | 'api';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface HistoryChangePayload {
|
|
277
|
+
canvas: HTMLElement;
|
|
278
|
+
canUndo: boolean;
|
|
279
|
+
canRedo: boolean;
|
|
280
|
+
}
|
|
281
|
+
|
|
255
282
|
/** Where a node was, or went: its parent and its index among the blocks there. */
|
|
256
283
|
export interface Position {
|
|
257
284
|
parent: HTMLElement;
|
|
@@ -385,6 +412,9 @@ export interface GridEditorEventMap {
|
|
|
385
412
|
'grideditor:after-autosave': AutosavePayload;
|
|
386
413
|
'grideditor:after-restore-draft': RestoreDraftPayload;
|
|
387
414
|
'grideditor:autosave-error': AutosaveErrorPayload;
|
|
415
|
+
'grideditor:after-undo': HistoryPayload;
|
|
416
|
+
'grideditor:after-redo': HistoryPayload;
|
|
417
|
+
'grideditor:history-change': HistoryChangePayload;
|
|
388
418
|
}
|
|
389
419
|
|
|
390
420
|
/** An event the editor dispatches on its canvas: a CustomEvent whose detail is the payload. */
|
|
@@ -523,6 +553,14 @@ export declare class GridEditor {
|
|
|
523
553
|
saveDraft?(): boolean;
|
|
524
554
|
getDraft?(): AutosaveDraft | null;
|
|
525
555
|
clearDraft?(): boolean;
|
|
556
|
+
/** The history plugin's, when it is loaded: true when it went to another step. */
|
|
557
|
+
undo?(): boolean;
|
|
558
|
+
redo?(): boolean;
|
|
559
|
+
/** Whether there is a step to go back to, a change not yet a step counting. */
|
|
560
|
+
canUndo?(): boolean;
|
|
561
|
+
canRedo?(): boolean;
|
|
562
|
+
/** What there is now becomes the first step, with nothing before or after it. */
|
|
563
|
+
clearHistory?(): boolean;
|
|
526
564
|
}
|
|
527
565
|
|
|
528
566
|
export default GridEditor;
|
package/dist/grideditor.esm.js
CHANGED
|
@@ -1545,6 +1545,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1545
1545
|
var label = typeof item.label === "function" ? item.label() : item.label || t(item.labelKey);
|
|
1546
1546
|
var colour = item.align === "end" ? "btn-primary" : "btn-light";
|
|
1547
1547
|
var button = labelButton(element("a", { "class": "btn btn-sm " + colour + " ge-add-container ge-add-feature" }), label, iconClass);
|
|
1548
|
+
var acting = typeof item.action === "function";
|
|
1548
1549
|
addClass(button, item.className || "");
|
|
1549
1550
|
if (typeof item.hidden === "function" ? item.hidden() : item.hidden) {
|
|
1550
1551
|
hide(button);
|
|
@@ -1554,7 +1555,20 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1554
1555
|
"data-ge-feature": name,
|
|
1555
1556
|
"data-ge-item": index
|
|
1556
1557
|
});
|
|
1558
|
+
if (acting) {
|
|
1559
|
+
button.setAttribute("data-ge-action", "");
|
|
1560
|
+
if (typeof item.disabled === "function" ? item.disabled() : item.disabled) {
|
|
1561
|
+
addClass(button, "disabled");
|
|
1562
|
+
button.setAttribute("aria-disabled", "true");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1557
1565
|
button.addEventListener("click", function() {
|
|
1566
|
+
if (acting) {
|
|
1567
|
+
if (!hasClass(button, "disabled")) {
|
|
1568
|
+
item.action(button);
|
|
1569
|
+
}
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1558
1572
|
if (activeTarget) {
|
|
1559
1573
|
addToTarget(button, item.source || "tool");
|
|
1560
1574
|
return;
|
|
@@ -1580,7 +1594,7 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
1580
1594
|
return !!settings.toolbar_drag;
|
|
1581
1595
|
}
|
|
1582
1596
|
function makeToolbarDraggable() {
|
|
1583
|
-
var buttons = all(mainControls, "[data-ge-toolbar]");
|
|
1597
|
+
var buttons = all(mainControls, "[data-ge-toolbar]:not([data-ge-action])");
|
|
1584
1598
|
buttons.forEach(function(button) {
|
|
1585
1599
|
removeClass(button, "ge-palette-button");
|
|
1586
1600
|
button.removeEventListener("pointerdown", startToolbarDrag);
|
|
@@ -2356,6 +2370,23 @@ function build(instance, baseElem, optionsOrMethod) {
|
|
|
2356
2370
|
getActiveTarget: function() {
|
|
2357
2371
|
return settings.active_target ? activeTarget : null;
|
|
2358
2372
|
},
|
|
2373
|
+
// True when it took: a node that cannot be, or no setting
|
|
2374
|
+
// for it, says nothing, since a plugin putting back what it
|
|
2375
|
+
// remembers cannot know the node is still one
|
|
2376
|
+
setSelected: function(node) {
|
|
2377
|
+
var chosen = panelMode() === "sidebar" && !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
|
|
2378
|
+
if (chosen) {
|
|
2379
|
+
changeSelection(node);
|
|
2380
|
+
}
|
|
2381
|
+
return chosen;
|
|
2382
|
+
},
|
|
2383
|
+
setActiveTarget: function(node) {
|
|
2384
|
+
var chosen = !!settings.active_target && isTarget(node);
|
|
2385
|
+
if (chosen) {
|
|
2386
|
+
changeTarget(node);
|
|
2387
|
+
}
|
|
2388
|
+
return chosen;
|
|
2389
|
+
},
|
|
2359
2390
|
// What keeps Escape from the selection and the target, and an
|
|
2360
2391
|
// inline panel unfolded in a drawer, which Escape leaves alone
|
|
2361
2392
|
panelOpen: function() {
|
|
@@ -5148,7 +5179,7 @@ GridEditor.t = translate;
|
|
|
5148
5179
|
GridEditor._plainHtml = plainHtml;
|
|
5149
5180
|
GridEditor.Sortable = null;
|
|
5150
5181
|
GridEditor.bootstrap = null;
|
|
5151
|
-
GridEditor.version = false ? "dev" : "9.0.0-beta.
|
|
5182
|
+
GridEditor.version = false ? "dev" : "9.0.0-beta.3";
|
|
5152
5183
|
GridEditor.locales = {
|
|
5153
5184
|
en: {
|
|
5154
5185
|
"tool.move": "Move",
|
package/dist/grideditor.js
CHANGED
|
@@ -1546,6 +1546,7 @@
|
|
|
1546
1546
|
var label = typeof item.label === "function" ? item.label() : item.label || t(item.labelKey);
|
|
1547
1547
|
var colour = item.align === "end" ? "btn-primary" : "btn-light";
|
|
1548
1548
|
var button = labelButton(element("a", { "class": "btn btn-sm " + colour + " ge-add-container ge-add-feature" }), label, iconClass);
|
|
1549
|
+
var acting = typeof item.action === "function";
|
|
1549
1550
|
addClass(button, item.className || "");
|
|
1550
1551
|
if (typeof item.hidden === "function" ? item.hidden() : item.hidden) {
|
|
1551
1552
|
hide(button);
|
|
@@ -1555,7 +1556,20 @@
|
|
|
1555
1556
|
"data-ge-feature": name,
|
|
1556
1557
|
"data-ge-item": index
|
|
1557
1558
|
});
|
|
1559
|
+
if (acting) {
|
|
1560
|
+
button.setAttribute("data-ge-action", "");
|
|
1561
|
+
if (typeof item.disabled === "function" ? item.disabled() : item.disabled) {
|
|
1562
|
+
addClass(button, "disabled");
|
|
1563
|
+
button.setAttribute("aria-disabled", "true");
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1558
1566
|
button.addEventListener("click", function() {
|
|
1567
|
+
if (acting) {
|
|
1568
|
+
if (!hasClass(button, "disabled")) {
|
|
1569
|
+
item.action(button);
|
|
1570
|
+
}
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1559
1573
|
if (activeTarget) {
|
|
1560
1574
|
addToTarget(button, item.source || "tool");
|
|
1561
1575
|
return;
|
|
@@ -1581,7 +1595,7 @@
|
|
|
1581
1595
|
return !!settings.toolbar_drag;
|
|
1582
1596
|
}
|
|
1583
1597
|
function makeToolbarDraggable() {
|
|
1584
|
-
var buttons = all(mainControls, "[data-ge-toolbar]");
|
|
1598
|
+
var buttons = all(mainControls, "[data-ge-toolbar]:not([data-ge-action])");
|
|
1585
1599
|
buttons.forEach(function(button) {
|
|
1586
1600
|
removeClass(button, "ge-palette-button");
|
|
1587
1601
|
button.removeEventListener("pointerdown", startToolbarDrag);
|
|
@@ -2357,6 +2371,23 @@
|
|
|
2357
2371
|
getActiveTarget: function() {
|
|
2358
2372
|
return settings.active_target ? activeTarget : null;
|
|
2359
2373
|
},
|
|
2374
|
+
// True when it took: a node that cannot be, or no setting
|
|
2375
|
+
// for it, says nothing, since a plugin putting back what it
|
|
2376
|
+
// remembers cannot know the node is still one
|
|
2377
|
+
setSelected: function(node) {
|
|
2378
|
+
var chosen = panelMode() === "sidebar" && !!node && node !== canvas && canvas.contains(node) && detailsFor.has(node);
|
|
2379
|
+
if (chosen) {
|
|
2380
|
+
changeSelection(node);
|
|
2381
|
+
}
|
|
2382
|
+
return chosen;
|
|
2383
|
+
},
|
|
2384
|
+
setActiveTarget: function(node) {
|
|
2385
|
+
var chosen = !!settings.active_target && isTarget(node);
|
|
2386
|
+
if (chosen) {
|
|
2387
|
+
changeTarget(node);
|
|
2388
|
+
}
|
|
2389
|
+
return chosen;
|
|
2390
|
+
},
|
|
2360
2391
|
// What keeps Escape from the selection and the target, and an
|
|
2361
2392
|
// inline panel unfolded in a drawer, which Escape leaves alone
|
|
2362
2393
|
panelOpen: function() {
|
|
@@ -5149,7 +5180,7 @@
|
|
|
5149
5180
|
GridEditor._plainHtml = plainHtml;
|
|
5150
5181
|
GridEditor.Sortable = null;
|
|
5151
5182
|
GridEditor.bootstrap = null;
|
|
5152
|
-
GridEditor.version = false ? "dev" : "9.0.0-beta.
|
|
5183
|
+
GridEditor.version = false ? "dev" : "9.0.0-beta.3";
|
|
5153
5184
|
GridEditor.locales = {
|
|
5154
5185
|
en: {
|
|
5155
5186
|
"tool.move": "Move",
|