@entifix/next-shell 0.19.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/back-office/account-menu.d.ts +10 -1
- package/dist/lib/back-office/account-menu.d.ts.map +1 -1
- package/dist/lib/back-office/account-menu.js +27 -3
- package/dist/lib/back-office/account-menu.js.map +1 -1
- package/dist/lib/back-office/back-office-shell.d.ts +0 -19
- package/dist/lib/back-office/back-office-shell.d.ts.map +1 -1
- package/dist/lib/back-office/back-office-shell.js +75 -59
- package/dist/lib/back-office/back-office-shell.js.map +1 -1
- package/dist/lib/back-office/breadcrumb-labels.d.ts +20 -0
- package/dist/lib/back-office/breadcrumb-labels.d.ts.map +1 -0
- package/dist/lib/back-office/breadcrumb-labels.js +52 -0
- package/dist/lib/back-office/breadcrumb-labels.js.map +1 -0
- package/dist/lib/back-office/breadcrumbs.d.ts.map +1 -1
- package/dist/lib/back-office/breadcrumbs.js +6 -1
- package/dist/lib/back-office/breadcrumbs.js.map +1 -1
- package/dist/lib/back-office/index.d.ts +1 -0
- package/dist/lib/back-office/index.d.ts.map +1 -1
- package/dist/lib/back-office/index.js +1 -0
- package/dist/lib/back-office/index.js.map +1 -1
- package/dist/lib/back-office/sidebar-nav.d.ts.map +1 -1
- package/dist/lib/back-office/sidebar-nav.js +31 -36
- package/dist/lib/back-office/sidebar-nav.js.map +1 -1
- package/dist/lib/command-palette/command-palette-host.d.ts.map +1 -1
- package/dist/lib/command-palette/command-palette-host.js +2 -9
- package/dist/lib/command-palette/command-palette-host.js.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.d.ts.map +1 -1
- package/dist/lib/command-palette/use-use-cases-source.js +3 -1
- package/dist/lib/command-palette/use-use-cases-source.js.map +1 -1
- package/dist/lib/confirm-action/confirm-action-state.d.ts +33 -0
- package/dist/lib/confirm-action/confirm-action-state.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action-state.js +33 -0
- package/dist/lib/confirm-action/confirm-action-state.js.map +1 -0
- package/dist/lib/confirm-action/confirm-action.d.ts +28 -0
- package/dist/lib/confirm-action/confirm-action.d.ts.map +1 -0
- package/dist/lib/confirm-action/confirm-action.js +129 -0
- package/dist/lib/confirm-action/confirm-action.js.map +1 -0
- package/dist/lib/confirm-action/index.d.ts +3 -0
- package/dist/lib/confirm-action/index.d.ts.map +1 -0
- package/dist/lib/confirm-action/index.js +3 -0
- package/dist/lib/confirm-action/index.js.map +1 -0
- package/dist/lib/crud/entity-crud-form.d.ts +5 -1
- package/dist/lib/crud/entity-crud-form.d.ts.map +1 -1
- package/dist/lib/crud/entity-crud-form.js +5 -10
- package/dist/lib/crud/entity-crud-form.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +120 -20
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +18 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
- package/dist/lib/crud/use-link-labels.d.ts +32 -0
- package/dist/lib/crud/use-link-labels.d.ts.map +1 -0
- package/dist/lib/crud/use-link-labels.js +76 -0
- package/dist/lib/crud/use-link-labels.js.map +1 -0
- package/dist/lib/i18n/catalog/en.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/en.js +4 -4
- package/dist/lib/i18n/catalog/en.js.map +1 -1
- package/dist/lib/i18n/catalog/es.d.ts +4 -2
- package/dist/lib/i18n/catalog/es.d.ts.map +1 -1
- package/dist/lib/i18n/catalog/es.js +4 -4
- package/dist/lib/i18n/catalog/es.js.map +1 -1
- package/dist/lib/i18n/catalog/index.d.ts +4 -4
- package/dist/lib/theme/theme-cookies.d.ts +27 -0
- package/dist/lib/theme/theme-cookies.d.ts.map +1 -0
- package/dist/lib/theme/theme-cookies.js +18 -0
- package/dist/lib/theme/theme-cookies.js.map +1 -0
- package/dist/lib/workspace/pending-flows.d.ts.map +1 -1
- package/dist/lib/workspace/pending-flows.js +15 -6
- package/dist/lib/workspace/pending-flows.js.map +1 -1
- package/dist/lib/workspace/workspace-shell.d.ts.map +1 -1
- package/dist/lib/workspace/workspace-shell.js +11 -2
- package/dist/lib/workspace/workspace-shell.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +5 -0
- package/dist/server.js.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/validation-messages.d.ts +0 -13
- package/dist/lib/crud/validation-messages.d.ts.map +0 -1
- package/dist/lib/crud/validation-messages.js +0 -36
- package/dist/lib/crud/validation-messages.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/back-office/index.ts"],"sourcesContent":["export * from './account-menu.js';\nexport * from './back-office-shell.js';\nexport * from './breadcrumbs.js';\nexport * from './nav.js';\nexport * from './sidebar-nav.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,yBAAyB;AACvC,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,mBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/index.ts"],"sourcesContent":["export * from './account-menu.js';\nexport * from './back-office-shell.js';\nexport * from './breadcrumb-labels.js';\nexport * from './breadcrumbs.js';\nexport * from './nav.js';\nexport * from './sidebar-nav.js';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB;AAClC,cAAc,yBAAyB;AACvC,cAAc,yBAAyB;AACvC,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidebar-nav.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/sidebar-nav.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhE;
|
|
1
|
+
{"version":3,"file":"sidebar-nav.d.ts","sourceRoot":"","sources":["../../../src/lib/back-office/sidebar-nav.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhE;AA6ED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,SAAiB,EACjB,eAAoB,EACpB,aAAa,GACd,EAAE,eAAe,+BA2GjB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { SCREEN_TYPE_LABEL_KEYS } from '@entifix/authz';
|
|
5
|
-
import { cn, useT, useTranslateKey } from '@entifix/react-controls';
|
|
6
|
-
import { usePathname } from 'next/navigation';
|
|
5
|
+
import { cn, Menu, useT, useTranslateKey } from '@entifix/react-controls';
|
|
6
|
+
import { usePathname, useRouter } from 'next/navigation';
|
|
7
7
|
import { useMemo } from 'react';
|
|
8
8
|
import { LocaleLink, useLocaleHref } from '../i18n/index.js';
|
|
9
9
|
import { groupByScreenType } from './group-by-screen-type.js';
|
|
@@ -12,47 +12,42 @@ import { groupByScreenType } from './group-by-screen-type.js';
|
|
|
12
12
|
}
|
|
13
13
|
const workspaceHref = (workspace)=>`/workspace?tab=${encodeURIComponent(workspace)}`;
|
|
14
14
|
/**
|
|
15
|
-
* The two "open where" choices for one destination.
|
|
15
|
+
* The two "open where" choices for one destination, behind one menu.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
* click worked by accident, and only with a mouse.
|
|
22
|
-
*
|
|
23
|
-
* They are now always rendered and always focusable. `text-content-muted` plus a
|
|
24
|
-
* hover/focus lift is what keeps a permanently visible control from competing
|
|
25
|
-
* with the destination itself — the affordance is quiet, not hidden.
|
|
26
|
-
*/ function ItemActions({ item, label }) {
|
|
17
|
+
* They were two 15px links beside every item: three Tab stops per destination,
|
|
18
|
+
* and two targets under the 24px floor (ADR 0025). One trigger at
|
|
19
|
+
* `--target-min` keeps both choices a keystroke away and costs one stop.
|
|
20
|
+
*/ function ItemMenu({ item, label }) {
|
|
27
21
|
const t = useT('shell');
|
|
28
22
|
const withLocale = useLocaleHref();
|
|
29
|
-
|
|
23
|
+
const router = useRouter();
|
|
24
|
+
const workspace = item.workspace;
|
|
25
|
+
return /*#__PURE__*/ _jsxs(Menu, {
|
|
26
|
+
className: "shrink-0",
|
|
30
27
|
children: [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"aria-label": t('nav.openInWorkspace', {
|
|
28
|
+
/*#__PURE__*/ _jsx(Menu.Trigger, {
|
|
29
|
+
"aria-label": t('nav.itemActions', {
|
|
34
30
|
label
|
|
35
31
|
}),
|
|
36
|
-
|
|
37
|
-
className: "rounded shrink-0 p-3xs text-content-muted focus-ring transition-colors hover:bg-surface hover:text-content",
|
|
32
|
+
className: "text-content-muted hover:text-content",
|
|
38
33
|
children: /*#__PURE__*/ _jsx("span", {
|
|
39
34
|
"aria-hidden": "true",
|
|
40
|
-
children: "
|
|
35
|
+
children: "⋯"
|
|
41
36
|
})
|
|
42
37
|
}),
|
|
43
|
-
/*#__PURE__*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
/*#__PURE__*/ _jsxs(Menu.Items, {
|
|
39
|
+
children: [
|
|
40
|
+
workspace !== undefined && /*#__PURE__*/ _jsx(Menu.Item, {
|
|
41
|
+
onClick: ()=>router.push(withLocale(workspaceHref(workspace))),
|
|
42
|
+
children: t('nav.openInWorkspace')
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ _jsx(Menu.Link, {
|
|
45
|
+
href: withLocale(item.href),
|
|
46
|
+
target: "_blank",
|
|
47
|
+
rel: "noopener noreferrer",
|
|
48
|
+
children: t('nav.openInNewTab')
|
|
49
|
+
})
|
|
50
|
+
]
|
|
56
51
|
})
|
|
57
52
|
]
|
|
58
53
|
});
|
|
@@ -142,7 +137,7 @@ function ItemLink({ item, active, collapsed }) {
|
|
|
142
137
|
}) : t('sidebar.collapseGroup', {
|
|
143
138
|
group: title
|
|
144
139
|
}),
|
|
145
|
-
className: cn('rounded tracking-wide flex items-center gap-3xs px-2xs text-step-xs uppercase focus-ring transition-colors hover:text-content', groupCollapsed && hasActive ? 'text-content' : 'text-content-muted'),
|
|
140
|
+
className: cn('rounded tracking-wide flex min-h-(--target-min) items-center gap-3xs px-2xs text-step-xs uppercase focus-ring transition-colors hover:text-content', groupCollapsed && hasActive ? 'text-content' : 'text-content-muted'),
|
|
146
141
|
children: [
|
|
147
142
|
/*#__PURE__*/ _jsx("span", {
|
|
148
143
|
"aria-hidden": "true",
|
|
@@ -162,7 +157,7 @@ function ItemLink({ item, active, collapsed }) {
|
|
|
162
157
|
active: isActive(pathname, item.href),
|
|
163
158
|
collapsed: collapsed
|
|
164
159
|
}),
|
|
165
|
-
!collapsed && /*#__PURE__*/ _jsx(
|
|
160
|
+
!collapsed && /*#__PURE__*/ _jsx(ItemMenu, {
|
|
166
161
|
item: item,
|
|
167
162
|
label: item.label
|
|
168
163
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/back-office/sidebar-nav.tsx"],"sourcesContent":["'use client';\n\nimport { SCREEN_TYPE_LABEL_KEYS } from '@entifix/authz';\nimport { cn, useT, useTranslateKey } from '@entifix/react-controls';\nimport { usePathname } from 'next/navigation';\nimport { useMemo } from 'react';\n\nimport { LocaleLink, useLocaleHref } from '../i18n/index.js';\nimport { groupByScreenType } from './group-by-screen-type.js';\nimport type { NavItem, NavSection } from './nav.js';\n\nexport interface SidebarNavProps {\n sections: NavSection[];\n /** When collapsed, labels and headings hide; only icons remain. */\n collapsed?: boolean;\n /** Which domain groups are collapsed, keyed by heading. */\n collapsedGroups?: Record<string, boolean>;\n onToggleGroup?: (title: string) => void;\n}\n\n/** A path is active when it equals the item href or is nested beneath it. */\nexport function isActive(pathname: string, href: string): boolean {\n return pathname === href || pathname.startsWith(`${href}/`);\n}\n\nconst workspaceHref = (workspace: string) =>\n `/workspace?tab=${encodeURIComponent(workspace)}`;\n\n/**\n * The two \"open where\" choices for one destination.\n *\n * Both used to be either absent or invisible. The workspace link existed but was\n * `opacity-0` until `group-hover/nav` — undiscoverable on touch, where there is\n * no hover — and was dropped entirely while collapsed, which is the mode a power\n * operator lives in. There was no open-in-a-browser-tab control at all; middle\n * click worked by accident, and only with a mouse.\n *\n * They are now always rendered and always focusable. `text-content-muted` plus a\n * hover/focus lift is what keeps a permanently visible control from competing\n * with the destination itself — the affordance is quiet, not hidden.\n */\nfunction ItemActions({ item, label }: { item: NavItem; label: string }) {\n const t = useT('shell');\n const withLocale = useLocaleHref();\n\n return (\n <>\n {item.workspace !== undefined && (\n <LocaleLink\n href={workspaceHref(item.workspace)}\n aria-label={t('nav.openInWorkspace', { label })}\n title={t('nav.openInWorkspaceShort')}\n className=\"rounded shrink-0 p-3xs text-content-muted focus-ring transition-colors hover:bg-surface hover:text-content\"\n >\n <span aria-hidden=\"true\">⧉</span>\n </LocaleLink>\n )}\n <a\n href={withLocale(item.href)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n aria-label={t('nav.openInNewTab', { label })}\n title={t('nav.openInNewTabShort')}\n className=\"rounded shrink-0 p-3xs text-content-muted focus-ring transition-colors hover:bg-surface hover:text-content\"\n >\n <span aria-hidden=\"true\">↗</span>\n </a>\n </>\n );\n}\n\nfunction ItemLink({\n item,\n active,\n collapsed,\n}: {\n item: NavItem;\n active: boolean;\n collapsed: boolean;\n}) {\n return (\n <LocaleLink\n href={item.href}\n aria-current={active ? 'page' : undefined}\n title={collapsed ? item.label : undefined}\n className={cn(\n 'flex flex-1 items-center gap-2xs rounded-md px-2xs py-3xs text-step-sm focus-ring transition-colors',\n active\n ? 'bg-primary text-primary-content'\n : 'text-content hover:bg-surface',\n )}\n >\n {item.icon !== undefined && (\n <span aria-hidden=\"true\" className=\"shrink-0\">\n {item.icon}\n </span>\n )}\n {!collapsed && <span className=\"truncate\">{item.label}</span>}\n </LocaleLink>\n );\n}\n\n/**\n * The back office's primary navigation: screen type › domain › destination.\n *\n * The top tier is the **type**, not the domain. Four fixed entries\n * against however many domains a host has, so a new operator has one\n * place to look; the daily operator's speed is the command palette's job.\n *\n * **Collapsed mode deliberately does not nest.** The icon column stays flat and\n * every group becomes a labelled separator, because a flyout submenu would cost\n * an extra click per navigation to precisely the operator who chose the compact\n * mode. What collapsing hides is labels, and the per-item tooltip already\n * returns those. Group collapse is therefore an expanded-mode affordance.\n */\nexport function SidebarNav({\n sections,\n collapsed = false,\n collapsedGroups = {},\n onToggleGroup,\n}: SidebarNavProps) {\n const t = useT('shell');\n // The four type names are `shell:` copy owned by `@entifix/authz`'s\n // `SCREEN_TYPE_LABEL_KEYS`, so they arrive as fully-qualified keys rather than\n // as names in this namespace — the documented escape hatch, not authored copy.\n const translateKey = useTranslateKey();\n const pathname = usePathname() ?? '';\n const tiers = useMemo(() => groupByScreenType(sections), [sections]);\n\n return (\n <nav aria-label={t('nav.primary')} className=\"flex flex-col gap-m\">\n {tiers.map((tier, tierIndex) => (\n <div\n key={tier.type ?? `tier-${tierIndex}`}\n className=\"flex flex-col gap-2xs\"\n >\n {tier.type !== undefined && !collapsed && (\n <p className=\"tracking-wide px-2xs text-step-xs font-semibold text-content uppercase\">\n {translateKey(SCREEN_TYPE_LABEL_KEYS[tier.type])}\n </p>\n )}\n {/* Collapsed, the heading is gone but the grouping is not: a rule plus\n an accessible name is what keeps the icon column from reading as\n one undifferentiated list. */}\n {collapsed && tierIndex > 0 && (\n <hr className=\"border-border\" aria-hidden=\"true\" />\n )}\n {/* `role=\"group\"` only where there is a name for it. An unnamed group\n is announced as an empty landmark, which is noise rather than\n structure — and the untyped section is not a screen group at all. */}\n <div\n className=\"flex flex-col gap-2xs\"\n {...(tier.type === undefined\n ? {}\n : {\n role: 'group',\n 'aria-label': translateKey(SCREEN_TYPE_LABEL_KEYS[tier.type]),\n })}\n >\n {tier.sections.map((section, sectionIndex) => {\n const title = section.title;\n const groupCollapsed =\n title !== undefined && collapsedGroups[title] === true;\n // A collapsed group holding the active route still shows where you\n // are — otherwise collapsing a group hides the answer.\n const hasActive = section.items.some(item =>\n isActive(pathname, item.href),\n );\n\n return (\n <div\n key={title ?? `section-${sectionIndex}`}\n className=\"flex flex-col gap-3xs\"\n >\n {title !== undefined &&\n !collapsed &&\n (onToggleGroup === undefined ? (\n <p className=\"tracking-wide px-2xs text-step-xs text-content-muted uppercase\">\n {title}\n </p>\n ) : (\n <button\n type=\"button\"\n onClick={() => onToggleGroup(title)}\n aria-expanded={!groupCollapsed}\n aria-label={\n groupCollapsed\n ? t('sidebar.expandGroup', { group: title })\n : t('sidebar.collapseGroup', { group: title })\n }\n className={cn(\n 'rounded tracking-wide flex items-center gap-3xs px-2xs text-step-xs uppercase focus-ring transition-colors hover:text-content',\n groupCollapsed && hasActive\n ? 'text-content'\n : 'text-content-muted',\n )}\n >\n <span aria-hidden=\"true\">\n {groupCollapsed ? '▸' : '▾'}\n </span>\n <span className=\"truncate\">{title}</span>\n </button>\n ))}\n {!(groupCollapsed && !collapsed) &&\n section.items.map(item => (\n <div\n key={item.href}\n className=\"flex items-center gap-3xs\"\n >\n <ItemLink\n item={item}\n active={isActive(pathname, item.href)}\n collapsed={collapsed}\n />\n {!collapsed && (\n <ItemActions item={item} label={item.label} />\n )}\n </div>\n ))}\n </div>\n );\n })}\n </div>\n </div>\n ))}\n </nav>\n );\n}\n"],"names":["SCREEN_TYPE_LABEL_KEYS","cn","useT","useTranslateKey","usePathname","useMemo","LocaleLink","useLocaleHref","groupByScreenType","isActive","pathname","href","startsWith","workspaceHref","workspace","encodeURIComponent","ItemActions","item","label","t","withLocale","undefined","aria-label","title","className","span","aria-hidden","a","target","rel","ItemLink","active","collapsed","aria-current","icon","SidebarNav","sections","collapsedGroups","onToggleGroup","translateKey","tiers","nav","map","tier","tierIndex","div","type","p","hr","role","section","sectionIndex","groupCollapsed","hasActive","items","some","button","onClick","aria-expanded","group"],"mappings":"AAAA;;;AAEA,SAASA,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,IAAI,EAAEC,eAAe,QAAQ,0BAA0B;AACpE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,OAAO,QAAQ,QA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uDAGH,MAACiC;wCACCV,MAAK;wCACLW,SAAS,IAAMnB,cAAcf;wCAC7BmC,iBAAe,CAACN;wCAChB9B,cACE8B,iBACIjC,EAAE,uBAAuB;4CAAEwC,OAAOpC;wCAAM,KACxCJ,EAAE,yBAAyB;4CAAEwC,OAAOpC;wCAAM;wCAEhDC,WAAWvB,GACT,iIACAmD,kBAAkBC,YACd,iBACA;;0DAGN,KAAC5B;gDAAKC,eAAY;0DACf0B,iBAAiB,MAAM;;0DAE1B,KAAC3B;gDAAKD,WAAU;0DAAYD;;;sCAEhC;oCACD,CAAE6B,CAAAA,kBAAkB,CAACpB,SAAQ,KAC5BkB,QAAQI,KAAK,CAACZ,GAAG,CAACzB,CAAAA,qBAChB,MAAC4B;4CAECrB,WAAU;;8DAEV,KAACM;oDACCb,MAAMA;oDACNc,QAAQtB,SAASC,UAAUO,KAAKN,IAAI;oDACpCqB,WAAWA;;gDAEZ,CAACA,2BACA,KAAChB;oDAAYC,MAAMA;oDAAMC,OAAOD,KAAKC,KAAK;;;2CATvCD,KAAKN,IAAI;;+BAnCfY,gBAAAA,QAAS,CAAC,QAAQ,EAAE4B,cAAc;wBAkD7C;;;gBAxFGR,aAAAA,KAAKG,IAAI,YAATH,aAAa,CAAC,KAAK,EAAEC,WAAW;;;AA8F/C"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/back-office/sidebar-nav.tsx"],"sourcesContent":["'use client';\n\nimport { SCREEN_TYPE_LABEL_KEYS } from '@entifix/authz';\nimport { cn, Menu, useT, useTranslateKey } from '@entifix/react-controls';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useMemo } from 'react';\n\nimport { LocaleLink, useLocaleHref } from '../i18n/index.js';\nimport { groupByScreenType } from './group-by-screen-type.js';\nimport type { NavItem, NavSection } from './nav.js';\n\nexport interface SidebarNavProps {\n sections: NavSection[];\n /** When collapsed, labels and headings hide; only icons remain. */\n collapsed?: boolean;\n /** Which domain groups are collapsed, keyed by heading. */\n collapsedGroups?: Record<string, boolean>;\n onToggleGroup?: (title: string) => void;\n}\n\n/** A path is active when it equals the item href or is nested beneath it. */\nexport function isActive(pathname: string, href: string): boolean {\n return pathname === href || pathname.startsWith(`${href}/`);\n}\n\nconst workspaceHref = (workspace: string) =>\n `/workspace?tab=${encodeURIComponent(workspace)}`;\n\n/**\n * The two \"open where\" choices for one destination, behind one menu.\n *\n * They were two 15px links beside every item: three Tab stops per destination,\n * and two targets under the 24px floor (ADR 0025). One trigger at\n * `--target-min` keeps both choices a keystroke away and costs one stop.\n */\nfunction ItemMenu({ item, label }: { item: NavItem; label: string }) {\n const t = useT('shell');\n const withLocale = useLocaleHref();\n const router = useRouter();\n const workspace = item.workspace;\n\n return (\n <Menu className=\"shrink-0\">\n <Menu.Trigger\n aria-label={t('nav.itemActions', { label })}\n className=\"text-content-muted hover:text-content\"\n >\n <span aria-hidden=\"true\">⋯</span>\n </Menu.Trigger>\n <Menu.Items>\n {workspace !== undefined && (\n <Menu.Item\n onClick={() => router.push(withLocale(workspaceHref(workspace)))}\n >\n {t('nav.openInWorkspace')}\n </Menu.Item>\n )}\n <Menu.Link\n href={withLocale(item.href)}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n {t('nav.openInNewTab')}\n </Menu.Link>\n </Menu.Items>\n </Menu>\n );\n}\n\nfunction ItemLink({\n item,\n active,\n collapsed,\n}: {\n item: NavItem;\n active: boolean;\n collapsed: boolean;\n}) {\n return (\n <LocaleLink\n href={item.href}\n aria-current={active ? 'page' : undefined}\n title={collapsed ? item.label : undefined}\n className={cn(\n 'flex flex-1 items-center gap-2xs rounded-md px-2xs py-3xs text-step-sm focus-ring transition-colors',\n active\n ? 'bg-primary text-primary-content'\n : 'text-content hover:bg-surface',\n )}\n >\n {item.icon !== undefined && (\n <span aria-hidden=\"true\" className=\"shrink-0\">\n {item.icon}\n </span>\n )}\n {!collapsed && <span className=\"truncate\">{item.label}</span>}\n </LocaleLink>\n );\n}\n\n/**\n * The back office's primary navigation: screen type › domain › destination.\n *\n * The top tier is the **type**, not the domain. Four fixed entries\n * against however many domains a host has, so a new operator has one\n * place to look; the daily operator's speed is the command palette's job.\n *\n * **Collapsed mode deliberately does not nest.** The icon column stays flat and\n * every group becomes a labelled separator, because a flyout submenu would cost\n * an extra click per navigation to precisely the operator who chose the compact\n * mode. What collapsing hides is labels, and the per-item tooltip already\n * returns those. Group collapse is therefore an expanded-mode affordance.\n */\nexport function SidebarNav({\n sections,\n collapsed = false,\n collapsedGroups = {},\n onToggleGroup,\n}: SidebarNavProps) {\n const t = useT('shell');\n // The four type names are `shell:` copy owned by `@entifix/authz`'s\n // `SCREEN_TYPE_LABEL_KEYS`, so they arrive as fully-qualified keys rather than\n // as names in this namespace — the documented escape hatch, not authored copy.\n const translateKey = useTranslateKey();\n const pathname = usePathname() ?? '';\n const tiers = useMemo(() => groupByScreenType(sections), [sections]);\n\n return (\n <nav aria-label={t('nav.primary')} className=\"flex flex-col gap-m\">\n {tiers.map((tier, tierIndex) => (\n <div\n key={tier.type ?? `tier-${tierIndex}`}\n className=\"flex flex-col gap-2xs\"\n >\n {tier.type !== undefined && !collapsed && (\n <p className=\"tracking-wide px-2xs text-step-xs font-semibold text-content uppercase\">\n {translateKey(SCREEN_TYPE_LABEL_KEYS[tier.type])}\n </p>\n )}\n {/* Collapsed, the heading is gone but the grouping is not: a rule plus\n an accessible name is what keeps the icon column from reading as\n one undifferentiated list. */}\n {collapsed && tierIndex > 0 && (\n <hr className=\"border-border\" aria-hidden=\"true\" />\n )}\n {/* `role=\"group\"` only where there is a name for it. An unnamed group\n is announced as an empty landmark, which is noise rather than\n structure — and the untyped section is not a screen group at all. */}\n <div\n className=\"flex flex-col gap-2xs\"\n {...(tier.type === undefined\n ? {}\n : {\n role: 'group',\n 'aria-label': translateKey(SCREEN_TYPE_LABEL_KEYS[tier.type]),\n })}\n >\n {tier.sections.map((section, sectionIndex) => {\n const title = section.title;\n const groupCollapsed =\n title !== undefined && collapsedGroups[title] === true;\n // A collapsed group holding the active route still shows where you\n // are — otherwise collapsing a group hides the answer.\n const hasActive = section.items.some(item =>\n isActive(pathname, item.href),\n );\n\n return (\n <div\n key={title ?? `section-${sectionIndex}`}\n className=\"flex flex-col gap-3xs\"\n >\n {title !== undefined &&\n !collapsed &&\n (onToggleGroup === undefined ? (\n <p className=\"tracking-wide px-2xs text-step-xs text-content-muted uppercase\">\n {title}\n </p>\n ) : (\n <button\n type=\"button\"\n onClick={() => onToggleGroup(title)}\n aria-expanded={!groupCollapsed}\n aria-label={\n groupCollapsed\n ? t('sidebar.expandGroup', { group: title })\n : t('sidebar.collapseGroup', { group: title })\n }\n className={cn(\n 'rounded tracking-wide flex min-h-(--target-min) items-center gap-3xs px-2xs text-step-xs uppercase focus-ring transition-colors hover:text-content',\n groupCollapsed && hasActive\n ? 'text-content'\n : 'text-content-muted',\n )}\n >\n <span aria-hidden=\"true\">\n {groupCollapsed ? '▸' : '▾'}\n </span>\n <span className=\"truncate\">{title}</span>\n </button>\n ))}\n {!(groupCollapsed && !collapsed) &&\n section.items.map(item => (\n <div\n key={item.href}\n className=\"flex items-center gap-3xs\"\n >\n <ItemLink\n item={item}\n active={isActive(pathname, item.href)}\n collapsed={collapsed}\n />\n {!collapsed && (\n <ItemMenu item={item} label={item.label} />\n )}\n </div>\n ))}\n </div>\n );\n })}\n </div>\n </div>\n ))}\n </nav>\n );\n}\n"],"names":["SCREEN_TYPE_LABEL_KEYS","cn","Menu","useT","useTranslateKey","usePathname","useRouter","useMemo","LocaleLink","useLocaleHref","groupByScreenType","isActive","pathname","href","startsWith","workspaceHref","workspace","encodeURIComponent","ItemMenu","item","label","t","withLocale","router","className","Trigger","aria-label","span","aria-hidden","Items","undefined","Item","onClick","push","Link","target","rel","ItemLink","active","collapsed","aria-current","title","icon","SidebarNav","sections","collapsedGroups","onToggleGroup","translateKey","tiers","nav","map","tier","tierIndex","div","type","p","hr","role","section","sectionIndex","groupCollapsed","hasActive","items","some","button","aria-expanded","group"],"mappings":"AAAA;;;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ACpD,mEAAmE;4BACnE,uDAAuD;4BACvD,MAAMoB,YAAYH,QAAQI,KAAK,CAACC,IAAI,CAAC5C,CAAAA,OACnCR,SAASC,UAAUO,KAAKN,IAAI;4BAG9B,qBACE,MAACwC;gCAEC7B,WAAU;;oCAETiB,UAAUX,aACT,CAACS,aACAO,CAAAA,kBAAkBhB,0BACjB,KAACyB;wCAAE/B,WAAU;kDACViB;uDAGH,MAACuB;wCACCV,MAAK;wCACLtB,SAAS,IAAMc,cAAcL;wCAC7BwB,iBAAe,CAACL;wCAChBlC,cACEkC,iBACIvC,EAAE,uBAAuB;4CAAE6C,OAAOzB;wCAAM,KACxCpB,EAAE,yBAAyB;4CAAE6C,OAAOzB;wCAAM;wCAEhDjB,WAAWvB,GACT,sJACA2D,kBAAkBC,YACd,iBACA;;0DAGN,KAAClC;gDAAKC,eAAY;0DACfgC,iBAAiB,MAAM;;0DAE1B,KAACjC;gDAAKH,WAAU;0DAAYiB;;;sCAEhC;oCACD,CAAEmB,CAAAA,kBAAkB,CAACrB,SAAQ,KAC5BmB,QAAQI,KAAK,CAACZ,GAAG,CAAC/B,CAAAA,qBAChB,MAACkC;4CAEC7B,WAAU;;8DAEV,KAACa;oDACClB,MAAMA;oDACNmB,QAAQ3B,SAASC,UAAUO,KAAKN,IAAI;oDACpC0B,WAAWA;;gDAEZ,CAACA,2BACA,KAACrB;oDAASC,MAAMA;oDAAMC,OAAOD,KAAKC,KAAK;;;2CATpCD,KAAKN,IAAI;;+BAnCf4B,gBAAAA,QAAS,CAAC,QAAQ,EAAEkB,cAAc;wBAkD7C;;;gBAxFGR,aAAAA,KAAKG,IAAI,YAATH,aAAa,CAAC,KAAK,EAAEC,WAAW;;;AA8F/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette-host.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/command-palette-host.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"command-palette-host.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/command-palette-host.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,2BAA2B,CAAC;AAgBnC,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,sDAAsD;IACtD,QAAQ,CAAC,GAAG,EAAE,SAAS,UAAU,EAAE,CAAC;IACpC;;;;;;;OAOG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAC5D;AAWD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,GAAG,EACH,eAA6B,GAC9B,EAAE,uBAAuB,+BA6JzB"}
|
|
@@ -24,15 +24,8 @@ import { useUseCaseSources } from './use-use-cases-source.js';
|
|
|
24
24
|
* Binding both, plus a permanently visible trigger, is what makes the collision
|
|
25
25
|
* a non-issue: whichever a given browser swallows, two other ways in remain.
|
|
26
26
|
*/ const HOTKEYS = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
mod: true
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
key: 'p',
|
|
33
|
-
mod: true,
|
|
34
|
-
shift: true
|
|
35
|
-
}
|
|
27
|
+
'Mod+K',
|
|
28
|
+
'Mod+Shift+P'
|
|
36
29
|
];
|
|
37
30
|
const NO_ENTITIES = [];
|
|
38
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/command-palette/command-palette-host.tsx"],"sourcesContent":["'use client';\n\nimport { NEW_COMMAND_PAGE } from '@entifix/authz';\nimport {\n type CommandOption,\n type CommandPage,\n type CommandSource,\n parseCommandTerm,\n ROOT_COMMAND_PAGE,\n} from '@entifix/core';\nimport {\n Button,\n CommandPalette,\n type CommandPaletteLabels,\n ConfirmDialog,\n useHotkey,\n useT,\n} from '@entifix/react-controls';\nimport { useRouter } from 'next/navigation';\nimport { useState } from 'react';\n\nimport type { NavSection } from '../back-office/nav.js';\nimport type { PaletteCommand } from './palette-command.js';\nimport { useCommandRecency } from './use-command-recency.js';\nimport { useCommandSource } from './use-command-source.js';\nimport { useNavSource } from './use-nav-source.js';\nimport { useRecordsSource } from './use-records-source.js';\nimport { useTabsSource } from './use-tabs-source.js';\nimport {\n type UseCaseCommandEntity,\n useUseCaseSources,\n} from './use-use-cases-source.js';\n\n/**\n * ⌘K **and** ⌘⇧P, and neither is load-bearing.\n *\n * The case for ⌘⇧P alone was that Chrome and Firefox claim ⌘K for address-bar\n * search. That is half the picture: ⌘⇧P / Ctrl+Shift+P is Firefox's private\n * window, so **both** candidates collide somewhere. ⌘K is also what Linear,\n * GitHub, Slack and Vercel trained people on, so leaving it unbound costs a\n * reflex.\n *\n * Binding both, plus a permanently visible trigger, is what makes the collision\n * a non-issue: whichever a given browser swallows, two other ways in remain.\n */\nconst HOTKEYS = [\n { key: 'k', mod: true },\n { key: 'p', mod: true, shift: true },\n] as const;\n\nexport interface CommandPaletteHostProps {\n /**\n * Deterministic commands, already permission-filtered and translated by the\n * server layout that has the principal.\n */\n readonly commands: readonly PaletteCommand[];\n /** The same resolved nav tree the sidebar renders. */\n readonly nav: readonly NavSection[];\n /**\n * Entities whose served `$metadata` contributes `unbound` verbs, with the\n * handler for each.\n *\n * ⚠️ Must be a **module-scope constant**: the sources are produced by a hook\n * per entity, so a fresh array each render changes the hook count. See\n * `useUseCaseSources`.\n */\n readonly useCaseEntities?: readonly UseCaseCommandEntity[];\n}\n\n/** A verb waiting on its confirmation. */\ninterface PendingConfirm {\n readonly option: CommandOption;\n readonly message: string;\n readonly tone: 'destructive' | 'neutral';\n}\n\nconst NO_ENTITIES: readonly UseCaseCommandEntity[] = [];\n\n/**\n * The back office's command palette: its trigger, its shortcuts, and everything\n * it can reach.\n *\n * This is the composition point. The control in `@entifix/react-controls` is\n * presentational and the sources are hooks; what lives here is the small set of\n * decisions neither can make — which sources a typed prefix asks for, what\n * selecting an option does, and when to ask first.\n *\n * **The grammar is for entry, the stack is for depth.** `>` narrows to commands\n * and actions, `#` to records, and anything else searches everything. Descending\n * into \"Nuevo…\" is a pushed page rather than a third prefix, because a prefix has\n * to be remembered and a list can be read.\n *\n * The whole thing is mounted in the chrome, so it is reachable from every route\n * the back office serves — including `/workspace`, which is where the open-tabs\n * group has anything in it.\n */\nexport function CommandPaletteHost({\n commands,\n nav,\n useCaseEntities = NO_ENTITIES,\n}: CommandPaletteHostProps) {\n const t = useT('shell');\n const router = useRouter();\n const recency = useCommandRecency();\n\n const [open, setOpen] = useState(false);\n const [rawTerm, setRawTerm] = useState('');\n const [stack, setStack] = useState<readonly string[]>([]);\n const [pending, setPending] = useState<PendingConfirm | null>(null);\n\n const { scope, term } = parseCommandTerm(rawTerm);\n\n // Every source runs on every render — the hook count may not depend on the\n // page or the prefix. What those decide is which sources are *shown*, which is\n // why each returns a whole `CommandSource` instead of being called\n // conditionally. So the root's commands and the create page's are two sources\n // rather than one that reads the stack.\n const commandSource = useCommandSource(commands, term, undefined);\n const createSource = useCommandSource(commands, term, NEW_COMMAND_PAGE);\n const useCaseSources = useUseCaseSources(useCaseEntities, term);\n const navSource = useNavSource(nav, term);\n const tabsSource = useTabsSource(term);\n const recordsSource = useRecordsSource(\n term,\n // A record fan-out is four authenticated requests per keystroke, so it is\n // spent only where its answer is rendered: not while closed, not while the\n // prefix says commands, and not on a pushed page, which shows its own\n // sources and nothing else.\n open && scope !== 'commands' && stack.length === 0,\n );\n\n const rank = (source: CommandSource): CommandSource => ({\n ...source,\n groups: source.groups.map(recency.rank),\n });\n\n const rootSources: CommandSource[] =\n scope === 'records'\n ? [recordsSource]\n : scope === 'commands'\n ? [commandSource, ...useCaseSources]\n : [\n commandSource,\n ...useCaseSources,\n navSource,\n tabsSource,\n recordsSource,\n ];\n\n const pages: CommandPage[] = [\n {\n id: ROOT_COMMAND_PAGE,\n placeholder: t('commandPalette.placeholder'),\n sources: rootSources.map(rank),\n },\n {\n id: NEW_COMMAND_PAGE,\n title: t('commandPalette.newTitle'),\n placeholder: t('commandPalette.newPlaceholder'),\n sources: [rank(createSource)],\n },\n ];\n\n const labels: CommandPaletteLabels = {\n title: t('commandPalette.title'),\n empty: t('commandPalette.empty'),\n loading: t('commandPalette.loading'),\n more: remaining => t('commandPalette.more', { count: remaining }),\n back: t('commandPalette.back'),\n };\n\n const close = () => {\n setOpen(false);\n setPending(null);\n };\n\n // Opening resets the term and the stack in the same handler that opens it,\n // rather than from an effect keyed on `open` — a fresh palette is a fact about\n // this event, not something to react to afterwards.\n const openPalette = () => {\n setRawTerm('');\n setStack([]);\n setPending(null);\n setOpen(true);\n };\n\n useHotkey(HOTKEYS, openPalette);\n\n const perform = (option: CommandOption) => {\n recency.remember(option.id);\n close();\n if (option.href !== undefined) {\n router.push(option.href);\n return;\n }\n // A rejected command is the handler's to report — it owns the request and\n // therefore the only context in which the failure means anything. Letting it\n // reject unhandled here would surface as an unhandled rejection instead.\n void option.run?.();\n };\n\n const select = (option: CommandOption) => {\n if (option.confirm !== undefined) {\n // The palette closes and the question stands alone. Leaving the list\n // behind a modal invites a second selection against a dialog that is\n // already about the first one.\n setOpen(false);\n setPending({\n option,\n message: option.confirm.message,\n tone: option.confirm.tone,\n });\n return;\n }\n perform(option);\n };\n\n return (\n <>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={openPalette}\n data-testid=\"command-palette-trigger\"\n >\n {t('commandPalette.open')}\n </Button>\n\n <CommandPalette\n open={open}\n onClose={close}\n pages={pages}\n stack={stack}\n onStackChange={setStack}\n term={rawTerm}\n onTermChange={setRawTerm}\n onSelect={select}\n labels={labels}\n />\n\n {pending !== null && (\n <ConfirmDialog\n open\n title={pending.option.label}\n message={pending.message}\n tone={pending.tone}\n onConfirm={() => {\n const option = pending.option;\n setPending(null);\n perform(option);\n }}\n onCancel={() => setPending(null)}\n />\n )}\n </>\n );\n}\n"],"names":["NEW_COMMAND_PAGE","parseCommandTerm","ROOT_COMMAND_PAGE","Button","CommandPalette","ConfirmDialog","useHotkey","useT","useRouter","useState","useCommandRecency","useCommandSource","useNavSource","useRecordsSource","useTabsSource","useUseCaseSources","HOTKEYS","key","mod","shift","NO_ENTITIES","CommandPaletteHost","commands","nav","useCaseEntities","t","router","recency","open","setOpen","rawTerm","setRawTerm","stack","setStack","pending","setPending","scope","term","commandSource","undefined","createSource","useCaseSources","navSource","tabsSource","recordsSource","length","rank","source","groups","map","rootSources","pages","id","placeholder","sources","title","labels","empty","loading","more","remaining","count","back","close","openPalette","perform","option","remember","href","push","run","select","confirm","message","tone","type","variant","size","onClick","data-testid","onClose","onStackChange","onTermChange","onSelect","label","onConfirm","onCancel"],"mappings":"AAAA;;;AAEA,SAASA,gBAAgB,QAAQ,iBAAiB;AAClD,SAIEC,gBAAgB,EAChBC,iBAAiB,QACZ,gBAAgB;AACvB,SACEC,MAAM,EACNC,cAAc,EAEdC,aAAa,EACbC,SAAS,EACTC,IAAI,QACC,0BAA0B;AACjC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,QAAQ,QAAQ,QAAQ;AAIjC,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SAASC,gBAAgB,QAAQ,0BAA0B;AAC3D,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,gBAAgB,QAAQ,0BAA0B;AAC3D,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAEEC,iBAAiB,QACZ,4BAA4B;AAEnC;;;;;;;;;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Te,eAAY;0BAEXtD,EAAE;;0BAGL,KAACrB;gBACCwB,MAAMA;gBACNoD,SAASjB;gBACTZ,OAAOA;gBACPnB,OAAOA;gBACPiD,eAAehD;gBACfI,MAAMP;gBACNoD,cAAcnD;gBACdoD,UAAUZ;gBACVf,QAAQA;;YAGTtB,YAAY,sBACX,KAAC7B;gBACCuB,IAAI;gBACJ2B,OAAOrB,QAAQgC,MAAM,CAACkB,KAAK;gBAC3BX,SAASvC,QAAQuC,OAAO;gBACxBC,MAAMxC,QAAQwC,IAAI;gBAClBW,WAAW;oBACT,MAAMnB,SAAShC,QAAQgC,MAAM;oBAC7B/B,WAAW;oBACX8B,QAAQC;gBACV;gBACAoB,UAAU,IAAMnD,WAAW;;;;AAKrC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/command-palette/command-palette-host.tsx"],"sourcesContent":["'use client';\n\nimport { NEW_COMMAND_PAGE } from '@entifix/authz';\nimport {\n type CommandOption,\n type CommandPage,\n type CommandSource,\n parseCommandTerm,\n ROOT_COMMAND_PAGE,\n} from '@entifix/core';\nimport {\n Button,\n CommandPalette,\n type CommandPaletteLabels,\n ConfirmDialog,\n useHotkey,\n useT,\n} from '@entifix/react-controls';\nimport { useRouter } from 'next/navigation';\nimport { useState } from 'react';\n\nimport type { NavSection } from '../back-office/nav.js';\nimport type { PaletteCommand } from './palette-command.js';\nimport { useCommandRecency } from './use-command-recency.js';\nimport { useCommandSource } from './use-command-source.js';\nimport { useNavSource } from './use-nav-source.js';\nimport { useRecordsSource } from './use-records-source.js';\nimport { useTabsSource } from './use-tabs-source.js';\nimport {\n type UseCaseCommandEntity,\n useUseCaseSources,\n} from './use-use-cases-source.js';\n\n/**\n * ⌘K **and** ⌘⇧P, and neither is load-bearing.\n *\n * The case for ⌘⇧P alone was that Chrome and Firefox claim ⌘K for address-bar\n * search. That is half the picture: ⌘⇧P / Ctrl+Shift+P is Firefox's private\n * window, so **both** candidates collide somewhere. ⌘K is also what Linear,\n * GitHub, Slack and Vercel trained people on, so leaving it unbound costs a\n * reflex.\n *\n * Binding both, plus a permanently visible trigger, is what makes the collision\n * a non-issue: whichever a given browser swallows, two other ways in remain.\n */\nconst HOTKEYS = ['Mod+K', 'Mod+Shift+P'];\n\nexport interface CommandPaletteHostProps {\n /**\n * Deterministic commands, already permission-filtered and translated by the\n * server layout that has the principal.\n */\n readonly commands: readonly PaletteCommand[];\n /** The same resolved nav tree the sidebar renders. */\n readonly nav: readonly NavSection[];\n /**\n * Entities whose served `$metadata` contributes `unbound` verbs, with the\n * handler for each.\n *\n * ⚠️ Must be a **module-scope constant**: the sources are produced by a hook\n * per entity, so a fresh array each render changes the hook count. See\n * `useUseCaseSources`.\n */\n readonly useCaseEntities?: readonly UseCaseCommandEntity[];\n}\n\n/** A verb waiting on its confirmation. */\ninterface PendingConfirm {\n readonly option: CommandOption;\n readonly message: string;\n readonly tone: 'destructive' | 'neutral';\n}\n\nconst NO_ENTITIES: readonly UseCaseCommandEntity[] = [];\n\n/**\n * The back office's command palette: its trigger, its shortcuts, and everything\n * it can reach.\n *\n * This is the composition point. The control in `@entifix/react-controls` is\n * presentational and the sources are hooks; what lives here is the small set of\n * decisions neither can make — which sources a typed prefix asks for, what\n * selecting an option does, and when to ask first.\n *\n * **The grammar is for entry, the stack is for depth.** `>` narrows to commands\n * and actions, `#` to records, and anything else searches everything. Descending\n * into \"Nuevo…\" is a pushed page rather than a third prefix, because a prefix has\n * to be remembered and a list can be read.\n *\n * The whole thing is mounted in the chrome, so it is reachable from every route\n * the back office serves — including `/workspace`, which is where the open-tabs\n * group has anything in it.\n */\nexport function CommandPaletteHost({\n commands,\n nav,\n useCaseEntities = NO_ENTITIES,\n}: CommandPaletteHostProps) {\n const t = useT('shell');\n const router = useRouter();\n const recency = useCommandRecency();\n\n const [open, setOpen] = useState(false);\n const [rawTerm, setRawTerm] = useState('');\n const [stack, setStack] = useState<readonly string[]>([]);\n const [pending, setPending] = useState<PendingConfirm | null>(null);\n\n const { scope, term } = parseCommandTerm(rawTerm);\n\n // Every source runs on every render — the hook count may not depend on the\n // page or the prefix. What those decide is which sources are *shown*, which is\n // why each returns a whole `CommandSource` instead of being called\n // conditionally. So the root's commands and the create page's are two sources\n // rather than one that reads the stack.\n const commandSource = useCommandSource(commands, term, undefined);\n const createSource = useCommandSource(commands, term, NEW_COMMAND_PAGE);\n const useCaseSources = useUseCaseSources(useCaseEntities, term);\n const navSource = useNavSource(nav, term);\n const tabsSource = useTabsSource(term);\n const recordsSource = useRecordsSource(\n term,\n // A record fan-out is four authenticated requests per keystroke, so it is\n // spent only where its answer is rendered: not while closed, not while the\n // prefix says commands, and not on a pushed page, which shows its own\n // sources and nothing else.\n open && scope !== 'commands' && stack.length === 0,\n );\n\n const rank = (source: CommandSource): CommandSource => ({\n ...source,\n groups: source.groups.map(recency.rank),\n });\n\n const rootSources: CommandSource[] =\n scope === 'records'\n ? [recordsSource]\n : scope === 'commands'\n ? [commandSource, ...useCaseSources]\n : [\n commandSource,\n ...useCaseSources,\n navSource,\n tabsSource,\n recordsSource,\n ];\n\n const pages: CommandPage[] = [\n {\n id: ROOT_COMMAND_PAGE,\n placeholder: t('commandPalette.placeholder'),\n sources: rootSources.map(rank),\n },\n {\n id: NEW_COMMAND_PAGE,\n title: t('commandPalette.newTitle'),\n placeholder: t('commandPalette.newPlaceholder'),\n sources: [rank(createSource)],\n },\n ];\n\n const labels: CommandPaletteLabels = {\n title: t('commandPalette.title'),\n empty: t('commandPalette.empty'),\n loading: t('commandPalette.loading'),\n more: remaining => t('commandPalette.more', { count: remaining }),\n back: t('commandPalette.back'),\n };\n\n const close = () => {\n setOpen(false);\n setPending(null);\n };\n\n // Opening resets the term and the stack in the same handler that opens it,\n // rather than from an effect keyed on `open` — a fresh palette is a fact about\n // this event, not something to react to afterwards.\n const openPalette = () => {\n setRawTerm('');\n setStack([]);\n setPending(null);\n setOpen(true);\n };\n\n useHotkey(HOTKEYS, openPalette);\n\n const perform = (option: CommandOption) => {\n recency.remember(option.id);\n close();\n if (option.href !== undefined) {\n router.push(option.href);\n return;\n }\n // A rejected command is the handler's to report — it owns the request and\n // therefore the only context in which the failure means anything. Letting it\n // reject unhandled here would surface as an unhandled rejection instead.\n void option.run?.();\n };\n\n const select = (option: CommandOption) => {\n if (option.confirm !== undefined) {\n // The palette closes and the question stands alone. Leaving the list\n // behind a modal invites a second selection against a dialog that is\n // already about the first one.\n setOpen(false);\n setPending({\n option,\n message: option.confirm.message,\n tone: option.confirm.tone,\n });\n return;\n }\n perform(option);\n };\n\n return (\n <>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={openPalette}\n data-testid=\"command-palette-trigger\"\n >\n {t('commandPalette.open')}\n </Button>\n\n <CommandPalette\n open={open}\n onClose={close}\n pages={pages}\n stack={stack}\n onStackChange={setStack}\n term={rawTerm}\n onTermChange={setRawTerm}\n onSelect={select}\n labels={labels}\n />\n\n {pending !== null && (\n <ConfirmDialog\n open\n title={pending.option.label}\n message={pending.message}\n tone={pending.tone}\n onConfirm={() => {\n const option = pending.option;\n setPending(null);\n perform(option);\n }}\n onCancel={() => setPending(null)}\n />\n )}\n </>\n );\n}\n"],"names":["NEW_COMMAND_PAGE","parseCommandTerm","ROOT_COMMAND_PAGE","Button","CommandPalette","ConfirmDialog","useHotkey","useT","useRouter","useState","useCommandRecency","useCommandSource","useNavSource","useRecordsSource","useTabsSource","useUseCaseSources","HOTKEYS","NO_ENTITIES","CommandPaletteHost","commands","nav","useCaseEntities","t","router","recency","open","setOpen","rawTerm","setRawTerm","stack","setStack","pending","setPending","scope","term","commandSource","undefined","createSource","useCaseSources","navSource","tabsSource","recordsSource","length","rank","source","groups","map","rootSources","pages","id","placeholder","sources","title","labels","empty","loading","more","remaining","count","back","close","openPalette","perform","option","remember","href","push","run","select","confirm","message","tone","type","variant","size","onClick","data-testid","onClose","onStackChange","onTermChange","onSelect","label","onConfirm","onCancel"],"mappings":"AAAA;;;AAEA,SAASA,gBAAgB,QAAQ,iBAAiB;A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AVJ;IACP;IAEA,MAAMK,SAAS,CAACL;QACd,IAAIA,OAAOM,OAAO,KAAKjC,WAAW;YAChC,qEAAqE;YACrE,qEAAqE;YACrE,+BAA+B;YAC/BV,QAAQ;YACRM,WAAW;gBACT+B;gBACAO,SAASP,OAAOM,OAAO,CAACC,OAAO;gBAC/BC,MAAMR,OAAOM,OAAO,CAACE,IAAI;YAC3B;YACA;QACF;QACAT,QAAQC;IACV;IAEA,qBACE;;0BACE,KAAC5D;gBACCqE,MAAK;gBACLC,SAAQ;gBACRC,MAAK;gBACLC,SAASd;gBACTe,eAAY;0BAEXtD,EAAE;;0BAGL,KAAClB;gBACCqB,MAAMA;gBACNoD,SAASjB;gBACTZ,OAAOA;gBACPnB,OAAOA;gBACPiD,eAAehD;gBACfI,MAAMP;gBACNoD,cAAcnD;gBACdoD,UAAUZ;gBACVf,QAAQA;;YAGTtB,YAAY,sBACX,KAAC1B;gBACCoB,IAAI;gBACJ2B,OAAOrB,QAAQgC,MAAM,CAACkB,KAAK;gBAC3BX,SAASvC,QAAQuC,OAAO;gBACxBC,MAAMxC,QAAQwC,IAAI;gBAClBW,WAAW;oBACT,MAAMnB,SAAShC,QAAQgC,MAAM;oBAC7B/B,WAAW;oBACX8B,QAAQC;gBACV;gBACAoB,UAAU,IAAMnD,WAAW;;;;AAKrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-use-cases-source.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/use-use-cases-source.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAI1B,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"use-use-cases-source.d.ts","sourceRoot":"","sources":["../../../src/lib/command-palette/use-use-cases-source.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAI1B,MAAM,eAAe,CAAC;AAUvB,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE5E;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IAAI;IAClE,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACvD,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC,GAAG,CACA;IACE,sDAAsD;IACtD,QAAQ,CAAC,cAAc,EAAE,oBAAoB,CAAC;IAC9C,QAAQ,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC;CACpC,GACD;IACE,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;IACvD,QAAQ,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC;CACjC,CACJ,CAAC;AA0FF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,SAAS,oBAAoB,EAAE,EACzC,IAAI,EAAE,MAAM,GACX,aAAa,EAAE,CAOjB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
3
|
import { envelopeEntityName, matchesCommand, parseKeywords } from '@entifix/core';
|
|
4
|
-
import { useCasesForSurface, useT, useTranslateKey } from '@entifix/react-controls';
|
|
4
|
+
import { shortcutLabel, useCasesForSurface, useT, useTranslateKey } from '@entifix/react-controls';
|
|
5
5
|
import { useEntityUseCases } from '@entifix/react-integration';
|
|
6
6
|
import { useMemo } from 'react';
|
|
7
7
|
/**
|
|
@@ -46,6 +46,8 @@ import { useMemo } from 'react';
|
|
|
46
46
|
label: translateKey(descriptor.labelKey),
|
|
47
47
|
keywords: parseKeywords(descriptor.keywordsKey === undefined ? undefined : translateKey(descriptor.keywordsKey)),
|
|
48
48
|
run
|
|
49
|
+
}, descriptor.shortcut === undefined ? {} : {
|
|
50
|
+
hint: shortcutLabel(descriptor.shortcut)
|
|
49
51
|
}, descriptor.confirm === undefined ? {} : {
|
|
50
52
|
confirm: {
|
|
51
53
|
tone: descriptor.confirm.tone,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/command-palette/use-use-cases-source.ts"],"sourcesContent":["'use client';\n\nimport {\n type CommandOption,\n type CommandSource,\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n envelopeEntityName,\n matchesCommand,\n parseKeywords,\n} from '@entifix/core';\nimport {\n useCasesForSurface,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport { useEntityUseCases } from '@entifix/react-integration';\nimport { useMemo } from 'react';\n\n/** How a declared verb is actually carried out, keyed by the verb. */\nexport type UseCaseHandlers = Readonly<Record<string, () => Promise<void>>>;\n\n/**\n * One entity whose served affordances contribute palette commands.\n *\n * The source comes one of two ways, and exactly one: built and handed over, or\n * read from the host's composition by a hook — typically\n * `() => useHostAdapters().userMetadata` — so the module declaring the entries\n * need not import the transport that fetches.\n */\nexport type UseCaseCommandEntity<TEntity extends Entity = Entity> = {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly handlers: UseCaseHandlers;\n} & (\n | {\n /** Where `GET /api/<entity>/$metadata` is reached. */\n readonly metadataSource: EntityMetadataSource;\n readonly useMetadataSource?: never;\n }\n | {\n /** Resolves the source from composition. Called as a hook, once per render. */\n readonly useMetadataSource: () => EntityMetadataSource;\n readonly metadataSource?: never;\n }\n);\n\n/**\n * The `unbound` verbs this caller may invoke, as one group.\n *\n * This is the surface the action placement map named and nothing rendered: all three\n * `unbound:*` cells resolve to `'command-palette'`, and until now the palette\n * did not exist, so a verb declared there was granted, exported, passed every\n * check the host's register ran and simply never appeared.\n *\n * The descriptors are **served, not imported**: `$metadata` filters them through\n * `PolicyDecisionTag` against the verified principal, which is a stronger check\n * than anything the browser could do — and it keeps every `@useCase()` class's\n * `Effect` body, repository tags and import closure out of the client bundle.\n *\n * ⚠️ A descriptor with **no handler throws**, at the first render of the\n * palette rather than on the click. A verb that appears and does nothing is\n * worse than one that is absent: it reads as a broken feature rather than a\n * missing wire, and it is the same posture `assertSearchable` and `surfaceFor`\n * already take.\n */\nfunction useUseCasesSource(\n entity: UseCaseCommandEntity,\n term: string,\n): CommandSource {\n const t = useT('shell');\n const translateKey = useTranslateKey();\n // The entries are module-scope, so which branch an entity takes never changes\n // between renders and the hook count stays fixed.\n const useSource = entity.useMetadataSource ?? (() => entity.metadataSource);\n const { metadata, isLoading } = useEntityUseCases(\n entity.entityConstructor,\n useSource(),\n );\n\n // Outside the memo: `useCasesForSurface` is a plain filter, but the name reads\n // as a hook to `react-hooks/rules-of-hooks`, which then refuses it inside a\n // callback. Hoisting is free — it is pure and cheap.\n const descriptors = useCasesForSurface('command-palette', metadata?.useCases);\n\n return useMemo(() => {\n const name = envelopeEntityName(entity.entityConstructor);\n\n const options: CommandOption[] = descriptors.map(descriptor => {\n const run = entity.handlers[descriptor.key];\n if (run === undefined) {\n throw new Error(\n `The use case \"${descriptor.key}\" on ${name} reaches the command palette but this host registered no handler for it. ` +\n 'Add one to the entity’s `handlers`, or stop declaring the verb `unbound`.',\n );\n }\n\n return {\n id: `use-case:${name}:${descriptor.key}`,\n label: translateKey(descriptor.labelKey),\n keywords: parseKeywords(\n descriptor.keywordsKey === undefined\n ? undefined\n : translateKey(descriptor.keywordsKey),\n ),\n run,\n ...(descriptor.confirm === undefined\n ? {}\n : {\n confirm: {\n tone: descriptor.confirm.tone,\n message: translateKey(descriptor.confirm.messageKey),\n },\n }),\n } satisfies CommandOption;\n });\n\n return {\n key: `use-cases:${name}`,\n groups: [\n {\n key: `use-cases:${name}`,\n label: t('commandPalette.groups.actions'),\n options: options.filter(option => matchesCommand(term, option)),\n isLoading,\n },\n ],\n } satisfies CommandSource;\n }, [entity, descriptors, isLoading, term, t, translateKey]);\n}\n\n/**\n * Every declared entity's palette verbs, as one source per entity.\n *\n * **Why the rule is disabled below.** `entities` is declared once at module\n * scope by the host and closed over, so it is the same array on every render and\n * the hook count is fixed — the invariant `react-hooks/rules-of-hooks` protects\n * and cannot see, because it reasons about the loop syntactically rather than\n * about the array's provenance. It is isolated here so the disable is written\n * once, with its reason, exactly as `useEntityLinkSources` does for pickers.\n */\nexport function useUseCaseSources(\n entities: readonly UseCaseCommandEntity[],\n term: string,\n): CommandSource[] {\n const sources: CommandSource[] = [];\n for (const entity of entities) {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- fixed-length loop over a module-scope array; see the note above.\n sources.push(useUseCasesSource(entity, term));\n }\n return sources;\n}\n"],"names":["envelopeEntityName","matchesCommand","parseKeywords","useCasesForSurface","useT","useTranslateKey","useEntityUseCases","useMemo","useUseCasesSource","entity","term","t","translateKey","useSource","useMetadataSource","metadataSource","metadata","isLoading","entityConstructor","descriptors","useCases","name","options","map","descriptor","run","handlers","key","undefined","Error","id","label","labelKey","keywords","keywordsKey","confirm","tone","message","messageKey","groups","filter","option","useUseCaseSources","entities","sources","push"],"mappings":"AAAA;;AAEA,SAMEA,kBAAkB,EAClBC,cAAc,EACdC,aAAa,QACR,gBAAgB;AACvB,SACEC,kBAAkB,EAClBC,IAAI,EACJC,eAAe,QACV,0BAA0B;AACjC,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,OAAO,QAAQ,QAAQ;AA6BhC;;;;;;;;;;;;;;;;;;CAkBC,GACD,SAASC,kBACPC,MAA4B,EAC5BC,IAAY;QAMMD;IAJlB,MAAME,IAAIP,KAAK;IACf,MAAMQ,eAAeP;IACrB,8EAA8E;IAC9E,kDAAkD;IAClD,MAAMQ,aAAYJ,4BAAAA,OAAOK,iBAAiB,YAAxBL,4BAA6B,IAAMA,OAAOM,cAAc;IAC1E,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGX,kBAC9BG,OAAOS,iBAAiB,EACxBL;IAGF,+EAA+E;IAC/E,4EAA4E;IAC5E,qDAAqD;IACrD,MAAMM,cAAchB,mBAAmB,mBAAmBa,4BAAAA,SAAUI,QAAQ;IAE5E,OAAOb,QAAQ;QACb,MAAMc,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/command-palette/use-use-cases-source.ts"],"sourcesContent":["'use client';\n\nimport {\n type CommandOption,\n type CommandSource,\n type Entity,\n type EntityConstructor,\n type EntityMetadataSource,\n envelopeEntityName,\n matchesCommand,\n parseKeywords,\n} from '@entifix/core';\nimport {\n shortcutLabel,\n useCasesForSurface,\n useT,\n useTranslateKey,\n} from '@entifix/react-controls';\nimport { useEntityUseCases } from '@entifix/react-integration';\nimport { useMemo } from 'react';\n\n/** How a declared verb is actually carried out, keyed by the verb. */\nexport type UseCaseHandlers = Readonly<Record<string, () => Promise<void>>>;\n\n/**\n * One entity whose served affordances contribute palette commands.\n *\n * The source comes one of two ways, and exactly one: built and handed over, or\n * read from the host's composition by a hook — typically\n * `() => useHostAdapters().userMetadata` — so the module declaring the entries\n * need not import the transport that fetches.\n */\nexport type UseCaseCommandEntity<TEntity extends Entity = Entity> = {\n readonly entityConstructor: EntityConstructor<TEntity>;\n readonly handlers: UseCaseHandlers;\n} & (\n | {\n /** Where `GET /api/<entity>/$metadata` is reached. */\n readonly metadataSource: EntityMetadataSource;\n readonly useMetadataSource?: never;\n }\n | {\n /** Resolves the source from composition. Called as a hook, once per render. */\n readonly useMetadataSource: () => EntityMetadataSource;\n readonly metadataSource?: never;\n }\n);\n\n/**\n * The `unbound` verbs this caller may invoke, as one group.\n *\n * This is the surface the action placement map named and nothing rendered: all three\n * `unbound:*` cells resolve to `'command-palette'`, and until now the palette\n * did not exist, so a verb declared there was granted, exported, passed every\n * check the host's register ran and simply never appeared.\n *\n * The descriptors are **served, not imported**: `$metadata` filters them through\n * `PolicyDecisionTag` against the verified principal, which is a stronger check\n * than anything the browser could do — and it keeps every `@useCase()` class's\n * `Effect` body, repository tags and import closure out of the client bundle.\n *\n * ⚠️ A descriptor with **no handler throws**, at the first render of the\n * palette rather than on the click. A verb that appears and does nothing is\n * worse than one that is absent: it reads as a broken feature rather than a\n * missing wire, and it is the same posture `assertSearchable` and `surfaceFor`\n * already take.\n */\nfunction useUseCasesSource(\n entity: UseCaseCommandEntity,\n term: string,\n): CommandSource {\n const t = useT('shell');\n const translateKey = useTranslateKey();\n // The entries are module-scope, so which branch an entity takes never changes\n // between renders and the hook count stays fixed.\n const useSource = entity.useMetadataSource ?? (() => entity.metadataSource);\n const { metadata, isLoading } = useEntityUseCases(\n entity.entityConstructor,\n useSource(),\n );\n\n // Outside the memo: `useCasesForSurface` is a plain filter, but the name reads\n // as a hook to `react-hooks/rules-of-hooks`, which then refuses it inside a\n // callback. Hoisting is free — it is pure and cheap.\n const descriptors = useCasesForSurface('command-palette', metadata?.useCases);\n\n return useMemo(() => {\n const name = envelopeEntityName(entity.entityConstructor);\n\n const options: CommandOption[] = descriptors.map(descriptor => {\n const run = entity.handlers[descriptor.key];\n if (run === undefined) {\n throw new Error(\n `The use case \"${descriptor.key}\" on ${name} reaches the command palette but this host registered no handler for it. ` +\n 'Add one to the entity’s `handlers`, or stop declaring the verb `unbound`.',\n );\n }\n\n return {\n id: `use-case:${name}:${descriptor.key}`,\n label: translateKey(descriptor.labelKey),\n keywords: parseKeywords(\n descriptor.keywordsKey === undefined\n ? undefined\n : translateKey(descriptor.keywordsKey),\n ),\n run,\n // Listed with its shortcut, so the palette teaches the chord.\n ...(descriptor.shortcut === undefined\n ? {}\n : { hint: shortcutLabel(descriptor.shortcut) }),\n ...(descriptor.confirm === undefined\n ? {}\n : {\n confirm: {\n tone: descriptor.confirm.tone,\n message: translateKey(descriptor.confirm.messageKey),\n },\n }),\n } satisfies CommandOption;\n });\n\n return {\n key: `use-cases:${name}`,\n groups: [\n {\n key: `use-cases:${name}`,\n label: t('commandPalette.groups.actions'),\n options: options.filter(option => matchesCommand(term, option)),\n isLoading,\n },\n ],\n } satisfies CommandSource;\n }, [entity, descriptors, isLoading, term, t, translateKey]);\n}\n\n/**\n * Every declared entity's palette verbs, as one source per entity.\n *\n * **Why the rule is disabled below.** `entities` is declared once at module\n * scope by the host and closed over, so it is the same array on every render and\n * the hook count is fixed — the invariant `react-hooks/rules-of-hooks` protects\n * and cannot see, because it reasons about the loop syntactically rather than\n * about the array's provenance. It is isolated here so the disable is written\n * once, with its reason, exactly as `useEntityLinkSources` does for pickers.\n */\nexport function useUseCaseSources(\n entities: readonly UseCaseCommandEntity[],\n term: string,\n): CommandSource[] {\n const sources: CommandSource[] = [];\n for (const entity of entities) {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- fixed-length loop over a module-scope array; see the note above.\n sources.push(useUseCasesSource(entity, term));\n }\n return sources;\n}\n"],"names":["envelopeEntityName","matchesCommand","parseKeywords","shortcutLabel","useCasesForSurface","useT","useTranslateKey","useEntityUseCases","useMemo","useUseCasesSource","entity","term","t","translateKey","useSource","useMetadataSource","metadataSource","metadata","isLoading","entityConstructor","descriptors","useCases","name","options","map","descriptor","run","handlers","key","undefined","Error","id","label","labelKey","keywords","keywordsKey","shortcut","hint","confirm","tone","message","messageKey","groups","filter","option","useUseCaseSources","entities","sources","push"],"mappings":"AAAA;;AAEA,SAMEA,kBAAkB,EAClBC,cAAc,EACdC,aAAa,QACR,gBAAgB;AACvB,SACEC,aAAa,EACbC,kBAAkB,EAClBC,IAAI,EACJC,eAAe,QACV,0BAA0B;AACjC,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,OAAO,QAAQ,QAAQ;AA6BhC;;;;;;;;;;;;;;;;;;CAkBC,GACD,SAASC,kBACPC,MAA4B,EAC5BC,IAAY;QAMMD;IAJlB,MAAME,IAAIP,KAAK;IACf,MAAMQ,eAAeP;IACrB,8EAA8E;IAC9E,kDAAkD;IAClD,MAAMQ,aAAYJ,4BAAAA,OAAOK,iBAAiB,YAAxBL,4BAA6B,IAAMA,OAAOM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AAaF;QAAWP;QAAMC;QAAGC;KAAa;AAC5D;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASgC,kBACdC,QAAyC,EACzCnC,IAAY;IAEZ,MAAMoC,UAA2B,EAAE;IACnC,KAAK,MAAMrC,UAAUoC,SAAU;QAC7B,0HAA0H;QAC1HC,QAAQC,IAAI,CAACvC,kBAAkBC,QAAQC;IACzC;IACA,OAAOoC;AACT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field a confirmed post carries. A form posted without it has not been
|
|
3
|
+
* through the confirmation, so {@link whenConfirmed} does not act on it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CONFIRM_FIELD = "__confirm";
|
|
6
|
+
/** The field the interstitial's Cancel posts, to step back without acting. */
|
|
7
|
+
export declare const CANCEL_FIELD = "__cancel";
|
|
8
|
+
/**
|
|
9
|
+
* Where a {@link ConfirmAction} stands: showing its trigger, or — after a post
|
|
10
|
+
* that skipped the confirmation — asking.
|
|
11
|
+
*/
|
|
12
|
+
export interface ConfirmActionState {
|
|
13
|
+
readonly step: 'idle' | 'confirm';
|
|
14
|
+
}
|
|
15
|
+
export declare const CONFIRM_ACTION_IDLE: ConfirmActionState;
|
|
16
|
+
/**
|
|
17
|
+
* The guard a Server Action behind a `ConfirmAction` runs first
|
|
18
|
+
* ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
19
|
+
*
|
|
20
|
+
* It acts only on a post that carries {@link CONFIRM_FIELD}, so a form posted
|
|
21
|
+
* straight to the action — a script, a stale page, a first post without
|
|
22
|
+
* JavaScript — is answered with the confirmation step instead. The check lives
|
|
23
|
+
* in the action, not the page, because the action is what a post reaches.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* 'use server';
|
|
27
|
+
* export async function cancelOrder(state: ConfirmActionState, form: FormData) {
|
|
28
|
+
* return whenConfirmed(form, () => orders.cancel(String(form.get('id'))));
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function whenConfirmed(formData: FormData, act: () => unknown): Promise<ConfirmActionState>;
|
|
33
|
+
//# sourceMappingURL=confirm-action-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-action-state.d.ts","sourceRoot":"","sources":["../../../src/lib/confirm-action/confirm-action-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,8EAA8E;AAC9E,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,eAAO,MAAM,mBAAmB,EAAE,kBAAqC,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,MAAM,OAAO,GACjB,OAAO,CAAC,kBAAkB,CAAC,CAK7B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field a confirmed post carries. A form posted without it has not been
|
|
3
|
+
* through the confirmation, so {@link whenConfirmed} does not act on it.
|
|
4
|
+
*/ export const CONFIRM_FIELD = '__confirm';
|
|
5
|
+
/** The field the interstitial's Cancel posts, to step back without acting. */ export const CANCEL_FIELD = '__cancel';
|
|
6
|
+
export const CONFIRM_ACTION_IDLE = {
|
|
7
|
+
step: 'idle'
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The guard a Server Action behind a `ConfirmAction` runs first
|
|
11
|
+
* ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
12
|
+
*
|
|
13
|
+
* It acts only on a post that carries {@link CONFIRM_FIELD}, so a form posted
|
|
14
|
+
* straight to the action — a script, a stale page, a first post without
|
|
15
|
+
* JavaScript — is answered with the confirmation step instead. The check lives
|
|
16
|
+
* in the action, not the page, because the action is what a post reaches.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* 'use server';
|
|
20
|
+
* export async function cancelOrder(state: ConfirmActionState, form: FormData) {
|
|
21
|
+
* return whenConfirmed(form, () => orders.cancel(String(form.get('id'))));
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/ export async function whenConfirmed(formData, act) {
|
|
25
|
+
if (formData.get(CANCEL_FIELD) !== null) return CONFIRM_ACTION_IDLE;
|
|
26
|
+
if (formData.get(CONFIRM_FIELD) !== '1') return {
|
|
27
|
+
step: 'confirm'
|
|
28
|
+
};
|
|
29
|
+
await act();
|
|
30
|
+
return CONFIRM_ACTION_IDLE;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=confirm-action-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/confirm-action/confirm-action-state.ts"],"sourcesContent":["/**\n * The field a confirmed post carries. A form posted without it has not been\n * through the confirmation, so {@link whenConfirmed} does not act on it.\n */\nexport const CONFIRM_FIELD = '__confirm';\n\n/** The field the interstitial's Cancel posts, to step back without acting. */\nexport const CANCEL_FIELD = '__cancel';\n\n/**\n * Where a {@link ConfirmAction} stands: showing its trigger, or — after a post\n * that skipped the confirmation — asking.\n */\nexport interface ConfirmActionState {\n readonly step: 'idle' | 'confirm';\n}\n\nexport const CONFIRM_ACTION_IDLE: ConfirmActionState = { step: 'idle' };\n\n/**\n * The guard a Server Action behind a `ConfirmAction` runs first\n * ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n *\n * It acts only on a post that carries {@link CONFIRM_FIELD}, so a form posted\n * straight to the action — a script, a stale page, a first post without\n * JavaScript — is answered with the confirmation step instead. The check lives\n * in the action, not the page, because the action is what a post reaches.\n *\n * ```ts\n * 'use server';\n * export async function cancelOrder(state: ConfirmActionState, form: FormData) {\n * return whenConfirmed(form, () => orders.cancel(String(form.get('id'))));\n * }\n * ```\n */\nexport async function whenConfirmed(\n formData: FormData,\n act: () => unknown,\n): Promise<ConfirmActionState> {\n if (formData.get(CANCEL_FIELD) !== null) return CONFIRM_ACTION_IDLE;\n if (formData.get(CONFIRM_FIELD) !== '1') return { step: 'confirm' };\n await act();\n return CONFIRM_ACTION_IDLE;\n}\n"],"names":["CONFIRM_FIELD","CANCEL_FIELD","CONFIRM_ACTION_IDLE","step","whenConfirmed","formData","act","get"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,gBAAgB,YAAY;AAEzC,4EAA4E,GAC5E,OAAO,MAAMC,eAAe,WAAW;AAUvC,OAAO,MAAMC,sBAA0C;IAAEC,MAAM;AAAO,EAAE;AAExE;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeC,cACpBC,QAAkB,EAClBC,GAAkB;IAElB,IAAID,SAASE,GAAG,CAACN,kBAAkB,MAAM,OAAOC;IAChD,IAAIG,SAASE,GAAG,CAACP,mBAAmB,KAAK,OAAO;QAAEG,MAAM;IAAU;IAClE,MAAMG;IACN,OAAOJ;AACT"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ConfirmDialogProps } from '@entifix/react-controls';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type ConfirmActionState } from './confirm-action-state.js';
|
|
4
|
+
/** A Server Action written with `whenConfirmed`, as `useActionState` calls it. */
|
|
5
|
+
export type ConfirmActionHandler = (state: ConfirmActionState, formData: FormData) => Promise<ConfirmActionState>;
|
|
6
|
+
export interface ConfirmActionProps extends Pick<ConfirmDialogProps, 'title' | 'message' | 'tone' | 'confirmLabel' | 'cancelLabel'> {
|
|
7
|
+
/** The Server Action, guarded by `whenConfirmed`. */
|
|
8
|
+
action: ConfirmActionHandler;
|
|
9
|
+
/** Posted with both steps as hidden inputs — the record's id, typically. */
|
|
10
|
+
fields?: Readonly<Record<string, string>>;
|
|
11
|
+
/** The trigger's label: the verb, as the page offers it. */
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Server Action form that asks before it acts, with or without JavaScript
|
|
16
|
+
* ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
17
|
+
*
|
|
18
|
+
* - **Without JavaScript** the trigger posts, the action answers with the
|
|
19
|
+
* confirmation step (`whenConfirmed` sees no confirmation field), and the
|
|
20
|
+
* page renders an interstitial with the title, the consequence and the verb.
|
|
21
|
+
* Its button posts again, carrying the field, and only that post acts.
|
|
22
|
+
* - **With JavaScript** the trigger opens a native `<dialog>` with the same
|
|
23
|
+
* copy, Cancel focused, and its button posts the confirmed form.
|
|
24
|
+
*
|
|
25
|
+
* The copy is `ConfirmDialog`'s text slots, already resolved by the page.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ConfirmAction({ action, fields, title, message, tone, confirmLabel, cancelLabel, children, }: ConfirmActionProps): import("react").JSX.Element;
|
|
28
|
+
//# sourceMappingURL=confirm-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-action.d.ts","sourceRoot":"","sources":["../../../src/lib/confirm-action/confirm-action.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,kBAAkB,EAAQ,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,OAAO,CAAC;AAEtE,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,2BAA2B,CAAC;AAEnC,kFAAkF;AAClF,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,QAAQ,KACf,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAC9C,kBAAkB,EAClB,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,GAAG,aAAa,CAC9D;IACC,qDAAqD;IACrD,MAAM,EAAE,oBAAoB,CAAC;IAC7B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,4DAA4D;IAC5D,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,MAAW,EACX,KAAK,EACL,OAAO,EACP,IAAgB,EAChB,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,EAAE,kBAAkB,+BAyGpB"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Button, useT } from '@entifix/react-controls';
|
|
4
|
+
import { useActionState, useId, useRef } from 'react';
|
|
5
|
+
import { CANCEL_FIELD, CONFIRM_ACTION_IDLE, CONFIRM_FIELD } from './confirm-action-state.js';
|
|
6
|
+
/**
|
|
7
|
+
* A Server Action form that asks before it acts, with or without JavaScript
|
|
8
|
+
* ([ADR 0026](../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
9
|
+
*
|
|
10
|
+
* - **Without JavaScript** the trigger posts, the action answers with the
|
|
11
|
+
* confirmation step (`whenConfirmed` sees no confirmation field), and the
|
|
12
|
+
* page renders an interstitial with the title, the consequence and the verb.
|
|
13
|
+
* Its button posts again, carrying the field, and only that post acts.
|
|
14
|
+
* - **With JavaScript** the trigger opens a native `<dialog>` with the same
|
|
15
|
+
* copy, Cancel focused, and its button posts the confirmed form.
|
|
16
|
+
*
|
|
17
|
+
* The copy is `ConfirmDialog`'s text slots, already resolved by the page.
|
|
18
|
+
*/ export function ConfirmAction({ action, fields = {}, title, message, tone = 'neutral', confirmLabel, cancelLabel, children }) {
|
|
19
|
+
const t = useT();
|
|
20
|
+
const [state, formAction, pending] = useActionState(action, CONFIRM_ACTION_IDLE);
|
|
21
|
+
const dialog = useRef(null);
|
|
22
|
+
const titleId = useId();
|
|
23
|
+
const messageId = useId();
|
|
24
|
+
const hidden = Object.entries(fields).map(([name, value])=>/*#__PURE__*/ _jsx("input", {
|
|
25
|
+
type: "hidden",
|
|
26
|
+
name: name,
|
|
27
|
+
value: value
|
|
28
|
+
}, name));
|
|
29
|
+
const cancelText = cancelLabel != null ? cancelLabel : t('confirm.cancel');
|
|
30
|
+
const confirmButton = /*#__PURE__*/ _jsx(Button, {
|
|
31
|
+
type: "submit",
|
|
32
|
+
name: CONFIRM_FIELD,
|
|
33
|
+
value: "1",
|
|
34
|
+
variant: tone === 'destructive' ? 'destructive' : 'primary',
|
|
35
|
+
disabled: pending,
|
|
36
|
+
onClick: ()=>{
|
|
37
|
+
var _dialog_current;
|
|
38
|
+
return (_dialog_current = dialog.current) == null ? void 0 : _dialog_current.close();
|
|
39
|
+
},
|
|
40
|
+
children: confirmLabel != null ? confirmLabel : t('confirm.confirm')
|
|
41
|
+
});
|
|
42
|
+
const copy = /*#__PURE__*/ _jsxs(_Fragment, {
|
|
43
|
+
children: [
|
|
44
|
+
/*#__PURE__*/ _jsx("h2", {
|
|
45
|
+
id: titleId,
|
|
46
|
+
className: "text-step-1 font-semibold text-content",
|
|
47
|
+
children: title
|
|
48
|
+
}),
|
|
49
|
+
/*#__PURE__*/ _jsx("p", {
|
|
50
|
+
id: messageId,
|
|
51
|
+
className: "mt-2xs text-step-sm text-content-muted",
|
|
52
|
+
children: message
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
if (state.step === 'confirm') return /*#__PURE__*/ _jsxs("section", {
|
|
57
|
+
"aria-labelledby": titleId,
|
|
58
|
+
"data-testid": "confirm-action-step",
|
|
59
|
+
className: "max-w-md rounded-lg border border-border bg-surface p-s",
|
|
60
|
+
children: [
|
|
61
|
+
copy,
|
|
62
|
+
/*#__PURE__*/ _jsxs("form", {
|
|
63
|
+
action: formAction,
|
|
64
|
+
className: "mt-s flex justify-end gap-xs",
|
|
65
|
+
children: [
|
|
66
|
+
hidden,
|
|
67
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
68
|
+
type: "submit",
|
|
69
|
+
name: CANCEL_FIELD,
|
|
70
|
+
value: "1",
|
|
71
|
+
variant: "ghost",
|
|
72
|
+
disabled: pending,
|
|
73
|
+
children: cancelText
|
|
74
|
+
}),
|
|
75
|
+
confirmButton
|
|
76
|
+
]
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
return /*#__PURE__*/ _jsxs("form", {
|
|
81
|
+
action: formAction,
|
|
82
|
+
onSubmit: (event)=>{
|
|
83
|
+
var _dialog_current, _dialog_current_querySelector, _dialog_current1;
|
|
84
|
+
const submitter = event.nativeEvent.submitter;
|
|
85
|
+
if ((submitter == null ? void 0 : submitter.getAttribute('name')) === CONFIRM_FIELD) return;
|
|
86
|
+
// Asked here, before the post; the action asks again if this is skipped.
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
(_dialog_current = dialog.current) == null ? void 0 : _dialog_current.showModal();
|
|
89
|
+
(_dialog_current1 = dialog.current) == null ? void 0 : (_dialog_current_querySelector = _dialog_current1.querySelector('[data-confirm-cancel]')) == null ? void 0 : _dialog_current_querySelector.focus();
|
|
90
|
+
},
|
|
91
|
+
children: [
|
|
92
|
+
hidden,
|
|
93
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
94
|
+
type: "submit",
|
|
95
|
+
variant: tone === 'destructive' ? 'destructive' : 'secondary',
|
|
96
|
+
disabled: pending,
|
|
97
|
+
children: children
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ _jsxs("dialog", {
|
|
100
|
+
ref: dialog,
|
|
101
|
+
role: "alertdialog",
|
|
102
|
+
"aria-labelledby": titleId,
|
|
103
|
+
"aria-describedby": messageId,
|
|
104
|
+
className: "max-w-md m-auto w-full rounded-lg border border-border bg-surface p-s text-content shadow-overlay backdrop:bg-scrim",
|
|
105
|
+
children: [
|
|
106
|
+
copy,
|
|
107
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
108
|
+
className: "mt-s flex justify-end gap-xs",
|
|
109
|
+
children: [
|
|
110
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
111
|
+
"data-confirm-cancel": true,
|
|
112
|
+
type: "button",
|
|
113
|
+
variant: "ghost",
|
|
114
|
+
onClick: ()=>{
|
|
115
|
+
var _dialog_current;
|
|
116
|
+
return (_dialog_current = dialog.current) == null ? void 0 : _dialog_current.close();
|
|
117
|
+
},
|
|
118
|
+
children: cancelText
|
|
119
|
+
}),
|
|
120
|
+
confirmButton
|
|
121
|
+
]
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=confirm-action.js.map
|