@superdoc-dev/cli 0.5.0-next.13 → 0.5.0-next.14

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 (2) hide show
  1. package/dist/index.js +425 -206
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -171649,7 +171649,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
171649
171649
  init_remark_gfm_z_sDF4ss_es();
171650
171650
  });
171651
171651
 
171652
- // ../../packages/superdoc/dist/chunks/src-C1tSJ0Z5.es.js
171652
+ // ../../packages/superdoc/dist/chunks/src-Lvsnnb5c.es.js
171653
171653
  function deleteProps(obj, propOrProps) {
171654
171654
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
171655
171655
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -236511,173 +236511,40 @@ var Node$13 = class Node$14 {
236511
236511
  this.deco = deco;
236512
236512
  }
236513
236513
  }, searchKey, BLOCK_SEPARATOR = `
236514
- `, ATOM_PLACEHOLDER = "", SearchIndex = class SearchIndex2 {
236515
- text = "";
236516
- segments = [];
236517
- valid = false;
236518
- docSize = 0;
236519
- doc = null;
236520
- build(doc$12) {
236521
- this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
236522
- this.segments = [];
236523
- this.docSize = doc$12.content.size;
236524
- this.doc = doc$12;
236525
- let offset$1 = 0;
236526
- this.#walkNodeContent(doc$12, 0, offset$1, (segment) => {
236527
- this.segments.push(segment);
236528
- offset$1 = segment.offsetEnd;
236529
- });
236530
- this.valid = true;
236531
- }
236532
- #walkNodeContent(node3, contentStart, offset$1, addSegment) {
236533
- let currentOffset = offset$1;
236534
- let isFirstChild = true;
236535
- node3.forEach((child, childContentOffset) => {
236536
- const childDocPos = contentStart + childContentOffset;
236537
- if (child.isBlock && !isFirstChild) {
236538
- addSegment({
236539
- offsetStart: currentOffset,
236540
- offsetEnd: currentOffset + 1,
236541
- docFrom: childDocPos,
236542
- docTo: childDocPos,
236543
- kind: "blockSep"
236544
- });
236545
- currentOffset += 1;
236546
- }
236547
- currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment);
236548
- isFirstChild = false;
236549
- });
236550
- return currentOffset;
236551
- }
236552
- #walkNode(node3, docPos, offset$1, addSegment) {
236553
- if (node3.isText) {
236554
- const text5 = node3.text || "";
236555
- if (text5.length > 0) {
236556
- addSegment({
236557
- offsetStart: offset$1,
236558
- offsetEnd: offset$1 + text5.length,
236559
- docFrom: docPos,
236560
- docTo: docPos + text5.length,
236561
- kind: "text"
236562
- });
236563
- return offset$1 + text5.length;
236564
- }
236565
- return offset$1;
236566
- }
236567
- if (node3.isLeaf) {
236568
- if (node3.type.name === "hard_break") {
236569
- addSegment({
236570
- offsetStart: offset$1,
236571
- offsetEnd: offset$1 + 1,
236572
- docFrom: docPos,
236573
- docTo: docPos + node3.nodeSize,
236574
- kind: "hardBreak"
236575
- });
236576
- return offset$1 + 1;
236577
- }
236578
- addSegment({
236579
- offsetStart: offset$1,
236580
- offsetEnd: offset$1 + 1,
236581
- docFrom: docPos,
236582
- docTo: docPos + node3.nodeSize,
236583
- kind: "atom"
236584
- });
236585
- return offset$1 + 1;
236586
- }
236587
- return this.#walkNodeContent(node3, docPos + 1, offset$1, addSegment);
236588
- }
236589
- invalidate() {
236590
- this.valid = false;
236591
- }
236592
- isStale(doc$12) {
236593
- return !this.valid || this.doc !== doc$12;
236594
- }
236595
- ensureValid(doc$12) {
236596
- if (this.isStale(doc$12))
236597
- this.build(doc$12);
236598
- }
236599
- offsetRangeToDocRanges(start$1, end$1) {
236600
- const ranges = [];
236601
- for (const segment of this.segments) {
236602
- if (segment.offsetEnd <= start$1)
236603
- continue;
236604
- if (segment.offsetStart >= end$1)
236605
- break;
236606
- if (segment.kind !== "text")
236607
- continue;
236608
- const overlapStart = Math.max(start$1, segment.offsetStart);
236609
- const overlapEnd = Math.min(end$1, segment.offsetEnd);
236610
- if (overlapStart < overlapEnd) {
236611
- const startInSegment = overlapStart - segment.offsetStart;
236612
- const endInSegment = overlapEnd - segment.offsetStart;
236613
- ranges.push({
236614
- from: segment.docFrom + startInSegment,
236615
- to: segment.docFrom + endInSegment
236616
- });
236617
- }
236618
- }
236619
- return ranges;
236620
- }
236621
- offsetToDocPos(offset$1) {
236622
- for (const segment of this.segments)
236623
- if (offset$1 >= segment.offsetStart && offset$1 < segment.offsetEnd) {
236624
- if (segment.kind === "text")
236625
- return segment.docFrom + (offset$1 - segment.offsetStart);
236626
- return segment.docFrom;
236514
+ `, ATOM_PLACEHOLDER = "", SearchIndex, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", mapIndexMatchesToDocMatches = ({ searchIndex, indexMatches, doc: doc$12, positionTracker }) => {
236515
+ const matches2 = [];
236516
+ for (const indexMatch of indexMatches) {
236517
+ const ranges = searchIndex.offsetRangeToDocRanges(indexMatch.start, indexMatch.end);
236518
+ if (ranges.length === 0)
236519
+ continue;
236520
+ const matchTexts = ranges.map((r$1) => doc$12.textBetween(r$1.from, r$1.to));
236521
+ const match$1 = {
236522
+ from: ranges[0].from,
236523
+ to: ranges[ranges.length - 1].to,
236524
+ text: matchTexts.join(""),
236525
+ id: v4_default(),
236526
+ ranges,
236527
+ trackerIds: []
236528
+ };
236529
+ if (positionTracker?.trackMany) {
236530
+ const trackedRanges = ranges.map((range, rangeIndex) => ({
236531
+ from: range.from,
236532
+ to: range.to,
236533
+ spec: {
236534
+ type: SEARCH_POSITION_TRACKER_TYPE,
236535
+ metadata: { rangeIndex }
236536
+ }
236537
+ }));
236538
+ const trackerIds = positionTracker.trackMany(trackedRanges);
236539
+ if (trackerIds.length > 0) {
236540
+ match$1.trackerIds = trackerIds;
236541
+ match$1.id = trackerIds[0];
236627
236542
  }
236628
- if (this.segments.length > 0 && offset$1 === this.segments[this.segments.length - 1].offsetEnd)
236629
- return this.segments[this.segments.length - 1].docTo;
236630
- return null;
236631
- }
236632
- static escapeRegex(str) {
236633
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
236634
- }
236635
- static toFlexiblePattern(searchString) {
236636
- const hasLeadingWhitespace = /^[\s\u00a0]+/.test(searchString);
236637
- const hasTrailingWhitespace = /[\s\u00a0]+$/.test(searchString);
236638
- const parts = searchString.replace(/^[\s\u00a0]+|[\s\u00a0]+$/g, "").split(/[\s\u00a0]+/).filter((part) => part.length > 0);
236639
- if (parts.length === 0)
236640
- return hasLeadingWhitespace || hasTrailingWhitespace ? "[\\s\\u00a0]+" : "";
236641
- const blockSeparatorPattern = "(?:\\n)*";
236642
- let pattern = parts.map((part) => {
236643
- return Array.from(part).map((ch) => SearchIndex2.escapeRegex(ch)).join(blockSeparatorPattern);
236644
- }).join("[\\s\\u00a0]+");
236645
- if (hasLeadingWhitespace)
236646
- pattern = "[\\s\\u00a0]+" + pattern;
236647
- if (hasTrailingWhitespace)
236648
- pattern = pattern + "[\\s\\u00a0]+";
236649
- return pattern;
236650
- }
236651
- search(pattern, options = {}) {
236652
- const { caseSensitive = false, maxMatches = 1000 } = options;
236653
- const matches2 = [];
236654
- let regex;
236655
- if (pattern instanceof RegExp) {
236656
- const flags = pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g";
236657
- regex = new RegExp(pattern.source, flags);
236658
- } else if (typeof pattern === "string") {
236659
- if (pattern.length === 0)
236660
- return matches2;
236661
- const flexiblePattern = SearchIndex2.toFlexiblePattern(pattern);
236662
- if (flexiblePattern.length === 0)
236663
- return matches2;
236664
- const flags = caseSensitive ? "g" : "gi";
236665
- regex = new RegExp(flexiblePattern, flags);
236666
- } else
236667
- return matches2;
236668
- let match$1;
236669
- while ((match$1 = regex.exec(this.text)) !== null && matches2.length < maxMatches) {
236670
- matches2.push({
236671
- start: match$1.index,
236672
- end: match$1.index + match$1[0].length,
236673
- text: match$1[0]
236674
- });
236675
- if (match$1[0].length === 0)
236676
- regex.lastIndex++;
236677
236543
  }
236678
- return matches2;
236544
+ matches2.push(match$1);
236679
236545
  }
236680
- }, customSearchHighlightsKey, isRegExp2 = (value) => Object.prototype.toString.call(value) === "[object RegExp]", SEARCH_POSITION_TRACKER_TYPE = "search-match", resolveMatchSelectionRange = (match$1, positionTracker) => {
236546
+ return matches2;
236547
+ }, resolveMatchSelectionRange = (match$1, positionTracker) => {
236681
236548
  if (!match$1)
236682
236549
  return {
236683
236550
  from: undefined,
@@ -252760,7 +252627,7 @@ var Node$13 = class Node$14 {
252760
252627
  return;
252761
252628
  console.log(...args$1);
252762
252629
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
252763
- var init_src_C1tSJ0Z5_es = __esm(() => {
252630
+ var init_src_Lvsnnb5c_es = __esm(() => {
252764
252631
  init_rolldown_runtime_B2q5OVn9_es();
252765
252632
  init_SuperConverter_OPfy6vj2_es();
252766
252633
  init_jszip_ChlR43oI_es();
@@ -270075,13 +269942,240 @@ function print() { __p += __j.call(arguments, '') }
270075
269942
  replaceCommand(true, true);
270076
269943
  replaceCommand(false, true);
270077
269944
  replaceCommand(false, false);
269945
+ SearchIndex = class SearchIndex2 {
269946
+ text = "";
269947
+ segments = [];
269948
+ valid = false;
269949
+ docSize = 0;
269950
+ doc = null;
269951
+ build(doc$12) {
269952
+ this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
269953
+ this.segments = [];
269954
+ this.docSize = doc$12.content.size;
269955
+ this.doc = doc$12;
269956
+ let offset$1 = 0;
269957
+ this.#walkNodeContent(doc$12, 0, offset$1, (segment) => {
269958
+ this.segments.push(segment);
269959
+ offset$1 = segment.offsetEnd;
269960
+ });
269961
+ this.valid = true;
269962
+ }
269963
+ #walkNodeContent(node3, contentStart, offset$1, addSegment) {
269964
+ let currentOffset = offset$1;
269965
+ let isFirstChild = true;
269966
+ node3.forEach((child, childContentOffset) => {
269967
+ const childDocPos = contentStart + childContentOffset;
269968
+ if (child.isBlock && !isFirstChild) {
269969
+ addSegment({
269970
+ offsetStart: currentOffset,
269971
+ offsetEnd: currentOffset + 1,
269972
+ docFrom: childDocPos,
269973
+ docTo: childDocPos,
269974
+ kind: "blockSep"
269975
+ });
269976
+ currentOffset += 1;
269977
+ }
269978
+ currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment);
269979
+ isFirstChild = false;
269980
+ });
269981
+ return currentOffset;
269982
+ }
269983
+ #walkNode(node3, docPos, offset$1, addSegment) {
269984
+ if (node3.isText) {
269985
+ const text5 = node3.text || "";
269986
+ if (text5.length > 0) {
269987
+ addSegment({
269988
+ offsetStart: offset$1,
269989
+ offsetEnd: offset$1 + text5.length,
269990
+ docFrom: docPos,
269991
+ docTo: docPos + text5.length,
269992
+ kind: "text"
269993
+ });
269994
+ return offset$1 + text5.length;
269995
+ }
269996
+ return offset$1;
269997
+ }
269998
+ if (node3.isLeaf) {
269999
+ if (node3.type.name === "hard_break") {
270000
+ addSegment({
270001
+ offsetStart: offset$1,
270002
+ offsetEnd: offset$1 + 1,
270003
+ docFrom: docPos,
270004
+ docTo: docPos + node3.nodeSize,
270005
+ kind: "hardBreak"
270006
+ });
270007
+ return offset$1 + 1;
270008
+ }
270009
+ addSegment({
270010
+ offsetStart: offset$1,
270011
+ offsetEnd: offset$1 + 1,
270012
+ docFrom: docPos,
270013
+ docTo: docPos + node3.nodeSize,
270014
+ kind: "atom"
270015
+ });
270016
+ return offset$1 + 1;
270017
+ }
270018
+ return this.#walkNodeContent(node3, docPos + 1, offset$1, addSegment);
270019
+ }
270020
+ invalidate() {
270021
+ this.valid = false;
270022
+ }
270023
+ isStale(doc$12) {
270024
+ return !this.valid || this.doc !== doc$12;
270025
+ }
270026
+ ensureValid(doc$12) {
270027
+ if (this.isStale(doc$12))
270028
+ this.build(doc$12);
270029
+ }
270030
+ offsetRangeToDocRanges(start$1, end$1) {
270031
+ const ranges = [];
270032
+ for (const segment of this.segments) {
270033
+ if (segment.offsetEnd <= start$1)
270034
+ continue;
270035
+ if (segment.offsetStart >= end$1)
270036
+ break;
270037
+ if (segment.kind !== "text")
270038
+ continue;
270039
+ const overlapStart = Math.max(start$1, segment.offsetStart);
270040
+ const overlapEnd = Math.min(end$1, segment.offsetEnd);
270041
+ if (overlapStart < overlapEnd) {
270042
+ const startInSegment = overlapStart - segment.offsetStart;
270043
+ const endInSegment = overlapEnd - segment.offsetStart;
270044
+ ranges.push({
270045
+ from: segment.docFrom + startInSegment,
270046
+ to: segment.docFrom + endInSegment
270047
+ });
270048
+ }
270049
+ }
270050
+ return ranges;
270051
+ }
270052
+ offsetToDocPos(offset$1) {
270053
+ for (const segment of this.segments)
270054
+ if (offset$1 >= segment.offsetStart && offset$1 < segment.offsetEnd) {
270055
+ if (segment.kind === "text")
270056
+ return segment.docFrom + (offset$1 - segment.offsetStart);
270057
+ return segment.docFrom;
270058
+ }
270059
+ if (this.segments.length > 0 && offset$1 === this.segments[this.segments.length - 1].offsetEnd)
270060
+ return this.segments[this.segments.length - 1].docTo;
270061
+ return null;
270062
+ }
270063
+ static escapeRegex(str) {
270064
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
270065
+ }
270066
+ static toFlexiblePattern(searchString) {
270067
+ const hasLeadingWhitespace = /^[\s\u00a0]+/.test(searchString);
270068
+ const hasTrailingWhitespace = /[\s\u00a0]+$/.test(searchString);
270069
+ const parts = searchString.replace(/^[\s\u00a0]+|[\s\u00a0]+$/g, "").split(/[\s\u00a0]+/).filter((part) => part.length > 0);
270070
+ if (parts.length === 0)
270071
+ return hasLeadingWhitespace || hasTrailingWhitespace ? "[\\s\\u00a0]+" : "";
270072
+ const blockSeparatorPattern = "(?:\\n)*";
270073
+ let pattern = parts.map((part) => {
270074
+ return Array.from(part).map((ch) => SearchIndex2.escapeRegex(ch)).join(blockSeparatorPattern);
270075
+ }).join("[\\s\\u00a0]+");
270076
+ if (hasLeadingWhitespace)
270077
+ pattern = "[\\s\\u00a0]+" + pattern;
270078
+ if (hasTrailingWhitespace)
270079
+ pattern = pattern + "[\\s\\u00a0]+";
270080
+ return pattern;
270081
+ }
270082
+ search(pattern, options = {}) {
270083
+ const { caseSensitive = false, maxMatches = 1000 } = options;
270084
+ const matches2 = [];
270085
+ let regex;
270086
+ if (pattern instanceof RegExp) {
270087
+ const flags = pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g";
270088
+ regex = new RegExp(pattern.source, flags);
270089
+ } else if (typeof pattern === "string") {
270090
+ if (pattern.length === 0)
270091
+ return matches2;
270092
+ const flexiblePattern = SearchIndex2.toFlexiblePattern(pattern);
270093
+ if (flexiblePattern.length === 0)
270094
+ return matches2;
270095
+ const flags = caseSensitive ? "g" : "gi";
270096
+ regex = new RegExp(flexiblePattern, flags);
270097
+ } else
270098
+ return matches2;
270099
+ let match$1;
270100
+ while ((match$1 = regex.exec(this.text)) !== null && matches2.length < maxMatches) {
270101
+ matches2.push({
270102
+ start: match$1.index,
270103
+ end: match$1.index + match$1[0].length,
270104
+ text: match$1[0]
270105
+ });
270106
+ if (match$1[0].length === 0)
270107
+ regex.lastIndex++;
270108
+ }
270109
+ return matches2;
270110
+ }
270111
+ static DIACRITICS_PATTERN = /[\u0300-\u036f\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7]/g;
270112
+ static stripDiacritics(str) {
270113
+ return str.normalize("NFD").replace(SearchIndex2.DIACRITICS_PATTERN, "");
270114
+ }
270115
+ static buildDiacriticOffsetMap(original) {
270116
+ const nfd = original.normalize("NFD");
270117
+ const toOriginal = [];
270118
+ let foldedChars = [];
270119
+ const nfdToOriginal = [];
270120
+ let origIdx = 0;
270121
+ for (let nfdIdx = 0;nfdIdx < nfd.length; ) {
270122
+ const origNfd = original[origIdx].normalize("NFD");
270123
+ for (let k$1 = 0;k$1 < origNfd.length; k$1++)
270124
+ nfdToOriginal[nfdIdx + k$1] = origIdx;
270125
+ nfdIdx += origNfd.length;
270126
+ origIdx++;
270127
+ }
270128
+ for (let nfdIdx = 0;nfdIdx < nfd.length; nfdIdx++) {
270129
+ const cp = nfd.charCodeAt(nfdIdx);
270130
+ if (cp >= 768 && cp <= 879 || cp >= 1425 && cp <= 1469 || cp === 1471 || cp === 1473 || cp === 1474 || cp === 1476 || cp === 1477 || cp === 1479)
270131
+ continue;
270132
+ foldedChars.push(nfd[nfdIdx]);
270133
+ toOriginal.push(nfdToOriginal[nfdIdx]);
270134
+ }
270135
+ toOriginal.push(original.length);
270136
+ return {
270137
+ folded: foldedChars.join(""),
270138
+ toOriginal
270139
+ };
270140
+ }
270141
+ searchIgnoringDiacritics(pattern, options = {}) {
270142
+ const { caseSensitive = false, maxMatches = 1000 } = options;
270143
+ if (!pattern || typeof pattern !== "string" || pattern.length === 0)
270144
+ return [];
270145
+ const { folded: foldedText, toOriginal } = SearchIndex2.buildDiacriticOffsetMap(this.text);
270146
+ const foldedQuery = SearchIndex2.stripDiacritics(pattern);
270147
+ const flexiblePattern = SearchIndex2.toFlexiblePattern(foldedQuery);
270148
+ if (flexiblePattern.length === 0)
270149
+ return [];
270150
+ const flags = caseSensitive ? "g" : "gi";
270151
+ const regex = new RegExp(flexiblePattern, flags);
270152
+ const matches2 = [];
270153
+ let match$1;
270154
+ while ((match$1 = regex.exec(foldedText)) !== null && matches2.length < maxMatches) {
270155
+ const originalStart = toOriginal[match$1.index];
270156
+ const originalEnd = toOriginal[match$1.index + match$1[0].length];
270157
+ matches2.push({
270158
+ start: originalStart,
270159
+ end: originalEnd,
270160
+ text: this.text.slice(originalStart, originalEnd)
270161
+ });
270162
+ if (match$1[0].length === 0)
270163
+ regex.lastIndex++;
270164
+ }
270165
+ return matches2;
270166
+ }
270167
+ };
270078
270168
  customSearchHighlightsKey = new PluginKey("customSearchHighlights");
270079
270169
  Search = Extension.create({
270080
270170
  addStorage() {
270081
270171
  return {
270082
270172
  searchResults: [],
270083
270173
  highlightEnabled: true,
270084
- searchIndex: new SearchIndex
270174
+ searchIndex: new SearchIndex,
270175
+ activeMatchIndex: -1,
270176
+ query: "",
270177
+ caseSensitive: false,
270178
+ ignoreDiacritics: false
270085
270179
  };
270086
270180
  },
270087
270181
  addPmPlugins() {
@@ -270090,8 +270184,26 @@ function print() { __p += __j.call(arguments, '') }
270090
270184
  const searchIndexInvalidatorPlugin = new Plugin({
270091
270185
  key: new PluginKey("searchIndexInvalidator"),
270092
270186
  appendTransaction(transactions, oldState, newState) {
270093
- if (transactions.some((tr) => tr.docChanged) && storage?.searchIndex)
270187
+ if (!transactions.some((tr) => tr.docChanged))
270188
+ return null;
270189
+ if (storage?.searchIndex)
270094
270190
  storage.searchIndex.invalidate();
270191
+ if (storage?.query) {
270192
+ storage.searchIndex.ensureValid(newState.doc);
270193
+ const indexMatches = (storage.ignoreDiacritics ? (q$1, opts) => storage.searchIndex.searchIgnoringDiacritics(q$1, opts) : (q$1, opts) => storage.searchIndex.search(q$1, opts))(storage.query, { caseSensitive: storage.caseSensitive });
270194
+ const refreshed = mapIndexMatchesToDocMatches({
270195
+ searchIndex: storage.searchIndex,
270196
+ indexMatches,
270197
+ doc: newState.doc
270198
+ });
270199
+ storage.searchResults = refreshed;
270200
+ if (refreshed.length === 0)
270201
+ storage.activeMatchIndex = -1;
270202
+ else if (storage.activeMatchIndex < 0)
270203
+ storage.activeMatchIndex = 0;
270204
+ else if (storage.activeMatchIndex >= refreshed.length)
270205
+ storage.activeMatchIndex = refreshed.length - 1;
270206
+ }
270095
270207
  return null;
270096
270208
  }
270097
270209
  });
@@ -270105,10 +270217,13 @@ function print() { __p += __j.call(arguments, '') }
270105
270217
  return null;
270106
270218
  const highlightEnabled = storage?.highlightEnabled !== false;
270107
270219
  const decorations = [];
270108
- for (const match$1 of matches2) {
270220
+ const activeIdx = storage?.activeMatchIndex ?? -1;
270221
+ for (let i4 = 0;i4 < matches2.length; i4++) {
270222
+ const match$1 = matches2[i4];
270223
+ const cls = i4 === activeIdx ? "ProseMirror-active-search-match" : "ProseMirror-search-match";
270109
270224
  const attrs = highlightEnabled ? {
270110
270225
  id: `search-match-${match$1.id}`,
270111
- class: "ProseMirror-search-match"
270226
+ class: cls
270112
270227
  } : { id: `search-match-${match$1.id}` };
270113
270228
  if (match$1.ranges && match$1.ranges.length > 0)
270114
270229
  for (const range of match$1.ranges)
@@ -270195,41 +270310,15 @@ function print() { __p += __j.call(arguments, '') }
270195
270310
  positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
270196
270311
  const searchIndex = this.storage.searchIndex;
270197
270312
  searchIndex.ensureValid(state.doc);
270198
- const indexMatches = searchIndex.search(searchPattern, {
270199
- caseSensitive,
270200
- maxMatches
270313
+ const resultMatches = mapIndexMatchesToDocMatches({
270314
+ searchIndex,
270315
+ indexMatches: searchIndex.search(searchPattern, {
270316
+ caseSensitive,
270317
+ maxMatches
270318
+ }),
270319
+ doc: state.doc,
270320
+ positionTracker
270201
270321
  });
270202
- const resultMatches = [];
270203
- for (const indexMatch of indexMatches) {
270204
- const ranges = searchIndex.offsetRangeToDocRanges(indexMatch.start, indexMatch.end);
270205
- if (ranges.length === 0)
270206
- continue;
270207
- const combinedText = ranges.map((r$1) => state.doc.textBetween(r$1.from, r$1.to)).join("");
270208
- const match$1 = {
270209
- from: ranges[0].from,
270210
- to: ranges[ranges.length - 1].to,
270211
- text: combinedText,
270212
- id: v4_default(),
270213
- ranges,
270214
- trackerIds: []
270215
- };
270216
- if (positionTracker?.trackMany) {
270217
- const trackedRanges = ranges.map((range, rangeIndex) => ({
270218
- from: range.from,
270219
- to: range.to,
270220
- spec: {
270221
- type: SEARCH_POSITION_TRACKER_TYPE,
270222
- metadata: { rangeIndex }
270223
- }
270224
- }));
270225
- const trackerIds = positionTracker.trackMany(trackedRanges);
270226
- if (trackerIds.length > 0) {
270227
- match$1.trackerIds = trackerIds;
270228
- match$1.id = trackerIds[0];
270229
- }
270230
- }
270231
- resultMatches.push(match$1);
270232
- }
270233
270322
  this.storage.searchResults = resultMatches;
270234
270323
  this.storage.highlightEnabled = highlight;
270235
270324
  return resultMatches;
@@ -270265,6 +270354,137 @@ function print() { __p += __j.call(arguments, '') }
270265
270354
  });
270266
270355
  }
270267
270356
  return true;
270357
+ },
270358
+ setSearchSession: (query2, options = {}) => ({ state, editor }) => {
270359
+ const caseSensitive = options.caseSensitive ?? false;
270360
+ const ignoreDiacritics = options.ignoreDiacritics ?? false;
270361
+ const highlight = options.highlight ?? true;
270362
+ this.storage.query = query2;
270363
+ this.storage.caseSensitive = caseSensitive;
270364
+ this.storage.ignoreDiacritics = ignoreDiacritics;
270365
+ const positionTracker = getPositionTracker(editor);
270366
+ positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
270367
+ if (!query2) {
270368
+ this.storage.searchResults = [];
270369
+ this.storage.activeMatchIndex = -1;
270370
+ this.storage.highlightEnabled = highlight;
270371
+ return {
270372
+ matches: [],
270373
+ activeMatchIndex: -1
270374
+ };
270375
+ }
270376
+ const searchIndex = this.storage.searchIndex;
270377
+ searchIndex.ensureValid(state.doc);
270378
+ const resultMatches = mapIndexMatchesToDocMatches({
270379
+ searchIndex,
270380
+ indexMatches: ignoreDiacritics ? searchIndex.searchIgnoringDiacritics(query2, { caseSensitive }) : searchIndex.search(query2, { caseSensitive }),
270381
+ doc: state.doc,
270382
+ positionTracker
270383
+ });
270384
+ this.storage.searchResults = resultMatches;
270385
+ this.storage.highlightEnabled = highlight;
270386
+ this.storage.activeMatchIndex = resultMatches.length > 0 ? 0 : -1;
270387
+ return {
270388
+ matches: resultMatches,
270389
+ activeMatchIndex: this.storage.activeMatchIndex
270390
+ };
270391
+ },
270392
+ clearSearchSession: () => ({ editor }) => {
270393
+ getPositionTracker(editor)?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
270394
+ this.storage.searchResults = [];
270395
+ this.storage.highlightEnabled = true;
270396
+ this.storage.activeMatchIndex = -1;
270397
+ this.storage.query = "";
270398
+ this.storage.caseSensitive = false;
270399
+ this.storage.ignoreDiacritics = false;
270400
+ return true;
270401
+ },
270402
+ nextSearchMatch: () => ({ state, editor }) => {
270403
+ const matches2 = this.storage.searchResults;
270404
+ if (!matches2 || matches2.length === 0)
270405
+ return {
270406
+ activeMatchIndex: -1,
270407
+ match: null
270408
+ };
270409
+ const nextIdx = (this.storage.activeMatchIndex + 1) % matches2.length;
270410
+ this.storage.activeMatchIndex = nextIdx;
270411
+ const match$1 = matches2[nextIdx];
270412
+ editor.commands.goToSearchResult(match$1);
270413
+ return {
270414
+ activeMatchIndex: nextIdx,
270415
+ match: match$1
270416
+ };
270417
+ },
270418
+ previousSearchMatch: () => ({ state, editor }) => {
270419
+ const matches2 = this.storage.searchResults;
270420
+ if (!matches2 || matches2.length === 0)
270421
+ return {
270422
+ activeMatchIndex: -1,
270423
+ match: null
270424
+ };
270425
+ const prevIdx = (this.storage.activeMatchIndex - 1 + matches2.length) % matches2.length;
270426
+ this.storage.activeMatchIndex = prevIdx;
270427
+ const match$1 = matches2[prevIdx];
270428
+ editor.commands.goToSearchResult(match$1);
270429
+ return {
270430
+ activeMatchIndex: prevIdx,
270431
+ match: match$1
270432
+ };
270433
+ },
270434
+ replaceSearchMatch: (replacement) => ({ state, dispatch, editor, commands: commands$1 }) => {
270435
+ const matches2 = this.storage.searchResults;
270436
+ const activeIdx = this.storage.activeMatchIndex;
270437
+ if (!matches2 || activeIdx < 0 || activeIdx >= matches2.length)
270438
+ return {
270439
+ matches: matches2 || [],
270440
+ activeMatchIndex: activeIdx
270441
+ };
270442
+ const match$1 = matches2[activeIdx];
270443
+ const from$1 = match$1.ranges[0].from;
270444
+ const to = match$1.ranges[match$1.ranges.length - 1].to;
270445
+ const tr = state.tr;
270446
+ if (replacement)
270447
+ tr.replace(from$1, to, new Slice(Fragment.from(state.schema.text(replacement)), 0, 0));
270448
+ else
270449
+ tr.replace(from$1, to, Slice.empty);
270450
+ if (dispatch)
270451
+ dispatch(tr);
270452
+ state.tr;
270453
+ const result = commands$1.setSearchSession(this.storage.query, {
270454
+ caseSensitive: this.storage.caseSensitive,
270455
+ ignoreDiacritics: this.storage.ignoreDiacritics,
270456
+ highlight: this.storage.highlightEnabled
270457
+ });
270458
+ if (result.matches.length > 0) {
270459
+ const newIdx = Math.min(activeIdx, result.matches.length - 1);
270460
+ this.storage.activeMatchIndex = newIdx;
270461
+ result.activeMatchIndex = newIdx;
270462
+ const nextMatch$1 = result.matches[newIdx];
270463
+ if (nextMatch$1)
270464
+ commands$1.goToSearchResult(nextMatch$1);
270465
+ }
270466
+ return result;
270467
+ },
270468
+ replaceAllSearchMatches: (replacement) => ({ state, dispatch, commands: commands$1 }) => {
270469
+ const matches2 = this.storage.searchResults;
270470
+ if (!matches2 || matches2.length === 0)
270471
+ return { replacedCount: 0 };
270472
+ const { schema } = state;
270473
+ const tr = state.tr;
270474
+ const count2 = matches2.length;
270475
+ for (let i4 = matches2.length - 1;i4 >= 0; i4--) {
270476
+ const match$1 = matches2[i4];
270477
+ const from$1 = match$1.ranges[0].from;
270478
+ const to = match$1.ranges[match$1.ranges.length - 1].to;
270479
+ if (replacement)
270480
+ tr.replace(from$1, to, new Slice(Fragment.from(schema.text(replacement)), 0, 0));
270481
+ else
270482
+ tr.replace(from$1, to, Slice.empty);
270483
+ }
270484
+ if (dispatch)
270485
+ dispatch(tr);
270486
+ commands$1.clearSearchSession();
270487
+ return { replacedCount: count2 };
270268
270488
  }
270269
270489
  };
270270
270490
  }
@@ -281379,7 +281599,6 @@ function print() { __p += __j.call(arguments, '') }
281379
281599
  EXCLUDED_PLUGIN_KEY_REF_LIST = [
281380
281600
  TrackChangesBasePluginKey,
281381
281601
  CommentsPluginKey,
281382
- customSearchHighlightsKey,
281383
281602
  AiPluginKey,
281384
281603
  CustomSelectionPluginKey,
281385
281604
  LinkedStylesPluginKey,
@@ -286317,7 +286536,7 @@ var init_zipper_YmNpPIyc_es = __esm(() => {
286317
286536
 
286318
286537
  // ../../packages/superdoc/dist/super-editor.es.js
286319
286538
  var init_super_editor_es = __esm(() => {
286320
- init_src_C1tSJ0Z5_es();
286539
+ init_src_Lvsnnb5c_es();
286321
286540
  init_SuperConverter_OPfy6vj2_es();
286322
286541
  init_jszip_ChlR43oI_es();
286323
286542
  init_xml_js_40FWvL78_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.5.0-next.13",
3
+ "version": "0.5.0-next.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -34,11 +34,11 @@
34
34
  "access": "public"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@superdoc-dev/cli-darwin-arm64": "0.5.0-next.13",
38
- "@superdoc-dev/cli-darwin-x64": "0.5.0-next.13",
39
- "@superdoc-dev/cli-linux-arm64": "0.5.0-next.13",
40
- "@superdoc-dev/cli-linux-x64": "0.5.0-next.13",
41
- "@superdoc-dev/cli-windows-x64": "0.5.0-next.13"
37
+ "@superdoc-dev/cli-darwin-arm64": "0.5.0-next.14",
38
+ "@superdoc-dev/cli-linux-x64": "0.5.0-next.14",
39
+ "@superdoc-dev/cli-darwin-x64": "0.5.0-next.14",
40
+ "@superdoc-dev/cli-linux-arm64": "0.5.0-next.14",
41
+ "@superdoc-dev/cli-windows-x64": "0.5.0-next.14"
42
42
  },
43
43
  "scripts": {
44
44
  "predev": "node scripts/ensure-superdoc-build.js",