frontile 0.18.12 → 0.18.13
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/declarations/components/layout/app-layout.d.ts +53 -5
- package/declarations/components/layout/app-layout.d.ts.map +1 -1
- package/declarations/components/layout/aside.d.ts +79 -0
- package/declarations/components/layout/aside.d.ts.map +1 -1
- package/declarations/components/layout/context.d.ts +12 -4
- package/declarations/components/layout/context.d.ts.map +1 -1
- package/declarations/components/layout/in-layout-region.d.ts +38 -0
- package/declarations/components/layout/in-layout-region.d.ts.map +1 -0
- package/declarations/components/layout/index.d.ts +2 -0
- package/declarations/components/layout/index.d.ts.map +1 -1
- package/declarations/components/layout/navbar.d.ts +43 -0
- package/declarations/components/layout/navbar.d.ts.map +1 -1
- package/declarations/components/layout/region.d.ts +60 -0
- package/declarations/components/layout/region.d.ts.map +1 -0
- package/declarations/components/layout/sidebar.d.ts +43 -0
- package/declarations/components/layout/sidebar.d.ts.map +1 -1
- package/declarations/components/overlays/tooltip.d.ts +1 -1
- package/declarations/components/status/badge.d.ts +4 -4
- package/declarations/components/status/badge.d.ts.map +1 -1
- package/declarations/services/frontile-layout-regions.d.ts +69 -0
- package/declarations/services/frontile-layout-regions.d.ts.map +1 -0
- package/dist/_app_/services/frontile-layout-regions.js +1 -0
- package/dist/components/layout/app-layout.js +11 -3
- package/dist/components/layout/app-layout.js.map +1 -1
- package/dist/components/layout/aside.js +56 -2
- package/dist/components/layout/aside.js.map +1 -1
- package/dist/components/layout/context.js.map +1 -1
- package/dist/components/layout/in-layout-region.js +42 -0
- package/dist/components/layout/in-layout-region.js.map +1 -0
- package/dist/components/layout/index.js +2 -0
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/layout/region.js +51 -0
- package/dist/components/layout/region.js.map +1 -0
- package/dist/components/overlays/tooltip.js.map +1 -1
- package/dist/components/status/badge.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/layout.js +2 -0
- package/dist/layout.js.map +1 -1
- package/dist/services/frontile-layout-regions.js +149 -0
- package/dist/services/frontile-layout-regions.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
3
|
+
import { modifier } from 'ember-modifier';
|
|
4
|
+
import { standaloneStyles } from './context.js';
|
|
5
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
6
|
+
import { setComponentTemplate } from '@ember/component';
|
|
7
|
+
import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../../runtime--fcdnjmJ-DOFHQ2m8.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A named place in the layout that any template, including a route template
|
|
11
|
+
* inside `{{outlet}}`, fills with `InLayoutRegion`. Its element is
|
|
12
|
+
* `display: contents`, so the content lays out as if it were written where
|
|
13
|
+
* the region sits. `data-has-content` is `true` while a source fills it.
|
|
14
|
+
*/
|
|
15
|
+
class Region extends Component {
|
|
16
|
+
static {
|
|
17
|
+
decorateFieldV2(this.prototype, "regions", [service('frontile-layout-regions')]);
|
|
18
|
+
}
|
|
19
|
+
#regions = (initializeDeferredDecorator(this, "regions"), void 0);
|
|
20
|
+
/** `@name`, read once. */name;
|
|
21
|
+
/** `@multiple`, read once. */
|
|
22
|
+
multiple;
|
|
23
|
+
constructor(owner, args) {
|
|
24
|
+
super(owner, args);
|
|
25
|
+
this.name = args.name;
|
|
26
|
+
this.multiple = args.multiple ?? false;
|
|
27
|
+
}
|
|
28
|
+
register = modifier(element => this.regions.registerTarget(this.name, element, {
|
|
29
|
+
multiple: this.multiple
|
|
30
|
+
}));
|
|
31
|
+
get classNames() {
|
|
32
|
+
const styles = this.args.layout?.styles ?? standaloneStyles();
|
|
33
|
+
return styles.region({
|
|
34
|
+
class: this.args.layout?.classes?.region
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
get hasContent() {
|
|
38
|
+
return this.regions.hasContent(this.name);
|
|
39
|
+
}
|
|
40
|
+
get hasContentString() {
|
|
41
|
+
return this.hasContent ? 'true' : 'false';
|
|
42
|
+
}
|
|
43
|
+
static {
|
|
44
|
+
setComponentTemplate(precompileTemplate("<div data-part=\"region\" data-region={{this.name}} data-has-content={{this.hasContentString}} class={{this.classNames}} {{this.register}} ...attributes>\n {{#unless this.hasContent}}{{yield}}{{/unless}}\n</div>", {
|
|
45
|
+
strictMode: true
|
|
46
|
+
}), this);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { Region, Region as default };
|
|
51
|
+
//# sourceMappingURL=region.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"region.js","sources":["../../../src/components/layout/region.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { service } from '@ember/service';\nimport { modifier } from 'ember-modifier';\nimport { standaloneStyles, type AppLayoutContext } from './context';\nimport type FrontileLayoutRegionsService from '../../services/frontile-layout-regions';\nimport type Owner from '@ember/owner';\n\ninterface RegionArgs {\n /**\n * The region's name, matched by `InLayoutRegion @name`. Names are global\n * to the app. Read once, when the region renders.\n */\n name: string;\n\n /**\n * Render every source, in the order they rendered, instead of only the\n * newest. After the region renders again, sources follow template order.\n * Read once, when the region renders.\n *\n * @defaultValue false\n */\n multiple?: boolean;\n\n /**\n * Supplied by `AppLayout`. Not part of the public API.\n *\n * @internal\n */\n layout?: AppLayoutContext;\n}\n\ninterface RegionSignature {\n Args: RegionArgs;\n Blocks: {\n /** Rendered while no `InLayoutRegion` fills the region. */\n default: [];\n };\n Element: HTMLDivElement;\n}\n\n/**\n * A named place in the layout that any template, including a route template\n * inside `{{outlet}}`, fills with `InLayoutRegion`. Its element is\n * `display: contents`, so the content lays out as if it were written where\n * the region sits. `data-has-content` is `true` while a source fills it.\n */\nclass Region extends Component<RegionSignature> {\n @service('frontile-layout-regions')\n declare regions: FrontileLayoutRegionsService;\n\n /** `@name`, read once. */\n name: string;\n /** `@multiple`, read once. */\n multiple: boolean;\n\n constructor(owner: Owner, args: RegionArgs) {\n super(owner, args);\n this.name = args.name;\n this.multiple = args.multiple ?? false;\n }\n\n register = modifier((element: HTMLElement) =>\n this.regions.registerTarget(this.name, element, {\n multiple: this.multiple\n })\n );\n\n get classNames(): string {\n const styles = this.args.layout?.styles ?? standaloneStyles();\n return styles.region({ class: this.args.layout?.classes?.region });\n }\n\n get hasContent(): boolean {\n return this.regions.hasContent(this.name);\n }\n\n get hasContentString(): 'true' | 'false' {\n return this.hasContent ? 'true' : 'false';\n }\n\n <template>\n <div\n data-part=\"region\"\n data-region={{this.name}}\n data-has-content={{this.hasContentString}}\n class={{this.classNames}}\n {{this.register}}\n ...attributes\n >\n {{#unless this.hasContent}}{{yield}}{{/unless}}\n </div>\n </template>\n}\n\nexport { Region, type RegionSignature, type RegionArgs };\nexport default Region;\n"],"names":["Region","Component","g","prototype","service","i","name","multiple","constructor","owner","args","register","modifier","element","regions","registerTarget","classNames","styles","layout","standaloneStyles","region","class","classes","hasContent","hasContentString","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;;;;AAwCA;;;;;;AAMA,MAAMA,eAAeC,SAAA,CAAU;AAAA,EAAA;AAAAC,IAAAA,eAAA,MAAAC,SAAA,EAAA,SAAA,EAAA,CAC5BC,OAAA,CAAQ,yBAAA,CAAA,CAAA,CAAA;AAAA;EAAA,QAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,EAAA,MAAA;AAGT,4BACAC,IAAA;AACA;EACAC,QAAA;AAEAC,EAAAA,WAAAA,CAAYC,KAAY,EAAEC,IAAgB,EAAE;AAC1C,IAAA,KAAK,CAACD,KAAA,EAAOC,IAAA,CAAA;AACb,IAAA,IAAI,CAACJ,IAAI,GAAGI,IAAA,CAAKJ,IAAI;AACrB,IAAA,IAAI,CAACC,QAAQ,GAAGG,IAAA,CAAKH,QAAQ,IAAI,KAAA;AACnC,EAAA;AAEAI,EAAAA,QAAA,GAAWC,QAAA,CAAUC,OAAS,IAC5B,IAAI,CAACC,OAAO,CAACC,cAAc,CAAC,IAAI,CAACT,IAAI,EAAEO,OAAA,EAAS;IAC9CN,QAAA,EAAU,IAAI,CAACA;AACjB,GAAA,CAAA,CAAA;EAGF,IAAIS,UAAAA,GAAqB;AACvB,IAAA,MAAMC,SAAS,IAAI,CAACP,IAAI,CAACQ,MAAM,EAAED,MAAA,IAAUE,gBAAA,EAAA;IAC3C,OAAOF,MAAA,CAAOG,MAAM,CAAC;MAAEC,KAAA,EAAO,IAAI,CAACX,IAAI,CAACQ,MAAM,EAAEI,OAAA,EAASF;AAAO,KAAA,CAAA;AAClE,EAAA;EAEA,IAAIG,UAAAA,GAAsB;IACxB,OAAO,IAAI,CAACT,OAAO,CAACS,UAAU,CAAC,IAAI,CAACjB,IAAI,CAAA;AAC1C,EAAA;EAEA,IAAIkB,gBAAAA,GAAqC;AACvC,IAAA,OAAO,IAAI,CAACD,UAAU,GAAG,MAAA,GAAS,OAAA;AACpC,EAAA;AAEA,EAAA;IAAAE,oBAAA,CAAAC,kBAAA,CAAA,sNAAA,EAWA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sources":["../../../src/components/overlays/tooltip.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\nimport { hash } from '@ember/helper';\nimport { modifier } from 'ember-modifier';\n\nimport { next, cancel } from '@ember/runloop';\nimport type { Timer as EmberTimer } from '@ember/runloop';\nimport { useStyles } from '@frontile/theme';\nimport { Popover, type PopoverSignature } from './popover';\nimport type {\n TooltipVariants,\n TooltipSlots,\n SlotsToClasses\n} from '@frontile/theme';\nimport type { ModifierLike, WithBoundArgs } from '@glint/template';\nimport type Owner from '@ember/owner';\n\n/**\n * The type of `Popover`'s yielded `Content`, already bound to its internal\n * wiring (`loop`, `isOpen`, `id`, ...). Reusing this instead of\n * `ComponentLike<ContentSignature>` matters: the latter is the *unbound*\n * signature, so invoking it in a template would again require every one of\n * those internal args -- exactly what `WithBoundArgs` exists to avoid.\n */\ntype BoundPopoverContent = PopoverSignature['Blocks']['default'][0]['Content'];\n\n/**\n * The concrete function signature backing `PopoverTriggerModifier`. Glint's\n * `ModifierLike` is deliberately opaque -- it exists to keep a modifier from\n * being invoked as a plain function in application code -- so there is no\n * type-safe way to call through to it. This narrow, well-understood cast is\n * the exception: `modifier()` from `ember-modifier` returns the exact\n * function it was given. `ember-modifier`'s `dist/index.js` ends `modifier()`\n * with `return setModifierManager(() => MANAGER, fn);`. Its own comment there\n * calls the declared return type \"a *lie*\" -- that is about the TYPE, not the\n * runtime: `setModifierManager` delegates to `@glimmer/manager`'s\n * `setInternalModifierManager`, whose body is `map.set(obj, manager), obj`,\n * so it really does hand back the same `fn`. At runtime `p.trigger` *is*\n * that function. `(el, positional, named) => teardown` is how\n * `Popover`'s own `trigger` is declared.\n *\n * WARNING FOR A FUTURE UPGRADER: this cast is verified against\n * `ember-modifier@4.3.0`'s *function-based* modifier manager, whose\n * `createModifier`/`updateModifier`/`installModifier` call the given function\n * directly as `instance(element, positional, named)` -- i.e. the manager adds\n * no wrapping of its own, so invoking `p.trigger`/`p.anchor` here as plain\n * functions is genuinely calling the same code the manager would call.\n * `ModifierLike` has no call signature *by design* (it exists specifically to\n * stop application code from doing this), so there is no type-safe\n * alternative to the cast. A major `ember-modifier` upgrade could change the\n * manager's calling convention (or start wrapping the function) with no\n * compiler signal at this cast site -- re-verify against the new\n * `dist/index.js` before assuming this still holds. The runtime `assert`\n * calls at the call sites below exist so a break here fails loudly (a thrown\n * dev-mode assertion) instead of silently (a tooltip that never opens).\n */\ntype PopoverTriggerFn = (\n element: HTMLElement,\n positional: ['hover'],\n named: { aria: 'describedby' }\n) => void | (() => void);\n\n/**\n * `p.anchor` (`Velcro`'s `hook`) needs the same runtime call-through as\n * `p.trigger` above -- it is what makes `velcro.loop`/`p.Content`'s `@loop`\n * resolve at all. A consumer normally applies `{{p.anchor}}` and\n * `{{p.trigger}}` as two separate modifiers on the trigger element (see\n * `popover-test.gts`); a tooltip's single yielded `t.trigger` has to install\n * both. Same upgrade warning as `PopoverTriggerFn` above: `ember-velcro`'s\n * `hook` is built with the identical `setModifierManager(() => MANAGER, fn)`\n * pattern, so the same function-based-modifier assumption applies here too.\n */\ntype PopoverAnchorFn = (\n element: HTMLElement | SVGElement\n) => void | (() => void);\n\n/**\n * A modifier value that will be invoked directly as a function rather than\n * applied in a template. See `PopoverTriggerFn` for why that is sound and\n * what has to be re-verified on an `ember-modifier` upgrade. Stands in for\n * `p.anchor`/`p.trigger` wherever this file only needs to cache and compare\n * their identity (not call them) -- the actual call sites still narrow to\n * `PopoverAnchorFn`/`PopoverTriggerFn` via the existing documented casts.\n */\ntype CallableModifier = object;\n\ninterface TooltipSignature {\n Args: {\n /**\n * The tooltip's text. A shorthand for the common case; pass a `Content`\n * block instead when the tooltip needs markup. Passing both asserts.\n */\n content?: string;\n\n /**\n * The requested placement of the tooltip relative to its trigger. This is\n * a preference, not a guarantee: the flip middleware may resolve it to\n * the opposite side when there is no room for it in the requested spot.\n *\n * @defaultValue 'top'\n */\n placement?: PopoverSignature['Args']['placement'];\n\n /**\n * Renders an arrow pointing at the trigger.\n *\n * @defaultValue false\n */\n arrow?: boolean;\n\n /**\n * The tooltip's size, which scales its padding and label text.\n *\n * @defaultValue 'md'\n */\n size?: TooltipVariants['size'];\n\n /**\n * The tooltip's semantic color role. The arrow inherits the body's\n * background, so it follows the chosen intent automatically.\n *\n * @defaultValue 'neutral'\n */\n color?: TooltipVariants['color'];\n\n /**\n * Milliseconds before opening on hover or keyboard focus.\n *\n * @defaultValue 200\n */\n openDelay?: number;\n\n /**\n * Milliseconds before closing. Also the window the pointer has to cross\n * the gap into the tooltip, so a very small value makes the tooltip\n * effectively non-interactive.\n *\n * @defaultValue 150\n */\n closeDelay?: number;\n\n /**\n * Closes as soon as the pointer leaves the trigger, rather than letting it\n * move onto the tooltip.\n *\n * @defaultValue false\n */\n disableInteractive?: boolean;\n\n /**\n * Installs the trigger but never opens. For a tooltip whose text is\n * conditionally irrelevant.\n *\n * @defaultValue false\n */\n isDisabled?: boolean;\n\n /**\n * Whether the tooltip is open. Pair with `onOpenChange` to control it;\n * leave it unset to let the tooltip manage its own state. Passing\n * `isOpen` alone, without `onOpenChange`, falls back to uncontrolled\n * behavior.\n */\n isOpen?: boolean;\n\n /**\n * Callback when the tooltip opens or closes, receiving the new state.\n */\n onOpenChange?: (isOpen: boolean) => void;\n\n /**\n * Callback when closing has finished, including any exit transition.\n */\n didClose?: () => void;\n\n /**\n * The gap, in pixels, between the trigger and the tooltip. The default\n * leaves room for the arrow when `@arrow` is enabled.\n *\n * @defaultValue 8\n */\n offsetOptions?: PopoverSignature['Args']['offsetOptions'];\n\n /**\n * Options for the floating-ui flip middleware, which moves the tooltip\n * to the opposite side when it would overflow the viewport. Forwarded\n * to the underlying `Popover`.\n */\n flipOptions?: PopoverSignature['Args']['flipOptions'];\n\n /**\n * Options for the floating-ui shift middleware, which nudges the\n * tooltip along its axis to keep it in view. Forwarded to the\n * underlying `Popover`.\n */\n shiftOptions?: PopoverSignature['Args']['shiftOptions'];\n\n /**\n * Additional floating-ui middleware, for positioning behavior beyond\n * what `placement`, `offsetOptions`, `flipOptions`, and `shiftOptions`\n * cover. Forwarded to the underlying `Popover`.\n */\n middleware?: PopoverSignature['Args']['middleware'];\n\n /**\n * The CSS positioning strategy, forwarded to the underlying\n * `Popover`/floating-ui.\n *\n * @defaultValue 'absolute'\n */\n strategy?: PopoverSignature['Args']['strategy'];\n\n /**\n * Custom class for the tooltip, merged with the theme's using Tailwind\n * Merge.\n */\n class?: string;\n\n /**\n * Class names for each slot, merged with the theme's.\n */\n classes?: SlotsToClasses<TooltipSlots>;\n };\n Element: HTMLDivElement;\n Blocks: {\n default: [\n {\n /**\n * The modifier to apply to the element the tooltip describes. Installs\n * the hover/focus listeners that open and close the tooltip, and keeps\n * `aria-describedby` in sync while it does.\n */\n trigger: ModifierLike<{ Element: HTMLElement }>;\n Content: WithBoundArgs<\n typeof TooltipContent,\n | 'PopoverContent'\n | 'classNames'\n | 'arrow'\n | 'disableInteractive'\n | 'hasContentArg'\n >;\n\n /**\n * Whether the tooltip is currently open.\n */\n isOpen: boolean;\n\n /**\n * Opens the tooltip.\n */\n open: () => void;\n\n /**\n * Closes the tooltip.\n */\n close: () => void;\n }\n ];\n };\n}\n\nclass Tooltip extends Component<TooltipSignature> {\n get classNames() {\n const { tooltip } = useStyles();\n\n const { base, arrow } = tooltip({\n size: this.args.size,\n color: this.args.color\n });\n\n return {\n base: base({ class: [this.args.classes?.base, this.args.class] }),\n arrow: arrow({ class: this.args.classes?.arrow })\n };\n }\n\n get placement(): PopoverSignature['Args']['placement'] {\n return this.args.placement ?? 'top';\n }\n\n get offsetOptions() {\n return this.args.offsetOptions ?? 8;\n }\n\n get openDelay(): number {\n return typeof this.args.openDelay === 'number' ? this.args.openDelay : 200;\n }\n\n get closeDelay(): number {\n return typeof this.args.closeDelay === 'number'\n ? this.args.closeDelay\n : 150;\n }\n\n /**\n * `p.trigger` cannot be curried in a `.gts` template with the template's\n * `(modifier ...)` keyword: even binding a single positional argument onto\n * a wrapper modifier -- whatever its declared type -- makes Glint's\n * `--declaration` pass fail with \"Type instantiation is excessively deep\n * and possibly infinite\" (reproduces the same way typed as `unknown`).\n * Applying a modifier directly (`{{this.someModifier someArg}}`) type-checks\n * fine; it is specifically the currying keyword's overload resolution that\n * Glint chokes on, so this file builds the bound modifier value from plain\n * JS instead of templated currying.\n *\n * `modifier()` from `ember-modifier` returns the exact function it is\n * given, with only a modifier manager attached out of band (see its\n * `dist/index.js`: `setModifierManager(() => MANAGER, fn); return fn;`),\n * and `ember-velcro`'s `hook` (`p.anchor`) is built the same way. So both\n * `p.anchor` and `p.trigger` are, at runtime, genuinely just those\n * functions -- calling them directly from plain JS is well-defined, even\n * though Glint's opaque `ModifierLike` intentionally exposes no call\n * signature for either.\n *\n * `t.trigger` has to install *both*: a tooltip's trigger element is also\n * its `Velcro` anchor. A normal `Popover` consumer applies `{{p.anchor}}`\n * and `{{p.trigger}}` as two separate modifiers on the same element (see\n * `popover-test.gts`); missing the anchor doesn't fail loudly by itself --\n * it just leaves `velcro.loop` (and so `p.Content`'s `@loop`) undefined,\n * which then asserts inside `Content`.\n *\n * Memoized on the `(anchor, trigger)` pair's identity (both stable for a\n * given `Popover` instance, since `Popover`/`Velcro` each assign their\n * fields once) so `t.trigger` keeps a stable identity across re-renders\n * instead of tearing down and reinstalling on every one.\n *\n * `@isDisabled` is read *inside* the installed function below, rather than\n * baked into this cache -- deliberately. `modifier()`'s function autotracks:\n * reading `this.args.isDisabled` there is what makes ember-modifier tear\n * down and reinstall the trigger's listeners when it changes, without\n * needing a new outer modifier identity (so the element itself is never\n * remounted). Passing `@isDisabled` through as an unreachable `openDelay`\n * (`Number.MAX_SAFE_INTEGER`) does not work instead: `@ember/test-helpers`'\n * `settled()` -- which every `await triggerEvent(...)` calls internally --\n * waits on `backburner.hasTimers()`, which is true for *any* pending\n * `later()` call no matter how far in the future, so a `mouseenter`\n * scheduling an effectively-infinite open left every subsequent `await`\n * hanging until the QUnit test timeout. Skipping the hover installation\n * entirely while disabled avoids ever scheduling that timer in the first\n * place.\n *\n * ANCHOR CHURN GUARD: the wrapper function below reads `this.isOpen`\n * *transitively* -- not directly, but through `trigger`'s own autotracking\n * of `aria-describedby` -- so `ember-modifier` tears the whole wrapper down\n * and reinstalls it on every open/close. Without a guard, that would call\n * `anchor(element)` again on every cycle, and `Velcro`'s `hook` reassigns\n * its own `@tracked hook` field each time it runs, which tears down and\n * restarts floating-ui's `autoUpdate` positioning loop for no reason -- a\n * normal `Popover` consumer never pays this cost, because there `anchor`\n * and `trigger` are two separate modifiers and `anchor`'s body reads\n * nothing tracked, so it installs once and never re-runs.\n *\n * The fix keys the anchor's lifecycle on the *element* in instance state\n * (`anchoredElement`/`anchorTeardown`), not on the wrapper modifier's own\n * re-run: `ensureAnchor` below only calls `anchor(element)` when the\n * element actually changes. The wrapper's own destructor -- called by\n * `ember-modifier` before *every* re-run, same-element re-runs included --\n * therefore does not tear the anchor down synchronously; it only tears\n * down `trigger` immediately (the half that legitimately needs to re-run on\n * every open/close -- that's what keeps `aria-describedby` in sync, which\n * controlled mode also depends on) and *defers* the anchor decision via\n * `scheduleAnchorTeardownCheck`.\n *\n * Why a deferred check, rather than just comparing `element` identity:\n * `ember-modifier` gives the destructor no way to tell \"about to re-run for\n * the same element\" apart from \"genuinely destroyed\" -- both call the same\n * returned closure. An identity comparison alone is correct for the\n * re-run case but has no destructor path left for the case where `element`\n * is removed entirely while\n * `Tooltip` itself keeps living (e.g. `{{#if this.show}}<button\n * {{t.trigger}}>{{/if}}`) -- nothing ever calls `ensureAnchor` again to\n * notice the change, and `willDestroy` only runs when `Tooltip` itself is\n * torn down. `scheduleAnchorTeardownCheck`/`confirmAnchorTeardown` resolve\n * the ambiguity by deferring one runloop turn (`@ember/runloop`'s `next`):\n * if the wrapper re-runs for the same element, `ensureAnchor` cancels the\n * pending check synchronously, before it fires; if `element` was genuinely\n * removed, nothing cancels it and the anchor is torn down for real one turn\n * later. The anchor is therefore torn down in exactly three places:\n * `ensureAnchor` (a different element arrived), `confirmAnchorTeardown`\n * (the deferred check fired unchallenged), and `willDestroy` (the component\n * itself is destroyed) -- never synchronously inside the wrapper's own\n * destructor.\n */\n cachedTrigger?: {\n anchor: CallableModifier;\n trigger: CallableModifier;\n modifier: ModifierLike<{ Element: HTMLElement }>;\n };\n\n /**\n * The element the anchor is currently installed on, and the teardown\n * `anchor(element)` handed back for it. Lives on the component instance\n * (not in the modifier's own closure) so it survives every open/close\n * re-run of the wrapper modifier -- see the churn-guard note above.\n */\n anchoredElement?: HTMLElement | SVGElement;\n anchorTeardown?: () => void;\n\n /**\n * A scheduled-but-not-yet-confirmed anchor teardown, set by the wrapper\n * modifier's destructor (see `makeTrigger`) and cancelled by `ensureAnchor`\n * if the wrapper turns out to have just re-run for the same element.\n *\n * WHY THIS EXISTS: `ember-modifier` calls the wrapper's destructor before\n * *every* re-run (same-element open/close churn included) as well as on\n * genuine removal, and does not tell us which. So the destructor alone\n * cannot decide whether to tear the anchor down. Deferring the decision by\n * one runloop turn resolves the ambiguity: if the wrapper is only\n * re-running, `ensureAnchor` runs synchronously afterwards (same tick,\n * before the deferred check fires) and cancels this; if the element was\n * genuinely removed, nothing calls `ensureAnchor` again, so the deferred\n * check fires and the anchor is torn down for real.\n *\n * Scheduled with `@ember/runloop`'s `next`/`cancel`, like the rest of this\n * codebase's timer usage (see `popover.gts`'s `hoverTimer`), rather than a\n * bespoke `setTimeout`.\n */\n pendingAnchorTeardown?: {\n element: HTMLElement | SVGElement;\n timer: EmberTimer;\n };\n\n /**\n * Installs `anchor` on `element` only if it is not already installed\n * there. Called on every wrapper re-run (every open/close), but is a no-op\n * on all but the first call and any call where the element genuinely\n * changed.\n *\n * Declared as a regular (prototype) method rather than an arrow-function\n * class field -- unlike `makeTrigger`, it is only ever called as\n * `this.ensureAnchor(...)`, never passed by reference, so it doesn't need\n * per-instance `this`-binding. Living on the prototype also makes it the\n * one seam the test suite can wrap to count real anchor installations\n * (see `tooltip-test.gts`'s anchor-churn-guard test).\n */\n ensureAnchor(anchor: CallableModifier, element: HTMLElement | SVGElement) {\n // The wrapper modifier re-ran for this same element -- any anchor\n // teardown its destructor speculatively scheduled (see\n // `scheduleAnchorTeardownCheck`) is stale: the element didn't actually go\n // away, so cancel the pending check before it can fire.\n if (\n this.pendingAnchorTeardown &&\n this.pendingAnchorTeardown.element === element\n ) {\n cancel(this.pendingAnchorTeardown.timer);\n this.pendingAnchorTeardown = undefined;\n }\n\n if (this.anchoredElement === element) {\n return;\n }\n\n // A different element arrived (or this is the first install for this\n // wrapper): tear down whatever anchor is currently installed before\n // installing the new one, so we never leak a stale `autoUpdate` loop.\n this.anchorTeardown?.();\n\n assert(\n \"Expected `p.anchor` to be a callable function (ember-velcro's `hook`, built the same way `ember-modifier`'s `modifier()` builds a callable function-based modifier). If this fires, an `ember-modifier` or `ember-velcro` upgrade likely changed how modifier values are constructed -- see the `PopoverAnchorFn`/`PopoverTriggerFn` comments above.\",\n typeof anchor === 'function'\n );\n\n const teardown = (anchor as unknown as PopoverAnchorFn)(element);\n\n this.anchoredElement = element;\n this.anchorTeardown = teardown ?? undefined;\n }\n\n /**\n * Called from the wrapper modifier's destructor -- i.e. on *every*\n * re-run of the wrapper, not only on genuine removal of `element`. Defers\n * the decision by one runloop turn: schedules `confirmAnchorTeardown` via\n * `next()`, which only actually tears the anchor down if nothing cancels\n * it first. `ensureAnchor` (above) is what cancels it, synchronously,\n * within the same runloop turn, if the wrapper turns out to have simply\n * re-run for the same element.\n */\n scheduleAnchorTeardownCheck(element: HTMLElement | SVGElement) {\n // Superseding an earlier pending check for a different element should\n // not normally happen (a new one would already have been resolved by an\n // intervening `ensureAnchor` call), but cancel defensively rather than\n // leak the earlier timer.\n if (this.pendingAnchorTeardown) {\n cancel(this.pendingAnchorTeardown.timer);\n }\n\n const timer = next(() => this.confirmAnchorTeardown(element));\n this.pendingAnchorTeardown = { element, timer };\n }\n\n /**\n * Runs one runloop turn after the wrapper modifier's destructor scheduled\n * it. If it gets here at all (i.e. `ensureAnchor` did not cancel it in the\n * meantime), the wrapper never re-ran for `element` -- the element was\n * genuinely removed -- so the anchor installed on it is torn down for\n * real.\n */\n confirmAnchorTeardown(element: HTMLElement | SVGElement) {\n if (\n !this.pendingAnchorTeardown ||\n this.pendingAnchorTeardown.element !== element\n ) {\n // Already superseded/cancelled (or, in principle, stale) -- nothing to\n // do.\n return;\n }\n\n this.pendingAnchorTeardown = undefined;\n\n if (this.anchoredElement === element) {\n this.anchorTeardown?.();\n this.anchoredElement = undefined;\n this.anchorTeardown = undefined;\n }\n }\n\n willDestroy() {\n super.willDestroy();\n if (this.pendingAnchorTeardown) {\n cancel(this.pendingAnchorTeardown.timer);\n this.pendingAnchorTeardown = undefined;\n }\n this.anchorTeardown?.();\n this.anchoredElement = undefined;\n this.anchorTeardown = undefined;\n }\n\n makeTrigger = (\n anchor: CallableModifier,\n trigger: CallableModifier\n ): ModifierLike<{ Element: HTMLElement }> => {\n if (\n !this.cachedTrigger ||\n this.cachedTrigger.anchor !== anchor ||\n this.cachedTrigger.trigger !== trigger\n ) {\n this.cachedTrigger = {\n anchor,\n trigger,\n modifier: modifier((element: HTMLElement) => {\n this.ensureAnchor(anchor, element);\n\n if (this.args.isDisabled) {\n return undefined;\n }\n\n assert(\n \"Expected `p.trigger` to be a callable function (a modifier built by `ember-modifier`'s `modifier()`). If this fires, an `ember-modifier` upgrade likely changed how function-based modifiers are constructed -- see the `PopoverTriggerFn` comment above.\",\n typeof trigger === 'function'\n );\n\n const teardownTrigger = (trigger as unknown as PopoverTriggerFn)(\n element,\n ['hover'],\n { aria: 'describedby' }\n );\n\n // `ember-modifier` calls this destructor before *every* re-run --\n // including a same-element re-run driven by `this.isOpen` churn --\n // and on genuine removal of `element`, with no way to tell which\n // from here. The trigger half always tears down and reinstalls\n // (that's what keeps `aria-describedby` in sync). The anchor half\n // cannot follow the same rule -- unconditionally tearing it down\n // here would reintroduce the churn this guard exists to prevent --\n // so it's handled by deferred confirmation: `scheduleAnchorTeardownCheck`\n // only *actually* tears the anchor down one runloop turn later, and\n // only if `ensureAnchor` doesn't cancel it first because the\n // wrapper turned out to just be re-running for the same element.\n // See the doc comments on `pendingAnchorTeardown` /\n // `scheduleAnchorTeardownCheck` / `confirmAnchorTeardown` above.\n return () => {\n teardownTrigger?.();\n this.scheduleAnchorTeardownCheck(element);\n };\n }) as unknown as ModifierLike<{ Element: HTMLElement }>\n };\n }\n\n return this.cachedTrigger.modifier;\n };\n\n <template>\n <Popover\n @placement={{this.placement}}\n @offsetOptions={{this.offsetOptions}}\n @flipOptions={{@flipOptions}}\n @shiftOptions={{@shiftOptions}}\n @middleware={{@middleware}}\n @strategy={{@strategy}}\n @openDelay={{this.openDelay}}\n @closeDelay={{this.closeDelay}}\n @isOpen={{@isOpen}}\n @onOpenChange={{@onOpenChange}}\n @didClose={{@didClose}}\n as |p|\n >\n {{yield\n (hash\n trigger=(this.makeTrigger p.anchor p.trigger)\n isOpen=p.isOpen\n open=p.open\n close=p.close\n Content=(component\n TooltipContent\n PopoverContent=p.Content\n classNames=this.classNames\n arrow=@arrow\n disableInteractive=@disableInteractive\n hasContentArg=(if @content true false)\n )\n )\n }}\n\n {{#if @content}}\n <TooltipContent\n @PopoverContent={{p.Content}}\n @classNames={{this.classNames}}\n @arrow={{@arrow}}\n @disableInteractive={{@disableInteractive}}\n ...attributes\n >\n {{@content}}\n </TooltipContent>\n {{/if}}\n </Popover>\n </template>\n}\n\ninterface TooltipContentSignature {\n Args: {\n /**\n * @internal\n */\n PopoverContent: BoundPopoverContent;\n\n /**\n * @internal\n */\n classNames: { base: string; arrow: string };\n\n /**\n * @internal\n */\n arrow?: boolean;\n\n /**\n * @internal\n */\n disableInteractive?: boolean;\n\n /**\n * @internal\n * Set only on the bound `Content` yielded to the consumer. Lets this\n * component assert when it renders while `@content` is also in use --\n * a `Tooltip` cannot otherwise tell whether the consumer invoked the\n * yielded `Content` block.\n */\n hasContentArg?: boolean;\n };\n Element: HTMLDivElement;\n Blocks: { default: [] };\n}\n\n/**\n * The tooltip's content. Configures `Popover.Content` for a tooltip: no focus\n * trap, no autofocus, no scroll lock, `role=\"tooltip\"`, and `tabindex=\"-1\"` so\n * it is never a tab stop -- `Overlay` sets `tabindex=\"0\"` but spreads\n * `...attributes` after it, so this wins.\n *\n * Its constructor also asserts that `@content` and a `<t.Content>` block are\n * never used together: `hasContentArg` is set only on the bound `Content`\n * yielded to the consumer (see `TooltipContentSignature['Args']`), so this\n * component renders with it `true` exactly when the consumer both passed\n * `@content` to `Tooltip` *and* invoked the yielded `Content` block. The\n * check has to live here, on the content side, rather than on `Tooltip`\n * itself, because a Glimmer component has no way to observe whether a\n * consumer invoked one of its yielded blocks -- `Tooltip` cannot tell\n * `<t.Content>` was used at all until this component actually renders.\n */\nclass TooltipContent extends Component<TooltipContentSignature> {\n constructor(owner: Owner, args: TooltipContentSignature['Args']) {\n super(owner, args);\n\n assert(\n '<Tooltip> received both @content and a <t.Content> block. Use one or the other.',\n !this.args.hasContentArg\n );\n }\n\n /**\n * `data-component`/`data-part` below are written before ...attributes, so\n * they flow through Popover.Content's own ...attributes forwarding onto\n * Overlay's rendered div and override its default data-component=\"overlay\"\n * -- the standard splattributes-override pattern Overlay's own template is\n * written to support (its literal data-component=\"overlay\" is likewise\n * placed before its own ...attributes). Tooltip has no element of its own:\n * its \"base\"/\"arrow\" slots render on the exact same portaled div\n * Overlay/Popover.Content own, so this is the only way to mark it\n * data-component=\"tooltip\" without touching overlay.gts/popover.gts.\n */\n <template>\n <@PopoverContent\n @class={{@classNames.base}}\n @arrowClass={{@classNames.arrow}}\n @arrow={{@arrow}}\n @disableInteractive={{@disableInteractive}}\n @transition={{hash name=\"overlay-transition--tooltip\"}}\n @blockScroll={{false}}\n @backdrop=\"none\"\n role=\"tooltip\"\n tabindex=\"-1\"\n data-component=\"tooltip\"\n data-part=\"base\"\n ...attributes\n >\n {{yield}}\n </@PopoverContent>\n </template>\n}\n\nexport { Tooltip, type TooltipSignature };\nexport default Tooltip;\n"],"names":["Tooltip","Component","classNames","tooltip","useStyles","base","arrow","size","args","color","class","classes","placement","offsetOptions","openDelay","closeDelay","cachedTrigger","anchoredElement","anchorTeardown","pendingAnchorTeardown","ensureAnchor","anchor","element","cancel","timer","undefined","assert","teardown","scheduleAnchorTeardownCheck","next","confirmAnchorTeardown","willDestroy","makeTrigger","trigger","modifier","isDisabled","teardownTrigger","aria","setComponentTemplate","precompileTemplate","strictMode","scope","Popover","hash","TooltipContent","constructor","owner","hasContentArg"],"mappings":";;;;;;;;;;AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BC;AAOD;;;;;;;;;AASC;AAKD;;;;;;;AAOC;AAkLD,MAAMA,gBAAgBC,SAAA,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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAA,OAAO,MAAA;AACLD,YAAAA,eAAA,IAAA;AACA,YAAA,IAAI,CAACR,2BAA2B,CAACN,OAAA,CAAA;UACnC,CAAA;QACF,CAAA;OACF;AACF,IAAA;AAEA,IAAA,OAAO,IAAI,CAACN,aAAa,CAACkB,QAAQ;EACpC,CAAA;AAEA,EAAA;IAAAI,oBAAA,CAAAC,kBAAA,CAAA,w2BAAA,EA4CA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,OAAA;QAAAC,IAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AAqCA;;;;;;;;;;;;;;;;AAgBA,MAAMA,uBAAuB3C,SAAA,CAAU;AACrC4C,EAAAA,WAAAA,CAAYC,KAAY,EAAEtC,IAAqC,EAAE;AAC/D,IAAA,KAAK,CAACsC,KAAA,EAAOtC,IAAA,CAAA;IAEbkB,MAAA,CACE,mFACA,CAAC,IAAI,CAAClB,IAAI,CAACuC,aAAa,CAAA;AAE5B,EAAA;AAEA;;;;;;;;;;AAUC;AACD,EAAA;IAAAT,oBAAA,CAAAC,kBAAA,CAAA,iXAAA,EAiBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAE,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
1
|
+
{"version":3,"file":"tooltip.js","sources":["../../../src/components/overlays/tooltip.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\nimport { hash } from '@ember/helper';\nimport { modifier } from 'ember-modifier';\n\nimport { next, cancel } from '@ember/runloop';\nimport type { Timer as EmberTimer } from '@ember/runloop';\nimport { useStyles } from '@frontile/theme';\nimport { Popover, type PopoverSignature } from './popover';\nimport type {\n TooltipVariants,\n TooltipSlots,\n SlotsToClasses\n} from '@frontile/theme';\nimport type { ModifierLike, WithBoundArgs } from '@glint/template';\nimport type Owner from '@ember/owner';\n\n/**\n * The type of `Popover`'s yielded `Content`, already bound to its internal\n * wiring (`loop`, `isOpen`, `id`, ...). Reusing this instead of\n * `ComponentLike<ContentSignature>` matters: the latter is the *unbound*\n * signature, so invoking it in a template would again require every one of\n * those internal args -- exactly what `WithBoundArgs` exists to avoid.\n */\ntype BoundPopoverContent = PopoverSignature['Blocks']['default'][0]['Content'];\n\n/**\n * The concrete function signature backing `PopoverTriggerModifier`. Glint's\n * `ModifierLike` is deliberately opaque -- it exists to keep a modifier from\n * being invoked as a plain function in application code -- so there is no\n * type-safe way to call through to it. This narrow, well-understood cast is\n * the exception: `modifier()` from `ember-modifier` returns the exact\n * function it was given. `ember-modifier`'s `dist/index.js` ends `modifier()`\n * with `return setModifierManager(() => MANAGER, fn);`. Its own comment there\n * calls the declared return type \"a *lie*\" -- that is about the TYPE, not the\n * runtime: `setModifierManager` delegates to `@glimmer/manager`'s\n * `setInternalModifierManager`, whose body is `map.set(obj, manager), obj`,\n * so it really does hand back the same `fn`. At runtime `p.trigger` *is*\n * that function. `(el, positional, named) => teardown` is how\n * `Popover`'s own `trigger` is declared.\n *\n * WARNING FOR A FUTURE UPGRADER: this cast is verified against\n * `ember-modifier@4.3.0`'s *function-based* modifier manager, whose\n * `createModifier`/`updateModifier`/`installModifier` call the given function\n * directly as `instance(element, positional, named)` -- i.e. the manager adds\n * no wrapping of its own, so invoking `p.trigger`/`p.anchor` here as plain\n * functions is genuinely calling the same code the manager would call.\n * `ModifierLike` has no call signature *by design* (it exists specifically to\n * stop application code from doing this), so there is no type-safe\n * alternative to the cast. A major `ember-modifier` upgrade could change the\n * manager's calling convention (or start wrapping the function) with no\n * compiler signal at this cast site -- re-verify against the new\n * `dist/index.js` before assuming this still holds. The runtime `assert`\n * calls at the call sites below exist so a break here fails loudly (a thrown\n * dev-mode assertion) instead of silently (a tooltip that never opens).\n */\ntype PopoverTriggerFn = (\n element: HTMLElement,\n positional: ['hover'],\n named: { aria: 'describedby' }\n) => void | (() => void);\n\n/**\n * `p.anchor` (`Velcro`'s `hook`) needs the same runtime call-through as\n * `p.trigger` above -- it is what makes `velcro.loop`/`p.Content`'s `@loop`\n * resolve at all. A consumer normally applies `{{p.anchor}}` and\n * `{{p.trigger}}` as two separate modifiers on the trigger element (see\n * `popover-test.gts`); a tooltip's single yielded `t.trigger` has to install\n * both. Same upgrade warning as `PopoverTriggerFn` above: `ember-velcro`'s\n * `hook` is built with the identical `setModifierManager(() => MANAGER, fn)`\n * pattern, so the same function-based-modifier assumption applies here too.\n */\ntype PopoverAnchorFn = (\n element: HTMLElement | SVGElement\n) => void | (() => void);\n\n/**\n * A modifier value that will be invoked directly as a function rather than\n * applied in a template. See `PopoverTriggerFn` for why that is sound and\n * what has to be re-verified on an `ember-modifier` upgrade. Stands in for\n * `p.anchor`/`p.trigger` wherever this file only needs to cache and compare\n * their identity (not call them) -- the actual call sites still narrow to\n * `PopoverAnchorFn`/`PopoverTriggerFn` via the existing documented casts.\n */\ntype CallableModifier = object;\n\ninterface TooltipSignature {\n Args: {\n /**\n * The tooltip's text. A shorthand for the common case; pass a `Content`\n * block instead when the tooltip needs markup. Passing both asserts.\n */\n content?: string;\n\n /**\n * The requested placement of the tooltip relative to its trigger. This is\n * a preference, not a guarantee: the flip middleware may resolve it to\n * the opposite side when there is no room for it in the requested spot.\n *\n * @defaultValue 'top'\n */\n placement?: PopoverSignature['Args']['placement'];\n\n /**\n * Renders an arrow pointing at the trigger.\n *\n * @defaultValue false\n */\n arrow?: boolean;\n\n /**\n * The tooltip's size, which scales its padding and text.\n *\n * @defaultValue 'md'\n */\n size?: TooltipVariants['size'];\n\n /**\n * The tooltip's semantic color role. The arrow inherits the body's\n * background, so it follows the chosen intent automatically.\n *\n * @defaultValue 'neutral'\n */\n color?: TooltipVariants['color'];\n\n /**\n * Milliseconds before opening on hover or keyboard focus.\n *\n * @defaultValue 200\n */\n openDelay?: number;\n\n /**\n * Milliseconds before closing. Also the window the pointer has to cross\n * the gap into the tooltip, so a very small value makes the tooltip\n * effectively non-interactive.\n *\n * @defaultValue 150\n */\n closeDelay?: number;\n\n /**\n * Closes as soon as the pointer leaves the trigger, rather than letting it\n * move onto the tooltip.\n *\n * @defaultValue false\n */\n disableInteractive?: boolean;\n\n /**\n * Installs the trigger but never opens. For a tooltip whose text is\n * conditionally irrelevant.\n *\n * @defaultValue false\n */\n isDisabled?: boolean;\n\n /**\n * Whether the tooltip is open. Pair with `onOpenChange` to control it;\n * leave it unset to let the tooltip manage its own state. Passing\n * `isOpen` alone, without `onOpenChange`, falls back to uncontrolled\n * behavior.\n */\n isOpen?: boolean;\n\n /**\n * Callback when the tooltip opens or closes, receiving the new state.\n */\n onOpenChange?: (isOpen: boolean) => void;\n\n /**\n * Callback when closing has finished, including any exit transition.\n */\n didClose?: () => void;\n\n /**\n * The gap, in pixels, between the trigger and the tooltip. The default\n * leaves room for the arrow when `@arrow` is enabled.\n *\n * @defaultValue 8\n */\n offsetOptions?: PopoverSignature['Args']['offsetOptions'];\n\n /**\n * Options for the floating-ui flip middleware, which moves the tooltip\n * to the opposite side when it would overflow the viewport. Forwarded\n * to the underlying `Popover`.\n */\n flipOptions?: PopoverSignature['Args']['flipOptions'];\n\n /**\n * Options for the floating-ui shift middleware, which nudges the\n * tooltip along its axis to keep it in view. Forwarded to the\n * underlying `Popover`.\n */\n shiftOptions?: PopoverSignature['Args']['shiftOptions'];\n\n /**\n * Additional floating-ui middleware, for positioning behavior beyond\n * what `placement`, `offsetOptions`, `flipOptions`, and `shiftOptions`\n * cover. Forwarded to the underlying `Popover`.\n */\n middleware?: PopoverSignature['Args']['middleware'];\n\n /**\n * The CSS positioning strategy, forwarded to the underlying\n * `Popover`/floating-ui.\n *\n * @defaultValue 'absolute'\n */\n strategy?: PopoverSignature['Args']['strategy'];\n\n /**\n * Custom class for the tooltip, merged with the theme's using Tailwind\n * Merge.\n */\n class?: string;\n\n /**\n * Class names for each slot, merged with the theme's.\n */\n classes?: SlotsToClasses<TooltipSlots>;\n };\n Element: HTMLDivElement;\n Blocks: {\n default: [\n {\n /**\n * The modifier to apply to the element the tooltip describes. Installs\n * the hover/focus listeners that open and close the tooltip, and keeps\n * `aria-describedby` in sync while it does.\n */\n trigger: ModifierLike<{ Element: HTMLElement }>;\n Content: WithBoundArgs<\n typeof TooltipContent,\n | 'PopoverContent'\n | 'classNames'\n | 'arrow'\n | 'disableInteractive'\n | 'hasContentArg'\n >;\n\n /**\n * Whether the tooltip is currently open.\n */\n isOpen: boolean;\n\n /**\n * Opens the tooltip.\n */\n open: () => void;\n\n /**\n * Closes the tooltip.\n */\n close: () => void;\n }\n ];\n };\n}\n\nclass Tooltip extends Component<TooltipSignature> {\n get classNames() {\n const { tooltip } = useStyles();\n\n const { base, arrow } = tooltip({\n size: this.args.size,\n color: this.args.color\n });\n\n return {\n base: base({ class: [this.args.classes?.base, this.args.class] }),\n arrow: arrow({ class: this.args.classes?.arrow })\n };\n }\n\n get placement(): PopoverSignature['Args']['placement'] {\n return this.args.placement ?? 'top';\n }\n\n get offsetOptions() {\n return this.args.offsetOptions ?? 8;\n }\n\n get openDelay(): number {\n return typeof this.args.openDelay === 'number' ? this.args.openDelay : 200;\n }\n\n get closeDelay(): number {\n return typeof this.args.closeDelay === 'number'\n ? this.args.closeDelay\n : 150;\n }\n\n /**\n * `p.trigger` cannot be curried in a `.gts` template with the template's\n * `(modifier ...)` keyword: even binding a single positional argument onto\n * a wrapper modifier -- whatever its declared type -- makes Glint's\n * `--declaration` pass fail with \"Type instantiation is excessively deep\n * and possibly infinite\" (reproduces the same way typed as `unknown`).\n * Applying a modifier directly (`{{this.someModifier someArg}}`) type-checks\n * fine; it is specifically the currying keyword's overload resolution that\n * Glint chokes on, so this file builds the bound modifier value from plain\n * JS instead of templated currying.\n *\n * `modifier()` from `ember-modifier` returns the exact function it is\n * given, with only a modifier manager attached out of band (see its\n * `dist/index.js`: `setModifierManager(() => MANAGER, fn); return fn;`),\n * and `ember-velcro`'s `hook` (`p.anchor`) is built the same way. So both\n * `p.anchor` and `p.trigger` are, at runtime, genuinely just those\n * functions -- calling them directly from plain JS is well-defined, even\n * though Glint's opaque `ModifierLike` intentionally exposes no call\n * signature for either.\n *\n * `t.trigger` has to install *both*: a tooltip's trigger element is also\n * its `Velcro` anchor. A normal `Popover` consumer applies `{{p.anchor}}`\n * and `{{p.trigger}}` as two separate modifiers on the same element (see\n * `popover-test.gts`); missing the anchor doesn't fail loudly by itself --\n * it just leaves `velcro.loop` (and so `p.Content`'s `@loop`) undefined,\n * which then asserts inside `Content`.\n *\n * Memoized on the `(anchor, trigger)` pair's identity (both stable for a\n * given `Popover` instance, since `Popover`/`Velcro` each assign their\n * fields once) so `t.trigger` keeps a stable identity across re-renders\n * instead of tearing down and reinstalling on every one.\n *\n * `@isDisabled` is read *inside* the installed function below, rather than\n * baked into this cache -- deliberately. `modifier()`'s function autotracks:\n * reading `this.args.isDisabled` there is what makes ember-modifier tear\n * down and reinstall the trigger's listeners when it changes, without\n * needing a new outer modifier identity (so the element itself is never\n * remounted). Passing `@isDisabled` through as an unreachable `openDelay`\n * (`Number.MAX_SAFE_INTEGER`) does not work instead: `@ember/test-helpers`'\n * `settled()` -- which every `await triggerEvent(...)` calls internally --\n * waits on `backburner.hasTimers()`, which is true for *any* pending\n * `later()` call no matter how far in the future, so a `mouseenter`\n * scheduling an effectively-infinite open left every subsequent `await`\n * hanging until the QUnit test timeout. Skipping the hover installation\n * entirely while disabled avoids ever scheduling that timer in the first\n * place.\n *\n * ANCHOR CHURN GUARD: the wrapper function below reads `this.isOpen`\n * *transitively* -- not directly, but through `trigger`'s own autotracking\n * of `aria-describedby` -- so `ember-modifier` tears the whole wrapper down\n * and reinstalls it on every open/close. Without a guard, that would call\n * `anchor(element)` again on every cycle, and `Velcro`'s `hook` reassigns\n * its own `@tracked hook` field each time it runs, which tears down and\n * restarts floating-ui's `autoUpdate` positioning loop for no reason -- a\n * normal `Popover` consumer never pays this cost, because there `anchor`\n * and `trigger` are two separate modifiers and `anchor`'s body reads\n * nothing tracked, so it installs once and never re-runs.\n *\n * The fix keys the anchor's lifecycle on the *element* in instance state\n * (`anchoredElement`/`anchorTeardown`), not on the wrapper modifier's own\n * re-run: `ensureAnchor` below only calls `anchor(element)` when the\n * element actually changes. The wrapper's own destructor -- called by\n * `ember-modifier` before *every* re-run, same-element re-runs included --\n * therefore does not tear the anchor down synchronously; it only tears\n * down `trigger` immediately (the half that legitimately needs to re-run on\n * every open/close -- that's what keeps `aria-describedby` in sync, which\n * controlled mode also depends on) and *defers* the anchor decision via\n * `scheduleAnchorTeardownCheck`.\n *\n * Why a deferred check, rather than just comparing `element` identity:\n * `ember-modifier` gives the destructor no way to tell \"about to re-run for\n * the same element\" apart from \"genuinely destroyed\" -- both call the same\n * returned closure. An identity comparison alone is correct for the\n * re-run case but has no destructor path left for the case where `element`\n * is removed entirely while\n * `Tooltip` itself keeps living (e.g. `{{#if this.show}}<button\n * {{t.trigger}}>{{/if}}`) -- nothing ever calls `ensureAnchor` again to\n * notice the change, and `willDestroy` only runs when `Tooltip` itself is\n * torn down. `scheduleAnchorTeardownCheck`/`confirmAnchorTeardown` resolve\n * the ambiguity by deferring one runloop turn (`@ember/runloop`'s `next`):\n * if the wrapper re-runs for the same element, `ensureAnchor` cancels the\n * pending check synchronously, before it fires; if `element` was genuinely\n * removed, nothing cancels it and the anchor is torn down for real one turn\n * later. The anchor is therefore torn down in exactly three places:\n * `ensureAnchor` (a different element arrived), `confirmAnchorTeardown`\n * (the deferred check fired unchallenged), and `willDestroy` (the component\n * itself is destroyed) -- never synchronously inside the wrapper's own\n * destructor.\n */\n cachedTrigger?: {\n anchor: CallableModifier;\n trigger: CallableModifier;\n modifier: ModifierLike<{ Element: HTMLElement }>;\n };\n\n /**\n * The element the anchor is currently installed on, and the teardown\n * `anchor(element)` handed back for it. Lives on the component instance\n * (not in the modifier's own closure) so it survives every open/close\n * re-run of the wrapper modifier -- see the churn-guard note above.\n */\n anchoredElement?: HTMLElement | SVGElement;\n anchorTeardown?: () => void;\n\n /**\n * A scheduled-but-not-yet-confirmed anchor teardown, set by the wrapper\n * modifier's destructor (see `makeTrigger`) and cancelled by `ensureAnchor`\n * if the wrapper turns out to have just re-run for the same element.\n *\n * WHY THIS EXISTS: `ember-modifier` calls the wrapper's destructor before\n * *every* re-run (same-element open/close churn included) as well as on\n * genuine removal, and does not tell us which. So the destructor alone\n * cannot decide whether to tear the anchor down. Deferring the decision by\n * one runloop turn resolves the ambiguity: if the wrapper is only\n * re-running, `ensureAnchor` runs synchronously afterwards (same tick,\n * before the deferred check fires) and cancels this; if the element was\n * genuinely removed, nothing calls `ensureAnchor` again, so the deferred\n * check fires and the anchor is torn down for real.\n *\n * Scheduled with `@ember/runloop`'s `next`/`cancel`, like the rest of this\n * codebase's timer usage (see `popover.gts`'s `hoverTimer`), rather than a\n * bespoke `setTimeout`.\n */\n pendingAnchorTeardown?: {\n element: HTMLElement | SVGElement;\n timer: EmberTimer;\n };\n\n /**\n * Installs `anchor` on `element` only if it is not already installed\n * there. Called on every wrapper re-run (every open/close), but is a no-op\n * on all but the first call and any call where the element genuinely\n * changed.\n *\n * Declared as a regular (prototype) method rather than an arrow-function\n * class field -- unlike `makeTrigger`, it is only ever called as\n * `this.ensureAnchor(...)`, never passed by reference, so it doesn't need\n * per-instance `this`-binding. Living on the prototype also makes it the\n * one seam the test suite can wrap to count real anchor installations\n * (see `tooltip-test.gts`'s anchor-churn-guard test).\n */\n ensureAnchor(anchor: CallableModifier, element: HTMLElement | SVGElement) {\n // The wrapper modifier re-ran for this same element -- any anchor\n // teardown its destructor speculatively scheduled (see\n // `scheduleAnchorTeardownCheck`) is stale: the element didn't actually go\n // away, so cancel the pending check before it can fire.\n if (\n this.pendingAnchorTeardown &&\n this.pendingAnchorTeardown.element === element\n ) {\n cancel(this.pendingAnchorTeardown.timer);\n this.pendingAnchorTeardown = undefined;\n }\n\n if (this.anchoredElement === element) {\n return;\n }\n\n // A different element arrived (or this is the first install for this\n // wrapper): tear down whatever anchor is currently installed before\n // installing the new one, so we never leak a stale `autoUpdate` loop.\n this.anchorTeardown?.();\n\n assert(\n \"Expected `p.anchor` to be a callable function (ember-velcro's `hook`, built the same way `ember-modifier`'s `modifier()` builds a callable function-based modifier). If this fires, an `ember-modifier` or `ember-velcro` upgrade likely changed how modifier values are constructed -- see the `PopoverAnchorFn`/`PopoverTriggerFn` comments above.\",\n typeof anchor === 'function'\n );\n\n const teardown = (anchor as unknown as PopoverAnchorFn)(element);\n\n this.anchoredElement = element;\n this.anchorTeardown = teardown ?? undefined;\n }\n\n /**\n * Called from the wrapper modifier's destructor -- i.e. on *every*\n * re-run of the wrapper, not only on genuine removal of `element`. Defers\n * the decision by one runloop turn: schedules `confirmAnchorTeardown` via\n * `next()`, which only actually tears the anchor down if nothing cancels\n * it first. `ensureAnchor` (above) is what cancels it, synchronously,\n * within the same runloop turn, if the wrapper turns out to have simply\n * re-run for the same element.\n */\n scheduleAnchorTeardownCheck(element: HTMLElement | SVGElement) {\n // Superseding an earlier pending check for a different element should\n // not normally happen (a new one would already have been resolved by an\n // intervening `ensureAnchor` call), but cancel defensively rather than\n // leak the earlier timer.\n if (this.pendingAnchorTeardown) {\n cancel(this.pendingAnchorTeardown.timer);\n }\n\n const timer = next(() => this.confirmAnchorTeardown(element));\n this.pendingAnchorTeardown = { element, timer };\n }\n\n /**\n * Runs one runloop turn after the wrapper modifier's destructor scheduled\n * it. If it gets here at all (i.e. `ensureAnchor` did not cancel it in the\n * meantime), the wrapper never re-ran for `element` -- the element was\n * genuinely removed -- so the anchor installed on it is torn down for\n * real.\n */\n confirmAnchorTeardown(element: HTMLElement | SVGElement) {\n if (\n !this.pendingAnchorTeardown ||\n this.pendingAnchorTeardown.element !== element\n ) {\n // Already superseded/cancelled (or, in principle, stale) -- nothing to\n // do.\n return;\n }\n\n this.pendingAnchorTeardown = undefined;\n\n if (this.anchoredElement === element) {\n this.anchorTeardown?.();\n this.anchoredElement = undefined;\n this.anchorTeardown = undefined;\n }\n }\n\n willDestroy() {\n super.willDestroy();\n if (this.pendingAnchorTeardown) {\n cancel(this.pendingAnchorTeardown.timer);\n this.pendingAnchorTeardown = undefined;\n }\n this.anchorTeardown?.();\n this.anchoredElement = undefined;\n this.anchorTeardown = undefined;\n }\n\n makeTrigger = (\n anchor: CallableModifier,\n trigger: CallableModifier\n ): ModifierLike<{ Element: HTMLElement }> => {\n if (\n !this.cachedTrigger ||\n this.cachedTrigger.anchor !== anchor ||\n this.cachedTrigger.trigger !== trigger\n ) {\n this.cachedTrigger = {\n anchor,\n trigger,\n modifier: modifier((element: HTMLElement) => {\n this.ensureAnchor(anchor, element);\n\n if (this.args.isDisabled) {\n return undefined;\n }\n\n assert(\n \"Expected `p.trigger` to be a callable function (a modifier built by `ember-modifier`'s `modifier()`). If this fires, an `ember-modifier` upgrade likely changed how function-based modifiers are constructed -- see the `PopoverTriggerFn` comment above.\",\n typeof trigger === 'function'\n );\n\n const teardownTrigger = (trigger as unknown as PopoverTriggerFn)(\n element,\n ['hover'],\n { aria: 'describedby' }\n );\n\n // `ember-modifier` calls this destructor before *every* re-run --\n // including a same-element re-run driven by `this.isOpen` churn --\n // and on genuine removal of `element`, with no way to tell which\n // from here. The trigger half always tears down and reinstalls\n // (that's what keeps `aria-describedby` in sync). The anchor half\n // cannot follow the same rule -- unconditionally tearing it down\n // here would reintroduce the churn this guard exists to prevent --\n // so it's handled by deferred confirmation: `scheduleAnchorTeardownCheck`\n // only *actually* tears the anchor down one runloop turn later, and\n // only if `ensureAnchor` doesn't cancel it first because the\n // wrapper turned out to just be re-running for the same element.\n // See the doc comments on `pendingAnchorTeardown` /\n // `scheduleAnchorTeardownCheck` / `confirmAnchorTeardown` above.\n return () => {\n teardownTrigger?.();\n this.scheduleAnchorTeardownCheck(element);\n };\n }) as unknown as ModifierLike<{ Element: HTMLElement }>\n };\n }\n\n return this.cachedTrigger.modifier;\n };\n\n <template>\n <Popover\n @placement={{this.placement}}\n @offsetOptions={{this.offsetOptions}}\n @flipOptions={{@flipOptions}}\n @shiftOptions={{@shiftOptions}}\n @middleware={{@middleware}}\n @strategy={{@strategy}}\n @openDelay={{this.openDelay}}\n @closeDelay={{this.closeDelay}}\n @isOpen={{@isOpen}}\n @onOpenChange={{@onOpenChange}}\n @didClose={{@didClose}}\n as |p|\n >\n {{yield\n (hash\n trigger=(this.makeTrigger p.anchor p.trigger)\n isOpen=p.isOpen\n open=p.open\n close=p.close\n Content=(component\n TooltipContent\n PopoverContent=p.Content\n classNames=this.classNames\n arrow=@arrow\n disableInteractive=@disableInteractive\n hasContentArg=(if @content true false)\n )\n )\n }}\n\n {{#if @content}}\n <TooltipContent\n @PopoverContent={{p.Content}}\n @classNames={{this.classNames}}\n @arrow={{@arrow}}\n @disableInteractive={{@disableInteractive}}\n ...attributes\n >\n {{@content}}\n </TooltipContent>\n {{/if}}\n </Popover>\n </template>\n}\n\ninterface TooltipContentSignature {\n Args: {\n /**\n * @internal\n */\n PopoverContent: BoundPopoverContent;\n\n /**\n * @internal\n */\n classNames: { base: string; arrow: string };\n\n /**\n * @internal\n */\n arrow?: boolean;\n\n /**\n * @internal\n */\n disableInteractive?: boolean;\n\n /**\n * @internal\n * Set only on the bound `Content` yielded to the consumer. Lets this\n * component assert when it renders while `@content` is also in use --\n * a `Tooltip` cannot otherwise tell whether the consumer invoked the\n * yielded `Content` block.\n */\n hasContentArg?: boolean;\n };\n Element: HTMLDivElement;\n Blocks: { default: [] };\n}\n\n/**\n * The tooltip's content. Configures `Popover.Content` for a tooltip: no focus\n * trap, no autofocus, no scroll lock, `role=\"tooltip\"`, and `tabindex=\"-1\"` so\n * it is never a tab stop -- `Overlay` sets `tabindex=\"0\"` but spreads\n * `...attributes` after it, so this wins.\n *\n * Its constructor also asserts that `@content` and a `<t.Content>` block are\n * never used together: `hasContentArg` is set only on the bound `Content`\n * yielded to the consumer (see `TooltipContentSignature['Args']`), so this\n * component renders with it `true` exactly when the consumer both passed\n * `@content` to `Tooltip` *and* invoked the yielded `Content` block. The\n * check has to live here, on the content side, rather than on `Tooltip`\n * itself, because a Glimmer component has no way to observe whether a\n * consumer invoked one of its yielded blocks -- `Tooltip` cannot tell\n * `<t.Content>` was used at all until this component actually renders.\n */\nclass TooltipContent extends Component<TooltipContentSignature> {\n constructor(owner: Owner, args: TooltipContentSignature['Args']) {\n super(owner, args);\n\n assert(\n '<Tooltip> received both @content and a <t.Content> block. Use one or the other.',\n !this.args.hasContentArg\n );\n }\n\n /**\n * `data-component`/`data-part` below are written before ...attributes, so\n * they flow through Popover.Content's own ...attributes forwarding onto\n * Overlay's rendered div and override its default data-component=\"overlay\"\n * -- the standard splattributes-override pattern Overlay's own template is\n * written to support (its literal data-component=\"overlay\" is likewise\n * placed before its own ...attributes). Tooltip has no element of its own:\n * its \"base\"/\"arrow\" slots render on the exact same portaled div\n * Overlay/Popover.Content own, so this is the only way to mark it\n * data-component=\"tooltip\" without touching overlay.gts/popover.gts.\n */\n <template>\n <@PopoverContent\n @class={{@classNames.base}}\n @arrowClass={{@classNames.arrow}}\n @arrow={{@arrow}}\n @disableInteractive={{@disableInteractive}}\n @transition={{hash name=\"overlay-transition--tooltip\"}}\n @blockScroll={{false}}\n @backdrop=\"none\"\n role=\"tooltip\"\n tabindex=\"-1\"\n data-component=\"tooltip\"\n data-part=\"base\"\n ...attributes\n >\n {{yield}}\n </@PopoverContent>\n </template>\n}\n\nexport { Tooltip, type TooltipSignature };\nexport default Tooltip;\n"],"names":["Tooltip","Component","classNames","tooltip","useStyles","base","arrow","size","args","color","class","classes","placement","offsetOptions","openDelay","closeDelay","cachedTrigger","anchoredElement","anchorTeardown","pendingAnchorTeardown","ensureAnchor","anchor","element","cancel","timer","undefined","assert","teardown","scheduleAnchorTeardownCheck","next","confirmAnchorTeardown","willDestroy","makeTrigger","trigger","modifier","isDisabled","teardownTrigger","aria","setComponentTemplate","precompileTemplate","strictMode","scope","Popover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PAAA,EACA,OAAOO,OAAA,KAAY,UAAA,CAAA;UAGrB,MAAMG,kBAAmBH,OAAA,CACvBX,OAAA,EACA,CAAC,OAAA,CAAQ,EACT;AAAEe,YAAAA,IAAA,EAAM;AAAc,WAAA,CAAA;AAGxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAA,OAAO,MAAA;AACLD,YAAAA,eAAA,IAAA;AACA,YAAA,IAAI,CAACR,2BAA2B,CAACN,OAAA,CAAA;UACnC,CAAA;QACF,CAAA;OACF;AACF,IAAA;AAEA,IAAA,OAAO,IAAI,CAACN,aAAa,CAACkB,QAAQ;EACpC,CAAA;AAEA,EAAA;IAAAI,oBAAA,CAAAC,kBAAA,CAAA,w2BAAA,EA4CA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,OAAA;QAAAC,IAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;AAqCA;;;;;;;;;;;;;;;;AAgBA,MAAMA,uBAAuB3C,SAAA,CAAU;AACrC4C,EAAAA,WAAAA,CAAYC,KAAY,EAAEtC,IAAqC,EAAE;AAC/D,IAAA,KAAK,CAACsC,KAAA,EAAOtC,IAAA,CAAA;IAEbkB,MAAA,CACE,mFACA,CAAC,IAAI,CAAClB,IAAI,CAACuC,aAAa,CAAA;AAE5B,EAAA;AAEA;;;;;;;;;;AAUC;AACD,EAAA;IAAAT,oBAAA,CAAAC,kBAAA,CAAA,iXAAA,EAiBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAE,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge.js","sources":["../../../src/components/status/badge.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { useStyles } from '@frontile/theme';\n\ninterface BadgeSignature {\n Args: {\n /**\n * The badge variant.
|
|
1
|
+
{"version":3,"file":"badge.js","sources":["../../../src/components/status/badge.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { useStyles } from '@frontile/theme';\n\ninterface BadgeSignature {\n Args: {\n /**\n * The badge variant. `solid` fills with the color's default level, `soft`\n * is a tinted surface, and `outline` draws the color as a border.\n *\n * @defaultValue 'solid'\n */\n variant?: 'solid' | 'soft' | 'outline';\n\n /**\n * The color of the badge.\n *\n * @defaultValue 'neutral'\n */\n color?:\n 'neutral' | 'primary' | 'secondary' | 'tertiary' | 'success' | 'danger';\n\n /**\n * The size of the badge. Uses Button's size names and text size: the same\n * `@size` gives the same label text size on Badge, Chip and Button.\n *\n * @defaultValue 'xs'\n */\n size?: '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\n /**\n * Adds a dot before the content, colored by `@color`.\n *\n * @defaultValue false\n */\n withDot?: boolean;\n\n /**\n * Custom class name, it will override the default ones using Tailwind Merge library.\n */\n class?: string;\n\n /**\n * A figure shown after the label, such as a price or a count. A number is\n * accepted, and `0` still renders; only `undefined` or `null` leaves the\n * value out. Rendered in its own part so the theme can give it a\n * tabular, heavier treatment.\n */\n value?: string | number;\n\n /**\n * A unit shown after the value, such as `/mo`. Rendered only when set.\n */\n unit?: string;\n };\n Blocks: {\n /**\n * The badge label.\n */\n default: [];\n\n /**\n * An icon shown before the label. Using this block means the label must\n * go in the `<:default>` block.\n */\n startIcon?: [];\n\n /**\n * An icon shown after the value and unit. Using this block means the label\n * must go in the `<:default>` block.\n */\n endIcon?: [];\n };\n Element: HTMLSpanElement;\n}\n\n/**\n * A non-interactive label for status or metadata. Renders, in order: dot, start\n * icon, label, value, unit, end icon.\n *\n * When you pass a named block (`<:startIcon>` or `<:endIcon>`), Glimmer no\n * longer treats loose content as the default block, so put the label in\n * `<:default>`.\n *\n * Facet 2.0 content parts map one-to-one onto this API, so there are no extra\n * slots: `leading` is the default block, `price` is `@value`, `unit` is\n * `@unit`, `startGlyph` is `<:startIcon>` and `endGlyph` is `<:endIcon>`.\n */\nclass Badge extends Component<BadgeSignature> {\n // `!= null` rather than truthiness, so a count of `0` is shown.\n get hasValue(): boolean {\n return this.args.value != null;\n }\n\n get classNames() {\n const { badge } = useStyles();\n\n const { base, value, unit, icon, dot } = badge({\n color: this.args.color,\n size: this.args.size,\n variant: this.args.variant\n });\n\n return {\n base: base({ class: this.args.class }),\n value: value(),\n unit: unit(),\n icon: icon(),\n dot: dot()\n };\n }\n\n <template>\n <span\n class={{this.classNames.base}}\n data-component=\"badge\"\n data-part=\"base\"\n ...attributes\n >\n {{#if @withDot}}\n <span class={{this.classNames.dot}} data-part=\"dot\"></span>\n {{/if}}\n {{#if (has-block \"startIcon\")}}\n <span\n class={{this.classNames.icon}}\n data-part=\"icon\"\n data-position=\"start\"\n >\n {{yield to=\"startIcon\"}}\n </span>\n {{/if}}\n {{yield}}\n {{#if this.hasValue}}\n <span\n class={{this.classNames.value}}\n data-part=\"value\"\n >{{@value}}</span>\n {{/if}}\n {{#if @unit}}\n <span class={{this.classNames.unit}} data-part=\"unit\">{{@unit}}</span>\n {{/if}}\n {{#if (has-block \"endIcon\")}}\n <span\n class={{this.classNames.icon}}\n data-part=\"icon\"\n data-position=\"end\"\n >\n {{yield to=\"endIcon\"}}\n </span>\n {{/if}}\n </span>\n </template>\n}\n\nexport { Badge, type BadgeSignature };\nexport default Badge;\n"],"names":["Badge","Component","hasValue","args","value","classNames","badge","useStyles","base","unit","icon","dot","color","size","variant","class","setComponentTemplate","precompileTemplate","strictMode"],"mappings":";;;;;AA2EA;;;;;;;;;;;;AAYA,MAAMA,cAAcC,SAAA,CAAU;AAC5B;EACA,IAAIC,QAAAA,GAAoB;AACtB,IAAA,OAAO,IAAI,CAACC,IAAI,CAACC,KAAK,IAAI,IAAA;AAC5B,EAAA;EAEA,IAAIC,UAAAA,GAAa;IACf,MAAM;AAAEC,MAAAA;KAAO,GAAGC,SAAA,EAAA;IAElB,MAAM;MAAEC,IAAI;MAAEJ,KAAK;MAAEK,IAAI;MAAEC,IAAI;AAAEC,MAAAA;KAAK,GAAGL,KAAA,CAAM;AAC7CM,MAAAA,KAAA,EAAO,IAAI,CAACT,IAAI,CAACS,KAAK;AACtBC,MAAAA,IAAA,EAAM,IAAI,CAACV,IAAI,CAACU,IAAI;AACpBC,MAAAA,OAAA,EAAS,IAAI,CAACX,IAAI,CAACW;AACrB,KAAA,CAAA;IAEA,OAAO;MACLN,IAAA,EAAMA,IAAA,CAAK;AAAEO,QAAAA,KAAA,EAAO,IAAI,CAACZ,IAAI,CAACY;AAAM,OAAA,CAAA;MACpCX,KAAA,EAAOA,KAAA,EAAA;MACPK,IAAA,EAAMA,IAAA,EAAA;MACNC,IAAA,EAAMA,IAAA,EAAA;MACNC,GAAA,EAAKA,GAAA;KACP;AACF,EAAA;AAEA,EAAA;IAAAK,oBAAA,CAAAC,kBAAA,CAAA,4xBAAA,EAuCA;MAAAC,UAAA,EAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;"}
|
package/dist/index.js
CHANGED
|
@@ -108,6 +108,8 @@ export { PageHeader } from './components/layout/page-header.js';
|
|
|
108
108
|
export { Sidebar } from './components/layout/sidebar.js';
|
|
109
109
|
export { SidebarGroup } from './components/layout/sidebar-group.js';
|
|
110
110
|
export { SidebarToggle } from './components/layout/sidebar-toggle.js';
|
|
111
|
+
export { Region } from './components/layout/region.js';
|
|
112
|
+
export { InLayoutRegion } from './components/layout/in-layout-region.js';
|
|
111
113
|
export { ListboxGroup } from './components/collections/listbox/group.js';
|
|
112
114
|
export { ListboxItem } from './components/collections/listbox/item.js';
|
|
113
115
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/layout.js
CHANGED
|
@@ -11,4 +11,6 @@ export { PageHeader } from './components/layout/page-header.js';
|
|
|
11
11
|
export { Sidebar } from './components/layout/sidebar.js';
|
|
12
12
|
export { SidebarGroup } from './components/layout/sidebar-group.js';
|
|
13
13
|
export { SidebarToggle } from './components/layout/sidebar-toggle.js';
|
|
14
|
+
export { Region } from './components/layout/region.js';
|
|
15
|
+
export { InLayoutRegion } from './components/layout/in-layout-region.js';
|
|
14
16
|
//# sourceMappingURL=layout.js.map
|
package/dist/layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layout.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import Service from '@ember/service';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { schedule } from '@ember/runloop';
|
|
4
|
+
import { warn } from '@ember/debug';
|
|
5
|
+
import { d as decorateFieldV2, i as initializeDeferredDecorator } from '../runtime--fcdnjmJ-DOFHQ2m8.js';
|
|
6
|
+
|
|
7
|
+
/** One named region: where it renders (the target) and who fills it. */
|
|
8
|
+
class LayoutRegionState {
|
|
9
|
+
static {
|
|
10
|
+
decorateFieldV2(this.prototype, "targets", [tracked], function () {
|
|
11
|
+
return [];
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
#targets = (initializeDeferredDecorator(this, "targets"), void 0);
|
|
15
|
+
/**
|
|
16
|
+
* Mounted targets in registration order. The newest is the one sources
|
|
17
|
+
* render into; when it goes away, the previous one takes over again.
|
|
18
|
+
* Reassigned, never mutated.
|
|
19
|
+
*/
|
|
20
|
+
static {
|
|
21
|
+
decorateFieldV2(this.prototype, "sources", [tracked], function () {
|
|
22
|
+
return [];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
#sources = (initializeDeferredDecorator(this, "sources"), void 0);
|
|
26
|
+
/** Sources in registration (render) order. Reassigned, never mutated. */
|
|
27
|
+
get hasContent() {
|
|
28
|
+
return this.sources.length > 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The target sources render into: the newest mounted one. */
|
|
32
|
+
get target() {
|
|
33
|
+
return this.targets[this.targets.length - 1];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Where `source` should render, or `null` when it is not shown. */
|
|
37
|
+
targetFor(source) {
|
|
38
|
+
const target = this.target;
|
|
39
|
+
if (!target) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const shown = target.multiple ? this.sources.includes(source) : this.sources[this.sources.length - 1] === source;
|
|
43
|
+
return shown ? target.element : null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Connects `InLayoutRegion` sources, rendered anywhere in the app, to the
|
|
49
|
+
* layout's named regions. Internal to Frontile: use `layout.Region`,
|
|
50
|
+
* `layout.Aside @region` and `InLayoutRegion` instead.
|
|
51
|
+
*
|
|
52
|
+
* Every write is deferred to `afterRender`. Sources register while the
|
|
53
|
+
* render is running, and the layout, which renders before `{{outlet}}`, has
|
|
54
|
+
* usually already read the same tracked state in that render. Writing it
|
|
55
|
+
* synchronously trips Glimmer's backtracking assertion. The deferred write
|
|
56
|
+
* re-renders in the same runloop, so no paint happens in between.
|
|
57
|
+
*/
|
|
58
|
+
class FrontileLayoutRegionsService extends Service {
|
|
59
|
+
#regions = new Map();
|
|
60
|
+
#emptyListeners = new Map();
|
|
61
|
+
#write(fn) {
|
|
62
|
+
schedule('afterRender', () => {
|
|
63
|
+
if (!this.isDestroying && !this.isDestroyed) {
|
|
64
|
+
fn();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The named region, created on first use (by a source or a target). */
|
|
70
|
+
region(name) {
|
|
71
|
+
let region = this.#regions.get(name);
|
|
72
|
+
if (!region) {
|
|
73
|
+
region = new LayoutRegionState();
|
|
74
|
+
this.#regions.set(name, region);
|
|
75
|
+
}
|
|
76
|
+
return region;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Whether any source fills the named region (tracked). */
|
|
80
|
+
hasContent(name) {
|
|
81
|
+
return this.region(name).hasContent;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Where `source` renders in the named region, or `null` (tracked). */
|
|
85
|
+
targetFor(name, source) {
|
|
86
|
+
return this.region(name).targetFor(source);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Adds an element sources render into. The newest target wins; removing
|
|
91
|
+
* it hands the sources back to the previous one. Returns the undo
|
|
92
|
+
* function, which removes only this registration.
|
|
93
|
+
*/
|
|
94
|
+
registerTarget(name, element, options = {}) {
|
|
95
|
+
const region = this.region(name);
|
|
96
|
+
const target = {
|
|
97
|
+
element,
|
|
98
|
+
multiple: options.multiple ?? false
|
|
99
|
+
};
|
|
100
|
+
this.#write(() => {
|
|
101
|
+
// A target that has left the document (the aside moving between its
|
|
102
|
+
// column and its drawer) is being replaced, not duplicated.
|
|
103
|
+
warn(`frontile: two targets render the layout region "${name}" at once; sources follow the newest. Region names are global to the app.`, !region.targets.some(other => other.element !== element && other.element.isConnected), {
|
|
104
|
+
id: 'frontile.layout-region.duplicate-target'
|
|
105
|
+
});
|
|
106
|
+
region.targets = [...region.targets, target];
|
|
107
|
+
});
|
|
108
|
+
return () => this.#write(() => {
|
|
109
|
+
region.targets = region.targets.filter(t => t !== target);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Adds a source to the named region. Returns the undo function. The
|
|
115
|
+
* removal is deferred too, so a swap in one render goes 1 → 2 → 1 and the
|
|
116
|
+
* region is never seen empty.
|
|
117
|
+
*/
|
|
118
|
+
addSource(name, source) {
|
|
119
|
+
const region = this.region(name);
|
|
120
|
+
this.#write(() => {
|
|
121
|
+
region.sources = [...region.sources, source];
|
|
122
|
+
});
|
|
123
|
+
return () => this.#write(() => {
|
|
124
|
+
const before = region.sources.length;
|
|
125
|
+
region.sources = region.sources.filter(s => s !== source);
|
|
126
|
+
if (before > 0 && region.sources.length === 0) {
|
|
127
|
+
this.#emptyListeners.get(name)?.forEach(listener => listener());
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Calls `listener` whenever the named region loses its last source. Runs
|
|
134
|
+
* after render, so it may change tracked state.
|
|
135
|
+
*/
|
|
136
|
+
onEmpty(name, listener) {
|
|
137
|
+
let listeners = this.#emptyListeners.get(name);
|
|
138
|
+
if (!listeners) {
|
|
139
|
+
listeners = new Set();
|
|
140
|
+
this.#emptyListeners.set(name, listeners);
|
|
141
|
+
}
|
|
142
|
+
const set = listeners;
|
|
143
|
+
set.add(listener);
|
|
144
|
+
return () => set.delete(listener);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { LayoutRegionState, FrontileLayoutRegionsService as default };
|
|
149
|
+
//# sourceMappingURL=frontile-layout-regions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontile-layout-regions.js","sources":["../../src/services/frontile-layout-regions.ts"],"sourcesContent":["import Service from '@ember/service';\nimport { tracked } from '@glimmer/tracking';\nimport { schedule } from '@ember/runloop';\nimport { warn } from '@ember/debug';\n\n/** A mounted target: the element sources render into, and how. */\ninterface RegionTarget {\n readonly element: Element;\n /** Whether every source renders (`true`) or only the newest. */\n readonly multiple: boolean;\n}\n\n/** One named region: where it renders (the target) and who fills it. */\nexport class LayoutRegionState {\n /**\n * Mounted targets in registration order. The newest is the one sources\n * render into; when it goes away, the previous one takes over again.\n * Reassigned, never mutated.\n */\n @tracked targets: readonly RegionTarget[] = [];\n /** Sources in registration (render) order. Reassigned, never mutated. */\n @tracked sources: readonly object[] = [];\n get hasContent(): boolean {\n return this.sources.length > 0;\n }\n\n /** The target sources render into: the newest mounted one. */\n get target(): RegionTarget | undefined {\n return this.targets[this.targets.length - 1];\n }\n\n /** Where `source` should render, or `null` when it is not shown. */\n targetFor(source: object): Element | null {\n const target = this.target;\n if (!target) {\n return null;\n }\n const shown = target.multiple\n ? this.sources.includes(source)\n : this.sources[this.sources.length - 1] === source;\n return shown ? target.element : null;\n }\n}\n\n/**\n * Connects `InLayoutRegion` sources, rendered anywhere in the app, to the\n * layout's named regions. Internal to Frontile: use `layout.Region`,\n * `layout.Aside @region` and `InLayoutRegion` instead.\n *\n * Every write is deferred to `afterRender`. Sources register while the\n * render is running, and the layout, which renders before `{{outlet}}`, has\n * usually already read the same tracked state in that render. Writing it\n * synchronously trips Glimmer's backtracking assertion. The deferred write\n * re-renders in the same runloop, so no paint happens in between.\n */\nexport default class FrontileLayoutRegionsService extends Service {\n #regions = new Map<string, LayoutRegionState>();\n #emptyListeners = new Map<string, Set<() => void>>();\n\n #write(fn: () => void): void {\n schedule('afterRender', () => {\n if (!this.isDestroying && !this.isDestroyed) {\n fn();\n }\n });\n }\n\n /** The named region, created on first use (by a source or a target). */\n region(name: string): LayoutRegionState {\n let region = this.#regions.get(name);\n if (!region) {\n region = new LayoutRegionState();\n this.#regions.set(name, region);\n }\n return region;\n }\n\n /** Whether any source fills the named region (tracked). */\n hasContent(name: string): boolean {\n return this.region(name).hasContent;\n }\n\n /** Where `source` renders in the named region, or `null` (tracked). */\n targetFor(name: string, source: object): Element | null {\n return this.region(name).targetFor(source);\n }\n\n /**\n * Adds an element sources render into. The newest target wins; removing\n * it hands the sources back to the previous one. Returns the undo\n * function, which removes only this registration.\n */\n registerTarget(\n name: string,\n element: Element,\n options: { multiple?: boolean } = {}\n ): () => void {\n const region = this.region(name);\n const target: RegionTarget = {\n element,\n multiple: options.multiple ?? false\n };\n this.#write(() => {\n // A target that has left the document (the aside moving between its\n // column and its drawer) is being replaced, not duplicated.\n warn(\n `frontile: two targets render the layout region \"${name}\" at once; sources follow the newest. Region names are global to the app.`,\n !region.targets.some(\n (other) => other.element !== element && other.element.isConnected\n ),\n { id: 'frontile.layout-region.duplicate-target' }\n );\n region.targets = [...region.targets, target];\n });\n return () =>\n this.#write(() => {\n region.targets = region.targets.filter((t) => t !== target);\n });\n }\n\n /**\n * Adds a source to the named region. Returns the undo function. The\n * removal is deferred too, so a swap in one render goes 1 → 2 → 1 and the\n * region is never seen empty.\n */\n addSource(name: string, source: object): () => void {\n const region = this.region(name);\n this.#write(() => {\n region.sources = [...region.sources, source];\n });\n return () =>\n this.#write(() => {\n const before = region.sources.length;\n region.sources = region.sources.filter((s) => s !== source);\n if (before > 0 && region.sources.length === 0) {\n this.#emptyListeners.get(name)?.forEach((listener) => listener());\n }\n });\n }\n\n /**\n * Calls `listener` whenever the named region loses its last source. Runs\n * after render, so it may change tracked state.\n */\n onEmpty(name: string, listener: () => void): () => void {\n let listeners = this.#emptyListeners.get(name);\n if (!listeners) {\n listeners = new Set();\n this.#emptyListeners.set(name, listeners);\n }\n const set = listeners;\n set.add(listener);\n return () => set.delete(listener);\n }\n}\n\ndeclare module '@ember/service' {\n interface Registry {\n 'frontile-layout-regions': FrontileLayoutRegionsService;\n }\n}\n"],"names":["LayoutRegionState","g","prototype","tracked","i","hasContent","sources","length","target","targets","targetFor","source","shown","multiple","includes","element","FrontileLayoutRegionsService","Service","Map","#write","fn","schedule","isDestroying","isDestroyed","region","name","get","set","registerTarget","options","warn","some","other","isConnected","id","filter","t","addSource","before","s","forEach","listener","onEmpty","listeners","Set","add","delete"],"mappings":";;;;;;AAYA;AACO,MAAMA,iBAAiB,CAAC;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,SAAA,EAAA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EAAE,CAAC;AACnE,MAAA;AACF,IAAA,CAAC,CAAC;AACN,EAAA;;AAEA;AACF;AACA;AACA;AACEC,EAAAA,OAAOA,CAACjB,IAAY,EAAEgB,QAAoB,EAAc;IACtD,IAAIE,SAAS,GAAG,IAAI,CAAC,eAAe,CAACjB,GAAG,CAACD,IAAI,CAAC;IAC9C,IAAI,CAACkB,SAAS,EAAE;AACdA,MAAAA,SAAS,GAAG,IAAIC,GAAG,EAAE;MACrB,IAAI,CAAC,eAAe,CAACjB,GAAG,CAACF,IAAI,EAAEkB,SAAS,CAAC;AAC3C,IAAA;IACA,MAAMhB,GAAG,GAAGgB,SAAS;AACrBhB,IAAAA,GAAG,CAACkB,GAAG,CAACJ,QAAQ,CAAC;AACjB,IAAA,OAAO,MAAMd,GAAG,CAACmB,MAAM,CAACL,QAAQ,CAAC;AACnC,EAAA;AACF;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frontile",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.13",
|
|
4
4
|
"description": "Component Library for Ember Octane apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"@embroider/addon-shim": "^1.11.0",
|
|
99
99
|
"@embroider/macros": "^1.21.4",
|
|
100
100
|
"@floating-ui/dom": "^1.8.0",
|
|
101
|
-
"@frontile/theme": "^0.18.
|
|
101
|
+
"@frontile/theme": "^0.18.13",
|
|
102
102
|
"@glint/template": "^1.11.1",
|
|
103
103
|
"@universal-ember/table": "^4.1.1",
|
|
104
104
|
"date-fns": "^4.4.0",
|
|
@@ -153,8 +153,9 @@
|
|
|
153
153
|
"type": "addon",
|
|
154
154
|
"main": "addon-main.js",
|
|
155
155
|
"app-js": {
|
|
156
|
+
"./services/frontile-layout-regions.js": "./dist/_app_/services/frontile-layout-regions.js",
|
|
156
157
|
"./services/notifications.js": "./dist/_app_/services/notifications.js"
|
|
157
158
|
}
|
|
158
159
|
},
|
|
159
|
-
"gitHead": "
|
|
160
|
+
"gitHead": "3a71985872a2de08f85908329002be2b0a59fea4"
|
|
160
161
|
}
|