@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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/abstract-search-provider.d.ts +113 -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 +107 -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 +107 -0
  20. package/es/libro-search-generic-provider.d.ts.map +1 -0
  21. package/es/libro-search-generic-provider.js +467 -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 +102 -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 +395 -0
  28. package/es/libro-search-protocol.d.ts +176 -0
  29. package/es/libro-search-protocol.d.ts.map +1 -0
  30. package/es/libro-search-protocol.js +36 -0
  31. package/es/libro-search-provider.d.ts +138 -0
  32. package/es/libro-search-provider.d.ts.map +1 -0
  33. package/es/libro-search-provider.js +759 -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 +85 -0
  37. package/es/libro-search-view.d.ts +59 -0
  38. package/es/libro-search-view.d.ts.map +1 -0
  39. package/es/libro-search-view.js +455 -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 +66 -0
  44. package/src/abstract-search-provider.ts +160 -0
  45. package/src/index.less +107 -0
  46. package/src/index.ts +9 -0
  47. package/src/libro-cell-search-provider.ts +39 -0
  48. package/src/libro-search-engine-html.ts +74 -0
  49. package/src/libro-search-engine-text.ts +34 -0
  50. package/src/libro-search-generic-provider.ts +303 -0
  51. package/src/libro-search-manager.ts +86 -0
  52. package/src/libro-search-model.ts +266 -0
  53. package/src/libro-search-protocol.ts +209 -0
  54. package/src/libro-search-provider.ts +507 -0
  55. package/src/libro-search-utils.spec.ts +37 -0
  56. package/src/libro-search-utils.ts +83 -0
  57. package/src/libro-search-view.tsx +404 -0
  58. package/src/module.ts +59 -0
@@ -0,0 +1,25 @@
1
+ import type { SearchMatch } from './libro-search-protocol.js';
2
+ /**
3
+ * Search Utils
4
+ */
5
+ export declare class LibroSearchUtils {
6
+ /**
7
+ * 查找当前 position 最靠近的匹配项,适用于文本中查找
8
+ * @param matches 匹配项列表,通常来自一个 cell 或者 output
9
+ * @param position 查找起点,当前位置的文本偏移量
10
+ * @param lower 查找范围下限,值为匹配列表 index
11
+ * @param higher 查找范围上限,值为匹配列表 index
12
+ * @returns 下一个匹配项的 index,如果没有找到则返回 null
13
+ */
14
+ findNext(matches: SearchMatch[], position: number, lower?: number, higher?: number): number | undefined;
15
+ /**
16
+ * Build the regular expression to use for searching.
17
+ *
18
+ * @param queryString Query string
19
+ * @param caseSensitive Whether the search is case sensitive or not
20
+ * @param regex Whether the expression is a regular expression
21
+ * @returns The regular expression to use
22
+ */
23
+ parseQuery(queryString: string, caseSensitive: boolean, regex: boolean): RegExp | undefined;
24
+ }
25
+ //# sourceMappingURL=libro-search-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-search-utils.d.ts","sourceRoot":"","sources":["../src/libro-search-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;GAEG;AACH,qBACa,gBAAgB;IAC3B;;;;;;;OAOG;IACH,QAAQ,CACN,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAI,EACT,MAAM,SAAW,GAChB,MAAM,GAAG,SAAS;IA+BrB;;;;;;;OAOG;IACH,UAAU,CACR,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,OAAO,EACtB,KAAK,EAAE,OAAO,GACb,MAAM,GAAG,SAAS;CAiBtB"}
@@ -0,0 +1,85 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import { singleton } from '@difizen/mana-app';
9
+ /**
10
+ * Search Utils
11
+ */
12
+ export var LibroSearchUtils = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
13
+ function LibroSearchUtils() {
14
+ _classCallCheck(this, LibroSearchUtils);
15
+ }
16
+ _createClass(LibroSearchUtils, [{
17
+ key: "findNext",
18
+ value:
19
+ /**
20
+ * 查找当前 position 最靠近的匹配项,适用于文本中查找
21
+ * @param matches 匹配项列表,通常来自一个 cell 或者 output
22
+ * @param position 查找起点,当前位置的文本偏移量
23
+ * @param lower 查找范围下限,值为匹配列表 index
24
+ * @param higher 查找范围上限,值为匹配列表 index
25
+ * @returns 下一个匹配项的 index,如果没有找到则返回 null
26
+ */
27
+ function findNext(matches, position) {
28
+ var lower = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
29
+ var higher = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Infinity;
30
+ var higherBound = Math.min(matches.length - 1, higher);
31
+ var lowerBound = lower;
32
+ while (lowerBound <= higherBound) {
33
+ // 取中间匹配项
34
+ var middle = Math.floor(0.5 * (lowerBound + higherBound));
35
+ // 中间匹配项的文本偏移量
36
+ var currentPosition = matches[middle].position;
37
+ if (currentPosition < position) {
38
+ // 中间值的偏移量小于查找起点
39
+ lowerBound = middle + 1; // 场景1:查找范围下限太小,需要增大,更新中间值
40
+ if (lowerBound < matches.length && matches[lowerBound].position > position) {
41
+ return lowerBound; // 场景2:下限已经是要查找的前一个匹配项了,下个匹配项的偏移量会大于查找起点。
42
+ }
43
+ } else if (currentPosition > position) {
44
+ // 中间值的偏移量大于查找起点
45
+ higherBound = middle - 1; // 场景1:查找范围上限太大,需要减小,更新中间值
46
+ if (higherBound > 0 && matches[higherBound].position < position) {
47
+ return middle; // 场景2:上限已经是要查找的后一个匹配项了,下个匹配项的偏移量会小于查找起点。
48
+ }
49
+ } else {
50
+ return middle; // 直接命中查找起点,选择此匹配项
51
+ }
52
+ }
53
+ // 查找起点不在 match 范围内,要么在范围前面,要么在范围后面
54
+ var first = lowerBound > 0 ? lowerBound - 1 : 0;
55
+ var match = matches[first];
56
+ return match.position >= position ? first : undefined;
57
+ }
58
+
59
+ /**
60
+ * Build the regular expression to use for searching.
61
+ *
62
+ * @param queryString Query string
63
+ * @param caseSensitive Whether the search is case sensitive or not
64
+ * @param regex Whether the expression is a regular expression
65
+ * @returns The regular expression to use
66
+ */
67
+ }, {
68
+ key: "parseQuery",
69
+ value: function parseQuery(queryString, caseSensitive, regex) {
70
+ var flag = caseSensitive ? 'g' : 'gi';
71
+ // escape regex characters in query if its a string search
72
+ var queryText = regex ? queryString : queryString.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
73
+ var ret = new RegExp(queryText, flag);
74
+
75
+ // If the empty string is hit, the search logic will freeze the browser tab
76
+ // Trying /^/ or /$/ on the codemirror search demo, does not find anything.
77
+ // So this is a limitation of the editor.
78
+ if (ret.test('')) {
79
+ return undefined;
80
+ }
81
+ return ret;
82
+ }
83
+ }]);
84
+ return LibroSearchUtils;
85
+ }()) || _class);
@@ -0,0 +1,59 @@
1
+ import type { LibroView } from '@difizen/libro-core';
2
+ import { LirboContextKey } from '@difizen/libro-core';
3
+ import { BaseView } from '@difizen/mana-app';
4
+ import type { CheckboxChangeEvent } from 'antd/es/checkbox';
5
+ import type { InputRef } from 'antd/es/input';
6
+ import type { FC } from 'react';
7
+ import type { LibroSearchProvider } from './libro-search-provider.js';
8
+ import { LibroSearchProviderFactory } from './libro-search-provider.js';
9
+ import { LibroSearchUtils } from './libro-search-utils.js';
10
+ export declare const ReplaceToggle: FC;
11
+ export declare const SearchIndex: FC;
12
+ export declare const SearchContent: FC;
13
+ export declare const SearchComponent: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
14
+ export declare class LibroSearchView extends BaseView {
15
+ findInputRef?: React.RefObject<InputRef> | null;
16
+ contextKey: LirboContextKey;
17
+ utils: LibroSearchUtils;
18
+ searchProviderFactory: LibroSearchProviderFactory;
19
+ constructor(contextKey: LirboContextKey, utils: LibroSearchUtils, searchProviderFactory: LibroSearchProviderFactory);
20
+ protected _libro?: LibroView;
21
+ get libro(): LibroView | undefined;
22
+ set libro(value: LibroView | undefined);
23
+ searchProvider?: LibroSearchProvider;
24
+ searchVisible: boolean;
25
+ get replaceVisible(): boolean;
26
+ settingVisible: boolean;
27
+ findStr?: string | undefined;
28
+ lastSearch?: string | undefined;
29
+ replaceStr: string;
30
+ caseSensitive: boolean;
31
+ useRegex: boolean;
32
+ view: import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>;
33
+ get contentHeight(): number;
34
+ get currentMatchIndex(): number | undefined;
35
+ get matchesCount(): number | undefined;
36
+ onviewWillUnmount: () => void;
37
+ show: () => void;
38
+ hide: () => void;
39
+ onFocus: () => void;
40
+ onBlur: (e: React.FocusEvent<HTMLDivElement>) => void;
41
+ search: (hightlightNext?: boolean) => void;
42
+ toggleReplace: () => void;
43
+ toggleSetting: () => void;
44
+ toggleCaseSensitive: () => void;
45
+ toggleUseRegex: () => void;
46
+ next: () => void;
47
+ previous: () => void;
48
+ searchCellOutputChange: (e: CheckboxChangeEvent) => void;
49
+ replace: () => void;
50
+ replaceAll: () => void;
51
+ initialQuery: () => void;
52
+ getHeaderHeight: () => number;
53
+ nextMatch: (reverse: boolean) => void;
54
+ handleKeydown: (e: KeyboardEvent) => void;
55
+ protected doHandleFindChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
56
+ handleFindChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
57
+ handleReplaceChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
58
+ }
59
+ //# sourceMappingURL=libro-search-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-search-view.d.ts","sourceRoot":"","sources":["../src/libro-search-view.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,mBAAmB,CAAC;AAIjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM3D,eAAO,MAAM,aAAa,EAAE,EAY3B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,EAOzB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,EAsH3B,CAAC;AAEF,eAAO,MAAM,eAAe,0FAiB1B,CAAC;AAEH,qBAEa,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;IAChD,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,gBAAgB,CAAC;IACxB,qBAAqB,EAAE,0BAA0B,CAAC;gBAGvB,UAAU,EAAE,eAAe,EAC1B,KAAK,EAAE,gBAAgB,EAEjD,qBAAqB,EAAE,0BAA0B;IAQnD,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAE7B,IAAI,KAAK,IAAI,SAAS,GAAG,SAAS,CAEjC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAGrC;IAEO,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,aAAa,UAAS;IAC9B,IAAI,cAAc,IAAI,OAAO,CAE5B;IACO,cAAc,UAAS;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAa;IACzC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAa;IAC5C,UAAU,SAAM;IAChB,aAAa,UAAS;IACtB,QAAQ,UAAS;IAEhB,IAAI,2FAAmB;IAEhC,IAAI,aAAa,WAShB;IACD,IAAI,iBAAiB,uBAMpB;IACD,IAAI,YAAY,uBAEf;IAED,iBAAiB,aAEf;IAEF,IAAI,aAKF;IACF,IAAI,aAKF;IAEF,OAAO,aAEL;IAEF,MAAM,MAAO,gBAAgB,CAAC,cAAc,CAAC,UAI3C;IAEF,MAAM,qCAcJ;IACF,aAAa,aAKX;IAEF,aAAa,aAGX;IAEF,mBAAmB,aAGjB;IAEF,cAAc,aAEZ;IAEF,IAAI,aAEF;IAEF,QAAQ,aAEN;IAEF,sBAAsB,MAAO,mBAAmB,UAI9C;IAEF,OAAO,aAEL;IACF,UAAU,aAER;IACF,YAAY,aAMV;IACF,eAAe,eAUb;IAEF,SAAS,YAAa,OAAO,UAM3B;IAEF,aAAa,MAAO,aAAa,UAqB/B;IAEF,SAAS,CAAC,kBAAkB,MAAO,MAAM,WAAW,CAAC,gBAAgB,CAAC,UAEpE;IAEF,gBAAgB,MAAO,MAAM,WAAW,CAAC,gBAAgB,CAAC,UAKxD;IACF,mBAAmB,MAAO,MAAM,WAAW,CAAC,gBAAgB,CAAC,UAE3D;CACH"}
@@ -0,0 +1,455 @@
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, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
13
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
+ 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; }
17
+ 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.'); }
18
+ import { RightOutlined, ArrowUpOutlined, ArrowDownOutlined, EllipsisOutlined, CloseOutlined, createFromIconfontCN } from '@ant-design/icons';
19
+ import { LirboContextKey } from '@difizen/libro-core';
20
+ import { prop, useInject } from '@difizen/mana-app';
21
+ import { BaseView, view, ViewInstance } from '@difizen/mana-app';
22
+ import { inject, transient } from '@difizen/mana-app';
23
+ import { l10n } from '@difizen/mana-l10n';
24
+ import { Input, Button, Checkbox, Tag } from 'antd';
25
+ import classnames from 'classnames';
26
+ import { forwardRef, useEffect, useRef } from 'react';
27
+ import { LibroSearchProviderFactory } from "./libro-search-provider.js";
28
+ import { LibroSearchUtils } from "./libro-search-utils.js";
29
+ import { jsx as _jsx } from "react/jsx-runtime";
30
+ import { jsxs as _jsxs } from "react/jsx-runtime";
31
+ var IconFont = createFromIconfontCN({
32
+ scriptUrl: '//at.alicdn.com/t/a/font_3381673_65wfctnq7rt.js'
33
+ });
34
+ export var ReplaceToggle = function ReplaceToggle() {
35
+ var instance = useInject(ViewInstance);
36
+ return /*#__PURE__*/_jsx("div", {
37
+ className: "libro-search-replace-toggle",
38
+ onClick: instance.toggleReplace,
39
+ children: /*#__PURE__*/_jsx(RightOutlined, {
40
+ className: classnames({
41
+ 'libro-search-replace-toggle-icon': true,
42
+ 'libro-search-replace-toggle-replace-icon': instance.replaceVisible
43
+ })
44
+ })
45
+ });
46
+ };
47
+ export var SearchIndex = function SearchIndex() {
48
+ var _instance$currentMatc, _instance$matchesCoun;
49
+ var instance = useInject(ViewInstance);
50
+ return /*#__PURE__*/_jsxs("div", {
51
+ className: "libro-search-index",
52
+ children: [(_instance$currentMatc = instance.currentMatchIndex) !== null && _instance$currentMatc !== void 0 ? _instance$currentMatc : '-', "/", (_instance$matchesCoun = instance.matchesCount) !== null && _instance$matchesCoun !== void 0 ? _instance$matchesCoun : '-']
53
+ });
54
+ };
55
+ export var SearchContent = function SearchContent() {
56
+ var _instance$searchProvi;
57
+ var instance = useInject(ViewInstance);
58
+ var findInputRef = useRef(null);
59
+ useEffect(function () {
60
+ var _instance$container;
61
+ if (findInputRef.current) {
62
+ findInputRef.current.focus();
63
+ }
64
+ instance.findInputRef = findInputRef;
65
+ if ((_instance$container = instance.container) !== null && _instance$container !== void 0 && _instance$container.current) {
66
+ var container = instance.container.current;
67
+ container.addEventListener('keydown', instance.handleKeydown);
68
+ return function () {
69
+ container.removeEventListener('keydown', instance.handleKeydown);
70
+ };
71
+ }
72
+ return;
73
+ }, [instance]);
74
+ return /*#__PURE__*/_jsxs("div", {
75
+ className: "libro-search-content",
76
+ style: {
77
+ height: "".concat(instance.contentHeight, "px")
78
+ },
79
+ children: [/*#__PURE__*/_jsx(ReplaceToggle, {}), /*#__PURE__*/_jsxs("table", {
80
+ className: "libro-search-input-area",
81
+ children: [/*#__PURE__*/_jsxs("tr", {
82
+ className: "libro-search-row",
83
+ children: [/*#__PURE__*/_jsx("td", {
84
+ className: "libro-search-input",
85
+ children: /*#__PURE__*/_jsx(Input, {
86
+ ref: findInputRef,
87
+ value: instance.findStr,
88
+ onChange: instance.handleFindChange,
89
+ size: "small",
90
+ suffix: /*#__PURE__*/_jsxs("span", {
91
+ className: "libro-search-input-suffix",
92
+ children: [/*#__PURE__*/_jsx(IconFont, {
93
+ className: classnames({
94
+ 'libro-search-input-suffix-active': instance.caseSensitive
95
+ }),
96
+ onClick: instance.toggleCaseSensitive,
97
+ type: "icon-Aa"
98
+ }), /*#__PURE__*/_jsx(IconFont, {
99
+ className: classnames({
100
+ 'libro-search-input-suffix-active': instance.useRegex
101
+ }),
102
+ onClick: instance.toggleUseRegex,
103
+ type: "icon-zhengzeshi"
104
+ })]
105
+ })
106
+ })
107
+ }), /*#__PURE__*/_jsxs("td", {
108
+ className: "libro-search-action",
109
+ children: [/*#__PURE__*/_jsx(SearchIndex, {}), /*#__PURE__*/_jsxs("div", {
110
+ children: [/*#__PURE__*/_jsx(Button, {
111
+ onClick: instance.previous,
112
+ icon: /*#__PURE__*/_jsx(ArrowUpOutlined, {}),
113
+ size: "small"
114
+ }), /*#__PURE__*/_jsx(Button, {
115
+ onClick: instance.next,
116
+ icon: /*#__PURE__*/_jsx(ArrowDownOutlined, {}),
117
+ size: "small"
118
+ }), /*#__PURE__*/_jsx(Button, {
119
+ onClick: instance.toggleSetting,
120
+ icon: /*#__PURE__*/_jsx(EllipsisOutlined, {}),
121
+ size: "small"
122
+ }), /*#__PURE__*/_jsx(Button, {
123
+ onClick: instance.hide,
124
+ icon: /*#__PURE__*/_jsx(CloseOutlined, {}),
125
+ size: "small"
126
+ })]
127
+ })]
128
+ })]
129
+ }), instance.replaceVisible && /*#__PURE__*/_jsxs("tr", {
130
+ className: "libro-search-row",
131
+ children: [/*#__PURE__*/_jsx("td", {
132
+ className: "libro-search-input",
133
+ children: /*#__PURE__*/_jsx(Input, {
134
+ value: instance.replaceStr,
135
+ onChange: instance.handleReplaceChange,
136
+ size: "small"
137
+ })
138
+ }), /*#__PURE__*/_jsx("td", {
139
+ className: "libro-search-action",
140
+ children: /*#__PURE__*/_jsxs("div", {
141
+ children: [/*#__PURE__*/_jsx(Button, {
142
+ onClick: instance.replace,
143
+ icon: /*#__PURE__*/_jsx(IconFont, {
144
+ type: "icon-zifuchuantihuan_2"
145
+ }),
146
+ size: "small"
147
+ }), /*#__PURE__*/_jsx(Button, {
148
+ onClick: instance.replaceAll,
149
+ icon: /*#__PURE__*/_jsx(IconFont, {
150
+ type: "icon-tihuantupian"
151
+ }),
152
+ size: "small"
153
+ })]
154
+ })
155
+ })]
156
+ }), instance.settingVisible && /*#__PURE__*/_jsxs("div", {
157
+ className: "libro-search-row",
158
+ children: [/*#__PURE__*/_jsx(Checkbox, {
159
+ checked: (_instance$searchProvi = instance.searchProvider) === null || _instance$searchProvi === void 0 ? void 0 : _instance$searchProvi.searchCellOutput,
160
+ onChange: instance.searchCellOutputChange,
161
+ disabled: instance.replaceVisible,
162
+ children: l10n.t('在 output 中查找')
163
+ }), instance.replaceVisible && /*#__PURE__*/_jsx(Tag, {
164
+ color: "warning",
165
+ children: l10n.t('替换功能不能在 output 生效')
166
+ })]
167
+ })]
168
+ })]
169
+ });
170
+ };
171
+ // TODO: 更改图标
172
+ export var SearchComponent = /*#__PURE__*/forwardRef(function SearchComponent(_props, ref) {
173
+ var instance = useInject(ViewInstance);
174
+ return /*#__PURE__*/_jsx("div", {
175
+ tabIndex: 1,
176
+ className: "libro-search-overlay",
177
+ style: {
178
+ top: instance.getHeaderHeight()
179
+ },
180
+ ref: ref,
181
+ onBlur: function onBlur(e) {
182
+ return instance.onBlur(e);
183
+ },
184
+ onFocus: instance.onFocus,
185
+ children: instance.searchVisible && /*#__PURE__*/_jsx(SearchContent, {})
186
+ });
187
+ });
188
+ export var LibroSearchView = (_dec = transient(), _dec2 = view('libro-search-view'), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec9 = prop(), _dec10 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
189
+ _inherits(LibroSearchView, _BaseView);
190
+ var _super = _createSuper(LibroSearchView);
191
+ function LibroSearchView(contextKey, utils, searchProviderFactory) {
192
+ var _this;
193
+ _classCallCheck(this, LibroSearchView);
194
+ _this = _super.call(this);
195
+ _initializerDefineProperty(_this, "searchProvider", _descriptor, _assertThisInitialized(_this));
196
+ _initializerDefineProperty(_this, "searchVisible", _descriptor2, _assertThisInitialized(_this));
197
+ _initializerDefineProperty(_this, "settingVisible", _descriptor3, _assertThisInitialized(_this));
198
+ _initializerDefineProperty(_this, "findStr", _descriptor4, _assertThisInitialized(_this));
199
+ _initializerDefineProperty(_this, "lastSearch", _descriptor5, _assertThisInitialized(_this));
200
+ _initializerDefineProperty(_this, "replaceStr", _descriptor6, _assertThisInitialized(_this));
201
+ _initializerDefineProperty(_this, "caseSensitive", _descriptor7, _assertThisInitialized(_this));
202
+ _initializerDefineProperty(_this, "useRegex", _descriptor8, _assertThisInitialized(_this));
203
+ _this.view = SearchComponent;
204
+ _this.onviewWillUnmount = function () {
205
+ var _this$searchProvider;
206
+ (_this$searchProvider = _this.searchProvider) === null || _this$searchProvider === void 0 ? void 0 : _this$searchProvider.endQuery();
207
+ };
208
+ _this.show = function () {
209
+ var _this$findInputRef, _this$findInputRef$cu;
210
+ _this.contextKey.disableCommandMode();
211
+ _this.searchVisible = true;
212
+ _this.initialQuery();
213
+ (_this$findInputRef = _this.findInputRef) === null || _this$findInputRef === void 0 ? void 0 : (_this$findInputRef$cu = _this$findInputRef.current) === null || _this$findInputRef$cu === void 0 ? void 0 : _this$findInputRef$cu.focus();
214
+ };
215
+ _this.hide = function () {
216
+ var _this$searchProvider2, _this$libro;
217
+ _this.searchVisible = false;
218
+ _this.contextKey.enableCommandMode();
219
+ (_this$searchProvider2 = _this.searchProvider) === null || _this$searchProvider2 === void 0 ? void 0 : _this$searchProvider2.endQuery();
220
+ (_this$libro = _this.libro) === null || _this$libro === void 0 ? void 0 : _this$libro.focus();
221
+ };
222
+ _this.onFocus = function () {
223
+ _this.contextKey.disableCommandMode();
224
+ };
225
+ _this.onBlur = function (e) {
226
+ var _this$libro2, _this$libro2$containe, _this$libro2$containe2;
227
+ if ((_this$libro2 = _this.libro) !== null && _this$libro2 !== void 0 && (_this$libro2$containe = _this$libro2.container) !== null && _this$libro2$containe !== void 0 && (_this$libro2$containe2 = _this$libro2$containe.current) !== null && _this$libro2$containe2 !== void 0 && _this$libro2$containe2.contains(e.relatedTarget)) {
228
+ _this.contextKey.enableCommandMode();
229
+ }
230
+ };
231
+ _this.search = function () {
232
+ var hightlightNext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
233
+ if (_this.searchProvider) {
234
+ _this.lastSearch = _this.findStr;
235
+ var query = _this.utils.parseQuery(_this.findStr || '', _this.caseSensitive, _this.useRegex);
236
+ if (query) {
237
+ var _this$searchProvider3;
238
+ (_this$searchProvider3 = _this.searchProvider) === null || _this$searchProvider3 === void 0 ? void 0 : _this$searchProvider3.startQuery(query, undefined, hightlightNext);
239
+ } else {
240
+ var _this$searchProvider4;
241
+ (_this$searchProvider4 = _this.searchProvider) === null || _this$searchProvider4 === void 0 ? void 0 : _this$searchProvider4.endQuery();
242
+ }
243
+ }
244
+ };
245
+ _this.toggleReplace = function () {
246
+ if (_this.searchProvider) {
247
+ _this.searchProvider.replaceMode = !_this.replaceVisible;
248
+ _this.search();
249
+ }
250
+ };
251
+ _this.toggleSetting = function () {
252
+ _this.settingVisible = !_this.settingVisible;
253
+ _this.search();
254
+ };
255
+ _this.toggleCaseSensitive = function () {
256
+ _this.caseSensitive = !_this.caseSensitive;
257
+ _this.search();
258
+ };
259
+ _this.toggleUseRegex = function () {
260
+ _this.useRegex = !_this.useRegex;
261
+ };
262
+ _this.next = function () {
263
+ var _this$searchProvider5;
264
+ (_this$searchProvider5 = _this.searchProvider) === null || _this$searchProvider5 === void 0 ? void 0 : _this$searchProvider5.highlightNext();
265
+ };
266
+ _this.previous = function () {
267
+ var _this$searchProvider6;
268
+ (_this$searchProvider6 = _this.searchProvider) === null || _this$searchProvider6 === void 0 ? void 0 : _this$searchProvider6.highlightPrevious();
269
+ };
270
+ _this.searchCellOutputChange = function (e) {
271
+ if (_this.searchProvider) {
272
+ _this.searchProvider.updateSearchCellOutput(e.target.checked);
273
+ }
274
+ };
275
+ _this.replace = function () {
276
+ var _this$searchProvider7;
277
+ (_this$searchProvider7 = _this.searchProvider) === null || _this$searchProvider7 === void 0 ? void 0 : _this$searchProvider7.replaceCurrentMatch(_this.replaceStr);
278
+ };
279
+ _this.replaceAll = function () {
280
+ var _this$searchProvider8;
281
+ (_this$searchProvider8 = _this.searchProvider) === null || _this$searchProvider8 === void 0 ? void 0 : _this$searchProvider8.replaceAllMatches(_this.replaceStr);
282
+ };
283
+ _this.initialQuery = function () {
284
+ var _this$searchProvider9;
285
+ var init = (_this$searchProvider9 = _this.searchProvider) === null || _this$searchProvider9 === void 0 ? void 0 : _this$searchProvider9.getInitialQuery();
286
+ if (init) {
287
+ _this.findStr = init;
288
+ _this.search(false);
289
+ }
290
+ };
291
+ _this.getHeaderHeight = function () {
292
+ var _this$libro3, _this$libro3$containe;
293
+ var height = 32;
294
+ var container = (_this$libro3 = _this.libro) === null || _this$libro3 === void 0 ? void 0 : (_this$libro3$containe = _this$libro3.container) === null || _this$libro3$containe === void 0 ? void 0 : _this$libro3$containe.current;
295
+ if (container) {
296
+ var elements = container.getElementsByClassName('libro-view-top');
297
+ if (elements.length > 0) {
298
+ height = elements[0].clientHeight;
299
+ }
300
+ }
301
+ return height;
302
+ };
303
+ _this.nextMatch = function (reverse) {
304
+ if (reverse) {
305
+ var _this$searchProvider10;
306
+ (_this$searchProvider10 = _this.searchProvider) === null || _this$searchProvider10 === void 0 ? void 0 : _this$searchProvider10.highlightPrevious();
307
+ } else {
308
+ var _this$searchProvider11;
309
+ (_this$searchProvider11 = _this.searchProvider) === null || _this$searchProvider11 === void 0 ? void 0 : _this$searchProvider11.highlightNext();
310
+ }
311
+ };
312
+ _this.handleKeydown = function (e) {
313
+ if (e.key === 'Escape') {
314
+ e.stopPropagation();
315
+ e.preventDefault();
316
+ _this.hide();
317
+ return;
318
+ }
319
+ if (e.key === 'Enter') {
320
+ e.stopPropagation();
321
+ e.preventDefault();
322
+ if (_this.findStr !== _this.lastSearch) {
323
+ _this.search();
324
+ return;
325
+ }
326
+ if (_this.matchesCount !== undefined && _this.matchesCount > 0) {
327
+ _this.nextMatch(e.shiftKey);
328
+ } else {
329
+ _this.search();
330
+ }
331
+ return;
332
+ }
333
+ };
334
+ _this.doHandleFindChange = function (e) {
335
+ _this.findStr = e.target.value;
336
+ };
337
+ _this.handleFindChange = function (e) {
338
+ _this.findStr = e.target.value;
339
+ if (_this.findStr !== _this.lastSearch) {
340
+ _this.search(false);
341
+ }
342
+ };
343
+ _this.handleReplaceChange = function (e) {
344
+ _this.replaceStr = e.target.value;
345
+ };
346
+ _this.contextKey = contextKey;
347
+ _this.utils = utils;
348
+ _this.searchProviderFactory = searchProviderFactory;
349
+ return _this;
350
+ }
351
+ LibroSearchView = inject(LibroSearchProviderFactory)(LibroSearchView, undefined, 2) || LibroSearchView;
352
+ LibroSearchView = inject(LibroSearchUtils)(LibroSearchView, undefined, 1) || LibroSearchView;
353
+ LibroSearchView = inject(LirboContextKey)(LibroSearchView, undefined, 0) || LibroSearchView;
354
+ _createClass(LibroSearchView, [{
355
+ key: "libro",
356
+ get: function get() {
357
+ return this._libro;
358
+ },
359
+ set: function set(value) {
360
+ this._libro = value;
361
+ this.searchProvider = this.searchProviderFactory({
362
+ view: this.libro
363
+ });
364
+ }
365
+ }, {
366
+ key: "replaceVisible",
367
+ get: function get() {
368
+ var _this$searchProvider$, _this$searchProvider12;
369
+ return (_this$searchProvider$ = (_this$searchProvider12 = this.searchProvider) === null || _this$searchProvider12 === void 0 ? void 0 : _this$searchProvider12.replaceMode) !== null && _this$searchProvider$ !== void 0 ? _this$searchProvider$ : false;
370
+ }
371
+ }, {
372
+ key: "contentHeight",
373
+ get: function get() {
374
+ var height = 32;
375
+ if (this.replaceVisible) {
376
+ height += 32;
377
+ }
378
+ if (this.settingVisible) {
379
+ height += 32;
380
+ }
381
+ return height;
382
+ }
383
+ }, {
384
+ key: "currentMatchIndex",
385
+ get: function get() {
386
+ var _this$searchProvider13;
387
+ var current = (_this$searchProvider13 = this.searchProvider) === null || _this$searchProvider13 === void 0 ? void 0 : _this$searchProvider13.currentMatchIndex;
388
+ if (current !== undefined) {
389
+ return current + 1;
390
+ }
391
+ return undefined;
392
+ }
393
+ }, {
394
+ key: "matchesCount",
395
+ get: function get() {
396
+ var _this$searchProvider14;
397
+ return (_this$searchProvider14 = this.searchProvider) === null || _this$searchProvider14 === void 0 ? void 0 : _this$searchProvider14.matchesCount;
398
+ }
399
+ }]);
400
+ return LibroSearchView;
401
+ }(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "searchProvider", [_dec3], {
402
+ configurable: true,
403
+ enumerable: true,
404
+ writable: true,
405
+ initializer: null
406
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "searchVisible", [_dec4], {
407
+ configurable: true,
408
+ enumerable: true,
409
+ writable: true,
410
+ initializer: function initializer() {
411
+ return false;
412
+ }
413
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "settingVisible", [_dec5], {
414
+ configurable: true,
415
+ enumerable: true,
416
+ writable: true,
417
+ initializer: function initializer() {
418
+ return false;
419
+ }
420
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "findStr", [_dec6], {
421
+ configurable: true,
422
+ enumerable: true,
423
+ writable: true,
424
+ initializer: function initializer() {
425
+ return undefined;
426
+ }
427
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "lastSearch", [_dec7], {
428
+ configurable: true,
429
+ enumerable: true,
430
+ writable: true,
431
+ initializer: function initializer() {
432
+ return undefined;
433
+ }
434
+ }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "replaceStr", [_dec8], {
435
+ configurable: true,
436
+ enumerable: true,
437
+ writable: true,
438
+ initializer: function initializer() {
439
+ return '';
440
+ }
441
+ }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "caseSensitive", [_dec9], {
442
+ configurable: true,
443
+ enumerable: true,
444
+ writable: true,
445
+ initializer: function initializer() {
446
+ return false;
447
+ }
448
+ }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "useRegex", [_dec10], {
449
+ configurable: true,
450
+ enumerable: true,
451
+ writable: true,
452
+ initializer: function initializer() {
453
+ return false;
454
+ }
455
+ })), _class2)) || _class) || _class);
package/es/module.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ import './index.less';
3
+ export declare const LibroSearchModule: ManaModule;
4
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,cAAc,CAAC;AAmBtB,eAAO,MAAM,iBAAiB,YAqCiB,CAAC"}