Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lssm

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lssm - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

33

dist/index.d.ts

@@ -11,5 +11,5 @@ export interface ModifierConfig {

private items;
private selectedItems;
private lastSelectedItem;
private lastNonShiftClickedItem;
private selected;
private lastSelected;
private lastNonShiftToggled;
private defaultConfig;

@@ -19,9 +19,10 @@ /**

*/
private setSelectedItemRange;
private setSingleSelectedItem;
private toggleItem;
private removeItemFromSelection;
private appendItemsToSelection;
private itemIsSelected;
private itemsAsGroups;
private setRange;
private setSingle;
private toggle;
private remove;
private append;
private isSelected;
private asGroups;
private getGroup;
/**

@@ -34,8 +35,10 @@ * Constructor

*/
selectItem(item: T, config?: ModifierConfig): this;
nextItem(config?: ModifierConfig): this;
previousItem(config?: ModifierConfig): this;
getSelectedItems(): T[];
clearSelection(): this;
select(item: T, config?: ModifierConfig): this;
next(config?: ModifierConfig): this;
previous(config?: ModifierConfig): this;
get(): T[];
getIndices(): number[];
set(items: T[]): this;
selectAll(): this;
clear(): this;
}

@@ -1,1 +0,1 @@

var lssm=function(h){"use strict";var g=Object.defineProperty;var p=(h,d,I)=>d in h?g(h,d,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[d]=I;var r=(h,d,I)=>(p(h,typeof d!="symbol"?d+"":d,I),I);class d{constructor(e){r(this,"items",[]);r(this,"selectedItems",[]);r(this,"lastSelectedItem",null);r(this,"lastNonShiftClickedItem",null);r(this,"defaultConfig",{ctrlKey:!1,metaKey:!1,shiftKey:!1});this.items=e}setSelectedItemRange(e){if(this.selectedItems.length){const s=this.lastNonShiftClickedItem,i=this.items.indexOf(s),t=this.items.indexOf(e);let l=0,f=0;if(this.itemIsSelected(s))l=Math.min(i,t),f=Math.max(i,t);else{const n=this.itemsAsGroups(),m=n.find(c=>c.includes(this.items[t]));if(m)if(i>t){const c=n.indexOf(m)+1;l=t,f=this.items.findIndex(o=>o===n[c][0])}else l=this.items.findIndex(c=>c===m[0]),f=t;else{const c=n.findIndex(a=>a.some(x=>this.items.indexOf(x)>i)),o=this.items.findIndex(a=>a===n[c][0]);i>t?(l=t,f=o):(l=o,f=t)}}const u=this.items.slice(l,f+1),S=this.itemsAsGroups().filter(n=>!u.some(m=>n.includes(m)));this.selectedItems=[...new Set([...u,...S.flat()])].sort((n,m)=>this.items.indexOf(n)-this.items.indexOf(m))}else{const s=this.items.indexOf(e);if(s<0)return;this.selectedItems=this.items.slice(0,s+1)}}setSingleSelectedItem(e){this.selectedItems=[e]}toggleItem(e){this.itemIsSelected(e)?this.removeItemFromSelection(e):this.appendItemsToSelection(e)}removeItemFromSelection(e){this.selectedItems=this.selectedItems.filter(s=>s!==e)}appendItemsToSelection(e){this.itemIsSelected(e)||(this.selectedItems=[...this.selectedItems,e])}itemIsSelected(e){return this.selectedItems.includes(e)}itemsAsGroups(){return this.items.reduce((e,s)=>{if(!this.itemIsSelected(s)||e.flat().includes(s))return e;let i=[];i=[...i,s];let t=this.items.indexOf(s);for(;this.itemIsSelected(this.items[t+1]);)i=[...i,this.items[t+1]],t++;return[...e,i]},[])}selectItem(e,s=this.defaultConfig){s={...this.defaultConfig,...s};const{ctrlKey:i,shiftKey:t}=s,l=s.metaKey||i;return l?this.toggleItem(e):t&&!l?this.setSelectedItemRange(e):this.setSingleSelectedItem(e),this.itemIsSelected(e)&&(this.lastSelectedItem=e),t||(this.lastNonShiftClickedItem=e),this}nextItem(e=this.defaultConfig){e={...this.defaultConfig,...e};const{shiftKey:s}=e;if(!this.selectedItems.length)this.selectedItems=[this.items[0]];else{const i=this.items.indexOf(this.lastSelectedItem);if(i<this.items.length-1){let t;i<this.items.indexOf(this.lastNonShiftClickedItem)?t=this.items[i+1]:t=this.items.find(l=>this.items.indexOf(l)>i&&!this.itemIsSelected(l)),s?this.itemIsSelected(t)?(this.selectedItems=this.selectedItems.filter(l=>l!==this.lastSelectedItem),this.lastSelectedItem=t):(this.selectedItems=[...this.selectedItems,t],this.lastSelectedItem=t):(this.selectedItems=[t],this.lastSelectedItem=t)}}return this}previousItem(e=this.defaultConfig){e={...this.defaultConfig,...e};const{shiftKey:s}=e;if(!this.selectedItems.length)this.selectedItems=[this.items[this.items.length-1]];else{const i=this.items.indexOf(this.lastSelectedItem);if(i>0){let t;i>this.items.indexOf(this.lastNonShiftClickedItem)?t=this.items[i-1]:t=this.items.slice().reverse().find(l=>this.items.indexOf(l)<=i&&!this.itemIsSelected(l)),s?this.itemIsSelected(t)?(this.selectedItems=this.selectedItems.filter(l=>l!==this.lastSelectedItem),this.lastSelectedItem=t):(this.selectedItems=[...this.selectedItems,t],this.lastSelectedItem=t):(this.selectedItems=[t],this.lastSelectedItem=t)}}return this}getSelectedItems(){return this.selectedItems.sort((e,s)=>this.items.indexOf(e)-this.items.indexOf(s))}clearSelection(){return this.selectedItems=[],this}selectAll(){return this.selectedItems=[...this.items],this}}return h.ListSelectionStateManager=d,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),h}({});
var lssm=function(n){"use strict";var p=Object.defineProperty;var I=(n,d,f)=>d in n?p(n,d,{enumerable:!0,configurable:!0,writable:!0,value:f}):n[d]=f;var a=(n,d,f)=>(I(n,typeof d!="symbol"?d+"":d,f),f);class d{constructor(t){a(this,"items",[]);a(this,"selected",[]);a(this,"lastSelected",null);a(this,"lastNonShiftToggled",null);a(this,"defaultConfig",{ctrlKey:!1,metaKey:!1,shiftKey:!1});this.items=t}setRange(t){if(this.selected.length){const s=this.lastNonShiftToggled,e=this.items.indexOf(s),i=this.items.indexOf(t);let h=0,l=0;if(this.isSelected(s))h=Math.min(e,i),l=Math.max(e,i);else{const r=this.asGroups(),c=r.find(o=>o.includes(this.items[i]));if(c)if(e>i){const o=r.indexOf(c)+1;h=i,l=this.items.findIndex(u=>u===r[o][0])}else h=this.items.findIndex(o=>o===c[0]),l=i;else{const o=r.findIndex(g=>g.some(x=>this.items.indexOf(x)>e)),u=this.items.findIndex(g=>g===r[o][0]);e>i?(h=i,l=u):(h=u,l=i)}}const S=this.items.slice(h,l+1),m=this.asGroups().filter(r=>!S.some(c=>r.includes(c)));this.set([...new Set([...S,...m.flat()])])}else{const s=this.items.indexOf(t);if(s<0)return;this.set(this.items.slice(0,s+1))}}setSingle(t){this.selected=[t]}toggle(t){this.isSelected(t)?this.remove(t):this.append(t)}remove(t){this.set(this.selected.filter(s=>s!==t))}append(t){this.isSelected(t)||this.set([...this.selected,t])}isSelected(t){return this.selected.includes(t)}asGroups(){return this.items.reduce((t,s)=>{if(!this.isSelected(s)||t.flat().includes(s))return t;let e=[s],i=this.items.indexOf(s);for(;this.isSelected(this.items[i+1]);)e=[...e,this.items[i+1]],i++;return[...t,e]},[])}getGroup(t){return this.isSelected?this.asGroups().find(s=>s.includes(t))??[]:[]}select(t,s=this.defaultConfig){s={...this.defaultConfig,...s};const{ctrlKey:e,shiftKey:i}=s,h=s.metaKey||e;return h?this.toggle(t):i&&!h?this.setRange(t):this.setSingle(t),this.isSelected(t)&&(this.lastSelected=t),i||(this.lastNonShiftToggled=t),this}next(t=this.defaultConfig){t={...this.defaultConfig,...t};const{shiftKey:s}=t;let e;if(!this.selected.length)return e=this.items[0],this.set([e]),this.lastSelected=e,this.lastNonShiftToggled=e,this;const i=this.items.indexOf(this.lastSelected),h=this.items.indexOf(this.lastNonShiftToggled);if(e=this.items[i+1],s){if(i>=h){this.append(e);const l=this.getGroup(e);this.lastSelected=l[l.length-1]}else{e=this.lastSelected;const l=this.getGroup(e);this.remove(e),this.lastSelected=l.length===1?l[0]:l[1],this.lastNonShiftToggled=l[l.length-1]}return this}else i===this.items.length-1?this.set([this.items[this.items.length-1]]):this.set([e]),this.lastSelected=e;return this}previous(t=this.defaultConfig){t={...this.defaultConfig,...t};const{shiftKey:s}=t;let e;if(!this.selected.length)return e=this.items[this.items.length-1],this.set([e]),this.lastSelected=e,this.lastNonShiftToggled=e,this;const i=this.items.indexOf(this.lastSelected),h=this.items.indexOf(this.lastNonShiftToggled);if(e=this.items[i-1],s){if(i<=h){this.append(e);const l=this.getGroup(e);this.lastSelected=l[0]}else{e=this.lastSelected;const l=this.getGroup(e);this.remove(e),this.lastNonShiftToggled=l[0],this.lastSelected=l[Math.max(0,l.length-2)]}return this}else i<1?this.set([this.items[0]]):this.set([e]),this.lastSelected=e;return this}get(){return this.selected.sort((t,s)=>this.items.indexOf(t)-this.items.indexOf(s))}getIndices(){return this.selected.map(t=>this.items.indexOf(t))}set(t){return this.selected=t.sort((s,e)=>this.items.indexOf(s)-this.items.indexOf(e)),this.selected.length||(this.lastSelected=null,this.lastNonShiftToggled=null),this}selectAll(){return this.set([...this.items]),this}clear(){return this.set([]),this}}return n.ListSelectionStateManager=d,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),n}({});
{
"name": "lssm",
"version": "1.0.0",
"version": "1.0.1",
"repository": "https://github.com/syropian/lssm",

@@ -21,3 +21,3 @@ "author": "Collin Henderson <collin@syropia.net>",

"dev": "vite",
"build": "tsc && vite build",
"build": "tsc ./src/index.ts --target es2017 --noEmit && vite build",
"build:demo": "vite build --mode demo",

@@ -30,7 +30,7 @@ "test": "vitest run",

"devDependencies": {
"@tailwindcss/typography": "^0.5.7",
"@types/node": "^18.7.23",
"@tailwindcss/typography": "^0.5.9",
"@types/node": "^20.3.1",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@vitejs/plugin-vue": "^3.1.2",
"@vitejs/plugin-vue": "^4.2.3",
"autoprefixer": "^10.4.12",

@@ -41,10 +41,10 @@ "eslint": "^8.24.0",

"postcss": "^8.4.18",
"prettier": "^2.7.1",
"tailwindcss": "^3.2.1",
"typescript": "^4.6.4",
"vite": "^3.1.0",
"vite-plugin-dts": "^1.6.4",
"vitest": "^0.23.4",
"vue": "^3.2.41"
"prettier": "^2.8.8",
"tailwindcss": "^3.3.2",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"vite-plugin-dts": "^2.3.0",
"vitest": "^0.32.2",
"vue": "^3.3.4"
}
}

@@ -9,3 +9,3 @@ # lssm [![Tests](https://github.com/syropian/lssm/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/syropian/lssm/actions/workflows/test.yml)

## Can I customize the style my lists?
## Can I customize the style of my lists?

@@ -12,0 +12,0 @@ `lssm` works purely with data and has no opinions on your UI layer. You can use a list manager to return the currently selected items, compare them against the orignal list of items, and render your UI accordingly.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc