labellife-design-tool 2.5.7 → 2.7.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/README.md +42 -0
- package/dist/cjs/canvas/workspace.js +265 -9
- package/dist/cjs/canvas/workspace.js.map +1 -1
- package/dist/cjs/config.js +215 -0
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/index.js +947 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/store.js +854 -7
- package/dist/cjs/model/store.js.map +1 -1
- package/dist/cjs/side-panel/index.js +173 -0
- package/dist/cjs/side-panel/index.js.map +1 -1
- package/dist/cjs/side-panel/side-panel.js +173 -0
- package/dist/cjs/side-panel/side-panel.js.map +1 -1
- package/dist/cjs/toolbar/toolbar.js +173 -0
- package/dist/cjs/toolbar/toolbar.js.map +1 -1
- package/dist/esm/canvas/workspace.js +265 -9
- package/dist/esm/canvas/workspace.js.map +1 -1
- package/dist/esm/config.js +214 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/index.js +946 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/store.js +854 -7
- package/dist/esm/model/store.js.map +1 -1
- package/dist/esm/side-panel/index.js +173 -0
- package/dist/esm/side-panel/index.js.map +1 -1
- package/dist/esm/side-panel/side-panel.js +173 -0
- package/dist/esm/side-panel/side-panel.js.map +1 -1
- package/dist/esm/toolbar/toolbar.js +173 -0
- package/dist/esm/toolbar/toolbar.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/model/store.js
CHANGED
|
@@ -42,6 +42,20 @@ function _asyncToGenerator(n) {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
function _classCallCheck(a, n) {
|
|
46
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
47
|
+
}
|
|
48
|
+
function _defineProperties(e, r) {
|
|
49
|
+
for (var t = 0; t < r.length; t++) {
|
|
50
|
+
var o = r[t];
|
|
51
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function _createClass(e, r, t) {
|
|
55
|
+
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
56
|
+
writable: false
|
|
57
|
+
}), e;
|
|
58
|
+
}
|
|
45
59
|
function _createForOfIteratorHelper(r, e) {
|
|
46
60
|
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
47
61
|
if (!t) {
|
|
@@ -112,7 +126,10 @@ function _iterableToArrayLimit(r, l) {
|
|
|
112
126
|
f = true,
|
|
113
127
|
o = false;
|
|
114
128
|
try {
|
|
115
|
-
if (i = (t = t.call(r)).next, 0 === l)
|
|
129
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
130
|
+
if (Object(t) !== t) return;
|
|
131
|
+
f = !1;
|
|
132
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
116
133
|
} catch (r) {
|
|
117
134
|
o = true, n = r;
|
|
118
135
|
} finally {
|
|
@@ -886,6 +903,22 @@ var TextElement = Shape.named('TextElement').props({
|
|
|
886
903
|
return {
|
|
887
904
|
toggleEditMode: function toggleEditMode(editing) {
|
|
888
905
|
self._editModeEnabled = editing !== undefined ? editing : !self._editModeEnabled;
|
|
906
|
+
},
|
|
907
|
+
// Ends an inline text edit. The canvas editor writes the text on every keystroke
|
|
908
|
+
// without recording a history state, so the finished edit is committed here (once,
|
|
909
|
+
// and only when the text really changed). That makes it undoable and lets the
|
|
910
|
+
// activity log see it.
|
|
911
|
+
finishEdit: function finishEdit(_ref) {
|
|
912
|
+
var text = _ref.text,
|
|
913
|
+
originalText = _ref.originalText;
|
|
914
|
+
self.text = text;
|
|
915
|
+
self._editModeEnabled = false;
|
|
916
|
+
if (text === originalText) return;
|
|
917
|
+
try {
|
|
918
|
+
mobxStateTree.getRoot(self).history.addUndoState();
|
|
919
|
+
} catch (e) {
|
|
920
|
+
console.warn('Text edit: failed to record history state', e);
|
|
921
|
+
}
|
|
889
922
|
}
|
|
890
923
|
};
|
|
891
924
|
});
|
|
@@ -1451,10 +1484,20 @@ var History = mobxStateTree.types.model('History', {
|
|
|
1451
1484
|
self.history.splice(0, self.history.length - 100);
|
|
1452
1485
|
self.undoIdx = self.history.length - 1;
|
|
1453
1486
|
}
|
|
1487
|
+
self._notifyActivity('onCommit', stateToSave);
|
|
1454
1488
|
} catch (e) {
|
|
1455
1489
|
console.warn('History: failed to save state', e);
|
|
1456
1490
|
}
|
|
1457
1491
|
},
|
|
1492
|
+
// Feeds the plain-English activity log; it must never break editing.
|
|
1493
|
+
_notifyActivity: function _notifyActivity(method, snapshot) {
|
|
1494
|
+
try {
|
|
1495
|
+
var tracker = mobxStateTree.getRoot(self)._activity;
|
|
1496
|
+
if (tracker) tracker[method](snapshot);
|
|
1497
|
+
} catch (e) {
|
|
1498
|
+
console.warn('Activity log: failed to update', e);
|
|
1499
|
+
}
|
|
1500
|
+
},
|
|
1458
1501
|
_restoreState: function _restoreState(state) {
|
|
1459
1502
|
if (!state) return;
|
|
1460
1503
|
self._ignoring = true;
|
|
@@ -1513,11 +1556,13 @@ var History = mobxStateTree.types.model('History', {
|
|
|
1513
1556
|
if (!self.canUndo) return;
|
|
1514
1557
|
self.undoIdx -= 1;
|
|
1515
1558
|
self._restoreState(self.history[self.undoIdx]);
|
|
1559
|
+
self._notifyActivity('undone', self.history[self.undoIdx]);
|
|
1516
1560
|
},
|
|
1517
1561
|
redo: function redo() {
|
|
1518
1562
|
if (!self.canRedo) return;
|
|
1519
1563
|
self.undoIdx += 1;
|
|
1520
1564
|
self._restoreState(self.history[self.undoIdx]);
|
|
1565
|
+
self._notifyActivity('redone', self.history[self.undoIdx]);
|
|
1521
1566
|
},
|
|
1522
1567
|
clear: function clear() {
|
|
1523
1568
|
self.history.clear();
|
|
@@ -1612,6 +1657,742 @@ function buildFontFaceCss(customFont) {
|
|
|
1612
1657
|
}).join('\n');
|
|
1613
1658
|
}
|
|
1614
1659
|
|
|
1660
|
+
// src/model/activity-log.js
|
|
1661
|
+
//
|
|
1662
|
+
// Turns what the user does into plain English sentences. Pure functions on
|
|
1663
|
+
// plain snapshot objects: no MST, no React, so it runs under plain node tests.
|
|
1664
|
+
// Never writes image data or URLs into a sentence.
|
|
1665
|
+
|
|
1666
|
+
var DEFAULT_OPTIONS = {
|
|
1667
|
+
includeTextContent: true,
|
|
1668
|
+
maxTextLength: 40,
|
|
1669
|
+
maxEntries: 300,
|
|
1670
|
+
maxSentenceLength: 200,
|
|
1671
|
+
mergeWindowMs: 1500
|
|
1672
|
+
};
|
|
1673
|
+
function clip(text, max) {
|
|
1674
|
+
var s = String(text == null ? '' : text);
|
|
1675
|
+
return s.length > max ? "".concat(s.slice(0, max), "\u2026") : s;
|
|
1676
|
+
}
|
|
1677
|
+
function imageSource(src) {
|
|
1678
|
+
var s = String(src || '');
|
|
1679
|
+
if (s.startsWith('data:') || s.startsWith('blob:')) return 'uploaded';
|
|
1680
|
+
if (s.toLowerCase().includes('unsplash')) return 'stock photo';
|
|
1681
|
+
return '';
|
|
1682
|
+
}
|
|
1683
|
+
function describeElement(el) {
|
|
1684
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
|
|
1685
|
+
var type = el && el.type;
|
|
1686
|
+
switch (type) {
|
|
1687
|
+
case 'text':
|
|
1688
|
+
{
|
|
1689
|
+
var text = el.text == null ? '' : String(el.text);
|
|
1690
|
+
if (!opts.includeTextContent || !text) return 'the text';
|
|
1691
|
+
return "the text \"".concat(clip(text, opts.maxTextLength), "\"");
|
|
1692
|
+
}
|
|
1693
|
+
case 'image':
|
|
1694
|
+
return 'the image';
|
|
1695
|
+
case 'figure':
|
|
1696
|
+
return el.subType ? "the shape (".concat(el.subType, ")") : 'the shape';
|
|
1697
|
+
case 'line':
|
|
1698
|
+
return 'the line';
|
|
1699
|
+
case 'group':
|
|
1700
|
+
return 'the group';
|
|
1701
|
+
case 'svg':
|
|
1702
|
+
return 'the graphic';
|
|
1703
|
+
default:
|
|
1704
|
+
return 'the element';
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// ── Start, final and popup sentences ────────────────────────────────
|
|
1709
|
+
|
|
1710
|
+
var MAX_LISTED_TEXTS = 5;
|
|
1711
|
+
var HIDDEN_VALUE = '(value hidden)';
|
|
1712
|
+
function walk(children, fn) {
|
|
1713
|
+
(children || []).forEach(function (child) {
|
|
1714
|
+
if (!child) return;
|
|
1715
|
+
fn(child);
|
|
1716
|
+
if (child.children) walk(child.children, fn);
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
function allElements(snapshot) {
|
|
1720
|
+
var out = [];
|
|
1721
|
+
(snapshot && snapshot.pages || []).forEach(function (page) {
|
|
1722
|
+
return walk(page && page.children, function (el) {
|
|
1723
|
+
return out.push(el);
|
|
1724
|
+
});
|
|
1725
|
+
});
|
|
1726
|
+
return out;
|
|
1727
|
+
}
|
|
1728
|
+
var num = function num(n) {
|
|
1729
|
+
return String(Number.isFinite(+n) ? +(+n).toFixed(2) : n);
|
|
1730
|
+
};
|
|
1731
|
+
function describeSize(snapshot) {
|
|
1732
|
+
var s = snapshot || {};
|
|
1733
|
+
return "".concat(num(s.width), " x ").concat(num(s.height), " ").concat(s.unit || 'px');
|
|
1734
|
+
}
|
|
1735
|
+
var plural = function plural(n, word) {
|
|
1736
|
+
return "".concat(n, " ").concat(word).concat(n === 1 ? '' : 's');
|
|
1737
|
+
};
|
|
1738
|
+
var COUNTED = [['text', 'text'], ['image', 'image'], ['figure', 'shape'], ['line', 'line'], ['svg', 'graphic']];
|
|
1739
|
+
function countParts(elements) {
|
|
1740
|
+
return COUNTED.map(function (_ref) {
|
|
1741
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
1742
|
+
type = _ref2[0],
|
|
1743
|
+
word = _ref2[1];
|
|
1744
|
+
return [elements.filter(function (e) {
|
|
1745
|
+
return e.type === type;
|
|
1746
|
+
}).length, word];
|
|
1747
|
+
}).filter(function (_ref3) {
|
|
1748
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
1749
|
+
n = _ref4[0];
|
|
1750
|
+
return n > 0;
|
|
1751
|
+
}).map(function (_ref5) {
|
|
1752
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
1753
|
+
n = _ref6[0],
|
|
1754
|
+
word = _ref6[1];
|
|
1755
|
+
return plural(n, word);
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
function joinWithAnd(parts) {
|
|
1759
|
+
if (parts.length <= 1) return parts.join('');
|
|
1760
|
+
return "".concat(parts.slice(0, -1).join(', '), " and ").concat(parts[parts.length - 1]);
|
|
1761
|
+
}
|
|
1762
|
+
function variableName(el) {
|
|
1763
|
+
var custom = el && el.custom || {};
|
|
1764
|
+
return custom.variableName || custom.promptText || 'the field';
|
|
1765
|
+
}
|
|
1766
|
+
function describeStart(snapshot) {
|
|
1767
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
|
|
1768
|
+
var elements = allElements(snapshot);
|
|
1769
|
+
var size = describeSize(snapshot);
|
|
1770
|
+
if (elements.length === 0) return ["Started from a blank label, ".concat(size, ".")];
|
|
1771
|
+
var parts = countParts(elements);
|
|
1772
|
+
var texts = elements.filter(function (e) {
|
|
1773
|
+
return e.type === 'text' && e.text;
|
|
1774
|
+
});
|
|
1775
|
+
if (opts.includeTextContent && texts.length && parts[0].endsWith(texts.length === 1 ? ' text' : ' texts')) {
|
|
1776
|
+
var listed = texts.slice(0, MAX_LISTED_TEXTS).map(function (e) {
|
|
1777
|
+
return "\"".concat(clip(e.text, opts.maxTextLength), "\"");
|
|
1778
|
+
}).join(', ');
|
|
1779
|
+
parts[0] = "".concat(parts[0], " (").concat(listed, ")");
|
|
1780
|
+
}
|
|
1781
|
+
var pages = (snapshot && snapshot.pages || []).length || 1;
|
|
1782
|
+
var sentences = ["Started from a template, ".concat(size, ", ").concat(plural(pages, 'page'), ", with ").concat(joinWithAnd(parts), ".")];
|
|
1783
|
+
var vars = elements.filter(function (e) {
|
|
1784
|
+
return e.custom && e.custom.inputField;
|
|
1785
|
+
});
|
|
1786
|
+
if (vars.length) {
|
|
1787
|
+
var named = vars.map(function (e) {
|
|
1788
|
+
return "\"".concat(variableName(e), "\" (").concat(e.custom.inputType || 'text', ")");
|
|
1789
|
+
}).join(', ');
|
|
1790
|
+
sentences.push("The template asked for ".concat(plural(vars.length, 'variable'), ": ").concat(named, "."));
|
|
1791
|
+
}
|
|
1792
|
+
return sentences;
|
|
1793
|
+
}
|
|
1794
|
+
function describeFinal(snapshot) {
|
|
1795
|
+
var parts = countParts(allElements(snapshot));
|
|
1796
|
+
return "Final label: ".concat([].concat(_toConsumableArray(parts.length ? parts : ['empty']), [describeSize(snapshot)]).join(', '), ".");
|
|
1797
|
+
}
|
|
1798
|
+
function describePopup() {
|
|
1799
|
+
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1800
|
+
action = _ref7.action,
|
|
1801
|
+
field = _ref7.field,
|
|
1802
|
+
value = _ref7.value;
|
|
1803
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
|
|
1804
|
+
if (action === 'finish') return 'User finished the variable questions.';
|
|
1805
|
+
var custom = field && field.custom || {};
|
|
1806
|
+
var name = variableName(field);
|
|
1807
|
+
var shown = function shown(v) {
|
|
1808
|
+
return opts.includeTextContent ? clip(v, opts.maxTextLength) : HIDDEN_VALUE;
|
|
1809
|
+
};
|
|
1810
|
+
switch (action) {
|
|
1811
|
+
case 'skip':
|
|
1812
|
+
return custom.removeIfSkipped ? "User skipped variable \"".concat(name, "\"; the element was removed from the label.") : "User skipped variable \"".concat(name, "\".");
|
|
1813
|
+
case 'back':
|
|
1814
|
+
return "User went back to change variable \"".concat(name, "\".");
|
|
1815
|
+
case 'submit':
|
|
1816
|
+
break;
|
|
1817
|
+
default:
|
|
1818
|
+
return "User answered variable \"".concat(name, "\".");
|
|
1819
|
+
}
|
|
1820
|
+
switch (custom.inputType) {
|
|
1821
|
+
case 'radio':
|
|
1822
|
+
{
|
|
1823
|
+
var isOption = Array.isArray(custom.options) && custom.options.includes(value);
|
|
1824
|
+
return isOption ? "User chose \"".concat(shown(value), "\" for variable \"").concat(name, "\".") : "User typed their own answer \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
|
|
1825
|
+
}
|
|
1826
|
+
case 'list':
|
|
1827
|
+
{
|
|
1828
|
+
var picked = String(value == null ? '' : value).split(', ').filter(Boolean).map(function (v) {
|
|
1829
|
+
return "\"".concat(shown(v), "\"");
|
|
1830
|
+
}).join(', ');
|
|
1831
|
+
return "User selected ".concat(picked, " for variable \"").concat(name, "\".");
|
|
1832
|
+
}
|
|
1833
|
+
case 'date':
|
|
1834
|
+
return "User picked the date \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
|
|
1835
|
+
case 'integer':
|
|
1836
|
+
return "User entered the number ".concat(shown(value), " for variable \"").concat(name, "\".");
|
|
1837
|
+
case 'image':
|
|
1838
|
+
return "User uploaded an image for variable \"".concat(name, "\".");
|
|
1839
|
+
default:
|
|
1840
|
+
return "User entered \"".concat(shown(value), "\" for variable \"").concat(name, "\".");
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// ── Diff: snapshot → sentences ──────────────────────────────────────
|
|
1845
|
+
|
|
1846
|
+
var words = function words(prop) {
|
|
1847
|
+
return String(prop).replace(/([A-Z])/g, ' $1').toLowerCase().trim();
|
|
1848
|
+
};
|
|
1849
|
+
var _short = function _short(v) {
|
|
1850
|
+
var s = String(v == null ? '' : v);
|
|
1851
|
+
return "".concat(s.length, ":").concat(s.slice(0, 40));
|
|
1852
|
+
};
|
|
1853
|
+
var isLocked = function isLocked(el) {
|
|
1854
|
+
return el.draggable === false && el.resizable === false && el.contentEditable === false && el.styleEditable === false;
|
|
1855
|
+
};
|
|
1856
|
+
var quotedText = function quotedText(el, n, opts) {
|
|
1857
|
+
return opts.includeTextContent && el.text ? "\"".concat(clip(el.text, opts.maxTextLength), "\"") : n;
|
|
1858
|
+
};
|
|
1859
|
+
|
|
1860
|
+
// One row per property group: how to read its value, and how to word the change.
|
|
1861
|
+
// A new property is one new row. `render(ctx)` returns (from, to) => sentence so a
|
|
1862
|
+
// merged entry can be re-worded with its first `from` and last `to`.
|
|
1863
|
+
var ROWS = [{
|
|
1864
|
+
key: 'text',
|
|
1865
|
+
props: ['text'],
|
|
1866
|
+
render: function render(_ref8) {
|
|
1867
|
+
var opts = _ref8.opts;
|
|
1868
|
+
return function (f, t) {
|
|
1869
|
+
return opts.includeTextContent ? "Changed the text \"".concat(clip(f, opts.maxTextLength), "\" to \"").concat(clip(t, opts.maxTextLength), "\".") : 'Changed the text.';
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
}, {
|
|
1873
|
+
key: 'fontFamily',
|
|
1874
|
+
props: ['fontFamily'],
|
|
1875
|
+
render: function render(_ref9) {
|
|
1876
|
+
var n = _ref9.n;
|
|
1877
|
+
return function (f, t) {
|
|
1878
|
+
return "Changed the font of ".concat(n, " to ").concat(t, ".");
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
}, {
|
|
1882
|
+
key: 'fontSize',
|
|
1883
|
+
props: ['fontSize'],
|
|
1884
|
+
render: function render(_ref0) {
|
|
1885
|
+
var n = _ref0.n;
|
|
1886
|
+
return function (f, t) {
|
|
1887
|
+
return "Changed the font size of ".concat(n, " from ").concat(f, " to ").concat(t, ".");
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
}, {
|
|
1891
|
+
key: 'fill',
|
|
1892
|
+
props: ['fill'],
|
|
1893
|
+
render: function render(_ref1) {
|
|
1894
|
+
var n = _ref1.n;
|
|
1895
|
+
return function (f, t) {
|
|
1896
|
+
return "Changed the colour of ".concat(n, " to ").concat(t, ".");
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
}, {
|
|
1900
|
+
key: 'position',
|
|
1901
|
+
props: ['x', 'y'],
|
|
1902
|
+
render: function render(_ref10) {
|
|
1903
|
+
var n = _ref10.n;
|
|
1904
|
+
return function () {
|
|
1905
|
+
return "Moved ".concat(n, ".");
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
}, {
|
|
1909
|
+
key: 'size',
|
|
1910
|
+
props: ['width', 'height'],
|
|
1911
|
+
render: function render(_ref11) {
|
|
1912
|
+
var n = _ref11.n;
|
|
1913
|
+
return function () {
|
|
1914
|
+
return "Resized ".concat(n, ".");
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
}, {
|
|
1918
|
+
key: 'rotation',
|
|
1919
|
+
props: ['rotation'],
|
|
1920
|
+
render: function render(_ref12) {
|
|
1921
|
+
var n = _ref12.n;
|
|
1922
|
+
return function (f, t) {
|
|
1923
|
+
return "Rotated ".concat(n, " to ").concat(t, " degrees.");
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
}, {
|
|
1927
|
+
key: 'visible',
|
|
1928
|
+
props: ['visible'],
|
|
1929
|
+
render: function render(_ref13) {
|
|
1930
|
+
var n = _ref13.n;
|
|
1931
|
+
return function (f, t) {
|
|
1932
|
+
return t ? "Showed ".concat(n, ".") : "Hid ".concat(n, ".");
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
}, {
|
|
1936
|
+
key: 'lock',
|
|
1937
|
+
props: ['draggable', 'resizable', 'contentEditable', 'styleEditable'],
|
|
1938
|
+
value: isLocked,
|
|
1939
|
+
render: function render(_ref14) {
|
|
1940
|
+
var n = _ref14.n;
|
|
1941
|
+
return function (f, t) {
|
|
1942
|
+
return t ? "Locked ".concat(n, ".") : "Unlocked ".concat(n, ".");
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
}, {
|
|
1946
|
+
key: 'crop',
|
|
1947
|
+
props: ['cropX', 'cropY', 'cropWidth', 'cropHeight'],
|
|
1948
|
+
render: function render(_ref15) {
|
|
1949
|
+
var n = _ref15.n;
|
|
1950
|
+
return function () {
|
|
1951
|
+
return "Cropped ".concat(n, ".");
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
}, {
|
|
1955
|
+
key: 'clipSrc',
|
|
1956
|
+
props: ['clipSrc'],
|
|
1957
|
+
render: function render(_ref16) {
|
|
1958
|
+
var n = _ref16.n;
|
|
1959
|
+
return function (f, t) {
|
|
1960
|
+
return t ? "Applied a mask to ".concat(n, ".") : "Removed the mask from ".concat(n, ".");
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
}, {
|
|
1964
|
+
key: 'curveEnabled',
|
|
1965
|
+
props: ['curveEnabled'],
|
|
1966
|
+
render: function render(_ref17) {
|
|
1967
|
+
var n = _ref17.n,
|
|
1968
|
+
next = _ref17.next,
|
|
1969
|
+
opts = _ref17.opts;
|
|
1970
|
+
return function (f, t) {
|
|
1971
|
+
return t ? "Applied curved text to ".concat(quotedText(next, n, opts), ".") : "Removed the curve from ".concat(n, ".");
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
}, {
|
|
1975
|
+
key: 'shadowEnabled',
|
|
1976
|
+
props: ['shadowEnabled'],
|
|
1977
|
+
render: function render(_ref18) {
|
|
1978
|
+
var n = _ref18.n;
|
|
1979
|
+
return function (f, t) {
|
|
1980
|
+
return t ? "Added a shadow to ".concat(n, ".") : "Removed the shadow from ".concat(n, ".");
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
}, {
|
|
1984
|
+
key: 'grayscaleEnabled',
|
|
1985
|
+
props: ['grayscaleEnabled'],
|
|
1986
|
+
render: function render(_ref19) {
|
|
1987
|
+
var n = _ref19.n;
|
|
1988
|
+
return function (f, t) {
|
|
1989
|
+
return t ? "Made ".concat(n, " grayscale.") : "Removed the grayscale from ".concat(n, ".");
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
}, {
|
|
1993
|
+
key: 'src',
|
|
1994
|
+
props: ['src'],
|
|
1995
|
+
value: function value(el) {
|
|
1996
|
+
return _short(el.src);
|
|
1997
|
+
},
|
|
1998
|
+
render: function render(_ref20) {
|
|
1999
|
+
var n = _ref20.n,
|
|
2000
|
+
next = _ref20.next;
|
|
2001
|
+
return function () {
|
|
2002
|
+
var source = imageSource(next.src);
|
|
2003
|
+
var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
|
|
2004
|
+
return "Replaced ".concat(n).concat(note, ".");
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
}];
|
|
2008
|
+
var HANDLED = new Set(['id', 'type', 'custom', 'children'].concat(_toConsumableArray(ROWS.flatMap(function (r) {
|
|
2009
|
+
return r.props;
|
|
2010
|
+
}))));
|
|
2011
|
+
function rowValue(row, el) {
|
|
2012
|
+
if (row.value) return row.value(el);
|
|
2013
|
+
return row.props.length === 1 ? el[row.props[0]] : row.props.map(function (p) {
|
|
2014
|
+
return el[p];
|
|
2015
|
+
}).join(',');
|
|
2016
|
+
}
|
|
2017
|
+
function indexSnapshot(snapshot) {
|
|
2018
|
+
var pages = new Map();
|
|
2019
|
+
var elements = new Map();
|
|
2020
|
+
var orders = new Map();
|
|
2021
|
+
(snapshot && snapshot.pages || []).forEach(function (page) {
|
|
2022
|
+
if (!page) return;
|
|
2023
|
+
pages.set(page.id, page);
|
|
2024
|
+
var _visit = function visit(children, parentId) {
|
|
2025
|
+
orders.set(parentId, (children || []).filter(Boolean).map(function (c) {
|
|
2026
|
+
return c.id;
|
|
2027
|
+
}));
|
|
2028
|
+
(children || []).forEach(function (child) {
|
|
2029
|
+
if (!child) return;
|
|
2030
|
+
elements.set(child.id, {
|
|
2031
|
+
el: child,
|
|
2032
|
+
parentId: parentId
|
|
2033
|
+
});
|
|
2034
|
+
if (child.children) _visit(child.children, child.id);
|
|
2035
|
+
});
|
|
2036
|
+
};
|
|
2037
|
+
_visit(page.children, page.id);
|
|
2038
|
+
});
|
|
2039
|
+
return {
|
|
2040
|
+
pages: pages,
|
|
2041
|
+
elements: elements,
|
|
2042
|
+
orders: orders
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
function indefinite(el, opts) {
|
|
2046
|
+
switch (el.type) {
|
|
2047
|
+
case 'text':
|
|
2048
|
+
return opts.includeTextContent && el.text ? "a text \"".concat(clip(el.text, opts.maxTextLength), "\"") : 'a text';
|
|
2049
|
+
case 'image':
|
|
2050
|
+
{
|
|
2051
|
+
var source = imageSource(el.src);
|
|
2052
|
+
var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
|
|
2053
|
+
return "an image".concat(note);
|
|
2054
|
+
}
|
|
2055
|
+
case 'figure':
|
|
2056
|
+
return el.subType ? "a shape (".concat(el.subType, ")") : 'a shape';
|
|
2057
|
+
case 'line':
|
|
2058
|
+
return 'a line';
|
|
2059
|
+
case 'group':
|
|
2060
|
+
return 'a group';
|
|
2061
|
+
case 'svg':
|
|
2062
|
+
return 'a graphic';
|
|
2063
|
+
default:
|
|
2064
|
+
return 'an element';
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
var BACKGROUND_IMAGE = /^(https?:|data:|blob:|url\()/;
|
|
2068
|
+
function diffToEntries(prev, next) {
|
|
2069
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS;
|
|
2070
|
+
if (!prev || !next) return [];
|
|
2071
|
+
var a = indexSnapshot(prev);
|
|
2072
|
+
var b = indexSnapshot(next);
|
|
2073
|
+
var out = [];
|
|
2074
|
+
|
|
2075
|
+
// Label size
|
|
2076
|
+
var sizeFrom = describeSize(prev);
|
|
2077
|
+
var sizeTo = describeSize(next);
|
|
2078
|
+
if (sizeFrom !== sizeTo) {
|
|
2079
|
+
out.push({
|
|
2080
|
+
key: 'label:size',
|
|
2081
|
+
from: sizeFrom,
|
|
2082
|
+
to: sizeTo,
|
|
2083
|
+
render: function render(f, t) {
|
|
2084
|
+
return "Changed the label size from ".concat(f, " to ").concat(t, ".");
|
|
2085
|
+
},
|
|
2086
|
+
sentence: "Changed the label size from ".concat(sizeFrom, " to ").concat(sizeTo, ".")
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// Pages
|
|
2091
|
+
var addedPages = new Set(_toConsumableArray(b.pages.keys()).filter(function (id) {
|
|
2092
|
+
return !a.pages.has(id);
|
|
2093
|
+
}));
|
|
2094
|
+
var removedPages = new Set(_toConsumableArray(a.pages.keys()).filter(function (id) {
|
|
2095
|
+
return !b.pages.has(id);
|
|
2096
|
+
}));
|
|
2097
|
+
addedPages.forEach(function (id) {
|
|
2098
|
+
return out.push({
|
|
2099
|
+
key: "".concat(id, ":added"),
|
|
2100
|
+
sentence: 'Added a page.'
|
|
2101
|
+
});
|
|
2102
|
+
});
|
|
2103
|
+
removedPages.forEach(function (id) {
|
|
2104
|
+
return out.push({
|
|
2105
|
+
key: "".concat(id, ":removed"),
|
|
2106
|
+
sentence: 'Removed a page.'
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
2109
|
+
|
|
2110
|
+
// Added and removed elements (only the top of an added/removed subtree)
|
|
2111
|
+
var added = new Set(_toConsumableArray(b.elements.keys()).filter(function (id) {
|
|
2112
|
+
return !a.elements.has(id);
|
|
2113
|
+
}));
|
|
2114
|
+
var removed = new Set(_toConsumableArray(a.elements.keys()).filter(function (id) {
|
|
2115
|
+
return !b.elements.has(id);
|
|
2116
|
+
}));
|
|
2117
|
+
added.forEach(function (id) {
|
|
2118
|
+
var _b$elements$get = b.elements.get(id),
|
|
2119
|
+
el = _b$elements$get.el,
|
|
2120
|
+
parentId = _b$elements$get.parentId;
|
|
2121
|
+
if (added.has(parentId) || addedPages.has(parentId)) return;
|
|
2122
|
+
out.push({
|
|
2123
|
+
key: "".concat(id, ":added"),
|
|
2124
|
+
sentence: "Added ".concat(indefinite(el, opts), ".")
|
|
2125
|
+
});
|
|
2126
|
+
});
|
|
2127
|
+
removed.forEach(function (id) {
|
|
2128
|
+
var _a$elements$get = a.elements.get(id),
|
|
2129
|
+
el = _a$elements$get.el,
|
|
2130
|
+
parentId = _a$elements$get.parentId;
|
|
2131
|
+
if (removed.has(parentId) || removedPages.has(parentId)) return;
|
|
2132
|
+
out.push({
|
|
2133
|
+
key: "".concat(id, ":removed"),
|
|
2134
|
+
sentence: "Removed ".concat(describeElement(el, opts), ".")
|
|
2135
|
+
});
|
|
2136
|
+
});
|
|
2137
|
+
|
|
2138
|
+
// Changed elements
|
|
2139
|
+
b.elements.forEach(function (_ref21, id) {
|
|
2140
|
+
var nextEl = _ref21.el;
|
|
2141
|
+
var before = a.elements.get(id);
|
|
2142
|
+
if (!before) return;
|
|
2143
|
+
var prevEl = before.el;
|
|
2144
|
+
var ctx = {
|
|
2145
|
+
n: describeElement(nextEl, opts),
|
|
2146
|
+
prev: prevEl,
|
|
2147
|
+
next: nextEl,
|
|
2148
|
+
opts: opts
|
|
2149
|
+
};
|
|
2150
|
+
ROWS.forEach(function (row) {
|
|
2151
|
+
var from = rowValue(row, prevEl);
|
|
2152
|
+
var to = rowValue(row, nextEl);
|
|
2153
|
+
if (from === to || from === undefined && to === undefined) return;
|
|
2154
|
+
var render = row.render(ctx);
|
|
2155
|
+
out.push({
|
|
2156
|
+
key: "".concat(id, ":").concat(row.key),
|
|
2157
|
+
from: from,
|
|
2158
|
+
to: to,
|
|
2159
|
+
render: render,
|
|
2160
|
+
sentence: render(from, to)
|
|
2161
|
+
});
|
|
2162
|
+
});
|
|
2163
|
+
var props = new Set([].concat(_toConsumableArray(Object.keys(prevEl)), _toConsumableArray(Object.keys(nextEl))));
|
|
2164
|
+
props.forEach(function (prop) {
|
|
2165
|
+
if (HANDLED.has(prop)) return;
|
|
2166
|
+
var from = JSON.stringify(prevEl[prop]);
|
|
2167
|
+
var to = JSON.stringify(nextEl[prop]);
|
|
2168
|
+
if (from === to) return;
|
|
2169
|
+
out.push({
|
|
2170
|
+
key: "".concat(id, ":").concat(prop),
|
|
2171
|
+
from: from,
|
|
2172
|
+
to: to,
|
|
2173
|
+
sentence: "Changed the ".concat(words(prop), " of ").concat(ctx.n, ".")
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
// Layer order within each parent, for elements present before and after
|
|
2179
|
+
b.orders.forEach(function (nextIds, parentId) {
|
|
2180
|
+
var prevIds = a.orders.get(parentId);
|
|
2181
|
+
if (!prevIds) return;
|
|
2182
|
+
var common = new Set(nextIds.filter(function (id) {
|
|
2183
|
+
return prevIds.includes(id);
|
|
2184
|
+
}));
|
|
2185
|
+
var pOrder = prevIds.filter(function (id) {
|
|
2186
|
+
return common.has(id);
|
|
2187
|
+
});
|
|
2188
|
+
var nOrder = nextIds.filter(function (id) {
|
|
2189
|
+
return common.has(id);
|
|
2190
|
+
});
|
|
2191
|
+
if (pOrder.join('|') === nOrder.join('|')) return;
|
|
2192
|
+
var mover = nOrder.find(function (c) {
|
|
2193
|
+
var p = pOrder.filter(function (id) {
|
|
2194
|
+
return id !== c;
|
|
2195
|
+
}).join('|');
|
|
2196
|
+
var n = nOrder.filter(function (id) {
|
|
2197
|
+
return id !== c;
|
|
2198
|
+
}).join('|');
|
|
2199
|
+
return p === n;
|
|
2200
|
+
});
|
|
2201
|
+
if (!mover) {
|
|
2202
|
+
out.push({
|
|
2203
|
+
key: "".concat(parentId, ":order"),
|
|
2204
|
+
sentence: 'Changed the layer order.'
|
|
2205
|
+
});
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
var name = describeElement(b.elements.get(mover).el, opts);
|
|
2209
|
+
var pos = nOrder.indexOf(mover);
|
|
2210
|
+
var sentence = pos === nOrder.length - 1 ? "Brought ".concat(name, " to the front.") : pos === 0 ? "Sent ".concat(name, " to the back.") : "Changed the layer order of ".concat(name, ".");
|
|
2211
|
+
out.push({
|
|
2212
|
+
key: "".concat(mover, ":order"),
|
|
2213
|
+
sentence: sentence
|
|
2214
|
+
});
|
|
2215
|
+
});
|
|
2216
|
+
|
|
2217
|
+
// Page background
|
|
2218
|
+
b.pages.forEach(function (page, id) {
|
|
2219
|
+
var before = a.pages.get(id);
|
|
2220
|
+
if (!before) return;
|
|
2221
|
+
var from = before.background || '';
|
|
2222
|
+
var to = page.background || '';
|
|
2223
|
+
if (from === to) return;
|
|
2224
|
+
var sentence = !to ? 'Removed the background.' : BACKGROUND_IMAGE.test(to) ? 'Set an image as the background.' : "Changed the background colour to ".concat(to, ".");
|
|
2225
|
+
out.push({
|
|
2226
|
+
key: "".concat(id, ":background"),
|
|
2227
|
+
sentence: sentence
|
|
2228
|
+
});
|
|
2229
|
+
});
|
|
2230
|
+
return out;
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
// ── Tracker: keeps the log, merges quick repeats, caps the size ─────
|
|
2234
|
+
|
|
2235
|
+
var ActivityTracker = /*#__PURE__*/function () {
|
|
2236
|
+
function ActivityTracker() {
|
|
2237
|
+
var getOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
|
|
2238
|
+
return DEFAULT_OPTIONS;
|
|
2239
|
+
};
|
|
2240
|
+
var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now;
|
|
2241
|
+
_classCallCheck(this, ActivityTracker);
|
|
2242
|
+
this._getOptions = getOptions;
|
|
2243
|
+
this._now = now;
|
|
2244
|
+
this.clear();
|
|
2245
|
+
}
|
|
2246
|
+
return _createClass(ActivityTracker, [{
|
|
2247
|
+
key: "_opts",
|
|
2248
|
+
get: function get() {
|
|
2249
|
+
return _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), this._getOptions() || {});
|
|
2250
|
+
}
|
|
2251
|
+
}, {
|
|
2252
|
+
key: "clear",
|
|
2253
|
+
value: function clear() {
|
|
2254
|
+
this._start = [];
|
|
2255
|
+
this._actions = [];
|
|
2256
|
+
this._dropped = false;
|
|
2257
|
+
this._baseline = null;
|
|
2258
|
+
}
|
|
2259
|
+
}, {
|
|
2260
|
+
key: "reset",
|
|
2261
|
+
value: function reset(snapshot) {
|
|
2262
|
+
var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
2263
|
+
this.clear();
|
|
2264
|
+
if (!snapshot) return;
|
|
2265
|
+
this._baseline = snapshot;
|
|
2266
|
+
this._start = [].concat(_toConsumableArray(describeStart(snapshot, this._opts)), _toConsumableArray(extra));
|
|
2267
|
+
}
|
|
2268
|
+
}, {
|
|
2269
|
+
key: "rebaseline",
|
|
2270
|
+
value: function rebaseline(snapshot) {
|
|
2271
|
+
if (snapshot) this._baseline = snapshot;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
// The canvas sometimes rewrites an element by itself (e.g. re-measuring a text's height once a
|
|
2275
|
+
// font has loaded). That is not something the user did, so fold it into the baseline for just
|
|
2276
|
+
// that element: the next commit then won't report it, and the user's own pending changes stay.
|
|
2277
|
+
}, {
|
|
2278
|
+
key: "patchBaseline",
|
|
2279
|
+
value: function patchBaseline(id, attrs) {
|
|
2280
|
+
if (!id || !this._baseline) return;
|
|
2281
|
+
var _patch = function patch(children) {
|
|
2282
|
+
return (children || []).map(function (child) {
|
|
2283
|
+
if (!child) return child;
|
|
2284
|
+
if (child.id === id) return _objectSpread2(_objectSpread2({}, child), attrs);
|
|
2285
|
+
return child.children ? _objectSpread2(_objectSpread2({}, child), {}, {
|
|
2286
|
+
children: _patch(child.children)
|
|
2287
|
+
}) : child;
|
|
2288
|
+
});
|
|
2289
|
+
};
|
|
2290
|
+
this._baseline = _objectSpread2(_objectSpread2({}, this._baseline), {}, {
|
|
2291
|
+
pages: (this._baseline.pages || []).map(function (page) {
|
|
2292
|
+
return page ? _objectSpread2(_objectSpread2({}, page), {}, {
|
|
2293
|
+
children: _patch(page.children)
|
|
2294
|
+
}) : page;
|
|
2295
|
+
})
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
}, {
|
|
2299
|
+
key: "onCommit",
|
|
2300
|
+
value: function onCommit(snapshot) {
|
|
2301
|
+
var _this = this;
|
|
2302
|
+
if (!snapshot) return;
|
|
2303
|
+
var previous = this._baseline;
|
|
2304
|
+
this._baseline = snapshot;
|
|
2305
|
+
if (!previous) return;
|
|
2306
|
+
diffToEntries(previous, snapshot, this._opts).forEach(function (entry) {
|
|
2307
|
+
return _this._add(entry);
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
}, {
|
|
2311
|
+
key: "record",
|
|
2312
|
+
value: function record(sentence, key) {
|
|
2313
|
+
this._add({
|
|
2314
|
+
key: key,
|
|
2315
|
+
sentence: String(sentence)
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
}, {
|
|
2319
|
+
key: "undone",
|
|
2320
|
+
value: function undone(snapshot) {
|
|
2321
|
+
this._add({
|
|
2322
|
+
sentence: 'Undid the last change.'
|
|
2323
|
+
});
|
|
2324
|
+
this.rebaseline(snapshot);
|
|
2325
|
+
}
|
|
2326
|
+
}, {
|
|
2327
|
+
key: "redone",
|
|
2328
|
+
value: function redone(snapshot) {
|
|
2329
|
+
this._add({
|
|
2330
|
+
sentence: 'Redid the last change.'
|
|
2331
|
+
});
|
|
2332
|
+
this.rebaseline(snapshot);
|
|
2333
|
+
}
|
|
2334
|
+
}, {
|
|
2335
|
+
key: "getLog",
|
|
2336
|
+
value: function getLog(finalSnapshot) {
|
|
2337
|
+
var maxSentenceLength = this._opts.maxSentenceLength;
|
|
2338
|
+
var lines = _toConsumableArray(this._start);
|
|
2339
|
+
if (this._dropped) lines.push('Earlier actions were left out.');
|
|
2340
|
+
this._actions.forEach(function (a) {
|
|
2341
|
+
return lines.push(a.sentence);
|
|
2342
|
+
});
|
|
2343
|
+
if (finalSnapshot) lines.push(describeFinal(finalSnapshot));
|
|
2344
|
+
return lines.map(function (line) {
|
|
2345
|
+
return clip(line, maxSentenceLength);
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
}, {
|
|
2349
|
+
key: "_add",
|
|
2350
|
+
value: function _add(entry) {
|
|
2351
|
+
var at = this._now();
|
|
2352
|
+
var last = this._actions[this._actions.length - 1];
|
|
2353
|
+
var _this$_opts = this._opts,
|
|
2354
|
+
mergeWindowMs = _this$_opts.mergeWindowMs,
|
|
2355
|
+
maxEntries = _this$_opts.maxEntries;
|
|
2356
|
+
if (entry.key && last && last.key === entry.key && at - last.at <= mergeWindowMs) {
|
|
2357
|
+
if (entry.render && last.render) {
|
|
2358
|
+
if (last.from === entry.to) {
|
|
2359
|
+
this._actions.pop();
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
this._actions[this._actions.length - 1] = _objectSpread2(_objectSpread2({}, entry), {}, {
|
|
2363
|
+
from: last.from,
|
|
2364
|
+
at: at,
|
|
2365
|
+
sentence: entry.render(last.from, entry.to)
|
|
2366
|
+
});
|
|
2367
|
+
} else {
|
|
2368
|
+
this._actions[this._actions.length - 1] = _objectSpread2(_objectSpread2({}, entry), {}, {
|
|
2369
|
+
at: at
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
this._actions.push(_objectSpread2(_objectSpread2({}, entry), {}, {
|
|
2375
|
+
at: at
|
|
2376
|
+
}));
|
|
2377
|
+
if (this._actions.length > maxEntries) {
|
|
2378
|
+
this._actions.shift();
|
|
2379
|
+
this._dropped = true;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
}]);
|
|
2383
|
+
}();
|
|
2384
|
+
|
|
2385
|
+
// ── Options singleton ───────────────────────────────────────────────
|
|
2386
|
+
// Window-level, like the other config: each Rollup output bundle gets its own
|
|
2387
|
+
// copy of this module, so a closure variable set from one would never be seen
|
|
2388
|
+
// by another.
|
|
2389
|
+
|
|
2390
|
+
var OPTIONS_KEY = '__labellife_activity_log_options__';
|
|
2391
|
+
function getActivityLogOptions() {
|
|
2392
|
+
var set = typeof window !== 'undefined' && window[OPTIONS_KEY] || {};
|
|
2393
|
+
return _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), set);
|
|
2394
|
+
}
|
|
2395
|
+
|
|
1615
2396
|
var _excluded = ["mimeType", "quality", "dpi", "dpiMetadata"],
|
|
1616
2397
|
_excluded2 = ["mimeType", "quality"],
|
|
1617
2398
|
_excluded3 = ["fileName"],
|
|
@@ -1728,7 +2509,9 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1728
2509
|
// incremented after each font load to trigger canvas re-render
|
|
1729
2510
|
_pendingInputFields: [],
|
|
1730
2511
|
// elements awaiting user input after loadJSON
|
|
1731
|
-
customFonts: []
|
|
2512
|
+
customFonts: [],
|
|
2513
|
+
// host-injected custom font catalog: [{ name, variants: [{weight,style,file}] }]
|
|
2514
|
+
_activity: new ActivityTracker(getActivityLogOptions) // plain-English log of what the user did
|
|
1732
2515
|
};
|
|
1733
2516
|
}).views(function (self) {
|
|
1734
2517
|
return {
|
|
@@ -1889,6 +2672,8 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1889
2672
|
if (self.pages.length > 0 && !self._activePageId) {
|
|
1890
2673
|
self._activePageId = self.pages[0].id;
|
|
1891
2674
|
}
|
|
2675
|
+
// A store that never loads a template still needs a baseline for the activity log.
|
|
2676
|
+
self._resetActivity();
|
|
1892
2677
|
},
|
|
1893
2678
|
set: function set(attrs) {
|
|
1894
2679
|
for (var _i2 = 0, _Object$entries2 = Object.entries(attrs); _i2 < _Object$entries2.length; _i2++) {
|
|
@@ -2549,6 +3334,7 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2549
3334
|
self.history.clear();
|
|
2550
3335
|
self.history.addUndoState();
|
|
2551
3336
|
}
|
|
3337
|
+
self._resetActivity();
|
|
2552
3338
|
|
|
2553
3339
|
// Auto-load fonts referenced in text elements
|
|
2554
3340
|
self._autoLoadFonts(data);
|
|
@@ -2573,6 +3359,67 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2573
3359
|
self.history.clear();
|
|
2574
3360
|
self.history.addUndoState();
|
|
2575
3361
|
}
|
|
3362
|
+
self._resetActivity();
|
|
3363
|
+
},
|
|
3364
|
+
// ── Activity log: plain-English record of what the user did ─────
|
|
3365
|
+
_activitySnapshot: function _activitySnapshot() {
|
|
3366
|
+
var snapshot = _objectSpread2({}, mobxStateTree.getSnapshot(self));
|
|
3367
|
+
delete snapshot.history;
|
|
3368
|
+
return snapshot;
|
|
3369
|
+
},
|
|
3370
|
+
_resetActivity: function _resetActivity() {
|
|
3371
|
+
try {
|
|
3372
|
+
self._activity.reset(self._activitySnapshot());
|
|
3373
|
+
} catch (e) {
|
|
3374
|
+
console.warn('Activity log: failed to reset', e);
|
|
3375
|
+
}
|
|
3376
|
+
},
|
|
3377
|
+
getActivityLog: function getActivityLog() {
|
|
3378
|
+
try {
|
|
3379
|
+
return self._activity.getLog(self._activitySnapshot());
|
|
3380
|
+
} catch (e) {
|
|
3381
|
+
console.warn('Activity log: failed to read', e);
|
|
3382
|
+
return [];
|
|
3383
|
+
}
|
|
3384
|
+
},
|
|
3385
|
+
recordActivity: function recordActivity(sentence) {
|
|
3386
|
+
try {
|
|
3387
|
+
self._activity.record(sentence);
|
|
3388
|
+
} catch (e) {
|
|
3389
|
+
console.warn('Activity log: failed to record', e);
|
|
3390
|
+
}
|
|
3391
|
+
},
|
|
3392
|
+
// For changes the canvas makes by itself (not the user): keeps them out of the log.
|
|
3393
|
+
syncActivityBaseline: function syncActivityBaseline(id, attrs) {
|
|
3394
|
+
try {
|
|
3395
|
+
self._activity.patchBaseline(id, attrs);
|
|
3396
|
+
} catch (e) {
|
|
3397
|
+
console.warn('Activity log: failed to sync baseline', e);
|
|
3398
|
+
}
|
|
3399
|
+
},
|
|
3400
|
+
clearActivityLog: function clearActivityLog() {
|
|
3401
|
+
// Keep the baseline at the current state so the next change is still logged.
|
|
3402
|
+
self._activity.clear();
|
|
3403
|
+
self._activity.rebaseline(self._activitySnapshot());
|
|
3404
|
+
},
|
|
3405
|
+
// Called by the input-fields popup. Logs the answer, then re-baselines so the
|
|
3406
|
+
// change it wrote into the element is not logged a second time.
|
|
3407
|
+
logPopupAnswer: function logPopupAnswer() {
|
|
3408
|
+
var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
3409
|
+
action = _ref11.action,
|
|
3410
|
+
field = _ref11.field,
|
|
3411
|
+
value = _ref11.value;
|
|
3412
|
+
try {
|
|
3413
|
+
// 'finish' can arrive twice (answer handler and a host dialog's onComplete): key it so it merges.
|
|
3414
|
+
self._activity.record(describePopup({
|
|
3415
|
+
action: action,
|
|
3416
|
+
field: field,
|
|
3417
|
+
value: value
|
|
3418
|
+
}, getActivityLogOptions()), action === 'finish' ? 'popup:finish' : undefined);
|
|
3419
|
+
self._activity.rebaseline(self._activitySnapshot());
|
|
3420
|
+
} catch (e) {
|
|
3421
|
+
console.warn('Activity log: failed to record popup answer', e);
|
|
3422
|
+
}
|
|
2576
3423
|
},
|
|
2577
3424
|
addFont: function addFont(font) {
|
|
2578
3425
|
var existing = self.fonts.find(function (f) {
|
|
@@ -2797,11 +3644,11 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2797
3644
|
};
|
|
2798
3645
|
});
|
|
2799
3646
|
function createStore() {
|
|
2800
|
-
var
|
|
2801
|
-
|
|
2802
|
-
key =
|
|
2803
|
-
|
|
2804
|
-
showCredit =
|
|
3647
|
+
var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
3648
|
+
_ref12$key = _ref12.key,
|
|
3649
|
+
key = _ref12$key === void 0 ? '' : _ref12$key,
|
|
3650
|
+
_ref12$showCredit = _ref12.showCredit,
|
|
3651
|
+
showCredit = _ref12$showCredit === void 0 ? false : _ref12$showCredit;
|
|
2805
3652
|
var store = Store.create({});
|
|
2806
3653
|
store._initConfig(key, showCredit);
|
|
2807
3654
|
return store;
|