@likable-hair/svelte 3.0.19 → 3.0.21
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/components/composed/common/MenuOrDrawer.svelte +3 -2
- package/dist/components/composed/common/MenuOrDrawer.svelte.d.ts +2 -1
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte +2 -2
- package/dist/components/composed/common/MenuOrDrawerOptions.svelte.d.ts +1 -1
- package/dist/components/composed/forms/Dropdown.svelte +19 -8
- package/dist/components/composed/forms/Dropdown.svelte.d.ts +7 -0
- package/dist/components/composed/list/PaginatedTable.svelte +179 -129
- package/dist/components/composed/list/PaginatedTable.svelte.d.ts +71 -2
- package/dist/components/composed/list/Paginator.svelte +12 -6
- package/dist/components/composed/search/FilterEditor.svelte +260 -0
- package/dist/components/composed/search/FilterEditor.svelte.d.ts +29 -0
- package/dist/components/composed/search/Filters.css +0 -0
- package/dist/components/composed/search/Filters.svelte +500 -0
- package/dist/components/composed/search/Filters.svelte.d.ts +46 -0
- package/dist/components/composed/search/MobileFilterEditor.svelte +342 -0
- package/dist/components/composed/search/MobileFilterEditor.svelte.d.ts +34 -0
- package/dist/components/composed/search/SearchBar.svelte +12 -11
- package/dist/components/composed/search/SearchBar.svelte.d.ts +1 -0
- package/dist/components/simple/buttons/Button.css +1 -0
- package/dist/components/simple/buttons/Button.svelte +8 -0
- package/dist/components/simple/common/Menu.svelte +29 -10
- package/dist/components/simple/common/Menu.svelte.d.ts +2 -0
- package/dist/components/simple/dates/DatePickerTextField.svelte +91 -61
- package/dist/components/simple/dates/DatePickerTextField.svelte.d.ts +2 -0
- package/dist/components/simple/dialogs/Dialog.svelte.d.ts +1 -1
- package/dist/components/simple/forms/Autocomplete.css +1 -0
- package/dist/components/simple/forms/Autocomplete.svelte +100 -46
- package/dist/components/simple/forms/Autocomplete.svelte.d.ts +4 -0
- package/dist/components/simple/lists/SelectableVerticalList.svelte +52 -9
- package/dist/components/simple/lists/SelectableVerticalList.svelte.d.ts +9 -0
- package/dist/components/simple/lists/SimpleTable.svelte +25 -23
- package/dist/components/simple/lists/SimpleTable.svelte.d.ts +3 -1
- package/dist/components/simple/lists/columnTypes.d.ts +35 -0
- package/dist/components/simple/lists/columnTypes.js +1 -0
- package/dist/components/simple/media/DescriptiveAvatar.svelte.d.ts +1 -1
- package/dist/components/simple/navigation/Chip.css +2 -1
- package/dist/components/simple/navigation/Chip.svelte +16 -5
- package/dist/components/simple/navigation/Chip.svelte.d.ts +1 -0
- package/dist/components/simple/navigation/Drawer.svelte +10 -0
- package/dist/components/simple/navigation/Drawer.svelte.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/filters/builder.d.ts +43 -0
- package/dist/utils/filters/builder.js +137 -0
- package/dist/utils/filters/filters.d.ts +89 -0
- package/dist/utils/filters/filters.js +102 -0
- package/dist/utils/filters/modifiers/join.d.ts +26 -0
- package/dist/utils/filters/modifiers/join.js +1 -0
- package/dist/utils/filters/modifiers/where.d.ts +29 -0
- package/dist/utils/filters/modifiers/where.js +1 -0
- package/dist/utils/filters/validator.d.ts +4 -0
- package/dist/utils/filters/validator.js +30 -0
- package/package.json +2 -1
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import "../../../css/main.css";
|
|
4
4
|
import "./SimpleTable.css";
|
|
5
|
-
import { dateToString } from "../dates/utils";
|
|
6
5
|
import Icon from "../media/Icon.svelte";
|
|
7
6
|
import { createEventDispatcher } from "svelte";
|
|
8
7
|
let clazz = {};
|
|
@@ -25,6 +24,9 @@ function handleHeaderClick(header) {
|
|
|
25
24
|
sortDirection
|
|
26
25
|
});
|
|
27
26
|
}
|
|
27
|
+
function formatDate(dateTime, dateFormat) {
|
|
28
|
+
return dateTime.setLocale(dateFormat.locale).toFormat(dateFormat.format);
|
|
29
|
+
}
|
|
28
30
|
</script>
|
|
29
31
|
|
|
30
32
|
{#if !!items && Array.isArray(items)}
|
|
@@ -33,8 +35,8 @@ function handleHeaderClick(header) {
|
|
|
33
35
|
<thead class="thead {clazz.header || ''}">
|
|
34
36
|
<tr>
|
|
35
37
|
{#each headers as head}
|
|
36
|
-
<th
|
|
37
|
-
style:width={head.width}
|
|
38
|
+
<th
|
|
39
|
+
style:width={head.width}
|
|
38
40
|
style:min-width={head.minWidth}
|
|
39
41
|
class:sortable={head.sortable}
|
|
40
42
|
on:click={() => handleHeaderClick(head)}
|
|
@@ -46,16 +48,16 @@ function handleHeaderClick(header) {
|
|
|
46
48
|
</slot>
|
|
47
49
|
</span>
|
|
48
50
|
{#if head.sortable}
|
|
49
|
-
<span
|
|
51
|
+
<span
|
|
50
52
|
class="header-sort-icon"
|
|
51
53
|
class:active={sortedBy == head.value}
|
|
52
|
-
class:asc={sortDirection ==
|
|
53
|
-
class:desc={sortDirection ==
|
|
54
|
+
class:asc={sortDirection == "asc"}
|
|
55
|
+
class:desc={sortDirection == "desc"}
|
|
54
56
|
>
|
|
55
|
-
{#if sortDirection ==
|
|
56
|
-
<Icon name="mdi-arrow-up"
|
|
57
|
+
{#if sortDirection == "asc"}
|
|
58
|
+
<Icon name="mdi-arrow-up" />
|
|
57
59
|
{:else}
|
|
58
|
-
<Icon name="mdi-arrow-down"
|
|
60
|
+
<Icon name="mdi-arrow-down" />
|
|
59
61
|
{/if}
|
|
60
62
|
</span>
|
|
61
63
|
{/if}
|
|
@@ -74,7 +76,7 @@ function handleHeaderClick(header) {
|
|
|
74
76
|
<tr class="item-tr {clazz.row || ''}">
|
|
75
77
|
{#each headers as header, j}
|
|
76
78
|
<td class="{clazz.cell || ''}">
|
|
77
|
-
{#if header.type == "custom"}
|
|
79
|
+
{#if header.type.key == "custom"}
|
|
78
80
|
<slot
|
|
79
81
|
name="custom"
|
|
80
82
|
index={i}
|
|
@@ -82,9 +84,15 @@ function handleHeaderClick(header) {
|
|
|
82
84
|
{header}
|
|
83
85
|
{item}
|
|
84
86
|
/>
|
|
85
|
-
{:else if
|
|
86
|
-
{
|
|
87
|
-
{:else}
|
|
87
|
+
{:else if header.type.key == "date"}
|
|
88
|
+
{formatDate(item[header.value], header.type.params)}
|
|
89
|
+
{:else if header.type.key == "icon"}
|
|
90
|
+
<Icon
|
|
91
|
+
--icon-color={header.type.params?.color }
|
|
92
|
+
--icon-size={header.type.params?.size}
|
|
93
|
+
name={header.type.params?.name || ''}
|
|
94
|
+
/>
|
|
95
|
+
{:else}
|
|
88
96
|
{item[header.value]}
|
|
89
97
|
{/if}
|
|
90
98
|
</td>
|
|
@@ -104,10 +112,7 @@ function handleHeaderClick(header) {
|
|
|
104
112
|
|
|
105
113
|
<style>
|
|
106
114
|
.simple-table-container {
|
|
107
|
-
width: var(
|
|
108
|
-
--simple-table-width,
|
|
109
|
-
var(--simple-table-default-width)
|
|
110
|
-
);
|
|
115
|
+
width: var(--simple-table-width, var(--simple-table-default-width));
|
|
111
116
|
min-width: var(
|
|
112
117
|
--simple-table-min-width,
|
|
113
118
|
var(--simple-table-default-min-width)
|
|
@@ -116,10 +121,7 @@ function handleHeaderClick(header) {
|
|
|
116
121
|
--simple-table-max-width,
|
|
117
122
|
var(--simple-table-default-max-width)
|
|
118
123
|
);
|
|
119
|
-
height: var(
|
|
120
|
-
--simple-table-height,
|
|
121
|
-
var(--simple-table-default-height)
|
|
122
|
-
);
|
|
124
|
+
height: var(--simple-table-height, var(--simple-table-default-height));
|
|
123
125
|
min-height: var(
|
|
124
126
|
--simple-table-min-height,
|
|
125
127
|
var(--simple-table-default-min-height)
|
|
@@ -158,7 +160,7 @@ function handleHeaderClick(header) {
|
|
|
158
160
|
|
|
159
161
|
.thead th.sortable {
|
|
160
162
|
cursor: pointer;
|
|
161
|
-
transition: all .1s ease-in;
|
|
163
|
+
transition: all 0.1s ease-in;
|
|
162
164
|
user-select: none;
|
|
163
165
|
}
|
|
164
166
|
|
|
@@ -221,7 +223,7 @@ function handleHeaderClick(header) {
|
|
|
221
223
|
--simple-table-row-height,
|
|
222
224
|
var(--simple-table-default-row-height)
|
|
223
225
|
);
|
|
224
|
-
transition: background-color .1s ease-in-out;
|
|
226
|
+
transition: background-color 0.1s ease-in-out;
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
.item-tr:hover {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
export type HeaderType = ColumnBoolean | ColumnString | ColumnNumber | ColumnDate | ColumnIcon | ColumnCheckBox | ColumnCustom;
|
|
2
3
|
export type Header = {
|
|
3
4
|
value: string;
|
|
4
5
|
label: string;
|
|
5
|
-
type:
|
|
6
|
+
type: HeaderType;
|
|
6
7
|
width?: string;
|
|
7
8
|
minWidth?: string;
|
|
8
9
|
sortable?: boolean;
|
|
@@ -12,6 +13,7 @@ export type Header = {
|
|
|
12
13
|
};
|
|
13
14
|
import '../../../css/main.css';
|
|
14
15
|
import './SimpleTable.css';
|
|
16
|
+
import type { ColumnBoolean, ColumnCheckBox, ColumnCustom, ColumnDate, ColumnIcon, ColumnNumber, ColumnString } from './columnTypes';
|
|
15
17
|
declare const __propDef: {
|
|
16
18
|
props: {
|
|
17
19
|
class?: {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type ColumnDate = {
|
|
2
|
+
key: "date";
|
|
3
|
+
params: {
|
|
4
|
+
format: string;
|
|
5
|
+
locale: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type ColumnIcon = {
|
|
9
|
+
key: "icon";
|
|
10
|
+
params: {
|
|
11
|
+
name: string;
|
|
12
|
+
color: string;
|
|
13
|
+
size: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type ColumnBoolean = {
|
|
17
|
+
key: "boolean";
|
|
18
|
+
params?: {};
|
|
19
|
+
};
|
|
20
|
+
export type ColumnString = {
|
|
21
|
+
key: "string";
|
|
22
|
+
params?: {};
|
|
23
|
+
};
|
|
24
|
+
export type ColumnNumber = {
|
|
25
|
+
key: "number";
|
|
26
|
+
params?: {};
|
|
27
|
+
};
|
|
28
|
+
export type ColumnCustom = {
|
|
29
|
+
key: "custom";
|
|
30
|
+
params?: {};
|
|
31
|
+
};
|
|
32
|
+
export type ColumnCheckBox = {
|
|
33
|
+
key: "checkbox";
|
|
34
|
+
params?: {};
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,7 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
src: string;
|
|
5
5
|
title?: string | undefined;
|
|
6
6
|
description?: string | undefined;
|
|
7
|
-
direction?: "
|
|
7
|
+
direction?: "column" | "row" | undefined;
|
|
8
8
|
reverse?: boolean | undefined;
|
|
9
9
|
avatarSpacing?: string | undefined;
|
|
10
10
|
width?: string | undefined;
|
|
@@ -10,5 +10,6 @@
|
|
|
10
10
|
--chip-default-font-size: inherit;
|
|
11
11
|
--chip-default-line-height: inherit;
|
|
12
12
|
--chip-default-cursor: pointer;
|
|
13
|
-
--chip-default-hover-background-color: rgb(var(--global-color-primary-600))
|
|
13
|
+
--chip-default-hover-background-color: rgb(var(--global-color-primary-600));
|
|
14
|
+
--chip-default-text-max-width: 200px
|
|
14
15
|
}
|
|
@@ -3,12 +3,13 @@ import "./Chip.css";
|
|
|
3
3
|
import Icon from "../media/Icon.svelte";
|
|
4
4
|
import Button from "../buttons/Button.svelte";
|
|
5
5
|
import { createEventDispatcher } from "svelte";
|
|
6
|
-
export let close = false, closeIcon = "mdi-close-circle", disabled = false, filter = false, filterIcon = "mdi-check", label = false, outlined = false, buttonTabIndex = null;
|
|
6
|
+
export let close = false, closeIcon = "mdi-close-circle", disabled = false, filter = false, filterIcon = "mdi-check", label = false, outlined = false, buttonTabIndex = null, truncateText = false;
|
|
7
7
|
const dispatch = createEventDispatcher();
|
|
8
8
|
function handleChipClick() {
|
|
9
9
|
dispatch("click");
|
|
10
10
|
}
|
|
11
|
-
function handleCloseClick() {
|
|
11
|
+
function handleCloseClick(e) {
|
|
12
|
+
e.detail.nativeEvent.stopPropagation();
|
|
12
13
|
dispatch("close");
|
|
13
14
|
}
|
|
14
15
|
</script>
|
|
@@ -26,8 +27,9 @@ function handleCloseClick() {
|
|
|
26
27
|
<Icon name={filterIcon} />
|
|
27
28
|
</div>
|
|
28
29
|
{/if}
|
|
29
|
-
<div
|
|
30
|
-
class="text"
|
|
30
|
+
<div
|
|
31
|
+
class="text"
|
|
32
|
+
class:truncate={truncateText}
|
|
31
33
|
>
|
|
32
34
|
<slot />
|
|
33
35
|
</div>
|
|
@@ -40,7 +42,8 @@ function handleCloseClick() {
|
|
|
40
42
|
--button-background-color="transparent"
|
|
41
43
|
--button-padding="0px"
|
|
42
44
|
--button-color="var(--chip-color, var(--chip-default-color))"
|
|
43
|
-
on:click
|
|
45
|
+
on:click
|
|
46
|
+
={handleCloseClick}
|
|
44
47
|
/>
|
|
45
48
|
</div>
|
|
46
49
|
{/if}
|
|
@@ -69,6 +72,14 @@ function handleCloseClick() {
|
|
|
69
72
|
);
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
.truncate {
|
|
76
|
+
max-width: var(--chip-text-max-width, var(--chip-default-text-max-width));
|
|
77
|
+
text-overflow: ellipsis;
|
|
78
|
+
white-space: nowrap;
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
72
83
|
.chip:not(.outlined) {
|
|
73
84
|
background-color: var(
|
|
74
85
|
--chip-background-color,
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
<script>import "../../../css/main.css";
|
|
2
2
|
import "./Drawer.css";
|
|
3
3
|
import Navigator from "./Navigator.svelte";
|
|
4
|
+
import { createEventDispatcher } from "svelte";
|
|
4
5
|
export let open = false, position = "left", overlay = true, items = [];
|
|
6
|
+
const dispatch = createEventDispatcher();
|
|
5
7
|
function handleClickOverlay() {
|
|
6
8
|
open = false;
|
|
9
|
+
overlay = false;
|
|
10
|
+
dispatch("close");
|
|
7
11
|
}
|
|
12
|
+
$:
|
|
13
|
+
if (open) {
|
|
14
|
+
overlay = true;
|
|
15
|
+
}
|
|
8
16
|
</script>
|
|
9
17
|
|
|
10
18
|
<div
|
|
@@ -75,6 +83,8 @@ function handleClickOverlay() {
|
|
|
75
83
|
);
|
|
76
84
|
color: var(--drawer-color, var(--drawer-default-color));
|
|
77
85
|
overflow: var(--drawer-overflow, var(--drawer-default-overflow));
|
|
86
|
+
border-radius: var(--drawer-border-radius);
|
|
87
|
+
margin: var(--drawer-margin);
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
.overlay {
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export { default as ProgressBar } from './components/simple/progress/ProgressBar
|
|
|
46
46
|
export { default as ProductCard } from './components/composed/shop/ProductCard.svelte';
|
|
47
47
|
export { default as ProductsGrid } from './components/composed/shop/ProductsGrid.svelte';
|
|
48
48
|
export { default as PaginatedTable } from './components/composed/list/PaginatedTable.svelte';
|
|
49
|
+
export { default as Filters } from './components/composed/search/Filters.svelte';
|
|
49
50
|
export { default as mediaQuery } from './stores/mediaQuery';
|
|
50
51
|
export { default as theme, toggleTheme, setTheme } from './stores/theme';
|
|
51
52
|
export { default as SimpleTimeLine } from './components/simple/timeline/SimpleTimeLine.svelte';
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ export { default as ProgressBar } from './components/simple/progress/ProgressBar
|
|
|
46
46
|
export { default as ProductCard } from './components/composed/shop/ProductCard.svelte';
|
|
47
47
|
export { default as ProductsGrid } from './components/composed/shop/ProductsGrid.svelte';
|
|
48
48
|
export { default as PaginatedTable } from './components/composed/list/PaginatedTable.svelte';
|
|
49
|
+
export { default as Filters } from './components/composed/search/Filters.svelte';
|
|
49
50
|
export { default as mediaQuery } from './stores/mediaQuery';
|
|
50
51
|
export { default as theme, toggleTheme, setTheme } from './stores/theme';
|
|
51
52
|
export { default as SimpleTimeLine } from './components/simple/timeline/SimpleTimeLine.svelte';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { JoinModifier } from "./modifiers/join";
|
|
2
|
+
import type { WhereModifier } from "./modifiers/where";
|
|
3
|
+
export type Modifier = WhereModifier | JoinModifier;
|
|
4
|
+
export type JsonQuery = {
|
|
5
|
+
modifiers: Modifier[];
|
|
6
|
+
};
|
|
7
|
+
export default class Builder {
|
|
8
|
+
private modifiers;
|
|
9
|
+
constructor();
|
|
10
|
+
where(callback: (builder: Builder) => void): Builder;
|
|
11
|
+
where(key: Record<string, string | number | Date>): Builder;
|
|
12
|
+
where(key: string, value: string | number | Date): Builder;
|
|
13
|
+
where(key: string, operator: string, value: string | number | Date | boolean): Builder;
|
|
14
|
+
whereNot(callback: (builder: Builder) => void): Builder;
|
|
15
|
+
whereNot(key: Record<string, string | number | Date>): Builder;
|
|
16
|
+
whereNot(key: string, value: string | number | Date): Builder;
|
|
17
|
+
whereNot(key: string, operator: string, value: string | number | Date): Builder;
|
|
18
|
+
orWhere(callback: (builder: Builder) => void): Builder;
|
|
19
|
+
orWhere(key: Record<string, string | number | Date>): Builder;
|
|
20
|
+
orWhere(key: string, value: string | number | Date): Builder;
|
|
21
|
+
orWhere(key: string, operator: string, value: string | number | Date): Builder;
|
|
22
|
+
orWhereNot(callback: (builder: Builder) => void): Builder;
|
|
23
|
+
orWhereNot(key: Record<string, string | number | Date>): Builder;
|
|
24
|
+
orWhereNot(key: string, value: string | number | Date): Builder;
|
|
25
|
+
orWhereNot(key: string, operator: string, value: string | number | Date): Builder;
|
|
26
|
+
private applyWhereClause;
|
|
27
|
+
join(table: string, onCallback: (onBuilder: OnClauseBuilder) => void): this;
|
|
28
|
+
leftJoin(table: string, onCallback: (onBuilder: OnClauseBuilder) => void): this;
|
|
29
|
+
rightJoin(table: string, onCallback: (onBuilder: OnClauseBuilder) => void): this;
|
|
30
|
+
private applyJoinClause;
|
|
31
|
+
toJson(): JsonQuery;
|
|
32
|
+
}
|
|
33
|
+
import type { JoinModifierOnClause } from "./modifiers/join";
|
|
34
|
+
declare class OnClauseBuilder {
|
|
35
|
+
private onClauses;
|
|
36
|
+
constructor();
|
|
37
|
+
get json(): JoinModifierOnClause[];
|
|
38
|
+
on(from: string, to: string): void;
|
|
39
|
+
on(from: string, operator: string, to: string): void;
|
|
40
|
+
orOn(from: string, to: string): void;
|
|
41
|
+
orOn(from: string, operator: string, to: string): void;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export default class Builder {
|
|
2
|
+
modifiers = [];
|
|
3
|
+
constructor() {
|
|
4
|
+
this.modifiers = [];
|
|
5
|
+
}
|
|
6
|
+
where(first, second, third) {
|
|
7
|
+
return this.applyWhereClause('and', first, second, third);
|
|
8
|
+
}
|
|
9
|
+
whereNot(first, second, third) {
|
|
10
|
+
return this.applyWhereClause('andNot', first, second, third);
|
|
11
|
+
}
|
|
12
|
+
orWhere(first, second, third) {
|
|
13
|
+
return this.applyWhereClause('or', first, second, third);
|
|
14
|
+
}
|
|
15
|
+
orWhereNot(first, second, third) {
|
|
16
|
+
return this.applyWhereClause('orNot', first, second, third);
|
|
17
|
+
}
|
|
18
|
+
applyWhereClause(logicalOperator, first, second, third) {
|
|
19
|
+
if (!!third) {
|
|
20
|
+
if (!!second && typeof first == 'string' && typeof second == 'string') {
|
|
21
|
+
this.modifiers.push({
|
|
22
|
+
method: 'where',
|
|
23
|
+
kind: 'simple',
|
|
24
|
+
key: first,
|
|
25
|
+
operator: second,
|
|
26
|
+
value: third,
|
|
27
|
+
logicalOperator: logicalOperator
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (typeof first == 'object') {
|
|
31
|
+
this.modifiers.push({
|
|
32
|
+
method: 'where',
|
|
33
|
+
kind: 'object',
|
|
34
|
+
values: first,
|
|
35
|
+
logicalOperator
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (typeof first == 'string' && !!second) {
|
|
40
|
+
this.modifiers.push({
|
|
41
|
+
method: 'where',
|
|
42
|
+
kind: 'simple',
|
|
43
|
+
key: first,
|
|
44
|
+
value: second,
|
|
45
|
+
logicalOperator
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else if (typeof first == 'function') {
|
|
49
|
+
let builder = new Builder();
|
|
50
|
+
first(builder);
|
|
51
|
+
if (!builder.modifiers.every(el => el.method == 'where'))
|
|
52
|
+
throw new Error('inconsistent json query from where callback');
|
|
53
|
+
this.modifiers.push({
|
|
54
|
+
method: 'where',
|
|
55
|
+
kind: 'grouped',
|
|
56
|
+
logicalOperator,
|
|
57
|
+
children: builder.modifiers.filter((el) => el.method == 'where')
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
join(table, onCallback) {
|
|
63
|
+
let onBuilder = new OnClauseBuilder();
|
|
64
|
+
onCallback(onBuilder);
|
|
65
|
+
this.applyJoinClause('inner', table, onBuilder.json);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
leftJoin(table, onCallback) {
|
|
69
|
+
let onBuilder = new OnClauseBuilder();
|
|
70
|
+
onCallback(onBuilder);
|
|
71
|
+
this.applyJoinClause('left', table, onBuilder.json);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
rightJoin(table, onCallback) {
|
|
75
|
+
let onBuilder = new OnClauseBuilder();
|
|
76
|
+
onCallback(onBuilder);
|
|
77
|
+
this.applyJoinClause('right', table, onBuilder.json);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
applyJoinClause(kind, table, on) {
|
|
81
|
+
this.modifiers.push({
|
|
82
|
+
method: 'join',
|
|
83
|
+
kind: kind,
|
|
84
|
+
on: on,
|
|
85
|
+
table: table
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
toJson() {
|
|
90
|
+
return {
|
|
91
|
+
modifiers: this.modifiers
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class OnClauseBuilder {
|
|
96
|
+
onClauses;
|
|
97
|
+
constructor() {
|
|
98
|
+
this.onClauses = [];
|
|
99
|
+
}
|
|
100
|
+
get json() {
|
|
101
|
+
return this.onClauses;
|
|
102
|
+
}
|
|
103
|
+
on(first, second, third) {
|
|
104
|
+
if (!third) {
|
|
105
|
+
this.onClauses.push({
|
|
106
|
+
from: first,
|
|
107
|
+
operator: '=',
|
|
108
|
+
to: second
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.onClauses.push({
|
|
113
|
+
from: first,
|
|
114
|
+
operator: second,
|
|
115
|
+
to: third
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
orOn(first, second, third) {
|
|
120
|
+
if (!third) {
|
|
121
|
+
this.onClauses.push({
|
|
122
|
+
from: first,
|
|
123
|
+
operator: '=',
|
|
124
|
+
to: second,
|
|
125
|
+
logicalOperator: 'or'
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.onClauses.push({
|
|
130
|
+
from: first,
|
|
131
|
+
operator: second,
|
|
132
|
+
to: third,
|
|
133
|
+
logicalOperator: 'or'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Builder from "./builder";
|
|
2
|
+
export declare const StringModes: readonly ["equal", "like", "ilike"];
|
|
3
|
+
export type StringMode = typeof StringModes[number];
|
|
4
|
+
export declare const GenericModes: readonly ["equal", "greater", "lower", "between"];
|
|
5
|
+
export type DateMode = typeof GenericModes[number];
|
|
6
|
+
export type NumberMode = typeof GenericModes[number];
|
|
7
|
+
export declare const SelectModes: readonly ["equal", "different"];
|
|
8
|
+
export type SelectMode = typeof SelectModes[number];
|
|
9
|
+
type MultiStringFilter = {
|
|
10
|
+
type: 'multiString';
|
|
11
|
+
columns: string[];
|
|
12
|
+
operator?: 'or' | 'and';
|
|
13
|
+
value?: string;
|
|
14
|
+
};
|
|
15
|
+
type ChoiceFilter = {
|
|
16
|
+
type: 'choice';
|
|
17
|
+
column: string;
|
|
18
|
+
value?: string;
|
|
19
|
+
operator?: 'or' | 'and';
|
|
20
|
+
options: any[];
|
|
21
|
+
};
|
|
22
|
+
type StringFilter = {
|
|
23
|
+
type: 'string';
|
|
24
|
+
column: string;
|
|
25
|
+
value?: string;
|
|
26
|
+
mode?: StringMode;
|
|
27
|
+
};
|
|
28
|
+
type DateFilter = {
|
|
29
|
+
type: 'date';
|
|
30
|
+
column: string;
|
|
31
|
+
} & ({
|
|
32
|
+
mode: 'between';
|
|
33
|
+
from?: Date;
|
|
34
|
+
to?: Date;
|
|
35
|
+
} | {
|
|
36
|
+
mode: 'equal' | 'greater' | 'lower';
|
|
37
|
+
value?: Date;
|
|
38
|
+
});
|
|
39
|
+
type NumberFilter = {
|
|
40
|
+
type: 'number';
|
|
41
|
+
column: string;
|
|
42
|
+
} & ({
|
|
43
|
+
mode: 'between';
|
|
44
|
+
from?: number;
|
|
45
|
+
to?: number;
|
|
46
|
+
} | {
|
|
47
|
+
mode: 'equal' | 'greater' | 'lower';
|
|
48
|
+
value?: number;
|
|
49
|
+
});
|
|
50
|
+
type SelectFilter = {
|
|
51
|
+
type: 'select';
|
|
52
|
+
column: string;
|
|
53
|
+
mode: SelectMode;
|
|
54
|
+
items: {
|
|
55
|
+
value: string | number;
|
|
56
|
+
label: string;
|
|
57
|
+
}[];
|
|
58
|
+
values?: {
|
|
59
|
+
value: string | number;
|
|
60
|
+
label?: string | number;
|
|
61
|
+
}[];
|
|
62
|
+
};
|
|
63
|
+
type BoolFilter = {
|
|
64
|
+
type: 'bool';
|
|
65
|
+
column: string;
|
|
66
|
+
mode: 'equal';
|
|
67
|
+
value?: boolean;
|
|
68
|
+
advanced?: false;
|
|
69
|
+
desctiprion: string;
|
|
70
|
+
};
|
|
71
|
+
export type Filter = {
|
|
72
|
+
name: string;
|
|
73
|
+
active?: boolean;
|
|
74
|
+
hidden?: boolean;
|
|
75
|
+
label: string;
|
|
76
|
+
advanced?: boolean;
|
|
77
|
+
} & (StringFilter | MultiStringFilter | ChoiceFilter | DateFilter | NumberFilter | SelectFilter | BoolFilter);
|
|
78
|
+
export default class Converter {
|
|
79
|
+
constructor();
|
|
80
|
+
createBuilder(params: {
|
|
81
|
+
filters: Filter[];
|
|
82
|
+
}): Builder;
|
|
83
|
+
private applyStringFilter;
|
|
84
|
+
private applyDateFilter;
|
|
85
|
+
private applyNumberFilter;
|
|
86
|
+
private applySelectFilter;
|
|
87
|
+
private applyBooleanFilter;
|
|
88
|
+
}
|
|
89
|
+
export {};
|