etudes 1.2.0 → 2.0.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 +1 -1
- package/lib/Accordion.d.ts +80 -71
- package/lib/Accordion.js +173 -183
- package/lib/Accordion.js.map +1 -1
- package/lib/BurgerButton.d.ts +20 -7
- package/lib/BurgerButton.js +113 -20
- package/lib/BurgerButton.js.map +1 -1
- package/lib/Conditional.d.ts +2 -3
- package/lib/Conditional.js +0 -1
- package/lib/Conditional.js.map +1 -1
- package/lib/DebugConsole.d.ts +14 -23
- package/lib/DebugConsole.js +86 -87
- package/lib/DebugConsole.js.map +1 -1
- package/lib/Dial.d.ts +53 -16
- package/lib/Dial.js +121 -35
- package/lib/Dial.js.map +1 -1
- package/lib/Dropdown.d.ts +68 -83
- package/lib/Dropdown.js +226 -161
- package/lib/Dropdown.js.map +1 -1
- package/lib/Each.d.ts +2 -2
- package/lib/Each.js.map +1 -1
- package/lib/ExtractChild.d.ts +5 -4
- package/lib/ExtractChild.js +13 -11
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +2 -2
- package/lib/ExtractChildren.js +7 -5
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/FlatSVG.d.ts +30 -25
- package/lib/FlatSVG.js +28 -37
- package/lib/FlatSVG.js.map +1 -1
- package/lib/List.d.ts +97 -54
- package/lib/List.js +124 -63
- package/lib/List.js.map +1 -1
- package/lib/MasonryGrid.d.ts +27 -15
- package/lib/MasonryGrid.js +163 -148
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Panorama.d.ts +100 -21
- package/lib/Panorama.js +45 -44
- package/lib/Panorama.js.map +1 -1
- package/lib/PanoramaSlider.d.ts +65 -23
- package/lib/PanoramaSlider.js +150 -45
- package/lib/PanoramaSlider.js.map +1 -1
- package/lib/RangeSlider.d.ts +29 -89
- package/lib/RangeSlider.js +272 -286
- package/lib/RangeSlider.js.map +1 -1
- package/lib/Repeat.d.ts +4 -3
- package/lib/Repeat.js +3 -2
- package/lib/Repeat.js.map +1 -1
- package/lib/RotatingGallery.d.ts +38 -36
- package/lib/RotatingGallery.js +47 -17
- package/lib/RotatingGallery.js.map +1 -1
- package/lib/SelectableButton.d.ts +13 -4
- package/lib/SelectableButton.js +3 -14
- package/lib/SelectableButton.js.map +1 -1
- package/lib/Slider.d.ts +103 -41
- package/lib/Slider.js +182 -82
- package/lib/Slider.js.map +1 -1
- package/lib/StepwiseSlider.d.ts +146 -59
- package/lib/StepwiseSlider.js +248 -142
- package/lib/StepwiseSlider.js.map +1 -1
- package/lib/SwipeContainer.d.ts +13 -5
- package/lib/SwipeContainer.js +5 -15
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/TextField.js +5 -15
- package/lib/TextField.js.map +1 -1
- package/lib/Video.d.ts +30 -51
- package/lib/Video.js +77 -119
- package/lib/Video.js.map +1 -1
- package/lib/WithTooltip.d.ts +16 -18
- package/lib/WithTooltip.js +167 -101
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useDocumentTitle.d.ts +2 -1
- package/lib/hooks/useDocumentTitle.js +2 -1
- package/lib/hooks/useDocumentTitle.js.map +1 -1
- package/lib/hooks/useDragEffect.d.ts +25 -16
- package/lib/hooks/useDragEffect.js +30 -20
- package/lib/hooks/useDragEffect.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +2 -1
- package/lib/hooks/useElementRect.js +5 -4
- package/lib/hooks/useElementRect.js.map +1 -1
- package/lib/hooks/useInterval.d.ts +2 -2
- package/lib/hooks/useInterval.js +1 -1
- package/lib/hooks/useInterval.js.map +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +6 -6
- package/lib/hooks/useLoadImageEffect.js.map +1 -1
- package/lib/hooks/usePrevious.d.ts +6 -0
- package/lib/hooks/usePrevious.js +17 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useResizeEffect.d.ts +2 -2
- package/lib/hooks/useResizeEffect.js +5 -8
- package/lib/hooks/useResizeEffect.js.map +1 -1
- package/lib/hooks/useSearchParamState.d.ts +10 -7
- package/lib/hooks/useSearchParamState.js +14 -10
- package/lib/hooks/useSearchParamState.js.map +1 -1
- package/lib/utils/asClassNameDict.d.ts +3 -0
- package/lib/utils/asClassNameDict.js +7 -0
- package/lib/utils/asClassNameDict.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +5 -0
- package/lib/utils/asComponentDict.js +23 -0
- package/lib/utils/asComponentDict.js.map +1 -0
- package/lib/utils/asStyleDict.d.ts +4 -0
- package/lib/utils/asStyleDict.js +7 -0
- package/lib/utils/asStyleDict.js.map +1 -0
- package/lib/utils/cloneStyledElement.d.ts +18 -0
- package/lib/utils/cloneStyledElement.js +63 -0
- package/lib/utils/cloneStyledElement.js.map +1 -0
- package/lib/utils/styles.d.ts +2 -0
- package/lib/utils/styles.js +22 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/utils/useDebug.d.ts +2 -0
- package/lib/utils/useDebug.js +46 -0
- package/lib/utils/useDebug.js.map +1 -0
- package/package.json +25 -33
- package/lib/AbstractSelectableCollection.d.ts +0 -94
- package/lib/AbstractSelectableCollection.js +0 -151
- package/lib/AbstractSelectableCollection.js.map +0 -1
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
+
if (!m) return o;
|
|
27
|
+
var i = m.call(o), r, ar = [], e;
|
|
28
|
+
try {
|
|
29
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) { e = { error: error }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e) throw e.error; }
|
|
37
|
+
}
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
41
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
42
|
+
if (ar || !(i in from)) {
|
|
43
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
+
ar[i] = from[i];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var react_1 = require("react");
|
|
51
|
+
function cloneStyledElement(element, props) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (props === void 0) { props = {}; }
|
|
54
|
+
var children = [];
|
|
55
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
56
|
+
children[_i - 2] = arguments[_i];
|
|
57
|
+
}
|
|
58
|
+
var _c = props, className = _c.className, style = _c.style, otherProps = __rest(_c, ["className", "style"]);
|
|
59
|
+
var elementProps = element.props;
|
|
60
|
+
return react_1.cloneElement.apply(void 0, __spreadArray([element, __assign({ className: "".concat((_a = elementProps.className) !== null && _a !== void 0 ? _a : '', " ").concat(className !== null && className !== void 0 ? className : '').split(' ').filter(Boolean).join(' '), style: __assign(__assign({}, (_b = elementProps.style) !== null && _b !== void 0 ? _b : {}), style !== null && style !== void 0 ? style : {}) }, otherProps)], __read(children), false));
|
|
61
|
+
}
|
|
62
|
+
exports.default = cloneStyledElement;
|
|
63
|
+
//# sourceMappingURL=cloneStyledElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneStyledElement.js","sourceRoot":"/","sources":["utils/cloneStyledElement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAyJ;AAkBzJ,SAAS,kBAAkB,CACzB,OAAuE,EACvE,KAAqE;;IAArE,sBAAA,EAAA,UAAqE;IACrE,kBAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,iCAAwB;;IAExB,IAAM,KAAsC,KAAY,EAAhD,SAAS,eAAA,EAAE,KAAK,WAAA,EAAK,UAAU,cAAjC,sBAAmC,CAAe,CAAA;IACxD,IAAM,YAAY,GAAG,OAAO,CAAC,KAAY,CAAA;IAEzC,OAAO,oBAAY,8BAAC,OAAO,EAAE,WAC3B,SAAS,EAAE,UAAG,MAAA,YAAY,CAAC,SAAS,mCAAI,EAAE,cAAI,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EACpG,KAAK,wBACA,MAAA,YAAY,CAAC,KAAK,mCAAI,EAAE,GACxB,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,KAEb,UAAU,CACP,UAAK,QAAQ,WAAC;AACxB,CAAC;AAED,kBAAe,kBAAkB,CAAA","sourcesContent":["import { Attributes, CElement, ClassAttributes, cloneElement, Component, ComponentState, FunctionComponentElement, ReactElement, ReactNode } from 'react'\n\n/**\n * Wrapper for {@link cloneElement} but instead of overwriting `className` and\n * `style` of the cloned element with the values specified in the `props`\n * argument, they are merged instead.\n *\n * @param element - The target element to clone.\n * @param props - The props to apply to the cloned element. Overlapping props\n * are overwritten with the exception of `className` and `style`,\n * which are merged.\n * @param children - Optional child elements add into the cloned element.\n *\n * @returns The cloned element.\n */\nfunction cloneStyledElement<P>(element: FunctionComponentElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): FunctionComponentElement<P>\nfunction cloneStyledElement<P, T extends Component<P, ComponentState>>(element: CElement<P, T>, props?: Partial<P> & ClassAttributes<T>, ...children: ReactNode[]): CElement<P, T>\nfunction cloneStyledElement<P>(element: ReactElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): ReactElement<P>\nfunction cloneStyledElement<P, T extends Component<P, ComponentState> = never>(\n element: FunctionComponentElement<P> | CElement<P, T> | ReactElement<P>,\n props: Partial<P> & Attributes | Partial<P> & ClassAttributes<T> = {},\n ...children: ReactNode[]\n) {\n const { className, style, ...otherProps } = props as any\n const elementProps = element.props as any\n\n return cloneElement(element, {\n className: `${elementProps.className ?? ''} ${className ?? ''}`.split(' ').filter(Boolean).join(' '),\n style: {\n ...elementProps.style ?? {},\n ...style ?? {},\n },\n ...otherProps,\n } as any, ...children)\n}\n\nexport default cloneStyledElement\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
function styles() {
|
|
15
|
+
var args = [];
|
|
16
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
17
|
+
args[_i] = arguments[_i];
|
|
18
|
+
}
|
|
19
|
+
return args.reduce(function (out, curr) { return (__assign(__assign({}, out), curr || {})); }, {});
|
|
20
|
+
}
|
|
21
|
+
exports.default = styles;
|
|
22
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"/","sources":["utils/styles.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,SAAwB,MAAM;IAAC,cAA8C;SAA9C,UAA8C,EAA9C,qBAA8C,EAA9C,IAA8C;QAA9C,yBAA8C;;IAC3E,OAAO,IAAI,CAAC,MAAM,CAAgB,UAAC,GAAG,EAAE,IAAI,IAAK,OAAA,uBAC5C,GAAG,GACH,IAAI,IAAI,EAAE,EACb,EAH+C,CAG/C,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AALD,yBAKC","sourcesContent":["import { CSSProperties } from 'react'\n\nexport default function styles(...args: (CSSProperties | undefined | false)[]): CSSProperties {\n return args.reduce<CSSProperties>((out, curr) => ({\n ...out,\n ...curr || {},\n }), {})\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
var debug_1 = __importDefault(require("debug"));
|
|
32
|
+
function useDebug(subnamespace) {
|
|
33
|
+
if (subnamespace === void 0) { subnamespace = ''; }
|
|
34
|
+
if (process.env.NODE_ENV === 'development') {
|
|
35
|
+
var namespace = __spreadArray(['etudes'], __read(subnamespace.split(':').filter(Boolean)), false).join(':');
|
|
36
|
+
if (typeof window === 'undefined')
|
|
37
|
+
debug_1.default.enable(namespace);
|
|
38
|
+
return (0, debug_1.default)(namespace);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
42
|
+
return function () { };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = useDebug;
|
|
46
|
+
//# sourceMappingURL=useDebug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebug.js","sourceRoot":"/","sources":["utils/useDebug.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAyB;AAEzB,SAAwB,QAAQ,CAAC,YAAiB;IAAjB,6BAAA,EAAA,iBAAiB;IAChD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;QAC1C,IAAM,SAAS,GAAG,eAAC,QAAQ,UAAK,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAE,IAAI,CAAC,GAAG,CAAC,CAAA;QAClF,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,eAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAE1D,OAAO,IAAA,eAAK,EAAC,SAAS,CAAC,CAAA;KACxB;SACI;QACH,gEAAgE;QAChE,OAAO,cAAO,CAAC,CAAA;KAChB;AACH,CAAC;AAXD,2BAWC","sourcesContent":["import debug from 'debug'\n\nexport default function useDebug(subnamespace = '') {\n if (process.env.NODE_ENV === 'development') {\n const namespace = ['etudes', ...subnamespace.split(':').filter(Boolean)].join(':')\n if (typeof window === 'undefined') debug.enable(namespace)\n\n return debug(namespace)\n }\n else {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {}\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etudes",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A study of
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A study of headless React components",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "rimraf lib",
|
|
8
8
|
"prebuild": "npm run lint",
|
|
9
9
|
"build": "npm run clean && cross-env NODE_ENV=production tsc",
|
|
10
10
|
"pages": "rimraf .gh-pages && webpack --config demo/config/build.conf.ts",
|
|
11
|
-
"demo": "npm run clean && concurrently \"cross-env NODE_ENV=production tsc -w\" \"wait-on lib && cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts\"",
|
|
11
|
+
"demo": "npm run clean && concurrently \"cross-env NODE_ENV=production tsc -w --diagnostics false\" \"wait-on lib && cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts\"",
|
|
12
12
|
"test": "echo \"No tests yet :)\"",
|
|
13
13
|
"lint": "eslint --ext .ts --ext .tsx src demo",
|
|
14
14
|
"lint:fix": "npm run lint -- --fix"
|
|
@@ -29,63 +29,55 @@
|
|
|
29
29
|
"lib"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
32
|
+
"@babel/core": "^7.20.2",
|
|
33
|
+
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
34
|
+
"@babel/preset-env": "^7.20.2",
|
|
35
35
|
"@babel/preset-react": "^7.18.6",
|
|
36
36
|
"@babel/preset-typescript": "^7.18.6",
|
|
37
|
-
"@babel/runtime": "^7.18.9",
|
|
38
37
|
"@types/debug": "^4.1.7",
|
|
39
38
|
"@types/html-webpack-plugin": "^3.2.6",
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/react": "^18.0.
|
|
42
|
-
"@types/react-dom": "^18.0.6",
|
|
39
|
+
"@types/react": "^18.0.25",
|
|
40
|
+
"@types/react-dom": "^18.0.8",
|
|
43
41
|
"@types/react-transition-group": "^4.4.5",
|
|
44
42
|
"@types/styled-components": "^5.1.26",
|
|
45
43
|
"@types/webpack": "^5.28.0",
|
|
46
|
-
"@types/webpack-env": "^1.
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
-
"babel-loader": "^
|
|
44
|
+
"@types/webpack-env": "^1.18.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
46
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
47
|
+
"babel-loader": "^9.1.0",
|
|
50
48
|
"babel-plugin-styled-components": "^2.0.7",
|
|
51
|
-
"concurrently": "^7.
|
|
49
|
+
"concurrently": "^7.5.0",
|
|
52
50
|
"cross-env": "^7.0.3",
|
|
53
51
|
"debug": "^4.3.4",
|
|
54
|
-
"eslint": "^8.
|
|
55
|
-
"file-loader": "^6.2.0",
|
|
52
|
+
"eslint": "^8.27.0",
|
|
56
53
|
"html-webpack-plugin": "^5.5.0",
|
|
57
|
-
"promptu": "^5.9.0",
|
|
58
|
-
"raw-loader": "^4.0.2",
|
|
59
54
|
"react": "^18.2.0",
|
|
60
55
|
"react-dom": "^18.2.0",
|
|
61
|
-
"react-router": "^6.3
|
|
62
|
-
"react-router-dom": "^6.3
|
|
56
|
+
"react-router": "^6.4.3",
|
|
57
|
+
"react-router-dom": "^6.4.3",
|
|
63
58
|
"rimraf": "^3.0.2",
|
|
64
|
-
"styled-components": "^5.3.
|
|
65
|
-
"ts-loader": "^9.3.1",
|
|
59
|
+
"styled-components": "^5.3.6",
|
|
66
60
|
"ts-node": "^10.9.1",
|
|
67
|
-
"typescript": "^4.
|
|
68
|
-
"url-loader": "^4.1.1",
|
|
61
|
+
"typescript": "^4.8.4",
|
|
69
62
|
"wait-on": "^6.0.1",
|
|
70
|
-
"webpack": "^5.
|
|
63
|
+
"webpack": "^5.75.0",
|
|
71
64
|
"webpack-cli": "^4.10.0",
|
|
72
|
-
"webpack-dev-server": "^4.
|
|
65
|
+
"webpack-dev-server": "^4.11.1"
|
|
73
66
|
},
|
|
74
67
|
"dependencies": {
|
|
75
|
-
"classnames": "^2.3.
|
|
68
|
+
"classnames": "^2.3.2",
|
|
76
69
|
"dirty-dom": "^7.2.0",
|
|
70
|
+
"fast-deep-equal": "^3.1.3",
|
|
77
71
|
"interactjs": "^1.10.17",
|
|
78
|
-
"lodash": "^4.17.21",
|
|
79
72
|
"react-transition-group": "^4.4.5",
|
|
80
73
|
"resize-observer-polyfill": "^1.5.1",
|
|
81
74
|
"spase": "^6.4.0"
|
|
82
75
|
},
|
|
83
76
|
"peerDependencies": {
|
|
84
|
-
"react": "^18.2.0"
|
|
85
|
-
"styled-components": "^5.3.5"
|
|
77
|
+
"react": "^18.2.0"
|
|
86
78
|
},
|
|
87
79
|
"optionalDependencies": {
|
|
88
|
-
"react-router": "^6.3
|
|
89
|
-
"react-router-dom": "^6.3
|
|
80
|
+
"react-router": "^6.4.3",
|
|
81
|
+
"react-router-dom": "^6.4.3"
|
|
90
82
|
}
|
|
91
83
|
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, PureComponent } from 'react';
|
|
2
|
-
export interface Props {
|
|
3
|
-
/**
|
|
4
|
-
* Class attribute of the root element.
|
|
5
|
-
*/
|
|
6
|
-
className?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Inline style attribute of the root element.
|
|
9
|
-
*/
|
|
10
|
-
style?: CSSProperties;
|
|
11
|
-
/**
|
|
12
|
-
* Indicates whether selections can be toggled. For example, in the case of
|
|
13
|
-
* a vertical list of selectable rows, being able to toggle a row means it
|
|
14
|
-
* gets deselected when selected again. Being unable to toggle the row means
|
|
15
|
-
* it does not get deselected when selected again.
|
|
16
|
-
*/
|
|
17
|
-
isTogglable?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Indicates whether selections are retained. For example, in the case of
|
|
20
|
-
* a vertical list of clickable rows, being able to retain a selection means
|
|
21
|
-
* when the row is clicked, it becomes and stays selected. Being unable to
|
|
22
|
-
* retain a selection means when the row is clicked, it does not become
|
|
23
|
-
* selected. It is simply clicked and the subsequent event is dispatched.
|
|
24
|
-
*/
|
|
25
|
-
shouldStaySelected?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* The default selected index. Any value below 0 indicates that nothing is
|
|
28
|
-
* selected.
|
|
29
|
-
*/
|
|
30
|
-
defaultSelectedIndex?: number;
|
|
31
|
-
/**
|
|
32
|
-
* Handler invoked when an index is deselected.
|
|
33
|
-
*/
|
|
34
|
-
onDeselectAt?: (index: number) => void;
|
|
35
|
-
/**
|
|
36
|
-
* Handler invoked when an index is selected.
|
|
37
|
-
*/
|
|
38
|
-
onSelectAt?: (index: number) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface State {
|
|
41
|
-
/**
|
|
42
|
-
* The current selected index. Any value less than 0 indicates that no index
|
|
43
|
-
* is selected.
|
|
44
|
-
*/
|
|
45
|
-
selectedIndex?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* An abstract component that mimics and handles index selection in an abstract
|
|
49
|
-
* collection.
|
|
50
|
-
*/
|
|
51
|
-
export default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {
|
|
52
|
-
constructor(props: P);
|
|
53
|
-
componentDidMount(): void;
|
|
54
|
-
componentDidUpdate(prevProps: P, prevState: S): void;
|
|
55
|
-
render(): JSX.Element;
|
|
56
|
-
/**
|
|
57
|
-
* Checks if an index is out of range.
|
|
58
|
-
*
|
|
59
|
-
* @param index - The index to check.
|
|
60
|
-
*
|
|
61
|
-
* @returns `true` if the index is out of range, `false` otherwise.
|
|
62
|
-
*/
|
|
63
|
-
isIndexOutOfRange(index: number): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Checks if an index is selected.
|
|
66
|
-
*
|
|
67
|
-
* @param index - The index to check.
|
|
68
|
-
*
|
|
69
|
-
* @returns `true` if the index is selected, `false` otherwise.
|
|
70
|
-
*/
|
|
71
|
-
isSelectedAt(index: number): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Toggles an index, i.e. reverses its selected state.
|
|
74
|
-
*
|
|
75
|
-
* @param index - The index to toggle.
|
|
76
|
-
*/
|
|
77
|
-
toggleAt(index: number): void;
|
|
78
|
-
/**
|
|
79
|
-
* Selects an index.
|
|
80
|
-
*
|
|
81
|
-
* @param index - The index to select.
|
|
82
|
-
*/
|
|
83
|
-
selectAt(index: number): void;
|
|
84
|
-
/**
|
|
85
|
-
* Deselects an index if it is currently selected.
|
|
86
|
-
*
|
|
87
|
-
* @param index - The index to deselect.
|
|
88
|
-
*/
|
|
89
|
-
deselectAt(index: number): void;
|
|
90
|
-
/**
|
|
91
|
-
* Deselects the currently selected index.
|
|
92
|
-
*/
|
|
93
|
-
deselectCurrent(): void;
|
|
94
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
var react_1 = __importStar(require("react"));
|
|
42
|
-
var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : function () { };
|
|
43
|
-
/**
|
|
44
|
-
* An abstract component that mimics and handles index selection in an abstract
|
|
45
|
-
* collection.
|
|
46
|
-
*/
|
|
47
|
-
var AbstractSelectableCollection = /** @class */ (function (_super) {
|
|
48
|
-
__extends(AbstractSelectableCollection, _super);
|
|
49
|
-
function AbstractSelectableCollection(props) {
|
|
50
|
-
var _this = this;
|
|
51
|
-
var _a;
|
|
52
|
-
_this = _super.call(this, props) || this;
|
|
53
|
-
_this.state = {
|
|
54
|
-
selectedIndex: (_a = _this.props.defaultSelectedIndex) !== null && _a !== void 0 ? _a : -1,
|
|
55
|
-
};
|
|
56
|
-
return _this;
|
|
57
|
-
}
|
|
58
|
-
AbstractSelectableCollection.prototype.componentDidMount = function () {
|
|
59
|
-
var _a, _b, _c;
|
|
60
|
-
if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {
|
|
61
|
-
(_b = (_a = this.props).onSelectAt) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.state.selectedIndex) !== null && _c !== void 0 ? _c : -1);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
AbstractSelectableCollection.prototype.componentDidUpdate = function (prevProps, prevState) {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
var _c = this.props, shouldStaySelected = _c.shouldStaySelected, onSelectAt = _c.onSelectAt, onDeselectAt = _c.onDeselectAt;
|
|
67
|
-
var prevSelectedIndex = (_a = prevState.selectedIndex) !== null && _a !== void 0 ? _a : -1;
|
|
68
|
-
var selectedIndex = (_b = this.state.selectedIndex) !== null && _b !== void 0 ? _b : -1;
|
|
69
|
-
if (prevState.selectedIndex !== selectedIndex) {
|
|
70
|
-
debug("Selected index changed: ".concat(selectedIndex));
|
|
71
|
-
if (shouldStaySelected === true) {
|
|
72
|
-
if (!this.isIndexOutOfRange(prevSelectedIndex))
|
|
73
|
-
onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(prevSelectedIndex);
|
|
74
|
-
if (!this.isIndexOutOfRange(selectedIndex))
|
|
75
|
-
onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(selectedIndex);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
AbstractSelectableCollection.prototype.render = function () {
|
|
80
|
-
return react_1.default.createElement(react_1.Fragment, null);
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Checks if an index is out of range.
|
|
84
|
-
*
|
|
85
|
-
* @param index - The index to check.
|
|
86
|
-
*
|
|
87
|
-
* @returns `true` if the index is out of range, `false` otherwise.
|
|
88
|
-
*/
|
|
89
|
-
AbstractSelectableCollection.prototype.isIndexOutOfRange = function (index) {
|
|
90
|
-
if (index < 0)
|
|
91
|
-
return true;
|
|
92
|
-
return false;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Checks if an index is selected.
|
|
96
|
-
*
|
|
97
|
-
* @param index - The index to check.
|
|
98
|
-
*
|
|
99
|
-
* @returns `true` if the index is selected, `false` otherwise.
|
|
100
|
-
*/
|
|
101
|
-
AbstractSelectableCollection.prototype.isSelectedAt = function (index) {
|
|
102
|
-
return (this.state.selectedIndex === index);
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Toggles an index, i.e. reverses its selected state.
|
|
106
|
-
*
|
|
107
|
-
* @param index - The index to toggle.
|
|
108
|
-
*/
|
|
109
|
-
AbstractSelectableCollection.prototype.toggleAt = function (index) {
|
|
110
|
-
if (this.props.isTogglable === true && this.isSelectedAt(index)) {
|
|
111
|
-
this.deselectAt(index);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.selectAt(index);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Selects an index.
|
|
119
|
-
*
|
|
120
|
-
* @param index - The index to select.
|
|
121
|
-
*/
|
|
122
|
-
AbstractSelectableCollection.prototype.selectAt = function (index) {
|
|
123
|
-
if (this.props.shouldStaySelected === true) {
|
|
124
|
-
if (this.isSelectedAt(index))
|
|
125
|
-
return;
|
|
126
|
-
this.setState({ selectedIndex: index });
|
|
127
|
-
}
|
|
128
|
-
else if (this.props.onSelectAt) {
|
|
129
|
-
this.props.onSelectAt(index);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Deselects an index if it is currently selected.
|
|
134
|
-
*
|
|
135
|
-
* @param index - The index to deselect.
|
|
136
|
-
*/
|
|
137
|
-
AbstractSelectableCollection.prototype.deselectAt = function (index) {
|
|
138
|
-
if (!this.isSelectedAt(index))
|
|
139
|
-
return;
|
|
140
|
-
this.setState({ selectedIndex: -1 });
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Deselects the currently selected index.
|
|
144
|
-
*/
|
|
145
|
-
AbstractSelectableCollection.prototype.deselectCurrent = function () {
|
|
146
|
-
this.setState({ selectedIndex: -1 });
|
|
147
|
-
};
|
|
148
|
-
return AbstractSelectableCollection;
|
|
149
|
-
}(react_1.PureComponent));
|
|
150
|
-
exports.default = AbstractSelectableCollection;
|
|
151
|
-
//# sourceMappingURL=AbstractSelectableCollection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractSelectableCollection.js","sourceRoot":"/","sources":["AbstractSelectableCollection.tsx"],"names":[],"mappings":"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","sourcesContent":["import React, { CSSProperties, Fragment, PureComponent } from 'react'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:asc') : () => {}\n\nexport interface Props {\n /**\n * Class attribute of the root element.\n */\n className?: string\n\n /**\n * Inline style attribute of the root element.\n */\n style?: CSSProperties\n\n /**\n * Indicates whether selections can be toggled. For example, in the case of\n * a vertical list of selectable rows, being able to toggle a row means it\n * gets deselected when selected again. Being unable to toggle the row means\n * it does not get deselected when selected again.\n */\n isTogglable?: boolean\n\n /**\n * Indicates whether selections are retained. For example, in the case of\n * a vertical list of clickable rows, being able to retain a selection means\n * when the row is clicked, it becomes and stays selected. Being unable to\n * retain a selection means when the row is clicked, it does not become\n * selected. It is simply clicked and the subsequent event is dispatched.\n */\n shouldStaySelected?: boolean\n\n /**\n * The default selected index. Any value below 0 indicates that nothing is\n * selected.\n */\n defaultSelectedIndex?: number\n\n /**\n * Handler invoked when an index is deselected.\n */\n onDeselectAt?: (index: number) => void\n\n /**\n * Handler invoked when an index is selected.\n */\n onSelectAt?: (index: number) => void\n}\n\nexport interface State {\n /**\n * The current selected index. Any value less than 0 indicates that no index\n * is selected.\n */\n selectedIndex?: number\n}\n\n/**\n * An abstract component that mimics and handles index selection in an abstract\n * collection.\n */\nexport default class AbstractSelectableCollection<P extends Props = Props, S extends State = State> extends PureComponent<P, S> {\n constructor(props: P) {\n super(props)\n\n this.state = {\n selectedIndex: this.props.defaultSelectedIndex ?? -1,\n } as any\n }\n\n componentDidMount() {\n if (this.state.selectedIndex !== undefined && this.state.selectedIndex > -1) {\n this.props.onSelectAt?.(this.state.selectedIndex ?? -1)\n }\n }\n\n componentDidUpdate(prevProps: P, prevState: S) {\n const { shouldStaySelected, onSelectAt, onDeselectAt } = this.props\n const prevSelectedIndex = prevState.selectedIndex ?? -1\n const selectedIndex = this.state.selectedIndex ?? -1\n\n if (prevState.selectedIndex !== selectedIndex) {\n debug(`Selected index changed: ${selectedIndex}`)\n\n if (shouldStaySelected === true) {\n if (!this.isIndexOutOfRange(prevSelectedIndex)) onDeselectAt?.(prevSelectedIndex)\n if (!this.isIndexOutOfRange(selectedIndex)) onSelectAt?.(selectedIndex)\n }\n }\n }\n\n render() {\n return <Fragment/>\n }\n\n /**\n * Checks if an index is out of range.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is out of range, `false` otherwise.\n */\n isIndexOutOfRange(index: number): boolean {\n if (index < 0) return true\n return false\n }\n\n /**\n * Checks if an index is selected.\n *\n * @param index - The index to check.\n *\n * @returns `true` if the index is selected, `false` otherwise.\n */\n isSelectedAt(index: number): boolean {\n return (this.state.selectedIndex === index)\n }\n\n /**\n * Toggles an index, i.e. reverses its selected state.\n *\n * @param index - The index to toggle.\n */\n toggleAt(index: number) {\n if (this.props.isTogglable === true && this.isSelectedAt(index)) {\n this.deselectAt(index)\n }\n else {\n this.selectAt(index)\n }\n }\n\n /**\n * Selects an index.\n *\n * @param index - The index to select.\n */\n selectAt(index: number) {\n if (this.props.shouldStaySelected === true) {\n if (this.isSelectedAt(index)) return\n this.setState({ selectedIndex: index })\n }\n else if (this.props.onSelectAt) {\n this.props.onSelectAt(index)\n }\n }\n\n /**\n * Deselects an index if it is currently selected.\n *\n * @param index - The index to deselect.\n */\n deselectAt(index: number) {\n if (!this.isSelectedAt(index)) return\n this.setState({ selectedIndex: -1 })\n }\n\n /**\n * Deselects the currently selected index.\n */\n deselectCurrent() {\n this.setState({ selectedIndex: -1 })\n }\n}\n"]}
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FlattenSimpleInterpolation } from 'styled-components';
|
|
2
|
-
export declare type ExtendedCSSFunction<P = Record<string, never>> = (props: P) => FlattenSimpleInterpolation;
|
|
3
|
-
export declare type ExtendedCSSProps<P = Record<string, never>> = Readonly<{
|
|
4
|
-
extendedCSS: ExtendedCSSFunction<P>;
|
|
5
|
-
}>;
|
|
6
|
-
export declare type Range = Readonly<[number, number]>;
|
|
7
|
-
export declare type Orientation = 'horizontal' | 'vertical';
|
package/lib/types/index.js
DELETED
package/lib/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["types/index.ts"],"names":[],"mappings":"","sourcesContent":["import { FlattenSimpleInterpolation } from 'styled-components'\n\nexport type ExtendedCSSFunction<P = Record<string, never>> = (props: P) => FlattenSimpleInterpolation\n\nexport type ExtendedCSSProps<P = Record<string, never>> = Readonly<{ extendedCSS: ExtendedCSSFunction<P> }>\n\nexport type Range = Readonly<[number, number]>\n\nexport type Orientation = 'horizontal' | 'vertical'\n"]}
|