@eintrek/erp-shell 0.1.66 → 0.1.68
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 +28 -2
- package/dist/chunks/guide-runtime-B2RjoQeb.cjs +3874 -0
- package/dist/chunks/guide-runtime-B2RjoQeb.cjs.map +1 -0
- package/dist/chunks/guide-runtime-BT7rN-5p.esm.js +3837 -0
- package/dist/chunks/guide-runtime-BT7rN-5p.esm.js.map +1 -0
- package/dist/guide/core.d.ts +19 -0
- package/dist/guide/dom.d.ts +2 -0
- package/dist/guide/events.d.ts +25 -0
- package/dist/guide/guide-runtime.d.ts +83 -0
- package/dist/guide/guide-styles.d.ts +7 -1
- package/dist/guide/machine.d.ts +68 -2
- package/dist/guide/patterns.d.ts +6 -2
- package/dist/guide/progress-client.d.ts +6 -5
- package/dist/guide/progress-sync.d.ts +68 -0
- package/dist/guide/types.d.ts +48 -3
- package/dist/guide-core.cjs +29 -0
- package/dist/guide-core.cjs.map +1 -0
- package/dist/guide-core.esm.js +7 -0
- package/dist/guide-core.esm.js.map +1 -0
- package/dist/{index.js → index.cjs} +129 -3431
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +110 -3414
- package/dist/index.esm.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +46 -2
- package/dist/index.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { useRef, useEffect, useMemo, useState, useCallback, createContext, useContext, Fragment, useSyncExternalStore, useTransition,
|
|
3
|
+
import React__default, { useRef, useEffect, useMemo, useState, useCallback, createContext, useContext, Fragment, useSyncExternalStore, useTransition, Suspense } from 'react';
|
|
4
4
|
import { useSession, signOut } from 'next-auth/react';
|
|
5
|
-
import { useQueryClient, useQuery, QueryClientContext, QueryClient,
|
|
5
|
+
import { useQueryClient, useQuery, QueryClientContext, QueryClient, hashKey, MutationCache, QueryCache, QueryClientProvider } from '@tanstack/react-query';
|
|
6
6
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
7
7
|
import { cn, Button, Tooltip, TooltipTrigger, TooltipContent, Breadcrumb, BreadcrumbList, BreadcrumbItem, BreadcrumbLink, BreadcrumbSeparator, BreadcrumbPage, Avatar, AvatarImage, AvatarFallback, Collapsible, CollapsibleTrigger, CollapsibleContent, Badge, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuItem, DropdownMenuSeparator, Skeleton, Dialog, DialogContent, DialogHeader, DialogTitle, Label, Textarea, DialogFooter, Card, CardHeader, CardContent } from '@eintrek/erp-theme';
|
|
8
8
|
import { PanelLeftClose, Menu, ChevronRight, Building2, Palette, ChevronUp, Sun, Moon, Monitor, Globe, UserCog, LayoutGrid, ExternalLink, CircleHelp, Loader2, LogOut, Calculator, Warehouse, FolderKanban, Users, Store, Headset, ChevronDown, Plus, ChevronsUpDown, Flag, MessageCircle, ImagePlus, X, CircleCheck, ArrowLeft, Ban, Home, ContactRound, UserPlus, ArrowRight, Compass, ArrowUpRight } from 'lucide-react';
|
|
@@ -14,8 +14,10 @@ import { createPortal } from 'react-dom';
|
|
|
14
14
|
import { useTheme, ThemeProvider as ThemeProvider$1 } from 'next-themes';
|
|
15
15
|
import axios, { isAxiosError, AxiosHeaders } from 'axios';
|
|
16
16
|
export { isAxiosError } from 'axios';
|
|
17
|
-
import {
|
|
17
|
+
import { j as reportApiEvent, h as guideAnchor, u as useGuideEntry, o as openGuidePanel, b as GuideErrorBoundary, d as GuideRuntime } from './chunks/guide-runtime-BT7rN-5p.esm.js';
|
|
18
|
+
export { A as GUIDE_API_EVENT, G as GUIDE_EVENT_PREFIX, a as GUIDE_LAYER_ATTRIBUTE, c as GuideProgressConflict, f as emitGuideEvent, r as reportApiCall } from './chunks/guide-runtime-BT7rN-5p.esm.js';
|
|
18
19
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
|
20
|
+
import '@floating-ui/dom';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Interval (ms) between session updates to trigger JWT callback and refresh
|
|
@@ -1259,35 +1261,35 @@ let declaredApp = null;
|
|
|
1259
1261
|
// The message the dialog should open on (the ตอบกลับ link's ?help=H1004),
|
|
1260
1262
|
// until it is closed or left.
|
|
1261
1263
|
let pendingRef = null;
|
|
1262
|
-
const listeners
|
|
1263
|
-
function emit
|
|
1264
|
-
listeners
|
|
1264
|
+
const listeners = new Set();
|
|
1265
|
+
function emit() {
|
|
1266
|
+
listeners.forEach(l => l());
|
|
1265
1267
|
}
|
|
1266
|
-
function subscribe
|
|
1267
|
-
listeners
|
|
1268
|
+
function subscribe(l) {
|
|
1269
|
+
listeners.add(l);
|
|
1268
1270
|
return () => {
|
|
1269
|
-
listeners
|
|
1271
|
+
listeners.delete(l);
|
|
1270
1272
|
};
|
|
1271
1273
|
}
|
|
1272
1274
|
/** Opens the dialog — a no-op when no layout has mounted one. */
|
|
1273
1275
|
function openHelp() {
|
|
1274
1276
|
if (!open) {
|
|
1275
1277
|
open = true;
|
|
1276
|
-
emit
|
|
1278
|
+
emit();
|
|
1277
1279
|
}
|
|
1278
1280
|
}
|
|
1279
1281
|
function closeHelp() {
|
|
1280
1282
|
pendingRef = null;
|
|
1281
1283
|
if (open) {
|
|
1282
1284
|
open = false;
|
|
1283
|
-
emit
|
|
1285
|
+
emit();
|
|
1284
1286
|
}
|
|
1285
1287
|
}
|
|
1286
1288
|
/** Opens the dialog on one of the person's messages, by id or "H1004". */
|
|
1287
1289
|
function openHelpOn(ref) {
|
|
1288
1290
|
pendingRef = ref;
|
|
1289
1291
|
open = true;
|
|
1290
|
-
emit
|
|
1292
|
+
emit();
|
|
1291
1293
|
}
|
|
1292
1294
|
/** The message the dialog was asked to open on, if it has not been left. */
|
|
1293
1295
|
function pendingHelpRef() {
|
|
@@ -1306,22 +1308,22 @@ function registerHelpHost() {
|
|
|
1306
1308
|
hosts += 1;
|
|
1307
1309
|
if (pendingRef)
|
|
1308
1310
|
open = true;
|
|
1309
|
-
emit
|
|
1311
|
+
emit();
|
|
1310
1312
|
return () => {
|
|
1311
1313
|
hosts -= 1;
|
|
1312
1314
|
if (hosts <= 0) {
|
|
1313
1315
|
hosts = 0;
|
|
1314
1316
|
open = false;
|
|
1315
1317
|
}
|
|
1316
|
-
emit
|
|
1318
|
+
emit();
|
|
1317
1319
|
};
|
|
1318
1320
|
}
|
|
1319
1321
|
function useHelpOpen() {
|
|
1320
|
-
return useSyncExternalStore(subscribe
|
|
1322
|
+
return useSyncExternalStore(subscribe, () => open, () => false);
|
|
1321
1323
|
}
|
|
1322
1324
|
/** True while a dialog host is mounted, i.e. the ช่วยเหลือ entry works. */
|
|
1323
1325
|
function useHelpAvailable() {
|
|
1324
|
-
return useSyncExternalStore(subscribe
|
|
1326
|
+
return useSyncExternalStore(subscribe, () => hosts > 0, () => false);
|
|
1325
1327
|
}
|
|
1326
1328
|
/**
|
|
1327
1329
|
* Every app names itself when it builds its app-switcher links
|
|
@@ -1345,17 +1347,17 @@ function declaredHelpApp() {
|
|
|
1345
1347
|
const OWNER_CHIP = "เจ้าของ";
|
|
1346
1348
|
/** How many role names the card spells out before counting the rest. */
|
|
1347
1349
|
const CARD_ROLE_LIMIT = 2;
|
|
1348
|
-
const isRecord
|
|
1350
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1349
1351
|
/**
|
|
1350
1352
|
* The answer, checked. Anything that is not the shape the card needs — an
|
|
1351
1353
|
* older API, a proxy's error page, another organisation's answer — is null,
|
|
1352
1354
|
* and the card shows no role line.
|
|
1353
1355
|
*/
|
|
1354
1356
|
function parseMyRoles(payload, organizationId) {
|
|
1355
|
-
if (!isRecord
|
|
1357
|
+
if (!isRecord(payload))
|
|
1356
1358
|
return null;
|
|
1357
1359
|
// Envelope { success, data } or the bare data.
|
|
1358
|
-
const data = isRecord
|
|
1360
|
+
const data = isRecord(payload.data) ? payload.data : payload;
|
|
1359
1361
|
if (!Array.isArray(data.roles))
|
|
1360
1362
|
return null;
|
|
1361
1363
|
if (typeof data.organization_id === "string" && data.organization_id !== organizationId) {
|
|
@@ -1364,7 +1366,7 @@ function parseMyRoles(payload, organizationId) {
|
|
|
1364
1366
|
const roles = [];
|
|
1365
1367
|
const seen = new Set();
|
|
1366
1368
|
for (const r of data.roles) {
|
|
1367
|
-
if (!isRecord
|
|
1369
|
+
if (!isRecord(r))
|
|
1368
1370
|
continue;
|
|
1369
1371
|
const name = typeof r.name_th === "string" ? r.name_th.trim() : "";
|
|
1370
1372
|
const key = typeof r.key === "string" ? r.key : "";
|
|
@@ -1585,242 +1587,6 @@ async function retryWithStoredOrganizations(config, status, send) {
|
|
|
1585
1587
|
return undefined;
|
|
1586
1588
|
}
|
|
1587
1589
|
|
|
1588
|
-
/**
|
|
1589
|
-
* Route and API-path patterns for tour steps.
|
|
1590
|
-
*
|
|
1591
|
-
* No runtime imports: the tests run this file in Node as it is.
|
|
1592
|
-
*/
|
|
1593
|
-
const trimSlash = (p) => (p.length > 1 ? p.replace(/\/+$/, "") : p);
|
|
1594
|
-
function splitPattern(pattern) {
|
|
1595
|
-
const q = pattern.indexOf("?");
|
|
1596
|
-
if (q < 0)
|
|
1597
|
-
return { path: pattern, query: new URLSearchParams() };
|
|
1598
|
-
return { path: pattern.slice(0, q), query: new URLSearchParams(pattern.slice(q + 1)) };
|
|
1599
|
-
}
|
|
1600
|
-
function paramName(segment) {
|
|
1601
|
-
const bracket = /^\[([A-Za-z0-9_]+)\]$/.exec(segment);
|
|
1602
|
-
if (bracket)
|
|
1603
|
-
return bracket[1];
|
|
1604
|
-
const colon = /^:([A-Za-z0-9_]+)$/.exec(segment);
|
|
1605
|
-
return colon ? colon[1] : null;
|
|
1606
|
-
}
|
|
1607
|
-
function safeDecode(s) {
|
|
1608
|
-
try {
|
|
1609
|
-
return decodeURIComponent(s);
|
|
1610
|
-
}
|
|
1611
|
-
catch {
|
|
1612
|
-
return s;
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Matches a Next-style page pattern ("/[code]/employee/[id]", optionally
|
|
1617
|
-
* "?tab=job") against a path and query. `[code]`, when given, must be the
|
|
1618
|
-
* organisation code. Returns the params, or null.
|
|
1619
|
-
*/
|
|
1620
|
-
function matchRoute(pattern, pathname, search, code) {
|
|
1621
|
-
const { path, query } = splitPattern(pattern);
|
|
1622
|
-
const want = trimSlash(path).split("/");
|
|
1623
|
-
const have = trimSlash(pathname || "/").split("/");
|
|
1624
|
-
if (want.length !== have.length)
|
|
1625
|
-
return null;
|
|
1626
|
-
const params = {};
|
|
1627
|
-
for (let i = 0; i < want.length; i++) {
|
|
1628
|
-
const name = paramName(want[i]);
|
|
1629
|
-
if (name) {
|
|
1630
|
-
if (!have[i])
|
|
1631
|
-
return null;
|
|
1632
|
-
params[name] = safeDecode(have[i]);
|
|
1633
|
-
continue;
|
|
1634
|
-
}
|
|
1635
|
-
if (want[i] !== have[i])
|
|
1636
|
-
return null;
|
|
1637
|
-
}
|
|
1638
|
-
if (code !== undefined && params.code !== undefined && params.code !== code) {
|
|
1639
|
-
return null;
|
|
1640
|
-
}
|
|
1641
|
-
if ([...query.keys()].length > 0) {
|
|
1642
|
-
const s = search instanceof URLSearchParams ? search : new URLSearchParams(search ?? "");
|
|
1643
|
-
for (const [k, v] of query.entries()) {
|
|
1644
|
-
if (s.get(k) !== v)
|
|
1645
|
-
return null;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
return params;
|
|
1649
|
-
}
|
|
1650
|
-
/** Fills a page pattern's params ("/[code]/x/[id]" → "/O1/x/42"); null if one is missing. */
|
|
1651
|
-
function fillRoute(pattern, params) {
|
|
1652
|
-
const { path, query } = splitPattern(pattern);
|
|
1653
|
-
const out = [];
|
|
1654
|
-
for (const seg of path.split("/")) {
|
|
1655
|
-
const name = paramName(seg);
|
|
1656
|
-
if (!name) {
|
|
1657
|
-
out.push(seg);
|
|
1658
|
-
continue;
|
|
1659
|
-
}
|
|
1660
|
-
const v = params[name];
|
|
1661
|
-
if (!v)
|
|
1662
|
-
return null;
|
|
1663
|
-
out.push(encodeURIComponent(v));
|
|
1664
|
-
}
|
|
1665
|
-
const qs = query.toString();
|
|
1666
|
-
return out.join("/") + (qs ? `?${qs}` : "");
|
|
1667
|
-
}
|
|
1668
|
-
/**
|
|
1669
|
-
* The path of a request, without origin, base URL query or hash:
|
|
1670
|
-
* ("/shifts/4", "https://hr-api/api/v1") → "/api/v1/shifts/4".
|
|
1671
|
-
*/
|
|
1672
|
-
function requestPath(url, baseURL) {
|
|
1673
|
-
const raw = url ?? "";
|
|
1674
|
-
let full = raw;
|
|
1675
|
-
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(raw) && baseURL) {
|
|
1676
|
-
full = baseURL.replace(/\/+$/, "") + "/" + raw.replace(/^\/+/, "");
|
|
1677
|
-
}
|
|
1678
|
-
try {
|
|
1679
|
-
return trimSlash(new URL(full, "http://local.invalid").pathname);
|
|
1680
|
-
}
|
|
1681
|
-
catch {
|
|
1682
|
-
return trimSlash(full.split(/[?#]/)[0] || "/");
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* Whether a request path matches a step's API path: the pattern's segments
|
|
1687
|
-
* must be the END of the path ("/shifts/[id]" matches "/api/v1/shifts/42");
|
|
1688
|
-
* `[x]`/`:x` is one segment, `*` any number (including none). A RegExp is
|
|
1689
|
-
* tested against the whole path.
|
|
1690
|
-
*/
|
|
1691
|
-
function matchApiPath(pattern, path) {
|
|
1692
|
-
if (pattern instanceof RegExp)
|
|
1693
|
-
return pattern.test(path);
|
|
1694
|
-
const want = trimSlash(pattern).split("/").filter(Boolean);
|
|
1695
|
-
const have = trimSlash(path).split("/").filter(Boolean);
|
|
1696
|
-
// Try every suffix of the path as the place the pattern starts.
|
|
1697
|
-
for (let start = 0; start <= have.length; start++) {
|
|
1698
|
-
if (matchSegments(want, 0, have, start))
|
|
1699
|
-
return true;
|
|
1700
|
-
}
|
|
1701
|
-
return false;
|
|
1702
|
-
}
|
|
1703
|
-
function matchSegments(want, wi, have, hi) {
|
|
1704
|
-
if (wi === want.length)
|
|
1705
|
-
return hi === have.length;
|
|
1706
|
-
const seg = want[wi];
|
|
1707
|
-
if (seg === "*") {
|
|
1708
|
-
for (let k = hi; k <= have.length; k++) {
|
|
1709
|
-
if (matchSegments(want, wi + 1, have, k))
|
|
1710
|
-
return true;
|
|
1711
|
-
}
|
|
1712
|
-
return false;
|
|
1713
|
-
}
|
|
1714
|
-
if (hi >= have.length)
|
|
1715
|
-
return false;
|
|
1716
|
-
if (paramName(seg) || seg === have[hi])
|
|
1717
|
-
return matchSegments(want, wi + 1, have, hi + 1);
|
|
1718
|
-
return false;
|
|
1719
|
-
}
|
|
1720
|
-
/** "2xx" or an exact status. */
|
|
1721
|
-
function matchStatus(want, status) {
|
|
1722
|
-
if (want === undefined || want === "2xx")
|
|
1723
|
-
return status >= 200 && status < 300;
|
|
1724
|
-
return status === want;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* The tour's event bus and anchor helper — the parts an app calls.
|
|
1729
|
-
*
|
|
1730
|
-
* - `guideAnchor(key, id?)` → `{ "data-guide": key, "data-guide-id"?: id }`
|
|
1731
|
-
* - `emitGuideEvent(name, detail?)` → window CustomEvent `erp:guide:<name>`
|
|
1732
|
-
* - `reportApiEvent(responseOrError)` → window CustomEvent `erp:api`, which
|
|
1733
|
-
* the shell's own axios instance already sends for every answer. An app
|
|
1734
|
-
* with a second axios instance calls it from that instance's interceptor.
|
|
1735
|
-
*
|
|
1736
|
-
* Only method, path, status, the saved record's id and (on a refusal) the
|
|
1737
|
-
* server's message go on the bus — never a request or response body.
|
|
1738
|
-
*
|
|
1739
|
-
* No runtime imports beyond sibling pure modules.
|
|
1740
|
-
*/
|
|
1741
|
-
const GUIDE_ATTRIBUTE = "data-guide";
|
|
1742
|
-
const GUIDE_ID_ATTRIBUTE = "data-guide-id";
|
|
1743
|
-
const GUIDE_LAYER_ATTRIBUTE = "data-erp-guide-layer";
|
|
1744
|
-
const API_EVENT = "erp:api";
|
|
1745
|
-
const GUIDE_EVENT_PREFIX = "erp:guide:";
|
|
1746
|
-
/** Spread onto the element a tour step points at. */
|
|
1747
|
-
function guideAnchor(key, id) {
|
|
1748
|
-
return id === undefined || id === null || id === ""
|
|
1749
|
-
? { [GUIDE_ATTRIBUTE]: key }
|
|
1750
|
-
: { [GUIDE_ATTRIBUTE]: key, [GUIDE_ID_ATTRIBUTE]: String(id) };
|
|
1751
|
-
}
|
|
1752
|
-
/** Announces an app event a step can wait for (`advanceOn: { event: name }`). */
|
|
1753
|
-
function emitGuideEvent(name, detail) {
|
|
1754
|
-
if (typeof window === "undefined" || !name)
|
|
1755
|
-
return;
|
|
1756
|
-
const clean = {};
|
|
1757
|
-
for (const [k, v] of Object.entries(detail ?? {})) {
|
|
1758
|
-
if (typeof v === "string" || typeof v === "number")
|
|
1759
|
-
clean[k] = String(v);
|
|
1760
|
-
}
|
|
1761
|
-
try {
|
|
1762
|
-
window.dispatchEvent(new CustomEvent(GUIDE_EVENT_PREFIX + name, { detail: clean }));
|
|
1763
|
-
}
|
|
1764
|
-
catch {
|
|
1765
|
-
/* never let the tour break the app */
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
const isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1769
|
-
function idOf(data) {
|
|
1770
|
-
const pick = (v) => typeof v === "string" && v ? v : typeof v === "number" ? String(v) : undefined;
|
|
1771
|
-
if (!isRecord$1(data))
|
|
1772
|
-
return undefined;
|
|
1773
|
-
return pick(data.id) ?? (isRecord$1(data.data) ? pick(data.data.id) : undefined);
|
|
1774
|
-
}
|
|
1775
|
-
function messageOf(data) {
|
|
1776
|
-
if (!isRecord$1(data))
|
|
1777
|
-
return undefined;
|
|
1778
|
-
const m = data.message ?? (isRecord$1(data.error) ? data.error.message : data.error);
|
|
1779
|
-
return typeof m === "string" && m.trim() ? m.trim().slice(0, 200) : undefined;
|
|
1780
|
-
}
|
|
1781
|
-
/** The bus detail for an axios answer or error; null when it is neither. */
|
|
1782
|
-
function apiEventDetail(responseOrError) {
|
|
1783
|
-
if (!isRecord$1(responseOrError))
|
|
1784
|
-
return null;
|
|
1785
|
-
const err = responseOrError;
|
|
1786
|
-
// An AxiosError has .response (or none: network failure) and .config.
|
|
1787
|
-
const isError = "isAxiosError" in responseOrError || ("response" in responseOrError && !("data" in responseOrError));
|
|
1788
|
-
const res = isError ? err.response : responseOrError;
|
|
1789
|
-
const config = (res?.config ?? err.config);
|
|
1790
|
-
if (!config)
|
|
1791
|
-
return null;
|
|
1792
|
-
const status = typeof res?.status === "number" ? res.status : 0;
|
|
1793
|
-
const detail = {
|
|
1794
|
-
method: (config.method ?? "get").toUpperCase(),
|
|
1795
|
-
path: requestPath(config.url, config.baseURL),
|
|
1796
|
-
status,
|
|
1797
|
-
};
|
|
1798
|
-
if (status >= 200 && status < 300) {
|
|
1799
|
-
const id = idOf(res?.data);
|
|
1800
|
-
if (id)
|
|
1801
|
-
detail.id = id;
|
|
1802
|
-
}
|
|
1803
|
-
else {
|
|
1804
|
-
const msg = messageOf(res?.data);
|
|
1805
|
-
if (msg)
|
|
1806
|
-
detail.message = msg;
|
|
1807
|
-
}
|
|
1808
|
-
return detail;
|
|
1809
|
-
}
|
|
1810
|
-
/** Puts an axios answer (or error) on the bus. Safe to call with anything. */
|
|
1811
|
-
function reportApiEvent(responseOrError) {
|
|
1812
|
-
if (typeof window === "undefined")
|
|
1813
|
-
return;
|
|
1814
|
-
try {
|
|
1815
|
-
const detail = apiEventDetail(responseOrError);
|
|
1816
|
-
if (detail)
|
|
1817
|
-
window.dispatchEvent(new CustomEvent(API_EVENT, { detail }));
|
|
1818
|
-
}
|
|
1819
|
-
catch {
|
|
1820
|
-
/* never let the tour break the app */
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
1590
|
const isBrowser = () => typeof window !== "undefined";
|
|
1825
1591
|
const isAuthEndpoint = (url) => !!url && url.includes("/api/auth/");
|
|
1826
1592
|
const isAuthPage = () => isBrowser() && window.location.pathname.startsWith("/auth/");
|
|
@@ -1956,7 +1722,7 @@ function platformApiBase(app) {
|
|
|
1956
1722
|
* This package's version, attached to help messages so the back office can
|
|
1957
1723
|
* tell which shell a report came from. Keep in step with package.json.
|
|
1958
1724
|
*/
|
|
1959
|
-
const SHELL_VERSION = "0.1.
|
|
1725
|
+
const SHELL_VERSION = "0.1.68";
|
|
1960
1726
|
|
|
1961
1727
|
const HELP_APP_LABEL = {
|
|
1962
1728
|
platform: "แพลตฟอร์ม",
|
|
@@ -2783,37 +2549,6 @@ const WORKSPACE_LIGHT_HEADER_VARS = {
|
|
|
2783
2549
|
"--header-title-py": "0px",
|
|
2784
2550
|
};
|
|
2785
2551
|
|
|
2786
|
-
let entry = null;
|
|
2787
|
-
let openPanelImpl = null;
|
|
2788
|
-
const listeners = new Set();
|
|
2789
|
-
function emit() {
|
|
2790
|
-
listeners.forEach(l => l());
|
|
2791
|
-
}
|
|
2792
|
-
function subscribe(l) {
|
|
2793
|
-
listeners.add(l);
|
|
2794
|
-
return () => {
|
|
2795
|
-
listeners.delete(l);
|
|
2796
|
-
};
|
|
2797
|
-
}
|
|
2798
|
-
/** Called by the host: the entry to show (null: none), and how to open the panel. */
|
|
2799
|
-
function publishGuideEntry(next, openPanel) {
|
|
2800
|
-
const same = (next === null && entry === null) ||
|
|
2801
|
-
(next !== null && entry !== null && next.done === entry.done && next.total === entry.total);
|
|
2802
|
-
openPanelImpl = openPanel;
|
|
2803
|
-
if (!same) {
|
|
2804
|
-
entry = next;
|
|
2805
|
-
emit();
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
/** Opens the tour's quest panel, when this user has a tour here. */
|
|
2809
|
-
function openGuidePanel() {
|
|
2810
|
-
openPanelImpl?.();
|
|
2811
|
-
}
|
|
2812
|
-
/** The "?" menu's entry, or null when there is no tour for this user. */
|
|
2813
|
-
function useGuideEntry() {
|
|
2814
|
-
return useSyncExternalStore(subscribe, () => entry, () => null);
|
|
2815
|
-
}
|
|
2816
|
-
|
|
2817
2552
|
const BUTTON_CLASS = "grid size-[34px] shrink-0 place-items-center rounded-lg text-[var(--header-fg-muted,#ffffffc7)] transition-colors hover:bg-[var(--header-hover,#ffffff1f)] hover:text-[var(--header-fg,#ffffff)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--header-fg-muted,#ffffffc7)]";
|
|
2818
2553
|
/**
|
|
2819
2554
|
* The ช่วยเหลือ button in the top bar. Drawn in the header's ink (the
|
|
@@ -3784,2339 +3519,84 @@ function resolveStaleOrganization({ code, organizations, organizationsStatus, or
|
|
|
3784
3519
|
return { action: "forget" };
|
|
3785
3520
|
}
|
|
3786
3521
|
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
const COPY = {
|
|
3791
|
-
fieldFix: "แก้ในช่องที่ไฮไลต์ แล้วกด ถัดไป",
|
|
3792
|
-
saveFailed: "บันทึกไม่สำเร็จ",
|
|
3793
|
-
blank: "ยังไม่ได้พิมพ์",
|
|
3794
|
-
exitToast: "ออกจากไกด์แล้ว",
|
|
3795
|
-
replayDone: "ทบทวนภารกิจเสร็จแล้ว",
|
|
3796
|
-
replayEnded: "จบการทบทวนแล้ว",
|
|
3797
|
-
hiddenToast: "ซ่อนแล้ว",
|
|
3798
|
-
aborted: "ไกด์ไปต่อไม่ได้ ลองอีกครั้งภายหลัง",
|
|
3799
|
-
bridgeTitle: "กดปุ่มเมนู",
|
|
3800
|
-
bridgeWhy: (app) => `เมนูทั้งหมดของ ${app} อยู่ในนี้`,
|
|
3801
|
-
};
|
|
3802
|
-
/* ------------------------------------------------------------------ */
|
|
3803
|
-
/* Helpers */
|
|
3804
|
-
/* ------------------------------------------------------------------ */
|
|
3805
|
-
const BRIDGE_TARGET = "shell.menu-toggle";
|
|
3806
|
-
function initialGuideState(audience, progress) {
|
|
3807
|
-
return {
|
|
3808
|
-
audience,
|
|
3809
|
-
progress,
|
|
3810
|
-
screen: { name: "idle" },
|
|
3811
|
-
panelOpen: false,
|
|
3812
|
-
justDone: null,
|
|
3813
|
-
chipPulse: 0,
|
|
3814
|
-
nudge: 0,
|
|
3815
|
-
gateDismissed: false,
|
|
3816
|
-
};
|
|
3817
|
-
}
|
|
3818
|
-
function findMission(suite, key) {
|
|
3819
|
-
return key ? suite.missions.find(m => m.key === key) : undefined;
|
|
3820
|
-
}
|
|
3821
|
-
function guideContext(env, data, params = {}) {
|
|
3822
|
-
return {
|
|
3823
|
-
code: env.code,
|
|
3824
|
-
pathname: env.pathname,
|
|
3825
|
-
search: env.search,
|
|
3826
|
-
params: { code: env.code, ...params },
|
|
3827
|
-
data,
|
|
3828
|
-
facts: env.facts,
|
|
3829
|
-
can: env.can,
|
|
3830
|
-
visible: (anchor) => env.isVisible(anchor),
|
|
3831
|
-
};
|
|
3832
|
-
}
|
|
3833
|
-
function resolveText(t, ctx) {
|
|
3834
|
-
if (t === undefined)
|
|
3835
|
-
return "";
|
|
3836
|
-
try {
|
|
3837
|
-
return typeof t === "function" ? t(ctx) : t;
|
|
3838
|
-
}
|
|
3839
|
-
catch {
|
|
3840
|
-
return "";
|
|
3841
|
-
}
|
|
3842
|
-
}
|
|
3843
|
-
/** Runs an app predicate; a throw counts as `fallback`. */
|
|
3844
|
-
function safe(fn, fallback) {
|
|
3845
|
-
try {
|
|
3846
|
-
return fn();
|
|
3847
|
-
}
|
|
3848
|
-
catch {
|
|
3849
|
-
return fallback;
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
function triggersOf(step) {
|
|
3853
|
-
if (!step.advanceOn)
|
|
3854
|
-
return [];
|
|
3855
|
-
return Array.isArray(step.advanceOn) ? step.advanceOn : [step.advanceOn];
|
|
3856
|
-
}
|
|
3857
|
-
function stepKind(step) {
|
|
3858
|
-
return step.kind ?? "click";
|
|
3859
|
-
}
|
|
3860
|
-
/** The last checkpoint at or before `index` (a mission's first step always is one). */
|
|
3861
|
-
function checkpointAtOrBefore(steps, index) {
|
|
3862
|
-
for (let i = Math.min(index, steps.length - 1); i > 0; i--) {
|
|
3863
|
-
if (steps[i].checkpoint)
|
|
3864
|
-
return i;
|
|
3865
|
-
}
|
|
3866
|
-
return 0;
|
|
3867
|
-
}
|
|
3868
|
-
function targetIdOf(step, ctx) {
|
|
3869
|
-
if (typeof step.targetId === "function")
|
|
3870
|
-
return safe(() => step.targetId(ctx), undefined);
|
|
3871
|
-
return step.targetId;
|
|
3872
|
-
}
|
|
3873
|
-
/** Whether the step's target (or the bridge's) is on screen. */
|
|
3874
|
-
function stepTargetVisible(step, env, ctx, bridge) {
|
|
3875
|
-
if (bridge)
|
|
3876
|
-
return env.isVisible(BRIDGE_TARGET);
|
|
3877
|
-
if (!step.target)
|
|
3878
|
-
return true;
|
|
3879
|
-
return env.isVisible(step.target, targetIdOf(step, ctx));
|
|
3880
|
-
}
|
|
3881
|
-
/** The anchor the spotlight is on for the current step. */
|
|
3882
|
-
function spotlightTarget(step, ctx, bridge) {
|
|
3883
|
-
if (bridge)
|
|
3884
|
-
return { anchor: BRIDGE_TARGET };
|
|
3885
|
-
if (!step.target)
|
|
3886
|
-
return null;
|
|
3887
|
-
return { anchor: step.target, id: targetIdOf(step, ctx) };
|
|
3888
|
-
}
|
|
3889
|
-
function needsBridge(step, env, ctx) {
|
|
3890
|
-
return (!!step.target &&
|
|
3891
|
-
step.target.startsWith("nav.") &&
|
|
3892
|
-
!env.sidebarOpen &&
|
|
3893
|
-
!env.isVisible(step.target, targetIdOf(step, ctx)));
|
|
3894
|
-
}
|
|
3895
|
-
/**
|
|
3896
|
-
* The page a step happens on: its own `route`, or else where the steps before
|
|
3897
|
-
* it left the user (an earlier step's route trigger or route). Undefined when
|
|
3898
|
-
* nothing says (a mission's first steps, which work from any page).
|
|
3899
|
-
*/
|
|
3900
|
-
function stepHomeRoute(steps, index) {
|
|
3901
|
-
for (let j = Math.min(index, steps.length - 1); j >= 0; j--) {
|
|
3902
|
-
const s = steps[j];
|
|
3903
|
-
if (j < index) {
|
|
3904
|
-
// What this earlier step moved the user to comes after where it happened.
|
|
3905
|
-
const t = triggersOf(s).find((x) => "route" in x);
|
|
3906
|
-
if (t)
|
|
3907
|
-
return t.route;
|
|
3908
|
-
}
|
|
3909
|
-
if (s.route)
|
|
3910
|
-
return s.route;
|
|
3911
|
-
}
|
|
3912
|
-
return undefined;
|
|
3913
|
-
}
|
|
3522
|
+
const EMPLOYEE_RECORD_REQUIRED = "EMPLOYEE_RECORD_REQUIRED";
|
|
3523
|
+
const EMPLOYEE_RECORD_REQUIRED_EVENT = "erp:employee-record-required";
|
|
3524
|
+
const EMPLOYEE_RECORD_OK_EVENT = "erp:employee-record-ok";
|
|
3914
3525
|
/**
|
|
3915
|
-
*
|
|
3916
|
-
*
|
|
3917
|
-
*
|
|
3526
|
+
* Shown when the API refuses every request because the signed-in account has
|
|
3527
|
+
* no employee record in this organisation.
|
|
3528
|
+
*
|
|
3529
|
+
* A gate rather than a banner. Leave, attendance, approvals and payslips all
|
|
3530
|
+
* identify a person by that record, so once the server started enforcing it
|
|
3531
|
+
* every call fails — and without something that says so, the app becomes a
|
|
3532
|
+
* screen of error toasts with no explanation and no way forward.
|
|
3918
3533
|
*/
|
|
3919
|
-
function
|
|
3920
|
-
const
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
if (own)
|
|
3935
|
-
return Array.isArray(own) ? own : [own];
|
|
3936
|
-
// Default: Escape to the dialog the tour opened; nothing on a stable page.
|
|
3937
|
-
if (!step || index === 0 || step.checkpoint)
|
|
3938
|
-
return [];
|
|
3939
|
-
return [{ escape: true }];
|
|
3940
|
-
}
|
|
3941
|
-
function routeParamsFor(step, env) {
|
|
3942
|
-
if (!step.route)
|
|
3943
|
-
return {};
|
|
3944
|
-
return matchRoute(step.route, env.pathname, env.search, env.code) ?? {};
|
|
3945
|
-
}
|
|
3946
|
-
/** A state trigger (route, visible) that holds now; the capture event for it. */
|
|
3947
|
-
function stateTriggerHolds(step, env) {
|
|
3948
|
-
for (const t of triggersOf(step)) {
|
|
3949
|
-
if ("route" in t) {
|
|
3950
|
-
const params = matchRoute(t.route, env.pathname, env.search, env.code);
|
|
3951
|
-
if (params)
|
|
3952
|
-
return { route: { pathname: env.pathname, params } };
|
|
3953
|
-
}
|
|
3954
|
-
else if ("visible" in t) {
|
|
3955
|
-
if (env.isVisible(t.visible))
|
|
3956
|
-
return {};
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
return null;
|
|
3960
|
-
}
|
|
3961
|
-
/** Any trigger that holds on a sync (route, visible, and — once armed — hidden). */
|
|
3962
|
-
function syncTriggerHolds(step, env, armed) {
|
|
3963
|
-
const held = stateTriggerHolds(step, env);
|
|
3964
|
-
if (held)
|
|
3965
|
-
return held;
|
|
3966
|
-
if (!armed)
|
|
3534
|
+
function EmployeeRequiredGate({ platformBaseUrl, }) {
|
|
3535
|
+
const [blocked, setBlocked] = useState(false);
|
|
3536
|
+
const params = useParams();
|
|
3537
|
+
const code = params?.code ?? "";
|
|
3538
|
+
useEffect(() => {
|
|
3539
|
+
const onBlocked = () => setBlocked(true);
|
|
3540
|
+
const onOk = () => setBlocked(false);
|
|
3541
|
+
window.addEventListener(EMPLOYEE_RECORD_REQUIRED_EVENT, onBlocked);
|
|
3542
|
+
window.addEventListener(EMPLOYEE_RECORD_OK_EVENT, onOk);
|
|
3543
|
+
return () => {
|
|
3544
|
+
window.removeEventListener(EMPLOYEE_RECORD_REQUIRED_EVENT, onBlocked);
|
|
3545
|
+
window.removeEventListener(EMPLOYEE_RECORD_OK_EVENT, onOk);
|
|
3546
|
+
};
|
|
3547
|
+
}, []);
|
|
3548
|
+
if (!blocked)
|
|
3967
3549
|
return null;
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
}
|
|
3972
|
-
return null;
|
|
3973
|
-
}
|
|
3974
|
-
/** Whether any of the step's `hidden` anchors is on screen now. */
|
|
3975
|
-
function hiddenAnchorShown(step, env) {
|
|
3976
|
-
return triggersOf(step).some(t => "hidden" in t && env.isVisible(t.hidden));
|
|
3977
|
-
}
|
|
3978
|
-
function missionCount(suite) {
|
|
3979
|
-
return suite.missions.length;
|
|
3980
|
-
}
|
|
3981
|
-
function missionSettled(m, entry, ctx) {
|
|
3982
|
-
if (entry?.status === "done")
|
|
3983
|
-
return true;
|
|
3984
|
-
if (m.optional && entry?.status === "skipped")
|
|
3985
|
-
return true;
|
|
3986
|
-
return safe(() => m.alreadyDone?.(ctx) === true, false);
|
|
3987
|
-
}
|
|
3988
|
-
function settledCount(suite, progress, ctx) {
|
|
3989
|
-
return suite.missions.filter(m => missionSettled(m, progress.missions[m.key], ctx)).length;
|
|
3990
|
-
}
|
|
3991
|
-
function gateState(suite, ctx) {
|
|
3992
|
-
if (!suite.gate)
|
|
3993
|
-
return true;
|
|
3994
|
-
return safe(() => suite.gate.ready(ctx), undefined);
|
|
3995
|
-
}
|
|
3996
|
-
function missionViews(suite, progress, ctx) {
|
|
3997
|
-
const gate = gateState(suite, ctx);
|
|
3998
|
-
const settled = (key) => {
|
|
3999
|
-
const m = findMission(suite, key);
|
|
4000
|
-
return !!m && missionSettled(m, progress.missions[key], ctx);
|
|
4001
|
-
};
|
|
4002
|
-
let nextMarked = false;
|
|
4003
|
-
return suite.missions.map(mission => {
|
|
4004
|
-
const entry = progress.missions[mission.key];
|
|
4005
|
-
let view;
|
|
4006
|
-
if (entry?.status === "done")
|
|
4007
|
-
view = "done";
|
|
4008
|
-
else if (safe(() => mission.alreadyDone?.(ctx) === true, false))
|
|
4009
|
-
view = "already";
|
|
4010
|
-
else if (entry?.status === "skipped")
|
|
4011
|
-
view = "skipped";
|
|
4012
|
-
else if (entry?.status === "active")
|
|
4013
|
-
view = "active";
|
|
4014
|
-
else if (gate === false)
|
|
4015
|
-
view = "waiting";
|
|
4016
|
-
else if ((mission.after ?? []).some(k => !settled(k)))
|
|
4017
|
-
view = "locked";
|
|
4018
|
-
else
|
|
4019
|
-
view = "todo";
|
|
4020
|
-
if (!nextMarked && (view === "todo" || view === "active" || view === "skipped")) {
|
|
4021
|
-
nextMarked = true;
|
|
4022
|
-
if (view === "todo")
|
|
4023
|
-
view = "next";
|
|
4024
|
-
}
|
|
4025
|
-
return { mission, view, entry };
|
|
4026
|
-
});
|
|
4027
|
-
}
|
|
4028
|
-
/** The mission the celebration offers next: the first one not settled and not locked. */
|
|
4029
|
-
function nextMissionKey(suite, progress, ctx) {
|
|
4030
|
-
for (const v of missionViews(suite, progress, ctx)) {
|
|
4031
|
-
if (v.view === "next" || v.view === "todo" || v.view === "active" || v.view === "skipped") {
|
|
4032
|
-
return v.mission.key;
|
|
4033
|
-
}
|
|
4034
|
-
}
|
|
4035
|
-
return null;
|
|
4036
|
-
}
|
|
4037
|
-
/** Whether the welcome should open by itself. */
|
|
4038
|
-
function welcomeDue(state, suite) {
|
|
4039
|
-
return (state.audience === "forced" &&
|
|
4040
|
-
state.progress.welcome === "not_seen" &&
|
|
4041
|
-
state.progress.status === "in_progress" &&
|
|
4042
|
-
!state.progress.mission_key &&
|
|
4043
|
-
state.screen.name === "idle" &&
|
|
4044
|
-
suite.missions.length > 0);
|
|
4045
|
-
}
|
|
4046
|
-
/** Whether the floating "ภารกิจ n/N" chip shows. */
|
|
4047
|
-
function chipVisible(state, suite, ctx) {
|
|
4048
|
-
return (state.audience !== "none" &&
|
|
4049
|
-
state.progress.welcome !== "not_seen" &&
|
|
4050
|
-
state.progress.status !== "completed" &&
|
|
4051
|
-
!state.progress.chip_hidden &&
|
|
4052
|
-
state.screen.name === "idle" &&
|
|
4053
|
-
!state.panelOpen &&
|
|
4054
|
-
settledCount(suite, state.progress, ctx) < missionCount(suite));
|
|
4055
|
-
}
|
|
4056
|
-
function withProgress(d, patch) {
|
|
4057
|
-
d.state = { ...d.state, progress: { ...d.state.progress, ...patch } };
|
|
4058
|
-
}
|
|
4059
|
-
function setMission(d, key, entry) {
|
|
4060
|
-
withProgress(d, { missions: { ...d.state.progress.missions, [key]: entry } });
|
|
4061
|
-
}
|
|
4062
|
-
function setScreen(d, screen) {
|
|
4063
|
-
d.state = { ...d.state, screen };
|
|
4064
|
-
}
|
|
4065
|
-
function save(d, immediate = false) {
|
|
4066
|
-
const existing = d.effects.find(e => e.type === "save");
|
|
4067
|
-
if (existing)
|
|
4068
|
-
existing.immediate = existing.immediate || immediate;
|
|
4069
|
-
else
|
|
4070
|
-
d.effects.push({ type: "save", immediate });
|
|
4071
|
-
}
|
|
4072
|
-
function announceStep(d, suite, env) {
|
|
4073
|
-
const s = d.state.screen;
|
|
4074
|
-
if (s.name !== "step")
|
|
4075
|
-
return;
|
|
4076
|
-
const mission = findMission(suite, s.mission);
|
|
4077
|
-
if (!mission)
|
|
4078
|
-
return;
|
|
4079
|
-
const step = mission.steps[s.index];
|
|
4080
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4081
|
-
const title = s.bridge ? COPY.bridgeTitle : plainTitle(resolveText(step.title, ctx));
|
|
4082
|
-
const why = s.bridge ? COPY.bridgeWhy(suite.appName) : plainTitle(resolveText(step.why, ctx));
|
|
4083
|
-
d.effects.push({
|
|
4084
|
-
type: "announce",
|
|
4085
|
-
text: `ขั้นที่ ${s.index + 1} จาก ${mission.steps.length}. ${title}${why ? `. ${why}` : ""}`,
|
|
4086
|
-
});
|
|
4087
|
-
}
|
|
4088
|
-
/** "กด [บันทึก]" → "กด บันทึก" (for screen readers). */
|
|
4089
|
-
function plainTitle(t) {
|
|
4090
|
-
return t.replace(/\[([^\]]+)\]/g, "$1");
|
|
3550
|
+
const base = platformBaseUrl?.replace(/\/$/, "") ?? "";
|
|
3551
|
+
const createHref = code ? `${base}/${code}/employee/create` : `${base}/`;
|
|
3552
|
+
return (jsx("div", { className: "fixed inset-0 z-[100] flex items-center justify-center bg-background/95 p-6 backdrop-blur-sm", children: jsxs("div", { className: "w-full max-w-md space-y-5 text-center", children: [jsx(ContactRound, { className: "mx-auto h-12 w-12 text-muted-foreground" }), jsxs("div", { className: "space-y-2", children: [jsx("h1", { className: "text-lg font-semibold tracking-tight", children: "\u0E1A\u0E31\u0E0D\u0E0A\u0E35\u0E19\u0E35\u0E49\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E1C\u0E39\u0E01\u0E01\u0E31\u0E1A\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19" }), jsx("p", { className: "text-sm text-muted-foreground", children: "\u0E25\u0E32 \u0E25\u0E07\u0E40\u0E27\u0E25\u0E32 \u0E40\u0E1A\u0E34\u0E01\u0E40\u0E07\u0E34\u0E19 \u0E41\u0E25\u0E30\u0E01\u0E32\u0E23\u0E2D\u0E19\u0E38\u0E21\u0E31\u0E15\u0E34 \u0E23\u0E30\u0E1A\u0E38\u0E15\u0E31\u0E27\u0E04\u0E19\u0E08\u0E32\u0E01\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19 \u0E08\u0E36\u0E07\u0E22\u0E31\u0E07\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E43\u0E19\u0E2D\u0E07\u0E04\u0E4C\u0E01\u0E23\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49" })] }), jsxs("div", { className: "flex flex-wrap justify-center gap-2", children: [jsx(Button, { onClick: () => window.location.reload(), children: "\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48" }), jsx(Button, { variant: "outline", asChild: true, children: jsxs("a", { href: createHref, children: [jsx(UserPlus, { className: "mr-1 h-4 w-4" }), "\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19"] }) })] }), jsx("p", { className: "text-xs text-muted-foreground", children: "\u0E16\u0E49\u0E32\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E41\u0E01\u0E49\u0E44\u0E02 \u0E43\u0E2B\u0E49\u0E41\u0E08\u0E49\u0E07\u0E1C\u0E39\u0E49\u0E14\u0E39\u0E41\u0E25\u0E2D\u0E07\u0E04\u0E4C\u0E01\u0E23" })] }) }));
|
|
4091
3553
|
}
|
|
3554
|
+
|
|
4092
3555
|
/**
|
|
4093
|
-
*
|
|
4094
|
-
*
|
|
3556
|
+
* Talking to platform-api about tour progress (API.md): the GET that says
|
|
3557
|
+
* who sees what, and the PUT that saves, with its rev check. This is the
|
|
3558
|
+
* shell's progress adapter (GuideHost); the rules live in progress-sync.ts.
|
|
4095
3559
|
*/
|
|
4096
|
-
function
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
let firstPass = true;
|
|
4100
|
-
while (i < steps.length) {
|
|
4101
|
-
const step = steps[i];
|
|
4102
|
-
const params = routeParamsFor(step, env);
|
|
4103
|
-
const ctx = guideContext(env, d.state.progress.context, params);
|
|
4104
|
-
if (step.requires && !safe(() => env.can(step.requires), true)) {
|
|
4105
|
-
// A replay writes nothing, not even what went wrong.
|
|
4106
|
-
if (!opts.replay)
|
|
4107
|
-
withProgress(d, { last_error: `forbidden:${step.requires}`.slice(0, 128) });
|
|
4108
|
-
i++;
|
|
4109
|
-
continue;
|
|
4110
|
-
}
|
|
4111
|
-
if (step.skipIf && safe(() => step.skipIf(ctx), false)) {
|
|
4112
|
-
i++;
|
|
4113
|
-
continue;
|
|
4114
|
-
}
|
|
4115
|
-
const autoPass = step.autoPass !== false && !(firstPass && opts.noAutoPass);
|
|
4116
|
-
firstPass = false;
|
|
4117
|
-
if (autoPass && stepKind(step) !== "input" && stepKind(step) !== "view") {
|
|
4118
|
-
const held = stateTriggerHolds(step, env);
|
|
4119
|
-
if (held) {
|
|
4120
|
-
captureInto(d, step, held, ctx);
|
|
4121
|
-
i++;
|
|
4122
|
-
continue;
|
|
4123
|
-
}
|
|
4124
|
-
}
|
|
4125
|
-
break;
|
|
4126
|
-
}
|
|
4127
|
-
if (i >= steps.length) {
|
|
4128
|
-
finishMission(d, suite, env, mission, opts.replay);
|
|
4129
|
-
return;
|
|
4130
|
-
}
|
|
4131
|
-
const step = steps[i];
|
|
4132
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4133
|
-
const where = placeRoute(steps, i);
|
|
4134
|
-
const away = !!where && !matchRoute(where, env.pathname, env.search, env.code);
|
|
4135
|
-
const bridge = !away && needsBridge(step, env, ctx);
|
|
4136
|
-
setScreen(d, {
|
|
4137
|
-
name: "step",
|
|
4138
|
-
mission: mission.key,
|
|
4139
|
-
index: i,
|
|
4140
|
-
replay: opts.replay,
|
|
4141
|
-
bridge,
|
|
4142
|
-
phase: away ? "away" : "waiting",
|
|
4143
|
-
error: opts.error ?? null,
|
|
4144
|
-
confirmExit: false,
|
|
4145
|
-
misses: 0,
|
|
4146
|
-
armed: hiddenAnchorShown(step, env),
|
|
4147
|
-
});
|
|
4148
|
-
if (!opts.replay) {
|
|
4149
|
-
const cp = checkpointAtOrBefore(steps, i);
|
|
4150
|
-
setMission(d, mission.key, { status: "active", step_key: step.key });
|
|
4151
|
-
withProgress(d, {
|
|
4152
|
-
mission_key: mission.key,
|
|
4153
|
-
step_key: step.key,
|
|
4154
|
-
step_index: i,
|
|
4155
|
-
checkpoint_key: steps[cp].key,
|
|
4156
|
-
});
|
|
4157
|
-
save(d);
|
|
4158
|
-
}
|
|
4159
|
-
if (!away) {
|
|
4160
|
-
// The target may already be there.
|
|
4161
|
-
markReadyIfVisible(d, suite, env);
|
|
4162
|
-
}
|
|
3560
|
+
function base(app) {
|
|
3561
|
+
// LIFF's progress is on peoplx-api, never here; the help channel's default.
|
|
3562
|
+
return platformApiBase(app === "liff" ? "other" : app);
|
|
4163
3563
|
}
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
const where = placeRoute(mission.steps, index);
|
|
4185
|
-
return (safe(() => step.resumeUrl?.(ctx), undefined) ??
|
|
4186
|
-
(where ? fillRoute(where, { ...d.state.progress.context, code: env.code }) : null));
|
|
3564
|
+
/** platform-api's `…/organizations/:id/guides/me` as a progress adapter. */
|
|
3565
|
+
function platformGuideProgress(organizationId) {
|
|
3566
|
+
const org = encodeURIComponent(organizationId);
|
|
3567
|
+
return {
|
|
3568
|
+
async fetchProgress({ app, signal }) {
|
|
3569
|
+
const res = await instance.get(`${base(app)}/organizations/${org}/guides/me`, {
|
|
3570
|
+
params: { app },
|
|
3571
|
+
signal,
|
|
3572
|
+
erpOrganizationId: organizationId,
|
|
3573
|
+
});
|
|
3574
|
+
return res.data;
|
|
3575
|
+
},
|
|
3576
|
+
async saveProgress({ app, guideKey, body }) {
|
|
3577
|
+
const res = await instance.put(`${base(app)}/organizations/${org}/guides/me/${encodeURIComponent(guideKey)}`, body, {
|
|
3578
|
+
validateStatus: s => (s >= 200 && s < 300) || s === 409,
|
|
3579
|
+
erpOrganizationId: organizationId,
|
|
3580
|
+
});
|
|
3581
|
+
return { status: res.status, data: res.data };
|
|
3582
|
+
},
|
|
3583
|
+
};
|
|
4187
3584
|
}
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
*/
|
|
4193
|
-
function recoverOffRoute(d, suite, env, navigate) {
|
|
4194
|
-
const s = d.state.screen;
|
|
4195
|
-
if (s.name !== "step")
|
|
4196
|
-
return;
|
|
4197
|
-
const mission = findMission(suite, s.mission);
|
|
4198
|
-
if (!mission)
|
|
4199
|
-
return;
|
|
4200
|
-
const cp = checkpointAtOrBefore(mission.steps, s.index);
|
|
4201
|
-
enterStep(d, suite, env, mission, cp, { replay: s.replay });
|
|
4202
|
-
const now = d.state.screen;
|
|
4203
|
-
if (navigate && now.name === "step" && now.phase === "away") {
|
|
4204
|
-
const href = resumeHref(mission, now.index, d, env);
|
|
4205
|
-
if (href)
|
|
4206
|
-
d.effects.push({ type: "navigate", href });
|
|
4207
|
-
}
|
|
3585
|
+
|
|
3586
|
+
function GuideHost(props) {
|
|
3587
|
+
// The boundary covers the adapters too (useSidebar throws without its provider).
|
|
3588
|
+
return (jsx(GuideErrorBoundary, { children: jsx(Suspense, { fallback: null, children: jsx(GuideHostInner, { ...props }) }) }));
|
|
4208
3589
|
}
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
for (const [k, v] of Object.entries(got)) {
|
|
4217
|
-
if (typeof v === "string" && v)
|
|
4218
|
-
clean[k] = v;
|
|
4219
|
-
}
|
|
4220
|
-
if (Object.keys(clean).length) {
|
|
4221
|
-
withProgress(d, { context: { ...d.state.progress.context, ...clean } });
|
|
4222
|
-
}
|
|
3590
|
+
let fallbackClient = null;
|
|
3591
|
+
function useShellQueryClient() {
|
|
3592
|
+
const provided = useContext(QueryClientContext);
|
|
3593
|
+
if (provided)
|
|
3594
|
+
return provided;
|
|
3595
|
+
fallbackClient ?? (fallbackClient = new QueryClient());
|
|
3596
|
+
return fallbackClient;
|
|
4223
3597
|
}
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
if (s.name !== "step")
|
|
4227
|
-
return;
|
|
4228
|
-
const mission = findMission(suite, s.mission);
|
|
4229
|
-
if (!mission)
|
|
4230
|
-
return;
|
|
4231
|
-
const step = mission.steps[s.index];
|
|
4232
|
-
if (capture) {
|
|
4233
|
-
captureInto(d, step, capture, guideContext(env, d.state.progress.context, routeParamsFor(step, env)));
|
|
4234
|
-
}
|
|
4235
|
-
enterStep(d, suite, env, mission, s.index + 1, { replay: s.replay });
|
|
4236
|
-
}
|
|
4237
|
-
function finishMission(d, suite, env, mission, replay) {
|
|
4238
|
-
if (replay) {
|
|
4239
|
-
setScreen(d, { name: "idle" });
|
|
4240
|
-
d.effects.push({ type: "toast", text: COPY.replayDone });
|
|
4241
|
-
return;
|
|
4242
|
-
}
|
|
4243
|
-
setMission(d, mission.key, { status: "done", step_key: null, skipped_step: null });
|
|
4244
|
-
withProgress(d, {
|
|
4245
|
-
mission_key: null,
|
|
4246
|
-
step_key: null,
|
|
4247
|
-
step_index: 0,
|
|
4248
|
-
checkpoint_key: null,
|
|
4249
|
-
context: {},
|
|
4250
|
-
last_error: null,
|
|
4251
|
-
});
|
|
4252
|
-
const ctx = guideContext(env, {});
|
|
4253
|
-
const all = settledCount(suite, d.state.progress, ctx) >= missionCount(suite);
|
|
4254
|
-
if (all)
|
|
4255
|
-
withProgress(d, { status: "completed" });
|
|
4256
|
-
setScreen(d, all ? { name: "complete" } : { name: "celebrate", mission: mission.key });
|
|
4257
|
-
d.state = { ...d.state, justDone: mission.key };
|
|
4258
|
-
save(d, true);
|
|
4259
|
-
const n = settledCount(suite, d.state.progress, ctx);
|
|
4260
|
-
const N = missionCount(suite);
|
|
4261
|
-
const title = resolveText(mission.done?.title, ctx) || `${mission.title}แล้ว`;
|
|
4262
|
-
d.effects.push({
|
|
4263
|
-
type: "announce",
|
|
4264
|
-
text: all
|
|
4265
|
-
? `ครบ ${N} ภารกิจ ${resolveText(suite.complete.title, ctx) || "บริษัทพร้อมใช้งานแล้ว"}`
|
|
4266
|
-
: `ภารกิจสำเร็จ ${title} เสร็จ ${n} จาก ${N} ภารกิจ`,
|
|
4267
|
-
});
|
|
4268
|
-
}
|
|
4269
|
-
function startMission(d, suite, env, key, replay) {
|
|
4270
|
-
const mission = findMission(suite, key);
|
|
4271
|
-
if (!mission || mission.steps.length === 0)
|
|
4272
|
-
return;
|
|
4273
|
-
const entry = d.state.progress.missions[key];
|
|
4274
|
-
// A mission already done is only ever replayed; its done status stays.
|
|
4275
|
-
const isReplay = replay || entry?.status === "done";
|
|
4276
|
-
const before = d.state.progress;
|
|
4277
|
-
d.state = { ...d.state, panelOpen: false, justDone: null };
|
|
4278
|
-
if (d.state.progress.welcome === "not_seen")
|
|
4279
|
-
withProgress(d, { welcome: "started" });
|
|
4280
|
-
if (!isReplay && d.state.progress.mission_key !== key)
|
|
4281
|
-
withProgress(d, { context: {} });
|
|
4282
|
-
if (!isReplay && d.state.progress.status !== "in_progress") {
|
|
4283
|
-
// Picking up an optional mission after the tour completed.
|
|
4284
|
-
withProgress(d, { status: "in_progress" });
|
|
4285
|
-
}
|
|
4286
|
-
// Resume where it was left: back to the checkpoint at or before it.
|
|
4287
|
-
let index = 0;
|
|
4288
|
-
if (!isReplay && entry && (entry.status === "active" || entry.status === "skipped")) {
|
|
4289
|
-
const at = mission.steps.findIndex(s => s.key === (entry.step_key ?? entry.skipped_step));
|
|
4290
|
-
if (at > 0)
|
|
4291
|
-
index = checkpointAtOrBefore(mission.steps, at);
|
|
4292
|
-
}
|
|
4293
|
-
enterStep(d, suite, env, mission, index, { replay: isReplay });
|
|
4294
|
-
// A replay never writes progress; only what starting it changed (the
|
|
4295
|
-
// welcome, first seen through a replay) is saved.
|
|
4296
|
-
if (isReplay && d.state.progress !== before)
|
|
4297
|
-
save(d);
|
|
4298
|
-
}
|
|
4299
|
-
function exitMission(d) {
|
|
4300
|
-
const s = d.state.screen;
|
|
4301
|
-
if (s.name !== "step")
|
|
4302
|
-
return;
|
|
4303
|
-
if (!s.replay) {
|
|
4304
|
-
const prev = d.state.progress.missions[s.mission];
|
|
4305
|
-
if (prev?.status !== "done") {
|
|
4306
|
-
setMission(d, s.mission, {
|
|
4307
|
-
status: "skipped",
|
|
4308
|
-
step_key: d.state.progress.step_key,
|
|
4309
|
-
skipped_step: d.state.progress.step_key,
|
|
4310
|
-
});
|
|
4311
|
-
}
|
|
4312
|
-
withProgress(d, { mission_key: null });
|
|
4313
|
-
save(d, true);
|
|
4314
|
-
}
|
|
4315
|
-
d.state = { ...d.state, chipPulse: d.state.chipPulse + 1 };
|
|
4316
|
-
setScreen(d, { name: "idle" });
|
|
4317
|
-
}
|
|
4318
|
-
function triggerMatchesSignal(t, sig, env, ctx) {
|
|
4319
|
-
if ("api" in t && sig.kind === "api") {
|
|
4320
|
-
if (t.api.method && t.api.method.toUpperCase() !== sig.method.toUpperCase())
|
|
4321
|
-
return null;
|
|
4322
|
-
if (!matchApiPath(t.api.path, sig.path))
|
|
4323
|
-
return null;
|
|
4324
|
-
if (!matchStatus(t.api.status, sig.status))
|
|
4325
|
-
return null;
|
|
4326
|
-
return { api: { method: sig.method.toUpperCase(), path: sig.path, status: sig.status, id: sig.id } };
|
|
4327
|
-
}
|
|
4328
|
-
if ("event" in t && sig.kind === "event") {
|
|
4329
|
-
return t.event === sig.name ? { event: { name: sig.name, detail: sig.detail } } : null;
|
|
4330
|
-
}
|
|
4331
|
-
if ("activate" in t && sig.kind === "activate")
|
|
4332
|
-
return {};
|
|
4333
|
-
if ("value" in t && sig.kind === "value") {
|
|
4334
|
-
return safe(() => t.value(sig.value, ctx), false) ? {} : null;
|
|
4335
|
-
}
|
|
4336
|
-
return null;
|
|
4337
|
-
}
|
|
4338
|
-
/** A refused save that a commit step listens for. */
|
|
4339
|
-
function apiFailureFor(step, sig) {
|
|
4340
|
-
if (sig.kind !== "api" || sig.status < 400)
|
|
4341
|
-
return false;
|
|
4342
|
-
return triggersOf(step).some(t => "api" in t &&
|
|
4343
|
-
(!t.api.method || t.api.method.toUpperCase() === sig.method.toUpperCase()) &&
|
|
4344
|
-
matchApiPath(t.api.path, sig.path));
|
|
4345
|
-
}
|
|
4346
|
-
/** A replay ends early: what puts the page back (nothing on another page). */
|
|
4347
|
-
function pushAbort(d, suite, s) {
|
|
4348
|
-
if (s.phase === "away")
|
|
4349
|
-
return;
|
|
4350
|
-
const mission = findMission(suite, s.mission);
|
|
4351
|
-
if (!mission)
|
|
4352
|
-
return;
|
|
4353
|
-
const actions = abortActionsFor(mission, s.index);
|
|
4354
|
-
if (actions.length)
|
|
4355
|
-
d.effects.push({ type: "abort", actions });
|
|
4356
|
-
}
|
|
4357
|
-
function reduceGuide(state, action, suite, env) {
|
|
4358
|
-
const d = { state, effects: [] };
|
|
4359
|
-
const s = state.screen;
|
|
4360
|
-
const ctxNow = () => guideContext(env, d.state.progress.context);
|
|
4361
|
-
switch (action.type) {
|
|
4362
|
-
case "welcome": {
|
|
4363
|
-
if (!welcomeDue(state, suite))
|
|
4364
|
-
break;
|
|
4365
|
-
const gate = gateState(suite, ctxNow());
|
|
4366
|
-
if (gate === undefined)
|
|
4367
|
-
break;
|
|
4368
|
-
if (gate === false) {
|
|
4369
|
-
if (!state.gateDismissed)
|
|
4370
|
-
setScreen(d, { name: "gate" });
|
|
4371
|
-
break;
|
|
4372
|
-
}
|
|
4373
|
-
setScreen(d, { name: "welcome", confirm: false });
|
|
4374
|
-
break;
|
|
4375
|
-
}
|
|
4376
|
-
case "welcomeSkip":
|
|
4377
|
-
if (s.name === "welcome")
|
|
4378
|
-
setScreen(d, { name: "welcome", confirm: true });
|
|
4379
|
-
break;
|
|
4380
|
-
case "welcomeStart":
|
|
4381
|
-
case "welcomeSkipCancel": {
|
|
4382
|
-
if (s.name !== "welcome")
|
|
4383
|
-
break;
|
|
4384
|
-
const first = nextMissionKey(suite, d.state.progress, ctxNow());
|
|
4385
|
-
if (first)
|
|
4386
|
-
startMission(d, suite, env, first, false);
|
|
4387
|
-
else
|
|
4388
|
-
setScreen(d, { name: "idle" });
|
|
4389
|
-
break;
|
|
4390
|
-
}
|
|
4391
|
-
case "welcomeSkipConfirm":
|
|
4392
|
-
if (s.name !== "welcome")
|
|
4393
|
-
break;
|
|
4394
|
-
withProgress(d, { welcome: "skipped" });
|
|
4395
|
-
d.state = { ...d.state, chipPulse: d.state.chipPulse + 1 };
|
|
4396
|
-
setScreen(d, { name: "idle" });
|
|
4397
|
-
save(d, true);
|
|
4398
|
-
break;
|
|
4399
|
-
case "gateLater":
|
|
4400
|
-
if (s.name === "gate") {
|
|
4401
|
-
d.state = { ...d.state, gateDismissed: true };
|
|
4402
|
-
setScreen(d, { name: "idle" });
|
|
4403
|
-
}
|
|
4404
|
-
break;
|
|
4405
|
-
case "start":
|
|
4406
|
-
if (state.audience === "none")
|
|
4407
|
-
break;
|
|
4408
|
-
if (s.name === "step" && !s.replay && s.mission !== action.mission) {
|
|
4409
|
-
// Leaving one mission for another: the first is set aside.
|
|
4410
|
-
exitMission(d);
|
|
4411
|
-
}
|
|
4412
|
-
startMission(d, suite, env, action.mission, !!action.replay);
|
|
4413
|
-
break;
|
|
4414
|
-
case "resume": {
|
|
4415
|
-
if (state.audience === "none" || s.name !== "idle")
|
|
4416
|
-
break;
|
|
4417
|
-
const mission = findMission(suite, d.state.progress.mission_key);
|
|
4418
|
-
if (!mission || d.state.progress.missions[mission.key]?.status !== "active")
|
|
4419
|
-
break;
|
|
4420
|
-
// Back to the last checkpoint at or before the step reached; the saved
|
|
4421
|
-
// checkpoint when the step is no longer in the tour.
|
|
4422
|
-
const stepAt = mission.steps.findIndex(st => st.key === d.state.progress.step_key);
|
|
4423
|
-
const cpAt = mission.steps.findIndex(st => st.key === d.state.progress.checkpoint_key);
|
|
4424
|
-
const index = stepAt >= 0 ? checkpointAtOrBefore(mission.steps, stepAt) : Math.max(cpAt, 0);
|
|
4425
|
-
enterStep(d, suite, env, mission, index, { replay: false });
|
|
4426
|
-
break;
|
|
4427
|
-
}
|
|
4428
|
-
case "sync": {
|
|
4429
|
-
if (s.name !== "step")
|
|
4430
|
-
break;
|
|
4431
|
-
const mission = findMission(suite, s.mission);
|
|
4432
|
-
if (!mission)
|
|
4433
|
-
break;
|
|
4434
|
-
const step = mission.steps[s.index];
|
|
4435
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4436
|
-
if (s.phase === "away") {
|
|
4437
|
-
const where = placeRoute(mission.steps, s.index);
|
|
4438
|
-
if (!where || matchRoute(where, env.pathname, env.search, env.code)) {
|
|
4439
|
-
// Arrived: run the step again from here (it may already be passed).
|
|
4440
|
-
enterStep(d, suite, env, mission, s.index, { replay: s.replay, error: s.error });
|
|
4441
|
-
}
|
|
4442
|
-
break;
|
|
4443
|
-
}
|
|
4444
|
-
if (s.confirmExit)
|
|
4445
|
-
break;
|
|
4446
|
-
const kind = stepKind(step);
|
|
4447
|
-
const armed = s.armed || hiddenAnchorShown(step, env);
|
|
4448
|
-
if (kind !== "input" && kind !== "view") {
|
|
4449
|
-
const held = syncTriggerHolds(step, env, armed);
|
|
4450
|
-
if (held) {
|
|
4451
|
-
advance(d, suite, env, held);
|
|
4452
|
-
break;
|
|
4453
|
-
}
|
|
4454
|
-
}
|
|
4455
|
-
if (!s.bridge && !stepTargetVisible(step, env, ctx, false) && offRoute(mission.steps, s.index, env)) {
|
|
4456
|
-
// The target is missing because the page is another one.
|
|
4457
|
-
recoverOffRoute(d, suite, env, false);
|
|
4458
|
-
break;
|
|
4459
|
-
}
|
|
4460
|
-
if (armed !== s.armed)
|
|
4461
|
-
setScreen(d, { ...s, armed });
|
|
4462
|
-
const cur = d.state.screen;
|
|
4463
|
-
// The menu step: done once the sidebar is open; needed again if shut.
|
|
4464
|
-
if (cur.bridge && (env.sidebarOpen || stepTargetVisible(step, env, ctx, false))) {
|
|
4465
|
-
setScreen(d, { ...cur, bridge: false, phase: "waiting" });
|
|
4466
|
-
}
|
|
4467
|
-
else if (!cur.bridge && needsBridge(step, env, ctx)) {
|
|
4468
|
-
setScreen(d, { ...cur, bridge: true, phase: "waiting" });
|
|
4469
|
-
}
|
|
4470
|
-
markReadyIfVisible(d, suite, env);
|
|
4471
|
-
break;
|
|
4472
|
-
}
|
|
4473
|
-
case "signal": {
|
|
4474
|
-
if (s.name !== "step" || s.phase === "away" || s.confirmExit)
|
|
4475
|
-
break;
|
|
4476
|
-
const mission = findMission(suite, s.mission);
|
|
4477
|
-
if (!mission)
|
|
4478
|
-
break;
|
|
4479
|
-
const step = mission.steps[s.index];
|
|
4480
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4481
|
-
const sig = action.signal;
|
|
4482
|
-
if (sig.kind === "typing") {
|
|
4483
|
-
if (s.error)
|
|
4484
|
-
setScreen(d, { ...s, error: null });
|
|
4485
|
-
break;
|
|
4486
|
-
}
|
|
4487
|
-
if (s.bridge)
|
|
4488
|
-
break;
|
|
4489
|
-
for (const t of triggersOf(step)) {
|
|
4490
|
-
const hit = triggerMatchesSignal(t, sig, env, ctx);
|
|
4491
|
-
if (hit) {
|
|
4492
|
-
advance(d, suite, env, hit);
|
|
4493
|
-
return { state: d.state, effects: d.effects };
|
|
4494
|
-
}
|
|
4495
|
-
}
|
|
4496
|
-
if (sig.kind === "api" && stepKind(step) === "commit" && apiFailureFor(step, sig)) {
|
|
4497
|
-
const mapped = safe(() => step.onApiError?.({ status: sig.status, message: sig.message }, ctx), undefined);
|
|
4498
|
-
if (mapped && mapped.step) {
|
|
4499
|
-
const to = mission.steps.findIndex(st => st.key === mapped.step);
|
|
4500
|
-
if (to >= 0) {
|
|
4501
|
-
enterStep(d, suite, env, mission, to, {
|
|
4502
|
-
replay: s.replay,
|
|
4503
|
-
noAutoPass: true,
|
|
4504
|
-
error: { title: mapped.message ?? sig.message ?? COPY.saveFailed, detail: COPY.fieldFix },
|
|
4505
|
-
});
|
|
4506
|
-
break;
|
|
4507
|
-
}
|
|
4508
|
-
}
|
|
4509
|
-
const error = mapped?.message
|
|
4510
|
-
? { title: mapped.message, detail: undefined }
|
|
4511
|
-
: { title: COPY.saveFailed, detail: sig.message };
|
|
4512
|
-
setScreen(d, { ...s, error });
|
|
4513
|
-
d.effects.push({ type: "announce", text: [error.title, error.detail].filter(Boolean).join(". ") });
|
|
4514
|
-
if (!s.replay)
|
|
4515
|
-
withProgress(d, { last_error: `api_${sig.status}:${step.key}`.slice(0, 128) });
|
|
4516
|
-
}
|
|
4517
|
-
break;
|
|
4518
|
-
}
|
|
4519
|
-
case "next": {
|
|
4520
|
-
if (s.name !== "step" || s.phase !== "ready" || s.confirmExit || s.bridge)
|
|
4521
|
-
break;
|
|
4522
|
-
const mission = findMission(suite, s.mission);
|
|
4523
|
-
if (!mission)
|
|
4524
|
-
break;
|
|
4525
|
-
const step = mission.steps[s.index];
|
|
4526
|
-
const kind = stepKind(step);
|
|
4527
|
-
if (kind === "view") {
|
|
4528
|
-
advance(d, suite, env);
|
|
4529
|
-
break;
|
|
4530
|
-
}
|
|
4531
|
-
if (kind !== "input")
|
|
4532
|
-
break;
|
|
4533
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4534
|
-
const value = safe(() => env.targetValue(), "");
|
|
4535
|
-
const problem = step.validate
|
|
4536
|
-
? safe(() => step.validate(value, ctx), null)
|
|
4537
|
-
: value.trim()
|
|
4538
|
-
? null
|
|
4539
|
-
: COPY.blank;
|
|
4540
|
-
if (problem) {
|
|
4541
|
-
setScreen(d, { ...s, error: { title: problem, detail: COPY.fieldFix } });
|
|
4542
|
-
d.state = { ...d.state, nudge: d.state.nudge + 1 };
|
|
4543
|
-
d.effects.push({ type: "announce", text: problem });
|
|
4544
|
-
}
|
|
4545
|
-
else {
|
|
4546
|
-
advance(d, suite, env);
|
|
4547
|
-
}
|
|
4548
|
-
break;
|
|
4549
|
-
}
|
|
4550
|
-
case "targetLost": {
|
|
4551
|
-
if (s.name !== "step" || s.phase !== "ready" || s.confirmExit)
|
|
4552
|
-
break;
|
|
4553
|
-
const mission = findMission(suite, s.mission);
|
|
4554
|
-
if (!mission)
|
|
4555
|
-
break;
|
|
4556
|
-
const step = mission.steps[s.index];
|
|
4557
|
-
const ctx = guideContext(env, d.state.progress.context, routeParamsFor(step, env));
|
|
4558
|
-
if (stepTargetVisible(step, env, ctx, s.bridge))
|
|
4559
|
-
break;
|
|
4560
|
-
if (!s.bridge && offRoute(mission.steps, s.index, env)) {
|
|
4561
|
-
recoverOffRoute(d, suite, env, false);
|
|
4562
|
-
break;
|
|
4563
|
-
}
|
|
4564
|
-
const cp = checkpointAtOrBefore(mission.steps, s.index);
|
|
4565
|
-
if (cp < s.index && !s.bridge) {
|
|
4566
|
-
// A dialog or a menu closed under the step: back to what opens it.
|
|
4567
|
-
enterStep(d, suite, env, mission, cp, { replay: s.replay, noAutoPass: false });
|
|
4568
|
-
}
|
|
4569
|
-
else {
|
|
4570
|
-
setScreen(d, { ...s, phase: "waiting" });
|
|
4571
|
-
}
|
|
4572
|
-
break;
|
|
4573
|
-
}
|
|
4574
|
-
case "timeout": {
|
|
4575
|
-
if (s.name !== "step" || s.phase !== "waiting")
|
|
4576
|
-
break;
|
|
4577
|
-
const mission = findMission(suite, s.mission);
|
|
4578
|
-
if (!mission)
|
|
4579
|
-
break;
|
|
4580
|
-
const step = mission.steps[s.index];
|
|
4581
|
-
if (!s.bridge && offRoute(mission.steps, s.index, env)) {
|
|
4582
|
-
recoverOffRoute(d, suite, env, false);
|
|
4583
|
-
break;
|
|
4584
|
-
}
|
|
4585
|
-
const anchor = s.bridge ? BRIDGE_TARGET : (step.target ?? step.key);
|
|
4586
|
-
// Diagnostic only: kept with the progress, sent with its next save (a
|
|
4587
|
-
// replay keeps nothing). The same error again changes nothing, so it
|
|
4588
|
-
// never sends a PUT on its own.
|
|
4589
|
-
if (!s.replay)
|
|
4590
|
-
withProgress(d, { last_error: `target_missing:${anchor}`.slice(0, 128) });
|
|
4591
|
-
const misses = s.misses + 1;
|
|
4592
|
-
const policy = step.onMissing ?? "retry";
|
|
4593
|
-
const cp = checkpointAtOrBefore(mission.steps, s.index);
|
|
4594
|
-
if (policy === "skip") {
|
|
4595
|
-
advance(d, suite, env);
|
|
4596
|
-
}
|
|
4597
|
-
else if (policy === "abort") {
|
|
4598
|
-
exitMission(d);
|
|
4599
|
-
d.effects.push({ type: "toast", text: COPY.aborted });
|
|
4600
|
-
}
|
|
4601
|
-
else if ((policy === "rewind" || (policy === "retry" && misses >= 2)) && cp < s.index) {
|
|
4602
|
-
enterStep(d, suite, env, mission, cp, { replay: s.replay });
|
|
4603
|
-
const now = d.state.screen;
|
|
4604
|
-
if (now.name === "step" && now.index === s.index) {
|
|
4605
|
-
// The checkpoint passed straight back to this step (its dialog is
|
|
4606
|
-
// still open): going back cannot help, so say so.
|
|
4607
|
-
setScreen(d, { ...now, phase: "missing", misses });
|
|
4608
|
-
d.effects.push({ type: "announce", text: "ไม่พบส่วนนี้บนหน้า" });
|
|
4609
|
-
}
|
|
4610
|
-
}
|
|
4611
|
-
else {
|
|
4612
|
-
setScreen(d, { ...s, phase: "missing", misses });
|
|
4613
|
-
d.effects.push({ type: "announce", text: "ไม่พบส่วนนี้บนหน้า" });
|
|
4614
|
-
}
|
|
4615
|
-
break;
|
|
4616
|
-
}
|
|
4617
|
-
case "retry": {
|
|
4618
|
-
if (s.name !== "step" || s.phase !== "missing")
|
|
4619
|
-
break;
|
|
4620
|
-
const mission = findMission(suite, s.mission);
|
|
4621
|
-
if (mission && !s.bridge && offRoute(mission.steps, s.index, env)) {
|
|
4622
|
-
// Polling again cannot help on another page: go back to the step's.
|
|
4623
|
-
recoverOffRoute(d, suite, env, true);
|
|
4624
|
-
break;
|
|
4625
|
-
}
|
|
4626
|
-
setScreen(d, { ...s, phase: "waiting" });
|
|
4627
|
-
markReadyIfVisible(d, suite, env);
|
|
4628
|
-
break;
|
|
4629
|
-
}
|
|
4630
|
-
case "blocked":
|
|
4631
|
-
if (s.name === "step")
|
|
4632
|
-
d.state = { ...d.state, nudge: d.state.nudge + 1 };
|
|
4633
|
-
break;
|
|
4634
|
-
case "exit":
|
|
4635
|
-
if (s.name !== "step")
|
|
4636
|
-
break;
|
|
4637
|
-
if (s.replay) {
|
|
4638
|
-
pushAbort(d, suite, s);
|
|
4639
|
-
setScreen(d, { name: "idle" });
|
|
4640
|
-
d.effects.push({ type: "toast", text: COPY.replayEnded });
|
|
4641
|
-
}
|
|
4642
|
-
else {
|
|
4643
|
-
setScreen(d, { ...s, confirmExit: true });
|
|
4644
|
-
}
|
|
4645
|
-
break;
|
|
4646
|
-
case "exitCancel":
|
|
4647
|
-
if (s.name === "step" && s.confirmExit)
|
|
4648
|
-
setScreen(d, { ...s, confirmExit: false });
|
|
4649
|
-
break;
|
|
4650
|
-
case "exitConfirm":
|
|
4651
|
-
if (s.name !== "step")
|
|
4652
|
-
break;
|
|
4653
|
-
exitMission(d);
|
|
4654
|
-
d.effects.push({ type: "toast", text: COPY.exitToast });
|
|
4655
|
-
break;
|
|
4656
|
-
case "endWithoutSave":
|
|
4657
|
-
if (s.name !== "step" || !s.replay)
|
|
4658
|
-
break;
|
|
4659
|
-
pushAbort(d, suite, s);
|
|
4660
|
-
setScreen(d, { name: "idle" });
|
|
4661
|
-
d.effects.push({ type: "toast", text: COPY.replayEnded });
|
|
4662
|
-
break;
|
|
4663
|
-
case "goResume": {
|
|
4664
|
-
if (s.name !== "step" || s.phase !== "away")
|
|
4665
|
-
break;
|
|
4666
|
-
const mission = findMission(suite, s.mission);
|
|
4667
|
-
if (!mission)
|
|
4668
|
-
break;
|
|
4669
|
-
const href = resumeHref(mission, s.index, d, env);
|
|
4670
|
-
if (href)
|
|
4671
|
-
d.effects.push({ type: "navigate", href });
|
|
4672
|
-
break;
|
|
4673
|
-
}
|
|
4674
|
-
case "celebrateNext": {
|
|
4675
|
-
if (s.name !== "celebrate")
|
|
4676
|
-
break;
|
|
4677
|
-
const next = nextMissionKey(suite, d.state.progress, ctxNow());
|
|
4678
|
-
if (next)
|
|
4679
|
-
startMission(d, suite, env, next, false);
|
|
4680
|
-
else
|
|
4681
|
-
setScreen(d, { name: "idle" });
|
|
4682
|
-
break;
|
|
4683
|
-
}
|
|
4684
|
-
case "rest":
|
|
4685
|
-
if (s.name !== "celebrate")
|
|
4686
|
-
break;
|
|
4687
|
-
setScreen(d, { name: "idle" });
|
|
4688
|
-
d.state = { ...d.state, panelOpen: true, justDone: s.mission };
|
|
4689
|
-
break;
|
|
4690
|
-
case "finish": {
|
|
4691
|
-
if (s.name !== "complete")
|
|
4692
|
-
break;
|
|
4693
|
-
setScreen(d, { name: "idle" });
|
|
4694
|
-
const href = resolveText(suite.complete.action.href, ctxNow());
|
|
4695
|
-
const filled = href ? (fillRoute(href, { code: env.code }) ?? href) : "";
|
|
4696
|
-
if (filled)
|
|
4697
|
-
d.effects.push({ type: "navigate", href: filled });
|
|
4698
|
-
break;
|
|
4699
|
-
}
|
|
4700
|
-
case "openPanel":
|
|
4701
|
-
if (state.audience !== "none" && s.name === "idle") {
|
|
4702
|
-
d.state = { ...d.state, panelOpen: true };
|
|
4703
|
-
}
|
|
4704
|
-
break;
|
|
4705
|
-
case "closePanel":
|
|
4706
|
-
d.state = { ...d.state, panelOpen: false, justDone: null };
|
|
4707
|
-
break;
|
|
4708
|
-
case "hideChip":
|
|
4709
|
-
withProgress(d, { chip_hidden: true });
|
|
4710
|
-
d.state = { ...d.state, panelOpen: false };
|
|
4711
|
-
d.effects.push({ type: "toast", text: COPY.hiddenToast });
|
|
4712
|
-
save(d, true);
|
|
4713
|
-
break;
|
|
4714
|
-
case "dismissMission": {
|
|
4715
|
-
const m = findMission(suite, action.mission);
|
|
4716
|
-
if (!m?.optional)
|
|
4717
|
-
break;
|
|
4718
|
-
setMission(d, m.key, { status: "skipped", step_key: null, skipped_step: null });
|
|
4719
|
-
const all = settledCount(suite, d.state.progress, ctxNow()) >= missionCount(suite);
|
|
4720
|
-
if (all) {
|
|
4721
|
-
withProgress(d, { status: "completed" });
|
|
4722
|
-
d.state = { ...d.state, panelOpen: false };
|
|
4723
|
-
setScreen(d, { name: "complete" });
|
|
4724
|
-
}
|
|
4725
|
-
save(d, true);
|
|
4726
|
-
break;
|
|
4727
|
-
}
|
|
4728
|
-
case "serverRow": {
|
|
4729
|
-
// A saved row came back: its rev, the server's status, and the dates
|
|
4730
|
-
// the server stamps on missions ("เสร็จ 26 ต.ค. 2569 13:04").
|
|
4731
|
-
const missions = { ...d.state.progress.missions };
|
|
4732
|
-
for (const [k, m] of Object.entries(missions)) {
|
|
4733
|
-
const r = action.progress.missions[k];
|
|
4734
|
-
if (r && r.status === m.status) {
|
|
4735
|
-
missions[k] = { ...m, completed_at: r.completed_at ?? m.completed_at, skipped_at: r.skipped_at ?? m.skipped_at };
|
|
4736
|
-
}
|
|
4737
|
-
}
|
|
4738
|
-
withProgress(d, { rev: action.progress.rev, server_status: action.progress.server_status, missions });
|
|
4739
|
-
break;
|
|
4740
|
-
}
|
|
4741
|
-
}
|
|
4742
|
-
return { state: d.state, effects: d.effects };
|
|
4743
|
-
}
|
|
4744
|
-
|
|
4745
|
-
/**
|
|
4746
|
-
* A tour's progress as platform-api stores it (one row per user, org and
|
|
4747
|
-
* suite: GET/PUT /organizations/:id/guides/me), and the rules for reading,
|
|
4748
|
-
* writing and merging it. See _claude-work/peoplx-guide/API.md.
|
|
4749
|
-
*
|
|
4750
|
-
* No runtime imports: the tests run this file in Node as it is.
|
|
4751
|
-
*/
|
|
4752
|
-
const KEY_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
4753
|
-
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4754
|
-
const str = (v) => (typeof v === "string" && v !== "" ? v : null);
|
|
4755
|
-
function freshProgress(version, rev = 0) {
|
|
4756
|
-
return {
|
|
4757
|
-
guide_version: version,
|
|
4758
|
-
rev,
|
|
4759
|
-
status: "in_progress",
|
|
4760
|
-
mission_key: null,
|
|
4761
|
-
step_key: null,
|
|
4762
|
-
step_index: 0,
|
|
4763
|
-
checkpoint_key: null,
|
|
4764
|
-
missions: {},
|
|
4765
|
-
context: {},
|
|
4766
|
-
welcome: "not_seen",
|
|
4767
|
-
chip_hidden: false,
|
|
4768
|
-
last_error: null,
|
|
4769
|
-
skipped_step: null,
|
|
4770
|
-
server_status: null,
|
|
4771
|
-
};
|
|
4772
|
-
}
|
|
4773
|
-
const ROW_STATUSES = ["in_progress", "completed", "skipped", "aborted"];
|
|
4774
|
-
const MISSION_STATUSES = ["todo", "active", "done", "skipped"];
|
|
4775
|
-
const WELCOMES = ["not_seen", "started", "skipped"];
|
|
4776
|
-
/** One row (a GET `guides[]` entry, a PUT answer, a 409's `current`). Null when off-shape. */
|
|
4777
|
-
function parseRow(raw) {
|
|
4778
|
-
if (!isRecord(raw))
|
|
4779
|
-
return null;
|
|
4780
|
-
const version = Number(raw.guide_version);
|
|
4781
|
-
const rev = Number(raw.rev);
|
|
4782
|
-
if (!Number.isInteger(version) || version < 1 || !Number.isInteger(rev) || rev < 0)
|
|
4783
|
-
return null;
|
|
4784
|
-
const status = ROW_STATUSES.includes(raw.status)
|
|
4785
|
-
? raw.status
|
|
4786
|
-
: "in_progress";
|
|
4787
|
-
const missions = {};
|
|
4788
|
-
if (isRecord(raw.missions)) {
|
|
4789
|
-
for (const [k, v] of Object.entries(raw.missions)) {
|
|
4790
|
-
if (!isRecord(v) || !MISSION_STATUSES.includes(v.status))
|
|
4791
|
-
continue;
|
|
4792
|
-
missions[k] = {
|
|
4793
|
-
status: v.status,
|
|
4794
|
-
step_key: str(v.step_key),
|
|
4795
|
-
skipped_step: str(v.skipped_step),
|
|
4796
|
-
completed_at: str(v.completed_at),
|
|
4797
|
-
skipped_at: str(v.skipped_at),
|
|
4798
|
-
};
|
|
4799
|
-
}
|
|
4800
|
-
}
|
|
4801
|
-
const context = {};
|
|
4802
|
-
if (isRecord(raw.context)) {
|
|
4803
|
-
for (const [k, v] of Object.entries(raw.context)) {
|
|
4804
|
-
if (typeof v === "string")
|
|
4805
|
-
context[k] = v;
|
|
4806
|
-
else if (typeof v === "number")
|
|
4807
|
-
context[k] = String(v);
|
|
4808
|
-
}
|
|
4809
|
-
}
|
|
4810
|
-
return {
|
|
4811
|
-
guide_version: version,
|
|
4812
|
-
rev,
|
|
4813
|
-
status,
|
|
4814
|
-
mission_key: str(raw.mission_key),
|
|
4815
|
-
step_key: str(raw.step_key),
|
|
4816
|
-
step_index: Number.isInteger(raw.step_index) ? raw.step_index : 0,
|
|
4817
|
-
checkpoint_key: str(raw.checkpoint_key),
|
|
4818
|
-
missions,
|
|
4819
|
-
context,
|
|
4820
|
-
welcome: WELCOMES.includes(raw.welcome) ? raw.welcome : "not_seen",
|
|
4821
|
-
chip_hidden: raw.chip_hidden === true,
|
|
4822
|
-
last_error: str(raw.last_error),
|
|
4823
|
-
skipped_step: str(raw.skipped_step),
|
|
4824
|
-
server_status: status,
|
|
4825
|
-
};
|
|
4826
|
-
}
|
|
4827
|
-
/**
|
|
4828
|
-
* The GET answer for one suite. Null — show nothing — for anything that is
|
|
4829
|
-
* not the expected shape (an older API, a proxy's page, another app's answer).
|
|
4830
|
-
*/
|
|
4831
|
-
function parseGuidesAnswer(payload, suite) {
|
|
4832
|
-
if (!isRecord(payload))
|
|
4833
|
-
return null;
|
|
4834
|
-
const data = isRecord(payload.data) ? payload.data : payload;
|
|
4835
|
-
const mode = data.mode;
|
|
4836
|
-
const audience = data.audience;
|
|
4837
|
-
if (mode !== "off" && mode !== "invite" && mode !== "forced")
|
|
4838
|
-
return null;
|
|
4839
|
-
if (audience !== "forced" && audience !== "optional" && audience !== "none")
|
|
4840
|
-
return null;
|
|
4841
|
-
if (typeof data.app === "string" && data.app !== suite.app)
|
|
4842
|
-
return null;
|
|
4843
|
-
const rows = Array.isArray(data.guides) ? data.guides : [];
|
|
4844
|
-
let row = null;
|
|
4845
|
-
for (const r of rows) {
|
|
4846
|
-
if (isRecord(r) && r.guide_key === suite.key) {
|
|
4847
|
-
row = parseRow(r);
|
|
4848
|
-
break;
|
|
4849
|
-
}
|
|
4850
|
-
}
|
|
4851
|
-
let progress;
|
|
4852
|
-
let newerOnServer = false;
|
|
4853
|
-
if (!row)
|
|
4854
|
-
progress = freshProgress(suite.version);
|
|
4855
|
-
else if (row.guide_version < suite.version) {
|
|
4856
|
-
// A new version of the tour: start over (the server resets the row on the
|
|
4857
|
-
// PUT); keep the rev the server will check.
|
|
4858
|
-
progress = { ...freshProgress(suite.version, row.rev), server_status: row.server_status };
|
|
4859
|
-
}
|
|
4860
|
-
else {
|
|
4861
|
-
progress = row;
|
|
4862
|
-
newerOnServer = row.guide_version > suite.version;
|
|
4863
|
-
}
|
|
4864
|
-
return { mode, audience: mode === "off" ? "none" : audience, progress, newerOnServer };
|
|
4865
|
-
}
|
|
4866
|
-
const TERMINAL = ["completed", "skipped", "aborted"];
|
|
4867
|
-
/** The PUT body for the client's state. Drops keys the server would refuse. */
|
|
4868
|
-
function putBody(p, app) {
|
|
4869
|
-
const key = (k) => (k && KEY_RE.test(k) ? k : null);
|
|
4870
|
-
const missions = {};
|
|
4871
|
-
for (const [k, m] of Object.entries(p.missions)) {
|
|
4872
|
-
if (!KEY_RE.test(k))
|
|
4873
|
-
continue;
|
|
4874
|
-
missions[k] = {
|
|
4875
|
-
status: m.status,
|
|
4876
|
-
step_key: key(m.step_key ?? null),
|
|
4877
|
-
skipped_step: key(m.skipped_step ?? null),
|
|
4878
|
-
};
|
|
4879
|
-
}
|
|
4880
|
-
const context = {};
|
|
4881
|
-
for (const [k, v] of Object.entries(p.context)) {
|
|
4882
|
-
if (typeof v === "string" && v.length <= 200)
|
|
4883
|
-
context[k] = v;
|
|
4884
|
-
}
|
|
4885
|
-
return {
|
|
4886
|
-
app,
|
|
4887
|
-
guide_version: p.guide_version,
|
|
4888
|
-
rev: p.rev,
|
|
4889
|
-
status: p.status,
|
|
4890
|
-
mission_key: key(p.mission_key),
|
|
4891
|
-
step_key: key(p.step_key),
|
|
4892
|
-
step_index: Math.max(0, Math.min(1000, Math.floor(p.step_index || 0))),
|
|
4893
|
-
checkpoint_key: key(p.checkpoint_key),
|
|
4894
|
-
missions,
|
|
4895
|
-
context,
|
|
4896
|
-
welcome: p.welcome,
|
|
4897
|
-
chip_hidden: p.chip_hidden,
|
|
4898
|
-
last_error: p.last_error ? p.last_error.slice(0, 128) : null,
|
|
4899
|
-
skipped_step: key(p.skipped_step),
|
|
4900
|
-
restart: p.status === "in_progress" &&
|
|
4901
|
-
p.server_status !== null &&
|
|
4902
|
-
TERMINAL.includes(p.server_status),
|
|
4903
|
-
};
|
|
4904
|
-
}
|
|
4905
|
-
function stable(v) {
|
|
4906
|
-
if (Array.isArray(v))
|
|
4907
|
-
return `[${v.map(stable).join(",")}]`;
|
|
4908
|
-
if (isRecord(v)) {
|
|
4909
|
-
return `{${Object.keys(v)
|
|
4910
|
-
.sort()
|
|
4911
|
-
.map(k => `${JSON.stringify(k)}:${stable(v[k])}`)
|
|
4912
|
-
.join(",")}}`;
|
|
4913
|
-
}
|
|
4914
|
-
return JSON.stringify(v) ?? "null";
|
|
4915
|
-
}
|
|
4916
|
-
/**
|
|
4917
|
-
* What a PUT would store, without the rev it is checked against: two equal
|
|
4918
|
-
* keys mean the save would change nothing, and it is not sent (a replay
|
|
4919
|
-
* starting, a step entered again, never bump the row's rev). Key order does
|
|
4920
|
-
* not matter.
|
|
4921
|
-
*/
|
|
4922
|
-
function payloadKey(p, app) {
|
|
4923
|
-
const { rev: _rev, restart: _restart, ...rest } = putBody(p, app);
|
|
4924
|
-
return stable(rest);
|
|
4925
|
-
}
|
|
4926
|
-
const MISSION_RANK = { todo: 0, skipped: 1, active: 1, done: 3 };
|
|
4927
|
-
const WELCOME_RANK = { not_seen: 0, skipped: 1, started: 1 };
|
|
4928
|
-
/**
|
|
4929
|
-
* After a 409: this tab's state laid over the server's, keeping whatever is
|
|
4930
|
-
* further along — a mission done anywhere stays done, the welcome once seen
|
|
4931
|
-
* stays seen, a hidden chip stays hidden. Otherwise this tab's own choice
|
|
4932
|
-
* wins. The rev is the server's.
|
|
4933
|
-
*/
|
|
4934
|
-
function mergeProgress(local, remote) {
|
|
4935
|
-
const missions = { ...remote.missions };
|
|
4936
|
-
for (const [k, m] of Object.entries(local.missions)) {
|
|
4937
|
-
const r = remote.missions[k];
|
|
4938
|
-
missions[k] = !r || MISSION_RANK[m.status] >= MISSION_RANK[r.status] ? { ...r, ...m } : r;
|
|
4939
|
-
}
|
|
4940
|
-
const welcome = WELCOME_RANK[local.welcome] >= WELCOME_RANK[remote.welcome] ? local.welcome : remote.welcome;
|
|
4941
|
-
const completed = local.status === "completed" || remote.status === "completed";
|
|
4942
|
-
const mission_key = local.mission_key && missions[local.mission_key]?.status === "active"
|
|
4943
|
-
? local.mission_key
|
|
4944
|
-
: remote.mission_key && missions[remote.mission_key]?.status === "active"
|
|
4945
|
-
? remote.mission_key
|
|
4946
|
-
: null;
|
|
4947
|
-
const fromLocal = mission_key !== null && mission_key === local.mission_key;
|
|
4948
|
-
return {
|
|
4949
|
-
...local,
|
|
4950
|
-
rev: remote.rev,
|
|
4951
|
-
server_status: remote.server_status,
|
|
4952
|
-
status: completed ? "completed" : local.status,
|
|
4953
|
-
missions,
|
|
4954
|
-
welcome,
|
|
4955
|
-
chip_hidden: local.chip_hidden || remote.chip_hidden,
|
|
4956
|
-
mission_key,
|
|
4957
|
-
step_key: fromLocal ? local.step_key : mission_key ? remote.step_key : null,
|
|
4958
|
-
step_index: fromLocal ? local.step_index : mission_key ? remote.step_index : 0,
|
|
4959
|
-
checkpoint_key: fromLocal ? local.checkpoint_key : mission_key ? remote.checkpoint_key : null,
|
|
4960
|
-
context: fromLocal ? local.context : mission_key ? remote.context : {},
|
|
4961
|
-
};
|
|
4962
|
-
}
|
|
4963
|
-
/**
|
|
4964
|
-
* Which of two copies (sessionStorage after F5, the server) to resume from:
|
|
4965
|
-
* the one further along for the same version; the server's on a tie.
|
|
4966
|
-
*/
|
|
4967
|
-
function furtherProgress(a, b) {
|
|
4968
|
-
const score = (p) => Object.values(p.missions).reduce((s, m) => s + MISSION_RANK[m.status] * 1000, 0) +
|
|
4969
|
-
(p.mission_key ? 100 + p.step_index : 0) +
|
|
4970
|
-
WELCOME_RANK[p.welcome];
|
|
4971
|
-
return score(a) > score(b) ? a : b;
|
|
4972
|
-
}
|
|
4973
|
-
|
|
4974
|
-
/**
|
|
4975
|
-
* Talking to platform-api about tour progress (API.md): the GET that says
|
|
4976
|
-
* who sees what, and the PUT that saves, with its rev check.
|
|
4977
|
-
*/
|
|
4978
|
-
function base(app) {
|
|
4979
|
-
return platformApiBase(app);
|
|
4980
|
-
}
|
|
4981
|
-
/** GET …/guides/me?app=…; null (show nothing) on any failure or odd answer. */
|
|
4982
|
-
async function fetchGuides(organizationId, suite, signal) {
|
|
4983
|
-
try {
|
|
4984
|
-
const res = await instance.get(`${base(suite.app)}/organizations/${encodeURIComponent(organizationId)}/guides/me`, { params: { app: suite.app }, signal, erpOrganizationId: organizationId });
|
|
4985
|
-
return parseGuidesAnswer(res.data, suite);
|
|
4986
|
-
}
|
|
4987
|
-
catch {
|
|
4988
|
-
return null;
|
|
4989
|
-
}
|
|
4990
|
-
}
|
|
4991
|
-
/**
|
|
4992
|
-
* PUT the whole state. On 409 the server's row comes back: merge (keeping
|
|
4993
|
-
* whatever is further along) and try once more with its rev. Returns the
|
|
4994
|
-
* stored row, or null when it could not be saved (the tour goes on; the
|
|
4995
|
-
* session copy keeps the place).
|
|
4996
|
-
*/
|
|
4997
|
-
async function saveGuides(organizationId, suite, progress) {
|
|
4998
|
-
const url = `${base(suite.app)}/organizations/${encodeURIComponent(organizationId)}/guides/me/${encodeURIComponent(suite.key)}`;
|
|
4999
|
-
let body = progress;
|
|
5000
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
5001
|
-
let res;
|
|
5002
|
-
try {
|
|
5003
|
-
res = await instance.put(url, putBody(body, suite.app), {
|
|
5004
|
-
validateStatus: s => (s >= 200 && s < 300) || s === 409,
|
|
5005
|
-
erpOrganizationId: organizationId,
|
|
5006
|
-
});
|
|
5007
|
-
}
|
|
5008
|
-
catch {
|
|
5009
|
-
return null;
|
|
5010
|
-
}
|
|
5011
|
-
const payload = res.data;
|
|
5012
|
-
if (res.status !== 409) {
|
|
5013
|
-
return parseRow(payload?.data ?? payload);
|
|
5014
|
-
}
|
|
5015
|
-
const current = parseRow(payload?.current);
|
|
5016
|
-
if (current && current.guide_version > body.guide_version) {
|
|
5017
|
-
// Another app build is ahead of this one: stop writing.
|
|
5018
|
-
return null;
|
|
5019
|
-
}
|
|
5020
|
-
if (!current)
|
|
5021
|
-
body = { ...body, rev: 0, server_status: null };
|
|
5022
|
-
else if (current.guide_version < body.guide_version) {
|
|
5023
|
-
// The server's row is the previous version: this one replaces it.
|
|
5024
|
-
body = { ...body, rev: current.rev, server_status: current.server_status };
|
|
5025
|
-
}
|
|
5026
|
-
else
|
|
5027
|
-
body = mergeProgress(body, current);
|
|
5028
|
-
}
|
|
5029
|
-
return null;
|
|
5030
|
-
}
|
|
5031
|
-
|
|
5032
|
-
/**
|
|
5033
|
-
* The tour's DOM side: finding anchors, deciding whether one is really on
|
|
5034
|
-
* screen, and the rectangles the spotlight cuts out. Browser only; every
|
|
5035
|
-
* function tolerates a missing document.
|
|
5036
|
-
*/
|
|
5037
|
-
const hasDocument = () => typeof document !== "undefined";
|
|
5038
|
-
function cssString(value) {
|
|
5039
|
-
return `"${value.replace(/["\\]/g, "\\$&")}"`;
|
|
5040
|
-
}
|
|
5041
|
-
function anchorSelector(anchor, id) {
|
|
5042
|
-
return (`[${GUIDE_ATTRIBUTE}=${cssString(anchor)}]` +
|
|
5043
|
-
(id ? `[${GUIDE_ID_ATTRIBUTE}=${cssString(id)}]` : ""));
|
|
5044
|
-
}
|
|
5045
|
-
/**
|
|
5046
|
-
* On screen: connected, with a size, not hidden by style, not inside
|
|
5047
|
-
* aria-hidden or inert (other than the guide's own), not a closed Radix part.
|
|
5048
|
-
*
|
|
5049
|
-
* aria-hidden that Radix put there (data-aria-hidden: everything outside an
|
|
5050
|
-
* open dialog, select or menu is hidden from screen readers) does not count:
|
|
5051
|
-
* a dialog's field is still on screen while its select's list is open.
|
|
5052
|
-
*/
|
|
5053
|
-
function isPresent(el) {
|
|
5054
|
-
if (!el || !el.isConnected)
|
|
5055
|
-
return false;
|
|
5056
|
-
const r = el.getBoundingClientRect();
|
|
5057
|
-
if (r.width <= 0 || r.height <= 0)
|
|
5058
|
-
return false;
|
|
5059
|
-
// Slid off the side (a closed drawer); off the top or bottom is only
|
|
5060
|
-
// scrolled away, and the tour scrolls it back. So is a tab scrolled out of
|
|
5061
|
-
// a row of tabs that scrolls sideways, as long as the row is on screen.
|
|
5062
|
-
if ((r.right <= 0 || r.left >= window.innerWidth) && !inSidewaysScroller(el))
|
|
5063
|
-
return false;
|
|
5064
|
-
if (el.getAttribute("data-state") === "closed")
|
|
5065
|
-
return false;
|
|
5066
|
-
const style = getComputedStyle(el);
|
|
5067
|
-
if (style.visibility === "hidden" || style.display === "none")
|
|
5068
|
-
return false;
|
|
5069
|
-
for (let n = el; n; n = n.parentElement) {
|
|
5070
|
-
if (n.hasAttribute(GUIDE_LAYER_ATTRIBUTE))
|
|
5071
|
-
break;
|
|
5072
|
-
if (n.hasAttribute("inert"))
|
|
5073
|
-
return false;
|
|
5074
|
-
if (n.getAttribute("aria-hidden") === "true" && !n.hasAttribute("data-aria-hidden"))
|
|
5075
|
-
return false;
|
|
5076
|
-
}
|
|
5077
|
-
return true;
|
|
5078
|
-
}
|
|
5079
|
-
/** The first matching anchor that is on screen. */
|
|
5080
|
-
function findAnchor(anchor, id) {
|
|
5081
|
-
if (!hasDocument() || !anchor)
|
|
5082
|
-
return null;
|
|
5083
|
-
let list;
|
|
5084
|
-
try {
|
|
5085
|
-
list = document.querySelectorAll(anchorSelector(anchor, id));
|
|
5086
|
-
}
|
|
5087
|
-
catch {
|
|
5088
|
-
return null;
|
|
5089
|
-
}
|
|
5090
|
-
for (const el of Array.from(list)) {
|
|
5091
|
-
if (isPresent(el))
|
|
5092
|
-
return el;
|
|
5093
|
-
}
|
|
5094
|
-
return null;
|
|
5095
|
-
}
|
|
5096
|
-
function anchorVisible(anchor, id) {
|
|
5097
|
-
return findAnchor(anchor, id) !== null;
|
|
5098
|
-
}
|
|
5099
|
-
const FIELD = "input:not([type=hidden]),textarea,select,[contenteditable=''],[contenteditable=true]";
|
|
5100
|
-
/** The field to type into: the anchor itself, or the first field inside it. */
|
|
5101
|
-
function fieldOf(el) {
|
|
5102
|
-
if (!el)
|
|
5103
|
-
return null;
|
|
5104
|
-
if (el.matches(FIELD))
|
|
5105
|
-
return el;
|
|
5106
|
-
return el.querySelector(FIELD);
|
|
5107
|
-
}
|
|
5108
|
-
function fieldValue(el) {
|
|
5109
|
-
const f = fieldOf(el);
|
|
5110
|
-
if (!f)
|
|
5111
|
-
return "";
|
|
5112
|
-
if ("value" in f && typeof f.value === "string")
|
|
5113
|
-
return f.value;
|
|
5114
|
-
return f.textContent ?? "";
|
|
5115
|
-
}
|
|
5116
|
-
const FOCUSABLE = "a[href],button:not([disabled]),input:not([disabled]):not([type=hidden]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1']),[contenteditable=''],[contenteditable=true]";
|
|
5117
|
-
function focusablesIn(root) {
|
|
5118
|
-
if (!root)
|
|
5119
|
-
return [];
|
|
5120
|
-
const own = root.matches(FOCUSABLE) ? [root] : [];
|
|
5121
|
-
return own.concat(Array.from(root.querySelectorAll(FOCUSABLE)).filter(isPresent));
|
|
5122
|
-
}
|
|
5123
|
-
function rectOf(el) {
|
|
5124
|
-
const r = el.getBoundingClientRect();
|
|
5125
|
-
return { x: r.left, y: r.top, width: r.width, height: r.height };
|
|
5126
|
-
}
|
|
5127
|
-
function padRect(r, pad) {
|
|
5128
|
-
return { x: r.x - pad, y: r.y - pad, width: r.width + pad * 2, height: r.height + pad * 2 };
|
|
5129
|
-
}
|
|
5130
|
-
function sameRect(a, b) {
|
|
5131
|
-
if (!a || !b)
|
|
5132
|
-
return a === b;
|
|
5133
|
-
return (Math.abs(a.x - b.x) < 0.5 &&
|
|
5134
|
-
Math.abs(a.y - b.y) < 0.5 &&
|
|
5135
|
-
Math.abs(a.width - b.width) < 0.5 &&
|
|
5136
|
-
Math.abs(a.height - b.height) < 0.5);
|
|
5137
|
-
}
|
|
5138
|
-
/** Open Radix poppers (a select's list, a menu): usable while a step runs. */
|
|
5139
|
-
const POPPER_SELECTOR = "[data-radix-popper-content-wrapper]";
|
|
5140
|
-
/** Toasts stay usable above the tour. */
|
|
5141
|
-
const TOASTER_SELECTOR = "[data-sonner-toaster]";
|
|
5142
|
-
/** Open dialogs (Radix dialog, alert dialog, sheet, popover content). */
|
|
5143
|
-
const OPEN_DIALOG_SELECTOR = '[role="dialog"][data-state="open"],[role="alertdialog"][data-state="open"]';
|
|
5144
|
-
/**
|
|
5145
|
-
* Whether an open dialog of the app's covers the target: the target is
|
|
5146
|
-
* neither in it nor around it (a confirm opened by the step's own button).
|
|
5147
|
-
* The ring and the hand would be drawn over the dialog, pointing at a button
|
|
5148
|
-
* behind it.
|
|
5149
|
-
*/
|
|
5150
|
-
function coveredByDialog(el) {
|
|
5151
|
-
if (!hasDocument() || !el)
|
|
5152
|
-
return false;
|
|
5153
|
-
for (const d of Array.from(document.querySelectorAll(OPEN_DIALOG_SELECTOR))) {
|
|
5154
|
-
if (inGuideLayer(d) || !isPresent(d))
|
|
5155
|
-
continue;
|
|
5156
|
-
if (d.contains(el) || el.contains(d))
|
|
5157
|
-
continue;
|
|
5158
|
-
return true;
|
|
5159
|
-
}
|
|
5160
|
-
return false;
|
|
5161
|
-
}
|
|
5162
|
-
function openPoppers() {
|
|
5163
|
-
if (!hasDocument())
|
|
5164
|
-
return [];
|
|
5165
|
-
return Array.from(document.querySelectorAll(POPPER_SELECTOR)).filter(isPresent);
|
|
5166
|
-
}
|
|
5167
|
-
function inGuideLayer(node) {
|
|
5168
|
-
if (!node || typeof Node === "undefined" || !(node instanceof Node))
|
|
5169
|
-
return false;
|
|
5170
|
-
const el = node instanceof Element ? node : node.parentElement;
|
|
5171
|
-
return !!el?.closest(`[${GUIDE_LAYER_ATTRIBUTE}]`);
|
|
5172
|
-
}
|
|
5173
|
-
function prefersReducedMotion() {
|
|
5174
|
-
return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
5175
|
-
}
|
|
5176
|
-
function isPhoneWidth() {
|
|
5177
|
-
return typeof window !== "undefined" && window.innerWidth < 768;
|
|
5178
|
-
}
|
|
5179
|
-
/* ---------------- what is really on screen ---------------- */
|
|
5180
|
-
const INFINITE = 1e7;
|
|
5181
|
-
/** The overlap of two rectangles, or null when they do not meet. */
|
|
5182
|
-
function intersectRect(a, b) {
|
|
5183
|
-
const x = Math.max(a.x, b.x);
|
|
5184
|
-
const y = Math.max(a.y, b.y);
|
|
5185
|
-
const right = Math.min(a.x + a.width, b.x + b.width);
|
|
5186
|
-
const bottom = Math.min(a.y + a.height, b.y + b.height);
|
|
5187
|
-
if (right - x <= 0 || bottom - y <= 0)
|
|
5188
|
-
return null;
|
|
5189
|
-
return { x, y, width: right - x, height: bottom - y };
|
|
5190
|
-
}
|
|
5191
|
-
/** The part of `rect` inside every clip (scroll boxes, the viewport); null when none is. */
|
|
5192
|
-
function visibleRect(rect, clips) {
|
|
5193
|
-
let r = rect;
|
|
5194
|
-
for (const c of clips) {
|
|
5195
|
-
if (!r)
|
|
5196
|
-
return null;
|
|
5197
|
-
r = intersectRect(r, c);
|
|
5198
|
-
}
|
|
5199
|
-
return r;
|
|
5200
|
-
}
|
|
5201
|
-
const clipsX = (v) => v !== "visible";
|
|
5202
|
-
const scrollsX = (v) => v === "auto" || v === "scroll";
|
|
5203
|
-
/**
|
|
5204
|
-
* The ancestors that cut the element off: anything with overflow other than
|
|
5205
|
-
* visible on an axis. The body and the root scroll the page and are covered by
|
|
5206
|
-
* the viewport. Read once per target; their rectangles are read every frame.
|
|
5207
|
-
*/
|
|
5208
|
-
function clipAncestors(el) {
|
|
5209
|
-
const out = [];
|
|
5210
|
-
if (typeof getComputedStyle !== "function")
|
|
5211
|
-
return out;
|
|
5212
|
-
for (let n = el.parentElement; n && n !== document.body && n !== document.documentElement; n = n.parentElement) {
|
|
5213
|
-
if (n.hasAttribute(GUIDE_LAYER_ATTRIBUTE))
|
|
5214
|
-
break;
|
|
5215
|
-
const s = getComputedStyle(n);
|
|
5216
|
-
const x = clipsX(s.overflowX);
|
|
5217
|
-
const y = clipsX(s.overflowY);
|
|
5218
|
-
if (x || y)
|
|
5219
|
-
out.push({ el: n, x, y });
|
|
5220
|
-
if (s.position === "fixed")
|
|
5221
|
-
break;
|
|
5222
|
-
}
|
|
5223
|
-
return out;
|
|
5224
|
-
}
|
|
5225
|
-
/** An ancestor's clip as a rectangle: unbounded on an axis it does not clip. */
|
|
5226
|
-
function clipRectOf(c) {
|
|
5227
|
-
const r = c.el.getBoundingClientRect();
|
|
5228
|
-
return {
|
|
5229
|
-
x: c.x ? r.left : -INFINITE,
|
|
5230
|
-
y: c.y ? r.top : -INFINITE,
|
|
5231
|
-
width: c.x ? r.width : INFINITE * 2,
|
|
5232
|
-
height: c.y ? r.height : INFINITE * 2,
|
|
5233
|
-
};
|
|
5234
|
-
}
|
|
5235
|
-
function viewportRect() {
|
|
5236
|
-
const vv = typeof window !== "undefined" ? window.visualViewport : undefined;
|
|
5237
|
-
return {
|
|
5238
|
-
x: 0,
|
|
5239
|
-
y: vv ? vv.offsetTop : 0,
|
|
5240
|
-
width: window.innerWidth,
|
|
5241
|
-
height: vv ? vv.height : window.innerHeight,
|
|
5242
|
-
};
|
|
5243
|
-
}
|
|
5244
|
-
/**
|
|
5245
|
-
* The part of the element a person can see: its box cut by every scroll box
|
|
5246
|
-
* around it and by the viewport. The spotlight, its hole, the ring and the
|
|
5247
|
-
* hand use this, so a tab half out of a sideways-scrolling row of tabs is not
|
|
5248
|
-
* spotlit where it cannot be pressed. Null when none of it is on screen.
|
|
5249
|
-
*/
|
|
5250
|
-
function visibleRectOf(el, ancestors = clipAncestors(el)) {
|
|
5251
|
-
return visibleRect(rectOf(el), [...ancestors.map(clipRectOf), viewportRect()]);
|
|
5252
|
-
}
|
|
5253
|
-
/** Inside a box that scrolls sideways (with somewhere to scroll) that is itself on screen. */
|
|
5254
|
-
function inSidewaysScroller(el) {
|
|
5255
|
-
if (typeof getComputedStyle !== "function")
|
|
5256
|
-
return false;
|
|
5257
|
-
for (let n = el.parentElement; n && n !== document.body && n !== document.documentElement; n = n.parentElement) {
|
|
5258
|
-
const s = getComputedStyle(n);
|
|
5259
|
-
if (scrollsX(s.overflowX) && n.scrollWidth > n.clientWidth + 1) {
|
|
5260
|
-
const r = n.getBoundingClientRect();
|
|
5261
|
-
return r.width > 0 && r.right > 0 && r.left < window.innerWidth;
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
return false;
|
|
5265
|
-
}
|
|
5266
|
-
/**
|
|
5267
|
-
* How to bring a target into view, or null when it already is: to the middle
|
|
5268
|
-
* when it is above or below the comfortable band (under the header, at the
|
|
5269
|
-
* bottom edge), the nearest edge when only a side is cut off (a tab out of a
|
|
5270
|
-
* sideways-scrolling row, on a phone).
|
|
5271
|
-
*/
|
|
5272
|
-
function revealPlan(rect, visible, viewportHeight) {
|
|
5273
|
-
const offVertically = rect.y < 70 || rect.y + rect.height > viewportHeight - 20;
|
|
5274
|
-
const cutSideways = !visible || visible.width < rect.width - 1;
|
|
5275
|
-
if (!offVertically && !cutSideways)
|
|
5276
|
-
return null;
|
|
5277
|
-
return { block: offVertically ? "center" : "nearest", inline: "nearest" };
|
|
5278
|
-
}
|
|
5279
|
-
/** Room left beside a target scrolled into a sideways scroll box. */
|
|
5280
|
-
const SIDEWAYS_MARGIN = 12;
|
|
5281
|
-
/**
|
|
5282
|
-
* How far to scroll a sideways scroll box so the target sits inside its
|
|
5283
|
-
* visible part (`box`: the box cut by the viewport) with `margin` to spare on
|
|
5284
|
-
* both sides; 0 when it already does. Clamped to what the box can scroll.
|
|
5285
|
-
* A target wider than the room is aligned to its start.
|
|
5286
|
-
*/
|
|
5287
|
-
function sidewaysDelta(target, box, scrollLeft, maxScrollLeft, margin = SIDEWAYS_MARGIN) {
|
|
5288
|
-
const left = box.x + margin;
|
|
5289
|
-
const right = box.x + box.width - margin;
|
|
5290
|
-
let delta = 0;
|
|
5291
|
-
if (target.x < left || target.width > right - left)
|
|
5292
|
-
delta = target.x - left;
|
|
5293
|
-
else if (target.x + target.width > right)
|
|
5294
|
-
delta = target.x + target.width - right;
|
|
5295
|
-
const next = Math.min(Math.max(scrollLeft + delta, 0), Math.max(maxScrollLeft, 0));
|
|
5296
|
-
return next - scrollLeft;
|
|
5297
|
-
}
|
|
5298
|
-
/** The nearest ancestor that scrolls sideways and has somewhere to scroll. */
|
|
5299
|
-
function sidewaysScroller(el) {
|
|
5300
|
-
if (typeof getComputedStyle !== "function")
|
|
5301
|
-
return null;
|
|
5302
|
-
for (let n = el.parentElement; n && n !== document.body && n !== document.documentElement; n = n.parentElement) {
|
|
5303
|
-
if (scrollsX(getComputedStyle(n).overflowX) && n.scrollWidth > n.clientWidth + 1)
|
|
5304
|
-
return n;
|
|
5305
|
-
}
|
|
5306
|
-
return null;
|
|
5307
|
-
}
|
|
5308
|
-
/**
|
|
5309
|
-
* Scrolls the target into view (instant under reduced motion). In a box that
|
|
5310
|
-
* scrolls sideways (a row of tabs on a phone) the box is scrolled first,
|
|
5311
|
-
* leaving SIDEWAYS_MARGIN beside the target so its whole label shows; then
|
|
5312
|
-
* the page, up or down only.
|
|
5313
|
-
*/
|
|
5314
|
-
function revealTarget(el) {
|
|
5315
|
-
const behavior = prefersReducedMotion() ? "auto" : "smooth";
|
|
5316
|
-
const scroller = sidewaysScroller(el);
|
|
5317
|
-
if (scroller) {
|
|
5318
|
-
const box = intersectRect(rectOf(scroller), viewportRect()) ?? rectOf(scroller);
|
|
5319
|
-
const dx = sidewaysDelta(rectOf(el), box, scroller.scrollLeft, scroller.scrollWidth - scroller.clientWidth);
|
|
5320
|
-
// Instant: the page's own scroll below must not cancel it.
|
|
5321
|
-
if (Math.abs(dx) >= 1)
|
|
5322
|
-
scroller.scrollLeft += dx;
|
|
5323
|
-
}
|
|
5324
|
-
const vh = window.visualViewport?.height ?? window.innerHeight;
|
|
5325
|
-
const plan = revealPlan(rectOf(el), visibleRectOf(el), vh);
|
|
5326
|
-
if (!plan)
|
|
5327
|
-
return;
|
|
5328
|
-
try {
|
|
5329
|
-
el.scrollIntoView({ ...plan, behavior });
|
|
5330
|
-
}
|
|
5331
|
-
catch {
|
|
5332
|
-
el.scrollIntoView();
|
|
5333
|
-
}
|
|
5334
|
-
}
|
|
5335
|
-
/* ---------------- the scrim's holes, as one union ---------------- */
|
|
5336
|
-
/**
|
|
5337
|
-
* The scrim's blocking area: the screen (with a 10 px margin) minus the union
|
|
5338
|
-
* of the holes, as rectangles that do not overlap. Cutting each hole out with
|
|
5339
|
-
* an even-odd fill made the place where two holes overlap (a field and the
|
|
5340
|
-
* select list open over it) solid again, and the option there could not be
|
|
5341
|
-
* pressed.
|
|
5342
|
-
*
|
|
5343
|
-
* Every hole edge splits the screen into a grid; a cell is blocked when no
|
|
5344
|
-
* hole covers it. Cells in a row are joined, and identical rows stacked.
|
|
5345
|
-
*/
|
|
5346
|
-
function blockedRects(holes, width, height) {
|
|
5347
|
-
const x0 = -10;
|
|
5348
|
-
const y0 = -10;
|
|
5349
|
-
const x1 = width + 10;
|
|
5350
|
-
const y1 = height + 10;
|
|
5351
|
-
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
5352
|
-
const hs = holes
|
|
5353
|
-
.filter(h => h.width > 0 && h.height > 0)
|
|
5354
|
-
.map(h => ({
|
|
5355
|
-
l: clamp(h.x, x0, x1),
|
|
5356
|
-
t: clamp(h.y, y0, y1),
|
|
5357
|
-
r: clamp(h.x + h.width, x0, x1),
|
|
5358
|
-
b: clamp(h.y + h.height, y0, y1),
|
|
5359
|
-
}))
|
|
5360
|
-
.filter(h => h.r > h.l && h.b > h.t);
|
|
5361
|
-
if (!hs.length)
|
|
5362
|
-
return [{ x: x0, y: y0, width: x1 - x0, height: y1 - y0 }];
|
|
5363
|
-
const uniq = (v) => Array.from(new Set(v)).sort((a, b) => a - b);
|
|
5364
|
-
const xs = uniq([x0, x1, ...hs.flatMap(h => [h.l, h.r])]);
|
|
5365
|
-
const ys = uniq([y0, y1, ...hs.flatMap(h => [h.t, h.b])]);
|
|
5366
|
-
const out = [];
|
|
5367
|
-
let prev = null;
|
|
5368
|
-
for (let j = 0; j < ys.length - 1; j++) {
|
|
5369
|
-
const top = ys[j];
|
|
5370
|
-
const bottom = ys[j + 1];
|
|
5371
|
-
const cy = (top + bottom) / 2;
|
|
5372
|
-
const row = [];
|
|
5373
|
-
for (let i = 0; i < xs.length - 1; i++) {
|
|
5374
|
-
const left = xs[i];
|
|
5375
|
-
const right = xs[i + 1];
|
|
5376
|
-
const cx = (left + right) / 2;
|
|
5377
|
-
const covered = hs.some(h => cx > h.l && cx < h.r && cy > h.t && cy < h.b);
|
|
5378
|
-
if (covered)
|
|
5379
|
-
continue;
|
|
5380
|
-
const last = row[row.length - 1];
|
|
5381
|
-
if (last && last.x + last.width === left)
|
|
5382
|
-
last.width = right - last.x;
|
|
5383
|
-
else
|
|
5384
|
-
row.push({ x: left, y: top, width: right - left, height: bottom - top });
|
|
5385
|
-
}
|
|
5386
|
-
const key = row.map(r => `${r.x},${r.width}`).join("|");
|
|
5387
|
-
if (prev && prev.key === key) {
|
|
5388
|
-
for (const r of prev.rects)
|
|
5389
|
-
r.height += bottom - top;
|
|
5390
|
-
}
|
|
5391
|
-
else {
|
|
5392
|
-
out.push(...row);
|
|
5393
|
-
prev = { key, rects: row };
|
|
5394
|
-
}
|
|
5395
|
-
}
|
|
5396
|
-
return out;
|
|
5397
|
-
}
|
|
5398
|
-
|
|
5399
|
-
/**
|
|
5400
|
-
* The tour's stylesheet. The shell has no CSS pipeline and the apps only scan
|
|
5401
|
-
* its dist for Tailwind classes, which cannot carry keyframes; so the layer
|
|
5402
|
-
* brings its own sheet, namespaced `eg-`, drawn from the theme's tokens
|
|
5403
|
-
* (--primary carries each app's brand accent; light and dark follow).
|
|
5404
|
-
*/
|
|
5405
|
-
const GUIDE_CSS = `
|
|
5406
|
-
[data-erp-guide-layer]{position:fixed;inset:0;z-index:1000;pointer-events:none;font-family:inherit;color:var(--popover-foreground,#1c2634);
|
|
5407
|
-
--eg-scrim:rgba(12,20,34,.64);--eg-card:var(--popover,#fff);--eg-fg:var(--popover-foreground,#1c2634);
|
|
5408
|
-
--eg-muted:var(--muted-foreground,#6d7886);--eg-soft:var(--muted,#eef3f9);--eg-line:var(--border,#e8ecf1);
|
|
5409
|
-
--eg-primary:var(--primary,#3280dd);--eg-on-primary:var(--primary-foreground,#fff);
|
|
5410
|
-
--eg-tint:color-mix(in oklab,var(--eg-primary) 13%,var(--eg-card));--eg-strong:color-mix(in oklab,var(--eg-primary) 82%,#000);
|
|
5411
|
-
--eg-danger:var(--destructive,#d23b4b);--eg-ok:#1d9a5f;--eg-gold:#e6a417;
|
|
5412
|
-
--eg-shadow:0 18px 50px -12px rgba(16,32,64,.35),0 4px 12px rgba(16,32,64,.08);line-height:1.5;font-size:14px}
|
|
5413
|
-
[data-erp-guide-layer] *{box-sizing:border-box}
|
|
5414
|
-
[data-erp-guide-layer] button{font:inherit;color:inherit;cursor:pointer}
|
|
5415
|
-
.eg-i{pointer-events:auto}
|
|
5416
|
-
.eg-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
5417
|
-
.eg-scrim-svg{position:fixed;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible}
|
|
5418
|
-
.eg-scrim-svg .eg-scrim-fill{fill:var(--eg-scrim);pointer-events:none}
|
|
5419
|
-
.eg-scrim-svg .eg-scrim-hit{fill:transparent;pointer-events:all}
|
|
5420
|
-
.eg-scrim{position:fixed;inset:0;background:var(--eg-scrim);pointer-events:auto}
|
|
5421
|
-
.eg-scrim.eg-light{background:rgba(12,20,34,.45)}
|
|
5422
|
-
.eg-scrim.eg-faint{background:rgba(12,20,34,.35)}
|
|
5423
|
-
.eg-ring{position:fixed;border-radius:12px;pointer-events:none;box-shadow:0 0 0 3px #fff,0 0 0 6px var(--eg-primary)}
|
|
5424
|
-
.eg-ring.eg-move{transition:left .26s ease,top .26s ease,width .26s ease,height .26s ease}
|
|
5425
|
-
.eg-ring::after{content:"";position:absolute;inset:-6px;border-radius:15px;border:3px solid var(--eg-primary);animation:eg-pulse 1.6s ease-out infinite}
|
|
5426
|
-
.eg-ring.eg-flash::after{animation:eg-flash .5s ease 1}
|
|
5427
|
-
@keyframes eg-pulse{0%{opacity:.9;transform:scale(1)}100%{opacity:0;transform:scale(1.12)}}
|
|
5428
|
-
@keyframes eg-flash{0%,100%{opacity:1;transform:none}50%{opacity:.2}}
|
|
5429
|
-
.eg-hand{position:fixed;width:46px;height:46px;pointer-events:none;filter:drop-shadow(0 4px 6px rgba(0,0,0,.35));animation:eg-tap 1.1s ease-in-out infinite}
|
|
5430
|
-
.eg-hand svg{width:46px;height:46px;fill:#fff;stroke:#1c2634;stroke-width:1.4;stroke-linejoin:round;stroke-linecap:round}
|
|
5431
|
-
.eg-hand.eg-flip svg{transform:scaleY(-1)}
|
|
5432
|
-
@keyframes eg-tap{0%,100%{transform:translate(6px,8px)}50%{transform:translate(0,0)}}
|
|
5433
|
-
.eg-bubble{position:fixed;left:0;top:0;width:320px;background:var(--eg-card);color:var(--eg-fg);border-radius:14px;box-shadow:var(--eg-shadow);padding:14px 16px 12px;border-top:4px solid var(--eg-primary);outline:none;pointer-events:auto}
|
|
5434
|
-
.eg-bubble.eg-err{border-top-color:var(--eg-danger)}
|
|
5435
|
-
.eg-bubble.eg-nudge{animation:eg-nudge .38s ease}
|
|
5436
|
-
@keyframes eg-nudge{0%,100%{translate:0}20%{translate:-7px}40%{translate:6px}60%{translate:-4px}80%{translate:2px}}
|
|
5437
|
-
.eg-b-top{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:12px;color:var(--eg-muted)}
|
|
5438
|
-
.eg-b-top .eg-mis{font-weight:600;color:var(--eg-strong);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
5439
|
-
.eg-b-top .eg-cnt{white-space:nowrap;font-weight:600}
|
|
5440
|
-
.eg-pips{display:flex;gap:4px;margin:8px 0 10px}
|
|
5441
|
-
.eg-pips i{flex:1;height:4px;border-radius:2px;background:var(--eg-soft)}
|
|
5442
|
-
.eg-pips i.eg-d{background:var(--eg-primary)}
|
|
5443
|
-
.eg-pips i.eg-c{background:color-mix(in oklab,var(--eg-primary) 45%,var(--eg-card))}
|
|
5444
|
-
.eg-b-t{margin:0;font-size:16px;font-weight:600;line-height:1.45}
|
|
5445
|
-
.eg-b-w{margin:2px 0 0;font-size:13.5px;color:var(--eg-muted)}
|
|
5446
|
-
.eg-bubble.eg-err .eg-b-t{color:var(--eg-danger)}
|
|
5447
|
-
.eg-k{display:inline-block;background:var(--eg-tint);color:var(--eg-strong);border-radius:7px;padding:0 7px;font-weight:600}
|
|
5448
|
-
.eg-b-f{display:flex;align-items:center;justify-content:space-between;margin-top:12px;gap:8px}
|
|
5449
|
-
.eg-b-f .eg-btn{height:34px;padding:0 14px;font-size:13.5px}
|
|
5450
|
-
.eg-exit{border:0;background:none;color:var(--eg-muted);font-size:12.5px;padding:4px 0;text-decoration:underline;text-underline-offset:3px}
|
|
5451
|
-
.eg-exit:hover{color:var(--eg-fg)}
|
|
5452
|
-
.eg-arrow{position:absolute;width:14px;height:14px;background:var(--eg-card);transform:rotate(45deg);border-radius:2px}
|
|
5453
|
-
.eg-arrow.eg-top{background:var(--eg-primary)}
|
|
5454
|
-
.eg-bubble.eg-err .eg-arrow.eg-top{background:var(--eg-danger)}
|
|
5455
|
-
.eg-btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:40px;padding:0 16px;border-radius:10px;border:1px solid transparent;font-size:14px;font-weight:600;white-space:nowrap}
|
|
5456
|
-
.eg-btn:focus-visible,.eg-exit:focus-visible,.eg-chip:focus-visible,.eg-x:focus-visible{outline:2px solid var(--eg-primary);outline-offset:2px}
|
|
5457
|
-
.eg-primary{background:var(--eg-primary);color:var(--eg-on-primary)!important}
|
|
5458
|
-
.eg-primary:hover{background:var(--eg-strong)}
|
|
5459
|
-
.eg-primary[disabled]{opacity:.55;cursor:default}
|
|
5460
|
-
.eg-ghost{background:var(--eg-card);border-color:var(--eg-line)}
|
|
5461
|
-
.eg-ghost:hover{background:var(--eg-soft)}
|
|
5462
|
-
.eg-ghost[disabled]{opacity:.55;cursor:default}
|
|
5463
|
-
.eg-link{background:none;border:0;color:var(--eg-muted);font-weight:500;padding:0 6px;height:32px}
|
|
5464
|
-
.eg-link:hover{color:var(--eg-fg);text-decoration:underline}
|
|
5465
|
-
.eg-modal{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:min(440px,calc(100vw - 32px));max-height:calc(100vh - 32px);overflow:auto;background:var(--eg-card);color:var(--eg-fg);border-radius:20px;box-shadow:var(--eg-shadow);padding:28px 28px 22px;text-align:center;outline:none;pointer-events:auto}
|
|
5466
|
-
.eg-modal.eg-pop{animation:eg-pop .32s cubic-bezier(.2,.9,.3,1.3)}
|
|
5467
|
-
@keyframes eg-pop{from{opacity:0;transform:translate(-50%,-46%) scale(.94)}}
|
|
5468
|
-
.eg-modal h2{margin:6px 0 4px;font-size:22px;font-weight:700;letter-spacing:-.2px;line-height:1.3}
|
|
5469
|
-
.eg-modal .eg-sub{margin:0;color:var(--eg-muted);font-size:14.5px}
|
|
5470
|
-
.eg-eyebrow{margin:0;font-size:12.5px;font-weight:600;letter-spacing:.3px;color:var(--eg-strong)}
|
|
5471
|
-
.eg-actions{display:grid;gap:6px;margin-top:20px}
|
|
5472
|
-
.eg-actions .eg-btn{height:44px}
|
|
5473
|
-
.eg-badge{width:64px;height:64px;border-radius:18px;margin:0 auto 12px;display:grid;place-items:center;background:var(--eg-tint);color:var(--eg-strong)}
|
|
5474
|
-
.eg-badge svg.eg-ic{width:30px;height:30px}
|
|
5475
|
-
.eg-quests{list-style:none;padding:0;margin:18px 0 0;text-align:left;display:grid;gap:6px}
|
|
5476
|
-
.eg-quests li{display:flex;align-items:center;gap:12px;padding:9px 12px;border-radius:11px;background:var(--eg-soft);font-size:14px}
|
|
5477
|
-
.eg-quests li .eg-n{width:26px;height:26px;border-radius:50%;background:var(--eg-card);border:1.5px solid var(--eg-line);display:grid;place-items:center;font-size:12px;font-weight:700;color:var(--eg-muted);flex:none}
|
|
5478
|
-
.eg-quests li.eg-first{background:var(--eg-tint)}
|
|
5479
|
-
.eg-quests li.eg-first .eg-n{border-color:var(--eg-primary);color:var(--eg-strong)}
|
|
5480
|
-
.eg-quests li.eg-ok .eg-n{background:var(--eg-ok);border-color:var(--eg-ok);color:#fff}
|
|
5481
|
-
.eg-quests li .eg-n svg.eg-ic{width:15px;height:15px;stroke-width:3}
|
|
5482
|
-
.eg-quests li .eg-t{flex:1}
|
|
5483
|
-
.eg-quests li small{color:var(--eg-muted);font-size:12px;white-space:nowrap}
|
|
5484
|
-
.eg-modal.eg-confirm{text-align:left;width:min(380px,calc(100vw - 32px));padding:22px}
|
|
5485
|
-
.eg-modal.eg-confirm h2{font-size:18px;margin-top:0}
|
|
5486
|
-
.eg-modal.eg-confirm .eg-actions{grid-template-columns:1fr 1fr}
|
|
5487
|
-
.eg-medal{width:84px;height:84px;border-radius:50%;margin:4px auto 10px;display:grid;place-items:center;color:#fff;background:radial-gradient(circle at 35% 30%,#ffd666,var(--eg-gold));box-shadow:0 0 0 8px #fff4d6;animation:eg-stamp .5s cubic-bezier(.2,.9,.3,1.4) .1s both}
|
|
5488
|
-
.eg-medal svg.eg-ic{width:42px;height:42px;stroke-width:2.6}
|
|
5489
|
-
@keyframes eg-stamp{from{transform:scale(.3) rotate(-25deg);opacity:0}}
|
|
5490
|
-
.eg-prog{display:flex;align-items:center;gap:10px;margin-top:16px;font-size:13px;color:var(--eg-muted);font-weight:600}
|
|
5491
|
-
.eg-prog .eg-bar{flex:1;height:8px;border-radius:4px;background:var(--eg-soft);overflow:hidden}
|
|
5492
|
-
.eg-prog .eg-bar i{display:block;height:100%;background:var(--eg-primary);border-radius:4px;transition:width .9s cubic-bezier(.2,.8,.2,1) .35s}
|
|
5493
|
-
.eg-burst{position:absolute;left:50%;top:70px;width:0;height:0;pointer-events:none}
|
|
5494
|
-
.eg-burst span{position:absolute;width:8px;height:12px;border-radius:2px;opacity:0;animation:eg-conf 1.1s cubic-bezier(.15,.7,.3,1) forwards}
|
|
5495
|
-
@keyframes eg-conf{0%{opacity:1;transform:translate(0,0) rotate(0)}100%{opacity:0;transform:translate(var(--x),var(--y)) rotate(var(--r))}}
|
|
5496
|
-
.eg-card{position:fixed;left:50%;bottom:28px;transform:translateX(-50%);width:min(360px,calc(100vw - 32px));background:var(--eg-card);color:var(--eg-fg);border-radius:14px;box-shadow:var(--eg-shadow);padding:14px 16px;border-top:4px solid var(--eg-primary);pointer-events:auto;outline:none}
|
|
5497
|
-
.eg-card .eg-row{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:12px}
|
|
5498
|
-
.eg-loading{display:flex;align-items:center;gap:10px;font-weight:600}
|
|
5499
|
-
.eg-spin{width:18px;height:18px;border-radius:50%;border:2.5px solid var(--eg-soft);border-top-color:var(--eg-primary);animation:eg-spin .8s linear infinite;flex:none}
|
|
5500
|
-
@keyframes eg-spin{to{transform:rotate(360deg)}}
|
|
5501
|
-
.eg-chip{position:fixed;right:22px;bottom:22px;display:flex;align-items:center;gap:10px;height:48px;padding:0 18px 0 8px;border-radius:24px;border:1px solid var(--eg-line);background:var(--eg-card);color:var(--eg-fg);box-shadow:0 8px 24px -8px rgba(16,32,64,.3);font-weight:600;font-size:14px;pointer-events:auto}
|
|
5502
|
-
.eg-chip svg{width:34px;height:34px}
|
|
5503
|
-
.eg-chip.eg-hi{animation:eg-hi 1.2s ease 2}
|
|
5504
|
-
@keyframes eg-hi{50%{box-shadow:0 0 0 6px color-mix(in oklab,var(--eg-primary) 35%,transparent),0 8px 24px -8px rgba(16,32,64,.3)}}
|
|
5505
|
-
.eg-panel{position:fixed;right:22px;bottom:82px;width:360px;max-height:calc(100vh - 110px);overflow:auto;background:var(--eg-card);color:var(--eg-fg);border:1px solid var(--eg-line);border-radius:16px;box-shadow:var(--eg-shadow);outline:none;pointer-events:auto}
|
|
5506
|
-
.eg-panel-bd{display:none}
|
|
5507
|
-
.eg-q-h{display:flex;align-items:center;gap:10px;padding:16px 12px 4px 18px}
|
|
5508
|
-
.eg-q-h h2{margin:0;font-size:16px;font-weight:700;flex:1}
|
|
5509
|
-
.eg-q-h .eg-n{font-size:13px;color:var(--eg-muted);font-weight:600}
|
|
5510
|
-
.eg-x{width:34px;height:34px;border-radius:10px;border:0;background:none;display:grid;place-items:center;color:var(--eg-muted)}
|
|
5511
|
-
.eg-x:hover{background:var(--eg-soft)}
|
|
5512
|
-
.eg-x svg.eg-ic{width:18px;height:18px}
|
|
5513
|
-
.eg-panel .eg-prog{margin:6px 18px 8px}
|
|
5514
|
-
.eg-q-list{list-style:none;margin:0;padding:4px 10px 6px;display:grid;gap:2px}
|
|
5515
|
-
.eg-q-item{display:flex;align-items:center;gap:12px;padding:10px 8px;border-radius:11px}
|
|
5516
|
-
.eg-q-item.eg-next{background:var(--eg-tint)}
|
|
5517
|
-
.eg-q-item .eg-n{width:30px;height:30px;border-radius:50%;border:1.5px solid var(--eg-line);display:grid;place-items:center;font-size:12.5px;font-weight:700;color:var(--eg-muted);flex:none;background:var(--eg-card)}
|
|
5518
|
-
.eg-q-item.eg-next .eg-n{border-color:var(--eg-primary);color:var(--eg-strong)}
|
|
5519
|
-
.eg-q-item.eg-done .eg-n{background:var(--eg-ok);border-color:var(--eg-ok);color:#fff}
|
|
5520
|
-
.eg-q-item.eg-done .eg-n svg.eg-ic{width:16px;height:16px;stroke-width:3}
|
|
5521
|
-
.eg-q-item.eg-dim .eg-n{opacity:.55}
|
|
5522
|
-
.eg-q-item.eg-just .eg-n{animation:eg-stamp .55s cubic-bezier(.2,.9,.3,1.4) .2s both}
|
|
5523
|
-
.eg-q-item .eg-t{flex:1;min-width:0}
|
|
5524
|
-
.eg-q-item .eg-t b{display:block;font-size:14px;font-weight:600}
|
|
5525
|
-
.eg-q-item.eg-done .eg-t b{color:var(--eg-muted)}
|
|
5526
|
-
.eg-q-item .eg-t small{display:block;font-size:12px;color:var(--eg-muted)}
|
|
5527
|
-
.eg-q-item .eg-t small.eg-sk{color:#b06a00}
|
|
5528
|
-
.eg-q-item .eg-t small.eg-lock{color:var(--eg-fg);font-weight:500}
|
|
5529
|
-
.eg-q-item .eg-btn{height:32px;padding:0 12px;font-size:13px}
|
|
5530
|
-
.eg-q-acts{display:flex;flex-direction:column;align-items:flex-end;gap:2px}
|
|
5531
|
-
.eg-q-acts .eg-link{height:22px;font-size:12px;padding:0 2px}
|
|
5532
|
-
.eg-q-f{border-top:1px solid var(--eg-line);padding:8px 12px;display:flex;justify-content:flex-end}
|
|
5533
|
-
.eg-toast{position:fixed;left:50%;bottom:84px;transform:translateX(-50%);background:#1c2634;color:#fff;padding:10px 16px;border-radius:10px;font-size:13.5px;box-shadow:var(--eg-shadow);max-width:calc(100vw - 32px);pointer-events:none}
|
|
5534
|
-
svg.eg-ic{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
|
|
5535
|
-
@media (max-width:767px){
|
|
5536
|
-
.eg-bubble{width:auto}
|
|
5537
|
-
.eg-arrow{display:none}
|
|
5538
|
-
.eg-modal{top:auto;bottom:12px;transform:translateX(-50%);width:calc(100vw - 24px);padding:24px 20px 18px}
|
|
5539
|
-
.eg-modal.eg-pop{animation:eg-up .3s cubic-bezier(.2,.9,.3,1.1)}
|
|
5540
|
-
.eg-modal .eg-actions .eg-btn{height:46px}
|
|
5541
|
-
.eg-chip{right:16px;bottom:calc(16px + env(safe-area-inset-bottom))}
|
|
5542
|
-
.eg-panel-bd{display:block;position:fixed;inset:0;background:rgba(15,23,42,.38);pointer-events:auto}
|
|
5543
|
-
.eg-panel{left:0;right:0;bottom:0;width:100%;max-height:85vh;border-radius:18px 18px 0 0;padding-bottom:env(safe-area-inset-bottom)}
|
|
5544
|
-
.eg-q-item{padding:12px 8px}
|
|
5545
|
-
.eg-card{bottom:calc(12px + env(safe-area-inset-bottom))}
|
|
5546
|
-
.eg-toast{bottom:calc(76px + env(safe-area-inset-bottom))}
|
|
5547
|
-
}
|
|
5548
|
-
@keyframes eg-up{from{opacity:0;transform:translate(-50%,30px)}}
|
|
5549
|
-
@media (prefers-reduced-motion:reduce){
|
|
5550
|
-
[data-erp-guide-layer] *,[data-erp-guide-layer] *::before,[data-erp-guide-layer] *::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important}
|
|
5551
|
-
.eg-ring::after{animation:none!important;opacity:1;transform:none}
|
|
5552
|
-
.eg-ring.eg-flash::after{animation:eg-flash .5s ease 1!important;animation-duration:.5s!important}
|
|
5553
|
-
.eg-hand{animation:none!important;transform:translate(4px,6px)}
|
|
5554
|
-
.eg-burst{display:none}
|
|
5555
|
-
.eg-bubble.eg-nudge{animation:none!important;border-top-color:var(--eg-danger)}
|
|
5556
|
-
}
|
|
5557
|
-
`;
|
|
5558
|
-
|
|
5559
|
-
/* ------------------------------------------------------------------ */
|
|
5560
|
-
/* Bits */
|
|
5561
|
-
/* ------------------------------------------------------------------ */
|
|
5562
|
-
const TH_MONTHS = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."];
|
|
5563
|
-
const pad2 = (n) => String(n).padStart(2, "0");
|
|
5564
|
-
/** "26 ต.ค. 2569 13:04" — day, month, Buddhist year, 24 h. */
|
|
5565
|
-
function formatThaiDateTime(iso) {
|
|
5566
|
-
if (!iso)
|
|
5567
|
-
return "";
|
|
5568
|
-
const d = new Date(iso);
|
|
5569
|
-
if (Number.isNaN(d.getTime()))
|
|
5570
|
-
return "";
|
|
5571
|
-
return `${d.getDate()} ${TH_MONTHS[d.getMonth()]} ${d.getFullYear() + 543} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
5572
|
-
}
|
|
5573
|
-
/** "กด [บันทึก]": the bracketed word is a chip in the brand colour. */
|
|
5574
|
-
function GuideTitle({ text }) {
|
|
5575
|
-
const parts = text.split(/(\[[^\]]+\])/g).filter(Boolean);
|
|
5576
|
-
return (jsx(Fragment$1, { children: parts.map((p, i) => p.startsWith("[") && p.endsWith("]") ? (jsx("span", { className: "eg-k", children: p.slice(1, -1) }, i)) : (jsx(React.Fragment, { children: p }, i))) }));
|
|
5577
|
-
}
|
|
5578
|
-
const Svg = ({ children, className = "eg-ic" }) => (jsx("svg", { className: className, viewBox: "0 0 24 24", "aria-hidden": "true", children: children }));
|
|
5579
|
-
const IconCheck = () => (jsx(Svg, { children: jsx("path", { d: "M20 6 9 17l-5-5" }) }));
|
|
5580
|
-
const IconX = () => (jsx(Svg, { children: jsx("path", { d: "M18 6 6 18M6 6l12 12" }) }));
|
|
5581
|
-
const IconFlag = () => (jsxs(Svg, { children: [jsx("path", { d: "M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z" }), jsx("path", { d: "M4 22v-7" })] }));
|
|
5582
|
-
const IconTrophy = () => (jsx(Svg, { children: jsx("path", { d: "M6 9H4.5a2.5 2.5 0 0 1 0-5H6M18 9h1.5a2.5 2.5 0 0 0 0-5H18M4 22h16M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22M18 2H6v7a6 6 0 0 0 12 0V2Z" }) }));
|
|
5583
|
-
const HAND_PATH = "M18 11V9.5a2 2 0 0 0-4 0V9a2 2 0 0 0-4 0v.5V4a2 2 0 0 0-4 0v10l-1.6-1.6a2 2 0 0 0-2.83 2.83l3.6 3.6C6.66 20.3 8.6 22 11.5 22H14a8 8 0 0 0 8-8v-3a2 2 0 0 0-4 0z";
|
|
5584
|
-
/** Rounded-rectangle subpath for the scrim's holes. */
|
|
5585
|
-
function roundRect(r, radius) {
|
|
5586
|
-
const rad = Math.max(0, Math.min(radius, r.width / 2, r.height / 2));
|
|
5587
|
-
const { x, y, width: w, height: h } = r;
|
|
5588
|
-
return (`M${x + rad} ${y}H${x + w - rad}A${rad} ${rad} 0 0 1 ${x + w} ${y + rad}` +
|
|
5589
|
-
`V${y + h - rad}A${rad} ${rad} 0 0 1 ${x + w - rad} ${y + h}` +
|
|
5590
|
-
`H${x + rad}A${rad} ${rad} 0 0 1 ${x} ${y + h - rad}` +
|
|
5591
|
-
`V${y + rad}A${rad} ${rad} 0 0 1 ${x + rad} ${y}Z`);
|
|
5592
|
-
}
|
|
5593
|
-
const rectPath = (r) => `M${r.x} ${r.y}H${r.x + r.width}V${r.y + r.height}H${r.x}Z`;
|
|
5594
|
-
/**
|
|
5595
|
-
* The dim layer that eats every press outside the holes. The holes are a
|
|
5596
|
-
* union: where two overlap (a field and the select list open over it) the
|
|
5597
|
-
* page stays open.
|
|
5598
|
-
*
|
|
5599
|
-
* - The look: one rectangle masked by the rounded holes (a mask adds holes
|
|
5600
|
-
* up, so an overlap is not filled back in).
|
|
5601
|
-
* - The presses: a transparent path made of the screen minus the holes, as
|
|
5602
|
-
* rectangles that do not overlap (blockedRects). A press inside a hole
|
|
5603
|
-
* reaches the page underneath; any other lands on the path (marked
|
|
5604
|
-
* data-eg-block) and is cancelled.
|
|
5605
|
-
* - `open`: the holes a press may go through, when not all of them (a "view"
|
|
5606
|
-
* step's target is shown but not pressable). Default: every hole.
|
|
5607
|
-
*/
|
|
5608
|
-
function Scrim({ holes, open, width, height }) {
|
|
5609
|
-
const maskId = "eg-scrim-mask-" + React.useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
5610
|
-
const block = blockedRects(open ?? holes, width, height).map(rectPath).join("");
|
|
5611
|
-
return (jsxs("svg", { className: "eg-scrim-svg", width: width, height: height, "aria-hidden": "true", children: [holes.length ? (jsx("defs", { children: jsxs("mask", { id: maskId, maskUnits: "userSpaceOnUse", x: -10, y: -10, width: width + 20, height: height + 20, children: [jsx("rect", { x: -10, y: -10, width: width + 20, height: height + 20, fill: "#fff" }), holes.map((h, i) => (jsx("path", { d: roundRect(h, 12), fill: "#000" }, i)))] }) })) : null, jsx("rect", { className: "eg-scrim-fill", x: -10, y: -10, width: width + 20, height: height + 20, mask: holes.length ? `url(#${maskId})` : undefined }), jsx("path", { className: "eg-scrim-hit", d: block, "data-eg-block": "" })] }));
|
|
5612
|
-
}
|
|
5613
|
-
/** Whether two rectangles overlap. */
|
|
5614
|
-
const meets = (a, b) => !!intersectRect(a, b);
|
|
5615
|
-
/** The smallest rectangle around all of them. */
|
|
5616
|
-
function boundingRect(rs) {
|
|
5617
|
-
const x = Math.min(...rs.map(r => r.x));
|
|
5618
|
-
const y = Math.min(...rs.map(r => r.y));
|
|
5619
|
-
const right = Math.max(...rs.map(r => r.x + r.width));
|
|
5620
|
-
const bottom = Math.max(...rs.map(r => r.y + r.height));
|
|
5621
|
-
return { x, y, width: right - x, height: bottom - y };
|
|
5622
|
-
}
|
|
5623
|
-
/** Where the bubble may go, in order of preference. */
|
|
5624
|
-
const BUBBLE_PLACEMENTS = ["right", "bottom", "top", "left"];
|
|
5625
|
-
/**
|
|
5626
|
-
* The first placement (in BUBBLE_PLACEMENTS order) whose bubble is on screen,
|
|
5627
|
-
* off the target (with its open list), and off everything to keep clear;
|
|
5628
|
-
* failing that, the first that is only on screen and off the target; -1 when
|
|
5629
|
-
* none is.
|
|
5630
|
-
*/
|
|
5631
|
-
function pickPlacement(results, bw, bh, anchor, clear, bounds) {
|
|
5632
|
-
const box = (r) => ({ x: r.x, y: r.y, width: bw, height: bh });
|
|
5633
|
-
const fits = (b) => b.x >= bounds.x - 1 && b.y >= bounds.y - 1 && b.x + b.width <= bounds.x + bounds.width + 1 && b.y + b.height <= bounds.y + bounds.height + 1;
|
|
5634
|
-
const ok = results.map(r => {
|
|
5635
|
-
const b = box(r);
|
|
5636
|
-
return fits(b) && !meets(b, anchor);
|
|
5637
|
-
});
|
|
5638
|
-
const best = results.findIndex((r, i) => ok[i] && !clear.some(c => meets(box(r), c)));
|
|
5639
|
-
return best >= 0 ? best : ok.indexOf(true);
|
|
5640
|
-
}
|
|
5641
|
-
const BUBBLE_TITLE_ID = "eg-bubble-title";
|
|
5642
|
-
const BUBBLE_WHY_ID = "eg-bubble-why";
|
|
5643
|
-
function useNudge(nudge, ref) {
|
|
5644
|
-
const first = useRef(nudge);
|
|
5645
|
-
useEffect(() => {
|
|
5646
|
-
if (nudge === first.current)
|
|
5647
|
-
return;
|
|
5648
|
-
const el = ref.current;
|
|
5649
|
-
if (!el)
|
|
5650
|
-
return;
|
|
5651
|
-
el.classList.remove("eg-nudge");
|
|
5652
|
-
void el.offsetWidth;
|
|
5653
|
-
el.classList.add("eg-nudge");
|
|
5654
|
-
}, [nudge, ref]);
|
|
5655
|
-
}
|
|
5656
|
-
function StepLayer(p) {
|
|
5657
|
-
const { spot, phone, viewport } = p;
|
|
5658
|
-
const bubbleRef = useRef(null);
|
|
5659
|
-
const arrowRef = useRef(null);
|
|
5660
|
-
const ringRef = useRef(null);
|
|
5661
|
-
const [pos, setPos] = useState(null);
|
|
5662
|
-
useNudge(p.nudge, bubbleRef);
|
|
5663
|
-
// Flash the ring with each nudge too (a press outside the hole).
|
|
5664
|
-
const firstNudge = useRef(p.nudge);
|
|
5665
|
-
useEffect(() => {
|
|
5666
|
-
if (p.nudge === firstNudge.current)
|
|
5667
|
-
return;
|
|
5668
|
-
const el = ringRef.current;
|
|
5669
|
-
if (!el)
|
|
5670
|
-
return;
|
|
5671
|
-
el.classList.remove("eg-flash");
|
|
5672
|
-
void el.offsetWidth;
|
|
5673
|
-
el.classList.add("eg-flash");
|
|
5674
|
-
}, [p.nudge]);
|
|
5675
|
-
const showBubble = p.phase === "ready" && (!!spot || !p.hasTarget);
|
|
5676
|
-
const gap = p.showHand ? 34 : 14;
|
|
5677
|
-
const spotKey = spot ? `${spot.x}|${spot.y}|${spot.width}|${spot.height}` : "";
|
|
5678
|
-
const contentKey = `${p.bubble.title}|${p.bubble.why}|${p.bubble.error?.title ?? ""}|${p.bubble.showNext}`;
|
|
5679
|
-
// What the bubble sits beside: the target, with an open list over it (the
|
|
5680
|
-
// list is what the person is choosing from now). What it must not cover:
|
|
5681
|
-
// open lists, and the other anchors the step allows (a map step's
|
|
5682
|
-
// coordinate fields).
|
|
5683
|
-
const popoverList = p.popovers ?? [];
|
|
5684
|
-
const anchor = spot ? boundingRect([spot, ...popoverList.filter(o => meets(o, spot))]) : null;
|
|
5685
|
-
const clear = [...popoverList, ...p.holes];
|
|
5686
|
-
const anchorKey = anchor ? `${anchor.x}|${anchor.y}|${anchor.width}|${anchor.height}` : "";
|
|
5687
|
-
const clearKey = clear.map(r => `${r.x},${r.y},${r.width},${r.height}`).join(";");
|
|
5688
|
-
useLayoutEffect(() => {
|
|
5689
|
-
const el = bubbleRef.current;
|
|
5690
|
-
if (!el || !showBubble)
|
|
5691
|
-
return;
|
|
5692
|
-
const m = 16;
|
|
5693
|
-
if (!spot || !anchor) {
|
|
5694
|
-
// Nothing to point at: the middle of the screen (the bottom on a phone).
|
|
5695
|
-
const bw = el.offsetWidth;
|
|
5696
|
-
const bh = el.offsetHeight;
|
|
5697
|
-
setPos(phone
|
|
5698
|
-
? { left: m, top: viewport.offsetTop + viewport.height - bh - m, side: "dock" }
|
|
5699
|
-
: { left: (window.innerWidth - bw) / 2, top: viewport.offsetTop + (viewport.height - bh) / 2, side: "dock" });
|
|
5700
|
-
return;
|
|
5701
|
-
}
|
|
5702
|
-
if (phone) {
|
|
5703
|
-
// Docked to the top or the bottom of the screen, whichever covers less
|
|
5704
|
-
// of the target and its open list (target in the lower half: top).
|
|
5705
|
-
const vh = viewport.height;
|
|
5706
|
-
const oy = viewport.offsetTop;
|
|
5707
|
-
const bh = el.offsetHeight;
|
|
5708
|
-
const topT = oy + m + 4;
|
|
5709
|
-
const botT = oy + vh - bh - m;
|
|
5710
|
-
const { y, height: h } = anchor;
|
|
5711
|
-
const overlapTop = Math.max(0, topT + bh + 8 - y);
|
|
5712
|
-
const overlapBot = Math.max(0, y + h + gap - botT);
|
|
5713
|
-
const top = y + h / 2 > vh / 2
|
|
5714
|
-
? overlapTop <= overlapBot
|
|
5715
|
-
? topT
|
|
5716
|
-
: botT
|
|
5717
|
-
: overlapBot <= overlapTop
|
|
5718
|
-
? botT
|
|
5719
|
-
: topT;
|
|
5720
|
-
setPos({ left: m, top, side: "dock" });
|
|
5721
|
-
return;
|
|
5722
|
-
}
|
|
5723
|
-
let cancelled = false;
|
|
5724
|
-
const a = anchor;
|
|
5725
|
-
const ref = {
|
|
5726
|
-
getBoundingClientRect: () => ({
|
|
5727
|
-
x: a.x,
|
|
5728
|
-
y: a.y,
|
|
5729
|
-
left: a.x,
|
|
5730
|
-
top: a.y,
|
|
5731
|
-
width: a.width,
|
|
5732
|
-
height: a.height,
|
|
5733
|
-
right: a.x + a.width,
|
|
5734
|
-
bottom: a.y + a.height,
|
|
5735
|
-
}),
|
|
5736
|
-
};
|
|
5737
|
-
const at = (placement) => computePosition(ref, el, {
|
|
5738
|
-
strategy: "fixed",
|
|
5739
|
-
placement,
|
|
5740
|
-
middleware: [
|
|
5741
|
-
offset(placement.startsWith("bottom") ? gap : 14),
|
|
5742
|
-
shift({ padding: m }),
|
|
5743
|
-
...(arrowRef.current ? [arrow({ element: arrowRef.current, padding: 14 })] : []),
|
|
5744
|
-
],
|
|
5745
|
-
});
|
|
5746
|
-
Promise.all(BUBBLE_PLACEMENTS.map(at))
|
|
5747
|
-
.then(results => {
|
|
5748
|
-
if (cancelled)
|
|
5749
|
-
return;
|
|
5750
|
-
const bw = el.offsetWidth;
|
|
5751
|
-
const bh = el.offsetHeight;
|
|
5752
|
-
const bounds = { x: m, y: viewport.offsetTop + m, width: window.innerWidth - 2 * m, height: viewport.height - 2 * m };
|
|
5753
|
-
const i = pickPlacement(results, bw, bh, a, clear, bounds);
|
|
5754
|
-
if (i < 0) {
|
|
5755
|
-
// Nowhere beside it: the bottom-right corner.
|
|
5756
|
-
setPos({ left: window.innerWidth - bw - m, top: viewport.height + viewport.offsetTop - bh - m, side: "dock" });
|
|
5757
|
-
return;
|
|
5758
|
-
}
|
|
5759
|
-
const { x, y, placement, middlewareData } = results[i];
|
|
5760
|
-
const side = placement.split("-")[0];
|
|
5761
|
-
setPos({ left: x, top: y, side, ax: middlewareData.arrow?.x, ay: middlewareData.arrow?.y });
|
|
5762
|
-
})
|
|
5763
|
-
.catch(() => {
|
|
5764
|
-
if (!cancelled)
|
|
5765
|
-
setPos({ left: m, top: m, side: "dock" });
|
|
5766
|
-
});
|
|
5767
|
-
return () => {
|
|
5768
|
-
cancelled = true;
|
|
5769
|
-
};
|
|
5770
|
-
// The keys stand for spot, the lists, the holes and the bubble's size.
|
|
5771
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5772
|
-
}, [spotKey, anchorKey, clearKey, contentKey, phone, showBubble, gap, viewport.height, viewport.offsetTop]);
|
|
5773
|
-
const popovers = p.popovers ?? [];
|
|
5774
|
-
const covered = !!p.covered;
|
|
5775
|
-
const holes = [...(spot && !covered ? [spot] : []), ...popovers, ...p.holes];
|
|
5776
|
-
const openHoles = p.targetPressable === false ? [...popovers, ...p.holes] : holes;
|
|
5777
|
-
const ringShown = !!spot && p.phase === "ready" && !covered && !popovers.some(o => meets(o, spot));
|
|
5778
|
-
const hand = spot && p.showHand && p.phase === "ready" && !covered && !popovers.length ? handPosition(spot, viewport.height) : null;
|
|
5779
|
-
let arrowStyle;
|
|
5780
|
-
if (pos && pos.side !== "dock") {
|
|
5781
|
-
if (pos.side === "right")
|
|
5782
|
-
arrowStyle = { left: -7, top: pos.ay };
|
|
5783
|
-
else if (pos.side === "left")
|
|
5784
|
-
arrowStyle = { right: -7, top: pos.ay };
|
|
5785
|
-
else if (pos.side === "bottom")
|
|
5786
|
-
arrowStyle = { top: -9, left: pos.ax };
|
|
5787
|
-
else
|
|
5788
|
-
arrowStyle = { bottom: -7, left: pos.ax };
|
|
5789
|
-
}
|
|
5790
|
-
return (jsxs(Fragment$1, { children: [jsx(Scrim, { holes: p.phase === "ready" ? holes : [], open: p.phase === "ready" ? openHoles : [], width: viewport.width, height: Math.max(viewport.height + viewport.offsetTop, 0) }), spot && ringShown ? (jsx("div", { ref: ringRef, className: "eg-ring" + (p.moving ? " eg-move" : ""), style: { left: spot.x, top: spot.y, width: spot.width, height: spot.height }, "aria-hidden": "true" })) : null, hand ? (jsx("div", { className: "eg-hand" + (hand.flip ? " eg-flip" : ""), style: { left: hand.left, top: hand.top }, "aria-hidden": "true", children: jsx("svg", { viewBox: "0 0 24 24", children: jsx("path", { d: HAND_PATH }) }) })) : null, showBubble ? (jsxs("div", { ref: bubbleRef, className: "eg-bubble" + (p.bubble.error ? " eg-err" : ""), role: "dialog", "aria-modal": "false", "aria-labelledby": BUBBLE_TITLE_ID, "aria-describedby": BUBBLE_WHY_ID, tabIndex: -1, "data-eg-bubble": "", style: {
|
|
5791
|
-
left: pos?.left ?? 0,
|
|
5792
|
-
top: pos?.top ?? 0,
|
|
5793
|
-
width: phone ? viewport.width - 32 : undefined,
|
|
5794
|
-
visibility: pos ? "visible" : "hidden",
|
|
5795
|
-
}, children: [jsx(BubbleBody, { ...p }), jsx("span", { ref: arrowRef, className: "eg-arrow" + (pos?.side === "bottom" ? " eg-top" : ""), style: arrowStyle ?? { display: "none" }, "aria-hidden": "true" })] })) : null, p.phase === "waiting" ? (jsxs("div", { className: "eg-card", role: "status", "data-eg-card": "", children: [jsxs("div", { className: "eg-loading", children: [jsx("span", { className: "eg-spin", "aria-hidden": "true" }), "\u0E01\u0E33\u0E25\u0E31\u0E07\u0E42\u0E2B\u0E25\u0E14\u2026"] }), jsx("div", { className: "eg-row", children: jsx("button", { type: "button", className: "eg-exit", onClick: p.onExit, children: p.bubble.replay ? "จบการทบทวน" : "ออกจากไกด์" }) })] })) : null, p.phase === "missing" ? (jsxs("div", { className: "eg-card eg-err", role: "alertdialog", "aria-labelledby": "eg-missing-t", "data-eg-card": "", tabIndex: -1, children: [jsx("p", { className: "eg-b-t", id: "eg-missing-t", children: "\u0E44\u0E21\u0E48\u0E1E\u0E1A\u0E2A\u0E48\u0E27\u0E19\u0E19\u0E35\u0E49\u0E1A\u0E19\u0E2B\u0E19\u0E49\u0E32" }), jsxs("div", { className: "eg-row", children: [jsx("button", { type: "button", className: "eg-exit", onClick: p.onExit, children: p.bubble.replay ? "จบการทบทวน" : "ออกจากไกด์" }), jsx("button", { type: "button", className: "eg-btn eg-primary", onClick: p.onRetry, children: "\u0E25\u0E2D\u0E07\u0E2D\u0E35\u0E01\u0E04\u0E23\u0E31\u0E49\u0E07" })] })] })) : null, p.phase === "away" ? (jsxs("div", { className: "eg-card", role: "dialog", "aria-modal": "false", "aria-labelledby": "eg-away-t", "data-eg-card": "", tabIndex: -1, children: [jsxs("div", { className: "eg-b-top", children: [jsxs("span", { className: "eg-mis", children: ["\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08 ", p.bubble.missionNo, " \u00B7 ", p.bubble.missionTitle, p.bubble.replay ? " (ทบทวน)" : ""] }), jsxs("span", { className: "eg-cnt", children: ["\u0E02\u0E31\u0E49\u0E19\u0E17\u0E35\u0E48 ", p.bubble.index + 1, "/", p.bubble.total] })] }), jsx("p", { className: "eg-b-t", id: "eg-away-t", style: { marginTop: 8 }, children: jsx(GuideTitle, { text: p.bubble.title }) }), jsxs("div", { className: "eg-row", children: [jsx("button", { type: "button", className: "eg-exit", onClick: p.onExit, children: p.bubble.replay ? "จบการทบทวน" : "ออกจากไกด์" }), jsx("button", { type: "button", className: "eg-btn eg-primary", onClick: p.onGoResume, children: "\u0E17\u0E33\u0E15\u0E48\u0E2D" })] })] })) : null, p.confirmExit ? (jsx(ConfirmModal, { title: "\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E44\u0E01\u0E14\u0E4C\u0E15\u0E2D\u0E19\u0E19\u0E35\u0E49?", line: "\u0E40\u0E1B\u0E34\u0E14\u0E15\u0E48\u0E2D\u0E44\u0E14\u0E49\u0E17\u0E35\u0E48\u0E1B\u0E38\u0E48\u0E21 ? \u0E21\u0E38\u0E21\u0E02\u0E27\u0E32\u0E1A\u0E19", leaveLabel: "\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E44\u0E01\u0E14\u0E4C", stayLabel: "\u0E17\u0E33\u0E15\u0E48\u0E2D", onLeave: p.onExitConfirm, onStay: p.onExitCancel })) : null] }));
|
|
5796
|
-
}
|
|
5797
|
-
function BubbleBody(p) {
|
|
5798
|
-
const b = p.bubble;
|
|
5799
|
-
const title = b.error ? b.error.title : b.title;
|
|
5800
|
-
const why = b.error ? (b.error.detail ?? "") : b.why;
|
|
5801
|
-
return (jsxs(Fragment$1, { children: [jsxs("div", { className: "eg-b-top", children: [jsxs("span", { className: "eg-mis", children: ["\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08 ", b.missionNo, " \u00B7 ", b.missionTitle, b.replay ? " (ทบทวน)" : ""] }), jsxs("span", { className: "eg-cnt", children: ["\u0E02\u0E31\u0E49\u0E19\u0E17\u0E35\u0E48 ", b.index + 1, "/", b.total] })] }), jsx("div", { className: "eg-pips", "aria-hidden": "true", children: Array.from({ length: b.total }, (_, i) => (jsx("i", { className: i < b.index ? "eg-d" : i === b.index ? "eg-c" : undefined }, i))) }), jsx("p", { className: "eg-b-t", id: BUBBLE_TITLE_ID, children: jsx(GuideTitle, { text: title }) }), jsx("p", { className: "eg-b-w", id: BUBBLE_WHY_ID, hidden: !why, children: jsx(GuideTitle, { text: why }) }), jsxs("div", { className: "eg-b-f", children: [jsx("button", { type: "button", className: "eg-exit", onClick: p.onExit, children: b.replay ? "จบการทบทวน" : "ออกจากไกด์" }), jsxs("span", { style: { display: "flex", gap: 6 }, children: [b.showEndWithoutSave ? (jsx("button", { type: "button", className: "eg-btn eg-ghost", onClick: p.onEndWithoutSave, children: "\u0E08\u0E1A\u0E42\u0E14\u0E22\u0E44\u0E21\u0E48\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01" })) : null, b.showNext ? (jsx("button", { type: "button", className: "eg-btn eg-primary", onClick: p.onNext, children: "\u0E16\u0E31\u0E14\u0E44\u0E1B" })) : null] })] })] }));
|
|
5802
|
-
}
|
|
5803
|
-
/** The fingertip at ≈62% across and down the target; upside down near the bottom. */
|
|
5804
|
-
function handPosition(spot, viewportHeight) {
|
|
5805
|
-
const { x, y, width: w, height: h } = spot;
|
|
5806
|
-
const px = x + Math.min(w * 0.62, w - 14);
|
|
5807
|
-
const py = y + h * 0.62;
|
|
5808
|
-
const flip = py + 50 > viewportHeight;
|
|
5809
|
-
return { left: px - 11.5, top: flip ? py - h * 0.3 - 42 : py - 4, flip };
|
|
5810
|
-
}
|
|
5811
|
-
/* ------------------------------------------------------------------ */
|
|
5812
|
-
/* Modals */
|
|
5813
|
-
/* ------------------------------------------------------------------ */
|
|
5814
|
-
function useAutoFocus() {
|
|
5815
|
-
const ref = useRef(null);
|
|
5816
|
-
useEffect(() => {
|
|
5817
|
-
ref.current?.focus({ preventScroll: true });
|
|
5818
|
-
}, []);
|
|
5819
|
-
return ref;
|
|
5820
|
-
}
|
|
5821
|
-
function ConfirmModal(p) {
|
|
5822
|
-
const stay = useAutoFocus();
|
|
5823
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-scrim eg-faint", "data-eg-block": "", onClick: p.onStay }), jsxs("div", { className: "eg-modal eg-confirm eg-pop", role: "alertdialog", "aria-modal": "true", "aria-labelledby": "eg-c-t", "aria-describedby": "eg-c-d", "data-eg-modal": "", children: [jsx("h2", { id: "eg-c-t", children: p.title }), jsx("p", { className: "eg-sub", id: "eg-c-d", style: { fontSize: 14 }, children: p.line }), jsxs("div", { className: "eg-actions", children: [jsx("button", { type: "button", className: "eg-btn eg-ghost", onClick: p.onLeave, children: p.leaveLabel }), jsx("button", { type: "button", ref: stay, className: "eg-btn eg-primary", onClick: p.onStay, children: p.stayLabel })] })] })] }));
|
|
5824
|
-
}
|
|
5825
|
-
function WelcomeModal(p) {
|
|
5826
|
-
const start = useAutoFocus();
|
|
5827
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-scrim", "data-eg-block": "" }), jsxs("div", { className: "eg-modal eg-pop", role: "dialog", "aria-modal": "true", "aria-labelledby": "eg-w-t", "data-eg-modal": "", tabIndex: -1, children: [jsx("div", { className: "eg-badge", children: jsx(IconFlag, {}) }), jsx("p", { className: "eg-eyebrow", children: "\u0E44\u0E01\u0E14\u0E4C\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" }), jsx("h2", { id: "eg-w-t", children: p.title }), p.subtitle ? jsx("p", { className: "eg-sub", children: p.subtitle }) : null, jsx("ol", { className: "eg-quests", children: p.missions.map((m, i) => (jsxs("li", { className: i === 0 ? "eg-first" : undefined, children: [jsx("span", { className: "eg-n", children: i + 1 }), jsx("span", { className: "eg-t", children: m.title }), jsxs("small", { children: [m.minutes, " \u0E19\u0E32\u0E17\u0E35"] })] }, i))) }), jsxs("div", { className: "eg-actions", children: [jsx("button", { type: "button", ref: start, className: "eg-btn eg-primary", onClick: p.onStart, children: "\u0E40\u0E23\u0E34\u0E48\u0E21\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08\u0E41\u0E23\u0E01" }), jsx("button", { type: "button", className: "eg-btn eg-link", onClick: p.onSkip, children: "\u0E02\u0E49\u0E32\u0E21\u0E44\u0E1B\u0E01\u0E48\u0E2D\u0E19" })] })] }), p.confirm ? (jsx(ConfirmModal, { title: "\u0E02\u0E49\u0E32\u0E21\u0E44\u0E01\u0E14\u0E4C\u0E44\u0E1B\u0E01\u0E48\u0E2D\u0E19?", line: "\u0E40\u0E1B\u0E34\u0E14\u0E15\u0E48\u0E2D\u0E44\u0E14\u0E49\u0E17\u0E35\u0E48\u0E1B\u0E38\u0E48\u0E21 ? \u0E21\u0E38\u0E21\u0E02\u0E27\u0E32\u0E1A\u0E19", leaveLabel: "\u0E02\u0E49\u0E32\u0E21\u0E44\u0E1B\u0E01\u0E48\u0E2D\u0E19", stayLabel: "\u0E40\u0E23\u0E34\u0E48\u0E21\u0E40\u0E25\u0E22", onLeave: p.onSkipConfirm, onStay: p.onSkipCancel })) : null] }));
|
|
5828
|
-
}
|
|
5829
|
-
function GateModal(p) {
|
|
5830
|
-
const go = useAutoFocus();
|
|
5831
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-scrim", "data-eg-block": "" }), jsxs("div", { className: "eg-modal eg-pop", role: "dialog", "aria-modal": "true", "aria-labelledby": "eg-g-t", "data-eg-modal": "", tabIndex: -1, children: [jsx("div", { className: "eg-badge", children: jsx(IconFlag, {}) }), jsx("p", { className: "eg-eyebrow", children: "\u0E44\u0E01\u0E14\u0E4C\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" }), jsx("h2", { id: "eg-g-t", children: p.title }), p.subtitle ? jsx("p", { className: "eg-sub", children: p.subtitle }) : null, jsxs("div", { className: "eg-actions", children: [jsx("a", { ref: go, className: "eg-btn eg-primary", href: p.href, style: { textDecoration: "none" }, children: p.actionLabel }), jsx("button", { type: "button", className: "eg-btn eg-link", onClick: p.onLater, children: "\u0E44\u0E27\u0E49\u0E17\u0E35\u0E2B\u0E25\u0E31\u0E07" })] })] })] }));
|
|
5832
|
-
}
|
|
5833
|
-
const CONFETTI_COLOURS = ["#3b82f6", "#7db7ff", "#e6a417", "#ff7a6b", "#1d9a5f", "#b0d2ff"];
|
|
5834
|
-
function Confetti({ reduced }) {
|
|
5835
|
-
// Fixed per mount, so a re-render does not throw new pieces.
|
|
5836
|
-
const [pieces] = useState(() => Array.from({ length: 26 }, (_, i) => {
|
|
5837
|
-
const a = (Math.PI * 2 * i) / 26 + Math.random() * 0.3;
|
|
5838
|
-
const dist = 90 + Math.random() * 90;
|
|
5839
|
-
return {
|
|
5840
|
-
background: CONFETTI_COLOURS[i % CONFETTI_COLOURS.length],
|
|
5841
|
-
"--x": `${Math.cos(a) * dist}px`,
|
|
5842
|
-
"--y": `${Math.sin(a) * dist + 40}px`,
|
|
5843
|
-
"--r": `${Math.random() * 540 - 270}deg`,
|
|
5844
|
-
animationDelay: `${Math.random() * 0.12}s`,
|
|
5845
|
-
};
|
|
5846
|
-
}));
|
|
5847
|
-
if (reduced)
|
|
5848
|
-
return null;
|
|
5849
|
-
return (jsx("div", { className: "eg-burst", "aria-hidden": "true", children: pieces.map((s, i) => (jsx("span", { style: s }, i))) }));
|
|
5850
|
-
}
|
|
5851
|
-
function ProgressBar({ from, to, total, label }) {
|
|
5852
|
-
const [width, setWidth] = useState(total ? (from / total) * 100 : 0);
|
|
5853
|
-
useEffect(() => {
|
|
5854
|
-
// Two frames so the bar is drawn at `from` before it runs to `to`.
|
|
5855
|
-
let raf2 = 0;
|
|
5856
|
-
const raf1 = requestAnimationFrame(() => {
|
|
5857
|
-
raf2 = requestAnimationFrame(() => setWidth(total ? (to / total) * 100 : 0));
|
|
5858
|
-
});
|
|
5859
|
-
return () => {
|
|
5860
|
-
cancelAnimationFrame(raf1);
|
|
5861
|
-
cancelAnimationFrame(raf2);
|
|
5862
|
-
};
|
|
5863
|
-
}, [to, total]);
|
|
5864
|
-
return (jsxs("div", { className: "eg-prog", children: [jsx("div", { className: "eg-bar", children: jsx("i", { style: { width: `${width}%` } }) }), jsx("span", { children: label })] }));
|
|
5865
|
-
}
|
|
5866
|
-
function CelebrateModal(p) {
|
|
5867
|
-
const primary = useAutoFocus();
|
|
5868
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-scrim eg-light", "data-eg-block": "" }), jsxs("div", { className: "eg-modal eg-pop", role: "dialog", "aria-modal": "true", "aria-labelledby": "eg-cel-t", "data-eg-modal": "", tabIndex: -1, children: [jsx(Confetti, { reduced: p.reduced }), jsx("div", { className: "eg-medal", children: jsx(IconCheck, {}) }), jsxs("p", { className: "eg-eyebrow", children: ["\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08 ", p.missionNo, " \u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08"] }), jsx("h2", { id: "eg-cel-t", children: p.title }), p.subtitle ? jsx("p", { className: "eg-sub", children: p.subtitle }) : null, jsx(ProgressBar, { from: p.reduced ? p.done : Math.max(0, p.done - 1), to: p.done, total: p.total, label: `${p.done}/${p.total} ภารกิจ` }), jsxs("div", { className: "eg-actions", children: [p.nextTitle ? (jsxs("button", { type: "button", ref: primary, className: "eg-btn eg-primary", onClick: p.onNext, children: ["\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08\u0E16\u0E31\u0E14\u0E44\u0E1B: ", p.nextTitle] })) : null, jsx("button", { type: "button", ref: p.nextTitle ? undefined : primary, className: "eg-btn eg-link", onClick: p.onRest, children: "\u0E1E\u0E31\u0E01\u0E01\u0E48\u0E2D\u0E19" })] })] })] }));
|
|
5869
|
-
}
|
|
5870
|
-
function CompleteModal(p) {
|
|
5871
|
-
const primary = useAutoFocus();
|
|
5872
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-scrim", "data-eg-block": "" }), jsxs("div", { className: "eg-modal eg-pop", role: "dialog", "aria-modal": "true", "aria-labelledby": "eg-f-t", "data-eg-modal": "", tabIndex: -1, children: [jsx(Confetti, { reduced: p.reduced }), jsx("div", { className: "eg-medal", children: jsx(IconTrophy, {}) }), jsxs("p", { className: "eg-eyebrow", children: ["\u0E04\u0E23\u0E1A ", p.total, " \u0E20\u0E32\u0E23\u0E01\u0E34\u0E08"] }), jsx("h2", { id: "eg-f-t", children: p.title }), p.subtitle ? jsx("p", { className: "eg-sub", children: p.subtitle }) : null, jsx("ol", { className: "eg-quests", children: p.missions.map((m, i) => (jsxs("li", { className: "eg-ok", children: [jsx("span", { className: "eg-n", children: jsx(IconCheck, {}) }), jsx("span", { className: "eg-t", children: m })] }, i))) }), jsxs("div", { className: "eg-actions", children: [jsx("button", { type: "button", ref: primary, className: "eg-btn eg-primary", onClick: p.onFinish, children: p.actionLabel }), p.secondary ? (jsx("a", { className: "eg-btn eg-ghost", href: p.secondary.href, style: { textDecoration: "none" }, children: p.secondary.label })) : null] })] })] }));
|
|
5873
|
-
}
|
|
5874
|
-
/* ------------------------------------------------------------------ */
|
|
5875
|
-
/* Quest chip and panel */
|
|
5876
|
-
/* ------------------------------------------------------------------ */
|
|
5877
|
-
function QuestChip({ done, total, pulse, onOpen }) {
|
|
5878
|
-
const ref = useRef(null);
|
|
5879
|
-
const first = useRef(pulse);
|
|
5880
|
-
useEffect(() => {
|
|
5881
|
-
if (pulse === first.current)
|
|
5882
|
-
return;
|
|
5883
|
-
const el = ref.current;
|
|
5884
|
-
if (!el)
|
|
5885
|
-
return;
|
|
5886
|
-
el.classList.remove("eg-hi");
|
|
5887
|
-
void el.offsetWidth;
|
|
5888
|
-
el.classList.add("eg-hi");
|
|
5889
|
-
}, [pulse]);
|
|
5890
|
-
const C = 2 * Math.PI * 14;
|
|
5891
|
-
const pct = total ? done / total : 0;
|
|
5892
|
-
return (jsxs("button", { ref: ref, type: "button", className: "eg-chip", onClick: onOpen, "aria-label": `ภารกิจเริ่มต้น เสร็จ ${done} จาก ${total}`, children: [jsxs("svg", { viewBox: "0 0 34 34", "aria-hidden": "true", children: [jsx("circle", { cx: "17", cy: "17", r: "14", fill: "none", stroke: "var(--eg-soft)", strokeWidth: "4" }), done ? (jsx("circle", { cx: "17", cy: "17", r: "14", fill: "none", stroke: "var(--eg-primary)", strokeWidth: "4", strokeLinecap: "round", strokeDasharray: `${C * pct} ${C}`, transform: "rotate(-90 17 17)" })) : null] }), "\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08 ", done, "/", total] }));
|
|
5893
|
-
}
|
|
5894
|
-
function QuestPanel(p) {
|
|
5895
|
-
const ref = useAutoFocus();
|
|
5896
|
-
return (jsxs(Fragment$1, { children: [jsx("div", { className: "eg-panel-bd", onClick: p.onClose }), jsxs("section", { ref: ref, className: "eg-panel", role: "dialog", "aria-labelledby": "eg-q-t", tabIndex: -1, "data-eg-panel": "", children: [jsxs("div", { className: "eg-q-h", children: [jsx("h2", { id: "eg-q-t", children: "\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" }), jsxs("span", { className: "eg-n", children: [p.done, "/", p.total] }), jsx("button", { type: "button", className: "eg-x", onClick: p.onClose, "aria-label": "\u0E1B\u0E34\u0E14", children: jsx(IconX, {}) })] }), jsx("div", { className: "eg-prog", children: jsx("div", { className: "eg-bar", children: jsx("i", { style: { width: `${p.total ? (p.done / p.total) * 100 : 0}%` } }) }) }), jsx("ol", { className: "eg-q-list", children: p.items.map((it, i) => (jsx(QuestRow, { item: it, n: i + 1, just: p.justDone === it.key, gate: p.gate, onStart: p.onStart, onDismiss: p.onDismiss }, it.key))) }), p.canHideChip ? (jsx("div", { className: "eg-q-f", children: jsx("button", { type: "button", className: "eg-btn eg-link", onClick: p.onHideChip, children: "\u0E0B\u0E48\u0E2D\u0E19\u0E1B\u0E38\u0E48\u0E21\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08" }) })) : null] })] }));
|
|
5897
|
-
}
|
|
5898
|
-
function QuestRow({ item, n, just, gate, onStart, onDismiss, }) {
|
|
5899
|
-
const v = item.view;
|
|
5900
|
-
const ticked = v === "done" || v === "already";
|
|
5901
|
-
const cls = "eg-q-item" +
|
|
5902
|
-
(ticked ? " eg-done" : v === "next" ? " eg-next" : "") +
|
|
5903
|
-
(v === "locked" || v === "waiting" ? " eg-dim" : "") +
|
|
5904
|
-
(just ? " eg-just" : "");
|
|
5905
|
-
let meta = `ประมาณ ${item.minutes} นาที`;
|
|
5906
|
-
if (v === "done")
|
|
5907
|
-
meta = item.completedAt ? `เสร็จ ${formatThaiDateTime(item.completedAt)}` : "เสร็จแล้ว";
|
|
5908
|
-
else if (v === "already")
|
|
5909
|
-
meta = "ทำไว้แล้ว";
|
|
5910
|
-
else if (v === "skipped")
|
|
5911
|
-
meta = jsx("span", { children: "\u0E02\u0E49\u0E32\u0E21\u0E44\u0E27\u0E49" });
|
|
5912
|
-
else if (v === "waiting" && gate)
|
|
5913
|
-
meta = gate.pending;
|
|
5914
|
-
// Locked: what to do first gets its own line under the title, so the title
|
|
5915
|
-
// keeps the row's width and the button stays short.
|
|
5916
|
-
const lockHint = v === "locked" && item.lockedBy ? `ทำ ${item.lockedBy} ก่อน` : null;
|
|
5917
|
-
let button;
|
|
5918
|
-
if (v === "done")
|
|
5919
|
-
button = jsx("button", { type: "button", className: "eg-btn eg-ghost", onClick: () => onStart(item.key, true), children: "\u0E17\u0E33\u0E0B\u0E49\u0E33" });
|
|
5920
|
-
else if (v === "already")
|
|
5921
|
-
button = jsx("button", { type: "button", className: "eg-btn eg-ghost", onClick: () => onStart(item.key, true), children: "\u0E14\u0E39\u0E27\u0E34\u0E18\u0E35\u0E17\u0E33" });
|
|
5922
|
-
else if (v === "waiting" && gate)
|
|
5923
|
-
button = (jsx("a", { className: "eg-btn eg-ghost", href: gate.href, style: { textDecoration: "none" }, children: gate.label }));
|
|
5924
|
-
else if (v === "locked")
|
|
5925
|
-
button = (jsx("button", { type: "button", className: "eg-btn eg-ghost", disabled: true, "aria-label": lockHint ? `เริ่ม (${lockHint})` : undefined, children: "\u0E40\u0E23\u0E34\u0E48\u0E21" }));
|
|
5926
|
-
else
|
|
5927
|
-
button = (jsx("button", { type: "button", className: "eg-btn " + (v === "next" ? "eg-primary" : "eg-ghost"), onClick: () => onStart(item.key, false), children: v === "skipped" || v === "active" ? "ทำต่อ" : "เริ่ม" }));
|
|
5928
|
-
const dismissable = item.optional && (v === "todo" || v === "next");
|
|
5929
|
-
return (jsxs("li", { className: cls, children: [jsx("span", { className: "eg-n", children: ticked ? jsx(IconCheck, {}) : n }), jsxs("div", { className: "eg-t", children: [jsx("b", { children: item.title }), lockHint ? jsx("small", { className: "eg-lock", children: lockHint }) : null, jsx("small", { className: v === "skipped" ? "eg-sk" : undefined, children: meta })] }), dismissable ? (jsxs("span", { className: "eg-q-acts", children: [button, jsx("button", { type: "button", className: "eg-btn eg-link", onClick: () => onDismiss(item.key), children: "\u0E44\u0E21\u0E48\u0E43\u0E0A\u0E49\u0E20\u0E32\u0E23\u0E01\u0E34\u0E08\u0E19\u0E35\u0E49" })] })) : (button)] }));
|
|
5930
|
-
}
|
|
5931
|
-
function GuideToast({ text }) {
|
|
5932
|
-
return (jsx("div", { className: "eg-toast", role: "status", children: text }));
|
|
5933
|
-
}
|
|
5934
|
-
|
|
5935
|
-
const EMPLOYEE_RECORD_REQUIRED = "EMPLOYEE_RECORD_REQUIRED";
|
|
5936
|
-
const EMPLOYEE_RECORD_REQUIRED_EVENT = "erp:employee-record-required";
|
|
5937
|
-
const EMPLOYEE_RECORD_OK_EVENT = "erp:employee-record-ok";
|
|
5938
|
-
/**
|
|
5939
|
-
* Shown when the API refuses every request because the signed-in account has
|
|
5940
|
-
* no employee record in this organisation.
|
|
5941
|
-
*
|
|
5942
|
-
* A gate rather than a banner. Leave, attendance, approvals and payslips all
|
|
5943
|
-
* identify a person by that record, so once the server started enforcing it
|
|
5944
|
-
* every call fails — and without something that says so, the app becomes a
|
|
5945
|
-
* screen of error toasts with no explanation and no way forward.
|
|
5946
|
-
*/
|
|
5947
|
-
function EmployeeRequiredGate({ platformBaseUrl, }) {
|
|
5948
|
-
const [blocked, setBlocked] = useState(false);
|
|
5949
|
-
const params = useParams();
|
|
5950
|
-
const code = params?.code ?? "";
|
|
5951
|
-
useEffect(() => {
|
|
5952
|
-
const onBlocked = () => setBlocked(true);
|
|
5953
|
-
const onOk = () => setBlocked(false);
|
|
5954
|
-
window.addEventListener(EMPLOYEE_RECORD_REQUIRED_EVENT, onBlocked);
|
|
5955
|
-
window.addEventListener(EMPLOYEE_RECORD_OK_EVENT, onOk);
|
|
5956
|
-
return () => {
|
|
5957
|
-
window.removeEventListener(EMPLOYEE_RECORD_REQUIRED_EVENT, onBlocked);
|
|
5958
|
-
window.removeEventListener(EMPLOYEE_RECORD_OK_EVENT, onOk);
|
|
5959
|
-
};
|
|
5960
|
-
}, []);
|
|
5961
|
-
if (!blocked)
|
|
5962
|
-
return null;
|
|
5963
|
-
const base = platformBaseUrl?.replace(/\/$/, "") ?? "";
|
|
5964
|
-
const createHref = code ? `${base}/${code}/employee/create` : `${base}/`;
|
|
5965
|
-
return (jsx("div", { className: "fixed inset-0 z-[100] flex items-center justify-center bg-background/95 p-6 backdrop-blur-sm", children: jsxs("div", { className: "w-full max-w-md space-y-5 text-center", children: [jsx(ContactRound, { className: "mx-auto h-12 w-12 text-muted-foreground" }), jsxs("div", { className: "space-y-2", children: [jsx("h1", { className: "text-lg font-semibold tracking-tight", children: "\u0E1A\u0E31\u0E0D\u0E0A\u0E35\u0E19\u0E35\u0E49\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49\u0E1C\u0E39\u0E01\u0E01\u0E31\u0E1A\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19" }), jsx("p", { className: "text-sm text-muted-foreground", children: "\u0E25\u0E32 \u0E25\u0E07\u0E40\u0E27\u0E25\u0E32 \u0E40\u0E1A\u0E34\u0E01\u0E40\u0E07\u0E34\u0E19 \u0E41\u0E25\u0E30\u0E01\u0E32\u0E23\u0E2D\u0E19\u0E38\u0E21\u0E31\u0E15\u0E34 \u0E23\u0E30\u0E1A\u0E38\u0E15\u0E31\u0E27\u0E04\u0E19\u0E08\u0E32\u0E01\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19 \u0E08\u0E36\u0E07\u0E22\u0E31\u0E07\u0E43\u0E0A\u0E49\u0E07\u0E32\u0E19\u0E43\u0E19\u0E2D\u0E07\u0E04\u0E4C\u0E01\u0E23\u0E19\u0E35\u0E49\u0E44\u0E21\u0E48\u0E44\u0E14\u0E49" })] }), jsxs("div", { className: "flex flex-wrap justify-center gap-2", children: [jsx(Button, { onClick: () => window.location.reload(), children: "\u0E25\u0E2D\u0E07\u0E43\u0E2B\u0E21\u0E48" }), jsx(Button, { variant: "outline", asChild: true, children: jsxs("a", { href: createHref, children: [jsx(UserPlus, { className: "mr-1 h-4 w-4" }), "\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E1E\u0E19\u0E31\u0E01\u0E07\u0E32\u0E19"] }) })] }), jsx("p", { className: "text-xs text-muted-foreground", children: "\u0E16\u0E49\u0E32\u0E04\u0E38\u0E13\u0E44\u0E21\u0E48\u0E21\u0E35\u0E2A\u0E34\u0E17\u0E18\u0E34\u0E4C\u0E41\u0E01\u0E49\u0E44\u0E02 \u0E43\u0E2B\u0E49\u0E41\u0E08\u0E49\u0E07\u0E1C\u0E39\u0E49\u0E14\u0E39\u0E41\u0E25\u0E2D\u0E07\u0E04\u0E4C\u0E01\u0E23" })] }) }));
|
|
5966
|
-
}
|
|
5967
|
-
|
|
5968
|
-
/* ------------------------------------------------------------------ */
|
|
5969
|
-
/* Fail-open wrappers */
|
|
5970
|
-
/* ------------------------------------------------------------------ */
|
|
5971
|
-
class GuideErrorBoundary extends React.Component {
|
|
5972
|
-
constructor() {
|
|
5973
|
-
super(...arguments);
|
|
5974
|
-
Object.defineProperty(this, "state", {
|
|
5975
|
-
enumerable: true,
|
|
5976
|
-
configurable: true,
|
|
5977
|
-
writable: true,
|
|
5978
|
-
value: { failed: false }
|
|
5979
|
-
});
|
|
5980
|
-
}
|
|
5981
|
-
static getDerivedStateFromError() {
|
|
5982
|
-
return { failed: true };
|
|
5983
|
-
}
|
|
5984
|
-
componentDidCatch(error) {
|
|
5985
|
-
if (typeof console !== "undefined")
|
|
5986
|
-
console.warn("[erp-shell guide] hidden after an error", error);
|
|
5987
|
-
try {
|
|
5988
|
-
publishGuideEntry(null, null);
|
|
5989
|
-
}
|
|
5990
|
-
catch {
|
|
5991
|
-
/* ignore */
|
|
5992
|
-
}
|
|
5993
|
-
}
|
|
5994
|
-
render() {
|
|
5995
|
-
return this.state.failed ? null : this.props.children;
|
|
5996
|
-
}
|
|
5997
|
-
}
|
|
5998
|
-
function GuideHost(props) {
|
|
5999
|
-
return (jsx(GuideErrorBoundary, { children: jsx(Suspense, { fallback: null, children: jsx(GuideHostInner, { ...props }) }) }));
|
|
6000
|
-
}
|
|
6001
|
-
let fallbackClient = null;
|
|
6002
|
-
function useShellQueryClient() {
|
|
6003
|
-
const provided = useContext(QueryClientContext);
|
|
6004
|
-
if (provided)
|
|
6005
|
-
return provided;
|
|
6006
|
-
fallbackClient ?? (fallbackClient = new QueryClient());
|
|
6007
|
-
return fallbackClient;
|
|
6008
|
-
}
|
|
6009
|
-
/* ------------------------------------------------------------------ */
|
|
6010
|
-
/* Session mirror (instant resume after F5) */
|
|
6011
|
-
/* ------------------------------------------------------------------ */
|
|
6012
|
-
const mirrorKey = (orgId, suite) => `erp-guide:${orgId}:${suite.key}`;
|
|
6013
|
-
function readMirror(orgId, suite) {
|
|
6014
|
-
try {
|
|
6015
|
-
const raw = sessionStorage.getItem(mirrorKey(orgId, suite));
|
|
6016
|
-
if (!raw)
|
|
6017
|
-
return null;
|
|
6018
|
-
const parsed = JSON.parse(raw);
|
|
6019
|
-
const row = parseRow(parsed);
|
|
6020
|
-
if (!row || row.guide_version !== suite.version)
|
|
6021
|
-
return null;
|
|
6022
|
-
return { ...row, server_status: parsed.server_status ?? null };
|
|
6023
|
-
}
|
|
6024
|
-
catch {
|
|
6025
|
-
return null;
|
|
6026
|
-
}
|
|
6027
|
-
}
|
|
6028
|
-
function writeMirror(orgId, suite, p) {
|
|
6029
|
-
try {
|
|
6030
|
-
sessionStorage.setItem(mirrorKey(orgId, suite), JSON.stringify(p));
|
|
6031
|
-
}
|
|
6032
|
-
catch {
|
|
6033
|
-
/* private mode: the server copy is enough */
|
|
6034
|
-
}
|
|
6035
|
-
}
|
|
6036
|
-
/* ------------------------------------------------------------------ */
|
|
6037
|
-
/* One tab at a time */
|
|
6038
|
-
/* ------------------------------------------------------------------ */
|
|
6039
|
-
/**
|
|
6040
|
-
* Whether this tab runs the tour. With two tabs open, the first holds a Web
|
|
6041
|
-
* Lock and the second shows nothing until the first goes away.
|
|
6042
|
-
*/
|
|
6043
|
-
function usePrimaryTab(name) {
|
|
6044
|
-
const [primary, setPrimary] = useState(false);
|
|
6045
|
-
useEffect(() => {
|
|
6046
|
-
const locks = (typeof navigator !== "undefined" ? navigator.locks : undefined);
|
|
6047
|
-
if (!locks?.request) {
|
|
6048
|
-
setPrimary(true);
|
|
6049
|
-
return;
|
|
6050
|
-
}
|
|
6051
|
-
const abort = new AbortController();
|
|
6052
|
-
let release = null;
|
|
6053
|
-
locks
|
|
6054
|
-
.request(name, { signal: abort.signal }, () => {
|
|
6055
|
-
setPrimary(true);
|
|
6056
|
-
return new Promise(resolve => {
|
|
6057
|
-
release = resolve;
|
|
6058
|
-
});
|
|
6059
|
-
})
|
|
6060
|
-
.catch(() => {
|
|
6061
|
-
/* aborted on unmount */
|
|
6062
|
-
});
|
|
6063
|
-
return () => {
|
|
6064
|
-
abort.abort();
|
|
6065
|
-
release?.();
|
|
6066
|
-
setPrimary(false);
|
|
6067
|
-
};
|
|
6068
|
-
}, [name]);
|
|
6069
|
-
return primary;
|
|
6070
|
-
}
|
|
6071
|
-
/* ------------------------------------------------------------------ */
|
|
6072
|
-
/* Putting the page back after a replay */
|
|
6073
|
-
/* ------------------------------------------------------------------ */
|
|
6074
|
-
const ABORT_DELAY_MS = 60;
|
|
6075
|
-
const ABORT_GAP_MS = 150;
|
|
6076
|
-
/**
|
|
6077
|
-
* Runs a replay's abort actions in order, once the tour has let go of the
|
|
6078
|
-
* page: press an anchor (passed over when it is not there), emit an app
|
|
6079
|
-
* event, or Escape to the open dialog (Radix listens on the document).
|
|
6080
|
-
*/
|
|
6081
|
-
function runAbort(actions) {
|
|
6082
|
-
actions.forEach((a, i) => {
|
|
6083
|
-
setTimeout(() => {
|
|
6084
|
-
try {
|
|
6085
|
-
if ("click" in a) {
|
|
6086
|
-
findAnchor(a.click)?.click();
|
|
6087
|
-
}
|
|
6088
|
-
else if ("event" in a) {
|
|
6089
|
-
emitGuideEvent(a.event);
|
|
6090
|
-
}
|
|
6091
|
-
else if ("escape" in a) {
|
|
6092
|
-
const t = document.activeElement ?? document.body;
|
|
6093
|
-
t.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: true, cancelable: true }));
|
|
6094
|
-
}
|
|
6095
|
-
}
|
|
6096
|
-
catch {
|
|
6097
|
-
/* never breaks the app */
|
|
6098
|
-
}
|
|
6099
|
-
}, ABORT_DELAY_MS + i * ABORT_GAP_MS);
|
|
6100
|
-
});
|
|
6101
|
-
}
|
|
6102
|
-
/** A step's own target takes presses: not on a "view" step, unless the step allows it. */
|
|
6103
|
-
function targetPressable(step, bridge) {
|
|
6104
|
-
if (!step || bridge)
|
|
6105
|
-
return true;
|
|
6106
|
-
if (stepKind(step) !== "view")
|
|
6107
|
-
return true;
|
|
6108
|
-
return !!step.target && (step.allow ?? []).includes(step.target);
|
|
6109
|
-
}
|
|
6110
|
-
/* ------------------------------------------------------------------ */
|
|
6111
|
-
/* Host */
|
|
6112
|
-
/* ------------------------------------------------------------------ */
|
|
6113
|
-
const TARGET_PAD = 6;
|
|
6114
|
-
const LOST_GRACE_MS = 350;
|
|
6115
|
-
const WAIT_MS = 8000;
|
|
6116
|
-
const WAIT_CAP_MS = 30000;
|
|
6117
|
-
const WELCOME_DELAY_MS = 500;
|
|
6118
|
-
const CELEBRATE_DELAY_MS = 450;
|
|
6119
|
-
const SAVE_DEBOUNCE_MS = 600;
|
|
3598
|
+
/** The shell's own queries (the tour's progress, the roles card) are not "the page loading". */
|
|
3599
|
+
const pageQuery = (q) => q.queryKey[0] !== "erp-shell";
|
|
6120
3600
|
function GuideHostInner({ config, organizationId, code }) {
|
|
6121
3601
|
const suite = config.suite;
|
|
6122
3602
|
const client = useShellQueryClient();
|
|
@@ -6125,8 +3605,6 @@ function GuideHostInner({ config, organizationId, code }) {
|
|
|
6125
3605
|
const search = searchParams?.toString() ?? "";
|
|
6126
3606
|
const router = useRouter();
|
|
6127
3607
|
const { open: sidebarOpen } = useSidebar();
|
|
6128
|
-
const fetching = useIsFetching({ predicate: q => q.queryKey[0] !== "erp-shell" }, client);
|
|
6129
|
-
const primary = usePrimaryTab(`erp-guide:${organizationId}:${suite.key}`);
|
|
6130
3608
|
// The shell's EmployeeRequiredGate is up: no tour over it.
|
|
6131
3609
|
const [employeeBlocked, setEmployeeBlocked] = useState(false);
|
|
6132
3610
|
useEffect(() => {
|
|
@@ -6139,808 +3617,26 @@ function GuideHostInner({ config, organizationId, code }) {
|
|
|
6139
3617
|
window.removeEventListener(EMPLOYEE_RECORD_OK_EVENT, off);
|
|
6140
3618
|
};
|
|
6141
3619
|
}, []);
|
|
6142
|
-
const
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
retry: false,
|
|
6149
|
-
refetchOnWindowFocus: false,
|
|
6150
|
-
}, client);
|
|
6151
|
-
const answer = query.data ?? null;
|
|
6152
|
-
const live = !!answer && answer.audience !== "none" && !answer.newerOnServer && primary && config.ready !== false && !employeeBlocked;
|
|
6153
|
-
/* ---------------- machine ---------------- */
|
|
6154
|
-
const [state, setState] = useState(null);
|
|
6155
|
-
const stateRef = useRef(null);
|
|
6156
|
-
// What the server holds (payloadKey), so a save that would change nothing
|
|
6157
|
-
// is not sent and does not bump its rev.
|
|
6158
|
-
const savedKey = useRef(null);
|
|
6159
|
-
useEffect(() => {
|
|
6160
|
-
if (!answer || answer.audience === "none" || answer.newerOnServer) {
|
|
6161
|
-
stateRef.current = null;
|
|
6162
|
-
setState(null);
|
|
6163
|
-
return;
|
|
6164
|
-
}
|
|
6165
|
-
if (stateRef.current)
|
|
6166
|
-
return;
|
|
6167
|
-
savedKey.current = answer.progress && answer.progress.rev > 0 ? payloadKey(answer.progress, suite.app) : null;
|
|
6168
|
-
// Resume from whichever copy is further along: the server's, or this
|
|
6169
|
-
// tab's session copy from before a refresh (its rev is the server's).
|
|
6170
|
-
const mirror = readMirror(organizationId, suite);
|
|
6171
|
-
let progress = answer.progress;
|
|
6172
|
-
if (mirror && furtherProgress(mirror, progress) === mirror)
|
|
6173
|
-
progress = mergeProgress(mirror, progress);
|
|
6174
|
-
const s = initialGuideState(answer.audience, progress);
|
|
6175
|
-
stateRef.current = s;
|
|
6176
|
-
setState(s);
|
|
6177
|
-
}, [answer, organizationId, suite]);
|
|
6178
|
-
// The latest page facts, read by the machine through env.
|
|
6179
|
-
const pageRef = useRef({ pathname, search, sidebarOpen, facts: config.facts ?? {}, can: config.can });
|
|
6180
|
-
pageRef.current = { pathname, search, sidebarOpen, facts: config.facts ?? {}, can: config.can };
|
|
6181
|
-
const targetElRef = useRef(null);
|
|
6182
|
-
const env = useCallback(() => {
|
|
6183
|
-
const pg = pageRef.current;
|
|
3620
|
+
const isBusy = useCallback(() => client.isFetching({ predicate: pageQuery }) > 0, [client]);
|
|
3621
|
+
// platform-api, with the GET answer kept in React Query as before 0.1.68
|
|
3622
|
+
// (fresh for 5 minutes, so a remount does not ask again; a failure is
|
|
3623
|
+
// kept too, and shows nothing).
|
|
3624
|
+
const progress = useMemo(() => {
|
|
3625
|
+
const platform = platformGuideProgress(organizationId);
|
|
6184
3626
|
return {
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
catch {
|
|
6194
|
-
return true;
|
|
6195
|
-
}
|
|
6196
|
-
},
|
|
6197
|
-
isVisible: (anchor, id) => anchorVisible(anchor, id),
|
|
6198
|
-
sidebarOpen: pg.sidebarOpen,
|
|
6199
|
-
targetValue: () => fieldValue(targetElRef.current),
|
|
6200
|
-
};
|
|
6201
|
-
}, [code]);
|
|
6202
|
-
/* ---------------- effects: save, announce, toast, navigate ---------------- */
|
|
6203
|
-
const [liveText, setLiveText] = useState("");
|
|
6204
|
-
const [toast, setToast] = useState(null);
|
|
6205
|
-
const toastTimer = useRef(null);
|
|
6206
|
-
const saveTimer = useRef(null);
|
|
6207
|
-
const saving = useRef(null);
|
|
6208
|
-
const savePending = useRef(false);
|
|
6209
|
-
const flushSave = useCallback(async () => {
|
|
6210
|
-
if (saveTimer.current) {
|
|
6211
|
-
clearTimeout(saveTimer.current);
|
|
6212
|
-
saveTimer.current = null;
|
|
6213
|
-
}
|
|
6214
|
-
if (saving.current) {
|
|
6215
|
-
savePending.current = true;
|
|
6216
|
-
return;
|
|
6217
|
-
}
|
|
6218
|
-
const run = async () => {
|
|
6219
|
-
do {
|
|
6220
|
-
savePending.current = false;
|
|
6221
|
-
const cur = stateRef.current;
|
|
6222
|
-
if (!cur)
|
|
6223
|
-
return;
|
|
6224
|
-
if (payloadKey(cur.progress, suite.app) === savedKey.current)
|
|
6225
|
-
continue;
|
|
6226
|
-
const row = await saveGuides(organizationId, suite, cur.progress);
|
|
6227
|
-
if (row)
|
|
6228
|
-
savedKey.current = payloadKey(row, suite.app);
|
|
6229
|
-
if (row && stateRef.current) {
|
|
6230
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
6231
|
-
dispatchRef.current({ type: "serverRow", progress: row });
|
|
6232
|
-
}
|
|
6233
|
-
} while (savePending.current);
|
|
6234
|
-
};
|
|
6235
|
-
saving.current = run().finally(() => {
|
|
6236
|
-
saving.current = null;
|
|
6237
|
-
});
|
|
6238
|
-
}, [organizationId, suite]);
|
|
6239
|
-
const runEffects = useCallback((effects) => {
|
|
6240
|
-
for (const e of effects) {
|
|
6241
|
-
try {
|
|
6242
|
-
if (e.type === "save") {
|
|
6243
|
-
if (stateRef.current)
|
|
6244
|
-
writeMirror(organizationId, suite, stateRef.current.progress);
|
|
6245
|
-
if (e.immediate)
|
|
6246
|
-
void flushSave();
|
|
6247
|
-
else {
|
|
6248
|
-
if (saveTimer.current)
|
|
6249
|
-
clearTimeout(saveTimer.current);
|
|
6250
|
-
saveTimer.current = setTimeout(() => void flushSave(), SAVE_DEBOUNCE_MS);
|
|
6251
|
-
}
|
|
6252
|
-
}
|
|
6253
|
-
else if (e.type === "announce") {
|
|
6254
|
-
setLiveText("");
|
|
6255
|
-
setTimeout(() => setLiveText(e.text), 60);
|
|
6256
|
-
}
|
|
6257
|
-
else if (e.type === "toast") {
|
|
6258
|
-
setToast(e.text);
|
|
6259
|
-
if (toastTimer.current)
|
|
6260
|
-
clearTimeout(toastTimer.current);
|
|
6261
|
-
toastTimer.current = setTimeout(() => setToast(null), 3200);
|
|
6262
|
-
}
|
|
6263
|
-
else if (e.type === "navigate") {
|
|
6264
|
-
if (/^https?:\/\//i.test(e.href))
|
|
6265
|
-
window.location.assign(e.href);
|
|
6266
|
-
else
|
|
6267
|
-
router.push(e.href);
|
|
6268
|
-
}
|
|
6269
|
-
else if (e.type === "abort") {
|
|
6270
|
-
// After this render takes the guard away, put the page back.
|
|
6271
|
-
runAbort(e.actions);
|
|
6272
|
-
}
|
|
6273
|
-
}
|
|
6274
|
-
catch {
|
|
6275
|
-
/* an effect never breaks the app */
|
|
6276
|
-
}
|
|
6277
|
-
}
|
|
6278
|
-
}, [flushSave, organizationId, router, suite]);
|
|
6279
|
-
const dispatch = useCallback((action) => {
|
|
6280
|
-
const cur = stateRef.current;
|
|
6281
|
-
if (!cur)
|
|
6282
|
-
return;
|
|
6283
|
-
let r;
|
|
6284
|
-
try {
|
|
6285
|
-
r = reduceGuide(cur, action, suite, env());
|
|
6286
|
-
}
|
|
6287
|
-
catch (err) {
|
|
6288
|
-
if (typeof console !== "undefined")
|
|
6289
|
-
console.warn("[erp-shell guide] stopped", err);
|
|
6290
|
-
stateRef.current = null;
|
|
6291
|
-
setState(null);
|
|
6292
|
-
return;
|
|
6293
|
-
}
|
|
6294
|
-
if (r.state !== cur) {
|
|
6295
|
-
stateRef.current = r.state;
|
|
6296
|
-
setState(r.state);
|
|
6297
|
-
}
|
|
6298
|
-
if (r.effects.length)
|
|
6299
|
-
runEffects(r.effects);
|
|
6300
|
-
}, [env, runEffects, suite]);
|
|
6301
|
-
const dispatchRef = useRef(dispatch);
|
|
6302
|
-
dispatchRef.current = dispatch;
|
|
6303
|
-
// Save what is pending when the page goes away.
|
|
6304
|
-
useEffect(() => {
|
|
6305
|
-
const flush = () => {
|
|
6306
|
-
if (saveTimer.current)
|
|
6307
|
-
void flushSave();
|
|
6308
|
-
};
|
|
6309
|
-
window.addEventListener("pagehide", flush);
|
|
6310
|
-
return () => {
|
|
6311
|
-
window.removeEventListener("pagehide", flush);
|
|
6312
|
-
flush();
|
|
6313
|
-
if (toastTimer.current)
|
|
6314
|
-
clearTimeout(toastTimer.current);
|
|
6315
|
-
};
|
|
6316
|
-
}, [flushSave]);
|
|
6317
|
-
/* ---------------- boot: resume, welcome ---------------- */
|
|
6318
|
-
const screen = state?.screen ?? { name: "idle" };
|
|
6319
|
-
const resumed = useRef(false);
|
|
6320
|
-
useEffect(() => {
|
|
6321
|
-
if (!live || !state || resumed.current)
|
|
6322
|
-
return;
|
|
6323
|
-
resumed.current = true;
|
|
6324
|
-
dispatch({ type: "resume" });
|
|
6325
|
-
}, [live, state, dispatch]);
|
|
6326
|
-
const welcomeRoutes = suite.welcomeRoutes ?? ["/[code]"];
|
|
6327
|
-
const onWelcomeRoute = welcomeRoutes.some(r => !!matchRoute(r, pathname, search, code));
|
|
6328
|
-
const due = !!state && live && welcomeDue(state, suite) && onWelcomeRoute && fetching === 0;
|
|
6329
|
-
const factsKey = useFactsKey(config.facts);
|
|
6330
|
-
useEffect(() => {
|
|
6331
|
-
if (!due)
|
|
6332
|
-
return;
|
|
6333
|
-
const t = setTimeout(() => dispatchRef.current({ type: "welcome" }), WELCOME_DELAY_MS);
|
|
6334
|
-
return () => clearTimeout(t);
|
|
6335
|
-
}, [due, factsKey]);
|
|
6336
|
-
/* ---------------- sync on route, sidebar, facts, DOM ---------------- */
|
|
6337
|
-
const inStep = live && screen.name === "step";
|
|
6338
|
-
useEffect(() => {
|
|
6339
|
-
if (inStep)
|
|
6340
|
-
dispatch({ type: "sync" });
|
|
6341
|
-
}, [inStep, pathname, search, sidebarOpen, factsKey, dispatch]);
|
|
6342
|
-
useEffect(() => {
|
|
6343
|
-
if (!inStep || typeof MutationObserver === "undefined")
|
|
6344
|
-
return;
|
|
6345
|
-
let raf = 0;
|
|
6346
|
-
const obs = new MutationObserver(records => {
|
|
6347
|
-
// Our own layer's changes are not the page's.
|
|
6348
|
-
if (records.every(r => inGuideLayer(r.target)))
|
|
6349
|
-
return;
|
|
6350
|
-
if (raf)
|
|
6351
|
-
return;
|
|
6352
|
-
raf = requestAnimationFrame(() => {
|
|
6353
|
-
raf = 0;
|
|
6354
|
-
dispatchRef.current({ type: "sync" });
|
|
6355
|
-
});
|
|
6356
|
-
});
|
|
6357
|
-
obs.observe(document.body, {
|
|
6358
|
-
childList: true,
|
|
6359
|
-
subtree: true,
|
|
6360
|
-
attributes: true,
|
|
6361
|
-
attributeFilter: ["data-state", "hidden", "aria-hidden", "class", "style", "open"],
|
|
6362
|
-
});
|
|
6363
|
-
return () => {
|
|
6364
|
-
obs.disconnect();
|
|
6365
|
-
if (raf)
|
|
6366
|
-
cancelAnimationFrame(raf);
|
|
6367
|
-
};
|
|
6368
|
-
}, [inStep]);
|
|
6369
|
-
/* ---------------- the current step ---------------- */
|
|
6370
|
-
const stepInfo = useMemo(() => {
|
|
6371
|
-
if (!state || screen.name !== "step")
|
|
6372
|
-
return null;
|
|
6373
|
-
const mission = findMission(suite, screen.mission);
|
|
6374
|
-
if (!mission)
|
|
6375
|
-
return null;
|
|
6376
|
-
const step = mission.steps[screen.index];
|
|
6377
|
-
if (!step)
|
|
6378
|
-
return null;
|
|
6379
|
-
const missionNo = suite.missions.indexOf(mission) + 1;
|
|
6380
|
-
return { mission, step, missionNo };
|
|
6381
|
-
}, [state, screen, suite]);
|
|
6382
|
-
const stepCtx = useMemo(() => {
|
|
6383
|
-
if (!state)
|
|
6384
|
-
return null;
|
|
6385
|
-
const e = env();
|
|
6386
|
-
const params = stepInfo?.step.route ? (matchRoute(stepInfo.step.route, e.pathname, e.search, code) ?? {}) : {};
|
|
6387
|
-
return guideContext(e, state.progress.context, params);
|
|
6388
|
-
// pathname/search/factsKey make it current.
|
|
6389
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6390
|
-
}, [state, stepInfo, env, code, pathname, search, factsKey]);
|
|
6391
|
-
const target = stepInfo && stepCtx && screen.name === "step"
|
|
6392
|
-
? spotlightTarget(stepInfo.step, stepCtx, screen.bridge)
|
|
6393
|
-
: null;
|
|
6394
|
-
const targetKey = target ? `${target.anchor}|${target.id ?? ""}` : "";
|
|
6395
|
-
const phase = screen.name === "step" ? screen.phase : null;
|
|
6396
|
-
const stepId = screen.name === "step" ? `${screen.mission}:${screen.index}:${screen.bridge ? "b" : ""}` : "";
|
|
6397
|
-
/* Measure every frame while a step is shown: the spotlight follows
|
|
6398
|
-
scrolling, dialogs animating in, the drawer sliding, the keyboard. */
|
|
6399
|
-
const [layout, setLayout] = useState({
|
|
6400
|
-
spot: null,
|
|
6401
|
-
covered: false,
|
|
6402
|
-
holes: [],
|
|
6403
|
-
popovers: [],
|
|
6404
|
-
vw: 0,
|
|
6405
|
-
vh: 0,
|
|
6406
|
-
oy: 0,
|
|
6407
|
-
});
|
|
6408
|
-
useEffect(() => {
|
|
6409
|
-
if (!inStep) {
|
|
6410
|
-
targetElRef.current = null;
|
|
6411
|
-
return;
|
|
6412
|
-
}
|
|
6413
|
-
let raf = 0;
|
|
6414
|
-
let lostSince = null;
|
|
6415
|
-
let last = { spot: null, covered: false, holes: [], popovers: [], vw: 0, vh: 0, oy: 0 };
|
|
6416
|
-
targetElRef.current = target ? findAnchor(target.anchor, target.id) : null;
|
|
6417
|
-
const allow = stepInfo?.step.allow ?? [];
|
|
6418
|
-
// The spotlight is the part of the target a person can see: cut by the
|
|
6419
|
-
// scroll boxes around it (a row of tabs that scrolls sideways) and the
|
|
6420
|
-
// viewport. Wholly out of view (scrolled away up or down), its own box,
|
|
6421
|
-
// and the tour scrolls it back.
|
|
6422
|
-
let clipFor = null;
|
|
6423
|
-
let clips = [];
|
|
6424
|
-
const spotOf = (el) => {
|
|
6425
|
-
if (el !== clipFor) {
|
|
6426
|
-
clipFor = el;
|
|
6427
|
-
clips = clipAncestors(el);
|
|
6428
|
-
}
|
|
6429
|
-
return padRect(visibleRectOf(el, clips) ?? rectOf(el), TARGET_PAD);
|
|
6430
|
-
};
|
|
6431
|
-
const tick = () => {
|
|
6432
|
-
raf = requestAnimationFrame(tick);
|
|
6433
|
-
const vv = window.visualViewport;
|
|
6434
|
-
const vw = window.innerWidth;
|
|
6435
|
-
const vh = vv ? vv.height : window.innerHeight;
|
|
6436
|
-
const oy = vv ? vv.offsetTop : 0;
|
|
6437
|
-
let el = targetElRef.current;
|
|
6438
|
-
if (target && (!el || !el.isConnected)) {
|
|
6439
|
-
el = findAnchor(target.anchor, target.id);
|
|
6440
|
-
targetElRef.current = el;
|
|
6441
|
-
}
|
|
6442
|
-
let spot = null;
|
|
6443
|
-
if (target && el && isPresent(el)) {
|
|
6444
|
-
lostSince = null;
|
|
6445
|
-
spot = spotOf(el);
|
|
6446
|
-
}
|
|
6447
|
-
else if (target) {
|
|
6448
|
-
// Maybe re-rendered under another node.
|
|
6449
|
-
const again = findAnchor(target.anchor, target.id);
|
|
6450
|
-
if (again) {
|
|
6451
|
-
targetElRef.current = again;
|
|
6452
|
-
spot = spotOf(again);
|
|
6453
|
-
lostSince = null;
|
|
6454
|
-
}
|
|
6455
|
-
else if (phase === "ready") {
|
|
6456
|
-
lostSince ?? (lostSince = performance.now());
|
|
6457
|
-
if (performance.now() - lostSince > LOST_GRACE_MS) {
|
|
6458
|
-
lostSince = null;
|
|
6459
|
-
dispatchRef.current({ type: "targetLost" });
|
|
6460
|
-
}
|
|
6461
|
-
}
|
|
6462
|
-
}
|
|
6463
|
-
if (phase === "waiting" && spot)
|
|
6464
|
-
dispatchRef.current({ type: "sync" });
|
|
6465
|
-
const popovers = [];
|
|
6466
|
-
for (const p of openPoppers())
|
|
6467
|
-
popovers.push(padRect(rectOf(p), 2));
|
|
6468
|
-
const holes = [];
|
|
6469
|
-
for (const a of allow) {
|
|
6470
|
-
const ael = findAnchor(a);
|
|
6471
|
-
if (ael)
|
|
6472
|
-
holes.push(padRect(rectOf(ael), TARGET_PAD));
|
|
6473
|
-
}
|
|
6474
|
-
const covered = !!spot && coveredByDialog(targetElRef.current);
|
|
6475
|
-
const next = { spot, covered, holes, popovers, vw, vh, oy };
|
|
6476
|
-
const sameList = (a, b) => a.length === b.length && a.every((h, i) => sameRect(h, b[i]));
|
|
6477
|
-
if (!sameRect(next.spot, last.spot) ||
|
|
6478
|
-
next.covered !== last.covered ||
|
|
6479
|
-
next.vw !== last.vw ||
|
|
6480
|
-
next.vh !== last.vh ||
|
|
6481
|
-
next.oy !== last.oy ||
|
|
6482
|
-
!sameList(next.holes, last.holes) ||
|
|
6483
|
-
!sameList(next.popovers, last.popovers)) {
|
|
6484
|
-
last = next;
|
|
6485
|
-
setLayout(next);
|
|
6486
|
-
}
|
|
6487
|
-
};
|
|
6488
|
-
raf = requestAnimationFrame(tick);
|
|
6489
|
-
return () => cancelAnimationFrame(raf);
|
|
6490
|
-
// stepId/targetKey/phase restart the loop for a new step.
|
|
6491
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6492
|
-
}, [inStep, stepId, targetKey, phase]);
|
|
6493
|
-
/* Waiting for the target: 8 s of not-loading time (30 s at most). */
|
|
6494
|
-
const fetchingRef = useRef(fetching);
|
|
6495
|
-
fetchingRef.current = fetching;
|
|
6496
|
-
useEffect(() => {
|
|
6497
|
-
if (!inStep || phase !== "waiting")
|
|
6498
|
-
return;
|
|
6499
|
-
let idle = 0;
|
|
6500
|
-
const started = Date.now();
|
|
6501
|
-
const timeout = stepInfo?.step.timeoutMs ?? WAIT_MS;
|
|
6502
|
-
const iv = setInterval(() => {
|
|
6503
|
-
if (fetchingRef.current === 0 && document.visibilityState !== "hidden")
|
|
6504
|
-
idle += 250;
|
|
6505
|
-
if (idle >= timeout || Date.now() - started >= WAIT_CAP_MS) {
|
|
6506
|
-
clearInterval(iv);
|
|
6507
|
-
dispatchRef.current({ type: "timeout" });
|
|
6508
|
-
}
|
|
6509
|
-
}, 250);
|
|
6510
|
-
return () => clearInterval(iv);
|
|
6511
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6512
|
-
}, [inStep, stepId, phase, screen.name === "step" ? screen.misses : 0]);
|
|
6513
|
-
/* On a step becoming ready: bring the target into view, focus, describe. */
|
|
6514
|
-
const readyKey = inStep && phase === "ready" ? stepId : "";
|
|
6515
|
-
useEffect(() => {
|
|
6516
|
-
if (!readyKey || !stepInfo || screen.name !== "step")
|
|
6517
|
-
return;
|
|
6518
|
-
const el = targetElRef.current ?? (target ? findAnchor(target.anchor, target.id) : null);
|
|
6519
|
-
if (el)
|
|
6520
|
-
revealTarget(el);
|
|
6521
|
-
const isInput = !screen.bridge && stepKind(stepInfo.step) === "input";
|
|
6522
|
-
const t = setTimeout(() => {
|
|
6523
|
-
if (isInput && el) {
|
|
6524
|
-
const f = fieldOf(el);
|
|
6525
|
-
f?.focus({ preventScroll: true });
|
|
6526
|
-
}
|
|
6527
|
-
else {
|
|
6528
|
-
const b = document.querySelector(`[${GUIDE_LAYER_ATTRIBUTE}] [data-eg-bubble]`);
|
|
6529
|
-
b?.focus({ preventScroll: true });
|
|
6530
|
-
}
|
|
6531
|
-
}, 30);
|
|
6532
|
-
// The target is described by the bubble while the step lasts.
|
|
6533
|
-
const described = el ? (isInput ? fieldOf(el) : el) : null;
|
|
6534
|
-
const prev = described?.getAttribute("aria-describedby") ?? null;
|
|
6535
|
-
if (described)
|
|
6536
|
-
described.setAttribute("aria-describedby", [BUBBLE_TITLE_ID, BUBBLE_WHY_ID, prev].filter(Boolean).join(" "));
|
|
6537
|
-
return () => {
|
|
6538
|
-
clearTimeout(t);
|
|
6539
|
-
if (!described)
|
|
6540
|
-
return;
|
|
6541
|
-
if (prev)
|
|
6542
|
-
described.setAttribute("aria-describedby", prev);
|
|
6543
|
-
else
|
|
6544
|
-
described.removeAttribute("aria-describedby");
|
|
6545
|
-
};
|
|
6546
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6547
|
-
}, [readyKey]);
|
|
6548
|
-
/* Signals from the page: API answers, app events, presses, typing. */
|
|
6549
|
-
useEffect(() => {
|
|
6550
|
-
if (!inStep || !stepInfo)
|
|
6551
|
-
return;
|
|
6552
|
-
const onApi = (e) => {
|
|
6553
|
-
const d = e.detail;
|
|
6554
|
-
if (!d || typeof d.status !== "number")
|
|
6555
|
-
return;
|
|
6556
|
-
dispatchRef.current({ type: "signal", signal: { kind: "api", method: d.method, path: d.path, status: d.status, id: d.id, message: d.message } });
|
|
6557
|
-
};
|
|
6558
|
-
window.addEventListener(API_EVENT, onApi);
|
|
6559
|
-
const names = triggersOf(stepInfo.step).flatMap(t => ("event" in t ? [t.event] : []));
|
|
6560
|
-
const onApp = (name) => (e) => dispatchRef.current({ type: "signal", signal: { kind: "event", name, detail: e.detail ?? undefined } });
|
|
6561
|
-
const appHandlers = names.map(n => [GUIDE_EVENT_PREFIX + n, onApp(n)]);
|
|
6562
|
-
appHandlers.forEach(([n, h]) => window.addEventListener(n, h));
|
|
6563
|
-
const inTarget = (node) => {
|
|
6564
|
-
const el = targetElRef.current;
|
|
6565
|
-
return !!el && node instanceof Node && el.contains(node);
|
|
6566
|
-
};
|
|
6567
|
-
// After the app has handled it, so what it does comes first.
|
|
6568
|
-
const later = (a) => setTimeout(() => dispatchRef.current(a), 0);
|
|
6569
|
-
const onPress = (e) => {
|
|
6570
|
-
if (inTarget(e.target))
|
|
6571
|
-
later({ type: "signal", signal: { kind: "activate" } });
|
|
6572
|
-
};
|
|
6573
|
-
const onKey = (e) => {
|
|
6574
|
-
if ((e.key === "Enter" || e.key === " ") && inTarget(e.target) && stepKind(stepInfo.step) !== "input") {
|
|
6575
|
-
later({ type: "signal", signal: { kind: "activate" } });
|
|
6576
|
-
}
|
|
6577
|
-
};
|
|
6578
|
-
const onInput = (e) => {
|
|
6579
|
-
if (!inTarget(e.target))
|
|
6580
|
-
return;
|
|
6581
|
-
dispatchRef.current({ type: "signal", signal: { kind: "typing" } });
|
|
6582
|
-
later({ type: "signal", signal: { kind: "value", value: fieldValue(targetElRef.current) } });
|
|
6583
|
-
};
|
|
6584
|
-
document.addEventListener("pointerup", onPress, true);
|
|
6585
|
-
document.addEventListener("keydown", onKey, true);
|
|
6586
|
-
document.addEventListener("input", onInput, true);
|
|
6587
|
-
document.addEventListener("change", onInput, true);
|
|
6588
|
-
return () => {
|
|
6589
|
-
window.removeEventListener(API_EVENT, onApi);
|
|
6590
|
-
appHandlers.forEach(([n, h]) => window.removeEventListener(n, h));
|
|
6591
|
-
document.removeEventListener("pointerup", onPress, true);
|
|
6592
|
-
document.removeEventListener("keydown", onKey, true);
|
|
6593
|
-
document.removeEventListener("input", onInput, true);
|
|
6594
|
-
document.removeEventListener("change", onInput, true);
|
|
6595
|
-
};
|
|
6596
|
-
}, [inStep, stepInfo]);
|
|
6597
|
-
/* ---------------- the guard ---------------- */
|
|
6598
|
-
const modalScreen = live && (screen.name === "welcome" || screen.name === "gate" || screen.name === "celebrate" || screen.name === "complete");
|
|
6599
|
-
const panelOpen = live && !!state?.panelOpen;
|
|
6600
|
-
const guarding = inStep || modalScreen;
|
|
6601
|
-
const guardingRef = useRef(guarding);
|
|
6602
|
-
guardingRef.current = guarding;
|
|
6603
|
-
const modalRef = useRef(false);
|
|
6604
|
-
modalRef.current = modalScreen || (screen.name === "step" && (screen.confirmExit || screen.phase !== "ready"));
|
|
6605
|
-
const stepInfoRef = useRef(stepInfo);
|
|
6606
|
-
stepInfoRef.current = stepInfo;
|
|
6607
|
-
useEffect(() => {
|
|
6608
|
-
if (!live)
|
|
6609
|
-
return;
|
|
6610
|
-
const allowedTarget = (node) => {
|
|
6611
|
-
if (!(node instanceof Node))
|
|
6612
|
-
return false;
|
|
6613
|
-
const el = targetElRef.current;
|
|
6614
|
-
// A "view" step's target is there to be read: ถัดไป is the way on.
|
|
6615
|
-
const sc = stateRef.current?.screen;
|
|
6616
|
-
const pressable = targetPressable(stepInfoRef.current?.step, sc?.name === "step" && sc.bridge);
|
|
6617
|
-
if (el && pressable && el.contains(node))
|
|
6618
|
-
return true;
|
|
6619
|
-
const elNode = node instanceof Element ? node : node.parentElement;
|
|
6620
|
-
if (!elNode)
|
|
6621
|
-
return false;
|
|
6622
|
-
if (elNode.closest(POPPER_SELECTOR) || elNode.closest(TOASTER_SELECTOR))
|
|
6623
|
-
return true;
|
|
6624
|
-
for (const a of stepInfoRef.current?.step.allow ?? []) {
|
|
6625
|
-
const ael = findAnchor(a);
|
|
6626
|
-
if (ael && ael.contains(node))
|
|
6627
|
-
return true;
|
|
6628
|
-
}
|
|
6629
|
-
return false;
|
|
6630
|
-
};
|
|
6631
|
-
const onPointer = (e) => {
|
|
6632
|
-
const t = e.target;
|
|
6633
|
-
if (inGuideLayer(t)) {
|
|
6634
|
-
// Our dim layer eats the press (and keeps focus where it is).
|
|
6635
|
-
if (t instanceof Element && t.closest("[data-eg-block]")) {
|
|
6636
|
-
e.preventDefault();
|
|
6637
|
-
if (e.type === "pointerdown")
|
|
6638
|
-
dispatchRef.current({ type: "blocked" });
|
|
6639
|
-
}
|
|
6640
|
-
// The app's open dialog or menu never hears the press (the click
|
|
6641
|
-
// itself goes on to our buttons).
|
|
6642
|
-
if (e.type !== "click")
|
|
6643
|
-
e.stopPropagation();
|
|
6644
|
-
return;
|
|
6645
|
-
}
|
|
6646
|
-
if (!guardingRef.current)
|
|
6647
|
-
return;
|
|
6648
|
-
if (modalRef.current || !allowedTarget(t)) {
|
|
6649
|
-
e.preventDefault();
|
|
6650
|
-
e.stopPropagation();
|
|
6651
|
-
if (e.type === "pointerdown")
|
|
6652
|
-
dispatchRef.current({ type: "blocked" });
|
|
6653
|
-
}
|
|
6654
|
-
};
|
|
6655
|
-
// Radix FocusScope pulls focus back into an open dialog; DismissableLayer
|
|
6656
|
-
// closes on focus outside. Neither may see focus moving to the tour.
|
|
6657
|
-
const onFocusIn = (e) => {
|
|
6658
|
-
if (inGuideLayer(e.target))
|
|
6659
|
-
e.stopPropagation();
|
|
6660
|
-
};
|
|
6661
|
-
const onFocusOut = (e) => {
|
|
6662
|
-
if (inGuideLayer(e.relatedTarget))
|
|
6663
|
-
e.stopPropagation();
|
|
6664
|
-
};
|
|
6665
|
-
const onKey = (e) => {
|
|
6666
|
-
const s = stateRef.current;
|
|
6667
|
-
if (!s)
|
|
6668
|
-
return;
|
|
6669
|
-
const sc = s.screen;
|
|
6670
|
-
const stop = () => {
|
|
6671
|
-
e.preventDefault();
|
|
6672
|
-
e.stopImmediatePropagation();
|
|
6673
|
-
};
|
|
6674
|
-
if (e.key === "Escape") {
|
|
6675
|
-
if (sc.name === "step") {
|
|
6676
|
-
stop();
|
|
6677
|
-
if (sc.confirmExit)
|
|
6678
|
-
dispatchRef.current({ type: "exitCancel" });
|
|
6679
|
-
else
|
|
6680
|
-
dispatchRef.current({ type: "exit" });
|
|
6681
|
-
}
|
|
6682
|
-
else if (sc.name === "welcome") {
|
|
6683
|
-
stop();
|
|
6684
|
-
dispatchRef.current({ type: sc.confirm ? "welcomeSkipCancel" : "welcomeSkip" });
|
|
6685
|
-
}
|
|
6686
|
-
else if (sc.name === "gate") {
|
|
6687
|
-
stop();
|
|
6688
|
-
dispatchRef.current({ type: "gateLater" });
|
|
6689
|
-
}
|
|
6690
|
-
else if (sc.name === "celebrate") {
|
|
6691
|
-
stop();
|
|
6692
|
-
dispatchRef.current({ type: "rest" });
|
|
6693
|
-
}
|
|
6694
|
-
else if (sc.name === "complete") {
|
|
6695
|
-
stop();
|
|
6696
|
-
dispatchRef.current({ type: "finish" });
|
|
6697
|
-
}
|
|
6698
|
-
else if (s.panelOpen) {
|
|
6699
|
-
stop();
|
|
6700
|
-
dispatchRef.current({ type: "closePanel" });
|
|
6701
|
-
}
|
|
6702
|
-
return;
|
|
6703
|
-
}
|
|
6704
|
-
if (!guardingRef.current)
|
|
6705
|
-
return;
|
|
6706
|
-
const layer = layerRef.current;
|
|
6707
|
-
if (e.key === "Tab") {
|
|
6708
|
-
// Tab stays on what the step is about: the target and the bubble, or
|
|
6709
|
-
// the open card.
|
|
6710
|
-
const modals = layer ? Array.from(layer.querySelectorAll("[data-eg-modal],[data-eg-card]")) : [];
|
|
6711
|
-
let list;
|
|
6712
|
-
if (sc.name === "step" && !sc.confirmExit && sc.phase === "ready") {
|
|
6713
|
-
const el = targetElRef.current;
|
|
6714
|
-
const step = stepInfoRef.current?.step;
|
|
6715
|
-
const isInput = !!step && !sc.bridge && stepKind(step) === "input";
|
|
6716
|
-
const inTargetList = el && targetPressable(step, sc.bridge) ? focusablesIn(isInput ? (fieldOf(el) ?? el) : el) : [];
|
|
6717
|
-
const bubble = layer?.querySelector("[data-eg-bubble]") ?? null;
|
|
6718
|
-
list = [...inTargetList, ...(bubble ? Array.from(bubble.querySelectorAll(FOCUSABLE)) : [])];
|
|
6719
|
-
for (const p of openPoppers())
|
|
6720
|
-
list.push(...focusablesIn(p));
|
|
6721
|
-
}
|
|
6722
|
-
else {
|
|
6723
|
-
const last = modals[modals.length - 1] ?? null;
|
|
6724
|
-
list = last ? Array.from(last.querySelectorAll(FOCUSABLE)) : [];
|
|
6725
|
-
}
|
|
6726
|
-
if (!list.length)
|
|
6727
|
-
return;
|
|
6728
|
-
stop();
|
|
6729
|
-
const i = list.indexOf(document.activeElement);
|
|
6730
|
-
const n = e.shiftKey ? (i <= 0 ? list.length - 1 : i - 1) : i === -1 || i === list.length - 1 ? 0 : i + 1;
|
|
6731
|
-
list[n].focus();
|
|
6732
|
-
return;
|
|
6733
|
-
}
|
|
6734
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
6735
|
-
const active = document.activeElement;
|
|
6736
|
-
if (inGuideLayer(active))
|
|
6737
|
-
return;
|
|
6738
|
-
if (sc.name === "step" && sc.phase === "ready" && !sc.confirmExit && e.key === "Enter") {
|
|
6739
|
-
const step = stepInfoRef.current?.step;
|
|
6740
|
-
const el = targetElRef.current;
|
|
6741
|
-
if (step && stepKind(step) === "input" && el && active instanceof Node && el.contains(active) && !(active instanceof HTMLTextAreaElement)) {
|
|
6742
|
-
// During the tour Enter is ถัดไป, not "submit the form".
|
|
6743
|
-
stop();
|
|
6744
|
-
dispatchRef.current({ type: "next" });
|
|
6745
|
-
return;
|
|
6746
|
-
}
|
|
6747
|
-
}
|
|
6748
|
-
if (modalRef.current || !allowedTarget(active))
|
|
6749
|
-
stop();
|
|
6750
|
-
}
|
|
6751
|
-
};
|
|
6752
|
-
window.addEventListener("pointerdown", onPointer, true);
|
|
6753
|
-
window.addEventListener("mousedown", onPointer, true);
|
|
6754
|
-
window.addEventListener("touchstart", onPointer, { capture: true, passive: false });
|
|
6755
|
-
window.addEventListener("click", onPointer, true);
|
|
6756
|
-
window.addEventListener("focusin", onFocusIn, true);
|
|
6757
|
-
window.addEventListener("focusout", onFocusOut, true);
|
|
6758
|
-
window.addEventListener("keydown", onKey, true);
|
|
6759
|
-
return () => {
|
|
6760
|
-
window.removeEventListener("pointerdown", onPointer, true);
|
|
6761
|
-
window.removeEventListener("mousedown", onPointer, true);
|
|
6762
|
-
window.removeEventListener("touchstart", onPointer, true);
|
|
6763
|
-
window.removeEventListener("click", onPointer, true);
|
|
6764
|
-
window.removeEventListener("focusin", onFocusIn, true);
|
|
6765
|
-
window.removeEventListener("focusout", onFocusOut, true);
|
|
6766
|
-
window.removeEventListener("keydown", onKey, true);
|
|
6767
|
-
};
|
|
6768
|
-
}, [live]);
|
|
6769
|
-
/* Focus comes back to where it was when the tour lets go. */
|
|
6770
|
-
const lastFocus = useRef(null);
|
|
6771
|
-
const engaged = guarding || panelOpen;
|
|
6772
|
-
useLayoutEffect(() => {
|
|
6773
|
-
if (engaged) {
|
|
6774
|
-
if (!lastFocus.current) {
|
|
6775
|
-
const a = document.activeElement;
|
|
6776
|
-
lastFocus.current = a instanceof HTMLElement && !inGuideLayer(a) ? a : null;
|
|
6777
|
-
}
|
|
6778
|
-
return;
|
|
6779
|
-
}
|
|
6780
|
-
const back = lastFocus.current;
|
|
6781
|
-
lastFocus.current = null;
|
|
6782
|
-
if (back && back.isConnected)
|
|
6783
|
-
back.focus({ preventScroll: true });
|
|
6784
|
-
}, [engaged]);
|
|
6785
|
-
/* ---------------- the layer ---------------- */
|
|
6786
|
-
const [layer, setLayer] = useState(null);
|
|
6787
|
-
const layerRef = useRef(null);
|
|
6788
|
-
useEffect(() => {
|
|
6789
|
-
const el = document.createElement("div");
|
|
6790
|
-
el.setAttribute(GUIDE_LAYER_ATTRIBUTE, "");
|
|
6791
|
-
document.body.appendChild(el);
|
|
6792
|
-
layerRef.current = el;
|
|
6793
|
-
setLayer(el);
|
|
6794
|
-
// A Radix modal (dialog, select, menu) hides everything outside it from
|
|
6795
|
-
// screen readers with aria-hidden's hideOthers. It keeps [aria-live]
|
|
6796
|
-
// elements but walks into their ancestors and hides the other children:
|
|
6797
|
-
// with the status line live, the bubble and its buttons were hidden.
|
|
6798
|
-
// Take off what it adds, at once. hideOthers marks what it hides with
|
|
6799
|
-
// data-aria-hidden (the layer never sets that, or inert); aria-hidden goes
|
|
6800
|
-
// only where it was just added, so the layer's own decorative aria-hidden
|
|
6801
|
-
// stays. (aria-live="off" on the layer would make hideOthers skip it, but
|
|
6802
|
-
// it changed what test tools match by text.)
|
|
6803
|
-
const obs = new MutationObserver(records => {
|
|
6804
|
-
for (const r of records) {
|
|
6805
|
-
const n = r.target;
|
|
6806
|
-
if (!(n instanceof Element))
|
|
6807
|
-
continue;
|
|
6808
|
-
if (r.attributeName === "inert" && n.hasAttribute("inert"))
|
|
6809
|
-
n.removeAttribute("inert");
|
|
6810
|
-
else if (r.attributeName === "data-aria-hidden" && n.hasAttribute("data-aria-hidden"))
|
|
6811
|
-
n.removeAttribute("data-aria-hidden");
|
|
6812
|
-
else if (r.attributeName === "aria-hidden" &&
|
|
6813
|
-
n.getAttribute("aria-hidden") === "true" &&
|
|
6814
|
-
(n === el || r.oldValue === null)) {
|
|
6815
|
-
n.removeAttribute("aria-hidden");
|
|
6816
|
-
}
|
|
6817
|
-
}
|
|
6818
|
-
});
|
|
6819
|
-
obs.observe(el, { attributes: true, attributeOldValue: true, subtree: true, attributeFilter: ["aria-hidden", "data-aria-hidden", "inert"] });
|
|
6820
|
-
return () => {
|
|
6821
|
-
obs.disconnect();
|
|
6822
|
-
el.remove();
|
|
6823
|
-
layerRef.current = null;
|
|
6824
|
-
};
|
|
6825
|
-
}, []);
|
|
6826
|
-
const [phone, setPhone] = useState(false);
|
|
6827
|
-
const [reduced, setReduced] = useState(false);
|
|
6828
|
-
useEffect(() => {
|
|
6829
|
-
const sync = () => {
|
|
6830
|
-
setPhone(isPhoneWidth());
|
|
6831
|
-
setReduced(prefersReducedMotion());
|
|
3627
|
+
fetchProgress: req => client.fetchQuery({
|
|
3628
|
+
queryKey: ["erp-shell", "guides", organizationId, suite.app, suite.key, suite.version],
|
|
3629
|
+
queryFn: ({ signal }) => platform.fetchProgress({ ...req, signal }).catch(() => null),
|
|
3630
|
+
staleTime: 5 * 60000,
|
|
3631
|
+
gcTime: 30 * 60000,
|
|
3632
|
+
retry: false,
|
|
3633
|
+
}),
|
|
3634
|
+
saveProgress: req => platform.saveProgress(req),
|
|
6832
3635
|
};
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
// The celebration waits a beat, so the new row can be seen first.
|
|
6838
|
-
const [celebrateShown, setCelebrateShown] = useState(false);
|
|
6839
|
-
const celebrateKey = screen.name === "celebrate" || screen.name === "complete" ? screen.name + (screen.name === "celebrate" ? screen.mission : "") : "";
|
|
6840
|
-
useEffect(() => {
|
|
6841
|
-
setCelebrateShown(false);
|
|
6842
|
-
if (!celebrateKey)
|
|
6843
|
-
return;
|
|
6844
|
-
const t = setTimeout(() => setCelebrateShown(true), CELEBRATE_DELAY_MS);
|
|
6845
|
-
return () => clearTimeout(t);
|
|
6846
|
-
}, [celebrateKey]);
|
|
6847
|
-
// Ring moves smoothly only right after a step change.
|
|
6848
|
-
const [moving, setMoving] = useState(false);
|
|
6849
|
-
useEffect(() => {
|
|
6850
|
-
if (!stepId)
|
|
6851
|
-
return;
|
|
6852
|
-
setMoving(true);
|
|
6853
|
-
const t = setTimeout(() => setMoving(false), 320);
|
|
6854
|
-
return () => clearTimeout(t);
|
|
6855
|
-
}, [stepId]);
|
|
6856
|
-
/* ---------------- the "?" menu entry ---------------- */
|
|
6857
|
-
const ctxIdle = useMemo(() => (state ? guideContext(env(), state.progress.context) : null), [state, env, factsKey, pathname]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
6858
|
-
const done = state && ctxIdle ? settledCount(suite, state.progress, ctxIdle) : 0;
|
|
6859
|
-
const total = suite.missions.length;
|
|
6860
|
-
useEffect(() => {
|
|
6861
|
-
if (!live || !state) {
|
|
6862
|
-
publishGuideEntry(null, null);
|
|
6863
|
-
return;
|
|
6864
|
-
}
|
|
6865
|
-
publishGuideEntry({ done, total }, () => dispatchRef.current({ type: "openPanel" }));
|
|
6866
|
-
}, [live, state, done, total]);
|
|
6867
|
-
useEffect(() => () => publishGuideEntry(null, null), []);
|
|
6868
|
-
if (!live || !state || !layer || !ctxIdle)
|
|
6869
|
-
return null;
|
|
6870
|
-
/* ---------------- render ---------------- */
|
|
6871
|
-
const views = missionViews(suite, state.progress, ctxIdle);
|
|
6872
|
-
const gate = suite.gate;
|
|
6873
|
-
const gateHref = gate ? resolveText(gate.action.href, ctxIdle) : "";
|
|
6874
|
-
const gateFailing = gate ? gateState(suite, ctxIdle) === false : false;
|
|
6875
|
-
let content = null;
|
|
6876
|
-
if (screen.name === "welcome") {
|
|
6877
|
-
content = (jsx(WelcomeModal, { title: resolveText(suite.welcome.title, ctxIdle), subtitle: resolveText(suite.welcome.subtitle, ctxIdle) || `มาตั้งค่าบริษัทให้พร้อมใน ${total} ภารกิจ`, missions: suite.missions.map(m => ({ title: m.title, minutes: m.minutes })), confirm: screen.confirm, onStart: () => dispatch({ type: "welcomeStart" }), onSkip: () => dispatch({ type: "welcomeSkip" }), onSkipConfirm: () => dispatch({ type: "welcomeSkipConfirm" }), onSkipCancel: () => dispatch({ type: "welcomeSkipCancel" }) }));
|
|
6878
|
-
}
|
|
6879
|
-
else if (screen.name === "gate" && gate) {
|
|
6880
|
-
content = (jsx(GateModal, { title: gate.title, subtitle: gate.subtitle, actionLabel: gate.action.label, href: gateHref, onLater: () => dispatch({ type: "gateLater" }) }));
|
|
6881
|
-
}
|
|
6882
|
-
else if (screen.name === "step" && stepInfo && stepCtx) {
|
|
6883
|
-
const { mission, step, missionNo } = stepInfo;
|
|
6884
|
-
const kind = stepKind(step);
|
|
6885
|
-
const bridge = screen.bridge;
|
|
6886
|
-
content = (jsx(StepLayer, { spot: layout.spot, holes: layout.holes, popovers: layout.popovers, covered: layout.covered, viewport: { width: layout.vw || window.innerWidth, height: layout.vh || window.innerHeight, offsetTop: layout.oy }, phone: phone, showHand: bridge || (kind !== "input" && kind !== "view"), bubble: {
|
|
6887
|
-
missionNo,
|
|
6888
|
-
missionTitle: mission.title,
|
|
6889
|
-
replay: screen.replay,
|
|
6890
|
-
index: screen.index,
|
|
6891
|
-
total: mission.steps.length,
|
|
6892
|
-
title: bridge ? "กดปุ่มเมนู" : resolveText(step.title, stepCtx),
|
|
6893
|
-
why: bridge ? `เมนูทั้งหมดของ ${suite.appName} อยู่ในนี้` : resolveText(step.why, stepCtx),
|
|
6894
|
-
error: screen.error,
|
|
6895
|
-
showNext: !bridge && (kind === "input" || kind === "view"),
|
|
6896
|
-
showEndWithoutSave: !bridge && screen.replay && kind === "commit",
|
|
6897
|
-
}, hasTarget: bridge || !!step.target, targetPressable: targetPressable(step, bridge), phase: screen.phase, confirmExit: screen.confirmExit, nudge: state.nudge, moving: moving, onExit: () => dispatch({ type: "exit" }), onNext: () => dispatch({ type: "next" }), onEndWithoutSave: () => dispatch({ type: "endWithoutSave" }), onRetry: () => dispatch({ type: "retry" }), onGoResume: () => dispatch({ type: "goResume" }), onExitConfirm: () => dispatch({ type: "exitConfirm" }), onExitCancel: () => dispatch({ type: "exitCancel" }) }));
|
|
6898
|
-
}
|
|
6899
|
-
else if (screen.name === "celebrate" && celebrateShown) {
|
|
6900
|
-
const mission = findMission(suite, screen.mission);
|
|
6901
|
-
const next = findMission(suite, nextMissionKey(suite, state.progress, ctxIdle));
|
|
6902
|
-
if (mission) {
|
|
6903
|
-
content = (jsx(CelebrateModal, { missionNo: suite.missions.indexOf(mission) + 1, title: resolveText(mission.done?.title, ctxIdle) || `${mission.title}แล้ว`, subtitle: resolveText(mission.done?.subtitle, ctxIdle), done: done, total: total, nextTitle: next?.title ?? null, reduced: reduced, onNext: () => dispatch({ type: "celebrateNext" }), onRest: () => dispatch({ type: "rest" }) }));
|
|
6904
|
-
}
|
|
6905
|
-
}
|
|
6906
|
-
else if (screen.name === "complete" && celebrateShown) {
|
|
6907
|
-
const secondary = suite.complete.secondary;
|
|
6908
|
-
let secondaryHref;
|
|
6909
|
-
try {
|
|
6910
|
-
secondaryHref = secondary ? (typeof secondary.href === "function" ? secondary.href(ctxIdle) : secondary.href) : undefined;
|
|
6911
|
-
}
|
|
6912
|
-
catch {
|
|
6913
|
-
secondaryHref = undefined;
|
|
6914
|
-
}
|
|
6915
|
-
content = (jsx(CompleteModal, { total: total, title: resolveText(suite.complete.title, ctxIdle) || "บริษัทพร้อมใช้งานแล้ว", subtitle: resolveText(suite.complete.subtitle, ctxIdle), missions: suite.missions.map(m => m.title), actionLabel: suite.complete.action.label, secondary: secondary && secondaryHref ? { label: secondary.label, href: secondaryHref } : null, reduced: reduced, onFinish: () => dispatch({ type: "finish" }) }));
|
|
6916
|
-
}
|
|
6917
|
-
const items = views.map(v => ({
|
|
6918
|
-
key: v.mission.key,
|
|
6919
|
-
title: v.mission.title,
|
|
6920
|
-
minutes: v.mission.minutes,
|
|
6921
|
-
view: v.view,
|
|
6922
|
-
optional: !!v.mission.optional,
|
|
6923
|
-
completedAt: v.entry?.completed_at ?? null,
|
|
6924
|
-
lockedBy: v.view === "locked"
|
|
6925
|
-
? (v.mission.after ?? [])
|
|
6926
|
-
.map(k => findMission(suite, k)?.title)
|
|
6927
|
-
.filter(Boolean)
|
|
6928
|
-
.join(", ")
|
|
6929
|
-
: undefined,
|
|
6930
|
-
}));
|
|
6931
|
-
const showChip = chipVisible(state, suite, ctxIdle);
|
|
6932
|
-
return createPortal(jsxs(Fragment$1, { children: [jsx("style", { children: GUIDE_CSS }), jsx("div", { className: "eg-sr", "aria-live": "polite", role: "status", children: liveText }), content, showChip ? jsx(QuestChip, { done: done, total: total, pulse: state.chipPulse, onOpen: () => dispatch({ type: "openPanel" }) }) : null, state.panelOpen && screen.name === "idle" ? (jsx(QuestPanel, { items: items, done: done, total: total, justDone: state.justDone, gate: gate && gateFailing ? { label: gate.action.label, pending: gate.pending, href: gateHref } : null, canHideChip: !state.progress.chip_hidden && state.progress.status !== "completed", onClose: () => dispatch({ type: "closePanel" }), onStart: (key, replayIt) => dispatch({ type: "start", mission: key, replay: replayIt }), onDismiss: key => dispatch({ type: "dismissMission", mission: key }), onHideChip: () => dispatch({ type: "hideChip" }) })) : null, toast ? jsx(GuideToast, { text: toast }) : null] }), layer);
|
|
6933
|
-
}
|
|
6934
|
-
/** A stable key for the facts object, so effects re-run when they change. */
|
|
6935
|
-
function useFactsKey(facts) {
|
|
6936
|
-
return useMemo(() => {
|
|
6937
|
-
try {
|
|
6938
|
-
return JSON.stringify(facts ?? {});
|
|
6939
|
-
}
|
|
6940
|
-
catch {
|
|
6941
|
-
return String(Math.random());
|
|
6942
|
-
}
|
|
6943
|
-
}, [facts]);
|
|
3636
|
+
}, [client, organizationId, suite.app, suite.key, suite.version]);
|
|
3637
|
+
const routing = useMemo(() => ({ pathname, search, navigate: (href) => router.push(href) }), [pathname, search, router]);
|
|
3638
|
+
const menu = useMemo(() => ({ open: sidebarOpen }), [sidebarOpen]);
|
|
3639
|
+
return (jsx(GuideRuntime, { config: config, organizationId: organizationId, code: code, routing: routing, progress: progress, isBusy: isBusy, menu: menu, hidden: employeeBlocked }));
|
|
6944
3640
|
}
|
|
6945
3641
|
|
|
6946
3642
|
/**
|
|
@@ -7718,5 +4414,5 @@ const getAxiosErrorMessage = (error) => {
|
|
|
7718
4414
|
return String(error);
|
|
7719
4415
|
};
|
|
7720
4416
|
|
|
7721
|
-
export { AccessDenied, ApiError, AppBreadcrumb, AppLayoutShell, AppSidebar, EMPLOYEE_RECORD_OK_EVENT, EMPLOYEE_RECORD_REQUIRED, EMPLOYEE_RECORD_REQUIRED_EVENT, EmployeeRequiredGate, FOR_ORGANIZATION_FIELD, FeatureFlagsProvider,
|
|
4417
|
+
export { AccessDenied, ApiError, AppBreadcrumb, AppLayoutShell, AppSidebar, EMPLOYEE_RECORD_OK_EVENT, EMPLOYEE_RECORD_REQUIRED, EMPLOYEE_RECORD_REQUIRED_EVENT, EmployeeRequiredGate, FOR_ORGANIZATION_FIELD, FeatureFlagsProvider, GuideHost, GuideRuntime, HeaderBackground, HelpButton, HelpDialogHost, NavMain, NavTools, NavUser, OWNER_CHIP, OrganizationSwitcher, PLAN_FEATURES, PermissionGateShell, PermissionProvider, PermissionRulesProvider, ReactQueryProvider, SHELL_VERSION, SessionBackedProfileCacheSeeder, SessionRefreshTrigger, SidebarContent, SidebarFooter, SidebarHeader, SidebarHelpCard, SidebarHelpLink, SidebarProvider, SidebarTrigger, TapMenu, ThemeProvider, WITHOUT_ORGANIZATION_FLAG, WORKSPACE_HEADER_VARS, WORKSPACE_LIGHT_HEADER_VARS, WorkspaceBrand, accountSettingsHref, instance as axiosInstance, buildSystemLinks, buildUrlWithCode, canAccessNavPermissionRoute, clearAccessTokenCache, clearOrganizationId, clearStoredOrganization, closeHelp, decodeJWT, describeAttached, describeBrowser, detectHelpApp, filterNavigationModulesByPermission, filterNavigationToolsByPermission, findOrganizationForCode, getAccessToken, getActiveModule, getActiveSubModule, getAxiosErrorMessage, getOrganizationId, getQueryClientConfig, getRequestOrganizationId, getRequiredChildGroups, getStoredOrganizationIds, getTabOrganizationId, guideAnchor, hasPlanFeature, isKnownStaleOrganizationId, isLikelyTransientNetworkError, isPathActive, myRolesQueryKey, normalizePathnameForPermissionRules, openGuidePanel, openHelp, organizationScopedQueryHash, parseMyRoles, platformBaseUrl, reportApiEvent, resolveActiveNav, resolveSidebarNav, resolveStaleOrganization, resolveUiRoutePermission, resolveUrlOrgGate, retryWithStoredOrganizations, roleSummary, runGlobalRequestPrecheck, runWithTransientRetry, setKnownOrganizationIds, setOrganizationId, setTabOrganizationId, shouldRetryQuery, toApiError, unwrapApiResponse, updateOrganizationId, useClearOrgOnUserChange, useFeatureFlag, useFeatureFlags, useGuideEntry, useInvalidateQueriesOnOrgChange, useKeycloakRoles, useMyRoles, useOrganizationIdState, usePermissionRules, useSessionRefresh, useSidebar, useSidebarToggle, withoutOrganization };
|
|
7722
4418
|
//# sourceMappingURL=index.esm.js.map
|