flet-box 0.0.0-stage → 1.0.2
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 +21 -0
- package/README.md +190 -2
- package/bin/cli.js +394 -0
- package/bin/commands/buildAndroid.js +200 -0
- package/bin/commands/buildIOS.js +237 -0
- package/bin/commands/create.js +406 -0
- package/bin/commands/createBundle.js +375 -0
- package/bin/commands/createComponent.js +115 -0
- package/bin/commands/createScreen.js +161 -0
- package/bin/commands/killServer.js +107 -0
- package/bin/commands/package.js +131 -0
- package/bin/commands/release.js +189 -0
- package/bin/commands/runBundle.js +62 -0
- package/bin/commands/runCloudflare.js +89 -0
- package/bin/commands/runNative.js +109 -0
- package/bin/commands/runServer.js +390 -0
- package/bin/ota/loader.js +361 -0
- package/bin/utils/bundleConfig.js +178 -0
- package/bin/utils/capacitor.js +137 -0
- package/bin/utils/colors.js +215 -0
- package/bin/utils/helpers.js +80 -0
- package/bin/utils/spinner.js +96 -0
- package/bin/utils/templates.js +1824 -0
- package/bin/utils/version.js +108 -0
- package/package.json +58 -4
- package/src/animations/AnimatedBox.js +607 -0
- package/src/animations/AnimatedText.js +105 -0
- package/src/animations/MatrixRain.js +220 -0
- package/src/animations/ParallaxBox.js +369 -0
- package/src/animations/animate.js +332 -0
- package/src/animations/index.js +25 -0
- package/src/app.js +41 -0
- package/src/assets/icon-1024-maskable.png +0 -0
- package/src/assets/icon-192-maskable.png +0 -0
- package/src/assets/icon-192.png +0 -0
- package/src/assets/icon-512-maskable.png +0 -0
- package/src/assets/icon-512.png +0 -0
- package/src/assets/logo.png +0 -0
- package/src/core/App.js +44 -0
- package/src/core/hmr-client.js +142 -0
- package/src/core/index.js +34 -0
- package/src/core/pwa.js +100 -0
- package/src/core/runApp.js +430 -0
- package/src/create-index.sh +237 -0
- package/src/fonts/MaterialIcons-Regular.woff2 +0 -0
- package/src/fonts/icons.css +23 -0
- package/src/index.d.ts +1930 -0
- package/src/index.js +288 -0
- package/src/navigations/AdaptiveScaffold.js +149 -0
- package/src/navigations/AppBar.js +331 -0
- package/src/navigations/BottomNavigation.js +298 -0
- package/src/navigations/CollapsibleSideBar.js +139 -0
- package/src/navigations/Drawer.js +333 -0
- package/src/navigations/DrawerItem.js +260 -0
- package/src/navigations/Router.js +475 -0
- package/src/navigations/Scaffold.js +537 -0
- package/src/navigations/Tabs.js +384 -0
- package/src/navigations/index.js +57 -0
- package/src/services/RamStore.js +213 -0
- package/src/services/Session.js +310 -0
- package/src/services/Storage.js +309 -0
- package/src/services/http.js +350 -0
- package/src/services/index.js +57 -0
- package/src/tools/animation.js +42 -0
- package/src/tools/array.js +95 -0
- package/src/tools/border.js +28 -0
- package/src/tools/clipboard.js +104 -0
- package/src/tools/color.js +329 -0
- package/src/tools/createList.js +215 -0
- package/src/tools/delay.js +55 -0
- package/src/tools/device.js +138 -0
- package/src/tools/dict.js +297 -0
- package/src/tools/dimensions.js +118 -0
- package/src/tools/filter.js +41 -0
- package/src/tools/flex.js +26 -0
- package/src/tools/gradient.js +34 -0
- package/src/tools/grid.js +57 -0
- package/src/tools/index.js +38 -0
- package/src/tools/mapList.js +107 -0
- package/src/tools/margin.js +93 -0
- package/src/tools/memo.js +60 -0
- package/src/tools/os.js +104 -0
- package/src/tools/padding.js +93 -0
- package/src/tools/print.js +69 -0
- package/src/tools/random.js +299 -0
- package/src/tools/ref.js +70 -0
- package/src/tools/rgba.js +4 -0
- package/src/tools/shadow.js +23 -0
- package/src/tools/string.js +85 -0
- package/src/tools/time.js +674 -0
- package/src/tools/transform.js +68 -0
- package/src/tools/transition.js +48 -0
- package/src/tools/useState.js +268 -0
- package/src/tools/uuid.js +42 -0
- package/src/utils/TextInputValidator.js +256 -0
- package/src/utils/composeUpdate.js +65 -0
- package/src/utils/getWidgetProps.js +35 -0
- package/src/utils/index.js +76 -0
- package/src/utils/markdownParser.js +368 -0
- package/src/utils/mediaTime.js +79 -0
- package/src/utils/navigation.js +263 -0
- package/src/utils/scriptInjector.js +73 -0
- package/src/utils/stackPosition.js +31 -0
- package/src/utils/stopWebRefresh.js +77 -0
- package/src/utils/styleInjector.js +38 -0
- package/src/utils/syntaxHighlight.js +339 -0
- package/src/utils/themes.js +347 -0
- package/src/utils/units.js +87 -0
- package/src/utils/visualEffects.js +169 -0
- package/src/widget-factory/addChildren.js +114 -0
- package/src/widget-factory/assignProps.js +256 -0
- package/src/widget-factory/createWidget.js +28 -0
- package/src/widget-factory/effects.js +132 -0
- package/src/widget-factory/index.js +7 -0
- package/src/widget-factory/lifecycle.js +210 -0
- package/src/widget-factory/makeParentable.js +89 -0
- package/src/widget-factory/pixTool.js +40 -0
- package/src/widget-factory/processProps.js +122 -0
- package/src/widget-factory/reactivity.js +98 -0
- package/src/widget-factory/remTool.js +34 -0
- package/src/widget-factory/stackPosition.js +87 -0
- package/src/widget-factory/stringTool.js +26 -0
- package/src/widget-factory/tools.js +249 -0
- package/src/widget-factory/translateProps.js +1049 -0
- package/src/widget-factory/warnings.js +284 -0
- package/src/widget-factory/widgetFactory.js +200 -0
- package/src/widgets/Accordion.js +562 -0
- package/src/widgets/AdMob.js +315 -0
- package/src/widgets/AdSense.js +268 -0
- package/src/widgets/AlertDialog.js +162 -0
- package/src/widgets/Audio.js +311 -0
- package/src/widgets/Avatar.js +210 -0
- package/src/widgets/Badge.js +189 -0
- package/src/widgets/BottomSheet.js +287 -0
- package/src/widgets/Button.js +247 -0
- package/src/widgets/Card.js +33 -0
- package/src/widgets/Carousel.js +301 -0
- package/src/widgets/Chart.js +632 -0
- package/src/widgets/Checkbox.js +106 -0
- package/src/widgets/Chip.js +153 -0
- package/src/widgets/CircularBar.js +352 -0
- package/src/widgets/CircularChart.js +549 -0
- package/src/widgets/CodeViewer.js +236 -0
- package/src/widgets/Column.js +29 -0
- package/src/widgets/Container.js +31 -0
- package/src/widgets/DataTable.js +257 -0
- package/src/widgets/Divider.js +93 -0
- package/src/widgets/DraggBox.js +115 -0
- package/src/widgets/Dropdown.js +505 -0
- package/src/widgets/DroppBox.js +180 -0
- package/src/widgets/FloatingActionButton.js +91 -0
- package/src/widgets/GridView.js +20 -0
- package/src/widgets/Icon.js +33 -0
- package/src/widgets/Image.js +15 -0
- package/src/widgets/Input.js +565 -0
- package/src/widgets/Inspector.js +254 -0
- package/src/widgets/InstallButton.js +110 -0
- package/src/widgets/ListTile.js +224 -0
- package/src/widgets/ListView.js +503 -0
- package/src/widgets/Markdown.js +1236 -0
- package/src/widgets/Modal.js +496 -0
- package/src/widgets/Pagination.js +195 -0
- package/src/widgets/ProgressBar.js +178 -0
- package/src/widgets/QRCode.js +467 -0
- package/src/widgets/Radio.js +132 -0
- package/src/widgets/Rating.js +261 -0
- package/src/widgets/Row.js +29 -0
- package/src/widgets/Skeleton.js +243 -0
- package/src/widgets/Slider.js +527 -0
- package/src/widgets/SnackBar.js +227 -0
- package/src/widgets/Stack.js +29 -0
- package/src/widgets/Stepper.js +296 -0
- package/src/widgets/Switch.js +102 -0
- package/src/widgets/Text.js +98 -0
- package/src/widgets/Tooltip.js +267 -0
- package/src/widgets/TreeView.js +370 -0
- package/src/widgets/Video.js +92 -0
- package/src/widgets/index.js +52 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// src/navigations/DrawerItem.js
|
|
2
|
+
import { Container } from "../widgets/Container.js";
|
|
3
|
+
import { Row } from "../widgets/Row.js";
|
|
4
|
+
import { Text } from "../widgets/Text.js";
|
|
5
|
+
import { Icon } from "../widgets/Icon.js";
|
|
6
|
+
import { colors } from "../utils/themes.js";
|
|
7
|
+
import { goTo, subscribe, getCurrentPath } from "./Router.js";
|
|
8
|
+
import { closeDrawer } from "./Drawer.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Module-level EventTarget used to broadcast selection events between all
|
|
12
|
+
* DrawerItem instances in the same drawer. When one item is selected, all
|
|
13
|
+
* others listen to the "drawer-item-selected" event and deactivate themselves,
|
|
14
|
+
* ensuring only one item appears active at a time without global mutable state.
|
|
15
|
+
*
|
|
16
|
+
* @type {EventTarget}
|
|
17
|
+
*/
|
|
18
|
+
const selectionEvent = new EventTarget();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Cached copy of the current route path at module load time.
|
|
22
|
+
* Updated via the router subscription so every item can determine its own
|
|
23
|
+
* active state without re-querying the router on every render.
|
|
24
|
+
*
|
|
25
|
+
* @type {string}
|
|
26
|
+
*/
|
|
27
|
+
let globalCurrentPath = getCurrentPath();
|
|
28
|
+
|
|
29
|
+
// Keep the module-level path cache in sync with router navigations.
|
|
30
|
+
subscribe(() => {
|
|
31
|
+
globalCurrentPath = getCurrentPath();
|
|
32
|
+
selectionEvent.dispatchEvent(
|
|
33
|
+
new CustomEvent("route-changed", { detail: { path: globalCurrentPath } }),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {Object} DrawerItemProps
|
|
39
|
+
* @property {string} [icon] - Material Icon name shown at the leading edge.
|
|
40
|
+
* @property {string} label - Display label (also used as the item's unique identity for selection broadcasts).
|
|
41
|
+
* @property {string} [route] - Router path navigated to when the item is pressed.
|
|
42
|
+
* @property {Function} [onPress] - Additional callback fired on every press, after routing.
|
|
43
|
+
* @property {Function} [onSelect] - Callback fired only on the first press when the item transitions to selected.
|
|
44
|
+
* @property {number} [borderRadius=24] - Corner radius of the item container.
|
|
45
|
+
* @property {number} [gap=12] - Gap between the icon, label, and trailing icon.
|
|
46
|
+
* @property {boolean} [disableTransform=true] - Disable CSS transform effects (avoids stacking context issues inside a drawer).
|
|
47
|
+
* @property {string} [trailingIcon="chevron_right"] - Material Icon name at the trailing edge.
|
|
48
|
+
* @property {string} [hintColor] - Background tint on hover when the item is not selected.
|
|
49
|
+
* @property {string} [selectedColor] - Accent color applied to text, icon, and background when active.
|
|
50
|
+
* @property {string} [unselectedColor] - Default text and icon color when inactive.
|
|
51
|
+
* @property {string} [iconColor] - Override color for the leading icon (defaults to selectedColor/unselectedColor).
|
|
52
|
+
* @property {string} [trailingIconColor] - Override color for the trailing icon.
|
|
53
|
+
* @property {boolean} [closeOnPress=true] - Whether to close the containing drawer automatically on press.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* DrawerItem renders a single tappable row inside a Drawer.
|
|
58
|
+
*
|
|
59
|
+
* It syncs its selected state with the router so the active route is always
|
|
60
|
+
* visually highlighted. When pressed, it navigates to `route`, fires any
|
|
61
|
+
* callbacks, optionally closes the drawer, and broadcasts a selection event
|
|
62
|
+
* so sibling DrawerItems can deactivate themselves.
|
|
63
|
+
*
|
|
64
|
+
* Keyboard navigation is supported: Enter and Space trigger the same action
|
|
65
|
+
* as a click, and the item has `role="button"` and `aria-selected` for
|
|
66
|
+
* screen-reader compatibility.
|
|
67
|
+
*
|
|
68
|
+
* @param {DrawerItemProps} props
|
|
69
|
+
* @returns {HTMLElement} The item container element.
|
|
70
|
+
*/
|
|
71
|
+
export const DrawerItem = (props) => {
|
|
72
|
+
const {
|
|
73
|
+
icon,
|
|
74
|
+
label,
|
|
75
|
+
route,
|
|
76
|
+
onPress,
|
|
77
|
+
onSelect,
|
|
78
|
+
borderRadius = 24,
|
|
79
|
+
gap = 12,
|
|
80
|
+
disableTransform = true,
|
|
81
|
+
trailingIcon = "chevron_right",
|
|
82
|
+
hintColor = colors.gray100,
|
|
83
|
+
selectedColor = colors.primary,
|
|
84
|
+
unselectedColor = colors.text,
|
|
85
|
+
iconColor,
|
|
86
|
+
trailingIconColor,
|
|
87
|
+
closeOnPress = true,
|
|
88
|
+
...rest
|
|
89
|
+
} = props;
|
|
90
|
+
|
|
91
|
+
// DOM references held in closure so updateUI can mutate them without
|
|
92
|
+
// querying the DOM repeatedly.
|
|
93
|
+
let containerRef = null;
|
|
94
|
+
let textRef = null;
|
|
95
|
+
let iconRef = null;
|
|
96
|
+
let trailingIconRef = null;
|
|
97
|
+
let isSelected = false;
|
|
98
|
+
let unsubscribeRouter = null;
|
|
99
|
+
let unsubscribeGlobal = null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Apply visual styles that reflect the current selected/unselected state.
|
|
103
|
+
* Called whenever `isSelected` changes.
|
|
104
|
+
*/
|
|
105
|
+
const updateUI = () => {
|
|
106
|
+
const finalTextColor = isSelected ? selectedColor : unselectedColor;
|
|
107
|
+
const finalIconColor = iconColor || finalTextColor;
|
|
108
|
+
const finalTrailingIconColor = trailingIconColor || finalTextColor;
|
|
109
|
+
|
|
110
|
+
if (containerRef) {
|
|
111
|
+
// Subtle tinted background on the selected item for visual hierarchy.
|
|
112
|
+
containerRef.style.backgroundColor = isSelected
|
|
113
|
+
? `${selectedColor}15`
|
|
114
|
+
: "transparent";
|
|
115
|
+
// Reflect selection state for screen readers.
|
|
116
|
+
containerRef.setAttribute("aria-selected", isSelected.toString());
|
|
117
|
+
}
|
|
118
|
+
if (textRef) {
|
|
119
|
+
textRef.style.color = finalTextColor;
|
|
120
|
+
textRef.style.fontWeight = isSelected ? "600" : "400";
|
|
121
|
+
}
|
|
122
|
+
if (iconRef) iconRef.style.color = finalIconColor;
|
|
123
|
+
if (trailingIconRef) trailingIconRef.style.color = finalTrailingIconColor;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Compare the current router path against this item's `route` and update
|
|
128
|
+
* `isSelected` accordingly. Only triggers a UI update when the state
|
|
129
|
+
* actually changes to avoid unnecessary DOM writes.
|
|
130
|
+
*/
|
|
131
|
+
const checkActive = () => {
|
|
132
|
+
const currentPath = getCurrentPath();
|
|
133
|
+
const shouldBeSelected =
|
|
134
|
+
route === currentPath || (route === "/" && currentPath === "");
|
|
135
|
+
if (shouldBeSelected !== isSelected) {
|
|
136
|
+
isSelected = shouldBeSelected;
|
|
137
|
+
updateUI();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Handle a press/click on the item.
|
|
143
|
+
* Order of operations: mark selected → fire callbacks → navigate → close drawer.
|
|
144
|
+
*/
|
|
145
|
+
const handleClick = () => {
|
|
146
|
+
if (!isSelected) {
|
|
147
|
+
isSelected = true;
|
|
148
|
+
updateUI();
|
|
149
|
+
// Broadcast to siblings so they deactivate themselves.
|
|
150
|
+
selectionEvent.dispatchEvent(
|
|
151
|
+
new CustomEvent("drawer-item-selected", { detail: { id: label } }),
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (onSelect) onSelect();
|
|
155
|
+
if (onPress) onPress();
|
|
156
|
+
if (route) goTo(route);
|
|
157
|
+
if (closeOnPress) closeDrawer();
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Subscribe to router changes to keep the active state in sync with
|
|
161
|
+
// browser back/forward navigation and programmatic goTo() calls.
|
|
162
|
+
unsubscribeRouter = subscribe(() => checkActive());
|
|
163
|
+
|
|
164
|
+
// Listen for sibling selection events: if another item was just selected,
|
|
165
|
+
// deactivate this one.
|
|
166
|
+
const handleGlobalSelection = (e) => {
|
|
167
|
+
if (isSelected && e.detail.id !== label) {
|
|
168
|
+
isSelected = false;
|
|
169
|
+
updateUI();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
selectionEvent.addEventListener("drawer-item-selected", handleGlobalSelection);
|
|
173
|
+
unsubscribeGlobal = () =>
|
|
174
|
+
selectionEvent.removeEventListener(
|
|
175
|
+
"drawer-item-selected",
|
|
176
|
+
handleGlobalSelection,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
// Compute initial active state before first render.
|
|
180
|
+
checkActive();
|
|
181
|
+
|
|
182
|
+
const container = Container({
|
|
183
|
+
padding: "12px 16px",
|
|
184
|
+
cursor: "pointer",
|
|
185
|
+
borderRadius: borderRadius,
|
|
186
|
+
margin: "4px 8px",
|
|
187
|
+
disableTransform: disableTransform,
|
|
188
|
+
// Keyboard accessibility: allow focus and respond to Enter/Space.
|
|
189
|
+
role: "button",
|
|
190
|
+
tabIndex: 0,
|
|
191
|
+
"aria-selected": isSelected.toString(),
|
|
192
|
+
onKeyDown: (e) => {
|
|
193
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
handleClick();
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
onclick: handleClick,
|
|
199
|
+
onHover: (e) => {
|
|
200
|
+
if (!isSelected) e.currentTarget.style.backgroundColor = hintColor;
|
|
201
|
+
},
|
|
202
|
+
onHoverEnd: (e) => {
|
|
203
|
+
if (!isSelected) e.currentTarget.style.backgroundColor = "transparent";
|
|
204
|
+
},
|
|
205
|
+
...rest,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// ========== BUILD ROW CONTENT ==========
|
|
209
|
+
const rowChildren = [];
|
|
210
|
+
|
|
211
|
+
if (icon) {
|
|
212
|
+
const iconWidget = Icon({ name: icon, size: 22, color: unselectedColor });
|
|
213
|
+
rowChildren.push(iconWidget);
|
|
214
|
+
iconRef = iconWidget;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const textWidget = Text({
|
|
218
|
+
text: label,
|
|
219
|
+
size: 15,
|
|
220
|
+
color: unselectedColor,
|
|
221
|
+
fontWeight: "400",
|
|
222
|
+
flex: 1,
|
|
223
|
+
});
|
|
224
|
+
rowChildren.push(textWidget);
|
|
225
|
+
textRef = textWidget;
|
|
226
|
+
|
|
227
|
+
if (trailingIcon) {
|
|
228
|
+
const trailWidget = Icon({
|
|
229
|
+
name: trailingIcon,
|
|
230
|
+
size: 18,
|
|
231
|
+
color: unselectedColor,
|
|
232
|
+
});
|
|
233
|
+
rowChildren.push(trailWidget);
|
|
234
|
+
trailingIconRef = trailWidget;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const row = Row({
|
|
238
|
+
alignItems: "center",
|
|
239
|
+
justifyContent: "space-between",
|
|
240
|
+
gap: gap,
|
|
241
|
+
children: rowChildren,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
container.appendChild(row);
|
|
245
|
+
containerRef = container;
|
|
246
|
+
// Apply the initial visual state now that DOM refs are set.
|
|
247
|
+
updateUI();
|
|
248
|
+
|
|
249
|
+
// Cleanup: unsubscribe from router and selection events to prevent memory leaks.
|
|
250
|
+
const originalCleanup = container._cleanup;
|
|
251
|
+
container._cleanup = () => {
|
|
252
|
+
if (unsubscribeRouter) unsubscribeRouter();
|
|
253
|
+
if (unsubscribeGlobal) unsubscribeGlobal();
|
|
254
|
+
if (originalCleanup) originalCleanup();
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
return container;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export default DrawerItem;
|