@vicaniddouglas/js_aide 1.11.0 → 1.13.0

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/README.md CHANGED
@@ -8,6 +8,19 @@ A versatile collection of modular JavaScript utility helpers designed to streaml
8
8
 
9
9
  ## Features
10
10
 
11
+ ### 🎮 Live Playground
12
+ Explore all library features—including the new Asynchronous Handshaking system—directly in our interactive sandbox.
13
+
14
+ **Access via Repository:**
15
+ 1. Clone the repository: `git clone https://gitlab.com/vicaniddouglas/js_aide.git`
16
+ 2. Open `demo/index.html` in any modern browser.
17
+
18
+ **Access via NPM:**
19
+ If you have the package installed locally, you can run the playground using:
20
+ ```bash
21
+ npm explore @vicaniddouglas/js_aide -- npm run serve:demo
22
+ ```
23
+
11
24
  ### `Router`
12
25
 
13
26
  A modern, feature-rich client-side router for Single-Page Applications (SPAs).
@@ -230,13 +243,32 @@ Every call returns a Promise that always resolves to this structure:
230
243
  #### New Proactive Options
231
244
  | Option | Type | Default | Description |
232
245
  | :--- | :--- | :--- | :--- |
233
- | `onSuccess` | `Function` | `null` | Runs automatically if `status` is `true`. |
234
- | `onError` | `Function` | `null` | Runs automatically if `status` is `false`. |
246
+ | `onSuccess` | `Function` | `null` | Runs automatically if `status` is `true`. **Strictly awaited.** |
247
+ | `onError` | `Function` | `null` | Runs automatically if `status` is `false`. **Strictly awaited.** |
248
+ | `showLoading` | `Function` | `null` | Called with `true`/`false`. **Strictly awaited.** |
235
249
  | `silent` | `Boolean` | `false` | If `true`, disables the automatic Red Popup on error. |
236
250
 
237
251
  #### Usage Patterns
238
252
 
239
- **1. The "Fire and Forget" (Proactive Success)**
253
+ **1. The "Sequential Async Flow" (Awaiting Callbacks)**
254
+ Because `sendRequest` **strictly awaits** your callbacks, you can safely use `async/await` inside them without worrying about race conditions or premature page reloads.
255
+ ```javascript
256
+ import { sendRequest, popup } from "@vicaniddouglas/js_aide";
257
+
258
+ await sendRequest({
259
+ endpoint: '/api/save',
260
+ onSuccess: async (data) => {
261
+ // This popup is BEAUTIFUL and BLOCKING.
262
+ // sendRequest will NOT finish until the user clicks OK.
263
+ await popup.success("Settings Saved!");
264
+ }
265
+ });
266
+
267
+ // This reload is GUARANTEED to happen only after the popup is closed.
268
+ window.location.reload();
269
+ ```
270
+
271
+ **2. The "Fire and Forget" (Proactive Success)**
240
272
  No need to check status if you only care about success. If it fails, the user gets a popup automatically.
241
273
  ```javascript
242
274
  import { sendRequest } from "@vicaniddouglas/js_aide";
@@ -318,6 +350,40 @@ popup.success("Photo Uploaded!", {
318
350
  });
319
351
  ```
320
352
 
353
+ #### 4. Asynchronous Handshaking (Zero-Alert)
354
+ The popup system provides replacements for native `confirm()` and `prompt()` that are fully asynchronous, themeable, and non-blocking in the developer's logic (via `await`).
355
+
356
+ **Confirmation Dialogs**
357
+ Returns `true` on confirm, `false` on cancel/close.
358
+ ```javascript
359
+ const confirmed = await popup.confirm("Are you sure you want to delete this?");
360
+
361
+ if (confirmed) {
362
+ await deleteRecord();
363
+ await popup.success("Deleted!");
364
+ }
365
+ ```
366
+
367
+ **Data-Entry Prompts**
368
+ Returns the input value as a **string** on submit, or `null` if cancelled.
369
+ ```javascript
370
+ const name = await popup.prompt("Enter your display name:", {
371
+ placeholder: "e.g., Douglas",
372
+ inputType: "text" // Options: text, number, currency, password
373
+ });
374
+
375
+ if (name) {
376
+ console.log("Hello", name);
377
+ }
378
+ ```
379
+
380
+ | Prompt Option | Description |
381
+ | :--- | :--- |
382
+ | `inputType` | Controls input behavior (`text`, `number`, `currency`, `password`). |
383
+ | `defaultValue`| Initial text inside the input. |
384
+ | `submitText` | Text for the action button (default: "Submit"). |
385
+ | `cancelText` | Text for the dismiss button (default: "Cancel"). |
386
+
321
387
  ## Development
322
388
 
323
389
  ### Running Tests
package/declarations.d.ts CHANGED
@@ -313,7 +313,10 @@ declare module "@vicaniddouglas/js_aide" {
313
313
  useQueue?: boolean;
314
314
  priority?: number;
315
315
  responseType?: "json" | "text";
316
- showLoading?: (isLoading: boolean) => void;
316
+ showLoading?: (isLoading: boolean) => void | Promise<void>;
317
+ onSuccess?: (data: any) => void | Promise<void>;
318
+ onError?: (log: string) => void | Promise<void>;
319
+ silent?: boolean;
317
320
  }
318
321
 
319
322
  type RequestInterceptor = (
@@ -1247,6 +1250,26 @@ declare module "@vicaniddouglas/js_aide" {
1247
1250
  color?: string;
1248
1251
  }
1249
1252
 
1253
+ interface ConfirmOptions extends PopupOptions {
1254
+ /** Text for the confirm button (default: "Confirm") */
1255
+ confirmText?: string;
1256
+ /** Text for the cancel button (default: "Cancel") */
1257
+ cancelText?: string;
1258
+ }
1259
+
1260
+ interface PromptOptions extends PopupOptions {
1261
+ /** Type of input: text, number, currency, or password */
1262
+ inputType?: "text" | "number" | "currency" | "password";
1263
+ /** Input placeholder text */
1264
+ placeholder?: string;
1265
+ /** Initial value for the input */
1266
+ defaultValue?: string;
1267
+ /** Text for the submit button (default: "Submit") */
1268
+ submitText?: string;
1269
+ /** Text for the cancel button (default: "Cancel") */
1270
+ cancelText?: string;
1271
+ }
1272
+
1250
1273
  export const popup: {
1251
1274
  /** Show a success modal (Green theme) */
1252
1275
  success(message: string, options?: PopupOptions): Promise<void>;
@@ -1254,6 +1277,10 @@ declare module "@vicaniddouglas/js_aide" {
1254
1277
  error(message: string, options?: PopupOptions): Promise<void>;
1255
1278
  /** Show an info modal (Blue theme) */
1256
1279
  info(message: string, options?: PopupOptions): Promise<void>;
1280
+ /** Show a confirmation dialog (Slate theme). Returns true if confirmed, false otherwise. */
1281
+ confirm(message: string, options?: ConfirmOptions): Promise<boolean>;
1282
+ /** Show a prompt dialog (Slate theme). Returns the value if submitted, null if cancelled. */
1283
+ prompt(message: string, options?: PromptOptions): Promise<string | null>;
1257
1284
  /** Programmatically close the current modal */
1258
1285
  close(): void;
1259
1286
  };