note.js 1.2 KB

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