@sutrata/editor 0.1.1 → 0.2.0

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 (268) hide show
  1. package/README.md +87 -0
  2. package/dist/ai/VoiceConfirmDialog.d.ts +1 -0
  3. package/dist/ai/VoiceConfirmDialog.js +6 -6
  4. package/dist/ai/VoiceToolbar.d.ts +1 -0
  5. package/dist/ai/VoiceToolbar.js +22 -16
  6. package/dist/ai/clean-response.d.ts +7 -0
  7. package/dist/ai/clean-response.js +58 -0
  8. package/dist/ai/format-transcript.d.ts +3 -0
  9. package/dist/ai/format-transcript.js +7 -0
  10. package/dist/ai/prompts.d.ts +8 -1
  11. package/dist/ai/prompts.js +34 -7
  12. package/dist/autocomplete/suggestions.js +1 -1
  13. package/dist/context/DocumentContext.d.ts +28 -4
  14. package/dist/context/DocumentContext.js +67 -37
  15. package/dist/editor/EditorView.js +32 -4
  16. package/dist/editor/SelectionMenu.js +5 -3
  17. package/dist/editor/external-decorations-plugin.d.ts +23 -0
  18. package/dist/editor/external-decorations-plugin.js +151 -0
  19. package/dist/editor/omitted-scene-plugin.d.ts +9 -0
  20. package/dist/editor/omitted-scene-plugin.js +44 -0
  21. package/dist/editor/plugins.js +4 -0
  22. package/dist/editor/private-metadata-plugin.d.ts +10 -0
  23. package/dist/editor/private-metadata-plugin.js +60 -0
  24. package/dist/editor/prosemirror-to-sutra.js +179 -74
  25. package/dist/editor/scene-heading-view.js +2 -0
  26. package/dist/editor/schema.js +69 -12
  27. package/dist/editor/sutra-to-prosemirror.d.ts +2 -0
  28. package/dist/editor/sutra-to-prosemirror.js +32 -34
  29. package/dist/extensions/ai-provider.d.ts +44 -0
  30. package/dist/extensions/ai-provider.js +27 -0
  31. package/dist/extensions/collab.d.ts +21 -0
  32. package/dist/extensions/collab.js +6 -0
  33. package/dist/extensions/command-registry.d.ts +49 -0
  34. package/dist/extensions/command-registry.js +28 -0
  35. package/dist/extensions/decorations.d.ts +48 -0
  36. package/dist/extensions/decorations.js +6 -0
  37. package/dist/extensions/export-registry.d.ts +59 -0
  38. package/dist/extensions/export-registry.js +10 -0
  39. package/dist/extensions/panel-registry.d.ts +30 -0
  40. package/dist/extensions/panel-registry.js +16 -0
  41. package/dist/extensions/registries.d.ts +15 -0
  42. package/dist/extensions/registries.js +12 -0
  43. package/dist/extensions/registry-store.d.ts +26 -0
  44. package/dist/extensions/registry-store.js +35 -0
  45. package/dist/extensions/session.d.ts +29 -0
  46. package/dist/extensions/session.js +20 -0
  47. package/dist/extensions/speech-provider.d.ts +35 -0
  48. package/dist/extensions/speech-provider.js +17 -0
  49. package/dist/file/builtin-exporters.d.ts +9 -0
  50. package/dist/file/builtin-exporters.js +72 -0
  51. package/dist/file/docx-exporter.js +7 -4
  52. package/dist/file/docx-importer.d.ts +9 -0
  53. package/dist/file/docx-importer.js +47 -19
  54. package/dist/file/scene-number.d.ts +5 -0
  55. package/dist/file/scene-number.js +8 -0
  56. package/dist/file/workflow-reports.js +13 -7
  57. package/dist/findreplace/FindReplace.js +5 -2
  58. package/dist/import/AIImportDialog.d.ts +11 -0
  59. package/dist/import/AIImportDialog.js +112 -0
  60. package/dist/import/ai-import.d.ts +51 -0
  61. package/dist/import/ai-import.js +200 -0
  62. package/dist/import/apply-import.d.ts +7 -0
  63. package/dist/import/apply-import.js +35 -0
  64. package/dist/import/extract.d.ts +17 -0
  65. package/dist/import/extract.js +18 -0
  66. package/dist/index.d.ts +17 -2
  67. package/dist/index.js +7 -0
  68. package/dist/locales/bn.json +8 -0
  69. package/dist/locales/en.json +8 -0
  70. package/dist/locales/gu.json +8 -0
  71. package/dist/locales/hi.json +8 -0
  72. package/dist/locales/kn.json +8 -0
  73. package/dist/locales/ml.json +8 -0
  74. package/dist/locales/mr.json +8 -0
  75. package/dist/locales/or.json +8 -0
  76. package/dist/locales/pa.json +8 -0
  77. package/dist/locales/si.json +8 -0
  78. package/dist/locales/ta.json +8 -0
  79. package/dist/locales/te.json +8 -0
  80. package/dist/navigator/SceneNavigator.js +125 -131
  81. package/dist/navigator/StatisticsDialog.js +5 -1
  82. package/dist/navigator/scene-edits.d.ts +18 -0
  83. package/dist/navigator/scene-edits.js +143 -0
  84. package/dist/navigator/scene-list.js +4 -4
  85. package/dist/navigator/scene-numbering.d.ts +37 -0
  86. package/dist/navigator/scene-numbering.js +88 -0
  87. package/dist/settings/SettingsDialog.js +8 -120
  88. package/dist/shell/AppBar.js +21 -2
  89. package/dist/shell/AppShell.js +18 -4
  90. package/dist/shell/ElementToolbar.d.ts +5 -0
  91. package/dist/shell/ElementToolbar.js +35 -25
  92. package/dist/shell/LanguageStatus.js +6 -0
  93. package/dist/shell/StatusBar.js +11 -6
  94. package/dist/shell/builtin-commands.d.ts +10 -0
  95. package/dist/shell/builtin-commands.js +43 -0
  96. package/dist/shell/icons.d.ts +6 -0
  97. package/dist/shell/icons.js +6 -0
  98. package/dist/shell/use-commands.d.ts +7 -0
  99. package/dist/shell/use-commands.js +24 -0
  100. package/dist/shell/use-panel-context.d.ts +3 -0
  101. package/dist/shell/use-panel-context.js +39 -0
  102. package/dist/source/SourceView.js +18 -1
  103. package/dist/styles/screenplay.css +113 -1
  104. package/dist/titlepage/ExportDialog.d.ts +5 -0
  105. package/dist/titlepage/ExportDialog.js +59 -96
  106. package/package.json +32 -5
  107. package/dist/ai/OnboardingDialog.d.ts +0 -6
  108. package/dist/ai/OnboardingDialog.js +0 -115
  109. package/dist/ai/ai-client.d.ts +0 -71
  110. package/dist/ai/ai-client.js +0 -494
  111. package/dist/ai/generated-providers.json +0 -3696
  112. package/dist/ai/voice-service.d.ts +0 -15
  113. package/dist/ai/voice-service.js +0 -81
  114. package/dist/editor/character-view.d.ts +0 -35
  115. package/dist/editor/character-view.js +0 -112
  116. package/dist/editor/transliterate-input.d.ts +0 -10
  117. package/dist/editor/transliterate-input.js +0 -88
  118. package/dist/extensions/types.d.ts +0 -73
  119. package/dist/extensions/types.js +0 -12
  120. package/scripts/copy-assets.mjs +0 -16
  121. package/scripts/generate-providers.mjs +0 -127
  122. package/src/ai/OnboardingDialog.tsx +0 -390
  123. package/src/ai/VoiceConfirmDialog.tsx +0 -137
  124. package/src/ai/VoiceToolbar.tsx +0 -321
  125. package/src/ai/ai-client.ts +0 -596
  126. package/src/ai/commands.ts +0 -164
  127. package/src/ai/generated-providers.json +0 -3696
  128. package/src/ai/prompts.ts +0 -62
  129. package/src/ai/voice-service.ts +0 -96
  130. package/src/autocomplete/AutocompletePlugin.ts +0 -21
  131. package/src/autocomplete/suggestions.ts +0 -147
  132. package/src/context/DocumentContext.tsx +0 -648
  133. package/src/desktop-api.d.ts +0 -40
  134. package/src/editor/EditorView.tsx +0 -82
  135. package/src/editor/SelectionMenu.tsx +0 -152
  136. package/src/editor/attr-pencil-plugin.ts +0 -172
  137. package/src/editor/character-decoration-plugin.ts +0 -104
  138. package/src/editor/editor-bus.ts +0 -51
  139. package/src/editor/find-highlight-plugin.ts +0 -68
  140. package/src/editor/frontmatter-field-view.ts +0 -52
  141. package/src/editor/frontmatter-field.ts +0 -115
  142. package/src/editor/grapheme-cursor.ts +0 -99
  143. package/src/editor/ime-plugin.ts +0 -85
  144. package/src/editor/insert-helper.ts +0 -43
  145. package/src/editor/keymap.ts +0 -124
  146. package/src/editor/language-class-plugin.ts +0 -91
  147. package/src/editor/plugins.ts +0 -26
  148. package/src/editor/prosemirror-to-sutra.ts +0 -192
  149. package/src/editor/scene-heading-view.ts +0 -147
  150. package/src/editor/schema.ts +0 -156
  151. package/src/editor/sutra-to-prosemirror.ts +0 -156
  152. package/src/extensions/storage-adapter.ts +0 -65
  153. package/src/extensions/types.ts +0 -60
  154. package/src/file/docx-exporter.ts +0 -585
  155. package/src/file/docx-importer.ts +0 -313
  156. package/src/file/print-paginator.ts +0 -301
  157. package/src/file/templates.ts +0 -73
  158. package/src/file/workflow-reports.ts +0 -820
  159. package/src/findreplace/FindReplace.tsx +0 -242
  160. package/src/findreplace/find-engine.ts +0 -97
  161. package/src/findreplace/scroll-to-match.ts +0 -89
  162. package/src/fonts/tofu-detect.ts +0 -53
  163. package/src/i18n/LanguageContext.tsx +0 -207
  164. package/src/i18n/language-detect.ts +0 -73
  165. package/src/i18n/useTranslation.tsx +0 -74
  166. package/src/index.ts +0 -27
  167. package/src/locales/bn.json +0 -143
  168. package/src/locales/en.json +0 -143
  169. package/src/locales/gu.json +0 -143
  170. package/src/locales/hi.json +0 -143
  171. package/src/locales/kn.json +0 -143
  172. package/src/locales/ml.json +0 -143
  173. package/src/locales/mr.json +0 -143
  174. package/src/locales/or.json +0 -143
  175. package/src/locales/pa.json +0 -143
  176. package/src/locales/si.json +0 -143
  177. package/src/locales/ta.json +0 -143
  178. package/src/locales/te.json +0 -143
  179. package/src/navigator/SceneNavigator.tsx +0 -844
  180. package/src/navigator/StatisticsDialog.tsx +0 -249
  181. package/src/navigator/scene-list.ts +0 -84
  182. package/src/settings/SettingsDialog.tsx +0 -303
  183. package/src/shell/AppBar.tsx +0 -354
  184. package/src/shell/AppShell.tsx +0 -71
  185. package/src/shell/ConfirmDialog.tsx +0 -71
  186. package/src/shell/ElementToolbar.tsx +0 -175
  187. package/src/shell/LanguageStatus.tsx +0 -101
  188. package/src/shell/StatusBar.tsx +0 -135
  189. package/src/shell/SutrataLogo.tsx +0 -89
  190. package/src/shell/Toast.tsx +0 -46
  191. package/src/shell/ToolbarButton.tsx +0 -30
  192. package/src/shell/VersionHistory.tsx +0 -212
  193. package/src/shell/Watermark.tsx +0 -9
  194. package/src/shell/fonts/fonts.css +0 -1133
  195. package/src/shell/icons.tsx +0 -335
  196. package/src/shell/toolbar-actions.ts +0 -59
  197. package/src/source/SourceView.tsx +0 -111
  198. package/src/source/find-highlight-source.ts +0 -57
  199. package/src/source/sutra-lang.ts +0 -121
  200. package/src/spellcheck/dictionaries.ts +0 -21
  201. package/src/spellcheck/hunspell.ts +0 -110
  202. package/src/spellcheck/spellcheck-plugin.ts +0 -83
  203. package/src/styles/StyleDialog.tsx +0 -148
  204. package/src/styles/builtin-styles.ts +0 -139
  205. package/src/styles/css-adapter.ts +0 -76
  206. package/src/styles/docx-adapter.ts +0 -109
  207. package/src/styles/embed-fonts.ts +0 -81
  208. package/src/styles/pagination.ts +0 -27
  209. package/src/styles/print-adapter.ts +0 -288
  210. package/src/styles/registry.ts +0 -20
  211. package/src/styles/screenplay.css +0 -3006
  212. package/src/styles/script-ranges.ts +0 -17
  213. package/src/styles/types.ts +0 -104
  214. package/src/styles/validate.ts +0 -114
  215. package/src/templates/templates.ts +0 -194
  216. package/src/titlepage/ExportDialog.tsx +0 -494
  217. package/src/titlepage/TitlePageDialog.tsx +0 -312
  218. package/src/titlepage/frontmatter-form.ts +0 -280
  219. package/src/titlepage/languages.ts +0 -37
  220. package/src/types.ts +0 -7
  221. package/tests/AppBar.test.tsx +0 -35
  222. package/tests/AppShell.test.tsx +0 -22
  223. package/tests/ElementToolbar.test.tsx +0 -36
  224. package/tests/LanguageStatus.test.tsx +0 -129
  225. package/tests/SelectionMenu.test.tsx +0 -71
  226. package/tests/ToolbarButton.test.tsx +0 -24
  227. package/tests/ai-onboarding.test.ts +0 -102
  228. package/tests/ai-status.test.tsx +0 -72
  229. package/tests/ai-structured.test.ts +0 -94
  230. package/tests/autocomplete/AutocompletePlugin.test.ts +0 -20
  231. package/tests/autocomplete/suggestions.test.ts +0 -106
  232. package/tests/document-context.test.tsx +0 -565
  233. package/tests/docx-importer.test.ts +0 -160
  234. package/tests/editor/character-decoration-plugin.test.ts +0 -101
  235. package/tests/editor/character-extension.test.ts +0 -44
  236. package/tests/editor/grapheme-cursor.test.ts +0 -118
  237. package/tests/editor/ime-plugin.test.ts +0 -72
  238. package/tests/editor/inline-note-bridge.test.ts +0 -32
  239. package/tests/editor/language-class-plugin.test.ts +0 -265
  240. package/tests/editor/title-page.test.ts +0 -124
  241. package/tests/embed-fonts.test.ts +0 -17
  242. package/tests/exporters.test.ts +0 -365
  243. package/tests/findreplace/FindReplace.test.tsx +0 -391
  244. package/tests/findreplace/find-engine.test.ts +0 -86
  245. package/tests/findreplace/scroll-to-match.test.ts +0 -50
  246. package/tests/fonts/tofu-detect.test.ts +0 -122
  247. package/tests/i18n/LanguageContext.test.tsx +0 -146
  248. package/tests/i18n/language-detect.test.ts +0 -54
  249. package/tests/i18n/locale-parity.test.ts +0 -25
  250. package/tests/i18n/useTranslation.test.tsx +0 -45
  251. package/tests/keymap.test.ts +0 -18
  252. package/tests/navigator/SceneNavigator.test.tsx +0 -177
  253. package/tests/navigator/StatisticsDialog.test.tsx +0 -63
  254. package/tests/navigator/scene-list.test.ts +0 -71
  255. package/tests/print-paginator.test.ts +0 -82
  256. package/tests/shell/VersionHistory.test.tsx +0 -129
  257. package/tests/spellcheck/hunspell.test.ts +0 -82
  258. package/tests/spellcheck/spellcheck-plugin.test.ts +0 -56
  259. package/tests/styles.test.ts +0 -315
  260. package/tests/templates/templates.test.ts +0 -83
  261. package/tests/titlepage/TitlePageDialog.test.tsx +0 -90
  262. package/tests/titlepage/apply-title-page.test.ts +0 -61
  263. package/tests/titlepage/frontmatter-form.test.ts +0 -115
  264. package/tests/toolbar-actions.test.ts +0 -93
  265. package/tests/voice-commands.test.ts +0 -58
  266. package/tsconfig.json +0 -17
  267. package/vitest.config.ts +0 -11
  268. package/vitest.setup.ts +0 -65
@@ -1,160 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { parse } from '@sutrata/parser'
3
- import { exportToDocx } from '../src/file/docx-exporter'
4
- import { importDocx } from '../src/file/docx-importer'
5
- import JSZip from 'jszip'
6
-
7
- const testSutra = `---
8
- title: Test Movie
9
- author: Writer Name
10
- ---
11
-
12
- ## Scene 1 {#1A}
13
-
14
- Action with **bold**, *italic*, and _underline_ text.
15
-
16
- @JOHN (V.O.)
17
- Hello Mary.
18
-
19
- @MARY
20
- (smiling)
21
- Hi John.
22
-
23
- @JOHN
24
- Dual dialogue left.
25
-
26
- @MARY ^
27
- Dual dialogue right.
28
-
29
- >> CUT TO:
30
-
31
- >> THE END <<
32
-
33
- ~ La la la
34
-
35
- [[ Note text ]]
36
-
37
- <!-- Comment text -->
38
-
39
- ===
40
-
41
- # A Section
42
-
43
- Final action line.
44
- `
45
-
46
- async function roundTrip(source: string) {
47
- const ast = parse(source)
48
- const blob = await exportToDocx(ast)
49
- const buffer = await blob.arrayBuffer()
50
- return importDocx(buffer)
51
- }
52
-
53
- describe('docx-importer', () => {
54
- it('reconstructs the screenplay body from an exported docx', async () => {
55
- const { bodyText, warnings } = await roundTrip(testSutra)
56
- expect(bodyText).not.toBeNull()
57
-
58
- // Reparse the reconstructed body (no frontmatter) and check it matches structurally.
59
- const reparsed = parse(bodyText!)
60
- const original = parse(testSutra)
61
-
62
- expect(reparsed.children).toHaveLength(original.children.length)
63
-
64
- const scene = reparsed.children[0]
65
- expect(scene?.type).toBe('scene-heading')
66
- if (scene?.type === 'scene-heading') {
67
- expect(scene.text).toBe('SCENE 1')
68
- expect(scene.id).toBe('1A')
69
-
70
- const action = scene.children[0]
71
- expect(action?.type).toBe('action')
72
- if (action?.type === 'action') {
73
- expect(action.spans).toEqual([
74
- { type: 'text', text: 'Action with ' },
75
- { type: 'bold', spans: [{ type: 'text', text: 'bold' }] },
76
- { type: 'text', text: ', ' },
77
- { type: 'italic', spans: [{ type: 'text', text: 'italic' }] },
78
- { type: 'text', text: ', and ' },
79
- { type: 'underline', spans: [{ type: 'text', text: 'underline' }] },
80
- { type: 'text', text: ' text.' },
81
- ])
82
- }
83
-
84
- const john = scene.children[1]
85
- expect(john?.type).toBe('character')
86
- if (john?.type === 'character') {
87
- expect(john.name).toBe('JOHN')
88
- expect(john.extension).toBe('(V.O.)')
89
- }
90
-
91
- const mary = scene.children[2]
92
- expect(mary?.type).toBe('character')
93
- if (mary?.type === 'character') {
94
- expect(mary.children[0]).toMatchObject({ type: 'parenthetical', text: 'smiling' })
95
- }
96
-
97
- const dual = scene.children[3]
98
- expect(dual?.type).toBe('dual-dialogue')
99
- if (dual?.type === 'dual-dialogue') {
100
- expect(dual.left.name).toBe('JOHN')
101
- expect(dual.right.name).toBe('MARY')
102
- expect(dual.right.isDual).toBe(true)
103
- }
104
-
105
- expect(scene.children[4]).toMatchObject({ type: 'transition', text: 'CUT TO:' })
106
- expect(scene.children[5]).toMatchObject({ type: 'centered', text: 'THE END' })
107
- expect(scene.children[6]).toMatchObject({ type: 'lyrics' })
108
- expect(scene.children[7]).toMatchObject({ type: 'note', text: 'Note text' })
109
- expect(scene.children[8]).toMatchObject({ type: 'comment', text: 'Comment text' })
110
- expect(scene.children[9]).toMatchObject({ type: 'page-break' })
111
- }
112
-
113
- const section = reparsed.children[1]
114
- expect(section?.type).toBe('section')
115
- if (section?.type === 'section') {
116
- expect(section.text).toBe('A Section')
117
- }
118
- expect(reparsed.children[2]).toMatchObject({ type: 'action' })
119
-
120
- // Title page is intentionally not reimported.
121
- expect(warnings.some(w => w.toLowerCase().includes('title page'))).toBe(true)
122
- })
123
-
124
- it('returns null bodyText and a warning for a non-Sutrata docx', async () => {
125
- const ast = parse('---\ntitle: Empty\n---\n')
126
- const blob = await exportToDocx(ast)
127
- const buffer = await blob.arrayBuffer()
128
- const { bodyText, warnings } = await importDocx(buffer)
129
- expect(bodyText).toBeNull()
130
- expect(warnings.length).toBeGreaterThan(0)
131
- })
132
-
133
- it('throws for a file that is not a docx', async () => {
134
- const buffer = new TextEncoder().encode('not a docx').buffer
135
- await expect(importDocx(buffer)).rejects.toThrow()
136
- })
137
-
138
- it('splits the scene id from the heading when Word normalizes the tab to <w:tab/>', async () => {
139
- // docx.js (the exporter) writes a literal tab character inside <w:t>. Word, when it
140
- // resaves the file, normalizes that into a <w:tab/> element instead — reproduce that
141
- // shape directly rather than going through exportToDocx.
142
- const documentXml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
143
- <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
144
- <w:body>
145
- <w:p>
146
- <w:pPr><w:pStyle w:val="CineSceneHeading"/></w:pPr>
147
- <w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">EXT. ROAD-RAIN EFFECT - MORNING</w:t></w:r>
148
- <w:r><w:tab/></w:r>
149
- <w:r><w:rPr><w:b/></w:rPr><w:t xml:space="preserve">1A</w:t></w:r>
150
- </w:p>
151
- </w:body>
152
- </w:document>`
153
- const zip = new JSZip()
154
- zip.file('word/document.xml', documentXml)
155
- const buffer = await zip.generateAsync({ type: 'arraybuffer' })
156
-
157
- const { bodyText } = await importDocx(buffer)
158
- expect(bodyText).toBe('## EXT. ROAD-RAIN EFFECT - MORNING {#1A}')
159
- })
160
- })
@@ -1,101 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { EditorState } from 'prosemirror-state'
3
- import { schema } from '../../src/editor/schema'
4
- import { createCharacterDecorationPlugin, findCharacterDecorationRanges } from '../../src/editor/character-decoration-plugin'
5
-
6
- describe('findCharacterDecorationRanges', () => {
7
- it('finds a single trailing extension', () => {
8
- const r = findCharacterDecorationRanges('ARAVIND (V.O.)')
9
- expect(r).toEqual({ parenStart: 8, parenEnd: 14 })
10
- })
11
-
12
- it('finds multiple trailing paren groups as one range', () => {
13
- const r = findCharacterDecorationRanges("ARAVIND (V.O.) (CONT'D)")
14
- expect(r).toEqual({ parenStart: 8, parenEnd: 23 })
15
- })
16
-
17
- it('finds a trailing dual-dialogue marker alone', () => {
18
- const r = findCharacterDecorationRanges('ARAVIND ^')
19
- expect(r).toEqual({ dualStart: 8, dualEnd: 9 })
20
- })
21
-
22
- it('finds both an extension and a dual marker together', () => {
23
- const r = findCharacterDecorationRanges('ARAVIND (V.O.) ^')
24
- expect(r).toEqual({ parenStart: 8, parenEnd: 14, dualStart: 15, dualEnd: 16 })
25
- })
26
-
27
- it('finds nothing for a plain name', () => {
28
- expect(findCharacterDecorationRanges('ARAVIND')).toEqual({})
29
- })
30
-
31
- it('finds nothing for an unclosed paren (still typing)', () => {
32
- expect(findCharacterDecorationRanges('ARAVIND (')).toEqual({})
33
- })
34
- })
35
-
36
- describe('character-decoration-plugin', () => {
37
- function createStateWithPlugin(text: string) {
38
- const plugin = createCharacterDecorationPlugin()
39
- const state = EditorState.create({
40
- doc: schema.node('doc', null, [schema.node('character', null, [schema.text(text)])]),
41
- plugins: [plugin],
42
- })
43
- return { state, plugin }
44
- }
45
-
46
- it('decorates the trailing extension with cs-character-extension', () => {
47
- const { state, plugin } = createStateWithPlugin('ARAVIND (V.O.)')
48
- const decorations = plugin.getState(state)!.find()
49
- const deco = decorations.find((d: any) => d.spec?.class === 'cs-character-extension')
50
- expect(deco).toBeDefined()
51
- // +1 for the block node's own opening position
52
- expect(deco.from).toBe(1 + 8)
53
- expect(deco.to).toBe(1 + 14)
54
- })
55
-
56
- it('decorates multiple trailing paren groups as one extension span', () => {
57
- const { state, plugin } = createStateWithPlugin("ARAVIND (V.O.) (CONT'D)")
58
- const decorations = plugin.getState(state)!.find()
59
- const deco = decorations.find((d: any) => d.spec?.class === 'cs-character-extension')
60
- expect(deco.from).toBe(1 + 8)
61
- expect(deco.to).toBe(1 + 23)
62
- })
63
-
64
- it('decorates a trailing dual-dialogue marker with cs-character-dual-marker', () => {
65
- const { state, plugin } = createStateWithPlugin('ARAVIND ^')
66
- const decorations = plugin.getState(state)!.find()
67
- const deco = decorations.find((d: any) => d.spec?.class === 'cs-character-dual-marker')
68
- expect(deco).toBeDefined()
69
- })
70
-
71
- it('decorates both an extension and a dual marker on the same cue', () => {
72
- const { state, plugin } = createStateWithPlugin('ARAVIND (V.O.) ^')
73
- const decorations = plugin.getState(state)!.find()
74
- expect(decorations.some((d: any) => d.spec?.class === 'cs-character-extension')).toBe(true)
75
- expect(decorations.some((d: any) => d.spec?.class === 'cs-character-dual-marker')).toBe(true)
76
- })
77
-
78
- it('produces no decorations for a plain character name', () => {
79
- const { state, plugin } = createStateWithPlugin('ARAVIND')
80
- expect(plugin.getState(state)!.find()).toHaveLength(0)
81
- })
82
-
83
- it('does not decorate non-character blocks', () => {
84
- const plugin = createCharacterDecorationPlugin()
85
- const state = EditorState.create({
86
- doc: schema.node('doc', null, [schema.node('action', null, [schema.text('Just an (aside) in action.')])]),
87
- plugins: [plugin],
88
- })
89
- expect(plugin.getState(state)!.find()).toHaveLength(0)
90
- })
91
-
92
- it('recomputes decorations after a doc-changing transaction', () => {
93
- const { state: initialState, plugin } = createStateWithPlugin('ARAVIND')
94
- expect(plugin.getState(initialState)!.find()).toHaveLength(0)
95
-
96
- const tr = initialState.tr.insertText(' (V.O.)', 8)
97
- const newState = initialState.apply(tr)
98
- const decorations = plugin.getState(newState)!.find()
99
- expect(decorations.some((d: any) => d.spec?.class === 'cs-character-extension')).toBe(true)
100
- })
101
- })
@@ -1,44 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { parse } from '@sutrata/parser'
3
- import { sutraToProsemirror } from '../../src/editor/sutra-to-prosemirror'
4
- import { prosemirrorToSutra } from '../../src/editor/prosemirror-to-sutra'
5
-
6
- function characterText(src: string): string {
7
- const pmDoc = sutraToProsemirror(parse(src))
8
- let text = ''
9
- pmDoc.descendants(node => {
10
- if (node.type.name === 'character') text = node.textContent
11
- })
12
- return text
13
- }
14
-
15
- describe('character extension/dual-marker — Sutra <-> ProseMirror bridge (text-based, no attrs)', () => {
16
- it('puts the extension directly in the character node text, no separate attr', () => {
17
- expect(characterText('## SC1\n\n@ARAVIND (V.O.)\nHello.\n')).toBe('ARAVIND (V.O.)')
18
- })
19
-
20
- it('handles multiple trailing paren groups', () => {
21
- expect(characterText("## SC1\n\n@ARAVIND (V.O.) (CONT'D)\nHello.\n")).toBe("ARAVIND (V.O.) (CONT'D)")
22
- })
23
-
24
- it('handles a plain name with no extension', () => {
25
- expect(characterText('## SC1\n\n@ARAVIND\nHello.\n')).toBe('ARAVIND')
26
- })
27
-
28
- it.each([
29
- '@ARAVIND (V.O.)',
30
- "@ARAVIND (V.O.) (CONT'D)",
31
- '@ARAVIND',
32
- ])('round-trips %s back to the exact source line', (cue) => {
33
- const src = `## SC1\n\n${cue}\nHello.\n`
34
- const out = prosemirrorToSutra(sutraToProsemirror(parse(src)))
35
- expect(out).toContain(cue)
36
- })
37
-
38
- it('round-trips a dual-dialogue pair including the ^ marker and an extension', () => {
39
- const src = "## SC1\n\n@ARAVIND (V.O.)\nHello.\n\n@MEERA ^\nHi.\n"
40
- const out = prosemirrorToSutra(sutraToProsemirror(parse(src)))
41
- expect(out).toContain('@ARAVIND (V.O.)')
42
- expect(out).toContain('@MEERA ^')
43
- })
44
- })
@@ -1,118 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { EditorState, TextSelection } from 'prosemirror-state'
3
- import { schema } from '../../src/editor/schema'
4
- import { moveByGrapheme, extendByGrapheme } from '../../src/editor/grapheme-cursor'
5
-
6
- /**
7
- * ProseMirror position layout for an action node containing text T (length n):
8
- * pos 1 = action open (= $cursor.start())
9
- * pos 2 = first UTF-16 code unit of T
10
- * ...
11
- * pos 1+n = action close (= $cursor.end())
12
- *
13
- * Each JS string character (UTF-16 code unit) takes exactly 1 PM position.
14
- * Surrogate pairs (emoji, etc.) each take 2 positions in PM.
15
- *
16
- * Cursor at pos 1 is before the very first character (the true block-start).
17
- * Cursor at pos 1+n is after the last character (the true block-end).
18
- */
19
- function makeState(text: string, cursorPos: number) {
20
- const doc = schema.node('doc', null, [
21
- schema.node('action', null, text ? [schema.text(text)] : []),
22
- ])
23
- const state = EditorState.create({ doc, schema })
24
- return state.apply(
25
- state.tr.setSelection(TextSelection.create(doc, cursorPos))
26
- )
27
- }
28
-
29
- describe('grapheme-cursor', () => {
30
- it('moveByGrapheme right advances over a single ASCII char', () => {
31
- // 'ABC': pos 1=start, pos 2='A', pos 3='B', pos 4='C', pos 5=end
32
- const state = makeState('ABC', 2) // cursor after 'A'... wait: pos 2 = after action_open = before 'A'?
33
- // No: pos 1 = action_open = start(). pos 2 = position after first char 'A'.
34
- // Actually: textBetween(1, 4) = 'ABC' → positions 1..4 map to chars A,B,C.
35
- // So pos 1 is before 'A', pos 2 is between 'A' and 'B', pos 3 is between 'B' and 'C', pos 4 is after 'C'.
36
- // Cursor at pos 1: textBetween(1, 4) = 'ABC', first grapheme 'A' (len 1) → advance to pos 2.
37
- // Cursor at pos 2: textBetween(2, 4) = 'BC', first grapheme 'B' → advance to pos 3. ✓
38
- let dispatched: any = null
39
- moveByGrapheme('right')(state, (tr) => { dispatched = tr })
40
- expect(dispatched).not.toBeNull()
41
- const sel = dispatched.selection as TextSelection
42
- expect(sel.$cursor?.pos).toBe(3) // 'B' is next, advance by 1
43
- })
44
-
45
- it('moveByGrapheme right advances over the first grapheme in a Tamil sequence', () => {
46
- // 'க்ஷ' = U+0B95 U+0BCD U+0BB7 (3 BMP chars, 3 PM positions)
47
- // Node.js ICU segments 'க்ஷA' as ['க்'(len 2), 'ஷ'(len 1), 'A'(len 1)]
48
- // Cursor at pos 1 (block start, before 'க'): textBetween(1, 5) = 'க்ஷA'
49
- // First grapheme 'க்' has length 2 → cursor advances to pos 3.
50
- const cluster = 'க்ஷ'
51
- expect(cluster.length).toBe(3) // 3 UTF-16 code units
52
- const state = makeState(cluster + 'A', 1) // cursor at block start, before 'க'
53
- let dispatched: any = null
54
- moveByGrapheme('right')(state, (tr) => { dispatched = tr })
55
- expect(dispatched).not.toBeNull()
56
- const sel = dispatched.selection as TextSelection
57
- // Advances by 2 (length of first grapheme 'க்'), not by 1 (single codepoint)
58
- expect(sel.$cursor?.pos).toBe(3)
59
- })
60
-
61
- it('moveByGrapheme left retreats over a Tamil grapheme cluster', () => {
62
- // 'Aக்ஷ': pos 1=start, pos 2='A', pos 3='க', pos 4='்', pos 5='ஷ', end()=5
63
- // Cursor at pos 4 (after 'A','க','்'): textBetween(1, 4) = 'Aக்'
64
- // graphemes of 'Aக்' = ['A', 'க்'] → last grapheme 'க்' (len 2) → retreat by 2 → pos 2
65
- const cluster = 'க்ஷ'
66
- const state = makeState('A' + cluster, 4) // cursor after 'க்'
67
- let dispatched: any = null
68
- moveByGrapheme('left')(state, (tr) => { dispatched = tr })
69
- expect(dispatched).not.toBeNull()
70
- const sel = dispatched.selection as TextSelection
71
- // Retreats by 2 (length of 'க்'), landing before 'க'
72
- expect(sel.$cursor?.pos).toBe(2)
73
- })
74
-
75
- it('moveByGrapheme right advances over emoji ZWJ sequence as one grapheme', () => {
76
- // '👨‍👩‍👧' is a family ZWJ emoji — 1 grapheme cluster, 8 UTF-16 code units = 8 PM positions
77
- // Cursor at pos 1 (block start): textBetween(1, 9) = emoji string (length 8)
78
- // Intl.Segmenter gives 1 grapheme of length 8 → advance by 8 → pos 9
79
- const emoji = '👨‍👩‍👧'
80
- expect(emoji.length).toBe(8) // 8 UTF-16 code units
81
- const state = makeState(emoji, 1) // cursor at block start, before emoji
82
- let dispatched: any = null
83
- moveByGrapheme('right')(state, (tr) => { dispatched = tr })
84
- expect(dispatched).not.toBeNull()
85
- const sel = dispatched.selection as TextSelection
86
- // Should advance by 8 (full emoji = single grapheme)
87
- expect(sel.$cursor?.pos).toBe(1 + emoji.length) // 9
88
- })
89
-
90
- it('moveByGrapheme right returns false at end of block', () => {
91
- // 'A': start()=1, end()=2. Cursor at pos 2 (after 'A') → pos(2) >= end(2) → false
92
- const state = makeState('A', 2) // cursor after 'A', at block end
93
- const result = moveByGrapheme('right')(state, () => {})
94
- expect(result).toBe(false)
95
- })
96
-
97
- it('moveByGrapheme left returns false at start of block', () => {
98
- // start() = 1 for any inline content. Cursor at pos 1 → pos(1) <= start(1) → false
99
- const state = makeState('A', 1) // cursor at block start
100
- const result = moveByGrapheme('left')(state, () => {})
101
- expect(result).toBe(false)
102
- })
103
-
104
- it('extendByGrapheme right extends selection over first Tamil grapheme', () => {
105
- // 'க்ஷ': cursor at pos 1 (before 'க')
106
- // textBetween(head=1, end=4) = 'க்ஷ'
107
- // graphemes ['க்','ஷ'] → first='க்' (len 2) → head goes to 1+2=3
108
- // anchor stays at 1
109
- const cluster = 'க்ஷ'
110
- const state = makeState(cluster, 1) // cursor at block start
111
- let dispatched: any = null
112
- extendByGrapheme('right')(state, (tr) => { dispatched = tr })
113
- expect(dispatched).not.toBeNull()
114
- const sel = dispatched.selection as TextSelection
115
- expect(sel.head).toBe(3) // extended by 2 (first grapheme 'க்')
116
- expect(sel.anchor).toBe(1) // anchor unchanged
117
- })
118
- })
@@ -1,72 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest'
2
- import { EditorState } from 'prosemirror-state'
3
- import { schema } from '../../src/editor/schema'
4
- import { createImePlugin, isComposing } from '../../src/editor/ime-plugin'
5
-
6
- // Minimal EditorView mock — only needs dom + dispatch + state
7
- function makeMockView(dom?: HTMLElement) {
8
- const el = dom ?? document.createElement('div')
9
- document.body.appendChild(el)
10
- return {
11
- dom: el,
12
- dispatch: vi.fn(),
13
- state: EditorState.create({ schema, plugins: [] }),
14
- }
15
- }
16
-
17
- describe('ime-plugin', () => {
18
- it('exports createImePlugin and isComposing', () => {
19
- expect(typeof createImePlugin).toBe('function')
20
- expect(typeof isComposing).toBe('function')
21
- })
22
-
23
- it('isComposing returns false when no composition active', () => {
24
- expect(isComposing()).toBe(false)
25
- })
26
-
27
- it('plugin view attaches compositionstart/end listeners to dom', () => {
28
- const dom = document.createElement('div')
29
- const addSpy = vi.spyOn(dom, 'addEventListener')
30
- const mockView = { ...makeMockView(dom), dom } as any
31
- const plugin = createImePlugin()
32
- plugin.spec.view!(mockView)
33
-
34
- expect(addSpy).toHaveBeenCalledWith('compositionstart', expect.any(Function))
35
- expect(addSpy).toHaveBeenCalledWith('compositionend', expect.any(Function))
36
- })
37
-
38
- it('plugin view removes listeners on destroy', () => {
39
- const dom = document.createElement('div')
40
- const removeSpy = vi.spyOn(dom, 'removeEventListener')
41
- const mockView = { ...makeMockView(dom), dom } as any
42
- const plugin = createImePlugin()
43
- const view = plugin.spec.view!(mockView)
44
-
45
- view!.destroy!()
46
-
47
- expect(removeSpy).toHaveBeenCalledWith('compositionstart', expect.any(Function))
48
- expect(removeSpy).toHaveBeenCalledWith('compositionend', expect.any(Function))
49
- })
50
-
51
- it('compositionstart sets composing = true', () => {
52
- const dom = document.createElement('div')
53
- const mockView = { ...makeMockView(dom), dom } as any
54
- const plugin = createImePlugin()
55
- const pluginView = plugin.spec.view!(mockView) as any
56
-
57
- dom.dispatchEvent(new Event('compositionstart'))
58
- expect(pluginView.isComposing()).toBe(true)
59
- })
60
-
61
- it('compositionend sets composing = false', () => {
62
- const dom = document.createElement('div')
63
- const mockView = { ...makeMockView(dom), dom } as any
64
- const plugin = createImePlugin()
65
- const pluginView = plugin.spec.view!(mockView) as any
66
-
67
- dom.dispatchEvent(new Event('compositionstart'))
68
- expect(pluginView.isComposing()).toBe(true)
69
- dom.dispatchEvent(new Event('compositionend'))
70
- expect(pluginView.isComposing()).toBe(false)
71
- })
72
- })
@@ -1,32 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { parse } from '@sutrata/parser'
3
- import { sutraToProsemirror } from '../../src/editor/sutra-to-prosemirror'
4
- import { prosemirrorToSutra } from '../../src/editor/prosemirror-to-sutra'
5
- import { schema } from '../../src/editor/schema'
6
-
7
- describe('inline [[ ]] note — Sutra <-> ProseMirror bridge', () => {
8
- it('carries the note_mark on the bracketed text when converting Sutra to ProseMirror', () => {
9
- const src = "## SC1\n\nThere's no next train. [[दर्शक को यहीं पता चलना चाहिए]]\n"
10
- const ast = parse(src)
11
- const pmDoc = sutraToProsemirror(ast)
12
-
13
- let found: { text: string | null; hasMark: boolean } | null = null
14
- pmDoc.descendants(node => {
15
- if (node.isText && node.text?.includes('दर्शक')) {
16
- found = { text: node.text, hasMark: !!node.marks.find(m => m.type === schema.marks['note_mark']) }
17
- }
18
- })
19
-
20
- expect(found).not.toBeNull()
21
- expect(found!.hasMark).toBe(true)
22
- })
23
-
24
- it('round-trips the note back into [[ ]] brackets when converting ProseMirror to Sutra', () => {
25
- const src = "## SC1\n\nThere's no next train. [[दर्शक को यहीं पता चलना चाहिए]]\n"
26
- const ast = parse(src)
27
- const pmDoc = sutraToProsemirror(ast)
28
- const out = prosemirrorToSutra(pmDoc)
29
-
30
- expect(out).toContain('[[दर्शक को यहीं पता चलना चाहिए]]')
31
- })
32
- })