Açıklama Yok

index.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var index_1 = require("./../Drawboard/index");
  4. var uuid_1 = require("./../../utils/uuid");
  5. var types_1 = require("../../markers/types");
  6. require("./index.less");
  7. var dom_1 = require("../../utils/dom");
  8. var prefix = 'fcw-page';
  9. var WhitePage = (function () {
  10. function WhitePage(source, _a) {
  11. var _b = _a === void 0 ? {} : _a, mode = _b.mode, eventHub = _b.eventHub, parentContainer = _b.parentContainer;
  12. this.id = uuid_1.uuid();
  13. this.mode = 'master';
  14. if (mode) {
  15. this.mode = mode;
  16. }
  17. this.eventHub = eventHub;
  18. this.parentContainer = parentContainer;
  19. this.initSource(source);
  20. if (this.mode === 'master') {
  21. this.initMaster();
  22. }
  23. if (this.mode === 'mirror') {
  24. this.initMirror();
  25. }
  26. }
  27. WhitePage.prototype.open = function () {
  28. this.drawboard.open();
  29. };
  30. WhitePage.prototype.hide = function () {
  31. this.drawboard.hide();
  32. };
  33. WhitePage.prototype.show = function () {
  34. this.drawboard.show();
  35. };
  36. WhitePage.prototype.close = function () {
  37. this.drawboard.close();
  38. };
  39. WhitePage.prototype.initSource = function (source) {
  40. if (typeof source.imgSrc === 'string' && !this.parentContainer) {
  41. throw new Error('Invalid source, If you set image url, you must also set parentContainer');
  42. }
  43. this.source = source;
  44. if (source.imgEle) {
  45. this.target = source.imgEle;
  46. }
  47. if (typeof source.imgSrc === 'string') {
  48. this.container = dom_1.createDivWithClassName(prefix, this.parentContainer);
  49. this.container.id = this.id;
  50. this.target = document.createElement('img');
  51. this.target.src = source.imgSrc;
  52. this.target.alt = 'Siema image';
  53. this.container.appendChild(this.target);
  54. }
  55. };
  56. WhitePage.prototype.initMaster = function () {
  57. var _this = this;
  58. if (this.eventHub) {
  59. this.drawboard = new index_1.Drawboard({ imgEle: this.target }, {
  60. page: this,
  61. onChange: function (ev) { return _this.eventHub.emit('sync', ev); }
  62. });
  63. }
  64. else {
  65. this.drawboard = new index_1.Drawboard({ imgEle: this.target }, { page: this });
  66. }
  67. };
  68. WhitePage.prototype.initMirror = function () {
  69. var _this = this;
  70. if (!this.eventHub) {
  71. throw new Error('Invalid eventHub');
  72. }
  73. this.drawboard = new index_1.Drawboard({ imgEle: this.target }, { page: this });
  74. this.eventHub.on('sync', function (ev) {
  75. try {
  76. if (ev.target === 'page' && ev.id === _this.id) {
  77. _this.onPageSync();
  78. }
  79. if (ev.target === 'marker') {
  80. _this.onMarkerSync(ev);
  81. }
  82. }
  83. catch (e) {
  84. console.warn(e);
  85. }
  86. });
  87. };
  88. WhitePage.prototype.onPageSync = function () { };
  89. WhitePage.prototype.onMarkerSync = function (ev) {
  90. if (ev.event === 'add' && ev.parentId === this.id) {
  91. var data = ev.data;
  92. var marker = this.drawboard.markerMap[data.id];
  93. if (!marker) {
  94. this.drawboard.addMarker(types_1.getMarkerByType(data.type), { id: data.id });
  95. }
  96. }
  97. if (!ev.id) {
  98. return;
  99. }
  100. if (ev.event === 'remove') {
  101. var data = ev.data;
  102. var marker = this.drawboard.markerMap[data.id];
  103. if (marker) {
  104. this.drawboard.deleteMarker(marker);
  105. }
  106. }
  107. if (ev.event === 'move' || ev.event === 'resize') {
  108. var marker = this.drawboard.markerMap[ev.id];
  109. if (marker) {
  110. marker.reactToManipulation(ev.event, ev.data);
  111. }
  112. }
  113. if (ev.event === 'changeText') {
  114. var marker = this.drawboard.markerMap[ev.id];
  115. if (marker) {
  116. marker.setText(ev.data);
  117. }
  118. }
  119. };
  120. return WhitePage;
  121. }());
  122. exports.WhitePage = WhitePage;