@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
|
@@ -0,0 +1,102 @@
|
|
|
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, _dec3, _class, _class2, _descriptor, _descriptor2;
|
|
3
|
+
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; }
|
|
4
|
+
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); } }
|
|
5
|
+
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); }); }; }
|
|
6
|
+
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 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
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); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
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.'); }
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15
|
+
import { LibroCommandRegister, LibroExtensionSlotContribution } from '@difizen/libro-core';
|
|
16
|
+
import { ViewManager, CommandContribution, KeybindingContribution } from '@difizen/mana-app';
|
|
17
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
18
|
+
import { LibroSearchView } from "./libro-search-view.js";
|
|
19
|
+
export var LibroSearchToggleCommand = {
|
|
20
|
+
ShowLibroSearch: {
|
|
21
|
+
id: 'libro-search:toggle',
|
|
22
|
+
keybind: 'ctrlcmd+F'
|
|
23
|
+
}
|
|
24
|
+
// LibroSearchToggle: {
|
|
25
|
+
// id: 'libro-search:toogle',
|
|
26
|
+
// keybind: 'ctrlcmd+F',
|
|
27
|
+
// },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export var LibroSearchManager = (_dec = singleton({
|
|
31
|
+
contrib: [CommandContribution, KeybindingContribution, LibroExtensionSlotContribution]
|
|
32
|
+
}), _dec2 = inject(ViewManager), _dec3 = inject(LibroCommandRegister), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
33
|
+
function LibroSearchManager() {
|
|
34
|
+
var _this = this;
|
|
35
|
+
_classCallCheck(this, LibroSearchManager);
|
|
36
|
+
_initializerDefineProperty(this, "viewManager", _descriptor, this);
|
|
37
|
+
_initializerDefineProperty(this, "libroCommandRegister", _descriptor2, this);
|
|
38
|
+
this.viewMap = new Map();
|
|
39
|
+
this.slot = 'container';
|
|
40
|
+
this.factory = /*#__PURE__*/function () {
|
|
41
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(libro) {
|
|
42
|
+
var view;
|
|
43
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
44
|
+
while (1) switch (_context.prev = _context.next) {
|
|
45
|
+
case 0:
|
|
46
|
+
_context.next = 2;
|
|
47
|
+
return _this.viewManager.getOrCreateView(LibroSearchView, {
|
|
48
|
+
parentId: libro.id
|
|
49
|
+
});
|
|
50
|
+
case 2:
|
|
51
|
+
view = _context.sent;
|
|
52
|
+
view.libro = libro;
|
|
53
|
+
_this.viewMap.set(libro.id, view);
|
|
54
|
+
view.onDisposed(function () {
|
|
55
|
+
_this.viewMap.delete(libro.id);
|
|
56
|
+
});
|
|
57
|
+
return _context.abrupt("return", view);
|
|
58
|
+
case 7:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee);
|
|
63
|
+
}));
|
|
64
|
+
return function (_x) {
|
|
65
|
+
return _ref.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}();
|
|
68
|
+
this.showSearchView = function (libro) {
|
|
69
|
+
var _this$viewMap$get;
|
|
70
|
+
(_this$viewMap$get = _this.viewMap.get(libro.id)) === null || _this$viewMap$get === void 0 ? void 0 : _this$viewMap$get.show();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
_createClass(LibroSearchManager, [{
|
|
74
|
+
key: "registerKeybindings",
|
|
75
|
+
value: function registerKeybindings(keybindings) {
|
|
76
|
+
this.libroCommandRegister.registerKeybinds(keybindings, LibroSearchToggleCommand, false, false);
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "registerCommands",
|
|
80
|
+
value: function registerCommands(commands) {
|
|
81
|
+
var _this2 = this;
|
|
82
|
+
this.libroCommandRegister.registerLibroCommand(commands, LibroSearchToggleCommand.ShowLibroSearch, {
|
|
83
|
+
execute: function execute(_cell, libro, _position) {
|
|
84
|
+
if (libro) {
|
|
85
|
+
_this2.showSearchView(libro);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
return LibroSearchManager;
|
|
92
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec2], {
|
|
93
|
+
configurable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
initializer: null
|
|
97
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "libroCommandRegister", [_dec3], {
|
|
98
|
+
configurable: true,
|
|
99
|
+
enumerable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
initializer: null
|
|
102
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Disposable } from '@difizen/mana-app';
|
|
2
|
+
import { DisposableCollection, Emitter } from '@difizen/mana-app';
|
|
3
|
+
import type { SearchProvider } from './libro-search-protocol.js';
|
|
4
|
+
import type { SearchFilter, SearchFilters } from './libro-search-protocol.js';
|
|
5
|
+
import { LibroSearchUtils } from './libro-search-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Search in a document model.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LibroSearchModel implements Disposable {
|
|
10
|
+
utils: LibroSearchUtils;
|
|
11
|
+
protected _disposed?: boolean;
|
|
12
|
+
protected _caseSensitive: boolean;
|
|
13
|
+
protected parsingError: string;
|
|
14
|
+
protected _filters: SearchFilters;
|
|
15
|
+
protected _replaceText: string;
|
|
16
|
+
protected searchDebouncer: any;
|
|
17
|
+
protected _searchExpression: string;
|
|
18
|
+
protected _useRegex: boolean;
|
|
19
|
+
protected disposedEmitter: Emitter<void>;
|
|
20
|
+
protected searchProvider: SearchProvider;
|
|
21
|
+
protected toDispose: DisposableCollection;
|
|
22
|
+
get onDisposed(): import("@difizen/mana-app").Event<void>;
|
|
23
|
+
get disposed(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Search document model
|
|
26
|
+
* @param searchProvider Provider for the current document
|
|
27
|
+
* @param searchDebounceTime Debounce search time
|
|
28
|
+
*/
|
|
29
|
+
constructor(utils: LibroSearchUtils, searchProvider: SearchProvider, searchDebounceTime: number);
|
|
30
|
+
/**
|
|
31
|
+
* Whether the search is case sensitive or not.
|
|
32
|
+
*/
|
|
33
|
+
get caseSensitive(): boolean;
|
|
34
|
+
set caseSensitive(v: boolean);
|
|
35
|
+
/**
|
|
36
|
+
* Current highlighted match index.
|
|
37
|
+
*/
|
|
38
|
+
get currentIndex(): number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Filter values.
|
|
41
|
+
*/
|
|
42
|
+
get filters(): SearchFilters;
|
|
43
|
+
/**
|
|
44
|
+
* Filter definitions for the current provider.
|
|
45
|
+
*/
|
|
46
|
+
get filtersDefinition(): Record<string, SearchFilter>;
|
|
47
|
+
/**
|
|
48
|
+
* The initial query string.
|
|
49
|
+
*/
|
|
50
|
+
get initialQuery(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the document is read-only or not.
|
|
53
|
+
*/
|
|
54
|
+
get isReadOnly(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Replacement expression
|
|
57
|
+
*/
|
|
58
|
+
get replaceText(): string;
|
|
59
|
+
set replaceText(v: string);
|
|
60
|
+
/**
|
|
61
|
+
* Search expression
|
|
62
|
+
*/
|
|
63
|
+
get searchExpression(): string;
|
|
64
|
+
set searchExpression(v: string);
|
|
65
|
+
/**
|
|
66
|
+
* Total number of matches.
|
|
67
|
+
*/
|
|
68
|
+
get totalMatches(): number | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Whether to use regular expression or not.
|
|
71
|
+
*/
|
|
72
|
+
get useRegex(): boolean;
|
|
73
|
+
set useRegex(v: boolean);
|
|
74
|
+
/**
|
|
75
|
+
* Dispose the model.
|
|
76
|
+
*/
|
|
77
|
+
dispose(): void;
|
|
78
|
+
/**
|
|
79
|
+
* End the query.
|
|
80
|
+
*/
|
|
81
|
+
endQuery(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Highlight the next match.
|
|
84
|
+
*/
|
|
85
|
+
highlightNext(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Highlight the previous match
|
|
88
|
+
*/
|
|
89
|
+
highlightPrevious(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Refresh search
|
|
92
|
+
*/
|
|
93
|
+
refresh(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Replace all matches.
|
|
96
|
+
*/
|
|
97
|
+
replaceAllMatches(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Replace the current match.
|
|
100
|
+
*/
|
|
101
|
+
replaceCurrentMatch(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Set the value of a given filter.
|
|
104
|
+
*
|
|
105
|
+
* @param name Filter name
|
|
106
|
+
* @param v Filter value
|
|
107
|
+
*/
|
|
108
|
+
setFilter(_name: string, _v: boolean): Promise<void>;
|
|
109
|
+
protected updateSearch(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=libro-search-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-search-model.d.ts","sourceRoot":"","sources":["../src/libro-search-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,qBACa,gBAAiB,YAAW,UAAU;IACjD,KAAK,EAAE,gBAAgB,CAAC;IACxB,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAS;IACtC,SAAS,CAAC,cAAc,UAAS;IACjC,SAAS,CAAC,YAAY,SAAM;IAC5B,SAAS,CAAC,QAAQ,EAAE,aAAa,CAG/B;IACF,SAAS,CAAC,YAAY,SAAM;IAC5B,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC;IAC/B,SAAS,CAAC,iBAAiB,SAAM;IACjC,SAAS,CAAC,SAAS,UAAS;IAC5B,SAAS,CAAC,eAAe,gBAAuB;IAChD,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC;IACzC,SAAS,CAAC,SAAS,uBAA8B;IACjD,IAAI,UAAU,4CAEb;IAED,IAAI,QAAQ,YAEX;IACD;;;;OAIG;gBAEyB,KAAK,EAAE,gBAAgB,EACjD,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,MAAM;IAqB5B;;OAEG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IACD,IAAI,aAAa,CAAC,CAAC,EAAE,OAAO,EAK3B;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED;;OAEG;IACH,IAAI,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAEpD;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAKzB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IACD,IAAI,WAAW,CAAC,CAAC,EAAE,MAAM,EAIxB;IAED;;OAEG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IACD,IAAI,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAK7B;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAErC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,CAAC,EAAE,OAAO,EAKtB;IAED;;OAEG;IACH,OAAO,IAAI,IAAI;IAcf;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;OAEG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxC;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;;;;OAKG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;cAe1C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB9C"}
|
|
@@ -0,0 +1,395 @@
|
|
|
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 _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; }
|
|
4
|
+
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); } }
|
|
5
|
+
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); }); }; }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
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); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
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); }
|
|
11
|
+
import { DisposableCollection, Emitter } from '@difizen/mana-app';
|
|
12
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
13
|
+
import debounce from 'lodash.debounce';
|
|
14
|
+
import { LibroSearchUtils } from "./libro-search-utils.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Search in a document model.
|
|
18
|
+
*/
|
|
19
|
+
export var LibroSearchModel = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
20
|
+
/**
|
|
21
|
+
* Search document model
|
|
22
|
+
* @param searchProvider Provider for the current document
|
|
23
|
+
* @param searchDebounceTime Debounce search time
|
|
24
|
+
*/
|
|
25
|
+
function LibroSearchModel(utils, searchProvider, searchDebounceTime) {
|
|
26
|
+
var _this = this;
|
|
27
|
+
_classCallCheck(this, LibroSearchModel);
|
|
28
|
+
this._disposed = false;
|
|
29
|
+
this._caseSensitive = false;
|
|
30
|
+
this.parsingError = '';
|
|
31
|
+
this._filters = {
|
|
32
|
+
searchCellOutput: true,
|
|
33
|
+
onlySearchSelectedCells: false
|
|
34
|
+
};
|
|
35
|
+
this._replaceText = '';
|
|
36
|
+
this._searchExpression = '';
|
|
37
|
+
this._useRegex = false;
|
|
38
|
+
this.disposedEmitter = new Emitter();
|
|
39
|
+
this.toDispose = new DisposableCollection();
|
|
40
|
+
this.utils = utils;
|
|
41
|
+
this.searchProvider = searchProvider;
|
|
42
|
+
// this._filters = {};
|
|
43
|
+
// if (this.searchProvider.getFilters) {
|
|
44
|
+
// const filters = this.searchProvider.getFilters();
|
|
45
|
+
// for (const filter in filters) {
|
|
46
|
+
// this._filters[filter] = filters[filter].default;
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
this.toDispose.push(searchProvider.stateChanged(this.refresh));
|
|
51
|
+
this.searchDebouncer = debounce(function () {
|
|
52
|
+
_this.updateSearch().catch(function (reason) {
|
|
53
|
+
console.error('Failed to update search on document.', reason);
|
|
54
|
+
});
|
|
55
|
+
}, searchDebounceTime);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether the search is case sensitive or not.
|
|
60
|
+
*/
|
|
61
|
+
LibroSearchModel = inject(LibroSearchUtils)(LibroSearchModel, undefined, 0) || LibroSearchModel;
|
|
62
|
+
_createClass(LibroSearchModel, [{
|
|
63
|
+
key: "onDisposed",
|
|
64
|
+
get: function get() {
|
|
65
|
+
return this.disposedEmitter.event;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "disposed",
|
|
69
|
+
get: function get() {
|
|
70
|
+
return !!this._disposed;
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "caseSensitive",
|
|
74
|
+
get: function get() {
|
|
75
|
+
return this._caseSensitive;
|
|
76
|
+
},
|
|
77
|
+
set: function set(v) {
|
|
78
|
+
if (this._caseSensitive !== v) {
|
|
79
|
+
this._caseSensitive = v;
|
|
80
|
+
this.refresh();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Current highlighted match index.
|
|
86
|
+
*/
|
|
87
|
+
}, {
|
|
88
|
+
key: "currentIndex",
|
|
89
|
+
get: function get() {
|
|
90
|
+
return this.searchProvider.currentMatchIndex;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Filter values.
|
|
95
|
+
*/
|
|
96
|
+
}, {
|
|
97
|
+
key: "filters",
|
|
98
|
+
get: function get() {
|
|
99
|
+
return this._filters;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Filter definitions for the current provider.
|
|
104
|
+
*/
|
|
105
|
+
}, {
|
|
106
|
+
key: "filtersDefinition",
|
|
107
|
+
get: function get() {
|
|
108
|
+
var _this$searchProvider$, _this$searchProvider$2, _this$searchProvider;
|
|
109
|
+
return (_this$searchProvider$ = (_this$searchProvider$2 = (_this$searchProvider = this.searchProvider).getFilters) === null || _this$searchProvider$2 === void 0 ? void 0 : _this$searchProvider$2.call(_this$searchProvider)) !== null && _this$searchProvider$ !== void 0 ? _this$searchProvider$ : {};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The initial query string.
|
|
114
|
+
*/
|
|
115
|
+
}, {
|
|
116
|
+
key: "initialQuery",
|
|
117
|
+
get: function get() {
|
|
118
|
+
if (!this.searchProvider.getInitialQuery) {
|
|
119
|
+
return this._searchExpression;
|
|
120
|
+
}
|
|
121
|
+
return this._searchExpression || this.searchProvider.getInitialQuery();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Whether the document is read-only or not.
|
|
126
|
+
*/
|
|
127
|
+
}, {
|
|
128
|
+
key: "isReadOnly",
|
|
129
|
+
get: function get() {
|
|
130
|
+
return this.searchProvider.isReadOnly;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Replacement expression
|
|
135
|
+
*/
|
|
136
|
+
}, {
|
|
137
|
+
key: "replaceText",
|
|
138
|
+
get: function get() {
|
|
139
|
+
return this._replaceText;
|
|
140
|
+
},
|
|
141
|
+
set: function set(v) {
|
|
142
|
+
if (this._replaceText !== v) {
|
|
143
|
+
this._replaceText = v;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Search expression
|
|
149
|
+
*/
|
|
150
|
+
}, {
|
|
151
|
+
key: "searchExpression",
|
|
152
|
+
get: function get() {
|
|
153
|
+
return this._searchExpression;
|
|
154
|
+
},
|
|
155
|
+
set: function set(v) {
|
|
156
|
+
if (this._searchExpression !== v) {
|
|
157
|
+
this._searchExpression = v;
|
|
158
|
+
this.refresh();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Total number of matches.
|
|
164
|
+
*/
|
|
165
|
+
}, {
|
|
166
|
+
key: "totalMatches",
|
|
167
|
+
get: function get() {
|
|
168
|
+
return this.searchProvider.matchesCount;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Whether to use regular expression or not.
|
|
173
|
+
*/
|
|
174
|
+
}, {
|
|
175
|
+
key: "useRegex",
|
|
176
|
+
get: function get() {
|
|
177
|
+
return this._useRegex;
|
|
178
|
+
},
|
|
179
|
+
set: function set(v) {
|
|
180
|
+
if (this._useRegex !== v) {
|
|
181
|
+
this._useRegex = v;
|
|
182
|
+
this.refresh();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Dispose the model.
|
|
188
|
+
*/
|
|
189
|
+
}, {
|
|
190
|
+
key: "dispose",
|
|
191
|
+
value: function dispose() {
|
|
192
|
+
var _this2 = this;
|
|
193
|
+
if (this.disposed) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (this._searchExpression) {
|
|
197
|
+
this.endQuery().catch(function (reason) {
|
|
198
|
+
console.error("Failed to end query '".concat(_this2._searchExpression, "."), reason);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
this.toDispose.dispose();
|
|
202
|
+
this.searchDebouncer.dispose();
|
|
203
|
+
this._disposed = true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* End the query.
|
|
208
|
+
*/
|
|
209
|
+
}, {
|
|
210
|
+
key: "endQuery",
|
|
211
|
+
value: function () {
|
|
212
|
+
var _endQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
213
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
214
|
+
while (1) switch (_context.prev = _context.next) {
|
|
215
|
+
case 0:
|
|
216
|
+
_context.next = 2;
|
|
217
|
+
return this.searchProvider.endQuery();
|
|
218
|
+
case 2:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context.stop();
|
|
221
|
+
}
|
|
222
|
+
}, _callee, this);
|
|
223
|
+
}));
|
|
224
|
+
function endQuery() {
|
|
225
|
+
return _endQuery.apply(this, arguments);
|
|
226
|
+
}
|
|
227
|
+
return endQuery;
|
|
228
|
+
}()
|
|
229
|
+
/**
|
|
230
|
+
* Highlight the next match.
|
|
231
|
+
*/
|
|
232
|
+
}, {
|
|
233
|
+
key: "highlightNext",
|
|
234
|
+
value: function () {
|
|
235
|
+
var _highlightNext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
236
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
237
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
238
|
+
case 0:
|
|
239
|
+
_context2.next = 2;
|
|
240
|
+
return this.searchProvider.highlightNext();
|
|
241
|
+
case 2:
|
|
242
|
+
case "end":
|
|
243
|
+
return _context2.stop();
|
|
244
|
+
}
|
|
245
|
+
}, _callee2, this);
|
|
246
|
+
}));
|
|
247
|
+
function highlightNext() {
|
|
248
|
+
return _highlightNext.apply(this, arguments);
|
|
249
|
+
}
|
|
250
|
+
return highlightNext;
|
|
251
|
+
}()
|
|
252
|
+
/**
|
|
253
|
+
* Highlight the previous match
|
|
254
|
+
*/
|
|
255
|
+
}, {
|
|
256
|
+
key: "highlightPrevious",
|
|
257
|
+
value: function () {
|
|
258
|
+
var _highlightPrevious = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
259
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
260
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
261
|
+
case 0:
|
|
262
|
+
_context3.next = 2;
|
|
263
|
+
return this.searchProvider.highlightPrevious();
|
|
264
|
+
case 2:
|
|
265
|
+
case "end":
|
|
266
|
+
return _context3.stop();
|
|
267
|
+
}
|
|
268
|
+
}, _callee3, this);
|
|
269
|
+
}));
|
|
270
|
+
function highlightPrevious() {
|
|
271
|
+
return _highlightPrevious.apply(this, arguments);
|
|
272
|
+
}
|
|
273
|
+
return highlightPrevious;
|
|
274
|
+
}()
|
|
275
|
+
/**
|
|
276
|
+
* Refresh search
|
|
277
|
+
*/
|
|
278
|
+
}, {
|
|
279
|
+
key: "refresh",
|
|
280
|
+
value: function refresh() {
|
|
281
|
+
this.searchDebouncer.invoke().catch(function (reason) {
|
|
282
|
+
console.error('Failed to invoke search document debouncer.', reason);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Replace all matches.
|
|
288
|
+
*/
|
|
289
|
+
}, {
|
|
290
|
+
key: "replaceAllMatches",
|
|
291
|
+
value: function () {
|
|
292
|
+
var _replaceAllMatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
293
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
294
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
295
|
+
case 0:
|
|
296
|
+
_context4.next = 2;
|
|
297
|
+
return this.searchProvider.replaceAllMatches(this._replaceText);
|
|
298
|
+
case 2:
|
|
299
|
+
case "end":
|
|
300
|
+
return _context4.stop();
|
|
301
|
+
}
|
|
302
|
+
}, _callee4, this);
|
|
303
|
+
}));
|
|
304
|
+
function replaceAllMatches() {
|
|
305
|
+
return _replaceAllMatches.apply(this, arguments);
|
|
306
|
+
}
|
|
307
|
+
return replaceAllMatches;
|
|
308
|
+
}()
|
|
309
|
+
/**
|
|
310
|
+
* Replace the current match.
|
|
311
|
+
*/
|
|
312
|
+
}, {
|
|
313
|
+
key: "replaceCurrentMatch",
|
|
314
|
+
value: function () {
|
|
315
|
+
var _replaceCurrentMatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
316
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
317
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
318
|
+
case 0:
|
|
319
|
+
_context5.next = 2;
|
|
320
|
+
return this.searchProvider.replaceCurrentMatch(this._replaceText);
|
|
321
|
+
case 2:
|
|
322
|
+
case "end":
|
|
323
|
+
return _context5.stop();
|
|
324
|
+
}
|
|
325
|
+
}, _callee5, this);
|
|
326
|
+
}));
|
|
327
|
+
function replaceCurrentMatch() {
|
|
328
|
+
return _replaceCurrentMatch.apply(this, arguments);
|
|
329
|
+
}
|
|
330
|
+
return replaceCurrentMatch;
|
|
331
|
+
}()
|
|
332
|
+
/**
|
|
333
|
+
* Set the value of a given filter.
|
|
334
|
+
*
|
|
335
|
+
* @param name Filter name
|
|
336
|
+
* @param v Filter value
|
|
337
|
+
*/
|
|
338
|
+
}, {
|
|
339
|
+
key: "setFilter",
|
|
340
|
+
value: function () {
|
|
341
|
+
var _setFilter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_name, _v) {
|
|
342
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
343
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
344
|
+
case 0:
|
|
345
|
+
case "end":
|
|
346
|
+
return _context6.stop();
|
|
347
|
+
}
|
|
348
|
+
}, _callee6);
|
|
349
|
+
}));
|
|
350
|
+
function setFilter(_x, _x2) {
|
|
351
|
+
return _setFilter.apply(this, arguments);
|
|
352
|
+
}
|
|
353
|
+
return setFilter;
|
|
354
|
+
}()
|
|
355
|
+
}, {
|
|
356
|
+
key: "updateSearch",
|
|
357
|
+
value: function () {
|
|
358
|
+
var _updateSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
359
|
+
var query;
|
|
360
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
361
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
362
|
+
case 0:
|
|
363
|
+
if (this.parsingError) {
|
|
364
|
+
this.parsingError = '';
|
|
365
|
+
}
|
|
366
|
+
_context7.prev = 1;
|
|
367
|
+
query = this.searchExpression ? this.utils.parseQuery(this.searchExpression, this.caseSensitive, this.useRegex) : null;
|
|
368
|
+
if (!query) {
|
|
369
|
+
_context7.next = 6;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
_context7.next = 6;
|
|
373
|
+
return this.searchProvider.startQuery(query, this._filters);
|
|
374
|
+
case 6:
|
|
375
|
+
_context7.next = 12;
|
|
376
|
+
break;
|
|
377
|
+
case 8:
|
|
378
|
+
_context7.prev = 8;
|
|
379
|
+
_context7.t0 = _context7["catch"](1);
|
|
380
|
+
this.parsingError = _context7.t0.toString();
|
|
381
|
+
console.error("Failed to parse expression ".concat(this.searchExpression), _context7.t0);
|
|
382
|
+
case 12:
|
|
383
|
+
case "end":
|
|
384
|
+
return _context7.stop();
|
|
385
|
+
}
|
|
386
|
+
}, _callee7, this, [[1, 8]]);
|
|
387
|
+
}));
|
|
388
|
+
function updateSearch() {
|
|
389
|
+
return _updateSearch.apply(this, arguments);
|
|
390
|
+
}
|
|
391
|
+
return updateSearch;
|
|
392
|
+
}()
|
|
393
|
+
}]);
|
|
394
|
+
return LibroSearchModel;
|
|
395
|
+
}()) || _class);
|