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

slack-block-builder

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slack-block-builder - npm Package Compare versions

Comparing version 2.2.0-beta.0 to 2.2.0-beta.1

dist/lib/paginator-state-manager.d.ts

4

dist/components/accordion.d.ts

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

import type { AccordionStateManager, State } from '../lib';
import type { AccordionStateManager, AccordionState } from '../lib';
import type { BlockBuilderReturnableFn, BlockBuilder, StringReturnableFn } from '../types';
export declare type TitleTextFn<T> = StringReturnableFn<T>;
export interface AccordionActionIdParams {
state: State;
expandedItems: AccordionState;
}

@@ -7,0 +7,0 @@ export declare type AccordionActionIdFn = StringReturnableFn<AccordionActionIdParams>;

@@ -25,3 +25,3 @@ "use strict";

actionId: this.actionIdFunction({
state: this.stateManager.getNextStateByItemIndex(index),
expandedItems: this.stateManager.getNextStateByItemIndex(index),
}),

@@ -28,0 +28,0 @@ })),

import { PaginatorUIComponent, PaginatorUIComponentParams } from './paginator';
import { AccordionUIComponent, AccordionUIComponentParams } from './accordion';
import { PaginationCalculatorParams, AccordionStateManagerParams } from '../lib';
import { PaginatorStateManagerParams, AccordionStateManagerParams } from '../lib';
export type { PaginatorUIComponent };
export type { AccordionUIComponent };
export declare type PaginatorParams<T> = PaginationCalculatorParams & Omit<PaginatorUIComponentParams<T>, 'paginator'>;
export declare type PaginatorParams<T> = PaginatorStateManagerParams & Omit<PaginatorUIComponentParams<T>, 'paginator'>;
export declare function Paginator<T>(params: PaginatorParams<T>): PaginatorUIComponent<T>;
export declare type EasyPaginatorParams<T> = Omit<PaginatorParams<T>, 'totalItems'>;
export declare function EasyPaginator<T>(params: EasyPaginatorParams<T>): PaginatorUIComponent<T>;
export declare type AccordionParams<T> = Omit<AccordionUIComponentParams<T>, 'stateManager'> & Omit<AccordionStateManagerParams, 'totalItems'>;
export declare type AccordionParams<T> = Omit<AccordionUIComponentParams<T>, 'stateManager'> & AccordionStateManagerParams;
export declare function Accordion<T>(params: AccordionParams<T>): AccordionUIComponent<T>;

@@ -12,0 +12,0 @@ declare const components: {

@@ -9,3 +9,3 @@ "use strict";

const { page, perPage, totalItems } = params;
const paginationCalculator = new lib_1.PaginationCalculator({ page, perPage, totalItems });
const paginationCalculator = new lib_1.PaginatorStateManager({ page, perPage, totalItems });
return new paginator_1.PaginatorUIComponent({

@@ -24,3 +24,3 @@ paginator: paginationCalculator,

const totalItems = items.length;
const paginationCalculator = new lib_1.PaginationCalculator({ page, perPage, totalItems });
const paginationCalculator = new lib_1.PaginatorStateManager({ page, perPage, totalItems });
const extractedItems = paginationCalculator.extractItems(items);

@@ -38,5 +38,4 @@ return new paginator_1.PaginatorUIComponent({

function Accordion(params) {
const { items, collapseOnExpand, state } = params;
const totalItems = items.length;
const stateManager = new lib_1.AccordionStateManager({ state, collapseOnExpand, totalItems });
const { items, expandedItems, collapseOnExpand } = params;
const stateManager = new lib_1.AccordionStateManager({ expandedItems, collapseOnExpand });
return new accordion_1.AccordionUIComponent({

@@ -43,0 +42,0 @@ items,

import type { StringReturnableFn, BlockBuilderReturnableFn, BlockBuilder } from '../types';
import type { PaginationCalculator } from '../lib';
export interface PaginatorActionIdParams<T> {
page: number;
totalItems: number;
perPage: number;
offset: number;
totalPages: number;
import type { PaginatorStateManager, PaginatorState } from '../lib';
export interface PaginatorActionIdParams<T> extends PaginatorState {
cursor: T;

@@ -19,3 +14,3 @@ }

items: T[];
paginator: PaginationCalculator;
paginator: PaginatorStateManager;
nextButtonText?: string;

@@ -22,0 +17,0 @@ previousButtonText?: string;

@@ -17,11 +17,8 @@ "use strict";

}
getActionIdParams(offset) {
const isMoveForward = offset < this.paginator.getOffset();
getActionIdParams(state) {
return {
offset,
page: this.paginator.getPageByOffset(offset),
totalItems: this.paginator.getTotalItems(),
perPage: this.paginator.getPerPage(),
totalPages: this.paginator.getTotalPages(),
cursor: isMoveForward ? this.items[this.items.length - 1] : this.items[0],
...state,
cursor: this.paginator.checkStateIsMoveForward(state)
? this.items[this.items.length - 1]
: this.items[0],
};

@@ -45,6 +42,6 @@ }

text: this.previousButtonText,
actionId: this.actionIdFunction(this.getActionIdParams(this.paginator.getPreviousPageOffset())),
actionId: this.actionIdFunction(this.getActionIdParams(this.paginator.getPreviousPageState())),
}), elements_1.Elements.Button({
text: this.nextButtonText,
actionId: this.actionIdFunction(this.getActionIdParams(this.paginator.getNextPageOffset())),
actionId: this.actionIdFunction(this.getActionIdParams(this.paginator.getNextPageState())),
})),

@@ -51,0 +48,0 @@ ]

@@ -1,18 +0,12 @@

export declare type State = number[];
export declare type AccordionState = number[];
export interface AccordionStateManagerParams {
totalItems: number;
state: State;
expandedItems: AccordionState;
collapseOnExpand?: boolean;
}
export declare class AccordionStateManager {
private readonly totalItems;
private readonly state;
private readonly expandedItems;
private readonly collapseOnExpand;
constructor(params: AccordionStateManagerParams);
private static isExpanded;
private initializeState;
private getDefaultState;
getItemStateByIndex(index: number): number;
checkItemIsExpandedByIndex(index: number): boolean;
getNextStateByItemIndex(index: number): State;
getNextStateByItemIndex(index: number): AccordionState;
}

@@ -6,42 +6,25 @@ "use strict";

constructor(params) {
this.totalItems = params.totalItems;
this.state = this.initializeState(params.state);
this.expandedItems = params.expandedItems || [];
this.collapseOnExpand = params.collapseOnExpand || false;
}
static isExpanded(position) {
return Math.sign(position) === -1;
}
initializeState(state) {
return Array.isArray(state) && state.length > 0
? state
: this.getDefaultState();
}
getDefaultState() {
const defaultState = [];
for (let i = 0; i < this.totalItems; i += 1) {
defaultState.push(i + 1);
}
return defaultState;
}
getItemStateByIndex(index) {
return this.state.find((position) => Math.abs(position) === index + 1);
}
checkItemIsExpandedByIndex(index) {
const itemState = this.getItemStateByIndex(index);
return AccordionStateManager.isExpanded(itemState);
return this.expandedItems.includes(index);
}
getNextStateByItemIndex(index) {
const currentState = this.getItemStateByIndex(index);
return this.state.map((itemState) => {
if (currentState === itemState) {
return AccordionStateManager.isExpanded(itemState)
? Math.abs(itemState)
: -Math.abs(itemState);
}
return this.collapseOnExpand
? Math.abs(itemState)
: itemState;
});
if (index === undefined) {
return this.expandedItems;
}
const isExpanded = this.checkItemIsExpandedByIndex(index);
if (isExpanded) {
const nextState = [...this.expandedItems];
const expandedItemsIndex = this.expandedItems
.findIndex((expandedItem) => expandedItem === index);
nextState.splice(expandedItemsIndex, 1);
return nextState;
}
return this.collapseOnExpand
? [index]
: [...this.expandedItems, index];
}
}
exports.AccordionStateManager = AccordionStateManager;
export * from './accordion-state-manager';
export * from './builder';
export * from './error';
export * from './pagination-calculator';
export * from './paginator-state-manager';
export * from './slack-dto';

@@ -16,3 +16,3 @@ "use strict";

__exportStar(require("./error"), exports);
__exportStar(require("./pagination-calculator"), exports);
__exportStar(require("./paginator-state-manager"), exports);
__exportStar(require("./slack-dto"), exports);

@@ -12,4 +12,4 @@ import type { BlockBuilder } from './builder-union-types';

export declare type Appendable<T> = UndefinableArray<T | UndefinableArray<T>>;
export declare type Callback<T, R> = (params: T) => R;
export declare type BlockBuilderReturnableFn<T> = Callback<T, BlockBuilder[]>;
export declare type StringReturnableFn<T> = Callback<T, string>;
export declare type Fn<T, R> = (arg: T) => R;
export declare type BlockBuilderReturnableFn<T> = Fn<T, BlockBuilder[]>;
export declare type StringReturnableFn<T> = Fn<T, string>;
{
"name": "slack-block-builder",
"version": "2.2.0-beta.0",
"version": "2.2.0-beta.1",
"description": "Maintainable code for interactive Slack messages, modals, home tabs, and workflow steps. A must-have for the Slack Block Kit framework.",

@@ -5,0 +5,0 @@ "author": {

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