@warpfx/client 0.1.3 → 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/dist/index.d.ts +102 -7
- package/dist/index.js +27 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,17 @@
|
|
|
5
5
|
* all calls go through FiveM's resource exports to the 'warp' resource.
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
|
-
* import { onReady, getEvents } from '@warp/client';
|
|
8
|
+
* import { onReady, getEvents, registerKeybind, sendNUI } from '@warp/client';
|
|
9
9
|
*
|
|
10
10
|
* onReady(() => {
|
|
11
11
|
* const events = getEvents();
|
|
12
12
|
* events.onServer('economy:balance', (data) => { ... });
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* registerKeybind('open_shop', {
|
|
15
|
+
* description: 'Open Shop',
|
|
16
|
+
* key: 'E',
|
|
17
|
+
* onPress: () => showNUI('shop'),
|
|
18
|
+
* });
|
|
14
19
|
* });
|
|
15
20
|
*/
|
|
16
21
|
/** Typed event bus for client-side and network communication. */
|
|
@@ -28,6 +33,24 @@ interface ClientEventBus<TMap extends Record<string, any> = Record<string, any>>
|
|
|
28
33
|
/** Unsubscribe from a server event. */
|
|
29
34
|
offServer<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
30
35
|
}
|
|
36
|
+
/** Key binding configuration. */
|
|
37
|
+
interface KeybindOptions {
|
|
38
|
+
/** Description shown in FiveM key mapping settings. */
|
|
39
|
+
description: string;
|
|
40
|
+
/** Default key (e.g. 'T', 'E', 'F5'). */
|
|
41
|
+
key: string;
|
|
42
|
+
/** Input device (defaults to 'keyboard'). */
|
|
43
|
+
device?: "keyboard" | "mouse_button" | "pad_analogbutton";
|
|
44
|
+
/** Callback when the key is pressed. */
|
|
45
|
+
onPress: () => void;
|
|
46
|
+
/** Callback when the key is released (optional). */
|
|
47
|
+
onRelease?: () => void;
|
|
48
|
+
}
|
|
49
|
+
/** Options for showNUI(). */
|
|
50
|
+
interface ShowNUIOptions {
|
|
51
|
+
/** Whether to show the mouse cursor. Defaults to true. */
|
|
52
|
+
cursor?: boolean;
|
|
53
|
+
}
|
|
31
54
|
/**
|
|
32
55
|
* Register a callback to run when Warp client is ready.
|
|
33
56
|
* If already ready, the callback fires immediately.
|
|
@@ -91,11 +114,83 @@ declare function useErrorHandler(handler: (error: ActionError) => void): () => v
|
|
|
91
114
|
*/
|
|
92
115
|
declare function getSyncState<T = any>(key: string): T | undefined;
|
|
93
116
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
117
|
+
* Call a server function and await the result.
|
|
118
|
+
*
|
|
119
|
+
* Unlike actions (fire-and-forget), this returns a Promise that resolves
|
|
120
|
+
* with the server's return value. Use for request/response patterns.
|
|
121
|
+
*
|
|
122
|
+
* @param name The registered function name.
|
|
123
|
+
* @param payload Optional data to send to the server.
|
|
124
|
+
* @param timeout Timeout in ms (default: 10000).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* const { balance } = await callServer<{ balance: number }>('economy:getBalance');
|
|
128
|
+
* const result = await callServer('shop:getPrice', { itemId: 'bread' });
|
|
96
129
|
*/
|
|
97
|
-
declare function
|
|
98
|
-
/**
|
|
130
|
+
declare function callServer<T = any>(name: string, payload?: any, timeout?: number): Promise<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Show the NUI overlay with focus.
|
|
133
|
+
* Optionally specify a panel name and cursor control.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* showNUI('inventory'); // panel + keyboard + cursor
|
|
137
|
+
* showNUI('chat', { cursor: false }); // panel + keyboard only
|
|
138
|
+
*/
|
|
139
|
+
declare function showNUI(panel?: string, opts?: ShowNUIOptions): void;
|
|
140
|
+
/** Hide the NUI overlay and release all focus. */
|
|
99
141
|
declare function hideNUI(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Set NUI focus directly without sending visibility events.
|
|
144
|
+
* Use this for custom focus control (e.g. keyboard-only overlays).
|
|
145
|
+
*
|
|
146
|
+
* @param hasFocus Whether NUI should capture keyboard input.
|
|
147
|
+
* @param hasCursor Whether to show the mouse cursor. Defaults to match hasFocus.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* setNUIFocus(true, false); // keyboard only, no cursor
|
|
151
|
+
* setNUIFocus(false); // release all focus
|
|
152
|
+
*/
|
|
153
|
+
declare function setNUIFocus(hasFocus: boolean, hasCursor?: boolean): void;
|
|
154
|
+
/**
|
|
155
|
+
* Send a message to the NUI (browser) layer.
|
|
156
|
+
* The payload fields are spread into the message alongside the type.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* sendNUI('inventory:open', { tab: 'weapons' });
|
|
160
|
+
* // NUI receives: { type: 'inventory:open', tab: 'weapons' }
|
|
161
|
+
*/
|
|
162
|
+
declare function sendNUI(type: string, payload?: Record<string, any>): void;
|
|
163
|
+
/**
|
|
164
|
+
* Register a handler for NUI callbacks (browser → client).
|
|
165
|
+
*
|
|
166
|
+
* When the NUI calls `fetch('https://warp/{name}', ...)`, this handler
|
|
167
|
+
* fires. Return a value to send it back to the NUI, or return nothing
|
|
168
|
+
* for the default `{ ok: true }` response.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* onNUI('inventoryDrop', (data) => {
|
|
172
|
+
* console.log('Dropped item:', data.itemId);
|
|
173
|
+
* });
|
|
174
|
+
*/
|
|
175
|
+
declare function onNUI<T = any>(name: string, handler: (data: T) => any): void;
|
|
176
|
+
/**
|
|
177
|
+
* Register a key binding with FiveM's key mapping system.
|
|
178
|
+
* Players can rebind the key in their FiveM settings.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* registerKeybind('open_inventory', {
|
|
182
|
+
* description: 'Open Inventory',
|
|
183
|
+
* key: 'I',
|
|
184
|
+
* onPress: () => showNUI('inventory'),
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* registerKeybind('sprint_boost', {
|
|
188
|
+
* description: 'Sprint Boost',
|
|
189
|
+
* key: 'LSHIFT',
|
|
190
|
+
* onPress: () => startBoost(),
|
|
191
|
+
* onRelease: () => stopBoost(),
|
|
192
|
+
* });
|
|
193
|
+
*/
|
|
194
|
+
declare function registerKeybind(name: string, options: KeybindOptions): void;
|
|
100
195
|
|
|
101
|
-
export { type ActionError, type ClientEventBus, type SyncHandle, getEvents, getSyncState, hideNUI, isReady, onReady, showNUI, useAction, useErrorHandler, useSync };
|
|
196
|
+
export { type ActionError, type ClientEventBus, type KeybindOptions, type ShowNUIOptions, type SyncHandle, callServer, getEvents, getSyncState, hideNUI, isReady, onNUI, onReady, registerKeybind, sendNUI, setNUIFocus, showNUI, useAction, useErrorHandler, useSync };
|
package/dist/index.js
CHANGED
|
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
callServer: () => callServer,
|
|
23
24
|
getEvents: () => getEvents,
|
|
24
25
|
getSyncState: () => getSyncState,
|
|
25
26
|
hideNUI: () => hideNUI,
|
|
26
27
|
isReady: () => isReady,
|
|
28
|
+
onNUI: () => onNUI,
|
|
27
29
|
onReady: () => onReady,
|
|
30
|
+
registerKeybind: () => registerKeybind,
|
|
31
|
+
sendNUI: () => sendNUI,
|
|
32
|
+
setNUIFocus: () => setNUIFocus,
|
|
28
33
|
showNUI: () => showNUI,
|
|
29
34
|
useAction: () => useAction,
|
|
30
35
|
useErrorHandler: () => useErrorHandler,
|
|
@@ -55,19 +60,39 @@ function useErrorHandler(handler) {
|
|
|
55
60
|
function getSyncState(key) {
|
|
56
61
|
return warp().getSyncState(key);
|
|
57
62
|
}
|
|
58
|
-
function
|
|
59
|
-
warp().
|
|
63
|
+
function callServer(name, payload, timeout) {
|
|
64
|
+
return warp().callServer(name, payload, timeout);
|
|
65
|
+
}
|
|
66
|
+
function showNUI(panel, opts) {
|
|
67
|
+
warp().showNUI(panel, opts);
|
|
60
68
|
}
|
|
61
69
|
function hideNUI() {
|
|
62
70
|
warp().hideNUI();
|
|
63
71
|
}
|
|
72
|
+
function setNUIFocus(hasFocus, hasCursor) {
|
|
73
|
+
warp().setNUIFocus(hasFocus, hasCursor);
|
|
74
|
+
}
|
|
75
|
+
function sendNUI(type, payload) {
|
|
76
|
+
warp().sendNUI(type, payload);
|
|
77
|
+
}
|
|
78
|
+
function onNUI(name, handler) {
|
|
79
|
+
warp().onNUI(name, handler);
|
|
80
|
+
}
|
|
81
|
+
function registerKeybind(name, options) {
|
|
82
|
+
warp().registerKeybind(name, options);
|
|
83
|
+
}
|
|
64
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
85
|
0 && (module.exports = {
|
|
86
|
+
callServer,
|
|
66
87
|
getEvents,
|
|
67
88
|
getSyncState,
|
|
68
89
|
hideNUI,
|
|
69
90
|
isReady,
|
|
91
|
+
onNUI,
|
|
70
92
|
onReady,
|
|
93
|
+
registerKeybind,
|
|
94
|
+
sendNUI,
|
|
95
|
+
setNUIFocus,
|
|
71
96
|
showNUI,
|
|
72
97
|
useAction,
|
|
73
98
|
useErrorHandler,
|