@number-flow/react 0.2.0 → 0.2.1
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/LICENSE.md +21 -0
- package/README.md +3 -2
- package/dist/index.js +12 -5
- package/dist/index.mjs +12 -5
- package/package.json +4 -6
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Maxwell Barvian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
[](https://number-flow.barvian.me)
|
|
2
|
+
|
|
1
3
|
# Number Flow for React
|
|
2
4
|
|
|
3
5
|
A React component to transition & format numbers.
|
|
4
6
|
|
|
5
|
-
[](https://number-flow.barvian.me)
|
|
6
|
-
|
|
7
7
|
[](https://npmjs.com/package/@number-flow/react)
|
|
8
|
+
[](https://bundlephobia.com/package/@number-flow/react@latest)
|
|
8
9
|
[](https://x.com/mbarvian)
|
|
9
10
|
|
|
10
11
|
---
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ __export(src_exports, {
|
|
|
45
45
|
module.exports = __toCommonJS(src_exports);
|
|
46
46
|
var React = __toESM(require("react"));
|
|
47
47
|
var import_number_flow = require("number-flow");
|
|
48
|
+
var isReact19 = React.version.startsWith("19.");
|
|
48
49
|
var OBSERVED_ATTRIBUTES = ["parts"];
|
|
49
50
|
var NumberFlowElement = class extends import_number_flow.NumberFlowLite {
|
|
50
51
|
attributeChangedCallback(attr, _oldValue, newValue) {
|
|
@@ -54,6 +55,7 @@ var NumberFlowElement = class extends import_number_flow.NumberFlowLite {
|
|
|
54
55
|
NumberFlowElement.observedAttributes = OBSERVED_ATTRIBUTES;
|
|
55
56
|
NumberFlowElement.define();
|
|
56
57
|
var formatters = {};
|
|
58
|
+
var serializeParts = isReact19 ? (p) => p : JSON.stringify;
|
|
57
59
|
var _el;
|
|
58
60
|
var NumberFlowImpl = class extends React.Component {
|
|
59
61
|
constructor(props) {
|
|
@@ -83,15 +85,20 @@ var NumberFlowImpl = class extends React.Component {
|
|
|
83
85
|
__privateGet(this, _el).addEventListener("animationsfinish", this.props.onAnimationsFinish);
|
|
84
86
|
}
|
|
85
87
|
componentDidMount() {
|
|
88
|
+
if (isReact19 && __privateGet(this, _el)) {
|
|
89
|
+
__privateGet(this, _el).parts = this.props.parts;
|
|
90
|
+
}
|
|
86
91
|
this.updateNonPartsProps();
|
|
87
92
|
}
|
|
88
93
|
getSnapshotBeforeUpdate(prevProps) {
|
|
89
94
|
this.updateNonPartsProps(prevProps);
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
95
|
+
if (this.props.isolate) return false;
|
|
96
|
+
if (prevProps.parts === this.props.parts) return false;
|
|
97
|
+
__privateGet(this, _el)?.willUpdate();
|
|
98
|
+
return true;
|
|
92
99
|
}
|
|
93
|
-
componentDidUpdate(
|
|
94
|
-
if (
|
|
100
|
+
componentDidUpdate(_, __, snapshot) {
|
|
101
|
+
if (snapshot) __privateGet(this, _el)?.didUpdate();
|
|
95
102
|
}
|
|
96
103
|
handleRef(el) {
|
|
97
104
|
if (this.props.innerRef) this.props.innerRef.current = el;
|
|
@@ -122,7 +129,7 @@ var NumberFlowImpl = class extends React.Component {
|
|
|
122
129
|
"data-will-change": willChange ? "" : void 0,
|
|
123
130
|
class: className,
|
|
124
131
|
...rest,
|
|
125
|
-
parts:
|
|
132
|
+
parts: serializeParts(parts)
|
|
126
133
|
},
|
|
127
134
|
/* @__PURE__ */ React.createElement(import_number_flow.SlottedTag, { style: (0, import_number_flow.slottedStyles)({ willChange }) }, parts.formatted)
|
|
128
135
|
)
|
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
prefersReducedMotion,
|
|
18
18
|
canAnimate as _canAnimate
|
|
19
19
|
} from "number-flow";
|
|
20
|
+
var isReact19 = React.version.startsWith("19.");
|
|
20
21
|
var OBSERVED_ATTRIBUTES = ["parts"];
|
|
21
22
|
var NumberFlowElement = class extends NumberFlowLite {
|
|
22
23
|
attributeChangedCallback(attr, _oldValue, newValue) {
|
|
@@ -26,6 +27,7 @@ var NumberFlowElement = class extends NumberFlowLite {
|
|
|
26
27
|
NumberFlowElement.observedAttributes = OBSERVED_ATTRIBUTES;
|
|
27
28
|
NumberFlowElement.define();
|
|
28
29
|
var formatters = {};
|
|
30
|
+
var serializeParts = isReact19 ? (p) => p : JSON.stringify;
|
|
29
31
|
var _el;
|
|
30
32
|
var NumberFlowImpl = class extends React.Component {
|
|
31
33
|
constructor(props) {
|
|
@@ -55,15 +57,20 @@ var NumberFlowImpl = class extends React.Component {
|
|
|
55
57
|
__privateGet(this, _el).addEventListener("animationsfinish", this.props.onAnimationsFinish);
|
|
56
58
|
}
|
|
57
59
|
componentDidMount() {
|
|
60
|
+
if (isReact19 && __privateGet(this, _el)) {
|
|
61
|
+
__privateGet(this, _el).parts = this.props.parts;
|
|
62
|
+
}
|
|
58
63
|
this.updateNonPartsProps();
|
|
59
64
|
}
|
|
60
65
|
getSnapshotBeforeUpdate(prevProps) {
|
|
61
66
|
this.updateNonPartsProps(prevProps);
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
67
|
+
if (this.props.isolate) return false;
|
|
68
|
+
if (prevProps.parts === this.props.parts) return false;
|
|
69
|
+
__privateGet(this, _el)?.willUpdate();
|
|
70
|
+
return true;
|
|
64
71
|
}
|
|
65
|
-
componentDidUpdate(
|
|
66
|
-
if (
|
|
72
|
+
componentDidUpdate(_, __, snapshot) {
|
|
73
|
+
if (snapshot) __privateGet(this, _el)?.didUpdate();
|
|
67
74
|
}
|
|
68
75
|
handleRef(el) {
|
|
69
76
|
if (this.props.innerRef) this.props.innerRef.current = el;
|
|
@@ -94,7 +101,7 @@ var NumberFlowImpl = class extends React.Component {
|
|
|
94
101
|
"data-will-change": willChange ? "" : void 0,
|
|
95
102
|
class: className,
|
|
96
103
|
...rest,
|
|
97
|
-
parts:
|
|
104
|
+
parts: serializeParts(parts)
|
|
98
105
|
},
|
|
99
106
|
/* @__PURE__ */ React.createElement(SlottedTag, { style: slottedStyles({ willChange }) }, parts.formatted)
|
|
100
107
|
)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.1",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Maxwell Barvian",
|
|
9
9
|
"email": "max@barvian.me",
|
|
@@ -59,14 +59,12 @@
|
|
|
59
59
|
"tsup": "^8.2.4"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"react": "^18.3.1",
|
|
65
|
-
"react-dom": "^18.3.1"
|
|
62
|
+
"react": "^18 || ^19.0.0-rc-915b914b3a-20240515",
|
|
63
|
+
"react-dom": "^18"
|
|
66
64
|
},
|
|
67
65
|
"scripts": {
|
|
68
66
|
"build": "tsup --tsconfig tsconfig.build.json",
|
|
69
67
|
"dev": "tsup --watch",
|
|
70
|
-
"test": "pnpm -r --workspace-concurrency 1 --filter=\"./test
|
|
68
|
+
"test": "pnpm -r --workspace-concurrency 1 --filter=\"./test/apps/*\" test"
|
|
71
69
|
}
|
|
72
70
|
}
|