use $ syntax (#4237)
* use $ syntax * missing test case change * try being a little smart * improve merge imports logic * add public as well * oops missed that one * last one there
This commit is contained in:
parent
2e703f7aaa
commit
c3848d0db4
@ -1,11 +1,11 @@
|
|||||||
{% extends "web/pages/base_page.js.jinja2" %}
|
{% extends "web/pages/base_page.js.jinja2" %}
|
||||||
|
|
||||||
{% block early_imports %}
|
{% block early_imports %}
|
||||||
import '/styles/styles.css'
|
import '$/styles/styles.css'
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block declaration %}
|
{% block declaration %}
|
||||||
import { EventLoopProvider, StateProvider, defaultColorMode } from "/utils/context.js";
|
import { EventLoopProvider, StateProvider, defaultColorMode } from "$/utils/context.js";
|
||||||
import { ThemeProvider } from 'next-themes'
|
import { ThemeProvider } from 'next-themes'
|
||||||
{% for library_alias, library_path in window_libraries %}
|
{% for library_alias, library_path in window_libraries %}
|
||||||
import * as {{library_alias}} from "{{library_path}}";
|
import * as {{library_alias}} from "{{library_path}}";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createContext, useContext, useMemo, useReducer, useState } from "react"
|
import { createContext, useContext, useMemo, useReducer, useState } from "react"
|
||||||
import { applyDelta, Event, hydrateClientStorage, useEventLoop, refs } from "/utils/state.js"
|
import { applyDelta, Event, hydrateClientStorage, useEventLoop, refs } from "$/utils/state.js"
|
||||||
|
|
||||||
{% if initial_state %}
|
{% if initial_state %}
|
||||||
export const initialState = {{ initial_state|json_dumps }}
|
export const initialState = {{ initial_state|json_dumps }}
|
||||||
@ -59,6 +59,8 @@ export const initialEvents = () => [
|
|||||||
{% else %}
|
{% else %}
|
||||||
export const state_name = undefined
|
export const state_name = undefined
|
||||||
|
|
||||||
|
export const exception_state_name = undefined
|
||||||
|
|
||||||
export const onLoadInternalEvent = () => []
|
export const onLoadInternalEvent = () => []
|
||||||
|
|
||||||
export const initialEvents = () => []
|
export const initialEvents = () => []
|
||||||
|
@ -4,8 +4,8 @@ import {
|
|||||||
ColorModeContext,
|
ColorModeContext,
|
||||||
defaultColorMode,
|
defaultColorMode,
|
||||||
isDevMode,
|
isDevMode,
|
||||||
lastCompiledTimeStamp
|
lastCompiledTimeStamp,
|
||||||
} from "/utils/context.js";
|
} from "$/utils/context.js";
|
||||||
|
|
||||||
export default function RadixThemesColorModeProvider({ children }) {
|
export default function RadixThemesColorModeProvider({ children }) {
|
||||||
const { theme, resolvedTheme, setTheme } = useTheme();
|
const { theme, resolvedTheme, setTheme } = useTheme();
|
||||||
@ -37,7 +37,7 @@ export default function RadixThemesColorModeProvider({ children }) {
|
|||||||
const allowedModes = ["light", "dark", "system"];
|
const allowedModes = ["light", "dark", "system"];
|
||||||
if (!allowedModes.includes(mode)) {
|
if (!allowedModes.includes(mode)) {
|
||||||
console.error(
|
console.error(
|
||||||
`Invalid color mode "${mode}". Defaulting to "${defaultColorMode}".`,
|
`Invalid color mode "${mode}". Defaulting to "${defaultColorMode}".`
|
||||||
);
|
);
|
||||||
mode = defaultColorMode;
|
mode = defaultColorMode;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"$/*": ["*"],
|
||||||
"@/*": ["public/*"]
|
"@/*": ["public/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import io from "socket.io-client";
|
import io from "socket.io-client";
|
||||||
import JSON5 from "json5";
|
import JSON5 from "json5";
|
||||||
import env from "/env.json";
|
import env from "$/env.json";
|
||||||
import Cookies from "universal-cookie";
|
import Cookies from "universal-cookie";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import Router, { useRouter } from "next/router";
|
import Router, { useRouter } from "next/router";
|
||||||
@ -12,9 +12,9 @@ import {
|
|||||||
onLoadInternalEvent,
|
onLoadInternalEvent,
|
||||||
state_name,
|
state_name,
|
||||||
exception_state_name,
|
exception_state_name,
|
||||||
} from "utils/context.js";
|
} from "$/utils/context.js";
|
||||||
import debounce from "/utils/helpers/debounce";
|
import debounce from "$/utils/helpers/debounce";
|
||||||
import throttle from "/utils/helpers/throttle";
|
import throttle from "$/utils/helpers/throttle";
|
||||||
import * as Babel from "@babel/standalone";
|
import * as Babel from "@babel/standalone";
|
||||||
|
|
||||||
// Endpoint URLs.
|
// Endpoint URLs.
|
||||||
|
@ -679,7 +679,7 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
for i, tags in imports.items()
|
for i, tags in imports.items()
|
||||||
if i not in constants.PackageJson.DEPENDENCIES
|
if i not in constants.PackageJson.DEPENDENCIES
|
||||||
and i not in constants.PackageJson.DEV_DEPENDENCIES
|
and i not in constants.PackageJson.DEV_DEPENDENCIES
|
||||||
and not any(i.startswith(prefix) for prefix in ["/", ".", "next/"])
|
and not any(i.startswith(prefix) for prefix in ["/", "$/", ".", "next/"])
|
||||||
and i != ""
|
and i != ""
|
||||||
and any(tag.install for tag in tags)
|
and any(tag.install for tag in tags)
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ def _compile_app(app_root: Component) -> str:
|
|||||||
window_libraries = [
|
window_libraries = [
|
||||||
(_normalize_library_name(name), name) for name in bundled_libraries
|
(_normalize_library_name(name), name) for name in bundled_libraries
|
||||||
] + [
|
] + [
|
||||||
("utils_context", f"/{constants.Dirs.UTILS}/context"),
|
("utils_context", f"$/{constants.Dirs.UTILS}/context"),
|
||||||
("utils_state", f"/{constants.Dirs.UTILS}/state"),
|
("utils_state", f"$/{constants.Dirs.UTILS}/state"),
|
||||||
]
|
]
|
||||||
|
|
||||||
return templates.APP_ROOT.render(
|
return templates.APP_ROOT.render(
|
||||||
@ -228,7 +228,7 @@ def _compile_components(
|
|||||||
"""
|
"""
|
||||||
imports = {
|
imports = {
|
||||||
"react": [ImportVar(tag="memo")],
|
"react": [ImportVar(tag="memo")],
|
||||||
f"/{constants.Dirs.STATE_PATH}": [ImportVar(tag="E"), ImportVar(tag="isTrue")],
|
f"$/{constants.Dirs.STATE_PATH}": [ImportVar(tag="E"), ImportVar(tag="isTrue")],
|
||||||
}
|
}
|
||||||
component_renders = []
|
component_renders = []
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ def _compile_stateful_components(
|
|||||||
# Don't import from the file that we're about to create.
|
# Don't import from the file that we're about to create.
|
||||||
all_imports = utils.merge_imports(*all_import_dicts)
|
all_imports = utils.merge_imports(*all_import_dicts)
|
||||||
all_imports.pop(
|
all_imports.pop(
|
||||||
f"/{constants.Dirs.UTILS}/{constants.PageNames.STATEFUL_COMPONENTS}", None
|
f"$/{constants.Dirs.UTILS}/{constants.PageNames.STATEFUL_COMPONENTS}", None
|
||||||
)
|
)
|
||||||
|
|
||||||
return templates.STATEFUL_COMPONENTS.render(
|
return templates.STATEFUL_COMPONENTS.render(
|
||||||
|
@ -83,6 +83,12 @@ def validate_imports(import_dict: ParsedImportDict):
|
|||||||
f"{_import.tag}/{_import.alias}" if _import.alias else _import.tag
|
f"{_import.tag}/{_import.alias}" if _import.alias else _import.tag
|
||||||
)
|
)
|
||||||
if import_name in used_tags:
|
if import_name in used_tags:
|
||||||
|
already_imported = used_tags[import_name]
|
||||||
|
if (already_imported[0] == "$" and already_imported[1:] == lib) or (
|
||||||
|
lib[0] == "$" and lib[1:] == already_imported
|
||||||
|
):
|
||||||
|
used_tags[import_name] = lib if lib[0] == "$" else already_imported
|
||||||
|
continue
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Can not compile, the tag {import_name} is used multiple time from {lib} and {used_tags[import_name]}"
|
f"Can not compile, the tag {import_name} is used multiple time from {lib} and {used_tags[import_name]}"
|
||||||
)
|
)
|
||||||
|
@ -1308,7 +1308,9 @@ class Component(BaseComponent, ABC):
|
|||||||
if self._get_ref_hook():
|
if self._get_ref_hook():
|
||||||
# Handle hooks needed for attaching react refs to DOM nodes.
|
# Handle hooks needed for attaching react refs to DOM nodes.
|
||||||
_imports.setdefault("react", set()).add(ImportVar(tag="useRef"))
|
_imports.setdefault("react", set()).add(ImportVar(tag="useRef"))
|
||||||
_imports.setdefault(f"/{Dirs.STATE_PATH}", set()).add(ImportVar(tag="refs"))
|
_imports.setdefault(f"$/{Dirs.STATE_PATH}", set()).add(
|
||||||
|
ImportVar(tag="refs")
|
||||||
|
)
|
||||||
|
|
||||||
if self._get_mount_lifecycle_hook():
|
if self._get_mount_lifecycle_hook():
|
||||||
# Handle hooks for `on_mount` / `on_unmount`.
|
# Handle hooks for `on_mount` / `on_unmount`.
|
||||||
@ -1665,7 +1667,7 @@ class CustomComponent(Component):
|
|||||||
"""A custom user-defined component."""
|
"""A custom user-defined component."""
|
||||||
|
|
||||||
# Use the components library.
|
# Use the components library.
|
||||||
library = f"/{Dirs.COMPONENTS_PATH}"
|
library = f"$/{Dirs.COMPONENTS_PATH}"
|
||||||
|
|
||||||
# The function that creates the component.
|
# The function that creates the component.
|
||||||
component_fn: Callable[..., Component] = Component.create
|
component_fn: Callable[..., Component] = Component.create
|
||||||
@ -2233,7 +2235,7 @@ class StatefulComponent(BaseComponent):
|
|||||||
"""
|
"""
|
||||||
if self.rendered_as_shared:
|
if self.rendered_as_shared:
|
||||||
return {
|
return {
|
||||||
f"/{Dirs.UTILS}/{PageNames.STATEFUL_COMPONENTS}": [
|
f"$/{Dirs.UTILS}/{PageNames.STATEFUL_COMPONENTS}": [
|
||||||
ImportVar(tag=self.tag)
|
ImportVar(tag=self.tag)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ class WebsocketTargetURL(Var):
|
|||||||
_js_expr="getBackendURL(env.EVENT).href",
|
_js_expr="getBackendURL(env.EVENT).href",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
"/env.json": [ImportVar(tag="env", is_default=True)],
|
"$/env.json": [ImportVar(tag="env", is_default=True)],
|
||||||
f"/{Dirs.STATE_PATH}": [ImportVar(tag="getBackendURL")],
|
f"$/{Dirs.STATE_PATH}": [ImportVar(tag="getBackendURL")],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_var_type=WebsocketTargetURL,
|
_var_type=WebsocketTargetURL,
|
||||||
|
@ -21,7 +21,7 @@ route_not_found: Var = Var(_js_expr=constants.ROUTE_NOT_FOUND)
|
|||||||
class ClientSideRouting(Component):
|
class ClientSideRouting(Component):
|
||||||
"""The client-side routing component."""
|
"""The client-side routing component."""
|
||||||
|
|
||||||
library = "/utils/client_side_routing"
|
library = "$/utils/client_side_routing"
|
||||||
tag = "useClientSideRouting"
|
tag = "useClientSideRouting"
|
||||||
|
|
||||||
def add_hooks(self) -> list[str]:
|
def add_hooks(self) -> list[str]:
|
||||||
|
@ -67,7 +67,7 @@ class Clipboard(Fragment):
|
|||||||
The import dict for the component.
|
The import dict for the component.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"/utils/helpers/paste.js": ImportVar(
|
"$/utils/helpers/paste.js": ImportVar(
|
||||||
tag="usePasteHandler", is_default=True
|
tag="usePasteHandler", is_default=True
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ from reflex.vars.base import LiteralVar, Var
|
|||||||
from reflex.vars.number import ternary_operation
|
from reflex.vars.number import ternary_operation
|
||||||
|
|
||||||
_IS_TRUE_IMPORT: ImportDict = {
|
_IS_TRUE_IMPORT: ImportDict = {
|
||||||
f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
f"$/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ DEFAULT_UPLOAD_ID: str = "default"
|
|||||||
upload_files_context_var_data: VarData = VarData(
|
upload_files_context_var_data: VarData = VarData(
|
||||||
imports={
|
imports={
|
||||||
"react": "useContext",
|
"react": "useContext",
|
||||||
f"/{Dirs.CONTEXTS_PATH}": "UploadFilesContext",
|
f"$/{Dirs.CONTEXTS_PATH}": "UploadFilesContext",
|
||||||
},
|
},
|
||||||
hooks={
|
hooks={
|
||||||
"const [filesById, setFilesById] = useContext(UploadFilesContext);": None,
|
"const [filesById, setFilesById] = useContext(UploadFilesContext);": None,
|
||||||
@ -134,8 +134,8 @@ uploaded_files_url_prefix = Var(
|
|||||||
_js_expr="getBackendURL(env.UPLOAD)",
|
_js_expr="getBackendURL(env.UPLOAD)",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
f"/{Dirs.STATE_PATH}": "getBackendURL",
|
f"$/{Dirs.STATE_PATH}": "getBackendURL",
|
||||||
"/env.json": ImportVar(tag="env", is_default=True),
|
"$/env.json": ImportVar(tag="env", is_default=True),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
).to(str)
|
).to(str)
|
||||||
@ -170,7 +170,7 @@ def _on_drop_spec(files: Var) -> Tuple[Var[Any]]:
|
|||||||
class UploadFilesProvider(Component):
|
class UploadFilesProvider(Component):
|
||||||
"""AppWrap component that provides a dict of selected files by ID via useContext."""
|
"""AppWrap component that provides a dict of selected files by ID via useContext."""
|
||||||
|
|
||||||
library = f"/{Dirs.CONTEXTS_PATH}"
|
library = f"$/{Dirs.CONTEXTS_PATH}"
|
||||||
tag = "UploadFilesProvider"
|
tag = "UploadFilesProvider"
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ uploaded_files_url_prefix = Var(
|
|||||||
_js_expr="getBackendURL(env.UPLOAD)",
|
_js_expr="getBackendURL(env.UPLOAD)",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
f"/{Dirs.STATE_PATH}": "getBackendURL",
|
f"$/{Dirs.STATE_PATH}": "getBackendURL",
|
||||||
"/env.json": ImportVar(tag="env", is_default=True),
|
"$/env.json": ImportVar(tag="env", is_default=True),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
).to(str)
|
).to(str)
|
||||||
|
@ -344,7 +344,7 @@ class DataEditor(NoSSRComponent):
|
|||||||
return {
|
return {
|
||||||
"": f"{format.format_library_name(self.library)}/dist/index.css",
|
"": f"{format.format_library_name(self.library)}/dist/index.css",
|
||||||
self.library: "GridCellKind",
|
self.library: "GridCellKind",
|
||||||
"/utils/helpers/dataeditor.js": ImportVar(
|
"$/utils/helpers/dataeditor.js": ImportVar(
|
||||||
tag="formatDataEditorCells", is_default=False, install=False
|
tag="formatDataEditorCells", is_default=False, install=False
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ def load_dynamic_serializer():
|
|||||||
for lib, names in component._get_all_imports().items():
|
for lib, names in component._get_all_imports().items():
|
||||||
formatted_lib_name = format_library_name(lib)
|
formatted_lib_name = format_library_name(lib)
|
||||||
if (
|
if (
|
||||||
not lib.startswith((".", "/"))
|
not lib.startswith((".", "/", "$/"))
|
||||||
and not lib.startswith("http")
|
and not lib.startswith("http")
|
||||||
and formatted_lib_name not in libs_in_window
|
and formatted_lib_name not in libs_in_window
|
||||||
):
|
):
|
||||||
@ -106,7 +106,7 @@ def load_dynamic_serializer():
|
|||||||
# Rewrite imports from `/` to destructure from window
|
# Rewrite imports from `/` to destructure from window
|
||||||
for ix, line in enumerate(module_code_lines[:]):
|
for ix, line in enumerate(module_code_lines[:]):
|
||||||
if line.startswith("import "):
|
if line.startswith("import "):
|
||||||
if 'from "/' in line:
|
if 'from "$/' in line or 'from "/' in line:
|
||||||
module_code_lines[ix] = (
|
module_code_lines[ix] = (
|
||||||
line.replace("import ", "const ", 1).replace(
|
line.replace("import ", "const ", 1).replace(
|
||||||
" from ", " = window['__reflex'][", 1
|
" from ", " = window['__reflex'][", 1
|
||||||
@ -157,7 +157,7 @@ def load_dynamic_serializer():
|
|||||||
merge_var_data=VarData.merge(
|
merge_var_data=VarData.merge(
|
||||||
VarData(
|
VarData(
|
||||||
imports={
|
imports={
|
||||||
f"/{constants.Dirs.STATE_PATH}": [
|
f"$/{constants.Dirs.STATE_PATH}": [
|
||||||
imports.ImportVar(tag="evalReactComponent"),
|
imports.ImportVar(tag="evalReactComponent"),
|
||||||
],
|
],
|
||||||
"react": [
|
"react": [
|
||||||
|
@ -187,7 +187,7 @@ class Form(BaseHTML):
|
|||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"react": "useCallback",
|
"react": "useCallback",
|
||||||
f"/{Dirs.STATE_PATH}": ["getRefValue", "getRefValues"],
|
f"$/{Dirs.STATE_PATH}": ["getRefValue", "getRefValues"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def add_hooks(self) -> list[str]:
|
def add_hooks(self) -> list[str]:
|
||||||
|
@ -221,7 +221,7 @@ class Theme(RadixThemesComponent):
|
|||||||
The import dict.
|
The import dict.
|
||||||
"""
|
"""
|
||||||
_imports: ImportDict = {
|
_imports: ImportDict = {
|
||||||
"/utils/theme.js": [ImportVar(tag="theme", is_default=True)],
|
"$/utils/theme.js": [ImportVar(tag="theme", is_default=True)],
|
||||||
}
|
}
|
||||||
if get_config().tailwind is None:
|
if get_config().tailwind is None:
|
||||||
# When tailwind is disabled, import the radix-ui styles directly because they will
|
# When tailwind is disabled, import the radix-ui styles directly because they will
|
||||||
@ -265,7 +265,7 @@ class ThemePanel(RadixThemesComponent):
|
|||||||
class RadixThemesColorModeProvider(Component):
|
class RadixThemesColorModeProvider(Component):
|
||||||
"""Next-themes integration for radix themes components."""
|
"""Next-themes integration for radix themes components."""
|
||||||
|
|
||||||
library = "/components/reflex/radix_themes_color_mode_provider.js"
|
library = "$/components/reflex/radix_themes_color_mode_provider.js"
|
||||||
tag = "RadixThemesColorModeProvider"
|
tag = "RadixThemesColorModeProvider"
|
||||||
is_default = True
|
is_default = True
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class Toaster(Component):
|
|||||||
_js_expr=f"{toast_ref} = toast",
|
_js_expr=f"{toast_ref} = toast",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
"/utils/state": [ImportVar(tag="refs")],
|
"$/utils/state": [ImportVar(tag="refs")],
|
||||||
self.library: [ImportVar(tag="toast", install=False)],
|
self.library: [ImportVar(tag="toast", install=False)],
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -114,8 +114,8 @@ class Imports(SimpleNamespace):
|
|||||||
|
|
||||||
EVENTS = {
|
EVENTS = {
|
||||||
"react": [ImportVar(tag="useContext")],
|
"react": [ImportVar(tag="useContext")],
|
||||||
f"/{Dirs.CONTEXTS_PATH}": [ImportVar(tag="EventLoopContext")],
|
f"$/{Dirs.CONTEXTS_PATH}": [ImportVar(tag="EventLoopContext")],
|
||||||
f"/{Dirs.STATE_PATH}": [ImportVar(tag=CompileVars.TO_EVENT)],
|
f"$/{Dirs.STATE_PATH}": [ImportVar(tag=CompileVars.TO_EVENT)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ NoValue = object()
|
|||||||
|
|
||||||
|
|
||||||
_refs_import = {
|
_refs_import = {
|
||||||
f"/{constants.Dirs.STATE_PATH}": [ImportVar(tag="refs")],
|
f"$/{constants.Dirs.STATE_PATH}": [ImportVar(tag="refs")],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ LiteralColorMode = Literal["system", "light", "dark"]
|
|||||||
|
|
||||||
# Reference the global ColorModeContext
|
# Reference the global ColorModeContext
|
||||||
color_mode_imports = {
|
color_mode_imports = {
|
||||||
f"/{constants.Dirs.CONTEXTS_PATH}": [ImportVar(tag="ColorModeContext")],
|
f"$/{constants.Dirs.CONTEXTS_PATH}": [ImportVar(tag="ColorModeContext")],
|
||||||
"react": [ImportVar(tag="useContext")],
|
"react": [ImportVar(tag="useContext")],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,12 @@ def merge_imports(
|
|||||||
for lib, fields in (
|
for lib, fields in (
|
||||||
import_dict if isinstance(import_dict, tuple) else import_dict.items()
|
import_dict if isinstance(import_dict, tuple) else import_dict.items()
|
||||||
):
|
):
|
||||||
|
# If the lib is an absolute path, we need to prefix it with a $
|
||||||
|
lib = (
|
||||||
|
"$" + lib
|
||||||
|
if lib.startswith(("/utils/", "/components/", "/styles/", "/public/"))
|
||||||
|
else lib
|
||||||
|
)
|
||||||
if isinstance(fields, (list, tuple, set)):
|
if isinstance(fields, (list, tuple, set)):
|
||||||
all_imports[lib].extend(
|
all_imports[lib].extend(
|
||||||
(
|
(
|
||||||
|
@ -217,7 +217,7 @@ class VarData:
|
|||||||
): None
|
): None
|
||||||
},
|
},
|
||||||
imports={
|
imports={
|
||||||
f"/{constants.Dirs.CONTEXTS_PATH}": [ImportVar(tag="StateContexts")],
|
f"$/{constants.Dirs.CONTEXTS_PATH}": [ImportVar(tag="StateContexts")],
|
||||||
"react": [ImportVar(tag="useContext")],
|
"react": [ImportVar(tag="useContext")],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -956,7 +956,7 @@ class Var(Generic[VAR_TYPE]):
|
|||||||
_js_expr="refs",
|
_js_expr="refs",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
f"/{constants.Dirs.STATE_PATH}": [imports.ImportVar(tag="refs")]
|
f"$/{constants.Dirs.STATE_PATH}": [imports.ImportVar(tag="refs")]
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
).to(ObjectVar, Dict[str, str])
|
).to(ObjectVar, Dict[str, str])
|
||||||
@ -2530,7 +2530,7 @@ def get_uuid_string_var() -> Var:
|
|||||||
unique_uuid_var = get_unique_variable_name()
|
unique_uuid_var = get_unique_variable_name()
|
||||||
unique_uuid_var_data = VarData(
|
unique_uuid_var_data = VarData(
|
||||||
imports={
|
imports={
|
||||||
f"/{constants.Dirs.STATE_PATH}": {ImportVar(tag="generateUUID")}, # type: ignore
|
f"$/{constants.Dirs.STATE_PATH}": {ImportVar(tag="generateUUID")}, # type: ignore
|
||||||
"react": "useMemo",
|
"react": "useMemo",
|
||||||
},
|
},
|
||||||
hooks={f"const {unique_uuid_var} = useMemo(generateUUID, [])": None},
|
hooks={f"const {unique_uuid_var} = useMemo(generateUUID, [])": None},
|
||||||
|
@ -1090,7 +1090,7 @@ boolean_types = Union[BooleanVar, bool]
|
|||||||
|
|
||||||
|
|
||||||
_IS_TRUE_IMPORT: ImportDict = {
|
_IS_TRUE_IMPORT: ImportDict = {
|
||||||
f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
f"$/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ def test_websocket_target_url():
|
|||||||
var_data = url._get_all_var_data()
|
var_data = url._get_all_var_data()
|
||||||
assert var_data is not None
|
assert var_data is not None
|
||||||
assert sorted(tuple((key for key, _ in var_data.imports))) == sorted(
|
assert sorted(tuple((key for key, _ in var_data.imports))) == sorted(
|
||||||
("/utils/state", "/env.json")
|
("$/utils/state", "$/env.json")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -22,10 +22,10 @@ def test_connection_banner():
|
|||||||
assert sorted(tuple(_imports)) == sorted(
|
assert sorted(tuple(_imports)) == sorted(
|
||||||
(
|
(
|
||||||
"react",
|
"react",
|
||||||
"/utils/context",
|
"$/utils/context",
|
||||||
"/utils/state",
|
"$/utils/state",
|
||||||
"@radix-ui/themes@^3.0.0",
|
"@radix-ui/themes@^3.0.0",
|
||||||
"/env.json",
|
"$/env.json",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,10 +40,10 @@ def test_connection_modal():
|
|||||||
assert sorted(tuple(_imports)) == sorted(
|
assert sorted(tuple(_imports)) == sorted(
|
||||||
(
|
(
|
||||||
"react",
|
"react",
|
||||||
"/utils/context",
|
"$/utils/context",
|
||||||
"/utils/state",
|
"$/utils/state",
|
||||||
"@radix-ui/themes@^3.0.0",
|
"@radix-ui/themes@^3.0.0",
|
||||||
"/env.json",
|
"$/env.json",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user