index.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var __assign = (this && this.__assign) || Object.assign || function(t) {
  12. for (var s, i = 1, n = arguments.length; i < n; i++) {
  13. s = arguments[i];
  14. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  15. t[p] = s[p];
  16. }
  17. return t;
  18. };
  19. import * as React from 'react';
  20. import { Dragact } from '../../src/lib/dragact';
  21. import { Card } from '../NormalLayout/index';
  22. import './index.css';
  23. var Words = [
  24. { content: 'You can do anything, but not everything.' },
  25. { content: 'Those who dare to fail miserably can achieve greatly.' },
  26. { content: 'You miss 100 percent of the shots you never take.' },
  27. { content: 'Those who believe in telekinetics, raise my hand.' },
  28. { content: 'I’d rather live with a good question than a bad answer.' }
  29. ];
  30. var fakeData = function () {
  31. var Y = 0;
  32. return Words.map(function (item, index) {
  33. if (index % 4 === 0)
  34. Y++;
  35. return __assign({}, item, { GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 2, key: index + '' });
  36. });
  37. };
  38. var storeLayout = void 666;
  39. var LayoutRestore = /** @class */ (function (_super) {
  40. __extends(LayoutRestore, _super);
  41. function LayoutRestore() {
  42. var _this = _super !== null && _super.apply(this, arguments) || this;
  43. _this.handleOnDragEnd = function () {
  44. var newLayout = _this.dragactNode.getLayout();
  45. var parsedLayout = JSON.stringify(newLayout);
  46. localStorage.setItem('layout', parsedLayout);
  47. };
  48. _this.renderDragact = function () {
  49. var margin = [5, 5];
  50. var dragactInit = {
  51. width: 600,
  52. col: 12,
  53. rowHeight: 800 / 12,
  54. margin: margin,
  55. className: 'normal-layout',
  56. layout: storeLayout ? storeLayout : fakeData(),
  57. placeholder: true
  58. };
  59. return (React.createElement(Dragact, __assign({}, dragactInit, { ref: function (node) { return node ? _this.dragactNode = node : null; }, onDragEnd: _this.handleOnDragEnd }), function (item, provided) {
  60. return React.createElement(Card, { item: item, provided: provided });
  61. }));
  62. };
  63. return _this;
  64. }
  65. LayoutRestore.prototype.componentWillMount = function () {
  66. var lastLayout = localStorage.getItem('layout');
  67. if (lastLayout) {
  68. storeLayout = JSON.parse(lastLayout);
  69. }
  70. };
  71. LayoutRestore.prototype.render = function () {
  72. return (React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  73. React.createElement("div", null,
  74. React.createElement("h1", { style: { textAlign: 'center' } }, "\u5B58\u50A8\u5E03\u5C40 Demo"),
  75. this.renderDragact())));
  76. };
  77. return LayoutRestore;
  78. }(React.Component));
  79. export { LayoutRestore };