@difizen/libro-search 0.0.0-snapshot-20241017072317

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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/abstract-search-provider.d.ts +114 -0
  4. package/es/abstract-search-provider.d.ts.map +1 -0
  5. package/es/abstract-search-provider.js +126 -0
  6. package/es/index.d.ts +10 -0
  7. package/es/index.d.ts.map +1 -0
  8. package/es/index.js +9 -0
  9. package/es/index.less +109 -0
  10. package/es/libro-cell-search-provider.d.ts +10 -0
  11. package/es/libro-cell-search-provider.d.ts.map +1 -0
  12. package/es/libro-cell-search-provider.js +54 -0
  13. package/es/libro-search-engine-html.d.ts +3 -0
  14. package/es/libro-search-engine-html.d.ts.map +1 -0
  15. package/es/libro-search-engine-html.js +59 -0
  16. package/es/libro-search-engine-text.d.ts +10 -0
  17. package/es/libro-search-engine-text.d.ts.map +1 -0
  18. package/es/libro-search-engine-text.js +32 -0
  19. package/es/libro-search-generic-provider.d.ts +109 -0
  20. package/es/libro-search-generic-provider.d.ts.map +1 -0
  21. package/es/libro-search-generic-provider.js +504 -0
  22. package/es/libro-search-manager.d.ts +22 -0
  23. package/es/libro-search-manager.d.ts.map +1 -0
  24. package/es/libro-search-manager.js +100 -0
  25. package/es/libro-search-model.d.ts +111 -0
  26. package/es/libro-search-model.d.ts.map +1 -0
  27. package/es/libro-search-model.js +410 -0
  28. package/es/libro-search-protocol.d.ts +164 -0
  29. package/es/libro-search-protocol.d.ts.map +1 -0
  30. package/es/libro-search-protocol.js +31 -0
  31. package/es/libro-search-provider.d.ts +143 -0
  32. package/es/libro-search-provider.d.ts.map +1 -0
  33. package/es/libro-search-provider.js +821 -0
  34. package/es/libro-search-utils.d.ts +25 -0
  35. package/es/libro-search-utils.d.ts.map +1 -0
  36. package/es/libro-search-utils.js +89 -0
  37. package/es/libro-search-view.d.ts +61 -0
  38. package/es/libro-search-view.d.ts.map +1 -0
  39. package/es/libro-search-view.js +590 -0
  40. package/es/module.d.ts +4 -0
  41. package/es/module.d.ts.map +1 -0
  42. package/es/module.js +35 -0
  43. package/package.json +67 -0
  44. package/src/abstract-search-provider.ts +159 -0
  45. package/src/index.less +109 -0
  46. package/src/index.spec.ts +11 -0
  47. package/src/index.ts +9 -0
  48. package/src/libro-cell-search-provider.ts +39 -0
  49. package/src/libro-search-engine-html.ts +74 -0
  50. package/src/libro-search-engine-text.ts +34 -0
  51. package/src/libro-search-generic-provider.ts +327 -0
  52. package/src/libro-search-manager.ts +87 -0
  53. package/src/libro-search-model.ts +265 -0
  54. package/src/libro-search-protocol.ts +194 -0
  55. package/src/libro-search-provider.ts +552 -0
  56. package/src/libro-search-utils.spec.ts +38 -0
  57. package/src/libro-search-utils.ts +85 -0
  58. package/src/libro-search-view.tsx +464 -0
  59. 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,114 @@
1
+ import type { SearchMatch } from '@difizen/libro-code-editor';
2
+ import type { Event } from '@difizen/mana-app';
3
+ import type { View } from '@difizen/mana-app';
4
+ import { Emitter } from '@difizen/mana-app';
5
+ import type { SearchFilter, SearchFilters, SearchProvider } from './libro-search-protocol.js';
6
+ /**
7
+ * Abstract class implementing the search provider interface.
8
+ */
9
+ export declare abstract class AbstractSearchProvider implements SearchProvider {
10
+ protected _stateChanged: Emitter<void>;
11
+ protected _disposed: boolean;
12
+ protected view: View;
13
+ get disposed(): boolean;
14
+ /**
15
+ * Constructor
16
+ */
17
+ constructor(option: {
18
+ view: View;
19
+ });
20
+ /**
21
+ * Signal indicating that something in the search has changed, so the UI should update
22
+ */
23
+ get stateChanged(): Event<void>;
24
+ /**
25
+ * The current index of the selected match.
26
+ */
27
+ get currentMatchIndex(): number | undefined;
28
+ /**
29
+ * Whether the search provider is disposed or not.
30
+ */
31
+ get isDisposed(): boolean;
32
+ /**
33
+ * The number of matches.
34
+ */
35
+ get matchesCount(): number | undefined;
36
+ /**
37
+ * Set to true if the widget under search is read-only, false
38
+ * if it is editable. Will be used to determine whether to show
39
+ * the replace option.
40
+ */
41
+ abstract get isReadOnly(): boolean;
42
+ /**
43
+ * Dispose of the resources held by the search provider.
44
+ *
45
+ * #### Notes
46
+ * If the object's `dispose` method is called more than once, all
47
+ * calls made after the first will be a no-op.
48
+ *
49
+ * #### Undefined Behavior
50
+ * It is undefined behavior to use any functionality of the object
51
+ * after it has been disposed unless otherwise explicitly noted.
52
+ */
53
+ dispose(): void;
54
+ /**
55
+ * Get an initial query value if applicable so that it can be entered
56
+ * into the search box as an initial query
57
+ *
58
+ * @returns Initial value used to populate the search box.
59
+ */
60
+ getInitialQuery(): string;
61
+ /**
62
+ * Get the filters for the given provider.
63
+ *
64
+ * @returns The filters.
65
+ *
66
+ * ### Notes
67
+ * TODO For now it only supports boolean filters (represented with checkboxes)
68
+ */
69
+ getFilters(): Record<string, SearchFilter>;
70
+ /**
71
+ * Start a search using the provided options.
72
+ *
73
+ * @param query A RegExp to be use to perform the search
74
+ * @param filters Filter parameters to pass to provider
75
+ */
76
+ abstract startQuery(query: RegExp, filters: SearchFilters, highlightNext?: boolean): Promise<void>;
77
+ /**
78
+ * Stop a search and clear any internal state of ssthe search provider.
79
+ */
80
+ abstract endQuery(): Promise<void>;
81
+ /**
82
+ * Clear currently highlighted match.
83
+ */
84
+ abstract clearHighlight(): Promise<void>;
85
+ /**
86
+ * Highlight the next match.
87
+ *
88
+ * @returns The next match if available
89
+ */
90
+ abstract highlightNext(): Promise<SearchMatch | undefined>;
91
+ /**
92
+ * Highlight the previous match.
93
+ *
94
+ * @returns The previous match if available.
95
+ */
96
+ abstract highlightPrevious(): Promise<SearchMatch | undefined>;
97
+ /**
98
+ * Replace the currently selected match with the provided text
99
+ *
100
+ * @param newText The replacement text
101
+ *
102
+ * @returns A promise that resolves with a boolean indicating whether a replace occurred.
103
+ */
104
+ abstract replaceCurrentMatch(newText: string): Promise<boolean>;
105
+ /**
106
+ * Replace all matches in the widget with the provided text
107
+ *
108
+ * @param newText The replacement text
109
+ *
110
+ * @returns A promise that resolves with a boolean indicating whether a replace occurred.
111
+ */
112
+ abstract replaceAllMatches(newText: string): Promise<boolean>;
113
+ }
114
+ //# 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,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,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,cAAc,EACf,MAAM,4BAA4B,CAAC;AACpC;;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(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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,109 @@
1
+ .libro-search-overlay {
2
+ position: absolute;
3
+ top: 0;
4
+ right: 0;
5
+ z-index: 2000;
6
+ background-color: var(--mana-color-bg-elevated);
7
+ box-shadow: 0 2px 2px 0 #7c68681a;
8
+ }
9
+
10
+ .libro-search-content {
11
+ display: flex;
12
+ align-items: center;
13
+ min-width: 320px;
14
+ padding: 2px 6px;
15
+ }
16
+
17
+ .libro-search-row {
18
+ display: flex;
19
+ align-items: center;
20
+ height: 32px;
21
+
22
+ input {
23
+ margin-right: 4px;
24
+ }
25
+
26
+ .ant-btn {
27
+ margin-left: 4px;
28
+ border: none;
29
+ box-shadow: none;
30
+ }
31
+ }
32
+
33
+ .libro-search-replace-toggle {
34
+ display: flex;
35
+ align-items: center;
36
+ height: 100%;
37
+ margin-right: 4px;
38
+ padding: 4px;
39
+ cursor: pointer;
40
+
41
+ &:hover {
42
+ background-color: var(--mana-activityBar-background);
43
+ }
44
+ }
45
+
46
+ .libro-search-input {
47
+ flex: 1;
48
+ align-items: center;
49
+
50
+ .ant-input-affix-wrapper-sm {
51
+ margin-right: 4px;
52
+ }
53
+ }
54
+
55
+ .libro-search-input-suffix {
56
+ span {
57
+ margin-left: 4px;
58
+ padding: 2px;
59
+ cursor: pointer;
60
+
61
+ &:hover {
62
+ background-color: var(--mana-activityBar-background);
63
+ }
64
+ }
65
+
66
+ .libro-search-input-suffix-active {
67
+ background-color: var(--mana-activityBar-background);
68
+ }
69
+ }
70
+
71
+ .libro-search-index {
72
+ display: flex;
73
+ align-items: center;
74
+ justify-content: center;
75
+ width: 50px;
76
+ margin-right: 16px;
77
+ margin-left: 4px;
78
+ }
79
+
80
+ .libro-search-action {
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: space-between;
84
+ }
85
+
86
+ .libro-search-replace-toggle-icon {
87
+ font-size: 12px;
88
+ transition: transform 0.2s linear;
89
+ }
90
+
91
+ .libro-search-replace-toggle-replace-icon {
92
+ transform: rotate(90deg);
93
+ }
94
+
95
+ .libro-search-input-area {
96
+ flex: 1;
97
+ }
98
+
99
+ .libro-selectedtext {
100
+ background-color: rgb(168, 172, 149) !important;
101
+
102
+ span {
103
+ background-color: rgb(168, 172, 149) !important;
104
+ }
105
+ }
106
+
107
+ mark.libro-searching {
108
+ padding: 0;
109
+ }
@@ -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(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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,3 @@
1
+ import type { HTMLSearchMatch } from './libro-search-protocol.js';
2
+ export declare const searchInHTML: (query: RegExp, rootNode: Node) => Promise<HTMLSearchMatch[]>;
3
+ //# sourceMappingURL=libro-search-engine-html.d.ts.map
@@ -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(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
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 '@difizen/libro-code-editor';
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
+ };