@superdoc-dev/cli 0.5.0-next.12 → 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 +433 -206
  2. package/package.json +7 -7
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-DIz6UVUx.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) => {
@@ -176230,6 +176230,14 @@ function buildFormattedCellBlock(schema, value, { blockType, blockAttrs, textMar
176230
176230
  const content3 = marks.length > 0 ? schema.text(ZERO_WIDTH_SPACE, marks) : null;
176231
176231
  return type.createAndFill(blockAttrs || null, content3);
176232
176232
  }
176233
+ const lines = text5.split(/\r?\n/);
176234
+ if (lines.length > 1) {
176235
+ const paragraphs = lines.map((line) => {
176236
+ const content3 = line ? schema.text(line, marks) : null;
176237
+ return type.createAndFill(blockAttrs || null, content3);
176238
+ }).filter(Boolean);
176239
+ return Fragment.from(paragraphs);
176240
+ }
176233
176241
  const textNode = schema.text(text5, marks);
176234
176242
  return type.createAndFill(blockAttrs || null, textNode);
176235
176243
  }
@@ -236503,173 +236511,40 @@ var Node$13 = class Node$14 {
236503
236511
  this.deco = deco;
236504
236512
  }
236505
236513
  }, searchKey, BLOCK_SEPARATOR = `
236506
- `, ATOM_PLACEHOLDER = "", SearchIndex = class SearchIndex2 {
236507
- text = "";
236508
- segments = [];
236509
- valid = false;
236510
- docSize = 0;
236511
- doc = null;
236512
- build(doc$12) {
236513
- this.text = doc$12.textBetween(0, doc$12.content.size, BLOCK_SEPARATOR, ATOM_PLACEHOLDER);
236514
- this.segments = [];
236515
- this.docSize = doc$12.content.size;
236516
- this.doc = doc$12;
236517
- let offset$1 = 0;
236518
- this.#walkNodeContent(doc$12, 0, offset$1, (segment) => {
236519
- this.segments.push(segment);
236520
- offset$1 = segment.offsetEnd;
236521
- });
236522
- this.valid = true;
236523
- }
236524
- #walkNodeContent(node3, contentStart, offset$1, addSegment) {
236525
- let currentOffset = offset$1;
236526
- let isFirstChild = true;
236527
- node3.forEach((child, childContentOffset) => {
236528
- const childDocPos = contentStart + childContentOffset;
236529
- if (child.isBlock && !isFirstChild) {
236530
- addSegment({
236531
- offsetStart: currentOffset,
236532
- offsetEnd: currentOffset + 1,
236533
- docFrom: childDocPos,
236534
- docTo: childDocPos,
236535
- kind: "blockSep"
236536
- });
236537
- currentOffset += 1;
236538
- }
236539
- currentOffset = this.#walkNode(child, childDocPos, currentOffset, addSegment);
236540
- isFirstChild = false;
236541
- });
236542
- return currentOffset;
236543
- }
236544
- #walkNode(node3, docPos, offset$1, addSegment) {
236545
- if (node3.isText) {
236546
- const text5 = node3.text || "";
236547
- if (text5.length > 0) {
236548
- addSegment({
236549
- offsetStart: offset$1,
236550
- offsetEnd: offset$1 + text5.length,
236551
- docFrom: docPos,
236552
- docTo: docPos + text5.length,
236553
- kind: "text"
236554
- });
236555
- return offset$1 + text5.length;
236556
- }
236557
- return offset$1;
236558
- }
236559
- if (node3.isLeaf) {
236560
- if (node3.type.name === "hard_break") {
236561
- addSegment({
236562
- offsetStart: offset$1,
236563
- offsetEnd: offset$1 + 1,
236564
- docFrom: docPos,
236565
- docTo: docPos + node3.nodeSize,
236566
- kind: "hardBreak"
236567
- });
236568
- return offset$1 + 1;
236569
- }
236570
- addSegment({
236571
- offsetStart: offset$1,
236572
- offsetEnd: offset$1 + 1,
236573
- docFrom: docPos,
236574
- docTo: docPos + node3.nodeSize,
236575
- kind: "atom"
236576
- });
236577
- return offset$1 + 1;
236578
- }
236579
- return this.#walkNodeContent(node3, docPos + 1, offset$1, addSegment);
236580
- }
236581
- invalidate() {
236582
- this.valid = false;
236583
- }
236584
- isStale(doc$12) {
236585
- return !this.valid || this.doc !== doc$12;
236586
- }
236587
- ensureValid(doc$12) {
236588
- if (this.isStale(doc$12))
236589
- this.build(doc$12);
236590
- }
236591
- offsetRangeToDocRanges(start$1, end$1) {
236592
- const ranges = [];
236593
- for (const segment of this.segments) {
236594
- if (segment.offsetEnd <= start$1)
236595
- continue;
236596
- if (segment.offsetStart >= end$1)
236597
- break;
236598
- if (segment.kind !== "text")
236599
- continue;
236600
- const overlapStart = Math.max(start$1, segment.offsetStart);
236601
- const overlapEnd = Math.min(end$1, segment.offsetEnd);
236602
- if (overlapStart < overlapEnd) {
236603
- const startInSegment = overlapStart - segment.offsetStart;
236604
- const endInSegment = overlapEnd - segment.offsetStart;
236605
- ranges.push({
236606
- from: segment.docFrom + startInSegment,
236607
- to: segment.docFrom + endInSegment
236608
- });
236609
- }
236610
- }
236611
- return ranges;
236612
- }
236613
- offsetToDocPos(offset$1) {
236614
- for (const segment of this.segments)
236615
- if (offset$1 >= segment.offsetStart && offset$1 < segment.offsetEnd) {
236616
- if (segment.kind === "text")
236617
- return segment.docFrom + (offset$1 - segment.offsetStart);
236618
- 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];
236619
236542
  }
236620
- if (this.segments.length > 0 && offset$1 === this.segments[this.segments.length - 1].offsetEnd)
236621
- return this.segments[this.segments.length - 1].docTo;
236622
- return null;
236623
- }
236624
- static escapeRegex(str) {
236625
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
236626
- }
236627
- static toFlexiblePattern(searchString) {
236628
- const hasLeadingWhitespace = /^[\s\u00a0]+/.test(searchString);
236629
- const hasTrailingWhitespace = /[\s\u00a0]+$/.test(searchString);
236630
- const parts = searchString.replace(/^[\s\u00a0]+|[\s\u00a0]+$/g, "").split(/[\s\u00a0]+/).filter((part) => part.length > 0);
236631
- if (parts.length === 0)
236632
- return hasLeadingWhitespace || hasTrailingWhitespace ? "[\\s\\u00a0]+" : "";
236633
- const blockSeparatorPattern = "(?:\\n)*";
236634
- let pattern = parts.map((part) => {
236635
- return Array.from(part).map((ch) => SearchIndex2.escapeRegex(ch)).join(blockSeparatorPattern);
236636
- }).join("[\\s\\u00a0]+");
236637
- if (hasLeadingWhitespace)
236638
- pattern = "[\\s\\u00a0]+" + pattern;
236639
- if (hasTrailingWhitespace)
236640
- pattern = pattern + "[\\s\\u00a0]+";
236641
- return pattern;
236642
- }
236643
- search(pattern, options = {}) {
236644
- const { caseSensitive = false, maxMatches = 1000 } = options;
236645
- const matches2 = [];
236646
- let regex;
236647
- if (pattern instanceof RegExp) {
236648
- const flags = pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g";
236649
- regex = new RegExp(pattern.source, flags);
236650
- } else if (typeof pattern === "string") {
236651
- if (pattern.length === 0)
236652
- return matches2;
236653
- const flexiblePattern = SearchIndex2.toFlexiblePattern(pattern);
236654
- if (flexiblePattern.length === 0)
236655
- return matches2;
236656
- const flags = caseSensitive ? "g" : "gi";
236657
- regex = new RegExp(flexiblePattern, flags);
236658
- } else
236659
- return matches2;
236660
- let match$1;
236661
- while ((match$1 = regex.exec(this.text)) !== null && matches2.length < maxMatches) {
236662
- matches2.push({
236663
- start: match$1.index,
236664
- end: match$1.index + match$1[0].length,
236665
- text: match$1[0]
236666
- });
236667
- if (match$1[0].length === 0)
236668
- regex.lastIndex++;
236669
236543
  }
236670
- return matches2;
236544
+ matches2.push(match$1);
236671
236545
  }
236672
- }, 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) => {
236673
236548
  if (!match$1)
236674
236549
  return {
236675
236550
  from: undefined,
@@ -252752,7 +252627,7 @@ var Node$13 = class Node$14 {
252752
252627
  return;
252753
252628
  console.log(...args$1);
252754
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;
252755
- var init_src_DIz6UVUx_es = __esm(() => {
252630
+ var init_src_Lvsnnb5c_es = __esm(() => {
252756
252631
  init_rolldown_runtime_B2q5OVn9_es();
252757
252632
  init_SuperConverter_OPfy6vj2_es();
252758
252633
  init_jszip_ChlR43oI_es();
@@ -270067,13 +269942,240 @@ function print() { __p += __j.call(arguments, '') }
270067
269942
  replaceCommand(true, true);
270068
269943
  replaceCommand(false, true);
270069
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
+ };
270070
270168
  customSearchHighlightsKey = new PluginKey("customSearchHighlights");
270071
270169
  Search = Extension.create({
270072
270170
  addStorage() {
270073
270171
  return {
270074
270172
  searchResults: [],
270075
270173
  highlightEnabled: true,
270076
- searchIndex: new SearchIndex
270174
+ searchIndex: new SearchIndex,
270175
+ activeMatchIndex: -1,
270176
+ query: "",
270177
+ caseSensitive: false,
270178
+ ignoreDiacritics: false
270077
270179
  };
270078
270180
  },
270079
270181
  addPmPlugins() {
@@ -270082,8 +270184,26 @@ function print() { __p += __j.call(arguments, '') }
270082
270184
  const searchIndexInvalidatorPlugin = new Plugin({
270083
270185
  key: new PluginKey("searchIndexInvalidator"),
270084
270186
  appendTransaction(transactions, oldState, newState) {
270085
- if (transactions.some((tr) => tr.docChanged) && storage?.searchIndex)
270187
+ if (!transactions.some((tr) => tr.docChanged))
270188
+ return null;
270189
+ if (storage?.searchIndex)
270086
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
+ }
270087
270207
  return null;
270088
270208
  }
270089
270209
  });
@@ -270097,10 +270217,13 @@ function print() { __p += __j.call(arguments, '') }
270097
270217
  return null;
270098
270218
  const highlightEnabled = storage?.highlightEnabled !== false;
270099
270219
  const decorations = [];
270100
- 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";
270101
270224
  const attrs = highlightEnabled ? {
270102
270225
  id: `search-match-${match$1.id}`,
270103
- class: "ProseMirror-search-match"
270226
+ class: cls
270104
270227
  } : { id: `search-match-${match$1.id}` };
270105
270228
  if (match$1.ranges && match$1.ranges.length > 0)
270106
270229
  for (const range of match$1.ranges)
@@ -270187,41 +270310,15 @@ function print() { __p += __j.call(arguments, '') }
270187
270310
  positionTracker?.untrackByType?.(SEARCH_POSITION_TRACKER_TYPE);
270188
270311
  const searchIndex = this.storage.searchIndex;
270189
270312
  searchIndex.ensureValid(state.doc);
270190
- const indexMatches = searchIndex.search(searchPattern, {
270191
- caseSensitive,
270192
- maxMatches
270313
+ const resultMatches = mapIndexMatchesToDocMatches({
270314
+ searchIndex,
270315
+ indexMatches: searchIndex.search(searchPattern, {
270316
+ caseSensitive,
270317
+ maxMatches
270318
+ }),
270319
+ doc: state.doc,
270320
+ positionTracker
270193
270321
  });
270194
- const resultMatches = [];
270195
- for (const indexMatch of indexMatches) {
270196
- const ranges = searchIndex.offsetRangeToDocRanges(indexMatch.start, indexMatch.end);
270197
- if (ranges.length === 0)
270198
- continue;
270199
- const combinedText = ranges.map((r$1) => state.doc.textBetween(r$1.from, r$1.to)).join("");
270200
- const match$1 = {
270201
- from: ranges[0].from,
270202
- to: ranges[ranges.length - 1].to,
270203
- text: combinedText,
270204
- id: v4_default(),
270205
- ranges,
270206
- trackerIds: []
270207
- };
270208
- if (positionTracker?.trackMany) {
270209
- const trackedRanges = ranges.map((range, rangeIndex) => ({
270210
- from: range.from,
270211
- to: range.to,
270212
- spec: {
270213
- type: SEARCH_POSITION_TRACKER_TYPE,
270214
- metadata: { rangeIndex }
270215
- }
270216
- }));
270217
- const trackerIds = positionTracker.trackMany(trackedRanges);
270218
- if (trackerIds.length > 0) {
270219
- match$1.trackerIds = trackerIds;
270220
- match$1.id = trackerIds[0];
270221
- }
270222
- }
270223
- resultMatches.push(match$1);
270224
- }
270225
270322
  this.storage.searchResults = resultMatches;
270226
270323
  this.storage.highlightEnabled = highlight;
270227
270324
  return resultMatches;
@@ -270257,6 +270354,137 @@ function print() { __p += __j.call(arguments, '') }
270257
270354
  });
270258
270355
  }
270259
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 };
270260
270488
  }
270261
270489
  };
270262
270490
  }
@@ -281371,7 +281599,6 @@ function print() { __p += __j.call(arguments, '') }
281371
281599
  EXCLUDED_PLUGIN_KEY_REF_LIST = [
281372
281600
  TrackChangesBasePluginKey,
281373
281601
  CommentsPluginKey,
281374
- customSearchHighlightsKey,
281375
281602
  AiPluginKey,
281376
281603
  CustomSelectionPluginKey,
281377
281604
  LinkedStylesPluginKey,
@@ -286309,7 +286536,7 @@ var init_zipper_YmNpPIyc_es = __esm(() => {
286309
286536
 
286310
286537
  // ../../packages/superdoc/dist/super-editor.es.js
286311
286538
  var init_super_editor_es = __esm(() => {
286312
- init_src_DIz6UVUx_es();
286539
+ init_src_Lvsnnb5c_es();
286313
286540
  init_SuperConverter_OPfy6vj2_es();
286314
286541
  init_jszip_ChlR43oI_es();
286315
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.12",
3
+ "version": "0.5.0-next.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -25,8 +25,8 @@
25
25
  "@types/ws": "^8.5.13",
26
26
  "typescript": "^5.9.2",
27
27
  "@superdoc/document-api": "0.0.1",
28
- "@superdoc/super-editor": "0.0.1",
29
28
  "@superdoc/pm-adapter": "0.0.0",
29
+ "@superdoc/super-editor": "0.0.1",
30
30
  "superdoc": "1.23.0"
31
31
  },
32
32
  "module": "src/index.ts",
@@ -34,11 +34,11 @@
34
34
  "access": "public"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@superdoc-dev/cli-darwin-arm64": "0.5.0-next.12",
38
- "@superdoc-dev/cli-darwin-x64": "0.5.0-next.12",
39
- "@superdoc-dev/cli-linux-x64": "0.5.0-next.12",
40
- "@superdoc-dev/cli-linux-arm64": "0.5.0-next.12",
41
- "@superdoc-dev/cli-windows-x64": "0.5.0-next.12"
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",