@herdingbits/trailhead-webawesome 0.1.2 → 0.2.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/dist/adapter.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Web Awesome Design System Adapter
3
3
  */
4
- import type { DesignSystemAdapter, FeedbackAdapter } from '@herdingbits/trailhead-types/adapters';
4
+ import type { DesignSystemAdapter, FeedbackAdapter, AuthAdapter } from '@herdingbits/trailhead-types/adapters';
5
5
  export interface WebAwesomeAdapterConfig {
6
6
  /** URL where Web Awesome is hosted (CDN or local path). Defaults to `${shellUrl}/webawesome`. */
7
7
  webAwesomeUrl?: string;
@@ -10,6 +10,7 @@ export declare class WebAwesomeAdapter implements DesignSystemAdapter {
10
10
  name: string;
11
11
  version: string;
12
12
  feedback: FeedbackAdapter;
13
+ auth: AuthAdapter;
13
14
  private readonly config?;
14
15
  constructor(config?: WebAwesomeAdapterConfig);
15
16
  init(shellUrl: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAA4C,MAAM,uCAAuC,CAAC;AA2F5I,MAAM,WAAW,uBAAuB;IACtC,iGAAiG;IACjG,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,iBAAkB,YAAW,mBAAmB;IAC3D,IAAI,SAAgB;IACpB,OAAO,SAAW;IAClB,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA0B;gBAEtC,MAAM,CAAC,EAAE,uBAAuB;IAKtC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB5C"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAA4C,WAAW,EAAuC,MAAM,uCAAuC,CAAC;AAuJ9L,MAAM,WAAW,uBAAuB;IACtC,iGAAiG;IACjG,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,iBAAkB,YAAW,mBAAmB;IAC3D,IAAI,SAAgB;IACpB,OAAO,SAAW;IAClB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA0B;gBAEtC,MAAM,CAAC,EAAE,uBAAuB;IAMtC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkB5C"}
package/dist/adapter.js CHANGED
@@ -75,12 +75,67 @@ class WebAwesomeFeedbackAdapter {
75
75
  });
76
76
  }
77
77
  }
78
+ class WebAwesomeAuthAdapter {
79
+ promptCredentials(errorMessage) {
80
+ let settle;
81
+ const result = new Promise((resolve) => {
82
+ settle = resolve;
83
+ });
84
+ let settled = false;
85
+ const dialog = document.createElement("div");
86
+ dialog.className = "shell-dialog-overlay";
87
+ dialog.innerHTML = `
88
+ <div class="shell-dialog">
89
+ <div class="shell-dialog-title">Session Expired</div>
90
+ <div class="shell-dialog-message">Sign in to continue where you left off.</div>
91
+ ${errorMessage ? `<div class="shell-dialog-error">${errorMessage}</div>` : ""}
92
+ <form class="shell-auth-form">
93
+ <input type="text" name="username" placeholder="Username" autocomplete="username" required />
94
+ <input type="password" name="password" placeholder="Password" autocomplete="current-password" required />
95
+ <div class="shell-dialog-buttons">
96
+ <button type="button" class="shell-btn shell-btn-secondary" data-action="cancel">Cancel</button>
97
+ <button type="submit" class="shell-btn shell-btn-primary">Sign In</button>
98
+ </div>
99
+ </form>
100
+ </div>
101
+ `;
102
+ const settleOnce = (value) => {
103
+ if (settled)
104
+ return;
105
+ settled = true;
106
+ dialog.remove();
107
+ settle(value);
108
+ };
109
+ const form = dialog.querySelector("form");
110
+ form.addEventListener("submit", (e) => {
111
+ e.preventDefault();
112
+ const data = new FormData(form);
113
+ settleOnce({
114
+ username: String(data.get("username") ?? ""),
115
+ password: String(data.get("password") ?? ""),
116
+ });
117
+ });
118
+ dialog.querySelector('[data-action="cancel"]')?.addEventListener("click", () => settleOnce(null));
119
+ // Click outside to cancel — matches showDialog's existing convention.
120
+ dialog.onclick = (e) => {
121
+ if (e.target === dialog)
122
+ settleOnce(null);
123
+ };
124
+ document.body.appendChild(dialog);
125
+ dialog.querySelector('input[name="username"]')?.focus();
126
+ return {
127
+ result,
128
+ close: () => settleOnce(null),
129
+ };
130
+ }
131
+ }
78
132
  export class WebAwesomeAdapter {
79
133
  constructor(config) {
80
134
  this.name = "webawesome";
81
135
  this.version = "1.0.0";
82
136
  this.config = config;
83
137
  this.feedback = new WebAwesomeFeedbackAdapter();
138
+ this.auth = new WebAwesomeAuthAdapter();
84
139
  }
85
140
  async init(shellUrl) {
86
141
  try {
package/dist/shell.css CHANGED
@@ -285,3 +285,32 @@ body {
285
285
  .shell-btn-default:hover {
286
286
  background-color: #e5e7eb;
287
287
  }
288
+
289
+ /* Re-authentication prompt */
290
+ .shell-dialog-error {
291
+ color: #dc2626;
292
+ background-color: #fef2f2;
293
+ border-radius: 6px;
294
+ padding: 0.5rem 0.75rem;
295
+ margin-bottom: 1rem;
296
+ font-size: 0.875rem;
297
+ }
298
+
299
+ .shell-auth-form {
300
+ display: flex;
301
+ flex-direction: column;
302
+ gap: 0.75rem;
303
+ }
304
+
305
+ .shell-auth-form input {
306
+ padding: 0.5rem 0.75rem;
307
+ border: 1px solid #d1d5db;
308
+ border-radius: 6px;
309
+ font-size: 0.875rem;
310
+ }
311
+
312
+ .shell-auth-form input:focus {
313
+ outline: none;
314
+ border-color: #3b82f6;
315
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
316
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herdingbits/trailhead-webawesome",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Web Awesome web components adapter for Trailhead. Vanilla TypeScript, no React required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,12 +21,12 @@
21
21
  "build": "npm run clean && tsc && cp src/shell.css dist/"
22
22
  },
23
23
  "peerDependencies": {
24
- "@herdingbits/trailhead-core": "^0.1.0",
25
- "@awesome.me/webawesome": "^3.6.0"
24
+ "@awesome.me/webawesome": "^3.6.0",
25
+ "@herdingbits/trailhead-core": "^0.2.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@herdingbits/trailhead-types": "^0.1.0",
29
28
  "@awesome.me/webawesome": "^3.10.0",
29
+ "@herdingbits/trailhead-types": "^0.2.0",
30
30
  "typescript": "^6.0.3"
31
31
  },
32
32
  "keywords": [