piral-search 1.0.0-pre.2217 → 1.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/LICENSE +1 -1
- package/README.md +8 -2
- package/esm/Search.js +3 -3
- package/esm/Search.js.map +1 -1
- package/esm/SearchInput.js +2 -2
- package/esm/SearchInput.js.map +1 -1
- package/esm/actions.js +46 -49
- package/esm/actions.js.map +1 -1
- package/esm/components.d.ts +4 -5
- package/esm/components.js +3 -3
- package/esm/components.js.map +1 -1
- package/esm/create.js +37 -38
- package/esm/create.js.map +1 -1
- package/esm/default.js +3 -3
- package/esm/default.js.map +1 -1
- package/esm/types.d.ts +11 -3
- package/esm/useDebounce.d.ts +8 -0
- package/esm/useDebounce.js +17 -0
- package/esm/useDebounce.js.map +1 -0
- package/esm/useSearch.js +7 -6
- package/esm/useSearch.js.map +1 -1
- package/lib/Search.js +7 -6
- package/lib/Search.js.map +1 -1
- package/lib/SearchInput.js +6 -5
- package/lib/SearchInput.js.map +1 -1
- package/lib/actions.js +49 -52
- package/lib/actions.js.map +1 -1
- package/lib/components.d.ts +4 -5
- package/lib/components.js +4 -4
- package/lib/components.js.map +1 -1
- package/lib/create.js +43 -44
- package/lib/create.js.map +1 -1
- package/lib/default.js +8 -5
- package/lib/default.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +11 -3
- package/lib/useDebounce.d.ts +8 -0
- package/lib/useDebounce.js +21 -0
- package/lib/useDebounce.js.map +1 -0
- package/lib/useSearch.js +8 -7
- package/lib/useSearch.js.map +1 -1
- package/package.json +29 -6
- package/piral-search.min.js +1 -0
- package/src/actions.test.ts +45 -44
- package/src/components.tsx +3 -5
- package/src/create.test.ts +16 -4
- package/src/create.ts +45 -23
- package/src/types.ts +12 -3
- package/src/useDebounce.test.ts +67 -0
- package/src/useDebounce.ts +19 -0
- package/src/useSearch.test.ts +17 -7
- package/src/useSearch.ts +2 -1
package/lib/actions.js
CHANGED
|
@@ -1,86 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createActions = void 0;
|
|
4
|
-
|
|
5
|
-
var piral_core_1 = require("piral-core");
|
|
4
|
+
const piral_core_1 = require("piral-core");
|
|
6
5
|
function defaultFilter(_, providerNames) {
|
|
7
6
|
return providerNames;
|
|
8
7
|
}
|
|
9
|
-
function createActions(config) {
|
|
10
|
-
|
|
11
|
-
var _a = config.emptyTrigger, emptyTrigger = _a === void 0 ? false : _a, _b = config.filter, filter = _b === void 0 ? defaultFilter : _b;
|
|
8
|
+
function createActions(config = {}) {
|
|
9
|
+
const { emptyTrigger = false, filter = defaultFilter } = config;
|
|
12
10
|
return {
|
|
13
|
-
setSearchInput
|
|
14
|
-
ctx.dispatch(
|
|
11
|
+
setSearchInput(ctx, input) {
|
|
12
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { search: Object.assign(Object.assign({}, state.search), { input }) })));
|
|
15
13
|
},
|
|
16
|
-
triggerSearch
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var loading = results.loading;
|
|
14
|
+
triggerSearch(ctx, query, immediate = false) {
|
|
15
|
+
const providers = ctx.readState((state) => state.registry.searchProviders);
|
|
16
|
+
const { input, results } = ctx.readState((state) => state.search);
|
|
17
|
+
const { loading } = results;
|
|
21
18
|
if (query === undefined) {
|
|
22
19
|
query = input;
|
|
23
20
|
}
|
|
24
21
|
if (input !== query || !loading) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ctx.resetSearchResults(query,
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
query
|
|
35
|
-
immediate
|
|
22
|
+
const selectedProviders = filter(query, Object.keys(providers));
|
|
23
|
+
const providerKeys = selectedProviders.filter((m) => !providers[m].onlyImmediate || immediate);
|
|
24
|
+
const acceptQuery = emptyTrigger || !!query;
|
|
25
|
+
const load = acceptQuery && providerKeys.length > 0;
|
|
26
|
+
ctx.resetSearchResults(query, load);
|
|
27
|
+
if (load) {
|
|
28
|
+
let searchCount = providerKeys.length;
|
|
29
|
+
let active = true;
|
|
30
|
+
const opts = {
|
|
31
|
+
query,
|
|
32
|
+
immediate,
|
|
36
33
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
provider.search(
|
|
40
|
-
|
|
41
|
-
},
|
|
34
|
+
providerKeys.forEach((key) => {
|
|
35
|
+
const provider = providers[key];
|
|
36
|
+
provider.search(opts).then((results) => {
|
|
37
|
+
active && ctx.appendSearchResults(results, --searchCount === 0);
|
|
38
|
+
}, (ex) => {
|
|
42
39
|
console.warn(ex);
|
|
43
|
-
|
|
40
|
+
active && --searchCount === 0 && ctx.appendSearchResults([], true);
|
|
44
41
|
});
|
|
45
42
|
});
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
ctx.appendSearchResults([],
|
|
43
|
+
return () => {
|
|
44
|
+
active = false;
|
|
45
|
+
providerKeys.forEach((key) => providers[key].cancel());
|
|
46
|
+
ctx.appendSearchResults([], load);
|
|
50
47
|
};
|
|
51
48
|
}
|
|
52
49
|
else if (!query) {
|
|
53
|
-
selectedProviders.forEach(
|
|
50
|
+
selectedProviders.forEach((key) => providers[key].clear());
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
return
|
|
53
|
+
return () => { };
|
|
57
54
|
},
|
|
58
|
-
resetSearchResults
|
|
59
|
-
ctx.dispatch(
|
|
60
|
-
input
|
|
55
|
+
resetSearchResults(ctx, input, loading) {
|
|
56
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { search: {
|
|
57
|
+
input,
|
|
61
58
|
results: {
|
|
62
|
-
loading
|
|
59
|
+
loading,
|
|
63
60
|
items: [],
|
|
64
61
|
},
|
|
65
|
-
} }))
|
|
62
|
+
} })));
|
|
66
63
|
},
|
|
67
|
-
appendSearchResults
|
|
68
|
-
ctx.dispatch(
|
|
64
|
+
appendSearchResults(ctx, items, done) {
|
|
65
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { search: Object.assign(Object.assign({}, state.search), { results: {
|
|
69
66
|
loading: !done,
|
|
70
|
-
items: piral_core_1.appendItems(state.search.results.items, items),
|
|
71
|
-
} }) }))
|
|
67
|
+
items: (0, piral_core_1.appendItems)(state.search.results.items, items),
|
|
68
|
+
} }) })));
|
|
72
69
|
},
|
|
73
|
-
prependSearchResults
|
|
74
|
-
ctx.dispatch(
|
|
70
|
+
prependSearchResults(ctx, items, done) {
|
|
71
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { search: Object.assign(Object.assign({}, state.search), { results: {
|
|
75
72
|
loading: !done,
|
|
76
|
-
items: piral_core_1.prependItems(state.search.results.items, items),
|
|
77
|
-
} }) }))
|
|
73
|
+
items: (0, piral_core_1.prependItems)(state.search.results.items, items),
|
|
74
|
+
} }) })));
|
|
78
75
|
},
|
|
79
|
-
registerSearchProvider
|
|
80
|
-
ctx.dispatch(
|
|
76
|
+
registerSearchProvider(ctx, name, value) {
|
|
77
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { searchProviders: (0, piral_core_1.withKey)(state.registry.searchProviders, name, value) }) })));
|
|
81
78
|
},
|
|
82
|
-
unregisterSearchProvider
|
|
83
|
-
ctx.dispatch(
|
|
79
|
+
unregisterSearchProvider(ctx, name) {
|
|
80
|
+
ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { searchProviders: (0, piral_core_1.withoutKey)(state.registry.searchProviders, name) }) })));
|
|
84
81
|
},
|
|
85
82
|
};
|
|
86
83
|
}
|
package/lib/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.js","sour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AE,IAAA,oBAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,OAEvE,CAAC,CAAC;QACN,CAAC;QACD,wBAAwB,CAAC,GAAuB,EAAE,IAAY;YAC5D,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,eAAe,EAAE,IAAA,uBAAU,EAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,OAEnE,CAAC,CAAC;QACN,CAAC;KACF,CAAC;AACJ,CAAC;AApHD,sCAoHC"}
|
package/lib/components.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const PiralSearchResult: React.ComponentType<SearchResultProps>;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const PiralSearchContainer: import("react").ComponentType<import("./types").SearchContainerProps>;
|
|
3
|
+
export declare const PiralSearchInput: import("react").ComponentType<import("./types").SearchInputProps>;
|
|
4
|
+
export declare const PiralSearchResult: import("react").ComponentType<import("./types").SearchResultProps>;
|
package/lib/components.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PiralSearchResult = exports.PiralSearchInput = exports.PiralSearchContainer = void 0;
|
|
4
|
-
|
|
5
|
-
exports.PiralSearchContainer = piral_core_1.getPiralComponent('SearchContainer');
|
|
6
|
-
exports.PiralSearchInput = piral_core_1.getPiralComponent('SearchInput');
|
|
7
|
-
exports.PiralSearchResult = piral_core_1.getPiralComponent('SearchResult');
|
|
4
|
+
const piral_core_1 = require("piral-core");
|
|
5
|
+
exports.PiralSearchContainer = (0, piral_core_1.getPiralComponent)('SearchContainer');
|
|
6
|
+
exports.PiralSearchInput = (0, piral_core_1.getPiralComponent)('SearchInput');
|
|
7
|
+
exports.PiralSearchResult = (0, piral_core_1.getPiralComponent)('SearchResult');
|
|
8
8
|
//# sourceMappingURL=components.js.map
|
package/lib/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";;;AAAA,2CAA+C;AAElC,QAAA,oBAAoB,GAAG,IAAA,8BAAiB,EAAC,iBAAiB,CAAC,CAAC;AAC5D,QAAA,gBAAgB,GAAG,IAAA,8BAAiB,EAAC,aAAa,CAAC,CAAC;AACpD,QAAA,iBAAiB,GAAG,IAAA,8BAAiB,EAAC,cAAc,CAAC,CAAC"}
|
package/lib/create.js
CHANGED
|
@@ -1,74 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSearchApi = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const piral_core_1 = require("piral-core");
|
|
7
|
+
const actions_1 = require("./actions");
|
|
8
|
+
const default_1 = require("./default");
|
|
9
|
+
const Search_1 = require("./Search");
|
|
10
|
+
const SearchInput_1 = require("./SearchInput");
|
|
10
11
|
function noop() { }
|
|
11
|
-
function createSearchRegistration(pilet, search, settings) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onlyImmediate: onlyImmediate, cancel: piral_base_1.isfunc(onCancel) ? onCancel : noop, clear: piral_base_1.isfunc(onClear) ? onClear : noop, search: search });
|
|
12
|
+
function createSearchRegistration(pilet, search, settings = {}) {
|
|
13
|
+
const { onlyImmediate = false, onCancel = noop, onClear = noop } = settings, rest = tslib_1.__rest(settings, ["onlyImmediate", "onCancel", "onClear"]);
|
|
14
|
+
return Object.assign(Object.assign({}, rest), { pilet,
|
|
15
|
+
onlyImmediate, cancel: (0, piral_core_1.isfunc)(onCancel) ? onCancel : noop, clear: (0, piral_core_1.isfunc)(onClear) ? onClear : noop, search });
|
|
16
16
|
}
|
|
17
17
|
function getSearchProviders(providers) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (
|
|
21
|
-
|
|
22
|
-
searchProviders["global-" + i++] = createSearchRegistration(undefined, search, settings);
|
|
18
|
+
const searchProviders = {};
|
|
19
|
+
let i = 0;
|
|
20
|
+
for (const { search, settings } of providers) {
|
|
21
|
+
searchProviders[`global-${i++}`] = createSearchRegistration(undefined, search, settings);
|
|
23
22
|
}
|
|
24
23
|
return searchProviders;
|
|
25
24
|
}
|
|
26
25
|
function toChild(content, api, context) {
|
|
27
|
-
if (typeof content === 'string' || react_1.isValidElement(content)) {
|
|
26
|
+
if (typeof content === 'string' || (0, react_1.isValidElement)(content)) {
|
|
28
27
|
return content;
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
|
-
|
|
32
|
-
return react_1.createElement(component);
|
|
30
|
+
const component = (0, piral_core_1.withApi)(context, content, api, 'extension');
|
|
31
|
+
return (0, react_1.createElement)(component);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
function wrapResults(result, api, context) {
|
|
36
|
-
|
|
37
|
-
return results.map(
|
|
35
|
+
const results = Array.isArray(result) ? result : [result];
|
|
36
|
+
return results.map((item) => toChild(item, api, context));
|
|
37
|
+
}
|
|
38
|
+
function withSearch(searchProviders, query, items) {
|
|
39
|
+
return (state) => (Object.assign(Object.assign({}, state), { components: Object.assign({ SearchContainer: default_1.DefaultContainer, SearchInput: default_1.DefaultInput, SearchResult: default_1.DefaultResult }, state.components), registry: Object.assign(Object.assign({}, state.registry), { searchProviders }), search: {
|
|
40
|
+
input: query,
|
|
41
|
+
results: {
|
|
42
|
+
loading: false,
|
|
43
|
+
items,
|
|
44
|
+
},
|
|
45
|
+
} }));
|
|
38
46
|
}
|
|
39
47
|
/**
|
|
40
48
|
* Creates new Pilet API extensions for search and filtering.
|
|
41
49
|
*/
|
|
42
|
-
function createSearchApi(config) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
context.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
loading: false,
|
|
51
|
-
items: results,
|
|
52
|
-
},
|
|
53
|
-
} })); });
|
|
54
|
-
return function (api, target) {
|
|
55
|
-
var pilet = target.name;
|
|
56
|
-
var next = 0;
|
|
50
|
+
function createSearchApi(config = {}) {
|
|
51
|
+
const { providers = [], results = [], query = '' } = config, actionConfig = tslib_1.__rest(config, ["providers", "results", "query"]);
|
|
52
|
+
return (context) => {
|
|
53
|
+
context.defineActions((0, actions_1.createActions)(actionConfig));
|
|
54
|
+
context.dispatch((0, piral_core_1.withAll)(withSearch(getSearchProviders(providers), query, results), (0, piral_core_1.withRootExtension)('piral-search', Search_1.Search), (0, piral_core_1.withRootExtension)('piral-search-input', SearchInput_1.SearchInput)));
|
|
55
|
+
return (api, target) => {
|
|
56
|
+
const pilet = target.name;
|
|
57
|
+
let next = 0;
|
|
57
58
|
return {
|
|
58
|
-
registerSearchProvider
|
|
59
|
+
registerSearchProvider(name, provider, settings) {
|
|
59
60
|
if (typeof name !== 'string') {
|
|
60
61
|
settings = provider;
|
|
61
62
|
provider = name;
|
|
62
63
|
name = next++;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
context.registerSearchProvider(id, createSearchRegistration(pilet,
|
|
66
|
-
|
|
67
|
-
}, settings));
|
|
68
|
-
return function () { return api.unregisterSearchProvider(name); };
|
|
65
|
+
const id = (0, piral_core_1.buildName)(pilet, name);
|
|
66
|
+
context.registerSearchProvider(id, createSearchRegistration(pilet, (q) => Promise.resolve(provider(q, api)).then((results) => wrapResults(results, api, context), () => []), settings));
|
|
67
|
+
return () => api.unregisterSearchProvider(name);
|
|
69
68
|
},
|
|
70
|
-
unregisterSearchProvider
|
|
71
|
-
|
|
69
|
+
unregisterSearchProvider(name) {
|
|
70
|
+
const id = (0, piral_core_1.buildName)(pilet, name);
|
|
72
71
|
context.unregisterSearchProvider(id);
|
|
73
72
|
},
|
|
74
73
|
};
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;;AAAA,iCAAkE;AAClE,2CAWoB;AACpB,uCAA0C;AAC1C,uCAA0E;AAC1E,qCAAkC;AAClC,+CAA4C;AAsD5C,SAAS,IAAI,KAAI,CAAC;AAElB,SAAS,wBAAwB,CAC/B,KAAa,EACb,MAAqB,EACrB,WAA2B,EAAE;IAE7B,MAAM,EAAE,aAAa,GAAG,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,KAAc,QAAQ,EAAjB,IAAI,kBAAK,QAAQ,EAA9E,wCAAmE,CAAW,CAAC;IACrF,uCACK,IAAI,KACP,KAAK;QACL,aAAa,EACb,MAAM,EAAE,IAAA,mBAAM,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAC1C,KAAK,EAAE,IAAA,mBAAM,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EACvC,MAAM,IACN;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,SAAuC;IACjE,MAAM,eAAe,GAAqC,EAAE,CAAC;IAC7D,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE;QAC5C,eAAe,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,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AAC;oBACF,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;gBAClD,CAAC;gBACD,wBAAwB,CAAC,IAAI;oBAC3B,MAAM,EAAE,GAAG,IAAA,sBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,OAAO,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAC;gBACvC,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAhDD,0CAgDC"}
|
package/lib/default.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultInput = exports.DefaultResult = exports.DefaultContainer = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const piral_core_1 = require("piral-core");
|
|
6
|
+
const DefaultContainer = (props) => (0, piral_core_1.defaultRender)(props.children);
|
|
7
|
+
exports.DefaultContainer = DefaultContainer;
|
|
8
|
+
const DefaultResult = (props) => (0, piral_core_1.defaultRender)(props.children);
|
|
9
|
+
exports.DefaultResult = DefaultResult;
|
|
10
|
+
const DefaultInput = (props) => (React.createElement("input", { onChange: (e) => props.setValue(e.target.value), value: props.value }));
|
|
11
|
+
exports.DefaultInput = DefaultInput;
|
|
9
12
|
//# sourceMappingURL=default.js.map
|
package/lib/default.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAA2C;AAGpC,MAAM,gBAAgB,GAAmC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAA5F,QAAA,gBAAgB,oBAA4E;AAClG,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAAtF,QAAA,aAAa,iBAAyE;AAC5F,MAAM,YAAY,GAA+B,CAAC,KAAK,EAAE,EAAE,CAAC,CACjE,+BAAO,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,CAC/E,CAAC;AAFW,QAAA,YAAY,gBAEvB"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./create"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./components"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./SearchInput"), exports);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactChild, ComponentType, ReactElement } from 'react';
|
|
2
|
-
import { Dict, Disposable, PiletApi, BaseRegistration, AnyComponent, BaseComponentProps, RegistrationDisposer } from 'piral-core';
|
|
1
|
+
import type { ReactChild, ComponentType, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { Dict, Disposable, PiletApi, BaseRegistration, AnyComponent, BaseComponentProps, RegistrationDisposer } from 'piral-core';
|
|
3
3
|
declare module 'piral-core/lib/types/custom' {
|
|
4
4
|
interface PiletCustomApi extends PiletSearchApi {
|
|
5
5
|
}
|
|
@@ -77,6 +77,10 @@ export interface SearchContainerProps {
|
|
|
77
77
|
* Gets if the results are still gathered.
|
|
78
78
|
*/
|
|
79
79
|
loading: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The search to display.
|
|
82
|
+
*/
|
|
83
|
+
children?: ReactNode;
|
|
80
84
|
}
|
|
81
85
|
export interface SearchInputProps {
|
|
82
86
|
setValue(value: string): void;
|
|
@@ -85,8 +89,12 @@ export interface SearchInputProps {
|
|
|
85
89
|
export interface SearchResultComponentProps extends BaseComponentProps {
|
|
86
90
|
}
|
|
87
91
|
export interface SearchResultProps {
|
|
92
|
+
/**
|
|
93
|
+
* The search results to display.
|
|
94
|
+
*/
|
|
95
|
+
children?: ReactNode;
|
|
88
96
|
}
|
|
89
|
-
export
|
|
97
|
+
export type SearchResultType = string | ReactElement<any> | AnyComponent<SearchResultComponentProps>;
|
|
90
98
|
export interface SearchProvider {
|
|
91
99
|
(options: SearchOptions, api: PiletApi): Promise<SearchResultType | Array<SearchResultType>>;
|
|
92
100
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
3
|
+
* Useful when user input should not fire immediately, but rather
|
|
4
|
+
* only after a certain timespan without any changes passed.
|
|
5
|
+
* @param value The value to consider.
|
|
6
|
+
* @param delay The timespan to pass before applying the value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDebounce<T>(value: T, delay?: number): T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
7
|
+
* Useful when user input should not fire immediately, but rather
|
|
8
|
+
* only after a certain timespan without any changes passed.
|
|
9
|
+
* @param value The value to consider.
|
|
10
|
+
* @param delay The timespan to pass before applying the value.
|
|
11
|
+
*/
|
|
12
|
+
function useDebounce(value, delay = 300) {
|
|
13
|
+
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
16
|
+
return () => clearTimeout(handler);
|
|
17
|
+
}, [value, delay]);
|
|
18
|
+
return debouncedValue;
|
|
19
|
+
}
|
|
20
|
+
exports.useDebounce = useDebounce;
|
|
21
|
+
//# sourceMappingURL=useDebounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../src/useDebounce.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAE5C;;;;;;GAMG;AACH,SAAgB,WAAW,CAAI,KAAQ,EAAE,KAAK,GAAG,GAAG;IAClD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAE5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC;AATD,kCASC"}
|
package/lib/useSearch.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSearch = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const piral_core_1 = require("piral-core");
|
|
6
|
+
const useDebounce_1 = require("./useDebounce");
|
|
6
7
|
/**
|
|
7
8
|
* Hook that yields the possibility of searching in Piral.
|
|
8
9
|
* Returns the current (live, i.e., non-debounced) input value
|
|
@@ -14,11 +15,11 @@ var piral_core_1 = require("piral-core");
|
|
|
14
15
|
* @param delay The delay [ms] to be used for the debounce.
|
|
15
16
|
*/
|
|
16
17
|
function useSearch(delay) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
react_1.useEffect(
|
|
18
|
+
const { setSearchInput, triggerSearch } = (0, piral_core_1.useActions)();
|
|
19
|
+
const searchInput = (0, piral_core_1.useGlobalState)((m) => m.search.input);
|
|
20
|
+
const query = (0, useDebounce_1.useDebounce)(searchInput, delay);
|
|
21
|
+
const cancel = (0, react_1.useRef)(undefined);
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
22
23
|
cancel.current && cancel.current();
|
|
23
24
|
cancel.current = triggerSearch(query, false);
|
|
24
25
|
}, [query]);
|
package/lib/useSearch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../src/useSearch.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../src/useSearch.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAC1C,2CAAoE;AACpE,+CAA4C;AAE5C;;;;;;;;;GASG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,IAAA,uBAAU,GAAE,CAAC;IACvD,MAAM,WAAW,GAAG,IAAA,2BAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAA,cAAM,EAAa,SAAS,CAAC,CAAC;IAE7C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnC,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AACvC,CAAC;AAZD,8BAYC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-search",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Plugin for centralizing search in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -20,11 +20,29 @@
|
|
|
20
20
|
"module": "esm/index.js",
|
|
21
21
|
"main": "lib/index.js",
|
|
22
22
|
"typings": "lib/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./esm/index.js",
|
|
26
|
+
"require": "./lib/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./esm/*": {
|
|
29
|
+
"import": "./esm/*"
|
|
30
|
+
},
|
|
31
|
+
"./lib/*": {
|
|
32
|
+
"require": "./lib/*"
|
|
33
|
+
},
|
|
34
|
+
"./_/*": {
|
|
35
|
+
"import": "./esm/*.js",
|
|
36
|
+
"require": "./lib/*.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
23
40
|
"sideEffects": false,
|
|
24
41
|
"files": [
|
|
25
42
|
"esm",
|
|
26
43
|
"lib",
|
|
27
|
-
"src"
|
|
44
|
+
"src",
|
|
45
|
+
"piral-search.min.js"
|
|
28
46
|
],
|
|
29
47
|
"repository": {
|
|
30
48
|
"type": "git",
|
|
@@ -34,17 +52,22 @@
|
|
|
34
52
|
"url": "https://github.com/smapiot/piral/issues"
|
|
35
53
|
},
|
|
36
54
|
"scripts": {
|
|
37
|
-
"
|
|
55
|
+
"cleanup": "rimraf esm lib piral-search.min.js",
|
|
56
|
+
"build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext",
|
|
57
|
+
"build:bundle": "esbuild src/index.ts --outfile=piral-search.min.js --bundle --external:piral-core --external:react --minify --global-name=piralSearch",
|
|
38
58
|
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
39
59
|
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
40
60
|
"typedoc": "typedoc --json ../../../docs/types/piral-search.json src --exclude \"src/**/*.test.*\"",
|
|
41
61
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
42
62
|
},
|
|
43
63
|
"devDependencies": {
|
|
44
|
-
"
|
|
64
|
+
"@types/react": "^18.0.0",
|
|
65
|
+
"piral-core": "^1.0.0",
|
|
66
|
+
"react": "^18.0.0"
|
|
45
67
|
},
|
|
46
68
|
"peerDependencies": {
|
|
47
|
-
"piral-core": "
|
|
69
|
+
"piral-core": "0.14.x || 0.15.x",
|
|
70
|
+
"react": ">=16.8.0"
|
|
48
71
|
},
|
|
49
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
|
|
50
73
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var piralSearch=(()=>{var re=Object.create;var y=Object.defineProperty,te=Object.defineProperties,ae=Object.getOwnPropertyDescriptor,oe=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var B=(e,r,a)=>r in e?y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,n=(e,r)=>{for(var a in r||(r={}))V.call(r,a)&&B(e,a,r[a]);if(v)for(var a of v(r))z.call(r,a)&&B(e,a,r[a]);return e},c=(e,r)=>te(e,oe(r)),J=e=>y(e,"__esModule",{value:!0});var p=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(r,a)=>(typeof require!="undefined"?require:r)[a]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var H=(e,r)=>{var a={};for(var t in e)V.call(e,t)&&r.indexOf(t)<0&&(a[t]=e[t]);if(e!=null&&v)for(var t of v(e))r.indexOf(t)<0&&z.call(e,t)&&(a[t]=e[t]);return a};var ne=(e,r)=>{J(e);for(var a in r)y(e,a,{get:r[a],enumerable:!0})},ce=(e,r,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of ie(r))!V.call(e,t)&&t!=="default"&&y(e,t,{get:()=>r[t],enumerable:!(a=ae(r,t))||a.enumerable});return e},u=e=>ce(J(y(e!=null?re(se(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var de={};ne(de,{PiralSearchContainer:()=>O,PiralSearchInput:()=>k,PiralSearchResult:()=>N,Search:()=>j,SearchInput:()=>$,createSearchApi:()=>fe,useSearch:()=>_});var D=u(p("react")),l=u(p("piral-core"));var m=u(p("piral-core"));function le(e,r){return r}function L(e={}){let{emptyTrigger:r=!1,filter:a=le}=e;return{setSearchInput(t,o){t.dispatch(s=>c(n({},s),{search:c(n({},s.search),{input:o})}))},triggerSearch(t,o,s=!1){let i=t.readState(f=>f.registry.searchProviders),{input:S,results:T}=t.readState(f=>f.search),{loading:R}=T;if(o===void 0&&(o=S),S!==o||!R){let f=a(o,Object.keys(i)),h=f.filter(d=>!i[d].onlyImmediate||s),P=(r||!!o)&&h.length>0;if(t.resetSearchResults(o,P),P){let d=h.length,C=!0,w={query:o,immediate:s};return h.forEach(E=>{i[E].search(w).then(F=>{C&&t.appendSearchResults(F,--d==0)},F=>{console.warn(F),C&&--d==0&&t.appendSearchResults([],!0)})}),()=>{C=!1,h.forEach(E=>i[E].cancel()),t.appendSearchResults([],P)}}else o||f.forEach(d=>i[d].clear())}return()=>{}},resetSearchResults(t,o,s){t.dispatch(i=>c(n({},i),{search:{input:o,results:{loading:s,items:[]}}}))},appendSearchResults(t,o,s){t.dispatch(i=>c(n({},i),{search:c(n({},i.search),{results:{loading:!s,items:(0,m.appendItems)(i.search.results.items,o)}})}))},prependSearchResults(t,o,s){t.dispatch(i=>c(n({},i),{search:c(n({},i.search),{results:{loading:!s,items:(0,m.prependItems)(i.search.results.items,o)}})}))},registerSearchProvider(t,o,s){t.dispatch(i=>c(n({},i),{registry:c(n({},i.registry),{searchProviders:(0,m.withKey)(i.registry.searchProviders,o,s)})}))},unregisterSearchProvider(t,o){t.dispatch(s=>c(n({},s),{registry:c(n({},s.registry),{searchProviders:(0,m.withoutKey)(s.registry.searchProviders,o)})}))}}}var M=u(p("react")),K=u(p("piral-core")),U=e=>(0,K.defaultRender)(e.children),W=e=>(0,K.defaultRender)(e.children),X=e=>M.createElement("input",{onChange:r=>e.setValue(r.target.value),value:e.value});var Q=u(p("react")),Y=u(p("piral-core"));var b=u(p("piral-core")),O=(0,b.getPiralComponent)("SearchContainer"),k=(0,b.getPiralComponent)("SearchInput"),N=(0,b.getPiralComponent)("SearchResult");var j=()=>{let{loading:e,items:r}=(0,Y.useGlobalState)(a=>a.search.results);return Q.createElement(O,{loading:e},r.map((a,t)=>Q.createElement(N,{key:t},a)))};var q=u(p("react"));var x=u(p("react")),I=u(p("piral-core"));var A=u(p("react"));function Z(e,r=300){let[a,t]=(0,A.useState)(e);return(0,A.useEffect)(()=>{let o=setTimeout(()=>t(e),r);return()=>clearTimeout(o)},[e,r]),a}function _(e){let{setSearchInput:r,triggerSearch:a}=(0,I.useActions)(),t=(0,I.useGlobalState)(i=>i.search.input),o=Z(t,e),s=(0,x.useRef)(void 0);return(0,x.useEffect)(()=>{s.current&&s.current(),s.current=a(o,!1)},[o]),[t,r]}var $=()=>{let[e,r]=_();return q.createElement(k,{setValue:r,value:e})};function G(){}function ee(e,r,a={}){let S=a,{onlyImmediate:t=!1,onCancel:o=G,onClear:s=G}=S,i=H(S,["onlyImmediate","onCancel","onClear"]);return c(n({},i),{pilet:e,onlyImmediate:t,cancel:(0,l.isfunc)(o)?o:G,clear:(0,l.isfunc)(s)?s:G,search:r})}function he(e){let r={},a=0;for(let{search:t,settings:o}of e)r[`global-${a++}`]=ee(void 0,t,o);return r}function pe(e,r,a){if(typeof e=="string"||(0,D.isValidElement)(e))return e;{let t=(0,l.withApi)(a,e,r,"extension");return(0,D.createElement)(t)}}function ue(e,r,a){return(Array.isArray(e)?e:[e]).map(o=>pe(o,r,a))}function Se(e,r,a){return t=>c(n({},t),{components:n({SearchContainer:U,SearchInput:X,SearchResult:W},t.components),registry:c(n({},t.registry),{searchProviders:e}),search:{input:r,results:{loading:!1,items:a}}})}function fe(e={}){let s=e,{providers:r=[],results:a=[],query:t=""}=s,o=H(s,["providers","results","query"]);return i=>(i.defineActions(L(o)),i.dispatch((0,l.withAll)(Se(he(r),t,a),(0,l.withRootExtension)("piral-search",j),(0,l.withRootExtension)("piral-search-input",$))),(S,T)=>{let R=T.name,f=0;return{registerSearchProvider(h,g,P){typeof h!="string"&&(P=g,g=h,h=f++);let d=(0,l.buildName)(R,h);return i.registerSearchProvider(d,ee(R,C=>Promise.resolve(g(C,S)).then(w=>ue(w,S,i),()=>[]),P)),()=>S.unregisterSearchProvider(h)},unregisterSearchProvider(h){let g=(0,l.buildName)(R,h);i.unregisterSearchProvider(g)}}})}return de;})();
|