@difizen/libro-search 0.0.2-alpha.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 +21 -0
- package/README.md +1 -0
- package/es/abstract-search-provider.d.ts +113 -0
- package/es/abstract-search-provider.d.ts.map +1 -0
- package/es/abstract-search-provider.js +126 -0
- package/es/index.d.ts +10 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +9 -0
- package/es/index.less +107 -0
- package/es/libro-cell-search-provider.d.ts +10 -0
- package/es/libro-cell-search-provider.d.ts.map +1 -0
- package/es/libro-cell-search-provider.js +54 -0
- package/es/libro-search-engine-html.d.ts +3 -0
- package/es/libro-search-engine-html.d.ts.map +1 -0
- package/es/libro-search-engine-html.js +59 -0
- package/es/libro-search-engine-text.d.ts +10 -0
- package/es/libro-search-engine-text.d.ts.map +1 -0
- package/es/libro-search-engine-text.js +32 -0
- package/es/libro-search-generic-provider.d.ts +107 -0
- package/es/libro-search-generic-provider.d.ts.map +1 -0
- package/es/libro-search-generic-provider.js +467 -0
- package/es/libro-search-manager.d.ts +22 -0
- package/es/libro-search-manager.d.ts.map +1 -0
- package/es/libro-search-manager.js +102 -0
- package/es/libro-search-model.d.ts +111 -0
- package/es/libro-search-model.d.ts.map +1 -0
- package/es/libro-search-model.js +395 -0
- package/es/libro-search-protocol.d.ts +176 -0
- package/es/libro-search-protocol.d.ts.map +1 -0
- package/es/libro-search-protocol.js +36 -0
- package/es/libro-search-provider.d.ts +138 -0
- package/es/libro-search-provider.d.ts.map +1 -0
- package/es/libro-search-provider.js +759 -0
- package/es/libro-search-utils.d.ts +25 -0
- package/es/libro-search-utils.d.ts.map +1 -0
- package/es/libro-search-utils.js +85 -0
- package/es/libro-search-view.d.ts +59 -0
- package/es/libro-search-view.d.ts.map +1 -0
- package/es/libro-search-view.js +455 -0
- package/es/module.d.ts +4 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +35 -0
- package/package.json +66 -0
- package/src/abstract-search-provider.ts +160 -0
- package/src/index.less +107 -0
- package/src/index.ts +9 -0
- package/src/libro-cell-search-provider.ts +39 -0
- package/src/libro-search-engine-html.ts +74 -0
- package/src/libro-search-engine-text.ts +34 -0
- package/src/libro-search-generic-provider.ts +303 -0
- package/src/libro-search-manager.ts +86 -0
- package/src/libro-search-model.ts +266 -0
- package/src/libro-search-protocol.ts +209 -0
- package/src/libro-search-provider.ts +507 -0
- package/src/libro-search-utils.spec.ts +37 -0
- package/src/libro-search-utils.ts +83 -0
- package/src/libro-search-view.tsx +404 -0
- package/src/module.ts +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Difizen Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# libro shared model
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Event } from '@difizen/mana-app';
|
|
2
|
+
import type { View } from '@difizen/mana-app';
|
|
3
|
+
import { Emitter } from '@difizen/mana-app';
|
|
4
|
+
import type { SearchFilter, SearchFilters, SearchMatch, SearchProvider } from './libro-search-protocol.js';
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class implementing the search provider interface.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class AbstractSearchProvider implements SearchProvider {
|
|
9
|
+
protected _stateChanged: Emitter<void>;
|
|
10
|
+
protected _disposed: boolean;
|
|
11
|
+
protected view: View;
|
|
12
|
+
get disposed(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Constructor
|
|
15
|
+
*/
|
|
16
|
+
constructor(option: {
|
|
17
|
+
view: View;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Signal indicating that something in the search has changed, so the UI should update
|
|
21
|
+
*/
|
|
22
|
+
get stateChanged(): Event<void>;
|
|
23
|
+
/**
|
|
24
|
+
* The current index of the selected match.
|
|
25
|
+
*/
|
|
26
|
+
get currentMatchIndex(): number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the search provider is disposed or not.
|
|
29
|
+
*/
|
|
30
|
+
get isDisposed(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The number of matches.
|
|
33
|
+
*/
|
|
34
|
+
get matchesCount(): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Set to true if the widget under search is read-only, false
|
|
37
|
+
* if it is editable. Will be used to determine whether to show
|
|
38
|
+
* the replace option.
|
|
39
|
+
*/
|
|
40
|
+
abstract get isReadOnly(): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Dispose of the resources held by the search provider.
|
|
43
|
+
*
|
|
44
|
+
* #### Notes
|
|
45
|
+
* If the object's `dispose` method is called more than once, all
|
|
46
|
+
* calls made after the first will be a no-op.
|
|
47
|
+
*
|
|
48
|
+
* #### Undefined Behavior
|
|
49
|
+
* It is undefined behavior to use any functionality of the object
|
|
50
|
+
* after it has been disposed unless otherwise explicitly noted.
|
|
51
|
+
*/
|
|
52
|
+
dispose(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get an initial query value if applicable so that it can be entered
|
|
55
|
+
* into the search box as an initial query
|
|
56
|
+
*
|
|
57
|
+
* @returns Initial value used to populate the search box.
|
|
58
|
+
*/
|
|
59
|
+
getInitialQuery(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Get the filters for the given provider.
|
|
62
|
+
*
|
|
63
|
+
* @returns The filters.
|
|
64
|
+
*
|
|
65
|
+
* ### Notes
|
|
66
|
+
* TODO For now it only supports boolean filters (represented with checkboxes)
|
|
67
|
+
*/
|
|
68
|
+
getFilters(): Record<string, SearchFilter>;
|
|
69
|
+
/**
|
|
70
|
+
* Start a search using the provided options.
|
|
71
|
+
*
|
|
72
|
+
* @param query A RegExp to be use to perform the search
|
|
73
|
+
* @param filters Filter parameters to pass to provider
|
|
74
|
+
*/
|
|
75
|
+
abstract startQuery(query: RegExp, filters: SearchFilters, highlightNext?: boolean): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Stop a search and clear any internal state of ssthe search provider.
|
|
78
|
+
*/
|
|
79
|
+
abstract endQuery(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Clear currently highlighted match.
|
|
82
|
+
*/
|
|
83
|
+
abstract clearHighlight(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Highlight the next match.
|
|
86
|
+
*
|
|
87
|
+
* @returns The next match if available
|
|
88
|
+
*/
|
|
89
|
+
abstract highlightNext(): Promise<SearchMatch | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Highlight the previous match.
|
|
92
|
+
*
|
|
93
|
+
* @returns The previous match if available.
|
|
94
|
+
*/
|
|
95
|
+
abstract highlightPrevious(): Promise<SearchMatch | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Replace the currently selected match with the provided text
|
|
98
|
+
*
|
|
99
|
+
* @param newText The replacement text
|
|
100
|
+
*
|
|
101
|
+
* @returns A promise that resolves with a boolean indicating whether a replace occurred.
|
|
102
|
+
*/
|
|
103
|
+
abstract replaceCurrentMatch(newText: string): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Replace all matches in the widget with the provided text
|
|
106
|
+
*
|
|
107
|
+
* @param newText The replacement text
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves with a boolean indicating whether a replace occurred.
|
|
110
|
+
*/
|
|
111
|
+
abstract replaceAllMatches(newText: string): Promise<boolean>;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=abstract-search-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-search-provider.d.ts","sourceRoot":"","sources":["../src/abstract-search-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,8BACsB,sBAAuB,YAAW,cAAc;IAEpE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,CAAiB;IACvD,SAAS,CAAC,SAAS,UAAS;IAC5B,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD;;OAEG;gBACS,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE;IAIlC;;OAEG;IACH,IAAI,YAAY,IAAI,KAAK,CAAC,IAAI,CAAC,CAE9B;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;;;OAIG;IACH,QAAQ,KAAK,UAAU,IAAI,OAAO,CAAC;IAEnC;;;;;;;;;;OAUG;IACH,OAAO,IAAI,IAAI;IAOf;;;;;OAKG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;;;;OAOG;IACH,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAI1C;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,EACtB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,IAAI,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAExC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAE1D;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAE9D;;;;;;OAMG;IACH,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAE/D;;;;;;OAMG;IACH,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAC9D"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
import { Emitter } from '@difizen/mana-app';
|
|
9
|
+
import { transient } from '@difizen/mana-app';
|
|
10
|
+
/**
|
|
11
|
+
* Abstract class implementing the search provider interface.
|
|
12
|
+
*/
|
|
13
|
+
export var AbstractSearchProvider = (_dec = transient(), _dec(_class = /*#__PURE__*/function () {
|
|
14
|
+
/**
|
|
15
|
+
* Constructor
|
|
16
|
+
*/
|
|
17
|
+
function AbstractSearchProvider(option) {
|
|
18
|
+
_classCallCheck(this, AbstractSearchProvider);
|
|
19
|
+
// Needs to be protected so subclass can emit the signal too.
|
|
20
|
+
this._stateChanged = new Emitter();
|
|
21
|
+
this._disposed = false;
|
|
22
|
+
this.view = option.view;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Signal indicating that something in the search has changed, so the UI should update
|
|
27
|
+
*/
|
|
28
|
+
_createClass(AbstractSearchProvider, [{
|
|
29
|
+
key: "disposed",
|
|
30
|
+
get: function get() {
|
|
31
|
+
return this._disposed;
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
key: "stateChanged",
|
|
35
|
+
get: function get() {
|
|
36
|
+
return this._stateChanged.event;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The current index of the selected match.
|
|
41
|
+
*/
|
|
42
|
+
}, {
|
|
43
|
+
key: "currentMatchIndex",
|
|
44
|
+
get: function get() {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether the search provider is disposed or not.
|
|
50
|
+
*/
|
|
51
|
+
}, {
|
|
52
|
+
key: "isDisposed",
|
|
53
|
+
get: function get() {
|
|
54
|
+
return this._disposed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The number of matches.
|
|
59
|
+
*/
|
|
60
|
+
}, {
|
|
61
|
+
key: "matchesCount",
|
|
62
|
+
get: function get() {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set to true if the widget under search is read-only, false
|
|
68
|
+
* if it is editable. Will be used to determine whether to show
|
|
69
|
+
* the replace option.
|
|
70
|
+
*/
|
|
71
|
+
}, {
|
|
72
|
+
key: "dispose",
|
|
73
|
+
value:
|
|
74
|
+
/**
|
|
75
|
+
* Dispose of the resources held by the search provider.
|
|
76
|
+
*
|
|
77
|
+
* #### Notes
|
|
78
|
+
* If the object's `dispose` method is called more than once, all
|
|
79
|
+
* calls made after the first will be a no-op.
|
|
80
|
+
*
|
|
81
|
+
* #### Undefined Behavior
|
|
82
|
+
* It is undefined behavior to use any functionality of the object
|
|
83
|
+
* after it has been disposed unless otherwise explicitly noted.
|
|
84
|
+
*/
|
|
85
|
+
function dispose() {
|
|
86
|
+
if (this._disposed) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this._disposed = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get an initial query value if applicable so that it can be entered
|
|
94
|
+
* into the search box as an initial query
|
|
95
|
+
*
|
|
96
|
+
* @returns Initial value used to populate the search box.
|
|
97
|
+
*/
|
|
98
|
+
}, {
|
|
99
|
+
key: "getInitialQuery",
|
|
100
|
+
value: function getInitialQuery() {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the filters for the given provider.
|
|
106
|
+
*
|
|
107
|
+
* @returns The filters.
|
|
108
|
+
*
|
|
109
|
+
* ### Notes
|
|
110
|
+
* TODO For now it only supports boolean filters (represented with checkboxes)
|
|
111
|
+
*/
|
|
112
|
+
}, {
|
|
113
|
+
key: "getFilters",
|
|
114
|
+
value: function getFilters() {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Start a search using the provided options.
|
|
120
|
+
*
|
|
121
|
+
* @param query A RegExp to be use to perform the search
|
|
122
|
+
* @param filters Filter parameters to pass to provider
|
|
123
|
+
*/
|
|
124
|
+
}]);
|
|
125
|
+
return AbstractSearchProvider;
|
|
126
|
+
}()) || _class);
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './module.js';
|
|
2
|
+
export * from './libro-search-protocol.js';
|
|
3
|
+
export * from './libro-search-utils.js';
|
|
4
|
+
export * from './libro-search-manager.js';
|
|
5
|
+
export * from './libro-search-engine-text.js';
|
|
6
|
+
export * from './libro-search-engine-html.js';
|
|
7
|
+
export * from './libro-search-generic-provider.js';
|
|
8
|
+
export * from './libro-search-view.js';
|
|
9
|
+
export * from './abstract-search-provider.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC"}
|
package/es/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./module.js";
|
|
2
|
+
export * from "./libro-search-protocol.js";
|
|
3
|
+
export * from "./libro-search-utils.js";
|
|
4
|
+
export * from "./libro-search-manager.js";
|
|
5
|
+
export * from "./libro-search-engine-text.js";
|
|
6
|
+
export * from "./libro-search-engine-html.js";
|
|
7
|
+
export * from "./libro-search-generic-provider.js";
|
|
8
|
+
export * from "./libro-search-view.js";
|
|
9
|
+
export * from "./abstract-search-provider.js";
|
package/es/index.less
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
.libro-search-overlay {
|
|
2
|
+
position: absolute;
|
|
3
|
+
top: 0;
|
|
4
|
+
right: 0;
|
|
5
|
+
box-shadow: 0 2px 2px 0 #7c68681a;
|
|
6
|
+
background-color: var(--mana-color-bg-elevated);
|
|
7
|
+
z-index: 2000;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.libro-search-content {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
padding: 2px 6px;
|
|
14
|
+
min-width: 320px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.libro-search-row {
|
|
18
|
+
height: 32px;
|
|
19
|
+
|
|
20
|
+
input {
|
|
21
|
+
margin-right: 4px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.ant-btn {
|
|
25
|
+
border: none;
|
|
26
|
+
box-shadow: none;
|
|
27
|
+
margin-left: 4px;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.libro-search-replace-toggle {
|
|
32
|
+
padding: 4px;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
height: 100%;
|
|
36
|
+
margin-right: 4px;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
|
|
39
|
+
&:hover {
|
|
40
|
+
background-color: var(--mana-activityBar-background);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.libro-search-input {
|
|
45
|
+
align-items: center;
|
|
46
|
+
flex: 1;
|
|
47
|
+
|
|
48
|
+
.ant-input-affix-wrapper-sm {
|
|
49
|
+
margin-right: 4px;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.libro-search-input-suffix {
|
|
54
|
+
span {
|
|
55
|
+
margin-left: 4px;
|
|
56
|
+
padding: 2px;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
|
|
59
|
+
&:hover {
|
|
60
|
+
background-color: var(--mana-activityBar-background);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.libro-search-input-suffix-active {
|
|
65
|
+
background-color: var(--mana-activityBar-background);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.libro-search-index {
|
|
70
|
+
// width: 24px;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
margin-left: 4px;
|
|
75
|
+
margin-right: 16px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.libro-search-action {
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
justify-content: space-between;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.libro-search-replace-toggle-icon {
|
|
85
|
+
font-size: 12px;
|
|
86
|
+
transition: transform 0.2s linear;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.libro-search-replace-toggle-replace-icon {
|
|
90
|
+
transform: rotate(90deg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.libro-search-input-area {
|
|
94
|
+
flex: 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.libro-selectedtext {
|
|
98
|
+
background-color: rgb(255, 225, 0);
|
|
99
|
+
|
|
100
|
+
span {
|
|
101
|
+
background-color: rgb(255, 225, 0);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
mark.libro-searching {
|
|
106
|
+
padding: 0;
|
|
107
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-core';
|
|
2
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
3
|
+
import { CellSearchProviderContribution } from './libro-search-protocol.js';
|
|
4
|
+
export declare class LibroCellSearchProvider {
|
|
5
|
+
protected providerContribution: Contribution.Provider<CellSearchProviderContribution>;
|
|
6
|
+
createCellSearchProvider(cell: CellView): import("./libro-search-protocol.js").CellSearchProvider | undefined;
|
|
7
|
+
getInitialQuery: (cell: CellView) => string;
|
|
8
|
+
protected findCellSearchProviderContribution(cell: CellView): CellSearchProviderContribution | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=libro-cell-search-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-cell-search-provider.d.ts","sourceRoot":"","sources":["../src/libro-cell-search-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E,qBACa,uBAAuB;IAElC,SAAS,CAAC,oBAAoB,EAAE,YAAY,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC;IAEtF,wBAAwB,CAAC,IAAI,EAAE,QAAQ;IAQvC,eAAe,SAAU,QAAQ,KAAG,MAAM,CAMxC;IAEF,SAAS,CAAC,kCAAkC,CAC1C,IAAI,EAAE,QAAQ,GACb,8BAA8B,GAAG,SAAS;CAQ9C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _dec, _dec2, _class, _class2, _descriptor;
|
|
3
|
+
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
10
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
11
|
+
import { Priority } from '@difizen/mana-app';
|
|
12
|
+
import { contrib, transient } from '@difizen/mana-app';
|
|
13
|
+
import { CellSearchProviderContribution } from "./libro-search-protocol.js";
|
|
14
|
+
export var LibroCellSearchProvider = (_dec = transient(), _dec2 = contrib(CellSearchProviderContribution), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
15
|
+
function LibroCellSearchProvider() {
|
|
16
|
+
var _this = this;
|
|
17
|
+
_classCallCheck(this, LibroCellSearchProvider);
|
|
18
|
+
_initializerDefineProperty(this, "providerContribution", _descriptor, this);
|
|
19
|
+
this.getInitialQuery = function (cell) {
|
|
20
|
+
var ctrb = _this.findCellSearchProviderContribution(cell);
|
|
21
|
+
if (ctrb && ctrb.getInitialQuery) {
|
|
22
|
+
return ctrb.getInitialQuery(cell);
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
_createClass(LibroCellSearchProvider, [{
|
|
28
|
+
key: "createCellSearchProvider",
|
|
29
|
+
value: function createCellSearchProvider(cell) {
|
|
30
|
+
var ctrb = this.findCellSearchProviderContribution(cell);
|
|
31
|
+
if (ctrb) {
|
|
32
|
+
return ctrb.factory(cell);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "findCellSearchProviderContribution",
|
|
38
|
+
value: function findCellSearchProviderContribution(cell) {
|
|
39
|
+
var prioritized = Priority.sortSync(this.providerContribution.getContributions(), function (contribution) {
|
|
40
|
+
return contribution.canHandle(cell);
|
|
41
|
+
});
|
|
42
|
+
var sorted = prioritized.map(function (c) {
|
|
43
|
+
return c.value;
|
|
44
|
+
});
|
|
45
|
+
return sorted[0];
|
|
46
|
+
}
|
|
47
|
+
}]);
|
|
48
|
+
return LibroCellSearchProvider;
|
|
49
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "providerContribution", [_dec2], {
|
|
50
|
+
configurable: true,
|
|
51
|
+
enumerable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
initializer: null
|
|
54
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-search-engine-html.d.ts","sourceRoot":"","sources":["../src/libro-search-engine-html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA8BlE,eAAO,MAAM,YAAY,UAChB,MAAM,YACH,IAAI,KACb,QAAQ,eAAe,EAAE,CAuC3B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
/* eslint-disable no-param-reassign */
|
|
6
|
+
|
|
7
|
+
var UNSUPPORTED_ELEMENTS = ['BASE', 'HEAD', 'LINK', 'META', 'STYLE', 'TITLE', 'SVG', 'SOURCE', 'SCRIPT', 'BODY', 'AREA', 'AUDIO', 'IMG', 'MAP', 'TRACK', 'VIDEO', 'APPLET', 'EMBED', 'IFRAME', 'NOEMBED', 'OBJECT', 'PARAM', 'PICTURE', 'CANVAS', 'NOSCRIPT'];
|
|
8
|
+
export var searchInHTML = /*#__PURE__*/function () {
|
|
9
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(query, rootNode) {
|
|
10
|
+
var matches, walker, node, match;
|
|
11
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
12
|
+
while (1) switch (_context.prev = _context.next) {
|
|
13
|
+
case 0:
|
|
14
|
+
if (rootNode instanceof Node) {
|
|
15
|
+
_context.next = 3;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
console.warn('Unable to search with HTMLSearchEngine the provided object.', rootNode);
|
|
19
|
+
return _context.abrupt("return", []);
|
|
20
|
+
case 3:
|
|
21
|
+
if (!query.global) {
|
|
22
|
+
query = new RegExp(query.source, query.flags + 'g');
|
|
23
|
+
}
|
|
24
|
+
matches = [];
|
|
25
|
+
walker = document.createTreeWalker(rootNode, NodeFilter.SHOW_TEXT, {
|
|
26
|
+
acceptNode: function acceptNode(node) {
|
|
27
|
+
var parentElement = node.parentElement;
|
|
28
|
+
while (parentElement !== rootNode) {
|
|
29
|
+
if (UNSUPPORTED_ELEMENTS.includes(parentElement.nodeName)) {
|
|
30
|
+
return NodeFilter.FILTER_REJECT;
|
|
31
|
+
}
|
|
32
|
+
parentElement = parentElement.parentElement;
|
|
33
|
+
}
|
|
34
|
+
return query.test(node.textContent) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
node = null;
|
|
38
|
+
while ((node = walker.nextNode()) !== null) {
|
|
39
|
+
query.lastIndex = 0;
|
|
40
|
+
match = null;
|
|
41
|
+
while ((match = query.exec(node.textContent)) !== null) {
|
|
42
|
+
matches.push({
|
|
43
|
+
text: match[0],
|
|
44
|
+
position: match.index,
|
|
45
|
+
node: node
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return _context.abrupt("return", Promise.resolve(matches));
|
|
50
|
+
case 9:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}, _callee);
|
|
55
|
+
}));
|
|
56
|
+
return function searchInHTML(_x, _x2) {
|
|
57
|
+
return _ref.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SearchMatch } from './libro-search-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Search for regular expression matches in a string.
|
|
4
|
+
*
|
|
5
|
+
* @param query Query regular expression
|
|
6
|
+
* @param data String to look into
|
|
7
|
+
* @returns List of matches
|
|
8
|
+
*/
|
|
9
|
+
export declare const searchText: (query: RegExp, data: string) => Promise<SearchMatch[]>;
|
|
10
|
+
//# sourceMappingURL=libro-search-engine-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-search-engine-text.d.ts","sourceRoot":"","sources":["../src/libro-search-engine-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;;GAMG;AAEH,eAAO,MAAM,UAAU,UAAW,MAAM,QAAQ,MAAM,KAAG,QAAQ,WAAW,EAAE,CAuB7E,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search for regular expression matches in a string.
|
|
3
|
+
*
|
|
4
|
+
* @param query Query regular expression
|
|
5
|
+
* @param data String to look into
|
|
6
|
+
* @returns List of matches
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export var searchText = function searchText(query, data) {
|
|
10
|
+
var searchData = data;
|
|
11
|
+
var searchQuery = query;
|
|
12
|
+
if (typeof searchData !== 'string') {
|
|
13
|
+
try {
|
|
14
|
+
searchData = JSON.stringify(searchData);
|
|
15
|
+
} catch (reason) {
|
|
16
|
+
console.warn('Unable to search.', reason, searchData);
|
|
17
|
+
return Promise.resolve([]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!searchQuery.global) {
|
|
21
|
+
searchQuery = new RegExp(searchQuery.source, searchQuery.flags + 'g');
|
|
22
|
+
}
|
|
23
|
+
var matches = [];
|
|
24
|
+
var match = null;
|
|
25
|
+
while ((match = searchQuery.exec(data)) !== null) {
|
|
26
|
+
matches.push({
|
|
27
|
+
text: match[0],
|
|
28
|
+
position: match.index
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return Promise.resolve(matches);
|
|
32
|
+
};
|