icex-dsh-fixer 0.2.5 → 0.2.7

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 (3) hide show
  1. package/client.js +64 -0
  2. package/index.js +10 -8
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -777,6 +777,10 @@ window.__ModuleLoader__.load({
777
777
  'rail.jump': 'Jump to input {index}: {prompt}',
778
778
  'rail.input': 'Input {index}',
779
779
  'rail.fallback': 'Turn {turn}',
780
+ 'menu.deleteSession': 'Delete session',
781
+ 'menu.deleting': 'Deleting…',
782
+ 'menu.deleteConfirm': 'Delete this session? Its log moves to the trash folder.',
783
+ 'menu.deleteFailed': 'Delete failed: {message}',
780
784
  }
781
785
 
782
786
  const zh = {
@@ -798,6 +802,10 @@ window.__ModuleLoader__.load({
798
802
  'rail.label': '输入锚点',
799
803
  'rail.jump': '跳转到第 {index} 条输入:{prompt}',
800
804
  'rail.input': '第 {index} 条输入',
805
+ 'menu.deleteSession': '删除会话',
806
+ 'menu.deleting': '删除中…',
807
+ 'menu.deleteConfirm': '删除这个会话?日志会移到回收站目录,可以再捞回来。',
808
+ 'menu.deleteFailed': '删除失败:{message}',
801
809
  'rail.fallback': '第 {turn} 轮',
802
810
  }
803
811
 
@@ -841,6 +849,10 @@ window.__ModuleLoader__.load({
841
849
  '.icex-tip-head { margin-bottom: 2px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }',
842
850
  '.icex-tip-text { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 18px; }',
843
851
  'html[data-icex-fixer-hide-native-rail][data-icex-fixer-rail-mounted] [data-conversation-content] nav[aria-label] { display: none !important; }',
852
+ '.icex-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0; padding: 6px 8px; border: 0; border-radius: var(--dsw-radius-md); background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; line-height: 18px; text-align: left; cursor: default; }',
853
+ '.icex-menu-item:hover, .icex-menu-item:focus-visible { background: var(--dsw-alias-bg-layer-1); outline: none; box-shadow: inset 0 0 0 1px var(--dsw-alias-border-l1); }',
854
+ '.icex-menu-item:disabled { opacity: 0.6; }',
855
+ '.icex-menu-danger { color: var(--dsw-alias-state-error-primary, #d5484b); }',
844
856
  '@media (prefers-reduced-motion: reduce) { .icex-rail-dot { transition: none; } .icex-rail-btn[data-busy] .icex-rail-dot { animation: none; } }',
845
857
  ]
846
858
 
@@ -867,6 +879,50 @@ window.__ModuleLoader__.load({
867
879
  )
868
880
  }
869
881
 
882
+ /**
883
+ * Session row menu item: delete one session by moving its log to the trash.
884
+ * The slot hands over the session id (as a string or a props object).
885
+ */
886
+ function DeleteSessionItem(props) {
887
+ const t = translator(props !== null && typeof props === 'object' ? props.t : undefined)
888
+ const sessionId = typeof props === 'string'
889
+ ? props
890
+ : props !== null && typeof props === 'object'
891
+ ? props.sessionId ?? props.id ?? props.value
892
+ : undefined
893
+ const busyState = useState(false)
894
+ const busy = busyState[0]
895
+ if (typeof sessionId !== 'string' || sessionId === '') return null
896
+
897
+ function remove() {
898
+ if (typeof window === 'undefined') return
899
+ if (window.confirm(t('menu.deleteConfirm')) !== true) return
900
+ busyState[1](true)
901
+ fetch('/api/icex-fixer/delete-session', {
902
+ method: 'POST',
903
+ credentials: 'same-origin',
904
+ headers: { 'content-type': 'application/json' },
905
+ body: JSON.stringify({ id: sessionId }),
906
+ }).then(function (response) {
907
+ return response.json().then(function (body) {
908
+ if (body.ok !== true) throw new Error(body.error ?? String(response.status))
909
+ window.location.reload()
910
+ })
911
+ }).catch(function (error) {
912
+ busyState[1](false)
913
+ window.alert(t('menu.deleteFailed', { message: String(error.message ?? error) }))
914
+ })
915
+ }
916
+
917
+ return h('button', {
918
+ type: 'button',
919
+ role: 'menuitem',
920
+ disabled: busy,
921
+ className: 'icex-menu-item icex-menu-danger',
922
+ onClick: remove,
923
+ }, busy ? t('menu.deleting') : t('menu.deleteSession'))
924
+ }
925
+
870
926
  function apply(ctx) {
871
927
  runtimeContext = ctx
872
928
  ctx.effect(installStyles, 'icex-dsh-fixer: styles')
@@ -899,6 +955,14 @@ window.__ModuleLoader__.load({
899
955
  locale: NS,
900
956
  }, SettingsPage)
901
957
  })
958
+ ctx.slots.inject('sidebar.workspaces.session.menu.item', function () {
959
+ return ctx.slots.register({
960
+ name: 'sidebar.workspaces.session.menu.item',
961
+ id: 'icex-fixer-delete-session',
962
+ order: 900,
963
+ locale: NS,
964
+ }, DeleteSessionItem)
965
+ })
902
966
  }
903
967
 
904
968
  const plugin = {
package/index.js CHANGED
@@ -118,12 +118,14 @@ async function handleDeleteSession(request) {
118
118
 
119
119
  /** Claim the session-delete route when this host carries a browser connection. */
120
120
  function registerSessionDeleteRoute(ctx) {
121
- const connection = ctx.get('connection')
122
- if (connection === undefined || connection.fetch === undefined || typeof connection.fetch.register !== 'function') return
123
- ctx.effect(() => connection.fetch.register({
124
- path: '/api/icex-fixer/delete-session',
125
- methods: ['POST'],
126
- requestBody: 'buffered',
127
- fetch: (request) => handleDeleteSession(request),
128
- }), 'icex-dsh-fixer: session delete route')
121
+ ctx.inject(['connection'], (scope) => {
122
+ const connection = scope.connection
123
+ if (connection === undefined || connection.fetch === undefined || typeof connection.fetch.register !== 'function') return
124
+ scope.effect(() => connection.fetch.register({
125
+ path: '/api/icex-fixer/delete-session',
126
+ methods: ['POST'],
127
+ requestBody: 'buffered',
128
+ fetch: (request) => handleDeleteSession(request),
129
+ }), 'icex-dsh-fixer: session delete route')
130
+ })
129
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icex-dsh-fixer",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Adjust the conversation width, navigate user inputs from a left anchor rail, and summon the window with a right-Option double tap.",
5
5
  "type": "module",
6
6
  "exports": {