@kubohiroya/turbowarp-plus-editor-code-views 0.16.0 → 0.17.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.
@@ -334,10 +334,14 @@ export interface SavedPaletteVisibility {
334
334
  order?: SavedPaletteOrder;
335
335
  }
336
336
 
337
- /** The order the palette's categories were dragged into: the top level, and the members of each group, by ID. */
337
+ /**
338
+ * The order the palette's categories were dragged into: the top level, and the members of each group, by ID; and the
339
+ * groups pinned open, whose members the palette shows in place of the group's child palette.
340
+ */
338
341
  export interface SavedPaletteOrder {
339
342
  categories?: string[];
340
343
  groups?: Record<string, string[]>;
344
+ pinned?: string[];
341
345
  }
342
346
 
343
347
  /** The order the palette's categories were dragged into, for the whole project. */
@@ -348,7 +352,12 @@ export interface PaletteOrder {
348
352
  /** A group's members, by ID, in order, or nothing when they were never reordered. */
349
353
  members(groupId: string): string[] | undefined;
350
354
  setMembers(groupId: string, ids: readonly string[]): void;
351
- /** The order to save, or nothing when nothing was reordered. */
355
+ /** Whether the group is pinned open, its members shown in the palette that shows the group. */
356
+ isPinned(groupId: string): boolean;
357
+ setPinned(groupId: string, pinned: boolean): void;
358
+ /** Calls `listener` after anything changes, including a loaded or forgotten order. Returns the function that stops. */
359
+ subscribe(listener: () => void): () => void;
360
+ /** The order to save, or nothing when nothing was reordered or pinned. */
352
361
  capture(): SavedPaletteOrder | undefined;
353
362
  /** Takes a saved order. A value that is not one leaves the palette in its own order. */
354
363
  apply(value: unknown): void;
@@ -359,39 +368,66 @@ export interface PaletteOrder {
359
368
  export function createPaletteOrder({onChange}: {onChange?(): void} = {}): PaletteOrder {
360
369
  let categories: string[] = [];
361
370
  let groups = new Map<string, string[]>();
371
+ let pinned = new Set<string>();
372
+ const listeners = new Set<() => void>();
373
+ const notify = () => {
374
+ for (const listener of [...listeners]) listener();
375
+ };
376
+ const changed = () => {
377
+ onChange?.();
378
+ notify();
379
+ };
362
380
  return {
363
381
  categories: () => [...categories],
364
382
  setCategories(ids) {
365
383
  categories = [...ids];
366
- onChange?.();
384
+ changed();
367
385
  },
368
386
  members: groupId => groups.has(groupId) ? [...groups.get(groupId)!] : undefined,
369
387
  setMembers(groupId, ids) {
370
388
  groups.set(groupId, [...ids]);
371
- onChange?.();
389
+ changed();
390
+ },
391
+ isPinned: groupId => pinned.has(groupId),
392
+ setPinned(groupId, value) {
393
+ if (pinned.has(groupId) === value) return;
394
+ if (value) pinned.add(groupId);
395
+ else pinned.delete(groupId);
396
+ changed();
397
+ },
398
+ subscribe(listener) {
399
+ listeners.add(listener);
400
+ return () => listeners.delete(listener);
372
401
  },
373
402
  capture() {
374
403
  const saved: SavedPaletteOrder = {};
375
404
  if (categories.length) saved.categories = [...categories];
376
405
  if (groups.size) saved.groups = Object.fromEntries([...groups].map(([id, ids]) => [id, [...ids]]));
377
- return saved.categories || saved.groups ? saved : undefined;
406
+ if (pinned.size) saved.pinned = [...pinned];
407
+ return saved.categories || saved.groups || saved.pinned ? saved : undefined;
378
408
  },
379
409
  apply(value) {
380
410
  categories = [];
381
411
  groups = new Map();
382
- if (!value || typeof value !== 'object') return;
383
- const saved = value as Record<string, unknown>;
384
- categories = strings(saved.categories) ?? [];
385
- if (saved.groups && typeof saved.groups === 'object' && !Array.isArray(saved.groups)) {
386
- for (const [id, ids] of Object.entries(saved.groups as Record<string, unknown>)) {
387
- const members = strings(ids);
388
- if (members) groups.set(id, members);
412
+ pinned = new Set();
413
+ if (value && typeof value === 'object') {
414
+ const saved = value as Record<string, unknown>;
415
+ categories = strings(saved.categories) ?? [];
416
+ if (saved.groups && typeof saved.groups === 'object' && !Array.isArray(saved.groups)) {
417
+ for (const [id, ids] of Object.entries(saved.groups as Record<string, unknown>)) {
418
+ const members = strings(ids);
419
+ if (members) groups.set(id, members);
420
+ }
389
421
  }
422
+ pinned = new Set(strings(saved.pinned) ?? []);
390
423
  }
424
+ notify();
391
425
  },
392
426
  reset() {
393
427
  categories = [];
394
428
  groups = new Map();
429
+ pinned = new Set();
430
+ notify();
395
431
  }
396
432
  };
397
433
  }
package/src/styles.css CHANGED
@@ -103,6 +103,7 @@
103
103
  }
104
104
 
105
105
  .tw-detached-palette__content {
106
+ position: relative;
106
107
  min-height: 0;
107
108
  display: grid;
108
109
  grid-template: "categories blocks" minmax(0, 1fr) / auto minmax(0, 1fr);
@@ -155,7 +156,16 @@
155
156
  cursor: pointer;
156
157
  }
157
158
 
159
+ .tw-detached-palette__category {
160
+ display: contents;
161
+ }
162
+
163
+ .tw-detached-palette__category[hidden] {
164
+ display: none;
165
+ }
166
+
158
167
  .tw-detached-palette__categories button {
168
+ position: relative;
159
169
  display: grid;
160
170
  place-items: center;
161
171
  inline-size: 40px;
@@ -1043,3 +1053,54 @@
1043
1053
  border-color: transparent transparent currentColor transparent;
1044
1054
  opacity: 0.55;
1045
1055
  }
1056
+
1057
+ /* The pin of a group: a child palette pins its group open; a pinned group's icon folds it back. */
1058
+ .tw-palette-group-pin {
1059
+ position: absolute;
1060
+ top: 1px;
1061
+ inset-inline-end: 1px;
1062
+ z-index: 1;
1063
+ inline-size: 14px;
1064
+ block-size: 14px;
1065
+ border-radius: 3px;
1066
+ background-color: currentColor;
1067
+ opacity: 0.6;
1068
+ cursor: pointer;
1069
+ mask: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 16 16%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.4%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z%22/%3E%3Cpath d=%22m7.5 8.5-4 4%22/%3E%3Cpath d=%22M2 2l12 12%22 stroke-linecap=%22round%22/%3E%3C/svg%3E") center / 12px 12px no-repeat;
1070
+ }
1071
+
1072
+ .tw-palette-group-pin[data-palette-group-pin="pinned"] {
1073
+ mask-image: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 16 16%22 fill=%22none%22 stroke=%22black%22 stroke-width=%221.4%22 stroke-linejoin=%22round%22%3E%3Cpath d=%22M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z%22/%3E%3Cpath d=%22m7.5 8.5-4 4%22/%3E%3C/svg%3E");
1074
+ opacity: 0.85;
1075
+ }
1076
+
1077
+ .tw-palette-group-pin:hover,
1078
+ .tw-palette-group-pin:focus-visible {
1079
+ opacity: 1;
1080
+ outline: none;
1081
+ }
1082
+
1083
+ /* Room for the pin at the child palette's top right. */
1084
+ .tw-palette-group-popup {
1085
+ padding-top: 1rem;
1086
+ }
1087
+
1088
+ .tw-palette-group-popup[data-horizontal] {
1089
+ padding-top: 0.25rem;
1090
+ padding-inline-end: 1.1rem;
1091
+ }
1092
+
1093
+ .tw-palette-group-popup > .tw-palette-group-pin {
1094
+ top: 3px;
1095
+ inset-inline-end: 3px;
1096
+ }
1097
+
1098
+ /* A pinned group shows its pin in place of the mark that it opens further. */
1099
+ .tw-palette-group[data-palette-group-pinned]::after,
1100
+ .tw-palette-group-item[data-palette-group-pinned]::after {
1101
+ display: none;
1102
+ }
1103
+
1104
+ .tw-palette-group-item[data-palette-group-pinned] {
1105
+ position: relative;
1106
+ }