@puredesktop/platform-editor 1.0.0-beta.1 → 1.0.0-beta.2

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 (45) hide show
  1. package/package.json +1 -1
  2. package/src/CollapsePanel.tsx +35 -35
  3. package/src/DocumentDiffView.tsx +130 -130
  4. package/src/DocumentEditor.test.ts +118 -118
  5. package/src/DocumentEditor.tsx +2651 -2631
  6. package/src/alignedLineDiff.test.ts +52 -52
  7. package/src/alignedLineDiff.ts +67 -67
  8. package/src/collectionAssetSrc.ts +2 -2
  9. package/src/commentUtils.test.ts +350 -350
  10. package/src/commentUtils.ts +546 -546
  11. package/src/constants/toolKeys.ts +14 -14
  12. package/src/contentFormat.test.ts +27 -27
  13. package/src/contentFormat.ts +18 -18
  14. package/src/editorExtensions.ts +155 -155
  15. package/src/extensions/appliedChangeMark.ts +115 -115
  16. package/src/extensions/autoReviewPrompts.test.ts +529 -529
  17. package/src/extensions/autoReviewPrompts.ts +1442 -1442
  18. package/src/extensions/collectionImage.ts +26 -26
  19. package/src/extensions/collectionImagePaste.ts +215 -215
  20. package/src/extensions/commentMark.ts +223 -223
  21. package/src/extensions/documentAssetIdentity.ts +54 -54
  22. package/src/extensions/figure.ts +92 -92
  23. package/src/extensions/footnote.ts +186 -186
  24. package/src/extensions/indexMarker.ts +88 -88
  25. package/src/extensions/mathEditing.ts +239 -239
  26. package/src/extensions/mermaidBlock.tsx +297 -297
  27. package/src/extensions/slashCommands.test.ts +170 -170
  28. package/src/extensions/slashCommands.ts +746 -746
  29. package/src/extensions/smartTypography.test.ts +74 -74
  30. package/src/extensions/smartTypography.ts +120 -120
  31. package/src/index.ts +138 -137
  32. package/src/insertCollectionImage.test.ts +60 -60
  33. package/src/insertCollectionImage.ts +63 -63
  34. package/src/insertInlineAssetKind.test.ts +67 -67
  35. package/src/insertInlineAssetKind.ts +49 -49
  36. package/src/mermaidPreview.test.ts +54 -54
  37. package/src/mermaidPreview.ts +115 -115
  38. package/src/styled.ts +697 -676
  39. package/src/toolbar/ToolBtn.tsx +77 -63
  40. package/src/toolbar/Toolbar.test.tsx +325 -325
  41. package/src/toolbar/Toolbar.tsx +662 -624
  42. package/src/toolbar/groups/HeadingGroup.tsx +175 -153
  43. package/src/toolbar/overlayTypes.ts +28 -28
  44. package/src/useEditorExtensions.ts +22 -22
  45. package/src/utils/markdownUtils.ts +331 -331
@@ -1,52 +1,52 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { buildAlignedLineDiff } from './alignedLineDiff.js'
3
-
4
- describe('buildAlignedLineDiff', () => {
5
- it('returns matching lines when texts are equal', () => {
6
- const { leftLines, rightLines } = buildAlignedLineDiff(
7
- 'alpha\nbeta',
8
- 'alpha\nbeta',
9
- )
10
-
11
- expect(leftLines).toEqual([
12
- { kind: 'same', lineNumber: 1, text: 'alpha' },
13
- { kind: 'same', lineNumber: 2, text: 'beta' },
14
- ])
15
- expect(rightLines).toEqual([
16
- { kind: 'same', lineNumber: 1, text: 'alpha' },
17
- { kind: 'same', lineNumber: 2, text: 'beta' },
18
- ])
19
- })
20
-
21
- it('aligns removals on the left and additions on the right', () => {
22
- const { leftLines, rightLines } = buildAlignedLineDiff(
23
- 'keep\nold\nstay',
24
- 'keep\nnew\nstay',
25
- )
26
-
27
- expect(leftLines.map(line => line.kind)).toEqual([
28
- 'same',
29
- 'removed',
30
- 'pad',
31
- 'same',
32
- ])
33
- expect(rightLines.map(line => line.kind)).toEqual([
34
- 'same',
35
- 'pad',
36
- 'added',
37
- 'same',
38
- ])
39
- expect(leftLines[1]?.text).toBe('old')
40
- expect(rightLines[2]?.text).toBe('new')
41
- expect(leftLines[1]?.lineNumber).toBe(2)
42
- expect(rightLines[2]?.lineNumber).toBe(2)
43
- })
44
-
45
- it('pads the opposite column for insertions and deletions', () => {
46
- const { leftLines, rightLines } = buildAlignedLineDiff('a\nb', 'a\nc\nd')
47
-
48
- expect(leftLines.some(line => line.kind === 'pad')).toBe(true)
49
- expect(rightLines.some(line => line.kind === 'pad')).toBe(true)
50
- expect(leftLines.length).toBe(rightLines.length)
51
- })
52
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import { buildAlignedLineDiff } from './alignedLineDiff.js'
3
+
4
+ describe('buildAlignedLineDiff', () => {
5
+ it('returns matching lines when texts are equal', () => {
6
+ const { leftLines, rightLines } = buildAlignedLineDiff(
7
+ 'alpha\nbeta',
8
+ 'alpha\nbeta',
9
+ )
10
+
11
+ expect(leftLines).toEqual([
12
+ { kind: 'same', lineNumber: 1, text: 'alpha' },
13
+ { kind: 'same', lineNumber: 2, text: 'beta' },
14
+ ])
15
+ expect(rightLines).toEqual([
16
+ { kind: 'same', lineNumber: 1, text: 'alpha' },
17
+ { kind: 'same', lineNumber: 2, text: 'beta' },
18
+ ])
19
+ })
20
+
21
+ it('aligns removals on the left and additions on the right', () => {
22
+ const { leftLines, rightLines } = buildAlignedLineDiff(
23
+ 'keep\nold\nstay',
24
+ 'keep\nnew\nstay',
25
+ )
26
+
27
+ expect(leftLines.map(line => line.kind)).toEqual([
28
+ 'same',
29
+ 'removed',
30
+ 'pad',
31
+ 'same',
32
+ ])
33
+ expect(rightLines.map(line => line.kind)).toEqual([
34
+ 'same',
35
+ 'pad',
36
+ 'added',
37
+ 'same',
38
+ ])
39
+ expect(leftLines[1]?.text).toBe('old')
40
+ expect(rightLines[2]?.text).toBe('new')
41
+ expect(leftLines[1]?.lineNumber).toBe(2)
42
+ expect(rightLines[2]?.lineNumber).toBe(2)
43
+ })
44
+
45
+ it('pads the opposite column for insertions and deletions', () => {
46
+ const { leftLines, rightLines } = buildAlignedLineDiff('a\nb', 'a\nc\nd')
47
+
48
+ expect(leftLines.some(line => line.kind === 'pad')).toBe(true)
49
+ expect(rightLines.some(line => line.kind === 'pad')).toBe(true)
50
+ expect(leftLines.length).toBe(rightLines.length)
51
+ })
52
+ })
@@ -1,67 +1,67 @@
1
- import { diffLines, type Change } from 'diff'
2
-
3
- export type AlignedDiffLineKind = 'same' | 'added' | 'removed' | 'pad'
4
-
5
- export interface AlignedDiffLine {
6
- kind: AlignedDiffLineKind
7
- lineNumber: number | null
8
- text: string
9
- }
10
-
11
- export interface AlignedLineDiffResult {
12
- leftLines: AlignedDiffLine[]
13
- rightLines: AlignedDiffLine[]
14
- }
15
-
16
- function stripFinalNewline(value: string): string {
17
- return value.endsWith('\n') ? value.slice(0, -1) : value
18
- }
19
-
20
- /**
21
- * Line-diff two strings into aligned left/right columns.
22
- * Removals stay on the left; additions on the right; the other side pads.
23
- */
24
- export function buildAlignedLineDiff(
25
- left: string,
26
- right: string,
27
- ): AlignedLineDiffResult {
28
- const parts: Change[] = diffLines(left, right)
29
- const leftLines: AlignedDiffLine[] = []
30
- const rightLines: AlignedDiffLine[] = []
31
- let leftLineNumber = 0
32
- let rightLineNumber = 0
33
-
34
- for (const part of parts) {
35
- const lines = stripFinalNewline(part.value).split('\n')
36
- if (part.added) {
37
- for (const text of lines) {
38
- rightLineNumber += 1
39
- rightLines.push({
40
- kind: 'added',
41
- lineNumber: rightLineNumber,
42
- text,
43
- })
44
- leftLines.push({ kind: 'pad', lineNumber: null, text: '' })
45
- }
46
- } else if (part.removed) {
47
- for (const text of lines) {
48
- leftLineNumber += 1
49
- leftLines.push({
50
- kind: 'removed',
51
- lineNumber: leftLineNumber,
52
- text,
53
- })
54
- rightLines.push({ kind: 'pad', lineNumber: null, text: '' })
55
- }
56
- } else {
57
- for (const text of lines) {
58
- leftLineNumber += 1
59
- rightLineNumber += 1
60
- leftLines.push({ kind: 'same', lineNumber: leftLineNumber, text })
61
- rightLines.push({ kind: 'same', lineNumber: rightLineNumber, text })
62
- }
63
- }
64
- }
65
-
66
- return { leftLines, rightLines }
67
- }
1
+ import { diffLines, type Change } from 'diff'
2
+
3
+ export type AlignedDiffLineKind = 'same' | 'added' | 'removed' | 'pad'
4
+
5
+ export interface AlignedDiffLine {
6
+ kind: AlignedDiffLineKind
7
+ lineNumber: number | null
8
+ text: string
9
+ }
10
+
11
+ export interface AlignedLineDiffResult {
12
+ leftLines: AlignedDiffLine[]
13
+ rightLines: AlignedDiffLine[]
14
+ }
15
+
16
+ function stripFinalNewline(value: string): string {
17
+ return value.endsWith('\n') ? value.slice(0, -1) : value
18
+ }
19
+
20
+ /**
21
+ * Line-diff two strings into aligned left/right columns.
22
+ * Removals stay on the left; additions on the right; the other side pads.
23
+ */
24
+ export function buildAlignedLineDiff(
25
+ left: string,
26
+ right: string,
27
+ ): AlignedLineDiffResult {
28
+ const parts: Change[] = diffLines(left, right)
29
+ const leftLines: AlignedDiffLine[] = []
30
+ const rightLines: AlignedDiffLine[] = []
31
+ let leftLineNumber = 0
32
+ let rightLineNumber = 0
33
+
34
+ for (const part of parts) {
35
+ const lines = stripFinalNewline(part.value).split('\n')
36
+ if (part.added) {
37
+ for (const text of lines) {
38
+ rightLineNumber += 1
39
+ rightLines.push({
40
+ kind: 'added',
41
+ lineNumber: rightLineNumber,
42
+ text,
43
+ })
44
+ leftLines.push({ kind: 'pad', lineNumber: null, text: '' })
45
+ }
46
+ } else if (part.removed) {
47
+ for (const text of lines) {
48
+ leftLineNumber += 1
49
+ leftLines.push({
50
+ kind: 'removed',
51
+ lineNumber: leftLineNumber,
52
+ text,
53
+ })
54
+ rightLines.push({ kind: 'pad', lineNumber: null, text: '' })
55
+ }
56
+ } else {
57
+ for (const text of lines) {
58
+ leftLineNumber += 1
59
+ rightLineNumber += 1
60
+ leftLines.push({ kind: 'same', lineNumber: leftLineNumber, text })
61
+ rightLines.push({ kind: 'same', lineNumber: rightLineNumber, text })
62
+ }
63
+ }
64
+ }
65
+
66
+ return { leftLines, rightLines }
67
+ }
@@ -1,2 +1,2 @@
1
- /** Sidecar attribute for collection-relative image paths (shell usage scan compat). */
2
- export const COLLECTION_ASSET_SRC_ATTR = 'data-writer-asset-src'
1
+ /** Sidecar attribute for collection-relative image paths (shell usage scan compat). */
2
+ export const COLLECTION_ASSET_SRC_ATTR = 'data-writer-asset-src'