Skip to content

Commit 02d6e3d

Browse files
committed
2.0.5
1 parent 328822b commit 02d6e3d

File tree

9 files changed

+103
-47
lines changed

9 files changed

+103
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Changelog
2+
- 2.0.5
3+
- Fixed TS types. Updated sandbox to TS
24
- 2.0.4
35
- Fixed import
46
- 2.0.2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-awesome-query-builder",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "User-friendly query builder for React. Demo: https://ukrbublik.github.io/react-awesome-query-builder",
55
"keywords": [
66
"reactjs",

sandbox/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
"author": "Denis Oblogin <ukrbublik@gmail.com> (https://github.com/ukrbublik)",
1818
"homepage": "https://ukrbublik.github.io/react-awesome-query-builder/",
1919
"dependencies": {
20+
"@types/node": "^13.13.4",
21+
"@types/react": "^16.9.34",
22+
"@types/react-dom": "^16.9.7",
23+
"antd": "^4.1.2",
2024
"react": "^16.4.1",
25+
"react-awesome-query-builder": "^2.0.5",
2126
"react-dom": "^16.4.1",
22-
"react-awesome-query-builder": "^2.0.3",
2327
"react-scripts": "3.0.1",
24-
"antd": "^4.1.2"
28+
"typescript": "^3.8.3"
2529
},
2630
"browserslist": {
2731
"production": [

sandbox/src/demo/config.jsx renamed to sandbox/src/demo/config.tsx

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from 'react';
22
import merge from 'lodash/merge';
3-
import { Widgets, Operators, BasicConfig } from 'react-awesome-query-builder';
3+
import {
4+
BasicConfig,
5+
// types:
6+
Operators, Widgets, Fields, Config, Types, Conjunctions, Settings, LocaleSettings, OperatorProximity, Funcs,
7+
} from 'react-awesome-query-builder';
48
import en_US from 'antd/lib/locale-provider/en_US';
59
import ru_RU from 'antd/lib/locale-provider/ru_RU';
610
import AntdConfig from 'react-awesome-query-builder/lib/config/antd';
@@ -14,11 +18,36 @@ const {
1418
const InitialConfig = AntdConfig; // BasicConfig
1519

1620

17-
const conjunctions = {
21+
const conjunctions: Conjunctions = {
1822
...InitialConfig.conjunctions
1923
};
2024

21-
const operators = {
25+
26+
const proximity: OperatorProximity = {
27+
...InitialConfig.operators.proximity,
28+
valueLabels: [
29+
{ label: 'Word 1', placeholder: 'Enter first word' },
30+
{ label: 'Word 2', placeholder: 'Enter second word' },
31+
],
32+
textSeparators: [
33+
//'Word 1',
34+
//'Word 2'
35+
],
36+
options: {
37+
...InitialConfig.operators.proximity.options,
38+
optionLabel: "Near", // label on top of "near" selectbox (for config.settings.showLabels==true)
39+
optionTextBefore: "Near", // label before "near" selectbox (for config.settings.showLabels==false)
40+
optionPlaceholder: "Select words between", // placeholder for "near" selectbox
41+
minProximity: 2,
42+
maxProximity: 10,
43+
defaults: {
44+
proximity: 2
45+
},
46+
customProps: {}
47+
}
48+
};
49+
50+
const operators: Operators = {
2251
...InitialConfig.operators,
2352
// examples of overriding
2453
between: {
@@ -32,32 +61,10 @@ const operators = {
3261
'to'
3362
],
3463
},
35-
proximity: {
36-
...InitialConfig.operators.proximity,
37-
valueLabels: [
38-
{ label: 'Word 1', placeholder: 'Enter first word' },
39-
{ label: 'Word 2', placeholder: 'Enter second word' },
40-
],
41-
textSeparators: [
42-
//'Word 1',
43-
//'Word 2'
44-
],
45-
options: {
46-
...InitialConfig.operators.proximity.options,
47-
optionLabel: "Near", // label on top of "near" selectbox (for config.settings.showLabels==true)
48-
optionTextBefore: "Near", // label before "near" selectbox (for config.settings.showLabels==false)
49-
optionPlaceholder: "Select words between", // placeholder for "near" selectbox
50-
minProximity: 2,
51-
maxProximity: 10,
52-
defaults: {
53-
proximity: 2
54-
},
55-
customProps: {}
56-
}
57-
},
64+
proximity,
5865
};
5966

60-
const widgets = {
67+
const widgets: Widgets = {
6168
...InitialConfig.widgets,
6269
// examples of overriding
6370
text: {
@@ -109,7 +116,7 @@ const widgets = {
109116
};
110117

111118

112-
const types = {
119+
const types: Types = {
113120
...InitialConfig.types,
114121
// examples of overriding
115122
boolean: merge(InitialConfig.types.boolean, {
@@ -125,7 +132,7 @@ const types = {
125132
};
126133

127134

128-
const localeSettings = {
135+
const localeSettings: LocaleSettings = {
129136
locale: {
130137
short: 'ru',
131138
full: 'ru-RU',
@@ -155,7 +162,7 @@ const localeSettings = {
155162
},
156163
};
157164

158-
const settings = {
165+
const settings: Settings = {
159166
...InitialConfig.settings,
160167
...localeSettings,
161168

@@ -186,7 +193,7 @@ const settings = {
186193

187194
//////////////////////////////////////////////////////////////////////
188195

189-
const fields = {
196+
const fields: Fields = {
190197
user: {
191198
label: 'User',
192199
tooltip: 'Group of fields',
@@ -383,7 +390,7 @@ const fields = {
383390

384391
//////////////////////////////////////////////////////////////////////
385392

386-
const funcs = {
393+
const funcs: Funcs = {
387394
LOWER: {
388395
label: 'Lowercase',
389396
mongoFunc: '$toLower',
@@ -428,14 +435,15 @@ const funcs = {
428435
},
429436
};
430437

431-
432-
export default {
438+
const config: Config = {
433439
conjunctions,
434440
operators,
435441
widgets,
436442
types,
437443
settings,
438444
fields,
439-
funcs,
445+
funcs
440446
};
441447

448+
export default config;
449+

sandbox/src/demo/demo.jsx renamed to sandbox/src/demo/demo.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, {Component} from 'react';
2-
import {Query, Builder, BasicConfig, Utils} from 'react-awesome-query-builder';
2+
import {
3+
Query, Builder, Utils,
4+
//types:
5+
ImmutableTree, Config, BuilderProps, JsonTree, JsonLogicTree
6+
} from 'react-awesome-query-builder';
37
import throttle from 'lodash/throttle';
48
import loadedConfig from './config';
59
import loadedInitValue from './init_value';
@@ -10,15 +14,23 @@ const {queryBuilderFormat, jsonLogicFormat, queryString, mongodbFormat, sqlForma
1014
const preStyle = { backgroundColor: 'darkgrey', margin: '10px', padding: '10px' };
1115
const preErrorStyle = { backgroundColor: 'lightpink', margin: '10px', padding: '10px' };
1216

13-
const emptyInitValue = {"id": uuid(), "type": "group"};
14-
const initValue = loadedInitValue && Object.keys(loadedInitValue).length > 0 ? loadedInitValue : emptyInitValue;
15-
const initLogic = loadedInitLogic && Object.keys(loadedInitLogic).length > 0 ? loadedInitLogic : undefined;
16-
let initTree;
17+
const emptyInitValue: JsonTree = {"id": uuid(), "type": "group"};
18+
const initValue: JsonTree = loadedInitValue && Object.keys(loadedInitValue).length > 0 ? loadedInitValue as JsonTree : emptyInitValue;
19+
const initLogic: JsonLogicTree = loadedInitLogic && Object.keys(loadedInitLogic).length > 0 ? loadedInitLogic : undefined;
20+
let initTree: ImmutableTree;
1721
initTree = checkTree(loadTree(initValue), loadedConfig);
1822
//initTree = checkTree(loadFromJsonLogic(initLogic, loadedConfig), loadedConfig); // <- this will work same
1923

2024

21-
export default class DemoQueryBuilder extends Component {
25+
interface DemoQueryBuilderState {
26+
tree: ImmutableTree;
27+
config: Config;
28+
}
29+
30+
export default class DemoQueryBuilder extends Component<{}, DemoQueryBuilderState> {
31+
private immutableTree: ImmutableTree;
32+
private config: Config;
33+
2234
state = {
2335
tree: initTree,
2436
config: loadedConfig
@@ -54,15 +66,15 @@ export default class DemoQueryBuilder extends Component {
5466
});
5567
};
5668

57-
renderBuilder = (props) => (
69+
renderBuilder = (props: BuilderProps) => (
5870
<div className="query-builder-container" style={{padding: '10px'}}>
5971
<div className="query-builder qb-lite">
6072
<Builder {...props} />
6173
</div>
6274
</div>
6375
)
6476

65-
onChange = (immutableTree, config) => {
77+
onChange = (immutableTree: ImmutableTree, config: Config) => {
6678
this.immutableTree = immutableTree;
6779
this.config = config;
6880
this.updateResult();
@@ -73,7 +85,7 @@ export default class DemoQueryBuilder extends Component {
7385
this.setState({tree: this.immutableTree, config: this.config});
7486
}, 100)
7587

76-
renderResult = ({tree: immutableTree, config}) => {
88+
renderResult = ({tree: immutableTree, config} : {tree: ImmutableTree, config: Config}) => {
7789
const {logic, data, errors} = jsonLogicFormat(immutableTree, config);
7890
return (
7991
<div>
File renamed without changes.

sandbox/src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

sandbox/tsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"allowJs": true,
10+
"skipLibCheck": true,
11+
"esModuleInterop": true,
12+
"allowSyntheticDefaultImports": true,
13+
"strict": true,
14+
"forceConsistentCasingInFileNames": true,
15+
"module": "esnext",
16+
"moduleResolution": "node",
17+
"resolveJsonModule": true,
18+
"isolatedModules": true,
19+
"strictNullChecks": false,
20+
"noEmit": true,
21+
"jsx": "preserve"
22+
},
23+
"include": [
24+
"src"
25+
]
26+
}

scripts/build-npm.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
rm -rf lib
22
babel -d lib ./modules
3+
cp modules/index.d.ts lib/index.d.ts
4+
cp modules/config/antd/index.d.ts lib/config/antd/index.d.ts
5+
cp modules/components/widgets/antd/index.d.ts lib/components/widgets/antd/index.d.ts
36
find lib -type d -name __tests__ | xargs rm -rf

0 commit comments

Comments
 (0)