reflex 0.8.0a7__py3-none-any.whl → 0.8.1a1__py3-none-any.whl
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.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/web/utils/state.js +18 -1
- reflex/.templates/web/vite-plugin-safari-cachebust.js +160 -0
- reflex/.templates/web/vite.config.js +28 -6
- reflex/app.py +1 -1
- reflex/components/__init__.py +1 -0
- reflex/components/component.py +53 -1
- reflex/components/core/upload.py +5 -5
- reflex/components/el/__init__.py +7 -1
- reflex/components/radix/themes/typography/link.py +1 -30
- reflex/components/react_router/__init__.py +5 -0
- reflex/components/react_router/dom.py +69 -0
- reflex/components/recharts/recharts.py +2 -2
- reflex/constants/installer.py +2 -2
- reflex/environment.py +46 -0
- reflex/event.py +18 -1
- reflex/istate/data.py +142 -69
- reflex/plugins/tailwind_v4.py +2 -2
- reflex/state.py +3 -3
- reflex/utils/exec.py +27 -5
- reflex/utils/lazy_loader.py +7 -1
- reflex/utils/processes.py +2 -1
- reflex/utils/pyi_generator.py +17 -2
- {reflex-0.8.0a7.dist-info → reflex-0.8.1a1.dist-info}/METADATA +2 -2
- {reflex-0.8.0a7.dist-info → reflex-0.8.1a1.dist-info}/RECORD +27 -24
- {reflex-0.8.0a7.dist-info → reflex-0.8.1a1.dist-info}/WHEEL +0 -0
- {reflex-0.8.0a7.dist-info → reflex-0.8.1a1.dist-info}/entry_points.txt +0 -0
- {reflex-0.8.0a7.dist-info → reflex-0.8.1a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -295,6 +295,20 @@ export const applyEvent = async (event, socket, navigate, params) => {
|
|
|
295
295
|
return false;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
if (event.name == "_blur_focus") {
|
|
299
|
+
const ref =
|
|
300
|
+
event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref;
|
|
301
|
+
const current = ref?.current;
|
|
302
|
+
if (current === undefined || current?.blur === undefined) {
|
|
303
|
+
console.error(
|
|
304
|
+
`No element found for ref ${event.payload.ref} in _blur_focus`,
|
|
305
|
+
);
|
|
306
|
+
} else {
|
|
307
|
+
current.blur();
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
|
|
298
312
|
if (event.name == "_set_value") {
|
|
299
313
|
const ref =
|
|
300
314
|
event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref;
|
|
@@ -370,7 +384,10 @@ export const applyEvent = async (event, socket, navigate, params) => {
|
|
|
370
384
|
...Object.fromEntries(new URLSearchParams(window.location.search)),
|
|
371
385
|
...params(),
|
|
372
386
|
},
|
|
373
|
-
asPath:
|
|
387
|
+
asPath:
|
|
388
|
+
window.location.pathname +
|
|
389
|
+
window.location.search +
|
|
390
|
+
window.location.hash,
|
|
374
391
|
};
|
|
375
392
|
}
|
|
376
393
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/* vite-plugin-safari-cachebust.js
|
|
2
|
+
*
|
|
3
|
+
* Rewrite modulepreload <link> tags and ESM imports to include a cache-busting
|
|
4
|
+
* query parameter for Safari browser.
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/remix-run/react-router/issues/12761
|
|
7
|
+
*
|
|
8
|
+
* The issue seems to be Safari over-aggressive caching of ESM imports (and modulepreload)
|
|
9
|
+
* which does not respect the cache-control headers sent by the server. This approach
|
|
10
|
+
* allows hot reload to work in Safari when adding routes or changing dependencies.
|
|
11
|
+
*
|
|
12
|
+
* No equivalent transformation is needed for production builds, as the
|
|
13
|
+
* output already contains the file hash in the name.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import('vite').Plugin} Plugin
|
|
18
|
+
* @typedef {import('vite').ViteDevServer} ViteDevServer
|
|
19
|
+
* @typedef {import('http').IncomingMessage} IncomingMessage
|
|
20
|
+
* @typedef {import('http').ServerResponse} ServerResponse
|
|
21
|
+
* @typedef {import('connect').NextHandleFunction} NextHandleFunction
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const pluginName = "vite-plugin-safari-cachebust";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a Vite plugin that adds cache-busting for Safari browsers
|
|
28
|
+
* @returns {Plugin} The Vite plugin
|
|
29
|
+
*/
|
|
30
|
+
export default function safariCacheBustPlugin() {
|
|
31
|
+
return {
|
|
32
|
+
name: pluginName,
|
|
33
|
+
/**
|
|
34
|
+
* Configure the dev server with the Safari middleware
|
|
35
|
+
* @param {ViteDevServer} server - The Vite dev server instance
|
|
36
|
+
*/
|
|
37
|
+
configureServer(server) {
|
|
38
|
+
server.middlewares.use(createSafariMiddleware());
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Determines if the user agent is Safari
|
|
45
|
+
* @param {string} ua - The user agent string
|
|
46
|
+
* @returns {boolean} True if the browser is Safari
|
|
47
|
+
*/
|
|
48
|
+
function isSafari(ua) {
|
|
49
|
+
return /Safari/.test(ua) && !/Chrome/.test(ua);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a middleware that adds cache-busting for Safari browsers
|
|
54
|
+
* @returns {NextHandleFunction} The middleware function
|
|
55
|
+
*/
|
|
56
|
+
function createSafariMiddleware() {
|
|
57
|
+
// Set when a log message for rewriting n links has been emitted.
|
|
58
|
+
let _have_logged_n = -1;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Rewrites module import links in HTML content with cache-busting parameters
|
|
62
|
+
* @param {string} html - The HTML content to process
|
|
63
|
+
* @returns {string} The processed HTML content
|
|
64
|
+
*/
|
|
65
|
+
function rewriteModuleImports(html) {
|
|
66
|
+
const currentTimestamp = new Date().getTime();
|
|
67
|
+
const parts = html.split(/(<link\s+rel="modulepreload"[^>]*>)/g);
|
|
68
|
+
/** @type {[string, string][]} */
|
|
69
|
+
const replacements = parts
|
|
70
|
+
.map((chunk) => {
|
|
71
|
+
const match = chunk.match(
|
|
72
|
+
/<link\s+rel="modulepreload"\s+href="([^"]+)"(.*?)\/?>/,
|
|
73
|
+
);
|
|
74
|
+
if (!match) return;
|
|
75
|
+
|
|
76
|
+
const [fullMatch, href, rest] = match;
|
|
77
|
+
if (/^(https?:)?\/\//.test(href)) return;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const newHref = href.includes("?")
|
|
81
|
+
? `${href}&__reflex_ts=${currentTimestamp}`
|
|
82
|
+
: `${href}?__reflex_ts=${currentTimestamp}`;
|
|
83
|
+
return [href, newHref];
|
|
84
|
+
} catch {
|
|
85
|
+
// no worries;
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
if (replacements.length && _have_logged_n !== replacements.length) {
|
|
90
|
+
_have_logged_n = replacements.length;
|
|
91
|
+
console.debug(
|
|
92
|
+
`[${pluginName}] Rewrote ${replacements.length} modulepreload links with __reflex_ts param.`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return replacements.reduce((accumulator, [target, replacement]) => {
|
|
96
|
+
return accumulator.split(target).join(replacement);
|
|
97
|
+
}, html);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Middleware function to handle Safari cache busting
|
|
102
|
+
* @param {IncomingMessage} req - The incoming request
|
|
103
|
+
* @param {ServerResponse} res - The server response
|
|
104
|
+
* @param {(err?: any) => void} next - The next middleware function
|
|
105
|
+
* @returns {void}
|
|
106
|
+
*/
|
|
107
|
+
return function safariCacheBustMiddleware(req, res, next) {
|
|
108
|
+
const ua = req.headers["user-agent"] || "";
|
|
109
|
+
// Remove our special cache bust query param to avoid affecting lower middleware layers.
|
|
110
|
+
if (
|
|
111
|
+
req.url &&
|
|
112
|
+
(req.url.includes("?__reflex_ts=") || req.url.includes("&__reflex_ts="))
|
|
113
|
+
) {
|
|
114
|
+
req.url = req.url.replace(/(\?|&)__reflex_ts=\d+/, "");
|
|
115
|
+
return next();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Only apply this middleware for Safari browsers.
|
|
119
|
+
if (!isSafari(ua)) return next();
|
|
120
|
+
|
|
121
|
+
// Only transform requests that want HTML.
|
|
122
|
+
const header_accept = req.headers["accept"] || "";
|
|
123
|
+
if (
|
|
124
|
+
typeof header_accept !== "string" ||
|
|
125
|
+
!header_accept.includes("text/html")
|
|
126
|
+
) {
|
|
127
|
+
return next();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let buffer = "";
|
|
131
|
+
const _end = res.end.bind(res);
|
|
132
|
+
|
|
133
|
+
res.setHeader("x-modified-by", "vite-plugin-safari-cachebust");
|
|
134
|
+
/**
|
|
135
|
+
* Overridden write method to collect chunks
|
|
136
|
+
* @param {any} chunk - The chunk to write
|
|
137
|
+
* @param {...any} args - Additional arguments
|
|
138
|
+
* @returns {boolean} Result of the write operation
|
|
139
|
+
*/
|
|
140
|
+
res.write = function (chunk, ...args) {
|
|
141
|
+
buffer += chunk instanceof Buffer ? chunk.toString("utf-8") : chunk;
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Overridden end method to process and send the final response
|
|
147
|
+
* @param {any} chunk - The final chunk to write
|
|
148
|
+
* @param {...any} args - Additional arguments
|
|
149
|
+
* @returns {ServerResponse<IncomingMessage>} The server response
|
|
150
|
+
*/
|
|
151
|
+
res.end = function (chunk, ...args) {
|
|
152
|
+
if (chunk) {
|
|
153
|
+
buffer += chunk instanceof Buffer ? chunk.toString("utf-8") : chunk;
|
|
154
|
+
}
|
|
155
|
+
buffer = rewriteModuleImports(buffer);
|
|
156
|
+
return _end(buffer, ...args);
|
|
157
|
+
};
|
|
158
|
+
return next();
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import { fileURLToPath, URL } from "url";
|
|
2
2
|
import { reactRouter } from "@react-router/dev/vite";
|
|
3
3
|
import { defineConfig } from "vite";
|
|
4
|
+
import safariCacheBustPlugin from "./vite-plugin-safari-cachebust";
|
|
5
|
+
|
|
6
|
+
// Ensure that bun always uses the react-dom/server.node functions.
|
|
7
|
+
function alwaysUseReactDomServerNode() {
|
|
8
|
+
return {
|
|
9
|
+
name: "vite-plugin-always-use-react-dom-server-node",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
|
|
12
|
+
resolveId(source, importer) {
|
|
13
|
+
if (
|
|
14
|
+
typeof importer === "string" &&
|
|
15
|
+
importer.endsWith("/entry.server.node.tsx") &&
|
|
16
|
+
source.includes("react-dom/server")
|
|
17
|
+
) {
|
|
18
|
+
return this.resolve("react-dom/server.node", importer, {
|
|
19
|
+
skipSelf: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
4
26
|
|
|
5
27
|
export default defineConfig((config) => ({
|
|
6
|
-
plugins: [
|
|
28
|
+
plugins: [
|
|
29
|
+
alwaysUseReactDomServerNode(),
|
|
30
|
+
reactRouter(),
|
|
31
|
+
safariCacheBustPlugin(),
|
|
32
|
+
],
|
|
7
33
|
build: {
|
|
8
34
|
rollupOptions: {
|
|
9
35
|
jsx: {},
|
|
@@ -29,10 +55,6 @@ export default defineConfig((config) => ({
|
|
|
29
55
|
find: "@",
|
|
30
56
|
replacement: fileURLToPath(new URL("./public", import.meta.url)),
|
|
31
57
|
},
|
|
32
|
-
]
|
|
33
|
-
config.command === "build"
|
|
34
|
-
? [{ find: "react-dom/server", replacement: "react-dom/server.node" }]
|
|
35
|
-
: [],
|
|
36
|
-
),
|
|
58
|
+
],
|
|
37
59
|
},
|
|
38
60
|
}));
|
reflex/app.py
CHANGED
|
@@ -1741,7 +1741,7 @@ async def process(
|
|
|
1741
1741
|
if (path := router_data.get(constants.RouteVar.PATH))
|
|
1742
1742
|
else "404"
|
|
1743
1743
|
).removeprefix("/")
|
|
1744
|
-
state.router = RouterData(router_data)
|
|
1744
|
+
state.router = RouterData.from_router_data(router_data)
|
|
1745
1745
|
|
|
1746
1746
|
# Preprocess the event.
|
|
1747
1747
|
update = await app._preprocess(state, event)
|
reflex/components/__init__.py
CHANGED
reflex/components/component.py
CHANGED
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import contextlib
|
|
6
6
|
import copy
|
|
7
7
|
import dataclasses
|
|
8
|
+
import enum
|
|
8
9
|
import functools
|
|
9
10
|
import inspect
|
|
10
11
|
import typing
|
|
@@ -479,6 +480,57 @@ def _components_from(
|
|
|
479
480
|
return ()
|
|
480
481
|
|
|
481
482
|
|
|
483
|
+
def _deterministic_hash(value: object) -> int:
|
|
484
|
+
"""Hash a rendered dictionary.
|
|
485
|
+
|
|
486
|
+
Args:
|
|
487
|
+
value: The dictionary to hash.
|
|
488
|
+
|
|
489
|
+
Returns:
|
|
490
|
+
The hash of the dictionary.
|
|
491
|
+
|
|
492
|
+
Raises:
|
|
493
|
+
TypeError: If the value is not hashable.
|
|
494
|
+
"""
|
|
495
|
+
if isinstance(value, BaseComponent):
|
|
496
|
+
# If the value is a component, hash its rendered code.
|
|
497
|
+
rendered_code = value.render()
|
|
498
|
+
return _deterministic_hash(rendered_code)
|
|
499
|
+
if isinstance(value, Var):
|
|
500
|
+
return _deterministic_hash((value._js_expr, value._get_all_var_data()))
|
|
501
|
+
if isinstance(value, VarData):
|
|
502
|
+
return _deterministic_hash(dataclasses.asdict(value))
|
|
503
|
+
if isinstance(value, dict):
|
|
504
|
+
# Sort the dictionary to ensure consistent hashing.
|
|
505
|
+
return _deterministic_hash(
|
|
506
|
+
tuple(sorted((k, _deterministic_hash(v)) for k, v in value.items()))
|
|
507
|
+
)
|
|
508
|
+
if isinstance(value, int):
|
|
509
|
+
# Hash numbers and booleans directly.
|
|
510
|
+
return int(value)
|
|
511
|
+
if isinstance(value, float):
|
|
512
|
+
return _deterministic_hash(str(value))
|
|
513
|
+
if isinstance(value, str):
|
|
514
|
+
return int(md5(f'"{value}"'.encode()).hexdigest(), 16)
|
|
515
|
+
if isinstance(value, (tuple, list)):
|
|
516
|
+
# Hash tuples by hashing each element.
|
|
517
|
+
return _deterministic_hash(
|
|
518
|
+
"[" + ",".join(map(str, map(_deterministic_hash, value))) + "]"
|
|
519
|
+
)
|
|
520
|
+
if isinstance(value, enum.Enum):
|
|
521
|
+
# Hash enums by their name.
|
|
522
|
+
return _deterministic_hash(str(value))
|
|
523
|
+
if value is None:
|
|
524
|
+
# Hash None as a special case.
|
|
525
|
+
return _deterministic_hash("None")
|
|
526
|
+
|
|
527
|
+
msg = (
|
|
528
|
+
f"Cannot hash value `{value}` of type `{type(value).__name__}`. "
|
|
529
|
+
"Only BaseComponent, Var, VarData, dict, str, tuple, and enum.Enum are supported."
|
|
530
|
+
)
|
|
531
|
+
raise TypeError(msg)
|
|
532
|
+
|
|
533
|
+
|
|
482
534
|
DEFAULT_TRIGGERS: Mapping[str, types.ArgsSpec | Sequence[types.ArgsSpec]] = {
|
|
483
535
|
EventTriggers.ON_FOCUS: no_args_event_spec,
|
|
484
536
|
EventTriggers.ON_BLUR: no_args_event_spec,
|
|
@@ -2430,7 +2482,7 @@ class StatefulComponent(BaseComponent):
|
|
|
2430
2482
|
return None
|
|
2431
2483
|
|
|
2432
2484
|
# Compute the hash based on the rendered code.
|
|
2433
|
-
code_hash =
|
|
2485
|
+
code_hash = _deterministic_hash(rendered_code)
|
|
2434
2486
|
|
|
2435
2487
|
# Format the tag name including the hash.
|
|
2436
2488
|
return format.format_state_name(
|
reflex/components/core/upload.py
CHANGED
|
@@ -50,7 +50,7 @@ upload_files_context_var_data: VarData = VarData(
|
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
53
|
+
def upload_file(id_: str | Var[str] = DEFAULT_UPLOAD_ID) -> Var:
|
|
54
54
|
"""Get the file upload drop trigger.
|
|
55
55
|
|
|
56
56
|
This var is passed to the dropzone component to update the file list when a
|
|
@@ -62,7 +62,7 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
62
62
|
Returns:
|
|
63
63
|
A var referencing the file upload drop trigger.
|
|
64
64
|
"""
|
|
65
|
-
id_var = LiteralStringVar.create(id_)
|
|
65
|
+
id_var = LiteralStringVar.create(id_) if not isinstance(id_, Var) else id_
|
|
66
66
|
var_name = f"""e => setFilesById(filesById => {{
|
|
67
67
|
const updatedFilesById = Object.assign({{}}, filesById);
|
|
68
68
|
updatedFilesById[{id_var!s}] = e;
|
|
@@ -79,7 +79,7 @@ def upload_file(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
82
|
+
def selected_files(id_: str | Var[str] = DEFAULT_UPLOAD_ID) -> Var:
|
|
83
83
|
"""Get the list of selected files.
|
|
84
84
|
|
|
85
85
|
Args:
|
|
@@ -88,9 +88,9 @@ def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> Var:
|
|
|
88
88
|
Returns:
|
|
89
89
|
A var referencing the list of selected file paths.
|
|
90
90
|
"""
|
|
91
|
-
id_var = LiteralStringVar.create(id_)
|
|
91
|
+
id_var = LiteralStringVar.create(id_) if not isinstance(id_, Var) else id_
|
|
92
92
|
return Var(
|
|
93
|
-
_js_expr=f"(filesById[{id_var!s}] ? filesById[{id_var!s}].map((f) =>
|
|
93
|
+
_js_expr=f"(filesById[{id_var!s}] ? filesById[{id_var!s}].map((f) => f.name) : [])",
|
|
94
94
|
_var_type=list[str],
|
|
95
95
|
_var_data=VarData.merge(
|
|
96
96
|
upload_files_context_var_data, id_var._get_all_var_data()
|
reflex/components/el/__init__.py
CHANGED
|
@@ -8,11 +8,17 @@ from . import elements
|
|
|
8
8
|
|
|
9
9
|
_SUBMODULES: set[str] = {"elements"}
|
|
10
10
|
_SUBMOD_ATTRS: dict[str, list[str]] = {
|
|
11
|
-
|
|
11
|
+
# rx.el.a is replaced by React Router's Link.
|
|
12
|
+
f"elements.{k}": [_v for _v in v if _v != "a"]
|
|
13
|
+
for k, v in elements._MAPPING.items()
|
|
14
|
+
}
|
|
15
|
+
_EXTRA_MAPPINGS: dict[str, str] = {
|
|
16
|
+
"a": "reflex.components.react_router.link",
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
__getattr__, __dir__, __all__ = lazy_loader.attach(
|
|
15
20
|
__name__,
|
|
16
21
|
submodules=_SUBMODULES,
|
|
17
22
|
submod_attrs=_SUBMOD_ATTRS,
|
|
23
|
+
**_EXTRA_MAPPINGS,
|
|
18
24
|
)
|
|
@@ -14,6 +14,7 @@ from reflex.components.core.cond import cond
|
|
|
14
14
|
from reflex.components.el.elements.inline import A
|
|
15
15
|
from reflex.components.markdown.markdown import MarkdownComponentMap
|
|
16
16
|
from reflex.components.radix.themes.base import LiteralAccentColor, RadixThemesComponent
|
|
17
|
+
from reflex.components.react_router.dom import ReactRouterLink
|
|
17
18
|
from reflex.utils.imports import ImportDict, ImportVar
|
|
18
19
|
from reflex.vars.base import Var
|
|
19
20
|
|
|
@@ -21,36 +22,6 @@ from .base import LiteralTextSize, LiteralTextTrim, LiteralTextWeight
|
|
|
21
22
|
|
|
22
23
|
LiteralLinkUnderline = Literal["auto", "hover", "always", "none"]
|
|
23
24
|
|
|
24
|
-
LiteralLinkDiscover = Literal["none", "render"]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class ReactRouterLink(A):
|
|
28
|
-
"""Links are accessible elements used primarily for navigation. This component is styled to resemble a hyperlink and semantically renders an <a>."""
|
|
29
|
-
|
|
30
|
-
library = "react-router"
|
|
31
|
-
|
|
32
|
-
tag = "Link"
|
|
33
|
-
|
|
34
|
-
alias = "ReactRouterLink"
|
|
35
|
-
|
|
36
|
-
# The page to link to.
|
|
37
|
-
to: Var[str]
|
|
38
|
-
|
|
39
|
-
# Replaces the current entry in the history stack instead of pushing a new one onto it.
|
|
40
|
-
replace: Var[bool]
|
|
41
|
-
|
|
42
|
-
# Will use document navigation instead of client side routing when the link is clicked: the browser will handle the transition normally (as if it were an <a href>).
|
|
43
|
-
reload_document: Var[bool]
|
|
44
|
-
|
|
45
|
-
# Prevents the scroll position from being reset to the top of the window when the link is clicked and the app is using ScrollRestoration. This only prevents new locations resetting scroll to the top, scroll position will be restored for back/forward button navigation.
|
|
46
|
-
prevent_scroll_reset: Var[bool]
|
|
47
|
-
|
|
48
|
-
# Defines the link discovery behavior
|
|
49
|
-
discover: Var[LiteralLinkDiscover]
|
|
50
|
-
|
|
51
|
-
# Enables a View Transition for this navigation.
|
|
52
|
-
view_transition: Var[bool]
|
|
53
|
-
|
|
54
25
|
|
|
55
26
|
_KNOWN_REACT_ROUTER_LINK_PROPS = frozenset(ReactRouterLink.get_props())
|
|
56
27
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Components for client side navigation within React Router applications."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import ClassVar, Literal, TypedDict
|
|
6
|
+
|
|
7
|
+
from reflex.components.el.elements.inline import A
|
|
8
|
+
from reflex.vars.base import Var
|
|
9
|
+
|
|
10
|
+
LiteralLinkDiscover = Literal["none", "render"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class To(TypedDict):
|
|
14
|
+
"""Structured object for navigating via the `to` prop."""
|
|
15
|
+
|
|
16
|
+
# A URL pathname, beginning with a /
|
|
17
|
+
pathname: str
|
|
18
|
+
|
|
19
|
+
# A URL search string, beginning with a ?.
|
|
20
|
+
search: str
|
|
21
|
+
|
|
22
|
+
# A URL fragment identifier, beginning with a #.
|
|
23
|
+
hash: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ReactRouterLink(A):
|
|
27
|
+
"""Links are accessible elements used primarily for navigation. This component is styled to resemble a hyperlink and semantically renders an <a>."""
|
|
28
|
+
|
|
29
|
+
library = "react-router"
|
|
30
|
+
|
|
31
|
+
tag = "Link"
|
|
32
|
+
|
|
33
|
+
alias = "ReactRouterLink"
|
|
34
|
+
|
|
35
|
+
# The page to link to.
|
|
36
|
+
to: Var[str | To]
|
|
37
|
+
|
|
38
|
+
# Replaces the current entry in the history stack instead of pushing a new one onto it.
|
|
39
|
+
replace: Var[bool]
|
|
40
|
+
|
|
41
|
+
# Will use document navigation instead of client side routing when the link is clicked: the browser will handle the transition normally (as if it were an <a href>).
|
|
42
|
+
reload_document: Var[bool]
|
|
43
|
+
|
|
44
|
+
# Prevents the scroll position from being reset to the top of the window when the link is clicked and the app is using ScrollRestoration. This only prevents new locations resetting scroll to the top, scroll position will be restored for back/forward button navigation.
|
|
45
|
+
prevent_scroll_reset: Var[bool]
|
|
46
|
+
|
|
47
|
+
# Defines the link discovery behavior
|
|
48
|
+
discover: Var[LiteralLinkDiscover]
|
|
49
|
+
|
|
50
|
+
# Enables a View Transition for this navigation.
|
|
51
|
+
view_transition: Var[bool]
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def create(cls, *children, **props):
|
|
55
|
+
"""Create a ReactRouterLink component for client-side navigation.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
*children: The children of the component.
|
|
59
|
+
**props: The props of the component.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
The ReactRouterLink component.
|
|
63
|
+
"""
|
|
64
|
+
# React Router special behavior is triggered on the `to` prop, not href.
|
|
65
|
+
if "to" not in props and "href" in props:
|
|
66
|
+
props["to"] = props.pop("href")
|
|
67
|
+
return super().create(*children, **props)
|
|
68
|
+
|
|
69
|
+
_invalid_children: ClassVar[list[str]] = ["A", "ReactRouterLink"]
|
|
@@ -8,7 +8,7 @@ from reflex.components.component import Component, MemoizationLeaf, NoSSRCompone
|
|
|
8
8
|
class Recharts(Component):
|
|
9
9
|
"""A component that wraps a recharts lib."""
|
|
10
10
|
|
|
11
|
-
library = "recharts@3.0.
|
|
11
|
+
library = "recharts@3.0.2"
|
|
12
12
|
|
|
13
13
|
def _get_style(self) -> dict:
|
|
14
14
|
return {"wrapperStyle": self.style}
|
|
@@ -17,7 +17,7 @@ class Recharts(Component):
|
|
|
17
17
|
class RechartsCharts(NoSSRComponent, MemoizationLeaf):
|
|
18
18
|
"""A component that wraps a recharts lib."""
|
|
19
19
|
|
|
20
|
-
library = "recharts@3.0.
|
|
20
|
+
library = "recharts@3.0.2"
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
LiteralAnimationEasing = Literal["ease", "ease-in", "ease-out", "ease-in-out", "linear"]
|
reflex/constants/installer.py
CHANGED
|
@@ -75,7 +75,7 @@ fetch-retries=0
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
def _determine_react_router_version() -> str:
|
|
78
|
-
default_version = "7.6.
|
|
78
|
+
default_version = "7.6.3"
|
|
79
79
|
if (version := os.getenv("REACT_ROUTER_VERSION")) and version != default_version:
|
|
80
80
|
from reflex.utils import console
|
|
81
81
|
|
|
@@ -143,7 +143,7 @@ class PackageJson(SimpleNamespace):
|
|
|
143
143
|
"postcss-import": "16.1.1",
|
|
144
144
|
"@react-router/dev": _react_router_version,
|
|
145
145
|
"@react-router/fs-routes": _react_router_version,
|
|
146
|
-
"rolldown-vite": "7.0.
|
|
146
|
+
"rolldown-vite": "7.0.3",
|
|
147
147
|
}
|
|
148
148
|
OVERRIDES = {
|
|
149
149
|
# This should always match the `react` version in DEPENDENCIES for recharts compatibility.
|
reflex/environment.py
CHANGED
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import concurrent.futures
|
|
6
6
|
import dataclasses
|
|
7
7
|
import enum
|
|
8
|
+
import importlib
|
|
8
9
|
import inspect
|
|
9
10
|
import multiprocessing
|
|
10
11
|
import os
|
|
@@ -24,6 +25,7 @@ from typing import (
|
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
from reflex import constants
|
|
28
|
+
from reflex.plugins import Plugin
|
|
27
29
|
from reflex.utils.exceptions import EnvironmentVarValueError
|
|
28
30
|
from reflex.utils.types import GenericType, is_union, value_inside_optional
|
|
29
31
|
|
|
@@ -126,6 +128,48 @@ def interpret_path_env(value: str, field_name: str) -> Path:
|
|
|
126
128
|
return Path(value)
|
|
127
129
|
|
|
128
130
|
|
|
131
|
+
def interpret_plugin_env(value: str, field_name: str) -> Plugin:
|
|
132
|
+
"""Interpret a plugin environment variable value.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
value: The environment variable value.
|
|
136
|
+
field_name: The field name.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
The interpreted value.
|
|
140
|
+
|
|
141
|
+
Raises:
|
|
142
|
+
EnvironmentVarValueError: If the value is invalid.
|
|
143
|
+
"""
|
|
144
|
+
if "." not in value:
|
|
145
|
+
msg = f"Invalid plugin value: {value!r} for {field_name}. Plugin name must be in the format 'package.module.PluginName'."
|
|
146
|
+
raise EnvironmentVarValueError(msg)
|
|
147
|
+
|
|
148
|
+
import_path, plugin_name = value.rsplit(".", 1)
|
|
149
|
+
|
|
150
|
+
try:
|
|
151
|
+
module = importlib.import_module(import_path)
|
|
152
|
+
except ImportError as e:
|
|
153
|
+
msg = f"Failed to import module {import_path!r} for {field_name}: {e}"
|
|
154
|
+
raise EnvironmentVarValueError(msg) from e
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
plugin_class = getattr(module, plugin_name, None)
|
|
158
|
+
except Exception as e:
|
|
159
|
+
msg = f"Failed to get plugin class {plugin_name!r} from module {import_path!r} for {field_name}: {e}"
|
|
160
|
+
raise EnvironmentVarValueError(msg) from e
|
|
161
|
+
|
|
162
|
+
if not inspect.isclass(plugin_class) or not issubclass(plugin_class, Plugin):
|
|
163
|
+
msg = f"Invalid plugin class: {plugin_name!r} for {field_name}. Must be a subclass of Plugin."
|
|
164
|
+
raise EnvironmentVarValueError(msg)
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
return plugin_class()
|
|
168
|
+
except Exception as e:
|
|
169
|
+
msg = f"Failed to instantiate plugin {plugin_name!r} for {field_name}: {e}"
|
|
170
|
+
raise EnvironmentVarValueError(msg) from e
|
|
171
|
+
|
|
172
|
+
|
|
129
173
|
def interpret_enum_env(value: str, field_type: GenericType, field_name: str) -> Any:
|
|
130
174
|
"""Interpret an enum environment variable value.
|
|
131
175
|
|
|
@@ -181,6 +225,8 @@ def interpret_env_var_value(
|
|
|
181
225
|
return interpret_path_env(value, field_name)
|
|
182
226
|
if field_type is ExistingPath:
|
|
183
227
|
return interpret_existing_path_env(value, field_name)
|
|
228
|
+
if field_type is Plugin:
|
|
229
|
+
return interpret_plugin_env(value, field_name)
|
|
184
230
|
if get_origin(field_type) is list:
|
|
185
231
|
return [
|
|
186
232
|
interpret_env_var_value(
|
reflex/event.py
CHANGED
|
@@ -570,7 +570,7 @@ class JavascriptHTMLInputElement:
|
|
|
570
570
|
class JavascriptInputEvent:
|
|
571
571
|
"""Interface for a Javascript InputEvent https://developer.mozilla.org/en-US/docs/Web/API/InputEvent."""
|
|
572
572
|
|
|
573
|
-
target: JavascriptHTMLInputElement = JavascriptHTMLInputElement()
|
|
573
|
+
target: JavascriptHTMLInputElement = JavascriptHTMLInputElement()
|
|
574
574
|
|
|
575
575
|
|
|
576
576
|
@dataclasses.dataclass(
|
|
@@ -1025,6 +1025,22 @@ def set_focus(ref: str) -> EventSpec:
|
|
|
1025
1025
|
)
|
|
1026
1026
|
|
|
1027
1027
|
|
|
1028
|
+
def blur_focus(ref: str) -> EventSpec:
|
|
1029
|
+
"""Blur focus of specified ref.
|
|
1030
|
+
|
|
1031
|
+
Args:
|
|
1032
|
+
ref: The ref.
|
|
1033
|
+
|
|
1034
|
+
Returns:
|
|
1035
|
+
An event to blur focus on the ref
|
|
1036
|
+
"""
|
|
1037
|
+
return server_side(
|
|
1038
|
+
"_blur_focus",
|
|
1039
|
+
get_fn_signature(blur_focus),
|
|
1040
|
+
ref=LiteralVar.create(format.format_ref(ref)),
|
|
1041
|
+
)
|
|
1042
|
+
|
|
1043
|
+
|
|
1028
1044
|
def scroll_to(elem_id: str, align_to_top: bool | Var[bool] = True) -> EventSpec:
|
|
1029
1045
|
"""Select the id of a html element for scrolling into view.
|
|
1030
1046
|
|
|
@@ -2293,6 +2309,7 @@ class EventNamespace:
|
|
|
2293
2309
|
back = staticmethod(back)
|
|
2294
2310
|
window_alert = staticmethod(window_alert)
|
|
2295
2311
|
set_focus = staticmethod(set_focus)
|
|
2312
|
+
blur_focus = staticmethod(blur_focus)
|
|
2296
2313
|
scroll_to = staticmethod(scroll_to)
|
|
2297
2314
|
set_value = staticmethod(set_value)
|
|
2298
2315
|
remove_cookie = staticmethod(remove_cookie)
|