@difizen/libro-core 0.3.7 → 0.3.9

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.
Files changed (37) hide show
  1. package/es/cell/libro-cell-service.d.ts +2 -0
  2. package/es/cell/libro-cell-service.d.ts.map +1 -1
  3. package/es/cell/libro-cell-service.js +9 -2
  4. package/es/cell/libro-cell-view.d.ts +2 -0
  5. package/es/cell/libro-cell-view.d.ts.map +1 -1
  6. package/es/cell/libro-cell-view.js +24 -0
  7. package/es/cell/libro-edit-cell-view.d.ts.map +1 -1
  8. package/es/cell/libro-edit-cell-view.js +3 -0
  9. package/es/command/libro-command-contribution.d.ts +4 -0
  10. package/es/command/libro-command-contribution.d.ts.map +1 -1
  11. package/es/command/libro-command-contribution.js +40 -26
  12. package/es/index.less +1 -1
  13. package/es/libro-protocol.d.ts +6 -2
  14. package/es/libro-protocol.d.ts.map +1 -1
  15. package/es/libro-protocol.js +0 -1
  16. package/es/libro-service.d.ts +2 -0
  17. package/es/libro-service.d.ts.map +1 -1
  18. package/es/libro-service.js +33 -19
  19. package/es/libro-setting.d.ts +1 -0
  20. package/es/libro-setting.d.ts.map +1 -1
  21. package/es/libro-setting.js +10 -0
  22. package/es/libro-view-tracker.d.ts +26 -1
  23. package/es/libro-view-tracker.d.ts.map +1 -1
  24. package/es/libro-view-tracker.js +92 -8
  25. package/es/libro-view.d.ts +2 -0
  26. package/es/libro-view.d.ts.map +1 -1
  27. package/es/libro-view.js +59 -20
  28. package/package.json +5 -5
  29. package/src/cell/libro-cell-service.ts +2 -0
  30. package/src/cell/libro-cell-view.tsx +30 -0
  31. package/src/cell/libro-edit-cell-view.tsx +1 -0
  32. package/src/command/libro-command-contribution.ts +37 -23
  33. package/src/libro-protocol.ts +7 -3
  34. package/src/libro-service.ts +7 -1
  35. package/src/libro-setting.ts +11 -0
  36. package/src/libro-view-tracker.ts +73 -2
  37. package/src/libro-view.tsx +34 -1
@@ -108,3 +108,14 @@ export const SupportCodeFormat: ConfigurationNode<boolean> = {
108
108
  type: 'boolean',
109
109
  },
110
110
  };
111
+
112
+ export const SpmReporter: ConfigurationNode<boolean> = {
113
+ id: 'libro.spm.reporter',
114
+ description: l10n.t('是否支持数据日志'),
115
+ title: l10n.t('是否支持数据日志'),
116
+ type: 'checkbox',
117
+ defaultValue: false,
118
+ schema: {
119
+ type: 'boolean',
120
+ },
121
+ };
@@ -1,9 +1,80 @@
1
- import { singleton } from '@difizen/mana-app';
1
+ import { singleton, Emitter, ConfigurationService, inject } from '@difizen/mana-app';
2
+ import { v4 } from 'uuid';
2
3
 
3
- import type { NotebookModel, NotebookView } from './libro-protocol.js';
4
+ import type {
5
+ ITracker,
6
+ NotebookModel,
7
+ NotebookView,
8
+ Options,
9
+ } from './libro-protocol.js';
10
+
11
+ export class Tracker implements ITracker {
12
+ [key: string]: any;
13
+ startTime?: number;
14
+ endTime?: number;
15
+ extra?: any;
16
+ id: string;
17
+
18
+ constructor(id?: string, extra?: any) {
19
+ this.id = id || v4();
20
+ this.startTime = Date.now();
21
+ this.extra = extra || {};
22
+ }
23
+
24
+ clearAll() {
25
+ this.startTime = undefined;
26
+ this.endTime = undefined;
27
+ }
28
+
29
+ getDuration() {
30
+ if (this.endTime && this.startTime) {
31
+ return this.endTime - this.startTime;
32
+ }
33
+ return undefined;
34
+ }
35
+
36
+ log() {
37
+ const result = {
38
+ id: this.id,
39
+ startTime: this.startTime,
40
+ endTime: this.endTime,
41
+ duration: this.getDuration(),
42
+ extra: this.extra,
43
+ };
44
+ this.clearAll();
45
+ return result;
46
+ }
47
+ }
4
48
 
5
49
  @singleton()
6
50
  export class LibroViewTracker {
7
51
  viewCache: Map<string, NotebookView> = new Map();
8
52
  modelCache: Map<string, NotebookModel> = new Map();
53
+ spmTracker: Map<string, Tracker> = new Map();
54
+ @inject(ConfigurationService) protected configurationService: ConfigurationService;
55
+ isEnabledSpmReporter: boolean;
56
+
57
+ protected onTrackerEmitter: Emitter<ITracker> = new Emitter();
58
+ get onTracker() {
59
+ return this.onTrackerEmitter.event;
60
+ }
61
+
62
+ getOrCreateSpmTracker(options: Options) {
63
+ const id = options.id || v4();
64
+ const exist = this.spmTracker.get(id);
65
+ if (exist) {
66
+ if (!exist.startTime) {
67
+ exist.startTime = Date.now();
68
+ }
69
+ return exist;
70
+ }
71
+ const tracker = new Tracker(id);
72
+ this.spmTracker.set(id, tracker);
73
+ return tracker;
74
+ }
75
+
76
+ tracker(tracker: Tracker) {
77
+ const trackerLog = tracker.log();
78
+ this.onTrackerEmitter.fire(trackerLog);
79
+ }
9
80
  }
@@ -62,6 +62,7 @@ import {
62
62
  HeaderToolbarVisible,
63
63
  RightContentFixed,
64
64
  } from './libro-setting.js';
65
+ import { LibroViewTracker } from './libro-view-tracker.js';
65
66
  import { LibroSlotManager, LibroSlotView } from './slot/index.js';
66
67
  import { useSize } from './utils/index.js';
67
68
  import { VirtualizedManagerHelper } from './virtualized-manager-helper.js';
@@ -325,7 +326,7 @@ export class LibroView extends BaseView implements NotebookView {
325
326
  @inject(LibroService) libroService: LibroService;
326
327
  @inject(LibroSlotManager) libroSlotManager: LibroSlotManager;
327
328
  @inject(LibroContextKey) contextKey: LibroContextKey;
328
-
329
+ @inject(LibroViewTracker) protected libroViewTracker: LibroViewTracker;
329
330
  @inject(ViewManager) protected viewManager: ViewManager;
330
331
  @inject(ConfigurationService) protected configurationService: ConfigurationService;
331
332
 
@@ -453,6 +454,14 @@ export class LibroView extends BaseView implements NotebookView {
453
454
  this.model.onChange?.();
454
455
  }),
455
456
  );
457
+ if (this.libroViewTracker.isEnabledSpmReporter) {
458
+ const libroTracker = this.libroViewTracker.getOrCreateSpmTracker({
459
+ id: this.id,
460
+ });
461
+ libroTracker.endTime = Date.now();
462
+ libroTracker.extra.cellsCount = this.model.cells.length;
463
+ this.libroViewTracker.tracker(libroTracker);
464
+ }
456
465
  this.initializedDefer.resolve();
457
466
  }, 0);
458
467
  }
@@ -519,11 +528,27 @@ export class LibroView extends BaseView implements NotebookView {
519
528
  };
520
529
 
521
530
  addCell = async (option: CellOptions, position?: number) => {
531
+ if (this.libroViewTracker.isEnabledSpmReporter && option.id) {
532
+ const id = option.id + this.id;
533
+ const libroTracker = this.libroViewTracker.getOrCreateSpmTracker({
534
+ id,
535
+ });
536
+ libroTracker.extra.cellsCount = this.model.cells.length;
537
+ libroTracker.extra.cellOperation = 'add';
538
+ }
522
539
  const cellView = await this.getCellViewByOption(option);
523
540
  this.model.addCell(cellView, position);
524
541
  };
525
542
 
526
543
  addCellAbove = async (option: CellOptions, position?: number) => {
544
+ if (this.libroViewTracker.isEnabledSpmReporter && option.id) {
545
+ const id = option.id + this.id;
546
+ const libroTracker = this.libroViewTracker.getOrCreateSpmTracker({
547
+ id,
548
+ });
549
+ libroTracker.extra.cellsCount = this.model.cells.length;
550
+ libroTracker.extra.cellOperation = 'add';
551
+ }
527
552
  const cellView = await this.getCellViewByOption(option);
528
553
  this.model.addCell(cellView, position, 'above');
529
554
  };
@@ -548,6 +573,14 @@ export class LibroView extends BaseView implements NotebookView {
548
573
  };
549
574
 
550
575
  deleteCell = (cell: CellView) => {
576
+ if (this.libroViewTracker.isEnabledSpmReporter && cell.model.id) {
577
+ const id = cell.model.id + this.id;
578
+ const libroTracker = this.libroViewTracker.getOrCreateSpmTracker({
579
+ id,
580
+ });
581
+ libroTracker.extra.cellsCount = this.model.cells.length;
582
+ libroTracker.extra.cellOperation = 'delete';
583
+ }
551
584
  const deleteIndex = this.model.getCells().findIndex((item) => {
552
585
  return equals(item, cell);
553
586
  });