Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* make more use of early returns
* improved ScrollSpy performance
* added new utility isDisabled to only attach event listeners to interactive elements
* update resolve tooling
* update dependencies
* update tests
* update docs
  • Loading branch information
thednp committed Nov 16, 2024
1 parent bf69dd7 commit 5ad2e59
Show file tree
Hide file tree
Showing 128 changed files with 3,203 additions and 3,015 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
[![NPM Version](https://img.shields.io/npm/v/bootstrap.native.svg)](https://www.npmjs.com/package/bootstrap.native)
[![jsDeliver](https://img.shields.io/jsdelivr/npm/hw/bootstrap.native)](https://www.jsdelivr.com/package/npm/bootstrap.native)
[![typescript version](https://img.shields.io/badge/typescript-5.6.3-brightgreen)](https://www.typescriptlang.org/)
[![vitest version](https://img.shields.io/badge/vitest-2.1.4-brightgreen)](https://vitest.dev/)
[![vite version](https://img.shields.io/badge/vite-5.4.10-brightgreen)](https://vitejs.dev/)
[![vitest version](https://img.shields.io/badge/vitest-2.1.5-brightgreen)](https://vitest.dev/)
[![vite version](https://img.shields.io/badge/vite-5.4.11-brightgreen)](https://vitejs.dev/)


The faster, lighter and more compact set of JavaScript components for **Bootstrap 5**, sourced with TypeScript and free from major dependecies such as jQuery, Popper.

The **bootstrap.native** library is available on npm, CDN and comes packed with Cypress powered tests and other goodies.
The **bootstrap.native** library is available on npm, CDN and comes packed with Vitest powered tests and other goodies.


The library is around ***39Kb*** minified and around ***12Kb*** gZipped. See <a href="http://thednp.github.io/bootstrap.native/">the demo</a> for components guidelines and examples, or the [Wiki/How to use](https://github.com/thednp/bootstrap.native/wiki/How-to-use) on how to install and use the library.
The library is around ***42Kb*** minified and around ***13Kb*** gZipped. See <a href="http://thednp.github.io/bootstrap.native/">the demo</a> for components guidelines and examples, or the [Wiki/How to use](https://github.com/thednp/bootstrap.native/wiki/How-to-use) on how to install and use the library.


# Wiki
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bootstrap-native.cjs.map

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions dist/bootstrap-native.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { default as default_2 } from '@thednp/position-observer';
import { MouseEvent as MouseEvent_2 } from '@thednp/shorty';
import { TouchEvent as TouchEvent_2 } from '@thednp/shorty';

/** Creates a new Alert instance. */
Expand Down Expand Up @@ -390,16 +391,11 @@ export declare class ScrollSpy extends BaseComponent {
static getInstance: (element: Element) => ScrollSpy | null;
element: HTMLElement;
options: ScrollSpyOptions;
target: HTMLElement | null;
target: HTMLElement;
scrollTarget: HTMLElement;
scrollTop: number;
maxScroll: number;
scrollHeight: number;
activeItem: HTMLElement | null;
items: HTMLElement[];
targets: HTMLElement[];
itemsLength: number;
offsets: number[];
_itemsLength: number;
_activeItem: HTMLElement | null;
_observables: Map<HTMLElement, HTMLElement>;
_observer: default_2;
/**
* @param target the target element
Expand All @@ -416,13 +412,28 @@ export declare class ScrollSpy extends BaseComponent {
get defaults(): Partial<ScrollSpyOptions>;
/** Updates all items. */
refresh: () => void;
/**
* This method provides an event handle
* for scrollspy
* @param e the event listener object
*/
_scrollTo: (e: MouseEvent_2<HTMLAnchorElement>) => void;
/**
* Toggles on/off the component observer.
*
* @param self the ScrollSpy instance
* @param add when `true`, listener is added
*/
_toggleEventListeners: (add?: boolean) => void;
/** Removes `ScrollSpy` from the target element. */
dispose(): void;
}

declare interface ScrollSpyOptions extends BaseOptions {
offset: number;
target: HTMLElement | string;
threshold: number | number[];
rootMargin: string;
}

/** Creates a new `Tab` instance. */
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-native.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bootstrap-native.js.map

Large diffs are not rendered by default.

1,836 changes: 922 additions & 914 deletions dist/bootstrap-native.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bootstrap-native.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/components/alert.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"use strict";const e=require("./base-component-DaZCwW-u.js"),i=require("./event-listener-BQdA_KAC.js"),u=require("./fadeClass-Co6nOzNJ.js"),r=require("./showClass-D_Ms1FgG.js"),h=require("./dataBsDismiss-CMHF7If_.js"),n="alert",a="Alert",v=`.${n}`,p=`[${h.dataBsDismiss}="${n}"]`,C=t=>e.to(t,a),E=t=>new d(t),c=e.vo(`close.bs.${n}`),q=e.vo(`closed.bs.${n}`),l=t=>{const{element:s}=t;e.q(s,q),t._toggleEventListeners(),t.dispose(),s.remove()};class d extends e.BaseComponent{static selector=v;static init=E;static getInstance=C;dismiss;constructor(s){super(s),this.dismiss=e.Ro(p,this.element),this._toggleEventListeners(!0)}get name(){return a}close=()=>{const{element:s}=this;s&&e.Yn(s,r.showClass)&&(e.q(s,c),c.defaultPrevented||(e.Zn(s,r.showClass),e.Yn(s,u.fadeClass)?e.ro(s,()=>l(this)):l(this)))};_toggleEventListeners=s=>{const m=s?i.E:i.r,{dismiss:o,close:g}=this;o&&m(o,e.mt,g)};dispose(){this._toggleEventListeners(),super.dispose()}}module.exports=d;
"use strict";const s=require("./base-component-CEXwoid1.js"),u=require("./fadeClass-Co6nOzNJ.js"),i=require("./showClass-D_Ms1FgG.js"),g=require("./dataBsDismiss-CMHF7If_.js"),h=require("./isDisabled-CST_xG4K.js"),n="alert",l="Alert",p=`.${n}`,v=`[${g.dataBsDismiss}="${n}"]`,C=t=>s.to(t,l),E=t=>new a(t),r=s.mo(`close.bs.${n}`),q=s.mo(`closed.bs.${n}`),c=t=>{const{element:e}=t;s.q(e,q),t._toggleEventListeners(),t.dispose(),e.remove()};class a extends s.BaseComponent{static selector=p;static init=E;static getInstance=C;dismiss;constructor(e){super(e),this.dismiss=s.Ro(v,this.element),this._toggleEventListeners(!0)}get name(){return l}close=()=>{const{element:e}=this;!e||!s.Zn(e,i.showClass)||(s.q(e,r),!r.defaultPrevented&&(s.Yn(e,i.showClass),s.Zn(e,u.fadeClass)?s.so(e,()=>c(this)):c(this)))};_toggleEventListeners=e=>{const d=e?s.E:s.r,{dismiss:o,close:m}=this;o&&!h.isDisabled(o)&&d(o,s.vt,m)};dispose(){this._toggleEventListeners(),super.dispose()}}module.exports=a;
//# sourceMappingURL=alert.cjs.map
2 changes: 1 addition & 1 deletion dist/components/alert.cjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions dist/components/alert.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { B as g, R as f, Y as n, q as l, Z as v, r as h, t as E, v as c, m as u } from "./base-component-Jx2aafTJ.mjs";
import { E as A, r as C } from "./event-listener-CUwvA4j6.mjs";
import { B as g, t as f, R as v, Z as n, q as l, m as c, Y as h, s as u, E, r as A, v as C } from "./base-component-CQAH5ZXF.mjs";
import { f as $ } from "./fadeClass-CLIYI_zn.mjs";
import { s as i } from "./showClass-C8hdJfjQ.mjs";
import { d as L } from "./dataBsDismiss-DdNPQYa-.mjs";
const e = "alert", m = "Alert", _ = `.${e}`, b = `[${L}="${e}"]`, B = (t) => E(t, m), I = (t) => new w(t), r = c(
import { d as b } from "./dataBsDismiss-DdNPQYa-.mjs";
import { i as L } from "./isDisabled-bThyhy2g.mjs";
const e = "alert", m = "Alert", _ = `.${e}`, B = `[${b}="${e}"]`, D = (t) => f(t, m), I = (t) => new w(t), r = c(
`close.bs.${e}`
), S = c(
`closed.bs.${e}`
Expand All @@ -14,11 +14,11 @@ const e = "alert", m = "Alert", _ = `.${e}`, b = `[${L}="${e}"]`, B = (t) => E(t
class w extends g {
static selector = _;
static init = I;
static getInstance = B;
static getInstance = D;
dismiss;
constructor(s) {
super(s), this.dismiss = f(
b,
super(s), this.dismiss = v(
B,
this.element
), this._toggleEventListeners(!0);
}
Expand All @@ -32,16 +32,16 @@ class w extends g {
*/
close = () => {
const { element: s } = this;
s && n(s, i) && (l(s, r), r.defaultPrevented || (v(s, i), n(s, $) ? h(s, () => a(this)) : a(this)));
!s || !n(s, i) || (l(s, r), !r.defaultPrevented && (h(s, i), n(s, $) ? u(s, () => a(this)) : a(this)));
};
/**
* Toggle on / off the `click` event listener.
*
* @param add when `true`, event listener is added
*/
_toggleEventListeners = (s) => {
const d = s ? A : C, { dismiss: o, close: p } = this;
o && d(o, u, p);
const d = s ? E : A, { dismiss: o, close: p } = this;
o && !L(o) && d(o, C, p);
};
dispose() {
this._toggleEventListeners(), super.dispose();
Expand Down
Loading

0 comments on commit 5ad2e59

Please sign in to comment.