@sourceloop/search-client 9.0.1 → 11.0.0
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/.prettierignore +2 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +123 -0
- package/README.md +26 -3
- package/bundle-element.ts +42 -0
- package/karma.conf.js +56 -0
- package/ng-package.json +7 -0
- package/package.json +28 -27
- package/src/favicon.ico +0 -0
- package/src/index.html +12 -0
- package/src/lib/lib-configuration.ts +112 -0
- package/src/lib/search/mocks/search.component.mock.ts +117 -0
- package/src/lib/search/promise-api-adapter.service.ts +31 -0
- package/src/lib/search/search.component.html +191 -0
- package/src/lib/search/search.component.scss +339 -0
- package/src/lib/search/search.component.spec.ts +306 -0
- package/src/lib/search/search.component.ts +457 -0
- package/src/lib/search-element.module.ts +49 -0
- package/src/lib/types.ts +85 -0
- package/src/main.ts +9 -0
- package/src/polyfills.ts +53 -0
- package/src/public-api.ts +10 -0
- package/src/styles.scss +4 -0
- package/src/test.ts +32 -0
- package/tsconfig.app.json +15 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +18 -0
- package/fesm2022/sourceloop-search-client.mjs +0 -564
- package/fesm2022/sourceloop-search-client.mjs.map +0 -1
- package/index.d.ts +0 -182
- /package/{assets → src/assets}/icomoon/fonts/icomoon.ttf +0 -0
- /package/{assets → src/assets}/icomoon/style.css +0 -0
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [11.0.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@10.0.0...@sourceloop/search-client@11.0.0) (2025-12-30)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **deps:** angular version upgrade and converted into workspace ([#65](https://github.com/sourcefuse/arc-ng-components/issues/65)) ([54dfe07](https://github.com/sourcefuse/arc-ng-components/commit/54dfe07c3834b206d4115f7932d9220ce2c73c44)), closes [#64](https://github.com/sourcefuse/arc-ng-components/issues/64)
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
- **deps:** YES
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
This pull request introduces significant refactoring and modernization
|
|
19
|
+
of the `SearchComponent` in the `search-lib` package, focusing on
|
|
20
|
+
adopting Angular's new signal-based inputs/outputs, streamlining
|
|
21
|
+
configuration management, and improving testability. Additionally, it
|
|
22
|
+
includes workspace and dependency updates at the root level, and some
|
|
23
|
+
cleanup of outdated scripts and files.
|
|
24
|
+
|
|
25
|
+
# [10.0.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@9.0.1...@sourceloop/search-client@10.0.0) (2025-12-11)
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- **sandbox:** version upgrade ([ca924ed](https://github.com/sourcefuse/arc-ng-components/commit/ca924edbaf68c53675728c8edad8d1c60f299013))
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
- **search-client:** add support for angular v21 ([#52](https://github.com/sourcefuse/arc-ng-components/issues/52)) ([26486e8](https://github.com/sourcefuse/arc-ng-components/commit/26486e8c683f63e37b29e7a41bb9c806f9ffc90c)), closes [#50](https://github.com/sourcefuse/arc-ng-components/issues/50)
|
|
34
|
+
|
|
35
|
+
### BREAKING CHANGES
|
|
36
|
+
|
|
37
|
+
- **search-client:** YES
|
|
38
|
+
|
|
39
|
+
## Description
|
|
40
|
+
|
|
41
|
+
This pull request upgrades the Angular dependencies for the search
|
|
42
|
+
module and related packages from Angular v20 to Angular v21. It also
|
|
43
|
+
updates the deprecation notice in documentation to reflect this new
|
|
44
|
+
support window.
|
|
45
|
+
|
|
46
|
+
## [9.0.1](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@9.0.0...@sourceloop/search-client@9.0.1) (2025-12-10)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @sourceloop/search-client
|
|
49
|
+
|
|
50
|
+
# [9.0.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@8.0.1...@sourceloop/search-client@9.0.0) (2025-12-09)
|
|
51
|
+
|
|
52
|
+
### Features
|
|
53
|
+
|
|
54
|
+
- **deps:** add support for angular v20 ([#49](https://github.com/sourcefuse/arc-ng-components/issues/49)) ([3ef0a0f](https://github.com/sourcefuse/arc-ng-components/commit/3ef0a0fdb0e3de05c1645e9e55f2de1069bfc6fe)), closes [#48](https://github.com/sourcefuse/arc-ng-components/issues/48)
|
|
55
|
+
|
|
56
|
+
### BREAKING CHANGES
|
|
57
|
+
|
|
58
|
+
- **deps:** YES
|
|
59
|
+
|
|
60
|
+
## [8.0.1](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@8.0.0...@sourceloop/search-client@8.0.1) (2025-12-09)
|
|
61
|
+
|
|
62
|
+
**Note:** Version bump only for package @sourceloop/search-client
|
|
63
|
+
|
|
64
|
+
# [8.0.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@6.1.0...@sourceloop/search-client@8.0.0) (2025-12-09)
|
|
65
|
+
|
|
66
|
+
### Documentation
|
|
67
|
+
|
|
68
|
+
- **search-client:** update readme after upgrading to angular 17 ([#34](https://github.com/sourcefuse/arc-ng-components/issues/34)) ([2471785](https://github.com/sourcefuse/arc-ng-components/commit/247178534a7c5a4561fd54d38f19412e3b58beac)), closes [#30](https://github.com/sourcefuse/arc-ng-components/issues/30) [#30](https://github.com/sourcefuse/arc-ng-components/issues/30)
|
|
69
|
+
|
|
70
|
+
### Features
|
|
71
|
+
|
|
72
|
+
- **deps:** adds support for Angular 19 and migrates the component to a fully standalone structure ([#45](https://github.com/sourcefuse/arc-ng-components/issues/45)) ([8f7f7e3](https://github.com/sourcefuse/arc-ng-components/commit/8f7f7e3f46c3edefd87877bf886db7eb31716435)), closes [#42](https://github.com/sourcefuse/arc-ng-components/issues/42)
|
|
73
|
+
|
|
74
|
+
### BREAKING CHANGES
|
|
75
|
+
|
|
76
|
+
- **deps:** YES
|
|
77
|
+
|
|
78
|
+
## Description
|
|
79
|
+
|
|
80
|
+
This pull request modernizes the `@sourceloop/search-client` library and
|
|
81
|
+
its example by upgrading to Angular 19, refactoring the search component
|
|
82
|
+
to be standalone, and updating documentation and configuration to
|
|
83
|
+
reflect these changes. The updates simplify integration for consumers
|
|
84
|
+
and leverage Angular's latest features for improved modularity and
|
|
85
|
+
maintainability.
|
|
86
|
+
|
|
87
|
+
- **search-client:**
|
|
88
|
+
|
|
89
|
+
## [7.0.1](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@7.0.0...@sourceloop/search-client@7.0.1) (2025-07-21)
|
|
90
|
+
|
|
91
|
+
**Note:** Version bump only for package @sourceloop/search-client
|
|
92
|
+
|
|
93
|
+
# [7.0.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@6.1.0...@sourceloop/search-client@7.0.0) (2025-07-18)
|
|
94
|
+
|
|
95
|
+
### Documentation
|
|
96
|
+
|
|
97
|
+
- **search-client:** update readme after upgrading to angular 17 ([#34](https://github.com/sourcefuse/arc-ng-components/issues/34)) ([2471785](https://github.com/sourcefuse/arc-ng-components/commit/247178534a7c5a4561fd54d38f19412e3b58beac)), closes [#30](https://github.com/sourcefuse/arc-ng-components/issues/30) [#30](https://github.com/sourcefuse/arc-ng-components/issues/30)
|
|
98
|
+
|
|
99
|
+
### BREAKING CHANGES
|
|
100
|
+
|
|
101
|
+
- **search-client:**
|
|
102
|
+
|
|
103
|
+
# [6.1.0](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@6.0.1...@sourceloop/search-client@6.1.0) (2024-04-10)
|
|
104
|
+
|
|
105
|
+
### Features
|
|
106
|
+
|
|
107
|
+
- **search-client:** allow custom allLabel ([#15](https://github.com/sourcefuse/arc-ng-components/issues/15)) ([8b45291](https://github.com/sourcefuse/arc-ng-components/commit/8b4529171ea587ff2fd8c733ccd50a819491fe47)), closes [#14](https://github.com/sourcefuse/arc-ng-components/issues/14)
|
|
108
|
+
|
|
109
|
+
## [6.0.1](https://github.com/sourcefuse/arc-ng-components/compare/@sourceloop/search-client@6.0.0...@sourceloop/search-client@6.0.1) (2024-01-12)
|
|
110
|
+
|
|
111
|
+
### Bug Fixes
|
|
112
|
+
|
|
113
|
+
- **search-client:** refactor the SCSS file in the search component to remove 'important' keyword ([#12](https://github.com/sourcefuse/arc-ng-components/issues/12)) ([1324f19](https://github.com/sourcefuse/arc-ng-components/commit/1324f194f3b3405505137d4a5919547195143175))
|
|
114
|
+
|
|
115
|
+
# 6.0.0 (2023-11-28)
|
|
116
|
+
|
|
117
|
+
### Features
|
|
118
|
+
|
|
119
|
+
- **deps:** add support for angular v14 ([#10](https://github.com/sourcefuse/arc-ng-components/issues/10)) ([acdb006](https://github.com/sourcefuse/arc-ng-components/commit/acdb006dc782f04283d0ce7e4335781e2f5360e3)), closes [#9](https://github.com/sourcefuse/arc-ng-components/issues/9) [#9](https://github.com/sourcefuse/arc-ng-components/issues/9)
|
|
120
|
+
|
|
121
|
+
### BREAKING CHANGES
|
|
122
|
+
|
|
123
|
+
- **deps:** search library does not support angular v13
|
package/README.md
CHANGED
|
@@ -2,9 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
An Angular module that exports a component that can enable users to search over configured models using the search microservice provided in the sourceloop microservice catalog.
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
### Angular Version Compatibility
|
|
6
|
+
|
|
7
|
+
To ensure smooth integration, install the Search Library version that corresponds to your Angular version:
|
|
8
|
+
|
|
9
|
+
<table border="1" cellpadding="8" style="border-collapse: collapse; width: 100%; text-align: left;">
|
|
10
|
+
<thead>
|
|
11
|
+
<tr>
|
|
12
|
+
<th>Angular Version</th>
|
|
13
|
+
<th>Compatible Search-Client Version</th>
|
|
14
|
+
</tr>
|
|
15
|
+
</thead>
|
|
16
|
+
<tbody>
|
|
17
|
+
<tr>
|
|
18
|
+
<td>Angular v19</td>
|
|
19
|
+
<td>@sourceloop/search-client v8.x</td>
|
|
20
|
+
</tr>
|
|
21
|
+
<tr>
|
|
22
|
+
<td>Angular v20</td>
|
|
23
|
+
<td>@sourceloop/search-client v9.x</td>
|
|
24
|
+
</tr>
|
|
25
|
+
<tr>
|
|
26
|
+
<td>Angular v21+</td>
|
|
27
|
+
<td>Latest version (v10.x and above)</td>
|
|
28
|
+
</tr>
|
|
29
|
+
</tbody>
|
|
30
|
+
</table>
|
|
8
31
|
|
|
9
32
|
## Angular Module
|
|
10
33
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import {ensureDir, readFileSync, writeFileSync} from 'fs-extra';
|
|
3
|
+
import {copyFile, rm} from 'fs/promises';
|
|
4
|
+
const concat = require('concat');
|
|
5
|
+
|
|
6
|
+
async function elementsBundler() {
|
|
7
|
+
const space = 2;
|
|
8
|
+
const files = [
|
|
9
|
+
'./dist/search-element/runtime.js',
|
|
10
|
+
'./dist/search-element/polyfills.js',
|
|
11
|
+
'./dist/search-element/main.js',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
await ensureDir('../search-element/dist');
|
|
15
|
+
await concat(files, '../search-element/dist/search-element.js');
|
|
16
|
+
await copyFile(
|
|
17
|
+
'./dist/search-element/styles.css',
|
|
18
|
+
'../search-element/dist/styles.css',
|
|
19
|
+
);
|
|
20
|
+
await copyFile('./dist/README.md', '../search-element/dist/README.md');
|
|
21
|
+
await rm('./dist/search-element', {recursive: true});
|
|
22
|
+
|
|
23
|
+
// generate the hash of element file to keep a track of the chnages
|
|
24
|
+
// whenever any changes are made in the element the corresponding js file will
|
|
25
|
+
// resulting in changing its hash, so the element will also be published
|
|
26
|
+
|
|
27
|
+
const file = '../search-element/dist/search-element.js';
|
|
28
|
+
const data = readFileSync(file);
|
|
29
|
+
const hash = crypto.createHash('sha256');
|
|
30
|
+
hash.update(new Uint8Array(data));
|
|
31
|
+
|
|
32
|
+
const fileHash = hash.digest('hex');
|
|
33
|
+
|
|
34
|
+
//update the package.json with the new hashCode
|
|
35
|
+
//if there will be changes in hash then the element will also be published
|
|
36
|
+
const packageJsonPath = '../search-element/package.json';
|
|
37
|
+
const jsonObj = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
38
|
+
jsonObj.hash = fileHash;
|
|
39
|
+
writeFileSync(packageJsonPath, JSON.stringify(jsonObj, null, space));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
elementsBundler();
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// sonarignore:start
|
|
2
|
+
module.exports = function (config) {
|
|
3
|
+
const isCI = !!process.env.CI;
|
|
4
|
+
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: '',
|
|
7
|
+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
|
+
plugins: [
|
|
9
|
+
require('karma-jasmine'),
|
|
10
|
+
require('karma-chrome-launcher'),
|
|
11
|
+
require('karma-jasmine-html-reporter'),
|
|
12
|
+
require('karma-coverage'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma'),
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
client: {
|
|
17
|
+
jasmine: {},
|
|
18
|
+
clearContext: false,
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
jasmineHtmlReporter: {
|
|
22
|
+
suppressAll: true,
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
coverageReporter: {
|
|
26
|
+
dir: require('path').join(__dirname, '../../coverage/my-lib'),
|
|
27
|
+
subdir: '.',
|
|
28
|
+
reporters: [{type: 'html'}, {type: 'text-summary'}],
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
reporters: ['progress', 'kjhtml'],
|
|
32
|
+
port: 9876,
|
|
33
|
+
colors: true,
|
|
34
|
+
logLevel: config.LOG_INFO,
|
|
35
|
+
|
|
36
|
+
autoWatch: !isCI,
|
|
37
|
+
singleRun: isCI,
|
|
38
|
+
restartOnFileChange: !isCI,
|
|
39
|
+
|
|
40
|
+
browsers: isCI ? ['ChromeHeadlessCI'] : ['Chrome'],
|
|
41
|
+
|
|
42
|
+
customLaunchers: {
|
|
43
|
+
ChromeHeadlessCI: {
|
|
44
|
+
base: 'ChromeHeadless',
|
|
45
|
+
flags: [
|
|
46
|
+
'--no-sandbox',
|
|
47
|
+
'--disable-gpu',
|
|
48
|
+
'--disable-dev-shm-usage',
|
|
49
|
+
'--disable-setuid-sandbox',
|
|
50
|
+
'--headless=new',
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
// sonarignore:end
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sourceloop/search-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "A global search component for search microservice.",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@angular/animations": "^
|
|
7
|
-
"@angular/cdk": "^
|
|
8
|
-
"@angular/common": "^
|
|
9
|
-
"@angular/compiler": "^
|
|
10
|
-
"@angular/core": "^
|
|
11
|
-
"@angular/elements": "^
|
|
6
|
+
"@angular/animations": "^21.0.3",
|
|
7
|
+
"@angular/cdk": "^21.0.2",
|
|
8
|
+
"@angular/common": "^21.0.3",
|
|
9
|
+
"@angular/compiler": "^21.0.3",
|
|
10
|
+
"@angular/core": "^21.0.3",
|
|
11
|
+
"@angular/elements": "^21.0.3",
|
|
12
12
|
"@angular/flex-layout": "~15.0.0-beta.42",
|
|
13
|
-
"@angular/forms": "^
|
|
14
|
-
"@angular/material": "^
|
|
15
|
-
"@angular/platform-browser": "^
|
|
16
|
-
"@angular/platform-browser-dynamic": "^
|
|
17
|
-
"@angular/router": "^
|
|
13
|
+
"@angular/forms": "^21.0.3",
|
|
14
|
+
"@angular/material": "^21.0.2",
|
|
15
|
+
"@angular/platform-browser": "^21.0.3",
|
|
16
|
+
"@angular/platform-browser-dynamic": "^21.0.3",
|
|
17
|
+
"@angular/router": "^21.0.3",
|
|
18
18
|
"rxjs": "~7.8.1",
|
|
19
19
|
"zone.js": "^0.15.0"
|
|
20
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"libraryBuild": "npx ng build search-lib && cp -r src/assets dist/assets",
|
|
23
|
+
"elementBuild": "npx ng build search-element",
|
|
24
|
+
"postbuild": "ts-node bundle-element.ts",
|
|
25
|
+
"build": "npm run libraryBuild && npm run elementBuild",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"pretest": "npm run build",
|
|
28
|
+
"test": "ng test"
|
|
29
|
+
},
|
|
21
30
|
"dependencies": {
|
|
22
31
|
"tslib": "^2.2.0"
|
|
23
32
|
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@angular/elements": "^21.0.3",
|
|
35
|
+
"@types/fs-extra": "^11.0.1",
|
|
36
|
+
"ng-packagr": "^21.0.0"
|
|
37
|
+
},
|
|
24
38
|
"repository": {
|
|
25
39
|
"type": "git",
|
|
26
40
|
"url": "https://github.com/sourcefuse/arc-ng-components",
|
|
@@ -33,18 +47,5 @@
|
|
|
33
47
|
},
|
|
34
48
|
"author": "Sourcefuse",
|
|
35
49
|
"license": "MIT",
|
|
36
|
-
"private": false
|
|
37
|
-
|
|
38
|
-
"module": "fesm2022/sourceloop-search-client.mjs",
|
|
39
|
-
"typings": "index.d.ts",
|
|
40
|
-
"exports": {
|
|
41
|
-
"./package.json": {
|
|
42
|
-
"default": "./package.json"
|
|
43
|
-
},
|
|
44
|
-
".": {
|
|
45
|
-
"types": "./index.d.ts",
|
|
46
|
-
"default": "./fesm2022/sourceloop-search-client.mjs"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"sideEffects": false
|
|
50
|
-
}
|
|
50
|
+
"private": false
|
|
51
|
+
}
|
package/src/favicon.ico
ADDED
|
Binary file
|
package/src/index.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>SearchElement</title>
|
|
6
|
+
<base href="/">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright (c) 2023 Sourcefuse Technologies
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT License.
|
|
4
|
+
// https://opensource.org/licenses/MIT
|
|
5
|
+
import {IDefaultReturnType, IModel} from './types';
|
|
6
|
+
export class Configuration<T = IDefaultReturnType> {
|
|
7
|
+
/** property to be displayed in the results */
|
|
8
|
+
displayPropertyName: keyof T;
|
|
9
|
+
/** list of model configuration to be render and categorize search results */
|
|
10
|
+
models: IModel[];
|
|
11
|
+
/** max number of results (based on limitByType option) */
|
|
12
|
+
limit?: number;
|
|
13
|
+
/** apply limit on individual models, or on overall results */
|
|
14
|
+
limitByType?: boolean;
|
|
15
|
+
/** apply a particular ordering on results */
|
|
16
|
+
order?: string[];
|
|
17
|
+
/** offset for results in case limit is used */
|
|
18
|
+
offset?: number;
|
|
19
|
+
/** save the search query in recent history */
|
|
20
|
+
saveInRecents?: boolean;
|
|
21
|
+
/** a placeholder to display in the search box */
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** a function to generate placeholder, overrides the placeholder property */
|
|
24
|
+
placeholderFunction?: (input: string, category: string) => string;
|
|
25
|
+
/** categorize results on the basis of models provided */
|
|
26
|
+
categorizeResults?: boolean;
|
|
27
|
+
/** hides the recent search list */
|
|
28
|
+
hideRecentSearch?: boolean;
|
|
29
|
+
/** hide the category selection button */
|
|
30
|
+
hideCategorizeButton?: boolean;
|
|
31
|
+
/** save value in recent search only on enter or change in category,
|
|
32
|
+
* if false, also saved on typing */
|
|
33
|
+
saveInRecentsOnlyOnEnter?: boolean;
|
|
34
|
+
/** search only on enter key or when category is changed */
|
|
35
|
+
searchOnlyOnEnter?: boolean;
|
|
36
|
+
noResultMessage?: string;
|
|
37
|
+
searchIconClass?: string;
|
|
38
|
+
crossIconClass?: string;
|
|
39
|
+
dropDownButtonIconClass?: string;
|
|
40
|
+
recentSearchIconClass?: string;
|
|
41
|
+
|
|
42
|
+
constructor(d: Configuration<T>) {
|
|
43
|
+
checkForError(d);
|
|
44
|
+
this.displayPropertyName = d.displayPropertyName;
|
|
45
|
+
this.models = d.models;
|
|
46
|
+
|
|
47
|
+
/* IRequestParameters - will be given default values before call is made in case undefined/null,
|
|
48
|
+
otherwise there ! is used on which sonar gives code smell */
|
|
49
|
+
this.limit = d.limit;
|
|
50
|
+
this.limitByType = d.limitByType;
|
|
51
|
+
this.order = d.order;
|
|
52
|
+
this.offset = d.offset;
|
|
53
|
+
this.saveInRecents = d.saveInRecents;
|
|
54
|
+
|
|
55
|
+
const displayTexts = setDisplayText(d);
|
|
56
|
+
this.noResultMessage = displayTexts.noResultMessage;
|
|
57
|
+
this.placeholder = displayTexts.placeholder;
|
|
58
|
+
this.placeholderFunction = displayTexts.placeholderFunction;
|
|
59
|
+
|
|
60
|
+
const searchConfig = setSearchConfig(d);
|
|
61
|
+
this.categorizeResults = searchConfig.categorizeResults;
|
|
62
|
+
this.hideRecentSearch = searchConfig.hideRecentSearch;
|
|
63
|
+
this.hideCategorizeButton = searchConfig.hideCategorizeButton;
|
|
64
|
+
this.saveInRecentsOnlyOnEnter = searchConfig.saveInRecentsOnlyOnEnter;
|
|
65
|
+
this.searchOnlyOnEnter = searchConfig.searchOnlyOnEnter;
|
|
66
|
+
|
|
67
|
+
const classes = setIconClasses(d);
|
|
68
|
+
this.searchIconClass = classes.searchIconClass;
|
|
69
|
+
this.crossIconClass = classes.crossIconClass;
|
|
70
|
+
this.dropDownButtonIconClass = classes.dropDownButtonIconClass;
|
|
71
|
+
this.recentSearchIconClass = classes.recentSearchIconClass;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function checkForError<T>(d: Configuration<T>) {
|
|
75
|
+
if (
|
|
76
|
+
d.categorizeResults === false &&
|
|
77
|
+
(d.hideCategorizeButton === false || d.hideCategorizeButton === undefined)
|
|
78
|
+
) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'You must provide hideCategorizeButton:true as categorizeResults is false',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (d.saveInRecents === false && d.saveInRecentsOnlyOnEnter === true) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
'You must provide saveInRecents:true for saveInRecentsOnlyOnEnter:true',
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function setDisplayText<T>(d: Configuration<T>) {
|
|
90
|
+
return {
|
|
91
|
+
placeholder: d.placeholder ?? 'Search',
|
|
92
|
+
noResultMessage: d.noResultMessage ?? 'No result found',
|
|
93
|
+
placeholderFunction: d.placeholderFunction,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function setSearchConfig<T>(d: Configuration<T>) {
|
|
97
|
+
return {
|
|
98
|
+
categorizeResults: d.categorizeResults ?? true,
|
|
99
|
+
hideRecentSearch: d.hideRecentSearch ?? false,
|
|
100
|
+
hideCategorizeButton: d.hideCategorizeButton ?? false,
|
|
101
|
+
saveInRecentsOnlyOnEnter: d.saveInRecentsOnlyOnEnter ?? false,
|
|
102
|
+
searchOnlyOnEnter: d.searchOnlyOnEnter ?? false,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function setIconClasses<T>(d: Configuration<T>) {
|
|
106
|
+
return {
|
|
107
|
+
searchIconClass: d.searchIconClass ?? 'icomoon Search',
|
|
108
|
+
crossIconClass: d.crossIconClass ?? 'icomoon close',
|
|
109
|
+
dropDownButtonIconClass: d.dropDownButtonIconClass ?? 'icomoon arrow_down',
|
|
110
|
+
recentSearchIconClass: d.recentSearchIconClass ?? 'icomoon Search',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {Configuration} from '../../lib-configuration';
|
|
2
|
+
import {
|
|
3
|
+
IModel,
|
|
4
|
+
IReturnType,
|
|
5
|
+
ISearchQuery,
|
|
6
|
+
ISearchService,
|
|
7
|
+
TypeEvent,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
export const Imodel: IModel = {
|
|
10
|
+
name: 'ToDo',
|
|
11
|
+
displayName: 'List',
|
|
12
|
+
};
|
|
13
|
+
export const IReturnMockValue: IReturnType[] = [
|
|
14
|
+
{
|
|
15
|
+
rank: 1,
|
|
16
|
+
source: '',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
export interface MockIReturnType {
|
|
20
|
+
rank: number;
|
|
21
|
+
source: string;
|
|
22
|
+
}
|
|
23
|
+
export const mockIModel: IModel = {
|
|
24
|
+
name: 'User',
|
|
25
|
+
displayName: 'Users',
|
|
26
|
+
};
|
|
27
|
+
export const mockConfig: Configuration<MockIReturnType> = {
|
|
28
|
+
displayPropertyName: 'source',
|
|
29
|
+
models: [
|
|
30
|
+
{
|
|
31
|
+
name: 'ToDo',
|
|
32
|
+
displayName: 'List',
|
|
33
|
+
imageUrl: 'https://picsum.photos/id/1/50',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'User',
|
|
37
|
+
displayName: 'Users',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
limit: 20,
|
|
41
|
+
limitByType: false,
|
|
42
|
+
order: [`name ASC`, `description DESC`],
|
|
43
|
+
offset: 0,
|
|
44
|
+
saveInRecents: true,
|
|
45
|
+
placeholder: '',
|
|
46
|
+
//placeholderFunction: (input: string, category: string) =>{},
|
|
47
|
+
categorizeResults: true,
|
|
48
|
+
hideRecentSearch: false,
|
|
49
|
+
hideCategorizeButton: false,
|
|
50
|
+
saveInRecentsOnlyOnEnter: true,
|
|
51
|
+
searchOnlyOnEnter: true,
|
|
52
|
+
noResultMessage: '',
|
|
53
|
+
searchIconClass: '',
|
|
54
|
+
crossIconClass: '',
|
|
55
|
+
dropDownButtonIconClass: '',
|
|
56
|
+
recentSearchIconClass: '',
|
|
57
|
+
};
|
|
58
|
+
export const ISearchMockValue: ISearchQuery[] = [
|
|
59
|
+
{
|
|
60
|
+
match: 'user',
|
|
61
|
+
limit: 10,
|
|
62
|
+
order: '',
|
|
63
|
+
limitByType: false,
|
|
64
|
+
offset: 2,
|
|
65
|
+
sources: [],
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
export class MockSearchService implements ISearchService<IReturnType> {
|
|
69
|
+
searchApiRequest = jasmine.createSpy();
|
|
70
|
+
recentSearchApiRequest = jasmine.createSpy();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const mockCategory = ['User'];
|
|
74
|
+
export function mockFunction(): void {
|
|
75
|
+
// This is intentional
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function mockOnChange(_mockValue: string | undefined): void {
|
|
79
|
+
// This is intentional
|
|
80
|
+
}
|
|
81
|
+
export const mockSuggestionUrl: IReturnType = {
|
|
82
|
+
rank: 1,
|
|
83
|
+
source: 'ToDo',
|
|
84
|
+
};
|
|
85
|
+
export const mockSuggestion: IReturnType = {
|
|
86
|
+
rank: 1,
|
|
87
|
+
source: 'User',
|
|
88
|
+
};
|
|
89
|
+
export const mockSuggestionForModel: IReturnType = {
|
|
90
|
+
rank: 1,
|
|
91
|
+
source: '',
|
|
92
|
+
};
|
|
93
|
+
export const mockEvent: TypeEvent = {
|
|
94
|
+
input: 'User',
|
|
95
|
+
};
|
|
96
|
+
export const url = 'https://picsum.photos/id/1/50';
|
|
97
|
+
export const value = '';
|
|
98
|
+
export const emittedValue = {
|
|
99
|
+
input: 'User',
|
|
100
|
+
event: new KeyboardEvent('click', {
|
|
101
|
+
key: 'Enter',
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
export const recentSearch: ISearchQuery = {
|
|
105
|
+
match: 'user',
|
|
106
|
+
limit: 10,
|
|
107
|
+
order: '',
|
|
108
|
+
limitByType: false,
|
|
109
|
+
offset: 2,
|
|
110
|
+
sources: [],
|
|
111
|
+
};
|
|
112
|
+
export function mockDisabledState(_disable: boolean): void {
|
|
113
|
+
// This is intentional
|
|
114
|
+
}
|
|
115
|
+
export const mockNoEvent: TypeEvent = {
|
|
116
|
+
input: '',
|
|
117
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Injectable} from '@angular/core';
|
|
2
|
+
import {from} from 'rxjs';
|
|
3
|
+
import {
|
|
4
|
+
IReturnType,
|
|
5
|
+
ISearchService,
|
|
6
|
+
ISearchServiceWithPromises,
|
|
7
|
+
} from '../types';
|
|
8
|
+
|
|
9
|
+
@Injectable({
|
|
10
|
+
providedIn: 'root',
|
|
11
|
+
})
|
|
12
|
+
export class PromiseApiAdapterService<T extends IReturnType> {
|
|
13
|
+
adapt(instance: ISearchServiceWithPromises<T>): ISearchService<T> {
|
|
14
|
+
// this is a workaround for the fact that the recentSearchApiRequestWithPromise
|
|
15
|
+
// method is optional in the ISearchServiceWithPromises interface
|
|
16
|
+
// and type system is not able maintain the type information of a property
|
|
17
|
+
const recentSearchMethod = instance.recentSearchApiRequestWithPromise;
|
|
18
|
+
return {
|
|
19
|
+
searchApiRequest: (requestParameters, saveInRecents) =>
|
|
20
|
+
from(
|
|
21
|
+
instance.searchApiRequestWithPromise(
|
|
22
|
+
requestParameters,
|
|
23
|
+
saveInRecents,
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
...(recentSearchMethod && {
|
|
27
|
+
recentSearchApiRequest: () => from(recentSearchMethod()),
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|