@univerjs/docs-find-replace 1.4.0 → 1.5.1
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/README.md +5 -3
- package/lib/cjs/index.js +12 -12
- package/lib/es/index.js +12 -12
- package/lib/index.js +12 -12
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
## Package Overview
|
|
10
10
|
|
|
11
|
-
| Package | UMD global | CSS | Locales | Facade entry |
|
|
12
|
-
| --- | --- | :---: | :---: | :---: |
|
|
13
|
-
| `@univerjs/docs-find-replace` | `UniverDocsFindReplace` | No | No | No |
|
|
11
|
+
| Package | UMD global | CSS | Locales | Facade entry | Worker entry |
|
|
12
|
+
| --- | --- | :---: | :---: | :---: | :---: |
|
|
13
|
+
| `@univerjs/docs-find-replace` | `UniverDocsFindReplace` | No | No | No | No |
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -22,6 +22,8 @@ npm install @univerjs/docs-find-replace @univerjs/find-replace
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
+
Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
|
|
26
|
+
|
|
25
27
|
```ts
|
|
26
28
|
import { LocaleType, mergeLocales, Univer } from '@univerjs/core';
|
|
27
29
|
import { UniverDocsFindReplacePlugin } from '@univerjs/docs-find-replace';
|
package/lib/cjs/index.js
CHANGED
|
@@ -9,7 +9,7 @@ let rxjs = require("rxjs");
|
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
11
|
var name = "@univerjs/docs-find-replace";
|
|
12
|
-
var version = "1.
|
|
12
|
+
var version = "1.5.1";
|
|
13
13
|
|
|
14
14
|
// src/config/config.ts
|
|
15
15
|
/**
|
|
@@ -143,7 +143,7 @@ const menuSchema = { [_univerjs_ui.RibbonStartGroup.OTHERS]: { [_univerjs_find_r
|
|
|
143
143
|
menuItemFactory: DocsFindReplaceMenuItemFactory
|
|
144
144
|
} } };
|
|
145
145
|
|
|
146
|
-
// \0@oxc-project+runtime@0.
|
|
146
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
147
147
|
function _typeof(o) {
|
|
148
148
|
"@babel/helpers - typeof";
|
|
149
149
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -153,25 +153,25 @@ function _typeof(o) {
|
|
|
153
153
|
}, _typeof(o);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
// \0@oxc-project+runtime@0.
|
|
157
|
-
function toPrimitive(t,
|
|
156
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
157
|
+
function toPrimitive(t, e) {
|
|
158
158
|
if ("object" != _typeof(t) || !t) return t;
|
|
159
|
-
var
|
|
160
|
-
if (void 0 !==
|
|
161
|
-
var i =
|
|
159
|
+
var r;
|
|
160
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
161
|
+
var i = r.call(t, e || "default");
|
|
162
162
|
if ("object" != _typeof(i)) return i;
|
|
163
163
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
164
164
|
}
|
|
165
|
-
return ("string" ===
|
|
165
|
+
return ("string" === e ? String : Number)(t);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
// \0@oxc-project+runtime@0.
|
|
168
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
169
169
|
function toPropertyKey(t) {
|
|
170
170
|
var i = toPrimitive(t, "string");
|
|
171
171
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
// \0@oxc-project+runtime@0.
|
|
174
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
175
175
|
function _defineProperty(e, r, t) {
|
|
176
176
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
177
177
|
value: t,
|
|
@@ -181,14 +181,14 @@ function _defineProperty(e, r, t) {
|
|
|
181
181
|
}) : e[r] = t, e;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
// \0@oxc-project+runtime@0.
|
|
184
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
185
185
|
function __decorateParam(paramIndex, decorator) {
|
|
186
186
|
return function(target, key) {
|
|
187
187
|
decorator(target, key, paramIndex);
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
// \0@oxc-project+runtime@0.
|
|
191
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
192
192
|
function __decorate(decorators, target, key, desc) {
|
|
193
193
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
194
194
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
package/lib/es/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Subject, debounceTime, filter, map, merge as merge$1 } from "rxjs";
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "@univerjs/docs-find-replace";
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.5.1";
|
|
12
12
|
|
|
13
13
|
// src/config/config.ts
|
|
14
14
|
/**
|
|
@@ -142,7 +142,7 @@ const menuSchema = { [RibbonStartGroup.OTHERS]: { [OpenFindDialogOperation.id]:
|
|
|
142
142
|
menuItemFactory: DocsFindReplaceMenuItemFactory
|
|
143
143
|
} } };
|
|
144
144
|
|
|
145
|
-
// \0@oxc-project+runtime@0.
|
|
145
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
146
146
|
function _typeof(o) {
|
|
147
147
|
"@babel/helpers - typeof";
|
|
148
148
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -152,25 +152,25 @@ function _typeof(o) {
|
|
|
152
152
|
}, _typeof(o);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
// \0@oxc-project+runtime@0.
|
|
156
|
-
function toPrimitive(t,
|
|
155
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
156
|
+
function toPrimitive(t, e) {
|
|
157
157
|
if ("object" != _typeof(t) || !t) return t;
|
|
158
|
-
var
|
|
159
|
-
if (void 0 !==
|
|
160
|
-
var i =
|
|
158
|
+
var r;
|
|
159
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
160
|
+
var i = r.call(t, e || "default");
|
|
161
161
|
if ("object" != _typeof(i)) return i;
|
|
162
162
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
163
163
|
}
|
|
164
|
-
return ("string" ===
|
|
164
|
+
return ("string" === e ? String : Number)(t);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
// \0@oxc-project+runtime@0.
|
|
167
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
168
168
|
function toPropertyKey(t) {
|
|
169
169
|
var i = toPrimitive(t, "string");
|
|
170
170
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
// \0@oxc-project+runtime@0.
|
|
173
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
174
174
|
function _defineProperty(e, r, t) {
|
|
175
175
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
176
176
|
value: t,
|
|
@@ -180,14 +180,14 @@ function _defineProperty(e, r, t) {
|
|
|
180
180
|
}) : e[r] = t, e;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
// \0@oxc-project+runtime@0.
|
|
183
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
184
184
|
function __decorateParam(paramIndex, decorator) {
|
|
185
185
|
return function(target, key) {
|
|
186
186
|
decorator(target, key, paramIndex);
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
// \0@oxc-project+runtime@0.
|
|
190
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
191
191
|
function __decorate(decorators, target, key, desc) {
|
|
192
192
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
193
193
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Subject, debounceTime, filter, map, merge as merge$1 } from "rxjs";
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "@univerjs/docs-find-replace";
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.5.1";
|
|
12
12
|
|
|
13
13
|
// src/config/config.ts
|
|
14
14
|
/**
|
|
@@ -142,7 +142,7 @@ const menuSchema = { [RibbonStartGroup.OTHERS]: { [OpenFindDialogOperation.id]:
|
|
|
142
142
|
menuItemFactory: DocsFindReplaceMenuItemFactory
|
|
143
143
|
} } };
|
|
144
144
|
|
|
145
|
-
// \0@oxc-project+runtime@0.
|
|
145
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
146
146
|
function _typeof(o) {
|
|
147
147
|
"@babel/helpers - typeof";
|
|
148
148
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -152,25 +152,25 @@ function _typeof(o) {
|
|
|
152
152
|
}, _typeof(o);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
// \0@oxc-project+runtime@0.
|
|
156
|
-
function toPrimitive(t,
|
|
155
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
156
|
+
function toPrimitive(t, e) {
|
|
157
157
|
if ("object" != _typeof(t) || !t) return t;
|
|
158
|
-
var
|
|
159
|
-
if (void 0 !==
|
|
160
|
-
var i =
|
|
158
|
+
var r;
|
|
159
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
160
|
+
var i = r.call(t, e || "default");
|
|
161
161
|
if ("object" != _typeof(i)) return i;
|
|
162
162
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
163
163
|
}
|
|
164
|
-
return ("string" ===
|
|
164
|
+
return ("string" === e ? String : Number)(t);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
// \0@oxc-project+runtime@0.
|
|
167
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
168
168
|
function toPropertyKey(t) {
|
|
169
169
|
var i = toPrimitive(t, "string");
|
|
170
170
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
// \0@oxc-project+runtime@0.
|
|
173
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
174
174
|
function _defineProperty(e, r, t) {
|
|
175
175
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
176
176
|
value: t,
|
|
@@ -180,14 +180,14 @@ function _defineProperty(e, r, t) {
|
|
|
180
180
|
}) : e[r] = t, e;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
// \0@oxc-project+runtime@0.
|
|
183
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
184
184
|
function __decorateParam(paramIndex, decorator) {
|
|
185
185
|
return function(target, key) {
|
|
186
186
|
decorator(target, key, paramIndex);
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
// \0@oxc-project+runtime@0.
|
|
190
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
191
191
|
function __decorate(decorators, target, key, desc) {
|
|
192
192
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
193
193
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFindReplace={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverEngineRender,e.UniverFindReplace,e.UniverUi,e.rxjs))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=`@univerjs/docs-find-replace`,l=`1.4.0`;let u={};function d(e,n,r,i={text:e.dataStream,characters:Array.from({length:e.dataStream.length},(e,t)=>({startOffset:t,endOffset:t+1,replaceable:!0}))}){if(!n.findString)return[];let a=t.regexp.createLiteralRegExp(n.findString,n.caseSensitive?`gu`:`giu`),o=n.matchesTheWholeWord?new Set(Array.from(new Intl.Segmenter(void 0,{granularity:`word`}).segment(i.text)).filter(e=>e.isWordLike).map(e=>`${e.index}:${e.index+e.segment.length}`)):null;return Array.from(i.text.matchAll(a)).filter(e=>(o==null?void 0:o.has(`${e.index}:${e.index+e[0].length}`))??!0).flatMap(t=>{var n;let a=i.characters.slice(t.index,t.index+t[0].length);if(!a.length)return[];let o=Math.min(...a.map(e=>e.startOffset)),s=Math.max(...a.map(e=>e.endOffset)),c=((n=e.customRanges)==null?void 0:n.some(e=>e.wholeEntity&&e.startIndex<s&&e.endIndex+1>o))??!1;return[{startOffset:o,endOffset:s,replaceable:!r&&!c&&a.every(e=>e.replaceable)}]})}let f={id:`docs.command.replace`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return{success:0,failure:0};let i=e.get(t.IUniverInstanceService),a=e.get(t.ICommandService),o=i.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),s=o==null?void 0:o.getBody();if(!o||!s)return{success:0,failure:+!!r.range};let c=d(s,r.query,!!o.getSnapshot().disabled),l=r.range?c.filter(e=>e.startOffset===r.range.startOffset&&e.endOffset===r.range.endOffset):c,u=l.filter(e=>e.replaceable),f=(r.range&&l.length===0?1:l.length)-u.length;if(!u.length)return{success:0,failure:f};let p=new t.TextX,m=new t.MemoryCursor;for(let e of u){var h,g;let n=o.sliceBody(e.startOffset,e.endOffset),i=r.replaceString?{dataStream:r.replaceString,textRuns:n!=null&&(h=n.textRuns)!=null&&h.length?[{...n.textRuns[0],st:0,ed:r.replaceString.length}]:void 0,customRanges:n!=null&&(g=n.customRanges)!=null&&g.length?[{...n.customRanges[0],startIndex:0,endIndex:r.replaceString.length-1}]:void 0}:null;p.push(...t.BuildTextUtils.selection.delete([{startOffset:e.startOffset,endOffset:e.endOffset,collapsed:!1}],s,m.cursor,i,!1)),m.moveCursorTo(e.endOffset)}let _=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(o));return a.syncExecuteCommand(n.RichTextEditingMutation.id,{unitId:r.unitId,actions:_,textRanges:[]})?{success:u.length,failure:f}:{success:0,failure:f+u.length}}};function p(e){let n=e.get(t.IContextService);return{id:a.OpenFindDialogOperation.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:o.MenuItemType.BUTTON,disabled$:n.subscribeContextValue$(t.FOCUSING_DOC).pipe((0,s.map)(e=>!e))}}let m={[o.RibbonStartGroup.OTHERS]:{[a.OpenFindDialogOperation.id]:{order:3,menuItemFactory:p}}};function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends a.FindModel{constructor(e,r,i,a,o,c,l){super(),this._doc=e,this._skeletonManager=r,this._selectionManager=i,this._renderManagerService=a,this._commandService=o,this._themeService=c,this._textResolverService=l,v(this,`_matchesUpdate$`,new s.Subject),v(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),v(this,`_activelyChangingMatch$`,new s.Subject),v(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),v(this,`_matches`,[]),v(this,`_position`,-1),v(this,`_query`,null),v(this,`_highlights`,[]),v(this,`unitId`,void 0),this.unitId=e.getUnitId(),this.disposeWithMe((0,t.toDisposable)((0,s.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>e.id===n.RichTextEditingMutation.id&&S(e.params)===this.unitId)),this._textResolverService.textChanged$.pipe((0,s.filter)(e=>e===this.unitId))).pipe((0,s.debounceTime)(220)).subscribe(()=>this._scan(!0)))),this.disposeWithMe((0,t.toDisposable)(this._skeletonManager.currentSkeleton$.subscribe(()=>this._refreshHighlights())))}get currentMatch(){return this._position<0?null:this._matches[this._position]??null}dispose(){super.dispose(),this._disposeHighlights(),this._matchesUpdate$.complete(),this._activelyChangingMatch$.complete()}getMatches(){return this._matches}start(e){this._query=e,this._position=-1,this._scan(!1)}moveToNextMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=0;else if(this._position>=0)t=this._position+1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findIndex(e=>e.range.startOffset>=((n==null?void 0:n.endOffset)??0))}return(t<0||t>=this._matches.length)&&(t=e!=null&&e.loop?0:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}moveToPreviousMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=this._matches.length-1;else if(this._position>=0)t=this._position-1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findLastIndex(e=>e.range.endOffset<=((n==null?void 0:n.startOffset)??0))}return t<0&&(t=e!=null&&e.loop?this._matches.length-1:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}async replace(e){let t=this.currentMatch;if(!(t!=null&&t.replaceable)||!this._query)return!1;let n=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e,range:t.range});return(n==null?void 0:n.success)===1}async replaceAll(e){return this._query?await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e})??{success:0,failure:this._matches.length}:{success:0,failure:0}}focusSelection(){this.currentMatch&&this._focusMatch(this.currentMatch)}_scan(e){var t;if(!this._query)return;let n=this._doc.getBody();if(!n){this._matches=[],this._position=-1,this._disposeHighlights(),e&&this._matchesUpdate$.next([]);return}let r=(t=this.currentMatch)==null?void 0:t.range.startOffset;this._matches=d(n,this._query,!!this._doc.getSnapshot().disabled,this._textResolverService.resolve(this.unitId,n)).map(e=>({provider:`docs-find-replace-provider`,unitId:this.unitId,range:{...e,collapsed:!1},replaceable:e.replaceable})),this._position=r==null?-1:this._matches.findIndex(e=>e.range.startOffset>=r),this._refreshHighlights(),e&&this._matchesUpdate$.next(this._matches)}_selectionMatchIndex(){let e=this._selectionManager.getActiveTextRange();return e?this._matches.findIndex(t=>t.range.startOffset<=e.startOffset&&t.range.endOffset>=e.endOffset):-1}_activate(e,t=!1){let n=this._matches[e];return n?(this._position=e,t?this._refreshHighlights():this._focusMatch(n),n):null}_focusMatch(e){var t;this._selectionManager.replaceDocRanges([e.range],{unitId:this.unitId,subUnitId:this.unitId},!0,{shouldFocus:!1}),(t=this._renderManagerService.getRenderUnitById(this.unitId))==null||t.with(r.DocBackScrollRenderController).scrollToRange(e.range),this._activelyChangingMatch$.next(e),this._refreshHighlights()}_refreshHighlights(){this._disposeHighlights();let e=this._renderManagerService.getRenderUnitById(this.unitId),n=this._skeletonManager.getSkeleton(),i=e==null?void 0:e.mainComponent;if(!e||!n||!i)return;let a=this._themeService.getColorFromTheme(`yellow.400`),o={strokeWidth:0,stroke:`rgba(0,0,0,0)`,strokeActive:`rgba(0,0,0,0)`,fill:new t.ColorKit(a).setAlpha(.3).toRgbString()},s={...o,fill:new t.ColorKit(a).setAlpha(.65).toRgbString()};this._matches.forEach((t,a)=>{let c=(0,r.getTextRangeFromCharIndex)(t.range.startOffset,t.range.endOffset,e.scene,i,n,a===this._position?s:o,``,-1);c&&this._highlights.push(c)})}_disposeHighlights(){this._highlights.forEach(e=>e.dispose()),this._highlights=[]}};x=b([y(2,(0,t.Inject)(n.DocSelectionManagerService)),y(3,i.IRenderManagerService),y(4,t.ICommandService),y(5,(0,t.Inject)(t.ThemeService)),y(6,(0,t.Inject)(n.DocTextResolverService))],x);function S(e){return typeof e==`object`&&e&&`unitId`in e&&typeof e.unitId==`string`?e.unitId:void 0}let C=class extends t.Disposable{constructor(e,t,n){super(),this._instanceService=e,this._renderManagerService=t,this._injector=n,v(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!0,matchesTheWholeCell:!1,findDirection:!1,findScope:!1,findBy:!1}),v(this,`_model`,null)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_DOC}async find(e){var r;this.terminate();let i=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!i)return[];let a=(r=this._renderManagerService.getRenderUnitById(i.getUnitId()))==null?void 0:r.with(n.DocSkeletonManagerService);return a?(this._model=this._injector.createInstance(x,i,a),this._model.start(e),[this._model]):[]}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null}dispose(){this.terminate(),super.dispose()}};C=b([y(0,t.IUniverInstanceService),y(1,i.IRenderManagerService),y(2,(0,t.Inject)(t.Injector))],C);let w=class extends t.Disposable{constructor(e,t,n,r){super(),this.disposeWithMe(e),this.disposeWithMe(t.registerFindReplaceProvider(e)),this.disposeWithMe(n.registerCommand(f)),r.mergeMenu(m)}};w=b([y(0,(0,t.Inject)(C)),y(1,a.IFindReplaceService),y(2,t.ICommandService),y(3,o.IMenuManagerService)],w);let T=class extends t.Plugin{constructor(e=u,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},u,this._config);this._configService.setConfig(`docs-find-replace.config`,i)}onStarting(){this._injector.add([C]),this._injector.add([w])}onSteady(){this._injector.get(w)}};v(T,`pluginName`,`DOCS_FIND_REPLACE_PLUGIN`),v(T,`packageName`,c),v(T,`version`,l),v(T,`type`,t.UniverInstanceType.UNIVER_DOC),T=b([(0,t.DependentOn)(n.UniverDocsPlugin,i.UniverRenderEnginePlugin,r.UniverDocsUIPlugin,a.UniverFindReplacePlugin),y(1,(0,t.Inject)(t.Injector)),y(2,t.IConfigService)],T),Object.defineProperty(e,"UniverDocsFindReplacePlugin",{enumerable:!0,get:function(){return T}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsFindReplace={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverEngineRender,e.UniverFindReplace,e.UniverUi,e.rxjs))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=`@univerjs/docs-find-replace`,l=`1.5.1`;let u={};function d(e,n,r,i={text:e.dataStream,characters:Array.from({length:e.dataStream.length},(e,t)=>({startOffset:t,endOffset:t+1,replaceable:!0}))}){if(!n.findString)return[];let a=t.regexp.createLiteralRegExp(n.findString,n.caseSensitive?`gu`:`giu`),o=n.matchesTheWholeWord?new Set(Array.from(new Intl.Segmenter(void 0,{granularity:`word`}).segment(i.text)).filter(e=>e.isWordLike).map(e=>`${e.index}:${e.index+e.segment.length}`)):null;return Array.from(i.text.matchAll(a)).filter(e=>(o==null?void 0:o.has(`${e.index}:${e.index+e[0].length}`))??!0).flatMap(t=>{var n;let a=i.characters.slice(t.index,t.index+t[0].length);if(!a.length)return[];let o=Math.min(...a.map(e=>e.startOffset)),s=Math.max(...a.map(e=>e.endOffset)),c=((n=e.customRanges)==null?void 0:n.some(e=>e.wholeEntity&&e.startIndex<s&&e.endIndex+1>o))??!1;return[{startOffset:o,endOffset:s,replaceable:!r&&!c&&a.every(e=>e.replaceable)}]})}let f={id:`docs.command.replace`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return{success:0,failure:0};let i=e.get(t.IUniverInstanceService),a=e.get(t.ICommandService),o=i.getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),s=o==null?void 0:o.getBody();if(!o||!s)return{success:0,failure:+!!r.range};let c=d(s,r.query,!!o.getSnapshot().disabled),l=r.range?c.filter(e=>e.startOffset===r.range.startOffset&&e.endOffset===r.range.endOffset):c,u=l.filter(e=>e.replaceable),f=(r.range&&l.length===0?1:l.length)-u.length;if(!u.length)return{success:0,failure:f};let p=new t.TextX,m=new t.MemoryCursor;for(let e of u){var h,g;let n=o.sliceBody(e.startOffset,e.endOffset),i=r.replaceString?{dataStream:r.replaceString,textRuns:n!=null&&(h=n.textRuns)!=null&&h.length?[{...n.textRuns[0],st:0,ed:r.replaceString.length}]:void 0,customRanges:n!=null&&(g=n.customRanges)!=null&&g.length?[{...n.customRanges[0],startIndex:0,endIndex:r.replaceString.length-1}]:void 0}:null;p.push(...t.BuildTextUtils.selection.delete([{startOffset:e.startOffset,endOffset:e.endOffset,collapsed:!1}],s,m.cursor,i,!1)),m.moveCursorTo(e.endOffset)}let _=t.JSONX.getInstance().editOp(p.serialize(),(0,t.getRichTextEditPath)(o));return a.syncExecuteCommand(n.RichTextEditingMutation.id,{unitId:r.unitId,actions:_,textRanges:[]})?{success:u.length,failure:f}:{success:0,failure:f+u.length}}};function p(e){let n=e.get(t.IContextService);return{id:a.OpenFindDialogOperation.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:o.MenuItemType.BUTTON,disabled$:n.subscribeContextValue$(t.FOCUSING_DOC).pipe((0,s.map)(e=>!e))}}let m={[o.RibbonStartGroup.OTHERS]:{[a.OpenFindDialogOperation.id]:{order:3,menuItemFactory:p}}};function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends a.FindModel{constructor(e,r,i,a,o,c,l){super(),this._doc=e,this._skeletonManager=r,this._selectionManager=i,this._renderManagerService=a,this._commandService=o,this._themeService=c,this._textResolverService=l,v(this,`_matchesUpdate$`,new s.Subject),v(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),v(this,`_activelyChangingMatch$`,new s.Subject),v(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),v(this,`_matches`,[]),v(this,`_position`,-1),v(this,`_query`,null),v(this,`_highlights`,[]),v(this,`unitId`,void 0),this.unitId=e.getUnitId(),this.disposeWithMe((0,t.toDisposable)((0,s.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>e.id===n.RichTextEditingMutation.id&&S(e.params)===this.unitId)),this._textResolverService.textChanged$.pipe((0,s.filter)(e=>e===this.unitId))).pipe((0,s.debounceTime)(220)).subscribe(()=>this._scan(!0)))),this.disposeWithMe((0,t.toDisposable)(this._skeletonManager.currentSkeleton$.subscribe(()=>this._refreshHighlights())))}get currentMatch(){return this._position<0?null:this._matches[this._position]??null}dispose(){super.dispose(),this._disposeHighlights(),this._matchesUpdate$.complete(),this._activelyChangingMatch$.complete()}getMatches(){return this._matches}start(e){this._query=e,this._position=-1,this._scan(!1)}moveToNextMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=0;else if(this._position>=0)t=this._position+1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findIndex(e=>e.range.startOffset>=((n==null?void 0:n.endOffset)??0))}return(t<0||t>=this._matches.length)&&(t=e!=null&&e.loop?0:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}moveToPreviousMatch(e){if(!this._matches.length)return null;if(e!=null&&e.stayIfOnMatch&&this.currentMatch)return this._activate(this._position,e.noFocus);let t;if(e!=null&&e.ignoreSelection)t=this._matches.length-1;else if(this._position>=0)t=this._position-1;else{let n=this._selectionManager.getActiveTextRange(),r=e!=null&&e.stayIfOnMatch?this._selectionMatchIndex():-1;t=r>=0?r:this._matches.findLastIndex(e=>e.range.endOffset<=((n==null?void 0:n.startOffset)??0))}return t<0&&(t=e!=null&&e.loop?this._matches.length-1:-1),t<0?(this._position=-1,this._refreshHighlights(),null):this._activate(t,e==null?void 0:e.noFocus)}async replace(e){let t=this.currentMatch;if(!(t!=null&&t.replaceable)||!this._query)return!1;let n=await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e,range:t.range});return(n==null?void 0:n.success)===1}async replaceAll(e){return this._query?await this._commandService.executeCommand(f.id,{unitId:this.unitId,query:this._query,replaceString:e})??{success:0,failure:this._matches.length}:{success:0,failure:0}}focusSelection(){this.currentMatch&&this._focusMatch(this.currentMatch)}_scan(e){var t;if(!this._query)return;let n=this._doc.getBody();if(!n){this._matches=[],this._position=-1,this._disposeHighlights(),e&&this._matchesUpdate$.next([]);return}let r=(t=this.currentMatch)==null?void 0:t.range.startOffset;this._matches=d(n,this._query,!!this._doc.getSnapshot().disabled,this._textResolverService.resolve(this.unitId,n)).map(e=>({provider:`docs-find-replace-provider`,unitId:this.unitId,range:{...e,collapsed:!1},replaceable:e.replaceable})),this._position=r==null?-1:this._matches.findIndex(e=>e.range.startOffset>=r),this._refreshHighlights(),e&&this._matchesUpdate$.next(this._matches)}_selectionMatchIndex(){let e=this._selectionManager.getActiveTextRange();return e?this._matches.findIndex(t=>t.range.startOffset<=e.startOffset&&t.range.endOffset>=e.endOffset):-1}_activate(e,t=!1){let n=this._matches[e];return n?(this._position=e,t?this._refreshHighlights():this._focusMatch(n),n):null}_focusMatch(e){var t;this._selectionManager.replaceDocRanges([e.range],{unitId:this.unitId,subUnitId:this.unitId},!0,{shouldFocus:!1}),(t=this._renderManagerService.getRenderUnitById(this.unitId))==null||t.with(r.DocBackScrollRenderController).scrollToRange(e.range),this._activelyChangingMatch$.next(e),this._refreshHighlights()}_refreshHighlights(){this._disposeHighlights();let e=this._renderManagerService.getRenderUnitById(this.unitId),n=this._skeletonManager.getSkeleton(),i=e==null?void 0:e.mainComponent;if(!e||!n||!i)return;let a=this._themeService.getColorFromTheme(`yellow.400`),o={strokeWidth:0,stroke:`rgba(0,0,0,0)`,strokeActive:`rgba(0,0,0,0)`,fill:new t.ColorKit(a).setAlpha(.3).toRgbString()},s={...o,fill:new t.ColorKit(a).setAlpha(.65).toRgbString()};this._matches.forEach((t,a)=>{let c=(0,r.getTextRangeFromCharIndex)(t.range.startOffset,t.range.endOffset,e.scene,i,n,a===this._position?s:o,``,-1);c&&this._highlights.push(c)})}_disposeHighlights(){this._highlights.forEach(e=>e.dispose()),this._highlights=[]}};x=b([y(2,(0,t.Inject)(n.DocSelectionManagerService)),y(3,i.IRenderManagerService),y(4,t.ICommandService),y(5,(0,t.Inject)(t.ThemeService)),y(6,(0,t.Inject)(n.DocTextResolverService))],x);function S(e){return typeof e==`object`&&e&&`unitId`in e&&typeof e.unitId==`string`?e.unitId:void 0}let C=class extends t.Disposable{constructor(e,t,n){super(),this._instanceService=e,this._renderManagerService=t,this._injector=n,v(this,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!0,matchesTheWholeCell:!1,findDirection:!1,findScope:!1,findBy:!1}),v(this,`_model`,null)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_DOC}async find(e){var r;this.terminate();let i=this._instanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!i)return[];let a=(r=this._renderManagerService.getRenderUnitById(i.getUnitId()))==null?void 0:r.with(n.DocSkeletonManagerService);return a?(this._model=this._injector.createInstance(x,i,a),this._model.start(e),[this._model]):[]}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null}dispose(){this.terminate(),super.dispose()}};C=b([y(0,t.IUniverInstanceService),y(1,i.IRenderManagerService),y(2,(0,t.Inject)(t.Injector))],C);let w=class extends t.Disposable{constructor(e,t,n,r){super(),this.disposeWithMe(e),this.disposeWithMe(t.registerFindReplaceProvider(e)),this.disposeWithMe(n.registerCommand(f)),r.mergeMenu(m)}};w=b([y(0,(0,t.Inject)(C)),y(1,a.IFindReplaceService),y(2,t.ICommandService),y(3,o.IMenuManagerService)],w);let T=class extends t.Plugin{constructor(e=u,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},u,this._config);this._configService.setConfig(`docs-find-replace.config`,i)}onStarting(){this._injector.add([C]),this._injector.add([w])}onSteady(){this._injector.get(w)}};v(T,`pluginName`,`DOCS_FIND_REPLACE_PLUGIN`),v(T,`packageName`,c),v(T,`version`,l),v(T,`type`,t.UniverInstanceType.UNIVER_DOC),T=b([(0,t.DependentOn)(n.UniverDocsPlugin,i.UniverRenderEnginePlugin,r.UniverDocsUIPlugin,a.UniverFindReplacePlugin),y(1,(0,t.Inject)(t.Injector)),y(2,t.IConfigService)],T),Object.defineProperty(e,"UniverDocsFindReplacePlugin",{enumerable:!0,get:function(){return T}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-find-replace",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Find and replace support for Univer Docs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"rxjs": ">=7.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@univerjs/core": "1.
|
|
56
|
-
"@univerjs/docs": "1.
|
|
57
|
-
"@univerjs/docs-ui": "1.
|
|
58
|
-
"@univerjs/engine-render": "1.
|
|
59
|
-
"@univerjs/find-replace": "1.
|
|
60
|
-
"@univerjs/ui": "1.
|
|
55
|
+
"@univerjs/core": "1.5.1",
|
|
56
|
+
"@univerjs/docs": "1.5.1",
|
|
57
|
+
"@univerjs/docs-ui": "1.5.1",
|
|
58
|
+
"@univerjs/engine-render": "1.5.1",
|
|
59
|
+
"@univerjs/find-replace": "1.5.1",
|
|
60
|
+
"@univerjs/ui": "1.5.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@univerjs-infra/shared": "1.
|
|
63
|
+
"@univerjs-infra/shared": "1.5.1",
|
|
64
64
|
"react": "18.3.1",
|
|
65
65
|
"rxjs": "7.8.2",
|
|
66
|
-
"tsrs": "0.
|
|
67
|
-
"vitest": "^5.0
|
|
66
|
+
"tsrs": "0.23.0-ts7.1.0-beta",
|
|
67
|
+
"vitest": "^5.1.0"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "vitest run",
|