labellife-design-tool 2.5.8 → 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.
@@ -5,6 +5,7 @@ import { Box, Typography, IconButton, Button, TextField, FormGroup, FormControlL
5
5
  import CloseIcon from '@mui/icons-material/Close';
6
6
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
7
7
  import Konva from 'konva';
8
+ import { getSnapshot } from 'mobx-state-tree';
8
9
  import CloudUploadIcon from '@mui/icons-material/CloudUpload';
9
10
  import ArrowBackIcon from '@mui/icons-material/ArrowBack';
10
11
 
@@ -201,6 +202,179 @@ function t(key, defaultValue) {
201
202
  return defaultValue || key;
202
203
  }
203
204
 
205
+ function clip(text, max) {
206
+ var s = String(text == null ? '' : text);
207
+ return s.length > max ? "".concat(s.slice(0, max), "\u2026") : s;
208
+ }
209
+ function imageSource(src) {
210
+ var s = String(src || '');
211
+ if (s.startsWith('data:') || s.startsWith('blob:')) return 'uploaded';
212
+ if (s.toLowerCase().includes('unsplash')) return 'stock photo';
213
+ return '';
214
+ }
215
+ var _short = function _short(v) {
216
+ var s = String(v == null ? '' : v);
217
+ return "".concat(s.length, ":").concat(s.slice(0, 40));
218
+ };
219
+ var isLocked = function isLocked(el) {
220
+ return el.draggable === false && el.resizable === false && el.contentEditable === false && el.styleEditable === false;
221
+ };
222
+ var quotedText = function quotedText(el, n, opts) {
223
+ return opts.includeTextContent && el.text ? "\"".concat(clip(el.text, opts.maxTextLength), "\"") : n;
224
+ };
225
+
226
+ // One row per property group: how to read its value, and how to word the change.
227
+ // A new property is one new row. `render(ctx)` returns (from, to) => sentence so a
228
+ // merged entry can be re-worded with its first `from` and last `to`.
229
+ var ROWS = [{
230
+ key: 'text',
231
+ props: ['text'],
232
+ render: function render(_ref8) {
233
+ var opts = _ref8.opts;
234
+ return function (f, t) {
235
+ return opts.includeTextContent ? "Changed the text \"".concat(clip(f, opts.maxTextLength), "\" to \"").concat(clip(t, opts.maxTextLength), "\".") : 'Changed the text.';
236
+ };
237
+ }
238
+ }, {
239
+ key: 'fontFamily',
240
+ props: ['fontFamily'],
241
+ render: function render(_ref9) {
242
+ var n = _ref9.n;
243
+ return function (f, t) {
244
+ return "Changed the font of ".concat(n, " to ").concat(t, ".");
245
+ };
246
+ }
247
+ }, {
248
+ key: 'fontSize',
249
+ props: ['fontSize'],
250
+ render: function render(_ref0) {
251
+ var n = _ref0.n;
252
+ return function (f, t) {
253
+ return "Changed the font size of ".concat(n, " from ").concat(f, " to ").concat(t, ".");
254
+ };
255
+ }
256
+ }, {
257
+ key: 'fill',
258
+ props: ['fill'],
259
+ render: function render(_ref1) {
260
+ var n = _ref1.n;
261
+ return function (f, t) {
262
+ return "Changed the colour of ".concat(n, " to ").concat(t, ".");
263
+ };
264
+ }
265
+ }, {
266
+ key: 'position',
267
+ props: ['x', 'y'],
268
+ render: function render(_ref10) {
269
+ var n = _ref10.n;
270
+ return function () {
271
+ return "Moved ".concat(n, ".");
272
+ };
273
+ }
274
+ }, {
275
+ key: 'size',
276
+ props: ['width', 'height'],
277
+ render: function render(_ref11) {
278
+ var n = _ref11.n;
279
+ return function () {
280
+ return "Resized ".concat(n, ".");
281
+ };
282
+ }
283
+ }, {
284
+ key: 'rotation',
285
+ props: ['rotation'],
286
+ render: function render(_ref12) {
287
+ var n = _ref12.n;
288
+ return function (f, t) {
289
+ return "Rotated ".concat(n, " to ").concat(t, " degrees.");
290
+ };
291
+ }
292
+ }, {
293
+ key: 'visible',
294
+ props: ['visible'],
295
+ render: function render(_ref13) {
296
+ var n = _ref13.n;
297
+ return function (f, t) {
298
+ return t ? "Showed ".concat(n, ".") : "Hid ".concat(n, ".");
299
+ };
300
+ }
301
+ }, {
302
+ key: 'lock',
303
+ props: ['draggable', 'resizable', 'contentEditable', 'styleEditable'],
304
+ value: isLocked,
305
+ render: function render(_ref14) {
306
+ var n = _ref14.n;
307
+ return function (f, t) {
308
+ return t ? "Locked ".concat(n, ".") : "Unlocked ".concat(n, ".");
309
+ };
310
+ }
311
+ }, {
312
+ key: 'crop',
313
+ props: ['cropX', 'cropY', 'cropWidth', 'cropHeight'],
314
+ render: function render(_ref15) {
315
+ var n = _ref15.n;
316
+ return function () {
317
+ return "Cropped ".concat(n, ".");
318
+ };
319
+ }
320
+ }, {
321
+ key: 'clipSrc',
322
+ props: ['clipSrc'],
323
+ render: function render(_ref16) {
324
+ var n = _ref16.n;
325
+ return function (f, t) {
326
+ return t ? "Applied a mask to ".concat(n, ".") : "Removed the mask from ".concat(n, ".");
327
+ };
328
+ }
329
+ }, {
330
+ key: 'curveEnabled',
331
+ props: ['curveEnabled'],
332
+ render: function render(_ref17) {
333
+ var n = _ref17.n,
334
+ next = _ref17.next,
335
+ opts = _ref17.opts;
336
+ return function (f, t) {
337
+ return t ? "Applied curved text to ".concat(quotedText(next, n, opts), ".") : "Removed the curve from ".concat(n, ".");
338
+ };
339
+ }
340
+ }, {
341
+ key: 'shadowEnabled',
342
+ props: ['shadowEnabled'],
343
+ render: function render(_ref18) {
344
+ var n = _ref18.n;
345
+ return function (f, t) {
346
+ return t ? "Added a shadow to ".concat(n, ".") : "Removed the shadow from ".concat(n, ".");
347
+ };
348
+ }
349
+ }, {
350
+ key: 'grayscaleEnabled',
351
+ props: ['grayscaleEnabled'],
352
+ render: function render(_ref19) {
353
+ var n = _ref19.n;
354
+ return function (f, t) {
355
+ return t ? "Made ".concat(n, " grayscale.") : "Removed the grayscale from ".concat(n, ".");
356
+ };
357
+ }
358
+ }, {
359
+ key: 'src',
360
+ props: ['src'],
361
+ value: function value(el) {
362
+ return _short(el.src);
363
+ },
364
+ render: function render(_ref20) {
365
+ var n = _ref20.n,
366
+ next = _ref20.next;
367
+ return function () {
368
+ var source = imageSource(next.src);
369
+ var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
370
+ return "Replaced ".concat(n).concat(note, ".");
371
+ };
372
+ }
373
+ }];
374
+ new Set(['id', 'type', 'custom', 'children'].concat(_toConsumableArray(ROWS.flatMap(function (r) {
375
+ return r.props;
376
+ }))));
377
+
204
378
  // ── Input Fields Dialog Config ───────────────────────────────────────
205
379
  var INPUT_FIELDS_CONFIG_KEY = '__labellife_input_fields_config__';
206
380
  if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
@@ -1245,10 +1419,15 @@ function computeCurvedCacheBounds(element) {
1245
1419
  function syncHeightKeepingCenter(element, newHeight) {
1246
1420
  if (Math.abs(newHeight - element.height) <= 1) return;
1247
1421
  var deltaY = (newHeight - element.height) / 2;
1248
- element.set({
1422
+ var attrs = {
1249
1423
  height: newHeight,
1250
1424
  y: element.y - deltaY
1251
- });
1425
+ };
1426
+ element.set(attrs);
1427
+ // An automatic re-layout, not a user action: keep it out of the activity log.
1428
+ if (element.store && element.store.syncActivityBaseline) {
1429
+ element.store.syncActivityBaseline(element.id, attrs);
1430
+ }
1252
1431
  }
1253
1432
 
1254
1433
  // Safari doesn't make a webfont available to canvas (not even to measureText) until some
@@ -1607,10 +1786,10 @@ var TextElementComponent = observer(function (_ref) {
1607
1786
  var cancel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1608
1787
  if (removed) return;
1609
1788
  removed = true;
1610
- element.set({
1611
- text: cancel ? originalText : textarea.value
1789
+ element.finishEdit({
1790
+ text: cancel ? originalText : textarea.value,
1791
+ originalText: originalText
1612
1792
  });
1613
- element.toggleEditMode(false);
1614
1793
  if (textareaRef.current === textarea) textareaRef.current = null;
1615
1794
  if (textarea.parentNode) {
1616
1795
  textarea.parentNode.removeChild(textarea);
@@ -2910,6 +3089,17 @@ var InputFieldsDialog = observer(function (_ref2) {
2910
3089
  var config = getInputFieldsConfig();
2911
3090
  var pendingFields = store._pendingInputFields || [];
2912
3091
 
3092
+ // Plain-English activity log (see model/activity-log.js). Called after the
3093
+ // element has been updated so the log can re-baseline past that change.
3094
+ var logAnswer = function logAnswer(action, el, value) {
3095
+ if (typeof store.logPopupAnswer !== 'function') return;
3096
+ store.logPopupAnswer({
3097
+ action: action,
3098
+ field: el ? getSnapshot(el) : undefined,
3099
+ value: value
3100
+ });
3101
+ };
3102
+
2913
3103
  // When disabled, clear any pending fields so they are treated as skipped
2914
3104
  useEffect(function () {
2915
3105
  if (!enabled && pendingFields.length > 0) {
@@ -2965,6 +3155,7 @@ var InputFieldsDialog = observer(function (_ref2) {
2965
3155
  text: previousValue || ''
2966
3156
  });
2967
3157
  }
3158
+ logAnswer('back', el);
2968
3159
  isGoingBackRef.current = true;
2969
3160
  store._unresolveInputField(el);
2970
3161
  }
@@ -3012,9 +3203,11 @@ var InputFieldsDialog = observer(function (_ref2) {
3012
3203
  });
3013
3204
  }
3014
3205
  }
3206
+ logAnswer('submit', el, value);
3015
3207
  store._resolveInputField(elementId);
3016
3208
  if (fields.length <= 1) {
3017
3209
  _flushRemovedElements();
3210
+ logAnswer('finish');
3018
3211
  store.history.addUndoState();
3019
3212
  if (_onComplete) _onComplete();
3020
3213
  } else {
@@ -3040,10 +3233,12 @@ var InputFieldsDialog = observer(function (_ref2) {
3040
3233
  skipped: true,
3041
3234
  removed: shouldRemove
3042
3235
  });
3236
+ logAnswer('skip', el);
3043
3237
  store._resolveInputField(elementId);
3044
3238
  if (fields.length <= 1) {
3045
3239
  var hadRemovals = removedDueToSkipRef.current.length > 0;
3046
3240
  _flushRemovedElements();
3241
+ logAnswer('finish');
3047
3242
  if (hadRemovals) store.history.addUndoState();
3048
3243
  if (_onComplete) _onComplete();
3049
3244
  } else {
@@ -3074,6 +3269,7 @@ var InputFieldsDialog = observer(function (_ref2) {
3074
3269
  text: previousValue || ''
3075
3270
  });
3076
3271
  }
3272
+ logAnswer('back', el);
3077
3273
  store._unresolveInputField(el);
3078
3274
  }
3079
3275
  setDisplayIndex(function (prev) {
@@ -3108,6 +3304,7 @@ var InputFieldsDialog = observer(function (_ref2) {
3108
3304
  canGoBack: canGoBack,
3109
3305
  onComplete: function onComplete() {
3110
3306
  _flushRemovedElements();
3307
+ logAnswer('finish');
3111
3308
  store.history.addUndoState();
3112
3309
  if (_onComplete) _onComplete();
3113
3310
  }