@egjs/react-grid
Version:
A React component that can arrange items according to the type of grids
242 lines (192 loc) • 6.5 kB
JavaScript
/*
Copyright (c) NAVER Corp.
name: @egjs/react-grid
license: MIT
author: NAVER Corp.
repository: https://github.com/naver/egjs-grid
version: 1.18.0
*/
;
var React = require('react');
var grid = require('@egjs/grid');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
};
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __decorate(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || from);
}
var REACT_GRID_EVENT_MAP = {
"contentError": "onContentError",
"renderComplete": "onRenderComplete"
};
var REACT_GRID_EVENTS = ["onContentError", "onRenderComplete"];
var REACT_GRID_PROPS = __spreadArray(["tag"], REACT_GRID_EVENTS);
var Grid =
/*#__PURE__*/
function (_super) {
__extends(Grid, _super);
function Grid() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._containerRef = React.createRef();
return _this;
}
var __proto = Grid.prototype;
__proto.render = function () {
var attributes = {};
var props = this.props;
var GridClass = this.constructor.GridClass;
var defaultOptions = GridClass.defaultOptions;
var Tag = props.tag || "div";
for (var name in props) {
if (name in defaultOptions || REACT_GRID_PROPS.indexOf(name) > -1) {
continue;
}
attributes[name] = props[name];
}
return React.createElement(Tag, __assign({
ref: this._containerRef
}, attributes), this.props.children);
};
__proto.componentDidMount = function () {
var GridClass = this.constructor.GridClass;
var defaultOptions = GridClass.defaultOptions;
var options = {};
var props = this.props;
for (var name in defaultOptions) {
if (name in props) {
options[name] = props[name];
}
}
var grid = new GridClass(this._containerRef.current, options);
var _loop_1 = function (eventName) {
var reactEventName = REACT_GRID_EVENT_MAP[eventName];
grid.on(eventName, function (e) {
var callback = props[reactEventName];
callback && callback(__assign({}, e));
});
};
for (var eventName in REACT_GRID_EVENT_MAP) {
_loop_1(eventName);
}
grid.syncElements();
this._grid = grid;
};
__proto.componentDidUpdate = function () {
var GridClass = this.constructor.GridClass;
var propertyTypes = GridClass.propertyTypes;
var props = this.props;
var grid = this._grid;
for (var name in propertyTypes) {
if (name in props) {
grid[name] = props[name];
}
}
this._grid.syncElements();
};
__proto.componentWillUnmount = function () {
this._grid.destroy();
};
__decorate([grid.withGridMethods], Grid.prototype, "_grid", void 0);
return Grid;
}(React.PureComponent);
var MasonryGrid =
/*#__PURE__*/
function (_super) {
__extends(MasonryGrid, _super);
function MasonryGrid() {
return _super !== null && _super.apply(this, arguments) || this;
}
MasonryGrid.GridClass = grid.MasonryGrid;
return MasonryGrid;
}(Grid);
var JustifiedGrid =
/*#__PURE__*/
function (_super) {
__extends(JustifiedGrid, _super);
function JustifiedGrid() {
return _super !== null && _super.apply(this, arguments) || this;
}
JustifiedGrid.GridClass = grid.JustifiedGrid;
return JustifiedGrid;
}(Grid);
var FrameGrid =
/*#__PURE__*/
function (_super) {
__extends(FrameGrid, _super);
function FrameGrid() {
return _super !== null && _super.apply(this, arguments) || this;
}
FrameGrid.GridClass = grid.FrameGrid;
return FrameGrid;
}(Grid);
var PackingGrid =
/*#__PURE__*/
function (_super) {
__extends(PackingGrid, _super);
function PackingGrid() {
return _super !== null && _super.apply(this, arguments) || this;
}
PackingGrid.GridClass = grid.PackingGrid;
return PackingGrid;
}(Grid);
var modules = {
__proto__: null,
Grid: Grid,
MasonryGrid: MasonryGrid,
JustifiedGrid: JustifiedGrid,
FrameGrid: FrameGrid,
PackingGrid: PackingGrid
};
module.exports = modules;
//# sourceMappingURL=grid.cjs.js.map