note.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const _ = require('../utils/under-dash');
  2. class Note {
  3. constructor(note) {
  4. this.note = note;
  5. }
  6. get model() {
  7. let value = null;
  8. switch (typeof this.note) {
  9. case 'string':
  10. value = {
  11. type: 'note',
  12. note: {
  13. texts: [
  14. {
  15. text: this.note,
  16. },
  17. ],
  18. },
  19. };
  20. break;
  21. default:
  22. value = {
  23. type: 'note',
  24. note: this.note,
  25. };
  26. break;
  27. }
  28. // Suitable for all cell comments
  29. return _.deepMerge({}, Note.DEFAULT_CONFIGS, value);
  30. }
  31. set model(value) {
  32. const {note} = value;
  33. const {texts} = note;
  34. if (texts.length === 1 && Object.keys(texts[0]).length === 1) {
  35. this.note = texts[0].text;
  36. } else {
  37. this.note = note;
  38. }
  39. }
  40. static fromModel(model) {
  41. const note = new Note();
  42. note.model = model;
  43. return note;
  44. }
  45. }
  46. Note.DEFAULT_CONFIGS = {
  47. note: {
  48. margins: {
  49. insetmode: 'auto',
  50. inset: [0.13, 0.13, 0.25, 0.25],
  51. },
  52. protection: {
  53. locked: 'True',
  54. lockText: 'True',
  55. },
  56. editAs: 'absolute',
  57. },
  58. };
  59. module.exports = Note;