@escalated-dev/escalated 0.7.0 → 0.8.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 (181) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +36 -1
  3. package/package.json +16 -7
  4. package/src/components/ActiveChatsPanel.vue +246 -0
  5. package/src/components/ActivityTimeline.stories.js +55 -55
  6. package/src/components/ActivityTimeline.vue +83 -83
  7. package/src/components/AdminDashboard.stories.js +1423 -1095
  8. package/src/components/AgentLoadIndicator.stories.js +37 -37
  9. package/src/components/AgentLoadIndicator.vue +49 -49
  10. package/src/components/AgentPerformanceCard.vue +44 -44
  11. package/src/components/ArticleEditor.vue +82 -82
  12. package/src/components/AssigneeSelect.vue +37 -37
  13. package/src/components/AttachmentList.vue +13 -1
  14. package/src/components/AuditLogEntry.vue +95 -95
  15. package/src/components/BulkActionBar.vue +166 -166
  16. package/src/components/CategoryTree.vue +89 -89
  17. package/src/components/ChartWidget.vue +46 -46
  18. package/src/components/ChatActionBar.vue +226 -0
  19. package/src/components/ChatBubble.vue +162 -0
  20. package/src/components/ChatComposer.vue +308 -0
  21. package/src/components/ChatQueue.vue +222 -0
  22. package/src/components/ChatThread.vue +197 -0
  23. package/src/components/CollisionWarning.stories.js +30 -30
  24. package/src/components/CollisionWarning.vue +68 -68
  25. package/src/components/ConditionalFieldRules.vue +135 -135
  26. package/src/components/ContextPanel.vue +66 -66
  27. package/src/components/ContextPanelSection.vue +65 -65
  28. package/src/components/CustomFieldRenderer.vue +159 -159
  29. package/src/components/EscalatedLayout.vue +35 -6
  30. package/src/components/FileDropzone.vue +57 -57
  31. package/src/components/FollowButton.stories.js +30 -30
  32. package/src/components/FollowButton.vue +88 -88
  33. package/src/components/KeyboardShortcutHelp.vue +213 -213
  34. package/src/components/KnowledgePanel.vue +122 -122
  35. package/src/components/KpiCard.stories.js +32 -32
  36. package/src/components/KpiCard.vue +88 -88
  37. package/src/components/MacroDropdown.vue +150 -150
  38. package/src/components/MentionDropdown.vue +154 -0
  39. package/src/components/MetricComparison.vue +89 -0
  40. package/src/components/PercentileChart.vue +67 -0
  41. package/src/components/PeriodSelector.vue +98 -0
  42. package/src/components/PermissionMatrix.vue +107 -107
  43. package/src/components/PinnedNotes.vue +129 -129
  44. package/src/components/PluginSlot.vue +68 -62
  45. package/src/components/PresenceIndicator.vue +46 -2
  46. package/src/components/PriorityBadge.stories.js +33 -33
  47. package/src/components/PriorityBadge.vue +46 -46
  48. package/src/components/ReplyComposer.vue +81 -18
  49. package/src/components/ReplyThread.vue +40 -2
  50. package/src/components/ReportChart.vue +395 -0
  51. package/src/components/ReportExportButton.vue +108 -0
  52. package/src/components/SatisfactionRating.vue +180 -180
  53. package/src/components/SaveViewDialog.vue +172 -0
  54. package/src/components/SavedViewSidebar.vue +208 -0
  55. package/src/components/ScheduleEditor.vue +104 -104
  56. package/src/components/SideConversation.vue +165 -165
  57. package/src/components/SideConversationList.vue +147 -147
  58. package/src/components/SkillTagManager.vue +83 -79
  59. package/src/components/SlaComplianceChart.vue +46 -53
  60. package/src/components/SlaTimer.stories.js +35 -35
  61. package/src/components/SlaTimer.vue +62 -62
  62. package/src/components/SnoozeButton.vue +247 -0
  63. package/src/components/StatsCard.stories.js +24 -24
  64. package/src/components/StatsCard.vue +58 -58
  65. package/src/components/StatusBadge.stories.js +53 -53
  66. package/src/components/StatusBadge.vue +78 -78
  67. package/src/components/TagSelect.vue +84 -84
  68. package/src/components/TicketFilters.vue +270 -225
  69. package/src/components/TicketLinkPanel.vue +193 -193
  70. package/src/components/TicketList.vue +655 -594
  71. package/src/components/TicketMergeDialog.vue +157 -157
  72. package/src/components/TicketSplitDialog.vue +98 -0
  73. package/src/components/TotpInput.stories.js +9 -9
  74. package/src/components/TotpInput.vue +81 -81
  75. package/src/components/TwoFactorSetup.vue +113 -113
  76. package/src/components/VariableTokenInput.vue +111 -0
  77. package/src/components/WorkflowActionConfig.vue +287 -0
  78. package/src/components/WorkflowActionList.vue +350 -0
  79. package/src/components/WorkflowConditionBuilder.vue +265 -0
  80. package/src/components/WorkflowTriggerSelector.vue +125 -0
  81. package/src/composables/useChat.js +187 -0
  82. package/src/composables/useI18n.js +30 -8
  83. package/src/composables/useKeyboardShortcuts.js +46 -46
  84. package/src/composables/useMentions.js +134 -0
  85. package/src/composables/usePluginExtensions.js +159 -159
  86. package/src/composables/usePluginHooks.js +65 -65
  87. package/src/composables/useRealtime.js +182 -0
  88. package/src/defineEscalatedPlugin.js +76 -76
  89. package/src/index.js +84 -72
  90. package/src/locales/README.md +13 -0
  91. package/src/locales/ar.json +727 -0
  92. package/src/locales/de.json +678 -430
  93. package/src/locales/en.json +717 -455
  94. package/src/locales/es.json +679 -430
  95. package/src/locales/fr.json +680 -431
  96. package/src/locales/index.js +12 -2
  97. package/src/locales/it.json +727 -0
  98. package/src/locales/ja.json +727 -0
  99. package/src/locales/ko.json +727 -0
  100. package/src/locales/nl.json +727 -0
  101. package/src/locales/pl.json +727 -0
  102. package/src/locales/pt-BR.json +727 -0
  103. package/src/locales/ru.json +727 -0
  104. package/src/locales/tr.json +727 -0
  105. package/src/locales/zh-CN.json +727 -0
  106. package/src/pages/Admin/ApiTokens/Index.vue +381 -381
  107. package/src/pages/Admin/AuditLog/Index.vue +154 -154
  108. package/src/pages/Admin/BusinessHours/Form.vue +172 -172
  109. package/src/pages/Admin/BusinessHours/Index.vue +113 -113
  110. package/src/pages/Admin/CannedResponses/Index.vue +127 -127
  111. package/src/pages/Admin/Capacity/Index.vue +134 -134
  112. package/src/pages/Admin/CustomFields/Form.vue +195 -195
  113. package/src/pages/Admin/CustomFields/Index.vue +134 -134
  114. package/src/pages/Admin/CustomObjects/Form.vue +202 -202
  115. package/src/pages/Admin/CustomObjects/Index.vue +127 -127
  116. package/src/pages/Admin/CustomObjects/Records.vue +228 -228
  117. package/src/pages/Admin/Departments/Form.vue +75 -75
  118. package/src/pages/Admin/Departments/Index.vue +110 -109
  119. package/src/pages/Admin/EscalationRules/Form.vue +157 -157
  120. package/src/pages/Admin/EscalationRules/Index.vue +178 -178
  121. package/src/pages/Admin/Import/Connect.vue +0 -1
  122. package/src/pages/Admin/Import/Index.vue +1 -1
  123. package/src/pages/Admin/Import/Progress.vue +1 -1
  124. package/src/pages/Admin/KnowledgeBase/Articles/Form.vue +142 -142
  125. package/src/pages/Admin/KnowledgeBase/Articles/Index.vue +195 -195
  126. package/src/pages/Admin/KnowledgeBase/Categories/Index.vue +193 -193
  127. package/src/pages/Admin/Macros/Index.vue +448 -448
  128. package/src/pages/Admin/Plugins/Index.vue +327 -327
  129. package/src/pages/Admin/Reports/AgentDetail.vue +132 -0
  130. package/src/pages/Admin/Reports/AgentMetrics.vue +115 -115
  131. package/src/pages/Admin/Reports/AgentRanking.vue +246 -0
  132. package/src/pages/Admin/Reports/Cohorts.vue +180 -0
  133. package/src/pages/Admin/Reports/Comparison.vue +141 -0
  134. package/src/pages/Admin/Reports/CsatReport.vue +127 -127
  135. package/src/pages/Admin/Reports/Dashboard.vue +36 -21
  136. package/src/pages/Admin/Reports/ResolutionTimes.vue +164 -0
  137. package/src/pages/Admin/Reports/ResponseTimes.vue +164 -0
  138. package/src/pages/Admin/Reports/SlaReport.vue +162 -166
  139. package/src/pages/Admin/Reports/SlaTrends.vue +183 -0
  140. package/src/pages/Admin/Reports.vue +206 -206
  141. package/src/pages/Admin/Roles/Form.vue +71 -71
  142. package/src/pages/Admin/Roles/Index.vue +122 -122
  143. package/src/pages/Admin/Settings/CsatSettings.vue +165 -165
  144. package/src/pages/Admin/Settings/DataRetention.vue +182 -182
  145. package/src/pages/Admin/Settings/EmailSettings.vue +243 -243
  146. package/src/pages/Admin/Settings/Sandbox.vue +135 -135
  147. package/src/pages/Admin/Settings/SsoSettings.vue +218 -218
  148. package/src/pages/Admin/Settings/TwoFactor.vue +110 -110
  149. package/src/pages/Admin/Settings.vue +1008 -468
  150. package/src/pages/Admin/Skills/Form.vue +193 -53
  151. package/src/pages/Admin/Skills/Index.vue +105 -94
  152. package/src/pages/Admin/SlaPolicies/Form.vue +118 -118
  153. package/src/pages/Admin/SlaPolicies/Index.vue +121 -120
  154. package/src/pages/Admin/Statuses/Form.vue +114 -114
  155. package/src/pages/Admin/Statuses/Index.vue +153 -153
  156. package/src/pages/Admin/Tags/Index.vue +191 -191
  157. package/src/pages/Admin/Tickets/Index.vue +126 -91
  158. package/src/pages/Admin/Tickets/Show.vue +29 -0
  159. package/src/pages/Admin/Users/Index.vue +145 -0
  160. package/src/pages/Admin/Webhooks/DeliveryLog.vue +120 -120
  161. package/src/pages/Admin/Webhooks/Form.vue +110 -110
  162. package/src/pages/Admin/Webhooks/Index.vue +136 -136
  163. package/src/pages/Admin/Workflows/Builder.vue +207 -0
  164. package/src/pages/Admin/Workflows/Index.vue +235 -0
  165. package/src/pages/Admin/Workflows/Logs.vue +286 -0
  166. package/src/pages/Agent/TicketIndex.vue +112 -88
  167. package/src/pages/Agent/TicketShow.vue +192 -60
  168. package/src/pages/Customer/Create.vue +1 -1
  169. package/src/pages/Customer/Index.vue +26 -1
  170. package/src/pages/Customer/KnowledgeBase/Article.vue +4 -2
  171. package/src/pages/Customer/KnowledgeBase/Index.vue +151 -151
  172. package/src/pages/Customer/Show.vue +69 -63
  173. package/src/pages/Guest/Create.vue +40 -15
  174. package/src/pages/Guest/Show.vue +124 -93
  175. package/src/plugin.js +26 -1
  176. package/src/utils/mentionHighlight.js +24 -0
  177. package/src/utils/sanitizeHtml.js +78 -64
  178. package/src/widget/EscalatedWidget.vue +804 -0
  179. package/src/widget/index.js +254 -0
  180. package/src/pages/Admin/Automations/Form.vue +0 -184
  181. package/src/pages/Admin/Automations/Index.vue +0 -129
@@ -1,93 +1,124 @@
1
- <script setup>
2
- import EscalatedLayout from '../../components/EscalatedLayout.vue';
3
- import StatusBadge from '../../components/StatusBadge.vue';
4
- import PriorityBadge from '../../components/PriorityBadge.vue';
5
- import ReplyThread from '../../components/ReplyThread.vue';
6
- import AttachmentList from '../../components/AttachmentList.vue';
7
- import SatisfactionRating from '../../components/SatisfactionRating.vue';
8
- import { useForm } from '@inertiajs/vue3';
9
- import { ref } from 'vue';
10
-
11
- const props = defineProps({ ticket: Object, token: String });
12
-
13
- const isResolved = ['resolved', 'closed'].includes(props.ticket.status);
14
-
15
- const replyForm = useForm({ body: '', attachments: [] });
16
- const showCopied = ref(false);
17
-
18
- function submitReply() {
19
- replyForm.post(route('escalated.guest.tickets.reply', props.token), {
20
- onSuccess: () => replyForm.reset(),
21
- });
22
- }
23
-
24
- function copyLink() {
25
- navigator.clipboard.writeText(window.location.href);
26
- showCopied.value = true;
27
- setTimeout(() => showCopied.value = false, 2000);
28
- }
29
- </script>
30
-
31
- <template>
32
- <EscalatedLayout :title="ticket.subject">
33
- <div class="mx-auto max-w-3xl">
34
- <!-- Bookmark notice -->
35
- <div class="mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3">
36
- <div class="flex items-start gap-3">
37
- <svg class="mt-0.5 h-5 w-5 shrink-0 text-amber-500" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" /></svg>
38
- <div>
39
- <p class="text-sm font-medium text-amber-800">Bookmark this page</p>
40
- <p class="mt-0.5 text-xs text-amber-600">This is your private link to view and reply to this ticket.</p>
41
- </div>
42
- <button @click="copyLink"
43
- class="ml-auto shrink-0 rounded-md border border-amber-300 bg-white px-2.5 py-1 text-xs font-medium text-amber-700 hover:bg-amber-50">
44
- {{ showCopied ? 'Copied!' : 'Copy Link' }}
45
- </button>
46
- </div>
47
- </div>
48
-
49
- <!-- Ticket header -->
50
- <div class="mb-4 flex flex-wrap items-center gap-3">
51
- <span class="font-mono text-sm text-gray-500">{{ ticket.reference }}</span>
52
- <StatusBadge :status="ticket.status" />
53
- <PriorityBadge :priority="ticket.priority" />
54
- <span v-if="ticket.department" class="text-sm text-gray-500">{{ ticket.department.name }}</span>
55
- </div>
56
-
57
- <!-- CSAT Rating -->
58
- <SatisfactionRating v-if="isResolved && !ticket.satisfaction_rating"
59
- :action="route('escalated.guest.tickets.rate', token)" />
60
-
61
- <!-- Description -->
62
- <div class="mb-6 rounded-lg border border-gray-200 bg-white p-4">
63
- <p class="whitespace-pre-wrap text-sm text-gray-700">{{ ticket.description }}</p>
64
- <AttachmentList v-if="ticket.attachments?.length" :attachments="ticket.attachments" class="mt-3" />
65
- </div>
66
-
67
- <!-- Replies -->
68
- <div class="mb-6">
69
- <h2 class="mb-4 text-lg font-semibold text-gray-900">Replies</h2>
70
- <ReplyThread :replies="ticket.replies || []" />
71
- </div>
72
-
73
- <!-- Reply form -->
74
- <div v-if="ticket.status !== 'closed'" class="rounded-lg border border-gray-200 bg-white p-4">
75
- <h2 class="mb-4 text-lg font-semibold text-gray-900">Reply</h2>
76
- <form @submit.prevent="submitReply">
77
- <textarea v-model="replyForm.body" rows="4" required placeholder="Write your reply..."
78
- class="w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"></textarea>
79
- <div v-if="replyForm.errors.body" class="mt-1 text-sm text-red-600">{{ replyForm.errors.body }}</div>
80
- <div class="mt-3 flex justify-end">
81
- <button type="submit" :disabled="replyForm.processing"
82
- class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-50">
83
- {{ replyForm.processing ? 'Sending...' : 'Send Reply' }}
84
- </button>
85
- </div>
86
- </form>
87
- </div>
88
- <div v-else class="rounded-lg border border-gray-200 bg-gray-50 px-4 py-6 text-center text-sm text-gray-500">
89
- This ticket is closed. No further replies can be added.
90
- </div>
91
- </div>
92
- </EscalatedLayout>
93
- </template>
1
+ <script setup>
2
+ import EscalatedLayout from '../../components/EscalatedLayout.vue';
3
+ import StatusBadge from '../../components/StatusBadge.vue';
4
+ import PriorityBadge from '../../components/PriorityBadge.vue';
5
+ import ReplyThread from '../../components/ReplyThread.vue';
6
+ import AttachmentList from '../../components/AttachmentList.vue';
7
+ import SatisfactionRating from '../../components/SatisfactionRating.vue';
8
+ import { useForm } from '@inertiajs/vue3';
9
+ import { ref } from 'vue';
10
+
11
+ const props = defineProps({ ticket: Object, token: String });
12
+
13
+ const isResolved = ['resolved', 'closed'].includes(props.ticket.status);
14
+
15
+ const replyForm = useForm({ body: '', attachments: [] });
16
+ const showCopied = ref(false);
17
+
18
+ function submitReply() {
19
+ replyForm.post(route('escalated.guest.tickets.reply', props.token), {
20
+ onSuccess: () => replyForm.reset(),
21
+ });
22
+ }
23
+
24
+ function copyLink() {
25
+ navigator.clipboard.writeText(window.location.href);
26
+ showCopied.value = true;
27
+ setTimeout(() => (showCopied.value = false), 2000);
28
+ }
29
+ </script>
30
+
31
+ <template>
32
+ <EscalatedLayout :title="ticket.subject">
33
+ <div class="mx-auto max-w-3xl">
34
+ <!-- Bookmark notice -->
35
+ <div class="mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3">
36
+ <div class="flex items-start gap-3">
37
+ <svg
38
+ class="mt-0.5 h-5 w-5 shrink-0 text-amber-500"
39
+ fill="none"
40
+ stroke="currentColor"
41
+ stroke-width="1.5"
42
+ viewBox="0 0 24 24"
43
+ >
44
+ <path
45
+ stroke-linecap="round"
46
+ stroke-linejoin="round"
47
+ d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"
48
+ />
49
+ </svg>
50
+ <div>
51
+ <p class="text-sm font-medium text-amber-800">Bookmark this page</p>
52
+ <p class="mt-0.5 text-xs text-amber-600">
53
+ This is your private link to view and reply to this ticket.
54
+ </p>
55
+ </div>
56
+ <button
57
+ class="ml-auto shrink-0 rounded-md border border-amber-300 bg-white px-2.5 py-1 text-xs font-medium text-amber-700 hover:bg-amber-50"
58
+ @click="copyLink"
59
+ >
60
+ {{ showCopied ? 'Copied!' : 'Copy Link' }}
61
+ </button>
62
+ </div>
63
+ </div>
64
+
65
+ <!-- Ticket header -->
66
+ <div class="mb-4 flex flex-wrap items-center gap-3">
67
+ <span class="font-mono text-sm text-gray-500">{{ ticket.reference }}</span>
68
+ <StatusBadge :status="ticket.status" />
69
+ <PriorityBadge :priority="ticket.priority" />
70
+ <span v-if="ticket.department" class="text-sm text-gray-500">{{ ticket.department.name }}</span>
71
+ </div>
72
+
73
+ <!-- CSAT Rating -->
74
+ <SatisfactionRating
75
+ v-if="isResolved && !ticket.satisfaction_rating"
76
+ :action="route('escalated.guest.tickets.rate', token)"
77
+ />
78
+
79
+ <!-- Description -->
80
+ <div class="mb-6 rounded-lg border border-gray-200 bg-white p-4">
81
+ <p class="whitespace-pre-wrap text-sm text-gray-700">{{ ticket.description }}</p>
82
+ <AttachmentList v-if="ticket.attachments?.length" :attachments="ticket.attachments" class="mt-3" />
83
+ </div>
84
+
85
+ <!-- Replies -->
86
+ <div class="mb-6">
87
+ <h2 class="mb-4 text-lg font-semibold text-gray-900">Replies</h2>
88
+ <ReplyThread :replies="ticket.replies || []" />
89
+ </div>
90
+
91
+ <!-- Reply form -->
92
+ <div v-if="ticket.status !== 'closed'" class="rounded-lg border border-gray-200 bg-white p-4">
93
+ <h2 class="mb-4 text-lg font-semibold text-gray-900">Reply</h2>
94
+ <form @submit.prevent="submitReply">
95
+ <textarea
96
+ v-model="replyForm.body"
97
+ rows="4"
98
+ required
99
+ placeholder="Write your reply..."
100
+ class="w-full rounded-lg border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
101
+ ></textarea>
102
+ <div v-if="replyForm.errors.body" class="mt-1 text-sm text-red-600">
103
+ {{ replyForm.errors.body }}
104
+ </div>
105
+ <div class="mt-3 flex justify-end">
106
+ <button
107
+ type="submit"
108
+ :disabled="replyForm.processing"
109
+ class="rounded-lg bg-indigo-600 px-4 py-2 text-sm font-medium text-white hover:bg-indigo-700 disabled:opacity-50"
110
+ >
111
+ {{ replyForm.processing ? 'Sending...' : 'Send Reply' }}
112
+ </button>
113
+ </div>
114
+ </form>
115
+ </div>
116
+ <div
117
+ v-else
118
+ class="rounded-lg border border-gray-200 bg-gray-50 px-4 py-6 text-center text-sm text-gray-500"
119
+ >
120
+ This ticket is closed. No further replies can be added.
121
+ </div>
122
+ </div>
123
+ </EscalatedLayout>
124
+ </template>
package/src/plugin.js CHANGED
@@ -17,6 +17,8 @@ import { markRaw } from 'vue';
17
17
  */
18
18
  export const EscalatedPlugin = {
19
19
  install(app, options = {}) {
20
+ installRouteShim();
21
+
20
22
  if (options.layout) {
21
23
  app.provide('escalated-layout', markRaw(options.layout));
22
24
  }
@@ -38,6 +40,29 @@ export const EscalatedPlugin = {
38
40
  },
39
41
  };
40
42
 
43
+ // 77 components in this package call the Ziggy `route()` helper (Laravel's
44
+ // named-route URL generator). Laravel hosts ship Ziggy and get `window.route`
45
+ // for free; other host frameworks (Rails, Django, NestJS, Phoenix, Symfony,
46
+ // Adonis, Go, .NET, Spring, WordPress) don't, and the call sites would
47
+ // otherwise throw a bare ReferenceError deep inside a component render with
48
+ // no hint at the cause.
49
+ //
50
+ // Install a stub that throws an informative error instead, so the host app's
51
+ // first failing request points at the actual missing dependency. Laravel hosts
52
+ // that already have Ziggy loaded are left alone.
53
+ function installRouteShim() {
54
+ if (typeof window === 'undefined') return;
55
+ if (typeof window.route === 'function') return;
56
+
57
+ window.route = function escalatedRouteShimMissing(name) {
58
+ throw new Error(
59
+ `[escalated] window.route('${name}') called, but no \`route()\` helper is installed on this host. ` +
60
+ `The escalated agent/admin UI depends on Laravel's Ziggy-style \`route(name, params)\` helper. ` +
61
+ `Install Ziggy (on Laravel hosts) or register a compatible shim on window.route before mounting the app.`,
62
+ );
63
+ };
64
+ }
65
+
41
66
  const themeDefaults = {
42
67
  primary: '#4f46e5',
43
68
  primaryHover: null,
@@ -69,7 +94,7 @@ function darken(hex, percent) {
69
94
  }
70
95
 
71
96
  function scaleBorderRadius(radius, factor) {
72
- const match = radius.match(/^([\d.]+)(.*)$/);
97
+ const match = radius.match(/^(\d+(?:\.\d+)?|\.\d+)([a-z%]*)$/i);
73
98
  if (!match) return radius;
74
99
  return `${(parseFloat(match[1]) * factor).toFixed(2)}${match[2] || 'rem'}`;
75
100
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * HTML-encode a string to prevent injection via mention names.
3
+ */
4
+ function escapeHtml(str) {
5
+ return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
6
+ }
7
+
8
+ /**
9
+ * Replace @{Name} patterns in text with styled mention badges.
10
+ *
11
+ * @param {string} html - The HTML or text content
12
+ * @param {boolean} dark - Whether dark mode is active
13
+ * @returns {string} HTML with mentions wrapped in styled spans
14
+ */
15
+ export function highlightMentions(html, dark = false) {
16
+ if (!html) return '';
17
+
18
+ const pillClass = dark
19
+ ? 'inline-flex items-center rounded-full bg-cyan-500/15 px-1.5 py-0.5 text-xs font-medium text-cyan-400 ring-1 ring-cyan-500/20'
20
+ : 'inline-flex items-center rounded-full bg-blue-100 px-1.5 py-0.5 text-xs font-medium text-blue-700 ring-1 ring-blue-200';
21
+
22
+ // Replace @{Name} with styled pill, encoding the name to prevent injection
23
+ return html.replace(/@\{([^}]+)\}/g, (match, name) => `<span class="${pillClass}">@${escapeHtml(name)}</span>`);
24
+ }
@@ -1,64 +1,78 @@
1
- /**
2
- * Sanitize HTML to prevent stored XSS.
3
- *
4
- * Uses the DOM parser to walk the tree and strip dangerous elements and
5
- * attributes rather than regex, which avoids incomplete-sanitization pitfalls.
6
- */
7
-
8
- const DANGEROUS_TAGS = new Set([
9
- 'script', 'style', 'iframe', 'object', 'embed', 'form', 'input',
10
- 'textarea', 'button', 'select', 'option', 'link', 'meta', 'base',
11
- 'applet', 'noscript', 'noframes',
12
- ])
13
-
14
- const URI_ATTRS = new Set(['href', 'src', 'action', 'formaction', 'xlink:href'])
15
-
16
- export function sanitizeHtml(html) {
17
- if (!html) return ''
18
-
19
- const doc = new DOMParser().parseFromString(html, 'text/html')
20
-
21
- // Remove dangerous elements
22
- for (const tag of DANGEROUS_TAGS) {
23
- const els = doc.body.getElementsByTagName(tag)
24
- while (els.length) els[0].remove()
25
- }
26
-
27
- // Walk all remaining elements and strip dangerous attributes
28
- const all = doc.body.querySelectorAll('*')
29
- for (let i = 0; i < all.length; i++) {
30
- const el = all[i]
31
- const attrs = [...el.attributes]
32
- for (let j = 0; j < attrs.length; j++) {
33
- const name = attrs[j].name.toLowerCase()
34
-
35
- // Remove event handlers (onclick, onerror, etc.)
36
- if (name.startsWith('on')) {
37
- el.removeAttribute(attrs[j].name)
38
- continue
39
- }
40
-
41
- // Remove javascript: / vbscript: / dangerous data: URIs
42
- if (URI_ATTRS.has(name)) {
43
- const val = (attrs[j].value || '').replace(/[\s\u0000-\u001F]+/g, '').toLowerCase()
44
- if (
45
- val.startsWith('javascript:') ||
46
- val.startsWith('vbscript:') ||
47
- (val.startsWith('data:') && !val.startsWith('data:image/'))
48
- ) {
49
- el.removeAttribute(attrs[j].name)
50
- }
51
- }
52
-
53
- // Remove style attributes containing expressions or javascript
54
- if (name === 'style') {
55
- const val = (attrs[j].value || '').toLowerCase()
56
- if (val.includes('expression(') || val.includes('javascript:') || val.includes('url(')) {
57
- el.removeAttribute(attrs[j].name)
58
- }
59
- }
60
- }
61
- }
62
-
63
- return doc.body.innerHTML
64
- }
1
+ /**
2
+ * Sanitize HTML to prevent stored XSS.
3
+ *
4
+ * Uses the DOM parser to walk the tree and strip dangerous elements and
5
+ * attributes rather than regex, which avoids incomplete-sanitization pitfalls.
6
+ */
7
+
8
+ const DANGEROUS_TAGS = new Set([
9
+ 'script',
10
+ 'style',
11
+ 'iframe',
12
+ 'object',
13
+ 'embed',
14
+ 'form',
15
+ 'input',
16
+ 'textarea',
17
+ 'button',
18
+ 'select',
19
+ 'option',
20
+ 'link',
21
+ 'meta',
22
+ 'base',
23
+ 'applet',
24
+ 'noscript',
25
+ 'noframes',
26
+ ]);
27
+
28
+ const URI_ATTRS = new Set(['href', 'src', 'action', 'formaction', 'xlink:href']);
29
+
30
+ export function sanitizeHtml(html) {
31
+ if (!html) return '';
32
+
33
+ const doc = new DOMParser().parseFromString(html, 'text/html');
34
+
35
+ // Remove dangerous elements
36
+ for (const tag of DANGEROUS_TAGS) {
37
+ const els = doc.body.getElementsByTagName(tag);
38
+ while (els.length) els[0].remove();
39
+ }
40
+
41
+ // Walk all remaining elements and strip dangerous attributes
42
+ const all = doc.body.querySelectorAll('*');
43
+ for (let i = 0; i < all.length; i++) {
44
+ const el = all[i];
45
+ const attrs = [...el.attributes];
46
+ for (let j = 0; j < attrs.length; j++) {
47
+ const name = attrs[j].name.toLowerCase();
48
+
49
+ // Remove event handlers (onclick, onerror, etc.)
50
+ if (name.startsWith('on')) {
51
+ el.removeAttribute(attrs[j].name);
52
+ continue;
53
+ }
54
+
55
+ // Remove javascript: / vbscript: / dangerous data: URIs
56
+ if (URI_ATTRS.has(name)) {
57
+ const val = (attrs[j].value || '').replace(/[\s\u0000-\u001F]+/g, '').toLowerCase();
58
+ if (
59
+ val.startsWith('javascript:') ||
60
+ val.startsWith('vbscript:') ||
61
+ (val.startsWith('data:') && !val.startsWith('data:image/'))
62
+ ) {
63
+ el.removeAttribute(attrs[j].name);
64
+ }
65
+ }
66
+
67
+ // Remove style attributes containing expressions or javascript
68
+ if (name === 'style') {
69
+ const val = (attrs[j].value || '').toLowerCase();
70
+ if (val.includes('expression(') || val.includes('javascript:') || val.includes('url(')) {
71
+ el.removeAttribute(attrs[j].name);
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ return doc.body.innerHTML;
78
+ }