@vellym/wbs 0.0.0-stage → 0.2.0-beta

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.
@@ -0,0 +1,1246 @@
1
+ // src/browser.ts
2
+ import { defineBrowserPlugin } from "@vellym/plugin-api";
3
+ import { reactRenderer } from "@vellym/plugin-api/react";
4
+
5
+ // ../ticket-engine/dist/definitions.js
6
+ import { SUMMARY_METHODS } from "@vellym/plugin-api";
7
+
8
+ // ../ticket-engine/dist/projection.js
9
+ var FIELD_KEY_PREFIX = "field:";
10
+ var fieldKey = (id) => `${FIELD_KEY_PREFIX}${id}`;
11
+
12
+ // ../ticket-engine/dist/hierarchy.js
13
+ function buildTicketHierarchy(tracker, rows) {
14
+ const diagnostics = [];
15
+ const nodes = new Map(rows.map((row) => [row.name, { row, children: [] }]));
16
+ const parents = /* @__PURE__ */ new Map();
17
+ if (tracker.parentField) {
18
+ for (const row of rows) {
19
+ const value = row.values[fieldKey(tracker.parentField)];
20
+ if (typeof value !== "string" || !value)
21
+ continue;
22
+ if (!nodes.has(value)) {
23
+ diagnostics.push({
24
+ file: row.name,
25
+ path: `/spec/fields/${tracker.parentField}`,
26
+ severity: "warning",
27
+ code: "TICKET_PARENT_UNRESOLVED",
28
+ message: {
29
+ ja: `\u89AA\u30C1\u30B1\u30C3\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${value}`,
30
+ en: `Parent ticket not found: ${value}`
31
+ }
32
+ });
33
+ } else
34
+ parents.set(row.name, value);
35
+ }
36
+ }
37
+ const checked = /* @__PURE__ */ new Set();
38
+ for (const name of nodes.keys()) {
39
+ if (checked.has(name))
40
+ continue;
41
+ const chain = [];
42
+ const positions = /* @__PURE__ */ new Map();
43
+ let cursor = name;
44
+ while (cursor && !checked.has(cursor)) {
45
+ const cycleStart = positions.get(cursor);
46
+ if (cycleStart !== void 0) {
47
+ for (const member of chain.slice(cycleStart)) {
48
+ parents.delete(member);
49
+ diagnostics.push({
50
+ file: member,
51
+ path: `/spec/fields/${tracker.parentField}`,
52
+ severity: "warning",
53
+ code: "TICKET_PARENT_CYCLE",
54
+ message: {
55
+ ja: "\u89AA\u5B50\u53C2\u7167\u304C\u5FAA\u74B0\u3057\u3066\u3044\u307E\u3059",
56
+ en: "The parent relationship contains a cycle."
57
+ }
58
+ });
59
+ }
60
+ break;
61
+ }
62
+ positions.set(cursor, chain.length);
63
+ chain.push(cursor);
64
+ cursor = parents.get(cursor);
65
+ }
66
+ for (const visited of chain)
67
+ checked.add(visited);
68
+ }
69
+ const roots = [];
70
+ for (const [name, node] of nodes) {
71
+ const parent = nodes.get(parents.get(name) ?? "");
72
+ if (parent)
73
+ parent.children.push(node);
74
+ else
75
+ roots.push(node);
76
+ }
77
+ return { roots, diagnostics };
78
+ }
79
+
80
+ // src/view.ts
81
+ var WBS_VIEW_ID = "wbs-tree";
82
+
83
+ // src/screen.tsx
84
+ import { useEffect, useRef, useState } from "react";
85
+ import { resolveLocalizedText, summarizeRows } from "@vellym/plugin-api";
86
+ import { Button, ChoiceControl, InputControl } from "@vellym/plugin-api/ui";
87
+
88
+ // src/model.ts
89
+ function excludedParents(rows, name, field) {
90
+ const children = /* @__PURE__ */ new Map();
91
+ for (const row of rows) {
92
+ const parent = row.values[fieldKey(field)];
93
+ if (typeof parent === "string") children.set(parent, [...children.get(parent) ?? [], row.name]);
94
+ }
95
+ const excluded = /* @__PURE__ */ new Set();
96
+ const pending = [name];
97
+ while (pending.length) {
98
+ const current = pending.pop();
99
+ if (excluded.has(current)) continue;
100
+ excluded.add(current);
101
+ pending.push(...children.get(current) ?? []);
102
+ }
103
+ return excluded;
104
+ }
105
+ function rankForAppend(rows, field) {
106
+ let maximum;
107
+ for (const row of rows) {
108
+ const rank = row.values[fieldKey(field)];
109
+ if (typeof rank !== "number" || !Number.isFinite(rank)) return void 0;
110
+ maximum = maximum === void 0 ? rank : Math.max(maximum, rank);
111
+ }
112
+ if (maximum === void 0) return 1;
113
+ const next = maximum + Math.max(1, Math.abs(maximum) * Number.EPSILON);
114
+ return Number.isFinite(next) && next > maximum ? next : void 0;
115
+ }
116
+ function sortedSiblings(nodes, field, locale) {
117
+ return [...nodes].sort((a, b) => {
118
+ const left = field ? a.row.values[fieldKey(field)] : void 0;
119
+ const right = field ? b.row.values[fieldKey(field)] : void 0;
120
+ const l = typeof left === "number" && Number.isFinite(left) ? left : void 0;
121
+ const r = typeof right === "number" && Number.isFinite(right) ? right : void 0;
122
+ if (l === void 0 !== (r === void 0)) return l === void 0 ? 1 : -1;
123
+ return (l !== void 0 && r !== void 0 ? l - r : 0) || a.row.title.localeCompare(b.row.title, locale) || a.row.name.localeCompare(b.row.name);
124
+ });
125
+ }
126
+ function flattenRows(nodes, field, locale, collapsed) {
127
+ const result = [];
128
+ const stack = [];
129
+ const push = (children, depth) => {
130
+ const sorted = sortedSiblings(children, field, locale);
131
+ const siblings = sorted.map((node) => node.row);
132
+ for (let index = sorted.length - 1; index >= 0; index--) {
133
+ stack.push({ node: sorted[index], depth, siblings, index });
134
+ }
135
+ };
136
+ push(nodes, 0);
137
+ while (stack.length) {
138
+ const item = stack.pop();
139
+ result.push(item);
140
+ if (!collapsed.has(item.node.row.name)) push(item.node.children, item.depth + 1);
141
+ }
142
+ return result;
143
+ }
144
+ function rowWindow(total, strategy, scrollTop, viewportHeight, rowHeight, loaded) {
145
+ if (strategy === "all") return { start: 0, end: total };
146
+ if (strategy === "incremental") return { start: 0, end: Math.min(total, loaded) };
147
+ const first = Math.min(total, Math.max(0, Math.floor(scrollTop / rowHeight)));
148
+ return {
149
+ start: Math.max(0, first - 10),
150
+ end: Math.min(total, Math.ceil((scrollTop + viewportHeight) / rowHeight) + 10)
151
+ };
152
+ }
153
+ function rankForInsert(rows, index, target, field) {
154
+ if (index < 0 || index >= rows.length || target < 0 || target >= rows.length) return void 0;
155
+ const remaining = rows.filter((_, spot) => spot !== index);
156
+ const rank = (row) => {
157
+ const value = row?.values[fieldKey(field)];
158
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
159
+ };
160
+ const before = remaining[target - 1];
161
+ const left = rank(before);
162
+ const right = rank(remaining[target]);
163
+ if (left === void 0 && right === void 0) {
164
+ if (before) return void 0;
165
+ const ranks = remaining.map(rank).filter((value) => value !== void 0);
166
+ return ranks.length ? Math.max(...ranks) + 1 : 0;
167
+ }
168
+ if (before && left === void 0) return void 0;
169
+ if (left === void 0) {
170
+ const result2 = right - Math.max(1, Math.abs(right) * Number.EPSILON);
171
+ return Number.isFinite(result2) && result2 < right ? result2 : void 0;
172
+ }
173
+ if (right === void 0) {
174
+ const result2 = left + Math.max(1, Math.abs(left) * Number.EPSILON);
175
+ return Number.isFinite(result2) && result2 > left ? result2 : void 0;
176
+ }
177
+ const result = left + (right - left) / 2;
178
+ return result > left && result < right ? result : void 0;
179
+ }
180
+
181
+ // src/timeline.ts
182
+ var DAY = 864e5;
183
+ function parseDate(value) {
184
+ if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return void 0;
185
+ const parsed = Date.parse(`${value}T00:00:00Z`);
186
+ return Number.isFinite(parsed) && new Date(parsed).toISOString().slice(0, 10) === value ? parsed : void 0;
187
+ }
188
+ var DAY_MS = DAY;
189
+ var MAX_TIMELINE_DAYS = { day: 182, week: 186 };
190
+ var TIMELINE_PRESETS = ["2w", "1m", "3m", "6m"];
191
+ function mondayOnOrBefore(timestamp) {
192
+ const day = Math.floor(timestamp / DAY) * DAY;
193
+ return day - (new Date(day).getUTCDay() + 6) % 7 * DAY;
194
+ }
195
+ function timelinePreset(value) {
196
+ const legacy = { "14": "2w", "35": "1m", "91": "3m", "182": "6m" };
197
+ const text = String(value);
198
+ return TIMELINE_PRESETS.includes(text) ? text : legacy[text];
199
+ }
200
+ function presetRange(timestamp, preset) {
201
+ if (preset === "2w") {
202
+ const start2 = mondayOnOrBefore(timestamp);
203
+ return { start: start2, end: start2 + 14 * DAY, mode: "day" };
204
+ }
205
+ const date2 = new Date(timestamp);
206
+ const start = Date.UTC(date2.getUTCFullYear(), date2.getUTCMonth(), 1);
207
+ const months = preset === "1m" ? 1 : preset === "3m" ? 3 : 6;
208
+ return {
209
+ start,
210
+ end: Date.UTC(date2.getUTCFullYear(), date2.getUTCMonth() + months, 1),
211
+ mode: preset === "1m" ? "day" : "week"
212
+ };
213
+ }
214
+ function timelineLabelSize(tier, width) {
215
+ const minimum = tier === "day" ? 22 : tier === "week" ? 44 : 30;
216
+ if (width < minimum) return "none";
217
+ return tier === "month" && width >= 84 ? "long" : "short";
218
+ }
219
+ function buildTimeline(rows, startField, endField, range = {}) {
220
+ let min = Infinity;
221
+ let max = -Infinity;
222
+ for (const row of rows) {
223
+ for (const value of [
224
+ startField ? row.values[fieldKey(startField)] : void 0,
225
+ endField ? row.values[fieldKey(endField)] : void 0
226
+ ]) {
227
+ const parsed = parseDate(value);
228
+ if (parsed !== void 0) {
229
+ min = Math.min(min, parsed);
230
+ max = Math.max(max, parsed);
231
+ }
232
+ }
233
+ }
234
+ const requestedStart = parseDate(range.from);
235
+ const requestedEnd = parseDate(range.to);
236
+ if (min === Infinity && requestedStart === void 0) return void 0;
237
+ const start = requestedStart ?? (range.mode ? mondayOnOrBefore(min) : min);
238
+ const requestedEndExclusive = requestedEnd !== void 0 ? requestedEnd + DAY : Math.max(max + DAY, start + DAY);
239
+ if (requestedEndExclusive <= start) return void 0;
240
+ const end = range.mode ? Math.min(
241
+ requestedEndExclusive,
242
+ start + MAX_TIMELINE_DAYS[range.mode] * DAY
243
+ ) : requestedEndExclusive;
244
+ const days = (end - start) / DAY;
245
+ const step = range.mode === "day" ? 1 : range.mode === "week" ? 7 : Math.max(1, Math.ceil(days / 12));
246
+ const firstDay = range.mode === "week" ? (8 - new Date(start).getUTCDay()) % 7 : 0;
247
+ const offset = firstDay >= days ? 0 : firstDay;
248
+ const ticks = [];
249
+ for (let day = offset; day < days; day += step) {
250
+ ticks.push({ position: day / days * 100, label: new Date(start + day * DAY).toISOString().slice(0, 10) });
251
+ }
252
+ return { start, end, ticks };
253
+ }
254
+ function timelineBar(timeline, startValue, endValue) {
255
+ const start = parseDate(startValue);
256
+ const end = parseDate(endValue);
257
+ if (start === void 0 && end === void 0) return void 0;
258
+ const actualStart = start ?? end - 6 * DAY;
259
+ const actualEnd = end !== void 0 ? end + DAY : start + 7 * DAY;
260
+ if (start !== void 0 && end !== void 0 && end < start) return void 0;
261
+ if (actualEnd <= actualStart) return void 0;
262
+ if (actualEnd <= timeline.start) return { left: 0, width: 0, before: true, after: false, outside: "before" };
263
+ if (actualStart >= timeline.end) return { left: 100, width: 0, before: false, after: true, outside: "after" };
264
+ const from = Math.max(timeline.start, actualStart);
265
+ const to = Math.min(timeline.end, actualEnd);
266
+ const span = timeline.end - timeline.start;
267
+ return {
268
+ left: (from - timeline.start) / span * 100,
269
+ width: Math.max((to - from) / span * 100, 0.25),
270
+ before: actualStart < timeline.start,
271
+ after: actualEnd > timeline.end
272
+ };
273
+ }
274
+ function timelineCells(timeline, mode, dayWidth) {
275
+ const days = (timeline.end - timeline.start) / DAY;
276
+ const cells = [];
277
+ for (let offset = 0; offset < days; offset += mode === "day" ? 1 : 7) {
278
+ const timestamp = timeline.start + offset * DAY;
279
+ const width = Math.min(mode === "day" ? 1 : 7, days - offset) * dayWidth;
280
+ cells.push({
281
+ timestamp,
282
+ left: offset * dayWidth,
283
+ width,
284
+ showLabel: timelineLabelSize(mode, width) !== "none"
285
+ });
286
+ }
287
+ const months = [];
288
+ let cursor = timeline.start;
289
+ while (cursor < timeline.end) {
290
+ const date2 = new Date(cursor);
291
+ const end = Math.min(timeline.end, Date.UTC(date2.getUTCFullYear(), date2.getUTCMonth() + 1, 1));
292
+ const width = (end - cursor) / DAY * dayWidth;
293
+ months.push({
294
+ timestamp: cursor,
295
+ left: (cursor - timeline.start) / DAY * dayWidth,
296
+ width,
297
+ labelSize: timelineLabelSize("month", width)
298
+ });
299
+ cursor = end;
300
+ }
301
+ return { cells, months };
302
+ }
303
+
304
+ // src/screen.tsx
305
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
306
+ var label = (ja, en, locale) => resolveLocalizedText({ ja, en }, locale);
307
+ var date = (value) => parseDate(value) !== void 0 ? value : void 0;
308
+ function TimelineTrack({ timeline, start, end, locale, closed, onReveal }) {
309
+ const s = parseDate(start), e = parseDate(end);
310
+ const short = (value) => String(value).slice(5);
311
+ if (s !== void 0 && e !== void 0 && e < s) return /* @__PURE__ */ jsx("strong", { className: "wbs-date-error", "data-schedule": "invalid", children: label(
312
+ `\u25B3 \u7D42\u4E86\u65E5\u304C\u958B\u59CB\u65E5\u3088\u308A\u524D\u3067\u3059\uFF08\u958B\u59CB ${short(start)} \uFF0F \u7D42\u4E86 ${short(end)}\uFF09`,
313
+ `\u25B3 End date precedes start date (start ${short(start)} / end ${short(end)})`,
314
+ locale
315
+ ) });
316
+ if (!timeline || s === void 0 && e === void 0) return /* @__PURE__ */ jsx("span", { "data-schedule": "none", children: label("\u2014 \u65E5\u7A0B\u306A\u3057", "\u2014 No dates", locale) });
317
+ const bar = timelineBar(timeline, start, end);
318
+ const kind = s === void 0 ? "end-only" : e === void 0 ? "start-only" : "period";
319
+ const text = s === void 0 ? label(`\u958B\u59CB\u65E5\u306A\u3057\u30FB\u7D42\u4E86 ${short(end)}`, `No start date \xB7 End ${short(end)}`, locale) : e === void 0 ? label(`\u958B\u59CB ${short(start)}\u30FB\u7D42\u4E86\u65E5\u306A\u3057`, `Start ${short(start)} \xB7 No end date`, locale) : `${closed ? "\u2713 " : ""}${short(start)}\u2013${short(end)}`;
320
+ if (bar?.outside) return /* @__PURE__ */ jsx("div", { className: `wbs-track wbs-outside-${bar.outside}`, "data-schedule": `outside-${bar.outside}`, children: /* @__PURE__ */ jsx(Button, { onClick: () => onReveal(bar.outside === "before" ? e ?? s : s ?? e), children: bar.outside === "before" ? label(`\u25C0 \u8868\u793A\u671F\u9593\u3088\u308A\u524D ${text}`, `\u25C0 Before range ${text}`, locale) : label(`\u8868\u793A\u671F\u9593\u3088\u308A\u5F8C ${text} \u25B6`, `After range ${text} \u25B6`, locale) }) });
321
+ return /* @__PURE__ */ jsx("div", { className: "wbs-track", "aria-label": bar ? `${String(start ?? "")} \u2013 ${String(end ?? "")}` : label("\u65E5\u7A0B\u672A\u8A2D\u5B9A", "No dates", locale), children: bar ? /* @__PURE__ */ jsxs(Fragment, { children: [
322
+ /* @__PURE__ */ jsx(
323
+ "span",
324
+ {
325
+ "aria-hidden": "true",
326
+ className: "wbs-bar",
327
+ "data-schedule": kind,
328
+ "data-closed": closed || void 0,
329
+ "data-before": bar.before || void 0,
330
+ "data-after": bar.after || void 0,
331
+ style: { left: `${bar.left}%`, width: `${bar.width}%` }
332
+ }
333
+ ),
334
+ /* @__PURE__ */ jsxs("span", { className: "wbs-bar-label", style: bar.left + bar.width < 65 ? { left: `${bar.left + bar.width}%` } : bar.left > 35 ? { right: `${100 - bar.left}%` } : { left: `${bar.left}%` }, children: [
335
+ bar.before ? `\u25C0 ${short(start ?? end)} ` : "",
336
+ text,
337
+ bar.after ? ` ${short(end ?? start)} \u25B6` : ""
338
+ ] })
339
+ ] }) : null });
340
+ }
341
+ function statusSymbol(data, id, category) {
342
+ const symbol = typeof id === "string" && Object.hasOwn(data.statusSymbols ?? {}, id) ? data.statusSymbols?.[id] : void 0;
343
+ return symbol?.trim() ? symbol : category === "closed" ? "\u2713" : "\u25A1";
344
+ }
345
+ function Indent({ depth, children }) {
346
+ let content = children;
347
+ for (let level = depth; level > 0; level--) {
348
+ content = /* @__PURE__ */ jsx("span", { className: "wbs-indent", "data-indent-level": level, children: content });
349
+ }
350
+ return content;
351
+ }
352
+ function WBSRows({ items, data, context, all, review, timeline, busy, movedName, collapsed, onToggle, onParent, onOrder, onDropOrder, onRenumber, onCreate, onReveal }) {
353
+ const [editingParent, setEditingParent] = useState();
354
+ const [menu, setMenu] = useState();
355
+ const [menuPosition, setMenuPosition] = useState({ left: "8px", top: "8px" });
356
+ const [dropPosition, setDropPosition] = useState();
357
+ const editable = !context.isStatic && !context.target?.readOnly;
358
+ const byName = new Map(all.map((row) => [row.name, row]));
359
+ function reviewNote(row) {
360
+ const seen = /* @__PURE__ */ new Set();
361
+ const chain = [];
362
+ let current = row;
363
+ while (current && !seen.has(current.name)) {
364
+ seen.add(current.name);
365
+ chain.push(String(current.values.number ?? current.name));
366
+ const parent = data.parentField ? current.values[fieldKey(data.parentField)] : void 0;
367
+ if (typeof parent !== "string" || !parent) break;
368
+ if (!byName.has(parent)) return label(`\u89AA ${parent} \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093`, `Parent ${parent} not found`, context.locale);
369
+ current = byName.get(parent);
370
+ }
371
+ return `\u25B3 ${chain.join(" \u2192 ")}${current ? ` \u2192 ${String(current.values.number ?? current.name)}` : ""}`;
372
+ }
373
+ useEffect(() => {
374
+ if (!menu) return;
375
+ const close = (event) => {
376
+ if (event.target instanceof Element && !event.target.closest(".wbs-row-menu, .wbs-actions")) {
377
+ setMenu(void 0);
378
+ setEditingParent(void 0);
379
+ }
380
+ };
381
+ document.addEventListener("pointerdown", close);
382
+ return () => document.removeEventListener("pointerdown", close);
383
+ }, [menu]);
384
+ return /* @__PURE__ */ jsx(Fragment, { children: items.map(({ node, depth, siblings: rows, index }) => {
385
+ const row = node.row;
386
+ const start = data.startField ? date(row.values[fieldKey(data.startField)]) : void 0;
387
+ const end = data.endField ? date(row.values[fieldKey(data.endField)]) : void 0;
388
+ const parent = data.parentField ? row.values[fieldKey(data.parentField)] : void 0;
389
+ const status = data.tracker?.statuses.find((item) => item.id === row.values.status);
390
+ const needsReview = review.has(row.name);
391
+ const descendants = editingParent === row.name && data.parentField ? excludedParents(all, row.name, data.parentField) : /* @__PURE__ */ new Set();
392
+ const dropTarget = editable && !needsReview && data.orderField ? {
393
+ onDragOver: (event) => {
394
+ event.preventDefault();
395
+ const rect = event.currentTarget.getBoundingClientRect();
396
+ const after = event.clientY > rect.top + rect.height / 2;
397
+ setDropPosition((current) => current?.name === row.name && current.after === after ? current : { name: row.name, after });
398
+ },
399
+ onDrop: (event) => {
400
+ event.preventDefault();
401
+ event.stopPropagation();
402
+ setDropPosition(void 0);
403
+ const rect = event.currentTarget.getBoundingClientRect();
404
+ onDropOrder(
405
+ rows,
406
+ event.dataTransfer.getData("text/plain"),
407
+ index,
408
+ event.clientY > rect.top + rect.height / 2
409
+ );
410
+ }
411
+ } : {};
412
+ return /* @__PURE__ */ jsxs(
413
+ "div",
414
+ {
415
+ role: "row",
416
+ "aria-level": depth + 1,
417
+ "aria-expanded": node.children.length ? !collapsed.has(row.name) : void 0,
418
+ "data-ticket-name": row.name,
419
+ "data-wbs-level": depth,
420
+ className: "wbs-row",
421
+ "data-moved": movedName === row.name || void 0,
422
+ "data-review": needsReview || void 0,
423
+ "data-drop": dropPosition?.name === row.name ? dropPosition.after ? "after" : "before" : void 0,
424
+ children: [
425
+ /* @__PURE__ */ jsxs("div", { role: "gridcell", className: "wbs-left", ...dropTarget, children: [
426
+ /* @__PURE__ */ jsx(Indent, { depth, children: /* @__PURE__ */ jsxs("span", { className: "wbs-cell-content", children: [
427
+ /* @__PURE__ */ jsx("span", { className: "wbs-toggle", children: node.children.length ? /* @__PURE__ */ jsx(
428
+ Button,
429
+ {
430
+ icon: true,
431
+ "aria-label": `${row.title}: ${label("\u5C55\u958B\u30FB\u6298\u308A\u305F\u305F\u307F", "Toggle children", context.locale)}`,
432
+ "aria-expanded": !collapsed.has(row.name),
433
+ onClick: () => onToggle(row.name),
434
+ children: collapsed.has(row.name) ? "\u25B8" : "\u25BE"
435
+ }
436
+ ) : null }),
437
+ depth >= 4 ? /* @__PURE__ */ jsxs("span", { className: "wbs-level-badge", children: [
438
+ "L",
439
+ depth + 1
440
+ ] }) : null,
441
+ /* @__PURE__ */ jsx("span", { className: "wbs-number", children: String(row.values.number ?? "") }),
442
+ /* @__PURE__ */ jsx("span", { className: "wbs-narrow-status", title: status?.label, children: statusSymbol(data, row.values.status, status?.category) }),
443
+ /* @__PURE__ */ jsx(Button, { className: "wbs-title", onClick: () => void context.openResource(row.name), children: row.title || row.name }),
444
+ needsReview && !context.isStatic ? /* @__PURE__ */ jsx("span", { className: "wbs-review-note", title: reviewNote(row), children: reviewNote(row) }) : null,
445
+ /* @__PURE__ */ jsxs("span", { className: "wbs-actions", children: [
446
+ editable && !needsReview && data.orderField && rows.length > 1 ? /* @__PURE__ */ jsx(
447
+ Button,
448
+ {
449
+ icon: true,
450
+ draggable: !busy,
451
+ disabled: busy,
452
+ "aria-label": `${row.title}: ${label("\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u9806\u5E8F\u3092\u5909\u66F4", "Drag to reorder", context.locale)}`,
453
+ "aria-keyshortcuts": "Alt+ArrowUp Alt+ArrowDown",
454
+ onKeyDown: (event) => {
455
+ if (event.altKey && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
456
+ event.preventDefault();
457
+ onOrder(rows, index, event.key === "ArrowUp" ? -1 : 1);
458
+ }
459
+ },
460
+ onDragStart: (event) => event.dataTransfer.setData("text/plain", row.name),
461
+ children: "\u283F"
462
+ }
463
+ ) : null,
464
+ /* @__PURE__ */ jsx(
465
+ Button,
466
+ {
467
+ icon: true,
468
+ "aria-label": `${row.title}: ${label("\u884C\u306E\u64CD\u4F5C", "Row actions", context.locale)}`,
469
+ "aria-expanded": menu === row.name,
470
+ onClick: (event) => {
471
+ const rect = event.currentTarget.getBoundingClientRect();
472
+ setMenuPosition({
473
+ left: `clamp(8px, ${rect.left}px, max(8px, calc(100vw - 368px)))`,
474
+ top: `clamp(8px, ${rect.bottom}px, max(8px, calc(100dvh - 370px)))`
475
+ });
476
+ setMenu(menu === row.name ? void 0 : row.name);
477
+ setEditingParent(void 0);
478
+ },
479
+ children: "\u22EF"
480
+ }
481
+ )
482
+ ] }),
483
+ /* @__PURE__ */ jsx("span", { className: "wbs-status", children: status ? `${statusSymbol(data, row.values.status, status.category)} ${status.label}` : String(row.values.status || label("\u672A\u8A2D\u5B9A", "Unset", context.locale)) })
484
+ ] }) }),
485
+ menu === row.name ? /* @__PURE__ */ jsxs(
486
+ "div",
487
+ {
488
+ role: "group",
489
+ "aria-label": label("\u884C\u306E\u64CD\u4F5C", "Row actions", context.locale),
490
+ className: "wbs-row-menu",
491
+ style: menuPosition,
492
+ onKeyDown: (event) => {
493
+ if (event.key === "Escape") {
494
+ setMenu(void 0);
495
+ setEditingParent(void 0);
496
+ }
497
+ },
498
+ children: [
499
+ /* @__PURE__ */ jsx(Button, { onClick: () => void context.openResource(row.name), children: label("\u8A73\u7D30", "Details", context.locale) }),
500
+ editable ? /* @__PURE__ */ jsxs(Fragment, { children: [
501
+ !needsReview && data.orderField ? /* @__PURE__ */ jsxs(Fragment, { children: [
502
+ /* @__PURE__ */ jsx(Button, { disabled: busy || index === 0, onClick: () => {
503
+ onOrder(rows, index, -1);
504
+ setMenu(void 0);
505
+ }, children: label("\u4E0A\u3078", "Move up", context.locale) }),
506
+ /* @__PURE__ */ jsx(Button, { disabled: busy || index === rows.length - 1, onClick: () => {
507
+ onOrder(rows, index, 1);
508
+ setMenu(void 0);
509
+ }, children: label("\u4E0B\u3078", "Move down", context.locale) })
510
+ ] }) : null,
511
+ data.parentField ? /* @__PURE__ */ jsxs(Fragment, { children: [
512
+ /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: () => setEditingParent(row.name), children: label("\u89AA\u3092\u5909\u66F4\u2026", "Change parent\u2026", context.locale) }),
513
+ needsReview ? /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: () => {
514
+ onParent(row, "");
515
+ setMenu(void 0);
516
+ }, children: label("\u89AA\u3092\u7A7A\u306B\u3057\u3066\u6700\u4E0A\u4F4D\u3078", "Clear parent and move to top level", context.locale) }) : null,
517
+ !needsReview && context.runCommand ? /* @__PURE__ */ jsx(Button, { disabled: busy, onClick: () => {
518
+ onCreate(row.name);
519
+ setMenu(void 0);
520
+ }, children: label("\u5B50\u30C1\u30B1\u30C3\u30C8\u3092\u8FFD\u52A0", "Add child task", context.locale) }) : null
521
+ ] }) : null
522
+ ] }) : null,
523
+ needsReview && !context.isStatic ? /* @__PURE__ */ jsx("small", { children: label("\u89AA\u306E\u53C2\u7167\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u4E26\u3073\u66FF\u3048\u3068\u5B50\u306E\u8FFD\u52A0\u306F\u3067\u304D\u307E\u305B\u3093\u3002", "Check the parent reference. Reordering and adding children are unavailable.", context.locale) }) : null,
524
+ editable && editingParent === row.name && data.parentField ? /* @__PURE__ */ jsxs("div", { role: "group", className: "wbs-parent-editor", children: [
525
+ /* @__PURE__ */ jsxs("label", { children: [
526
+ label("\u89AA\u3092\u5909\u66F4", "Change parent", context.locale),
527
+ " ",
528
+ /* @__PURE__ */ jsx(
529
+ ChoiceControl,
530
+ {
531
+ mode: "select",
532
+ "aria-label": `${row.title}: ${label("\u89AA", "Parent", context.locale)}`,
533
+ value: typeof parent === "string" ? parent : "",
534
+ disabled: busy,
535
+ options: [
536
+ { value: "", label: label("\u672A\u8A2D\u5B9A", "Unset", context.locale) },
537
+ ...all.filter((option) => !descendants.has(option.name) && !review.has(option.name)).map((option) => ({ value: option.name, label: option.title }))
538
+ ],
539
+ onChange: (value) => {
540
+ onParent(row, value);
541
+ setEditingParent(void 0);
542
+ setMenu(void 0);
543
+ }
544
+ }
545
+ )
546
+ ] }),
547
+ /* @__PURE__ */ jsx(Button, { onClick: () => setEditingParent(void 0), children: label("\u9589\u3058\u308B", "Close", context.locale) }),
548
+ !needsReview && data.orderField && rows.length > 0 ? /* @__PURE__ */ jsxs(Button, { disabled: busy, onClick: () => onRenumber(rows), children: [
549
+ label("\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3059", "Renumber order", context.locale),
550
+ " (",
551
+ rows.length,
552
+ ")"
553
+ ] }) : null
554
+ ] }) : null
555
+ ]
556
+ }
557
+ ) : null
558
+ ] }),
559
+ /* @__PURE__ */ jsx(
560
+ "div",
561
+ {
562
+ role: "gridcell",
563
+ className: "wbs-timeline-cell",
564
+ title: `${start || label("\u672A\u8A2D\u5B9A", "Unset", context.locale)} \u2013 ${end || label("\u672A\u8A2D\u5B9A", "Unset", context.locale)}`,
565
+ ...dropTarget,
566
+ children: /* @__PURE__ */ jsx(TimelineTrack, { timeline, start, end, locale: context.locale, closed: status?.category === "closed", onReveal })
567
+ }
568
+ )
569
+ ]
570
+ },
571
+ row.name
572
+ );
573
+ }) });
574
+ }
575
+ function WBSScreen({ context }) {
576
+ const base = context.rendererData;
577
+ const [configuration, setConfiguration] = useState({});
578
+ const data = base ? { ...base, ...configuration } : void 0;
579
+ const [parents, setParents] = useState({});
580
+ const [orders, setOrders] = useState({});
581
+ const [message, setMessage] = useState("");
582
+ const [busy, setBusy] = useState(false);
583
+ const [movedName, setMovedName] = useState();
584
+ const editable = !context.isStatic && !context.target?.readOnly;
585
+ useEffect(() => {
586
+ if (!movedName) return;
587
+ const timer = window.setTimeout(() => setMovedName(void 0), 1400);
588
+ return () => window.clearTimeout(timer);
589
+ }, [movedName]);
590
+ const tracker = data?.tracker;
591
+ const parentField = data?.parentField;
592
+ const orderField = data?.orderField;
593
+ useEffect(() => {
594
+ setParents((current) => Object.fromEntries(Object.entries(current).filter(([name, value]) => {
595
+ const row = context.rows.find((item) => item.name === name);
596
+ return row && (!parentField || row.values[fieldKey(parentField)] !== value);
597
+ })));
598
+ setOrders((current) => Object.fromEntries(Object.entries(current).filter(([name, value]) => {
599
+ const row = context.rows.find((item) => item.name === name);
600
+ return row && (!orderField || row.values[fieldKey(orderField)] !== value);
601
+ })));
602
+ }, [context.rows, parentField, orderField]);
603
+ const rows = context.rows.map((row) => ({ ...row, values: {
604
+ ...row.values,
605
+ ...parentField && parents[row.name] !== void 0 ? { [fieldKey(parentField)]: parents[row.name] } : {},
606
+ ...orderField && orders[row.name] !== void 0 ? { [fieldKey(orderField)]: orders[row.name] } : {}
607
+ } }));
608
+ const available = buildTimeline(rows, data?.startField, data?.endField);
609
+ const [mode, setMode] = useState(() => available && (available.end - available.start) / DAY_MS > 35 ? "week" : "day");
610
+ const initialPreset = timelinePreset(settings(context).timelinePreset) ?? (available && (available.end - available.start) / DAY_MS > 31 ? "3m" : "1m");
611
+ const iso = (timestamp) => new Date(timestamp).toISOString().slice(0, 10);
612
+ const [preset, setPreset] = useState(initialPreset);
613
+ const [range, setRange] = useState(() => {
614
+ const initial = presetRange(available?.start ?? Date.now(), initialPreset);
615
+ return { from: iso(initial.start), to: iso(initial.end - DAY_MS) };
616
+ });
617
+ const [draftRange, setDraftRange] = useState(range);
618
+ const timeline = buildTimeline(rows, data?.startField, data?.endField, {
619
+ mode,
620
+ ...range.from ? { from: range.from } : {},
621
+ ...range.to ? { to: range.to } : {}
622
+ });
623
+ function changeRange(from, to, nextMode = mode) {
624
+ const start = parseDate(from);
625
+ const finish = parseDate(to);
626
+ if (start === void 0 || finish === void 0) return;
627
+ const limit = nextMode === "week" ? 186 : 182;
628
+ const bounded = Math.min(Math.max(start, finish), start + (limit - 1) * DAY_MS);
629
+ setMode(nextMode);
630
+ const next = { from: iso(start), to: iso(bounded) };
631
+ setRange(next);
632
+ setDraftRange(next);
633
+ setMessage(finish > bounded ? label(
634
+ `\u8868\u793A\u7BC4\u56F2\u306F\u6700\u5927${limit}\u65E5\u3067\u3059\u3002\u7D42\u4E86\u65E5\u3092\u8ABF\u6574\u3057\u307E\u3057\u305F\u3002`,
635
+ `The visible range is limited to ${limit} days. End date adjusted.`,
636
+ context.locale
637
+ ) : "");
638
+ }
639
+ function reveal(timestamp) {
640
+ const days = timeline ? (timeline.end - timeline.start) / DAY_MS : 35;
641
+ const start = mondayOnOrBefore(timestamp);
642
+ changeRange(iso(start), iso(start + (days - 1) * DAY_MS));
643
+ }
644
+ const hierarchy = tracker ? buildTicketHierarchy({ ...tracker, ...parentField ? { parentField } : { parentField: void 0 } }, rows) : { roots: [], diagnostics: [] };
645
+ const review = /* @__PURE__ */ new Set();
646
+ for (const diagnostic of hierarchy.diagnostics) {
647
+ if (diagnostic.file && parentField) {
648
+ for (const name of excludedParents(rows, diagnostic.file, parentField)) review.add(name);
649
+ }
650
+ }
651
+ const renumberMessage = label("\u5148\u306B\u79FB\u52D5\u5148\u306E\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3057\u3066\u304F\u3060\u3055\u3044", "Renumber the destination before moving", context.locale);
652
+ const saveMessage = (result) => {
653
+ setMessage(result.ok ? label("\u2713 \u4FDD\u5B58\u6E08\u307F", "\u2713 Saved", context.locale) : result.reason === "conflict" ? label("\u4ED6\u3067\u5909\u66F4\u3055\u308C\u307E\u3057\u305F\u3002\u8868\u793A\u306F\u64CD\u4F5C\u524D\u306E\u307E\u307E\u3067\u3059\u3002\u518D\u8AAD\u307F\u8FBC\u307F\u3057\u3066\u304F\u3060\u3055\u3044\u3002", "Changed elsewhere. The previous display is preserved; reload.", context.locale) : result.message);
654
+ };
655
+ async function changeParent(row, parent) {
656
+ if (!parentField || busy || !editable || parent && (excludedParents(rows, row.name, parentField).has(parent) || review.has(parent))) return;
657
+ const currentParent = row.values[fieldKey(parentField)];
658
+ if ((typeof currentParent === "string" ? currentParent : "") === parent) return;
659
+ const destination = rows.filter((item) => item.name !== row.name && !review.has(item.name) && (item.values[fieldKey(parentField)] || "") === parent);
660
+ const rank = orderField ? rankForAppend(destination, orderField) : void 0;
661
+ if (orderField && rank === void 0 || !orderField && destination.length) {
662
+ setMessage(renumberMessage);
663
+ return;
664
+ }
665
+ setBusy(true);
666
+ setMovedName(void 0);
667
+ const result = await context.save([
668
+ { path: ["fields", parentField], value: parent || null },
669
+ ...orderField && rank !== void 0 ? [{ path: ["fields", orderField], value: rank }] : []
670
+ ], { targetName: row.name });
671
+ setBusy(false);
672
+ saveMessage(result);
673
+ if (!result.ok) return;
674
+ setParents((current) => ({ ...current, [row.name]: parent }));
675
+ if (orderField && rank !== void 0) setOrders((current) => ({ ...current, [row.name]: rank }));
676
+ setMovedName(row.name);
677
+ }
678
+ async function configure(setting, value) {
679
+ if (busy || !editable) return;
680
+ setBusy(true);
681
+ const result = await context.save([{ path: ["wbs", setting], value: value || null }]);
682
+ setBusy(false);
683
+ if (!result.ok) {
684
+ setMessage(result.message);
685
+ return;
686
+ }
687
+ setMessage("");
688
+ setConfiguration((current) => ({ ...current, [setting]: value }));
689
+ }
690
+ async function createTask(parent) {
691
+ if (!context.runCommand || busy || !parentField || !editable || review.has(parent)) return;
692
+ setBusy(true);
693
+ const result = await context.runCommand("ticket.create", {
694
+ parent,
695
+ parentField
696
+ });
697
+ setBusy(false);
698
+ if (!result.ok) {
699
+ setMessage(result.message);
700
+ return;
701
+ }
702
+ setMessage("");
703
+ }
704
+ async function moveOrder(siblings, index, delta) {
705
+ if (!orderField || busy || !editable || review.has(siblings[index]?.name ?? "") || index + delta < 0 || index + delta >= siblings.length) return;
706
+ const rank = rankForInsert(siblings, index, index + delta, orderField);
707
+ if (rank === void 0) {
708
+ setMessage(label("\u3053\u306E\u4F4D\u7F6E\u3078\u52D5\u304B\u3059\u306B\u306F\u3001\u5148\u306B\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3057\u3066\u304F\u3060\u3055\u3044", "Renumber before moving here", context.locale));
709
+ return;
710
+ }
711
+ const row = siblings[index];
712
+ setBusy(true);
713
+ setMovedName(void 0);
714
+ const result = await context.save([{ path: ["fields", orderField], value: rank }], { targetName: row.name });
715
+ setBusy(false);
716
+ saveMessage(result);
717
+ if (!result.ok) return;
718
+ setMessage(label(
719
+ `\u2713 \u4FDD\u5B58\u6E08\u307F\u3002\u540C\u3058\u968E\u5C64\u306E${index + delta + 1}\u756A\u76EE / ${siblings.length}\u4EF6`,
720
+ `\u2713 Saved. Position ${index + delta + 1} of ${siblings.length} siblings`,
721
+ context.locale
722
+ ));
723
+ setOrders((current) => ({ ...current, [row.name]: rank }));
724
+ setMovedName(row.name);
725
+ }
726
+ async function dropOrder(siblings, dragged, target, after) {
727
+ if (!orderField || busy || !editable || review.has(dragged)) return;
728
+ const source = siblings.findIndex((row2) => row2.name === dragged);
729
+ if (source === -1) return;
730
+ const index = target + (after ? 1 : 0) - (source < target + (after ? 1 : 0) ? 1 : 0);
731
+ if (index === source) return;
732
+ const rank = rankForInsert(siblings, source, index, orderField);
733
+ if (rank === void 0) {
734
+ setMessage(label("\u3053\u306E\u4F4D\u7F6E\u3078\u52D5\u304B\u3059\u306B\u306F\u3001\u5148\u306B\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3057\u3066\u304F\u3060\u3055\u3044", "Renumber before moving here", context.locale));
735
+ return;
736
+ }
737
+ const row = siblings[source];
738
+ setBusy(true);
739
+ setMovedName(void 0);
740
+ const result = await context.save([{ path: ["fields", orderField], value: rank }], { targetName: row.name });
741
+ setBusy(false);
742
+ saveMessage(result);
743
+ if (!result.ok) return;
744
+ setMessage(label(
745
+ `\u2713 \u4FDD\u5B58\u6E08\u307F\u3002\u540C\u3058\u968E\u5C64\u306E${index + 1}\u756A\u76EE / ${siblings.length}\u4EF6`,
746
+ `\u2713 Saved. Position ${index + 1} of ${siblings.length} siblings`,
747
+ context.locale
748
+ ));
749
+ setOrders((current) => ({ ...current, [row.name]: rank }));
750
+ setMovedName(row.name);
751
+ }
752
+ async function renumber(siblings) {
753
+ if (!orderField || busy || !editable || !window.confirm(label(
754
+ `${siblings.length}\u4EF6\u306E\u30C1\u30B1\u30C3\u30C8\u306E\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3057\u307E\u3059\u3002\u5B9F\u884C\u3057\u307E\u3059\u304B\uFF1F`,
755
+ `Renumber ${siblings.length} tickets one by one?`,
756
+ context.locale
757
+ ))) return;
758
+ setBusy(true);
759
+ for (const [index, row] of siblings.entries()) {
760
+ if (row.values[fieldKey(orderField)] === index + 1) continue;
761
+ const result = await context.save([{ path: ["fields", orderField], value: index + 1 }], { targetName: row.name });
762
+ if (!result.ok) {
763
+ setMessage(`${row.title}: ${result.message}`);
764
+ setBusy(false);
765
+ return;
766
+ }
767
+ setOrders((current) => ({ ...current, [row.name]: index + 1 }));
768
+ }
769
+ setBusy(false);
770
+ setMessage(label("\u4E26\u3073\u9806\u3092\u4ED8\u3051\u76F4\u3057\u307E\u3057\u305F", "Order renumbered", context.locale));
771
+ }
772
+ return /* @__PURE__ */ jsxs(
773
+ "section",
774
+ {
775
+ "aria-label": label("WBS\u306E\u968E\u5C64", "WBS hierarchy", context.locale),
776
+ style: { width: "100%", minWidth: 0 },
777
+ children: [
778
+ editable && tracker ? /* @__PURE__ */ jsxs("details", { children: [
779
+ /* @__PURE__ */ jsx("summary", { children: label("WBS\u306E\u8A2D\u5B9A", "WBS settings", context.locale) }),
780
+ [
781
+ ["parentField", "reference", "\u89AA", "Parent"],
782
+ ["startField", "date", "\u958B\u59CB", "Start"],
783
+ ["endField", "date", "\u7D42\u4E86", "End"],
784
+ ["orderField", "number", "\u9806\u5E8F", "Order"]
785
+ ].map(
786
+ ([setting, type, ja, en]) => /* @__PURE__ */ jsxs("label", { children: [
787
+ " ",
788
+ label(ja, en, context.locale),
789
+ " ",
790
+ /* @__PURE__ */ jsx(
791
+ ChoiceControl,
792
+ {
793
+ mode: "select",
794
+ "aria-label": label(ja, en, context.locale),
795
+ value: data?.[setting] ?? "",
796
+ disabled: busy,
797
+ options: [
798
+ { value: "", label: label("\u6307\u5B9A\u3057\u306A\u3044", "None", context.locale) },
799
+ ...tracker.fields.filter((field) => field.type === type).map((field) => ({ value: field.id, label: field.label }))
800
+ ],
801
+ onChange: (value) => void configure(setting, value)
802
+ }
803
+ )
804
+ ] }, setting)
805
+ )
806
+ ] }) : null,
807
+ !context.isStatic && [...data?.diagnostics ?? [], ...hierarchy.diagnostics].length > 0 ? /* @__PURE__ */ jsxs("div", { role: "alert", children: [
808
+ /* @__PURE__ */ jsx("h2", { children: label("WBS\u306E\u8A2D\u5B9A\u306B\u554F\u984C\u304C\u3042\u308A\u307E\u3059", "Check WBS definition", context.locale) }),
809
+ /* @__PURE__ */ jsx("ul", { children: [...data?.diagnostics ?? [], ...hierarchy.diagnostics].map(
810
+ (diagnostic, index) => /* @__PURE__ */ jsx("li", { children: resolveLocalizedText(diagnostic.message, context.locale) }, `${diagnostic.code}:${index}`)
811
+ ) })
812
+ ] }) : null,
813
+ busy || message ? /* @__PURE__ */ jsx("p", { role: "status", children: busy ? label("\u25CB \u4FDD\u5B58\u4E2D\u2026", "\u25CB Saving\u2026", context.locale) : message }) : null,
814
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "var(--space-3)", flexWrap: "wrap" }, children: [
815
+ /* @__PURE__ */ jsxs("label", { children: [
816
+ label("\u7BC4\u56F2", "Range", context.locale),
817
+ " ",
818
+ /* @__PURE__ */ jsx(
819
+ ChoiceControl,
820
+ {
821
+ mode: "select",
822
+ "aria-label": label("\u7BC4\u56F2", "Range", context.locale),
823
+ value: preset,
824
+ options: [
825
+ ...TIMELINE_PRESETS.map((item) => ({ value: item, label: label(
826
+ item === "2w" ? "2\u9031\u9593" : item === "1m" ? "1\u304B\u6708" : item === "3m" ? "3\u304B\u6708" : "6\u304B\u6708",
827
+ item === "2w" ? "2 weeks" : item === "1m" ? "1 month" : item === "3m" ? "3 months" : "6 months",
828
+ context.locale
829
+ ) })),
830
+ { value: "custom", label: label("\u671F\u9593\u3092\u6307\u5B9A\u2026", "Custom range\u2026", context.locale) }
831
+ ],
832
+ onChange: (value) => {
833
+ if (value === "custom") {
834
+ setPreset("custom");
835
+ setDraftRange(range);
836
+ return;
837
+ }
838
+ const nextPreset = timelinePreset(value);
839
+ if (!nextPreset) return;
840
+ setPreset(nextPreset);
841
+ context.setViewSettings({ ...settings(context), timelinePreset: nextPreset });
842
+ const next = presetRange(parseDate(range.from) ?? Date.now(), nextPreset);
843
+ changeRange(iso(next.start), iso(next.end - DAY_MS), next.mode);
844
+ }
845
+ }
846
+ )
847
+ ] }),
848
+ /* @__PURE__ */ jsx(Button, { onClick: () => reveal(Date.now() - 7 * DAY_MS), children: label("\u4ECA\u65E5", "Today", context.locale) }),
849
+ preset === "custom" ? /* @__PURE__ */ jsxs(Fragment, { children: [
850
+ /* @__PURE__ */ jsxs("label", { children: [
851
+ label("\u8868\u793A\u958B\u59CB", "Range start", context.locale),
852
+ " ",
853
+ /* @__PURE__ */ jsx(
854
+ InputControl,
855
+ {
856
+ type: "date",
857
+ "aria-label": label("\u8868\u793A\u958B\u59CB", "Range start", context.locale),
858
+ value: draftRange.from,
859
+ onChange: (event) => setDraftRange((current) => ({ ...current, from: event.target.value })),
860
+ onBlur: (event) => changeRange(event.currentTarget.value, draftRange.to || event.currentTarget.value),
861
+ onKeyDown: (event) => {
862
+ if (event.key === "Enter" || event.key === "Tab") changeRange(event.currentTarget.value, draftRange.to || event.currentTarget.value);
863
+ }
864
+ }
865
+ )
866
+ ] }),
867
+ /* @__PURE__ */ jsxs("label", { children: [
868
+ label("\u8868\u793A\u7D42\u4E86", "Range end", context.locale),
869
+ " ",
870
+ /* @__PURE__ */ jsx(
871
+ InputControl,
872
+ {
873
+ type: "date",
874
+ "aria-label": label("\u8868\u793A\u7D42\u4E86", "Range end", context.locale),
875
+ value: draftRange.to,
876
+ onChange: (event) => setDraftRange((current) => ({ ...current, to: event.target.value })),
877
+ onBlur: (event) => changeRange(draftRange.from || event.currentTarget.value, event.currentTarget.value),
878
+ onKeyDown: (event) => {
879
+ if (event.key === "Enter" || event.key === "Tab") changeRange(draftRange.from || event.currentTarget.value, event.currentTarget.value);
880
+ }
881
+ }
882
+ )
883
+ ] })
884
+ ] }) : null,
885
+ /* @__PURE__ */ jsxs("label", { children: [
886
+ label("\u76EE\u76DB\u308A", "Scale", context.locale),
887
+ " ",
888
+ /* @__PURE__ */ jsx(
889
+ ChoiceControl,
890
+ {
891
+ mode: "select",
892
+ "aria-label": label("\u76EE\u76DB\u308A", "Scale", context.locale),
893
+ value: mode,
894
+ onChange: (value) => changeRange(range.from, range.to, value),
895
+ options: [
896
+ { value: "day", label: label("\u65E5\u3054\u3068", "Daily", context.locale) },
897
+ { value: "week", label: label("\u9031\u3054\u3068", "Weekly", context.locale) }
898
+ ]
899
+ }
900
+ )
901
+ ] })
902
+ ] }),
903
+ tracker ? /* @__PURE__ */ jsx(
904
+ WBSGrid,
905
+ {
906
+ context,
907
+ data,
908
+ roots: hierarchy.roots,
909
+ rows,
910
+ review,
911
+ timeline,
912
+ busy,
913
+ movedName,
914
+ mode,
915
+ onReveal: reveal,
916
+ onParent: (row, parent) => void changeParent(row, parent),
917
+ onOrder: (siblings, index, delta) => void moveOrder(siblings, index, delta),
918
+ onDropOrder: (siblings, dragged, target, after) => void dropOrder(siblings, dragged, target, after),
919
+ onRenumber: (siblings) => void renumber(siblings),
920
+ onCreate: (parent) => {
921
+ if (parent) void createTask(parent);
922
+ }
923
+ },
924
+ context.target?.name
925
+ ) : /* @__PURE__ */ jsx("p", { children: label("\u30C1\u30B1\u30C3\u30C8\u7BA1\u7406\u306E\u5B9A\u7FA9\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093", "Tracker definition unavailable", context.locale) })
926
+ ]
927
+ }
928
+ );
929
+ }
930
+ function settings(context) {
931
+ const value = context.getViewSettings();
932
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
933
+ }
934
+ function WBSGrid({ context, data, roots, rows, review, timeline, mode, busy, movedName, ...actions }) {
935
+ const [collapsed, setCollapsed] = useState(() => {
936
+ const stored = settings(context).collapsed;
937
+ return new Set(Array.isArray(stored) ? stored.filter((name) => typeof name === "string" && rows.some((row) => row.name === name)) : []);
938
+ });
939
+ const [width, setWidth] = useState(() => {
940
+ const value = settings(context).leftWidth;
941
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(240, Math.min(560, value)) : 400;
942
+ });
943
+ const [measuredDayWidth, setMeasuredDayWidth] = useState();
944
+ const scrollRef = useRef(null);
945
+ const headerRef = useRef(null);
946
+ const probeRef = useRef(null);
947
+ const resizeStart = useRef(void 0);
948
+ const [viewport, setViewport] = useState({ top: 0, height: 600, rowHeight: 36 });
949
+ const names = new Set(rows.map((row) => row.name));
950
+ const missingRoots = roots.filter((node) => review.has(node.row.name) && data.parentField && !names.has(String(node.row.values[fieldKey(data.parentField)])));
951
+ const missing = new Set(flattenRows(missingRoots, data.orderField, context.locale, /* @__PURE__ */ new Set()).map((item) => item.node.row.name));
952
+ const groups = [
953
+ {
954
+ id: "tasks",
955
+ roots: roots.filter((node) => !review.has(node.row.name)),
956
+ count: rows.length - review.size,
957
+ title: label("\u30BF\u30B9\u30AF", "Tasks", context.locale)
958
+ },
959
+ {
960
+ id: "missing",
961
+ roots: missingRoots,
962
+ count: missing.size,
963
+ title: label("\u25B3 \u89AA\u304C\u898B\u3064\u304B\u3089\u306A\u3044\u30C1\u30B1\u30C3\u30C8", "\u25B3 Parent not found", context.locale)
964
+ },
965
+ {
966
+ id: "cycle",
967
+ roots: roots.filter((node) => review.has(node.row.name) && !missing.has(node.row.name)),
968
+ count: review.size - missing.size,
969
+ title: label("\u25B3 \u89AA\u5B50\u304C\u5FAA\u74B0\u3057\u3066\u3044\u308B\u30C1\u30B1\u30C3\u30C8", "\u25B3 Cyclic parent relationships", context.locale)
970
+ }
971
+ ];
972
+ const groupItems = groups.map((group) => flattenRows(group.roots, data.orderField, context.locale, collapsed));
973
+ const entries = [];
974
+ groups.forEach((group, index) => {
975
+ if (group.id !== "tasks" && group.count) entries.push({ group: index });
976
+ for (const item of groupItems[index]) entries.push({ group: index, item });
977
+ });
978
+ const days = timeline ? (timeline.end - timeline.start) / DAY_MS : 35;
979
+ const dayWidth = measuredDayWidth ?? (mode === "day" ? 24 : 9);
980
+ const tiers = timeline ? timelineCells(timeline, mode, dayWidth) : void 0;
981
+ const today = Math.floor(Date.now() / DAY_MS) * DAY_MS;
982
+ function persist(update) {
983
+ context.setViewSettings({ ...settings(context), ...update });
984
+ }
985
+ useEffect(() => {
986
+ const header = headerRef.current?.querySelector(".wbs-date-header");
987
+ if (!header || typeof ResizeObserver === "undefined") return;
988
+ const measure = () => {
989
+ const width2 = header.getBoundingClientRect().width;
990
+ if (width2 > 0) setMeasuredDayWidth(width2 / days);
991
+ };
992
+ measure();
993
+ const observer = new ResizeObserver(measure);
994
+ observer.observe(header);
995
+ return () => observer.disconnect();
996
+ }, [days, mode]);
997
+ useEffect(() => {
998
+ const valid = new Set(rows.map((row) => row.name));
999
+ const next = new Set([...collapsed].filter((name) => valid.has(name)));
1000
+ if (next.size !== collapsed.size) setCollapsed(next);
1001
+ persist({ collapsed: [...next] });
1002
+ }, [rows.map((row) => row.name).join("\n")]);
1003
+ useEffect(() => {
1004
+ const element = scrollRef.current;
1005
+ if (!element) return;
1006
+ const measure = () => setViewport({
1007
+ top: element.scrollTop,
1008
+ height: Math.max(0, element.clientHeight - (headerRef.current?.offsetHeight ?? 48)),
1009
+ rowHeight: probeRef.current?.getBoundingClientRect().height || 36
1010
+ });
1011
+ measure();
1012
+ if (typeof ResizeObserver === "undefined") return;
1013
+ const observer = new ResizeObserver(measure);
1014
+ observer.observe(element);
1015
+ if (probeRef.current) observer.observe(probeRef.current);
1016
+ return () => observer.disconnect();
1017
+ }, []);
1018
+ useEffect(() => {
1019
+ if (!movedName) return;
1020
+ const full = flattenRows(roots, data.orderField, context.locale, /* @__PURE__ */ new Set());
1021
+ const index = full.findIndex((item) => item.node.row.name === movedName);
1022
+ if (index < 0) return;
1023
+ const ancestors = [];
1024
+ let depth = full[index].depth;
1025
+ for (let i = index - 1; i >= 0 && depth > 0; i--) {
1026
+ if (full[i].depth < depth) {
1027
+ ancestors.push(full[i].node.row.name);
1028
+ depth = full[i].depth;
1029
+ }
1030
+ }
1031
+ setCollapsed((current) => {
1032
+ const next = new Set([...current].filter((name) => !ancestors.includes(name)));
1033
+ persist({ collapsed: [...next] });
1034
+ return next;
1035
+ });
1036
+ }, [movedName]);
1037
+ const strategy = entries.length > 300 ? "virtual" : "all";
1038
+ const window2 = rowWindow(entries.length, strategy, viewport.top, viewport.height, viewport.rowHeight, 0);
1039
+ const visible = entries.slice(window2.start, window2.end);
1040
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1041
+ /* @__PURE__ */ jsxs("div", { className: "wbs-toolbar", children: [
1042
+ /* @__PURE__ */ jsxs("span", { children: [
1043
+ label("\u30C1\u30B1\u30C3\u30C8", "Tickets", context.locale),
1044
+ ": ",
1045
+ rows.length
1046
+ ] }),
1047
+ review.size ? /* @__PURE__ */ jsx(Button, { onClick: () => {
1048
+ const index = entries.findIndex((entry) => !entry.item);
1049
+ if (index < 0 || !scrollRef.current) return;
1050
+ const top = index * viewport.rowHeight;
1051
+ scrollRef.current.scrollTop = top;
1052
+ setViewport((current) => ({ ...current, top: scrollRef.current?.scrollTop ?? top }));
1053
+ }, children: label(`\u25B3 \u8981\u78BA\u8A8D ${review.size}\u4EF6`, `\u25B3 Needs attention: ${review.size}`, context.locale) }) : null
1054
+ ] }),
1055
+ data.tracker?.summary?.length ? /* @__PURE__ */ jsx(
1056
+ "section",
1057
+ {
1058
+ className: "wbs-summary",
1059
+ "aria-live": "polite",
1060
+ "aria-label": label("\u8868\u793A\u4E2D\u306E\u30C1\u30B1\u30C3\u30C8\u306E\u96C6\u8A08", "Visible tickets summary", context.locale),
1061
+ children: /* @__PURE__ */ jsx("ul", { children: data.tracker.summary.map(({ field, method, groupBy }, index) => {
1062
+ const result = summarizeRows(rows, fieldKey(field.id), field.type, method, context.locale, {
1063
+ ...field.options ? { valueLabels: field.options } : {},
1064
+ ...groupBy ? { groupBy: { key: fieldKey(groupBy.id), type: groupBy.type, order: groupBy.type === "select" ? groupBy.options?.map((option) => option.value) : void 0, labels: groupBy.options, labelOf: groupBy.type === "reference" ? (value) => context.rows.find((row) => row.name === value)?.title ?? value : void 0 } } : {}
1065
+ });
1066
+ return /* @__PURE__ */ jsxs("li", { children: [
1067
+ field.label,
1068
+ " ",
1069
+ result.text,
1070
+ result.excluded ? ` (${label("\u5024\u306E\u5F62\u5F0F\u304C\u5408\u308F\u306A\u3044\u305F\u3081\u96C6\u8A08\u304B\u3089\u9664\u5916", "Invalid values excluded", context.locale)}: ${result.excluded})` : "",
1071
+ result.multiCounted ? /* @__PURE__ */ jsxs("span", { children: [
1072
+ " ",
1073
+ label("\u8907\u6570\u306E\u5024\u3092\u6301\u3064\u30C1\u30B1\u30C3\u30C8\u306F\u3001\u305D\u308C\u305E\u308C\u306E\u5024\u3067\u6570\u3048\u3066\u3044\u307E\u3059", "Counted in multiple groups", context.locale)
1074
+ ] }) : null,
1075
+ result.groups ? /* @__PURE__ */ jsx("ul", { children: result.groups.map((group) => /* @__PURE__ */ jsxs("li", { children: [
1076
+ group.label,
1077
+ ": ",
1078
+ group.text,
1079
+ group.excluded ? ` (${label("\u5024\u306E\u5F62\u5F0F\u304C\u5408\u308F\u306A\u3044\u305F\u3081\u96C6\u8A08\u304B\u3089\u9664\u5916", "Invalid values excluded", context.locale)}: ${group.excluded})` : ""
1080
+ ] }, group.value ?? "__unset")) }) : null
1081
+ ] }, `${field.id}-${method}-${index}`);
1082
+ }) })
1083
+ }
1084
+ ) : null,
1085
+ /* @__PURE__ */ jsxs(
1086
+ "div",
1087
+ {
1088
+ ref: scrollRef,
1089
+ className: "wbs-scroll",
1090
+ style: { "--wbs-left-width": `${width}px` },
1091
+ onScroll: (event) => {
1092
+ const top = event.currentTarget.scrollTop;
1093
+ setViewport((current) => ({ ...current, top }));
1094
+ },
1095
+ children: [
1096
+ /* @__PURE__ */ jsx("div", { ref: probeRef, className: "wbs-row wbs-probe", "aria-hidden": "true" }),
1097
+ /* @__PURE__ */ jsxs(
1098
+ "div",
1099
+ {
1100
+ role: "treegrid",
1101
+ "aria-label": label("WBS\u306E\u968E\u5C64", "WBS hierarchy", context.locale),
1102
+ "aria-rowcount": entries.length + 1,
1103
+ className: "wbs-grid",
1104
+ "data-mode": mode,
1105
+ style: {
1106
+ "--wbs-days": days,
1107
+ "--wbs-day-width": `${dayWidth}px`,
1108
+ "--wbs-today-offset": timeline ? (today - timeline.start) / DAY_MS : 0
1109
+ },
1110
+ children: [
1111
+ timeline && today >= timeline.start && today < timeline.end ? /* @__PURE__ */ jsx(
1112
+ "span",
1113
+ {
1114
+ "aria-hidden": "true",
1115
+ className: "wbs-today-line"
1116
+ }
1117
+ ) : null,
1118
+ /* @__PURE__ */ jsxs("div", { role: "row", className: "wbs-header wbs-row", ref: headerRef, children: [
1119
+ /* @__PURE__ */ jsxs("strong", { role: "columnheader", className: "wbs-left", children: [
1120
+ label("\u30C1\u30B1\u30C3\u30C8", "Task", context.locale),
1121
+ /* @__PURE__ */ jsx(
1122
+ "span",
1123
+ {
1124
+ role: "separator",
1125
+ "aria-label": label("\u30C1\u30B1\u30C3\u30C8\u5217\u306E\u5E45", "Task column width", context.locale),
1126
+ "aria-orientation": "vertical",
1127
+ "aria-valuemin": 240,
1128
+ "aria-valuemax": 560,
1129
+ "aria-valuenow": width,
1130
+ tabIndex: 0,
1131
+ className: "wbs-resizer",
1132
+ onKeyDown: (event) => {
1133
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
1134
+ event.preventDefault();
1135
+ const next = Math.max(240, Math.min(560, width + (event.key === "ArrowLeft" ? -16 : 16)));
1136
+ setWidth(next);
1137
+ persist({ leftWidth: next });
1138
+ },
1139
+ onPointerDown: (event) => {
1140
+ resizeStart.current = { x: event.clientX, width };
1141
+ event.currentTarget.setPointerCapture(event.pointerId);
1142
+ },
1143
+ onPointerMove: (event) => {
1144
+ if (resizeStart.current) setWidth(Math.max(240, Math.min(
1145
+ 560,
1146
+ resizeStart.current.width + event.clientX - resizeStart.current.x
1147
+ )));
1148
+ },
1149
+ onPointerUp: () => {
1150
+ resizeStart.current = void 0;
1151
+ persist({ leftWidth: width });
1152
+ },
1153
+ onPointerCancel: () => {
1154
+ resizeStart.current = void 0;
1155
+ }
1156
+ }
1157
+ )
1158
+ ] }),
1159
+ /* @__PURE__ */ jsx("div", { role: "columnheader", "aria-label": label("\u65E5\u7A0B\u8868", "Date timeline", context.locale), className: "wbs-date-header", children: tiers ? /* @__PURE__ */ jsxs(Fragment, { children: [
1160
+ /* @__PURE__ */ jsx("div", { className: "wbs-month-tier", children: tiers.months.map((cell) => /* @__PURE__ */ jsx(
1161
+ "span",
1162
+ {
1163
+ style: { left: `${cell.left / (days * dayWidth) * 100}%`, width: `${cell.width / (days * dayWidth) * 100}%` },
1164
+ children: cell.labelSize === "none" ? "" : new Intl.DateTimeFormat(context.locale, {
1165
+ month: "short",
1166
+ ...cell.labelSize === "long" ? { year: "numeric" } : {},
1167
+ timeZone: "UTC"
1168
+ }).format(cell.timestamp)
1169
+ },
1170
+ cell.timestamp
1171
+ )) }),
1172
+ /* @__PURE__ */ jsx("div", { className: "wbs-tick-tier", children: tiers.cells.map((cell) => /* @__PURE__ */ jsx(
1173
+ "span",
1174
+ {
1175
+ title: new Date(cell.timestamp).toISOString().slice(0, 10),
1176
+ "data-weekend": mode === "day" && [0, 6].includes(new Date(cell.timestamp).getUTCDay()) || void 0,
1177
+ "data-monday": new Date(cell.timestamp).getUTCDay() === 1 || void 0,
1178
+ "data-current": mode === "day" ? cell.timestamp === today || void 0 : cell.timestamp === mondayOnOrBefore(today) || void 0,
1179
+ style: { left: `${cell.left / (days * dayWidth) * 100}%`, width: `${cell.width / (days * dayWidth) * 100}%` },
1180
+ children: cell.showLabel ? mode === "day" ? new Date(cell.timestamp).getUTCDate() : `${new Date(cell.timestamp).getUTCMonth() + 1}/${new Date(cell.timestamp).getUTCDate()}` : ""
1181
+ },
1182
+ cell.timestamp
1183
+ )) })
1184
+ ] }) : /* @__PURE__ */ jsx("span", { children: label("\u958B\u59CB\u65E5\u304B\u7D42\u4E86\u65E5\u3092\u5165\u308C\u308B\u3068\u3001\u65E5\u7A0B\u8868\u306B\u8868\u793A\u3055\u308C\u307E\u3059", "Add dates to show the timeline", context.locale) }) })
1185
+ ] }),
1186
+ window2.start > 0 ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", style: { height: window2.start * viewport.rowHeight } }) : null,
1187
+ groups.map((group, index) => visible.some((entry) => entry.group === index) ? /* @__PURE__ */ jsxs("div", { role: "rowgroup", "aria-label": group.title, children: [
1188
+ visible.some((entry) => entry.group === index && !entry.item) ? /* @__PURE__ */ jsxs("div", { role: "row", className: "wbs-review-heading", children: [
1189
+ /* @__PURE__ */ jsxs("span", { role: "gridcell", title: `${group.title}\uFF08${group.count}\uFF09`, children: [
1190
+ /* @__PURE__ */ jsx("span", { className: "wbs-review-title", children: group.title }),
1191
+ /* @__PURE__ */ jsxs("span", { children: [
1192
+ "\uFF08",
1193
+ group.count,
1194
+ "\uFF09"
1195
+ ] })
1196
+ ] }),
1197
+ /* @__PURE__ */ jsx("span", { role: "gridcell", className: "wbs-review-description", children: !context.isStatic ? group.id === "missing" ? label("\u89AA\u306B\u6307\u5B9A\u3055\u308C\u305F\u30C1\u30B1\u30C3\u30C8\u304C\u5B58\u5728\u3057\u307E\u305B\u3093\u3002\u89AA\u3092\u5909\u66F4\u3059\u308B\u304B\u3001\u89AA\u3092\u7A7A\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002", "The parent ticket does not exist. Change or clear the parent.", context.locale) : label("\u89AA\u3092\u305F\u3069\u308B\u3068\u81EA\u5206\u306B\u623B\u308A\u307E\u3059\u3002\u3069\u3061\u3089\u304B\u306E\u89AA\u3092\u5909\u66F4\u3057\u3066\u304F\u3060\u3055\u3044\u3002", "Following parents returns to the same ticket. Change one of the parents.", context.locale) : null })
1198
+ ] }) : null,
1199
+ /* @__PURE__ */ jsx(
1200
+ WBSRows,
1201
+ {
1202
+ items: visible.flatMap((entry) => entry.group === index && entry.item ? [entry.item] : []),
1203
+ data,
1204
+ context,
1205
+ all: rows,
1206
+ review,
1207
+ movedName,
1208
+ timeline,
1209
+ busy,
1210
+ collapsed,
1211
+ onToggle: (name) => {
1212
+ const next = new Set(collapsed);
1213
+ if (next.has(name)) next.delete(name);
1214
+ else next.add(name);
1215
+ setCollapsed(next);
1216
+ persist({ collapsed: [...next] });
1217
+ },
1218
+ ...actions
1219
+ }
1220
+ )
1221
+ ] }, group.id) : null),
1222
+ strategy === "virtual" && window2.end < entries.length ? /* @__PURE__ */ jsx(
1223
+ "div",
1224
+ {
1225
+ "aria-hidden": "true",
1226
+ style: { height: (entries.length - window2.end) * viewport.rowHeight }
1227
+ }
1228
+ ) : null
1229
+ ]
1230
+ }
1231
+ )
1232
+ ]
1233
+ }
1234
+ )
1235
+ ] });
1236
+ }
1237
+
1238
+ // src/browser.ts
1239
+ var browser_default = defineBrowserPlugin({
1240
+ activate(host) {
1241
+ host.registerViewRenderer(WBS_VIEW_ID, reactRenderer(WBSScreen));
1242
+ }
1243
+ });
1244
+ export {
1245
+ browser_default as default
1246
+ };