@the-portland-company/shell 0.3.4 → 0.3.5
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/CHANGELOG.md +7 -0
- package/dist/index.cjs +18 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -154,8 +154,15 @@ interface ShellModeValue {
|
|
|
154
154
|
modes: ShellModeConfig[];
|
|
155
155
|
/** Switch to a different mode. App owns side effects. */
|
|
156
156
|
switchMode: (modeId: string) => void;
|
|
157
|
-
/**
|
|
158
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Optional convenience accessor for the current mode's config. If
|
|
159
|
+
* omitted, shell auto-derives it via `modes.find(m => m.id === currentMode)`.
|
|
160
|
+
* Avoid object-method syntax (`getModeConfig() { return this.modes[0] }`) —
|
|
161
|
+
* the function is destructured by shell internals and `this` will not be
|
|
162
|
+
* bound. Use a closure (`getModeConfig: () => modes[0]`) or just leave it
|
|
163
|
+
* unset and let shell resolve.
|
|
164
|
+
*/
|
|
165
|
+
getModeConfig?: () => ShellModeConfig;
|
|
159
166
|
}
|
|
160
167
|
/** ---------------- Nav items ---------------- */
|
|
161
168
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -154,8 +154,15 @@ interface ShellModeValue {
|
|
|
154
154
|
modes: ShellModeConfig[];
|
|
155
155
|
/** Switch to a different mode. App owns side effects. */
|
|
156
156
|
switchMode: (modeId: string) => void;
|
|
157
|
-
/**
|
|
158
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Optional convenience accessor for the current mode's config. If
|
|
159
|
+
* omitted, shell auto-derives it via `modes.find(m => m.id === currentMode)`.
|
|
160
|
+
* Avoid object-method syntax (`getModeConfig() { return this.modes[0] }`) —
|
|
161
|
+
* the function is destructured by shell internals and `this` will not be
|
|
162
|
+
* bound. Use a closure (`getModeConfig: () => modes[0]`) or just leave it
|
|
163
|
+
* unset and let shell resolve.
|
|
164
|
+
*/
|
|
165
|
+
getModeConfig?: () => ShellModeConfig;
|
|
159
166
|
}
|
|
160
167
|
/** ---------------- Nav items ---------------- */
|
|
161
168
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1269,6 +1269,20 @@ function getUserDisplayName(user) {
|
|
|
1269
1269
|
if (!user) return "User";
|
|
1270
1270
|
return user.profile?.full_name || user.profile?.name || user.user_metadata?.full_name || user.user_metadata?.name || (typeof user.email === "string" ? user.email.split("@")[0] : "") || user.email || "User";
|
|
1271
1271
|
}
|
|
1272
|
+
|
|
1273
|
+
// src/lib/resolveModeConfig.ts
|
|
1274
|
+
function resolveModeConfig(mode) {
|
|
1275
|
+
if (!mode) return null;
|
|
1276
|
+
const modes = mode.modes ?? [];
|
|
1277
|
+
if (typeof mode.getModeConfig === "function") {
|
|
1278
|
+
try {
|
|
1279
|
+
const result = mode.getModeConfig();
|
|
1280
|
+
if (result) return result;
|
|
1281
|
+
} catch {
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return modes.find((m) => m.id === mode.currentMode) ?? modes[0] ?? null;
|
|
1285
|
+
}
|
|
1272
1286
|
function avatarUrlFromUser(user) {
|
|
1273
1287
|
if (!user) return void 0;
|
|
1274
1288
|
const meta = user.raw.user_metadata;
|
|
@@ -1293,7 +1307,7 @@ function UserMenu() {
|
|
|
1293
1307
|
if (status !== "authenticated" || !user) return null;
|
|
1294
1308
|
const displayName = getUserDisplayName(user.raw);
|
|
1295
1309
|
const avatarUrl = userAvatarUrl ?? avatarUrlFromUser(user);
|
|
1296
|
-
const modeConfig = mode
|
|
1310
|
+
const modeConfig = resolveModeConfig(mode);
|
|
1297
1311
|
const currentOrg = org?.currentOrg ?? null;
|
|
1298
1312
|
const linkedAccounts = linked?.linkedAccounts ?? [];
|
|
1299
1313
|
const activeRoleConfig = role?.activeRoleConfig ?? null;
|
|
@@ -1581,7 +1595,7 @@ function NavItem({
|
|
|
1581
1595
|
const navigate = useNavigate();
|
|
1582
1596
|
const mode = useShellMode();
|
|
1583
1597
|
const currentMode = mode?.currentMode ?? null;
|
|
1584
|
-
const modeConfig = mode
|
|
1598
|
+
const modeConfig = resolveModeConfig(mode);
|
|
1585
1599
|
const navPref = useShellNavigationPreference();
|
|
1586
1600
|
const showSubMenu = navPref?.showSubMenu ?? true;
|
|
1587
1601
|
const navHoverGradient = currentMode === MODE_CAMPAIGN ? "linear-gradient(90deg, #F2C94C 0%, #E63946 100%)" : currentMode === MODE_PETITION ? "linear-gradient(90deg, #F2C94C 0%, #007BFF 100%)" : "linear-gradient(90deg, #007BFF 0%, #E63946 100%)";
|
|
@@ -2128,8 +2142,8 @@ var OrgPill_default = OrgPill;
|
|
|
2128
2142
|
function ModePill() {
|
|
2129
2143
|
const mode = useShellMode();
|
|
2130
2144
|
if (!mode) return null;
|
|
2131
|
-
const { currentMode, modes, switchMode
|
|
2132
|
-
const modeConfig =
|
|
2145
|
+
const { currentMode, modes, switchMode } = mode;
|
|
2146
|
+
const modeConfig = resolveModeConfig(mode);
|
|
2133
2147
|
if (!modeConfig) return null;
|
|
2134
2148
|
const hasMultipleModes = modes.length > 1;
|
|
2135
2149
|
const isDisabled = !hasMultipleModes;
|