Skip to content

Commit e6ea55b

Browse files
Mohsinmohsinhijazee
Mohsin
authored andcommitted
ComboBox - New methods + bullet proofing.
Changes to the Combobox - Constructor does not rely on `window.$hsComboBoxCollection` being initalised. Thus users for bundlers (vite etc) don't have to load all of `preline.js` - Fixed an error about invalid nullish statement Public methods selectValue() and selectAttribute - selectedItem() returns elemnent that was selected - selectedValue() returns the value. - selectedAttr() returns the custom attribute. One option to the ComboBox options: - apiSearchQueryTransformer to allow transforming query before fetch package.json: Few watch commands and generation scripts added.
1 parent 0c521a3 commit e6ea55b

13 files changed

+2485
-67
lines changed

dist/combobox.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface IComboBoxOptions {
2424
apiDataPart?: string | null;
2525
apiQuery?: string | null;
2626
apiSearchQuery?: string | null;
27+
apiSearchQueryTransformer?: QueryTransformer | string | null;
2728
apiHeaders?: {};
2829
apiGroupField?: string | null;
2930
outputItemTemplate?: string | null;
@@ -40,8 +41,12 @@ export interface IComboBox {
4041
options?: IComboBoxOptions;
4142
open(): void;
4243
close(): void;
44+
selectedItem(): HTMLElement | null;
45+
selectedValue(): string | null;
46+
selectedAttr(attr: string): string | null;
4347
recalculateDirection(): void;
4448
}
49+
export type QueryTransformer = (query: string) => string;
4550
declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComboBox {
4651
gap: number;
4752
viewport: string | HTMLElement | null;
@@ -50,6 +55,7 @@ declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComb
5055
apiDataPart: string | null;
5156
apiQuery: string | null;
5257
apiSearchQuery: string | null;
58+
apiSearchQueryTransformer: ((query: string) => string) | null;
5359
apiHeaders: {};
5460
apiGroupField: string | null;
5561
outputItemTemplate: string | null;
@@ -65,6 +71,7 @@ declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComb
6571
private readonly output;
6672
private readonly itemsWrapper;
6773
private items;
74+
private selectedItemElement;
6875
private tabs;
6976
private readonly toggle;
7077
private readonly toggleClose;
@@ -79,6 +86,7 @@ declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComb
7986
isCurrent: boolean;
8087
private animationInProcess;
8188
constructor(el: HTMLElement, options?: IComboBoxOptions, events?: {});
89+
private parseApiQueryTransformer;
8290
private init;
8391
private build;
8492
private setResultAndRender;
@@ -114,9 +122,13 @@ declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComb
114122
private destroyOutputPlaceholder;
115123
private resultItems;
116124
private setValueAndOpen;
117-
open(val?: string): boolean;
118125
private setValueAndClear;
126+
open(val?: string): boolean;
119127
close(val?: string | null): boolean;
128+
setSearchQueryTransformer(transformer: (query: string) => string): void;
129+
selectedItem(): HTMLElement | null;
130+
selectedValue(): string | null;
131+
selectedAttr(attr: string): string | null;
120132
recalculateDirection(): void;
121133
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSComboBox | ICollectionItem<HSComboBox>;
122134
static autoInit(): void;

dist/index.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export interface IComboBoxOptions {
207207
apiDataPart?: string | null;
208208
apiQuery?: string | null;
209209
apiSearchQuery?: string | null;
210+
apiSearchQueryTransformer?: QueryTransformer | string | null;
210211
apiHeaders?: {};
211212
apiGroupField?: string | null;
212213
outputItemTemplate?: string | null;
@@ -223,8 +224,12 @@ export interface IComboBox {
223224
options?: IComboBoxOptions;
224225
open(): void;
225226
close(): void;
227+
selectedItem(): HTMLElement | null;
228+
selectedValue(): string | null;
229+
selectedAttr(attr: string): string | null;
226230
recalculateDirection(): void;
227231
}
232+
export type QueryTransformer = (query: string) => string;
228233
export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComboBox {
229234
gap: number;
230235
viewport: string | HTMLElement | null;
@@ -233,6 +238,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
233238
apiDataPart: string | null;
234239
apiQuery: string | null;
235240
apiSearchQuery: string | null;
241+
apiSearchQueryTransformer: ((query: string) => string) | null;
236242
apiHeaders: {};
237243
apiGroupField: string | null;
238244
outputItemTemplate: string | null;
@@ -248,6 +254,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
248254
private readonly output;
249255
private readonly itemsWrapper;
250256
private items;
257+
private selectedItemElement;
251258
private tabs;
252259
private readonly toggle;
253260
private readonly toggleClose;
@@ -262,6 +269,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
262269
isCurrent: boolean;
263270
private animationInProcess;
264271
constructor(el: HTMLElement, options?: IComboBoxOptions, events?: {});
272+
private parseApiQueryTransformer;
265273
private init;
266274
private build;
267275
private setResultAndRender;
@@ -297,9 +305,13 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
297305
private destroyOutputPlaceholder;
298306
private resultItems;
299307
private setValueAndOpen;
300-
open(val?: string): boolean;
301308
private setValueAndClear;
309+
open(val?: string): boolean;
302310
close(val?: string | null): boolean;
311+
setSearchQueryTransformer(transformer: (query: string) => string): void;
312+
selectedItem(): HTMLElement | null;
313+
selectedValue(): string | null;
314+
selectedAttr(attr: string): string | null;
303315
recalculateDirection(): void;
304316
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSComboBox | ICollectionItem<HSComboBox>;
305317
static autoInit(): void;

dist/preline.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export interface IComboBoxOptions {
207207
apiDataPart?: string | null;
208208
apiQuery?: string | null;
209209
apiSearchQuery?: string | null;
210+
apiSearchQueryTransformer?: QueryTransformer | string | null;
210211
apiHeaders?: {};
211212
apiGroupField?: string | null;
212213
outputItemTemplate?: string | null;
@@ -223,8 +224,12 @@ export interface IComboBox {
223224
options?: IComboBoxOptions;
224225
open(): void;
225226
close(): void;
227+
selectedItem(): HTMLElement | null;
228+
selectedValue(): string | null;
229+
selectedAttr(attr: string): string | null;
226230
recalculateDirection(): void;
227231
}
232+
export type QueryTransformer = (query: string) => string;
228233
export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComboBox {
229234
gap: number;
230235
viewport: string | HTMLElement | null;
@@ -233,6 +238,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
233238
apiDataPart: string | null;
234239
apiQuery: string | null;
235240
apiSearchQuery: string | null;
241+
apiSearchQueryTransformer: ((query: string) => string) | null;
236242
apiHeaders: {};
237243
apiGroupField: string | null;
238244
outputItemTemplate: string | null;
@@ -248,6 +254,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
248254
private readonly output;
249255
private readonly itemsWrapper;
250256
private items;
257+
private selectedItemElement;
251258
private tabs;
252259
private readonly toggle;
253260
private readonly toggleClose;
@@ -262,6 +269,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
262269
isCurrent: boolean;
263270
private animationInProcess;
264271
constructor(el: HTMLElement, options?: IComboBoxOptions, events?: {});
272+
private parseApiQueryTransformer;
265273
private init;
266274
private build;
267275
private setResultAndRender;
@@ -297,9 +305,13 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
297305
private destroyOutputPlaceholder;
298306
private resultItems;
299307
private setValueAndOpen;
300-
open(val?: string): boolean;
301308
private setValueAndClear;
309+
open(val?: string): boolean;
302310
close(val?: string | null): boolean;
311+
setSearchQueryTransformer(transformer: (query: string) => string): void;
312+
selectedItem(): HTMLElement | null;
313+
selectedValue(): string | null;
314+
selectedAttr(attr: string): string | null;
303315
recalculateDirection(): void;
304316
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSComboBox | ICollectionItem<HSComboBox>;
305317
static autoInit(): void;

dts-config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ const config = {
1717
outFile: './dist/index.d.ts',
1818
output: outputConfig,
1919
},
20+
{
21+
filePath: './src/index.ts',
22+
outFile: './dist/preline.d.ts',
23+
output: outputConfig,
24+
},
25+
{
26+
filePath: './src/index.ts',
27+
outFile: './preline.d.ts',
28+
output: outputConfig,
29+
},
30+
{
31+
filePath: './src/index.ts',
32+
outFile: './index.d.ts',
33+
output: outputConfig,
34+
},
2035
...fs
2136
.readdirSync(pluginsDir)
2237
.map((pluginName) => writeFile(pluginsDir, pluginName))

index.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export interface IComboBoxOptions {
207207
apiDataPart?: string | null;
208208
apiQuery?: string | null;
209209
apiSearchQuery?: string | null;
210+
apiSearchQueryTransformer?: QueryTransformer | string | null;
210211
apiHeaders?: {};
211212
apiGroupField?: string | null;
212213
outputItemTemplate?: string | null;
@@ -223,8 +224,12 @@ export interface IComboBox {
223224
options?: IComboBoxOptions;
224225
open(): void;
225226
close(): void;
227+
selectedItem(): HTMLElement | null;
228+
selectedValue(): string | null;
229+
selectedAttr(attr: string): string | null;
226230
recalculateDirection(): void;
227231
}
232+
export type QueryTransformer = (query: string) => string;
228233
export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implements IComboBox {
229234
gap: number;
230235
viewport: string | HTMLElement | null;
@@ -233,6 +238,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
233238
apiDataPart: string | null;
234239
apiQuery: string | null;
235240
apiSearchQuery: string | null;
241+
apiSearchQueryTransformer: ((query: string) => string) | null;
236242
apiHeaders: {};
237243
apiGroupField: string | null;
238244
outputItemTemplate: string | null;
@@ -248,6 +254,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
248254
private readonly output;
249255
private readonly itemsWrapper;
250256
private items;
257+
private selectedItemElement;
251258
private tabs;
252259
private readonly toggle;
253260
private readonly toggleClose;
@@ -262,6 +269,7 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
262269
isCurrent: boolean;
263270
private animationInProcess;
264271
constructor(el: HTMLElement, options?: IComboBoxOptions, events?: {});
272+
private parseApiQueryTransformer;
265273
private init;
266274
private build;
267275
private setResultAndRender;
@@ -297,9 +305,13 @@ export declare class HSComboBox extends HSBasePlugin<IComboBoxOptions> implement
297305
private destroyOutputPlaceholder;
298306
private resultItems;
299307
private setValueAndOpen;
300-
open(val?: string): boolean;
301308
private setValueAndClear;
309+
open(val?: string): boolean;
302310
close(val?: string | null): boolean;
311+
setSearchQueryTransformer(transformer: (query: string) => string): void;
312+
selectedItem(): HTMLElement | null;
313+
selectedValue(): string | null;
314+
selectedAttr(attr: string): string | null;
303315
recalculateDirection(): void;
304316
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSComboBox | ICollectionItem<HSComboBox>;
305317
static autoInit(): void;

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,41 @@
4040
"access": "public"
4141
},
4242
"scripts": {
43+
"watch:all": "concurrently \"pnpm run watch\" \"pnpm run watch:dts\" \"pnpm run watch:mjs\" \"pnpm run copyjs:watch\"",
44+
"copyjs": "cp dist/index.js dist/preline.js && cp dist/index.js preline.js && cp dist/index.js index.js",
45+
"copyjs:watch": "pnpm exec chokidar './dist/index.js' -c 'pnpm run copyjs'",
4346
"watch": "webpack --config webpack.config.js --watch",
4447
"watch:mjs": "webpack --config webpack.config.mjs.js --watch",
48+
"watch:dts": "pnpm exec chokidar './src/**/*.ts' -c 'pnpm run generate-dts'",
4549
"build": "webpack --config webpack.config.js",
4650
"build:mjs": "webpack --config webpack.config.mjs.js",
4751
"pretty": "prettier --write \"./**/*.{js,jsx,ts,tsx,json}\"",
4852
"generate-dts": "dts-bundle-generator --config dts-config.js"
4953
},
54+
"dependencies": {
55+
"@popperjs/core": "^2.11.8"
56+
},
5057
"devDependencies": {
51-
"@types/clipboard": "^2.0.7",
52-
"@types/datatables.net": "^1.12.0",
5358
"@types/dropzone": "^5.7.8",
5459
"@types/jquery": "^3.5.30",
5560
"@types/lodash": "^4.17.6",
56-
"@types/nouislider": "^15.0.0",
5761
"@types/prismjs": "^1.26.4",
5862
"@types/vinyl": "^2.0.12",
63+
"apexcharts": "^3.54.0",
64+
"chokidar-cli": "^3.0.0",
65+
"clipboard": "^2.0.11",
66+
"concurrently": "^9.0.1",
67+
"datatables.net": "^2.1.8",
68+
"datatables.net-dt": "^2.1.8",
69+
"dropzone": "6.0.0-beta.2",
5970
"dts-bundle-generator": "^9.0.0",
71+
"nouislider": "^15.8.1",
6072
"prettier": "^3.0.0",
6173
"source-map-loader": "^4.0.1",
74+
"tailwindcss": "^3.4.13",
6275
"terser-webpack-plugin": "^5.3.9",
6376
"ts-loader": "^9.5.1",
6477
"typescript": "^5.5.3",
6578
"webpack-cli": "^5.0.1"
66-
},
67-
"dependencies": {
68-
"@popperjs/core": "^2.11.2"
6979
}
7080
}

0 commit comments

Comments
 (0)