domma-cms 0.55.1 → 0.69.3

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 (305) hide show
  1. package/CLAUDE.md +194 -3
  2. package/README.md +18 -14
  3. package/admin/css/admin.css +1 -1
  4. package/admin/css/contacts.css +1 -0
  5. package/admin/dist/domma/domma-tools.css +3 -3
  6. package/admin/dist/domma/domma-tools.min.js +3 -3
  7. package/admin/index.html +1 -0
  8. package/admin/js/api.js +1 -1
  9. package/admin/js/app.js +4 -4
  10. package/admin/js/lib/analytics-shape.js +1 -0
  11. package/admin/js/lib/contacts-arrange.js +1 -0
  12. package/admin/js/lib/help-popover.js +1 -0
  13. package/admin/js/lib/notes-arrange.js +1 -0
  14. package/admin/js/lib/page-picker.js +1 -0
  15. package/admin/js/lib/plugin-accent.js +1 -0
  16. package/admin/js/lib/plugin-chrome.js +1 -0
  17. package/admin/js/lib/shortcode-context-menu.js +2 -2
  18. package/admin/js/lib/sidebar-grouping.js +1 -1
  19. package/admin/js/lib/sidebar-grouping.test.js +1 -1
  20. package/admin/js/lib/sidebar-renderer.js +4 -4
  21. package/admin/js/lib/slideover-resizable.js +1 -0
  22. package/admin/js/lib/todo-arrange.js +1 -0
  23. package/admin/js/lib/tool-kit.js +1 -0
  24. package/admin/js/templates/analytics.html +138 -0
  25. package/admin/js/templates/contacts.html +156 -0
  26. package/admin/js/templates/context-menu-editor.html +212 -0
  27. package/admin/js/templates/context-menus.html +16 -0
  28. package/admin/js/templates/notes.html +137 -0
  29. package/admin/js/templates/plugin-code.html +1 -1
  30. package/admin/js/templates/plugin-marketplace.html +17 -4
  31. package/admin/js/templates/plugins.html +13 -7
  32. package/{plugins/site-search/admin/templates/site-search.html → admin/js/templates/search.html} +50 -4
  33. package/admin/js/templates/settings.html +16 -97
  34. package/admin/js/templates/theme.html +211 -0
  35. package/admin/js/templates/todo.html +113 -0
  36. package/admin/js/views/analytics.js +62 -0
  37. package/admin/js/views/contacts.js +174 -0
  38. package/admin/js/views/context-menu-editor.js +55 -0
  39. package/admin/js/views/context-menus.js +5 -0
  40. package/admin/js/views/form-editor.js +7 -7
  41. package/admin/js/views/index.js +1 -1
  42. package/admin/js/views/notes.js +104 -0
  43. package/admin/js/views/plugin-marketplace.js +1 -1
  44. package/admin/js/views/plugins.js +28 -24
  45. package/admin/js/views/search.js +1 -0
  46. package/admin/js/views/settings.js +3 -3
  47. package/admin/js/views/theme.js +1 -0
  48. package/admin/js/views/todo.js +96 -0
  49. package/bin/cli.js +6 -10
  50. package/bin/lib/plugin-version.js +28 -0
  51. package/bin/update.js +27 -2
  52. package/config/menus/admin-sidebar.json +129 -23
  53. package/config/plugins.json +5 -5
  54. package/config/search.json +13 -0
  55. package/config/server.json +3 -1
  56. package/package.json +14 -10
  57. package/plugins/_lib/admin/mail/compose-window.js +914 -0
  58. package/plugins/_lib/admin/mail/contacts.js +301 -0
  59. package/plugins/_lib/admin/mail/diagnostics-section.js +133 -0
  60. package/plugins/_lib/admin/mail/folder-tree.js +254 -0
  61. package/plugins/_lib/admin/mail/identity.js +480 -0
  62. package/plugins/_lib/admin/mail/image-senders-section.js +131 -0
  63. package/plugins/_lib/admin/mail/keyboard.js +136 -0
  64. package/plugins/_lib/admin/mail/mail.css +1 -0
  65. package/plugins/_lib/admin/mail/mail.html +71 -0
  66. package/plugins/_lib/admin/mail/panes.js +253 -0
  67. package/plugins/_lib/admin/mail/reader-view.js +4473 -0
  68. package/plugins/_lib/admin/mail/resizable.js +26 -0
  69. package/plugins/_lib/admin/mail/rules.js +343 -0
  70. package/plugins/_lib/admin/mail/scheduling.js +203 -0
  71. package/plugins/_lib/admin/mail/section-kit.js +277 -0
  72. package/plugins/_lib/admin/mail/templates.js +238 -0
  73. package/plugins/_lib/admin/mail/threads.js +200 -0
  74. package/plugins/_lib/admin/mail/vacation.js +269 -0
  75. package/plugins/_lib/admin/ui/help.css +1 -0
  76. package/plugins/_lib/admin/ui/help.js +174 -0
  77. package/plugins/_lib/admin/ui/resizable.js +151 -0
  78. package/plugins/_lib/dataStore.js +117 -0
  79. package/plugins/_lib/mail/accounts.js +919 -0
  80. package/plugins/_lib/mail/bodyTokens.js +101 -0
  81. package/plugins/_lib/mail/compose.js +256 -0
  82. package/plugins/_lib/mail/defaults.js +57 -0
  83. package/plugins/_lib/mail/diagnostics.js +154 -0
  84. package/plugins/_lib/mail/envelope.js +161 -0
  85. package/plugins/_lib/mail/folders.js +192 -0
  86. package/plugins/_lib/mail/handoff.js +274 -0
  87. package/plugins/_lib/mail/imapPool.js +293 -0
  88. package/plugins/_lib/mail/mbox.js +74 -0
  89. package/plugins/_lib/mail/pollSchedule.js +79 -0
  90. package/plugins/_lib/mail/poller.js +135 -0
  91. package/plugins/_lib/mail/priority.js +138 -0
  92. package/plugins/_lib/mail/readRoutes.js +680 -0
  93. package/plugins/_lib/mail/render.js +291 -0
  94. package/plugins/_lib/mail/ruleRunner.js +152 -0
  95. package/plugins/_lib/mail/scheduler.js +254 -0
  96. package/plugins/_lib/mail/secretbox.js +229 -0
  97. package/plugins/_lib/mail/send.js +396 -0
  98. package/plugins/_lib/mail/store.js +1022 -0
  99. package/plugins/_lib/mail/sync.js +292 -0
  100. package/plugins/_lib/mail/syncPlan.js +126 -0
  101. package/plugins/_lib/mail/syncSelection.js +82 -0
  102. package/plugins/_lib/mail/unsubscribe.js +183 -0
  103. package/plugins/_lib/mail/vacationRunner.js +114 -0
  104. package/plugins/_lib/mail/write.js +473 -0
  105. package/plugins/_lib/schemaSync.js +83 -0
  106. package/plugins/_template/admin/css/index.css +0 -0
  107. package/plugins/_template/admin/templates/index.html +4 -4
  108. package/plugins/_template/admin/views/index.js +7 -0
  109. package/plugins/blog/CLAUDE.md +237 -0
  110. package/plugins/blog/admin/css/index.css +178 -0
  111. package/plugins/blog/admin/templates/blog.html +35 -41
  112. package/plugins/blog/admin/templates/categories.html +19 -6
  113. package/plugins/blog/admin/templates/comments.html +26 -9
  114. package/plugins/blog/admin/templates/post-editor.html +63 -40
  115. package/plugins/blog/admin/templates/settings.html +3 -9
  116. package/plugins/blog/admin/views/blog.js +288 -159
  117. package/plugins/blog/admin/views/categories.js +212 -206
  118. package/plugins/blog/admin/views/comments.js +207 -158
  119. package/plugins/blog/admin/views/kit.js +372 -0
  120. package/plugins/blog/admin/views/post-editor.js +306 -39
  121. package/plugins/blog/admin/views/settings-cog.js +56 -0
  122. package/plugins/blog/admin/views/settings.js +16 -84
  123. package/plugins/blog/blocks/blog-card-compact.css +17 -0
  124. package/plugins/blog/blocks/blog-card-compact.html +8 -0
  125. package/plugins/blog/blocks/blog-card-row.css +22 -0
  126. package/plugins/blog/blocks/blog-card-row.html +11 -0
  127. package/plugins/blog/blocks/blog-card.css +35 -0
  128. package/plugins/blog/blocks/blog-card.html +16 -0
  129. package/plugins/blog/blocks/blog-post-classic.css +15 -0
  130. package/plugins/blog/blocks/blog-post-classic.html +28 -0
  131. package/plugins/blog/blocks/blog-post-feature.css +20 -0
  132. package/plugins/blog/blocks/blog-post-feature.html +30 -0
  133. package/plugins/blog/blocks/blog-post-minimal.css +10 -0
  134. package/plugins/blog/blocks/blog-post-minimal.html +23 -0
  135. package/plugins/blog/blocks/blog-post-sidebar.css +22 -0
  136. package/plugins/blog/blocks/blog-post-sidebar.html +36 -0
  137. package/plugins/blog/collections/categories/schema.json +7 -6
  138. package/plugins/blog/collections/comments/schema.json +11 -10
  139. package/plugins/blog/collections/posts/schema.json +16 -13
  140. package/plugins/blog/config.js +6 -0
  141. package/plugins/blog/lib/layouts.js +304 -0
  142. package/plugins/blog/lib/page.js +158 -0
  143. package/plugins/blog/lib/render.js +119 -0
  144. package/plugins/blog/lib/samples.js +234 -0
  145. package/plugins/blog/plugin.js +259 -26
  146. package/plugins/blog/plugin.json +21 -73
  147. package/plugins/blog/plugin.public.js +217 -0
  148. package/plugins/blog/public/blog.css +177 -0
  149. package/plugins/blog/public/blog.js +586 -0
  150. package/plugins/blog/public/samples/aurora.svg +7 -0
  151. package/plugins/blog/public/samples/dusk.svg +7 -0
  152. package/plugins/blog/public/samples/ember.svg +7 -0
  153. package/plugins/blog/public/samples/harbour.svg +7 -0
  154. package/plugins/blog/public/samples/meadow.svg +7 -0
  155. package/plugins/blog/public/samples/rosewood.svg +7 -0
  156. package/plugins/blog/templates/index.html +9 -8
  157. package/plugins/blog/templates/post.html +4 -17
  158. package/plugins/blog/tests/layouts.test.js +97 -0
  159. package/plugins/blog/tests/public.test.js +71 -0
  160. package/plugins/free-tier.lock.json +74 -0
  161. package/plugins/mail-reader/CLAUDE.md +78 -0
  162. package/plugins/mail-reader/admin/views/mail.js +19 -0
  163. package/plugins/mail-reader/config.js +7 -0
  164. package/plugins/mail-reader/plugin.js +48 -0
  165. package/plugins/mail-reader/plugin.json +34 -0
  166. package/public/css/forms.css +1 -1
  167. package/public/css/search.css +1 -0
  168. package/public/css/site.css +1 -1
  169. package/public/css/theme-switcher.css +1 -0
  170. package/public/js/analytics.js +1 -0
  171. package/public/js/collection-context.js +2 -2
  172. package/public/js/context-menus.js +1 -0
  173. package/public/js/form-logic-engine.js +1 -1
  174. package/public/js/forms.js +2 -2
  175. package/public/js/search.js +1 -0
  176. package/public/js/site.js +1 -1
  177. package/public/js/theme-switcher.js +1 -0
  178. package/scripts/build.js +77 -4
  179. package/scripts/copy-domma.js +48 -0
  180. package/scripts/run-tests.mjs +92 -0
  181. package/scripts/seed.js +1996 -0
  182. package/{plugins/analytics/plugin.js → server/routes/api/analytics.js} +89 -41
  183. package/server/routes/api/collections.js +34 -0
  184. package/server/routes/api/contacts.js +506 -0
  185. package/server/routes/api/context-menus.js +104 -0
  186. package/server/routes/api/dashboard.js +8 -2
  187. package/server/routes/api/forms.js +42 -3
  188. package/{plugins/notes/plugin.js → server/routes/api/notes.js} +61 -17
  189. package/server/routes/api/notifications.js +69 -19
  190. package/server/routes/api/plugin-marketplace.js +78 -23
  191. package/server/routes/api/plugins.js +198 -9
  192. package/server/routes/api/search.js +43 -0
  193. package/server/routes/api/theme.js +69 -0
  194. package/server/routes/api/todo.js +178 -0
  195. package/server/routes/public.js +42 -7
  196. package/server/server.js +135 -1
  197. package/server/services/adapters/FileAdapter.js +6 -1
  198. package/server/services/collections.js +13 -3
  199. package/server/services/content.js +26 -0
  200. package/server/services/contextMenus.js +477 -0
  201. package/server/services/managerClient.js +72 -136
  202. package/server/services/markdown.js +124 -10
  203. package/server/services/permissionRegistry.js +74 -0
  204. package/server/services/pluginEntitlement.js +171 -0
  205. package/server/services/pluginEnvelope.js +242 -0
  206. package/server/services/pluginFiles.js +52 -11
  207. package/server/services/pluginInstaller.js +246 -26
  208. package/server/services/pluginScaffold.js +5 -0
  209. package/server/services/plugins.js +340 -7
  210. package/server/services/presetCollections.js +344 -0
  211. package/server/services/promoted-plugins-migration.js +254 -0
  212. package/server/services/publicCors.js +46 -0
  213. package/server/services/renderer.js +224 -22
  214. package/server/services/roles.js +1 -1
  215. package/server/services/search-migration.js +82 -0
  216. package/server/services/search.js +413 -0
  217. package/server/services/sidebar-migration.js +1 -0
  218. package/server/services/sidebarBadges.js +37 -0
  219. package/server/services/siteGitignore.js +307 -0
  220. package/server/services/themeSettings.js +580 -0
  221. package/server/services/users.js +8 -0
  222. package/server/templates/page.html +4 -2
  223. package/plugins/analytics/admin/templates/analytics.html +0 -61
  224. package/plugins/analytics/admin/views/analytics.js +0 -176
  225. package/plugins/analytics/config.js +0 -14
  226. package/plugins/analytics/plugin.json +0 -57
  227. package/plugins/analytics/public/inject-body.html +0 -60
  228. package/plugins/analytics/public/inject-head.html +0 -1
  229. package/plugins/blog/templates/author.html +0 -9
  230. package/plugins/blog/templates/category.html +0 -9
  231. package/plugins/blog/templates/tag.html +0 -9
  232. package/plugins/contacts/admin/templates/contacts.html +0 -126
  233. package/plugins/contacts/admin/views/contacts.js +0 -710
  234. package/plugins/contacts/collections/user-contact-groups/schema.json +0 -35
  235. package/plugins/contacts/collections/user-contacts/schema.json +0 -71
  236. package/plugins/contacts/config.js +0 -6
  237. package/plugins/contacts/data/contacts.json +0 -20
  238. package/plugins/contacts/plugin.js +0 -291
  239. package/plugins/contacts/plugin.json +0 -33
  240. package/plugins/demo-viewer/config.js +0 -4
  241. package/plugins/demo-viewer/plugin.js +0 -36
  242. package/plugins/demo-viewer/plugin.json +0 -9
  243. package/plugins/invoice/admin/templates/editor.html +0 -129
  244. package/plugins/invoice/admin/templates/index.html +0 -43
  245. package/plugins/invoice/admin/templates/issuers.html +0 -5
  246. package/plugins/invoice/admin/templates/receivers.html +0 -5
  247. package/plugins/invoice/admin/views/editor.js +0 -267
  248. package/plugins/invoice/admin/views/index.js +0 -155
  249. package/plugins/invoice/admin/views/issuers.js +0 -23
  250. package/plugins/invoice/admin/views/party-view.js +0 -148
  251. package/plugins/invoice/admin/views/receivers.js +0 -22
  252. package/plugins/invoice/collections/invoice-issuers/schema.json +0 -16
  253. package/plugins/invoice/collections/invoice-receivers/schema.json +0 -15
  254. package/plugins/invoice/collections/invoices/schema.json +0 -27
  255. package/plugins/invoice/config.js +0 -16
  256. package/plugins/invoice/plugin.js +0 -283
  257. package/plugins/invoice/plugin.json +0 -85
  258. package/plugins/invoice/templates/invoice-print.html +0 -213
  259. package/plugins/notes/admin/templates/notes.html +0 -83
  260. package/plugins/notes/admin/views/notes.js +0 -281
  261. package/plugins/notes/collections/user-notes/schema.json +0 -54
  262. package/plugins/notes/config.js +0 -6
  263. package/plugins/notes/data/notes.json +0 -1
  264. package/plugins/notes/plugin.json +0 -33
  265. package/plugins/site-search/admin/views/site-search.js +0 -116
  266. package/plugins/site-search/config.js +0 -15
  267. package/plugins/site-search/plugin.js +0 -188
  268. package/plugins/site-search/plugin.json +0 -40
  269. package/plugins/site-search/public/inject-body.html +0 -17
  270. package/plugins/site-search/public/inject-head.html +0 -1
  271. package/plugins/site-search/public/search.css +0 -1
  272. package/plugins/site-search/public/search.js +0 -1
  273. package/plugins/surveys/admin/templates/audience.html +0 -47
  274. package/plugins/surveys/admin/templates/results.html +0 -58
  275. package/plugins/surveys/admin/templates/survey-editor.html +0 -141
  276. package/plugins/surveys/admin/templates/surveys.html +0 -25
  277. package/plugins/surveys/admin/views/audience.js +0 -301
  278. package/plugins/surveys/admin/views/results.js +0 -172
  279. package/plugins/surveys/admin/views/survey-editor.js +0 -211
  280. package/plugins/surveys/admin/views/surveys.js +0 -161
  281. package/plugins/surveys/collections/survey-contacts/schema.json +0 -13
  282. package/plugins/surveys/collections/survey-groups/schema.json +0 -11
  283. package/plugins/surveys/collections/survey-invites/schema.json +0 -16
  284. package/plugins/surveys/collections/surveys/schema.json +0 -23
  285. package/plugins/surveys/config.js +0 -8
  286. package/plugins/surveys/plugin.js +0 -174
  287. package/plugins/surveys/plugin.json +0 -65
  288. package/plugins/surveys/public/dist-shared.mjs +0 -1
  289. package/plugins/surveys/public/survey.css +0 -1
  290. package/plugins/surveys/public/survey.mjs +0 -1
  291. package/plugins/surveys/templates/survey-page.html +0 -63
  292. package/plugins/theme-switcher/admin/templates/theme-switcher.html +0 -86
  293. package/plugins/theme-switcher/admin/views/theme-switcher.js +0 -65
  294. package/plugins/theme-switcher/config.js +0 -10
  295. package/plugins/theme-switcher/plugin.js +0 -26
  296. package/plugins/theme-switcher/plugin.json +0 -74
  297. package/plugins/theme-switcher/public/inject-body.html +0 -153
  298. package/plugins/theme-switcher/public/inject-head.html +0 -260
  299. package/plugins/todo/admin/templates/todo.html +0 -158
  300. package/plugins/todo/admin/views/todo.js +0 -343
  301. package/plugins/todo/collections/todos/schema.json +0 -60
  302. package/plugins/todo/config.js +0 -7
  303. package/plugins/todo/data/todos.json +0 -1
  304. package/plugins/todo/plugin.js +0 -102
  305. package/plugins/todo/plugin.json +0 -33
@@ -1,43 +0,0 @@
1
- <div class="view-header d-flex align-items-center justify-content-between mb-4">
2
- <h1 class="h3 mb-0"><span data-icon="file-text"></span> Invoices</h1>
3
- <button id="btn-new-invoice" class="btn btn-primary">
4
- <span data-icon="plus"></span> New Invoice
5
- </button>
6
- </div>
7
-
8
- <div class="grid grid-cols-4 gap-3 mb-4">
9
- <div class="card"><div class="card-body">
10
- <div class="text-muted small">Total invoices</div>
11
- <div class="h3 mb-0" id="kpi-total">-</div>
12
- </div></div>
13
- <div class="card"><div class="card-body">
14
- <div class="text-muted small">Outstanding</div>
15
- <div class="h3 mb-0" id="kpi-outstanding">-</div>
16
- </div></div>
17
- <div class="card"><div class="card-body">
18
- <div class="text-muted small">Paid</div>
19
- <div class="h3 mb-0" id="kpi-paid">-</div>
20
- </div></div>
21
- <div class="card"><div class="card-body">
22
- <div class="text-muted small">Drafts</div>
23
- <div class="h3 mb-0" id="kpi-drafts">-</div>
24
- </div></div>
25
- </div>
26
-
27
- <div class="card mb-3">
28
- <div class="card-body">
29
- <div class="d-flex gap-2 flex-wrap">
30
- <select id="filter-status" class="form-select" style="width:auto;">
31
- <option value="">All statuses</option>
32
- <option value="draft">Draft</option>
33
- <option value="sent">Sent</option>
34
- <option value="paid">Paid</option>
35
- <option value="overdue">Overdue</option>
36
- <option value="cancelled">Cancelled</option>
37
- </select>
38
- <input id="filter-search" type="search" class="form-control" style="width:240px;" placeholder="Search number or receiver…">
39
- </div>
40
- </div>
41
- </div>
42
-
43
- <div id="invoices-table"></div>
@@ -1,5 +0,0 @@
1
- <div class="view-header d-flex align-items-center justify-content-between mb-4">
2
- <h1 class="h3 mb-0"><span data-icon="briefcase"></span> Issuers</h1>
3
- <button id="btn-new" class="btn btn-primary"><span data-icon="plus"></span> New Issuer</button>
4
- </div>
5
- <div id="party-table"></div>
@@ -1,5 +0,0 @@
1
- <div class="view-header d-flex align-items-center justify-content-between mb-4">
2
- <h1 class="h3 mb-0"><span data-icon="users"></span> Receivers</h1>
3
- <button id="btn-new" class="btn btn-primary"><span data-icon="plus"></span> New Receiver</button>
4
- </div>
5
- <div id="party-table"></div>
@@ -1,267 +0,0 @@
1
- /**
2
- * Invoice plugin - editor view. Create or edit a single invoice.
3
- */
4
- function escapeHtml(s) {
5
- return String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
6
- }
7
-
8
- function fmt(amount, currency) {
9
- try {
10
- return new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency || 'GBP' }).format(Number(amount) || 0);
11
- } catch {
12
- return `${currency || 'GBP'} ${Number(amount).toFixed(2)}`;
13
- }
14
- }
15
-
16
- function round2(n) {
17
- return Math.round((Number(n) + Number.EPSILON) * 100) / 100;
18
- }
19
-
20
- const BASE = '/api/plugins/invoice';
21
-
22
- export const editorView = {
23
- templateUrl: '/plugins/invoice/admin/templates/editor.html',
24
-
25
- async onMount($container) {
26
- const id = R.current?.params?.id ?? null;
27
- const isEdit = Boolean(id);
28
- let invoice = null;
29
- let issuers = [];
30
- let receivers = [];
31
- let lineItems = [];
32
-
33
- try {
34
- const [issRes, recRes] = await Promise.all([
35
- H.get(`${BASE}/issuers`),
36
- H.get(`${BASE}/receivers`)
37
- ]);
38
- issuers = issRes.data ?? issRes ?? [];
39
- receivers = recRes.data ?? recRes ?? [];
40
- } catch {
41
- E.toast('Could not load issuers / receivers.', { type: 'error' });
42
- }
43
-
44
- if (isEdit) {
45
- try {
46
- const res = await H.get(`${BASE}/invoices/${id}`);
47
- invoice = res.data ?? res;
48
- lineItems = Array.isArray(invoice.lineItems) ? [...invoice.lineItems] : [];
49
- } catch {
50
- E.toast('Invoice not found.', { type: 'error' });
51
- R.navigate('#/plugins/invoice');
52
- return;
53
- }
54
- }
55
-
56
- const $title = $container.find('#editor-title');
57
- const $number = $container.find('#f-number');
58
- const $status = $container.find('#f-status');
59
- const $issueDate = $container.find('#f-issue-date');
60
- const $dueDate = $container.find('#f-due-date');
61
- const $issuer = $container.find('#f-issuer');
62
- const $receiver = $container.find('#f-receiver');
63
- const $vatEnabled = $container.find('#f-vat-enabled');
64
- const $vatRate = $container.find('#f-vat-rate');
65
- const $currency = $container.find('#f-currency');
66
- const $notes = $container.find('#f-notes');
67
- const $print = $container.find('#btn-print');
68
- const $body = $container.find('#line-items-body');
69
- const $vatRow = $container.find('#vat-row');
70
- const $tSubtotal = $container.find('#t-subtotal');
71
- const $tVat = $container.find('#t-vat');
72
- const $tVatRate = $container.find('#t-vat-rate');
73
- const $tTotal = $container.find('#t-total');
74
-
75
- function populateSelect($select, list, valueKey, labelFn, selected) {
76
- const el = $select.get(0);
77
- while (el.firstChild) el.removeChild(el.firstChild);
78
- const placeholder = document.createElement('option');
79
- placeholder.value = '';
80
- placeholder.textContent = '- select -';
81
- el.appendChild(placeholder);
82
- for (const item of list) {
83
- const opt = document.createElement('option');
84
- opt.value = item[valueKey];
85
- opt.textContent = labelFn(item);
86
- if (item[valueKey] === selected) opt.selected = true;
87
- el.appendChild(opt);
88
- }
89
- }
90
-
91
- populateSelect($issuer, issuers, 'id', (i) => i.name || '(unnamed)', invoice?.issuerId);
92
- populateSelect($receiver, receivers, 'id', (r) => r.company || r.name || '(unnamed)', invoice?.receiverId);
93
-
94
- const today = new Date().toISOString().slice(0, 10);
95
- $title.text(isEdit ? `Edit Invoice ${invoice?.number ?? ''}` : 'New Invoice');
96
- $number.val(invoice?.number ?? '');
97
- $status.val(invoice?.status ?? 'draft');
98
- $issueDate.val(invoice?.issueDate ?? today);
99
- $dueDate.val(invoice?.dueDate ?? '');
100
- $vatEnabled.prop('checked', invoice?.vatEnabled !== false);
101
- $vatRate.val(invoice?.vatRate ?? 20);
102
- $currency.val(invoice?.currency ?? 'GBP');
103
- $notes.val(invoice?.notes ?? '');
104
-
105
- if (isEdit) {
106
- $print.attr('href', `${BASE}/invoices/${id}/print`).css('display', '');
107
- }
108
-
109
- if (!lineItems.length) {
110
- lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
111
- }
112
- renderLineItems();
113
- recomputeTotals();
114
-
115
- function makeCell(child) {
116
- const td = document.createElement('td');
117
- td.appendChild(child);
118
- return td;
119
- }
120
-
121
- function renderLineItems() {
122
- const body = $body.get(0);
123
- while (body.firstChild) body.removeChild(body.firstChild);
124
-
125
- lineItems.forEach((item, idx) => {
126
- const tr = document.createElement('tr');
127
-
128
- const desc = document.createElement('input');
129
- desc.type = 'text';
130
- desc.className = 'form-control li-desc';
131
- desc.dataset.idx = idx;
132
- desc.value = item.description ?? '';
133
- desc.placeholder = 'Description';
134
-
135
- const qty = document.createElement('input');
136
- qty.type = 'number';
137
- qty.className = 'form-control li-qty';
138
- qty.dataset.idx = idx;
139
- qty.min = '0';
140
- qty.step = '0.01';
141
- qty.value = Number(item.quantity) || 0;
142
-
143
- const price = document.createElement('input');
144
- price.type = 'number';
145
- price.className = 'form-control li-price';
146
- price.dataset.idx = idx;
147
- price.min = '0';
148
- price.step = '0.01';
149
- price.value = Number(item.unitPrice) || 0;
150
-
151
- const totalCell = document.createElement('td');
152
- totalCell.style.cssText = 'text-align:right;font-variant-numeric:tabular-nums;';
153
- totalCell.id = `line-total-${idx}`;
154
- totalCell.textContent = '-';
155
-
156
- const removeBtn = document.createElement('button');
157
- removeBtn.type = 'button';
158
- removeBtn.className = 'btn btn-sm btn-ghost li-remove';
159
- removeBtn.dataset.idx = idx;
160
- removeBtn.title = 'Remove';
161
- removeBtn.textContent = '×';
162
-
163
- tr.appendChild(makeCell(desc));
164
- tr.appendChild(makeCell(qty));
165
- tr.appendChild(makeCell(price));
166
- tr.appendChild(totalCell);
167
- tr.appendChild(makeCell(removeBtn));
168
- body.appendChild(tr);
169
- });
170
-
171
- updateLineTotals();
172
- }
173
-
174
- function updateLineTotals() {
175
- const currency = $currency.val();
176
- lineItems.forEach((item, idx) => {
177
- const lineTotal = round2((Number(item.quantity) || 0) * (Number(item.unitPrice) || 0));
178
- const cell = $container.find(`#line-total-${idx}`).get(0);
179
- if (cell) cell.textContent = fmt(lineTotal, currency);
180
- });
181
- }
182
-
183
- function recomputeTotals() {
184
- const currency = $currency.val();
185
- const vatEnabled = $vatEnabled.prop('checked');
186
- const vatRate = Number($vatRate.val()) || 0;
187
-
188
- let subtotal = 0;
189
- for (const item of lineItems) {
190
- subtotal += (Number(item.quantity) || 0) * (Number(item.unitPrice) || 0);
191
- }
192
- subtotal = round2(subtotal);
193
- const vat = vatEnabled ? round2(subtotal * (vatRate / 100)) : 0;
194
- const total = round2(subtotal + vat);
195
-
196
- $tSubtotal.text(fmt(subtotal, currency));
197
- $tVat.text(fmt(vat, currency));
198
- $tVatRate.text(vatRate);
199
- $tTotal.text(fmt(total, currency));
200
- $vatRow.css('display', vatEnabled ? '' : 'none');
201
- updateLineTotals();
202
- }
203
-
204
- $body.on('input', '.li-desc', function () {
205
- lineItems[Number(this.dataset.idx)].description = this.value;
206
- });
207
- $body.on('input', '.li-qty', function () {
208
- lineItems[Number(this.dataset.idx)].quantity = Number(this.value) || 0;
209
- recomputeTotals();
210
- });
211
- $body.on('input', '.li-price', function () {
212
- lineItems[Number(this.dataset.idx)].unitPrice = Number(this.value) || 0;
213
- recomputeTotals();
214
- });
215
- $body.on('click', '.li-remove', function () {
216
- const idx = Number(this.dataset.idx);
217
- lineItems.splice(idx, 1);
218
- if (!lineItems.length) lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
219
- renderLineItems();
220
- recomputeTotals();
221
- });
222
-
223
- $container.find('#btn-add-line').on('click', () => {
224
- lineItems.push({ description: '', quantity: 1, unitPrice: 0 });
225
- renderLineItems();
226
- recomputeTotals();
227
- });
228
-
229
- $vatEnabled.on('change', recomputeTotals);
230
- $vatRate.on('input', recomputeTotals);
231
- $currency.on('change', recomputeTotals);
232
-
233
- $container.find('#btn-save').on('click', async () => {
234
- const issuerId = $issuer.val();
235
- const receiverId = $receiver.val();
236
- if (!issuerId) { E.toast('Pick an issuer.', { type: 'error' }); return; }
237
- if (!receiverId) { E.toast('Pick a receiver.', { type: 'error' }); return; }
238
-
239
- const body = {
240
- number: $number.val()?.trim() || undefined,
241
- status: $status.val(),
242
- issueDate: $issueDate.val(),
243
- dueDate: $dueDate.val() || '',
244
- issuerId,
245
- receiverId,
246
- vatEnabled: $vatEnabled.prop('checked'),
247
- vatRate: Number($vatRate.val()) || 0,
248
- currency: $currency.val(),
249
- notes: $notes.val() ?? '',
250
- lineItems
251
- };
252
-
253
- try {
254
- const res = isEdit
255
- ? await H.put(`${BASE}/invoices/${id}`, body)
256
- : await H.post(`${BASE}/invoices`, body);
257
- if (res.error) throw new Error(res.error);
258
- E.toast(isEdit ? 'Invoice saved.' : 'Invoice created.', { type: 'success' });
259
- R.navigate('#/plugins/invoice');
260
- } catch (err) {
261
- E.toast(err?.message ?? 'Save failed.', { type: 'error' });
262
- }
263
- });
264
-
265
- Domma.icons.scan();
266
- }
267
- };
@@ -1,155 +0,0 @@
1
- /**
2
- * Invoice plugin - list view.
3
- */
4
- function escapeHtml(s) {
5
- return String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
6
- }
7
-
8
- const BASE = '/api/plugins/invoice';
9
-
10
- const STATUS_BADGE = {
11
- draft: 'badge-secondary',
12
- sent: 'badge-info',
13
- paid: 'badge-success',
14
- overdue: 'badge-danger',
15
- cancelled: 'badge-secondary'
16
- };
17
-
18
- export const indexView = {
19
- templateUrl: '/plugins/invoice/admin/templates/index.html',
20
-
21
- async onMount($container) {
22
- let invoices = [];
23
- let receivers = [];
24
- let table = null;
25
-
26
- function receiverName(id) {
27
- const r = receivers.find((x) => x.id === id);
28
- if (!r) return '-';
29
- return r.company || r.name || id;
30
- }
31
-
32
- function fmt(amount, currency) {
33
- try {
34
- return new Intl.NumberFormat('en-GB', { style: 'currency', currency: currency || 'GBP' }).format(Number(amount) || 0);
35
- } catch {
36
- return `${currency || 'GBP'} ${Number(amount).toFixed(2)}`;
37
- }
38
- }
39
-
40
- function buildTable(data) {
41
- const el = $container.find('#invoices-table').get(0);
42
- if (!el) return;
43
- if (table) {
44
- table.setData(data);
45
- Domma.icons.scan(el);
46
- return;
47
- }
48
- table = T.create(el, {
49
- data,
50
- columns: [
51
- {
52
- key: 'number', title: 'Number', sortable: true,
53
- render: (v, row) => `<a href="#/plugins/invoice/edit/${escapeHtml(row.id)}" style="font-weight:600;">${escapeHtml(v || '-')}</a>`
54
- },
55
- { key: 'receiverId', title: 'Billed To', sortable: false,
56
- render: (v) => escapeHtml(receiverName(v))
57
- },
58
- { key: 'issueDate', title: 'Issue Date', sortable: true,
59
- render: (v) => v ? escapeHtml(D(v).format('DD MMM YYYY')) : '-'
60
- },
61
- { key: 'totals', title: 'Total', sortable: false,
62
- render: (totals, row) => `<span style="font-variant-numeric:tabular-nums;">${escapeHtml(fmt(totals?.total ?? 0, row.currency))}</span>`
63
- },
64
- { key: 'status', title: 'Status', sortable: true,
65
- render: (v) => `<span class="badge ${STATUS_BADGE[v] || 'badge-secondary'}">${escapeHtml(v || 'draft')}</span>`
66
- },
67
- { key: 'id', title: 'Actions', sortable: false,
68
- render: (id) => `<div style="display:flex;gap:.4rem;">
69
- <button class="btn btn-sm btn-outline edit-btn" data-id="${escapeHtml(id)}"><span data-icon="edit" data-icon-size="14"></span></button>
70
- <a class="btn btn-sm btn-outline" href="${BASE}/invoices/${escapeHtml(id)}/print" target="_blank" title="Print / PDF"><span data-icon="printer" data-icon-size="14"></span></a>
71
- <button class="btn btn-sm btn-danger delete-btn" data-id="${escapeHtml(id)}"><span data-icon="trash" data-icon-size="14"></span></button>
72
- </div>`
73
- }
74
- ],
75
- emptyMessage: 'No invoices yet. Click “New Invoice” to create your first.'
76
- });
77
-
78
- el.addEventListener('click', async (e) => {
79
- const editBtn = e.target.closest('.edit-btn');
80
- const delBtn = e.target.closest('.delete-btn');
81
- if (editBtn) R.navigate('#/plugins/invoice/edit/' + editBtn.dataset.id);
82
- if (delBtn) {
83
- const id = delBtn.dataset.id;
84
- const inv = invoices.find((x) => x.id === id);
85
- const ok = await E.confirm(`Delete invoice ${inv?.number ?? ''}?`);
86
- if (!ok) return;
87
- try {
88
- await H.delete(`${BASE}/invoices/${id}`);
89
- E.toast('Invoice deleted.', { type: 'success' });
90
- await reload();
91
- } catch {
92
- E.toast('Delete failed.', { type: 'error' });
93
- }
94
- }
95
- });
96
-
97
- Domma.icons.scan(el);
98
- }
99
-
100
- function refreshKpis() {
101
- const counts = { total: invoices.length, outstanding: 0, paid: 0, drafts: 0 };
102
- for (const i of invoices) {
103
- if (i.status === 'paid') counts.paid++;
104
- else if (i.status === 'draft') counts.drafts++;
105
- else if (i.status === 'sent' || i.status === 'overdue') counts.outstanding++;
106
- }
107
- $container.find('#kpi-total').text(counts.total);
108
- $container.find('#kpi-outstanding').text(counts.outstanding);
109
- $container.find('#kpi-paid').text(counts.paid);
110
- $container.find('#kpi-drafts').text(counts.drafts);
111
- }
112
-
113
- function applyFilters() {
114
- const status = $container.find('#filter-status').val() || '';
115
- const q = ($container.find('#filter-search').val() || '').toString().toLowerCase().trim();
116
- let filtered = invoices;
117
- if (status) filtered = filtered.filter((i) => i.status === status);
118
- if (q) {
119
- filtered = filtered.filter((i) =>
120
- (i.number ?? '').toLowerCase().includes(q) ||
121
- receiverName(i.receiverId).toLowerCase().includes(q)
122
- );
123
- }
124
- buildTable(filtered);
125
- }
126
-
127
- async function reload() {
128
- try {
129
- const [invRes, recRes] = await Promise.all([
130
- H.get(`${BASE}/invoices`),
131
- H.get(`${BASE}/receivers`).catch(() => ({ data: [] }))
132
- ]);
133
- invoices = invRes.data ?? invRes ?? [];
134
- receivers = recRes.data ?? recRes ?? [];
135
- } catch {
136
- invoices = [];
137
- receivers = [];
138
- E.toast('Could not load invoices.', { type: 'error' });
139
- }
140
- refreshKpis();
141
- applyFilters();
142
- }
143
-
144
- $container.find('#btn-new-invoice').on('click', () => R.navigate('#/plugins/invoice/new'));
145
- $container.find('#filter-status').on('change', applyFilters);
146
- let timer = null;
147
- $container.find('#filter-search').on('input', () => {
148
- clearTimeout(timer);
149
- timer = setTimeout(applyFilters, 200);
150
- });
151
-
152
- await reload();
153
- Domma.icons.scan();
154
- }
155
- };
@@ -1,23 +0,0 @@
1
- /**
2
- * Invoice plugin - issuers CRUD view.
3
- */
4
- import {mountPartyView} from './party-view.js?v=1';
5
-
6
- export const issuersView = {
7
- templateUrl: '/plugins/invoice/admin/templates/issuers.html',
8
- onMount: ($container) => mountPartyView($container, {
9
- kind: 'issuer',
10
- endpoint: '/api/plugins/invoice/issuers',
11
- label: 'Issuer',
12
- fields: [
13
- { key: 'name', label: 'Trading Name', required: true, type: 'text' },
14
- { key: 'email', label: 'Email', type: 'text' },
15
- { key: 'phone', label: 'Phone', type: 'text' },
16
- { key: 'website', label: 'Website', type: 'text' },
17
- { key: 'vatNumber', label: 'VAT Number', type: 'text' },
18
- { key: 'logoUrl', label: 'Logo URL', type: 'text' },
19
- { key: 'address', label: 'Address', type: 'textarea' },
20
- { key: 'bankDetails', label: 'Bank Details', type: 'textarea' }
21
- ]
22
- })
23
- };
@@ -1,148 +0,0 @@
1
- /**
2
- * Shared CRUD view for issuers and receivers.
3
- * Renders a sortable table and an edit slideover driven by a fields[] config.
4
- */
5
- function escapeHtml(s) {
6
- return String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
7
- }
8
-
9
- export async function mountPartyView($container, config) {
10
- let parties = [];
11
- let table = null;
12
-
13
- function buildTable(data) {
14
- const el = $container.find('#party-table').get(0);
15
- if (!el) return;
16
- if (table) {
17
- table.setData(data);
18
- Domma.icons.scan(el);
19
- return;
20
- }
21
-
22
- const cols = [
23
- { key: 'name', title: 'Name', sortable: true,
24
- render: (v, row) => `<a href="#" data-id="${escapeHtml(row.id)}" class="party-edit" style="font-weight:600;">${escapeHtml(v || '(unnamed)')}</a>`
25
- }
26
- ];
27
- if (config.fields.some((f) => f.key === 'company')) {
28
- cols.push({ key: 'company', title: 'Company', sortable: true, render: (v) => escapeHtml(v || '-') });
29
- }
30
- cols.push(
31
- { key: 'email', title: 'Email', sortable: true, render: (v) => v ? `<a href="mailto:${escapeHtml(v)}">${escapeHtml(v)}</a>` : '-' },
32
- { key: 'vatNumber', title: 'VAT', sortable: false, render: (v) => v ? `<code>${escapeHtml(v)}</code>` : '-' },
33
- { key: 'id', title: 'Actions', sortable: false,
34
- render: (id) => `<div style="display:flex;gap:.4rem;">
35
- <button class="btn btn-sm btn-outline party-edit" data-id="${escapeHtml(id)}"><span data-icon="edit" data-icon-size="14"></span></button>
36
- <button class="btn btn-sm btn-danger party-delete" data-id="${escapeHtml(id)}"><span data-icon="trash" data-icon-size="14"></span></button>
37
- </div>` }
38
- );
39
-
40
- table = T.create(el, { data, columns: cols, emptyMessage: `No ${config.label.toLowerCase()}s yet.` });
41
-
42
- el.addEventListener('click', async (e) => {
43
- const editEl = e.target.closest('.party-edit');
44
- const delEl = e.target.closest('.party-delete');
45
- if (editEl) {
46
- e.preventDefault();
47
- const party = parties.find((p) => p.id === editEl.dataset.id);
48
- openEditor(party);
49
- }
50
- if (delEl) {
51
- const party = parties.find((p) => p.id === delEl.dataset.id);
52
- const ok = await E.confirm(`Delete ${config.label.toLowerCase()} "${party?.name ?? ''}"?`);
53
- if (!ok) return;
54
- try {
55
- await H.delete(`${config.endpoint}/${party.id}`);
56
- E.toast('Deleted.', { type: 'success' });
57
- await reload();
58
- } catch {
59
- E.toast('Delete failed.', { type: 'error' });
60
- }
61
- }
62
- });
63
-
64
- Domma.icons.scan(el);
65
- }
66
-
67
- async function reload() {
68
- try {
69
- const res = await H.get(config.endpoint);
70
- parties = res.data ?? res ?? [];
71
- } catch {
72
- parties = [];
73
- E.toast(`Could not load ${config.label.toLowerCase()}s.`, { type: 'error' });
74
- }
75
- buildTable(parties);
76
- }
77
-
78
- function openEditor(existing) {
79
- const isEdit = Boolean(existing);
80
- const form = document.createElement('div');
81
- form.style.cssText = 'display:flex;flex-direction:column;gap:.75rem;padding:.5rem;';
82
-
83
- const inputs = {};
84
- for (const field of config.fields) {
85
- const wrap = document.createElement('div');
86
- const label = document.createElement('label');
87
- label.className = 'form-label';
88
- label.textContent = field.label + (field.required ? ' *' : '');
89
- wrap.appendChild(label);
90
-
91
- let input;
92
- if (field.type === 'textarea') {
93
- input = document.createElement('textarea');
94
- input.rows = 3;
95
- } else {
96
- input = document.createElement('input');
97
- input.type = 'text';
98
- }
99
- input.className = 'form-control';
100
- input.value = existing?.[field.key] ?? '';
101
- wrap.appendChild(input);
102
- form.appendChild(wrap);
103
- inputs[field.key] = input;
104
- }
105
-
106
- const saveBtn = document.createElement('button');
107
- saveBtn.type = 'button';
108
- saveBtn.className = 'btn btn-primary mt-2';
109
- saveBtn.textContent = isEdit ? 'Save changes' : 'Create';
110
- form.appendChild(saveBtn);
111
-
112
- const slideover = E.slideover({
113
- title: isEdit ? `Edit ${config.label}` : `New ${config.label}`,
114
- size: 'md',
115
- position: 'right',
116
- content: form
117
- });
118
-
119
- saveBtn.addEventListener('click', async () => {
120
- const body = {};
121
- for (const field of config.fields) {
122
- body[field.key] = inputs[field.key].value;
123
- }
124
- if (!body.name?.trim()) {
125
- E.toast('Name is required.', { type: 'error' });
126
- return;
127
- }
128
- try {
129
- const res = isEdit
130
- ? await H.put(`${config.endpoint}/${existing.id}`, body)
131
- : await H.post(config.endpoint, body);
132
- if (res.error) throw new Error(res.error);
133
- slideover.close();
134
- E.toast(isEdit ? 'Saved.' : 'Created.', { type: 'success' });
135
- await reload();
136
- } catch (err) {
137
- E.toast(err?.message ?? 'Save failed.', { type: 'error' });
138
- }
139
- });
140
-
141
- slideover.open();
142
- }
143
-
144
- $container.find('#btn-new').on('click', () => openEditor(null));
145
-
146
- await reload();
147
- Domma.icons.scan();
148
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Invoice plugin - receivers CRUD view.
3
- */
4
- import {mountPartyView} from './party-view.js?v=1';
5
-
6
- export const receiversView = {
7
- templateUrl: '/plugins/invoice/admin/templates/receivers.html',
8
- onMount: ($container) => mountPartyView($container, {
9
- kind: 'receiver',
10
- endpoint: '/api/plugins/invoice/receivers',
11
- label: 'Receiver',
12
- fields: [
13
- { key: 'name', label: 'Contact Name', required: true, type: 'text' },
14
- { key: 'company', label: 'Company', type: 'text' },
15
- { key: 'email', label: 'Email', type: 'text' },
16
- { key: 'phone', label: 'Phone', type: 'text' },
17
- { key: 'vatNumber', label: 'VAT Number', type: 'text' },
18
- { key: 'reference', label: 'Reference', type: 'text' },
19
- { key: 'address', label: 'Address', type: 'textarea' }
20
- ]
21
- })
22
- };