@hachej/boring-workspace 0.1.23 → 0.1.24

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.
@@ -1,76 +1,76 @@
1
- import { jsx as i, jsxs as B } from "react/jsx-runtime";
2
- import { useRef as T, useEffect as I, useMemo as R, useCallback as x, createContext as C, useContext as _ } from "react";
3
- import { Tree as q } from "react-arborist";
4
- import { FolderOpenIcon as z, FolderIcon as S, ChevronRightIcon as J, Loader2Icon as K } from "lucide-react";
5
- import { I as Q } from "./WorkspaceProvider-Cn0sPgaB.js";
6
- import { Input as U } from "@hachej/boring-ui-kit";
7
- import { c as v } from "./utils-B6yFEsav.js";
8
- import { createDragDropManager as X } from "dnd-core";
9
- import { HTML5Backend as Y } from "react-dnd-html5-backend";
10
- const k = Symbol.for("@hachej/boring-workspace/file-tree-dnd-manager");
11
- function Z() {
1
+ import { jsx as u, jsxs as C } from "react/jsx-runtime";
2
+ import { useRef as I, useEffect as y, useMemo as A, useCallback as k, createContext as _, useContext as z } from "react";
3
+ import { Tree as K } from "react-arborist";
4
+ import { FolderOpenIcon as S, FolderIcon as J, ChevronRightIcon as Q, Loader2Icon as U } from "lucide-react";
5
+ import { K as X } from "./WorkspaceProvider-BW4wzbpR.js";
6
+ import { Input as Y } from "@hachej/boring-ui-kit";
7
+ import { c as x } from "./utils-B6yFEsav.js";
8
+ import { createDragDropManager as Z } from "dnd-core";
9
+ import { HTML5Backend as $ } from "react-dnd-html5-backend";
10
+ const F = Symbol.for("@hachej/boring-workspace/file-tree-dnd-manager");
11
+ function E() {
12
12
  const r = globalThis;
13
- return r[k] ?? (r[k] = X(
14
- Y,
13
+ return r[F] ?? (r[F] = Z(
14
+ $,
15
15
  typeof window > "u" ? void 0 : window
16
- )), r[k];
16
+ )), r[F];
17
17
  }
18
- const y = /* @__PURE__ */ new Set(), D = C({
18
+ const M = /* @__PURE__ */ new Set(), P = _({
19
19
  onContextMenu: void 0,
20
20
  editing: null,
21
- pendingPaths: y,
21
+ pendingPaths: M,
22
22
  onSubmitEdit: void 0,
23
23
  onCancelEdit: void 0
24
24
  });
25
- function $({
25
+ function G({
26
26
  initialValue: r,
27
27
  onSubmit: p,
28
28
  onCancel: h,
29
- isDraft: c
29
+ isDraft: f
30
30
  }) {
31
- const t = T(null), u = T(!1);
32
- I(() => {
31
+ const t = I(null), i = I(!1);
32
+ y(() => {
33
33
  const e = t.current;
34
34
  if (e)
35
- if (e.focus(), !c && r.includes(".")) {
35
+ if (e.focus(), !f && r.includes(".")) {
36
36
  const o = r.lastIndexOf(".");
37
37
  e.setSelectionRange(0, o);
38
38
  } else
39
39
  e.select();
40
- }, [r, c]);
40
+ }, [r, f]);
41
41
  const d = () => {
42
42
  var o;
43
- if (u.current) return;
44
- u.current = !0;
43
+ if (i.current) return;
44
+ i.current = !0;
45
45
  const e = ((o = t.current) == null ? void 0 : o.value.trim()) ?? "";
46
46
  !e || e === r ? h() : p(e);
47
47
  };
48
- return /* @__PURE__ */ i(
49
- U,
48
+ return /* @__PURE__ */ u(
49
+ Y,
50
50
  {
51
51
  ref: t,
52
52
  type: "text",
53
53
  defaultValue: r,
54
54
  "data-testid": "file-tree-edit-input",
55
- "aria-label": c ? "Name" : "Rename",
55
+ "aria-label": f ? "Name" : "Rename",
56
56
  onPointerDown: (e) => e.stopPropagation(),
57
57
  onClick: (e) => e.stopPropagation(),
58
58
  onKeyDown: (e) => {
59
- e.stopPropagation(), e.key === "Enter" ? (e.preventDefault(), d()) : e.key === "Escape" && (e.preventDefault(), u.current = !0, h());
59
+ e.stopPropagation(), e.key === "Enter" ? (e.preventDefault(), d()) : e.key === "Escape" && (e.preventDefault(), i.current = !0, h());
60
60
  },
61
61
  onBlur: d,
62
62
  className: "h-5 min-w-0 flex-1 rounded-sm border-[color:var(--accent)]/60 px-1 text-[13px] leading-[1.2] focus-visible:ring-[color:var(--accent)]"
63
63
  }
64
64
  );
65
65
  }
66
- function E({ node: r, style: p, dragHandle: h }) {
67
- const { onContextMenu: c, editing: t, pendingPaths: u, onSubmitEdit: d, onCancelEdit: e } = _(D), o = r.data, f = o.kind === "dir", l = (t == null ? void 0 : t.path) === o.path, g = u.has(o.path), b = f ? r.isOpen ? z : S : Q(o.name || "untitled");
68
- return /* @__PURE__ */ B(
66
+ function H({ node: r, style: p, dragHandle: h }) {
67
+ const { onContextMenu: f, editing: t, pendingPaths: i, onSubmitEdit: d, onCancelEdit: e } = z(P), o = r.data, m = o.kind === "dir", l = (t == null ? void 0 : t.path) === o.path, b = i.has(o.path), w = m ? r.isOpen ? S : J : X(o.name || "untitled");
68
+ return /* @__PURE__ */ C(
69
69
  "div",
70
70
  {
71
71
  ref: h,
72
72
  style: p,
73
- className: v(
73
+ className: x(
74
74
  "group relative mx-1 flex items-center gap-1.5 rounded-md px-2 py-0.5 text-[13px] leading-[1.4] cursor-pointer select-none text-foreground",
75
75
  "transition-colors duration-150 ease-[cubic-bezier(0.22,1,0.36,1)]",
76
76
  !l && "hover:bg-foreground/[0.04]",
@@ -78,52 +78,52 @@ function E({ node: r, style: p, dragHandle: h }) {
78
78
  r.willReceiveDrop && "bg-foreground/5 outline outline-1 outline-border"
79
79
  ),
80
80
  onClick: (s) => {
81
- l || (s.stopPropagation(), f ? r.toggle() : (r.select(), r.activate()));
81
+ l || (s.stopPropagation(), m ? r.toggle() : (r.select(), r.activate()));
82
82
  },
83
83
  onContextMenu: (s) => {
84
- l || o.isDraft || (s.preventDefault(), s.stopPropagation(), c == null || c(s, o));
84
+ l || o.isDraft || (s.preventDefault(), s.stopPropagation(), f == null || f(s, o));
85
85
  },
86
86
  children: [
87
- f ? /* @__PURE__ */ i(
88
- J,
87
+ m ? /* @__PURE__ */ u(
88
+ Q,
89
89
  {
90
- className: v(
90
+ className: x(
91
91
  "h-3 w-3 shrink-0 text-muted-foreground/70 transition-transform duration-150 ease-[cubic-bezier(0.22,1,0.36,1)]",
92
92
  r.isOpen && "rotate-90"
93
93
  ),
94
94
  strokeWidth: 2
95
95
  }
96
- ) : /* @__PURE__ */ i("span", { className: "w-3 shrink-0" }),
97
- /* @__PURE__ */ i(
98
- b,
96
+ ) : /* @__PURE__ */ u("span", { className: "w-3 shrink-0" }),
97
+ /* @__PURE__ */ u(
98
+ w,
99
99
  {
100
- className: v(
100
+ className: x(
101
101
  "h-4 w-4 shrink-0",
102
102
  r.isSelected ? "text-[color:var(--accent)]" : "text-muted-foreground/80"
103
103
  ),
104
104
  strokeWidth: 1.5
105
105
  }
106
106
  ),
107
- l ? /* @__PURE__ */ i(
108
- $,
107
+ l ? /* @__PURE__ */ u(
108
+ G,
109
109
  {
110
110
  initialValue: (t == null ? void 0 : t.initialValue) ?? o.name ?? "",
111
111
  isDraft: !!(t != null && t.isDraft),
112
112
  onSubmit: (s) => d == null ? void 0 : d(o.path, s),
113
113
  onCancel: () => e == null ? void 0 : e()
114
114
  }
115
- ) : /* @__PURE__ */ i(
115
+ ) : /* @__PURE__ */ u(
116
116
  "span",
117
117
  {
118
- className: v(
118
+ className: x(
119
119
  "truncate",
120
- g && "text-muted-foreground italic"
120
+ b && "text-muted-foreground italic"
121
121
  ),
122
122
  children: o.name
123
123
  }
124
124
  ),
125
- g && !l && /* @__PURE__ */ i(
126
- K,
125
+ b && !l && /* @__PURE__ */ u(
126
+ U,
127
127
  {
128
128
  "data-testid": "file-tree-pending-spinner",
129
129
  "aria-label": "Pending",
@@ -135,67 +135,77 @@ function E({ node: r, style: p, dragHandle: h }) {
135
135
  }
136
136
  );
137
137
  }
138
- function ie({
138
+ function ce({
139
139
  files: r,
140
140
  selectedPath: p,
141
141
  searchQuery: h,
142
- height: c = 400,
142
+ height: f = 400,
143
143
  editing: t,
144
- revealPath: u,
144
+ revealPath: i,
145
145
  pendingPaths: d,
146
146
  onSelect: e,
147
147
  onExpand: o,
148
- onCollapse: f,
148
+ onCollapse: m,
149
149
  onContextMenu: l,
150
- onSubmitEdit: g,
151
- onCancelEdit: b,
152
- onDragDrop: s,
153
- className: P
150
+ onSubmitEdit: b,
151
+ onCancelEdit: w,
152
+ onRevealHandled: s,
153
+ onDragDrop: T,
154
+ className: D
154
155
  }) {
155
- const N = T(null);
156
- I(() => {
156
+ const v = I(null);
157
+ y(() => {
157
158
  if (!(t != null && t.isDraft)) return;
158
159
  const n = requestAnimationFrame(() => {
159
160
  var a;
160
- (a = N.current) == null || a.scrollTo(t.path);
161
+ (a = v.current) == null || a.scrollTo(t.path);
161
162
  });
162
163
  return () => cancelAnimationFrame(n);
163
- }, [t == null ? void 0 : t.isDraft, t == null ? void 0 : t.path]), I(() => {
164
- if (!u) return;
165
- const n = requestAnimationFrame(() => {
166
- var a;
167
- (a = N.current) == null || a.scrollTo(u);
164
+ }, [t == null ? void 0 : t.isDraft, t == null ? void 0 : t.path]), y(() => {
165
+ if (!i) return;
166
+ let n = 0;
167
+ const a = requestAnimationFrame(() => {
168
+ const c = v.current;
169
+ if (!c) return;
170
+ c.openParents(i);
171
+ const N = c.get(i);
172
+ N && (N.isInternal && N.open(), n = requestAnimationFrame(() => {
173
+ var g;
174
+ (g = v.current) == null || g.scrollTo(i), s == null || s(i);
175
+ }));
168
176
  });
169
- return () => cancelAnimationFrame(n);
170
- }, [r, u]);
171
- const F = R(
177
+ return () => {
178
+ cancelAnimationFrame(a), cancelAnimationFrame(n);
179
+ };
180
+ }, [r, s, i]);
181
+ const O = A(
172
182
  () => p || void 0,
173
183
  [p]
174
- ), M = x(
184
+ ), R = k(
175
185
  (n) => {
176
186
  n.data.kind === "file" && (e == null || e(n.data.path));
177
187
  },
178
188
  [e]
179
- ), A = x(
189
+ ), W = k(
180
190
  (n) => {
181
- var m;
182
- const a = (m = N.current) == null ? void 0 : m.get(n);
183
- a && (a.isOpen ? o == null || o(a.data.path) : f == null || f(a.data.path));
191
+ var c;
192
+ const a = (c = v.current) == null ? void 0 : c.get(n);
193
+ a && (a.isOpen ? o == null || o(a.data.path) : m == null || m(a.data.path));
184
194
  },
185
- [o, f]
186
- ), O = x(
195
+ [o, m]
196
+ ), j = k(
187
197
  (n) => {
188
- if (!s) return;
189
- const a = !n.parentNode || n.parentNode.isRoot, m = a ? "." : n.parentNode.data.path;
198
+ if (!T) return;
199
+ const a = !n.parentNode || n.parentNode.isRoot, c = a ? "." : n.parentNode.data.path;
190
200
  if (!(!a && n.parentNode.data.kind !== "dir"))
191
- for (const L of n.dragNodes) {
192
- const w = L.data.path;
193
- if (m === w || m !== "." && m.startsWith(w + "/")) return;
194
- s(w, m);
201
+ for (const N of n.dragNodes) {
202
+ const g = N.data.path;
203
+ if (c === g || c !== "." && c.startsWith(g + "/")) return;
204
+ T(g, c);
195
205
  }
196
206
  },
197
- [s]
198
- ), W = x(
207
+ [T]
208
+ ), L = k(
199
209
  (n) => {
200
210
  if (!n.parentNode || n.parentNode.isRoot) return !1;
201
211
  if (n.parentNode.data.kind !== "dir") return !0;
@@ -204,53 +214,53 @@ function ie({
204
214
  return !1;
205
215
  },
206
216
  []
207
- ), j = x(
217
+ ), q = k(
208
218
  (n, a) => n.data.name.toLowerCase().includes(a.toLowerCase()),
209
219
  []
210
- ), H = R(
220
+ ), B = A(
211
221
  () => ({
212
222
  onContextMenu: l,
213
223
  editing: t ?? null,
214
- pendingPaths: d ?? y,
215
- onSubmitEdit: g,
216
- onCancelEdit: b
224
+ pendingPaths: d ?? M,
225
+ onSubmitEdit: b,
226
+ onCancelEdit: w
217
227
  }),
218
- [l, t, d, g, b]
228
+ [l, t, d, b, w]
219
229
  );
220
- return r.length === 0 ? /* @__PURE__ */ i(
230
+ return r.length === 0 ? /* @__PURE__ */ u(
221
231
  "div",
222
232
  {
223
- className: v(
233
+ className: x(
224
234
  "flex h-full items-center justify-center text-sm text-muted-foreground",
225
- P
235
+ D
226
236
  ),
227
237
  children: "No files"
228
238
  }
229
- ) : /* @__PURE__ */ i(D.Provider, { value: H, children: /* @__PURE__ */ i("div", { "data-boring-workspace-part": "file-tree", className: v("file-tree", P), children: /* @__PURE__ */ i(
230
- q,
239
+ ) : /* @__PURE__ */ u(P.Provider, { value: B, children: /* @__PURE__ */ u("div", { "data-boring-workspace-part": "file-tree", className: x("file-tree", D), children: /* @__PURE__ */ u(
240
+ K,
231
241
  {
232
- ref: N,
242
+ ref: v,
233
243
  data: r,
234
244
  idAccessor: "path",
235
245
  childrenAccessor: "children",
236
246
  openByDefault: !1,
237
247
  width: "100%",
238
- height: c,
248
+ height: f,
239
249
  rowHeight: 26,
240
250
  indent: 14,
241
- selection: F,
251
+ selection: O,
242
252
  searchTerm: h ?? "",
243
- searchMatch: j,
244
- onActivate: M,
245
- onToggle: A,
246
- onMove: O,
247
- disableDrop: W,
253
+ searchMatch: q,
254
+ onActivate: R,
255
+ onToggle: W,
256
+ onMove: j,
257
+ disableDrop: L,
248
258
  disableEdit: !0,
249
- dndManager: Z(),
250
- children: E
259
+ dndManager: E(),
260
+ children: H
251
261
  }
252
262
  ) }) });
253
263
  }
254
264
  export {
255
- ie as FileTree
265
+ ce as FileTree
256
266
  };
@@ -4,7 +4,7 @@ import { ReactNodeViewRenderer as Z, NodeViewWrapper as G, useEditor as J, Edito
4
4
  import et from "@tiptap/starter-kit";
5
5
  import rt from "@tiptap/extension-underline";
6
6
  import it from "@tiptap/extension-link";
7
- import j from "@tiptap/extension-placeholder";
7
+ import q from "@tiptap/extension-placeholder";
8
8
  import nt from "@tiptap/extension-task-list";
9
9
  import at from "@tiptap/extension-task-item";
10
10
  import ot from "@tiptap/extension-text-align";
@@ -15,15 +15,15 @@ import { TableHeader as ut } from "@tiptap/extension-table-header";
15
15
  import { TableCell as gt } from "@tiptap/extension-table-cell";
16
16
  import dt from "@tiptap/extension-image";
17
17
  import { c as U } from "./utils-B6yFEsav.js";
18
- import { ao as q, ap as _ } from "./WorkspaceProvider-Cn0sPgaB.js";
18
+ import { _ as j, aq as _ } from "./WorkspaceProvider-BW4wzbpR.js";
19
19
  import { uploadFile as ft } from "@hachej/boring-agent/front";
20
20
  import mt from "@tiptap/extension-code-block-lowlight";
21
21
  import { createLowlight as pt, common as ht } from "lowlight";
22
22
  import { Markdown as wt } from "@tiptap/markdown";
23
23
  import { BoldIcon as kt, ItalicIcon as vt, UnderlineIcon as bt, StrikethroughIcon as It, Heading1Icon as At, Heading2Icon as yt, Heading3Icon as Lt, ListIcon as xt, ListOrderedIcon as Nt, ListChecksIcon as Ct, QuoteIcon as Tt, CodeIcon as Mt, LinkIcon as Rt, ImageIcon as Ht, HighlighterIcon as Ut, AlignLeftIcon as St, AlignCenterIcon as $t, AlignRightIcon as Bt, MinusIcon as Dt, Loader2Icon as Et } from "lucide-react";
24
24
  import { Toolbar as Ft, Input as zt, ToolbarButton as Wt, ToolbarSeparator as Pt } from "@hachej/boring-ui-kit";
25
- function jt(t) {
26
- const r = q(), i = _(), [a, s] = E(0);
25
+ function qt(t) {
26
+ const r = j(), i = _(), [a, s] = E(0);
27
27
  return { upload: K(
28
28
  async (g, o) => {
29
29
  s((p) => p + 1);
@@ -42,7 +42,7 @@ function jt(t) {
42
42
  ), uploading: a > 0 };
43
43
  }
44
44
  const F = 64, z = 2e3;
45
- function qt(t) {
45
+ function jt(t) {
46
46
  return t.replace(/\\/g, "\\\\").replace(/]/g, "\\]");
47
47
  }
48
48
  function B(t) {
@@ -75,7 +75,7 @@ const O = dt.extend({
75
75
  var y, b, A, n, c, k, I;
76
76
  const r = typeof ((y = t.attrs) == null ? void 0 : y.src) == "string" ? t.attrs.src : "", i = typeof ((b = t.attrs) == null ? void 0 : b.alt) == "string" ? t.attrs.alt : "", a = typeof ((A = t.attrs) == null ? void 0 : A.title) == "string" ? t.attrs.title : "", s = W((n = t.attrs) == null ? void 0 : n.width), l = W((c = t.attrs) == null ? void 0 : c.height), g = ((k = t.attrs) == null ? void 0 : k.align) === "center" || ((I = t.attrs) == null ? void 0 : I.align) === "right" ? t.attrs.align : "left";
77
77
  if (!s && !l && g === "left") {
78
- const h = qt(i);
78
+ const h = jt(i);
79
79
  return a ? `![${h}](${r} "${a.replace(/"/g, '\\"')}")` : `![${h}](${r})`;
80
80
  }
81
81
  const p = `<img ${[
@@ -235,7 +235,7 @@ const Gt = [
235
235
  defaultProtocol: "https",
236
236
  HTMLAttributes: { rel: "noopener noreferrer nofollow", target: "_blank" }
237
237
  }),
238
- j.configure({
238
+ q.configure({
239
239
  placeholder: "Start writing..."
240
240
  }),
241
241
  nt,
@@ -436,7 +436,7 @@ function xe({
436
436
  className: s,
437
437
  documentPath: l
438
438
  }) {
439
- const g = q(), o = _(), { upload: p, uploading: y } = jt(), [b, A] = E(!1), n = Q(() => {
439
+ const g = j(), o = _(), { upload: p, uploading: y } = qt(), [b, A] = E(!1), n = Q(() => {
440
440
  const d = O.configure({
441
441
  inline: !1,
442
442
  allowBase64: !0,
@@ -444,7 +444,7 @@ function xe({
444
444
  }), m = Gt.map((w) => w.name === "image" ? d : w);
445
445
  return a ? [
446
446
  ...m.filter((w) => w.name !== "placeholder"),
447
- j.configure({ placeholder: a })
447
+ q.configure({ placeholder: a })
448
448
  ] : m;
449
449
  }, [g, l, a, o]), c = L(r);
450
450
  c.current = r;