@difizen/libro-search-code-cell 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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/es/code-cell-search-protocol.d.ts +26 -0
- package/es/code-cell-search-protocol.d.ts.map +1 -0
- package/es/code-cell-search-protocol.js +3 -0
- package/es/code-cell-search-provider-contribution.d.ts +18 -0
- package/es/code-cell-search-provider-contribution.d.ts.map +1 -0
- package/es/code-cell-search-provider-contribution.js +64 -0
- package/es/code-cell-search-provider.d.ts +52 -0
- package/es/code-cell-search-provider.d.ts.map +1 -0
- package/es/code-cell-search-provider.js +430 -0
- package/es/code-editor-cell-search-provider.d.ts +138 -0
- package/es/code-editor-cell-search-provider.d.ts.map +1 -0
- package/es/code-editor-cell-search-provider.js +578 -0
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +4 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +30 -0
- package/es/search-highlighter.d.ts +58 -0
- package/es/search-highlighter.d.ts.map +1 -0
- package/es/search-highlighter.js +241 -0
- package/package.json +55 -0
- package/src/code-cell-search-protocol.ts +40 -0
- package/src/code-cell-search-provider-contribution.ts +39 -0
- package/src/code-cell-search-provider.ts +229 -0
- package/src/code-editor-cell-search-provider.ts +392 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +4 -0
- package/src/module.ts +46 -0
- package/src/search-highlighter.ts +207 -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,26 @@
|
|
|
1
|
+
import type { LibroCodeCellView } from '@difizen/libro-code-cell';
|
|
2
|
+
import type { IEditor, SearchMatch } from '@difizen/libro-code-editor';
|
|
3
|
+
import type { CellSearchProvider } from '@difizen/libro-search';
|
|
4
|
+
export type CodeEditorSearchHighlighterFactory = (editor: IEditor | undefined) => CodeEditorSearchHighlighter;
|
|
5
|
+
export declare const CodeEditorSearchHighlighterFactory: unique symbol;
|
|
6
|
+
export declare const CodeCellSearchOption: unique symbol;
|
|
7
|
+
export interface CodeCellSearchOption {
|
|
8
|
+
cell: LibroCodeCellView;
|
|
9
|
+
}
|
|
10
|
+
export declare const CodeCellSearchProviderFactory: unique symbol;
|
|
11
|
+
export type CodeCellSearchProviderFactory = (option: CodeCellSearchOption) => CellSearchProvider;
|
|
12
|
+
export interface CodeEditorSearchHighlighter {
|
|
13
|
+
/**
|
|
14
|
+
* The list of matches
|
|
15
|
+
*/
|
|
16
|
+
get matches(): SearchMatch[];
|
|
17
|
+
set matches(v: SearchMatch[]);
|
|
18
|
+
get currentIndex(): number | undefined;
|
|
19
|
+
set currentIndex(v: number | undefined);
|
|
20
|
+
setEditor: (editor: IEditor) => void;
|
|
21
|
+
clearHighlight: () => void;
|
|
22
|
+
endQuery: () => Promise<void>;
|
|
23
|
+
highlightNext: () => Promise<SearchMatch | undefined>;
|
|
24
|
+
highlightPrevious: () => Promise<SearchMatch | undefined>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=code-cell-search-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-search-protocol.d.ts","sourceRoot":"","sources":["../src/code-cell-search-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,kCAAkC,GAAG,CAC/C,MAAM,EAAE,OAAO,GAAG,SAAS,KACxB,2BAA2B,CAAC;AACjC,eAAO,MAAM,kCAAkC,eAE9C,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAiC,CAAC;AACnE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,eAAO,MAAM,6BAA6B,eAA0C,CAAC;AACrF,MAAM,MAAM,6BAA6B,GAAG,CAC1C,MAAM,EAAE,oBAAoB,KACzB,kBAAkB,CAAC;AAExB,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;IAC7B,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE;IAE9B,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAAC;IACvC,IAAI,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE;IAExC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAErC,cAAc,EAAE,MAAM,IAAI,CAAC;IAE3B,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9B,aAAa,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IACtD,iBAAiB,EAAE,MAAM,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;CAC3D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-core';
|
|
2
|
+
import { CellSearchProviderContribution } from '@difizen/libro-search';
|
|
3
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
4
|
+
import { CodeCellSearchProviderFactory } from './code-cell-search-protocol.js';
|
|
5
|
+
export declare class CodeCellSearchProviderContribution implements CellSearchProviderContribution {
|
|
6
|
+
viewManager: ViewManager;
|
|
7
|
+
providerfactory: CodeCellSearchProviderFactory;
|
|
8
|
+
canHandle: (cell: CellView) => 100 | 0;
|
|
9
|
+
factory(cell: CellView): import("@difizen/libro-search").CellSearchProvider;
|
|
10
|
+
/**
|
|
11
|
+
* Get an initial query value if applicable so that it can be entered
|
|
12
|
+
* into the search box as an initial query
|
|
13
|
+
*
|
|
14
|
+
* @returns Initial value used to populate the search box.
|
|
15
|
+
*/
|
|
16
|
+
getInitialQuery: (cell: CellView) => string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=code-cell-search-provider-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-search-provider-contribution.d.ts","sourceRoot":"","sources":["../src/code-cell-search-provider-contribution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAE/E,qBACa,kCACX,YAAW,8BAA8B;IAEpB,WAAW,EAAE,WAAW,CAAC;IAE9C,eAAe,EAAE,6BAA6B,CAAC;IAC/C,SAAS,SAAU,QAAQ,aAKzB;IACF,OAAO,CAAC,IAAI,EAAE,QAAQ;IAGtB;;;;;OAKG;IACH,eAAe,SAAU,QAAQ,KAAG,MAAM,CAOxC;CACH"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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, _dec3, _class, _class2, _descriptor, _descriptor2;
|
|
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 { LibroCodeCellView } from '@difizen/libro-code-cell';
|
|
12
|
+
import { CellSearchProviderContribution } from '@difizen/libro-search';
|
|
13
|
+
import { ViewManager } from '@difizen/mana-app';
|
|
14
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
15
|
+
import { CodeCellSearchProviderFactory } from "./code-cell-search-protocol.js";
|
|
16
|
+
export var CodeCellSearchProviderContribution = (_dec = singleton({
|
|
17
|
+
contrib: CellSearchProviderContribution
|
|
18
|
+
}), _dec2 = inject(ViewManager), _dec3 = inject(CodeCellSearchProviderFactory), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
19
|
+
function CodeCellSearchProviderContribution() {
|
|
20
|
+
_classCallCheck(this, CodeCellSearchProviderContribution);
|
|
21
|
+
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
22
|
+
_initializerDefineProperty(this, "providerfactory", _descriptor2, this);
|
|
23
|
+
this.canHandle = function (cell) {
|
|
24
|
+
if (cell instanceof LibroCodeCellView) {
|
|
25
|
+
return 100;
|
|
26
|
+
}
|
|
27
|
+
return 0;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Get an initial query value if applicable so that it can be entered
|
|
31
|
+
* into the search box as an initial query
|
|
32
|
+
*
|
|
33
|
+
* @returns Initial value used to populate the search box.
|
|
34
|
+
*/
|
|
35
|
+
this.getInitialQuery = function (cell) {
|
|
36
|
+
if (cell instanceof LibroCodeCellView) {
|
|
37
|
+
var _cell$editor;
|
|
38
|
+
var selection = (_cell$editor = cell.editor) === null || _cell$editor === void 0 ? void 0 : _cell$editor.getSelectionValue();
|
|
39
|
+
// if there are newlines, just return empty string
|
|
40
|
+
return (selection === null || selection === void 0 ? void 0 : selection.search(/\r?\n|\r/g)) === -1 ? selection : '';
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
_createClass(CodeCellSearchProviderContribution, [{
|
|
46
|
+
key: "factory",
|
|
47
|
+
value: function factory(cell) {
|
|
48
|
+
return this.providerfactory({
|
|
49
|
+
cell: cell
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}]);
|
|
53
|
+
return CodeCellSearchProviderContribution;
|
|
54
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
55
|
+
configurable: true,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
initializer: null
|
|
59
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "providerfactory", [_dec3], {
|
|
60
|
+
configurable: true,
|
|
61
|
+
enumerable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
initializer: null
|
|
64
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SearchMatch } from '@difizen/libro-code-editor';
|
|
2
|
+
import type { GenericSearchProvider, SearchFilters } from '@difizen/libro-search';
|
|
3
|
+
import { GenericSearchProviderFactory } from '@difizen/libro-search';
|
|
4
|
+
import { CodeCellSearchOption, CodeEditorSearchHighlighterFactory } from './code-cell-search-protocol.js';
|
|
5
|
+
import { CodeEditorCellSearchProvider } from './code-editor-cell-search-provider.js';
|
|
6
|
+
export declare class CodeCellSearchProvider extends CodeEditorCellSearchProvider {
|
|
7
|
+
protected genericSearchProviderFactory: GenericSearchProviderFactory;
|
|
8
|
+
protected outputsProvider: GenericSearchProvider[];
|
|
9
|
+
protected currentProviderIndex: number;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*
|
|
13
|
+
* @param cell Cell widget
|
|
14
|
+
*/
|
|
15
|
+
constructor(highlighterFactory: CodeEditorSearchHighlighterFactory, genericSearchProviderFactory: GenericSearchProviderFactory, option: CodeCellSearchOption);
|
|
16
|
+
/**
|
|
17
|
+
* Number of matches in the cell.
|
|
18
|
+
*/
|
|
19
|
+
get matchesCount(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Clear currently highlighted match.
|
|
22
|
+
*/
|
|
23
|
+
clearHighlight(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Dispose the search provider
|
|
26
|
+
*/
|
|
27
|
+
dispose(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Highlight the next match.
|
|
30
|
+
*
|
|
31
|
+
* @returns The next match if there is one.
|
|
32
|
+
*/
|
|
33
|
+
highlightNext(): Promise<SearchMatch | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Highlight the previous match.
|
|
36
|
+
*
|
|
37
|
+
* @returns The previous match if there is one.
|
|
38
|
+
*/
|
|
39
|
+
highlightPrevious(): Promise<SearchMatch | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the search using the provided options. Should update the UI to highlight
|
|
42
|
+
* all matches and "select" the first match.
|
|
43
|
+
*
|
|
44
|
+
* @param query A RegExp to be use to perform the search
|
|
45
|
+
* @param filters Filter parameters to pass to provider
|
|
46
|
+
*/
|
|
47
|
+
startQuery(query: RegExp | null, filters?: SearchFilters): Promise<void>;
|
|
48
|
+
endQuery(): Promise<void>;
|
|
49
|
+
refresh(): Promise<void>;
|
|
50
|
+
protected setupOutputProvider: () => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=code-cell-search-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-cell-search-provider.d.ts","sourceRoot":"","sources":["../src/code-cell-search-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAGrE,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EACnC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AAErF,qBACa,sBAAuB,SAAQ,4BAA4B;IACtE,SAAS,CAAC,4BAA4B,EAAE,4BAA4B,CAAC;IAC7D,SAAS,CAAC,eAAe,EAAE,qBAAqB,EAAE,CAAC;IACnD,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAC/C;;;;OAIG;gBAGD,kBAAkB,EAAE,kCAAkC,EAEtD,4BAA4B,EAAE,4BAA4B,EAC5B,MAAM,EAAE,oBAAoB;IAyB5D;;OAEG;IACH,IAAa,YAAY,IAAI,MAAM,CAYlC;IAED;;OAEG;IACY,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9C;;OAEG;IACM,OAAO,IAAI,IAAI;IAWxB;;;;OAIG;IACY,aAAa,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAqChE;;;;OAIG;IACY,iBAAiB,IAAI,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAqCpE;;;;;;OAMG;IACY,UAAU,CACvB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC;IAYD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC,OAAO;IAMb,SAAS,CAAC,mBAAmB,sBAc3B;CACH"}
|