luna-icon-list 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Luna Icon List
2
+
3
+ Show list of icons and their names.
4
+
5
+ ## Demo
6
+
7
+ https://luna.liriliri.io/?path=/story/icon-list
8
+
9
+ ## Install
10
+
11
+ Add the following script and style to your page.
12
+
13
+ ```html
14
+ <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/luna-icon-list/luna-icon-list.css" />
15
+ <script src="//cdn.jsdelivr.net/npm/luna-icon-list/luna-icon-list.js"></script>
16
+ ```
17
+
18
+ You can also get it on npm.
19
+
20
+ ```bash
21
+ npm install luna-icon-list --save
22
+ ```
23
+
24
+ ```javascript
25
+ import 'luna-icon-list/luna-icon-list.css'
26
+ import LunaIconList from 'luna-icon-list'
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```javascript
32
+ const iconList = new LunaIconList(container)
33
+ iconList.setIcons([
34
+ {
35
+ src: '/logo.png',
36
+ name: 'Luna',
37
+ },
38
+ ])
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ * filter(string | RegExp | AnyFn): Icon filter.
44
+ * selectable(boolean): Whether icon is selectable.
45
+ * size(number): Icon size.
46
+
47
+ ## Api
48
+
49
+ ### append(data: IIcon): void
50
+
51
+ Append icon.
52
+
53
+ ### clear(): void
54
+
55
+ Clear all icons.
56
+
57
+ ## Types
58
+
59
+ ### IIcon
60
+
@@ -0,0 +1,43 @@
1
+ import Component, { IComponentOptions } from '../share/Component';
2
+ import types from 'licia/types';
3
+ export interface IOptions extends IComponentOptions {
4
+ size?: number;
5
+ filter?: string | RegExp | types.AnyFn;
6
+ selectable?: boolean;
7
+ }
8
+ export interface IIcon {
9
+ src: string;
10
+ name: string;
11
+ }
12
+ export default class IconList extends Component<IOptions> {
13
+ private resizeSensor;
14
+ private icons;
15
+ private displayIcons;
16
+ private frag;
17
+ private appendTimer;
18
+ private onResize;
19
+ private selectedIcon;
20
+ constructor(container: HTMLElement, options?: IOptions);
21
+ destroy(): void;
22
+ setIcons(icons: Array<IIcon>): void;
23
+ clear(): void;
24
+ append(data: IIcon): void;
25
+ private _append;
26
+ private selectIcon;
27
+ private filterIcon;
28
+ private bindEvent;
29
+ private updateColumnCount;
30
+ private render;
31
+ }
32
+ export declare class Icon {
33
+ container: HTMLElement;
34
+ data: IIcon;
35
+ private $container;
36
+ private iconList;
37
+ private $icon;
38
+ constructor(iconList: IconList, data: IIcon);
39
+ setSize(size: number): void;
40
+ select(): void;
41
+ deselect(): void;
42
+ render(): void;
43
+ }
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Icon = void 0;
22
+ var Component_1 = __importDefault(require("../share/Component"));
23
+ var util_1 = require("../share/util");
24
+ var throttle_1 = __importDefault(require("licia/throttle"));
25
+ var h_1 = __importDefault(require("licia/h"));
26
+ var _1 = __importDefault(require("licia/$"));
27
+ var isFn_1 = __importDefault(require("licia/isFn"));
28
+ var isRegExp_1 = __importDefault(require("licia/isRegExp"));
29
+ var trim_1 = __importDefault(require("licia/trim"));
30
+ var isStr_1 = __importDefault(require("licia/isStr"));
31
+ var contain_1 = __importDefault(require("licia/contain"));
32
+ var isNull_1 = __importDefault(require("licia/isNull"));
33
+ var each_1 = __importDefault(require("licia/each"));
34
+ var lowerCase_1 = __importDefault(require("licia/lowerCase"));
35
+ var ResizeSensor_1 = __importDefault(require("licia/ResizeSensor"));
36
+ var GAP = 20;
37
+ var MIN_APPEND_INTERVAL = 100;
38
+ var IconList = (function (_super) {
39
+ __extends(IconList, _super);
40
+ function IconList(container, options) {
41
+ if (options === void 0) { options = {}; }
42
+ var _this = _super.call(this, container, { compName: 'icon-list' }, options) || this;
43
+ _this.icons = [];
44
+ _this.displayIcons = [];
45
+ _this.frag = document.createDocumentFragment();
46
+ _this.appendTimer = null;
47
+ _this.selectedIcon = null;
48
+ _this._append = function () {
49
+ _this.container.appendChild(_this.frag);
50
+ _this.appendTimer = null;
51
+ _this.updateColumnCount();
52
+ };
53
+ _this.updateColumnCount = function () {
54
+ var _a = _this, $container = _a.$container, c = _a.c;
55
+ var containerWidth = $container.offset().width;
56
+ var size = _this.options.size + 16;
57
+ var columnCount = Math.floor(containerWidth / (size + GAP));
58
+ if (_this.icons.length > columnCount) {
59
+ var gap = Math.floor((containerWidth - columnCount * size) / columnCount);
60
+ $container.addClass(c('grid'));
61
+ $container.css({
62
+ gridTemplateColumns: "repeat(".concat(columnCount, ", minmax(0, 1fr))"),
63
+ gap: "".concat(GAP, "px ").concat(gap, "px"),
64
+ paddingLeft: "".concat(gap / 2, "px"),
65
+ paddingRight: "".concat(gap / 2, "px"),
66
+ });
67
+ }
68
+ else {
69
+ $container.rmClass(c('grid'));
70
+ $container.css({
71
+ gap: '0',
72
+ paddingLeft: "".concat(GAP / 2, "px"),
73
+ paddingRight: "".concat(GAP / 2, "px"),
74
+ });
75
+ }
76
+ };
77
+ _this.resizeSensor = new ResizeSensor_1.default(container);
78
+ _this.onResize = (0, throttle_1.default)(function () {
79
+ _this.updateColumnCount();
80
+ }, 16);
81
+ _this.initOptions(options, {
82
+ size: 72,
83
+ selectable: true,
84
+ });
85
+ _this.bindEvent();
86
+ return _this;
87
+ }
88
+ IconList.prototype.destroy = function () {
89
+ _super.prototype.destroy.call(this);
90
+ this.resizeSensor.destroy();
91
+ };
92
+ IconList.prototype.setIcons = function (icons) {
93
+ var _this = this;
94
+ this.clear();
95
+ (0, each_1.default)(icons, function (data) {
96
+ var icon = new Icon(_this, data);
97
+ icon.setSize(_this.options.size);
98
+ _this.icons.push(icon);
99
+ if (_this.filterIcon(icon)) {
100
+ _this.displayIcons.push(icon);
101
+ }
102
+ });
103
+ this.render();
104
+ };
105
+ IconList.prototype.clear = function () {
106
+ this.$container.html('');
107
+ this.icons = [];
108
+ this.displayIcons = [];
109
+ this.selectIcon(null);
110
+ this.updateColumnCount();
111
+ };
112
+ IconList.prototype.append = function (data) {
113
+ var icon = new Icon(this, data);
114
+ icon.setSize(this.options.size);
115
+ this.icons.push(icon);
116
+ var isVisible = this.filterIcon(icon);
117
+ if (isVisible) {
118
+ this.displayIcons.push(icon);
119
+ }
120
+ this.frag.appendChild(icon.container);
121
+ if (!this.appendTimer) {
122
+ this.appendTimer = setTimeout(this._append, MIN_APPEND_INTERVAL);
123
+ }
124
+ };
125
+ IconList.prototype.selectIcon = function (icon) {
126
+ if (!this.options.selectable) {
127
+ return;
128
+ }
129
+ if (this.selectedIcon === icon) {
130
+ return;
131
+ }
132
+ if (this.selectedIcon) {
133
+ this.selectedIcon.deselect();
134
+ this.selectedIcon = null;
135
+ if ((0, isNull_1.default)(icon)) {
136
+ this.emit('deselect');
137
+ }
138
+ }
139
+ if (!(0, isNull_1.default)(icon)) {
140
+ this.selectedIcon = icon;
141
+ icon.select();
142
+ this.emit('select', icon);
143
+ }
144
+ };
145
+ IconList.prototype.filterIcon = function (icon) {
146
+ var filter = this.options.filter;
147
+ if (filter) {
148
+ if ((0, isFn_1.default)(filter)) {
149
+ return filter(icon);
150
+ }
151
+ else if ((0, isRegExp_1.default)(filter)) {
152
+ return filter.test(icon.data.name);
153
+ }
154
+ else if ((0, isStr_1.default)(filter)) {
155
+ filter = (0, trim_1.default)(filter);
156
+ if (filter) {
157
+ return (0, contain_1.default)((0, lowerCase_1.default)(icon.data.name), (0, lowerCase_1.default)(filter));
158
+ }
159
+ }
160
+ }
161
+ return true;
162
+ };
163
+ IconList.prototype.bindEvent = function () {
164
+ var _this = this;
165
+ this.resizeSensor.addListener(this.onResize);
166
+ var self = this;
167
+ var itemClass = this.c('.icon, .name');
168
+ this.$container
169
+ .on('click', itemClass, function (e) {
170
+ e.stopPropagation();
171
+ var item = this.parentNode;
172
+ var icon = item.icon;
173
+ self.selectIcon(icon);
174
+ setTimeout(function () {
175
+ if (item.hasDoubleClick) {
176
+ return;
177
+ }
178
+ self.emit('click', e.origEvent, icon);
179
+ }, 200);
180
+ })
181
+ .on('dblclick', itemClass, function (e) {
182
+ e.stopPropagation();
183
+ var item = this.parentNode;
184
+ var icon = item.icon;
185
+ item.hasDoubleClick = true;
186
+ self.emit('dblclick', e.origEvent, icon);
187
+ setTimeout(function () {
188
+ item.hasDoubleClick = false;
189
+ }, 300);
190
+ })
191
+ .on('click', function () { return _this.selectIcon(null); })
192
+ .on('contextmenu', itemClass, function (e) {
193
+ e.preventDefault();
194
+ var icon = this.parentNode.icon;
195
+ self.selectIcon(icon);
196
+ self.emit('contextmenu', e.origEvent, icon);
197
+ });
198
+ this.on('changeOption', function (name) {
199
+ switch (name) {
200
+ case 'size':
201
+ (0, each_1.default)(_this.icons, function (icon) {
202
+ icon.setSize(_this.options.size);
203
+ });
204
+ _this.updateColumnCount();
205
+ break;
206
+ case 'filter':
207
+ _this.displayIcons = [];
208
+ (0, each_1.default)(_this.icons, function (icon) {
209
+ if (_this.filterIcon(icon)) {
210
+ _this.displayIcons.push(icon);
211
+ }
212
+ });
213
+ if (_this.selectedIcon && !_this.filterIcon(_this.selectedIcon)) {
214
+ _this.selectIcon(null);
215
+ }
216
+ _this.render();
217
+ break;
218
+ }
219
+ });
220
+ };
221
+ IconList.prototype.render = function () {
222
+ var _a = this, displayIcons = _a.displayIcons, $container = _a.$container, container = _a.container;
223
+ var frag = document.createDocumentFragment();
224
+ $container.html('');
225
+ (0, each_1.default)(displayIcons, function (icon) {
226
+ frag.appendChild(icon.container);
227
+ });
228
+ container.appendChild(frag);
229
+ this.updateColumnCount();
230
+ };
231
+ return IconList;
232
+ }(Component_1.default));
233
+ exports.default = IconList;
234
+ var Icon = (function () {
235
+ function Icon(iconList, data) {
236
+ this.container = (0, h_1.default)('div');
237
+ ;
238
+ this.container.icon = this;
239
+ this.$container = (0, _1.default)(this.container);
240
+ this.$container.addClass(iconList.c('item'));
241
+ this.iconList = iconList;
242
+ this.data = data;
243
+ this.render();
244
+ this.$icon = this.$container.find(iconList.c('.icon'));
245
+ }
246
+ Icon.prototype.setSize = function (size) {
247
+ var width = "".concat(size + 16, "px");
248
+ this.$container.css({
249
+ width: width,
250
+ });
251
+ this.$icon.css({
252
+ width: width,
253
+ height: width,
254
+ });
255
+ };
256
+ Icon.prototype.select = function () {
257
+ this.$container.addClass(this.iconList.c('selected'));
258
+ };
259
+ Icon.prototype.deselect = function () {
260
+ this.$container.rmClass(this.iconList.c('selected'));
261
+ };
262
+ Icon.prototype.render = function () {
263
+ var _a = this, data = _a.data, $container = _a.$container;
264
+ var src = data.src, name = data.name;
265
+ $container.append(this.iconList.c("\n <div class=\"icon\">\n <img src=\"".concat(src, "\" draggable=\"false\"></img>\n </div>\n <div class=\"name\">").concat(name, "</div>\n ")));
266
+ };
267
+ return Icon;
268
+ }());
269
+ exports.Icon = Icon;
270
+ if (typeof module !== 'undefined') {
271
+ (0, util_1.exportCjs)(module, IconList);
272
+ }
@@ -0,0 +1,14 @@
1
+ import { FC } from 'react';
2
+ import { IOptions, IIcon, Icon } from './index';
3
+ interface IIconListProps extends IOptions {
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ onSelect?: (icon: Icon) => void;
7
+ onDeselect?: () => void;
8
+ onClick?: (e: MouseEvent, icon: Icon) => void;
9
+ onDoubleClick?: (e: MouseEvent, icon: Icon) => void;
10
+ onContextMenu?: (e: PointerEvent, icon: Icon) => void;
11
+ icons: Array<IIcon>;
12
+ }
13
+ declare const LunaIconList: FC<IIconListProps>;
14
+ export default LunaIconList;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
+ var react_1 = require("react");
8
+ var index_1 = __importDefault(require("./index"));
9
+ var hooks_1 = require("../share/hooks");
10
+ var each_1 = __importDefault(require("licia/each"));
11
+ var LunaIconList = function (props) {
12
+ var iconListRef = (0, react_1.useRef)(null);
13
+ var iconList = (0, react_1.useRef)();
14
+ var prevProps = (0, hooks_1.usePrevious)(props);
15
+ (0, react_1.useEffect)(function () {
16
+ iconList.current = new index_1.default(iconListRef.current, {
17
+ size: props.size,
18
+ selectable: props.selectable,
19
+ filter: props.filter,
20
+ });
21
+ iconList.current.setIcons(props.icons);
22
+ }, []);
23
+ (0, hooks_1.useNonInitialEffect)(function () {
24
+ if (iconList.current) {
25
+ iconList.current.setIcons(props.icons);
26
+ }
27
+ }, [props.icons]);
28
+ (0, hooks_1.useEvent)(iconList, 'select', prevProps === null || prevProps === void 0 ? void 0 : prevProps.onSelect, props.onSelect);
29
+ (0, hooks_1.useEvent)(iconList, 'deselect', prevProps === null || prevProps === void 0 ? void 0 : prevProps.onDeselect, props.onDeselect);
30
+ (0, hooks_1.useEvent)(iconList, 'click', prevProps === null || prevProps === void 0 ? void 0 : prevProps.onClick, props.onClick);
31
+ (0, hooks_1.useEvent)(iconList, 'dblclick', prevProps === null || prevProps === void 0 ? void 0 : prevProps.onDoubleClick, props.onDoubleClick);
32
+ (0, hooks_1.useEvent)(iconList, 'contextmenu', prevProps === null || prevProps === void 0 ? void 0 : prevProps.onContextMenu, props.onContextMenu);
33
+ (0, each_1.default)(['theme', 'size', 'selectable', 'filter'], function (key) {
34
+ (0, hooks_1.useOption)(iconList, key, props[key]);
35
+ });
36
+ return ((0, jsx_runtime_1.jsx)("div", { className: props.className || '', style: props.style, ref: iconListRef }));
37
+ };
38
+ exports.default = LunaIconList;
@@ -0,0 +1,29 @@
1
+ import Emitter from 'licia/Emitter';
2
+ import $ from 'licia/$';
3
+ interface IOptions {
4
+ compName: string;
5
+ }
6
+ export interface IComponentOptions {
7
+ theme?: string;
8
+ }
9
+ export default class Component<Options extends IComponentOptions = any> extends Emitter {
10
+ c: (name: string) => string;
11
+ container: HTMLElement;
12
+ $container: $.$;
13
+ private subComponents;
14
+ private compName;
15
+ private theme;
16
+ protected options: Required<Options>;
17
+ constructor(container: Element, { compName }: IOptions, { theme: t }?: IComponentOptions);
18
+ destroy(): void;
19
+ setOption(name: string | Partial<Options>, val?: any): void;
20
+ getOption(name: string): any;
21
+ addSubComponent(component: Component): void;
22
+ removeSubComponent(component: Component): void;
23
+ destroySubComponents(): void;
24
+ protected initOptions(options: Options, defs?: any): void;
25
+ protected find(selector: string): $.$;
26
+ private setTheme;
27
+ private onThemeChange;
28
+ }
29
+ export {};
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var Emitter_1 = __importDefault(require("licia/Emitter"));
22
+ var _1 = __importDefault(require("licia/$"));
23
+ var util_1 = require("./util");
24
+ var each_1 = __importDefault(require("licia/each"));
25
+ var extend_1 = __importDefault(require("licia/extend"));
26
+ var defaults_1 = __importDefault(require("licia/defaults"));
27
+ var remove_1 = __importDefault(require("licia/remove"));
28
+ var theme_1 = __importDefault(require("licia/theme"));
29
+ var startWith_1 = __importDefault(require("licia/startWith"));
30
+ var Component = (function (_super) {
31
+ __extends(Component, _super);
32
+ function Component(container, _a, _b) {
33
+ var compName = _a.compName;
34
+ var _c = _b === void 0 ? {} : _b, _d = _c.theme, t = _d === void 0 ? 'light' : _d;
35
+ var _this = _super.call(this) || this;
36
+ _this.subComponents = [];
37
+ _this.theme = '';
38
+ _this.onThemeChange = function (t) {
39
+ if (_this.options.theme === 'auto') {
40
+ _this.setTheme(t);
41
+ }
42
+ };
43
+ _this.compName = compName;
44
+ _this.c = (0, util_1.classPrefix)(compName);
45
+ _this.options = {};
46
+ _this.container = container;
47
+ _this.$container = (0, _1.default)(container);
48
+ _this.$container.addClass([
49
+ "luna-".concat(compName),
50
+ _this.c("platform-".concat((0, util_1.getPlatform)())),
51
+ ]);
52
+ _this.on('changeOption', function (name, val) {
53
+ if (name === 'theme' && val) {
54
+ var t_1 = val;
55
+ if (val === 'auto') {
56
+ t_1 = theme_1.default.get();
57
+ }
58
+ _this.setTheme(t_1);
59
+ (0, each_1.default)(_this.subComponents, function (component) {
60
+ return component.setOption('theme', val);
61
+ });
62
+ }
63
+ });
64
+ theme_1.default.on('change', _this.onThemeChange);
65
+ _this.setOption('theme', t);
66
+ return _this;
67
+ }
68
+ Component.prototype.destroy = function () {
69
+ var _this = this;
70
+ this.destroySubComponents();
71
+ var $container = this.$container;
72
+ var classes = $container.attr('class');
73
+ (0, each_1.default)(classes.split(/\s+/), function (c) {
74
+ if ((0, startWith_1.default)(c, "luna-".concat(_this.compName))) {
75
+ $container.rmClass(c);
76
+ }
77
+ });
78
+ $container.html('');
79
+ this.emit('destroy');
80
+ this.removeAllListeners();
81
+ theme_1.default.off('change', this.onThemeChange);
82
+ };
83
+ Component.prototype.setOption = function (name, val) {
84
+ var _this = this;
85
+ var options = this.options;
86
+ var newOptions = {};
87
+ if (typeof name === 'string') {
88
+ newOptions[name] = val;
89
+ }
90
+ else {
91
+ newOptions = name;
92
+ }
93
+ (0, each_1.default)(newOptions, function (val, name) {
94
+ var oldVal = options[name];
95
+ options[name] = val;
96
+ if (val === oldVal) {
97
+ return;
98
+ }
99
+ _this.emit('changeOption', name, val, oldVal);
100
+ });
101
+ };
102
+ Component.prototype.getOption = function (name) {
103
+ return this.options[name];
104
+ };
105
+ Component.prototype.addSubComponent = function (component) {
106
+ component.setOption('theme', this.options.theme);
107
+ this.subComponents.push(component);
108
+ };
109
+ Component.prototype.removeSubComponent = function (component) {
110
+ (0, remove_1.default)(this.subComponents, function (com) { return com === component; });
111
+ };
112
+ Component.prototype.destroySubComponents = function () {
113
+ (0, each_1.default)(this.subComponents, function (component) { return component.destroy(); });
114
+ this.subComponents = [];
115
+ };
116
+ Component.prototype.initOptions = function (options, defs) {
117
+ if (defs === void 0) { defs = {}; }
118
+ (0, defaults_1.default)(options, defs);
119
+ (0, extend_1.default)(this.options, options);
120
+ };
121
+ Component.prototype.find = function (selector) {
122
+ return this.$container.find(this.c(selector));
123
+ };
124
+ Component.prototype.setTheme = function (theme) {
125
+ var _a = this, c = _a.c, $container = _a.$container;
126
+ if (this.theme) {
127
+ $container.rmClass(c("theme-".concat(this.theme)));
128
+ }
129
+ $container.addClass(c("theme-".concat(theme)));
130
+ this.theme = theme;
131
+ };
132
+ return Component;
133
+ }(Emitter_1.default));
134
+ exports.default = Component;
@@ -0,0 +1,7 @@
1
+ import { DependencyList, EffectCallback } from 'react';
2
+ import Component from './Component';
3
+ export declare function useForceUpdate(): () => void;
4
+ export declare function usePrevious<T>(value: T): T | undefined;
5
+ export declare function useNonInitialEffect(effect: EffectCallback, deps?: DependencyList): void;
6
+ export declare function useEvent<C extends Component>(component: React.MutableRefObject<C | undefined>, event: string, prev: any, prop: any): void;
7
+ export declare function useOption<C extends Component, P>(component: React.MutableRefObject<C | undefined>, key: keyof P, prop: any): void;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.useOption = exports.useEvent = exports.useNonInitialEffect = exports.usePrevious = exports.useForceUpdate = void 0;
20
+ var react_1 = require("react");
21
+ function useForceUpdate() {
22
+ var _a = __read((0, react_1.useState)(0), 2), _ = _a[0], setForceUpdateValue = _a[1];
23
+ return function () { return setForceUpdateValue(function (value) { return value + 1; }); };
24
+ }
25
+ exports.useForceUpdate = useForceUpdate;
26
+ function usePrevious(value) {
27
+ var ref = (0, react_1.useRef)();
28
+ (0, react_1.useEffect)(function () {
29
+ ref.current = value;
30
+ });
31
+ return ref.current;
32
+ }
33
+ exports.usePrevious = usePrevious;
34
+ function useNonInitialEffect(effect, deps) {
35
+ var initialRender = (0, react_1.useRef)(true);
36
+ (0, react_1.useEffect)(function () {
37
+ var effectReturns = function () { };
38
+ if (initialRender.current) {
39
+ initialRender.current = false;
40
+ }
41
+ else {
42
+ effectReturns = effect();
43
+ }
44
+ if (effectReturns && typeof effectReturns === 'function') {
45
+ return effectReturns;
46
+ }
47
+ }, deps);
48
+ }
49
+ exports.useNonInitialEffect = useNonInitialEffect;
50
+ function useEvent(component, event, prev, prop) {
51
+ (0, react_1.useEffect)(function () {
52
+ if (component.current) {
53
+ if (prev) {
54
+ component.current.off(event, prev);
55
+ }
56
+ if (prop) {
57
+ component.current.on(event, prop);
58
+ }
59
+ }
60
+ }, [prop]);
61
+ }
62
+ exports.useEvent = useEvent;
63
+ function useOption(component, key, prop) {
64
+ useNonInitialEffect(function () {
65
+ if (component.current) {
66
+ component.current.setOption(key, prop);
67
+ }
68
+ }, [prop]);
69
+ }
70
+ exports.useOption = useOption;
@@ -0,0 +1,12 @@
1
+ export declare function exportCjs(module: any, clazz: any): void;
2
+ export declare function classPrefix(name: string): (str: string) => string;
3
+ export declare const hasTouchSupport: boolean;
4
+ export declare function eventClient(type: string, e: any): any;
5
+ export declare function eventPage(type: string, e: any): any;
6
+ export declare function measuredScrollbarWidth(): number;
7
+ export declare function hasVerticalScrollbar(el: HTMLElement): boolean;
8
+ export declare function executeAfterTransition(el: HTMLElement, callback: () => any): any;
9
+ export declare function pxToNum(str: string): number;
10
+ export declare function getPlatform(): string;
11
+ export declare function resetCanvasSize(canvas: HTMLCanvasElement): void;
12
+ export declare function loadImage(url: string): Promise<HTMLImageElement>;