@sutrata/editor 0.1.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 (337) hide show
  1. package/LICENSE +674 -0
  2. package/dist/ai/OnboardingDialog.d.ts +6 -0
  3. package/dist/ai/OnboardingDialog.js +115 -0
  4. package/dist/ai/VoiceConfirmDialog.d.ts +9 -0
  5. package/dist/ai/VoiceConfirmDialog.js +37 -0
  6. package/dist/ai/VoiceToolbar.d.ts +2 -0
  7. package/dist/ai/VoiceToolbar.js +177 -0
  8. package/dist/ai/ai-client.d.ts +71 -0
  9. package/dist/ai/ai-client.js +494 -0
  10. package/dist/ai/commands.d.ts +12 -0
  11. package/dist/ai/commands.js +140 -0
  12. package/dist/ai/generated-providers.json +3696 -0
  13. package/dist/ai/prompts.d.ts +25 -0
  14. package/dist/ai/prompts.js +59 -0
  15. package/dist/ai/voice-service.d.ts +15 -0
  16. package/dist/ai/voice-service.js +81 -0
  17. package/dist/autocomplete/AutocompletePlugin.d.ts +2 -0
  18. package/dist/autocomplete/AutocompletePlugin.js +19 -0
  19. package/dist/autocomplete/suggestions.d.ts +25 -0
  20. package/dist/autocomplete/suggestions.js +126 -0
  21. package/dist/context/DocumentContext.d.ts +68 -0
  22. package/dist/context/DocumentContext.js +605 -0
  23. package/dist/desktop-api.d.ts +40 -0
  24. package/dist/editor/EditorView.d.ts +2 -0
  25. package/dist/editor/EditorView.js +78 -0
  26. package/dist/editor/SelectionMenu.d.ts +2 -0
  27. package/dist/editor/SelectionMenu.js +102 -0
  28. package/dist/editor/attr-pencil-plugin.d.ts +17 -0
  29. package/dist/editor/attr-pencil-plugin.js +158 -0
  30. package/dist/editor/character-decoration-plugin.d.ts +26 -0
  31. package/dist/editor/character-decoration-plugin.js +77 -0
  32. package/dist/editor/character-view.d.ts +35 -0
  33. package/dist/editor/character-view.js +112 -0
  34. package/dist/editor/editor-bus.d.ts +14 -0
  35. package/dist/editor/editor-bus.js +39 -0
  36. package/dist/editor/find-highlight-plugin.d.ts +7 -0
  37. package/dist/editor/find-highlight-plugin.js +57 -0
  38. package/dist/editor/frontmatter-field-view.d.ts +10 -0
  39. package/dist/editor/frontmatter-field-view.js +48 -0
  40. package/dist/editor/frontmatter-field.d.ts +21 -0
  41. package/dist/editor/frontmatter-field.js +116 -0
  42. package/dist/editor/grapheme-cursor.d.ts +10 -0
  43. package/dist/editor/grapheme-cursor.js +104 -0
  44. package/dist/editor/ime-plugin.d.ts +18 -0
  45. package/dist/editor/ime-plugin.js +71 -0
  46. package/dist/editor/insert-helper.d.ts +1 -0
  47. package/dist/editor/insert-helper.js +42 -0
  48. package/dist/editor/keymap.d.ts +3 -0
  49. package/dist/editor/keymap.js +131 -0
  50. package/dist/editor/language-class-plugin.d.ts +7 -0
  51. package/dist/editor/language-class-plugin.js +75 -0
  52. package/dist/editor/plugins.d.ts +1 -0
  53. package/dist/editor/plugins.js +25 -0
  54. package/dist/editor/prosemirror-to-sutra.d.ts +2 -0
  55. package/dist/editor/prosemirror-to-sutra.js +208 -0
  56. package/dist/editor/scene-heading-view.d.ts +27 -0
  57. package/dist/editor/scene-heading-view.js +136 -0
  58. package/dist/editor/schema.d.ts +3 -0
  59. package/dist/editor/schema.js +135 -0
  60. package/dist/editor/sutra-to-prosemirror.d.ts +3 -0
  61. package/dist/editor/sutra-to-prosemirror.js +154 -0
  62. package/dist/editor/transliterate-input.d.ts +10 -0
  63. package/dist/editor/transliterate-input.js +88 -0
  64. package/dist/extensions/storage-adapter.d.ts +59 -0
  65. package/dist/extensions/storage-adapter.js +9 -0
  66. package/dist/extensions/types.d.ts +73 -0
  67. package/dist/extensions/types.js +12 -0
  68. package/dist/file/docx-exporter.d.ts +8 -0
  69. package/dist/file/docx-exporter.js +494 -0
  70. package/dist/file/docx-importer.d.ts +10 -0
  71. package/dist/file/docx-importer.js +283 -0
  72. package/dist/file/print-paginator.d.ts +29 -0
  73. package/dist/file/print-paginator.js +289 -0
  74. package/dist/file/templates.d.ts +2 -0
  75. package/dist/file/templates.js +66 -0
  76. package/dist/file/workflow-reports.d.ts +34 -0
  77. package/dist/file/workflow-reports.js +719 -0
  78. package/dist/findreplace/FindReplace.d.ts +2 -0
  79. package/dist/findreplace/FindReplace.js +164 -0
  80. package/dist/findreplace/find-engine.d.ts +29 -0
  81. package/dist/findreplace/find-engine.js +69 -0
  82. package/dist/findreplace/scroll-to-match.d.ts +29 -0
  83. package/dist/findreplace/scroll-to-match.js +74 -0
  84. package/dist/fonts/tofu-detect.d.ts +1 -0
  85. package/dist/fonts/tofu-detect.js +48 -0
  86. package/dist/i18n/LanguageContext.d.ts +10 -0
  87. package/dist/i18n/LanguageContext.js +174 -0
  88. package/dist/i18n/language-detect.d.ts +1 -0
  89. package/dist/i18n/language-detect.js +58 -0
  90. package/dist/i18n/useTranslation.d.ts +11 -0
  91. package/dist/i18n/useTranslation.js +60 -0
  92. package/dist/index.d.ts +11 -0
  93. package/dist/index.js +5 -0
  94. package/dist/locales/bn.json +143 -0
  95. package/dist/locales/en.json +143 -0
  96. package/dist/locales/gu.json +143 -0
  97. package/dist/locales/hi.json +143 -0
  98. package/dist/locales/kn.json +143 -0
  99. package/dist/locales/ml.json +143 -0
  100. package/dist/locales/mr.json +143 -0
  101. package/dist/locales/or.json +143 -0
  102. package/dist/locales/pa.json +143 -0
  103. package/dist/locales/si.json +143 -0
  104. package/dist/locales/ta.json +143 -0
  105. package/dist/locales/te.json +143 -0
  106. package/dist/navigator/SceneNavigator.d.ts +2 -0
  107. package/dist/navigator/SceneNavigator.js +612 -0
  108. package/dist/navigator/StatisticsDialog.d.ts +6 -0
  109. package/dist/navigator/StatisticsDialog.js +146 -0
  110. package/dist/navigator/scene-list.d.ts +16 -0
  111. package/dist/navigator/scene-list.js +70 -0
  112. package/dist/settings/SettingsDialog.d.ts +6 -0
  113. package/dist/settings/SettingsDialog.js +147 -0
  114. package/dist/shell/AppBar.d.ts +2 -0
  115. package/dist/shell/AppBar.js +34 -0
  116. package/dist/shell/AppShell.d.ts +2 -0
  117. package/dist/shell/AppShell.js +30 -0
  118. package/dist/shell/ConfirmDialog.d.ts +16 -0
  119. package/dist/shell/ConfirmDialog.js +23 -0
  120. package/dist/shell/ElementToolbar.d.ts +2 -0
  121. package/dist/shell/ElementToolbar.js +30 -0
  122. package/dist/shell/LanguageStatus.d.ts +2 -0
  123. package/dist/shell/LanguageStatus.js +65 -0
  124. package/dist/shell/StatusBar.d.ts +2 -0
  125. package/dist/shell/StatusBar.js +54 -0
  126. package/dist/shell/SutrataLogo.d.ts +8 -0
  127. package/dist/shell/SutrataLogo.js +7 -0
  128. package/dist/shell/Toast.d.ts +12 -0
  129. package/dist/shell/Toast.js +21 -0
  130. package/dist/shell/ToolbarButton.d.ts +11 -0
  131. package/dist/shell/ToolbarButton.js +4 -0
  132. package/dist/shell/VersionHistory.d.ts +12 -0
  133. package/dist/shell/VersionHistory.js +89 -0
  134. package/dist/shell/Watermark.d.ts +3 -0
  135. package/dist/shell/Watermark.js +10 -0
  136. package/dist/shell/fonts/fonts.css +1133 -0
  137. package/dist/shell/icons.d.ts +45 -0
  138. package/dist/shell/icons.js +51 -0
  139. package/dist/shell/toolbar-actions.d.ts +6 -0
  140. package/dist/shell/toolbar-actions.js +58 -0
  141. package/dist/source/SourceView.d.ts +1 -0
  142. package/dist/source/SourceView.js +106 -0
  143. package/dist/source/find-highlight-source.d.ts +14 -0
  144. package/dist/source/find-highlight-source.js +47 -0
  145. package/dist/source/sutra-lang.d.ts +2 -0
  146. package/dist/source/sutra-lang.js +97 -0
  147. package/dist/spellcheck/dictionaries.d.ts +9 -0
  148. package/dist/spellcheck/dictionaries.js +16 -0
  149. package/dist/spellcheck/hunspell.d.ts +23 -0
  150. package/dist/spellcheck/hunspell.js +94 -0
  151. package/dist/spellcheck/spellcheck-plugin.d.ts +18 -0
  152. package/dist/spellcheck/spellcheck-plugin.js +75 -0
  153. package/dist/styles/StyleDialog.d.ts +6 -0
  154. package/dist/styles/StyleDialog.js +63 -0
  155. package/dist/styles/builtin-styles.d.ts +43 -0
  156. package/dist/styles/builtin-styles.js +131 -0
  157. package/dist/styles/css-adapter.d.ts +32 -0
  158. package/dist/styles/css-adapter.js +71 -0
  159. package/dist/styles/docx-adapter.d.ts +7 -0
  160. package/dist/styles/docx-adapter.js +84 -0
  161. package/dist/styles/embed-fonts.d.ts +20 -0
  162. package/dist/styles/embed-fonts.js +81 -0
  163. package/dist/styles/pagination.d.ts +19 -0
  164. package/dist/styles/pagination.js +22 -0
  165. package/dist/styles/print-adapter.d.ts +6 -0
  166. package/dist/styles/print-adapter.js +288 -0
  167. package/dist/styles/registry.d.ts +6 -0
  168. package/dist/styles/registry.js +14 -0
  169. package/dist/styles/screenplay.css +3006 -0
  170. package/dist/styles/script-ranges.d.ts +6 -0
  171. package/dist/styles/script-ranges.js +17 -0
  172. package/dist/styles/types.d.ts +93 -0
  173. package/dist/styles/types.js +18 -0
  174. package/dist/styles/validate.d.ts +12 -0
  175. package/dist/styles/validate.js +105 -0
  176. package/dist/templates/templates.d.ts +10 -0
  177. package/dist/templates/templates.js +181 -0
  178. package/dist/titlepage/ExportDialog.d.ts +1 -0
  179. package/dist/titlepage/ExportDialog.js +152 -0
  180. package/dist/titlepage/TitlePageDialog.d.ts +6 -0
  181. package/dist/titlepage/TitlePageDialog.js +96 -0
  182. package/dist/titlepage/frontmatter-form.d.ts +56 -0
  183. package/dist/titlepage/frontmatter-form.js +245 -0
  184. package/dist/titlepage/languages.d.ts +10 -0
  185. package/dist/titlepage/languages.js +31 -0
  186. package/dist/types.d.ts +6 -0
  187. package/dist/types.js +1 -0
  188. package/package.json +47 -0
  189. package/scripts/copy-assets.mjs +16 -0
  190. package/scripts/generate-providers.mjs +127 -0
  191. package/src/ai/OnboardingDialog.tsx +390 -0
  192. package/src/ai/VoiceConfirmDialog.tsx +137 -0
  193. package/src/ai/VoiceToolbar.tsx +321 -0
  194. package/src/ai/ai-client.ts +596 -0
  195. package/src/ai/commands.ts +164 -0
  196. package/src/ai/generated-providers.json +3696 -0
  197. package/src/ai/prompts.ts +62 -0
  198. package/src/ai/voice-service.ts +96 -0
  199. package/src/autocomplete/AutocompletePlugin.ts +21 -0
  200. package/src/autocomplete/suggestions.ts +147 -0
  201. package/src/context/DocumentContext.tsx +648 -0
  202. package/src/desktop-api.d.ts +40 -0
  203. package/src/editor/EditorView.tsx +82 -0
  204. package/src/editor/SelectionMenu.tsx +152 -0
  205. package/src/editor/attr-pencil-plugin.ts +172 -0
  206. package/src/editor/character-decoration-plugin.ts +104 -0
  207. package/src/editor/editor-bus.ts +51 -0
  208. package/src/editor/find-highlight-plugin.ts +68 -0
  209. package/src/editor/frontmatter-field-view.ts +52 -0
  210. package/src/editor/frontmatter-field.ts +115 -0
  211. package/src/editor/grapheme-cursor.ts +99 -0
  212. package/src/editor/ime-plugin.ts +85 -0
  213. package/src/editor/insert-helper.ts +43 -0
  214. package/src/editor/keymap.ts +124 -0
  215. package/src/editor/language-class-plugin.ts +91 -0
  216. package/src/editor/plugins.ts +26 -0
  217. package/src/editor/prosemirror-to-sutra.ts +192 -0
  218. package/src/editor/scene-heading-view.ts +147 -0
  219. package/src/editor/schema.ts +156 -0
  220. package/src/editor/sutra-to-prosemirror.ts +156 -0
  221. package/src/extensions/storage-adapter.ts +65 -0
  222. package/src/extensions/types.ts +60 -0
  223. package/src/file/docx-exporter.ts +585 -0
  224. package/src/file/docx-importer.ts +313 -0
  225. package/src/file/print-paginator.ts +301 -0
  226. package/src/file/templates.ts +73 -0
  227. package/src/file/workflow-reports.ts +820 -0
  228. package/src/findreplace/FindReplace.tsx +242 -0
  229. package/src/findreplace/find-engine.ts +97 -0
  230. package/src/findreplace/scroll-to-match.ts +89 -0
  231. package/src/fonts/tofu-detect.ts +53 -0
  232. package/src/i18n/LanguageContext.tsx +207 -0
  233. package/src/i18n/language-detect.ts +73 -0
  234. package/src/i18n/useTranslation.tsx +74 -0
  235. package/src/index.ts +27 -0
  236. package/src/locales/bn.json +143 -0
  237. package/src/locales/en.json +143 -0
  238. package/src/locales/gu.json +143 -0
  239. package/src/locales/hi.json +143 -0
  240. package/src/locales/kn.json +143 -0
  241. package/src/locales/ml.json +143 -0
  242. package/src/locales/mr.json +143 -0
  243. package/src/locales/or.json +143 -0
  244. package/src/locales/pa.json +143 -0
  245. package/src/locales/si.json +143 -0
  246. package/src/locales/ta.json +143 -0
  247. package/src/locales/te.json +143 -0
  248. package/src/navigator/SceneNavigator.tsx +844 -0
  249. package/src/navigator/StatisticsDialog.tsx +249 -0
  250. package/src/navigator/scene-list.ts +84 -0
  251. package/src/settings/SettingsDialog.tsx +303 -0
  252. package/src/shell/AppBar.tsx +354 -0
  253. package/src/shell/AppShell.tsx +71 -0
  254. package/src/shell/ConfirmDialog.tsx +71 -0
  255. package/src/shell/ElementToolbar.tsx +175 -0
  256. package/src/shell/LanguageStatus.tsx +101 -0
  257. package/src/shell/StatusBar.tsx +135 -0
  258. package/src/shell/SutrataLogo.tsx +89 -0
  259. package/src/shell/Toast.tsx +46 -0
  260. package/src/shell/ToolbarButton.tsx +30 -0
  261. package/src/shell/VersionHistory.tsx +212 -0
  262. package/src/shell/Watermark.tsx +9 -0
  263. package/src/shell/fonts/fonts.css +1133 -0
  264. package/src/shell/icons.tsx +335 -0
  265. package/src/shell/toolbar-actions.ts +59 -0
  266. package/src/source/SourceView.tsx +111 -0
  267. package/src/source/find-highlight-source.ts +57 -0
  268. package/src/source/sutra-lang.ts +121 -0
  269. package/src/spellcheck/dictionaries.ts +21 -0
  270. package/src/spellcheck/hunspell.ts +110 -0
  271. package/src/spellcheck/spellcheck-plugin.ts +83 -0
  272. package/src/styles/StyleDialog.tsx +148 -0
  273. package/src/styles/builtin-styles.ts +139 -0
  274. package/src/styles/css-adapter.ts +76 -0
  275. package/src/styles/docx-adapter.ts +109 -0
  276. package/src/styles/embed-fonts.ts +81 -0
  277. package/src/styles/pagination.ts +27 -0
  278. package/src/styles/print-adapter.ts +288 -0
  279. package/src/styles/registry.ts +20 -0
  280. package/src/styles/screenplay.css +3006 -0
  281. package/src/styles/script-ranges.ts +17 -0
  282. package/src/styles/types.ts +104 -0
  283. package/src/styles/validate.ts +114 -0
  284. package/src/templates/templates.ts +194 -0
  285. package/src/titlepage/ExportDialog.tsx +494 -0
  286. package/src/titlepage/TitlePageDialog.tsx +312 -0
  287. package/src/titlepage/frontmatter-form.ts +280 -0
  288. package/src/titlepage/languages.ts +37 -0
  289. package/src/types.ts +7 -0
  290. package/tests/AppBar.test.tsx +35 -0
  291. package/tests/AppShell.test.tsx +22 -0
  292. package/tests/ElementToolbar.test.tsx +36 -0
  293. package/tests/LanguageStatus.test.tsx +129 -0
  294. package/tests/SelectionMenu.test.tsx +71 -0
  295. package/tests/ToolbarButton.test.tsx +24 -0
  296. package/tests/ai-onboarding.test.ts +102 -0
  297. package/tests/ai-status.test.tsx +72 -0
  298. package/tests/ai-structured.test.ts +94 -0
  299. package/tests/autocomplete/AutocompletePlugin.test.ts +20 -0
  300. package/tests/autocomplete/suggestions.test.ts +106 -0
  301. package/tests/document-context.test.tsx +565 -0
  302. package/tests/docx-importer.test.ts +160 -0
  303. package/tests/editor/character-decoration-plugin.test.ts +101 -0
  304. package/tests/editor/character-extension.test.ts +44 -0
  305. package/tests/editor/grapheme-cursor.test.ts +118 -0
  306. package/tests/editor/ime-plugin.test.ts +72 -0
  307. package/tests/editor/inline-note-bridge.test.ts +32 -0
  308. package/tests/editor/language-class-plugin.test.ts +265 -0
  309. package/tests/editor/title-page.test.ts +124 -0
  310. package/tests/embed-fonts.test.ts +17 -0
  311. package/tests/exporters.test.ts +365 -0
  312. package/tests/findreplace/FindReplace.test.tsx +391 -0
  313. package/tests/findreplace/find-engine.test.ts +86 -0
  314. package/tests/findreplace/scroll-to-match.test.ts +50 -0
  315. package/tests/fonts/tofu-detect.test.ts +122 -0
  316. package/tests/i18n/LanguageContext.test.tsx +146 -0
  317. package/tests/i18n/language-detect.test.ts +54 -0
  318. package/tests/i18n/locale-parity.test.ts +25 -0
  319. package/tests/i18n/useTranslation.test.tsx +45 -0
  320. package/tests/keymap.test.ts +18 -0
  321. package/tests/navigator/SceneNavigator.test.tsx +177 -0
  322. package/tests/navigator/StatisticsDialog.test.tsx +63 -0
  323. package/tests/navigator/scene-list.test.ts +71 -0
  324. package/tests/print-paginator.test.ts +82 -0
  325. package/tests/shell/VersionHistory.test.tsx +129 -0
  326. package/tests/spellcheck/hunspell.test.ts +82 -0
  327. package/tests/spellcheck/spellcheck-plugin.test.ts +56 -0
  328. package/tests/styles.test.ts +315 -0
  329. package/tests/templates/templates.test.ts +83 -0
  330. package/tests/titlepage/TitlePageDialog.test.tsx +90 -0
  331. package/tests/titlepage/apply-title-page.test.ts +61 -0
  332. package/tests/titlepage/frontmatter-form.test.ts +115 -0
  333. package/tests/toolbar-actions.test.ts +93 -0
  334. package/tests/voice-commands.test.ts +58 -0
  335. package/tsconfig.json +17 -0
  336. package/vitest.config.ts +11 -0
  337. package/vitest.setup.ts +65 -0
@@ -0,0 +1,146 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useDocument } from '../context/DocumentContext';
3
+ import { extractWorkflowData } from '../file/workflow-reports';
4
+ import { getEditorView } from '../editor/editor-bus';
5
+ import { schema } from '../editor/schema';
6
+ export function StatisticsDialog({ onClose }) {
7
+ const { ast, text, setText } = useDocument();
8
+ const { scenes, characters } = extractWorkflowData(ast);
9
+ const handleUpdateActor = (charName, actorName) => {
10
+ const cleanChar = charName.trim().toUpperCase();
11
+ if (!cleanChar)
12
+ return;
13
+ const view = getEditorView();
14
+ const key = `characters.${cleanChar}`;
15
+ if (view) {
16
+ let tr = view.state.tr;
17
+ let titlePagePos = null;
18
+ view.state.doc.forEach((node, offset) => {
19
+ if (node.type.name === 'title_page')
20
+ titlePagePos = offset;
21
+ });
22
+ if (titlePagePos !== null) {
23
+ const tpNode = view.state.doc.nodeAt(titlePagePos);
24
+ let existingPos = null;
25
+ let pos = titlePagePos + 1; // inside title_page
26
+ tpNode.forEach((field) => {
27
+ if (field.attrs['fmKey'] === key) {
28
+ existingPos = pos;
29
+ }
30
+ pos += field.nodeSize;
31
+ });
32
+ if (existingPos !== null) {
33
+ const fieldNode = view.state.doc.nodeAt(existingPos);
34
+ if (actorName.trim() === '') {
35
+ tr = tr.delete(existingPos, existingPos + fieldNode.nodeSize);
36
+ }
37
+ else {
38
+ tr = tr.replaceWith(existingPos + 1, existingPos + fieldNode.nodeSize - 1, schema.text(actorName));
39
+ }
40
+ }
41
+ else if (actorName.trim() !== '') {
42
+ const insertPos = titlePagePos + tpNode.nodeSize - 1; // end of title_page
43
+ const newField = schema.nodes['frontmatter_field'].create({ fmKey: key }, schema.text(actorName));
44
+ tr = tr.insert(insertPos, newField);
45
+ }
46
+ view.dispatch(tr);
47
+ }
48
+ else {
49
+ const freshText = updateActorInText(text, cleanChar, actorName);
50
+ setText(freshText);
51
+ }
52
+ }
53
+ else {
54
+ const freshText = updateActorInText(text, cleanChar, actorName);
55
+ setText(freshText);
56
+ }
57
+ };
58
+ // Word count helper
59
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
60
+ // Sum up estimated duration. Each scene's est-duration is "MM:SS" — sum
61
+ // in seconds and only convert to minutes/hours once, at the end. Summing
62
+ // the MM parts alone (the previous approach) silently dropped every
63
+ // scene's seconds component, undercounting the total by tens of minutes
64
+ // on a script with many scenes.
65
+ let totalSeconds = 0;
66
+ scenes.forEach(s => {
67
+ const match = /^(\d+):(\d{1,2})$/.exec(s.estDuration.trim());
68
+ if (match && match[1] && match[2]) {
69
+ totalSeconds += Number.parseInt(match[1], 10) * 60 + Number.parseInt(match[2], 10);
70
+ }
71
+ });
72
+ const totalMinutes = Math.round(totalSeconds / 60);
73
+ const totalDurationLabel = totalSeconds === 0
74
+ ? 'TBD'
75
+ : totalMinutes >= 60
76
+ ? `${Math.floor(totalMinutes / 60)}h ${totalMinutes % 60}m`
77
+ : `${totalMinutes} min`;
78
+ return (_jsx("div", { className: "cs-dialog-overlay", role: "presentation", onClick: e => {
79
+ if (e.target === e.currentTarget)
80
+ onClose();
81
+ }, children: _jsxs("div", { className: "cs-dialog", role: "dialog", "aria-modal": "true", "aria-labelledby": "cs-stats-dialog-title", style: { maxWidth: '640px', width: '92%', maxHeight: '85vh', display: 'flex', flexDirection: 'column' }, children: [_jsxs("div", { className: "cs-panel-header", children: [_jsx("span", { id: "cs-stats-dialog-title", className: "cs-panel-title", children: "Script Statistics" }), _jsx("button", { className: "cs-panel-close", onClick: onClose, "aria-label": "Close", children: "\u00D7" })] }), _jsxs("div", { className: "cs-panel-body", style: { overflowY: 'auto', flex: 1, padding: '20px' }, children: [_jsxs("div", { className: "cs-stats-summary-grid", children: [_jsxs("div", { className: "cs-stats-card", children: [_jsx("div", { className: "cs-stats-card-val", children: scenes.length }), _jsx("div", { className: "cs-stats-card-lbl", children: "Scenes" })] }), _jsxs("div", { className: "cs-stats-card", children: [_jsx("div", { className: "cs-stats-card-val", children: wordCount.toLocaleString() }), _jsx("div", { className: "cs-stats-card-lbl", children: "Words" })] }), _jsxs("div", { className: "cs-stats-card", children: [_jsx("div", { className: "cs-stats-card-val", children: totalDurationLabel }), _jsx("div", { className: "cs-stats-card-lbl", children: "Est. Duration" })] })] }), _jsxs("div", { className: "cs-stats-section-hdr", children: ["Cast List & Occurrences (", characters.length, ")"] }), characters.length === 0 ? (_jsx("div", { style: { color: 'var(--cs-ui-text-light-muted, #8c897f)', fontStyle: 'italic', fontSize: '12px' }, children: "No character cues detected in the screenplay yet." })) : (_jsxs("table", { className: "cs-stats-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { style: { textAlign: 'left', width: '35%' }, children: "Character" }), _jsx("th", { style: { textAlign: 'left' }, children: "Actor" }), _jsx("th", { style: { textAlign: 'center', width: '15%' }, children: "Scenes" })] }) }), _jsx("tbody", { children: characters.map((c, i) => (_jsxs("tr", { children: [_jsx("td", { style: { fontWeight: '600' }, children: c.name }), _jsx("td", { children: _jsx("input", { type: "text", className: "cs-stats-actor-input", value: c.actor, onChange: (e) => handleUpdateActor(c.name, e.target.value), placeholder: "Assign actor...", "aria-label": `Actor for ${c.name}` }) }), _jsx("td", { style: { textAlign: 'center', fontWeight: '500' }, children: c.sceneCount })] }, i))) })] }))] }), _jsx("div", { style: {
82
+ borderTop: '1px solid var(--cs-ui-border-light-subtle, #eeece4)',
83
+ display: 'flex',
84
+ justifyContent: 'flex-end',
85
+ padding: '12px 20px',
86
+ background: 'var(--cs-ui-bg-panel-subtle, #f4f2ea)',
87
+ }, children: _jsx("button", { type: "button", className: "cs-confirm-btn-primary", onClick: onClose, children: "Close" }) })] }) }));
88
+ }
89
+ function updateActorInText(text, charName, actorName) {
90
+ const lines = text.split('\n');
91
+ const fmStartIndex = lines.indexOf('---');
92
+ if (fmStartIndex === -1) {
93
+ return `---\ncharacters:\n ${charName}: ${actorName}\n---\n\n${text}`;
94
+ }
95
+ const fmEndIndex = lines.indexOf('---', fmStartIndex + 1);
96
+ if (fmEndIndex === -1)
97
+ return text;
98
+ const fmLines = lines.slice(fmStartIndex + 1, fmEndIndex);
99
+ let charsLineIdx = -1;
100
+ for (let i = 0; i < fmLines.length; i++) {
101
+ if (fmLines[i].trim() === 'characters:') {
102
+ charsLineIdx = i;
103
+ break;
104
+ }
105
+ }
106
+ const cleanChar = charName.toUpperCase();
107
+ if (charsLineIdx === -1) {
108
+ if (actorName.trim() !== '') {
109
+ fmLines.push('characters:');
110
+ fmLines.push(` ${cleanChar}: ${actorName}`);
111
+ }
112
+ }
113
+ else {
114
+ let insertIdx = charsLineIdx + 1;
115
+ let charLineIdx = -1;
116
+ while (insertIdx < fmLines.length) {
117
+ const line = fmLines[insertIdx];
118
+ if (!line.startsWith(' ') && line.trim() !== '') {
119
+ break;
120
+ }
121
+ const match = /^\s+([A-Za-z0-9_ -]+)\s*:(.*)/.exec(line);
122
+ if (match && match[1]?.trim().toUpperCase() === cleanChar) {
123
+ charLineIdx = insertIdx;
124
+ break;
125
+ }
126
+ insertIdx++;
127
+ }
128
+ if (charLineIdx !== -1) {
129
+ if (actorName.trim() === '') {
130
+ fmLines.splice(charLineIdx, 1);
131
+ }
132
+ else {
133
+ fmLines[charLineIdx] = ` ${cleanChar}: ${actorName}`;
134
+ }
135
+ }
136
+ else if (actorName.trim() !== '') {
137
+ fmLines.splice(insertIdx, 0, ` ${cleanChar}: ${actorName}`);
138
+ }
139
+ }
140
+ const newLines = [
141
+ ...lines.slice(0, fmStartIndex + 1),
142
+ ...fmLines,
143
+ ...lines.slice(fmEndIndex)
144
+ ];
145
+ return newLines.join('\n');
146
+ }
@@ -0,0 +1,16 @@
1
+ export interface SceneEntry {
2
+ id: string | null;
3
+ heading: string;
4
+ synopsis: string;
5
+ status: string;
6
+ tags: string[];
7
+ location: string;
8
+ index: number;
9
+ textOffset: number;
10
+ estDuration?: string;
11
+ }
12
+ /**
13
+ * Derive a flat scene list from Sutra source text.
14
+ * Scenes are identified by scene heading lines (## prefix).
15
+ */
16
+ export declare function buildSceneList(text: string): SceneEntry[];
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Derive a flat scene list from Sutra source text.
3
+ * Scenes are identified by scene heading lines (## prefix).
4
+ */
5
+ export function buildSceneList(text) {
6
+ const lines = text.split('\n');
7
+ const scenes = [];
8
+ let sceneIndex = 0;
9
+ let currentOffset = 0;
10
+ for (let i = 0; i < lines.length; i++) {
11
+ const line = lines[i] ?? '';
12
+ const trimmed = line.trim();
13
+ // Scene headings start with ## (Sutra sigil)
14
+ if (trimmed.startsWith('## ') || trimmed.startsWith('##\t')) {
15
+ const headingRaw = trimmed.slice(3).trim();
16
+ const sceneStart = currentOffset;
17
+ // Extract scene id from inline {#...} on the heading line, then strip it
18
+ const idMatch = /\{#([^}]+)\}/.exec(headingRaw);
19
+ const sceneId = idMatch?.[1] ?? null;
20
+ const heading = headingRaw.replace(/\s*\{#[^}]+\}/, '').trim();
21
+ // Collect metadata (& key: value) until next heading
22
+ let synopsis = '';
23
+ let status = '';
24
+ let tags = [];
25
+ let location = '';
26
+ let estDuration = '';
27
+ let j = i + 1;
28
+ while (j < lines.length) {
29
+ const nextLine = (lines[j] ?? '').trim();
30
+ if (nextLine.startsWith('## ') || nextLine.startsWith('##\t'))
31
+ break;
32
+ if (nextLine.startsWith('& synopsis:')) {
33
+ if (!synopsis)
34
+ synopsis = nextLine.replace('& synopsis:', '').trim();
35
+ }
36
+ else if (nextLine.startsWith('& status:')) {
37
+ status = nextLine.replace('& status:', '').trim();
38
+ }
39
+ else if (nextLine.startsWith('& tags:')) {
40
+ tags = nextLine
41
+ .replace('& tags:', '')
42
+ .trim()
43
+ .split(',')
44
+ .map((t) => t.trim())
45
+ .filter(Boolean);
46
+ }
47
+ else if (nextLine.startsWith('& location:')) {
48
+ location = nextLine.replace('& location:', '').trim();
49
+ }
50
+ else if (nextLine.startsWith('& est-duration:')) {
51
+ estDuration = nextLine.replace('& est-duration:', '').trim();
52
+ }
53
+ j++;
54
+ }
55
+ scenes.push({
56
+ id: sceneId,
57
+ heading,
58
+ synopsis,
59
+ status,
60
+ tags,
61
+ location,
62
+ estDuration: estDuration || undefined,
63
+ index: ++sceneIndex,
64
+ textOffset: sceneStart,
65
+ });
66
+ }
67
+ currentOffset += (line?.length ?? 0) + 1; // +1 for \n
68
+ }
69
+ return scenes;
70
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ onClose: () => void;
4
+ }
5
+ export declare function SettingsDialog({ onClose }: Props): React.JSX.Element;
6
+ export {};
@@ -0,0 +1,147 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { useTranslation } from '../i18n/useTranslation';
4
+ import { useDocument } from '../context/DocumentContext';
5
+ import { getAIConfig, saveAIConfig, fetchProviders, getApiKey, setApiKey, deleteApiKey, testConnection, listModels, } from '../ai/ai-client';
6
+ const UI_LANGUAGES = [
7
+ { code: 'en', label: 'English' },
8
+ { code: 'hi', label: 'हिन्दी' },
9
+ { code: 'ta', label: 'தமிழ்' },
10
+ { code: 'te', label: 'తెలుగు' },
11
+ { code: 'ml', label: 'മലയാളം' },
12
+ { code: 'kn', label: 'ಕನ್ನಡ' },
13
+ { code: 'bn', label: 'বাংলা' },
14
+ { code: 'gu', label: 'ગુજરાતી' },
15
+ { code: 'mr', label: 'मराठी' },
16
+ { code: 'pa', label: 'ਪੰਜਾਬੀ' },
17
+ { code: 'or', label: 'ଓଡ଼ିଆ' },
18
+ { code: 'si', label: 'සිංහල' },
19
+ ];
20
+ export function SettingsDialog({ onClose }) {
21
+ const { t, locale, setLocale } = useTranslation();
22
+ const { setAIOnboardingVisible } = useDocument();
23
+ const dialogRef = useRef(null);
24
+ // AI states
25
+ const [aiConfig, setAiConfig] = useState(getAIConfig());
26
+ const [providers, setProviders] = useState([]);
27
+ const [activeKey, setActiveKey] = useState('');
28
+ const [showKey, setShowKey] = useState(false);
29
+ const [testStatus, setTestStatus] = useState('idle');
30
+ const [testError, setTestError] = useState('');
31
+ const [dynamicModels, setDynamicModels] = useState(null);
32
+ const [modelsLoading, setModelsLoading] = useState(false);
33
+ useEffect(() => {
34
+ dialogRef.current?.focus();
35
+ void loadProviders();
36
+ }, []);
37
+ const loadProviders = async () => {
38
+ const p = await fetchProviders(aiConfig);
39
+ setProviders(p);
40
+ };
41
+ // Loads the stored key for the selected provider, then refreshes its
42
+ // model list from the provider's live /models endpoint (falls back to the
43
+ // static list on any error — see listModels). Depends on `providers` too
44
+ // so it re-runs once fetchProviders() resolves on mount, instead of
45
+ // racing it.
46
+ useEffect(() => {
47
+ let cancelled = false;
48
+ const run = async () => {
49
+ setTestStatus('idle');
50
+ setTestError('');
51
+ const key = await getApiKey(aiConfig.preferredProvider);
52
+ if (cancelled)
53
+ return;
54
+ setActiveKey(key || '');
55
+ setDynamicModels(null);
56
+ const provider = providers.find(p => p.id === aiConfig.preferredProvider);
57
+ if (key && provider) {
58
+ setModelsLoading(true);
59
+ const models = await listModels(provider, key);
60
+ if (!cancelled) {
61
+ setDynamicModels(models);
62
+ setModelsLoading(false);
63
+ }
64
+ }
65
+ };
66
+ void run();
67
+ return () => { cancelled = true; };
68
+ }, [aiConfig.preferredProvider, providers]);
69
+ const handleKeyDown = (e) => {
70
+ if (e.key === 'Escape')
71
+ onClose();
72
+ };
73
+ const handleProviderChange = (e) => {
74
+ const nextProvider = e.target.value;
75
+ const provider = providers.find(p => p.id === nextProvider);
76
+ const nextModel = provider?.models[0]?.id || '';
77
+ const updated = {
78
+ ...aiConfig,
79
+ preferredProvider: nextProvider,
80
+ preferredModel: nextModel,
81
+ };
82
+ setAiConfig(updated);
83
+ saveAIConfig(updated);
84
+ };
85
+ const handleModelChange = (e) => {
86
+ const updated = {
87
+ ...aiConfig,
88
+ preferredModel: e.target.value,
89
+ };
90
+ setAiConfig(updated);
91
+ saveAIConfig(updated);
92
+ };
93
+ const handleKeyChange = async (e) => {
94
+ const val = e.target.value;
95
+ setActiveKey(val);
96
+ if (val.trim()) {
97
+ await setApiKey(aiConfig.preferredProvider, val.trim());
98
+ }
99
+ else {
100
+ await deleteApiKey(aiConfig.preferredProvider);
101
+ }
102
+ setTestStatus('idle');
103
+ };
104
+ const handleTestKey = async () => {
105
+ if (!activeKey.trim()) {
106
+ setTestStatus('error');
107
+ setTestError('Please enter an API key to test.');
108
+ return;
109
+ }
110
+ setTestStatus('testing');
111
+ setTestError('');
112
+ try {
113
+ const ok = await testConnection(aiConfig.preferredProvider, activeKey.trim(), aiConfig);
114
+ if (ok) {
115
+ setTestStatus('success');
116
+ const provider = providers.find(p => p.id === aiConfig.preferredProvider);
117
+ if (provider) {
118
+ setModelsLoading(true);
119
+ setDynamicModels(await listModels(provider, activeKey.trim()));
120
+ setModelsLoading(false);
121
+ }
122
+ }
123
+ else {
124
+ setTestStatus('error');
125
+ setTestError('Connection failed: empty or invalid response.');
126
+ }
127
+ }
128
+ catch (err) {
129
+ setTestStatus('error');
130
+ setTestError(err.message || String(err));
131
+ }
132
+ };
133
+ const currentProvider = providers.find(p => p.id === aiConfig.preferredProvider);
134
+ const models = dynamicModels ?? currentProvider?.models ?? [];
135
+ return (_jsx("div", { className: "cs-dialog-overlay", onClick: onClose, children: _jsxs("div", { ref: dialogRef, className: "cs-dialog cs-settings-dialog", role: "dialog", "aria-modal": "true", "aria-label": t('settings.title'), tabIndex: -1, onClick: e => e.stopPropagation(), onKeyDown: handleKeyDown, style: { maxWidth: '480px' }, children: [_jsxs("div", { className: "cs-dialog-header", children: [_jsx("span", { className: "cs-dialog-title", children: t('settings.title') }), _jsx("button", { className: "cs-fr-close", "aria-label": t('settings.close'), onClick: onClose, children: "\u00D7" })] }), _jsxs("div", { className: "cs-settings-body", style: { maxHeight: '80vh', overflowY: 'auto' }, children: [_jsx("div", { className: "cs-settings-section-label", children: t('settings.general') }), _jsxs("div", { className: "cs-settings-row", children: [_jsx("label", { className: "cs-settings-label", htmlFor: "cs-ui-lang-select", children: t('settings.uiLanguage') }), _jsx("select", { id: "cs-ui-lang-select", className: "cs-settings-select", value: locale, onChange: e => setLocale(e.target.value), children: UI_LANGUAGES.map(lang => (_jsx("option", { value: lang.code, children: lang.label }, lang.code))) })] }), _jsx("div", { style: { margin: '14px 0 6px 0', borderTop: '1px solid var(--cs-ui-border-light, #e8e8e4)', paddingTop: '14px' }, className: "cs-settings-section-label", children: "Intelligence & Voice Settings" }), _jsxs("div", { className: "cs-settings-row", children: [_jsx("label", { className: "cs-settings-label", htmlFor: "cs-ai-provider-select", children: "Preferred Provider" }), _jsx("select", { id: "cs-ai-provider-select", className: "cs-settings-select", value: aiConfig.preferredProvider, onChange: handleProviderChange, children: providers.map(p => (_jsx("option", { value: p.id, children: p.name }, p.id))) })] }), _jsxs("div", { className: "cs-settings-row", children: [_jsxs("label", { className: "cs-settings-label", htmlFor: "cs-ai-model-select", children: ["Preferred Model", modelsLoading ? ' (refreshing...)' : ''] }), _jsx("select", { id: "cs-ai-model-select", className: "cs-settings-select", value: aiConfig.preferredModel, onChange: handleModelChange, disabled: models.length === 0, children: models.map(m => (_jsx("option", { value: m.id, children: m.name }, m.id))) })] }), _jsxs("div", { className: "cs-settings-row", style: { flexDirection: 'column', alignItems: 'stretch', gap: '6px' }, children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', width: '100%' }, children: [_jsxs("label", { className: "cs-settings-label", htmlFor: "cs-ai-key-input", children: ["API Key for ", currentProvider?.name || aiConfig.preferredProvider] }), _jsx("button", { type: "button", style: { background: 'none', border: 'none', color: 'var(--cs-ui-accent, #c4760a)', cursor: 'pointer', fontSize: '11px', padding: 0 }, onClick: () => setShowKey(!showKey), children: showKey ? 'Hide' : 'Show' })] }), _jsx("input", { id: "cs-ai-key-input", type: showKey ? 'text' : 'password', style: {
136
+ width: '100%',
137
+ padding: '7px 10px',
138
+ border: '1px solid var(--cs-ui-border-light, #ccc)',
139
+ borderRadius: '4px',
140
+ boxSizing: 'border-box',
141
+ fontFamily: 'monospace',
142
+ fontSize: '12px',
143
+ }, value: activeKey, onChange: handleKeyChange, placeholder: `Enter API Key for ${aiConfig.preferredProvider}` }), _jsx("div", { style: { display: 'flex', gap: '8px', marginTop: '4px' }, children: _jsx("button", { type: "button", className: "cs-voice-btn-secondary", style: { padding: '4px 10px', fontSize: '12px' }, onClick: handleTestKey, disabled: testStatus === 'testing', children: testStatus === 'testing' ? 'Testing...' : 'Test Connection' }) }), testStatus === 'success' && (_jsx("span", { style: { color: '#10b981', fontSize: '12px', marginTop: '2px' }, children: "\u2713 Key verified! Connection succeeded." })), testStatus === 'error' && (_jsxs("span", { style: { color: '#ef4444', fontSize: '12px', marginTop: '2px', whiteSpace: 'pre-wrap' }, children: ["\u2717 Error: ", testError] }))] }), _jsx("div", { style: { marginTop: '16px', display: 'flex', justifyContent: 'flex-start' }, children: _jsx("button", { type: "button", className: "cs-voice-btn-primary", style: { padding: '6px 12px', fontSize: '12px' }, onClick: () => {
144
+ onClose();
145
+ setAIOnboardingVisible(true);
146
+ }, children: "Open Setup Wizard" }) })] })] }) }));
147
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function AppBar(): React.JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useDocument } from '../context/DocumentContext';
4
+ import { useTranslation } from '../i18n/useTranslation';
5
+ import { NavigatorIcon, TitlePageIcon, NewIcon, OpenIcon, SaveIcon, SaveAsIcon, SourceIcon, FormattedIcon, RibbonIcon, ExportIcon, SettingsIcon, ImportDocxIcon, StyleIcon, MicIcon, MenuIcon, CloseIcon, } from './icons';
6
+ import { SutrataLogo } from './SutrataLogo';
7
+ import { getTemplate } from '../templates/templates';
8
+ import { openTitlePageForm } from '../titlepage/TitlePageDialog';
9
+ function AbBtn({ label, shortcut, active, variant, onClick, children }) {
10
+ const variantClass = variant === 'primary' ? ' cs-ab-btn-primary' : variant === 'secondary' ? ' cs-ab-btn-secondary' : '';
11
+ return (_jsxs("button", { type: "button", "aria-label": label, className: `cs-ab-btn${active ? ' cs-ab-active' : ''}${variantClass}`, onClick: onClick, children: [children, _jsxs("span", { className: "cs-tb-tip", role: "tooltip", children: [_jsx("span", { children: label }), shortcut ? _jsx("span", { className: "cs-tb-key", children: shortcut }) : null] })] }));
12
+ }
13
+ export function AppBar() {
14
+ const { mode, setMode, isDirty, filePath, ribbonVisible, setRibbonVisible, navVisible, setNavVisible, exportVisible, setExportVisible, settingsVisible, setSettingsVisible, metadataVisible, setMetadataVisible, voiceActive, setVoiceActive, newDocument, openFile, saveFile, saveFileAs, setText, importDocx, styleVisible, setStyleVisible, showConfirm, showToast, } = useDocument();
15
+ const { t, locale } = useTranslation();
16
+ const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
17
+ const name = filePath ?? 'untitled.sutra';
18
+ const nextMode = mode === 'formatted' ? 'source' : 'formatted';
19
+ const handleNew = () => {
20
+ newDocument(getTemplate(locale));
21
+ };
22
+ const handleImportDocx = async () => {
23
+ try {
24
+ const warnings = await importDocx();
25
+ if (warnings && warnings.length) {
26
+ showToast(warnings.join(' • '), 'warn');
27
+ }
28
+ }
29
+ catch (err) {
30
+ showToast(err instanceof Error ? err.message : 'Failed to import the Word document.', 'error');
31
+ }
32
+ };
33
+ return (_jsxs("header", { className: "cs-app-bar", role: "banner", "aria-label": "Application header", children: [_jsxs("div", { className: "cs-ab-group cs-ab-left", children: [_jsxs("div", { className: "cs-ab-brand", title: "Sutrata Multilingual Screenplay Editor", children: [_jsx(SutrataLogo, { size: 20, showText: false }), _jsx("span", { className: "cs-ab-brand-title", children: "Sutrata" })] }), _jsx("span", { className: "cs-ab-sep cs-ab-desktop-only" }), _jsx(AbBtn, { label: t('appbar.navigator'), shortcut: "Ctrl+Shift+B", active: navVisible, onClick: () => setNavVisible(!navVisible), children: _jsx(NavigatorIcon, { size: 18 }) }), _jsx("span", { className: "cs-ab-desktop-only", children: _jsx(AbBtn, { label: t('appbar.titlePage'), onClick: openTitlePageForm, children: _jsx(TitlePageIcon, { size: 18 }) }) }), _jsxs("div", { className: "cs-ab-file-pill", title: filePath ?? 'untitled.sutra', children: [_jsx("span", { className: "cs-ab-file-name", children: name }), isDirty && _jsx("span", { className: "cs-ab-dirty", title: "Unsaved edits" })] })] }), _jsx("span", { className: "cs-ab-spacer cs-ab-desktop-only" }), _jsxs("div", { className: "cs-ab-group cs-ab-desktop-group", children: [_jsx(AbBtn, { label: mode === 'formatted' ? t('appbar.switchToSource') : t('appbar.switchToFormatted'), shortcut: "Ctrl+Shift+E", onClick: () => setMode(nextMode), children: mode === 'formatted' ? _jsx(SourceIcon, { size: 18 }) : _jsx(FormattedIcon, { size: 18 }) }), _jsx(AbBtn, { label: ribbonVisible ? t('appbar.hideToolbar') : t('appbar.showToolbar'), shortcut: "Ctrl+Shift+H", active: ribbonVisible, onClick: () => setRibbonVisible(!ribbonVisible), children: _jsx(RibbonIcon, { size: 18 }) }), _jsx(AbBtn, { label: "Voice Dictation", shortcut: "Ctrl+Shift+V", active: voiceActive, onClick: () => setVoiceActive(!voiceActive), children: _jsx(MicIcon, { size: 18 }) }), _jsx(AbBtn, { label: metadataVisible ? 'Hide Metadata' : 'Show Metadata', active: metadataVisible, onClick: () => setMetadataVisible(!metadataVisible), children: _jsx("span", { style: { fontWeight: 700, fontSize: '13px' }, children: "&" }) })] }), _jsx("span", { className: "cs-ab-spacer cs-ab-desktop-only" }), _jsxs("div", { className: "cs-ab-group cs-ab-desktop-group", children: [_jsx(AbBtn, { label: t('appbar.new'), onClick: handleNew, children: _jsx(NewIcon, { size: 18 }) }), _jsx(AbBtn, { label: t('appbar.open'), shortcut: "Ctrl+O", onClick: () => { void openFile(); }, children: _jsx(OpenIcon, { size: 18 }) }), _jsx(AbBtn, { label: t('appbar.importDocx'), onClick: () => { void handleImportDocx(); }, children: _jsx(ImportDocxIcon, { size: 18 }) }), _jsx("span", { className: "cs-ab-sep" }), _jsx(AbBtn, { label: t('appbar.save'), shortcut: "Ctrl+S", variant: "primary", onClick: () => { void saveFile(); }, children: _jsx(SaveIcon, { size: 17 }) }), _jsx(AbBtn, { label: t('appbar.saveAs'), shortcut: "Ctrl+Shift+S", onClick: () => { void saveFileAs(); }, children: _jsx(SaveAsIcon, { size: 17 }) }), _jsx("span", { className: "cs-ab-sep" }), _jsx(AbBtn, { label: t('appbar.export'), variant: "secondary", active: exportVisible, onClick: () => setExportVisible(!exportVisible), children: _jsx(ExportIcon, { size: 18 }) }), _jsx(AbBtn, { label: t('appbar.style'), active: styleVisible, onClick: () => setStyleVisible(!styleVisible), children: _jsx(StyleIcon, { size: 18 }) }), _jsx(AbBtn, { label: t('settings.title'), active: settingsVisible, onClick: () => setSettingsVisible(!settingsVisible), children: _jsx(SettingsIcon, { size: 18 }) })] }), _jsxs("div", { className: "cs-ab-group cs-ab-mobile-controls", children: [_jsx(AbBtn, { label: t('appbar.save'), variant: isDirty ? 'primary' : undefined, onClick: () => { void saveFile(); }, children: _jsx(SaveIcon, { size: 17 }) }), _jsx(AbBtn, { label: "Menu", active: mobileMenuOpen, onClick: () => setMobileMenuOpen(!mobileMenuOpen), children: mobileMenuOpen ? _jsx(CloseIcon, { size: 18 }) : _jsx(MenuIcon, { size: 18 }) })] }), mobileMenuOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "cs-mobile-menu-backdrop", "aria-hidden": "true", onClick: () => setMobileMenuOpen(false) }), _jsxs("div", { className: "cs-mobile-menu-drawer", role: "dialog", "aria-modal": "true", "aria-label": "Application Menu", children: [_jsxs("div", { className: "cs-mm-header", children: [_jsxs("div", { className: "cs-mm-brand", children: [_jsx(SutrataLogo, { size: 22, showText: false }), _jsx("span", { children: "Sutrata" })] }), _jsx("button", { type: "button", className: "cs-mm-close", "aria-label": "Close menu", onClick: () => setMobileMenuOpen(false), children: _jsx(CloseIcon, { size: 18 }) })] }), _jsxs("div", { className: "cs-mm-file-info", children: [_jsx("span", { className: "cs-mm-file-name", children: name }), isDirty && _jsx("span", { className: "cs-ab-dirty", title: "Unsaved edits" })] }), _jsxs("div", { className: "cs-mm-section", children: [_jsx("div", { className: "cs-mm-section-title", children: "Views & Tools" }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { setMode(nextMode); setMobileMenuOpen(false); }, children: [mode === 'formatted' ? _jsx(SourceIcon, { size: 18 }) : _jsx(FormattedIcon, { size: 18 }), _jsx("span", { children: mode === 'formatted' ? t('appbar.switchToSource') : t('appbar.switchToFormatted') })] }), _jsxs("button", { type: "button", className: `cs-mm-item${navVisible ? ' cs-mm-active' : ''}`, onClick: () => { setNavVisible(!navVisible); setMobileMenuOpen(false); }, children: [_jsx(NavigatorIcon, { size: 18 }), _jsx("span", { children: t('appbar.navigator') })] }), _jsxs("button", { type: "button", className: `cs-mm-item${ribbonVisible ? ' cs-mm-active' : ''}`, onClick: () => { setRibbonVisible(!ribbonVisible); setMobileMenuOpen(false); }, children: [_jsx(RibbonIcon, { size: 18 }), _jsx("span", { children: ribbonVisible ? t('appbar.hideToolbar') : t('appbar.showToolbar') })] }), _jsxs("button", { type: "button", className: `cs-mm-item${voiceActive ? ' cs-mm-active' : ''}`, onClick: () => { setVoiceActive(!voiceActive); setMobileMenuOpen(false); }, children: [_jsx(MicIcon, { size: 18 }), _jsx("span", { children: "Voice Dictation" })] }), _jsxs("button", { type: "button", className: `cs-mm-item${metadataVisible ? ' cs-mm-active' : ''}`, onClick: () => { setMetadataVisible(!metadataVisible); setMobileMenuOpen(false); }, children: [_jsx("span", { style: { fontWeight: 700, width: 18, textAlign: 'center' }, children: "&" }), _jsx("span", { children: metadataVisible ? 'Hide Metadata' : 'Show Metadata' })] })] }), _jsxs("div", { className: "cs-mm-section", children: [_jsx("div", { className: "cs-mm-section-title", children: "File Operations" }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { openTitlePageForm(); setMobileMenuOpen(false); }, children: [_jsx(TitlePageIcon, { size: 18 }), _jsx("span", { children: t('appbar.titlePage') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { handleNew(); setMobileMenuOpen(false); }, children: [_jsx(NewIcon, { size: 18 }), _jsx("span", { children: t('appbar.new') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { void openFile(); setMobileMenuOpen(false); }, children: [_jsx(OpenIcon, { size: 18 }), _jsx("span", { children: t('appbar.open') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { void handleImportDocx(); setMobileMenuOpen(false); }, children: [_jsx(ImportDocxIcon, { size: 18 }), _jsx("span", { children: t('appbar.importDocx') })] }), _jsxs("button", { type: "button", className: "cs-mm-item cs-mm-primary", onClick: () => { void saveFile(); setMobileMenuOpen(false); }, children: [_jsx(SaveIcon, { size: 18 }), _jsx("span", { children: t('appbar.save') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { void saveFileAs(); setMobileMenuOpen(false); }, children: [_jsx(SaveAsIcon, { size: 18 }), _jsx("span", { children: t('appbar.saveAs') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { setExportVisible(true); setMobileMenuOpen(false); }, children: [_jsx(ExportIcon, { size: 18 }), _jsx("span", { children: t('appbar.export') })] })] }), _jsxs("div", { className: "cs-mm-section", children: [_jsx("div", { className: "cs-mm-section-title", children: "Preferences" }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { setStyleVisible(true); setMobileMenuOpen(false); }, children: [_jsx(StyleIcon, { size: 18 }), _jsx("span", { children: t('appbar.style') })] }), _jsxs("button", { type: "button", className: "cs-mm-item", onClick: () => { setSettingsVisible(true); setMobileMenuOpen(false); }, children: [_jsx(SettingsIcon, { size: 18 }), _jsx("span", { children: t('settings.title') })] })] })] })] }))] }));
34
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function AppShell(): React.JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { AppBar } from './AppBar';
4
+ import { ElementToolbar } from './ElementToolbar';
5
+ import { StatusBar } from './StatusBar';
6
+ import { EditorView } from '../editor/EditorView';
7
+ import { SourceView } from '../source/SourceView';
8
+ import { useDocument } from '../context/DocumentContext';
9
+ import { SceneNavigator } from '../navigator/SceneNavigator';
10
+ import { FindReplace } from '../findreplace/FindReplace';
11
+ import { ExportDialog } from '../titlepage/ExportDialog';
12
+ import { TitlePageDialog, OPEN_TITLE_PAGE_EVENT } from '../titlepage/TitlePageDialog';
13
+ import { SettingsDialog } from '../settings/SettingsDialog';
14
+ import { StyleDialog } from '../styles/StyleDialog';
15
+ import { Watermark } from './Watermark';
16
+ import { ConfirmDialog } from './ConfirmDialog';
17
+ import { ToastContainer } from './Toast';
18
+ import { VoiceToolbar } from '../ai/VoiceToolbar';
19
+ import { OnboardingDialog } from '../ai/OnboardingDialog';
20
+ import { SelectionMenu } from '../editor/SelectionMenu';
21
+ export function AppShell() {
22
+ const { mode, ribbonVisible, navVisible, setNavVisible, exportVisible, settingsVisible, setSettingsVisible, styleVisible, setStyleVisible, metadataVisible, voiceActive, aiOnboardingVisible, setAIOnboardingVisible, confirmModal, closeConfirm, toasts, dismissToast, } = useDocument();
23
+ const [titlePageVisible, setTitlePageVisible] = useState(false);
24
+ useEffect(() => {
25
+ const open = () => setTitlePageVisible(true);
26
+ window.addEventListener(OPEN_TITLE_PAGE_EVENT, open);
27
+ return () => window.removeEventListener(OPEN_TITLE_PAGE_EVENT, open);
28
+ }, []);
29
+ return (_jsxs("div", { className: `cs-shell ${metadataVisible ? '' : 'cs-hide-metadata'}`, children: [_jsx(Watermark, {}), _jsx(AppBar, {}), voiceActive && _jsx(VoiceToolbar, {}), ribbonVisible && _jsx(ElementToolbar, {}), _jsxs("div", { className: "cs-shell-body", children: [navVisible && (_jsxs(_Fragment, { children: [_jsx("div", { className: "cs-nav-backdrop", "aria-hidden": "true", onClick: () => setNavVisible(false) }), _jsx(SceneNavigator, {})] })), _jsx("div", { className: "cs-editor-area", children: _jsx("main", { className: "cs-main", children: mode === 'formatted' ? _jsx(EditorView, {}) : _jsx(SourceView, {}) }) })] }), _jsx(StatusBar, {}), _jsx(FindReplace, {}), exportVisible && _jsx(ExportDialog, {}), titlePageVisible && _jsx(TitlePageDialog, { onClose: () => setTitlePageVisible(false) }), settingsVisible && _jsx(SettingsDialog, { onClose: () => setSettingsVisible(false) }), styleVisible && _jsx(StyleDialog, { onClose: () => setStyleVisible(false) }), aiOnboardingVisible && _jsx(OnboardingDialog, { onClose: () => setAIOnboardingVisible(false) }), confirmModal && _jsx(ConfirmDialog, { options: confirmModal, onClose: closeConfirm }), _jsx(ToastContainer, { toasts: toasts, onDismiss: dismissToast }), _jsx(SelectionMenu, {})] }));
30
+ }
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ export interface ConfirmOptions {
3
+ title: string;
4
+ message: string;
5
+ confirmLabel?: string;
6
+ cancelLabel?: string;
7
+ destructive?: boolean;
8
+ onConfirm: () => void;
9
+ onCancel?: () => void;
10
+ }
11
+ interface ConfirmDialogProps {
12
+ options: ConfirmOptions;
13
+ onClose: () => void;
14
+ }
15
+ export declare function ConfirmDialog({ options, onClose }: ConfirmDialogProps): React.JSX.Element;
16
+ export {};
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ export function ConfirmDialog({ options, onClose }) {
4
+ const confirmBtnRef = useRef(null);
5
+ useEffect(() => {
6
+ confirmBtnRef.current?.focus();
7
+ const onKey = (e) => {
8
+ if (e.key === 'Escape') {
9
+ options.onCancel?.();
10
+ onClose();
11
+ }
12
+ };
13
+ window.addEventListener('keydown', onKey);
14
+ return () => window.removeEventListener('keydown', onKey);
15
+ }, [options, onClose]);
16
+ return (_jsx("div", { className: "cs-confirm-overlay", role: "presentation", onClick: () => { options.onCancel?.(); onClose(); }, children: _jsxs("div", { className: "cs-confirm-dialog", role: "alertdialog", "aria-modal": "true", "aria-labelledby": "cs-confirm-title", "aria-describedby": "cs-confirm-desc", onClick: (e) => e.stopPropagation(), children: [_jsx("div", { id: "cs-confirm-title", className: "cs-confirm-title", children: options.title }), _jsx("div", { id: "cs-confirm-desc", className: "cs-confirm-msg", children: options.message }), _jsxs("div", { className: "cs-confirm-actions", children: [_jsx("button", { type: "button", className: "cs-confirm-btn-cancel", onClick: () => {
17
+ options.onCancel?.();
18
+ onClose();
19
+ }, children: options.cancelLabel ?? 'Cancel' }), _jsx("button", { ref: confirmBtnRef, type: "button", className: options.destructive ? 'cs-confirm-btn-danger' : 'cs-confirm-btn-primary', onClick: () => {
20
+ options.onConfirm();
21
+ onClose();
22
+ }, children: options.confirmLabel ?? 'Confirm' })] })] }) }));
23
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function ElementToolbar(): React.JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { ToolbarButton } from './ToolbarButton';
4
+ import { makeSetBlock, makeSetOrToggleNote, makeToggleMark, undo, redo } from './toolbar-actions';
5
+ import { runCommand, activeBlockType, subscribe } from '../editor/editor-bus';
6
+ import { useTranslation } from '../i18n/useTranslation';
7
+ import { UndoIcon, RedoIcon, SceneIcon, ActionIcon, CharacterIcon, DialogueIcon, ParentheticalIcon, TransitionIcon, CenteredIcon, LyricsIcon, NoteIcon, PageBreakIcon, SectionIcon, BoldIcon, ItalicIcon, UnderlineIcon, OverflowIcon, CloseIcon, } from './icons';
8
+ const ELEMENTS = [
9
+ { type: 'scene_heading', label: 'Scene Heading', sigil: '##', shortcut: 'Alt+Shift+H', Icon: SceneIcon, translationKey: 'toolbar.scene' },
10
+ { type: 'action', label: 'Action', sigil: '(plain)', shortcut: 'Alt+Shift+A', Icon: ActionIcon, translationKey: 'toolbar.action' },
11
+ { type: 'character', label: 'Character', sigil: '@', shortcut: 'Alt+Shift+C', Icon: CharacterIcon, translationKey: 'toolbar.character' },
12
+ { type: 'dialogue', label: 'Dialogue', sigil: '(after @)', shortcut: 'Alt+Shift+D', Icon: DialogueIcon, translationKey: 'toolbar.dialogue' },
13
+ { type: 'parenthetical', label: 'Parenthetical', sigil: '( )', shortcut: 'Alt+Shift+P', Icon: ParentheticalIcon, translationKey: 'toolbar.parenthetical' },
14
+ { type: 'transition', label: 'Transition', sigil: '>>', shortcut: 'Alt+Shift+X', Icon: TransitionIcon, translationKey: 'toolbar.transition' },
15
+ { type: 'centered', label: 'Centered', sigil: '>> <<', shortcut: '', Icon: CenteredIcon, translationKey: 'toolbar.centered' },
16
+ { type: 'lyrics', label: 'Lyrics', sigil: '~', shortcut: 'Alt+Shift+L', Icon: LyricsIcon, translationKey: 'toolbar.lyrics' },
17
+ { type: 'note', label: 'Note', sigil: '[[ ]]', shortcut: 'Alt+Shift+N', Icon: NoteIcon, translationKey: 'toolbar.note' },
18
+ { type: 'page_break', label: 'Page Break', sigil: '===', shortcut: '', Icon: PageBreakIcon, translationKey: 'toolbar.pageBreak' },
19
+ { type: 'section', label: 'Section', sigil: '#', shortcut: '', Icon: SectionIcon, translationKey: 'toolbar.section' },
20
+ ];
21
+ export function ElementToolbar() {
22
+ const [activeType, setActiveType] = useState(null);
23
+ const [overflowOpen, setOverflowOpen] = useState(false);
24
+ const { t } = useTranslation();
25
+ useEffect(() => subscribe(() => setActiveType(activeBlockType())), []);
26
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "cs-element-toolbar", role: "toolbar", "aria-label": "Editing toolbar", children: [_jsx(ToolbarButton, { label: t('toolbar.undo'), shortcut: "Mod-Z", onClick: () => runCommand(undo), children: _jsx(UndoIcon, { size: 20 }) }), _jsx(ToolbarButton, { label: t('toolbar.redo'), shortcut: "Mod-Shift-Z", onClick: () => runCommand(redo), children: _jsx(RedoIcon, { size: 20 }) }), _jsx("span", { className: "cs-tb-sep" }), ELEMENTS.map(el => (_jsx(ToolbarButton, { label: t(el.translationKey), sigil: el.sigil, shortcut: el.shortcut || undefined, active: activeType === el.type, onClick: () => runCommand(el.type === 'note' ? makeSetOrToggleNote() : makeSetBlock(el.type)), children: _jsx(el.Icon, { size: 20 }) }, el.type))), _jsx("span", { className: "cs-tb-sep" }), _jsx(ToolbarButton, { label: t('toolbar.bold'), shortcut: "Mod-B", onClick: () => runCommand(makeToggleMark('bold')), children: _jsx(BoldIcon, { size: 20 }) }), _jsx(ToolbarButton, { label: t('toolbar.italic'), shortcut: "Mod-I", onClick: () => runCommand(makeToggleMark('italic')), children: _jsx(ItalicIcon, { size: 20 }) }), _jsx(ToolbarButton, { label: t('toolbar.underline'), shortcut: "Mod-U", onClick: () => runCommand(makeToggleMark('underline')), children: _jsx(UnderlineIcon, { size: 20 }) }), _jsx("button", { type: "button", className: `cs-tb-overflow${overflowOpen ? ' cs-tb-overflow-active' : ''}`, "aria-label": "More", "aria-expanded": overflowOpen, onClick: () => setOverflowOpen(!overflowOpen), children: _jsx(OverflowIcon, { size: 18 }) })] }), overflowOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "cs-tb-overflow-backdrop", "aria-hidden": "true", onClick: () => setOverflowOpen(false) }), _jsxs("div", { className: "cs-tb-overflow-sheet", role: "dialog", "aria-modal": "true", "aria-label": "Screenplay Elements & Formatting", children: [_jsxs("div", { className: "cs-tb-overflow-header", children: [_jsx("span", { className: "cs-tb-overflow-title", children: "Formatting & Elements" }), _jsx("button", { type: "button", className: "cs-tb-overflow-close", "aria-label": "Close", onClick: () => setOverflowOpen(false), children: _jsx(CloseIcon, { size: 18 }) })] }), _jsx("div", { className: "cs-tb-overflow-section-label", children: "Inline Formatting" }), _jsxs("div", { className: "cs-tb-overflow-inline-grid", children: [_jsxs("button", { type: "button", className: "cs-tb-overflow-item", onClick: () => { runCommand(makeToggleMark('bold')); setOverflowOpen(false); }, children: [_jsx(BoldIcon, { size: 18 }), _jsx("span", { children: t('toolbar.bold') })] }), _jsxs("button", { type: "button", className: "cs-tb-overflow-item", onClick: () => { runCommand(makeToggleMark('italic')); setOverflowOpen(false); }, children: [_jsx(ItalicIcon, { size: 18 }), _jsx("span", { children: t('toolbar.italic') })] }), _jsxs("button", { type: "button", className: "cs-tb-overflow-item", onClick: () => { runCommand(makeToggleMark('underline')); setOverflowOpen(false); }, children: [_jsx(UnderlineIcon, { size: 18 }), _jsx("span", { children: t('toolbar.underline') })] }), _jsxs("button", { type: "button", className: "cs-tb-overflow-item", onClick: () => { runCommand(undo); setOverflowOpen(false); }, children: [_jsx(UndoIcon, { size: 18 }), _jsx("span", { children: t('toolbar.undo') })] }), _jsxs("button", { type: "button", className: "cs-tb-overflow-item", onClick: () => { runCommand(redo); setOverflowOpen(false); }, children: [_jsx(RedoIcon, { size: 18 }), _jsx("span", { children: t('toolbar.redo') })] })] }), _jsx("div", { className: "cs-tb-overflow-section-label", children: "Screenplay Elements" }), _jsx("div", { className: "cs-tb-overflow-list", children: ELEMENTS.map(el => (_jsxs("button", { type: "button", className: `cs-tb-overflow-list-item${activeType === el.type ? ' cs-tb-overflow-item-active' : ''}`, onClick: () => {
27
+ runCommand(el.type === 'note' ? makeSetOrToggleNote() : makeSetBlock(el.type));
28
+ setOverflowOpen(false);
29
+ }, children: [_jsx("div", { className: "cs-tb-overflow-list-icon", children: _jsx(el.Icon, { size: 18 }) }), _jsxs("div", { className: "cs-tb-overflow-list-text", children: [_jsx("span", { className: "cs-tb-overflow-list-name", children: t(el.translationKey) }), _jsx("span", { className: "cs-tb-overflow-list-sigil", children: el.sigil })] }), activeType === el.type && (_jsx("span", { className: "cs-tb-overflow-current-badge", children: "Active" }))] }, el.type))) })] })] }))] }));
30
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function LanguageStatus(): React.JSX.Element;