@vinena/knobs 0.5.2 → 0.6.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +7 -6
  3. package/dist/context-amfyasb5.js +23 -0
  4. package/dist/context-svtr7vwt.js +22 -0
  5. package/dist/early.global.js +6 -6
  6. package/dist/edit/css.d.ts +59 -0
  7. package/dist/edit/html.d.ts +91 -0
  8. package/dist/edit/keep.d.ts +175 -0
  9. package/dist/edit/log.d.ts +107 -0
  10. package/dist/edit/replay.d.ts +28 -0
  11. package/dist/edit/risk.d.ts +33 -0
  12. package/dist/edit/rule.d.ts +31 -0
  13. package/dist/edit/source.d.ts +12 -0
  14. package/dist/edit/text.d.ts +66 -0
  15. package/dist/elementsview-fyc06wjt.js +3702 -0
  16. package/dist/elementsview-k6zvvcne.js +3701 -0
  17. package/dist/engine/browserdraw.d.ts +5 -0
  18. package/dist/engine/browserkit.d.ts +2 -0
  19. package/dist/engine/devices.d.ts +3 -2
  20. package/dist/engine/dock.d.ts +3 -4
  21. package/dist/engine/frame.d.ts +1 -1
  22. package/dist/engine/frames.d.ts +1 -0
  23. package/dist/engine/identity.d.ts +5 -1
  24. package/dist/engine/index.d.ts +2 -0
  25. package/dist/engine/mock.d.ts +0 -2
  26. package/dist/engine/mockdata.d.ts +4 -3
  27. package/dist/engine/mockdraw.d.ts +2 -14
  28. package/dist/engine/morphrun.d.ts +4 -0
  29. package/dist/engine/native.d.ts +31 -3
  30. package/dist/engine/notice.d.ts +1 -2
  31. package/dist/engine/style.d.ts +15 -0
  32. package/dist/engine/width.d.ts +3 -0
  33. package/dist/{framekit-w0v516w5.js → framekit-622h6w1f.js} +264 -105
  34. package/dist/{framekit-te90cjs0.js → framekit-yx612r28.js} +264 -105
  35. package/dist/index-0zp9py56.js +859 -0
  36. package/dist/{index-9re7sv56.js → index-1mstjadm.js} +126 -2167
  37. package/dist/{index-30fc6php.js → index-4a4x1bt2.js} +1 -1
  38. package/dist/index-58jdczmj.js +44 -0
  39. package/dist/index-5tv6sr74.js +23 -0
  40. package/dist/index-6bc2ztfd.js +688 -0
  41. package/dist/index-7cb4x1vj.js +1885 -0
  42. package/dist/index-a974q3aa.js +34 -0
  43. package/dist/{index-r72tz2vn.js → index-aymfvd8s.js} +1 -1
  44. package/dist/{index-trx7bxdk.js → index-aynkv7qk.js} +11 -8
  45. package/dist/{index-xjhwp5cj.js → index-dzm8ywq0.js} +504 -2362
  46. package/dist/{index-dan2kpsd.js → index-f60yax1j.js} +13 -8
  47. package/dist/index-f67wctn3.js +1858 -0
  48. package/dist/{index-agwr37gw.js → index-ftjdt358.js} +8 -171
  49. package/dist/{index-pewcdh28.js → index-gm51cthv.js} +2 -45
  50. package/dist/index-kfdzsyyw.js +1859 -0
  51. package/dist/index-t4kssacm.js +208 -0
  52. package/dist/index-v0ht9q0g.js +1518 -0
  53. package/dist/{index-sxe5079a.js → index-x59vz1xx.js} +262 -901
  54. package/dist/index-xh39jtkq.js +32 -0
  55. package/dist/index-yb7fc59g.js +718 -0
  56. package/dist/index-zd6adby9.js +496 -0
  57. package/dist/index.d.ts +62 -0
  58. package/dist/index.global.js +447 -160
  59. package/dist/index.js +533 -485
  60. package/dist/react-0wepdf60.js +1519 -0
  61. package/dist/{react-4pvp6amm.js → react-1gqwa2yw.js} +1 -1
  62. package/dist/{index-hv02xka3.js → react-3mfz1x2a.js} +126 -2167
  63. package/dist/react-4rbjw9af.js +33 -0
  64. package/dist/react-5rq7bnsy.js +210 -0
  65. package/dist/react-6bz05qk1.js +860 -0
  66. package/dist/{react-05jh9jv5.js → react-6fnxxs30.js} +8 -171
  67. package/dist/react-6q2cw2ya.js +689 -0
  68. package/dist/{react-sw8d8c94.js → react-6t4dbdzn.js} +11 -8
  69. package/dist/react-88es9b5q.js +719 -0
  70. package/dist/react-97b5b8j4.js +46 -0
  71. package/dist/{react-16spgn0h.js → react-bxzn8vq5.js} +1 -1
  72. package/dist/{react-ayg1bgw3.js → react-cs62p9qh.js} +83 -722
  73. package/dist/react-ethftdxp.js +497 -0
  74. package/dist/react-fp73vhyd.js +36 -0
  75. package/dist/{react-exjcpxma.js → react-me102s1a.js} +2 -45
  76. package/dist/react-t2qnewz2.js +24 -0
  77. package/dist/react-ttj8f9qp.js +1886 -0
  78. package/dist/{react-zy1mmhgz.js → react-v8497a41.js} +13 -8
  79. package/dist/{react-fm9y8dbn.js → react-wqn4sx0n.js} +276 -2133
  80. package/dist/react.js +529 -485
  81. package/dist/replay-j18rw92k.js +258 -0
  82. package/dist/replay-vtg0vqj2.js +257 -0
  83. package/dist/{storageview-s7heg93p.js → storageview-6xj7zb63.js} +11 -7
  84. package/dist/{storageview-r595qpt9.js → storageview-pzn8yaad.js} +11 -7
  85. package/dist/styles/force.d.ts +66 -0
  86. package/dist/types.d.ts +7 -0
  87. package/dist/ui/bindings.d.ts +31 -5
  88. package/dist/ui/changes.d.ts +49 -0
  89. package/dist/ui/cssauto.d.ts +119 -0
  90. package/dist/ui/cssedit.d.ts +80 -0
  91. package/dist/ui/domedit.d.ts +99 -0
  92. package/dist/ui/domtree.d.ts +26 -1
  93. package/dist/ui/elementsview.d.ts +19 -2
  94. package/dist/ui/htmledit.d.ts +62 -0
  95. package/dist/ui/inspector.d.ts +6 -1
  96. package/dist/ui/keys.d.ts +12 -8
  97. package/dist/ui/pane.d.ts +0 -2
  98. package/dist/ui/panel.d.ts +3 -0
  99. package/dist/ui/prefs.d.ts +30 -10
  100. package/dist/ui/settings.d.ts +10 -0
  101. package/dist/ui/size.d.ts +14 -22
  102. package/dist/ui/stylesview.d.ts +30 -1
  103. package/package.json +1 -1
  104. package/skills/devknobs/SKILL.md +95 -0
  105. package/dist/elementsview-2z4pkrdz.js +0 -2873
  106. package/dist/elementsview-qn8qyksa.js +0 -2874
  107. package/dist/index-78r0f8pw.js +0 -27
  108. package/dist/react-adky72h9.js +0 -29
@@ -1,7 +1,8 @@
1
1
  import { type BaseKeys, type Binding, type Combo, type KeyLike, type Keys } from "./keys";
2
2
  /**
3
3
  * Where the keys the user set in the panel are kept, in `localStorage`, so they
4
- * hold across reloads and in new tabs of the origin. Reset all leaves them.
4
+ * hold across reloads and in new tabs of the origin. Reset all leaves them. A
5
+ * mount with a `keysStore` keeps them there instead.
5
6
  */
6
7
  export declare const KEYS_KEY = "devknobs:keys";
7
8
  /** The version of the keys `KEYS_KEY` keeps. Bump it with a new shape, see stored.ts. */
@@ -19,9 +20,9 @@ export type StoredKeys = Partial<Record<Binding, string>>;
19
20
  */
20
21
  export declare function isReserved(combo: Combo): boolean;
21
22
  /**
22
- * Why a combination cannot be a binding's, or null where it can: a key alone
23
- * types, so it needs a modifier unless it is a function key, the browser keeps
24
- * some, `/` is the search's, and no two bindings share one. `others` are the
23
+ * Why a combination cannot be a binding's, or null where it can: the browser
24
+ * keeps some, `/` is the search's, and no two bindings share one. A key alone
25
+ * is fine, as it acts only where no field has the focus. `others` are the
25
26
  * keys the other bindings have now.
26
27
  */
27
28
  export declare function comboProblem(combo: Combo, binding: Binding, others?: Partial<Keys>): string | null;
@@ -56,6 +57,8 @@ export declare function recordStep(event: KeyLike, binding: Binding, others: Par
56
57
  * reads and could have been set in the panel, each in its kept form.
57
58
  */
58
59
  export declare function readKeys(json: string | null | undefined): StoredKeys;
60
+ /** The stored keys as `readKeys` reads them, from the value itself rather than its json. */
61
+ export declare function keysOf(value: unknown): StoredKeys;
59
62
  /**
60
63
  * The keys in force: a key the user set wins over `base`, the mount options
61
64
  * or the defaults, another binding's too: the binding whose default it took
@@ -64,6 +67,26 @@ export declare function readKeys(json: string | null | undefined): StoredKeys;
64
67
  * always keeps a key. Without grab, its key is no other binding's to clash with.
65
68
  */
66
69
  export declare function resolveKeys(base: BaseKeys, stored: StoredKeys, grab?: boolean): Keys;
70
+ /**
71
+ * @internal Where a mount keeps the keys the user sets in place of `localStorage`, for
72
+ * the devknobs extension, which keeps them for every site. `load` gives what
73
+ * was last kept, read as `keysOf` reads it, `save` keeps them with their
74
+ * version, and `subscribe` hears them change elsewhere and returns the way to
75
+ * stop. `load` answers at once, so it gives the last it knows.
76
+ */
77
+ export interface KeysStore {
78
+ load(): unknown;
79
+ save(keys: {
80
+ v: number;
81
+ } & StoredKeys): void;
82
+ subscribe(listener: () => void): () => void;
83
+ }
84
+ /**
85
+ * The keys a panel acts on: those of the bindings it lists, such as no
86
+ * elements view's without inspect. One it does not list has none, so its key
87
+ * goes to the page. The panel's always keeps its own.
88
+ */
89
+ export declare function keysListed(keys: Keys, listed: readonly Binding[]): Keys;
67
90
  /** The keys in force, kept in step with the ones the user sets, here or in another tab. */
68
91
  export interface LiveKeys {
69
92
  get(): Keys;
@@ -80,10 +103,13 @@ export interface LiveKeys {
80
103
  /**
81
104
  * The keys for a mount's options, with the ones the user set on top. Another
82
105
  * document of the origin that sets them, as the page above the width knob's
83
- * frame does, is heard through the storage event.
106
+ * frame does, is heard through the storage event. With a `store`, they are
107
+ * the store's, and so are their changes. In fresh mode nothing kept is read
108
+ * from either, and nothing is written to the store.
84
109
  */
85
110
  export declare function createKeys(options?: {
86
111
  hotkey?: string;
87
112
  grabKey?: string;
88
113
  grab?: boolean;
114
+ store?: KeysStore;
89
115
  }): LiveKeys;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The changes at the foot of the Elements view: how many edits are in force,
3
+ * each as a `-` line before and a `+` line after under the place it is in,
4
+ * and the ways to hand them on: the prompt for an agent, the diff, and undo
5
+ * all. The diff lines are folded away until the count's button shows them,
6
+ * and the way the user leaves them is kept where `diff` says. With edits kept after a reload, a line says how many were made again
7
+ * as the page loaded and lists those that were not, one says when edits
8
+ * past the caps are not kept, and kept html and attribute edits wait there,
9
+ * listed, for a click on their `apply`: they could change what a script of
10
+ * the page does, so only the user makes them again. It shows only while there is something to say. To use it:
11
+ *
12
+ * const changes = createChanges(edits, copy, isMac(), keeper(), { get, set });
13
+ * view.append(changes.node); changes.destroy();
14
+ */
15
+ import { type Keeper, type SavedEdit, type Skipped } from "../edit/keep";
16
+ import type { EditLog } from "../edit/log";
17
+ /** What the copy buttons say for a moment after a copy, and after one that did not go. */
18
+ export declare const COPIED = "copied";
19
+ export declare const NOT_COPIED = "could not copy";
20
+ /** Copies a text, and says whether it went, at once or once the clipboard answers. */
21
+ export type Copy = (text: string) => boolean | Promise<boolean>;
22
+ /** What the line under the buttons says, for agents that run code in the page. */
23
+ export declare const AGENT_NOTE = "agents read and apply edits: devknobs.edits() / setEdits()";
24
+ /** What the line about edits made again as the page loaded says. */
25
+ export declare function keptLine(kept: number, missed: number): string;
26
+ /** What the line over the kept edits that wait says: how many html and attribute edits, and the edits after them. */
27
+ export declare function waitLine(html: number, attributes: number, more: number): string;
28
+ /** What the line under them says: a page script may have planted them. */
29
+ export declare const WAIT_NOTE = "apply only edits you made on this page";
30
+ /** The most characters a waiting edit's value shows, cut at its end. */
31
+ export declare const WAIT_MAX = 120;
32
+ /** Whether a waiting edit's value is longer than its line shows at first. */
33
+ export declare function waitCut(edit: SavedEdit): boolean;
34
+ /** A waiting edit's value as data, cut short unless `full`. */
35
+ export declare function waitValue(edit: SavedEdit, full?: boolean): string;
36
+ /** An edit that was not made again, as its line says it: `text on h1.title: not found on the page`, `padding on a.cta: ...`. */
37
+ export declare function missedLine(skipped: Skipped): string;
38
+ export interface Changes {
39
+ node: HTMLElement;
40
+ destroy(): void;
41
+ }
42
+ /** What the head says of the keys that undo and redo: `Z` and `⇧Z` on a Mac, `Z` and `Shift Z` elsewhere. */
43
+ export declare function undoHint(mac: boolean): string;
44
+ /** Whether the diff lines show, and where the way the user leaves them is kept. */
45
+ export interface DiffShown {
46
+ get(): boolean;
47
+ set(open: boolean): void;
48
+ }
49
+ export declare function createChanges(log: EditLog, copy: Copy, mac?: boolean, keep?: Keeper | null, diffShown?: DiffShown | null): Changes;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The suggestions of the styles view's fields, as the browsers' tools have
3
+ * them: under a property's name, every property the browser knows and the
4
+ * custom properties the page sets; under a value, the keywords the browser
5
+ * takes for that property, named colors where it takes a color, `var()` of
6
+ * each custom property, and the global keywords. What the browser knows is
7
+ * asked of it, never listed here: the names come from a style's own keys,
8
+ * and a keyword shows only where `CSS.supports` takes it. The list opens as
9
+ * the field is typed in, filtered by what was typed, its start first, and
10
+ * whole as an empty field gets the focus:
11
+ *
12
+ * ↑ ↓ mark one in the list ↩ Tab take the one marked, then the field goes on
13
+ * esc close the list click take it, the field stays open
14
+ *
15
+ * None is marked as the list opens. With none marked, ↩ and Tab take the
16
+ * first only where it completes the word typed: a number, a `#` color or an
17
+ * empty field keeps what was typed. ↩ in an empty field takes from the list
18
+ * only once it was moved in.
19
+ *
20
+ * To use it:
21
+ *
22
+ * const auto = autocomplete(input, () => valueSuggestions("display", browserCss(element)), "value");
23
+ * if (auto.key(event)) return; auto.close();
24
+ */
25
+ /** The keywords every property takes. */
26
+ export declare const GLOBAL_KEYWORDS: string[];
27
+ /** Keywords that properties take, each shown only where the browser takes it for the property. */
28
+ export declare const KEYWORDS: string[];
29
+ /** Words for properties that take a name of the page's own, where the browser takes any word. */
30
+ export declare const NAMED_KEYWORDS: Record<string, string[]>;
31
+ /** The colors css names, for a property that takes a color. */
32
+ export declare const NAMED_COLORS: string[];
33
+ /** The most suggestions a list shows. */
34
+ export declare const MOST = 50;
35
+ /** What the suggestions are drawn from: the browser's word on a value, the properties it knows, the page's custom properties. */
36
+ export interface CssWorld {
37
+ supports(property: string, value: string): boolean;
38
+ /** Every property the browser knows, as css writes it. */
39
+ properties(): string[];
40
+ /** The custom properties the page sets, as `--name`. */
41
+ customs(): string[];
42
+ }
43
+ /** A key of a style object as css writes it: `backgroundColor` as `background-color`, `webkitMask` as `-webkit-mask`. */
44
+ export declare function cssName(key: string): string;
45
+ /**
46
+ * The properties a style object names: its keys and the longhands it lists,
47
+ * those the browser takes, the prefixed ones last. Method names and the
48
+ * like are not properties, and the browser refuses them.
49
+ */
50
+ export declare function propertyNames(style: object, supports: CssWorld["supports"]): string[];
51
+ /** A rule that holds declarations, or rules of its own. */
52
+ interface RuleLike {
53
+ style?: {
54
+ length: number;
55
+ [at: number]: string;
56
+ };
57
+ cssRules?: ArrayLike<RuleLike>;
58
+ }
59
+ /** The custom properties that rules set, read from the sheets the page may read, in the order found. */
60
+ export declare function customsIn(sheets: ArrayLike<{
61
+ cssRules?: ArrayLike<RuleLike>;
62
+ }>, more?: readonly string[]): string[];
63
+ /** What an element's window knows of css, asked as the field opens, or nothing where it cannot be asked. */
64
+ export declare function browserCss(element: Element): CssWorld;
65
+ /** A property's names, the custom properties of the page after the browser's. */
66
+ export declare function nameSuggestions(world: CssWorld): string[];
67
+ /**
68
+ * What a property's value may be: its keywords, named colors where it takes
69
+ * a color, `var()` of each custom property, and the global keywords. None
70
+ * for a property the browser does not know.
71
+ */
72
+ export declare function valueSuggestions(property: string, world: CssWorld): string[];
73
+ /**
74
+ * The suggestions for what was typed: those that start with it first, then
75
+ * those that hold it, case aside, at most `MOST`. Nothing typed keeps them all.
76
+ */
77
+ export declare function matching(items: readonly string[], typed: string, most?: number): string[];
78
+ /** The word of a value the caret is in, which a suggestion takes the place of: after the last space, comma, slash or paren. */
79
+ export declare function wordAt(text: string, caret: number): {
80
+ start: number;
81
+ end: number;
82
+ word: string;
83
+ };
84
+ /**
85
+ * Whether a suggestion completes the word typed, so ↩ with none marked may
86
+ * take it: it starts with the word, case aside, past a `var(` of its own.
87
+ * A number or a `#` color is a value of its own, never the start of a keyword.
88
+ */
89
+ export declare function completes(word: string, suggestion: string): boolean;
90
+ /** What a key does while the list is open: move the mark to `to`, close it, take the one marked, or nothing of the list's. */
91
+ export type ListKey = {
92
+ act: "move";
93
+ to: number;
94
+ } | {
95
+ act: "close";
96
+ } | {
97
+ act: "take";
98
+ } | null;
99
+ /** What a key does to a list of `count`, marked at `at` (-1 for none), open or not. Down opens a closed one. */
100
+ export declare function listKey(event: Pick<KeyboardEvent, "key" | "shiftKey" | "metaKey" | "ctrlKey" | "altKey">, open: boolean, count: number, at: number): ListKey;
101
+ export interface Autocomplete {
102
+ /** A key on the field. True where it was the list's own: the field leaves it alone. Enter and Tab take the one marked, else the first where it completes the word, and still go to the field. */
103
+ key(event: KeyboardEvent): boolean;
104
+ /** Whether the list shows. */
105
+ open(): boolean;
106
+ /** Close the list, and take it off the page. */
107
+ close(): void;
108
+ /**
109
+ * Escape, as the panel hears it before the field: close the list where it
110
+ * shows, and say so. The field then leaves that escape alone.
111
+ */
112
+ dismiss(): boolean;
113
+ }
114
+ /**
115
+ * Suggestions under a field: the whole of it for a name, the word at the
116
+ * caret for a value. `items` is asked as the list opens.
117
+ */
118
+ export declare function autocomplete(input: HTMLInputElement | HTMLTextAreaElement, items: () => string[], kind: "name" | "value"): Autocomplete;
119
+ export {};
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The editing of the styles view, as the browsers' tools have it: a click on
3
+ * a value makes it a field, the box at a line's start turns the line off and
4
+ * on, and a line under a block adds a property to it. The view draws, and
5
+ * hands each line and block here to be made editable; every edit goes to the
6
+ * log. While a field is open, or a click that closed one is still under way,
7
+ * the editor is busy: the view waits with its next read of the styles, and
8
+ * is told once it may go ahead. A line under the element's rules adds a new
9
+ * rule, its selector typed first, and the line that adds a property to it
10
+ * opens once it is drawn. To use it:
11
+ *
12
+ * const editor = createCssEditor({ log, node, settled });
13
+ * editor.begin(); editor.editable(row, value, declaration, place, null); editor.addLine(place);
14
+ * editor.newRuleLine(element, ".cta");
15
+ * if (editor.busy()) wait(); editor.destroy();
16
+ */
17
+ import { type CssPlace, type Off } from "../edit/css";
18
+ import type { EditLog } from "../edit/log";
19
+ import { type Locate } from "../edit/source";
20
+ import type { OwnBlock, StyleDeclaration } from "../styles/types";
21
+ /** What the line that adds a property says. */
22
+ export declare const ADD = "+ add property";
23
+ /** What the line that adds a rule says. */
24
+ export declare const NEW_RULE = "+ new rule";
25
+ /** How long a field closed by a click elsewhere keeps the view as it is, for that click to land, at most, in ms. */
26
+ export declare const HOLD = 1000;
27
+ /** Where a block's edits go, short of the selector, which is made only for an edit. */
28
+ export type Place = Omit<CssPlace, "selector">;
29
+ export interface CssEditorContext {
30
+ log: EditLog;
31
+ /** The view's node, which takes the focus back after an edit. */
32
+ node: HTMLElement;
33
+ /** Where an edited element is written. Defaults to grab's lookup. */
34
+ locate?: Locate;
35
+ /** The editor is no longer busy: a read of the styles that waited may go ahead. */
36
+ settled(): void;
37
+ }
38
+ export interface CssEditor {
39
+ /** Where a block's edits go, or null where it cannot be edited. */
40
+ placeOf(block: OwnBlock, owner: Element): Place | null;
41
+ /** The declarations of a block that edits turned off, in the order they stand. */
42
+ offs(place: Place): Off[];
43
+ /** The view draws its lines anew: the values shown before go. */
44
+ begin(): void;
45
+ /** Make a line editable: a box that turns it off and on, and its value a field on a click. */
46
+ editable(row: HTMLElement, value: HTMLElement, declaration: StyleDeclaration, place: Place, off: Off | null): void;
47
+ /** The line under a block that adds a property to it. */
48
+ addLine(place: Place): HTMLElement;
49
+ /** The line that adds a new rule for an element, its selector field filled with `selector`. */
50
+ newRuleLine(element: Element, selector: string): HTMLElement;
51
+ /** A field is open, or a click that closed one is still under way. */
52
+ busy(): boolean;
53
+ /** Close the field open, with or without its edit. Says whether one was open. */
54
+ close(commit: boolean): boolean;
55
+ /** Escape closes the open field's suggestions first. Says whether a list of them showed. */
56
+ dismiss(): boolean;
57
+ destroy(): void;
58
+ }
59
+ /** An element's own `style`, where it has one. */
60
+ export declare function styleOf(element: Element): CSSStyleDeclaration | null;
61
+ /** A declaration an edit turned off, as a line of the view shows it. */
62
+ export declare function offDeclaration(off: Off): StyleDeclaration;
63
+ /** What a declaration's checkbox is called: what a press does, `turn off padding` while it is on. */
64
+ export declare function toggleLabel(property: string, on: boolean): string;
65
+ /** A selector that finds the element, for an edit's target. */
66
+ export declare function selectorOf(element: Element): string;
67
+ /**
68
+ * Fit a field to what it holds: as wide as its longest line, but never wider
69
+ * than the line it stands in, and as tall as its text wraps to, so a long
70
+ * value goes on under itself and nothing scrolls sideways.
71
+ */
72
+ export declare function fitField(area: HTMLTextAreaElement): void;
73
+ /** A one-line field of the editor, as wide as what it holds, that wraps where it is wider than its line. */
74
+ export declare function editField(value: string, label: string): HTMLTextAreaElement;
75
+ /**
76
+ * What a new rule's selector starts as: the element's classes, else a short
77
+ * selector that finds it, then the states forced on it, as `.cta:hover`.
78
+ */
79
+ export declare function newRuleSelector(element: Element, states?: readonly string[]): string;
80
+ export declare function createCssEditor(context: CssEditorContext): CssEditor;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The editing of the DOM tree, as the browsers' tools have it: a double-click
3
+ * on a line's text or on an attribute makes it a field, and the selected line
4
+ * takes keys and has its actions in a bar under the tree. Every edit goes to
5
+ * the log, as the styles view's do. The keys are plain, and never act while a
6
+ * field has the focus:
7
+ *
8
+ * Enter edit the text a add an attribute
9
+ * F2 edit as html h hide, or show again
10
+ * Delete delete the node ⇧↑ move up among its siblings
11
+ * ⇧↓ move down among its siblings
12
+ *
13
+ * An element's line is also dragged by its handle, before or after another
14
+ * element, or into one, through `move`.
15
+ * A one-line field puts its edit on with Enter and leaves with esc. The html
16
+ * field, and the field of a text or a value with line breaks in it, takes
17
+ * line breaks with Enter, and puts its edit on with ⇧↩ (Shift Enter
18
+ * elsewhere), its apply button, or as the focus leaves it; ⌘↩ and Ctrl Enter
19
+ * put it on too. The html field is the editor of htmledit.ts. A field closed as it was opened makes no edit. An element
20
+ * that holds devknobs' own nodes, as the body holds the panel, is not
21
+ * replaced, hidden or deleted. To use it, as the tree does:
22
+ *
23
+ * const editor = createDomEditor(hooks, { log });
24
+ * editor.dblclick(row, target); editor.key(event, row); editor.selected(row);
25
+ */
26
+ import { parseHtml } from "../edit/html";
27
+ import type { EditLog } from "../edit/log";
28
+ import { type Locate } from "../edit/source";
29
+ import { type Entry, type Row } from "./domtree";
30
+ import type { HtmlSize } from "./prefs";
31
+ /** What a key on the selected line does. */
32
+ export type TreeEditAction = "text" | "attr" | "html" | "hide" | "delete" | "up" | "down";
33
+ /** What the bar's buttons say. */
34
+ export declare const ACTIONS: Record<TreeEditAction, string>;
35
+ /** What the tree lends its editor. */
36
+ export interface TreeHooks {
37
+ /** The tree's list, which takes the focus back after an edit. */
38
+ list: HTMLElement;
39
+ /** The text of a line as built, where its fields go. Null where the line does not show. */
40
+ code(row: Row): HTMLElement | null;
41
+ /** What a node holds, as lines: the line after a deleted node is selected. */
42
+ children(node: Node): Entry[];
43
+ /** Select a node's line, and tell the view. */
44
+ select(node: Node): void;
45
+ /** The field closed: lines that waited are built now. */
46
+ settled(): void;
47
+ }
48
+ export interface DomEditorOptions {
49
+ log: EditLog;
50
+ /** Where an edited element is written. Defaults to grab's lookup. */
51
+ locate?: Locate;
52
+ /** Parses html in a document. Defaults to the page's own parser. */
53
+ parse?: typeof parseHtml;
54
+ /** How tall the html editor starts, and where the size the user gives it is kept. */
55
+ htmlSize?: {
56
+ get(): HtmlSize;
57
+ set(size: HtmlSize): void;
58
+ };
59
+ }
60
+ export interface DomEditor {
61
+ /** The bar of actions for the selected line. */
62
+ bar: HTMLElement;
63
+ /** A double-click on a line: its text or the attribute under the pointer becomes a field. */
64
+ dblclick(row: Row, target: EventTarget | null): boolean;
65
+ /** A key on the selected line. Says whether it acted. */
66
+ key(event: KeyboardEvent, row: Row | null): boolean;
67
+ /** The selection moved, or its node changed: the bar follows it. */
68
+ selected(row: Row | null): void;
69
+ /** A field is open. */
70
+ busy(): boolean;
71
+ /** Close the field open, with or without its edit; one whose edit is refused closes without it. Says whether one was open. */
72
+ close(commit: boolean): boolean;
73
+ /** Move an element into `parent`, before `next`, or at its end with null, and select it. Says whether it moved. */
74
+ move(element: Element, parent: Element, next: Element | null): boolean;
75
+ destroy(): void;
76
+ }
77
+ /** The key that puts the html field's edit on, as its hint says it: `⇧↩` on a Mac, `Shift Enter` elsewhere. */
78
+ export declare function applyHint(mac: boolean): string;
79
+ /** Whether a key puts the html field's edit on: shift and Enter, or ⌘↩ and Ctrl Enter as well. Enter alone breaks the line. */
80
+ export declare function commitsHtml(event: Pick<KeyboardEvent, "key" | "shiftKey" | "metaKey" | "ctrlKey" | "altKey">): boolean;
81
+ /** What a key on the selected line does: no modifier but shift, and never in a field. Null for any other key. */
82
+ export declare function treeEditKey(event: KeyboardEvent): TreeEditAction | null;
83
+ /** The text a line edits: a text line's own, in an element, or the one text that stands in an element's line. */
84
+ export declare function textOf(row: Row): Node | null;
85
+ /** Which of its element's texts a text is: `text`, then `text 2` and on, the blank ones not counted. */
86
+ export declare function textProperty(node: Node): string;
87
+ /**
88
+ * The attributes `text` writes, `name="value"` as in a tag, read by the
89
+ * page's own parser, in an svg tag for an svg element's, so `viewBox` keeps
90
+ * its case. Null where it writes none.
91
+ */
92
+ export declare function parseAttributes(doc: Document, text: string, svg?: boolean, parse?: typeof parseHtml): [string, string][] | null;
93
+ /** Whether an element holds devknobs' own nodes, as the body holds the panel and the head its styles. */
94
+ export declare function holdsOwn(element: Element): boolean;
95
+ /** The actions a line can take. */
96
+ export declare function actionsFor(row: Row | null): TreeEditAction[];
97
+ /** An attribute's value as a tag writes it in quotes: `&` and `"` as references, which the parser reads back. */
98
+ export declare function quotedValue(value: string): string;
99
+ export declare function createDomEditor(hooks: TreeHooks, options: DomEditorOptions): DomEditor;
@@ -11,11 +11,15 @@
11
11
  * past `CHILD_CAP` children a line says how many more there are, which shows
12
12
  * them all. Only the lines that show are built, each once, and built again
13
13
  * when its node changes. One observer watches what shows, and a node that
14
- * changed lights for a moment. To use it:
14
+ * changed lights for a moment. Given an editor, its text and attributes
15
+ * can be edited, as `domedit.ts` says, and an element's line has a handle,
16
+ * ⋮⋮, on hover and while selected, that drags the element before or after
17
+ * another, or into one; esc lets go without a move. To use it:
15
18
  *
16
19
  * const tree = createDomTree({ outline, select, copy });
17
20
  * body.append(tree.node); tree.reveal(element); tree.destroy();
18
21
  */
22
+ import type { DomEditor, TreeHooks } from "./domedit";
19
23
  /** How many children of a node show before the line that shows the rest, as in the browser's tools. */
20
24
  export declare const CHILD_CAP = 500;
21
25
  /** The longest text that stands inside its element's line, as in the browser's tools. */
@@ -108,6 +112,21 @@ export interface TreeModel {
108
112
  pieces(row: Row): Piece[];
109
113
  }
110
114
  export declare function createTreeModel(page?: TreePage): TreeModel;
115
+ /** Where a dragged element goes: into `parent`, before `next`, or at its end with null, shown on a line as `where`. */
116
+ export interface DropPlace {
117
+ parent: Element;
118
+ next: Element | null;
119
+ where: "before" | "after" | "into";
120
+ }
121
+ /**
122
+ * Where an element dragged onto a line goes, by how far down the line the
123
+ * pointer is, 0 at its top and 1 at its bottom. An element's line: its top
124
+ * quarter before it, its bottom quarter after it, or, where it is open, first
125
+ * in it, and the middle into it, at its end. An end tag's line: its top half
126
+ * into the element, at its end, the rest after it. Null on other lines, on
127
+ * the dragged element's own and those in it, and where the place cannot take it.
128
+ */
129
+ export declare function dropAt(row: Row, fraction: number, dragged: Element, open: boolean): DropPlace | null;
111
130
  /** Whether a line can be selected: every one but an end tag and the line that shows more. */
112
131
  export declare function selectable(row: Row): boolean;
113
132
  /** The line of the node a line is in: the one a level up, before it. */
@@ -131,13 +150,19 @@ export interface DomTreeContext {
131
150
  select(node: Node, pseudo: string | null): void;
132
151
  /** Put a text on the clipboard. */
133
152
  copy(text: string): void;
153
+ /** Makes the tree's editor, which the lines' text and attributes are edited with. Left out, the tree is read only. */
154
+ editor?(hooks: TreeHooks): DomEditor;
134
155
  }
135
156
  export interface DomTree {
136
157
  node: HTMLElement;
137
158
  /** Show the tree of the node's document, with the node selected and in view. Null shows no tree. */
138
159
  reveal(node: Node | null, pseudo?: string | null): void;
160
+ /** Select a node's line, and tell the view, as a click on it does. */
161
+ select(node: Node): void;
139
162
  /** The node selected, or null. */
140
163
  selected(): Node | null;
164
+ /** Close a field open in the tree, without its edit. Says whether one was open. */
165
+ escape(): boolean;
141
166
  destroy(): void;
142
167
  }
143
168
  export declare function createDomTree(context: DomTreeContext, model?: TreeModel): DomTree;
@@ -5,11 +5,19 @@
5
5
  * shows its element's styles, and an element the styles show, a pick on the
6
6
  * page or a crumb, is revealed in the tree. The node selected is `$0` on its
7
7
  * page's window while the view is up, as in the browser's console, unless the
8
- * page has a `$0` of its own. To use it, as the styles view:
8
+ * page has a `$0` of its own. The styles and the tree's html can be edited,
9
+ * and the edits are listed at the foot, with Z to undo and ⇧Z to redo while
10
+ * the focus is in the view and not in a field. Where an undo takes away the
11
+ * node selected, as one of an element written anew as html, the node put
12
+ * back in its place is selected. A switch at the top keeps the edits after a
13
+ * reload, as `edit/keep.ts` says. To use it, as the styles view:
9
14
  *
10
15
  * const view = createElementsView(context);
11
16
  * body.append(view.node); view.show(element); view.destroy();
12
17
  */
18
+ import { type Keeper } from "../edit/keep";
19
+ import { type EditLog } from "../edit/log";
20
+ import { type Copy } from "./changes";
13
21
  import { createDomTree, type DomTree } from "./domtree";
14
22
  import { type StylesContext, type StylesPage, type StylesView } from "./stylesview";
15
23
  /** The name the console knows the node selected in the Elements panel by. */
@@ -18,8 +26,17 @@ export declare const DOLLAR = "$0";
18
26
  export interface ElementsParts {
19
27
  page?: StylesPage;
20
28
  tree?: (context: Parameters<typeof createDomTree>[0]) => DomTree;
21
- copy?: (text: string) => void;
29
+ /** Copies a text, and says whether it went. */
30
+ copy?: Copy;
31
+ /** The log the edits go to. Defaults to the page's one. */
32
+ edits?: EditLog;
33
+ /** What keeps the edits after a reload. Defaults to the page's one; without one the view has no switch. */
34
+ keep?: Keeper | null;
22
35
  }
36
+ /** What the switch at the top of the view says. */
37
+ export declare const KEEP_LABEL = "keep edits after reload";
38
+ /** Whether a keydown is the view's undo, z, or its redo, shift z: no other modifier, and not in a field. */
39
+ export declare function undoKey(event: KeyboardEvent): "undo" | "redo" | null;
23
40
  /**
24
41
  * Sets `$0` on a window while a node is selected, and takes it away after.
25
42
  * A window that already has a `$0` keeps it, and one the page set over ours
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The editor of the tree's "edit as html": a text box over the same text
3
+ * colored as html (tags, attributes, values, comments), the two kept in step
4
+ * as it scrolls, with the line numbers beside it. A line wider than the box
5
+ * wraps, in the text and its colors alike, and its number stands at its
6
+ * first row. It types as a code editor:
7
+ *
8
+ * ↩ a new line with the line's indent, one more after an opening tag
9
+ * > closes the tag it ends, `<div>` making `<div></div>`, but a void one
10
+ * " ' a pair of quotes after `=` in a tag, and over the closing one
11
+ *
12
+ * Its height is dragged by the grip under it, and the expand button makes
13
+ * it as tall as the panel. Both are kept as `size` says. The field around it
14
+ * puts its edit on and leaves, as domedit.ts says. To use it:
15
+ *
16
+ * const editor = htmlEditor(markup, label, size);
17
+ * row.append(editor.frame); editor.shown(); editor.area.value; editor.restore();
18
+ */
19
+ import { type HtmlSize } from "./prefs";
20
+ /** How much a level of html is indented. */
21
+ export declare const INDENT = " ";
22
+ /** Elements that have no end tag. */
23
+ export declare const VOID_ELEMENTS: Set<string>;
24
+ /** A piece of html as the editor colors it. */
25
+ export interface HtmlToken {
26
+ kind: "tag" | "attr" | "val" | "com" | "doc" | "text";
27
+ text: string;
28
+ }
29
+ /**
30
+ * Html cut into the pieces it is colored by: a tag's name and its marks, an
31
+ * attribute's name and its value, a comment, a doctype, and the text between.
32
+ * What is not closed yet runs to the end, so a half-typed tag colors too.
33
+ */
34
+ export declare function htmlTokens(text: string): HtmlToken[];
35
+ /** What a key types in place of the selection: `insert`, and where the caret goes from its start, past it where nothing is typed. */
36
+ export interface Typed {
37
+ insert: string;
38
+ caret: number;
39
+ }
40
+ /**
41
+ * What a key does to the editor's text, typed at `start` to `end`, or null
42
+ * for the browser's own: ↩ keeps the line's indent, ">" closes a tag, a quote
43
+ * pairs after `=` in a tag and steps over the closing one.
44
+ */
45
+ export declare function typedKey(text: string, start: number, end: number, key: string): Typed | null;
46
+ /** A text's tokens by line, each cut where it has a line break, so a line wraps as a block of its own. */
47
+ export declare function tokenLines(text: string): HtmlToken[][];
48
+ export interface HtmlEditor {
49
+ /** The editor, what goes in the line. */
50
+ frame: HTMLElement;
51
+ /** The text box, the field itself. */
52
+ area: HTMLTextAreaElement;
53
+ /** The editor is on the page: it takes the size it was left at. */
54
+ shown(): void;
55
+ /** The editor goes: the tree's box gets back the height it had. */
56
+ restore(): void;
57
+ }
58
+ /** The editor for `value`, its size from `size`, which keeps what the user sets. */
59
+ export declare function htmlEditor(value: string, label: string, size?: {
60
+ get(): HtmlSize;
61
+ set(next: HtmlSize): void;
62
+ } | null): HtmlEditor;
@@ -30,6 +30,11 @@ export interface Inspector {
30
30
  * opens the view on the element it holds, and with none it starts picking.
31
31
  */
32
32
  open(): void;
33
+ /**
34
+ * What the elements view's key does: open the view on the element it holds,
35
+ * else on the page's body, and pick nothing.
36
+ */
37
+ elements(): void;
33
38
  /** The name of the element the view holds, as devtools names one, or null with none. */
34
39
  picked(): string | null;
35
40
  /**
@@ -53,7 +58,7 @@ export declare function createInspector(context: {
53
58
  inspect: InspectControl;
54
59
  tips: Tips;
55
60
  /** Where the view's mode is kept. Without it the view is the advanced one. */
56
- prefs?: Pick<LivePrefs, "get" | "setStylesMode" | "setStylesBox">;
61
+ prefs?: Pick<LivePrefs, "get" | "setStylesMode" | "setStylesBox" | "setChangesDiff" | "setHtmlSize">;
57
62
  /** Inspect's key as it is now, for the select button to say. */
58
63
  key?: () => string;
59
64
  }, load?: LoadStyles, pane?: PaneDoor): Inspector;