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.
- package/README.md +42 -0
- package/dist/cjs/canvas/workspace.js +202 -5
- 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 +884 -11
- 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 +202 -5
- 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 +883 -12
- 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/README.md
CHANGED
|
@@ -259,6 +259,48 @@ const dispose = store.on('change', (data) => {
|
|
|
259
259
|
dispose(); // Remove listener
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
+
### Activity Log
|
|
263
|
+
|
|
264
|
+
The store keeps a plain-English record of what the user did, one sentence per
|
|
265
|
+
meaningful action, for analytics. It never contains image data or image URLs.
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
store.getActivityLog();
|
|
269
|
+
// [
|
|
270
|
+
// 'Started from a template, 50 x 30 mm, 1 page, with 2 texts ("Happy Birthday", "Name"), 1 image.',
|
|
271
|
+
// 'The template asked for 1 variable: "First Name" (text).',
|
|
272
|
+
// 'Selected template "Birthday Card".', // added by the host via recordActivity
|
|
273
|
+
// 'User entered "Anna" for variable "First Name".',
|
|
274
|
+
// 'Added a text "Welcome".',
|
|
275
|
+
// 'Changed the font size of the text "Welcome" from 20 to 32.',
|
|
276
|
+
// 'Added an image (uploaded by the user).',
|
|
277
|
+
// 'Final label: 3 texts, 2 images, 50 x 30 mm.',
|
|
278
|
+
// ]
|
|
279
|
+
|
|
280
|
+
store.recordActivity('Selected template "Birthday Card".'); // host adds its own sentence
|
|
281
|
+
store.clearActivityLog();
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
- Each committed change (the same moments the undo history records) becomes one sentence. Quick repeats on the
|
|
285
|
+
same element and property within 1.5 s merge into one sentence, and a change that returns to where it started
|
|
286
|
+
disappears.
|
|
287
|
+
- `loadJSON()` and `store.clear()` start a new log. Undo and redo add `Undid the last change.` / `Redid the last change.`
|
|
288
|
+
- Input-field popup answers are logged for the built-in dialogs and for host-supplied ones, e.g.
|
|
289
|
+
`User chose "Option A" for variable "Size".`, `User skipped variable "Photo".`
|
|
290
|
+
- Sentences are always English (not translated) and the log only lives in memory.
|
|
291
|
+
|
|
292
|
+
Options (call once at startup; typed text can contain personal data, so you can turn it off):
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
import { setActivityLogOptions } from 'labellife-design-tool';
|
|
296
|
+
|
|
297
|
+
setActivityLogOptions({
|
|
298
|
+
includeTextContent: true, // false: texts and answers are replaced by "(value hidden)" / left out
|
|
299
|
+
maxTextLength: 40, // longer texts are cut with an ellipsis
|
|
300
|
+
maxEntries: 300, // oldest actions are dropped beyond this
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
262
304
|
### Font Management
|
|
263
305
|
|
|
264
306
|
```js
|
|
@@ -9,6 +9,7 @@ var material = require('@mui/material');
|
|
|
9
9
|
var CloseIcon = require('@mui/icons-material/Close');
|
|
10
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
11
|
var Konva = require('konva');
|
|
12
|
+
var mobxStateTree = require('mobx-state-tree');
|
|
12
13
|
var CloudUploadIcon = require('@mui/icons-material/CloudUpload');
|
|
13
14
|
var ArrowBackIcon = require('@mui/icons-material/ArrowBack');
|
|
14
15
|
|
|
@@ -205,6 +206,179 @@ function t(key, defaultValue) {
|
|
|
205
206
|
return defaultValue || key;
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
function clip(text, max) {
|
|
210
|
+
var s = String(text == null ? '' : text);
|
|
211
|
+
return s.length > max ? "".concat(s.slice(0, max), "\u2026") : s;
|
|
212
|
+
}
|
|
213
|
+
function imageSource(src) {
|
|
214
|
+
var s = String(src || '');
|
|
215
|
+
if (s.startsWith('data:') || s.startsWith('blob:')) return 'uploaded';
|
|
216
|
+
if (s.toLowerCase().includes('unsplash')) return 'stock photo';
|
|
217
|
+
return '';
|
|
218
|
+
}
|
|
219
|
+
var _short = function _short(v) {
|
|
220
|
+
var s = String(v == null ? '' : v);
|
|
221
|
+
return "".concat(s.length, ":").concat(s.slice(0, 40));
|
|
222
|
+
};
|
|
223
|
+
var isLocked = function isLocked(el) {
|
|
224
|
+
return el.draggable === false && el.resizable === false && el.contentEditable === false && el.styleEditable === false;
|
|
225
|
+
};
|
|
226
|
+
var quotedText = function quotedText(el, n, opts) {
|
|
227
|
+
return opts.includeTextContent && el.text ? "\"".concat(clip(el.text, opts.maxTextLength), "\"") : n;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// One row per property group: how to read its value, and how to word the change.
|
|
231
|
+
// A new property is one new row. `render(ctx)` returns (from, to) => sentence so a
|
|
232
|
+
// merged entry can be re-worded with its first `from` and last `to`.
|
|
233
|
+
var ROWS = [{
|
|
234
|
+
key: 'text',
|
|
235
|
+
props: ['text'],
|
|
236
|
+
render: function render(_ref8) {
|
|
237
|
+
var opts = _ref8.opts;
|
|
238
|
+
return function (f, t) {
|
|
239
|
+
return opts.includeTextContent ? "Changed the text \"".concat(clip(f, opts.maxTextLength), "\" to \"").concat(clip(t, opts.maxTextLength), "\".") : 'Changed the text.';
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: 'fontFamily',
|
|
244
|
+
props: ['fontFamily'],
|
|
245
|
+
render: function render(_ref9) {
|
|
246
|
+
var n = _ref9.n;
|
|
247
|
+
return function (f, t) {
|
|
248
|
+
return "Changed the font of ".concat(n, " to ").concat(t, ".");
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}, {
|
|
252
|
+
key: 'fontSize',
|
|
253
|
+
props: ['fontSize'],
|
|
254
|
+
render: function render(_ref0) {
|
|
255
|
+
var n = _ref0.n;
|
|
256
|
+
return function (f, t) {
|
|
257
|
+
return "Changed the font size of ".concat(n, " from ").concat(f, " to ").concat(t, ".");
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}, {
|
|
261
|
+
key: 'fill',
|
|
262
|
+
props: ['fill'],
|
|
263
|
+
render: function render(_ref1) {
|
|
264
|
+
var n = _ref1.n;
|
|
265
|
+
return function (f, t) {
|
|
266
|
+
return "Changed the colour of ".concat(n, " to ").concat(t, ".");
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}, {
|
|
270
|
+
key: 'position',
|
|
271
|
+
props: ['x', 'y'],
|
|
272
|
+
render: function render(_ref10) {
|
|
273
|
+
var n = _ref10.n;
|
|
274
|
+
return function () {
|
|
275
|
+
return "Moved ".concat(n, ".");
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}, {
|
|
279
|
+
key: 'size',
|
|
280
|
+
props: ['width', 'height'],
|
|
281
|
+
render: function render(_ref11) {
|
|
282
|
+
var n = _ref11.n;
|
|
283
|
+
return function () {
|
|
284
|
+
return "Resized ".concat(n, ".");
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}, {
|
|
288
|
+
key: 'rotation',
|
|
289
|
+
props: ['rotation'],
|
|
290
|
+
render: function render(_ref12) {
|
|
291
|
+
var n = _ref12.n;
|
|
292
|
+
return function (f, t) {
|
|
293
|
+
return "Rotated ".concat(n, " to ").concat(t, " degrees.");
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: 'visible',
|
|
298
|
+
props: ['visible'],
|
|
299
|
+
render: function render(_ref13) {
|
|
300
|
+
var n = _ref13.n;
|
|
301
|
+
return function (f, t) {
|
|
302
|
+
return t ? "Showed ".concat(n, ".") : "Hid ".concat(n, ".");
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}, {
|
|
306
|
+
key: 'lock',
|
|
307
|
+
props: ['draggable', 'resizable', 'contentEditable', 'styleEditable'],
|
|
308
|
+
value: isLocked,
|
|
309
|
+
render: function render(_ref14) {
|
|
310
|
+
var n = _ref14.n;
|
|
311
|
+
return function (f, t) {
|
|
312
|
+
return t ? "Locked ".concat(n, ".") : "Unlocked ".concat(n, ".");
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}, {
|
|
316
|
+
key: 'crop',
|
|
317
|
+
props: ['cropX', 'cropY', 'cropWidth', 'cropHeight'],
|
|
318
|
+
render: function render(_ref15) {
|
|
319
|
+
var n = _ref15.n;
|
|
320
|
+
return function () {
|
|
321
|
+
return "Cropped ".concat(n, ".");
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}, {
|
|
325
|
+
key: 'clipSrc',
|
|
326
|
+
props: ['clipSrc'],
|
|
327
|
+
render: function render(_ref16) {
|
|
328
|
+
var n = _ref16.n;
|
|
329
|
+
return function (f, t) {
|
|
330
|
+
return t ? "Applied a mask to ".concat(n, ".") : "Removed the mask from ".concat(n, ".");
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}, {
|
|
334
|
+
key: 'curveEnabled',
|
|
335
|
+
props: ['curveEnabled'],
|
|
336
|
+
render: function render(_ref17) {
|
|
337
|
+
var n = _ref17.n,
|
|
338
|
+
next = _ref17.next,
|
|
339
|
+
opts = _ref17.opts;
|
|
340
|
+
return function (f, t) {
|
|
341
|
+
return t ? "Applied curved text to ".concat(quotedText(next, n, opts), ".") : "Removed the curve from ".concat(n, ".");
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
key: 'shadowEnabled',
|
|
346
|
+
props: ['shadowEnabled'],
|
|
347
|
+
render: function render(_ref18) {
|
|
348
|
+
var n = _ref18.n;
|
|
349
|
+
return function (f, t) {
|
|
350
|
+
return t ? "Added a shadow to ".concat(n, ".") : "Removed the shadow from ".concat(n, ".");
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: 'grayscaleEnabled',
|
|
355
|
+
props: ['grayscaleEnabled'],
|
|
356
|
+
render: function render(_ref19) {
|
|
357
|
+
var n = _ref19.n;
|
|
358
|
+
return function (f, t) {
|
|
359
|
+
return t ? "Made ".concat(n, " grayscale.") : "Removed the grayscale from ".concat(n, ".");
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}, {
|
|
363
|
+
key: 'src',
|
|
364
|
+
props: ['src'],
|
|
365
|
+
value: function value(el) {
|
|
366
|
+
return _short(el.src);
|
|
367
|
+
},
|
|
368
|
+
render: function render(_ref20) {
|
|
369
|
+
var n = _ref20.n,
|
|
370
|
+
next = _ref20.next;
|
|
371
|
+
return function () {
|
|
372
|
+
var source = imageSource(next.src);
|
|
373
|
+
var note = source === 'uploaded' ? ' (uploaded by the user)' : source ? " (".concat(source, ")") : '';
|
|
374
|
+
return "Replaced ".concat(n).concat(note, ".");
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}];
|
|
378
|
+
new Set(['id', 'type', 'custom', 'children'].concat(_toConsumableArray(ROWS.flatMap(function (r) {
|
|
379
|
+
return r.props;
|
|
380
|
+
}))));
|
|
381
|
+
|
|
208
382
|
// ── Input Fields Dialog Config ───────────────────────────────────────
|
|
209
383
|
var INPUT_FIELDS_CONFIG_KEY = '__labellife_input_fields_config__';
|
|
210
384
|
if (typeof window !== 'undefined' && !window[INPUT_FIELDS_CONFIG_KEY]) {
|
|
@@ -1249,10 +1423,15 @@ function computeCurvedCacheBounds(element) {
|
|
|
1249
1423
|
function syncHeightKeepingCenter(element, newHeight) {
|
|
1250
1424
|
if (Math.abs(newHeight - element.height) <= 1) return;
|
|
1251
1425
|
var deltaY = (newHeight - element.height) / 2;
|
|
1252
|
-
|
|
1426
|
+
var attrs = {
|
|
1253
1427
|
height: newHeight,
|
|
1254
1428
|
y: element.y - deltaY
|
|
1255
|
-
}
|
|
1429
|
+
};
|
|
1430
|
+
element.set(attrs);
|
|
1431
|
+
// An automatic re-layout, not a user action: keep it out of the activity log.
|
|
1432
|
+
if (element.store && element.store.syncActivityBaseline) {
|
|
1433
|
+
element.store.syncActivityBaseline(element.id, attrs);
|
|
1434
|
+
}
|
|
1256
1435
|
}
|
|
1257
1436
|
|
|
1258
1437
|
// Safari doesn't make a webfont available to canvas (not even to measureText) until some
|
|
@@ -1611,10 +1790,10 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
1611
1790
|
var cancel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1612
1791
|
if (removed) return;
|
|
1613
1792
|
removed = true;
|
|
1614
|
-
element.
|
|
1615
|
-
text: cancel ? originalText : textarea.value
|
|
1793
|
+
element.finishEdit({
|
|
1794
|
+
text: cancel ? originalText : textarea.value,
|
|
1795
|
+
originalText: originalText
|
|
1616
1796
|
});
|
|
1617
|
-
element.toggleEditMode(false);
|
|
1618
1797
|
if (textareaRef.current === textarea) textareaRef.current = null;
|
|
1619
1798
|
if (textarea.parentNode) {
|
|
1620
1799
|
textarea.parentNode.removeChild(textarea);
|
|
@@ -2914,6 +3093,17 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
2914
3093
|
var config = getInputFieldsConfig();
|
|
2915
3094
|
var pendingFields = store._pendingInputFields || [];
|
|
2916
3095
|
|
|
3096
|
+
// Plain-English activity log (see model/activity-log.js). Called after the
|
|
3097
|
+
// element has been updated so the log can re-baseline past that change.
|
|
3098
|
+
var logAnswer = function logAnswer(action, el, value) {
|
|
3099
|
+
if (typeof store.logPopupAnswer !== 'function') return;
|
|
3100
|
+
store.logPopupAnswer({
|
|
3101
|
+
action: action,
|
|
3102
|
+
field: el ? mobxStateTree.getSnapshot(el) : undefined,
|
|
3103
|
+
value: value
|
|
3104
|
+
});
|
|
3105
|
+
};
|
|
3106
|
+
|
|
2917
3107
|
// When disabled, clear any pending fields so they are treated as skipped
|
|
2918
3108
|
React.useEffect(function () {
|
|
2919
3109
|
if (!enabled && pendingFields.length > 0) {
|
|
@@ -2969,6 +3159,7 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
2969
3159
|
text: previousValue || ''
|
|
2970
3160
|
});
|
|
2971
3161
|
}
|
|
3162
|
+
logAnswer('back', el);
|
|
2972
3163
|
isGoingBackRef.current = true;
|
|
2973
3164
|
store._unresolveInputField(el);
|
|
2974
3165
|
}
|
|
@@ -3016,9 +3207,11 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
3016
3207
|
});
|
|
3017
3208
|
}
|
|
3018
3209
|
}
|
|
3210
|
+
logAnswer('submit', el, value);
|
|
3019
3211
|
store._resolveInputField(elementId);
|
|
3020
3212
|
if (fields.length <= 1) {
|
|
3021
3213
|
_flushRemovedElements();
|
|
3214
|
+
logAnswer('finish');
|
|
3022
3215
|
store.history.addUndoState();
|
|
3023
3216
|
if (_onComplete) _onComplete();
|
|
3024
3217
|
} else {
|
|
@@ -3044,10 +3237,12 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
3044
3237
|
skipped: true,
|
|
3045
3238
|
removed: shouldRemove
|
|
3046
3239
|
});
|
|
3240
|
+
logAnswer('skip', el);
|
|
3047
3241
|
store._resolveInputField(elementId);
|
|
3048
3242
|
if (fields.length <= 1) {
|
|
3049
3243
|
var hadRemovals = removedDueToSkipRef.current.length > 0;
|
|
3050
3244
|
_flushRemovedElements();
|
|
3245
|
+
logAnswer('finish');
|
|
3051
3246
|
if (hadRemovals) store.history.addUndoState();
|
|
3052
3247
|
if (_onComplete) _onComplete();
|
|
3053
3248
|
} else {
|
|
@@ -3078,6 +3273,7 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
3078
3273
|
text: previousValue || ''
|
|
3079
3274
|
});
|
|
3080
3275
|
}
|
|
3276
|
+
logAnswer('back', el);
|
|
3081
3277
|
store._unresolveInputField(el);
|
|
3082
3278
|
}
|
|
3083
3279
|
setDisplayIndex(function (prev) {
|
|
@@ -3112,6 +3308,7 @@ var InputFieldsDialog = mobxReactLite.observer(function (_ref2) {
|
|
|
3112
3308
|
canGoBack: canGoBack,
|
|
3113
3309
|
onComplete: function onComplete() {
|
|
3114
3310
|
_flushRemovedElements();
|
|
3311
|
+
logAnswer('finish');
|
|
3115
3312
|
store.history.addUndoState();
|
|
3116
3313
|
if (_onComplete) _onComplete();
|
|
3117
3314
|
}
|