spell-ui 0.8.12 → 0.8.13

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 (68) hide show
  1. package/README-components.md +5 -3
  2. package/dist/{Dragging-B93hbRxF.js → Dragging-tHPSvf3G.js} +56 -13
  3. package/dist/Dragging-tHPSvf3G.js.map +1 -0
  4. package/dist/_spell-element/DOMElement.d.ts +8 -1
  5. package/dist/_spell-element/drawnWindow.d.ts +62 -0
  6. package/dist/_util/Dragging.d.ts +7 -0
  7. package/dist/components/components.types.d.ts +2 -0
  8. package/dist/components/ui-diagram/UIDiagram.d.ts +3 -0
  9. package/dist/components/ui-graph/GraphLayout.d.ts +54 -0
  10. package/dist/components/ui-graph/UIGraph.d.ts +355 -0
  11. package/dist/components/ui-graph/UIGraph.en.d.ts +137 -0
  12. package/dist/components/ui-graph/UIGraph.es.d.ts +48 -0
  13. package/dist/components/ui-graph/UIGraph.types.d.ts +193 -0
  14. package/dist/components/ui-graph/index.d.ts +5 -0
  15. package/dist/components/ui-json/UIJson.d.ts +275 -10
  16. package/dist/components/ui-json/UIJson.en.d.ts +148 -9
  17. package/dist/components/ui-json/UIJson.es.d.ts +34 -3
  18. package/dist/components/ui-json/index.d.ts +2 -2
  19. package/dist/components/ui-split-panel/UISplitPanel.d.ts +2 -16
  20. package/dist/components/ui-tree/UITree.d.ts +758 -26
  21. package/dist/components/ui-tree/UITree.en.d.ts +113 -3
  22. package/dist/components/ui-tree/UITree.es.d.ts +24 -0
  23. package/dist/components/ui-tree/UITree.types.d.ts +34 -0
  24. package/dist/components/ui-tree/UITreeItem.d.ts +40 -1
  25. package/dist/components/ui-tree/UITreeItem.en.d.ts +9 -0
  26. package/dist/components/ui-tree/UITreeItem.es.d.ts +2 -0
  27. package/dist/components/ui-tree/index.d.ts +3 -2
  28. package/dist/components/ui-tree-diagram/UITreeDiagram.d.ts +3 -0
  29. package/dist/{components.es-DEa8Ep42.js → components.es-DilRG1VO.js} +117 -9
  30. package/dist/components.es-DilRG1VO.js.map +1 -0
  31. package/dist/core.js +713 -671
  32. package/dist/core.js.map +1 -1
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +97 -96
  35. package/dist/jsx.d.ts +489 -20
  36. package/dist/ui-diagram.js +2 -2
  37. package/dist/ui-diagram.js.map +1 -1
  38. package/dist/ui-graph.editor-DLsXPyby.js +5 -0
  39. package/dist/ui-graph.editor-DLsXPyby.js.map +1 -0
  40. package/dist/ui-graph.js +1295 -0
  41. package/dist/ui-graph.js.map +1 -0
  42. package/dist/ui-json.editor-BS-v1bqO.js +5 -0
  43. package/dist/ui-json.editor-BS-v1bqO.js.map +1 -0
  44. package/dist/ui-json.js +629 -32
  45. package/dist/ui-json.js.map +1 -1
  46. package/dist/ui-property-editor.js +3 -2
  47. package/dist/ui-property-editor.js.map +1 -1
  48. package/dist/ui-root.js +34 -3
  49. package/dist/ui-root.js.map +1 -1
  50. package/dist/ui-site-nav.js +4 -4
  51. package/dist/ui-site-nav.js.map +1 -1
  52. package/dist/ui-split-panel.js +31 -61
  53. package/dist/ui-split-panel.js.map +1 -1
  54. package/dist/ui-tree-diagram.js +1 -1
  55. package/dist/ui-tree-diagram.js.map +1 -1
  56. package/dist/ui-tree.editor-Bqsa0dYQ.js +5 -0
  57. package/dist/ui-tree.editor-Bqsa0dYQ.js.map +1 -0
  58. package/dist/ui-tree.js +1734 -237
  59. package/dist/ui-tree.js.map +1 -1
  60. package/dist/util/PaneSizes.d.ts +42 -0
  61. package/dist/util/index.d.ts +2 -0
  62. package/package.json +1 -1
  63. package/dist/Dragging-B93hbRxF.js.map +0 -1
  64. package/dist/components.es-DEa8Ep42.js.map +0 -1
  65. package/dist/ui-json.editor-BgZbrB_W.js +0 -5
  66. package/dist/ui-json.editor-BgZbrB_W.js.map +0 -1
  67. package/dist/ui-tree.editor-BoQztwdz.js +0 -5
  68. package/dist/ui-tree.editor-BoQztwdz.js.map +0 -1
package/dist/ui-json.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import "./rolldown-runtime-c6e9CmGy.js";
2
- import { DOMLoadableElement as e, Gt as t, Jt as n, Kt as r, LoadableComponent as i, SourceEvent as a, SourceStatus as o, Ut as s, Warnings as c, Wt as l, Yt as u, cssState as d, derived as f, ft as p, ht as m, onChange as h, proto as g, protoMerged as _, st as v } from "./core.js";
2
+ import { ClipboardCopy as e, DOMLoadableElement as t, Gt as n, Jt as r, Kt as i, LoadableComponent as a, SourceEvent as o, SourceStatus as s, Ut as c, Warnings as l, Wt as u, Yt as d, after as f, afterSolidUpdate as p, beforeNextPaint as m, cssState as h, derived as g, ft as _, gt as v, ht as ee, mt as y, onChange as te, proto as b, protoMerged as ne, qt as x, st as re, state as S, untracked as C, whileConnected as ie } from "./core.js";
3
+ import "./ui-icon.js";
4
+ import "./ui-button.js";
5
+ import "./ui-loader.js";
6
+ import "./ui-message.js";
7
+ import { For as ae, Show as w } from "solid-js";
8
+ import { className as oe, createComponent as T, delegateEvents as se, effect as E, getOwner as D, insert as O, memo as k, readShallow as ce, ref as A, setAttribute as j, style as M, template as N } from "@solidjs/web";
3
9
  // src/components/ui-json/JsonChild.ts
4
- var y = "ui-json-data-changed", b = class JsonChild {
10
+ var le = "ui-json-data-changed", ue = class JsonChild {
5
11
  static of(e) {
6
12
  for (let t of e.children) if (JsonChild.isJsonElement(t) || t.localName === "script" && t.getAttribute("type")?.trim() === "application/json") return t;
7
13
  }
@@ -19,7 +25,7 @@ var y = "ui-json-data-changed", b = class JsonChild {
19
25
  static isJsonElement(e) {
20
26
  return /^[a-z]+-json$/.test(e.localName);
21
27
  }
22
- }, [x, , S, C, w] = p, T = {
28
+ }, [de, , fe, pe, me] = _, he = {
23
29
  tag: "ui-json",
24
30
  icon: "code",
25
31
  topics: ["data display", "modules"],
@@ -29,40 +35,202 @@ var y = "ui-json-data-changed", b = class JsonChild {
29
35
  "json script",
30
36
  "application/json",
31
37
  "data block",
38
+ "json viewer",
39
+ "json tree",
40
+ "object inspector",
41
+ "pretty print",
32
42
  "datos"
33
43
  ],
44
+ skeleton: "4 line paragraph",
34
45
  noun: "JSON data",
35
46
  partOfSpeech: "property",
36
- description: "JSON data holds data in a page, as its text or from a file with `source`. It draws nothing: `value` is the parsed data, `ui-changed` says when it changed, and an element it sits inside may read it.",
37
- attributes: [...v],
47
+ description: "JSON data holds data in a page, as its text or from a file with `source`, and shows it as an outline whose objects and arrays open and close. `value` is the parsed data, and an element it sits inside may read it.",
48
+ attributes: [
49
+ ...re,
50
+ {
51
+ name: "depth",
52
+ group: "behaviour",
53
+ kind: "number",
54
+ default: 1,
55
+ description: "How many levels start open: `1`, the top object or array alone; `0`, everything closed. New data opens this way again."
56
+ },
57
+ {
58
+ name: "quotes",
59
+ group: "appearance",
60
+ kind: "boolean",
61
+ default: !0,
62
+ description: "Keys in quotes, as JSON writes them: `\"type\": \"optical\"`. `quotes=\"no\"`: `type: \"optical\"`, as JSON5 allows (a key that isn't a name keeps its quotes). The header's quotes button sets it. Copy always copies JSON."
63
+ },
64
+ {
65
+ name: "no-header",
66
+ group: "appearance",
67
+ kind: "boolean",
68
+ default: !1,
69
+ description: "Hides the header: the Copy and quotes buttons."
70
+ },
71
+ {
72
+ name: "editable",
73
+ group: "behaviour",
74
+ kind: "boolean",
75
+ default: !1,
76
+ description: "Double-click a key or a value to edit it, in a control that fits the value: a text field for a string, a number field for a number, a date picker for an ISO date, a checkbox for `true` / `false`, a pick list for a key `editors` gives choices. Enter (or leaving it) keeps the edit, Escape drops it. `value` changes and `ui-changed` is sent; what's open stays open."
77
+ },
78
+ {
79
+ name: "editors",
80
+ group: "behaviour",
81
+ kind: "json",
82
+ reflect: !1,
83
+ description: "With `editable`, the control for each key, as a PROPERTY: `{ direction: [\"in\", \"out\"], when: \"date\" }`. A list of strings makes a pick list; a word names the control: `text`, `number`, `date`, `datetime`, `boolean` or `json` (a text field read as JSON). A key it doesn't name gets the control its value's type picks."
84
+ }
85
+ ],
38
86
  events: [
39
- x,
87
+ de,
40
88
  {
41
89
  name: "ui-changed",
42
90
  detail: "{ value: unknown, content: string }",
43
- description: "The data changed: loaded from `source`, set through `value` or `content`, or its text edited. `value` is `undefined` when the text is empty or isn't JSON."
91
+ description: "The data changed: loaded from `source`, set through `value` or `content`, edited in the outline, or its text edited. `value` is `undefined` when the text is empty or isn't JSON."
44
92
  },
45
- S,
46
- C,
47
- w
93
+ fe,
94
+ pe,
95
+ me,
96
+ {
97
+ name: "ui-navigating",
98
+ cancelable: !0,
99
+ detail: "{ path: (string | number)[], key: string | number | undefined, value: unknown, part: \"key\" | \"value\" }",
100
+ description: "A key or a value was clicked (not a double-click, nor the end of a text selection). `path`: the keys from the top value down to that member (`[]`: the top value); `key`: its key, an array member's index; `value`: its value (an object or array too, when its key was clicked); `part`: which was clicked. The page decides what it means (jumping to what a value names) and calls `preventDefault()`."
101
+ },
102
+ {
103
+ name: "ui-copied",
104
+ detail: "{ content: string }",
105
+ description: "The Copy button copied `content`, as JSON."
106
+ }
48
107
  ],
49
108
  slots: [],
50
- parts: [],
51
- states: [...m],
52
- texts: []
53
- }, E = "@layer ui.components.json.types{:host{display:none}}", D, O, k, A, j, M, N, DOMJsonElement = class extends e {
54
- static {
55
- r(this, "DOMJsonElement");
109
+ parts: [
110
+ ...y,
111
+ {
112
+ name: "viewer",
113
+ description: "The box round it all."
114
+ },
115
+ {
116
+ name: "header",
117
+ description: "The bar above the data: Copy, then the quotes button."
118
+ },
119
+ {
120
+ name: "row",
121
+ description: "Each line."
122
+ },
123
+ {
124
+ name: "toggle",
125
+ description: "Each object's or array's open / close button, a chevron in the left gutter; Alt-click: its whole branch."
126
+ },
127
+ {
128
+ name: "preview",
129
+ description: "A closed object or array, on one line."
130
+ },
131
+ {
132
+ name: "editor",
133
+ description: "The control a key or value is edited in (`editable`)."
134
+ }
135
+ ],
136
+ states: [...ee],
137
+ texts: [
138
+ ...v,
139
+ {
140
+ key: "jsonCopy",
141
+ text: "Copy JSON",
142
+ description: "The header's Copy button."
143
+ },
144
+ {
145
+ key: "jsonCopied",
146
+ text: "Copied",
147
+ description: "The Copy button, for a moment after it copied."
148
+ },
149
+ {
150
+ key: "jsonQuotes",
151
+ text: "Quotes round keys",
152
+ description: "The quotes button's name (a toggle)."
153
+ },
154
+ {
155
+ key: "jsonQuotesOff",
156
+ text: "Hide the quotes round keys",
157
+ description: "The quotes button's tooltip, on."
158
+ },
159
+ {
160
+ key: "jsonQuotesOn",
161
+ text: "Show the quotes round keys",
162
+ description: "The quotes button's tooltip, off."
163
+ },
164
+ {
165
+ key: "jsonEditKey",
166
+ text: "Key",
167
+ description: "The field a key is edited in."
168
+ },
169
+ {
170
+ key: "jsonEditValue",
171
+ text: "Value",
172
+ description: "The control a value is edited in."
173
+ },
174
+ {
175
+ key: "jsonOpen",
176
+ text: "Open {key}",
177
+ description: "A closed object's or array's toggle."
178
+ },
179
+ {
180
+ key: "jsonClose",
181
+ text: "Close {key}",
182
+ description: "An open object's or array's toggle."
183
+ },
184
+ {
185
+ key: "jsonAllInside",
186
+ text: "Alt: everything inside",
187
+ description: "Added to a toggle's tooltip."
188
+ },
189
+ {
190
+ key: "jsonTop",
191
+ text: "the data",
192
+ description: "The top value's name, in its toggle's label."
193
+ },
194
+ {
195
+ key: "jsonEmpty",
196
+ text: "No data",
197
+ description: "Nothing to show: no text, or a `source` still loading."
198
+ },
199
+ {
200
+ key: "jsonInvalid",
201
+ text: "This isn't JSON: {message}",
202
+ description: "The error message when its text isn't JSON; `{message}` is the parser's."
203
+ }
204
+ ]
205
+ }, ge = "@layer ui.components.json.types{:host{display:block}:host([hidden]){display:none}.ui.json{--_ui-json-font-family:var(--ui-json-font-family,var(--ui-font-family-mono,ui-monospace, monospace));--_ui-json-font-size:var(--ui-json-font-size,.875em);--_ui-json-line-height:var(--ui-json-line-height,1.5);--_ui-json-color:var(--ui-json-color,var(--ui-code-color,var(--ui-text-color)));--_ui-json-key-color:var(--ui-json-key-color,var(--ui-code-attr,light-dark(#b8322a,#e06c75)));--_ui-json-string-color:var(--ui-json-string-color,var(--ui-code-string,light-dark(#387a37,#98c379)));--_ui-json-number-color:var(--ui-json-number-color,var(--ui-code-number,var(--ui-code-constant,light-dark(#986801,#d19a66))));--_ui-json-keyword-color:var(--ui-json-keyword-color,var(--ui-code-keyword,light-dark(#a626a4,#c678dd)));--_ui-json-punctuation-color:var(--ui-json-punctuation-color,var(--ui-text-muted));--_ui-json-muted-color:var(--ui-json-muted-color,var(--ui-text-muted));--_ui-json-hover-background:var(--ui-json-hover-background,var(--ui-surface-muted,transparent));--_ui-json-focus-color:var(--ui-json-focus-color,var(--ui-focus-color,var(--ui-primary)));--_json-tool-size:28px;--_json-gutter:1.5em;font-family:var(--_ui-json-font-family);font-size:var(--_ui-json-font-size);line-height:var(--_ui-json-line-height);color:var(--_ui-json-color);tab-size:2;position:relative}.row{--_json-indent:calc(var(--_json-gutter) + var(--level,0) * 2ch);text-indent:-2ch;white-space:pre-wrap;overflow-wrap:break-word;border-radius:.25em;padding-inline-start:calc(var(--_json-indent) + 2ch);position:relative}.row.container{text-indent:0;white-space:pre;align-items:baseline;padding-inline-start:var(--_json-indent);display:flex}.row.container>*{flex:none}.row.container>.preview{text-overflow:ellipsis;flex:0 auto;min-width:0;overflow:hidden}.row.container:hover{background:var(--_ui-json-hover-background)}.header{border-block-end:1px solid var(--ui-border-color,transparent);font-family:var(--ui-font-family,system-ui);justify-content:flex-start;gap:.25em;margin-block-end:.25em;padding-block-end:.25em;display:flex}.tool{all:unset;box-sizing:border-box;width:var(--_json-tool-size);height:var(--_json-tool-size);border-radius:var(--ui-radius-s,4px);color:var(--_ui-json-muted-color);cursor:pointer;place-items:center;display:inline-grid}.tool ui-icon{margin:0}.tool:hover{color:var(--_ui-json-color);background:color-mix(in srgb, currentColor 8%, transparent)}.tool[aria-pressed=true]{color:var(--_ui-json-color);background:color-mix(in srgb, currentColor 14%, transparent)}.tool[aria-pressed=true]:hover{background:color-mix(in srgb, currentColor 18%, transparent)}.tool:focus-visible{outline:2px solid var(--_ui-json-focus-color);outline-offset:-2px}.tool .glyph{font-family:var(--_ui-json-font-family);letter-spacing:.05em;font-size:1.125em;line-height:1}.toggle{all:unset;width:var(--_json-gutter);height:calc(var(--_ui-json-line-height) * 1em);cursor:pointer;color:var(--_ui-json-muted-color);border-radius:.25em;place-items:center;display:grid;position:absolute;inset-block-start:0;inset-inline-start:calc(var(--level,0) * 2ch)}.toggle ui-icon{margin:0;font-size:.875em}.toggle:hover{color:var(--_ui-json-color)}.toggle:focus-visible{outline:2px solid var(--_ui-json-focus-color);outline-offset:-1px}.key{color:var(--_ui-json-key-color)}.string{color:var(--_ui-json-string-color)}.number{color:var(--_ui-json-number-color)}.boolean,.null{color:var(--_ui-json-keyword-color)}.punct{color:var(--_ui-json-punctuation-color)}.link{cursor:pointer}.link:hover{text-decoration:underline;-webkit-text-decoration-color:color-mix(in srgb, currentColor 55%, transparent);-webkit-text-decoration-color:color-mix(in srgb, currentColor 55%, transparent);text-decoration-color:color-mix(in srgb, currentColor 55%, transparent);text-underline-offset:.2em}.edit{--ui-font-family:var(--_ui-json-font-family);--ui-font-size:1em;--ui-scale:1;--ui-control-height:0px;text-indent:0;vertical-align:top;margin:0;font-size:1em}ui-input.edit,ui-select.edit{box-sizing:border-box;height:calc(var(--_ui-json-line-height) * 1em)}ui-input.edit::part(control),ui-select.edit::part(select){min-height:0;line-height:calc(var(--_ui-json-line-height) * 1em - 2 * var(--ui-border-width,1px));padding-block:0}ui-input.edit::part(control){padding-inline:.25em}ui-input.edit{width:min(calc(var(--edit-chars,8) * 1ch + .5em + 2 * var(--ui-border-width,1px)), 100%)}ui-checkbox.edit{--ui-scale:calc(1 / 1.21428);vertical-align:middle}@media (width<768px){.edit{font-size:max(1em,16px)}}.empty{color:var(--_ui-json-muted-color);font-style:italic}.probe{visibility:hidden;white-space:pre;pointer-events:none;position:absolute}}", _e = /* @__PURE__ */ N("<div class=\"ui json\"><span class=probe aria-hidden=true>0000000000</span><div class=body>"), ve = /* @__PURE__ */ N("<div class=header><button type=button class=\"tool copy\"><ui-icon></ui-icon></button><button type=button class=\"tool quotes\"><span class=glyph aria-hidden=true>\"\"", 1), ye = /* @__PURE__ */ N("<div class=empty>"), be = /* @__PURE__ */ N("<span class=punct>,"), xe = /* @__PURE__ */ N("<div class=row><!><!><!>"), Se = /* @__PURE__ */ N("<span class=punct>"), Ce = /* @__PURE__ */ N("<div class=\"row container\"><button type=button class=toggle><ui-icon></ui-icon></button><!><!>", 1), we = /* @__PURE__ */ N("<div class=row><span class=punct>"), Te = /* @__PURE__ */ N("<span class=preview>"), Ee = /* @__PURE__ */ N("<span>"), De = /* @__PURE__ */ N("<span class=key>"), Oe = /* @__PURE__ */ N("<span class=punct>: "), ke = /* @__PURE__ */ N("<ui-select class=edit>", 1), Ae = /* @__PURE__ */ N("<ui-checkbox class=edit>", 1), je = /* @__PURE__ */ N("<ui-input class=edit>", 1), Me, Ne, P, F, Pe, Fe, I, L, R, z, B, V, H, Ie, Le, Re, ze, Be, U, W, G, K, q, J = class _DOMJsonElement extends (P = t, Ne = [C], Me = [C], P) {
206
+ constructor() {
207
+ super(...arguments), d(F, 5, this);
56
208
  }
57
209
  get value() {
58
- return this.component ? this.component.value : F.parsedFrom(i.inlineTextOf(this)).value;
210
+ return this.component ? this.component.value : X.parsedFrom(a.inlineTextOf(this)).value;
59
211
  }
60
212
  set value(e) {
61
213
  this.content = JSON.stringify(e, null, 2) ?? "";
62
214
  }
63
- }, P = class _UIJson extends (M = i, j = [g], A = [_], k = [f], O = [d("error")], D = [h("parsed")], M) {
215
+ get item() {
216
+ return this.shownItem;
217
+ }
218
+ set item(e) {
219
+ this.shownItem = e;
220
+ let t = e?.data;
221
+ this.value = t === void 0 ? e instanceof Element ? void 0 : e : t;
222
+ }
223
+ copy() {
224
+ return this.component?.copy() ?? Promise.resolve(!1);
225
+ }
226
+ setQuotes(e) {
227
+ this.component?.setQuotes(e);
228
+ }
229
+ };
230
+ F = n(P), c(F, 1, "copy", Ne, J), c(F, 1, "setQuotes", Me, J), u(F, J), i(J, "DOMJsonElement");
231
+ var Ve = J, Y = class _UIJson extends (U = a, Be = [b], ze = [ne], Re = [g], Le = [h("error")], Ie = [te("parsed")], H = [S], V = [C], B = [C], z = [C], R = [S], L = [ie], I = [S], Fe = [C], Pe = [C], U) {
64
232
  constructor() {
65
- super(...arguments), u(N, 5, this), n(this, "hasStarted", !1);
233
+ super(...arguments), d(W, 5, this), r(this, "hasStarted", !1), r(this, "keepsToggles", !1), x(this, G, d(W, 8, this, /* @__PURE__ */ new Map())), d(W, 11, this), r(this, "clipboard", new e()), r(this, "box"), x(this, K, d(W, 12, this)), d(W, 15, this), x(this, q, d(W, 16, this)), d(W, 19, this), r(this, "pendingNavigate");
66
234
  }
67
235
  get parsed() {
68
236
  return _UIJson.parsedFrom(this.textToShow);
@@ -73,24 +241,324 @@ var y = "ui-json-data-changed", b = class JsonChild {
73
241
  get hasError() {
74
242
  return super.hasError || !!this.parsed.error;
75
243
  }
244
+ get errorText() {
245
+ let { error: e } = this.parsed;
246
+ return e ? this.translationForKey("jsonInvalid", { message: e instanceof Error ? e.message : plainText(e) }) : super.errorText;
247
+ }
76
248
  onParsedChanged({ value: e, error: t }) {
77
249
  let n = !this.hasStarted;
78
- this.hasStarted = !0, t ? this.onLoadError(t, "render") : this.loadStatus === o.error && (this.loadStatus = o.loaded), n || (this.domElement.dispatchEvent(new Event(y, { bubbles: !0 })), this.send("ui-changed", {
250
+ this.hasStarted = !0, t ? this.onLoadError(t, "render") : this.loadStatus === s.error && (this.loadStatus = s.loaded), n || (this.keepsToggles ? this.keepsToggles = !1 : this.toggled = /* @__PURE__ */ new Map(), this.domElement.dispatchEvent(new Event(le, { bubbles: !0 })), this.send("ui-changed", {
79
251
  value: e,
80
252
  content: this.content
81
253
  }));
82
254
  }
83
255
  onLoadError(e, t) {
84
- c.warn(`<${this.domElement.localName}>`, "can't read its data", e), super.onLoadError(e, t);
256
+ l.warn(`<${this.domElement.localName}>`, "can't read its data", e), super.onLoadError(e, t);
85
257
  }
86
258
  sendSourceEvent(e, t) {
87
- return e === a.change || super.sendSourceEvent(e, t);
259
+ return e === o.change || super.sendSourceEvent(e, t);
88
260
  }
89
- render() {
90
- return null;
261
+ get openDepth() {
262
+ let e = Number(this.depth ?? 1);
263
+ return Number.isFinite(e) ? e : 1;
264
+ }
265
+ isOpen(e, t) {
266
+ return this.toggled.get(e) ?? t < this.openDepth;
267
+ }
268
+ toggle(e, t, n, r = !1) {
269
+ let a = !this.isOpen(e, n), o = new Map(this.toggled);
270
+ if (o.set(e, a), r) {
271
+ let n = /* @__PURE__ */ i((e, t) => {
272
+ for (let [r, i] of entriesOf(e)) {
273
+ if (!isContainer(i)) continue;
274
+ let e = t + Z + r;
275
+ o.set(e, a), n(i, e);
276
+ }
277
+ }, "walk");
278
+ n(t, e);
279
+ }
280
+ this.toggled = o;
281
+ }
282
+ async copy() {
283
+ let e = JSON.stringify(this.value, null, 2) ?? "", t = await this.clipboard.copy(e);
284
+ return t && this.send("ui-copied", { content: e }), t;
285
+ }
286
+ setQuotes(e) {
287
+ e ? this.domElement.removeAttribute("quotes") : this.domElement.setAttribute("quotes", "no");
91
288
  }
92
289
  renderContent() {
93
- return null;
290
+ let e = this;
291
+ var t = _e(), n = t.firstChild, r = n.nextSibling;
292
+ return A(() => (t) => e.box = t, t), O(t, T(w, {
293
+ get when() {
294
+ return k(() => !e.noHeader)() && e.value !== void 0;
295
+ },
296
+ get children() {
297
+ return e.header();
298
+ }
299
+ }), n), O(r, () => e.tree()), E(() => e.partForName("viewer"), (e) => {
300
+ j(t, "part", e);
301
+ }), t;
302
+ }
303
+ watchWidth() {
304
+ if (typeof ResizeObserver > "u") return;
305
+ let e = /* @__PURE__ */ i(() => {
306
+ let e = this.box?.querySelector(".probe");
307
+ if (!this.box || !e) return;
308
+ let t = e.getBoundingClientRect().width / 10, n = this.box.getBoundingClientRect().width;
309
+ if (!t || !n) return;
310
+ let r = Math.floor(n / t);
311
+ r !== this.columns && (this.columns = r);
312
+ }, "measure"), t = new ResizeObserver(e);
313
+ return p(() => {
314
+ this.box && t.observe(this.box), e();
315
+ }), () => t.disconnect();
316
+ }
317
+ header() {
318
+ let e = /* @__PURE__ */ i(() => this.translationForKey(this.clipboard.isCopied ? "jsonCopied" : "jsonCopy"), "copyLabel"), t = this;
319
+ var n = ve(), r = n.firstChild, a = r.firstChild, o = r.nextSibling;
320
+ return r._$$click = () => void t.copy(), a._$owner = D(), o._$$click = () => t.setQuotes(!t.quotes), E(() => ({
321
+ e: t.partForName("header"),
322
+ t: e(),
323
+ a: e(),
324
+ o: t.clipboard.isCopied ? We : Ue,
325
+ i: t.quotes ? "true" : "false",
326
+ n: t.translationForKey("jsonQuotes"),
327
+ s: t.translationForKey(t.quotes ? "jsonQuotesOff" : "jsonQuotesOn")
328
+ }), ({ e, t, a: i, o: s, i: c, n: l, s: u }, d) => {
329
+ e !== d?.e && j(n, "part", e), t !== d?.t && j(r, "aria-label", t), i !== d?.a && j(r, "title", i), s !== d?.o && j(a, "name", s), c !== d?.i && j(o, "aria-pressed", c), l !== d?.n && j(o, "aria-label", l), u !== d?.s && j(o, "title", u);
330
+ }), n;
331
+ }
332
+ tree() {
333
+ let { value: e } = this.parsed;
334
+ if (e === void 0) {
335
+ let e = this;
336
+ return this.isLoading || this.hasError ? void 0 : (() => {
337
+ var t = ye();
338
+ return O(t, () => e.translationForKey("jsonEmpty")), t;
339
+ })();
340
+ }
341
+ return this.entry(void 0, e, "", [], 0, !0);
342
+ }
343
+ entry(e, t, n, r, a, o) {
344
+ let s = o ? void 0 : be();
345
+ if (!isContainer(t)) {
346
+ let i = this;
347
+ var c = xe(), l = c.firstChild, u = l.nextSibling, d = u.nextSibling;
348
+ return O(c, () => i.keyOf(e, t, n, r), l), O(c, () => i.scalar(t, e, n, r), u), O(c, s, d), E(() => ({
349
+ e: i.partForName("row"),
350
+ t: `--level: ${a}`
351
+ }), ({ e, t }, n) => {
352
+ e !== n?.e && j(c, "part", e), M(c, t, n?.t);
353
+ }), c;
354
+ }
355
+ let f = Array.isArray(t), p = entriesOf(t);
356
+ if (!p.length) {
357
+ let i = this;
358
+ var m = xe(), h = m.firstChild, g = h.nextSibling, _ = g.nextSibling;
359
+ return O(m, () => i.keyOf(e, t, n, r), h), O(m, () => i.link((() => {
360
+ var e = Se();
361
+ return O(e, f ? "[]" : "{}"), e;
362
+ })(), "value", e, t, r), g), O(m, s, _), E(() => ({
363
+ e: i.partForName("row"),
364
+ t: `--level: ${a}`
365
+ }), ({ e, t }, n) => {
366
+ e !== n?.e && j(m, "part", e), M(m, t, n?.t);
367
+ }), m;
368
+ }
369
+ let v = /* @__PURE__ */ i(() => this.isOpen(n, a), "open"), ee = e === void 0 ? this.translationForKey("jsonTop") : String(e), y = /* @__PURE__ */ i(() => this.translationForKey(v() ? "jsonClose" : "jsonOpen", { key: ee }), "toggleLabel"), te = p[p.length - 1][0], b = this;
370
+ return [(() => {
371
+ var i = Ce(), o = i.firstChild, c = o.firstChild, l = o.nextSibling, u = l.nextSibling;
372
+ return o._$$click = (e) => b.toggle(n, t, a, e.altKey), c._$owner = D(), O(i, () => b.keyOf(e, t, n, r), l), O(i, T(w, {
373
+ get when() {
374
+ return v();
375
+ },
376
+ get fallback() {
377
+ return b.closed(t, s, a, e);
378
+ },
379
+ get children() {
380
+ var e = Se();
381
+ return O(e, f ? "[" : "{"), e;
382
+ }
383
+ }), u), E(() => ({
384
+ e: b.partForName("row"),
385
+ t: `--level: ${a}`,
386
+ a: !!v(),
387
+ o: b.partForName("toggle"),
388
+ i: v() ? "true" : "false",
389
+ n: y(),
390
+ s: `${y()} (${b.translationForKey("jsonAllInside")})`,
391
+ h: v() ? "chevron-down" : "chevron-right"
392
+ }), ({ e, t, a: n, o: r, i: a, n: s, s: l, h: u }, d) => {
393
+ e !== d?.e && j(i, "part", e), M(i, t, d?.t), n !== d?.a && o.classList.toggle("open", n), r !== d?.o && j(o, "part", r), a !== d?.i && j(o, "aria-expanded", a), s !== d?.n && j(o, "aria-label", s), l !== d?.s && j(o, "title", l), u !== d?.h && j(c, "name", u);
394
+ }), i;
395
+ })(), T(w, {
396
+ get when() {
397
+ return v();
398
+ },
399
+ get children() {
400
+ return [T(ae, {
401
+ each: p,
402
+ children: ([e, t]) => {
403
+ let i = f ? Number(e) : e;
404
+ return b.entry(i, t, n + Z + e, [...r, i], a + 1, e === te);
405
+ }
406
+ }), (() => {
407
+ var e = we(), t = e.firstChild;
408
+ return O(t, f ? "]" : "}"), O(e, s, null), E(() => ({
409
+ e: b.partForName("row"),
410
+ t: `--level: ${a}`
411
+ }), ({ e: t, t: n }, r) => {
412
+ t !== r?.e && j(e, "part", t), M(e, n, r?.t);
413
+ }), e;
414
+ })()];
415
+ }
416
+ })];
417
+ }
418
+ closed(e, t, n, r) {
419
+ let i = 3 + n * 2 + (typeof r == "string" ? JSON.stringify(r).length + 2 : 0) + 1, a = previewTokens(e, this.columns === void 0 ? Ke : Math.max(Ge, this.columns - i), !!this.quotes), o = this;
420
+ return [(() => {
421
+ var e = Te();
422
+ return O(e, () => a.map(([e, t]) => (() => {
423
+ var n = Ee();
424
+ return O(n, t), E(() => ce(e), (e, t) => {
425
+ oe(n, e, t);
426
+ }), n;
427
+ })())), E(() => o.partForName("preview"), (t) => {
428
+ j(e, "part", t);
429
+ }), e;
430
+ })(), t];
431
+ }
432
+ keyOf(e, t, n, r) {
433
+ if (typeof e != "string") return;
434
+ let i = this, a = this.link((() => {
435
+ var t = De();
436
+ return O(t, () => keyText(e, !!i.quotes)), t;
437
+ })(), "key", e, t, r), o = this;
438
+ return [k(() => o.editableAs(a, {
439
+ id: n + Je + "key",
440
+ part: "key",
441
+ at: r,
442
+ kind: "text",
443
+ value: e
444
+ })), Oe()];
445
+ }
446
+ scalar(e, t, n, r) {
447
+ let a = this.link((() => {
448
+ var t = Ee();
449
+ return O(t, () => scalarText(e)), E(() => ce(scalarKind(e)), (e, n) => {
450
+ oe(t, e, n);
451
+ }), t;
452
+ })(), "value", t, e, r), o = /* @__PURE__ */ i(() => ({
453
+ id: n + Je + "value",
454
+ part: "value",
455
+ at: r,
456
+ kind: this.editorKindFor(t, e),
457
+ value: e
458
+ }), "edit");
459
+ return this.editableAs(a, o);
460
+ }
461
+ link(e, t, n, r, i) {
462
+ let a = e;
463
+ return a.classList.add("link"), a.addEventListener("click", (e) => this.navigate(e, {
464
+ path: i,
465
+ key: n,
466
+ value: r,
467
+ part: t
468
+ })), a;
469
+ }
470
+ editorKindFor(e, t) {
471
+ let n = typeof e == "string" ? this.editorsByKey[e] : void 0;
472
+ return Array.isArray(n) ? n.map(String) : typeof n == "string" && He.includes(n) ? n : typeof t == "number" ? "number" : typeof t == "boolean" ? "boolean" : typeof t == "string" ? Xe.test(t) ? "date" : $.test(t) ? "datetime" : "text" : "json";
473
+ }
474
+ get editorsByKey() {
475
+ let e = this.editors;
476
+ return isContainer(e) && !Array.isArray(e) ? e : {};
477
+ }
478
+ editableAs(e, t) {
479
+ let n = typeof t == "function" ? t : () => t;
480
+ e.addEventListener("dblclick", (e) => {
481
+ this.editable && (e.preventDefault(), this.pendingNavigate?.cancel(), window.getSelection()?.removeAllRanges(), loadEditors().catch((e) => l.warn(`<${this.domElement.localName}>`, "can't load its editors", e)), this.editing = n().id);
482
+ });
483
+ let r = this;
484
+ return T(w, {
485
+ get when() {
486
+ return r.editing === n().id;
487
+ },
488
+ fallback: e,
489
+ get children() {
490
+ return r.editor(n());
491
+ }
492
+ });
493
+ }
494
+ editor(e) {
495
+ let t = this.translationForKey(e.part === "key" ? "jsonEditKey" : "jsonEditValue"), n = this.partForName("editor"), r = /* @__PURE__ */ i((t) => this.watchEditor(t, e), "ref"), { kind: a } = e;
496
+ if (Array.isArray(a)) {
497
+ let i = a.map((e) => ({
498
+ value: e,
499
+ text: e
500
+ }));
501
+ var o = ke();
502
+ return j(o, "part", n), j(o, "aria-label", t), j(o, "options", i), A(() => r, o), o._$owner = D(), E(() => plainText(e.value), (e) => {
503
+ j(o, "value", e);
504
+ }), o;
505
+ }
506
+ if (a === "boolean") {
507
+ var s = Ae();
508
+ return j(s, "part", n), j(s, "aria-label", t), A(() => r, s), s._$owner = D(), E(() => e.value === !0, (e) => {
509
+ j(s, "selected", e);
510
+ }), s;
511
+ }
512
+ let c = shownForEditing(e);
513
+ var l = je();
514
+ return j(l, "part", n), j(l, "aria-label", t), j(l, "step", a === "number" ? "any" : a === "datetime" ? "1" : void 0), j(l, "value", c), A(() => r, l), l._$owner = D(), E(() => ({
515
+ e: Ze[a],
516
+ t: `--edit-chars: ${editChars(c)}`
517
+ }), ({ e, t }, n) => {
518
+ e !== n?.e && j(l, "type", e), M(l, t, n?.t);
519
+ }), l;
520
+ }
521
+ watchEditor(e, t) {
522
+ let n = /* @__PURE__ */ i(() => this.commitEdit(t, valueFromEditor(e, t)), "keep");
523
+ e.addEventListener("keydown", (e) => {
524
+ if (e.key === "Enter") n();
525
+ else if (e.key === "Escape") this.editing = void 0;
526
+ else return;
527
+ e.preventDefault(), e.stopPropagation();
528
+ }), e.addEventListener("input", () => e.style.setProperty("--edit-chars", String(editChars(plainText(e.value))))), e.addEventListener("focusout", (t) => {
529
+ let r = t.relatedTarget;
530
+ (!r || r !== e && !e.contains(r)) && n();
531
+ });
532
+ let r = /* @__PURE__ */ i((e) => {
533
+ let { selected: n, value: r } = e.detail;
534
+ this.commitEdit(t, t.kind === "boolean" ? !!n : plainText(r));
535
+ }, "keepChosen");
536
+ (Array.isArray(t.kind) || t.kind === "boolean") && e.addEventListener("ui-changed", r), p(() => {
537
+ Promise.resolve(e.ready).then(() => m(() => {
538
+ e.focus(), e.shadowRoot?.querySelector("input:not([type=checkbox])")?.select();
539
+ }));
540
+ });
541
+ }
542
+ commitEdit(e, t) {
543
+ if (this.editing !== e.id || (this.editing = void 0, t === Q)) return;
544
+ let n = this.value, { at: r } = e, i;
545
+ if (e.part === "value") {
546
+ if (Object.is(t, valueAt(n, r))) return;
547
+ i = setAt(n, r, t);
548
+ } else {
549
+ let e = r[r.length - 1], a = String(t), o = valueAt(n, r.slice(0, -1));
550
+ if (!a || a === e || Object.hasOwn(o, a)) return;
551
+ i = renameAt(n, r, a);
552
+ let s = pathOf(r), c = pathOf([...r.slice(0, -1), a]), l = /* @__PURE__ */ new Map();
553
+ for (let [e, t] of this.toggled) l.set(e === s || e.startsWith(s + Z) ? c + e.slice(s.length) : e, t);
554
+ this.toggled = l;
555
+ }
556
+ this.keepsToggles = !0, this.content = JSON.stringify(i, null, 2) ?? "";
557
+ }
558
+ navigate(e, t) {
559
+ if (e.detail > 1 || this.editing) return;
560
+ let n = window.getSelection();
561
+ n && !n.isCollapsed && n.toString() || (this.pendingNavigate?.cancel(), this.editable ? (this.pendingNavigate = f(Ye, () => this.send("ui-navigating", t)), this.pendingNavigate.catch(() => {})) : this.send("ui-navigating", t));
94
562
  }
95
563
  static parsedFrom(e) {
96
564
  if (!e.trim()) return {};
@@ -101,14 +569,143 @@ var y = "ui-json-data-changed", b = class JsonChild {
101
569
  }
102
570
  }
103
571
  };
104
- N = t(M), s(N, 2, "parsed", k, P), s(N, 2, "hasError", O, P), s(N, 1, "onParsedChanged", D, P), s(N, 13, "vocabulary", j, P), s(N, 13, "elementSetup", A, P), l(N, P), r(P, "UIJson"), n(P, "vocabulary", u(N, 8, P, T)), u(N, 11, P), n(P, "elementSetup", u(N, 12, P, {
105
- styleSheets: { json: E },
106
- DOMElement: DOMJsonElement,
572
+ W = n(U), G = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), c(W, 2, "parsed", Re, Y), c(W, 2, "hasError", Le, Y), c(W, 1, "onParsedChanged", Ie, Y), c(W, 4, "toggled", H, Y, G), c(W, 1, "toggle", V, Y), c(W, 1, "copy", B, Y), c(W, 1, "setQuotes", z, Y), c(W, 4, "columns", R, Y, K), c(W, 1, "watchWidth", L, Y), c(W, 4, "editing", I, Y, q), c(W, 1, "commitEdit", Fe, Y), c(W, 1, "navigate", Pe, Y), c(W, 13, "vocabulary", Be, Y), c(W, 13, "elementSetup", ze, Y), u(W, Y), i(Y, "UIJson"), r(Y, "vocabulary", d(W, 20, Y, he)), d(W, 23, Y), r(Y, "elementSetup", d(W, 24, Y, {
573
+ styleSheets: { json: ge },
574
+ DOMElement: Ve,
107
575
  delegatesFocus: !1
108
- })), u(N, 15, P);
109
- var F = P;
576
+ })), d(W, 27, Y);
577
+ var X = Y, He = [
578
+ "text",
579
+ "number",
580
+ "date",
581
+ "datetime",
582
+ "boolean",
583
+ "json"
584
+ ], Ue = "clipboard outline", We = "check circle outline", Ge = 24, Ke = 90, qe = 32, Z = "", Je = "", Ye = .3, Q = /* @__PURE__ */ Symbol("no change"), Xe = /^\d{4}-\d{2}-\d{2}$/, $ = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?)(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/, Ze = {
585
+ text: "text",
586
+ number: "number",
587
+ date: "date",
588
+ datetime: "datetime-local",
589
+ boolean: "text",
590
+ json: "text"
591
+ };
592
+ function loadEditors() {
593
+ return Promise.all([
594
+ import("./ui-input.js"),
595
+ import("./ui-select.js"),
596
+ import("./ui-checkbox.js")
597
+ ]);
598
+ }
599
+ i(loadEditors, "loadEditors");
600
+ function editChars(e) {
601
+ return Math.max(4, e.length + 1);
602
+ }
603
+ i(editChars, "editChars");
604
+ function shownForEditing({ part: e, kind: t, value: n }) {
605
+ return t === "datetime" ? $.exec(plainText(n))?.[1] ?? "" : t === "json" && e === "value" ? scalarText(n) : plainText(n);
606
+ }
607
+ i(shownForEditing, "shownForEditing");
608
+ function valueFromEditor(e, { part: t, kind: n, value: r }) {
609
+ if (n === "boolean") return !!e.selected;
610
+ let i = plainText(e.value);
611
+ if (t === "key") return keyFromText(i);
612
+ if (Array.isArray(n) || n === "text") return i;
613
+ if (n === "json") return readLoose(i);
614
+ if (!i) return Q;
615
+ if (n === "number") return Number.isFinite(Number(i)) ? Number(i) : Q;
616
+ if (n === "datetime") {
617
+ let [, e = "", , t = ""] = $.exec(plainText(r)) ?? [], n = e.length > 16;
618
+ return (n && i.length === 16 ? i + ":00" : n ? i.slice(0, 19) : i.slice(0, 16)) + t;
619
+ }
620
+ return i;
621
+ }
622
+ i(valueFromEditor, "valueFromEditor");
623
+ function keyFromText(e) {
624
+ let t = readLoose(e.trim());
625
+ return (typeof t == "string" ? t : e.trim()) || Q;
626
+ }
627
+ i(keyFromText, "keyFromText");
628
+ function plainText(e) {
629
+ return typeof e == "string" ? e : e == null ? "" : JSON.stringify(e) ?? "";
630
+ }
631
+ i(plainText, "plainText");
632
+ function isContainer(e) {
633
+ return typeof e == "object" && !!e;
634
+ }
635
+ i(isContainer, "isContainer");
636
+ function entriesOf(e) {
637
+ return isContainer(e) ? Array.isArray(e) ? e.map((e, t) => [String(t), e]) : Object.entries(e) : [];
638
+ }
639
+ i(entriesOf, "entriesOf");
640
+ function scalarKind(e) {
641
+ return typeof e == "string" ? "string" : typeof e == "number" ? "number" : typeof e == "boolean" ? "boolean" : "null";
642
+ }
643
+ i(scalarKind, "scalarKind");
644
+ function scalarText(e) {
645
+ return e === void 0 ? "null" : JSON.stringify(e) ?? "";
646
+ }
647
+ i(scalarText, "scalarText");
648
+ function keyText(e, t) {
649
+ return t || !/^[A-Za-z_$][\w$]*$/.test(e) ? JSON.stringify(e) : e;
650
+ }
651
+ i(keyText, "keyText");
652
+ function pathOf(e) {
653
+ return e.map((e) => Z + e).join("");
654
+ }
655
+ i(pathOf, "pathOf");
656
+ function readLoose(e) {
657
+ try {
658
+ return JSON.parse(e);
659
+ } catch {
660
+ return e;
661
+ }
662
+ }
663
+ i(readLoose, "readLoose");
664
+ function valueAt(e, t) {
665
+ let n = e;
666
+ for (let e of t) n = isContainer(n) ? n[e] : void 0;
667
+ return n;
668
+ }
669
+ i(valueAt, "valueAt");
670
+ function setAt(e, t, n) {
671
+ if (!t.length) return n;
672
+ let [r, ...i] = t, a = setAt(e[r], i, n);
673
+ return Array.isArray(e) ? e.map((e, t) => t === r ? a : e) : {
674
+ ...e,
675
+ [r]: a
676
+ };
677
+ }
678
+ i(setAt, "setAt");
679
+ function renameAt(e, t, n) {
680
+ let r = t.slice(0, -1), i = t[t.length - 1], a = valueAt(e, r);
681
+ return setAt(e, r, Object.fromEntries(Object.entries(a).map(([e, t]) => [e === i ? n : e, t])));
682
+ }
683
+ i(renameAt, "renameAt");
684
+ function previewTokens(e, t, n) {
685
+ let r = [], a = t - 4, o = /* @__PURE__ */ i((e, t) => {
686
+ r.push([e, t]), a -= t.length;
687
+ }, "push"), s = /* @__PURE__ */ i((e, t) => {
688
+ let i = Array.isArray(e), c = entriesOf(e), [l, u] = i ? ["[", "]"] : ["{", "}"];
689
+ if (!c.length) return o("punct", l + u);
690
+ if (t >= 2) return o("punct", `${l} ... ${u}`);
691
+ o("punct", l + " ");
692
+ for (let e = 0; e < c.length; e++) {
693
+ let l = r.length, d = a;
694
+ e && o("punct", ", ");
695
+ let [f, p] = c[e];
696
+ if (i || (o("key", keyText(f, n)), o("punct", ": ")), isContainer(p)) s(p, t + 1);
697
+ else {
698
+ let e = scalarText(p);
699
+ typeof p == "string" && e.length > qe && (e = e.slice(0, 30) + "…\""), o(scalarKind(p), e);
700
+ }
701
+ if (a < 0 && e) return r.length = l, a = d, o("punct", `, ... ${u}`);
702
+ }
703
+ o("punct", " " + u);
704
+ }, "walk");
705
+ return s(e, 0), r;
706
+ }
110
707
  // src/components/ui-json/index.ts
111
- F.define();
112
- export { DOMJsonElement, b as JsonChild, F as UIJson, y as t };
708
+ i(previewTokens, "previewTokens"), se(["click"]), X.define();
709
+ export { Ve as DOMJsonElement, He as JSON_EDITOR_KINDS, ue as JsonChild, X as UIJson, le as t };
113
710
 
114
711
  //# sourceMappingURL=ui-json.js.map