@crypto512/jicon-mcp 1.0.4 → 1.1.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.
Files changed (113) hide show
  1. package/README.md +40 -3
  2. package/TOOL_LIST.md +261 -140
  3. package/dist/config/constants.d.ts +2 -0
  4. package/dist/config/constants.d.ts.map +1 -1
  5. package/dist/config/constants.js +2 -0
  6. package/dist/config/constants.js.map +1 -1
  7. package/dist/config/loader.d.ts.map +1 -1
  8. package/dist/config/loader.js +2 -0
  9. package/dist/config/loader.js.map +1 -1
  10. package/dist/config/types.d.ts +6 -0
  11. package/dist/config/types.d.ts.map +1 -1
  12. package/dist/config/types.js +4 -0
  13. package/dist/config/types.js.map +1 -1
  14. package/dist/confluence/client.d.ts +11 -2
  15. package/dist/confluence/client.d.ts.map +1 -1
  16. package/dist/confluence/client.js +29 -12
  17. package/dist/confluence/client.js.map +1 -1
  18. package/dist/confluence/tools.d.ts +2 -2
  19. package/dist/confluence/tools.d.ts.map +1 -1
  20. package/dist/confluence/tools.js +95 -58
  21. package/dist/confluence/tools.js.map +1 -1
  22. package/dist/index.js +17 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/jira/client.d.ts.map +1 -1
  25. package/dist/jira/client.js +3 -13
  26. package/dist/jira/client.js.map +1 -1
  27. package/dist/jira/tools.d.ts.map +1 -1
  28. package/dist/jira/tools.js +9 -30
  29. package/dist/jira/tools.js.map +1 -1
  30. package/dist/permissions/tool-registry.d.ts +4 -2
  31. package/dist/permissions/tool-registry.d.ts.map +1 -1
  32. package/dist/permissions/tool-registry.js +14 -2
  33. package/dist/permissions/tool-registry.js.map +1 -1
  34. package/dist/tempo/formatters.d.ts.map +1 -1
  35. package/dist/tempo/formatters.js +1 -16
  36. package/dist/tempo/formatters.js.map +1 -1
  37. package/dist/tempo/tools.d.ts +2 -2
  38. package/dist/tempo/tools.d.ts.map +1 -1
  39. package/dist/tempo/tools.js +5 -13
  40. package/dist/tempo/tools.js.map +1 -1
  41. package/dist/utils/buffer-tools.d.ts +115 -63
  42. package/dist/utils/buffer-tools.d.ts.map +1 -1
  43. package/dist/utils/buffer-tools.js +385 -388
  44. package/dist/utils/buffer-tools.js.map +1 -1
  45. package/dist/utils/content-buffer.d.ts +24 -1
  46. package/dist/utils/content-buffer.d.ts.map +1 -1
  47. package/dist/utils/content-buffer.js +49 -39
  48. package/dist/utils/content-buffer.js.map +1 -1
  49. package/dist/utils/jicon-help.d.ts +5 -5
  50. package/dist/utils/jicon-help.d.ts.map +1 -1
  51. package/dist/utils/jicon-help.js +258 -588
  52. package/dist/utils/jicon-help.js.map +1 -1
  53. package/dist/utils/plantuml/client.d.ts +1 -1
  54. package/dist/utils/plantuml/client.d.ts.map +1 -1
  55. package/dist/utils/plantuml/client.js +34 -59
  56. package/dist/utils/plantuml/client.js.map +1 -1
  57. package/dist/utils/plantuml/docker-manager.d.ts +3 -1
  58. package/dist/utils/plantuml/docker-manager.d.ts.map +1 -1
  59. package/dist/utils/plantuml/docker-manager.js +6 -2
  60. package/dist/utils/plantuml/docker-manager.js.map +1 -1
  61. package/dist/utils/plantuml/include-expander.d.ts +32 -0
  62. package/dist/utils/plantuml/include-expander.d.ts.map +1 -0
  63. package/dist/utils/plantuml/include-expander.js +129 -0
  64. package/dist/utils/plantuml/include-expander.js.map +1 -0
  65. package/dist/utils/plantuml/index.d.ts +2 -1
  66. package/dist/utils/plantuml/index.d.ts.map +1 -1
  67. package/dist/utils/plantuml/index.js +3 -1
  68. package/dist/utils/plantuml/index.js.map +1 -1
  69. package/dist/utils/plantuml/service.d.ts +32 -8
  70. package/dist/utils/plantuml/service.d.ts.map +1 -1
  71. package/dist/utils/plantuml/service.js +108 -15
  72. package/dist/utils/plantuml/service.js.map +1 -1
  73. package/dist/utils/plantuml/tools.d.ts +4 -4
  74. package/dist/utils/plantuml/tools.d.ts.map +1 -1
  75. package/dist/utils/plantuml/tools.js +50 -5
  76. package/dist/utils/plantuml/tools.js.map +1 -1
  77. package/dist/utils/plantuml/types.d.ts +4 -4
  78. package/dist/utils/plantuml/validation-helper.d.ts +33 -0
  79. package/dist/utils/plantuml/validation-helper.d.ts.map +1 -0
  80. package/dist/utils/plantuml/validation-helper.js +97 -0
  81. package/dist/utils/plantuml/validation-helper.js.map +1 -0
  82. package/dist/utils/response-formatter.js +7 -7
  83. package/dist/utils/response-formatter.js.map +1 -1
  84. package/dist/utils/time-formatter.d.ts +10 -0
  85. package/dist/utils/time-formatter.d.ts.map +1 -0
  86. package/dist/utils/time-formatter.js +22 -0
  87. package/dist/utils/time-formatter.js.map +1 -0
  88. package/dist/utils/xhtml/error-locator.d.ts +70 -0
  89. package/dist/utils/xhtml/error-locator.d.ts.map +1 -0
  90. package/dist/utils/xhtml/error-locator.js +229 -0
  91. package/dist/utils/xhtml/error-locator.js.map +1 -0
  92. package/dist/utils/xhtml/index.d.ts +6 -3
  93. package/dist/utils/xhtml/index.d.ts.map +1 -1
  94. package/dist/utils/xhtml/index.js +7 -3
  95. package/dist/utils/xhtml/index.js.map +1 -1
  96. package/dist/utils/xhtml/operations.d.ts +54 -0
  97. package/dist/utils/xhtml/operations.d.ts.map +1 -1
  98. package/dist/utils/xhtml/operations.js +205 -0
  99. package/dist/utils/xhtml/operations.js.map +1 -1
  100. package/dist/utils/xhtml/plantuml.d.ts +1 -1
  101. package/dist/utils/xhtml/plantuml.d.ts.map +1 -1
  102. package/dist/utils/xhtml/plantuml.js +19 -30
  103. package/dist/utils/xhtml/plantuml.js.map +1 -1
  104. package/dist/utils/xhtml/serializer.d.ts +5 -0
  105. package/dist/utils/xhtml/serializer.d.ts.map +1 -1
  106. package/dist/utils/xhtml/serializer.js +18 -4
  107. package/dist/utils/xhtml/serializer.js.map +1 -1
  108. package/dist/utils/xhtml/types.d.ts +3 -3
  109. package/dist/utils/xhtml/types.d.ts.map +1 -1
  110. package/dist/utils/xhtml/validator.d.ts.map +1 -1
  111. package/dist/utils/xhtml/validator.js +87 -4
  112. package/dist/utils/xhtml/validator.js.map +1 -1
  113. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * XHTML Error Locator
3
+ *
4
+ * Parses Confluence XHTML error messages and maps them to buffer element IDs
5
+ * to enable targeted fixes instead of full buffer recreation.
6
+ */
7
+ import type { ApiError } from "../../types.js";
8
+ /**
9
+ * Parsed location from Confluence error message
10
+ */
11
+ export interface ConfluenceErrorLocation {
12
+ row: number;
13
+ col: number;
14
+ }
15
+ /**
16
+ * Location mapped to buffer structure
17
+ */
18
+ export interface BufferErrorLocation {
19
+ elementId: number;
20
+ elementType: string;
21
+ lineInElement: number;
22
+ lineContent: string;
23
+ errorContext: string;
24
+ }
25
+ /**
26
+ * Suggested action for error recovery
27
+ */
28
+ export interface SuggestedAction {
29
+ tool: string;
30
+ args: Record<string, unknown>;
31
+ description: string;
32
+ }
33
+ /**
34
+ * Enhanced error with location and recovery actions
35
+ */
36
+ export interface EnhancedXhtmlError extends ApiError {
37
+ errorLocation?: BufferErrorLocation;
38
+ suggestedActions?: SuggestedAction[];
39
+ }
40
+ /**
41
+ * Parse Confluence XHTML error message to extract row/col
42
+ *
43
+ * Handles formats:
44
+ * - "[row,col {unknown-source}]: [420,14]"
45
+ * - "at line 420, column 14"
46
+ * - "line 420:14"
47
+ */
48
+ export declare function parseConfluenceXhtmlError(message: string): ConfluenceErrorLocation | null;
49
+ /**
50
+ * Locate an error position within a buffer's element structure
51
+ */
52
+ export declare function locateErrorInBuffer(bufferId: string, row: number, col: number): BufferErrorLocation | null;
53
+ /**
54
+ * Enhance an API error with XHTML error location and recovery actions
55
+ *
56
+ * @param error - Original API error from Confluence
57
+ * @param bufferId - Buffer ID containing the content that caused the error
58
+ * @returns Enhanced error with location info and suggested actions, or null if not applicable
59
+ */
60
+ export declare function enhanceXhtmlError(error: ApiError, bufferId: string): EnhancedXhtmlError | null;
61
+ /**
62
+ * Get element content by ID from a buffer
63
+ * Returns the outerHTML of the element
64
+ */
65
+ export declare function getElementContentById(bufferId: string, elementId: number): {
66
+ content: string;
67
+ elementType: string;
68
+ lineCount: number;
69
+ } | null;
70
+ //# sourceMappingURL=error-locator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-locator.d.ts","sourceRoot":"","sources":["../../../src/utils/xhtml/error-locator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,QAAQ;IAClD,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,GAAG,IAAI,CA8BzF;AAwDD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,mBAAmB,GAAG,IAAI,CAyC5B;AAgDD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,MAAM,GACf,kBAAkB,GAAG,IAAI,CAmB3B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA8BpE"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * XHTML Error Locator
3
+ *
4
+ * Parses Confluence XHTML error messages and maps them to buffer element IDs
5
+ * to enable targeted fixes instead of full buffer recreation.
6
+ */
7
+ import { contentBuffer } from "../content-buffer.js";
8
+ import { parseXhtml, getContentRoot } from "./parser.js";
9
+ /**
10
+ * Parse Confluence XHTML error message to extract row/col
11
+ *
12
+ * Handles formats:
13
+ * - "[row,col {unknown-source}]: [420,14]"
14
+ * - "at line 420, column 14"
15
+ * - "line 420:14"
16
+ */
17
+ export function parseConfluenceXhtmlError(message) {
18
+ // Format: [row,col {unknown-source}]: [420,14]
19
+ // Handle whitespace variations: [row,col {unknown-source}]: [ 123 , 45 ]
20
+ const bracketMatch = message.match(/\[row,col\s*\{[^}]*\}\]\s*:\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/i);
21
+ if (bracketMatch) {
22
+ return {
23
+ row: parseInt(bracketMatch[1], 10),
24
+ col: parseInt(bracketMatch[2], 10),
25
+ };
26
+ }
27
+ // Format: at line 420, column 14
28
+ const atLineMatch = message.match(/at line\s+(\d+),?\s*column\s+(\d+)/i);
29
+ if (atLineMatch) {
30
+ return {
31
+ row: parseInt(atLineMatch[1], 10),
32
+ col: parseInt(atLineMatch[2], 10),
33
+ };
34
+ }
35
+ // Format: line 420:14
36
+ const lineColonMatch = message.match(/line\s+(\d+):(\d+)/i);
37
+ if (lineColonMatch) {
38
+ return {
39
+ row: parseInt(lineColonMatch[1], 10),
40
+ col: parseInt(lineColonMatch[2], 10),
41
+ };
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * Count lines in a string
47
+ */
48
+ function countLines(text) {
49
+ return (text.match(/\n/g) || []).length + 1;
50
+ }
51
+ /**
52
+ * Get start line number for an element in the serialized content
53
+ */
54
+ function getElementStartLine(content, elementId) {
55
+ const lines = content.split("\n");
56
+ const idPattern = new RegExp(`data-jicon-id=["']${elementId}["']`);
57
+ for (let i = 0; i < lines.length; i++) {
58
+ if (idPattern.test(lines[i])) {
59
+ return i + 1; // 1-indexed
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+ /**
65
+ * Get the line range for an element (start line to end line)
66
+ */
67
+ function getElementLineRange(content, elementId) {
68
+ const parseResult = parseXhtml(content);
69
+ if (!parseResult.document)
70
+ return null;
71
+ const root = getContentRoot(parseResult.document);
72
+ if (!root)
73
+ return null;
74
+ const element = root.querySelector(`[data-jicon-id="${elementId}"]`);
75
+ if (!element)
76
+ return null;
77
+ // Get the outer HTML of the element
78
+ const outerHtml = element.outerHTML;
79
+ // Find where this element starts in the content
80
+ const startLine = getElementStartLine(content, elementId);
81
+ if (!startLine)
82
+ return null;
83
+ // Count lines in the element
84
+ const elementLines = countLines(outerHtml);
85
+ return {
86
+ startLine,
87
+ endLine: startLine + elementLines - 1,
88
+ };
89
+ }
90
+ /**
91
+ * Locate an error position within a buffer's element structure
92
+ */
93
+ export function locateErrorInBuffer(bufferId, row, col) {
94
+ const bufferInfo = contentBuffer.getInfo(bufferId);
95
+ if (!bufferInfo)
96
+ return null;
97
+ // Get buffer content
98
+ const chunk = contentBuffer.getChunk(bufferId, 0, bufferInfo.totalSize);
99
+ if (!chunk)
100
+ return null;
101
+ const content = chunk.chunk;
102
+ const lines = content.split("\n");
103
+ // Validate row is within bounds
104
+ if (row < 1 || row > lines.length)
105
+ return null;
106
+ const lineContent = lines[row - 1]; // Convert to 0-indexed
107
+ const structure = bufferInfo.structure;
108
+ if (!structure || structure.length === 0)
109
+ return null;
110
+ // Find which element contains this line
111
+ for (const elem of structure) {
112
+ const range = getElementLineRange(content, elem.id);
113
+ if (range && row >= range.startLine && row <= range.endLine) {
114
+ // Calculate line within element
115
+ const lineInElement = row - range.startLine + 1;
116
+ // Extract error context around the column
117
+ const contextStart = Math.max(0, col - 25);
118
+ const contextEnd = Math.min(lineContent.length, col + 25);
119
+ const errorContext = lineContent.substring(contextStart, contextEnd);
120
+ return {
121
+ elementId: elem.id,
122
+ elementType: elem.type,
123
+ lineInElement,
124
+ lineContent: lineContent.length > 100 ? lineContent.substring(0, 100) + "..." : lineContent,
125
+ errorContext,
126
+ };
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+ /**
132
+ * Build suggested actions for error recovery
133
+ */
134
+ function buildSuggestedActions(bufferId, location) {
135
+ const actions = [];
136
+ if (location) {
137
+ // Action 1: Get element content for inspection
138
+ actions.push({
139
+ tool: "buffer_get_element",
140
+ args: {
141
+ bufferId,
142
+ elementId: location.elementId,
143
+ },
144
+ description: `Inspect element ${location.elementId} (${location.elementType}) containing the error`,
145
+ });
146
+ // Action 2: Replace element
147
+ actions.push({
148
+ tool: "buffer_edit",
149
+ args: {
150
+ bufferId,
151
+ replace: location.elementId,
152
+ content: "<!-- fixed content here -->",
153
+ },
154
+ description: `Replace element ${location.elementId} with fixed content`,
155
+ });
156
+ }
157
+ else {
158
+ // Fallback: use buffer_grep to find the problematic content
159
+ actions.push({
160
+ tool: "buffer_grep",
161
+ args: {
162
+ bufferId,
163
+ pattern: "<\\d|<[a-z]+\\|",
164
+ "-C": 2,
165
+ },
166
+ description: "Search for XML-like patterns that might cause parsing errors",
167
+ });
168
+ }
169
+ return actions;
170
+ }
171
+ /**
172
+ * Enhance an API error with XHTML error location and recovery actions
173
+ *
174
+ * @param error - Original API error from Confluence
175
+ * @param bufferId - Buffer ID containing the content that caused the error
176
+ * @returns Enhanced error with location info and suggested actions, or null if not applicable
177
+ */
178
+ export function enhanceXhtmlError(error, bufferId) {
179
+ // Only enhance XHTML parsing errors
180
+ if (!error.message)
181
+ return null;
182
+ const parsedLocation = parseConfluenceXhtmlError(error.message);
183
+ if (!parsedLocation)
184
+ return null;
185
+ // Try to locate the error in the buffer
186
+ const bufferLocation = locateErrorInBuffer(bufferId, parsedLocation.row, parsedLocation.col);
187
+ // Build suggested actions
188
+ const suggestedActions = buildSuggestedActions(bufferId, bufferLocation);
189
+ // Return enhanced error
190
+ return {
191
+ ...error,
192
+ errorLocation: bufferLocation ?? undefined,
193
+ suggestedActions,
194
+ };
195
+ }
196
+ /**
197
+ * Get element content by ID from a buffer
198
+ * Returns the outerHTML of the element
199
+ */
200
+ export function getElementContentById(bufferId, elementId) {
201
+ const bufferInfo = contentBuffer.getInfo(bufferId);
202
+ if (!bufferInfo)
203
+ return null;
204
+ const chunk = contentBuffer.getChunk(bufferId, 0, bufferInfo.totalSize);
205
+ if (!chunk)
206
+ return null;
207
+ const parseResult = parseXhtml(chunk.chunk);
208
+ if (!parseResult.document)
209
+ return null;
210
+ const root = getContentRoot(parseResult.document);
211
+ if (!root)
212
+ return null;
213
+ const element = root.querySelector(`[data-jicon-id="${elementId}"]`);
214
+ if (!element)
215
+ return null;
216
+ const content = element.outerHTML;
217
+ const lineCount = countLines(content);
218
+ // Determine element type
219
+ let elementType = element.tagName.toLowerCase();
220
+ if (elementType === "ac:structured-macro") {
221
+ elementType = element.getAttribute("ac:name") || "macro";
222
+ }
223
+ return {
224
+ content,
225
+ elementType,
226
+ lineCount,
227
+ };
228
+ }
229
+ //# sourceMappingURL=error-locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-locator.js","sourceRoot":"","sources":["../../../src/utils/xhtml/error-locator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuCzD;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,+CAA+C;IAC/C,4EAA4E;IAC5E,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,4DAA4D,CAAC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;IACrE,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;IAClC,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEtC,yBAAyB;IACzB,IAAI,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAChD,IAAI,WAAW,KAAK,qBAAqB,EAAE,CAAC;QAC1C,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC;IAC3D,CAAC;IAED,OAAO;QACL,OAAO;QACP,WAAW;QACX,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -6,12 +6,15 @@
6
6
  export type { Position, Operation, SemanticPosition, BufferEditXhtmlArgs, ValidationError, ValidationWarning, ValidationResult, XhtmlEditSuccess, XhtmlEditError, XhtmlEditResult, PlantUmlValidationResult, ParseResult, SelectorMatch, SelectorResult, } from "./types.js";
7
7
  export { PositionSchema, OperationSchema, SemanticPositionSchema, BufferEditXhtmlSchema, } from "./types.js";
8
8
  export { parseXhtml, getContentRoot, isValidXhtml, wrapWithNamespaces, CONFLUENCE_NAMESPACES, } from "./parser.js";
9
- export { serializeXhtml, serializeFragment, prettyPrint, } from "./serializer.js";
9
+ export { serializeXhtml, serializeFragment, prettyPrint, stripJiconIds, } from "./serializer.js";
10
10
  export { querySelector, isValidSelector, describeSelector, findUnsupportedPseudo, } from "./selector.js";
11
- export { executeOperation, executeInsert, executeUpdate, executeRemove, executeMoveOperation, executeWrap, resolveSemanticPosition, } from "./operations.js";
11
+ export { executeOperation, executeInsert, executeUpdate, executeRemove, executeMoveOperation, executeWrap, resolveSemanticPosition, parseStructure, findElementById, insertById, appendToDocument, replaceById, removeById, } from "./operations.js";
12
+ export type { ElementInfo } from "./operations.js";
12
13
  export { validateXhtml, validateXhtmlAsync, isValid, formatValidationErrors, formatValidationWarnings, getValidationReport, } from "./validator.js";
13
14
  export type { AsyncValidationResult, PlantUmlValidationInfo } from "./validator.js";
14
15
  export { CONFLUENCE_ELEMENTS, RESOURCE_IDENTIFIERS, KNOWN_MACROS, STANDARD_HTML_ELEMENTS, isConfluenceElement, isStandardHtmlElement, isKnownMacro, getElementDef, getRequiredAttributes, getValidAttributeValues, } from "./confluence-schema.js";
15
- export { validatePlantUml, normalizePlantUml, extractDiagramContent, buildPlantUmlMacro, validateAndBuildPlantUmlMacro, generateMacroId, extractPlantUmlFromMacro, extractPlantUmlFromMacroWithError, updatePlantUmlInMacro, } from "./plantuml.js";
16
+ export { validatePlantUml, normalizePlantUml, extractDiagramContent, buildPlantUmlMacro, validateAndBuildPlantUmlMacro, generateMacroId, extractPlantUmlFromMacro, extractPlantUmlFromMacroWithError, updatePlantUmlInMacro, detectRawPlantUml, } from "./plantuml.js";
16
17
  export type { PlantUmlExtractionResult } from "./plantuml.js";
18
+ export { parseConfluenceXhtmlError, locateErrorInBuffer, enhanceXhtmlError, getElementContentById, } from "./error-locator.js";
19
+ export type { ConfluenceErrorLocation, BufferErrorLocation, SuggestedAction, EnhancedXhtmlError, } from "./error-locator.js";
17
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/xhtml/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,OAAO,EACP,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAGpF,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,6BAA6B,EAC7B,eAAe,EACf,wBAAwB,EACxB,iCAAiC,EACjC,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/xhtml/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,qBAAqB,GACtB,M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ACV,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
@@ -7,15 +7,19 @@ export { PositionSchema, OperationSchema, SemanticPositionSchema, BufferEditXhtm
7
7
  // Parser
8
8
  export { parseXhtml, getContentRoot, isValidXhtml, wrapWithNamespaces, CONFLUENCE_NAMESPACES, } from "./parser.js";
9
9
  // Serializer
10
- export { serializeXhtml, serializeFragment, prettyPrint, } from "./serializer.js";
10
+ export { serializeXhtml, serializeFragment, prettyPrint, stripJiconIds, } from "./serializer.js";
11
11
  // Selector
12
12
  export { querySelector, isValidSelector, describeSelector, findUnsupportedPseudo, } from "./selector.js";
13
13
  // Operations
14
- export { executeOperation, executeInsert, executeUpdate, executeRemove, executeMoveOperation, executeWrap, resolveSemanticPosition, } from "./operations.js";
14
+ export { executeOperation, executeInsert, executeUpdate, executeRemove, executeMoveOperation, executeWrap, resolveSemanticPosition,
15
+ // Element ID-based operations
16
+ parseStructure, findElementById, insertById, appendToDocument, replaceById, removeById, } from "./operations.js";
15
17
  // Validator
16
18
  export { validateXhtml, validateXhtmlAsync, isValid, formatValidationErrors, formatValidationWarnings, getValidationReport, } from "./validator.js";
17
19
  // Confluence Schema
18
20
  export { CONFLUENCE_ELEMENTS, RESOURCE_IDENTIFIERS, KNOWN_MACROS, STANDARD_HTML_ELEMENTS, isConfluenceElement, isStandardHtmlElement, isKnownMacro, getElementDef, getRequiredAttributes, getValidAttributeValues, } from "./confluence-schema.js";
19
21
  // PlantUML
20
- export { validatePlantUml, normalizePlantUml, extractDiagramContent, buildPlantUmlMacro, validateAndBuildPlantUmlMacro, generateMacroId, extractPlantUmlFromMacro, extractPlantUmlFromMacroWithError, updatePlantUmlInMacro, } from "./plantuml.js";
22
+ export { validatePlantUml, normalizePlantUml, extractDiagramContent, buildPlantUmlMacro, validateAndBuildPlantUmlMacro, generateMacroId, extractPlantUmlFromMacro, extractPlantUmlFromMacroWithError, updatePlantUmlInMacro, detectRawPlantUml, } from "./plantuml.js";
23
+ // Error Locator
24
+ export { parseConfluenceXhtmlError, locateErrorInBuffer, enhanceXhtmlError, getElementContentById, } from "./error-locator.js";
21
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/xhtml/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,OAAO,EACL,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,WAAW;AACX,OAAO,EACL,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,aAAa;AACb,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,YAAY;AACZ,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,OAAO,EACP,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAGxB,oBAAoB;AACpB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAEhC,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,6BAA6B,EAC7B,eAAe,EACf,wBAAwB,EACxB,iCAAiC,EACjC,qBAAqB,GACtB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/xhtml/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,OAAO,EACL,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,WAAW;AACX,OAAO,EACL,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,aAAa;AACb,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,uBAAuB;AACvB,8BAA8B;AAC9B,cAAc,EACd,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,iBAAiB,CAAC;AAGzB,YAAY;AACZ,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,OAAO,EACP,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAGxB,oBAAoB;AACpB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAEhC,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,6BAA6B,EAC7B,eAAe,EACf,wBAAwB,EACxB,iCAAiC,EACjC,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,gBAAgB;AAChB,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC"}
@@ -96,5 +96,59 @@ export declare function executeOperation(document: Document, operation: Operatio
96
96
  matchIndex?: number;
97
97
  matchAll?: boolean;
98
98
  }): XhtmlEditSuccess | XhtmlEditError;
99
+ /**
100
+ * Element info for structure tracking
101
+ */
102
+ export interface ElementInfo {
103
+ id: number;
104
+ type: string;
105
+ text?: string;
106
+ children?: number;
107
+ }
108
+ /**
109
+ * Parse XHTML document and build structure with element IDs
110
+ * IDs are assigned via data-jicon-id attributes for stability
111
+ */
112
+ export declare function parseStructure(document: Document): {
113
+ structure: ElementInfo[];
114
+ nextId: number;
115
+ };
116
+ /**
117
+ * Find element by its jicon ID
118
+ */
119
+ export declare function findElementById(document: Document, id: number): Element | null;
120
+ /**
121
+ * Insert content relative to an element ID
122
+ * Returns the ID(s) assigned to the new element(s)
123
+ */
124
+ export declare function insertById(document: Document, targetId: number, position: "before" | "after", content: string, nextId: number): {
125
+ success: boolean;
126
+ insertedIds: number[];
127
+ nextId: number;
128
+ error?: string;
129
+ };
130
+ /**
131
+ * Append content at document end
132
+ */
133
+ export declare function appendToDocument(document: Document, content: string, nextId: number): {
134
+ success: boolean;
135
+ insertedIds: number[];
136
+ nextId: number;
137
+ error?: string;
138
+ };
139
+ /**
140
+ * Replace element by ID with new content
141
+ */
142
+ export declare function replaceById(document: Document, targetId: number, content: string): {
143
+ success: boolean;
144
+ error?: string;
145
+ };
146
+ /**
147
+ * Remove element by ID
148
+ */
149
+ export declare function removeById(document: Document, targetId: number): {
150
+ success: boolean;
151
+ error?: string;
152
+ };
99
153
  export {};
100
154
  //# sourceMappingURL=operations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../src/utils/xhtml/operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,O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ACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,GACf;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAatC"}
@@ -593,4 +593,209 @@ export function executeOperation(document, operation, selector, options) {
593
593
  return { error: true, message: `Unknown operation: ${operation}` };
594
594
  }
595
595
  }
596
+ const JICON_ID_ATTR = "data-jicon-id";
597
+ /**
598
+ * Get element type from tag name, handling Confluence macros specially
599
+ */
600
+ function getElementType(el) {
601
+ const tagName = el.tagName.toLowerCase();
602
+ // Handle Confluence macros
603
+ if (tagName === "ac:structured-macro") {
604
+ const macroName = el.getAttribute("ac:name");
605
+ if (macroName) {
606
+ return macroName; // "plantuml", "code", "info", etc.
607
+ }
608
+ }
609
+ return tagName;
610
+ }
611
+ /**
612
+ * Get preview text from element (truncated)
613
+ */
614
+ function getPreviewText(el, maxLength = 50) {
615
+ const text = el.textContent?.trim();
616
+ if (!text)
617
+ return undefined;
618
+ if (text.length <= maxLength)
619
+ return text;
620
+ return text.substring(0, maxLength) + "...";
621
+ }
622
+ /**
623
+ * Count children for container elements
624
+ */
625
+ function getChildCount(el) {
626
+ const tagName = el.tagName.toLowerCase();
627
+ if (tagName === "ul" || tagName === "ol") {
628
+ return el.querySelectorAll("li").length;
629
+ }
630
+ if (tagName === "table") {
631
+ return el.querySelectorAll("tr").length;
632
+ }
633
+ return undefined;
634
+ }
635
+ /**
636
+ * Parse XHTML document and build structure with element IDs
637
+ * IDs are assigned via data-jicon-id attributes for stability
638
+ */
639
+ export function parseStructure(document) {
640
+ const structure = [];
641
+ const root = getContentRoot(document);
642
+ if (!root) {
643
+ return { structure, nextId: 1 };
644
+ }
645
+ let maxId = 0;
646
+ // Walk top-level elements and assign IDs
647
+ for (const child of root.children) {
648
+ const el = child;
649
+ // Get existing ID or assign new one
650
+ let id = parseInt(el.getAttribute(JICON_ID_ATTR) || "0", 10);
651
+ if (!id || isNaN(id)) {
652
+ id = ++maxId;
653
+ el.setAttribute(JICON_ID_ATTR, String(id));
654
+ }
655
+ else {
656
+ maxId = Math.max(maxId, id);
657
+ }
658
+ structure.push({
659
+ id,
660
+ type: getElementType(el),
661
+ text: getPreviewText(el),
662
+ children: getChildCount(el),
663
+ });
664
+ }
665
+ return { structure, nextId: maxId + 1 };
666
+ }
667
+ /**
668
+ * Find element by its jicon ID
669
+ */
670
+ export function findElementById(document, id) {
671
+ const root = getContentRoot(document);
672
+ if (!root)
673
+ return null;
674
+ return root.querySelector(`[${JICON_ID_ATTR}="${id}"]`);
675
+ }
676
+ /**
677
+ * Insert content relative to an element ID
678
+ * Returns the ID(s) assigned to the new element(s)
679
+ */
680
+ export function insertById(document, targetId, position, content, nextId) {
681
+ const targetEl = findElementById(document, targetId);
682
+ if (!targetEl) {
683
+ return { success: false, insertedIds: [], nextId, error: `Element not found: ${targetId}` };
684
+ }
685
+ try {
686
+ const nodes = parseContent(document, content);
687
+ if (nodes.length === 0) {
688
+ return { success: false, insertedIds: [], nextId, error: "Content to insert is empty or invalid" };
689
+ }
690
+ const insertedIds = [];
691
+ let currentNextId = nextId;
692
+ // Assign IDs to new elements and insert
693
+ for (const node of nodes) {
694
+ if (node.nodeType === 1) { // Element node
695
+ const el = node;
696
+ el.setAttribute(JICON_ID_ATTR, String(currentNextId));
697
+ insertedIds.push(currentNextId);
698
+ currentNextId++;
699
+ }
700
+ }
701
+ // Insert nodes
702
+ const parent = targetEl.parentNode;
703
+ if (!parent) {
704
+ return { success: false, insertedIds: [], nextId, error: "Target element has no parent" };
705
+ }
706
+ if (position === "before") {
707
+ for (const node of nodes) {
708
+ parent.insertBefore(node, targetEl);
709
+ }
710
+ }
711
+ else {
712
+ const nextSibling = targetEl.nextSibling;
713
+ for (const node of nodes) {
714
+ parent.insertBefore(node, nextSibling);
715
+ }
716
+ }
717
+ return { success: true, insertedIds, nextId: currentNextId };
718
+ }
719
+ catch (e) {
720
+ return { success: false, insertedIds: [], nextId, error: e instanceof Error ? e.message : String(e) };
721
+ }
722
+ }
723
+ /**
724
+ * Append content at document end
725
+ */
726
+ export function appendToDocument(document, content, nextId) {
727
+ const root = getContentRoot(document);
728
+ if (!root) {
729
+ return { success: false, insertedIds: [], nextId, error: "Document has no content root" };
730
+ }
731
+ try {
732
+ const nodes = parseContent(document, content);
733
+ if (nodes.length === 0) {
734
+ return { success: false, insertedIds: [], nextId, error: "Content to insert is empty or invalid" };
735
+ }
736
+ const insertedIds = [];
737
+ let currentNextId = nextId;
738
+ for (const node of nodes) {
739
+ if (node.nodeType === 1) {
740
+ const el = node;
741
+ el.setAttribute(JICON_ID_ATTR, String(currentNextId));
742
+ insertedIds.push(currentNextId);
743
+ currentNextId++;
744
+ }
745
+ root.appendChild(node);
746
+ }
747
+ return { success: true, insertedIds, nextId: currentNextId };
748
+ }
749
+ catch (e) {
750
+ return { success: false, insertedIds: [], nextId, error: e instanceof Error ? e.message : String(e) };
751
+ }
752
+ }
753
+ /**
754
+ * Replace element by ID with new content
755
+ */
756
+ export function replaceById(document, targetId, content) {
757
+ const targetEl = findElementById(document, targetId);
758
+ if (!targetEl) {
759
+ return { success: false, error: `Element not found: ${targetId}` };
760
+ }
761
+ try {
762
+ const nodes = parseContent(document, content);
763
+ if (nodes.length === 0) {
764
+ return { success: false, error: "Replacement content is empty or invalid" };
765
+ }
766
+ const parent = targetEl.parentNode;
767
+ if (!parent) {
768
+ return { success: false, error: "Target element has no parent" };
769
+ }
770
+ // Preserve the original ID on the first replacement element
771
+ if (nodes[0].nodeType === 1) {
772
+ nodes[0].setAttribute(JICON_ID_ATTR, String(targetId));
773
+ }
774
+ // Insert new nodes before the target
775
+ for (const node of nodes) {
776
+ parent.insertBefore(node, targetEl);
777
+ }
778
+ // Remove the target
779
+ parent.removeChild(targetEl);
780
+ return { success: true };
781
+ }
782
+ catch (e) {
783
+ return { success: false, error: e instanceof Error ? e.message : String(e) };
784
+ }
785
+ }
786
+ /**
787
+ * Remove element by ID
788
+ */
789
+ export function removeById(document, targetId) {
790
+ const targetEl = findElementById(document, targetId);
791
+ if (!targetEl) {
792
+ return { success: false, error: `Element not found: ${targetId}` };
793
+ }
794
+ const parent = targetEl.parentNode;
795
+ if (!parent) {
796
+ return { success: false, error: "Target element has no parent" };
797
+ }
798
+ parent.removeChild(targetEl);
799
+ return { success: true };
800
+ }
596
801
  //# sourceMappingURL=operations.js.map