deictic 0.0.1 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/annotations/client.d.ts +4 -0
- package/dist/annotations/client.d.ts.map +1 -0
- package/dist/annotations/client.js +497 -0
- package/dist/annotations/client.js.map +1 -0
- package/dist/annotations/index.d.ts +110 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/index.js +22 -0
- package/dist/annotations/index.js.map +1 -0
- package/dist/astro.d.ts +29 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +24 -0
- package/dist/astro.js.map +1 -0
- package/dist/bun.d.ts +12 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +67 -0
- package/dist/bun.js.map +1 -0
- package/dist/client/index.d.ts +93 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1329 -0
- package/dist/client/index.js.map +1 -0
- package/dist/endpoints.js +354 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.d.ts +23 -0
- package/dist/index3.d.ts +98 -0
- package/dist/index3.d.ts.map +1 -0
- package/dist/index4.d.ts +74 -0
- package/dist/index4.d.ts.map +1 -0
- package/dist/index5.d.ts +70 -0
- package/dist/index5.d.ts.map +1 -0
- package/dist/integration.d.ts +19 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +277 -0
- package/dist/integration.js.map +1 -0
- package/dist/kept.js +23 -0
- package/dist/kept.js.map +1 -0
- package/dist/loader.d.ts +15 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +17 -0
- package/dist/loader.js.map +1 -0
- package/dist/marks.js +14 -0
- package/dist/marks.js.map +1 -0
- package/dist/next.d.ts +17 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +150 -0
- package/dist/next.js.map +1 -0
- package/dist/playwright.js +105 -0
- package/dist/playwright.js.map +1 -0
- package/dist/recommended/index.d.ts +25 -0
- package/dist/recommended/index.d.ts.map +1 -0
- package/dist/recommended/index.js +19 -0
- package/dist/recommended/index.js.map +1 -0
- package/dist/recordings/client.d.ts +4 -0
- package/dist/recordings/client.d.ts.map +1 -0
- package/dist/recordings/client.js +376 -0
- package/dist/recordings/client.js.map +1 -0
- package/dist/recordings/index.d.ts +2 -0
- package/dist/recordings/index.js +3 -0
- package/dist/recordings.js +235 -0
- package/dist/recordings.js.map +1 -0
- package/dist/screenshots/client.d.ts +23 -0
- package/dist/screenshots/client.d.ts.map +1 -0
- package/dist/screenshots/client.js +76 -0
- package/dist/screenshots/client.js.map +1 -0
- package/dist/screenshots/dom.d.ts +4 -0
- package/dist/screenshots/dom.d.ts.map +1 -0
- package/dist/screenshots/dom.js +92 -0
- package/dist/screenshots/dom.js.map +1 -0
- package/dist/screenshots/index.d.ts +2 -0
- package/dist/screenshots/index.js +98 -0
- package/dist/screenshots/index.js.map +1 -0
- package/dist/screenshots/rrweb.d.ts +9 -0
- package/dist/screenshots/rrweb.d.ts.map +1 -0
- package/dist/screenshots/rrweb.js +60 -0
- package/dist/screenshots/rrweb.js.map +1 -0
- package/dist/shortcut.js +63 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/tailwind/client.d.ts +4 -0
- package/dist/tailwind/client.d.ts.map +1 -0
- package/dist/tailwind/client.js +613 -0
- package/dist/tailwind/client.js.map +1 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +557 -0
- package/dist/tailwind/index.js.map +1 -0
- package/dist/tasks/client.d.ts +6 -0
- package/dist/tasks/client.d.ts.map +1 -0
- package/dist/tasks/client.js +642 -0
- package/dist/tasks/client.js.map +1 -0
- package/dist/tasks/index.d.ts +159 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +348 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/vite.d.ts +17 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +44 -0
- package/dist/vite.js.map +1 -0
- package/dist/voice/client.d.ts +4 -0
- package/dist/voice/client.d.ts.map +1 -0
- package/dist/voice/client.js +66 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/index.d.ts +47 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +74 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/waveform.js +93 -0
- package/dist/waveform.js.map +1 -0
- package/dist/webpack.d.ts +50 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +78 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +307 -7
- package/skills/deictic/SKILL.md +47 -0
- package/skills/deictic/references/install.md +81 -0
- package/skills/deictic/references/recordings.md +83 -0
- package/skills/deictic/references/tasks.md +79 -0
- package/skills/deictic/references/watch.md +43 -0
- package/skills/deictic/scripts/frame.mjs +62 -0
- package/skills/deictic/scripts/lib.mjs +193 -0
- package/skills/deictic/scripts/recording.mjs +186 -0
- package/skills/deictic/scripts/task.mjs +84 -0
- package/skills/deictic/scripts/transcribe.mjs +93 -0
- package/skills/deictic/scripts/voice.mjs +50 -0
- package/skills/deictic/scripts/watch.mjs +51 -0
- package/src/astro.ts +34 -0
- package/src/bun.ts +79 -0
- package/src/client/index.ts +833 -0
- package/src/client/lightbox.ts +256 -0
- package/src/client/style.ts +243 -0
- package/src/client/tooltip.ts +78 -0
- package/src/client/waveform.ts +98 -0
- package/src/index.ts +240 -0
- package/src/loader.ts +28 -0
- package/src/next.ts +133 -0
- package/src/plugins/annotations/client.ts +301 -0
- package/src/plugins/annotations/draw.ts +169 -0
- package/src/plugins/annotations/index.ts +105 -0
- package/src/plugins/annotations/svg.ts +61 -0
- package/src/plugins/recommended/index.ts +35 -0
- package/src/plugins/recordings/client.ts +315 -0
- package/src/plugins/recordings/index.ts +174 -0
- package/src/plugins/recordings/marks.ts +11 -0
- package/src/plugins/recordings/ours.ts +70 -0
- package/src/plugins/recordings/replay.ts +139 -0
- package/src/plugins/screenshots/client.ts +63 -0
- package/src/plugins/screenshots/dom.ts +79 -0
- package/src/plugins/screenshots/index.ts +194 -0
- package/src/plugins/screenshots/playwright.ts +119 -0
- package/src/plugins/screenshots/rrweb.ts +45 -0
- package/src/plugins/tailwind/catalog.ts +396 -0
- package/src/plugins/tailwind/client.ts +669 -0
- package/src/plugins/tailwind/index.ts +267 -0
- package/src/plugins/tasks/client.ts +622 -0
- package/src/plugins/tasks/index.ts +513 -0
- package/src/plugins/voice/client.ts +57 -0
- package/src/plugins/voice/index.ts +114 -0
- package/src/shortcut.ts +83 -0
- package/src/tools/astro.ts +81 -0
- package/src/tools/editor.ts +22 -0
- package/src/tools/endpoints.ts +163 -0
- package/src/tools/history.ts +203 -0
- package/src/tools/integration.ts +106 -0
- package/src/tools/kept.ts +21 -0
- package/src/tools/locate.ts +94 -0
- package/src/tools/plugins.ts +41 -0
- package/src/tools/source.ts +72 -0
- package/src/vite.ts +62 -0
- package/src/webpack.ts +107 -0
- package/index.js +0 -1
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tailwind's panel: the element's classes as chips, a field to add more, and Save. Every change
|
|
3
|
+
* previews on the page at once, on every element from the same place in the source, keeping the
|
|
4
|
+
* classes the source adds at runtime; closing without saving puts the page back.
|
|
5
|
+
*
|
|
6
|
+
* Where a class helper adds more on a condition (`cn('…', active && '…')`), each condition whose classes are a
|
|
7
|
+
* string in the file is a state to pick, beside the element's own list: picked, its classes are the chips, and
|
|
8
|
+
* they show on the clicked element whether or not the condition holds there. A dot marks the ones that do hold,
|
|
9
|
+
* read from the element's classes, which is all the page says of a condition.
|
|
10
|
+
*
|
|
11
|
+
* What the project's Tailwind knows comes from the server half's routes. The field completes the word being
|
|
12
|
+
* typed. A chip of a class Tailwind knows shows what it sets (a colour's swatch, a size's value) and opens the
|
|
13
|
+
* classes of its kind to switch between, with a field for a value of one's own (`text-[13px]`). A class no file
|
|
14
|
+
* used before has no CSS in the page's build until it's saved, so the preview brings its own, in a style of the
|
|
15
|
+
* page's that goes as the panel does. The completions and a chip's kind open in boxes of their own beside the popup
|
|
16
|
+
* (in the overlay's root, placed each frame), so the popup keeps its size and nothing in it moves. Without Tailwind v4 the chips are plain and nothing completes.
|
|
17
|
+
*/
|
|
18
|
+
import { defineClientPlugin } from '#src/index.ts';
|
|
19
|
+
|
|
20
|
+
import type { Alternatives, ClassInfo, Model, Op } from './index.ts';
|
|
21
|
+
|
|
22
|
+
const STYLE = `
|
|
23
|
+
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
|
|
24
|
+
.chip { display: inline-flex; align-items: stretch; border: 1px solid var(--deictic-line); border-radius: 4px; font: 12px/20px ui-monospace, monospace; }
|
|
25
|
+
.chip.open { border-color: var(--deictic-accent); }
|
|
26
|
+
.chip .name { display: inline-flex; align-items: center; gap: 5px; padding: 0 2px 0 6px; border: 0; border-radius: 3px 0 0 3px; font: inherit; }
|
|
27
|
+
.chip button.name:hover { background: rgb(255 255 255 / 0.08); }
|
|
28
|
+
.chip .x { border: 0; padding: 0 5px; color: var(--deictic-muted); }
|
|
29
|
+
.chip .x:hover { color: var(--deictic-problem); }
|
|
30
|
+
/* A colour over a checker, so one that's part clear shows it. */
|
|
31
|
+
.swatch {
|
|
32
|
+
flex: none;
|
|
33
|
+
width: 10px;
|
|
34
|
+
height: 10px;
|
|
35
|
+
border-radius: 2px;
|
|
36
|
+
box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
|
|
37
|
+
background: linear-gradient(var(--c), var(--c)), repeating-conic-gradient(#71717a 0 25%, #d4d4d8 0 50%) 0 0 / 6px 6px;
|
|
38
|
+
}
|
|
39
|
+
.hint { color: var(--deictic-muted); }
|
|
40
|
+
/* Beside the popup, not in it: in its flow they'd resize it under the pointer with every word and click. */
|
|
41
|
+
.editor, .suggest {
|
|
42
|
+
position: fixed;
|
|
43
|
+
left: 0;
|
|
44
|
+
top: 0;
|
|
45
|
+
z-index: 2147483647;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
border: 1px solid var(--deictic-line);
|
|
48
|
+
border-radius: 6px;
|
|
49
|
+
font: 13px/1.4 system-ui, sans-serif;
|
|
50
|
+
color: var(--deictic-fg);
|
|
51
|
+
background: var(--deictic-bg);
|
|
52
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
|
|
53
|
+
}
|
|
54
|
+
.editor[hidden], .suggest[hidden] { display: none; }
|
|
55
|
+
.editor .top { display: flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }
|
|
56
|
+
.editor .top button:first-of-type { margin-left: auto; }
|
|
57
|
+
.editor .top .more { padding: 0 6px; font: 12px/18px system-ui, sans-serif; }
|
|
58
|
+
.editor .top .more[aria-expanded='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }
|
|
59
|
+
.custom[hidden] { display: none; }
|
|
60
|
+
.alts { position: relative; display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; padding: 2px 8px 8px; overflow: auto; }
|
|
61
|
+
.alts button { display: inline-flex; align-items: center; gap: 5px; padding: 0 6px; font: 12px/20px ui-monospace, monospace; }
|
|
62
|
+
.alts button[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-accent); }
|
|
63
|
+
.alts .family { display: flex; gap: 2px; flex-basis: 100%; }
|
|
64
|
+
.alts .family button { padding: 0; border: 0; border-radius: 3px; }
|
|
65
|
+
.alts .family .swatch { width: 18px; height: 18px; border-radius: 3px; }
|
|
66
|
+
.alts .family button[aria-pressed='true'] { outline: 2px solid var(--deictic-fg); outline-offset: 1px; }
|
|
67
|
+
.custom { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--deictic-line); }
|
|
68
|
+
.custom input[type='color'] { flex: none; width: 28px; height: 24px; padding: 1px; cursor: pointer; }
|
|
69
|
+
.custom input[aria-invalid='true'] { border-color: var(--deictic-problem); }
|
|
70
|
+
.suggest { max-height: 168px; overflow: auto; }
|
|
71
|
+
.option { display: flex; align-items: center; gap: 6px; padding: 1px 6px; font: 12px/20px ui-monospace, monospace; cursor: pointer; }
|
|
72
|
+
.option[aria-selected='true'] { background: rgb(255 255 255 / 0.1); }
|
|
73
|
+
.option .hint { margin-left: auto; }
|
|
74
|
+
.row { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; align-items: center; }
|
|
75
|
+
.states { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
|
|
76
|
+
.state { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 0 8px; border-radius: 999px; font: 12px/20px ui-monospace, monospace; color: var(--deictic-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
77
|
+
.state[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }
|
|
78
|
+
.state .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--deictic-accent); }
|
|
79
|
+
.note { margin: -2px 0 8px; font-size: 12px; color: var(--deictic-muted); }
|
|
80
|
+
.note:empty { display: none; }
|
|
81
|
+
.note code { color: var(--deictic-fg); }
|
|
82
|
+
.extras { display: grid; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--deictic-line); font-size: 12px; color: var(--deictic-muted); }
|
|
83
|
+
.extra { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
|
|
84
|
+
.extra .when { flex-basis: 100%; }
|
|
85
|
+
.extra code { color: var(--deictic-fg); }
|
|
86
|
+
/* The code's own classes: shown, not edited here, and faint while their condition doesn't hold. */
|
|
87
|
+
.chip.fixed { border-style: dashed; }
|
|
88
|
+
.chip.fixed .name { padding-right: 6px; }
|
|
89
|
+
.chip.fixed.off { opacity: 0.45; }
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const split = (list: string) => list.split(/\s+/).filter(Boolean);
|
|
93
|
+
|
|
94
|
+
/** A list of classes to edit: the element's own, or those one of the helper's arguments adds (`at`, its place). */
|
|
95
|
+
interface State {
|
|
96
|
+
at?: number;
|
|
97
|
+
label: string;
|
|
98
|
+
saved: string[];
|
|
99
|
+
draft: string[];
|
|
100
|
+
}
|
|
101
|
+
/** The family a shade is of: `bg-red` for `bg-red-500`. */
|
|
102
|
+
const familyOf = (name: string) => /^(.*)-\d+(\/[^/]*)?!?$/.exec(name)?.[1];
|
|
103
|
+
|
|
104
|
+
function make<Tag extends keyof HTMLElementTagNameMap>(tag: Tag, className: string, text?: string): HTMLElementTagNameMap[Tag] {
|
|
105
|
+
const el = document.createElement(tag);
|
|
106
|
+
el.className = className;
|
|
107
|
+
if (text !== undefined) el.textContent = text;
|
|
108
|
+
if (el instanceof HTMLButtonElement) el.type = 'button';
|
|
109
|
+
return el;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function swatch(color: string): HTMLElement {
|
|
113
|
+
const el = make('span', 'swatch');
|
|
114
|
+
// A custom property takes any text, and one that isn't a colour draws nothing.
|
|
115
|
+
el.style.setProperty('--c', color);
|
|
116
|
+
return el;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A class as it reads everywhere: its colour, its name, and what it sets where the name doesn't say. */
|
|
120
|
+
function face(into: HTMLElement, info: ClassInfo) {
|
|
121
|
+
if (info.color !== undefined) into.append(swatch(info.color));
|
|
122
|
+
into.append(info.name);
|
|
123
|
+
const { value } = info;
|
|
124
|
+
if (info.color !== undefined || value === undefined || value.length > 18 || value.includes('var(') || info.name.endsWith(value)) return;
|
|
125
|
+
into.append(make('span', 'hint', value));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default defineClientPlugin<Model, Op>({
|
|
129
|
+
name: 'tailwind',
|
|
130
|
+
label: 'Tailwind',
|
|
131
|
+
mount(panel, context) {
|
|
132
|
+
const style = document.createElement('style');
|
|
133
|
+
style.textContent = STYLE;
|
|
134
|
+
panel.append(style);
|
|
135
|
+
|
|
136
|
+
const { model } = context;
|
|
137
|
+
if (!model.editable) {
|
|
138
|
+
const note = document.createElement('p');
|
|
139
|
+
note.textContent = 'These classes are built at runtime, so there is no one list to edit:';
|
|
140
|
+
const code = document.createElement('code');
|
|
141
|
+
code.textContent = model.source;
|
|
142
|
+
panel.append(note, code);
|
|
143
|
+
return () => {};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// What the page rendered, to put back over a preview that wasn't saved.
|
|
147
|
+
const originals = context.elements.map((el) => el.getAttribute('class'));
|
|
148
|
+
const others = model.others ?? [];
|
|
149
|
+
// The lists to edit: the element's own, then each of the helper's arguments whose classes are a string in the
|
|
150
|
+
// file, by its place among them. One is shown at a time, each keeps its draft, and Save writes every one changed.
|
|
151
|
+
const states: State[] = [
|
|
152
|
+
{ label: 'Base', saved: split(model.classes), draft: split(model.classes) },
|
|
153
|
+
...others.flatMap((other, at): State[] =>
|
|
154
|
+
other.editable === true
|
|
155
|
+
? [{ at, label: other.when ?? other.source, saved: split(other.classes ?? ''), draft: split(other.classes ?? '') }]
|
|
156
|
+
: [],
|
|
157
|
+
),
|
|
158
|
+
];
|
|
159
|
+
const own = states[0]!;
|
|
160
|
+
let current = own;
|
|
161
|
+
// What the page has beyond the source's list: classes the helper's other arguments added, per element. Read
|
|
162
|
+
// only for a helper, as the page may not have caught up with the source yet (just after an undo).
|
|
163
|
+
const runtime = context.elements.map((el) =>
|
|
164
|
+
model.others === undefined ? [] : split(el.getAttribute('class') ?? '').filter((c) => !own.saved.includes(c)),
|
|
165
|
+
);
|
|
166
|
+
// Which arguments' classes each element has now: all there is to see of a condition from the page. Most of
|
|
167
|
+
// them will do, as a helper that merges (`twMerge`) drops the ones a later class overrides.
|
|
168
|
+
const on = others.map((other) => {
|
|
169
|
+
const adds = split(other.classes ?? '');
|
|
170
|
+
return runtime.map((has) => adds.length > 0 && adds.filter((c) => has.includes(c)).length * 2 >= adds.length);
|
|
171
|
+
});
|
|
172
|
+
// And what no argument read here accounts for: left as it is through every preview.
|
|
173
|
+
const told = new Set(others.flatMap((other) => split(other.classes ?? '')));
|
|
174
|
+
const untold = runtime.map((has) => has.filter((c) => !told.has(c)));
|
|
175
|
+
const clicked = context.elements.indexOf(context.element);
|
|
176
|
+
/**
|
|
177
|
+
* An element's classes with each list as `pick` has it. `forced` adds the shown state's to the clicked element
|
|
178
|
+
* though its condition doesn't hold there, so there's something to see while it's edited.
|
|
179
|
+
*/
|
|
180
|
+
const classesOf = (i: number, pick: (state: State) => string[], forced: boolean) => [
|
|
181
|
+
...pick(own),
|
|
182
|
+
...others.flatMap((other, at) => {
|
|
183
|
+
const state = states.find((s) => s.at === at);
|
|
184
|
+
if (on[at]![i] !== true && !(forced && state === current && i === clicked)) return [];
|
|
185
|
+
return state === undefined ? split(other.classes ?? '') : pick(state);
|
|
186
|
+
}),
|
|
187
|
+
...untold[i]!,
|
|
188
|
+
];
|
|
189
|
+
const unsaved = () => states.some((state) => state.draft.join(' ') !== state.saved.join(' '));
|
|
190
|
+
let previewed = false;
|
|
191
|
+
let committed = false;
|
|
192
|
+
let gone = false;
|
|
193
|
+
|
|
194
|
+
// The server's answer, or nothing where it has none: the panel works without, only plainer.
|
|
195
|
+
const ask = async <T>(route: string, init?: RequestInit): Promise<T | undefined> => {
|
|
196
|
+
try {
|
|
197
|
+
const res = await context.request(route, init);
|
|
198
|
+
return res.ok ? ((await res.json()) as T) : undefined;
|
|
199
|
+
} catch {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const naming = (classes: string[]): RequestInit => ({
|
|
204
|
+
method: 'POST',
|
|
205
|
+
headers: { 'content-type': 'application/json' },
|
|
206
|
+
body: JSON.stringify({ classes }),
|
|
207
|
+
});
|
|
208
|
+
/** What Tailwind says of each class seen so far. */
|
|
209
|
+
const known = new Map<string, ClassInfo>();
|
|
210
|
+
/** Set once the server says it has no Tailwind to ask. */
|
|
211
|
+
let plain = false;
|
|
212
|
+
|
|
213
|
+
const chips = make('div', 'chips');
|
|
214
|
+
const editor = make('div', 'editor');
|
|
215
|
+
editor.hidden = true;
|
|
216
|
+
const input = document.createElement('input');
|
|
217
|
+
input.placeholder = 'Add classes, Enter to add';
|
|
218
|
+
input.spellcheck = false;
|
|
219
|
+
input.autocomplete = 'off';
|
|
220
|
+
const list = make('div', 'suggest');
|
|
221
|
+
list.setAttribute('role', 'listbox');
|
|
222
|
+
list.hidden = true;
|
|
223
|
+
const save = make('button', 'primary', 'Save');
|
|
224
|
+
const row = make('div', 'row');
|
|
225
|
+
row.append(save);
|
|
226
|
+
const picks = make('div', 'states');
|
|
227
|
+
const note = make('div', 'note');
|
|
228
|
+
if (states.length > 1) panel.append(picks, note);
|
|
229
|
+
panel.append(chips, input, row);
|
|
230
|
+
// The root the panel is in, where its styles are: the overlay's, or its own where the popup is pinned in a page.
|
|
231
|
+
const around = panel.getRootNode();
|
|
232
|
+
const root = around instanceof ShadowRoot ? around : context.root;
|
|
233
|
+
root.append(editor, list);
|
|
234
|
+
|
|
235
|
+
/** The chip whose kind is open in the editor, by its place in the current.draft. */
|
|
236
|
+
let editing: number | undefined;
|
|
237
|
+
// Each box under what it's about (over it where there's no room under), as wide as the field, and kept there
|
|
238
|
+
// every frame: the popup follows its element and can be dragged, and a chip is drawn again with every change.
|
|
239
|
+
const floats: [box: HTMLElement, by: () => Element | undefined][] = [
|
|
240
|
+
[editor, () => (editing === undefined ? undefined : chips.children[editing])],
|
|
241
|
+
[list, () => input],
|
|
242
|
+
];
|
|
243
|
+
const place = () => {
|
|
244
|
+
for (const [box, by] of floats) {
|
|
245
|
+
if (box.hidden !== false) continue;
|
|
246
|
+
const anchor = by();
|
|
247
|
+
if (anchor === undefined) continue;
|
|
248
|
+
const at = anchor.getBoundingClientRect();
|
|
249
|
+
const span = input.getBoundingClientRect();
|
|
250
|
+
const height = box.offsetHeight;
|
|
251
|
+
const below = window.innerHeight - at.bottom;
|
|
252
|
+
const top = height + 12 > below && at.top > below ? at.top - height - 4 : at.bottom + 4;
|
|
253
|
+
const place = `${Math.round(span.left)}px ${Math.round(top)}px`;
|
|
254
|
+
if (box.style.translate !== place) box.style.translate = place;
|
|
255
|
+
const width = `${Math.round(span.width)}px`;
|
|
256
|
+
if (box.style.width !== width) box.style.width = width;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
let following = requestAnimationFrame(function follow() {
|
|
260
|
+
following = requestAnimationFrame(follow);
|
|
261
|
+
place();
|
|
262
|
+
});
|
|
263
|
+
const extras = make('div', 'extras');
|
|
264
|
+
// The arguments with no list to edit here: a bare key, a call, a name from another file.
|
|
265
|
+
const fixed = others.filter((other) => other.editable !== true);
|
|
266
|
+
if (fixed.length > 0) panel.append(extras);
|
|
267
|
+
// What the clicked element has of them now, as the page rendered it.
|
|
268
|
+
const lit = new Set(runtime[clicked] ?? []);
|
|
269
|
+
/** Those arguments: what each adds as chips under what it waits on, or its code where nothing says. */
|
|
270
|
+
const drawExtras = () => {
|
|
271
|
+
extras.replaceChildren(
|
|
272
|
+
...fixed.map((extra) => {
|
|
273
|
+
const row = make('div', 'extra');
|
|
274
|
+
const when = make('div', 'when');
|
|
275
|
+
if (extra.when === undefined) when.append('Always');
|
|
276
|
+
else when.append('When ', make('code', '', extra.when));
|
|
277
|
+
row.append(when);
|
|
278
|
+
// Nothing says what it adds (a call, a prop): its code is all there is to show.
|
|
279
|
+
if (extra.classes === undefined) {
|
|
280
|
+
when.append(', whatever ', make('code', '', extra.source), ' adds');
|
|
281
|
+
return row;
|
|
282
|
+
}
|
|
283
|
+
for (const c of split(extra.classes)) {
|
|
284
|
+
const on = lit.has(c);
|
|
285
|
+
const chip = make('span', on ? 'chip fixed' : 'chip fixed off');
|
|
286
|
+
chip.title = on ? 'On the element now. Change it in the code' : 'Not on the element now. Change it in the code';
|
|
287
|
+
const name = make('span', 'name');
|
|
288
|
+
face(name, known.get(c) ?? { name: c, known: false });
|
|
289
|
+
chip.append(name);
|
|
290
|
+
row.append(chip);
|
|
291
|
+
}
|
|
292
|
+
return row;
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// The classes the page's build had as the panel opened: any other may have no CSS there yet.
|
|
298
|
+
const built = new Set([...states.flatMap((state) => state.saved), ...told]);
|
|
299
|
+
let sheet: HTMLStyleElement | undefined;
|
|
300
|
+
let styled = '';
|
|
301
|
+
const lend = async () => {
|
|
302
|
+
const fresh = [...new Set(states.flatMap((state) => state.draft))].filter((c) => !built.has(c));
|
|
303
|
+
const key = fresh.join(' ');
|
|
304
|
+
if (plain || key === styled) return;
|
|
305
|
+
styled = key;
|
|
306
|
+
const answer = fresh.length === 0 ? { css: '' } : await ask<{ css: string }>('css', naming(fresh));
|
|
307
|
+
if (answer === undefined || key !== styled || gone) return;
|
|
308
|
+
sheet ??= document.head.appendChild(document.createElement('style'));
|
|
309
|
+
sheet.textContent = answer.css;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const preview = () => {
|
|
313
|
+
save.disabled = !unsaved();
|
|
314
|
+
context.unsaved(unsaved() ? save : undefined);
|
|
315
|
+
if (!unsaved() && !previewed && current === own) return;
|
|
316
|
+
context.elements.forEach((el, i) => el.setAttribute('class', classesOf(i, (state) => state.draft, true).join(' ')));
|
|
317
|
+
previewed = true;
|
|
318
|
+
void lend();
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/** The lists as buttons: the element's own, and each condition, dotted where it holds on the element now. */
|
|
322
|
+
const drawStates = () => {
|
|
323
|
+
picks.replaceChildren(
|
|
324
|
+
...states.map((state) => {
|
|
325
|
+
const pick = make('button', 'state');
|
|
326
|
+
const holds = state.at !== undefined && on[state.at]![clicked] === true;
|
|
327
|
+
if (holds) pick.append(make('span', 'dot'));
|
|
328
|
+
pick.append(state.at === undefined || others[state.at]!.when !== undefined ? state.label : `always: ${state.label}`);
|
|
329
|
+
pick.setAttribute('aria-pressed', String(state === current));
|
|
330
|
+
if (state.at !== undefined) pick.title = holds ? 'On the element now' : 'Not on the element now: shown on it while you edit';
|
|
331
|
+
pick.addEventListener('click', () => {
|
|
332
|
+
shut(false);
|
|
333
|
+
hide();
|
|
334
|
+
current = state;
|
|
335
|
+
drawStates();
|
|
336
|
+
render();
|
|
337
|
+
input.focus();
|
|
338
|
+
});
|
|
339
|
+
return pick;
|
|
340
|
+
}),
|
|
341
|
+
);
|
|
342
|
+
const shared = current.at === undefined ? undefined : others[current.at]!.shared;
|
|
343
|
+
note.replaceChildren(...(shared === undefined ? [] : ['From ', make('code', '', shared), ': everything that uses it changes too.']));
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
let opened = 0;
|
|
347
|
+
const drawChips = () => {
|
|
348
|
+
chips.replaceChildren(
|
|
349
|
+
...current.draft.map((c, i) => {
|
|
350
|
+
const chip = make('span', i === editing ? 'chip open' : 'chip');
|
|
351
|
+
const info = known.get(c);
|
|
352
|
+
const name = make(info?.known === true ? 'button' : 'span', 'name');
|
|
353
|
+
face(name, info ?? { name: c, known: false });
|
|
354
|
+
if (name instanceof HTMLButtonElement) {
|
|
355
|
+
name.title = `Change ${c}`;
|
|
356
|
+
name.addEventListener('click', () => void (editing === i ? shut() : edit(i)));
|
|
357
|
+
}
|
|
358
|
+
const remove = make('button', 'x', '×');
|
|
359
|
+
remove.title = `Remove ${c}`;
|
|
360
|
+
remove.addEventListener('click', () => {
|
|
361
|
+
shut();
|
|
362
|
+
current.draft = current.draft.toSpliced(i, 1);
|
|
363
|
+
render();
|
|
364
|
+
});
|
|
365
|
+
chip.append(name, remove);
|
|
366
|
+
return chip;
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
const describe = async () => {
|
|
371
|
+
const shown = [...states.flatMap((state) => state.draft), ...told];
|
|
372
|
+
const missing = [...new Set(shown)].filter((c) => !known.has(c));
|
|
373
|
+
if (plain || missing.length === 0) return;
|
|
374
|
+
const answer = await ask<{ available: boolean; items: ClassInfo[] }>('info', naming(missing));
|
|
375
|
+
if (answer === undefined) return;
|
|
376
|
+
plain = !answer.available;
|
|
377
|
+
for (const item of answer.items) known.set(item.name, item);
|
|
378
|
+
if (answer.items.length === 0) return;
|
|
379
|
+
drawChips();
|
|
380
|
+
drawExtras();
|
|
381
|
+
};
|
|
382
|
+
const render = () => {
|
|
383
|
+
drawChips();
|
|
384
|
+
preview();
|
|
385
|
+
void describe();
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const shut = (focus = true) => {
|
|
389
|
+
opened++;
|
|
390
|
+
if (editing === undefined) return;
|
|
391
|
+
editing = undefined;
|
|
392
|
+
editor.hidden = true;
|
|
393
|
+
editor.removeAttribute('data-deictic-modal');
|
|
394
|
+
editor.replaceChildren();
|
|
395
|
+
drawChips();
|
|
396
|
+
if (focus) input.focus();
|
|
397
|
+
};
|
|
398
|
+
// A press anywhere else in the overlay closes the editor, as it would a menu. The chips open and close it themselves.
|
|
399
|
+
const onPress = (e: Event) => {
|
|
400
|
+
const path = e.composedPath();
|
|
401
|
+
if (!path.includes(editor) && !path.includes(chips)) shut(false);
|
|
402
|
+
};
|
|
403
|
+
root.addEventListener('pointerdown', onPress, true);
|
|
404
|
+
/** Puts `name` where the open chip's class is. The same class twice would be one, so that's left. */
|
|
405
|
+
const swap = (name: string, info: ClassInfo) => {
|
|
406
|
+
if (editing === undefined || current.draft.includes(name)) return;
|
|
407
|
+
known.set(name, info);
|
|
408
|
+
current.draft = current.draft.with(editing, name);
|
|
409
|
+
render();
|
|
410
|
+
};
|
|
411
|
+
const edit = async (at: number) => {
|
|
412
|
+
const turn = ++opened;
|
|
413
|
+
const was = current.draft[at]!;
|
|
414
|
+
const found = await ask<Alternatives | null>(`alternatives?${new URLSearchParams({ class: was })}`);
|
|
415
|
+
if (turn !== opened || current.draft[at] !== was || found === undefined || found === null) return;
|
|
416
|
+
editing = at;
|
|
417
|
+
drawChips();
|
|
418
|
+
|
|
419
|
+
const top = make('div', 'top', found.label);
|
|
420
|
+
const close = make('button', 'icon', '×');
|
|
421
|
+
close.title = 'Close';
|
|
422
|
+
close.addEventListener('click', () => shut());
|
|
423
|
+
top.append(close);
|
|
424
|
+
|
|
425
|
+
const alts = make('div', 'alts');
|
|
426
|
+
const buttons = new Map<string, HTMLButtonElement>();
|
|
427
|
+
const press = () => {
|
|
428
|
+
for (const [name, button] of buttons) button.setAttribute('aria-pressed', String(name === current.draft[at]));
|
|
429
|
+
};
|
|
430
|
+
const choice = (item: ClassInfo, bare: boolean) => {
|
|
431
|
+
const button = make('button', '');
|
|
432
|
+
if (bare && item.color !== undefined) {
|
|
433
|
+
button.append(swatch(item.color));
|
|
434
|
+
button.title = item.name;
|
|
435
|
+
} else {
|
|
436
|
+
face(button, item);
|
|
437
|
+
}
|
|
438
|
+
button.addEventListener('click', () => {
|
|
439
|
+
swap(item.name, item);
|
|
440
|
+
press();
|
|
441
|
+
});
|
|
442
|
+
buttons.set(item.name, button);
|
|
443
|
+
return button;
|
|
444
|
+
};
|
|
445
|
+
// A colour's shades in a row, a family under a family; whatever has no shades (`black`, `inherit`) comes first, named.
|
|
446
|
+
const families = new Map<string, HTMLElement>();
|
|
447
|
+
const loose: HTMLElement[] = [];
|
|
448
|
+
for (const item of found.items) {
|
|
449
|
+
const family = found.colors && item.color !== undefined ? familyOf(item.name) : undefined;
|
|
450
|
+
if (family === undefined) {
|
|
451
|
+
loose.push(choice(item, false));
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const shades = families.get(family) ?? make('div', 'family');
|
|
455
|
+
families.set(family, shades);
|
|
456
|
+
shades.append(choice(item, true));
|
|
457
|
+
}
|
|
458
|
+
alts.append(...loose, ...families.values());
|
|
459
|
+
press();
|
|
460
|
+
|
|
461
|
+
editor.replaceChildren(top, alts);
|
|
462
|
+
const { custom } = found;
|
|
463
|
+
if (custom !== undefined) {
|
|
464
|
+
const form = make('form', 'custom');
|
|
465
|
+
const field = document.createElement('input');
|
|
466
|
+
field.placeholder = found.colors ? 'A colour of your own: #12b358' : `A value of your own${hinted(known.get(was))}`;
|
|
467
|
+
field.spellcheck = false;
|
|
468
|
+
field.value = custom.value?.replaceAll('_', ' ') ?? '';
|
|
469
|
+
const named = (value: string) => `${custom.before}${value.trim().replace(/\s+/g, '_')}${custom.after}`;
|
|
470
|
+
if (found.colors) {
|
|
471
|
+
const picker = document.createElement('input');
|
|
472
|
+
picker.type = 'color';
|
|
473
|
+
picker.title = 'Pick a colour';
|
|
474
|
+
if (/^#[\da-f]{6}$/i.test(field.value)) picker.value = field.value;
|
|
475
|
+
// Each colour tried shows on the page as it's picked: a hex is a colour to Tailwind, with nothing to check.
|
|
476
|
+
picker.addEventListener('input', () => {
|
|
477
|
+
field.value = picker.value;
|
|
478
|
+
field.removeAttribute('aria-invalid');
|
|
479
|
+
swap(named(picker.value), { name: named(picker.value), known: true, color: picker.value, value: picker.value });
|
|
480
|
+
press();
|
|
481
|
+
});
|
|
482
|
+
form.append(picker);
|
|
483
|
+
}
|
|
484
|
+
const set = make('button', '', 'Set');
|
|
485
|
+
set.type = 'submit';
|
|
486
|
+
field.addEventListener('input', () => field.removeAttribute('aria-invalid'));
|
|
487
|
+
form.addEventListener('submit', (e) => {
|
|
488
|
+
e.preventDefault();
|
|
489
|
+
if (field.value.trim() === '') return;
|
|
490
|
+
const name = named(field.value);
|
|
491
|
+
void ask<{ items: ClassInfo[] }>('info', naming([name])).then((answer) => {
|
|
492
|
+
const info = answer?.items[0];
|
|
493
|
+
if (turn !== opened || editing !== at) return;
|
|
494
|
+
if (info?.known !== true) {
|
|
495
|
+
field.setAttribute('aria-invalid', 'true');
|
|
496
|
+
field.title = `Tailwind makes nothing of ${name}`;
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
swap(name, info);
|
|
500
|
+
// Its kind may be another now (`text-[red]` is a colour), and the list has it to show as chosen.
|
|
501
|
+
void edit(at);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
form.append(field, set);
|
|
505
|
+
// Shown on asking, or where the class already has a value of its own to show.
|
|
506
|
+
let asked = custom.value !== undefined;
|
|
507
|
+
const more = make('button', 'more', 'Custom');
|
|
508
|
+
more.title = 'Set a value of your own';
|
|
509
|
+
const show = () => {
|
|
510
|
+
form.hidden = !asked;
|
|
511
|
+
more.setAttribute('aria-expanded', String(asked));
|
|
512
|
+
};
|
|
513
|
+
show();
|
|
514
|
+
more.addEventListener('click', () => {
|
|
515
|
+
asked = !asked;
|
|
516
|
+
show();
|
|
517
|
+
if (asked) field.focus();
|
|
518
|
+
});
|
|
519
|
+
close.before(more);
|
|
520
|
+
editor.append(form);
|
|
521
|
+
}
|
|
522
|
+
// Esc closes the editor, not the popup, and reaches it only from inside: so the focus goes in.
|
|
523
|
+
editor.setAttribute('data-deictic-modal', '');
|
|
524
|
+
editor.hidden = false;
|
|
525
|
+
// Placed as it shows, not a frame later, when it would flash where it was.
|
|
526
|
+
place();
|
|
527
|
+
const chosen = buttons.get(current.draft[at]);
|
|
528
|
+
if (chosen !== undefined) alts.scrollTop = chosen.offsetTop - alts.clientHeight / 2;
|
|
529
|
+
(chosen ?? editor.querySelector('button'))?.focus();
|
|
530
|
+
};
|
|
531
|
+
editor.addEventListener('keydown', (e) => {
|
|
532
|
+
if (e.key !== 'Escape') return;
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
shut();
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
const commit = async () => {
|
|
538
|
+
// One change each, in the history too. One the server refuses leaves the rest as they are, still to save.
|
|
539
|
+
for (const state of states) {
|
|
540
|
+
if (state.draft.join(' ') === state.saved.join(' ')) continue;
|
|
541
|
+
const next = await context.apply({ classes: state.draft.join(' '), ...(state.at === undefined ? {} : { at: state.at }) });
|
|
542
|
+
if (next.editable) state.saved = split(state.at === undefined ? next.classes : (next.others?.[state.at]?.classes ?? ''));
|
|
543
|
+
state.draft = [...state.saved];
|
|
544
|
+
committed = true;
|
|
545
|
+
}
|
|
546
|
+
previewed = false;
|
|
547
|
+
shut();
|
|
548
|
+
render();
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/** What completes the word being typed, and the one Enter takes. */
|
|
552
|
+
let options: ClassInfo[] = [];
|
|
553
|
+
let active = 0;
|
|
554
|
+
let typed = 0;
|
|
555
|
+
const drawOptions = () => {
|
|
556
|
+
list.hidden = options.length === 0;
|
|
557
|
+
// While it's open, Esc closes it and not the popup.
|
|
558
|
+
list.toggleAttribute('data-deictic-modal', options.length > 0);
|
|
559
|
+
list.replaceChildren(
|
|
560
|
+
...options.map((item, i) => {
|
|
561
|
+
const option = make('div', 'option');
|
|
562
|
+
option.setAttribute('role', 'option');
|
|
563
|
+
option.setAttribute('aria-selected', String(i === active));
|
|
564
|
+
face(option, item);
|
|
565
|
+
option.addEventListener('click', () => take(item));
|
|
566
|
+
return option;
|
|
567
|
+
}),
|
|
568
|
+
);
|
|
569
|
+
place();
|
|
570
|
+
const shown = list.children[active];
|
|
571
|
+
if (!(shown instanceof HTMLElement)) return;
|
|
572
|
+
if (shown.offsetTop < list.scrollTop) list.scrollTop = shown.offsetTop;
|
|
573
|
+
else if (shown.offsetTop + shown.offsetHeight > list.scrollTop + list.clientHeight)
|
|
574
|
+
list.scrollTop = shown.offsetTop + shown.offsetHeight - list.clientHeight;
|
|
575
|
+
};
|
|
576
|
+
const hide = () => {
|
|
577
|
+
typed++;
|
|
578
|
+
options = [];
|
|
579
|
+
drawOptions();
|
|
580
|
+
};
|
|
581
|
+
const suggest = async () => {
|
|
582
|
+
const turn = ++typed;
|
|
583
|
+
const word = /\S*$/.exec(input.value)![0];
|
|
584
|
+
if (plain || word === '') return hide();
|
|
585
|
+
const answer = await ask<{ items: ClassInfo[] }>(`complete?${new URLSearchParams({ q: word })}`);
|
|
586
|
+
if (turn !== typed) return;
|
|
587
|
+
options = (answer?.items ?? []).filter((item) => !current.draft.includes(item.name));
|
|
588
|
+
active = 0;
|
|
589
|
+
drawOptions();
|
|
590
|
+
};
|
|
591
|
+
/** Adds what the field holds. False when it held nothing new. */
|
|
592
|
+
const add = () => {
|
|
593
|
+
const added = split(input.value).filter((c) => !current.draft.includes(c));
|
|
594
|
+
input.value = '';
|
|
595
|
+
hide();
|
|
596
|
+
if (added.length === 0) return false;
|
|
597
|
+
current.draft = [...current.draft, ...added];
|
|
598
|
+
render();
|
|
599
|
+
return true;
|
|
600
|
+
};
|
|
601
|
+
const take = (item: ClassInfo) => {
|
|
602
|
+
input.value = input.value.replace(/\S*$/, item.name);
|
|
603
|
+
input.focus();
|
|
604
|
+
// A variant is the start of a class: the rest is still to type.
|
|
605
|
+
if (item.variant === true) {
|
|
606
|
+
void suggest();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
known.set(item.name, item);
|
|
610
|
+
add();
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
input.addEventListener('input', () => void suggest());
|
|
614
|
+
// A press in the list mustn't take the focus from the field, which would close the list under it.
|
|
615
|
+
list.addEventListener('mousedown', (e) => e.preventDefault());
|
|
616
|
+
input.addEventListener('blur', hide);
|
|
617
|
+
input.addEventListener('keydown', (e) => {
|
|
618
|
+
if (options.length > 0) {
|
|
619
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
620
|
+
e.preventDefault();
|
|
621
|
+
active = (active + (e.key === 'ArrowDown' ? 1 : options.length - 1)) % options.length;
|
|
622
|
+
drawOptions();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (e.key === 'Enter' || e.key === 'Tab') {
|
|
626
|
+
e.preventDefault();
|
|
627
|
+
take(options[active]!);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (e.key === 'Escape') {
|
|
631
|
+
e.preventDefault();
|
|
632
|
+
hide();
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (e.key !== 'Enter') return;
|
|
637
|
+
e.preventDefault();
|
|
638
|
+
if (!add()) void commit().catch(() => {});
|
|
639
|
+
});
|
|
640
|
+
save.addEventListener('click', () => void commit().catch(() => {}));
|
|
641
|
+
drawStates();
|
|
642
|
+
drawExtras();
|
|
643
|
+
render();
|
|
644
|
+
input.focus();
|
|
645
|
+
|
|
646
|
+
// A saved list reaches the page through the bundler's update, which this mustn't race.
|
|
647
|
+
return () => {
|
|
648
|
+
gone = true;
|
|
649
|
+
sheet?.remove();
|
|
650
|
+
cancelAnimationFrame(following);
|
|
651
|
+
root.removeEventListener('pointerdown', onPress, true);
|
|
652
|
+
editor.remove();
|
|
653
|
+
list.remove();
|
|
654
|
+
if (!previewed) return;
|
|
655
|
+
context.elements.forEach((el, i) => {
|
|
656
|
+
// As the page rendered it, or, once something's saved, as the source now has it: never the classes from before.
|
|
657
|
+
const was = committed ? classesOf(i, (state) => state.saved, false).join(' ') : originals[i];
|
|
658
|
+
if (was === null || was === undefined || (was === '' && originals[i] === null)) el.removeAttribute('class');
|
|
659
|
+
else el.setAttribute('class', was);
|
|
660
|
+
});
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
/** What a field for a value of one's own shows as the kind of thing to type: the class's value now. */
|
|
666
|
+
function hinted(info: ClassInfo | undefined): string {
|
|
667
|
+
const value = info?.value;
|
|
668
|
+
return value === undefined || value.length > 18 || value.includes('var(') ? '' : `: ${value}`;
|
|
669
|
+
}
|