@c2n/overlay 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/overlay.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LitElement, html, unsafeCSS } from "lit";
2
2
  import { isServer } from "lit-html/is-server.js";
3
- import { customElement, property } from "lit/decorators.js";
3
+ import { property } from "lit/decorators.js";
4
+ import { customElement } from "@c2n/core/element-helper.js";
4
5
  //#region ../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
5
6
  var min = Math.min;
6
7
  var max = Math.max;
@@ -1163,6 +1164,8 @@ var Overlay = class Overlay extends LitElement {
1163
1164
  super();
1164
1165
  this.open = false;
1165
1166
  this.placement = "bottom-start";
1167
+ this.offset = void 0;
1168
+ this.crossOffset = void 0;
1166
1169
  this.disabledCrossAxis = false;
1167
1170
  this.fitTarget = false;
1168
1171
  this.freeWidth = false;
@@ -1217,8 +1220,8 @@ var Overlay = class Overlay extends LitElement {
1217
1220
  this.cleanupPosition = null;
1218
1221
  }
1219
1222
  async updatePosition(anchor) {
1220
- const mainAxis = this.readPixels("--c2-overlay--offset-y", 8);
1221
- const crossAxis = this.readPixels("--c2-overlay--offset-x", 0);
1223
+ const mainAxis = Number.isFinite(this.offset) ? this.offset : this.readPixels("--c2-overlay--offset-y", 8);
1224
+ const crossAxis = Number.isFinite(this.crossOffset) ? this.crossOffset : this.readPixels("--c2-overlay--offset-x", 0);
1222
1225
  const padding = this.readPixels("--c2-overlay--viewport-padding", 8);
1223
1226
  if (this.fitTarget) this.style.width = `${anchor.offsetWidth}px`;
1224
1227
  else this.style.removeProperty("width");
@@ -1257,7 +1260,7 @@ var Overlay = class Overlay extends LitElement {
1257
1260
  else if (!this.open && isOpen) this.hidePopover();
1258
1261
  } catch {}
1259
1262
  }
1260
- if (changed.has("placement") && this.matches(":popover-open")) this.startPositioning();
1263
+ if ((changed.has("placement") || changed.has("offset") || changed.has("crossOffset")) && this.matches(":popover-open")) this.startPositioning();
1261
1264
  }
1262
1265
  render() {
1263
1266
  return html`<slot></slot>`;
@@ -1268,6 +1271,11 @@ __decorate([property({
1268
1271
  reflect: true
1269
1272
  })], Overlay.prototype, "open", void 0);
1270
1273
  __decorate([property({ reflect: true })], Overlay.prototype, "placement", void 0);
1274
+ __decorate([property({ type: Number })], Overlay.prototype, "offset", void 0);
1275
+ __decorate([property({
1276
+ type: Number,
1277
+ attribute: "cross-offset"
1278
+ })], Overlay.prototype, "crossOffset", void 0);
1271
1279
  __decorate([property({
1272
1280
  type: Boolean,
1273
1281
  reflect: true,
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@c2n/overlay",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/overlay.js",
6
6
  "exports": {
7
7
  ".": {
8
- "default": "./dist/overlay.js",
9
- "types": "./types/src/overlay.d.ts"
8
+ "types": "./types/src/overlay.d.ts",
9
+ "default": "./dist/overlay.js"
10
+ },
11
+ "./react": {
12
+ "types": "./react.d.ts",
13
+ "default": "./react.js"
14
+ },
15
+ "./vue": {
16
+ "types": "./vue.d.ts",
17
+ "default": "./vue.js"
10
18
  },
11
19
  "./custom-elements.json": "./custom-elements.json"
12
20
  },
13
21
  "files": [
14
22
  "dist",
15
- "types"
23
+ "types",
24
+ "react.d.ts",
25
+ "react.js",
26
+ "vue.d.ts",
27
+ "vue.js"
16
28
  ],
17
29
  "keywords": [
18
30
  "overlay",
@@ -48,7 +60,7 @@
48
60
  }
49
61
  },
50
62
  "dependencies": {
51
- "@c2n/core": "0.0.6",
63
+ "@c2n/core": "0.0.8",
52
64
  "@floating-ui/dom": "1.8.0",
53
65
  "lit": "3.3.3"
54
66
  },
@@ -56,5 +68,5 @@
56
68
  "@c2n/config": "*"
57
69
  },
58
70
  "customElements": "custom-elements.json",
59
- "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
71
+ "gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
60
72
  }
package/react.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/overlay. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/overlay/react'
6
+ //
7
+ // Register the elements at module scope before React renders, or React writes an object prop as an
8
+ // attribute and it stringifies.
9
+
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react'
11
+ import type { Overlay } from '@c2n/overlay'
12
+
13
+ /** Standard React host-element attributes plus the element's own public properties. */
14
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
15
+
16
+ declare module 'react' {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'c2-overlay': C2Props<Overlay>
20
+ }
21
+ }
22
+ }
23
+
24
+ export {}
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}
@@ -1,6 +1,16 @@
1
1
  import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
2
3
  import { type Placement } from '@floating-ui/dom';
3
4
  export type { Placement };
5
+ /** Events fired by {@link Overlay}, keyed for `addEventListener`. */
6
+ export interface OverlayEventMap {
7
+ toggle: ToggleEvent;
8
+ beforetoggle: ToggleEvent;
9
+ }
10
+ export interface Overlay {
11
+ addEventListener: TypedAddEventListener<Overlay, OverlayEventMap>;
12
+ removeEventListener: TypedRemoveEventListener<Overlay, OverlayEventMap>;
13
+ }
4
14
  /**
5
15
  * Anchored popup built on the browser Popover API: the element sits in the top layer, opens and light-dismisses
6
16
  * natively (Escape, click outside) and is positioned next to its anchor with floating-ui. The anchor is found in
@@ -30,7 +40,11 @@ export declare class Overlay extends LitElement {
30
40
  /** Open state, kept in sync with the native popover (setting it shows or hides the popover). */
31
41
  open: boolean;
32
42
  /** Preferred placement (floating-ui names). The one in use is reflected as `current-placement`. */
33
- placement: Placement;
43
+ placement: 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
44
+ /** Distance in pixels from the anchor along the placement direction. Falls back to `--c2-overlay--offset-y`. */
45
+ offset: number | undefined;
46
+ /** Shift in pixels perpendicular to the placement direction. Falls back to `--c2-overlay--offset-x`. */
47
+ crossOffset: number | undefined;
34
48
  /** Do not flip across the cross axis when there is no room (only along the main axis). */
35
49
  disabledCrossAxis: boolean;
36
50
  /** Make the overlay exactly as wide as the anchor. */
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAGtE,OAAO,EAA0D,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGzG,YAAY,EAAE,SAAS,EAAE,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBACa,OAAQ,SAAQ,UAAU;IACrC,OAAgB,MAAM,0BAAoB;IAE1C,gGAAgG;IACpD,IAAI,UAAQ;IAExD,mGAAmG;IACtE,SAAS,EAAE,SAAS,CAAiB;IAElE,0FAA0F;IACZ,iBAAiB,UAAQ;IAEvG,sDAAsD;IACA,SAAS,UAAQ;IAEvE,yGAAyG;IACnD,SAAS,UAAQ;IAEvE,iIAAiI;IACrH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAY;IAEhE,OAAO,CAAC,eAAe,CAA4B;;IAU1C,iBAAiB;IAKjB,oBAAoB;IAK7B,2CAA2C;IAC3C,IAAI,aAAa,IAAI,WAAW,GAAG,IAAI,CAetC;IAED,OAAO,CAAC,kBAAkB,CAGzB;IAED,OAAO,CAAC,YAAY,CAEnB;IAED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,GAAG,SAAS,CAAY;IAElG,0FAA0F;IACZ,iBAAiB,UAAQ;IAEvG,sDAAsD;IACA,SAAS,UAAQ;IAEvE,yGAAyG;IACnD,SAAS,UAAQ;IAEvE,iIAAiI;IACrH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAY;IAEhE,OAAO,CAAC,eAAe,CAA4B;;IAU1C,iBAAiB;IAKjB,oBAAoB;IAK7B,2CAA2C;IAC3C,IAAI,aAAa,IAAI,WAAW,GAAG,IAAI,CAetC;IAED,OAAO,CAAC,kBAAkB,CAGzB;IAED,OAAO,CAAC,YAAY,CAEnB;IAED,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,eAAe;YAKT,cAAc;IA8BnB,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAarC,MAAM;CAGhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,OAAO,CAAA;KACtB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/overlay. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/overlay/vue'
6
+ //
7
+ // Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
8
+ // nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
9
+
10
+ import type { DefineComponent, HTMLAttributes } from 'vue'
11
+ import type { Overlay, OverlayEventMap } from '@c2n/overlay'
12
+
13
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
14
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
15
+
16
+ declare module 'vue' {
17
+ interface GlobalComponents {
18
+ 'c2-overlay': DefineComponent<
19
+ C2Props<Overlay> & {
20
+ 'cross-offset'?: unknown
21
+ 'disabled-cross-axis'?: unknown
22
+ 'fit-anchor'?: unknown
23
+ 'free-width'?: unknown
24
+ onToggle?: (event: OverlayEventMap['toggle']) => void
25
+ onBeforetoggle?: (event: OverlayEventMap['beforetoggle']) => void
26
+ }
27
+ >
28
+ }
29
+ }
30
+
31
+ declare module '@vue/runtime-dom' {
32
+ interface HTMLAttributes {
33
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
34
+ slot?: string
35
+ }
36
+ }
37
+
38
+ export {}
package/vue.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}