etudes 2.0.0 → 2.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/lib/Accordion.d.ts +4 -4
- package/lib/BurgerButton.d.ts +1 -1
- package/lib/Conditional.d.ts +1 -1
- package/lib/DebugConsole.d.ts +1 -1
- package/lib/Dial.d.ts +1 -1
- package/lib/Dropdown.d.ts +4 -4
- package/lib/Each.d.ts +1 -1
- package/lib/ExtractChild.d.ts +1 -1
- package/lib/ExtractChildren.d.ts +1 -1
- package/lib/FlatSVG.d.ts +1 -1
- package/lib/List.d.ts +3 -3
- package/lib/MasonryGrid.d.ts +2 -2
- package/lib/Panorama.d.ts +1 -1
- package/lib/PanoramaSlider.d.ts +1 -1
- package/lib/RangeSlider.d.ts +3 -3
- package/lib/Repeat.d.ts +1 -1
- package/lib/RotatingGallery.d.ts +1 -1
- package/lib/SelectableButton.d.ts +1 -1
- package/lib/Slider.d.ts +2 -2
- package/lib/StepwiseSlider.d.ts +2 -2
- package/lib/SwipeContainer.d.ts +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/Video.d.ts +1 -1
- package/lib/WithTooltip.d.ts +1 -1
- package/lib/hooks/useDragEffect.d.ts +3 -3
- package/lib/hooks/useInterval.d.ts +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +2 -2
- package/lib/hooks/useResizeEffect.d.ts +1 -1
- package/lib/hooks/useSearchParamState.d.ts +1 -1
- package/lib/providers/I18nProvider.d.ts +179 -0
- package/lib/providers/I18nProvider.js +470 -0
- package/lib/providers/I18nProvider.js.map +1 -0
- package/lib/providers/ScrollPositionProvider.d.ts +15 -0
- package/lib/providers/ScrollPositionProvider.js +112 -0
- package/lib/providers/ScrollPositionProvider.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +2 -2
- package/package.json +20 -19
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
+
if (!m) return o;
|
|
28
|
+
var i = m.call(o), r, ar = [], e;
|
|
29
|
+
try {
|
|
30
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
+
}
|
|
32
|
+
catch (error) { e = { error: error }; }
|
|
33
|
+
finally {
|
|
34
|
+
try {
|
|
35
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
+
}
|
|
37
|
+
finally { if (e) throw e.error; }
|
|
38
|
+
}
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.useScrollPosition = exports.ScrollPositionContext = void 0;
|
|
43
|
+
var react_1 = __importStar(require("react"));
|
|
44
|
+
var spase_1 = require("spase");
|
|
45
|
+
exports.ScrollPositionContext = (0, react_1.createContext)(undefined);
|
|
46
|
+
function ScrollPositionProvider(_a) {
|
|
47
|
+
var children = _a.children;
|
|
48
|
+
var _b = __read((0, react_1.useState)({
|
|
49
|
+
minPos: new spase_1.Point(),
|
|
50
|
+
maxPos: new spase_1.Point(),
|
|
51
|
+
pos: new spase_1.Point(),
|
|
52
|
+
step: new spase_1.Point(),
|
|
53
|
+
}), 2), value = _b[0], setValue = _b[1];
|
|
54
|
+
(0, react_1.useEffect)(function () {
|
|
55
|
+
var updateScrollPosition = function () {
|
|
56
|
+
var refRect = spase_1.Rect.fromViewport();
|
|
57
|
+
var refRectMin = refRect.clone({ x: 0, y: 0 });
|
|
58
|
+
var refRectFull = spase_1.Rect.from(window, { overflow: true });
|
|
59
|
+
if (!refRectFull)
|
|
60
|
+
return;
|
|
61
|
+
var refRectMax = refRectMin.clone({ x: refRectFull.width - refRect.width, y: refRectFull.height - refRect.height });
|
|
62
|
+
var step = new spase_1.Point([refRect.left / refRectMax.left, refRect.top / refRectMax.top]);
|
|
63
|
+
setValue({
|
|
64
|
+
minPos: new spase_1.Point([refRectMin.left, refRectMin.top]),
|
|
65
|
+
maxPos: new spase_1.Point([refRectMax.left, refRectMax.top]),
|
|
66
|
+
pos: new spase_1.Point([refRect.left, refRect.top]),
|
|
67
|
+
step: step,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
window.addEventListener('scroll', updateScrollPosition);
|
|
71
|
+
window.addEventListener('resize', updateScrollPosition);
|
|
72
|
+
window.addEventListener('orientationchange', updateScrollPosition);
|
|
73
|
+
updateScrollPosition();
|
|
74
|
+
return function () {
|
|
75
|
+
window.removeEventListener('scroll', updateScrollPosition);
|
|
76
|
+
window.removeEventListener('resize', updateScrollPosition);
|
|
77
|
+
window.removeEventListener('orientationchange', updateScrollPosition);
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
80
|
+
return (react_1.default.createElement(exports.ScrollPositionContext.Provider, { value: value }, children));
|
|
81
|
+
}
|
|
82
|
+
exports.default = ScrollPositionProvider;
|
|
83
|
+
function useScrollPosition(targetRef) {
|
|
84
|
+
var context = (0, react_1.useContext)(exports.ScrollPositionContext);
|
|
85
|
+
if (!context)
|
|
86
|
+
throw Error('Cannot fetch the current scroll position context, is the corresponding provider instated?');
|
|
87
|
+
if (!targetRef) {
|
|
88
|
+
return {
|
|
89
|
+
pos: context.pos,
|
|
90
|
+
step: context.step,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
var element = targetRef.current;
|
|
94
|
+
var refRect = spase_1.Rect.fromViewport();
|
|
95
|
+
var rect = spase_1.Rect.from(element);
|
|
96
|
+
if (!refRect || !rect) {
|
|
97
|
+
return {
|
|
98
|
+
pos: new spase_1.Point(),
|
|
99
|
+
step: new spase_1.Point(),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var posX = refRect.right - rect.left;
|
|
103
|
+
var posY = refRect.bottom - rect.top;
|
|
104
|
+
var stepX = posX / rect.width;
|
|
105
|
+
var stepY = posY / rect.height;
|
|
106
|
+
return {
|
|
107
|
+
pos: new spase_1.Point([posX, posY]),
|
|
108
|
+
step: new spase_1.Point([stepX, stepY]),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
exports.useScrollPosition = useScrollPosition;
|
|
112
|
+
//# sourceMappingURL=ScrollPositionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollPositionProvider.js","sourceRoot":"/","sources":["providers/ScrollPositionProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2G;AAC3G,+BAAmC;AActB,QAAA,qBAAqB,GAAG,IAAA,qBAAa,EAAyC,SAAS,CAAC,CAAA;AAErG,SAAwB,sBA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AAC,OAAO,IAAI,CAAC,IAAI,EAAE;QACrB,OAAO;YACL,GAAG,EAAE,IAAI,aAAK,EAAE;YAChB,IAAI,EAAE,IAAI,aAAK,EAAE;SAClB,CAAA;KACF;IAED,IAAM,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAA;IACtC,IAAM,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAA;IACtC,IAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IAC/B,IAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,CAAA;IAEhC,OAAO;QACL,GAAG,EAAE,IAAI,aAAK,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAI,aAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KAChC,CAAA;AACH,CAAC;AAhCD,8CAgCC","sourcesContent":["import React, { createContext, PropsWithChildren, RefObject, useContext, useEffect, useState } from 'react'\nimport { Point, Rect } from 'spase'\n\ntype ScrollPosition = {\n pos: Point\n step: Point\n}\n\ntype ScrollPositionContextValue = ScrollPosition & {\n minPos: Point\n maxPos: Point\n}\n\ntype ScrollPositionProviderProps = PropsWithChildren\n\nexport const ScrollPositionContext = createContext<ScrollPositionContextValue | undefined>(undefined)\n\nexport default function ScrollPositionProvider({\n children,\n}: ScrollPositionProviderProps) {\n const [value, setValue] = useState<ScrollPositionContextValue>({\n minPos: new Point(),\n maxPos: new Point(),\n pos: new Point(),\n step: new Point(),\n })\n\n useEffect(() => {\n const updateScrollPosition = () => {\n const refRect = Rect.fromViewport()\n const refRectMin = refRect.clone({ x: 0, y: 0 })\n const refRectFull = Rect.from(window, { overflow: true })\n\n if (!refRectFull) return\n\n const refRectMax = refRectMin.clone({ x: refRectFull.width - refRect.width, y: refRectFull.height - refRect.height })\n const step = new Point([refRect.left / refRectMax.left, refRect.top / refRectMax.top])\n\n setValue({\n minPos: new Point([refRectMin.left, refRectMin.top]),\n maxPos: new Point([refRectMax.left, refRectMax.top]),\n pos: new Point([refRect.left, refRect.top]),\n step,\n })\n }\n\n window.addEventListener('scroll', updateScrollPosition)\n window.addEventListener('resize', updateScrollPosition)\n window.addEventListener('orientationchange', updateScrollPosition)\n\n updateScrollPosition()\n\n return () => {\n window.removeEventListener('scroll', updateScrollPosition)\n window.removeEventListener('resize', updateScrollPosition)\n window.removeEventListener('orientationchange', updateScrollPosition)\n }\n }, [])\n\n return (\n <ScrollPositionContext.Provider value={value}>\n {children}\n </ScrollPositionContext.Provider>\n )\n}\n\nexport function useScrollPosition(targetRef?: RefObject<Element>): ScrollPosition {\n const context = useContext(ScrollPositionContext)\n if (!context) throw Error('Cannot fetch the current scroll position context, is the corresponding provider instated?')\n\n if (!targetRef) {\n return {\n pos: context.pos,\n step: context.step,\n }\n }\n\n const element = targetRef.current\n\n const refRect = Rect.fromViewport()\n const rect = Rect.from(element)\n\n if (!refRect || !rect) {\n return {\n pos: new Point(),\n step: new Point(),\n }\n }\n\n const posX = refRect.right - rect.left\n const posY = refRect.bottom - rect.top\n const stepX = posX / rect.width\n const stepY = posY / rect.height\n\n return {\n pos: new Point([posX, posY]),\n step: new Point([stepX, stepY]),\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSXElementConstructor, ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type ComponentTypeDict = Record<string, JSXElementConstructor<any>>;
|
|
3
|
+
type ComponentElementDict<T extends ComponentTypeDict> = Record<keyof T, JSX.Element>;
|
|
4
4
|
export default function asComponentDict<T extends ComponentTypeDict>(children?: ReactNode, typeDict?: T): Partial<ComponentElementDict<T>>;
|
|
5
5
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etudes",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A study of headless React components",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -29,55 +29,56 @@
|
|
|
29
29
|
"lib"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.20.
|
|
32
|
+
"@babel/core": "^7.20.12",
|
|
33
33
|
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
34
34
|
"@babel/preset-env": "^7.20.2",
|
|
35
35
|
"@babel/preset-react": "^7.18.6",
|
|
36
36
|
"@babel/preset-typescript": "^7.18.6",
|
|
37
37
|
"@types/debug": "^4.1.7",
|
|
38
38
|
"@types/html-webpack-plugin": "^3.2.6",
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/react
|
|
39
|
+
"@types/node-polyglot": "^2.4.2",
|
|
40
|
+
"@types/react": "^18.0.27",
|
|
41
|
+
"@types/react-dom": "^18.0.10",
|
|
41
42
|
"@types/react-transition-group": "^4.4.5",
|
|
42
43
|
"@types/styled-components": "^5.1.26",
|
|
43
44
|
"@types/webpack": "^5.28.0",
|
|
44
45
|
"@types/webpack-env": "^1.18.0",
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
46
|
-
"@typescript-eslint/parser": "^5.
|
|
47
|
-
"babel-loader": "^9.1.
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.50.0",
|
|
48
|
+
"babel-loader": "^9.1.2",
|
|
48
49
|
"babel-plugin-styled-components": "^2.0.7",
|
|
49
|
-
"concurrently": "^7.
|
|
50
|
+
"concurrently": "^7.6.0",
|
|
50
51
|
"cross-env": "^7.0.3",
|
|
51
52
|
"debug": "^4.3.4",
|
|
52
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^8.33.0",
|
|
53
54
|
"html-webpack-plugin": "^5.5.0",
|
|
54
55
|
"react": "^18.2.0",
|
|
55
56
|
"react-dom": "^18.2.0",
|
|
56
|
-
"react-router": "^6.
|
|
57
|
-
"react-router-dom": "^6.
|
|
58
|
-
"rimraf": "^
|
|
57
|
+
"react-router": "^6.8.0",
|
|
58
|
+
"react-router-dom": "^6.8.0",
|
|
59
|
+
"rimraf": "^4.1.2",
|
|
59
60
|
"styled-components": "^5.3.6",
|
|
60
61
|
"ts-node": "^10.9.1",
|
|
61
|
-
"typescript": "^4.
|
|
62
|
-
"wait-on": "^
|
|
62
|
+
"typescript": "^4.9.5",
|
|
63
|
+
"wait-on": "^7.0.1",
|
|
63
64
|
"webpack": "^5.75.0",
|
|
64
|
-
"webpack-cli": "^
|
|
65
|
+
"webpack-cli": "^5.0.1",
|
|
65
66
|
"webpack-dev-server": "^4.11.1"
|
|
66
67
|
},
|
|
67
68
|
"dependencies": {
|
|
68
69
|
"classnames": "^2.3.2",
|
|
69
|
-
"dirty-dom": "^7.2.0",
|
|
70
70
|
"fast-deep-equal": "^3.1.3",
|
|
71
71
|
"interactjs": "^1.10.17",
|
|
72
|
+
"node-polyglot": "^2.5.0",
|
|
72
73
|
"react-transition-group": "^4.4.5",
|
|
73
74
|
"resize-observer-polyfill": "^1.5.1",
|
|
74
|
-
"spase": "^6.
|
|
75
|
+
"spase": "^6.5.0"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
77
78
|
"react": "^18.2.0"
|
|
78
79
|
},
|
|
79
80
|
"optionalDependencies": {
|
|
80
|
-
"react-router": "^6.
|
|
81
|
-
"react-router-dom": "^6.
|
|
81
|
+
"react-router": "^6.8.0",
|
|
82
|
+
"react-router-dom": "^6.8.0"
|
|
82
83
|
}
|
|
83
84
|
}
|